@popoverai/dotrequirements 0.23.0 → 0.24.1

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 (235) hide show
  1. package/README.md +169 -22
  2. package/dist/cli.js +121 -60
  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-initial.d.ts +11 -0
  36. package/dist/codebase-to-spec/prompts/planner-initial.js +125 -0
  37. package/dist/codebase-to-spec/prompts/planner-revise.d.ts +14 -0
  38. package/dist/codebase-to-spec/prompts/planner-revise.js +60 -0
  39. package/dist/codebase-to-spec/prompts/spec-reviewer.d.ts +16 -0
  40. package/dist/codebase-to-spec/prompts/spec-reviewer.js +96 -0
  41. package/dist/codebase-to-spec/prompts/specifier.d.ts +12 -0
  42. package/dist/codebase-to-spec/prompts/specifier.js +100 -0
  43. package/dist/codebase-to-spec/prompts/style-check.d.ts +12 -0
  44. package/dist/codebase-to-spec/prompts/style-check.js +78 -0
  45. package/dist/codebase-to-spec/schemas.d.ts +257 -0
  46. package/dist/codebase-to-spec/schemas.js +183 -0
  47. package/dist/codebase-to-spec/skill-install.d.ts +57 -0
  48. package/dist/codebase-to-spec/skill-install.js +79 -0
  49. package/dist/codebase-to-spec/slice.d.ts +49 -0
  50. package/dist/codebase-to-spec/slice.js +111 -0
  51. package/dist/codebase-to-spec/specifier.d.ts +60 -0
  52. package/dist/codebase-to-spec/specifier.js +79 -0
  53. package/dist/codebase-to-spec/style-check.d.ts +29 -0
  54. package/dist/codebase-to-spec/style-check.js +33 -0
  55. package/dist/codebase-to-spec/summary.d.ts +51 -0
  56. package/dist/codebase-to-spec/summary.js +183 -0
  57. package/dist/codebase-to-spec/validate.d.ts +46 -0
  58. package/dist/codebase-to-spec/validate.js +130 -0
  59. package/dist/commands/acceptance-test.d.ts +6 -0
  60. package/dist/commands/{browsertest.js → acceptance-test.js} +36 -29
  61. package/dist/commands/ai-setup.d.ts +5 -0
  62. package/dist/commands/ai-setup.js +441 -0
  63. package/dist/commands/codebase-to-spec/compose.d.ts +14 -0
  64. package/dist/commands/codebase-to-spec/compose.js +57 -0
  65. package/dist/commands/codebase-to-spec/edit-loop.d.ts +16 -0
  66. package/dist/commands/codebase-to-spec/edit-loop.js +83 -0
  67. package/dist/commands/codebase-to-spec/fan-out.d.ts +19 -0
  68. package/dist/commands/codebase-to-spec/fan-out.js +77 -0
  69. package/dist/commands/codebase-to-spec/index.d.ts +9 -0
  70. package/dist/commands/codebase-to-spec/index.js +135 -0
  71. package/dist/commands/codebase-to-spec/pack.d.ts +22 -0
  72. package/dist/commands/codebase-to-spec/pack.js +76 -0
  73. package/dist/commands/codebase-to-spec/plan-loop.d.ts +26 -0
  74. package/dist/commands/codebase-to-spec/plan-loop.js +105 -0
  75. package/dist/commands/codebase-to-spec/present.d.ts +21 -0
  76. package/dist/commands/codebase-to-spec/present.js +92 -0
  77. package/dist/commands/codebase-to-spec/run.d.ts +20 -0
  78. package/dist/commands/codebase-to-spec/run.js +85 -0
  79. package/dist/commands/codebase-to-spec/skill-install.d.ts +20 -0
  80. package/dist/commands/codebase-to-spec/skill-install.js +51 -0
  81. package/dist/commands/codebase-to-spec/specify-area.d.ts +18 -0
  82. package/dist/commands/codebase-to-spec/specify-area.js +82 -0
  83. package/dist/commands/codebase-to-spec/style-check.d.ts +15 -0
  84. package/dist/commands/codebase-to-spec/style-check.js +42 -0
  85. package/dist/commands/codebase-to-spec/validate.d.ts +18 -0
  86. package/dist/commands/codebase-to-spec/validate.js +38 -0
  87. package/dist/commands/create-requirement-document.d.ts +2 -0
  88. package/dist/commands/create-requirement-document.js +41 -0
  89. package/dist/commands/finalize.js +7 -7
  90. package/dist/commands/get.d.ts +2 -0
  91. package/dist/commands/get.js +55 -0
  92. package/dist/commands/init.js +132 -117
  93. package/dist/commands/link.js +27 -27
  94. package/dist/commands/list.d.ts +6 -0
  95. package/dist/commands/list.js +43 -0
  96. package/dist/commands/mcp.js +1 -1
  97. package/dist/commands/prepare.js +4 -4
  98. package/dist/commands/pull.js +116 -121
  99. package/dist/commands/push.js +106 -112
  100. package/dist/commands/report.d.ts +6 -2
  101. package/dist/commands/report.js +177 -122
  102. package/dist/commands/requirements-for.d.ts +2 -0
  103. package/dist/commands/requirements-for.js +29 -0
  104. package/dist/commands/review-test.d.ts +2 -0
  105. package/dist/commands/review-test.js +75 -0
  106. package/dist/commands/search.d.ts +6 -0
  107. package/dist/commands/search.js +39 -0
  108. package/dist/commands/style-check.d.ts +7 -0
  109. package/dist/commands/style-check.js +75 -0
  110. package/dist/commands/tests-for.d.ts +2 -0
  111. package/dist/commands/tests-for.js +80 -0
  112. package/dist/commands/validate.d.ts +6 -0
  113. package/dist/commands/validate.js +72 -0
  114. package/dist/config.js +1 -1
  115. package/dist/convex.d.ts +34 -22
  116. package/dist/convex.js +38 -22
  117. package/dist/harness/cache.d.ts +1 -5
  118. package/dist/harness/cache.js +49 -59
  119. package/dist/harness/convexReporting.d.ts +1 -1
  120. package/dist/harness/convexReporting.js +9 -7
  121. package/dist/harness/coverageCache.js +3 -3
  122. package/dist/harness/finalize.js +59 -46
  123. package/dist/harness/index.d.ts +6 -7
  124. package/dist/harness/index.js +9 -10
  125. package/dist/harness/prepare.js +6 -5
  126. package/dist/harness/requirementsLoader.d.ts +2 -2
  127. package/dist/harness/requirementsLoader.js +13 -35
  128. package/dist/harness/tracking.js +18 -18
  129. package/dist/harness/types.d.ts +1 -1
  130. package/dist/mcp/convexClient.d.ts +0 -39
  131. package/dist/mcp/convexClient.js +2 -107
  132. package/dist/mcp/handlers/authoring.d.ts +1 -1
  133. package/dist/mcp/handlers/authoring.js +30 -234
  134. package/dist/mcp/handlers/debug.d.ts +2 -3
  135. package/dist/mcp/handlers/debug.js +10 -10
  136. package/dist/mcp/handlers/get.d.ts +1 -1
  137. package/dist/mcp/handlers/get.js +11 -10
  138. package/dist/mcp/handlers/index.d.ts +20 -20
  139. package/dist/mcp/handlers/index.js +10 -10
  140. package/dist/mcp/handlers/list.d.ts +4 -33
  141. package/dist/mcp/handlers/list.js +16 -38
  142. package/dist/mcp/handlers/push.d.ts +1 -1
  143. package/dist/mcp/handlers/push.js +28 -18
  144. package/dist/mcp/handlers/report.d.ts +16 -0
  145. package/dist/mcp/handlers/report.js +134 -0
  146. package/dist/mcp/handlers/review.d.ts +1 -1
  147. package/dist/mcp/handlers/review.js +40 -59
  148. package/dist/mcp/handlers/search.d.ts +1 -1
  149. package/dist/mcp/handlers/search.js +7 -9
  150. package/dist/mcp/handlers/test-mapping.d.ts +1 -1
  151. package/dist/mcp/handlers/test-mapping.js +14 -14
  152. package/dist/mcp/handlers/types.d.ts +3 -3
  153. package/dist/mcp/handlers/types.js +2 -2
  154. package/dist/mcp/index.d.ts +1 -1
  155. package/dist/mcp/index.js +147 -167
  156. package/dist/push/core.d.ts +2 -2
  157. package/dist/push/core.js +20 -20
  158. package/dist/push/index.d.ts +1 -1
  159. package/dist/push/index.js +2 -2
  160. package/dist/requirements/cloud-ai.d.ts +57 -0
  161. package/dist/requirements/cloud-ai.js +104 -0
  162. package/dist/requirements/cloud-coverage.d.ts +41 -0
  163. package/dist/requirements/cloud-coverage.js +60 -0
  164. package/dist/requirements/coverage.d.ts +45 -0
  165. package/dist/requirements/coverage.js +114 -0
  166. package/dist/{mcp → requirements}/grep.d.ts +10 -1
  167. package/dist/{mcp → requirements}/grep.js +89 -44
  168. package/dist/{mcp/requirements.d.ts → requirements/index.d.ts} +19 -3
  169. package/dist/{mcp/requirements.js → requirements/index.js} +54 -35
  170. package/dist/requirements/style-guide.d.ts +67 -0
  171. package/dist/requirements/style-guide.js +299 -0
  172. package/dist/{mcp → requirements}/testCodeExtractor.js +24 -26
  173. package/dist/schema/browser.d.ts +8 -8
  174. package/dist/schema/browser.js +13 -15
  175. package/dist/schema/builder.d.ts +1 -1
  176. package/dist/schema/builder.js +13 -44
  177. package/dist/schema/conversions.d.ts +2 -2
  178. package/dist/schema/conversions.js +11 -11
  179. package/dist/schema/index.d.ts +9 -9
  180. package/dist/schema/index.js +15 -15
  181. package/dist/schema/parser-core.d.ts +1 -1
  182. package/dist/schema/parser-core.js +23 -22
  183. package/dist/schema/parser.d.ts +3 -3
  184. package/dist/schema/parser.js +27 -31
  185. package/dist/schema/resolver.d.ts +1 -1
  186. package/dist/schema/resolver.js +9 -9
  187. package/dist/schema/scenario.d.ts +1 -1
  188. package/dist/schema/scenario.js +1 -1
  189. package/dist/schema/schemas.d.ts +3 -3
  190. package/dist/schema/schemas.js +41 -28
  191. package/dist/schema/test-schema.js +27 -27
  192. package/dist/templates/context-file-section.md +3 -2
  193. package/dist/templates/example-requirements.js +1 -1
  194. package/dist/templates/example-requirements.ts +3 -1
  195. package/dist/templates/requirements-readme.js +1 -1
  196. package/dist/templates/requirements-readme.ts +1 -1
  197. package/dist/templates/skills/codebase-to-spec/SKILL.md +118 -0
  198. package/dist/utils/brand.js +3 -3
  199. package/dist/utils/browser-launch.js +4 -4
  200. package/dist/utils/context-file.d.ts +1 -1
  201. package/dist/utils/context-file.js +26 -26
  202. package/dist/utils/env.js +7 -7
  203. package/dist/utils/gitignore.js +7 -7
  204. package/dist/utils/oauth-callback-server.d.ts +1 -1
  205. package/dist/utils/oauth-callback-server.js +27 -25
  206. package/dist/utils/oauth-flow.js +32 -29
  207. package/dist/utils/project-discovery.d.ts +3 -3
  208. package/dist/utils/project-discovery.js +18 -17
  209. package/dist/utils/project-name.js +8 -8
  210. package/dist/utils/project-selector.d.ts +1 -1
  211. package/dist/utils/project-selector.js +24 -21
  212. package/dist/utils/project-settings.d.ts +1 -1
  213. package/dist/utils/project-settings.js +24 -22
  214. package/dist/utils/templates.js +6 -6
  215. package/package.json +3 -2
  216. package/dist/commands/browsertest.d.ts +0 -6
  217. package/dist/commands/login.d.ts +0 -12
  218. package/dist/commands/login.js +0 -117
  219. package/dist/commands/logout.d.ts +0 -5
  220. package/dist/commands/logout.js +0 -17
  221. package/dist/commands/mcp-setup.d.ts +0 -5
  222. package/dist/commands/mcp-setup.js +0 -431
  223. package/dist/commands/test.d.ts +0 -6
  224. package/dist/commands/test.js +0 -78
  225. package/dist/mcp/handlers/coverage.d.ts +0 -44
  226. package/dist/mcp/handlers/coverage.js +0 -105
  227. package/dist/mcp/types.d.ts +0 -27
  228. package/dist/mcp/types.js +0 -2
  229. package/dist/utils/local-project.d.ts +0 -31
  230. package/dist/utils/local-project.js +0 -33
  231. package/dist/utils/token-refresh.d.ts +0 -24
  232. package/dist/utils/token-refresh.js +0 -69
  233. package/dist/utils/token-storage.d.ts +0 -31
  234. package/dist/utils/token-storage.js +0 -57
  235. /package/dist/{mcp → requirements}/testCodeExtractor.d.ts +0 -0
