# Slice 3 progress: Engineering

Branch `thin-v1-slice3` from `thin-v1-slice2b` (f77a0c9). Spec:
`docs/superpowers/specs/2026-11-06-equipo-thin-v1.md` §§0-3, 7, 8 row 3,
plus Paul's additions of 2026-11-07 (`slice3-additions.md`: agent-wide
forge credential, grants seen within a minute, a self-resolving grant
card, projects as products, tasks recorded at once with stages, findings
and a thread). Conventions and scripts as in `SLICE1-PROGRESS.md`,
`SLICE2-PROGRESS.md` and `SLICE2B-PROGRESS.md`.

## Plan

Headless first, in this order, each behaviour with a test that fails
first or a mutation shown to fail it:

1. Contracts (`internal/wire`): `Task`, `Step`, `Finding`, `ThreadEntry`,
   `TaskList`, project `title` and `attachments`, card `task_id`,
   snapshot `tasks`; events `task` and `step`; frames `dispatch`,
   `cancel_step`, `step`, `recheck`; `sync.steps`; coordinator tools
   `record_task`, `add_finding`, `start_task`, `read_task`, `cancel_task`.
2. Instance: task, step, thread and attachment tables; the tools
   authorised in the runner frame's transaction; `GET /tasks`,
   `GET /tasks/{id}`, `POST /tasks/{id}/cancel`, `POST /tasks/{id}/retry`
   (refused until the runner confirmed termination of the current
   attempt), `GET /steps/{id}/log`, `POST /tasks/{id}/thread`; forward-only
   step reports; `sync` settles steps; grant card resolves itself.
3. Runner: `steps` table with a unique running index per task; one step
   at a time; worktree from the project clone with a private git dir the
   namespace never sees; the Engineering CLI in bubblewrap (the existing
   `implement` action, unchanged containment); runner commit; candidate
   SHA recorded; push through `internal/runner/forge` with
   record-then-reconcile and a lease check right before the push;
   cancel and crash end with a termination report; agent-wide forge
   credential; a cheap periodic reach check and `recheck`.
4. Headless scenarios: 2 to the branch, 4 (runner killed mid-step,
   termination, retry), cancel, grant resolves.
5. Staging with the real CLI; the Woodstar witness.
6. UI: task card (receipt style) with Retry and Cancel, Tasks page and
   Projects page on API v1.

## Done

1. Contracts (`internal/wire/tasks.go`, fixtures): resources `Task`
   (project, repo, title, brief, stage, branch, base SHA, URL, creator,
   turn, findings, steps, thread), `Step` (index, specialist, state,
   reason, attempt, base and candidate SHA, pushed, terminated, summary,
   log tail), `Finding` (text, repo, path, line), `ThreadEntry`,
   `TaskList`, `TaskAccepted`, `StepLog`, `PostThread`; `Project.title`
   and `Project.attachments` (`{kind: repo, ref, name}`); `Card.task_id`;
   `Snapshot.tasks`; events `task` and `step`; frames `dispatch`,
   `cancel_step`, `step`, `recheck` (all durable) and `Sync.steps`; stages
   noted, investigated, in_progress, in_review, ready_to_merge, done,
   cancelled (in_review and ready_to_merge defined, not reached); tools
   `record_task`, `add_finding`, `start_task`, `read_task`,
   `cancel_task`; `TaskBranch` is `equipo/<task-id>-<slug>`.

