@nodetool-ai/cli-execution 0.0.0-stage → 0.8.9-bootstrap.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.
Files changed (103) hide show
  1. package/dist/.nodetool-build-stamp +1 -0
  2. package/dist/debug/browser-runner.d.ts +21 -0
  3. package/dist/debug/browser-runner.d.ts.map +1 -0
  4. package/dist/debug/browser-runner.js +196 -0
  5. package/dist/debug/browser-runner.js.map +1 -0
  6. package/dist/debug/collector.d.ts +9 -0
  7. package/dist/debug/collector.d.ts.map +1 -0
  8. package/dist/debug/collector.js +9 -0
  9. package/dist/debug/collector.js.map +1 -0
  10. package/dist/debug/diff.d.ts +48 -0
  11. package/dist/debug/diff.d.ts.map +1 -0
  12. package/dist/debug/diff.js +68 -0
  13. package/dist/debug/diff.js.map +1 -0
  14. package/dist/debug/harness.d.ts +11 -0
  15. package/dist/debug/harness.d.ts.map +1 -0
  16. package/dist/debug/harness.js +102 -0
  17. package/dist/debug/harness.js.map +1 -0
  18. package/dist/debug/index.d.ts +17 -0
  19. package/dist/debug/index.d.ts.map +1 -0
  20. package/dist/debug/index.js +16 -0
  21. package/dist/debug/index.js.map +1 -0
  22. package/dist/debug/markdown.d.ts +3 -0
  23. package/dist/debug/markdown.d.ts.map +1 -0
  24. package/dist/debug/markdown.js +127 -0
  25. package/dist/debug/markdown.js.map +1 -0
  26. package/dist/debug/server-runner.d.ts +24 -0
  27. package/dist/debug/server-runner.d.ts.map +1 -0
  28. package/dist/debug/server-runner.js +211 -0
  29. package/dist/debug/server-runner.js.map +1 -0
  30. package/dist/debug/target.d.ts +34 -0
  31. package/dist/debug/target.d.ts.map +1 -0
  32. package/dist/debug/target.js +95 -0
  33. package/dist/debug/target.js.map +1 -0
  34. package/dist/debug/trace.d.ts +30 -0
  35. package/dist/debug/trace.d.ts.map +1 -0
  36. package/dist/debug/trace.js +87 -0
  37. package/dist/debug/trace.js.map +1 -0
  38. package/dist/debug/types.d.ts +82 -0
  39. package/dist/debug/types.d.ts.map +1 -0
  40. package/dist/debug/types.js +13 -0
  41. package/dist/debug/types.js.map +1 -0
  42. package/dist/debug/verdict.d.ts +3 -0
  43. package/dist/debug/verdict.d.ts.map +1 -0
  44. package/dist/debug/verdict.js +78 -0
  45. package/dist/debug/verdict.js.map +1 -0
  46. package/dist/debug/watch.d.ts +23 -0
  47. package/dist/debug/watch.d.ts.map +1 -0
  48. package/dist/debug/watch.js +68 -0
  49. package/dist/debug/watch.js.map +1 -0
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +3 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/local-model-interfaces.d.ts +20 -0
  55. package/dist/local-model-interfaces.d.ts.map +1 -0
  56. package/dist/local-model-interfaces.js +39 -0
  57. package/dist/local-model-interfaces.js.map +1 -0
  58. package/dist/node/run-node.d.ts +31 -0
  59. package/dist/node/run-node.d.ts.map +1 -0
  60. package/dist/node/run-node.js +92 -0
  61. package/dist/node/run-node.js.map +1 -0
  62. package/dist/node-registry.d.ts +29 -0
  63. package/dist/node-registry.d.ts.map +1 -0
  64. package/dist/node-registry.js +38 -0
  65. package/dist/node-registry.js.map +1 -0
  66. package/dist/packs/host.d.ts +14 -0
  67. package/dist/packs/host.d.ts.map +1 -0
  68. package/dist/packs/host.js +38 -0
  69. package/dist/packs/host.js.map +1 -0
  70. package/dist/run-budget.d.ts +40 -0
  71. package/dist/run-budget.d.ts.map +1 -0
  72. package/dist/run-budget.js +119 -0
  73. package/dist/run-budget.js.map +1 -0
  74. package/dist/run-dsl-supervised.d.ts +11 -0
  75. package/dist/run-dsl-supervised.d.ts.map +1 -0
  76. package/dist/run-dsl-supervised.js +89 -0
  77. package/dist/run-dsl-supervised.js.map +1 -0
  78. package/dist/run-dsl.d.ts +40 -0
  79. package/dist/run-dsl.d.ts.map +1 -0
  80. package/dist/run-dsl.js +65 -0
  81. package/dist/run-dsl.js.map +1 -0
  82. package/dist/run-json.d.ts +24 -0
  83. package/dist/run-json.d.ts.map +1 -0
  84. package/dist/run-json.js +132 -0
  85. package/dist/run-json.js.map +1 -0
  86. package/dist/sandbox-catalog.d.ts +26 -0
  87. package/dist/sandbox-catalog.d.ts.map +1 -0
  88. package/dist/sandbox-catalog.js +83 -0
  89. package/dist/sandbox-catalog.js.map +1 -0
  90. package/dist/supervisor.d.ts +97 -0
  91. package/dist/supervisor.d.ts.map +1 -0
  92. package/dist/supervisor.js +194 -0
  93. package/dist/supervisor.js.map +1 -0
  94. package/dist/validate/index.d.ts +29 -0
  95. package/dist/validate/index.d.ts.map +1 -0
  96. package/dist/validate/index.js +79 -0
  97. package/dist/validate/index.js.map +1 -0
  98. package/dist/workflow-file.d.ts +3 -0
  99. package/dist/workflow-file.d.ts.map +1 -0
  100. package/dist/workflow-file.js +176 -0
  101. package/dist/workflow-file.js.map +1 -0
  102. package/package.json +70 -4
  103. package/README.md +0 -3
