@tagma/sdk 0.4.14 → 0.4.15
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 +569 -569
- package/dist/dag.d.ts.map +1 -1
- package/dist/dag.js +22 -56
- package/dist/dag.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +63 -37
- package/dist/engine.js.map +1 -1
- package/dist/middlewares/static-context.d.ts.map +1 -1
- package/dist/middlewares/static-context.js +7 -3
- package/dist/middlewares/static-context.js.map +1 -1
- package/dist/prompt-doc.d.ts +36 -0
- package/dist/prompt-doc.d.ts.map +1 -0
- package/dist/prompt-doc.js +44 -0
- package/dist/prompt-doc.js.map +1 -0
- package/dist/sdk.d.ts +3 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +4 -0
- package/dist/sdk.js.map +1 -1
- package/dist/task-ref.d.ts +55 -0
- package/dist/task-ref.d.ts.map +1 -0
- package/dist/task-ref.js +101 -0
- package/dist/task-ref.js.map +1 -0
- package/dist/templates.d.ts +20 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +93 -0
- package/dist/templates.js.map +1 -0
- package/dist/validate-raw.d.ts.map +1 -1
- package/dist/validate-raw.js +27 -53
- package/dist/validate-raw.js.map +1 -1
- package/package.json +2 -2
- package/scripts/preinstall.js +31 -31
- package/src/adapters/stdin-approval.ts +106 -106
- package/src/adapters/websocket-approval.ts +224 -224
- package/src/approval.ts +131 -131
- package/src/bootstrap.ts +37 -37
- package/src/completions/exit-code.ts +34 -34
- package/src/completions/file-exists.ts +66 -66
- package/src/completions/output-check.ts +86 -86
- package/src/config-ops.ts +307 -307
- package/src/dag.ts +24 -54
- package/src/drivers/claude-code.ts +250 -250
- package/src/engine.ts +1137 -1098
- package/src/hooks.ts +187 -187
- package/src/logger.ts +182 -182
- package/src/middlewares/static-context.ts +49 -45
- package/src/pipeline-runner.ts +156 -156
- package/src/prompt-doc.ts +49 -0
- package/src/registry.ts +242 -242
- package/src/runner.ts +395 -395
- package/src/schema.test.ts +101 -101
- package/src/schema.ts +338 -338
- package/src/sdk.ts +111 -92
- package/src/task-ref.ts +120 -0
- package/src/triggers/file.ts +164 -164
- package/src/triggers/manual.ts +86 -86
- package/src/types.ts +18 -18
- package/src/utils.ts +203 -203
- package/src/validate-raw.ts +412 -442
package/scripts/preinstall.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
// Preinstall guard — refuses installation under npm / yarn / pnpm.
|
|
2
|
-
// @tagma/sdk is published as pre-built JS (dist/) but historically shipped
|
|
3
|
-
// TypeScript source. The guard remains for external consumers who might try
|
|
4
|
-
// to install via non-Bun managers that can't resolve the dist/ entry points.
|
|
5
|
-
//
|
|
6
|
-
// In the monorepo, Bun workspace links this package directly, so this script
|
|
7
|
-
// is only hit during `npm publish` or external installs.
|
|
8
|
-
|
|
9
|
-
const ua = process.env.npm_config_user_agent || '';
|
|
10
|
-
if (process.versions.bun || ua.startsWith('bun/') || ua.startsWith('bun ')) {
|
|
11
|
-
process.exit(0);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const red = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
15
|
-
const bold = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
16
|
-
const cyan = (s) => `\x1b[36m${s}\x1b[0m`;
|
|
17
|
-
|
|
18
|
-
process.stderr.write(
|
|
19
|
-
[
|
|
20
|
-
'',
|
|
21
|
-
red(bold(' @tagma/sdk requires Bun (>= 1.3).')),
|
|
22
|
-
'',
|
|
23
|
-
' Install with:',
|
|
24
|
-
cyan(' bun add @tagma/sdk'),
|
|
25
|
-
'',
|
|
26
|
-
' Get Bun: https://bun.sh',
|
|
27
|
-
'',
|
|
28
|
-
].join('\n') + '\n',
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
process.exit(1);
|
|
1
|
+
// Preinstall guard — refuses installation under npm / yarn / pnpm.
|
|
2
|
+
// @tagma/sdk is published as pre-built JS (dist/) but historically shipped
|
|
3
|
+
// TypeScript source. The guard remains for external consumers who might try
|
|
4
|
+
// to install via non-Bun managers that can't resolve the dist/ entry points.
|
|
5
|
+
//
|
|
6
|
+
// In the monorepo, Bun workspace links this package directly, so this script
|
|
7
|
+
// is only hit during `npm publish` or external installs.
|
|
8
|
+
|
|
9
|
+
const ua = process.env.npm_config_user_agent || '';
|
|
10
|
+
if (process.versions.bun || ua.startsWith('bun/') || ua.startsWith('bun ')) {
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const red = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
15
|
+
const bold = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
16
|
+
const cyan = (s) => `\x1b[36m${s}\x1b[0m`;
|
|
17
|
+
|
|
18
|
+
process.stderr.write(
|
|
19
|
+
[
|
|
20
|
+
'',
|
|
21
|
+
red(bold(' @tagma/sdk requires Bun (>= 1.3).')),
|
|
22
|
+
'',
|
|
23
|
+
' Install with:',
|
|
24
|
+
cyan(' bun add @tagma/sdk'),
|
|
25
|
+
'',
|
|
26
|
+
' Get Bun: https://bun.sh',
|
|
27
|
+
'',
|
|
28
|
+
].join('\n') + '\n',
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
process.exit(1);
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import * as readline from 'readline';
|
|
2
|
-
import type { ApprovalGateway, ApprovalRequest } from '../approval';
|
|
3
|
-
|
|
4
|
-
// ═══ CLI Stdin Adapter ═══
|
|
5
|
-
//
|
|
6
|
-
// Subscribes to the gateway's 'requested' events, prompts the user on stdout,
|
|
7
|
-
// reads a line from stdin, and calls gateway.resolve(). Handles at most one
|
|
8
|
-
// prompt at a time — additional requests queue up.
|
|
9
|
-
|
|
10
|
-
export interface StdinApprovalAdapter {
|
|
11
|
-
readonly detach: () => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function attachStdinApprovalAdapter(gateway: ApprovalGateway): StdinApprovalAdapter {
|
|
15
|
-
const queue: ApprovalRequest[] = [];
|
|
16
|
-
let processing = false;
|
|
17
|
-
let rl: readline.Interface | null = null;
|
|
18
|
-
|
|
19
|
-
function ensureReadline(): readline.Interface {
|
|
20
|
-
if (!rl) {
|
|
21
|
-
rl = readline.createInterface({ input: process.stdin, terminal: false });
|
|
22
|
-
}
|
|
23
|
-
return rl;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function readOneLine(): Promise<string> {
|
|
27
|
-
return new Promise((resolvePromise) => {
|
|
28
|
-
const reader = ensureReadline();
|
|
29
|
-
const handler = (line: string): void => {
|
|
30
|
-
reader.off('line', handler);
|
|
31
|
-
resolvePromise(line);
|
|
32
|
-
};
|
|
33
|
-
reader.on('line', handler);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function processNext(): Promise<void> {
|
|
38
|
-
if (processing) return;
|
|
39
|
-
processing = true;
|
|
40
|
-
try {
|
|
41
|
-
while (queue.length > 0) {
|
|
42
|
-
const req = queue.shift()!;
|
|
43
|
-
// If the request was already resolved by another path while queued, skip it.
|
|
44
|
-
if (!gateway.pending().some((p) => p.id === req.id)) continue;
|
|
45
|
-
|
|
46
|
-
process.stdout.write(
|
|
47
|
-
`\n[APPROVAL REQUIRED] ${req.message}\n` +
|
|
48
|
-
` id: ${req.id}\n` +
|
|
49
|
-
` task: ${req.taskId}${req.trackId ? ` (track: ${req.trackId})` : ''}\n` +
|
|
50
|
-
` approve / reject > `,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const input = (await readOneLine()).trim().toLowerCase();
|
|
54
|
-
|
|
55
|
-
const approveAliases = new Set(['approve', 'yes', 'y', 'ok', 'true', '1']);
|
|
56
|
-
const rejectAliases = new Set(['reject', 'no', 'n', 'deny', 'false', '0']);
|
|
57
|
-
|
|
58
|
-
if (approveAliases.has(input)) {
|
|
59
|
-
gateway.resolve(req.id, { outcome: 'approved', actor: 'cli' });
|
|
60
|
-
} else if (rejectAliases.has(input)) {
|
|
61
|
-
gateway.resolve(req.id, {
|
|
62
|
-
outcome: 'rejected',
|
|
63
|
-
actor: 'cli',
|
|
64
|
-
reason: 'user rejected via CLI',
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
process.stdout.write(` unrecognized input "${input}" — treating as rejection\n`);
|
|
68
|
-
gateway.resolve(req.id, {
|
|
69
|
-
outcome: 'rejected',
|
|
70
|
-
actor: 'cli',
|
|
71
|
-
reason: `unrecognized CLI input: ${input}`,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} finally {
|
|
76
|
-
processing = false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const unsubscribe = gateway.subscribe((event) => {
|
|
81
|
-
switch (event.type) {
|
|
82
|
-
case 'requested':
|
|
83
|
-
queue.push(event.request);
|
|
84
|
-
void processNext();
|
|
85
|
-
return;
|
|
86
|
-
case 'resolved':
|
|
87
|
-
case 'expired':
|
|
88
|
-
case 'aborted': {
|
|
89
|
-
// Drop from queue if it's still waiting its turn.
|
|
90
|
-
const idx = queue.findIndex((r) => r.id === event.request.id);
|
|
91
|
-
if (idx >= 0) queue.splice(idx, 1);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
detach: () => {
|
|
99
|
-
unsubscribe();
|
|
100
|
-
if (rl) {
|
|
101
|
-
rl.close();
|
|
102
|
-
rl = null;
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
1
|
+
import * as readline from 'readline';
|
|
2
|
+
import type { ApprovalGateway, ApprovalRequest } from '../approval';
|
|
3
|
+
|
|
4
|
+
// ═══ CLI Stdin Adapter ═══
|
|
5
|
+
//
|
|
6
|
+
// Subscribes to the gateway's 'requested' events, prompts the user on stdout,
|
|
7
|
+
// reads a line from stdin, and calls gateway.resolve(). Handles at most one
|
|
8
|
+
// prompt at a time — additional requests queue up.
|
|
9
|
+
|
|
10
|
+
export interface StdinApprovalAdapter {
|
|
11
|
+
readonly detach: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function attachStdinApprovalAdapter(gateway: ApprovalGateway): StdinApprovalAdapter {
|
|
15
|
+
const queue: ApprovalRequest[] = [];
|
|
16
|
+
let processing = false;
|
|
17
|
+
let rl: readline.Interface | null = null;
|
|
18
|
+
|
|
19
|
+
function ensureReadline(): readline.Interface {
|
|
20
|
+
if (!rl) {
|
|
21
|
+
rl = readline.createInterface({ input: process.stdin, terminal: false });
|
|
22
|
+
}
|
|
23
|
+
return rl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readOneLine(): Promise<string> {
|
|
27
|
+
return new Promise((resolvePromise) => {
|
|
28
|
+
const reader = ensureReadline();
|
|
29
|
+
const handler = (line: string): void => {
|
|
30
|
+
reader.off('line', handler);
|
|
31
|
+
resolvePromise(line);
|
|
32
|
+
};
|
|
33
|
+
reader.on('line', handler);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function processNext(): Promise<void> {
|
|
38
|
+
if (processing) return;
|
|
39
|
+
processing = true;
|
|
40
|
+
try {
|
|
41
|
+
while (queue.length > 0) {
|
|
42
|
+
const req = queue.shift()!;
|
|
43
|
+
// If the request was already resolved by another path while queued, skip it.
|
|
44
|
+
if (!gateway.pending().some((p) => p.id === req.id)) continue;
|
|
45
|
+
|
|
46
|
+
process.stdout.write(
|
|
47
|
+
`\n[APPROVAL REQUIRED] ${req.message}\n` +
|
|
48
|
+
` id: ${req.id}\n` +
|
|
49
|
+
` task: ${req.taskId}${req.trackId ? ` (track: ${req.trackId})` : ''}\n` +
|
|
50
|
+
` approve / reject > `,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const input = (await readOneLine()).trim().toLowerCase();
|
|
54
|
+
|
|
55
|
+
const approveAliases = new Set(['approve', 'yes', 'y', 'ok', 'true', '1']);
|
|
56
|
+
const rejectAliases = new Set(['reject', 'no', 'n', 'deny', 'false', '0']);
|
|
57
|
+
|
|
58
|
+
if (approveAliases.has(input)) {
|
|
59
|
+
gateway.resolve(req.id, { outcome: 'approved', actor: 'cli' });
|
|
60
|
+
} else if (rejectAliases.has(input)) {
|
|
61
|
+
gateway.resolve(req.id, {
|
|
62
|
+
outcome: 'rejected',
|
|
63
|
+
actor: 'cli',
|
|
64
|
+
reason: 'user rejected via CLI',
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
process.stdout.write(` unrecognized input "${input}" — treating as rejection\n`);
|
|
68
|
+
gateway.resolve(req.id, {
|
|
69
|
+
outcome: 'rejected',
|
|
70
|
+
actor: 'cli',
|
|
71
|
+
reason: `unrecognized CLI input: ${input}`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} finally {
|
|
76
|
+
processing = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const unsubscribe = gateway.subscribe((event) => {
|
|
81
|
+
switch (event.type) {
|
|
82
|
+
case 'requested':
|
|
83
|
+
queue.push(event.request);
|
|
84
|
+
void processNext();
|
|
85
|
+
return;
|
|
86
|
+
case 'resolved':
|
|
87
|
+
case 'expired':
|
|
88
|
+
case 'aborted': {
|
|
89
|
+
// Drop from queue if it's still waiting its turn.
|
|
90
|
+
const idx = queue.findIndex((r) => r.id === event.request.id);
|
|
91
|
+
if (idx >= 0) queue.splice(idx, 1);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
detach: () => {
|
|
99
|
+
unsubscribe();
|
|
100
|
+
if (rl) {
|
|
101
|
+
rl.close();
|
|
102
|
+
rl = null;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|