# Agent setup controller report

Round 2 adds automatic coordinator binding, setup and failure notes, and chat
focus/transition fixes. The round 2 evidence and handoff follow the original
R1–R5 report below.

The coordinator can propose a repository project in the conversation. The
project is created only when its person taps **Set up**. **Not now** closes
the card without creating a project. This branch was rebased onto `main`
`96920a2` after the chat UI merge. Commit only; the controller pushes.

## Delivered

- R1: each normal heartbeat sends the sorted repository keys from the dedicated
  forge credential file. Legacy string values and separate API/Git values both
  work. No credential values enter the report. The instance replaces the list
  per authenticated runner and resolves the person through the current runner
  and roster. Failed local discovery withdraws old names. Revoked runners are
  excluded immediately. Rotation-only heartbeats leave discovery unchanged.
- R2: `propose_project({repository, why})` is in the coordinator-only tool list.
  Repository names must match a current report from this person's runners.
  Proposals are private, audited, replayable and deduplicated while pending.
  Confirmation checks the person, binding generation, current owner role,
  repository report and card revision inside the write transaction. It uses the
  existing project validator. Account, project, decision owners, audit, card
  update and follow-up message commit together. Replay creates nothing twice.
- R3: the prompt tells the coordinator to propose setup for a new repository or
  app and to recommend a repository when the team has no projects. Context
  contains reported names and eligible existing project metadata. Existing
  project restrictions still apply to the selected model connection. Empty
  conversations explain that people can say what they want fixed.
- R4: the optional new-project form requires only a repository. A datalist offers
  reported names and still accepts typed names. More options is collapsed.
  Existing project edits keep the previous validation path.
- R5: only coordinator policy inventories changed. Its obsolete live certificate
  was removed from the active manifest. Both specialist certificates, their
  isolation tuples and all specialist inventory hashes are unchanged. Historical
  evidence files are unchanged. The coordinator remains uncertified.

Defaults: the last repository segment supplies the name; its namespace supplies
an account label, created if needed; kind is Repository; branch is `main`; the
confirming person owns work and merge decisions. No project playbook or approval
override is written. The existing team/kind playbook resolution and approval
default apply. Tests verify an installed team playbook is inherited. Model
connection consent and execution gates retain their existing behavior.

Migration `0034_agent_setup.sql` adds `runner_repositories` and
`project_proposals`; Models and the schema snapshot match. Form parsing lives in
`setup`, and the new integration tests have their own package. Size budgets were
not raised. The historical reference inventory received only the changed model
line's hash.

## Policy identities

These are portable constructor inventory hashes, not new live certificates.

| Provider/action | Before | After |
|---|---|---|
| Claude/coordinate | `a671f7b2fe5b2d9864684d2260400f278041f35f0b33afbe7e2569551aba9e7f` | `ed4d28bda3454a731a0265a46f25d7b567ad05606ef288751100eb4b31e7f6f2` |
| Codex/coordinate | `d6815e9d94c8c96ae63e40505011be6c7ec226db1e2479454eee83ca6b8f4c6e` | `26a6d7dbb36a6787f651a22ae9785ac827e02bb8de8b89f93a0b403108577a86` |

The retired Claude coordinator live policy hash is
`7390776107a4ae309ed3182e2c6079dd08e7f4fdcaee0cb64287eb2bf0671529`.
The controller must rerun the starter gate for the new coordinator policies.
Offline tests grant no production certification.

## Verification

Before implementation:

- `CGO_ENABLED=0 go test ./internal/coordinator -run '^TestProposeProjectSchema' -count=1`
  failed with `runner.invalid` for the new tool.
- `CGO_ENABLED=0 go test ./internal/plan3test -run '^TestAgentSetup' -count=1`
  failed to compile because the reporting and proposal-answer APIs did not exist.
  These tests were later moved to `internal/agentsetuptest` to keep the existing
  package within its size budget.
- `CGO_ENABLED=0 go test ./internal/agentsetuptest -run '^TestAgentSetupContextScope$' -count=1`
  failed with `setup context disclosed a project denied to this connection`.
  Applying the existing project-access check restored it.

Passing targeted commands:

