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
@@ -15,6 +15,17 @@ function buildBlock(templateContent) {
15
15
  return `${MARKER_START}\n${templateContent}\n${MARKER_END}`;
16
16
  }
17
17
 
18
+ /** Normalize line endings for idempotent compare (CA-02 / Windows CRLF). */
19
+ function normalizeEol(text) {
20
+ return text.replace(/\r\n/g, '\n');
21
+ }
22
+
23
+ function contentUnchanged(next, raw) {
24
+ const a = normalizeEol(next).trimEnd() + '\n';
25
+ const b = normalizeEol(raw).trimEnd() + '\n';
26
+ return a === b;
27
+ }
28
+
18
29
  /**
19
30
  * Merge or replace the managed SDD-AI testing policy block in `.agents/testing.md`.
20
31
  * Skips if `.agents/` does not exist (no SDD layout yet).
@@ -70,11 +81,12 @@ function syncTestingPolicyBlock(projectRoot, packageRoot) {
70
81
  action = 'replaced';
71
82
  }
72
83
 
73
- if (next === existing) {
84
+ const normalized = next.trimEnd() + '\n';
85
+ if (contentUnchanged(normalized, existing)) {
74
86
  return { status: 'unchanged' };
75
87
  }
76
88
 
77
- fs.writeFileSync(testingPath, next);
89
+ fs.writeFileSync(testingPath, normalized);
78
90
  return { status: action };
79
91
  }
80
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "refacil-sdd-ai",
3
- "version": "5.2.2",
3
+ "version": "5.3.0",
4
4
  "description": "SDD-AI: Specification-Driven Development with AI — development methodology using AI with Claude Code, Cursor, OpenCode and Codex",
5
5
  "bin": {
6
6
  "refacil-sdd-ai": "./bin/cli.js"
@@ -13,6 +13,7 @@
13
13
  "agents/",
14
14
  "templates/",
15
15
  "README.md",
16
+ "NOTICE.md",
16
17
  "refacil-bus-diagrams.md"
17
18
  ],
18
19
  "keywords": [
@@ -38,13 +39,15 @@
38
39
  "node": ">=20.0.0"
39
40
  },
40
41
  "scripts": {
41
- "test": "node --test test/hooks.test.js test/installer.test.js test/ignore-files.test.js test/methodology-migration-pending.test.js test/sdd.test.js test/config.test.js test/refactor-integrar-openspec-nativo.test.js test/refactor-rutas-refacil-sdd.test.js test/refactor-agents-english.test.js test/remove-openspec-legacy.test.js test/find-project-root.test.js test/opencode-installer.test.js test/opencode-plugin.test.js test/toml-converter.test.js test/testing-policy-sync.test.js test/session-repo-sync.test.js"
42
+ "postinstall": "node ./bin/postinstall.js",
43
+ "test": "node --test --test-concurrency=1 test/global-paths.test.js test/opencode-global-path-windows.test.js test/opencode-migrate.test.js test/opencode-clean-global.test.js test/skills-parity.test.js test/multi-ide-parity-pass2.test.js test/repo-ide-sync.test.js test/global-install.test.js test/hooks.test.js test/installer.test.js test/ignore-files.test.js test/methodology-migration-pending.test.js test/sdd.test.js test/test-scope.test.js test/config.test.js test/refactor-integrar-openspec-nativo.test.js test/refactor-rutas-refacil-sdd.test.js test/refactor-agents-english.test.js test/remove-openspec-legacy.test.js test/find-project-root.test.js test/project-root.test.js test/opencode-installer.test.js test/opencode-plugin.test.js test/check-review.test.js test/toml-converter.test.js test/testing-policy-sync.test.js test/session-repo-sync.test.js test/compact-guidance.test.js test/codegraph.test.js test/codegraph-telemetry.test.js test/compact-codegraph.test.js test/autopilot-skill-install.test.js test/read-spec-md-parser.test.js test/read-spec.test.js test/spec-sync.test.js test/kapso-init-session-removed.test.js test/kapso-preflight.test.js test/autopilot-ready-message.test.js test/stats-observability.test.js test/bus-from-env.test.js test/imp-scoped-test-execution.test.js test/broker-port-env.test.js"
42
44
  },
43
45
  "dependencies": {
44
46
  "smol-toml": "^1.6.1",
45
47
  "ws": "^8.18.0"
46
48
  },
47
49
  "optionalDependencies": {
48
- "@clack/prompts": "^0.9.0"
50
+ "@clack/prompts": "^0.9.0",
51
+ "@colbymchenry/codegraph": "0.7.9"
49
52
  }
50
53
  }
@@ -33,16 +33,16 @@ With the selected `changeName`, run `refacil-sdd-ai sdd status <changeName> --js
33
33
  ```
34
34
 
35
35
  Validations:
36
- - If `artifacts.proposal` is `false` or `artifacts.tasks` is `false` or `artifacts.specs` is `false`:
36
+ - Build `missingArtifacts` from every false value in `artifacts` (`proposal`, `design`, `tasks`, `specs`) and report the complete list. Do not stop at the first missing artifact.
37
+ - If `ready.forApply` is `false` or `missingArtifacts.length > 0`:
37
38
  ```
38
39
  The change at refacil-sdd/changes/[name]/ is incomplete.
39
- Missing: [list of artifacts with false]
40
+ Missing: [complete list of artifacts with false]
40
41
  Run: /refacil:propose to complete the artifacts before implementing.
41
42
  ```
42
43
  **Stop.**
43
- - If `ready.forApply` is `false` for the same reason: same message above.
44
44
 
45
- Note: `specs` is `true` if `specs.md` exists in the root **OR** at least one `.md` under the change's `specs/` folder.
45
+ Note: `ready.forApply` is the contract source of truth and is `true` only when `proposal.md`, `design.md`, `tasks.md`, and a valid spec source exist. `specs` is `true` if non-empty `specs.md` exists in the root and/or at least one non-empty `.md` exists under `specs/**/*.md` (recursive; empty folders do not count). The same source set is used by `sdd status`, `sync-spec`, test/verify criteria extraction, and archive.
46
46
 
47
47
  **IMPORTANT**: This command NEVER generates SDD artifacts. If they do not exist, the user must use `/refacil:propose`.
48
48
 
@@ -52,57 +52,24 @@ Run `git branch --show-current` to get the current branch.
52
52
 
53
53
  If the current branch is already a working branch (`feature/*`, `fix/*`, `hotfix/*`, `refactor/*`, etc.), continue without interruption to Step 1.5.
54
54
 
55
- If the current branch is protected, execute the 3-gate protocol below strictly. Each gate is a hard stopdo not proceed to the next gate until the user has replied.
55
+ If the current branch is protected, **read `METHODOLOGY-CONTRACT.md §4 — Protected branch policy`** before acting, then execute the gate protocol defined there. For this skill, Gates 1 and 2 are merged into a single interactionpropose and confirm in one message, wait for one reply.
56
56
 
57
- ---
58
-
59
- **[GATE 1 — STOP AND WAIT: ask for task identifier]**
60
-
61
- 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:
62
-
63
- > "What is the task number or identifier for this branch? (e.g. SEGINF-20, REF-123, or a short descriptive name)"
64
-
65
- If the user says they have no ID, note that and proceed to Gate 2 with `<ID> = none`.
66
-
67
- ---
68
-
69
- **[GATE 2 — STOP AND WAIT: propose branch name and ask for approval]**
70
-
71
- Only after receiving the user's reply to Gate 1:
72
-
73
- 1. Verify clean working directory (`git status --porcelain`).
74
- 2. If there are uncommitted changes, ask for approval to stash them (`git stash push -m "auto-stash-refacil"`). Do NOT stash without approval.
75
- 3. Detect the effective configuration by running:
76
- ```
77
- refacil-sdd-ai sdd config --json
78
- ```
79
- Parse `baseBranch` and `protectedBranches` from the JSON output.
80
- If the command fails or exits non-zero, fall back to:
81
- - `protectedBranches` = [master, main]
82
- - `baseBranch` = main (or master if main does not exist in the repo)
83
- 4. Determine the base branch:
84
- - Use the `baseBranch` value from the config (or the fallback).
85
- - 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.
86
- 5. Compose the branch name with `feature/` prefix:
87
- - Feature: `feature/<ID>` (e.g. `feature/SEGINF-20`)
88
- - Without ID: propose a short descriptive name (e.g. `feature/add-configurable-branches`)
89
- 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:
90
-
91
- > "I'll create branch `<proposed-name>` from `<base-branch>`. Shall I proceed?"
92
-
93
- ---
57
+ **See `METHODOLOGY-CONTRACT.md §4 — Protected branch policy`** for the complete gate protocol.
94
58
 
95
- **[GATE 3 — execute only after explicit approval from Gate 2]**
59
+ Apply-specific annotations:
60
+ - Default branch name: `feature/<changeName>` (e.g. `feature/my-change`). If the user provides a ticket or ID → `feature/<ID>`.
61
+ - Stash handling: if uncommitted changes exist, inform the user in the same Gate 1+2 message and stash before creating the branch (`git stash push -m "auto-stash-refacil"`), restoring after (`git stash pop`).
62
+ - If the user explicitly says "no" or "cancelar" → stop entirely. Do not create any branch.
96
63
 
97
- Only after the user explicitly confirms (e.g. "yes", "go", "ok", "proceed"):
64
+ ### Step 1.5a: Detect CodeGraph availability (non-blocking)
98
65
 
99
- 1. Switch to the base branch and update it (`git checkout <base>` + `git pull origin <base>`).
100
- 2. Create the working branch (`git checkout -b <branch-name>`).
101
- 3. If a stash was approved in Gate 2, restore it (`git stash pop`).
66
+ Run: `refacil-sdd-ai codegraph status --json`
102
67
 
103
- If the user does not approve at Gate 2, stop entirely. Do not create any branch. Do not continue with implementation.
68
+ Parse the JSON output and set `codegraphAvailable`:
69
+ - `true` if and only if the result contains `"installed": true` AND `"initialized": true`
70
+ - `false` in all other cases (not installed, not initialized, command fails, invalid JSON, or any error)
104
71
 
105
- ---
72
+ **IMPORTANT**: if the index is not available, continue silently — do NOT gate, pause, ask, or wait. Apply does not interrupt for CodeGraph. Unlike `/refacil:propose`, `/refacil:explore`, or `/refacil:bug` (which benefit from graph traversal to discover scope), `/refacil:apply` typically follows a propose that already resolved the architecture. The implementer uses CodeGraph only for structural lookups during implementation, not for scope discovery.
106
73
 
107
74
  ### Step 1.5: Build structured briefing (reduces sub-agent tool calls)
108
75
 
@@ -114,19 +81,11 @@ Before invoking the sub-agent, extract the key context by reading the artifacts.
114
81
  - List of files to **modify** (full paths)
115
82
  3. **Tasks** — read `refacil-sdd/changes/<changeName>/tasks.md`. Extract the full numbered list.
116
83
  4. **`testScope`** — default **`scoped`**. Inspect `$ARGUMENTS` **and** the user message invoking this skill for explicit **whole-repo** regression (e.g. `full`, `all tests`, `whole suite`, `suite completa`, `suite completa del repo`). If present → **`testScope: full`**. Otherwise **`scoped`**.
117
- 5. **`testCommand`** — read `refacil-prereqs/METHODOLOGY-CONTRACT.md` §3 for the baseline. If **`testScope: full`**, set **`testCommand`** to that baseline verbatim. If **`scoped`**, build a **narrowed** command per **§3.1** and the builder below (**never** silently run workspace-wide/monorepo root scripts that fan out to every package unless **every** scoped path warrants it pick the smallest roots that cover **`scope.create` `scope.modify`**).
118
- 6. **Architecture context** — read `.agents/stack.md` if it exists; if not, `.agents/architecture.md`; if neither exists, read only the first 60 lines of `AGENTS.md`. **Do not read the entire `.agents/` folder**.
84
+ 5. **`testBaselineCommand`** — resolve the §3 baseline command language-agnostically at the **affected component root** (nearest ancestor of the files in `scope.create`/`scope.modify` with a stack manifest per §3 component principle). Pass it verbatim. The implementer derives its own smoke command dynamically after editing the BRIEFING must NOT include a precomputed `smokeTestCommand`. Do not pre-narrow the baseline here; narrowing is the implementer's responsibility.
119
85
 
120
- #### Scoped `testCommand` builder (apply complements §3.1)
86
+ > **Note — component-rooted, no pre-narrowing**: the wrapper resolves the baseline at the component root (not necessarily the monorepo root). The implementer uses `git diff`/`git status` after editing to discover the actual touched files, then calls `sdd test-scope` itself (which handles the `cd <component>` prefix automatically). This keeps the BRIEFING minimal and makes the smoke reflect what was *actually* changed in this run.
121
87
 
122
- 1. **Baseline** — command from METHODOLOGY-CONTRACT §3 detection (respect `AGENTS.md` if it defines tests).
123
- 2. **`T`** — sorted unique **`scope.create` ∪ `scope.modify`**. Omit entries that clearly do not justify a test run (`refacil-sdd/**/*.md` planning-only, etc.).
124
- 3. If **`testScope: full`** or **`T`** is empty: **`testCommand` = baseline** (omit **`verificationWarning`** unless you document user intent).
125
- 4. If **`scoped`** and **`T`** non-empty**:
126
- - Prefer **narrowing instructions** documented in **`AGENTS.md`** or **`.agents/testing.md`** when present (follow them strictly).
127
- - Otherwise use stack-aware suffixes/path filters documented for that toolchain (examples: **`pnpm exec jest`** / **`npm test`** with **`--`** + dirs or **`--testPathPattern`**, **`pytest`** paths, **`go test ./rel/...`**, **`cargo test -p member`**, **Gradle `-p`/`--tests`**, **Maven `-pl`/`-Dtest=`** — see METHODOLOGY-CONTRACT §3.1 **Scoped command patterns**).
128
- - Pick the **smallest** dirs/modules covering all of **`T`**; include explicit test files from **`T`** when they exist.
129
- - If narrowing is unsafe: **`testCommand` = baseline** and set **`verificationWarning: Scoped narrowing unavailable — falling back to baseline suite (high CPU/RAM)`**.
88
+ 6. **Architecture context** — read `.agents/stack.md` if it exists; if not, `.agents/architecture.md`; if neither exists, read only the first 60 lines of `AGENTS.md`. **Do not read the entire `.agents/` folder**.
130
89
 
131
90
  Build the BRIEFING block that you will include literally in the delegation prompt:
132
91
 
@@ -137,14 +96,16 @@ objective: <objective in 1-2 sentences from the proposal>
137
96
  scope:
138
97
  create: [path/new-file-1.ts, path/new-file-2.ts, ...]
139
98
  modify: [path/existing-1.ts, path/existing-2.ts, ...]
140
- doNotTouch: [refacil-sdd/, .claude/, .cursor/, AGENTS.md, package-lock.json]
99
+ doNotTouch: [refacil-sdd/, .claude/, .cursor/, .opencode/, AGENTS.md, package-lock.json]
100
+ # Note: also do not modify global Codex user dir (~/.codex/) — skills/agents/hooks are outside the repo.
141
101
  tasks:
142
102
  1. <task 1>
143
103
  2. <task 2>
144
104
  ...
145
105
  testScope: scoped | full
146
- testCommand: <exact shell command Step 5narrowed when scoped>
147
- verificationWarning: <optional set when scoped fallback hits baseline suite>
106
+ testBaselineCommand: <project baseline from METHODOLOGY-CONTRACT.md §3the implementer derives the smoke dynamically>
107
+ codegraphAvailable: true | false
108
+ verificationWarning: <optional — set if applicable>
148
109
  architectureContext: |
149
110
  <extract from stack.md or first lines of AGENTS.md>
150
111
  specsNote: <"specs.md" | "specs/**/*.md" | "both — report contradictions in issues">
@@ -176,6 +137,20 @@ This command merges into memory.yaml at the repo root using `findProjectRoot()`
176
137
 
177
138
  If `result` is `"FAILED"`, skip and wait for user instructions.
178
139
 
140
+ ### Step 2.6: Log CodeGraph telemetry (silent)
141
+
142
+ After parsing the `refacil-apply-result` block, run **once** (do not mention it to the user unless it fails):
143
+
144
+ ```bash
145
+ refacil-sdd-ai compact log-codegraph-event --skill implementer --has-graph <codegraphAvailable> --tool-calls <N> --tokens <N>
146
+ ```
147
+
148
+ - `--has-graph`: use the `codegraphAvailable` value detected in Step 1.5a (`true` or `false`).
149
+ - `--tool-calls`: number of `codegraph_*` tool calls the sub-agent made (0 if it did not use the graph).
150
+ - `--tokens`: conservative estimate of tokens saved (~800–1500 per useful tool call; 0 if no graph or no calls).
151
+
152
+ 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.
153
+
179
154
  ### Step 3: Present result and next step
180
155
 
181
156
  Show the user the **report** (everything before the `refacil-apply-result` block). Do not show the JSON block — it is internal metadata.
@@ -197,4 +172,4 @@ If the sub-agent returned `result: "PARTIAL"` or `"FAILED"`, present the `issues
197
172
  - **Always build the briefing (Step 1.5) before delegating** — it is the key piece that reduces the sub-agent cost.
