loop: auto-commit changes when saving in diff view
What I've done is create a git commit whenever the user edits things,
and amend if possible. The existing detection logic pushes the commits
to the host, BUT, I had to do some plumbing to make that happen. The
agent state machine would be out of sorts if I did this (since we're
doing things outside of the loop), but, I didn't tell it, so... it's ok!
If the user has the agent running when editing, everyone can get
confused. There's no atomicity for the git operations, etc.
I suspect in practice this will all be as fine as everything else is.
I'm not running the autoformatters. That's a weird editing experience.
The alternative was to do what the diff comments does, and let the agent
deal with the changes by sending it a message. I chose not to do that:
first of all, I want the push to happen fast, since I don't like losing
user data. Second, the latency on an operation is distracting sometimes,
and sometimes what I do next is just cherrypick my changes over, and I'm
not interested in the pedantry of the agent and the code formatters and
so forth. If they were faster, maybe.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: sec50af415124810bk
diff --git a/loop/agent.go b/loop/agent.go
index 98925e2..cb22b84 100644
--- a/loop/agent.go
+++ b/loop/agent.go
@@ -104,6 +104,9 @@
// SessionID returns the unique session identifier.
SessionID() string
+ // DetectGitChanges checks for new git commits and pushes them if found
+ DetectGitChanges(ctx context.Context)
+
// OutstandingLLMCallCount returns the number of outstanding LLM calls.
OutstandingLLMCallCount() int
@@ -1417,7 +1420,18 @@
return shouldContinue && !toolEndsTurn, resp
}
-// processGitChanges checks for new git commits and runs autoformatters if needed
+// DetectGitChanges checks for new git commits and pushes them if found
+func (a *Agent) DetectGitChanges(ctx context.Context) {
+ // Check for git commits
+ _, err := a.handleGitCommits(ctx)
+ if err != nil {
+ // Just log the error, don't stop execution
+ slog.WarnContext(ctx, "Failed to check for new git commits", "error", err)
+ }
+}
+
+// processGitChanges checks for new git commits, runs autoformatters if needed, and returns any messages generated
+// This is used internally by the agent loop
func (a *Agent) processGitChanges(ctx context.Context) []string {
// Check for git commits after tool execution
newCommits, err := a.handleGitCommits(ctx)