2. Instance (`internal/equipo/chat/tasks.go`, migration 0043): tasks,
   steps, entries (findings and thread notes) and project attachments
   are team records; every active member gets their events. The tools
   are authorised in the runner frame's transaction like the slice 2
   tools: `record_task` (repository from the allowlist, adds the project
   with its receipt, task noted, a task card in the turn), `add_finding`
   (the team's task, a repository in the catalog, a clean path; noted
   becomes investigated), `start_task` (owner only, once per task; the
   step, the dispatch command and the events in one transaction),
   `read_task`, `cancel_task`. Routes: `GET /tasks`, `GET /tasks/{id}`,
   `POST /tasks/{id}/cancel` (at once when no step runs, else a
   `cancel_step` and the task ends on the runner's termination report),
   `POST /tasks/{id}/retry` (409 `not_retryable` until the current
   attempt failed with termination; a new attempt from the recorded
   base), `GET /steps/{id}/log`, `POST /tasks/{id}/thread` (idempotent).
   Step reports: only the current attempt, only forward, base and
   candidate set once per attempt, done only for the attempt's own
   pushed candidate. `sync` settles a step the primary runner no longer
   holds (failed, `interrupted`, terminated) unless its dispatch is
   still unacked. Projects are products: titled from the catalog
   (woodstar is Woodstar; oficina/sample's README heading Woodstar),
   with the repository attached.
   Tests: `TestContractTasks`, `TestContractStepSync`,
   `TestContractTaskToolsScope`. Mutations observed failing: Retry
   without termination, stale attempt accepted, candidate changed,
   cancel ending before the runner, sync settling a held step, sync
   settling an unacked dispatch, done with another candidate.

3. Forge (`internal/runner/forge/branch.go`): `PushBranch`, the
   runner's only push. Validates the repository, the task branch
   (`equipo/...`, never the default), the candidate (a descendant of the
   base, present and connected in the runner's private repository) and
   the person (one of the runner's owners); writes a record before any
   network write; confirms the lease right before the push; pushes with
   `--force-with-lease` on the observed head; a later call for the same
   attempt reconciles from the remote (already there is success, no
   second push). Tests: `TestPushBranch`,
   `TestPushBranchReconcilesACutPush`, `TestPushBranchRefuses`; each
   guard mutated and observed failing.

4. Workspace (`internal/runner/workspace/task.go`): `TaskTree`. The
   namespace sees only the files at the base (no `.git`); the runner's
   private repository (under its state directory, never mounted)
   borrows the clone's objects; the runner commits what changed
   (`add -A`, `write-tree`, `commit-tree` on the base) and refuses a
   `.git` entry at any depth or a special file. No filter, hook or
   config from the repository runs (`TestTaskTree` plants them).

5. Runner (`step.go`, `engineer.go`): a `steps` table with a unique
   running attempt per task; dispatch, cancel (a cancel first holds the
   attempt so a late dispatch never runs) and reports through the
   outbox; a step engine that runs one attempt at a time; the Engineer:
   lease, clone, base (the default branch's tip, reported), task tree,
   the CLI in the existing `implement` profile (workspace read-write,
   containment and policy unchanged), a permission callback with nobody
   to ask (`claude.StepPermission`: workspace file actions under the
   same protected-path and field checks, everything else denied), the
   step's pinned tools answered "not needed", a per-step log and a
   bounded tail, the runner's commit, the candidate recorded before the
   push, `PushBranch`. Cancel kills the namespace; every final report
   carries termination only once the namespace exit was observed. After
   a crash, an attempt that had not committed is reported failed
   (`runner_restarted`) with termination (namespaces verified gone at
   start); a committed one only pushes. Tests: `TestStepState*`,
   `TestEngineerRefusesOtherPersons`, `TestStepPermission`; mutations
   observed failing: recovery, cancel mark, cancel-first hold, unique
   running index, persons, permission callback, termination.

6. House rule 2026-11-07.6: record the task at once, investigate, attach
   findings, start the task, reply in two or three lines; never offer
   to merge or open a pull request; when nothing is reachable, one short
   line and no repeat of the grant card.

7. Paul's additions: the forge credential file's agent-wide
   `{agent, api, git}` serves every repository the hub lists for the
   agent (per-repository entries override); `Repos` (the allowlist) is
   the file, created and hub-listed repositories. The hub list is
   trusted 55 s and asked conditionally (`If-None-Match`); a watcher
   checks reach about once a minute and at once on `recheck`; a change
   goes out in a hello and the index fetches only the new repositories
   (`Index.Delta`). Access cards carry the namespace the name says
   (`NamespaceGuess`: Woodstar is woodstar), the check action (`choice:
   check`) sends `recheck`, and an open card resolves itself when a
   hello's catalog reaches the name. Tests: `TestContractGrantCard`,
   `TestForgeCredentialAgentWide`, headless `3_grant` (resolved 48 ms
   after the check).

8. Headless (fake CLI in real bwrap, local forge): `3_engineering`
   (scenario 2 to the branch: noted 0.9 s after the send, stages noted,
   investigated, in_progress, step done and pushed in about 2 s, branch
   at the candidate in the forge, parent the base, README fixed, main
   unmoved, log tail), `4_step_crash` (SIGKILL mid-step, Retry 409
   while down, failed `runner_restarted` with termination after
   restart, attempt 2 pushed), `3_step_cancel`, `3_step_contained`
   (writes to `/etc` and the runtime home denied), `3_grant`. The whole
   suite runs in 90 s locally.

9. UI (built by a forked session on `thin-v1-slice3-ui` up to 468563c,
   merged): the task card is a quiet receipt before its turn's
   reply: the title (linking to `/tasks/<id>`) and its stage in plain
   words, or "Stopped: <reason>"; once pushed "Pushed <branch> at
   <sha7>" and Open on Amadan; Retry only after a failure with
   termination, Cancel until the task ends; actions on hover or focus,
   behind ⋯ on touch; `task` and `step` events refresh the feed like
   card events. Grant card: the real `amadan agent grant <agent>
   <namespace>` and Check now; resolved, one line "<name> is reachable
   now." Tasks page `/tasks` (all team tasks, `?project=` filter) and
   `/tasks/tk…` (findings, steps with summary and log tail, notes,
   Retry, Cancel); "Tasks" in the nav. Projects page `/projects`
   (titles, attachments, task counts, no forms or budgets) and
   `/projects/p_…`; the old overview moved to `/projects/accounts`.
   `TestBrowserTaskCard` at 390 px touch, `TestPages*`; mutations
   observed failing: receipt placement, Retry before termination,
   project filter, namespace in the command, resolved card, Cancel,
   the task/step stream listeners.

10. Person API overlap: the old engine's `GET /tasks` (browser
    session), `GET /tasks/{id}` and `POST /tasks/{id}/cancel` (old,
    upper-case ids) still serve the old tasks until the slice 7 sweep;
    a device bearer and `tk` ids get the thin routes (plan3test was
    failing on this and passes now).

11. Live fix: the project clone is shallow (the index fetches with
    depth 1), so the first live push was refused when the private
    repository could not walk past the base. The private repository now
    carries the clone's shallow boundary (`TestTaskTreeFromShallowClone`
    failed first; the local forge's sample gained history and
    `3_engineering` failed without the fix).

12. Merged `thin-v1-slice2b` at 721732c (notebook UI) as the
    coordinator asked; `thin-v1-thinking` waits for Paul's pick.

13. Review round 1 (Astra at 9ad3dbb, REQUEST CHANGES, five Important
    and one Minor), after merging `thin-v1-slice2b` at 001736f. Each fix
    has a test that failed first and a mutation observed failing:
    1. Execution authority: tasks and projects stay shared within the
       team (reads, events), but only a task's creator starts, retries
       or cancels it, onto their own runner, through API v1 (403), the
       pages (no Retry or Cancel for a teammate; 403 on post) and the
       coordinator tools (`not_yours` for start_task, cancel_task and
       add_finding; read_task allowed). Removed members read nothing.
       `TestContractTaskAuthority` (two owners, two runners).
    2. Termination needs the containment's verified exit: Wait's error
       is kept, and an unverified exit is no termination (no commit,
       publish or Retry), its namespace record kept (`TestStopStep...`).
    3. A push replaces only its recorded predecessor (no branch, or a
       commit an earlier attempt pushed), fixed before the first push; a
       reconcile that finds another head is a conflict, never a force
       (`TestPushBranchNeverOverwritesOthers`: lost answer, then the
       person advances; `TestPushBranchLeaseHolds`: the branch moves
       mid-push).
    4. A step's private repository is kept until its final report is
       acked, then swept; a recorded push already on the remote
       reconciles as published before any local check
       (`TestPushBranchReconcilesWithoutTheRepository`,
       `TestStepFilesKeptUntilAcked`).
    5. Unproven terminations stay `pending` (with their namespace id)
       through acks and restarts; startup and every sync re-probe them
       through the containment, and a verified exit sends a follow-up
       report with termination, so Retry becomes possible; startup
       recovery claims termination only for namespaces it verified
       (`TestStepPendingTermination`, `TestStepRecoverWithoutProof`).
    6. Minor: a grant card resolves only for its intended namespace or a
       repository named after it, never on a fuzzy hit.
    7. Paul: a click anywhere in the compose box focuses the message
       (`chat-compose.js`, its own file so the thinking-line branch
       merges cleanly); `TestBrowserComposerFocus` at 1280 with a mouse
       and 390 with touch, Send keeps its click.

## Decisions

- Tool set: `record_task`, `add_finding`, `start_task(task, brief)`,
  `read_task`, `cancel_task` instead of one `start_task(project, kind,
  brief, steps[])`: Paul asked for the task to exist before any code,
  and findings to attach to it. One Engineering step per task in slice
  3; Review is slice 4.
- After its step pushes, a task stays `in_progress` (slice 4 moves it to
  review). The card shows the branch, the SHA and Open on Amadan.
- Open on Amadan is `https://amadan.net/<ns>/<repo>?branch=<branch>`
  (the hub routes `?branch=` on the repository page; `/tree/...` is not
  a route).
- The Engineering step runs the existing `implement` profile unchanged
  (its policy, mounts and init check), so containment is exactly as in
  §5; its pinned tools (`submit_candidate`, `ask_person`,
  `submit_render`) are served and answer that the runner commits.
- The model never runs git on the task: the working copy has no `.git`,
  and the runner commits after the namespace has exited.
- Commit identity: `Equipo Engineering <engineering@equipo.invalid>`.
- Retry starts the step again from the recorded base, on the same task
  branch (`--force-with-lease` on the observed head).
- Thread notes are recorded and shown; they do not start a coordinator
  turn yet (the coordinator reads them with `read_task`).
- The person check in `stepReport` is defence in depth: the primary
  runner check that follows already refuses another person's runner, so
  no test can observe it alone. Likewise `StepPermission`'s protected
  path check (the allow path repeats it).
- `internal/runner/thin` is over the 5,000-line ceiling (5,686): a
  recorded exemption to 6,000 until the slice 7 sweep.

## Live runs (budget: 12 coordinator turns, 4 Engineering steps)

Used: 1 coordinator turn, 2 Engineering steps. No automatic move-in or
explore turn ran on the suite runner (its turns today: only the one).

1. Release 0b54b1b (deployed with `--swap hold`, both staging runner
   units installed), suite person, scripted message "Fix the Woodstar
   iOS swipe-back bug." (1 counted turn, Engineering step 1):
   - task `tklkbx5vid3y` noted 4.0 s after the send, under the
     woodstar/woodstar project (Working in card), stages noted,
     investigated, in_progress;
   - finding: the outer navigation controller hides its bar, which
     turns off the edge swipe (`ios/Woodstar/AccountNavigationHost.swift:15`);
   - the reply: "I found the cause and Engineering is fixing it now in
     woodstar. ..." (no question, no merge offer);
   - step 1 ran the real CLI in containment (read three Swift files,
     edited the host, the compact navigation and a UI test), the runner
     committed `e971eb4`; the push was refused: shallow clone (item 11).
     Failed `push_failed` with termination, so Retry was allowed.
2. Release 3d3dba3 (the fix), Retry through `POST /api/v1/tasks/
   tklkbx5vid3y/retry` (202, attempt 2; Engineering step 2): started
   13:59:45, done 14:00:29 (44 s), candidate `82a4a0cc643155fb7e3e1f6a3a1dbd66cf8d44c3`
   on base `0194d925`, pushed, terminated. `git ls-remote` on
   amadan.net/woodstar/woodstar shows
   `equipo/tklkbx5vid3y-ios-edge-swipe-to-go-back-doesn-t-work-o` at
   that SHA; Woodstar's main untouched by Equipo; no PR opened. The
   card's URL: https://amadan.net/woodstar/woodstar?branch=equipo/tklkbx5vid3y-ios-edge-swipe-to-go-back-doesn-t-work-o
   The step's summary says it could not build or run the iOS UI test on
   Linux and asks for that before merging.

## Copy for review

Accepted for now with the existing marker in `copy.go` (and listed in
the plan 3 inventory):
- `nav.tasks` "Tasks"
- `chat.card.access_resolved` "%s is reachable now."
- `chat.card.grant_check` "Check now"
- `work.stage.noted` "Noted", `work.stage.investigated` "Looking into
  it", `work.stage.in_progress` "In progress", `work.stage.in_review`
  "In review", `work.stage.ready_to_merge` "Ready to merge",
  `work.stage.done` "Done", `work.stage.cancelled` "Cancelled"
- `work.stopped` "Stopped: %s"
- `work.reason.runner_restarted` "the runner restarted",
  `no_changes` "nothing needed changing", `push_failed` "the push to
  Amadan failed", `push_conflict` "the branch changed on Amadan",
  `step_timeout` "it ran out of time", `interrupted` "the runner lost
  track of it", `other` "something went wrong"
- `work.pushed` "Pushed %s at %s", `work.open` "Open on Amadan",
  `work.retry` "Retry", `work.cancel` "Cancel"
- `work.step` "Engineering, attempt %d: %s"; `work.step.queued`
  "waiting", `running` "working", `done` "done", `failed` "stopped",
  `cancelled` "cancelled"
- `work.findings` "Findings", `work.steps` "Engineering", `work.notes`
  "Notes", `work.note_add` "Add a note", `work.notes_empty` "No notes
  yet.", `work.noted_by` "Noted by %s"
- `work.tasks_empty` "No tasks yet. Tell the coordinator what needs
  doing.", `work.all_tasks` "All tasks", `work.projects_empty` "No
  projects yet. They appear here when the coordinator adds them.",
  `work.task_count` "Tasks: %d"
- `chat.activity.record_task` "Noting the task…"
- `chat.activity.add_finding` "Noting what I found…"
- `chat.activity.start_task` "Handing it to Engineering…"
- `chat.activity.read_task` "Checking the task…"
- `chat.activity.cancel_task` "Cancelling the task…"

## Open issues

- Staging is shared with the 2b review session, which restaged 721732c
  at 14:00:56; the final slice 3 build is restaged after CI.
- The hub sends no ETag for `/api/v1/repos`, so the minute check is a
  plain small GET per runner.
- Engineering cannot build or test iOS on the Linux runner; the step
  says so in its summary. Review and checks are slice 4.
- `TestBrowserMoveIn` waits 5 s for the move-in line; under a load of
  30+ on this box it timed out once in a full browser run (passes
  alone and in later full runs). Browser tests are not in CI.
- `internal/headless` measured 158 to 207 s locally under load (budget
  180 s; CI measured 98 s before the merges).
- Retry of a step whose push failed runs the specialist again (a new
  attempt); re-publishing the earlier candidate alone is not offered.
- A recorded task branch keeps attempt 1's slug from the coordinator's
  title (`...-doesn-t-work-o`, cut at 40 characters).

## Blockers

None yet.