198
173
  - **Always delegate implementation to the sub-agent**. Do not replicate implementation logic or SDD artifact-apply logic here.
199
174
  - Even when artifacts are Spanish, implementation output is English-only: created file/folder names, source code, test code, identifiers, and code comments.
200
- - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question in Step 3, immediately invoke the **Skill tool** with `skill: "refacil:test"`. Do not describe it in text or wait for the user to type `/refacil:test`. (See `METHODOLOGY-CONTRACT.md §5`.)
175
+ - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question in Step 3, immediately execute `/refacil:test`. Do not describe it in text or wait for the user to type it. (See `METHODOLOGY-CONTRACT.md §5`.)
@@ -6,12 +6,16 @@ user-invocable: true
6
6
 
7
7
  # refacil:archive — Archive Completed Change
8
8
 
9
- This command archives completed SDD changes (bug fixes manually, regular changes via `refacil-sdd-ai sdd archive`), syncs `refacil-sdd/specs/`, and enforces team pre-verification checks.
9
+ This command archives completed SDD changes through `refacil-sdd-ai sdd archive <changeName>`, syncs `refacil-sdd/specs/`, and enforces team pre-verification checks.
10
10
 
11
11
  **Prerequisites**: `sdd` profile from `refacil-prereqs/SKILL.md` + rules from `METHODOLOGY-CONTRACT.md`.
