@rarebit-one/harness-kernel 0.7.0 → 0.9.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 (106) hide show
  1. package/README.md +83 -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 +49 -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 +36 -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 +19 -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/index.d.ts +7 -0
  34. package/dist/engines/index.d.ts.map +1 -1
  35. package/dist/engines/index.js +4 -1
  36. package/dist/engines/index.js.map +1 -1
  37. package/dist/engines/native.d.ts +9 -1
  38. package/dist/engines/native.d.ts.map +1 -1
  39. package/dist/engines/native.js +130 -5
  40. package/dist/engines/native.js.map +1 -1
  41. package/dist/engines/types.d.ts +29 -1
  42. package/dist/engines/types.d.ts.map +1 -1
  43. package/dist/events.d.ts +61 -10
  44. package/dist/events.d.ts.map +1 -1
  45. package/dist/events.js.map +1 -1
  46. package/dist/index.d.ts +7 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +4 -1
  49. package/dist/index.js.map +1 -1
  50. package/dist/loop.d.ts +21 -2
  51. package/dist/loop.d.ts.map +1 -1
  52. package/dist/loop.js +7 -2
  53. package/dist/loop.js.map +1 -1
  54. package/dist/models/chat.d.ts +6 -2
  55. package/dist/models/chat.d.ts.map +1 -1
  56. package/dist/models/chat.js +15 -9
  57. package/dist/models/chat.js.map +1 -1
  58. package/dist/models/types.d.ts +15 -1
  59. package/dist/models/types.d.ts.map +1 -1
  60. package/dist/models/types.js.map +1 -1
  61. package/dist/primitives/codeExec.d.ts +7 -0
  62. package/dist/primitives/codeExec.d.ts.map +1 -1
  63. package/dist/primitives/codeExec.js +32 -4
  64. package/dist/primitives/codeExec.js.map +1 -1
  65. package/dist/primitives/http.d.ts +6 -0
  66. package/dist/primitives/http.d.ts.map +1 -1
  67. package/dist/primitives/http.js +28 -11
  68. package/dist/primitives/http.js.map +1 -1
  69. package/dist/private.d.ts +76 -0
  70. package/dist/private.d.ts.map +1 -0
  71. package/dist/private.js +245 -0
  72. package/dist/private.js.map +1 -0
  73. package/dist/processGroup.d.ts +16 -0
  74. package/dist/processGroup.d.ts.map +1 -0
  75. package/dist/processGroup.js +39 -0
  76. package/dist/processGroup.js.map +1 -0
  77. package/dist/providers/anthropic.d.ts +12 -2
  78. package/dist/providers/anthropic.d.ts.map +1 -1
  79. package/dist/providers/anthropic.js +30 -3
  80. package/dist/providers/anthropic.js.map +1 -1
  81. package/dist/providers/mock.d.ts +2 -2
  82. package/dist/providers/mock.d.ts.map +1 -1
  83. package/dist/providers/mock.js +5 -1
  84. package/dist/providers/mock.js.map +1 -1
  85. package/dist/providers/openai.d.ts +11 -2
  86. package/dist/providers/openai.d.ts.map +1 -1
  87. package/dist/providers/openai.js +25 -5
  88. package/dist/providers/openai.js.map +1 -1
  89. package/dist/providers/types.d.ts +21 -1
  90. package/dist/providers/types.d.ts.map +1 -1
  91. package/dist/signals.d.ts +46 -0
  92. package/dist/signals.d.ts.map +1 -0
  93. package/dist/signals.js +72 -0
  94. package/dist/signals.js.map +1 -0
  95. package/dist/tools/metadata.d.ts +18 -2
  96. package/dist/tools/metadata.d.ts.map +1 -1
  97. package/dist/tools/metadata.js +7 -0
  98. package/dist/tools/metadata.js.map +1 -1
  99. package/dist/tools/modelTool.d.ts.map +1 -1
  100. package/dist/tools/modelTool.js +7 -3
  101. package/dist/tools/modelTool.js.map +1 -1
  102. package/dist/tools/registry.d.ts +24 -5
  103. package/dist/tools/registry.d.ts.map +1 -1
  104. package/dist/tools/registry.js +43 -12
  105. package/dist/tools/registry.js.map +1 -1
  106. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/primitives/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEpD,iFAAiF;AACjF,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAAA;AAI1F;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,WAAW,CAAA;AAE1C,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAA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C,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAO3D;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACpD,OAAO,CAAC,gBAAgB,CAAC,CA6B3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,KAAK,CAW5D;AA8ED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CA+DhF"}
