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>
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
core "dappco.re/go/core"
|
|
)
|
|
|
|
// autoCreatePR pushes the agent's branch and creates a PR on Forge
|
|
// if the agent made any commits beyond the initial clone.
|
|
func (s *PrepSubsystem) autoCreatePR(wsDir string) {
|
|
st, err := ReadStatus(wsDir)
|
|
if err != nil || st.Branch == "" || st.Repo == "" {
|
|
return
|
|
}
|
|
|
|
ctx := context.Background()
|
|
repoDir := core.JoinPath(wsDir, "repo")
|
|
|
|
// PRs target dev — agents never merge directly to main
|
|
base := "dev"
|
|
|
|
out := s.gitOutput(ctx, repoDir, "log", "--oneline", core.Concat("origin/", base, "..HEAD"))
|
|
if out == "" {
|
|
return
|
|
}
|
|
|
|
commitCount := len(core.Split(out, "\n"))
|
|
|
|
org := st.Org
|
|
if org == "" {
|
|
org = "core"
|
|
}
|
|
|
|
// Push the branch to forge
|
|
forgeRemote := core.Sprintf("ssh://git@forge.lthn.ai:2223/%s/%s.git", org, st.Repo)
|
|
if !s.gitCmdOK(ctx, repoDir, "push", forgeRemote, st.Branch) {
|
|
if st2, err := ReadStatus(wsDir); err == nil {
|
|
st2.Question = "PR push failed"
|
|
writeStatus(wsDir, st2)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Create PR via Forge API
|
|
title := core.Sprintf("[agent/%s] %s", st.Agent, truncate(st.Task, 60))
|
|
body := s.buildAutoPRBody(st, commitCount)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
prURL, _, err := s.forgeCreatePR(ctx, org, st.Repo, st.Branch, base, title, body)
|
|
if err != nil {
|
|
if st2, err := ReadStatus(wsDir); err == nil {
|
|
st2.Question = core.Sprintf("PR creation failed: %v", err)
|
|
writeStatus(wsDir, st2)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Update status with PR URL
|
|
if st2, err := ReadStatus(wsDir); err == nil {
|
|
st2.PRURL = prURL
|
|
writeStatus(wsDir, st2)
|
|
}
|
|
}
|
|
|
|
func (s *PrepSubsystem) buildAutoPRBody(st *WorkspaceStatus, commits int) string {
|
|
b := core.NewBuilder()
|
|
b.WriteString("## Task\n\n")
|
|
b.WriteString(st.Task)
|
|
b.WriteString("\n\n")
|
|
if st.Issue > 0 {
|
|
b.WriteString(core.Sprintf("Closes #%d\n\n", st.Issue))
|
|
}
|
|
b.WriteString(core.Sprintf("**Agent:** %s\n", st.Agent))
|
|
b.WriteString(core.Sprintf("**Commits:** %d\n", commits))
|
|
b.WriteString(core.Sprintf("**Branch:** `%s`\n", st.Branch))
|
|
b.WriteString("\n---\n")
|
|
b.WriteString("Auto-created by core-agent dispatch system.\n")
|
|
b.WriteString("Co-Authored-By: Virgil <virgil@lethean.io>\n")
|
|
return b.String()
|
|
}
|
|
|
|
func truncate(s string, max int) string {
|
|
if len(s) <= max {
|
|
return s
|
|
}
|
|
return core.Concat(s[:max], "...")
|
|
}
|