12
12
 
13
13
  ## Instructions
14
14
 
15
+ ### Step 0: Autopilot mode detection
16
+
17
+ Try to read `refacil-sdd/.autopilot-active`. If the file exists and its `changeName` field matches the change being archived → `autopilotMode = true`, extract `taskReference` from the file. Otherwise `autopilotMode = false` (normal mode, ask user as usual).
18
+
15
19
  ### Step 1: Pre-verification checks
16
20
 
17
21
  Before archiving, run `refacil-sdd-ai sdd status <changeName> --json` and parse the JSON to get the change status.
@@ -20,7 +24,18 @@ Verify the change is truly complete:
20
24
 
21
25
  1. **Tasks completed**: Use the `tasksProgress` (or `tasks`) field from the JSON — verify that `tasks.pending === 0`. If there are incomplete tasks, inform the user and ask if they want to continue anyway.
22
26
 
23
- 2. **Tests pass**: Resolve and run the test command according to `refacil-prereqs/METHODOLOGY-CONTRACT.md`. If there are failing tests, inform and ask if they want to continue.
27
+ 2. **Current `/refacil:test` evidence**: Do not re-run the test suite by default. Run `refacil-sdd-ai sdd get-memory <changeName> --json` and verify that:
28
+ - `memory.lastStep` is `test`, `verify`, or `review` (test evidence remains valid after later validation phases if it is still fresh).
29
+ - `memory.commandsRun` is present and non-empty.
30
+ - `memory.criteriaRun` is an array with at least one covered CA/CR criterion.
31
+ - `memory.touchedFiles`, when present, still covers the files currently changed for this SDD change.
32
+ - The evidence is fresh: no relevant changed file was modified after the recorded `/refacil:test` evidence. Use reliable timestamps, hashes, or an equivalent snapshot when available. If freshness cannot be proven, treat the evidence as stale.
33
+
34
+ If the evidence is current, archive may continue and should report `Tests: PASS (from /refacil:test evidence: <commandsRun>)`.
35
+
36
+ If evidence is missing or stale:
37
+ - `autopilotMode = false`: stop and ask the user whether to run `/refacil:test` now or explicitly continue without current test evidence. Do not silently run tests.
38
+ - `autopilotMode = true`: abort archiving with a clear error: `Cannot archive in autopilot: current /refacil:test evidence is missing or stale.` Do not ask the user and do not re-run tests.
24
39
 
