--- description: Total deslop, optimization, rule alignment, architecture refactor, cruft removal, and test rework of one extension argument-hint: " [focus]" --- # Massive cleanup Target: `$ARGUMENTS` Resolve the extension directory under `extensions/`. Stop with one question when the target is ambiguous. Optional focus narrows priority, never scope. ## Load first - `coding-guidelines`, `desloppy`, `vertical-slices` skills. - `extensions/AGENTS.md`, `extensions/DEBUG.md`, `extensions/SETTINGS.md`. - `.system/specs/PX-SPEC-DZLVGRW4-pi-extension-architecture/index.md` and the approved plans for it. - The extension's `README.md`, `package.json`, `mise.toml`, and every source and test file. ## Mandate Treat the extension as if written today against the current rules and architecture. Rewrite freely. Preserve user-observable behavior except where the removal is the point; list every intentional behavior change. 1. Deslop. Remove accidental complexity, duplication, needless indirection, weak types, defensive noise, commented-out code, stale comments, and `any` reach-ins. 2. Optimize. Fast `session_start`, lazy-loaded command and tool implementations, no startup subprocesses, network, or filesystem scans, minimal context impact. Measure before claiming gains. 3. Align to project rules. Generated settings and debug helpers only, no direct `getFlag`/`registerFlag`/settings reads, no `console.*` in runtime, Pi peers in `peerDependencies`, no sibling imports, tool widgets honoring native expansion, cross-platform paths and executables. 4. Refactor to the package architecture. Everything the generated `dist/` package needs is declared under `pi-ext` (entries, resources, assets, justified externals). Runtime files resolve relative to `import.meta.url`; extension-dependent paths derive from it. Portable third-party code bundles; every external carries a demonstrated incompatibility. No dependence on repository source, workspace links, or ancestor `node_modules`. 5. Remove cruft. Legacy compatibility shims, dead settings, migration code for versions no one runs, unused exports, unused dependencies, obsolete docs. Check Git history when unsure whether something is still load-bearing; delete when it is not. 6. Rework tests. Delete tests that assert implementation details, mock the unit under test, duplicate other tests, snapshot volatile data, or pass regardless of behavior. Add tests for real behavior that is untested: contract loading through Pi, tool and command dispatch, settings precedence, error paths, cancellation, platform fallbacks, relocation of the generated package. Keep the mandatory harness test. Prefer deterministic inputs and controlled fake executables over mocks. ## Method Work in vertical slices; each slice leaves the extension loadable and its tests green. Debug root causes; never paper over failures. Change generated files only through their templates and `//:codegen`. Do not touch other extensions except to fix a shared template when the rules demand it. Verify after each slice and freshly at the end: - `mise run //extensions/:lint` - `mise run //extensions/:test` - `mise run //extensions/:check` - `mise run //extensions/:verify-package` Run root `//:check` and `//:test` once at the end. Update `README.md` to match the result; keep it terse and link sources. Do not commit unless the user asks. ## Report - Removed: files, exports, dependencies, settings, compatibility paths, with line counts before and after. - Behavior changes: each one, with rationale. - Tests: deleted with reason, added with covered behavior. - Measurements: startup, bundle size, context impact, before and after. - Verification results, read in full. - Open questions or rule conflicts found in the extension or the rules themselves.