fix(discovery): bind project discovery to the running framework install - #3561
Conversation
A globally installed CLI never registered a project's tools/ directory, so the default `ai-agent` template failed on every chat message with `Unknown tool reference: calculator`. Discovery rewrites bare `veryfront/*` imports in project files to the project's own `node_modules/veryfront` package. That is correct when the CLI is the project's own install, but a globally installed CLI runs from a different install: the project copy is then a second framework instance whose extension contracts were never bootstrapped. `defineSchema()` throws `Missing extension for contract "SchemaValidator"`, tool discovery aborts for that file, and the project registers 0 tools while agents/ still loads. Prefer the framework install that is actually executing when it is a different npm install than the project's. Source checkouts and jsr:/https: runtimes are not npm installs, so the project-local preference is unchanged there and for project-local CLI launches.
📝 WalkthroughWalkthroughChangesDiscovery import resolution
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
CI triage: the red shard was an unrelated flake, not a regression from this PR
Why it is not this PR:
Proof it is a flake: re-ran the failed jobs on the same commit ( Likely cause, for whoever owns #3553: the test drives the follower with Also note: the |
|
@coderabbitai review |
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/discovery/import-rewriter.test.ts`:
- Around line 474-552: Replace the Deno-specific fixture setup and cleanup in
both tests around the discovery import assertions with runtime-neutral helpers
from `#veryfront/testing/deno-compat.ts`, including temporary-directory creation,
directory creation, file writes, and recursive removal. Preserve the existing
test scenarios and assertions so the regression coverage runs under Node, Bun,
and Deno.
In `@src/discovery/import-rewriter.ts`:
- Around line 512-525: Exclude bare veryfront framework specifiers from the
earlier generic package-rewriting pass so they remain unchanged when
veryfrontSpecifiers is collected. Update the generic rewrite logic in the
surrounding import-rewriting flow, preserving veryfront/schemas and related
framework specifiers for the framework-specific loop containing
resolveRuntimeSpecifierToFileUrl and rewriteResolvedSpecifierImports.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ea5a9aac-d0d8-4b78-82b3-d36c126e92c6
📒 Files selected for processing (2)
src/discovery/import-rewriter.test.tssrc/discovery/import-rewriter.ts
Found by a DX dogfood walk of https://veryfront.com/docs/code/getting-started/create-project against published CLI 0.1.1228, installed the way the installation page tells you to (
npm install -g veryfront).Symptom
The app boots and renders with a clean browser console, but every chat message fails — including the template's own built-in suggestion buttons:
tools/calculator.tsin the scaffold declaresid: "calculator"exactly. WithVERYFRONT_DEBUG=1the real failure is visible at boot:It is specific to the launcher. Same project, same 0.1.1228, cache cleared:
veryfront dev(global npm install)agents/loads,tools/does notnpm run dev(node_modules/.bin/veryfront)bun run dev(--runtime bunscaffold)Root cause
rewriteDiscoveryImportsrewrites bareveryfront/*imports in discovered project files to the project's ownnode_modules/veryfrontpackage (#3037 — discovery modules are emitted outside the project tree, so they must not resolve by chance).That is correct when the CLI is the project's install. A globally installed CLI runs from a different install, so the project copy becomes a second framework instance in the same process — and nothing ever bootstraps its extension contracts.
defineSchema()in that instance resolvesSchemaValidatoragainst an empty contract registry and throws. Tool discovery catches the error per file, so the project registers 0 tools;agents/assistant.tsimports onlyveryfront/agent, which needs no contract, so agents keep loading and the failure only surfaces later asUnknown tool reference.ext-schema-zodis bundled in the package and is loaded — just into the CLI's instance, not the project copy's. Hence the misleading "install it withdeno add" advice.Fix
Prefer the framework install that is actually executing when it is a different npm install than the project's. The project-local preference from #3037 is unchanged everywhere it was already right:
jsr:/https:runtimes — not an npm install, so the rule never triggers and the existing fail-closed behaviour for a present-but-unreadable project package is preserved.Regression test
src/discovery/import-rewriter.test.ts— Deno BDD, alongside the eight existing tests that pin this exact resolution decision.binds discovery imports to the running framework install when the CLI runs from another install— fails before the fix, resolving to<project>/node_modules/veryfront/local/schemas.jsinstead of the running install.keeps project-local veryfront exports when the running install is the project's own— pins the Expose programmatic project runtime discovery #3037 behaviour that must not regress.It lives in
veryfront-coderather thanveryfront-e2ebecause the defect is pure module resolution: reproducible in-process, no browser, no deployment, no credentials — so it runs in the pre-push gate. The runtime resolver is injected through a new optionalresolveSpecifieroption (mirroringrewriteForDeno's existing seam) so a test can stand in for a globally installed CLI deterministically.Verification
Beyond the unit test, the same change was applied to the published 0.1.1228 artifact and the finding's command re-run against a freshly scaffolded
ai-agentproject:Zero occurrences of
Unknown tool reference(was one per message). Full pre-push suite passed.Summary by CodeRabbit
Bug Fixes
Tests