@tacuchi/agent-workflow-cli 20.16.0 → 20.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +25 -4
  2. package/dist/application/branch-resolver.js +28 -0
  3. package/dist/application/branch-resolver.js.map +1 -1
  4. package/dist/application/check-branch-service.js.map +1 -1
  5. package/dist/application/git-flow-service.js +59 -40
  6. package/dist/application/git-flow-service.js.map +1 -1
  7. package/dist/application/parsers/phases.js +135 -0
  8. package/dist/application/parsers/phases.js.map +1 -0
  9. package/dist/application/parsers/project-block.js +23 -3
  10. package/dist/application/parsers/project-block.js.map +1 -1
  11. package/dist/application/project-md-upsert-service.js +12 -5
  12. package/dist/application/project-md-upsert-service.js.map +1 -1
  13. package/dist/application/project-tab-data.js +37 -2
  14. package/dist/application/project-tab-data.js.map +1 -1
  15. package/dist/application/render/project-block.js +23 -1
  16. package/dist/application/render/project-block.js.map +1 -1
  17. package/dist/application/status-service.js +66 -2
  18. package/dist/application/status-service.js.map +1 -1
  19. package/dist/application/workspace-init-service.js +5 -3
  20. package/dist/application/workspace-init-service.js.map +1 -1
  21. package/dist/cli/commands/git-flow.js +3 -3
  22. package/dist/cli/commands/git-flow.js.map +1 -1
  23. package/dist/cli/tui/app.js +21 -1
  24. package/dist/cli/tui/app.js.map +1 -1
  25. package/dist/cli/tui/components/git-flow-actions.js +1 -0
  26. package/dist/cli/tui/components/git-flow-actions.js.map +1 -1
  27. package/dist/cli/tui/tabs/config-tab.js +88 -19
  28. package/dist/cli/tui/tabs/config-tab.js.map +1 -1
  29. package/dist/cli/tui/tabs/project-tab.js +10 -2
  30. package/dist/cli/tui/tabs/project-tab.js.map +1 -1
  31. package/package.json +1 -1
  32. package/skills/w/SKILL.md +9 -7
  33. package/skills/w/artifacts/artifacts-core/CHECKPOINT.md +3 -1
  34. package/skills/w/artifacts/artifacts-exec/DECISION.md +2 -0
  35. package/skills/w/commands/README.md +1 -1
  36. package/skills/w/commands/plan-exec.md +6 -3
  37. package/skills/w/commands/plan-new.md +7 -3
  38. package/skills/w/commands/plan-refine.md +5 -2
  39. package/skills/w/commands/resume.md +8 -6
  40. package/skills/w/commands/spec-new.md +53 -15
  41. package/skills/w/commands/spec-refine.md +7 -6
  42. package/skills/w/commands/status.md +10 -5
  43. package/skills/w/loops/CHASSIS.md +3 -3
  44. package/skills/w/loops/CODE-POLICIES.md +2 -0
  45. package/skills/w/loops/plan-exec-loop/LOOP.md +97 -36
  46. package/skills/w/loops/plan-new-loop/LOOP.md +63 -11
  47. package/skills/w/loops/plan-refine-loop/LOOP.md +89 -21
  48. package/skills/w/loops/quick-loop/LOOP.md +1 -1
  49. package/skills/w/loops/spec-refine-loop/LOOP.md +140 -60
@@ -2,11 +2,11 @@
2
2
  name: plan-exec-loop
3
3
  description: >-
4
4
  Executes an implementation plan (docs/plans/PPP-plan-<slug>.md) as a living
5
- doc: reads and updates it phase by phase while editing the real code and
6
- managing DB and git. Heir of the chassis (loops/CHASSIS.md +
7
- CODE-POLICIES.md). Deltas: single resumable session, safe git (verified
8
- branch, per-source proposed commits, never push/--amend/--no-verify), DB
9
- scripts-only (never executes DML/DDL), per-phase and final validation,
5
+ doc: runs it phase by phase each phase a verifiable state — while editing
6
+ the real code and managing DB and git. Heir of the chassis (loops/CHASSIS.md
7
+ + CODE-POLICIES.md). Deltas: executability entry gate, deviation gate
8
+ (structural to plan-refine, functional to spec-refine), single resumable
9
+ session, safe git, DB scripts-only, phase proof plus progressive tests,
10
10
  pre-commit closing review gate, no auto-export. Composes git and sql.
11
11
  Started by /w:plan-exec. Invoke to implement an already generated plan.
12
12
  ---
@@ -22,10 +22,10 @@ PLAN
22
22
  2 — the AI runs it end to end.
23
23
 
24
24
  ## Started by
25
- `/w:plan-exec` — **resumable** (same chassis mechanism; here resume keys off the plan-doc checkboxes + CHECKPOINT, see Delta 1).
25
+ `/w:plan-exec` — **resumable** (same chassis mechanism; here resume keys off the plan-doc phase states + checkboxes + CHECKPOINT, see Delta 1).
26
26
 
27
27
  ## Reads