@@ -0,0 +1,77 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec fan-out` subcommand.
3
+ *
4
+ * Runs the specifier for every area in the cached outline, in parallel up to
5
+ * a bounded concurrency limit, with retry-once on failure.
6
+ *
7
+ * Requirements covered:
8
+ * - CTS-CLI-2: granular `fan-out` subcommand
9
+ * - CTS-SPEC-1.2: bounded concurrent execution
10
+ * - CTS-SPEC-5: failure detection + retry + non-blocking continuation
11
+ */
12
+ import { existsSync } from "node:fs";
13
+ import { cachePaths } from "../../codebase-to-spec/cache.js";
14
+ import { ExitCode } from "../../codebase-to-spec/exit-codes.js";
15
+ import { DEFAULT_FAN_OUT_CONCURRENCY, runFanOut, } from "../../codebase-to-spec/fan-out.js";
16
+ import { StdoutProgress } from "../../codebase-to-spec/progress.js";
17
+ import { findProjectRoot } from "../../utils/project-settings.js";
18
+ import { readFinalOutline } from "./plan-loop.js";
19
+ export async function fanOutCommand(options = {}) {
20
+ const progress = new StdoutProgress();
21
+ const projectRoot = options.projectRoot ?? findProjectRoot(process.cwd()) ?? process.cwd();
22
+ const paths = cachePaths(projectRoot);
23
+ const cliBinary = options.cliBinary ?? "dotrequirements";
24
+ if (!existsSync(paths.outlineFinal)) {
25
+ process.stderr.write(`Missing outline at ${paths.outlineFinal}. Run \`dotrequirements cts plan-loop\` first.\n`);
26
+ process.exitCode = ExitCode.MissingInput;
27
+ return;
28
+ }
29
+ if (!existsSync(paths.source)) {
30
+ process.stderr.write(`Missing uncompressed pack at ${paths.source}. Run \`dotrequirements cts pack\` first.\n`);
31
+ process.exitCode = ExitCode.MissingInput;
32
+ return;
33
+ }
34
+ const outline = readFinalOutline(projectRoot);
35
+ const concurrency = options.concurrency ?? DEFAULT_FAN_OUT_CONCURRENCY;
36
+ progress.emit({
37
+ stage: "specify",
38
+ step: "start",
39
+ message: `Fan-out: ${outline.areas.length} areas (concurrency=${concurrency})`,
40
+ });
41
+ const result = await runFanOut({
42
+ outline,
43
+ fullPackPath: paths.source,
44
+ partialPathFor: (sanitized) => paths.partial(sanitized),
45
+ slicePathFor: (sanitized) => `${paths.partialsDir}/slice-${sanitized}.txt`,
46
+ validateCommand: `${cliBinary} cts validate`,
47
+ styleCheckCommand: `${cliBinary} cts style-check`,
48
+ addDirs: [paths.root],
49
+ concurrency,
50
+ model: options.model,
51
+ progress,
52
+ });
53
+ // Summary
54
+ const failed = result.outcomes.filter((o) => o.status === "failed");
55
+ const completed = result.outcomes.filter((o) => o.status === "completed");
56
+ const skipped = result.outcomes.filter((o) => o.status === "skipped-resume");
57
+ progress.emit({
58
+ stage: "specify",
59
+ step: "summary",
60
+ message: `Completed: ${completed.length} / Skipped (resume): ${skipped.length} / Failed: ${failed.length}`,
61
+ data: {
62
+ completed: completed.length,
63
+ skipped: skipped.length,
64
+ failed: failed.length,
65
+ },
66
+ });
67
+ if (failed.length > 0) {
68
+ for (const o of failed) {
69
+ process.stderr.write(` failed: ${o.area.name} (${o.area.prefix}) — ${o.failureCause ?? "unknown"}\n`);
70
+ }
71
+ // Per CTS-SPEC-5, a failed specifier does not block the rest of the
72
+ // pipeline; we still let the caller decide. Surface non-zero so wrappers
73
+ // can react if they care.
74
+ process.exitCode = ExitCode.StageFailed;
75
+ }
76
+ }
77
+ //# sourceMappingURL=fan-out.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Command registrar for `dotrequirements codebase-to-spec` (alias: `cts`).
3
+ *
4
+ * Subcommands route to focused handlers in this directory. Each subcommand can
5
+ * be invoked granularly (e.g., `dotrequirements cts pack`) per CTS-CLI-2.
6
+ */
7
+ import type { Command } from "commander";
8
+ export declare function registerCodebaseToSpec(program: Command): void;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Command registrar for `dotrequirements codebase-to-spec` (alias: `cts`).
3
+ *
4
+ * Subcommands route to focused handlers in this directory. Each subcommand can
5
+ * be invoked granularly (e.g., `dotrequirements cts pack`) per CTS-CLI-2.
6
+ */
7
+ import { composeCommand } from "./compose.js";
8
+ import { editLoopCommand } from "./edit-loop.js";
9
+ import { fanOutCommand } from "./fan-out.js";
10
+ import { packCommand } from "./pack.js";
11
+ import { planLoopCommand } from "./plan-loop.js";
12
+ import { presentCommand } from "./present.js";
13
+ import { runCommand } from "./run.js";
14
+ import { skillInstallCommand } from "./skill-install.js";
15
+ import { specifyAreaCommand } from "./specify-area.js";
16
+ import { styleCheckCommand } from "./style-check.js";
17
+ import { validateCommand } from "./validate.js";
18
+ export function registerCodebaseToSpec(program) {
19
+ const cts = program
20
+ .command("codebase-to-spec")
21
+ .alias("cts")
22
+ .description("Generate dotrequirements behavioral specifications from a codebase");
23
+ cts
24
+ .command("pack")
25
+ .description("Pack the codebase (compressed and uncompressed views) into the cache")
26
+ .option("-s, --scope <path>", "Limit to files under this path (subdir of project root)")
27
+ .option("--fresh", "Clear the cache before running")
28
+ .option("--budget <tokens>", "Override the working-context budget (in tokens)", (v) => parseInt(v, 10))
29
+ .action((opts) => packCommand({ ...opts, budgetTokens: opts.budget }));
30
+ cts
31
+ .command("plan-loop")
32
+ .description("Run the planner + outline review loop on the cached pack")
33
+ .option("--max-turns <n>", "Hard cap on review turns", (v) => parseInt(v, 10))
34
+ .option("--model <name>", "Override the model used by the planner and reviewer")
35
+ .action((opts) => planLoopCommand({
36
+ maxTurns: opts.maxTurns,
37
+ model: opts.model,
38
+ }));
39
+ cts
40
+ .command("specify-area <name>")
41
+ .description("Run the specifier for one named area from the cached outline")
42
+ .option("--model <name>", "Override the model used by the specifier")
43
+ .action((name, opts) => specifyAreaCommand(name, {
44
+ model: opts.model,
45
+ }));
46
+ cts
47
+ .command("fan-out")
48
+ .description("Run all specifiers in parallel for areas in the cached outline")
49
+ .option("-c, --concurrency <n>", "Max concurrent specifiers", (v) => parseInt(v, 10))
50
+ .option("--model <name>", "Override the model used by specifiers")
51
+ .action((opts) => fanOutCommand({
52
+ concurrency: opts.concurrency,
53
+ model: opts.model,
54
+ }));
55
+ cts
56
+ .command("validate <partial-path>")
57
+ .description("Validate the schema/syntax of a partial-spec file (deterministic, offline)")
58
+ .action((partialPath) => validateCommand(partialPath));
59
+ cts
60
+ .command("style-check <partial-path>")
61
+ .description("Run a local style-check on a partial-spec file (severity-categorized feedback)")
62
+ .option("--model <name>", "Override the model used for the check")
63
+ .action((partialPath, opts) => styleCheckCommand(partialPath, { model: opts.model }));
64
+ cts
65
+ .command("compose")
66
+ .description("Assemble per-area partials into a single composed spec")
67
+ .action(() => composeCommand());
68
+ cts
69
+ .command("edit-loop")
70
+ .description("Run the spec reviewer + editor loop on the composed spec")
71
+ .option("--max-turns <n>", "Hard cap on edit-loop turns", (v) => parseInt(v, 10))
72
+ .option("--model <name>", "Override the model used by the reviewer and editor")
73
+ .action((opts) => editLoopCommand({
74
+ maxTurns: opts.maxTurns,
75
+ model: opts.model,
76
+ }));
77
+ cts
78
+ .command("present")
79
+ .description("Write the final spec to .requirements/ and emit a pipeline summary")
80
+ .option("--interactive", "Force interactive mode (override TTY detection)")
81
+ .option("--non-interactive", "Force non-interactive mode (override TTY detection)")
82
+ .option("--overwrite", "Replace existing .requirements/ files without prompting")
83
+ .option("--skip-existing", "Leave existing .requirements/ files untouched")
84
+ .action((opts) => {
85
+ const forceMode = opts.interactive
86
+ ? "interactive"
87
+ : opts.nonInteractive
88
+ ? "non-interactive"
89
+ : undefined;
90
+ return presentCommand({
91
+ forceMode,
92
+ overwrite: opts.overwrite,
93
+ skipExisting: opts.skipExisting,
94
+ });
95
+ });
96
+ cts
97
+ .command("run")
98
+ .description("Run the full pipeline (pack → plan → specify → compose → edit → present)")
99
+ .option("-s, --scope <path>", "Limit to files under this path (subdir of project root)")
100
+ .option("--fresh", "Clear the cache before running")
101
+ .option("--budget <tokens>", "Override the working-context budget (in tokens)", (v) => parseInt(v, 10))
102
+ .option("--max-turns <n>", "Hard cap on outline review turns", (v) => parseInt(v, 10))
103
+ .option("--model <name>", "Override the model used by agent calls")
104
+ .option("--interactive", "Force interactive mode for the present stage")
105
+ .option("--non-interactive", "Force non-interactive mode for the present stage")
106
+ .option("--overwrite", "Replace existing .requirements/ files without prompting")
107
+ .option("--skip-existing", "Leave existing .requirements/ files untouched")
108
+ .action((opts) => {
109
+ const forceMode = opts.interactive
110
+ ? "interactive"
111
+ : opts.nonInteractive
112
+ ? "non-interactive"
113
+ : undefined;
114
+ return runCommand({
115
+ ...opts,
116
+ budgetTokens: opts.budget,
117
+ maxTurns: opts.maxTurns,
118
+ forceMode,
119
+ overwrite: opts.overwrite,
120
+ skipExisting: opts.skipExisting,
121
+ });
122
+ });
123
+ cts
124
+ .command("skill-install")
125
+ .description("Install the codebase-to-spec skill (SKILL.md) into the host's skills directory")
126
+ .option("--global", "Install to ~/.claude/skills/ instead of the project")
127
+ .option("--target-dir <path>", "Install into a custom skills directory (for non-Claude-Code hosts)")
128
+ .option("--overwrite", "Replace an existing SKILL.md if one is already present")
129
+ .action((opts) => skillInstallCommand({
130
+ global: opts.global,
131
+ targetDir: opts.targetDir,
132
+ overwrite: opts.overwrite,
133
+ }));
134
+ }
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec pack` subcommand.
3
+ *
4
+ * Packs the codebase into the cache directory and runs the budget check.
5
+ *
6
+ * Requirements covered:
7
+ * - CTS-CLI-3: Pipeline refuses to spec a codebase that exceeds the working context budget
8
+ * - CTS-PACK-1: Pack stage produces compressed and uncompressed views of the codebase
9
+ * - CTS-PACK-2: Engineer can extend the ignore list per project
10
+ * - CTS-OBSERVE-1: CLI emits structured progress as the pipeline runs
11
+ */
12
+ export interface PackOptions {
13
+ scope?: string;
14
+ fresh?: boolean;
15
+ budgetTokens?: number;
16
+ /** Override progress emitter, mainly for tests. */
17
+ progress?: import("../../codebase-to-spec/progress.js").ProgressEmitter;
18
+ /** Override the project root, mainly for tests. */
19
+ projectRoot?: string;
20
+ }
21
+ export declare function packCommand(rawOptions?: PackOptions): Promise<void>;
22
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec pack` subcommand.
3
+ *
4
+ * Packs the codebase into the cache directory and runs the budget check.
5
+ *
6
+ * Requirements covered:
7
+ * - CTS-CLI-3: Pipeline refuses to spec a codebase that exceeds the working context budget
8
+ * - CTS-PACK-1: Pack stage produces compressed and uncompressed views of the codebase
9
+ * - CTS-PACK-2: Engineer can extend the ignore list per project
10
+ * - CTS-OBSERVE-1: CLI emits structured progress as the pipeline runs
11
+ */
12
+ import { resolve } from "node:path";
13
+ import { checkBudget, countTokensInFileExact, DEFAULT_BUDGET_TOKENS, formatBudgetExceededMessage, } from "../../codebase-to-spec/budget.js";
14
+ import { clearCache, ensureCacheDir } from "../../codebase-to-spec/cache.js";
15
+ import { ExitCode } from "../../codebase-to-spec/exit-codes.js";
16
+ import { runPack } from "../../codebase-to-spec/pack.js";
17
+ import { StdoutProgress } from "../../codebase-to-spec/progress.js";
18
+ import { findProjectRoot } from "../../utils/project-settings.js";
19
+ export async function packCommand(rawOptions = {}) {
20
+ const progress = rawOptions.progress ?? new StdoutProgress();
21
+ const projectRoot = rawOptions.projectRoot ?? findProjectRoot(process.cwd()) ?? process.cwd();
22
+ const budgetTokens = rawOptions.budgetTokens ?? DEFAULT_BUDGET_TOKENS;
23
+ if (rawOptions.fresh) {
24
+ progress.emit({
25
+ stage: "pack",
26
+ step: "clear-cache",
27
+ message: "Clearing existing cache (--fresh)",
28
+ });
29
+ clearCache(projectRoot);
30
+ }
31
+ const paths = ensureCacheDir(projectRoot);
32
+ const scope = rawOptions.scope
33
+ ? resolve(projectRoot, rawOptions.scope)
34
+ : undefined;
35
+ progress.emit({
36
+ stage: "pack",
37
+ step: "start",
38
+ message: scope
39
+ ? `Packing codebase at ${scope}`
40
+ : `Packing codebase at ${projectRoot}`,
41
+ });
42
+ const packResult = await runPack({
43
+ projectRoot,
44
+ paths,
45
+ scope: rawOptions.scope,
46
+ });
47
+ progress.emit({
48
+ stage: "pack",
49
+ step: "done",
50
+ message: `Packed ${packResult.fileCount} files → ${paths.overview} (compressed), ${paths.source} (uncompressed)`,
51
+ data: { fileCount: packResult.fileCount },
52
+ });
53
+ // Budget check (CTS-CLI-3)
54
+ const measured = countTokensInFileExact(paths.overview);
55
+ const budget = checkBudget(measured, budgetTokens);
56
+ progress.emit({
57
+ stage: "pack",
58
+ step: "budget-check",
59
+ message: `Compressed pack is ${budget.measuredTokens.toLocaleString()} tokens (budget: ${budget.budgetTokens.toLocaleString()})`,
60
+ data: {
61
+ measuredTokens: budget.measuredTokens,
62
+ budgetTokens: budget.budgetTokens,
63
+ },
64
+ });
65
+ if (!budget.withinBudget) {
66
+ process.stderr.write(`${formatBudgetExceededMessage(budget)}\n`);
67
+ process.exitCode = ExitCode.BudgetExceeded;
68
+ return;
69
+ }
70
+ progress.emit({
71
+ stage: "pack",
72
+ step: "budget-ok",
73
+ message: `Budget OK. Ready for the plan stage.`,
74
+ });
75
+ }
76
+ //# sourceMappingURL=pack.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec plan-loop` subcommand.
3
+ *
4
+ * Reads the compressed pack from the cache and runs the outline review loop
5
+ * (planner → reviewer → revise → ... → approved). Writes per-turn artifacts
6
+ * and the final outline.
7
+ *
8
+ * Requirements covered:
9
+ * - CTS-CLI-2: `dotrequirements cts plan-loop` runs only the outline review loop and exits
10
+ * - CTS-PLAN-1..6: end-to-end loop behavior
11
+ * - CTS-RESUME-1.1: skip loop if outline-final.json exists
12
+ * - CTS-OBSERVE-1, CTS-OBSERVE-2: progress + failure observability
13
+ */
14
+ import type { Outline } from "../../codebase-to-spec/schemas.js";
15
+ export interface PlanLoopOptions {
16
+ maxTurns?: number;
17
+ model?: string;
18
+ progress?: import("../../codebase-to-spec/progress.js").ProgressEmitter;
19
+ projectRoot?: string;
20
+ }
21
+ export declare function planLoopCommand(rawOptions?: PlanLoopOptions): Promise<void>;
22
+ /**
23
+ * Helper used by `cts run` and tests to consume the outline that plan-loop wrote.
24
+ */
25
+ export declare function readFinalOutline(projectRoot: string): Outline;
26
+ //# sourceMappingURL=plan-loop.d.ts.map
@@ -0,0 +1,105 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec plan-loop` subcommand.
3
+ *
4
+ * Reads the compressed pack from the cache and runs the outline review loop
5
+ * (planner → reviewer → revise → ... → approved). Writes per-turn artifacts
6
+ * and the final outline.
7
+ *
8
+ * Requirements covered:
9
+ * - CTS-CLI-2: `dotrequirements cts plan-loop` runs only the outline review loop and exits
10
+ * - CTS-PLAN-1..6: end-to-end loop behavior
11
+ * - CTS-RESUME-1.1: skip loop if outline-final.json exists
12
+ * - CTS-OBSERVE-1, CTS-OBSERVE-2: progress + failure observability
13
+ */
14
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
15
+ import { cachePaths } from "../../codebase-to-spec/cache.js";
16
+ import { ExitCode } from "../../codebase-to-spec/exit-codes.js";
17
+ import { DEFAULT_OUTLINE_LOOP_MAX_TURNS, runOutlineReviewLoop, } from "../../codebase-to-spec/outline-review-loop.js";
18
+ import { StdoutProgress } from "../../codebase-to-spec/progress.js";
19
+ import { findProjectRoot } from "../../utils/project-settings.js";
20
+ export async function planLoopCommand(rawOptions = {}) {
21
+ const progress = rawOptions.progress ?? new StdoutProgress();
22
+ const projectRoot = rawOptions.projectRoot ?? findProjectRoot(process.cwd()) ?? process.cwd();
23
+ const paths = cachePaths(projectRoot);
24
+ const maxTurns = rawOptions.maxTurns ?? DEFAULT_OUTLINE_LOOP_MAX_TURNS;
25
+ // Resume — if outline-final.json already exists, skip the loop entirely.
26
+ if (existsSync(paths.outlineFinal)) {
27
+ progress.emit({
28
+ stage: "plan",
29
+ step: "resume-skip",
30
+ message: `outline-final.json exists at ${paths.outlineFinal}; skipping plan loop`,
31
+ });
32
+ return;
33
+ }
34
+ // Require the compressed pack from the prior stage.
35
+ if (!existsSync(paths.overview)) {
36
+ process.stderr.write(`Missing compressed pack at ${paths.overview}. Run \`dotrequirements cts pack\` first.\n`);
37
+ process.exitCode = ExitCode.MissingInput;
38
+ return;
39
+ }
40
+ progress.emit({
41
+ stage: "plan",
42
+ step: "start",
43
+ message: `Starting plan + outline review loop (max-turns=${maxTurns})`,
44
+ });
45
+ let result;
46
+ try {
47
+ result = await runOutlineReviewLoop({
48
+ overviewPath: paths.overview,
49
+ addDirs: [paths.root],
50
+ maxTurns,
51
+ model: rawOptions.model,
52
+ progress,
53
+ });
54
+ }
55
+ catch (err) {
56
+ process.stderr.write(`\nPlan loop failed: ${err instanceof Error ? err.message : String(err)}\n`);
57
+ process.exitCode = ExitCode.StageFailed;
58
+ return;
59
+ }
60
+ // Persist per-turn artifacts (one outline per turn, one review per turn) so
61
+ // we have full evidence and resumability.
62
+ result.outlinesByTurn.forEach((outline, idx) => {
63
+ const path = paths.outlineTurn(idx + 1);
64
+ writeFileSync(path, `${JSON.stringify(outline, null, 2)}\n`, "utf-8");
65
+ });
66
+ result.reviewsByTurn.forEach((review, idx) => {
67
+ const path = paths.outlineReviewTurn(idx + 1);
68
+ writeFileSync(path, `${JSON.stringify(review, null, 2)}\n`, "utf-8");
69
+ });
70
+ // Write the final outline.
71
+ writeFileSync(paths.outlineFinal, `${JSON.stringify(result.outline, null, 2)}\n`, "utf-8");
72
+ if (result.hitMaxTurns) {
73
+ progress.emit({
74
+ stage: "plan",
75
+ step: "max-turns-hit",
76
+ message: `Loop hit max-turns (${maxTurns}) without converging. Using latest outline anyway.`,
77
+ data: { turnsUsed: result.turnsUsed, finalVerdict: result.finalVerdict },
78
+ });
79
+ process.exitCode = ExitCode.MaxTurnsHit;
80
+ }
81
+ else {
82
+ progress.emit({
83
+ stage: "plan",
84
+ step: "done",
85
+ message: `Plan loop converged at turn ${result.turnsUsed} with verdict: ${result.finalVerdict}`,
86
+ data: { turnsUsed: result.turnsUsed, finalVerdict: result.finalVerdict },
87
+ });
88
+ }
89
+ progress.emit({
90
+ stage: "plan",
91
+ step: "outline-written",
92
+ message: `Final outline → ${paths.outlineFinal} (${result.outline.areas.length} areas)`,
93
+ });
94
+ }
95
+ /**
96
+ * Helper used by `cts run` and tests to consume the outline that plan-loop wrote.
97
+ */
98
+ export function readFinalOutline(projectRoot) {
99
+ const paths = cachePaths(projectRoot);
100
+ if (!existsSync(paths.outlineFinal)) {
101
+ throw new Error(`Missing ${paths.outlineFinal}. Run \`cts plan-loop\` first.`);
102
+ }
103
+ return JSON.parse(readFileSync(paths.outlineFinal, "utf-8"));
104
+ }
105
+ //# sourceMappingURL=plan-loop.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec present` subcommand.
3
+ *
4
+ * Writes the final spec to `.requirements/` and emits a pipeline summary.
5
+ *
6
+ * Requirements covered:
7
+ * - CTS-CLI-2: granular `present` subcommand
8
+ * - CTS-CLI-4: TTY-driven interactive/non-interactive selection
9
+ * - CTS-PRESENT-1..4
10
+ */
11
+ export interface PresentCmdOptions {
12
+ /** Force --interactive or --non-interactive (overrides TTY detection). */
13
+ forceMode?: "interactive" | "non-interactive";
14
+ /** Replace existing .requirements/ files without prompting (non-interactive). */
15
+ overwrite?: boolean;
16
+ /** Skip writing files that would conflict (non-interactive). */
17
+ skipExisting?: boolean;
18
+ projectRoot?: string;
19
+ }
20
+ export declare function presentCommand(rawOptions?: PresentCmdOptions): Promise<void>;
21
+ //# sourceMappingURL=present.d.ts.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec present` subcommand.
3
+ *
4
+ * Writes the final spec to `.requirements/` and emits a pipeline summary.
5
+ *
6
+ * Requirements covered:
7
+ * - CTS-CLI-2: granular `present` subcommand
8
+ * - CTS-CLI-4: TTY-driven interactive/non-interactive selection
9
+ * - CTS-PRESENT-1..4
10
+ */
11
+ import { existsSync, writeFileSync } from "node:fs";
12
+ import { cachePaths } from "../../codebase-to-spec/cache.js";
13
+ import { ExitCode } from "../../codebase-to-spec/exit-codes.js";
14
+ import { detectMode } from "../../codebase-to-spec/interactive.js";
15
+ import { runPresent, } from "../../codebase-to-spec/present.js";
16
+ import { StdoutProgress } from "../../codebase-to-spec/progress.js";
17
+ import { buildPipelineSummary, renderSummaryText, } from "../../codebase-to-spec/summary.js";
18
+ import { findProjectRoot } from "../../utils/project-settings.js";
19
+ import { readFinalOutline } from "./plan-loop.js";
20
+ function resolveOverwritePolicy(isInteractive, options) {
21
+ if (options.overwrite && options.skipExisting) {
22
+ return { error: "--overwrite and --skip-existing are mutually exclusive." };
23
+ }
24
+ if (options.overwrite)
25
+ return "overwrite";
26
+ if (options.skipExisting)
27
+ return "skip-existing";
28
+ if (isInteractive)
29
+ return "prompt";
30
+ return "fail-fast";
31
+ }
32
+ export async function presentCommand(rawOptions = {}) {
33
+ const progress = new StdoutProgress();
34
+ const projectRoot = rawOptions.projectRoot ?? findProjectRoot(process.cwd()) ?? process.cwd();
35
+ const paths = cachePaths(projectRoot);
36
+ if (!existsSync(paths.outlineFinal)) {
37
+ process.stderr.write(`Missing outline at ${paths.outlineFinal}. Run \`dotrequirements cts plan-loop\` first.\n`);
38
+ process.exitCode = ExitCode.MissingInput;
39
+ return;
40
+ }
41
+ if (!existsSync(paths.specFinal)) {
42
+ process.stderr.write(`Missing final spec at ${paths.specFinal}. Run \`dotrequirements cts edit-loop\` first.\n`);
43
+ process.exitCode = ExitCode.MissingInput;
44
+ return;
45
+ }
46
+ const outline = readFinalOutline(projectRoot);
47
+ const { isInteractive } = detectMode(rawOptions.forceMode);
48
+ const policy = resolveOverwritePolicy(isInteractive, rawOptions);
49
+ if (typeof policy === "object") {
50
+ process.stderr.write(`${policy.error}\n`);
51
+ process.exitCode = ExitCode.InvalidFlags;
52
+ return;
53
+ }
54
+ progress.emit({
55
+ stage: "present",
56
+ step: "start",
57
+ message: `Writing final spec to .requirements/ (mode: ${isInteractive ? "interactive" : "non-interactive"}, policy: ${policy})`,
58
+ });
59
+ const result = await runPresent({
60
+ outline,
61
+ finalSpecPath: paths.specFinal,
62
+ projectRoot,
63
+ overwritePolicy: policy,
64
+ });
65
+ // Per-file outcome announcements.
66
+ for (const action of result.actions) {
67
+ progress.emit({
68
+ stage: "present",
69
+ step: action.action,
70
+ message: `${action.action}: ${action.path}`,
71
+ });
72
+ }
73
+ if (!result.allWritten) {
74
+ if (result.conflictPath) {
75
+ // fail-fast bailed before any write.
76
+ process.stderr.write(`Refusing to overwrite ${result.conflictPath}. Re-run with --overwrite or --skip-existing, or run in interactive mode.\n`);
77
+ process.exitCode = ExitCode.OverwriteRefused;
78
+ return;
79
+ }
80
+ // Other partial failures (validation, merge conflict, etc.).
81
+ process.exitCode = ExitCode.StageFailed;
82
+ }
83
+ // Emit the pipeline summary.
84
+ const summary = buildPipelineSummary({
85
+ outline,
86
+ paths,
87
+ outputPaths: result.outputPaths,
88
+ });
89
+ writeFileSync(paths.pipelineSummary, `${JSON.stringify(summary, null, 2)}\n`, "utf-8");
90
+ process.stdout.write(`\n${renderSummaryText(summary)}\n`);
91
+ }
92
+ //# sourceMappingURL=present.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec run` subcommand.
3
+ *
4
+ * Chains the pipeline stages. Currently: pack → plan-loop. Subsequent
5
+ * increments will chain specify → compose → edit → present.
6
+ *
7
+ * Requirements covered (incrementally):
8
+ * - CTS-CLI-1: User can run the pipeline end-to-end with a single command
9
+ */
10
+ import { type PackOptions } from "./pack.js";
11
+ export interface RunOptions extends PackOptions {
12
+ maxTurns?: number;
13
+ model?: string;
14
+ concurrency?: number;
15
+ forceMode?: "interactive" | "non-interactive";
16
+ overwrite?: boolean;
17
+ skipExisting?: boolean;
18
+ }
19
+ export declare function runCommand(options?: RunOptions): Promise<void>;
20
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `dotrequirements codebase-to-spec run` subcommand.
3
+ *
4
+ * Chains the pipeline stages. Currently: pack → plan-loop. Subsequent
5
+ * increments will chain specify → compose → edit → present.
6
+ *
7
+ * Requirements covered (incrementally):
8
+ * - CTS-CLI-1: User can run the pipeline end-to-end with a single command
9
+ */
10
+ import { ExitCode } from "../../codebase-to-spec/exit-codes.js";
11
+ import { composeCommand } from "./compose.js";
12
+ import { editLoopCommand } from "./edit-loop.js";
13
+ import { fanOutCommand } from "./fan-out.js";
14
+ import { packCommand } from "./pack.js";
15
+ import { planLoopCommand } from "./plan-loop.js";
16
+ import { presentCommand } from "./present.js";
17
+ export async function runCommand(options = {}) {
18
+ // Stage 1 — Pack
19
+ await packCommand(options);
20
+ if (process.exitCode && process.exitCode !== 0) {
21
+ return;
22
+ }
23
+ // Stage 2 — Plan + outline review loop
24
+ await planLoopCommand({
25
+ maxTurns: options.maxTurns,
26
+ model: options.model,
27
+ progress: options.progress,
28
+ projectRoot: options.projectRoot,
29
+ });
30
+ if (process.exitCode &&
31
+ process.exitCode !== 0 &&
32
+ process.exitCode !== ExitCode.MaxTurnsHit) {
33
+ return;
34
+ }
35
+ // Reset exit code from MaxTurnsHit so downstream stages can still proceed
36
+ // (we use the latest outline anyway per CTS-PLAN-6).
37
+ if (process.exitCode === ExitCode.MaxTurnsHit) {
38
+ process.exitCode = 0;
39
+ }
40
+ // Stage 3 — Specifier fan-out
41
+ await fanOutCommand({
42
+ concurrency: options.concurrency,
43
+ model: options.model,
44
+ projectRoot: options.projectRoot,
45
+ });
46
+ if (process.exitCode &&
47
+ process.exitCode !== 0 &&
48
+ process.exitCode !== ExitCode.StageFailed) {
49
+ return;
50
+ }
51
+ // StageFailed from fan-out means some specifiers failed; per CTS-SPEC-5 the
52
+ // pipeline continues. Other areas still produced partials.
53
+ if (process.exitCode === ExitCode.StageFailed) {
54
+ process.exitCode = 0;
55
+ }
56
+ // Stage 4 — Compose
57
+ await composeCommand({ projectRoot: options.projectRoot });
58
+ if (process.exitCode && process.exitCode !== 0) {
59
+ return;
60
+ }
61
+ // Stage 5 — Spec review + edit loop
62
+ await editLoopCommand({
63
+ maxTurns: options.maxTurns,
64
+ model: options.model,
65
+ projectRoot: options.projectRoot,
66
+ });
67
+ if (process.exitCode &&
68
+ process.exitCode !== 0 &&
69
+ process.exitCode !== ExitCode.MaxTurnsHit) {
70
+ return;
71
+ }
72
+ if (process.exitCode === ExitCode.MaxTurnsHit) {
73
+ process.exitCode = 0;
74
+ }
75
+ // Stage 6 — Present (write final spec to .requirements/ + emit summary)
76
+ await presentCommand({
77
+ forceMode: options.forceMode,
78
+ overwrite: options.overwrite,
79
+ skipExisting: options.skipExisting,
80
+ projectRoot: options.projectRoot,
81
+ });
82
+ // Present sets a non-zero exit code on overwrite refusal or validation
83
+ // failure; let it propagate.
84
+ }
85
+ //# sourceMappingURL=run.js.map