groundswell 0.0.3 → 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 (292) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -9
  3. package/dist/cache/cache-key.d.ts +20 -0
  4. package/dist/cache/cache-key.d.ts.map +1 -1
  5. package/dist/cache/cache-key.js +9 -0
  6. package/dist/cache/cache-key.js.map +1 -1
  7. package/dist/core/agent.d.ts +120 -29
  8. package/dist/core/agent.d.ts.map +1 -1
  9. package/dist/core/agent.js +584 -177
  10. package/dist/core/agent.js.map +1 -1
  11. package/dist/core/mcp-handler.d.ts +63 -5
  12. package/dist/core/mcp-handler.d.ts.map +1 -1
  13. package/dist/core/mcp-handler.js +184 -4
  14. package/dist/core/mcp-handler.js.map +1 -1
  15. package/dist/core/workflow-context.d.ts +6 -2
  16. package/dist/core/workflow-context.d.ts.map +1 -1
  17. package/dist/core/workflow-context.js +99 -4
  18. package/dist/core/workflow-context.js.map +1 -1
  19. package/dist/core/workflow.d.ts +315 -13
  20. package/dist/core/workflow.d.ts.map +1 -1
  21. package/dist/core/workflow.js +552 -30
  22. package/dist/core/workflow.js.map +1 -1
  23. package/dist/debugger/event-replayer.d.ts +422 -0
  24. package/dist/debugger/event-replayer.d.ts.map +1 -0
  25. package/dist/debugger/event-replayer.js +639 -0
  26. package/dist/debugger/event-replayer.js.map +1 -0
  27. package/dist/debugger/tree-debugger.d.ts +170 -1
  28. package/dist/debugger/tree-debugger.d.ts.map +1 -1
  29. package/dist/debugger/tree-debugger.js +423 -1
  30. package/dist/debugger/tree-debugger.js.map +1 -1
  31. package/dist/decorators/step.d.ts.map +1 -1
  32. package/dist/decorators/step.js +129 -47
  33. package/dist/decorators/step.js.map +1 -1
  34. package/dist/harnesses/claude-code-harness.d.ts +391 -0
  35. package/dist/harnesses/claude-code-harness.d.ts.map +1 -0
  36. package/dist/harnesses/claude-code-harness.js +1076 -0
  37. package/dist/harnesses/claude-code-harness.js.map +1 -0
  38. package/dist/harnesses/harness-registry.d.ts +440 -0
  39. package/dist/harnesses/harness-registry.d.ts.map +1 -0
  40. package/dist/harnesses/harness-registry.js +543 -0
  41. package/dist/harnesses/harness-registry.js.map +1 -0
  42. package/dist/harnesses/index.d.ts +12 -0
  43. package/dist/harnesses/index.d.ts.map +1 -0
  44. package/dist/harnesses/index.js +11 -0
  45. package/dist/harnesses/index.js.map +1 -0
  46. package/dist/harnesses/pi-harness.d.ts +219 -0
  47. package/dist/harnesses/pi-harness.d.ts.map +1 -0
  48. package/dist/harnesses/pi-harness.js +676 -0
  49. package/dist/harnesses/pi-harness.js.map +1 -0
  50. package/dist/harnesses/pi-schema-converter.d.ts +24 -0
  51. package/dist/harnesses/pi-schema-converter.d.ts.map +1 -0
  52. package/dist/harnesses/pi-schema-converter.js +81 -0
  53. package/dist/harnesses/pi-schema-converter.js.map +1 -0
  54. package/dist/harnesses/register-defaults.d.ts +24 -0
  55. package/dist/harnesses/register-defaults.d.ts.map +1 -0
  56. package/dist/harnesses/register-defaults.js +40 -0
  57. package/dist/harnesses/register-defaults.js.map +1 -0
  58. package/dist/harnesses/session-store.d.ts +201 -0
  59. package/dist/harnesses/session-store.d.ts.map +1 -0
  60. package/dist/harnesses/session-store.js +254 -0
  61. package/dist/harnesses/session-store.js.map +1 -0
  62. package/dist/index.d.ts +12 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +17 -0
  65. package/dist/index.js.map +1 -1
  66. package/dist/reflection/reflection.d.ts.map +1 -1
  67. package/dist/reflection/reflection.js +19 -4
  68. package/dist/reflection/reflection.js.map +1 -1
  69. package/dist/types/agent.d.ts +1253 -2
  70. package/dist/types/agent.d.ts.map +1 -1
  71. package/dist/types/agent.js +418 -1
  72. package/dist/types/agent.js.map +1 -1
  73. package/dist/types/decorators.d.ts +10 -1
  74. package/dist/types/decorators.d.ts.map +1 -1
  75. package/dist/types/events.d.ts +26 -0
  76. package/dist/types/events.d.ts.map +1 -1
  77. package/dist/types/harnesses.d.ts +474 -0
  78. package/dist/types/harnesses.d.ts.map +1 -0
  79. package/dist/types/harnesses.js +2 -0
  80. package/dist/types/harnesses.js.map +1 -0
  81. package/dist/types/index.d.ts +9 -1
  82. package/dist/types/index.d.ts.map +1 -1
  83. package/dist/types/index.js +6 -0
  84. package/dist/types/index.js.map +1 -1
  85. package/dist/types/providers.d.ts +691 -0
  86. package/dist/types/providers.d.ts.map +1 -0
  87. package/dist/types/providers.js +14 -0
  88. package/dist/types/providers.js.map +1 -0
  89. package/dist/types/restart.d.ts +132 -0
  90. package/dist/types/restart.d.ts.map +1 -0
  91. package/dist/types/restart.js +2 -0
  92. package/dist/types/restart.js.map +1 -0
  93. package/dist/types/streaming.d.ts +194 -0
  94. package/dist/types/streaming.d.ts.map +1 -0
  95. package/dist/types/streaming.js +67 -0
  96. package/dist/types/streaming.js.map +1 -0
  97. package/dist/types/workflow-context.d.ts +137 -1
  98. package/dist/types/workflow-context.d.ts.map +1 -1
  99. package/dist/utils/agent-validation.d.ts +88 -0
  100. package/dist/utils/agent-validation.d.ts.map +1 -0
  101. package/dist/utils/agent-validation.js +87 -0
  102. package/dist/utils/agent-validation.js.map +1 -0
  103. package/dist/utils/delay.d.ts +7 -0
  104. package/dist/utils/delay.d.ts.map +1 -0
  105. package/dist/utils/delay.js +9 -0
  106. package/dist/utils/delay.js.map +1 -0
  107. package/dist/utils/harness-config.d.ts +180 -0
  108. package/dist/utils/harness-config.d.ts.map +1 -0
  109. package/dist/utils/harness-config.js +311 -0
  110. package/dist/utils/harness-config.js.map +1 -0
  111. package/dist/utils/index.d.ts +9 -1
  112. package/dist/utils/index.d.ts.map +1 -1
  113. package/dist/utils/index.js +8 -1
  114. package/dist/utils/index.js.map +1 -1
  115. package/dist/utils/model-spec.d.ts +110 -0
  116. package/dist/utils/model-spec.d.ts.map +1 -0
  117. package/dist/utils/model-spec.js +149 -0
  118. package/dist/utils/model-spec.js.map +1 -0
  119. package/dist/utils/provider-config.d.ts +10 -0
  120. package/dist/utils/provider-config.d.ts.map +1 -0
  121. package/dist/utils/provider-config.js +10 -0
  122. package/dist/utils/provider-config.js.map +1 -0
  123. package/dist/utils/restart-analysis.d.ts +202 -0
  124. package/dist/utils/restart-analysis.d.ts.map +1 -0
  125. package/dist/utils/restart-analysis.js +426 -0
  126. package/dist/utils/restart-analysis.js.map +1 -0
  127. package/dist/utils/session-serialization.d.ts +118 -0
  128. package/dist/utils/session-serialization.d.ts.map +1 -0
  129. package/dist/utils/session-serialization.js +217 -0
  130. package/dist/utils/session-serialization.js.map +1 -0
  131. package/package.json +31 -5
  132. package/CHANGELOG.md +0 -188
  133. package/dist/__tests__/adversarial/attachChild-performance.test.d.ts +0 -16
  134. package/dist/__tests__/adversarial/attachChild-performance.test.d.ts.map +0 -1
  135. package/dist/__tests__/adversarial/attachChild-performance.test.js +0 -187
  136. package/dist/__tests__/adversarial/attachChild-performance.test.js.map +0 -1
  137. package/dist/__tests__/adversarial/circular-reference.test.d.ts +0 -13
  138. package/dist/__tests__/adversarial/circular-reference.test.d.ts.map +0 -1
  139. package/dist/__tests__/adversarial/circular-reference.test.js +0 -92
  140. package/dist/__tests__/adversarial/circular-reference.test.js.map +0 -1
  141. package/dist/__tests__/adversarial/complex-circular-reference.test.d.ts +0 -16
  142. package/dist/__tests__/adversarial/complex-circular-reference.test.d.ts.map +0 -1
  143. package/dist/__tests__/adversarial/complex-circular-reference.test.js +0 -127
  144. package/dist/__tests__/adversarial/complex-circular-reference.test.js.map +0 -1
  145. package/dist/__tests__/adversarial/concurrent-task-failures.test.d.ts +0 -21
  146. package/dist/__tests__/adversarial/concurrent-task-failures.test.d.ts.map +0 -1
  147. package/dist/__tests__/adversarial/concurrent-task-failures.test.js +0 -667
  148. package/dist/__tests__/adversarial/concurrent-task-failures.test.js.map +0 -1
  149. package/dist/__tests__/adversarial/deep-analysis.test.d.ts +0 -6
  150. package/dist/__tests__/adversarial/deep-analysis.test.d.ts.map +0 -1
  151. package/dist/__tests__/adversarial/deep-analysis.test.js +0 -877
  152. package/dist/__tests__/adversarial/deep-analysis.test.js.map +0 -1
  153. package/dist/__tests__/adversarial/deep-hierarchy-stress.test.d.ts +0 -13
  154. package/dist/__tests__/adversarial/deep-hierarchy-stress.test.d.ts.map +0 -1
  155. package/dist/__tests__/adversarial/deep-hierarchy-stress.test.js +0 -186
  156. package/dist/__tests__/adversarial/deep-hierarchy-stress.test.js.map +0 -1
  157. package/dist/__tests__/adversarial/e2e-prd-validation.test.d.ts +0 -6
  158. package/dist/__tests__/adversarial/e2e-prd-validation.test.d.ts.map +0 -1
  159. package/dist/__tests__/adversarial/e2e-prd-validation.test.js +0 -626
  160. package/dist/__tests__/adversarial/e2e-prd-validation.test.js.map +0 -1
  161. package/dist/__tests__/adversarial/edge-case.test.d.ts +0 -6
  162. package/dist/__tests__/adversarial/edge-case.test.d.ts.map +0 -1
  163. package/dist/__tests__/adversarial/edge-case.test.js +0 -857
  164. package/dist/__tests__/adversarial/edge-case.test.js.map +0 -1
  165. package/dist/__tests__/adversarial/error-merge-strategy.test.d.ts +0 -20
  166. package/dist/__tests__/adversarial/error-merge-strategy.test.d.ts.map +0 -1
  167. package/dist/__tests__/adversarial/error-merge-strategy.test.js +0 -907
  168. package/dist/__tests__/adversarial/error-merge-strategy.test.js.map +0 -1
  169. package/dist/__tests__/adversarial/incremental-performance.test.d.ts +0 -2
  170. package/dist/__tests__/adversarial/incremental-performance.test.d.ts.map +0 -1
  171. package/dist/__tests__/adversarial/incremental-performance.test.js +0 -113
  172. package/dist/__tests__/adversarial/incremental-performance.test.js.map +0 -1
  173. package/dist/__tests__/adversarial/node-map-update-benchmarks.test.d.ts +0 -22
  174. package/dist/__tests__/adversarial/node-map-update-benchmarks.test.d.ts.map +0 -1
  175. package/dist/__tests__/adversarial/node-map-update-benchmarks.test.js +0 -383
  176. package/dist/__tests__/adversarial/node-map-update-benchmarks.test.js.map +0 -1
  177. package/dist/__tests__/adversarial/observer-propagation.test.d.ts +0 -21
  178. package/dist/__tests__/adversarial/observer-propagation.test.d.ts.map +0 -1
  179. package/dist/__tests__/adversarial/observer-propagation.test.js +0 -404
  180. package/dist/__tests__/adversarial/observer-propagation.test.js.map +0 -1
  181. package/dist/__tests__/adversarial/parent-validation.test.d.ts +0 -13
  182. package/dist/__tests__/adversarial/parent-validation.test.d.ts.map +0 -1
  183. package/dist/__tests__/adversarial/parent-validation.test.js +0 -128
  184. package/dist/__tests__/adversarial/parent-validation.test.js.map +0 -1
  185. package/dist/__tests__/adversarial/prd-12-2-compliance.test.d.ts +0 -20
  186. package/dist/__tests__/adversarial/prd-12-2-compliance.test.d.ts.map +0 -1
  187. package/dist/__tests__/adversarial/prd-12-2-compliance.test.js +0 -482
  188. package/dist/__tests__/adversarial/prd-12-2-compliance.test.js.map +0 -1
  189. package/dist/__tests__/adversarial/prd-compliance.test.d.ts +0 -6
  190. package/dist/__tests__/adversarial/prd-compliance.test.d.ts.map +0 -1
  191. package/dist/__tests__/adversarial/prd-compliance.test.js +0 -886
  192. package/dist/__tests__/adversarial/prd-compliance.test.js.map +0 -1
  193. package/dist/__tests__/compatibility/backward-compatibility.test.d.ts +0 -22
  194. package/dist/__tests__/compatibility/backward-compatibility.test.d.ts.map +0 -1
  195. package/dist/__tests__/compatibility/backward-compatibility.test.js +0 -1843
  196. package/dist/__tests__/compatibility/backward-compatibility.test.js.map +0 -1
  197. package/dist/__tests__/helpers/index.d.ts +0 -10
  198. package/dist/__tests__/helpers/index.d.ts.map +0 -1
  199. package/dist/__tests__/helpers/index.js +0 -10
  200. package/dist/__tests__/helpers/index.js.map +0 -1
  201. package/dist/__tests__/helpers/tree-verification.d.ts +0 -90
  202. package/dist/__tests__/helpers/tree-verification.d.ts.map +0 -1
  203. package/dist/__tests__/helpers/tree-verification.js +0 -202
  204. package/dist/__tests__/helpers/tree-verification.js.map +0 -1
  205. package/dist/__tests__/integration/agent-workflow.test.d.ts +0 -2
  206. package/dist/__tests__/integration/agent-workflow.test.d.ts.map +0 -1
  207. package/dist/__tests__/integration/agent-workflow.test.js +0 -256
  208. package/dist/__tests__/integration/agent-workflow.test.js.map +0 -1
  209. package/dist/__tests__/integration/bidirectional-consistency.test.d.ts +0 -14
  210. package/dist/__tests__/integration/bidirectional-consistency.test.d.ts.map +0 -1
  211. package/dist/__tests__/integration/bidirectional-consistency.test.js +0 -668
  212. package/dist/__tests__/integration/bidirectional-consistency.test.js.map +0 -1
  213. package/dist/__tests__/integration/observer-logging.test.d.ts +0 -2
  214. package/dist/__tests__/integration/observer-logging.test.d.ts.map +0 -1
  215. package/dist/__tests__/integration/observer-logging.test.js +0 -517
  216. package/dist/__tests__/integration/observer-logging.test.js.map +0 -1
  217. package/dist/__tests__/integration/tree-mirroring.test.d.ts +0 -2
  218. package/dist/__tests__/integration/tree-mirroring.test.d.ts.map +0 -1
  219. package/dist/__tests__/integration/tree-mirroring.test.js +0 -117
  220. package/dist/__tests__/integration/tree-mirroring.test.js.map +0 -1
  221. package/dist/__tests__/integration/workflow-reparenting.test.d.ts +0 -12
  222. package/dist/__tests__/integration/workflow-reparenting.test.d.ts.map +0 -1
  223. package/dist/__tests__/integration/workflow-reparenting.test.js +0 -239
  224. package/dist/__tests__/integration/workflow-reparenting.test.js.map +0 -1
  225. package/dist/__tests__/unit/agent.test.d.ts +0 -2
  226. package/dist/__tests__/unit/agent.test.d.ts.map +0 -1
  227. package/dist/__tests__/unit/agent.test.js +0 -143
  228. package/dist/__tests__/unit/agent.test.js.map +0 -1
  229. package/dist/__tests__/unit/cache-key.test.d.ts +0 -5
  230. package/dist/__tests__/unit/cache-key.test.d.ts.map +0 -1
  231. package/dist/__tests__/unit/cache-key.test.js +0 -145
  232. package/dist/__tests__/unit/cache-key.test.js.map +0 -1
  233. package/dist/__tests__/unit/cache.test.d.ts +0 -5
  234. package/dist/__tests__/unit/cache.test.d.ts.map +0 -1
  235. package/dist/__tests__/unit/cache.test.js +0 -132
  236. package/dist/__tests__/unit/cache.test.js.map +0 -1
  237. package/dist/__tests__/unit/context.test.d.ts +0 -2
  238. package/dist/__tests__/unit/context.test.d.ts.map +0 -1
  239. package/dist/__tests__/unit/context.test.js +0 -220
  240. package/dist/__tests__/unit/context.test.js.map +0 -1
  241. package/dist/__tests__/unit/decorators.test.d.ts +0 -2
  242. package/dist/__tests__/unit/decorators.test.d.ts.map +0 -1
  243. package/dist/__tests__/unit/decorators.test.js +0 -162
  244. package/dist/__tests__/unit/decorators.test.js.map +0 -1
  245. package/dist/__tests__/unit/introspection-tools.test.d.ts +0 -5
  246. package/dist/__tests__/unit/introspection-tools.test.d.ts.map +0 -1
  247. package/dist/__tests__/unit/introspection-tools.test.js +0 -191
  248. package/dist/__tests__/unit/introspection-tools.test.js.map +0 -1
  249. package/dist/__tests__/unit/logger.test.d.ts +0 -2
  250. package/dist/__tests__/unit/logger.test.d.ts.map +0 -1
  251. package/dist/__tests__/unit/logger.test.js +0 -241
  252. package/dist/__tests__/unit/logger.test.js.map +0 -1
  253. package/dist/__tests__/unit/observable.test.d.ts +0 -2
  254. package/dist/__tests__/unit/observable.test.d.ts.map +0 -1
  255. package/dist/__tests__/unit/observable.test.js +0 -251
  256. package/dist/__tests__/unit/observable.test.js.map +0 -1
  257. package/dist/__tests__/unit/prompt.test.d.ts +0 -2
  258. package/dist/__tests__/unit/prompt.test.d.ts.map +0 -1
  259. package/dist/__tests__/unit/prompt.test.js +0 -113
  260. package/dist/__tests__/unit/prompt.test.js.map +0 -1
  261. package/dist/__tests__/unit/reflection.test.d.ts +0 -5
  262. package/dist/__tests__/unit/reflection.test.d.ts.map +0 -1
  263. package/dist/__tests__/unit/reflection.test.js +0 -160
  264. package/dist/__tests__/unit/reflection.test.js.map +0 -1
  265. package/dist/__tests__/unit/tree-debugger-incremental.test.d.ts +0 -2
  266. package/dist/__tests__/unit/tree-debugger-incremental.test.d.ts.map +0 -1
  267. package/dist/__tests__/unit/tree-debugger-incremental.test.js +0 -136
  268. package/dist/__tests__/unit/tree-debugger-incremental.test.js.map +0 -1
  269. package/dist/__tests__/unit/tree-debugger.test.d.ts +0 -2
  270. package/dist/__tests__/unit/tree-debugger.test.d.ts.map +0 -1
  271. package/dist/__tests__/unit/tree-debugger.test.js +0 -69
  272. package/dist/__tests__/unit/tree-debugger.test.js.map +0 -1
  273. package/dist/__tests__/unit/utils/workflow-error-utils.test.d.ts +0 -2
  274. package/dist/__tests__/unit/utils/workflow-error-utils.test.d.ts.map +0 -1
  275. package/dist/__tests__/unit/utils/workflow-error-utils.test.js +0 -154
  276. package/dist/__tests__/unit/utils/workflow-error-utils.test.js.map +0 -1
  277. package/dist/__tests__/unit/workflow-detachChild.test.d.ts +0 -2
  278. package/dist/__tests__/unit/workflow-detachChild.test.d.ts.map +0 -1
  279. package/dist/__tests__/unit/workflow-detachChild.test.js +0 -76
  280. package/dist/__tests__/unit/workflow-detachChild.test.js.map +0 -1
  281. package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.d.ts +0 -2
  282. package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.d.ts.map +0 -1
  283. package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.js +0 -122
  284. package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.js.map +0 -1
  285. package/dist/__tests__/unit/workflow-isDescendantOf.test.d.ts +0 -2
  286. package/dist/__tests__/unit/workflow-isDescendantOf.test.d.ts.map +0 -1
  287. package/dist/__tests__/unit/workflow-isDescendantOf.test.js +0 -140
  288. package/dist/__tests__/unit/workflow-isDescendantOf.test.js.map +0 -1
  289. package/dist/__tests__/unit/workflow.test.d.ts +0 -2
  290. package/dist/__tests__/unit/workflow.test.d.ts.map +0 -1
  291. package/dist/__tests__/unit/workflow.test.js +0 -330
  292. package/dist/__tests__/unit/workflow.test.js.map +0 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Agent response validation utilities
