diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-06-03 23:01:39 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-06-03 23:01:39 +0000 |
| commit | 68cf1e24dd2ca2612b72babc4b35280cd3512f92 (patch) | |
| tree | 14b73f21570a2f42ae729ca7e9676de6628d6819 /internal/event | |
| parent | b28cfc6ff288d083f6c8e9c055b69bfcadbceccc (diff) | |
| parent | 7388337d3be5cc7f65ef547e30b2e39884dd165b (diff) | |
merge: integrate oss branch — budget gating, MCP back-channel, events, loopback-only bind
Key features from OSS branch:
- Budget gating: rolling per-provider spend caps with BUDGET_EXCEEDED task state
- Agent MCP back-channel: runners mint tokens; /mcp endpoint resolves them
- Chatbot MCP server at /chatbot/mcp (requires api_token in config)
- Event timeline: unified event stream replacing ad-hoc question/summary flows
- Loopback-only default bind (127.0.0.1:8484); external_bind_allowed=true to expose
- repository_url required on task creation (enforces traceability)
- Auto-checker: spawns verification task after each execution
Conflict resolutions:
- serve.go: keep cfg.Runners.XEnabled() conditional registration from main + agentRegistry from oss
- config.go: keep RunnersConfig from main + BudgetConfig/ExternalBindAllowed from oss
- server.go: handleStaticFiles (base-path rewrite) kept; deduplicated duplicate from both sides
- executor/claude.go: accepted oss deletion (ClaudeRunner replaced by ContainerRunner)
- container_test.go: added noopChannel + AgentChannel parameter to Run call
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/event')
| -rw-r--r-- | internal/event/event.go | 50 | ||||
| -rw-r--r-- | internal/event/event_test.go | 42 |
2 files changed, 92 insertions, 0 deletions
diff --git a/internal/event/event.go b/internal/event/event.go new file mode 100644 index 0000000..2573fde --- /dev/null +++ b/internal/event/event.go @@ -0,0 +1,50 @@ +// Package event defines the Event type and canonical kinds/actors for the +// task observability stream. Events are immutable, per-task, monotonically +// sequenced records persisted by internal/storage. +package event + +import ( + "encoding/json" + "time" +) + +// Kind enumerates the canonical event types. +type Kind string + +const ( + KindStateChange Kind = "state_change" + KindAgentMessage Kind = "agent_message" + KindClarificationRequest Kind = "clarification_request" + KindClarificationAnswer Kind = "clarification_answer" + KindHumanMessage Kind = "human_message" + KindSummary Kind = "summary" + KindCommitMade Kind = "commit_made" + KindSubtaskSpawned Kind = "subtask_spawned" + KindCostReport Kind = "cost_report" + KindExecutionStarted Kind = "execution_started" + KindExecutionEnded Kind = "execution_ended" +) + +// Actor identifies the originator of an event. +type Actor string + +const ( + ActorAgent Actor = "agent" + ActorUser Actor = "user" + ActorChatbot Actor = "chatbot" + ActorSystem Actor = "system" + ActorWebhook Actor = "webhook" +) + +// Event is a single timestamped record on a task's audit/observability stream. +// Once written, events are append-only — the seq column is per-task monotonic +// and assigned by the storage layer on insert. +type Event struct { + ID string `json:"id"` + TaskID string `json:"task_id"` + Seq int64 `json:"seq"` + Timestamp time.Time `json:"timestamp"` + Kind Kind `json:"kind"` + Actor Actor `json:"actor"` + Payload json.RawMessage `json:"payload"` +} diff --git a/internal/event/event_test.go b/internal/event/event_test.go new file mode 100644 index 0000000..a2cd143 --- /dev/null +++ b/internal/event/event_test.go @@ -0,0 +1,42 @@ +package event + +import ( + "encoding/json" + "testing" + "time" +) + +func TestEvent_JSONRoundTrip(t *testing.T) { + original := Event{ + ID: "evt-1", + TaskID: "task-1", + Seq: 42, + Timestamp: time.Date(2026, 5, 22, 12, 0, 0, 0, time.UTC), + Kind: KindClarificationRequest, + Actor: ActorAgent, + Payload: json.RawMessage(`{"question":"which env?"}`), + } + + data, err := json.Marshal(original) + if err != nil { + t.Fatalf("marshal: %v", err) + } + + var got Event + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("unmarshal: %v", err) + } + + if got.ID != original.ID || got.TaskID != original.TaskID || got.Seq != original.Seq { + t.Errorf("id/task/seq mismatch: got %+v want %+v", got, original) + } + if !got.Timestamp.Equal(original.Timestamp) { + t.Errorf("timestamp mismatch: got %v want %v", got.Timestamp, original.Timestamp) + } + if got.Kind != original.Kind || got.Actor != original.Actor { + t.Errorf("kind/actor mismatch: got %v/%v want %v/%v", got.Kind, got.Actor, original.Kind, original.Actor) + } + if string(got.Payload) != string(original.Payload) { + t.Errorf("payload mismatch: got %s want %s", got.Payload, original.Payload) + } +} |
