@rarebit-one/harness-kernel 0.7.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.
Files changed (97) hide show
  1. package/README.md +65 -7
  2. package/dist/agent.d.ts +12 -3
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +191 -94
  5. package/dist/agent.js.map +1 -1
  6. package/dist/connectors/mcpClient.d.ts +6 -1
  7. package/dist/connectors/mcpClient.d.ts.map +1 -1
  8. package/dist/connectors/mcpClient.js +1 -1
  9. package/dist/connectors/mcpClient.js.map +1 -1
  10. package/dist/engines/acp.d.ts +22 -0
  11. package/dist/engines/acp.d.ts.map +1 -1
  12. package/dist/engines/acp.js +45 -10
  13. package/dist/engines/acp.js.map +1 -1
  14. package/dist/engines/acpDriver.d.ts +7 -0
  15. package/dist/engines/acpDriver.d.ts.map +1 -1
  16. package/dist/engines/acpDriver.js +60 -17
  17. package/dist/engines/acpDriver.js.map +1 -1
  18. package/dist/engines/claudeCode.d.ts +6 -0
  19. package/dist/engines/claudeCode.d.ts.map +1 -1
  20. package/dist/engines/claudeCode.js +32 -10
  21. package/dist/engines/claudeCode.js.map +1 -1
  22. package/dist/engines/claudeCodeDriver.d.ts +11 -0
  23. package/dist/engines/claudeCodeDriver.d.ts.map +1 -1
  24. package/dist/engines/claudeCodeDriver.js +35 -5
  25. package/dist/engines/claudeCodeDriver.js.map +1 -1
  26. package/dist/engines/codex.d.ts +12 -0
  27. package/dist/engines/codex.d.ts.map +1 -1
  28. package/dist/engines/codex.js +15 -1
  29. package/dist/engines/codex.js.map +1 -1
  30. package/dist/engines/codexDriver.d.ts.map +1 -1
  31. package/dist/engines/codexDriver.js +51 -12
  32. package/dist/engines/codexDriver.js.map +1 -1
  33. package/dist/engines/native.d.ts.map +1 -1
  34. package/dist/engines/native.js +59 -4
  35. package/dist/engines/native.js.map +1 -1
  36. package/dist/engines/types.d.ts +16 -1
  37. package/dist/engines/types.d.ts.map +1 -1
  38. package/dist/events.d.ts +55 -10
  39. package/dist/events.d.ts.map +1 -1
  40. package/dist/events.js.map +1 -1
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/loop.d.ts +21 -2
  46. package/dist/loop.d.ts.map +1 -1
  47. package/dist/loop.js +7 -2
  48. package/dist/loop.js.map +1 -1
  49. package/dist/models/chat.d.ts +6 -2
  50. package/dist/models/chat.d.ts.map +1 -1
  51. package/dist/models/chat.js +15 -9
  52. package/dist/models/chat.js.map +1 -1
  53. package/dist/models/types.d.ts +15 -1
  54. package/dist/models/types.d.ts.map +1 -1
  55. package/dist/models/types.js.map +1 -1
  56. package/dist/primitives/codeExec.d.ts +7 -0
  57. package/dist/primitives/codeExec.d.ts.map +1 -1
  58. package/dist/primitives/codeExec.js +32 -4
  59. package/dist/primitives/codeExec.js.map +1 -1
  60. package/dist/primitives/http.d.ts +6 -0
  61. package/dist/primitives/http.d.ts.map +1 -1
  62. package/dist/primitives/http.js +28 -11
  63. package/dist/primitives/http.js.map +1 -1
  64. package/dist/processGroup.d.ts +16 -0
  65. package/dist/processGroup.d.ts.map +1 -0
  66. package/dist/processGroup.js +39 -0
  67. package/dist/processGroup.js.map +1 -0
  68. package/dist/providers/anthropic.d.ts +12 -2
  69. package/dist/providers/anthropic.d.ts.map +1 -1
  70. package/dist/providers/anthropic.js +30 -3
  71. package/dist/providers/anthropic.js.map +1 -1
  72. package/dist/providers/mock.d.ts +2 -2
  73. package/dist/providers/mock.d.ts.map +1 -1
  74. package/dist/providers/mock.js +5 -1
  75. package/dist/providers/mock.js.map +1 -1
  76. package/dist/providers/openai.d.ts +11 -2
  77. package/dist/providers/openai.d.ts.map +1 -1
  78. package/dist/providers/openai.js +25 -5
  79. package/dist/providers/openai.js.map +1 -1
  80. package/dist/providers/types.d.ts +21 -1
  81. package/dist/providers/types.d.ts.map +1 -1
  82. package/dist/signals.d.ts +46 -0
  83. package/dist/signals.d.ts.map +1 -0
  84. package/dist/signals.js +72 -0
  85. package/dist/signals.js.map +1 -0
  86. package/dist/tools/metadata.d.ts +18 -2
  87. package/dist/tools/metadata.d.ts.map +1 -1
  88. package/dist/tools/metadata.js +7 -0
  89. package/dist/tools/metadata.js.map +1 -1
  90. package/dist/tools/modelTool.d.ts.map +1 -1
  91. package/dist/tools/modelTool.js +7 -3
  92. package/dist/tools/modelTool.js.map +1 -1
  93. package/dist/tools/registry.d.ts +24 -5
  94. package/dist/tools/registry.d.ts.map +1 -1
  95. package/dist/tools/registry.js +43 -12
  96. package/dist/tools/registry.js.map +1 -1
  97. package/package.json +3 -3
