agent/pkg/agentic/events.go
Snider 422777580b
Some checks failed
CI / test (push) Failing after 3s
fix: address Codex review findings — 2 high, 3 medium
High: Fix missed-notification bug — track completions by workspace
name instead of count, so harvest status rewrites don't suppress
future notifications. Also tracks blocked/failed terminal states.

High: Safety gate fail-closed — check ALL changed files (not just
added), reject on git diff failure instead of proceeding.

Medium: emitCompletionEvent now passes actual status (completed,
failed, blocked) instead of hardcoding "completed".

Medium/AX: Harvest no longer auto-pushes to source repos. Sets
status to ready-for-review only — pushing happens during explicit
review, not silently in the background.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-21 15:31:29 +00:00

48 lines
1.2 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
"encoding/json"
"os"
"path/filepath"
"time"
)
// CompletionEvent is emitted when a dispatched agent finishes.
// Written to ~/.core/workspace/events.jsonl as append-only log.
type CompletionEvent struct {
Type string `json:"type"`
Agent string `json:"agent"`
Workspace string `json:"workspace"`
Status string `json:"status"`
Timestamp string `json:"timestamp"`
}
// emitCompletionEvent appends a completion event to the events log.
// The plugin's hook watches this file to notify the orchestrating agent.
// Status should be the actual terminal state: completed, failed, or blocked.
func emitCompletionEvent(agent, workspace, status string) {
eventsFile := filepath.Join(WorkspaceRoot(), "events.jsonl")
event := CompletionEvent{
Type: "agent_completed",
Agent: agent,
Workspace: workspace,
Status: status,
Timestamp: time.Now().UTC().Format(time.RFC3339),
}
data, err := json.Marshal(event)
if err != nil {
return
}
// Append to events log
f, err := os.OpenFile(eventsFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return
}
defer f.Close()
f.Write(append(data, '\n'))
}