oficina / equipo Public

Reduce live control prompts to the first tuple per provider

Co-Authored-By: Astra <noreply@openai.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev a5f18b851e88ea8f6a2918e60044910e59f78d1e parent 75ba867
24 files changed, +855 −37
  • docs/live-gate.md +1 −1
  • docs/superpowers/plans/CONTROLLER-REPORT-fewer-prompts.md +103 −0
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md +1 −0
  • internal/directlive/answer_source.go +58 −0
  • internal/directlive/answer_source_test.go +79 −0
  • internal/directlive/approval_controls_test.go +6 −1
  • internal/directlive/certificate.go +18 −2
  • internal/directlive/controls.go +5 −2
  • internal/directlive/coordinator_certificate_test.go +104 −1
  • internal/directlive/driver.go +6 −1
  • internal/directlive/driver_test.go +17 −1
  • internal/directlive/fewer_prompts_test.go +92 −0
  • internal/directlive/person_controls.go +12 −0
  • internal/directlive/probe_answers.go +7 −2
  • internal/directlive/probes.go +2 −2
  • internal/directlive/terminal.go +6 −0
  • internal/directlive/terminal_retry_test.go +76 −0
  • internal/directlive/turn.go +44 −4
  • internal/equipo/copy.go +1 −1
  • internal/equipotest/runner_release_test.go +3 −3
  • internal/release/manifest.go +17 −16
  • internal/runner/provider/person_controls.go +92 −0
  • internal/runner/provider/providertest/person_controls.go +68 −0
  • scripts/runner-release-check.py +37 −0

CI passed — run details

