@tagma/sdk 0.7.4 → 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 (190) hide show
  1. package/README.md +60 -53
  2. package/dist/completions/file-exists.js +1 -1
  3. package/dist/completions/file-exists.js.map +1 -1
  4. package/dist/completions/output-check.d.ts.map +1 -1
  5. package/dist/completions/output-check.js +17 -4
  6. package/dist/completions/output-check.js.map +1 -1
  7. package/dist/config.d.ts +4 -4
  8. package/dist/config.d.ts.map +1 -1
  9. package/dist/config.js +2 -2
  10. package/dist/config.js.map +1 -1
  11. package/dist/dataflow.d.ts +3 -0
  12. package/dist/dataflow.d.ts.map +1 -0
  13. package/dist/dataflow.js +2 -0
  14. package/dist/dataflow.js.map +1 -0
  15. package/dist/drivers/opencode.d.ts.map +1 -1
  16. package/dist/drivers/opencode.js +23 -71
  17. package/dist/drivers/opencode.js.map +1 -1
  18. package/dist/middlewares/static-context.d.ts.map +1 -1
  19. package/dist/middlewares/static-context.js +1 -2
  20. package/dist/middlewares/static-context.js.map +1 -1
  21. package/dist/pipeline-runner.d.ts.map +1 -1
  22. package/dist/pipeline-runner.js +2 -2
  23. package/dist/pipeline-runner.js.map +1 -1
  24. package/dist/schema.d.ts.map +1 -1
  25. package/dist/schema.js +3 -4
  26. package/dist/schema.js.map +1 -1
  27. package/dist/triggers/file.d.ts.map +1 -1
  28. package/dist/triggers/file.js +1 -2
  29. package/dist/triggers/file.js.map +1 -1
  30. package/dist/triggers/manual.d.ts.map +1 -1
  31. package/dist/triggers/manual.js +1 -2
  32. package/dist/triggers/manual.js.map +1 -1
  33. package/dist/types.d.ts +1 -2
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/types.js +1 -12
  36. package/dist/types.js.map +1 -1
  37. package/dist/utils-api.d.ts +1 -1
  38. package/dist/utils-api.d.ts.map +1 -1
  39. package/dist/utils-api.js +1 -1
  40. package/dist/utils-api.js.map +1 -1
  41. package/dist/validate-raw.d.ts.map +1 -1
  42. package/dist/validate-raw.js +5 -12
  43. package/dist/validate-raw.js.map +1 -1
  44. package/package.json +11 -24
  45. package/dist/adapters/stdin-approval.d.ts +0 -2
  46. package/dist/adapters/stdin-approval.d.ts.map +0 -1
  47. package/dist/adapters/stdin-approval.js +0 -2
  48. package/dist/adapters/stdin-approval.js.map +0 -1
  49. package/dist/adapters/websocket-approval.d.ts +0 -2
  50. package/dist/adapters/websocket-approval.d.ts.map +0 -1
  51. package/dist/adapters/websocket-approval.js +0 -2
  52. package/dist/adapters/websocket-approval.js.map +0 -1
  53. package/dist/core/dataflow.d.ts +0 -23
  54. package/dist/core/dataflow.d.ts.map +0 -1
  55. package/dist/core/dataflow.js +0 -99
  56. package/dist/core/dataflow.js.map +0 -1
  57. package/dist/core/log-prune.d.ts +0 -16
  58. package/dist/core/log-prune.d.ts.map +0 -1
  59. package/dist/core/log-prune.js +0 -34
  60. package/dist/core/log-prune.js.map +0 -1
  61. package/dist/core/preflight.d.ts +0 -13
  62. package/dist/core/preflight.d.ts.map +0 -1
  63. package/dist/core/preflight.js +0 -61
  64. package/dist/core/preflight.js.map +0 -1
  65. package/dist/core/run-context.d.ts +0 -55
  66. package/dist/core/run-context.d.ts.map +0 -1
  67. package/dist/core/run-context.js +0 -158
  68. package/dist/core/run-context.js.map +0 -1
  69. package/dist/core/run-state.d.ts +0 -25
  70. package/dist/core/run-state.d.ts.map +0 -1
  71. package/dist/core/run-state.js +0 -93
  72. package/dist/core/run-state.js.map +0 -1
  73. package/dist/core/scheduler.d.ts +0 -13
  74. package/dist/core/scheduler.d.ts.map +0 -1
  75. package/dist/core/scheduler.js +0 -35
  76. package/dist/core/scheduler.js.map +0 -1
  77. package/dist/core/task-executor.d.ts +0 -13
  78. package/dist/core/task-executor.d.ts.map +0 -1
  79. package/dist/core/task-executor.js +0 -610
  80. package/dist/core/task-executor.js.map +0 -1
  81. package/dist/core/trigger-errors.d.ts +0 -9
  82. package/dist/core/trigger-errors.d.ts.map +0 -1
  83. package/dist/core/trigger-errors.js +0 -15
  84. package/dist/core/trigger-errors.js.map +0 -1
  85. package/dist/dag.d.ts +0 -45
  86. package/dist/dag.d.ts.map +0 -1
  87. package/dist/dag.js +0 -177
  88. package/dist/dag.js.map +0 -1
  89. package/dist/hooks.d.ts +0 -73
  90. package/dist/hooks.d.ts.map +0 -1
  91. package/dist/hooks.js +0 -106
  92. package/dist/hooks.js.map +0 -1
  93. package/dist/pipeline-definition.d.ts +0 -3
  94. package/dist/pipeline-definition.d.ts.map +0 -1
  95. package/dist/pipeline-definition.js +0 -4
  96. package/dist/pipeline-definition.js.map +0 -1
  97. package/dist/ports.d.ts +0 -196
  98. package/dist/ports.d.ts.map +0 -1
  99. package/dist/ports.js +0 -688
  100. package/dist/ports.js.map +0 -1
  101. package/dist/prompt-doc.d.ts +0 -70
  102. package/dist/prompt-doc.d.ts.map +0 -1
  103. package/dist/prompt-doc.js +0 -154
  104. package/dist/prompt-doc.js.map +0 -1
  105. package/dist/registry.d.ts +0 -3
  106. package/dist/registry.d.ts.map +0 -1
  107. package/dist/registry.js +0 -2
  108. package/dist/registry.js.map +0 -1
  109. package/dist/task-ref.d.ts +0 -55
  110. package/dist/task-ref.d.ts.map +0 -1
  111. package/dist/task-ref.js +0 -103
  112. package/dist/task-ref.js.map +0 -1
  113. package/dist/utils.d.ts +0 -13
  114. package/dist/utils.d.ts.map +0 -1
  115. package/dist/utils.js +0 -177
  116. package/dist/utils.js.map +0 -1
  117. package/src/adapters/stdin-approval.ts +0 -1
  118. package/src/adapters/websocket-approval.ts +0 -1
  119. package/src/approval.ts +0 -9
  120. package/src/bootstrap.ts +0 -55
  121. package/src/completions/exit-code.ts +0 -34
  122. package/src/completions/file-exists.ts +0 -66
  123. package/src/completions/output-check.test.ts +0 -50
  124. package/src/completions/output-check.ts +0 -92
  125. package/src/config-ops.test.ts +0 -70
  126. package/src/config-ops.ts +0 -328
  127. package/src/config.ts +0 -26
  128. package/src/core/dataflow.test.ts +0 -166
  129. package/src/core/dataflow.ts +0 -161
  130. package/src/core/log-prune.test.ts +0 -58
  131. package/src/core/log-prune.ts +0 -43
  132. package/src/core/preflight.test.ts +0 -49
  133. package/src/core/preflight.ts +0 -89
  134. package/src/core/run-context.test.ts +0 -291
  135. package/src/core/run-context.ts +0 -211
  136. package/src/core/run-state.test.ts +0 -98
  137. package/src/core/run-state.ts +0 -122
  138. package/src/core/scheduler.test.ts +0 -83
  139. package/src/core/scheduler.ts +0 -42
  140. package/src/core/task-executor.ts +0 -752
  141. package/src/core/trigger-errors.ts +0 -15
  142. package/src/dag.test.ts +0 -56
  143. package/src/dag.ts +0 -245
  144. package/src/drivers/opencode.ts +0 -410
  145. package/src/engine-ports-mixed.test.ts +0 -182
  146. package/src/engine-ports.test.ts +0 -210
  147. package/src/engine-task-type.test.ts +0 -56
  148. package/src/engine.ts +0 -32
  149. package/src/hooks.ts +0 -193
  150. package/src/index.ts +0 -31
  151. package/src/logger.ts +0 -2
  152. package/src/middlewares/static-context.ts +0 -49
  153. package/src/package-split.test.ts +0 -15
  154. package/src/pipeline-definition.ts +0 -5
  155. package/src/pipeline-runner.test.ts +0 -144
  156. package/src/pipeline-runner.ts +0 -194
  157. package/src/plugin-registry.test.ts +0 -448
  158. package/src/plugins.ts +0 -21
  159. package/src/ports.test.ts +0 -678
  160. package/src/ports.ts +0 -925
  161. package/src/prompt-doc.test.ts +0 -174
  162. package/src/prompt-doc.ts +0 -169
  163. package/src/registry.ts +0 -7
  164. package/src/runner.test.ts +0 -142
  165. package/src/runner.ts +0 -1
  166. package/src/runtime/adapters/stdin-approval.ts +0 -1
  167. package/src/runtime/adapters/websocket-approval.ts +0 -1
  168. package/src/runtime/bun-process-runner.ts +0 -1
  169. package/src/runtime-adapters.test.ts +0 -10
  170. package/src/runtime.ts +0 -12
  171. package/src/schema-ports.test.ts +0 -172
  172. package/src/schema.test.ts +0 -213
  173. package/src/schema.ts +0 -379
  174. package/src/tagma.test.ts +0 -317
  175. package/src/tagma.ts +0 -67
  176. package/src/task-ref.test.ts +0 -401
  177. package/src/task-ref.ts +0 -121
  178. package/src/triggers/file.test.ts +0 -79
  179. package/src/triggers/file.ts +0 -131
  180. package/src/triggers/manual.ts +0 -86
  181. package/src/types.ts +0 -18
  182. package/src/utils-api.ts +0 -8
  183. package/src/utils.test.ts +0 -28
  184. package/src/utils.ts +0 -203
  185. package/src/validate-raw-plugin-types.test.ts +0 -60
  186. package/src/validate-raw-ports.test.ts +0 -136
  187. package/src/validate-raw.ts +0 -852
  188. package/src/yaml-compiler.test.ts +0 -108
  189. package/src/yaml-compiler.ts +0 -110
  190. package/src/yaml.ts +0 -11
