Lift the factory TUI out of idss into the vendored harness (identity-sourced, no product paths) #29

Closed
opened 2026-08-23 03:34:54 +00:00 by ben · 1 comment
Owner

Problem

The factory TUI (idss #573 → #607/#611/#612/#613/#614/#615/#617/#618, closed 2026-08-20) is the only visual monitor of the factory, and it lives in one consumer's per-repo layer — Matou/idss at .sandcastle/tui/ (Python + Textual, ~3.8k lines incl. tests). It is not in onboarding/vendor-manifest, so matou-app and this repo's own swarm get no monitor, and an operator watching the pool has to read Forgejo /actions/tasks and the Mattermost channel by hand.

The code is factory-shaped — every tab reads state the harness here writes (swarm.db, cancel markers, limit markers, drive-status JSON, the healer ledger, tracker labels, ask-human.sh threads) — but it carries idss-specific defaults that violate CLAUDE.md's "no repo names, hosts, or product-specific paths in harness files" rule:

  • data/tracker.py:16, data/ask_inbox.py:26 — DEFAULT_API = "https://git.matou.nz/api/v1/repos/Matou/idss"
  • data/healer_ledger.py:26 — ~/swarm/Matou/idss/.sandcastle/.state/healer/
  • data/limits.py:9-10 — /tmp/matou-swarm-claude-{limit,active-token}
  • data/drive_status.py:33 — /tmp/matou-<tag>-rehearsal-drive-status.json
  • data/rearm.py — dispatches swarm.yml by name
  • data/worker_classes.py — reads idss's docs/agents/worker-classes.json

Proposal

Lift tui/ into this repo as a vendored directory (tui/ at root, listed in onboarding/vendor-manifest), with every per-repo value sourced from the consumer's identity layer instead of defaulted:

  1. Identity, not defaults. A small tui/data/identity.py that shells swarm-identity.sh (or reads the env it exports) for: Forgejo API base + owner/repo, healer state dir, limit/active marker paths, drive-status path, workflow file name. No product string anywhere under tui/.
  2. Worker-class table moves with it. docs/agents/worker-classes.json is factory data (the 13 classes are the harness's, not idss's); move it here and let the Fleet tab read the vendored copy. Per-repo rows (the matou-app check-verifications class) become an identity-layer enrichment.
  3. Multi-consumer Monitor. The one-host assumption (local swarm.db) stays for v1 — note in the README that the TUI runs on a swarm host and shows that host's db. A fleet-wide view (reading every enrolled host's db, #3/#6 host registry) is a follow-up, not this ticket.
  4. Tests come along — the suite already shells out to the real swarm-db.py for schema fidelity, which is exactly the posture this repo's offline tests take. Drop into tests/ as offline pytest; requirements.txt stays TUI-scoped.
  5. Onboarding — onboard.sh vendor carries it; the README "Run it" block moves into onboarding/README.md as the operator entry point.
  6. idss side — once pinned, idss deletes its .sandcastle/tui/ copy on its next re-vendor (pull-only; link from idss, don't push).

Acceptance

  • grep -rE 'idss|matou|git\.matou' tui/ returns only test fixtures.
  • Offline suite green from this repo; onboard.sh vendor drift check passes for a consumer carrying tui/.
  • FORGEJO_TOKEN=… python tui/app.py on matou-workstation from the dev-factory self-copy shows this repo's own queue, not idss's.

Out of scope

Fleet-wide multi-host reads, the README-admitted UI-thread-blocking fetches, label-cache invalidation — ticket separately if wanted.

Refs: idss #573 (design + slices), #574 (data layer), ADR 0186 (cancel); survey docs/research/2026-08-15-factory-reengineering-survey.md §5; STATUS.md "Factory tickets living elsewhere".

## Problem The factory TUI (idss #573 → #607/#611/#612/#613/#614/#615/#617/#618, closed 2026-08-20) is the only visual monitor of the factory, and it lives in **one consumer's per-repo layer** — `Matou/idss` at `.sandcastle/tui/` (Python + Textual, ~3.8k lines incl. tests). It is not in `onboarding/vendor-manifest`, so `matou-app` and this repo's own swarm get no monitor, and an operator watching the pool has to read Forgejo `/actions/tasks` and the Mattermost channel by hand. The code is factory-shaped — every tab reads state the harness here writes (`swarm.db`, cancel markers, limit markers, drive-status JSON, the healer ledger, tracker labels, `ask-human.sh` threads) — but it carries idss-specific defaults that violate CLAUDE.md's "no repo names, hosts, or product-specific paths in harness files" rule: - `data/tracker.py:16`, `data/ask_inbox.py:26` — `DEFAULT_API = "https://git.matou.nz/api/v1/repos/Matou/idss"` - `data/healer_ledger.py:26` — `~/swarm/Matou/idss/.sandcastle/.state/healer/` - `data/limits.py:9-10` — `/tmp/matou-swarm-claude-{limit,active-token}` - `data/drive_status.py:33` — `/tmp/matou-<tag>-rehearsal-drive-status.json` - `data/rearm.py` — dispatches `swarm.yml` by name - `data/worker_classes.py` — reads idss's `docs/agents/worker-classes.json` ## Proposal Lift `tui/` into this repo as a vendored directory (`tui/` at root, listed in `onboarding/vendor-manifest`), with every per-repo value sourced from the consumer's identity layer instead of defaulted: 1. **Identity, not defaults.** A small `tui/data/identity.py` that shells `swarm-identity.sh` (or reads the env it exports) for: Forgejo API base + owner/repo, healer state dir, limit/active marker paths, drive-status path, workflow file name. No product string anywhere under `tui/`. 2. **Worker-class table moves with it.** `docs/agents/worker-classes.json` is factory data (the 13 classes are the harness's, not idss's); move it here and let the Fleet tab read the vendored copy. Per-repo rows (the `matou-app` check-verifications class) become an identity-layer enrichment. 3. **Multi-consumer Monitor.** The one-host assumption (local `swarm.db`) stays for v1 — note in the README that the TUI runs on a swarm host and shows that host's db. A fleet-wide view (reading every enrolled host's db, #3/#6 host registry) is a follow-up, not this ticket. 4. **Tests come along** — the suite already shells out to the real `swarm-db.py` for schema fidelity, which is exactly the posture this repo's offline tests take. Drop into `tests/` as offline pytest; `requirements.txt` stays TUI-scoped. 5. **Onboarding** — `onboard.sh vendor` carries it; the README "Run it" block moves into `onboarding/README.md` as the operator entry point. 6. **idss side** — once pinned, idss deletes its `.sandcastle/tui/` copy on its next re-vendor (pull-only; link from idss, don't push). ## Acceptance - `grep -rE 'idss|matou|git\.matou' tui/` returns only test fixtures. - Offline suite green from this repo; `onboard.sh vendor` drift check passes for a consumer carrying `tui/`. - `FORGEJO_TOKEN=… python tui/app.py` on matou-workstation from the **dev-factory** self-copy shows this repo's own queue, not idss's. ## Out of scope Fleet-wide multi-host reads, the README-admitted UI-thread-blocking fetches, label-cache invalidation — ticket separately if wanted. Refs: idss #573 (design + slices), #574 (data layer), ADR 0186 (cancel); survey `docs/research/2026-08-15-factory-reengineering-survey.md` §5; STATUS.md "Factory tickets living elsewhere".

Close report — landed

Ruled by agent under ADR 0174 — veto anytime. Every change is a commit plus an offline test (two-way doors); no credential, no security-posture change, no destructive step. The one human residue is the pin bump itself (GOTCHAS 4), which is not this ticket's job.

Commits: 25fc9c9 (the lift), 4e04e62 (STATUS pointers). Root-only — a human re-vendor carries tui/** to .sandcastle/.

Acceptance, as written

criterion result
grep -rE 'idss|matou|git\.matou' tui/ returns only test fixtures Returns NOTHING. The fixtures were scrubbed too (Owner/repo, host-a/host-b, forge.example.invalid), so the ratchet is absolute rather than "only in tests" — a stronger condition than asked, and one a grep can enforce forever
Offline suite green from this repo ✅ 66 files (62 vendored tests/ + 4 onboarding/tests/), including new tests/tui-test.sh. The Python suite is 157 cases across 14 files
onboard.sh vendor drift check passes for a consumer carrying tui/ ✅ vendor-manifest gains tui/**; vendor-manifest-coverage-test.sh passes (every tracked path classified exactly once), and onboard_expand_manifest's git ls-files + mkdir -p handle the nested tui/data/, tui/tests/ without change. Proven in the vendored SHAPE below rather than by mutating the live self-copy, which only a human pin bump may touch
FORGEJO_TOKEN=… python tui/app.py from dev-factory shows this repo's queue ✅ run headless (Textual's own pilot, the same harness its tests use) with no injection at all — see the transcript below

The live run, from this checkout

resolved identity layer:
  harness_dir            /home/dev/session-runner/dev-factory
  forgejo_api            https://git.matou.nz/api/v1/repos/Matou/dev-factory
  repo_slug              Matou/dev-factory
  healer_state           /home/dev/swarm/Matou/dev-factory/.sandcastle/.state/healer
  limit_marker           /tmp/matou-swarm-claude-limit
  cancel_dir             /home/dev/swarm/state/cancel-request
  swarm_db               /home/dev/swarm/state/swarm.db
  drive_status_file      None
sub_title: 'Matou/dev-factory'
queue rows: 7
   40 | Forgejo run retention on git.matou.nz — the /actions | ready-for-human
   37 | The host env file is product-flavoured; the factory' | ready-for-session
   33 | session-runner-prompt.md / .sandcastle prompt-enrich | ready-for-session
   32 | session: add the #26 per-repo concurrency group to t | ready-for-session
   29 | Lift the factory TUI out of idss into the vendored h | in-progress
   17 | The harness assumes a pnpm repo — a bash-only consum | deferred
    6 | onboard-host: host registry + idempotent machine enr | ready-for-human
drive panel: Drive: no DRIVE_STATUS_FILE declared by this repo's identity layer
limit panel: Claude: not parked — account B
runs rows: 20 | fleet rows: 9 | incidents rows: 1 | inbox rows: 2

That is this repo's own queue (#29 itself showing in-progress), its own healer ledger, and the shared host swarm.db — not idss's.

Second proof, the layout consumers actually get: the same tui/ dropped into a scratch .sandcastle/ beside the live self-copy's REAL vendored libs (copied out read-only — the running copy is untouched) resolved identically (Matou/dev-factory, its healer dir, the shared db). Third: tests/tui-test.sh run standalone from that scratch copy passed its structural checks and printed its loud skip — #23's rule that a vendored test may not reach outside the harness dir.

How each proposal point landed

1. Identity, not defaults. New tui/data/identity.py is the single seam. It does not re-derive the harness's defaults in Python — it SOURCES the sibling files that own them (swarm-identity.sh → FORGEJO_API/REPO_SLUG/HEAL_WORKDIR/RUNNER_HOST; limit-lib.sh → both markers; cancel-lib.sh → SWARM_CANCEL_DIR; swarm-db-lib.sh → SWARM_DB), so the monitor cannot drift from the scripts it monitors, and because every one of those is a ${VAR:-default} assignment the process env keeps its usual precedence for free. Two values have no sourceable owner and are mirrored with their source named beside them: HEALER_STATE (heal.sh is an entry point — sourcing it would RUN the healer) and the bind-mounted chat secret (ask-human.sh). Every data/ reader then takes its path/URL as a plain argument; not one keeps a default it could silently fall back to.

A ruling the ticket did not anticipate — unresolved values are STATED, never guessed. The drive-status record is written by a consumer's own rehearsal machinery; the harness writes no such file, so the factory has no default to offer. Rather than inventing one, DRIVE_STATUS_FILE is an optional identity declaration and the panel says so when it is absent (visible in the transcript above). Same posture across the app: the Queue/Inbox tabs name the missing variable and the onboard.sh identity command that fixes it, and Cancel refuses rather than writing a marker into an invented dir that nothing polls.

2. Worker-class table. Moved as tui/worker-classes.json — beside its reader, not docs/agents/: docs/** is vendor-excluded, so a manifest entry there would be classified twice and fail vendor-manifest-coverage-test.sh. It carries the NINE classes whose code lives in this repo. The other four are not factory data and did not come: rehearsal-executor, rehearsal-cycle, clan-lab-reap are idss's own (scripts/, .claude/) and check-verifications is matou-app's — exactly the "per-repo rows become an enrichment" the ticket asked for, applied to hosts as well, since hosts and /tmp/... lock literals are per-deployment facts that would be wrong in every other consumer. Consumers declare both in worker-classes.local.json beside their swarm-identity.sh, merged by id (known id → field-wise override, so declaring hosts keeps the vendored description; new id → appended). Lock/marker paths in the table now name the LIB that owns them instead of repeating literals, for the same anti-drift reason.

3. Multi-consumer Monitor. One host, one repo for v1, as ruled — stated up front in tui/README.md and again in onboarding/README.md, with the fleet-wide read named as a follow-up. The header's subtitle is the resolved repo slug, so which factory you are looking at is never a guess.

4. Tests came along — with one deliberate deviation. They live at tui/tests/ (14 files, 157 cases: 143 ported plus new coverage for identity resolution, the overlay merge, and the no-identity-layer degradation), not dropped into the root tests/ as the ticket suggested. That directory is a bash suite driven by for t in tests/*.sh, which would never execute a test_*.py, and pytest needs the package layout tui/ already has. Instead new tests/tui-test.sh is the bridge: it runs the pytest suite when a venv or system pytest exists, skips loudly when neither does (a silent skip would read as coverage that isn't there), and always enforces four structural conditions — no product literal under tui/, no hardcoded forge host, no data/ reader defaulting a host path, and a vendored table declaring no hosts. Each was proven to RED against the exact regression it exists to catch, then green again. requirements.txt stays TUI-scoped; the venv is gitignored.

A real bug surfaced while porting. Two of the ported tests FAILED on this host: the app read the session's live MATTERMOST_URL/CHANNEL_ID/BOT_TOKEN when the test injected none, so an "offline" test's behaviour depended on the host's environment (with those unset the suite was 143/143 green — the failure was purely the leak). tests/test_app.py now injects a whole synthetic Identity, so nothing about the running host can reach an assertion.

5. Onboarding. onboarding/README.md gains "Watching a factory — the TUI": the venv+run block, which credential each tab needs and which tabs work without any, and the two per-repo declarations (DRIVE_STATUS_FILE, the overlay). tui/README.md is rewritten — resolution table, tab-by-tab keys and write paths, scope, and the three known gaps kept honest.

6. idss side. Filed as Matou/idss#715 (link, not push — ADR 0001): at its pin bump the vendored copy supersedes .sandcastle/tui/ byte-for-byte (every file it carries is in the new manifest, so nothing is left half-old), plus the DRIVE_STATUS_FILE and overlay it should declare to keep its drive and Fleet panels whole. Matou/matou-app#80 is the same link for the repo that gets a monitor for the first time.

Out of scope, untouched (as ruled)

Fleet-wide multi-host reads, the UI-thread-blocking fetches, and label-cache invalidation — all three are recorded as known gaps in tui/README.md rather than quietly dropped. Not ticketed here; ticket them if wanted.

Not proven, stated plainly

The vendored .sandcastle/tui/ on this host is proven by SHAPE (a scratch copy against the real vendored libs), not by mutating the live self-copy — a root change reaches it only when a human runs onboard.sh vendor .sandcastle <sha> (GOTCHAS 4). The consumer-side acceptance in idss/matou-app likewise waits on their pin bumps.

## Close report — landed **Ruled by agent under ADR 0174 — veto anytime.** Every change is a commit plus an offline test (two-way doors); no credential, no security-posture change, no destructive step. The one human residue is the pin bump itself (GOTCHAS 4), which is not this ticket's job. Commits: `25fc9c9` (the lift), `4e04e62` (STATUS pointers). Root-only — a human re-vendor carries `tui/**` to `.sandcastle/`. ### Acceptance, as written | criterion | result | | --- | --- | | `grep -rE 'idss\|matou\|git\.matou' tui/` returns only test fixtures | **Returns NOTHING.** The fixtures were scrubbed too (`Owner/repo`, `host-a`/`host-b`, `forge.example.invalid`), so the ratchet is absolute rather than "only in tests" — a stronger condition than asked, and one a grep can enforce forever | | Offline suite green from this repo | ✅ 66 files (62 vendored `tests/` + 4 `onboarding/tests/`), including new `tests/tui-test.sh`. The Python suite is 157 cases across 14 files | | `onboard.sh vendor` drift check passes for a consumer carrying `tui/` | ✅ `vendor-manifest` gains `tui/**`; `vendor-manifest-coverage-test.sh` passes (every tracked path classified exactly once), and `onboard_expand_manifest`'s `git ls-files` + `mkdir -p` handle the nested `tui/data/`, `tui/tests/` without change. Proven in the vendored SHAPE below rather than by mutating the live self-copy, which only a human pin bump may touch | | `FORGEJO_TOKEN=… python tui/app.py` from dev-factory shows **this** repo's queue | ✅ run headless (Textual's own pilot, the same harness its tests use) with no injection at all — see the transcript below | ### The live run, from this checkout ``` resolved identity layer: harness_dir /home/dev/session-runner/dev-factory forgejo_api https://git.matou.nz/api/v1/repos/Matou/dev-factory repo_slug Matou/dev-factory healer_state /home/dev/swarm/Matou/dev-factory/.sandcastle/.state/healer limit_marker /tmp/matou-swarm-claude-limit cancel_dir /home/dev/swarm/state/cancel-request swarm_db /home/dev/swarm/state/swarm.db drive_status_file None sub_title: 'Matou/dev-factory' queue rows: 7 40 | Forgejo run retention on git.matou.nz — the /actions | ready-for-human 37 | The host env file is product-flavoured; the factory' | ready-for-session 33 | session-runner-prompt.md / .sandcastle prompt-enrich | ready-for-session 32 | session: add the #26 per-repo concurrency group to t | ready-for-session 29 | Lift the factory TUI out of idss into the vendored h | in-progress 17 | The harness assumes a pnpm repo — a bash-only consum | deferred 6 | onboard-host: host registry + idempotent machine enr | ready-for-human drive panel: Drive: no DRIVE_STATUS_FILE declared by this repo's identity layer limit panel: Claude: not parked — account B runs rows: 20 | fleet rows: 9 | incidents rows: 1 | inbox rows: 2 ``` That is this repo's own queue (#29 itself showing `in-progress`), its own healer ledger, and the shared host `swarm.db` — not idss's. **Second proof, the layout consumers actually get:** the same `tui/` dropped into a scratch `.sandcastle/` beside the live self-copy's REAL vendored libs (copied out read-only — the running copy is untouched) resolved identically (`Matou/dev-factory`, its healer dir, the shared db). **Third:** `tests/tui-test.sh` run standalone from that scratch copy passed its structural checks and printed its loud skip — #23's rule that a vendored test may not reach outside the harness dir. ### How each proposal point landed **1. Identity, not defaults.** New `tui/data/identity.py` is the single seam. It does not re-derive the harness's defaults in Python — it SOURCES the sibling files that own them (`swarm-identity.sh` → `FORGEJO_API`/`REPO_SLUG`/`HEAL_WORKDIR`/`RUNNER_HOST`; `limit-lib.sh` → both markers; `cancel-lib.sh` → `SWARM_CANCEL_DIR`; `swarm-db-lib.sh` → `SWARM_DB`), so the monitor cannot drift from the scripts it monitors, and because every one of those is a `${VAR:-default}` assignment the process env keeps its usual precedence for free. Two values have no sourceable owner and are mirrored with their source named beside them: `HEALER_STATE` (heal.sh is an entry point — sourcing it would RUN the healer) and the bind-mounted chat secret (ask-human.sh). Every `data/` reader then takes its path/URL as a plain argument; not one keeps a default it could silently fall back to. **A ruling the ticket did not anticipate — unresolved values are STATED, never guessed.** The drive-status record is written by a consumer's own rehearsal machinery; the harness writes no such file, so the factory has *no* default to offer. Rather than inventing one, `DRIVE_STATUS_FILE` is an optional identity declaration and the panel says so when it is absent (visible in the transcript above). Same posture across the app: the Queue/Inbox tabs name the missing variable *and* the `onboard.sh identity` command that fixes it, and Cancel **refuses** rather than writing a marker into an invented dir that nothing polls. **2. Worker-class table.** Moved as `tui/worker-classes.json` — beside its reader, **not** `docs/agents/`: `docs/**` is vendor-excluded, so a manifest entry there would be classified twice and fail `vendor-manifest-coverage-test.sh`. It carries the NINE classes whose code lives in this repo. The other four are not factory data and did not come: `rehearsal-executor`, `rehearsal-cycle`, `clan-lab-reap` are idss's own (`scripts/`, `.claude/`) and `check-verifications` is matou-app's — exactly the "per-repo rows become an enrichment" the ticket asked for, applied to hosts as well, since `hosts` and `/tmp/...` lock literals are per-deployment facts that would be wrong in every other consumer. Consumers declare both in `worker-classes.local.json` beside their `swarm-identity.sh`, merged by `id` (known id → field-wise override, so declaring `hosts` keeps the vendored description; new id → appended). Lock/marker paths in the table now name the LIB that owns them instead of repeating literals, for the same anti-drift reason. **3. Multi-consumer Monitor.** One host, one repo for v1, as ruled — stated up front in `tui/README.md` and again in `onboarding/README.md`, with the fleet-wide read named as a follow-up. The header's subtitle is the resolved repo slug, so which factory you are looking at is never a guess. **4. Tests came along — with one deliberate deviation.** They live at `tui/tests/` (14 files, 157 cases: 143 ported plus new coverage for identity resolution, the overlay merge, and the no-identity-layer degradation), **not** dropped into the root `tests/` as the ticket suggested. That directory is a *bash* suite driven by `for t in tests/*.sh`, which would never execute a `test_*.py`, and pytest needs the package layout `tui/` already has. Instead new `tests/tui-test.sh` is the bridge: it runs the pytest suite when a venv or system pytest exists, **skips loudly** when neither does (a silent skip would read as coverage that isn't there), and always enforces four structural conditions — no product literal under `tui/`, no hardcoded forge host, no `data/` reader defaulting a host path, and a vendored table declaring no hosts. Each was proven to RED against the exact regression it exists to catch, then green again. `requirements.txt` stays TUI-scoped; the venv is gitignored. **A real bug surfaced while porting.** Two of the ported tests FAILED on this host: the app read the session's live `MATTERMOST_URL`/`CHANNEL_ID`/`BOT_TOKEN` when the test injected none, so an "offline" test's behaviour depended on the host's environment (with those unset the suite was 143/143 green — the failure was purely the leak). `tests/test_app.py` now injects a whole synthetic `Identity`, so nothing about the running host can reach an assertion. **5. Onboarding.** `onboarding/README.md` gains "Watching a factory — the TUI": the venv+run block, which credential each tab needs and which tabs work without any, and the two per-repo declarations (`DRIVE_STATUS_FILE`, the overlay). `tui/README.md` is rewritten — resolution table, tab-by-tab keys and write paths, scope, and the three known gaps kept honest. **6. idss side.** Filed as `Matou/idss#715` (link, not push — ADR 0001): at its pin bump the vendored copy supersedes `.sandcastle/tui/` byte-for-byte (every file it carries is in the new manifest, so nothing is left half-old), plus the `DRIVE_STATUS_FILE` and overlay it should declare to keep its drive and Fleet panels whole. `Matou/matou-app#80` is the same link for the repo that gets a monitor for the first time. ### Out of scope, untouched (as ruled) Fleet-wide multi-host reads, the UI-thread-blocking fetches, and label-cache invalidation — all three are recorded as known gaps in `tui/README.md` rather than quietly dropped. Not ticketed here; ticket them if wanted. ### Not proven, stated plainly The vendored `.sandcastle/tui/` on this host is proven by SHAPE (a scratch copy against the real vendored libs), not by mutating the live self-copy — a root change reaches it only when a human runs `onboard.sh vendor .sandcastle <sha>` (GOTCHAS 4). The consumer-side acceptance in idss/matou-app likewise waits on their pin bumps.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#29
No description provided.