@@ -0,0 +1,132 @@
1
+ /**
2
+ * JSON reporting for a finished run.
3
+ *
4
+ * A run that reaches here has already executed and been paid for, so reporting
5
+ * must not be able to fail it. Two things sit between a run result and a JSON
6
+ * string. GPU image nodes emit raw-RGBA bytes as their in-flight format so
7
+ * chained shader ops skip the codec, and every boundary that hands out a
8
+ * portable image encodes them first (`packages/runtime/src/image-codec.ts`) —
9
+ * this is that boundary for the CLI. And three 1024² frames in one
10
+ * `JSON.stringify(…, null, 2)` exceed what a single JS string can hold.
11
+ *
12
+ * So binary payloads at or over `maxInlineBytes` are written next to the run
13
+ * and replaced by a `$file` pointer, and a stringify that still overflows
14
+ * degrades to a summary instead of throwing.
15
+ */
16
+ import { mkdirSync, writeFileSync } from "node:fs";
17
+ import { dirname, join, resolve } from "node:path";
18
+ import { isRawRgbaImage } from "@nodetool-ai/protocol";
19
+ import { encodeRawImageRef } from "@nodetool-ai/runtime";
20
+ import { isFunctionValue, isObjectLike, isRecord, isString } from "@nodetool-ai/cli-common/predicates";
21
+ /**
22
+ * Above this many bytes a payload is written to disk. A byte array in JSON is
23
+ * one number per byte, so even a modest buffer costs megabytes of text and is
24
+ * unusable to whatever reads it.
25
+ */
26
+ const DEFAULT_MAX_INLINE_BYTES = 64 * 1024;
27
+ /** The file extension for `mimeType`, or `bin` when it names nothing usable. */
28
+ function extensionFor(mimeType) {
29
+ const subtype = mimeType?.split("/")[1]?.split(";")[0]?.replace(/\+.*$/, "");
30
+ return subtype && /^[a-z0-9.-]+$/i.test(subtype) ? subtype : "bin";
31
+ }
32
+ function writeBinary(data, mimeType, spill) {
33
+ if (spill.files.length === 0) {
34
+ mkdirSync(spill.dir, { recursive: true });
35
+ }
36
+ const file = join(spill.dir, `payload-${spill.files.length}.${extensionFor(mimeType)}`);
37
+ writeFileSync(file, data);
38
+ spill.files.push(file);
39
+ const pointer = { $file: file, bytes: data.byteLength };
40
+ if (mimeType) {
41
+ pointer.mimeType = mimeType;
42
+ }
43
+ return pointer;
44
+ }
45
+ async function encodeImage(ref) {
46
+ try {
47
+ const encoded = await encodeRawImageRef(ref);
48
+ return isObjectLike(encoded) ? encoded : ref;
49
+ }
50
+ catch {
51
+ // No codec on this install (sharp missing). Keep the raw ref: its bytes
52
+ // still spill to disk below rather than being dropped.
53
+ return ref;
54
+ }
55
+ }
56
+ /**
57
+ * Walk `value`, PNG-encoding raw-RGBA images and spilling large binaries.
58
+ * `mimeType` is the one declared by the nearest enclosing object, so a ref's
59
+ * `data` is named by its own `mimeType`.
60
+ */
61
+ async function prepare(value, mimeType, spill) {
62
+ if (value instanceof Uint8Array) {
63
+ return value.byteLength >= spill.limit
64
+ ? writeBinary(value, mimeType, spill)
65
+ : value;
66
+ }
67
+ if (Array.isArray(value)) {
68
+ return Promise.all(value.map((item) => prepare(item, mimeType, spill)));
69
+ }
70
+ if (!isObjectLike(value)) {
71
+ return value;
72
+ }
73
+ // A value with its own serializer (a `Date`, say) decides its own JSON.
74
+ // Decomposing it into own enumerable properties turns a timestamp into `{}`.
75
+ if (isFunctionValue(value.toJSON)) {
76
+ return value;
77
+ }
78
+ const record = isRawRgbaImage(value) ? await encodeImage(value) : value;
79
+ const childMime = isString(record.mimeType) ? record.mimeType : mimeType;
80
+ const out = {};
81
+ for (const [key, item] of Object.entries(record)) {
82
+ out[key] = await prepare(item, childMime, spill);
83
+ }
84
+ return out;
85
+ }
86
+ /** The JSON text for a run result, plus every payload file it points at. */
87
+ export async function formatRunJson(value, opts = {}) {
88
+ const spill = {
89
+ dir: opts.outputDir ?? resolve(process.cwd(), "nodetool-output"),
90
+ limit: opts.maxInlineBytes ?? DEFAULT_MAX_INLINE_BYTES,
91
+ files: []
92
+ };
93
+ try {
94
+ const prepared = await prepare(value, undefined, spill);
95
+ return { json: JSON.stringify(prepared, null, 2), files: spill.files };
96
+ }
97
+ catch (e) {
98
+ // Whatever went wrong here, the run itself is done. Report the failure as
99
+ // JSON on the JSON channel instead of raising it over a finished run.
100
+ const summary = {
101
+ error: `Result could not be serialized as JSON: ${String(e)}`,
102
+ keys: isRecord(value) ? Object.keys(value) : [],
103
+ files: spill.files
104
+ };
105
+ return { json: JSON.stringify(summary, null, 2), files: spill.files };
106
+ }
107
+ }
108
+ /** Print a run result as JSON, noting on stderr where any payloads landed. */
109
+ export async function printRunJson(value, opts = {}) {
110
+ const { json, files } = await formatRunJson(value, opts);
111
+ console.log(json);
112
+ const first = files[0];
113
+ if (first) {
114
+ console.error(`Wrote ${files.length} payload file(s) to ${dirname(first)}`);
115
+ }
116
+ }
117
+ /**
118
+ * One-line rendering of a value for the human-readable output. Byte arrays are
119
+ * described rather than expanded, so a 4 MB frame does not cost tens of
120
+ * megabytes of text on its way to being truncated to `maxChars`.
121
+ */
122
+ export function previewJson(value, maxChars) {
123
+ // `JSON.stringify` is typed `string` but returns undefined for an undefined
124
+ // or non-serializable root.
125
+ const text = JSON.stringify(value, (_key, item) => item instanceof Uint8Array ? `<${item.byteLength} bytes>` : item);
126
+ if (text === undefined)
127
+ return "undefined";
128
+ if (maxChars === undefined || text.length <= maxChars)
129
+ return text;
130
+ return `${text.slice(0, maxChars)}…`;
131
+ }
132
+ //# sourceMappingURL=run-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-json.js","sourceRoot":"","sources":["../src/run-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,QAAQ,EACT,MAAM,oCAAoC,CAAC;AAE5C;;;;GAIG;AACH,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AA0B3C,gFAAgF;AAChF,SAAS,YAAY,CAAC,QAA4B;IAChD,MAAM,OAAO,GAAG,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7E,OAAO,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AACrE,CAAC;AAED,SAAS,WAAW,CAClB,IAAgB,EAChB,QAA4B,EAC5B,KAAY;IAEZ,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CACf,KAAK,CAAC,GAAG,EACT,WAAW,KAAK,CAAC,KAAK,CAAC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AAC,CAAC,IAAI,CACjE,CAAC;IACF,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IACnE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC;AACvC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type SandboxModuleCatalog } from "@nodetool-ai/runtime";
2
+ /**
3
+ * Discover installed sandbox packs and make the catalog this process's default,
4
+ * so the CLI's validation and execution harnesses resolve sandbox modules
5
+ * through the same instance the server uses. Discovery executes no pack code.
6
+ * A failure leaves the CLI without a catalog rather than without a registry.
7
+ * Returns the installed catalog, or null when discovery failed.
8
+ *
9
+ * This path never compiles. npm-backed modules resolve only from the cache,
10
+ * whose entries are re-verified against their inputs' current contents; a miss
11
+ * becomes the `pending-compile` diagnostic naming `nodetool packs compile`.
12
+ */
13
+ export declare function installSandboxCatalog(): SandboxModuleCatalog | null;
14
+ /**
15
+ * `specifier -> absolute path to that installed pack's shipped .d.ts`, read
16
+ * from each discovered pack's own `package.json` `types` field (a pack ships
17
+ * none by declaring no `types` field, which this simply leaves out). Used by
18
+ * `jsscript validate` to type-check a script's imports against the packs it
19
+ * actually has installed — see `@nodetool-ai/execution`'s `type-check.ts`.
20
+ * Runs discovery again rather than threading it through
21
+ * {@link installSandboxCatalog}, which only keeps the catalog; this stays a
22
+ * separate, cheap, synchronous call so a caller that does not need types
23
+ * pays nothing for them.
24
+ */
25
+ export declare function discoverPackDtsSources(): ReadonlyMap<string, string>;
26
+ //# sourceMappingURL=sandbox-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-catalog.d.ts","sourceRoot":"","sources":["../src/sandbox-catalog.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAsB9B;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,GAAG,IAAI,CAenE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAepE"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The CLI's sandbox pack catalog, apart from the node registry so a harness
3
+ * that runs sandbox code without node types does not load every node package.
4
+ */
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { discoverSandboxCatalog } from "@nodetool-ai/node-sdk";
8
+ import { setProcessSandboxModuleCatalog } from "@nodetool-ai/runtime";
9
+ import { createCachedNpmLookup } from "@nodetool-ai/sandbox-compiler/cache";
10
+ import { z } from "zod";
11
+ /** The one field this module reads off a pack's `package.json`; everything else in the file is irrelevant here. */
12
+ const packageJsonTypesField = z
13
+ .object({ types: z.string().trim().min(1).optional() })
14
+ .passthrough();
15
+ /** The pack's declared `types` path, or `undefined` for any reason — missing file, invalid JSON, no `types` field. Never throws. */
16
+ function readPackageJsonTypesField(packageJsonPath) {
17
+ if (!existsSync(packageJsonPath))
18
+ return undefined;
19
+ let raw;
20
+ try {
21
+ raw = JSON.parse(readFileSync(packageJsonPath, "utf8"));
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ const parsed = packageJsonTypesField.safeParse(raw);
27
+ return parsed.success ? parsed.data.types : undefined;
28
+ }
29
+ /**
30
+ * Discover installed sandbox packs and make the catalog this process's default,
31
+ * so the CLI's validation and execution harnesses resolve sandbox modules
32
+ * through the same instance the server uses. Discovery executes no pack code.
33
+ * A failure leaves the CLI without a catalog rather than without a registry.
34
+ * Returns the installed catalog, or null when discovery failed.
35
+ *
36
+ * This path never compiles. npm-backed modules resolve only from the cache,
37
+ * whose entries are re-verified against their inputs' current contents; a miss
38
+ * becomes the `pending-compile` diagnostic naming `nodetool packs compile`.
39
+ */
40
+ export function installSandboxCatalog() {
41
+ try {
42
+ const { catalog } = discoverSandboxCatalog(undefined, {
43
+ compiled: createCachedNpmLookup()
44
+ });
45
+ setProcessSandboxModuleCatalog(catalog);
46
+ return catalog;
47
+ }
48
+ catch (error) {
49
+ console.warn(`Sandbox module catalog unavailable: ${error instanceof Error ? error.message : String(error)}`);
50
+ return null;
51
+ }
52
+ }
53
+ /**
54
+ * `specifier -> absolute path to that installed pack's shipped .d.ts`, read
55
+ * from each discovered pack's own `package.json` `types` field (a pack ships
56
+ * none by declaring no `types` field, which this simply leaves out). Used by
57
+ * `jsscript validate` to type-check a script's imports against the packs it
58
+ * actually has installed — see `@nodetool-ai/execution`'s `type-check.ts`.
59
+ * Runs discovery again rather than threading it through
60
+ * {@link installSandboxCatalog}, which only keeps the catalog; this stays a
61
+ * separate, cheap, synchronous call so a caller that does not need types
62
+ * pays nothing for them.
63
+ */
64
+ export function discoverPackDtsSources() {
65
+ const sources = new Map();
66
+ try {
67
+ const { discoveries } = discoverSandboxCatalog();
68
+ for (const discovery of discoveries) {
69
+ const types = readPackageJsonTypesField(join(discovery.dir, "package.json"));
70
+ if (types === undefined)
71
+ continue;
72
+ const dtsPath = join(discovery.dir, types);
73
+ if (existsSync(dtsPath))
74
+ sources.set(discovery.name, dtsPath);
75
+ }
76
+ }
77
+ catch {
78
+ // Discovery failure here is the same non-fatal case installSandboxCatalog
79
+ // already warns about; a caller that wants types simply gets none.
80
+ }
81
+ return sources;
82
+ }
83
+ //# sourceMappingURL=sandbox-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-catalog.js","sourceRoot":"","sources":["../src/sandbox-catalog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,8BAA8B,EAE/B,MAAM,sBAAsB,CAA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AE,CACH,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,WAAW,EAAE,GAAG,sBAAsB,EAAE,CAAC;QACjD,KAAK,MAAM,SAAS,IAAI,WAAW,EAAE,CAAC;YACpC,MAAM,KAAK,GAAG,yBAAyB,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC;YAC7E,IAAI,KAAK,KAAK,SAAS;gBAAE,SAAS;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3C,IAAI,UAAU,CAAC,OAAO,CAAC;gBAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,mEAAmE;IACrE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,97 @@
1
+ import type { SupervisorHandle } from "@nodetool-ai/execution";
2
+ import type { Intervention, ProcessingMessage } from "@nodetool-ai/protocol";
3
+ import type { ProcessingContext } from "@nodetool-ai/runtime";
4
+ import type { Command } from "commander";
5
+ /**
6
+ * Model used when `--supervise` is given without `--supervisor-model`.
7
+ * `NODETOOL_SUPERVISOR_MODEL` overrides it.
8
+ */
9
+ export declare const DEFAULT_SUPERVISOR_MODEL = "anthropic/claude-sonnet-4-6";
10
+ /** The five flags, as Commander parses them. */
11
+ export interface SupervisorCliOptions {
12
+ supervise?: boolean;
13
+ maxDecisions?: string;
14
+ maxRetries?: string;
15
+ supervisorCostCap?: string;
16
+ supervisorModel?: string;
17
+ }
18
+ /**
19
+ * A validated supervisor configuration. Every bound is optional: an omitted
20
+ * flag means "whatever the kernel's `BoundedHandle` and the `SupervisorAgent`
21
+ * default to", so the defaults live in one place instead of being copied here.
22
+ */
23
+ export interface SupervisorRunConfig {
24
+ /** `provider/model`, as written or defaulted. Resolved when the handle is built. */
25
+ modelSpec: string;
26
+ maxDecisions?: number;
27
+ maxRetriesPerNode?: number;
28
+ maxCostUsd?: number;
29
+ }
30
+ /** Register the supervisor flags on a run-shaped command. */
31
+ export declare function addSupervisorOptions(command: Command): Command;
32
+ /**
33
+ * Turn the flags into a config, or `null` when the run is unsupervised.
34
+ *
35
+ * A bound passed without `--supervise` is a mistake worth reporting: it reads
36
+ * as "supervision, bounded", and silently running unsupervised would hide a
37
+ * failure the user asked to be handled.
38
+ */
39
+ export declare function parseSupervisorFlags(opts: SupervisorCliOptions): SupervisorRunConfig | null;
40
+ /**
41
+ * Split `provider/model` into its parts.
42
+ *
43
+ * Model ids themselves contain slashes (`openrouter/openai/gpt-5.4-mini`), so
44
+ * the split is decided by the registry rather than by counting separators:
45
+ * the leading segment is the provider only if a provider by that name is
46
+ * registered.
47
+ */
48
+ export declare function parseModelSpec(spec: string, isRegisteredProvider: (id: string) => boolean): {
49
+ providerId: string;
50
+ model: string;
51
+ };
52
+ interface SupervisorHandleInit {
53
+ config: SupervisorRunConfig;
54
+ /**
55
+ * The run's context — the supervisor's tools and its `supervisor:` memory
56
+ * keys share it, so a downstream agent can read the decisions back. The
57
+ * *provider* is a fresh instance and is never the run's.
58
+ */
59
+ context: ProcessingContext;
60
+ }
61
+ interface BuiltSupervisor {
62
+ handle: SupervisorHandle;
63
+ providerId: string;
64
+ model: string;
65
+ }
66
+ /**
67
+ * Build the bounded, LLM-backed handle. Imports are dynamic so the agents
68
+ * package and a provider are loaded only for a run that asked for them.
69
+ */
70
+ export declare function createSupervisorHandle(init: SupervisorHandleInit): Promise<BuiltSupervisor>;
71
+ /**
72
+ * Print one `⛨` line per decision as it happens, by draining the session's
73
+ * message stream. Lines go to stderr so `--json` stdout stays parseable.
74
+ */
75
+ export declare function streamInterventionLines(messages: AsyncIterable<ProcessingMessage>, write?: (line: string) => void): Promise<void>;
76
+ /** The run's closing supervised line. Nothing is printed for a clean run. */
77
+ export declare function printSupervisedSummary(interventions: readonly Intervention[], write?: (line: string) => void): void;
78
+ interface SupervisorCostAttribution {
79
+ interventions: readonly Intervention[];
80
+ jobId: string;
81
+ workflowId: string | null;
82
+ userId: string;
83
+ providerId: string;
84
+ model: string;
85
+ }
86
+ /**
87
+ * Write supervisor spend into the prediction ledger `nodetool costs` reads.
88
+ *
89
+ * One row per decision that cost money, attributed to the run (workflow id,
90
+ * plus the job id in metadata — the ledger has no job column) and tagged
91
+ * `supervisor` in `node_type`, so supervision is separable from the spend of
92
+ * the workflow it supervised. Best-effort: a ledger failure never fails a run
93
+ * that already finished. Returns the number of rows written.
94
+ */
95
+ export declare function recordSupervisorCost(attribution: SupervisorCostAttribution): Promise<number>;
96
+ export {};
97
+ //# sourceMappingURL=supervisor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC;;;GAGG;AACH,eAAO,MAAM,wBAAwB,gCAAgC,CAAC;AAEtE,gDAAgD;AAChD,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;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E,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,yBAAyB,GACrC,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
@@ -0,0 +1,194 @@
1
+ /**
2
+ * The CLI's supervisor surface: five flags, one handle, and the lines a
3
+ * supervised run prints.
4
+ *
5
+ * Flag parsing and model-spec resolution are pure so they can be unit-tested
6
+ * without a provider, a database, or a kernel. Everything that needs a
7
+ * provider or the agents package is behind a dynamic import, so an
8
+ * unsupervised run loads none of it.
9
+ *
10
+ * The handle goes to `ExecutionSessionOptions.supervisor` — the one
11
+ * integration point every surface shares (docs/workflow-supervisor-design.md
12
+ * §7). No CLI code touches `WorkflowRunner`.
13
+ */
14
+ import { formatInterventionLine, formatSupervisedSummary, summarizeInterventions } from "@nodetool-ai/execution/debug";
15
+ import { parseNumericOption } from "@nodetool-ai/cli-common/numeric-options";
16
+ import { isNumber } from "@nodetool-ai/cli-common/predicates";
17
+ /**
18
+ * Model used when `--supervise` is given without `--supervisor-model`.
19
+ * `NODETOOL_SUPERVISOR_MODEL` overrides it.
20
+ */
21
+ export const DEFAULT_SUPERVISOR_MODEL = "anthropic/claude-sonnet-4-6";
22
+ /** Register the supervisor flags on a run-shaped command. */
23
+ export function addSupervisorOptions(command) {
24
+ return command
25
+ .option("--supervise", "Let a supervisor agent decide what to do when a node fails (retry / repair / skip / fail)")
26
+ .option("--max-decisions <n>", "Supervisor decisions allowed in this run (default: 10)")
27
+ .option("--max-retries <n>", "Supervisor retries allowed per node invocation (default: 2)")
28
+ .option("--supervisor-cost-cap <usd>", "Ceiling on supervisor spend for this run, in USD (default: 0.50)")
29
+ .option("--supervisor-model <provider/model>", `Model that supervises the run (default: ${DEFAULT_SUPERVISOR_MODEL})`);
30
+ }
31
+ function positiveInt(value, flag) {
32
+ return parseNumericOption(value, flag, { integer: true, min: 0 });
33
+ }
34
+ function positiveNumber(value, flag) {
35
+ return parseNumericOption(value, flag, { min: 0 });
36
+ }
37
+ /**
38
+ * Turn the flags into a config, or `null` when the run is unsupervised.
39
+ *
40
+ * A bound passed without `--supervise` is a mistake worth reporting: it reads
41
+ * as "supervision, bounded", and silently running unsupervised would hide a
42
+ * failure the user asked to be handled.
43
+ */
44
+ export function parseSupervisorFlags(opts) {
45
+ const bounded = opts.maxDecisions !== undefined ||
46
+ opts.maxRetries !== undefined ||
47
+ opts.supervisorCostCap !== undefined ||
48
+ opts.supervisorModel !== undefined;
49
+ if (!opts.supervise) {
50
+ if (bounded) {
51
+ throw new Error("Supervisor options were given without --supervise; add --supervise or drop them.");
52
+ }
53
+ return null;
54
+ }
55
+ const config = {
56
+ modelSpec: opts.supervisorModel ??
57
+ process.env.NODETOOL_SUPERVISOR_MODEL ??
58
+ DEFAULT_SUPERVISOR_MODEL
59
+ };
60
+ if (opts.maxDecisions !== undefined) {
61
+ config.maxDecisions = positiveInt(opts.maxDecisions, "--max-decisions");
62
+ }
63
+ if (opts.maxRetries !== undefined) {
64
+ config.maxRetriesPerNode = positiveInt(opts.maxRetries, "--max-retries");
65
+ }
66
+ if (opts.supervisorCostCap !== undefined) {
67
+ config.maxCostUsd = positiveNumber(opts.supervisorCostCap, "--supervisor-cost-cap");
68
+ }
69
+ return config;
70
+ }
71
+ /**
72
+ * Split `provider/model` into its parts.
73
+ *
74
+ * Model ids themselves contain slashes (`openrouter/openai/gpt-5.4-mini`), so
75
+ * the split is decided by the registry rather than by counting separators:
76
+ * the leading segment is the provider only if a provider by that name is
77
+ * registered.
78
+ */
79
+ export function parseModelSpec(spec, isRegisteredProvider) {
80
+ const cut = spec.indexOf("/");
81
+ const head = cut === -1 ? spec : spec.slice(0, cut);
82
+ if (cut === -1 || !isRegisteredProvider(head.toLowerCase())) {
83
+ throw new Error(`--supervisor-model must be "<provider>/<model>" with a registered provider ` +
84
+ `(got "${spec}"). Example: anthropic/claude-sonnet-4-6.`);
85
+ }
86
+ return { providerId: head.toLowerCase(), model: spec.slice(cut + 1) };
87
+ }
88
+ /**
89
+ * Build the bounded, LLM-backed handle. Imports are dynamic so the agents
90
+ * package and a provider are loaded only for a run that asked for them.
91
+ */
92
+ export async function createSupervisorHandle(init) {
93
+ const [{ BoundedHandle }, { SupervisorAgent }, { listRegisteredProviderIds }] = await Promise.all([
94
+ import("@nodetool-ai/kernel"),
95
+ import("@nodetool-ai/agents"),
96
+ import("@nodetool-ai/runtime")
97
+ ]);
98
+ const { createProviderStrict } = await import("@nodetool-ai/cli-providers");
99
+ const { providerId, model } = parseModelSpec(init.config.modelSpec, (id) => listRegisteredProviderIds().includes(id));
100
+ const provider = await createProviderStrict(providerId);
101
+ const agentOptions = {
102
+ provider,
103
+ model,
104
+ // The supervisor reads and writes the run's memory (`supervisor:` keys)
105
+ // but must not push its own provider chatter into the run's message
106
+ // stream — the CLI drains that stream for `⛨` lines — so it gets a
107
+ // listener-free copy, matching the agent surface.
108
+ context: init.context.copy({
109
+ shareMemory: true,
110
+ inheritMessageListeners: false
111
+ })
112
+ };
113
+ if (init.config.maxCostUsd !== undefined) {
114
+ agentOptions.maxCostUsd = init.config.maxCostUsd;
115
+ }
116
+ const agent = new SupervisorAgent(agentOptions);
117
+ const bounds = {};
118
+ if (init.config.maxDecisions !== undefined) {
119
+ bounds.maxDecisions = init.config.maxDecisions;
120
+ }
121
+ if (init.config.maxRetriesPerNode !== undefined) {
122
+ bounds.maxRetriesPerNode = init.config.maxRetriesPerNode;
123
+ }
124
+ const handle = new BoundedHandle(agent, bounds);
125
+ return { handle, providerId, model };
126
+ }
127
+ /**
128
+ * Print one `⛨` line per decision as it happens, by draining the session's
129
+ * message stream. Lines go to stderr so `--json` stdout stays parseable.
130
+ */
131
+ export async function streamInterventionLines(messages, write = (line) => console.error(line)) {
132
+ for await (const message of messages) {
133
+ if (message.type !== "supervisor_decision")
134
+ continue;
135
+ const intervention = {
136
+ escalation: message.escalation,
137
+ verdict: message.verdict,
138
+ decidedBy: message.decided_by
139
+ };
140
+ if (isNumber(message.cost)) {
141
+ intervention.costUsd = message.cost;
142
+ }
143
+ write(formatInterventionLine(intervention));
144
+ }
145
+ }
146
+ /** The run's closing supervised line. Nothing is printed for a clean run. */
147
+ export function printSupervisedSummary(interventions, write = (line) => console.log(line)) {
148
+ if (interventions.length === 0)
149
+ return;
150
+ write(formatSupervisedSummary(summarizeInterventions(interventions)));
151
+ }
152
+ /**
153
+ * Write supervisor spend into the prediction ledger `nodetool costs` reads.
154
+ *
155
+ * One row per decision that cost money, attributed to the run (workflow id,
156
+ * plus the job id in metadata — the ledger has no job column) and tagged
157
+ * `supervisor` in `node_type`, so supervision is separable from the spend of
158
+ * the workflow it supervised. Best-effort: a ledger failure never fails a run
159
+ * that already finished. Returns the number of rows written.
160
+ */
161
+ export async function recordSupervisorCost(attribution) {
162
+ const billable = attribution.interventions.filter((i) => isNumber(i.costUsd) && i.costUsd > 0);
163
+ if (billable.length === 0)
164
+ return 0;
165
+ const { Prediction } = await import("@nodetool-ai/models");
166
+ let written = 0;
167
+ for (const intervention of billable) {
168
+ try {
169
+ await Prediction.create({
170
+ user_id: attribution.userId,
171
+ provider: attribution.providerId,
172
+ model: attribution.model,
173
+ node_id: intervention.escalation.nodeId,
174
+ node_type: "supervisor",
175
+ workflow_id: attribution.workflowId,
176
+ cost: intervention.costUsd,
177
+ status: "completed",
178
+ metadata: {
179
+ kind: "supervisor",
180
+ job_id: attribution.jobId,
181
+ decided_by: intervention.decidedBy,
182
+ verdict: intervention.verdict.action,
183
+ escalated_node_type: intervention.escalation.nodeType
184
+ }
185
+ });
186
+ written += 1;
187
+ }
188
+ catch (err) {
189
+ console.error(`Failed to record supervisor cost: ${err instanceof Error ? err.message : String(err)}`);
190
+ }
191
+ }
192
+ return written;
193
+ }
194
+ //# sourceMappingUR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,UAAU,CAAC,QAAQ;iBACtD;aACF,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CACX,qCAAqC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CACxF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Wires the node-sdk {@link validateGraph} to the real node registry and the
3
+ * shared target resolver (DB id / JSON file / DSL file). Integration code —
4
+ * the registry pulls in every node pack — while the validation logic itself is
5
+ * unit-tested in node-sdk's graph-validation.test.ts.
6
+ */
7
+ import { type GraphValidationRegistry, type GraphValidationReport, type NodeRegistry } from "@nodetool-ai/node-sdk";
8
+ import type { DebugGraph, DebugTargetInfo } from "../debug/types.js";
9
+ interface ValidateResult {
10
+ target: DebugTargetInfo;
11
+ report: GraphValidationReport;
12
+ }
13
+ type ValidationRegistry = GraphValidationRegistry & Partial<Pick<NodeRegistry, "list" | "getNodePackageId">>;
14
+ interface ValidateDeps {
15
+ loadFromDb: (id: string) => Promise<{
16
+ graph: DebugGraph;
17
+ } | null>;
18
+ /** Registry view supplied by tests or an embedding host. */
19
+ registry?: ValidationRegistry;
20
+ /**
21
+ * Answers which exact `keys` this install can resolve from its secret store.
22
+ * Omit where no store exists — file/DSL targets skip the missing-secret
23
+ * check entirely rather than guess.
24
+ */
25
+ availableSecrets?: (keys: readonly string[]) => Promise<ReadonlySet<string>> | ReadonlySet<string>;
26
+ }
27
+ export declare function runValidate(ref: string, deps: ValidateDeps): Promise<ValidateResult>;
28
+ export {};
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAO/B,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,UAAU,cAAc;IACtB,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,qBAAqB,CAAC;CAC/B;AAED,KAAK,kBAAkB,GAAG,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC;AAE7G,UAAU,YAAY;IACpB,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAClE,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CACjB,IAAI,EAAE,SAAS,MAAM,EAAE,KACpB,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;CACzD;AAmBD,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,cAAc,CAAC,CAyDzB"}