@nathapp/nax 0.50.2 → 0.51.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 (352) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/nax.js +579 -373
  3. package/package.json +1 -3
  4. package/bin/nax.ts +0 -1195
  5. package/src/acceptance/fix-generator.ts +0 -322
  6. package/src/acceptance/generator.ts +0 -423
  7. package/src/acceptance/index.ts +0 -42
  8. package/src/acceptance/refinement.ts +0 -224
  9. package/src/acceptance/templates/cli.ts +0 -47
  10. package/src/acceptance/templates/component.ts +0 -78
  11. package/src/acceptance/templates/e2e.ts +0 -43
  12. package/src/acceptance/templates/index.ts +0 -21
  13. package/src/acceptance/templates/snapshot.ts +0 -50
  14. package/src/acceptance/templates/unit.ts +0 -48
  15. package/src/acceptance/types.ts +0 -135
  16. package/src/agents/acp/adapter.ts +0 -888
  17. package/src/agents/acp/cost.ts +0 -9
  18. package/src/agents/acp/index.ts +0 -7
  19. package/src/agents/acp/interaction-bridge.ts +0 -126
  20. package/src/agents/acp/parser.ts +0 -119
  21. package/src/agents/acp/spawn-client.ts +0 -373
  22. package/src/agents/acp/types.ts +0 -22
  23. package/src/agents/aider/adapter.ts +0 -135
  24. package/src/agents/claude/adapter.ts +0 -258
  25. package/src/agents/claude/complete.ts +0 -80
  26. package/src/agents/claude/cost.ts +0 -16
  27. package/src/agents/claude/execution.ts +0 -215
  28. package/src/agents/claude/index.ts +0 -3
  29. package/src/agents/claude/interactive.ts +0 -77
  30. package/src/agents/claude/plan.ts +0 -179
  31. package/src/agents/codex/adapter.ts +0 -153
  32. package/src/agents/cost/calculate.ts +0 -154
  33. package/src/agents/cost/index.ts +0 -10
  34. package/src/agents/cost/parse.ts +0 -97
  35. package/src/agents/cost/pricing.ts +0 -59
  36. package/src/agents/cost/types.ts +0 -45
  37. package/src/agents/gemini/adapter.ts +0 -177
  38. package/src/agents/index.ts +0 -18
  39. package/src/agents/opencode/adapter.ts +0 -106
  40. package/src/agents/registry.ts +0 -136
  41. package/src/agents/shared/decompose.ts +0 -154
  42. package/src/agents/shared/model-resolution.ts +0 -43
  43. package/src/agents/shared/types-extended.ts +0 -164
  44. package/src/agents/shared/validation.ts +0 -69
  45. package/src/agents/shared/version-detection.ts +0 -109
  46. package/src/agents/types.ts +0 -205
  47. package/src/analyze/classifier.ts +0 -282
  48. package/src/analyze/index.ts +0 -16
  49. package/src/analyze/scanner.ts +0 -171
  50. package/src/analyze/types.ts +0 -51
  51. package/src/cli/accept.ts +0 -108
  52. package/src/cli/agents.ts +0 -87
  53. package/src/cli/analyze-parser.ts +0 -291
  54. package/src/cli/analyze.ts +0 -352
  55. package/src/cli/config-descriptions.ts +0 -218
  56. package/src/cli/config-diff.ts +0 -103
  57. package/src/cli/config-display.ts +0 -285
  58. package/src/cli/config-get.ts +0 -55
  59. package/src/cli/config.ts +0 -14
  60. package/src/cli/constitution.ts +0 -17
  61. package/src/cli/diagnose-analysis.ts +0 -159
  62. package/src/cli/diagnose-formatter.ts +0 -87
  63. package/src/cli/diagnose.ts +0 -203
  64. package/src/cli/generate.ts +0 -250
  65. package/src/cli/index.ts +0 -42
  66. package/src/cli/init-context.ts +0 -405
  67. package/src/cli/init-detect.ts +0 -303
  68. package/src/cli/init.ts +0 -296
  69. package/src/cli/interact.ts +0 -295
  70. package/src/cli/plan.ts +0 -509
  71. package/src/cli/plugins.ts +0 -122
  72. package/src/cli/prompts-export.ts +0 -58
  73. package/src/cli/prompts-init.ts +0 -200
  74. package/src/cli/prompts-main.ts +0 -183
  75. package/src/cli/prompts-shared.ts +0 -70
  76. package/src/cli/prompts-tdd.ts +0 -88
  77. package/src/cli/prompts.ts +0 -17
  78. package/src/cli/runs.ts +0 -174
  79. package/src/cli/status-cost.ts +0 -151
  80. package/src/cli/status-features.ts +0 -405
  81. package/src/cli/status.ts +0 -13
  82. package/src/commands/common.ts +0 -171
  83. package/src/commands/diagnose.ts +0 -17
  84. package/src/commands/index.ts +0 -9
  85. package/src/commands/logs-formatter.ts +0 -201
  86. package/src/commands/logs-reader.ts +0 -171
  87. package/src/commands/logs.ts +0 -103
  88. package/src/commands/precheck.ts +0 -86
  89. package/src/commands/runs.ts +0 -220
  90. package/src/commands/unlock.ts +0 -96
  91. package/src/config/defaults.ts +0 -217
  92. package/src/config/index.ts +0 -22
  93. package/src/config/loader.ts +0 -143
  94. package/src/config/merge.ts +0 -106
  95. package/src/config/merger.ts +0 -147
  96. package/src/config/path-security.ts +0 -121
  97. package/src/config/paths.ts +0 -27
  98. package/src/config/permissions.ts +0 -63
  99. package/src/config/runtime-types.ts +0 -520
  100. package/src/config/schema-types.ts +0 -53
  101. package/src/config/schema.ts +0 -60
  102. package/src/config/schemas.ts +0 -425
  103. package/src/config/test-strategy.ts +0 -71
  104. package/src/config/types.ts +0 -57
  105. package/src/config/validate.ts +0 -103
  106. package/src/constitution/generator.ts +0 -158
  107. package/src/constitution/generators/aider.ts +0 -41
  108. package/src/constitution/generators/claude.ts +0 -35
  109. package/src/constitution/generators/cursor.ts +0 -36
  110. package/src/constitution/generators/opencode.ts +0 -38
  111. package/src/constitution/generators/types.ts +0 -33
  112. package/src/constitution/generators/windsurf.ts +0 -36
  113. package/src/constitution/index.ts +0 -11
  114. package/src/constitution/loader.ts +0 -121
  115. package/src/constitution/types.ts +0 -31
  116. package/src/context/auto-detect.ts +0 -228
  117. package/src/context/builder.ts +0 -299
  118. package/src/context/elements.ts +0 -122
  119. package/src/context/formatter.ts +0 -107
  120. package/src/context/generator.ts +0 -343
  121. package/src/context/generators/aider.ts +0 -34
  122. package/src/context/generators/claude.ts +0 -28
  123. package/src/context/generators/codex.ts +0 -28
  124. package/src/context/generators/cursor.ts +0 -28
  125. package/src/context/generators/gemini.ts +0 -28
  126. package/src/context/generators/opencode.ts +0 -30
  127. package/src/context/generators/windsurf.ts +0 -28
  128. package/src/context/greenfield.ts +0 -114
  129. package/src/context/index.ts +0 -34
  130. package/src/context/injector.ts +0 -279
  131. package/src/context/parent-context.ts +0 -39
  132. package/src/context/test-scanner.ts +0 -370
  133. package/src/context/types.ts +0 -98
  134. package/src/decompose/apply.ts +0 -50
  135. package/src/decompose/builder.ts +0 -181
  136. package/src/decompose/index.ts +0 -8
  137. package/src/decompose/sections/codebase.ts +0 -26
  138. package/src/decompose/sections/constraints.ts +0 -32
  139. package/src/decompose/sections/index.ts +0 -4
  140. package/src/decompose/sections/sibling-stories.ts +0 -25
  141. package/src/decompose/sections/target-story.ts +0 -31
  142. package/src/decompose/types.ts +0 -55
  143. package/src/decompose/validators/complexity.ts +0 -45
  144. package/src/decompose/validators/coverage.ts +0 -134
  145. package/src/decompose/validators/dependency.ts +0 -91
  146. package/src/decompose/validators/index.ts +0 -35
  147. package/src/decompose/validators/overlap.ts +0 -128
  148. package/src/errors.ts +0 -67
  149. package/src/execution/batching.ts +0 -157
  150. package/src/execution/crash-heartbeat.ts +0 -77
  151. package/src/execution/crash-recovery.ts +0 -79
  152. package/src/execution/crash-signals.ts +0 -165
  153. package/src/execution/crash-writer.ts +0 -154
  154. package/src/execution/deferred-review.ts +0 -105
  155. package/src/execution/dry-run.ts +0 -81
  156. package/src/execution/escalation/escalation.ts +0 -46
  157. package/src/execution/escalation/index.ts +0 -13
  158. package/src/execution/escalation/tier-escalation.ts +0 -346
  159. package/src/execution/escalation/tier-outcome.ts +0 -143
  160. package/src/execution/executor-types.ts +0 -73
  161. package/src/execution/helpers.ts +0 -38
  162. package/src/execution/index.ts +0 -27
  163. package/src/execution/iteration-runner.ts +0 -160
  164. package/src/execution/lifecycle/acceptance-loop.ts +0 -280
  165. package/src/execution/lifecycle/headless-formatter.ts +0 -83
  166. package/src/execution/lifecycle/index.ts +0 -11
  167. package/src/execution/lifecycle/parallel-lifecycle.ts +0 -101
  168. package/src/execution/lifecycle/precheck-runner.ts +0 -140
  169. package/src/execution/lifecycle/run-cleanup.ts +0 -81
  170. package/src/execution/lifecycle/run-completion.ts +0 -247
  171. package/src/execution/lifecycle/run-initialization.ts +0 -187
  172. package/src/execution/lifecycle/run-regression.ts +0 -305
  173. package/src/execution/lifecycle/run-setup.ts +0 -240
  174. package/src/execution/lifecycle/story-size-prompts.ts +0 -123
  175. package/src/execution/lock.ts +0 -129
  176. package/src/execution/parallel-coordinator.ts +0 -281
  177. package/src/execution/parallel-executor-rectification-pass.ts +0 -117
  178. package/src/execution/parallel-executor-rectify.ts +0 -136
  179. package/src/execution/parallel-executor.ts +0 -330
  180. package/src/execution/parallel-worker.ts +0 -149
  181. package/src/execution/parallel.ts +0 -13
  182. package/src/execution/pid-registry.ts +0 -275
  183. package/src/execution/pipeline-result-handler.ts +0 -221
  184. package/src/execution/progress.ts +0 -27
  185. package/src/execution/queue-handler.ts +0 -109
  186. package/src/execution/runner-completion.ts +0 -171
  187. package/src/execution/runner-execution.ts +0 -243
  188. package/src/execution/runner-setup.ts +0 -86
  189. package/src/execution/runner.ts +0 -265
  190. package/src/execution/sequential-executor.ts +0 -219
  191. package/src/execution/status-file.ts +0 -264
  192. package/src/execution/status-writer.ts +0 -181
  193. package/src/execution/story-context.ts +0 -266
  194. package/src/execution/story-selector.ts +0 -76
  195. package/src/execution/test-output-parser.ts +0 -14
  196. package/src/execution/timeout-handler.ts +0 -100
  197. package/src/hooks/index.ts +0 -2
  198. package/src/hooks/runner.ts +0 -280
  199. package/src/hooks/types.ts +0 -79
  200. package/src/interaction/chain.ts +0 -170
  201. package/src/interaction/index.ts +0 -61
  202. package/src/interaction/init.ts +0 -84
  203. package/src/interaction/plugins/auto.ts +0 -243
  204. package/src/interaction/plugins/cli.ts +0 -300
  205. package/src/interaction/plugins/telegram.ts +0 -384
  206. package/src/interaction/plugins/webhook.ts +0 -286
  207. package/src/interaction/state.ts +0 -171
  208. package/src/interaction/triggers.ts +0 -250
  209. package/src/interaction/types.ts +0 -170
  210. package/src/logger/formatters.ts +0 -84
  211. package/src/logger/index.ts +0 -16
  212. package/src/logger/logger.ts +0 -296
  213. package/src/logger/types.ts +0 -48
  214. package/src/logging/formatter.ts +0 -355
  215. package/src/logging/index.ts +0 -22
  216. package/src/logging/types.ts +0 -93
  217. package/src/metrics/aggregator.ts +0 -191
  218. package/src/metrics/index.ts +0 -14
  219. package/src/metrics/tracker.ts +0 -200
  220. package/src/metrics/types.ts +0 -115
  221. package/src/optimizer/index.ts +0 -63
  222. package/src/optimizer/noop.optimizer.ts +0 -24
  223. package/src/optimizer/rule-based.optimizer.ts +0 -248
  224. package/src/optimizer/types.ts +0 -53
  225. package/src/pipeline/event-bus.ts +0 -297
  226. package/src/pipeline/events.ts +0 -130
  227. package/src/pipeline/index.ts +0 -19
  228. package/src/pipeline/runner.ts +0 -149
  229. package/src/pipeline/stages/acceptance-setup.ts +0 -140
  230. package/src/pipeline/stages/acceptance.ts +0 -215
  231. package/src/pipeline/stages/autofix.ts +0 -262
  232. package/src/pipeline/stages/completion.ts +0 -110
  233. package/src/pipeline/stages/constitution.ts +0 -63
  234. package/src/pipeline/stages/context.ts +0 -122
  235. package/src/pipeline/stages/execution.ts +0 -359
  236. package/src/pipeline/stages/index.ts +0 -86
  237. package/src/pipeline/stages/optimizer.ts +0 -74
  238. package/src/pipeline/stages/prompt.ts +0 -79
  239. package/src/pipeline/stages/queue-check.ts +0 -103
  240. package/src/pipeline/stages/rectify.ts +0 -101
  241. package/src/pipeline/stages/regression.ts +0 -99
  242. package/src/pipeline/stages/review.ts +0 -94
  243. package/src/pipeline/stages/routing.ts +0 -276
  244. package/src/pipeline/stages/verify.ts +0 -286
  245. package/src/pipeline/subscribers/events-writer.ts +0 -135
  246. package/src/pipeline/subscribers/hooks.ts +0 -179
  247. package/src/pipeline/subscribers/interaction.ts +0 -103
  248. package/src/pipeline/subscribers/registry.ts +0 -73
  249. package/src/pipeline/subscribers/reporters.ts +0 -174
  250. package/src/pipeline/types.ts +0 -220
  251. package/src/plugins/extensions.ts +0 -225
  252. package/src/plugins/index.ts +0 -33
  253. package/src/plugins/loader.ts +0 -352
  254. package/src/plugins/plugin-logger.ts +0 -41
  255. package/src/plugins/registry.ts +0 -168
  256. package/src/plugins/types.ts +0 -206
  257. package/src/plugins/validator.ts +0 -352
  258. package/src/prd/index.ts +0 -220
  259. package/src/prd/schema.ts +0 -268
  260. package/src/prd/types.ts +0 -273
  261. package/src/prd/validate.ts +0 -41
  262. package/src/precheck/checks-agents.ts +0 -63
  263. package/src/precheck/checks-blockers.ts +0 -23
  264. package/src/precheck/checks-cli.ts +0 -68
  265. package/src/precheck/checks-config.ts +0 -102
  266. package/src/precheck/checks-git.ts +0 -117
  267. package/src/precheck/checks-system.ts +0 -101
  268. package/src/precheck/checks-warnings.ts +0 -221
  269. package/src/precheck/checks.ts +0 -36
  270. package/src/precheck/index.ts +0 -374
  271. package/src/precheck/story-size-gate.ts +0 -144
  272. package/src/precheck/types.ts +0 -31
  273. package/src/prompts/builder.ts +0 -166
  274. package/src/prompts/index.ts +0 -2
  275. package/src/prompts/loader.ts +0 -43
  276. package/src/prompts/sections/conventions.ts +0 -19
  277. package/src/prompts/sections/hermetic.ts +0 -41
  278. package/src/prompts/sections/index.ts +0 -12
  279. package/src/prompts/sections/isolation.ts +0 -70
  280. package/src/prompts/sections/role-task.ts +0 -182
  281. package/src/prompts/sections/story.ts +0 -55
  282. package/src/prompts/sections/verdict.ts +0 -70
  283. package/src/prompts/types.ts +0 -21
  284. package/src/queue/index.ts +0 -2
  285. package/src/queue/manager.ts +0 -254
  286. package/src/queue/types.ts +0 -54
  287. package/src/review/index.ts +0 -8
  288. package/src/review/orchestrator.ts +0 -154
  289. package/src/review/runner.ts +0 -303
  290. package/src/review/types.ts +0 -70
  291. package/src/routing/batch-route.ts +0 -35
  292. package/src/routing/builder.ts +0 -81
  293. package/src/routing/chain.ts +0 -75
  294. package/src/routing/content-hash.ts +0 -25
  295. package/src/routing/index.ts +0 -20
  296. package/src/routing/loader.ts +0 -62
  297. package/src/routing/router.ts +0 -305
  298. package/src/routing/strategies/adaptive.ts +0 -215
  299. package/src/routing/strategies/index.ts +0 -8
  300. package/src/routing/strategies/keyword.ts +0 -180
  301. package/src/routing/strategies/llm-prompts.ts +0 -224
  302. package/src/routing/strategies/llm.ts +0 -320
  303. package/src/routing/strategies/manual.ts +0 -50
  304. package/src/routing/strategy.ts +0 -102
  305. package/src/tdd/cleanup.ts +0 -120
  306. package/src/tdd/index.ts +0 -22
  307. package/src/tdd/isolation.ts +0 -117
  308. package/src/tdd/orchestrator.ts +0 -406
  309. package/src/tdd/prompts.ts +0 -40
  310. package/src/tdd/rectification-gate.ts +0 -274
  311. package/src/tdd/session-runner.ts +0 -263
  312. package/src/tdd/types.ts +0 -84
  313. package/src/tdd/verdict-reader.ts +0 -266
  314. package/src/tdd/verdict.ts +0 -152
  315. package/src/tui/App.tsx +0 -265
  316. package/src/tui/components/AgentPanel.tsx +0 -75
  317. package/src/tui/components/CostOverlay.tsx +0 -118
  318. package/src/tui/components/HelpOverlay.tsx +0 -107
  319. package/src/tui/components/StatusBar.tsx +0 -63
  320. package/src/tui/components/StoriesPanel.tsx +0 -177
  321. package/src/tui/hooks/useKeyboard.ts +0 -142
  322. package/src/tui/hooks/useLayout.ts +0 -137
  323. package/src/tui/hooks/usePipelineEvents.ts +0 -183
  324. package/src/tui/hooks/usePty.ts +0 -189
  325. package/src/tui/index.tsx +0 -38
  326. package/src/tui/types.ts +0 -76
  327. package/src/utils/errors.ts +0 -12
  328. package/src/utils/git.ts +0 -245
  329. package/src/utils/json-file.ts +0 -72
  330. package/src/utils/log-test-output.ts +0 -25
  331. package/src/utils/path-security.ts +0 -73
  332. package/src/utils/queue-writer.ts +0 -54
  333. package/src/verification/crash-detector.ts +0 -34
  334. package/src/verification/executor.ts +0 -250
  335. package/src/verification/index.ts +0 -12
  336. package/src/verification/orchestrator-types.ts +0 -154
  337. package/src/verification/orchestrator.ts +0 -76
  338. package/src/verification/parser.ts +0 -220
  339. package/src/verification/rectification-loop.ts +0 -172
  340. package/src/verification/rectification.ts +0 -108
  341. package/src/verification/runners.ts +0 -129
  342. package/src/verification/smart-runner.ts +0 -307
  343. package/src/verification/strategies/acceptance.ts +0 -136
  344. package/src/verification/strategies/regression.ts +0 -90
  345. package/src/verification/strategies/scoped.ts +0 -154
  346. package/src/verification/types.ts +0 -117
  347. package/src/version.ts +0 -40
  348. package/src/worktree/dispatcher.ts +0 -6
  349. package/src/worktree/index.ts +0 -2
  350. package/src/worktree/manager.ts +0 -193
  351. package/src/worktree/merge.ts +0 -302
  352. package/src/worktree/types.ts +0 -4
