|
| 1 | +# Technical debt — known parallel implementations of pi-mono |
| 2 | + |
| 3 | +Six items where we re-implemented (or fight) functionality pi-mono already |
| 4 | +ships. Surfaced in the 2026-05-14 cross-stack audit. Each item lists |
| 5 | +estimated effort, ship-on-main feasibility, and what unblocks it. |
| 6 | + |
| 7 | +## Ship-on-main (no pi-tui dependency) |
| 8 | + |
| 9 | +### 3. OAuth storage — replace ours with pi-mono's AuthStorage |
| 10 | +- **Where**: `src/auth/credentials.ts` + `src/auth/token-manager.ts` (~280 LOC) |
| 11 | +- **Upstream**: `pi-mono/packages/coding-agent/src/core/auth-storage.ts` (~350 LOC) |
| 12 | +- **Why**: pi-mono's version is production-hardened, ships provider-specific |
| 13 | + flows, handles refresh + revocation. We re-derived the basics. |
| 14 | +- **Risk**: our `TokenManager` does multi-process single-flight refresh via |
| 15 | + proper-lockfile (the user runs 5–10 instances at once). Verify pi-mono |
| 16 | + handles this — if not, contribute it upstream before swap. |
| 17 | +- **Effort**: ~½ day swap, ~1 day if lock contribution needed upstream. |
| 18 | + |
| 19 | +### 4. Session store — adopt pi-mono's SessionManager |
| 20 | +- **Where**: `src/sessions/store.ts` (subset of pi-mono's `SessionManager` ~1000 LOC) |
| 21 | +- **Upstream**: `pi-mono/packages/coding-agent/src/core/session-manager.ts` |
| 22 | +- **What we're missing today**: cwd-validation, fork semantics, conflict |
| 23 | + resolution. If a user moves `~/.codebase`, we drop sessions silently. |
| 24 | +- **What stays ours**: the resume CLI flag flow, the per-cwd hashing |
| 25 | + convention. The picker UI (interactive resume chooser) is pi-tui-coupled |
| 26 | + and stays deferred until phase 5. |
| 27 | +- **Effort**: ~1 day. |
| 28 | + |
| 29 | +### 5. Model resolution — adopt pi-mono's ModelRegistry |
| 30 | +- **Where**: `src/agent/config.ts:110–150` |
| 31 | +- **Upstream**: `pi-mono/packages/coding-agent/src/core/model-registry.ts` (~900 LOC) |
| 32 | +- **Gains**: provider registration, custom models, fallbacks, thinking-level |
| 33 | + scoping. Drop-in for our `resolveConfig` + `buildProxiedConfig`. |
| 34 | +- **Effort**: ~½ day. |
| 35 | + |
| 36 | +### 6. Wire pi-agent-core's tool lifecycle hooks |
| 37 | +- **Where**: `src/hooks/manager.ts` + `src/hooks/runner.ts` |
| 38 | +- **Upstream**: `pi-agent-core` exports `beforeToolCall` / `afterToolCall` |
| 39 | + in `AgentLoopConfig` (`packages/agent/src/types.ts:47–100`). |
| 40 | +- **Today**: our `HookManager` exists but doesn't reach into pi's loop, so |
| 41 | + user hooks can't observe tool calls. |
| 42 | +- **Effort**: ~2 hours. |
| 43 | + |
| 44 | +## Pi-tui-blocked (deferred until phase 5) |
| 45 | + |
| 46 | +### 1. Hand-rolled kill ring + undo + paste handling |
| 47 | +- **Where**: `src/ui/input-state.ts:1–100` |
| 48 | +- **Upstream**: pi-tui's `Editor` ships this natively. |
| 49 | +- **Why blocked on pi-tui**: the algorithms are entangled with pi-tui's |
| 50 | + grapheme segmenter, autocomplete provider, and visual layout. Can't |
| 51 | + cleanly lift just the kill-ring without bringing the editor. |
| 52 | +- **Effort**: 0 incremental cost — pi-tui migration already covers this. |
| 53 | + |
| 54 | +### 2. Event re-encoding (AgentEvent → Action union) |
| 55 | +- **Where**: `src/agent/events.ts:25–80` |
| 56 | +- **Why blocked on pi-tui**: the reducer exists because React wants |
| 57 | + immutable state slices. Subscribing to `bundle.subscribe()` directly |
| 58 | + and dropping the `Action` union only pays off in an imperative renderer |
| 59 | + (which pi-tui is). On main with ink, moving the impedance mismatch |
| 60 | + doesn't reduce it. |
| 61 | +- **Effort**: 0 incremental cost — pi-tui migration removes the reducer |
| 62 | + by construction. |
| 63 | + |
| 64 | +## Worth keeping (not debt) |
| 65 | + |
| 66 | +These are legitimately ours; pi-mono has no equivalent and we shouldn't |
| 67 | +try to upstream them blindly: |
| 68 | + |
| 69 | +- `src/permissions/` — effect-based permissions (~600 LOC). Pi-mono has |
| 70 | + no permission system at all. Contributing upstream would be polite but |
| 71 | + it's not a "remove duplication" task. |
| 72 | +- `src/glue/` — small-talk classifier + reply path (~250 LOC). Skips |
| 73 | + agent turns for chit-chat. |
| 74 | +- `src/memory/` — episodic memory (~350 LOC). Per-cwd recent decisions. |
| 75 | +- `src/plan/` — plan-mode Q&A → review → execute (~200 LOC). |
| 76 | +- `src/user-queries/` — modal-overlay primitive (~400 LOC). |
0 commit comments