@tagma/sdk 0.7.3 → 0.7.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 (230) hide show
  1. package/README.md +85 -57
  2. package/dist/approval.d.ts +2 -12
  3. package/dist/approval.d.ts.map +1 -1
  4. package/dist/approval.js +1 -90
  5. package/dist/approval.js.map +1 -1
  6. package/dist/bootstrap.d.ts +1 -1
  7. package/dist/bootstrap.d.ts.map +1 -1
  8. package/dist/completions/file-exists.js +1 -1
  9. package/dist/completions/file-exists.js.map +1 -1
  10. package/dist/completions/output-check.d.ts.map +1 -1
  11. package/dist/completions/output-check.js +17 -4
  12. package/dist/completions/output-check.js.map +1 -1
  13. package/dist/config.d.ts +4 -4
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +2 -2
  16. package/dist/config.js.map +1 -1
  17. package/dist/dataflow.d.ts +3 -0
  18. package/dist/dataflow.d.ts.map +1 -0
  19. package/dist/dataflow.js +2 -0
  20. package/dist/dataflow.js.map +1 -0
  21. package/dist/drivers/opencode.d.ts.map +1 -1
  22. package/dist/drivers/opencode.js +23 -71
  23. package/dist/drivers/opencode.js.map +1 -1
  24. package/dist/engine.d.ts +5 -56
  25. package/dist/engine.d.ts.map +1 -1
  26. package/dist/engine.js +7 -297
  27. package/dist/engine.js.map +1 -1
  28. package/dist/index.d.ts +4 -6
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +2 -4
  31. package/dist/index.js.map +1 -1
  32. package/dist/logger.d.ts +2 -60
  33. package/dist/logger.d.ts.map +1 -1
  34. package/dist/logger.js +1 -153
  35. package/dist/logger.js.map +1 -1
  36. package/dist/middlewares/static-context.d.ts.map +1 -1
  37. package/dist/middlewares/static-context.js +1 -2
  38. package/dist/middlewares/static-context.js.map +1 -1
  39. package/dist/pipeline-runner.d.ts.map +1 -1
  40. package/dist/pipeline-runner.js +2 -2
  41. package/dist/pipeline-runner.js.map +1 -1
  42. package/dist/plugins.d.ts +2 -2
  43. package/dist/plugins.d.ts.map +1 -1
  44. package/dist/plugins.js +1 -1
  45. package/dist/plugins.js.map +1 -1
  46. package/dist/runner.d.ts +1 -35
  47. package/dist/runner.d.ts.map +1 -1
  48. package/dist/runner.js +1 -610
  49. package/dist/runner.js.map +1 -1
  50. package/dist/runtime/adapters/stdin-approval.d.ts +2 -0
  51. package/dist/runtime/adapters/stdin-approval.d.ts.map +1 -0
  52. package/dist/runtime/adapters/stdin-approval.js +2 -0
  53. package/dist/runtime/adapters/stdin-approval.js.map +1 -0
  54. package/dist/runtime/adapters/websocket-approval.d.ts +2 -0
  55. package/dist/runtime/adapters/websocket-approval.d.ts.map +1 -0
  56. package/dist/runtime/adapters/websocket-approval.js +2 -0
  57. package/dist/runtime/adapters/websocket-approval.js.map +1 -0
  58. package/dist/runtime/bun-process-runner.d.ts +2 -0
  59. package/dist/runtime/bun-process-runner.d.ts.map +1 -0
  60. package/dist/runtime/bun-process-runner.js +2 -0
  61. package/dist/runtime/bun-process-runner.js.map +1 -0
  62. package/dist/runtime.d.ts +2 -8
  63. package/dist/runtime.d.ts.map +1 -1
  64. package/dist/runtime.js +1 -7
  65. package/dist/runtime.js.map +1 -1
  66. package/dist/schema.d.ts.map +1 -1
  67. package/dist/schema.js +3 -4
  68. package/dist/schema.js.map +1 -1
  69. package/dist/tagma.d.ts +3 -4
  70. package/dist/tagma.d.ts.map +1 -1
  71. package/dist/tagma.js +2 -3
  72. package/dist/tagma.js.map +1 -1
  73. package/dist/triggers/file.d.ts.map +1 -1
  74. package/dist/triggers/file.js +74 -108
  75. package/dist/triggers/file.js.map +1 -1
  76. package/dist/triggers/manual.d.ts.map +1 -1
  77. package/dist/triggers/manual.js +1 -2
  78. package/dist/triggers/manual.js.map +1 -1
  79. package/dist/types.d.ts +1 -2
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/types.js +1 -12
  82. package/dist/types.js.map +1 -1
  83. package/dist/utils-api.d.ts +1 -1
  84. package/dist/utils-api.d.ts.map +1 -1
  85. package/dist/utils-api.js +1 -1
  86. package/dist/utils-api.js.map +1 -1
  87. package/dist/validate-raw.d.ts.map +1 -1
  88. package/dist/validate-raw.js +5 -12
  89. package/dist/validate-raw.js.map +1 -1
  90. package/package.json +20 -22
  91. package/dist/adapters/stdin-approval.d.ts +0 -6
  92. package/dist/adapters/stdin-approval.d.ts.map +0 -1
  93. package/dist/adapters/stdin-approval.js +0 -90
  94. package/dist/adapters/stdin-approval.js.map +0 -1
  95. package/dist/adapters/websocket-approval.d.ts +0 -28
  96. package/dist/adapters/websocket-approval.d.ts.map +0 -1
  97. package/dist/adapters/websocket-approval.js +0 -147
  98. package/dist/adapters/websocket-approval.js.map +0 -1
  99. package/dist/core/dataflow.d.ts +0 -23
  100. package/dist/core/dataflow.d.ts.map +0 -1
  101. package/dist/core/dataflow.js +0 -99
  102. package/dist/core/dataflow.js.map +0 -1
  103. package/dist/core/log-prune.d.ts +0 -16
  104. package/dist/core/log-prune.d.ts.map +0 -1
  105. package/dist/core/log-prune.js +0 -34
  106. package/dist/core/log-prune.js.map +0 -1
  107. package/dist/core/preflight.d.ts +0 -13
  108. package/dist/core/preflight.d.ts.map +0 -1
  109. package/dist/core/preflight.js +0 -61
  110. package/dist/core/preflight.js.map +0 -1
  111. package/dist/core/run-context.d.ts +0 -55
  112. package/dist/core/run-context.d.ts.map +0 -1
  113. package/dist/core/run-context.js +0 -158
  114. package/dist/core/run-context.js.map +0 -1
  115. package/dist/core/run-state.d.ts +0 -25
  116. package/dist/core/run-state.d.ts.map +0 -1
  117. package/dist/core/run-state.js +0 -93
  118. package/dist/core/run-state.js.map +0 -1
  119. package/dist/core/scheduler.d.ts +0 -13
  120. package/dist/core/scheduler.d.ts.map +0 -1
  121. package/dist/core/scheduler.js +0 -35
  122. package/dist/core/scheduler.js.map +0 -1
  123. package/dist/core/task-executor.d.ts +0 -13
  124. package/dist/core/task-executor.d.ts.map +0 -1
  125. package/dist/core/task-executor.js +0 -601
  126. package/dist/core/task-executor.js.map +0 -1
  127. package/dist/core/trigger-errors.d.ts +0 -9
  128. package/dist/core/trigger-errors.d.ts.map +0 -1
  129. package/dist/core/trigger-errors.js +0 -15
  130. package/dist/core/trigger-errors.js.map +0 -1
  131. package/dist/dag.d.ts +0 -45
  132. package/dist/dag.d.ts.map +0 -1
  133. package/dist/dag.js +0 -177
  134. package/dist/dag.js.map +0 -1
  135. package/dist/hooks.d.ts +0 -73
  136. package/dist/hooks.d.ts.map +0 -1
  137. package/dist/hooks.js +0 -106
  138. package/dist/hooks.js.map +0 -1
  139. package/dist/pipeline-definition.d.ts +0 -3
  140. package/dist/pipeline-definition.d.ts.map +0 -1
  141. package/dist/pipeline-definition.js +0 -4
  142. package/dist/pipeline-definition.js.map +0 -1
  143. package/dist/ports.d.ts +0 -196
  144. package/dist/ports.d.ts.map +0 -1
  145. package/dist/ports.js +0 -688
  146. package/dist/ports.js.map +0 -1
  147. package/dist/prompt-doc.d.ts +0 -70
  148. package/dist/prompt-doc.d.ts.map +0 -1
  149. package/dist/prompt-doc.js +0 -154
  150. package/dist/prompt-doc.js.map +0 -1
  151. package/dist/registry.d.ts +0 -67
  152. package/dist/registry.d.ts.map +0 -1
  153. package/dist/registry.js +0 -293
  154. package/dist/registry.js.map +0 -1
  155. package/dist/task-ref.d.ts +0 -55
  156. package/dist/task-ref.d.ts.map +0 -1
  157. package/dist/task-ref.js +0 -103
  158. package/dist/task-ref.js.map +0 -1
  159. package/dist/utils.d.ts +0 -13
  160. package/dist/utils.d.ts.map +0 -1
  161. package/dist/utils.js +0 -177
  162. package/dist/utils.js.map +0 -1
  163. package/src/adapters/stdin-approval.ts +0 -106
  164. package/src/adapters/websocket-approval.ts +0 -224
  165. package/src/approval.ts +0 -131
  166. package/src/bootstrap.ts +0 -55
  167. package/src/completions/exit-code.ts +0 -34
  168. package/src/completions/file-exists.ts +0 -66
  169. package/src/completions/output-check.test.ts +0 -50
  170. package/src/completions/output-check.ts +0 -92
  171. package/src/config-ops.test.ts +0 -70
  172. package/src/config-ops.ts +0 -328
  173. package/src/config.ts +0 -26
  174. package/src/core/dataflow.test.ts +0 -166
  175. package/src/core/dataflow.ts +0 -161
  176. package/src/core/log-prune.test.ts +0 -58
  177. package/src/core/log-prune.ts +0 -43
  178. package/src/core/preflight.test.ts +0 -49
  179. package/src/core/preflight.ts +0 -89
  180. package/src/core/run-context.test.ts +0 -256
  181. package/src/core/run-context.ts +0 -211
  182. package/src/core/run-state.test.ts +0 -98
  183. package/src/core/run-state.ts +0 -122
  184. package/src/core/scheduler.test.ts +0 -83
  185. package/src/core/scheduler.ts +0 -42
  186. package/src/core/task-executor.ts +0 -743
  187. package/src/core/trigger-errors.ts +0 -15
  188. package/src/dag.test.ts +0 -56
  189. package/src/dag.ts +0 -245
  190. package/src/drivers/opencode.ts +0 -410
  191. package/src/engine-ports-mixed.test.ts +0 -156
  192. package/src/engine-ports.test.ts +0 -166
  193. package/src/engine-task-type.test.ts +0 -56
  194. package/src/engine.ts +0 -458
  195. package/src/hooks.ts +0 -193
  196. package/src/index.ts +0 -33
  197. package/src/logger.ts +0 -182
  198. package/src/middlewares/static-context.ts +0 -49
  199. package/src/pipeline-definition.ts +0 -5
  200. package/src/pipeline-runner.test.ts +0 -91
  201. package/src/pipeline-runner.ts +0 -194
  202. package/src/plugin-registry.test.ts +0 -382
  203. package/src/plugins.ts +0 -21
  204. package/src/ports.test.ts +0 -678
  205. package/src/ports.ts +0 -925
  206. package/src/prompt-doc.test.ts +0 -174
  207. package/src/prompt-doc.ts +0 -169
  208. package/src/registry.ts +0 -353
  209. package/src/runner.test.ts +0 -142
  210. package/src/runner.ts +0 -666
  211. package/src/runtime.ts +0 -20
  212. package/src/schema-ports.test.ts +0 -172
  213. package/src/schema.test.ts +0 -213
  214. package/src/schema.ts +0 -379
  215. package/src/tagma.test.ts +0 -155
  216. package/src/tagma.ts +0 -62
  217. package/src/task-ref.test.ts +0 -401
  218. package/src/task-ref.ts +0 -121
  219. package/src/triggers/file.ts +0 -164
  220. package/src/triggers/manual.ts +0 -86
  221. package/src/types.ts +0 -18
  222. package/src/utils-api.ts +0 -8
  223. package/src/utils.test.ts +0 -28
  224. package/src/utils.ts +0 -203
  225. package/src/validate-raw-plugin-types.test.ts +0 -60
  226. package/src/validate-raw-ports.test.ts +0 -136
  227. package/src/validate-raw.ts +0 -852
  228. package/src/yaml-compiler.test.ts +0 -108
  229. package/src/yaml-compiler.ts +0 -110
  230. package/src/yaml.ts +0 -11
