@fabric-harness/sdk 6.9.1 → 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/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.map +1 -1
- package/dist/policied-sandbox.js +16 -3
- package/dist/policied-sandbox.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/session.d.ts +54 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +305 -23
- 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/tools.d.ts +2 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +10 -2
- 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
package/dist/session.d.ts
CHANGED
|
@@ -180,6 +180,12 @@ export declare class StubFabricSession implements FabricSession {
|
|
|
180
180
|
private readonly options;
|
|
181
181
|
private readonly store;
|
|
182
182
|
private readonly eventSubscribers;
|
|
183
|
+
/**
|
|
184
|
+
* The proposal tools of each tool map `resolveTools()` returned, decided
|
|
185
|
+
* once at resolution (#274). Dispatch and recovery read only this: a tool
|
|
186
|
+
* not found here runs as an ordinary tool, whatever its `execute` is later.
|
|
187
|
+
*/
|
|
188
|
+
private readonly resolvedProposals;
|
|
183
189
|
private durableRuntime;
|
|
184
190
|
private readonly mounts;
|
|
185
191
|
/** Set when this session has registered its sandbox in the in-process ref registry. */
|
|
@@ -211,6 +217,12 @@ export declare class StubFabricSession implements FabricSession {
|
|
|
211
217
|
* in-flight bytes. Deterministic ids for submissions keep recovery stable.
|
|
212
218
|
*/
|
|
213
219
|
private prepareInputAttachments;
|
|
220
|
+
/**
|
|
221
|
+
* A durable runtime receives neither this session's or the call's tools nor
|
|
222
|
+
* its proposal authority, so a proposal tool would silently not be offered.
|
|
223
|
+
* Refused here, called immediately before each delegation (prompt, task).
|
|
224
|
+
*/
|
|
225
|
+
private refuseProposalToolsOnDurableRuntime;
|
|
214
226
|
private getDurableRuntime;
|
|
215
227
|
voice(options: GovernedVoiceOptions): Promise<GovernedVoiceSession>;
|
|
216
228
|
prompt<TResult = string>(text: string, promptOptions?: PromptOptions<TResult>): Promise<TResult>;
|
|
@@ -281,6 +293,12 @@ export declare class StubFabricSession implements FabricSession {
|
|
|
281
293
|
* agent's rendered policy is re-rendered by the runtime, so for one only a
|
|
282
294
|
* policy the caller set on the session is forwarded.
|
|
283
295
|
*/
|
|
296
|
+
/**
|
|
297
|
+
* Prompt options forwarded to a durable runtime, with the policy above and
|
|
298
|
+
* the resolved `stopReasonGuard` (call over session over agent), so a
|
|
299
|
+
* setting made on `init()` or `agent.session()` reaches the worker's loop.
|
|
300
|
+
*/
|
|
301
|
+
private durablePromptOptions;
|
|
284
302
|
private durablePolicy;
|
|
285
303
|
private createSandbox;
|
|
286
304
|
private executeToolCalls;
|
|
@@ -293,7 +311,20 @@ export declare class StubFabricSession implements FabricSession {
|
|
|
293
311
|
private evaluateScopedCommandToolCall;
|
|
294
312
|
private commandTextForApproval;
|
|
295
313
|
private clampBashToolInput;
|
|
314
|
+
/**
|
|
315
|
+
* Combine the session's and the prompt's tools. Later definitions replace
|
|
316
|
+
* earlier ones of the same name. `policy` is the effective policy the tools
|
|
317
|
+
* will run under: proposal tools are checked against it here. Each tool is
|
|
318
|
+
* classified here, once, and the proposal tools are kept with the returned
|
|
319
|
+
* map for dispatch and recovery (#274).
|
|
320
|
+
*/
|
|
296
321
|
private resolveTools;
|
|
322
|
+
/**
|
|
323
|
+
* The resolution-time classification of `tool`, found in `tools` under
|
|
324
|
+
* `name`, if it was classified a proposal tool. A definition that replaced
|
|
325
|
+
* the classified one in the map afterwards is not a proposal tool.
|
|
326
|
+
*/
|
|
327
|
+
private resolvedProposal;
|
|
297
328
|
private activateSkillForTool;
|
|
298
329
|
/**
|
|
299
330
|
* Packaged directories the `read` tool can serve.
|
|
@@ -333,6 +364,29 @@ export declare class StubFabricSession implements FabricSession {
|
|
|
333
364
|
private authorizeRecoveredToolCall;
|
|
334
365
|
private recordEntry;
|
|
335
366
|
private finalizeDynamicResult;
|
|
367
|
+
/**
|
|
368
|
+
* Run one proposal call through the SDK-owned runner kept with the resolved
|
|
369
|
+
* tool, and settle it once. On the normal path this code writes no entry of
|
|
370
|
+
* its own between the call's tool_call entry and its tool_result. A failure
|
|
371
|
+
* after the port was called settles as a non-error `unknown` result; a
|
|
372
|
+
* failure before it is an ordinary error. This path attempts the result
|
|
373
|
+
* write once, unconditionally, as an ordinary tool does: if it fails, the
|
|
374
|
+
* error propagates, and a later prompt that finds the call trailing and
|
|
375
|
+
* dangling settles it as unknown. If a second prompt starts while the
|
|
376
|
+
* proposal is still in flight, that prompt can settle the call as unknown
|
|
377
|
+
* first and this path then appends the real result, so the call ends with
|
|
378
|
+
* two results; the port is still called at most once. Known and tracked in
|
|
379
|
+
* https://github.com/Fabric-Pro/fabric-harness/issues/335.
|
|
380
|
+
*/
|
|
381
|
+
private executeProposalCall;
|
|
382
|
+
/**
|
|
383
|
+
* Settle a dangling proposal call after a crash, as a non-error `unknown`
|
|
384
|
+
* result: the harness cannot tell whether the port was called, and it does
|
|
385
|
+
* not call it again. Only the tool_call entry's marker is read.
|
|
386
|
+
*/
|
|
387
|
+
private settleRecoveredProposal;
|
|
388
|
+
/** Refuse a proposal call with its configuration error; nothing is submitted. */
|
|
389
|
+
private refuseProposalCall;
|
|
336
390
|
private createToolStep;
|
|
337
391
|
private createToolProgressLogger;
|
|
338
392
|
private recordSandboxOrphanSettlement;
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAkB7B,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,aAAa,CAAC;AAYpE,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAkB7B,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,aAAa,CAAC;AAYpE,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAC;AAiCnE,OAAO,KAAK,EACV,gBAAgB,EAKhB,qBAAqB,EACrB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B;YAyDhB,IAAI;CAmBnB;AAgGD,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAiKD,oHAAoH;AACpH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,EAAE,EACvB,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,CAAC,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,GAC9C,qBAAqB,GAAG,SAAS,CAwBnC"}
|
package/dist/session.js
CHANGED
|
@@ -26,6 +26,7 @@ import { formatPackagedSkillResourceList, readPackagedSkillFile } from "./skills
|
|
|
26
26
|
import { defaultSessionStore } from "./store.js";
|
|
27
27
|
import { currentSubmissionContext } from "./submission-context.js";
|
|
28
28
|
import { executeTool } from "./tool-execution.js";
|
|
29
|
+
import { assertProposalToolConfiguration, classifyTools, createProposalCallTracker, isProposalTool, proposalApprovalRuleReason, proposalConfigurationError, proposalTranscriptRecord, unknownResult, } from "./proposal-tool.js";
|
|
29
30
|
import { createActivateSkillTool, createBuiltinTools, createCommandTools, hasScopedCommandRenderer, renderScopedCommand, shellQuote, unwrapHookToolRunResult, } from "./tools.js";
|
|
30
31
|
import { MAX_TASK_DEPTH } from "./types.js";
|
|
31
32
|
let nextTaskId = 0;
|
|
@@ -129,6 +130,12 @@ export class StubFabricSession {
|
|
|
129
130
|
options;
|
|
130
131
|
store;
|
|
131
132
|
eventSubscribers = new Set();
|
|
133
|
+
/**
|
|
134
|
+
* The proposal tools of each tool map `resolveTools()` returned, decided
|
|
135
|
+
* once at resolution (#274). Dispatch and recovery read only this: a tool
|
|
136
|
+
* not found here runs as an ordinary tool, whatever its `execute` is later.
|
|
137
|
+
*/
|
|
138
|
+
resolvedProposals = new WeakMap();
|
|
132
139
|
durableRuntime;
|
|
133
140
|
mounts = [];
|
|
134
141
|
/** Set when this session has registered its sandbox in the in-process ref registry. */
|
|
@@ -148,6 +155,11 @@ export class StubFabricSession {
|
|
|
148
155
|
this.id = id;
|
|
149
156
|
this.options = options;
|
|
150
157
|
this.store = options.store ?? defaultSessionStore;
|
|
158
|
+
// Session start: a proposal tool the policy would gate, that has no
|
|
159
|
+
// authority, or that shares a name is refused before anything runs. Each
|
|
160
|
+
// prompt and dynamic render checks again with its effective policy.
|
|
161
|
+
if (options.tools?.some(isProposalTool))
|
|
162
|
+
this.resolveTools([], [], options.policy);
|
|
151
163
|
this.sandboxPromise = this.createSandbox();
|
|
152
164
|
this.fs = createFabricFs(() => this.sandboxPromise);
|
|
153
165
|
this.costBudget = new CostBudgetTracker(options.costLimit);
|
|
@@ -197,6 +209,17 @@ export class StubFabricSession {
|
|
|
197
209
|
idPrefix: submissionId ? `att_${submissionId}` : `att_prompt_${randomUUID()}`,
|
|
198
210
|
});
|
|
199
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* A durable runtime receives neither this session's or the call's tools nor
|
|
214
|
+
* its proposal authority, so a proposal tool would silently not be offered.
|
|
215
|
+
* Refused here, called immediately before each delegation (prompt, task).
|
|
216
|
+
*/
|
|
217
|
+
refuseProposalToolsOnDurableRuntime(callTools) {
|
|
218
|
+
const delegated = [...(this.options.tools ?? []), ...(callTools ?? [])].find((tool) => isProposalTool(tool));
|
|
219
|
+
if (delegated) {
|
|
220
|
+
throw proposalConfigurationError(delegated.name, "cannot run on a durable session runtime: the runtime does not receive this session's tools or its proposal authority. Run proposal tools in an inline session.");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
200
223
|
getDurableRuntime() {
|
|
201
224
|
if (this.durableRuntime)
|
|
202
225
|
return this.durableRuntime;
|
|
@@ -277,15 +300,18 @@ export class StubFabricSession {
|
|
|
277
300
|
publicMessage: "Inline attachments are not supported by the configured durable runtime.",
|
|
278
301
|
});
|
|
279
302
|
}
|
|
303
|
+
this.refuseProposalToolsOnDurableRuntime(options.tools);
|
|
280
304
|
// Delegate to the durable runtime; the runtime is responsible for
|
|
281
305
|
// recording entries / events on its own side. We still emit a single
|
|
282
306
|
// local prompt_start/end pair so local subscribers see activity.
|
|
283
307
|
await this.emit("prompt_start", { text });
|
|
284
308
|
try {
|
|
309
|
+
// Checked again here: a prompt_start subscriber ran since the first check.
|
|
310
|
+
this.refuseProposalToolsOnDurableRuntime(options.tools);
|
|
285
311
|
const forwardedPolicy = this.durablePolicy(options.policy);
|
|
286
312
|
const result = await durable.prompt({
|
|
287
313
|
text,
|
|
288
|
-
options:
|
|
314
|
+
options: this.durablePromptOptions(options, forwardedPolicy),
|
|
289
315
|
...(this.options.dynamic ? { dynamic: this.options.dynamic.executionDescriptor() } : {}),
|
|
290
316
|
});
|
|
291
317
|
await this.emit("prompt_end", { text });
|
|
@@ -304,7 +330,7 @@ export class StubFabricSession {
|
|
|
304
330
|
const lifecycleSignal = options.signal ?? new AbortController().signal;
|
|
305
331
|
try {
|
|
306
332
|
let sandbox = createScopedSandboxEnv(await this.sandbox, options.cwd);
|
|
307
|
-
let tools = this.resolveTools(options.tools, options.commands);
|
|
333
|
+
let tools = this.resolveTools(options.tools, options.commands, options.policy ?? this.options.policy);
|
|
308
334
|
let joinedRenderReady = false;
|
|
309
335
|
const currentTurnConfiguration = () => ({
|
|
310
336
|
...(typeof this.options.model === "string" ? { model: this.options.model } : {}),
|
|
@@ -393,7 +419,7 @@ export class StubFabricSession {
|
|
|
393
419
|
}
|
|
394
420
|
role = this.resolveRole(this.options.role);
|
|
395
421
|
}
|
|
396
|
-
tools = this.resolveTools(options.tools, options.commands);
|
|
422
|
+
tools = this.resolveTools(options.tools, options.commands, options.policy ?? this.options.policy);
|
|
397
423
|
if (!config.dynamic) {
|
|
398
424
|
throw new Error("[fabric-harness] A dynamic-agent refresh did not return its runtime.");
|
|
399
425
|
}
|
|
@@ -569,6 +595,9 @@ export class StubFabricSession {
|
|
|
569
595
|
...(options.modelRetryDelayMs !== undefined
|
|
570
596
|
? { modelRetryDelayMs: options.modelRetryDelayMs }
|
|
571
597
|
: {}),
|
|
598
|
+
...((options.stopReasonGuard ?? this.options.stopReasonGuard) !== undefined
|
|
599
|
+
? { stopReasonGuard: options.stopReasonGuard ?? this.options.stopReasonGuard }
|
|
600
|
+
: {}),
|
|
572
601
|
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
573
602
|
...(options.policy !== undefined ? { policy: options.policy } : {}),
|
|
574
603
|
...((options.approvalTimeoutMs ?? this.options.approvalTimeoutMs) !== undefined
|
|
@@ -874,14 +903,15 @@ export class StubFabricSession {
|
|
|
874
903
|
publicMessage: "Inline attachments are not supported by the configured durable runtime.",
|
|
875
904
|
});
|
|
876
905
|
}
|
|
906
|
+
this.refuseProposalToolsOnDurableRuntime(options.tools);
|
|
877
907
|
const taskId = options.id ?? `${this.id}:task-${++nextTaskId}`;
|
|
878
908
|
await this.emit("task_start", { taskId, depth: 1, parentSessionId: this.id });
|
|
879
909
|
try {
|
|
910
|
+
// Checked again here: a task_start subscriber ran since the first check.
|
|
911
|
+
this.refuseProposalToolsOnDurableRuntime(options.tools);
|
|
880
912
|
const { id: _id, ...requestedTaskOptions } = options;
|
|
881
913
|
const forwardedPolicy = this.durablePolicy(options.policy);
|
|
882
|
-
const taskOptions = forwardedPolicy
|
|
883
|
-
? { ...requestedTaskOptions, policy: forwardedPolicy }
|
|
884
|
-
: requestedTaskOptions;
|
|
914
|
+
const taskOptions = this.durablePromptOptions(requestedTaskOptions, forwardedPolicy);
|
|
885
915
|
const result = await durable.task({
|
|
886
916
|
text,
|
|
887
917
|
taskId,
|
|
@@ -1718,6 +1748,19 @@ export class StubFabricSession {
|
|
|
1718
1748
|
* agent's rendered policy is re-rendered by the runtime, so for one only a
|
|
1719
1749
|
* policy the caller set on the session is forwarded.
|
|
1720
1750
|
*/
|
|
1751
|
+
/**
|
|
1752
|
+
* Prompt options forwarded to a durable runtime, with the policy above and
|
|
1753
|
+
* the resolved `stopReasonGuard` (call over session over agent), so a
|
|
1754
|
+
* setting made on `init()` or `agent.session()` reaches the worker's loop.
|
|
1755
|
+
*/
|
|
1756
|
+
durablePromptOptions(options, policy) {
|
|
1757
|
+
const stopReasonGuard = options.stopReasonGuard ?? this.options.stopReasonGuard;
|
|
1758
|
+
return {
|
|
1759
|
+
...options,
|
|
1760
|
+
...(policy !== undefined ? { policy } : {}),
|
|
1761
|
+
...(stopReasonGuard !== undefined ? { stopReasonGuard } : {}),
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1721
1764
|
durablePolicy(callPolicy, reRendered = true) {
|
|
1722
1765
|
if (callPolicy !== undefined)
|
|
1723
1766
|
return callPolicy;
|
|
@@ -1754,6 +1797,9 @@ export class StubFabricSession {
|
|
|
1754
1797
|
const sandbox = this.sandboxUnderPolicy(sessionSandbox, policy);
|
|
1755
1798
|
for (const requestedCall of calls) {
|
|
1756
1799
|
const tool = tools.get(requestedCall.tool);
|
|
1800
|
+
// Decided when these tools were resolved, and never derived again from
|
|
1801
|
+
// the definition: a tool not classified then runs as an ordinary tool.
|
|
1802
|
+
const proposal = this.resolvedProposal(tools, requestedCall.tool, tool);
|
|
1757
1803
|
const canonical = canonicalizeToolCall({
|
|
1758
1804
|
...requestedCall,
|
|
1759
1805
|
tool: tool?.policyAlias ?? requestedCall.tool,
|
|
@@ -1782,7 +1828,8 @@ export class StubFabricSession {
|
|
|
1782
1828
|
: (renderedCommand ?? this.commandTextForApproval(tool, call.input));
|
|
1783
1829
|
const executingPrincipal = toolExecutingPrincipal(tool);
|
|
1784
1830
|
const mountDecision = this.checkMountWriteAccess(call);
|
|
1785
|
-
|
|
1831
|
+
// Policy judges a proposal tool by its own name; resolution refuses an alias.
|
|
1832
|
+
const policyCall = !proposal && tool?.policyAlias ? { ...call, tool: tool.policyAlias } : call;
|
|
1786
1833
|
// File paths are judged in every form the sandbox reaches, as its layer
|
|
1787
1834
|
// judges them, so an approval is asked for here when one is needed there.
|
|
1788
1835
|
const decision = mountDecision ?? evaluateToolCallPolicyInSandbox(policyCall, policy, sandbox);
|
|
@@ -1822,6 +1869,12 @@ export class StubFabricSession {
|
|
|
1822
1869
|
continue;
|
|
1823
1870
|
}
|
|
1824
1871
|
if (!decision.allowed && decision.approvalRequired) {
|
|
1872
|
+
// Policy wins: a proposal tool matched by an approval rule here (a
|
|
1873
|
+
// call-level policy from a custom loop) is refused, never prompted.
|
|
1874
|
+
if (proposal) {
|
|
1875
|
+
await this.refuseProposalCall(call, toolCallId, proposalApprovalRuleReason(decision.matchedPattern), results);
|
|
1876
|
+
continue;
|
|
1877
|
+
}
|
|
1825
1878
|
const grant = await this.requestApproval({
|
|
1826
1879
|
kind: "tool",
|
|
1827
1880
|
tool: call.tool,
|
|
@@ -1863,6 +1916,10 @@ export class StubFabricSession {
|
|
|
1863
1916
|
}
|
|
1864
1917
|
}
|
|
1865
1918
|
if (!commandDecision.allowed && commandDecision.approvalRequired) {
|
|
1919
|
+
if (proposal) {
|
|
1920
|
+
await this.refuseProposalCall(call, toolCallId, proposalApprovalRuleReason(commandDecision.matchedPattern), results);
|
|
1921
|
+
continue;
|
|
1922
|
+
}
|
|
1866
1923
|
// The approval names the exact command the tool will run.
|
|
1867
1924
|
const grant = await this.requestApproval({
|
|
1868
1925
|
kind: "command",
|
|
@@ -1910,11 +1967,16 @@ export class StubFabricSession {
|
|
|
1910
1967
|
if (boundCommand !== undefined)
|
|
1911
1968
|
approvedSandboxCalls.push({ tool: "bash", input: { command: boundCommand } });
|
|
1912
1969
|
}
|
|
1913
|
-
await (recordToolCall ?? ((data) => this.recordEntry("tool_call", data)))({
|
|
1970
|
+
const toolCallEntry = await (recordToolCall ?? ((data) => this.recordEntry("tool_call", data)))({
|
|
1914
1971
|
tool: call.tool,
|
|
1915
1972
|
input: call.input,
|
|
1916
1973
|
inputDigest: approvalInputDigest(call.input),
|
|
1917
1974
|
policyDigest: approvalInputDigest(policy ?? null),
|
|
1975
|
+
// Harness-set from the resolution-time classification: recovery settles
|
|
1976
|
+
// a trailing dangling call carrying it as unknown and does not run it
|
|
1977
|
+
// again. A call hidden behind a later turn boundary (a signal, say)
|
|
1978
|
+
// is outside the trailing window and is not settled by recovery.
|
|
1979
|
+
...(proposal ? { proposal: { actionId: proposal.runner.actionId } } : {}),
|
|
1918
1980
|
...(executingPrincipal
|
|
1919
1981
|
? { executingPrincipal: executingPrincipal }
|
|
1920
1982
|
: {}),
|
|
@@ -1938,6 +2000,18 @@ export class StubFabricSession {
|
|
|
1938
2000
|
...(effectiveInput !== undefined ? { input: effectiveInput } : {}),
|
|
1939
2001
|
...(attribution ? { attribution: attribution } : {}),
|
|
1940
2002
|
});
|
|
2003
|
+
if (proposal) {
|
|
2004
|
+
await this.executeProposalCall({
|
|
2005
|
+
call,
|
|
2006
|
+
proposal,
|
|
2007
|
+
toolCallId,
|
|
2008
|
+
sandbox,
|
|
2009
|
+
results,
|
|
2010
|
+
...(signal ? { signal } : {}),
|
|
2011
|
+
...(attribution ? { attribution: attribution } : {}),
|
|
2012
|
+
});
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
1941
2015
|
if (!tool?.execute) {
|
|
1942
2016
|
const error = `Tool is not available: ${call.tool}`;
|
|
1943
2017
|
results.push({
|
|
@@ -2284,31 +2358,63 @@ export class StubFabricSession {
|
|
|
2284
2358
|
const timeout = typeof record.timeout === "number" ? record.timeout : undefined;
|
|
2285
2359
|
return { ...record, timeout: clampCommandTimeout(timeout, policy) };
|
|
2286
2360
|
}
|
|
2287
|
-
|
|
2288
|
-
|
|
2361
|
+
/**
|
|
2362
|
+
* Combine the session's and the prompt's tools. Later definitions replace
|
|
2363
|
+
* earlier ones of the same name. `policy` is the effective policy the tools
|
|
2364
|
+
* will run under: proposal tools are checked against it here. Each tool is
|
|
2365
|
+
* classified here, once, and the proposal tools are kept with the returned
|
|
2366
|
+
* map for dispatch and recovery (#274).
|
|
2367
|
+
*/
|
|
2368
|
+
resolveTools(promptTools, promptCommands, policy) {
|
|
2369
|
+
const ordered = [];
|
|
2289
2370
|
const commandToolOptions = this.options.resolveSecret
|
|
2290
2371
|
? { resolveSecret: this.options.resolveSecret }
|
|
2291
2372
|
: {};
|
|
2292
2373
|
// Built-ins run on the sandbox each call is handed (`context.sandbox`),
|
|
2293
2374
|
// which carries that call's effective policy, not one captured here.
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
for (const
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2375
|
+
// One push per tool: a spread argument list has an engine limit, and the
|
|
2376
|
+
// base resolved lists of any length.
|
|
2377
|
+
for (const list of [
|
|
2378
|
+
createBuiltinTools(undefined, this.effectivePackagedSkills()),
|
|
2379
|
+
createCommandTools(this.options.commands ?? [], commandToolOptions),
|
|
2380
|
+
this.options.tools ?? [],
|
|
2381
|
+
createCommandTools(promptCommands ?? [], commandToolOptions),
|
|
2382
|
+
promptTools ?? [],
|
|
2383
|
+
]) {
|
|
2384
|
+
for (const tool of list)
|
|
2385
|
+
ordered.push(tool);
|
|
2386
|
+
}
|
|
2304
2387
|
const skills = this.options.skills ?? [];
|
|
2305
2388
|
if (skills.length > 0) {
|
|
2306
2389
|
const skillNames = skills.map((skill) => skill.name);
|
|
2307
|
-
|
|
2308
|
-
tools.set(activateSkillTool.name, activateSkillTool);
|
|
2390
|
+
ordered.push(createActivateSkillTool(skillNames, (name) => this.activateSkillForTool(name)));
|
|
2309
2391
|
}
|
|
2392
|
+
const classified = classifyTools(ordered);
|
|
2393
|
+
const authority = this.options.proposalAuthority;
|
|
2394
|
+
assertProposalToolConfiguration({ tools: classified, policy, authority });
|
|
2395
|
+
const tools = new Map();
|
|
2396
|
+
for (const tool of ordered)
|
|
2397
|
+
tools.set(tool.name, tool);
|
|
2398
|
+
const proposals = new Map();
|
|
2399
|
+
for (const { tool, runner } of classified) {
|
|
2400
|
+
// The configuration check above refused a proposal tool without an
|
|
2401
|
+
// authority or sharing its name, so each one is its name's only tool.
|
|
2402
|
+
if (runner && authority)
|
|
2403
|
+
proposals.set(tool.name, { tool, runner, authority });
|
|
2404
|
+
}
|
|
2405
|
+
if (proposals.size > 0)
|
|
2406
|
+
this.resolvedProposals.set(tools, proposals);
|
|
2310
2407
|
return tools;
|
|
2311
2408
|
}
|
|
2409
|
+
/**
|
|
2410
|
+
* The resolution-time classification of `tool`, found in `tools` under
|
|
2411
|
+
* `name`, if it was classified a proposal tool. A definition that replaced
|
|
2412
|
+
* the classified one in the map afterwards is not a proposal tool.
|
|
2413
|
+
*/
|
|
2414
|
+
resolvedProposal(tools, name, tool) {
|
|
2415
|
+
const resolved = this.resolvedProposals.get(tools)?.get(name);
|
|
2416
|
+
return resolved !== undefined && resolved.tool === tool ? resolved : undefined;
|
|
2417
|
+
}
|
|
2312
2418
|
async activateSkillForTool(name) {
|
|
2313
2419
|
const cached = this.skillCache.get(name);
|
|
2314
2420
|
if (cached !== undefined)
|
|
@@ -2466,12 +2572,23 @@ export class StubFabricSession {
|
|
|
2466
2572
|
for (const call of dangling) {
|
|
2467
2573
|
const toolName = typeof call.data?.tool === "string" ? call.data.tool : undefined;
|
|
2468
2574
|
const toolCallId = typeof call.data?.toolCallId === "string" ? call.data.toolCallId : undefined;
|
|
2575
|
+
// A proposal call carries the harness's marker on its tool_call entry.
|
|
2576
|
+
// It is settled as unknown, from the marker alone: it is never run
|
|
2577
|
+
// again, the port is not called, and the current tool of that name,
|
|
2578
|
+
// if any, is not consulted.
|
|
2579
|
+
if (call.data?.proposal !== undefined && toolName && toolCallId) {
|
|
2580
|
+
await this.settleRecoveredProposal(call, toolName, toolCallId);
|
|
2581
|
+
continue;
|
|
2582
|
+
}
|
|
2469
2583
|
const tool = toolName ? tools.get(toolName) : undefined;
|
|
2470
2584
|
if (call.data?.durable !== true ||
|
|
2471
2585
|
!tool?.durable ||
|
|
2472
2586
|
!tool.execute ||
|
|
2473
2587
|
!toolCallId ||
|
|
2474
|
-
!toolName
|
|
2588
|
+
!toolName ||
|
|
2589
|
+
// An unmarked call never runs through a tool that is now a proposal
|
|
2590
|
+
// tool; it is settled below like any call that cannot be re-entered.
|
|
2591
|
+
this.resolvedProposal(tools, toolName, tool) !== undefined) {
|
|
2475
2592
|
continue;
|
|
2476
2593
|
}
|
|
2477
2594
|
await this.emit("tool_start", {
|
|
@@ -2860,6 +2977,145 @@ export class StubFabricSession {
|
|
|
2860
2977
|
}
|
|
2861
2978
|
return { value, continued: appended.length > 0 };
|
|
2862
2979
|
}
|
|
2980
|
+
/**
|
|
2981
|
+
* Run one proposal call through the SDK-owned runner kept with the resolved
|
|
2982
|
+
* tool, and settle it once. On the normal path this code writes no entry of
|
|
2983
|
+
* its own between the call's tool_call entry and its tool_result. A failure
|
|
2984
|
+
* after the port was called settles as a non-error `unknown` result; a
|
|
2985
|
+
* failure before it is an ordinary error. This path attempts the result
|
|
2986
|
+
* write once, unconditionally, as an ordinary tool does: if it fails, the
|
|
2987
|
+
* error propagates, and a later prompt that finds the call trailing and
|
|
2988
|
+
* dangling settles it as unknown. If a second prompt starts while the
|
|
2989
|
+
* proposal is still in flight, that prompt can settle the call as unknown
|
|
2990
|
+
* first and this path then appends the real result, so the call ends with
|
|
2991
|
+
* two results; the port is still called at most once. Known and tracked in
|
|
2992
|
+
* https://github.com/Fabric-Pro/fabric-harness/issues/335.
|
|
2993
|
+
*/
|
|
2994
|
+
async executeProposalCall(input) {
|
|
2995
|
+
const { call, proposal, toolCallId, results, attribution } = input;
|
|
2996
|
+
const tracker = createProposalCallTracker({
|
|
2997
|
+
sessionId: this.id,
|
|
2998
|
+
...(this.options.tenantId !== undefined ? { tenantId: this.options.tenantId } : {}),
|
|
2999
|
+
...(this.options.actor !== undefined ? { actor: this.options.actor } : {}),
|
|
3000
|
+
authority: proposal.authority,
|
|
3001
|
+
});
|
|
3002
|
+
const startedAt = performance.now();
|
|
3003
|
+
let result;
|
|
3004
|
+
let failure;
|
|
3005
|
+
try {
|
|
3006
|
+
// No progress logger: it writes transcript entries of its own, which
|
|
3007
|
+
// would land between this call's tool_call and its tool_result.
|
|
3008
|
+
await executeTool(proposalDispatchTool(proposal, tracker.binding), call.input, {
|
|
3009
|
+
sandbox: input.sandbox,
|
|
3010
|
+
toolCallId,
|
|
3011
|
+
...(input.signal ? { signal: input.signal } : {}),
|
|
3012
|
+
});
|
|
3013
|
+
result = tracker.outcome()?.result;
|
|
3014
|
+
}
|
|
3015
|
+
catch (error) {
|
|
3016
|
+
failure = error;
|
|
3017
|
+
}
|
|
3018
|
+
const durationMs = Math.max(0, Math.round(performance.now() - startedAt));
|
|
3019
|
+
// An abort before submission reaches here from the shared abort helper,
|
|
3020
|
+
// which copies the abort reason's text into an AbortError. That text is
|
|
3021
|
+
// not this tool's to publish: replace it with a fixed message. Errors
|
|
3022
|
+
// proposal-tool.ts itself throws are not AbortErrors and keep their text.
|
|
3023
|
+
// Matched by name: the looser isAbortError() also matches message text, and
|
|
3024
|
+
// a validation error that mentions "cancelled" must keep its message.
|
|
3025
|
+
if (failure instanceof Error &&
|
|
3026
|
+
failure.name === "AbortError" &&
|
|
3027
|
+
tracker.submittedKey() === undefined) {
|
|
3028
|
+
failure = new Error(`Proposal tool "${call.tool}" was cancelled before submission; nothing was submitted.`);
|
|
3029
|
+
}
|
|
3030
|
+
// A failure after the port was called (an answer that could not be read,
|
|
3031
|
+
// say) may still have landed: unknown, not an error.
|
|
3032
|
+
const submittedKey = tracker.submittedKey();
|
|
3033
|
+
if (result === undefined && submittedKey !== undefined)
|
|
3034
|
+
result = unknownResult(submittedKey);
|
|
3035
|
+
if (result === undefined) {
|
|
3036
|
+
const message = failure instanceof Error ? failure.message : String(failure);
|
|
3037
|
+
results.push({
|
|
3038
|
+
tool: call.tool,
|
|
3039
|
+
input: call.input,
|
|
3040
|
+
error: message,
|
|
3041
|
+
...(call.id ? { id: toolCallId } : {}),
|
|
3042
|
+
});
|
|
3043
|
+
await this.recordEntry("error", { tool: call.tool, toolCallId, error: message });
|
|
3044
|
+
await deliverAfterSettlement(call.tool, () => this.emit("tool_end", {
|
|
3045
|
+
tool: call.tool,
|
|
3046
|
+
toolCallId,
|
|
3047
|
+
durationMs,
|
|
3048
|
+
error: message,
|
|
3049
|
+
...(attribution ? { attribution } : {}),
|
|
3050
|
+
}));
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
3053
|
+
const output = result;
|
|
3054
|
+
await this.recordToolResult({
|
|
3055
|
+
tool: call.tool,
|
|
3056
|
+
output,
|
|
3057
|
+
durationMs,
|
|
3058
|
+
toolCallId,
|
|
3059
|
+
// Harness-set: only the SDK-owned runner's outcome produces it.
|
|
3060
|
+
proposal: proposalTranscriptRecord({ actionId: proposal.runner.actionId, result }),
|
|
3061
|
+
...(attribution ? { attribution } : {}),
|
|
3062
|
+
}, []);
|
|
3063
|
+
results.push({
|
|
3064
|
+
tool: call.tool,
|
|
3065
|
+
input: call.input,
|
|
3066
|
+
output: result,
|
|
3067
|
+
...(call.id ? { id: toolCallId } : {}),
|
|
3068
|
+
});
|
|
3069
|
+
await deliverAfterSettlement(call.tool, () => this.emit("tool_end", {
|
|
3070
|
+
tool: call.tool,
|
|
3071
|
+
toolCallId,
|
|
3072
|
+
durationMs,
|
|
3073
|
+
output,
|
|
3074
|
+
...(attribution ? { attribution } : {}),
|
|
3075
|
+
}));
|
|
3076
|
+
}
|
|
3077
|
+
/**
|
|
3078
|
+
* Settle a dangling proposal call after a crash, as a non-error `unknown`
|
|
3079
|
+
* result: the harness cannot tell whether the port was called, and it does
|
|
3080
|
+
* not call it again. Only the tool_call entry's marker is read.
|
|
3081
|
+
*/
|
|
3082
|
+
async settleRecoveredProposal(call, toolName, toolCallId) {
|
|
3083
|
+
const marker = call.data?.proposal;
|
|
3084
|
+
const markedAction = typeof marker === "object" && marker !== null && !Array.isArray(marker)
|
|
3085
|
+
? marker.actionId
|
|
3086
|
+
: undefined;
|
|
3087
|
+
const result = unknownResult();
|
|
3088
|
+
const output = result;
|
|
3089
|
+
await this.recordToolResult({
|
|
3090
|
+
tool: toolName,
|
|
3091
|
+
toolCallId,
|
|
3092
|
+
output,
|
|
3093
|
+
durationMs: 0,
|
|
3094
|
+
proposal: proposalTranscriptRecord({
|
|
3095
|
+
actionId: typeof markedAction === "string" ? markedAction : "",
|
|
3096
|
+
result,
|
|
3097
|
+
}),
|
|
3098
|
+
recovered: true,
|
|
3099
|
+
}, []);
|
|
3100
|
+
await deliverAfterSettlement(toolName, () => this.emit("tool_end", { tool: toolName, recovery: true, toolCallId, durationMs: 0, output }));
|
|
3101
|
+
}
|
|
3102
|
+
/** Refuse a proposal call with its configuration error; nothing is submitted. */
|
|
3103
|
+
async refuseProposalCall(call, toolCallId, reason, results) {
|
|
3104
|
+
const error = proposalConfigurationError(call.tool, reason).message;
|
|
3105
|
+
results.push({
|
|
3106
|
+
tool: call.tool,
|
|
3107
|
+
input: call.input,
|
|
3108
|
+
error,
|
|
3109
|
+
...(call.id ? { id: call.id } : {}),
|
|
3110
|
+
});
|
|
3111
|
+
await this.recordEntry("error", {
|
|
3112
|
+
tool: call.tool,
|
|
3113
|
+
toolCallId,
|
|
3114
|
+
error,
|
|
3115
|
+
approvalRequired: false,
|
|
3116
|
+
});
|
|
3117
|
+
await this.emit("error", { tool: call.tool, error, approvalRequired: false });
|
|
3118
|
+
}
|
|
2863
3119
|
createToolStep(toolCallId) {
|
|
2864
3120
|
const used = new Set();
|
|
2865
3121
|
return {
|
|
@@ -3346,6 +3602,32 @@ function isAbortError(error) {
|
|
|
3346
3602
|
function sameFabricActor(a, b) {
|
|
3347
3603
|
return approvalInputDigest(a ?? null) === approvalInputDigest(b ?? null);
|
|
3348
3604
|
}
|
|
3605
|
+
/** The tool the session dispatches for a proposal call: the stored SDK-owned runner, never `tool.execute`. */
|
|
3606
|
+
function proposalDispatchTool(proposal, binding) {
|
|
3607
|
+
const timeoutMs = proposal.tool.timeoutMs;
|
|
3608
|
+
return {
|
|
3609
|
+
name: proposal.tool.name,
|
|
3610
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
3611
|
+
execute: (input, context) => proposal.runner.run(input, context, binding),
|
|
3612
|
+
};
|
|
3613
|
+
}
|
|
3614
|
+
/**
|
|
3615
|
+
* Run event delivery after a proposal call settled. A failing subscriber is
|
|
3616
|
+
* logged with a fixed label and cannot re-enter settlement.
|
|
3617
|
+
*/
|
|
3618
|
+
async function deliverAfterSettlement(tool, deliver) {
|
|
3619
|
+
try {
|
|
3620
|
+
await deliver();
|
|
3621
|
+
}
|
|
3622
|
+
catch {
|
|
3623
|
+
try {
|
|
3624
|
+
getLogger().warn("tool_end delivery failed after a proposal call settled", { tool });
|
|
3625
|
+
}
|
|
3626
|
+
catch {
|
|
3627
|
+
// Diagnostics never decide the outcome.
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3349
3631
|
function toolStepEntryId(toolCallId, name) {
|
|
3350
3632
|
return `tool-step:${encodeURIComponent(toolCallId)}:${encodeURIComponent(name)}`;
|
|
3351
3633
|
}
|