mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
48ab492f49
Adds real-time git status watching for workspace agents, so the frontend
can subscribe over WebSocket and show
git file changes in near real-time.
1. Subscription is scoped to a **chat** via `GET
/api/experimental/chats/{chat}/git/watch`.
2. The workspace agent automatically determines which paths to watch
based on tool calls made by the chat (and its ancestor chats).
3. Workspace agent polls subscribed repo working trees on a 30s
interval, on tools calls, and on explicit `refresh` from the client.
4. Scans are rate-limited to at most once per second.
5. Edited paths are tracked **in-memory** inside the workspace agent.
There is no database persistence — state is lost on agent restart. This
will be addresses in a future PR.
6. Messages sent over WebSocket include a full-repo snapshot (unified
diff, branch, origin). A new message is emitted only when the snapshot
changes.
This PR was implemented with AI with me closely controlling what it's
doing. The code follows a plan file that was updated continuously during
implementation. Here's the file if you'd like to see it:
[project.md](https://gist.github.com/hugodutka/8722cf80c92f8a56555f7bc595b770e2).
It reflects the current state of the PR.
36 lines
905 B
Go
36 lines
905 B
Go
package agentgit
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/coder/coder/v2/codersdk/workspacesdk"
|
|
)
|
|
|
|
// ExtractChatContext reads chat identity headers from the request.
|
|
// Returns zero values if headers are absent (non-chat request).
|
|
func ExtractChatContext(r *http.Request) (chatID uuid.UUID, ancestorIDs []uuid.UUID, ok bool) {
|
|
raw := r.Header.Get(workspacesdk.CoderChatIDHeader)
|
|
if raw == "" {
|
|
return uuid.Nil, nil, false
|
|
}
|
|
chatID, err := uuid.Parse(raw)
|
|
if err != nil {
|
|
return uuid.Nil, nil, false
|
|
}
|
|
rawAncestors := r.Header.Get(workspacesdk.CoderAncestorChatIDsHeader)
|
|
if rawAncestors != "" {
|
|
var ids []string
|
|
if err := json.Unmarshal([]byte(rawAncestors), &ids); err == nil {
|
|
for _, s := range ids {
|
|
if id, err := uuid.Parse(s); err == nil {
|
|
ancestorIDs = append(ancestorIDs, id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return chatID, ancestorIDs, true
|
|
}
|