25
40
  3. **Working tree scope hygiene**: Run `git status` and check whether there are files unrelated to the current change scope. It is expected to have uncommitted changes in this step. If unrelated files are detected, warn the user and ask whether to continue archiving anyway. Do not suggest commit in this step; commit/push decisions are handled in `refacil:up-code`.
26
41
 
@@ -31,57 +46,62 @@ Verify the change is truly complete:
31
46
  ```
32
47
  This verification is **mandatory and blocking** — it cannot be skipped.
33
48
 
34
- If any of checks 1-3 fail, inform the user but allow them to decide whether to continue.
49
+ If any of checks 1-3 fail, inform the user but allow them to decide whether to continue, except missing/stale test evidence in autopilot mode, which is blocking.
35
50
  If check 4 fails, archiving cannot continue.
36
51
 
37
52
  ### Step 1.5: Request task reference(s) (traceability — mandatory)
38
53
 
39
- Before proceeding to archiving, ask the user for the task reference(s) associated with the change (URL, issue/ticket number, or short task name):
54
+ - `autopilotMode = true`: use `taskReference` from `refacil-sdd/.autopilot-active` directly. Do NOT ask the user. Set `taskReferences = [taskReference]` and continue.
40
55
 
41
- ```
42
- Task reference(s) associated with this change (URL, ticket number, or task name; if multiple, separate with commas):
43
- ```
44
-
45
- **Rules:**
46
- - The user may enter one or multiple references separated by commas in a single message.
47
- - Accepted formats: URL (`https://tracker.company.com/TASK-123`), identifier (`TASK-123`, `INC-9001`), or short descriptive name (`ajuste checkout`).
48
- - Minimum validation rule for each reference (operational and mandatory):
49
- - `URL`: starts with `http://` or `https://` and has at least one non-space character after the protocol.
50
- - `identifier`: matches `^[A-Za-z][A-Za-z0-9_-]*-\d+$` (examples: `BP-4610`, `INC-9001`).
51
- - `short name`: 3-80 characters, includes at least one letter, and is not only symbols/spaces.
52
- - If the user provides no reference (answers empty, "n", "no", "none", blank Enter), **block the archiving** and ask again:
53
- ```
54
- Cannot archive without at least one task reference.
55
- Provide the task URL, identifier, or name that originated this change to continue.
56
- ```
57
- - If the user provides a non-empty but invalid value (for example: `---`, `???`, `123`, `_`), **reject it** and ask again:
56
+ - `autopilotMode = false` (normal): ask the user for the task reference(s) associated with the change (URL, issue/ticket number, or short task name):
58
57
  ```
59
- Invalid task reference format.
60
- Use one of: URL (https://...), identifier (ABC-123), or short task name (3-80 chars, includes letters).
58
+ Task reference(s) associated with this change (URL, ticket number, or task name; if multiple, separate with commas):
61
59
  ```
