Maintainability pass: clip consolidation, workflow steps/tools split, chat-session decomposition + 0048 draft #123

Merged
chad merged 6 commits from glen/refactor-maintainability into main 2026-10-17 23:05:36 -04:00
Collaborator

Maintenance refactor from the architecture review — four mechanical commits, a fresh-eyes review, and a draft design doc. Zero behavior change: the review child verified every moved function byte-identical and probed the tool key set across all gate combinations empirically; full suite 777 passed throughout.

The commits

  1. lib/clip.ts — seven hand-rolled text-clip helpers consolidated into four shared shapes (clipEnds/clipHead/clipTail/clipLines). gh/forgejo/web_fetch markers unified onto the informative … [N chars clipped] convention (3 test assertions follow). Three justified locals stay: wake's pointer-aware clipText, harness-events' unknown→JSON value clip, child-status's null-passthrough.

  2. workflows/chat/steps/ — the 646-line steps.ts (42 "use step" functions) split by domain into 7 files + index re-export; importers keep from "./steps". Every function keeps its directive and lazy imports (paths ../../→../../../).

  3. workflows/chat/tools/ — the 540-line tools.ts split into per-domain factories; buildChatTools signature and gating unchanged; key sets verified identical.

  4. components/chat-cards/ — chat-session.tsx 1,584→725 lines: approval cards, tool dispatch, and ChatMessageView extracted verbatim. Adding a tool card now touches a 135-line dispatch file, not a 1,600-line session.

  5. docs/0048-machines-retirement.md (DRAFT — needs your approval before any implementation). Maps the machine-era read residue exhaustively and frames the real decision: A) keep /r/ rendering, delete only the dead "is it live?" semantics (~150 lines, zero risk) vs B) backfill run transcripts and delete the run view entirely (~zero residue, needs a migration). The review caught my first draft's wrong premise (run rows carry no transcript per 0012) — corrected.

Review findings addressed: the doc's residue list completed (redirect, hrefFor, glyph, sandboxes lease arm, reaper's second read, previews' read, the project-delete write), nonexistent identifiers fixed, and three code nits (web.ts marker, unused ToolContext, alias placement).

The 0048 implementation itself is deliberately NOT in this PR — it follows separately once you pick A or B.

Maintenance refactor from the architecture review — four mechanical commits, a fresh-eyes review, and a draft design doc. **Zero behavior change**: the review child verified every moved function byte-identical and probed the tool key set across all gate combinations empirically; full suite 777 passed throughout. ## The commits 1. **`lib/clip.ts`** — seven hand-rolled text-clip helpers consolidated into four shared shapes (`clipEnds`/`clipHead`/`clipTail`/`clipLines`). gh/forgejo/web_fetch markers unified onto the informative `… [N chars clipped]` convention (3 test assertions follow). Three justified locals stay: wake's pointer-aware `clipText`, harness-events' unknown→JSON value clip, child-status's null-passthrough. 2. **`workflows/chat/steps/`** — the 646-line steps.ts (42 `"use step"` functions) split by domain into 7 files + index re-export; importers keep `from "./steps"`. Every function keeps its directive and lazy imports (paths `../../`→`../../../`). 3. **`workflows/chat/tools/`** — the 540-line tools.ts split into per-domain factories; `buildChatTools` signature and gating unchanged; key sets verified identical. 4. **`components/chat-cards/`** — chat-session.tsx 1,584→725 lines: approval cards, tool dispatch, and `ChatMessageView` extracted verbatim. Adding a tool card now touches a 135-line dispatch file, not a 1,600-line session. 5. **`docs/0048-machines-retirement.md`** (DRAFT — needs your approval before any implementation). Maps the machine-era read residue exhaustively and frames the real decision: **A)** keep `/r/` rendering, delete only the dead "is it live?" semantics (~150 lines, zero risk) vs **B)** backfill run transcripts and delete the run view entirely (~zero residue, needs a migration). The review caught my first draft's wrong premise (run rows carry no transcript per 0012) — corrected. Review findings addressed: the doc's residue list completed (redirect, hrefFor, glyph, sandboxes lease arm, reaper's second read, previews' read, the project-delete write), nonexistent identifiers fixed, and three code nits (web.ts marker, unused `ToolContext`, alias placement). The 0048 implementation itself is deliberately NOT in this PR — it follows separately once you pick A or B.
lib/clip.ts carries the four shapes every call site used: clipEnds
(head+tail, command output), clipHead (API responses/messages/snippets),
clipTail (preview logs), clipLines (summaries). gh/forgejo's sparser
'[clipped at N characters]' marker unifies onto the informative
'… [N chars clipped]' convention (two test assertions follow). Three
justified locals stay: wake's pointer-aware clipText, harness-events'
unknown→JSON value clip, child-status's null-passthrough.
workflows/chat/steps/{turn,sandbox,web,projects,children,plan,hosts}.ts,
each function keeping its "use step" directive and lazy Node imports
(paths rewritten ../../ -> ../../../); steps/index.ts re-exports the
union so the four importers (turn body, tools, plan-tools, model) keep
their './steps' paths unchanged. persistTurn's private textOf helper
moves with it; the floating maybeTitleStep doc comment is reunited with
its function. No behavior change — the full suite passes unchanged.
workflows/chat/tools/{core,children,web,hosts,projects,sandbox}.ts each
build one group via a small factory (closing over conversationId and the
same hasSandbox/hasProject/hosts gates); tools/index.ts keeps
buildChatTools with its exact signature and doc, spreading the groups.
shared.ts holds the ToolContext type and the shared commandDescription
zod schema. Tool key set verified identical to the single-file original;
hostTools keeps the hasProject gate (a test pins it).
components/chat-cards/{approvals,dispatch,message-view}.tsx hold the
approval-gated cards (create_pr evidence, ask_chad, accept_plan, exec,
project gates, the PR card), the agent-tool dispatch switch + generic
fallback, and ChatMessageView with its chips/copy/images helpers —
moved verbatim, imported back, ChatMessageView re-exported so
chat.tsx / agent-panel.tsx are untouched. Adding a tool card now means
touching dispatch.tsx (135 lines), not a 1,600-line session file.
Draft, not yet approved. 0037 phase 5 deleted the write paths; the
reads remain spread over attention/organize/child-status/reaper/inspect
plus /r/[runId] and db/machines.ts. The doc maps the residue, frames
the one real decision (freeze rendering + delete machinery, keeping the
historical rows, vs keeping the read paths), and proposes option A with
a sequenced plan.
docs(0048): correct the draft — full residue map, honest option framing
All checks were successful
deploy / checks (pull_request) Successful in 40s
deploy / deploy (pull_request) Has been skipped
c956a5a9d2
Fresh-eyes review caught four should-fixes: the residue list missed the
/r redirect, hrefFor's run arm, sidebar glyph, sandboxes lease arm,
reaper's second machineRuns read, and previews' read; option A's
'runs already render as chats' premise was wrong (0012: run rows carry
no transcript — the words live in stage conversations); runWhere /
NeedsYouThread.kind claims named nonexistent identifiers; and one live
WRITE remains (project-delete nulls machine_runs.sandbox columns).
Rewritten: exhaustive residue, A (keep rendering, delete dead
semantics) vs B (backfill transcript, delete the run view) framed as
Chad's call.

Code nits from the same review also fixed: web_fetch's inline clip
marker now uses clipHead (one marker convention), tools/shared.ts drops
the unused ToolContext export, bash.ts's clipOutput alias moves below
the import block.
chad merged commit 9a5246a7fb into main 2026-10-17 23:05:36 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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
chad/sweatshop-legacy!123
No description provided.