Skip to content

bug(cli): resolveCliPath returns 'Cannot locate agentv CLI entry point' when Studio is run from source against a foreign cwd #1221

@christso

Description

@christso

Objective

resolveCliPath in apps/cli/src/commands/results/eval-runner.ts:215 returns "Cannot locate agentv CLI entry point" when Studio is run from source against a project directory that is not the agentv monorepo itself, and agentv is not installed globally.

Repro

# Pretend we're a user with a project that isn't the agentv repo
TMPDIR=$(mktemp -d)
cd "$TMPDIR"

# Boot Studio from a source checkout of the agentv worktree, pointed at $TMPDIR cwd
bun /path/to/agentv/apps/cli/src/cli.ts studio --port 4182 &
sleep 4

# Hit the launch endpoint
curl -s -X POST http://localhost:4182/api/eval/run -H "Content-Type: application/json" \
  -d '{"suite_filter":"any.eval.yaml","output":"runs/r1","resume":true}'
# → {"error":"Cannot locate agentv CLI entry point"}

Root cause

The path math in fallback path 2 is off by one. With currentDir = .../apps/cli/src/commands/results:

  • path.resolve(currentDir, '../../../cli.ts').../apps/cli/cli.ts (missing src/) ❌
  • Should be path.resolve(currentDir, '../../cli.ts').../apps/cli/src/cli.ts

The first candidate (path.join(cwd, 'apps/cli/src/cli.ts')) only succeeds when cwd is the agentv repo. The third fallback (global agentv binary) only works when the user has a published version installed. So a developer running Studio from a worktree against any other project hits all three failure modes.

// apps/cli/src/commands/results/eval-runner.ts:215-216
const fromSrc = path.resolve(currentDir, '../../../cli.ts'); // ❌ off-by-one
const fromDist = path.resolve(currentDir, '../../cli.js');   // also suspect — see below

Discovered by

PR #1220 e2e UAT — exercising the new "Resume run" / "Rerun failed cases" buttons against a synthetic project (not the agentv repo) hit this error. Worked around by installing a wrapper agentv shim on PATH.

Acceptance signals

  • Source-from-worktree Studio launches CLI subprocess successfully when cwd is unrelated to the agentv repo
  • Same for built-dist Studio (verify the fromDist path against tsup output layout — bundled cli.js sits at apps/cli/dist/cli.js, so resolving from a chunk's location may also need adjustment)
  • Tests in apps/cli/test/commands/results/serve.test.ts cover the launch-from-foreign-cwd case (currently the resume API tests tolerate [202, 500] because they hit this bug)

Non-goals

  • The existing global-agentv fallback works fine for end users who installed via npm; this only blocks dev-from-source workflows.

Suggested fix

- const fromSrc = path.resolve(currentDir, '../../../cli.ts');
- const fromDist = path.resolve(currentDir, '../../cli.js');
+ const fromSrc = path.resolve(currentDir, '../../cli.ts');
+ const fromDist = path.resolve(currentDir, 'cli.js'); // dist is bundled flat

Verify both branches with: bun apps/cli/src/cli.ts studio --port X (src) and bun apps/cli/dist/cli.js studio --port X (dist) from a foreign cwd, then POST to /api/eval/preview to confirm the spawn args resolve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions