@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,15 +0,0 @@
1
- export class TriggerBlockedError extends Error {
2
- readonly code = 'TRIGGER_BLOCKED' as const;
3
- constructor(message: string) {
4
- super(message);
5
- this.name = 'TriggerBlockedError';
6
- }
7
- }
8
-
9
- export class TriggerTimeoutError extends Error {
10
- readonly code = 'TRIGGER_TIMEOUT' as const;
11
- constructor(message: string) {
12
- super(message);
13
- this.name = 'TriggerTimeoutError';
14
- }
15
- }
package/src/dag.test.ts DELETED
@@ -1,56 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { buildDag } from './dag';
3
- import type { PipelineConfig, TaskConfig, TrackConfig, Permissions } from './types';
4
-
5
- const PERMS: Permissions = { read: true, write: false, execute: false };
6
-
7
- function task(id: string, depends_on?: string[]): TaskConfig {
8
- return { id, name: id, prompt: 'x', permissions: PERMS, depends_on };
9
- }
10
-
11
- function track(id: string, tasks: TaskConfig[]): TrackConfig {
12
- return { id, name: id, driver: 'opencode', permissions: PERMS, tasks };
13
- }
14
-
15
- function pipeline(tasks: TaskConfig[]): PipelineConfig {
16
- return { name: 'test', tracks: [track('t', tasks)] };
17
- }
18
-
19
- function qid(id: string): string {
20
- return `t.${id}`;
21
- }
22
-
23
- describe('buildDag', () => {
24
- test('empty pipeline yields empty sorted array', () => {
25
- const dag = buildDag({ name: 'empty', tracks: [track('t', [])] });
26
- expect(dag.sorted).toEqual([]);
27
- expect(dag.nodes.size).toBe(0);
28
- });
29
-
30
- test('single node returns that node', () => {
31
- const dag = buildDag(pipeline([task('only')]));
32
- expect(dag.sorted).toEqual([qid('only')]);
33
- expect(dag.nodes.size).toBe(1);
34
- });
35
-
36
- test('linear chain A -> B -> C produces correct order', () => {
37
- const dag = buildDag(pipeline([task('a'), task('b', ['a']), task('c', ['b'])]));
38
- expect(dag.sorted).toEqual([qid('a'), qid('b'), qid('c')]);
39
- });
40
-
41
- test('diamond A -> B,C; B,C -> D: A first, D last, B/C in between', () => {
42
- const dag = buildDag(
43
- pipeline([task('a'), task('b', ['a']), task('c', ['a']), task('d', ['b', 'c'])]),
44
- );
45
- expect(dag.sorted[0]).toBe(qid('a'));
46
- expect(dag.sorted[dag.sorted.length - 1]).toBe(qid('d'));
47
- const mid = dag.sorted.slice(1, -1).sort();
48
- expect(mid).toEqual([qid('b'), qid('c')]);
49
- });
50
-
51
- test('cycle detection throws', () => {
52
- expect(() => buildDag(pipeline([task('a', ['b']), task('b', ['a'])]))).toThrow(
53
- /[Cc]ircular|cycle/,
54
- );
55
- });
56
- });
package/src/dag.ts DELETED
@@ -1,245 +0,0 @@
1
- import type {
2
- PipelineConfig,
3
- RawPipelineConfig,
4
- RawTaskConfig,
5
- TaskConfig,
6
- TrackConfig,
7
- } from './types';
8
- import { buildTaskIndex, qualifyTaskId, resolveTaskRef } from './task-ref';
9
-
10
- export interface DagNode {
11
- readonly taskId: string; // fully qualified: track_id.task_id or just task_id
12
- readonly task: TaskConfig;
13
- readonly track: TrackConfig;
14
- readonly dependsOn: readonly string[];
15
- /**
16
- * H1: `task.continue_from` may be written by users as a bare task id
17
- * (e.g. `review`) or a same-track shorthand. The driver needs the
18
- * fully-qualified upstream id to look up output/session/normalized maps
19
- * deterministically — bare lookups race when two tracks happen to share
20
- * a task name. dag.ts performs the qualification once, here, so the
21
- * engine never has to.
22
- */
23
- readonly resolvedContinueFrom?: string;
24
- }
25
-
26
- export interface Dag {
27
- readonly nodes: ReadonlyMap<string, DagNode>;
28
- readonly sorted: readonly string[]; // topological order
29
- }
30
-
31
- export function buildDag(config: PipelineConfig): Dag {
32
- const nodes = new Map<string, DagNode>();
33
-
34
- // 1. Register all nodes. Duplicates throw — same-track task-id collisions
35
- // would otherwise silently overwrite one another in the DAG.
36
- for (const track of config.tracks) {
37
- for (const task of track.tasks) {
38
- const qid = qualifyTaskId(track.id, task.id);
39
- if (nodes.has(qid)) {
40
- throw new Error(`Duplicate task ID: "${qid}"`);
41
- }
42
- nodes.set(qid, {
43
- taskId: qid,
44
- task,
45
- track,
46
- dependsOn: [], // filled below
47
- });
48
- }
49
- }
50
-
51
- // Shared index for ref resolution — same code path validate-raw uses.
52
- const index = buildTaskIndex(config);
53
-
54
- function resolveRef(ref: string, fromTrackId: string): string {
55
- const result = resolveTaskRef(ref, fromTrackId, index);
56
- if (result.kind === 'ambiguous') {
57
- throw new Error(
58
- `Ambiguous task reference "${ref}" exists in multiple tracks. ` +
59
- `Use "track_id.task_id" format.`,
60
- );
61
- }
62
- if (result.kind === 'not_found') {
63
- throw new Error(`Task reference "${ref}" not found`);
64
- }
65
- return result.qid;
66
- }
67
-
68
- // 2. Resolve depends_on and continue_from to qualified IDs
69
- for (const track of config.tracks) {
70
- for (const task of track.tasks) {
71
- const qid = qualifyTaskId(track.id, task.id);
72
- const deps: string[] = [];
73
- let resolvedContinueFrom: string | undefined;
74
-
75
- if (task.depends_on) {
76
- for (const dep of task.depends_on) {
77
- deps.push(resolveRef(dep, track.id));
78
- }
79
- }
80
- if (task.continue_from) {
81
- // Preserve the ambiguous-vs-not-found distinction in the user-facing
82
- // error: rewording "ambiguous" as "no such task found" (the previous
83
- // behavior) hid the real problem and sent users searching for a
84
- // missing task that actually existed in two places.
85
- const result = resolveTaskRef(task.continue_from, track.id, index);
86
- if (result.kind === 'ambiguous') {
87
- throw new Error(
88
- `Task "${qid}": continue_from "${task.continue_from}" is ambiguous — ` +
89
- `multiple tracks have a task with this id. Use the fully-qualified ` +
90
- `form "trackId.${task.continue_from}".`,
91
- );
92
- }
93
- if (result.kind === 'not_found') {
94
- throw new Error(
95
- `Task "${qid}": continue_from "${task.continue_from}" — no such task found. ` +
96
- `Use a fully-qualified reference (trackId.taskId) or ensure the target task exists.`,
97
- );
98
- }
99
- resolvedContinueFrom = result.qid;
100
- if (!deps.includes(result.qid)) {
101
- deps.push(result.qid); // continue_from implies dependency
102
- }
103
- }
104
-
105
- // Replace node with resolved deps + qualified continue_from.
106
- const node = nodes.get(qid)!;
107
- nodes.set(qid, { ...node, dependsOn: deps, resolvedContinueFrom });
108
- }
109
- }
110
-
111
- // 3. Topological sort + cycle detection (Kahn's algorithm)
112
- const inDegree = new Map<string, number>();
113
- const adjacency = new Map<string, string[]>(); // parent → children
114
-
115
- for (const [id] of nodes) {
116
- inDegree.set(id, 0);
117
- adjacency.set(id, []);
118
- }
119
-
120
- for (const [id, node] of nodes) {
121
- for (const dep of node.dependsOn) {
122
- adjacency.get(dep)!.push(id);
123
- inDegree.set(id, (inDegree.get(id) ?? 0) + 1);
124
- }
125
- }
126
-
127
- // D20: deterministic topo order. Kahn's algorithm dequeues in insertion
128
- // order by default, which depends on map iteration order — itself a
129
- // function of the (track, task) order in the YAML. Two pipelines that
130
- // are DAG-equivalent but written in a different order produced different
131
- // `sorted` arrays, leading to subtle run-to-run non-determinism for
132
- // parallel tasks with side effects (writing the same file, touching the
133
- // same repo). Break the tie by qualified id so identical DAG shapes
134
- // always yield identical schedules across machines and across YAML
135
- // round-trips.
136
- const ready: string[] = [];
137
- for (const [id, degree] of inDegree) {
138
- if (degree === 0) ready.push(id);
139
- }
140
- ready.sort();
141
-
142
- const sorted: string[] = [];
143
- let qi = 0;
144
- while (qi < ready.length) {
145
- const current = ready[qi++]!;
146
- sorted.push(current);
147
- // Collect children whose in-degree hits zero in this step, then push
148
- // them into the ready bucket in sorted order — keeps each "wave" of
149
- // parallel-eligible tasks ordered by qid.
150
- const newlyReady: string[] = [];
151
- for (const child of adjacency.get(current)!) {
152
- const newDegree = inDegree.get(child)! - 1;
153
- inDegree.set(child, newDegree);
154
- if (newDegree === 0) newlyReady.push(child);
155
- }
156
- if (newlyReady.length > 1) newlyReady.sort();
157
- for (const child of newlyReady) ready.push(child);
158
- }
159
-
160
- if (sorted.length !== nodes.size) {
161
- // Only report nodes that are actually part of cycles (in-degree > 0
162
- // after Kahn's algorithm), not their downstream dependents.
163
- const sortedSet = new Set(sorted);
164
- const cycleMembers = [...nodes.keys()].filter(
165
- (id) => !sortedSet.has(id) && (inDegree.get(id) ?? 0) > 0,
166
- );
167
- throw new Error(`Circular dependency detected involving tasks: ${cycleMembers.join(', ')}`);
168
- }
169
-
170
- return { nodes, sorted };
171
- }
172
-
173
- // ═══ Raw DAG (for visual editor — no workDir required) ═══
174
-
175
- export interface RawDagNode {
176
- readonly taskId: string; // fully qualified: track_id.task_id
177
- readonly trackId: string;
178
- readonly rawTask: RawTaskConfig;
179
- readonly dependsOn: readonly string[]; // fully qualified IDs, best-effort resolved
180
- }
181
-
182
- export interface RawDag {
183
- readonly nodes: ReadonlyMap<string, RawDagNode>;
184
- /** Directed edges: from → to means "from must complete before to starts" */
185
- readonly edges: readonly { readonly from: string; readonly to: string }[];
186
- }
187
-
188
- /**
189
- * Build a lightweight DAG from a raw (unresolved) pipeline config.
190
- * Unlike buildDag, this function:
191
- * - Does not require a workDir or resolved PipelineConfig
192
- * - Is lenient: missing or ambiguous refs are silently skipped
193
- *
194
- * Intended for the visual editor to render the flow graph before a pipeline is run.
195
- */
196
- export function buildRawDag(config: RawPipelineConfig): RawDag {
197
- const nodes = new Map<string, RawDagNode>();
198
-
199
- // 1. Register all concrete tasks. Duplicates are skipped (not thrown) so
200
- // partially-typed editor state doesn't produce a hard error.
201
- for (const track of config.tracks) {
202
- for (const task of track.tasks) {
203
- const qid = qualifyTaskId(track.id, task.id);
204
- if (nodes.has(qid)) continue;
205
- nodes.set(qid, { taskId: qid, trackId: track.id, rawTask: task, dependsOn: [] });
206
- }
207
- }
208
-
209
- const index = buildTaskIndex(config);
210
-
211
- function tryResolve(ref: string, fromTrackId: string): string | null {
212
- const result = resolveTaskRef(ref, fromTrackId, index);
213
- return result.kind === 'resolved' ? result.qid : null;
214
- }
215
-
216
- // 2. Resolve dependency refs leniently (missing / ambiguous refs are skipped)
217
- const edges: { from: string; to: string }[] = [];
218
-
219
- for (const track of config.tracks) {
220
- for (const task of track.tasks) {
221
- const qid = qualifyTaskId(track.id, task.id);
222
- const deps: string[] = [];
223
-
224
- for (const ref of task.depends_on ?? []) {
225
- const resolved = tryResolve(ref, track.id);
226
- if (resolved && !deps.includes(resolved)) {
227
- deps.push(resolved);
228
- edges.push({ from: resolved, to: qid });
229
- }
230
- }
231
- if (task.continue_from) {
232
- const resolved = tryResolve(task.continue_from, track.id);
233
- if (resolved && !deps.includes(resolved)) {
234
- deps.push(resolved);
235
- edges.push({ from: resolved, to: qid });
236
- }
237
- }
238
-
239
- const node = nodes.get(qid)!;
240
- nodes.set(qid, { ...node, dependsOn: deps });
241
- }
242
- }
243
-
244
- return { nodes, edges };
245
- }