@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,226 @@
1
+ /**
2
+ * @file tool.schemas.ts
3
+ * @description Zod schemas for tool abstraction layer (WU-1394)
4
+ *
5
+ * Provides runtime validation and TypeScript type inference for tool inputs,
6
+ * outputs, and metadata. Supports JSON Schema export for provider adapters
7
+ * (MCP, OpenAI, Gemini).
8
+ *
9
+ * Reference: tools/lib/arg-parser.mjs for current argument handling patterns
10
+ */
11
+ import { z, type ZodTypeAny } from 'zod';
12
+ /**
13
+ * Schema for tool input
14
+ *
15
+ * Represents the standardized input format for all tools in the system.
16
+ * Maps command names to their arguments and optional context.
17
+ */
18
+ export declare const ToolInputSchema: z.ZodObject<{
19
+ command: z.ZodString;
20
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
21
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
22
+ }, z.core.$strip>;
23
+ export type ToolInput = z.infer<typeof ToolInputSchema>;
24
+ /**
25
+ * Schema for tool error details
26
+ */
27
+ export declare const ToolErrorSchema: z.ZodObject<{
28
+ code: z.ZodString;
29
+ message: z.ZodString;
30
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
31
+ stack: z.ZodOptional<z.ZodString>;
32
+ tryNext: z.ZodOptional<z.ZodArray<z.ZodString>>;
33
+ }, z.core.$strip>;
34
+ export type ToolError = z.infer<typeof ToolErrorSchema>;
35
+ /**
36
+ * Schema for tool output
37
+ *
38
+ * Standardized response format for all tools. Success/failure indicated by
39
+ * the `success` field, with data/error fields providing details.
40
+ */
41
+ export declare const ToolOutputSchema: z.ZodObject<{
42
+ success: z.ZodBoolean;
43
+ data: z.ZodOptional<z.ZodUnknown>;
44
+ error: z.ZodOptional<z.ZodObject<{
45
+ code: z.ZodString;
46
+ message: z.ZodString;
47
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
48
+ stack: z.ZodOptional<z.ZodString>;
49
+ tryNext: z.ZodOptional<z.ZodArray<z.ZodString>>;
50
+ }, z.core.$strip>>;
51
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
52
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
53
+ }, z.core.$strip>;
54
+ export type ToolOutput = z.infer<typeof ToolOutputSchema>;
55
+ /**
56
+ * Schema for tool metadata
57
+ *
58
+ * Describes a tool's capabilities, domain, permissions, and usage examples.
59
+ */
60
+ export declare const ToolMetadataSchema: z.ZodObject<{
61
+ name: z.ZodString;
62
+ description: z.ZodString;
63
+ domain: z.ZodEnum<{
64
+ git: "git";
65
+ test: "test";
66
+ file: "file";
67
+ wu: "wu";
68
+ initiative: "initiative";
69
+ docs: "docs";
70
+ security: "security";
71
+ explore: "explore";
72
+ db: "db";
73
+ metrics: "metrics";
74
+ orchestration: "orchestration";
75
+ util: "util";
76
+ }>;
77
+ permission: z.ZodEnum<{
78
+ read: "read";
79
+ write: "write";
80
+ admin: "admin";
81
+ }>;
82
+ version: z.ZodString;
83
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
84
+ examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
85
+ description: z.ZodString;
86
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
87
+ output: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
88
+ }, z.core.$strip>>>;
89
+ deprecated: z.ZodOptional<z.ZodBoolean>;
90
+ replacedBy: z.ZodOptional<z.ZodString>;
91
+ }, z.core.$strip>;
92
+ export type ToolMetadata = z.infer<typeof ToolMetadataSchema>;
93
+ /**
94
+ * Schema for tool definition
95
+ *
96
+ * Complete tool specification including metadata, schemas, and execution function.
97
+ */
98
+ export declare const ToolDefinitionSchema: z.ZodObject<{
99
+ metadata: z.ZodObject<{
100
+ name: z.ZodString;
101
+ description: z.ZodString;
102
+ domain: z.ZodEnum<{
103
+ git: "git";
104
+ test: "test";
105
+ file: "file";
106
+ wu: "wu";
107
+ initiative: "initiative";
108
+ docs: "docs";
109
+ security: "security";
110
+ explore: "explore";
111
+ db: "db";
112
+ metrics: "metrics";
113
+ orchestration: "orchestration";
114
+ util: "util";
115
+ }>;
116
+ permission: z.ZodEnum<{
117
+ read: "read";
118
+ write: "write";
119
+ admin: "admin";
120
+ }>;
121
+ version: z.ZodString;
122
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
123
+ examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
124
+ description: z.ZodString;
125
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
126
+ output: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
127
+ }, z.core.$strip>>>;
128
+ deprecated: z.ZodOptional<z.ZodBoolean>;
129
+ replacedBy: z.ZodOptional<z.ZodString>;
130
+ }, z.core.$strip>;
131
+ inputSchema: z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
132
+ outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
133
+ execute: z.ZodCustom<(input: any, context?: Record<string, unknown>) => Promise<ToolOutput>, (input: any, context?: Record<string, unknown>) => Promise<ToolOutput>>;
134
+ }, z.core.$strip>;
135
+ export type ToolDefinition = z.infer<typeof ToolDefinitionSchema>;
136
+ /**
137
+ * Schema for tool execution result (audit logging)
138
+ */
139
+ export declare const ToolExecutionResultSchema: z.ZodObject<{
140
+ tool: z.ZodString;
141
+ status: z.ZodEnum<{
142
+ cancelled: "cancelled";
143
+ success: "success";
144
+ timeout: "timeout";
145
+ failed: "failed";
146
+ pending: "pending";
147
+ running: "running";
148
+ }>;
149
+ startedAt: z.ZodString;
150
+ completedAt: z.ZodOptional<z.ZodString>;
151
+ durationMs: z.ZodOptional<z.ZodNumber>;
152
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
153
+ output: z.ZodOptional<z.ZodObject<{
154
+ success: z.ZodBoolean;
155
+ data: z.ZodOptional<z.ZodUnknown>;
156
+ error: z.ZodOptional<z.ZodObject<{
157
+ code: z.ZodString;
158
+ message: z.ZodString;
159
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
160
+ stack: z.ZodOptional<z.ZodString>;
161
+ tryNext: z.ZodOptional<z.ZodArray<z.ZodString>>;
162
+ }, z.core.$strip>>;
163
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
164
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
165
+ }, z.core.$strip>>;
166
+ error: z.ZodOptional<z.ZodObject<{
167
+ code: z.ZodString;
168
+ message: z.ZodString;
169
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
170
+ stack: z.ZodOptional<z.ZodString>;
171
+ tryNext: z.ZodOptional<z.ZodArray<z.ZodString>>;
172
+ }, z.core.$strip>>;
173
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
174
+ }, z.core.$strip>;
175
+ export type ToolExecutionResult = z.infer<typeof ToolExecutionResultSchema>;
176
+ /**
177
+ * Convert Zod schema to JSON Schema for provider adapters
178
+ *
179
+ * Uses Zod 4's native z.toJSONSchema() for robust conversion.
180
+ * Supports MCP, OpenAI Functions, and Gemini Tools formats.
181
+ *
182
+ * @param schema - Zod schema to convert
183
+ * @param options - Conversion options
184
+ * @returns JSON Schema object
185
+ *
186
+ * @example
187
+ * const inputSchema = z.object({ id: z.string() });
188
+ * const jsonSchema = toJSONSchema(inputSchema);
189
+ * // Returns: { type: 'object', properties: { id: { type: 'string' } }, ... }
190
+ */
191
+ export declare function toJSONSchema(schema: ZodTypeAny, options?: {
192
+ /** Schema name (for $id field) */
193
+ name?: string;
194
+ /** Base URI for schema references */
195
+ baseUri?: string;
196
+ }): Record<string, unknown>;
197
+ /**
198
+ * Validate tool input against schema
199
+ *
200
+ * @param input - Tool input to validate
201
+ * @param schema - Zod schema to validate against
202
+ * @returns Validation result with parsed data or errors
203
+ */
204
+ export declare function validateToolInput<T>(input: unknown, schema: z.ZodType<T>): {
205
+ success: true;
206
+ data: T;
207
+ } | {
208
+ success: false;
209
+ error: z.ZodError;
210
+ };
211
+ /**
212
+ * Create standardized tool output for success case
213
+ *
214
+ * @param data - Output data
215
+ * @param metadata - Optional execution metadata
216
+ * @returns Standardized ToolOutput
217
+ */
218
+ export declare function createSuccessOutput(data: unknown, metadata?: Record<string, unknown>): ToolOutput;
219
+ /**
220
+ * Create standardized tool output for error case
221
+ *
222
+ * @param error - Error details
223
+ * @param metadata - Optional execution metadata
224
+ * @returns Standardized ToolOutput
225
+ */
226
+ export declare function createErrorOutput(error: ToolError, metadata?: Record<string, unknown>): ToolOutput;
@@ -0,0 +1,226 @@
1
+ /**
2
+ * @file tool.schemas.ts
3
+ * @description Zod schemas for tool abstraction layer (WU-1394)
4
+ *
5
+ * Provides runtime validation and TypeScript type inference for tool inputs,
6
+ * outputs, and metadata. Supports JSON Schema export for provider adapters
7
+ * (MCP, OpenAI, Gemini).
8
+ *
9
+ * Reference: tools/lib/arg-parser.mjs for current argument handling patterns
10
+ */
11
+ import { z } from 'zod';
12
+ import { TOOL_DOMAINS, PERMISSION_LEVELS, TOOL_STATUS, } from './tool.constants.js';
13
+ /**
14
+ * Schema for tool input
15
+ *
16
+ * Represents the standardized input format for all tools in the system.
17
+ * Maps command names to their arguments and optional context.
18
+ */
19
+ export const ToolInputSchema = z.object({
20
+ /** Tool command name (e.g., 'wu:claim', 'git:commit') */
21
+ command: z.string().min(1).describe('Tool command name'),
22
+ /** Tool-specific arguments (validated by tool's inputSchema) */
23
+ arguments: z.record(z.string(), z.unknown()).default({}),
24
+ /** Optional execution context (session ID, user, etc.) */
25
+ context: z
26
+ .record(z.string(), z.unknown())
27
+ .optional()
28
+ .describe('Execution context (session_id, user, etc.)'),
29
+ });
30
+ /**
31
+ * Schema for tool error details
32
+ */
33
+ export const ToolErrorSchema = z.object({
34
+ /** Error code from TOOL_ERROR_CODES or ErrorCodes */
35
+ code: z.string(),
36
+ /** Human-readable error message */
37
+ message: z.string(),
38
+ /** Optional additional error details */
39
+ details: z.record(z.string(), z.unknown()).optional(),
40
+ /** Optional stack trace (for debugging) */
41
+ stack: z.string().optional(),
42
+ /** Optional suggestions for resolution (WU-1339: Agent-friendly errors) */
43
+ tryNext: z.array(z.string()).optional().describe('Suggested next actions'),
44
+ });
45
+ /**
46
+ * Schema for tool output
47
+ *
48
+ * Standardized response format for all tools. Success/failure indicated by
49
+ * the `success` field, with data/error fields providing details.
50
+ */
51
+ export const ToolOutputSchema = z.object({
52
+ /** Operation success status */
53
+ success: z.boolean(),
54
+ /** Output data (present when success=true) */
55
+ data: z.unknown().optional(),
56
+ /** Error details (present when success=false) */
57
+ error: ToolErrorSchema.optional(),
58
+ /** Optional warning messages */
59
+ warnings: z.array(z.string()).optional(),
60
+ /** Optional execution metadata (duration, timestamp, etc.) */
61
+ metadata: z.record(z.string(), z.unknown()).optional(),
62
+ });
63
+ /**
64
+ * Schema for tool metadata
65
+ *
66
+ * Describes a tool's capabilities, domain, permissions, and usage examples.
67
+ */
68
+ export const ToolMetadataSchema = z.object({
69
+ /** Tool name (unique identifier) */
70
+ name: z.string().min(1),
71
+ /** Human-readable description */
72
+ description: z.string().min(1),
73
+ /** Tool domain classification */
74
+ domain: z.enum([
75
+ TOOL_DOMAINS.WU,
76
+ TOOL_DOMAINS.GIT,
77
+ TOOL_DOMAINS.FILE,
78
+ TOOL_DOMAINS.EXPLORE,
79
+ TOOL_DOMAINS.TEST,
80
+ TOOL_DOMAINS.DB,
81
+ TOOL_DOMAINS.SECURITY,
82
+ TOOL_DOMAINS.INITIATIVE,
83
+ TOOL_DOMAINS.METRICS,
84
+ TOOL_DOMAINS.ORCHESTRATION,
85
+ TOOL_DOMAINS.DOCS,
86
+ TOOL_DOMAINS.UTIL,
87
+ ]),
88
+ /** Required permission level */
89
+ permission: z.enum([
90
+ PERMISSION_LEVELS.READ,
91
+ PERMISSION_LEVELS.WRITE,
92
+ PERMISSION_LEVELS.ADMIN,
93
+ ]),
94
+ /** Tool version (semantic versioning) */
95
+ version: z.string().regex(/^\d+\.\d+\.\d+$/, 'Must be semantic version (x.y.z)'),
96
+ /** Optional tags for categorization */
97
+ tags: z.array(z.string()).optional(),
98
+ /** Optional usage examples */
99
+ examples: z
100
+ .array(z.object({
101
+ description: z.string(),
102
+ input: z.record(z.string(), z.unknown()),
103
+ output: z.record(z.string(), z.unknown()).optional(),
104
+ }))
105
+ .optional(),
106
+ /** Optional deprecation notice */
107
+ deprecated: z.boolean().optional(),
108
+ /** Optional replacement tool (if deprecated) */
109
+ replacedBy: z.string().optional(),
110
+ });
111
+ /**
112
+ * Schema for tool definition
113
+ *
114
+ * Complete tool specification including metadata, schemas, and execution function.
115
+ */
116
+ export const ToolDefinitionSchema = z.object({
117
+ /** Tool metadata */
118
+ metadata: ToolMetadataSchema,
119
+ /** Input schema (Zod schema for argument validation) */
120
+ inputSchema: z.custom((val) => val instanceof z.ZodType),
121
+ /** Optional output schema (Zod schema for response validation) */
122
+ outputSchema: z.custom((val) => val instanceof z.ZodType).optional(),
123
+ /** Tool execution function */
124
+ execute: z.custom((val) => typeof val === 'function'),
125
+ });
126
+ /**
127
+ * Schema for tool execution result (audit logging)
128
+ */
129
+ export const ToolExecutionResultSchema = z.object({
130
+ /** Tool name */
131
+ tool: z.string(),
132
+ /** Execution status */
133
+ status: z.enum([
134
+ TOOL_STATUS.PENDING,
135
+ TOOL_STATUS.RUNNING,
136
+ TOOL_STATUS.SUCCESS,
137
+ TOOL_STATUS.FAILED,
138
+ TOOL_STATUS.TIMEOUT,
139
+ TOOL_STATUS.CANCELLED,
140
+ ]),
141
+ /** Start timestamp */
142
+ startedAt: z.string().datetime(),
143
+ /** End timestamp */
144
+ completedAt: z.string().datetime().optional(),
145
+ /** Execution duration in milliseconds */
146
+ durationMs: z.number().int().nonnegative().optional(),
147
+ /** Tool input (sanitized, no sensitive data) */
148
+ input: z.record(z.string(), z.unknown()),
149
+ /** Tool output (sanitized) */
150
+ output: ToolOutputSchema.optional(),
151
+ /** Error details (if failed) */
152
+ error: ToolErrorSchema.optional(),
153
+ /** Execution context (session, user, etc.) */
154
+ context: z.record(z.string(), z.unknown()).optional(),
155
+ });
156
+ /**
157
+ * Convert Zod schema to JSON Schema for provider adapters
158
+ *
159
+ * Uses Zod 4's native z.toJSONSchema() for robust conversion.
160
+ * Supports MCP, OpenAI Functions, and Gemini Tools formats.
161
+ *
162
+ * @param schema - Zod schema to convert
163
+ * @param options - Conversion options
164
+ * @returns JSON Schema object
165
+ *
166
+ * @example
167
+ * const inputSchema = z.object({ id: z.string() });
168
+ * const jsonSchema = toJSONSchema(inputSchema);
169
+ * // Returns: { type: 'object', properties: { id: { type: 'string' } }, ... }
170
+ */
171
+ export function toJSONSchema(schema, options) {
172
+ // Use Zod 4's native JSON Schema conversion
173
+ const jsonSchema = z.toJSONSchema(schema);
174
+ // Add $id if name is provided
175
+ if (options?.name) {
176
+ return {
177
+ ...jsonSchema,
178
+ $id: `${options.baseUri || ''}#/${options.name}`,
179
+ };
180
+ }
181
+ return jsonSchema;
182
+ }
183
+ /**
184
+ * Validate tool input against schema
185
+ *
186
+ * @param input - Tool input to validate
187
+ * @param schema - Zod schema to validate against
188
+ * @returns Validation result with parsed data or errors
189
+ */
190
+ export function validateToolInput(input, schema) {
191
+ const result = schema.safeParse(input);
192
+ if (result.success) {
193
+ return { success: true, data: result.data };
194
+ }
195
+ else {
196
+ return { success: false, error: result.error };
197
+ }
198
+ }
199
+ /**
200
+ * Create standardized tool output for success case
201
+ *
202
+ * @param data - Output data
203
+ * @param metadata - Optional execution metadata
204
+ * @returns Standardized ToolOutput
205
+ */
206
+ export function createSuccessOutput(data, metadata) {
207
+ return {
208
+ success: true,
209
+ data,
210
+ metadata,
211
+ };
212
+ }
213
+ /**
214
+ * Create standardized tool output for error case
215
+ *
216
+ * @param error - Error details
217
+ * @param metadata - Optional execution metadata
218
+ * @returns Standardized ToolOutput
219
+ */
220
+ export function createErrorOutput(error, metadata) {
221
+ return {
222
+ success: false,
223
+ error,
224
+ metadata,
225
+ };
226
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @file worktree-guard.mjs
3
+ * @description WU context validation and main branch protection (WU-1396)
4
+ *
5
+ * Provides runtime guards to enforce worktree discipline:
6
+ * - Detect if current directory is inside a worktree
7
+ * - Extract WU ID and lane from worktree path or git branch
8
+ * - Throw descriptive error when write operations attempted outside worktree
9
+ * - Check if on main/master branch
10
+ *
11
+ * Used by wu- scripts to prevent writes to main checkout when worktrees exist.
12
+ * Complements .claude/hooks/user-prompt-submit-hook (human agent protection).
13
+ *
14
+ * @see {@link .claude/hooks/user-prompt-submit-hook} - Agent blocking hook
15
+ * @see {@link docs/04-operations/_frameworks/lumenflow/lumenflow-complete.md} - Worktree discipline
16
+ */
17
+ /**
18
+ * Git adapter interface for worktree operations
19
+ */
20
+ interface GitAdapter {
21
+ getCurrentBranch(): Promise<string>;
22
+ }
23
+ /**
24
+ * Options with git adapter
25
+ */
26
+ interface GitOptions {
27
+ /** GitAdapter instance (for testing) */
28
+ git?: GitAdapter;
29
+ }
30
+ /**
31
+ * Options for isInWorktree
32
+ */
33
+ interface CwdOptions {
34
+ /** Current working directory (defaults to process.cwd()) */
35
+ cwd?: string;
36
+ }
37
+ /**
38
+ * Combined options for context functions
39
+ */
40
+ interface WorktreeContextOptions extends GitOptions, CwdOptions {
41
+ /** Operation name for error message */
42
+ operation?: string;
43
+ }
44
+ /**
45
+ * Check if on main or master branch
46
+ *
47
+ * @param {GitOptions} [options] - Options
48
+ * @returns {Promise<boolean>} True if on main/master branch
49
+ *
50
+ * @example
51
+ * if (await isMainBranch()) {
52
+ * console.log('On main branch');
53
+ * }
54
+ */
55
+ export declare function isMainBranch(options?: GitOptions): Promise<boolean>;
56
+ /**
57
+ * Check if current directory is inside a worktree
58
+ *
59
+ * Detects worktree by checking if path contains worktrees/<lane>-wu-<id> pattern.
60
+ * Works correctly from nested directories within worktree.
61
+ *
62
+ * @param {Object} [options] - Options
63
+ * @param {string} [options.cwd] - Current working directory (defaults to process.cwd())
64
+ * @returns {boolean} True if inside a worktree directory
65
+ *
66
+ * @example
67
+ * if (isInWorktree()) {
68
+ * console.log('Working in a worktree');
69
+ * }
70
+ *
71
+ * // From nested directory
72
+ * isInWorktree({ cwd: '/project/worktrees/operations-wu-123/tools/lib' }); // true
73
+ */
74
+ export declare function isInWorktree(options?: CwdOptions): boolean;
75
+ /**
76
+ * Get WU context from current directory or git branch
77
+ *
78
+ * Extracts WU ID, lane, and worktree path from:
79
+ * 1. Worktree directory path (priority) - works from nested directories
80
+ * 2. Git branch name (fallback) - lane/operations-tooling/wu-1396
81
+ *
82
+ * @param {Object} [options] - Options
83
+ * @param {string} [options.cwd] - Current working directory (defaults to process.cwd())
84
+ * @param {Object} [options.git] - GitAdapter instance (for testing)
85
+ * @returns {Promise<Object|null>} WU context or null if not in WU workspace
86
+ *
87
+ * @example
88
+ * // From worktree
89
+ * const ctx = await getWUContext();
90
+ * // { wuId: 'WU-1396', lane: 'operations-tooling', worktreePath: 'worktrees/operations-tooling-wu-1396' }
91
+ *
92
+ * // From lane branch (not in worktree)
93
+ * const ctx = await getWUContext();
94
+ * // { wuId: 'WU-1396', lane: 'operations-tooling', worktreePath: null }
95
+ *
96
+ * // From main checkout on main branch
97
+ * const ctx = await getWUContext();
98
+ * // null
99
+ */
100
+ export declare function getWUContext(options?: WorktreeContextOptions): Promise<{
101
+ wuId: string;
102
+ lane: any;
103
+ worktreePath: any;
104
+ }>;
105
+ /**
106
+ * Assert that current context is inside a worktree or on a lane branch
107
+ *
108
+ * Throws descriptive error if:
109
+ * - On main/master branch AND
110
+ * - Not in a worktree directory
111
+ *
112
+ * Used by write operations to prevent modifications to main checkout.
113
+ *
114
+ * @param {Object} [options] - Options
115
+ * @param {string} [options.cwd] - Current working directory (defaults to process.cwd())
116
+ * @param {Object} [options.git] - GitAdapter instance (for testing)
117
+ * @param {string} [options.operation] - Operation name for error message
118
+ * @throws {Error} If not in worktree and on main branch
119
+ *
120
+ * @example
121
+ * // In a wu- script write operation
122
+ * await assertWorktreeRequired({ operation: 'wu:claim' });
123
+ *
124
+ * // Will throw if on main in main checkout:
125
+ * // Error: BLOCKED: Operation 'wu:claim' requires a worktree.
126
+ * // You are on 'main' branch in main checkout.
127
+ * // ...
128
+ */
129
+ export declare function assertWorktreeRequired(options?: WorktreeContextOptions): Promise<void>;
130
+ export {};