@rarebit-one/harness-kernel 0.6.0 → 0.8.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 +65 -7
- package/dist/agent.d.ts +12 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +191 -94
- package/dist/agent.js.map +1 -1
- package/dist/connectors/mcpClient.d.ts +6 -1
- package/dist/connectors/mcpClient.d.ts.map +1 -1
- package/dist/connectors/mcpClient.js +1 -1
- package/dist/connectors/mcpClient.js.map +1 -1
- package/dist/engines/acp.d.ts +121 -0
- package/dist/engines/acp.d.ts.map +1 -0
- package/dist/engines/acp.js +219 -0
- package/dist/engines/acp.js.map +1 -0
- package/dist/engines/acpDriver.d.ts +33 -0
- package/dist/engines/acpDriver.d.ts.map +1 -0
- package/dist/engines/acpDriver.js +150 -0
- package/dist/engines/acpDriver.js.map +1 -0
- package/dist/engines/claudeCode.d.ts +6 -0
- package/dist/engines/claudeCode.d.ts.map +1 -1
- package/dist/engines/claudeCode.js +32 -10
- package/dist/engines/claudeCode.js.map +1 -1
- package/dist/engines/claudeCodeDriver.d.ts +11 -0
- package/dist/engines/claudeCodeDriver.d.ts.map +1 -1
- package/dist/engines/claudeCodeDriver.js +35 -5
- package/dist/engines/claudeCodeDriver.js.map +1 -1
- package/dist/engines/codex.d.ts +12 -0
- package/dist/engines/codex.d.ts.map +1 -1
- package/dist/engines/codex.js +15 -1
- package/dist/engines/codex.js.map +1 -1
- package/dist/engines/codexDriver.d.ts.map +1 -1
- package/dist/engines/codexDriver.js +51 -12
- package/dist/engines/codexDriver.js.map +1 -1
- package/dist/engines/index.d.ts.map +1 -1
- package/dist/engines/index.js +8 -0
- package/dist/engines/index.js.map +1 -1
- package/dist/engines/native.d.ts.map +1 -1
- package/dist/engines/native.js +59 -4
- package/dist/engines/native.js.map +1 -1
- package/dist/engines/types.d.ts +16 -1
- package/dist/engines/types.d.ts.map +1 -1
- package/dist/events.d.ts +55 -10
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loop.d.ts +21 -2
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +7 -2
- package/dist/loop.js.map +1 -1
- package/dist/models/chat.d.ts +6 -2
- package/dist/models/chat.d.ts.map +1 -1
- package/dist/models/chat.js +15 -9
- package/dist/models/chat.js.map +1 -1
- package/dist/models/types.d.ts +15 -1
- package/dist/models/types.d.ts.map +1 -1
- package/dist/models/types.js.map +1 -1
- package/dist/primitives/codeExec.d.ts +7 -0
- package/dist/primitives/codeExec.d.ts.map +1 -1
- package/dist/primitives/codeExec.js +32 -4
- package/dist/primitives/codeExec.js.map +1 -1
- package/dist/primitives/http.d.ts +6 -0
- package/dist/primitives/http.d.ts.map +1 -1
- package/dist/primitives/http.js +28 -11
- package/dist/primitives/http.js.map +1 -1
- package/dist/processGroup.d.ts +16 -0
- package/dist/processGroup.d.ts.map +1 -0
- package/dist/processGroup.js +39 -0
- package/dist/processGroup.js.map +1 -0
- package/dist/providers/anthropic.d.ts +12 -2
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +30 -3
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/mock.d.ts +2 -2
- package/dist/providers/mock.d.ts.map +1 -1
- package/dist/providers/mock.js +5 -1
- package/dist/providers/mock.js.map +1 -1
- package/dist/providers/openai.d.ts +11 -2
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +25 -5
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/types.d.ts +21 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/signals.d.ts +46 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +72 -0
- package/dist/signals.js.map +1 -0
- package/dist/tools/metadata.d.ts +18 -2
- package/dist/tools/metadata.d.ts.map +1 -1
- package/dist/tools/metadata.js +7 -0
- package/dist/tools/metadata.js.map +1 -1
- package/dist/tools/modelTool.d.ts.map +1 -1
- package/dist/tools/modelTool.js +7 -3
- package/dist/tools/modelTool.js.map +1 -1
- package/dist/tools/registry.d.ts +24 -5
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +43 -12
- package/dist/tools/registry.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { McpServer } from "@zed-industries/agent-client-protocol";
|
|
2
|
+
import type { RunOutcome } from "../events.js";
|
|
3
|
+
import type { StoppedBy } from "../signals.js";
|
|
4
|
+
import type { AgentEngine, EngineContext, EngineResult, EngineSupport, RunSpec } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A named external agent this engine can drive over the Agent Client Protocol.
|
|
7
|
+
* ACP is a JSON-RPC-over-stdio protocol between a *client* (this engine) and a
|
|
8
|
+
* coding *agent* running as a separate process, so every ACP agent reduces to
|
|
9
|
+
* "which subprocess to spawn, with what argv and env". The capability MCP server
|
|
10
|
+
* and the run's connectors are handed to the agent through `session/new`, so a
|
|
11
|
+
* spec never has to describe those — only its own launch.
|
|
12
|
+
*
|
|
13
|
+
* External agent product names appearing here follow the existing `claude-code`
|
|
14
|
+
* / `codex` precedent: an adapter's honest identity is the tool it drives, not a
|
|
15
|
+
* consumer's brand.
|
|
16
|
+
*/
|
|
17
|
+
export interface AcpAgentSpec {
|
|
18
|
+
/** Engine name; also the `provider.engine` value that selects it. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** Env var that must equal `"1"` for {@link AcpEngine.supports} to allow this agent. */
|
|
21
|
+
readonly enableEnv: string;
|
|
22
|
+
/** The executable to spawn — an ACP server over stdio. */
|
|
23
|
+
readonly command: string;
|
|
24
|
+
/** The process argv for a run (e.g. the ACP subcommand). */
|
|
25
|
+
args(spec: RunSpec): string[];
|
|
26
|
+
/** Extra process env — e.g. the provider credentials the agent reads for itself. */
|
|
27
|
+
env(spec: RunSpec): Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Driver-neutral options the engine derives from a {@link RunSpec} and hands to
|
|
31
|
+
* the ACP driver. The default driver spawns `command`+`args` and speaks ACP over
|
|
32
|
+
* its stdio; tests inject a fake driver and assert this mapping.
|
|
33
|
+
*/
|
|
34
|
+
export interface AcpOptions {
|
|
35
|
+
command: string;
|
|
36
|
+
args: string[];
|
|
37
|
+
env: Record<string, string>;
|
|
38
|
+
/** The prepared sandbox working tree — the agent's cwd and ACP `session/new` cwd. */
|
|
39
|
+
cwd: string;
|
|
40
|
+
/** The run's MCP servers (connectors + the capability server) for `session/new`. */
|
|
41
|
+
mcpServers: McpServer[];
|
|
42
|
+
/** The task prompt (workflow prompt + inputs). */
|
|
43
|
+
prompt: string;
|
|
44
|
+
/** Wall-clock budget in ms; undefined means no engine-imposed limit. */
|
|
45
|
+
maxDurationMs?: number;
|
|
46
|
+
/** Append a line to the run log (the driver surfaces the agent's stderr here). */
|
|
47
|
+
log: (line: string) => void;
|
|
48
|
+
/** The caller's cancel; the driver merges it with its own `maxDurationMs` timer. */
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
/**
|
|
51
|
+
* How long the agent gets to answer `session/cancel` after a stop before its
|
|
52
|
+
* process is killed. Defaults to 5s. Bounds every stop, so a hung agent
|
|
53
|
+
* cannot keep a canceled or timed-out run alive.
|
|
54
|
+
*/
|
|
55
|
+
cancelGraceMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/** Streaming callbacks the driver invokes as ACP `session/update`s arrive. */
|
|
58
|
+
export interface AcpClientEvents {
|
|
59
|
+
/** An `agent_message_chunk` — accumulated into the run's prose result. */
|
|
60
|
+
onAssistantChunk(text: string): void;
|
|
61
|
+
/** A human-readable line for the run log (thoughts, tool-call titles). */
|
|
62
|
+
onLog(line: string): void;
|
|
63
|
+
}
|
|
64
|
+
/** What one ACP prompt turn resolved to. */
|
|
65
|
+
export interface AcpOutcome {
|
|
66
|
+
/** The ACP `stopReason` (`end_turn`, `cancelled`, `refusal`, …). */
|
|
67
|
+
stopReason: string;
|
|
68
|
+
/** Set when the driver stopped the turn itself: its own timer
|
|
69
|
+
* (`"deadline"`) or the caller's signal (`"signal"`). */
|
|
70
|
+
stoppedBy?: StoppedBy;
|
|
71
|
+
}
|
|
72
|
+
/** The injectable boundary to the ACP transport. Tests supply a fake. */
|
|
73
|
+
export type AcpDriver = (opts: AcpOptions, events: AcpClientEvents) => Promise<AcpOutcome>;
|
|
74
|
+
/**
|
|
75
|
+
* Drives a run with any ACP-speaking coding agent (Claude Code, Codex, eve, …)
|
|
76
|
+
* against the sandbox working tree. One engine, one transport: where the codex
|
|
77
|
+
* engine wrote a `config.toml` and the Claude Code engine mounted an in-process
|
|
78
|
+
* SDK MCP server, this hands the run's connectors + the runner-hosted capability
|
|
79
|
+
* server to the agent through the ACP `session/new` `mcpServers` field, and reads
|
|
80
|
+
* back the capability server's emissions file — so an ACP agent reaches emit
|
|
81
|
+
* parity with native.
|
|
82
|
+
*
|
|
83
|
+
* Because an ACP agent runs arbitrary code, `supports()` refuses unless the
|
|
84
|
+
* operator enabled this specific agent AND the run is on the ephemeral runner
|
|
85
|
+
* profile (one throwaway container per run is the safety boundary). File edits
|
|
86
|
+
* are out-of-band: the agent edits `cwd` directly and the caller's change-set
|
|
87
|
+
* diff captures them, so this engine advertises no client filesystem capability.
|
|
88
|
+
*/
|
|
89
|
+
export declare class AcpEngine implements AgentEngine {
|
|
90
|
+
readonly name: string;
|
|
91
|
+
private readonly agent;
|
|
92
|
+
private readonly capabilityServerScript;
|
|
93
|
+
private readonly drive;
|
|
94
|
+
/**
|
|
95
|
+
* `capabilityServerScript` is REQUIRED, exactly as for codex: the capability
|
|
96
|
+
* surface is injected, and a child process cannot be handed a closure, so the
|
|
97
|
+
* application must supply the entrypoint that serves its own tools over stdio.
|
|
98
|
+
*/
|
|
99
|
+
constructor(agent: AcpAgentSpec, capabilityServerScript: string, drive?: AcpDriver);
|
|
100
|
+
supports(spec: RunSpec): EngineSupport;
|
|
101
|
+
run(spec: RunSpec, ctx: EngineContext): Promise<EngineResult>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Map an ACP turn's ending onto the run outcome vocabulary. Who stopped it
|
|
105
|
+
* wins when the driver knows (`stoppedBy`); otherwise the ACP `stopReason`
|
|
106
|
+
* decides. `max_turn_requests` is the agent's own step budget; `max_tokens`
|
|
107
|
+
* still produced an answer (truncated), so it stays `completed`; a `refusal`
|
|
108
|
+
* did not do the work, so it is `failed`. An agent-side `cancelled` with no
|
|
109
|
+
* known stopper is reported as `canceled`.
|
|
110
|
+
*/
|
|
111
|
+
export declare function acpRunOutcome(outcome: AcpOutcome): RunOutcome;
|
|
112
|
+
/**
|
|
113
|
+
* The eve agent (Vercel's open-source framework), driven over `eve acp` — its
|
|
114
|
+
* stdio ACP server surface. eve reads its own model/provider from the authored
|
|
115
|
+
* eve application in the workdir; we pass through whatever provider credentials
|
|
116
|
+
* the run carries so a BYO key reaches it. (Open: an eve "agent" is an authored
|
|
117
|
+
* app, so the workdir must contain one — a workflow-declared app path with an
|
|
118
|
+
* `agent/`-root default is the follow-up; today it runs the app at the workdir root.)
|
|
119
|
+
*/
|
|
120
|
+
export declare const EVE_AGENT: AcpAgentSpec;
|
|
121
|
+
//# sourceMappingURL=acp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.d.ts","sourceRoot":"","sources":["../../src/engines/acp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAQlG;;;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AAC,EAAE,SAAS,CAAA;CACtB;AAED,yEAAyE;AACzE,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AAE1F;;;;;;;;;;;;;;GAcG;AACH,qBAAa,SAAU,YAAW,WAAW;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAQ;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IAEjC;;;;OAIG;gBAED,KAAK,EAAE,YAAY,EACnB,sBAAsB,EAAE,MAAM,EAC9B,KAAK,GAAE,SAA4B;IAQrC,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa;IAgBhC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;CAgFpE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAa7D;AA8CD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,EAAE,YAavB,CAAA"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { mkdtemp, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { CAPABILITY_SERVER_NAME } from "./capabilityMcp.js";
|
|
5
|
+
import { connectorServers } from "./connectorMcp.js";
|
|
6
|
+
import { readEmissions } from "./capabilityEmissions.js";
|
|
7
|
+
import { defaultAcpDriver } from "./acpDriver.js";
|
|
8
|
+
const LOG_TRUNCATE = 2000;
|
|
9
|
+
/**
|
|
10
|
+
* Drives a run with any ACP-speaking coding agent (Claude Code, Codex, eve, …)
|
|
11
|
+
* against the sandbox working tree. One engine, one transport: where the codex
|
|
12
|
+
* engine wrote a `config.toml` and the Claude Code engine mounted an in-process
|
|
13
|
+
* SDK MCP server, this hands the run's connectors + the runner-hosted capability
|
|
14
|
+
* server to the agent through the ACP `session/new` `mcpServers` field, and reads
|
|
15
|
+
* back the capability server's emissions file — so an ACP agent reaches emit
|
|
16
|
+
* parity with native.
|
|
17
|
+
*
|
|
18
|
+
* Because an ACP agent runs arbitrary code, `supports()` refuses unless the
|
|
19
|
+
* operator enabled this specific agent AND the run is on the ephemeral runner
|
|
20
|
+
* profile (one throwaway container per run is the safety boundary). File edits
|
|
21
|
+
* are out-of-band: the agent edits `cwd` directly and the caller's change-set
|
|
22
|
+
* diff captures them, so this engine advertises no client filesystem capability.
|
|
23
|
+
*/
|
|
24
|
+
export class AcpEngine {
|
|
25
|
+
name;
|
|
26
|
+
agent;
|
|
27
|
+
capabilityServerScript;
|
|
28
|
+
drive;
|
|
29
|
+
/**
|
|
30
|
+
* `capabilityServerScript` is REQUIRED, exactly as for codex: the capability
|
|
31
|
+
* surface is injected, and a child process cannot be handed a closure, so the
|
|
32
|
+
* application must supply the entrypoint that serves its own tools over stdio.
|
|
33
|
+
*/
|
|
34
|
+
constructor(agent, capabilityServerScript, drive = defaultAcpDriver) {
|
|
35
|
+
this.agent = agent;
|
|
36
|
+
this.name = agent.name;
|
|
37
|
+
this.capabilityServerScript = capabilityServerScript;
|
|
38
|
+
this.drive = drive;
|
|
39
|
+
}
|
|
40
|
+
supports(spec) {
|
|
41
|
+
if (process.env[this.agent.enableEnv] !== "1") {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
reason: `${this.name} engine is disabled (set ${this.agent.enableEnv}=1)`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (spec.workflow.runner?.profile !== "ephemeral") {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
reason: `${this.name} engine requires the ephemeral runner profile (per-run container isolation)`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return { ok: true };
|
|
54
|
+
}
|
|
55
|
+
async run(spec, ctx) {
|
|
56
|
+
// Emissions land OUTSIDE the sandbox so the bookkeeping file is never captured
|
|
57
|
+
// by the change set; the capability server (an external process) writes here and
|
|
58
|
+
// we read it back after the run.
|
|
59
|
+
const emissionsDir = await mkdtemp(path.join(tmpdir(), "harness-emit-"));
|
|
60
|
+
const emissionsFile = path.join(emissionsDir, "emissions.json");
|
|
61
|
+
const capabilityEnv = {
|
|
62
|
+
HARNESS_WORKSPACE_ID: spec.workspaceId,
|
|
63
|
+
HARNESS_WORKDIR: spec.workdir,
|
|
64
|
+
HARNESS_EMISSIONS_FILE: emissionsFile,
|
|
65
|
+
};
|
|
66
|
+
const servers = {
|
|
67
|
+
...connectorServers(spec.connectors),
|
|
68
|
+
[CAPABILITY_SERVER_NAME]: {
|
|
69
|
+
type: "stdio",
|
|
70
|
+
command: process.execPath,
|
|
71
|
+
args: [this.capabilityServerScript],
|
|
72
|
+
env: capabilityEnv,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const options = {
|
|
76
|
+
command: this.agent.command,
|
|
77
|
+
args: this.agent.args(spec),
|
|
78
|
+
// The capability env also rides on the process env so the stdio capability
|
|
79
|
+
// server inherits it regardless of how the agent forwards `session/new` env.
|
|
80
|
+
env: { ...this.agent.env(spec), ...capabilityEnv },
|
|
81
|
+
cwd: spec.workdir,
|
|
82
|
+
mcpServers: toAcpMcpServers(servers),
|
|
83
|
+
prompt: buildPrompt(spec),
|
|
84
|
+
...(spec.limits?.maxDurationMs !== undefined
|
|
85
|
+
? { maxDurationMs: spec.limits.maxDurationMs }
|
|
86
|
+
: {}),
|
|
87
|
+
log: ctx.log,
|
|
88
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
89
|
+
};
|
|
90
|
+
ctx.log(`${this.name}: driving ACP agent in ${spec.workdir}`);
|
|
91
|
+
const chunks = [];
|
|
92
|
+
let outcome;
|
|
93
|
+
try {
|
|
94
|
+
outcome = await this.drive(options, {
|
|
95
|
+
onAssistantChunk: (text) => {
|
|
96
|
+
if (text)
|
|
97
|
+
chunks.push(text);
|
|
98
|
+
},
|
|
99
|
+
onLog: (line) => {
|
|
100
|
+
if (line)
|
|
101
|
+
ctx.log(`${this.name}: ${truncate(line, LOG_TRUNCATE)}`);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
// A driver that throws on the caller's abort was still canceled, not broken.
|
|
107
|
+
if (!ctx.signal?.aborted)
|
|
108
|
+
throw err;
|
|
109
|
+
outcome = { stopReason: "cancelled", stoppedBy: "signal" };
|
|
110
|
+
}
|
|
111
|
+
if (outcome.stopReason && outcome.stopReason !== "end_turn") {
|
|
112
|
+
ctx.log(`${this.name}: stopped (${outcome.stopReason})`);
|
|
113
|
+
}
|
|
114
|
+
// Report whether the emissions round trip HAPPENED, not what it carried —
|
|
115
|
+
// presence plus size separates "the server never wrote" from "it wrote and the
|
|
116
|
+
// run emitted nothing"; the byte count comes from the file (see codex engine).
|
|
117
|
+
const emissionsStat = await stat(emissionsFile).then((st) => st, () => undefined);
|
|
118
|
+
const emissions = await readEmissions(emissionsFile);
|
|
119
|
+
ctx.log(`${this.name}: capability emissions — file ${emissionsStat ? `present (${emissionsStat.size} bytes)` : "absent"}` +
|
|
120
|
+
`${emissionsStat && emissions === undefined ? ", unreadable" : ""}`);
|
|
121
|
+
await rm(emissionsDir, { recursive: true, force: true });
|
|
122
|
+
return {
|
|
123
|
+
text: chunks.join("").trim() || "(no output)",
|
|
124
|
+
...(emissions !== undefined ? { emissions } : {}),
|
|
125
|
+
outcome: acpRunOutcome(outcome),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Map an ACP turn's ending onto the run outcome vocabulary. Who stopped it
|
|
131
|
+
* wins when the driver knows (`stoppedBy`); otherwise the ACP `stopReason`
|
|
132
|
+
* decides. `max_turn_requests` is the agent's own step budget; `max_tokens`
|
|
133
|
+
* still produced an answer (truncated), so it stays `completed`; a `refusal`
|
|
134
|
+
* did not do the work, so it is `failed`. An agent-side `cancelled` with no
|
|
135
|
+
* known stopper is reported as `canceled`.
|
|
136
|
+
*/
|
|
137
|
+
export function acpRunOutcome(outcome) {
|
|
138
|
+
if (outcome.stoppedBy === "deadline")
|
|
139
|
+
return "timed_out";
|
|
140
|
+
if (outcome.stoppedBy === "signal")
|
|
141
|
+
return "canceled";
|
|
142
|
+
switch (outcome.stopReason) {
|
|
143
|
+
case "cancelled":
|
|
144
|
+
return "canceled";
|
|
145
|
+
case "max_turn_requests":
|
|
146
|
+
return "steps_exhausted";
|
|
147
|
+
case "refusal":
|
|
148
|
+
return "failed";
|
|
149
|
+
default:
|
|
150
|
+
return "completed";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Translate the run's serializable MCP servers into ACP's `McpServer[]`. Same
|
|
155
|
+
* source data every other engine consumes (`connectorServers`), reshaped to the
|
|
156
|
+
* ACP wire form: env and headers become `{ name, value }` arrays.
|
|
157
|
+
*/
|
|
158
|
+
function toAcpMcpServers(servers) {
|
|
159
|
+
return Object.entries(servers).map(([name, server]) => {
|
|
160
|
+
if (server.type === "stdio") {
|
|
161
|
+
return {
|
|
162
|
+
name,
|
|
163
|
+
command: server.command,
|
|
164
|
+
args: server.args ?? [],
|
|
165
|
+
env: Object.entries(server.env ?? {}).map(([key, value]) => ({ name: key, value })),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
name,
|
|
170
|
+
type: server.type,
|
|
171
|
+
url: server.url,
|
|
172
|
+
headers: Object.entries(server.headers ?? {}).map(([key, value]) => ({ name: key, value })),
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function buildPrompt(spec) {
|
|
177
|
+
const inputs = JSON.stringify(spec.inputs ?? {}, null, 2);
|
|
178
|
+
return [
|
|
179
|
+
spec.workflow.prompt ?? `Execute the "${spec.workflow.name ?? spec.workflowPath}" workflow.`,
|
|
180
|
+
"",
|
|
181
|
+
"## Inputs",
|
|
182
|
+
"```json",
|
|
183
|
+
inputs,
|
|
184
|
+
"```",
|
|
185
|
+
"",
|
|
186
|
+
"You are running as an autonomous workflow. The current working directory is the",
|
|
187
|
+
"workspace — inspect and edit its files directly with your tools. When finished,",
|
|
188
|
+
"reply with the workflow's output as Markdown.",
|
|
189
|
+
].join("\n");
|
|
190
|
+
}
|
|
191
|
+
function truncate(text, max) {
|
|
192
|
+
return text.length <= max ? text : `${text.slice(0, max)}…`;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The eve agent (Vercel's open-source framework), driven over `eve acp` — its
|
|
196
|
+
* stdio ACP server surface. eve reads its own model/provider from the authored
|
|
197
|
+
* eve application in the workdir; we pass through whatever provider credentials
|
|
198
|
+
* the run carries so a BYO key reaches it. (Open: an eve "agent" is an authored
|
|
199
|
+
* app, so the workdir must contain one — a workflow-declared app path with an
|
|
200
|
+
* `agent/`-root default is the follow-up; today it runs the app at the workdir root.)
|
|
201
|
+
*/
|
|
202
|
+
export const EVE_AGENT = {
|
|
203
|
+
name: "eve",
|
|
204
|
+
enableEnv: "RUNNER_ENABLE_EVE",
|
|
205
|
+
command: "eve",
|
|
206
|
+
args: () => ["acp"],
|
|
207
|
+
env: (spec) => {
|
|
208
|
+
const env = {};
|
|
209
|
+
const creds = spec.provider.credentials;
|
|
210
|
+
if (creds?.anthropic)
|
|
211
|
+
env.ANTHROPIC_API_KEY = creds.anthropic;
|
|
212
|
+
if (creds?.openai)
|
|
213
|
+
env.OPENAI_API_KEY = creds.openai;
|
|
214
|
+
if (creds?.openrouter)
|
|
215
|
+
env.OPENROUTER_API_KEY = creds.openrouter;
|
|
216
|
+
return env;
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=acp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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|
4
|
+
* The outcome of a prompt turn that returned. A stop is credited only when the
|
|
5
|
+
* agent actually answered `cancelled`: a stop that lands just after a clean
|
|
6
|
+
* `end_turn` must not relabel a finished run as canceled or timed out.
|
|
7
|
+
*/
|
|
8
|
+
export declare function promptOutcome(stopReason: string, stoppedBy: StoppedBy | undefined): AcpOutcome;
|
|
9
|
+
/**
|
|
10
|
+
* The default ACP driver: the single integration boundary to an ACP agent
|
|
11
|
+
* subprocess, mirroring `defaultCodexDriver`'s injectable shape. It spawns the
|
|
12
|
+
* agent, wires an {@link ClientSideConnection} over its stdio via
|
|
13
|
+
* {@link ndJsonStream}, and runs one ACP turn: `initialize` → `session/new`
|
|
14
|
+
* (with the run's cwd + MCP servers) → `session/prompt`.
|
|
15
|
+
*
|
|
16
|
+
* The host `Client` it implements is deliberately minimal:
|
|
17
|
+
* - `sessionUpdate` accumulates `agent_message_chunk`s (the run's prose) and
|
|
18
|
+
* surfaces thoughts / tool-call titles to the log.
|
|
19
|
+
* - `requestPermission` AUTO-APPROVES (selects an `allow_*` option). This is
|
|
20
|
+
* the ACP equivalent of the codex driver's `--dangerously-bypass-approvals`
|
|
21
|
+
* and the Claude Code driver's `bypassPermissions`, justified the same way:
|
|
22
|
+
* an ACP agent only runs inside a throwaway ephemeral container, so the
|
|
23
|
+
* container — not an approval prompt — is the safety boundary.
|
|
24
|
+
* - No `readTextFile`/`writeTextFile`/terminal capability is advertised, so the
|
|
25
|
+
* agent edits `cwd` directly and the caller's change-set diff is the sole
|
|
26
|
+
* edit path (no second, protocol-level way for a file to change).
|
|
27
|
+
*
|
|
28
|
+
* Exercised only when the operator enables the agent (per-agent env flag) on the
|
|
29
|
+
* ephemeral profile; every test injects a fake driver, so no binary/network is
|
|
30
|
+
* touched in CI.
|
|
31
|
+
*/
|
|
32
|
+
export declare function defaultAcpDriver(opts: AcpOptions, events: AcpClientEvents): Promise<AcpOutcome>;
|
|
33
|
+
//# sourceMappingURL=acpDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpDriver.d.ts","sourceRoot":"","sources":["../../src/engines/acpDriver.ts"],"names":[],"mappings":"AAQA,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEvE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,CAE9F;AAKD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,UAAU,CAAC,CA6GrB"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { Readable, Writable } from "node:stream";
|
|
3
|
+
import { ClientSideConnection, ndJsonStream, PROTOCOL_VERSION, } from "@zed-industries/agent-client-protocol";
|
|
4
|
+
import { runStop } from "../signals.js";
|
|
5
|
+
/**
|
|
6
|
+
* The outcome of a prompt turn that returned. A stop is credited only when the
|
|
7
|
+
* agent actually answered `cancelled`: a stop that lands just after a clean
|
|
8
|
+
* `end_turn` must not relabel a finished run as canceled or timed out.
|
|
9
|
+
*/
|
|
10
|
+
export function promptOutcome(stopReason, stoppedBy) {
|
|
11
|
+
return stopReason === "cancelled" && stoppedBy ? { stopReason, stoppedBy } : { stopReason };
|
|
12
|
+
}
|
|
13
|
+
/** How long an agent gets to honour `session/cancel` before it is killed. */
|
|
14
|
+
const DEFAULT_CANCEL_GRACE_MS = 5_000;
|
|
15
|
+
/**
|
|
16
|
+
* The default ACP driver: the single integration boundary to an ACP agent
|
|
17
|
+
* subprocess, mirroring `defaultCodexDriver`'s injectable shape. It spawns the
|
|
18
|
+
* agent, wires an {@link ClientSideConnection} over its stdio via
|
|
19
|
+
* {@link ndJsonStream}, and runs one ACP turn: `initialize` → `session/new`
|
|
20
|
+
* (with the run's cwd + MCP servers) → `session/prompt`.
|
|
21
|
+
*
|
|
22
|
+
* The host `Client` it implements is deliberately minimal:
|
|
23
|
+
* - `sessionUpdate` accumulates `agent_message_chunk`s (the run's prose) and
|
|
24
|
+
* surfaces thoughts / tool-call titles to the log.
|
|
25
|
+
* - `requestPermission` AUTO-APPROVES (selects an `allow_*` option). This is
|
|
26
|
+
* the ACP equivalent of the codex driver's `--dangerously-bypass-approvals`
|
|
27
|
+
* and the Claude Code driver's `bypassPermissions`, justified the same way:
|
|
28
|
+
* an ACP agent only runs inside a throwaway ephemeral container, so the
|
|
29
|
+
* container — not an approval prompt — is the safety boundary.
|
|
30
|
+
* - No `readTextFile`/`writeTextFile`/terminal capability is advertised, so the
|
|
31
|
+
* agent edits `cwd` directly and the caller's change-set diff is the sole
|
|
32
|
+
* edit path (no second, protocol-level way for a file to change).
|
|
33
|
+
*
|
|
34
|
+
* Exercised only when the operator enables the agent (per-agent env flag) on the
|
|
35
|
+
* ephemeral profile; every test injects a fake driver, so no binary/network is
|
|
36
|
+
* touched in CI.
|
|
37
|
+
*/
|
|
38
|
+
export async function defaultAcpDriver(opts, events) {
|
|
39
|
+
const child = spawn(opts.command, opts.args, {
|
|
40
|
+
cwd: opts.cwd,
|
|
41
|
+
env: { ...process.env, ...opts.env },
|
|
42
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
43
|
+
});
|
|
44
|
+
let stderr = "";
|
|
45
|
+
child.stderr?.setEncoding("utf8");
|
|
46
|
+
child.stderr?.on("data", (chunk) => {
|
|
47
|
+
stderr += chunk;
|
|
48
|
+
});
|
|
49
|
+
// A spawn failure (e.g. the agent binary is absent) surfaces here; the awaited
|
|
50
|
+
// protocol calls below then reject and we rethrow with the stderr tail.
|
|
51
|
+
child.on("error", (err) => {
|
|
52
|
+
stderr += `\n${String(err)}`;
|
|
53
|
+
});
|
|
54
|
+
const client = {
|
|
55
|
+
// Not `async`: these return a resolved promise directly (the ACP `Client`
|
|
56
|
+
// methods are `Promise`-typed, but there is nothing to await).
|
|
57
|
+
sessionUpdate({ update }) {
|
|
58
|
+
switch (update.sessionUpdate) {
|
|
59
|
+
case "agent_message_chunk":
|
|
60
|
+
if (update.content.type === "text")
|
|
61
|
+
events.onAssistantChunk(update.content.text);
|
|
62
|
+
break;
|
|
63
|
+
case "agent_thought_chunk":
|
|
64
|
+
if (update.content.type === "text")
|
|
65
|
+
events.onLog(`thought: ${update.content.text}`);
|
|
66
|
+
break;
|
|
67
|
+
case "tool_call":
|
|
68
|
+
events.onLog(`tool: ${update.title}`);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
},
|
|
75
|
+
requestPermission({ options }) {
|
|
76
|
+
const allow = options.find((o) => o.kind === "allow_always") ??
|
|
77
|
+
options.find((o) => o.kind === "allow_once");
|
|
78
|
+
return Promise.resolve(allow
|
|
79
|
+
? { outcome: { outcome: "selected", optionId: allow.optionId } }
|
|
80
|
+
: { outcome: { outcome: "cancelled" } });
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const stream = ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
|
|
84
|
+
const conn = new ClientSideConnection(() => client, stream);
|
|
85
|
+
// The run's own timer merged with the caller's cancel. Once a session exists
|
|
86
|
+
// the stop is a protocol-level `session/cancel` (the agent winds the turn
|
|
87
|
+
// down and answers `cancelled`), with a bounded grace period: an agent that
|
|
88
|
+
// is hung or ignores the cancel is killed, so a stop can never hang the run.
|
|
89
|
+
// Before a session exists there is nothing to cancel, so it is killed at once.
|
|
90
|
+
//
|
|
91
|
+
// Every protocol await races `forced`, which rejects on a force-stop: a
|
|
92
|
+
// killed agent never answers, and its pending requests would otherwise wait
|
|
93
|
+
// forever.
|
|
94
|
+
let sessionId = "";
|
|
95
|
+
let forceTimer;
|
|
96
|
+
let rejectForced = () => { };
|
|
97
|
+
const forced = new Promise((_, reject) => {
|
|
98
|
+
rejectForced = reject;
|
|
99
|
+
});
|
|
100
|
+
forced.catch(() => { }); // observed via the races below; never unhandled
|
|
101
|
+
const guarded = (call) => Promise.race([call, forced]);
|
|
102
|
+
const forceStop = () => {
|
|
103
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
104
|
+
child.kill("SIGKILL");
|
|
105
|
+
rejectForced(new Error(`${opts.command}: agent force-stopped`));
|
|
106
|
+
};
|
|
107
|
+
const stop = runStop(opts.maxDurationMs, opts.signal);
|
|
108
|
+
const onStop = () => {
|
|
109
|
+
if (!sessionId)
|
|
110
|
+
return forceStop();
|
|
111
|
+
void conn.cancel({ sessionId }).catch(() => { });
|
|
112
|
+
forceTimer = setTimeout(forceStop, opts.cancelGraceMs ?? DEFAULT_CANCEL_GRACE_MS);
|
|
113
|
+
};
|
|
114
|
+
if (stop.signal?.aborted)
|
|
115
|
+
onStop();
|
|
116
|
+
else
|
|
117
|
+
stop.signal?.addEventListener("abort", onStop, { once: true });
|
|
118
|
+
try {
|
|
119
|
+
await guarded(conn.initialize({ protocolVersion: PROTOCOL_VERSION, clientCapabilities: {} }));
|
|
120
|
+
const session = await guarded(conn.newSession({ cwd: opts.cwd, mcpServers: opts.mcpServers }));
|
|
121
|
+
sessionId = session.sessionId;
|
|
122
|
+
// A stop that landed while the session was being created killed nothing
|
|
123
|
+
// yet (there was no session): honour it now rather than run the turn.
|
|
124
|
+
const early = stop.stoppedBy();
|
|
125
|
+
if (early)
|
|
126
|
+
return { stopReason: "cancelled", stoppedBy: early };
|
|
127
|
+
const res = await guarded(conn.prompt({ sessionId, prompt: [{ type: "text", text: opts.prompt }] }));
|
|
128
|
+
return promptOutcome(res.stopReason, stop.stoppedBy());
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
// A force-stop (or the kill-before-session path) rejects the pending
|
|
132
|
+
// protocol call; that is the stop, not an agent failure.
|
|
133
|
+
const stoppedBy = stop.stoppedBy();
|
|
134
|
+
if (stoppedBy)
|
|
135
|
+
return { stopReason: "cancelled", stoppedBy };
|
|
136
|
+
if (stderr.trim()) {
|
|
137
|
+
const tail = stderr.length > 4000 ? `…${stderr.slice(-4000)}` : stderr;
|
|
138
|
+
opts.log(`${opts.command} stderr:\n${tail}`);
|
|
139
|
+
}
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
if (forceTimer)
|
|
144
|
+
clearTimeout(forceTimer);
|
|
145
|
+
stop.signal?.removeEventListener("abort", onStop);
|
|
146
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
147
|
+
child.kill();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=acpDriver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpDriver.js","sourceRoot":"","sources":["../../src/engines/acpDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,GAEjB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAkB,MAAM,eAAe,CAAA;AAGvD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB,EAAE,SAAgC;IAChF,OAAO,UAAU,KAAK,WAAW,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAA;AAC7F,CAAC;AAED,6EAA6E;AAC7E,MAAM,uBAAuB,GAAG,KAAK,CAAA;AAErC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAgB,EAChB,MAAuB;IAEvB,MAAM,KAAK,GAAG,KAAK,C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AA;QACxC,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACjD,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,EAAE,CAAA;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StoppedBy } from "../signals.js";
|
|
1
2
|
import type { ConnectorConfig } from "../types.js";
|
|
2
3
|
import type { AgentEngine, EngineContext, EngineResult, EngineSupport, RunSpec } from "./types.js";
|
|
3
4
|
import { type CapabilityContext, type CapabilityTool } from "./capability.js";
|
|
@@ -25,6 +26,8 @@ export interface ClaudeCodeOptions {
|
|
|
25
26
|
/** The run's external MCP connectors; the driver mounts them as SDK mcpServers so
|
|
26
27
|
* they become tools inside Claude Code (parity with the native engine). */
|
|
27
28
|
connectors?: ConnectorConfig[];
|
|
29
|
+
/** The caller's cancel; the driver merges it with its own `maxDurationMs` timer. */
|
|
30
|
+
signal?: AbortSignal;
|
|
28
31
|
}
|
|
29
32
|
/** A normalized message from the harness (driver-agnostic). */
|
|
30
33
|
export type ClaudeCodeMessage = {
|
|
@@ -34,6 +37,9 @@ export type ClaudeCodeMessage = {
|
|
|
34
37
|
kind: "result";
|
|
35
38
|
text: string;
|
|
36
39
|
isError: boolean;
|
|
40
|
+
/** Set when the driver stopped the harness early: its own timer
|
|
41
|
+
* (`"deadline"`) or the caller's signal (`"signal"`). */
|
|
42
|
+
stoppedBy?: StoppedBy;
|
|
37
43
|
};
|
|
38
44
|
/**
|
|
39
45
|
* The injectable boundary to the Claude Code harness: given mapped options, yield
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"","sources":["../../src/engines/claudeCode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claudeCode.d.ts","sourceRoot":"","sources":["../../src/engines/claudeCode.ts"],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B,GAAG,CAAC,GAAG,EAAE,iBAAiB,KAAK,cAAc,EAAE,CAAA;AAEhF,0FAA0F;AAC1F,eAAO,MAAM,sBAAsB,EAAE,qBAA2D,CAAA;AAEhG;;;;;;;;;;GAUG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD,QAAQ,CAAC,IAAI,iBAAgB;IAE7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;gBAGrD,KAAK,GAAE,gBAA0C,EACjD,eAAe,GAAE,qBAA8C;IAMjE,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa;IAiBhC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;CA+DpE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { harnessOutcome } from "../signals.js";
|
|
1
2
|
import { defaultClaudeCodeDriver } from "./claudeCodeDriver.js";
|
|
2
3
|
import { writeFileCapability } from "./capability.js";
|
|
3
4
|
const DEFAULT_MODEL = "claude-opus-4-8";
|
|
@@ -62,21 +63,42 @@ export class ClaudeCodeEngine {
|
|
|
62
63
|
...(spec.limits?.maxDurationMs !== undefined
|
|
63
64
|
? { maxDurationMs: spec.limits.maxDurationMs }
|
|
64
65
|
: {}),
|
|
66
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
65
67
|
};
|
|
66
68
|
ctx.log(`claude-code: driving model ${model} in ${spec.workdir}`);
|
|
67
69
|
let finalText = "";
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
let lastAssistantText = "";
|
|
71
|
+
let outcome = "completed";
|
|
72
|
+
try {
|
|
73
|
+
for await (const message of this.drive(options)) {
|
|
74
|
+
if (message.kind === "assistant") {
|
|
75
|
+
if (message.text) {
|
|
76
|
+
lastAssistantText = message.text;
|
|
77
|
+
ctx.log(`claude-code: ${truncate(message.text, LOG_TRUNCATE)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
finalText = message.text;
|
|
82
|
+
outcome = harnessOutcome(message.isError, message.stoppedBy);
|
|
83
|
+
if (message.stoppedBy)
|
|
84
|
+
ctx.log(`claude-code: stopped (${outcome})`);
|
|
85
|
+
else if (message.isError)
|
|
86
|
+
ctx.log("claude-code: harness reported an error");
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
|
-
|
|
90
|
+
catch (err) {
|
|
91
|
+
// A driver that throws on the caller's abort was still canceled, not broken.
|
|
92
|
+
if (!ctx.signal?.aborted)
|
|
93
|
+
throw err;
|
|
94
|
+
outcome = "canceled";
|
|
95
|
+
ctx.log("claude-code: stopped (canceled)");
|
|
96
|
+
}
|
|
97
|
+
const stopped = outcome === "canceled" || outcome === "timed_out";
|
|
98
|
+
return {
|
|
99
|
+
text: finalText || (stopped ? lastAssistantText : "") || "(no output)",
|
|
100
|
+
outcome,
|
|
101
|
+
};
|
|
80
102
|
}
|
|
81
103
|
}
|
|
82
104
|
function buildPrompt(spec) {
|