@tagma/sdk 0.5.2 → 0.6.0

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Tagma
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tagma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagma/sdk",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "Local AI task orchestration engine — core SDK for tagma pipelines",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -42,7 +42,7 @@
42
42
  "release:publish": "bun scripts/release.ts --publish"
43
43
  },
44
44
  "dependencies": {
45
- "@tagma/types": "0.3.0",
45
+ "@tagma/types": "0.4.0",
46
46
  "js-yaml": "^4.1.0",
47
47
  "chokidar": "^4.0.0"
48
48
  },
@@ -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
+ }