Fix GitStateMonitor reporting agent own changes as human activity#241
Fix GitStateMonitor reporting agent own changes as human activity#241
Conversation
The old takeDelta() took a snapshot and diffed against the previous one in a single call, always called before runAgent(). This meant the baseline was set before the agent ran, so everything the agent did during its turn (file edits, commits) would show up in the next turn's delta as if the human had done it. Split into two separate operations: - getDelta(): called before runAgent(), diffs against the stored baseline to capture only what the human changed between turns. Does not update the baseline. - takeSnapshot(): called after runAgent() returns, captures the post-agent state as the new baseline for the next turn. This way the agent's own work is always behind the baseline and never appears in the delta the agent receives.
string | undefined is consistent with how the rest of the codebase signals "no value". The null return was unnecessary and forced a ?? undefined coercion at the call site. Also moved the getDelta() call to immediately before runAgent() to keep the delta capture as close to agent start as possible.
bananabot9000
left a comment
There was a problem hiding this comment.
Clean fix. The old takeDelta() was snapshot-then-diff in one call — so the snapshot taken after the agent ran became the baseline, and the agent's own edits/commits showed up as "human activity" on the next turn.
Split into getDelta() (diff only, no snapshot update) and takeSnapshot() (update baseline only) makes the sequencing explicit: diff before the agent runs, snapshot after. The agent's own changes fall between the two calls and are excluded from the next delta.
null → undefined return type aligns with the gitDelta ?? undefined removal in main.ts. Minor: the old takeDelta also handled first-call baseline setup (#previous === null → snapshot + return null). Now the first getDelta() returns undefined without snapshotting — the first takeSnapshot() after runAgent() sets the baseline instead. Same net effect, cleaner separation.
Approve.
The GitStateMonitor was refactored to split takeDelta() into two separate operations, but the tests were not updated to match. They still called takeDelta() which no longer exists, causing four failures. Update the GitStateMonitor tests to use the new two-call pattern: - takeSnapshot() establishes / advances the baseline - getDelta() diffs current state against the baseline without mutating it Also align the return value expectations: getDelta() returns undefined (not null) when there is no baseline or no change, matching the implementation signature of Promise<string | undefined>.
Summary
takeDelta()intogetDelta()andtakeSnapshot()getDelta()diffs against the stored baseline without updating it; returnsundefinedif no baseline yettakeSnapshot()captures post-agent state afterrunAgent()returnsRelated Issues
Fixes #234
Co-Authored-By: Claude noreply@anthropic.com