agent/pkg/agentic/resume.go
Snider f83c753277 feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As

core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00

116 lines
3.7 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
"context"
core "dappco.re/go/core"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// ResumeInput is the input for agentic_resume.
//
// input := agentic.ResumeInput{Workspace: "go-scm-1773581173", Answer: "Use the existing queue config"}
type ResumeInput struct {
Workspace string `json:"workspace"` // workspace name (e.g. "go-scm-1773581173")
Answer string `json:"answer,omitempty"` // answer to the blocked question (written to ANSWER.md)
Agent string `json:"agent,omitempty"` // override agent type (default: same as original)
DryRun bool `json:"dry_run,omitempty"` // preview without executing
}
// ResumeOutput is the output for agentic_resume.
//
// out := agentic.ResumeOutput{Success: true, Workspace: "go-scm-1773581173", Agent: "codex"}
type ResumeOutput struct {
Success bool `json:"success"`
Workspace string `json:"workspace"`
Agent string `json:"agent"`
PID int `json:"pid,omitempty"`
OutputFile string `json:"output_file,omitempty"`
Prompt string `json:"prompt,omitempty"`
}
func (s *PrepSubsystem) registerResumeTool(server *mcp.Server) {
mcp.AddTool(server, &mcp.Tool{
Name: "agentic_resume",
Description: "Resume a blocked agent workspace. Writes ANSWER.md if an answer is provided, then relaunches the agent with instructions to read it and continue.",
}, s.resume)
}
func (s *PrepSubsystem) resume(ctx context.Context, _ *mcp.CallToolRequest, input ResumeInput) (*mcp.CallToolResult, ResumeOutput, error) {
if input.Workspace == "" {
return nil, ResumeOutput{}, core.E("resume", "workspace is required", nil)
}
wsDir := core.JoinPath(WorkspaceRoot(), input.Workspace)
repoDir := core.JoinPath(wsDir, "repo")
// Verify workspace exists
if !fs.IsDir(core.JoinPath(repoDir, ".git")) {
return nil, ResumeOutput{}, core.E("resume", "workspace not found: "+input.Workspace, nil)
}
// Read current status
st, err := ReadStatus(wsDir)
if err != nil {
return nil, ResumeOutput{}, core.E("resume", "no status.json in workspace", err)
}
if st.Status != "blocked" && st.Status != "failed" && st.Status != "completed" {
return nil, ResumeOutput{}, core.E("resume", "workspace is "+st.Status+", not resumable (must be blocked, failed, or completed)", nil)
}
// Determine agent
agent := st.Agent
if input.Agent != "" {
agent = input.Agent
}
// Write ANSWER.md if answer provided
if input.Answer != "" {
answerPath := core.JoinPath(repoDir, "ANSWER.md")
content := core.Sprintf("# Answer\n\n%s\n", input.Answer)
if r := fs.Write(answerPath, content); !r.OK {
err, _ := r.Value.(error)
return nil, ResumeOutput{}, core.E("resume", "failed to write ANSWER.md", err)
}
}
// Build resume prompt — inline the task and answer, no file references
prompt := core.Concat("You are resuming previous work.\n\nORIGINAL TASK:\n", st.Task)
if input.Answer != "" {
prompt = core.Concat(prompt, "\n\nANSWER TO YOUR QUESTION:\n", input.Answer)
}
prompt = core.Concat(prompt, "\n\nContinue working. Read BLOCKED.md to see what you were stuck on. Commit when done.")
if input.DryRun {
return nil, ResumeOutput{
Success: true,
Workspace: input.Workspace,
Agent: agent,
Prompt: prompt,
}, nil
}
// Spawn agent via go-process
pid, _, err := s.spawnAgent(agent, prompt, wsDir)
if err != nil {
return nil, ResumeOutput{}, err
}
// Update status
st.Status = "running"
st.PID = pid
st.Runs++
st.Question = ""
writeStatus(wsDir, st)
return nil, ResumeOutput{
Success: true,
Workspace: input.Workspace,
Agent: agent,
PID: pid,
OutputFile: core.JoinPath(wsDir, core.Sprintf("agent-%s.log", agent)),
}, nil
}