Provider, Codex, and CLI Bootstrap Refactor Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Reduce one-off provider install logic, split the overgrown Codex harness adapter, and replace ad hoc SQLite-free CLI parsing with a clearer dispatch layer without changing external behavior.
Architecture: Introduce shared provider install-target helpers used by setup, uninstall, and doctor. Move SQLite-free command dispatch into a dedicated CLI module with small command descriptors. Split Codex provider code into focused modules while preserving the existing public imports used by tests.
Tech Stack: TypeScript ESM, Commander, Vitest, Node fs/process APIs.
Task 1: Provider Instruction Targets#
Files:
- Create:
src/agent/install-targets.ts - Modify:
src/commands/setup.ts - Modify:
src/commands/uninstall.ts - Modify:
src/commands/doctor-checks/install.ts - Test:
test/setup.test.ts,test/uninstall.test.ts,test/doctor.test.ts
Steps:
- Extract Claude import-file and Codex inline-block behavior behind provider instruction target helpers.
- Keep setup and uninstall output compatible with existing tests.
- Add doctor checks for Codex instructions while preserving existing stable install keys.
- Run targeted setup/uninstall/doctor tests.
Task 2: SQLite-Free CLI Bootstrap#
Files:
- Create:
src/cli/sqlite-free.ts - Modify:
src/cli.ts - Test:
test/cli.test.ts
Steps:
- Move SQLite-free dispatch and flag parsers into a focused module.
- Use a small descriptor table for recovery-safe command dispatch.
- Preserve setup shortcut behavior and worker/update fast paths.
- Run CLI tests.
Task 3: Codex Harness Adapter Split#
Files:
- Create:
src/harness/providers/codex/request.ts - Create:
src/harness/providers/codex/app-server.ts - Create:
src/harness/providers/codex/events.ts - Modify:
src/harness/providers/codex.ts - Test:
test/codex-harness-provider.test.ts
Steps:
- Move request construction and unsupported-field validation into
request.ts. - Move app-server process/JSON-RPC runner into
app-server.ts. - Move notification/event/usage mapping into
events.ts. - Re-export existing public test imports from
codex.ts. - Replace hard-coded app-server client version with package version lookup.
- Run Codex harness tests.
Task 4: Full Verification#
Steps:
- Run
npm run lint. - Run
npm test. - Run
almanac healthand note remaining wiki-only dead refs if unchanged.
Implementation Log#
- 2026-05-13: Initial plan created after reading
provider-install-layer,harness-providers,sqlite-free-cli-bootstrap, andlifecycle-cli. - 2026-05-13: Began Task 1 by creating
src/agent/install-targets.tsto centralize Claude import-file and Codex inline-instruction behavior. - 2026-05-13: Updated
src/commands/setup.tsandsrc/commands/uninstall.tsto call the shared instruction helpers while preserving legacy exports used by tests. - 2026-05-13: Updated
doctorinstall checks soinstall.importvalidates both Claude import and Codex managed instructions while keeping the existing stable key list. - 2026-05-13: Verified Task 1 with
npm test -- test/setup.test.ts test/uninstall.test.ts test/doctor.test.tsandnpm run lint. - 2026-05-13: Completed Task 2 by moving recovery-safe command routing and setup shortcut parsing into
src/cli/sqlite-free.ts. - 2026-05-13: Verified Task 2 with
npm test -- test/cli.test.tsandnpm run lint. - 2026-05-13: Began Task 3 by extracting Codex request construction to
src/harness/providers/codex/request.tsand Codex readiness probes tosrc/harness/providers/codex/status.ts. - 2026-05-13: Replaced the hard-coded Codex app-server client version with package-version lookup from the request module.
- 2026-05-13: Verified the Codex extraction with
npm test -- test/codex-harness-provider.test.tsandnpm run lint. - 2026-05-13: Follow-up Codex cleanup split
src/harness/providers/codex.tsinto a 106-line facade pluscodex/exec.ts,codex/app-server.ts, andcodex/events.ts. - 2026-05-13: Verified the Codex event/protocol split with
npm run lintandnpm test -- test/codex-harness-provider.test.ts.
Decision Log#
- Keep this as a refactor, not a feature expansion: no new public commands and no behavior change unless required to remove a smell safely.
- Preserve existing exported compatibility functions from
setup.tsanduninstall.tsso current tests and external callers do not need a coordinated migration. - Do not implement Cursor install behavior in this pass. Cursor remains gated/placeholder; the target abstraction should make it easier later without pretending support exists now.
- Keep
install.importas the stable doctor key rather than adding a new Codex-specific install key. The message now describes "Agent instruction entries" so JSON consumers do not see a breaking key list. - Keep
tryParseSetupShortcutre-exported fromsrc/cli.tseven though its implementation moved, because tests and external code may already import it from the process entrypoint. - Keep
src/harness/providers/codex.tsas the compatibility facade. Tests and downstream imports continue using the old module path while the implementation lives in smaller files. - Split Codex by responsibility rather than protocol names alone:
exec.tsowns the legacycodex exec --jsonpath,app-server.tsowns JSON-RPC process handling, andevents.tsowns normalized harness-event mapping plus failure/usage parsing.