```sh
CGO_ENABLED=0 go test ./internal/agentsetuptest -count=1
CGO_ENABLED=0 go test ./internal/coordinator ./internal/equipo ./internal/release ./internal/runner/transporttest -run 'TestProposeProjectSchema|TestCoordinatorToolAllowlist|TestMigrationModels|TestConversationMigrationSnapshot|TestPlanWorkflowReleasePolicyInventory|TestRunnerHeartbeatWireReports' -count=1
CGO_ENABLED=0 go test ./internal/runner/forge ./internal/runner/heartbeat -run 'TestRepositoryNames|TestForgeCredential' -count=1
CGO_ENABLED=0 go test ./internal/plan3test ./internal/runner/provider/claude ./internal/runner/provider/codex -run 'TestCoordinatorAuthorityProjectContext|TestCoordinatorContext|TestCoordinatorSessionContinuity' -count=1
```

The fake CLI is a local Python subprocess that reads the actual coordinator
prompt and emits `propose_project`. Its call crosses the real tool broker,
runner journal, loopback HTTP protocol and instance transaction. Repository
URL, app name and no-project cases each reach a card, then an authenticated
HTML form tap, then one persisted project. Provider event transport and
containment are simulated; no live provider account is used.

### Guard mutations

Each mutation was applied alone and restored. Each command below exited 1
with an assertion failure, rather than a compilation failure. The restored
suite passes. The card-state test removes a queue replay record to check the
state guard independently of queue idempotency. An initial weaker test was
strengthened after that separate guard concealed the mutation.

Use `CGO_ENABLED=0 go test <package> -run '<filter>' -count=1`:

| Guard deliberately broken | Package | Filter | Observed failure |
|---|---|---|---|
| repository allowlist | `./internal/agentsetuptest` | `^TestAgentSetupGuards/unreported$` | unreachable repository accepted |
| tap rechecks discovery | `./internal/agentsetuptest` | `^TestAgentSetupGuards/withdrawn$` | guard accepted withdrawn |
| current owner | `./internal/agentsetuptest` | `^TestAgentSetupGuards/role$` | guard accepted role |
| binding generation | `./internal/agentsetuptest` | `^TestAgentSetupGuards/generation$` | guard accepted generation |
| card revision | `./internal/agentsetuptest` | `^TestAgentSetupGuards/stale$` | guard accepted stale |
| card terminal state | `./internal/agentsetuptest` | `^TestAgentSetupDuplicateAndDecline$` | declined card reused |
| person isolation | `./internal/agentsetuptest` | `^TestAgentSetupTap$` | another person accepted |
| pending deduplication | `./internal/agentsetuptest` | `^TestAgentSetupDuplicateAndDecline$` | duplicate pending card |
| existing project | `./internal/agentsetuptest` | `^TestAgentSetupDuplicateAndDecline$` | existing project proposed |
| audit atomicity | `./internal/agentsetuptest` | `^TestAgentSetupGuards/audit$` | guard accepted audit |
| decline consent | `./internal/agentsetuptest` | `^TestAgentSetupGuards/decline$` | refused proposal created a project |
| coordinator instructions | `./internal/agentsetuptest` | `^TestAgentSetupFakeCLI/Fix_new-app$` | Fake CLI instruction assertion failed |
| heartbeat names | `./internal/runner/heartbeat` | `^TestRepositoryNames$` | names missing from serialized heartbeat |
| runner revocation | `./internal/agentsetuptest` | `^TestAgentSetupHeartbeat$` | revoked runner repository retained |

### Full gate

Two complete `make -k ci` runs were made. The first exited 2. It exposed
context visibility regressions, expected certification-count changes, the
missing copy-inventory rows, one stale reference hash and one lint finding.
Targeted reruns of every failing group passed after correction.

The single full rerun exited 0: 34 test packages ran uncached with zero
failures. Build, vet, formatting, static analysis, vulnerability and secret
scans, reference inventory, size budgets, adapter checks, namespace checks,
migration comparison and performance checks passed. The conversation's median
response was 20.587 ms against 150 ms; cold boot was 111 ms against 500 ms.

The local run printed timing warnings for existing packages. These are
informational locally but are enforced in CI; no time limits were raised:

| Package | Measured | Limit |
|---|---:|---:|
| `internal/runner` | 5m56.061s | 5m30s |
| `internal/runner/provider` | 21.532s | 15s |
| `internal/runner/provider/claude` | 47.184s | 45s |
| `internal/runner/provider/codex` | 39.056s | 35s |

The new integration package passed within its unchanged 10-second default.
Its independent guard and fake-CLI cases run in parallel.

### Browser evidence

Both widths passed browser checks for one confirmation card, live creation and
completion, no horizontal overflow, a repository datalist and one required
field. The scriptless variant also submitted the real confirmation form.

```sh
EQUIPO_BROWSER_ARTIFACTS="$PWD/docs/mockups/built/2026-11-06" CGO_ENABLED=0 go test -tags browser ./internal/agentsetuptest -run '^TestAgentSetupBrowser' -count=1
EQUIPO_BROWSER_NO_JS=1 CGO_ENABLED=0 go test -tags browser ./internal/agentsetuptest -run '^TestAgentSetupBrowser' -count=1
```

Screenshots are in `docs/mockups/built/2026-11-06/`:
`agent-setup-card-1280.png`, `agent-setup-card-390.png`,
`agent-setup-empty-1280.png`, `agent-setup-empty-390.png`.

## Copy and handoff

No copy-review server was started. Eleven new strings and the revised
`conversation.empty` are individually marked `COPY REVIEW PENDING` in
`internal/equipo/copy.go`. The existing complete copy inventory in
`CONTROLLER-REPORT-plan-3.md` contains the same text and marks it for review.
README prose was left unchanged.

The controller's remaining work is to review copy, rerun the live starter gate,
and push this commit. No merge, push or deployment was performed here.
All servers and browser processes started for the checks have stopped. Scratch
files created for this task were removed; default Go caches were retained.
The supplied worktree remains in place for the controller.

## Round 2: automatic coordinator binding (2026-11-06)

Merged local `main` first as `449715a`. The only conflict was in `copy.go`:
kept the previous agent-setup empty state pending and retained main's approvals
for unchanged chat strings. No fetch or push was attempted.

A1: sending a main-conversation message now binds an unconfigured coordinator
to the first eligible connection by ID. Candidates belong to the current
person and an active runner in this instance. The release must certify the
provider's coordinate action; reported provider, launcher, bubblewrap and
policy versions must match. Existing freshness, availability, routing and
isolation checks apply. The binding records current member and connection
revisions. Message, binding, human-attributed audit, queued turn and system
note commit together. A replay adds no note, binding or turn. Existing bindings
are retained, including explicit project selection and the existing poll path.

A2: missing runners, connections, certification or usable online connections
produce a plain system note with the next action. Existing offline or changed
bindings also explain the problem when sending. Interrupted, fenced, waiting
connection and budget states are visible in the conversation. Lease and attempt
deadlines produce a timeout note, with live refresh scheduled for both. Retry
controls for uncertain turns remain hidden until containment is confirmed.
Reads do not rewrite turn state or authorize a new attempt.

A3: an app-owned script skips cross-document transitions when the source and
destination have the same origin, path and query. Composer and answer forms
restore focus to the composer after POST + 303; ordinary page navigation keeps
its transition. Browser tests exercise actual composer and project-answer
submissions at 1280 and 390. Vendored Rastrillo files remain byte-identical.

Selection logic moved into the conversation package to stay within the existing
source budget. No budget, migration, schema, policy constructor, policy inventory
or certification file changed in round 2. The prior coordinator hashes above
still apply. Its live certification is still required; the fake release injected
by tests cannot authorize a real runner's policy or executable checks.

### Round 2 verification

Initial failing tests:

- `CGO_ENABLED=0 go test ./internal/agentsetuptest -run 'TestCoordinatorMissingSetupNote|TestCoordinatorFailureVisible' -count=1`
  failed with a missing setup note and silent uncertain, fenced, waiting
  connection and budget states.
- `CGO_ENABLED=0 go test ./internal/agentsetuptest -run '^TestCoordinatorExistingOfflineNote$' -count=1`
  failed because an existing offline binding produced no note.

The fake Python CLI now receives an authenticated first HTML message with no
binding, runs through automatic binding and the real runner protocol, posts a
reply with `post_message`, and reaches delivered state. A separate subprocess
failure reaches an uncertain turn with a visible recovery action after
containment. Existing project-proposal flows still pass. No live provider is
used; containment and provider event transport are simulated.

Eleven guard mutations each exited 1 with a test assertion, then were restored.
Commands use `CGO_ENABLED=0 go test ./internal/agentsetuptest -run '<filter>' -count=1`:

| Broken guard | Filter | Observed failure |
|---|---|---|
| coordinate certification | `^TestCoordinatorAutoBind/uncertified$` | ineligible binding accepted |
| online freshness | `^TestCoordinatorAutoBind/offline$` | offline binding accepted |
| certified provider version | `^TestCoordinatorAutoBind/wrong-version$` | wrong version accepted |
| candidate person filter | `^TestCoordinatorAutoBind/eligible$` | eligible binding missing |
| connection revocation | `^TestCoordinatorAutoBind/connection-revoked$` | revoked connection bound |
| deterministic order | `^TestCoordinatorAutoBind/deterministic$` | wrong binding selected |
| audit atomicity | `^TestCoordinatorAutoBind/audit$` | audit failure ignored |
| setup replay | `^TestCoordinatorMissingSetupNote$` | replay attempted duplicate setup write |
| failure visibility | `^TestCoordinatorFailureVisible/uncertain$` | silent turn |
| timeout visibility | `^TestCoordinatorTimeoutVisible$` | timeout note missing |
| same-page transition skip | `^TestAgentSetupBrowser/390$` with `-tags browser` | transition was not skipped |

The certification and version fixtures were strengthened after independent
version and isolation checks initially concealed those mutations. Restored
checks cover current membership, foreign ownership, revoked runners and
connections, unavailable reports, lookup/decode errors and audit rollback.
Timeout tests also verify that live refresh is scheduled. Historical conversation
and migration assertions now include the setup note beside the person's message.

Eight new copy entries and the revised `coordinator.uncertain` and
`coordinator.waiting_connection` are individually marked `COPY REVIEW PENDING`.
The consolidated Plan 3 copy inventory contains their exact text. The controller
applies Paul's acceptance before release. No copy-review server was started;
README prose is unchanged.

Targeted checks passed:

```sh
CGO_ENABLED=0 go test ./internal/agentsetuptest -count=1
CGO_ENABLED=0 go test -tags browser ./internal/agentsetuptest -run '^TestAgentSetupBrowser' -count=1
CGO_ENABLED=0 go test ./internal/agentsetuptest ./internal/plan3test -run 'TestCoordinatorAutoBind|TestCoordinatorExistingOfflineNote|TestPlan3ReleaseBoundaries/inventory' -count=1
```

The first full `make -k ci` exited 2 with one failing package:
`internal/tryequipo`, test `TestAutomaticAnswerProcessChain`. Its captured
terminal output showed the provider check passing and the shell printing
`exit`; the Python driver then failed its one-shot, nonblocking child-exit
check. A process-reaping race is the likely cause, not a proven diagnosis.
`CGO_ENABLED=0 go test ./internal/tryequipo -run '^TestAutomaticAnswerProcessChain$' -count=3 -v`
passed all three isolated runs. That unrelated fixture is unchanged.

Every other gate passed on the first full run. Conversation median response was
19.594 ms against 150 ms; cold boot was 110 ms against 500 ms. Existing local-only
timing warnings: runner 5m54.874s/5m30s, provider 22.456s/15s, Claude
53.751s/45s, Codex 43.872s/35s. No time limits were raised.

The single full rerun exited 0. All 34 test packages ran uncached with zero
failures. Reference scan, build, vet, formatting, static analysis, vulnerability
and secret scans, size budgets, adapter and namespace checks, migration
comparison and performance passed. Conversation median response was 20.991 ms;
cold boot was 115 ms. The four local timing warnings remained: runner
5m54.195s/5m30s, provider 21.528s/15s, Claude 47.469s/45s and Codex 39.94s/35s.
Timing limits are enforced in CI environments; these existing warnings were not
waived or changed. Two full runs total, one rerun; no third run.

Controller: apply copy acceptance, rerun live coordinator certification and push
the local commits. No push or deployment was performed. Test servers and browser
processes have stopped, and task scratch was removed. Default Go caches and the
controller-provided worktree remain in place.
