@popoverai/dotrequirements 0.22.0 → 0.24.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 (230) hide show
  1. package/README.md +173 -23
  2. package/dist/cli.js +121 -61
  3. package/dist/codebase-to-spec/budget.d.ts +53 -0
  4. package/dist/codebase-to-spec/budget.js +80 -0
  5. package/dist/codebase-to-spec/cache.d.ts +49 -0
  6. package/dist/codebase-to-spec/cache.js +54 -0
  7. package/dist/codebase-to-spec/claude.d.ts +69 -0
  8. package/dist/codebase-to-spec/claude.js +126 -0
  9. package/dist/codebase-to-spec/compose.d.ts +49 -0
  10. package/dist/codebase-to-spec/compose.js +124 -0
  11. package/dist/codebase-to-spec/edit-loop.d.ts +54 -0
  12. package/dist/codebase-to-spec/edit-loop.js +195 -0
  13. package/dist/codebase-to-spec/editor.d.ts +54 -0
  14. package/dist/codebase-to-spec/editor.js +74 -0
  15. package/dist/codebase-to-spec/exit-codes.d.ts +40 -0
  16. package/dist/codebase-to-spec/exit-codes.js +58 -0
  17. package/dist/codebase-to-spec/fan-out.d.ts +63 -0
  18. package/dist/codebase-to-spec/fan-out.js +215 -0
  19. package/dist/codebase-to-spec/interactive.d.ts +30 -0
  20. package/dist/codebase-to-spec/interactive.js +48 -0
  21. package/dist/codebase-to-spec/outline-review-loop.d.ts +51 -0
  22. package/dist/codebase-to-spec/outline-review-loop.js +187 -0
  23. package/dist/codebase-to-spec/pack.d.ts +51 -0
  24. package/dist/codebase-to-spec/pack.js +127 -0
  25. package/dist/codebase-to-spec/planner.d.ts +41 -0
  26. package/dist/codebase-to-spec/planner.js +76 -0
  27. package/dist/codebase-to-spec/present.d.ts +94 -0
  28. package/dist/codebase-to-spec/present.js +288 -0
  29. package/dist/codebase-to-spec/progress.d.ts +33 -0
  30. package/dist/codebase-to-spec/progress.js +28 -0
  31. package/dist/codebase-to-spec/prompts/editor.d.ts +13 -0
  32. package/dist/codebase-to-spec/prompts/editor.js +57 -0
  33. package/dist/codebase-to-spec/prompts/outline-reviewer.d.ts +12 -0
  34. package/dist/codebase-to-spec/prompts/outline-reviewer.js +87 -0
  35. package/dist/codebase-to-spec/prompts/planner-apply.d.ts +12 -0
  36. package/dist/codebase-to-spec/prompts/planner-apply.js +32 -0
  37. package/dist/codebase-to-spec/prompts/planner-initial.d.ts +11 -0
  38. package/dist/codebase-to-spec/prompts/planner-initial.js +125 -0
  39. package/dist/codebase-to-spec/prompts/planner-revise.d.ts +14 -0
  40. package/dist/codebase-to-spec/prompts/planner-revise.js +60 -0
  41. package/dist/codebase-to-spec/prompts/spec-reviewer.d.ts +16 -0
  42. package/dist/codebase-to-spec/prompts/spec-reviewer.js +96 -0
  43. package/dist/codebase-to-spec/prompts/specifier.d.ts +12 -0
  44. package/dist/codebase-to-spec/prompts/specifier.js +100 -0
  45. package/dist/codebase-to-spec/prompts/style-check.d.ts +12 -0
  46. package/dist/codebase-to-spec/prompts/style-check.js +78 -0
  47. package/dist/codebase-to-spec/schemas.d.ts +257 -0
  48. package/dist/codebase-to-spec/schemas.js +183 -0
  49. package/dist/codebase-to-spec/skill-install.d.ts +57 -0
  50. package/dist/codebase-to-spec/skill-install.js +79 -0
  51. package/dist/codebase-to-spec/slice.d.ts +49 -0
  52. package/dist/codebase-to-spec/slice.js +111 -0
  53. package/dist/codebase-to-spec/specifier.d.ts +60 -0
  54. package/dist/codebase-to-spec/specifier.js +79 -0
  55. package/dist/codebase-to-spec/style-check.d.ts +29 -0
  56. package/dist/codebase-to-spec/style-check.js +33 -0
  57. package/dist/codebase-to-spec/summary.d.ts +51 -0
  58. package/dist/codebase-to-spec/summary.js +183 -0
  59. package/dist/codebase-to-spec/validate.d.ts +46 -0
  60. package/dist/codebase-to-spec/validate.js +130 -0
  61. package/dist/commands/acceptance-test.d.ts +6 -0
  62. package/dist/commands/acceptance-test.js +212 -0
  63. package/dist/commands/ai-setup.d.ts +5 -0
  64. package/dist/commands/ai-setup.js +441 -0
  65. package/dist/commands/browsertest.d.ts +0 -1
  66. package/dist/commands/browsertest.js +51 -26
  67. package/dist/commands/codebase-to-spec/compose.d.ts +14 -0
  68. package/dist/commands/codebase-to-spec/compose.js +57 -0
  69. package/dist/commands/codebase-to-spec/edit-loop.d.ts +16 -0
  70. package/dist/commands/codebase-to-spec/edit-loop.js +83 -0
  71. package/dist/commands/codebase-to-spec/fan-out.d.ts +19 -0
  72. package/dist/commands/codebase-to-spec/fan-out.js +77 -0
  73. package/dist/commands/codebase-to-spec/index.d.ts +9 -0
  74. package/dist/commands/codebase-to-spec/index.js +135 -0
  75. package/dist/commands/codebase-to-spec/pack.d.ts +22 -0
  76. package/dist/commands/codebase-to-spec/pack.js +76 -0
  77. package/dist/commands/codebase-to-spec/plan-loop.d.ts +26 -0
  78. package/dist/commands/codebase-to-spec/plan-loop.js +105 -0
  79. package/dist/commands/codebase-to-spec/present.d.ts +21 -0
  80. package/dist/commands/codebase-to-spec/present.js +92 -0
  81. package/dist/commands/codebase-to-spec/run.d.ts +20 -0
  82. package/dist/commands/codebase-to-spec/run.js +85 -0
  83. package/dist/commands/codebase-to-spec/skill-install.d.ts +20 -0
  84. package/dist/commands/codebase-to-spec/skill-install.js +51 -0
  85. package/dist/commands/codebase-to-spec/specify-area.d.ts +18 -0
  86. package/dist/commands/codebase-to-spec/specify-area.js +82 -0
  87. package/dist/commands/codebase-to-spec/style-check.d.ts +15 -0
  88. package/dist/commands/codebase-to-spec/style-check.js +42 -0
  89. package/dist/commands/codebase-to-spec/validate.d.ts +18 -0
  90. package/dist/commands/codebase-to-spec/validate.js +38 -0
  91. package/dist/commands/create-requirement-document.d.ts +2 -0
  92. package/dist/commands/create-requirement-document.js +41 -0
  93. package/dist/commands/finalize.js +7 -7
  94. package/dist/commands/get.d.ts +2 -0
  95. package/dist/commands/get.js +55 -0
  96. package/dist/commands/init.js +132 -117
  97. package/dist/commands/link.js +27 -27
  98. package/dist/commands/list.d.ts +6 -0
  99. package/dist/commands/list.js +43 -0
  100. package/dist/commands/mcp-setup.js +159 -149
  101. package/dist/commands/mcp.js +1 -1
  102. package/dist/commands/prepare.js +4 -4
  103. package/dist/commands/pull.js +116 -121
  104. package/dist/commands/push.js +106 -112
  105. package/dist/commands/report.d.ts +6 -2
  106. package/dist/commands/report.js +177 -122
  107. package/dist/commands/requirements-for.d.ts +2 -0
  108. package/dist/commands/requirements-for.js +29 -0
  109. package/dist/commands/review-test.d.ts +2 -0
  110. package/dist/commands/review-test.js +75 -0
  111. package/dist/commands/search.d.ts +6 -0
  112. package/dist/commands/search.js +39 -0
  113. package/dist/commands/style-check.d.ts +7 -0
  114. package/dist/commands/style-check.js +75 -0
  115. package/dist/commands/test.js +53 -59
  116. package/dist/commands/tests-for.d.ts +2 -0
  117. package/dist/commands/tests-for.js +80 -0
  118. package/dist/commands/validate.d.ts +6 -0
  119. package/dist/commands/validate.js +72 -0
  120. package/dist/config.js +1 -1
  121. package/dist/convex.d.ts +34 -22
  122. package/dist/convex.js +38 -22
  123. package/dist/harness/cache.d.ts +1 -5
  124. package/dist/harness/cache.js +49 -59
  125. package/dist/harness/convexReporting.d.ts +1 -1
  126. package/dist/harness/convexReporting.js +9 -7
  127. package/dist/harness/coverageCache.js +3 -3
  128. package/dist/harness/finalize.js +59 -46
  129. package/dist/harness/index.d.ts +6 -7
  130. package/dist/harness/index.js +9 -10
  131. package/dist/harness/prepare.js +6 -5
  132. package/dist/harness/requirementsLoader.d.ts +2 -2
  133. package/dist/harness/requirementsLoader.js +13 -35
  134. package/dist/harness/tracking.js +18 -18
  135. package/dist/harness/types.d.ts +1 -1
  136. package/dist/mcp/convexClient.d.ts +0 -39
  137. package/dist/mcp/convexClient.js +2 -107
  138. package/dist/mcp/grep.d.ts +1 -1
  139. package/dist/mcp/grep.js +87 -42
  140. package/dist/mcp/handlers/authoring.d.ts +1 -1
  141. package/dist/mcp/handlers/authoring.js +30 -234
  142. package/dist/mcp/handlers/coverage.d.ts +1 -1
  143. package/dist/mcp/handlers/coverage.js +13 -15
  144. package/dist/mcp/handlers/debug.d.ts +2 -3
  145. package/dist/mcp/handlers/debug.js +10 -10
  146. package/dist/mcp/handlers/get.d.ts +1 -1
  147. package/dist/mcp/handlers/get.js +11 -10
  148. package/dist/mcp/handlers/index.d.ts +20 -20
  149. package/dist/mcp/handlers/index.js +10 -10
  150. package/dist/mcp/handlers/list.d.ts +4 -33
  151. package/dist/mcp/handlers/list.js +16 -38
  152. package/dist/mcp/handlers/push.d.ts +1 -1
  153. package/dist/mcp/handlers/push.js +28 -18
  154. package/dist/mcp/handlers/report.d.ts +16 -0
  155. package/dist/mcp/handlers/report.js +134 -0
  156. package/dist/mcp/handlers/review.d.ts +1 -1
  157. package/dist/mcp/handlers/review.js +40 -59
  158. package/dist/mcp/handlers/search.d.ts +1 -1
  159. package/dist/mcp/handlers/search.js +7 -9
  160. package/dist/mcp/handlers/test-mapping.d.ts +1 -1
  161. package/dist/mcp/handlers/test-mapping.js +14 -14
  162. package/dist/mcp/handlers/types.d.ts +3 -3
  163. package/dist/mcp/handlers/types.js +2 -2
  164. package/dist/mcp/index.d.ts +1 -1
  165. package/dist/mcp/index.js +156 -178
  166. package/dist/mcp/requirements.d.ts +2 -2
  167. package/dist/mcp/requirements.js +30 -30
  168. package/dist/mcp/testCodeExtractor.js +24 -26
  169. package/dist/mcp/types.d.ts +1 -1
  170. package/dist/push/core.d.ts +2 -2
  171. package/dist/push/core.js +20 -20
  172. package/dist/push/index.d.ts +1 -1
  173. package/dist/push/index.js +2 -2
  174. package/dist/requirements/cloud-ai.d.ts +57 -0
  175. package/dist/requirements/cloud-ai.js +104 -0
  176. package/dist/requirements/cloud-coverage.d.ts +41 -0
  177. package/dist/requirements/cloud-coverage.js +60 -0
  178. package/dist/requirements/coverage.d.ts +45 -0
  179. package/dist/requirements/coverage.js +114 -0
  180. package/dist/requirements/grep.d.ts +33 -0
  181. package/dist/requirements/grep.js +306 -0
  182. package/dist/requirements/index.d.ts +73 -0
  183. package/dist/requirements/index.js +174 -0
  184. package/dist/requirements/style-guide.d.ts +67 -0
  185. package/dist/requirements/style-guide.js +299 -0
  186. package/dist/requirements/testCodeExtractor.d.ts +22 -0
  187. package/dist/requirements/testCodeExtractor.js +150 -0
  188. package/dist/schema/browser.d.ts +8 -6
  189. package/dist/schema/browser.js +14 -14
  190. package/dist/schema/builder.d.ts +1 -1
  191. package/dist/schema/builder.js +13 -44
  192. package/dist/schema/conversions.d.ts +2 -2
  193. package/dist/schema/conversions.js +11 -11
  194. package/dist/schema/index.d.ts +9 -7
  195. package/dist/schema/index.js +15 -13
  196. package/dist/schema/parser-core.d.ts +1 -1
  197. package/dist/schema/parser-core.js +23 -22
  198. package/dist/schema/parser.d.ts +3 -3
  199. package/dist/schema/parser.js +27 -31
  200. package/dist/schema/resolver.d.ts +1 -1
  201. package/dist/schema/resolver.js +9 -9
  202. package/dist/schema/scenario.d.ts +91 -0
  203. package/dist/schema/scenario.js +82 -0
  204. package/dist/schema/schemas.d.ts +3 -3
  205. package/dist/schema/schemas.js +41 -28
  206. package/dist/schema/test-schema.js +27 -27
  207. package/dist/templates/context-file-section.md +3 -2
  208. package/dist/templates/example-requirements.js +1 -1
  209. package/dist/templates/example-requirements.ts +3 -1
  210. package/dist/templates/requirements-readme.js +1 -1
  211. package/dist/templates/requirements-readme.ts +1 -1
  212. package/dist/templates/skills/codebase-to-spec/SKILL.md +118 -0
  213. package/dist/utils/brand.js +3 -3
  214. package/dist/utils/browser-launch.js +4 -4
  215. package/dist/utils/context-file.d.ts +1 -1
  216. package/dist/utils/context-file.js +26 -26
  217. package/dist/utils/env.js +7 -7
  218. package/dist/utils/gitignore.js +7 -7
  219. package/dist/utils/oauth-callback-server.d.ts +1 -1
  220. package/dist/utils/oauth-callback-server.js +27 -25
  221. package/dist/utils/oauth-flow.js +32 -29
  222. package/dist/utils/project-discovery.d.ts +3 -3
  223. package/dist/utils/project-discovery.js +18 -17
  224. package/dist/utils/project-name.js +8 -8
  225. package/dist/utils/project-selector.d.ts +1 -1
  226. package/dist/utils/project-selector.js +24 -21
  227. package/dist/utils/project-settings.d.ts +5 -4
  228. package/dist/utils/project-settings.js +28 -20
  229. package/dist/utils/templates.js +6 -6
  230. package/package.json +2 -1
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Pipeline summary generation.
3
+ *
4
+ * Reads cached artifacts to assemble a structured summary of what the
5
+ * pipeline produced. Surfaced both as JSON (parseable by wrappers like the
6
+ * skill) and as a short human-readable block.
7
+ *
8
+ * Requirements covered:
9
+ * - CTS-PRESENT-4: Final pipeline summary is surfaced
10
+ * - CTS-OBSERVE-2 (partial): structured failure information available
11
+ */
12
+ import { existsSync, readFileSync, statSync } from "node:fs";
13
+ import { sanitizeAreaName } from "./fan-out.js";
14
+ import { parseOutlineReview, parseSpecReview, } from "./schemas.js";
15
+ /**
16
+ * Count top-level requirements in a file by counting fenced
17
+ * \`\`\`dotrequirements blocks. Each block represents one root requirement
18
+ * (CTS-OBSERVE-2 counts each requirement ID once, excluding child criteria).
19
+ */
20
+ function countRequirementsInFile(path) {
21
+ if (!existsSync(path))
22
+ return 0;
23
+ const content = readFileSync(path, "utf-8");
24
+ const matches = content.match(/```dotrequirements\b/g);
25
+ return matches ? matches.length : 0;
26
+ }
27
+ /**
28
+ * Look at outline-review-N.json files in the cache and return how many turns
29
+ * ran and what the final verdict was. Returns {turnsUsed: 0, finalVerdict: null}
30
+ * if no review artifacts exist.
31
+ */
32
+ function summarizeOutlineReview(paths) {
33
+ let n = 0;
34
+ let lastReviewPath = null;
35
+ while (true) {
36
+ const path = paths.outlineReviewTurn(n + 1);
37
+ if (!existsSync(path))
38
+ break;
39
+ n++;
40
+ lastReviewPath = path;
41
+ }
42
+ if (!lastReviewPath)
43
+ return { turnsUsed: 0, finalVerdict: null, residualNotes: [] };
44
+ try {
45
+ const review = parseOutlineReview(readFileSync(lastReviewPath, "utf-8"));
46
+ const notes = [];
47
+ // Surface unresolved findings as residual notes if verdict isn't 'approved'.
48
+ if (review.verdict !== "approved") {
49
+ for (const cat of [
50
+ ["coverage_gap", review.coverage_gaps],
51
+ ["framing_error", review.framing_errors],
52
+ ["granularity", review.granularity_issues],
53
+ ["file_assignment", review.file_assignment_issues],
54
+ ]) {
55
+ for (const note of cat[1]) {
56
+ notes.push(`outline.${cat[0]}: ${note}`);
57
+ }
58
+ }
59
+ }
60
+ return { turnsUsed: n, finalVerdict: review.verdict, residualNotes: notes };
61
+ }
62
+ catch {
63
+ return { turnsUsed: n, finalVerdict: null, residualNotes: [] };
64
+ }
65
+ }
66
+ function summarizeSpecReview(paths) {
67
+ let n = 0;
68
+ let lastReviewPath = null;
69
+ while (true) {
70
+ const path = paths.specReviewTurn(n + 1);
71
+ if (!existsSync(path))
72
+ break;
73
+ n++;
74
+ lastReviewPath = path;
75
+ }
76
+ if (!lastReviewPath)
77
+ return { turnsUsed: 0, finalVerdict: null, residualNotes: [] };
78
+ try {
79
+ const review = parseSpecReview(readFileSync(lastReviewPath, "utf-8"));
80
+ const notes = [];
81
+ if (review.verdict !== "approved") {
82
+ for (const cat of [
83
+ ["coverage_gap", review.coverage_gaps],
84
+ ["framing_error", review.framing_errors],
85
+ ["cross_area", review.cross_area_issues],
86
+ ["internal_mechanics", review.internal_mechanics_drift],
87
+ ]) {
88
+ for (const note of cat[1]) {
89
+ notes.push(`spec.${cat[0]}: ${note}`);
90
+ }
91
+ }
92
+ }
93
+ return { turnsUsed: n, finalVerdict: review.verdict, residualNotes: notes };
94
+ }
95
+ catch {
96
+ return { turnsUsed: n, finalVerdict: null, residualNotes: [] };
97
+ }
98
+ }
99
+ function summarizeSpecifiers(outline, paths) {
100
+ let completed = 0;
101
+ const missingAreas = [];
102
+ for (const area of outline.areas) {
103
+ const partialPath = paths.partial(sanitizeAreaName(area.name));
104
+ if (!existsSync(partialPath)) {
105
+ missingAreas.push(area.name);
106
+ continue;
107
+ }
108
+ const content = readFileSync(partialPath, "utf-8").trim();
109
+ if (!content ||
110
+ content.startsWith("_(missing partial") ||
111
+ content.startsWith("_(no files")) {
112
+ missingAreas.push(area.name);
113
+ continue;
114
+ }
115
+ completed++;
116
+ }
117
+ return { completed, missing: missingAreas.length, missingAreas };
118
+ }
119
+ export function buildPipelineSummary(input) {
120
+ const { outline, paths, outputPaths } = input;
121
+ const outlineReview = summarizeOutlineReview(paths);
122
+ const specReview = summarizeSpecReview(paths);
123
+ const specifiers = summarizeSpecifiers(outline, paths);
124
+ // Count top-level requirements across all written .requirements/ files.
125
+ let totalRequirements = 0;
126
+ for (const path of outputPaths) {
127
+ totalRequirements += countRequirementsInFile(path);
128
+ }
129
+ // Fall back to counting the final cached spec if nothing was written (e.g.
130
+ // dry-run / interrupted) — that way the summary still reflects what the
131
+ // pipeline produced.
132
+ if (totalRequirements === 0 && existsSync(paths.specFinal)) {
133
+ totalRequirements = countRequirementsInFile(paths.specFinal);
134
+ }
135
+ return {
136
+ totalAreas: outline.areas.length,
137
+ totalRequirements,
138
+ outline: outlineReview,
139
+ specifiers,
140
+ specReview,
141
+ outputs: { paths: outputPaths },
142
+ };
143
+ }
144
+ /**
145
+ * Render a short human-readable block for the summary. Designed to fit on a
146
+ * small number of lines (CTS-PRESENT-4.2). Wrappers that want richer
147
+ * presentation can read the JSON form instead.
148
+ */
149
+ export function renderSummaryText(summary) {
150
+ const lines = [];
151
+ lines.push(`Pipeline summary:`);
152
+ lines.push(` Areas: ${summary.totalAreas}`);
153
+ lines.push(` Top-level reqs: ${summary.totalRequirements}`);
154
+ lines.push(` Outline review: ${summary.outline.turnsUsed} turn(s), verdict: ${summary.outline.finalVerdict ?? "n/a"}`);
155
+ lines.push(` Specifiers: ${summary.specifiers.completed} completed, ${summary.specifiers.missing} missing`);
156
+ lines.push(` Spec review: ${summary.specReview.turnsUsed} turn(s), verdict: ${summary.specReview.finalVerdict ?? "n/a"}`);
157
+ lines.push(` Output files:`);
158
+ for (const path of summary.outputs.paths) {
159
+ lines.push(` - ${path}`);
160
+ }
161
+ if (summary.outline.residualNotes.length ||
162
+ summary.specReview.residualNotes.length) {
163
+ lines.push(``);
164
+ lines.push(` Residual notes (worth reviewing manually):`);
165
+ for (const note of [
166
+ ...summary.outline.residualNotes,
167
+ ...summary.specReview.residualNotes,
168
+ ]) {
169
+ lines.push(` - ${note}`);
170
+ }
171
+ }
172
+ if (summary.specifiers.missingAreas.length) {
173
+ lines.push(``);
174
+ lines.push(` Missing specifier output for:`);
175
+ for (const area of summary.specifiers.missingAreas) {
176
+ lines.push(` - ${area}`);
177
+ }
178
+ }
179
+ return lines.join("\n");
180
+ }
181
+ /** Suppress unused-var warning. */
182
+ void statSync;
183
+ //# sourceMappingURL=summary.js.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Local schema validation for a partial-spec file.
3
+ *
4
+ * Mirrors the existing `dotrequirements validate` path (and the
5
+ * `mcp__dotrequirements__validate_requirements` MCP tool), but works on
6
+ * partial files — which lack YAML frontmatter — by synthesizing a minimal
7
+ * wrapper before running the canonical parser.
8
+ *
9
+ * This is a deterministic syntax check: it catches things like missing
10
+ * `→`/`->` arrows, malformed position paths, indentation/position mismatches,
11
+ * and duplicate IDs — things the AI-driven style-check is not guaranteed
12
+ * to notice.
13
+ *
14
+ * Convention from CLAUDE.md: validate before style-check. Validate is the
15
+ * cheap, deterministic gate; style-check is the AI clarity pass.
16
+ *
17
+ * Requirements covered:
18
+ * - CTS-SPEC-3: Specifier worker runs a local schema validator on its draft,
19
+ * then a local style-check, applying feedback from each.
20
+ */
21
+ export interface ValidateOptions {
22
+ /** Path to the partial-spec file to validate. */
23
+ partialPath: string;
24
+ }
25
+ export interface ValidateResult {
26
+ /** True if the partial parsed cleanly. */
27
+ ok: boolean;
28
+ /** Human-readable error message when `ok === false`. */
29
+ error?: string;
30
+ /** Number of requirement blocks found (when `ok === true`). */
31
+ requirementCount?: number;
32
+ }
33
+ /**
34
+ * Validate a partial-spec file. Reads the file, synthesizes a frontmatter
35
+ * envelope, and delegates to the canonical parser. Errors are surfaced as
36
+ * a single human-readable string so the calling agent can act on them as
37
+ * MUST FIX items.
38
+ */
39
+ export declare function runValidate(options: ValidateOptions): ValidateResult;
40
+ /**
41
+ * Format a ValidateResult as the Markdown feedback block the specifier
42
+ * agent reads on stdout. Mirrors the severity-categorized shape produced
43
+ * by `runStyleCheck`, so the prompt can describe them uniformly.
44
+ */
45
+ export declare function formatValidateFeedback(result: ValidateResult): string;
46
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Local schema validation for a partial-spec file.
3
+ *
4
+ * Mirrors the existing `dotrequirements validate` path (and the
5
+ * `mcp__dotrequirements__validate_requirements` MCP tool), but works on
6
+ * partial files — which lack YAML frontmatter — by synthesizing a minimal
7
+ * wrapper before running the canonical parser.
8
+ *
9
+ * This is a deterministic syntax check: it catches things like missing
10
+ * `→`/`->` arrows, malformed position paths, indentation/position mismatches,
11
+ * and duplicate IDs — things the AI-driven style-check is not guaranteed
12
+ * to notice.
13
+ *
14
+ * Convention from CLAUDE.md: validate before style-check. Validate is the
15
+ * cheap, deterministic gate; style-check is the AI clarity pass.
16
+ *
17
+ * Requirements covered:
18
+ * - CTS-SPEC-3: Specifier worker runs a local schema validator on its draft,
19
+ * then a local style-check, applying feedback from each.
20
+ */
21
+ import { readFileSync } from "node:fs";
22
+ import { parseRequirementsFile } from "../schema/parser.js";
23
+ import { ValidationError } from "../schema/schemas.js";
24
+ /**
25
+ * Wrap a partial in a synthetic frontmatter envelope so the canonical
26
+ * Markdown-with-frontmatter parser can validate it.
27
+ */
28
+ function wrapPartial(partialBody) {
29
+ return [
30
+ "---",
31
+ "document:",
32
+ ' title: "Codebase-to-spec partial"',
33
+ "---",
34
+ "",
35
+ partialBody,
36
+ ].join("\n");
37
+ }
38
+ /**
39
+ * Validate a partial-spec file. Reads the file, synthesizes a frontmatter
40
+ * envelope, and delegates to the canonical parser. Errors are surfaced as
41
+ * a single human-readable string so the calling agent can act on them as
42
+ * MUST FIX items.
43
+ */
44
+ export function runValidate(options) {
45
+ let content;
46
+ try {
47
+ content = readFileSync(options.partialPath, "utf-8");
48
+ }
49
+ catch (err) {
50
+ return {
51
+ ok: false,
52
+ error: `Could not read ${options.partialPath}: ${err instanceof Error ? err.message : String(err)}`,
53
+ };
54
+ }
55
+ // Sanity check: the partial should contain at least one fenced
56
+ // dotrequirements block. A partial with no blocks is also a syntax error
57
+ // worth surfacing as MUST FIX.
58
+ if (!/```dotrequirements\s/.test(content)) {
59
+ return {
60
+ ok: false,
61
+ error: "No `dotrequirements` fenced code blocks found in partial. Every requirement must live inside a ```dotrequirements ... ``` block.",
62
+ };
63
+ }
64
+ try {
65
+ const parsed = parseRequirementsFile(wrapPartial(content));
66
+ return {
67
+ ok: true,
68
+ requirementCount: parsed.requirements.length,
69
+ };
70
+ }
71
+ catch (err) {
72
+ return {
73
+ ok: false,
74
+ error: describeValidationError(err),
75
+ };
76
+ }
77
+ }
78
+ /**
79
+ * The canonical parser wraps low-level failures (e.g. "Each criterion line
80
+ * must contain the delimiter `->` or `→`") inside a high-level ValidationError
81
+ * (e.g. "Failed to parse requirement FOO-001"). We want both — the high-level
82
+ * context tells the agent which block to fix, the low-level reason tells it
83
+ * what to fix.
84
+ */
85
+ function describeValidationError(err) {
86
+ if (err instanceof ValidationError) {
87
+ const parts = [err.message];
88
+ let cursor = err.cause;
89
+ while (cursor instanceof Error) {
90
+ // Don't repeat the same message twice if the wrapper just rethrew.
91
+ if (cursor.message && cursor.message !== parts[parts.length - 1]) {
92
+ parts.push(cursor.message);
93
+ }
94
+ cursor = cursor.cause;
95
+ }
96
+ return parts.join(" — ");
97
+ }
98
+ if (err instanceof Error) {
99
+ return err.message;
100
+ }
101
+ return String(err);
102
+ }
103
+ /**
104
+ * Format a ValidateResult as the Markdown feedback block the specifier
105
+ * agent reads on stdout. Mirrors the severity-categorized shape produced
106
+ * by `runStyleCheck`, so the prompt can describe them uniformly.
107
+ */
108
+ export function formatValidateFeedback(result) {
109
+ if (result.ok) {
110
+ return [
111
+ "# Schema validation: PASS",
112
+ "",
113
+ `${result.requirementCount ?? 0} requirement block(s) parsed cleanly.`,
114
+ "",
115
+ "No syntax issues. Proceed to the style-check step.",
116
+ "",
117
+ ].join("\n");
118
+ }
119
+ return [
120
+ "# Schema validation: FAIL",
121
+ "",
122
+ "## MUST FIX",
123
+ "",
124
+ `- ${result.error}`,
125
+ "",
126
+ "Fix the syntax issue above with the Edit tool, then re-run validate.",
127
+ "",
128
+ ].join("\n");
129
+ }
130
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,6 @@
1
+ interface AcceptanceTestOptions {
2
+ json?: boolean;
3
+ }
4
+ export declare function acceptanceTestCommand(requirementKey: string, url: string | undefined, options: AcceptanceTestOptions): Promise<void>;
5
+ export {};
6
+ //# sourceMappingURL=acceptance-test.d.ts.map
@@ -0,0 +1,212 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { formatRequirement, getRequirementTree, loadAllRequirements, } from "../requirements/index.js";
4
+ import { getProjectInfo, readProjectSettings, } from "../utils/project-settings.js";
5
+ const execFileAsync = promisify(execFile);
6
+ function extractResults(parsed) {
7
+ if (Array.isArray(parsed))
8
+ return parsed;
9
+ if (parsed && typeof parsed === "object") {
10
+ const obj = parsed;
11
+ // { results: [...] } format
12
+ if (Array.isArray(obj.results))
13
+ return obj.results;
14
+ // { structured_output: { results: [...] } } format
15
+ if (obj.structured_output && typeof obj.structured_output === "object") {
16
+ const so = obj.structured_output;
17
+ if (Array.isArray(so.results))
18
+ return so.results;
19
+ }
20
+ }
21
+ throw new Error("Unexpected browser-automation output format");
22
+ }
23
+ export async function acceptanceTestCommand(requirementKey, url, options) {
24
+ // 1. Find project and load settings
25
+ const projectInfo = getProjectInfo();
26
+ if (!projectInfo) {
27
+ console.error("Error: No dotrequirements project found.");
28
+ console.log('Run "dotrequirements init" to create one.');
29
+ process.exit(1);
30
+ }
31
+ let settings;
32
+ try {
33
+ settings = readProjectSettings(projectInfo.rootPath);
34
+ }
35
+ catch (err) {
36
+ // Settings file exists but is invalid
37
+ console.error(`Error: ${err.message}`);
38
+ process.exit(1);
39
+ }
40
+ // 2. Determine URL
41
+ const targetURL = url || settings?.defaultURL;
42
+ if (!targetURL) {
43
+ console.error("Error: No URL provided and no defaultURL in project-settings.json.");
44
+ console.log('Either provide a URL argument or add "defaultURL" to .requirements/project-settings.json');
45
+ process.exit(1);
46
+ }
47
+ // 3. Resolve model config
48
+ const modelName = settings?.browserTest?.modelName;
49
+ const modelApiKey = settings?.browserTest?.modelApiKey;
50
+ const geminiApiKey = settings?.browserTest?.geminiApiKey;
51
+ if (!modelName && !modelApiKey && !geminiApiKey) {
52
+ console.error("Error: no browser-test model configured in project-settings.json.");
53
+ console.log("Add a block like:\n" +
54
+ ' "browserTest": {\n' +
55
+ ' "modelName": "gateway/anthropic/claude-haiku-4-5",\n' +
56
+ ' "modelApiKey": "..."\n' +
57
+ " }\n" +
58
+ "to .requirements/project-settings.json. See the docs for supported models.");
59
+ process.exit(1);
60
+ }
61
+ if ((modelName && !modelApiKey) || (modelApiKey && !modelName)) {
62
+ console.error("Error: browserTest.modelName and browserTest.modelApiKey must be set together.");
63
+ process.exit(1);
64
+ }
65
+ // 4. Load requirements
66
+ const { flattened } = await loadAllRequirements(projectInfo.rootPath);
67
+ if (flattened.length === 0) {
68
+ console.error("Error: No requirements found in .requirements/");
69
+ process.exit(1);
70
+ }
71
+ // 5. Find the requirement tree
72
+ const requirementTree = getRequirementTree(flattened, requirementKey);
73
+ if (requirementTree.length === 0) {
74
+ console.error(`Error: Requirement "${requirementKey}" not found.`);
75
+ process.exit(1);
76
+ }
77
+ // 6. Format each requirement as an assertion
78
+ const assertions = requirementTree.map((req) => formatRequirement(req));
79
+ // 7. Build environment with injected secrets
80
+ const env = { ...process.env };
81
+ // env var keeps the key out of process listings (not a CLI flag)
82
+ if (modelApiKey) {
83
+ env.MODEL_API_KEY = modelApiKey;
84
+ }
85
+ else if (geminiApiKey) {
86
+ env.GEMINI_API_KEY = geminiApiKey;
87
+ }
88
+ if (settings?.browserTest?.vercelBypassSecret) {
89
+ env.VERCEL_AUTOMATION_BYPASS_SECRET =
90
+ settings.browserTest.vercelBypassSecret;
91
+ }
92
+ if (settings?.browserTest?.browserbaseApiKey) {
93
+ env.BROWSERBASE_API_KEY = settings.browserTest.browserbaseApiKey;
94
+ }
95
+ if (settings?.browserTest?.browserbaseProjectId) {
96
+ env.BROWSERBASE_PROJECT_ID = settings.browserTest.browserbaseProjectId;
97
+ }
98
+ // 8. Run browser-automation
99
+ if (!options.json) {
100
+ console.log(`Testing ${requirementKey} against ${targetURL}...\n`);
101
+ }
102
+ try {
103
+ const modelFlags = modelName ? ["--modelName", modelName] : [];
104
+ const { stdout } = await execFileAsync("npx", [
105
+ "@popoverai/browser-automation",
106
+ "test",
107
+ ...modelFlags,
108
+ targetURL,
109
+ ...assertions,
110
+ ], { env, maxBuffer: 10 * 1024 * 1024 });
111
+ // 9. Parse results
112
+ let results;
113
+ try {
114
+ const parsed = JSON.parse(stdout.trim());
115
+ results = extractResults(parsed);
116
+ }
117
+ catch (parseErr) {
118
+ console.error("Error: Could not parse browser-automation output");
119
+ console.error(parseErr.message);
120
+ console.error(stdout);
121
+ process.exit(1);
122
+ }
123
+ // 10. Display results
124
+ if (options.json) {
125
+ outputJson(requirementTree, results);
126
+ }
127
+ else {
128
+ displayResults(requirementTree, results);
129
+ }
130
+ // 11. Exit with appropriate code
131
+ const failedCount = results.filter((r) => r.status !== "passed").length;
132
+ if (failedCount > 0) {
133
+ process.exit(1);
134
+ }
135
+ }
136
+ catch (err) {
137
+ const error = err;
138
+ // browser-automation returns exit code 1 on failure, but still outputs JSON
139
+ if (error.stdout) {
140
+ try {
141
+ const parsed = JSON.parse(error.stdout.trim());
142
+ const results = extractResults(parsed);
143
+ if (options.json) {
144
+ outputJson(requirementTree, results);
145
+ }
146
+ else {
147
+ displayResults(requirementTree, results);
148
+ }
149
+ process.exit(1);
150
+ }
151
+ catch {
152
+ // Not JSON, show raw output
153
+ console.error("browser-automation error:");
154
+ if (error.stdout)
155
+ console.error(error.stdout);
156
+ if (error.stderr)
157
+ console.error(error.stderr);
158
+ process.exit(1);
159
+ }
160
+ }
161
+ else {
162
+ console.error(`Error running browser-automation: ${error.message}`);
163
+ if (error.stderr)
164
+ console.error(error.stderr);
165
+ process.exit(1);
166
+ }
167
+ }
168
+ }
169
+ function displayResults(requirements, results) {
170
+ let passedCount = 0;
171
+ let failedCount = 0;
172
+ for (let i = 0; i < requirements.length; i++) {
173
+ const req = requirements[i];
174
+ const result = results[i];
175
+ if (!result) {
176
+ console.log(` ? ${req.id}: No result`);
177
+ failedCount++;
178
+ continue;
179
+ }
180
+ const indent = " ".repeat(req.path.length);
181
+ const label = req.label ? ` (${req.label})` : "";
182
+ const icon = result.status === "passed" ? "\u2713" : "\u2717";
183
+ console.log(`${indent}${icon} ${req.id}${label}: ${req.content}`);
184
+ if (result.status !== "passed" && result.notes) {
185
+ console.log(`${indent} \u2192 ${result.notes}`);
186
+ }
187
+ if (result.status === "passed") {
188
+ passedCount++;
189
+ }
190
+ else {
191
+ failedCount++;
192
+ }
193
+ }
194
+ console.log();
195
+ if (failedCount === 0) {
196
+ console.log(`${passedCount}/${requirements.length} passed`);
197
+ }
198
+ else {
199
+ console.log(`${passedCount}/${requirements.length} passed, ${failedCount} failed`);
200
+ }
201
+ }
202
+ function outputJson(requirements, results) {
203
+ const combined = requirements.map((req, i) => ({
204
+ id: req.id,
205
+ label: req.label || null,
206
+ content: req.content,
207
+ status: results[i]?.status || "blocked",
208
+ notes: results[i]?.notes || null,
209
+ }));
210
+ console.log(JSON.stringify(combined, null, 2));
211
+ }
212
+ //# sourceMappingURL=acceptance-test.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * AI setup command - configures the MCP server for AI assistants
3
+ */
4
+ export declare function aiSetupCommand(): Promise<void>;
5
+ //# sourceMappingURL=ai-setup.d.ts.map