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,157 @@
1
+ ---
2
+ name: refacil:stats
3
+ description: Show statistics for a change — token savings, review history, compact and CodeGraph telemetry; optional narrative interpretation
4
+ user-invocable: true
5
+ ---
6
+
7
+ # refacil:stats — Change Statistics
8
+
9
+ This skill is a **read-only utility** that surfaces observability data for a given change. It is optional — it does not block or affect any existing flow. Run it at any point to understand how a change is progressing or has progressed.
10
+
11
+ **Prerequisites**: `sdd` profile from `refacil-prereqs/SKILL.md`.
12
+
13
+ ## Flow
14
+
15
+ ### Step 1: Resolve change name
16
+
17
+ 1. If `$ARGUMENTS` provides a change name, use it directly.
18
+ 2. If not, run `refacil-sdd-ai sdd list --json` and use the single active change if there is only one.
19
+ 2.5. If `sdd list --json` returns `[]` (no active changes), auto-select the most recent archived change:
20
+ - Run `refacil-sdd-ai sdd list --include-archived --json`.
21
+ - From the returned array, filter items where `archived` is `true`. Sort descending by `archivedDate` (tiebreak: name descending). Select the first item.
22
+ - If an archived change is found: inform the user ("No active changes found — showing stats for most recently archived change: `<name>`") and continue to Step 2 with that `changeName`.
23
+ - If no archived changes exist either: inform the user that there is no change history and stop.
24
+ 3. If there are multiple active changes and no argument, ask the user to specify the change name. Do not proceed with ambiguous scope.
25
+
26
+ If the change name is given but not found in the active changes, do **not** suggest `/refacil:propose`. Instead:
27
+ 1. Run `refacil-sdd-ai sdd list --include-archived --json` to check for archived changes.
28
+ 2. If archived changes exist, show the list and ask the user to confirm which name they want to query (they may have misspelled or the change was already archived).
29
+ 3. Only if there are no active **and** no archived changes should you inform the user that there is no work history for the given name.
30
+
31
+ ### Step 2: Run the stats CLI command
32
+
33
+ Execute:
34
+
35
+ ```bash
36
+ refacil-sdd-ai sdd stats <changeName> --json
37
+ ```
38
+
39
+ If the command exits with code 1 (change not found or invalid name), show the CLI error message. The step 1 fallback (archived lookup) should have already been applied before reaching here, so a code 1 at this point means the name is genuinely absent in both active and archived locations — inform the user and stop.
40
+
41
+ ### Step 3: Parse the JSON output
42
+
43
+ Parse the JSON block returned by the CLI. Expected fields:
44
+
45
+ ```json
46
+ {
47
+ "changeName": "<name>",
48
+ "isArchived": true | false,
49
+ "archivedDate": "<YYYY-MM-DD or null>",
50
+ "startDate": "<ISO timestamp or null>",
51
+ "memory": {
52
+ "testCommand": "<command or null>",
53
+ "lastStep": "<step or null>",
54
+ "criteriaRun": ["CA-01", "CR-01", ...]
55
+ },
56
+ "review": {
57
+ "passed": true | false,
58
+ "verdict": "<verdict or null>",
59
+ "date": "<ISO timestamp or null>",
60
+ "failCount": <int>
61
+ },
62
+ "compact": {
63
+ "eventsInPeriod": <int>,
64
+ "rewrites": <int>,
65
+ "estimatedTokensSavedByRewrites": <int>,
66
+ "alreadyCompact": <int>,
67
+ "estimatedTokensSavedAlreadyCompact": <int>
68
+ },
69
+ "codegraph": {
70
+ "eventsInPeriod": <int>,
71
+ "totalToolCalls": <int>,
72
+ "estimatedTokensSaved": <int>
73
+ }
74
+ }
75
+ ```
76
+
77
+ If any field is null or 0, treat it as "no data" — do not error.
78
+
79
+ ### Step 4: Show numbers (structured display)
80
+
81
+ Present the data in a readable format. If `isArchived` is `true`, add `[archivado el <archivedDate>]` to the header:
82
+
83
+ ```
84
+ === Stats: <changeName> [archivado el <archivedDate>] === ← only when isArchived: true
85
+ === Stats: <changeName> === ← when isArchived: false
86
+
87
+ Phase progress
88
+ Started: <startDate or "unknown">
89
+ Last step: <lastStep or "not recorded">
90
+ Criteria: <criteriaRun list or "none">
91
+
92
+ Review
93
+ Passed: <yes/no>
94
+ Verdict: <verdict or "pending">
95
+ Date: <date or "—">
96
+ Fail count: <failCount>
97
+
98
+ Token savings (change period)
99
+ Compact rewrites: <rewrites> events — ~<estimatedTokensSavedByRewrites> tokens saved
100
+ Already compact: <alreadyCompact> events — ~<estimatedTokensSavedAlreadyCompact> tokens (skill discipline)
101
+ CodeGraph tool calls: <totalToolCalls> — ~<estimatedTokensSaved> tokens saved
102
+ ```
103
+
104
+ ### Step 5: Narrative interpretation (anomaly detection)
105
+
106
+ After the numbers, add a brief narrative. Apply these heuristics:
107
+
108
+ **Anomalous passes**: if `review.passed` is `true` but `memory.criteriaRun` is empty or `memory.lastStep` is `apply` (no test phase recorded) — flag this:
109
+ ```
110
+ Note: the change was reviewed but no test phase is recorded in memory. Recommend running /refacil:test before archiving.
111
+ ```
112
+
113
+ **Token concentration**: if `compact.estimatedTokensSavedByRewrites` is 0 and `codegraph.estimatedTokensSaved` is also 0 — flag this:
114
+ ```
115
+ Note: no token savings recorded for this change. Compact and CodeGraph telemetry may not be active.
116
+ ```
117
+
118
+ **Comparison with previous changes** (optional — only if data exists):
119
+ - Read all other change directories under `refacil-sdd/changes/` that have `memory.yaml`.
120
+ - If at least 2 other changes have `criteriaRun` data, compute the average criteria count and compare:
121
+ ```
122
+ This change ran <N> criteria vs. an average of <avg> in previous changes.
123
+ ```
124
+ - If no other changes have sufficient data, skip this comparison silently.
125
+
126
+ **No anomalies**: if none of the above apply, show:
127
+ ```
128
+ No anomalies detected. The change looks healthy.
129
+ ```
130
+
131
+ ### Step 6: Next step (optional)
132
+
133
+ **Skip this step entirely if `isArchived === true`** — archived changes have no actionable next steps.
134
+
135
+ If `memory.lastStep` is `apply` (no test yet):
136
+ ```
137
+ Recommended next step: /refacil:test
138
+ ```
139
+
140
+ If `memory.lastStep` is `test` and `review.passed` is `false`:
141
+ ```
142
+ Recommended next step: /refacil:verify
143
+ ```
144
+
145
+ If `review.passed` is `true`:
146
+ ```
147
+ The change is reviewed. Next step: /refacil:archive (if all tasks are done).
148
+ ```
149
+
150
+ ## Rules
151
+
152
+ - **This skill is read-only** — it does not modify any file, branch, or memory.
153
+ - **Does not block any flow** — absence of stats data is reported as zeros, not as an error.
154
+ - **Non-existent change**: exit with code 1 and a clear message (CA-12).
155
+ - **Missing data fields**: treat as zero or null — never throw; degrade gracefully.
156
+ - Comparison with previous changes is **optional** — only if data exists. Never block on its absence.
157
+ - This skill does not call any sub-agent — it is a direct CLI wrapper with narrative.
@@ -6,6 +6,10 @@ user-invocable: true
6
6
 
