# Slice 2 progress: Tools and projects

Branch `thin-v1-slice2` from `thin-v1-slice1` (3ddf7d0). Spec:
`docs/superpowers/specs/2026-11-06-equipo-thin-v1.md` §8 row 2, plus four
additions from Paul on 2026-11-07 (thinking line, no repository
questions, keyboard-safe chat, context index). Conventions and scripts as
in `SLICE1-PROGRESS.md`.

## Done

1. Contracts (`internal/wire`, fixtures under `wiretest/testdata`):
   resources `Project`, `ProjectList`, `Card`, `Answered`, `CardConflict`,
   `Activity`, `TurnTiming` (on `Turn`, null until replied); routes
   `GET/POST /projects`, `DELETE /projects/{id}`,
   `POST /cards/{id}/answer` (409 with the current card when stale or
   answered); events `card`, `project`, `activity`; frames `tool_call`,
   `tool_result` (both durable), `activity` (sent once, like deltas);
   `hello` gained `create_in`, `home`, `agent` and `catalog`.

2. Instance (`internal/equipo/chat`, migration 0037): projects are team
   records; cards belong to one person's conversation. Every tool call is
   authorised inside the runner frame's write transaction: the lease and
   credential (`current`), the person's primary runner, the turn running on
   that attempt; results are stored by call id, so a repeat returns the
   stored result. Tools:
   - `status` (read only: runner versions, connections, projects,
     `can_add`, `create_in`, `home`; no secrets or paths),
   - `find` (catalog match by name, alias, summary, hint; nothing
     reachable puts one access card in the conversation),
   - `search_code` and `read_file` (authorised for repositories in the
     catalog; the runner reads its own clone),
   - `add_project` (only the person's runner-advertised allowlist; Added
     card for a new project, Working in for an existing one),
   - `create_project` (instance authorises: a namespace the agent may
     create in, no such project; runner creates; `project_created`
     confirmed only after that turn's authorisation) with a Created card,
   - `ask_person` (question card; the answer becomes the person's next
     message, prefixed for the coordinator with the question).
   Change on a project card points the work at another repository (the
   choice is the person's message); Remove marks the project removed and
   its cards removed. Adding or creating never widens publishing
   authority: the agent already writes there, and forge checks still guard
   every push.

3. Runner (`internal/runner/thin`): the coordinator's tool socket lists
   exactly the conversation's tools (`provider.ConverseTools`) and the
   permission callback, which allows only those; the policy allows the
   same MCP tools (nothing native). Calls go to the instance as durable
   `tool_call` frames and wait for `tool_result`. Clone on demand: added,
   created and read projects are fetched into
   `<workspace root>/repos/<hash>-<name>.git` (bare), git with hooks,
   helpers and system config off, the forge git password in a
   `GIT_CONFIG_*` header in the environment (never argv or logs).
   Context index: every repository the agent reaches (credential file,
   created, and the hub's writable list) is shallow-fetched hourly; the
   catalog (summary from README or AGENTS.md, names from headings,
   manifests, app bundles and repeated capitalised words such as
   Woodstar, language hints, default branch, last update) goes in hello,
   bounded to 100 repositories. A fresh session's opening lists it.
   Activity: thinking and tool starts from `stream_event`
   `content_block_start` (tool name only). Timing: each reply carries
   where its time went.

4. House rule (fresh session): decide where work goes and report it in
   one line; never ask the person to choose a repository, never list
   repositories to pick, never mention Set up; existing work goes to the
   repository that clearly fits, new work to a new repository in the
   related namespace or home, otherwise best fit with one short reason;
   names of apps go through `find`, then `search_code` and `read_file`;
   nothing reachable gets one line ending "Grant access".

5. Headless (fake CLI, local forge of bare repositories): scenario 2 to
   the project (`project`), `find` (Woodstar found, code read, granted
   repository readable, path tricks refused, Moonbeam gets the access
   card), `new_work` (created in oficina, refused outside, Change, Remove)
   and `question` (422 outside the options, 409 stale and answered). All
   slice 1 scenarios still green. Live variants assert no repository or
   framework question and a project or access card.

6. Chat page: cards under the message that ends their turn (Added /
   Working in / Created with Change or Move and Remove; question options or
   a text answer; access card with the grant command), posted in the
   background; the thinking line shows the latest activity label with a
   shimmer (static with reduced motion) and counts up in seconds from the
   send, and the first streamed text replaces it; the chat is sized to the
   visual viewport and re-pinned on viewport and composer resizes while
   following, never while the person reads back. The old composer's "Any
   project" picker is removed. Browser test at 390 px.

7. Guards observed failing when broken (mutation checks): allowlist,
   ended turn, call-id replay, created-without-authorisation, create
   namespace, card revision, owner-only projects API, read path cleaning,
   visual viewport sizing, no-yank, reduced motion, streaming hides the
   line.

## Read tools: v1 decision (controller, 2026-11-07)

`search_code` and `read_file` run git on the runner's own bare clone,
outside the model's namespace; the model never gets filesystem access.
Accepted for v1 with this hardening (`readGit` in
`internal/runner/thin/index.go`):
- Read-only plumbing only, at one commit resolved per call
  (`rev-parse HEAD^{commit}`): `grep --no-textconv --no-ext-grep`,
  `ls-tree`, `cat-file -t/-s/blob` by object id (no path, so no
  attributes, filters or textconv can apply). No `show`, no checkout.
- Command-line overrides, which outrank the clone's own config:
  `core.hooksPath=/dev/null`, `core.fsmonitor=false`, `diff.external=`,
  `core.attributesFile=/dev/null`, `protocol.allow=never` (no network),
  `credential.helper=`, `core.sshCommand=/bin/false`, auto maintenance
  off. Environment: `GIT_CONFIG_NOSYSTEM=1`, `GIT_CONFIG_GLOBAL=/dev/null`,
  `GIT_TERMINAL_PROMPT=0`, `GIT_NO_LAZY_FETCH=1`, `HOME=/nonexistent`,
  `GIT_DIR` and `GIT_CEILING_DIRECTORIES` pinned to the clone.
- 20 s per command, 1 MiB of output, files over 1 MiB refused, tool
  output clipped to 16 KiB; paths cleaned (no `..`, no leading `-`, no
  `:`); symlinks reported as links and never followed; submodules not read.
- `TestReadToolsHostileRepository`: a repository whose attributes ask for
  filters and textconv, whose clone config sets filter, textconv,
  external diff, fsmonitor, hooks path, pager and `attr.tree=HEAD`, with
  hooks installed and symlinks pointing out of the clone, runs nothing
  and reads nothing outside the clone. Mutations observed failing: grep
  with `--textconv`, a path-addressed `show --textconv`, following
  symlinks. The hook and fsmonitor overrides are defence in depth: read
  plumbing on a bare clone never triggers them, so no test can observe
  them failing.

## Repository creation (Paul's rule 3)

Checked as the runner's agent `equipo-docs-t1~paul@keymail.dev` with its
bearer from the runner's credential file, never printed: `GET
/api/v1/repos` lists 16 writable repositories, all in `oficina`; a
`POST /api/v1/repos` with an invalid name in `oficina` returned 400 on
the name (the hub checks writer rank first), so the agent may create
repositories in `oficina`. Nothing was created. One git password and
one API bearer serve every repository of the agent.

So "Created" works today for Oficina-related work. Unrelated new work
needs a home namespace the agent is granted. Proposed name: `equipo-work`
(Paul creates it and runs `amadan agent grant equipo-docs-t1
equipo-work`; then set `EQUIPO_RUNNER_HOME_NAMESPACE=equipo-work` on the
runner). Until then unrelated new work goes to the best-fitting existing
repository with Change. Created repositories are recorded in the runner's
state directory, never written into the credential file.

## Review round 1 (Astra at b90ac60, REQUEST CHANGES)

Each fix has a test that failed first (or, where the first failure was a
compile error, a mutation observed failing):
1. Tool replays: a repeated call id is answered from the store only for
   the same turn, attempt, tool and arguments (hash), and only after the
   turn is checked again for this primary runner (running, same
   attempt). A stored create authorisation replayed after the turn ended
   gets `turn_ended`; after owner-to-member demotion the runner is no
   longer primary and gets nothing back (`TestToolReplayRevalidates`).
   Migration 0038 adds `attempt` and `args_hash` to `chat_tool_calls`.
2. Repository creation: the runner keeps each create call's progress
   (`creations` in its state); a resent call never creates again, and
   before creating it asks the hub afresh whether the repository exists
   (an earlier answer was lost) and adopts it. `fileForge.Create` also
   re-checks after a failed POST (`TestCreateProjectIsIdempotent`).
3. Answers: the card points at its answer inside `send`, before the
   message can be dispatched, so the coordinator gets the question (or
   the replaced project) with an answer dispatched at once
   (`TestAnswerDispatchCarriesContext`).
4. Page refreshes run one at a time (a request during one runs once
   after it) and a page with an older cursor than the one shown is
   dropped (`TestBrowserRefreshRace`: a slow stale page no longer undoes
   the newer one; either mechanism alone holds, removing both fails).
Minor: a stale revision on an actionable project card (added, working,
created) is `card_stale`; done cards are `card_answered`
(`TestProjectCardStaleRevision`).

Added (Paul): the team setting "New projects go to …" (`chat_settings`
key `project_home`), shown as `home` in `status` and `GET /projects`,
set or cleared by the coordinator's `set_project_home` tool only when the
person asks, only to a namespace in the runner's `create_in`. Unset, the
coordinator uses the best-fitting existing repository with Change (a
local repository with a later "Publish to …" is not built). No namespace
is created. Tests: `TestProjectHomeSetting`, headless `2_project_home`.
The house rule version moved, so sessions restart on the new rule.

Staging after review 1 (release bdbb99c, 14 live turns): the full run
passed scenarios 1, 3, 6, 7, 8 and cancel; `runner_crash` failed in the
test only: the edge answered 502 to both runners for about 4 s at
10:05:39, the suite's event stream dropped, and that session did not
reconnect, while the crashed turn did recover (attempt 2, replied 30 s
after the kill). The slice 1 scenario sessions that do not manage their
own stream now resume from their cursor like a client (test code only).
A second run of `runner_crash`, `2_project`, `2_find` and `2_new_work`
on bdbb99c passed (4 turns). `make staged-check` refuses bdbb99c: the
record needs one uninterrupted full run (about 13 live turns).

## Decisions

- Cards carry fixed fields for every kind (no optional objects) so one
  shape serves the fixtures and native apps. For an access card
  `question` is the name looked for, `options` the namespaces reached and
  `choice` the agent's name.
- Activity labels come from the instance's copy (`chat.activity.*`), so
  native apps get them in the event; the runner sends names only.
- The thin `POST /api/v1/projects` replaces the old project-form API
  (spec §1); the old parity test now creates its project by the form.
- Read tools run git on the runner's own bare clone (objects only: `git
  grep` and `git show` on `HEAD`), not inside the model's namespace; the
  model never gets filesystem access.

## Staging

The suite now runs as its own owner, `suite@equipo-staging.invalid`,
added by the owner's session in `staging-thin.py signin` (no setup for
Paul), with its own runner user unit and state root (both named in the
script, beside the owner's), repository creation off. The owner's runner unit stays running for Paul, with creation on.
Both read the production runner's forge credential file in place.

Rehearsal runs (release b8158bb and before), 16 live turns:
- The first live turn was refused at init: a tool with no required
  input sent `"required": null`; fixed, and refused inits now log tool
  and server names.
- The hub answers 429 to a burst of one agent's git requests: the index
  now waits 4 s between repositories (16 indexed, about a minute hourly).
- All slice 1 scenarios and `2_project` passed live: "Fix the README typo
  in equipo." got "Working in equipo." with an Added card, no question.
- `2_find` live behaved right (one line ending "Grant access", an access
  card, no question) but the test's client missed the reply; the slice 2
  scenarios now resume their stream from the cursor like a real client.
  Activity labels for find, search_code, read_file and create_project
  were missing; added.

Final release 330e534 (built by `make release`, deployed, both runners
installed), real Claude CLI 2.1.312, 30 live turns used in total:
- Release 196e684: all slice 1 scenarios green live (cold 2.76 s, warm
  1.02 s, cold resume 4.52 s in the rehearsal before it); `2_project`
  failed: a resumed session answered "Working in equipo" from memory
  without the `add_project` call, so no card. Fixed in 330e534 (house
  rule version on the session; the rule asks for the call every time).
- Release 330e534, slice 2 scenarios live, all green (3 turns):
  - "Fix the README typo in equipo." -> "Working in equipo" card (fresh
    session under the new rule), no question.
  - "In Woodstar, the panes aren't slideable ..." -> "Woodstar isn't in
    any of the repositories I can reach, which are all in oficina. Grant
    access", one access card, no framework question.
  - "Build a small website that introduces the Oficina suite." -> "I'm
    working in suite. I can't create new repositories here, so I picked
    suite because it's the shared repository for the whole Oficina
    suite." with an Added card (the suite runner has creation off).
- `make staged-check` refuses 330e534: the staged record needs one full
  suite run on that release (about 14 live turns), which the 30-turn
  budget did not leave room for.

Where a turn's time went (real CLI). Instance and runner each measure on
their own clock; the client measures from its POST.
- Fresh session, cold process ("Fix the README typo", 330e534): client
  commit 42 ms; queued (commit to runner ack) 35 ms; runner receipt to
  stdin 2.1 s (process start, refresh and staging of the copy, lease);
  first stream event 0.8 s; thinking 1.5 s; first tool 2.0 s; first
  text 5.2 s; result 5.2 s. The client saw the first activity line at
  3.7 s and the first text at 7.4 s.
- Warm process: queued 34 to 65 ms; runner to stdin 0.2 s (lease round
  trip through the edge and copy check); first event under 10 ms;
  thinking 0.6 s; find 0.7 s; first text 1.6 to 4.1 s depending on tools.
- Last text to committed message: under 30 ms on the runner every time.
Where a turn's time went (rehearsal, real CLI, warm process):
- "Fix the README typo in equipo": message commit to runner ack 55 ms,
  runner receipt to stdin 219 ms (lease round trip and copy check),
  first stream event 8 ms, thinking 622 ms, first tool 1.3 s, first text
  7.0 s (the model read files first), result 7.0 s.
- "In Woodstar ...": queued 58 ms, start 216 ms, first tool (find)
  0.7 s, first text 2.3 s.
- A turn right after a runner restart: start 6.4 s (process start,
  refresh and resume), first text 1.4 s after stdin.
Non-model delay found and fixed: the copy rotation before most turns
(slice 1 cold 2.7 to 3.5 s against warm 0.9 s); the runner now rotates in
the background within the idle window (`TestHeadlessPrewarm`).

## Open issues

- Staged record: one full staging suite run on the final release is
  needed before `make staged-check` passes (about 14 live turns).
- Paul's staging runner may create repositories in `oficina` for real
  (it has creation on, as asked). The suite runner does not.
- Both staging runners read the production runner's forge credential
  file in place and index all 16 `oficina` repositories hourly, paced at
  4 s; the hub's rate limit is shared with the production runner.
- Home namespace for unrelated new work: not granted yet (proposal
  `equipo-work`, above).
- Unreachable names: the access card cannot say where a name lives
  (the agent sees only granted namespaces); it shows the grant command
  with a namespace placeholder.

## Blockers

None.
