refacil-sdd-ai 5.2.2 → 5.3.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 (76) hide show
  1. package/NOTICE.md +46 -0
  2. package/README.md +209 -42
  3. package/agents/auditor.md +46 -0
  4. package/agents/debugger.md +41 -1
  5. package/agents/implementer.md +76 -10
  6. package/agents/investigator.md +36 -0
  7. package/agents/proposer.md +46 -2
  8. package/agents/tester.md +45 -8
  9. package/agents/validator.md +67 -13
  10. package/bin/cli.js +428 -83
  11. package/bin/postinstall.js +20 -0
  12. package/lib/bus/broker.js +121 -3
  13. package/lib/bus/spawn.js +189 -121
  14. package/lib/check-review.js +102 -0
  15. package/lib/codegraph-telemetry.js +135 -0
  16. package/lib/codegraph.js +273 -0
  17. package/lib/commands/autopilot.js +120 -0
  18. package/lib/commands/bus.js +29 -36
  19. package/lib/commands/compact.js +185 -46
  20. package/lib/commands/read-spec.js +352 -0
  21. package/lib/commands/sdd.js +429 -44
  22. package/lib/compact-guidance.js +122 -77
  23. package/lib/config.js +136 -0
  24. package/lib/global-paths.js +56 -20
  25. package/lib/hooks.js +32 -4
  26. package/lib/ide-detection.js +1 -1
  27. package/lib/ignore-files.js +5 -1
  28. package/lib/installer.js +202 -19
  29. package/lib/kapso.js +241 -0
  30. package/lib/methodology-migration-pending.js +13 -0
  31. package/lib/open-browser.js +32 -0
  32. package/lib/opencode-migrate.js +148 -0
  33. package/lib/opencode-plugin/index.js +84 -104
  34. package/lib/opencode-plugin/rules.js +236 -0
  35. package/lib/project-root.js +154 -0
  36. package/lib/repo-ide-sync.js +5 -0
  37. package/lib/spec-reader/lang.js +72 -0
  38. package/lib/spec-reader/md-parser.js +299 -0
  39. package/lib/spec-reader/session.js +139 -0
  40. package/lib/spec-reader/ui/app.js +685 -0
  41. package/lib/spec-reader/ui/index.html +59 -0
  42. package/lib/spec-reader/ui/mixed-lang.js +200 -0
  43. package/lib/spec-reader/ui/model-cache.js +117 -0
  44. package/lib/spec-reader/ui/style.css +294 -0
  45. package/lib/spec-reader/ui/supertonic-helper.js +565 -0
  46. package/lib/spec-sync.js +258 -0
  47. package/lib/test-scope.js +713 -0
  48. package/lib/testing-policy-sync.js +14 -2
  49. package/package.json +6 -3
  50. package/skills/apply/SKILL.md +39 -64
  51. package/skills/archive/SKILL.md +74 -48
  52. package/skills/ask/SKILL.md +43 -8
  53. package/skills/autopilot/SKILL.md +476 -0
  54. package/skills/bug/SKILL.md +52 -53
  55. package/skills/explore/SKILL.md +48 -1
  56. package/skills/guide/SKILL.md +31 -13
  57. package/skills/inbox/SKILL.md +9 -0
  58. package/skills/join/SKILL.md +1 -1
  59. package/skills/prereqs/BUS-CROSS-REPO.md +33 -16
  60. package/skills/prereqs/METHODOLOGY-CONTRACT.md +96 -17
  61. package/skills/prereqs/SKILL.md +1 -1
  62. package/skills/propose/SKILL.md +74 -19
  63. package/skills/read-spec/SKILL.md +76 -0
  64. package/skills/reply/SKILL.md +42 -9
  65. package/skills/review/SKILL.md +63 -25
  66. package/skills/review/checklist.md +2 -2
  67. package/skills/say/SKILL.md +40 -4
  68. package/skills/setup/SKILL.md +59 -5
  69. package/skills/setup/troubleshooting.md +11 -3
  70. package/skills/stats/SKILL.md +157 -0
  71. package/skills/test/SKILL.md +35 -10
  72. package/skills/up-code/SKILL.md +20 -13
  73. package/skills/update/SKILL.md +32 -1
  74. package/skills/verify/SKILL.md +78 -41
  75. package/templates/compact-guidance.md +10 -0
  76. package/templates/methodology-guide.md +5 -0
