Skip to content

Write the rewrite execution plan #183

Closed

Description

@omridevk

Question

Write the rewrite execution plan (superpowers:writing-plans → docs/superpowers/plans/): from the closed design — no new packages (send folds into library + core verdict/runId + ui-kit-chat composer + thin app dialog), wire deltas (runId-stamped lifecycle, force in per-call data, verdict sole authority), delete/rework list from the salvage inventory, frozen test suite as acceptance. Blocked by: truth table, salvage inventory, base-branch ruling.

Activity

  1. omridevk commented on Aug 2, 2026

    @omridevk
    ContributorAuthor

    Chat-Stack Clean-Room Rewrite — Execution Plan

    For agentic workers: REQUIRED SUB-SKILL: superpowers:subagent-driven-development or superpowers:executing-plans, task-by-task. Steps use checkbox syntax.

    Goal: Rebuild the chat stack on the platform (tanstack ai native, CLI semantics) with core purified of external-terminal vocabulary, the external-terminal domain rewritten from scratch inside the terminal extension, and the frozen behavior suite green.

    Architecture: Fork from main; whitelist-import the salvaged 679 files from archive/connected-external-terminal; rewrite the condemned areas fresh. Core = pure tanstack chat (runId-stamped lifecycle, no verdicts/force/epochs/queues). Terminal extension = adopt/connect/presence/mirroring, rewritten. packages/client = new ~100 LoC subscribe connection. App = thin views.

    Tech stack: @tanstack/ai 0.42.x line (upgrade from 0.41/0.2.2 adapters — delta is one fan-out-cap feature, verified), Solid, Ark, oRPC, vitest browser.

    Global constraints

    • Banned identifiers anywhere in new code: bridge, pipeline, maintenance, manager, sendWhenAvailable, holdAndFlush, veto, epoch, snapshotKey, externalRev, forceSend; adapter only when implementing a library-defined adapter interface. Enforced by a grep gate (Task 12).
    • Banned mechanisms: queues/buffers for sends, polling where push exists, callback registries where one function serves, client re-derivation of server truth.
    • Core source must contain zero external-terminal vocabulary (adopt, attach, candidate, presence, terminal): grep-gated same task.
    • Platform ladder P0: every mechanism names its level; level-3 needs a one-sentence gap justification in the PR description.
    • Repo style: functions only, no comments, strict TS, oxfmt. All gates: typecheck, build, test, fallow, lint.
    • Tests are the acceptance suite: never edited to pass, except the ruled dispositions (deleted flagged list; rehomed adopt tests — imports/mount only, assertions untouched).

    Task 1: Branch + whitelist import

    Files: new branch chat-rewrite from main.

    • Generate the import list: git diff --name-only main...archive/connected-external-terminal minus the DELETE 5, minus the REWORK 18, minus the 19 deleted flagged tests, minus docs/assets/pr-176/**.
    • git checkout archive/connected-external-terminal -- <list> in path batches; single commit feat: import salvaged work from connected-external-terminal.
    • pnpm install && pnpm typecheck — EXPECTED RED (missing REWORK files); record the error list; it is the worklist cross-check for Tasks 2-9.
    • Commit.

    Task 2: tanstack 0.42 upgrade

    Files: root + package manifests, lockfile.

    • Bump @tanstack/ai 0.42.0, ai-client 0.22.1, ai-solid 0.15.1, ai-sandbox 0.2.4, adapters 0.2.3.
    • pnpm install; typecheck delta must show no new errors beyond Task 1's list. Commit.

    Task 3: Wire contract (contract + protocol)

    Files: packages/contract/src/contract.ts, packages/protocol/src/chat-types.ts, packages/protocol/src/harness-types.ts (import; already good).

    • chat.send input: {sessionId, runId: string, messages...} — no force. Output {ok, runId} echo.
    • Remove: SEND_BLOCK_CODES/SEND_CONFIRM_CODES/SendBlockedSchema/SendConfirmSchema/SendVerdict, EXTERNAL_BLOCKED/EXTERNAL_CONFIRM error entries.
    • Lifecycle events on the attach stream each carry runId (client's for widget runs, server-minted for external). No snapshotKey/externalRev fields anywhere.
    • Keep (import from archive): candidates/adopt/detach/connectCommand RPC shapes — but MOVE their declarations to the terminal extension's contract surface (Task 7 consumes). Core contract has zero adopt vocabulary.
    • Typecheck the two packages alone. Commit.

    Task 4: Core chat purge + rebuild

    Files: rewrite fresh (archive = anti-reference): packages/core/src/chat/run.ts, attach.ts, gate.ts, app.ts, api/rpc/chat.ts, api/rpc/mount.ts, api/mcp.ts, session.ts.

    • run.ts: accept caller runId, stamp all emitted lifecycle events; keep claimRun exclusivity (one turn per session — plain library semantics), claimMintedToken, run tracker. Remove SESSION_ATTACHED throws.
    • attach.ts: snapshot + live events only, runId-stamped; no epoch synthesis. Transcript mirroring NOT here (extension, Task 7).
    • gate.ts: read typed ToolCallPart (no zod re-parse); construct library ApprovalRequestedEvent typed; delete sessionAsk/StreamProcessor forgery + ensureToolCallPart timeout forging.
    • Message conversion: convertMessagesToModelMessages/normalizeToUIMessage from the library; both hand converters die.
    • api/mcp.ts ask/reply: in-process promise — MCP tool call awaits; user RPC reply resolves; AbortSignal on run cancel; no DB polls, no ToolDecider.
    • app.ts: no sendVetoes, no notifyChange/bumpExternal, no decideMcpTool. Extension surface (packages/extension/src/types.ts): remove beforeSend/notifyChange; keep session/token/launch observation hooks (they carry no send authority).
    • Core-purity grep gate passes (no terminal vocabulary in packages/core/src).
    • Core unit/IT suite (minus rehomed) green. Commit per file-cluster.

    Task 5: packages/client rewrite

    Files: delete all src; new packages/client/src/connection.ts (~100 LoC) + entry.

    • Library SubscribeConnectionAdapter (their name): subscribe = attach stream; send = rpc chat.send with runId from the library's runContext. No options beyond that.
    • Frozen client tests minus deleted flagged ones green. Commit.

    Task 6: ui-kit-chat composer draft persistence

    Files: packages/ui-kit-chat/src/composer/* (locations per existing package layout).

    • Draft (text+attachments+grabs+quote) snapshot/restore/clear on the assistant-ui composer runtime shape; survives reload via storage-history package.
    • Failure restore: send that died before its runId appeared on the stream → restore draft; after → notice only. One predicate, no attempt tracking.
    • Frozen ui-kit-chat browser tests green. Commit.

    Task 7: Terminal extension — external-terminal domain rewritten

    Files: packages/extensions/terminal/src/server/* new modules: session adoption (candidates/adopt/detach/tokens), connect planning/exec, presence, transcript mirror (ONE module, tearable), extension-owned RPC contract (from Task 3).

    • Rewrite from scratch against the frozen behavior tests (rehomed, Task 8) — archive code consulted only as anti-reference; harness connect/history sidecars (imported, good) are the platform surface.
    • Presence machine (idle/launching/connected/working/stale) drives the pill; NO sendPolicy — presence is display + busy state only.
    • Mirror: one producer module server-side, one consumer entry client-side; documented as the sync-engine tear-out point.
    • Extension suite green. Commit per module.

    Task 8: Test realignment (ruled dispositions only)

    • Delete the 19 flagged tests (list in map ticket Salvage inventory: triage the 426-file frozen-branch diff #181); strip force assertions from connect-flow.browser.test.tsx only.
    • Rehome adopt/observer tests from core/client suites into the extension suite: imports + router mount adjusted, assertions verbatim; diff reviewed to prove assertion-identity.
    • Commit.

    Task 9: App recomposition

    Files: apps/conciv/src/chat/** deleted; new thin view files; behavior relocated to owning packages (composer logic → ui-kit-chat; connect UI → terminal extension client; notices already Ark toast).

    • Rebuild chat pane as wiring + views only; no hooks with banned names; any file exceeding wiring/rendering moves to a package.
    • Send-while-running = the same busy/steer affordance as own runs, from server presence. No dialogs, no confirm.
    • Frozen app browser tests (minus deleted) green. Commit.

    Task 10: Full frozen suite

    • pnpm turbo run test --force (whiteboard suite CI-ONLY — never locally). Fix code, never tests, until green locally for the non-banned suites; push branch for CI whiteboard verification.

    Task 11: Screenshot pass

    • Playwright screenshots of composer states (idle/busy/steer), presence pill states, adopt flow; attach to PR.

    Task 12: Gates

    • Banned-identifier grep gate + core-purity grep gate added as a repo script wired into lint.
    • pnpm typecheck && pnpm build && pnpm lint, fallow audit --changed-since main — zero INTRODUCED.
    • Changeset; PR referencing map Chat rewrite map #177 with ladder-level table; CI green; user verifies before merge.

    Open inputs (non-blocking)

  2. omridevk commented on Aug 2, 2026

    @omridevk
    ContributorAuthor

    The plan draft in the earlier comment is VOID — written before the governing reframe (#192) and design v2.x; it still instructs building adopt/presence/mirroring. The plan will be rewritten from design v2.4 (pinned on map #177) once specs #190/#191 close. Do not execute anything from the old draft.

  3. omridevk commented on Aug 3, 2026

    @omridevk
    ContributorAuthor

    Chat-Stack Rewrite — Execution Plan (v2, from design v2.6 + specs #190/#191)

    Supersedes the voided draft above. Governing artifacts: design v2.6 (map #177 pinned comments),
    spec #190 (core), spec #191 (extension), salvage inventory #181 + its rulings. Each task below
    gets its own tracking issue with the full dispatch spec (files, interfaces, DoD) at open time.

    Goal: the clean-room chat stack green against the disposed frozen suite.

    Base: fork chat-rewrite from main; good work enters by whitelist import from
    archive/connected-external-terminal (ruling #182).

    Global constraints (every task)

    • Banned identifiers: bridge, pipeline, maintenance, manager, sendWhenAvailable, holdAndFlush,
      veto, epoch, snapshotKey, externalRev, forceSend, adopt, attach (except chat.subscribe's
      predecessor cleanup), presence; adapter only for library-defined interfaces. Gate in Task 12.
    • Core purity: no adopt/attach/presence/terminal/verdict vocabulary in packages/core/src.
    • Platform ladder P0: PR description carries the design's L3 table.
    • Repo style: functions only, zero comments, strict TS, oxfmt. One implementation agent at a time
      (shared dist). Whiteboard suite: CI-ONLY, never local.
    • Test edits: ONLY per the three ruled buckets (whole-file with feature / assertion surgery /
      rename-only), enumerated in Task 8. Anything unlisted must pass unedited.

    Tasks

    T1 — Branch + whitelist import

    Generate import list = git diff --name-only main...archive/connected-external-terminal minus:
    spec-191 do-not-import delta, inventory DELETE 5 + REWORK 18 (rewritten fresh), Task-8
    whole-file-bucket tests, docs/assets/pr-176/**. git checkout archive/... -- <paths>; single
    import commit; pnpm install; record expected-red typecheck ledger (= rework worklist).

    T2 — tanstack 0.42 line upgrade

    ai 0.42.0 / client 0.22.1 / solid 0.15.1 / sandbox 0.2.4 / adapters 0.2.3 (delta verified = tool-call
    caps only). No new typecheck errors beyond T1 ledger.

    T3 — Wire delta (packages/contract, packages/protocol)

    Per design v2.6 Wire section verbatim: sessions create/resolve/open/restore/list{includeHidden}/
    rename/model/delete; chat subscribe/send{sessionId,runId,content}/stop{sessionId}/
    permissionDecision/uiReply kept; launch+connectCommand REMOVED here (extension adds them, T7);
    attach*/force/verdict/epoch schemas deleted. THE DELTA RULE: every other route untouched.

    T4 — Core rebuild (packages/core) per spec #190

    Six modules (session-rows / run / subscribe / stop / ask / transcript) with the spec's contracts:
    MESSAGES_SNAPSHOT lead (UIMessages verbatim, never bundled with terminal events), runId-stamped
    live chunks, UIMessages straight into chat() (no pre-conversion), claimRun spans approval
    continuations, in-process ask promises, tombstone/restore, monotonic row-keyed snapshot cache,
    truncated-line tolerance. Delete list per spec. Core tests in kept buckets green.

    T5 — Client rewrite (packages/client)

    Delete all src; new: SubscribeConnectionAdapter (subscribe = chat.subscribe closure-bound per
    session, threadId = row id; send = stop-then-send steer sequencing, reads+caches
    runContext.runId, THROWS on rejection), chat client config queue: 'interrupt', reconnect retry
    loop (pacer AsyncRetryer if needed), makeQueryUtils kept. Client tests per buckets green.

    T6 — Composer completion (packages/ui-kit-chat)

    Draft persist (text+attachments+grabs+quote) via storage-history; restore on adapter throw;
    refresh button = subscribe({restart:true}), disabled while own run streams. Browser tests green.

    T7 — Terminal extension per spec #191

    terminal.launch/terminal.connectCommand (terminal-opener + connect.plan argv move in);
    pty routes minus chat couplings; claude plugin = skills + session MCP bridge (hooks-plugin +
    /hook endpoint deleted); all spec-191 deletions executed. Extension tests per buckets green.

    T8 — Test disposition (the ONLY test edits, one commit)

    Execute the three buckets verbatim from: #181 flagged list + spec #191 buckets + core/client
    additions (FIFO-queue assertion, BUSY-retry cases, wire.it verdict/BUSY lines, turn-detach BUSY
    line, send-force.it whole-file, mcp-approval reworked lines, sessions.stop→chat.stop and
    attach→subscribe rename-onlys). The task issue enumerates every file; the diff is reviewed
    against the enumeration line-by-line.

    T9 — App recomposition (apps/conciv)

    src/chat junk drawer deleted; panes rebuilt as views + wiring; composer connect UI per spec
    #191 (launch-menu + copy survive; candidates die); session selector keeps updatedAt/
    messageCount/origin/usage + core-run running dot; refresh button wired. App browser tests green.

    T10 — Full frozen suite

    pnpm turbo run test --force locally minus whiteboard; push branch → CI for whiteboard + full
    matrix. Fix code, never tests, until green.

    T11 — Screenshot pass

    Composer idle/streaming/steer, session list, refresh affordance, launch menu, terminal pane;
    attached to PR.

    T12 — Gates + PR

    Banned-identifier + core-purity grep gates wired into lint; fallow audit zero INTRODUCED;
    typecheck/build/lint; changeset; PR references map #177 with the L3 ladder table; user verifies
    before merge (hard rule).

    Sequencing

    T1 → T2 → T3 → {T4, then T5} → {T6, T7 parallel-safe after T3, but SERIAL per shared-dist rule}
    → T8 → T9 → T10 → T11 → T12. One agent at a time; conciv-implementer for T3-T5/T7,
    conciv-frontend for T6/T9, conciv-mechanic for T1/T2/T8/T11/T12 mechanical steps. Orchestrator
    reviews every diff + reruns gates personally per task (hard rule).

  4. omridevk commented on Aug 3, 2026

    @omridevk
    ContributorAuthor

    Resolved (user approved, 2026-08-03). Plan v2 (comment above) is locked. Tracking issues minted with serial blocking: T1 #194 → T2 #195 → T3 #196 → T4 #197 → T5 #198 → T6 #199 → T7 #200 → T8 #201 → T9 #202 → T10 #203 → T11 #204 → T12 #205. Execution starts at #194.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions