feat: real-time file tracking via post-file-edit hook#637
feat: real-time file tracking via post-file-edit hook#637
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 1536d1523eec
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 50f1205aa19a
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 1065c97cae2c
Update resolveFilesTouched to merge state.FilesTouched AND the tracking file (.git/entire-sessions/<session-id>.files), falling back to transcript extraction only when both sources are empty. Results are deduplicated and sorted. Add cleanup of the tracking file at two points: - After condensation (state.FilesTouched = nil) - After carry-forward (state.FilesTouched = remainingFiles) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: c169ccec299e
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 9bfea85f075f
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 1c855fb06961
Prevent line injection in the append-only tracking file by rejecting paths containing \n or \r characters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 4c0ce7ae83d3
PR SummaryMedium Risk Overview This introduces a new lifecycle The session Written by Cursor Bugbot for commit 83f1882. Configure here. |
There was a problem hiding this comment.
Pull request overview
This PR introduces Phase 1 of a transcript parsing replacement plan by adding real-time file tracking via a post-file-edit hook. Instead of relying solely on transcript parsing to determine which files an agent edited, agent file edits are now tracked in real-time using an append-only .files tracking file stored alongside session state in .git/entire-sessions/.
Changes:
- Adds
FileEditevent type andFilePathfield to the agent event system, with Claude Code'sPostToolUse[Write]andPostToolUse[Edit]hooks wired to fire the new event - Introduces
AppendFileTouched,ReadFilesTouched, andClearFilesTouchedmethods onStateStorefor append-only file tracking with deduplication, newline injection prevention, and idempotent cleanup - Updates
resolveFilesTouchedto merge state-based and tracking-file-based file lists, falling back to transcript extraction only when both are empty, with cleanup at condensation and carry-forward points
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
cmd/entire/cli/agent/event.go |
Adds FileEdit event type and FilePath field to the Event struct |
cmd/entire/cli/agent/claudecode/lifecycle.go |
Adds parseFileEdit method and registers HookNamePostFileEdit in hook names |
cmd/entire/cli/agent/claudecode/lifecycle_test.go |
Tests for parseFileEdit and AllHookTypes coverage |
cmd/entire/cli/agent/claudecode/hooks.go |
Registers PostToolUse[Write] and PostToolUse[Edit] hook matchers during installation |
cmd/entire/cli/agent/claudecode/hooks_test.go |
Verifies Write and Edit hook matchers are installed alongside existing hooks |
cmd/entire/cli/hook_registry.go |
Classifies post-file-edit as a "tool" hook type |
cmd/entire/cli/lifecycle.go |
Adds handleLifecycleFileEdit with fail-open, lightweight file tracking |
cmd/entire/cli/session/state.go |
Implements AppendFileTouched, ReadFilesTouched, ClearFilesTouched on StateStore |
cmd/entire/cli/session/state_test.go |
Comprehensive unit tests for file tracking storage including security and edge cases |
cmd/entire/cli/strategy/manual_commit_hooks.go |
Merges tracking file data in resolveFilesTouched, clears tracking at condensation/carry-forward |
cmd/entire/cli/strategy/manual_commit_test.go |
Tests for tracking file read and merge behavior in resolveFilesTouched |
cmd/entire/cli/integration_test/hooks.go |
Adds SimulatePostFileEdit test helper |
cmd/entire/cli/integration_test/file_tracking_test.go |
End-to-end integration test for file tracking through hook binary |
cmd/entire/cli/integration_test/agent_test.go |
Updates expected hook count from 7 to 9 |
- Add Debug/Warn logging at silent error suppression points in parseFileEdit, handleLifecycleFileEdit, and resolveFilesTouched - Extract clearFilesTracking helper to deduplicate cleanup pattern - Simplify merge loop in resolveFilesTouched using append - Use ReadFilesTouched in integration test instead of manual dedup - Add test for parseFileEdit with malformed tool_input JSON Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: d7ebe011b701
|
bugbot run |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 35db4ea2bbf4
Summary
post-file-edithook, eliminating the need for transcript parsing to determine which files an agent touched.git/entire-sessions/<session-id>.files) that records file paths as agents edit themPostToolUse[Write]andPostToolUse[Edit]hooks to fire the new eventresolveFilesTouchednow merges the tracking file withstate.FilesTouched, falling back to transcript extraction only when both are emptyThis is Phase 1 of the transcript parsing replacement plan. Other agents (Gemini CLI, Factory AI Droid, OpenCode, Copilot CLI) will be wired in follow-up PRs.
Architecture
At checkpoint time,
resolveFilesTouchedmerges:state.FilesTouched(from previous turns' SaveStep)Changes
New event type & handler:
FileEditevent type inagent/event.gohandleLifecycleFileEditinlifecycle.go— normalizes to repo-relative paths, fail-openSession package:
AppendFileTouched— O_APPEND write, one path per lineReadFilesTouched— deduplicated, sorted readClearFilesTouched— cleanup after condensationStrategy integration:
resolveFilesTouchedmerges tracking file + state, falls back to transcriptClaude Code wiring:
PostToolUse[Write]andPostToolUse[Edit]matchers in hooksparseFileEditextractsfile_pathfromtool_inputJSONTest plan
mise run fmt && mise run lint && mise run test:ciclean🤖 Generated with Claude Code