@opengsd/gsd-core 1.9.0 → 1.10.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 (223) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -3
  3. package/.opencode/plugins/gsd-core.js +8 -1
  4. package/agents/gsd-code-fixer.md +131 -34
  5. package/agents/gsd-debugger.md +12 -246
  6. package/agents/gsd-executor.md +7 -5
  7. package/agents/gsd-integration-checker.md +3 -0
  8. package/agents/gsd-plan-checker.md +9 -0
  9. package/agents/gsd-planner.md +5 -8
  10. package/agents/gsd-roadmapper.md +21 -3
  11. package/agents/gsd-verifier.md +14 -70
  12. package/bin/install.js +503 -341
  13. package/commands/gsd/mempalace-capture.md +1 -1
  14. package/commands/gsd/new-milestone.md +1 -1
  15. package/commands/gsd/plan-phase.md +1 -1
  16. package/gsd-core/bin/gsd-tools.cjs +607 -63
  17. package/gsd-core/bin/lib/active-workstream-store.cjs +25 -0
  18. package/gsd-core/bin/lib/agent-install-check.cjs +38 -6
  19. package/gsd-core/bin/lib/api-coverage.cjs +120 -0
  20. package/gsd-core/bin/lib/audit.cjs +89 -1
  21. package/gsd-core/bin/lib/broken-windows.cjs +36 -6
  22. package/gsd-core/bin/lib/capability-registry.cjs +96 -110
  23. package/gsd-core/bin/lib/capability-validator.cjs +12 -2
  24. package/gsd-core/bin/lib/check-command-router.cjs +43 -1
  25. package/gsd-core/bin/lib/command-aliases.cjs +72 -0
  26. package/gsd-core/bin/lib/commands.cjs +26 -25
  27. package/gsd-core/bin/lib/commonjs-marker.cjs +136 -0
  28. package/gsd-core/bin/lib/config-loader.cjs +1 -0
  29. package/gsd-core/bin/lib/config.cjs +12 -1
  30. package/gsd-core/bin/lib/context-composer.cjs +278 -0
  31. package/gsd-core/bin/lib/context-predicates.cjs +506 -0
  32. package/gsd-core/bin/lib/core-utils.cjs +91 -12
  33. package/gsd-core/bin/lib/docs.cjs +3 -2
  34. package/gsd-core/bin/lib/external-job.cjs +19 -4
  35. package/gsd-core/bin/lib/frontmatter.cjs +84 -12
  36. package/gsd-core/bin/lib/gate-predicate-evaluator.cjs +57 -6
  37. package/gsd-core/bin/lib/git-base-branch.cjs +58 -15
  38. package/gsd-core/bin/lib/graphify.cjs +142 -27
  39. package/gsd-core/bin/lib/gsd2-import.cjs +27 -4
  40. package/gsd-core/bin/lib/host-integration.cjs +13 -1
  41. package/gsd-core/bin/lib/init-command-router.cjs +83 -8
  42. package/gsd-core/bin/lib/init.cjs +1021 -57
  43. package/gsd-core/bin/lib/install-engine.cjs +64 -10
  44. package/gsd-core/bin/lib/install-profiles.cjs +27 -1
  45. package/gsd-core/bin/lib/installer-migration-authoring.cjs +3 -1
  46. package/gsd-core/bin/lib/installer-migration-report.cjs +4 -0
  47. package/gsd-core/bin/lib/installer-migrations/007-retire-config-root-commonjs-marker.cjs +149 -0
  48. package/gsd-core/bin/lib/installer-migrations/008-cursor-retire-commands-surface.cjs +55 -0
  49. package/gsd-core/bin/lib/installer-migrations/009-pi-retire-reserved-hooks-dir.cjs +199 -0
  50. package/gsd-core/bin/lib/installer-migrations.cjs +87 -1
  51. package/gsd-core/bin/lib/io.cjs +28 -3
  52. package/gsd-core/bin/lib/markdown-sectionizer.cjs +6 -0
  53. package/gsd-core/bin/lib/mcp-catalog.cjs +518 -0
  54. package/gsd-core/bin/lib/mcp-server.cjs +135 -3
  55. package/gsd-core/bin/lib/milestone.cjs +106 -51
  56. package/gsd-core/bin/lib/phase-id.cjs +63 -0
  57. package/gsd-core/bin/lib/phase-locator.cjs +138 -45
  58. package/gsd-core/bin/lib/phase.cjs +260 -25
  59. package/gsd-core/bin/lib/plan-dependency-graph.cjs +232 -0
  60. package/gsd-core/bin/lib/planning-workspace.cjs +4 -0
  61. package/gsd-core/bin/lib/project-root.cjs +48 -0
  62. package/gsd-core/bin/lib/prompt-budget.cjs +128 -165
  63. package/gsd-core/bin/lib/retired-artifact-cleanup.cjs +80 -0
  64. package/gsd-core/bin/lib/review-lane-descriptor.cjs +99 -0
  65. package/gsd-core/bin/lib/review-lane-runner.cjs +30 -6
  66. package/gsd-core/bin/lib/roadmap-command-router.cjs +42 -9
  67. package/gsd-core/bin/lib/roadmap-parser.cjs +100 -18
  68. package/gsd-core/bin/lib/roadmap.cjs +37 -7
  69. package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +195 -62
  70. package/gsd-core/bin/lib/runtime-artifact-layout.cjs +15 -3
  71. package/gsd-core/bin/lib/runtime-homes.cjs +154 -41
  72. package/gsd-core/bin/lib/runtime-hooks-surface.cjs +105 -41
  73. package/gsd-core/bin/lib/section-manifest.cjs +209 -0
  74. package/gsd-core/bin/lib/shell-command-projection.cjs +113 -27
  75. package/gsd-core/bin/lib/smart-entry.cjs +12 -0
  76. package/gsd-core/bin/lib/state-transition.cjs +73 -8
  77. package/gsd-core/bin/lib/state.cjs +151 -62
  78. package/gsd-core/bin/lib/surface.cjs +12 -1
  79. package/gsd-core/bin/lib/uat-predicate.cjs +11 -1
  80. package/gsd-core/bin/lib/uat.cjs +320 -21
  81. package/gsd-core/bin/lib/unusable-input.cjs +9 -0
  82. package/gsd-core/bin/lib/verification.cjs +29 -12
  83. package/gsd-core/bin/lib/verify.cjs +29 -5
  84. package/gsd-core/bin/lib/workflow-fragments.cjs +557 -0
  85. package/gsd-core/bin/lib/workstream-inventory-builder.cjs +181 -18
  86. package/gsd-core/bin/lib/workstream-inventory.cjs +519 -27
  87. package/gsd-core/bin/lib/workstream.cjs +6 -0
  88. package/gsd-core/bin/lib/worktree-base-ref.cjs +50 -6
  89. package/gsd-core/bin/lib/worktree-safety.cjs +276 -118
  90. package/gsd-core/bin/shared/config-schema.manifest.json +2 -0
  91. package/gsd-core/references/artifact-types.md +10 -3
  92. package/gsd-core/references/autonomous-ui-design-contract.md +42 -0
  93. package/gsd-core/references/debugger-techniques.md +255 -0
  94. package/gsd-core/references/research-documentation-lookup.md +5 -3
  95. package/gsd-core/references/specless-probe-fallback.md +7 -6
  96. package/gsd-core/references/verifier-wiring-patterns.md +100 -0
  97. package/gsd-core/references/worktree-branch-check.md +2 -2
  98. package/gsd-core/templates/summary-complex.md +2 -0
  99. package/gsd-core/templates/summary-minimal.md +2 -0
  100. package/gsd-core/templates/summary-standard.md +2 -0
  101. package/gsd-core/templates/summary.md +2 -0
  102. package/gsd-core/workflows/audit-milestone.md +3 -0
  103. package/gsd-core/workflows/autonomous/steps/converge-banner.md +1 -0
  104. package/gsd-core/workflows/autonomous/steps/converge-dispatch-bg.md +11 -0
  105. package/gsd-core/workflows/autonomous/steps/converge-dispatch-inline.md +7 -0
  106. package/gsd-core/workflows/autonomous/steps/converge-fail-fast.md +21 -0
  107. package/gsd-core/workflows/autonomous/steps/converge-loop.md +7 -0
  108. package/gsd-core/workflows/autonomous.md +32 -69
  109. package/gsd-core/workflows/code-review/steps/dispatch-fix.md +39 -0
  110. package/gsd-core/workflows/code-review/steps/structural-pre-pass.md +83 -0
  111. package/gsd-core/workflows/code-review.md +42 -145
  112. package/gsd-core/workflows/complete-milestone/steps/git-tag.md +29 -0
  113. package/gsd-core/workflows/complete-milestone.md +23 -81
  114. package/gsd-core/workflows/debug.md +9 -12
  115. package/gsd-core/workflows/diagnose-issues.md +22 -0
  116. package/gsd-core/workflows/discovery-phase.md +4 -4
  117. package/gsd-core/workflows/discuss-phase-assumptions/steps/auto-advance-dispatch.md +15 -0
  118. package/gsd-core/workflows/discuss-phase-assumptions.md +5 -16
  119. package/gsd-core/workflows/docs-update/steps/dispatch-monorepo-packages.md +51 -0
  120. package/gsd-core/workflows/docs-update.md +8 -51
  121. package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +34 -2
  122. package/gsd-core/workflows/execute-phase/steps/gap-closure-artifacts.md +50 -0
  123. package/gsd-core/workflows/execute-phase/steps/partial-wave.md +31 -0
  124. package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +19 -0
  125. package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +42 -0
  126. package/gsd-core/workflows/execute-phase/steps/regression-gate.md +43 -37
  127. package/gsd-core/workflows/execute-phase.md +65 -137
  128. package/gsd-core/workflows/execute-plan.md +1 -1
  129. package/gsd-core/workflows/help/modes/full.md +6 -1
  130. package/gsd-core/workflows/ingest-docs.md +2 -1
  131. package/gsd-core/workflows/new-milestone/steps/project-md-milestone-write.md +16 -0
  132. package/gsd-core/workflows/new-milestone/steps/reset-phase-safety.md +19 -0
  133. package/gsd-core/workflows/new-milestone.md +21 -38
  134. package/gsd-core/workflows/new-project/steps/auto-mode-config.md +176 -0
  135. package/gsd-core/workflows/new-project/steps/auto-mode-detection.md +32 -0
  136. package/gsd-core/workflows/new-project/steps/codebase-map-offer.md +18 -0
  137. package/gsd-core/workflows/new-project.md +13 -226
  138. package/gsd-core/workflows/plan-phase/steps/adr-ingest-express-path.md +15 -0
  139. package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +110 -0
  140. package/gsd-core/workflows/plan-phase/steps/prd-express-gate.md +8 -0
  141. package/gsd-core/workflows/plan-phase/steps/research-only-early-exit.md +17 -0
  142. package/gsd-core/workflows/plan-phase/steps/research-only-modifiers.md +16 -0
  143. package/gsd-core/workflows/plan-phase/steps/reviews-prerequisite.md +17 -0
  144. package/gsd-core/workflows/plan-phase/steps/stall-detection-helpers.md +149 -0
  145. package/gsd-core/workflows/plan-phase.md +49 -193
  146. package/gsd-core/workflows/progress/steps/forensic-audit.md +125 -0
  147. package/gsd-core/workflows/progress/steps/mvp-display.md +18 -0
  148. package/gsd-core/workflows/progress.md +11 -153
  149. package/gsd-core/workflows/quick/steps/discussion-phase.md +124 -0
  150. package/gsd-core/workflows/quick/steps/plan-checker-loop.md +111 -0
  151. package/gsd-core/workflows/quick/steps/quick-verification.md +46 -0
  152. package/gsd-core/workflows/quick/steps/research-phase.md +72 -0
  153. package/gsd-core/workflows/quick/steps/worktree-pre-dispatch-commit.md +37 -0
  154. package/gsd-core/workflows/quick.md +20 -390
  155. package/gsd-core/workflows/resume-project.md +3 -0
  156. package/gsd-core/workflows/review/steps/reviewer-instances-note-1.md +4 -0
  157. package/gsd-core/workflows/review/steps/reviewer-instances-note-2.md +3 -0
  158. package/gsd-core/workflows/review.md +15 -8
  159. package/gsd-core/workflows/section-manifest.json +219 -0
  160. package/gsd-core/workflows/sketch.md +1 -1
  161. package/gsd-core/workflows/spec-phase.md +17 -14
  162. package/gsd-core/workflows/spike-wrap-up.md +20 -5
  163. package/gsd-core/workflows/spike.md +50 -16
  164. package/gsd-core/workflows/sync-skills.md +49 -11
  165. package/gsd-core/workflows/transition/steps/workstream-collision-check.md +17 -0
  166. package/gsd-core/workflows/transition.md +8 -21
  167. package/gsd-core/workflows/ui-phase.md +8 -7
  168. package/gsd-core/workflows/update/steps/channel-banner.md +7 -0
  169. package/gsd-core/workflows/update.md +18 -7
  170. package/gsd-core/workflows/verify-phase.md +4 -7
  171. package/gsd-core/workflows/verify-work/steps/automated-ui-verification.md +36 -0
  172. package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +21 -0
  173. package/gsd-core/workflows/verify-work.md +8 -58
  174. package/hooks/dist/gsd-agent-isolation-guard.js +428 -0
  175. package/hooks/dist/gsd-check-update-worker.js +14 -5
  176. package/hooks/dist/gsd-cursor-subagent-start.js +532 -26
  177. package/hooks/dist/gsd-read-injection-scanner.js +7 -0
  178. package/hooks/dist/gsd-statusline.js +72 -6
  179. package/hooks/dist/gsd-worktree-path-guard.js +2 -1
  180. package/hooks/dist/gsd-write-guard.js +359 -0
  181. package/hooks/dist/lib/isolation-sentinel.js +268 -0
  182. package/hooks/dist/managed-hooks-registry.cjs +2 -0
  183. package/hooks/gsd-agent-isolation-guard.js +428 -0
  184. package/hooks/gsd-check-update-worker.js +14 -5
  185. package/hooks/gsd-cursor-subagent-start.js +532 -26
  186. package/hooks/gsd-read-injection-scanner.js +7 -0
  187. package/hooks/gsd-statusline.js +72 -6
  188. package/hooks/gsd-worktree-path-guard.js +2 -1
  189. package/hooks/gsd-write-guard.js +359 -0
  190. package/hooks/hooks.json +12 -0
  191. package/hooks/lib/isolation-sentinel.js +268 -0
  192. package/hooks/managed-hooks-registry.cjs +2 -0
  193. package/package.json +14 -5
  194. package/pi/gsd.cjs +57 -12
  195. package/scripts/build-hooks.js +9 -0
  196. package/scripts/changeset/lint.cjs +9 -2
  197. package/scripts/changeset/serialize.cjs +5 -1
  198. package/scripts/gen-capability-matrix.cjs +1 -1
  199. package/scripts/gen-context-index.cjs +448 -0
  200. package/scripts/gen-inventory-manifest.cjs +101 -1
  201. package/scripts/gen-prompt-budget-parity-corpus.cjs +645 -0
  202. package/scripts/gen-registry.cjs +39 -15
  203. package/scripts/gen-section-manifest.cjs +638 -0
  204. package/scripts/generate-package-identity.cjs +4 -2
  205. package/scripts/lint-allow-test-rule-refs.allowlist.json +17 -31
  206. package/scripts/lint-compiled-artifact-sync.cjs +6 -1
  207. package/scripts/lint-docs-command-form.cjs +195 -0
  208. package/scripts/lint-docs-required.cjs +9 -1
  209. package/scripts/lint-emitted-drift-ack.cjs +215 -20
  210. package/scripts/lint-example-parser-parity.cjs +395 -0
  211. package/scripts/lint-test-file-count.allowlist.json +27 -1
  212. package/scripts/mutation-matrix.cjs +13 -0
  213. package/scripts/prompt-injection-scan.sh +27 -6
  214. package/scripts/registry-schema.cjs +323 -94
  215. package/scripts/run-tests.cjs +3 -2
  216. package/scripts/validate-registry.cjs +10 -6
  217. package/skills/gsd-autonomous/SKILL.md +1 -1
  218. package/skills/gsd-execute-phase/SKILL.md +1 -1
  219. package/skills/gsd-mempalace-capture/SKILL.md +1 -1
  220. package/skills/gsd-new-milestone/SKILL.md +1 -1
  221. package/skills/gsd-plan-phase/SKILL.md +2 -2
  222. package/vscode/package.json +1 -1
  223. package/scripts/gen-emitted-baseline.cjs +0 -145