@@ -1,211 +0,0 @@
1
- import type {
2
- AbortReason,
3
- OnFailure,
4
- Permissions,
5
- PipelineConfig,
6
- RunEventPayload,
7
- TaskConfig,
8
- TaskState,
9
- TaskStatus,
10
- } from '../types';
11
- import type { Dag } from '../dag';
12
- import type { UpstreamBindingData } from '../ports';
13
- import {
14
- executeHook,
15
- buildTaskContext,
16
- type PipelineInfo,
17
- type TaskInfo,
18
- type TrackInfo,
19
- } from '../hooks';
20
- import type { TagmaRuntime } from '../runtime';
21
- import { isTerminal } from './run-state';
22
- import { nowISO } from '../utils';
23
-
24
- function isPromptTaskConfig(
25
- task: TaskConfig,
26
- ): task is TaskConfig & { readonly prompt: string; readonly command?: undefined } {
27
- return task.prompt !== undefined && task.command === undefined;
28
- }
29
-
30
- export interface RunContextOptions {
31
- readonly runId: string;
32
- readonly dag: Dag;
33
- readonly config: PipelineConfig;
34
- readonly workDir: string;
35
- readonly pipelineInfo: PipelineInfo;
36
- readonly onEvent?: (event: RunEventPayload) => void;
37
- readonly runtime: TagmaRuntime;
38
- }
39
-
40
- /**
41
- * Per-run state container. Owns the maps and abort tracking that
42
- * `runPipeline` previously held as closure locals, plus the small
43
- * methods that read/write that state. Scheduler, dataflow, and
44
- * task-executor extractions in later phases pass `ctx` instead of
45
- * relying on closure capture.
46
- */
47
- export class RunContext {
48
- readonly runId: string;
49
- readonly dag: Dag;
50
- readonly config: PipelineConfig;
51
- readonly workDir: string;
52
- readonly pipelineInfo: PipelineInfo;
53
- readonly onEvent?: (event: RunEventPayload) => void;
54
- readonly runtime: TagmaRuntime;
55
-
56
- readonly states = new Map<string, TaskState>();
57
- readonly sessionMap = new Map<string, string>();
58
- readonly normalizedMap = new Map<string, string>();
59
- readonly outputValuesMap = new Map<string, Readonly<Record<string, unknown>>>();
60
- readonly bindingDataMap = new Map<string, UpstreamBindingData>();
61
- readonly resolvedInputsMap = new Map<string, Readonly<Record<string, unknown>>>();
62
- readonly directDownstreams: Map<string, string[]>;
63
- readonly abortController = new AbortController();
64
- abortReason: AbortReason | null = null;
65
-
66
- constructor(options: RunContextOptions) {
67
- this.runId = options.runId;
68
- this.dag = options.dag;
69
- this.config = options.config;
70
- this.workDir = options.workDir;
71
- this.pipelineInfo = options.pipelineInfo;
72
- this.onEvent = options.onEvent;
73
- this.runtime = options.runtime;
74
-
75
- for (const [id, node] of this.dag.nodes) {
76
- this.states.set(id, {
77
- config: node.task,
78
- trackConfig: node.track,
79
- status: 'idle',
80
- result: null,
81
- startedAt: null,
82
- finishedAt: null,
83
- });
84
- }
85
-
86
- this.directDownstreams = new Map<string, string[]>();
87
- for (const [id] of this.dag.nodes) this.directDownstreams.set(id, []);
88
- for (const [id, node] of this.dag.nodes) {
89
- for (const upstream of node.dependsOn) {
90
- const list = this.directDownstreams.get(upstream);
91
- if (list) list.push(id);
92
- }
93
- }
94
- }
95
-
96
- emit(event: RunEventPayload): void {
97
- this.onEvent?.(event);
98
- }
99
-
100
- setTaskStatus(taskId: string, newStatus: TaskStatus): void {
101
- const state = this.states.get(taskId)!;
102
- // Terminal lock: once a task reaches a terminal state it must not be
103
- // re-transitioned. This prevents stop_all from marking running tasks as
104
- // skipped and then having their in-flight processTask promise overwrite
105
- // that with success/failed, producing an invalid double transition.
106
- if (isTerminal(state.status)) return;
107
- state.status = newStatus;
108
- const result = state.result;
109
- const cfg = state.config;
110
- this.emit({
111
- type: 'task_update',
112
- runId: this.runId,
113
- taskId,
114
- status: newStatus,
115
- startedAt: state.startedAt ?? undefined,
116
- finishedAt: state.finishedAt ?? undefined,
117
- durationMs: result?.durationMs,
118
- exitCode: result?.exitCode,
119
- stdout: result?.stdout,
120
- stderr: result?.stderr,
121
- stdoutPath: result?.stdoutPath ?? null,
122
- stderrPath: result?.stderrPath ?? null,
123
- stdoutBytes: result?.stdoutBytes ?? null,
124
- stderrBytes: result?.stderrBytes ?? null,
125
- sessionId: result?.sessionId ?? null,
126
- normalizedOutput: result?.normalizedOutput ?? null,
127
- inputs: this.resolvedInputsMap.get(taskId) ?? null,
128
- outputs: this.outputValuesMap.get(taskId) ?? null,
129
- resolvedDriver: cfg.driver ?? null,
130
- resolvedModel: cfg.model ?? null,
131
- resolvedPermissions: (cfg.permissions as Permissions | undefined) ?? null,
132
- });
133
- }
134
-
135
- getOnFailure(taskId: string): OnFailure {
136
- return this.dag.nodes.get(taskId)?.track.on_failure ?? 'skip_downstream';
137
- }
138
-
139
- isDependencySatisfied(depId: string): 'satisfied' | 'unsatisfied' | 'skip' {
140
- const depState = this.states.get(depId);
141
- if (!depState) return 'skip';
142
- switch (depState.status) {
143
- case 'success':
144
- return 'satisfied';
145
- case 'skipped':
146
- return 'skip';
147
- case 'failed':
148
- case 'timeout':
149
- case 'blocked':
150
- return this.getOnFailure(depId) === 'ignore' ? 'satisfied' : 'skip';
151
- default:
152
- return 'unsatisfied';
153
- }
154
- }
155
-
156
- /**
157
- * H3: stop_all marks every still-waiting task across every track as
158
- * skipped and aborts in-flight tasks via the shared signal. The
159
- * terminal lock in setTaskStatus prevents any later re-transition
160
- * should a completed running task try to overwrite the skipped state.
161
- */
162
- applyStopAll(): void {
163
- if (this.abortReason === null) this.abortReason = 'stop_all';
164
- this.abortController.abort();
165
- for (const [id, state] of this.states) {
166
- if (state.status === 'waiting') {
167
- state.finishedAt = nowISO();
168
- this.setTaskStatus(id, 'skipped');
169
- }
170
- }
171
- }
172
-
173
- buildTaskInfoObj(taskId: string): TaskInfo {
174
- const state = this.states.get(taskId)!;
175
- return {
176
- id: taskId,
177
- name: state.config.name,
178
- type: isPromptTaskConfig(state.config) ? 'ai' : 'command',
179
- status: state.status,
180
- exit_code: state.result?.exitCode ?? null,
181
- duration_ms: state.result?.durationMs ?? null,
182
- stderr_path: state.result?.stderrPath ?? null,
183
- session_id: state.result?.sessionId ?? null,
184
- started_at: state.startedAt,
185
- finished_at: state.finishedAt,
186
- };
187
- }
188
-
189
- trackInfoOf(taskId: string): TrackInfo {
190
- const node = this.dag.nodes.get(taskId)!;
191
- return { id: node.track.id, name: node.track.name };
192
- }
193
-
194
- async fireHook(
195
- taskId: string,
196
- event: 'task_success' | 'task_failure',
197
- ): Promise<void> {
198
- await executeHook(
199
- this.config.hooks,
200
- event,
201
- buildTaskContext(
202
- event,
203
- this.pipelineInfo,
204
- this.trackInfoOf(taskId),
205
- this.buildTaskInfoObj(taskId),
206
- ),
207
- this.workDir,
208
- this.abortController.signal,
209
- );
210
- }
211
- }
@@ -1,98 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import {
3
- isTerminal,
4
- freezeStates,
5
- summarizeStates,
6
- toRunTaskState,
7
- } from './run-state';
8
- import type { TaskState, TaskStatus } from '../types';
9
-
10
- describe('isTerminal', () => {
11
- test('returns true for terminal statuses', () => {
12
- expect(isTerminal('success')).toBe(true);
13
- expect(isTerminal('failed')).toBe(true);
14
- expect(isTerminal('timeout')).toBe(true);
15
- expect(isTerminal('skipped')).toBe(true);
16
- expect(isTerminal('blocked')).toBe(true);
17
- });
18
- test('returns false for non-terminal statuses', () => {
19
- expect(isTerminal('idle')).toBe(false);
20
- expect(isTerminal('waiting')).toBe(false);
21
- expect(isTerminal('running')).toBe(false);
22
- });
23
- });
24
-
25
- function makeState(status: TaskStatus, opts: Partial<TaskState> = {}): TaskState {
26
- return {
27
- config: { id: 't', name: 't' } as TaskState['config'],
28
- trackConfig: { id: 'tr', name: 'tr', tasks: [] } as TaskState['trackConfig'],
29
- status,
30
- result: null,
31
- startedAt: null,
32
- finishedAt: null,
33
- ...opts,
34
- };
35
- }
36
-
37
- describe('freezeStates', () => {
38
- test('produces a deep copy that survives source mutation', () => {
39
- const src = new Map<string, TaskState>();
40
- src.set('a', makeState('success'));
41
- const frozen = freezeStates(src);
42
- src.get('a')!.status = 'failed';
43
- expect(frozen.get('a')!.status).toBe('success');
44
- });
45
-
46
- test('copies result object so mutation does not bleed through', () => {
47
- const src = new Map<string, TaskState>();
48
- src.set('a', makeState('success', {
49
- result: {
50
- exitCode: 0,
51
- stdout: 'x',
52
- stderr: '',
53
- stdoutPath: null,
54
- stderrPath: null,
55
- durationMs: 1,
56
- sessionId: null,
57
- normalizedOutput: null,
58
- outputs: null,
59
- } as TaskState['result'],
60
- }));
61
- const frozen = freezeStates(src);
62
- src.get('a')!.result!.stdout = 'mutated';
63
- expect(frozen.get('a')!.result!.stdout).toBe('x');
64
- });
65
- });
66
-
67
- describe('summarizeStates', () => {
68
- test('counts each terminal status into its own bucket', () => {
69
- const m = new Map<string, TaskState>();
70
- m.set('a', makeState('success'));
71
- m.set('b', makeState('failed'));
72
- m.set('c', makeState('skipped'));
73
- m.set('d', makeState('timeout'));
74
- m.set('e', makeState('blocked'));
75
- m.set('f', makeState('running'));
76
- expect(summarizeStates(m)).toEqual({
77
- total: 6,
78
- success: 1,
79
- failed: 1,
80
- skipped: 1,
81
- timeout: 1,
82
- blocked: 1,
83
- });
84
- });
85
- });
86
-
87
- describe('toRunTaskState', () => {
88
- test('projects null result onto wire shape with empty stdout/stderr', () => {
89
- const wire = toRunTaskState('t1', 'trk', 'Task 1', makeState('idle'));
90
- expect(wire.taskId).toBe('t1');
91
- expect(wire.trackId).toBe('trk');
92
- expect(wire.status).toBe('idle');
93
- expect(wire.stdout).toBe('');
94
- expect(wire.stderr).toBe('');
95
- expect(wire.exitCode).toBeNull();
96
- expect(wire.logs).toEqual([]);
97
- });
98
- });
@@ -1,122 +0,0 @@
1
- import type {
2
- TaskState,
3
- TaskStatus,
4
- RunTaskState,
5
- Permissions,
6
- } from '../types';
7
-
8
- export function isTerminal(status: TaskStatus): boolean {
9
- return (
10
- status === 'success' ||
11
- status === 'failed' ||
12
- status === 'timeout' ||
13
- status === 'skipped' ||
14
- status === 'blocked'
15
- );
16
- }
17
-
18
- /** Return a deep-copied, caller-safe snapshot of the states map. */
19
- export function freezeStates(
20
- states: Map<string, TaskState>,
21
- ): ReadonlyMap<string, TaskState> {
22
- const copy = new Map<string, TaskState>();
23
- for (const [id, s] of states) {
24
- copy.set(id, {
25
- config: { ...s.config },
26
- trackConfig: { ...s.trackConfig },
27
- status: s.status,
28
- result: s.result ? { ...s.result } : null,
29
- startedAt: s.startedAt,
30
- finishedAt: s.finishedAt,
31
- });
32
- }
33
- return copy;
34
- }
35
-
36
- export interface RunSummary {
37
- total: number;
38
- success: number;
39
- failed: number;
40
- skipped: number;
41
- timeout: number;
42
- blocked: number;
43
- }
44
-
45
- /**
46
- * Tally terminal task counts. Idle/waiting/running tasks are counted in
47
- * `total` but not in any per-status bucket — same semantics as the
48
- * original engine.ts summary loop.
49
- */
50
- export function summarizeStates(
51
- states: ReadonlyMap<string, TaskState>,
52
- ): RunSummary {
53
- const summary: RunSummary = {
54
- total: 0,
55
- success: 0,
56
- failed: 0,
57
- skipped: 0,
58
- timeout: 0,
59
- blocked: 0,
60
- };
61
- for (const [, state] of states) {
62
- summary.total++;
63
- switch (state.status) {
64
- case 'success':
65
- summary.success++;
66
- break;
67
- case 'failed':
68
- summary.failed++;
69
- break;
70
- case 'skipped':
71
- summary.skipped++;
72
- break;
73
- case 'timeout':
74
- summary.timeout++;
75
- break;
76
- case 'blocked':
77
- summary.blocked++;
78
- break;
79
- }
80
- }
81
- return summary;
82
- }
83
-
84
- /**
85
- * Project the engine's internal TaskState onto the wire RunTaskState
86
- * shape. `logs` / `totalLogCount` default to empty — they are populated
87
- * on the server side from streamed `task_log` events, not from state.
88
- */
89
- export function toRunTaskState(
90
- taskId: string,
91
- trackId: string,
92
- taskName: string,
93
- state: TaskState,
94
- ): RunTaskState {
95
- const result = state.result;
96
- const cfg = state.config;
97
- return {
98
- taskId,
99
- trackId,
100
- taskName,
101
- status: state.status,
102
- startedAt: state.startedAt,
103
- finishedAt: state.finishedAt,
104
- durationMs: result?.durationMs ?? null,
105
- exitCode: result?.exitCode ?? null,
106
- stdout: result?.stdout ?? '',
107
- stderr: result?.stderr ?? '',
108
- stdoutPath: result?.stdoutPath ?? null,
109
- stderrPath: result?.stderrPath ?? null,
110
- stdoutBytes: result?.stdoutBytes ?? null,
111
- stderrBytes: result?.stderrBytes ?? null,
112
- sessionId: result?.sessionId ?? null,
113
- normalizedOutput: result?.normalizedOutput ?? null,
114
- resolvedDriver: cfg.driver ?? null,
115
- resolvedModel: cfg.model ?? null,
116
- resolvedPermissions: (cfg.permissions as Permissions | undefined) ?? null,
117
- outputs: result?.outputs ?? null,
118
- inputs: null,
119
- logs: [],
120
- totalLogCount: 0,
121
- };
122
- }
@@ -1,83 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { buildDag } from '../dag';
3
- import type { PipelineConfig } from '../types';
4
- import { RunContext } from './run-context';
5
- import {
6
- allTasksTerminal,
7
- findLaunchableTasks,
8
- skipNonTerminalTasks,
9
- } from './scheduler';
10
-
11
- function makeContext(config: PipelineConfig): RunContext {
12
- return new RunContext({
13
- runId: 'run_scheduler',
14
- dag: buildDag(config),
15
- config,
16
- workDir: '/tmp/wd',
17
- pipelineInfo: {
18
- name: config.name,
19
- run_id: 'run_scheduler',
20
- started_at: '2026-04-26T00:00:00Z',
21
- },
22
- });
23
- }
24
-
25
- const chainConfig: PipelineConfig = {
26
- name: 'p',
27
- tracks: [
28
- {
29
- id: 't',
30
- name: 'T',
31
- tasks: [
32
- { id: 'a', name: 'A', command: 'echo a' },
33
- { id: 'b', name: 'B', command: 'echo b', depends_on: ['a'] },
34
- { id: 'c', name: 'C', command: 'echo c' },
35
- ],
36
- },
37
- ],
38
- };
39
-
40
- describe('findLaunchableTasks', () => {
41
- test('returns waiting roots that are not already running', () => {
42
- const ctx = makeContext(chainConfig);
43
- for (const state of ctx.states.values()) state.status = 'waiting';
44
-
45
- expect(findLaunchableTasks(ctx, new Set())).toEqual(['t.a', 't.c']);
46
- expect(findLaunchableTasks(ctx, new Set(['t.a']))).toEqual(['t.c']);
47
- });
48
-
49
- test('returns dependents only after dependencies are terminal', () => {
50
- const ctx = makeContext(chainConfig);
51
- for (const state of ctx.states.values()) state.status = 'waiting';
52
-
53
- expect(findLaunchableTasks(ctx, new Set())).not.toContain('t.b');
54
- ctx.states.get('t.a')!.status = 'success';
55
- expect(findLaunchableTasks(ctx, new Set())).toContain('t.b');
56
- });
57
- });
58
-
59
- describe('allTasksTerminal', () => {
60
- test('returns true only when every task is terminal', () => {
61
- const ctx = makeContext(chainConfig);
62
- for (const state of ctx.states.values()) state.status = 'success';
63
- expect(allTasksTerminal(ctx)).toBe(true);
64
- ctx.states.get('t.b')!.status = 'waiting';
65
- expect(allTasksTerminal(ctx)).toBe(false);
66
- });
67
- });
68
-
69
- describe('skipNonTerminalTasks', () => {
70
- test('marks every non-terminal task as skipped and leaves terminal tasks alone', () => {
71
- const ctx = makeContext(chainConfig);
72
- ctx.states.get('t.a')!.status = 'success';
73
- ctx.states.get('t.b')!.status = 'waiting';
74
- ctx.states.get('t.c')!.status = 'running';
75
-
76
- skipNonTerminalTasks(ctx, '2026-04-26T01:00:00Z');
77
-
78
- expect(ctx.states.get('t.a')!.status).toBe('success');
79
- expect(ctx.states.get('t.b')!.status).toBe('skipped');
80
- expect(ctx.states.get('t.b')!.finishedAt).toBe('2026-04-26T01:00:00Z');
81
- expect(ctx.states.get('t.c')!.status).toBe('skipped');
82
- });
83
- });
@@ -1,42 +0,0 @@
1
- import type { RunContext } from './run-context';
2
- import { isTerminal } from './run-state';
3
- import { nowISO } from '../utils';
4
-
5
- /**
6
- * Return waiting tasks whose dependency states are terminal and which are not
7
- * already in flight. The caller owns actually launching them.
8
- */
9
- export function findLaunchableTasks(
10
- ctx: RunContext,
11
- runningTaskIds: ReadonlySet<string>,
12
- ): string[] {
13
- const launchable: string[] = [];
14
- for (const [id, state] of ctx.states) {
15
- if (state.status !== 'waiting' || runningTaskIds.has(id)) continue;
16
- const node = ctx.dag.nodes.get(id)!;
17
- const allDepsTerminal =
18
- node.dependsOn.length === 0 ||
19
- node.dependsOn.every((depId) => isTerminal(ctx.states.get(depId)!.status));
20
- if (allDepsTerminal) launchable.push(id);
21
- }
22
- return launchable;
23
- }
24
-
25
- export function allTasksTerminal(ctx: RunContext): boolean {
26
- return [...ctx.states.values()].every((state) => isTerminal(state.status));
27
- }
28
-
29
- /**
30
- * Abort cleanup helper: after in-flight tasks settle, any remaining
31
- * non-terminal tasks are waiting/idle tasks that were never started.
32
- */
33
- export function skipNonTerminalTasks(
34
- ctx: RunContext,
35
- finishedAt = nowISO(),
36
- ): void {
37
- for (const [id, state] of ctx.states) {
38
- if (isTerminal(state.status)) continue;
39
- state.finishedAt = finishedAt;
40
- ctx.setTaskStatus(id, 'skipped');
41
- }
42
- }