@tagma/sdk 0.1.8 → 0.1.9
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.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/adapters/stdin-approval.ts +117 -117
- package/src/adapters/websocket-approval.ts +175 -144
- package/src/approval.ts +4 -1
- package/src/completions/exit-code.ts +19 -19
- package/src/completions/file-exists.ts +39 -39
- package/src/completions/output-check.ts +57 -57
- package/src/config-ops.ts +239 -220
- package/src/dag.ts +222 -222
- package/src/drivers/claude-code.ts +207 -207
- package/src/engine.ts +743 -714
- package/src/hooks.ts +147 -138
- package/src/logger.ts +112 -107
- package/src/middlewares/static-context.ts +29 -29
- package/src/pipeline-runner.ts +126 -125
- package/src/runner.ts +213 -195
- package/src/schema.ts +386 -358
- package/src/triggers/file.ts +105 -94
- package/src/triggers/manual.ts +61 -61
- package/src/utils.ts +154 -147
- package/src/validate-raw.ts +223 -203
package/src/validate-raw.ts
CHANGED
|
@@ -1,203 +1,223 @@
|
|
|
1
|
-
// ═══ Raw Pipeline Config Validation ═══
|
|
2
|
-
//
|
|
3
|
-
// Validates a RawPipelineConfig without resolving inheritance or executing
|
|
4
|
-
// anything — intended for real-time feedback in a visual editor (e.g. drag
|
|
5
|
-
// to add a task, live error highlighting).
|
|
6
|
-
//
|
|
7
|
-
// Returns a flat list of ValidationError objects. An empty array means valid.
|
|
8
|
-
|
|
9
|
-
import type { RawPipelineConfig } from './types';
|
|
10
|
-
|
|
11
|
-
export interface ValidationError {
|
|
12
|
-
/** JSONPath-style location, e.g. "tracks[0].tasks[1].prompt" */
|
|
13
|
-
path: string;
|
|
14
|
-
message: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validate a raw pipeline config.
|
|
19
|
-
* Checks structure, required fields, prompt/command exclusivity,
|
|
20
|
-
* depends_on reference integrity, and circular dependencies.
|
|
21
|
-
*
|
|
22
|
-
* Does NOT check plugin registration — plugins may not be loaded yet
|
|
23
|
-
* when the frontend is editing a config offline.
|
|
24
|
-
*/
|
|
25
|
-
export function validateRaw(config: RawPipelineConfig): ValidationError[] {
|
|
26
|
-
const errors: ValidationError[] = [];
|
|
27
|
-
|
|
28
|
-
// ── Top level ──
|
|
29
|
-
if (!config.name?.trim()) {
|
|
30
|
-
errors.push({ path: 'name', message: 'Pipeline name is required' });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!config.tracks || config.tracks.length === 0) {
|
|
34
|
-
errors.push({ path: 'tracks', message: 'At least one track is required' });
|
|
35
|
-
return errors; // No point going further without tracks
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ── Build qualified ID sets for cross-reference checks ──
|
|
39
|
-
// Qualified ID format: "trackId.taskId" (mirrors the engine's convention)
|
|
40
|
-
const allQualified = new Set<string>();
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!track.
|
|
65
|
-
errors.push({ path: `${trackPath}.
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
allQualified: Set<string>,
|
|
154
|
-
bareToQualified: Map<string, string>,
|
|
155
|
-
):
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
1
|
+
// ═══ Raw Pipeline Config Validation ═══
|
|
2
|
+
//
|
|
3
|
+
// Validates a RawPipelineConfig without resolving inheritance or executing
|
|
4
|
+
// anything — intended for real-time feedback in a visual editor (e.g. drag
|
|
5
|
+
// to add a task, live error highlighting).
|
|
6
|
+
//
|
|
7
|
+
// Returns a flat list of ValidationError objects. An empty array means valid.
|
|
8
|
+
|
|
9
|
+
import type { RawPipelineConfig } from './types';
|
|
10
|
+
|
|
11
|
+
export interface ValidationError {
|
|
12
|
+
/** JSONPath-style location, e.g. "tracks[0].tasks[1].prompt" */
|
|
13
|
+
path: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Validate a raw pipeline config.
|
|
19
|
+
* Checks structure, required fields, prompt/command exclusivity,
|
|
20
|
+
* depends_on reference integrity, and circular dependencies.
|
|
21
|
+
*
|
|
22
|
+
* Does NOT check plugin registration — plugins may not be loaded yet
|
|
23
|
+
* when the frontend is editing a config offline.
|
|
24
|
+
*/
|
|
25
|
+
export function validateRaw(config: RawPipelineConfig): ValidationError[] {
|
|
26
|
+
const errors: ValidationError[] = [];
|
|
27
|
+
|
|
28
|
+
// ── Top level ──
|
|
29
|
+
if (!config.name?.trim()) {
|
|
30
|
+
errors.push({ path: 'name', message: 'Pipeline name is required' });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!config.tracks || config.tracks.length === 0) {
|
|
34
|
+
errors.push({ path: 'tracks', message: 'At least one track is required' });
|
|
35
|
+
return errors; // No point going further without tracks
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ── Build qualified ID sets for cross-reference checks ──
|
|
39
|
+
// Qualified ID format: "trackId.taskId" (mirrors the engine's convention)
|
|
40
|
+
const allQualified = new Set<string>();
|
|
41
|
+
// bare taskId → qualified ID, or "__ambiguous__" when multiple tracks share that bare name.
|
|
42
|
+
// "__ambiguous__" signals that a bare ref is unresolvable without a track prefix.
|
|
43
|
+
const bareToQualified = new Map<string, string>();
|
|
44
|
+
const bareIdCount = new Map<string, number>();
|
|
45
|
+
|
|
46
|
+
for (const track of config.tracks) {
|
|
47
|
+
if (!track.id) continue;
|
|
48
|
+
for (const task of track.tasks ?? []) {
|
|
49
|
+
if (!task.id) continue;
|
|
50
|
+
const qid = `${track.id}.${task.id}`;
|
|
51
|
+
allQualified.add(qid);
|
|
52
|
+
const count = (bareIdCount.get(task.id) ?? 0) + 1;
|
|
53
|
+
bareIdCount.set(task.id, count);
|
|
54
|
+
// Mark as ambiguous when a second track introduces the same bare name.
|
|
55
|
+
bareToQualified.set(task.id, count === 1 ? qid : '__ambiguous__');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── Per-track validation ──
|
|
60
|
+
for (let ti = 0; ti < config.tracks.length; ti++) {
|
|
61
|
+
const track = config.tracks[ti];
|
|
62
|
+
const trackPath = `tracks[${ti}]`;
|
|
63
|
+
|
|
64
|
+
if (!track.id?.trim()) {
|
|
65
|
+
errors.push({ path: `${trackPath}.id`, message: 'Track id is required' });
|
|
66
|
+
}
|
|
67
|
+
if (!track.name?.trim()) {
|
|
68
|
+
errors.push({ path: `${trackPath}.name`, message: 'Track name is required' });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!track.tasks || track.tasks.length === 0) {
|
|
72
|
+
errors.push({ path: `${trackPath}.tasks`, message: `Track "${track.id || ti}": must have at least one task` });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ── Per-task validation ──
|
|
77
|
+
for (let ki = 0; ki < track.tasks.length; ki++) {
|
|
78
|
+
const task = track.tasks[ki];
|
|
79
|
+
const taskPath = `${trackPath}.tasks[${ki}]`;
|
|
80
|
+
|
|
81
|
+
if (!task.id?.trim()) {
|
|
82
|
+
errors.push({ path: `${taskPath}.id`, message: 'Task id is required' });
|
|
83
|
+
continue; // Can't check further without an id
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Template-based tasks: skip prompt/command checks (params validated at runtime)
|
|
87
|
+
if (task.use) continue;
|
|
88
|
+
|
|
89
|
+
const hasPrompt = typeof task.prompt === 'string' && task.prompt.trim().length > 0;
|
|
90
|
+
const hasCommand = typeof task.command === 'string' && task.command.trim().length > 0;
|
|
91
|
+
|
|
92
|
+
if (!hasPrompt && !hasCommand) {
|
|
93
|
+
errors.push({
|
|
94
|
+
path: taskPath,
|
|
95
|
+
message: `Task "${task.id}": must have "prompt" or "command"`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (hasPrompt && hasCommand) {
|
|
99
|
+
errors.push({
|
|
100
|
+
path: taskPath,
|
|
101
|
+
message: `Task "${task.id}": cannot have both "prompt" and "command"`,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ── depends_on reference checks ──
|
|
106
|
+
if (task.depends_on && task.depends_on.length > 0) {
|
|
107
|
+
for (const dep of task.depends_on) {
|
|
108
|
+
const resolved = resolveDepRef(dep, track.id, allQualified, bareToQualified);
|
|
109
|
+
if (!resolved) {
|
|
110
|
+
errors.push({
|
|
111
|
+
path: `${taskPath}.depends_on`,
|
|
112
|
+
message: `Task "${task.id}": depends_on "${dep}" — no such task found`,
|
|
113
|
+
});
|
|
114
|
+
} else if (resolved === '__ambiguous__') {
|
|
115
|
+
errors.push({
|
|
116
|
+
path: `${taskPath}.depends_on`,
|
|
117
|
+
message: `Task "${task.id}": depends_on "${dep}" is ambiguous — multiple tracks have a task with this id. Use the fully-qualified form "trackId.${dep}".`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ── continue_from reference check ──
|
|
124
|
+
if (task.continue_from) {
|
|
125
|
+
const resolved = resolveDepRef(task.continue_from, track.id, allQualified, bareToQualified);
|
|
126
|
+
if (!resolved) {
|
|
127
|
+
errors.push({
|
|
128
|
+
path: `${taskPath}.continue_from`,
|
|
129
|
+
message: `Task "${task.id}": continue_from "${task.continue_from}" — no such task found`,
|
|
130
|
+
});
|
|
131
|
+
} else if (resolved === '__ambiguous__') {
|
|
132
|
+
errors.push({
|
|
133
|
+
path: `${taskPath}.continue_from`,
|
|
134
|
+
message: `Task "${task.id}": continue_from "${task.continue_from}" is ambiguous — multiple tracks have a task with this id. Use the fully-qualified form "trackId.${task.continue_from}".`,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ── Cycle detection ──
|
|
142
|
+
errors.push(...detectCycles(config, allQualified, bareToQualified));
|
|
143
|
+
|
|
144
|
+
return errors;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── Helpers ──
|
|
148
|
+
|
|
149
|
+
// Returns the resolved qualified ID, null (not found), or '__ambiguous__' (multiple tracks match).
|
|
150
|
+
function resolveDepRef(
|
|
151
|
+
ref: string,
|
|
152
|
+
fromTrackId: string,
|
|
153
|
+
allQualified: Set<string>,
|
|
154
|
+
bareToQualified: Map<string, string>,
|
|
155
|
+
): string | null {
|
|
156
|
+
// Fully qualified reference (trackId.taskId) — always unambiguous
|
|
157
|
+
if (allQualified.has(ref)) return ref;
|
|
158
|
+
// Same-track shorthand — always unambiguous (shadows any global bare match)
|
|
159
|
+
const sameTrack = `${fromTrackId}.${ref}`;
|
|
160
|
+
if (allQualified.has(sameTrack)) return sameTrack;
|
|
161
|
+
// Global bare lookup — may be '__ambiguous__' when multiple tracks share the name
|
|
162
|
+
return bareToQualified.get(ref) ?? null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function detectCycles(
|
|
166
|
+
config: RawPipelineConfig,
|
|
167
|
+
allQualified: Set<string>,
|
|
168
|
+
bareToQualified: Map<string, string>,
|
|
169
|
+
): ValidationError[] {
|
|
170
|
+
// Build adjacency: qualifiedId → [resolved dep qualifiedIds]
|
|
171
|
+
const adj = new Map<string, string[]>();
|
|
172
|
+
|
|
173
|
+
for (const track of config.tracks) {
|
|
174
|
+
if (!track.id) continue;
|
|
175
|
+
for (const task of track.tasks ?? []) {
|
|
176
|
+
if (!task.id || task.use) continue;
|
|
177
|
+
const qid = `${track.id}.${task.id}`;
|
|
178
|
+
const deps: string[] = [];
|
|
179
|
+
for (const dep of task.depends_on ?? []) {
|
|
180
|
+
const resolved = resolveDepRef(dep, track.id, allQualified, bareToQualified);
|
|
181
|
+
if (resolved) deps.push(resolved);
|
|
182
|
+
}
|
|
183
|
+
if (task.continue_from) {
|
|
184
|
+
const resolved = resolveDepRef(task.continue_from, track.id, allQualified, bareToQualified);
|
|
185
|
+
if (resolved && !deps.includes(resolved)) deps.push(resolved);
|
|
186
|
+
}
|
|
187
|
+
adj.set(qid, deps);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const errors: ValidationError[] = [];
|
|
192
|
+
const visited = new Set<string>();
|
|
193
|
+
const inStack = new Set<string>();
|
|
194
|
+
// Deduplicate cycles: the same cycle can be discovered from multiple entry points.
|
|
195
|
+
// Canonical key = sorted node list joined — order-independent fingerprint.
|
|
196
|
+
const seenCycles = new Set<string>();
|
|
197
|
+
|
|
198
|
+
function dfs(id: string, path: string[]): void {
|
|
199
|
+
if (inStack.has(id)) {
|
|
200
|
+
const cycleStart = path.indexOf(id);
|
|
201
|
+
const cycleNodes = [...path.slice(cycleStart), id];
|
|
202
|
+
const key = [...cycleNodes].sort().join(',');
|
|
203
|
+
if (!seenCycles.has(key)) {
|
|
204
|
+
seenCycles.add(key);
|
|
205
|
+
errors.push({ path: 'tracks', message: `Circular dependency detected: ${cycleNodes.join(' → ')}` });
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (visited.has(id)) return;
|
|
210
|
+
visited.add(id);
|
|
211
|
+
inStack.add(id);
|
|
212
|
+
for (const dep of adj.get(id) ?? []) {
|
|
213
|
+
dfs(dep, [...path, id]);
|
|
214
|
+
}
|
|
215
|
+
inStack.delete(id);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const id of adj.keys()) {
|
|
219
|
+
if (!visited.has(id)) dfs(id, []);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return errors;
|
|
223
|
+
}
|