62
- - Repeat until at least one valid reference is received.
63
- - Save the references in `taskReferences` to use when writing `review.yaml` in the following steps.
60
+
61
+ **Rules:**
62
+ - The user may enter one or multiple references separated by commas in a single message.
63
+ - Accepted formats: URL (`https://tracker.company.com/TASK-123`), identifier (`TASK-123`, `INC-9001`), or short descriptive name (`checkout-adjustment`).
64
+ - Minimum validation rule for each reference (operational and mandatory):
65
+ - `URL`: starts with `http://` or `https://` and has at least one non-space character after the protocol.
66
+ - `identifier`: matches `^[A-Za-z][A-Za-z0-9_-]*-\d+$` (examples: `BP-4610`, `INC-9001`).
67
+ - `short name`: 3-80 characters, includes at least one letter, and is not only symbols/spaces.
68
+ - If the user provides no reference (answers empty, "n", "no", "none", blank Enter), **block the archiving** and ask again:
69
+ ```
70
+ Cannot archive without at least one task reference.
71
+ Provide the task URL, identifier, or name that originated this change to continue.
72
+ ```
73
+ - If the user provides a non-empty but invalid value (for example: `---`, `???`, `123`, `_`), **reject it** and ask again:
74
+ ```
75
+ Invalid task reference format.
76
+ Use one of: URL (https://...), identifier (ABC-123), or short task name (3-80 chars, includes letters).
77
+ ```
78
+ - Repeat until at least one valid reference is received.
79
+ - Save the references in `taskReferences` to use when writing `review.yaml` in the following steps.
64
80
 
