@lumenflow/core 1.0.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 (263) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +119 -0
  3. package/dist/active-wu-detector.d.ts +33 -0
  4. package/dist/active-wu-detector.js +106 -0
  5. package/dist/adapters/filesystem-metrics.adapter.d.ts +108 -0
  6. package/dist/adapters/filesystem-metrics.adapter.js +519 -0
  7. package/dist/adapters/terminal-renderer.adapter.d.ts +106 -0
  8. package/dist/adapters/terminal-renderer.adapter.js +337 -0
  9. package/dist/arg-parser.d.ts +63 -0
  10. package/dist/arg-parser.js +560 -0
  11. package/dist/backlog-editor.d.ts +98 -0
  12. package/dist/backlog-editor.js +179 -0
  13. package/dist/backlog-generator.d.ts +111 -0
  14. package/dist/backlog-generator.js +381 -0
  15. package/dist/backlog-parser.d.ts +45 -0
  16. package/dist/backlog-parser.js +102 -0
  17. package/dist/backlog-sync-validator.d.ts +78 -0
  18. package/dist/backlog-sync-validator.js +294 -0
  19. package/dist/branch-drift.d.ts +34 -0
  20. package/dist/branch-drift.js +51 -0
  21. package/dist/cleanup-install-config.d.ts +33 -0
  22. package/dist/cleanup-install-config.js +37 -0
  23. package/dist/cleanup-lock.d.ts +139 -0
  24. package/dist/cleanup-lock.js +313 -0
  25. package/dist/code-path-validator.d.ts +146 -0
  26. package/dist/code-path-validator.js +537 -0
  27. package/dist/code-paths-overlap.d.ts +55 -0
  28. package/dist/code-paths-overlap.js +245 -0
  29. package/dist/commands-logger.d.ts +77 -0
  30. package/dist/commands-logger.js +254 -0
  31. package/dist/commit-message-utils.d.ts +25 -0
  32. package/dist/commit-message-utils.js +41 -0
  33. package/dist/compliance-parser.d.ts +150 -0
  34. package/dist/compliance-parser.js +507 -0
  35. package/dist/constants/backlog-patterns.d.ts +20 -0
  36. package/dist/constants/backlog-patterns.js +23 -0
  37. package/dist/constants/dora-constants.d.ts +49 -0
  38. package/dist/constants/dora-constants.js +53 -0
  39. package/dist/constants/gate-constants.d.ts +15 -0
  40. package/dist/constants/gate-constants.js +15 -0
  41. package/dist/constants/linter-constants.d.ts +16 -0
  42. package/dist/constants/linter-constants.js +16 -0
  43. package/dist/constants/tokenizer-constants.d.ts +15 -0
  44. package/dist/constants/tokenizer-constants.js +15 -0
  45. package/dist/core/scope-checker.d.ts +97 -0
  46. package/dist/core/scope-checker.js +163 -0
  47. package/dist/core/tool-runner.d.ts +161 -0
  48. package/dist/core/tool-runner.js +393 -0
  49. package/dist/core/tool.constants.d.ts +105 -0
  50. package/dist/core/tool.constants.js +101 -0
  51. package/dist/core/tool.schemas.d.ts +226 -0
  52. package/dist/core/tool.schemas.js +226 -0
  53. package/dist/core/worktree-guard.d.ts +130 -0
  54. package/dist/core/worktree-guard.js +242 -0
  55. package/dist/coverage-gate.d.ts +108 -0
  56. package/dist/coverage-gate.js +196 -0
  57. package/dist/date-utils.d.ts +75 -0
  58. package/dist/date-utils.js +140 -0
  59. package/dist/dependency-graph.d.ts +142 -0
  60. package/dist/dependency-graph.js +550 -0
  61. package/dist/dependency-guard.d.ts +54 -0
  62. package/dist/dependency-guard.js +142 -0
  63. package/dist/dependency-validator.d.ts +105 -0
  64. package/dist/dependency-validator.js +154 -0
  65. package/dist/docs-path-validator.d.ts +36 -0
  66. package/dist/docs-path-validator.js +95 -0
  67. package/dist/domain/orchestration.constants.d.ts +99 -0
  68. package/dist/domain/orchestration.constants.js +97 -0
  69. package/dist/domain/orchestration.schemas.d.ts +280 -0
  70. package/dist/domain/orchestration.schemas.js +211 -0
  71. package/dist/domain/orchestration.types.d.ts +133 -0
  72. package/dist/domain/orchestration.types.js +12 -0
  73. package/dist/error-handler.d.ts +116 -0
  74. package/dist/error-handler.js +136 -0
  75. package/dist/file-classifiers.d.ts +62 -0
  76. package/dist/file-classifiers.js +108 -0
  77. package/dist/gates-agent-mode.d.ts +81 -0
  78. package/dist/gates-agent-mode.js +94 -0
  79. package/dist/generate-traceability.d.ts +107 -0
  80. package/dist/generate-traceability.js +411 -0
  81. package/dist/git-adapter.d.ts +395 -0
  82. package/dist/git-adapter.js +649 -0
  83. package/dist/git-staged-validator.d.ts +32 -0
  84. package/dist/git-staged-validator.js +48 -0
  85. package/dist/hardcoded-strings.d.ts +61 -0
  86. package/dist/hardcoded-strings.js +270 -0
  87. package/dist/incremental-lint.d.ts +78 -0
  88. package/dist/incremental-lint.js +129 -0
  89. package/dist/incremental-test.d.ts +39 -0
  90. package/dist/incremental-test.js +61 -0
  91. package/dist/index.d.ts +42 -0
  92. package/dist/index.js +61 -0
  93. package/dist/invariants/check-automated-tests.d.ts +50 -0
  94. package/dist/invariants/check-automated-tests.js +166 -0
  95. package/dist/invariants-runner.d.ts +103 -0
  96. package/dist/invariants-runner.js +527 -0
  97. package/dist/lane-checker.d.ts +50 -0
  98. package/dist/lane-checker.js +319 -0
  99. package/dist/lane-inference.d.ts +39 -0
  100. package/dist/lane-inference.js +195 -0
  101. package/dist/lane-lock.d.ts +211 -0
  102. package/dist/lane-lock.js +474 -0
  103. package/dist/lane-validator.d.ts +48 -0
  104. package/dist/lane-validator.js +114 -0
  105. package/dist/logs-lib.d.ts +104 -0
  106. package/dist/logs-lib.js +207 -0
  107. package/dist/lumenflow-config-schema.d.ts +272 -0
  108. package/dist/lumenflow-config-schema.js +207 -0
  109. package/dist/lumenflow-config.d.ts +95 -0
  110. package/dist/lumenflow-config.js +236 -0
  111. package/dist/manual-test-validator.d.ts +80 -0
  112. package/dist/manual-test-validator.js +200 -0
  113. package/dist/merge-lock.d.ts +115 -0
  114. package/dist/merge-lock.js +251 -0
  115. package/dist/micro-worktree.d.ts +159 -0
  116. package/dist/micro-worktree.js +427 -0
  117. package/dist/migration-deployer.d.ts +69 -0
  118. package/dist/migration-deployer.js +151 -0
  119. package/dist/orchestration-advisory-loader.d.ts +28 -0
  120. package/dist/orchestration-advisory-loader.js +87 -0
  121. package/dist/orchestration-advisory.d.ts +58 -0
  122. package/dist/orchestration-advisory.js +94 -0
  123. package/dist/orchestration-di.d.ts +48 -0
  124. package/dist/orchestration-di.js +57 -0
  125. package/dist/orchestration-rules.d.ts +57 -0
  126. package/dist/orchestration-rules.js +201 -0
  127. package/dist/orphan-detector.d.ts +131 -0
  128. package/dist/orphan-detector.js +226 -0
  129. package/dist/path-classifiers.d.ts +57 -0
  130. package/dist/path-classifiers.js +93 -0
  131. package/dist/piped-command-detector.d.ts +34 -0
  132. package/dist/piped-command-detector.js +64 -0
  133. package/dist/ports/dashboard-renderer.port.d.ts +112 -0
  134. package/dist/ports/dashboard-renderer.port.js +25 -0
  135. package/dist/ports/metrics-collector.port.d.ts +132 -0
  136. package/dist/ports/metrics-collector.port.js +26 -0
  137. package/dist/process-detector.d.ts +84 -0
  138. package/dist/process-detector.js +172 -0
  139. package/dist/prompt-linter.d.ts +72 -0
  140. package/dist/prompt-linter.js +312 -0
  141. package/dist/prompt-monitor.d.ts +15 -0
  142. package/dist/prompt-monitor.js +205 -0
  143. package/dist/rebase-artifact-cleanup.d.ts +145 -0
  144. package/dist/rebase-artifact-cleanup.js +433 -0
  145. package/dist/retry-strategy.d.ts +189 -0
  146. package/dist/retry-strategy.js +283 -0
  147. package/dist/risk-detector.d.ts +108 -0
  148. package/dist/risk-detector.js +252 -0
  149. package/dist/rollback-utils.d.ts +76 -0
  150. package/dist/rollback-utils.js +104 -0
  151. package/dist/section-headings.d.ts +43 -0
  152. package/dist/section-headings.js +49 -0
  153. package/dist/spawn-escalation.d.ts +90 -0
  154. package/dist/spawn-escalation.js +253 -0
  155. package/dist/spawn-monitor.d.ts +229 -0
  156. package/dist/spawn-monitor.js +672 -0
  157. package/dist/spawn-recovery.d.ts +82 -0
  158. package/dist/spawn-recovery.js +298 -0
  159. package/dist/spawn-registry-schema.d.ts +98 -0
  160. package/dist/spawn-registry-schema.js +108 -0
  161. package/dist/spawn-registry-store.d.ts +146 -0
  162. package/dist/spawn-registry-store.js +273 -0
  163. package/dist/spawn-tree.d.ts +121 -0
  164. package/dist/spawn-tree.js +285 -0
  165. package/dist/stamp-status-validator.d.ts +84 -0
  166. package/dist/stamp-status-validator.js +134 -0
  167. package/dist/stamp-utils.d.ts +100 -0
  168. package/dist/stamp-utils.js +229 -0
  169. package/dist/state-machine.d.ts +26 -0
  170. package/dist/state-machine.js +83 -0
  171. package/dist/system-map-validator.d.ts +80 -0
  172. package/dist/system-map-validator.js +272 -0
  173. package/dist/telemetry.d.ts +80 -0
  174. package/dist/telemetry.js +213 -0
  175. package/dist/token-counter.d.ts +51 -0
  176. package/dist/token-counter.js +145 -0
  177. package/dist/usecases/get-dashboard-data.usecase.d.ts +52 -0
  178. package/dist/usecases/get-dashboard-data.usecase.js +61 -0
  179. package/dist/usecases/get-suggestions.usecase.d.ts +100 -0
  180. package/dist/usecases/get-suggestions.usecase.js +153 -0
  181. package/dist/user-normalizer.d.ts +41 -0
  182. package/dist/user-normalizer.js +141 -0
  183. package/dist/validators/phi-constants.d.ts +97 -0
  184. package/dist/validators/phi-constants.js +152 -0
  185. package/dist/validators/phi-scanner.d.ts +58 -0
  186. package/dist/validators/phi-scanner.js +215 -0
  187. package/dist/worktree-ownership.d.ts +50 -0
  188. package/dist/worktree-ownership.js +74 -0
  189. package/dist/worktree-scanner.d.ts +103 -0
  190. package/dist/worktree-scanner.js +168 -0
  191. package/dist/worktree-symlink.d.ts +99 -0
  192. package/dist/worktree-symlink.js +359 -0
  193. package/dist/wu-backlog-updater.d.ts +17 -0
  194. package/dist/wu-backlog-updater.js +37 -0
  195. package/dist/wu-checkpoint.d.ts +124 -0
  196. package/dist/wu-checkpoint.js +233 -0
  197. package/dist/wu-claim-helpers.d.ts +26 -0
  198. package/dist/wu-claim-helpers.js +63 -0
  199. package/dist/wu-claim-resume.d.ts +106 -0
  200. package/dist/wu-claim-resume.js +276 -0
  201. package/dist/wu-consistency-checker.d.ts +95 -0
  202. package/dist/wu-consistency-checker.js +567 -0
  203. package/dist/wu-constants.d.ts +1275 -0
  204. package/dist/wu-constants.js +1382 -0
  205. package/dist/wu-create-validators.d.ts +42 -0
  206. package/dist/wu-create-validators.js +93 -0
  207. package/dist/wu-done-branch-only.d.ts +63 -0
  208. package/dist/wu-done-branch-only.js +191 -0
  209. package/dist/wu-done-messages.d.ts +119 -0
  210. package/dist/wu-done-messages.js +185 -0
  211. package/dist/wu-done-pr.d.ts +72 -0
  212. package/dist/wu-done-pr.js +174 -0
  213. package/dist/wu-done-retry-helpers.d.ts +85 -0
  214. package/dist/wu-done-retry-helpers.js +172 -0
  215. package/dist/wu-done-ui.d.ts +37 -0
  216. package/dist/wu-done-ui.js +69 -0
  217. package/dist/wu-done-validators.d.ts +411 -0
  218. package/dist/wu-done-validators.js +1229 -0
  219. package/dist/wu-done-worktree.d.ts +182 -0
  220. package/dist/wu-done-worktree.js +1097 -0
  221. package/dist/wu-helpers.d.ts +128 -0
  222. package/dist/wu-helpers.js +248 -0
  223. package/dist/wu-lint.d.ts +70 -0
  224. package/dist/wu-lint.js +234 -0
  225. package/dist/wu-paths.d.ts +171 -0
  226. package/dist/wu-paths.js +178 -0
  227. package/dist/wu-preflight-validators.d.ts +86 -0
  228. package/dist/wu-preflight-validators.js +251 -0
  229. package/dist/wu-recovery.d.ts +138 -0
  230. package/dist/wu-recovery.js +341 -0
  231. package/dist/wu-repair-core.d.ts +131 -0
  232. package/dist/wu-repair-core.js +669 -0
  233. package/dist/wu-schema-normalization.d.ts +17 -0
  234. package/dist/wu-schema-normalization.js +82 -0
  235. package/dist/wu-schema.d.ts +793 -0
  236. package/dist/wu-schema.js +881 -0
  237. package/dist/wu-spawn-helpers.d.ts +121 -0
  238. package/dist/wu-spawn-helpers.js +271 -0
  239. package/dist/wu-spawn.d.ts +158 -0
  240. package/dist/wu-spawn.js +1306 -0
  241. package/dist/wu-state-schema.d.ts +213 -0
  242. package/dist/wu-state-schema.js +156 -0
  243. package/dist/wu-state-store.d.ts +264 -0
  244. package/dist/wu-state-store.js +691 -0
  245. package/dist/wu-status-transition.d.ts +63 -0
  246. package/dist/wu-status-transition.js +382 -0
  247. package/dist/wu-status-updater.d.ts +25 -0
  248. package/dist/wu-status-updater.js +116 -0
  249. package/dist/wu-transaction-collectors.d.ts +116 -0
  250. package/dist/wu-transaction-collectors.js +272 -0
  251. package/dist/wu-transaction.d.ts +170 -0
  252. package/dist/wu-transaction.js +273 -0
  253. package/dist/wu-validation-constants.d.ts +60 -0
  254. package/dist/wu-validation-constants.js +66 -0
  255. package/dist/wu-validation.d.ts +118 -0
  256. package/dist/wu-validation.js +243 -0
  257. package/dist/wu-validator.d.ts +62 -0
  258. package/dist/wu-validator.js +325 -0
  259. package/dist/wu-yaml-fixer.d.ts +97 -0
  260. package/dist/wu-yaml-fixer.js +264 -0
  261. package/dist/wu-yaml.d.ts +86 -0
  262. package/dist/wu-yaml.js +222 -0
  263. package/package.json +114 -0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Orchestration Domain Types