@@ -1,161 +0,0 @@
1
- import type {
2
- PortDef,
3
- TaskConfig,
4
- TaskInputBindings,
5
- TaskOutputBindings,
6
- TaskPorts,
7
- TaskResult,
8
- } from '../types';
9
- import {
10
- extractTaskBindingOutputs,
11
- extractTaskOutputs,
12
- inferPromptPorts,
13
- } from '../ports';
14
- import type { RunContext } from './run-context';
15
-
16
- function isPromptTaskConfig(
17
- task: TaskConfig,
18
- ): task is TaskConfig & { readonly prompt: string; readonly command?: undefined } {
19
- return task.prompt !== undefined && task.command === undefined;
20
- }
21
-
22
- function isCommandTaskConfig(
23
- task: TaskConfig,
24
- ): task is TaskConfig & { readonly command: string; readonly prompt?: undefined } {
25
- return task.command !== undefined && task.prompt === undefined;
26
- }
27
-
28
- function inputBindingsToPorts(bindings: TaskInputBindings | undefined): PortDef[] | undefined {
29
- if (!bindings || Object.keys(bindings).length === 0) return undefined;
30
- return Object.entries(bindings).map(([name, binding]) => ({
31
- name,
32
- type: binding.type ?? 'json',
33
- ...(binding.description ? { description: binding.description } : {}),
34
- ...(binding.required !== undefined ? { required: binding.required } : {}),
35
- ...(binding.default !== undefined ? { default: binding.default } : {}),
36
- ...(binding.enum ? { enum: [...binding.enum] } : {}),
37
- ...(binding.from ? { from: binding.from } : {}),
38
- }));
39
- }
40
-
41
- function outputBindingsToPorts(bindings: TaskOutputBindings | undefined): PortDef[] | undefined {
42
- if (!bindings || Object.keys(bindings).length === 0) return undefined;
43
- return Object.entries(bindings).map(([name, binding]) => ({
44
- name,
45
- type: binding.type ?? 'json',
46
- ...(binding.description ? { description: binding.description } : {}),
47
- ...(binding.default !== undefined ? { default: binding.default } : {}),
48
- ...(binding.enum ? { enum: [...binding.enum] } : {}),
49
- }));
50
- }
51
-
52
- function taskBindingsAsPorts(task: TaskConfig): TaskPorts | undefined {
53
- const inputs = inputBindingsToPorts(task.inputs);
54
- const outputs = outputBindingsToPorts(task.outputs);
55
- if (!inputs && !outputs) return undefined;
56
- return {
57
- ...(inputs ? { inputs } : {}),
58
- ...(outputs ? { outputs } : {}),
59
- };
60
- }
61
-
62
- export type EffectivePortsResult =
63
- | {
64
- readonly kind: 'ready';
65
- readonly isPromptTask: boolean;
66
- readonly effectivePorts: TaskPorts | undefined;
67
- }
68
- | {
69
- readonly kind: 'blocked';
70
- readonly reason: string;
71
- };
72
-
73
- export function inferEffectivePorts(
74
- ctx: RunContext,
75
- taskId: string,
76
- ): EffectivePortsResult {
77
- const node = ctx.dag.nodes.get(taskId)!;
78
- const task = node.task;
79
- const isPromptTask = isPromptTaskConfig(task);
80
-
81
- if (!isPromptTask) {
82
- return { kind: 'ready', isPromptTask: false, effectivePorts: taskBindingsAsPorts(task) };
83
- }
84
-
85
- const inference = inferPromptPorts({
86
- upstreams: node.dependsOn.map((upstreamId) => {
87
- const upstream = ctx.dag.nodes.get(upstreamId);
88
- const isUpstreamCommand = upstream ? isCommandTaskConfig(upstream.task) : false;
89
- return {
90
- taskId: upstreamId,
91
- outputs: isUpstreamCommand ? outputBindingsToPorts(upstream?.task.outputs) : undefined,
92
- };
93
- }),
94
- downstreams: (ctx.directDownstreams.get(taskId) ?? []).map((downstreamId) => {
95
- const downstream = ctx.dag.nodes.get(downstreamId);
96
- const isDownstreamCommand = downstream ? isCommandTaskConfig(downstream.task) : false;
97
- return {
98
- taskId: downstreamId,
99
- inputs: isDownstreamCommand ? inputBindingsToPorts(downstream?.task.inputs) : undefined,
100
- };
101
- }),
102
- });
103
-
104
- if (inference.inputConflicts.length > 0 || inference.outputConflicts.length > 0) {
105
- const lines: string[] = [];
106
- for (const conflict of inference.inputConflicts) lines.push(conflict.reason);
107
- for (const conflict of inference.outputConflicts) lines.push(conflict.reason);
108
- return { kind: 'blocked', reason: lines.join('\n') };
109
- }
110
-
111
- return { kind: 'ready', isPromptTask: true, effectivePorts: inference.ports };
112
- }
113
-
114
- export interface ExtractSuccessfulOutputsOptions {
115
- readonly task: TaskConfig;
116
- readonly effectivePorts: TaskPorts | undefined;
117
- readonly result: TaskResult;
118
- }
119
-
120
- export interface ExtractSuccessfulOutputsResult {
121
- readonly outputs: Readonly<Record<string, unknown>> | null;
122
- readonly bindingDiagnostic: string | null;
123
- readonly portDiagnostic: string | null;
124
- }
125
-
126
- export function extractSuccessfulOutputs(
127
- options: ExtractSuccessfulOutputsOptions,
128
- ): ExtractSuccessfulOutputsResult {
129
- const { task, effectivePorts, result } = options;
130
- let extractedOutputs: Readonly<Record<string, unknown>> | null = null;
131
-
132
- const bindingExtraction = extractTaskBindingOutputs(
133
- task.outputs,
134
- result.stdout,
135
- result.stderr,
136
- result.normalizedOutput,
137
- );
138
- if (task.outputs && Object.keys(task.outputs).length > 0) {
139
- extractedOutputs = bindingExtraction.outputs;
140
- }
141
-
142
- if ((!task.outputs || Object.keys(task.outputs).length === 0) && effectivePorts?.outputs?.length) {
143
- const portExtraction = extractTaskOutputs(
144
- effectivePorts,
145
- result.stdout,
146
- result.normalizedOutput,
147
- );
148
- extractedOutputs = portExtraction.outputs;
149
- return {
150
- outputs: extractedOutputs,
151
- bindingDiagnostic: bindingExtraction.diagnostic,
152
- portDiagnostic: portExtraction.diagnostic,
153
- };
154
- }
155
-
156
- return {
157
- outputs: extractedOutputs,
158
- bindingDiagnostic: bindingExtraction.diagnostic,
159
- portDiagnostic: null,
160
- };
161
- }
@@ -1,58 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { mkdtempSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { pruneLogDirs } from './log-prune';
6
-
7
- function fixture(): string {
8
- return mkdtempSync(join(tmpdir(), 'tagma-prune-'));
9
- }
10
-
11
- describe('pruneLogDirs', () => {
12
- test('returns silently when logsDir does not exist', async () => {
13
- const root = fixture();
14
- try {
15
- await expect(
16
- pruneLogDirs(join(root, 'nope'), 5, 'run_live'),
17
- ).resolves.toBeUndefined();
18
- } finally {
19
- rmSync(root, { recursive: true, force: true });
20
- }
21
- });
22
-
23
- test('keeps the live run plus (keep-1) most recent historical runs', async () => {
24
- const root = fixture();
25
- try {
26
- for (const id of ['run_001', 'run_002', 'run_003', 'run_004', 'run_005']) {
27
- mkdirSync(join(root, id));
28
- }
29
- await pruneLogDirs(root, 3, 'run_005'); // keep=3 → 1 live + 2 historical
30
- expect(readdirSync(root).sort()).toEqual(['run_003', 'run_004', 'run_005']);
31
- } finally {
32
- rmSync(root, { recursive: true, force: true });
33
- }
34
- });
35
-
36
- test('never deletes the excluded live runId even if it would be pruned', async () => {
37
- const root = fixture();
38
- try {
39
- for (const id of ['run_001', 'run_002', 'run_003']) mkdirSync(join(root, id));
40
- await pruneLogDirs(root, 1, 'run_001');
41
- expect(readdirSync(root).sort()).toEqual(['run_001']);
42
- } finally {
43
- rmSync(root, { recursive: true, force: true });
44
- }
45
- });
46
-
47
- test('ignores entries that do not look like run dirs', async () => {
48
- const root = fixture();
49
- try {
50
- mkdirSync(join(root, 'run_001'));
51
- mkdirSync(join(root, 'not_a_run'));
52
- await pruneLogDirs(root, 1, 'run_001');
53
- expect(readdirSync(root).sort()).toEqual(['not_a_run', 'run_001']);
54
- } finally {
55
- rmSync(root, { recursive: true, force: true });
56
- }
57
- });
58
- });
@@ -1,43 +0,0 @@
1
- import { readdir, rm } from 'node:fs/promises';
2
- import { resolve } from 'node:path';
3
-
4
- /**
5
- * Delete the oldest subdirectories under `logsDir`, keeping only the
6
- * most recent `keep` total runs (including the currently-live run
7
- * identified by `excludeRunId`). Directories are sorted
8
- * lexicographically; because runIds are prefixed with a base-36
9
- * timestamp, lexicographic order equals chronological order.
10
- *
11
- * `excludeRunId` is always skipped from deletion even if it would
12
- * otherwise be pruned — this prevents a concurrent run from removing a
13
- * live log directory that is still in use.
14
- *
15
- * The live run occupies one slot out of `keep`, so the maximum number
16
- * of *historical* dirs to retain is `keep - 1`.
17
- */
18
- export async function pruneLogDirs(
19
- logsDir: string,
20
- keep: number,
21
- excludeRunId: string,
22
- ): Promise<void> {
23
- let entries: string[];
24
- try {
25
- entries = await readdir(logsDir);
26
- } catch {
27
- return; // logsDir doesn't exist yet
28
- }
29
-
30
- const runDirs = entries
31
- .filter((e) => e.startsWith('run_') && e !== excludeRunId)
32
- .sort();
33
- const historyKeep = Math.max(0, keep - 1);
34
- const toDelete = runDirs.slice(0, Math.max(0, runDirs.length - historyKeep));
35
-
36
- await Promise.all(
37
- toDelete.map((dir) =>
38
- rm(resolve(logsDir, dir), { recursive: true, force: true }).catch(() => {
39
- // Ignore deletion errors — stale dirs are better than a crash
40
- }),
41
- ),
42
- );
43
- }
@@ -1,49 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { preflight } from './preflight';
3
- import { buildDag } from '../dag';
4
- import { PluginRegistry } from '../registry';
5
- import { bootstrapBuiltins } from '../bootstrap';
6
- import type { PipelineConfig } from '../types';
7
-
8
- function emptyConfig(overrides: Partial<PipelineConfig> = {}): PipelineConfig {
9
- return {
10
- name: 'p',
11
- tracks: [{ id: 't', name: 'T', tasks: [] }],
12
- ...overrides,
13
- };
14
- }
15
-
16
- describe('preflight', () => {
17
- test('throws when a referenced driver is not registered', () => {
18
- const reg = new PluginRegistry();
19
- const cfg = emptyConfig({
20
- tracks: [
21
- { id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] },
22
- ],
23
- });
24
- expect(() => preflight(cfg, buildDag(cfg), reg)).toThrow(
25
- /driver "opencode" not registered/,
26
- );
27
- });
28
-
29
- test('passes when all referenced plugins are registered', () => {
30
- const reg = new PluginRegistry();
31
- bootstrapBuiltins(reg);
32
- const cfg = emptyConfig({
33
- tracks: [
34
- { id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] },
35
- ],
36
- });
37
- expect(() => preflight(cfg, buildDag(cfg), reg)).not.toThrow();
38
- });
39
-
40
- test('skips driver check for command-only tasks', () => {
41
- const reg = new PluginRegistry(); // no drivers registered
42
- const cfg = emptyConfig({
43
- tracks: [
44
- { id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo hi' }] },
45
- ],
46
- });
47
- expect(() => preflight(cfg, buildDag(cfg), reg)).not.toThrow();
48
- });
49
- });
@@ -1,89 +0,0 @@
1
- import type { PipelineConfig, TaskConfig, DriverPlugin } from '../types';
2
- import type { Dag } from '../dag';
3
- import type { PluginRegistry } from '../registry';
4
-
5
- function isCommandOnly(
6
- task: TaskConfig,
7
- ): task is TaskConfig & { readonly command: string; readonly prompt?: undefined } {
8
- return task.command !== undefined && task.prompt === undefined;
9
- }
10
-
11
- /**
12
- * Validate that every plugin referenced by the pipeline (drivers,
13
- * triggers, completions, middlewares) is registered, and that
14
- * `continue_from` is only used between drivers that can hand off via
15
- * sessionResume or text-injection. Throws with all errors aggregated
16
- * into one message so the caller sees every misconfiguration in a
17
- * single pass.
18
- */
19
- export function preflight(
20
- config: PipelineConfig,
21
- dag: Dag,
22
- registry: PluginRegistry,
23
- ): void {
24
- const errors: string[] = [];
25
-
26
- for (const [, node] of dag.nodes) {
27
- const task = node.task;
28
- const track = node.track;
29
- const driverName = task.driver ?? track.driver ?? config.driver ?? 'opencode';
30
-
31
- const isCommand = isCommandOnly(task);
32
-
33
- if (!isCommand && !registry.hasHandler('drivers', driverName)) {
34
- errors.push(`Task "${node.taskId}": driver "${driverName}" not registered`);
35
- }
36
-
37
- if (task.trigger && !registry.hasHandler('triggers', task.trigger.type)) {
38
- errors.push(
39
- `Task "${node.taskId}": trigger type "${task.trigger.type}" not registered`,
40
- );
41
- }
42
-
43
- if (task.completion && !registry.hasHandler('completions', task.completion.type)) {
44
- errors.push(
45
- `Task "${node.taskId}": completion type "${task.completion.type}" not registered`,
46
- );
47
- }
48
-
49
- const mws = task.middlewares ?? track.middlewares ?? [];
50
- for (const mw of mws) {
51
- if (!registry.hasHandler('middlewares', mw.type)) {
52
- errors.push(
53
- `Task "${node.taskId}": middleware type "${mw.type}" not registered`,
54
- );
55
- }
56
- }
57
-
58
- if (task.continue_from && registry.hasHandler('drivers', driverName)) {
59
- const driver = registry.getHandler<DriverPlugin>('drivers', driverName);
60
- if (!driver.capabilities.sessionResume) {
61
- const upstreamId = node.resolvedContinueFrom;
62
- if (upstreamId) {
63
- const upstream = dag.nodes.get(upstreamId);
64
- if (upstream) {
65
- const upstreamDriverName =
66
- upstream.task.driver ?? upstream.track.driver ?? config.driver ?? 'opencode';
67
- const upstreamDriver = registry.hasHandler('drivers', upstreamDriverName)
68
- ? registry.getHandler<DriverPlugin>('drivers', upstreamDriverName)
69
- : null;
70
- const canNormalize = typeof upstreamDriver?.parseResult === 'function';
71
-
72
- if (!canNormalize) {
73
- errors.push(
74
- `Task "${node.taskId}" uses continue_from: "${task.continue_from}", ` +
75
- `but upstream task "${upstreamId}" its driver ` +
76
- `does not implement parseResult for text-injection handoff. ` +
77
- `Use a driver with parseResult, or remove continue_from.`,
78
- );
79
- }
80
- }
81
- }
82
- }
83
- }
84
- }
85
-
86
- if (errors.length > 0) {
87
- throw new Error(`Preflight validation failed:\n - ${errors.join('\n - ')}`);
88
- }
89
- }
@@ -1,256 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { RunContext } from './run-context';
3
- import { buildDag } from '../dag';
4
- import type { PipelineConfig, RunEventPayload } from '../types';
5
- import type { PipelineInfo } from '../hooks';
6
- import type { TagmaRuntime } from '../runtime';
7
-
8
- const fakeRuntime: TagmaRuntime = {
9
- async runCommand() {
10
- throw new Error('fakeRuntime.runCommand should not be called by RunContext tests');
11
- },
12
- async runSpawn() {
13
- throw new Error('fakeRuntime.runSpawn should not be called by RunContext tests');
14
- },
15
- };
16
-
17
- function makeContext(overrides: Partial<{
18
- config: PipelineConfig;
19
- onEvent: (e: RunEventPayload) => void;
20
- }> = {}): { ctx: RunContext; events: RunEventPayload[] } {
21
- const config: PipelineConfig = overrides.config ?? {
22
- name: 'p',
23
- tracks: [
24
- {
25
- id: 't',
26
- name: 'T',
27
- tasks: [
28
- { id: 'a', name: 'A', command: 'echo a' },
29
- { id: 'b', name: 'B', command: 'echo b', depends_on: ['a'] },
30
- ],
31
- },
32
- ],
33
- };
34
- const events: RunEventPayload[] = [];
35
- const onEvent = overrides.onEvent ?? ((e: RunEventPayload) => { events.push(e); });
36
- const ctx = new RunContext({
37
- runId: 'run_test',
38
- dag: buildDag(config),
39
- config,
40
- workDir: '/tmp/wd',
41
- pipelineInfo: { name: config.name, run_id: 'run_test', started_at: '2026-04-26T00:00:00Z' } as PipelineInfo,
42
- onEvent,
43
- runtime: fakeRuntime,
44
- });
45
- return { ctx, events };
46
- }
47
-
48
- describe('RunContext constructor', () => {
49
- test('initializes one idle state per dag node', () => {
50
- const { ctx } = makeContext();
51
- expect(ctx.states.size).toBe(2);
52
- expect(ctx.states.get('t.a')!.status).toBe('idle');
53
- expect(ctx.states.get('t.b')!.status).toBe('idle');
54
- });
55
-
56
- test('initializes all state maps as empty', () => {
57
- const { ctx } = makeContext();
58
- expect(ctx.sessionMap.size).toBe(0);
59
- expect(ctx.normalizedMap.size).toBe(0);
60
- expect(ctx.outputValuesMap.size).toBe(0);
61
- expect(ctx.bindingDataMap.size).toBe(0);
62
- expect(ctx.resolvedInputsMap.size).toBe(0);
63
- });
64
-
65
- test('computes directDownstreams reverse adjacency from dag', () => {
66
- const { ctx } = makeContext();
67
- expect([...ctx.directDownstreams.get('t.a')!]).toEqual(['t.b']);
68
- expect([...ctx.directDownstreams.get('t.b')!]).toEqual([]);
69
- });
70
-
71
- test('starts with abortReason null and a fresh AbortController', () => {
72
- const { ctx } = makeContext();
73
- expect(ctx.abortReason).toBeNull();
74
- expect(ctx.abortController.signal.aborted).toBe(false);
75
- });
76
- });
77
-
78
- describe('RunContext.emit', () => {
79
- test('forwards events to onEvent', () => {
80
- const { ctx, events } = makeContext();
81
- ctx.emit({ type: 'run_end', runId: 'run_test', success: true, abortReason: null });
82
- expect(events).toHaveLength(1);
83
- expect(events[0]).toEqual({ type: 'run_end', runId: 'run_test', success: true, abortReason: null });
84
- });
85
-
86
- test('is a no-op when onEvent is undefined', () => {
87
- const config: PipelineConfig = {
88
- name: 'p',
89
- tracks: [{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo a' }] }],
90
- };
91
- const ctx = new RunContext({
92
- runId: 'run_test',
93
- dag: buildDag(config),
94
- config,
95
- workDir: '/tmp/wd',
96
- pipelineInfo: { name: 'p', run_id: 'run_test', started_at: 'now' } as PipelineInfo,
97
- runtime: fakeRuntime,
98
- });
99
- expect(() => ctx.emit({ type: 'run_end', runId: 'run_test', success: true, abortReason: null })).not.toThrow();
100
- });
101
- });
102
-
103
- describe('RunContext.setTaskStatus', () => {
104
- test('transitions a non-terminal task and emits task_update', () => {
105
- const { ctx, events } = makeContext();
106
- ctx.setTaskStatus('t.a', 'waiting');
107
- expect(ctx.states.get('t.a')!.status).toBe('waiting');
108
- expect(events).toHaveLength(1);
109
- expect(events[0].type).toBe('task_update');
110
- if (events[0].type === 'task_update') {
111
- expect(events[0].taskId).toBe('t.a');
112
- expect(events[0].status).toBe('waiting');
113
- }
114
- });
115
-
116
- test('refuses to re-transition a terminal task (terminal lock)', () => {
117
- const { ctx, events } = makeContext();
118
- ctx.setTaskStatus('t.a', 'success');
119
- events.length = 0;
120
- ctx.setTaskStatus('t.a', 'failed');
121
- expect(ctx.states.get('t.a')!.status).toBe('success');
122
- expect(events).toHaveLength(0);
123
- });
124
-
125
- test('echoes resolvedInputs and outputs from the maps in the emitted event', () => {
126
- const { ctx, events } = makeContext();
127
- ctx.resolvedInputsMap.set('t.a', { x: 1 });
128
- ctx.outputValuesMap.set('t.a', { y: 2 });
129
- ctx.setTaskStatus('t.a', 'running');
130
- if (events[0].type === 'task_update') {
131
- expect(events[0].inputs).toEqual({ x: 1 });
132
- expect(events[0].outputs).toEqual({ y: 2 });
133
- } else {
134
- throw new Error('expected task_update');
135
- }
136
- });
137
- });
138
-
139
- describe('RunContext.getOnFailure', () => {
140
- test('returns the track-level on_failure setting', () => {
141
- const config: PipelineConfig = {
142
- name: 'p',
143
- tracks: [
144
- {
145
- id: 't',
146
- name: 'T',
147
- on_failure: 'stop_all',
148
- tasks: [{ id: 'a', name: 'A', command: 'echo a' }],
149
- },
150
- ],
151
- };
152
- const { ctx } = makeContext({ config });
153
- expect(ctx.getOnFailure('t.a')).toBe('stop_all');
154
- });
155
-
156
- test('defaults to skip_downstream when track does not specify', () => {
157
- const { ctx } = makeContext();
158
- expect(ctx.getOnFailure('t.a')).toBe('skip_downstream');
159
- });
160
- });
161
-
162
- describe('RunContext.isDependencySatisfied', () => {
163
- test('returns satisfied for success', () => {
164
- const { ctx } = makeContext();
165
- ctx.states.get('t.a')!.status = 'success';
166
- expect(ctx.isDependencySatisfied('t.a')).toBe('satisfied');
167
- });
168
-
169
- test('returns skip for skipped', () => {
170
- const { ctx } = makeContext();
171
- ctx.states.get('t.a')!.status = 'skipped';
172
- expect(ctx.isDependencySatisfied('t.a')).toBe('skip');
173
- });
174
-
175
- test('returns skip for failed under default policy, satisfied under ignore', () => {
176
- const cfgSkip: PipelineConfig = {
177
- name: 'p',
178
- tracks: [{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo a' }] }],
179
- };
180
- const cfgIgnore: PipelineConfig = {
181
- name: 'p',
182
- tracks: [
183
- {
184
- id: 't',
185
- name: 'T',
186
- on_failure: 'ignore',
187
- tasks: [{ id: 'a', name: 'A', command: 'echo a' }],
188
- },
189
- ],
190
- };
191
- const a = makeContext({ config: cfgSkip }).ctx;
192
- a.states.get('t.a')!.status = 'failed';
193
- expect(a.isDependencySatisfied('t.a')).toBe('skip');
194
-
195
- const b = makeContext({ config: cfgIgnore }).ctx;
196
- b.states.get('t.a')!.status = 'failed';
197
- expect(b.isDependencySatisfied('t.a')).toBe('satisfied');
198
- });
199
-
200
- test('returns unsatisfied for non-terminal statuses', () => {
201
- const { ctx } = makeContext();
202
- ctx.states.get('t.a')!.status = 'running';
203
- expect(ctx.isDependencySatisfied('t.a')).toBe('unsatisfied');
204
- });
205
- });
206
-
207
- describe('RunContext.applyStopAll', () => {
208
- test('aborts the controller, sets abortReason, marks waiting tasks as skipped', () => {
209
- const { ctx } = makeContext();
210
- ctx.states.get('t.a')!.status = 'waiting';
211
- ctx.states.get('t.b')!.status = 'waiting';
212
- ctx.applyStopAll();
213
- expect(ctx.abortReason).toBe('stop_all');
214
- expect(ctx.abortController.signal.aborted).toBe(true);
215
- expect(ctx.states.get('t.a')!.status).toBe('skipped');
216
- expect(ctx.states.get('t.b')!.status).toBe('skipped');
217
- });
218
-
219
- test('does not overwrite an existing abortReason', () => {
220
- const { ctx } = makeContext();
221
- ctx.abortReason = 'timeout';
222
- ctx.applyStopAll();
223
- expect(ctx.abortReason).toBe('timeout');
224
- expect(ctx.abortController.signal.aborted).toBe(true);
225
- });
226
-
227
- test('leaves running and terminal tasks alone', () => {
228
- const { ctx } = makeContext();
229
- ctx.states.get('t.a')!.status = 'running';
230
- ctx.states.get('t.b')!.status = 'success';
231
- ctx.applyStopAll();
232
- expect(ctx.states.get('t.a')!.status).toBe('running');
233
- expect(ctx.states.get('t.b')!.status).toBe('success');
234
- });
235
- });
236
-
237
- describe('RunContext.buildTaskInfoObj / trackInfoOf', () => {
238
- test('buildTaskInfoObj reports type=command for command tasks', () => {
239
- const { ctx } = makeContext();
240
- expect(ctx.buildTaskInfoObj('t.a').type).toBe('command');
241
- });
242
-
243
- test('buildTaskInfoObj reports type=ai for prompt tasks', () => {
244
- const config: PipelineConfig = {
245
- name: 'p',
246
- tracks: [{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] }],
247
- };
248
- const { ctx } = makeContext({ config });
249
- expect(ctx.buildTaskInfoObj('t.a').type).toBe('ai');
250
- });
251
-
252
- test('trackInfoOf returns the track id and name', () => {
253
- const { ctx } = makeContext();
254
- expect(ctx.trackInfoOf('t.a')).toEqual({ id: 't', name: 'T' });
255
- });
256
- });