| 1 | --- |
| 2 | name: cw-slice |
| 3 | description: "Use before writing code for any Codewhale feature, upgrade, or refactor: find the existing owner of the behavior, bound the change to one reviewable slice, and fix the evidence bar before you start." |
| 4 | --- |
| 5 | |
| 6 | # cw-slice |
| 7 | |
| 8 | The expensive mistake in this repo is not a bad implementation — it is a second |
| 9 | implementation. A new `model_*`, `*_config`, `provider_*`, or "bridge" module |
| 10 | beside the one that already does the job ships two systems and a comment that is |
| 11 | no longer true. This skill is the ponytail ladder's rung 2 with commands |
| 12 | attached: **find the thing that already exists, then edit it.** |
| 13 | |
| 14 | Stage 2 of the loop: [cw-orient](../cw-orient/SKILL.md) → **slice** → |
| 15 | [cw-gates](../cw-gates/SKILL.md) → [cw-dogfood](../cw-dogfood/SKILL.md) → |
| 16 | [cw-land](../cw-land/SKILL.md) → [cw-handoff](../cw-handoff/SKILL.md). |
| 17 | |
| 18 | ## When to use |
| 19 | |
| 20 | - Any feature, upgrade, refactor, or "make X work like Y" request. |
| 21 | - Before creating a new module, trait, config struct, or command. |
| 22 | - When a plan or issue tells you to build something and you have not yet |
| 23 | confirmed it does not already exist. |
| 24 | |
| 25 | ## Workflow |
| 26 | |
| 27 | 1. **Walk the ladder before opening an editor** (`AGENTS.md`, "The ponytail |
| 28 | method" — not restated here, since a second copy is what rung 2 forbids). |
| 29 | Stop at the first rung that answers. The ladder runs *after* reading the |
| 30 | code, never instead of it: a short diff written without reading the call |
| 31 | sites is a guess, not a small change. State the rung only when the choice |
| 32 | isn't obvious from the diff itself. |
| 33 | |
| 34 | 2. **Grep for the predecessor.** This is the step that gets skipped and the one |
| 35 | that costs the most: |
| 36 | ```bash |
| 37 | grep -rn "<the concept, in the words the code would use>" crates --include='*.rs' | head -40 |
| 38 | ls crates |
| 39 | grep -rln 'model_\|_config\|provider_' crates/*/src --include='*.rs' | head -30 |
| 40 | ``` |
| 41 | Search behavior and symbols, not just filenames. If you find an owner, edit |
| 42 | it. If you are still adding a new layer, its module doc must name the |
| 43 | predecessor it replaces — otherwise you are editing the wrong file. |
| 44 | |
| 45 | 3. **Check the contracts you are about to walk into.** One of these is |
| 46 | guard-tested, the rest are convention — either way, move them with their |
| 47 | code, not around it: |
| 48 | - One turn loop: `crates/tui/src/core/engine/turn_loop.rs`, guarded by |
| 49 | `crates/core/tests/single_turn_loop.rs`. A second loop fails the guard; |
| 50 | changing the shape means changing the guard with it. |
| 51 | - One base prompt: `BASE_PROMPT` in `crates/tui/src/prompts/text.rs`. |
| 52 | - The subagent tool is `agent`; `agent_open` / `agent_eval` / |
| 53 | `agent_close` / `delegate_to_agent` are removed surfaces. If the shape |
| 54 | must move, move the code and add the guard test that judges the new |
| 55 | shape — the convention is not a fence around the area. |
| 56 | - The system prompt + tool catalog are a session-pinned KV-cache prefix |
| 57 | (`docs/CACHE.md`). Any new session-context contributor must state its cache |
| 58 | effect — frozen prefix vs. append-only history. Never splice a volatile |
| 59 | fact into the prefix. |
| 60 | - `crates/tui/src/core/` is a module inside the TUI crate. `crates/core` is a |
| 61 | different crate that runs no turns. Do not confuse them. |
| 62 | - Repeatedly misidentified as dead, verify consumers before removing: |
| 63 | `runtime/src/context_budget.rs`, `tui/src/model_registry.rs`, |
| 64 | `runtime/src/prompt_zones.rs`, `tui/src/tools/remember.rs`, `config/src/route/`. |
| 65 | |
| 66 | 4. **Read the scoped guidance for the files you will touch.** `crates/tui/AGENTS.md` |
| 67 | owns the UI contracts (one owner per fact, `codewhale_palette::grammar` semantics, typed |
| 68 | state enums, toast routing, `tr(locale, MessageId::...)` for user prose). |
| 69 | `crates/tui/locales/AGENTS.md` owns string changes. `web/AGENTS.md` owns the |
| 70 | site. `docs/MOTION_CONTRACT.md` owns motion. Design law lives in |
| 71 | `docs/design/`, not in a prototype file someone left in a sibling directory. |
| 72 | |
| 73 | 5. **Bound the slice.** One coherent change, reviewable in one sitting, that |
| 74 | leaves the tree building and green. `AGENTS.md`'s two corollaries keep |
| 75 | slices honest: an abstraction must delete caller code, and a migration |
| 76 | ships its last consumer or does not start. |
| 77 | |
| 78 | 6. **Fix the evidence bar now, not after.** Decide before writing code what will |
| 79 | prove this works, and write it into your plan: |
| 80 | - the focused test or existing check that covers the behavior |
| 81 | (`scripts/dev-test.sh --list` maps an area to its fastest invocation); |
| 82 | - whether the change is visible enough to need [cw-dogfood](../cw-dogfood/SKILL.md); |
| 83 | - whether it is cross-cutting enough to need the full sweep in |
| 84 | [cw-gates](../cw-gates/SKILL.md). |
| 85 | |
| 86 | 7. **Write the implementation first.** Code first, then tests (see `AGENTS.md` |
| 87 | — this repo does not practice TDD). Build it, prove it runs, then add or |
| 88 | adjust tests to cover what you actually built. |
| 89 | |
| 90 | ## Red flags / don't |
| 91 | |
| 92 | - Don't add a module that "bridges", "mirrors", "stages", or "wraps" something |
| 93 | that already exists without naming that thing in the module doc. |
| 94 | - Don't fork a singleton (turn loop, base prompt, delegation axis, |
| 95 | lifecycle system) without moving its guard test and consumers with it. |
| 96 | The repo has one of each on purpose; a silent second one is the failure |
| 97 | mode, not the refactor. |
| 98 | - Don't write tests first. Don't add tests by default either — add one when it |
| 99 | cheaply protects safety, data integrity, protocol compatibility, or a |
| 100 | reproduced regression. |
| 101 | - Don't contort production code to keep a brittle assertion green. A test that |
| 102 | only encodes old behavior is evidence, not a veto: change it with the code. |
| 103 | - Don't cut trust-boundary validation, data-loss handling, security, or |
| 104 | accessibility to make a diff shorter. Brevity is never a reason to drop a guard. |
| 105 | - Don't leave a `#[allow(dead_code)]` behind as the cost of an incomplete |
| 106 | migration — `scripts/check-dead-code-budget.py` is the running receipt. |
| 107 | |
| 108 | ## Output |
| 109 | |
| 110 | Default shape before the first edit — compress when trivial (a one-line |
| 111 | change gets a one-line note, not four bullets): |
| 112 | |
| 113 | - which rung of the ladder you stopped at and why; |
| 114 | - the existing owner you found (`path/to/file.rs:line`), or the predecessor |
| 115 | your new module names; |
| 116 | - the bounded slice, in one sentence; |
| 117 | - the evidence bar you will meet, chosen in advance. |
| 118 |