@@ -0,0 +1,476 @@
1
+ ---
2
+ name: refacil:autopilot
3
+ description: Run the SDD implementation cycle autonomously after /refacil:propose was approved by the human — chains apply → test → verify → review → archive → up-code in a single invocation, and notifies the user via WhatsApp through Kapso when finished (success or failure). Use when the user says "autopilot", "ejecuta el resto del flujo", "termina solo", "modo autónomo", or indicates they will step away from the computer.
4
+ user-invocable: true
5
+ ---
6
+
7
+ # refacil:autopilot — Autonomous Implementation Pipeline
8
+
9
+ This skill is an **orchestrator wrapper** that runs the post-proposal SDD cycle without human intervention. It assumes the human has already executed `/refacil:propose` and approved the generated artifacts (proposal, design, specs, tasks). It chains the existing skills in order, respects the methodology contract and review gate, and notifies the outcome via WhatsApp through Kapso at the end.
10
+
11
+ **Prerequisites**:
12
+ - `sdd` profile from `refacil-prereqs/SKILL.md` + rules from `METHODOLOGY-CONTRACT.md`.
13
+ - Artifacts of the target change already generated and human-approved (i.e. `/refacil:propose` already ran).
14
+ - Credentials file `~/.refacil-sdd-ai/kapso.env` exists with:
15
+ - `KAPSO_API_KEY`
16
+ - `KAPSO_PHONE_NUMBER_ID`
17
+ - `NOTIFY_PHONE` (E.164 format, e.g. `+5731XXXXXXXX`)
18
+
19
+ ## When to invoke
20
+
21
+ Activate when:
22
+ - The user explicitly invokes `/refacil:autopilot [changeName]`.
23
+ - The user says variants like: "autopilot", "modo autónomo", "termina solo el flujo", "ejecuta el resto sin preguntarme", "me voy del PC, completa el SDD".
24
+
25
+ Do **NOT** activate when:
26
+ - The user has not yet run `/refacil:propose` for the target change.
27
+ - The user says "review the proposal" or asks anything still in the design phase.
28
+
29
+ ## Improvement passes — global rule
30
+
31
+ Each implementation phase below (`apply`, `test`, `review`) runs in **up to 2 passes**:
32
+
33
+ - **Pass 1**: execute the phase normally. After the underlying skill completes, ask the corresponding sub-agent to list **acceptable improvements** it identified but did not implement during pass 1 (refactors, missing edge-case tests, doc gaps, small quality wins). "Acceptable" means: within scope of the change, non-breaking, no new dependencies, no scope creep beyond the proposal.
34
+ - **Pass 2**: if pass 1 returned improvements, apply them all in a single pass.
35
+ - **Hard cap**: never run a 3rd pass on the same phase. If issues remain after pass 2, they are recorded as `warnings` in the notification payload and autopilot continues. If they are *blocking* (e.g., review still rejects, verify rounds exhausted), autopilot aborts and notifies failure.
36
+
37
+ `verify` is exempt from this loop — it already has 2 built-in autofix rounds (see METHODOLOGY-CONTRACT.md §3.1). Autopilot does NOT add a 3rd round on top.
38
+
39
+ After pass 2 of any phase, re-run `sdd status <changeName> --json` to ensure the state is still consistent (tasks pending count, artifacts intact) before moving to the next phase.
40
+
41
+ ## Flow
42
+
43
+ ### Step 0: Preflight validation (blocking)
44
+
45
+ Run `refacil-sdd-ai sdd list --json` to get active changes.
46
+
47
+ - If there are no active changes → stop and instruct the user to run `/refacil:propose` first. Do NOT notify Kapso (this is a usage error, not an autopilot run).
48
+ - If `$ARGUMENTS` provided a change name → use it.
49
+ - If there is a single active change and no `$ARGUMENTS` → use it.
50
+ - If there are multiple active changes and no `$ARGUMENTS` → stop and ask the user to specify which change. Autopilot requires unambiguous scope.
51
+
52
+ With the resolved `changeName`, run `refacil-sdd-ai sdd status <changeName> --json` and validate:
53
+
54
+ - `artifacts.proposal` AND `artifacts.design` AND `artifacts.tasks` AND `artifacts.specs` must all be `true`.
55
+ - `ready.forApply` must be `true`.
56
+ - Treat `ready.forApply` as the contract source of truth. It is `true` only with `proposal.md`, `design.md`, `tasks.md`, and valid non-empty specs from `specs.md` and/or recursive `specs/**/*.md`; empty `specs/` folders do not count. This is the same spec source set used by `sdd status`, `sync-spec`, test/verify criteria extraction, and archive.
57
+ - If validation fails, build `missingArtifacts` from every false value in `artifacts` and report the full list.
58
+
59
+ If any of the above fails → stop and instruct the user to complete `/refacil:propose` for `<changeName>`, including `Missing artifacts: <comma-separated list>`. Do NOT notify Kapso.
60
+
61
+ ### Step 0.5: Verify Kapso credentials (optional — guided)
62
+
63
+ **(a)** Attempt to read `~/.refacil-sdd-ai/kapso.env`. Parse all lines of the form `KEY=VALUE`.
64
+
65
+ **(b)** Check that `KAPSO_API_KEY`, `KAPSO_PHONE_NUMBER_ID`, and `NOTIFY_PHONE` are all present and non-empty. If all three are present → set `kapsoEnabled = true` and continue to Step 0.6.
66
+
67
+ **(c)** If the file is absent or any of the three keys is missing or empty → `kapsoEnabled = false`. Ask the user (in the session language):
68
+
69
+ > Kapso credentials not found or incomplete in `~/.refacil-sdd-ai/kapso.env`. Do you want to configure it now to receive a WhatsApp notification when the pipeline finishes?
70
+ >
71
+ > - Run `refacil-sdd-ai kapso setup` in another terminal and reply **done** when finished.
72
+ > - Reply **no** to continue without notification.
73
+
74
+ Wait for the user's reply:
75
+
76
+ - If the user replies **done** / **listo** / **ok** / **yes** (case-insensitive) → re-read `~/.refacil-sdd-ai/kapso.env` and re-check. If now complete → `kapsoEnabled = true`. If still incomplete → inform the user and set `kapsoEnabled = false`, continue.
77
+ - If the user replies **no** (or any other input) → set `kapsoEnabled = false` and continue.
78
+
79
+ **(d)** Continue the pipeline regardless of `kapsoEnabled`. Kapso is optional — a missing or misconfigured credential must never block the SDD pipeline.
80
+
81
+ ### Step 0.6: Pre-flight user input (single interaction — gather all before starting)
82
+
83
+ **Resume detection**: before anything else, try to read `refacil-sdd/.autopilot-active`. If the file exists and its `changeName` matches the resolved `changeName` from Step 0, the pre-flight was already completed in a prior session — skip this entire step (Steps 0.6 Case A and B) and go directly to Step 0.7. The marker already contains `taskReference`, `createPR`, `baseBranch`, and `includeUpCode` (fallback to `true` if the field is missing from an older marker).
84
+
85
+ All user input needed for the full pipeline must be collected here, in **one message and one reply**. This step only collects configuration — the pipeline does not start until the user sends an explicit affirmative after the ready message.
86
+
87
+ Run in parallel:
88
+ - `git branch --show-current` → `currentBranch`
89
+ - `git status --porcelain` → detect uncommitted changes
90
+ - `refacil-sdd-ai sdd config --json` → `baseBranch`, `protectedBranches`
91
+
92
+ **IDE detection**: Before presenting the pre-flight message, determine which IDE is running this session from the available context (system prompt, environment variables, CLI invocation style). Apply the following mapping:
93
+
94
+ | Signal | `detectedIDE` |
95
+ |---|---|
96
+ | System prompt contains "Claude Code" / `claude` CLI context | `claude-code` |
97
+ | Cursor-specific context / agent header | `cursor` |
98
+ | Codex CLI context | `codex` |
99
+ | OpenCode CLI context | `opencode` |
100
+ | Cannot determine | `unknown` |
101
+
102
+ Also detect the OS from session context:
103
+ - Windows (PowerShell / cmd environment) → `detectedOS = "windows"`
104
+ - macOS / Linux / WSL → `detectedOS = "unix"`
105
+ - Unknown → `detectedOS = "unknown"`
106
+
107
+ On **Windows**: just open a new terminal and run the command directly — no wrapper needed. Leave that terminal open while the pipeline runs.
108
+ On **Unix**: wrap with `nohup ... >> log 2>&1 &` so the process survives after closing the terminal.
109
+
110
+ Map `detectedIDE` + `detectedOS` → `idePermissionInstruction` (shown literally in the pre-flight message).
111
+
112
+ Generate `idePermissionInstruction` in the **session language** using the template below (command lines stay literal). The instruction always opens the IDE **interactively** with the auto-permissions flag — the user sees output in real time and types `/refacil:autopilot` to start. No `-p` / non-interactive mode.
113
+
114
+ **`claude-code`**: Tell the user that avoiding permission prompts requires a new session. Instruct them to: close this session → open a new terminal → `cd` to the project → run `claude --dangerously-skip-permissions` → once Claude opens, type `/refacil:autopilot`.
115
+
116
+ **`cursor`**: Set `idePermissionInstruction = ""` (empty — Cursor runs autopilot in the current session; no need to open another session). Do NOT include any instruction to open a new session. Case A and Case B proceed normally.
117
+
118
+ **`codex`**: Tell the user that skipping permission prompts requires a new session. Instruct them to: close this session → open a new terminal → `cd` to the project → run `codex --dangerously-bypass-approvals-and-sandbox` → once Codex opens, type `/refacil:autopilot`.
119
+
120
+ **`opencode`**: Tell the user that skipping permission prompts requires a new session. Instruct them to: close this session → open a new terminal → `cd` to the project → run `opencode --dangerously-skip-permissions` → once open, type `/refacil:autopilot`.
121
+
122
+ **`unknown`**: Tell the user their IDE could not be detected. Show the open command for each IDE and instruct them to type `/refacil:autopilot` once it opens:
123
+ - Claude Code: `claude --dangerously-skip-permissions`
124
+ - Cursor: open Cursor in this repo, confirm in chat, then `/refacil:autopilot` (no headless launcher)
125
+ - Codex: `codex --dangerously-bypass-approvals-and-sandbox`
126
+ - OpenCode: `opencode --dangerously-skip-permissions`
127
+
128
+ **Kapso pre-flight (`kapsoEnabled = true` only)** — run once per session to surface the 24h window notice. Before presenting the ready message, check whether `kapsoPreflightShown` has already been set in this session:
129
+
130
+ - If `kapsoPreflightShown` is **not yet set** → run `refacil-sdd-ai kapso preflight` (exits 0, prints JSON). Parse `preflightMessage` from the output and include it in the ready message below. Then set `kapsoPreflightShown = true` so the block is not repeated if autopilot is re-invoked later in the same session.
131
+ - If `kapsoPreflightShown` is **already set** → omit the pre-flight block from the ready message (the user already saw it).
132
+ - Do **NOT** block or wait for confirmation of the WhatsApp notice — informational only.
133
+ - If `kapsoEnabled = false`, skip this sub-step entirely and omit the block.
134
+
135
+ **Case A — `currentBranch` is in `protectedBranches`:**
136
+
137
+ Present ONE data-collection message **in the session language** covering these three points (no permissions question here). This message only collects configuration; answering it does **not** start the pipeline.
138
+
139
+ 1. **Working branch** — will create `feature/<changeName>` from `<baseBranch>`. Ask if they have a ticket/ID (e.g. PROJ-123) to use as the branch suffix, or reply "ok" to use the change name.
140
+ 2. **Task reference** — URL, ticket, or short name for the final archive record (e.g. `https://tracker.co/PROJ-123`). If same as ticket in point 1, no need to repeat.
141
+ 3. **Up-code and PR at the end?** — three options (default: include up-code and create PR):
142
+ - Reply "sin up-code", "no up-code", "sin push", "no push", "skip up-code", or "omitir up-code" → `includeUpCode = false`, `createPR = false` (cycle ends after archive)
143
+ - Reply "sin PR", "no PR", "solo push", or "without pr" → `includeUpCode = true`, `createPR = false` (push but no PR)
144
+ - Any other reply / no signal → `includeUpCode = true`, `createPR = true` (default: push + PR)
145
+
146
+ If there are uncommitted changes, add a note that they will be stashed before branch creation and restored after.
147
+
148
+ Wait for the user's reply. Parse:
149
+ - URL (`http://` or `https://`) found → `taskReference = <url>`, `branchSuffix = <changeName>` (unless a ticket was also given)
150
+ - Ticket/ID (`[A-Za-z][A-Za-z0-9_-]*-\d+`, e.g. `PROJ-123`) found → `branchSuffix = <ticket>`, `taskReference = <ticket>` (overridden by URL if both present)
151
+ - "sin up-code" / "no up-code" / "sin push" / "no push" / "skip up-code" / "omitir up-code" found (case-insensitive) → `includeUpCode = false`, `createPR = false`
152
+ - "sin PR" / "no PR" / "solo push" / "sin pr" / "without pr" found (case-insensitive, only when no up-code skip signal) → `includeUpCode = true`, `createPR = false`
153
+ - No signal → `includeUpCode = true`, `createPR = true` (default)
154
+ - "ok" or bare affirmative with no recognizable data → `branchSuffix = <changeName>`, `taskReference = refacil-sdd-autopilot/<changeName>` (synthetic — annotated in the final notification)
155
+
156
+ Then create the branch (do NOT ask again):
157
+ 1. If uncommitted changes → `git stash push -m "auto-stash-refacil"`.
158
+ 2. `git checkout <baseBranch> && git pull origin <baseBranch>`.
159
+ 3. `git checkout -b feature/<branchSuffix>`.
160
+ 4. If stash was pushed → `git stash pop`.
161
+
162
+ Write the autopilot marker so sub-skills can detect autonomous mode and skip their own confirmation prompts:
163
+
164
+ ```bash
165
+ printf '{"changeName":"%s","taskReference":"%s","createPR":%s,"baseBranch":"%s","includeUpCode":%s}\n' \
166
+ "<changeName>" "<taskReference>" "<true|false>" "<baseBranch>" "<true|false>" \
167
+ > "refacil-sdd/.autopilot-active"
168
+ ```
169
+
170
+ **After writing the marker**, generate and present the ready message using the CLI:
171
+
172
+ ```bash
173
+ refacil-sdd-ai autopilot ready-message --change "<changeName>" --ide "<detectedIDE>" --lang "<sessionLang>"
174
+ ```
175
+
176
+ Where `<sessionLang>` is `es` (default) or `en` based on the session language. This command prints the localized ready message to stdout. Present its output to the user, prepending the Kapso pre-flight block if `kapsoEnabled = true` and `kapsoPreflightShown` is not yet set (see above). When `detectedIDE = cursor`, `idePermissionInstruction` is empty — do NOT append any instruction to open a new session or use `cursor-agent`; the pipeline runs in this Cursor session. For all other IDEs, append the `idePermissionInstruction` after the CLI output. The ready message must not imply that the pipeline starts as soon as the user answers the pre-flight questions — it starts only after the user sends an explicit affirmative below. Replace any mention of "you can step away from your PC" / "puedes alejarte del PC" with neutral text indicating that the pipeline runs autonomously once started and the user can continue other activities.
177
+
178
+ **EXPLICIT CONFIRMATION GATE — STOP AND WAIT**: after displaying the ready message, do NOT continue automatically. Wait for the user to reply with an explicit affirmative:
179
+ - Affirmative ("go", "ok", "start", "yes", "sí", "dale", "arrancar", etc.) → continue to Step 0.7 in this session.
180
+ - No reply / session closed → the next session launched with the headless command will pick up via resume detection at the top of Step 0.6.
181
+ - Non-affirmative in-session reply (e.g. "no", "cancel", any other response) → do NOT start the pipeline; re-display the ready message and instruct the user to reply with an affirmative (go, ok, start, sí, dale, arrancar) when ready.
182
+
183
+ **Case B — `currentBranch` is already a working branch (not protected):**
184
+
185
+ Only ask for task reference and up-code/PR preference (branch creation is skipped). Present the message **in the session language** covering these two points. This message only collects configuration; answering it does **not** start the pipeline.
186
+
187
+ 1. **Task reference** — URL, ticket, or short name for the final archive record.
188
+ 2. **Up-code and PR at the end?** — three options (default: include up-code and create PR):
189
+ - Reply "sin up-code", "no up-code", "sin push", "no push", "skip up-code", or "omitir up-code" → `includeUpCode = false`, `createPR = false` (cycle ends after archive)
190
+ - Reply "sin PR", "no PR", "solo push", or "without pr" → `includeUpCode = true`, `createPR = false` (push but no PR)
191
+ - Any other reply / no signal → `includeUpCode = true`, `createPR = true` (default: push + PR)
192
+
193
+ Parse the reply — **branch creation is skipped in Case B, so do NOT derive `branchSuffix`**:
194
+ - URL (`http://` or `https://`) found → `taskReference = <url>`
195
+ - Ticket/ID (`[A-Za-z][A-Za-z0-9_-]*-\d+`, e.g. `PROJ-123`) found **only if not embedded inside a URL** → `taskReference = <ticket>`; if a ticket is embedded inside a URL, `taskReference = <full url>` (do not extract the ticket as a standalone value)
196
+ - "sin up-code" / "no up-code" / "sin push" / "no push" / "skip up-code" / "omitir up-code" found (case-insensitive) → `includeUpCode = false`, `createPR = false`
197
+ - "sin PR" / "no PR" / "solo push" / "sin pr" / "without pr" found (case-insensitive, only when no up-code skip signal) → `includeUpCode = true`, `createPR = false`
198
+ - No signal → `includeUpCode = true`, `createPR = true` (default)
199
+ - Unrecognizable → `taskReference = refacil-sdd-autopilot/<changeName>` (synthetic), `includeUpCode = true`, `createPR = true`
200
+
201
+ After writing the marker, generate and present the ready message using `refacil-sdd-ai autopilot ready-message --change "<changeName>" --ide "<detectedIDE>" --lang "<sessionLang>"` (same as Case A), prepend the Kapso pre-flight block if applicable, and apply the **EXPLICIT CONFIRMATION GATE** — wait for the user's affirmative reply before continuing to Step 0.7. The ready message must not imply that answering the pre-flight questions starts the flow; it must not say "you can step away from your PC" / "puedes alejarte del PC" — replace with neutral text indicating the pipeline runs autonomously once started and the user can continue other activities.
202
+
203
+ Write the autopilot marker (same as Case A):
204
+
205
+ ```bash
206
+ printf '{"changeName":"%s","taskReference":"%s","createPR":%s,"baseBranch":"%s","includeUpCode":%s}\n' \
207
+ "<changeName>" "<taskReference>" "<true|false>" "<baseBranch>" "<true|false>" \
208
+ > "refacil-sdd/.autopilot-active"
209
+ ```
210
+
211
+ Store `taskReference`, `createPR`, and `includeUpCode` for Steps 5 and 5.5.
212
+
213
+ ### Step 0.7: Capture starting state
214
+
215
+ Capture for the final notification payload:
216
+ - `repoSlug`: derived from `git remote get-url origin` (basename without `.git`).
217
+ - `branchAtStart`: `git branch --show-current`.
218
+ - `startedAt`: ISO-8601 timestamp (`new Date().toISOString()`).
219
+ - `changeName`: from Step 0.
220
+
221
+ **Immediately write `startedAt` into the marker** so the CLI can compute the exact duration when notifying — the AI must not compute elapsed time itself. Because this update uses `JSON.parse` + `JSON.stringify` on the existing object, all fields already in the marker (`changeName`, `taskReference`, `createPR`, `baseBranch`, `includeUpCode`) are preserved automatically:
222
+
223
+ ```bash
224
+ node -e "
225
+ const fs=require('fs');
226
+ const p='refacil-sdd/.autopilot-active';
227
+ const m=JSON.parse(fs.readFileSync(p,'utf8'));
228
+ m.startedAt=new Date().toISOString();
229
+ fs.writeFileSync(p,JSON.stringify(m));
230
+ "
231
+ ```
232
+
233
+ Initialize accumulators (used across phases):
234
+ - `improvementsApplied`: `{ apply: 0, test: 0, review: 0 }` — counters incremented when a phase's pass 2 successfully applies improvements.
235
+ - `warnings`: `[]` — list of strings, max 10 entries. Each entry is a short string like `"apply pass 2 reverted: 3 tests broke"` or `"test pass 2 skipped: improvement list empty"` (only the actionable ones, no need to log empty skips). Use this to fill the "Warnings" block in the success notification.
236
+ - `kapsoPreflightShown`: `false` — set to `true` in Step 0.6 after the pre-flight block is shown. Prevents repeating the WhatsApp window notice if autopilot is re-invoked later in the same session.
237
+
238
+ ### Step 1: Run /refacil:apply (up to 2 passes)
239
+
240
+ **Autonomous mode**: the branch was already created in Step 0.6, so apply starts directly on the working branch (no gate interruption). When invoking `/refacil:apply`, include a prompt-level note that the sub-agent is running in autonomous mode — it must make decisions without asking clarifying questions. If apply's flow-continuity question ("continue with /refacil:test?") appears, answer it internally (yes); do NOT surface it to the user.
241
+
242
+ **Pass 1**: invoke `/refacil:apply <changeName>` in the current session. This delegates to the `refacil-implementer` sub-agent and implements all tasks.
243
+
244
+ After it finishes, run `refacil-sdd-ai sdd status <changeName> --json` and verify:
245
+ - `tasks.pending` is `0`.
246
+ - `tasks.done` equals `tasks.total`.
247
+
248
+ If pending tasks remain → treat as `phase: apply` failure, go to Step 6.
249
+
250
+ **Pass 2 (improvement pass — only if pass 1 succeeded)**: ask the implementer for a list of acceptable improvements it identified but did not apply (refactors, small quality wins, minor cleanups strictly within the change scope). If the list is non-empty, invoke `/refacil:apply <changeName>` with a prompt-level instruction (not a CLI flag) telling the sub-agent to apply ONLY those listed improvements without expanding scope.
251
+
252
+ After pass 2:
253
+ - If pass 2 introduces test failures or breaks anything that pass 1 left working → abort the autopilot run, preserve the working tree exactly as-is, capture the failing command/output as evidence, and go to Step 6. Do not attempt destructive rollback or history rewrites. Record this as a failure, not a warning.
254
+ - If pass 2 succeeds cleanly → continue to Step 2.
255
+ - If the improvement list was empty → skip pass 2 entirely, continue to Step 2.
256
+
257
+ **No pass 3.** Any further improvements identified in pass 2 are recorded as warnings in the final payload.
258
+
259
+ ### Step 2: Run /refacil:test (up to 2 passes)
260
+
261
+ **Autonomous mode**: the tester sub-agent must make decisions (stack detection, test patterns) without asking. If test's flow-continuity question ("continue with /refacil:verify?") appears after passing, answer it internally (yes); do NOT surface it to the user.
262
+
263
+ **Pass 1**: invoke `/refacil:test <changeName>`. Defaults are `testScope: scoped`, `runCoverage: true` (narrowed to changed files) as per the methodology contract §3.1 — autopilot does NOT override these defaults.
264
+
265
+ If tests fail, `/refacil:test` handles the fix loop internally (up to 3 rounds) without asking the user. If it still cannot produce passing tests after those rounds, it returns a phase failure — autopilot goes to Step 6 (which notifies via Kapso if `kapsoEnabled = true`). Do NOT ask the user at any point.
266
+
267
+ **Pass 2 (improvement pass — only if pass 1 succeeded)**: ask the tester for a list of acceptable additional tests it identified but did not write (edge cases, branch coverage gaps, missing negative paths). If non-empty, invoke `/refacil:test <changeName>` with a prompt-level instruction (not a CLI flag) to add only those tests. The improvements must:
268
+ - Cover behavior already specified in the proposal (no new behavior).
269
+ - Not require changes to source code.
270
+
271
+ After pass 2:
272
+ - If the new tests pass → continue to Step 3.
273
+ - If any new test fails after addition → abort the autopilot run, preserve the working tree exactly as-is, capture the failing test output as evidence, and go to Step 6. Do not roll back with destructive git commands.
274
+ - If the improvement list was empty → skip pass 2 entirely, continue to Step 3.
275
+
276
+ **No pass 3.**
277
+
278
+ ### Step 3: Run /refacil:verify (built-in 2 rounds — no extra pass)
279
+
280
+ **Autonomous mode**: if verify asks "do you want me to apply these corrections?", answer yes internally — do NOT surface it to the user. If verify's flow-continuity question ("continue with /refacil:review?") appears after APPROVED, answer yes internally.
281
+
282
+ Invoke `/refacil:verify <changeName>` **without** tokens that force `testExecution: full`. After a successful Step 2 (`/refacil:test`), verify must use **`testExecution: none`** by default (§3.2) — CA/CR validation only, trusting `memory.commandsRun`.
283
+
284
+ The validator sub-agent supports up to 2 autofix rounds and always attempts to fix any findings (CRITICAL, WARNING, or observations) before returning. Autopilot answers "yes, apply corrections" internally for every round — do NOT surface it to the user.
285
+
286
+ After the built-in rounds:
287
+ - If APPROVED with no remaining issues → continue to Step 4.
288
+ - If APPROVED with remaining warnings/observations (non-blocking) → record them as `warnings` in the final payload and continue to Step 4.
289
+ - If REQUIRES_CORRECTIONS with unresolved issues after 2 rounds → treat as `phase: verify` failure, go to Step 6. Save the validator's top 3 issues for the WhatsApp payload.
290
+
291
+ Do NOT add a third manual round beyond the validator's built-in 2.
292
+
293
+ ### Step 4: Run /refacil:review (up to 2 passes)
294
+
295
+ **Autonomous mode**: if review asks "do you want me to apply these corrections?", answer yes/all internally for auto-fixable findings — do NOT surface it to the user. If review's flow-continuity question ("continue with /refacil:archive?") appears after APROBADO, answer yes internally.
296
+
297
+ **Pass 1**: invoke `/refacil:review <changeName>`. The auditor sub-agent evaluates against the quality checklist. After invocation, verify `.review-passed` exists in `refacil-sdd/changes/<changeName>/` (remember §8 of METHODOLOGY-CONTRACT.md: do not conclude from `ls` without `-a`).
298
+
299
+ **Pass 2 (always run if there are ANY findings — including MEDIUM/LOW observations from APROBADO CON OBSERVACIONES)**: regardless of whether pass 1 returned APROBADO CON OBSERVACIONES or REQUIERE CORRECCIONES, if the auditor reported any findings, run pass 2. Categorize each finding:
300
+ - **Auto-fixable** (formatting, naming, missing docstring, small refactor strictly within change scope, no test impact) — including MEDIUM/LOW observations.
301
+ - **Pre-existing debt** (flagged as pre-existing by the auditor) — skip, do not fix.
302
+ - **Requires human judgment** (architectural concern, scope question, business logic doubt) — do not fix, record as warning.
303
+
304
+ Apply all auto-fixable findings in a single batch, then re-invoke `/refacil:review <changeName>`.
305
+
306
+ After pass 2:
307
+ - If verdict is APROBADO or APROBADO CON OBSERVACIONES → `.review-passed` exists → continue to Step 5. Any remaining non-fixable or pre-existing findings are recorded as `warnings` in the final payload.
308
+ - If verdict is still REQUIERE CORRECCIONES after pass 2 → treat as `phase: review` failure, go to Step 6. Do NOT attempt a 3rd pass.
309
+ - If pass 1 had NO findings at all (clean APROBADO) → skip pass 2 entirely, continue to Step 5.
310
+
311
+ ### Step 5: Run /refacil:archive
312
+
313
+ **Autonomous mode**: answer archive's pre-check interactive prompts internally without asking the user:
314
+ - "Tasks complete?" → yes (apply ensured 0 pending).
315
+ - "Unrelated files in working tree?" → continue anyway (expected in multi-change repos).
316
+ - "Task reference?" → respond with `taskReference` captured in Step 0.6; do NOT ask the user again.
317
+ - Archive's flow-continuity question ("continue with /refacil:up-code?") → answer yes internally.
318
+
319
+ If any pre-check reveals a genuinely blocking issue (e.g., `.review-passed` missing) → treat as `phase: archive` failure, go to Step 6.
320
+
321
+ If `taskReference` is the synthetic fallback (`refacil-sdd-autopilot/<changeName>`), annotate this in the final WhatsApp notification so the user knows to update `review.yaml` with the real reference when they return.
322
+
323
+ If `/refacil:archive` fails for any other reason → `phase: archive` failure, go to Step 6.
324
+
325
+ ### Step 5.5: Run /refacil:up-code
326
+
327
+ **Read `includeUpCode` from the marker** (`refacil-sdd/.autopilot-active`). If the field is missing (older marker), treat it as `true`.
328
+
329
+ **If `includeUpCode = false`**: skip `/refacil:up-code` entirely. Assign `prLink = "skipped"`. Log: `"up-code omitido por elección del usuario (includeUpCode=false)"`. Go directly to Step 7 — do NOT skip Steps 7 or 8.
330
+
331
+ **If `includeUpCode = true`**: invoke `/refacil:up-code` with a commit message derived from the proposal title.
332
+
333
+ **Autonomous mode** — pre-resolve all up-code interactive prompts internally:
334
+
335
+ - **Staging**: confirm "yes, stage all" internally. Safe because implementation just happened in this session and the diff is bounded by the change. Do NOT ask the user.
336
+ - **Commit message**: generate from the proposal title (e.g. `feat: <proposal title>`). Do NOT ask for approval.
337
+ - **Target branch**: use `baseBranch` from `refacil-sdd-ai sdd config --json`. Do NOT ask the user.
338
+ - **PR creation**: depends on `createPR` from Step 0.6:
339
+ - `createPR = true` (default) → create the PR against `baseBranch`. Capture the PR link for the notification payload.
340
+ - `createPR = false` → push only. Do NOT create a PR. Record `prLink = null` in the payload; the notification will show "Push: ✓ (sin PR)".
341
+
342
+ If push fails → `phase: up-code` failure, go to Step 6.
343
+
344
+ Steps 7 and 8 always execute after this step, regardless of whether `includeUpCode` is `true` or `false`.
345
+
346
+ ### Step 6: Failure handling (any phase)
347
+
348
+ When any phase fails:
349
+
350
+ 1. Do NOT continue to subsequent phases.
351
+ 2. Do NOT force-push or rewrite history.
352
+ 3. Capture:
353
+ - `phase`: which step failed.
354
+ - `errorSummary`: 1-3 line summary.
355
+ - `branchAtFailure`: `git branch --show-current`.
356
+ - `lastCommit`: `git log -1 --oneline`.
357
+ 4. Delete the autopilot marker: `rm -f "refacil-sdd/.autopilot-active"`.
358
+ 5. Send the failure notification via Kapso only if `kapsoEnabled = true` (Step 7, failure template).
359
+ 6. Leave the working tree as-is so the user can inspect when they return. Normal recovery must never use destructive reset commands; preserve local edits and report the evidence needed for manual repair.
360
+
361
+ ### Step 7: Notify via Kapso
362
+
363
+ **This step always executes at the end of the cycle**, regardless of whether `includeUpCode` is `true` or `false`. Execute the notification only if `kapsoEnabled = true`. If `kapsoEnabled = false`, skip and print a local notice (see below).
364
+
365
+ All notification logic — credentials, message formatting, HTTP call, error logging — is handled by the CLI. Do NOT construct curl calls or read the env file directly.
366
+
367
+ **Success notification**:
368
+
369
+ The `--pr` flag value depends on `includeUpCode`:
370
+ - `includeUpCode = true` and push succeeded with PR → `--pr "<prLink>"`
371
+ - `includeUpCode = true` and push succeeded without PR (`createPR = false`) → `--pr ""` (empty string)
372
+ - `includeUpCode = false` → `--pr "skipped"`
373
+
374
+ ```bash
375
+ refacil-sdd-ai kapso notify success \
376
+ --repo "<repoSlug>" \
377
+ --change "<changeName>" \
378
+ --branch "<branchAtStart>" \
379
+ --tasks "<tasks.done>/<tasks.total>" \
380
+ --duration "<minutes>" \
381
+ --pr "<prLink | empty string | skipped>" \
382
+ --apply "<improvementsApplied.apply>" \
383
+ --test "<improvementsApplied.test>" \
384
+ --review "<improvementsApplied.review>" \
385
+ --warnings "<top 3 warnings joined by | or empty>"
386
+ ```
387
+
388
+ **Failure notification**:
389
+
390
+ ```bash
391
+ refacil-sdd-ai kapso notify failure \
392
+ --repo "<repoSlug>" \
393
+ --change "<changeName>" \
394
+ --branch "<branchAtFailure>" \
395
+ --phase "<phase>" \
396
+ --last-commit "<lastCommit>" \
397
+ --error "<errorSummary>"
398
+ ```
399
+
400
+ The CLI reads credentials from `~/.refacil-sdd-ai/kapso.env` internally. If Kapso returns an error, it logs to `~/.refacil-sdd-ai/autopilot.log` and exits without crashing — the SDD work is intact.
401
+
402
+ **If `kapsoEnabled = false`** (credentials absent or skipped): print a local notice instead:
403
+
404
+ ```
405
+ Autopilot completado (sin notificación WhatsApp — Kapso no configurado).
406
+ Para habilitar notificaciones en futuros runs: refacil-sdd-ai kapso setup
407
+ ```
408
+
409
+ ### Step 8: Terminal step
410
+
411
+ **This step always executes at the end of the cycle**, regardless of whether `includeUpCode` is `true` or `false`.
412
+
413
+ Delete the autopilot marker: `rm -f "refacil-sdd/.autopilot-active"`.
414
+
415
+ Print a concise summary to the session log:
416
+
417
+ ```
418
+ === Autopilot terminó ===
419
+ Resultado: <success|failure>
420
+ Change: <changeName>
421
+ PR: <prLink | N/A (createPR=false) | N/A (up-code omitido)>
422
+ Notificación WhatsApp: <enviada|fallida|desactivada>
423
+ ```
424
+
425
+ PR line rules:
426
+ - `includeUpCode = true` and push succeeded with PR → actual PR link
427
+ - `includeUpCode = true` and `createPR = false` → `N/A`
428
+ - `includeUpCode = false` → `N/A (up-code omitido)`
429
+
430
+ This is the terminal step. Do NOT suggest a next skill — apply METHODOLOGY-CONTRACT.md §5.
431
+
432
+ ## Rules
433
+
434
+ - **No interruptions after Step 0.6**: once the user replies to the pre-flight message, autopilot runs the full pipeline without surfacing any question to the user. All flow-continuity questions from sub-skills (apply, test, verify, review, archive) are answered internally (yes/continue). All "apply corrections?" prompts from verify and review are answered yes internally. Sub-agents are invoked with a context note that they are running in autonomous mode and must not ask for clarification.
435
+ - **NEVER skip `/refacil:review`**: the auditor sub-agent and `.review-passed` are the quality gate; autopilot does not bypass it.
436
+ - **NEVER force-push or rewrite history**: even on failure, leave the branch as-is.
437
+ - **NEVER notify success when any phase failed**: failure notifications are mandatory so the user knows to come back.
438
+ - **NEVER write Kapso credentials into commits, logs visible to the IDE, or AGENTS.md**: source the env file only at the moment of the curl call.
439
+ - **Single-repo scope per invocation**: autopilot runs in the repo where it was invoked. Do not attempt to coordinate across repos within a single autopilot run — that is what `refacil:bus` and `refacil:ask` are for.
440
+ - **Respect the methodology contract**: branch policy, protected branches, test scope defaults, and the review gate are all delegated to the underlying skills. Autopilot does NOT override them.
441
+ - **No third autofix round**: `/refacil:verify` has 2 built-in rounds. If those fail, the change needs human attention — notify and stop.
442
+ - **Kapso is optional**: a missing or misconfigured `kapso.env` must never block or abort the SDD pipeline. Autopilot always runs the full cycle; it only skips the WhatsApp notification if credentials are unavailable.
443
+ - **`includeUpCode` does not block notification**: Steps 7 (Kapso notification) and 8 (terminal summary) always execute when the cycle ends, whether `includeUpCode` is `true` or `false`. Setting `includeUpCode = false` only skips `/refacil:up-code` — it does not skip the end-of-cycle steps.
444
+ - **Language policy**: this skill's instructions are in English (per the contract). All user-facing text in the session must be in the **session language**. Kapso end-of-run messages sent by `refacil-sdd-ai kapso notify` are defined in `lib/kapso.js`.
445
+
446
+ ## Invocation by IDE
447
+
448
+ This skill is IDE-agnostic — its instructions only invoke other `/refacil:*` skills, which already work in all four supported IDEs. The headless launch command differs per IDE.
449
+
450
+ Open a new terminal, `cd` to the project, run the IDE with its auto-permissions flag, then type `/refacil:autopilot` once it opens. Output is visible in real time.
451
+
452
+ | IDE | Open command | Then type |
453
+ |---|---|---|
454
+ | Claude Code | `claude --dangerously-skip-permissions` | `/refacil:autopilot` |
455
+ | Cursor | This IDE session (after explicit confirmation in Step 0.6) | `/refacil:autopilot` |
456
+ | Codex | `codex --dangerously-bypass-approvals-and-sandbox` | `/refacil:autopilot` |
457
+ | OpenCode | `opencode --dangerously-skip-permissions` | `/refacil:autopilot` |
458
+
459
+ ### Notes on the auto-accept flags
460
+
461
+ - **Claude Code `--permission-mode auto`**: Auto Mode (released March 2026) uses a server-side classifier (Sonnet 4.6) to evaluate each action before execution. Safer than `--dangerously-skip-permissions` because it blocks scope-escalation, credential exploration, force-pushes outside the working branch, and similar overeager actions. In headless mode, 3 consecutive denials or 20 total denials terminate the process — this is the desired behavior for autopilot (the failure notification will fire). If you prefer the no-guardrails version: replace with `--dangerously-skip-permissions`.
462
+ - **Codex `--full-auto --sandbox workspace-write`**: the official CI combo from OpenAI's docs. Allows edits inside the workspace, denies broader access.
463
+ - **Cursor**: autopilot runs in the **current Cursor session** after explicit confirmation in Step 0.6 — do not use `cursor-agent` or other headless launchers for this skill.
464
+ - **OpenCode `--dangerously-skip-permissions`**: official flag on `opencode run` (auto-approves any permission not explicitly denied). For finer control, use `OPENCODE_PERMISSION` env var with an inline JSON permissions config.
465
+
466
+ When the run finishes (success or failure), the user gets a WhatsApp message via Kapso (if configured) and can come back to review.
467
+
468
+ ## Skill installation across IDEs
469
+
470
+ This skill follows the standard `refacil-sdd-ai` skill installation:
471
+ - `~/.claude/skills/refacil-autopilot/SKILL.md` (Claude Code — byte-for-byte)
472
+ - `~/.cursor/skills/refacil-autopilot/SKILL.md` (Cursor — frontmatter unchanged since this is a top-level skill, not a sub-agent)
473
+ - `~/.config/opencode/skills/refacil-autopilot/SKILL.md` (OpenCode — byte-for-byte)
474
+ - `~/.codex/skills/refacil-autopilot/SKILL.md` (Codex — byte-for-byte)
475
+
476
+ No agent file is required since autopilot delegates to existing sub-agents (`refacil-implementer`, `refacil-tester`, `refacil-validator`, `refacil-auditor`) through their respective skills.
@@ -36,11 +36,41 @@ If `$ARGUMENTS` does not bring enough information, ask the user:
36
36
 
