fix(web): hand resolved pi-coding-agent entry to the /web child process - #355
Open
FHMinyi wants to merge 1 commit into
Open
fix(web): hand resolved pi-coding-agent entry to the /web child process#355FHMinyi wants to merge 1 commit into
FHMinyi wants to merge 1 commit into
Conversation
npm-installed users hit exit code 1 on /web: the standalone child process cannot resolve the peer dependency @earendil-works/pi-coding-agent from the npm package location. The parent extension runs inside Pi, so resolve the package entry there: walk up from realpathSync(process.argv[1]) to the pi-coding-agent package root and hand dist/index.js to the child via OPENPI_PI_CODING_AGENT_ENTRY. The child maps the bare specifier to that absolute path through a jiti alias. Resolution is fail-soft and any inherited stale env value is dropped, preserving the previous behavior when no path is found. Closes openpi-dev#341
Author
|
@tt-a1i 佬 review 下🥺 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #341.
Users who install via
pi install npm:@tt-a1i/openpi(the documented install path) cannot start the Web Workbench:/webreportsOpenPI Web Workbench exited with code 1.and the real error is swallowed when the TUI resumes. The spawned standalone node process fails withCannot find module '@earendil-works/pi-coding-agent'because the package is apeerDependency, whichpi install npm:does not install. Dev checkouts never see this because the same-name devDependency resolves.Value
Makes
/webandopenpi webwork for every npm-installed user — currently the feature is broken for 100% of that install base. No behavior change for dev checkouts or for environments where resolution fails.Approach
The parent extension runs inside the Pi process, where the loader resolves the peer package. It resolves the entry path and hands it to the child through
OPENPI_PI_CODING_AGENT_ENTRY; the child (bin/openpi.js) maps the bare specifier to that absolute path via a jitialias.Why walk-up instead of
import.meta.resolve/createRequire(verified with a probe extension inside a real Pi process, fnm + node 24):pi-coding-agent/dist/core/extensions/loader.js) jiti-aliases the specifier to<pkg>/dist/index.js, so dynamicimport()works, butimport.meta.resolveandcreateRequire(import.meta.url)are not intercepted and fail from the extension's location.createRequire(process.argv[1])fails because argv[1] is a version-manager shim symlink (node does not realpath it); afterrealpathSync, CJS resolution is still rejected (exportshas norequirecondition).realpathSync(process.argv[1])→ walk up to thepackage.jsonnamed@earendil-works/pi-coding-agent→ use<root>/dist/index.js(the exact path Pi's own loader aliases to), verified withexistsSync.Design choices:
OPENPI_PI_CODING_AGENT_ENTRYis deleted, and the child behaves exactly as before.WebCommandDependenciesseam so tests fake it without touching the filesystem.Known limitation (not addressed here): bun/SEA compiled Pi binaries have no node_modules tree, so walk-up finds nothing and behavior is unchanged; the
/webspawn viaprocess.execPathalready assumes a node runtime.Validation
bun run testonmain @ 72fbba5: 1243 pass / 0 fail / 1 skipped.bun run check: config contract, discipline ledger, web syntax check, biome format + lint, tsc — all green.tests/extensions/web/index.test.ts: the launcher hands the resolved entry to the child env and drops a stale inherited value when resolution fails.tests/web/cli.test.ts: end-to-end — a stub package layout without the peer dependency proves the jiti alias redirects the bare@earendil-works/pi-coding-agentimport to the handed-over entry.OPENPI_PI_CODING_AGENT_ENTRY=<global pi dist/index.js> node bin/openpi.js web --no-workspace --no-open— WebHost started on127.0.0.1:53056, printed the authenticated ready screen, and released the host lease on shutdown./webpath (thectx.mode === "tui"gate cannot be automated here); the smoke exercised the identical child command the TUI spawns.Impact
/webandopenpi webnow start for npm-installed users; unchanged otherwise.