28
- `docs/plans/PPP-plan-<slug>.md` (locate via the `docs/plans/PPP-plan-*.md` glob or the exact path from the command argument). It runs **any** plan, whether or not it passed through [`plan-refine-loop`](../plan-refine-loop/LOOP.md) — plan-refine is auxiliary, not mandatory; no gate requires it. If the plan includes UI, it also reads the **design SPECs** (`NNN-SPEC-<SLUG>.md`) its Tasks reference — artifacts of the plan-new/plan-refine session, read **read-only** as the design reference while implementing (see [`SPEC.md`](../../artifacts/artifacts-design/SPEC.md)).
28
+ `docs/plans/PPP-plan-<slug>.md` (locate via the `docs/plans/PPP-plan-*.md` glob or the exact path from the command argument) **and its source spec** (resolved through the plan's `## Origin`) — the entry gate reads both. It runs **any** plan, whether or not it passed through [`plan-refine-loop`](../plan-refine-loop/LOOP.md) — plan-refine is auxiliary, not mandatory; no gate requires it. What it does require is an **executable shape** (§ *Entry gate — executability*). If the plan includes UI, it also reads the **design SPECs** (`NNN-SPEC-<SLUG>.md`) its Tasks reference — artifacts of the plan-new/plan-refine session, read **read-only** as the design reference while implementing (see [`SPEC.md`](../../artifacts/artifacts-design/SPEC.md)).
29
29
 
30
30
  ## Writes
31
31
  - `docs/plans/PPP-plan-<slug>.md` (**read/update**, living doc: phase/task state, `Open questions`).
@@ -54,16 +54,55 @@ Read **[`../CHASSIS.md`](../CHASSIS.md)** — the loop's **full engine** — **a
54
54
 
55
55
  > **Compat (legacy):** old workspaces may hold `plan-exec-phase-*` sessions (one per phase) and `*-research-*` ones — historical, left as-is; new runs use a single session.
56
56
 
57
- ## Delta 1One session per run; per-phase progress in the plan-doc
57
+ ## Entry gateexecutability
58
+
59
+ **Before touching code**, read the plan and its spec and check the shape execution depends on:
60
+
61
+ 1. every phase declares its `Resultado`, its `Condición de salida` and its `Validación de fase`;
62
+ 2. if temporary behavior exists, its current boundary and retirement phase are identifiable; otherwise the simulation check is not applicable;
63
+ 3. the primary proof of the first `pendiente` phase is identifiable;
64
+ 4. no structural contradiction is evident (a phase that undoes an earlier one, evidence nobody can produce).
65
+
66
+ Execution **no longer accepts in silence** a plan that would force it to invent its own structure. Two outcomes:
67
+
68
+ - **Minor gap** — the plan is all but executable: an exit condition derivable from what is already written, the obvious evidence unnamed, micro-tasks to group. `plan-exec` may **normalize it with consent** — one structured-choice content question, labels `Normalizar y ejecutar` (recommended) | `Ir a plan-refine`. Normalizing edits the `### Fn` blocks in place, **adds no scope and moves no boundary**, and is recorded in `DECISION` + `CHECKPOINT`.
69
+ - **Structural gap** — phases, contracts, journey or simulation boundary are missing. It does **not** improvise: record the finding in `CHECKPOINT`, hand off to [`plan-refine-loop`](../plan-refine-loop/LOOP.md) (`/w:plan-refine`) and resume execution over the refined plan.
70
+
71
+ > The gate reads the **canonical phase contract** from [`plan-new-loop`](../plan-new-loop/LOOP.md) § *Phase contract (canonical)* — required sections, the `> Estado:` vocabulary, semantic granularity. Execution references it; it never redefines it. The marker is a **line of its own** inside the `### Fn` block (`> Estado: <value>`); written any other way it reads as `pendiente`.
72
+
73
+ ## Delta 1 — One session per run; the phase cycle in the plan-doc
58
74
 
59
75
  - Walks the plan's `### Fn` blocks under `## Tasks` in order (respecting deps) **inside the run's single session** (no session-per-phase). *(Legacy plans: a separate `## Phases` table — walk it the same way.)*
60
- - **Per-phase progress lives in the plan-doc** (`- [x]`) and in the single `CHECKPOINT` (Completed/Pending/Next): **artifact-first** `CHECKPOINT.Next` is set to the imminent phase **before** starting it; the plan-doc's `- [x]` checkbox is flipped **after** completing the task.
61
- - Executes the phase's tasks; **skips** the ones already `- [x]` in the plan (the plan-doc is the per-task source of truth). Marks `- [x]` **in the plan** (living doc; never in a separate `TASKS`).
62
- - **Checkbox-only residue (hard rule):** execution writes into the plan-doc **only** three things — checkbox flips (`- [ ]` → `- [x]`), deferrals appended to its `## Open questions` (the declared-gap escape hatch: Delta 4's unapplied migration, Delta 5's deferred findings, Delta 7's failed probe), and, on close, the single status line (Delta 6). Per-phase results, review-gate findings and metrics go to the session's `DECISION`/`CHECKPOINT` **never** into the plan-doc. Phase blocks are updated **in place NEVER append a duplicate `### Fn` block** (same contract as CHECKPOINT sections).
63
- - At **every phase boundary**: validate, run the **closing review gate** (Delta 5), update the `CHECKPOINT` (Completed += Phase N, Next = Phase N+1) and propose commits.
64
- - Records in `DECISION` only the **non-obvious**, **as it is decided** (per-phase decisions accumulate in the SINGLE `DECISION`, tagged by phase/task e.g. `Origin: T2 (F1)`).
76
+ - **Phase cycle** (artifact-first, one per `### Fn`): read `Resultado` + `Condición de salida` → confirm the initial state → flip `> Estado: en ejecución` and seed `CHECKPOINT.Next` execute its tasks → run the phase proof plus the justified focused tests (Delta 4). Then: closing review gate over the phase's whole diff (Delta 5) → confirm the `Condición de salida` flip `> Estado: validada` → update `CHECKPOINT` and propose commits (Delta 2).
77
+ - Executes the phase's tasks; **skips** the ones already `- [x]` in the plan (the plan-doc is the per-task source of truth). **Micro steps stay internal** (canonical contract): they reach `CHECKPOINT` only when a resume needs them, never the plan.
78
+ - **Marking order (hard rule):** a task is marked `- [x]` when its local work is finished. A phase reaches `validada` **only** when its primary proof **ran and passed**, the needed focused checks passed, its `Condición de salida` is true, the review gate is green and every remaining review finding is explicitly deferreda blocker is never deferred into `validada`. **Never** because all its checkboxes are ticked.
79
+ - **Intermediate states:** `bloqueada` = the phase is stopped on a live blocker — recorded in `CHECKPOINT` + the plan's `## Open questions`, back to `en ejecución` when it clears; it counts as **not validated**. A phase whose work is complete but whose operative check the AI **cannot run** (an unapplied migration — Delta 3) **stays `bloqueada`**: its finished tasks keep their boxes ticked, and the reason goes on its own `> Bloqueo:` line, dropped when the blocker clears. It counts as **not validated** until the check runs and passes. Never a silent `validada`.
80
+ - **Plan-doc residue (hard rule):** execution writes into the plan-doc **only** five things checkbox flips (`- [ ]` → `- [x]`), the phase's own `> Estado:` line, its `> Bloqueo:` line while blocked, deferrals appended to its `## Open questions`, and, on close, the single plan status line (Delta 6). The declared-gap hatch is Deltas 4, 5 and 7. Per-phase results, review-gate findings and metrics go to the session's `DECISION`/`CHECKPOINT` **never** into the plan-doc. Phase blocks are updated **in place — NEVER append a duplicate `### Fn` block** (same contract as CHECKPOINT sections). The entry gate's consented normalization is the single exception, and it lands before execution starts.
81
+ - **CHECKPOINT per phase:** on closing a phase record the **functional state reached**, the simulation boundary in force **only when the change carries one**, the tests run and their result, the non-obvious decisions, the deferrals and the next state being pursued. Enumerating every file touched is not required unless it helps a resume.
82
+ - Records in `DECISION` only the **non-obvious**, **as it is decided** (per-phase decisions accumulate in the SINGLE `DECISION`, tagged by phase/task — e.g. `Origin: T2 (F1)`). A structural deviation is **not** settled with an entry there (§ *Deviation gate*).
65
83
  - The chassis **gap-driven** engine applies here **inside a task**: facing a non-obvious decision/doubt → inline research, a probe (Delta 7) OR structured-choice.
66
84
 
85
+ > **Legacy plans degrade safely.** `plan-exec` still runs plans with `### Fn` blocks, `- [ ]` tasks, legacy sections and **no** `> Estado:` line: a missing line reads `pendiente`, and nothing is back-filled. A plan with every box ticked is **not** validated by that fact — the session (`CHECKPOINT`, review gate) decides. What is genuinely missing is closed by the entry gate or by `plan-refine`, never assumed.
86
+
87
+ ## Deviation gate
88
+
89
+ Execution resolves **detail**, never **redesign**. This gate lives **only** in this loop — the chassis does not carry it.
90
+
91
+ - **Local decision — `plan-exec` continues.** A class or method name; a local helper; internal code layout; imports; a choice between equivalent APIs already allowed; a fix needed to compile; a minor refactor that does not move the journey; one extra focused test for a risk found while implementing. Recorded in `DECISION` only when it is not obvious.
92
+ - **Structural deviation — stop and return to `plan-refine`.** Stop when the change touches: an input or output; an observable state; a relevant endpoint or public contract; the set of participating components or repositories; the phase order; the simulation boundary; the integration strategy; a material dependency; the main persistence mechanism; a phase already `validada`; the evidence needed to demonstrate the result. A decision that substantially expands or shrinks the work counts too.
93
+ - **Functional change — return to `spec-refine`.** Stop when the change touches: the expected result; the functional scope; a business rule; an acceptance criterion; the actor or consumer; or a product decision.
94
+
95
+ On either return path: `CHECKPOINT` records the state reached and the trigger, the phase keeps the state it really has (`en ejecución` or `bloqueada`, never `validada`), the working tree is left committed or acknowledged (Delta 2), and the human is told through a structured-choice which command to run. Resuming later over the corrected plan is a normal `create_or_resume`.
96
+
97
+ | Finding | `plan-exec` | `plan-refine` | `spec-refine` |
98
+ |---|---|---|---|
99
+ | Rename a helper · internal implementation · test for a local risk | continues | — | — |
100
+ | Change the public DTO | stops | yes | yes, if behavior changes |
101
+ | Add a participating repository | stops | yes | — |
102
+ | Move the simulation to another boundary | stops | yes | — |
103
+ | Change the phase order | stops | yes | — |
104
+ | Add a functional rule · change an acceptance criterion | stops | — | yes |
105
+
67
106
  ## Delta 2 — Git policy: **safe branch + proposed commits**
68
107
 
69
108
  Full policy in [`../CODE-POLICIES.md`](../CODE-POLICIES.md) (§ *Safe git*: branch-check before editing, rejected commit — changes stay + get recorded —, working-tree precondition between phases). **Inline:** before editing, verify each source's expected branch (`aw check-branch --source <alias>`; on mismatch → pause and resolve with the human); at each phase close and **after the review gate** (Delta 5), **proposed commits per source** (approve first) — never `push`/`--amend`/`--no-verify`.
@@ -72,23 +111,30 @@ Full policy in [`../CODE-POLICIES.md`](../CODE-POLICIES.md) (§ *Safe git*: bran
72
111
 
73
112
  Full policy in [`../CODE-POLICIES.md`](../CODE-POLICIES.md) (§ *DB scripts-only*). **Inline:** read-only queries → the session's `SCRIPTS.sql`, executed via MCP (`sql-mutation-guard`); DDL/DML migrations → the AI **drafts them in `SCRIPTS.sql` but NEVER executes them** — their promotion to `docs/scripts/` is done by a separate `export-*`, never this loop.
74
113
 
75
- ## Delta 4 — Validation
114
+ ## Delta 4 — Validation: phase proof + progressive tests
76
115
 
77
- - After executing (per phase and at the end): run tests/checks against `Validations` + the Final behavior block of `## Solution` (legacy plans: the `## Final behavior` section) + the spec's acceptance/success criteria (its `## Scenarios`, if present, are ready-made test cases: GIVEN=arrange · WHEN=act · THEN=assert).
78
- - A validation that **runs and fails** back to the task (gap); no advancing.
79
- - **Validation depending on an unapplied migration**: since the AI never executes the DML, it **cannot run it read-only** it is **deferred** (handoff to a DBA), it does **not block progress**. Recorded in the plan's `Open questions` + `BACKLOG`, marked "verification pending until the SQL is applied". (Reuses the chassis degrade/defer pattern + `MAX` cap → avoids the "back to the task" loop.)
116
+ - The phase's **primary proof** is its `Validación de fase`: it demonstrates the **state reached**, not the structure written. Three levels, and the loop never descends one automatically:
117
+ 1. **phase proof** component interaction, endpoint smoke test, vertical run down to the stub, persistence integration, or the main path end to end;
118
+ 2. **focused tests** added when the layer carries its own rules, a relevant transformation, error handling, persistence, transactions, temporal logic or external integration;
119
+ 3. **risk tests** — security, concurrency, idempotency, retries, known regressions.
120
+ - **One vertical proof per operation while wiring** (request → controller → use case → repository → fake or stub → expected response): it demonstrates the path once instead of re-asserting the same happy path at every layer. Trivial mappers, plain DTOs and framework behavior get no dedicated test.
121
+ - Compatible with **TDD without a test per method**: the evidence may be written before, during or after the phase's code. What is mandatory is that the `Condición de salida` be demonstrated **before** the phase is flipped to `validada`.
122
+ - Each added test is re-weighed at the closing review gate ([`../CODE-POLICIES.md`](../CODE-POLICIES.md) § *Closing review gate* → *Test-value lens*, tag `overtest`): over-testing is a **finding to fix or justify**, never an automatic rejection.
123
+ - Also run the plan's `## Validations` (cross-cutting rules and constraints) + the Final behavior block of `## Solution` (legacy plans: the `## Final behavior` section) + the spec's acceptance/success criteria (its `## Scenarios`, if present, are ready-made test cases: GIVEN=arrange · WHEN=act · THEN=assert).
124
+ - A validation that **runs and fails** → back into the phase (gap): no advancing, no `validada`.
125
+ - **Validation depending on an unapplied migration**: since the AI never executes the DML, it **cannot run it read-only** → the check is **deferred** (handoff to a DBA) and the phase **stays `bloqueada`**. A phase whose implementation is finished but whose operative proof cannot run does not become `validada`: the work may be complete and its boxes ticked, but the state waits until the proof runs and passes. The reason goes on its `> Bloqueo:` line, in `CHECKPOINT`, in the plan's `## Open questions` and in `BACKLOG`, marked "verification pending until the SQL is applied". (Reuses the chassis degrade/defer pattern + `MAX` cap → avoids the "back to the task" loop.)
80
126
 
81
- > The **final validation** is PLAN-exec's **convergence gate** = **`Success criteria` green** (*verification-first*; analogous to SPEC's *analyze gate* and plan-new's *coherence gate*): the plan is not marked *done* until it passes or is explicitly deferred (SQL handoff). For code these are **runnable tests** (TDD); for non-executable DB migrations, a **rubric** (SCRIPTS.sql valid + reviewed).
127
+ > The **final validation** is PLAN-exec's **convergence gate** = **`Success criteria` green** (*verification-first*; analogous to SPEC's *analyze gate* and plan-new's *coherence gate*): the plan is not marked *done* until it passes. A deferred check never counts as a passed one — it keeps its phase `bloqueada` and the plan open. For code these are **runnable tests** (TDD); for non-executable DB migrations, a **rubric** (SCRIPTS.sql valid + reviewed).
82
128
 
83
129
  ## Delta 5 — Closing review gate (conventions, pre-commit)
84
130
 
85
- Full gate in [`../CODE-POLICIES.md`](../CODE-POLICIES.md) (§ *Closing review gate*): **independent** diff re-read + installed ambient conventions; findings → fix (re-validating the phase) or defer justified. Here only the exec wiring: it runs **between the phase validation (Delta 4) and its commits (Delta 2)**; only with the gate green are the phase's commits proposed.
131
+ Full gate in [`../CODE-POLICIES.md`](../CODE-POLICIES.md) (§ *Closing review gate*): **independent** diff re-read + installed ambient conventions + the floor lenses (minimality, **test value**, **temporary simulation**, tooling); findings → fix (re-validating the phase) or defer justified. Here only the exec wiring: it runs over the phase's **whole** diff, **between the phase validation (Delta 4) and its commits (Delta 2)**; only with the gate green is the phase flipped to `validada` and its commits proposed.
86
132
 
87
133
  ## Delta 6 — Completion / close
88
134
 
89
- - A phase closes **done** when its tasks are `- [x]` and its validation passed **or** was deferred (SQL handoff). Possible state: **"done SQL pending application"**.
90
- - All phases done → final *structured-choice* (content: `Marcar plan done` / `Preguntar algo más`; flow: `Compactar`/`Cerrar`).
91
- - **Marking done = ONE line in the plan-doc**, under the title's blockquote: `> Estado: done — YYYY-MM-DD · sesión NNN` (or `done — SQL pendiente de aplicar`), updated in place on a re-run. No per-phase result tables, no ✅ suffixes — that record lives in the session (`DECISION`/`CHECKPOINT`).
135
+ - A phase closes when its `> Estado:` reads `validada`: work done, `Condición de salida` true, proof **run and passed**. A proof still waiting on an operative handoff leaves it `bloqueada`.
136
+ - **Every phase `validada` + the final validation passed** → final *structured-choice* (content: `Marcar plan done` / `Preguntar algo más`; flow: `Compactar`/`Cerrar`). `Marcar plan done` is offered under no other condition: one `bloqueada` phase keeps the plan open, however many of its tasks are ticked.
137
+ - **Marking done = ONE line in the plan-doc**, under the title's blockquote: `> Estado: done — YYYY-MM-DD · sesión NNN`, updated in place on a re-run. It never replaces the per-phase lines inside the `### Fn` blocks — position tells the two apart. No per-phase result tables, no ✅ suffixes — that record lives in the session (`DECISION`/`CHECKPOINT`).
92
138
  - **No automatic export**: the artifacts (`SCRIPTS.sql`, `DECISION`, …) stay in the session. Promoting them to `docs/` (scripts, manuals, …) is a separate step via `export-*`.
93
139
 
94
140
  ## Delta 7 — Probe (PoC) tasks
@@ -104,43 +150,58 @@ Chassis § *Proof of concept (probe)*, instantiated for execution — for a plan
104
150
  ```
105
151
  plan-exec-loop(PPP-plan-<slug>.md):
106
152
  session = create_or_resume("<slug>-plan-exec") # <slug> from the plan-doc; ONE session per run; CLI prepends global NNN; CHECKPOINT, resume
107
- plan = read(PPP-plan-<slug>.md)
153
+ plan = read(PPP-plan-<slug>.md, its spec, checkpoint)
154
+ entry gate (executability): result · exit condition · phase proof · simulation boundary if any · no structural contradiction
155
+ minor gap → structured-choice [Normalizar y ejecutar | Ir a plan-refine] → normalize in place + DECISION
156
+ structural gap → CHECKPOINT(blocker) → hand off to /w:plan-refine → stop
108
157
  for each Phase (### Fn block in ## Tasks; legacy: ## Phases table) in plan (in order, respecting deps):
109
- if Phase done (all its Tasks - [x] in the plan): skip # resume via plan-doc checkboxes
158
+ if Estado == validada: skip # legacy (no line): all its Tasks - [x] AND the session shows it closed
159
+ read Resultado + Condición de salida; confirm the initial state
160
+ set > Estado: en ejecución
110
161
  seed CHECKPOINT.Next = Phase N (Pending = its Tasks) # BEFORE starting the phase: seed the intent (artifact-first)
111
162
  for each Task of the Phase:
112
163
  if Task - [x] in the plan: skip # intra-phase resume by checkbox
113
164
  verify each source's expected branch (branch-check)
114
165
  on mismatch → pause + resolve with the human
115
- execute Task:
166
+ execute Task (micro steps internal — never plan entries):
116
167
  edit code in the sources (minimal change)
117
168
  if it creates a tool/utility → the ambient creating-tools skill documents it in docs/tools
118
169
  if read-only DB query → SCRIPTS.sql + execute read-only
119
170
  if DB change (DDL/DML) → draft in SCRIPTS.sql (session artifact, DO NOT execute)
120
- if non-obvious decision → DECISION (tagged by phase/task, in the SINGLE DECISION)
171
+ deviation gate:
172
+ local decision → resolve; DECISION only if non-obvious (tagged by phase/task)
173
+ structural deviation → CHECKPOINT(state + trigger) → stop → /w:plan-refine
174
+ functional change → CHECKPOINT(state + trigger) → stop → /w:spec-refine
121
175
  if probe (PoC) task / runnable doubt → seed check → run throwaway code in the
122
176
  session folder → verdict → CONCLUSIONS/DECISION; failed → structured-choice (Delta 7)
123
177
  if doubt/gap → inline research, probe OR structured-choice # chassis
124
- mark Task - [x] IN THE PLAN # AFTER completing the Task; checkbox flip ONLY — results go to DECISION/CHECKPOINT
125
- phase validation:
126
- what runs and fails → back to the task
127
- what depends on an unapplied migration → defer (Open questions + BACKLOG)
178
+ mark Task - [x] IN THE PLAN # AFTER its local work; checkbox flip ONLY — results go to DECISION/CHECKPOINT
179
+ phase proof (Validación de fase) + the justified focused tests: # Delta 4 levels 1→3
180
+ what runs and fails → back into the phase (no validada)
181
+ what cannot run (unapplied migration) → defer the CHECK, never the validation: the phase stays bloqueada
128
182
  closing review gate (pre-commit): # Delta 5: CHECKPOINT.Next = "review phase N"
129
- INDEPENDENT re-read of the phase diff + installed ambient conventions
183
+ INDEPENDENT re-read of the WHOLE phase diff + installed ambient conventions
184
+ + floor lenses: minimality · test value (overtest) · temporary simulation · tooling
130
185
  findings → fix (and re-validate the phase) OR defer justified (Open questions + BACKLOG)
131
- update CHECKPOINT (Completed += Phase N, Next = Phase N+1) # AFTER: Pending→Completed + Next = next phase (see artifact-first cycle)
186
+ confirm the Condición de salida set > Estado: validada # ONLY with the proof run and passed; NEVER from the checkboxes alone
187
+ blocker still live → set > Estado: bloqueada + > Bloqueo: <reason> + CHECKPOINT + Open questions
188
+ check not runnable (SQL) → set > Estado: bloqueada + > Bloqueo: <reason> + CHECKPOINT + Open questions + BACKLOG
189
+ update CHECKPOINT (functional state reached · simulation boundary if any · tests + result · decisions · deferrals · next state)
132
190
  propose commit(s) per source (approve first) # never push/amend/--no-verify; only after the gate is green
133
191
  if rejected → changes stay; record "phase uncommitted"
134
192
  next-phase precondition: working tree clean or acknowledged
135
- final validation (whatever can run; the SQL-dependent part stays as a handoff)
136
- structured_choice(content: [Marcar plan done, Preguntar algo más], flow: [Compactar, Cerrar])
137
- mark plan done ONE status line under the title blockquote (Delta 6), updated in place
193
+ final validation (whatever can run; a deferred check keeps its phase bloqueada)
194
+ if every phase validada AND the final validation passed:
195
+ structured_choice(content: [Marcar plan done, Preguntar algo más], flow: [Compactar, Cerrar])
196
+ mark plan done → ONE status line under the title blockquote (Delta 6), updated in place
197
+ else: the plan stays open → CHECKPOINT.Next = run the pending validation of the blocked phase(s)
138
198
  # NO export: artifacts stay in the session; a separate export-* promotes them
139
199
  finalize: CHECKPOINT (+ BACKLOG if something is deferred) + close session + report
140
200
  ```
141
201
 
142
202
  ## Convergence / exit
143
203
 
144
- - Plan complete + validation OK (or deferred with a handoff) + **every phase passed its closing review gate** before committing → `Marcar plan done`.
204
+ - **Every phase `validada`** + final validation **run and passed** + **every phase passed its closing review gate** before committing → `Marcar plan done`. A phase left `pendiente`, `en ejecución` or `bloqueada` keeps the plan open, whatever its checkboxes say — a proof waiting on an operative handoff (an unapplied migration) is exactly that case.
205
+ - A **structural deviation** or a **functional change** exits this loop without converging (§ *Deviation gate*): `CHECKPOINT` + `finalize`, and the work continues in `plan-refine` / `spec-refine`. Same exit when the entry gate finds a structural gap.
145
206
  - `Cerrar` (`flow` control, at any time) → `finalize` persists `CHECKPOINT` (and `BACKLOG` only if something remained unexecuted / uncommitted / unapplied), closes the session, reports.
146
207
  - Promoting artifacts to `docs/` (via `export-*`) is **always** a later, explicit step outside this loop.
@@ -3,7 +3,8 @@ name: plan-new-loop
3
3
  description: >-
4
4
  Generates a rich implementation plan (docs/plans/PPP-plan-<slug>.md) from a
5
5
  spec. Heir of the chassis (loops/CHASSIS.md). Deltas: the plan absorbs the
6
- TECHNICAL-NOTE level + phased Tasks (### Fn blocks) with live state,
6
+ TECHNICAL-NOTE level + Tasks phased by verifiable functional state
7
+ (### Fn blocks with live state),
7
8
  code/impact-mapping research, planning gap taxonomy, and per-screen design
8
9
  SPECs via ui-design
9
10
  when the plan includes UI. If the spec is not refined it suggests
@@ -25,7 +26,7 @@ PLAN
25
26
  `/w:plan-new` — **resumable** (same chassis mechanism, keyed off CHECKPOINT).
26
27
 
27
28
  ## Reads
28
- `docs/specs/NNN-spec-*.md` (glob — locates the spec by number; or the exact path from the command argument). **Refined vs draft** is distinguished by the **presence** of `## Refinement decisions` in the spec (legacy specs may also carry `## Q&A traceability`): if missing → **soft-suggest** running `/w:spec-refine` first (planning over a solid spec produces better plans), but the user may proceed.
29
+ `docs/specs/NNN-spec-*.md` (glob — locates the spec by number; or the exact path from the command argument). **Ready vs not** is read from the spec's frontmatter `status`: `ready-for-plan` proceed (legacy compat: a frontmatter-less spec carrying `## Refinement decisions`, or the older `## Q&A traceability`, counts as ready). Otherwise → **soft-suggest** running `/w:spec-refine` first (planning over a solid spec produces better plans), **never a block**: the user may proceed. Questions the spec left with destination `PLAN` are **input to this loop**, not a reason to send it back.
29
30
 
30
31
  ## Writes
31
32
  `docs/plans/PPP-plan-<slug>.md` (`generate`; **overwrites with confirmation** if it exists) — or **several sibling plans** when an accepted split applies (§ *Split gate (multi-plan)*). It writes only `docs/plans` — never other `docs/` folders, no auto-export. If the plan **includes UI**, it also produces **design SPECs** (`NNN-SPEC-<SLUG>.md`) as artifacts **of its session** (see *Delta 4* — they are not `docs/`, no auto-export).
@@ -62,10 +63,12 @@ The plan absorbs the `TECHNICAL-NOTE` level **inline** (user decision) + the roa
62
63
  aligned with the spec criteria. One narration, not four.
63
64
  ## Impacted FE · BE · DB (schemas/tables/functions) · APIs · integr. (core)
64
65
  ## Dependencies docs / sources / databases / sessions · inter-plan order on a split (opt.)
65
- ## Tasks (core) `### Fn — <name>` blocks 1-line objective +
66
- complexity XS–S — each holding its `- [ ] Tn.m` tasks
67
- (≤XS, deps and live state). The `### Fn` headers are the
68
- ONLY source of phases; there is no separate Phases table.
66
+ ## Tasks (core) `### Fn — <name>` blocks per the phase contract
67
+ below: each one a verifiable functional state with its
68
+ `> Estado:` line, its evidence and its `- [ ] Tn.m`
69
+ units of purpose never a list of layers or files.
70
+ The `### Fn` headers are the ONLY source of phases;
71
+ there is no separate Phases table.
69
72
  ## Validations validations / constraints / business logic (core)
70
73
  ## Risks / impact technical risks and impacts (opt.)
71
74
  ## Assumptions assumptions — only the delta over the spec, never re-imported (opt.)
@@ -76,6 +79,46 @@ The plan absorbs the `TECHNICAL-NOTE` level **inline** (user decision) + the roa
76
79
 
77
80
  > **Catalog implication:** `TECHNICAL-NOTE` stops being a session artifact and becomes **sections of the plan-doc**. Reconciled in [`plan-exec-loop`](../plan-exec-loop/LOOP.md): the single plan-exec session carries **no** `TECHNICAL-NOTE` nor its own `TASKS`; the technical detail and the progress live inline in the plan-doc (living).
78
81
 
82
+ ## Phase contract (canonical)
83
+
84
+ A `### Fn` block is a **verifiable state of the system**, never a list of layers, files or classes. It answers one question: *what can the system do or demonstrate at the end that it could not at the start?* The contract is defined **once** here — [`plan-refine-loop`](../plan-refine-loop/LOOP.md) and [`plan-exec-loop`](../plan-exec-loop/LOOP.md) reference it and never redefine it.
85
+
86
+ ```markdown
87
+ ### F1 — <result-oriented name>
88
+
89
+ > Estado: pendiente
90
+
91
+ **Resultado:** <the new verifiable state of the system>
92
+
93
+ **Recorrido afectado:** <consumer → components → current boundary>
94
+
95
+ **Trabajo:**
96
+ - [ ] T1.1 — <coherent unit of work>
97
+
98
+ **Límite de simulación:** antes <where it is> → después <where it lands, or removed>
99
+
100
+ **Validación de fase:** <the primary proof that the promised state was reached>
101
+
102
+ **Condición de salida:** <falsifiable result · contract preserved · simulation, if any, located or removed>
103
+
104
+ **Diferido:** <work consciously reserved for another phase>
105
+ ```
106
+
107
+ - **Always**: `Resultado` · `Trabajo` · `Validación de fase` · `Condición de salida`.
108
+ - **Conditional**: `Estado inicial` (when it is not obvious) · `Recorrido afectado` (distributed change) · `Límite de simulación` (temporary behavior exists) · `Diferido` · `Dependencias` (the phase cannot run in direct sequence).
109
+
110
+ **Phase state = machine state.** One `> Estado: <value>` line directly under the `### Fn` heading; vocabulary `pendiente` | `en ejecución` | `bloqueada` | `validada`, updated **in place**, never duplicated. It is what `aw status` counts (`phases_validated` / `phases_total`), **alongside — not instead of —** the checkbox progress. A phase reaches `validada` only when its work is done, its `Condición de salida` holds, its validation **ran and passed**, and the closing review gate passed. **Never** because all its checkboxes are ticked. *(Legacy plans carry no line at all: `aw status` reports them as zero phases — checkbox progress only. A missing line among stated blocks reads `pendiente`, and nothing is back-filled.)*
111
+
112
+ **The state line carries its value alone** — no comment, no suffix, no annotation; an annotated value reads as `pendiente`. A blocker's reason lives on its own `> Bloqueo: <reason>` line inside the block, and in `CHECKPOINT`, `## Open questions` and `BACKLOG`.
113
+
114
+ > Position disambiguates the two marks: the plan-level `> Estado: done — …` line lives under the title (plan-exec § *Delta 6*); the phase-level one lives inside its `### Fn` block.
115
+
116
+ **Granularity is semantic, not mechanical.** A phase earns its place when it leaves a demonstrable state, can be reviewed as a unit, and — when the change carries temporary behavior — moves or retires a simulation. A task is a **coherent unit of purpose** and may touch several files. Naming an edit operation — "create class X", "add method Y", "update the import" — describes a **micro step**: internal to execution, recorded in `CHECKPOINT` when a resume needs it, never a plan entry. `XS–S` stays an orientation of risk and scope; it never mandates splitting a semantic task into mechanical operations.
117
+
118
+ ## Incremental strategy (reference, never a template)
119
+
120
+ A change spread over consumer, service and data often lands well as: consumer shell → minimal real integration → vertical skeleton → real implementation from the source outwards → hardening → finish. **Reference to adapt, never a mandatory shape.** Backend-only, CLI, batch, library and database-only changes have their own journey, and inserting a layer the project does not have fails the minimality lens. A small change may be **one phase**, when that phase already is a coherent verifiable state.
121
+
79
122
  ## Delta 2 — Gap taxonomy (of "plan")
80
123
 
81
124
  Replaces the spec gap taxonomy with a planning-oriented one:
@@ -85,9 +128,13 @@ Replaces the spec gap taxonomy with a planning-oriented one:
85
128
  | Approach/Solution undefined | the how is vague | research / human |
86
129
  | Components unidentified | FE/BE/DB impact unknown | **research** (maps the code) |
87
130
  | AS-IS wiring unknown | current state unknown | **research** |
88
- | Phase too large | complexity > S | human (re-split) |
131
+ | Journey unmapped | the observable contract, the participating components or the repo/process boundaries are unknown — the phases cannot be ordered | **research** |
132
+ | Phase without a state | a `### Fn` mixes unrelated functional states, or nothing can be validated until the very end | the AI re-shapes it by state (**human** confirms an order change) |
89
133
  | Plan splittable | independently deliverable tranches — different moments/priorities, no shared deps/risk | **human consents** → split (see *Split gate (multi-plan)*) |
90
- | Task not atomic | complexity > XS | the AI re-splits |
134
+ | Task named as an edit | the name states an edit operation ("create class X", "add method Y") instead of a purpose | the AI re-states it by purpose |
135
+ | Structural micro-tasks | the plan enumerates files, classes or methods as entries | the AI groups them by purpose |
136
+ | Simulation without lifecycle | temporary behavior exists with no phase that displaces it and no phase that retires it | the AI derives both / **human** |
137
+ | Phase without evidence | the block declares no `Validación de fase` | the AI derives it from the criteria / **human** |
91
138
  | Over-engineered solution | approach heavier than the criteria need — needless abstraction/layer/dependency, or a phase/task not required to meet the spec (chassis § *Minimality*) | AI proposes the lighter path + **human** confirms (**probe** if "lighter works" is a runnable doubt) |
92
139
  | Missing deps | order unclear | research / human |
93
140
  | Spec criteria uncovered | tasks don't trace to acceptance criteria | the AI derives + human confirms |
@@ -132,8 +179,8 @@ Resolves the **Plan splittable** gap (Delta 2) — the canonical definition for
132
179
  ```
133
180
  plan-new-loop(spec):
134
181
  input = glob(docs/specs/NNN-spec-*.md) | argument path
135
- if the spec does NOT have ## Refinement decisions:
136
- soft-suggest /w:spec-refine (the user may proceed anyway)
182
+ if the spec is not status: ready-for-plan (nor a legacy mark):
183
+ soft-suggest /w:spec-refine # never blocks — the user may proceed anyway
137
184
  session = create_or_resume("<slug>-plan-new") # CLI prepends global NNN
138
185
  seed SESSION.Success criteria = coherence-gate checklist # verification-first, BEFORE
139
186
  work = plan skeleton (Delta 1) derived from the spec (+ checkpoint progress if resuming)
@@ -147,7 +194,11 @@ plan-new-loop(spec):
147
194
  - every spec acceptance criterion traces to a phase/task
148
195
  (split: each criterion → exactly one sibling — complete, disjoint partition)
149
196
  - the Final behavior block of ## Solution covers the criteria
150
- - ### Fn phases XS–S · tasks XS · deps without cycles · Impacted consistent with Solution
197
+ - every ### Fn leaves a verifiable state with its own exit condition never a list of layers or files
198
+ - the order allows early integration · deps without cycles · Impacted consistent with Solution
199
+ - the simulation boundary, ONLY when the change carries one, is located, its displacement planned, and one phase owns its retirement
200
+ - every phase declares its primary evidence; per-layer tests are justified, never automatic
201
+ - resumable: a stop between phases leaves a stable state and a legible next intent
151
202
  - minimality (chassis § *Minimality*): the Solution is the lightest that meets its Final behavior block; no phase/task/abstraction the criteria don't require
152
203
  - (UI) every screen/UI task traces to its design SPEC and does not contradict ## UI spec
153
204
  whatever fails → comes back as a gap
@@ -163,6 +214,7 @@ finalize: CHECKPOINT persisted (+ BACKLOG only if something is deferred) + close
163
214
  ## Convergence / exit
164
215
 
165
216
  - **No material gaps** → **coherence gate** (the *Sequence* checklist; the PLAN-new instance of the chassis convergence gate). Criterion→task traceability is a **checked invariant**, never a separate section.
217
+ - **The gate judges functional states, not size.** A plan converges when every `### Fn` is a verifiable state with its exit condition and its primary evidence — plus its simulation boundary located, **only when the change carries one**; a phase that only enumerates layers or files comes back as a gap, however small it is.
166
218
  - Passes → `Guardar plan` (writes with confirmation if it exists) → `finalize`.
167
219
  - **Split branch**: `Guardar planes` writes the N siblings sequentially (mint before each write) → `finalize` — one session, one HISTORY row.
168
220
  - `Cerrar` at any time → `finalize` (persists `CHECKPOINT`; `BACKLOG` only if something is deferred; closes the session, reports).
@@ -1,13 +1,14 @@
1
1
  ---
2
2
  name: plan-refine-loop
3
3
  description: >-
4
- Refines an existing plan (docs/plans/PPP-plan-<slug>.md) by editing it IN
5
- PLACE an auxiliary, NOT mandatory step before plan-exec. Heir of the
6
- chassis (loops/CHASSIS.md). Deltas: reuses plan-new-loop's gap taxonomy and
7
- coherence gate, adds Refinement decisions (trace, no gating), and
8
- produces/updates design SPECs via ui-design when the refine
9
- touches UI. Started by /w:plan-refine; resumable and re-runnable on demand.
10
- Invoke when an already generated plan must be adjusted before executing it.
4
+ Turns an existing plan (docs/plans/PPP-plan-<slug>.md) into an EXECUTABLE
5
+ sequence of functional states, editing it IN PLACE. Heir of the chassis
6
+ (loops/CHASSIS.md). Deltas: functional journey map, phases re-shaped by
7
+ verifiable state (contract in plan-new-loop), simulation lifecycle,
8
+ evidence by behavior, executability gate, replanning of partially executed
9
+ plans, and design SPECs via ui-design on UI changes. Started by
10
+ /w:plan-refine also the return path when plan-exec stops on a structural
11
+ deviation; resumable and re-runnable on demand.
11
12
  ---
12
13
 
13
14
  # plan-refine-loop
@@ -22,11 +23,19 @@ PLAN
22
23
  ## Layer
23
24
  2 — the AI runs it end to end.
24
25
 
26
+ ## Objective — an executable sequence of functional states
27
+
28
+ This loop turns a plan into a sequence of **verifiable states of the system**. Exit condition:
29
+
30
+ > `plan-exec` can implement every phase **without inventing** contracts, observable states, structural order, simulation boundary or exit evidence.
31
+
32
+ The phase contract is defined **once** in [`plan-new-loop`](../plan-new-loop/LOOP.md) § *Phase contract (canonical)* — this loop **applies** it and never redefines it: a `### Fn` block is a state the system reaches, with its `> Estado:` line, its work, its evidence and its exit condition.
33
+
25
34
  ## Auxiliary / NOT mandatory
26
- `plan-exec` runs **any** plan, refined or not — there is **no** gate requiring plan-refine. This loop exists to incorporate changes (new requirements, scope adjustments, deps/risks spotted on re-read) **before** executing, without regenerating the plan from scratch.
35
+ `plan-exec` runs **any** plan that is already executable, refined or not — there is **no** gate requiring plan-refine. This loop exists to incorporate changes (new requirements, scope adjustments, deps/risks spotted on re-read) **before** executing, and to give an unexecutable plan the shape its execution needs, without regenerating it from scratch.
27
36
 
28
37
  ## Started by
29
- `/w:plan-refine` — **resumable** (same chassis mechanism, keyed off CHECKPOINT) and **re-runnable on demand** (see *Compact / resume*).
38
+ `/w:plan-refine` — **resumable** (same chassis mechanism, keyed off CHECKPOINT) and **re-runnable on demand** (see *Compact / resume*). Second path: **the return from execution** — `plan-exec` derives here when its entry check finds a structural gap it cannot normalize, or when it stops mid-run on a structural deviation (§ *Replanning executed work*).
30
39
 
31
40
  ## Reads
32
41
  `docs/plans/PPP-plan-*.md` (glob — locates the plan by number; or the exact path from the command argument). **Always the plan itself**: this loop edits it in place; there is no separate "refined" file. Provenance is irrelevant — generated by `plan-new`, **hand-written, or adopted** from a host planner (`plan-new` mode 4 / `persist`); existence is the only requirement.
@@ -52,25 +61,27 @@ The plan uses the **same skeleton** [`plan-new-loop`](../plan-new-loop/LOOP.md)
52
61
 
53
62
  ```markdown
54
63
  ## Refinement decisions ← NEW (ADDED) — the run's single trace
55
- What was adjusted while refining and why (new requirements, scope changes,
56
- deps/risks). Includes what inline research resolved (ref to the session's
57
- CONCLUSIONS) and every doubt asked to the human, as entries
58
- `Q: <question> → <chosen answer> — <rationale>`.
64
+ MATERIAL changes only: contracts, journey, shape or order of the phases,
65
+ movement of the simulation boundary, risks that altered the plan, and work
66
+ already executed that conditions the replanning. A doubt that changed one of
67
+ those goes as `Q: <question> → <chosen answer> — <rationale>` (ref to the
68
+ session's CONCLUSIONS for what research resolved). A micro-decision, or a
69
+ question that changed nothing, is NOT transcribed.
59
70
  ```
60
71
 
61
72
  > **No gating contract** (unlike spec↔plan): the presence of `## Refinement decisions` in the plan is **audit trace only** — `plan-exec` neither requires nor checks it (it runs any plan). It serves to (a) distinguish a re-refined plan from a freshly generated one on resume, and (b) record what changed and why. *(Legacy plans may also carry `## Q&A traceability`; new runs never write it.)*
62
73
 
63
- > The plan **never mutates by execution** (plan-exec tracks that in the plan-doc's Tasks) only by a (re-)refine.
74
+ > **Execution updates progress; refinement changes structure.** `plan-exec` updates the plan's operational state in place — task checkboxes, the phase `> Estado:` line with its `> Bloqueo:` line while blocked, declared deferrals and the final plan status line. It does **not** redesign contracts, phase shape or order, participating components, evidence or simulation boundaries: those structural changes are this loop's, and a change of functional behavior belongs to `spec-refine`.
64
75
 
65
76
  ## Delta 2 — Gap taxonomy (of "plan")
66
77
 
67
- Reuses plan-new-loop's gap taxonomy **in full** ([`plan-new-loop`](../plan-new-loop/LOOP.md) § *Delta 2*): vague Approach/Solution, components unidentified, AS-IS wiring unknown, phase too large, task not atomic, missing deps, spec criteria uncovered, unaddressed risks, plan splittable, UI without design SPEC. **Focus difference:** plan-new **builds** the plan from scratch; plan-refine **detects what changed** against the written plan (or against the spec, if the spec was re-refined) and closes **those** gaps typically fewer and more localized. One extra re-refine gap:
78
+ Reuses plan-new-loop's gap taxonomy **in full** ([`plan-new-loop`](../plan-new-loop/LOOP.md) § *Delta 2*), semantic rows included: journey unmapped, phase without a state, task named as an edit, structural micro-tasks, simulation without lifecycle, phase without evidence, plus the shared ones (vague Approach/Solution, components unidentified, AS-IS wiring unknown, over-engineered solution, missing deps, spec criteria uncovered, unaddressed risks, splittable plan, UI without design SPEC). **Focus difference:** plan-new **builds** the plan from scratch; plan-refine re-shapes what is already written — what changed against the plan (or against the spec, if the spec was re-refined) and what still keeps the plan from being executable. One extra re-refine gap:
68
79
 
69
80
  | Gap | Signal | Resolved by |
70
81
  |---|---|---|
71
82
  | Plan↔spec drift | the spec was re-refined and the plan fell out of line | **research** (re-reads the spec) / **human** |
72
83
 
73
- > **Spec-less degradation (hand-written / adopted plans).** When the plan has **no source spec** (`## Origin` = adopted / hand-written), the spec-anchored checks **degrade gracefully**: "spec criteria uncovered" and "plan↔spec drift" do **not** apply — criterion→task traceability anchors to the plan's **own** Final behavior block (in `## Solution`) / `## Validations` instead. The rest of the taxonomy (atomicity, deps, Impacted↔Solution, UI→SPEC) applies unchanged. Normalizing an adopted plan to the full Delta 1 schema **is** this loop's job (missing `(core)` sections are gaps).
84
+ > **Spec-less degradation (hand-written / adopted plans).** When the plan has **no source spec** (`## Origin` = adopted / hand-written), the spec-anchored checks **degrade gracefully**: "spec criteria uncovered" and "plan↔spec drift" do **not** apply — criterion→task traceability anchors to the plan's **own** Final behavior block (in `## Solution`) / `## Validations` instead. The rest of the taxonomy (phase shape, simulation, evidence, deps, Impacted↔Solution, UI→SPEC) applies unchanged. Normalizing an adopted plan to the full Delta 1 schema **is** this loop's job (missing `(core)` sections are gaps).
74
85
 
75
86
  > **Adjust the Solution the laziest-that-works way** (chassis § *Minimality*, generative side): reuse what already exists before adding abstractions, layers or dependencies — the coherence gate only *confirms* minimality, and a re-refine is a chance to *remove* over-building, not add it.
76
87
 
@@ -82,6 +93,57 @@ Same as plan-new (maps code/impact: FE/BE/DB components, AS-IS wiring, deps), bu
82
93
 
83
94
  Same mechanism as [`plan-new-loop`](../plan-new-loop/LOOP.md) (§ *Delta 4*: the **`ui-design`** capability → per-screen `NNN-SPEC-<SLUG>.md`, see [`SPEC.md`](../../artifacts/artifacts-design/SPEC.md)), **scoped to the delta**: only the screens **new or changed** by the refine get a design SPEC. The updated SPEC is written in **plan-refine's own session** (each loop manages ITS session's artifacts — it never edits plan-new's) and the plan **re-points** the UI Task reference to the current SPEC. Untouched screens keep their original SPEC.
84
95
 
96
+ ## Functional journey map
97
+
98
+ Before re-shaping phases, the plan must answer what execution would otherwise have to invent. The answers land **inside the existing sections** (`## Solution`, `## Impacted`, the `### Fn` blocks) — this loop adds no plan section beyond its trace:
99
+
100
+ - **Observable contract** — who starts the operation, what inputs it provides, what successful result and what errors or states it observes, which contracts are created or changed, and what must stay compatible.
101
+ - **Technical journey** — participating components and their approximate order, boundaries between repos or processes, where persistence and external integrations sit, what already exists and what must be wired.
102
+ - **Incremental strategy** — the first demonstrable journey and, **only when the change carries temporary behavior**, where a safe simulation can live, how it is displaced and which phase retires it (reference shapes: [`plan-new-loop`](../plan-new-loop/LOOP.md) § *Incremental strategy*).
103
+ - **Evidence** — the primary proof of each phase, which rules deserve an isolated test, which integrations need a real one, and what cannot be validated because of operational constraints (that one goes to `## Open questions`).
104
+
105
+ > **Bounded research** (Delta 3, sharpened): investigate **only** what is needed to order the phases — journey, boundaries, existing contracts, where the simulation can live, risks that change the plan's design. What `plan-exec` resolves locally is **not** pre-investigated here.
106
+
107
+ ## Simulation lifecycle
108
+
109
+ **This section applies only when the journey introduces temporary behavior** — a stub, fake, in-memory adapter, controlled fixture or temporary response. None in the change → no `Límite de simulación`, and no artificial phase invented to retire one. When there is, it is planned, never improvised: every simulation declares **purpose · location · the contract it stands for · the phase where it appears · the phase where it moves or disappears · what prevents its accidental selection in a production runtime · the minimum proof needed while it exists**.
110
+
111
+ - **Explicit over hidden**: `Stub…` / `Fake…`, in-memory adapter, temporary provider or controlled fixture — never a hardcode buried inside production code.
112
+ - **Displacement rule**: each affected phase writes its `Límite de simulación` as normalized prose — `antes <where it is>` → `después <where it lands, or removed>` — never as an implicit assumption.
113
+ - **Removal gate**: the change is not complete while a main-path simulation stays active, a configuration can still select it, the plan does not explain why it remains, or its removal was never validated. Test doubles isolated from the production runtime may stay.
114
+
115
+ ## Evidence by behavior
116
+
117
+ Each phase carries proof of behavior, not of structure. Three levels, **chosen** — never descended automatically:
118
+
119
+ 1. **Primary phase proof** — demonstrates the state the phase promised: component interaction, endpoint smoke, a vertical run down to the stub, persistence integration, or the end-to-end happy path.
120
+ 2. **Focused proofs** — where a layer owns rules, a relevant transformation, error handling, persistence, transactions, temporal logic or an external integration.
121
+ 3. **Risk proofs** — security, concurrency, idempotency, retries, known regressions, plausible high-impact failures.
122
+
123
+ The primary proof lives **inside its `### Fn` block** (`Validación de fase`); `## Validations` keeps the cross-cutting rules and constraints. A simulation gets only the minimum proof that demonstrates the wiring — no suite is built around what the next phase retires.
124
+
125
+ > **Necessity gate** (design criterion, not a record to keep): what behavior does the test demonstrate, what unique failure would it catch, is that already demonstrated elsewhere, does it target a stable boundary or an internal detail, does the layer own logic or risk, is it still worth keeping once the simulation is gone? No clear answer → it is not planned. Whatever slips through and only mirrors structure is flagged `overtest` by execution's closing review gate.
126
+
127
+ ## Executability gate
128
+
129
+ This loop's instance of the chassis convergence gate — the same one `plan-exec` verifies on entry. Whatever fails comes back as a gap:
130
+
131
+ - **Contract** — relevant inputs, outputs and observable states identified; the final behavior matches the spec; no functional criterion invented here.
132
+ - **Journey** — main components identified, order reasonable, repo/process boundaries visible, the described architecture the one the project actually has.
133
+ - **Phases** — each leaves a verifiable state with its exit condition, none is a list of layers or files, the order allows early integration, deferrals are explicit.
134
+ - **Simulation** *(only when the change carries one)* — initial boundary identified, every displacement foreseen, one phase owns the retirement, nothing can stay active by accident. No temporary behavior → the check does not apply, and no empty `Límite de simulación` is required.
135
+ - **Evidence** — every phase declares its primary proof, per-layer tests are justified, the same scenario is not duplicated by default, declared risks have evidence or an explicit deferral.
136
+ - **Resumability** — tasks legible enough for a `CHECKPOINT`, intermediate states stable, pending work distinguishable from work already `validada`.
137
+
138
+ ## Replanning executed work
139
+
140
+ A partially executed plan is replanned **forward**, never rewritten backwards:
141
+
142
+ - Phases already `validada` **stay as they are**, and their result becomes the initial state of what follows. Completed tasks are not re-written as if they had never happened.
143
+ - Only pending work is re-designed. A `validada` phase that the new shape invalidates gets a **compensating correction** as a new phase — never a silent edit of the closed one.
144
+ - **Return from `plan-exec`** (structural deviation — [`plan-exec-loop`](../plan-exec-loop/LOOP.md) § *Deviation gate*): the deviation enters as a **material gap** of this run. Changed input or output, observable state, public contract, participating components, phase order, simulation boundary or integration strategy — all land in `## Refinement decisions` with what execution already proved.
145
+ - **Legacy plans** (no phase state, micro-task shape) are migrated to the phase contract when this round touches them: completed tasks preserved, micro-tasks grouped by purpose, results and exit conditions derived from the spec and from the plan itself. Functional evidence that neither backs is **not invented** — it becomes an `## Open questions` entry.
146
+
85
147
  ## Split gate — refine semantics
86
148
 
87
149
  The gate itself — signals, offer, anti-duplicate, sibling contract, partition — is defined **once** in [`plan-new-loop`](../plan-new-loop/LOOP.md) § *Split gate (multi-plan)* (this flow's guaranteed load already includes that file); this loop only adds the **in-place semantics** of splitting an existing plan:
@@ -103,8 +165,11 @@ Full mechanism (3 cases, `Compactar`, re-run with `--reopen`) in the chassis (§
103
165
  plan-refine-loop(plan):
104
166
  input = glob(docs/plans/PPP-plan-*.md) | argument path # always the plan itself (in place)
105
167
  session = create_or_resume("<slug>-plan-refine") # reopens if it exists (see Compact / resume)
106
- seed SESSION.Success criteria = coherence-gate checklist # verification-first, BEFORE
107
- work = read(plan) (+ the spec if realignment is needed; + checkpoint progress if resuming)
168
+ seed SESSION.Success criteria = executability-gate checklist # verification-first, BEFORE
169
+ work = read(plan) (+ the spec if realignment is needed; + checkpoint/exec history if resuming or returning from plan-exec)
170
+ journey = map(observable contract, technical journey, incremental strategy, evidence) # bounded research
171
+ work = phases grouped by verifiable state (phase contract) + simulation lifecycle if any + primary proof each
172
+ keep validated phases and their completed tasks; redesign ONLY pending work
108
173
  repeat: # chassis engine
109
174
  gaps = detect_gaps(work) (plan-new taxonomy + plan↔spec drift) minus the exhausted ones
110
175
  if gaps == ∅: break
@@ -112,8 +177,9 @@ plan-refine-loop(plan):
112
177
  research (scoped to the delta — Delta 3) · human (structured-choice) · probe (chassis) ·
113
178
  ui-design (Delta 4, only new/changed screens)
114
179
  integrate + update CHECKPOINT # artifact-first cycle
115
- coherence gate (read-only) = Success criteria green:
116
- - plan-new checklist (criterion→task · Final behavior block of Solution · XS–S/XS · deps · Impacted↔Solution · UI→current SPEC · minimality)
180
+ executability gate (read-only) = Success criteria green:
181
+ - contract · journey · phases · simulation · evidence · resumability Executability gate)
182
+ - plan-new checklist (criterion→task · Final behavior block of Solution · deps · Impacted↔Solution · UI→current SPEC · minimality)
117
183
  # spec-less plan (adopted/hand-written): criteria anchor to the plan's own Final behavior block/Validations (see Delta 2)
118
184
  - re-refine's own check: the plan is REALIGNED with what changed
119
185
  whatever fails → comes back as a gap
@@ -128,7 +194,9 @@ finalize: CHECKPOINT persisted (+ BACKLOG only if something is deferred) + close
128
194
 
129
195
  ## Convergence / exit
130
196
 
131
- - **No material gaps** → **coherence gate** (the *Sequence* checklist; plan-new's gate + the re-refine's own realignment check).
197
+ - **No material gaps** → **executability gate** (the *Sequence* checklist: contract · journey · phases · simulation · evidence · resumability, plus plan-new's coherence checks and the re-refine's own realignment check).
132
198
  - Passes → `Guardar plan refinado` (edits in place with confirmation) → `finalize`.
133
199
  - **Split branch**: `Guardar planes` edits the original reduced and writes the extracted siblings → `finalize`.
134
200
  - `Cerrar` at any time → `finalize` (persists `CHECKPOINT`; `BACKLOG` only if something is deferred; closes the session, reports).
201
+
202
+ > **After refining:** the plan goes to `plan-exec`, which re-checks this same gate on entry — a plan saved here should never bounce back for its structure.
@@ -58,7 +58,7 @@ Read **[`../CHASSIS.md`](../CHASSIS.md)** — the loop's **full engine** — **a
58
58
  - **`Recortar alcance`** → the AI proposes the **sub-task that DOES fit** a quick; the loop continues with it (`SESSION.Objective` = the sub-task; the original prompt goes into the session's `## Origin`) and the rest is deferred to `BACKLOG` ("trimmed at the gate — may warrant its own spec, `/w:spec-new`").
59
59
  - **Anti-duplicate** (the `create_or_resume` spirit): if a spec whose `## Origin` references this same objective already exists (or an equivalent `*-spec-refine` session), the recommended option becomes **resuming that spec** (`/w:spec-refine` semantics) — never a second draft.
60
60
  - **Live transition to SPEC** (shared by the gate and mid-loop escalation). On acceptance, the work line **moves to the SPEC flow**: the explicit consent in the structured-choice **equals invoking the destination command** (*consented exception* — rule 3 of the *Continuity rule*, [`../../SKILL.md`](../../SKILL.md) § *Operating context*). On the SPEC side:
61
- 1. **Materialize the draft** via the [`../../commands/spec-new.md`](../../commands/spec-new.md) procedure: `aw next-number docs/specs`, slug, schema, single-pass **NO RESEARCH**. `## Origin` = "escalated from `/w:quick`" + the original prompt (+ the origin quick session if it exists).
61
+ 1. **Materialize the draft** via the [`../../commands/spec-new.md`](../../commands/spec-new.md) procedure: `aw next-number docs/specs`, slug, schema, single-pass **NO RESEARCH** — its bounded reconnaissance does **not** re-fire (this run's context arrives adopted). `## Origin` = "escalated from `/w:quick`" + the original prompt (+ the origin quick session if it exists). The draft is born `status: draft`: only the SPEC gate promotes it to `ready-for-plan`.
62
62
  2. **Load and execute** [`../spec-refine-loop/LOOP.md`](../spec-refine-loop/LOOP.md) — over that spec (trampoline pattern).
63
63
  3. The run's session is that loop's **normal** `NNN-<slug>-spec-refine` (the CLI numbers it; its `## Origin` records the escalation). **Invariant 2 intact**: quick, while it is quick, never writes `docs/` — the draft is written by the SPEC flow, post-consent.
64
64
  - **Mid-loop escalation + handoff**: if the task grows (same gate signals) → propose moving up to **SPEC/PLAN** (structured-choice, recommendation first). If the user accepts: