@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
package/dist/signals.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers for the run's cancellation signals: a caller's cancel and a
|
|
3
|
+
* wall-clock deadline, merged into one signal whose `reason` still says which
|
|
4
|
+
* of the two fired. Not exported from `index.ts`.
|
|
5
|
+
*/
|
|
6
|
+
/** Node's timers cap at 2^31-1 ms; a longer delay would fire after 1ms instead. */
|
|
7
|
+
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
8
|
+
/**
|
|
9
|
+
* A signal that fires when a wall-clock budget runs out. Clamped to what a
|
|
10
|
+
* timer can represent, so an "effectively unlimited" budget stays unlimited
|
|
11
|
+
* rather than overflowing into an immediate abort, and a negative one fires at
|
|
12
|
+
* once.
|
|
13
|
+
*/
|
|
14
|
+
export function deadlineSignal(maxDurationMs) {
|
|
15
|
+
const ms = Number.isFinite(maxDurationMs)
|
|
16
|
+
? Math.min(Math.max(0, Math.ceil(maxDurationMs)), MAX_TIMER_MS)
|
|
17
|
+
: MAX_TIMER_MS;
|
|
18
|
+
return AbortSignal.timeout(ms);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Map an external harness's ending onto the run outcome vocabulary: its own
|
|
22
|
+
* timer → `timed_out`, the caller's signal → `canceled`, otherwise the
|
|
23
|
+
* harness's error flag decides between `failed` and `completed`.
|
|
24
|
+
*/
|
|
25
|
+
export function harnessOutcome(isError, stoppedBy) {
|
|
26
|
+
if (stoppedBy === "deadline")
|
|
27
|
+
return "timed_out";
|
|
28
|
+
if (stoppedBy === "signal")
|
|
29
|
+
return "canceled";
|
|
30
|
+
return isError ? "failed" : "completed";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* True when `err` is the run's abort surfacing, not an unrelated failure that
|
|
34
|
+
* merely happened after it. Requires the signal to have fired, and the error to
|
|
35
|
+
* be its reason, to carry it as `cause` (how `run_code` and `http_fetch` wrap
|
|
36
|
+
* it), or to be one of the abort errors the platform and the provider SDKs
|
|
37
|
+
* raise (`AbortError`, `TimeoutError`, the Anthropic/OpenAI SDKs'
|
|
38
|
+
* `APIUserAbortError`, matched by name or class name).
|
|
39
|
+
*/
|
|
40
|
+
export function isAbortError(err, signal) {
|
|
41
|
+
if (!signal?.aborted)
|
|
42
|
+
return false;
|
|
43
|
+
if (err === signal.reason)
|
|
44
|
+
return true;
|
|
45
|
+
if (!(err instanceof Error))
|
|
46
|
+
return false;
|
|
47
|
+
if (err.cause !== undefined && err.cause === signal.reason)
|
|
48
|
+
return true;
|
|
49
|
+
return ABORT_ERROR_NAMES.has(err.name) || ABORT_ERROR_NAMES.has(err.constructor.name);
|
|
50
|
+
}
|
|
51
|
+
const ABORT_ERROR_NAMES = new Set(["AbortError", "TimeoutError", "APIUserAbortError"]);
|
|
52
|
+
/**
|
|
53
|
+
* Merge an optional wall-clock budget with an optional caller signal.
|
|
54
|
+
*
|
|
55
|
+
* `AbortSignal.any` carries the first source's `reason` through by identity,
|
|
56
|
+
* so comparing it against the deadline's own reason tells a timeout from a
|
|
57
|
+
* cancel without a second flag that could drift from the signal.
|
|
58
|
+
*/
|
|
59
|
+
export function runStop(maxDurationMs, external) {
|
|
60
|
+
const deadline = maxDurationMs !== undefined && maxDurationMs > 0 ? deadlineSignal(maxDurationMs) : undefined;
|
|
61
|
+
const sources = [deadline, external].filter((s) => s !== undefined);
|
|
62
|
+
const signal = sources.length > 1 ? AbortSignal.any(sources) : sources[0];
|
|
63
|
+
return {
|
|
64
|
+
...(signal ? { signal } : {}),
|
|
65
|
+
stoppedBy: () => {
|
|
66
|
+
if (!signal?.aborted)
|
|
67
|
+
return undefined;
|
|
68
|
+
return deadline !== undefined && signal.reason === deadline.reason ? "deadline" : "signal";
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=signals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.js","sourceRoot":"","sources":["../src/signals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,mFAAmF;AACnF,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AAEhC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,aAAqB;IAClD,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC;QACvC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC;QAC/D,CAAC,CAAC,YAAY,CAAA;IAChB,OAAO,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE,SAAqB;IACpE,IAAI,SAAS,KAAK,UAAU;QAAE,OAAO,WAAW,CAAA;IAChD,IAAI,SAAS,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAA;IAC7C,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAA;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY,EAAE,MAA+B;IACxE,IAAI,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO,KAAK,CAAA;IAClC,IAAI,GAAG,KAAK,MAAM,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACtC,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACzC,IAAI,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adata.d.ts
CHANGED
|
@@ -34,8 +34,9 @@ export type ResultRetention = "ephemeral" | "standard" | "persistent";
|
|
|
34
34
|
export type ClientResultVisibility = "full" | "suppressed";
|
|
35
35
|
/**
|
|
36
36
|
* Optional descriptive metadata on a {@link Tool}. Every field is optional and
|
|
37
|
-
* an absent field
|
|
38
|
-
*
|
|
37
|
+
* an absent field means "no restriction" — except `replay`, where absent means
|
|
38
|
+
* `"unsafe"` (see the field). A tool that declares no metadata behaves exactly
|
|
39
|
+
* as it did before this existed.
|
|
39
40
|
*/
|
|
40
41
|
export interface ToolMetadata {
|
|
41
42
|
/** Human-facing label, where a UI wants something friendlier than `name`. */
|
|
@@ -60,6 +61,16 @@ export interface ToolMetadata {
|
|
|
60
61
|
undoToolName?: string | null;
|
|
61
62
|
/** How long undo stays available. */
|
|
62
63
|
undoWindowSeconds?: number | null;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the tool may be executed again after an interruption — e.g. when
|
|
66
|
+
* a run is resumed and this call was in flight. `"safe"` declares the effect
|
|
67
|
+
* idempotent (a read, or a write keyed so a repeat is a no-op); `"unsafe"`
|
|
68
|
+
* declares it is not. **Absent means unsafe**: this is the one field where
|
|
69
|
+
* "no claim" is NOT "no restriction", because re-running an effect nobody
|
|
70
|
+
* vouched for is exactly the failure a replay consumer must avoid. The
|
|
71
|
+
* kernel only records the claim; deciding to replay is the application's.
|
|
72
|
+
*/
|
|
73
|
+
replay?: "safe" | "unsafe";
|
|
63
74
|
resultRetention?: ResultRetention;
|
|
64
75
|
clientResultVisibility?: ClientResultVisibility;
|
|
65
76
|
}
|
|
@@ -88,6 +99,11 @@ export declare function selectTools(tools: Tool[], selection?: ToolSelection): T
|
|
|
88
99
|
export declare function toToolSpecs(tools: Tool[]): ToolSpec[];
|
|
89
100
|
/** Tools that must not execute until a human has approved them. */
|
|
90
101
|
export declare function toolsRequiringConfirmation(tools: Tool[]): Tool[];
|
|
102
|
+
/**
|
|
103
|
+
* Tools that declared `replay: "safe"` — the only ones a consumer may re-run
|
|
104
|
+
* after an interruption. An undeclared tool is excluded: absent means unsafe.
|
|
105
|
+
*/
|
|
106
|
+
export declare function replaySafeTools(tools: Tool[]): Tool[];
|
|
91
107
|
/** Look up the tool that undoes `name`, when one is declared and reversible. */
|
|
92
108
|
export declare function undoToolFor(tools: Tool[], name: string): Tool | undefined;
|
|
93
109
|
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/tools/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;AAElE,iEAAiE;AACjE,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,CAAA;AAErE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,YAAY,CAAA;AAE1D
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/tools/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;AAElE,iEAAiE;AACjE,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,CAAA;AAErE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,YAAY,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IA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I,EAAE,GAAG,IAAI,EAAE,CAErD;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAIzE"}
|
package/dist/tools/metadata.js
CHANGED
|
@@ -39,6 +39,13 @@ export function toToolSpecs(tools) {
|
|
|
39
39
|
export function toolsRequiringConfirmation(tools) {
|
|
40
40
|
return tools.filter((tool) => tool.meta?.requiresConfirmation === true);
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Tools that declared `replay: "safe"` — the only ones a consumer may re-run
|
|
44
|
+
* after an interruption. An undeclared tool is excluded: absent means unsafe.
|
|
45
|
+
*/
|
|
46
|
+
export function replaySafeTools(tools) {
|
|
47
|
+
return tools.filter((tool) => tool.meta?.replay === "safe");
|
|
48
|
+
}
|
|
42
49
|
/** Look up the tool that undoes `name`, when one is declared and reversible. */
|
|
43
50
|
export function undoToolFor(tools, name) {
|
|
44
51
|
const tool = tools.find((t) => t.spec.name === name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/tools/metadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/tools/metadata.ts"],"names":[],"mappings":"AA4FA,qDAAqD;AACrD,MAAM,UAAU,aAAa,CAAC,IAAU,EAAE,YAA2B,EAAE;IACrE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IACtB,IAAI,SAAS,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAClF,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IAEtB,0EAA0E;IAC1E,6EAA6E;IAC7E,4CAA4C;IAC5C,IAAI,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAA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M,UAAU,WAAW,CAAC,KAAa,EAAE,IAAY;IACrD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IACpD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAA;IACxE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;AACnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelTool.d.ts","sourceRoot":"","sources":["../../src/tools/modelTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"modelTool.d.ts","sourceRoot":"","sources":["../../src/tools/modelTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,eAAe,CAAA;AAElE,6DAA6D;AAC7D,MAAM,WAAW,gBAAgB,CAAC,GAAG,EAAE,GAAG;IACxC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,uEAAuE;IACvE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,CAAA;IAClD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,MAAM,CAAA;IAChD,IAAI,CAAC,EAAE,YAAY,CAAA;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAClC,KAAK,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EAChC,OAAO,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GACnC,IAAI,CAiCN"}
|
package/dist/tools/modelTool.js
CHANGED
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export function modelAsTool(model, options, context = {}) {
|
|
15
15
|
const project = options.toContent ?? ((result) => JSON.stringify(result.value));
|
|
16
|
-
const run = async (input) => {
|
|
16
|
+
const run = async (input, toolCtx) => {
|
|
17
|
+
// The run's signal (from the loop) and any signal bound at construction
|
|
18
|
+
// both cancel the call; either one firing is enough.
|
|
19
|
+
const signals = [context.signal, toolCtx?.signal].filter((s) => s !== undefined);
|
|
20
|
+
const signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
17
21
|
const ctx = {
|
|
18
22
|
log: context.log ?? (() => { }),
|
|
19
|
-
...(
|
|
23
|
+
...(signal ? { signal } : {}),
|
|
20
24
|
...(context.correlationId ? { correlationId: context.correlationId } : {}),
|
|
21
25
|
...(context.budget ? { budget: context.budget } : {}),
|
|
22
26
|
};
|
|
@@ -30,7 +34,7 @@ export function modelAsTool(model, options, context = {}) {
|
|
|
30
34
|
inputSchema: options.inputSchema,
|
|
31
35
|
},
|
|
32
36
|
...(options.meta ? { meta: options.meta } : {}),
|
|
33
|
-
execute: async (input) => (await run(input)).content,
|
|
37
|
+
execute: async (input, toolCtx) => (await run(input, toolCtx)).content,
|
|
34
38
|
executeStructured: run,
|
|
35
39
|
};
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelTool.js","sourceRoot":"","sources":["../../src/tools/modelTool.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CACzB,KAAgC,EAChC,OAAmC,EACnC,UAAkC,EAAE;IAEpC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,MAAwB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAEjG,MAAM,GAAG,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"modelTool.js","sourceRoot":"","sources":["../../src/tools/modelTool.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CACzB,KAAgC,EAChC,OAAmC,EACnC,UAAkC,EAAE;IAEpC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,MAAwB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAEjG,MAAM,GAAG,GAAG,KAAK,EACf,KAA8B,EAC9B,OAAqB,EACA,EAAE;QACvB,wEAAwE;QACxE,qDAAqD;QACrD,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,CACtD,CAAC,CAAC,EAAoB,EAAE,CAAC,CAAC,KAAK,SAAS,CACzC,CAAA;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QACzE,MAAM,GAAG,GAAkB;YACzB,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;YAC9B,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7B,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAA;QAChE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,CAAA;IAC/D,CAAC,CAAA;IAED,OAAO;QACL,IAAI,EAAE;YACJ,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC;QACD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO;QACtE,iBAAiB,EAAE,GAAG;KACvB,CAAA;AACH,CAAC"}
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -17,6 +17,23 @@ export interface ToolOutput {
|
|
|
17
17
|
/** The typed payload, preserved for callers and clients. */
|
|
18
18
|
structured?: unknown;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* What the loop hands a tool alongside its input.
|
|
22
|
+
*
|
|
23
|
+
* `signal` fires when the run is canceled or its deadline passes; a tool that
|
|
24
|
+
* does real work (a subprocess, an HTTP call, a remote MCP call) should stop
|
|
25
|
+
* when it does. `callId` is the model's id for this call — the same id the
|
|
26
|
+
* `tool.called` event carries — so a tool can key an idempotency token or a log
|
|
27
|
+
* line to it. `runId` is present when the caller supplied one.
|
|
28
|
+
*
|
|
29
|
+
* Optional on both executors, so a tool written before this existed, and a
|
|
30
|
+
* caller that invokes a tool directly, keep working unchanged.
|
|
31
|
+
*/
|
|
32
|
+
export interface ToolContext {
|
|
33
|
+
signal: AbortSignal;
|
|
34
|
+
callId: string;
|
|
35
|
+
runId?: string;
|
|
36
|
+
}
|
|
20
37
|
/** A tool the agent can call: its public spec plus a server-side executor. */
|
|
21
38
|
export interface Tool {
|
|
22
39
|
spec: ToolSpec;
|
|
@@ -26,7 +43,7 @@ export interface Tool {
|
|
|
26
43
|
* Execute and return the model-facing string. This is the required contract
|
|
27
44
|
* every tool implements, and the only one the loop needs.
|
|
28
45
|
*/
|
|
29
|
-
execute(input: Record<string, unknown
|
|
46
|
+
execute(input: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
30
47
|
/**
|
|
31
48
|
* Optional richer executor. When present the loop calls this instead and
|
|
32
49
|
* keeps the typed payload alongside the string; when absent nothing changes.
|
|
@@ -36,10 +53,10 @@ export interface Tool {
|
|
|
36
53
|
* types `execute` as returning a plain `string`, and widening it to a union
|
|
37
54
|
* would break them at the type level for a payload most tools never produce.
|
|
38
55
|
*/
|
|
39
|
-
executeStructured?(input: Record<string, unknown
|
|
56
|
+
executeStructured?(input: Record<string, unknown>, ctx?: ToolContext): Promise<ToolOutput>;
|
|
40
57
|
}
|
|
41
|
-
/** Run a tool through its richest available executor. */
|
|
42
|
-
export declare function executeTool(tool: Tool, input: Record<string, unknown
|
|
58
|
+
/** Run a tool through its richest available executor, handing it `ctx` when given. */
|
|
59
|
+
export declare function executeTool(tool: Tool, input: Record<string, unknown>, ctx?: ToolContext): Promise<ToolOutput>;
|
|
43
60
|
/**
|
|
44
61
|
* General-purpose primitives, scoped to the run sandbox. `env` carries the
|
|
45
62
|
* resolved secrets (see secretsToEnv) into executed code. Domain logic is the
|
|
@@ -58,7 +75,9 @@ export declare function primitiveTools(sandboxDir: string, env: NodeJS.ProcessEn
|
|
|
58
75
|
* namespaced `<connector>__<tool>` to avoid collisions. Returns a `close` to
|
|
59
76
|
* tear down the connections when the run ends.
|
|
60
77
|
*/
|
|
61
|
-
export declare function connectorTools(connectors: ConnectorConfig[], connect?: (config: ConnectorConfig) => Promise<McpConnection
|
|
78
|
+
export declare function connectorTools(connectors: ConnectorConfig[], connect?: (config: ConnectorConfig) => Promise<McpConnection>, opts?: {
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}): Promise<{
|
|
62
81
|
tools: Tool[];
|
|
63
82
|
close: () => Promise<void>;
|
|
64
83
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAA;IACf,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,8EAA8E;AAC9E,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,QAAQ,CAAA;IACd,8EAA8E;IAC9E,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB;;;O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AAE,OAAO,CAAC,EAC9B,GAAG,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,UAAU,CAAC,CAGrB;AAeD;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,IAAI,EAAE,CAgGR;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,eAAe,EAAE,EAC7B,OAAO,GAAE,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,aAAa,CAAc,EACzE,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAClC,OAAO,CAAC;IAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CA+DxD"}
|
package/dist/tools/registry.js
CHANGED
|
@@ -2,11 +2,11 @@ import { runCode } from "../primitives/codeExec.js";
|
|
|
2
2
|
import { httpFetch } from "../primitives/http.js";
|
|
3
3
|
import { readFileSafe, listFiles } from "../primitives/fs.js";
|
|
4
4
|
import { connectMcp } from "../connectors/mcpClient.js";
|
|
5
|
-
/** Run a tool through its richest available executor. */
|
|
6
|
-
export async function executeTool(tool, input) {
|
|
5
|
+
/** Run a tool through its richest available executor, handing it `ctx` when given. */
|
|
6
|
+
export async function executeTool(tool, input, ctx) {
|
|
7
7
|
if (tool.executeStructured)
|
|
8
|
-
return tool.executeStructured(input);
|
|
9
|
-
return { content: await tool.execute(input) };
|
|
8
|
+
return tool.executeStructured(input, ctx);
|
|
9
|
+
return { content: await tool.execute(input, ctx) };
|
|
10
10
|
}
|
|
11
11
|
const str = (v) => (typeof v === "string" ? v : "");
|
|
12
12
|
const strArray = (v) => (Array.isArray(v) ? v.map(String) : []);
|
|
@@ -52,21 +52,24 @@ export function primitiveTools(sandboxDir, env, allowed, allowHosts) {
|
|
|
52
52
|
required: ["command"],
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
|
-
execute: async (input) => {
|
|
55
|
+
execute: async (input, ctx) => {
|
|
56
56
|
const command = str(input.command);
|
|
57
57
|
const args = strArray(input.args);
|
|
58
58
|
const stdin = typeof input.stdin === "string" ? input.stdin : undefined;
|
|
59
|
+
// An abort (run canceled or out of time) kills the whole process group.
|
|
60
|
+
const signal = ctx?.signal;
|
|
59
61
|
// Default to running the command line through a shell (mirrors the verify
|
|
60
62
|
// gate's `/bin/sh -c`), so an agent can hand us `node scan.mjs` as a single
|
|
61
63
|
// string. When explicit args are given, exec the binary directly (no shell).
|
|
62
64
|
const result = args.length > 0
|
|
63
|
-
? await runCode({ cwd: sandboxDir, command, args, env, stdin })
|
|
65
|
+
? await runCode({ cwd: sandboxDir, command, args, env, stdin, signal })
|
|
64
66
|
: await runCode({
|
|
65
67
|
cwd: sandboxDir,
|
|
66
68
|
command: "/bin/sh",
|
|
67
69
|
args: ["-c", command],
|
|
68
70
|
env,
|
|
69
71
|
stdin,
|
|
72
|
+
signal,
|
|
70
73
|
});
|
|
71
74
|
return JSON.stringify(result);
|
|
72
75
|
},
|
|
@@ -109,13 +112,14 @@ export function primitiveTools(sandboxDir, env, allowed, allowHosts) {
|
|
|
109
112
|
required: ["url"],
|
|
110
113
|
},
|
|
111
114
|
},
|
|
112
|
-
execute: async (input) => {
|
|
115
|
+
execute: async (input, ctx) => {
|
|
113
116
|
const res = await httpFetch({
|
|
114
117
|
url: str(input.url),
|
|
115
118
|
method: str(input.method) || "GET",
|
|
116
119
|
headers: stringHeaders(input.headers),
|
|
117
120
|
body: typeof input.body === "string" ? input.body : undefined,
|
|
118
121
|
allowHosts, // egress allowlist from the workflow's permissions (undefined = any public host)
|
|
122
|
+
signal: ctx?.signal,
|
|
119
123
|
});
|
|
120
124
|
return JSON.stringify({ status: res.status, body: res.body });
|
|
121
125
|
},
|
|
@@ -128,8 +132,23 @@ export function primitiveTools(sandboxDir, env, allowed, allowHosts) {
|
|
|
128
132
|
* namespaced `<connector>__<tool>` to avoid collisions. Returns a `close` to
|
|
129
133
|
* tear down the connections when the run ends.
|
|
130
134
|
*/
|
|
131
|
-
export async function connectorTools(connectors, connect = connectMcp) {
|
|
135
|
+
export async function connectorTools(connectors, connect = connectMcp, opts = {}) {
|
|
136
|
+
const { signal } = opts;
|
|
132
137
|
const connections = [];
|
|
138
|
+
// Each setup await stops waiting the moment `signal` aborts, so a stalled
|
|
139
|
+
// server cannot hold a canceled run; the catch below then closes every
|
|
140
|
+
// connection already open, and one still connecting is closed if it lands.
|
|
141
|
+
const step = (work) => {
|
|
142
|
+
if (!signal)
|
|
143
|
+
return work;
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
const onAbort = () => reject(signal.reason);
|
|
146
|
+
if (signal.aborted)
|
|
147
|
+
return onAbort();
|
|
148
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
149
|
+
work.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
150
|
+
});
|
|
151
|
+
};
|
|
133
152
|
const tools = [];
|
|
134
153
|
const close = async () => {
|
|
135
154
|
await Promise.allSettled(connections.map((c) => c.close()));
|
|
@@ -138,9 +157,17 @@ export async function connectorTools(connectors, connect = connectMcp) {
|
|
|
138
157
|
for (const config of connectors) {
|
|
139
158
|
if (config.kind !== "mcp")
|
|
140
159
|
continue;
|
|
141
|
-
const
|
|
160
|
+
const connecting = connect(config);
|
|
161
|
+
let conn;
|
|
162
|
+
try {
|
|
163
|
+
conn = await step(connecting);
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
void connecting.then((late) => late.close()).catch(() => { });
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
142
169
|
connections.push(conn);
|
|
143
|
-
const listed = (await conn.listTools());
|
|
170
|
+
const listed = (await step(conn.listTools()));
|
|
144
171
|
for (const tool of listed.tools ?? []) {
|
|
145
172
|
tools.push({
|
|
146
173
|
spec: {
|
|
@@ -148,8 +175,12 @@ export async function connectorTools(connectors, connect = connectMcp) {
|
|
|
148
175
|
description: tool.description ?? `${config.name} tool ${tool.name}`,
|
|
149
176
|
inputSchema: tool.inputSchema ?? { type: "object" },
|
|
150
177
|
},
|
|
151
|
-
execute: async (input) => {
|
|
152
|
-
|
|
178
|
+
execute: async (input, ctx) => {
|
|
179
|
+
// The signal reaches the MCP request, which sends the server a
|
|
180
|
+
// cancellation notification instead of leaving the call running.
|
|
181
|
+
const result = ctx
|
|
182
|
+
? await conn.callTool(tool.name, input, { signal: ctx.signal })
|
|
183
|
+
: await conn.callTool(tool.name, input);
|
|
153
184
|
return JSON.stringify(result);
|
|
154
185
|
},
|
|
155
186
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAsB,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAsB,MAAM,4BAA4B,CAAA;AA6D3E,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAU,EACV,KAA8B,EAC9B,GAAiB;IAEjB,IAAI,IAAI,CAAC,iBAAiB;QAAE,OAAO,I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CAAC;gBACtC,KAAK,CAAC,IAAI,CAAC;oBACT,IAAI,EAAE;wBACJ,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;wBACpC,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,GAAG,MAAM,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,EAAE;wBACnE,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;qBACpD;oBACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;wBAC5B,+DAA+D;wBAC/D,iEAAiE;wBACjE,MAAM,MAAM,GAAG,GAAG;4BAChB,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;4BAC/D,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;wBACzC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;oBAC/B,CAAC;iBACF,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wDAAwD;QACxD,MAAM,KAAK,EAAE,CAAA;QACb,MAAM,GAAG,CAAA;IACX,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rarebit-one/harness-kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Provider-neutral AI-harness kernel — LLM adapters, tool-use loop, MCP connectors, and a pluggable agent-engine seam",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jaryl Sim <code@jaryl.dev>",
|
|
@@ -51,8 +51,9 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@anthropic-ai/claude-agent-sdk": "^0.3.228",
|
|
54
|
-
"@anthropic-ai/sdk": "^0.
|
|
54
|
+
"@anthropic-ai/sdk": "^0.129.0",
|
|
55
55
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
56
|
+
"@zed-industries/agent-client-protocol": "^0.4.5",
|
|
56
57
|
"openai": "^7.4.0",
|
|
57
58
|
"undici": "^8.10.0",
|
|
58
59
|
"zod": "^4.4.3"
|
|
@@ -67,6 +68,6 @@
|
|
|
67
68
|
"prettier": "^3.9.5",
|
|
68
69
|
"typescript": "^6.0.3",
|
|
69
70
|
"typescript-eslint": "^8.67.0",
|
|
70
|
-
"vitest": "^
|
|
71
|
+
"vitest": "^5.0.1"
|
|
71
72
|
}
|
|
72
73
|
}
|