7
7
  # refacil:test — Test Generation Entrypoint
8
8
 
9
+ This skill is the **canonical test phase** of the SDD flow: it generates tests, runs the change-scoped suite, and records results in `memory.yaml` for later phases. **`/refacil:verify`** and **`/refacil:review`** rely on that memory and do **not** re-run the full pipeline by default (**METHODOLOGY-CONTRACT.md §3.2**).
10
+
11
+ **Role distinction — smoke vs. full-suite**: `/refacil:apply` runs a dynamic smoke command after editing (narrowed to touched files, no coverage). `/refacil:test` is responsible for the **full scoped run WITH coverage** on changed/new code (default `testScope: scoped`) or repo-wide suite with coverage (when `testScope: full`). This applies in both manual and autopilot flows — the tester MUST NOT skip coverage or delegate it back to apply.
12
+
9
13
  This skill is a **thin wrapper** that resolves the scope, extracts CA/CR criteria and the list of files to test, and delegates to the `refacil-tester` sub-agent with a **structured briefing**. The sub-agent starts with the criteria already extracted — it does not re-read specs from scratch.
10
14
 
11
15
  **Prerequisites**: `sdd` profile from `refacil-prereqs/SKILL.md` + test command from `METHODOLOGY-CONTRACT.md §3` and **§3.1** (default: scoped tests **and** scoped coverage on changed/new code; full suite/coverage **on-demand** via explicit arguments).
@@ -18,7 +22,7 @@ This skill is a **thin wrapper** that resolves the scope, extracts CA/CR criteri
18
22
 
19
23
  - **Defaults**: `testScope: scoped`, `runCoverage: true` (coverage **narrowed** to `filesToTest` / the change — not repo-wide).
20
24
 
21
- - **`testScope: full`** only if the user **explicitly** asked for **whole-repo / whole-suite** tests (e.g. `full`, `all tests`, `whole suite`, `suite completa`, `todas`). This is heavier; use sparingly before merge or debugging.
25
+ - **`testScope: full`** only if the user **explicitly** asked for a full suite (e.g. `full`, `all tests`, `whole suite`, `suite completa`, `todas`). Runs the full suite of **each affected component** (component-bounded per §3 — never all monorepo packages). Heavier; use sparingly before merge or debugging.
22
26
 
23
27
  - **`runCoverage: false`** if the user **explicitly** asked to skip coverage (e.g. `no coverage`, `nocoverage`, `skip coverage`, `sin cobertura`, `quick`, `solo tests`). Otherwise leave `runCoverage: true`.
24
28
 
@@ -33,13 +37,15 @@ This skill is a **thin wrapper** that resolves the scope, extracts CA/CR criteri
33
37
  - If there are multiple active folders, **stop** and ask the user to select which one to test.
34
38
  - If there are no active changes, inform to run `/refacil:propose` and stop.
35
39
 
40
+ **Autopilot mode detection**: once `changeName` is set, try to read `refacil-sdd/.autopilot-active`. If the file exists and its `changeName` field matches the current `changeName` → set `autopilotMode = true`. Otherwise `autopilotMode = false` (normal mode, ask user as usual).
41
+
36
42
  ### Step 1: Build briefing (change mode only)
37
43
 
38
44
  Before invoking the sub-agent, extract the key context:
39
45
 
