agent/pkg/agentic/commands_workspace.go

170 lines
6 KiB
Go
Raw Permalink Normal View History

// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
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
"context"
core "dappco.re/go/core"
)
func (s *PrepSubsystem) registerWorkspaceCommands() {
c := s.Core()
c.Command("workspace/list", core.Command{Description: "List all agent workspaces with status", Action: s.cmdWorkspaceList})
c.Command("agentic:workspace/list", core.Command{Description: "List all agent workspaces with status", Action: s.cmdWorkspaceList})
c.Command("workspace/clean", core.Command{Description: "Remove completed/failed/blocked workspaces", Action: s.cmdWorkspaceClean})
c.Command("agentic:workspace/clean", core.Command{Description: "Remove completed/failed/blocked workspaces", Action: s.cmdWorkspaceClean})
c.Command("workspace/dispatch", core.Command{Description: "Dispatch an agent to work on a repo task", Action: s.cmdWorkspaceDispatch})
c.Command("agentic:workspace/dispatch", core.Command{Description: "Dispatch an agent to work on a repo task", Action: s.cmdWorkspaceDispatch})
c.Command("workspace/watch", core.Command{Description: "Watch workspaces until they complete", Action: s.cmdWorkspaceWatch})
c.Command("agentic:workspace/watch", core.Command{Description: "Watch workspaces until they complete", Action: s.cmdWorkspaceWatch})
c.Command("watch", core.Command{Description: "Watch workspaces until they complete", Action: s.cmdWorkspaceWatch})
c.Command("agentic:watch", core.Command{Description: "Watch workspaces until they complete", Action: s.cmdWorkspaceWatch})
}
func (s *PrepSubsystem) cmdWorkspaceList(_ core.Options) core.Result {
statusFiles := WorkspaceStatusPaths()
count := 0
for _, sf := range statusFiles {
workspaceDir := core.PathDir(sf)
workspaceName := WorkspaceName(workspaceDir)
result := ReadStatusResult(workspaceDir)
workspaceStatus, ok := workspaceStatusValue(result)
if !ok {
continue
}
core.Print(nil, " %-8s %-8s %-10s %s", workspaceStatus.Status, workspaceStatus.Agent, workspaceStatus.Repo, workspaceName)
count++
}
if count == 0 {
core.Print(nil, " no workspaces")
}
return core.Result{OK: true}
}
func (s *PrepSubsystem) cmdWorkspaceClean(options core.Options) core.Result {
workspaceRoot := WorkspaceRoot()
filesystem := s.Core().Fs()
filter := options.String("_arg")
if filter == "" {
filter = "all"
}
if !workspaceCleanFilterValid(filter) {
core.Print(nil, "usage: core-agent workspace clean [all|completed|failed|blocked]")
return core.Result{Value: core.E("agentic.cmdWorkspaceClean", core.Concat("unknown filter: ", filter), nil), OK: false}
}
statusFiles := WorkspaceStatusPaths()
var toRemove []string
for _, sf := range statusFiles {
workspaceDir := core.PathDir(sf)
workspaceName := WorkspaceName(workspaceDir)
result := ReadStatusResult(workspaceDir)
workspaceStatus, ok := workspaceStatusValue(result)
if !ok {
continue
}
status := workspaceStatus.Status
switch filter {
case "all":
if status == "completed" || status == "failed" || status == "blocked" || status == "merged" || status == "ready-for-review" {
toRemove = append(toRemove, workspaceName)
}
case "completed":
if status == "completed" || status == "merged" || status == "ready-for-review" {
toRemove = append(toRemove, workspaceName)
}
case "failed":
if status == "failed" {
toRemove = append(toRemove, workspaceName)
}
case "blocked":
if status == "blocked" {
toRemove = append(toRemove, workspaceName)
}
}
}
if len(toRemove) == 0 {
core.Print(nil, "nothing to clean")
return core.Result{OK: true}
}
for _, name := range toRemove {
path := core.JoinPath(workspaceRoot, name)
filesystem.DeleteAll(path)
core.Print(nil, " removed %s", name)
}
core.Print(nil, "\n %d workspaces removed", len(toRemove))
return core.Result{OK: true}
}
func workspaceCleanFilterValid(filter string) bool {
switch filter {
case "all", "completed", "failed", "blocked":
return true
default:
return false
}
}
// input := DispatchInput{Repo: "go-io", Task: "Fix the failing tests", Issue: 12}
func (s *PrepSubsystem) cmdWorkspaceDispatch(options core.Options) core.Result {
input := workspaceDispatchInputFromOptions(options)
if input.Repo == "" {
core.Print(nil, "usage: core-agent workspace dispatch <repo> --task=\"...\" --issue=N|--pr=N|--branch=X [--agent=codex] [--template=coding] [--plan-template=bug-fix] [--persona=code/reviewer] [--tag=v0.8.0] [--dry-run]")
return core.Result{Value: core.E("agentic.cmdWorkspaceDispatch", "repo is required", nil), OK: false}
}
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
_, out, err := s.dispatch(context.Background(), nil, input)
if err != nil {
core.Print(nil, "dispatch failed: %s", err.Error())
return core.Result{Value: err, OK: false}
}
agent := out.Agent
if agent == "" {
agent = "codex"
}
core.Print(nil, "dispatched %s to %s", agent, input.Repo)
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
if out.WorkspaceDir != "" {
core.Print(nil, " workspace: %s", out.WorkspaceDir)
}
if out.PID > 0 {
core.Print(nil, " pid: %d", out.PID)
}
return core.Result{OK: true}
}
func (s *PrepSubsystem) cmdWorkspaceWatch(options core.Options) core.Result {
watchOptions := core.NewOptions(options.Items()...)
if watchOptions.String("workspace") == "" && len(optionStringSliceValue(watchOptions, "workspaces")) == 0 {
if workspace := optionStringValue(options, "_arg"); workspace != "" {
watchOptions.Set("workspace", workspace)
}
}
input := watchInputFromOptions(watchOptions)
_, output, err := s.watch(s.commandContext(), nil, input)
if err != nil {
core.Print(nil, "error: %v", err)
return core.Result{Value: err, OK: false}
}
core.Print(nil, "completed: %d", len(output.Completed))
core.Print(nil, "failed: %d", len(output.Failed))
core.Print(nil, "duration: %s", output.Duration)
return core.Result{Value: output, OK: output.Success}
}
func workspaceDispatchInputFromOptions(options core.Options) DispatchInput {
dispatchOptions := core.NewOptions(options.Items()...)
if dispatchOptions.String("repo") == "" {
if repo := optionStringValue(options, "_arg", "repo"); repo != "" {
dispatchOptions.Set("repo", repo)
}
}
return dispatchInputFromOptions(dispatchOptions)
}