37
37
  If `$ARGUMENTS` is already clear, do not ask again.
38
38
 
39
+ ### Step 1.5: CodeGraph availability check
40
+
41
+ Run `refacil-sdd-ai codegraph status --json` and set `codegraphAvailable`:
42
+ - `true` if `installed === true` AND `initialized === true`
43
+ - `false` otherwise
44
+
45
+ **If `mode` is `enabled` or `per-repo` but `codegraphAvailable` is `false`**:
46
+
47
+ ---
48
+
49
+ **[GATE — STOP AND WAIT: CodeGraph not indexed]**
50
+
51
+ Do NOT proceed to Step 2. Do NOT delegate to the sub-agent. STOP and ask the user exactly this, then wait for their reply:
52
+
53
+ ```
54
+ CodeGraph is enabled but not indexed for this repo (~30s to build).
55
+ Bug investigation traces call graphs — CodeGraph makes it significantly more accurate.
56
+
57
+ Do you want me to run /refacil:update first to build the index?
58
+ yes → run /refacil:update then continue with the investigation
59
+ no → continue with standard investigation now
60
+ ```
61
+
62
+ Only after the user replies:
63
+ - **"yes"** (or "si", "dale", "sí", "go", "ok"): immediately execute `/refacil:update`.
64
+ - **"no"** (or "skip", "continue", "continúa"): set `codegraphAvailable: false` and continue.
65
+
66
+ ---
67
+
39
68
  ### Step 2: Delegate investigation to the refacil-debugger sub-agent (mode: investigation)
