@telora/factory 0.4.5

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 (301) hide show
  1. package/dist/audit.d.ts +69 -0
  2. package/dist/audit.d.ts.map +1 -0
  3. package/dist/audit.js +376 -0
  4. package/dist/audit.js.map +1 -0
  5. package/dist/builder-completion.d.ts +35 -0
  6. package/dist/builder-completion.d.ts.map +1 -0
  7. package/dist/builder-completion.js +375 -0
  8. package/dist/builder-completion.js.map +1 -0
  9. package/dist/builder-spawner.d.ts +40 -0
  10. package/dist/builder-spawner.d.ts.map +1 -0
  11. package/dist/builder-spawner.js +493 -0
  12. package/dist/builder-spawner.js.map +1 -0
  13. package/dist/completion-gate.d.ts +52 -0
  14. package/dist/completion-gate.d.ts.map +1 -0
  15. package/dist/completion-gate.js +336 -0
  16. package/dist/completion-gate.js.map +1 -0
  17. package/dist/completion-report.d.ts +36 -0
  18. package/dist/completion-report.d.ts.map +1 -0
  19. package/dist/completion-report.js +348 -0
  20. package/dist/completion-report.js.map +1 -0
  21. package/dist/completion.d.ts +58 -0
  22. package/dist/completion.d.ts.map +1 -0
  23. package/dist/completion.js +287 -0
  24. package/dist/completion.js.map +1 -0
  25. package/dist/config.d.ts +16 -0
  26. package/dist/config.d.ts.map +1 -0
  27. package/dist/config.js +57 -0
  28. package/dist/config.js.map +1 -0
  29. package/dist/context-manager.d.ts +152 -0
  30. package/dist/context-manager.d.ts.map +1 -0
  31. package/dist/context-manager.js +421 -0
  32. package/dist/context-manager.js.map +1 -0
  33. package/dist/crash-detection.d.ts +70 -0
  34. package/dist/crash-detection.d.ts.map +1 -0
  35. package/dist/crash-detection.js +123 -0
  36. package/dist/crash-detection.js.map +1 -0
  37. package/dist/crash-recovery.d.ts +83 -0
  38. package/dist/crash-recovery.d.ts.map +1 -0
  39. package/dist/crash-recovery.js +522 -0
  40. package/dist/crash-recovery.js.map +1 -0
  41. package/dist/crash-resolution.d.ts +34 -0
  42. package/dist/crash-resolution.d.ts.map +1 -0
  43. package/dist/crash-resolution.js +382 -0
  44. package/dist/crash-resolution.js.map +1 -0
  45. package/dist/escalation.d.ts +150 -0
  46. package/dist/escalation.d.ts.map +1 -0
  47. package/dist/escalation.js +352 -0
  48. package/dist/escalation.js.map +1 -0
  49. package/dist/execution-target.d.ts +31 -0
  50. package/dist/execution-target.d.ts.map +1 -0
  51. package/dist/execution-target.js +71 -0
  52. package/dist/execution-target.js.map +1 -0
  53. package/dist/execution-unit-init.d.ts +28 -0
  54. package/dist/execution-unit-init.d.ts.map +1 -0
  55. package/dist/execution-unit-init.js +115 -0
  56. package/dist/execution-unit-init.js.map +1 -0
  57. package/dist/execution.d.ts +17 -0
  58. package/dist/execution.d.ts.map +1 -0
  59. package/dist/execution.js +20 -0
  60. package/dist/execution.js.map +1 -0
  61. package/dist/factory-engine.d.ts +100 -0
  62. package/dist/factory-engine.d.ts.map +1 -0
  63. package/dist/factory-engine.js +243 -0
  64. package/dist/factory-engine.js.map +1 -0
  65. package/dist/gap-detection.d.ts +43 -0
  66. package/dist/gap-detection.d.ts.map +1 -0
  67. package/dist/gap-detection.js +149 -0
  68. package/dist/gap-detection.js.map +1 -0
  69. package/dist/gate-context.d.ts +23 -0
  70. package/dist/gate-context.d.ts.map +1 -0
  71. package/dist/gate-context.js +63 -0
  72. package/dist/gate-context.js.map +1 -0
  73. package/dist/gate-engine.d.ts +55 -0
  74. package/dist/gate-engine.d.ts.map +1 -0
  75. package/dist/gate-engine.js +191 -0
  76. package/dist/gate-engine.js.map +1 -0
  77. package/dist/gates/adversarial.d.ts +59 -0
  78. package/dist/gates/adversarial.d.ts.map +1 -0
  79. package/dist/gates/adversarial.js +426 -0
  80. package/dist/gates/adversarial.js.map +1 -0
  81. package/dist/gates/adversary-spawner.d.ts +35 -0
  82. package/dist/gates/adversary-spawner.d.ts.map +1 -0
  83. package/dist/gates/adversary-spawner.js +286 -0
  84. package/dist/gates/adversary-spawner.js.map +1 -0
  85. package/dist/gates/adversary-test-dir.d.ts +41 -0
  86. package/dist/gates/adversary-test-dir.d.ts.map +1 -0
  87. package/dist/gates/adversary-test-dir.js +150 -0
  88. package/dist/gates/adversary-test-dir.js.map +1 -0
  89. package/dist/gates/behavioral-parser.d.ts +32 -0
  90. package/dist/gates/behavioral-parser.d.ts.map +1 -0
  91. package/dist/gates/behavioral-parser.js +190 -0
  92. package/dist/gates/behavioral-parser.js.map +1 -0
  93. package/dist/gates/behavioral-runner.d.ts +36 -0
  94. package/dist/gates/behavioral-runner.d.ts.map +1 -0
  95. package/dist/gates/behavioral-runner.js +306 -0
  96. package/dist/gates/behavioral-runner.js.map +1 -0
  97. package/dist/gates/behavioral.d.ts +37 -0
  98. package/dist/gates/behavioral.d.ts.map +1 -0
  99. package/dist/gates/behavioral.js +485 -0
  100. package/dist/gates/behavioral.js.map +1 -0
  101. package/dist/gates/deterministic.d.ts +24 -0
  102. package/dist/gates/deterministic.d.ts.map +1 -0
  103. package/dist/gates/deterministic.js +186 -0
  104. package/dist/gates/deterministic.js.map +1 -0
  105. package/dist/git-factory.d.ts +59 -0
  106. package/dist/git-factory.d.ts.map +1 -0
  107. package/dist/git-factory.js +102 -0
  108. package/dist/git-factory.js.map +1 -0
  109. package/dist/guard-evaluation.d.ts +48 -0
  110. package/dist/guard-evaluation.d.ts.map +1 -0
  111. package/dist/guard-evaluation.js +416 -0
  112. package/dist/guard-evaluation.js.map +1 -0
  113. package/dist/index.d.ts +30 -0
  114. package/dist/index.d.ts.map +1 -0
  115. package/dist/index.js +39 -0
  116. package/dist/index.js.map +1 -0
  117. package/dist/instance-completion.d.ts +34 -0
  118. package/dist/instance-completion.d.ts.map +1 -0
  119. package/dist/instance-completion.js +366 -0
  120. package/dist/instance-completion.js.map +1 -0
  121. package/dist/instance-lifecycle.d.ts +15 -0
  122. package/dist/instance-lifecycle.d.ts.map +1 -0
  123. package/dist/instance-lifecycle.js +18 -0
  124. package/dist/instance-lifecycle.js.map +1 -0
  125. package/dist/instance-phase-dispatch.d.ts +75 -0
  126. package/dist/instance-phase-dispatch.d.ts.map +1 -0
  127. package/dist/instance-phase-dispatch.js +674 -0
  128. package/dist/instance-phase-dispatch.js.map +1 -0
  129. package/dist/instance-poll-loop.d.ts +43 -0
  130. package/dist/instance-poll-loop.d.ts.map +1 -0
  131. package/dist/instance-poll-loop.js +360 -0
  132. package/dist/instance-poll-loop.js.map +1 -0
  133. package/dist/instance-state-machine.d.ts +52 -0
  134. package/dist/instance-state-machine.d.ts.map +1 -0
  135. package/dist/instance-state-machine.js +235 -0
  136. package/dist/instance-state-machine.js.map +1 -0
  137. package/dist/log-manager.d.ts +28 -0
  138. package/dist/log-manager.d.ts.map +1 -0
  139. package/dist/log-manager.js +71 -0
  140. package/dist/log-manager.js.map +1 -0
  141. package/dist/pipeline-evaluator.d.ts +61 -0
  142. package/dist/pipeline-evaluator.d.ts.map +1 -0
  143. package/dist/pipeline-evaluator.js +107 -0
  144. package/dist/pipeline-evaluator.js.map +1 -0
  145. package/dist/pipeline-metrics.d.ts +52 -0
  146. package/dist/pipeline-metrics.d.ts.map +1 -0
  147. package/dist/pipeline-metrics.js +40 -0
  148. package/dist/pipeline-metrics.js.map +1 -0
  149. package/dist/pipeline-traversal.d.ts +43 -0
  150. package/dist/pipeline-traversal.d.ts.map +1 -0
  151. package/dist/pipeline-traversal.js +68 -0
  152. package/dist/pipeline-traversal.js.map +1 -0
  153. package/dist/plan-parser.d.ts +76 -0
  154. package/dist/plan-parser.d.ts.map +1 -0
  155. package/dist/plan-parser.js +223 -0
  156. package/dist/plan-parser.js.map +1 -0
  157. package/dist/planning-phase.d.ts +52 -0
  158. package/dist/planning-phase.d.ts.map +1 -0
  159. package/dist/planning-phase.js +444 -0
  160. package/dist/planning-phase.js.map +1 -0
  161. package/dist/planning-prompt.d.ts +64 -0
  162. package/dist/planning-prompt.d.ts.map +1 -0
  163. package/dist/planning-prompt.js +251 -0
  164. package/dist/planning-prompt.js.map +1 -0
  165. package/dist/planning.d.ts +16 -0
  166. package/dist/planning.d.ts.map +1 -0
  167. package/dist/planning.js +17 -0
  168. package/dist/planning.js.map +1 -0
  169. package/dist/process-runner.d.ts +41 -0
  170. package/dist/process-runner.d.ts.map +1 -0
  171. package/dist/process-runner.js +81 -0
  172. package/dist/process-runner.js.map +1 -0
  173. package/dist/product-config.d.ts +34 -0
  174. package/dist/product-config.d.ts.map +1 -0
  175. package/dist/product-config.js +43 -0
  176. package/dist/product-config.js.map +1 -0
  177. package/dist/queries/cycle-evaluations.d.ts +23 -0
  178. package/dist/queries/cycle-evaluations.d.ts.map +1 -0
  179. package/dist/queries/cycle-evaluations.js +37 -0
  180. package/dist/queries/cycle-evaluations.js.map +1 -0
  181. package/dist/queries/escalations.d.ts +30 -0
  182. package/dist/queries/escalations.d.ts.map +1 -0
  183. package/dist/queries/escalations.js +42 -0
  184. package/dist/queries/escalations.js.map +1 -0
  185. package/dist/queries/execution-units.d.ts +76 -0
  186. package/dist/queries/execution-units.d.ts.map +1 -0
  187. package/dist/queries/execution-units.js +109 -0
  188. package/dist/queries/execution-units.js.map +1 -0
  189. package/dist/queries/gate-results.d.ts +32 -0
  190. package/dist/queries/gate-results.d.ts.map +1 -0
  191. package/dist/queries/gate-results.js +44 -0
  192. package/dist/queries/gate-results.js.map +1 -0
  193. package/dist/queries/instances.d.ts +51 -0
  194. package/dist/queries/instances.d.ts.map +1 -0
  195. package/dist/queries/instances.js +77 -0
  196. package/dist/queries/instances.js.map +1 -0
  197. package/dist/queries/sessions.d.ts +50 -0
  198. package/dist/queries/sessions.d.ts.map +1 -0
  199. package/dist/queries/sessions.js +81 -0
  200. package/dist/queries/sessions.js.map +1 -0
  201. package/dist/queries/shared.d.ts +38 -0
  202. package/dist/queries/shared.d.ts.map +1 -0
  203. package/dist/queries/shared.js +119 -0
  204. package/dist/queries/shared.js.map +1 -0
  205. package/dist/queries/specs.d.ts +12 -0
  206. package/dist/queries/specs.d.ts.map +1 -0
  207. package/dist/queries/specs.js +21 -0
  208. package/dist/queries/specs.js.map +1 -0
  209. package/dist/queries/strategies.d.ts +14 -0
  210. package/dist/queries/strategies.d.ts.map +1 -0
  211. package/dist/queries/strategies.js +18 -0
  212. package/dist/queries/strategies.js.map +1 -0
  213. package/dist/queries/work-units.d.ts +42 -0
  214. package/dist/queries/work-units.d.ts.map +1 -0
  215. package/dist/queries/work-units.js +57 -0
  216. package/dist/queries/work-units.js.map +1 -0
  217. package/dist/queries/workflows.d.ts +29 -0
  218. package/dist/queries/workflows.d.ts.map +1 -0
  219. package/dist/queries/workflows.js +103 -0
  220. package/dist/queries/workflows.js.map +1 -0
  221. package/dist/remediation-units.d.ts +40 -0
  222. package/dist/remediation-units.d.ts.map +1 -0
  223. package/dist/remediation-units.js +263 -0
  224. package/dist/remediation-units.js.map +1 -0
  225. package/dist/replanning.d.ts +72 -0
  226. package/dist/replanning.d.ts.map +1 -0
  227. package/dist/replanning.js +403 -0
  228. package/dist/replanning.js.map +1 -0
  229. package/dist/resource-limits.d.ts +62 -0
  230. package/dist/resource-limits.d.ts.map +1 -0
  231. package/dist/resource-limits.js +322 -0
  232. package/dist/resource-limits.js.map +1 -0
  233. package/dist/scheduler.d.ts +98 -0
  234. package/dist/scheduler.d.ts.map +1 -0
  235. package/dist/scheduler.js +203 -0
  236. package/dist/scheduler.js.map +1 -0
  237. package/dist/session-adapter.d.ts +89 -0
  238. package/dist/session-adapter.d.ts.map +1 -0
  239. package/dist/session-adapter.js +108 -0
  240. package/dist/session-adapter.js.map +1 -0
  241. package/dist/sop-generator.d.ts +29 -0
  242. package/dist/sop-generator.d.ts.map +1 -0
  243. package/dist/sop-generator.js +235 -0
  244. package/dist/sop-generator.js.map +1 -0
  245. package/dist/spec-profiles.d.ts +41 -0
  246. package/dist/spec-profiles.d.ts.map +1 -0
  247. package/dist/spec-profiles.js +131 -0
  248. package/dist/spec-profiles.js.map +1 -0
  249. package/dist/strategy-design-graph.d.ts +23 -0
  250. package/dist/strategy-design-graph.d.ts.map +1 -0
  251. package/dist/strategy-design-graph.js +205 -0
  252. package/dist/strategy-design-graph.js.map +1 -0
  253. package/dist/strategy-design-prompt.d.ts +28 -0
  254. package/dist/strategy-design-prompt.d.ts.map +1 -0
  255. package/dist/strategy-design-prompt.js +108 -0
  256. package/dist/strategy-design-prompt.js.map +1 -0
  257. package/dist/strategy-design-schema.d.ts +767 -0
  258. package/dist/strategy-design-schema.d.ts.map +1 -0
  259. package/dist/strategy-design-schema.js +126 -0
  260. package/dist/strategy-design-schema.js.map +1 -0
  261. package/dist/strategy-design.d.ts +69 -0
  262. package/dist/strategy-design.d.ts.map +1 -0
  263. package/dist/strategy-design.js +411 -0
  264. package/dist/strategy-design.js.map +1 -0
  265. package/dist/strategy-gating.d.ts +31 -0
  266. package/dist/strategy-gating.d.ts.map +1 -0
  267. package/dist/strategy-gating.js +276 -0
  268. package/dist/strategy-gating.js.map +1 -0
  269. package/dist/team-prompt-builder.d.ts +47 -0
  270. package/dist/team-prompt-builder.d.ts.map +1 -0
  271. package/dist/team-prompt-builder.js +362 -0
  272. package/dist/team-prompt-builder.js.map +1 -0
  273. package/dist/trace-engine.d.ts +40 -0
  274. package/dist/trace-engine.d.ts.map +1 -0
  275. package/dist/trace-engine.js +344 -0
  276. package/dist/trace-engine.js.map +1 -0
  277. package/dist/types.d.ts +612 -0
  278. package/dist/types.d.ts.map +1 -0
  279. package/dist/types.js +9 -0
  280. package/dist/types.js.map +1 -0
  281. package/dist/unit-session-lifecycle.d.ts +78 -0
  282. package/dist/unit-session-lifecycle.d.ts.map +1 -0
  283. package/dist/unit-session-lifecycle.js +141 -0
  284. package/dist/unit-session-lifecycle.js.map +1 -0
  285. package/dist/unit-session.d.ts +30 -0
  286. package/dist/unit-session.d.ts.map +1 -0
  287. package/dist/unit-session.js +370 -0
  288. package/dist/unit-session.js.map +1 -0
  289. package/dist/watchdogs.d.ts +33 -0
  290. package/dist/watchdogs.d.ts.map +1 -0
  291. package/dist/watchdogs.js +170 -0
  292. package/dist/watchdogs.js.map +1 -0
  293. package/dist/work-unit-scheduler.d.ts +34 -0
  294. package/dist/work-unit-scheduler.d.ts.map +1 -0
  295. package/dist/work-unit-scheduler.js +91 -0
  296. package/dist/work-unit-scheduler.js.map +1 -0
  297. package/dist/workflow-transition.d.ts +90 -0
  298. package/dist/workflow-transition.d.ts.map +1 -0
  299. package/dist/workflow-transition.js +340 -0
  300. package/dist/workflow-transition.js.map +1 -0
  301. package/package.json +65 -0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Shared API client infrastructure for factory query modules.
3
+ *
4
+ * Uses tracker auth (TELORA_TRACKER_ID) to call the product-api edge function.
5
+ * Delegates to @telora/daemon-core's createApiClient with factory-specific
6
+ * circuit breaker topology and action-to-concern mapping.
7
+ */
8
+ import type { FactoryConfig } from '../types.js';
9
+ import { type ParsedTokenUsage } from '@telora/daemon-core';
10
+ import type { z } from 'zod';
11
+ export declare const safeInterval: any;
12
+ export declare const TokenSniffingTransform: any;
13
+ export declare const parseTokenUsageFromOutput: any;
14
+ export declare const sumTokenUsage: any;
15
+ export type { ParsedTokenUsage };
16
+ /**
17
+ * Initialize the API client with config.
18
+ */
19
+ export declare function initApiClient(factoryConfig: FactoryConfig): void;
20
+ /**
21
+ * Validate the configured tracker auth by calling a lightweight API endpoint.
22
+ * Throws immediately with a clear error message if auth is invalid.
23
+ */
24
+ export declare function validateTrackerAuth(): Promise<void>;
25
+ /**
26
+ * Call the product-api edge function with tracker authentication.
27
+ * Includes retry with exponential backoff and circuit breaker protection.
28
+ */
29
+ export declare function callApi<T>(action: string, params?: Record<string, unknown>): Promise<T>;
30
+ /**
31
+ * Call the product-api edge function and validate the response with a Zod schema.
32
+ */
33
+ export declare function callApiValidated<T>(action: string, schema: z.ZodType<T>, params?: Record<string, unknown>): Promise<T>;
34
+ /**
35
+ * Single attempt to call the product-api edge function.
36
+ */
37
+ export declare function callApiOnce<T>(action: string, params?: Record<string, unknown>): Promise<T>;
38
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/queries/shared.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAQL,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,eAAO,MAAM,YAAY,KAAgB,CAAC;AAC1C,eAAO,MAAM,sBAAsB,KAA0B,CAAC;AAC9D,eAAO,MAAM,yBAAyB,KAA6B,CAAC;AACpE,eAAO,MAAM,aAAa,KAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAiFjC;;GAEG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAEhE;AASD;;;GAGG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,OAAO,CAAC,CAAC,CAAC,CAEZ"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Shared API client infrastructure for factory query modules.
3
+ *
4
+ * Uses tracker auth (TELORA_TRACKER_ID) to call the product-api edge function.
5
+ * Delegates to @telora/daemon-core's createApiClient with factory-specific
6
+ * circuit breaker topology and action-to-concern mapping.
7
+ */
8
+ import { createApiClient, CircuitBreaker, safeInterval as _safeInterval, TokenSniffingTransform as _TokenSniffingTransform, parseTokenUsageFromOutput as _parseTokenUsageFromOutput, sumTokenUsage as _sumTokenUsage, } from '@telora/daemon-core';
9
+ // Re-export @telora/daemon-core utilities for use by other factory modules.
10
+ // This keeps @telora/daemon-core imports centralized in this module so that
11
+ // test files using mock.module() only need to mock this single module.
12
+ export const safeInterval = _safeInterval;
13
+ export const TokenSniffingTransform = _TokenSniffingTransform;
14
+ export const parseTokenUsageFromOutput = _parseTokenUsageFromOutput;
15
+ export const sumTokenUsage = _sumTokenUsage;
16
+ // ---------------------------------------------------------------------------
17
+ // Per-concern circuit breakers (factory-specific thresholds)
18
+ // ---------------------------------------------------------------------------
19
+ const circuitBreakers = {
20
+ polling: new CircuitBreaker({
21
+ failureThreshold: 5,
22
+ cooldownMs: 30000,
23
+ maxCooldownMs: 120000,
24
+ label: 'polling',
25
+ }),
26
+ critical: new CircuitBreaker({
27
+ failureThreshold: 2,
28
+ cooldownMs: 60000,
29
+ maxCooldownMs: 180000,
30
+ label: 'critical',
31
+ }),
32
+ activity: new CircuitBreaker({
33
+ failureThreshold: 5,
34
+ cooldownMs: 30000,
35
+ maxCooldownMs: 120000,
36
+ label: 'activity',
37
+ }),
38
+ };
39
+ // ---------------------------------------------------------------------------
40
+ // Action-to-concern mapping (factory-specific)
41
+ // ---------------------------------------------------------------------------
42
+ const ACTION_CONCERN_MAP = {
43
+ // Polling concern (instance discovery)
44
+ factory_get_pending_instances: 'polling',
45
+ factory_get_instance_blueprint: 'polling',
46
+ factory_get_instance_work_units: 'polling',
47
+ factory_get_cycle_evaluations: 'polling',
48
+ // Activity concern (status updates, session tracking)
49
+ factory_update_instance_status: 'activity',
50
+ factory_create_work_units: 'activity',
51
+ factory_update_work_unit_status: 'activity',
52
+ factory_create_session: 'activity',
53
+ factory_update_session: 'activity',
54
+ factory_get_active_sessions: 'activity',
55
+ factory_create_gate_result: 'activity',
56
+ factory_get_gate_results: 'activity',
57
+ factory_get_accumulated_adversary_tests: 'activity',
58
+ factory_create_cycle_evaluation: 'activity',
59
+ // Strategy design concern (designing phase)
60
+ factory_create_strategies: 'activity',
61
+ factory_get_instance_strategies: 'polling',
62
+ // Spec completion callback (non-blocking, best-effort)
63
+ factory_spec_complete_callback: 'activity',
64
+ // Critical concern (escalation)
65
+ factory_create_escalation: 'critical',
66
+ factory_get_active_escalation_instance_ids: 'polling',
67
+ // Workflow concern (reuses existing circuit breakers)
68
+ factory_resolve_workflow: 'polling',
69
+ factory_update_instance_workflow_stage: 'activity',
70
+ factory_update_work_unit_workflow_stage: 'activity',
71
+ daemon_get_transition_guards: 'polling',
72
+ daemon_create_transition_evaluation: 'activity',
73
+ };
74
+ function getConcernForAction(action) {
75
+ return ACTION_CONCERN_MAP[action] ?? 'activity';
76
+ }
77
+ // ---------------------------------------------------------------------------
78
+ // API client (lazy-initialized via daemon-core factory)
79
+ // ---------------------------------------------------------------------------
80
+ let client = null;
81
+ /**
82
+ * Initialize the API client with config.
83
+ */
84
+ export function initApiClient(factoryConfig) {
85
+ client = createApiClient(factoryConfig, circuitBreakers, getConcernForAction);
86
+ }
87
+ function getClient() {
88
+ if (!client) {
89
+ throw new Error('API client not initialized. Call initApiClient first.');
90
+ }
91
+ return client;
92
+ }
93
+ /**
94
+ * Validate the configured tracker auth by calling a lightweight API endpoint.
95
+ * Throws immediately with a clear error message if auth is invalid.
96
+ */
97
+ export async function validateTrackerAuth() {
98
+ return getClient().validateTrackerAuth();
99
+ }
100
+ /**
101
+ * Call the product-api edge function with tracker authentication.
102
+ * Includes retry with exponential backoff and circuit breaker protection.
103
+ */
104
+ export async function callApi(action, params = {}) {
105
+ return getClient().callApi(action, params);
106
+ }
107
+ /**
108
+ * Call the product-api edge function and validate the response with a Zod schema.
109
+ */
110
+ export async function callApiValidated(action, schema, params = {}) {
111
+ return getClient().callApiValidated(action, schema, params);
112
+ }
113
+ /**
114
+ * Single attempt to call the product-api edge function.
115
+ */
116
+ export async function callApiOnce(action, params = {}) {
117
+ return getClient().callApiOnce(action, params);
118
+ }
119
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/queries/shared.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Factory spec queries.
3
+ *
4
+ * Provides operations for factory_specs table via the product-api edge function.
5
+ */
6
+ /**
7
+ * Update a spec's last_completion_summary with data from a factory completion report.
8
+ *
9
+ * Fire-and-forget: callers should catch and log errors rather than propagating them.
10
+ */
11
+ export declare function updateSpecCompletionSummary(specId: string, summary: Record<string, unknown>): Promise<void>;
12
+ //# sourceMappingURL=specs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specs.d.ts","sourceRoot":"","sources":["../../src/queries/specs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAKf"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Factory spec queries.
3
+ *
4
+ * Provides operations for factory_specs table via the product-api edge function.
5
+ */
6
+ import { callApi } from './shared.js';
7
+ // ---------------------------------------------------------------------------
8
+ // Spec completion callback
9
+ // ---------------------------------------------------------------------------
10
+ /**
11
+ * Update a spec's last_completion_summary with data from a factory completion report.
12
+ *
13
+ * Fire-and-forget: callers should catch and log errors rather than propagating them.
14
+ */
15
+ export async function updateSpecCompletionSummary(specId, summary) {
16
+ await callApi('factory_spec_complete_callback', {
17
+ specId,
18
+ summary,
19
+ });
20
+ }
21
+ //# sourceMappingURL=specs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specs.js","sourceRoot":"","sources":["../../src/queries/specs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAc,EACd,OAAgC;IAEhC,MAAM,OAAO,CAAC,gCAAgC,EAAE;QAC9C,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Factory strategy queries.
3
+ *
4
+ * Provides operations for factory-created product_strategies via the product-api edge function.
5
+ */
6
+ import type { StrategyExecutionStatus } from '../strategy-design.js';
7
+ /**
8
+ * Update the execution_status of a factory-created strategy.
9
+ * Optionally sets gate_fix_started_at alongside the status transition.
10
+ */
11
+ export declare function updateStrategyExecutionStatus(strategyId: string, executionStatus: StrategyExecutionStatus, options?: {
12
+ gateFixStartedAt?: string | null;
13
+ }): Promise<void>;
14
+ //# sourceMappingURL=strategies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../src/queries/strategies.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE;;;GAGG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,uBAAuB,EACxC,OAAO,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC7C,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Factory strategy queries.
3
+ *
4
+ * Provides operations for factory-created product_strategies via the product-api edge function.
5
+ */
6
+ import { callApi } from './shared.js';
7
+ /**
8
+ * Update the execution_status of a factory-created strategy.
9
+ * Optionally sets gate_fix_started_at alongside the status transition.
10
+ */
11
+ export async function updateStrategyExecutionStatus(strategyId, executionStatus, options) {
12
+ await callApi('factory_update_strategy_execution_status', {
13
+ strategyId,
14
+ executionStatus,
15
+ ...(options?.gateFixStartedAt !== undefined && { gateFixStartedAt: options.gateFixStartedAt }),
16
+ });
17
+ }
18
+ //# sourceMappingURL=strategies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.js","sourceRoot":"","sources":["../../src/queries/strategies.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,UAAkB,EAClB,eAAwC,EACxC,OAA8C;IAE9C,MAAM,OAAO,CAAC,0CAA0C,EAAE;QACxD,UAAU;QACV,eAAe;QACf,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,SAAS,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC;KAC/F,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Factory work unit queries.
3
+ *
4
+ * Provides CRUD operations for factory_work_units table.
5
+ */
6
+ import type { FactoryWorkUnit, WorkUnitStatus } from '../types.js';
7
+ /**
8
+ * Bulk insert work units for an instance (from the AI-generated work plan).
9
+ *
10
+ * @param instanceId - The factory instance ID
11
+ * @param units - Array of work units to insert. blockedBy uses real UUIDs
12
+ * (caller must map tempId references to real IDs).
13
+ * @returns The created work units with their assigned IDs.
14
+ */
15
+ export declare function createWorkUnits(instanceId: string, units: Array<{
16
+ id: string;
17
+ title: string;
18
+ description: string;
19
+ sortOrder: number;
20
+ blockedBy: string[];
21
+ cycleNumber?: number;
22
+ strategyId?: string;
23
+ infrastructureOwned?: boolean;
24
+ }>): Promise<FactoryWorkUnit[]>;
25
+ /**
26
+ * Get all work units for an instance.
27
+ */
28
+ export declare function getInstanceWorkUnits(instanceId: string): Promise<FactoryWorkUnit[]>;
29
+ /**
30
+ * Update a work unit's status and optional fields.
31
+ */
32
+ export declare function updateWorkUnitStatus(workUnitId: string, status: WorkUnitStatus, fields?: Record<string, unknown>): Promise<void>;
33
+ /**
34
+ * Get completed work units for an instance.
35
+ * Used by McpAdapter to poll for status changes made via MCP tool calls.
36
+ */
37
+ export declare function getCompletedWorkUnits(instanceId: string): Promise<FactoryWorkUnit[]>;
38
+ /**
39
+ * Update a work unit's workflow stage and optionally its status.
40
+ */
41
+ export declare function updateWorkUnitWorkflowStage(workUnitId: string, currentWorkflowStageId: string | null, status?: WorkUnitStatus): Promise<void>;
42
+ //# sourceMappingURL=work-units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-units.d.ts","sourceRoot":"","sources":["../../src/queries/work-units.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMnE;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,KAAK,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC,GACD,OAAO,CAAC,eAAe,EAAE,CAAC,CAM5B;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC,CAM5B;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,EACtB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC,CAM5B;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,MAAM,EAClB,sBAAsB,EAAE,MAAM,GAAG,IAAI,EACrC,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Factory work unit queries.
3
+ *
4
+ * Provides CRUD operations for factory_work_units table.
5
+ */
6
+ import { callApi } from './shared.js';
7
+ // ---------------------------------------------------------------------------
8
+ // Query functions
9
+ // ---------------------------------------------------------------------------
10
+ /**
11
+ * Bulk insert work units for an instance (from the AI-generated work plan).
12
+ *
13
+ * @param instanceId - The factory instance ID
14
+ * @param units - Array of work units to insert. blockedBy uses real UUIDs
15
+ * (caller must map tempId references to real IDs).
16
+ * @returns The created work units with their assigned IDs.
17
+ */
18
+ export async function createWorkUnits(instanceId, units) {
19
+ const result = await callApi('factory_create_work_units', { instanceId, units });
20
+ return result.workUnits || [];
21
+ }
22
+ /**
23
+ * Get all work units for an instance.
24
+ */
25
+ export async function getInstanceWorkUnits(instanceId) {
26
+ const result = await callApi('factory_get_instance_work_units', { instanceId });
27
+ return result.workUnits || [];
28
+ }
29
+ /**
30
+ * Update a work unit's status and optional fields.
31
+ */
32
+ export async function updateWorkUnitStatus(workUnitId, status, fields = {}) {
33
+ await callApi('factory_update_work_unit_status', {
34
+ workUnitId,
35
+ status,
36
+ ...fields,
37
+ });
38
+ }
39
+ /**
40
+ * Get completed work units for an instance.
41
+ * Used by McpAdapter to poll for status changes made via MCP tool calls.
42
+ */
43
+ export async function getCompletedWorkUnits(instanceId) {
44
+ const result = await callApi('factory_get_instance_work_units', { instanceId, fields: { status: 'completed' } });
45
+ return result.workUnits || [];
46
+ }
47
+ /**
48
+ * Update a work unit's workflow stage and optionally its status.
49
+ */
50
+ export async function updateWorkUnitWorkflowStage(workUnitId, currentWorkflowStageId, status) {
51
+ await callApi('factory_update_work_unit_workflow_stage', {
52
+ workUnitId,
53
+ currentWorkflowStageId,
54
+ ...(status ? { status } : {}),
55
+ });
56
+ }
57
+ //# sourceMappingURL=work-units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-units.js","sourceRoot":"","sources":["../../src/queries/work-units.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAkB,EAClB,KASE;IAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAC1B,2BAA2B,EAC3B,EAAE,UAAU,EAAE,KAAK,EAAE,CACtB,CAAC;IACF,OAAO,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,OAAO,CAC1B,iCAAiC,EACjC,EAAE,UAAU,EAAE,CACf,CAAC;IACF,OAAO,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAAkB,EAClB,MAAsB,EACtB,SAAkC,EAAE;IAEpC,MAAM,OAAO,CAAC,iCAAiC,EAAE;QAC/C,UAAU;QACV,MAAM;QACN,GAAG,MAAM;KACV,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,UAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,OAAO,CAC1B,iCAAiC,EACjC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAChD,CAAC;IACF,OAAO,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,UAAkB,EAClB,sBAAqC,EACrC,MAAuB;IAEvB,MAAM,OAAO,CAAC,yCAAyC,EAAE;QACvD,UAAU;QACV,sBAAsB;QACtB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Factory workflow queries.
3
+ *
4
+ * Provides workflow resolution, guard fetching, and audit trail recording
5
+ * for factory workflow-governed transitions via the product-api edge function.
6
+ */
7
+ import type { ResolvedFactoryWorkflow, WorkflowGuard, WorkflowTrigger, TransitionEvaluationRecord } from '../types.js';
8
+ /**
9
+ * Resolve the built-in workflow for a factory entity type.
10
+ * Returns the workflow with all stages and transitions, or null if not found.
11
+ *
12
+ * Uses the factory_resolve_workflow product-api action which calls the
13
+ * resolve_factory_workflow SQL function.
14
+ */
15
+ export declare function resolveFactoryWorkflow(entityType: string): Promise<ResolvedFactoryWorkflow | null>;
16
+ /**
17
+ * Fetch guards and triggers for a specific transition.
18
+ * Reuses the existing daemon_get_transition_guards product-api action.
19
+ */
20
+ export declare function fetchTransitionGuards(transitionId: string): Promise<{
21
+ guards: WorkflowGuard[];
22
+ triggers: WorkflowTrigger[];
23
+ }>;
24
+ /**
25
+ * Create a transition evaluation audit record.
26
+ * Reuses the existing daemon_create_transition_evaluation product-api action.
27
+ */
28
+ export declare function createTransitionEvaluation(record: TransitionEvaluationRecord): Promise<string>;
29
+ //# sourceMappingURL=workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/queries/workflows.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,uBAAuB,EAGvB,aAAa,EACb,eAAe,EAMf,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AA8CrB;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CA+BzC;AAMD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC,CAoBnE;AAMD;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,0BAA0B,GACjC,OAAO,CAAC,MAAM,CAAC,CAkBjB"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Factory workflow queries.
3
+ *
4
+ * Provides workflow resolution, guard fetching, and audit trail recording
5
+ * for factory workflow-governed transitions via the product-api edge function.
6
+ */
7
+ import { callApi } from './shared.js';
8
+ // ---------------------------------------------------------------------------
9
+ // Transform helpers (camelCase API -> snake_case internal types)
10
+ // ---------------------------------------------------------------------------
11
+ function transformGuard(api) {
12
+ return {
13
+ id: api.id,
14
+ transition_id: api.transitionId,
15
+ name: api.name,
16
+ description: api.description,
17
+ enforcement: api.enforcement,
18
+ conditions: api.conditions ?? [],
19
+ parameter_schema: api.parameterSchema ?? {},
20
+ sort_order: api.sortOrder,
21
+ };
22
+ }
23
+ function transformTrigger(api) {
24
+ return {
25
+ id: api.id,
26
+ transition_id: api.transitionId,
27
+ name: api.name,
28
+ trigger_event: api.triggerEvent,
29
+ action_type: api.actionType,
30
+ action_config: api.actionConfig ?? {},
31
+ directive_template: api.directiveTemplate,
32
+ decision_paths: api.decisionPaths,
33
+ sort_order: api.sortOrder,
34
+ };
35
+ }
36
+ // ---------------------------------------------------------------------------
37
+ // Workflow resolution
38
+ // ---------------------------------------------------------------------------
39
+ /**
40
+ * Resolve the built-in workflow for a factory entity type.
41
+ * Returns the workflow with all stages and transitions, or null if not found.
42
+ *
43
+ * Uses the factory_resolve_workflow product-api action which calls the
44
+ * resolve_factory_workflow SQL function.
45
+ */
46
+ export async function resolveFactoryWorkflow(entityType) {
47
+ const result = await callApi('factory_resolve_workflow', { entityType });
48
+ if (!result.workflow)
49
+ return null;
50
+ const stages = result.workflow.stages;
51
+ const transitions = result.workflow.transitions;
52
+ const stageByName = new Map();
53
+ const stageById = new Map();
54
+ for (const stage of stages) {
55
+ stageByName.set(stage.name, stage);
56
+ stageById.set(stage.id, stage);
57
+ }
58
+ return {
59
+ id: result.workflow.id,
60
+ stages,
61
+ transitions,
62
+ stageByName,
63
+ stageById,
64
+ };
65
+ }
66
+ // ---------------------------------------------------------------------------
67
+ // Guard / trigger fetching (reuses daemon action)
68
+ // ---------------------------------------------------------------------------
69
+ /**
70
+ * Fetch guards and triggers for a specific transition.
71
+ * Reuses the existing daemon_get_transition_guards product-api action.
72
+ */
73
+ export async function fetchTransitionGuards(transitionId) {
74
+ const result = await callApi('daemon_get_transition_guards', { transitionId });
75
+ return {
76
+ guards: (result.guards ?? []).map(transformGuard),
77
+ triggers: (result.triggers ?? []).map(transformTrigger),
78
+ };
79
+ }
80
+ // ---------------------------------------------------------------------------
81
+ // Audit trail
82
+ // ---------------------------------------------------------------------------
83
+ /**
84
+ * Create a transition evaluation audit record.
85
+ * Reuses the existing daemon_create_transition_evaluation product-api action.
86
+ */
87
+ export async function createTransitionEvaluation(record) {
88
+ const result = await callApi('daemon_create_transition_evaluation', {
89
+ fields: {
90
+ organizationId: record.organization_id,
91
+ entityType: record.entity_type,
92
+ entityId: record.entity_id,
93
+ transitionId: record.transition_id,
94
+ guardId: record.guard_id,
95
+ result: record.result,
96
+ blocked: record.blocked,
97
+ enforcementLevel: record.enforcement_level,
98
+ evaluationDetails: record.evaluation_details,
99
+ },
100
+ });
101
+ return result.evaluationId;
102
+ }
103
+ //# sourceMappingURL=workflows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/queries/workflows.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAetC,8EAA8E;AAC9E,iEAAiE;AACjE,8EAA8E;AAE9E,SAAS,cAAc,CAAC,GAIvB;IACC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,aAAa,EAAE,GAAG,CAAC,YAAY;QAC/B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,WAAW,EAAE,GAAG,CAAC,WAA+B;QAChD,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE;QAChC,gBAAgB,EAAE,GAAG,CAAC,eAAe,IAAI,EAAE;QAC3C,UAAU,EAAE,GAAG,CAAC,SAAS;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,GAKzB;IACC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,aAAa,EAAE,GAAG,CAAC,YAAY;QAC/B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,aAAa,EAAE,GAAG,CAAC,YAA4B;QAC/C,WAAW,EAAE,GAAG,CAAC,UAA+B;QAChD,aAAa,EAAE,GAAG,CAAC,YAAY,IAAI,EAAE;QACrC,kBAAkB,EAAE,GAAG,CAAC,iBAAiB;QACzC,cAAc,EAAE,GAAG,CAAC,aAAa;QACjC,UAAU,EAAE,GAAG,CAAC,SAAS;KAC1B,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,OAAO,CASzB,0BAA0B,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAE/C,IAAI,CAAC,MAAM,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAElC,MAAM,MAAM,GAAoB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IACvD,MAAM,WAAW,GAAyB,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;IAEtE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;IACrD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE;QACtB,MAAM;QACN,WAAW;QACX,WAAW;QACX,SAAS;KACV,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,kDAAkD;AAClD,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,YAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,OAAO,CAazB,8BAA8B,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;IAErD,OAAO;QACL,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC;QACjD,QAAQ,EAAE,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC;KACxD,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,MAAkC;IAElC,MAAM,MAAM,GAAG,MAAM,OAAO,CAC1B,qCAAqC,EACrC;QACE,MAAM,EAAE;YACN,cAAc,EAAE,MAAM,CAAC,eAAe;YACtC,UAAU,EAAE,MAAM,CAAC,WAAW;YAC9B,QAAQ,EAAE,MAAM,CAAC,SAAS;YAC1B,YAAY,EAAE,MAAM,CAAC,aAAa;YAClC,OAAO,EAAE,MAAM,CAAC,QAAQ;YACxB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,gBAAgB,EAAE,MAAM,CAAC,iBAAiB;YAC1C,iBAAiB,EAAE,MAAM,CAAC,kBAAkB;SAC7C;KACF,CACF,CAAC;IACF,OAAO,MAAM,CAAC,YAAY,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Remediation unit generation for factory re-planning.
3
+ *
4
+ * Generates new work units to address detected gaps after a build cycle
5
+ * fails the completion gate. Contains:
6
+ * - Re-planning prompt builder (original spec + fresh audit + cycle history)
7
+ * - Re-planning phase orchestrator (audit, plan generation, unit creation)
8
+ */
9
+ import type { ResourceGovernor } from '@telora/daemon-core';
10
+ import type { FactoryBlueprint, FactoryConfig, FactoryInstanceState } from './types.js';
11
+ /**
12
+ * Build the re-planning prompt that instructs Claude Code to generate work
13
+ * units for remaining gaps in a multi-cycle factory run.
14
+ *
15
+ * Key differences from buildPlanningPrompt():
16
+ * - Explicitly states this is iteration N (not a fresh start)
17
+ * - Includes prior cycle evaluation history
18
+ * - Includes a fresh codebase audit against the current state
19
+ * - Instructs the planner to only generate work for remaining gaps
20
+ */
21
+ export declare function buildReplanningPrompt(specification: string, blueprint: FactoryBlueprint, auditReport: string | null, priorCycleContext: string, cycleNumber: number, gateContext?: string): string;
22
+ /**
23
+ * Run a full re-planning phase for a factory instance.
24
+ *
25
+ * This is the fresh-context equivalent of runPlanningPhase() but skips
26
+ * worktree/branch creation (already exists from cycle 1). Steps:
27
+ * 1. Fetch all prior cycle evaluations
28
+ * 2. Fetch all work units, filter to completed
29
+ * 3. Run fresh codebase audit against current worktree state
30
+ * 4. Format prior cycle context
31
+ * 5. Build re-planning prompt
32
+ * 6. Generate and validate work plan (with retries)
33
+ * 7. Map tempIds to UUIDs and create work units with correct cycle_number
34
+ */
35
+ export declare function runReplanningPhase(state: FactoryInstanceState, config: FactoryConfig, governor?: ResourceGovernor | null): Promise<{
36
+ success: boolean;
37
+ error?: string;
38
+ workUnitsCreated: number;
39
+ }>;
40
+ //# sourceMappingURL=remediation-units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remediation-units.d.ts","sourceRoot":"","sources":["../src/remediation-units.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAc5D,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEb,oBAAoB,EAGrB,MAAM,YAAY,CAAC;AAiBpB;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,iBAAiB,EAAE,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAqJR;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,oBAAoB,EAC3B,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAAC,CAqNzE"}