@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,401 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import type { PipelineConfig, RawPipelineConfig } from './types';
3
- import {
4
- TASK_ID_RE,
5
- isValidTaskId,
6
- qualifyTaskId,
7
- isQualifiedRef,
8
- buildTaskIndex,
9
- resolveTaskRef,
10
- AMBIGUOUS,
11
- } from './task-ref';
12
- import { buildDag, buildRawDag } from './dag';
13
- import { validateRaw } from './validate-raw';
14
-
15
- // ═══ Low-level helpers ═══
16
-
17
- describe('isValidTaskId', () => {
18
- test('accepts letter-led ids with letters, digits, underscores, hyphens', () => {
19
- for (const id of ['a', 'A', '_', 'task_1', 'Task-2', '_private', 'a_b-c_1']) {
20
- expect(isValidTaskId(id)).toBe(true);
21
- expect(TASK_ID_RE.test(id)).toBe(true);
22
- }
23
- });
24
-
25
- test('rejects empty, digit-led, dot-bearing, and whitespace forms', () => {
26
- for (const id of ['', '1task', 'a.b', 'foo bar', '-leading', 'has/slash', 'dot.']) {
27
- expect(isValidTaskId(id)).toBe(false);
28
- }
29
- });
30
-
31
- test('rejects non-string values', () => {
32
- expect(isValidTaskId(null as unknown as string)).toBe(false);
33
- expect(isValidTaskId(undefined as unknown as string)).toBe(false);
34
- expect(isValidTaskId(42 as unknown as string)).toBe(false);
35
- });
36
- });
37
-
38
- describe('qualifyTaskId + isQualifiedRef', () => {
39
- test('qualifyTaskId joins with dot; isQualifiedRef detects dotted form', () => {
40
- expect(qualifyTaskId('alpha', 'review')).toBe('alpha.review');
41
- expect(isQualifiedRef('alpha.review')).toBe(true);
42
- expect(isQualifiedRef('review')).toBe(false);
43
- });
44
- });
45
-
46
- // ═══ Index build ═══
47
-
48
- describe('buildTaskIndex', () => {
49
- test('collects all qualified ids and unique bare ids', () => {
50
- const cfg: RawPipelineConfig = {
51
- name: 'T',
52
- tracks: [
53
- { id: 'alpha', name: 'A', tasks: [{ id: 'plan', prompt: 'p' }] },
54
- { id: 'beta', name: 'B', tasks: [{ id: 'ship', prompt: 'p' }] },
55
- ],
56
- };
57
- const idx = buildTaskIndex(cfg);
58
- expect(idx.allQualified.has('alpha.plan')).toBe(true);
59
- expect(idx.allQualified.has('beta.ship')).toBe(true);
60
- expect(idx.bareToQualified.get('plan')).toBe('alpha.plan');
61
- expect(idx.bareToQualified.get('ship')).toBe('beta.ship');
62
- });
63
-
64
- test('marks bare ids shared across tracks as ambiguous', () => {
65
- const cfg: RawPipelineConfig = {
66
- name: 'T',
67
- tracks: [
68
- { id: 'alpha', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
69
- { id: 'beta', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
70
- ],
71
- };
72
- const idx = buildTaskIndex(cfg);
73
- expect(idx.bareToQualified.get('review')).toBe(AMBIGUOUS);
74
- expect(idx.allQualified.has('alpha.review')).toBe(true);
75
- expect(idx.allQualified.has('beta.review')).toBe(true);
76
- });
77
-
78
- test('tolerates tracks/tasks missing ids (editor in-progress state)', () => {
79
- const cfg = {
80
- name: 'T',
81
- tracks: [
82
- { id: '', name: 'half-typed', tasks: [{ id: 'x', prompt: 'p' }] },
83
- { id: 'ok', name: 'OK', tasks: [{ id: '', prompt: 'p' }, { id: 'y', prompt: 'p' }] },
84
- ],
85
- } as unknown as RawPipelineConfig;
86
- const idx = buildTaskIndex(cfg);
87
- expect(idx.allQualified.size).toBe(1);
88
- expect(idx.allQualified.has('ok.y')).toBe(true);
89
- });
90
- });
91
-
92
- // ═══ Ref resolution ═══
93
-
94
- describe('resolveTaskRef', () => {
95
- const cfg: RawPipelineConfig = {
96
- name: 'T',
97
- tracks: [
98
- {
99
- id: 'alpha',
100
- name: 'A',
101
- tasks: [
102
- { id: 'plan', prompt: 'p' },
103
- { id: 'review', prompt: 'p' },
104
- ],
105
- },
106
- {
107
- id: 'beta',
108
- name: 'B',
109
- tasks: [
110
- { id: 'review', prompt: 'p' },
111
- { id: 'ship', prompt: 'p' },
112
- ],
113
- },
114
- ],
115
- };
116
- const idx = buildTaskIndex(cfg);
117
-
118
- test('fully qualified ref resolves when it exists', () => {
119
- expect(resolveTaskRef('alpha.plan', 'beta', idx)).toEqual({
120
- kind: 'resolved',
121
- qid: 'alpha.plan',
122
- });
123
- });
124
-
125
- test('fully qualified ref that does not exist is not_found', () => {
126
- expect(resolveTaskRef('alpha.ghost', 'beta', idx)).toEqual({
127
- kind: 'not_found',
128
- ref: 'alpha.ghost',
129
- });
130
- });
131
-
132
- test('bare ref prefers same-track shorthand', () => {
133
- // "review" exists in both tracks — from beta's perspective, the same-
134
- // track shadow must win over the cross-track ambiguous pool.
135
- expect(resolveTaskRef('review', 'beta', idx)).toEqual({
136
- kind: 'resolved',
137
- qid: 'beta.review',
138
- });
139
- expect(resolveTaskRef('review', 'alpha', idx)).toEqual({
140
- kind: 'resolved',
141
- qid: 'alpha.review',
142
- });
143
- });
144
-
145
- test('bare ref not in current track is ambiguous when multiple tracks have it', () => {
146
- const twoForeign: RawPipelineConfig = {
147
- name: 'T',
148
- tracks: [
149
- { id: 'a', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
150
- { id: 'b', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
151
- { id: 'c', name: 'C', tasks: [{ id: 'other', prompt: 'p' }] },
152
- ],
153
- };
154
- const idx2 = buildTaskIndex(twoForeign);
155
- expect(resolveTaskRef('review', 'c', idx2)).toEqual({ kind: 'ambiguous', ref: 'review' });
156
- });
157
-
158
- test('bare ref unique in the pool resolves cross-track', () => {
159
- expect(resolveTaskRef('ship', 'alpha', idx)).toEqual({
160
- kind: 'resolved',
161
- qid: 'beta.ship',
162
- });
163
- });
164
-
165
- test('bare ref nobody has is not_found', () => {
166
- expect(resolveTaskRef('nowhere', 'alpha', idx)).toEqual({
167
- kind: 'not_found',
168
- ref: 'nowhere',
169
- });
170
- });
171
- });
172
-
173
- // ═══ Regression: bug #2 — same bare task id in multiple tracks ═══
174
-
175
- describe('regression: continue_from across same-named tasks (bug #2)', () => {
176
- test('bare continue_from resolves via same-track shadow — qualified id handed downstream', () => {
177
- // Two tracks, each with a "review" task and a follower that continues
178
- // from it. The follower MUST bind to its own track's review via the
179
- // same-track shorthand, not to the other track's review.
180
- const resolved: PipelineConfig = {
181
- name: 'Same-Bare',
182
- tracks: [
183
- {
184
- id: 'alpha',
185
- name: 'Alpha',
186
- tasks: [
187
- { id: 'review', name: 'Review', prompt: 'do A' },
188
- {
189
- id: 'ship',
190
- name: 'Ship',
191
- prompt: 'ship A',
192
- depends_on: ['review'],
193
- continue_from: 'review',
194
- },
195
- ],
196
- },
197
- {
198
- id: 'beta',
199
- name: 'Beta',
200
- tasks: [
201
- { id: 'review', name: 'Review', prompt: 'do B' },
202
- {
203
- id: 'ship',
204
- name: 'Ship',
205
- prompt: 'ship B',
206
- depends_on: ['review'],
207
- continue_from: 'review',
208
- },
209
- ],
210
- },
211
- ],
212
- };
213
- const dag = buildDag(resolved);
214
- const alphaShip = dag.nodes.get('alpha.ship')!;
215
- const betaShip = dag.nodes.get('beta.ship')!;
216
- expect(alphaShip.resolvedContinueFrom).toBe('alpha.review');
217
- expect(betaShip.resolvedContinueFrom).toBe('beta.review');
218
- // And the dep edges get qualified too, preventing engine map-key misses.
219
- expect(alphaShip.dependsOn).toContain('alpha.review');
220
- expect(betaShip.dependsOn).toContain('beta.review');
221
- });
222
-
223
- test('bare continue_from pointing at a foreign ambiguous task throws', () => {
224
- const resolved: PipelineConfig = {
225
- name: 'Ambiguous',
226
- tracks: [
227
- {
228
- id: 'alpha',
229
- name: 'Alpha',
230
- tasks: [
231
- { id: 'review', name: 'Review', prompt: 'p' },
232
- // ship has no local "review" so bare "review" is ambiguous.
233
- { id: 'filler', name: 'Filler', prompt: 'p' },
234
- ],
235
- },
236
- {
237
- id: 'beta',
238
- name: 'Beta',
239
- tasks: [{ id: 'review', name: 'Review', prompt: 'p' }],
240
- },
241
- {
242
- id: 'gamma',
243
- name: 'Gamma',
244
- tasks: [
245
- {
246
- id: 'ship',
247
- name: 'Ship',
248
- prompt: 'ship',
249
- continue_from: 'review',
250
- },
251
- ],
252
- },
253
- ],
254
- };
255
- expect(() => buildDag(resolved)).toThrow(/ambiguous/i);
256
- });
257
-
258
- test('qualified continue_from always wins — no same-track-shadow risk', () => {
259
- const resolved: PipelineConfig = {
260
- name: 'Qualified',
261
- tracks: [
262
- {
263
- id: 'alpha',
264
- name: 'Alpha',
265
- tasks: [
266
- { id: 'plan', name: 'Plan', prompt: 'p' },
267
- {
268
- id: 'plan_v2',
269
- name: 'Plan v2',
270
- prompt: 'p2',
271
- continue_from: 'plan',
272
- },
273
- ],
274
- },
275
- {
276
- id: 'beta',
277
- name: 'Beta',
278
- tasks: [
279
- { id: 'plan', name: 'Plan B', prompt: 'p' },
280
- {
281
- id: 'cross',
282
- name: 'Cross',
283
- prompt: 'x',
284
- continue_from: 'alpha.plan',
285
- },
286
- ],
287
- },
288
- ],
289
- };
290
- const dag = buildDag(resolved);
291
- expect(dag.nodes.get('alpha.plan_v2')!.resolvedContinueFrom).toBe('alpha.plan');
292
- expect(dag.nodes.get('beta.cross')!.resolvedContinueFrom).toBe('alpha.plan');
293
- });
294
- });
295
-
296
- // ═══ Regression: bug #10 — editor-generated ids always pass validate-raw ═══
297
-
298
- describe('regression: TASK_ID_RE is the single source of truth (bug #10)', () => {
299
- test('validateRaw rejects exactly what isValidTaskId rejects', () => {
300
- // Any string the helper says is invalid must be flagged by validateRaw
301
- // as an "invalid characters" error — proving they read from the same
302
- // regex rather than two drifted copies.
303
- const invalids = ['1bad', 'has.dot', 'with space', '-leading', 'q?mark', ''];
304
- for (const badId of invalids) {
305
- const cfg: RawPipelineConfig = {
306
- name: 'T',
307
- tracks: [
308
- {
309
- id: 'ok',
310
- name: 'OK',
311
- tasks: [{ id: badId, prompt: 'p' }],
312
- },
313
- ],
314
- };
315
- const errs = validateRaw(cfg);
316
- expect(errs.length).toBeGreaterThan(0);
317
- expect(isValidTaskId(badId)).toBe(false);
318
- }
319
- });
320
- });
321
-
322
- // ═══ Regression: buildDag topo sort is deterministic (bug #13) ═══
323
-
324
- describe('regression: buildDag topo sort is deterministic', () => {
325
- const base = (trackOrder: readonly string[]): PipelineConfig => ({
326
- name: 'Determinism',
327
- tracks: trackOrder.map((id) => ({
328
- id,
329
- name: id,
330
- tasks: [
331
- { id: 'a', name: 'A', prompt: 'p' },
332
- { id: 'b', name: 'B', prompt: 'p', depends_on: ['a'] },
333
- ],
334
- })),
335
- });
336
-
337
- test('parallel tasks with equal depth sort by qid, independent of YAML order', () => {
338
- const forward = buildDag(base(['alpha', 'beta', 'gamma']));
339
- const reversed = buildDag(base(['gamma', 'beta', 'alpha']));
340
- expect(forward.sorted).toEqual(reversed.sorted);
341
- // And the actual order is alphabetical by qid — every "a" before every "b".
342
- expect(forward.sorted).toEqual([
343
- 'alpha.a',
344
- 'beta.a',
345
- 'gamma.a',
346
- 'alpha.b',
347
- 'beta.b',
348
- 'gamma.b',
349
- ]);
350
- });
351
-
352
- test('diamond dependency still produces a unique sorted order', () => {
353
- // root -> left, right -> join
354
- const cfg: PipelineConfig = {
355
- name: 'Diamond',
356
- tracks: [
357
- {
358
- id: 't',
359
- name: 't',
360
- tasks: [
361
- { id: 'root', name: 'r', prompt: 'p' },
362
- { id: 'left', name: 'l', prompt: 'p', depends_on: ['root'] },
363
- { id: 'right', name: 'r', prompt: 'p', depends_on: ['root'] },
364
- { id: 'join', name: 'j', prompt: 'p', depends_on: ['left', 'right'] },
365
- ],
366
- },
367
- ],
368
- };
369
- const first = buildDag(cfg).sorted;
370
- const second = buildDag(cfg).sorted;
371
- expect(first).toEqual(second);
372
- // root first, join last; left/right in alphabetical order between.
373
- expect(first[0]).toBe('t.root');
374
- expect(first[first.length - 1]).toBe('t.join');
375
- expect(first.indexOf('t.left')).toBeLessThan(first.indexOf('t.right'));
376
- });
377
- });
378
-
379
- // ═══ Regression: buildRawDag stays lenient (editor real-time view) ═══
380
-
381
- describe('buildRawDag tolerates unresolved refs', () => {
382
- test('ambiguous bare continue_from is silently skipped (no edge, no throw)', () => {
383
- const cfg: RawPipelineConfig = {
384
- name: 'T',
385
- tracks: [
386
- { id: 'a', name: 'A', tasks: [{ id: 'review', prompt: 'p' }] },
387
- { id: 'b', name: 'B', tasks: [{ id: 'review', prompt: 'p' }] },
388
- {
389
- id: 'c',
390
- name: 'C',
391
- tasks: [{ id: 'use', prompt: 'p', continue_from: 'review' }],
392
- },
393
- ],
394
- };
395
- const raw = buildRawDag(cfg);
396
- expect(raw.nodes.size).toBe(3);
397
- // No edge for the ambiguous ref — the editor panel should prompt the
398
- // user to qualify it instead of silently linking to the wrong track.
399
- expect(raw.edges.find((e) => e.to === 'c.use')).toBeUndefined();
400
- });
401
- });
package/src/task-ref.ts DELETED
@@ -1,121 +0,0 @@
1
- // ═══ Task reference resolution — single source of truth ═══
2
- //
3
- // Before this module existed, four sites each carried their own copy of the
4
- // "what is a valid id" + "how do I resolve a bare / same-track-shorthand /
5
- // fully qualified ref" logic:
6
- //
7
- // - dag.ts/buildDag (threw on unresolved, threw on ambiguous)
8
- // - dag.ts/buildRawDag (silently skipped unresolved and ambiguous)
9
- // - validate-raw.ts (reported both as errors, with different wording)
10
- // - engine.ts/resolveRefInDag (returned null on ambiguous)
11
- //
12
- // In addition, the editor shipped its own regex for id validation in
13
- // `shared/config-id.ts` and a test-local copy in `config-id-generation.test.ts`,
14
- // creating multiple places where the character set could drift from the
15
- // validator. Bugs observed downstream (silent context loss when two tracks
16
- // happened to share a bare task name; editor-generated ids occasionally
17
- // failing SDK validate-raw) all traced back to this duplication.
18
- //
19
- // Callers now build a TaskIndex once and use `resolveTaskRef` to classify
20
- // each reference, then decide themselves whether to throw / warn / skip —
21
- // instead of re-implementing the index build and the lookup logic.
22
-
23
- import type { PipelineConfig, RawPipelineConfig } from './types';
24
-
25
- /**
26
- * D8: task and track ids must match this pattern. No dots: the `.` is the
27
- * qualified-id separator ("trackId.taskId"), so allowing it inside either
28
- * part would make qid parsing ambiguous and break every resolver below.
29
- */
30
- export const TASK_ID_RE = /^[A-Za-z_][A-Za-z0-9_-]*$/;
31
-
32
- export function isValidTaskId(id: unknown): id is string {
33
- return typeof id === 'string' && TASK_ID_RE.test(id);
34
- }
35
-
36
- /** Canonical qualified form used throughout the engine. */
37
- export function qualifyTaskId(trackId: string, taskId: string): string {
38
- return `${trackId}.${taskId}`;
39
- }
40
-
41
- /** Does the reference already include a track prefix? */
42
- export function isQualifiedRef(ref: string): boolean {
43
- return ref.includes('.');
44
- }
45
-
46
- /**
47
- * Sentinel stored in `TaskIndex.bareToQualified` when a bare task id is
48
- * shared by more than one track, making it unresolvable without a prefix.
49
- * Exposed so callers that want to inspect the index directly know what to
50
- * look for — but prefer `resolveTaskRef` which returns a typed `kind`.
51
- */
52
- export const AMBIGUOUS = '__ambiguous__';
53
-
54
- export interface TaskIndex {
55
- /** All fully-qualified ids ("trackId.taskId") present in the config. */
56
- readonly allQualified: ReadonlySet<string>;
57
- /** bare taskId → qid, or the {@link AMBIGUOUS} sentinel. */
58
- readonly bareToQualified: ReadonlyMap<string, string>;
59
- }
60
-
61
- /**
62
- * Build the index used by {@link resolveTaskRef}. Tolerant of partially
63
- * malformed configs: tracks or tasks missing an `id` are skipped so the
64
- * editor can call this during real-time validation on in-progress edits.
65
- */
66
- export function buildTaskIndex(config: RawPipelineConfig | PipelineConfig): TaskIndex {
67
- const allQualified = new Set<string>();
68
- const bareToQualified = new Map<string, string>();
69
- for (const track of config.tracks ?? []) {
70
- if (!track?.id) continue;
71
- if (!Array.isArray(track.tasks)) continue;
72
- for (const task of track.tasks ?? []) {
73
- if (!task?.id) continue;
74
- const qid = qualifyTaskId(track.id, task.id);
75
- allQualified.add(qid);
76
- if (bareToQualified.has(task.id)) {
77
- bareToQualified.set(task.id, AMBIGUOUS);
78
- } else {
79
- bareToQualified.set(task.id, qid);
80
- }
81
- }
82
- }
83
- return { allQualified, bareToQualified };
84
- }
85
-
86
- export type RefResolution =
87
- | { readonly kind: 'resolved'; readonly qid: string }
88
- | { readonly kind: 'ambiguous'; readonly ref: string }
89
- | { readonly kind: 'not_found'; readonly ref: string };
90
-
91
- /**
92
- * Resolve a dependency / continue_from reference to a canonical qid.
93
- *
94
- * 1. If the ref already contains a `.`, treat it as fully qualified —
95
- * return `resolved` when the qid exists, `not_found` otherwise.
96
- * 2. Otherwise, prefer the same-track shorthand (`fromTrackId.ref`).
97
- * 3. Fall back to a global bare lookup. Returns `ambiguous` when more
98
- * than one track has a task with that bare name.
99
- *
100
- * Callers decide the policy: `buildDag` throws on non-resolved, `buildRawDag`
101
- * skips silently, `validateRaw` emits a structured ValidationError.
102
- */
103
- export function resolveTaskRef(
104
- ref: string,
105
- fromTrackId: string,
106
- index: TaskIndex,
107
- ): RefResolution {
108
- if (isQualifiedRef(ref)) {
109
- return index.allQualified.has(ref)
110
- ? { kind: 'resolved', qid: ref }
111
- : { kind: 'not_found', ref };
112
- }
113
- const sameTrack = qualifyTaskId(fromTrackId, ref);
114
- if (index.allQualified.has(sameTrack)) {
115
- return { kind: 'resolved', qid: sameTrack };
116
- }
117
- const global = index.bareToQualified.get(ref);
118
- if (global === AMBIGUOUS) return { kind: 'ambiguous', ref };
119
- if (global !== undefined) return { kind: 'resolved', qid: global };
120
- return { kind: 'not_found', ref };
121
- }
@@ -1,164 +0,0 @@
1
- import { watch } from 'chokidar';
2
- import { resolve, dirname } from 'path';
3
- import { mkdir } from 'fs/promises';
4
- import type { TriggerPlugin, TriggerContext } from '../types';
5
- import { parseDuration, validatePath } from '../utils';
6
- import { TriggerTimeoutError } from '../engine';
7
-
8
- const IS_WINDOWS = process.platform === 'win32';
9
-
10
- function pathsEqual(a: string, b: string): boolean {
11
- return IS_WINDOWS ? a.toLowerCase() === b.toLowerCase() : a === b;
12
- }
13
-
14
- export const FileTrigger: TriggerPlugin = {
15
- name: 'file',
16
- schema: {
17
- description: 'Wait for a file to appear or be modified before the task runs.',
18
- fields: {
19
- path: {
20
- type: 'path',
21
- required: true,
22
- description: 'Path to the file to watch (relative to workDir or absolute).',
23
- placeholder: 'e.g. build/output.json',
24
- },
25
- timeout: {
26
- type: 'duration',
27
- description: 'Maximum wait time (e.g. 30s, 5m). Omit or 0 to wait indefinitely.',
28
- placeholder: '30s',
29
- },
30
- },
31
- },
32
-
33
- watch(config: Record<string, unknown>, ctx: TriggerContext): Promise<unknown> {
34
- const filePath = config.path as string;
35
- if (!filePath) throw new Error(`file trigger: "path" is required`);
36
-
37
- const safePath = validatePath(filePath, ctx.workDir);
38
- const timeoutMs = config.timeout != null ? parseDuration(String(config.timeout)) : 0;
39
-
40
- // Hoist the async work into a named async function so the Promise
41
- // constructor itself is synchronous — avoids the no-async-promise-executor
42
- // lint error and ensures exceptions are always propagated via reject().
43
- async function start(
44
- resolve_p: (value: unknown) => void,
45
- reject: (reason?: unknown) => void,
46
- ): Promise<void> {
47
- if (ctx.signal.aborted) {
48
- reject(new Error('Pipeline aborted'));
49
- return;
50
- }
51
-
52
- let settled = false;
53
- let timer: ReturnType<typeof setTimeout> | null = null;
54
-
55
- // Ensure the parent directory exists so the watcher doesn't fail
56
- // with ENOENT for nested paths like `build/output/result.json`.
57
- const dir = dirname(safePath);
58
- try {
59
- await mkdir(dir, { recursive: true });
60
- } catch {
61
- /* best effort — dir may already exist */
62
- }
63
-
64
- // Pass `cwd: dir` so chokidar resolves paths relative to the watched
65
- // directory. The 'add'/'change' events will then carry paths relative
66
- // to `dir`, which we resolve with `resolve(dir, addedPath)` for an
67
- // accurate absolute comparison — fixing the ambiguous process.cwd()
68
- // resolution of the previous implementation.
69
- const watcher = watch(dir, {
70
- ignoreInitial: true,
71
- depth: 0,
72
- cwd: dir,
73
- awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },
74
- });
75
-
76
- const cleanup = () => {
77
- if (settled) return;
78
- settled = true;
79
- watcher.close().catch(() => {
80
- /* ignore */
81
- });
82
- if (timer) clearTimeout(timer);
83
- ctx.signal.removeEventListener('abort', onAbort);
84
- };
85
-
86
- const onAbort = () => {
87
- cleanup();
88
- reject(new Error('Pipeline aborted'));
89
- };
90
-
91
- watcher.on('add', (addedPath: string) => {
92
- if (settled) return;
93
- if (pathsEqual(resolve(dir, addedPath), safePath)) {
94
- cleanup();
95
- resolve_p({ path: safePath });
96
- }
97
- });
98
-
99
- // Also fire on 'change' so that overwriting an existing file is detected.
100
- // Without this, upstream tasks that truncate-and-rewrite a file emit only
101
- // a 'change' event and the downstream trigger would never resolve.
102
- watcher.on('change', (changedPath: string) => {
103
- if (settled) return;
104
- if (pathsEqual(resolve(dir, changedPath), safePath)) {
105
- cleanup();
106
- resolve_p({ path: safePath });
107
- }
108
- });
109
-
110
- watcher.on('error', (err: unknown) => {
111
- if (settled) return;
112
- cleanup();
113
- reject(
114
- new Error(
115
- `file trigger watch error: ${err instanceof Error ? err.message : String(err)}`,
116
- ),
117
- );
118
- });
119
-
120
- // After the watcher finishes its initial scan, check if the file already exists.
121
- // Doing this inside 'ready' eliminates the race window between existence check
122
- // and watcher startup, so we neither miss events nor double-resolve.
123
- watcher.on('ready', () => {
124
- if (settled) return;
125
- Bun.file(safePath)
126
- .exists()
127
- .then((exists) => {
128
- if (settled) return;
129
- if (exists) {
130
- cleanup();
131
- resolve_p({ path: safePath });
132
- }
133
- })
134
- .catch((err: unknown) => {
135
- if (settled) return;
136
- cleanup();
137
- reject(
138
- new Error(
139
- `file trigger existence check failed: ${err instanceof Error ? err.message : String(err)}`,
140
- ),
141
- );
142
- });
143
- });
144
-
145
- if (timeoutMs > 0) {
146
- timer = setTimeout(() => {
147
- if (settled) return;
148
- cleanup();
149
- reject(
150
- new TriggerTimeoutError(
151
- `file trigger timeout: ${filePath} did not appear within ${config.timeout}`,
152
- ),
153
- );
154
- }, timeoutMs);
155
- }
156
-
157
- ctx.signal.addEventListener('abort', onAbort);
158
- }
159
-
160
- return new Promise((resolve_p, reject) => {
161
- start(resolve_p, reject).catch(reject);
162
- });
163
- },
164
- };