oficina / equipo Public

fix: align Claude workspace approvals and report preflight diagnostics

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 488b79d07ee58598ef5340c742b8f5ef0a3e8e19 parent 1dc07df
11 files changed, +364 −16
  • docs/live-gate.md +5 −1
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md +186 −0
  • internal/runner/approval_once_test.go +27 −0
  • internal/runner/capture.go +6 −1
  • internal/runner/provider/claude/answers.go +11 −1
  • internal/runner/provider/claude/answers_test.go +1 −1
  • internal/runner/provider/claude/launcher.go +20 −5
  • internal/runner/provider/claude/launcher_test.go +4 −3
  • internal/runner/provider/claude/parity_test.go +84 −0
  • internal/runner/provider/types.go +4 −3
  • internal/runnerproto/questions.go +16 −1
diff --git a/docs/live-gate.md b/docs/live-gate.md
index 7a5d6c43..5a51c3db 100644
--- a/docs/live-gate.md
+++ b/docs/live-gate.md
@@ -41,7 +41,11 @@ launch evidence.
## Prepare the accounts and bounded inputs
-1. Review the branch and pending copy with Paul. Before upgrading an existing
+1. Review the branch and pending copy with Paul. Before any model prompt, run
+ the adapter Open preflight against the dedicated Claude home. Record the
+ closed-stdin exit code and first stderr line as a sanitized fixture, and pin
+ the observed outcome before certification continues. A failed preflight must
+ keep the connection unavailable. Before upgrading an existing
instance, stop its old runner and every process it launched. Migrations 0018 and 0019
retain evidence and charges while fencing unfinished work. Tasks with claimed
old work wait for an owner to use **Old runner stopped** on the task page.
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
index 2e841382..d87c61da 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
@@ -25511,3 +25511,189 @@ Exit 0:
ok amadan.net/oficina/equipo/internal/runner 0.003s
```
+
+## B1-I2
+
+Engineering sandboxed Bash auto-allows with failIfUnavailable and allowUnsandboxedCommands unchanged. Native filesystem rules allow only the attempt workspace; every deny remains. Review/Product keep their native read-only lists. Claude native requests now use the same durable profile approval and label path as Codex, preserving the exact request and requiring current authority before reply. Tests cover policy permission decisions, an outside-workspace Write, Allow once/Deny, durable approval and revoked authority. No new UI strings.
+
+Interpretations: Red command used TestClaudeEngineeringAutomaticWorkspace, TestClaudePreflightExitDiagnostic and TestClaudeApprovalJournalBeyondProfile in the adapter and runner packages. Policy tests assert the exact CLI configuration; they do not claim live sandbox certification.
+
+### B1-I23-red
+
+```text
+--- FAIL: TestClaudeEngineeringAutomaticWorkspace (0.06s)
+ parity_test.go:12: sandboxed Bash requires a person or weakens containment
+--- FAIL: TestClaudePreflightExitDiagnostic (0.23s)
+ parity_test.go:19: missing CLI diagnostic: claude_process_failed
+FAIL
+rastrillo-budget/v1 ran 287ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.289s
+--- FAIL: TestClaudeApprovalJournalBeyondProfile (0.24s)
+ approval_once_test.go:199: provider_policy_rejected
+FAIL
+rastrillo-budget/v1 ran 237ms
+FAIL amadan.net/oficina/equipo/internal/runner 0.240s
+FAIL
+```
+
+### B1-I23-green
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner -run '^TestClaude(EngineeringAutomaticWorkspace|PreflightExitDiagnostic|ApprovalJournalBeyondProfile|NativeAuthorization)$' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/provider/claude 0.500s
+ok amadan.net/oficina/equipo/internal/runner 0.182s
+```
+
+### B1-I2-mut-bash
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner -run '^TestClaude(EngineeringAutomaticWorkspace|PreflightExitDiagnostic|ApprovalJournalBeyondProfile|NativeAuthorization)$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestClaudeEngineeringAutomaticWorkspace (0.05s)
+ parity_test.go:22: sandboxed Bash requires a person or weakens containment
+FAIL
+rastrillo-budget/v1 ran 492ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.494s
+ok amadan.net/oficina/equipo/internal/runner 0.205s
+FAIL
+```
+
+### B1-I2-mut-workspace
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner -run '^TestClaude(EngineeringAutomaticWorkspace|PreflightExitDiagnostic|ApprovalJournalBeyondProfile|NativeAuthorization)$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestClaudeEngineeringAutomaticWorkspace (0.05s)
+ parity_test.go:26: workspace tool requires a person Write
+FAIL
+rastrillo-budget/v1 ran 514ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.516s
+ok amadan.net/oficina/equipo/internal/runner 0.178s
+FAIL
+```
+
+### B1-I2-mut-journal
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner -run '^TestClaude(EngineeringAutomaticWorkspace|PreflightExitDiagnostic|ApprovalJournalBeyondProfile|NativeAuthorization)$' -count=1`
+
+Exit 1:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/provider/claude 0.472s
+--- FAIL: TestClaudeApprovalJournalBeyondProfile (0.24s)
+ approval_once_test.go:206: provider_policy_rejected
+FAIL
+rastrillo-budget/v1 ran 243ms
+FAIL amadan.net/oficina/equipo/internal/runner 0.246s
+FAIL
+```
+
+### B1-I2-mut-authority
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner -run '^TestClaude(EngineeringAutomaticWorkspace|PreflightExitDiagnostic|ApprovalJournalBeyondProfile|NativeAuthorization)$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestClaudeNativeAuthorization (0.25s)
+ parity_test.go:65: revoked approval accepted
+FAIL
+rastrillo-budget/v1 ran 521ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.523s
+ok amadan.net/oficina/equipo/internal/runner 0.348s
+FAIL
+```
+
+### B1-I23-green-final
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaude' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/provider/claude 11.983s
+```
+
+
+## B1-I3
+
+Capture exposes its bounded redacted diagnostics after draining. Failed Claude preflight reports the process exit code, signal and first stderr line. The live-gate first step requires a dedicated-home Open preflight and sanitized observed fixture before any prompt. No real Claude invocation was made. No new UI strings.
+
+Interpretations: Red command used TestClaudeEngineeringAutomaticWorkspace, TestClaudePreflightExitDiagnostic and TestClaudeApprovalJournalBeyondProfile in the adapter and runner packages. Policy tests assert the exact CLI configuration; they do not claim live sandbox certification.
+
+### B1-I23-red
+
+```text
+--- FAIL: TestClaudeEngineeringAutomaticWorkspace (0.06s)
+ parity_test.go:12: sandboxed Bash requires a person or weakens containment
+--- FAIL: TestClaudePreflightExitDiagnostic (0.23s)
+ parity_test.go:19: missing CLI diagnostic: claude_process_failed
+FAIL
+rastrillo-budget/v1 ran 287ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.289s
+--- FAIL: TestClaudeApprovalJournalBeyondProfile (0.24s)
+ approval_once_test.go:199: provider_policy_rejected
+FAIL
+rastrillo-budget/v1 ran 237ms
+FAIL amadan.net/oficina/equipo/internal/runner 0.240s
+FAIL
+```
+
+### B1-I23-green
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude ./internal/runner -run '^TestClaude(EngineeringAutomaticWorkspace|PreflightExitDiagnostic|ApprovalJournalBeyondProfile|NativeAuthorization)$' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/provider/claude 0.500s
+ok amadan.net/oficina/equipo/internal/runner 0.182s
+```
+
+### B1-I3-mut-diagnostic
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePreflightExitDiagnostic$ -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestClaudePreflightExitDiagnostic (0.18s)
+ parity_test.go:38: missing CLI diagnostic: claude_process_failed: exit=1 signal=0 stderr=: <nil>
+FAIL
+rastrillo-budget/v1 ran 177ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.179s
+FAIL
+```
+
+### B1-I3-mut-diagnostic
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePreflightExitDiagnostic$ -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestClaudePreflightExitDiagnostic (0.18s)
+ parity_test.go:38: missing CLI diagnostic: claude_process_failed: exit=1 signal=0 stderr=: <nil>
+FAIL
+rastrillo-budget/v1 ran 177ms
+FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.179s
+FAIL
+```
+
+### B1-I23-green-final
+
+`CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaude' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/provider/claude 11.983s
+```
+
diff --git a/internal/runner/approval_once_test.go b/internal/runner/approval_once_test.go
index c4d83753..e7e8808f 100644
--- a/internal/runner/approval_once_test.go
+++ b/internal/runner/approval_once_test.go
@@ -188,3 +188,30 @@ func TestCodexApprovalJournalWriteFailure(t *testing.T) {
t.Fatal("partial approval transaction persisted")
}
}
+
+func TestClaudeApprovalJournalBeyondProfile(t *testing.T) {
+ b := directToolFixture(t)
+ j, _, session, _ := directFixture(t, "claude")
+ ctx := context.Background()
+ mustJournal(t, j.BeginTurn(ctx, session, directTurn()))
+ mustJournal(t, j.consumeTurn(ctx, session.AttemptKey, session.ID, "hello"))
+ b.Journal = j
+ b.Session = session
+ b.Agent.Provider = "claude"
+ b.Agent.AgentID = session.AttemptKey
+ b.Agent.ProviderSessionID = session.ID
+ ev := provider.Event{Kind: "request", RequestID: "permission:write", SessionID: session.ID, TurnID: b.TurnID, Payload: json.RawMessage(`{"tool_name":"Write","tool_use_id":"write","input":{"file_path":"/outside/file","content":"x"}}`)}
+ l := &nativeAnswerLauncher{event: ev}
+ relay := DirectQuestionRelay{Binding: b, Launcher: l, Current: func(context.Context, runnerproto.Question) (time.Time, error) { return b.LeaseDeadline, nil }, Answerer: func(context.Context, runnerproto.Question) (string, error) { return "person@example.com", nil }}
+ mustJournal(t, relay.Handle(ctx, ev, func(_ context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ if q.ValidateAnswer(runnerproto.QuestionAnswer{Behavior: "allow"}) != nil || q.ValidateAnswer(runnerproto.QuestionAnswer{Behavior: "deny"}) != nil {
+ t.Fatal("missing Allow once/Deny")
+ }
+ return runnerproto.QuestionAnswer{Behavior: "allow"}, nil
+ }))
+ var records []runnerproto.Question
+ mustJournal(t, j.readStates(ctx, "profile-approval", &records))
+ if len(records) != 1 {
+ t.Fatal("out-of-profile approval not journaled")
+ }
+}
diff --git a/internal/runner/capture.go b/internal/runner/capture.go
index 549e1f99..46f4dfac 100644
--- a/internal/runner/capture.go
+++ b/internal/runner/capture.go
@@ -178,6 +178,8 @@ func (f *captureFactory) Open(ctx context.Context, p provider.Process, l provide
var once sync.Once
var failure error
var failureMu sync.Mutex
+ var diagnosticMu sync.Mutex
+ var diagnosticText string
fail := func(e error) {
once.Do(func() {
failureMu.Lock()
@@ -205,6 +207,9 @@ func (f *captureFactory) Open(ctx context.Context, p provider.Process, l provide
diagnostics := make(chan error, 1)
go func() {
b, e := io.ReadAll(io.LimitReader(stderr, maxDiagnostics))
+ diagnosticMu.Lock()
+ diagnosticText = redactText(string(b), nil)
+ diagnosticMu.Unlock()
if e == nil {
_, e = io.Copy(io.Discard, stderr)
}
@@ -284,7 +289,7 @@ func (f *captureFactory) Open(ctx context.Context, p provider.Process, l provide
failureMu.Unlock()
close(done)
}()
- return &provider.Capture{Input: ci, Frames: frames, Done: done}, nil
+ return &provider.Capture{Input: ci, Frames: frames, Done: done, Diagnostics: func() string { diagnosticMu.Lock(); defer diagnosticMu.Unlock(); return diagnosticText }}, nil
}
func (j *Journal) AppendFrame(ctx context.Context, attempt, stream string, seq int64, frame []byte) error {
if attempt == "" || stream == "" || seq <= 0 || len(frame) > MaxFrameBytes || !uniqueFrame(frame) {
diff --git a/internal/runner/provider/claude/answers.go b/internal/runner/provider/claude/answers.go
index 7515b165..02868b06 100644
--- a/internal/runner/provider/claude/answers.go
+++ b/internal/runner/provider/claude/answers.go
@@ -19,6 +19,7 @@ type permissionRequest struct {
Input json.RawMessage `json:"input"`
}
type pendingPermission struct {
+ raw json.RawMessage
request permissionRequest
turn string
reply chan json.RawMessage
@@ -48,7 +49,7 @@ func (l *Launcher) Permission(ctx context.Context, session provider.Session, raw
return nil, errNotReady
}
id := "permission:" + rand.Text()
- p := &pendingPermission{request: q, turn: s.turn.ID, reply: make(chan json.RawMessage, 1)}
+ p := &pendingPermission{raw: bytes.Clone(raw), request: q, turn: s.turn.ID, reply: make(chan json.RawMessage, 1)}
if s.permissions == nil {
s.permissions = map[string]*pendingPermission{}
}
@@ -178,6 +179,15 @@ func (l *Launcher) respond(ctx context.Context, session provider.Session, a prov
if e != nil {
return e
}
+ if a.Behavior == "allow" && p.request.Tool != "AskUserQuestion" && p.request.Tool != "ask_person" {
+ if a.Authorize == nil {
+ return provider.ErrPolicy
+ }
+ ev := provider.Event{Kind: "request", SessionID: session.ID, TurnID: p.turn, RequestID: a.RequestID, Payload: p.raw}
+ if e = a.Authorize(ctx, ev); e != nil {
+ return e
+ }
+ }
delete(s.permissions, a.RequestID)
p.reply <- result
return nil
diff --git a/internal/runner/provider/claude/answers_test.go b/internal/runner/provider/claude/answers_test.go
index ed23e8e1..449cc346 100644
--- a/internal/runner/provider/claude/answers_test.go
+++ b/internal/runner/provider/claude/answers_test.go
@@ -105,7 +105,7 @@ func TestClaudePermissionResponseScopedMCPPolicy(t *testing.T) {
t.Fatal(e)
}
var settings struct{ Permissions struct{ Allow []string } }
- if json.Unmarshal(got.Settings, &settings) != nil || strings.Join(settings.Permissions.Allow, ",") != strings.Join(in.Tools, ",") {
+ if json.Unmarshal(got.Settings, &settings) != nil || !strings.HasPrefix(strings.Join(settings.Permissions.Allow, ","), strings.Join(in.Tools, ",")) {
t.Fatal("scoped MCP would fall through native permission hook", string(got.Settings))
}
in.Tools = []string{"mcp__equipo__publish"}
diff --git a/internal/runner/provider/claude/launcher.go b/internal/runner/provider/claude/launcher.go
index f9093cb1..15f7da84 100644
--- a/internal/runner/provider/claude/launcher.go
+++ b/internal/runner/provider/claude/launcher.go
@@ -133,10 +133,16 @@ func PolicyInputs(b provider.Binding, in provider.PolicyInputs, specialist, mode
nativeDenies = append(nativeDenies, tool+"(/"+path+")", tool+"(/"+path+"/**)")
}
}
+ allow := append([]string{}, in.Tools...)
+ for _, tool := range native {
+ if slices.Contains([]string{"Write", "Edit", "Read", "Glob", "Grep"}, tool) {
+ allow = append(allow, tool+"(//workspace/**)")
+ }
+ }
settings := map[string]any{
"disableAllHooks": true, "enabledPlugins": map[string]any{},
- "sandbox": map[string]any{"enabled": true, "failIfUnavailable": true, "allowUnsandboxedCommands": false, "autoAllowBashIfSandboxed": false, "excludedCommands": []string{}, "filesystem": map[string]any{"denyRead": denied, "denyWrite": denied}, "network": map[string]any{"allowUnixSockets": []string{}}},
- "permissions": map[string]any{"deny": nativeDenies, "allow": append([]string{}, in.Tools...)},
+ "sandbox": map[string]any{"enabled": true, "failIfUnavailable": true, "allowUnsandboxedCommands": false, "autoAllowBashIfSandboxed": true, "excludedCommands": []string{}, "filesystem": map[string]any{"denyRead": denied, "denyWrite": denied}, "network": map[string]any{"allowUnixSockets": []string{}}},
+ "permissions": map[string]any{"deny": nativeDenies, "allow": allow},
}
in.Settings, _ = json.Marshal(settings)
in.MCP = json.RawMessage(`{"mcpServers":{"equipo":{"type":"stdio","command":"/opt/equipo-tool-proxy","args":["--socket","/tool/equipo.sock"]}}}`)
@@ -381,14 +387,15 @@ drained:
select {
case e = <-cap.Done:
if e != nil {
- return nil, e
+ exit, _ := proc.Wait(ctx)
+ return nil, probeDiagnostic(exit, cap, e)
}
case <-ctx.Done():
return nil, ctx.Err()
}
exit, e := proc.Wait(ctx)
if e != nil || exit.Code != 0 || exit.Signal != 0 {
- return nil, errFailed
+ return nil, probeDiagnostic(exit, cap, e)
}
for _, raw := range frames {
var v struct {
@@ -397,7 +404,7 @@ drained:
}
json.Unmarshal(raw, &v)
if v.Type == "result" || v.Error {
- return nil, errFailed
+ return nil, probeDiagnostic(exit, cap, errFailed)
}
}
return frames, nil
@@ -783,3 +790,11 @@ func (l *Launcher) validateInit(s *sessionState, raw []byte) error {
}
return nil
}
+
+func probeDiagnostic(exit provider.Exit, cap *provider.Capture, cause error) error {
+ line := ""
+ if cap.Diagnostics != nil {
+ line = strings.SplitN(cap.Diagnostics(), "\n", 2)[0]
+ }
+ return fmt.Errorf("%w: exit=%d signal=%d stderr=%s: %v", errFailed, exit.Code, exit.Signal, line, cause)
+}
diff --git a/internal/runner/provider/claude/launcher_test.go b/internal/runner/provider/claude/launcher_test.go
index e33a3a6f..074539fc 100644
--- a/internal/runner/provider/claude/launcher_test.go
+++ b/internal/runner/provider/claude/launcher_test.go
@@ -172,13 +172,14 @@ func (f *captureFactory) Open(ctx context.Context, p provider.Process, l provide
if f.malformed && nth == 3 {
return &provider.Capture{Input: p.Stdin()}, nil
}
+ var diagnostics strings.Builder
frames := make(chan provider.Frame)
done := make(chan error, 1)
go func() {
defer p.Stdout().Close()
defer p.Stderr().Close()
stderrDone := make(chan struct{})
- go func() { io.Copy(io.Discard, p.Stderr()); close(stderrDone) }()
+ go func() { io.Copy(&diagnostics, p.Stderr()); close(stderrDone) }()
scan := bufio.NewScanner(p.Stdout())
scan.Buffer(make([]byte, 4096), MaxFrameBytes+1)
var seq int64
@@ -206,7 +207,7 @@ func (f *captureFactory) Open(ctx context.Context, p provider.Process, l provide
f.blocker = &blockedInput{underlying: input, started: make(chan struct{}), done: make(chan struct{})}
input = f.blocker
}
- return &provider.Capture{Input: input, Frames: frames, Done: done}, nil
+ return &provider.Capture{Input: input, Frames: frames, Done: done, Diagnostics: func() string { return diagnostics.String() }}, nil
}
type fixture struct {
@@ -331,7 +332,7 @@ func TestClaudeLaunchPolicy(t *testing.T) {
if sandbox["enabled"] != true || sandbox["failIfUnavailable"] != true || sandbox["allowUnsandboxedCommands"] != false {
t.Fatal("sandbox weakened")
}
- if sandbox["autoAllowBashIfSandboxed"] != false {
+ if sandbox["autoAllowBashIfSandboxed"] != true {
t.Fatal("automatic shell approval enabled")
}
if len(sandbox["excludedCommands"].([]any)) != 0 {
diff --git a/internal/runner/provider/claude/parity_test.go b/internal/runner/provider/claude/parity_test.go
new file mode 100644
index 00000000..4774b276
--- /dev/null
+++ b/internal/runner/provider/claude/parity_test.go
@@ -0,0 +1,84 @@
+package claude
+
+import (
+ "amadan.net/oficina/equipo/internal/runner/provider"
+ "bytes"
+ "context"
+ "encoding/json"
+ "slices"
+ "strings"
+ "testing"
+ "time"
+)
+
+func TestClaudeEngineeringAutomaticWorkspace(t *testing.T) {
+ f := fixtureFor(t, "Engineering")
+ var settings struct {
+ Sandbox map[string]any
+ Permissions struct{ Allow, Deny []string }
+ }
+ json.Unmarshal(f.inputs.Settings, &settings)
+ if settings.Sandbox["autoAllowBashIfSandboxed"] != true || settings.Sandbox["allowUnsandboxedCommands"] != false || settings.Sandbox["failIfUnavailable"] != true {
+ t.Fatal("sandboxed Bash requires a person or weakens containment")
+ }
+ for _, tool := range []string{"Write", "Edit", "Read", "Glob", "Grep"} {
+ if !slices.Contains(settings.Permissions.Allow, tool+"(//workspace/**)") {
+ t.Fatal("workspace tool requires a person", tool)
+ }
+ }
+ if slices.Contains(settings.Permissions.Allow, "Write") || len(settings.Permissions.Deny) == 0 {
+ t.Fatal("unscoped write or removed denials")
+ }
+}
+func TestClaudePreflightExitDiagnostic(t *testing.T) {
+ f := fixtureFor(t, "Engineering")
+ f.host.mode = "sandbox"
+ _, err := f.l.Open(context.Background(), f.launch)
+ if err == nil || !strings.Contains(err.Error(), "exit=1") || !strings.Contains(err.Error(), "Sandbox required but unavailable") {
+ t.Fatalf("missing CLI diagnostic: %v", err)
+ }
+}
+func TestClaudeOutOfWorkspaceOriginalAction(t *testing.T) {
+ f := fixtureFor(t, "Engineering")
+ raw, err := permissionResult(permissionRequest{Tool: "Write", Input: json.RawMessage(`{"file_path":"/outside/file","content":"x"}`)}, provider.Answer{Behavior: "allow"}, f.launch.Policy)
+ if err != nil || !strings.Contains(string(raw), "/outside/file") {
+ t.Fatal("explicit original action refused", err)
+ }
+}
+
+func TestClaudeNativeAuthorization(t *testing.T) {
+ f := fixtureFor(t, "Engineering")
+ s, events := openFixture(t, f)
+ f.l.mu.Lock()
+ state, _ := f.l.state(s)
+ state.active = true
+ state.turn = provider.Turn{ID: "turn"}
+ f.l.mu.Unlock()
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ defer cancel()
+ raw := json.RawMessage(`{"tool_name":"Write","tool_use_id":"outside","input":{"file_path":"/outside/file","content":"x"}}`)
+ done := make(chan error, 1)
+ go func() { _, err := f.l.Permission(ctx, s, raw); done <- err }()
+ ev := <-events
+ answer := provider.Answer{RequestID: ev.RequestID, TurnID: "turn", Behavior: "allow", Authorize: func(context.Context, provider.Event) error { return provider.ErrIdentity }}
+ if err := f.l.Respond(ctx, s, answer); err == nil {
+ t.Fatal("revoked approval accepted")
+ }
+ called := false
+ answer.Authorize = func(_ context.Context, got provider.Event) error {
+ called = true
+ if !bytes.Equal(got.Payload, raw) {
+ t.Fatal("request changed")
+ }
+ return nil
+ }
+ if err := f.l.Respond(ctx, s, answer); err != nil {
+ t.Fatal(err)
+ }
+ if !called {
+ t.Fatal("authority not checked")
+ }
+ if err := <-done; err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/internal/runner/provider/types.go b/internal/runner/provider/types.go
index b27bc731..85e0a436 100644
--- a/internal/runner/provider/types.go
+++ b/internal/runner/provider/types.go
@@ -128,9 +128,10 @@ type Frame struct {
// Capture is the durable I/O boundary. Adapters consume Frames through their
// own Decode([]byte) ([]Event, error), never directly from process stdout.
type Capture struct {
- Input io.WriteCloser
- Frames <-chan Frame
- Done <-chan error
+ Diagnostics func() string
+ Input io.WriteCloser
+ Frames <-chan Frame
+ Done <-chan error
}
type CaptureFactory interface {
diff --git a/internal/runnerproto/questions.go b/internal/runnerproto/questions.go
index f5650c93..657ed7c3 100644
--- a/internal/runnerproto/questions.go
+++ b/internal/runnerproto/questions.go
@@ -180,9 +180,24 @@ func (q Question) NativeApproval() (codex.NativeRequest, error) {
ToolCall json.RawMessage `json:"tool_call"`
Input json.RawMessage
}
- if q.Validate() != nil || q.Kind != "tool" || json.Unmarshal(q.RawRequest, &raw) != nil || !raw.Direct || raw.Provider != "codex" || raw.TurnID == "" {
+ if q.Validate() != nil || q.Kind != "tool" || json.Unmarshal(q.RawRequest, &raw) != nil || !raw.Direct || (raw.Provider != "codex" && raw.Provider != "claude") || raw.TurnID == "" {
return codex.NativeRequest{}, ErrInvalid
}
+ if raw.Provider == "claude" {
+ var original struct {
+ Tool string `json:"tool_name"`
+ ToolUseID string `json:"tool_use_id"`
+ Input json.RawMessage
+ }
+ if json.Unmarshal(raw.Request, &original) != nil || original.Tool == "" || original.Tool != raw.Name || !SameRequestJSON(raw.Input, original.Input) {
+ return codex.NativeRequest{}, ErrInvalid
+ }
+ item := original.ToolUseID
+ if item == "" {
+ item = q.PermissionID
+ }
+ return codex.NativeRequest{RequestID: q.PermissionID, ItemID: item, TurnID: raw.TurnID, SessionID: q.SessionID, Request: raw.Request}, nil
+ }
var frame struct {
Method string
Params json.RawMessage