Skip to content

Fix GitStateMonitor reporting agent own changes as human activity#241

Merged
shellicar merged 4 commits intomainfrom
fix/git-state-monitor-own-changes
Apr 10, 2026
Merged

Fix GitStateMonitor reporting agent own changes as human activity#241
shellicar merged 4 commits intomainfrom
fix/git-state-monitor-own-changes

Conversation

@shellicar
Copy link
Copy Markdown
Owner

Summary

  • Split takeDelta() into getDelta() and takeSnapshot()
  • getDelta() diffs against the stored baseline without updating it; returns undefined if no baseline yet
  • takeSnapshot() captures post-agent state after runAgent() returns
  • Agent no longer sees its own commits and file edits reported as human activity in the next turn

Related Issues

Fixes #234

Co-Authored-By: Claude noreply@anthropic.com

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.
@shellicar shellicar added this to the 1.0 milestone Apr 10, 2026
@shellicar shellicar added the bug Something isn't working label Apr 10, 2026
@shellicar shellicar self-assigned this Apr 10, 2026
@shellicar shellicar added the pkg: claude-sdk-cli The new SDK-based CLI label Apr 10, 2026
@shellicar shellicar requested a review from bananabot9000 April 10, 2026 15:47
@shellicar shellicar enabled auto-merge (squash) April 10, 2026 15:47
Copy link
Copy Markdown
Collaborator

@bananabot9000 bananabot9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

nullundefined 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>.
@shellicar shellicar merged commit 80c6c0e into main Apr 10, 2026
3 checks passed
@shellicar shellicar deleted the fix/git-state-monitor-own-changes branch April 10, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pkg: claude-sdk-cli The new SDK-based CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitStateMonitor reports the agent's own changes as human activity

2 participants