@tagma/sdk 0.6.12 → 0.7.1
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 +56 -15
- package/dist/bootstrap.d.ts +6 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +5 -6
- package/dist/bootstrap.js.map +1 -1
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/core/dataflow.d.ts +23 -0
- package/dist/core/dataflow.d.ts.map +1 -0
- package/dist/core/dataflow.js +99 -0
- package/dist/core/dataflow.js.map +1 -0
- package/dist/core/log-prune.d.ts +16 -0
- package/dist/core/log-prune.d.ts.map +1 -0
- package/dist/core/log-prune.js +34 -0
- package/dist/core/log-prune.js.map +1 -0
- package/dist/core/preflight.d.ts +13 -0
- package/dist/core/preflight.d.ts.map +1 -0
- package/dist/core/preflight.js +61 -0
- package/dist/core/preflight.js.map +1 -0
- package/dist/core/run-context.d.ts +52 -0
- package/dist/core/run-context.d.ts.map +1 -0
- package/dist/core/run-context.js +156 -0
- package/dist/core/run-context.js.map +1 -0
- package/dist/core/run-state.d.ts +25 -0
- package/dist/core/run-state.d.ts.map +1 -0
- package/dist/core/run-state.js +93 -0
- package/dist/core/run-state.js.map +1 -0
- package/dist/core/scheduler.d.ts +13 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +35 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/task-executor.d.ts +13 -0
- package/dist/core/task-executor.d.ts.map +1 -0
- package/dist/core/task-executor.js +623 -0
- package/dist/core/task-executor.js.map +1 -0
- package/dist/core/trigger-errors.d.ts +9 -0
- package/dist/core/trigger-errors.d.ts.map +1 -0
- package/dist/core/trigger-errors.js +15 -0
- package/dist/core/trigger-errors.js.map +1 -0
- package/dist/engine.d.ts +6 -14
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +68 -1035
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/pipeline-definition.d.ts +3 -0
- package/dist/pipeline-definition.d.ts.map +1 -0
- package/dist/pipeline-definition.js +4 -0
- package/dist/pipeline-definition.js.map +1 -0
- package/dist/pipeline-runner.d.ts +2 -1
- package/dist/pipeline-runner.d.ts.map +1 -1
- package/dist/pipeline-runner.js +2 -2
- package/dist/pipeline-runner.js.map +1 -1
- package/dist/plugins.d.ts +5 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +3 -0
- package/dist/plugins.js.map +1 -0
- package/dist/ports.d.ts +4 -0
- package/dist/ports.d.ts.map +1 -1
- package/dist/ports.js +27 -4
- package/dist/ports.js.map +1 -1
- package/dist/registry.d.ts +3 -19
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +7 -35
- package/dist/registry.js.map +1 -1
- package/dist/tagma.d.ts +24 -0
- package/dist/tagma.d.ts.map +1 -0
- package/dist/tagma.js +23 -0
- package/dist/tagma.js.map +1 -0
- package/dist/utils-api.d.ts +2 -0
- package/dist/utils-api.d.ts.map +1 -0
- package/dist/utils-api.js +2 -0
- package/dist/utils-api.js.map +1 -0
- package/dist/validate-raw.d.ts +4 -4
- package/dist/validate-raw.js +91 -132
- package/dist/validate-raw.js.map +1 -1
- package/dist/yaml.d.ts +4 -0
- package/dist/yaml.d.ts.map +1 -0
- package/dist/yaml.js +3 -0
- package/dist/yaml.js.map +1 -0
- package/package.json +53 -8
- package/src/bootstrap.ts +6 -6
- package/src/config.ts +26 -0
- package/src/core/dataflow.test.ts +166 -0
- package/src/core/dataflow.ts +161 -0
- package/src/core/log-prune.test.ts +58 -0
- package/src/core/log-prune.ts +43 -0
- package/src/core/preflight.test.ts +49 -0
- package/src/core/preflight.ts +89 -0
- package/src/core/run-context.test.ts +244 -0
- package/src/core/run-context.ts +207 -0
- package/src/core/run-state.test.ts +98 -0
- package/src/core/run-state.ts +122 -0
- package/src/core/scheduler.test.ts +83 -0
- package/src/core/scheduler.ts +42 -0
- package/src/core/task-executor.ts +769 -0
- package/src/core/trigger-errors.ts +15 -0
- package/src/engine-ports-mixed.test.ts +68 -411
- package/src/engine-ports.test.ts +37 -341
- package/src/engine.ts +80 -1248
- package/src/index.ts +28 -0
- package/src/pipeline-definition.ts +5 -0
- package/src/pipeline-runner.test.ts +5 -9
- package/src/pipeline-runner.ts +3 -2
- package/src/plugin-registry.test.ts +7 -10
- package/src/plugins.ts +18 -0
- package/src/ports.test.ts +80 -0
- package/src/ports.ts +36 -4
- package/src/registry.ts +7 -49
- package/src/schema-ports.test.ts +41 -214
- package/src/tagma.test.ts +84 -0
- package/src/tagma.ts +47 -0
- package/src/utils-api.ts +8 -0
- package/src/validate-raw-ports.test.ts +80 -393
- package/src/validate-raw.ts +93 -137
- package/src/yaml.ts +11 -0
- package/dist/sdk.d.ts +0 -32
- package/dist/sdk.d.ts.map +0 -1
- package/dist/sdk.js +0 -41
- package/dist/sdk.js.map +0 -1
- package/src/sdk.ts +0 -151
package/dist/yaml.js
ADDED
package/dist/yaml.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.js","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tagma/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Local AI task orchestration engine — core SDK for tagma pipelines",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,14 +12,59 @@
|
|
|
12
12
|
"homepage": "https://github.com/GoTagma/tagma-mono/tree/main/packages/sdk#readme",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
|
-
"main": "./dist/
|
|
16
|
-
"module": "./dist/
|
|
17
|
-
"types": "./dist/
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"types": "./dist/
|
|
21
|
-
"import": "./dist/
|
|
22
|
-
"default": "./dist/
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./yaml": {
|
|
25
|
+
"types": "./dist/yaml.d.ts",
|
|
26
|
+
"import": "./dist/yaml.js",
|
|
27
|
+
"default": "./dist/yaml.js"
|
|
28
|
+
},
|
|
29
|
+
"./config": {
|
|
30
|
+
"types": "./dist/config.d.ts",
|
|
31
|
+
"import": "./dist/config.js",
|
|
32
|
+
"default": "./dist/config.js"
|
|
33
|
+
},
|
|
34
|
+
"./plugins": {
|
|
35
|
+
"types": "./dist/plugins.d.ts",
|
|
36
|
+
"import": "./dist/plugins.js",
|
|
37
|
+
"default": "./dist/plugins.js"
|
|
38
|
+
},
|
|
39
|
+
"./runner": {
|
|
40
|
+
"types": "./dist/pipeline-runner.d.ts",
|
|
41
|
+
"import": "./dist/pipeline-runner.js",
|
|
42
|
+
"default": "./dist/pipeline-runner.js"
|
|
43
|
+
},
|
|
44
|
+
"./logger": {
|
|
45
|
+
"types": "./dist/logger.d.ts",
|
|
46
|
+
"import": "./dist/logger.js",
|
|
47
|
+
"default": "./dist/logger.js"
|
|
48
|
+
},
|
|
49
|
+
"./approval": {
|
|
50
|
+
"types": "./dist/approval.d.ts",
|
|
51
|
+
"import": "./dist/approval.js",
|
|
52
|
+
"default": "./dist/approval.js"
|
|
53
|
+
},
|
|
54
|
+
"./utils": {
|
|
55
|
+
"types": "./dist/utils-api.d.ts",
|
|
56
|
+
"import": "./dist/utils-api.js",
|
|
57
|
+
"default": "./dist/utils-api.js"
|
|
58
|
+
},
|
|
59
|
+
"./adapters/stdin-approval": {
|
|
60
|
+
"types": "./dist/adapters/stdin-approval.d.ts",
|
|
61
|
+
"import": "./dist/adapters/stdin-approval.js",
|
|
62
|
+
"default": "./dist/adapters/stdin-approval.js"
|
|
63
|
+
},
|
|
64
|
+
"./adapters/websocket-approval": {
|
|
65
|
+
"types": "./dist/adapters/websocket-approval.d.ts",
|
|
66
|
+
"import": "./dist/adapters/websocket-approval.js",
|
|
67
|
+
"default": "./dist/adapters/websocket-approval.js"
|
|
23
68
|
},
|
|
24
69
|
"./ports": {
|
|
25
70
|
"types": "./dist/ports.d.ts",
|
|
@@ -47,7 +92,7 @@
|
|
|
47
92
|
"release:publish": "bun scripts/release.ts --publish"
|
|
48
93
|
},
|
|
49
94
|
"dependencies": {
|
|
50
|
-
"@tagma/types": "0.4.
|
|
95
|
+
"@tagma/types": "0.4.9",
|
|
51
96
|
"js-yaml": "^4.1.0",
|
|
52
97
|
"chokidar": "^4.0.0"
|
|
53
98
|
}
|
package/src/bootstrap.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PluginRegistry } from './registry';
|
|
2
2
|
|
|
3
3
|
// Built-in Drivers
|
|
4
4
|
// Only opencode is built in. Other drivers (codex, claude-code) ship as
|
|
@@ -20,15 +20,15 @@ import { OutputCheckCompletion } from './completions/output-check';
|
|
|
20
20
|
import { StaticContextMiddleware } from './middlewares/static-context';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Register every built-in plugin into `target
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* Register every built-in plugin into `target`. Hosts instantiate one
|
|
24
|
+
* PluginRegistry per workspace or SDK instance and call this once per
|
|
25
|
+
* instance so each workspace sees the same built-ins without sharing
|
|
26
|
+
* registration state.
|
|
27
27
|
*
|
|
28
28
|
* Built-in handlers are stateless module singletons — registering the same
|
|
29
29
|
* handler object into N registries is cheap and safe; no cloning is needed.
|
|
30
30
|
*/
|
|
31
|
-
export function bootstrapBuiltins(target: PluginRegistry
|
|
31
|
+
export function bootstrapBuiltins(target: PluginRegistry): void {
|
|
32
32
|
// Drivers
|
|
33
33
|
target.registerPlugin('drivers', 'opencode', OpenCodeDriver);
|
|
34
34
|
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createEmptyPipeline,
|
|
3
|
+
setPipelineField,
|
|
4
|
+
upsertTrack,
|
|
5
|
+
removeTrack,
|
|
6
|
+
moveTrack,
|
|
7
|
+
updateTrack,
|
|
8
|
+
upsertTask,
|
|
9
|
+
removeTask,
|
|
10
|
+
moveTask,
|
|
11
|
+
transferTask,
|
|
12
|
+
} from './config-ops';
|
|
13
|
+
export { validateRaw } from './validate-raw';
|
|
14
|
+
export type { ValidationError, KnownPluginTypes } from './validate-raw';
|
|
15
|
+
export { buildRawDag } from './dag';
|
|
16
|
+
export type { RawDag, RawDagNode } from './dag';
|
|
17
|
+
export {
|
|
18
|
+
TASK_ID_RE,
|
|
19
|
+
isValidTaskId,
|
|
20
|
+
qualifyTaskId,
|
|
21
|
+
isQualifiedRef,
|
|
22
|
+
buildTaskIndex,
|
|
23
|
+
resolveTaskRef,
|
|
24
|
+
AMBIGUOUS,
|
|
25
|
+
} from './task-ref';
|
|
26
|
+
export type { TaskIndex, RefResolution } from './task-ref';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { buildDag } from '../dag';
|
|
3
|
+
import type { PipelineConfig, TaskResult } from '../types';
|
|
4
|
+
import { RunContext } from './run-context';
|
|
5
|
+
import {
|
|
6
|
+
inferEffectivePorts,
|
|
7
|
+
extractSuccessfulOutputs,
|
|
8
|
+
} from './dataflow';
|
|
9
|
+
|
|
10
|
+
function makeContext(config: PipelineConfig): RunContext {
|
|
11
|
+
return new RunContext({
|
|
12
|
+
runId: 'run_dataflow',
|
|
13
|
+
dag: buildDag(config),
|
|
14
|
+
config,
|
|
15
|
+
workDir: '/tmp/wd',
|
|
16
|
+
pipelineInfo: {
|
|
17
|
+
name: config.name,
|
|
18
|
+
run_id: 'run_dataflow',
|
|
19
|
+
started_at: '2026-04-26T00:00:00Z',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function result(stdout: string, normalizedOutput: string | null = null): TaskResult {
|
|
25
|
+
return {
|
|
26
|
+
exitCode: 0,
|
|
27
|
+
stdout,
|
|
28
|
+
stderr: '',
|
|
29
|
+
stdoutPath: null,
|
|
30
|
+
stderrPath: null,
|
|
31
|
+
durationMs: 1,
|
|
32
|
+
sessionId: null,
|
|
33
|
+
normalizedOutput,
|
|
34
|
+
failureKind: null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('inferEffectivePorts', () => {
|
|
39
|
+
test('returns typed outputs for command tasks', () => {
|
|
40
|
+
const config: PipelineConfig = {
|
|
41
|
+
name: 'p',
|
|
42
|
+
tracks: [
|
|
43
|
+
{
|
|
44
|
+
id: 't',
|
|
45
|
+
name: 'T',
|
|
46
|
+
tasks: [
|
|
47
|
+
{
|
|
48
|
+
id: 'cmd',
|
|
49
|
+
name: 'Cmd',
|
|
50
|
+
command: 'echo',
|
|
51
|
+
outputs: { city: { type: 'string' } },
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
const ctx = makeContext(config);
|
|
58
|
+
const inferred = inferEffectivePorts(ctx, 't.cmd');
|
|
59
|
+
expect(inferred.kind).toBe('ready');
|
|
60
|
+
if (inferred.kind === 'ready') {
|
|
61
|
+
expect(inferred.isPromptTask).toBe(false);
|
|
62
|
+
expect(inferred.effectivePorts?.outputs?.[0]?.name).toBe('city');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('infers prompt inputs from upstream command outputs', () => {
|
|
67
|
+
const config: PipelineConfig = {
|
|
68
|
+
name: 'p',
|
|
69
|
+
tracks: [
|
|
70
|
+
{
|
|
71
|
+
id: 't',
|
|
72
|
+
name: 'T',
|
|
73
|
+
tasks: [
|
|
74
|
+
{
|
|
75
|
+
id: 'up',
|
|
76
|
+
name: 'Up',
|
|
77
|
+
command: 'echo',
|
|
78
|
+
outputs: { city: { type: 'string' } },
|
|
79
|
+
},
|
|
80
|
+
{ id: 'prompt', name: 'Prompt', prompt: 'hi', depends_on: ['up'] },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
const ctx = makeContext(config);
|
|
86
|
+
const inferred = inferEffectivePorts(ctx, 't.prompt');
|
|
87
|
+
expect(inferred.kind).toBe('ready');
|
|
88
|
+
if (inferred.kind === 'ready') {
|
|
89
|
+
expect(inferred.isPromptTask).toBe(true);
|
|
90
|
+
expect(inferred.effectivePorts?.inputs?.[0]?.name).toBe('city');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('blocks prompt tasks when upstream command outputs are ambiguous', () => {
|
|
95
|
+
const config: PipelineConfig = {
|
|
96
|
+
name: 'p',
|
|
97
|
+
tracks: [
|
|
98
|
+
{
|
|
99
|
+
id: 't',
|
|
100
|
+
name: 'T',
|
|
101
|
+
tasks: [
|
|
102
|
+
{
|
|
103
|
+
id: 'a',
|
|
104
|
+
name: 'A',
|
|
105
|
+
command: 'echo',
|
|
106
|
+
outputs: { city: { type: 'string' } },
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'b',
|
|
110
|
+
name: 'B',
|
|
111
|
+
command: 'echo',
|
|
112
|
+
outputs: { city: { type: 'string' } },
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 'prompt',
|
|
116
|
+
name: 'Prompt',
|
|
117
|
+
prompt: 'hi',
|
|
118
|
+
depends_on: ['a', 'b'],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
const ctx = makeContext(config);
|
|
125
|
+
const inferred = inferEffectivePorts(ctx, 't.prompt');
|
|
126
|
+
expect(inferred.kind).toBe('blocked');
|
|
127
|
+
if (inferred.kind === 'blocked') {
|
|
128
|
+
expect(inferred.reason).toContain('city');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('extractSuccessfulOutputs', () => {
|
|
134
|
+
test('extracts typed binding outputs', () => {
|
|
135
|
+
const config: PipelineConfig = {
|
|
136
|
+
name: 'p',
|
|
137
|
+
tracks: [
|
|
138
|
+
{
|
|
139
|
+
id: 't',
|
|
140
|
+
name: 'T',
|
|
141
|
+
tasks: [
|
|
142
|
+
{
|
|
143
|
+
id: 'cmd',
|
|
144
|
+
name: 'Cmd',
|
|
145
|
+
command: 'echo',
|
|
146
|
+
outputs: { city: { type: 'string' }, raw: { from: 'stdout' } },
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
};
|
|
152
|
+
const ctx = makeContext(config);
|
|
153
|
+
const node = ctx.dag.nodes.get('t.cmd')!;
|
|
154
|
+
const extracted = extractSuccessfulOutputs({
|
|
155
|
+
task: node.task,
|
|
156
|
+
effectivePorts: undefined,
|
|
157
|
+
result: result('{"city":"Paris"}'),
|
|
158
|
+
});
|
|
159
|
+
expect(extracted.outputs).toEqual({
|
|
160
|
+
raw: '{"city":"Paris"}',
|
|
161
|
+
city: 'Paris',
|
|
162
|
+
});
|
|
163
|
+
expect(extracted.bindingDiagnostic).toBeNull();
|
|
164
|
+
expect(extracted.portDiagnostic).toBeNull();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PortDef,
|
|
3
|
+
TaskConfig,
|
|
4
|
+
TaskInputBindings,
|
|
5
|
+
TaskOutputBindings,
|
|
6
|
+
TaskPorts,
|
|
7
|
+
TaskResult,
|
|
8
|
+
} from '../types';
|
|
9
|
+
import {
|
|
10
|
+
extractTaskBindingOutputs,
|
|
11
|
+
extractTaskOutputs,
|
|
12
|
+
inferPromptPorts,
|
|
13
|
+
} from '../ports';
|
|
14
|
+
import type { RunContext } from './run-context';
|
|
15
|
+
|
|
16
|
+
function isPromptTaskConfig(
|
|
17
|
+
task: TaskConfig,
|
|
18
|
+
): task is TaskConfig & { readonly prompt: string; readonly command?: undefined } {
|
|
19
|
+
return task.prompt !== undefined && task.command === undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isCommandTaskConfig(
|
|
23
|
+
task: TaskConfig,
|
|
24
|
+
): task is TaskConfig & { readonly command: string; readonly prompt?: undefined } {
|
|
25
|
+
return task.command !== undefined && task.prompt === undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function inputBindingsToPorts(bindings: TaskInputBindings | undefined): PortDef[] | undefined {
|
|
29
|
+
if (!bindings || Object.keys(bindings).length === 0) return undefined;
|
|
30
|
+
return Object.entries(bindings).map(([name, binding]) => ({
|
|
31
|
+
name,
|
|
32
|
+
type: binding.type ?? 'json',
|
|
33
|
+
...(binding.description ? { description: binding.description } : {}),
|
|
34
|
+
...(binding.required !== undefined ? { required: binding.required } : {}),
|
|
35
|
+
...(binding.default !== undefined ? { default: binding.default } : {}),
|
|
36
|
+
...(binding.enum ? { enum: [...binding.enum] } : {}),
|
|
37
|
+
...(binding.from ? { from: binding.from } : {}),
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function outputBindingsToPorts(bindings: TaskOutputBindings | undefined): PortDef[] | undefined {
|
|
42
|
+
if (!bindings || Object.keys(bindings).length === 0) return undefined;
|
|
43
|
+
return Object.entries(bindings).map(([name, binding]) => ({
|
|
44
|
+
name,
|
|
45
|
+
type: binding.type ?? 'json',
|
|
46
|
+
...(binding.description ? { description: binding.description } : {}),
|
|
47
|
+
...(binding.default !== undefined ? { default: binding.default } : {}),
|
|
48
|
+
...(binding.enum ? { enum: [...binding.enum] } : {}),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function taskBindingsAsPorts(task: TaskConfig): TaskPorts | undefined {
|
|
53
|
+
const inputs = inputBindingsToPorts(task.inputs);
|
|
54
|
+
const outputs = outputBindingsToPorts(task.outputs);
|
|
55
|
+
if (!inputs && !outputs) return undefined;
|
|
56
|
+
return {
|
|
57
|
+
...(inputs ? { inputs } : {}),
|
|
58
|
+
...(outputs ? { outputs } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type EffectivePortsResult =
|
|
63
|
+
| {
|
|
64
|
+
readonly kind: 'ready';
|
|
65
|
+
readonly isPromptTask: boolean;
|
|
66
|
+
readonly effectivePorts: TaskPorts | undefined;
|
|
67
|
+
}
|
|
68
|
+
| {
|
|
69
|
+
readonly kind: 'blocked';
|
|
70
|
+
readonly reason: string;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export function inferEffectivePorts(
|
|
74
|
+
ctx: RunContext,
|
|
75
|
+
taskId: string,
|
|
76
|
+
): EffectivePortsResult {
|
|
77
|
+
const node = ctx.dag.nodes.get(taskId)!;
|
|
78
|
+
const task = node.task;
|
|
79
|
+
const isPromptTask = isPromptTaskConfig(task);
|
|
80
|
+
|
|
81
|
+
if (!isPromptTask) {
|
|
82
|
+
return { kind: 'ready', isPromptTask: false, effectivePorts: taskBindingsAsPorts(task) };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const inference = inferPromptPorts({
|
|
86
|
+
upstreams: node.dependsOn.map((upstreamId) => {
|
|
87
|
+
const upstream = ctx.dag.nodes.get(upstreamId);
|
|
88
|
+
const isUpstreamCommand = upstream ? isCommandTaskConfig(upstream.task) : false;
|
|
89
|
+
return {
|
|
90
|
+
taskId: upstreamId,
|
|
91
|
+
outputs: isUpstreamCommand ? outputBindingsToPorts(upstream?.task.outputs) : undefined,
|
|
92
|
+
};
|
|
93
|
+
}),
|
|
94
|
+
downstreams: (ctx.directDownstreams.get(taskId) ?? []).map((downstreamId) => {
|
|
95
|
+
const downstream = ctx.dag.nodes.get(downstreamId);
|
|
96
|
+
const isDownstreamCommand = downstream ? isCommandTaskConfig(downstream.task) : false;
|
|
97
|
+
return {
|
|
98
|
+
taskId: downstreamId,
|
|
99
|
+
inputs: isDownstreamCommand ? inputBindingsToPorts(downstream?.task.inputs) : undefined,
|
|
100
|
+
};
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (inference.inputConflicts.length > 0 || inference.outputConflicts.length > 0) {
|
|
105
|
+
const lines: string[] = [];
|
|
106
|
+
for (const conflict of inference.inputConflicts) lines.push(conflict.reason);
|
|
107
|
+
for (const conflict of inference.outputConflicts) lines.push(conflict.reason);
|
|
108
|
+
return { kind: 'blocked', reason: lines.join('\n') };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { kind: 'ready', isPromptTask: true, effectivePorts: inference.ports };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface ExtractSuccessfulOutputsOptions {
|
|
115
|
+
readonly task: TaskConfig;
|
|
116
|
+
readonly effectivePorts: TaskPorts | undefined;
|
|
117
|
+
readonly result: TaskResult;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface ExtractSuccessfulOutputsResult {
|
|
121
|
+
readonly outputs: Readonly<Record<string, unknown>> | null;
|
|
122
|
+
readonly bindingDiagnostic: string | null;
|
|
123
|
+
readonly portDiagnostic: string | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function extractSuccessfulOutputs(
|
|
127
|
+
options: ExtractSuccessfulOutputsOptions,
|
|
128
|
+
): ExtractSuccessfulOutputsResult {
|
|
129
|
+
const { task, effectivePorts, result } = options;
|
|
130
|
+
let extractedOutputs: Readonly<Record<string, unknown>> | null = null;
|
|
131
|
+
|
|
132
|
+
const bindingExtraction = extractTaskBindingOutputs(
|
|
133
|
+
task.outputs,
|
|
134
|
+
result.stdout,
|
|
135
|
+
result.stderr,
|
|
136
|
+
result.normalizedOutput,
|
|
137
|
+
);
|
|
138
|
+
if (task.outputs && Object.keys(task.outputs).length > 0) {
|
|
139
|
+
extractedOutputs = bindingExtraction.outputs;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if ((!task.outputs || Object.keys(task.outputs).length === 0) && effectivePorts?.outputs?.length) {
|
|
143
|
+
const portExtraction = extractTaskOutputs(
|
|
144
|
+
effectivePorts,
|
|
145
|
+
result.stdout,
|
|
146
|
+
result.normalizedOutput,
|
|
147
|
+
);
|
|
148
|
+
extractedOutputs = portExtraction.outputs;
|
|
149
|
+
return {
|
|
150
|
+
outputs: extractedOutputs,
|
|
151
|
+
bindingDiagnostic: bindingExtraction.diagnostic,
|
|
152
|
+
portDiagnostic: portExtraction.diagnostic,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
outputs: extractedOutputs,
|
|
158
|
+
bindingDiagnostic: bindingExtraction.diagnostic,
|
|
159
|
+
portDiagnostic: null,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { mkdtempSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { pruneLogDirs } from './log-prune';
|
|
6
|
+
|
|
7
|
+
function fixture(): string {
|
|
8
|
+
return mkdtempSync(join(tmpdir(), 'tagma-prune-'));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('pruneLogDirs', () => {
|
|
12
|
+
test('returns silently when logsDir does not exist', async () => {
|
|
13
|
+
const root = fixture();
|
|
14
|
+
try {
|
|
15
|
+
await expect(
|
|
16
|
+
pruneLogDirs(join(root, 'nope'), 5, 'run_live'),
|
|
17
|
+
).resolves.toBeUndefined();
|
|
18
|
+
} finally {
|
|
19
|
+
rmSync(root, { recursive: true, force: true });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('keeps the live run plus (keep-1) most recent historical runs', async () => {
|
|
24
|
+
const root = fixture();
|
|
25
|
+
try {
|
|
26
|
+
for (const id of ['run_001', 'run_002', 'run_003', 'run_004', 'run_005']) {
|
|
27
|
+
mkdirSync(join(root, id));
|
|
28
|
+
}
|
|
29
|
+
await pruneLogDirs(root, 3, 'run_005'); // keep=3 → 1 live + 2 historical
|
|
30
|
+
expect(readdirSync(root).sort()).toEqual(['run_003', 'run_004', 'run_005']);
|
|
31
|
+
} finally {
|
|
32
|
+
rmSync(root, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('never deletes the excluded live runId even if it would be pruned', async () => {
|
|
37
|
+
const root = fixture();
|
|
38
|
+
try {
|
|
39
|
+
for (const id of ['run_001', 'run_002', 'run_003']) mkdirSync(join(root, id));
|
|
40
|
+
await pruneLogDirs(root, 1, 'run_001');
|
|
41
|
+
expect(readdirSync(root).sort()).toEqual(['run_001']);
|
|
42
|
+
} finally {
|
|
43
|
+
rmSync(root, { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('ignores entries that do not look like run dirs', async () => {
|
|
48
|
+
const root = fixture();
|
|
49
|
+
try {
|
|
50
|
+
mkdirSync(join(root, 'run_001'));
|
|
51
|
+
mkdirSync(join(root, 'not_a_run'));
|
|
52
|
+
await pruneLogDirs(root, 1, 'run_001');
|
|
53
|
+
expect(readdirSync(root).sort()).toEqual(['not_a_run', 'run_001']);
|
|
54
|
+
} finally {
|
|
55
|
+
rmSync(root, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readdir, rm } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Delete the oldest subdirectories under `logsDir`, keeping only the
|
|
6
|
+
* most recent `keep` total runs (including the currently-live run
|
|
7
|
+
* identified by `excludeRunId`). Directories are sorted
|
|
8
|
+
* lexicographically; because runIds are prefixed with a base-36
|
|
9
|
+
* timestamp, lexicographic order equals chronological order.
|
|
10
|
+
*
|
|
11
|
+
* `excludeRunId` is always skipped from deletion even if it would
|
|
12
|
+
* otherwise be pruned — this prevents a concurrent run from removing a
|
|
13
|
+
* live log directory that is still in use.
|
|
14
|
+
*
|
|
15
|
+
* The live run occupies one slot out of `keep`, so the maximum number
|
|
16
|
+
* of *historical* dirs to retain is `keep - 1`.
|
|
17
|
+
*/
|
|
18
|
+
export async function pruneLogDirs(
|
|
19
|
+
logsDir: string,
|
|
20
|
+
keep: number,
|
|
21
|
+
excludeRunId: string,
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
let entries: string[];
|
|
24
|
+
try {
|
|
25
|
+
entries = await readdir(logsDir);
|
|
26
|
+
} catch {
|
|
27
|
+
return; // logsDir doesn't exist yet
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const runDirs = entries
|
|
31
|
+
.filter((e) => e.startsWith('run_') && e !== excludeRunId)
|
|
32
|
+
.sort();
|
|
33
|
+
const historyKeep = Math.max(0, keep - 1);
|
|
34
|
+
const toDelete = runDirs.slice(0, Math.max(0, runDirs.length - historyKeep));
|
|
35
|
+
|
|
36
|
+
await Promise.all(
|
|
37
|
+
toDelete.map((dir) =>
|
|
38
|
+
rm(resolve(logsDir, dir), { recursive: true, force: true }).catch(() => {
|
|
39
|
+
// Ignore deletion errors — stale dirs are better than a crash
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { preflight } from './preflight';
|
|
3
|
+
import { buildDag } from '../dag';
|
|
4
|
+
import { PluginRegistry } from '../registry';
|
|
5
|
+
import { bootstrapBuiltins } from '../bootstrap';
|
|
6
|
+
import type { PipelineConfig } from '../types';
|
|
7
|
+
|
|
8
|
+
function emptyConfig(overrides: Partial<PipelineConfig> = {}): PipelineConfig {
|
|
9
|
+
return {
|
|
10
|
+
name: 'p',
|
|
11
|
+
tracks: [{ id: 't', name: 'T', tasks: [] }],
|
|
12
|
+
...overrides,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('preflight', () => {
|
|
17
|
+
test('throws when a referenced driver is not registered', () => {
|
|
18
|
+
const reg = new PluginRegistry();
|
|
19
|
+
const cfg = emptyConfig({
|
|
20
|
+
tracks: [
|
|
21
|
+
{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
expect(() => preflight(cfg, buildDag(cfg), reg)).toThrow(
|
|
25
|
+
/driver "opencode" not registered/,
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('passes when all referenced plugins are registered', () => {
|
|
30
|
+
const reg = new PluginRegistry();
|
|
31
|
+
bootstrapBuiltins(reg);
|
|
32
|
+
const cfg = emptyConfig({
|
|
33
|
+
tracks: [
|
|
34
|
+
{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', prompt: 'hi' }] },
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
expect(() => preflight(cfg, buildDag(cfg), reg)).not.toThrow();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('skips driver check for command-only tasks', () => {
|
|
41
|
+
const reg = new PluginRegistry(); // no drivers registered
|
|
42
|
+
const cfg = emptyConfig({
|
|
43
|
+
tracks: [
|
|
44
|
+
{ id: 't', name: 'T', tasks: [{ id: 'a', name: 'A', command: 'echo hi' }] },
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
expect(() => preflight(cfg, buildDag(cfg), reg)).not.toThrow();
|
|
48
|
+
});
|
|
49
|
+
});
|