@fabric-harness/sdk 6.9.0 → 6.10.1
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/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +8 -0
- package/dist/agent.js.map +1 -1
- package/dist/channel-runtime.d.ts +2 -0
- package/dist/channel-runtime.d.ts.map +1 -1
- package/dist/channel-runtime.js +1 -0
- package/dist/channel-runtime.js.map +1 -1
- package/dist/channel.d.ts +11 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js.map +1 -1
- package/dist/context.d.ts +28 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +18 -0
- package/dist/context.js.map +1 -1
- package/dist/conversation-ownership.d.ts +151 -0
- package/dist/conversation-ownership.d.ts.map +1 -0
- package/dist/conversation-ownership.js +239 -0
- package/dist/conversation-ownership.js.map +1 -0
- package/dist/dispatch.d.ts +7 -0
- package/dist/dispatch.d.ts.map +1 -1
- package/dist/dispatch.js.map +1 -1
- package/dist/dynamic-agent.d.ts.map +1 -1
- package/dist/dynamic-agent.js +8 -0
- package/dist/dynamic-agent.js.map +1 -1
- package/dist/error.d.ts +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/experimental.d.ts +6 -5
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +5 -3
- package/dist/experimental.js.map +1 -1
- package/dist/governed-voice.d.ts.map +1 -1
- package/dist/governed-voice.js +5 -0
- package/dist/governed-voice.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/loop.d.ts +8 -0
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +22 -1
- package/dist/loop.js.map +1 -1
- package/dist/model-pricing.js +1 -1
- package/dist/model-pricing.js.map +1 -1
- package/dist/model.d.ts +20 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +88 -9
- package/dist/model.js.map +1 -1
- package/dist/persistent-agent.d.ts +1 -1
- package/dist/persistent-agent.d.ts.map +1 -1
- package/dist/persistent-agent.js.map +1 -1
- package/dist/pi-loop-runtime.d.ts.map +1 -1
- package/dist/pi-loop-runtime.js +142 -8
- package/dist/pi-loop-runtime.js.map +1 -1
- package/dist/policied-sandbox.d.ts +9 -3
- package/dist/policied-sandbox.d.ts.map +1 -1
- package/dist/policied-sandbox.js +290 -54
- package/dist/policied-sandbox.js.map +1 -1
- package/dist/policy.d.ts +3 -3
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +115 -64
- package/dist/policy.js.map +1 -1
- package/dist/proposal-tool.d.ts +260 -0
- package/dist/proposal-tool.d.ts.map +1 -0
- package/dist/proposal-tool.js +562 -0
- package/dist/proposal-tool.js.map +1 -0
- package/dist/sandbox-ref.d.ts +2 -2
- package/dist/sandbox-ref.d.ts.map +1 -1
- package/dist/sandbox-ref.js +143 -70
- package/dist/sandbox-ref.js.map +1 -1
- package/dist/sandbox.d.ts +8 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +22 -1
- package/dist/sandbox.js.map +1 -1
- package/dist/session.d.ts +71 -3
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +590 -160
- package/dist/session.js.map +1 -1
- package/dist/stop-reason-guard.d.ts +89 -0
- package/dist/stop-reason-guard.d.ts.map +1 -0
- package/dist/stop-reason-guard.js +261 -0
- package/dist/stop-reason-guard.js.map +1 -0
- package/dist/strict.d.ts +8 -1
- package/dist/strict.d.ts.map +1 -1
- package/dist/strict.js +4 -1
- package/dist/strict.js.map +1 -1
- package/dist/suspending-sandbox.d.ts +2 -2
- package/dist/suspending-sandbox.d.ts.map +1 -1
- package/dist/suspending-sandbox.js +65 -26
- package/dist/suspending-sandbox.js.map +1 -1
- package/dist/tools.d.ts +17 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +104 -48
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/voice-pipeline.d.ts +67 -0
- package/dist/voice-pipeline.d.ts.map +1 -1
- package/dist/voice-pipeline.js +350 -20
- package/dist/voice-pipeline.js.map +1 -1
- package/dist/voice-sentences.d.ts +43 -0
- package/dist/voice-sentences.d.ts.map +1 -0
- package/dist/voice-sentences.js +99 -0
- package/dist/voice-sentences.js.map +1 -0
- package/package.json +30 -13
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FabricError } from
|
|
1
|
+
import { FabricError } from "./error.js";
|
|
2
|
+
import { registerSandboxWrapper } from "./sandbox.js";
|
|
2
3
|
/**
|
|
3
4
|
* Decorator that adds idle-based auto-suspend to any `SandboxEnv` whose
|
|
4
5
|
* underlying implementation supports `suspend()` / `resume()`. If the inner
|
|
@@ -29,43 +30,71 @@ export class SuspendingSandboxEnv {
|
|
|
29
30
|
if (inner.capabilities) {
|
|
30
31
|
this.capabilities = {
|
|
31
32
|
...inner.capabilities,
|
|
32
|
-
suspend: typeof inner.suspend ===
|
|
33
|
-
resume: typeof inner.resume ===
|
|
33
|
+
suspend: typeof inner.suspend === "function",
|
|
34
|
+
resume: typeof inner.resume === "function",
|
|
34
35
|
};
|
|
35
36
|
}
|
|
37
|
+
registerSandboxWrapper(this, inner);
|
|
38
|
+
}
|
|
39
|
+
resolvePath(path) {
|
|
40
|
+
return this.inner.resolvePath(path);
|
|
36
41
|
}
|
|
37
|
-
resolvePath(path) { return this.inner.resolvePath(path); }
|
|
38
42
|
async exec(command, options) {
|
|
39
43
|
return this.access(() => this.inner.exec(command, options));
|
|
40
44
|
}
|
|
41
|
-
async readFile(path) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
async
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
async
|
|
48
|
-
|
|
45
|
+
async readFile(path) {
|
|
46
|
+
return this.access(() => this.inner.readFile(path));
|
|
47
|
+
}
|
|
48
|
+
async readFileBuffer(path) {
|
|
49
|
+
return this.access(() => this.inner.readFileBuffer(path));
|
|
50
|
+
}
|
|
51
|
+
async writeFile(path, content) {
|
|
52
|
+
await this.access(() => this.inner.writeFile(path, content));
|
|
53
|
+
}
|
|
54
|
+
async stat(path) {
|
|
55
|
+
return this.access(() => this.inner.stat(path));
|
|
56
|
+
}
|
|
57
|
+
async readdir(path) {
|
|
58
|
+
return this.access(() => this.inner.readdir(path));
|
|
59
|
+
}
|
|
60
|
+
async exists(path) {
|
|
61
|
+
return this.access(() => this.inner.exists(path));
|
|
62
|
+
}
|
|
63
|
+
async mkdir(path, options) {
|
|
64
|
+
await this.access(() => this.inner.mkdir(path, options));
|
|
65
|
+
}
|
|
66
|
+
async rm(path, options) {
|
|
67
|
+
await this.access(() => this.inner.rm(path, options));
|
|
68
|
+
}
|
|
49
69
|
async snapshot() {
|
|
50
70
|
const snapshot = this.inner.snapshot;
|
|
51
71
|
if (!snapshot)
|
|
52
|
-
throw new FabricError({
|
|
72
|
+
throw new FabricError({
|
|
73
|
+
code: "SANDBOX_UNAVAILABLE",
|
|
74
|
+
message: "Sandbox does not support snapshots. Guard with sandbox.capabilities before calling, or use a sandbox backend that implements snapshot (e.g. local or docker).",
|
|
75
|
+
});
|
|
53
76
|
return this.access(() => snapshot.call(this.inner));
|
|
54
77
|
}
|
|
55
78
|
async restore(snapshot) {
|
|
56
79
|
const restore = this.inner.restore;
|
|
57
80
|
if (!restore)
|
|
58
|
-
throw new FabricError({
|
|
81
|
+
throw new FabricError({
|
|
82
|
+
code: "SANDBOX_UNAVAILABLE",
|
|
83
|
+
message: "Sandbox does not support restore. Guard with sandbox.capabilities before calling, or use a sandbox backend that implements restore (e.g. local or docker).",
|
|
84
|
+
});
|
|
59
85
|
await this.access(() => restore.call(this.inner, snapshot));
|
|
60
86
|
}
|
|
61
87
|
async fork(snapshot) {
|
|
62
88
|
const fork = this.inner.fork;
|
|
63
89
|
if (!fork)
|
|
64
|
-
throw new FabricError({
|
|
90
|
+
throw new FabricError({
|
|
91
|
+
code: "SANDBOX_UNAVAILABLE",
|
|
92
|
+
message: "Sandbox does not support fork. Guard with sandbox.capabilities before calling, or use a sandbox backend that implements fork (e.g. local or docker).",
|
|
93
|
+
});
|
|
65
94
|
return this.access(() => fork.call(this.inner, snapshot));
|
|
66
95
|
}
|
|
67
96
|
async suspend() {
|
|
68
|
-
if (typeof this.inner.suspend !==
|
|
97
|
+
if (typeof this.inner.suspend !== "function")
|
|
69
98
|
return;
|
|
70
99
|
this.cancelIdleTimer();
|
|
71
100
|
if (!this.suspended) {
|
|
@@ -74,7 +103,7 @@ export class SuspendingSandboxEnv {
|
|
|
74
103
|
}
|
|
75
104
|
}
|
|
76
105
|
async resume() {
|
|
77
|
-
if (typeof this.inner.resume !==
|
|
106
|
+
if (typeof this.inner.resume !== "function")
|
|
78
107
|
return;
|
|
79
108
|
if (this.suspended) {
|
|
80
109
|
await this.inner.resume();
|
|
@@ -87,21 +116,23 @@ export class SuspendingSandboxEnv {
|
|
|
87
116
|
await this.inner.cleanup();
|
|
88
117
|
}
|
|
89
118
|
/** True when the sandbox is currently suspended (for tests / introspection). */
|
|
90
|
-
get isSuspended() {
|
|
119
|
+
get isSuspended() {
|
|
120
|
+
return this.suspended;
|
|
121
|
+
}
|
|
91
122
|
async access(operation) {
|
|
92
123
|
this.cancelIdleTimer();
|
|
93
124
|
if (this.suspended) {
|
|
94
125
|
if (!this.autoResume) {
|
|
95
126
|
throw new FabricError({
|
|
96
|
-
code:
|
|
97
|
-
message:
|
|
127
|
+
code: "SANDBOX_UNAVAILABLE",
|
|
128
|
+
message: "Sandbox is suspended; pass autoResumeOnAccess: true (default) or call resume() before use.",
|
|
98
129
|
retryable: true,
|
|
99
130
|
});
|
|
100
131
|
}
|
|
101
|
-
if (typeof this.inner.resume !==
|
|
132
|
+
if (typeof this.inner.resume !== "function") {
|
|
102
133
|
throw new FabricError({
|
|
103
|
-
code:
|
|
104
|
-
message:
|
|
134
|
+
code: "SANDBOX_UNAVAILABLE",
|
|
135
|
+
message: "Sandbox is suspended but the underlying backend does not support resume().",
|
|
105
136
|
});
|
|
106
137
|
}
|
|
107
138
|
await this.inner.resume();
|
|
@@ -126,10 +157,18 @@ export class SuspendingSandboxEnv {
|
|
|
126
157
|
this.cancelIdleTimer();
|
|
127
158
|
const timer = setTimeout(() => {
|
|
128
159
|
// Best-effort suspend; swallow errors so a failing provider doesn't crash the process.
|
|
129
|
-
void suspend
|
|
160
|
+
void suspend
|
|
161
|
+
.call(this.inner)
|
|
162
|
+
.then(() => {
|
|
163
|
+
this.suspended = true;
|
|
164
|
+
})
|
|
165
|
+
.catch(() => undefined);
|
|
130
166
|
}, this.idleMs);
|
|
131
167
|
// Don't keep the event loop alive just for the suspend timer.
|
|
132
|
-
if (typeof timer ===
|
|
168
|
+
if (typeof timer === "object" &&
|
|
169
|
+
timer !== null &&
|
|
170
|
+
"unref" in timer &&
|
|
171
|
+
typeof timer.unref === "function") {
|
|
133
172
|
timer.unref();
|
|
134
173
|
}
|
|
135
174
|
this.idleTimer = timer;
|
|
@@ -149,7 +188,7 @@ export class SuspendingSandboxEnv {
|
|
|
149
188
|
export function withIdleSuspend(inner, options) {
|
|
150
189
|
if (!options?.idleSuspendMs || options.idleSuspendMs <= 0)
|
|
151
190
|
return inner;
|
|
152
|
-
if (typeof inner.suspend !==
|
|
191
|
+
if (typeof inner.suspend !== "function")
|
|
153
192
|
return inner;
|
|
154
193
|
return new SuspendingSandboxEnv(inner, options);
|
|
155
194
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suspending-sandbox.js","sourceRoot":"","sources":["../src/suspending-sandbox.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"suspending-sandbox.js","sourceRoot":"","sources":["../src/suspending-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAatD;;;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AAO,EAAE,aAAa,IAAI,OAAO,CAAC,aAAa,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACxE,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,IAAI,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { FileStat, SandboxEnv, SandboxOrphanSettlement } from "./sandbox.js";
|
|
2
1
|
import type { CapabilityPolicy } from "./policy.js";
|
|
2
|
+
import type { FileStat, SandboxEnv, SandboxOrphanSettlement } from "./sandbox.js";
|
|
3
3
|
import type { ApprovalGrant, FabricActor, JsonObject, PackagedSkillDirectory, ResultValidator, ShellResult } from "./types.js";
|
|
4
4
|
export interface ToolContext {
|
|
5
5
|
sandbox: SandboxEnv;
|
|
6
|
+
/**
|
|
7
|
+
* @internal The command a scoped command tool runs, rendered once by the
|
|
8
|
+
* harness for this call so the command judged and approved is the one run.
|
|
9
|
+
*/
|
|
10
|
+
__fabricScopedCommand?: string;
|
|
6
11
|
/** Stable identity of the logical call, preserved across durable retries. */
|
|
7
12
|
toolCallId?: string;
|
|
8
13
|
/** Cancels provider work when the owning prompt, task, or submission is aborted. */
|
|
@@ -235,9 +240,16 @@ export declare function defineTool<TInput = unknown, TOutput = unknown>(tool: To
|
|
|
235
240
|
export declare function defineTool<TInput = unknown, TOutput = unknown, THarness extends boolean = false, TDurable extends boolean = false>(tool: HookToolDefinition<TInput, TOutput, THarness, TDurable>): ToolDef<TInput, TOutput>;
|
|
236
241
|
export type BuiltinTool = ToolDef<ReadFileInput, string> | ToolDef<ReadFileBufferInput, Uint8Array> | ToolDef<WriteFileInput, void> | ToolDef<EditInput, void> | ToolDef<StatInput, FileStat> | ToolDef<ReaddirInput, string[]> | ToolDef<ExistsInput, boolean> | ToolDef<MkdirInput, void> | ToolDef<RmInput, void> | ToolDef<BashInput, ShellResult> | ToolDef<GrepInput, GrepMatch[]> | ToolDef<GlobInput, string[]>;
|
|
237
242
|
export type BuiltinFileTool = Exclude<BuiltinTool, ToolDef<BashInput, ShellResult> | ToolDef<GrepInput, GrepMatch[]> | ToolDef<GlobInput, string[]>>;
|
|
243
|
+
/** @internal Whether `tool` carries a scoped command renderer (`createCommandTools`). */
|
|
244
|
+
export declare function hasScopedCommandRenderer(tool: ToolDef | undefined): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* @internal The exact command a scoped command tool runs for `input`, as the
|
|
247
|
+
* sandbox sees it, so an approval can be bound to that command.
|
|
248
|
+
*/
|
|
249
|
+
export declare function renderScopedCommand(tool: ToolDef | undefined, input: unknown): string | undefined;
|
|
238
250
|
export declare function createCommandTools(commands: Command[], options?: CommandToolOptions): ToolDef<CommandToolInput, ShellResult>[];
|
|
239
|
-
export declare function createBuiltinTools(sandbox
|
|
240
|
-
export declare function createFileTools(sandbox
|
|
251
|
+
export declare function createBuiltinTools(sandbox?: SandboxEnv, packagedSkills?: Record<string, PackagedSkillDirectory>): BuiltinTool[];
|
|
252
|
+
export declare function createFileTools(sandbox?: SandboxEnv, packagedSkills?: Record<string, PackagedSkillDirectory>): BuiltinFileTool[];
|
|
241
253
|
export declare function readFileTool(sandbox?: SandboxEnv, packagedSkills?: Record<string, PackagedSkillDirectory>): ToolDef<ReadFileInput, string>;
|
|
242
254
|
export declare function readFileBufferTool(sandbox?: SandboxEnv): ToolDef<ReadFileBufferInput, Uint8Array>;
|
|
243
255
|
export declare function writeFileTool(sandbox?: SandboxEnv): ToolDef<WriteFileInput, void>;
|
|
@@ -264,6 +276,8 @@ export interface ResultToolBundle<TResult> {
|
|
|
264
276
|
tools: ToolDef[];
|
|
265
277
|
getOutcome(): ResultOutcome<TResult>;
|
|
266
278
|
}
|
|
279
|
+
/** @internal Every tool name the harness itself adds to a prompt's tools after they are resolved. */
|
|
280
|
+
export declare const HARNESS_RESULT_TOOL_NAMES: readonly string[];
|
|
267
281
|
/**
|
|
268
282
|
* Produce the per-call `finish` and `give_up` tool pair for a given ResultValidator.
|
|
269
283
|
*
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,eAAe,EACf,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,UAAU,CAAC;IACpB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,+EAA+E;IAC/E,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,0FAA0F;IAC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B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAC1C,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAqBrC;AA8PD,MAAM,MAAM,aAAa,CAAC,OAAO,IAC7B;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,gBAAgB,CAAC,OAAO;IACvC,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,UAAU,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;CACtC;AAKD,qGAAqG;AACrG,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAEH;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,GAClC,gBAAgB,CAAC,OAAO,CAAC,CAkF3B;AAUD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|
package/dist/tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { execSandboxCommand } from "./sandbox.js";
|
|
3
|
-
import {
|
|
2
|
+
import { execSandboxCommand, underlyingSandbox } from "./sandbox.js";
|
|
3
|
+
import { isPackagedSkillPath, readPackagedSkillFile } from "./skills.js";
|
|
4
4
|
const hookToolRunResultSymbol = Symbol.for("fabric-harness.hook-tool-run-result");
|
|
5
5
|
/** Internal bridge preserving the V2 hook-tool envelope through portable runtimes. */
|
|
6
6
|
export function unwrapHookToolRunResult(value) {
|
|
@@ -150,49 +150,94 @@ function requireSandbox(sandbox) {
|
|
|
150
150
|
throw new Error("A SandboxEnv is required to execute this tool.");
|
|
151
151
|
return sandbox;
|
|
152
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Renders the exact sandbox command a scoped command tool runs for an input.
|
|
155
|
+
* A symbol property, so copies of the tool definition keep it and JSON drops it.
|
|
156
|
+
*/
|
|
157
|
+
const SCOPED_COMMAND_RENDERER = Symbol.for("fabric-harness.scopedCommandRenderer");
|
|
158
|
+
/** @internal Whether `tool` carries a scoped command renderer (`createCommandTools`). */
|
|
159
|
+
export function hasScopedCommandRenderer(tool) {
|
|
160
|
+
return Boolean(tool &&
|
|
161
|
+
typeof tool[SCOPED_COMMAND_RENDERER] ===
|
|
162
|
+
"function");
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @internal The exact command a scoped command tool runs for `input`, as the
|
|
166
|
+
* sandbox sees it, so an approval can be bound to that command.
|
|
167
|
+
*/
|
|
168
|
+
export function renderScopedCommand(tool, input) {
|
|
169
|
+
const render = tool
|
|
170
|
+
? tool[SCOPED_COMMAND_RENDERER]
|
|
171
|
+
: undefined;
|
|
172
|
+
if (typeof render !== "function")
|
|
173
|
+
return undefined;
|
|
174
|
+
try {
|
|
175
|
+
return render(input);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
153
181
|
export function createCommandTools(commands, options = {}) {
|
|
154
|
-
return commands.map((command) =>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
inputSchema: command.argsSchema ?? {
|
|
158
|
-
type: "object",
|
|
159
|
-
additionalProperties: false,
|
|
160
|
-
properties: {
|
|
161
|
-
args: { type: "array", items: { type: "string" }, description: "Command arguments." },
|
|
162
|
-
cwd: { type: "string", description: "Working directory inside the sandbox." },
|
|
163
|
-
timeout: { type: "number", description: "Timeout in milliseconds." },
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
metadata: {
|
|
167
|
-
kind: "command",
|
|
168
|
-
effect: "execute",
|
|
169
|
-
command: command.name,
|
|
170
|
-
executable: command.executable ?? command.name,
|
|
171
|
-
envKeys: Object.keys(command.env ?? {}),
|
|
172
|
-
},
|
|
173
|
-
async execute(input, context) {
|
|
174
|
-
const env = requireSandbox(context?.sandbox);
|
|
182
|
+
return commands.map((command) => {
|
|
183
|
+
const render = (input) => {
|
|
184
|
+
const safeInput = typeof input === "object" && input !== null ? input : {};
|
|
175
185
|
const builtArgs = command.buildArgs
|
|
176
|
-
? command.buildArgs(
|
|
177
|
-
: [
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
? command.buildArgs(safeInput)
|
|
187
|
+
: [
|
|
188
|
+
...(command.args ?? []),
|
|
189
|
+
...(Array.isArray(safeInput.args)
|
|
190
|
+
? safeInput.args.filter((value) => typeof value === "string")
|
|
191
|
+
: []),
|
|
192
|
+
];
|
|
193
|
+
return [command.executable ?? command.name, ...builtArgs.map(shellQuote)].join(" ");
|
|
194
|
+
};
|
|
195
|
+
const tool = defineTool({
|
|
196
|
+
name: command.name,
|
|
197
|
+
description: command.description ?? `Run the scoped ${command.name} command in the session sandbox.`,
|
|
198
|
+
inputSchema: command.argsSchema ?? {
|
|
199
|
+
type: "object",
|
|
200
|
+
additionalProperties: false,
|
|
201
|
+
properties: {
|
|
202
|
+
args: { type: "array", items: { type: "string" }, description: "Command arguments." },
|
|
203
|
+
cwd: { type: "string", description: "Working directory inside the sandbox." },
|
|
204
|
+
timeout: { type: "number", description: "Timeout in milliseconds." },
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
metadata: {
|
|
208
|
+
kind: "command",
|
|
209
|
+
effect: "execute",
|
|
210
|
+
command: command.name,
|
|
211
|
+
executable: command.executable ?? command.name,
|
|
212
|
+
envKeys: Object.keys(command.env ?? {}),
|
|
213
|
+
},
|
|
214
|
+
async execute(input, context) {
|
|
215
|
+
const env = requireSandbox(context?.sandbox);
|
|
216
|
+
// The harness renders once per call and hands that command here, so
|
|
217
|
+
// the command judged and approved is the one run.
|
|
218
|
+
const shellCommand = context?.__fabricScopedCommand ?? render(input);
|
|
219
|
+
const execOptions = {};
|
|
220
|
+
const scopedEnv = await resolveCommandEnv(command.env, options);
|
|
221
|
+
const cwd = input.cwd ?? command.cwd;
|
|
222
|
+
if (cwd !== undefined)
|
|
223
|
+
execOptions.cwd = cwd;
|
|
224
|
+
if (Object.keys(scopedEnv).length > 0)
|
|
225
|
+
execOptions.env = scopedEnv;
|
|
226
|
+
if (input.timeout !== undefined)
|
|
227
|
+
execOptions.timeout = input.timeout;
|
|
228
|
+
return execSandboxCommand(env, shellCommand, {
|
|
229
|
+
...execOptions,
|
|
230
|
+
...(context?.signal ? { signal: context.signal } : {}),
|
|
231
|
+
...(context?.onOrphanSettled ? { onOrphanSettled: context.onOrphanSettled } : {}),
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
Object.defineProperty(tool, SCOPED_COMMAND_RENDERER, {
|
|
236
|
+
value: (input) => render(input),
|
|
237
|
+
enumerable: true,
|
|
238
|
+
});
|
|
239
|
+
return tool;
|
|
240
|
+
});
|
|
196
241
|
}
|
|
197
242
|
export function createBuiltinTools(sandbox, packagedSkills) {
|
|
198
243
|
return [
|
|
@@ -644,10 +689,13 @@ function utf8Length(value) {
|
|
|
644
689
|
}
|
|
645
690
|
async function withFileMutation(env, file, signal, operation) {
|
|
646
691
|
const key = env.resolvePath(file);
|
|
647
|
-
|
|
692
|
+
// Locks belong to the sandbox itself, not to a policy or scope wrapper of
|
|
693
|
+
// it: a call's policy wrapper is created per call.
|
|
694
|
+
const owner = underlyingSandbox(env);
|
|
695
|
+
let queue = mutationQueues.get(owner);
|
|
648
696
|
if (!queue) {
|
|
649
697
|
queue = new Map();
|
|
650
|
-
mutationQueues.set(
|
|
698
|
+
mutationQueues.set(owner, queue);
|
|
651
699
|
}
|
|
652
700
|
const previous = queue.get(key) ?? Promise.resolve();
|
|
653
701
|
let release;
|
|
@@ -666,7 +714,7 @@ async function withFileMutation(env, file, signal, operation) {
|
|
|
666
714
|
if (queue.get(key) === tail)
|
|
667
715
|
queue.delete(key);
|
|
668
716
|
if (queue.size === 0)
|
|
669
|
-
mutationQueues.delete(
|
|
717
|
+
mutationQueues.delete(owner);
|
|
670
718
|
}
|
|
671
719
|
}
|
|
672
720
|
function countOccurrences(value, search) {
|
|
@@ -761,6 +809,14 @@ function isSecretRef(value) {
|
|
|
761
809
|
value.kind === "secret" &&
|
|
762
810
|
typeof value.name === "string");
|
|
763
811
|
}
|
|
812
|
+
/** Names of the result tools the native loop adds to a prompt's tools when it has a result validator. */
|
|
813
|
+
const FINISH_TOOL_NAME = "finish";
|
|
814
|
+
const GIVE_UP_TOOL_NAME = "give_up";
|
|
815
|
+
/** @internal Every tool name the harness itself adds to a prompt's tools after they are resolved. */
|
|
816
|
+
export const HARNESS_RESULT_TOOL_NAMES = Object.freeze([
|
|
817
|
+
FINISH_TOOL_NAME,
|
|
818
|
+
GIVE_UP_TOOL_NAME,
|
|
819
|
+
]);
|
|
764
820
|
/**
|
|
765
821
|
* Produce the per-call `finish` and `give_up` tool pair for a given ResultValidator.
|
|
766
822
|
*
|
|
@@ -781,7 +837,7 @@ export function createResultTools(validator) {
|
|
|
781
837
|
"cannot produce a result that conforms to the required schema. Provide a clear `reason`. " +
|
|
782
838
|
"This ends the task with a failure.";
|
|
783
839
|
const finishTool = {
|
|
784
|
-
name:
|
|
840
|
+
name: FINISH_TOOL_NAME,
|
|
785
841
|
description: finishDescription,
|
|
786
842
|
inputSchema: { type: "object", properties: {}, additionalProperties: true },
|
|
787
843
|
async execute(input) {
|
|
@@ -817,7 +873,7 @@ export function createResultTools(validator) {
|
|
|
817
873
|
},
|
|
818
874
|
};
|
|
819
875
|
const giveUpTool = {
|
|
820
|
-
name:
|
|
876
|
+
name: GIVE_UP_TOOL_NAME,
|
|
821
877
|
description: giveUpDescription,
|
|
822
878
|
inputSchema: {
|
|
823
879
|
type: "object",
|