Skip to content

fix(workspace): default hook cwd to workspaceFileDir for file-referenced templates#1081

Merged
christso merged 1 commit intomainfrom
fix/1080-hook-cwd-workspace-file-dir
Apr 13, 2026
Merged

fix(workspace): default hook cwd to workspaceFileDir for file-referenced templates#1081
christso merged 1 commit intomainfrom
fix/1080-hook-cwd-workspace-file-dir

Conversation

@christso
Copy link
Copy Markdown
Collaborator

@christso christso commented Apr 13, 2026

Summary

When a workspace is defined via a file reference (e.g., workspace: .templates/eval-workspace-setup.yaml), hook commands with no explicit cwd now resolve relative to the workspace file's directory instead of the eval file's directory.

This makes file-referenced templates self-contained — the same template produces identical behavior regardless of which eval file references it.

  • Added workspaceFileDir to WorkspaceConfig — set when workspace is resolved from a file reference
  • Added workspaceFileDir to ScriptExecutionContext — passed through from workspace config
  • Changed cwd fallback chain: config.cwdcontext.workspaceFileDircontext.evalDir
  • Preserved workspaceFileDir in mergeWorkspaceConfigs

Closes #1080

Test plan

  • New unit tests verify workspaceFileDir takes priority over evalDir when no explicit cwd is set
  • New unit tests verify explicit cwd still overrides workspaceFileDir
  • New unit tests verify workspaceFileDir is set for file references and undefined for inline configs
  • Existing tests still pass (1615 core tests, 67 eval tests)
  • All pre-push hooks pass (build, typecheck, lint, test, validate)
  • Manual red/green UAT with nested eval file referencing a shared template

🤖 Generated with Claude Code

…ced templates

When a workspace is defined via a file reference, hook commands with no
explicit cwd now resolve relative to the workspace file's directory
instead of the eval file's directory. This makes file-referenced
templates self-contained — the same template produces identical behavior
regardless of which eval file references it.

Closes #1080

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying agentv with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6926e8b
Status: ✅  Deploy successful!
Preview URL: https://3d4c5dab.agentv.pages.dev
Branch Preview URL: https://fix-1080-hook-cwd-workspace.agentv.pages.dev

View logs

@christso
Copy link
Copy Markdown
Collaborator Author

Red/Green UAT

Setup

Directory structure:

/tmp/uat-1080/
  scripts/check.mjs                          # Hook script
  evals/
    templates/
      workspace.yaml                         # command: ["node", "../../scripts/check.mjs"]
    group-a/
      root-eval.eval.yaml                    # workspace: ../templates/workspace.yaml
      subdir/
        nested-eval.eval.yaml                # workspace: ../../templates/workspace.yaml

The template uses ../../scripts/check.mjs — a relative path that resolves correctly from evals/templates/ (the template's directory) but not from evals/group-a/subdir/ (the nested eval's directory).

Red (main) — nested eval fails

$ bun apps/cli/src/cli.ts eval nested-eval.eval.yaml --dry-run

[ERROR] ⚠ Eval file failed: nested-eval.eval.yaml — before_all script failed:
  Script failed: error: Module not found '/tmp/uat-1080/evals/scripts/check.mjs'

The hook's cwd defaulted to evalDir (evals/group-a/subdir/), so ../../scripts/check.mjs resolved to /tmp/uat-1080/evals/scripts/check.mjs instead of /tmp/uat-1080/scripts/check.mjs.

Root eval on main: ✅ (cwd happened to be at the right depth — evals/group-a/)

Green (fix branch) — both evals pass

$ bun apps/cli/src/cli.ts eval root-eval.eval.yaml --dry-run    → EXIT CODE: 0 ✅
$ bun apps/cli/src/cli.ts eval nested-eval.eval.yaml --dry-run  → EXIT CODE: 0 ✅

Both evals now use workspaceFileDir (evals/templates/) as default cwd, so ../../scripts/check.mjs resolves to /tmp/uat-1080/scripts/check.mjs consistently regardless of eval file depth.

(Scores are 0% as expected with --dry-run — the key signal is no execution errors on the hook.)

@christso christso marked this pull request as ready for review April 13, 2026 12:33
@christso christso merged commit 6625f25 into main Apr 13, 2026
4 checks passed
@christso christso deleted the fix/1080-hook-cwd-workspace-file-dir branch April 13, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook cwd should default to workspaceFileDir when workspace is a file reference

1 participant