65
81
  ### Step 2: Determine change type
66
82
 
67
83
  Inspect the change folder in `refacil-sdd/changes/`:
68
84
 
69
- - **It is a bug fix** if the folder name starts with `fix-` (created by `refacil:bug`).
70
- - **It is a regular change** in any other case (created by `refacil:propose`).
85
+ - First inspect the artifact structure, then classify:
86
+ - **Full SDD artifact set present** (`proposal.md`, `specs.md`, `design.md`, and `tasks.md`) → **regular change**, even when the folder name starts with `fix-`.
87
+ - Example: `fix-seginf-20` containing `proposal.md` + `specs.md` + `design.md` + `tasks.md` → treat as **regular change** and follow Step 2B.
88
+ - **Minimal bug-fix artifact set** (`summary.md` exists and the full SDD artifact set is absent) → **bug fix**.
89
+ - Example: `fix-null-pointer-pay` containing only `summary.md` (and optionally `.review-passed`) → treat as **bug fix** and follow Step 2A.
90
+ - Any other incomplete or ambiguous structure → stop and report the missing artifacts; do not guess from the folder prefix alone.
71
91
 
72
92
  Depending on the type, follow the corresponding step:
73
93
 
74
94
  ### Step 2A: Bug fix → Archive with native CLI
75
95
 
76
- Bug fixes only contain `summary.md` (and optionally `.review-passed`). The CLI `refacil-sdd-ai sdd archive` handles the folder move internally with its own `findProjectRoot()`, so there is no need for manual `mv` — use the CLI for the move, and only write specs/review.yaml manually (the CLI does not cover those).
96
+ Minimal bug fixes only contain `summary.md` (and optionally `.review-passed`) and do not include the full SDD artifact set. The CLI `refacil-sdd-ai sdd archive` handles the folder move internally with its own `findProjectRoot()`, so use the CLI for the move, and only write specs/review.yaml yourself (the CLI does not cover those).
77
97
 
78
98
  0. **Read artifacts before archiving**: read `summary.md` and `.review-passed` from `refacil-sdd/changes/[fix-name]/` **now**, before the CLI moves the folder. The archived path will be different.
79
99
 
80
- 1. **Archive with the CLI** — let the CLI handle the move (it automatically deletes memory.yaml if present):
100
+ 1. **Archive with the CLI** — let the CLI handle the move (it preserves `memory.yaml` by moving the complete change directory):
81
101
  ```bash
82
102
  refacil-sdd-ai sdd archive [fix-name]
83
103
  ```
84
- The CLI resolves the repo root internally, deletes memory.yaml if present, moves the folder to `refacil-sdd/changes/archive/[ISO-date]-[fix-name]/`, and exits with code 0 on success. If it exits non-zero, stop and report the error to the user.
104
+ The CLI resolves the repo root internally, **skips spec sync** for `fix-*` (no `specs.md` in the change folder), preserves `memory.yaml` if present, moves the folder to `refacil-sdd/changes/archive/[ISO-date]-[fix-name]/`, and exits with code 0 on success. If it exits non-zero, stop and report the error to the user.
85
105
 
86
106
  2. **Document in specs**: using the content read in step 0, create an individual spec at `$(git rev-parse --show-toplevel)/refacil-sdd/specs/[descriptive-name]/spec.md`.
87
107
 
@@ -124,17 +144,21 @@ Bug fixes only contain `summary.md` (and optionally `.review-passed`). The CLI `
124
144
 
125
145
  ### Step 2B: Regular change → Archive with native CLI
126
146
 
127
- The spec and review evidence are written **before** running the CLI archive command, while the artifacts are still at their original paths. The CLI only moves the folder — it never syncs specs.
128
-
129
147
  `refacil-sdd-ai sdd archive` normalizes the provided `changeName` to lowercase before validation/path resolution. Prefer lowercase names for consistency across commands and records.
130
148
 
131
- 1. **Sync spec to `refacil-sdd/specs/` (before archiving)**:
132
- - Read `refacil-sdd/changes/<changeName>/specs.md` (and all `.md` under `specs/` if that subfolder exists).
133
- - Determine the spec folder name: use `<changeName>` unless a more descriptive name is clearly better.
134
- - If `refacil-sdd/specs/<specName>/spec.md` already exists, integrate the changes (ADDED add, MODIFIED update, REMOVED delete sections).
135
- - If it does NOT exist, create `refacil-sdd/specs/<specName>/spec.md` with the content derived from `specs.md` (convert acceptance/rejection criteria into Requirements + Scenarios format).
149
+ **Spec sync (CLI mandatory, same language as change artifacts)**:
150
+
151
+ - `sdd archive` runs **`refacil-sdd-ai sdd sync-spec <changeName>` automatically** before moving the folder.
152
+ - The CLI copies CA/CR blocks from `specs.md` or `specs/**/*.md` into `refacil-sdd/specs/<changeName>/spec.md` using catalog headings that match the change artifact language (Spanish vs English section titles see `sdd sync-spec` / METHODOLOGY-CONTRACT).
153
+ - **Do NOT translate or rewrite** the criteria in another language. Structural conversion only (Gherkin keywords stay as written in the source artifacts).
154
+ - Language is detected from the change proposal heading marker (Spanish vs English template), not invented by the agent.
155
+ - To sync without archiving: `refacil-sdd-ai sdd sync-spec <changeName>`.
156
+
157
+ 1. **Verify spec sync output** (after archive, or run `sync-spec` manually first):
158
+ - Confirm `refacil-sdd/specs/<changeName>/spec.md` exists and matches the language of the archived change specs.
159
+ - Do **not** replace CLI output with an agent-written English summary.
136
160
 
137
- 2. **Persist review evidence (before archiving)**:
161
+ 2. **Persist review evidence (before or after archive)**:
138
162
  - Read `refacil-sdd/changes/<changeName>/.review-passed` (dotfile — use `ls -la` or read by explicit path, not directory listing).
139
163
  - Create/update `refacil-sdd/specs/<specName>/review.yaml` with its fields plus `taskReferences` from Step 1.5:
140
164
  ```yaml
