Slice 3: activity feed and active project (SSE + MCP tools)
Add internal/activity (thread-safe active project + bounded event feed with subscriber fan-out). Service exposes active-project/activity methods and takes the feed. New MCP tools get_active_project/set_active_project/get_activity and HTTP endpoints GET/POST /api/active-project, /api/activity, and /events (SSE). New <activity-feed> component updates live via EventSource; <repo-list> sets the active project on selection. Verified end-to-end in the running app: user actions push live events and set the active project (actor=user), all readable by Claude over MCP. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
|
||||
"gitmanager/internal/activity"
|
||||
"gitmanager/internal/git"
|
||||
"gitmanager/internal/repos"
|
||||
"gitmanager/internal/service"
|
||||
@@ -41,7 +42,7 @@ func TestMCPRoundTrip(t *testing.T) {
|
||||
scanner := repos.NewScanner(g, log, []string{root}, 3, nil, time.Minute, false)
|
||||
scanner.Refresh(context.Background())
|
||||
|
||||
svc := service.New(g, scanner.Index)
|
||||
svc := service.New(g, scanner.Index, activity.New(log, 200))
|
||||
srv := NewServer(svc, "test")
|
||||
|
||||
// Wire an in-memory client<->server session.
|
||||
@@ -100,6 +101,64 @@ func TestMCPRoundTrip(t *testing.T) {
|
||||
if !res.IsError {
|
||||
t.Fatalf("expected IsError for unknown repo, got success")
|
||||
}
|
||||
|
||||
// active project starts empty.
|
||||
res, err = cs.CallTool(ctx, &mcpsdk.CallToolParams{Name: "get_active_project"})
|
||||
if err != nil {
|
||||
t.Fatalf("get_active_project: %v", err)
|
||||
}
|
||||
var ap struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
decodeResult(t, res, &ap)
|
||||
if ap.Path != "" {
|
||||
t.Fatalf("expected empty active project, got %q", ap.Path)
|
||||
}
|
||||
|
||||
// set_active_project to our repo, then read it back.
|
||||
res, err = cs.CallTool(ctx, &mcpsdk.CallToolParams{
|
||||
Name: "set_active_project",
|
||||
Arguments: map[string]any{"path": states[0].Path},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("set_active_project: %v", err)
|
||||
}
|
||||
if res.IsError {
|
||||
t.Fatalf("set_active_project returned tool error: %+v", res.Content)
|
||||
}
|
||||
res, _ = cs.CallTool(ctx, &mcpsdk.CallToolParams{Name: "get_active_project"})
|
||||
decodeResult(t, res, &ap)
|
||||
if ap.Path != states[0].Path {
|
||||
t.Fatalf("active project = %q, want %q", ap.Path, states[0].Path)
|
||||
}
|
||||
|
||||
// setting an unknown project is a tool error.
|
||||
res, err = cs.CallTool(ctx, &mcpsdk.CallToolParams{
|
||||
Name: "set_active_project",
|
||||
Arguments: map[string]any{"path": filepath.Join(root, "nope")},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("set_active_project(bad) protocol error: %v", err)
|
||||
}
|
||||
if !res.IsError {
|
||||
t.Fatalf("expected IsError for unknown active project")
|
||||
}
|
||||
|
||||
// the activity feed should now contain the active-project-changed event.
|
||||
res, _ = cs.CallTool(ctx, &mcpsdk.CallToolParams{Name: "get_activity"})
|
||||
var act struct {
|
||||
Events []activity.Event `json:"events"`
|
||||
}
|
||||
decodeResult(t, res, &act)
|
||||
found := false
|
||||
for _, ev := range act.Events {
|
||||
if ev.Kind == "active-project-changed" && ev.Repo == states[0].Path && ev.Actor == activity.ActorClaude {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected an active-project-changed event by claude, got %+v", act.Events)
|
||||
}
|
||||
}
|
||||
|
||||
// decodeResult unmarshals the JSON text content of a tool result into v.
|
||||
|
||||
Reference in New Issue
Block a user