@@ -115,32 +115,47 @@ export function pinnedAgent(records) {
115
115
  * A fresh dispatcher is built per hop (each hop is validated + pinned to its own
116
116
  * address) and closed in `done()` so connections aren't reused across hosts.
117
117
  */
118
- async function fetchWithTimeout(fetchImpl, target, init, records, timeoutMs) {
118
+ async function fetchWithTimeout(fetchImpl, target, init, records, timeoutMs, signal) {
119
+ // Same error whether the signal fired before this hop or during it.
120
+ if (signal?.aborted)
121
+ throw new Error(`http aborted: ${target}`, { cause: signal.reason });
119
122
  const controller = new AbortController();
120
123
  const agent = pinnedAgent(records);
121
124
  let timedOut = false;
125
+ let aborted = false;
122
126
  const timer = setTimeout(() => {
123
127
  timedOut = true;
124
128
  controller.abort();
125
129
  }, timeoutMs);
130
+ // The caller's signal drives the SAME controller as the timeout, so whatever
131
+ // the timeout bounds (headers and the streamed body) an abort bounds too.
132
+ const onAbort = () => {
133
+ aborted = true;
134
+ controller.abort(signal?.reason);
135
+ };
136
+ signal?.addEventListener("abort", onAbort, { once: true });
126
137
  const closeAgent = () => {
127
138
  void agent.close().catch(() => { });
128
139
  };
140
+ const release = () => {
141
+ clearTimeout(timer);
142
+ signal?.removeEventListener("abort", onAbort);
143
+ closeAgent();
144
+ };
129
145
  try {
130
146
  const res = await fetchImpl(target, { ...init, signal: controller.signal, dispatcher: agent });
131
147
  return {
132
148
  res,
133
149
  controller,
134
150
  timedOut: () => timedOut,
135
- done: () => {
136
- clearTimeout(timer);
137
- closeAgent();
138
- },
151
+ aborted: () => aborted,
152
+ done: release,
139
153
  };
140
154
  }
141
155
  catch (err) {
142
- clearTimeout(timer);
143
- closeAgent();
156
+ release();
157
+ if (aborted)
158
+ throw new Error(`http aborted: ${target}`, { cause: err });
144
159
  if (timedOut) {
145
160
  throw new Error(`http timeout after ${timeoutMs}ms: ${target}`, { cause: err });
146
161
  }
@@ -165,11 +180,11 @@ async function fetchWithTimeout(fetchImpl, target, init, records, timeoutMs) {
165
180
  * allowlist for untrusted callers regardless.
166
181
  */
167
182
  export async function httpFetch(options) {
168
- const { url, method = "GET", headers, body, allowHosts, maxBytes = DEFAULT_MAX_BYTES, maxRedirects = DEFAULT_MAX_REDIRECTS, timeoutMs = defaultTimeoutMs(), lookup = defaultLookup, fetchImpl = undiciFetch, } = options;
183
+ const { url, method = "GET", headers, body, allowHosts, maxBytes = DEFAULT_MAX_BYTES, maxRedirects = DEFAULT_MAX_REDIRECTS, timeoutMs = defaultTimeoutMs(), lookup = defaultLookup, fetchImpl = undiciFetch, signal, } = options;
169
184
  const assertSafe = (target) => assertSafeUrl(target, { allowHosts, lookup });
170
185
  let currentUrl = url;
171
186
  let records = await assertSafe(currentUrl);
172
- let hop = await fetchWithTimeout(fetchImpl, currentUrl, { method, headers, body, redirect: "manual" }, records, timeoutMs);
187
+ let hop = await fetchWithTimeout(fetchImpl, currentUrl, { method, headers, body, redirect: "manual" }, records, timeoutMs, signal);
173
188
  let hops = 0;
174
189
  while (hop.res.status >= 300 && hop.res.status < 400 && hop.res.headers.has("location")) {
175
190
  // Cancel the unread redirect body so the socket isn't left half-open before
@@ -181,7 +196,7 @@ export async function httpFetch(options) {
181
196
  const next = new URL(hop.res.headers.get("location"), currentUrl).toString();
182
197
  records = await assertSafe(next); // validate AND re-pin the new hop's address
183
198
  currentUrl = next;
184
- hop = await fetchWithTimeout(fetchImpl, currentUrl, { method, headers, redirect: "manual" }, records, timeoutMs);
199
+ hop = await fetchWithTimeout(fetchImpl, currentUrl, { method, headers, redirect: "manual" }, records, timeoutMs, signal);
185
200
  hops += 1;
186
201
  }
187
202
  const res = hop.res;
@@ -203,7 +218,7 @@ export async function httpFetch(options) {
203
218
  * sends headers then drip-feeds the body still can't stall the run.
204
219
  */
205
220
  async function readBodyCapped(hop, target, maxBytes) {
206
- const { res, controller, timedOut, done } = hop;
221
+ const { res, controller, timedOut, aborted, done } = hop;
207
222
  try {
208
223
  if (!res.body)
209
224
  return await res.text();
@@ -228,6 +243,8 @@ async function readBodyCapped(hop, target, maxBytes) {
228
243
  catch (err) {
229
244
  // The timer aborts the controller, which surfaces here as an abort/read
230
245
  // error — translate it to the same clear timeout message as the header phase.
246
+ if (aborted())
247
+ throw new Error(`http aborted: ${target}`, { cause: err });
231
248
  if (timedOut() || controller.signal.aborted) {
232
249
  throw new Error(`http timeout: ${target}`, { cause: err });
233
250
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/primitives/http.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,GAAG,MAAM,mBAAmB,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AAKpD,MAAM,aAAa,GAAW,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;AAyCvE,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AACzC,MAAM,qBAAqB,GAAG,CAAC,CAAA;AAC/B,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAElC,6EAA6E;AAC7E,SAAS,gBAAgB;IACvB,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,GA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,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,CAAA,CAAC,UAAU;IAC3D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA,CAAC,UAAU;IAClD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG;QAAE,OAAO,IAAI,CAAA,CAAC,mBAAmB;IACrE,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,YAAY,CAAC,EAAU;IAC9B,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAClD,qFAAqF;IACrF,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;IACvD,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC;QAAE,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,OAAO,CACL,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAC9F,CAAA;AACH,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Private runs: the run's observable channels carry phase codes only.
3
+ *
4
+ * A run marked `RunSpec.private` works on material its caller must not let out
5
+ * of the host: the tool arguments, tool results and model prose of such a run
6
+ * are the material itself. Everything else in the kernel assumes the opposite —
7
+ * `log` lines quote tool errors and cancel reasons, and the event stream carries
8
+ * raw tool arguments and every turn's text — so a private run cannot simply
9
+ * reuse those channels and hope each sink redacts.
10
+ *
11
+ * Instead the channels are narrowed at the source. {@link privateRunChannels}
12
+ * wraps a caller's `log` and event sink so that:
13
+ *
14
+ * - **`log` receives no free text at all.** Every line the kernel (or a loop,
15
+ * a context provider, a connector) would have written is dropped, and one
16
+ * fixed-vocabulary phase line is written per event instead.
17
+ * - **Events keep their shape, `seq` and `at`, but lose their content.**
18
+ * Model text, tool arguments, error messages and the final text are
19
+ * removed; the event is marked `redacted: true` so a consumer can tell an
20
+ * empty field from a withheld one. A tool name the run did not register (a
21
+ * name the model made up, which is model output) is replaced as well, and
22
+ * every tool-call id (provider output) becomes a per-run `call-<n>`
23
+ * surrogate. Events are rebuilt from an allow-list of fields, so anything
24
+ * the kernel does not know about is dropped rather than forwarded.
25
+ *
26
+ * What survives is deliberately structural: event types, step numbers, the
27
+ * registered tool names, outcomes, budgets, numeric usage and result sizes in
28
+ * bytes. That is enough for a caller to show progress and account for cost, and
29
+ * none of it is the run's material.
30
+ *
31
+ * The run's return value is NOT narrowed: `EngineResult.text` goes back to the
32
+ * caller that started the run, which decides where (if anywhere) it is written.
33
+ */
34
+ import type { RunEventSink } from "./events.js";
35
+ /** What every withheld string field is replaced with. */
36
+ export declare const PRIVATE_REDACTION = "[redacted]";
37
+ /**
38
+ * Thrown by an engine in place of whatever a private run threw. The original
39
+ * error's message can quote the run's material (a tool's error, a provider's
40
+ * echo of the prompt), so it is not carried — not as the message and not as
41
+ * `cause`, which error reporters walk and upload. Only the phase survives.
42
+ */
43
+ export declare class PrivateRunError extends Error {
44
+ /** Where the run failed: setting the run up, or inside the loop. */
45
+ readonly phase: "setup" | "loop";
46
+ constructor(phase: "setup" | "loop");
47
+ }
48
+ /** The narrowed channels for one private run. */
49
+ export interface PrivateRunChannels {
50
+ /** Drops every free-text line. Hand this to anything that would log. */
51
+ log: (line: string) => void;
52
+ /**
53
+ * Redacts each event, forwards it to the caller's sink (if any), and writes
54
+ * its phase line to the caller's `log`. Always defined, so the phase lines
55
+ * appear even when the caller attached no sink.
56
+ */
57
+ emit: RunEventSink;
58
+ }
59
+ /**
60
+ * Narrow a run's `log` and event sink for a private run. One instance per run:
61
+ * it learns the registered tool names from that run's `run.started`.
62
+ */
63
+ export declare function privateRunChannels(log: (line: string) => void, sink?: RunEventSink): PrivateRunChannels;
64
+ /**
65
+ * The `supports()` refusal every out-of-process engine gives a private run.
66
+ * Such an engine hands the run's material to a harness process the kernel does
67
+ * not observe, so it cannot keep the private-run guarantees — and per the
68
+ * fail-loud rule it refuses rather than running without them.
69
+ */
70
+ export declare function refusePrivateRun(engine: string, spec: {
71
+ private?: boolean | undefined;
72
+ }): {
73
+ ok: false;
74
+ reason: string;
75
+ } | undefined;
76
+ //# sourceMappingURL=private.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private.d.ts","sourceRoot":"","sources":["../src/private.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,aAAa,CAAA;AAGzD,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,eAAe,CAAA;AAK7C;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAA;gBAEpB,KAAK,EAAE,OAAO,GAAG,MAAM;CAKpC;AAED,iDAAiD;AACjD,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3B;;;;OAIG;IACH,IAAI,EAAE,YAAY,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC3B,IAAI,CAAC,EAAE,YAAY,GAClB,kBAAkB,CAoHpB;AA6ED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GACtC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAM3C"}
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Private runs: the run's observable channels carry phase codes only.
3
+ *
4
+ * A run marked `RunSpec.private` works on material its caller must not let out
5
+ * of the host: the tool arguments, tool results and model prose of such a run
6
+ * are the material itself. Everything else in the kernel assumes the opposite —
7
+ * `log` lines quote tool errors and cancel reasons, and the event stream carries
8
+ * raw tool arguments and every turn's text — so a private run cannot simply
9
+ * reuse those channels and hope each sink redacts.
10
+ *
11
+ * Instead the channels are narrowed at the source. {@link privateRunChannels}
12
+ * wraps a caller's `log` and event sink so that:
13
+ *
14
+ * - **`log` receives no free text at all.** Every line the kernel (or a loop,
15
+ * a context provider, a connector) would have written is dropped, and one
16
+ * fixed-vocabulary phase line is written per event instead.
17
+ * - **Events keep their shape, `seq` and `at`, but lose their content.**
18
+ * Model text, tool arguments, error messages and the final text are
19
+ * removed; the event is marked `redacted: true` so a consumer can tell an
20
+ * empty field from a withheld one. A tool name the run did not register (a
21
+ * name the model made up, which is model output) is replaced as well, and
22
+ * every tool-call id (provider output) becomes a per-run `call-<n>`
23
+ * surrogate. Events are rebuilt from an allow-list of fields, so anything
24
+ * the kernel does not know about is dropped rather than forwarded.
25
+ *
26
+ * What survives is deliberately structural: event types, step numbers, the
27
+ * registered tool names, outcomes, budgets, numeric usage and result sizes in
28
+ * bytes. That is enough for a caller to show progress and account for cost, and
29
+ * none of it is the run's material.
30
+ *
31
+ * The run's return value is NOT narrowed: `EngineResult.text` goes back to the
32
+ * caller that started the run, which decides where (if anywhere) it is written.
33
+ */
34
+ /** What every withheld string field is replaced with. */
35
+ export const PRIVATE_REDACTION = "[redacted]";
36
+ /** Stands in for a tool name the run never registered (model output). */
37
+ const UNREGISTERED_TOOL = "(unregistered)";
38
+ /**
39
+ * Thrown by an engine in place of whatever a private run threw. The original
40
+ * error's message can quote the run's material (a tool's error, a provider's
41
+ * echo of the prompt), so it is not carried — not as the message and not as
42
+ * `cause`, which error reporters walk and upload. Only the phase survives.
43
+ */
44
+ export class PrivateRunError extends Error {
45
+ /** Where the run failed: setting the run up, or inside the loop. */
46
+ phase;
47
+ constructor(phase) {
48
+ super(`private run failed during ${phase} (details withheld)`);
49
+ this.name = "PrivateRunError";
50
+ this.phase = phase;
51
+ }
52
+ }
53
+ /**
54
+ * Narrow a run's `log` and event sink for a private run. One instance per run:
55
+ * it learns the registered tool names from that run's `run.started`.
56
+ */
57
+ export function privateRunChannels(log, sink) {
58
+ let registered;
59
+ const toolName = (name) => (registered?.has(name) ? name : UNREGISTERED_TOOL);
60
+ // Tool-call ids come from the provider's output, so they are model output
61
+ // too. Each is replaced by a surrogate assigned in first-seen order; the map
62
+ // lives for the run, so a turn's call and its tool events still correlate.
63
+ const surrogates = new Map();
64
+ const callId = (id) => {
65
+ let surrogate = surrogates.get(id);
66
+ if (surrogate === undefined) {
67
+ surrogate = `call-${surrogates.size + 1}`;
68
+ surrogates.set(id, surrogate);
69
+ }
70
+ return surrogate;
71
+ };
72
+ // Each redacted event is REBUILT from an allow-list of fields rather than
73
+ // spread from the original: a field the kernel does not know about (one a
74
+ // custom loop added, say) is dropped, never forwarded. Enum-typed fields are
75
+ // re-checked at runtime, since a custom loop's value is only as narrow as
76
+ // its author's types.
77
+ const base = (event) => ({
78
+ seq: event.seq,
79
+ at: event.at,
80
+ redacted: true,
81
+ });
82
+ const redact = (event) => {
83
+ switch (event.type) {
84
+ case "run.started":
85
+ registered = new Set(event.tools);
86
+ return {
87
+ ...base(event),
88
+ type: event.type,
89
+ maxSteps: event.maxSteps,
90
+ maxDurationMs: event.maxDurationMs,
91
+ tools: [...event.tools],
92
+ };
93
+ case "model.turn": {
94
+ const usage = redactUsage(event.usage);
95
+ return {
96
+ ...base(event),
97
+ type: event.type,
98
+ step: event.step,
99
+ text: "",
100
+ toolCalls: event.toolCalls.map((c) => ({ id: callId(c.id), name: toolName(c.name) })),
101
+ ...(usage ? { usage } : {}),
102
+ };
103
+ }
104
+ case "model.turn.failed":
105
+ return {
106
+ ...base(event),
107
+ type: event.type,
108
+ step: event.step,
109
+ phase: "summary",
110
+ error: PRIVATE_REDACTION,
111
+ };
112
+ case "tool.called":
113
+ return {
114
+ ...base(event),
115
+ type: event.type,
116
+ step: event.step,
117
+ callId: callId(event.callId),
118
+ name: toolName(event.name),
119
+ input: {},
120
+ ...undoFields(event),
121
+ };
122
+ case "tool.succeeded":
123
+ return {
124
+ ...base(event),
125
+ type: event.type,
126
+ step: event.step,
127
+ callId: callId(event.callId),
128
+ name: toolName(event.name),
129
+ bytes: event.bytes,
130
+ ...undoFields(event),
131
+ };
132
+ case "tool.failed":
133
+ return {
134
+ ...base(event),
135
+ type: event.type,
136
+ step: event.step,
137
+ callId: callId(event.callId),
138
+ name: toolName(event.name),
139
+ reason: oneOf(event.reason, FAILURE_REASONS, "threw"),
140
+ error: PRIVATE_REDACTION,
141
+ };
142
+ case "run.budget_exhausted":
143
+ return {
144
+ ...base(event),
145
+ type: event.type,
146
+ kind: oneOf(event.kind, BUDGET_KINDS, "steps"),
147
+ step: event.step,
148
+ };
149
+ case "run.finished":
150
+ // `text` is the run's final prose; dropped rather than blanked, the same
151
+ // way the failure path omits it.
152
+ return {
153
+ ...base(event),
154
+ type: event.type,
155
+ outcome: oneOf(event.outcome, OUTCOMES, "failed"),
156
+ ...(event.steps !== undefined ? { steps: event.steps } : {}),
157
+ ...(event.error !== undefined ? { error: PRIVATE_REDACTION } : {}),
158
+ };
159
+ }
160
+ };
161
+ return {
162
+ log: () => { },
163
+ emit(event) {
164
+ const redacted = redact(event);
165
+ log(phaseLine(redacted));
166
+ sink?.(redacted);
167
+ },
168
+ };
169
+ }
170
+ const FAILURE_REASONS = ["threw", "unknown_tool", "aborted"];
171
+ const BUDGET_KINDS = ["steps", "duration"];
172
+ const OUTCOMES = ["completed", "steps_exhausted", "timed_out", "canceled", "failed"];
173
+ /** `value` when it is one of `allowed`, else `fallback`. */
174
+ function oneOf(value, allowed, fallback) {
175
+ return allowed.includes(value) ? value : fallback;
176
+ }
177
+ /** Numbers only. A unit-usage `unit` label is provider-supplied text, so it goes. */
178
+ function redactUsage(usage) {
179
+ if (!usage)
180
+ return undefined;
181
+ if ("units" in usage)
182
+ return typeof usage.units === "number" ? { units: usage.units } : undefined;
183
+ const out = {};
184
+ for (const key of [
185
+ "inputTokens",
186
+ "outputTokens",
187
+ "totalTokens",
188
+ "cacheReadTokens",
189
+ "cacheWriteTokens",
190
+ ]) {
191
+ const n = usage[key];
192
+ if (typeof n === "number")
193
+ out[key] = n;
194
+ }
195
+ return out;
196
+ }
197
+ /**
198
+ * The reversibility fields, copied from the tool's own registered metadata
199
+ * (application-supplied, never model output), each only when declared.
200
+ */
201
+ function undoFields(event) {
202
+ return {
203
+ ...(typeof event.reversible === "boolean" ? { reversible: event.reversible } : {}),
204
+ ...(event.undoToolName !== undefined ? { undoToolName: event.undoToolName } : {}),
205
+ ...(event.undoWindowSeconds !== undefined
206
+ ? { undoWindowSeconds: event.undoWindowSeconds }
207
+ : {}),
208
+ ...(event.replay === "safe" || event.replay === "unsafe" ? { replay: event.replay } : {}),
209
+ };
210
+ }
211
+ /** The one log line a redacted event becomes: fixed keys, structural values. */
212
+ function phaseLine(event) {
213
+ switch (event.type) {
214
+ case "run.started":
215
+ return `phase=${event.type} tools=${event.tools.length} max_steps=${event.maxSteps}`;
216
+ case "model.turn":
217
+ return `phase=${event.type} step=${event.step} tool_calls=${event.toolCalls.length}`;
218
+ case "model.turn.failed":
219
+ return `phase=${event.type} step=${event.step} during=${event.phase}`;
220
+ case "tool.called":
221
+ case "tool.succeeded":
222
+ return `phase=${event.type} step=${event.step} tool=${event.name}`;
223
+ case "tool.failed":
224
+ return `phase=${event.type} step=${event.step} tool=${event.name} reason=${event.reason}`;
225
+ case "run.budget_exhausted":
226
+ return `phase=${event.type} step=${event.step} kind=${event.kind}`;
227
+ case "run.finished":
228
+ return `phase=${event.type} outcome=${event.outcome}${event.steps !== undefined ? ` steps=${event.steps}` : ""}`;
229
+ }
230
+ }
231
+ /**
232
+ * The `supports()` refusal every out-of-process engine gives a private run.
233
+ * Such an engine hands the run's material to a harness process the kernel does
234
+ * not observe, so it cannot keep the private-run guarantees — and per the
235
+ * fail-loud rule it refuses rather than running without them.
236
+ */
237
+ export function refusePrivateRun(engine, spec) {
238
+ if (!spec.private)
239
+ return undefined;
240
+ return {
241
+ ok: false,
242
+ reason: `${engine} engine cannot run a private run: only the in-process native engine keeps its material off the run's log and event channels`,
243
+ };
244
+ }
245
+ //# sourceMappingURL=private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private.js","sourceRoot":"","sources":["../src/private.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAKH,yDAAyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAA;AAE7C,yEAAyE;AACzE,MAAM,iBAAiB,GAAG,gBAAgB,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,oEAAoE;IAC3D,KAAK,CAAkB;IAEhC,YAAY,KAAuB;QACjC,KAAK,CAAC,6BAA6B,KAAK,qBAAqB,CAAC,CAAA;QAC9D,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAcD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAA2B,EAC3B,IAAmB;IAEnB,IAAI,UAAmC,CAAA;IACvC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;IAE7F,0EAA0E;IAC1E,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC5C,MAAM,MAAM,GAAG,CAA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OAAO,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,CAAA;QAC3F,KAAK,sBAAsB;YACzB,OAAO,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,EAAE,CAAA;QACpE,KAAK,cAAc;YACjB,OAAO,SAAS,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,OAAO,GACjD,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EACxD,EAAE,CAAA;IACN,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,IAAuC;IAEvC,IAAI,CAAC,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IACnC,OAAO;QACL,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,GAAG,MAAM,6HAA6H;KAC/I,CAAA;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Internal: stop a child process that leads its own process group (spawned
3
+ * with `detached: true`). Not exported from `index.ts`.
4
+ */
5
+ import type { ChildProcess } from "node:child_process";
6
+ /** How long a stopped harness gets to exit on SIGTERM before SIGKILL. */
7
+ export declare const DEFAULT_STOP_GRACE_MS = 5000;
8
+ /**
9
+ * SIGTERM the group, wait up to `graceMs` for the leader to exit, then SIGKILL
10
+ * whatever remains of the group — unconditionally, so a descendant that
11
+ * ignored SIGTERM (or outlived its parent) cannot keep running after this
12
+ * resolves. SIGKILL cannot be ignored, so when this resolves nothing in the
13
+ * group is still executing.
14
+ */
15
+ export declare function terminateProcessGroup(child: ChildProcess, graceMs: number): Promise<void>;
16
+ //# sourceMappingURL=processGroup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processGroup.d.ts","sourceRoot":"","sources":["../src/processGroup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,OAAQ,CAAA;AAe1C;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAa/F"}
@@ -0,0 +1,39 @@
1
+ /** How long a stopped harness gets to exit on SIGTERM before SIGKILL. */
2
+ export const DEFAULT_STOP_GRACE_MS = 5_000;
3
+ /** Signal the whole group; fall back to the leader if the group is gone. */
4
+ function signalGroup(child, sig) {
5
+ try {
6
+ if (child.pid !== undefined)
7
+ process.kill(-child.pid, sig);
8
+ }
9
+ catch {
10
+ try {
11
+ child.kill(sig);
12
+ }
13
+ catch {
14
+ // already gone
15
+ }
16
+ }
17
+ }
18
+ /**
19
+ * SIGTERM the group, wait up to `graceMs` for the leader to exit, then SIGKILL
20
+ * whatever remains of the group — unconditionally, so a descendant that
21
+ * ignored SIGTERM (or outlived its parent) cannot keep running after this
22
+ * resolves. SIGKILL cannot be ignored, so when this resolves nothing in the
23
+ * group is still executing.
24
+ */
25
+ export async function terminateProcessGroup(child, graceMs) {
26
+ const exited = () => child.exitCode !== null || child.signalCode !== null;
27
+ signalGroup(child, "SIGTERM");
28
+ if (!exited()) {
29
+ await new Promise((resolve) => {
30
+ const timer = setTimeout(resolve, graceMs);
31
+ child.once("exit", () => {
32
+ clearTimeout(timer);
33
+ resolve();
34
+ });
35
+ });
36
+ }
37
+ signalGroup(child, "SIGKILL");
38
+ }
39
+ //# sourceMappingURL=processGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processGroup.js","sourceRoot":"","sources":["../src/processGroup.ts"],"names":[],"mappings":"AAMA,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAE1C,4EAA4E;AAC5E,SAAS,WAAW,CAAC,KAAmB,EAAE,GAAmB;IAC3D,IAAI,CAAC;QACH,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,eAAe;QACjB,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAAmB,EAAE,OAAe;IAC9E,MAAM,MAAM,GAAG,GAAY,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,CAAA;IAClF,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAC7B,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;gBACtB,YAAY,CAAC,KAAK,CAAC,CAAA;gBACnB,OAAO,EAAE,CAAA;YACX,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;AAC/B,CAAC"}
@@ -1,15 +1,25 @@
1
1
  import Anthropic from "@anthropic-ai/sdk";
2
- import type { AgentMessage, CompletionRequest, ConverseRequest, ConverseResult, Provider } from "./types.js";
2
+ import type { TokenUsage } from "../models/types.js";
3
+ import type { AgentMessage, CompletionRequest, ConverseOptions, ConverseRequest, ConverseResult, Provider } from "./types.js";
3
4
  /** Map provider-neutral messages to Anthropic's message params (pure; tested). */
4
5
  export declare function toAnthropicMessages(messages: AgentMessage[]): Anthropic.MessageParam[];
5
6
  /** Reduce an Anthropic response's content blocks to text + tool calls (pure; tested). */
6
7
  export declare function parseAnthropicContent(content: Anthropic.ContentBlock[]): ConverseResult;
8
+ /**
9
+ * Map an Anthropic `usage` block to the kernel's token accounting (pure; tested).
10
+ *
11
+ * Anthropic's `input_tokens` counts only UNCACHED input; cache reads and cache
12
+ * writes are reported separately. Total input is the sum of all three, so that
13
+ * is what `inputTokens` carries, with the cache split out alongside.
14
+ */
15
+ export declare function anthropicUsage(usage: Pick<Anthropic.Usage, "input_tokens" | "output_tokens" | "cache_read_input_tokens" | "cache_creation_input_tokens"> | Pick<Anthropic.Usage, "input_tokens" | "output_tokens"> | null | undefined): TokenUsage | undefined;
7
16
  export declare class AnthropicProvider implements Provider {
8
17
  readonly name = "anthropic";
18
+ readonly reportsUsage = true;
9
19
  private client;
10
20
  private model;
11
21
  constructor(apiKey: string, model?: string);
12
22
  complete(req: CompletionRequest): Promise<string>;
13
- converse(req: ConverseRequest): Promise<ConverseResult>;
23
+ converse(req: ConverseRequest, opts?: ConverseOptions): Promise<ConverseResult>;
14
24
  }
15
25
  //# sourceMappingURL=anthropic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAEzC,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,QAAQ,EAET,MAAM,YAAY,CAAA;AAEnB,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC,YAAY,EAAE,CAwBtF;AAED,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,EAAE,GAAG,cAAc,CAevF;AAED,qBAAa,iBAAkB,YAAW,QAAQ;IA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SAAqD;IAYhF,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAcjD,QAAQ,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAqBtF"}
@@ -45,8 +45,31 @@ export function parseAnthropicContent(content) {
45
45
  }
46
46
  return { text, toolCalls };
47
47
  }
48
+ /**
49
+ * Map an Anthropic `usage` block to the kernel's token accounting (pure; tested).
50
+ *
51
+ * Anthropic's `input_tokens` counts only UNCACHED input; cache reads and cache
52
+ * writes are reported separately. Total input is the sum of all three, so that
53
+ * is what `inputTokens` carries, with the cache split out alongside.
54
+ */
55
+ export function anthropicUsage(usage) {
56
+ if (!usage)
57
+ return undefined;
58
+ const cacheRead = "cache_read_input_tokens" in usage ? (usage.cache_read_input_tokens ?? 0) : 0;
59
+ const cacheWrite = "cache_creation_input_tokens" in usage ? (usage.cache_creation_input_tokens ?? 0) : 0;
60
+ const inputTokens = usage.input_tokens + cacheRead + cacheWrite;
61
+ const outputTokens = usage.output_tokens;
62
+ return {
63
+ inputTokens,
64
+ outputTokens,
65
+ totalTokens: inputTokens + outputTokens,
66
+ ...(cacheRead > 0 ? { cacheReadTokens: cacheRead } : {}),
67
+ ...(cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),
68
+ };
69
+ }
48
70
  export class AnthropicProvider {
49
71
  name = "anthropic";
72
+ reportsUsage = true;
50
73
  client;
51
74
  model;
52
75
  constructor(apiKey, model = process.env.ANTHROPIC_MODEL ?? "claude-sonnet-4-6") {
@@ -72,7 +95,7 @@ export class AnthropicProvider {
72
95
  .map((block) => block.text)
73
96
  .join("\n");
74
97
  }
75
- async converse(req) {
98
+ async converse(req, opts) {
76
99
  const message = await this.client.messages.create({
77
100
  model: this.model,
78
101
  max_tokens: maxTokens(),
@@ -83,8 +106,12 @@ export class AnthropicProvider {
83
106
  input_schema: t.inputSchema,
84
107
  })),
85
108
  messages: toAnthropicMessages(req.messages),
86
- });
87
- return parseAnthropicContent(message.content);
109
+ },
110
+ // Per-request, so an abort cancels THIS call (retries included) and
111
+ // leaves the shared client untouched.
112
+ opts?.signal ? { signal: opts.signal } : undefined);
113
+ const usage = anthropicUsage(message.usage);
114
+ return { ...parseAnthropicContent(message.content), ...(usage ? { usage } : {}) };
88
115
  }
89
116
  }
90
117
  //# sourceMappingURL=anthropic.js.map