@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,186 @@
1
+ /**
2
+ * Deterministic gate evaluation.
3
+ *
4
+ * Runs configured shell commands (typecheck, lint, test, build) in the
5
+ * worktree directory and captures structured results. Commands execute
6
+ * sequentially; the first failure short-circuits remaining checks.
7
+ */
8
+ import { spawn } from 'node:child_process';
9
+ import { resolveTraceChecks, runTraceChecks, formatTraceOutput } from '../trace-engine.js';
10
+ // ============================================================================
11
+ // Constants
12
+ // ============================================================================
13
+ /** Log prefix for deterministic gate messages. */
14
+ const LOG_PREFIX = '[gate:deterministic]';
15
+ /** Default commands when the blueprint does not configure any. */
16
+ const DEFAULT_COMMANDS = [
17
+ 'npm run typecheck',
18
+ 'npm run lint',
19
+ 'npm test',
20
+ 'npm run build',
21
+ ];
22
+ /** Maximum output length per check (chars). Truncates from start, keeping tail. */
23
+ const MAX_OUTPUT_CHARS = 10_000;
24
+ /** Per-command timeout in milliseconds (10 minutes). */
25
+ const COMMAND_TIMEOUT_MS = 600_000;
26
+ // ============================================================================
27
+ // Output truncation
28
+ // ============================================================================
29
+ /**
30
+ * Truncate output to the configured maximum length.
31
+ * Keeps the tail (most recent output) and prepends a truncation marker.
32
+ */
33
+ function truncateOutput(output) {
34
+ if (output.length <= MAX_OUTPUT_CHARS) {
35
+ return output;
36
+ }
37
+ const truncationMarker = '... [output truncated] ...\n';
38
+ const keepLength = MAX_OUTPUT_CHARS - truncationMarker.length;
39
+ return truncationMarker + output.slice(-keepLength);
40
+ }
41
+ /**
42
+ * Run a single shell command in the given working directory.
43
+ *
44
+ * Uses `child_process.spawn` with `/bin/sh -c` to handle shell syntax
45
+ * (pipes, redirects, etc.). Captures combined stdout+stderr. Enforces
46
+ * a per-command timeout.
47
+ */
48
+ function runCommand(command, cwd) {
49
+ return new Promise((resolve) => {
50
+ const startTime = Date.now();
51
+ const chunks = [];
52
+ let settled = false;
53
+ const proc = spawn('/bin/sh', ['-c', command], {
54
+ cwd,
55
+ stdio: ['ignore', 'pipe', 'pipe'],
56
+ env: { ...process.env, CI: 'true', PORT: '0' },
57
+ });
58
+ // Capture stdout
59
+ proc.stdout.on('data', (chunk) => {
60
+ chunks.push(chunk);
61
+ });
62
+ // Capture stderr (interleaved with stdout in the output)
63
+ proc.stderr.on('data', (chunk) => {
64
+ chunks.push(chunk);
65
+ });
66
+ // Timeout guard
67
+ const timer = setTimeout(() => {
68
+ if (!settled) {
69
+ settled = true;
70
+ proc.kill('SIGTERM');
71
+ // Give the process a brief window to exit after SIGTERM
72
+ setTimeout(() => {
73
+ try {
74
+ proc.kill('SIGKILL');
75
+ }
76
+ catch {
77
+ // Process may already be gone -- ignore
78
+ }
79
+ }, 5000);
80
+ const durationMs = Date.now() - startTime;
81
+ const output = Buffer.concat(chunks).toString('utf-8');
82
+ resolve({
83
+ exitCode: 124, // Conventional timeout exit code (like GNU timeout)
84
+ output: truncateOutput(output + `\n[TIMEOUT] Command exceeded ${COMMAND_TIMEOUT_MS}ms limit`),
85
+ durationMs,
86
+ });
87
+ }
88
+ }, COMMAND_TIMEOUT_MS);
89
+ proc.on('close', (code) => {
90
+ if (!settled) {
91
+ settled = true;
92
+ clearTimeout(timer);
93
+ const durationMs = Date.now() - startTime;
94
+ const output = Buffer.concat(chunks).toString('utf-8');
95
+ resolve({
96
+ exitCode: code ?? 1,
97
+ output: truncateOutput(output),
98
+ durationMs,
99
+ });
100
+ }
101
+ });
102
+ proc.on('error', (error) => {
103
+ if (!settled) {
104
+ settled = true;
105
+ clearTimeout(timer);
106
+ const durationMs = Date.now() - startTime;
107
+ const output = Buffer.concat(chunks).toString('utf-8');
108
+ resolve({
109
+ exitCode: 1,
110
+ output: truncateOutput(output + `\n[ERROR] Failed to spawn command: ${error.message}`),
111
+ durationMs,
112
+ });
113
+ }
114
+ });
115
+ });
116
+ }
117
+ // ============================================================================
118
+ // Public API
119
+ // ============================================================================
120
+ /**
121
+ * Run deterministic gate checks in the given worktree.
122
+ *
123
+ * Executes the configured commands sequentially. Each command is run as a
124
+ * shell command in the worktree directory. The first failure short-circuits
125
+ * remaining checks.
126
+ *
127
+ * @param worktreePath - Absolute path to the git worktree directory
128
+ * @param config - Blueprint deterministic gate config, or null for defaults
129
+ * @returns Overall pass/fail and per-check results
130
+ */
131
+ export async function runDeterministicGates(worktreePath, config, traceChecks) {
132
+ const commands = config?.commands?.length
133
+ ? config.commands
134
+ : DEFAULT_COMMANDS;
135
+ const results = [];
136
+ let allPassed = true;
137
+ console.log(`${LOG_PREFIX} Running ${commands.length} check(s) in ${worktreePath}`);
138
+ for (const command of commands) {
139
+ console.log(`${LOG_PREFIX} Running: ${command}`);
140
+ const { exitCode, output, durationMs } = await runCommand(command, worktreePath);
141
+ const passed = exitCode === 0;
142
+ const result = {
143
+ checkName: command,
144
+ passed,
145
+ output,
146
+ durationMs,
147
+ isAdversaryGenerated: false,
148
+ };
149
+ results.push(result);
150
+ if (passed) {
151
+ console.log(`${LOG_PREFIX} PASSED: ${command} (${durationMs}ms)`);
152
+ }
153
+ else {
154
+ allPassed = false;
155
+ console.warn(`${LOG_PREFIX} FAILED: ${command} (exit code ${exitCode}, ${durationMs}ms)`);
156
+ // Short-circuit: stop running remaining checks after first failure
157
+ break;
158
+ }
159
+ }
160
+ // Run trace checks after command-based checks pass
161
+ if (allPassed && traceChecks && traceChecks.length > 0) {
162
+ const resolved = resolveTraceChecks(traceChecks);
163
+ if (resolved.length > 0) {
164
+ console.log(`${LOG_PREFIX} Running ${resolved.length} trace check(s)...`);
165
+ const traceResults = await runTraceChecks(resolved, worktreePath);
166
+ for (const trace of traceResults) {
167
+ const result = {
168
+ checkName: `trace:${trace.checkName}`,
169
+ passed: trace.passed,
170
+ output: formatTraceOutput(trace),
171
+ durationMs: trace.durationMs,
172
+ isAdversaryGenerated: false,
173
+ };
174
+ results.push(result);
175
+ if (!trace.passed) {
176
+ allPassed = false;
177
+ break; // Short-circuit like command checks
178
+ }
179
+ }
180
+ }
181
+ }
182
+ console.log(`${LOG_PREFIX} Gate evaluation ${allPassed ? 'PASSED' : 'FAILED'} ` +
183
+ `(${results.length}/${commands.length} check(s) executed)`);
184
+ return { passed: allPassed, results };
185
+ }
186
+ //# sourceMappingURL=deterministic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deterministic.js","sourceRoot":"","sources":["../../src/gates/deterministic.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE3F,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,kDAAkD;AAClD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAE1C,kEAAkE;AAClE,MAAM,gBAAgB,GAAsB;IAC1C,mBAAmB;IACnB,cAAc;IACd,UAAU;IACV,eAAe;CAChB,CAAC;AAEF,mFAAmF;AACnF,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,wDAAwD;AACxD,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEnC,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;GAGG;AACH,SAAS,cAAc,CAAC,MAAc;IACpC,IAAI,MAAM,CAAC,MAAM,IAAI,gBAAgB,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;IACxD,MAAM,UAAU,GAAG,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAC9D,OAAO,gBAAgB,GAAG,MAA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,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,qBAAqB,CAC3D,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AACxC,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Git worktree management for the factory orchestrator.
3
+ *
4
+ * Thin wrappers around @telora/daemon-core shared git/worktree operations,
5
+ * adding factory-specific conventions:
6
+ * - Factory worktrees live in `.telora/factory-worktrees/` (separate from
7
+ * daemon worktrees in `.telora/worktrees/`).
8
+ * - Branch naming: `factory/{blueprint-name}-{short-id}` (caller provides
9
+ * the full branch name).
10
+ *
11
+ * All heavy lifting (git process spawning, worktree creation/removal,
12
+ * WIP commits) is delegated to daemon-core.
13
+ */
14
+ import { runGit, commitWip, type GitResult } from '@telora/daemon-core';
15
+ export { runGit, commitWip };
16
+ export type { GitResult };
17
+ /**
18
+ * Create a git worktree for a factory instance.
19
+ *
20
+ * The worktree is created at `{worktreeDir}/{sanitized-branch}` with a new
21
+ * branch forked from HEAD of the current default branch. If the branch already
22
+ * exists (e.g. from a paused instance), the existing branch is checked out
23
+ * into the worktree instead.
24
+ *
25
+ * This is a thin wrapper around `createWorktreeBase` from daemon-core.
26
+ * Factory worktrees never specify a `baseBranch`, so they fork from HEAD.
27
+ *
28
+ * @param repoPath Absolute path to the main git repository.
29
+ * @param worktreeDir Parent directory for factory worktrees
30
+ * (typically `.telora/factory-worktrees/`).
31
+ * @param branchName Full branch name, e.g. `factory/my-blueprint-a1b2c3d4`.
32
+ * @returns Absolute path to the created worktree directory.
33
+ * @throws If the worktree cannot be created.
34
+ */
35
+ export declare function createFactoryWorktree(repoPath: string, worktreeDir: string, branchName: string): string;
36
+ /**
37
+ * Ensure MCP server build artifacts are available in a worktree.
38
+ *
39
+ * The MCP server dist/ directories are gitignored build artifacts that only
40
+ * exist in the main repo. Worktrees won't have them, which prevents Claude
41
+ * Code from loading MCP tools via .mcp.json (which uses relative paths).
42
+ * Symlinks each MCP dist/ directory from the main repo into the worktree.
43
+ */
44
+ export declare function ensureMcpServerInWorktree(repoPath: string, worktreePath: string): void;
45
+ /**
46
+ * Remove a factory worktree after completion or cancellation.
47
+ *
48
+ * Delegates to `removeWorktreeBase` from daemon-core, which handles:
49
+ * - Already-removed worktrees (just prune git state)
50
+ * - `git worktree remove --force` as the primary removal path
51
+ * - Fallback to manual directory deletion if git removal fails
52
+ *
53
+ * @param repoPath Absolute path to the main git repository.
54
+ * @param worktreePath Absolute path to the factory worktree to remove.
55
+ * @returns `true` if the worktree was removed (or already gone),
56
+ * `false` if removal failed.
57
+ */
58
+ export declare function removeWorktree(repoPath: string, worktreePath: string): boolean;
59
+ //# sourceMappingURL=git-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-factory.d.ts","sourceRoot":"","sources":["../src/git-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EACL,MAAM,EACN,SAAS,EAGT,KAAK,SAAS,EACf,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC7B,YAAY,EAAE,SAAS,EAAE,CAAC;AAI1B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,CAQR;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CA8BtF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAE9E"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Git worktree management for the factory orchestrator.
3
+ *
4
+ * Thin wrappers around @telora/daemon-core shared git/worktree operations,
5
+ * adding factory-specific conventions:
6
+ * - Factory worktrees live in `.telora/factory-worktrees/` (separate from
7
+ * daemon worktrees in `.telora/worktrees/`).
8
+ * - Branch naming: `factory/{blueprint-name}-{short-id}` (caller provides
9
+ * the full branch name).
10
+ *
11
+ * All heavy lifting (git process spawning, worktree creation/removal,
12
+ * WIP commits) is delegated to daemon-core.
13
+ */
14
+ import { existsSync, mkdirSync, readdirSync, symlinkSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+ import { runGit, commitWip, createWorktreeBase, removeWorktreeBase, } from '@telora/daemon-core';
17
+ // ── Re-exports ─────────────────────────────────────────────────────
18
+ // Other factory modules import runGit, commitWip, and GitResult from
19
+ // this file. Re-export them so those imports continue to work.
20
+ export { runGit, commitWip };
21
+ // ── Factory-specific wrappers ──────────────────────────────────────
22
+ /**
23
+ * Create a git worktree for a factory instance.
24
+ *
25
+ * The worktree is created at `{worktreeDir}/{sanitized-branch}` with a new
26
+ * branch forked from HEAD of the current default branch. If the branch already
27
+ * exists (e.g. from a paused instance), the existing branch is checked out
28
+ * into the worktree instead.
29
+ *
30
+ * This is a thin wrapper around `createWorktreeBase` from daemon-core.
31
+ * Factory worktrees never specify a `baseBranch`, so they fork from HEAD.
32
+ *
33
+ * @param repoPath Absolute path to the main git repository.
34
+ * @param worktreeDir Parent directory for factory worktrees
35
+ * (typically `.telora/factory-worktrees/`).
36
+ * @param branchName Full branch name, e.g. `factory/my-blueprint-a1b2c3d4`.
37
+ * @returns Absolute path to the created worktree directory.
38
+ * @throws If the worktree cannot be created.
39
+ */
40
+ export function createFactoryWorktree(repoPath, worktreeDir, branchName) {
41
+ const result = createWorktreeBase(repoPath, worktreeDir, branchName);
42
+ console.log(`[git-factory] Worktree ready: ${result.worktreePath}`);
43
+ // Symlink MCP server dist/ from main repo so .mcp.json relative paths resolve
44
+ ensureMcpServerInWorktree(repoPath, result.worktreePath);
45
+ return result.worktreePath;
46
+ }
47
+ /**
48
+ * Ensure MCP server build artifacts are available in a worktree.
49
+ *
50
+ * The MCP server dist/ directories are gitignored build artifacts that only
51
+ * exist in the main repo. Worktrees won't have them, which prevents Claude
52
+ * Code from loading MCP tools via .mcp.json (which uses relative paths).
53
+ * Symlinks each MCP dist/ directory from the main repo into the worktree.
54
+ */
55
+ export function ensureMcpServerInWorktree(repoPath, worktreePath) {
56
+ const mcpDir = join(repoPath, 'mcp');
57
+ if (!existsSync(mcpDir))
58
+ return;
59
+ let entries;
60
+ try {
61
+ entries = readdirSync(mcpDir);
62
+ }
63
+ catch {
64
+ return;
65
+ }
66
+ for (const serverName of entries) {
67
+ const sourceDist = join(mcpDir, serverName, 'dist');
68
+ if (!existsSync(sourceDist))
69
+ continue;
70
+ const targetDist = join(worktreePath, 'mcp', serverName, 'dist');
71
+ if (existsSync(targetDist))
72
+ continue;
73
+ const targetParent = join(worktreePath, 'mcp', serverName);
74
+ if (!existsSync(targetParent)) {
75
+ mkdirSync(targetParent, { recursive: true });
76
+ }
77
+ try {
78
+ symlinkSync(sourceDist, targetDist, 'dir');
79
+ console.log(`[git-factory] Symlinked MCP dist: ${serverName}/dist -> ${sourceDist}`);
80
+ }
81
+ catch (err) {
82
+ console.warn(`[git-factory] Failed to symlink MCP dist for ${serverName}: ${err instanceof Error ? err.message : String(err)}`);
83
+ }
84
+ }
85
+ }
86
+ /**
87
+ * Remove a factory worktree after completion or cancellation.
88
+ *
89
+ * Delegates to `removeWorktreeBase` from daemon-core, which handles:
90
+ * - Already-removed worktrees (just prune git state)
91
+ * - `git worktree remove --force` as the primary removal path
92
+ * - Fallback to manual directory deletion if git removal fails
93
+ *
94
+ * @param repoPath Absolute path to the main git repository.
95
+ * @param worktreePath Absolute path to the factory worktree to remove.
96
+ * @returns `true` if the worktree was removed (or already gone),
97
+ * `false` if removal failed.
98
+ */
99
+ export function removeWorktree(repoPath, worktreePath) {
100
+ return removeWorktreeBase(repoPath, worktreePath);
101
+ }
102
+ //# sourceMappingURL=git-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-factory.js","sourceRoot":"","sources":["../src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pD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;YAAE,SAAS;QAEtC,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACjE,IAAI,UAAU,CAAC,UAAU,CAAC;YAAE,SAAS;QAErC,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9B,SAAS,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC;YACH,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,qCAAqC,UAAU,YAAY,UAAU,EAAE,CAAC,CAAC;QACvF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,gDAAgD,UAAU,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClI,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,YAAoB;IACnE,OAAO,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Pure guard condition evaluation functions for the factory engine.
3
+ *
4
+ * These are extracted from packages/daemon/src/guard-engine.ts and kept
5
+ * in sync. They evaluate guard condition trees against an EvaluationContext
6
+ * without any database dependencies -- all data must be pre-fetched.
7
+ */
8
+ import type { GuardConditionNode, ConditionEvalResult, EvaluationContext, GuardEvalResult, FactoryTemplateContext } from './types.js';
9
+ /**
10
+ * Evaluate a JSONB condition tree for a guard.
11
+ * Root-level nodes are combined with AND.
12
+ */
13
+ export declare function evaluateGuardConditionTree(conditions: GuardConditionNode[], ctx: EvaluationContext): {
14
+ passed: boolean;
15
+ details: ConditionEvalResult[];
16
+ };
17
+ /**
18
+ * Build factory evaluation context from in-memory state.
19
+ * Pure function -- no database queries.
20
+ */
21
+ export declare function buildFactoryEvaluationContext(params: {
22
+ instanceId: string;
23
+ instanceState: {
24
+ tokensUsed: number;
25
+ completionGateIterations: number;
26
+ wallClockStartedAt: string | null;
27
+ };
28
+ blueprint: {
29
+ maxTokenBudget: number | null;
30
+ maxWallClockHours: number | null;
31
+ maxInstanceIterations: number | null;
32
+ };
33
+ workUnits: Array<{
34
+ status: string;
35
+ }>;
36
+ gateResults: Array<{
37
+ strategyId: string;
38
+ gateType: string;
39
+ iteration: number;
40
+ passed: boolean;
41
+ }>;
42
+ strategyId?: string;
43
+ }): EvaluationContext;
44
+ /**
45
+ * Interpolate guard and factory template variables.
46
+ */
47
+ export declare function interpolateTemplate(template: string | null, evalResult: GuardEvalResult | null, factoryCtx?: FactoryTemplateContext | null): string;
48
+ //# sourceMappingURL=guard-evaluation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard-evaluation.d.ts","sourceRoot":"","sources":["../src/guard-evaluation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,YAAY,CAAC;AA0UpB;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,kBAAkB,EAAE,EAChC,GAAG,EAAE,iBAAiB,GACrB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,mBAAmB,EAAE,CAAA;CAAE,CAWrD;AAMD;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE;QAC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