agent/pkg/agentic/events.go
Snider e66ea0512b fix: address re-review findings — nil pointer, races, curl, clone error
Important:
- Fix nil pointer dereference on resp.StatusCode when err!=nil (8 sites)
- Replace curl shell-out with net/http in monitor inbox check
- Handle clone failure in prep.go (was silently swallowed)
- Use GitHubOrg() instead of hardcoded "dAppCore"

Medium:
- Fix JSONL append race (read+write → os.OpenFile O_APPEND)
- Remove dead google/mcp/ directory

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 19:27:44 +00:00

49 lines
1.1 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.
func emitCompletionEvent(agent, workspace string) {
eventsFile := filepath.Join(WorkspaceRoot(), "events.jsonl")
event := CompletionEvent{
Type: "agent_completed",
Agent: agent,
Workspace: workspace,
Status: "completed",
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'))
}