@@ -150,7 +174,7 @@ The spec and review evidence are written **before** running the CLI archive comm
150
174
  ```
151
175
  - If `review.yaml` already exists, update only the fields that changed without removing others.
152
176
 
153
- 3. **Run the CLI archive**: `refacil-sdd-ai sdd archive <changeName>` — the CLI automatically deletes memory.yaml if present, then moves the change to `refacil-sdd/changes/archive/<date>-<changeName>/`.
177
+ 3. **Run the CLI archive**: `refacil-sdd-ai sdd archive <changeName>` — sync-spec, preserves `memory.yaml` if present, then moves the complete change directory to `refacil-sdd/changes/archive/<date>-<changeName>/`.
154
178
  4. Verify the command completed successfully (exit 0) and the original folder no longer exists.
155
179
 
156
180
  5. Continue to **Step 3**.
@@ -162,7 +186,7 @@ The goal is for `refacil-sdd/specs/` to document how the system works TODAY.
162
186
  Before showing the summary, run a **final cleanup verification** (applies to both bug fixes and regular changes):
163
187
 
164
188
  - `$(git rev-parse --show-toplevel)/refacil-sdd/changes/[original-name]/` **must NOT exist** (only the archived version must survive in `refacil-sdd/changes/archive/...`).
165
- - If the source folder survived for any reason (failed move, partial copy, interrupted move), explicitly delete it with `rm -rf "$(git rev-parse --show-toplevel)/refacil-sdd/changes/[original-name]"` before confirming to the user.
189
+ - If the source folder survived for any reason (failed move, partial copy, interrupted move), do not claim success. Stop, report the residue path, and ask the user whether to remove it after they inspect the archived copy.
166
190
 
167
191
  ```
168
192
  === Change archived ===