package/README.md CHANGED
@@ -31,8 +31,7 @@ build provenance attestation.
31
31
 
32
32
  v0 is a mechanical extraction of a proven, already-provider-neutral agent core
33
33
  into a standalone package — the mechanics are battle-tested, the packaging is
34
- new. Seam-widening (a general `ModelInvocation` seam, streaming, multimodal
35
- input, middleware, context providers) is planned as an additive v0.2.
34
+ new.
36
35
 
37
36
  ## Install
38
37
 
@@ -48,12 +47,12 @@ ESM-only, Node >= 22.
48
47
  |------|---------|
49
48
  | **Model seam** | `ModelInvocation` — one arrow for every model kind, with declared capabilities, a uniform result envelope and `probe()` |
50
49
  | **Providers** | `Provider` interface + `selectProvider()` over Anthropic, OpenAI, OpenRouter, a self-hosted `local` (any OpenAI-compatible server), and an offline `mock`; `chatModel()` puts any of them on the seam |
51
- | **Agent loop** | `runAgent()` — a provider-neutral tool-use loop with step and wall-clock budgets |
50
+ | **Agent loop** | `runAgent()` — a provider-neutral tool-use loop with step and wall-clock budgets, cancellable through an `AbortSignal` |
52
51
  | **Loop** | `Loop` + `nativeLoop` — the control loop as a seam; the kernel ships one and it is the loop `runAgent` has always run |
53
52
  | **Run events** | `RunEvent` — an ordered, structured account of a run (turns, tool calls, budgets, outcome), emitted to an optional sink |
54
- | **Tools** | `Tool`, `primitiveTools()` (`run_code`, `read_file`, `list_files`, `http_fetch`), `connectorTools()`, `modelAsTool()`, metadata + projections |
53
+ | **Tools** | `Tool` (+ `ToolContext`), `primitiveTools()` (`run_code`, `read_file`, `list_files`, `http_fetch`), `connectorTools()`, `modelAsTool()`, metadata + projections (`replaySafeTools`, …) |
55
54
  | **Connectors** | `connectMcp()` — MCP clients over stdio / streamable HTTP / SSE |
56
- | **Engines** | The `AgentEngine` seam + `native`, `claude-code`, and `codex` harnesses, plus the capability *mechanism* (scope guards, a generic `write_file`, and MCP/stdio transports) — the capability *set* is yours to inject |
55
+ | **Engines** | The `AgentEngine` seam + `native`, `claude-code`, `codex`, and ACP (`eve`) harnesses, plus the capability *mechanism* (scope guards, a generic `write_file`, and MCP/stdio transports) — the capability *set* is yours to inject |
57
56
  | **Routing** | `RouteResolver` + `StaticRouteResolver` — capability → model, prompt, tools |
58
57
  | **Context** | `ContextProvider` chain, assembled in parallel and rendered into the prompt |
59
58
  | **Secrets** | `secretsToEnv()` — resolved secret values into an exec environment |
@@ -102,8 +101,8 @@ const model = registry.resolve(route.model) // the resolver picks, the registry
102
101
  const model = withMiddleware(anyModel, [correlationMiddleware(), loggingMiddleware()])