40
46
  1. **Criteria** — read the change specification (`refacil-sdd/changes/<changeName>/specs.md` and/or `specs/**/*.md` if they exist). Extract the list of acceptance criteria (CA-XX) and rejection criteria (CR-XX) with their descriptions.
41
47
  2. **Files to test** — read `refacil-sdd/changes/<changeName>/design.md`. Extract the list of created/modified files.
42
- 3. **Test command (baseline)** — read `refacil-prereqs/METHODOLOGY-CONTRACT.md` §3 (and `AGENTS.md` if it overrides). Extract the baseline command **without** automatically adding coverage flags.
48
+ 3. **Test command (baseline)** — read `refacil-prereqs/METHODOLOGY-CONTRACT.md` §3 (and `AGENTS.md` if it overrides). Resolve the baseline command language-agnostically at the **affected component root** (nearest ancestor of changed files with a stack manifest — per §3 component principle). Extract the command without automatically adding coverage flags. If the change spans multiple components, extract a baseline per component; pass the primary one in `testCommand` and note extras in the briefing.
43
49
  4. **Test pattern** — find an existing relevant test file (1 example file, not multiple). If `testing-patterns.md` exists in this directory, include it.
44
50
  5. **Coverage command** — if `runCoverage: true`, detect the project coverage entrypoint per §3 (`test:cov`, `pytest --cov`, JaCoCo, `cargo llvm-cov`, etc.); otherwise set `coverageCommand: null`.
45
51
 
@@ -62,8 +68,11 @@ testScope: scoped | full
62
68
  runCoverage: true | false
63
69
  coverageCommand: <project coverage entrypoint or null>
64
70
  testPatternFile: <path of an existing test file as reference, or null>
71
+ codegraphAvailable: true | false
65
72
  ```
66
73
 
74
+ Detect CodeGraph availability before delegating: run `refacil-sdd-ai codegraph status --json` and set `codegraphAvailable: true` only if `installed === true` AND `initialized === true`. If the command fails or the index is not ready, set `false` and continue without interruption.
75
+
67
76
  The sub-agent (`refacil-tester`) applies **§3.1**: scoped tests by default; with `runCoverage: true`, runs **scoped** coverage (change-only) unless `testScope: full`.
68
77
 
69
78
  ### Step 2: Delegate to the refacil-tester sub-agent
@@ -79,6 +88,20 @@ The sub-agent will use the briefing to generate tests directly without re-readin
79
88
 
80
89
  Returns ONE single message with the report + JSON block fenced as ` ```refacil-test-result `.
81
90
 
91
+ ### Step 2.5: Log CodeGraph telemetry (silent)
92
+
93
+ After the sub-agent completes, run **once** (do not mention it to the user unless it fails):
94
+
95
+ ```bash
96
+ refacil-sdd-ai compact log-codegraph-event --skill tester --has-graph <true|false> --tool-calls <N> --tokens <N>
97
+ ```
98
+
99
+ - `--has-graph`: the `codegraphAvailable` value if it was passed to the sub-agent; otherwise `false`.
100
+ - `--tool-calls`: number of `codegraph_*` tool calls the sub-agent made (0 if it did not use the graph).
101
+ - `--tokens`: conservative estimate of tokens saved (~800–1500 per useful tool call; 0 if no graph or no calls).
102
+
103
+ Estimate `--tool-calls` and `--tokens` from the sub-agent's `<usage>` block using the same criteria as `explore/SKILL.md` Step 1.5. If the command fails, ignore it; it must not block the flow.
104
+
82
105
  ### Step 3: Present the report and process result
83
106
 
84
107
  Show the user the **report** (everything before the `refacil-test-result` block). Do not show the JSON block — it is internal metadata.
@@ -86,7 +109,9 @@ Show the user the **report** (everything before the `refacil-test-result` block)
86
109
  If the sub-agent returned something out of format, inform the user: "The tester returned an unstructured report — review the tests manually." and stop.
87
110
 
88
111
  Parse the `refacil-test-result` block from the sub-agent:
89
- - **If `passed: false`** (tests failed): present the `issues` from the JSON and ask the user how to proceed. **Do not continue to Step 4** until the tests pass.
112
+ - **If `passed: false`** (tests failed):
113
+ - `autopilotMode = false` (normal): present the `issues` from the JSON and ask the user how to proceed. **Do not continue to Step 4** until the tests pass.
114
+ - `autopilotMode = true`: attempt to fix the failing tests automatically (apply corrections to the test/source code — do NOT expand scope). Re-invoke the tester. **Maximum 3 rounds total.** If tests pass within those rounds → continue to Step 4. If still failing after round 3 → return phase failure to the autopilot pipeline (autopilot Step 6 handles Kapso notification). Do NOT ask the user at any point.
90
115
  - **If `passed: true`**: continue to Step 4.
91
116
 
92
117
  ### Step 3.5: Update cross-skill memory (memory.yaml)