@@ -0,0 +1,506 @@
1
+ "use strict";
2
+ /**
3
+ * Context Predicates — CONTEXT.md predicate fact-store parser.
4
+ *
5
+ * Ported from the reference prototype
6
+ * `examples/dynamic-context-management/context-predicates.cjs` (ADR-1671,
7
+ * "Dynamic context management platform", Option-E predicate fact-store).
8
+ * Behavior is preserved BYTE-FOR-BEHAVIOR from the prototype for the parts it
9
+ * shares: `ID_RE`, the first-`=` split, the naive triple-backtick fence
10
+ * toggle, and the `- ` list-item-only form. Known prototype defects are
11
+ * DELIBERATELY carried forward here — a later commit fixes them behind a
12
+ * failing-first test.
13
+ *
14
+ * Two intentional deviations from the prototype (ADR-1671 open question 4):
15
+ * - `Duplicate` carries `count`, not `lines: number[]`.
16
+ * - `ContextIndex.predicates` entries carry `{id, klass, value}` with NO
17
+ * `line` field — a committed artifact with no line numbers cannot drift
18
+ * on a line shift. The live parse result (`Predicate`) still carries
19
+ * `line` and `section`.
20
+ *
21
+ * One addition beyond the prototype: `ParseResult.malformed` collects
22
+ * backtick lines that look like a predicate declaration attempt (contains a
23
+ * backtick-wrapped `id=value`-shaped inner with an `=` at index >= 1) but are
24
+ * rejected, with a distinct named `reason` per rejection class: `empty-value`
25
+ * (e.g. `` `ID=` ``), `empty-segment` (a doubled dot in the id, e.g.
26
+ * `` `A..b=1` ``), `invalid-id-chars` (disallowed characters in the id, e.g. a
27
+ * space: `` `FOO BAR=1` ``), `lowercase-leading-class` (id's first segment
28
+ * starts lowercase, e.g. `` `foo.bar=1` ``), and `value-contains-newline` (an
29
+ * embedded CR/LF/U+2028/U+2029 in the value). A line with no `=` at all (e.g.
30
+ * `` `ID` ``, ordinary inline code) is NOT a declaration attempt and never
31
+ * produces a diagnostic. This does not change any accept/reject outcome —
32
+ * only adds diagnostics.
33
+ *
34
+ * Grammar (from discovery facts):
35
+ * Two line forms, each on exactly one source line:
36
+ * 1. Bare backtick-wrapped, optionally indented: `ID=value`, ` `ID=value``
37
+ * 2. List-item backtick: `-`/`*`/`+`/`N.` marker followed by `ID=value`
38
+ *
39
+ * ID grammar: CLASS(.subkey)* where CLASS = first dot-separated segment.
40
+ * ID chars: [A-Za-z0-9._-] (CLASS always uppercase; subkeys may be mixed).
41
+ * Split on FIRST '=' only; everything before is the ID, everything after is
42
+ * the value (up to the closing backtick).
43
+ *
44
+ * Skip:
45
+ * - Fenced code blocks: ``` or ~~~, fence-length- and fence-char-aware
46
+ * (a longer fence containing a shorter same-char fence line stays a
47
+ * single skipped region; mismatched-char lines are fence content, not
48
+ * a toggle)
49
+ * - HTML comments (`<!-- ... -->`), including multi-line
50
+ * - Prose lines (headings, blank lines, list items without a predicate)
51
+ * - Blockquote lines (session-log preamble, etc.)
52
+ *
53
+ * Fence-length-awareness note: `src/markdown-sectionizer.cts`'s
54
+ * `stripFencedCode` is the repo's canonical CommonMark fence-stripper, but its
55
+ * `StripFencedResult.text` DROPS fence delimiter and content lines from the
56
+ * output — it does not preserve original line numbers. This parser reports
57
+ * `Predicate.line`/`Malformed.line` as 1-based SOURCE line numbers, which
58
+ * callers assert on — so line-accurate skip detection is required, and
59
+ * `stripFencedCode` cannot serve it directly.
60
+ *
61
+ * Comment/fence precedence (DEFECT.CONTEXT-PREDICATES-COMMENT-FENCE-BLIND,
62
+ * #2928 review): `computeSkippedLineFlags` previously ran the HTML-comment
63
+ * scan and a delegated call to `markdown-sectionizer.cts`'s exported
64
+ * `scanFencedBlocks` seam as two INDEPENDENT passes over the raw lines. That
65
+ * is unsound: `scanFencedBlocks` is comment-blind, so a fence delimiter
66
+ * appearing INSIDE an HTML comment (with no later matching close in the
67
+ * file) was treated as a real *unterminated* fence — silently skipping every
68
+ * remaining line to EOF and permanently dropping later predicates. The
69
+ * converse is also unsound the other way: a bare two-pass ordering that
70
+ * resolves comments first and only then masks-and-rescans for fences
71
+ * mis-handles a `<!--`/`-->` token that appears *inside a genuine fenced
72
+ * block* (proven while fixing this: guarding the comment pass by a
73
+ * comment-blind fence pass, or vice versa, always breaks one of the two
74
+ * directions — the two constructs must suppress each other's
75
+ * open/close detection while active, which only a single interleaved
76
+ * left-to-right pass can guarantee).
77
+ *
78
+ * Chosen precedence (documented per the review's requirement): the two
79
+ * constructs are scanned in ONE forward pass with two mutually-exclusive
80
+ * states, `fence: {char,len} | null` and `inHtmlComment: boolean`.
81
+ * - While a fence is open, only a fence-close delimiter (same char, run
82
+ * length >= the opener's) can close it; any `<!--`/`-->` token on a
83
+ * fenced-content line is fence content, never a comment boundary.
84
+ * - While NEITHER is open and an HTML comment opens, only a `-->` token
85
+ * can close it; any fence delimiter seen while inside a comment is
86
+ * comment content, never a fence boundary.
87
+ * - When neither is open, a comment opener (`<!--`) is checked BEFORE a
88
+ * fence opener on the same line — HTML comments are lexically outermost
89
+ * in this document's grammar — so a fence-shaped info string that
90
+ * happens to also look like `<!--...-->` never spuriously opens/closes
91
+ * anything once the line has already been claimed as a fence opener (the
92
+ * inverse: a genuine one-line comment `<!-- ``` -->` is masked whole and
93
+ * never interpreted as a fence delimiter).
94
+ * This single-pass design reuses `markdown-sectionizer.cts`'s exact
95
+ * delimiter-matching rule (same regex, same `len >= open.len` /
96
+ * mismatched-char-is-content / backtick-info-string-cannot-contain-backtick
97
+ * semantics as `scanFencedBlocks`), so non-comment-interacting documents are
98
+ * byte-for-byte identical to delegating to `scanFencedBlocks` (see
99
+ * `tests/context-predicates.test.cjs`'s fence-skip parity suite) — the
100
+ * interleaving is required ONLY to resolve the comment/fence interaction,
101
+ * not to change fence semantics themselves. This is therefore a second,
102
+ * necessarily local copy of the (tiny) delimiter-match condition — the
103
+ * scanFencedBlocks seam cannot serve both scans at once, because the correct
104
+ * boundary decision for either construct depends on the OTHER construct's
105
+ * live state at that exact line, not just on a static, comment-blind
106
+ * pre-scan of the raw lines.
107
+ *
108
+ * ADR-457 build-at-publish: compiled by tsc to
109
+ * gsd-core/bin/lib/context-predicates.cjs (gitignored).
110
+ */
111
+ Object.defineProperty(exports, "__esModule", { value: true });
112
+ exports.parsePredicates = parsePredicates;
113
+ exports.selectPredicates = selectPredicates;
114
+ exports.buildIndex = buildIndex;
115
+ // ID grammar, validated STRUCTURALLY rather than by a single regex
116
+ // (DEFECT.CONTEXT-PREDICATES-ID-REDOS, #2928 review). The formerly-used regex
117
+ // `^([A-Z][A-Z0-9_-]*(?:\.[A-Za-z0-9_.-]+)*)=(.+)$` is exponential: the
118
+ // group `(?:\.[A-Za-z0-9_.-]+)*` is ambiguous because its own character
119
+ // class contains `.`, so N consecutive dots have exponentially many
120
+ // backtick-partitionings for the regex engine to try on a failed match
121
+ // (measured: ~565ms for 40 consecutive dots, doubling roughly every 5).
122
+ // `.github/workflows/test.yml` runs `lint:ci` -> `lint:generated-sync` ->
123
+ // `gen-context-index.cjs --check` on `pull_request`, which parses the PR's
124
+ // own CONTEXT.md — so any external contributor could hang the shared CI
125
+ // runner with one crafted line, no write access required.
126
+ //
127
+ // Fix: split the candidate id on '.' and validate each segment with a
128
+ // simple, non-backtracking, per-segment pattern — linear in id length, no
129
+ // ambiguous quantifier. First segment (CLASS) must start with an uppercase
130
+ // letter; subsequent segments may start with letter/digit and include
131
+ // hyphens/underscores. We intentionally allow lowercase-starting
132
+ // sub-segments (e.g. PRED.k320.rule).
133
+ //
134
+ // Behavior change vs. the old regex: an EMPTY segment (a doubled dot, e.g.
135
+ // `A..b`) now REJECTS — the old regex accepted it because `.` was inside the
136
+ // subsequent-segment character class, so `.` itself could satisfy
137
+ // `[A-Za-z0-9_.-]+` with a single character. The real repo CONTEXT.md was
138
+ // checked (`grep -nE '\`[A-Z][A-Za-z0-9_.-]*\.\.[A-Za-z0-9_.-]*='
139
+ // CONTEXT.md`) and contains ZERO ids with a doubled dot, so rejecting the
140
+ // empty-segment case is the correct, stricter grammar with no behavior loss
141
+ // against real data (pinned by a dedicated test below).
142
+ const ID_FIRST_SEGMENT_RE = /^[A-Z][A-Z0-9_-]*$/;
143
+ const ID_SUBSEQUENT_SEGMENT_RE = /^[A-Za-z0-9_-]+$/;
144
+ /**
145
+ * Structurally validate a candidate predicate id (linear time — no ambiguous
146
+ * backtracking quantifier; see the ID grammar comment above), returning WHY it
147
+ * is invalid so malformed diagnostics can name the exact rejection class.
148
+ *
149
+ * @param id - candidate id (everything before the first '=')
150
+ */
151
+ function validateIdDetailed(id) {
152
+ const segments = id.split('.');
153
+ // A doubled dot (or leading/trailing dot) produces an empty segment.
154
+ if (segments.some((seg) => seg === ''))
155
+ return { valid: false, reason: 'empty-segment' };
156
+ const first = segments[0];
157
+ if (!ID_FIRST_SEGMENT_RE.test(first)) {
158
+ // Distinguish "starts lowercase" (a highly plausible typo, e.g.
159
+ // `foo.bar=1`) from any other first-segment character-set violation
160
+ // (e.g. a space, `FOO BAR=1`).
161
+ if (/^[a-z]/.test(first))
162
+ return { valid: false, reason: 'lowercase-leading-class' };
163
+ return { valid: false, reason: 'invalid-id-chars' };
164
+ }
165
+ for (let i = 1; i < segments.length; i++) {
166
+ if (!ID_SUBSEQUENT_SEGMENT_RE.test(segments[i]))
167
+ return { valid: false, reason: 'invalid-id-chars' };
168
+ }
169
+ return { valid: true };
170
+ }
171
+ /**
172
+ * Structurally validate a candidate predicate id (linear time — no ambiguous
173
+ * backtracking quantifier; see the ID grammar comment above).
174
+ *
175
+ * @param id - candidate id (everything before the first '=')
176
+ */
177
+ function isValidId(id) {
178
+ return validateIdDetailed(id).valid;
179
+ }
180
+ // List markers recognized ahead of a backtick-wrapped declaration:
181
+ // `-`, `*`, `+`, or a numbered marker (`1.`, `42.`), each followed by
182
+ // whitespace. Mirrors the marker family `iterateBullets`/`updateBullet`
183
+ // (markdown-sectionizer.cts) recognize, widened here beyond the
184
+ // prototype-carried-forward dash-only form (ADR-1671 Phase 1 commit 3).
185
+ const LIST_MARKER_RE = /^[ \t]*(?:[-*+]|\d+\.)[ \t]+/;
186
+ /**
187
+ * Strip a source line down to its backtick-wrapped "inner" content, if any.
188
+ * Handles both line forms:
189
+ * 1. Bare backtick line, optionally indented: `ID=value`, ` `ID=value``
190
+ * 2. List-item backtick, any of `-`/`*`/`+`/`N.`, optionally indented:
191
+ * `- `ID=value``, `* `ID=value``, `+ `ID=value``, `1. `ID=value``
192
+ *
193
+ * @param raw - the original source line (with newline stripped)
194
+ * @returns the inner content between the backticks, or null if the line is
195
+ * not backtick-wrapped in either recognized form
196
+ */
197
+ function extractInner(raw) {
198
+ const line = raw.trimEnd();
199
+ // Bare backtick-wrapped, tolerating leading indentation — shape decides
200
+ // the bare form, not column 0 (Postel: CONTEXT.md authors indent freely).
201
+ const bareTrimmed = line.replace(/^[ \t]+/, '');
202
+ if (bareTrimmed.startsWith('`') && bareTrimmed.endsWith('`') && bareTrimmed.length > 2) {
203
+ return bareTrimmed.slice(1, -1);
204
+ }
205
+ // List-item form: strip optional leading whitespace + list marker, then
206
+ // check for backtick wrapping. `stripped !== line` guards against a line
207
+ // with no marker at all (LIST_MARKER_RE.replace would otherwise no-op and
208
+ // re-check the same failed bare-form test).
209
+ const stripped = line.replace(LIST_MARKER_RE, '');
210
+ if (stripped !== line && stripped.startsWith('`') && stripped.endsWith('`') && stripped.length > 2) {
211
+ return stripped.slice(1, -1);
212
+ }
213
+ return null;
214
+ }
215
+ /**
216
+ * Parse a single source line and return a raw {id, value} if it is a
217
+ * predicate, or null otherwise.
218
+ *
219
+ * @param raw - the original source line (with newline stripped)
220
+ */
221
+ function extractPredicate(raw) {
222
+ const inner = extractInner(raw);
223
+ if (inner === null)
224
+ return null;
225
+ // Split on FIRST '=' only.
226
+ const eqIdx = inner.indexOf('=');
227
+ if (eqIdx < 1)
228
+ return null;
229
+ const id = inner.slice(0, eqIdx);
230
+ const value = inner.slice(eqIdx + 1);
231
+ // Value must be non-empty (the old ID_RE's trailing `(.+)$` requirement)
232
+ // and must contain no embedded ECMAScript LineTerminator character (LF,
233
+ // CR, U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR) -- the old
234
+ // regex's `.` metachar excludes exactly those four characters and carried
235
+ // no `s`/`m` flag, so a value spanning an embedded \r (possible only via
236
+ // the documented lone-CR limit: a "line" with no real \n at all still
237
+ // carries a mid-string \r joining what the author intended as two
238
+ // separate lines) could never satisfy `(.+)$`. Preserved byte-for-behavior
239
+ // here so `yieldsNoPredicatesForLoneCrDocumentAsDocumentedLimit` stays
240
+ // pinned. And the id must match the structural grammar (no spaces,
241
+ // correct char set, no empty segment -- see isValidId's doc comment).
242
+ if (value === '' || /[\n\r\u2028\u2029]/.test(value) || !isValidId(id))
243
+ return null;
244
+ return { id, value };
245
+ }
246
+ /**
247
+ * Detect the "looks like a predicate declaration attempt but is rejected"
248
+ * malformed case for a line that {@link extractPredicate} already rejected —
249
+ * naming WHY, so a maintainer's typo is diagnosable instead of silently
250
+ * vanishing. Only fires when the line is backtick-wrapped (in either
251
+ * recognized form) AND contains an `=` at index >= 1 — a plain inline-code
252
+ * line with no `=` at all (e.g. `` `ID` ``) is not a declaration attempt and
253
+ * never produces a diagnostic. Does not change any accept/reject decision —
254
+ * diagnostic only.
255
+ *
256
+ * Reason precedence when a line fails more than one check at once: id
257
+ * validity is checked first (an invalid id makes the value irrelevant), then
258
+ * empty-value, then embedded-newline.
259
+ *
260
+ * @param raw - the original source line (with newline stripped)
261
+ */
262
+ function detectMalformed(raw) {
263
+ const inner = extractInner(raw);
264
+ if (inner === null)
265
+ return null;
266
+ const eqIdx = inner.indexOf('=');
267
+ if (eqIdx < 1)
268
+ return null;
269
+ const id = inner.slice(0, eqIdx);
270
+ const value = inner.slice(eqIdx + 1);
271
+ const idCheck = validateIdDetailed(id);
272
+ if (!idCheck.valid) {
273
+ return { text: raw.trimEnd(), reason: idCheck.reason };
274
+ }
275
+ if (value === '') {
276
+ return { text: raw.trimEnd(), reason: 'empty-value' };
277
+ }
278
+ if (/[\n\r\u2028\u2029]/.test(value)) {
279
+ return { text: raw.trimEnd(), reason: 'value-contains-newline' };
280
+ }
281
+ return null;
282
+ }
283
+ // Fence delimiter line matcher — mirrors `markdown-sectionizer.cts`'s
284
+ // `scanFencedBlocks` regex exactly (≥3 backticks/tildes, ≤3-space indent
285
+ // tolerance). Kept local so the single interleaved pass below can decide,
286
+ // line by line, whether a delimiter is a REAL fence boundary given the
287
+ // comment state AT THAT LINE — see the module doc comment's "Comment/fence
288
+ // precedence" section for why this can't be a call-then-mask over
289
+ // `scanFencedBlocks`'s output.
290
+ const FENCE_DELIM_RE = /^( {0,3})(`{3,}|~{3,})(.*)$/;
291
+ /**
292
+ * Compute, per source line, whether that line falls inside a fenced code
293
+ * block or an HTML comment (`<!-- ... -->`, single- or multi-line).
294
+ * LINE-PRESERVING: returns one boolean per input line (no lines dropped or
295
+ * collapsed) — see the module doc comment for why that distinction is
296
+ * load-bearing here.
297
+ *
298
+ * Single interleaved forward pass over two mutually-exclusive states —
299
+ * `fence` (open fence delimiter char + run length, or null) and
300
+ * `inHtmlComment` — so each construct suppresses the OTHER's open/close
301
+ * detection while it is active (module doc comment's "Comment/fence
302
+ * precedence"). This is the fix for DEFECT.CONTEXT-PREDICATES-COMMENT-FENCE-
303
+ * BLIND: a fence delimiter inside a real HTML comment is comment content
304
+ * (never opens a fence), and a `<!--`/`-->` token inside a real fenced block
305
+ * is fence content (never opens/closes a comment).
306
+ *
307
+ * @param lines - source lines (as produced by `markdown.split('\n')`)
308
+ */
309
+ function computeSkippedLineFlags(lines) {
310
+ const skip = new Array(lines.length).fill(false);
311
+ let fence = null;
312
+ let inHtmlComment = false;
313
+ for (let i = 0; i < lines.length; i++) {
314
+ // Strip trailing \r (CRLF safety), mirroring stripFencedCode's/
315
+ // scanFencedBlocks's own `rawLine.replace(/\r$/, '')`.
316
+ const line = lines[i].replace(/\r$/, '');
317
+ if (fence !== null) {
318
+ // Inside a real fence: only a matching closer can end it. Any
319
+ // `<!--`/`-->` on this line is fence content, not a comment boundary
320
+ // (converse precedence).
321
+ skip[i] = true;
322
+ const m = FENCE_DELIM_RE.exec(line);
323
+ if (m) {
324
+ const char = m[2][0];
325
+ const len = m[2].length;
326
+ const trailing = m[3];
327
+ if (char === fence.char && len >= fence.len && /^\s*$/.test(trailing)) {
328
+ fence = null;
329
+ }
330
+ }
331
+ continue;
332
+ }
333
+ if (inHtmlComment) {
334
+ // Inside a real comment: only '-->' can end it. Any fence delimiter on
335
+ // this line is comment content, not a fence boundary (primary
336
+ // precedence — the DEFECT.CONTEXT-PREDICATES-COMMENT-FENCE-BLIND
337
+ // repro: a fence delimiter with no later real closer must not skip to
338
+ // EOF just because it happened to appear inside a comment).
339
+ skip[i] = true;
340
+ if (line.includes('-->'))
341
+ inHtmlComment = false;
342
+ continue;
343
+ }
344
+ // Neither construct open: HTML comments are lexically outermost in this
345
+ // document's grammar, so a comment opener is checked BEFORE a fence
346
+ // opener on the same line.
347
+ const trimmed = line.trim();
348
+ if (trimmed.startsWith('<!--')) {
349
+ skip[i] = true;
350
+ if (!trimmed.includes('-->')) {
351
+ inHtmlComment = true; // multi-line: stays open until a later '-->'
352
+ }
353
+ continue;
354
+ }
355
+ const m = FENCE_DELIM_RE.exec(line);
356
+ if (m) {
357
+ const char = m[2][0];
358
+ const trailing = m[3];
359
+ // CommonMark §4.5: a backtick fence opener's info string must not
360
+ // itself contain a backtick — such a line is ordinary content, not a
361
+ // valid opener (mirrors scanFencedBlocks).
362
+ if (!(char === '`' && trailing.includes('`'))) {
363
+ skip[i] = true;
364
+ fence = { char, len: m[2].length };
365
+ continue;
366
+ }
367
+ }
368
+ skip[i] = false;
369
+ }
370
+ return skip;
371
+ }
372
+ /**
373
+ * Parse all predicates from a CONTEXT.md markdown string.
374
+ *
375
+ * @param markdown
376
+ */
377
+ function parsePredicates(markdown) {
378
+ const lines = markdown.split('\n');
379
+ const predicates = [];
380
+ const malformed = [];
381
+ // Track id -> occurrence count for duplicate detection
382
+ const idCounts = new Map();
383
+ const skippedLines = computeSkippedLineFlags(lines);
384
+ let currentSection = '';
385
+ const allSections = [];
386
+ const seenSections = new Set();
387
+ for (let i = 0; i < lines.length; i++) {
388
+ const raw = lines[i];
389
+ const lineNo = i + 1; // 1-based
390
+ // Fenced code blocks and HTML comments (line-preserving; see
391
+ // computeSkippedLineFlags's doc comment).
392
+ if (skippedLines[i])
393
+ continue;
394
+ // Track section headings for the section field.
395
+ if (raw.startsWith('#')) {
396
+ currentSection = raw.replace(/^#+\s*/, '').trim();
397
+ if (currentSection && !seenSections.has(currentSection)) {
398
+ seenSections.add(currentSection);
399
+ allSections.push(currentSection);
400
+ }
401
+ continue;
402
+ }
403
+ // Blockquote lines (start with ">") are prose — skip.
404
+ if (raw.trimStart().startsWith('>'))
405
+ continue;
406
+ // Attempt extraction.
407
+ const pred = extractPredicate(raw);
408
+ if (!pred) {
409
+ const bad = detectMalformed(raw);
410
+ if (bad) {
411
+ malformed.push({ line: lineNo, text: bad.text, reason: bad.reason });
412
+ }
413
+ continue;
414
+ }
415
+ const klass = pred.id.split('.')[0];
416
+ predicates.push({
417
+ id: pred.id,
418
+ klass,
419
+ value: pred.value,
420
+ line: lineNo,
421
+ section: currentSection,
422
+ });
423
+ idCounts.set(pred.id, (idCounts.get(pred.id) || 0) + 1);
424
+ }
425
+ // Build duplicates list: ids with >1 occurrence.
426
+ const duplicates = [];
427
+ for (const [id, count] of idCounts) {
428
+ if (count > 1)
429
+ duplicates.push({ id, count });
430
+ }
431
+ // Sort duplicates by id for determinism.
432
+ duplicates.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
433
+ // Skipped sections: headings that yielded zero predicates (pure prose).
434
+ const activeSections = new Set(predicates.map((p) => p.section));
435
+ const skippedSections = allSections.filter((s) => !activeSections.has(s));
436
+ return { predicates, duplicates, malformed, skippedSections };
437
+ }
438
+ /**
439
+ * Select predicates by one or more optional criteria (ANDed together).
440
+ *
441
+ * @param predicates
442
+ * @param opts
443
+ */
444
+ function selectPredicates(predicates, opts = {}) {
445
+ const { klass, prefix, contains } = opts;
446
+ const containsLower = contains ? contains.toLowerCase() : null;
447
+ return predicates.filter((p) => {
448
+ if (klass !== undefined && p.klass !== klass)
449
+ return false;
450
+ if (prefix !== undefined && !p.id.startsWith(prefix))
451
+ return false;
452
+ if (containsLower !== null) {
453
+ const haystack = (p.id + ' ' + p.value).toLowerCase();
454
+ if (!haystack.includes(containsLower))
455
+ return false;
456
+ }
457
+ return true;
458
+ });
459
+ }
460
+ /**
461
+ * Build a deterministic index object from a parsed predicates array.
462
+ *
463
+ * @param predicates
464
+ */
465
+ function buildIndex(predicates) {
466
+ // Count per class.
467
+ const classCounts = {};
468
+ for (const p of predicates) {
469
+ classCounts[p.klass] = (classCounts[p.klass] || 0) + 1;
470
+ }
471
+ // Sort classes object by key for determinism.
472
+ const classes = {};
473
+ for (const k of Object.keys(classCounts).sort()) {
474
+ classes[k] = classCounts[k];
475
+ }
476
+ // Sort predicates by id then by line number (line used for ordering only —
477
+ // the committed index entry itself omits `line`; see module doc).
478
+ const sortedPredicates = predicates
479
+ .slice()
480
+ .sort((a, b) => {
481
+ if (a.id < b.id)
482
+ return -1;
483
+ if (a.id > b.id)
484
+ return 1;
485
+ return a.line - b.line;
486
+ })
487
+ .map(({ id, klass, value }) => ({ id, klass, value }));
488
+ // Rebuild duplicates from the (sorted-by-id) predicates for determinism.
489
+ const idCounts = new Map();
490
+ for (const p of predicates) {
491
+ idCounts.set(p.id, (idCounts.get(p.id) || 0) + 1);
492
+ }
493
+ const duplicates = [];
494
+ for (const [id, count] of idCounts) {
495
+ if (count > 1)
496
+ duplicates.push({ id, count });
497
+ }
498
+ duplicates.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
499
+ return {
500
+ schemaVersion: 1,
501
+ count: predicates.length,
502
+ classes,
503
+ predicates: sortedPredicates,
504
+ duplicates,
505
+ };
506
+ }
@@ -98,7 +98,58 @@ function pathExistsInternal(cwd, targetPath) {
98
98
  function generateSlugInternal(text) {
99
99
  if (!text)
100
100
  return null;
101
- return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').substring(0, 60);
101
+ // #2849: strip leading/trailing hyphens AFTER truncation, not only before.
102
+ // .substring(0, 60) can land on a separator, re-introducing a trailing hyphen
103
+ // the strip step exists to prevent. Truncation cannot add a leading hyphen, so
104
+ // running the full ^-+|-+$ pass last is equivalent for leading hyphens and
105
+ // fixes the trailing-hyphen-after-truncation case.
106
+ return transliterateForSlug(text).replace(/[^a-z0-9]+/g, '-').substring(0, 60).replace(/^-+|-+$/g, '');
107
+ }
108
+ // ─── Transliteration (#2848) ─────────────────────────────────────────────────
109
+ //
110
+ // Non-Latin titles used to reduce to an empty slug: the `[^a-z0-9]+` strip
111
+ // removed every character of an all-Cyrillic title and the hyphen cleanup left
112
+ // "". Callers then created unnamed phase directories (`01-`) and empty
113
+ // `milestone_slug` init JSON. The fix transliterates Cyrillic to ASCII BEFORE
114
+ // the existing ASCII filter, so a non-Latin title yields a usable ASCII slug
115
+ // while Latin-script text (which hits zero map entries) is byte-for-byte
116
+ // unchanged — the negative control is satisfied by construction.
117
+ //
118
+ // Multi-letter mappings (ж→zh, ч→ch, ш→sh, щ→sch, ю→yu, я→ya) are applied as a
119
+ // single pass; soft/hard signs (ъ, ь) drop to nothing rather than a hyphen.
120
+ // Scope is Cyrillic (Russian + the reported Ukrainian/Belarusian extras
121
+ // і ї є ґ ў) per the issue's confirmed-working patch. CJK and other
122
+ // non-transliterated scripts keep the existing strip-to-ASCII behavior.
123
+ const CYRILLIC_TRANSLITERATION = {
124
+ // multi-letter first (longest-match-safe within a single pass via ordered keys)
125
+ а: 'a', б: 'b', в: 'v', г: 'g', д: 'd', е: 'e', ё: 'e', ж: 'zh',
126
+ з: 'z', и: 'i', й: 'y', к: 'k', л: 'l', м: 'm', н: 'n', о: 'o',
127
+ п: 'p', р: 'r', с: 's', т: 't', у: 'u', ф: 'f', х: 'h', ц: 'ts',
128
+ ч: 'ch', ш: 'sh', щ: 'sch', ъ: '', ы: 'y', ь: '', э: 'e', ю: 'yu',
129
+ я: 'ya',
130
+ // Ukrainian / Belarusian extras reported in #2848
131
+ є: 'ye', і: 'i', ї: 'yi', ґ: 'g', ў: 'u',
132
+ };
133
+ const CYRILLIC_TRANSLITERATION_KEYS = Object.keys(CYRILLIC_TRANSLITERATION);
134
+ /**
135
+ * Lowercase + transliterate Cyrillic characters to ASCII. The output still
136
+ * contains non-ASCII for scripts outside the map (CJK, etc.) — the caller's
137
+ * existing `[^a-z0-9]+` filter handles those. Latin-script input is returned
138
+ * lowercased with no other change.
139
+ *
140
+ * Shared by `generateSlugInternal` (core-utils) and `slugify` (gsd2-import) so
141
+ * the transliteration step is not duplicated across the two slug helpers (#2848
142
+ * explicitly requires both be fixed).
143
+ */
144
+ function transliterateForSlug(text) {
145
+ const lowered = text.toLowerCase();
146
+ let out = '';
147
+ for (const ch of lowered) {
148
+ out += CYRILLIC_TRANSLITERATION_KEYS.includes(ch)
149
+ ? CYRILLIC_TRANSLITERATION[ch]
150
+ : ch;
151
+ }
152
+ return out;
102
153
  }
103
154
  // ─── Phase file helpers ──────────────────────────────────────────────────────
104
155
  /** Filter a file list to just PLAN.md / *-PLAN.md entries. */
@@ -222,27 +273,54 @@ function countMatchedSummaries(planFiles, summaryFiles) {
222
273
  const summarySet = new Set(summaryFiles);
223
274
  let matched = 0;
224
275
  for (const plan of planFiles) {
225
- const slashIdx = plan.lastIndexOf('/');
226
- const dir = slashIdx >= 0 ? plan.slice(0, slashIdx + 1) : '';
227
- const base = (dir ? plan.slice(dir.length) : plan).replace(/\.md$/i, '');
228
- const candidates = [
229
- dir + base.replace(/PLAN/i, 'SUMMARY') + '.md',
230
- dir + base + '-SUMMARY.md',
231
- ];
232
- const extended = base.match(/^(\d+)-PLAN-(\d+)/i);
233
- if (extended)
234
- candidates.push(dir + extended[1] + '-' + extended[2] + '-SUMMARY.md');
235
- if (candidates.some((c) => summarySet.has(c)))
276
+ if (summaryCandidates(plan).some((c) => summarySet.has(c)))
236
277
  matched++;
237
278
  }
238
279
  return matched;
239
280
  }
281
+ /**
282
+ * The candidate `*-SUMMARY.md` filenames a single plan's completion record
283
+ * could take, per the three naming conventions documented above
284
+ * `countMatchedSummaries`. Extracted so `findUnsummarizedPlans` can reuse the
285
+ * exact same matching rule without duplicating it (a divergence between the
286
+ * count and the list would let a plan be counted as matched while still
287
+ * appearing in the unsummarized set, or vice versa).
288
+ */
289
+ function summaryCandidates(plan) {
290
+ const slashIdx = plan.lastIndexOf('/');
291
+ const dir = slashIdx >= 0 ? plan.slice(0, slashIdx + 1) : '';
292
+ const base = (dir ? plan.slice(dir.length) : plan).replace(/\.md$/i, '');
293
+ const candidates = [
294
+ dir + base.replace(/PLAN/i, 'SUMMARY') + '.md',
295
+ dir + base + '-SUMMARY.md',
296
+ ];
297
+ const extended = base.match(/^(\d+)-PLAN-(\d+)/i);
298
+ if (extended)
299
+ candidates.push(dir + extended[1] + '-' + extended[2] + '-SUMMARY.md');
300
+ return candidates;
301
+ }
302
+ /**
303
+ * #2648: the plan files in `planFiles` that have NO matching completion record
304
+ * in `summaryFiles`, using the identical matching rule as `countMatchedSummaries`
305
+ * (so the count and the named list can never disagree). Callers that must NAME
306
+ * the missing plans — e.g. phase.complete's fail-closed coverage gate, which
307
+ * refuses completion when any non-retired plan lacks a SUMMARY — need the list,
308
+ * not just the count. `planFiles` is expected to be already superseded-filtered
309
+ * (the caller passes `scanPhasePlans(...).planFiles`, which drops
310
+ * `status: superseded` plans), so a deliberately-retired plan never appears
311
+ * here and never blocks completion.
312
+ */
313
+ function findUnsummarizedPlans(planFiles, summaryFiles) {
314
+ const summarySet = new Set(summaryFiles);
315
+ return planFiles.filter((plan) => !summaryCandidates(plan).some((c) => summarySet.has(c)));
316
+ }
240
317
  module.exports = {
241
318
  toPosixPath,
242
319
  detectSubRepos,
243
320
  extractOneLinerFromBody,
244
321
  pathExistsInternal,
245
322
  generateSlugInternal,
323
+ transliterateForSlug,
246
324
  filterPlanFiles,
247
325
  filterSummaryFiles,
248
326
  getPhaseFileStats,
@@ -250,4 +328,5 @@ module.exports = {
250
328
  timeAgo,
251
329
  extractCanonicalPlanId,
252
330
  countMatchedSummaries,
331
+ findUnsummarizedPlans,
253
332
  };
@@ -30,6 +30,7 @@ const { pathExistsInternal, toPosixPath } = coreUtils;
30
30
  // eslint-disable-next-line @typescript-eslint/no-require-imports
31
31
  const agentInstallCheck = require("./agent-install-check.cjs");
32
32
  const { checkAgentsInstalled } = agentInstallCheck;
33
+ const runtime_slash_cjs_1 = require("./runtime-slash.cjs");
33
34
  const shell_command_projection_cjs_1 = require("./shell-command-projection.cjs");
34
35
  // ─── Constants ────────────────────────────────────────────────────────────────
35
36
  const GSD_MARKER = '<!-- generated-by: gsd-doc-writer -->';
@@ -256,7 +257,7 @@ function cmdDocsInit(cwd, raw) {
256
257
  };
257
258
  // Inject project_root and agent installation status (mirrors withProjectRoot in init.cjs)
258
259
  result['project_root'] = cwd;
259
- const agentStatus = checkAgentsInstalled();
260
+ const agentStatus = checkAgentsInstalled((0, runtime_slash_cjs_1.resolveRuntime)(cwd), cwd);
260
261
  result['agents_installed'] = agentStatus.agents_installed;
261
262
  result['missing_agents'] = agentStatus.missing_agents;
262
263
  // #2402: withProjectRoot injects response_language when set; cmdDocsInit predates
@@ -267,4 +268,4 @@ function cmdDocsInit(cwd, raw) {
267
268
  }
268
269
  output(result, raw, undefined);
269
270
  }
270
- module.exports = { cmdDocsInit };
271
+ module.exports = { cmdDocsInit, detectMonorepoWorkspaces };