diff --git a/pkg/agentic/commands.go b/pkg/agentic/commands.go index e6f4da3..bd7bc33 100644 --- a/pkg/agentic/commands.go +++ b/pkg/agentic/commands.go @@ -13,7 +13,7 @@ import ( // registerCommands adds agentic CLI commands to Core's command tree. func (s *PrepSubsystem) registerCommands(ctx context.Context) { - s.commandCtx = ctx + s.startupContext = ctx c := s.Core() c.Command("run/task", core.Command{Description: "Run a single task end-to-end", Action: s.cmdRunTask}) c.Command("run/orchestrator", core.Command{Description: "Run the queue orchestrator (standalone, no MCP)", Action: s.cmdOrchestrator}) @@ -28,8 +28,8 @@ func (s *PrepSubsystem) registerCommands(ctx context.Context) { // ctx := s.commandContext() // _ = ctx.Err() func (s *PrepSubsystem) commandContext() context.Context { - if s.commandCtx != nil { - return s.commandCtx + if s.startupContext != nil { + return s.startupContext } return context.Background() } diff --git a/pkg/agentic/commands_forge.go b/pkg/agentic/commands_forge.go index cf6da53..847c599 100644 --- a/pkg/agentic/commands_forge.go +++ b/pkg/agentic/commands_forge.go @@ -176,7 +176,7 @@ func (s *PrepSubsystem) cmdIssueCreate(options core.Options) core.Result { return core.Result{Value: core.E("agentic.cmdIssueCreate", "repo and title are required", nil), OK: false} } - createOpts := &forge_types.CreateIssueOption{Title: title, Body: body, Ref: ref} + createOptions := &forge_types.CreateIssueOption{Title: title, Body: body, Ref: ref} if milestone != "" { var milestones []forge_types.Milestone @@ -184,14 +184,14 @@ func (s *PrepSubsystem) cmdIssueCreate(options core.Options) core.Result { if err == nil { for _, m := range milestones { if m.Title == milestone { - createOpts.Milestone = m.ID + createOptions.Milestone = m.ID break } } } } if assignee != "" { - createOpts.Assignees = []string{assignee} + createOptions.Assignees = []string{assignee} } if labels != "" { labelNames := core.Split(labels, ",") @@ -201,7 +201,7 @@ func (s *PrepSubsystem) cmdIssueCreate(options core.Options) core.Result { name = core.Trim(name) for _, l := range allLabels { if l.Name == name { - createOpts.Labels = append(createOpts.Labels, l.ID) + createOptions.Labels = append(createOptions.Labels, l.ID) break } } @@ -209,7 +209,7 @@ func (s *PrepSubsystem) cmdIssueCreate(options core.Options) core.Result { } } - issue, err := s.forge.Issues.Create(ctx, forge.Params{"owner": org, "repo": repo}, createOpts) + issue, err := s.forge.Issues.Create(ctx, forge.Params{"owner": org, "repo": repo}, createOptions) if err != nil { core.Print(nil, "error: %v", err) return core.Result{Value: err, OK: false} diff --git a/pkg/agentic/commands_test.go b/pkg/agentic/commands_test.go index 1405f46..3d79ffa 100644 --- a/pkg/agentic/commands_test.go +++ b/pkg/agentic/commands_test.go @@ -660,7 +660,7 @@ func TestCommands_CmdRunTask_Bad_MissingArgs(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdRunTask(core.NewOptions()) assert.False(t, r.OK) } @@ -669,7 +669,7 @@ func TestCommands_CmdRunTask_Bad_MissingTask(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdRunTask(core.NewOptions(core.Option{Key: "repo", Value: "go-io"})) assert.False(t, r.OK) } @@ -678,7 +678,7 @@ func TestCommands_CmdOrchestrator_Good_CancelledCtx(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithCancel(context.Background()) cancel() // cancel immediately - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdOrchestrator(core.NewOptions()) assert.True(t, r.OK) } @@ -742,7 +742,7 @@ func TestCommands_CmdOrchestrator_Bad_DoneContext(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-1*time.Second)) defer cancel() - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdOrchestrator(core.NewOptions()) assert.True(t, r.OK) // returns OK after ctx.Done() } @@ -751,7 +751,7 @@ func TestCommands_CmdOrchestrator_Ugly_CancelledImmediately(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithCancel(context.Background()) cancel() - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdOrchestrator(core.NewOptions()) assert.True(t, r.OK) // exits immediately when context is already cancelled } @@ -795,7 +795,7 @@ func TestCommands_CmdRunTask_Good_DefaultsApplied(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - s.commandCtx = ctx + s.startupContext = ctx // Provide repo + task but omit agent + org — tests that defaults (codex, core) are applied r := s.cmdRunTask(core.NewOptions( core.Option{Key: "repo", Value: "go-io"}, @@ -809,7 +809,7 @@ func TestCommands_CmdRunTask_Ugly_MixedIssueString(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdRunTask(core.NewOptions( core.Option{Key: "repo", Value: "go-io"}, core.Option{Key: "task", Value: "fix it"}, @@ -839,7 +839,7 @@ func TestCommands_CommandContext_Ugly_CancelledStartupContext(t *testing.T) { s, _ := testPrepWithCore(t, nil) ctx, cancel := context.WithCancel(context.Background()) cancel() // pre-cancelled - s.commandCtx = ctx + s.startupContext = ctx r := s.cmdOrchestrator(core.NewOptions()) assert.True(t, r.OK) } diff --git a/pkg/agentic/dispatch_sync.go b/pkg/agentic/dispatch_sync.go index 0e9ae19..287114c 100644 --- a/pkg/agentic/dispatch_sync.go +++ b/pkg/agentic/dispatch_sync.go @@ -45,10 +45,10 @@ func (s *PrepSubsystem) DispatchSync(ctx context.Context, input DispatchSyncInpu Issue: input.Issue, } - prepCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) + prepContext, cancel := context.WithTimeout(ctx, 5*time.Minute) defer cancel() - _, prepOut, err := s.prepWorkspace(prepCtx, nil, prepInput) + _, prepOut, err := s.prepWorkspace(prepContext, nil, prepInput) if err != nil { return DispatchSyncResult{Err: core.E("agentic.DispatchSync", "prep workspace failed", err)} } diff --git a/pkg/agentic/prep.go b/pkg/agentic/prep.go index 996607e..100043b 100644 --- a/pkg/agentic/prep.go +++ b/pkg/agentic/prep.go @@ -29,20 +29,20 @@ type AgentOptions struct{} // core.New(core.WithService(agentic.Register)) type PrepSubsystem struct { *core.ServiceRuntime[AgentOptions] - forge *forge.Forge - forgeURL string - forgeToken string - brainURL string - brainKey string - codePath string - commandCtx context.Context - dispatchMu sync.Mutex // serialises concurrency check + spawn - drainMu sync.Mutex - pokeCh chan struct{} - frozen bool - backoff map[string]time.Time // pool → paused until - failCount map[string]int // pool → consecutive fast failures - workspaces *core.Registry[*WorkspaceStatus] // in-memory workspace state + forge *forge.Forge + forgeURL string + forgeToken string + brainURL string + brainKey string + codePath string + startupContext context.Context + dispatchMu sync.Mutex // serialises concurrency check + spawn + drainMu sync.Mutex + pokeCh chan struct{} + frozen bool + backoff map[string]time.Time // pool → paused until + failCount map[string]int // pool → consecutive fast failures + workspaces *core.Registry[*WorkspaceStatus] // in-memory workspace state } var _ coremcp.Subsystem = (*PrepSubsystem)(nil) @@ -822,8 +822,8 @@ func (s *PrepSubsystem) pullWikiContent(ctx context.Context, org, repo string) s if name == "" { name = meta.Title } - page, pErr := s.forge.Wiki.GetPage(ctx, org, repo, name) - if pErr != nil || page.ContentBase64 == "" { + page, pageErr := s.forge.Wiki.GetPage(ctx, org, repo, name) + if pageErr != nil || page.ContentBase64 == "" { continue } content, _ := base64.StdEncoding.DecodeString(page.ContentBase64) diff --git a/pkg/agentic/remote.go b/pkg/agentic/remote.go index 5d634d9..09c16a7 100644 --- a/pkg/agentic/remote.go +++ b/pkg/agentic/remote.go @@ -82,7 +82,7 @@ func (s *PrepSubsystem) dispatchRemote(ctx context.Context, _ *mcp.CallToolReque callParams["variables"] = input.Variables } - rpcReq := map[string]any{ + rpcRequest := map[string]any{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", @@ -91,7 +91,7 @@ func (s *PrepSubsystem) dispatchRemote(ctx context.Context, _ *mcp.CallToolReque "arguments": callParams, }, } - body := []byte(core.JSONMarshalString(rpcReq)) + body := []byte(core.JSONMarshalString(rpcRequest)) url := core.Sprintf("http://%s/mcp", addr) @@ -144,7 +144,7 @@ func (s *PrepSubsystem) dispatchRemote(ctx context.Context, _ *mcp.CallToolReque Agent: input.Agent, } - var rpcResp struct { + var rpcResponse struct { Result struct { Content []struct { Text string `json:"text"` @@ -154,13 +154,13 @@ func (s *PrepSubsystem) dispatchRemote(ctx context.Context, _ *mcp.CallToolReque Message string `json:"message"` } `json:"error"` } - if r := core.JSONUnmarshal(result, &rpcResp); r.OK { - if rpcResp.Error != nil { + if r := core.JSONUnmarshal(result, &rpcResponse); r.OK { + if rpcResponse.Error != nil { output.Success = false - output.Error = rpcResp.Error.Message - } else if len(rpcResp.Result.Content) > 0 { + output.Error = rpcResponse.Error.Message + } else if len(rpcResponse.Result.Content) > 0 { var dispatchOut DispatchOutput - if r := core.JSONUnmarshalString(rpcResp.Result.Content[0].Text, &dispatchOut); r.OK { + if r := core.JSONUnmarshalString(rpcResponse.Result.Content[0].Text, &dispatchOut); r.OK { output.Success = dispatchOut.Success output.WorkspaceDir = dispatchOut.WorkspaceDir output.PID = dispatchOut.PID diff --git a/pkg/agentic/remote_status.go b/pkg/agentic/remote_status.go index da94b71..8d65021 100644 --- a/pkg/agentic/remote_status.go +++ b/pkg/agentic/remote_status.go @@ -63,7 +63,7 @@ func (s *PrepSubsystem) statusRemote(ctx context.Context, _ *mcp.CallToolRequest }, nil } - rpcReq := map[string]any{ + rpcRequest := map[string]any{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", @@ -72,7 +72,7 @@ func (s *PrepSubsystem) statusRemote(ctx context.Context, _ *mcp.CallToolRequest "arguments": map[string]any{}, }, } - body := []byte(core.JSONMarshalString(rpcReq)) + body := []byte(core.JSONMarshalString(rpcRequest)) callResult := mcpCallResult(ctx, url, token, sessionID, body) if !callResult.OK { @@ -99,7 +99,7 @@ func (s *PrepSubsystem) statusRemote(ctx context.Context, _ *mcp.CallToolRequest Host: input.Host, } - var rpcResp struct { + var rpcResponse struct { Result struct { Content []struct { Text string `json:"text"` @@ -110,19 +110,19 @@ func (s *PrepSubsystem) statusRemote(ctx context.Context, _ *mcp.CallToolRequest Message string `json:"message"` } `json:"error"` } - if r := core.JSONUnmarshal(result, &rpcResp); !r.OK { + if r := core.JSONUnmarshal(result, &rpcResponse); !r.OK { output.Success = false output.Error = "failed to parse response" return nil, output, nil } - if rpcResp.Error != nil { + if rpcResponse.Error != nil { output.Success = false - output.Error = rpcResp.Error.Message + output.Error = rpcResponse.Error.Message return nil, output, nil } - if len(rpcResp.Result.Content) > 0 { + if len(rpcResponse.Result.Content) > 0 { var statusOut StatusOutput - if r := core.JSONUnmarshalString(rpcResp.Result.Content[0].Text, &statusOut); r.OK { + if r := core.JSONUnmarshalString(rpcResponse.Result.Content[0].Text, &statusOut); r.OK { output.Stats = statusOut } } diff --git a/pkg/agentic/transport.go b/pkg/agentic/transport.go index 25174fc..e8ae088 100644 --- a/pkg/agentic/transport.go +++ b/pkg/agentic/transport.go @@ -231,7 +231,7 @@ func mcpInitialize(ctx context.Context, url, token string) (string, error) { } func mcpInitializeResult(ctx context.Context, url, token string) core.Result { - initReq := map[string]any{ + initializeRequest := map[string]any{ "jsonrpc": "2.0", "id": 1, "method": "initialize", @@ -245,7 +245,7 @@ func mcpInitializeResult(ctx context.Context, url, token string) core.Result { }, } - body := core.JSONMarshalString(initReq) + body := core.JSONMarshalString(initializeRequest) req, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(body)) if err != nil { return core.Result{Value: core.E("mcpInitialize", "create request", err), OK: false} @@ -268,18 +268,18 @@ func mcpInitializeResult(ctx context.Context, url, token string) core.Result { drainSSE(resp) // Send initialised notification - notif := core.JSONMarshalString(map[string]any{ + notification := core.JSONMarshalString(map[string]any{ "jsonrpc": "2.0", "method": "notifications/initialized", }) - notifReq, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(notif)) + notificationRequest, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(notification)) if err != nil { return core.Result{Value: core.E("mcpInitialize", "create notification request", err), OK: false} } - mcpHeaders(notifReq, token, sessionID) - notifResp, err := defaultClient.Do(notifReq) + mcpHeaders(notificationRequest, token, sessionID) + notificationResponse, err := defaultClient.Do(notificationRequest) if err == nil { - notifResp.Body.Close() + notificationResponse.Body.Close() } return core.Result{Value: sessionID, OK: true} diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 12942a6..487c422 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -160,7 +160,7 @@ func (m *Subsystem) RegisterTools(server *mcp.Server) { // service.Start(ctx) func (m *Subsystem) Start(ctx context.Context) { - loopCtx, cancel := context.WithCancel(ctx) + loopContext, cancel := context.WithCancel(ctx) m.cancel = cancel core.Info("monitor: started (interval=%s)", m.interval) @@ -168,7 +168,7 @@ func (m *Subsystem) Start(ctx context.Context) { m.wg.Add(1) go func() { defer m.wg.Done() - m.loop(loopCtx) + m.loop(loopContext) }() }