@@ -1,423 +0,0 @@
1
- /**
2
- * Acceptance Test Generator
3
- *
4
- * Parses spec.md acceptance criteria (AC-N lines) and generates acceptance.test.ts
5
- * via LLM call to the agent adapter.
6
- */
7
-
8
- import { join } from "node:path";
9
- import { ClaudeCodeAdapter } from "../agents/claude";
10
- import type { AgentAdapter } from "../agents/types";
11
- import { getLogger } from "../logger";
12
- import type { UserStory } from "../prd/types";
13
- import type {
14
- AcceptanceCriterion,
15
- AcceptanceTestResult,
16
- GenerateAcceptanceTestsOptions,
17
- GenerateFromPRDOptions,
18
- RefinedCriterion,
19
- } from "./types";
20
-
21
- /**
22
- * Parse acceptance criteria from spec.md content.
23
- *
24
- * Extracts lines matching "AC-N: description" or "- AC-N: description" patterns.
25
- *
26
- * @param specContent - Full spec.md markdown content
27
- * @returns Array of extracted acceptance criteria
28
- *
29
- * @example
30
- * ```ts
31
- * const spec = `
32
- * ## Acceptance Criteria
33
- * - AC-1: System should handle empty input
34
- * - AC-2: set(key, value, ttl) expires after ttl milliseconds
35
- * `;
36
- * const criteria = parseAcceptanceCriteria(spec);
37
- * // Returns: [
38
- * // { id: "AC-1", text: "System should handle empty input", lineNumber: 3 },
39
- * // { id: "AC-2", text: "set(key, value, ttl) expires after ttl", lineNumber: 4 },
40
- * // ]
41
- * ```
42
- */
43
- /**
44
- * Injectable dependencies for generateFromPRD — allows tests to mock
45
- * adapter.complete() and file writes without real binaries or disk I/O.
46
- *
47
- * @internal
48
- */
49
- export const _generatorPRDDeps = {
50
- adapter: new ClaudeCodeAdapter() as AgentAdapter,
51
- writeFile: async (path: string, content: string): Promise<void> => {
52
- await Bun.write(path, content);
53
- },
54
- };
55
-
56
- /**
57
- * Generate acceptance tests from PRD UserStory[] and RefinedCriterion[].
58
- *
59
- * This is a stub — implementation is provided by the implementer session.
60
- *
61
- * @param stories - User stories from the PRD
62
- * @param refinedCriteria - Refined criteria produced by the refinement module
63
- * @param options - Generation options
64
- * @returns Generated test code and processed criteria
65
- */
66
- export async function generateFromPRD(
67
- _stories: UserStory[],
68
- refinedCriteria: RefinedCriterion[],
69
- options: GenerateFromPRDOptions,
70
- ): Promise<AcceptanceTestResult> {
71
- const logger = getLogger();
72
-
73
- const criteria: AcceptanceCriterion[] = refinedCriteria.map((c, i) => ({
74
- id: `AC-${i + 1}`,
75
- text: c.refined,
76
- lineNumber: i + 1,
77
- }));
78
-
79
- if (refinedCriteria.length === 0) {
80
- return { testCode: "", criteria: [] };
81
- }
82
-
83
- const criteriaList = refinedCriteria.map((c, i) => `AC-${i + 1}: ${c.refined}`).join("\n");
84
-
85
- const strategyInstructions = buildStrategyInstructions(options.testStrategy, options.testFramework);
86
-
87
- const prompt = `You are a test engineer. Generate acceptance tests for the "${options.featureName}" feature based on the refined acceptance criteria below.
88
-
89
- CODEBASE CONTEXT:
90
- ${options.codebaseContext}
91
-
92
- ACCEPTANCE CRITERIA (refined):
93
- ${criteriaList}
94
-
95
- ${strategyInstructions}Generate a complete acceptance.test.ts file using bun:test framework. Each AC maps to exactly one test named "AC-N: <description>".
96
-
97
- Structure example (do NOT wrap in markdown fences — output raw TypeScript only):
98
-
99
- import { describe, test, expect } from "bun:test";
100
-
101
- describe("${options.featureName} - Acceptance Tests", () => {
102
- test("AC-1: <description>", async () => {
103
- // Test implementation
104
- });
105
- });
106
-
107
- IMPORTANT: Output raw TypeScript code only. Do NOT use markdown code fences (\`\`\`typescript or \`\`\`). Start directly with the import statement.`;
108
-
109
- logger.info("acceptance", "Generating tests from PRD refined criteria", { count: refinedCriteria.length });
110
-
111
- const rawOutput = await _generatorPRDDeps.adapter.complete(prompt, {
112
- model: options.modelDef.model,
113
- config: options.config,
114
- });
115
- const testCode = extractTestCode(rawOutput);
116
-
117
- if (!testCode) {
118
- logger.warn("acceptance", "LLM returned non-code output for acceptance tests — falling back to skeleton", {
119
- outputPreview: rawOutput.slice(0, 200),
120
- });
121
- const skeletonCriteria: AcceptanceCriterion[] = refinedCriteria.map((c, i) => ({
122
- id: `AC-${i + 1}`,
123
- text: c.refined,
124
- lineNumber: i + 1,
125
- }));
126
- return { testCode: generateSkeletonTests(options.featureName, skeletonCriteria), criteria: skeletonCriteria };
127
- }
128
-
129
- const refinedJsonContent = JSON.stringify(
130
- refinedCriteria.map((c, i) => ({
131
- acId: `AC-${i + 1}`,
132
- original: c.original,
133
- refined: c.refined,
134
- testable: c.testable,
135
- storyId: c.storyId,
136
- })),
137
- null,
138
- 2,
139
- );
140
-
141
- await _generatorPRDDeps.writeFile(join(options.featureDir, "acceptance-refined.json"), refinedJsonContent);
142
-
143
- return { testCode, criteria };
144
- }
145
-
146
- function buildStrategyInstructions(strategy?: string, framework?: string): string {
147
- switch (strategy) {
148
- case "component": {
149
- const fw = framework ?? "ink-testing-library";
150
- if (fw === "react") {
151
- return "TEST STRATEGY: component (react)\nImport render and screen from @testing-library/react. Render the component and use screen.getByText to assert on output.\n\n";
152
- }
153
- return "TEST STRATEGY: component (ink-testing-library)\nImport render from ink-testing-library. Render the component and use lastFrame() to assert on output.\n\n";
154
- }
155
- case "cli":
156
- return "TEST STRATEGY: cli\nUse Bun.spawn to run the binary. Read stdout and assert on the text output.\n\n";
157
- case "e2e":
158
- return "TEST STRATEGY: e2e\nUse fetch() against http://localhost to call the running service. Assert on response body using response.text() or response.json().\n\n";
159
- case "snapshot":
160
- return "TEST STRATEGY: snapshot\nRender the component and use toMatchSnapshot() to capture and compare snapshots.\n\n";
161
- default:
162
- return "";
163
- }
164
- }
165
-
166
- export function parseAcceptanceCriteria(specContent: string): AcceptanceCriterion[] {
167
- const criteria: AcceptanceCriterion[] = [];
168
- const lines = specContent.split("\n");
169
-
170
- for (let i = 0; i < lines.length; i++) {
171
- const line = lines[i];
172
- const lineNumber = i + 1;
173
-
174
- // Match patterns:
175
- // - AC-1: description
176
- // - [ ] AC-1: description
177
- // AC-1: description
178
- const acMatch = line.match(/^\s*-?\s*(?:\[.\])?\s*(AC-\d+):\s*(.+)$/i);
179
-
180
- if (acMatch) {
181
- const id = acMatch[1].toUpperCase(); // Normalize to uppercase
182
- const text = acMatch[2].trim();
183
-
184
- criteria.push({
185
- id,
186
- text,
187
- lineNumber,
188
- });
189
- }
190
- }
191
-
192
- return criteria;
193
- }
194
-
195
- /**
196
- * Build LLM prompt for generating acceptance tests.
197
- *
198
- * Combines acceptance criteria, codebase context, and test generation instructions.
199
- *
200
- * @param criteria - Extracted acceptance criteria
201
- * @param featureName - Feature name for context
202
- * @param codebaseContext - File tree, dependencies, test patterns
203
- * @returns Formatted prompt string
204
- *
205
- * @example
206
- * ```ts
207
- * const prompt = buildAcceptanceTestPrompt(
208
- * [{ id: "AC-1", text: "handles empty input", lineNumber: 5 }],
209
- * "url-shortener",
210
- * "File tree:\nsrc/\n index.ts\n"
211
- * );
212
- * ```
213
- */
214
- export function buildAcceptanceTestPrompt(
215
- criteria: AcceptanceCriterion[],
216
- featureName: string,
217
- codebaseContext: string,
218
- ): string {
219
- const criteriaList = criteria.map((ac) => `${ac.id}: ${ac.text}`).join("\n");
220
-
221
- return `You are a test engineer. Generate acceptance tests for the "${featureName}" feature based on the acceptance criteria below.
222
-
223
- CODEBASE CONTEXT:
224
- ${codebaseContext}
225
-
226
- ACCEPTANCE CRITERIA:
227
- ${criteriaList}
228
-
229
- Generate a complete acceptance.test.ts file using bun:test framework. Follow these rules:
230
-
231
- 1. **One test per AC**: Each acceptance criterion maps to exactly one test
232
- 2. **Test observable behavior only**: No implementation details, only user-facing behavior
233
- 3. **Independent tests**: No shared state between tests
234
- 4. **Real-implementation**: Tests should use real implementations without mocking (test observable behavior, not internal units)
235
- 5. **Clear test names**: Use format "AC-N: <description>" for test names
236
- 6. **Async where needed**: Use async/await for operations that may be asynchronous
237
-
238
- Use this structure:
239
-
240
- \`\`\`typescript
241
- import { describe, test, expect } from "bun:test";
242
-
243
- describe("${featureName} - Acceptance Tests", () => {
244
- test("AC-1: <description>", async () => {
245
- // Test implementation
246
- });
247
-
248
- test("AC-2: <description>", async () => {
249
- // Test implementation
250
- });
251
- });
252
- \`\`\`
253
-
254
- **Important**:
255
- - Import the feature code being tested
256
- - Set up any necessary test fixtures
257
- - Use expect() assertions to verify behavior
258
- - Clean up resources if needed (close connections, delete temp files)
259
-
260
- Respond with ONLY the TypeScript test code (no markdown code fences, no explanation).`;
261
- }
262
-
263
- /**
264
- * Generate acceptance tests from spec.md acceptance criteria.
265
- *
266
- * Parses AC lines from spec, builds LLM prompt, calls agent adapter,
267
- * and returns generated test code. Falls back to skeleton tests if LLM fails.
268
- *
269
- * @param adapter - Agent adapter to use for test generation
270
- * @param options - Generation options with spec content, context, and model
271
- * @returns Generated test code and processed criteria
272
- * @throws Error if AC parsing fails or agent call fails critically
273
- *
274
- * @example
275
- * ```ts
276
- * const adapter = new ClaudeCodeAdapter();
277
- * const result = await generateAcceptanceTests(adapter, {
278
- * specContent: await Bun.file("spec.md").text(),
279
- * featureName: "url-shortener",
280
- * workdir: "/project",
281
- * codebaseContext: "File tree:\nsrc/\n",
282
- * modelTier: "balanced",
283
- * modelDef: { provider: "anthropic", model: "claude-sonnet-4-5" },
284
- * });
285
- *
286
- * await Bun.write("acceptance.test.ts", result.testCode);
287
- * ```
288
- */
289
- export async function generateAcceptanceTests(
290
- adapter: AgentAdapter,
291
- options: GenerateAcceptanceTestsOptions,
292
- ): Promise<AcceptanceTestResult> {
293
- // Parse acceptance criteria from spec
294
- const logger = getLogger();
295
- const criteria = parseAcceptanceCriteria(options.specContent);
296
-
297
- if (criteria.length === 0) {
298
- // No AC found — generate empty skeleton
299
- logger.warn("acceptance", "⚠ No acceptance criteria found in spec.md");
300
- return {
301
- testCode: generateSkeletonTests(options.featureName, []),
302
- criteria: [],
303
- };
304
- }
305
-
306
- logger.info("acceptance", "Found acceptance criteria", { count: criteria.length });
307
-
308
- // Build prompt
309
- const prompt = buildAcceptanceTestPrompt(criteria, options.featureName, options.codebaseContext);
310
-
311
- try {
312
- // Call adapter to generate tests
313
- const output = await adapter.complete(prompt, {
314
- model: options.modelDef.model,
315
- config: options.config,
316
- });
317
-
318
- // Extract test code from output
319
- const testCode = extractTestCode(output);
320
-
321
- if (!testCode) {
322
- logger.warn("acceptance", "LLM returned non-code output for acceptance tests — falling back to skeleton", {
323
- outputPreview: output.slice(0, 200),
324
- });
325
- return {
326
- testCode: generateSkeletonTests(options.featureName, criteria),
327
- criteria,
328
- };
329
- }
330
-
331
- return {
332
- testCode,
333
- criteria,
334
- };
335
- } catch (error) {
336
- logger.warn("acceptance", "⚠ Agent test generation error", { error: (error as Error).message });
337
- // Fall back to skeleton
338
- return {
339
- testCode: generateSkeletonTests(options.featureName, criteria),
340
- criteria,
341
- };
342
- }
343
- }
344
-
345
- /**
346
- * Extract TypeScript test code from agent output.
347
- *
348
- * Handles markdown code fences and extracts clean test code.
349
- *
350
- * @param output - Agent stdout
351
- * @returns Extracted test code
352
- */
353
- function extractTestCode(output: string): string | null {
354
- let code: string | undefined;
355
-
356
- // Try to extract from markdown code fence
357
- const fenceMatch = output.match(/```(?:typescript|ts)?\s*([\s\S]*?)\s*```/);
358
- if (fenceMatch) {
359
- code = fenceMatch[1].trim();
360
- }
361
-
362
- // If no fence, try to find import statement and take everything from there
363
- if (!code) {
364
- const importMatch = output.match(/import\s+{[\s\S]+/);
365
- if (importMatch) {
366
- code = importMatch[0].trim();
367
- }
368
- }
369
-
370
- // If no fence and no import, try to find describe() block
371
- if (!code) {
372
- const describeMatch = output.match(/describe\s*\([\s\S]+/);
373
- if (describeMatch) {
374
- code = describeMatch[0].trim();
375
- }
376
- }
377
-
378
- if (!code) return null;
379
-
380
- // Validate: extracted code must contain at least one test-like keyword
381
- const hasTestKeyword = /\b(?:describe|test|it|expect)\s*\(/.test(code);
382
- if (!hasTestKeyword) {
383
- return null;
384
- }
385
-
386
- return code;
387
- }
388
-
389
- /**
390
- * Generate skeleton acceptance tests with TODO placeholders.
391
- *
392
- * Used as fallback when LLM test generation fails.
393
- *
394
- * @param featureName - Feature name
395
- * @param criteria - Acceptance criteria to generate skeletons for
396
- * @returns TypeScript test code with TODO placeholders
397
- *
398
- * @example
399
- * ```ts
400
- * const skeleton = generateSkeletonTests("auth", [
401
- * { id: "AC-1", text: "login succeeds", lineNumber: 5 },
402
- * ]);
403
- * // Generates test with TODO comment
404
- * ```
405
- */
406
- export function generateSkeletonTests(featureName: string, criteria: AcceptanceCriterion[]): string {
407
- const tests = criteria
408
- .map((ac) => {
409
- return ` test("${ac.id}: ${ac.text}", async () => {
410
- // TODO: Implement acceptance test for ${ac.id}
411
- // ${ac.text}
412
- expect(true).toBe(false); // Replace with actual test
413
- });`;
414
- })
415
- .join("\n\n");
416
-
417
- return `import { describe, test, expect } from "bun:test";
418
-
419
- describe("${featureName} - Acceptance Tests", () => {
420
- ${tests || " // No acceptance criteria found"}
421
- });
422
- `;
423
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Acceptance Test Generation Module
3
- *
4
- * Barrel exports for acceptance test generation functionality.
5
- */
6
-
7
- export type {
8
- AcceptanceCriterion,
9
- GenerateAcceptanceTestsOptions,
10
- GenerateFromPRDOptions,
11
- AcceptanceTestResult,
12
- RefinedCriterion,
13
- RefinementContext,
14
- } from "./types";
15
-
16
- export {
17
- buildRefinementPrompt,
18
- parseRefinementResponse,
19
- refineAcceptanceCriteria,
20
- _refineDeps,
21
- } from "./refinement";
22
-
23
- export {
24
- parseAcceptanceCriteria,
25
- buildAcceptanceTestPrompt,
26
- generateAcceptanceTests,
27
- generateFromPRD,
28
- generateSkeletonTests,
29
- _generatorPRDDeps,
30
- } from "./generator";
31
-
32
- export type {
33
- FixStory,
34
- GenerateFixStoriesOptions,
35
- } from "./fix-generator";
36
-
37
- export {
38
- generateFixStories,
39
- findRelatedStories,
40
- parseACTextFromSpec,
41
- convertFixStoryToUserStory,
42
- } from "./fix-generator";
@@ -1,224 +0,0 @@
1
- /**
2
- * AC Refinement Module
3
- *
4
- * Takes raw PRD acceptanceCriteria strings and refines them into concrete,
5
- * testable assertions using an LLM call via adapter.complete().
6
- */
7
-
8
- import type { AgentAdapter } from "../agents";
9
- import { ClaudeCodeAdapter } from "../agents/claude";
10
- import { resolveModel } from "../config/schema";
11
- import { getLogger } from "../logger";
12
- import { errorMessage } from "../utils/errors";
13
- import type { RefinedCriterion, RefinementContext } from "./types";
14
-
15
- /**
16
- * Injectable dependencies — allows tests to mock adapter.complete()
17
- * without needing the claude binary.
18
- *
19
- * @internal
20
- */
21
- export const _refineDeps = {
22
- adapter: new ClaudeCodeAdapter() as AgentAdapter,
23
- };
24
-
25
- /**
26
- * Strategy-specific context for the refinement prompt.
27
- */
28
- export interface RefinementPromptOptions {
29
- /** Test strategy — controls strategy-specific prompt instructions */
30
- testStrategy?: "unit" | "component" | "cli" | "e2e" | "snapshot";
31
- /** Test framework — informs LLM which testing library syntax to use */
32
- testFramework?: string;
33
- }
34
-
35
- /**
36
- * Build the LLM prompt for refining acceptance criteria.
37
- *
38
- * @param criteria - Raw AC strings from PRD
39
- * @param codebaseContext - File tree / dependency context
40
- * @param options - Optional strategy/framework context
41
- * @returns Formatted prompt string
42
- */
43
- export function buildRefinementPrompt(
44
- criteria: string[],
45
- codebaseContext: string,
46
- options?: RefinementPromptOptions,
47
- ): string {
48
- const criteriaList = criteria.map((c, i) => `${i + 1}. ${c}`).join("\n");
49
- const strategySection = buildStrategySection(options);
50
- const refinedExample = buildRefinedExample(options?.testStrategy);
51
-
52
- return `You are an acceptance criteria refinement assistant. Your task is to convert raw acceptance criteria into concrete, machine-verifiable assertions.
53
-
54
- CODEBASE CONTEXT:
55
- ${codebaseContext}
56
- ${strategySection}
57
- ACCEPTANCE CRITERIA TO REFINE:
58
- ${criteriaList}
59
-
60
- For each criterion, produce a refined version that is concrete and automatically testable where possible.
61
- Respond with ONLY a JSON array (no markdown code fences):
62
- [{
63
- "original": "<exact original criterion text>",
64
- "refined": "<concrete, machine-verifiable description>",
65
- "testable": true,
66
- "storyId": ""
67
- }]
68
-
69
- Rules:
70
- - "original" must match the input criterion text exactly
71
- - "refined" must be a concrete assertion (e.g., ${refinedExample})
72
- - "testable" is false only if the criterion cannot be automatically verified (e.g., "UX feels responsive", "design looks good")
73
- - "storyId" leave as empty string — it will be assigned by the caller
74
- - Respond with ONLY the JSON array`;
75
- }
76
-
77
- /**
78
- * Build strategy-specific instructions section for the prompt.
79
- */
80
- function buildStrategySection(options?: RefinementPromptOptions): string {
81
- if (!options?.testStrategy) {
82
- return "";
83
- }
84
-
85
- const framework = options.testFramework ? ` Use ${options.testFramework} testing library syntax.` : "";
86
-
87
- switch (options.testStrategy) {
88
- case "component":
89
- return `
90
- TEST STRATEGY: component
91
- Focus assertions on rendered output visible on screen — text content, visible elements, and screen state.
92
- Assert what the user sees rendered in the component, not what internal functions produce.${framework}
93
- `;
94
- case "cli":
95
- return `
96
- TEST STRATEGY: cli
97
- Focus assertions on stdout and stderr text output from the CLI command.
98
- Assert about terminal output content, exit codes, and standard output/standard error streams.${framework}
99
- `;
100
- case "e2e":
101
- return `
102
- TEST STRATEGY: e2e
103
- Focus assertions on HTTP response content — status codes, response bodies, and endpoint behavior.
104
- Assert about HTTP responses, status codes, and API endpoint output.${framework}
105
- `;
106
- default:
107
- return framework ? `\nTEST FRAMEWORK: ${options.testFramework}\n` : "";
108
- }
109
- }
110
-
111
- /**
112
- * Build the "refined" example string based on the test strategy.
113
- */
114
- function buildRefinedExample(testStrategy?: RefinementPromptOptions["testStrategy"]): string {
115
- switch (testStrategy) {
116
- case "component":
117
- return '"Text content visible on screen matches expected", "Rendered output contains expected element"';
118
- case "cli":
119
- return '"stdout contains expected text", "stderr is empty on success", "exit code is 0"';
120
- case "e2e":
121
- return '"HTTP status 200 returned", "Response body contains expected field", "Endpoint returns JSON"';
122
- default:
123
- return '"Array of length N returned", "HTTP status 200 returned"';
124
- }
125
- }
126
-
127
- /**
128
- * Parse the LLM JSON response into RefinedCriterion[].
129
- *
130
- * Falls back gracefully: if JSON is malformed or a criterion is missing,
131
- * uses the original text with testable: true.
132
- *
133
- * @param response - Raw LLM response text
134
- * @param criteria - Original criteria strings (used as fallback)
135
- * @returns Array of refined criteria
136
- */
137
- export function parseRefinementResponse(response: string, criteria: string[]): RefinedCriterion[] {
138
- if (!response || !response.trim()) {
139
- return fallbackCriteria(criteria);
140
- }
141
-
142
- try {
143
- const parsed: unknown = JSON.parse(response);
144
-
145
- if (!Array.isArray(parsed)) {
146
- return fallbackCriteria(criteria);
147
- }
148
-
149
- return (parsed as RefinedCriterion[]).map((item, i) => ({
150
- original: typeof item.original === "string" && item.original.length > 0 ? item.original : (criteria[i] ?? ""),
151
- refined: typeof item.refined === "string" && item.refined.length > 0 ? item.refined : (criteria[i] ?? ""),
152
- testable: typeof item.testable === "boolean" ? item.testable : true,
153
- storyId: typeof item.storyId === "string" ? item.storyId : "",
154
- }));
155
- } catch {
156
- return fallbackCriteria(criteria);
157
- }
158
- }
159
-
160
- /**
161
- * Refine raw acceptance criteria strings into concrete, testable assertions.
162
- *
163
- * @param criteria - Raw AC strings from PRD
164
- * @param context - Refinement context (storyId, codebase context, config)
165
- * @returns Promise resolving to array of refined criteria
166
- */
167
- export async function refineAcceptanceCriteria(
168
- criteria: string[],
169
- context: RefinementContext,
170
- ): Promise<RefinedCriterion[]> {
171
- if (criteria.length === 0) {
172
- return [];
173
- }
174
-
175
- const { storyId, codebaseContext, config, testStrategy, testFramework } = context;
176
- const logger = getLogger();
177
-
178
- const modelTier = config.acceptance?.model ?? "fast";
179
- const modelEntry = config.models[modelTier] ?? config.models.fast;
180
-
181
- if (!modelEntry) {
182
- throw new Error(`[refinement] config.models.${modelTier} not configured`);
183
- }
184
-
185
- const modelDef = resolveModel(modelEntry);
186
- const prompt = buildRefinementPrompt(criteria, codebaseContext, { testStrategy, testFramework });
187
-
188
- let response: string;
189
-
190
- try {
191
- response = await _refineDeps.adapter.complete(prompt, {
192
- jsonMode: true,
193
- maxTokens: 4096,
194
- model: modelDef.model,
195
- config,
196
- });
197
- } catch (error) {
198
- const reason = errorMessage(error);
199
- logger.warn("refinement", "adapter.complete() failed, falling back to original criteria", {
200
- storyId,
201
- error: reason,
202
- });
203
- return fallbackCriteria(criteria, storyId);
204
- }
205
-
206
- const parsed = parseRefinementResponse(response, criteria);
207
-
208
- return parsed.map((item) => ({
209
- ...item,
210
- storyId: item.storyId || storyId,
211
- }));
212
- }
213
-
214
- /**
215
- * Build fallback RefinedCriterion[] using original criterion text.
216
- */
217
- function fallbackCriteria(criteria: string[], storyId = ""): RefinedCriterion[] {
218
- return criteria.map((c) => ({
219
- original: c,
220
- refined: c,
221
- testable: true,
222
- storyId,
223
- }));
224
- }