runner: Codex runs Engineering and Review steps on the thin runner
Astra round 1, finding 5: only Claude could run Engineering and Review, so an Engineering step refused on quota could not fail over to Codex (spec gate 1c, F6). The capability matrix now lets Codex run both roles. Engineer.run dispatches a Codex binding to runCodex (codexstep.go): the pinned app-server in the implement or inspect containment, checked like the coordinator (version, runtime home, account, effective config, thread policy, ValidateThinPolicy digests), one thread and one turn, the step's own tools over MCP after an approval correlated with the call (shared answerApproval; everything else refused), limits, auth, usage through CodexTally, and the namespace's exit proven before the result counts. A Codex step keeps no session, so it is not askable. Its tool socket lists no permission tool. fakecodex plays Engineering (command, file edits, submit_candidate) and Review (submit_review) steps, with steplimit and reviewlimit words. Headless C5_engineering_to_codex and C5_review_on_codex, and unit tests for approvals, the socket and activity. Budget for thin raised to 11500.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 files changed,
+633
−48
.rastrillo/budgets.txt+1 −1internal/fakecodex/fake.go+110 −23internal/headless/connections_test.go+60 −0internal/runner/connect/choose.go+5 −4internal/runner/connect/choose_test.go+3 −2internal/runner/thin/codex.go+18 −7internal/runner/thin/codexstep.go+307 −0internal/runner/thin/codexstep_test.go+108 −0internal/runner/thin/engineer.go+8 −2internal/runner/thin/judge.go+4 −4internal/runner/thin/mcp.go+8 −4internal/runner/thin/run.go+1 −1
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index f588108c..eb15d21f 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -35,7 +35,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full |
| perf GET /releases/* skip Verified runner release file downloads, not browser GET screens. |
| time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s; niced serial reruns measured 5.773s and 5.750s. The added coordinator mount check has no repeated launches to remove; 15s leaves 38 percent headroom for namespace, process-exit and recovery assertions. |
| time internal/tryequipo 30s Release starter-set controller K3 records CI runs of 10.8s and 13.1s; 30s retains the guide integration checks with headroom on the shared runner. |
| -size internal/runner/thin 11200 - Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path. |
| +size internal/runner/thin 11500 - Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path. |
| time internal/thintest 60s Thin v1 slice 4c adds the merge, adoption, cancel and retention contract tests (CI measured 35.7s). Thin v1 contract tests: a real instance and a scripted runner per test, fixtures replayed against every request, frame and event. Slice 3 adds the task, step-sync and grant contracts; CI measured 14.805s. 30s keeps room for the slice 4 review contracts. UX1 adds step activity, task source and duplicates, coordinator merging and project facts (four contracts, about 6s); the package measured 34s locally under load, so 40s. UX1's inner screens gallery (two owners, seven tasks, every page) adds about 3s; measured 40.9s locally under load, so 60s. |
| time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s). Measured 17.8s locally under load. Slice 4b review adds a 16 MiB git output bound, an injected index-pack failure and stall (3s deadline) and held-answer tests; measured 30.3s locally under load. 45s keeps 33 percent headroom. |
| time internal/headless 360s Connections slice 1 adds TestHeadlessConnections (usage rows, failover, Codex coordinator, device code, Claude sign-in, failure kinds, cancel and sign-out, writes replayed, Engineering and Review moving connection, the waiting turn): eleven scenarios, about 55 to 100s locally. Thin v1 headless suite: real instance, runner and bubblewrap per scenario (spec 7, under two minutes). Slice 4 adds the review and checks scenarios (4_review with its fix rounds, branch move and merge; 4_checks_honest); loaded CI measured 170s on 2026-11-07. Slice 4b adds 4b_ask (about 12s); loaded CI measured 182.9s. 240s keeps 30 percent headroom. |
diff --git a/internal/fakecodex/fake.go b/internal/fakecodex/fake.go| index 92aaf9fe..edcecf2b 100644 |
| --- a/internal/fakecodex/fake.go |
| +++ b/internal/fakecodex/fake.go |
| @@ -19,6 +19,16 @@ |
| // "limit:<email>" (the account at that email has spent its limit: both |
| // windows at 100% and the turn fails usageLimitExceeded), "sleep:<ms>" |
| // pauses mid-reply, "fail" fails the turn. |
| +// |
| +// Steps: a prompt starting "[Equipo: engineering]" is an Engineering step. |
| +// It shows a command, applies each "edit:<path>|<old>|<new>" to the file |
| +// in its working directory (the namespace's /workspace) as a fileChange |
| +// item, calls submit_candidate through MCP and replies with a |
| +// "Headline: ..." line and a summary. A prompt starting "[Equipo: |
| +// review]" is a Review step: it calls submit_review (approve, or |
| +// changes_requested for each "review:changes:<path>|<line>|<text>"). |
| +// "steplimit:<email>" and "reviewlimit:<email>" refuse such a step on |
| +// quota as "limit:<email>" does a turn. |
| package fakecodex |
| import ( |
| @@ -362,9 +372,13 @@ func (s *server) record(thread, prompt, reply string) int { |
| } |
| var ( |
| - toolWord = regexp.MustCompile(`tool:([a-z_]+)(?::([^\n]*))?`) |
| - limitWord = regexp.MustCompile(`\blimit:([^\s|]+@[^\s|]+[a-z])`) |
| - sleepWord = regexp.MustCompile(`\bsleep:([0-9]+)`) |
| + toolWord = regexp.MustCompile(`tool:([a-z_]+)(?::([^\n]*))?`) |
| + limitWord = regexp.MustCompile(`\blimit:([^\s|]+@[^\s|]+[a-z])`) |
| + stepLimitWord = regexp.MustCompile(`\bsteplimit:([^\s|]+@[^\s|]+[a-z])`) |
| + reviewLimitWord = regexp.MustCompile(`\breviewlimit:([^\s|]+@[^\s|]+[a-z])`) |
| + sleepWord = regexp.MustCompile(`\bsleep:([0-9]+)`) |
| + editWord = regexp.MustCompile(`edit:([^|\n]+)\|([^|\n]*)\|([^\n]*)`) |
| + reviewChanges = regexp.MustCompile(`review:changes:([^|\n]+)\|([0-9]+)\|([^\n;]*)`) |
| ) |
| func (s *server) runTurn(thread, turn, prompt string, stop chan struct{}) { |
| @@ -386,34 +400,25 @@ func (s *server) runTurn(thread, turn, prompt string, stop chan struct{}) { |
| } |
| s.notify("turn/started", map[string]any{"threadId": thread, "turn": map[string]any{"id": turn, "status": "inProgress", "items": []any{}}}) |
| a, _ := s.auth() |
| - if m := limitWord.FindStringSubmatch(newest); m != nil && m[1] == a.Email { |
| + engineering, review := strings.HasPrefix(prompt, "[Equipo: engineering]"), strings.HasPrefix(prompt, "[Equipo: review]") |
| + spent := func(word *regexp.Regexp, text string) bool { |
| + m := word.FindStringSubmatch(text) |
| + return m != nil && m[1] == a.Email |
| + } |
| + if spent(limitWord, newest) || engineering && spent(stepLimitWord, prompt) || review && spent(reviewLimitWord, prompt) { |
| s.notify("account/rateLimits/updated", map[string]any{"rateLimits": s.limits(true)}) |
| e := map[string]any{"message": "You've hit your usage limit.", "codexErrorInfo": "usageLimitExceeded", "additionalDetails": nil} |
| s.notify("error", map[string]any{"threadId": thread, "turnId": turn, "willRetry": false, "error": e}) |
| done("failed", e) |
| return |
| } |
| + if engineering || review { |
| + s.step(thread, turn, prompt, review, done) |
| + return |
| + } |
| reply := "" |
| for i, m := range toolWord.FindAllStringSubmatch(newest, -1) { |
| - item := fmt.Sprintf("mcp_%s_%d", turn[:8], i) |
| - input := fakeclaude.ToolInput(m[1], m[2]) |
| - args, _ := json.Marshal(input) |
| - started := map[string]any{"id": item, "type": "mcpToolCall", "server": "equipo", "tool": m[1], "arguments": json.RawMessage(args), "status": "inProgress"} |
| - s.notify("item/started", map[string]any{"threadId": thread, "turnId": turn, "item": started}) |
| - answer := s.request("mcpServer/elicitation/request", map[string]any{"threadId": thread, "turnId": turn, "serverName": "equipo", "mode": "form", "message": "Allow the equipo MCP server to run tool " + m[1] + "?", "_meta": map[string]any{"codex_approval_kind": "mcp_tool_call", "tool_params": json.RawMessage(args)}, "requestedSchema": map[string]any{"type": "object", "properties": map[string]any{}}}) |
| - var v struct { |
| - Action string `json:"action"` |
| - } |
| - _ = json.Unmarshal(answer, &v) |
| - text, isError := "user declined the tool call", true |
| - if v.Action == "accept" { |
| - text, isError = s.callTool(m[1], input) |
| - } |
| - status := "completed" |
| - if isError { |
| - status = "failed" |
| - } |
| - s.notify("item/completed", map[string]any{"threadId": thread, "turnId": turn, "item": map[string]any{"id": item, "type": "mcpToolCall", "server": "equipo", "tool": m[1], "arguments": json.RawMessage(args), "status": status, "result": map[string]any{"content": []any{map[string]string{"type": "text", "text": text}}}, "error": nil}}) |
| + text, _ := s.mcpTool(thread, turn, fmt.Sprintf("mcp_%s_%d", turn[:8], i), m[1], fakeclaude.ToolInput(m[1], m[2])) |
| reply += fmt.Sprintf(" [%s: %s]", m[1], text) |
| if interrupted() { |
| return |
| @@ -482,6 +487,88 @@ func (s *server) runTurn(thread, turn, prompt string, stop chan struct{}) { |
| done("completed", nil) |
| } |
| +// mcpTool calls an Equipo tool as Codex does: the item starts, the |
| +// client is asked to approve the call, and only an accepted call reaches |
| +// the MCP server. |
| +func (s *server) mcpTool(thread, turn, item, name string, input map[string]any) (string, bool) { |
| + args, _ := json.Marshal(input) |
| + started := map[string]any{"id": item, "type": "mcpToolCall", "server": "equipo", "tool": name, "arguments": json.RawMessage(args), "status": "inProgress"} |
| + s.notify("item/started", map[string]any{"threadId": thread, "turnId": turn, "item": started}) |
| + answer := s.request("mcpServer/elicitation/request", map[string]any{"threadId": thread, "turnId": turn, "serverName": "equipo", "mode": "form", "message": "Allow the equipo MCP server to run tool " + name + "?", "_meta": map[string]any{"codex_approval_kind": "mcp_tool_call", "tool_params": json.RawMessage(args)}, "requestedSchema": map[string]any{"type": "object", "properties": map[string]any{}}}) |
| + var v struct { |
| + Action string `json:"action"` |
| + } |
| + _ = json.Unmarshal(answer, &v) |
| + text, isError := "user declined the tool call", true |
| + if v.Action == "accept" { |
| + text, isError = s.callTool(name, input) |
| + } |
| + status := "completed" |
| + if isError { |
| + status = "failed" |
| + } |
| + s.notify("item/completed", map[string]any{"threadId": thread, "turnId": turn, "item": map[string]any{"id": item, "type": "mcpToolCall", "server": "equipo", "tool": name, "arguments": json.RawMessage(args), "status": status, "result": map[string]any{"content": []any{map[string]string{"type": "text", "text": text}}}, "error": nil}}) |
| + return text, isError |
| +} |
| + |
| +// step plays an Engineering or Review step in the working directory. |
| +func (s *server) step(thread, turn, prompt string, review bool, done func(string, any)) { |
| + item := func(kind string, i int) string { return fmt.Sprintf("%s_%s_%d", kind, turn[:8], i) } |
| + var notes []string |
| + reply := "" |
| + if !review { |
| + edits := editWord.FindAllStringSubmatch(prompt, -1) |
| + if len(edits) > 0 { |
| + cmd := map[string]any{"id": item("cmd", 0), "type": "commandExecution", "command": "cat " + edits[0][1], "cwd": "/workspace", "status": "inProgress"} |
| + s.notify("item/started", map[string]any{"threadId": thread, "turnId": turn, "item": cmd}) |
| + cmd["status"] = "completed" |
| + s.notify("item/completed", map[string]any{"threadId": thread, "turnId": turn, "item": cmd}) |
| + } |
| + for i, m := range edits { |
| + change := map[string]any{"id": item("patch", i), "type": "fileChange", "changes": []any{map[string]any{"path": filepath.Join("/workspace", filepath.Clean("/"+m[1])), "kind": map[string]string{"type": "update"}, "diff": ""}}, "status": "inProgress"} |
| + s.notify("item/started", map[string]any{"threadId": thread, "turnId": turn, "item": change}) |
| + raw, err := os.ReadFile(m[1]) |
| + if err == nil { |
| + err = os.WriteFile(m[1], []byte(strings.Replace(string(raw), m[2], m[3], 1)), 0644) |
| + } |
| + change["status"] = "completed" |
| + note := fmt.Sprintf("Replaced %q with %q in %s.", m[2], m[3], m[1]) |
| + if err != nil { |
| + change["status"], note = "failed", "Could not change "+m[1]+"." |
| + } |
| + s.notify("item/completed", map[string]any{"threadId": thread, "turnId": turn, "item": change}) |
| + notes = append(notes, note) |
| + } |
| + if text, isError := s.mcpTool(thread, turn, item("mcp", 0), "submit_candidate", map[string]any{}); isError { |
| + notes = append(notes, "[submit_candidate failed: "+text+"]") |
| + } |
| + reply = "Headline: Made the change the task asks for.\n\n" + strings.Join(notes, " ") |
| + if len(edits) == 0 { |
| + reply = "Headline: Nothing needed changing.\n\nI looked and changed nothing." |
| + } |
| + } else { |
| + verdict, headline, summary, findings := "approve", "Approved.", "The change does what the task asks.", []map[string]any{} |
| + for _, m := range reviewChanges.FindAllStringSubmatch(prompt, -1) { |
| + line, _ := strconv.Atoi(m[2]) |
| + verdict, headline, summary = "changes_requested", "Asked for one more change.", "One thing needs changing." |
| + findings = append(findings, map[string]any{"path": m[1], "line": line, "text": m[3]}) |
| + } |
| + reply = summary + " (from Codex)" |
| + if text, isError := s.mcpTool(thread, turn, item("mcp", 0), "submit_review", map[string]any{"verdict": verdict, "headline": headline, "summary": summary + " (from Codex)", "findings": findings}); isError { |
| + reply += " [submit_review failed: " + text + "]" |
| + } |
| + } |
| + msg := item("msg", 0) |
| + s.notify("item/started", map[string]any{"threadId": thread, "turnId": turn, "item": map[string]any{"id": msg, "type": "agentMessage", "text": ""}}) |
| + s.notify("item/agentMessage/delta", map[string]any{"threadId": thread, "turnId": turn, "itemId": msg, "delta": reply}) |
| + s.notify("item/completed", map[string]any{"threadId": thread, "turnId": turn, "item": map[string]any{"id": msg, "type": "agentMessage", "text": reply}}) |
| + used := tokens{Input: len(prompt) / 4, Cached: len(prompt) / 8, Output: len(reply) / 4, Reasoning: 5} |
| + s.total = s.total.plus(used) |
| + s.usage(thread, turn, s.total, used) |
| + s.notify("account/rateLimits/updated", map[string]any{"rateLimits": s.limits(false)}) |
| + done("completed", nil) |
| +} |
| + |
| type tokens struct{ Input, Cached, Output, Reasoning int } |
| func (a tokens) plus(b tokens) tokens { |
diff --git a/internal/headless/connections_test.go b/internal/headless/connections_test.go| index a8cc77a9..746e8d06 100644 |
| --- a/internal/headless/connections_test.go |
| +++ b/internal/headless/connections_test.go |
| @@ -110,6 +110,8 @@ func TestHeadlessConnections(t *testing.T) { |
| {"C3_codex_device_code", connCodexDeviceCode}, |
| {"C4_claude_sign_in", connClaudeSignIn}, |
| {"C5_engineering_failover", connEngineeringFailover}, |
| + {"C5_engineering_to_codex", connEngineeringToCodex}, |
| + {"C5_review_on_codex", connReviewOnCodex}, |
| {"C5_review_failover", connReviewFailover}, |
| {"C5_engineering_waits", connEngineeringWaits}, |
| {"C5_review_auth", connReviewAuth}, |
| @@ -365,6 +367,64 @@ func connEngineeringFailover(t *testing.T, env *Env, inst *thintest.Instance, r |
| } |
| } |
| +// C5 across families (F6): the owner's Claude refuses an Engineering |
| +// step on quota; once its exit is proven the step's second attempt runs |
| +// on Codex, pushes, and the card shows both. |
| +func connEngineeringToCodex(t *testing.T, env *Env, inst *thintest.Instance, r *localRunner) { |
| + r.addAccount(t, "codex", "codex-1", second) |
| + r.start(t) |
| + s := open(t, env) |
| + s.keep() |
| + text := "tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|Fix it. steplimit:" + thintest.Owner + " edit:README.md|teh panes|the panes" |
| + sent := s.send(t, text) |
| + id := s.taskOf(t, sent.Turn.ID) |
| + step := s.step(t, id, 5*time.Minute, wire.StepDone, wire.StepFailed) |
| + if step.State != wire.StepDone || !step.Pushed || step.Account != "codex-1" || step.Attempt != 2 || step.Headline != "Made the change the task asks for." { |
| + t.Fatalf("step %+v", step) |
| + } |
| + // The card shows both: the step on Codex, and Claude limited. |
| + if step.Family != "gpt" || step.Switched == nil || step.Switched.From != "claude" || step.Switched.ResetsAt == nil { |
| + t.Fatalf("step switched %+v", step.Switched) |
| + } |
| + if step.Askable { |
| + t.Fatal("a Codex step keeps no session to ask") |
| + } |
| + if page := inst.Get(t, "/tasks/"+id); !strings.Contains(page, "Claude was limited") { |
| + t.Fatal("the task page does not show the switch") |
| + } |
| + if got := stepUsage(t, inst, step.ID); got != "1/failed/claude-1 2/replied/codex-1" { |
| + t.Fatalf("step usage rows %q", got) |
| + } |
| +} |
| + |
| +// C5, Review on another family: Engineering runs on the owner's Claude, |
| +// and Review on their Codex connection approves, labelled other_family. |
| +func connReviewOnCodex(t *testing.T, env *Env, inst *thintest.Instance, r *localRunner) { |
| + r.addAccount(t, "codex", "codex-1", second) |
| + r.start(t) |
| + s := open(t, env) |
| + s.keep() |
| + text := "tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|Fix it. edit:README.md|teh panes|the panes" |
| + sent := s.send(t, text) |
| + id := s.taskOf(t, sent.Turn.ID) |
| + var review wire.Step |
| + s.wait(t, "review done", 5*time.Minute, func(c *thintest.Conversation) bool { |
| + for _, st := range c.Tasks[id].Steps { |
| + if st.Specialist == wire.SpecialistReview && wire.StepTerminal(c.Steps[st.ID].State) { |
| + review = c.Steps[st.ID] |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + if review.State != wire.StepDone || review.Verdict != wire.VerdictApprove || review.Account != "codex-1" || review.ReviewLabel != wire.ReviewOtherFamily || !strings.Contains(review.Summary, "(from Codex)") || review.Askable { |
| + t.Fatalf("review %+v", review) |
| + } |
| + if got := stepUsage(t, inst, review.ID); got != "1/replied/codex-1" { |
| + t.Fatalf("review usage rows %q", got) |
| + } |
| +} |
| + |
| // stepUsage is a step's usage rows as attempt/outcome/connection. |
| func stepUsage(t *testing.T, inst *thintest.Instance, step string) string { |
| t.Helper() |
diff --git a/internal/runner/connect/choose.go b/internal/runner/connect/choose.go| index 9af97d11..637a3fc5 100644 |
| --- a/internal/runner/connect/choose.go |
| +++ b/internal/runner/connect/choose.go |
| @@ -33,12 +33,13 @@ const ( |
| ) |
| // capable is the slice 1 capability matrix (spec §5): which harness can |
| -// run which role here. Codex Engineering and Review on the thin runner |
| -// come with the Codex step path; until then they are not chosen. |
| +// run which role here. Codex runs Engineering and Review through the |
| +// thin runner's Codex step path (the app-server in the implement or |
| +// inspect containment). |
| var capable = map[string][]string{ |
| RoleCoordinator: {"claude", "codex"}, |
| - RoleEngineering: {"claude"}, |
| - RoleReview: {"claude"}, |
| + RoleEngineering: {"claude", "codex"}, |
| + RoleReview: {"claude", "codex"}, |
| } |
| // Capable reports whether a provider's harness can run role here. |
diff --git a/internal/runner/connect/choose_test.go b/internal/runner/connect/choose_test.go| index 900c4844..dfcbaea0 100644 |
| --- a/internal/runner/connect/choose_test.go |
| +++ b/internal/runner/connect/choose_test.go |
| @@ -38,7 +38,8 @@ func TestChoose(t *testing.T) { |
| {"limited without reset never by itself", []Candidate{limited(claude, time.Time{})}, RoleCoordinator, "", nil, "", "", ""}, |
| {"stickiness is a rule", []Candidate{used(claude, 0.97), used(codex, 0.1)}, RoleCoordinator, "claude-a", nil, "", "claude-a", ReasonHeadroom}, |
| {"failover to the most headroom", []Candidate{limited(claude, now.Add(time.Hour)), used(claude2, 0.7), used(codex, 0.2)}, RoleCoordinator, "claude-a", nil, "", "codex-1", ReasonFailover}, |
| - {"engineering skips codex", []Candidate{limited(claude, now.Add(time.Hour)), codex}, RoleEngineering, "", nil, "", "", ""}, |
| + {"engineering fails over to codex", []Candidate{limited(claude, now.Add(time.Hour)), codex}, RoleEngineering, "claude-a", nil, "", "codex-1", ReasonOnlyOption}, |
| + {"review away from engineering's on codex", []Candidate{claude, codex}, RoleReview, "", []string{"claude-a"}, "", "codex-1", ReasonOnlyOption}, |
| {"avoid", []Candidate{claude, claude2}, RoleEngineering, "", []string{"claude-a"}, "", "claude-2", ReasonOnlyOption}, |
| {"signed out never", []Candidate{{ID: "claude-a", Provider: "claude", State: "sign_in_again"}, codex}, RoleCoordinator, "claude-a", nil, "", "codex-1", ReasonOnlyOption}, |
| {"unchecked is never chosen", []Candidate{{ID: "codex-1", Provider: "codex"}}, RoleCoordinator, "", nil, "", "", ""}, |
| @@ -47,7 +48,7 @@ func TestChoose(t *testing.T) { |
| {"on the preference already", []Candidate{claude, codex}, RoleCoordinator, "codex-1", nil, "codex", "codex-1", ReasonHeadroom}, |
| {"preference never overrides health", []Candidate{claude, limited(codex, now.Add(time.Hour))}, RoleCoordinator, "claude-a", nil, "codex", "claude-a", ReasonOnlyOption}, |
| {"preference among a provider's accounts by headroom", []Candidate{used(claude, 0.6), used(claude2, 0.1), codex}, RoleCoordinator, "", nil, "claude", "claude-2", ReasonPreference}, |
| - {"preference a role cannot use", []Candidate{claude, claude2, codex}, RoleEngineering, "claude-a", nil, "codex", "claude-a", ReasonHeadroom}, |
| + {"preference nothing here can use", []Candidate{claude, claude2, codex}, RoleEngineering, "claude-a", nil, "pi", "claude-a", ReasonHeadroom}, |
| {"connecting is never chosen", []Candidate{{ID: "codex-1", Provider: "codex", State: "connecting"}}, RoleCoordinator, "", nil, "", "", ""}, |
| } { |
| t.Run(tc.name, func(t *testing.T) { |
diff --git a/internal/runner/thin/codex.go b/internal/runner/thin/codex.go| index 77c44557..81664d27 100644 |
| --- a/internal/runner/thin/codex.go |
| +++ b/internal/runner/thin/codex.go |
| @@ -108,6 +108,11 @@ type codexItem struct { |
| Server string `json:"server"` |
| Tool string `json:"tool"` |
| Arguments json.RawMessage `json:"arguments"` |
| + // Command and Changes are a step's shell command and file changes. |
| + Command string `json:"command"` |
| + Changes []struct { |
| + Path string `json:"path"` |
| + } `json:"changes"` |
| } |
| func (c *codexCoordinator) Turn(ctx context.Context, in TurnInput, emit func(string)) TurnResult { |
| @@ -321,25 +326,31 @@ func (c *codexCoordinator) Turn(ctx context.Context, in TurnInput, emit func(str |
| } |
| } |
| -// answer replies to a request the app-server makes. Only an approval to |
| -// call one of the conversation's own Equipo tools, correlated with the |
| +// answer replies to a request the app-server makes: only the |
| +// conversation's own Equipo tools are approved. |
| +func (c *codexCoordinator) answer(p *codexProcess, m connect.Message, items map[string]codexItem) { |
| + answerApproval(p.rpc, m, items, provider.ConverseTools()) |
| +} |
| + |
| +// answerApproval replies to a request the app-server makes. Only an |
| +// approval to call one of names on the Equipo server, correlated with the |
| // tool call Codex started, is accepted; every other request (shell, |
| // patch, questions, anything new) is refused. |
| -func (c *codexCoordinator) answer(p *codexProcess, m connect.Message, items map[string]codexItem) { |
| +func answerApproval(rpc *connect.AppServer, m connect.Message, items map[string]codexItem, names []string) { |
| if m.Method == "mcpServer/elicitation/request" { |
| server, args, ok := codex.ToolApproval(m.Params) |
| if ok && server == "equipo" { |
| for _, it := range items { |
| - if it.Server == "equipo" && slices.Contains(provider.ConverseTools(), it.Tool) && codex.SameArguments(it.Arguments, args) { |
| - _ = p.rpc.Answer(m.ID, map[string]any{"action": "accept", "content": map[string]any{}}) |
| + if it.Server == "equipo" && slices.Contains(names, it.Tool) && codex.SameArguments(it.Arguments, args) { |
| + _ = rpc.Answer(m.ID, map[string]any{"action": "accept", "content": map[string]any{}}) |
| return |
| } |
| } |
| } |
| - _ = p.rpc.Answer(m.ID, map[string]any{"action": "decline"}) |
| + _ = rpc.Answer(m.ID, map[string]any{"action": "decline"}) |
| return |
| } |
| - _ = p.rpc.Refuse(m.ID) |
| + _ = rpc.Refuse(m.ID) |
| } |
| func (c *codexCoordinator) interrupt(p *codexProcess, turn string) { |
diff --git a/internal/runner/thin/codexstep.go b/internal/runner/thin/codexstep.go| new file mode 100644 |
| index 00000000..1b45b0dd |
| --- /dev/null |
| +++ b/internal/runner/thin/codexstep.go |
| @@ -0,0 +1,307 @@ |
| +package thin |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "io" |
| + "os" |
| + "strings" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner" |
| + "amadan.net/oficina/equipo/internal/runner/connect" |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| + "amadan.net/oficina/equipo/internal/runner/provider/codex" |
| + "amadan.net/oficina/equipo/internal/runner/workspace" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// runCodex runs a step's specialist on a Codex connection: the pinned |
| +// app-server in the action's containment (implement: the task tree |
| +// read-write; inspect: read-only), one thread and one turn, the step's |
| +// own tools over MCP after an approval correlated with the call, every |
| +// other request refused, and the namespace's exit proven before the |
| +// result counts. A Codex step keeps no session, so it cannot be asked |
| +// (kept sessions are Claude's for now). |
| +func (e *Engineer) runCodex(ctx context.Context, r stepRow, tree workspace.TaskTree, spec specialistRun) stepResult { |
| + o, x := e.O, e.Codex |
| + x.defaults() |
| + b := spec.binding |
| + if spec.resume != "" { |
| + return stepResult{reason: "session_gone", terminated: true} |
| + } |
| + direct, err := o.Runner.DirectBinding(b) |
| + if err != nil { |
| + return stepResult{reason: "account_unavailable", terminated: true} |
| + } |
| + lease, err := provider.OpenRuntimeCopy(ctx, direct, o.Refresh, o.LockWait) |
| + if err != nil { |
| + e.log("step account", err) |
| + return stepResult{reason: reasonFor(err), terminated: true} |
| + } |
| + defer lease.Close() |
| + binding := lease.Binding() |
| + scratch, err := os.MkdirTemp(o.Runner.ScratchRoot, "policy-") |
| + if err != nil { |
| + return stepResult{reason: "provider_failed", terminated: true} |
| + } |
| + defer os.RemoveAll(scratch) |
| + // Codex asks for each tool call through an elicitation, never a |
| + // permission tool: the socket lists only the step's own tools. |
| + tool, err := openToolSet(context.Background(), o.Runner.StateDir, toolSet{list: spec.tools, names: spec.names}, spec.call) |
| + if err != nil { |
| + return stepResult{reason: "provider_failed", terminated: true} |
| + } |
| + defer tool.Close() |
| + sel := provider.Selection{ConnectionID: b.LocalID, Provider: b.Provider, Family: b.Family, Model: b.Model, AccountID: b.AccountID} |
| + in, err := runner.CertificationInputs(ctx, o.Runner, sel, binding, tree.Dir, spec.action, scratch) |
| + if err != nil { |
| + e.log("step policy", err) |
| + return stepResult{reason: "policy_rejected", terminated: true} |
| + } |
| + policy, err := provider.BuildPolicy(binding, in) |
| + if err == nil { |
| + err = codex.ValidateThinPolicy(binding, policy, x.Digest, x.HostDigest) |
| + } |
| + if err != nil { |
| + e.log("step policy", err) |
| + return stepResult{reason: "policy_rejected", terminated: true} |
| + } |
| + if err = lease.CheckCopy(ctx); err != nil { |
| + return stepResult{reason: reasonFor(err), terminated: true} |
| + } |
| + bound := e.MaxStep |
| + if spec.limit > 0 { |
| + bound = spec.limit |
| + } |
| + limit := min(bound, time.Until(lease.FreshUntil())-o.Margin) |
| + if limit < minTurn { |
| + return stepResult{reason: "account_unavailable", terminated: true} |
| + } |
| + launch := provider.Launch{ToolSocket: tool.Path, AttemptKey: "step/" + stepKey(r) + "/" + uuid(), Workspace: tree.Dir, Selection: sel, Binding: binding, Policy: policy} |
| + pctx, kill := context.WithCancel(context.Background()) |
| + defer kill() |
| + record := spec.record |
| + if record == nil { |
| + record = func(ctx context.Context, id string) error { return e.O.State.setStepNamespace(ctx, r, id) } |
| + } |
| + proc, err := recordedStart(pctx, o.Manager, launch, in.Argv, record) |
| + if err != nil { |
| + e.log("step start", err) |
| + return stepResult{reason: "policy_rejected", terminated: true} |
| + } |
| + exited := make(chan error, 1) |
| + go func() { |
| + _, err := proc.Wait(context.Background()) |
| + exited <- err |
| + }() |
| + go func() { _, _ = io.Copy(io.Discard, io.LimitReader(proc.Stderr(), 1<<20)) }() |
| + var logFile io.WriteCloser = nopWriteCloser{} |
| + if !spec.noLog { |
| + logFile = e.openLog(r) |
| + } |
| + defer logFile.Close() |
| + rpc := connect.NewAppServer(proc.Stdout(), proc.Stdin()) |
| + res := e.codexStep(ctx, rpc, b, policy, limit, spec, logFile) |
| + res.terminated = stopStep(func() { proc.Stdin().Close() }, exited, kill, ctx.Err() == nil && res.reason == "", 10*time.Second, 30*time.Second) |
| + if !res.terminated { |
| + // The namespace record stays: a restarted runner verifies it. |
| + e.log("step stop", errors.New("exit not verified")) |
| + return res |
| + } |
| + e.forget(proc.ID()) |
| + return res |
| +} |
| + |
| +// codexStep checks the app-server it talks to (pinned version, runtime |
| +// home, the expected account, the effective configuration, the thread's |
| +// policy), then runs the step as one turn and reads it to its end. |
| +func (e *Engineer) codexStep(ctx context.Context, rpc *connect.AppServer, b runner.AccountBinding, policy provider.Policy, limit time.Duration, spec specialistRun, logFile io.Writer) stepResult { |
| + tail := &stepTail{} |
| + cancelled := func() stepResult { |
| + if ctx.Err() != nil { |
| + return stepResult{reason: "cancelled", tail: tail.String()} |
| + } |
| + return stepResult{reason: "step_timeout", tail: tail.String()} |
| + } |
| + tctx, cancel := context.WithTimeout(ctx, limit) |
| + defer cancel() |
| + sctx, done := context.WithTimeout(tctx, 30*time.Second) |
| + defer done() |
| + raw, _, err := rpc.Call(sctx, "initialize", codex.InitializeParams()) |
| + if err == nil { |
| + err = codex.CheckInitialize(raw) |
| + } |
| + if err == nil { |
| + err = rpc.Notify("initialized", map[string]any{}) |
| + } |
| + if err == nil { |
| + raw, _, err = rpc.Call(sctx, "account/read", map[string]bool{"refreshToken": false}) |
| + } |
| + if err == nil { |
| + var id provider.Identity |
| + if id, err = provider.CodexLoginIdentity(raw); err == nil && id.AccountID != b.AccountID { |
| + err = provider.ErrIdentity |
| + } |
| + } |
| + if err == nil { |
| + raw, _, err = rpc.Call(sctx, "config/read", map[string]any{"cwd": "/workspace", "includeLayers": true}) |
| + } |
| + if err == nil { |
| + err = codex.CheckConfig(raw, policy) |
| + } |
| + thread := "" |
| + if err == nil { |
| + raw, _, err = rpc.Call(sctx, "thread/start", codex.ThreadParams(policy, "")) |
| + } |
| + if err == nil { |
| + thread, err = codex.CheckThread(raw, b.Model, "") |
| + } |
| + if err != nil { |
| + if tctx.Err() != nil { |
| + return cancelled() |
| + } |
| + e.log("step codex", err) |
| + return stepResult{reason: "policy_rejected", tail: tail.String()} |
| + } |
| + raw, _, err = rpc.Call(tctx, "turn/start", codex.TurnParams(policy, thread, spec.prompt)) |
| + var started struct { |
| + Turn struct{ ID string } `json:"turn"` |
| + } |
| + if err != nil || json.Unmarshal(raw, &started) != nil || started.Turn.ID == "" { |
| + if tctx.Err() != nil { |
| + return cancelled() |
| + } |
| + return stepResult{reason: "provider_failed", tail: tail.String()} |
| + } |
| + turnID := started.Turn.ID |
| + tally := connect.NewCodexTally(thread, true) |
| + tally.Begin(turnID) |
| + usage := func() []wire.Usage { |
| + row := tally.Row() |
| + row.Model = b.Model |
| + return []wire.Usage{row} |
| + } |
| + var seen *connect.Limit |
| + final, lastActivity := "", "" |
| + items := map[string]codexItem{} |
| + written := 0 |
| + for { |
| + select { |
| + case <-tctx.Done(): |
| + ictx, stop := context.WithTimeout(context.Background(), 2*time.Second) |
| + _, _, _ = rpc.Call(ictx, "turn/interrupt", map[string]string{"threadId": thread, "turnId": turnID}) |
| + stop() |
| + res := cancelled() |
| + res.tokens, res.session = usage(), thread |
| + return res |
| + case m, ok := <-rpc.Messages: |
| + if !ok { |
| + return stepResult{reason: "provider_failed", tail: tail.String(), tokens: usage(), session: thread} |
| + } |
| + if line, err := json.Marshal(map[string]any{"method": m.Method, "params": m.Params}); err == nil && written+len(line) < stepLogLimit { |
| + n, _ := logFile.Write(append(line, '\n')) |
| + written += n |
| + } |
| + if len(m.ID) > 0 { |
| + answerApproval(rpc, m, items, spec.names) |
| + continue |
| + } |
| + var n struct { |
| + ThreadID string `json:"threadId"` |
| + Item codexItem `json:"item"` |
| + Turn json.RawMessage `json:"turn"` |
| + RateLimits json.RawMessage `json:"rateLimits"` |
| + } |
| + if json.Unmarshal(m.Params, &n) != nil { |
| + continue |
| + } |
| + if n.ThreadID != "" && n.ThreadID != thread { |
| + return stepResult{reason: "policy_rejected", tail: tail.String(), tokens: usage(), session: thread} |
| + } |
| + switch m.Method { |
| + case "item/started": |
| + if n.Item.Type == "mcpToolCall" { |
| + items[n.Item.ID] = n.Item |
| + } |
| + kind, subject, line := itemActivity(n.Item) |
| + if line != "" { |
| + tail.add(line) |
| + } |
| + if kind != "" && spec.activity != nil && kind+"\x00"+subject != lastActivity { |
| + lastActivity = kind + "\x00" + subject |
| + spec.activity(kind, subject) |
| + } |
| + case "item/completed": |
| + if n.Item.Type == "agentMessage" && strings.TrimSpace(n.Item.Text) != "" { |
| + final = n.Item.Text |
| + tail.add(final) |
| + } |
| + delete(items, n.Item.ID) |
| + case "account/rateLimits/updated": |
| + if l, _, ok := connect.CodexRateLimits(n.RateLimits); ok { |
| + seen = &l |
| + } |
| + case "thread/tokenUsage/updated": |
| + if th, turn, total, last, ok := connect.CodexNotice(m.Params); ok { |
| + tally.Notice(th, turn, total, last) |
| + } |
| + case "turn/completed": |
| + var t struct { |
| + ID string `json:"id"` |
| + Status string `json:"status"` |
| + Error json.RawMessage `json:"error"` |
| + } |
| + if json.Unmarshal(n.Turn, &t) != nil || t.ID != turnID { |
| + continue |
| + } |
| + tally.End() |
| + res := stepResult{tail: tail.String(), tokens: usage(), session: thread} |
| + if t.Status == "completed" { |
| + res.summary, res.seen = final, seen |
| + return res |
| + } |
| + switch failure := connect.CodexFailure(t.Error); { |
| + case ctx.Err() != nil || t.Status == "interrupted": |
| + res.reason = "cancelled" |
| + case failure == connect.FailQuota || seen != nil && seen.Limited: |
| + l := connect.Limit{Limited: true} |
| + if seen != nil { |
| + l = *seen |
| + l.Limited = true |
| + } |
| + res.reason, res.limit = "limited", &l |
| + case failure == connect.FailAuth: |
| + res.reason, res.auth = "sign_in_again", true |
| + default: |
| + res.reason, res.summary, res.seen = "provider_failed", final, seen |
| + } |
| + return res |
| + } |
| + } |
| + } |
| +} |
| + |
| +// itemActivity is what a Codex item shows: the activity kind and its |
| +// subject (clipped), and the line it adds to the step's tail. |
| +func itemActivity(it codexItem) (kind, subject, line string) { |
| + switch it.Type { |
| + case "commandExecution": |
| + kind, subject = wire.ActivityRun, it.Command |
| + case "fileChange": |
| + kind = wire.ActivityEdit |
| + if len(it.Changes) > 0 { |
| + subject = it.Changes[0].Path |
| + } |
| + case "mcpToolCall": |
| + kind, line = wire.ActivityOther, it.Tool |
| + default: |
| + return "", "", "" |
| + } |
| + subject = strings.TrimPrefix(strings.TrimSpace(strings.SplitN(strings.TrimSpace(subject), "\n", 2)[0]), "/workspace/") |
| + if line == "" { |
| + line = map[string]string{wire.ActivityRun: "Bash ", wire.ActivityEdit: "Edit "}[kind] + subject |
| + } |
| + return kind, clip(subject, wire.MaxActivitySubject), line |
| +} |
diff --git a/internal/runner/thin/codexstep_test.go b/internal/runner/thin/codexstep_test.go| new file mode 100644 |
| index 00000000..f9ef3143 |
| --- /dev/null |
| +++ b/internal/runner/thin/codexstep_test.go |
| @@ -0,0 +1,108 @@ |
| +package thin |
| + |
| +import ( |
| + "bufio" |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "io" |
| + "net" |
| + "slices" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/connect" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// A Codex step approves only its own tools, and only the call Codex |
| +// started with those exact arguments; shell, patch and anything else the |
| +// app-server asks is refused. |
| +func TestCodexStepApprovals(t *testing.T) { |
| + var out bytes.Buffer |
| + rpc := connect.NewAppServer(strings.NewReader(""), &out) |
| + items := map[string]codexItem{ |
| + "a": {ID: "a", Type: "mcpToolCall", Server: "equipo", Tool: "submit_review", Arguments: json.RawMessage(`{"verdict":"approve","headline":"Approved.","summary":"ok"}`)}, |
| + "b": {ID: "b", Type: "mcpToolCall", Server: "equipo", Tool: "status", Arguments: json.RawMessage(`{}`)}, |
| + } |
| + names := []string{"submit_review", "ask_person"} |
| + elicit := func(server, args string) json.RawMessage { |
| + return json.RawMessage(`{"serverName":"` + server + `","mode":"form","_meta":{"codex_approval_kind":"mcp_tool_call","tool_params":` + args + `}}`) |
| + } |
| + for _, tc := range []struct { |
| + name, method string |
| + params json.RawMessage |
| + want string |
| + }{ |
| + {"own tool, same arguments", "mcpServer/elicitation/request", elicit("equipo", `{"summary":"ok","verdict":"approve","headline":"Approved."}`), `"accept"`}, |
| + {"own tool, other arguments", "mcpServer/elicitation/request", elicit("equipo", `{"verdict":"changes_requested","headline":"x","summary":"ok"}`), `"decline"`}, |
| + {"a tool the step does not have", "mcpServer/elicitation/request", elicit("equipo", `{}`), `"decline"`}, |
| + {"another server", "mcpServer/elicitation/request", elicit("other", `{"verdict":"approve","headline":"Approved.","summary":"ok"}`), `"decline"`}, |
| + {"shell", "item/commandExecution/requestApproval", json.RawMessage(`{"command":"curl example.com"}`), `refused by policy`}, |
| + {"patch", "item/fileChange/requestApproval", json.RawMessage(`{}`), `refused by policy`}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + out.Reset() |
| + answerApproval(rpc, connect.Message{ID: json.RawMessage(`"s1"`), Method: tc.method, Params: tc.params}, items, names) |
| + if !strings.Contains(out.String(), tc.want) || tc.want == `"decline"` && strings.Contains(out.String(), `"accept"`) { |
| + t.Fatalf("answer %s, want %s", out.String(), tc.want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A Codex step's tool socket lists only the step's tools: Codex asks |
| +// through the app-server, so there is no permission tool to call. |
| +func TestCodexStepSocketHasNoPermission(t *testing.T) { |
| + a, b := net.Pipe() |
| + defer a.Close() |
| + call := func(context.Context, string, string, json.RawMessage) (string, bool) { return "Recorded.", false } |
| + go serveMCP(context.Background(), b, toolSet{list: reviewTools, names: []string{"submit_review", "ask_person"}}, call) |
| + r := bufio.NewReader(a) |
| + ask := func(q string) map[string]any { |
| + t.Helper() |
| + if _, err := io.WriteString(a, q+"\n"); err != nil { |
| + t.Fatal(err) |
| + } |
| + line, err := r.ReadBytes('\n') |
| + var v map[string]any |
| + if err != nil || json.Unmarshal(line, &v) != nil { |
| + t.Fatal(err) |
| + } |
| + return v |
| + } |
| + ask(`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}`) |
| + var names []string |
| + for _, tool := range ask(`{"jsonrpc":"2.0","id":2,"method":"tools/list"}`)["result"].(map[string]any)["tools"].([]any) { |
| + names = append(names, tool.(map[string]any)["name"].(string)) |
| + } |
| + if !slices.Equal(names, []string{"submit_review", "ask_person"}) { |
| + t.Fatalf("tools %v", names) |
| + } |
| + if v := ask(`{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"permission","arguments":{"tool_name":"Bash","input":{}}}}`); v["error"] == nil { |
| + t.Fatalf("permission answered on a Codex step: %v", v) |
| + } |
| +} |
| + |
| +// What a Codex step shows while it runs: commands and file changes, |
| +// without the /workspace prefix, and the tools it calls. |
| +func TestCodexStepActivity(t *testing.T) { |
| + edit := codexItem{Type: "fileChange"} |
| + edit.Changes = append(edit.Changes, struct { |
| + Path string `json:"path"` |
| + }{Path: "/workspace/README.md"}) |
| + for _, tc := range []struct { |
| + item codexItem |
| + kind, subject, line string |
| + }{ |
| + {codexItem{Type: "commandExecution", Command: "go test ./...\nsecond line"}, wire.ActivityRun, "go test ./...", "Bash go test ./..."}, |
| + {edit, wire.ActivityEdit, "README.md", "Edit README.md"}, |
| + {codexItem{Type: "mcpToolCall", Server: "equipo", Tool: "submit_candidate"}, wire.ActivityOther, "", "submit_candidate"}, |
| + {codexItem{Type: "reasoning", Text: "secret plan"}, "", "", ""}, |
| + } { |
| + kind, subject, line := itemActivity(tc.item) |
| + if kind != tc.kind || subject != tc.subject || line != tc.line { |
| + t.Fatalf("%+v: %q %q %q", tc.item, kind, subject, line) |
| + } |
| + } |
| +} |
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go| index b4f72212..d7e064b7 100644 |
| --- a/internal/runner/thin/engineer.go |
| +++ b/internal/runner/thin/engineer.go |
| @@ -52,7 +52,9 @@ type Engineer struct { |
| keptLast [2]int64 |
| keptAt time.Time |
| - O ClaudeOptions |
| + O ClaudeOptions |
| + // Codex pins the Codex binaries a step may run on a Codex connection. |
| + Codex CodexOptions |
| Clones *Clones |
| Forge Forge |
| // Authorize confirms the execution lease before the step starts and |
| @@ -552,8 +554,12 @@ func (e *Engineer) observe(id string, res stepResult) { |
| } |
| // run starts the CLI for the step in containment and waits for its |
| -// result, then for the namespace's exit. |
| +// result, then for the namespace's exit. A Codex connection runs the |
| +// app-server instead (runCodex). |
| func (e *Engineer) run(ctx context.Context, r stepRow, tree workspace.TaskTree, spec specialistRun) stepResult { |
| + if spec.binding.Provider == "codex" { |
| + return e.runCodex(ctx, r, tree, spec) |
| + } |
| o := e.O |
| b := spec.binding |
| direct, err := o.Runner.DirectBinding(b) |
diff --git a/internal/runner/thin/judge.go b/internal/runner/thin/judge.go| index a8ae5aa6..0466e514 100644 |
| --- a/internal/runner/thin/judge.go |
| +++ b/internal/runner/thin/judge.go |
| @@ -598,10 +598,10 @@ func verdictOf(args json.RawMessage) (verdict, headline, summary string, finding |
| } |
| // reviewer picks the account Review runs on, away from Engineering's: a |
| -// healthy account of another provider family when this runner can run |
| -// one (none yet: the thin runner runs Claude only until the Codex step |
| -// path lands), else another Claude account (same family), else a fresh |
| -// session on the same account (same family, same account). |
| +// healthy account of another provider family when this runner has one |
| +// (with connections; without them, Claude accounts only), else another |
| +// account of the same family, else a fresh session on the same account |
| +// (same family, same account). |
| func (e *Engineer) reviewer(ctx context.Context, person, avoid string) (runner.AccountBinding, string, error) { |
| if e.Conns != nil { |
| return e.reviewOn(ctx, person, avoid) |
diff --git a/internal/runner/thin/mcp.go b/internal/runner/thin/mcp.go| index 44c08455..78ce5f2f 100644 |
| --- a/internal/runner/thin/mcp.go |
| +++ b/internal/runner/thin/mcp.go |
| @@ -44,7 +44,8 @@ func openToolSocket(ctx context.Context, root string, call ToolFunc) (*toolSocke |
| // toolSet is what one process's tool socket serves: the tools it lists |
| // beside the permission callback, the names it may call, and the |
| -// callback's answer. |
| +// callback's answer (nil: no permission tool, as for Codex, which asks |
| +// through the app-server instead). |
| type toolSet struct { |
| list []any |
| names []string |
| @@ -213,8 +214,11 @@ func serveMCP(ctx context.Context, c net.Conn, set toolSet, call ToolFunc) { |
| reply["error"] = map[string]any{"code": -32600, "message": "not initialized"} |
| break |
| } |
| - permission := map[string]any{"name": "permission", "inputSchema": map[string]any{"type": "object", "properties": map[string]any{"tool_name": map[string]string{"type": "string"}, "tool_use_id": map[string]string{"type": "string"}, "input": map[string]string{"type": "object"}}, "required": []string{"tool_name", "input"}, "additionalProperties": false}} |
| - tools := append([]any{permission}, set.list...) |
| + tools := slices.Clone(set.list) |
| + if set.permission != nil { |
| + permission := map[string]any{"name": "permission", "inputSchema": map[string]any{"type": "object", "properties": map[string]any{"tool_name": map[string]string{"type": "string"}, "tool_use_id": map[string]string{"type": "string"}, "input": map[string]string{"type": "object"}}, "required": []string{"tool_name", "input"}, "additionalProperties": false}} |
| + tools = append([]any{permission}, tools...) |
| + } |
| reply["result"] = map[string]any{"tools": tools} |
| case "tools/call": |
| var p struct { |
| @@ -226,7 +230,7 @@ func serveMCP(ctx context.Context, c net.Conn, set toolSet, call ToolFunc) { |
| reply["error"] = map[string]any{"code": -32602, "message": "unavailable"} |
| break |
| } |
| - if p.Name == "permission" { |
| + if p.Name == "permission" && set.permission != nil { |
| reply["result"] = map[string]any{"content": []any{map[string]string{"type": "text", "text": set.permission(p.Arguments)}}} |
| break |
| } |
diff --git a/internal/runner/thin/run.go b/internal/runner/thin/run.go| index bb0a3d84..6a55d166 100644 |
| --- a/internal/runner/thin/run.go |
| +++ b/internal/runner/thin/run.go |
| @@ -206,7 +206,7 @@ func Run(ctx context.Context, c runner.Config, o Options) error { |
| if err = engine.Start(ctx); err != nil { |
| return err |
| } |
| - engineer := &Engineer{O: o.Claude, Clones: clones, Forge: fg, Authorize: link.Confirm, Owners: coordinatorPersons(c)(), MaxStep: o.MaxStep, Note: o.StepNote, Healthy: conns.Usable, Conns: conns, Delta: link.Delta, Activity: link.Activity, StepActivity: link.StepActivity, Retention: o.KeptRetention, Host: c.MachineLabel} |
| + engineer := &Engineer{O: o.Claude, Codex: o.Codex, Clones: clones, Forge: fg, Authorize: link.Confirm, Owners: coordinatorPersons(c)(), MaxStep: o.MaxStep, Note: o.StepNote, Healthy: conns.Usable, Conns: conns, Delta: link.Delta, Activity: link.Activity, StepActivity: link.StepActivity, Retention: o.KeptRetention, Host: c.MachineLabel} |
| link.Forget = engineer.RemoveKept |
| merges := &MergeWatch{State: state, Clones: clones, Git: c.GitPath, Notify: link.Notify, Logger: o.Logger, Every: o.MergeEvery} |
| if merges.Every <= 0 { |