fix(telemetry): resolve the repository from the host, not from payload.cwd - #892
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The functional change is minimal and aligns handleFileWritten with existing host-abstracted behavior, with only a small test-mock consistency nit noted.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Fixes telemetry’s handleFileWritten to resolve the repository root via the host’s readCwd(host, payload) (consistent with the observed-files pass), preventing tool-stated writes from being dropped when a host’s workspace path is not payload.cwd.
Changes:
- Update
handleFileWrittento usereadCwd(host, payload)instead ofpayload.cwdwhen resolving the runs directory. - Add a regression test that injects a test-only host entry to validate tool-stated writes when the host reports a workspace path (without
cwd).
| File | Description |
|---|---|
| scripts/__tests__/aidd-telemetry-file-writes.test.js | Adds regression coverage using an injected host table entry to reproduce the workspace-vs-cwd mismatch. |
| plugins/aidd-telemetry/hooks/lib/file-writes.cjs | Switches repo resolution for tool-stated writes to host-provided readCwd, aligning behavior with the observed pass. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| require.cache[indexId].exports = { | ||
| ...realExports, | ||
| TOOLS_BY_HOST: tools, | ||
| toolFor: (host) => tools[host] || null, | ||
| readCwd: (host, payload) => (tools[host] ? tools[host].readCwd(payload) : undefined), | ||
| }; |
There was a problem hiding this comment.
Good catch — fixed. readSessionId now resolves through the same merged table as toolFor and readCwd, so the stub is consistent whichever of the three a caller reaches for:
const toolFor = (host) => tools[host] || null;
readCwd: (host, payload) => (toolFor(host) ? toolFor(host).readCwd(payload) : undefined),
readSessionId: (host, payload) => (toolFor(host) ? toolFor(host).readSessionId(payload) : undefined),Pushed in b79c7a8, which also trims the comments on both files down to the density of the code around them.
…d.cwd handleFileWritten resolved the runs directory from payload.cwd, one host's spelling read as a rule, where handleTaskFilesObserved already reads the host's own readCwd. A host naming its workspace any other way had every write it stated dropped, and the turn-end walk then recorded the same file as "observed". No declared host changes behaviour: the four naming no written path return before that line, and Claude Code declares readCwd: (payload) => payload.cwd. The regression test therefore carries a test-only host entry. Refs ai-driven-dev#859 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2764f6b to
b79c7a8
Compare

🎯 What & why
handleFileWrittenresolved the runs directory frompayload.cwd, one host's spelling read as a rule, wherehandleTaskFilesObservedalready reads the host's ownreadCwd. A host naming its workspace any other way had every write it stated dropped, and the turn-end walk then recorded the same file asobserved— a loss that reads as ordinary output, which is why nothing caught it.Split out of the Antigravity work in #859 at the maintainer's request: a defect in shipped code, no roadmap decision needed.
🛠️ How it works
One line —
file-writes.cjs:107now readsreadCwd(host, payload), the same seam the observed pass uses three lines of the same shape below.No declared host changes behaviour: the four naming no written path (Codex, Copilot, Cursor, OpenCode) return at
statedRawPathbefore that line, and Claude Code declaresreadCwd: (payload) => payload.cwd. That is also why the regression test carries a test-only host: the only host that states a written path is the only one that carriescwd, so the witness is one more table entry — a workspace named in its own field, nocwd, and a hook working directory outside the repository. It lives inrequire.cachefor the body of the test only.🧪 How to verify
That A/B is the before/after measured in #859:
session_startalone, versussession_start+file_writtenwithsource: "tool-stated".Whole suite, as the
scripts-testspre-commit command runs it, onnext83b0246eplus this branch:→
454 tests, 454 pass, 0 fail, 0 skipped(macOS 27, Node 26.5.0, pnpm 12.3.4).antigravity(task C of feat(cli): support a single-clone global install shared by several CLIs #859), in its own PR.🔗 Linked issue
Refs #859
✅ I certify