3
+ *
4
+ * TypeScript types inferred from Zod schemas.
5
+ * Single source of truth - schemas validate at runtime, types at compile time.
6
+ *
7
+ * @module orchestration.types
8
+ * @see {@link ./orchestration.schemas.mjs} - Schemas these types are inferred from
9
+ * @see {@link ./orchestration.constants.mjs} - Constants and derived types
10
+ */
11
+ import type { z } from 'zod';
12
+ import type { GlobalStatusSchema, AgentMetricSchema, WUProgressSchema, TimelineEventSchema, AlertSchema, SuggestionSchema, ExecutionPlanSchema, UserChoiceSchema, DashboardDataSchema } from './orchestration.schemas.js';
13
+ export type { Lane, AgentName, SeverityLevel, AgentResultStatus, TimelineEventType, EventSeverityLevel, UserChoiceOption, MandatoryAgentName, } from './orchestration.constants.js';
14
+ export { LANES, AGENT_NAMES, SEVERITY_LEVELS, AGENT_RESULT_STATUSES, TIMELINE_EVENT_TYPES, EVENT_SEVERITY_LEVELS, USER_CHOICE_OPTIONS, MANDATORY_AGENT_NAMES, } from './orchestration.constants.js';
15
+ /**
16
+ * Global orchestration status.
17
+ * Shows high-level dashboard metrics at a glance.
18
+ *
19
+ * @example
20
+ * const status: GlobalStatus = {
21
+ * activeWUs: 2,
22
+ * completed24h: 5,
23
+ * blocked: 1,
24
+ * gatesFailing: 0,
25
+ * longestRunning: { wuId: 'WU-1234', lane: 'Intelligence', durationMs: 2700000 },
26
+ * pendingMandatory: [{ wuId: 'WU-1235', agent: 'security-auditor' }],
27
+ * };
28
+ */
29
+ export type GlobalStatus = z.infer<typeof GlobalStatusSchema>;
30
+ /**
31
+ * Per-agent metrics for dashboard display.
32
+ * Tracks invocation counts, pass rates, and timing.
33
+ *
34
+ * @example
35
+ * const metric: AgentMetric = {
36
+ * invoked: 3,
37
+ * passRate: 100,
38
+ * avgDurationMs: 120000,
39
+ * lastRun: { wuId: 'WU-1234', timestamp: '2025-01-15T10:00:00Z', result: 'pass' },
40
+ * };
41
+ */
42
+ export type AgentMetric = z.infer<typeof AgentMetricSchema>;
43
+ /**
44
+ * Work Unit progress for dashboard display.
45
+ * Shows DoD progress and agent status per WU.
46
+ *
47
+ * @example
48
+ * const progress: WUProgress = {
49
+ * wuId: 'WU-1234',
50
+ * lane: 'Intelligence',
51
+ * title: 'LLM Classification Feature',
52
+ * dodProgress: 8,
53
+ * dodTotal: 11,
54
+ * agents: { 'beacon-guardian': 'pass', 'code-reviewer': 'pending' },
55
+ * headline: 'Blocked on code-reviewer - awaiting approval',
56
+ * };
57
+ */
58
+ export type WUProgress = z.infer<typeof WUProgressSchema>;
59
+ /**
60
+ * Timeline event for orchestration history.
61
+ * Records key events for dashboard display.
62
+ *
63
+ * @example
64
+ * const event: TimelineEvent = {
65
+ * timestamp: '2025-01-15T09:00:00Z',
66
+ * event: 'claim',
67
+ * wuId: 'WU-1234',
68
+ * detail: 'Claimed for Intelligence lane',
69
+ * severity: 'info',
70
+ * };
71
+ */
72
+ export type TimelineEvent = z.infer<typeof TimelineEventSchema>;
73
+ /**
74
+ * Dashboard alert for items requiring attention.
75
+ *
76
+ * @example
77
+ * const alert: Alert = {
78
+ * severity: 'high',
79
+ * message: 'Mandatory agent not yet invoked',
80
+ * wuId: 'WU-1235',
81
+ * action: 'Run security-auditor before wu:done',
82
+ * };
83
+ */
84
+ export type Alert = z.infer<typeof AlertSchema>;
85
+ /**
86
+ * Orchestration suggestion for next actions.
87
+ *
88
+ * @example
89
+ * const suggestion: Suggestion = {
90
+ * id: 'sug-001',
91
+ * priority: 'high',
92
+ * action: 'Run security-auditor',
93
+ * reason: 'WU touches auth paths',
94
+ * command: 'pnpm orchestrate:run security-auditor',
95
+ * };
96
+ */
97
+ export type Suggestion = z.infer<typeof SuggestionSchema>;
98
+ /**
99
+ * Execution plan for proposed orchestration actions.
100
+ *
101
+ * @example
102
+ * const plan: ExecutionPlan = {
103
+ * wuId: 'WU-1234',
104
+ * steps: [
105
+ * { order: 1, agent: 'beacon-guardian', status: 'pending' },
106
+ * { order: 2, action: 'gates', status: 'pending' },
107
+ * ],
108
+ * estimatedTokens: 5000,
109
+ * };
110
+ */
111
+ export type ExecutionPlan = z.infer<typeof ExecutionPlanSchema>;
112
+ /**
113
+ * User choice on execution plan confirmation.
114
+ *
115
+ * @example
116
+ * const choice: UserChoice = { choice: 'approve' };
117
+ * const editChoice: UserChoice = { choice: 'edit', modifications: ['Skip step 2'] };
118
+ */
119
+ export type UserChoice = z.infer<typeof UserChoiceSchema>;
120
+ /**
121
+ * Complete dashboard data aggregating all metrics.
122
+ * This is the main data structure passed to renderers.
123
+ *
124
+ * @example
125
+ * const data: DashboardData = {
126
+ * globalStatus: { ... },
127
+ * agentMetrics: { 'security-auditor': { ... } },
128
+ * wuProgress: [{ ... }],
129
+ * timeline: [{ ... }],
130
+ * alerts: [{ ... }],
131
+ * };
132
+ */
133
+ export type DashboardData = z.infer<typeof DashboardDataSchema>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Orchestration Domain Types
3
+ *
4
+ * TypeScript types inferred from Zod schemas.
5
+ * Single source of truth - schemas validate at runtime, types at compile time.
6
+ *
7
+ * @module orchestration.types
8
+ * @see {@link ./orchestration.schemas.mjs} - Schemas these types are inferred from
9
+ * @see {@link ./orchestration.constants.mjs} - Constants and derived types
10
+ */
11
+ // Re-export const values as well
12
+ export { LANES, AGENT_NAMES, SEVERITY_LEVELS, AGENT_RESULT_STATUSES, TIMELINE_EVENT_TYPES, EVENT_SEVERITY_LEVELS, USER_CHOICE_OPTIONS, MANDATORY_AGENT_NAMES, } from './orchestration.constants.js';
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @file error-handler.mjs
3
+ * @description Structured error handling with error codes
4
+ * WU-1082: Extract shared utilities (eliminate die() duplication)
5
+ *
6
+ * Replaces die() function in:
7
+ * - tools/wu-claim.mjs
8
+ * - tools/wu-done.mjs
9
+ * - tools/wu-block.mjs
10
+ * - tools/wu-unblock.mjs
11
+ * - tools/wu-create.mjs
12
+ * - tools/wu-cleanup.mjs
13
+ * - tools/gates-pre-commit.mjs
14
+ * - tools/validate.mjs
15
+ * - tools/guard-worktree-commit.mjs
16
+ */
17
+ /**
18
+ * Structured error class with error codes and details
19
+ * @class WUError
20
+ * @extends Error
21
+ */
22
+ export declare class WUError extends Error {
23
+ /** Error code (e.g., 'WU_NOT_FOUND') */
24
+ code: string;
25
+ /** Additional error context */
26
+ details: Record<string, unknown>;
27
+ /** Suggested commands or actions to try (optional) */
28
+ tryNext?: string[];
29
+ /** Alias for details for agent-friendly access */
30
+ context?: Record<string, unknown>;
31
+ /**
32
+ * Create a WU error
33
+ * @param {string} code - Error code (e.g., 'WU_NOT_FOUND')
34
+ * @param {string} message - Human-readable error message
35
+ * @param {object} [details={}] - Additional error context
36
+ */
37
+ constructor(code: string, message: string, details?: Record<string, unknown>);
38
+ }
39
+ /**
40
+ * Exit process with error message (replaces die() function)
41
+ * Auto-detects script name from process.argv[1] - no string literals needed!
42
+ * @param {string} message - Error message to log
43
+ * @param {number} [exitCode=1] - Process exit code
44
+ * @example
45
+ * die('WU file not found');
46
+ * die('Gates failed', 2);
47
+ */
48
+ export declare function die(message: any, exitCode?: number): void;
49
+ /**
50
+ * Create a WUError instance (factory function)
51
+ * @param {string} code - Error code
52
+ * @param {string} message - Error message
53
+ * @param {object} [details={}] - Error details
54
+ * @returns {WUError} Structured error instance
55
+ * @example
56
+ * throw createError('WU_NOT_FOUND', 'WU-123 not found', { id: 'WU-123' });
57
+ */
58
+ export declare function createError(code: any, message: any, details?: {}): WUError;
59
+ /**
60
+ * Options for creating agent-friendly errors
61
+ */
62
+ export interface AgentFriendlyErrorOptions {
63
+ /** Array of suggested commands or actions to try */
64
+ tryNext?: string[];
65
+ /** Additional context information */
66
+ context?: Record<string, unknown>;
67
+ }
68
+ /**
69
+ * Create an agent-friendly error with try-next command suggestions
70
+ * WU-1339: Agent-friendly error messages and hints (AX3)
71
+ *
72
+ * @param {string} code - Error code from ErrorCodes
73
+ * @param {string} message - Human-readable error message
74
+ * @param {AgentFriendlyErrorOptions} options - Options object
75
+ * @returns {WUError} Error instance with tryNext property and context
76
+ * @example
77
+ * throw createAgentFriendlyError(
78
+ * ErrorCodes.WU_NOT_FOUND,
79
+ * 'WU-1234 not found',
80
+ * {
81
+ * tryNext: ['pnpm wu:create --id WU-1234 --lane "<lane>" --title "..."'],
82
+ * context: { wuId: 'WU-1234' }
83
+ * }
84
+ * );
85
+ */
86
+ export declare function createAgentFriendlyError(code: any, message: any, options?: AgentFriendlyErrorOptions): WUError;
87
+ /**
88
+ * Common error codes for WU operations
89
+ */
90
+ export declare const ErrorCodes: {
91
+ WU_NOT_FOUND: string;
92
+ WU_ALREADY_CLAIMED: string;
93
+ WU_NOT_CLAIMED: string;
94
+ INVALID_WU_ID: string;
95
+ INVALID_LANE: string;
96
+ GATES_FAILED: string;
97
+ GIT_ERROR: string;
98
+ VALIDATION_ERROR: string;
99
+ FILE_NOT_FOUND: string;
100
+ YAML_PARSE_ERROR: string;
101
+ PARSE_ERROR: string;
102
+ WORKTREE_ERROR: string;
103
+ BRANCH_ERROR: string;
104
+ STATE_ERROR: string;
105
+ SECTION_NOT_FOUND: string;
106
+ INTERNAL_ERROR: string;
107
+ RECOVERY_ERROR: string;
108
+ TRANSACTION_ERROR: string;
109
+ LOCK_ERROR: string;
110
+ INIT_NOT_FOUND: string;
111
+ INIT_ALREADY_EXISTS: string;
112
+ INVALID_INIT_ID: string;
113
+ INVALID_SLUG: string;
114
+ INVALID_PHASE: string;
115
+ DEPENDENCY_CYCLE: string;
116
+ };
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @file error-handler.mjs
3
+ * @description Structured error handling with error codes
4
+ * WU-1082: Extract shared utilities (eliminate die() duplication)
5
+ *
6
+ * Replaces die() function in:
7
+ * - tools/wu-claim.mjs
8
+ * - tools/wu-done.mjs
9
+ * - tools/wu-block.mjs
10
+ * - tools/wu-unblock.mjs
11
+ * - tools/wu-create.mjs
12
+ * - tools/wu-cleanup.mjs
13
+ * - tools/gates-pre-commit.mjs
14
+ * - tools/validate.mjs
15
+ * - tools/guard-worktree-commit.mjs
16
+ */
17
+ /**
18
+ * Structured error class with error codes and details
19
+ * @class WUError
20
+ * @extends Error
21
+ */
22
+ export class WUError extends Error {
23
+ /** Error code (e.g., 'WU_NOT_FOUND') */
24
+ code;
25
+ /** Additional error context */
26
+ details;
27
+ /** Suggested commands or actions to try (optional) */
28
+ tryNext;
29
+ /** Alias for details for agent-friendly access */
30
+ context;
31
+ /**
32
+ * Create a WU error
33
+ * @param {string} code - Error code (e.g., 'WU_NOT_FOUND')
34
+ * @param {string} message - Human-readable error message
35
+ * @param {object} [details={}] - Additional error context
36
+ */
37
+ constructor(code, message, details = {}) {
38
+ super(message);
39
+ this.name = 'WUError';
40
+ this.code = code;
41
+ this.details = details;
42
+ // Maintains proper stack trace for where error was thrown (V8 only)
43
+ if (Error.captureStackTrace) {
44
+ Error.captureStackTrace(this, WUError);
45
+ }
46
+ }
47
+ }
48
+ /**
49
+ * Exit process with error message (replaces die() function)
50
+ * Auto-detects script name from process.argv[1] - no string literals needed!
51
+ * @param {string} message - Error message to log
52
+ * @param {number} [exitCode=1] - Process exit code
53
+ * @example
54
+ * die('WU file not found');
55
+ * die('Gates failed', 2);
56
+ */
57
+ export function die(message, exitCode = 1) {
58
+ // Auto-detect script name from process.argv[1] (eliminates string literal duplication)
59
+ const scriptPath = process.argv[1] || 'unknown';
60
+ const scriptName = scriptPath.split('/').pop().replace('.js', '');
61
+ console.error(`[${scriptName}] ${message}`);
62
+ process.exit(exitCode);
63
+ }
64
+ /**
65
+ * Create a WUError instance (factory function)
66
+ * @param {string} code - Error code
67
+ * @param {string} message - Error message
68
+ * @param {object} [details={}] - Error details
69
+ * @returns {WUError} Structured error instance
70
+ * @example
71
+ * throw createError('WU_NOT_FOUND', 'WU-123 not found', { id: 'WU-123' });
72
+ */
73
+ export function createError(code, message, details = {}) {
74
+ return new WUError(code, message, details);
75
+ }
76
+ /**
77
+ * Create an agent-friendly error with try-next command suggestions
78
+ * WU-1339: Agent-friendly error messages and hints (AX3)
79
+ *
80
+ * @param {string} code - Error code from ErrorCodes
81
+ * @param {string} message - Human-readable error message
82
+ * @param {AgentFriendlyErrorOptions} options - Options object
83
+ * @returns {WUError} Error instance with tryNext property and context
84
+ * @example
85
+ * throw createAgentFriendlyError(
86
+ * ErrorCodes.WU_NOT_FOUND,
87
+ * 'WU-1234 not found',
88
+ * {
89
+ * tryNext: ['pnpm wu:create --id WU-1234 --lane "<lane>" --title "..."'],
90
+ * context: { wuId: 'WU-1234' }
91
+ * }
92
+ * );
93
+ */
94
+ export function createAgentFriendlyError(code, message, options = {}) {
95
+ const { tryNext, context = {} } = options;
96
+ const error = createError(code, message, context);
97
+ // Add tryNext suggestions if provided
98
+ if (tryNext && Array.isArray(tryNext) && tryNext.length > 0) {
99
+ error.tryNext = tryNext;
100
+ }
101
+ // Expose details as context for agent-friendly access
102
+ // (WUError stores context in details property, but we expose it as context for clarity)
103
+ error.context = error.details;
104
+ return error;
105
+ }
106
+ /**
107
+ * Common error codes for WU operations
108
+ */
109
+ export const ErrorCodes = {
110
+ WU_NOT_FOUND: 'WU_NOT_FOUND',
111
+ WU_ALREADY_CLAIMED: 'WU_ALREADY_CLAIMED',
112
+ WU_NOT_CLAIMED: 'WU_NOT_CLAIMED',
113
+ INVALID_WU_ID: 'INVALID_WU_ID',
114
+ INVALID_LANE: 'INVALID_LANE',
115
+ GATES_FAILED: 'GATES_FAILED',
116
+ GIT_ERROR: 'GIT_ERROR',
117
+ VALIDATION_ERROR: 'VALIDATION_ERROR',
118
+ FILE_NOT_FOUND: 'FILE_NOT_FOUND',
119
+ YAML_PARSE_ERROR: 'YAML_PARSE_ERROR',
120
+ PARSE_ERROR: 'PARSE_ERROR',
121
+ WORKTREE_ERROR: 'WORKTREE_ERROR',
122
+ BRANCH_ERROR: 'BRANCH_ERROR',
123
+ STATE_ERROR: 'STATE_ERROR',
124
+ SECTION_NOT_FOUND: 'SECTION_NOT_FOUND',
125
+ INTERNAL_ERROR: 'INTERNAL_ERROR',
126
+ RECOVERY_ERROR: 'RECOVERY_ERROR',
127
+ TRANSACTION_ERROR: 'TRANSACTION_ERROR', // WU-1369: Atomic transaction errors
128
+ LOCK_ERROR: 'LOCK_ERROR', // WU-1747: Merge lock errors
129
+ // Initiative system error codes (WU-1247)
130
+ INIT_NOT_FOUND: 'INIT_NOT_FOUND',
131
+ INIT_ALREADY_EXISTS: 'INIT_ALREADY_EXISTS',
132
+ INVALID_INIT_ID: 'INVALID_INIT_ID',
133
+ INVALID_SLUG: 'INVALID_SLUG',
134
+ INVALID_PHASE: 'INVALID_PHASE',
135
+ DEPENDENCY_CYCLE: 'DEPENDENCY_CYCLE',
136
+ };
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * File Classifiers
4
+ *
5
+ * Shared utilities for classifying file types.
6
+ * Consolidates duplicated classification logic from wu-validator.mjs
7
+ * and code-path-validator.mjs.
8
+ *
9
+ * WU-1848: DRY Consolidation - Eliminate duplicated code patterns
10
+ *
11
+ * @see tools/lib/wu-validator.mjs - Original isTestFile, isMarkdownFile
12
+ * @see tools/lib/code-path-validator.mjs - Duplicated implementations
13
+ */
14
+ /**
15
+ * Prefixes for paths that qualify as documentation-only.
16
+ * @constant {string[]}
17
+ */
18
+ declare const DOCS_ONLY_PREFIXES: readonly string[];
19
+ /**
20
+ * Root file patterns that qualify as docs-only.
21
+ * @constant {string[]}
22
+ */
23
+ declare const DOCS_ONLY_ROOT_FILES: readonly string[];
24
+ /**
25
+ * Test file patterns for detection
26
+ * @constant {RegExp[]}
27
+ */
28
+ declare const TEST_FILE_PATTERNS: readonly RegExp[];
29
+ /**
30
+ * Check if a file path is a test file
31
+ *
32
+ * Detects test files by extension and directory patterns:
33
+ * - *.test.ts, *.test.tsx, *.test.js, *.test.jsx, *.test.mjs
34
+ * - *.spec.ts, *.spec.tsx, *.spec.js, *.spec.jsx, *.spec.mjs
35
+ * - Files in __tests__ directories
36
+ * - *.test-utils.* files
37
+ * - *.mock.* files
38
+ *
39
+ * @param {string} filePath - Path to check
40
+ * @returns {boolean} True if file is a test file
41
+ */
42
+ export declare function isTestFile(filePath: any): boolean;
43
+ /**
44
+ * Check if a file path is a markdown file
45
+ *
46
+ * @param {string} filePath - Path to check
47
+ * @returns {boolean} True if file is a markdown file (.md extension)
48
+ */
49
+ export declare function isMarkdownFile(filePath: any): boolean;
50
+ /**
51
+ * Check if a file path is a documentation-only path
52
+ *
53
+ * Documentation paths include:
54
+ * - docs/, ai/, .claude/, memory-bank/ directories
55
+ * - README* files at root
56
+ * - CLAUDE*.md files at root
57
+ *
58
+ * @param {string} filePath - Path to check
59
+ * @returns {boolean} True if file is in a documentation path
60
+ */
61
+ export declare function isDocumentationPath(filePath: any): boolean;
62
+ export { DOCS_ONLY_PREFIXES, DOCS_ONLY_ROOT_FILES, TEST_FILE_PATTERNS };
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * File Classifiers
4
+ *
5
+ * Shared utilities for classifying file types.
6
+ * Consolidates duplicated classification logic from wu-validator.mjs
7
+ * and code-path-validator.mjs.
8
+ *
9
+ * WU-1848: DRY Consolidation - Eliminate duplicated code patterns
10
+ *
11
+ * @see tools/lib/wu-validator.mjs - Original isTestFile, isMarkdownFile
12
+ * @see tools/lib/code-path-validator.mjs - Duplicated implementations
13
+ */
14
+ /**
15
+ * Prefixes for paths that qualify as documentation-only.
16
+ * @constant {string[]}
17
+ */
18
+ const DOCS_ONLY_PREFIXES = Object.freeze(['docs/', 'ai/', '.claude/', 'memory-bank/']);
19
+ /**
20
+ * Root file patterns that qualify as docs-only.
21
+ * @constant {string[]}
22
+ */
23
+ const DOCS_ONLY_ROOT_FILES = Object.freeze(['readme', 'claude']);
24
+ /**
25
+ * Test file patterns for detection
26
+ * @constant {RegExp[]}
27
+ */
28
+ const TEST_FILE_PATTERNS = Object.freeze([
29
+ /\.test\.(ts|tsx|js|jsx|mjs)$/,
30
+ /\.spec\.(ts|tsx|js|jsx|mjs)$/,
31
+ /__tests__\//,
32
+ /\.test-utils\./,
33
+ /\.mock\./,
34
+ ]);
35
+ /**
36
+ * Check if a file path is a test file
37
+ *
38
+ * Detects test files by extension and directory patterns:
39
+ * - *.test.ts, *.test.tsx, *.test.js, *.test.jsx, *.test.mjs
40
+ * - *.spec.ts, *.spec.tsx, *.spec.js, *.spec.jsx, *.spec.mjs
41
+ * - Files in __tests__ directories
42
+ * - *.test-utils.* files
43
+ * - *.mock.* files
44
+ *
45
+ * @param {string} filePath - Path to check
46
+ * @returns {boolean} True if file is a test file
47
+ */
48
+ export function isTestFile(filePath) {
49
+ if (!filePath || typeof filePath !== 'string') {
50
+ return false;
51
+ }
52
+ // Normalise Windows paths to forward slashes
53
+ const normalized = filePath.replace(/\\/g, '/');
54
+ return TEST_FILE_PATTERNS.some((pattern) => pattern.test(normalized));
55
+ }
56
+ /**
57
+ * Check if a file path is a markdown file
58
+ *
59
+ * @param {string} filePath - Path to check
60
+ * @returns {boolean} True if file is a markdown file (.md extension)
61
+ */
62
+ export function isMarkdownFile(filePath) {
63
+ if (!filePath || typeof filePath !== 'string') {
64
+ return false;
65
+ }
66
+ // Normalise Windows paths to forward slashes
67
+ const normalized = filePath.replace(/\\/g, '/');
68
+ return /\.md$/i.test(normalized);
69
+ }
70
+ /**
71
+ * Check if a file path is a documentation-only path
72
+ *
73
+ * Documentation paths include:
74
+ * - docs/, ai/, .claude/, memory-bank/ directories
75
+ * - README* files at root
76
+ * - CLAUDE*.md files at root
77
+ *
78
+ * @param {string} filePath - Path to check
79
+ * @returns {boolean} True if file is in a documentation path
80
+ */
81
+ export function isDocumentationPath(filePath) {
82
+ if (!filePath || typeof filePath !== 'string') {
83
+ return false;
84
+ }
85
+ const path = filePath.trim();
86
+ if (path.length === 0) {
87
+ return false;
88
+ }
89
+ // Check docs-only prefixes (docs/, ai/, .claude/, memory-bank/)
90
+ for (const prefix of DOCS_ONLY_PREFIXES) {
91
+ if (path.startsWith(prefix)) {
92
+ return true;
93
+ }
94
+ }
95
+ // Check if it's a markdown file (*.md)
96
+ if (isMarkdownFile(path)) {
97
+ // Check root file patterns (README*, CLAUDE*.md)
98
+ const lowerPath = path.toLowerCase();
99
+ for (const pattern of DOCS_ONLY_ROOT_FILES) {
100
+ if (lowerPath.startsWith(pattern)) {
101
+ return true;
102
+ }
103
+ }
104
+ }
105
+ return false;
106
+ }
107
+ // Export constants for external use
108
+ export { DOCS_ONLY_PREFIXES, DOCS_ONLY_ROOT_FILES, TEST_FILE_PATTERNS };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Options for agent mode detection
3
+ */
4
+ interface GatesAgentModeOptions {
5
+ /** Command line arguments */
6
+ argv?: string[];
7
+ /** Environment variables */
8
+ env?: Record<string, string | undefined>;
9
+ /** stdout stream */
10
+ stdout?: {
11
+ isTTY?: boolean;
12
+ };
13
+ }
14
+ /**
15
+ * Options for log path functions
16
+ */
17
+ interface GatesLogOptions {
18
+ /** Working directory */
19
+ cwd: string;
20
+ /** Environment variables */
21
+ env?: Record<string, string | undefined>;
22
+ }
23
+ /**
24
+ * Options for building gate log path
25
+ */
26
+ interface BuildGatesLogPathOptions extends GatesLogOptions {
27
+ /** WU ID */
28
+ wuId?: string;
29
+ /** Lane name */
30
+ lane?: string;
31
+ /** Current timestamp */
32
+ now?: Date;
33
+ }
34
+ /**
35
+ * Options for updating symlink
36
+ */
37
+ interface UpdateGatesLatestSymlinkOptions extends GatesLogOptions {
38
+ /** Path to the actual gate log file */
39
+ logPath: string;
40
+ }
41
+ /**
42
+ * Determine whether gates should run in low-noise "agent mode".
43
+ *
44
+ * Agent mode is intended for Claude Code sessions, where tool output is injected into the
45
+ * conversation context and can trigger "prompt too long".
46
+ *
47
+ * Detection strategy (WU-1827):
48
+ * 1. --verbose flag always forces full output (returns false)
49
+ * 2. CLAUDE_PROJECT_DIR env var is a strong hint (returns true if set)
50
+ * 3. TTY check: non-TTY + non-CI = likely agent mode (returns true)
51
+ * 4. Interactive TTY = human user (returns false)
52
+ *
53
+ * @param {GatesAgentModeOptions} options
54
+ * @returns {boolean} True if gates should run in agent mode
55
+ */
56
+ export declare function shouldUseGatesAgentMode({ argv, env, stdout }?: GatesAgentModeOptions): boolean;
57
+ export declare function getGatesLogDir({ cwd, env }: GatesLogOptions): string;
58
+ export declare function buildGatesLogPath({ cwd, env, wuId, lane, now, }: BuildGatesLogPathOptions): string;
59
+ /**
60
+ * Get the path to the gates-latest.log symlink (WU-2064)
61
+ *
62
+ * @param {Object} options
63
+ * @param {string} options.cwd - Working directory
64
+ * @param {Object} [options.env] - Environment variables
65
+ * @returns {string} Path to the symlink
66
+ */
67
+ export declare function getGatesLatestSymlinkPath({ cwd, env }: GatesLogOptions): string;
68
+ /**
69
+ * Create or update the gates-latest.log symlink to point to the most recent gate run (WU-2064)
70
+ *
71
+ * This provides a stable path for agents to access the most recent gate log
72
+ * without needing to know the timestamp-based filename.
73
+ *
74
+ * @param {Object} options
75
+ * @param {string} options.logPath - Path to the actual gate log file
76
+ * @param {string} options.cwd - Working directory
77
+ * @param {Object} [options.env] - Environment variables
78
+ * @returns {boolean} True if symlink was created/updated successfully
79
+ */
80
+ export declare function updateGatesLatestSymlink({ logPath, cwd, env }: UpdateGatesLatestSymlinkOptions): boolean;
81
+ export {};