diff --git a/docs/live-gate.md b/docs/live-gate.md
index 4e55e343..913941bd 100644
--- a/docs/live-gate.md
+++ b/docs/live-gate.md
@@ -66,7 +66,7 @@ routing per tool; declines are allowed except where they leave Claude’s
staged-home isolation unproven. The account-change
check uses private copies of two connected accounts for each provider, leaving their credential sources
untouched. Human approval questions
-arrive through the terminal and expire after 60 seconds.
+arrive through the terminal for only the first specialist tuple of each provider, expire after 60 seconds, and are answered automatically for later tuples.
V1 does not refresh tokens. A manifest candidate records `certified_refresh:
null` and a reason. Egress permits only the provider's inference host. An expired
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-fewer-prompts.md b/docs/superpowers/plans/CONTROLLER-REPORT-fewer-prompts.md
new file mode 100644
index 00000000..84601b6a
--- /dev/null
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-fewer-prompts.md
@@ -0,0 +1,103 @@
+# Fewer prompts, 2026-11-05
+
+The first specialist tuple in run order uses a person for its controls, once
+per provider. Later tuples supply the expected answers automatically. Both
+sources use the same validation, 60-second answer deadline and production
+relay. The native approval receipt records the selected source too.
+
+Answer artifacts and control checks record `answered_by: "person"` or
+`"automatic"`. MCP questions inherit the active turn's control expectation
+and deadline; their proxy context previously lacked that information.
+Control checks count answers from their own control turns, so unrelated probe
+answers cannot satisfy them.
+
+Each manifest candidate needs `provider_checks.<provider>.person-answered-controls`
+for every provider it certifies. The reference identifies a certified tuple.
+The candidate builder and release checker verify that tuple's passing control
+checks, source attribution and hashed answer artifacts. Allow, deny and question
+answers are required. Workspace approval answers are verified when the provider
+requests approval; a workspace read that needs no approval still has to pass.
+Coordinator evidence cannot satisfy this requirement.
+
+The terminal retries misspellings, malformed JSON and JSON values that are not
+objects. It clears the previous line without extending the deadline. A parsed
+object still goes straight to `ValidateAnswer`, so an invalid structured answer
+fails normally. `TCIFLUSH` remains before each prompt.
+
+`docs/live-gate.md` changes one sentence under the brief's copy acceptance.
+The new `live.answer-retry` hint in `internal/equipo/copy.go` is individually
+marked `COPY REVIEW PENDING`: “Enter Allow once, Deny, or a valid JSON object.”
+The same hint is listed as pending in the existing Plan 3 copy inventory.
+No copy-review server was started. README prose is unchanged.
+
+## Verification
+
+Before implementation, these commands failed for the reported defects:
+
+- `CGO_ENABLED=0 go test ./internal/directlive -run '^TestControlTerminalRetriesTypos$' -count=1`: all three line endings failed on `Alloe once` with `runner.invalid`.
+- `CGO_ENABLED=0 go test ./internal/directlive -run '^TestCandidateRequiresPersonControls$' -count=1`: a candidate with no person-answered tuple was accepted.
+
+After implementation:
+
+- `CGO_ENABLED=0 go test ./internal/directlive -run '^Test(Candidate|CoordinatorManifest|ControlSources|AnswerSources|ControlTerminal|TerminalRetry)' -count=1`: passed. Covers run-order selection, validation, deadlines, false person proofs, typo retries, CR/LF/CRLF, valid but invalid answer objects, and queued-input flushing.
+- `CGO_ENABLED=0 go test ./internal/directlive -run '^TestFewerPromptsFakeCLI$' -count=1`: passed in 79.482 seconds. Both providers run Review first and Engineering second. The first tuples use a person; later tuples answer automatically through the production relay. Every control check passes and all answer artifacts have attribution. The fixture's workspace reads need no approval, giving six person answers total. The source-selection test also exercises workspace approval and counts eight answers. Removing one provider's proof, then both proofs, fails the same provider gate used by the candidate builder.
+- `CGO_ENABLED=0 go test ./internal/equipotest -run '^TestDirectReleaseRequiresCertification$' -count=1`: passed for both release targets. Missing person proof, automatic proof, missing provider checks, another provider's reference and changed answer artifacts all fail before a build.
+
+An early version of the driver test attempted to certify the fake CLI's entire
+bundle. It correctly failed because the fake Codex has no provider sandbox.
+The test now verifies its real control observations through the provider gate;
+separate synthetic candidate fixtures test complete manifest construction.
+No fake CLI bundle is represented as production certification.
+
+Each guard below was disabled separately. Every listed test failed for the
+protected behavior, with no compilation failures. The original source was
+restored after each test. Commands use `CGO_ENABLED=0 go test <package> -run
+'<pattern>' -count=1`.
+
+| Guard disabled | Package | Pattern | Observed failure |
+| --- | --- | --- | --- |
+| First tuple only | `./internal/directlive` | `^TestControlSourcesFollowRunOrder$` | Later Codex tuple selected a person |
+| Candidate provider requirement | `./internal/directlive` | `^TestCandidateRequiresPersonControls$` | Candidate accepted without person proof |
+| Individual answer attribution | `./internal/directlive` | `^TestCandidateRejectsFalsePersonProof$/automatic-answer$` | Automatic answer accepted as person proof |
+| Release provider requirement | `./internal/equipotest` | `^TestDirectReleaseRequiresCertification$/release$/no_person_controls$` | Synthetic release reached its fake build without person proof |
+| Typo recognition | `./internal/directlive` | `^TestControlTerminalRetriesTypos$` | Misspelling ended each control |
+| Parsed-object validation | `./internal/directlive` | `^TestTerminalRetryDeadlineAndValidObject$/object$` | `{}` was accepted |
+| Deadline enforcement | `./internal/directlive` | `^TestTerminalRetryDeadlineAndValidObject$/deadline$` | Typo loop outlived its deadline |
+| Input flushing | `./internal/directlive` | `^TestControlTerminalFlushPending$` | Queued `Deny` answered the next allow prompt |
+
+The restored targeted commands passed again before the full gate.
+
+The first `make -k ci` completed with failures in size budgets and the Plan 3
+copy inventory. All other lanes passed. The app was one source line over its
+limit; the release tests were 26 test lines over. The inventory was missing the
+new hint. The fixture setup now lives with the existing provider test helpers,
+spare blank lines were removed, and the hint has its required inventory row.
+All existing budget limits remain unchanged. `make budget` and the targeted
+release, candidate and `TestPlan3ReleaseBoundaries` tests passed after repair.
+The new fake-driver test joins the existing parallel queue and three-worker
+limit, so it does not hold up unrelated fake-driver scenarios.
+
+The single full rerun, `make -k ci`, exited 0. It passed build, vet,
+formatting, staticcheck, govulncheck, gitleaks, size budgets, all 29 tested
+packages, adapter checks, namespace checks, migrations and performance.
+The test step took 5m31.608s; directlive took 4m11.981s, within its 360s budget.
+Cold boot measured 102ms against 500ms. There were no vulnerability findings
+in called code and no secret findings.
+
+Provider timing warnings were nonfatal locally: provider 20.656s against 15s,
+Claude 45.989s against 45s, and Codex 38.361s against 35s. CI mode enforces those
+timing limits, so equivalent load on the remote runner could still fail them.
+No timing allowance was raised. Total full gate runs: two, including one rerun.
+
+## Delivery
+
+OFFLINE ONLY: zero live provider launches and no account-home reads. Tests used
+disposable fake accounts and executables. No default-branch push, merge,
+deployment or execution enablement was attempted. Go caches stayed at their
+default locations.
+
+Delivery branch: `fewer-prompts`. Commit subject:
+`Reduce live control prompts to the first tuple per provider`.
+Commit body: `Co-Authored-By: Astra <noreply@openai.com>`.
+The verification scratch was removed. No process started for this task remains
+running. The branch is for controller review; deployment remains a human action.
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
index f2e6fabf..279687e1 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
@@ -5157,6 +5157,7 @@ records to satisfy a gate. Release remains blocked while any row is pending.
| `live.check-deny` | Equipo is checking that this is refused. Type Deny. | Guided live probe controls | COPY ACCEPTED FOR NOW (Paul, 2026-11-05; live-probe brief) |
| `live.check-allow` | Equipo is checking one-time approval. Type Allow once. | Guided live probe controls | COPY ACCEPTED FOR NOW (Paul, 2026-11-05; live-probe brief) |
| `live.check-question` | Equipo is checking that your answer reaches the agent. Enter an answers JSON object. | Guided live probe controls | COPY ACCEPTED FOR NOW (Paul, 2026-11-05; live-probe brief) |
+| `live.answer-retry` | Enter Allow once, Deny, or a valid JSON object. | Guided live control typo retry | COPY REVIEW REQUIRED |
| `CopyCalibrationFunding` | calibration funding is too low; rerun with JobInput=%d JobOutput=%d ProjectInputHeadroom=%d ProjectOutputHeadroom=%d TeamInputHeadroom=%d TeamOutputHeadroom=%d: %w | Direct isolation Round 3 | COPY REVIEW REQUIRED |
diff --git a/internal/directlive/answer_source.go b/internal/directlive/answer_source.go
new file mode 100644
index 00000000..8ad87498
--- /dev/null
+++ b/internal/directlive/answer_source.go
@@ -0,0 +1,58 @@
+package directlive
+
+import (
+ "context"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runnerproto"
+)
+
+type answerSource struct {
+ answeredBy string
+ read answerFunc
+}
+
+func (s answerSource) answer(ctx context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
+ defer cancel()
+ if err := ctx.Err(); err != nil {
+ return runnerproto.QuestionAnswer{}, err
+ }
+ a, err := s.read(ctx, q)
+ if err == nil {
+ err = ctx.Err()
+ }
+ if err == nil {
+ err = q.ValidateAnswer(a)
+ }
+ return a, err
+}
+
+func (d *driver) controlSource(family, role string) answerSource {
+ if d.personControls == nil {
+ d.personControls = map[string]bool{}
+ }
+ if role != "Coordinator" && !d.worker && !d.personControls[family] {
+ d.personControls[family] = true
+ return answerSource{"person", d.answer}
+ }
+ return answerSource{"automatic", expectedAnswer}
+}
+
+func expectedAnswer(ctx context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ expectation, _ := ctx.Value(probeExpectationKey{}).(probeExpectation)
+ a := runnerproto.QuestionAnswer{Behavior: expectation.behavior}
+ if expectation.behavior == "question" {
+ a.Behavior = "allow"
+ a.UpdatedInput = marshal(map[string]any{"answers": map[string]string{"answer": "ordinary"}})
+ }
+ return a, nil
+}
+
+func (x *exercise) source(ctx context.Context) answerSource {
+ expectation, _ := ctx.Value(probeExpectationKey{}).(probeExpectation)
+ if expectation.control != "" && x.controlSource.read != nil {
+ return x.controlSource
+ }
+ return answerSource{"person", x.d.answer}
+}
diff --git a/internal/directlive/answer_source_test.go b/internal/directlive/answer_source_test.go
new file mode 100644
index 00000000..c5c78179
--- /dev/null
+++ b/internal/directlive/answer_source_test.go
@@ -0,0 +1,79 @@
+package directlive
+
+import (
+ "context"
+ "errors"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runnerproto"
+)
+
+func TestControlSourcesFollowRunOrder(t *testing.T) {
+ calls := 0
+ d := driver{answer: func(ctx context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ calls++
+ return expectedAnswer(ctx, q)
+ }}
+ for _, family := range []string{"codex", "claude"} {
+ if got := d.controlSource(family, "Coordinator").answeredBy; got != "automatic" {
+ t.Fatal(got)
+ }
+ for i, role := range []string{"Review", "Engineering", "Engineering-reproduction", "Copy"} {
+ source := d.controlSource(family, role)
+ want := "automatic"
+ if i == 0 {
+ want = "person"
+ }
+ if source.answeredBy != want {
+ t.Fatalf("%s/%s: %s", family, role, source.answeredBy)
+ }
+ for _, control := range []string{"workspace", "allow", "deny", "question"} {
+ q := runnerproto.Question{Kind: "tool", RawRequest: []byte(`{"direct":true,"provider":"claude","name":"Read","input":{"file_path":"/workspace/sentinel"}}`)}
+ if control == "question" {
+ q.Kind = "person"
+ q.RawRequest = []byte(`{"kind":"person","question":"Which case?"}`)
+ }
+ a, err := source.answer(withControlExpectation(context.Background(), control), q)
+ want := "allow"
+ if control == "deny" {
+ want = "deny"
+ }
+ if err != nil || a.Behavior != want {
+ t.Fatalf("%s/%s/%s: %+v %v", family, role, control, a, err)
+ }
+ }
+ }
+ }
+ if calls != 8 {
+ t.Fatalf("person prompts = %d, want 8", calls)
+ }
+}
+
+func TestAnswerSourcesShareValidationAndDeadline(t *testing.T) {
+ for _, by := range []string{"person", "automatic"} {
+ t.Run(by, func(t *testing.T) {
+ s := answerSource{by, expectedAnswer}
+ q := runnerproto.Question{Kind: "other"}
+ ctx := withControlExpectation(context.Background(), "allow")
+ if _, err := s.answer(ctx, q); !errors.Is(err, runnerproto.ErrInvalid) {
+ t.Fatalf("invalid answer accepted: %v", err)
+ }
+ expired, cancel := context.WithDeadline(ctx, time.Now().Add(-time.Second))
+ defer cancel()
+ if _, err := s.answer(expired, q); !errors.Is(err, context.DeadlineExceeded) {
+ t.Fatalf("expired answer accepted: %v", err)
+ }
+ s.read = func(ctx context.Context, _ runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ deadline, ok := ctx.Deadline()
+ if !ok || time.Until(deadline) > 60*time.Second {
+ t.Fatal("missing answer deadline")
+ }
+ return runnerproto.QuestionAnswer{Behavior: "deny"}, nil
+ }
+ if _, err := s.answer(ctx, q); err != nil {
+ t.Fatal(err)
+ }
+ })
+ }
+}
diff --git a/internal/directlive/approval_controls_test.go b/internal/directlive/approval_controls_test.go
index cfcb8f1a..64487154 100644
--- a/internal/directlive/approval_controls_test.go
+++ b/internal/directlive/approval_controls_test.go
@@ -61,7 +61,7 @@ try:
while b'\n' in pending:
line,pending=pending.split(b'\n',1)
if line.startswith(b'Type Allow once, Deny,'):
- os.write(fd,answers[sent]+ending+(b'Allow once\n' if os.environ.get('EQUIPO_TEST_STALE_INPUT')=='1' else b''));sent+=1
+ os.write(fd,(b'Alloe once\r[]\rnull\r{broken\r \r' if os.environ.get('EQUIPO_TEST_TYPOS')=='1' else b'')+answers[sent]+ending+(b'Allow once\n' if os.environ.get('EQUIPO_TEST_STALE_INPUT')=='1' else b''));sent+=1
_,status=os.waitpid(pid,0)
print(output.decode())
sys.exit(os.waitstatus_to_exitcode(status))
@@ -94,3 +94,8 @@ func TestControlTerminalFlushPending(t *testing.T) {
t.Setenv("EQUIPO_TEST_STALE_INPUT", "1")
TestControlTerminalRawReturn(t)
}
+
+func TestControlTerminalRetriesTypos(t *testing.T) {
+ t.Setenv("EQUIPO_TEST_TYPOS", "1")
+ TestControlTerminalRawReturn(t)
+}
diff --git a/internal/directlive/certificate.go b/internal/directlive/certificate.go
index 3986f1f9..8ccd6ad9 100644
--- a/internal/directlive/certificate.go
+++ b/internal/directlive/certificate.go
@@ -20,6 +20,7 @@ func ManifestCandidate(root string) error {
return errEvidence
}
m := release.BuildManifest()
+ m.ProviderChecks = map[string]map[string]release.Certification{}
m.DirectPolicies = nil
m.Certifications = nil
m.VerifiedIsolationTuples = nil
@@ -58,6 +59,9 @@ func ManifestCandidate(root string) error {
m.DirectPolicies = append(m.DirectPolicies, c)
destination := filepath.Join("internal/release/evidence", provider.DigestDirectEvidence([]byte(e.RunID))[:16], name)
m.Certifications = append(m.Certifications, release.Certification{Provider: e.Provider, PolicyHash: e.PolicyHash, Path: destination, SHA256: digest, DirectIsolationSHA256: e.Checks["direct-isolation"].SHA256})
+ if e.ValidatePersonControls(filepath.Dir(path)) == nil {
+ m.ProviderChecks[e.Provider] = map[string]release.Certification{provider.PersonAnsweredControls: m.Certifications[len(m.Certifications)-1]}
+ }
m.VerifiedIsolationTuples = append(m.VerifiedIsolationTuples, team.IsolationTuple{Provider: e.Provider, ProviderVersion: e.ProviderVersion, LauncherVersion: e.LauncherVersion, BwrapVersion: e.BwrapVersion, PolicyVersion: e.PolicyVersion, IsolationConfigHash: e.PolicyHash})
if binaries != nil && string(marshal(binaries)) != string(marshal(e.Binaries)) {
return errEvidence
@@ -67,8 +71,8 @@ func ManifestCandidate(root string) error {
}
binaries = e.Binaries
}
- if len(m.DirectPolicies) == 0 {
- return errEvidence
+ if err := requireProviderControls(m); err != nil {
+ return err
}
for _, name := range []string{"claude", "codex", "codex-code-mode-host", "bwrap", "equipo-tool-proxy"} {
version := map[string]string{"claude": m.Claude, "codex": m.Codex, "codex-code-mode-host": m.Codex, "bwrap": m.BwrapVersion, "equipo-tool-proxy": m.LauncherVersion}[name]
@@ -76,3 +80,15 @@ func ManifestCandidate(root string) error {
}
return save(root, "candidate-manifest.json", m)
}
+
+func requireProviderControls(m release.Manifest) error {
+ if len(m.DirectPolicies) == 0 {
+ return errEvidence
+ }
+ for _, c := range m.DirectPolicies {
+ if _, ok := m.ProviderChecks[c.Provider][provider.PersonAnsweredControls]; !ok {
+ return errEvidence
+ }
+ }
+ return nil
+}
diff --git a/internal/directlive/controls.go b/internal/directlive/controls.go
index cd6dd9ae..3ef752d6 100644
--- a/internal/directlive/controls.go
+++ b/internal/directlive/controls.go
@@ -62,13 +62,16 @@ func (x *exercise) controls(ctx context.Context) error {
}
}
x.mu.Lock()
- checks := map[string]bool{"person-native-approval": x.answers["allow"] > 0 && x.answers["deny"] > 0, "real-question-answer": x.questions > 0, "policy-escalation-denied": x.escalationDenied, "equipo-broker-approval": x.brokerApprovals > 0, "stale-broker-denied": x.staleDenied, "invalid-broker-denied": x.invalidDenied}
+ checks := map[string]bool{"person-native-approval": x.controlPassed["allow"] && x.controlPassed["deny"], "real-question-answer": x.controlPassed["question"], "policy-escalation-denied": x.escalationDenied, "equipo-broker-approval": x.brokerApprovals > 0, "stale-broker-denied": x.staleDenied, "invalid-broker-denied": x.invalidDenied}
x.mu.Unlock()
for name, ok := range checks {
- if err := x.check(name, ok, map[string]any{"answers": x.answers, "questions": x.questions, "broker_approvals": x.brokerApprovals, "stale_denied": x.staleDenied, "invalid_denied": x.invalidDenied}); err != nil {
+ if err := x.check(name, ok, map[string]any{"answered_by": x.controlSource.answeredBy, "answers": x.answers, "questions": x.questions, "broker_approvals": x.brokerApprovals, "stale_denied": x.staleDenied, "invalid_denied": x.invalidDenied}); err != nil {
return err
}
}
+ if err := x.personControlCheck(); err != nil {
+ return err
+ }
return x.namespaceChecks(ctx)
}
func (x *exercise) namespaceChecks(ctx context.Context) error {
diff --git a/internal/directlive/coordinator_certificate_test.go b/internal/directlive/coordinator_certificate_test.go
index 11a1b44c..18fd1270 100644
--- a/internal/directlive/coordinator_certificate_test.go
+++ b/internal/directlive/coordinator_certificate_test.go
@@ -14,7 +14,7 @@ import (
"amadan.net/oficina/equipo/internal/runner/provider/providertest"
)
-func TestCoordinatorManifestExclusion(t *testing.T) {
+func candidateFixture(t *testing.T) string {
root := t.TempDir()
raw := []byte("synthetic manifest-selection fixture")
hash := provider.DigestDirectEvidence(raw)
@@ -65,6 +65,12 @@ func TestCoordinatorManifestExclusion(t *testing.T) {
if err := save(root, "index.json", []string{"specialist/certification.json", "coordinator/certification.json"}); err != nil {
t.Fatal(err)
}
+ return root
+}
+
+func TestCoordinatorManifestExclusion(t *testing.T) {
+ root := candidateFixture(t)
+ addCandidatePersonProof(t, root)
if err := ManifestCandidate(root); err != nil {
t.Fatal("coordinator failure blocked specialist candidate", err)
}
@@ -103,3 +109,100 @@ func TestMergedPlanPolicyInventory(t *testing.T) {
}
}
}
+
+func TestCandidateRequiresPersonControls(t *testing.T) {
+ root := candidateFixture(t)
+ if err := ManifestCandidate(root); err == nil {
+ t.Fatal("candidate accepted a run with no person-answered tuple")
+ }
+}
+
+func addCandidatePersonProof(t *testing.T, root string) {
+ t.Helper()
+ dir := filepath.Join(root, "specialist")
+ raw, err := os.ReadFile(filepath.Join(dir, "certification.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var e provider.DirectEvidence
+ if err = json.Unmarshal(raw, &e); err != nil {
+ t.Fatal(err)
+ }
+ providertest.PersonControls(t, dir, &e, "")
+ if err = os.WriteFile(filepath.Join(dir, "certification.json"), marshal(e), 0600); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestCandidateRejectsFalsePersonProof(t *testing.T) {
+ for _, mode := range []string{"automatic-proof", "automatic-answer", "wrong-answer", "missing-question", "failed-control", "failed-tuple", "bad-answer-hash"} {
+ t.Run(mode, func(t *testing.T) {
+ root := candidateFixture(t)
+ addCandidatePersonProof(t, root)
+ dir := filepath.Join(root, "specialist")
+ raw, err := os.ReadFile(filepath.Join(dir, "certification.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var e provider.DirectEvidence
+ if err = json.Unmarshal(raw, &e); err != nil {
+ t.Fatal(err)
+ }
+ proofRef := e.Checks[provider.PersonAnsweredControls]
+ raw, err = os.ReadFile(filepath.Join(dir, proofRef.Artifact))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var proof provider.PersonControlProof
+ if err = json.Unmarshal(raw, &proof); err != nil {
+ t.Fatal(err)
+ }
+ switch mode {
+ case "automatic-proof":
+ proof.AnsweredBy = "automatic"
+ case "missing-question":
+ delete(proof.Answers, "question")
+ case "failed-control", "failed-tuple":
+ key := "person-native-approval"
+ if mode == "failed-tuple" {
+ key = "tuple-completed"
+ }
+ o := e.Checks[key]
+ o.Status = "not-certified"
+ e.Checks[key] = o
+ default:
+ o := proof.Answers["allow"][0]
+ raw, err = os.ReadFile(filepath.Join(dir, o.Artifact))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if mode == "wrong-answer" {
+ raw = []byte(strings.Replace(string(raw), `"behavior":"allow"`, `"behavior":"deny"`, 1))
+ } else {
+ raw = []byte(strings.Replace(string(raw), `"person"`, `"automatic"`, 1))
+ }
+ if err = os.WriteFile(filepath.Join(dir, o.Artifact), raw, 0600); err != nil {
+ t.Fatal(err)
+ }
+ e.Artifacts[o.Artifact] = provider.DigestDirectEvidence(raw)
+ if mode != "bad-answer-hash" {
+ o.SHA256 = e.Artifacts[o.Artifact]
+ proof.Answers["allow"][0] = o
+ }
+ }
+ raw = marshal(proof)
+ if err = os.WriteFile(filepath.Join(dir, proofRef.Artifact), raw, 0600); err != nil {
+ t.Fatal(err)
+ }
+ proofRef.SHA256 = provider.DigestDirectEvidence(raw)
+ e.Artifacts[proofRef.Artifact] = proofRef.SHA256
+ e.Checks[provider.PersonAnsweredControls] = proofRef
+ if err = os.WriteFile(filepath.Join(dir, "certification.json"), marshal(e), 0600); err != nil {
+ t.Fatal(err)
+ }
+ if err = ManifestCandidate(root); err == nil {
+ t.Fatal("false person proof accepted", mode)
+ }
+ })
+ }
+}
diff --git a/internal/directlive/driver.go b/internal/directlive/driver.go
index 6c3a63a5..0c32a117 100644
--- a/internal/directlive/driver.go
+++ b/internal/directlive/driver.go
@@ -27,6 +27,7 @@ func EnvironmentPaths(getenv func(string) string) Paths {
}
type driver struct {
+ personControls map[string]bool
currencyCap bool
invalidFrame bool
stagedMarker string
@@ -185,6 +186,10 @@ func (p Paths) verify() (map[string]string, error) {
func marshal(v any) []byte { raw, _ := json.Marshal(v); return raw }
type exercise struct {
+ controlPassed map[string]bool
+ answerContext context.Context
+ controlSource answerSource
+ controlAnswers map[string][]provider.LiveObservation
claudeSettings []claudeSettingsReadback
inputs provider.PolicyInputs
mu sync.Mutex
@@ -217,7 +222,7 @@ func (d *driver) exercise(ctx context.Context, b provider.DirectLiveBinding, rol
err = fmt.Errorf("%s: %w", phase, err)
}
}()
- x := &exercise{d: d, root: root, evidence: e, answers: map[string]int{}}
+ x := &exercise{d: d, root: root, evidence: e, answers: map[string]int{}, controlSource: d.controlSource(b.Binding.Provider, role)}
defer func() { e = x.evidence }()
scratch := d.workerRoot
if scratch == "" {
diff --git a/internal/directlive/driver_test.go b/internal/directlive/driver_test.go
index 8625aba8..43d5e6ad 100644
--- a/internal/directlive/driver_test.go
+++ b/internal/directlive/driver_test.go
@@ -32,6 +32,11 @@ func TestDirectDriverFakeCLI(t *testing.T) {
})
}
}
+func TestFewerPromptsFakeCLI(t *testing.T) {
+ t.Parallel()
+ runFakeDriver(t, false, "EQUIPO_FAKE_FEWER_PROMPTS=1")
+}
+
func runFakeDriver(t *testing.T, badCoordinator bool, env ...string) {
t.Helper()
defer fakeDriverWorkers.acquire()()
@@ -125,7 +130,12 @@ func TestDirectDriverFakeWorker(t *testing.T) {
}
}
p := Paths{Claude: filepath.Join(root, "claude"), Codex: filepath.Join(root, "codex"), CodeModeHost: filepath.Join(root, "codex-code-mode-host"), Bwrap: "/usr/bin/bwrap", Runner: os.Args[0], ToolProxy: filepath.Join(root, "equipo-tool-proxy")}
- answer := func(_ context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ personCalls := 0
+ answer := func(ctx context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
+ if os.Getenv("EQUIPO_FAKE_FEWER_PROMPTS") == "1" {
+ personCalls++
+ return expectedAnswer(ctx, q)
+ }
if q.Kind == "person" || q.Kind == "question" {
return runnerproto.QuestionAnswer{Behavior: "allow", UpdatedInput: json.RawMessage(`{"answers":{"answer":"fixture"}}`)}, nil
}
@@ -185,6 +195,9 @@ func TestDirectDriverFakeWorker(t *testing.T) {
if os.Getenv("EQUIPO_FAKE_BAD_COORDINATOR") == "1" {
roles = []string{"Engineering", "Coordinator"}
}
+ if os.Getenv("EQUIPO_FAKE_FEWER_PROMPTS") == "1" {
+ roles = []string{"Review", "Engineering"}
+ }
source := "fake-cli"
if os.Getenv("EQUIPO_FAKE_LIVE_MODE") == "1" {
source = "direct-live"
@@ -206,6 +219,9 @@ func TestDirectDriverFakeWorker(t *testing.T) {
if os.Getenv("EQUIPO_FAKE_COORDINATOR_ONLY") == "1" && ManifestCandidate(c.EvidenceDir) == nil {
t.Fatal("coordinator-only observations became release authority")
}
+ if os.Getenv("EQUIPO_FAKE_FEWER_PROMPTS") == "1" {
+ checkFewerPromptRun(t, c.EvidenceDir, personCalls)
+ }
for path, before := range original {
raw, err := os.ReadFile(path)
if err != nil || string(raw) != before {
diff --git a/internal/directlive/fewer_prompts_test.go b/internal/directlive/fewer_prompts_test.go
new file mode 100644
index 00000000..9c035ee9
--- /dev/null
+++ b/internal/directlive/fewer_prompts_test.go
@@ -0,0 +1,92 @@
+package directlive
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/release"
+ "amadan.net/oficina/equipo/internal/runner/provider"
+)
+
+func checkFewerPromptRun(t *testing.T, root string, calls int) {
+ t.Helper()
+ // The fake workspace read needs no approval, leaving three controls per provider.
+ if calls != 6 {
+ t.Fatalf("person prompts = %d, want 6", calls)
+ }
+ m := release.Manifest{ProviderChecks: map[string]map[string]release.Certification{}}
+ for _, family := range []string{"claude", "codex"} {
+ for _, role := range []string{"Review", "Engineering"} {
+ dir := filepath.Join(root, family+"-"+role)
+ raw, err := os.ReadFile(filepath.Join(dir, "certification.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var e provider.DirectEvidence
+ if err = json.Unmarshal(raw, &e); err != nil {
+ t.Fatal(err)
+ }
+ want := "automatic"
+ if role == "Review" {
+ want = "person"
+ }
+ if (e.ValidatePersonControls(dir) == nil) != (want == "person") {
+ t.Fatalf("%s/%s: wrong person proof", family, role)
+ }
+ m.DirectPolicies = append(m.DirectPolicies, release.PolicyCertificate{Provider: family, PolicyHash: e.PolicyHash})
+ if e.ValidatePersonControls(dir) == nil {
+ m.ProviderChecks[family] = map[string]release.Certification{provider.PersonAnsweredControls: {Provider: family, PolicyHash: e.PolicyHash}}
+ }
+ for _, name := range provider.ControlChecks {
+ if e.Checks[name].Status != "pass" {
+ t.Fatalf("%s/%s: %s failed", family, role, name)
+ }
+ raw, err = os.ReadFile(filepath.Join(dir, e.Checks[name].Artifact))
+ var check struct {
+ AnsweredBy string `json:"answered_by"`
+ }
+ if err != nil || json.Unmarshal(raw, &check) != nil || check.AnsweredBy != want {
+ t.Fatalf("%s/%s: %s attribution: %s %v", family, role, name, raw, err)
+ }
+ }
+ files, err := filepath.Glob(filepath.Join(dir, "answer-*.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ controls := 0
+ for _, file := range files {
+ raw, err = os.ReadFile(file)
+ var a struct {
+ AnsweredBy string `json:"answered_by"`
+ Control string `json:"control"`
+ }
+ if err != nil || json.Unmarshal(raw, &a) != nil {
+ t.Fatalf("answer: %s %v", raw, err)
+ }
+ if a.AnsweredBy != "automatic" && a.AnsweredBy != "person" {
+ t.Fatal("missing answer attribution")
+ }
+ if a.Control != "" {
+ controls++
+ if a.AnsweredBy != want {
+ t.Fatalf("%s: %s", file, a.AnsweredBy)
+ }
+ }
+ }
+ if controls != 3 {
+ t.Fatalf("%s/%s: %d controls", family, role, controls)
+ }
+ }
+ }
+ if err := requireProviderControls(m); err != nil {
+ t.Fatal("mixed-source run rejected", err)
+ }
+ for _, family := range []string{"codex", "claude"} {
+ delete(m.ProviderChecks, family)
+ if err := requireProviderControls(m); err == nil {
+ t.Fatal("run without person-answered controls certified", family)
+ }
+ }
+}
diff --git a/internal/directlive/person_controls.go b/internal/directlive/person_controls.go
new file mode 100644
index 00000000..abf05fda
--- /dev/null
+++ b/internal/directlive/person_controls.go
@@ -0,0 +1,12 @@
+package directlive
+
+import "amadan.net/oficina/equipo/internal/runner/provider"
+
+func (x *exercise) personControlCheck() error {
+ proof := provider.PersonControlProof{AnsweredBy: x.controlSource.answeredBy, Answers: x.controlAnswers}
+ ok := proof.Validate(x.root) == nil
+ for _, name := range provider.ControlChecks {
+ ok = ok && x.evidence.Checks[name].Status == "pass"
+ }
+ return x.check(provider.PersonAnsweredControls, ok, proof)
+}
diff --git a/internal/directlive/probe_answers.go b/internal/directlive/probe_answers.go
index 2eaaf709..ab0aeac1 100644
--- a/internal/directlive/probe_answers.go
+++ b/internal/directlive/probe_answers.go
@@ -5,14 +5,19 @@ import "context"
type probeExpectationKey struct{}
type probeExpectation struct {
behavior string
+ control string
automatic bool
}
func withProbeExpectation(ctx context.Context, behavior string) context.Context {
- return context.WithValue(ctx, probeExpectationKey{}, probeExpectation{behavior, true})
+ return context.WithValue(ctx, probeExpectationKey{}, probeExpectation{behavior: behavior, automatic: true})
}
func withControlExpectation(ctx context.Context, behavior string) context.Context {
- return context.WithValue(ctx, probeExpectationKey{}, probeExpectation{behavior, false})
+ control := behavior
+ if behavior == "workspace" {
+ behavior = "allow"
+ }
+ return context.WithValue(ctx, probeExpectationKey{}, probeExpectation{behavior: behavior, control: control})
}
func terminalGuidance(ctx context.Context) string {
expectation, _ := ctx.Value(probeExpectationKey{}).(probeExpectation)
diff --git a/internal/directlive/probes.go b/internal/directlive/probes.go
index a62df95e..35c08f95 100644
--- a/internal/directlive/probes.go
+++ b/internal/directlive/probes.go
@@ -159,11 +159,11 @@ func (x *exercise) probes(ctx context.Context, inventory []string) error {
x.mu.Lock()
x.probing = false
x.mu.Unlock()
- frames, err := x.turn(withControlExpectation(ctx, "allow"), prompt)
+ frames, err := x.turn(withControlExpectation(ctx, "workspace"), prompt)
if err != nil {
return err
}
- return x.check("workspace-positive-control", observedRead(x.evidence.Provider, frames, tool, path, false), map[string]any{"path": path, "turn": x.sequence})
+ return x.check("workspace-positive-control", observedRead(x.evidence.Provider, frames, tool, path, false), map[string]any{"path": path, "turn": x.sequence, "answered_by": x.controlSource.answeredBy})
}
func (x *exercise) calibration() error {
in, out, err := provider.DirectReservations(x.evidence.Usage)
diff --git a/internal/directlive/terminal.go b/internal/directlive/terminal.go
index ab989f6a..0af53b10 100644
--- a/internal/directlive/terminal.go
+++ b/internal/directlive/terminal.go
@@ -58,6 +58,7 @@ func terminalAnswer(ctx context.Context, q runnerproto.Question) (runnerproto.Qu
}
if b[0] == '\n' || b[0] == '\r' {
text := strings.TrimSpace(string(raw))
+ raw = raw[:0]
if text == "" {
continue
}
@@ -67,6 +68,11 @@ func terminalAnswer(ctx context.Context, q runnerproto.Question) (runnerproto.Qu
case "Deny":
answer.Behavior = "deny"
default:
+ var object map[string]json.RawMessage
+ if json.Unmarshal([]byte(text), &object) != nil || object == nil {
+ fmt.Fprintln(tty, equipo.RunnerText("live.answer-retry"))
+ continue
+ }
answer.Behavior = "allow"
answer.UpdatedInput = json.RawMessage(text)
}
diff --git a/internal/directlive/terminal_retry_test.go b/internal/directlive/terminal_retry_test.go
new file mode 100644
index 00000000..90523f55
--- /dev/null
+++ b/internal/directlive/terminal_retry_test.go
@@ -0,0 +1,76 @@
+package directlive
+
+import (
+ "context"
+ "errors"
+ "os"
+ "os/exec"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runnerproto"
+)
+
+func TestTerminalRetryDeadlineAndValidObject(t *testing.T) {
+ if mode := os.Getenv("EQUIPO_TEST_RETRY_MODE"); mode != "" {
+ ctx, cancel := context.WithTimeout(context.Background(), 600*time.Millisecond)
+ defer cancel()
+ q := runnerproto.Question{Kind: "person", RawRequest: []byte(`{"kind":"person","question":"Which case?"}`)}
+ _, err := terminalAnswer(withControlExpectation(ctx, "question"), q)
+ want := runnerproto.ErrInvalid
+ if mode == "deadline" {
+ want = context.DeadlineExceeded
+ }
+ if !errors.Is(err, want) {
+ t.Fatalf("answer error = %v, want %v", err, want)
+ }
+ return
+ }
+ script := `import os,pty,select,signal,sys,time
+pid,fd=pty.fork()
+if pid==0:
+ os.environ['EQUIPO_TEST_RETRY_MODE']=sys.argv[2]
+ os.execv(sys.argv[1],[sys.argv[1],'-test.run=^TestTerminalRetryDeadlineAndValidObject$'])
+output=b''; sent=False; reaped=False; end=time.monotonic()+3; last=0
+try:
+ while time.monotonic()<end:
+ if select.select([fd],[],[],0.05)[0]:
+ try:data=os.read(fd,65536)
+ except OSError:break
+ output+=data
+ if b'Type Allow once, Deny,' in output:
+ if sys.argv[2]=='object' and not sent:os.write(fd,b'{}\n');sent=True
+ if sys.argv[2]=='deadline' and time.monotonic()-last>0.15:os.write(fd,b'Alloe once\n');last=time.monotonic()
+ done,status=os.waitpid(pid,os.WNOHANG)
+ if done:reaped=True;break
+ if not reaped:
+ done,status=os.waitpid(pid,os.WNOHANG)
+ reaped=bool(done)
+ print(output.decode())
+ if not reaped:raise RuntimeError('answer deadline was extended')
+ if sys.argv[2]=='object' and b'Enter Allow once' in output:raise RuntimeError('valid JSON object was retried')
+ if sys.argv[2]=='deadline' and output.count(b'Enter Allow once')<2:raise RuntimeError('typos were not retried')
+ sys.exit(os.waitstatus_to_exitcode(status))
+finally:
+ if not reaped:
+ try:os.kill(pid,signal.SIGKILL)
+ except ProcessLookupError:pass
+ os.waitpid(pid,0)
+ os.close(fd)
+`
+ for _, mode := range []string{"object", "deadline"} {
+ t.Run(mode, func(t *testing.T) {
+ self, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ out, err := exec.CommandContext(ctx, "python3", "-c", script, self, mode).CombinedOutput()
+ if err != nil || !strings.Contains(string(out), "PASS") {
+ t.Fatalf("terminal retry: %s %v", out, err)
+ }
+ })
+ }
+}
diff --git a/internal/directlive/turn.go b/internal/directlive/turn.go
index 46d7c4fc..88cf9e88 100644
--- a/internal/directlive/turn.go
+++ b/internal/directlive/turn.go
@@ -25,7 +25,9 @@ func (x *exercise) relay() runner.DirectQuestionRelay {
return time.Time{}, provider.ErrIdentity
}
return x.binding.LeaseDeadline, nil
- }, Answerer: func(context.Context, runnerproto.Question) (string, error) { return "terminal-operator", nil }}
+ }, Answerer: func(ctx context.Context, _ runnerproto.Question) (string, error) {
+ return x.source(ctx).answeredBy, nil
+ }}
}
func (x *exercise) open(ctx context.Context, tool string) error {
deadline, _ := ctx.Deadline()
@@ -80,6 +82,10 @@ func (x *exercise) open(ctx context.Context, tool string) error {
return err
}
func (x *exercise) turn(ctx context.Context, prompt string) ([][]byte, error) {
+ x.mu.Lock()
+ x.answerContext = ctx
+ x.mu.Unlock()
+ defer func() { x.mu.Lock(); x.answerContext = nil; x.mu.Unlock() }()
d := x.d
beforeInput, beforeOutput := d.input, d.output
if err := d.reserveRecovery(); err != nil {
@@ -169,10 +175,22 @@ func (x *exercise) turn(ctx context.Context, prompt string) ([][]byte, error) {
func (x *exercise) answer(ctx context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
var a runnerproto.QuestionAnswer
var err error
+ answeredBy := "automatic"
expectation, _ := ctx.Value(probeExpectationKey{}).(probeExpectation)
x.mu.Lock()
- probing, routing := x.probing, x.routing
+ probing, routing, turnCtx := x.probing, x.routing, x.answerContext
x.mu.Unlock()
+ if turnCtx != nil {
+ if expectation.control == "" && !expectation.automatic {
+ expectation, _ = turnCtx.Value(probeExpectationKey{}).(probeExpectation)
+ ctx = context.WithValue(ctx, probeExpectationKey{}, expectation)
+ }
+ if deadline, ok := turnCtx.Deadline(); ok {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithDeadline(ctx, deadline)
+ defer cancel()
+ }
+ }
if probing || expectation.automatic && expectation.behavior == "deny" {
a.Behavior = "deny"
} else if (routing || expectation.automatic && expectation.behavior == "allow") && (q.Kind == "question" || q.Kind == "person") {
@@ -183,7 +201,9 @@ func (x *exercise) answer(ctx context.Context, q runnerproto.Question) (runnerpr
}
a.UpdatedInput = marshal(map[string]any{"answers": map[string]string{key: "Continue"}})
} else {
- a, err = x.d.answer(ctx, q)
+ source := x.source(ctx)
+ answeredBy = source.answeredBy
+ a, err = source.answer(ctx, q)
}
if err != nil {
return a, err
@@ -199,8 +219,28 @@ func (x *exercise) answer(ctx context.Context, q runnerproto.Question) (runnerpr
}
x.mu.Unlock()
name := fmt.Sprintf("answer-%d-%s.json", x.sequence, q.ID)
- if err = save(x.root, name, map[string]any{"question": q, "answer": a}); err != nil {
+ o, err := observation(x.root, name, "pass", map[string]any{"question": q, "answer": a, "answered_by": answeredBy, "control": expectation.control})
+ if err != nil {
return a, err
}
+ if expectation.control != "" {
+ x.mu.Lock()
+ if x.controlAnswers == nil {
+ x.controlAnswers = map[string][]provider.LiveObservation{}
+ }
+ if x.controlPassed == nil {
+ x.controlPassed = map[string]bool{}
+ }
+ matches := a.Behavior == expectation.behavior
+ if expectation.behavior == "question" {
+ matches = (q.Kind == "person" || q.Kind == "question") && a.Behavior == "allow"
+ }
+ if len(x.controlAnswers[expectation.control]) == 0 {
+ x.controlPassed[expectation.control] = true
+ }
+ x.controlPassed[expectation.control] = x.controlPassed[expectation.control] && matches
+ x.controlAnswers[expectation.control] = append(x.controlAnswers[expectation.control], o)
+ x.mu.Unlock()
+ }
return a, nil
}
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 4846eb79..364e5667 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -766,7 +766,6 @@ var runnerDraftCopy = map[string]string{
"evidence.after": "After",
// COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): evidence.approved
"evidence.approved": "Approved",
-
// COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): plan.awaiting_approval
"plan.awaiting_approval": "Waiting for your plan approval",
// COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): plan.proposed
@@ -803,6 +802,7 @@ var runnerDraftCopy = map[string]string{
"live.check-deny": "Equipo is checking that this is refused. Type Deny.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-05, live-probe brief): live.check-deny
"live.check-allow": "Equipo is checking one-time approval. Type Allow once.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-05, live-probe brief): live.check-allow
"live.check-question": "Equipo is checking that your answer reaches the agent. Enter an answers JSON object.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-05, live-probe brief): live.check-question
+ "live.answer-retry": "Enter Allow once, Deny, or a valid JSON object.", // COPY REVIEW PENDING: live.answer-retry
"live.answer": "Type Allow once, Deny, or an answers JSON object. This request expires in 60 seconds.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): live.answer
"live.beyond-profile": "Allow once is recorded as approved beyond profile.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): live.beyond-profile
// COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): isolation.approved_beyond_profile
diff --git a/internal/equipotest/runner_release_test.go b/internal/equipotest/runner_release_test.go
index 1545b97c..5b801916 100644
--- a/internal/equipotest/runner_release_test.go
+++ b/internal/equipotest/runner_release_test.go
@@ -57,7 +57,7 @@ func TestRunnerReleaseContractPackaging(t *testing.T) {
func TestDirectReleaseRequiresCertification(t *testing.T) {
for _, target := range []string{"release", "release-runner"} {
t.Run(target, func(t *testing.T) {
- runnerPackagingScenarios(t, target, []string{"clean", "missing_certification", "changed_policy", "fake_evidence", "fake_cli", "bwrap", "copy", "changed_tuple", "missing_assertion", "pending_live_copy", "pending_plan3_docs", "missing_plan3_inventory", "tampered_capture", "codex_policy", "tool_inventory", "underfunded"})
+ runnerPackagingScenarios(t, target, []string{"clean", "missing_certification", "changed_policy", "fake_evidence", "fake_cli", "bwrap", "copy", "changed_tuple", "missing_assertion", "pending_live_copy", "pending_plan3_docs", "missing_plan3_inventory", "tampered_capture", "codex_policy", "tool_inventory", "underfunded", "no_person_controls", "automatic_controls", "missing_provider_check", "wrong_provider_check", "tampered_person_answer"})
})
}
}
@@ -191,6 +191,7 @@ func installCertificationFixture(t *testing.T, root string, m *release.Manifest,
}
}
providertest.SaveIsolation(t, dir, &e)
+ providertest.PersonControls(t, dir, &e, scenario)
tools := map[string]string{"Read": "native", "Write": "native", "Edit": "native", "Glob": "search", "Grep": "search", "Bash": "shell", "mcp__equipo__submit_render": "mcp", "mcp__equipo__ask_person": "mcp", "mcp__equipo__submit_candidate": "mcp"}
for name, surface := range tools {
tool := provider.LiveTool{Name: name, Surface: surface, Exposed: true, Probes: map[string]provider.LiveObservation{}}
@@ -233,6 +234,7 @@ func installCertificationFixture(t *testing.T, root string, m *release.Manifest,
executionMust(t, os.WriteFile(filepath.Join(dir, "capture.json"), []byte("changed"), 0600))
}
}
+ providertest.PersonControlReferences(m, scenario)
switch scenario {
case "missing_certification":
m.Certifications = []release.Certification{}
@@ -254,7 +256,6 @@ func releaseCertificationFixture(t *testing.T, root, bin, scenario string) []str
if scenario == "missing_plan3_inventory" {
executionMust(t, os.Remove(filepath.Join(root, "docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md")))
}
-
t.Helper()
var fixture release.Manifest
rawManifest, err := os.ReadFile(filepath.Join(root, "internal/release/manifest.json"))
@@ -285,6 +286,5 @@ func releaseCertificationFixture(t *testing.T, root, bin, scenario string) []str
bytes, err := json.Marshal(fixture)
executionMust(t, err)
executionMust(t, os.WriteFile(filepath.Join(root, "internal/release/manifest.json"), bytes, 0600))
-
return installed
}
diff --git a/internal/release/manifest.go b/internal/release/manifest.go
index 68d6a892..707f34bd 100644
--- a/internal/release/manifest.go
+++ b/internal/release/manifest.go
@@ -48,22 +48,23 @@ type Certification struct {
}
type Manifest struct {
- UncertifiedPolicies []UncertifiedPolicy `json:"uncertified_policies,omitempty"`
- Certifications []Certification `json:"certifications"`
- LiveGateCopyReviewed bool `json:"live_gate_copy_reviewed"`
- Binaries []BinaryDigest `json:"binaries"`
- DirectPolicies []PolicyCertificate `json:"direct_policies,omitempty"`
- LauncherVersion string `json:"launcher_version,omitempty"`
- BwrapVersion string `json:"bwrap_version,omitempty"`
- PolicyVersion string `json:"policy_version,omitempty"`
- Schema int `json:"schema"`
- RunnerTarget string `json:"runner_target"`
- InstanceTarget string `json:"instance_target"`
- Go string `json:"go"`
- Codex string `json:"codex"`
- Claude string `json:"claude"`
- VerifiedIsolationTuples []team.IsolationTuple `json:"verified_isolation_tuples"`
- GateEvidence []string `json:"gate_evidence"`
+ ProviderChecks map[string]map[string]Certification `json:"provider_checks,omitempty"`
+ UncertifiedPolicies []UncertifiedPolicy `json:"uncertified_policies,omitempty"`
+ Certifications []Certification `json:"certifications"`
+ LiveGateCopyReviewed bool `json:"live_gate_copy_reviewed"`
+ Binaries []BinaryDigest `json:"binaries"`
+ DirectPolicies []PolicyCertificate `json:"direct_policies,omitempty"`
+ LauncherVersion string `json:"launcher_version,omitempty"`
+ BwrapVersion string `json:"bwrap_version,omitempty"`
+ PolicyVersion string `json:"policy_version,omitempty"`
+ Schema int `json:"schema"`
+ RunnerTarget string `json:"runner_target"`
+ InstanceTarget string `json:"instance_target"`
+ Go string `json:"go"`
+ Codex string `json:"codex"`
+ Claude string `json:"claude"`
+ VerifiedIsolationTuples []team.IsolationTuple `json:"verified_isolation_tuples"`
+ GateEvidence []string `json:"gate_evidence"`
}
func BuildManifest() Manifest {
diff --git a/internal/runner/provider/person_controls.go b/internal/runner/provider/person_controls.go
new file mode 100644
index 00000000..79ae15e6
--- /dev/null
+++ b/internal/runner/provider/person_controls.go
@@ -0,0 +1,92 @@
+package provider
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "slices"
+)
+
+const PersonAnsweredControls = "person-answered-controls"
+
+var ControlChecks = []string{"workspace-positive-control", "person-native-approval", "real-question-answer", "policy-escalation-denied", "equipo-broker-approval", "stale-broker-denied", "invalid-broker-denied"}
+
+type PersonControlProof struct {
+ AnsweredBy string `json:"answered_by"`
+ Answers map[string][]LiveObservation `json:"answers"`
+}
+
+func (e DirectEvidence) ValidatePersonControls(root string) error {
+ if e.Specialist == "Coordinator" || e.Checks["tuple-completed"].Status == "not-certified" {
+ return ErrPolicy
+ }
+ for _, key := range append([]string{PersonAnsweredControls}, ControlChecks...) {
+ if VerifyDirectObservation(root, e.Checks[key], "pass") != nil {
+ return ErrPolicy
+ }
+ raw, err := os.ReadFile(filepath.Join(root, e.Checks[key].Artifact))
+ var attribution struct {
+ AnsweredBy string `json:"answered_by"`
+ }
+ if err != nil || json.Unmarshal(raw, &attribution) != nil || attribution.AnsweredBy != "person" {
+ return ErrPolicy
+ }
+ }
+ raw, err := os.ReadFile(filepath.Join(root, e.Checks[PersonAnsweredControls].Artifact))
+ var proof PersonControlProof
+ if err != nil || json.Unmarshal(raw, &proof) != nil || proof.AnsweredBy != "person" {
+ return ErrPolicy
+ }
+ return proof.Validate(root)
+}
+
+func (p PersonControlProof) Validate(root string) error {
+ if p.AnsweredBy != "person" || (len(p.Answers) < 3 || len(p.Answers) > 4) {
+ return ErrPolicy
+ }
+ for key := range p.Answers {
+ if !slices.Contains([]string{"workspace", "allow", "deny", "question"}, key) {
+ return ErrPolicy
+ }
+ }
+ seen := map[string]bool{}
+ for _, control := range []string{"workspace", "allow", "deny", "question"} {
+ if control != "workspace" && len(p.Answers[control]) == 0 {
+ return ErrPolicy
+ }
+ for _, o := range p.Answers[control] {
+ if seen[o.Artifact] || VerifyDirectObservation(root, o, "pass") != nil {
+ return ErrPolicy
+ }
+ seen[o.Artifact] = true
+ raw, err := os.ReadFile(filepath.Join(root, o.Artifact))
+ var a struct {
+ AnsweredBy string `json:"answered_by"`
+ Control string `json:"control"`
+ Answer struct {
+ Behavior string `json:"behavior"`
+ UpdatedInput json.RawMessage `json:"updated_input"`
+ } `json:"answer"`
+ }
+ if err != nil || json.Unmarshal(raw, &a) != nil || a.AnsweredBy != "person" || a.Control != control {
+ return ErrPolicy
+ }
+ want := "allow"
+ if control == "deny" {
+ want = "deny"
+ }
+ if a.Answer.Behavior != want {
+ return ErrPolicy
+ }
+ if control == "question" {
+ var input struct {
+ Answers map[string]string `json:"answers"`
+ }
+ if json.Unmarshal(a.Answer.UpdatedInput, &input) != nil || input.Answers["answer"] == "" {
+ return ErrPolicy
+ }
+ }
+ }
+ }
+ return nil
+}
diff --git a/internal/runner/provider/providertest/person_controls.go b/internal/runner/provider/providertest/person_controls.go
new file mode 100644
index 00000000..a814d685
--- /dev/null
+++ b/internal/runner/provider/providertest/person_controls.go
@@ -0,0 +1,68 @@
+package providertest
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/release"
+ "amadan.net/oficina/equipo/internal/runner/provider"
+)
+
+// PersonControls writes synthetic person-answer evidence for offline fixtures.
+func PersonControls(t *testing.T, root string, e *provider.DirectEvidence, scenario string) {
+ t.Helper()
+ write := func(name string, value any) provider.LiveObservation {
+ raw, err := json.Marshal(value)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err = os.WriteFile(filepath.Join(root, name), raw, 0600); err != nil {
+ t.Fatal(err)
+ }
+ hash := provider.DigestDirectEvidence(raw)
+ e.Artifacts[name] = hash
+ return provider.LiveObservation{Status: "pass", Artifact: name, SHA256: hash, Detail: "synthetic unit-test fixture"}
+ }
+ for _, name := range provider.ControlChecks {
+ e.Checks[name] = write(name+".json", map[string]string{"answered_by": "person"})
+ }
+ proof := provider.PersonControlProof{AnsweredBy: "person", Answers: map[string][]provider.LiveObservation{}}
+ for _, control := range []string{"workspace", "allow", "deny", "question"} {
+ behavior := "allow"
+ if control == "deny" {
+ behavior = "deny"
+ }
+ answer := map[string]any{"behavior": behavior}
+ if control == "question" {
+ answer["updated_input"] = map[string]any{"answers": map[string]string{"answer": "ordinary"}}
+ }
+ proof.Answers[control] = []provider.LiveObservation{write("answer-"+control+".json", map[string]any{"answered_by": "person", "control": control, "answer": answer})}
+ }
+ if scenario == "automatic_controls" {
+ proof.AnsweredBy = "automatic"
+ }
+ e.Checks[provider.PersonAnsweredControls] = write("person-answered-controls.json", proof)
+ if scenario == "no_person_controls" {
+ delete(e.Checks, provider.PersonAnsweredControls)
+ }
+ if scenario == "tampered_person_answer" {
+ if err := os.WriteFile(filepath.Join(root, "answer-allow.json"), []byte("changed"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+func PersonControlReferences(m *release.Manifest, scenario string) {
+ m.ProviderChecks = map[string]map[string]release.Certification{}
+ for _, ref := range m.Certifications {
+ m.ProviderChecks[ref.Provider] = map[string]release.Certification{provider.PersonAnsweredControls: ref}
+ }
+ switch scenario {
+ case "missing_provider_check":
+ delete(m.ProviderChecks, "codex")
+ case "wrong_provider_check":
+ m.ProviderChecks["codex"] = m.ProviderChecks["claude"]
+ }
+}
diff --git a/scripts/runner-release-check.py b/scripts/runner-release-check.py
index 6f041682..6cd31ba4 100644
--- a/scripts/runner-release-check.py
+++ b/scripts/runner-release-check.py
@@ -40,6 +40,42 @@ def observation(base, value, status):
require(digest(local_file(base, value["artifact"])) == value["sha256"])
+def person_controls(base, record):
+ require(record["specialist"] != "Coordinator")
+ require(record["checks"].get("tuple-completed", {}).get("status") != "not-certified")
+ for name in ("person-answered-controls", "workspace-positive-control", "person-native-approval", "real-question-answer", "policy-escalation-denied", "equipo-broker-approval", "stale-broker-denied", "invalid-broker-denied"):
+ observation(base, record["checks"][name], "pass")
+ check = json.loads(local_file(base, record["checks"][name]["artifact"]).read_text())
+ require(check["answered_by"] == "person")
+ proof = json.loads(local_file(base, record["checks"]["person-answered-controls"]["artifact"]).read_text())
+ require(proof["answered_by"] == "person" and set(proof["answers"]) in ({"allow", "deny", "question"}, {"workspace", "allow", "deny", "question"}))
+ seen = set()
+ for control, answers in proof["answers"].items():
+ require(answers or control == "workspace")
+ for ref in answers:
+ observation(base, ref, "pass")
+ require(ref["artifact"] not in seen)
+ seen.add(ref["artifact"])
+ answer = json.loads(local_file(base, ref["artifact"]).read_text())
+ require(answer["answered_by"] == "person" and answer["control"] == control)
+ require(answer["answer"]["behavior"] == ("deny" if control == "deny" else "allow"))
+ if control == "question":
+ require(answer["answer"]["updated_input"]["answers"]["answer"])
+
+
+def provider_checks(manifest):
+ families = {p["provider"] for p in manifest["direct_policies"]}
+ require(set(manifest["provider_checks"]) == families)
+ for family in families:
+ ref = manifest["provider_checks"][family]["person-answered-controls"]
+ require(ref["provider"] == family and ref in manifest["certifications"])
+ path = local_file(root, ref["path"])
+ require(digest(path) == ref["sha256"])
+ record = json.loads(path.read_text())
+ require(record["provider"] == family and record["policy_hash"] == ref["policy_hash"])
+ person_controls(path.parent, record)
+
+
def native_refusal(frames, tool, path):
calls, valid = {}, True
for frame in frames:
@@ -245,6 +281,7 @@ try:
require(pin and installed[name] == pin[1])
require(len(manifest["certifications"]) == len(manifest["direct_policies"]))
require(len(manifest["verified_isolation_tuples"]) == len(manifest["direct_policies"]))
+ provider_checks(manifest)
seen = set()
for certificate in manifest["direct_policies"]:
require(certificate["provider_version"] == manifest[certificate["provider"]])