oficina / equipo Public

feat: define direct provider contracts and historical decoding

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev c87a6f2b0788c94305d8f2903833c29a0a05eef5 parent c5dfe71
10 files changed, +1,136 −3
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md +639 −0
  • internal/equipo/team/direct_history_test.go +149 −0
  • internal/equipo/team/git_evidence.go +36 −2
  • internal/release/manifest.go +3 −0
  • internal/runner/provider/budget_test.go +9 −0
  • internal/runner/provider/errors.go +11 −0
  • internal/runner/provider/types.go +152 −0
  • internal/runner/provider/types_test.go +131 −0
  • internal/runnerproto/containment.go +2 −0
  • internal/runnerproto/types.go +4 −1

CI passed — run details

diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
new file mode 100644
index 00000000..3dfbdc1e
--- /dev/null
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
@@ -0,0 +1,639 @@
+# Plan 2b controller report
+
+## Task 1: Direct provider contract and historical compatibility
+
+Status: DONE. Work stayed on `plan-2b` in `/home/paulca/amadan.net/oficina/equipo-plan-2b`.
+
+### Built
+
+Declared the exact Selection, Binding, Identity, Mount, Policy, Launch, Session, Turn, Answer, Event, Exit, Process, ProcessHost and Launcher contracts from the brief. Declared Task 7's Frame, Capture and CaptureFactory signatures exactly as supplied. Provider types are independent declarations with only standard-library imports. The package documents that Open sends no prompt, Events attaches before StartTurn, constructors require ProcessHost and CaptureFactory, and adapters decode captured frames rather than raw process stdout.
+
+Added direct contract version/provider validation, observed-session correlation against selection and binding, and turn-event correlation. Session IDs, attempt keys, turn IDs and admission IDs remain separate fields. These checks confer no execution authority.
+
+Extended isolation tuples, connection reports and the release manifest with LauncherVersion, BwrapVersion and PolicyVersion. Direct tuple identity includes all six values: provider, provider version, launcher revision, bubblewrap version, policy schema and effective policy hash. Existing full-struct comparisons retain every new identity field. ContainmentProof has an optional Version field, with zero preserving historical unversioned proofs.
+
+Historical Paseo, trial and unconfined JSON remains readable. ValidForDirectLaunch rejects historical tuples, mixed identities, tainted snapshots, incomplete tuples, unsupported provider names and invalid hashes. This is a structural check; actual dispatch also needs release certification. Core schema version remains 7. Scope, Handle, Usage, TokenUsage and action classifications are unchanged. No runtime cutover or certified tuple was fabricated.
+
+### Files
+
+- `internal/runner/provider/types.go`: exact contracts and correlation checks.
+- `internal/runner/provider/errors.go`: typed internal error codes.
+- `internal/runner/provider/types_test.go`: contract signatures, version/provider refusals and identity tests.
+- `internal/runner/provider/budget_test.go`: TestMain copied from the existing runner/paseo budget pattern.
+- `internal/equipo/team/git_evidence.go`: additive tuple fields, historical validation and direct validity check.
+- `internal/equipo/team/direct_history_test.go`: fixed historical JSON fixtures, tuple identity, wire and manifest tests.
+- `internal/runnerproto/types.go`: DirectVersion and report fields.
+- `internal/runnerproto/containment.go`: additive proof version.
+- `internal/release/manifest.go`: additive direct release metadata.
+- `docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md`: this task's evidence.
+
+Full local report: `/home/paulca/amadan.net/oficina/equipo-plan-2b/.superpowers/sdd/2026-11-03-equipo-plan-2b-direct/task-1-report.md`. The repository ignores `.superpowers/`; the local report is saved there, while the controller report is committed.
+
+### Interpretations
+
+1. Version 2 is additive: `provider.Version = 2`, exposed as `runnerproto.DirectVersion`. Existing `runnerproto.Version = 1` remains for Paseo and enrolment. Inspection found explicit version-1 requests and validations throughout the current runtime and instance. Changing that constant alone would break the runtime before Task 9. Future direct producers and consumers must use DirectVersion; the current instance does not yet accept direct requests.
+2. Unsupported versions in the contract test means protocol versions. Task 1 does not pin production provider, bubblewrap or policy versions. Values in test fixtures are examples, not release certification.
+3. `IsolationSnapshot.Valid()` remains the historical evidence reader. `ValidForDirectLaunch()` is a separate structural prerequisite, so retaining readable trial/unconfined history does not grant direct eligibility. Actual verified-tuple matching and removal of active legacy exception paths remain later tasks.
+4. The brief lists containment.go and manifest.go without giving new containment-proof internals or release pins. Added only optional proof versioning and the named direct version fields. Task 2 defines namespace exit proofs; later release work sets real pins after certification.
+5. Session.Validate and Event.ValidateIdentity provide the identity checks required by the tests without adding fields to the prescribed interfaces. ValidateIdentity applies to turn-bound events; adapters must validate session-level events through their session path. Contract validation and correlation are separate from authorization and account/policy preflight.
+
+### RED
+
+Tests and the budget TestMain were written before implementation. Command, from the repository root:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/provider ./internal/equipo/team -run 'TestDirect|TestHistoricalIsolation' -count=1
+```
+
+Exit 1. Output excerpts:
+
+```text
+internal/runner/provider/types_test.go:15:13: undefined: ValidateContract
+internal/runner/provider/types_test.go:26:12: undefined: Launch
+FAIL amadan.net/oficina/equipo/internal/runner/provider [build failed]
+internal/equipo/team/direct_history_test.go:15:76: unknown field LauncherVersion in struct literal of type team.IsolationTuple
+internal/equipo/team/direct_history_test.go:29:11: got.ValidForDirectLaunch undefined
+FAIL amadan.net/oficina/equipo/internal/equipo/team [build failed]
+```
+
+### GREEN
+
+Repeated the exact RED command after implementation, after strengthening the fixtures and identity assertions, and after all mutations were restored. Every green run exited 0. Final output:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/provider 0.002s
+ok amadan.net/oficina/equipo/internal/equipo/team 0.004s
+```
+
+Targeted compatibility command:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner ./internal/runner/paseo ./internal/equipo/team -run '^(TestRunnerServiceLifecycleWiring|TestRunnerServiceVersions|TestRunnerJournalCrashBoundaries|TestPaseoAdapterContract|TestTrialEvidenceAndPublication|TestEvidenceObservedIsolation)$' -count=1
+```
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner 0.988s
+ok amadan.net/oficina/equipo/internal/runner/paseo 0.004s
+ok amadan.net/oficina/equipo/internal/equipo/team 0.785s
+```
+
+`git diff --check` exited 0. `gofmt -l` on all nine Go files returned no paths. Dependency inspection used:
+
+```sh
+CGO_ENABLED=0 go list -f '{{join .Imports "\n"}}' ./internal/runner/provider
+```
+
+Output: `context`, `encoding/json`, `io`, `time`. No runner, runnerproto or Paseo import, and no aliases to Paseo types.
+
+### Mutations
+
+36 distinct mutations compiled, failed the named test with assertions, and passed after restoration. Each mutation was applied alone to the implementation, then restored from its exact pre-mutation contents in a finally block. The same targeted command was run for the mutation and its restoration. No compiler failure was counted as proof. The history-ineligible mutation uses `_ = v` to remain compilable.
+
+One initial mutation survived: removing the selection-provider comparison was still covered by the binding-provider comparison when only the observed session changed. Added assertions that change the selection independently of the binding. The repeated mutation then failed as required. That initial run and its restoration both exited 0; it was not counted among the 36 proved mutations.
+
+1. `version` in `internal/runner/provider/types.go`.
+
+ Change: `if version != Version {` to `if false {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectContractRejectsUnknownVersion$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectContractRejectsUnknownVersion (0.00s)
+ types_test.go:21: version -1 accepted: <nil>
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+2. `provider` in `internal/runner/provider/types.go`.
+
+ Change: `if name != "claude" && name != "codex" {` to `if false {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectContractRejectsUnknownVersion$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectContractRejectsUnknownVersion (0.00s)
+ types_test.go:26: provider "" accepted: <nil>
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+3. `session-required` in `internal/runner/provider/types.go`.
+
+ Change: `s.ID == "" || (l.ResumeSessionID != "" && s.ID != l.ResumeSessionID)` to `(l.ResumeSessionID != "" && s.ID != l.ResumeSessionID)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:70: empty new session accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+4. `resume-identity` in `internal/runner/provider/types.go`.
+
+ Change: `s.ID == "" || (l.ResumeSessionID != "" && s.ID != l.ResumeSessionID)` to `s.ID == ""`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:51: changed session identity accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+5. `identity-required` in `internal/runner/provider/types.go`.
+
+ Change: `pair[0] == "" || pair[0] != pair[1]` to `pair[0] != pair[1]`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:73: empty matching launch identities accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+6. `identity-match` in `internal/runner/provider/types.go`.
+
+ Change: `pair[0] == "" || pair[0] != pair[1]` to `pair[0] == ""`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:51: changed session identity accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+7. `identity-l.AttemptKey` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.AttemptKey, l.AttemptKey},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:47: missing session identity accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.001s`.
+
+8. `identity-l.Selection.Provider` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.Provider, l.Selection.Provider},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:59: changed selection Provider accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+9. `identity-l.Selection.AccountID` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.AccountID, l.Selection.AccountID},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:59: changed selection AccountID accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.001s`.
+
+10. `identity-l.Selection.Model` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.Model, l.Selection.Model},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:47: missing session identity accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+11. `identity-l.Selection.Family` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.Family, l.Selection.Family},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:47: missing session identity accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+12. `identity-l.Binding.Provider` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.Provider, l.Binding.Provider},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:66: changed binding Provider accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+13. `identity-l.Binding.AccountID` in `internal/runner/provider/types.go`.
+
+ Change: `\t\t{s.AccountID, l.Binding.AccountID},\n` to `(delete this row)`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:66: changed binding AccountID accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+14. `event-e.SessionID == ""` in `internal/runner/provider/types.go`.
+
+ Change: `e.SessionID == "" || e.SessionID != s.ID || e.TurnID == "" || e.TurnID != t.ID` to `e.SessionID != s.ID || e.TurnID == "" || e.TurnID != t.ID`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:83: empty matching session identities accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+15. `event-e.SessionID != s.ID` in `internal/runner/provider/types.go`.
+
+ Change: `e.SessionID == "" || e.SessionID != s.ID || e.TurnID == "" || e.TurnID != t.ID` to `e.SessionID == "" || e.TurnID == "" || e.TurnID != t.ID`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:100: mismatched event accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+16. `event-e.TurnID == ""` in `internal/runner/provider/types.go`.
+
+ Change: `e.SessionID == "" || e.SessionID != s.ID || e.TurnID == "" || e.TurnID != t.ID` to `e.SessionID == "" || e.SessionID != s.ID || e.TurnID != t.ID`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:86: empty matching turn identities accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+17. `event-e.TurnID != t.ID` in `internal/runner/provider/types.go`.
+
+ Change: `e.SessionID == "" || e.SessionID != s.ID || e.TurnID == "" || e.TurnID != t.ID` to `e.SessionID == "" || e.SessionID != s.ID || e.TurnID == ""`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestDirectIdentitySeparatesSessionAndAttempt$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIdentitySeparatesSessionAndAttempt (0.00s)
+ types_test.go:100: mismatched event accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/runner/provider 0.002s`.
+
+18. `history-readable` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `return v.Provider != "" && v.ProviderVersion != "" && v.PaseoVersion != "" && lowerHex(v.IsolationConfigHash, 64)` to `return false`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestHistoricalIsolationRemainsReadable$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestHistoricalIsolationRemainsReadable (0.00s)
+ direct_history_test.go:42: history lost or rejected: {"status":"confined","runner_tainted":false,"acknowledgement_ids":null,"observed_tuples":[{"provider":"codex","provider_version":"0.165.0","paseo_version":"0.14.0","isolation_config_hash":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}]}
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+19. `history-excludes-LauncherVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.LauncherVersion == "" && v.BwrapVersion == "" && v.PolicyVersion == ""` to `v.BwrapVersion == "" && v.PolicyVersion == ""`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestHistoricalIsolationRemainsReadable$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestHistoricalIsolationRemainsReadable (0.00s)
+ direct_history_test.go:62: partial direct identity accepted as history: LauncherVersion
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+20. `history-excludes-BwrapVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.LauncherVersion == "" && v.BwrapVersion == "" && v.PolicyVersion == ""` to `v.LauncherVersion == "" && v.PolicyVersion == ""`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestHistoricalIsolationRemainsReadable$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestHistoricalIsolationRemainsReadable (0.00s)
+ direct_history_test.go:62: partial direct identity accepted as history: BwrapVersion
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+21. `history-excludes-PolicyVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.LauncherVersion == "" && v.BwrapVersion == "" && v.PolicyVersion == ""` to `v.LauncherVersion == "" && v.BwrapVersion == ""`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestHistoricalIsolationRemainsReadable$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestHistoricalIsolationRemainsReadable (0.00s)
+ direct_history_test.go:62: partial direct identity accepted as history: PolicyVersion
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+22. `snapshot-valid` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !p.valid() || p.RunnerTainted {` to `if p.RunnerTainted {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:120: unsafe direct snapshot accepted: {Trial:<nil> Status:confined RunnerTainted:false AcknowledgementIDs:[] ObservedTuples:[]}
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+23. `snapshot-untainted` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !p.valid() || p.RunnerTainted {` to `if !p.valid() {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:120: unsafe direct snapshot accepted: {Trial:<nil> Status:unconfined RunnerTainted:true AcknowledgementIDs:[ack] ObservedTuples:[{Provider:codex ProviderVersion:0.165.0 PaseoVersion: LauncherVersion:revision BwrapVersion:0.11.0 PolicyVersion:1 IsolationConfigHash:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}]}
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+24. `history-ineligible` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !v.direct() {` to `_ = v\n\t\tif false {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestHistoricalIsolationRemainsReadable$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestHistoricalIsolationRemainsReadable (0.00s)
+ direct_history_test.go:53: historical evidence granted direct eligibility
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+25. `direct-provider` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `(v.Provider == "claude" || v.Provider == "codex") &&` to `true &&`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:82: incomplete tuple accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.004s`.
+
+26. `direct-ProviderVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.ProviderVersion != "" && v.PaseoVersion == "" &&` to `true && v.PaseoVersion == "" &&`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:82: incomplete tuple accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+27. `direct-LauncherVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.LauncherVersion != "" &&` to `true &&`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:82: incomplete tuple accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.010s`.
+
+28. `direct-BwrapVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.BwrapVersion != "" &&` to `true &&`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:82: incomplete tuple accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.013s`.
+
+29. `direct-PolicyVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.PolicyVersion != "" &&` to `true &&`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:82: incomplete tuple accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+30. `direct-no-paseo` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `v.PaseoVersion == "" &&` to `true &&`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:120: unsafe direct snapshot accepted: {Trial:<nil> Status:confined RunnerTainted:false AcknowledgementIDs:[] ObservedTuples:[{Provider:codex ProviderVersion:0.165.0 PaseoVersion:0.14.0 LauncherVersion:revision BwrapVersion:0.11.0 PolicyVersion:1 IsolationConfigHash:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}]}
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+31. `direct-hash` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `\t\tlowerHex(v.IsolationConfigHash, 64)\n` to `\t\ttrue\n`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:82: incomplete tuple accepted
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+32. `tuple-identity-LauncherVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !slices.Contains(have.ObservedTuples, v) {` to `found := false\n for _, candidate := range have.ObservedTuples {\n candidate.LauncherVersion = ""\n v.LauncherVersion = ""\n if candidate == v { found = true }\n }\n if !found {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:95: tuple identity change ignored
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+33. `tuple-identity-BwrapVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !slices.Contains(have.ObservedTuples, v) {` to `found := false\n for _, candidate := range have.ObservedTuples {\n candidate.BwrapVersion = ""\n v.BwrapVersion = ""\n if candidate == v { found = true }\n }\n if !found {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:95: tuple identity change ignored
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.003s`.
+
+34. `tuple-identity-PolicyVersion` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !slices.Contains(have.ObservedTuples, v) {` to `found := false\n for _, candidate := range have.ObservedTuples {\n candidate.PolicyVersion = ""\n v.PolicyVersion = ""\n if candidate == v { found = true }\n }\n if !found {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectIsolationTupleIdentity (0.00s)
+ direct_history_test.go:95: tuple identity change ignored
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.003s`.
+
+35. `wire-version` in `internal/runnerproto/types.go`.
+
+ Change: `DirectVersion = provider.Version` to `DirectVersion = provider.Version + 1`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectWireAndManifest$ -count=1`.
+
+ RED exit 1; assertion excerpt:
+
+ ```text
+ --- FAIL: TestDirectWireAndManifest (0.00s)
+ direct_history_test.go:127: direct or historical wire version changed
+ ```
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.003s`.
+
+36. `snapshot-tuple-validation` in `internal/equipo/team/git_evidence.go`.
+
+ Change: `if !v.valid() {` to `_ = v` followed by `if false {`.
+
+ Command for RED and restoration: `CGO_ENABLED=0 go test ./internal/equipo/team -run ^TestDirectIsolationTupleIdentity$ -count=1`.
+
+ RED exit 1: `--- FAIL: TestDirectIsolationTupleIdentity`; assertion: `incomplete tuple accepted`.
+
+ Restored exit 0: `ok amadan.net/oficina/equipo/internal/equipo/team 0.002s`.
+
+### User-facing strings
+
+No UI strings, README prose or copy.go entries were added. New internal diagnostic codes are `provider_version_unsupported`, `provider_unsupported` and `provider_identity_mismatch`. They have no new user-facing route in this task. If later surfaced, map them to individually pending copy.go entries for review. No copy-review skill, server, model prompt or helper agent was used.
+
+### Concerns and limits
+
+No unresolved Task 1 failure. Direct runtime wiring, provider adapters, namespace proof enforcement, policy/account preflight, durable capture implementation and release certification remain later tasks. The old runtime and historical readers remain in place by design. No full suite or make ci was run, as instructed; only the named targeted tests ran. No provider login, enrolment, credential home or live provider run occurred.
+
+All mutation source changes were restored. The task's scratch evidence directory is removed after saving these reports. No server or background process was left running. No push, merge or deployment was performed.
diff --git a/internal/equipo/team/direct_history_test.go b/internal/equipo/team/direct_history_test.go
new file mode 100644
index 00000000..845e23d5
--- /dev/null
+++ b/internal/equipo/team/direct_history_test.go
@@ -0,0 +1,149 @@
+package team_test
+
+import (
+ "encoding/json"
+ "reflect"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/equipo/team"
+ "amadan.net/oficina/equipo/internal/release"
+ "amadan.net/oficina/equipo/internal/runnerproto"
+)
+
+func directTuple() team.IsolationTuple {
+ return team.IsolationTuple{Provider: "codex", ProviderVersion: "0.165.0", LauncherVersion: "revision", BwrapVersion: "0.11.0", PolicyVersion: "1", IsolationConfigHash: strings.Repeat("a", 64)}
+}
+
+func TestHistoricalIsolationRemainsReadable(t *testing.T) {
+ for _, status := range []string{"confined", "unconfined", "trial"} {
+ t.Run(status, func(t *testing.T) {
+ legacy := team.IsolationSnapshot{Status: "confined", ObservedTuples: []team.IsolationTuple{{Provider: "codex", ProviderVersion: "0.165.0", PaseoVersion: "0.14.0", IsolationConfigHash: strings.Repeat("a", 64)}}}
+ if status != "confined" {
+ legacy.Status = "unconfined"
+ legacy.RunnerTainted = true
+ legacy.AcknowledgementIDs = []string{"ack"}
+ }
+ if status == "trial" {
+ legacy.Trial = &team.TrialSnapshot{Label: "supervised trial", AcknowledgementIDs: []string{"trial-ack"}, UnverifiedChecks: team.TrialChecks(), ProviderVersionSource: "observed_locally"}
+ }
+ raw := []byte(`{"status":"confined","runner_tainted":false,"acknowledgement_ids":null,"observed_tuples":[{"provider":"codex","provider_version":"0.165.0","paseo_version":"0.14.0","isolation_config_hash":"` + strings.Repeat("a", 64) + `"}]}`)
+ if status != "confined" {
+ raw = []byte(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(string(raw), `"status":"confined"`, `"status":"unconfined"`), `"runner_tainted":false`, `"runner_tainted":true`), `"acknowledgement_ids":null`, `"acknowledgement_ids":["ack"]`))
+ }
+ if status == "trial" {
+ raw = append([]byte(`{"trial":{"label":"supervised trial","acknowledgement_ids":["trial-ack"],"unverified_checks":["account_unverified","no_failover","provider_version","effective_isolation","recoverable_completion"],"provider_version_source":"observed_locally"},`), raw[1:]...)
+ }
+ var got team.IsolationSnapshot
+ if err := json.Unmarshal(raw, &got); err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(got, legacy) || !got.Valid() {
+ t.Fatalf("history lost or rejected: %s", raw)
+ }
+ encoded, err := json.Marshal(got)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var again team.IsolationSnapshot
+ if err := json.Unmarshal(encoded, &again); err != nil || !reflect.DeepEqual(got, again) {
+ t.Fatalf("historical round trip failed: %v", err)
+ }
+ if got.ValidForDirectLaunch() {
+ t.Fatal("historical evidence granted direct eligibility")
+ }
+ })
+ }
+ for _, field := range []string{"LauncherVersion", "BwrapVersion", "PolicyVersion"} {
+ hybrid := team.IsolationTuple{Provider: "codex", ProviderVersion: "0.165.0", PaseoVersion: "0.14.0", IsolationConfigHash: strings.Repeat("a", 64)}
+ reflect.ValueOf(&hybrid).Elem().FieldByName(field).SetString("partial")
+ snapshot := team.IsolationSnapshot{Status: "confined", ObservedTuples: []team.IsolationTuple{hybrid}}
+ if snapshot.Valid() || snapshot.ValidForDirectLaunch() {
+ t.Fatalf("partial direct identity accepted as history: %s", field)
+ }
+ }
+ if team.SchemaVersion != 7 {
+ t.Fatalf("JSON extension changed schema: %d", team.SchemaVersion)
+ }
+}
+
+func TestDirectIsolationTupleIdentity(t *testing.T) {
+ snapshot := team.IsolationSnapshot{Status: "confined", ObservedTuples: []team.IsolationTuple{directTuple()}}
+ if !snapshot.Valid() || !snapshot.ValidForDirectLaunch() {
+ t.Fatal("complete direct tuple rejected")
+ }
+ for _, field := range []string{"Provider", "ProviderVersion", "LauncherVersion", "BwrapVersion", "PolicyVersion", "IsolationConfigHash"} {
+ t.Run(field, func(t *testing.T) {
+ changed := directTuple()
+ reflect.ValueOf(&changed).Elem().FieldByName(field).SetString("")
+ bad := snapshot
+ bad.ObservedTuples = []team.IsolationTuple{changed}
+ if bad.Valid() || bad.ValidForDirectLaunch() {
+ t.Fatal("incomplete tuple accepted")
+ }
+ changed = directTuple()
+ value := "different"
+ if field == "Provider" {
+ value = "claude"
+ }
+ if field == "IsolationConfigHash" {
+ value = strings.Repeat("b", 64)
+ }
+ reflect.ValueOf(&changed).Elem().FieldByName(field).SetString(value)
+ bad.ObservedTuples = []team.IsolationTuple{changed}
+ if !bad.Valid() || team.IsolationContains(bad, snapshot) {
+ t.Fatal("tuple identity change ignored")
+ }
+ })
+ }
+ for _, change := range []func(*team.IsolationSnapshot){
+ func(s *team.IsolationSnapshot) {
+ s.Status = "unconfined"
+ s.RunnerTainted = true
+ s.AcknowledgementIDs = []string{"ack"}
+ },
+ func(s *team.IsolationSnapshot) { s.RunnerTainted = true; s.AcknowledgementIDs = []string{"ack"} },
+ func(s *team.IsolationSnapshot) {
+ s.Trial = &team.TrialSnapshot{Label: "supervised trial", AcknowledgementIDs: []string{"ack"}, UnverifiedChecks: team.TrialChecks(), ProviderVersionSource: "observed_locally"}
+ s.Status = "unconfined"
+ s.RunnerTainted = true
+ },
+ func(s *team.IsolationSnapshot) { s.ObservedTuples[0].PaseoVersion = "0.14.0" },
+ func(s *team.IsolationSnapshot) { s.ObservedTuples[0].Provider = "unknown" },
+ func(s *team.IsolationSnapshot) { s.ObservedTuples[0].IsolationConfigHash = strings.Repeat("z", 64) },
+ func(s *team.IsolationSnapshot) { s.ObservedTuples = nil },
+ } {
+ bad := snapshot
+ bad.ObservedTuples = []team.IsolationTuple{directTuple()}
+ change(&bad)
+ if bad.ValidForDirectLaunch() {
+ t.Fatalf("unsafe direct snapshot accepted: %+v", bad)
+ }
+ }
+}
+
+func TestDirectWireAndManifest(t *testing.T) {
+ if runnerproto.DirectVersion != 2 || runnerproto.Version != 1 {
+ t.Fatal("direct or historical wire version changed")
+ }
+ tuple := directTuple()
+ manifest := release.Manifest{LauncherVersion: tuple.LauncherVersion, BwrapVersion: tuple.BwrapVersion, PolicyVersion: tuple.PolicyVersion, VerifiedIsolationTuples: []team.IsolationTuple{tuple}}
+ report := runnerproto.ConnectionReport{Provider: tuple.Provider, ProviderVersion: tuple.ProviderVersion, LauncherVersion: tuple.LauncherVersion, BwrapVersion: tuple.BwrapVersion, PolicyVersion: tuple.PolicyVersion, IsolationConfigHash: tuple.IsolationConfigHash}
+ for _, value := range []any{manifest, report, runnerproto.RunnerRequest{Version: runnerproto.DirectVersion}, runnerproto.ContainmentProof{Version: runnerproto.DirectVersion}} {
+ raw, err := json.Marshal(value)
+ if err != nil {
+ t.Fatal(err)
+ }
+ dst := reflect.New(reflect.TypeOf(value))
+ if err := json.Unmarshal(raw, dst.Interface()); err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(value, dst.Elem().Interface()) {
+ t.Fatalf("wire identity lost: %s", raw)
+ }
+ }
+ old := release.BuildManifest()
+ if old.PaseoClient != "0.14.0" || len(old.VerifiedIsolationTuples) != 0 {
+ t.Fatal("historical manifest changed or fabricated certification")
+ }
+}
diff --git a/internal/equipo/team/git_evidence.go b/internal/equipo/team/git_evidence.go
index 71536fef..36406c46 100644
--- a/internal/equipo/team/git_evidence.go
+++ b/internal/equipo/team/git_evidence.go
@@ -42,7 +42,10 @@ type RepositoryCheckResult struct {
type IsolationTuple struct {
Provider string `json:"provider"`
ProviderVersion string `json:"provider_version"`
- PaseoVersion string `json:"paseo_version"`
+ PaseoVersion string `json:"paseo_version,omitempty"`
+ LauncherVersion string `json:"launcher_version,omitempty"`
+ BwrapVersion string `json:"bwrap_version,omitempty"`
+ PolicyVersion string `json:"policy_version,omitempty"`
IsolationConfigHash string `json:"isolation_config_hash"`
}
@@ -109,12 +112,43 @@ func (p IsolationSnapshot) valid() bool {
}
}
for _, v := range p.ObservedTuples {
- if v.Provider == "" || v.ProviderVersion == "" || v.PaseoVersion == "" || !lowerHex(v.IsolationConfigHash, 64) {
+ if !v.valid() {
return false
}
}
return true
}
+
+// ValidForDirectLaunch checks the shape of direct isolation evidence. A caller
+// must also match the exact tuple against release certification before dispatch.
+// Historical snapshots remain readable through Valid, but grant no direct work.
+func (p IsolationSnapshot) ValidForDirectLaunch() bool {
+ // Valid unconfined and trial snapshots are always tainted.
+ if !p.valid() || p.RunnerTainted {
+ return false
+ }
+ for _, v := range p.ObservedTuples {
+ if !v.direct() {
+ return false
+ }
+ }
+ return true
+}
+
+func (v IsolationTuple) valid() bool {
+ if v.LauncherVersion == "" && v.BwrapVersion == "" && v.PolicyVersion == "" {
+ return v.Provider != "" && v.ProviderVersion != "" && v.PaseoVersion != "" && lowerHex(v.IsolationConfigHash, 64)
+ }
+ return v.direct()
+}
+
+func (v IsolationTuple) direct() bool {
+ return (v.Provider == "claude" || v.Provider == "codex") &&
+ v.ProviderVersion != "" && v.PaseoVersion == "" &&
+ v.LauncherVersion != "" && v.BwrapVersion != "" && v.PolicyVersion != "" &&
+ lowerHex(v.IsolationConfigHash, 64)
+}
+
func mergeIsolation(a, b IsolationSnapshot) IsolationSnapshot {
a.Trial = MergeTrial(a.Trial, b.Trial)
if a.Trial != nil {
diff --git a/internal/release/manifest.go b/internal/release/manifest.go
index e7802b07..66179e66 100644
--- a/internal/release/manifest.go
+++ b/internal/release/manifest.go
@@ -10,6 +10,9 @@ import (
var manifest string
type Manifest struct {
+ 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"`
diff --git a/internal/runner/provider/budget_test.go b/internal/runner/provider/budget_test.go
new file mode 100644
index 00000000..88de10f0
--- /dev/null
+++ b/internal/runner/provider/budget_test.go
@@ -0,0 +1,9 @@
+package provider
+
+import (
+ "amadan.net/rastrillo/rastrillo/budget"
+ "os"
+ "testing"
+)
+
+func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
diff --git a/internal/runner/provider/errors.go b/internal/runner/provider/errors.go
new file mode 100644
index 00000000..2094e582
--- /dev/null
+++ b/internal/runner/provider/errors.go
@@ -0,0 +1,11 @@
+package provider
+
+type Error string
+
+func (e Error) Error() string { return string(e) }
+
+const (
+ ErrVersion Error = "provider_version_unsupported"
+ ErrProvider Error = "provider_unsupported"
+ ErrIdentity Error = "provider_identity_mismatch"
+)
diff --git a/internal/runner/provider/types.go b/internal/runner/provider/types.go
new file mode 100644
index 00000000..872acfa6
--- /dev/null
+++ b/internal/runner/provider/types.go
@@ -0,0 +1,152 @@
+// Package provider defines the contract shared by direct CLI adapters.
+package provider
+
+import (
+ "context"
+ "encoding/json"
+ "io"
+ "time"
+)
+
+const Version = 2
+
+type Selection struct {
+ ConnectionID, Provider, Family, Model, AccountID string
+}
+
+type Binding struct {
+ ID, Home, AccountID, Provider string
+}
+
+type Identity struct {
+ AccountID, HomeID, ProviderVersion string
+}
+
+type Mount struct {
+ Source, Target string
+ ReadOnly bool
+}
+
+type Policy struct {
+ Hash string
+ Manifest json.RawMessage
+ Mounts []Mount
+ Env map[string]string
+ Settings, MCP json.RawMessage
+}
+
+type Launch struct {
+ AttemptKey, Workspace, ResumeSessionID string
+ Selection Selection
+ Binding Binding
+ Policy Policy
+}
+
+// ID is the provider's session identity. AttemptKey remains local to Equipo,
+// including when another attempt resumes the same provider session.
+type Session struct {
+ ID, AttemptKey, Provider, AccountID, Model, Family string
+}
+
+type Turn struct {
+ ID, AdmissionID, Prompt string
+}
+
+type Answer struct {
+ RequestID, TurnID, Behavior string
+ Input json.RawMessage
+}
+
+type Event struct {
+ SessionID, TurnID, RequestID, Kind string
+ Payload json.RawMessage
+}
+
+type Exit struct {
+ Code int
+ Signal int
+ ObservedAt time.Time
+}
+
+type Process interface {
+ Stdin() io.WriteCloser
+ Stdout() io.ReadCloser
+ Stderr() io.ReadCloser
+ ID() string
+ Wait(context.Context) (Exit, error)
+}
+
+// ProcessHost owns the namespace and the lifetime of its processes.
+type ProcessHost interface {
+ Start(context.Context, Launch, []string) (Process, error)
+}
+
+// Constructors for adapters must require a ProcessHost and CaptureFactory.
+// Open sends no prompt. Attach Events before calling StartTurn.
+type Launcher interface {
+ Preflight(context.Context, Binding, Policy) (Identity, error)
+ Open(context.Context, Launch) (Session, error)
+ Events(context.Context, Session) (<-chan Event, error)
+ StartTurn(context.Context, Session, Turn) error
+ Respond(context.Context, Session, Answer) error
+ Interrupt(context.Context, Session) error
+ Close(context.Context, Session) error
+}
+
+type Frame struct {
+ Sequence int64
+ Bytes json.RawMessage
+}
+
+// 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
+}
+
+type CaptureFactory interface {
+ Open(context.Context, Process, Launch) (*Capture, error)
+}
+
+func ValidateContract(version int, name string) error {
+ if version != Version {
+ return ErrVersion
+ }
+ if name != "claude" && name != "codex" {
+ return ErrProvider
+ }
+ return nil
+}
+
+// Validate binds an observed session to its launch, including a requested resume.
+// Identity equality does not confer permission to dispatch a turn.
+func (s Session) Validate(l Launch) error {
+ if s.ID == "" || (l.ResumeSessionID != "" && s.ID != l.ResumeSessionID) {
+ return ErrIdentity
+ }
+ for _, pair := range [][2]string{
+ {s.AttemptKey, l.AttemptKey},
+ {s.Provider, l.Selection.Provider},
+ {s.AccountID, l.Selection.AccountID},
+ {s.Model, l.Selection.Model},
+ {s.Family, l.Selection.Family},
+ {s.Provider, l.Binding.Provider},
+ {s.AccountID, l.Binding.AccountID},
+ } {
+ if pair[0] == "" || pair[0] != pair[1] {
+ return ErrIdentity
+ }
+ }
+ return nil
+}
+
+// ValidateIdentity checks correlation for an event that belongs to a turn.
+// Session-level events without a turn use the adapter's session checks instead.
+func (e Event) ValidateIdentity(s Session, t Turn) error {
+ if e.SessionID == "" || e.SessionID != s.ID || e.TurnID == "" || e.TurnID != t.ID {
+ return ErrIdentity
+ }
+ return nil
+}
diff --git a/internal/runner/provider/types_test.go b/internal/runner/provider/types_test.go
new file mode 100644
index 00000000..f62af70e
--- /dev/null
+++ b/internal/runner/provider/types_test.go
@@ -0,0 +1,131 @@
+package provider
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "io"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func TestDirectContractRejectsUnknownVersion(t *testing.T) {
+ for _, name := range []string{"claude", "codex"} {
+ if err := ValidateContract(2, name); err != nil {
+ t.Fatalf("supported contract: %v", err)
+ }
+ }
+ for _, version := range []int{-1, 0, 1, 3} {
+ if err := ValidateContract(version, "claude"); !errors.Is(err, ErrVersion) {
+ t.Errorf("version %d accepted: %v", version, err)
+ }
+ }
+ for _, name := range []string{"", "unknown", "paseo", "Claude", "openai", "codex "} {
+ if err := ValidateContract(2, name); !errors.Is(err, ErrProvider) {
+ t.Errorf("provider %q accepted: %v", name, err)
+ }
+ }
+}
+
+func TestDirectIdentitySeparatesSessionAndAttempt(t *testing.T) {
+ launch := Launch{AttemptKey: "attempt-2", Workspace: "/work", ResumeSessionID: "provider-session", Selection: Selection{ConnectionID: "connection", Provider: "codex", Family: "gpt", Model: "model", AccountID: "account"}, Binding: Binding{ID: "binding", Home: "/login", AccountID: "account", Provider: "codex"}}
+ session := Session{ID: "provider-session", AttemptKey: "attempt-2", Provider: "codex", AccountID: "account", Model: "model", Family: "gpt"}
+ turn := Turn{ID: "turn-3", AdmissionID: "admission-4", Prompt: "test"}
+ event := Event{SessionID: session.ID, TurnID: turn.ID, RequestID: "request-5", Kind: "usage", Payload: json.RawMessage(`{}`)}
+ if err := session.Validate(launch); err != nil {
+ t.Fatal(err)
+ }
+ if err := event.ValidateIdentity(session, turn); err != nil {
+ t.Fatal(err)
+ }
+ for _, field := range []string{"ID", "AttemptKey", "Provider", "AccountID", "Model", "Family"} {
+ t.Run("session_"+field, func(t *testing.T) {
+ bad := session
+ reflect.ValueOf(&bad).Elem().FieldByName(field).SetString("")
+ if !errors.Is(bad.Validate(launch), ErrIdentity) {
+ t.Fatal("missing session identity accepted")
+ }
+ reflect.ValueOf(&bad).Elem().FieldByName(field).SetString("other")
+ if !errors.Is(bad.Validate(launch), ErrIdentity) {
+ t.Fatal("changed session identity accepted")
+ }
+ })
+ }
+ for _, field := range []string{"Provider", "AccountID", "Model", "Family"} {
+ bad := launch
+ reflect.ValueOf(&bad.Selection).Elem().FieldByName(field).SetString("other")
+ if !errors.Is(session.Validate(bad), ErrIdentity) {
+ t.Fatalf("changed selection %s accepted", field)
+ }
+ }
+ for _, field := range []string{"Provider", "AccountID"} {
+ bad := launch
+ reflect.ValueOf(&bad.Binding).Elem().FieldByName(field).SetString("other")
+ if !errors.Is(session.Validate(bad), ErrIdentity) {
+ t.Fatalf("changed binding %s accepted", field)
+ }
+ }
+ fresh := launch
+ fresh.ResumeSessionID = ""
+ if err := session.Validate(fresh); err != nil {
+ t.Fatalf("new session rejected: %v", err)
+ }
+ emptySession := session
+ emptySession.ID = ""
+ if !errors.Is(emptySession.Validate(fresh), ErrIdentity) {
+ t.Fatal("empty new session accepted")
+ }
+ if !errors.Is((Session{ID: "session"}).Validate(Launch{}), ErrIdentity) {
+ t.Fatal("empty matching launch identities accepted")
+ }
+ if !errors.Is((Event{TurnID: turn.ID}).ValidateIdentity(Session{}, turn), ErrIdentity) {
+ t.Fatal("empty matching session identities accepted")
+ }
+ if !errors.Is((Event{SessionID: session.ID}).ValidateIdentity(session, Turn{}), ErrIdentity) {
+ t.Fatal("empty matching turn identities accepted")
+ }
+ for _, test := range []struct {
+ name string
+ event Event
+ }{
+ {"attempt_as_session", Event{SessionID: launch.AttemptKey, TurnID: turn.ID}},
+ {"turn_as_session", Event{SessionID: turn.ID, TurnID: turn.ID}},
+ {"session_as_turn", Event{SessionID: session.ID, TurnID: session.ID}},
+ {"missing_session", Event{TurnID: turn.ID}},
+ {"missing_turn", Event{SessionID: session.ID}},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ if !errors.Is(test.event.ValidateIdentity(session, turn), ErrIdentity) {
+ t.Fatal("mismatched event accepted")
+ }
+ })
+ }
+ if !errors.Is((Event{}).ValidateIdentity(Session{}, Turn{}), ErrIdentity) {
+ t.Fatal("empty identities accepted")
+ }
+}
+
+// Method expressions check the public interface signatures without an adapter.
+func TestDirectInterfaceSignatures(t *testing.T) {
+ var _ func(Process) io.WriteCloser = Process.Stdin
+ var _ func(Process) io.ReadCloser = Process.Stdout
+ var _ func(Process) io.ReadCloser = Process.Stderr
+ var _ func(Process) string = Process.ID
+ var _ func(Process, context.Context) (Exit, error) = Process.Wait
+ var _ func(ProcessHost, context.Context, Launch, []string) (Process, error) = ProcessHost.Start
+ var _ func(Launcher, context.Context, Binding, Policy) (Identity, error) = Launcher.Preflight
+ var _ func(Launcher, context.Context, Launch) (Session, error) = Launcher.Open
+ var _ func(Launcher, context.Context, Session) (<-chan Event, error) = Launcher.Events
+ var _ func(Launcher, context.Context, Session, Turn) error = Launcher.StartTurn
+ var _ func(Launcher, context.Context, Session, Answer) error = Launcher.Respond
+ var _ func(Launcher, context.Context, Session) error = Launcher.Interrupt
+ var _ func(Launcher, context.Context, Session) error = Launcher.Close
+ var _ func(CaptureFactory, context.Context, Process, Launch) (*Capture, error) = CaptureFactory.Open
+ _ = Frame{Sequence: int64(1), Bytes: json.RawMessage(`{}`)}
+ _ = Capture{Input: (io.WriteCloser)(nil), Frames: (<-chan Frame)(nil), Done: (<-chan error)(nil)}
+ _ = Identity{AccountID: "account", HomeID: "home", ProviderVersion: "version"}
+ _ = Policy{Hash: "hash", Manifest: json.RawMessage(`{}`), Mounts: []Mount{{Source: "/source", Target: "/target", ReadOnly: true}}, Env: map[string]string{}, Settings: json.RawMessage(`{}`), MCP: json.RawMessage(`{}`)}
+ _ = Exit{Code: int(0), Signal: int(0), ObservedAt: time.Now()}
+ _ = Answer{RequestID: "request", TurnID: "turn", Behavior: "deny", Input: json.RawMessage(`{}`)}
+}
diff --git a/internal/runnerproto/containment.go b/internal/runnerproto/containment.go
index 8315495f..bdb4753c 100644
--- a/internal/runnerproto/containment.go
+++ b/internal/runnerproto/containment.go
@@ -30,6 +30,8 @@ type ProcessInventory struct {
CheckedAt time.Time `json:"checked_at"`
}
type ContainmentProof struct {
+ // Zero identifies a historical proof without a version field.
+ Version int `json:"version,omitempty"`
Scope team.Scope `json:"scope"`
Handle team.Handle `json:"handle"`
Owner ProcessOwner `json:"owner"`
diff --git a/internal/runnerproto/types.go b/internal/runnerproto/types.go
index 9f3a8405..80f7e66e 100644
--- a/internal/runnerproto/types.go
+++ b/internal/runnerproto/types.go
@@ -2,12 +2,14 @@ package runnerproto
import (
"amadan.net/oficina/equipo/internal/equipo/team"
+ "amadan.net/oficina/equipo/internal/runner/provider"
"encoding/json"
"time"
)
const (
- Version = 1
+ Version = 1 // Legacy Paseo runtime and enrolment.
+ DirectVersion = provider.Version
DeviceAudience = "equipo.device.v1"
RunnerAudience = "equipo.runner.v1"
PollIntervalSeconds = 5
@@ -117,6 +119,7 @@ type ConnectionRouting struct {
}
type ConnectionReport struct {
+ LauncherVersion, BwrapVersion, PolicyVersion string
TrialReady bool
ProviderVersionSource string
LocalID, Provider, ProviderVersion, PaseoVersion, Family, Model, AccountLabel, Kind, UnavailableReason, IsolationConfigHash string