@@ -108,12 +133,12 @@ This command merges into memory.yaml, preserving fields from other steps (e.g. `
108
133
 
109
134
  ### Step 4: Flow continuity (only if tests passed)
110
135
 
111
- Add:
112
-
113
- ```
114
- The next step is to validate the implementation against the specs.
115
- Do you want me to continue with /refacil:verify?
116
- ```
136
+ - `autopilotMode = false` (normal): ask the user:
137
+ ```
138
+ The next step is to validate the implementation against the specs.
139
+ Do you want me to continue with /refacil:verify?
140
+ ```
141
+ - `autopilotMode = true`: proceed to `/refacil:verify` immediately without asking.
117
142
 
118
143
  ## Rules
119
144
 
@@ -122,4 +147,4 @@ Do you want me to continue with /refacil:verify?
122
147
  - **Always delegate to the sub-agent**. Do not replicate stack detection or generation logic here.
123
148
  - **Do not invoke with ambiguous scope**. If there are multiple active changes, ask for selection first.
124
149
  - Test implementation is English-only (test file names, test cases/descriptions, identifiers, and comments), regardless of the SDD artifact language.
125
- - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question **and tests passed (`passed: true`)**, immediately invoke the **Skill tool** with `skill: "refacil:verify"`. Do not describe it in text or wait for the user to type `/refacil:verify`. (See `METHODOLOGY-CONTRACT.md §5`.)
150
+ - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question **and tests passed (`passed: true`)**, immediately execute `/refacil:verify`. Do not describe it in text or wait for the user to type it. (See `METHODOLOGY-CONTRACT.md §5`.)
@@ -28,6 +28,8 @@ If the command fails or exits non-zero, use the default list: master, main.
28
28
  ```
29
29
  - If the branch is a working branch (`feature/*`, `fix/*`, `hotfix/*`, `refactor/*`, etc.), continue.
30
30
 
31
+ **Autopilot mode detection**: try to read `refacil-sdd/.autopilot-active`. If the file exists → `autopilotMode = true`, extract `baseBranch` and `createPR` from the file. Otherwise `autopilotMode = false` (normal mode, ask user as usual).
32
+
31
33
  ### Step 2: Verify review (mandatory)
32
34
 
33
35
  Before continuing, verify if there are active changes in `refacil-sdd/changes/` (exclude the `archive/` folder).
@@ -60,12 +62,14 @@ Run `git status` to verify if there are changes to push.
60
62
  ### Step 4: Commit changes
61
63
 
62
64
  1. Run `git status --short` and show the user the list of detected files.
63
- 2. Ask for explicit confirmation before staging everything.
64
- 3. If the user confirms global staging, use `git add -A`.
65
- 4. If the user requests partial staging, add only the indicated paths.
66
- 5. If the user provided a message as argument (`$ARGUMENTS`), use it as the commit message.
67
- 6. If no message was provided, generate a descriptive one based on the detected changes with `git diff --staged --stat`.
68
- 7. Run `git commit -m "[message]"`.
65
+ 2. **Stage**:
66
+ - `autopilotMode = false` (normal): ask the user for confirmation before staging:
67
+ - If confirmed `git add -A`.
68
+ - If partial staging requested add only the indicated paths.
69
+ - `autopilotMode = true`: run `git add -A` immediately do NOT ask.
70
+ 3. If the user provided a message as argument (`$ARGUMENTS`), use it as the commit message.
71
+ 4. If no message was provided, generate a descriptive one based on the detected changes with `git diff --staged --stat`.
72
+ 5. Run `git commit -m "[message]"`.
69
73
 
70
74
  ### Step 5: Push to remote
71
75
 
@@ -81,13 +85,16 @@ Run `git push -u origin [current-branch]` to push the changes.
81
85
  Remote: origin/[branch-name]
82
86
  ```
83
87
 
84
- 2. **Ask the user** which branch they want to create the PR to. Show the list of protected branches obtained from `sdd config --json` in Step 1 so the user can pick one:
85
- ```
86
- Which branch do you want to create the PR to?
87
- Protected branches available: [list from sdd config --json]
88
- ```
89
-
90
- Verify the chosen branch exists on the remote by inspecting `git branch -r` output before generating the link. If it does not exist, inform the user and ask them to confirm or correct the name. If the user indicates a branch not in the protected branches list, warn them before proceeding.
88
+ 2. **Select target branch**:
89
+ - `autopilotMode = false` (normal): ask the user which branch to PR to, showing the protected branches list:
90
+ ```
91
+ Which branch do you want to create the PR to?
92
+ Protected branches available: [list from sdd config --json]
93
+ ```
94
+ Verify the chosen branch exists on the remote (`git branch -r`). If not, inform the user and ask to confirm or correct. Warn if not in the protected branches list.
95
+ - `autopilotMode = true`: use `baseBranch` from `refacil-sdd/.autopilot-active` as the target branch, and respect the `createPR` flag:
96
+ - `createPR = true` → generate the PR link against `baseBranch`.
97
+ - `createPR = false` → skip PR creation entirely. Do NOT generate a link.
91
98
 
92
99
  3. Get the remote repository URL with `git remote get-url origin` and detect the VCS hosting used by this repository to generate the correct PR/MR link:
93
100
  - **GitHub** (url contains `github.com`): `https://github.com/[owner]/[repo]/compare/[target-branch]...[current-branch]?expand=1`
@@ -10,9 +10,39 @@ Detects the current repo state and applies only what is pending. Does not repeat
10
10
 
11
11
  The `notify-update` hook uses the **same engine** as this command; do not manually re-evaluate the repo to decide if there is work to do.
12
12
 
13
+ ## Step 0.5: CodeGraph setup (if needed)
14
+
15
+ Run `refacil-sdd-ai codegraph status --json` and parse the output.
16
+
17
+ **If `mode` is `disabled` or `null`**: skip this step entirely.
18
+
19
+ **If `mode` is `enabled` or `per-repo`**:
20
+
21
+ 1. **CLI not installed** (`installed: false`): inform the user and ask for confirmation **before running anything**:
22
+
23
+ ```
24
+ CodeGraph is enabled but the CLI (@colbymchenry/codegraph) is not installed.
25
+ Installing it will run: npm install -g @colbymchenry/codegraph (~20 s)
26
+ Proceed? (yes / no)
27
+ ```
28
+
29
+ - **If yes**: run `refacil-sdd-ai codegraph setup` and **show its full output** to the user. This command installs the package, then builds the index **synchronously** — it blocks until `.codegraph/` is fully ready. Wait for it to complete before continuing. After it finishes, inform:
30
+ ```
31
+ CodeGraph: installed and index complete. .codegraph/ is ready.
32
+ Future /refacil:explore, /refacil:propose, and /refacil:bug sessions will use it automatically.
33
+ ```
34
+ - **If no**: skip CodeGraph for this session. Inform: "You can install it later with `npm install -g @colbymchenry/codegraph`, then run `/refacil:update` again."
35
+
36
+ 2. **CLI installed but repo not indexed** (`installed: true`, `initialized: false`): run `refacil-sdd-ai codegraph setup` and **show its full output**. This command blocks until the index is fully built — wait for it to finish before continuing. Inform:
37
+ ```
38
+ CodeGraph: index complete. .codegraph/ is ready.
39
+ ```
40
+
41
+ 3. **CLI installed and repo indexed** (`installed: true`, `initialized: true`): skip — nothing to do.
42
+
13
43
  ## Step 1: Validate with the CLI (mandatory)
14
44
 
15
- In the **repo root** (where `AGENTS.md` or `.claude/` is), run with `Bash`:
45
+ In the **repo root** (where `AGENTS.md` is), run with `Bash`:
16
46
 
17
47
  ```bash
18
48
  refacil-sdd-ai migration-pending
@@ -34,6 +64,7 @@ The implementation lives in `lib/methodology-migration-pending.js` of the packag
34
64
  | 1 | `AGENTS.md` exists and `.agents/` folder does not | Restructure into `.agents/` + rewrite as index |
35
65
  | 2 | `CLAUDE.md` has more than 5 lines or does not point to `AGENTS.md` | Replace with minimal index |
36
66
  | 3 | `.cursorrules` has more than 5 lines or does not point to `AGENTS.md` | Replace with minimal index |
67
+ | 4 | CodeGraph CLI not installed and mode is `enabled`/`per-repo` | Step 0.5: `refacil-sdd-ai codegraph setup` |
37
68
 
38
69
  ## Step 2: Confirm with the user
39
70
 
@@ -8,7 +8,7 @@ user-invocable: true
8
8
 
9
9
  This skill is a **wrapper** that builds a **structured briefing** with the test command and criteria already extracted, delegates the analysis to the `refacil-validator` sub-agent, and handles the interaction with the user to apply corrections.
10
10
 
11
- **Prerequisites**: `sdd` profile from `refacil-prereqs/SKILL.md` + rules from `METHODOLOGY-CONTRACT.md` (including **§3.1** — default scoped tests **and** scoped coverage; full regression on explicit request).
11
+ **Prerequisites**: `sdd` profile from `refacil-prereqs/SKILL.md` + rules from `METHODOLOGY-CONTRACT.md` (including **§3.2** — `/refacil:test` owns full test+coverage; verify defaults to **no re-run** when test memory exists).
12
12
 
13
13
  ## Flow
14
14
 
@@ -19,15 +19,18 @@ Determine the scope before invoking the sub-agent. Prioritize in this order:
19
19
  2. Active change in `refacil-sdd/changes/`.
20
20
  3. If there are multiple active changes and no `$ARGUMENTS`, **stop** and ask the user to explicitly select which change to validate.
21
21
 
22
- **Test intent** align with **`/refacil:test`** (same tokens):
22
+ **Autopilot mode detection**: once `changeName` is resolved, try to read `refacil-sdd/.autopilot-active`. If the file exists and its `changeName` field matches → `autopilotMode = true`. Otherwise `autopilotMode = false` (normal mode, ask user as usual).
23
23
 
24
- - **Defaults**: `testScope: scoped`, `runCoverage: true` (coverage **narrowed** to diff / changed files).
24
+ **Test execution intent** see **§3.2**:
25
25
 
26
- - **`testScope: full`** only if the user explicitly asked (`full`, `all tests`, `whole suite`, `suite completa`, `todas`).
26
+ - **Default**: `testExecution: none` when `get-memory` has `commandsRun` and `lastStep` is `test` (or later) verify validates CA/CR **without** re-running the test pipeline.
27
27
 
28
- - **`runCoverage: false`** if the user explicitly asked to skip coverage (`no coverage`, `nocoverage`, `skip coverage`, `sin cobertura`, `quick`, `solo tests`). Otherwise leave `runCoverage: true`.
28
+ - **`testExecution: full`** if the user explicitly asked to re-run tests (`full`, `all tests`, `re-run`, `run tests`, `ejecutar tests`, `whole suite`, `suite completa`, `todas`) then also set `testScope` / `runCoverage` like **`/refacil:test`**:
29
+ - **`testScope: full`** for whole-suite tokens above.
30
+ - **`runCoverage: false`** for `no coverage`, `nocoverage`, `skip coverage`, `sin cobertura`, `quick`, `solo tests`.
31
+ - **`full` + `no coverage`**: `testScope: full`, `runCoverage: false`.
29
32
 
30
- - **`full` + `no coverage`**: full tests only (`testScope: full`, `runCoverage: false`).
33
+ - **No test memory** (`commandsRun` empty): emit WARNING, set `testExecution: full` (CR-01) unless only `changedFiles` allow a minimal scoped run.
31
34
 
32
35
  Do not invoke the sub-agent with ambiguous scope.
33
36
 
@@ -41,19 +44,28 @@ If **this session** inspects the change directory before or after delegating, ap
41
44
 
42
45
  Before invoking the sub-agent, extract the context that the validator would otherwise calculate on its own:
43
46
 
47
+ 0. **CodeGraph detection** — run `refacil-sdd-ai codegraph status --json` and extract:
48
+ - `codegraphAvailable = true` if `installed === true` AND `initialized === true`
49
+ - `codegraphAvailable = false` otherwise
50
+ - Include `codegraphAvailable` as a field in the briefing so the validator can use CodeGraph for Dimension 3 (Coherence) analysis when available (see `METHODOLOGY-CONTRACT.md §3C`).
51
+
44
52
  1. **Scope files** — run `git diff --name-only HEAD` to populate `changedFiles`.
45
53
 
46
- 2. **Cross-skill memory** — when `changeName` is known, run `refacil-sdd-ai sdd get-memory <changeName> --json`. Parse `commandsRun` and `criteriaRun`. If the output is `{}` or the command fails, omit those fields — do not block verification (CR-04).
54
+ 2. **Cross-skill memory** — when `changeName` is known, run `refacil-sdd-ai sdd get-memory <changeName> --json`. Parse `commandsRun`, `criteriaRun`, and `lastStep`. If the output is `{}` or the command fails, omit those fields — do not block verification (CR-04).
55
+
56
+ 3. **Resolve `testExecution`** (§3.2) from Step 0 and memory:
57
+ - User forced re-run → `testExecution: full`.
58
+ - `commandsRun` non-empty and `lastStep` is `test` (or `verify`/`review` after test) and user did **not** force re-run → `testExecution: none`.
59
+ - Otherwise → `testExecution: full` with WARNING (no test phase recorded).
47
60
 
48
- 3. **Test command** — follow `METHODOLOGY-CONTRACT.md` §3.1. Set `testScope` and `runCoverage` from Step 0 (`scoped` / `runCoverage: true` by default).
49
- - If the user requested `testScope: full`, set `testCommand` to the baseline §3 command (no narrowing).
50
- - Else if `commandsRun` from memory is non-empty and the user did **not** force `full`, prefer the **last** entry in `commandsRun` as `testCommand` (same invocation as `/refacil:test` when memory was updated).
51
- - Else build a **scoped** `testCommand` from `changedFiles`: include paths that are already test artifacts; for touched sources, infer companion tests from **project convention** (`AGENTS.md`, test config — co-located `*Test*` / `*Spec*`, `tests/`, language-specific layouts), not from a single language suffix.
52
- - If you cannot build any scoped command, fall back to baseline §3 and add a one-line WARNING in the handoff that the run may be heavy.
61
+ 4. **Test commands** — only when `testExecution` is `full` or `smoke`:
62
+ - **`full`**: follow §3.1 set `testScope` and `runCoverage` from Step 0; build `testCommand` (scoped from `changedFiles` or baseline if `full`); set `coverageCommand` when `runCoverage: true`.
63
+ - **`smoke`**: build `smokeTestCommand` for companion tests of `correctionTouchedFiles` only; `runCoverage: false`, `coverageCommand: null`.
64
+ - **`none`**: omit `testCommand` and `coverageCommand`; set `testsDelegatedFrom: test` and include `commandsRun` for the report.
53
65
 
54
- 4. **Coverage command** — detect per §3 when `runCoverage: true`; otherwise set `coverageCommand: null`. When `testScope` is `scoped` and `runCoverage: true`, instruct the validator to **narrow coverage collection** to `changedFiles` / companion tests only (same as §3.1).
66
+ 5. **Coverage command** — only when `testExecution: full` and `runCoverage: true`; otherwise `coverageCommand: null`.
55
67
 
56
- 5. **CA/CR criteria** — if there is an active change, read the specification in `refacil-sdd/changes/<changeName>/`:
68
+ 6. **CA/CR criteria** — if there is an active change, read the specification in `refacil-sdd/changes/<changeName>/`:
57
69
  - `specs.md` if it exists, and/or files under `specs/` (recursively).
58
70
  - Extract the list of CA-XX (acceptance criteria) and CR-XX (rejection criteria) with their descriptions.
59
71
  - If there are no specs or the scope is `git-diff`, omit this field.
@@ -63,10 +75,14 @@ Build the BRIEFING block:
63
75
  ```
64
76
  BRIEFING:
65
77
  changeName: <name or null if scope=git-diff>
66
- testCommand: <exact command line the validator must run — scoped by default>
78
+ testExecution: none | smoke | full
79
+ testCommand: <required when full; omit when none>
80
+ smokeTestCommand: <required when smoke; omit otherwise>
67
81
  testScope: scoped | full
68
82
  runCoverage: true | false
69
- coverageCommand: <project coverage entrypoint or null>
83
+ coverageCommand: <project coverage entrypoint or null when full+runCoverage>
84
+ testsDelegatedFrom: test | null
85
+ correctionTouchedFiles: [...] # only on re-verify after Step 5 corrections
70
86
  criteria:
71
87
  acceptance:
72
88
  - CA-01: <description>
@@ -75,6 +91,7 @@ criteria:
75
91
  - CR-01: <description>
76
92
  changedFiles: [path/file-1, ...]
77
93
  mode: concise | detailed
94
+ codegraphAvailable: true | false # from CodeGraph detection in Step 1.0
78
95
  commandsRun: [<command>, ...] # from memory.yaml — omit if not present
79
96
  criteriaRun: [CA-01, CR-01, ...] # from memory.yaml — omit if not present
80
97
  ```
@@ -84,15 +101,29 @@ criteriaRun: [CA-01, CR-01, ...] # from memory.yaml — omit if not presen
84
101
  Invoke `refacil-validator` passing it the BRIEFING from the previous step.
85
102
 
86
103
  The sub-agent:
87
- - Uses `testCommand` from the briefing directly (without looking it up in METHODOLOGY-CONTRACT.md).
88
- - Applies **§3.1**: `testScope` and `runCoverage` from the briefing (defaults scoped + scoped coverage).
104
+ - Applies **`testExecution`** from the briefing (§3.2) **does not** run tests when `none`.
105
+ - When `full`, uses `testCommand` / coverage per §3.1; when `smoke`, runs only `smokeTestCommand` (no coverage).
89
106
  - Uses `criteria` from the briefing for verification (without re-reading specs from scratch).
90
107
  - Uses `changedFiles` to focus the 3D verification on those files.
91
- - Applies the 3D framework (Completeness/Correctness/Coherence) directly.
92
- - Runs tests then coverage per briefing (`runCoverage: true` by default **narrowed** coverage unless `testScope: full`).
108
+ - Applies the **3D framework (Completeness/Correctness/Coherence)** per **`METHODOLOGY-CONTRACT.md §3C — 3C Criterion`** — including the severity table and graceful degradation rule.
109
+ - If `codegraphAvailable: true` is in the briefing, uses CodeGraph on `changedFiles` for Dimension 3 (Coherence) analysis.
93
110
  - Optionally consults the bus cross-repo for ambiguities.
94
111
  - Returns combined report + JSON block fenced as ` ```refacil-verify-result `.
95
112
 
113
+ ### Step 2.5: Log CodeGraph telemetry (silent)
114
+
115
+ After the sub-agent completes, run **once** (do not mention it to the user unless it fails):
116
+
117
+ ```bash
118
+ refacil-sdd-ai compact log-codegraph-event --skill validator --has-graph <true|false> --tool-calls <N> --tokens <N>
119
+ ```
120
+
121
+ - `--has-graph`: the `codegraphAvailable` value from Step 1.0 of this skill.
122
+ - `--tool-calls`: number of `codegraph_*` tool calls the sub-agent made (0 if it did not use the graph).
123
+ - `--tokens`: conservative estimate of tokens saved (~800–1500 per useful tool call; 0 if no graph or no calls).
124
+
125
+ Estimate `--tool-calls` and `--tokens` from the sub-agent's `<usage>` block using the same criteria as `explore/SKILL.md` Step 1.5. If the command fails, ignore it; it must not block the flow.
126
+
96
127
  ### Step 3: Present the report
97
128
 
98
129
  Show the user the **combined report** (everything before the `refacil-verify-result` block). Do not show the JSON block — it is internal metadata.
@@ -117,28 +148,30 @@ Parse the ` ```refacil-verify-result ` block from the sub-agent.
117
148
 
118
149
  #### If `result` is APPROVED:
119
150
 
120
- ```
121
- RESULT: APPROVED
151
+ - `autopilotMode = false` (normal): ask the user:
152
+ ```
153
+ RESULT: APPROVED
122
154
 
123
- The next step is the quality review with the team checklist.
124
- Do you want me to continue with `/refacil:review`?
125
- ```
155
+ The next step is the quality review with the team checklist.
156
+ Do you want me to continue with `/refacil:review`?
157
+ ```
158
+ - `autopilotMode = true`: proceed to `/refacil:review` immediately without asking.
126
159
 
127
160
  #### If `result` is REQUIRES_CORRECTIONS:
128
161
 
129
- Present the issues and ask:
162
+ - `autopilotMode = false` (normal): present the issues and ask:
163
+ ```
164
+ RESULT: REQUIRES_CORRECTIONS
130
165
 
131
- ```
132
- RESULT: REQUIRES_CORRECTIONS
133
-
134
- Required corrections:
135
- 1. [CRITICAL/WARNING] [description] — [suggested fix]
136
- 2. ...
166
+ Required corrections:
167
+ 1. [CRITICAL/WARNING] [description] — [suggested fix]
168
+ 2. ...
137
169
 
138
- Do you want me to apply these corrections? (yes/no)
139
- - Yes: I will apply the fixes and automatically re-verify
140
- - No: you can fix them manually and then continue with /refacil:verify
141
- ```
170
+ Do you want me to apply these corrections? (yes/no)
171
+ - Yes: I will apply the fixes and automatically re-verify
172
+ - No: you can fix them manually and then continue with /refacil:verify
173
+ ```
174
+ - `autopilotMode = true`: apply corrections automatically (yes internally) without asking, then re-verify. If still failing after 2 rounds → abort (return failure to the autopilot pipeline without asking the user).
142
175
 
143
176
  ### Step 5: Apply corrections (if the user accepts)
144
177
 
@@ -146,16 +179,20 @@ Do you want me to apply these corrections? (yes/no)
146
179
 
147
180
  1. Apply ONLY the listed corrections — do not add new functionality, do not refactor unrelated code.
148
181
  2. If there are tests that need adjustment, adjust them as well.
149
- 3. Show summary of modified files.
150
- 4. **Automatically re-run from Step 2** (re-invoke the sub-agent with the same briefing) to confirm the corrections resolved the issues.
182
+ 3. Show summary of modified files; record paths in `correctionTouchedFiles`.
183
+ 4. **Re-verify** (max 2 rounds): rebuild briefing with `testExecution: smoke` on companion tests of `correctionTouchedFiles`, **or** `testExecution: none` and tell the user:
184
+ ```
185
+ Corrections applied. Run /refacil:test before the next full verify to refresh the test suite.
186
+ ```
187
+ **Never** set `testExecution: full` in autofix re-verify unless the user explicitly requested re-run in this invocation.
151
188
  5. Maximum **2 rounds** of automatic correction. If issues persist, list them for manual correction.
152
189
 
153
- **If the user does not accept:** list the issues for manual correction. Suggest `/refacil:verify` again.
190
+ **If the user does not accept:** list the issues for manual correction. Suggest `/refacil:test` then `/refacil:verify`.
154
191
 
155
192
  ## Rules
156
193
 
157
194
  - **Always build the briefing (Step 1) before delegating** — reduces the sub-agent tool calls.
158
- - **Defaults**: `testScope: scoped`, `runCoverage: true` (change-only coverage). **`testScope: full`** or **no coverage** only when Step 0 tokens say so.
195
+ - **Defaults**: `testExecution: none` when test memory exists; **`testExecution: full`** only when Step 0 forces re-run or CR-01 applies. Smoke only after corrections; never full suite in autofix rounds.
159
196
  - **Always delegate to the sub-agent** for the analysis. Do not replicate spec reading or test execution logic here.
160
197
  - **Dotfiles in `refacil-sdd/changes/`**: never assert absence of `.review-passed` without `-a`; see §8.
161
198
  - **Corrections are ONLY applied by this wrapper** (Step 5), after explicit approval.
@@ -164,4 +201,4 @@ Do you want me to apply these corrections? (yes/no)
164
201
  - **Sub-agent failsafe (CA-01)**: if the validator fails to load (tool error) or returns no response — stop and inform the user. Do NOT escalate to any other agent.
165
202
  - **Unstructured output (CA-02)**: if the validator responds but without a `refacil-verify-result` block — show the raw report and stop. Do NOT re-invoke another agent.
166
203
  - **SCOPE_ERROR (CR-03)**: if the validator returns `SCOPE_ERROR: <reason>` — propagate and ask for clarification. CA-01 does NOT apply here.
167
- - **Flow continuity**: if the result is APPROVED and the user confirms affirmatively, immediately invoke the **Skill tool** with `skill: "refacil:review"`. (See `METHODOLOGY-CONTRACT.md §5`.)
204
+ - **Flow continuity**: if the result is APPROVED and the user confirms affirmatively, immediately execute `/refacil:review`. (See `METHODOLOGY-CONTRACT.md §5`.)
@@ -41,5 +41,15 @@ Rules to minimize context consumption when working in this repository.
41
41
  - `docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"`.
42
42
  - `docker logs --tail 100` always; never full logs.
43
43
 
44
+ **CodeGraph (when available)**
45
+ When `codegraph_*` MCP tools are present in the session, prefer them over `Grep`, `Read`, and `Glob` for all structural queries:
46
+ - Symbol lookup → `codegraph_search` before `Grep`
47
+ - Tracing flows → `codegraph_callers` / `codegraph_callees`
48
+ - Module context → `codegraph_context` (replaces reading multiple files)
49
+ - Impact analysis → `codegraph_impact` before touching shared code
50
+ - Fall back to native tools only for literal text search or when CodeGraph returns empty results.
51
+
52
+ If the session context contains a `[refacil-sdd-ai] CodeGraph` message (CLI not installed or repo not indexed): relay it to the user in the first response and offer to run `/refacil:update`.
53
+
44
54
  **General rule**
45
55
  When in doubt between verbosity and conciseness, choose conciseness. The user can request detail on demand.
@@ -18,9 +18,14 @@ Skills are identical in `.claude/skills/refacil-*/` (Claude Code) and `.cursor/s
18
18
  | `/refacil:up-code` | Push code and create PR |
19
19
  | `/refacil:bug` | Guided bugfix flow |
20
20
  | `/refacil:update` | Apply pending **methodology** migrations (same engine as `notify-update`; e.g. `AGENTS.md` → `.agents/` index pattern) |
21
+ | `/refacil:stats` | Show change progress, task status, review gate, and test commands from SDD artifacts |
22
+ | `/refacil:read-spec` | Listen to a change's specs in the browser with on-device TTS |
23
+ | `/refacil:autopilot` | Autonomous pipeline: chains `apply → test → verify → review → archive` in one invocation; `up-code` (push + PR) optional via pre-flight. Optional WhatsApp notification via Kapso |
21
24
 
22
25
  **Typical feature flow:** `setup` → `explore` (optional) → `propose` → `apply` → `test` → `verify` → `review` → `archive` → `up-code`.
23
26
 
27
+ **Autonomous alternative:** after `propose` is approved, `/refacil:autopilot` chains `apply → test → verify → review → archive` (and optionally `up-code`) in a single invocation instead of running each step manually.
28
+
24
29
  **Bug flow:** `bug` replaces `propose`/`apply` for the fix path; then `test` / `review` / `archive` / `up-code` as appropriate (see skill `refacil:bug`).
25
30
 
26
31
  **Legacy layout:** if the repo still has **`openspec/changes/`**, run any **`refacil-sdd-ai sdd …`** command or open a session ( **`check-update`** ) to migrate into **`refacil-sdd/`**; then remove **`openspec/`** when no longer referenced. Optional OpenSpec CLI (**`opsx:*`**) may coexist; SDD-AI uses **`refacil-sdd/`** and **`/refacil:*`** as the primary interface.