agent/pkg/agentic/handlers.go
Snider 537226bd4d feat: AX v0.8.0 upgrade — Core features + quality gates
AX Quality Gates (RFC-025):
- Eliminate os/exec from all test + production code (12+ files)
- Eliminate encoding/json from all test files (15 files, 66 occurrences)
- Eliminate os from all test files except TestMain (Go runtime contract)
- Eliminate path/filepath, net/url from all files
- String concat: 39 violations replaced with core.Concat()
- Test naming AX-7: 264 test functions renamed across all 6 packages
- Example test 1:1 coverage complete

Core Features Adopted:
- Task Composition: agent.completion pipeline (QA → PR → Verify → Ingest → Poke)
- PerformAsync: completion pipeline runs with WaitGroup + progress tracking
- Config: agents.yaml loaded once, feature flags (auto-qa/pr/merge/ingest)
- Named Locks: c.Lock("drain") for queue serialisation
- Registry: workspace state with cross-package QUERY access
- QUERY: c.QUERY(WorkspaceQuery{Status: "running"}) for cross-service queries
- Action descriptions: 25+ Actions self-documenting
- Data mounts: prompts/tasks/flows/personas/workspaces via c.Data()
- Content Actions: agentic.prompt/task/flow/persona callable via IPC
- Drive endpoints: forge + brain registered with tokens
- Drive REST helpers: DriveGet/DrivePost/DriveDo for Drive-aware HTTP
- HandleIPCEvents: auto-discovered by WithService (no manual wiring)
- Entitlement: frozen-queue gate on write Actions
- CLI dispatch: workspace dispatch wired to real dispatch method
- CLI: --quiet/-q and --debug/-d global flags
- CLI: banner, version, check (with service/action/command counts), env
- main.go: minimal — 5 services + c.Run(), no os import
- cmd tests: 84.2% coverage (was 0%)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 06:38:02 +00:00

74 lines
2.1 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
// IPC handler for agent lifecycle events.
// Auto-discovered by Core's WithService via the HandleIPCEvents interface.
// No manual RegisterHandlers call needed — Core wires it during service registration.
package agentic
import (
"dappco.re/go/agent/pkg/messages"
core "dappco.re/go/core"
)
// HandleIPCEvents implements Core's IPC handler interface.
// Auto-registered by WithService — no manual wiring needed.
//
// Handles:
//
// AgentCompleted → ingest findings + poke queue
// PokeQueue → drain queue
//
// The completion pipeline (QA → PR → Verify) runs via the "agent.completion" Task,
// triggered by PerformAsync in onAgentComplete. These handlers cover cross-cutting
// concerns that fire on ALL completions.
func (s *PrepSubsystem) HandleIPCEvents(c *core.Core, msg core.Message) core.Result {
switch ev := msg.(type) {
case messages.AgentCompleted:
// Ingest findings (feature-flag gated)
if c.Config().Enabled("auto-ingest") {
if wsDir := resolveWorkspace(ev.Workspace); wsDir != "" {
s.ingestFindings(wsDir)
}
}
// Poke queue to fill freed slot
s.Poke()
case messages.PokeQueue:
s.drainQueue()
_ = ev // signal message, no fields
}
return core.Result{OK: true}
}
// resolveWorkspace converts a workspace name back to the full path.
//
// resolveWorkspace("core/go-io/task-5") → "/Users/snider/Code/.core/workspace/core/go-io/task-5"
func resolveWorkspace(name string) string {
wsRoot := WorkspaceRoot()
path := core.JoinPath(wsRoot, name)
if fs.IsDir(path) {
return path
}
return ""
}
// findWorkspaceByPR finds a workspace directory by repo name and branch.
// Scans running/completed workspaces for a matching repo+branch combination.
func findWorkspaceByPR(repo, branch string) string {
wsRoot := WorkspaceRoot()
old := core.PathGlob(core.JoinPath(wsRoot, "*", "status.json"))
deep := core.PathGlob(core.JoinPath(wsRoot, "*", "*", "*", "status.json"))
for _, path := range append(old, deep...) {
wsDir := core.PathDir(path)
st, err := ReadStatus(wsDir)
if err != nil {
continue
}
if st.Repo == repo && st.Branch == branch {
return wsDir
}
}
return ""
}