@tagma/sdk 0.4.7 → 0.4.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/LICENSE +21 -21
- package/README.md +3 -34
- package/dist/dag.d.ts +0 -1
- package/dist/dag.d.ts.map +1 -1
- package/dist/dag.js +0 -5
- package/dist/dag.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +12 -38
- package/dist/engine.js.map +1 -1
- package/dist/hooks.d.ts +0 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +0 -5
- package/dist/runner.js.map +1 -1
- package/dist/schema.d.ts +1 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -143
- package/dist/schema.js.map +1 -1
- package/dist/schema.test.js.map +1 -1
- package/dist/sdk.d.ts +1 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -3
- package/dist/sdk.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -12
- package/dist/utils.js.map +1 -1
- package/dist/validate-raw.d.ts.map +1 -1
- package/dist/validate-raw.js +1 -4
- package/dist/validate-raw.js.map +1 -1
- package/package.json +1 -1
- package/src/dag.ts +0 -3
- package/src/engine.ts +12 -39
- package/src/hooks.ts +0 -1
- package/src/registry.ts +214 -214
- package/src/runner.ts +0 -5
- package/src/schema.test.ts +97 -97
- package/src/schema.ts +53 -228
- package/src/sdk.ts +1 -5
- package/src/utils.ts +0 -14
- package/src/validate-raw.ts +1 -4
- package/src/templates.ts +0 -97
package/src/schema.test.ts
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import yaml from 'js-yaml';
|
|
3
|
-
import type { PipelineConfig, RawPipelineConfig } from './types';
|
|
4
|
-
import { deresolvePipeline, serializePipeline } from './schema';
|
|
5
|
-
|
|
6
|
-
function parsePipelineYaml(content: string): RawPipelineConfig {
|
|
7
|
-
const doc = yaml.load(content) as { pipeline: RawPipelineConfig };
|
|
8
|
-
return doc.pipeline;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe('completion default serialization', () => {
|
|
12
|
-
test('serializePipeline omits default exit_code completions from raw configs', () => {
|
|
13
|
-
const raw: RawPipelineConfig = {
|
|
14
|
-
name: 'Serialize Defaults',
|
|
15
|
-
tracks: [
|
|
16
|
-
{
|
|
17
|
-
id: 'track_a',
|
|
18
|
-
name: 'Track A',
|
|
19
|
-
tasks: [
|
|
20
|
-
{ id: 'task_1', prompt: 'hello', completion: { type: 'exit_code' } },
|
|
21
|
-
{ id: 'task_2', prompt: 'world', completion: { type: 'exit_code', expect: 0 } },
|
|
22
|
-
{ id: 'task_3', prompt: 'keep me', completion: { type: 'exit_code', expect: 2 } },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const parsed = parsePipelineYaml(serializePipeline(raw));
|
|
29
|
-
expect(parsed.tracks[0].tasks[0].completion).toBeUndefined();
|
|
30
|
-
expect(parsed.tracks[0].tasks[1].completion).toBeUndefined();
|
|
31
|
-
expect(parsed.tracks[0].tasks[2].completion).toEqual({ type: 'exit_code', expect: 2 });
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('serializePipeline preserves non-default completion plugins', () => {
|
|
35
|
-
const raw: RawPipelineConfig = {
|
|
36
|
-
name: 'Serialize Explicit',
|
|
37
|
-
tracks: [
|
|
38
|
-
{
|
|
39
|
-
id: 'track_a',
|
|
40
|
-
name: 'Track A',
|
|
41
|
-
tasks: [
|
|
42
|
-
{ id: 'task_1', prompt: 'check file', completion: { type: 'file_exists', path: './out.txt' } },
|
|
43
|
-
],
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const parsed = parsePipelineYaml(serializePipeline(raw));
|
|
49
|
-
expect(parsed.tracks[0].tasks[0].completion).toEqual({
|
|
50
|
-
type: 'file_exists',
|
|
51
|
-
path: './out.txt',
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('deresolvePipeline also omits the default exit_code completion', () => {
|
|
56
|
-
const resolved: PipelineConfig = {
|
|
57
|
-
name: 'Deresolve Defaults',
|
|
58
|
-
tracks: [
|
|
59
|
-
{
|
|
60
|
-
id: 'track_a',
|
|
61
|
-
name: 'Track A',
|
|
62
|
-
driver: 'claude-code',
|
|
63
|
-
permissions: { read: true, write: false, execute: false },
|
|
64
|
-
on_failure: 'skip_downstream',
|
|
65
|
-
cwd: 'D:/workspace',
|
|
66
|
-
tasks: [
|
|
67
|
-
{
|
|
68
|
-
id: 'task_1',
|
|
69
|
-
name: 'Task 1',
|
|
70
|
-
prompt: 'hello',
|
|
71
|
-
driver: 'claude-code',
|
|
72
|
-
permissions: { read: true, write: false, execute: false },
|
|
73
|
-
cwd: 'D:/workspace',
|
|
74
|
-
completion: { type: 'exit_code', expect: 0 },
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: 'task_2',
|
|
78
|
-
name: 'Task 2',
|
|
79
|
-
prompt: 'custom',
|
|
80
|
-
driver: 'claude-code',
|
|
81
|
-
permissions: { read: true, write: false, execute: false },
|
|
82
|
-
cwd: 'D:/workspace',
|
|
83
|
-
completion: { type: 'output_check', check: 'test -f ./done.txt' },
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const raw = deresolvePipeline(resolved, 'D:/workspace');
|
|
91
|
-
expect(raw.tracks[0].tasks[0].completion).toBeUndefined();
|
|
92
|
-
expect(raw.tracks[0].tasks[1].completion).toEqual({
|
|
93
|
-
type: 'output_check',
|
|
94
|
-
check: 'test -f ./done.txt',
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import type { PipelineConfig, RawPipelineConfig } from './types';
|
|
4
|
+
import { parseYaml, deresolvePipeline, serializePipeline } from './schema';
|
|
5
|
+
|
|
6
|
+
function parsePipelineYaml(content: string): RawPipelineConfig {
|
|
7
|
+
const doc = yaml.load(content) as { pipeline: RawPipelineConfig };
|
|
8
|
+
return doc.pipeline;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('completion default serialization', () => {
|
|
12
|
+
test('serializePipeline omits default exit_code completions from raw configs', () => {
|
|
13
|
+
const raw: RawPipelineConfig = {
|
|
14
|
+
name: 'Serialize Defaults',
|
|
15
|
+
tracks: [
|
|
16
|
+
{
|
|
17
|
+
id: 'track_a',
|
|
18
|
+
name: 'Track A',
|
|
19
|
+
tasks: [
|
|
20
|
+
{ id: 'task_1', prompt: 'hello', completion: { type: 'exit_code' } },
|
|
21
|
+
{ id: 'task_2', prompt: 'world', completion: { type: 'exit_code', expect: 0 } },
|
|
22
|
+
{ id: 'task_3', prompt: 'keep me', completion: { type: 'exit_code', expect: 2 } },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const parsed = parsePipelineYaml(serializePipeline(raw));
|
|
29
|
+
expect(parsed.tracks[0].tasks[0].completion).toBeUndefined();
|
|
30
|
+
expect(parsed.tracks[0].tasks[1].completion).toBeUndefined();
|
|
31
|
+
expect(parsed.tracks[0].tasks[2].completion).toEqual({ type: 'exit_code', expect: 2 });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('serializePipeline preserves non-default completion plugins', () => {
|
|
35
|
+
const raw: RawPipelineConfig = {
|
|
36
|
+
name: 'Serialize Explicit',
|
|
37
|
+
tracks: [
|
|
38
|
+
{
|
|
39
|
+
id: 'track_a',
|
|
40
|
+
name: 'Track A',
|
|
41
|
+
tasks: [
|
|
42
|
+
{ id: 'task_1', prompt: 'check file', completion: { type: 'file_exists', path: './out.txt' } },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const parsed = parsePipelineYaml(serializePipeline(raw));
|
|
49
|
+
expect(parsed.tracks[0].tasks[0].completion).toEqual({
|
|
50
|
+
type: 'file_exists',
|
|
51
|
+
path: './out.txt',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('deresolvePipeline also omits the default exit_code completion', () => {
|
|
56
|
+
const resolved: PipelineConfig = {
|
|
57
|
+
name: 'Deresolve Defaults',
|
|
58
|
+
tracks: [
|
|
59
|
+
{
|
|
60
|
+
id: 'track_a',
|
|
61
|
+
name: 'Track A',
|
|
62
|
+
driver: 'claude-code',
|
|
63
|
+
permissions: { read: true, write: false, execute: false },
|
|
64
|
+
on_failure: 'skip_downstream',
|
|
65
|
+
cwd: 'D:/workspace',
|
|
66
|
+
tasks: [
|
|
67
|
+
{
|
|
68
|
+
id: 'task_1',
|
|
69
|
+
name: 'Task 1',
|
|
70
|
+
prompt: 'hello',
|
|
71
|
+
driver: 'claude-code',
|
|
72
|
+
permissions: { read: true, write: false, execute: false },
|
|
73
|
+
cwd: 'D:/workspace',
|
|
74
|
+
completion: { type: 'exit_code', expect: 0 },
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'task_2',
|
|
78
|
+
name: 'Task 2',
|
|
79
|
+
prompt: 'custom',
|
|
80
|
+
driver: 'claude-code',
|
|
81
|
+
permissions: { read: true, write: false, execute: false },
|
|
82
|
+
cwd: 'D:/workspace',
|
|
83
|
+
completion: { type: 'output_check', check: 'test -f ./done.txt' },
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const raw = deresolvePipeline(resolved, 'D:/workspace');
|
|
91
|
+
expect(raw.tracks[0].tasks[0].completion).toBeUndefined();
|
|
92
|
+
expect(raw.tracks[0].tasks[1].completion).toEqual({
|
|
93
|
+
type: 'output_check',
|
|
94
|
+
check: 'test -f ./done.txt',
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
package/src/schema.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import yaml from 'js-yaml';
|
|
2
|
-
import { resolve, relative } from 'path';
|
|
3
|
-
import type {
|
|
4
|
-
PipelineConfig, RawPipelineConfig, RawTrackConfig, RawTaskConfig,
|
|
5
|
-
TrackConfig, TaskConfig, Permissions, MiddlewareConfig, CompletionConfig,
|
|
6
|
-
|
|
7
|
-
} from './
|
|
8
|
-
import { truncateForName, validatePathParam, validatePath } from './utils';
|
|
1
|
+
import yaml from 'js-yaml';
|
|
2
|
+
import { resolve, relative } from 'path';
|
|
3
|
+
import type {
|
|
4
|
+
PipelineConfig, RawPipelineConfig, RawTrackConfig, RawTaskConfig,
|
|
5
|
+
TrackConfig, TaskConfig, Permissions, MiddlewareConfig, CompletionConfig,
|
|
6
|
+
} from './types';
|
|
7
|
+
import { truncateForName, validatePath } from './utils';
|
|
9
8
|
import { DEFAULT_PERMISSIONS } from './types';
|
|
10
9
|
import { buildDag } from './dag';
|
|
11
10
|
|
|
@@ -39,7 +38,6 @@ function validateRawTrack(track: RawTrackConfig): void {
|
|
|
39
38
|
|
|
40
39
|
function validateRawTask(task: RawTaskConfig, trackId: string): void {
|
|
41
40
|
if (!task.id) throw new Error(`track "${trackId}": task.id is required`);
|
|
42
|
-
if (task.use) return; // template usage, validated later
|
|
43
41
|
|
|
44
42
|
const hasPromptKey = typeof task.prompt === 'string';
|
|
45
43
|
const hasCommandKey = typeof task.command === 'string';
|
|
@@ -53,168 +51,6 @@ function validateRawTask(task: RawTaskConfig, trackId: string): void {
|
|
|
53
51
|
// flagged as non-fatal validation errors by validate-raw.ts.
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
// ═══ Template Expansion ═══
|
|
57
|
-
|
|
58
|
-
export async function expandTemplates(
|
|
59
|
-
tasks: readonly RawTaskConfig[],
|
|
60
|
-
instancePrefix: string,
|
|
61
|
-
): Promise<RawTaskConfig[]> {
|
|
62
|
-
const result: RawTaskConfig[] = [];
|
|
63
|
-
|
|
64
|
-
for (const task of tasks) {
|
|
65
|
-
if (!task.use) {
|
|
66
|
-
result.push(task);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const template = await loadTemplate(task.use);
|
|
71
|
-
const params = resolveTemplateParams(template, task.with ?? {}, task.id);
|
|
72
|
-
const expanded = expandTemplateTask(template, params, task.id, instancePrefix);
|
|
73
|
-
result.push(...expanded);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function validateTemplateRef(ref: string): void {
|
|
80
|
-
const stripped = ref.replace(/@v\d+$/, '');
|
|
81
|
-
// Reject path traversal and absolute paths before they reach import().
|
|
82
|
-
if (stripped.includes('..') || stripped.startsWith('/') || /^[a-zA-Z]:/.test(stripped)) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Invalid template ref "${ref}": path traversal and absolute paths are not allowed. ` +
|
|
85
|
-
`Use a scoped package name, e.g. "@tagma/template-review".`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
// Whitelist: only @tagma/template-* packages are allowed.
|
|
89
|
-
if (!stripped.startsWith('@tagma/template-')) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
`Invalid template ref "${ref}": only "@tagma/template-*" packages are allowed as templates. ` +
|
|
92
|
-
`Example: "@tagma/template-review".`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function loadTemplate(ref: string): Promise<TemplateConfig> {
|
|
98
|
-
validateTemplateRef(ref);
|
|
99
|
-
// Strip version suffix for import
|
|
100
|
-
const moduleName = ref.replace(/@v\d+$/, '');
|
|
101
|
-
try {
|
|
102
|
-
const mod = await import(moduleName);
|
|
103
|
-
// Expect the module to export a template.yaml content or parsed object
|
|
104
|
-
if (mod.template) return mod.template as TemplateConfig;
|
|
105
|
-
|
|
106
|
-
// Try loading template.yaml from the package.
|
|
107
|
-
// NOTE: require.resolve is a CommonJS API. Bun supports it natively, but
|
|
108
|
-
// this would need import.meta.resolve() for pure ESM runtimes (e.g. Deno).
|
|
109
|
-
const pkgPath = require.resolve(`${moduleName}/template.yaml`);
|
|
110
|
-
const content = await Bun.file(pkgPath).text();
|
|
111
|
-
const doc = yaml.load(content) as { template: TemplateConfig };
|
|
112
|
-
return doc.template;
|
|
113
|
-
} catch (err) {
|
|
114
|
-
if (err instanceof Error && err.message.startsWith('Invalid template ref')) throw err;
|
|
115
|
-
throw new Error(`Failed to load template: "${ref}". Is the package installed?`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function resolveTemplateParams(
|
|
120
|
-
template: TemplateConfig,
|
|
121
|
-
provided: Record<string, unknown>,
|
|
122
|
-
instanceId: string,
|
|
123
|
-
): Record<string, unknown> {
|
|
124
|
-
const params: Record<string, unknown> = {};
|
|
125
|
-
const defs = template.params ?? {};
|
|
126
|
-
|
|
127
|
-
for (const [key, def] of Object.entries(defs)) {
|
|
128
|
-
const value = provided[key] ?? def.default;
|
|
129
|
-
if (value === undefined) {
|
|
130
|
-
throw new Error(`Template "${template.name}" instance "${instanceId}": missing required param "${key}"`);
|
|
131
|
-
}
|
|
132
|
-
validateParamType(key, value, def, template.name, instanceId);
|
|
133
|
-
params[key] = value;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Warn about unknown params
|
|
137
|
-
for (const key of Object.keys(provided)) {
|
|
138
|
-
if (!(key in defs)) {
|
|
139
|
-
console.warn(`Template "${template.name}" instance "${instanceId}": unknown param "${key}"`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return params;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function validateParamType(
|
|
147
|
-
key: string, value: unknown, def: TemplateParamDef,
|
|
148
|
-
templateName: string, instanceId: string,
|
|
149
|
-
): void {
|
|
150
|
-
const ctx = `Template "${templateName}" instance "${instanceId}" param "${key}"`;
|
|
151
|
-
const ptype = def.type ?? 'string';
|
|
152
|
-
|
|
153
|
-
switch (ptype) {
|
|
154
|
-
case 'string':
|
|
155
|
-
if (typeof value !== 'string') throw new Error(`${ctx}: expected string, got ${typeof value}`);
|
|
156
|
-
break;
|
|
157
|
-
case 'path':
|
|
158
|
-
if (typeof value !== 'string') throw new Error(`${ctx}: expected path string, got ${typeof value}`);
|
|
159
|
-
validatePathParam(value);
|
|
160
|
-
break;
|
|
161
|
-
case 'enum':
|
|
162
|
-
if (!def.enum?.includes(value as string)) {
|
|
163
|
-
throw new Error(`${ctx}: value "${value}" not in allowed values [${def.enum?.join(', ')}]`);
|
|
164
|
-
}
|
|
165
|
-
break;
|
|
166
|
-
case 'number':
|
|
167
|
-
if (typeof value !== 'number') throw new Error(`${ctx}: expected number, got ${typeof value}`);
|
|
168
|
-
if (def.min !== undefined && value < def.min) throw new Error(`${ctx}: ${value} < min ${def.min}`);
|
|
169
|
-
if (def.max !== undefined && value > def.max) throw new Error(`${ctx}: ${value} > max ${def.max}`);
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function expandTemplateTask(
|
|
175
|
-
template: TemplateConfig,
|
|
176
|
-
params: Record<string, unknown>,
|
|
177
|
-
instanceId: string,
|
|
178
|
-
instancePrefix: string,
|
|
179
|
-
): RawTaskConfig[] {
|
|
180
|
-
return template.tasks.map(task => {
|
|
181
|
-
const prefixedId = `${instanceId}.${task.id}`;
|
|
182
|
-
|
|
183
|
-
// Replace ${{ params.xxx }} in string fields
|
|
184
|
-
const interpolate = (s: string): string =>
|
|
185
|
-
s.replace(/\$\{\{\s*params\.(\w+)\s*\}\}/g, (_, key) => String(params[key] ?? ''));
|
|
186
|
-
|
|
187
|
-
const newTask: Record<string, unknown> = { ...task, id: prefixedId };
|
|
188
|
-
|
|
189
|
-
// Interpolate string fields
|
|
190
|
-
if (task.prompt) newTask.prompt = interpolate(task.prompt);
|
|
191
|
-
if (task.command) newTask.command = interpolate(task.command);
|
|
192
|
-
|
|
193
|
-
// Namespace depends_on
|
|
194
|
-
if (task.depends_on) {
|
|
195
|
-
newTask.depends_on = task.depends_on.map(dep => `${instanceId}.${dep}`);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Namespace continue_from
|
|
199
|
-
if (task.continue_from) {
|
|
200
|
-
newTask.continue_from = `${instanceId}.${task.continue_from}`;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Rewrite output path to instance namespace so parallel template
|
|
204
|
-
// instances don't collide on the same file. Handles any relative path
|
|
205
|
-
// (e.g. ./tmp/foo, ./output/bar, ./build/result.json) by injecting
|
|
206
|
-
// the instanceId as the first directory component after `./`.
|
|
207
|
-
if (task.output) {
|
|
208
|
-
const original = interpolate(task.output);
|
|
209
|
-
newTask.output = original.startsWith('./')
|
|
210
|
-
? `./${instanceId}/${original.slice(2)}`
|
|
211
|
-
: `${instanceId}/${original}`;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return newTask as unknown as RawTaskConfig;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
54
|
// ═══ Config Inheritance Resolution ═══
|
|
219
55
|
|
|
220
56
|
export function resolveConfig(raw: RawPipelineConfig, workDir: string): PipelineConfig {
|
|
@@ -263,7 +99,6 @@ export function resolveConfig(raw: RawPipelineConfig, workDir: string): Pipeline
|
|
|
263
99
|
continue_from: rawTask.continue_from
|
|
264
100
|
? qualifyContinueFrom(rawTask.continue_from, rawTrack.id)
|
|
265
101
|
: undefined,
|
|
266
|
-
output: rawTask.output,
|
|
267
102
|
// Inheritance: Task > Track > Pipeline
|
|
268
103
|
model: rawTask.model ?? rawTrack.model ?? raw.model,
|
|
269
104
|
reasoning_effort: rawTask.reasoning_effort ?? rawTrack.reasoning_effort ?? raw.reasoning_effort,
|
|
@@ -307,42 +142,42 @@ export function resolveConfig(raw: RawPipelineConfig, workDir: string): Pipeline
|
|
|
307
142
|
}
|
|
308
143
|
|
|
309
144
|
// Field-by-field permissions comparison — avoids relying on JSON.stringify key order.
|
|
310
|
-
function permissionsEqual(a: Permissions | undefined, b: Permissions | undefined): boolean {
|
|
311
|
-
if (a === b) return true;
|
|
312
|
-
if (!a || !b) return false;
|
|
313
|
-
return a.read === b.read && a.write === b.write && a.execute === b.execute;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function isDefaultExitCodeCompletion(
|
|
317
|
-
completion: CompletionConfig | undefined,
|
|
318
|
-
): boolean {
|
|
319
|
-
if (!completion || completion.type !== 'exit_code') return false;
|
|
320
|
-
const { type: _type, expect, ...rest } = completion as CompletionConfig & {
|
|
321
|
-
expect?: unknown;
|
|
322
|
-
};
|
|
323
|
-
if (Object.keys(rest).length > 0) return false;
|
|
324
|
-
return expect === undefined || expect === 0;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function stripDefaultTaskCompletion<T extends { completion?: CompletionConfig }>(
|
|
328
|
-
task: T,
|
|
329
|
-
): T {
|
|
330
|
-
if (!isDefaultExitCodeCompletion(task.completion)) return task;
|
|
331
|
-
const { completion: _completion, ...rest } = task;
|
|
332
|
-
return rest as T;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function stripDefaultCompletionsForSerialization<
|
|
336
|
-
T extends PipelineConfig | RawPipelineConfig,
|
|
337
|
-
>(config: T): T {
|
|
338
|
-
return {
|
|
339
|
-
...config,
|
|
340
|
-
tracks: config.tracks.map((track) => ({
|
|
341
|
-
...track,
|
|
342
|
-
tasks: track.tasks.map((task) => stripDefaultTaskCompletion(task)),
|
|
343
|
-
})),
|
|
344
|
-
} as T;
|
|
345
|
-
}
|
|
145
|
+
function permissionsEqual(a: Permissions | undefined, b: Permissions | undefined): boolean {
|
|
146
|
+
if (a === b) return true;
|
|
147
|
+
if (!a || !b) return false;
|
|
148
|
+
return a.read === b.read && a.write === b.write && a.execute === b.execute;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function isDefaultExitCodeCompletion(
|
|
152
|
+
completion: CompletionConfig | undefined,
|
|
153
|
+
): boolean {
|
|
154
|
+
if (!completion || completion.type !== 'exit_code') return false;
|
|
155
|
+
const { type: _type, expect, ...rest } = completion as CompletionConfig & {
|
|
156
|
+
expect?: unknown;
|
|
157
|
+
};
|
|
158
|
+
if (Object.keys(rest).length > 0) return false;
|
|
159
|
+
return expect === undefined || expect === 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function stripDefaultTaskCompletion<T extends { completion?: CompletionConfig }>(
|
|
163
|
+
task: T,
|
|
164
|
+
): T {
|
|
165
|
+
if (!isDefaultExitCodeCompletion(task.completion)) return task;
|
|
166
|
+
const { completion: _completion, ...rest } = task;
|
|
167
|
+
return rest as T;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function stripDefaultCompletionsForSerialization<
|
|
171
|
+
T extends PipelineConfig | RawPipelineConfig,
|
|
172
|
+
>(config: T): T {
|
|
173
|
+
return {
|
|
174
|
+
...config,
|
|
175
|
+
tracks: config.tracks.map((track) => ({
|
|
176
|
+
...track,
|
|
177
|
+
tasks: track.tasks.map((task) => stripDefaultTaskCompletion(task)),
|
|
178
|
+
})),
|
|
179
|
+
} as T;
|
|
180
|
+
}
|
|
346
181
|
|
|
347
182
|
// ═══ YAML Serialization ═══
|
|
348
183
|
|
|
@@ -350,12 +185,12 @@ function stripDefaultCompletionsForSerialization<
|
|
|
350
185
|
* Serialize a pipeline config back to YAML string.
|
|
351
186
|
* Wraps the config under the top-level `pipeline` key as expected by parseYaml.
|
|
352
187
|
*/
|
|
353
|
-
export function serializePipeline(config: PipelineConfig | RawPipelineConfig): string {
|
|
354
|
-
return yaml.dump(
|
|
355
|
-
{ pipeline: stripDefaultCompletionsForSerialization(config) },
|
|
356
|
-
{ lineWidth: 120, indent: 2 },
|
|
357
|
-
);
|
|
358
|
-
}
|
|
188
|
+
export function serializePipeline(config: PipelineConfig | RawPipelineConfig): string {
|
|
189
|
+
return yaml.dump(
|
|
190
|
+
{ pipeline: stripDefaultCompletionsForSerialization(config) },
|
|
191
|
+
{ lineWidth: 120, indent: 2 },
|
|
192
|
+
);
|
|
193
|
+
}
|
|
359
194
|
|
|
360
195
|
/**
|
|
361
196
|
* Convert a resolved PipelineConfig back to a RawPipelineConfig for serialization.
|
|
@@ -388,7 +223,6 @@ export function deresolvePipeline(config: PipelineConfig, workDir: string): RawP
|
|
|
388
223
|
...(task.depends_on?.length ? { depends_on: task.depends_on } : {}),
|
|
389
224
|
...(task.trigger ? { trigger: task.trigger } : {}),
|
|
390
225
|
...(task.continue_from ? { continue_from: task.continue_from } : {}),
|
|
391
|
-
...(task.output ? { output: task.output } : {}),
|
|
392
226
|
...(taskCwdRel ? { cwd: taskCwdRel } : {}),
|
|
393
227
|
...(task.model && task.model !== effectiveTrackModel ? { model: task.model } : {}),
|
|
394
228
|
...(task.reasoning_effort && task.reasoning_effort !== effectiveTrackReasoning
|
|
@@ -397,9 +231,9 @@ export function deresolvePipeline(config: PipelineConfig, workDir: string): RawP
|
|
|
397
231
|
...(task.driver && task.driver !== effectiveTrackDriver ? { driver: task.driver } : {}),
|
|
398
232
|
...(task.timeout ? { timeout: task.timeout } : {}),
|
|
399
233
|
...(task.middlewares !== undefined ? { middlewares: task.middlewares } : {}),
|
|
400
|
-
...(task.completion && !isDefaultExitCodeCompletion(task.completion)
|
|
401
|
-
? { completion: task.completion }
|
|
402
|
-
: {}),
|
|
234
|
+
...(task.completion && !isDefaultExitCodeCompletion(task.completion)
|
|
235
|
+
? { completion: task.completion }
|
|
236
|
+
: {}),
|
|
403
237
|
...(task.agent_profile ? { agent_profile: task.agent_profile } : {}),
|
|
404
238
|
...(task.permissions && !permissionsEqual(task.permissions, track.permissions)
|
|
405
239
|
? { permissions: task.permissions }
|
|
@@ -460,14 +294,5 @@ export function validateConfig(config: PipelineConfig): string[] {
|
|
|
460
294
|
|
|
461
295
|
export async function loadPipeline(yamlContent: string, workDir: string): Promise<PipelineConfig> {
|
|
462
296
|
const raw = parseYaml(yamlContent);
|
|
463
|
-
|
|
464
|
-
// Expand templates in each track
|
|
465
|
-
const expandedTracks: RawTrackConfig[] = [];
|
|
466
|
-
for (const track of raw.tracks) {
|
|
467
|
-
const expandedTasks = await expandTemplates(track.tasks, track.id);
|
|
468
|
-
expandedTracks.push({ ...track, tasks: expandedTasks });
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
const expandedRaw: RawPipelineConfig = { ...raw, tracks: expandedTracks };
|
|
472
|
-
return resolveConfig(expandedRaw, workDir);
|
|
297
|
+
return resolveConfig(raw, workDir);
|
|
473
298
|
}
|
package/src/sdk.ts
CHANGED
|
@@ -30,11 +30,7 @@ export { validateRaw } from './validate-raw';
|
|
|
30
30
|
export type { ValidationError } from './validate-raw';
|
|
31
31
|
|
|
32
32
|
// ── Schema: parse / resolve / load / serialize / validate ──
|
|
33
|
-
export { parseYaml, resolveConfig,
|
|
34
|
-
|
|
35
|
-
// ── Templates: discovery + manifest loading (F1) ──
|
|
36
|
-
export { discoverTemplates, loadTemplateManifest } from './templates';
|
|
37
|
-
export type { TemplateManifest } from './templates';
|
|
33
|
+
export { parseYaml, resolveConfig, loadPipeline, serializePipeline, deresolvePipeline, validateConfig } from './schema';
|
|
38
34
|
|
|
39
35
|
// ── DAG ──
|
|
40
36
|
export { buildDag, buildRawDag } from './dag';
|
package/src/utils.ts
CHANGED
|
@@ -33,20 +33,6 @@ export function validatePath(filePath: string, projectRoot: string): string {
|
|
|
33
33
|
return resolved;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const SHELL_META_CHARS = /[;&|$`\\!><()\[\]{}*?#~]/;
|
|
37
|
-
|
|
38
|
-
export function validatePathParam(filePath: string): void {
|
|
39
|
-
if (filePath.includes('..')) {
|
|
40
|
-
throw new Error(`Template param type=path: ".." traversal not allowed in "${filePath}"`);
|
|
41
|
-
}
|
|
42
|
-
if (resolve(filePath) === filePath) {
|
|
43
|
-
throw new Error(`Template param type=path: absolute path not allowed: "${filePath}"`);
|
|
44
|
-
}
|
|
45
|
-
if (SHELL_META_CHARS.test(filePath)) {
|
|
46
|
-
throw new Error(`Template param type=path: shell metacharacters not allowed in "${filePath}"`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
36
|
let runCounter = 0;
|
|
51
37
|
|
|
52
38
|
export function generateRunId(): string {
|
package/src/validate-raw.ts
CHANGED
|
@@ -180,9 +180,6 @@ export function validateRaw(
|
|
|
180
180
|
}
|
|
181
181
|
seenTaskIds.add(task.id);
|
|
182
182
|
|
|
183
|
-
// Template-based tasks: skip prompt/command checks (params validated at runtime)
|
|
184
|
-
if (task.use) continue;
|
|
185
|
-
|
|
186
183
|
const hasPromptKey = typeof task.prompt === 'string';
|
|
187
184
|
const hasCommandKey = typeof task.command === 'string';
|
|
188
185
|
const promptEmpty = hasPromptKey && task.prompt!.trim().length === 0;
|
|
@@ -333,7 +330,7 @@ function detectCycles(
|
|
|
333
330
|
for (const track of config.tracks) {
|
|
334
331
|
if (!track.id) continue;
|
|
335
332
|
for (const task of track.tasks ?? []) {
|
|
336
|
-
if (!task.id
|
|
333
|
+
if (!task.id) continue;
|
|
337
334
|
const qid = `${track.id}.${task.id}`;
|
|
338
335
|
const deps: string[] = [];
|
|
339
336
|
for (const dep of task.depends_on ?? []) {
|