103
102
  ```
104
103
 
105
- **4. Engines.** The `AgentEngine` seam — `native`, `claude-code`, `codex`, or
106
- your own. File mutations stay out of band.
104
+ **4. Engines.** The `AgentEngine` seam — `native`, `claude-code`, `codex`, an
105
+ ACP agent (`eve`), or your own. File mutations stay out of band.
107
106
 
108
107
  **5. Context providers.** Replace a single pre-baked context string with a
109
108
  chain, so a live source can inject fragments:
@@ -171,6 +170,12 @@ threw and never returned a result, so any number there would be invented. The
171
170
  `model.turn` events already in the stream are the authoritative record of how
172
171
  far it got.
173
172
 
173
+ A model call the loop **absorbs** rather than propagates emits
174
+ `model.turn.failed` (with a `phase`). Today that is only the tools-free summary
175
+ requested after the step budget runs out: if it fails, the run falls back to the
176
+ last assistant prose and still finishes `steps_exhausted`, and the event is what
177
+ tells a consumer the final text is not a summary.
178
+
174
179
  Engines take the same sink through `EngineContext`:
175
180
 
176
181
  ```ts
@@ -206,6 +211,59 @@ undoable but nothing recorded that the tool *ran*, so an application had nothing
206
211
  concrete to undo. Deciding whether to undo remains policy, and stays in the
207
212
  application.
208
213
 