@@ -171,25 +195,27 @@ Before showing the summary, run a **final cleanup verification** (applies to bot
171
195
  Location: refacil-sdd/changes/archive/[date]-[name]/
172
196
  Original folder deleted: YES
173
197
  Specs synced: YES
174
- Tests: PASS
198
+ Tests: PASS (from /refacil:test evidence)
175
199
 
176
200
  The change has been completed and archived successfully.
177
201
  ```
178
202
 
179
203
  ### Step 4: Recommend pushing the code
180
204
 
181
- After confirming the archiving, recommend the user push the changes to the remote:
205
+ After confirming the archiving:
182
206
 
183
- ```
184
- The next step is to push the change and create the PR.
185
- Do you want me to continue with /refacil:up-code?
186
- ```
207
+ - `autopilotMode = false` (normal): ask the user:
208
+ ```
209
+ The next step is to push the change and create the PR.
210
+ Do you want me to continue with /refacil:up-code?
211
+ ```
212
+ - `autopilotMode = true`: proceed to `/refacil:up-code` immediately without asking.
187
213
 
188
214
  ## Rules
189
215
 
190
216
  - Always verify completeness before archiving
191
- - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question in Step 4, immediately invoke the **Skill tool** with `skill: "refacil:up-code"`. Do not describe it in text or wait for the user to type `/refacil:up-code`. (See `METHODOLOGY-CONTRACT.md §5`.)
217
+ - **Flow continuity**: if the user confirms affirmatively ("yes", "ok", "go", "continue", etc.) the continuity question in Step 4, immediately execute `/refacil:up-code`. Do not describe it in text or wait for the user to type it. (See `METHODOLOGY-CONTRACT.md §5`.)
192
218
  - Spec synchronization is MANDATORY in the Refacil methodology
193
219
  - The `.review-passed` metadata must be persisted separately in YAML (`review.yaml`) inside each spec folder
194
220
  - Do not delete artifacts, only move them to archive/ for traceability
195
- - **The original folder in `refacil-sdd/changes/[name]/` must NOT survive archiving** — neither for bug fixes (Step 2A) nor for regular changes (Step 2B). Use `git mv` or `mv` (not `cp -r`) and verify explicitly. If residue remains, delete it with `rm -rf` before Step 3.
221
+ - **The original folder in `refacil-sdd/changes/[name]/` must NOT survive archiving** — neither for bug fixes (Step 2A) nor for regular changes (Step 2B). Use the native CLI move and verify explicitly. If residue remains, stop and report it instead of performing an automatic destructive cleanup.
@@ -53,23 +53,56 @@ This framing increases response quality and reduces back-and-forth.
53
53
  When the question is about cross-repo integration contracts, draft the `--text` using this minimal template:
54
54
 
55
55
  ```text
56
- integrationPoint: <endpoint/event/queue + direction X->Y or Y->X>
57
- inputContract: <required/optional fields + key validation rules>
58
- outputContract: <expected output/status/errors>
59
- compatibility: <version/flags/env constraints or "unknown">
60
- sourceOfTruthRequest: <where to confirm in destination repo>
61
- question: <concrete doubt to resolve>
56
+ integrationPoint: [endpoint/event/queue + direction X->Y or Y->X]
57
+ inputContract: [required/optional fields + key validation rules]
58
+ outputContract: [expected output/status/errors]
59
+ compatibility: [version/flags/env constraints or "unknown"]
60
+ sourceOfTruthRequest: [where to confirm in destination repo]
61
+ question: [concrete doubt to resolve]
62
62
  ```
63
63
 
64
64
  If some fields are unknown, send `unknown` explicitly — do not invent values.
65
65
 
66
+ ## Safe bus text delivery
67
+
68
+ **Use `--text` for simple messages** (no special characters, single-line):
69
+ ```bash
70
+ refacil-sdd-ai bus ask --to [destination] --text "Simple question here"
71
+ ```
72
+
73
+ **Do NOT use `<` or `>` inside `--text`** — shells may interpret them as redirection operators and truncate or discard the message.
74
+
75
+ For messages containing `<`, `>`, `|`, newlines, or other special characters, use `--from-env`:
76
+
77
+ **PowerShell (Windows)**:
78
+ ```powershell
79
+ $env:BUS_TEXT = "integrationPoint: POST /api/pay -> processor`ninputContract: amount<number>, currency<string>"
80
+ refacil-sdd-ai bus ask --to [destination] --from-env BUS_TEXT
81
+ Remove-Item Env:BUS_TEXT
82
+ ```
83
+
84
+ **bash (inline, preferred — automatic cleanup)**:
85
+ ```bash
86
+ BUS_TEXT="integrationPoint: POST /api/pay -> processor
87
+ inputContract: amount<number>" refacil-sdd-ai bus ask --to [destination] --from-env BUS_TEXT
88
+ ```
89
+
90
+ **bash (export + unset alternative)**:
91
+ ```bash
92
+ export BUS_TEXT="message with <special> chars"
93
+ refacil-sdd-ai bus ask --to [destination] --from-env BUS_TEXT
94
+ unset BUS_TEXT
95
+ ```
96
+
97
+ > Note: the CLI cannot perform cleanup itself — it runs as a child process and cannot modify the parent shell's environment. Cleanup (`Remove-Item` / `unset`) is the responsibility of the invoking script or shell.
98
+
66
99
  ### Step 2: Decide whether to use `--wait`
67
100
 
68
101
  Two modes:
69
102
 
70
103
  **Blocking mode (recommended when you need the response to continue)**:
71
104
  ```bash
72
- refacil-sdd-ai bus ask --to <destination> --text "<question>" --wait 180
105
+ refacil-sdd-ai bus ask --to [destination] --text "[question]" --wait 180
73
106
  ```
74
107
  - The CLI blocks until it receives the response or the timeout passes (default suggested: 60-180s)
75
108
  - If the other side is in `/refacil:attend`, the response comes back automatically
@@ -78,7 +111,7 @@ refacil-sdd-ai bus ask --to <destination> --text "<question>" --wait 180
78
111
 
79
112
  **Fire-and-forget mode**:
80
113
  ```bash
81
- refacil-sdd-ai bus ask --to <destination> --text "<question>"
114
+ refacil-sdd-ai bus ask --to [destination] --text "[question]"
82
115
  ```
83
116
  - Does not block; returns immediately after sending
84
117
  - Use it when you do not know if the other side is active or you do not need the response now
@@ -103,3 +136,5 @@ Use `Bash` with the chosen command.
103
136
  - If you **agreed** with another session that they will change their repo, they must use **`/refacil:propose`** there and **notify you via bus** when done; if they request changes from you, you do the same here. Full convention: `refacil-prereqs/BUS-CROSS-REPO.md`.
104
137
  - **`ask`s that are change requests** must be **substantive in scope** (Step 1.5): the recipient already uses the methodology; do not repeat the guide in the text. Do not use the bus to request opaque quick fixes when the impact requires SDD-AI.
105
138
  - For cross-repo contract clarifications, prefer Step 1.7 template. The same structure should also be expected in replies to ease retries.
139
+ - **Cross-repo contracts, bug reports, and actionable content ALWAYS use `bus ask --to SESSION`**, never `bus say`. `say` is a broadcast-only announcement with no delivery guarantee for late-joining sessions and no inbox visibility. If the content is extensive, split it into numbered parts, each as an independent `ask`.
140
+ - Do not use `<` or `>` inside `--text` arguments. Use `--from-env` instead (see "Safe bus text delivery" above).