@clemrig/factory 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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.js +1 -1
- 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 +2 -34
- package/dist/app/runs.js +3 -63
- 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/status.js +3 -3
- package/dist/cli/status.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/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,45 +0,0 @@
|
|
|
1
|
-
import { type UsageReport } from "../../engine/metrics.js";
|
|
2
|
-
import { type Runtime } from "../../engine/profiles.js";
|
|
3
|
-
import type { AgentPort, AgentRequest, RecordActivity } from "../../engine/types.js";
|
|
4
|
-
import type { RuntimeAdapter, RuntimeCall } from "./adapter.js";
|
|
5
|
-
export interface CallOptions {
|
|
6
|
-
/** The repository the agent works in. */
|
|
7
|
-
repo: string;
|
|
8
|
-
/** The executable's absolute path; by default its name, looked up in the PATH. */
|
|
9
|
-
executable?: string;
|
|
10
|
-
/** Records the call's activity under the calling stage. */
|
|
11
|
-
record?: RecordActivity;
|
|
12
|
-
/** Each measure as the runtime announces it; one unmeasured report when a started call announced none. */
|
|
13
|
-
onUsage?: (report: UsageReport) => void | Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* One agent call, the same for every runtime: the request goes through standard
|
|
17
|
-
* input, the adapter reads each output line, and the final text is the result.
|
|
18
|
-
* The call's activity is recorded as it goes; a call that started always reports
|
|
19
|
-
* its measures, even when it fails.
|
|
20
|
-
*/
|
|
21
|
-
export declare function runCall<R extends Runtime>(adapter: RuntimeAdapter<R>, call: RuntimeCall<R> & {
|
|
22
|
-
context: unknown;
|
|
23
|
-
schema: Record<string, unknown>;
|
|
24
|
-
}, options: CallOptions): Promise<unknown>;
|
|
25
|
-
export interface AgentRuntimeOptions extends Pick<CallOptions, "onUsage"> {
|
|
26
|
-
/** The repository agents work in. */
|
|
27
|
-
dir: string;
|
|
28
|
-
/** Relative skill, extension and MCP command paths of profiles belong to it. */
|
|
29
|
-
factoryDir: string;
|
|
30
|
-
/** Prompt texts by name. */
|
|
31
|
-
prompts: Record<string, string>;
|
|
32
|
-
/** The run, whose directory keeps each runtime's sessions in a subdirectory of its name. */
|
|
33
|
-
run: {
|
|
34
|
-
id: string;
|
|
35
|
-
directory: string;
|
|
36
|
-
};
|
|
37
|
-
/** The executables checked before the run, by absolute path. */
|
|
38
|
-
executables?: Partial<Record<Runtime, string>>;
|
|
39
|
-
}
|
|
40
|
-
/** Validates each request's profile, then runs it on the runtime the profile selects, with its named prompt. */
|
|
41
|
-
export declare class AgentRuntime implements AgentPort {
|
|
42
|
-
#private;
|
|
43
|
-
constructor(options: AgentRuntimeOptions);
|
|
44
|
-
execute(request: AgentRequest, record?: RecordActivity): Promise<unknown>;
|
|
45
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { mkdir } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
3
|
-
import { sumUsage, } from "../../engine/metrics.js";
|
|
4
|
-
import { resolveProfile, } from "../../engine/profiles.js";
|
|
5
|
-
import { ProcessStartError, runProcess } from "../process.js";
|
|
6
|
-
import { agentPrompt, parseAgentJson } from "./protocol.js";
|
|
7
|
-
import { runtimes } from "./registry.js";
|
|
8
|
-
/** The figures announced for the call: its session's total, or the sum of its responses. */
|
|
9
|
-
function callUsage(reports) {
|
|
10
|
-
const session = reports.findLast((report) => report.scope === "session" && report.usage);
|
|
11
|
-
if (session?.usage)
|
|
12
|
-
return { scope: "session", usage: session.usage };
|
|
13
|
-
const responses = reports.flatMap(({ usage }) => (usage ? [usage] : []));
|
|
14
|
-
return responses.length ? { scope: "call", usage: sumUsage(responses) } : {};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* One agent call, the same for every runtime: the request goes through standard
|
|
18
|
-
* input, the adapter reads each output line, and the final text is the result.
|
|
19
|
-
* The call's activity is recorded as it goes; a call that started always reports
|
|
20
|
-
* its measures, even when it fails.
|
|
21
|
-
*/
|
|
22
|
-
export async function runCall(adapter, call, options) {
|
|
23
|
-
const { label } = adapter;
|
|
24
|
-
const { record, onUsage } = options;
|
|
25
|
-
const session = `${adapter.name}:${call.session}`;
|
|
26
|
-
await mkdir(call.sessions.directory, { recursive: true, mode: 0o700 });
|
|
27
|
-
const started = await adapter.start(call);
|
|
28
|
-
// A request that cannot be written fails before the call starts.
|
|
29
|
-
const request = agentPrompt(call);
|
|
30
|
-
record?.({
|
|
31
|
-
kind: "call",
|
|
32
|
-
status: "started",
|
|
33
|
-
runtime: adapter.name,
|
|
34
|
-
model: adapter.model(call.profile),
|
|
35
|
-
session: call.session,
|
|
36
|
-
});
|
|
37
|
-
const reports = [];
|
|
38
|
-
const tools = new Map();
|
|
39
|
-
let text;
|
|
40
|
-
let running = true;
|
|
41
|
-
let succeeded = false;
|
|
42
|
-
try {
|
|
43
|
-
const exit = await runProcess([options.executable ?? adapter.executable, ...started.args], options.repo, call.profile.timeoutMs, (line) => {
|
|
44
|
-
if (!line)
|
|
45
|
-
return;
|
|
46
|
-
let event;
|
|
47
|
-
try {
|
|
48
|
-
event = JSON.parse(line);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
throw new Error(`${label} emitted invalid JSONL output`);
|
|
52
|
-
}
|
|
53
|
-
for (const item of started.read(event))
|
|
54
|
-
switch (item.type) {
|
|
55
|
-
case "tool": {
|
|
56
|
-
const { id, name, status } = item;
|
|
57
|
-
if (status === "started") {
|
|
58
|
-
tools.set(id, Date.now());
|
|
59
|
-
record?.({ kind: "tool", id, name, status });
|
|
60
|
-
}
|
|
61
|
-
else
|
|
62
|
-
record?.({
|
|
63
|
-
kind: "tool",
|
|
64
|
-
id,
|
|
65
|
-
name,
|
|
66
|
-
status,
|
|
67
|
-
durationMs: Date.now() - (tools.get(id) ?? Date.now()),
|
|
68
|
-
});
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case "response":
|
|
72
|
-
record?.({
|
|
73
|
-
kind: "response",
|
|
74
|
-
tokens: item.tokens,
|
|
75
|
-
provisional: true,
|
|
76
|
-
});
|
|
77
|
-
break;
|
|
78
|
-
case "usage":
|
|
79
|
-
reports.push({ session, scope: item.scope, usage: item.usage });
|
|
80
|
-
if (item.scope === "response" && item.usage) {
|
|
81
|
-
const { costUsd, ...tokens } = item.usage;
|
|
82
|
-
record?.({
|
|
83
|
-
kind: "response",
|
|
84
|
-
tokens,
|
|
85
|
-
costUsd,
|
|
86
|
-
provisional: false,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
break;
|
|
90
|
-
case "warning":
|
|
91
|
-
record?.({ kind: "warning", message: item.message });
|
|
92
|
-
break;
|
|
93
|
-
case "failure":
|
|
94
|
-
throw new Error(item.message);
|
|
95
|
-
case "result":
|
|
96
|
-
text = item.text;
|
|
97
|
-
}
|
|
98
|
-
}, request);
|
|
99
|
-
if (exit.exitCode !== 0)
|
|
100
|
-
throw new Error(`${label} exited with code ${exit.exitCode}: ${exit.stderr.trim() || "no error output"}`);
|
|
101
|
-
if (text === undefined)
|
|
102
|
-
throw new Error(`${label} completed without a final result`);
|
|
103
|
-
succeeded = true;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
if (error instanceof ProcessStartError)
|
|
107
|
-
running = false;
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
for (const report of reports)
|
|
112
|
-
await onUsage?.(report);
|
|
113
|
-
if (running && !reports.length)
|
|
114
|
-
await onUsage?.({ session, scope: "response", usage: undefined });
|
|
115
|
-
record?.({
|
|
116
|
-
kind: "call",
|
|
117
|
-
status: succeeded ? "completed" : "failed",
|
|
118
|
-
runtime: adapter.name,
|
|
119
|
-
...callUsage(reports),
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
return parseAgentJson(text);
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
// The workflow's gate owns output-format feedback and retry routing.
|
|
127
|
-
return text;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/** Relative skill, extension and MCP command paths belong to `.factory/`; a bare command stays a PATH lookup. */
|
|
131
|
-
function resolvePaths(profile, factoryDir) {
|
|
132
|
-
if (profile.runtime === "pi")
|
|
133
|
-
return {
|
|
134
|
-
...profile,
|
|
135
|
-
skills: profile.skills.map((path) => resolve(factoryDir, path)),
|
|
136
|
-
extensions: profile.extensions.map((path) => resolve(factoryDir, path)),
|
|
137
|
-
};
|
|
138
|
-
const command = (value) => value.includes("/") && !isAbsolute(value)
|
|
139
|
-
? resolve(factoryDir, value)
|
|
140
|
-
: value;
|
|
141
|
-
return {
|
|
142
|
-
...profile,
|
|
143
|
-
mcpServers: Object.fromEntries(Object.entries(profile.mcpServers).map(([name, server]) => [
|
|
144
|
-
name,
|
|
145
|
-
{ ...server, command: command(server.command) },
|
|
146
|
-
])),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
/** Validates each request's profile, then runs it on the runtime the profile selects, with its named prompt. */
|
|
150
|
-
export class AgentRuntime {
|
|
151
|
-
#options;
|
|
152
|
-
constructor(options) {
|
|
153
|
-
this.#options = options;
|
|
154
|
-
}
|
|
155
|
-
async execute(request, record) {
|
|
156
|
-
const { dir, factoryDir, prompts, run, onUsage, executables } = this.#options;
|
|
157
|
-
const systemPrompt = Object.hasOwn(prompts, request.prompt)
|
|
158
|
-
? prompts[request.prompt]
|
|
159
|
-
: undefined;
|
|
160
|
-
if (systemPrompt === undefined)
|
|
161
|
-
throw new Error(`No prompt loaded: ${request.prompt}`);
|
|
162
|
-
const profile = resolvePaths(resolveProfile(request.profile), factoryDir);
|
|
163
|
-
const options = {
|
|
164
|
-
repo: dir,
|
|
165
|
-
executable: executables?.[profile.runtime],
|
|
166
|
-
record,
|
|
167
|
-
onUsage,
|
|
168
|
-
};
|
|
169
|
-
const call = {
|
|
170
|
-
systemPrompt,
|
|
171
|
-
session: request.session,
|
|
172
|
-
sessions: {
|
|
173
|
-
runId: run.id,
|
|
174
|
-
directory: join(run.directory, profile.runtime),
|
|
175
|
-
},
|
|
176
|
-
context: request.context,
|
|
177
|
-
schema: request.schema,
|
|
178
|
-
};
|
|
179
|
-
return profile.runtime === "pi"
|
|
180
|
-
? runCall(runtimes.pi, { ...call, profile }, options)
|
|
181
|
-
: runCall(runtimes["claude-code"], { ...call, profile }, options);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
//# sourceMappingURL=agent-runtime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runtime.js","sourceRoot":"","sources":["../../../src/system/runtimes/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAEL,QAAQ,GAET,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,cAAc,GACf,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAazC,4FAA4F;AAC5F,SAAS,SAAS,CAAC,OAAsB;IAIvC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAC9B,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,CACvD,CAAC;IACF,IAAI,OAAO,EAAE,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACtE,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO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,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;YAC1C,MAAM;YACN,OAAO;SACR,CAAC;QACF,MAAM,IAAI,GAAG;YACX,YAAY;YACZ,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE;gBACR,KAAK,EAAE,GAAG,CAAC,EAAE;gBACb,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC;aAChD;YACD,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;QACF,OAAO,OAAO,CAAC,OAAO,KAAK,IAAI;YAC7B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC;YACrD,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type RuntimeAdapter } from "./adapter.js";
|
|
2
|
-
/** Claude Code session IDs are UUIDs: a stable one per session name. */
|
|
3
|
-
export declare function claudeCodeSessionId(name: string): string;
|
|
4
|
-
/**
|
|
5
|
-
* Claude Code in print mode, in a session that holds only the profile's tools and
|
|
6
|
-
* MCP servers. Its sessions need UUIDs: the run keeps a marker per session, so
|
|
7
|
-
* that the next call resumes it. At the end of each call, Claude Code announces
|
|
8
|
-
* its session's total, which is reported as it is.
|
|
9
|
-
*/
|
|
10
|
-
export declare const claudeCode: RuntimeAdapter<"claude-code">;
|
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { runtimeLabels } from "../../engine/profiles.js";
|
|
6
|
-
import { parseEvent, } from "./adapter.js";
|
|
7
|
-
import { agentSessionName } from "./protocol.js";
|
|
8
|
-
const label = runtimeLabels["claude-code"];
|
|
9
|
-
const anyEvent = z.looseObject({
|
|
10
|
-
type: z.string(),
|
|
11
|
-
subtype: z.unknown().optional(),
|
|
12
|
-
});
|
|
13
|
-
/** What the session holds. Capabilities are required: an unreported one could hide a tool. */
|
|
14
|
-
const initEvent = z.looseObject({
|
|
15
|
-
session_id: z.string(),
|
|
16
|
-
tools: z.array(z.string()),
|
|
17
|
-
mcp_servers: z.array(z.looseObject({ name: z.string(), status: z.string() })),
|
|
18
|
-
plugins: z.array(z.looseObject({ name: z.string(), path: z.string() })),
|
|
19
|
-
skills: z.array(z.string()).optional(),
|
|
20
|
-
slash_commands: z.array(z.string()).optional(),
|
|
21
|
-
output_style: z.string().optional(),
|
|
22
|
-
memory_paths: z.unknown().optional(),
|
|
23
|
-
});
|
|
24
|
-
/** A content block; a tool use names its call and its tool, a tool result its call. */
|
|
25
|
-
const contentBlock = z
|
|
26
|
-
.looseObject({
|
|
27
|
-
type: z.string(),
|
|
28
|
-
id: z.unknown().optional(),
|
|
29
|
-
name: z.unknown().optional(),
|
|
30
|
-
tool_use_id: z.unknown().optional(),
|
|
31
|
-
is_error: z.boolean().optional(),
|
|
32
|
-
})
|
|
33
|
-
.superRefine((block, context) => {
|
|
34
|
-
const required = block.type === "tool_use"
|
|
35
|
-
? ["id", "name"]
|
|
36
|
-
: block.type === "tool_result"
|
|
37
|
-
? ["tool_use_id"]
|
|
38
|
-
: [];
|
|
39
|
-
for (const key of required)
|
|
40
|
-
if (typeof block[key] !== "string")
|
|
41
|
-
context.addIssue({
|
|
42
|
-
code: "custom",
|
|
43
|
-
path: [key],
|
|
44
|
-
message: "expected a string",
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
const messageEvent = z.looseObject({
|
|
48
|
-
/** Set on a subagent's messages. */
|
|
49
|
-
parent_tool_use_id: z.unknown().optional(),
|
|
50
|
-
message: z.looseObject({
|
|
51
|
-
id: z.unknown().optional(),
|
|
52
|
-
usage: z.unknown().optional(),
|
|
53
|
-
// Text content holds no tool call.
|
|
54
|
-
content: z.preprocess((content) => (typeof content === "string" ? [] : content), z.array(contentBlock)),
|
|
55
|
-
}),
|
|
56
|
-
});
|
|
57
|
-
/** `result`, `errors` and the subtype only explain a failure: their shape never hides it. */
|
|
58
|
-
const resultEvent = z.looseObject({
|
|
59
|
-
subtype: z.unknown().optional(),
|
|
60
|
-
is_error: z.boolean(),
|
|
61
|
-
result: z.unknown().optional(),
|
|
62
|
-
stop_reason: z.string().nullable().optional(),
|
|
63
|
-
errors: z.unknown().optional(),
|
|
64
|
-
modelUsage: z.unknown().optional(),
|
|
65
|
-
});
|
|
66
|
-
const text = (value) => (typeof value === "string" ? value : "");
|
|
67
|
-
/** Every model of the call, subagents and compactions included; measured on a best-effort basis. */
|
|
68
|
-
const modelUsage = z
|
|
69
|
-
.record(z.string(), z.looseObject({
|
|
70
|
-
inputTokens: z.number().nonnegative(),
|
|
71
|
-
outputTokens: z.number().nonnegative(),
|
|
72
|
-
cacheReadInputTokens: z.number().nonnegative(),
|
|
73
|
-
cacheCreationInputTokens: z.number().nonnegative(),
|
|
74
|
-
costUSD: z.number().nonnegative(),
|
|
75
|
-
}))
|
|
76
|
-
.refine((models) => Object.keys(models).length > 0);
|
|
77
|
-
function usageOf(value) {
|
|
78
|
-
const parsed = modelUsage.safeParse(value);
|
|
79
|
-
if (!parsed.success)
|
|
80
|
-
return undefined;
|
|
81
|
-
const usage = {
|
|
82
|
-
input: 0,
|
|
83
|
-
output: 0,
|
|
84
|
-
cacheRead: 0,
|
|
85
|
-
cacheWrite: 0,
|
|
86
|
-
costUsd: 0,
|
|
87
|
-
};
|
|
88
|
-
for (const model of Object.values(parsed.data)) {
|
|
89
|
-
usage.input += model.inputTokens;
|
|
90
|
-
usage.output += model.outputTokens;
|
|
91
|
-
usage.cacheRead += model.cacheReadInputTokens;
|
|
92
|
-
usage.cacheWrite += model.cacheCreationInputTokens;
|
|
93
|
-
usage.costUsd += model.costUSD;
|
|
94
|
-
}
|
|
95
|
-
return usage;
|
|
96
|
-
}
|
|
97
|
-
/** A response's tokens on its assistant events; output tokens are provisional until the result. */
|
|
98
|
-
const stepUsage = z.looseObject({
|
|
99
|
-
input_tokens: z.number().nonnegative(),
|
|
100
|
-
output_tokens: z.number().nonnegative(),
|
|
101
|
-
cache_read_input_tokens: z.number().nonnegative(),
|
|
102
|
-
cache_creation_input_tokens: z.number().nonnegative(),
|
|
103
|
-
});
|
|
104
|
-
/** Claude Code session IDs are UUIDs: a stable one per session name. */
|
|
105
|
-
export function claudeCodeSessionId(name) {
|
|
106
|
-
const hex = createHash("sha256").update(name).digest("hex");
|
|
107
|
-
const variant = ((Number.parseInt(hex[16] ?? "0", 16) & 0x3) | 0x8).toString(16);
|
|
108
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
109
|
-
}
|
|
110
|
-
const isMcpTool = (tool) => tool.startsWith("mcp__");
|
|
111
|
-
function profileArgs(profile, systemPrompt) {
|
|
112
|
-
const servers = Object.keys(profile.mcpServers).length
|
|
113
|
-
? ["--mcp-config", JSON.stringify({ mcpServers: profile.mcpServers })]
|
|
114
|
-
: [];
|
|
115
|
-
return [
|
|
116
|
-
"--model",
|
|
117
|
-
profile.model,
|
|
118
|
-
"--effort",
|
|
119
|
-
profile.thinking,
|
|
120
|
-
"--append-system-prompt",
|
|
121
|
-
systemPrompt,
|
|
122
|
-
// No settings file: no CLAUDE.md, installed plugins, hooks, permissions or output style
|
|
123
|
-
// from the operator's setup. `--safe-mode` would also drop the profile's MCP servers.
|
|
124
|
-
"--setting-sources",
|
|
125
|
-
"",
|
|
126
|
-
"--strict-mcp-config",
|
|
127
|
-
...servers,
|
|
128
|
-
"--disable-slash-commands",
|
|
129
|
-
"--settings",
|
|
130
|
-
JSON.stringify({ outputStyle: "default", autoMemoryEnabled: false }),
|
|
131
|
-
// `--tools` bounds built-in tools only; the allowlist is what lets MCP tools run.
|
|
132
|
-
"--tools",
|
|
133
|
-
profile.tools.filter((tool) => !isMcpTool(tool)).join(","),
|
|
134
|
-
...(profile.tools.length
|
|
135
|
-
? ["--allowedTools", profile.tools.join(",")]
|
|
136
|
-
: []),
|
|
137
|
-
"--permission-mode",
|
|
138
|
-
"dontAsk",
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Checks the started session against the profile: what the agent can do must be
|
|
143
|
-
* exactly what the profile grants (failure); any other customization is a warning.
|
|
144
|
-
*/
|
|
145
|
-
function checkSession(profile, init) {
|
|
146
|
-
const declared = Object.keys(profile.mcpServers);
|
|
147
|
-
// A server that failed to start would otherwise surface as missing tools.
|
|
148
|
-
const unavailable = declared.flatMap((server) => {
|
|
149
|
-
const status = init.mcp_servers.find(({ name }) => name === server)?.status;
|
|
150
|
-
return status === "connected" ? [] : [`${server} (${status ?? "missing"})`];
|
|
151
|
-
});
|
|
152
|
-
if (unavailable.length)
|
|
153
|
-
return failure(`${label} MCP servers are not connected: ${unavailable.join(", ")}`);
|
|
154
|
-
// An unknown name would silently remove a tool the profile grants.
|
|
155
|
-
const missing = profile.tools.filter((tool) => !init.tools.includes(tool));
|
|
156
|
-
if (missing.length)
|
|
157
|
-
return failure(`${label} does not provide tools: ${missing.join(", ")}`);
|
|
158
|
-
const capabilities = [
|
|
159
|
-
[
|
|
160
|
-
"tools",
|
|
161
|
-
init.tools.filter((tool) => !profile.tools.includes(tool) &&
|
|
162
|
-
!declared.some((server) => tool.startsWith(`mcp__${server}__`))),
|
|
163
|
-
],
|
|
164
|
-
[
|
|
165
|
-
"MCP servers",
|
|
166
|
-
init.mcp_servers
|
|
167
|
-
.map(({ name }) => name)
|
|
168
|
-
.filter((name) => !declared.includes(name)),
|
|
169
|
-
],
|
|
170
|
-
[
|
|
171
|
-
"plugins",
|
|
172
|
-
init.plugins
|
|
173
|
-
.filter(({ path }) => path !== "builtin")
|
|
174
|
-
.map(({ name }) => name),
|
|
175
|
-
],
|
|
176
|
-
];
|
|
177
|
-
const extra = capabilities.flatMap(([field, names]) => names.length ? [`${field} ${names.join(", ")}`] : []);
|
|
178
|
-
if (extra.length)
|
|
179
|
-
return failure(`${label} session is not isolated: ${extra.join("; ")}`);
|
|
180
|
-
const customizations = [
|
|
181
|
-
...[
|
|
182
|
-
["skills", init.skills],
|
|
183
|
-
["slash commands", init.slash_commands],
|
|
184
|
-
].flatMap(([field, names]) => names === undefined
|
|
185
|
-
? [`${field} unreported`]
|
|
186
|
-
: names.length
|
|
187
|
-
? [`${field} ${names.join(", ")}`]
|
|
188
|
-
: []),
|
|
189
|
-
...(init.memory_paths === undefined ? [] : ["auto memory"]),
|
|
190
|
-
...(init.output_style === "default"
|
|
191
|
-
? []
|
|
192
|
-
: [`output style ${init.output_style ?? "unreported"}`]),
|
|
193
|
-
];
|
|
194
|
-
return customizations.length
|
|
195
|
-
? [
|
|
196
|
-
{
|
|
197
|
-
type: "warning",
|
|
198
|
-
message: `${label} session is not fully isolated: ${customizations.join("; ")}`,
|
|
199
|
-
},
|
|
200
|
-
]
|
|
201
|
-
: [];
|
|
202
|
-
}
|
|
203
|
-
/** `claude auth status --json`; it also names the account, which is never read. */
|
|
204
|
-
const loginStatus = z.looseObject({
|
|
205
|
-
loggedIn: z.boolean(),
|
|
206
|
-
authMethod: z.string().optional(),
|
|
207
|
-
apiKeySource: z.string().optional(),
|
|
208
|
-
});
|
|
209
|
-
function readLogin(stdout) {
|
|
210
|
-
let status;
|
|
211
|
-
try {
|
|
212
|
-
status = loginStatus.parse(JSON.parse(stdout));
|
|
213
|
-
}
|
|
214
|
-
catch {
|
|
215
|
-
return {
|
|
216
|
-
connected: false,
|
|
217
|
-
detail: `${label} login status is unreadable`,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
if (!status.loggedIn)
|
|
221
|
-
return { connected: false, detail: `${label} is not logged in` };
|
|
222
|
-
// An API key in the environment replaces the login.
|
|
223
|
-
return {
|
|
224
|
-
connected: true,
|
|
225
|
-
detail: status.authMethod === "claude.ai"
|
|
226
|
-
? "claude.ai subscription"
|
|
227
|
-
: status.authMethod === "api_key"
|
|
228
|
-
? `API key (${status.apiKeySource ?? "unknown source"})`
|
|
229
|
-
: `${status.authMethod ?? "unknown"} login`,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
const failure = (message) => [
|
|
233
|
-
{ type: "failure", message },
|
|
234
|
-
];
|
|
235
|
-
/**
|
|
236
|
-
* Claude Code in print mode, in a session that holds only the profile's tools and
|
|
237
|
-
* MCP servers. Its sessions need UUIDs: the run keeps a marker per session, so
|
|
238
|
-
* that the next call resumes it. At the end of each call, Claude Code announces
|
|
239
|
-
* its session's total, which is reported as it is.
|
|
240
|
-
*/
|
|
241
|
-
export const claudeCode = {
|
|
242
|
-
name: "claude-code",
|
|
243
|
-
label,
|
|
244
|
-
executable: "claude",
|
|
245
|
-
minimumVersion: "2.1.296",
|
|
246
|
-
connection: () => ({
|
|
247
|
-
args: ["auth", "status", "--json"],
|
|
248
|
-
read: readLogin,
|
|
249
|
-
}),
|
|
250
|
-
model: (profile) => profile.model,
|
|
251
|
-
async start({ profile, systemPrompt, session, sessions }) {
|
|
252
|
-
const name = agentSessionName(sessions.runId, session);
|
|
253
|
-
const sessionId = claudeCodeSessionId(name);
|
|
254
|
-
const marker = join(sessions.directory, name);
|
|
255
|
-
// `--session-id` refuses an existing session and `--resume` a missing one.
|
|
256
|
-
const created = existsSync(marker);
|
|
257
|
-
const tools = new Map();
|
|
258
|
-
const responses = new Set();
|
|
259
|
-
let initialized = false;
|
|
260
|
-
/** A main-loop response once, however many events carry it; unreadable tokens are not reported. */
|
|
261
|
-
const responseOf = (type, parent, message) => {
|
|
262
|
-
if (type !== "assistant" || parent || typeof message.id !== "string")
|
|
263
|
-
return [];
|
|
264
|
-
if (responses.has(message.id))
|
|
265
|
-
return [];
|
|
266
|
-
responses.add(message.id);
|
|
267
|
-
const usage = stepUsage.safeParse(message.usage);
|
|
268
|
-
return usage.success
|
|
269
|
-
? [
|
|
270
|
-
{
|
|
271
|
-
type: "response",
|
|
272
|
-
tokens: {
|
|
273
|
-
input: usage.data.input_tokens,
|
|
274
|
-
output: usage.data.output_tokens,
|
|
275
|
-
cacheRead: usage.data.cache_read_input_tokens,
|
|
276
|
-
cacheWrite: usage.data.cache_creation_input_tokens,
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
]
|
|
280
|
-
: [];
|
|
281
|
-
};
|
|
282
|
-
return {
|
|
283
|
-
args: [
|
|
284
|
-
"--print",
|
|
285
|
-
"--output-format",
|
|
286
|
-
"stream-json",
|
|
287
|
-
"--verbose",
|
|
288
|
-
...profileArgs(profile, systemPrompt),
|
|
289
|
-
created ? "--resume" : "--session-id",
|
|
290
|
-
sessionId,
|
|
291
|
-
"--name",
|
|
292
|
-
`${sessions.runId}:${session}`,
|
|
293
|
-
],
|
|
294
|
-
read(raw) {
|
|
295
|
-
const event = parseEvent(label, anyEvent, raw);
|
|
296
|
-
if (event.type === "system" && event.subtype === "init") {
|
|
297
|
-
const init = parseEvent(label, initEvent, raw);
|
|
298
|
-
if (init.session_id !== sessionId)
|
|
299
|
-
return failure(`${label} started session ${init.session_id} instead of ${sessionId}`);
|
|
300
|
-
if (!created)
|
|
301
|
-
writeFileSync(marker, `${JSON.stringify({ sessionId })}\n`, {
|
|
302
|
-
mode: 0o600,
|
|
303
|
-
});
|
|
304
|
-
initialized = true;
|
|
305
|
-
return checkSession(profile, init);
|
|
306
|
-
}
|
|
307
|
-
if (event.type === "assistant" || event.type === "user") {
|
|
308
|
-
const { parent_tool_use_id: parent, message } = parseEvent(label, messageEvent, raw);
|
|
309
|
-
return [
|
|
310
|
-
...responseOf(event.type, parent, message),
|
|
311
|
-
...message.content.flatMap((block) => {
|
|
312
|
-
if (block.type === "tool_use") {
|
|
313
|
-
tools.set(String(block.id), String(block.name));
|
|
314
|
-
return [
|
|
315
|
-
{
|
|
316
|
-
type: "tool",
|
|
317
|
-
id: String(block.id),
|
|
318
|
-
name: String(block.name),
|
|
319
|
-
status: "started",
|
|
320
|
-
},
|
|
321
|
-
];
|
|
322
|
-
}
|
|
323
|
-
if (block.type !== "tool_result")
|
|
324
|
-
return [];
|
|
325
|
-
const id = String(block.tool_use_id);
|
|
326
|
-
return [
|
|
327
|
-
{
|
|
328
|
-
type: "tool",
|
|
329
|
-
id,
|
|
330
|
-
name: tools.get(id) ?? id,
|
|
331
|
-
status: block.is_error ? "failed" : "completed",
|
|
332
|
-
},
|
|
333
|
-
];
|
|
334
|
-
}),
|
|
335
|
-
];
|
|
336
|
-
}
|
|
337
|
-
if (event.type !== "result")
|
|
338
|
-
return [];
|
|
339
|
-
const result = parseEvent(label, resultEvent, raw);
|
|
340
|
-
const total = usageOf(result.modelUsage);
|
|
341
|
-
// A crash result may announce zeroed figures (Claude Code's cost tracking docs):
|
|
342
|
-
// nothing is measured, so the session keeps its earlier total.
|
|
343
|
-
const crashed = result.is_error &&
|
|
344
|
-
result.subtype === "error_during_execution" &&
|
|
345
|
-
total !== undefined &&
|
|
346
|
-
Object.values(total).every((value) => value === 0);
|
|
347
|
-
const usage = {
|
|
348
|
-
type: "usage",
|
|
349
|
-
scope: "session",
|
|
350
|
-
usage: crashed ? undefined : total,
|
|
351
|
-
};
|
|
352
|
-
if (result.is_error) {
|
|
353
|
-
const errors = Array.isArray(result.errors)
|
|
354
|
-
? result.errors.filter((error) => typeof error === "string")
|
|
355
|
-
: [];
|
|
356
|
-
return [
|
|
357
|
-
usage,
|
|
358
|
-
...failure(`${label} ${text(result.subtype) || "error"}: ${text(result.result) || errors.join("; ") || "no detail provided"}`),
|
|
359
|
-
];
|
|
360
|
-
}
|
|
361
|
-
if (result.stop_reason && result.stop_reason !== "end_turn")
|
|
362
|
-
return [
|
|
363
|
-
usage,
|
|
364
|
-
...failure(`${label} final response ended with stop reason ${result.stop_reason}`),
|
|
365
|
-
];
|
|
366
|
-
// Without an init event, neither the session nor its isolation was checked.
|
|
367
|
-
if (!initialized)
|
|
368
|
-
return [
|
|
369
|
-
usage,
|
|
370
|
-
...failure(`${label} answered without reporting its session (init)`),
|
|
371
|
-
];
|
|
372
|
-
// A successful call's final text is what the stage receives.
|
|
373
|
-
if (typeof result.result !== "string")
|
|
374
|
-
return [
|
|
375
|
-
usage,
|
|
376
|
-
...failure(`${label} emitted an unexpected result event: result: expected a string`),
|
|
377
|
-
];
|
|
378
|
-
return [usage, { type: "result", text: result.result }];
|
|
379
|
-
},
|
|
380
|
-
};
|
|
381
|
-
},
|
|
382
|
-
};
|
|
383
|
-
//# sourceMappingURL=claude-code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../../src/system/runtimes/claude-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAGL,UAAU,GAGX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,KAAK,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAE3C,MAAM,QAAQ,GAAG,CAAC,CAAC,WAAW,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEH,8FAA8F;AAC9F,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;IAC9B,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