214
+ ### Cancellation, tool context and usage
215
+
216
+ Every entry point takes an optional `AbortSignal` — `runAgent({ signal })`,
217
+ `engine.run(spec, { log, signal })`, and `LoopContext.signal` for a custom loop:
218
+
219
+ ```ts
220
+ const controller = new AbortController()
221
+ const result = await engine.run(spec, { log, signal: controller.signal })
222
+ // later: controller.abort("user canceled")
223
+ result.outcome // "completed" | "steps_exhausted" | "timed_out" | "canceled" | "failed"
224
+ ```
225
+
226
+ The native loop merges it with its own wall-clock deadline and threads the
227
+ result into every model request (`Provider.converse(req, { signal })`, which the
228
+ Anthropic and OpenAI adapters hand to the SDK per request) and every tool call.
229
+ So neither a cancel nor the deadline waits for an in-flight step: `run_code`
230
+ kills its whole process group, `http_fetch` aborts the request, and MCP calls
231
+ send the server a cancellation. An abort is a **clean stop, not a throw** — the
232
+ run resolves with the prose it had, `outcome: "canceled"` (the caller's signal)
233
+ or `"timed_out"` (the deadline), and no summary call is spent. A model
234
+ that ignores the signal and answers anyway has its turn recorded and its prose
235
+ kept, but the outcome is still the stop's, and none of the tools it asked for
236
+ run; an unrelated error that merely coincides with the stop still propagates.
237
+ `EngineResult.outcome` carries the same value; the external engines map their
238
+ harness's ending onto it.
239
+
240
+ Tools receive a second argument, `ToolContext`:
241
+
242
+ ```ts
243
+ const tool: Tool = {
244
+ spec,
245
+ meta: { replay: "safe" }, // idempotent: may be re-run after an interruption
246
+ execute: async (input, ctx) => {
247
+ // ctx.signal — stop when the run stops; ctx.callId — the model's call id
248
+ // (matches tool.called.callId); ctx.runId — when the caller supplied one
249
+ return doWork(input, { signal: ctx?.signal, idempotencyKey: ctx?.callId })
250
+ },
251
+ }
252
+ ```
253
+
254
+ `ToolMetadata.replay` is `"safe"` or `"unsafe"`, and **absent means unsafe**.
255
+ It is copied onto `tool.called` / `tool.succeeded`, and `replaySafeTools()`
256
+ selects the tools that declared it. The kernel only records the claim; whether
257
+ to replay is the application's decision.
258
+
259
+ Token usage is reported where the provider's API returns it:
260
+ `ConverseResult.usage`, `ModelResult.usage` and `model.turn.usage` on the
261
+ event stream. A provider opts in with `reportsUsage: true` (the Anthropic and
262
+ OpenAI-compatible adapters do), and `chatModel` derives `caps.usage` from it, so
263
+ the mock and custom providers never advertise usage they do not deliver. `inputTokens` is all input processed, cached or not (so
264
+ `totalTokens = inputTokens + outputTokens`); `cacheReadTokens` /
265
+ `cacheWriteTokens` break out the prompt-cache share of it.
266
+
209
267
  ## Usage
210
268
 
211
269
  ```ts
package/dist/agent.d.ts CHANGED
@@ -16,11 +16,20 @@ export interface RunAgentOptions {
16
16
  tools: Tool[];
17
17
  maxSteps?: number;
18
18
  /**
19
- * Wall-clock budget for the whole loop in ms. Checked between steps; when
20
- * exceeded the loop stops cleanly and returns what's accumulated (with a note)
21
- * rather than throwing. Defaults to `RUNNER_RUN_TIMEOUT_MS` if set, else 10min.
19
+ * Wall-clock budget for the whole loop in ms. Enforced both between steps and
20
+ * mid-call (the in-flight model request and tool are aborted); when exceeded
21
+ * the loop stops cleanly and returns what's accumulated (with a note) rather
22
+ * than throwing. Defaults to `RUNNER_RUN_TIMEOUT_MS` if set, else 10min.
22
23
  */
23
24
  maxDurationMs?: number;
25
+ /**
26
+ * Cancels the run. On abort the in-flight model request and tool are
27
+ * stopped, no summary call is made, and the run resolves (never rejects)
28
+ * with the prose accumulated so far and `outcome: "canceled"`.
29
+ */
30
+ signal?: AbortSignal;
31
+ /** The run's id, handed to tools on `ToolContext.runId`. */
32
+ runId?: string;
24
33
  log?: (line: string) => void;
25
34
  /**
26
35
  * Structured event sink. Absent (the default) means the loop behaves exactly
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAGlB,MAAM,aAAa,CAA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AC,MAAM,CAAC,CAsBxE;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAgP/F"}
package/dist/agent.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { runEventEmitter, } from "./events.js";
2
2
  import { nativeLoop, runWithEvents, } from "./loop.js";
3
3
  import { asChatModel } from "./models/chat.js";
4
+ import { deadlineSignal, isAbortError } from "./signals.js";
4
5
  import { executeTool } from "./tools/registry.js";
5
6
  import { toToolSpecs } from "./tools/metadata.js";
6
7
  const DEFAULT_MAX_STEPS = 12;
@@ -47,8 +48,18 @@ function undoFields(meta) {
47
48
  ...(meta?.reversible !== undefined ? { reversible: meta.reversible } : {}),
48
49
  ...(meta?.undoToolName !== undefined ? { undoToolName: meta.undoToolName } : {}),
49
50
  ...(meta?.undoWindowSeconds !== undefined ? { undoWindowSeconds: meta.undoWindowSeconds } : {}),
51
+ ...(meta?.replay !== undefined ? { replay: meta.replay } : {}),
50
52
  };
51
53
  }
54
+ /** A short, human-readable rendering of an abort reason for the run note. */
55
+ function describeReason(reason) {
56
+ if (typeof reason === "string")
57
+ return reason;
58
+ // The DOMException a bare `abort()` produces says nothing a caller chose.
59
+ if (reason instanceof Error && reason.name !== "AbortError")
60
+ return reason.message;
61
+ return "";
62
+ }
52
63
  /**
53
64
  * A detached copy of a tool's arguments for the event stream.
54
65
  *
@@ -88,7 +99,12 @@ export async function runAgent(options) {
88
99
  userPrompt: options.userPrompt,
89
100
  tools: options.tools,
90
101
  limits: resolveLoopLimits(options),
91
- }, { log, events: runEventEmitter(options.emit, log) });
102
+ }, {
103
+ log,
104
+ events: runEventEmitter(options.emit, log),
105
+ ...(options.signal ? { signal: options.signal } : {}),
106
+ ...(options.runId !== undefined ? { runId: options.runId } : {}),
107
+ });
92
108
  return result.text;
93
109
  }
94
110
  /**
@@ -103,122 +119,176 @@ export async function runNativeLoop(req, loopCtx) {
103
119
  const { model, system, userPrompt, tools } = req;
104
120
  const { maxSteps, maxDurationMs } = req.limits;
105
121
  const log = loopCtx.log;
106
- const ctx = { log, budget: { maxDurationMs } };
122
+ // One signal for the whole run: the caller's cancel merged with the run's own
123
+ // deadline. It reaches every model call (through `InvokeContext.signal`, down
124
+ // to the provider's HTTP request) and every tool (through `ToolContext`), so
125
+ // neither a cancel nor the deadline has to wait for an in-flight step to end.
126
+ const deadline = deadlineSignal(maxDurationMs);
127
+ const signal = loopCtx.signal ? AbortSignal.any([loopCtx.signal, deadline]) : deadline;
128
+ const ctx = { log, signal, budget: { maxDurationMs } };
107
129
  // The emitter is the caller's: `seq` is per RUN, not per loop, so a loop that
108
130
  // made its own would restart the numbering mid-stream.
109
131
  const events = loopCtx.events;
110
132
  const byName = new Map(tools.map((t) => [t.spec.name, t]));
111
133
  const specs = toToolSpecs(tools);
112
134
  const messages = [{ role: "user", text: userPrompt }];
113
- const deadline = Date.now() + maxDurationMs;
135
+ const deadlineAt = Date.now() + maxDurationMs;
114
136
  let finalText = "";
115
137
  let lastAssistantText = "";
116
138
  let exhausted = false;
117
139
  let timedOut = false;
118
140
  let stepsTaken = 0;
119
- // A throw propagates untouched; `runWithEvents` closes the stream around it,
120
- // so every loop gets that property rather than only this one.
121
- for (let step = 0; step < maxSteps; step += 1) {
122
- // Wall-clock budget: enforced between steps so an in-flight provider/tool
123
- // call isn't interrupted mid-flight, mirroring how maxSteps stops cleanly.
124
- // Because the check is only between steps, a single step can overshoot the
125
- // budget by its entire duration: up to (provider timeout × maxRetries) for the
126
- // converse call plus the time to execute all of that step's tool calls. So the
127
- // effective ceiling is `maxDurationMs + one full step`, not `maxDurationMs`.
128
- if (Date.now() >= deadline) {
129
- timedOut = true;
130
- log(`reached run time budget (${maxDurationMs}ms) after ${step} step(s)`);
141
+ let step = 0;
142
+ /**
143
+ * The run was stopped mid-flight. `signal.reason` says by whom: the deadline
144
+ * signal's own reason means the budget ran out (`timed_out`); anything else
145
+ * is the caller's (`canceled`). Either way it is a clean stop — the
146
+ * accumulated prose comes back with a note, no summary call is spent, and
147
+ * nothing is thrown, so `runWithEvents` never reports it as `failed`.
148
+ */
149
+ const stopped = () => {
150
+ const accumulated = lastAssistantText || "(no output before the run was stopped)";
151
+ if (signal.reason === deadline.reason) {
152
+ log(`reached run time budget (${maxDurationMs}ms) during step ${step}; in-flight work aborted`);
131
153
  events.emit({ type: "run.budget_exhausted", kind: "duration", step });
132
- break;
133
- }
134
- const { value: turn } = await model.invoke({ system, messages, tools: specs }, ctx);
135
- stepsTaken = step + 1;
136
- messages.push({ role: "assistant", text: turn.text, toolCalls: turn.toolCalls });
137
- if (turn.text)
138
- lastAssistantText = turn.text;
139
- events.emit({
140
- type: "model.turn",
141
- step,
142
- text: turn.text,
143
- toolCalls: turn.toolCalls.map((c) => ({ id: c.id, name: c.name })),
144
- });
145
- if (turn.toolCalls.length === 0) {
146
- finalText = turn.text;
147
- break;
154
+ const text = `${accumulated}\n\n[run stopped: wall-clock budget of ${maxDurationMs}ms exceeded]`;
155
+ return { text, steps: stepsTaken, outcome: "timed_out" };
148
156
  }
149
- const results = [];
150
- for (const call of turn.toolCalls) {
151
- const tool = byName.get(call.name);
152
- if (!tool) {
153
- results.push({
154
- toolCallId: call.id,
155
- content: `unknown tool: ${call.name}`,
156
- isError: true,
157
- });
158
- log(`tool ${call.name} (unknown)`);
159
- events.emit({
160
- type: "tool.failed",
161
- step,
162
- callId: call.id,
163
- name: call.name,
164
- reason: "unknown_tool",
165
- error: `unknown tool: ${call.name}`,
166
- });
167
- continue;
157
+ const why = describeReason(signal.reason);
158
+ log(`run canceled during step ${step}${why ? `: ${why}` : ""}`);
159
+ const text = `${accumulated}\n\n[run stopped: canceled${why ? ` (${why})` : ""}]`;
160
+ return { text, steps: stepsTaken, outcome: "canceled" };
161
+ };
162
+ try {
163
+ for (; step < maxSteps; step += 1) {
164
+ // Wall-clock budget, checked between steps. The deadline signal also
165
+ // aborts an in-flight model request or tool, so a step can no longer
166
+ // overshoot the budget by its whole duration — only by however long a
167
+ // call that ignores its signal takes to return.
168
+ if (Date.now() >= deadlineAt) {
169
+ timedOut = true;
170
+ log(`reached run time budget (${maxDurationMs}ms) after ${step} step(s)`);
171
+ events.emit({ type: "run.budget_exhausted", kind: "duration", step });
172
+ break;
168
173
  }
169
- // Emitted BEFORE execution: a process that dies mid-tool still leaves
170
- // evidence that the effect may have started, which is the one case a
171
- // rollback consumer cannot afford to infer from silence.
174
+ signal.throwIfAborted();
175
+ const turnResult = await model.invoke({ system, messages, tools: specs }, ctx);
176
+ const turn = turnResult.value;
177
+ stepsTaken = step + 1;
178
+ messages.push({ role: "assistant", text: turn.text, toolCalls: turn.toolCalls });
179
+ if (turn.text)
180
+ lastAssistantText = turn.text;
172
181
  events.emit({
173
- type: "tool.called",
182
+ type: "model.turn",
174
183
  step,
175
- callId: call.id,
176
- name: call.name,
177
- input: detach(call.input),
178
- ...undoFields(tool.meta),
184
+ text: turn.text,
185
+ toolCalls: turn.toolCalls.map((c) => ({ id: c.id, name: c.name })),
186
+ ...(turnResult.usage ? { usage: turnResult.usage } : {}),
179
187
  });
180
- try {
181
- // Uses the tool's structured executor when it has one, so a typed
182
- // payload survives alongside the string the model sees. Tools without
183
- // one take the original string path unchanged.
184
- const output = await executeTool(tool, call.input);
185
- results.push({
186
- toolCallId: call.id,
187
- content: truncate(output.content),
188
- ...(output.structured !== undefined ? { structured: output.structured } : {}),
189
- });
190
- log(`tool ${call.name} ok (${output.content.length} bytes)`);
191
- // Reversibility is copied from the tool's own metadata at call time —
192
- // the tool set can differ per run, so a consumer reading the stream
193
- // later must not have to reconstruct which registry was in play.
188
+ // A model that ignored its signal can still answer after the stop. The
189
+ // turn happened, so it is recorded above and its prose is kept, but the
190
+ // outcome is the stop's — `canceled` or `timed_out`, never `completed` —
191
+ // and none of the tools it asked for run.
192
+ if (signal.aborted)
193
+ return stopped();
194
+ if (turn.toolCalls.length === 0) {
195
+ finalText = turn.text;
196
+ break;
197
+ }
198
+ const results = [];
199
+ for (const call of turn.toolCalls) {
200
+ // Never START a tool once the run is stopping: a side effect begun
201
+ // after a cancel is the one thing a cancel must prevent.
202
+ signal.throwIfAborted();
203
+ const tool = byName.get(call.name);
204
+ if (!tool) {
205
+ results.push({
206
+ toolCallId: call.id,
207
+ content: `unknown tool: ${call.name}`,
208
+ isError: true,
209
+ });
210
+ log(`tool ${call.name} (unknown)`);
211
+ events.emit({
212
+ type: "tool.failed",
213
+ step,
214
+ callId: call.id,
215
+ name: call.name,
216
+ reason: "unknown_tool",
217
+ error: `unknown tool: ${call.name}`,
218
+ });
219
+ continue;
220
+ }
221
+ // Emitted BEFORE execution: a process that dies mid-tool still leaves
222
+ // evidence that the effect may have started, which is the one case a
223
+ // rollback consumer cannot afford to infer from silence.
194
224
  events.emit({
195
- type: "tool.succeeded",
225
+ type: "tool.called",
196
226
  step,
197
227
  callId: call.id,
198
228
  name: call.name,
199
- bytes: Buffer.byteLength(output.content, "utf8"),
229
+ input: detach(call.input),
200
230
  ...undoFields(tool.meta),
201
231
  });
232
+ try {
233
+ // Uses the tool's structured executor when it has one, so a typed
234
+ // payload survives alongside the string the model sees. Tools without
235
+ // one take the original string path unchanged.
236
+ const output = await executeTool(tool, call.input, {
237
+ signal,
238
+ callId: call.id,
239
+ ...(loopCtx.runId !== undefined ? { runId: loopCtx.runId } : {}),
240
+ });
241
+ results.push({
242
+ toolCallId: call.id,
243
+ content: truncate(output.content),
244
+ ...(output.structured !== undefined ? { structured: output.structured } : {}),
245
+ });
246
+ log(`tool ${call.name} ok (${output.content.length} bytes)`);
247
+ // Reversibility is copied from the tool's own metadata at call time —
248
+ // the tool set can differ per run, so a consumer reading the stream
249
+ // later must not have to reconstruct which registry was in play.
250
+ events.emit({
251
+ type: "tool.succeeded",
252
+ step,
253
+ callId: call.id,
254
+ name: call.name,
255
+ bytes: Buffer.byteLength(output.content, "utf8"),
256
+ ...undoFields(tool.meta),
257
+ });
258
+ }
259
+ catch (err) {
260
+ const message = err instanceof Error ? err.message : String(err);
261
+ results.push({ toolCallId: call.id, content: message, isError: true });
262
+ log(`tool ${call.name} error: ${message}`);
263
+ // Recorded even when the run is stopping: `tool.called` is already in
264
+ // the stream, and a call with no closing event looks like a crash.
265
+ events.emit({
266
+ type: "tool.failed",
267
+ step,
268
+ callId: call.id,
269
+ name: call.name,
270
+ // A tool stopped by the run's cancel/deadline did not break.
271
+ // Only when the error IS the stop, not a failure that coincided with it.
272
+ reason: isAbortError(err, signal) ? "aborted" : "threw",
273
+ error: message,
274
+ });
275
+ }
202
276
  }
203
- catch (err) {
204
- const message = err instanceof Error ? err.message : String(err);
205
- results.push({ toolCallId: call.id, content: message, isError: true });
206
- log(`tool ${call.name} error: ${message}`);
207
- events.emit({
208
- type: "tool.failed",
209
- step,
210
- callId: call.id,
211
- name: call.name,
212
- reason: "threw",
213
- error: message,
214
- });
277
+ messages.push({ role: "tool", results });
278
+ if (step === maxSteps - 1) {
279
+ exhausted = true;
280
+ events.emit({ type: "run.budget_exhausted", kind: "steps", step });
215
281
  }
216
282
  }
217
- messages.push({ role: "tool", results });
218
- if (step === maxSteps - 1) {
219
- exhausted = true;
220
- events.emit({ type: "run.budget_exhausted", kind: "steps", step });
221
- }
283
+ }
284
+ catch (err) {
285
+ // Only an error that IS the abort (its reason, an SDK abort error, or
286
+ // `throwIfAborted` above) is a clean stop. A real failure that merely
287
+ // coincides with the abort propagates untouched, and `runWithEvents`
288
+ // closes the stream around it as `failed`.
289
+ if (isAbortError(err, signal))
290
+ return stopped();
291
+ throw err;
222
292
  }
223
293
  // Ran out of time mid-loop: don't spend more of the (already-blown) budget on
224
294
  // a summary call — just return whatever prose we accumulated, clearly noted.
@@ -231,16 +301,43 @@ export async function runNativeLoop(req, loopCtx) {
231
301
  // can summarize, falling back to its last prose rather than losing the work.
232
302
  if (!finalText && exhausted) {
233
303
  log(`reached max steps (${maxSteps}); requesting a final summary`);
304
+ // A run stopped while the last tools ran gets no summary call: the caller
305
+ // asked it to stop, or its time is already gone.
306
+ if (signal.aborted)
307
+ return stopped();
234
308
  try {
235
- const summary = (await model.invoke({ system, messages, tools: [] }, ctx)).value;
309
+ const summaryResult = await model.invoke({ system, messages, tools: [] }, ctx);
310
+ const summary = summaryResult.value;
236
311
  // Emitted like any other turn: `run.finished.text` can come from this
237
312
  // call, and a terminal event whose text traces back to no turn in the
238
313
  // transcript would break the stream's one promise.
239
- events.emit({ type: "model.turn", step: stepsTaken, text: summary.text, toolCalls: [] });
314
+ events.emit({
315
+ type: "model.turn",
316
+ step: stepsTaken,
317
+ text: summary.text,
318
+ toolCalls: [],
319
+ ...(summaryResult.usage ? { usage: summaryResult.usage } : {}),
320
+ });
240
321
  finalText = summary.text || lastAssistantText;
322
+ // Same rule as a turn: a summary that arrives after the stop is kept,
323
+ // but the run still ends with the stop's outcome.
324
+ if (signal.aborted) {
325
+ if (summary.text)
326
+ lastAssistantText = summary.text;
327
+ return stopped();
328
+ }
241
329
  }
242
330
  catch (err) {
243
- log(`final summary failed: ${err instanceof Error ? err.message : String(err)}`);
331
+ // Stopped during the summary itself: that is a cancel or a timeout, not
332
+ // a summary that failed and was absorbed.
333
+ if (isAbortError(err, signal))
334
+ return stopped();
335
+ const error = err instanceof Error ? err.message : String(err);
336
+ log(`final summary failed: ${error}`);
337
+ // The stream must not be quieter than the log: without this, a
338
+ // `run.finished` whose text fell back to an earlier turn would look
339
+ // exactly like one whose summary succeeded.
340
+ events.emit({ type: "model.turn.failed", step: stepsTaken, phase: "summary", error });
244
341
  finalText = lastAssistantText;
245
342
  }
246
343
  }
package/dist/agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,UAAU,EACV,aAAa,GAId,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,WAAW,EAAkB,MAAM,kBAAkB,CAAA;AAG9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C,iBAAiB,CAAC,CAAC,CAAC,WAAW,CAAA;IAChG,6EAA6E;IAC7E,6EAA6E;IAC7E,yDAAyD;IACzD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA;AAC7C,CAAC"}
@@ -5,10 +5,15 @@ import type { ConnectorConfig } from "../types.js";
5
5
  * with the connector's own name. Servers use it for logging and telemetry.
6
6
  */
7
7
  export declare const MCP_CLIENT_NAME = "harness-kernel";
8
+ /** Per-call options for {@link McpConnection.callTool}. */
9
+ export interface McpCallOptions {
10
+ /** Aborts the request; the SDK notifies the server that the call was cancelled. */
11
+ signal?: AbortSignal;
12
+ }
8
13
  /** A live MCP connection, narrowed to what the tool registry needs. */
9
14
  export interface McpConnection {
10
15
  listTools(): Promise<unknown>;
11
- callTool(name: string, args?: Record<string, unknown>): Promise<unknown>;
16
+ callTool(name: string, args?: Record<string, unknown>, opts?: McpCallOptions): Promise<unknown>;
12
17
  close(): Promise<void>;
13
18
  }
14
19
  /** Connect to an MCP connector using the transport implied by its config. */
@@ -1 +1 @@
1
- {"version":3,"file":"mcpClient.d.ts","sourceRoot":"","sources":["../../src/connectors/mcpClient.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,eAAe,mBAAmB,CAAA;AAE/C,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACxE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAwCD,6EAA6E;AAC7E,wBAAsB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAEhF;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,aAAa,CAAC,CASxB"}
1
+ {"version":3,"file":"mcpClient.d.ts","sourceRoot":"","sources":["../../src/connectors/mcpClient.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,eAAe,mBAAmB,CAAA;AAE/C,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,mFAAmF;IACnF,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAwCD,6EAA6E;AAC7E,wBAAsB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAEhF;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,aAAa,CAAC,CAcxB"}
@@ -56,7 +56,7 @@ export async function connectWithTransport(name, transport) {
56
56
  await client.connect(transport);
57
57
  return {
58
58
  listTools: () => client.listTools(),
59
- callTool: (toolName, args = {}) => client.callTool({ name: toolName, arguments: args }),
59
+ callTool: (toolName, args = {}, opts) => client.callTool({ name: toolName, arguments: args }, undefined, opts?.signal ? { signal: opts.signal } : undefined),
60
60
  close: () => client.close(),
61
61
  };
62
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mcpClient.js","sourceRoot":"","sources":["../../src/connectors/mcpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAA;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAI5E;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAAA;AAS/C,kFAAkF;AAClF,SAAS,UAAU,CAAC,MAAuB;IACzC,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACxD,OAAO,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAA;IACvF,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC;AAED,SAAS,cAAc,CAAC,MAAuB;IAC7C,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,CAAC,IAAI,sCAAsC,CAAC,CAAA;YACjF,CAAC;YACD,0DAA0D;YAC1D,MAAM,GAAG,GACP,MAAM,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK;gBACjD,CAAC,CAAC,EAAE,GAAG,qBAAqB,EAAE,EAAE,cAAc,EAAE,MAAM,CAAC,IAAI,C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