@tagma/sdk 0.7.3 → 0.7.4
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 +26 -5
- package/dist/adapters/stdin-approval.d.ts +1 -5
- package/dist/adapters/stdin-approval.d.ts.map +1 -1
- package/dist/adapters/stdin-approval.js +1 -89
- package/dist/adapters/stdin-approval.js.map +1 -1
- package/dist/adapters/websocket-approval.d.ts +1 -27
- package/dist/adapters/websocket-approval.d.ts.map +1 -1
- package/dist/adapters/websocket-approval.js +1 -146
- package/dist/adapters/websocket-approval.js.map +1 -1
- package/dist/approval.d.ts +2 -12
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +1 -90
- package/dist/approval.js.map +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/core/task-executor.d.ts.map +1 -1
- package/dist/core/task-executor.js +13 -4
- package/dist/core/task-executor.js.map +1 -1
- package/dist/engine.d.ts +5 -56
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +7 -297
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +2 -60
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +1 -153
- package/dist/logger.js.map +1 -1
- package/dist/plugins.d.ts +2 -2
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +1 -1
- package/dist/plugins.js.map +1 -1
- package/dist/registry.d.ts +2 -66
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +1 -292
- package/dist/registry.js.map +1 -1
- package/dist/runner.d.ts +1 -35
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -610
- package/dist/runner.js.map +1 -1
- package/dist/runtime/adapters/stdin-approval.d.ts +2 -0
- package/dist/runtime/adapters/stdin-approval.d.ts.map +1 -0
- package/dist/runtime/adapters/stdin-approval.js +2 -0
- package/dist/runtime/adapters/stdin-approval.js.map +1 -0
- package/dist/runtime/adapters/websocket-approval.d.ts +2 -0
- package/dist/runtime/adapters/websocket-approval.d.ts.map +1 -0
- package/dist/runtime/adapters/websocket-approval.js +2 -0
- package/dist/runtime/adapters/websocket-approval.js.map +1 -0
- package/dist/runtime/bun-process-runner.d.ts +2 -0
- package/dist/runtime/bun-process-runner.d.ts.map +1 -0
- package/dist/runtime/bun-process-runner.js +2 -0
- package/dist/runtime/bun-process-runner.js.map +1 -0
- package/dist/runtime.d.ts +2 -8
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -7
- package/dist/runtime.js.map +1 -1
- package/dist/tagma.d.ts +3 -4
- package/dist/tagma.d.ts.map +1 -1
- package/dist/tagma.js +2 -3
- package/dist/tagma.js.map +1 -1
- package/dist/triggers/file.d.ts.map +1 -1
- package/dist/triggers/file.js +74 -107
- package/dist/triggers/file.js.map +1 -1
- package/package.json +15 -4
- package/src/adapters/stdin-approval.ts +1 -106
- package/src/adapters/websocket-approval.ts +1 -224
- package/src/approval.ts +5 -127
- package/src/bootstrap.ts +1 -1
- package/src/core/run-context.test.ts +35 -0
- package/src/core/task-executor.ts +13 -4
- package/src/engine-ports-mixed.test.ts +70 -44
- package/src/engine-ports.test.ts +77 -33
- package/src/engine.ts +18 -444
- package/src/index.ts +4 -6
- package/src/logger.ts +2 -182
- package/src/package-split.test.ts +15 -0
- package/src/pipeline-runner.test.ts +65 -12
- package/src/plugin-registry.test.ts +69 -3
- package/src/plugins.ts +2 -2
- package/src/registry.ts +7 -353
- package/src/runner.ts +1 -666
- package/src/runtime/adapters/stdin-approval.ts +1 -0
- package/src/runtime/adapters/websocket-approval.ts +1 -0
- package/src/runtime/bun-process-runner.ts +1 -0
- package/src/runtime-adapters.test.ts +10 -0
- package/src/runtime.ts +12 -20
- package/src/tagma.test.ts +162 -0
- package/src/tagma.ts +9 -4
- package/src/triggers/file.test.ts +79 -0
- package/src/triggers/file.ts +85 -118
package/dist/logger.js
CHANGED
|
@@ -1,154 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { mkdirSync, writeFileSync, openSync, writeSync, closeSync } from 'node:fs';
|
|
3
|
-
const TASK_PREFIX_RE = /\[task:([^\]]+)\]/;
|
|
4
|
-
function taskIdFromPrefix(prefix) {
|
|
5
|
-
const m = TASK_PREFIX_RE.exec(prefix);
|
|
6
|
-
return m ? m[1] : null;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Dual-channel logger.
|
|
10
|
-
*
|
|
11
|
-
* - `info/warn/error` → console AND file (brief, user-visible events)
|
|
12
|
-
* - `debug` → file ONLY (verbose diagnostics)
|
|
13
|
-
* - `section` → file ONLY (visual separators)
|
|
14
|
-
* - `quiet` → file ONLY (bulk payload like full stdout dumps)
|
|
15
|
-
*
|
|
16
|
-
* Log file path: <workDir>/.tagma/logs/<runId>/pipeline.log (one file per pipeline run,
|
|
17
|
-
* truncated on construction). Every line is also forwarded to the optional
|
|
18
|
-
* `onLine` callback as a structured `LogRecord`, so callers that want to
|
|
19
|
-
* stream the run process over IPC/SSE don't need to tail the file.
|
|
20
|
-
*/
|
|
21
|
-
export class Logger {
|
|
22
|
-
filePath;
|
|
23
|
-
runDir;
|
|
24
|
-
onLine;
|
|
25
|
-
/** Persistent file descriptor for append writes (avoids open/close per line). */
|
|
26
|
-
fd;
|
|
27
|
-
constructor(workDir, runId, onLine) {
|
|
28
|
-
this.runDir = resolve(workDir, '.tagma', 'logs', runId);
|
|
29
|
-
this.filePath = resolve(this.runDir, 'pipeline.log');
|
|
30
|
-
this.onLine = onLine ?? null;
|
|
31
|
-
mkdirSync(dirname(this.filePath), { recursive: true });
|
|
32
|
-
const header = `# Pipeline run ${runId} @ ${new Date().toISOString()}\n` +
|
|
33
|
-
`# Host: ${process.platform} ${process.arch} Bun: ${process.versions.bun ?? 'n/a'}\n` +
|
|
34
|
-
`# Work dir: ${workDir}\n\n`;
|
|
35
|
-
writeFileSync(this.filePath, header);
|
|
36
|
-
// Open once for all subsequent appends (O_APPEND is implied by 'a' flag)
|
|
37
|
-
this.fd = openSync(this.filePath, 'a');
|
|
38
|
-
}
|
|
39
|
-
info(prefix, message) {
|
|
40
|
-
const ts = timestamp();
|
|
41
|
-
const line = `${ts} ${prefix} ${message}`;
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.log(line);
|
|
44
|
-
this.emit('info', ts, line, taskIdFromPrefix(prefix));
|
|
45
|
-
this.append(line);
|
|
46
|
-
}
|
|
47
|
-
warn(prefix, message) {
|
|
48
|
-
const ts = timestamp();
|
|
49
|
-
const line = `${ts} ${prefix} WARN: ${message}`;
|
|
50
|
-
console.warn(line);
|
|
51
|
-
this.emit('warn', ts, line, taskIdFromPrefix(prefix));
|
|
52
|
-
this.append(line);
|
|
53
|
-
}
|
|
54
|
-
error(prefix, message) {
|
|
55
|
-
const ts = timestamp();
|
|
56
|
-
const line = `${ts} ${prefix} ERROR: ${message}`;
|
|
57
|
-
console.error(line);
|
|
58
|
-
this.emit('error', ts, line, taskIdFromPrefix(prefix));
|
|
59
|
-
this.append(line);
|
|
60
|
-
}
|
|
61
|
-
/** File-only diagnostic log line. */
|
|
62
|
-
debug(prefix, message) {
|
|
63
|
-
const ts = timestamp();
|
|
64
|
-
const line = `${ts} ${prefix} DEBUG: ${message}`;
|
|
65
|
-
this.emit('debug', ts, line, taskIdFromPrefix(prefix));
|
|
66
|
-
this.append(line);
|
|
67
|
-
}
|
|
68
|
-
/** File-only visual separator with title. */
|
|
69
|
-
section(title, taskId) {
|
|
70
|
-
const ts = timestamp();
|
|
71
|
-
const text = `\n━━━ ${title} ━━━`;
|
|
72
|
-
this.emit('section', ts, text, taskId ?? null);
|
|
73
|
-
this.append(text);
|
|
74
|
-
}
|
|
75
|
-
/** File-only bulk payload (e.g. full stdout / stderr dumps). */
|
|
76
|
-
quiet(message, taskId) {
|
|
77
|
-
const ts = timestamp();
|
|
78
|
-
this.emit('quiet', ts, message, taskId ?? null);
|
|
79
|
-
this.append(message);
|
|
80
|
-
}
|
|
81
|
-
append(line) {
|
|
82
|
-
if (this.fd === null)
|
|
83
|
-
return;
|
|
84
|
-
try {
|
|
85
|
-
const data = line.endsWith('\n') ? line : line + '\n';
|
|
86
|
-
writeSync(this.fd, data);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// Swallow log write failures; engine correctness shouldn't depend on logging.
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/** Close the persistent file handle. Called by the engine at run completion. */
|
|
93
|
-
close() {
|
|
94
|
-
if (this.fd !== null) {
|
|
95
|
-
try {
|
|
96
|
-
closeSync(this.fd);
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
/* already closed */
|
|
100
|
-
}
|
|
101
|
-
this.fd = null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
emit(level, ts, text, taskId) {
|
|
105
|
-
if (!this.onLine)
|
|
106
|
-
return;
|
|
107
|
-
try {
|
|
108
|
-
this.onLine({ level, taskId, timestamp: ts, text });
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// Never let a listener error derail the pipeline.
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
get path() {
|
|
115
|
-
return this.filePath;
|
|
116
|
-
}
|
|
117
|
-
/** Directory that holds all artifacts for this run (pipeline.log, *.stderr, etc.). */
|
|
118
|
-
get dir() {
|
|
119
|
-
return this.runDir;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function timestamp() {
|
|
123
|
-
const d = new Date();
|
|
124
|
-
const hh = String(d.getHours()).padStart(2, '0');
|
|
125
|
-
const mm = String(d.getMinutes()).padStart(2, '0');
|
|
126
|
-
const ss = String(d.getSeconds()).padStart(2, '0');
|
|
127
|
-
const ms = String(d.getMilliseconds()).padStart(3, '0');
|
|
128
|
-
return `${hh}:${mm}:${ss}.${ms}`;
|
|
129
|
-
}
|
|
130
|
-
/** Return the last `n` non-empty lines of `text`, joined with newlines. */
|
|
131
|
-
export function tailLines(text, n) {
|
|
132
|
-
if (!text)
|
|
133
|
-
return '';
|
|
134
|
-
const lines = text.split(/\r?\n/).filter((l) => l.length > 0);
|
|
135
|
-
return lines.slice(-n).join('\n');
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Truncate a blob to at most `maxBytes` UTF-8 bytes for log embedding,
|
|
139
|
-
* appending a marker when truncation occurred.
|
|
140
|
-
* Uses TextEncoder so CJK and emoji (multi-byte) characters are counted correctly.
|
|
141
|
-
*/
|
|
142
|
-
export function clip(text, maxBytes = 16 * 1024) {
|
|
143
|
-
if (!text)
|
|
144
|
-
return '';
|
|
145
|
-
const encoder = new TextEncoder();
|
|
146
|
-
const bytes = encoder.encode(text);
|
|
147
|
-
if (bytes.length <= maxBytes)
|
|
148
|
-
return text;
|
|
149
|
-
const omittedBytes = bytes.length - maxBytes;
|
|
150
|
-
// TextDecoder handles partial code-point boundaries safely (replacement char insertion)
|
|
151
|
-
const truncated = new TextDecoder().decode(bytes.slice(0, maxBytes));
|
|
152
|
-
return truncated + `\n…[truncated ${omittedBytes} bytes]`;
|
|
153
|
-
}
|
|
1
|
+
export { clip, Logger, tailLines } from '@tagma/core';
|
|
154
2
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { bootstrapBuiltins } from './bootstrap';
|
|
2
|
-
export { PluginRegistry, isValidPluginName, PLUGIN_NAME_RE, readPluginManifest, } from '
|
|
3
|
-
export type { RegisteredCapability, RegisterResult } from '
|
|
2
|
+
export { PluginRegistry, isValidPluginName, PLUGIN_NAME_RE, readPluginManifest, } from '@tagma/core';
|
|
3
|
+
export type { RegisteredCapability, RegisterResult } from '@tagma/core';
|
|
4
4
|
export type { CapabilityHandler, PluginCategory, PluginCapabilities, PluginModule, PluginManifest, PluginSetupContext, TagmaPlugin, DriverPlugin, TriggerPlugin, CompletionPlugin, MiddlewarePlugin, } from './types';
|
|
5
5
|
//# sourceMappingURL=plugins.d.ts.map
|
package/dist/plugins.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GACnB,MAAM,
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
|
package/dist/plugins.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { bootstrapBuiltins } from './bootstrap';
|
|
2
|
-
export { PluginRegistry, isValidPluginName, PLUGIN_NAME_RE, readPluginManifest, } from '
|
|
2
|
+
export { PluginRegistry, isValidPluginName, PLUGIN_NAME_RE, readPluginManifest, } from '@tagma/core';
|
|
3
3
|
//# sourceMappingURL=plugins.js.map
|
package/dist/plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GACnB,MAAM,
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,67 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
export interface RegisteredCapability {
|
|
4
|
-
readonly category: PluginCategory;
|
|
5
|
-
readonly type: string;
|
|
6
|
-
readonly result: RegisterResult;
|
|
7
|
-
}
|
|
8
|
-
export type RegisterResult = 'registered' | 'replaced' | 'unchanged';
|
|
9
|
-
export declare const PLUGIN_NAME_RE: RegExp;
|
|
10
|
-
export declare function isValidPluginName(name: unknown): name is string;
|
|
11
|
-
/**
|
|
12
|
-
* Parse and validate the `tagmaPlugin` field of a `package.json` blob.
|
|
13
|
-
*
|
|
14
|
-
* Returns the strongly-typed manifest if the field is present and
|
|
15
|
-
* well-formed (`category` is one of the four known categories and `type`
|
|
16
|
-
* is a non-empty string). Returns `null` if the field is absent —that
|
|
17
|
-
* is the host's signal that the package is a library, not a plugin.
|
|
18
|
-
*
|
|
19
|
-
* Throws if the field is present but malformed: that's a packaging bug
|
|
20
|
-
* the plugin author should hear about loudly, not a silent skip.
|
|
21
|
-
*
|
|
22
|
-
* Hosts use this during auto-discovery to decide whether to load a
|
|
23
|
-
* package as a plugin without having to dynamically `import()` it.
|
|
24
|
-
*/
|
|
25
|
-
export declare function readPluginManifest(pkgJson: unknown): PluginManifest | null;
|
|
26
|
-
/**
|
|
27
|
-
* Instance-scoped plugin registry. Each workspace in a multi-tenant sidecar
|
|
28
|
-
* owns its own PluginRegistry, so installing/uninstalling a driver in one
|
|
29
|
-
* workspace cannot clobber another.
|
|
30
|
-
*/
|
|
31
|
-
export declare class PluginRegistry {
|
|
32
|
-
private readonly registries;
|
|
33
|
-
/**
|
|
34
|
-
* Register a plugin under (category, type). Returns:
|
|
35
|
-
* - 'registered' on first registration
|
|
36
|
-
* - 'replaced' when an existing entry was overwritten with a different handler
|
|
37
|
-
* - 'unchanged' when the same handler instance was already present
|
|
38
|
-
*
|
|
39
|
-
* Throws if `category` is unknown, `type` is empty, or `handler` violates
|
|
40
|
-
* the minimum interface contract for the category.
|
|
41
|
-
*/
|
|
42
|
-
registerPlugin<T extends PluginType>(category: PluginCategory, type: string, handler: T): RegisterResult;
|
|
43
|
-
registerTagmaPlugin(plugin: TagmaPlugin): RegisteredCapability[];
|
|
44
|
-
/**
|
|
45
|
-
* Remove a plugin from the in-process registry. Returns true if a plugin
|
|
46
|
-
* was actually removed. Note: ESM module caching is not affected, so
|
|
47
|
-
* re-importing the same file after unregister will yield the cached module — * callers wanting a fresh load must restart the host process.
|
|
48
|
-
*/
|
|
49
|
-
unregisterPlugin(category: PluginCategory, type: string): boolean;
|
|
50
|
-
getHandler<T extends PluginType>(category: PluginCategory, type: string): T;
|
|
51
|
-
hasHandler(category: PluginCategory, type: string): boolean;
|
|
52
|
-
listRegistered(category: PluginCategory): string[];
|
|
53
|
-
/**
|
|
54
|
-
* Load and register a list of plugin packages into this registry.
|
|
55
|
-
*
|
|
56
|
-
* @param pluginNames - Validated npm package names to load.
|
|
57
|
-
* @param resolveFrom - Optional absolute path to resolve plugins from (e.g.
|
|
58
|
-
* the workspace's working directory). When omitted, the default ESM
|
|
59
|
-
* resolution uses the SDK's own `node_modules`, which will fail for
|
|
60
|
-
* plugins installed only in the user's workspace. CLI callers should
|
|
61
|
-
* pass `process.cwd()` or the workspace root so that workspace-local
|
|
62
|
-
* plugins resolve correctly.
|
|
63
|
-
*/
|
|
64
|
-
loadPlugins(pluginNames: readonly string[], resolveFrom?: string): Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
export {};
|
|
1
|
+
export { isValidPluginName, PluginRegistry, PLUGIN_NAME_RE, readPluginManifest, } from '@tagma/core';
|
|
2
|
+
export type { RegisteredCapability, RegisterResult } from '@tagma/core';
|
|
67
3
|
//# sourceMappingURL=registry.d.ts.map
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/registry.js
CHANGED
|
@@ -1,293 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
const CAPABILITY_CATEGORIES = [
|
|
4
|
-
'drivers',
|
|
5
|
-
'triggers',
|
|
6
|
-
'completions',
|
|
7
|
-
'middlewares',
|
|
8
|
-
];
|
|
9
|
-
const VALID_CATEGORIES = new Set(CAPABILITY_CATEGORIES);
|
|
10
|
-
const PLUGIN_TYPE_RE = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
11
|
-
function singularCategory(category) {
|
|
12
|
-
switch (category) {
|
|
13
|
-
case 'drivers':
|
|
14
|
-
return 'driver';
|
|
15
|
-
case 'triggers':
|
|
16
|
-
return 'trigger';
|
|
17
|
-
case 'completions':
|
|
18
|
-
return 'completion';
|
|
19
|
-
case 'middlewares':
|
|
20
|
-
return 'middleware';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Minimal contract enforcement so a malformed plugin fails fast at
|
|
25
|
-
* registration time rather than crashing the engine mid-run.
|
|
26
|
-
*
|
|
27
|
-
* For drivers we materialize `capabilities` and assert each field is a
|
|
28
|
-
* boolean —otherwise a plugin author can write
|
|
29
|
-
* get capabilities() { throw new Error('boom') }
|
|
30
|
-
* and pass the basic typeof check, then crash preflight when the engine
|
|
31
|
-
* touches `driver.capabilities.sessionResume`. (R8)
|
|
32
|
-
*/
|
|
33
|
-
function validateContract(category, handler) {
|
|
34
|
-
if (!handler || typeof handler !== 'object') {
|
|
35
|
-
throw new Error(`Plugin handler for category "${category}" must be an object`);
|
|
36
|
-
}
|
|
37
|
-
const h = handler;
|
|
38
|
-
if (typeof h.name !== 'string' || h.name.length === 0) {
|
|
39
|
-
throw new Error(`Plugin handler for category "${category}" must declare a non-empty "name"`);
|
|
40
|
-
}
|
|
41
|
-
switch (category) {
|
|
42
|
-
case 'drivers': {
|
|
43
|
-
if (typeof h.buildCommand !== 'function') {
|
|
44
|
-
throw new Error(`drivers plugin "${h.name}" must export buildCommand()`);
|
|
45
|
-
}
|
|
46
|
-
// Materialize capabilities —this triggers any throwing getter NOW
|
|
47
|
-
// instead of during preflight.
|
|
48
|
-
let caps;
|
|
49
|
-
try {
|
|
50
|
-
caps = h.capabilities;
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
throw new Error(`drivers plugin "${h.name}" capabilities accessor threw: ` +
|
|
54
|
-
(err instanceof Error ? err.message : String(err)));
|
|
55
|
-
}
|
|
56
|
-
if (!caps || typeof caps !== 'object') {
|
|
57
|
-
throw new Error(`drivers plugin "${h.name}" must declare capabilities object`);
|
|
58
|
-
}
|
|
59
|
-
const c = caps;
|
|
60
|
-
for (const field of ['sessionResume', 'systemPrompt', 'outputFormat']) {
|
|
61
|
-
if (typeof c[field] !== 'boolean') {
|
|
62
|
-
throw new Error(`drivers plugin "${h.name}".capabilities.${field} must be a boolean (got ${typeof c[field]})`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Optional methods, but if present must be functions.
|
|
66
|
-
for (const opt of ['parseResult', 'resolveModel', 'resolveTools']) {
|
|
67
|
-
if (h[opt] !== undefined && typeof h[opt] !== 'function') {
|
|
68
|
-
throw new Error(`drivers plugin "${h.name}".${opt} must be a function or undefined`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case 'triggers':
|
|
74
|
-
if (typeof h.watch !== 'function') {
|
|
75
|
-
throw new Error(`triggers plugin "${h.name}" must export watch()`);
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case 'completions':
|
|
79
|
-
if (typeof h.check !== 'function') {
|
|
80
|
-
throw new Error(`completions plugin "${h.name}" must export check()`);
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
case 'middlewares':
|
|
84
|
-
if (typeof h.enhanceDoc !== 'function') {
|
|
85
|
-
throw new Error(`middlewares plugin "${h.name}" must export enhanceDoc()`);
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Plugin name must be a scoped npm package or a tagma-prefixed package.
|
|
91
|
-
// Reject absolute/relative paths and suspicious patterns to prevent
|
|
92
|
-
// arbitrary code execution via crafted YAML configs.
|
|
93
|
-
export const PLUGIN_NAME_RE = /^(@[a-z0-9-]+\/[a-z0-9._-]+|tagma-plugin-[a-z0-9._-]+)$/;
|
|
94
|
-
export function isValidPluginName(name) {
|
|
95
|
-
return typeof name === 'string' && PLUGIN_NAME_RE.test(name);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Parse and validate the `tagmaPlugin` field of a `package.json` blob.
|
|
99
|
-
*
|
|
100
|
-
* Returns the strongly-typed manifest if the field is present and
|
|
101
|
-
* well-formed (`category` is one of the four known categories and `type`
|
|
102
|
-
* is a non-empty string). Returns `null` if the field is absent —that
|
|
103
|
-
* is the host's signal that the package is a library, not a plugin.
|
|
104
|
-
*
|
|
105
|
-
* Throws if the field is present but malformed: that's a packaging bug
|
|
106
|
-
* the plugin author should hear about loudly, not a silent skip.
|
|
107
|
-
*
|
|
108
|
-
* Hosts use this during auto-discovery to decide whether to load a
|
|
109
|
-
* package as a plugin without having to dynamically `import()` it.
|
|
110
|
-
*/
|
|
111
|
-
export function readPluginManifest(pkgJson) {
|
|
112
|
-
if (!pkgJson || typeof pkgJson !== 'object')
|
|
113
|
-
return null;
|
|
114
|
-
const raw = pkgJson.tagmaPlugin;
|
|
115
|
-
if (raw === undefined)
|
|
116
|
-
return null;
|
|
117
|
-
if (!raw || typeof raw !== 'object') {
|
|
118
|
-
throw new Error('tagmaPlugin field must be an object with { category, type }');
|
|
119
|
-
}
|
|
120
|
-
const m = raw;
|
|
121
|
-
const category = m.category;
|
|
122
|
-
const type = m.type;
|
|
123
|
-
if (typeof category !== 'string' || !VALID_CATEGORIES.has(category)) {
|
|
124
|
-
throw new Error(`tagmaPlugin.category must be one of ${[...VALID_CATEGORIES].join(', ')}, got ${JSON.stringify(category)}`);
|
|
125
|
-
}
|
|
126
|
-
if (typeof type !== 'string' || type.length === 0) {
|
|
127
|
-
throw new Error(`tagmaPlugin.type must be a non-empty string, got ${JSON.stringify(type)}`);
|
|
128
|
-
}
|
|
129
|
-
if (!PLUGIN_TYPE_RE.test(type)) {
|
|
130
|
-
throw new Error(`tagmaPlugin.type must match ${PLUGIN_TYPE_RE} (letters, digits, underscores, hyphens; no paths or dots), got ${JSON.stringify(type)}`);
|
|
131
|
-
}
|
|
132
|
-
return { category: category, type };
|
|
133
|
-
}
|
|
134
|
-
function isRecord(value) {
|
|
135
|
-
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
136
|
-
}
|
|
137
|
-
function isTagmaPlugin(value) {
|
|
138
|
-
if (!isRecord(value))
|
|
139
|
-
return false;
|
|
140
|
-
if (typeof value.name !== 'string' || value.name.length === 0)
|
|
141
|
-
return false;
|
|
142
|
-
if (value.capabilities !== undefined && !isRecord(value.capabilities))
|
|
143
|
-
return false;
|
|
144
|
-
if (value.setup !== undefined && typeof value.setup !== 'function')
|
|
145
|
-
return false;
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
function hasSupportedCapabilityMap(plugin) {
|
|
149
|
-
if (!plugin.capabilities)
|
|
150
|
-
return false;
|
|
151
|
-
const capabilities = plugin.capabilities;
|
|
152
|
-
return CAPABILITY_CATEGORIES.some((category) => capabilities[category] !== undefined);
|
|
153
|
-
}
|
|
154
|
-
function moduleDefaultPlugin(name, mod) {
|
|
155
|
-
if (!isRecord(mod) || !isTagmaPlugin(mod.default) || !hasSupportedCapabilityMap(mod.default)) {
|
|
156
|
-
throw new Error(`Plugin "${name}" must default-export a TagmaPlugin with capabilities maps`);
|
|
157
|
-
}
|
|
158
|
-
return mod.default;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Instance-scoped plugin registry. Each workspace in a multi-tenant sidecar
|
|
162
|
-
* owns its own PluginRegistry, so installing/uninstalling a driver in one
|
|
163
|
-
* workspace cannot clobber another.
|
|
164
|
-
*/
|
|
165
|
-
export class PluginRegistry {
|
|
166
|
-
registries = {
|
|
167
|
-
drivers: new Map(),
|
|
168
|
-
triggers: new Map(),
|
|
169
|
-
completions: new Map(),
|
|
170
|
-
middlewares: new Map(),
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Register a plugin under (category, type). Returns:
|
|
174
|
-
* - 'registered' on first registration
|
|
175
|
-
* - 'replaced' when an existing entry was overwritten with a different handler
|
|
176
|
-
* - 'unchanged' when the same handler instance was already present
|
|
177
|
-
*
|
|
178
|
-
* Throws if `category` is unknown, `type` is empty, or `handler` violates
|
|
179
|
-
* the minimum interface contract for the category.
|
|
180
|
-
*/
|
|
181
|
-
registerPlugin(category, type, handler) {
|
|
182
|
-
if (!VALID_CATEGORIES.has(category)) {
|
|
183
|
-
throw new Error(`Unknown plugin category "${category}"`);
|
|
184
|
-
}
|
|
185
|
-
if (typeof type !== 'string' || type.length === 0) {
|
|
186
|
-
throw new Error(`Plugin type must be a non-empty string (category="${category}")`);
|
|
187
|
-
}
|
|
188
|
-
if (!PLUGIN_TYPE_RE.test(type)) {
|
|
189
|
-
throw new Error(`Plugin type "${type}" must match ${PLUGIN_TYPE_RE} (letters, digits, underscores, hyphens; no paths or dots)`);
|
|
190
|
-
}
|
|
191
|
-
validateContract(category, handler);
|
|
192
|
-
const registry = this.registries[category];
|
|
193
|
-
const existing = registry.get(type);
|
|
194
|
-
if (existing === handler)
|
|
195
|
-
return 'unchanged';
|
|
196
|
-
const wasReplaced = existing !== undefined;
|
|
197
|
-
registry.set(type, handler);
|
|
198
|
-
if (wasReplaced) {
|
|
199
|
-
// D18: surface silent shadowing. Hot-reload flows legitimately replace
|
|
200
|
-
// handlers; installing two different plugin packages that both claim
|
|
201
|
-
// the same (category, type) does not —the second wins and breaks the
|
|
202
|
-
// first's consumers with no audit trail. A console.warn is cheap,
|
|
203
|
-
// respects existing callers that rely on 'replaced', and gives ops a
|
|
204
|
-
// grep-able signal when registrations collide unexpectedly.
|
|
205
|
-
console.warn(`[tagma-sdk] registerPlugin: replaced existing ${category}/${type} - ` +
|
|
206
|
-
`check for duplicate plugin packages claiming the same type.`);
|
|
207
|
-
}
|
|
208
|
-
return wasReplaced ? 'replaced' : 'registered';
|
|
209
|
-
}
|
|
210
|
-
registerTagmaPlugin(plugin) {
|
|
211
|
-
if (!isTagmaPlugin(plugin)) {
|
|
212
|
-
throw new Error('TagmaPlugin must be an object with a non-empty "name"');
|
|
213
|
-
}
|
|
214
|
-
if (!plugin.capabilities) {
|
|
215
|
-
throw new Error(`TagmaPlugin "${plugin.name}" must declare capabilities`);
|
|
216
|
-
}
|
|
217
|
-
const registered = [];
|
|
218
|
-
const capabilities = plugin.capabilities;
|
|
219
|
-
for (const category of CAPABILITY_CATEGORIES) {
|
|
220
|
-
const handlers = capabilities[category];
|
|
221
|
-
if (handlers === undefined)
|
|
222
|
-
continue;
|
|
223
|
-
if (!isRecord(handlers)) {
|
|
224
|
-
throw new Error(`TagmaPlugin "${plugin.name}" capabilities.${category} must be an object map`);
|
|
225
|
-
}
|
|
226
|
-
for (const [type, handler] of Object.entries(handlers)) {
|
|
227
|
-
const result = this.registerPlugin(category, type, handler);
|
|
228
|
-
registered.push({ category, type, result });
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (registered.length === 0) {
|
|
232
|
-
throw new Error(`TagmaPlugin "${plugin.name}" must declare at least one supported capability`);
|
|
233
|
-
}
|
|
234
|
-
return registered;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Remove a plugin from the in-process registry. Returns true if a plugin
|
|
238
|
-
* was actually removed. Note: ESM module caching is not affected, so
|
|
239
|
-
* re-importing the same file after unregister will yield the cached module — * callers wanting a fresh load must restart the host process.
|
|
240
|
-
*/
|
|
241
|
-
unregisterPlugin(category, type) {
|
|
242
|
-
if (!VALID_CATEGORIES.has(category))
|
|
243
|
-
return false;
|
|
244
|
-
return this.registries[category].delete(type);
|
|
245
|
-
}
|
|
246
|
-
getHandler(category, type) {
|
|
247
|
-
const handler = this.registries[category].get(type);
|
|
248
|
-
if (!handler) {
|
|
249
|
-
throw new Error(`${category} type "${type}" not registered.\n` +
|
|
250
|
-
`Install the plugin: bun add @tagma/${singularCategory(category)}-${type}`);
|
|
251
|
-
}
|
|
252
|
-
return handler;
|
|
253
|
-
}
|
|
254
|
-
hasHandler(category, type) {
|
|
255
|
-
return this.registries[category].has(type);
|
|
256
|
-
}
|
|
257
|
-
listRegistered(category) {
|
|
258
|
-
return [...this.registries[category].keys()];
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Load and register a list of plugin packages into this registry.
|
|
262
|
-
*
|
|
263
|
-
* @param pluginNames - Validated npm package names to load.
|
|
264
|
-
* @param resolveFrom - Optional absolute path to resolve plugins from (e.g.
|
|
265
|
-
* the workspace's working directory). When omitted, the default ESM
|
|
266
|
-
* resolution uses the SDK's own `node_modules`, which will fail for
|
|
267
|
-
* plugins installed only in the user's workspace. CLI callers should
|
|
268
|
-
* pass `process.cwd()` or the workspace root so that workspace-local
|
|
269
|
-
* plugins resolve correctly.
|
|
270
|
-
*/
|
|
271
|
-
async loadPlugins(pluginNames, resolveFrom) {
|
|
272
|
-
for (const name of pluginNames) {
|
|
273
|
-
if (!isValidPluginName(name)) {
|
|
274
|
-
throw new Error(`Plugin "${name}" rejected: plugin names must be scoped npm packages ` +
|
|
275
|
-
`(e.g. @tagma/trigger-xyz) or tagma-plugin-* packages. ` +
|
|
276
|
-
`Relative/absolute paths are not allowed.`);
|
|
277
|
-
}
|
|
278
|
-
let moduleUrl = name;
|
|
279
|
-
if (resolveFrom) {
|
|
280
|
-
// Resolve the package entry point relative to the caller's directory
|
|
281
|
-
// so plugins installed in the workspace's node_modules are found
|
|
282
|
-
// even when the SDK itself lives elsewhere (e.g. a global install
|
|
283
|
-
// or a monorepo sibling package).
|
|
284
|
-
const req = createRequire(resolveFrom.endsWith('/') ? resolveFrom : resolveFrom + '/');
|
|
285
|
-
const resolved = req.resolve(name);
|
|
286
|
-
moduleUrl = pathToFileURL(resolved).href;
|
|
287
|
-
}
|
|
288
|
-
const mod = await import(moduleUrl);
|
|
289
|
-
this.registerTagmaPlugin(moduleDefaultPlugin(name, mod));
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
1
|
+
export { isValidPluginName, PluginRegistry, PLUGIN_NAME_RE, readPluginManifest, } from '@tagma/core';
|
|
293
2
|
//# sourceMappingURL=registry.js.map
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export interface RunOptions {
|
|
3
|
-
readonly timeoutMs?: number;
|
|
4
|
-
readonly signal?: AbortSignal;
|
|
5
|
-
/**
|
|
6
|
-
* If set, stream the child's stdout to this file path as it arrives. The
|
|
7
|
-
* returned `TaskResult.stdout` is still a bounded in-memory tail
|
|
8
|
-
* (`maxStdoutTailBytes`) — callers that need the full output should read
|
|
9
|
-
* from the returned `stdoutPath`. Parent directories are created as needed.
|
|
10
|
-
*/
|
|
11
|
-
readonly stdoutPath?: string;
|
|
12
|
-
/** Symmetric to `stdoutPath` for stderr. */
|
|
13
|
-
readonly stderrPath?: string;
|
|
14
|
-
/**
|
|
15
|
-
* Cap on bytes retained in memory for the returned `TaskResult.stdout`
|
|
16
|
-
* string. Defaults to `DEFAULT_STDOUT_TAIL_BYTES`. Bytes beyond this cap
|
|
17
|
-
* from the HEAD of the stream are dropped from the in-memory string; the
|
|
18
|
-
* on-disk file (if `stdoutPath` is set) is still the full output.
|
|
19
|
-
*/
|
|
20
|
-
readonly maxStdoutTailBytes?: number;
|
|
21
|
-
readonly maxStderrTailBytes?: number;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* R2: Validate a SpawnSpec returned by a third-party driver. Returns null on
|
|
25
|
-
* success or a human-readable error message describing the first violation.
|
|
26
|
-
*
|
|
27
|
-
* Catching this here is critical: an undetected bad spec ends up calling
|
|
28
|
-
* Bun.spawn with garbage and the resulting TypeError leaks into engine
|
|
29
|
-
* processTask's catch block as "Cannot read properties of undefined". By
|
|
30
|
-
* validating here we surface a clear "Driver X returned invalid args" message
|
|
31
|
-
* instead, and short-circuit before holding any process resources.
|
|
32
|
-
*/
|
|
33
|
-
export declare function validateSpawnSpec(spec: unknown, driverName: string): string | null;
|
|
34
|
-
export declare function runSpawn(spec: SpawnSpec, driver: DriverPlugin | null, opts?: RunOptions): Promise<TaskResult>;
|
|
35
|
-
export declare function runCommand(command: string, cwd: string, opts?: RunOptions): Promise<TaskResult>;
|
|
1
|
+
export { runCommand, runSpawn } from '@tagma/runtime-bun';
|
|
36
2
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
|