@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,170 +0,0 @@
1
- /**
2
- * Interaction System Types (v0.15.0)
3
- *
4
- * Interactive pipeline core for user prompts, decision gates, and pause/resume.
5
- */
6
-
7
- /** Interaction request types */
8
- export type InteractionType = "confirm" | "choose" | "input" | "review" | "notify" | "webhook";
9
-
10
- /** Pipeline stage where interaction occurs */
11
- export type InteractionStage = "pre-flight" | "execution" | "review" | "merge" | "cost" | "custom";
12
-
13
- /** Fallback behavior when interaction times out */
14
- export type InteractionFallback = "continue" | "skip" | "escalate" | "abort";
15
-
16
- /** Interaction request — sent to plugin */
17
- export interface InteractionRequest {
18
- /** Unique request ID (e.g., 'ix-US003-review-1') */
19
- id: string;
20
- /** Type of interaction */
21
- type: InteractionType;
22
- /** Feature name */
23
- featureName: string;
24
- /** Story ID (optional, for story-level interactions) */
25
- storyId?: string;
26
- /** Pipeline stage */
27
- stage: InteractionStage;
28
- /** Human-readable question/summary */
29
- summary: string;
30
- /** Longer context/details (optional) */
31
- detail?: string;
32
- /** Options for choose type */
33
- options?: Array<{ key: string; label: string; description?: string }>;
34
- /** Timeout in milliseconds (optional) */
35
- timeout?: number;
36
- /** Fallback behavior on timeout */
37
- fallback: InteractionFallback;
38
- /** Arbitrary metadata */
39
- metadata?: Record<string, unknown>;
40
- /** Creation timestamp */
41
- createdAt: number;
42
- }
43
-
44
- /** Interaction response action */
45
- export type InteractionAction = "approve" | "reject" | "choose" | "input" | "skip" | "abort";
46
-
47
- /** Interaction response — returned from plugin */
48
- export interface InteractionResponse {
49
- /** Request ID this response is for */
50
- requestId: string;
51
- /** Action taken */
52
- action: InteractionAction;
53
- /** Value (for choose/input types) */
54
- value?: string;
55
- /** Who responded (user, system, timeout, etc.) */
56
- respondedBy?: string;
57
- /** Response timestamp */
58
- respondedAt: number;
59
- }
60
-
61
- /** Interaction plugin interface */
62
- export interface InteractionPlugin {
63
- /** Plugin name */
64
- name: string;
65
- /** Send interaction request to user */
66
- send(request: InteractionRequest): Promise<void>;
67
- /** Receive interaction response from user (blocking) */
68
- receive(requestId: string, timeout?: number): Promise<InteractionResponse>;
69
- /** Cancel a pending interaction (optional) */
70
- cancel?(requestId: string): Promise<void>;
71
- /** Initialize plugin with config (optional) */
72
- init?(config: Record<string, unknown>): Promise<void>;
73
- /** Teardown plugin (optional) */
74
- destroy?(): Promise<void>;
75
- }
76
-
77
- /** Built-in trigger names */
78
- export type TriggerName =
79
- | "security-review" // abort (red) — critical security issues found
80
- | "cost-exceeded" // abort (red) — cost limit exceeded
81
- | "merge-conflict" // abort (red) — merge conflict detected
82
- | "cost-warning" // escalate (yellow) — approaching cost limit
83
- | "max-retries" // skip (yellow) — max retries reached
84
- | "pre-merge" // escalate (yellow) — before merging to main
85
- | "human-review" // skip (yellow) — human review required on max retries / critical failure
86
- | "story-oversized" // continue (yellow) — story has too many acceptance criteria
87
- | "story-ambiguity" // continue (green) — story requirements unclear
88
- | "review-gate"; // continue (green) — code review checkpoint
89
-
90
- /** Trigger configuration */
91
- export interface TriggerConfig {
92
- /** Whether trigger is enabled */
93
- enabled: boolean;
94
- /** Override default fallback behavior */
95
- fallback?: InteractionFallback;
96
- /** Override default timeout (ms) */
97
- timeout?: number;
98
- /** Custom summary template (supports {{variable}} syntax) */
99
- summary?: string;
100
- /** Custom detail template */
101
- detail?: string;
102
- }
103
-
104
- /** Safety tier for triggers */
105
- export type TriggerSafety = "red" | "yellow" | "green";
106
-
107
- /** Built-in trigger metadata */
108
- export interface TriggerMetadata {
109
- /** Default fallback behavior */
110
- defaultFallback: InteractionFallback;
111
- /** Safety tier */
112
- safety: TriggerSafety;
113
- /** Default summary */
114
- defaultSummary: string;
115
- }
116
-
117
- /** Map of built-in triggers to their metadata */
118
- export const TRIGGER_METADATA: Record<TriggerName, TriggerMetadata> = {
119
- "security-review": {
120
- defaultFallback: "abort",
121
- safety: "red",
122
- defaultSummary: "Security review failed — abort execution?",
123
- },
124
- "cost-exceeded": {
125
- defaultFallback: "abort",
126
- safety: "red",
127
- defaultSummary: "Cost limit exceeded ({{cost}} USD) — abort execution?",
128
- },
129
- "merge-conflict": {
130
- defaultFallback: "abort",
131
- safety: "red",
132
- defaultSummary: "Merge conflict detected in {{storyId}} — abort execution?",
133
- },
134
- "cost-warning": {
135
- defaultFallback: "escalate",
136
- safety: "yellow",
137
- defaultSummary: "Cost warning: {{cost}} USD / {{limit}} USD — escalate to higher tier?",
138
- },
139
- "max-retries": {
140
- defaultFallback: "skip",
141
- safety: "yellow",
142
- defaultSummary: "Max retries reached for {{storyId}} — skip story?",
143
- },
144
- "pre-merge": {
145
- defaultFallback: "escalate",
146
- safety: "yellow",
147
- defaultSummary: "Pre-merge checkpoint for {{storyId}} — proceed with merge?",
148
- },
149
- "human-review": {
150
- defaultFallback: "skip",
151
- safety: "yellow",
152
- defaultSummary: "Human review required for story {{storyId}} — skip and continue?",
153
- },
154
- "story-oversized": {
155
- defaultFallback: "continue",
156
- safety: "yellow",
157
- defaultSummary:
158
- "Story {{storyId}} is oversized ({{criteriaCount}} acceptance criteria) — decompose into smaller stories?",
159
- },
160
- "story-ambiguity": {
161
- defaultFallback: "continue",
162
- safety: "green",
163
- defaultSummary: "Story {{storyId}} requirements unclear — continue with best effort?",
164
- },
165
- "review-gate": {
166
- defaultFallback: "continue",
167
- safety: "green",
168
- defaultSummary: "Code review checkpoint for {{storyId}} — proceed?",
169
- },
170
- };
@@ -1,84 +0,0 @@
1
- import chalk from "chalk";
2
- import type { LogEntry } from "./types.js";
3
-
4
- /**
5
- * Format log entry for human-readable console output with chalk colors
6
- *
7
- * @param entry - The log entry to format
8
- * @returns Chalk-formatted console string
9
- *
10
- * @example
11
- * ```typescript
12
- * const entry: LogEntry = {
13
- * timestamp: "2026-02-20T10:30:00.123Z",
14
- * level: "info",
15
- * stage: "routing",
16
- * storyId: "user-auth-001",
17
- * message: "Classified as simple task",
18
- * data: { complexity: "simple", model: "claude-sonnet-4-5" }
19
- * };
20
- * console.log(formatConsole(entry));
21
- * // [10:30:00] [routing] [user-auth-001] Classified as simple task
22
- * ```
23
- */
24
- export function formatConsole(entry: LogEntry): string {
25
- const timestamp = new Date(entry.timestamp).toLocaleTimeString("en-US", {
26
- hour12: false,
27
- });
28
-
29
- // Level-specific color coding
30
- let levelColor: (text: string) => string;
31
- switch (entry.level) {
32
- case "error":
33
- levelColor = chalk.red;
34
- break;
35
- case "warn":
36
- levelColor = chalk.yellow;
37
- break;
38
- case "info":
39
- levelColor = chalk.blue;
40
- break;
41
- case "debug":
42
- levelColor = chalk.gray;
43
- break;
44
- }
45
-
46
- // Build base message with timestamp, stage, and optional storyId
47
- const parts = [chalk.gray(`[${timestamp}]`), levelColor(`[${entry.stage}]`)];
48
-
49
- if (entry.storyId) {
50
- parts.push(chalk.cyan(`[${entry.storyId}]`));
51
- }
52
-
53
- parts.push(entry.message);
54
-
55
- // Append data if present (pretty-printed on next line)
56
- let output = parts.join(" ");
57
- if (entry.data && Object.keys(entry.data).length > 0) {
58
- output += `\n${chalk.gray(JSON.stringify(entry.data, null, 2))}`;
59
- }
60
-
61
- return output;
62
- }
63
-
64
- /**
65
- * Format log entry as JSON Lines (JSONL) for machine-readable file output
66
- *
67
- * @param entry - The log entry to format
68
- * @returns Single-line JSON string
69
- *
70
- * @example
71
- * ```typescript
72
- * const entry: LogEntry = {
73
- * timestamp: "2026-02-20T10:30:00.123Z",
74
- * level: "info",
75
- * stage: "routing",
76
- * message: "Task classified"
77
- * };
78
- * console.log(formatJsonl(entry));
79
- * // {"timestamp":"2026-02-20T10:30:00.123Z","level":"info","stage":"routing","message":"Task classified"}
80
- * ```
81
- */
82
- export function formatJsonl(entry: LogEntry): string {
83
- return JSON.stringify(entry);
84
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Structured logging module for nax
3
- *
4
- * Provides level-gated console output and JSONL file logging for all stages.
5
- *
6
- * @module logger
7
- */
8
-
9
- export { Logger, initLogger, getLogger, getSafeLogger, resetLogger } from "./logger.js";
10
- export { formatConsole, formatJsonl } from "./formatters.js";
11
- export type {
12
- LogLevel,
13
- LogEntry,
14
- LoggerOptions,
15
- StoryLogger,
16
- } from "./types.js";
@@ -1,296 +0,0 @@
1
- import { appendFileSync, mkdirSync } from "node:fs";
2
- import { type FormatterOptions, type VerbosityMode, formatLogEntry } from "../logging/index.js";
3
- import { formatConsole, formatJsonl } from "./formatters.js";
4
- import type { LogEntry, LogLevel, LoggerOptions, StoryLogger } from "./types.js";
5
-
6
- /**
7
- * Severity ordering for log levels (lower number = more severe)
8
- */
9
- const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {
10
- error: 0,
11
- warn: 1,
12
- info: 2,
13
- debug: 3,
14
- };
15
-
16
- /**
17
- * Singleton logger instance
18
- */
19
- let instance: Logger | null = null;
20
-
21
- /**
22
- * Structured logger with level gating and dual output (console + JSONL file)
23
- *
24
- * @example
25
- * ```typescript
26
- * // Initialize logger (usually in CLI entry point)
27
- * initLogger({ level: "info", filePath: "nax/features/auth/runs/run-123.jsonl" });
28
- *
29
- * // Use logger throughout application
30
- * const logger = getLogger();
31
- * logger.info("routing", "Task classified", { complexity: "simple" });
32
- *
33
- * // Story-scoped logger
34
- * const storyLogger = logger.withStory("user-auth-001");
35
- * storyLogger.info("agent.start", "Starting agent session");
36
- * ```
37
- */
38
- export class Logger {
39
- private readonly level: LogLevel;
40
- private readonly filePath?: string;
41
- private readonly useChalk: boolean;
42
- private readonly formatterMode?: VerbosityMode;
43
- private readonly headless: boolean;
44
-
45
- constructor(options: LoggerOptions) {
46
- this.level = options.level;
47
- this.filePath = options.filePath;
48
- this.useChalk = options.useChalk ?? true;
49
- this.formatterMode = options.formatterMode;
50
- this.headless = options.headless ?? false;
51
-
52
- // Ensure parent directory exists if file path provided
53
- if (this.filePath) {
54
- this.initFileDirectory();
55
- }
56
- }
57
-
58
- /**
59
- * Create parent directory for log file if it doesn't exist
60
- */
61
- private initFileDirectory(): void {
62
- if (!this.filePath) return;
63
-
64
- try {
65
- const dir = this.filePath.substring(0, this.filePath.lastIndexOf("/"));
66
- if (dir) {
67
- mkdirSync(dir, { recursive: true });
68
- }
69
- } catch (error) {
70
- console.error(`[logger] Failed to create log directory: ${error}`);
71
- }
72
- }
73
-
74
- /**
75
- * Check if a log level should be displayed on console
76
- */
77
- private shouldLog(level: LogLevel): boolean {
78
- return LOG_LEVEL_PRIORITY[level] <= LOG_LEVEL_PRIORITY[this.level];
79
- }
80
-
81
- /**
82
- * Internal log method — writes to console (if level permits) and file (always)
83
- */
84
- private log(level: LogLevel, stage: string, message: string, data?: Record<string, unknown>, storyId?: string): void {
85
- const entry: LogEntry = {
86
- timestamp: new Date().toISOString(),
87
- level,
88
- stage,
89
- message,
90
- ...(storyId && { storyId }),
91
- ...(data && { data }),
92
- };
93
-
94
- // Console output (level-gated)
95
- if (this.shouldLog(level)) {
96
- let consoleOutput: string | null = null;
97
-
98
- // Use formatter in headless mode if mode is specified
99
- if (this.headless && this.formatterMode) {
100
- const formatterOptions: FormatterOptions = {
101
- mode: this.formatterMode,
102
- useColor: this.useChalk,
103
- };
104
- const formatted = formatLogEntry(entry, formatterOptions);
105
- if (formatted.shouldDisplay) {
106
- consoleOutput = formatted.output;
107
- }
108
- // If formatter says not to display, consoleOutput stays null
109
- } else {
110
- // Default console formatting (existing behavior)
111
- consoleOutput = this.useChalk ? formatConsole(entry) : this.formatPlainConsole(entry);
112
- }
113
-
114
- // Only log if we have output to display
115
- if (consoleOutput !== null) {
116
- console.log(consoleOutput);
117
- }
118
- }
119
-
120
- // File output (always write all levels)
121
- if (this.filePath) {
122
- this.writeToFile(entry);
123
- }
124
- }
125
-
126
- /**
127
- * Plain console format (no chalk) — used when useChalk is false
128
- */
129
- private formatPlainConsole(entry: LogEntry): string {
130
- const timestamp = new Date(entry.timestamp).toLocaleTimeString("en-US", {
131
- hour12: false,
132
- });
133
- const parts = [`[${timestamp}]`, `[${entry.stage}]`];
134
- if (entry.storyId) {
135
- parts.push(`[${entry.storyId}]`);
136
- }
137
- parts.push(entry.message);
138
- let output = parts.join(" ");
139
- if (entry.data && Object.keys(entry.data).length > 0) {
140
- output += `\n${JSON.stringify(entry.data, null, 2)}`;
141
- }
142
- return output;
143
- }
144
-
145
- /**
146
- * Write JSONL line to file (synchronous append)
147
- */
148
- private writeToFile(entry: LogEntry): void {
149
- if (!this.filePath) return;
150
-
151
- try {
152
- appendFileSync(this.filePath, `${formatJsonl(entry)}\n`);
153
- } catch (error) {
154
- console.error(`[logger] Failed to write to log file: ${error}`);
155
- }
156
- }
157
-
158
- /**
159
- * Log an error message
160
- */
161
- error(stage: string, message: string, data?: Record<string, unknown>): void {
162
- this.log("error", stage, message, data);
163
- }
164
-
165
- /**
166
- * Log a warning message
167
- */
168
- warn(stage: string, message: string, data?: Record<string, unknown>): void {
169
- this.log("warn", stage, message, data);
170
- }
171
-
172
- /**
173
- * Log an info message
174
- */
175
- info(stage: string, message: string, data?: Record<string, unknown>): void {
176
- this.log("info", stage, message, data);
177
- }
178
-
179
- /**
180
- * Log a debug message
181
- */
182
- debug(stage: string, message: string, data?: Record<string, unknown>): void {
183
- this.log("debug", stage, message, data);
184
- }
185
-
186
- /**
187
- * Create a story-scoped logger that auto-injects storyId
188
- *
189
- * @param storyId - Story identifier to inject into all log calls
190
- * @returns StoryLogger instance
191
- *
192
- * @example
193
- * ```typescript
194
- * const logger = getLogger();
195
- * const storyLogger = logger.withStory("user-auth-001");
196
- * storyLogger.info("agent.start", "Starting agent"); // storyId auto-added
197
- * ```
198
- */
199
- withStory(storyId: string): StoryLogger {
200
- return {
201
- error: (stage: string, message: string, data?: Record<string, unknown>) =>
202
- this.log("error", stage, message, data, storyId),
203
- warn: (stage: string, message: string, data?: Record<string, unknown>) =>
204
- this.log("warn", stage, message, data, storyId),
205
- info: (stage: string, message: string, data?: Record<string, unknown>) =>
206
- this.log("info", stage, message, data, storyId),
207
- debug: (stage: string, message: string, data?: Record<string, unknown>) =>
208
- this.log("debug", stage, message, data, storyId),
209
- };
210
- }
211
-
212
- /**
213
- * Close logger (cleanup method for shutdown)
214
- * Note: Bun.write handles file operations automatically, no manual cleanup needed
215
- */
216
- close(): void {
217
- // No-op: Bun handles file operations internally
218
- }
219
- }
220
-
221
- /**
222
- * Initialize the singleton logger instance
223
- *
224
- * @param options - Logger configuration options
225
- * @throws Error if logger is already initialized
226
- *
227
- * @example
228
- * ```typescript
229
- * initLogger({
230
- * level: "info",
231
- * filePath: "nax/features/auth/runs/2026-02-20T10-30-00Z.jsonl"
232
- * });
233
- * ```
234
- */
235
- export function initLogger(options: LoggerOptions): Logger {
236
- if (instance) {
237
- throw new Error("Logger already initialized. Call getLogger() to access existing instance.");
238
- }
239
- instance = new Logger(options);
240
- return instance;
241
- }
242
-
243
- /**
244
- * Get the singleton logger instance
245
- *
246
- * @throws Error if logger has not been initialized
247
- * @returns Logger instance
248
- *
249
- * @example
250
- * ```typescript
251
- * const logger = getLogger();
252
- * logger.info("routing", "Task classified");
253
- * ```
254
- */
255
- /**
256
- * No-op logger for tests/environments where logger isn't initialized
257
- */
258
- const noopLogger: Logger = new Logger({ level: "error", useChalk: false, headless: false });
259
-
260
- export function getLogger(): Logger {
261
- if (!instance) {
262
- return noopLogger;
263
- }
264
- return instance;
265
- }
266
-
267
- /**
268
- * Safely get logger instance, returns null if not initialized
269
- *
270
- * @returns Logger instance or null if not initialized
271
- *
272
- * @example
273
- * ```typescript
274
- * const logger = getSafeLogger();
275
- * logger?.info("routing", "Task classified");
276
- * ```
277
- */
278
- export function getSafeLogger(): Logger | null {
279
- try {
280
- const logger = getLogger();
281
- return logger === noopLogger ? null : logger;
282
- } catch {
283
- return null;
284
- }
285
- }
286
-
287
- /**
288
- * Reset logger singleton (for testing only)
289
- * @internal
290
- */
291
- export function resetLogger(): void {
292
- if (instance) {
293
- instance.close();
294
- }
295
- instance = null;
296
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Log level type — ordered from most to least severe
3
- */
4
- export type LogLevel = "error" | "warn" | "info" | "debug";
5
-
6
- /**
7
- * Structured log entry format
8
- */
9
- export interface LogEntry {
10
- /** ISO timestamp when log was created */
11
- timestamp: string;
12
- /** Severity level */
13
- level: LogLevel;
14
- /** Pipeline stage or module name */
15
- stage: string;
16
- /** Optional story identifier for context */
17
- storyId?: string;
18
- /** Human-readable message */
19
- message: string;
20
- /** Optional structured metadata */
21
- data?: Record<string, unknown>;
22
- }
23
-
24
- /**
25
- * Logger initialization options
26
- */
27
- export interface LoggerOptions {
28
- /** Minimum log level for console output (file gets all levels) */
29
- level: LogLevel;
30
- /** Optional path to JSONL log file */
31
- filePath?: string;
32
- /** Whether to use chalk for console formatting (default: true) */
33
- useChalk?: boolean;
34
- /** Formatter verbosity mode for console output (default: uses formatConsole) */
35
- formatterMode?: "quiet" | "normal" | "verbose" | "json";
36
- /** Whether running in headless mode (enables formatter) */
37
- headless?: boolean;
38
- }
39
-
40
- /**
41
- * Story-scoped logger that auto-injects storyId into all log calls
42
- */
43
- export interface StoryLogger {
44
- error(stage: string, message: string, data?: Record<string, unknown>): void;
45
- warn(stage: string, message: string, data?: Record<string, unknown>): void;
46
- info(stage: string, message: string, data?: Record<string, unknown>): void;
47
- debug(stage: string, message: string, data?: Record<string, unknown>): void;
48
- }