@clemrig/factory 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -17
- package/dist/app/doctor.d.ts +2 -4
- package/dist/app/doctor.js +6 -4
- package/dist/app/doctor.js.map +1 -1
- package/dist/app/factory.d.ts +2 -0
- package/dist/app/factory.js +13 -2
- package/dist/app/factory.js.map +1 -1
- package/dist/app/init.d.ts +1 -5
- package/dist/app/init.js +1 -13
- package/dist/app/init.js.map +1 -1
- package/dist/app/options.d.ts +17 -0
- package/dist/app/options.js +78 -0
- package/dist/app/options.js.map +1 -0
- package/dist/app/run.d.ts +4 -20
- package/dist/app/run.js +22 -93
- package/dist/app/run.js.map +1 -1
- package/dist/app/runs.d.ts +4 -32
- package/dist/app/runs.js +9 -61
- package/dist/app/runs.js.map +1 -1
- package/dist/cli/application.d.ts +1 -1
- package/dist/cli/application.js +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/doctor.d.ts +1 -1
- package/dist/cli/doctor.js +1 -1
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/help.d.ts +1 -1
- package/dist/cli/help.js +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +1 -1
- package/dist/cli/launcher.d.ts +1 -1
- package/dist/cli/launcher.js +4 -4
- package/dist/cli/launcher.js.map +1 -1
- package/dist/cli/reporter.d.ts +1 -1
- package/dist/cli/reporter.js +1 -2
- package/dist/cli/reporter.js.map +1 -1
- package/dist/cli/run.d.ts +1 -5
- package/dist/cli/run.js +24 -11
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/ui.d.ts +1 -1
- package/dist/cli/ui.js +10 -3
- package/dist/cli/ui.js.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/system/factory.d.ts +1 -1
- package/dist/system/factory.js +1 -1
- package/dist/system/factory.js.map +1 -1
- package/dist/system/npm.d.ts +5 -0
- package/dist/system/npm.js +14 -0
- package/dist/system/npm.js.map +1 -0
- package/dist/system/templates.d.ts +1 -1
- package/dist/system/templates.js +1 -1
- package/package.json +7 -17
- package/dist/engine/metrics.d.ts +0 -45
- package/dist/engine/metrics.js +0 -60
- package/dist/engine/metrics.js.map +0 -1
- package/dist/engine/primitives.d.ts +0 -34
- package/dist/engine/primitives.js +0 -81
- package/dist/engine/primitives.js.map +0 -1
- package/dist/engine/profiles.d.ts +0 -53
- package/dist/engine/profiles.js +0 -117
- package/dist/engine/profiles.js.map +0 -1
- package/dist/engine/runner.d.ts +0 -13
- package/dist/engine/runner.js +0 -157
- package/dist/engine/runner.js.map +0 -1
- package/dist/engine/types.d.ts +0 -194
- package/dist/engine/types.js +0 -2
- package/dist/engine/types.js.map +0 -1
- package/dist/engine/workflow.d.ts +0 -18
- package/dist/engine/workflow.js +0 -196
- package/dist/engine/workflow.js.map +0 -1
- package/dist/system/process.d.ts +0 -21
- package/dist/system/process.js +0 -238
- package/dist/system/process.js.map +0 -1
- package/dist/system/runtimes/adapter.d.ts +0 -90
- package/dist/system/runtimes/adapter.js +0 -20
- package/dist/system/runtimes/adapter.js.map +0 -1
- package/dist/system/runtimes/agent-runtime.d.ts +0 -45
- package/dist/system/runtimes/agent-runtime.js +0 -184
- package/dist/system/runtimes/agent-runtime.js.map +0 -1
- package/dist/system/runtimes/claude-code.d.ts +0 -10
- package/dist/system/runtimes/claude-code.js +0 -383
- package/dist/system/runtimes/claude-code.js.map +0 -1
- package/dist/system/runtimes/inspect.d.ts +0 -25
- package/dist/system/runtimes/inspect.js +0 -129
- package/dist/system/runtimes/inspect.js.map +0 -1
- package/dist/system/runtimes/pi.d.ts +0 -7
- package/dist/system/runtimes/pi.js +0 -235
- package/dist/system/runtimes/pi.js.map +0 -1
- package/dist/system/runtimes/protocol.d.ts +0 -9
- package/dist/system/runtimes/protocol.js +0 -38
- package/dist/system/runtimes/protocol.js.map +0 -1
- package/dist/system/runtimes/registry.d.ts +0 -5
- package/dist/system/runtimes/registry.js +0 -5
- package/dist/system/runtimes/registry.js.map +0 -1
- package/dist/system/store.d.ts +0 -20
- package/dist/system/store.js +0 -126
- package/dist/system/store.js.map +0 -1
- package/dist/ui/server.d.ts +0 -8
- package/dist/ui/server.js +0 -111
- package/dist/ui/server.js.map +0 -1
- package/dist/ui/static/dashboard.js +0 -266
- package/dist/ui/static/follow.js +0 -67
- package/dist/ui/static/index.html +0 -20
- package/dist/ui/static/style.css +0 -166
- package/dist/ui/static/timeline.js +0 -180
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { RunState, Workflow, WorkflowDefinition } from "./types.js";
|
|
3
|
-
/** True for a workflow returned by `defineWorkflow`. */
|
|
4
|
-
export declare function isWorkflow(value: unknown): value is Workflow;
|
|
5
|
-
/** By default a run shows its validated data, never raw agent output. */
|
|
6
|
-
export declare function presentData(state: Readonly<RunState>): string[];
|
|
7
|
-
/**
|
|
8
|
-
* Validates a workflow when it is declared: graph, retry maximums, loops, agent
|
|
9
|
-
* stages and inputs. Agent profiles are returned with their defaults applied.
|
|
10
|
-
*/
|
|
11
|
-
export declare function defineWorkflow(definition: WorkflowDefinition): Workflow;
|
|
12
|
-
/** Whether a field takes an option given alone: a boolean, possibly optional or defaulted. */
|
|
13
|
-
export declare function isFlag(schema: z.ZodType): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Validates `factory run` options against the workflow's input object. An option
|
|
16
|
-
* given without a value is `true`, accepted only by a boolean field.
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseInput(workflow: Pick<Workflow, "name" | "input">, options: Record<string, string | boolean>): Record<string, unknown>;
|
package/dist/engine/workflow.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { profileSchema } from "./profiles.js";
|
|
3
|
-
/** Workflow and prompt names name files and directories. */
|
|
4
|
-
const FILE_NAME = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
5
|
-
/** A session name is a segment of session file names: it starts and ends alphanumeric. */
|
|
6
|
-
const SESSION = /^[a-zA-Z0-9](?:[a-zA-Z0-9_-]*[a-zA-Z0-9])?$/;
|
|
7
|
-
const OPTION = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
8
|
-
const GLOBAL_OPTIONS = ["json", "help", "max-cost-usd"];
|
|
9
|
-
const defined = new WeakSet();
|
|
10
|
-
/** True for a workflow returned by `defineWorkflow`. */
|
|
11
|
-
export function isWorkflow(value) {
|
|
12
|
-
return typeof value === "object" && value !== null && defined.has(value);
|
|
13
|
-
}
|
|
14
|
-
function graphProblems(definition) {
|
|
15
|
-
const { nodes, initial } = definition;
|
|
16
|
-
const problems = [];
|
|
17
|
-
const exists = (name) => Object.hasOwn(nodes, name);
|
|
18
|
-
if (!exists(initial))
|
|
19
|
-
problems.push(`initial stage ${initial} is not defined`);
|
|
20
|
-
for (const [name, node] of Object.entries(nodes)) {
|
|
21
|
-
// A correction counter is named `<stage>.<outcome>`.
|
|
22
|
-
if (name.includes("."))
|
|
23
|
-
problems.push(`stage ${name} must not contain "."`);
|
|
24
|
-
for (const outcome of node.stage.outcomes)
|
|
25
|
-
if (outcome.includes("."))
|
|
26
|
-
problems.push(`${name}: outcome ${outcome} must not contain "."`);
|
|
27
|
-
const routed = Object.keys(node.on);
|
|
28
|
-
for (const outcome of node.stage.outcomes)
|
|
29
|
-
if (!routed.includes(outcome))
|
|
30
|
-
problems.push(`${name}: outcome ${outcome} has no route`);
|
|
31
|
-
for (const outcome of routed) {
|
|
32
|
-
if (!node.stage.outcomes.includes(outcome))
|
|
33
|
-
problems.push(`${name}: route for unknown outcome ${outcome}`);
|
|
34
|
-
const edge = node.on[outcome];
|
|
35
|
-
if (edge === null || edge === undefined)
|
|
36
|
-
continue;
|
|
37
|
-
const target = typeof edge === "string" ? edge : edge.to;
|
|
38
|
-
if (!exists(target))
|
|
39
|
-
problems.push(`${name}.${outcome}: unknown target ${target}`);
|
|
40
|
-
if (typeof edge === "object" &&
|
|
41
|
-
!(Number.isInteger(edge.max) && edge.max >= 1 && edge.max <= 100))
|
|
42
|
-
problems.push(`${name}.${outcome}: retry maximum must be an integer from 1 to 100, got ${edge.max}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const loop = loopWithoutRetry(nodes);
|
|
46
|
-
if (loop)
|
|
47
|
-
problems.push(`loop without retry: ${loop.join(" → ")}`);
|
|
48
|
-
return problems;
|
|
49
|
-
}
|
|
50
|
-
/** A cycle of plain routes: nothing would bound how often it runs. */
|
|
51
|
-
function loopWithoutRetry(nodes) {
|
|
52
|
-
const done = new Set();
|
|
53
|
-
const path = [];
|
|
54
|
-
const visit = (name) => {
|
|
55
|
-
if (done.has(name))
|
|
56
|
-
return undefined;
|
|
57
|
-
const start = path.indexOf(name);
|
|
58
|
-
if (start >= 0)
|
|
59
|
-
return [...path.slice(start), name];
|
|
60
|
-
path.push(name);
|
|
61
|
-
for (const edge of Object.values(nodes[name]?.on ?? {}))
|
|
62
|
-
if (typeof edge === "string" && Object.hasOwn(nodes, edge)) {
|
|
63
|
-
const loop = visit(edge);
|
|
64
|
-
if (loop)
|
|
65
|
-
return loop;
|
|
66
|
-
}
|
|
67
|
-
path.pop();
|
|
68
|
-
done.add(name);
|
|
69
|
-
return undefined;
|
|
70
|
-
};
|
|
71
|
-
for (const name of Object.keys(nodes)) {
|
|
72
|
-
const loop = visit(name);
|
|
73
|
-
if (loop)
|
|
74
|
-
return loop;
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
/** Each agent stage: profile, prompt name and session name. */
|
|
79
|
-
function agentProblems(definition, agents) {
|
|
80
|
-
const problems = [];
|
|
81
|
-
/** Stages by fixed session name, to keep each conversation on one runtime. */
|
|
82
|
-
const sessions = new Map();
|
|
83
|
-
for (const [name, node] of Object.entries(definition.nodes)) {
|
|
84
|
-
const declared = node.stage.agent;
|
|
85
|
-
if (!declared)
|
|
86
|
-
continue;
|
|
87
|
-
const prompt = declared.prompt ?? name;
|
|
88
|
-
if (!FILE_NAME.test(prompt))
|
|
89
|
-
problems.push(`${name}: prompt name ${prompt} must be letters, digits, - or _`);
|
|
90
|
-
const { session } = declared;
|
|
91
|
-
if (typeof session !== "function" && !SESSION.test(session ?? name))
|
|
92
|
-
problems.push(`${name}: session ${session ?? `${name} (the stage name by default)`} must start and end with a letter or digit and contain only letters, digits, - or _`);
|
|
93
|
-
const parsed = profileSchema.safeParse(declared.profile);
|
|
94
|
-
if (!parsed.success) {
|
|
95
|
-
for (const issue of parsed.error.issues)
|
|
96
|
-
problems.push(`${name}.profile${issue.path.map((key) => `.${String(key)}`).join("")}: ${issue.message}`);
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
agents[name] = { profile: parsed.data, prompt };
|
|
100
|
-
if (typeof session !== "function") {
|
|
101
|
-
const fixed = session ?? name;
|
|
102
|
-
sessions.set(fixed, [...(sessions.get(fixed) ?? []), name]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
for (const [session, stages] of sessions) {
|
|
106
|
-
const runtimes = new Set(stages.map((stage) => agents[stage]?.profile.runtime));
|
|
107
|
-
if (runtimes.size > 1)
|
|
108
|
-
problems.push(`session ${session} is used by stages on different runtimes: ${stages.map((stage) => `${stage} (${agents[stage]?.profile.runtime})`).join(", ")}`);
|
|
109
|
-
}
|
|
110
|
-
return problems;
|
|
111
|
-
}
|
|
112
|
-
function inputProblems(input) {
|
|
113
|
-
if (input === undefined)
|
|
114
|
-
return [];
|
|
115
|
-
if (!(input instanceof z.ZodObject))
|
|
116
|
-
return ["input must be a z.object"];
|
|
117
|
-
return Object.keys(input.shape).flatMap((name) => GLOBAL_OPTIONS.includes(name)
|
|
118
|
-
? [`input ${name} conflicts with the global --${name} option`]
|
|
119
|
-
: OPTION.test(name)
|
|
120
|
-
? []
|
|
121
|
-
: [`input ${name} is not a valid option name`]);
|
|
122
|
-
}
|
|
123
|
-
/** By default a run shows its validated data, never raw agent output. */
|
|
124
|
-
export function presentData(state) {
|
|
125
|
-
return [JSON.stringify(state.data, null, 2)];
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Validates a workflow when it is declared: graph, retry maximums, loops, agent
|
|
129
|
-
* stages and inputs. Agent profiles are returned with their defaults applied.
|
|
130
|
-
*/
|
|
131
|
-
export function defineWorkflow(definition) {
|
|
132
|
-
if (!FILE_NAME.test(definition.name))
|
|
133
|
-
throw new Error(`Invalid workflow ${definition.name}: name must be letters, digits, - or _`);
|
|
134
|
-
const agents = {};
|
|
135
|
-
const { maxCostUsd } = definition;
|
|
136
|
-
const problems = [
|
|
137
|
-
...(maxCostUsd === undefined ||
|
|
138
|
-
(typeof maxCostUsd === "number" &&
|
|
139
|
-
Number.isFinite(maxCostUsd) &&
|
|
140
|
-
maxCostUsd > 0)
|
|
141
|
-
? []
|
|
142
|
-
: [
|
|
143
|
-
`maxCostUsd must be a positive number of USD, got ${String(maxCostUsd)}`,
|
|
144
|
-
]),
|
|
145
|
-
...graphProblems(definition),
|
|
146
|
-
...agentProblems(definition, agents),
|
|
147
|
-
...inputProblems(definition.input),
|
|
148
|
-
];
|
|
149
|
-
if (problems.length)
|
|
150
|
-
throw new Error(`Invalid workflow ${definition.name}: ${problems.join("; ")}`);
|
|
151
|
-
const workflow = {
|
|
152
|
-
...definition,
|
|
153
|
-
agents,
|
|
154
|
-
presentResult: definition.presentResult ?? presentData,
|
|
155
|
-
};
|
|
156
|
-
defined.add(workflow);
|
|
157
|
-
return workflow;
|
|
158
|
-
}
|
|
159
|
-
/** Whether a field takes an option given alone: a boolean, possibly optional or defaulted. */
|
|
160
|
-
export function isFlag(schema) {
|
|
161
|
-
let def = schema.def;
|
|
162
|
-
while (def.innerType &&
|
|
163
|
-
["optional", "nullable", "default"].includes(def.type))
|
|
164
|
-
def = def.innerType.def;
|
|
165
|
-
return def.type === "boolean";
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Validates `factory run` options against the workflow's input object. An option
|
|
169
|
-
* given without a value is `true`, accepted only by a boolean field.
|
|
170
|
-
*/
|
|
171
|
-
export function parseInput(workflow, options) {
|
|
172
|
-
const input = workflow.input ?? z.object({});
|
|
173
|
-
const shape = input.shape;
|
|
174
|
-
const valueless = Object.keys(options).filter((name) => {
|
|
175
|
-
const field = Object.hasOwn(shape, name) ? shape[name] : undefined;
|
|
176
|
-
return options[name] === true && field !== undefined && !isFlag(field);
|
|
177
|
-
});
|
|
178
|
-
const given = Object.fromEntries(Object.entries(options).filter(([name]) => !valueless.includes(name)));
|
|
179
|
-
const parsed = input.strict().safeParse(given);
|
|
180
|
-
if (parsed.success && !valueless.length)
|
|
181
|
-
return parsed.data;
|
|
182
|
-
const issues = parsed.success ? [] : parsed.error.issues;
|
|
183
|
-
const problems = valueless.map((name) => `--${name}: missing value`);
|
|
184
|
-
problems.push(...issues.flatMap((issue) => {
|
|
185
|
-
if (issue.code === "unrecognized_keys")
|
|
186
|
-
return issue.keys.map((key) => `unknown option --${key}`);
|
|
187
|
-
const name = String(issue.path[0] ?? "");
|
|
188
|
-
if (valueless.includes(name))
|
|
189
|
-
return [];
|
|
190
|
-
return Object.hasOwn(options, name)
|
|
191
|
-
? [`--${name}: ${issue.message}`]
|
|
192
|
-
: [`missing option --${name}`];
|
|
193
|
-
}));
|
|
194
|
-
throw new Error(`Invalid input for ${workflow.name}: ${problems.join("; ")}`);
|
|
195
|
-
}
|
|
196
|
-
//# sourceMappingURL=workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/engine/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAS9C,4DAA4D;AAC5D,MAAM,SAAS,GAAG,6BAA6B,CAAC;AAChD,0FAA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CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC"}
|
package/dist/system/process.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export declare class ProcessStartError extends Error {
|
|
2
|
-
constructor(executable: string, cause: Error);
|
|
3
|
-
}
|
|
4
|
-
export declare class ProcessInterruptedError extends Error {
|
|
5
|
-
constructor(signal: NodeJS.Signals, executable: string);
|
|
6
|
-
}
|
|
7
|
-
/** Kills every running child's process group at once, before a forced exit. */
|
|
8
|
-
export declare function killProcessGroups(): void;
|
|
9
|
-
/** Runs `work` with `dir` as the process's working directory, then restores the previous one. */
|
|
10
|
-
export declare function inDirectory<T>(dir: string, work: () => Promise<T>): Promise<T>;
|
|
11
|
-
/**
|
|
12
|
-
* Runs an executable without a shell. A failure terminates the entire child group
|
|
13
|
-
* and settles only after the child closes and the TERM→KILL grace period finishes.
|
|
14
|
-
*/
|
|
15
|
-
export declare function runProcess(command: string[], cwd: string, timeoutMs: number, onLine?: (line: string) => void, stdin?: string): Promise<{
|
|
16
|
-
exitCode: number;
|
|
17
|
-
stdout: string;
|
|
18
|
-
stderr: string;
|
|
19
|
-
stdoutTruncated: boolean;
|
|
20
|
-
stderrTruncated: boolean;
|
|
21
|
-
}>;
|
package/dist/system/process.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
const MAX_CAPTURE_BYTES = 2 * 1024 * 1024;
|
|
3
|
-
const MAX_LINE_BYTES = 32 * 1024 * 1024;
|
|
4
|
-
const KILL_GRACE_MS = 1_000;
|
|
5
|
-
export class ProcessStartError extends Error {
|
|
6
|
-
constructor(executable, cause) {
|
|
7
|
-
super(`Could not start ${executable}: ${cause.message}`, { cause });
|
|
8
|
-
this.name = "ProcessStartError";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export class ProcessInterruptedError extends Error {
|
|
12
|
-
constructor(signal, executable) {
|
|
13
|
-
super(`Process interrupted by ${signal}: ${executable}`);
|
|
14
|
-
this.name = "ProcessInterruptedError";
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
class BoundedCapture {
|
|
18
|
-
#chunks = [];
|
|
19
|
-
#length = 0;
|
|
20
|
-
#dropped = false;
|
|
21
|
-
append(chunk) {
|
|
22
|
-
if (chunk.length === 0)
|
|
23
|
-
return;
|
|
24
|
-
if (chunk.length >= MAX_CAPTURE_BYTES) {
|
|
25
|
-
this.#dropped ||= this.#length > 0 || chunk.length > MAX_CAPTURE_BYTES;
|
|
26
|
-
this.#chunks = [chunk.subarray(chunk.length - MAX_CAPTURE_BYTES)];
|
|
27
|
-
this.#length = MAX_CAPTURE_BYTES;
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
this.#chunks.push(chunk);
|
|
31
|
-
this.#length += chunk.length;
|
|
32
|
-
while (this.#length > MAX_CAPTURE_BYTES) {
|
|
33
|
-
const first = this.#chunks.shift();
|
|
34
|
-
if (!first)
|
|
35
|
-
break;
|
|
36
|
-
this.#length -= first.length;
|
|
37
|
-
this.#dropped = true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
get truncated() {
|
|
41
|
-
return this.#dropped;
|
|
42
|
-
}
|
|
43
|
-
text() {
|
|
44
|
-
const prefix = this.#dropped ? "[earlier process output truncated]\n" : "";
|
|
45
|
-
return prefix + Buffer.concat(this.#chunks, this.#length).toString("utf8");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function signalGroup(child, signal) {
|
|
49
|
-
if (!child.pid)
|
|
50
|
-
return;
|
|
51
|
-
if (process.platform !== "win32") {
|
|
52
|
-
try {
|
|
53
|
-
process.kill(-child.pid, signal);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
// The process group can already be gone.
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
child.kill(signal);
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// The child can already be gone.
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function groupStillExists(child) {
|
|
68
|
-
if (process.platform === "win32" || !child.pid)
|
|
69
|
-
return false;
|
|
70
|
-
try {
|
|
71
|
-
process.kill(-child.pid, 0);
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/** Children still running, so that a forced exit does not leave them behind. */
|
|
79
|
-
const running = new Set();
|
|
80
|
-
/** Kills every running child's process group at once, before a forced exit. */
|
|
81
|
-
export function killProcessGroups() {
|
|
82
|
-
for (const child of running)
|
|
83
|
-
signalGroup(child, "SIGKILL");
|
|
84
|
-
}
|
|
85
|
-
/** Runs `work` with `dir` as the process's working directory, then restores the previous one. */
|
|
86
|
-
export async function inDirectory(dir, work) {
|
|
87
|
-
const previous = process.cwd();
|
|
88
|
-
process.chdir(dir);
|
|
89
|
-
try {
|
|
90
|
-
return await work();
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
process.chdir(previous);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Runs an executable without a shell. A failure terminates the entire child group
|
|
98
|
-
* and settles only after the child closes and the TERM→KILL grace period finishes.
|
|
99
|
-
*/
|
|
100
|
-
export async function runProcess(command, cwd, timeoutMs, onLine, stdin) {
|
|
101
|
-
if (command.length === 0 || !command[0])
|
|
102
|
-
throw new Error("Process command must include an executable");
|
|
103
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
104
|
-
throw new Error("Process timeout must be positive");
|
|
105
|
-
const executable = command[0];
|
|
106
|
-
return new Promise((resolve, reject) => {
|
|
107
|
-
const child = spawn(executable, command.slice(1), {
|
|
108
|
-
cwd,
|
|
109
|
-
detached: process.platform !== "win32",
|
|
110
|
-
shell: false,
|
|
111
|
-
stdio: [stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
112
|
-
});
|
|
113
|
-
running.add(child);
|
|
114
|
-
const stdout = new BoundedCapture();
|
|
115
|
-
const stderr = new BoundedCapture();
|
|
116
|
-
let pending = Buffer.alloc(0);
|
|
117
|
-
let failure;
|
|
118
|
-
let closeResult;
|
|
119
|
-
let terminating = false;
|
|
120
|
-
let killSent = false;
|
|
121
|
-
let killTimer;
|
|
122
|
-
let settled = false;
|
|
123
|
-
const onParentSignal = (signal) => {
|
|
124
|
-
requestTermination(new ProcessInterruptedError(signal, executable));
|
|
125
|
-
};
|
|
126
|
-
const cleanup = () => {
|
|
127
|
-
running.delete(child);
|
|
128
|
-
clearTimeout(timeout);
|
|
129
|
-
if (killTimer)
|
|
130
|
-
clearTimeout(killTimer);
|
|
131
|
-
process.removeListener("SIGINT", onParentSignal);
|
|
132
|
-
process.removeListener("SIGTERM", onParentSignal);
|
|
133
|
-
};
|
|
134
|
-
const settle = () => {
|
|
135
|
-
if (settled || !closeResult || (terminating && !killSent))
|
|
136
|
-
return;
|
|
137
|
-
settled = true;
|
|
138
|
-
cleanup();
|
|
139
|
-
if (failure) {
|
|
140
|
-
reject(failure);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
resolve({
|
|
144
|
-
exitCode: closeResult.code ?? (closeResult.signal ? 1 : 0),
|
|
145
|
-
stdout: stdout.text(),
|
|
146
|
-
stderr: stderr.text(),
|
|
147
|
-
stdoutTruncated: stdout.truncated,
|
|
148
|
-
stderrTruncated: stderr.truncated,
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
const sendKill = () => {
|
|
152
|
-
killTimer = undefined;
|
|
153
|
-
killSent = true;
|
|
154
|
-
signalGroup(child, "SIGKILL");
|
|
155
|
-
settle();
|
|
156
|
-
};
|
|
157
|
-
const requestTermination = (error) => {
|
|
158
|
-
if (!failure || error instanceof ProcessInterruptedError)
|
|
159
|
-
failure = error;
|
|
160
|
-
if (terminating)
|
|
161
|
-
return;
|
|
162
|
-
terminating = true;
|
|
163
|
-
signalGroup(child, "SIGTERM");
|
|
164
|
-
killTimer = setTimeout(sendKill, KILL_GRACE_MS);
|
|
165
|
-
};
|
|
166
|
-
const timeout = setTimeout(() => {
|
|
167
|
-
requestTermination(new Error(`Process timed out after ${timeoutMs}ms: ${executable}`));
|
|
168
|
-
}, timeoutMs);
|
|
169
|
-
timeout.unref();
|
|
170
|
-
process.once("SIGINT", onParentSignal);
|
|
171
|
-
process.once("SIGTERM", onParentSignal);
|
|
172
|
-
child.once("error", (error) => {
|
|
173
|
-
requestTermination(new ProcessStartError(executable, error));
|
|
174
|
-
});
|
|
175
|
-
if (stdin !== undefined) {
|
|
176
|
-
if (!child.stdin)
|
|
177
|
-
requestTermination(new Error("Process stdin is unavailable"));
|
|
178
|
-
else {
|
|
179
|
-
child.stdin.once("error", (error) => {
|
|
180
|
-
requestTermination(new Error(`Could not write process stdin: ${error.message}`, {
|
|
181
|
-
cause: error,
|
|
182
|
-
}));
|
|
183
|
-
});
|
|
184
|
-
child.stdin.end(stdin);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (!child.stdout || !child.stderr)
|
|
188
|
-
requestTermination(new Error("Process output streams are unavailable"));
|
|
189
|
-
child.stdout?.on("data", (chunk) => {
|
|
190
|
-
stdout.append(chunk);
|
|
191
|
-
if (!onLine || failure)
|
|
192
|
-
return;
|
|
193
|
-
pending = Buffer.concat([pending, chunk]);
|
|
194
|
-
while (!failure) {
|
|
195
|
-
const newline = pending.indexOf(0x0a);
|
|
196
|
-
if (newline < 0)
|
|
197
|
-
break;
|
|
198
|
-
const line = pending
|
|
199
|
-
.subarray(0, newline)
|
|
200
|
-
.toString("utf8")
|
|
201
|
-
.replace(/\r$/, "");
|
|
202
|
-
pending = pending.subarray(newline + 1);
|
|
203
|
-
if (Buffer.byteLength(line) > MAX_LINE_BYTES) {
|
|
204
|
-
requestTermination(new Error(`Process output line exceeded ${MAX_LINE_BYTES} byte limit`));
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
try {
|
|
208
|
-
onLine(line);
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
requestTermination(error instanceof Error ? error : new Error(String(error)));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (!failure && pending.length > MAX_LINE_BYTES)
|
|
215
|
-
requestTermination(new Error(`Process output line exceeded ${MAX_LINE_BYTES} byte limit`));
|
|
216
|
-
});
|
|
217
|
-
child.stderr?.on("data", (chunk) => stderr.append(chunk));
|
|
218
|
-
child.once("close", (code, signal) => {
|
|
219
|
-
closeResult = { code, signal };
|
|
220
|
-
if (!failure && groupStillExists(child))
|
|
221
|
-
requestTermination(new Error(`Process group remained after ${executable} exited`));
|
|
222
|
-
if (!failure && onLine && pending.length > 0) {
|
|
223
|
-
if (pending.length > MAX_LINE_BYTES)
|
|
224
|
-
requestTermination(new Error(`Process output line exceeded ${MAX_LINE_BYTES} byte limit`));
|
|
225
|
-
else {
|
|
226
|
-
try {
|
|
227
|
-
onLine(pending.toString("utf8").replace(/\r$/, ""));
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
requestTermination(error instanceof Error ? error : new Error(String(error)));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
settle();
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
//# sourceMappingURL=process.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/system/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC1C,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACxC,MAAM,aAAa,GAAG,KAAK,CAAC;AAE5B,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,UAAkB,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P,gCAAgC,cAAc,aAAa,CAC5D,CACF,CAAC;qBACC,CAAC;oBACJ,IAAI,CAAC;wBACH,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;oBACtD,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,kBAAkB,CAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
import type { AgentUsage, TokenCounts } from "../../engine/metrics.js";
|
|
3
|
-
import type { ResolvedProfile, Runtime } from "../../engine/profiles.js";
|
|
4
|
-
/** A runtime's profile, with its defaults applied. */
|
|
5
|
-
export type ProfileOf<R extends Runtime> = Extract<ResolvedProfile, {
|
|
6
|
-
runtime: R;
|
|
7
|
-
}>;
|
|
8
|
-
/** One agent call, as a runtime prepares it. */
|
|
9
|
-
export interface RuntimeCall<R extends Runtime> {
|
|
10
|
-
profile: ProfileOf<R>;
|
|
11
|
-
/** The workflow's prompt, appended to the runtime's own system prompt. */
|
|
12
|
-
systemPrompt: string;
|
|
13
|
-
/** The conversation within the run. */
|
|
14
|
-
session: string;
|
|
15
|
-
/** The run, and the directory where it keeps this runtime's sessions. */
|
|
16
|
-
sessions: {
|
|
17
|
-
runId: string;
|
|
18
|
-
directory: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/** What an output line of a runtime means for the call, the same for every runtime. */
|
|
22
|
-
export type RuntimeEvent = {
|
|
23
|
-
type: "tool";
|
|
24
|
-
id: string;
|
|
25
|
-
name: string;
|
|
26
|
-
status: "started" | "completed" | "failed";
|
|
27
|
-
}
|
|
28
|
-
/** A model response's tokens as the call goes, before the figures announced at its end. */
|
|
29
|
-
| {
|
|
30
|
-
type: "response";
|
|
31
|
-
tokens: TokenCounts;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* A measure as the runtime announces it: one response's final figures, or its
|
|
35
|
-
* session's total so far; `undefined` when nothing measurable was announced.
|
|
36
|
-
*/
|
|
37
|
-
| {
|
|
38
|
-
type: "usage";
|
|
39
|
-
scope: "response" | "session";
|
|
40
|
-
usage: AgentUsage | undefined;
|
|
41
|
-
}
|
|
42
|
-
/** A customization of the session that does not change what the agent can do. */
|
|
43
|
-
| {
|
|
44
|
-
type: "warning";
|
|
45
|
-
message: string;
|
|
46
|
-
}
|
|
47
|
-
/** The runtime reported that the call failed: it stops there. */
|
|
48
|
-
| {
|
|
49
|
-
type: "failure";
|
|
50
|
-
message: string;
|
|
51
|
-
}
|
|
52
|
-
/** The agent's final text. */
|
|
53
|
-
| {
|
|
54
|
-
type: "result";
|
|
55
|
-
text: string;
|
|
56
|
-
};
|
|
57
|
-
/** A prepared call: the arguments after the executable, and the reader of its output. */
|
|
58
|
-
export interface RuntimeProcess {
|
|
59
|
-
args: string[];
|
|
60
|
-
/** Reads one parsed output line; throws on output the adapter cannot rely on. */
|
|
61
|
-
read(event: unknown): RuntimeEvent[];
|
|
62
|
-
}
|
|
63
|
-
/** The connection a profile would use: connected or not, and which one, never the account. */
|
|
64
|
-
export interface Connection {
|
|
65
|
-
connected: boolean;
|
|
66
|
-
detail: string;
|
|
67
|
-
}
|
|
68
|
-
/** What factory needs from an agent runtime. */
|
|
69
|
-
export interface RuntimeAdapter<R extends Runtime> {
|
|
70
|
-
name: R;
|
|
71
|
-
/** As the operator reads it. */
|
|
72
|
-
label: string;
|
|
73
|
-
/** Found in the PATH. */
|
|
74
|
-
executable: string;
|
|
75
|
-
/** The oldest version validated by a real call; `--version` prints it first. */
|
|
76
|
-
minimumVersion: string;
|
|
77
|
-
/** The command that reports a profile's connection without a provider request, and how to read its output. */
|
|
78
|
-
connection(profile: ProfileOf<R>): {
|
|
79
|
-
args: string[];
|
|
80
|
-
read(stdout: string): Connection;
|
|
81
|
-
};
|
|
82
|
-
/** The model a call is recorded with. */
|
|
83
|
-
model(profile: ProfileOf<R>): string;
|
|
84
|
-
start(call: RuntimeCall<R>): Promise<RuntimeProcess>;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* An output event the adapter relies on, validated: a missing or malformed field
|
|
88
|
-
* stops the call with the event and the field, rather than being misread.
|
|
89
|
-
*/
|
|
90
|
-
export declare function parseEvent<T>(label: string, schema: z.ZodType<T>, event: unknown): T;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An output event the adapter relies on, validated: a missing or malformed field
|
|
3
|
-
* stops the call with the event and the field, rather than being misread.
|
|
4
|
-
*/
|
|
5
|
-
export function parseEvent(label, schema, event) {
|
|
6
|
-
const parsed = schema.safeParse(event);
|
|
7
|
-
if (parsed.success)
|
|
8
|
-
return parsed.data;
|
|
9
|
-
const type = typeof event === "object" &&
|
|
10
|
-
event !== null &&
|
|
11
|
-
"type" in event &&
|
|
12
|
-
typeof event.type === "string"
|
|
13
|
-
? `${event.type} `
|
|
14
|
-
: "";
|
|
15
|
-
const issues = parsed.error.issues
|
|
16
|
-
.map(({ path, message }) => `${path.join(".") || "value"}: ${message}`)
|
|
17
|
-
.join("; ");
|
|
18
|
-
throw new Error(`${label} emitted an unexpected ${type}event: ${issues}`);
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/system/runtimes/adapter.ts"],"names":[],"mappings":"AA+EA;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,KAAa,EACb,MAAoB,EACpB,KAAc;IAEd,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACvC,MAAM,IAAI,GACR,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC5B,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG;QAClB,CAAC,CAAC,EAAE,CAAC;IACT,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;SAC/B,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;SACtE,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,0BAA0B,IAAI,UAAU,MAAM,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|