fix(story-mode): a file a python or node script rewrites counts as changed

From review round 5: Claude rewrote textstats.py, the change the user
asked for, through `python3 - <<EOF ... open(p, "w").write(s)`, and
the page listed only the two files the same command wrote with `cat >`.
A script fed to python or node by a here-document is now read for the
files it opens for writing (`open(target, 'w'|'a'|...)`, `Path(...)
.write_text`, `writeFileSync`), with the target a string literal or a
name bound to one (`p = "textstats.py"`); anything computed is left
out, never guessed, and scratch targets are skipped. They are edits
without lines, like the files Claude Code says a command modified,
since what the script changed is not in the command.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-18 13:18:13 +02:00
1 parent b220d6d6d7
commit c36700a9c0
2 files changed
+84 -4

No files matched your search

+34 -2
View File
@@ -939,10 +939,42 @@ describe('buildStoryPage', () => {
),
end(1000),
];
(lines[1] as { cwd?: string }).cwd = '/w';
(lines[2] as { cwd?: string }).cwd = '/w';
const page = pageOf(lines);
expect(page.events[1].edits?.map((d) => d.file)).toEqual(['/w/test_a.py']);
expect(page.filesChanged).toBe(1);
// The script's own write and the file Claude Code says changed: both, neither with lines.
expect(page.events[1].edits?.map((d) => [d.file, d.hunks.length])).toEqual([
['/w/t.py', 0],
['/w/test_a.py', 0],
]);
expect(page.filesChanged).toBe(2);
});
it('a python or node script fed by a here-document: the files it opens for writing, never guessed', () => {
const files = (command: string) => heredocWrites(command, '/w').map((d) => d.file);
expect(
files(
[
"python3 - <<'EOF'",
'p = "textstats.py"',
's = open(p).read()',
"s = s.replace('a', 'b')",
'open(p, "w").write(s)',
"Path('README.md').write_text('# x')",
"with open('notes.txt', mode='a') as f: f.write('x')",
"open('/tmp/scratch.txt', 'w').write('x')",
"open(os.path.join(d, 'x.py'), 'w')",
"open('data.json').read()",
'EOF',
].join('\n')
)
).toEqual(['/w/textstats.py', '/w/README.md', '/w/notes.txt']);
expect(files("node <<'EOF'\nconst out = 'dist/app.js';\nfs.writeFileSync(out, code);\nEOF")).toEqual([
'/w/dist/app.js',
]);
expect(files("python3 - <<'EOF'\nprint(open('a.py').read())\nEOF")).toEqual([]);
const [edit] = heredocWrites("python3 - <<'EOF'\nopen('a.py', 'w').write('x')\nEOF", '/w');
expect(edit).toMatchObject({ file: '/w/a.py', added: 0, removed: 0, hunks: [], truncated: true });
});
it('a compaction says what it did; ToolSearch is looking; EnterPlanMode says plan mode', () => {