From b8e948f2d64795b3abdb076a5684863ccf55f231 Mon Sep 17 00:00:00 2001 From: Virgil Date: Mon, 30 Mar 2026 22:40:28 +0000 Subject: [PATCH] fix(ax): continue AX naming cleanup Co-Authored-By: Virgil --- pkg/agentic/commands.go | 11 ++-- pkg/agentic/dispatch.go | 4 +- pkg/agentic/dispatch_sync.go | 14 ++-- pkg/agentic/epic.go | 32 ++++----- pkg/agentic/prep.go | 2 +- pkg/agentic/transport.go | 122 +++++++++++++++++------------------ 6 files changed, 92 insertions(+), 93 deletions(-) diff --git a/pkg/agentic/commands.go b/pkg/agentic/commands.go index b274854..2c4da73 100644 --- a/pkg/agentic/commands.go +++ b/pkg/agentic/commands.go @@ -26,7 +26,6 @@ func (s *PrepSubsystem) registerCommands(ctx context.Context) { } // ctx := s.commandContext() -// _ = ctx.Err() func (s *PrepSubsystem) commandContext() context.Context { if s.startupContext != nil { return s.startupContext @@ -72,12 +71,12 @@ func (s *PrepSubsystem) runTask(ctx context.Context, options core.Options) core. }) if !result.OK { - failureErr := result.Err - if failureErr == nil { - failureErr = core.E("agentic.runTask", "dispatch failed", nil) + failureError := result.Error + if failureError == nil { + failureError = core.E("agentic.runTask", "dispatch failed", nil) } - core.Print(nil, "FAILED: %v", failureErr) - return core.Result{Value: failureErr, OK: false} + core.Print(nil, "FAILED: %v", failureError) + return core.Result{Value: failureError, OK: false} } core.Print(nil, "DONE: %s", result.Status) diff --git a/pkg/agentic/dispatch.go b/pkg/agentic/dispatch.go index c36920d..bb33a43 100644 --- a/pkg/agentic/dispatch.go +++ b/pkg/agentic/dispatch.go @@ -515,7 +515,7 @@ func (s *PrepSubsystem) runQA(workspaceDir string) bool { return true } -func (s *PrepSubsystem) dispatch(ctx context.Context, req *mcp.CallToolRequest, input DispatchInput) (*mcp.CallToolResult, DispatchOutput, error) { +func (s *PrepSubsystem) dispatch(ctx context.Context, callRequest *mcp.CallToolRequest, input DispatchInput) (*mcp.CallToolResult, DispatchOutput, error) { if input.Repo == "" { return nil, DispatchOutput{}, core.E("dispatch", "repo is required", nil) } @@ -547,7 +547,7 @@ func (s *PrepSubsystem) dispatch(ctx context.Context, req *mcp.CallToolRequest, Variables: input.Variables, Persona: input.Persona, } - _, prepOut, err := s.prepWorkspace(ctx, req, prepInput) + _, prepOut, err := s.prepWorkspace(ctx, callRequest, prepInput) if err != nil { return nil, DispatchOutput{}, core.E("dispatch", "prep workspace failed", err) } diff --git a/pkg/agentic/dispatch_sync.go b/pkg/agentic/dispatch_sync.go index 287114c..7699150 100644 --- a/pkg/agentic/dispatch_sync.go +++ b/pkg/agentic/dispatch_sync.go @@ -23,11 +23,11 @@ type DispatchSyncInput struct { // DispatchSyncResult is the output of a synchronous task run. // // if result.OK { core.Print(nil, "done: %s", result.Status) } -// if !result.OK { core.Print(nil, "%v", result.Err) } +// if !result.OK { core.Print(nil, "%v", result.Error) } type DispatchSyncResult struct { OK bool Status string - Err error + Error error PRURL string } @@ -50,10 +50,10 @@ func (s *PrepSubsystem) DispatchSync(ctx context.Context, input DispatchSyncInpu _, prepOut, err := s.prepWorkspace(prepContext, nil, prepInput) if err != nil { - return DispatchSyncResult{Err: core.E("agentic.DispatchSync", "prep workspace failed", err)} + return DispatchSyncResult{Error: core.E("agentic.DispatchSync", "prep workspace failed", err)} } if !prepOut.Success { - return DispatchSyncResult{Err: core.E("agentic.DispatchSync", "prep failed", nil)} + return DispatchSyncResult{Error: core.E("agentic.DispatchSync", "prep failed", nil)} } workspaceDir := prepOut.WorkspaceDir @@ -65,7 +65,7 @@ func (s *PrepSubsystem) DispatchSync(ctx context.Context, input DispatchSyncInpu // Spawn agent directly — no queue, no concurrency check pid, processID, _, err := s.spawnAgent(input.Agent, prompt, workspaceDir) if err != nil { - return DispatchSyncResult{Err: core.E("agentic.DispatchSync", "spawn agent failed", err)} + return DispatchSyncResult{Error: core.E("agentic.DispatchSync", "spawn agent failed", err)} } core.Print(nil, " pid: %d", pid) @@ -83,7 +83,7 @@ func (s *PrepSubsystem) DispatchSync(ctx context.Context, input DispatchSyncInpu for { select { case <-ctx.Done(): - return DispatchSyncResult{Err: core.E("agentic.DispatchSync", "cancelled", ctx.Err())} + return DispatchSyncResult{Error: core.E("agentic.DispatchSync", "cancelled", ctx.Err())} case <-ticker.C: if pid > 0 && !ProcessAlive(runtime, processID, pid) { // Process exited — read final status @@ -91,7 +91,7 @@ func (s *PrepSubsystem) DispatchSync(ctx context.Context, input DispatchSyncInpu st, ok := workspaceStatusValue(result) if !ok { err, _ := result.Value.(error) - return DispatchSyncResult{Err: core.E("agentic.DispatchSync", "can't read final status", err)} + return DispatchSyncResult{Error: core.E("agentic.DispatchSync", "can't read final status", err)} } return DispatchSyncResult{ OK: st.Status == "completed", diff --git a/pkg/agentic/epic.go b/pkg/agentic/epic.go index 5ddf7ea..9137334 100644 --- a/pkg/agentic/epic.go +++ b/pkg/agentic/epic.go @@ -53,7 +53,7 @@ func (s *PrepSubsystem) registerEpicTool(server *mcp.Server) { }, s.createEpic) } -func (s *PrepSubsystem) createEpic(ctx context.Context, req *mcp.CallToolRequest, input EpicInput) (*mcp.CallToolResult, EpicOutput, error) { +func (s *PrepSubsystem) createEpic(ctx context.Context, callRequest *mcp.CallToolRequest, input EpicInput) (*mcp.CallToolResult, EpicOutput, error) { if input.Title == "" { return nil, EpicOutput{}, core.E("createEpic", "title is required", nil) } @@ -127,7 +127,7 @@ func (s *PrepSubsystem) createEpic(ctx context.Context, req *mcp.CallToolRequest // Step 4: Optionally dispatch agents to each child if input.Dispatch { for _, child := range children { - _, _, err := s.dispatch(ctx, req, DispatchInput{ + _, _, err := s.dispatch(ctx, callRequest, DispatchInput{ Repo: input.Repo, Org: input.Org, Task: child.Title, @@ -158,21 +158,21 @@ func (s *PrepSubsystem) createIssue(ctx context.Context, org, repo, title, body data := core.JSONMarshalString(payload) url := core.Sprintf("%s/api/v1/repos/%s/%s/issues", s.forgeURL, org, repo) - r := HTTPPost(ctx, url, data, s.forgeToken, "token") - if !r.OK { + httpResult := HTTPPost(ctx, url, data, s.forgeToken, "token") + if !httpResult.OK { return ChildRef{}, core.E("createIssue", "create issue request failed", nil) } - var result struct { + var createdIssue struct { Number int `json:"number"` HTMLURL string `json:"html_url"` } - core.JSONUnmarshalString(r.Value.(string), &result) + core.JSONUnmarshalString(httpResult.Value.(string), &createdIssue) return ChildRef{ - Number: result.Number, + Number: createdIssue.Number, Title: title, - URL: result.HTMLURL, + URL: createdIssue.HTMLURL, }, nil } @@ -184,8 +184,8 @@ func (s *PrepSubsystem) resolveLabelIDs(ctx context.Context, org, repo string, n // Fetch existing labels url := core.Sprintf("%s/api/v1/repos/%s/%s/labels?limit=50", s.forgeURL, org, repo) - r := HTTPGet(ctx, url, s.forgeToken, "token") - if !r.OK { + httpResult := HTTPGet(ctx, url, s.forgeToken, "token") + if !httpResult.OK { return nil } @@ -193,7 +193,7 @@ func (s *PrepSubsystem) resolveLabelIDs(ctx context.Context, org, repo string, n ID int64 `json:"id"` Name string `json:"name"` } - core.JSONUnmarshalString(r.Value.(string), &existing) + core.JSONUnmarshalString(httpResult.Value.(string), &existing) nameToID := make(map[string]int64) for _, l := range existing { @@ -235,14 +235,14 @@ func (s *PrepSubsystem) createLabel(ctx context.Context, org, repo, name string) }) url := core.Sprintf("%s/api/v1/repos/%s/%s/labels", s.forgeURL, org, repo) - r := HTTPPost(ctx, url, payload, s.forgeToken, "token") - if !r.OK { + httpResult := HTTPPost(ctx, url, payload, s.forgeToken, "token") + if !httpResult.OK { return 0 } - var result struct { + var createdLabel struct { ID int64 `json:"id"` } - core.JSONUnmarshalString(r.Value.(string), &result) - return result.ID + core.JSONUnmarshalString(httpResult.Value.(string), &createdLabel) + return createdLabel.ID } diff --git a/pkg/agentic/prep.go b/pkg/agentic/prep.go index c6dfa2c..d40c5e9 100644 --- a/pkg/agentic/prep.go +++ b/pkg/agentic/prep.go @@ -199,7 +199,7 @@ func (s *PrepSubsystem) OnStartup(ctx context.Context) core.Result { return core.Result{OK: true} } -// registerCommands is in commands.go +// s.registerCommands(ctx) // subsystem := agentic.NewPrep() // _ = subsystem.OnShutdown(context.Background()) diff --git a/pkg/agentic/transport.go b/pkg/agentic/transport.go index e8ae088..168c137 100644 --- a/pkg/agentic/transport.go +++ b/pkg/agentic/transport.go @@ -31,27 +31,27 @@ type httpStream struct { // stream := &httpStream{client: defaultClient, url: "https://forge.lthn.ai/api/v1/version", method: "GET"} // _ = stream.Send(nil) func (s *httpStream) Send(data []byte) error { - req, err := http.NewRequestWithContext(context.Background(), s.method, s.url, core.NewReader(string(data))) + request, err := http.NewRequestWithContext(context.Background(), s.method, s.url, core.NewReader(string(data))) if err != nil { return err } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "application/json") + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Accept", "application/json") if s.token != "" { - req.Header.Set("Authorization", core.Concat("token ", s.token)) + request.Header.Set("Authorization", core.Concat("token ", s.token)) } - resp, err := s.client.Do(req) + response, err := s.client.Do(request) if err != nil { return err } - r := core.ReadAll(resp.Body) - if !r.OK { - err, _ := r.Value.(error) + readResult := core.ReadAll(response.Body) + if !readResult.OK { + err, _ := readResult.Value.(error) return core.E("httpStream.Send", "failed to read response", err) } - s.response = []byte(r.Value.(string)) + s.response = []byte(readResult.Value.(string)) return nil } @@ -94,35 +94,35 @@ func RegisterHTTPTransport(c *core.Core) { // HTTPGet performs a GET request. Returns Result{Value: string (response body), OK: bool}. // Auth is "token {token}" for Forge, "Bearer {token}" for Brain. // -// r := agentic.HTTPGet(ctx, "https://forge.lthn.ai/api/v1/repos", "my-token", "token") +// result := agentic.HTTPGet(ctx, "https://forge.lthn.ai/api/v1/repos", "my-token", "token") func HTTPGet(ctx context.Context, url, token, authScheme string) core.Result { return httpDo(ctx, "GET", url, "", token, authScheme) } // HTTPPost performs a POST request with a JSON body. Returns Result{Value: string, OK: bool}. // -// r := agentic.HTTPPost(ctx, url, core.JSONMarshalString(payload), token, "token") +// result := agentic.HTTPPost(ctx, url, core.JSONMarshalString(payload), token, "token") func HTTPPost(ctx context.Context, url, body, token, authScheme string) core.Result { return httpDo(ctx, "POST", url, body, token, authScheme) } // HTTPPatch performs a PATCH request with a JSON body. // -// r := agentic.HTTPPatch(ctx, url, body, token, "token") +// result := agentic.HTTPPatch(ctx, url, body, token, "token") func HTTPPatch(ctx context.Context, url, body, token, authScheme string) core.Result { return httpDo(ctx, "PATCH", url, body, token, authScheme) } // HTTPDelete performs a DELETE request. // -// r := agentic.HTTPDelete(ctx, url, body, token, "Bearer") +// result := agentic.HTTPDelete(ctx, url, body, token, "Bearer") func HTTPDelete(ctx context.Context, url, body, token, authScheme string) core.Result { return httpDo(ctx, "DELETE", url, body, token, authScheme) } // HTTPDo performs an HTTP request with the specified method. // -// r := agentic.HTTPDo(ctx, "PUT", url, body, token, "token") +// result := agentic.HTTPDo(ctx, "PUT", url, body, token, "token") func HTTPDo(ctx context.Context, method, url, body, token, authScheme string) core.Result { return httpDo(ctx, method, url, body, token, authScheme) } @@ -132,7 +132,7 @@ func HTTPDo(ctx context.Context, method, url, body, token, authScheme string) co // DriveGet performs a GET request using a named Drive endpoint. // Reads base URL and token from the Drive handle registered in Core. // -// r := DriveGet(c, "forge", "/api/v1/repos/core/go-io", "token") +// result := DriveGet(c, "forge", "/api/v1/repos/core/go-io", "token") func DriveGet(c *core.Core, drive, path, authScheme string) core.Result { base, token := driveEndpoint(c, drive) if base == "" { @@ -143,7 +143,7 @@ func DriveGet(c *core.Core, drive, path, authScheme string) core.Result { // DrivePost performs a POST request using a named Drive endpoint. // -// r := DrivePost(c, "forge", "/api/v1/repos/core/go-io/issues", body, "token") +// result := DrivePost(c, "forge", "/api/v1/repos/core/go-io/issues", body, "token") func DrivePost(c *core.Core, drive, path, body, authScheme string) core.Result { base, token := driveEndpoint(c, drive) if base == "" { @@ -154,7 +154,7 @@ func DrivePost(c *core.Core, drive, path, body, authScheme string) core.Result { // DriveDo performs an HTTP request using a named Drive endpoint. // -// r := DriveDo(c, "forge", "PATCH", "/api/v1/repos/core/go-io/pulls/5", body, "token") +// result := DriveDo(c, "forge", "PATCH", "/api/v1/repos/core/go-io/pulls/5", body, "token") func DriveDo(c *core.Core, drive, method, path, body, authScheme string) core.Result { base, token := driveEndpoint(c, drive) if base == "" { @@ -165,49 +165,49 @@ func DriveDo(c *core.Core, drive, method, path, body, authScheme string) core.Re // driveEndpoint reads base URL and token from a named Drive handle. func driveEndpoint(c *core.Core, name string) (base, token string) { - r := c.Drive().Get(name) - if !r.OK { + driveResult := c.Drive().Get(name) + if !driveResult.OK { return "", "" } - h := r.Value.(*core.DriveHandle) - return h.Transport, h.Options.String("token") + driveHandle := driveResult.Value.(*core.DriveHandle) + return driveHandle.Transport, driveHandle.Options.String("token") } // httpDo is the single HTTP execution point. Every HTTP call in core/agent routes here. func httpDo(ctx context.Context, method, url, body, token, authScheme string) core.Result { - var req *http.Request + var request *http.Request var err error if body != "" { - req, err = http.NewRequestWithContext(ctx, method, url, core.NewReader(body)) + request, err = http.NewRequestWithContext(ctx, method, url, core.NewReader(body)) } else { - req, err = http.NewRequestWithContext(ctx, method, url, nil) + request, err = http.NewRequestWithContext(ctx, method, url, nil) } if err != nil { return core.Result{Value: core.E("httpDo", "create request", err), OK: false} } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "application/json") + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Accept", "application/json") if token != "" { if authScheme == "" { authScheme = "token" } - req.Header.Set("Authorization", core.Concat(authScheme, " ", token)) + request.Header.Set("Authorization", core.Concat(authScheme, " ", token)) } - resp, err := defaultClient.Do(req) + response, err := defaultClient.Do(request) if err != nil { return core.Result{Value: core.E("httpDo", "request failed", err), OK: false} } - r := core.ReadAll(resp.Body) - if !r.OK { - err, _ := r.Value.(error) + readResult := core.ReadAll(response.Body) + if !readResult.OK { + err, _ := readResult.Value.(error) return core.Result{Value: core.E("httpDo", "failed to read response", err), OK: false} } - return core.Result{Value: r.Value.(string), OK: resp.StatusCode < 400} + return core.Result{Value: readResult.Value.(string), OK: response.StatusCode < 400} } // --- MCP Streamable HTTP Transport --- @@ -246,26 +246,26 @@ func mcpInitializeResult(ctx context.Context, url, token string) core.Result { } body := core.JSONMarshalString(initializeRequest) - req, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(body)) + request, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(body)) if err != nil { return core.Result{Value: core.E("mcpInitialize", "create request", err), OK: false} } - mcpHeaders(req, token, "") + mcpHeaders(request, token, "") - resp, err := defaultClient.Do(req) + response, err := defaultClient.Do(request) if err != nil { return core.Result{Value: core.E("mcpInitialize", "request failed", err), OK: false} } - defer resp.Body.Close() + defer response.Body.Close() - if resp.StatusCode != 200 { - return core.Result{Value: core.E("mcpInitialize", core.Sprintf("HTTP %d", resp.StatusCode), nil), OK: false} + if response.StatusCode != 200 { + return core.Result{Value: core.E("mcpInitialize", core.Sprintf("HTTP %d", response.StatusCode), nil), OK: false} } - sessionID := resp.Header.Get("Mcp-Session-Id") + sessionID := response.Header.Get("Mcp-Session-Id") // Drain SSE response - drainSSE(resp) + drainSSE(response) // Send initialised notification notification := core.JSONMarshalString(map[string]any{ @@ -303,28 +303,28 @@ func mcpCall(ctx context.Context, url, token, sessionID string, body []byte) ([] } func mcpCallResult(ctx context.Context, url, token, sessionID string, body []byte) core.Result { - req, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(string(body))) + request, err := http.NewRequestWithContext(ctx, "POST", url, core.NewReader(string(body))) if err != nil { return core.Result{Value: core.E("mcpCall", "create request", err), OK: false} } - mcpHeaders(req, token, sessionID) + mcpHeaders(request, token, sessionID) - resp, err := defaultClient.Do(req) + response, err := defaultClient.Do(request) if err != nil { return core.Result{Value: core.E("mcpCall", "request failed", err), OK: false} } - defer resp.Body.Close() + defer response.Body.Close() - if resp.StatusCode != 200 { - return core.Result{Value: core.E("mcpCall", core.Sprintf("HTTP %d", resp.StatusCode), nil), OK: false} + if response.StatusCode != 200 { + return core.Result{Value: core.E("mcpCall", core.Sprintf("HTTP %d", response.StatusCode), nil), OK: false} } - return readSSEDataResult(resp) + return readSSEDataResult(response) } // readSSEData reads an SSE response and extracts JSON from data: lines. -func readSSEData(resp *http.Response) ([]byte, error) { - result := readSSEDataResult(resp) +func readSSEData(response *http.Response) ([]byte, error) { + result := readSSEDataResult(response) if !result.OK { err, _ := result.Value.(error) if err == nil { @@ -340,13 +340,13 @@ func readSSEData(resp *http.Response) ([]byte, error) { } // readSSEDataResult parses an SSE response and extracts the first data: payload as core.Result. -func readSSEDataResult(resp *http.Response) core.Result { - r := core.ReadAll(resp.Body) - if !r.OK { - err, _ := r.Value.(error) +func readSSEDataResult(response *http.Response) core.Result { + readResult := core.ReadAll(response.Body) + if !readResult.OK { + err, _ := readResult.Value.(error) return core.Result{Value: core.E("readSSEData", "failed to read response", err), OK: false} } - for _, line := range core.Split(r.Value.(string), "\n") { + for _, line := range core.Split(readResult.Value.(string), "\n") { if core.HasPrefix(line, "data: ") { return core.Result{Value: []byte(core.TrimPrefix(line, "data: ")), OK: true} } @@ -355,18 +355,18 @@ func readSSEDataResult(resp *http.Response) core.Result { } // mcpHeaders applies standard MCP HTTP headers. -func mcpHeaders(req *http.Request, token, sessionID string) { - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "application/json, text/event-stream") +func mcpHeaders(request *http.Request, token, sessionID string) { + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Accept", "application/json, text/event-stream") if token != "" { - req.Header.Set("Authorization", core.Concat("Bearer ", token)) + request.Header.Set("Authorization", core.Concat("Bearer ", token)) } if sessionID != "" { - req.Header.Set("Mcp-Session-Id", sessionID) + request.Header.Set("Mcp-Session-Id", sessionID) } } // drainSSE reads and discards an SSE response body. -func drainSSE(resp *http.Response) { - core.ReadAll(resp.Body) +func drainSSE(response *http.Response) { + core.ReadAll(response.Body) }