Skip to content

fix(hooks): resolve open(var) paths in inline scripts; stop reporting read-only opens as edits - #177

Merged
AkashGoenka merged 2 commits into
mainfrom
fix/inline-script-var-paths-176
Sep 29, 2026
Merged

AkashGoenka merged 2 commits into
mainfrom
fix/inline-script-var-paths-176

Conversation

@AkashGoenka

Copy link
Copy Markdown
Owner

Closes #176

What changed

hooks/evidence.mjs:

  • inlineCalls replaces the single API_ARG_RE scan. For each file-open call in an inline script it resolves the path (a quoted literal, or a bare identifier resolved one hop to the last literal assignment before the call) and tiers that call on its own.
  • WRITE_API_RE: open counts as a write only when a mode string follows the first argument. The old pattern matched the first letter of the path, so open('assets/x.json') was an "edit".
  • Still unattributed on purpose: for p in [...], sys.argv, string concatenation, ${} templates, globs.

Evidence

  • The command from the report went from bashEditTargets -> [] to ['assets/i18n/en.json', 'app/pages/analytic/components/CardWidget/CardWidget.tsx'].
  • 752 local transcripts, 11,133 inline file opens: 31% literal (already handled), 38% bare identifier, 1,838 of those have a preceding literal assignment. Attributed commands 2,779 -> 3,880 (+40%).
  • 6 new tests fail on the old code and pass on the new. Full suite 869/869, tsc --noEmit clean.

Deliberate test change

tests/cochange-nudge.test.ts had a test asserting that const f="src/b.ts"; writeFileSync(f, s) claims nothing. That is exactly the shape this PR resolves, so it now asserts the file IS an edit. I added two controls for what the old test was really protecting: a genuinely computed write target stays silent, and a file that is only read through a variable is never claimed as an edit.

Not in this PR

prettier --write / eslint --fix as edits (listed as out of scope in #176). The notebook note for hooks/evidence.mjs still describes the older behaviour; it needs a kb write and goes through kb commit, not this feature branch.

🤖 Generated with Claude Code

AkashGoenka and others added 2 commits September 29, 2026 22:10
… read-only opens as edits (#176)

Inline scripts that do `p='x.json'` then `open(p)` named no file, so the nudge
and capture worklist never saw the read or the edit. 38% of inline file opens
use a bare identifier; a preceding literal assignment exists for 1,838 of them
across 752 local transcripts (+40% attributed commands).

- inlineCalls: resolve `open(ident)` one hop to the last literal assignment
  before the call; tier each open call on its own instead of the whole command.
- WRITE_API_RE: `open` is a write only when a mode string follows the path
  argument. The old `[^)]*['"][wax]` matched the first letter of the path, so
  open('assets/x.json') was reported as an edit.
- Loops, argv, computed and `${}` paths stay unattributed.
- cochange-nudge test that pinned "variable holding a literal claims nothing"
  now pins the new behaviour, plus controls for a truly computed target and a
  file that is only read.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@AkashGoenka
AkashGoenka merged commit c96a2ca into main Sep 29, 2026
8 checks passed
@AkashGoenka
AkashGoenka deleted the fix/inline-script-var-paths-176 branch September 29, 2026 16:45
@AkashGoenka AkashGoenka mentioned this pull request Sep 29, 2026
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.

Inline scripts: resolve open(var) paths and stop reporting read-only opens as edits

1 participant