3
+ *
4
+ * Provides pure, side-effect-free functions for validating AgentResponse
5
+ * instances using Zod schemas. The utilities enable both Agent and Workflow
6
+ * classes to perform validation without duplicating code.
7
+ *
8
+ * @module agent-validation
9
+ */
10
+ import type { AgentResponse } from '../types/agent.js';
11
+ import { z } from 'zod';
12
+ /**
13
+ * Validation result type for agent response validation
14
+ *
15
+ * Provides structured validation result with boolean validity flag
16
+ * and optional ZodError for detailed error information.
17
+ */
18
+ export interface ValidationResult {
19
+ /** Whether the response is valid according to the schema */
20
+ valid: boolean;
21
+ /** Zod validation errors (present when valid is false) */
22
+ errors?: z.ZodError;
23
+ }
24
+ /**
25
+ * Validate an AgentResponse against a Zod schema
26
+ *
27
+ * This is a pure, side-effect-free function that validates AgentResponse
28
+ * instances using Zod schemas. It returns a structured ValidationResult
29
+ * with validity flag and optional error details.
30
+ *
31
+ * **Validation Flow:**
32
+ * 1. Create AgentResponseSchema using provided dataSchema
33
+ * 2. Call schema.safeParse(response) for non-throwing validation
34
+ * 3. Return { valid: true } if validation succeeds
35
+ * 4. Return { valid: false, errors: ZodError } if validation fails
36
+ *
37
+ * **Pure Function Guarantee:**
38
+ * - Deterministic: Same input always produces same output
39
+ * - No side effects: Doesn't modify inputs, emit events, or log
40
+ * - No external dependencies: Doesn't use Date.now(), Math.random(), etc.
41
+ *
42
+ * @template T - The type of response data
43
+ * @param response - The AgentResponse to validate
44
+ * @param dataSchema - The Zod schema for the response data (defaults to z.unknown())
45
+ * @returns Structured validation result with validity flag and optional errors
46
+ *
47
+ * @example Valid response
48
+ * ```ts
49
+ * const response: AgentResponse<string> = {
50
+ * status: 'success',
51
+ * data: 'Hello, World!',
52
+ * error: null,
53
+ * metadata: { agentId: 'agent-123', timestamp: Date.now() }
54
+ * };
55
+ *
56
+ * const result = validateAgentResponse(response);
57
+ * // Returns: { valid: true }
58
+ * ```
59
+ *
60
+ * @example Invalid response
61
+ * ```ts
62
+ * const response = {
63
+ * status: 'success',
64
+ * data: null, // Invalid: data should be string, not null
65
+ * error: null,
66
+ * metadata: { agentId: 'agent-123', timestamp: Date.now() }
67
+ * };
68
+ *
69
+ * const result = validateAgentResponse(response, z.string());
70
+ * // Returns: { valid: false, errors: ZodError }
71
+ * ```
72
+ *
73
+ * @remarks
74
+ * **Integration with Agent.validateResponse():**
75
+ * This utility is called by Agent.validateResponse() which adds:
76
+ * - console.error logging with agentId
77
+ * - INTERNAL_ERROR response creation on validation failure
78
+ *
79
+ * **Integration with Workflow.validateAgentResponse():**
80
+ * This utility is called by Workflow.validateAgentResponse() which adds:
81
+ * - invalidResponse event emission
82
+ * - WorkflowError creation with INVALID_RESPONSE_FORMAT context
83
+ *
84
+ * @see {@link AgentResponseSchema} - Schema factory used for validation
85
+ * @see {@link ValidationResult} - Return type structure
86
+ */
87
+ export declare function validateAgentResponse<T>(response: AgentResponse<T>, dataSchema?: z.ZodTypeAny): ValidationResult;
88
+ //# sourceMappingURL=agent-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-validation.d.ts","sourceRoot":"","sources":["../../src/utils/agent-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,KAAK,EAAE,OAAO,CAAC;IACf,0DAA0D;IAC1D,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,UAAU,GAAE,CAAC,CAAC,UAAwB,GACrC,gBAAgB,CAclB"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Agent response validation utilities
3
+ *
4
+ * Provides pure, side-effect-free functions for validating AgentResponse
5
+ * instances using Zod schemas. The utilities enable both Agent and Workflow
6
+ * classes to perform validation without duplicating code.
7
+ *
8
+ * @module agent-validation
9
+ */
10
+ import { AgentResponseSchema } from '../types/agent.js';
11
+ import { z } from 'zod';
12
+ /**
13
+ * Validate an AgentResponse against a Zod schema
14
+ *
15
+ * This is a pure, side-effect-free function that validates AgentResponse
16
+ * instances using Zod schemas. It returns a structured ValidationResult
17
+ * with validity flag and optional error details.
18
+ *
19
+ * **Validation Flow:**
20
+ * 1. Create AgentResponseSchema using provided dataSchema
21
+ * 2. Call schema.safeParse(response) for non-throwing validation
22
+ * 3. Return { valid: true } if validation succeeds
23
+ * 4. Return { valid: false, errors: ZodError } if validation fails
24
+ *
25
+ * **Pure Function Guarantee:**
26
+ * - Deterministic: Same input always produces same output
27
+ * - No side effects: Doesn't modify inputs, emit events, or log
28
+ * - No external dependencies: Doesn't use Date.now(), Math.random(), etc.
29
+ *
30
+ * @template T - The type of response data
31
+ * @param response - The AgentResponse to validate
32
+ * @param dataSchema - The Zod schema for the response data (defaults to z.unknown())
33
+ * @returns Structured validation result with validity flag and optional errors
34
+ *
35
+ * @example Valid response
36
+ * ```ts
37
+ * const response: AgentResponse<string> = {
38
+ * status: 'success',
39
+ * data: 'Hello, World!',
40
+ * error: null,
41
+ * metadata: { agentId: 'agent-123', timestamp: Date.now() }
42
+ * };
43
+ *
44
+ * const result = validateAgentResponse(response);
45
+ * // Returns: { valid: true }
46
+ * ```
47
+ *
48
+ * @example Invalid response
49
+ * ```ts
50
+ * const response = {
51
+ * status: 'success',
52
+ * data: null, // Invalid: data should be string, not null
53
+ * error: null,
54
+ * metadata: { agentId: 'agent-123', timestamp: Date.now() }
55
+ * };
56
+ *
57
+ * const result = validateAgentResponse(response, z.string());
58
+ * // Returns: { valid: false, errors: ZodError }
59
+ * ```
60
+ *
61
+ * @remarks
62
+ * **Integration with Agent.validateResponse():**
63
+ * This utility is called by Agent.validateResponse() which adds:
64
+ * - console.error logging with agentId
65
+ * - INTERNAL_ERROR response creation on validation failure
66
+ *
67
+ * **Integration with Workflow.validateAgentResponse():**
68
+ * This utility is called by Workflow.validateAgentResponse() which adds:
69
+ * - invalidResponse event emission
70
+ * - WorkflowError creation with INVALID_RESPONSE_FORMAT context
71
+ *
72
+ * @see {@link AgentResponseSchema} - Schema factory used for validation
73
+ * @see {@link ValidationResult} - Return type structure
74
+ */
75
+ export function validateAgentResponse(response, dataSchema = z.unknown()) {
76
+ // Create schema for this response type
77
+ const schema = AgentResponseSchema(dataSchema);
78
+ // Validate response against schema (non-throwing)
79
+ const validation = schema.safeParse(response);
80
+ if (validation.success) {
81
+ // Response is valid
82
+ return { valid: true };
83
+ }
84
+ // Validation failed - return structured error
85
+ return { valid: false, errors: validation.error };
86
+ }
87
+ //# sourceMappingURL=agent-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-validation.js","sourceRoot":"","sources":["../../src/utils/agent-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA0B,EAC1B,aAA2B,CAAC,CAAC,OAAO,EAAE;IAEtC,uCAAuC;IACvC,MAAM,MAAM,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE/C,kDAAkD;IAClD,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAE9C,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,oBAAoB;QACpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,8CAA8C;IAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a promise that resolves after a specified delay
3
+ * @param ms - Delay in milliseconds
4
+ * @returns Promise that resolves after delay
5
+ */
6
+ export declare function delay(ms: number): Promise<void>;
7
+ //# sourceMappingURL=delay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/utils/delay.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Creates a promise that resolves after a specified delay
3
+ * @param ms - Delay in milliseconds
4
+ * @returns Promise that resolves after delay
5
+ */
6
+ export function delay(ms) {
7
+ return new Promise((resolve) => setTimeout(resolve, ms));
8
+ }
9
+ //# sourceMappingURL=delay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../src/utils/delay.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Harness configuration cascade utilities (PRD §7.6 / §7.7).
3
+ *
4
+ * ## Dual-Cascade Architecture
5
+ *
6
+ * This module provides the v1.2 canonical harness-configuration functions that operate
7
+ * on the `GlobalHarnessConfig` / `HarnessId` / `HarnessOptions` types. It also contains
8
+ * deprecated legacy aliases (`configureProviders` / `getGlobalProviderConfig` /
9
+ * `resolveProviderConfig` / `resetGlobalConfig`) that preserve backward compatibility
10
+ * with existing consumers (`agent.ts`, legacy test files) during the migration.
11
+ *
12
+ * ## Dual-Singleton Design (Scope Decision)
13
+ *
14
+ * The legacy and harness functions validate **disjoint id sets**:
15
+ * - `configureHarnesses` accepts only `'pi' | 'claude-code'`
16
+ * - `configureProviders` accepts the full `ProviderId` superset (including `'anthropic'`)
17
+ *
18
+ * Existing consumers (agent.ts, 4 integration/override test files) pass `'anthropic'`
19
+ * through `configureProviders`. Making it delegate to `configureHarnesses` would throw and break
20
+ * those consumers, which are out of scope for this task (owned by P3.M1 / P4.M1).
21
+ *
22
+ * Therefore, **`configureProviders` keeps its own module-private singleton** with permissive
23
+ * validation, while `resolveProviderConfig` safely delegates to `resolveHarnessConfig` (which
24
+ * performs NO id validation — it treats ids as opaque string keys).
25
+ *
26
+ * Once P3.M1 rewires agent.ts to read the harness path and P4.M1 removes the legacy literals,
27
+ * the legacy singleton can be deleted and the aliases collapse to true delegation.
28
+ *
29
+ * @see {@link GlobalHarnessConfig} in types/harnesses.ts
30
+ * @see {@link GlobalProviderConfig} in types/providers.ts
31
+ */
32
+ import type { GlobalHarnessConfig, HarnessId, HarnessOptions } from '../types/harnesses.js';
33
+ import type { GlobalProviderConfig, ProviderId, ProviderOptions } from '../types/providers.js';
34
+ /**
35
+ * Configure the global harness settings.
36
+ *
37
+ * Validates and stores the harness configuration. Should be called once at
38
+ * application startup. The harness cascade (PRD §7.7) uses this as the lowest
39
+ * priority layer — agent and prompt overrides take precedence.
40
+ *
41
+ * ## Validation
42
+ *
43
+ * - `defaultHarness` must be `'pi'` or `'claude-code'`
44
+ * - `harnessDefaults` keys (if present) must be valid `HarnessId` values
45
+ * - `defaultModelProvider` is an **open set** (any string) — NOT validated (PRD §7.8)
46
+ *
47
+ * @param config - Global harness configuration
48
+ * @throws {Error} If `defaultHarness` is invalid
49
+ * @throws {Error} If `harnessDefaults` contains invalid harness IDs
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { configureHarnesses } from 'groundswell';
54
+ *
55
+ * configureHarnesses({
56
+ * defaultHarness: 'pi',
57
+ * defaultModelProvider: 'anthropic',
58
+ * harnessDefaults: {
59
+ * 'claude-code': { apiKey: process.env.ANTHROPIC_API_KEY },
60
+ * },
61
+ * });
62
+ * ```
63
+ */
64
+ export declare function configureHarnesses(config: GlobalHarnessConfig): void;
65
+ /**
66
+ * Get the current global harness configuration.
67
+ *
68
+ * Returns the configured value if `configureHarnesses()` was called, otherwise
69
+ * returns the default configuration. **Never returns null.**
70
+ *
71
+ * @returns Current global harness configuration
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const config = getGlobalHarnessConfig();
76
+ * console.log(config.defaultHarness); // 'pi' (default)
77
+ * ```
78
+ */
79
+ export declare function getGlobalHarnessConfig(): GlobalHarnessConfig;
80
+ /**
81
+ * Resolve harness configuration via the PRD §7.7 cascade.
82
+ *
83
+ * A **pure function** — takes `globalConfig` as a parameter and does NOT read
84
+ * the singleton. This purity enables both `resolveHarnessConfig` and the legacy
85
+ * `resolveProviderConfig` (which delegates to this function) to work correctly.
86
+ *
87
+ * ## Provider Resolution (nullish coalescing — prompt wins)
88
+ *
89
+ * ```ts
90
+ * const harness = promptHarness ?? agentHarness ?? globalConfig.defaultHarness;
91
+ * ```
92
+ *
93
+ * ## Options Merge (object spread — last write wins)
94
+ *
95
+ * ```ts
96
+ * const options = {
97
+ * ...globalConfig.harnessDefaults?.[harness], // base
98
+ * ...agentOptions, // middle
99
+ * ...promptOptions, // top
100
+ * };
101
+ * ```
102
+ *
103
+ * @param globalConfig - Global harness configuration
104
+ * @param agentHarness - Agent-level harness override (optional)
105
+ * @param agentOptions - Agent-level options override (optional)
106
+ * @param promptHarness - Prompt-level harness override (optional)
107
+ * @param promptOptions - Prompt-level options override (optional)
108
+ * @returns Resolved harness and merged options
109
+ */
110
+ export declare function resolveHarnessConfig(globalConfig: GlobalHarnessConfig, agentHarness?: HarnessId, agentOptions?: HarnessOptions, promptHarness?: HarnessId, promptOptions?: HarnessOptions): {
111
+ harness: HarnessId;
112
+ options: HarnessOptions;
113
+ };
114
+ /**
115
+ * Reset the global harness configuration to defaults.
116
+ *
117
+ * **FOR TESTING PURPOSES ONLY.**
118
+ *
119
+ * @internal
120
+ */
121
+ export declare function resetGlobalHarnessConfig(): void;
122
+ /**
123
+ * Configure global provider settings.
124
+ *
125
+ * @deprecated Since v1.2. Use {@link configureHarnesses}.
126
+ *
127
+ * This function keeps its **own module-private singleton** (`globalProviderConfig`)
128
+ * with permissive `ProviderId` validation. It does NOT delegate to
129
+ * `configureHarnesses` because the harness validator rejects `'anthropic'`,
130
+ * which existing consumers still pass.
131
+ *
132
+ * @param config - Global provider configuration
133
+ * @throws {Error} If `defaultProvider` is invalid
134
+ * @throws {Error} If `providerDefaults` contains invalid provider IDs
135
+ */
136
+ export declare function configureProviders(config: GlobalProviderConfig): void;
137
+ /**
138
+ * Get the current global provider configuration.
139
+ *
140
+ * @deprecated Since v1.2. Use {@link getGlobalHarnessConfig}.
141
+ *
142
+ * Reads the legacy `globalProviderConfig` singleton. Returns the configured value
143
+ * if `configureProviders()` was called, otherwise the legacy default
144
+ * (`defaultProvider: 'anthropic'`). **Never returns null.**
145
+ *
146
+ * @returns Current global provider configuration
147
+ */
148
+ export declare function getGlobalProviderConfig(): GlobalProviderConfig;
149
+ /**
150
+ * Resolve provider configuration via the cascade.
151
+ *
152
+ * @deprecated Since v1.2. Use {@link resolveHarnessConfig}.
153
+ *
154
+ * **Delegates to {@link resolveHarnessConfig}** — the cascade algorithm is shared.
155
+ * Translates the `GlobalProviderConfig` shape to `GlobalHarnessConfig` (field renames),
156
+ * calls `resolveHarnessConfig` (which performs NO id validation — safe for legacy literals),
157
+ * and maps the result back to `{ provider, options }`.
158
+ *
159
+ * @param globalConfig - Global provider configuration from configureProviders()
160
+ * @param agentProvider - Agent-level provider override (optional)
161
+ * @param agentOptions - Agent-level options override (optional)
162
+ * @param promptProvider - Prompt-level provider override (optional)
163
+ * @param promptOptions - Prompt-level options override (optional)
164
+ * @returns Resolved provider and merged options
165
+ */
166
+ export declare function resolveProviderConfig(globalConfig: GlobalProviderConfig, agentProvider?: ProviderId, agentOptions?: ProviderOptions, promptProvider?: ProviderId, promptOptions?: ProviderOptions): {
167
+ provider: ProviderId;
168
+ options: ProviderOptions;
169
+ };
170
+ /**
171
+ * Reset global configuration to defaults.
172
+ *
173
+ * @deprecated Since v1.2. Use {@link resetGlobalHarnessConfig}.
174
+ *
175
+ * **FOR TESTING PURPOSES ONLY.**
176
+ *
177
+ * @internal
178
+ */
179
+ export declare function resetGlobalConfig(): void;
180
+ //# sourceMappingURL=harness-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-config.d.ts","sourceRoot":"","sources":["../../src/utils/harness-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,eAAe,EAChB,MAAM,uBAAuB,CAAC;AA4C/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAuBpE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,IAAI,mBAAmB,CAE5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,mBAAmB,EACjC,YAAY,CAAC,EAAE,SAAS,EACxB,YAAY,CAAC,EAAE,cAAc,EAC7B,aAAa,CAAC,EAAE,SAAS,EACzB,aAAa,CAAC,EAAE,cAAc,GAC7B;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAejD;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAiDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAuBrE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,IAAI,oBAAoB,CAE9D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,oBAAoB,EAClC,aAAa,CAAC,EAAE,UAAU,EAC1B,YAAY,CAAC,EAAE,eAAe,EAC9B,cAAc,CAAC,EAAE,UAAU,EAC3B,aAAa,CAAC,EAAE,eAAe,GAC9B;IAAE,QAAQ,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAmBpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}