40
69
 
41
70
  Invoke the `refacil-debugger` sub-agent passing it:
42
71
  - `mode: investigation`
43
72
  - `description`: complete bug description (collected in Step 1 or from `$ARGUMENTS`).
73
+ - `codegraphAvailable: true | false` (from Step 1.5).
44
74
 
45
75
  The sub-agent:
46
76
  - Reproduces and minimizes the failure scope first.
@@ -50,6 +80,14 @@ The sub-agent:
50
80
  - Reviews recent commits if the bug is new.
51
81
  - Returns hypotheses ordered by confidence + proposed correction, fenced as ` ```refacil-debug-investigation `.
52
82
 
83
+ After investigation completes, log telemetry silently:
84
+
85
+ ```bash
86
+ refacil-sdd-ai compact log-codegraph-event --skill debugger --has-graph <true|false> --tool-calls <N> --tokens <N>
87
+ ```
88
+
89
+ Same estimation criteria as `explore/SKILL.md` Step 1.5. Repeat after re-investigations when applicable.
90
+
53
91
  ### Step 3: Confirm hypothesis with the user
54
92
 
55
93
  Show the user the hypotheses and the proposed correction. Ask explicitly:
@@ -79,61 +117,20 @@ If the sub-agent reported `crossRepo: true` in any hypothesis: before implementi
79
117
 
80
118
  ### Step 4: Validate working branch (before implementing)
81
119
 
82
- Run `git branch --show-current` to get the current branch.
120
+ 1. Run `git branch --show-current` `currentBranch`.
121
+ 2. Run `refacil-sdd-ai sdd config --json` and parse `protectedBranches` and `baseBranch`.
122
+ - If the command fails or exits non-zero, fall back to:
123
+ - `protectedBranches` = [master, main]
124
+ - `baseBranch` = main (or master if main does not exist in the repo)
83
125
 
84
- If the current branch is already a working branch (`feature/*`, `fix/*`, `hotfix/*`, `refactor/*`, etc.), continue without interruption to Step 5.
126
+ **Decision (apply before any gate):**
85
127
 
86
- If the current branch is protected, execute the 3-gate protocol below strictly. Each gate is a hard stop do not proceed to the next gate until the user has replied.
128
+ - If `currentBranch` is **not** listed in `protectedBranches` you are already on a writable branch. Continue without interruption to **Step 5**. Do **not** ask for a task ID. Do **not** create another branch.
129
+ - If `currentBranch` **is** listed in `protectedBranches` → **read `METHODOLOGY-CONTRACT.md §4 — Protected branch policy`** before acting, then execute the 3-gate protocol defined there strictly. Each gate is a hard stop — do not proceed to the next gate until the user has replied.
87
130
 
88
- ---
131
+ **See `METHODOLOGY-CONTRACT.md §4 — Protected branch policy`** for the complete GATE 1 / GATE 2 / GATE 3 protocol.
89
132
 
90
- **[GATE 1 STOP AND WAIT: ask for task identifier]**
91
-
92
- Ask the user exactly this question and then STOP. Do NOT run any git command. Do NOT propose a branch name. Do NOT continue to Gate 2 until the user replies:
93
-
94
- > "What is the task number or identifier for this branch? (e.g. SEGINF-20, REF-123, or a short descriptive name)"
95
-
96
- If the user says they have no ID, note that and proceed to Gate 2 with `<ID> = none`.
97
-
98
- ---
99
-
100
- **[GATE 2 — STOP AND WAIT: propose branch name and ask for approval]**
101
-
102
- Only after receiving the user's reply to Gate 1:
103
-
104
- 1. Verify clean working directory (`git status --porcelain`).
105
- 2. If there are uncommitted changes, ask for approval to stash them (`git stash push -m "auto-stash-refacil"`). Do NOT stash without approval.
106
- 3. Detect the effective configuration by running:
107
- ```
108
- refacil-sdd-ai sdd config --json
109
- ```
110
- Parse `baseBranch` and `protectedBranches` from the JSON output.
111
- If the command fails or exits non-zero, fall back to:
112
- - `protectedBranches` = [master, main]
113
- - `baseBranch` = main (or master if main does not exist in the repo)
114
- 4. Determine the base branch:
115
- - Use the `baseBranch` value from the config (or the fallback).
116
- - Only if that branch does not exist in the repo (new repo), use `main` or `master` as a temporary exception and recommend adopting the standard flow.
117
- 5. Compose the branch name with `fix/` prefix:
118
- - Bugfix: `fix/<ID>` (e.g. `fix/SEGINF-20`)
119
- - Without ID: propose a short descriptive name (e.g. `fix/session-timeout-redis`)
120
- 6. Present the proposed name and ask for approval. Then STOP. Do NOT run `git checkout` or `git switch`. Do NOT create the branch yet. Wait for the user's explicit confirmation:
121
-
122
- > "I'll create branch `<proposed-name>` from `<base-branch>`. Shall I proceed?"
123
-
124
- ---
125
-
126
- **[GATE 3 — execute only after explicit approval from Gate 2]**
127
-
128
- Only after the user explicitly confirms (e.g. "yes", "go", "ok", "proceed"):
129
-
130
- 1. Switch to the base branch and update it (`git checkout <base>` + `git pull origin <base>`).
131
- 2. Create the working branch (`git checkout -b <branch-name>`).
132
- 3. If a stash was approved in Gate 2, restore it (`git stash pop`).
133
-
134
- If the user does not approve at Gate 2, stop entirely. Do not create any branch. Do not continue with implementation.
135
-
136
- ---
133
+ Apply-specific annotation: use `fix/<ID>` as the branch prefix (e.g. `fix/SEGINF-20`, `fix/session-timeout-redis`).
137
134
 
138
135
  ### Step 5: Delegate implementation to the refacil-debugger sub-agent (mode: fix)
139
136
 
@@ -148,7 +145,7 @@ Invoke the `refacil-debugger` sub-agent passing it:
148
145
  The sub-agent:
149
146
  - Implements the minimal and focused fix.
150
147
  - Generates regression tests (reproduces the bug + verifies the fix + normal-path assertions where warranted).
151
- - Creates `refacil-sdd/changes/fix-<name>/summary.md` with traceability.
148
+ - Creates `refacil-sdd/changes/fix-<name>/summary.md` with traceability. This `fix-*` folder is the approved operational exception to the regular proposal artifacts: it does not need `proposal.md`, `design.md`, `tasks.md`, or `specs.md` to be archived later, but it must include a substantive `summary.md`, regression test evidence from the debugger run, and an approved review before archive.
152
149
  - Runs **`testCommand`** per **`METHODOLOGY-CONTRACT.md §3.1`** (narrowed when `scoped`; full baseline only when `full` or narrow fallback warns).
153
150
  - Returns the report fenced as ` ```refacil-debug-fix `.
154
151
 
@@ -175,6 +172,8 @@ If the sub-agent returned `result: "FAILED"` (tests not passing), present the fa
175
172
  - **NEVER implement without explicit user approval** (Step 3).
176
173
  - **Always validate the branch** (Step 4) before delegating the fix.
177
174
  - **Do not replicate investigation or implementation logic here** — that lives in `refacil-debugger`.
175
+ - **`fix-*` archive exception**: do not route bug fixes through `/refacil:propose` merely to satisfy regular readiness. `fix-*` changes are valid for archive with `summary.md`, regression tests, and `.review-passed`; `/refacil:archive` documents the fix into `refacil-sdd/specs/` instead of requiring proposal artifacts.
178
176
  - Bugfix implementation output is English-only: source/test file names, identifiers, test descriptions, and code comments, regardless of the language used in user-facing text or SDD artifacts.
179
177
  - Step 3 (bus cross-repo) is **optional** — only applies if the sub-agent reported `crossRepo: true`.
180
- - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question in Step 6, immediately invoke the **Skill tool** with `skill: "refacil:review"`. Do not describe it in text or wait for the user to type `/refacil:review`. (See `METHODOLOGY-CONTRACT.md §5`.)
178
+ - **CodeGraph gate (Step 1.5)**: if `mode` is `enabled`/`per-repo` and `codegraphAvailable` is `false`, the GATE is **mandatory** — never skip it. If the user replies affirmatively ("yes", "si", "", "dale", "ok", "go"), immediately execute `/refacil:update` without any prior text. Do not describe it. Do not ask again. (See `METHODOLOGY-CONTRACT.md §5`.)
179
+ - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question in Step 6, immediately execute `/refacil:review`. Do not describe it in text or wait for the user to type it. (See `METHODOLOGY-CONTRACT.md §5`.)