@code-yeongyu/senpi-agent-core 2026.11.3-3 → 2026.11.5-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-loop.js +20 -186
- package/dist/agent.d.ts +4 -0
- package/dist/agent.js +4 -0
- package/dist/conformance/index.d.ts +30 -0
- package/dist/conformance/index.js +21 -0
- package/dist/conformance/loop-core-manifest.d.ts +1 -1
- package/dist/conformance/loop-core-manifest.js +18 -0
- package/dist/conformance/registry.js +20 -18
- package/dist/egress/types.d.ts +102 -0
- package/dist/egress/types.js +7 -0
- package/dist/execution/canonical-digest.d.ts +10 -0
- package/dist/execution/canonical-digest.js +20 -0
- package/dist/execution/canonical-json.d.ts +3 -0
- package/dist/execution/canonical-json.js +12 -0
- package/dist/execution/chain-count.d.ts +26 -0
- package/dist/execution/chain-count.js +45 -0
- package/dist/execution/coordinator-codec.js +13 -2
- package/dist/execution/coordinator-consent.d.ts +29 -0
- package/dist/execution/coordinator-consent.js +63 -0
- package/dist/execution/coordinator-plan.d.ts +1 -2
- package/dist/execution/coordinator-plan.js +4 -17
- package/dist/execution/coordinator-sequential.d.ts +15 -0
- package/dist/execution/coordinator-sequential.js +34 -0
- package/dist/execution/coordinator-types.d.ts +45 -0
- package/dist/execution/coordinator.d.ts +3 -1
- package/dist/execution/coordinator.js +35 -3
- package/dist/execution/device-files-node.d.ts +8 -0
- package/dist/execution/device-files-node.js +150 -0
- package/dist/execution/device-files.d.ts +109 -0
- package/dist/execution/device-files.js +124 -0
- package/dist/execution/ledger-types.d.ts +3 -1
- package/dist/execution/ledger.d.ts +9 -3
- package/dist/execution/ledger.js +8 -2
- package/dist/execution/loop-hook-host-hand.d.ts +33 -0
- package/dist/execution/loop-hook-host-hand.js +71 -0
- package/dist/execution/loop-hook-host-protocol.d.ts +46 -0
- package/dist/execution/loop-hook-host-protocol.js +47 -0
- package/dist/execution/loop-hook-host.d.ts +40 -0
- package/dist/execution/loop-hook-host.js +87 -0
- package/dist/execution/nested-codec.d.ts +5 -0
- package/dist/execution/nested-codec.js +41 -0
- package/dist/execution/nested-types.d.ts +92 -0
- package/dist/execution/nested-types.js +3 -0
- package/dist/execution/nested.d.ts +48 -0
- package/dist/execution/nested.js +206 -0
- package/dist/execution/plane-model.d.ts +33 -0
- package/dist/execution/plane-model.js +80 -0
- package/dist/execution/plane-session.d.ts +56 -0
- package/dist/execution/plane-session.js +178 -0
- package/dist/execution/plane.d.ts +75 -0
- package/dist/execution/plane.js +172 -0
- package/dist/execution/prepared/executor-body.d.ts +22 -0
- package/dist/execution/prepared/executor-body.js +73 -0
- package/dist/execution/prepared/executor-freeze.d.ts +17 -0
- package/dist/execution/prepared/executor-freeze.js +42 -0
- package/dist/execution/prepared/executor-pipeline.d.ts +11 -0
- package/dist/execution/prepared/executor-pipeline.js +26 -0
- package/dist/execution/prepared/executor-types.d.ts +131 -0
- package/dist/execution/prepared/executor-types.js +2 -0
- package/dist/execution/prepared/executor.d.ts +8 -0
- package/dist/execution/prepared/executor.js +261 -0
- package/dist/execution/prepared/memory-batch-store.d.ts +4 -0
- package/dist/execution/prepared/memory-batch-store.js +4 -0
- package/dist/execution/prepared/pipeline-prepared-batch.d.ts +27 -0
- package/dist/execution/prepared/pipeline-prepared-batch.js +175 -0
- package/dist/execution/prepared/pipeline-prepared.d.ts +10 -0
- package/dist/execution/prepared/pipeline-prepared.js +54 -0
- package/dist/execution/remote-device-files.d.ts +12 -0
- package/dist/execution/remote-device-files.js +113 -0
- package/dist/execution/remote-epoch-gate.d.ts +19 -0
- package/dist/execution/remote-epoch-gate.js +46 -0
- package/dist/execution/remote-epoch.d.ts +53 -0
- package/dist/execution/remote-epoch.js +74 -0
- package/dist/execution/remote-executor.d.ts +17 -0
- package/dist/execution/remote-executor.js +70 -18
- package/dist/execution/remote-file-call.d.ts +14 -0
- package/dist/execution/remote-file-call.js +31 -0
- package/dist/execution/remote-hand-ledger.d.ts +11 -3
- package/dist/execution/remote-hand-ledger.js +31 -15
- package/dist/execution/remote-link.d.ts +41 -0
- package/dist/execution/remote-link.js +153 -0
- package/dist/execution/remote-protocol.d.ts +50 -4
- package/dist/execution/remote-protocol.js +48 -2
- package/dist/execution/remote-tool-host.d.ts +23 -3
- package/dist/execution/remote-tool-host.js +25 -64
- package/dist/execution/scope-lifecycle.d.ts +81 -0
- package/dist/execution/scope-lifecycle.js +173 -0
- package/dist/execution/testing/batch-executor.js +32 -3
- package/dist/execution/testing/batch-harness.d.ts +25 -3
- package/dist/execution/testing/batch-harness.js +83 -5
- package/dist/execution/testing/cancel-cases.d.ts +8 -0
- package/dist/execution/testing/cancel-cases.js +64 -0
- package/dist/execution/testing/consent-cases.d.ts +14 -0
- package/dist/execution/testing/consent-cases.js +66 -0
- package/dist/execution/testing/epoch-cases.d.ts +8 -0
- package/dist/execution/testing/epoch-cases.js +84 -0
- package/dist/execution/testing/epoch-harness.d.ts +47 -0
- package/dist/execution/testing/epoch-harness.js +172 -0
- package/dist/execution/testing/epoch-registry.d.ts +3 -0
- package/dist/execution/testing/epoch-registry.js +17 -0
- package/dist/execution/testing/hand-harness.d.ts +3 -0
- package/dist/execution/testing/hand-harness.js +27 -22
- package/dist/execution/testing/hand-registry.d.ts +3 -0
- package/dist/execution/testing/hand-registry.js +20 -0
- package/dist/execution/testing/kill-epoch.d.ts +9 -0
- package/dist/execution/testing/kill-epoch.js +71 -0
- package/dist/execution/testing/kill-hook.d.ts +14 -0
- package/dist/execution/testing/kill-hook.js +117 -0
- package/dist/execution/testing/kill-nest.d.ts +6 -0
- package/dist/execution/testing/kill-nest.js +55 -0
- package/dist/execution/testing/kill-wakex.d.ts +6 -0
- package/dist/execution/testing/kill-wakex.js +81 -0
- package/dist/execution/testing/lifecycle-cases.d.ts +9 -0
- package/dist/execution/testing/lifecycle-cases.js +60 -0
- package/dist/execution/testing/lifecycle-registry.d.ts +3 -0
- package/dist/execution/testing/lifecycle-registry.js +19 -0
- package/dist/execution/testing/multi-epoch-cases.d.ts +4 -0
- package/dist/execution/testing/multi-epoch-cases.js +29 -0
- package/dist/execution/testing/multi-lifecycle-cases.d.ts +4 -0
- package/dist/execution/testing/multi-lifecycle-cases.js +34 -0
- package/dist/execution/testing/multi-seq-cases.d.ts +4 -0
- package/dist/execution/testing/multi-seq-cases.js +46 -0
- package/dist/execution/testing/nest-cases.d.ts +39 -0
- package/dist/execution/testing/nest-cases.js +181 -0
- package/dist/execution/testing/nest-registry.d.ts +3 -0
- package/dist/execution/testing/nest-registry.js +27 -0
- package/dist/execution/testing/scope-cases.d.ts +6 -0
- package/dist/execution/testing/scope-cases.js +49 -0
- package/dist/execution/testing/seq-cases.d.ts +6 -0
- package/dist/execution/testing/seq-cases.js +71 -0
- package/dist/execution/testing/seq-registry.d.ts +3 -0
- package/dist/execution/testing/seq-registry.js +32 -0
- package/dist/execution/testing/wake-exec-cases.d.ts +20 -0
- package/dist/execution/testing/wake-exec-cases.js +147 -0
- package/dist/execution/testing/wake-registry.d.ts +3 -0
- package/dist/execution/testing/wake-registry.js +26 -0
- package/dist/execution/tool-host.d.ts +23 -3
- package/dist/execution/tool-host.js +18 -1
- package/dist/execution/tool-outcome-events.d.ts +11 -0
- package/dist/execution/tool-outcome-events.js +47 -0
- package/dist/execution/wake-inbox.d.ts +25 -0
- package/dist/execution/wake-inbox.js +85 -0
- package/dist/execution/wake-outbox.d.ts +30 -0
- package/dist/execution/wake-outbox.js +87 -0
- package/dist/execution/wake-types.d.ts +45 -0
- package/dist/execution/wake-types.js +3 -0
- package/dist/harness/agent-harness.d.ts +6 -0
- package/dist/harness/execution/tool-host-call.d.ts +13 -0
- package/dist/harness/execution/tool-host-call.js +55 -0
- package/dist/harness/execution/tools.d.ts +2 -1
- package/dist/harness/execution/tools.js +32 -17
- package/dist/harness/runtime/drive/tools.js +1 -1
- package/dist/harness/runtime/harness.js +1 -0
- package/dist/harness/runtime/types.d.ts +1 -0
- package/dist/index.d.ts +27 -2
- package/dist/index.js +24 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.js +1 -0
- package/dist/public-entry.d.ts +10 -0
- package/dist/public-entry.js +23 -0
- package/dist/step-commit.d.ts +24 -0
- package/dist/step-commit.js +24 -0
- package/dist/tool-name-alias.d.ts +1 -7
- package/dist/tool-name-alias.js +0 -17
- package/dist/transport/testing/multi-cases.js +8 -8
- package/dist/types.d.ts +37 -1
- package/package.json +3 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createToolResultMessage, emitToolResultMessage, shouldTerminateToolBatch } from "../tool-outcome-events.js";
|
|
2
|
+
import { runPreparedBatch } from "./pipeline-prepared-batch.js";
|
|
3
|
+
/**
|
|
4
|
+
* The prepared pipeline as the session's ToolHost (S18b): every model-issued batch runs through the batch coordinator
|
|
5
|
+
* and the prepared executor in this process, with today's events, result messages and source order. A batch the loop
|
|
6
|
+
* runs sequentially runs as consecutive one-call batches, so each call is prepared after the previous one finished.
|
|
7
|
+
*/
|
|
8
|
+
export function createPreparedToolHost(source, openStore) {
|
|
9
|
+
return {
|
|
10
|
+
async execute(call, options) {
|
|
11
|
+
const { emit, signal, recordWitness, local } = options;
|
|
12
|
+
if (local === undefined)
|
|
13
|
+
throw new Error("the prepared pipeline runs only in the loop's own process");
|
|
14
|
+
if (recordWitness) {
|
|
15
|
+
for (const raw of call.calls) {
|
|
16
|
+
const pending = recordWitness({ pipeline: "prepared", toolCallId: raw.id });
|
|
17
|
+
if (pending)
|
|
18
|
+
await pending;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const batch = (calls) => runPreparedBatch({
|
|
22
|
+
source,
|
|
23
|
+
openStore,
|
|
24
|
+
calls,
|
|
25
|
+
scope: call.scope,
|
|
26
|
+
context: local.context,
|
|
27
|
+
assistantMessage: local.assistantMessage,
|
|
28
|
+
emit,
|
|
29
|
+
...(signal === undefined ? {} : { signal }),
|
|
30
|
+
});
|
|
31
|
+
const outcomes = [];
|
|
32
|
+
const messages = [];
|
|
33
|
+
const report = async (finished) => {
|
|
34
|
+
for (const outcome of finished) {
|
|
35
|
+
const message = createToolResultMessage(outcome);
|
|
36
|
+
await emitToolResultMessage(message, emit);
|
|
37
|
+
outcomes.push(outcome);
|
|
38
|
+
messages.push(message);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
if (call.mode === "sequential") {
|
|
42
|
+
for (const raw of call.calls) {
|
|
43
|
+
await report(await batch([raw]));
|
|
44
|
+
if (signal?.aborted)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
await report(await batch(call.calls));
|
|
50
|
+
return { messages, terminate: shouldTerminateToolBatch(outcomes) };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=pipeline-prepared.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DeviceFiles } from "./device-files.ts";
|
|
2
|
+
import type { HandLink } from "./remote-link.ts";
|
|
3
|
+
import type { ExecutionScope } from "./tool-host.ts";
|
|
4
|
+
/** How long an operation waits for the hand's `hello` before answering `unsupported` (C1). */
|
|
5
|
+
export declare const HELLO_WAIT_MS = 5000;
|
|
6
|
+
/**
|
|
7
|
+
* A session's {@link DeviceFiles} on a hand (S40): each operation is one `file` message on the scope's lane, after the
|
|
8
|
+
* hand announced the channel in its `hello` (or `unsupported`, sent nowhere). A write over the limit is refused here,
|
|
9
|
+
* before anything is sent; the hand checks the limit again before it reads or writes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRemoteDeviceFiles(link: HandLink, scope: ExecutionScope, mintId: () => string): DeviceFiles;
|
|
12
|
+
//# sourceMappingURL=remote-device-files.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DeviceFileError, decodeBase64, encodeBase64, FILE_CHANNEL, FILE_CHANNEL_MAX_BYTES, fileOutcomeOf, RUN_CHANNEL, } from "./device-files.js";
|
|
2
|
+
/** How long an operation waits for the hand's `hello` before answering `unsupported` (C1). */
|
|
3
|
+
export const HELLO_WAIT_MS = 5000;
|
|
4
|
+
const GRANT_REFUSALS = new Set(["grant_missing", "grant_expired", "workspace_unknown", "capability_missing"]);
|
|
5
|
+
function refusalError(reason) {
|
|
6
|
+
if (GRANT_REFUSALS.has(reason))
|
|
7
|
+
return new DeviceFileError("refused_by_grant", reason);
|
|
8
|
+
if (reason === "epoch_fenced")
|
|
9
|
+
return new DeviceFileError("refused_by_policy", reason);
|
|
10
|
+
if (reason === "hand_closed" || reason.startsWith("scope_unavailable"))
|
|
11
|
+
return new DeviceFileError("hand_unreachable", reason);
|
|
12
|
+
return new DeviceFileError("protocol", reason);
|
|
13
|
+
}
|
|
14
|
+
function valueOf(reply) {
|
|
15
|
+
switch (reply.kind) {
|
|
16
|
+
case "settled": {
|
|
17
|
+
const outcome = fileOutcomeOf(reply.result.details);
|
|
18
|
+
if (outcome === undefined)
|
|
19
|
+
throw new DeviceFileError("protocol", "the hand sent no file outcome");
|
|
20
|
+
if (!outcome.ok)
|
|
21
|
+
throw new DeviceFileError(outcome.code, outcome.message);
|
|
22
|
+
return outcome.value;
|
|
23
|
+
}
|
|
24
|
+
case "terminal": {
|
|
25
|
+
const { reason, uncertain } = reply.terminal;
|
|
26
|
+
throw new DeviceFileError("interrupted", `the operation ended without an outcome (${reason})`, {
|
|
27
|
+
reason,
|
|
28
|
+
uncertain,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
case "refused":
|
|
32
|
+
throw refusalError(reply.reason);
|
|
33
|
+
case "aborted":
|
|
34
|
+
throw new DeviceFileError("aborted", "the operation was aborted");
|
|
35
|
+
case "unreachable":
|
|
36
|
+
throw new DeviceFileError("hand_unreachable", reply.reason);
|
|
37
|
+
case "closed":
|
|
38
|
+
throw new DeviceFileError("hand_unreachable", "the hand link was closed");
|
|
39
|
+
case "epoch_refused":
|
|
40
|
+
throw new DeviceFileError("refused_by_policy", `epoch: ${reply.reason}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A session's {@link DeviceFiles} on a hand (S40): each operation is one `file` message on the scope's lane, after the
|
|
45
|
+
* hand announced the channel in its `hello` (or `unsupported`, sent nowhere). A write over the limit is refused here,
|
|
46
|
+
* before anything is sent; the hand checks the limit again before it reads or writes.
|
|
47
|
+
*/
|
|
48
|
+
export function createRemoteDeviceFiles(link, scope, mintId) {
|
|
49
|
+
const call = async (op, args, signal, channel = FILE_CHANNEL) => {
|
|
50
|
+
const hello = await link.hello(HELLO_WAIT_MS, signal);
|
|
51
|
+
if (signal?.aborted)
|
|
52
|
+
throw new DeviceFileError("aborted", "the operation was aborted");
|
|
53
|
+
if (hello === undefined || !hello.ops.includes(channel))
|
|
54
|
+
throw new DeviceFileError("unsupported", `the hand serves no ${channel} channel`);
|
|
55
|
+
return valueOf(await link.dispatch({ kind: "file", executionId: mintId(), scope, op, args }, signal));
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
read: async (path, options) => {
|
|
59
|
+
const value = await call("read", { path }, options?.signal);
|
|
60
|
+
if (typeof value !== "string")
|
|
61
|
+
throw new DeviceFileError("protocol", "malformed read outcome");
|
|
62
|
+
return decodeBase64(value);
|
|
63
|
+
},
|
|
64
|
+
write: async (path, data, options) => {
|
|
65
|
+
if (data.byteLength > FILE_CHANNEL_MAX_BYTES)
|
|
66
|
+
throw new DeviceFileError("too_large", path);
|
|
67
|
+
const exclusive = options?.exclusive === true;
|
|
68
|
+
await call("write", { path, data: encodeBase64(data), exclusive }, options?.signal);
|
|
69
|
+
},
|
|
70
|
+
list: async (path, options) => {
|
|
71
|
+
const value = await call("list", { path }, options?.signal);
|
|
72
|
+
if (!Array.isArray(value) || !value.every((entry) => typeof entry === "string"))
|
|
73
|
+
throw new DeviceFileError("protocol", "malformed list outcome");
|
|
74
|
+
return value;
|
|
75
|
+
},
|
|
76
|
+
stat: async (path, options) => (await call("stat", { path }, options?.signal)),
|
|
77
|
+
rename: async (from, to, options) => {
|
|
78
|
+
await call("rename", { path: from, to }, options?.signal);
|
|
79
|
+
},
|
|
80
|
+
remove: async (path, options) => {
|
|
81
|
+
await call("remove", { path }, options?.signal);
|
|
82
|
+
},
|
|
83
|
+
mkdir: async (path, options) => {
|
|
84
|
+
await call("mkdir", { path }, options?.signal);
|
|
85
|
+
},
|
|
86
|
+
run: async (request, options) => {
|
|
87
|
+
if (request.stdin !== undefined && request.stdin.byteLength > FILE_CHANNEL_MAX_BYTES)
|
|
88
|
+
throw new DeviceFileError("too_large", "stdin");
|
|
89
|
+
const args = {
|
|
90
|
+
path: request.cwd,
|
|
91
|
+
exe: request.exe,
|
|
92
|
+
argv: [...request.argv],
|
|
93
|
+
env: { ...request.env },
|
|
94
|
+
...(request.stdin === undefined ? {} : { stdin: encodeBase64(request.stdin) }),
|
|
95
|
+
...(request.timeoutMs === undefined ? {} : { timeoutMs: request.timeoutMs }),
|
|
96
|
+
activityLock: request.activityLock === true,
|
|
97
|
+
};
|
|
98
|
+
const value = await call("run", args, options?.signal, RUN_CHANNEL);
|
|
99
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
100
|
+
throw new DeviceFileError("protocol", "malformed run outcome");
|
|
101
|
+
const { code, signal, stdout, stderr } = value;
|
|
102
|
+
if (typeof stdout !== "string" || typeof stderr !== "string")
|
|
103
|
+
throw new DeviceFileError("protocol", "malformed run outcome");
|
|
104
|
+
return {
|
|
105
|
+
code: typeof code === "number" ? code : null,
|
|
106
|
+
signal: typeof signal === "string" ? signal : null,
|
|
107
|
+
stdout: decodeBase64(stdout),
|
|
108
|
+
stderr,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=remote-device-files.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RemoteFloor, RemoteFloorAck, RemoteFloorRefused } from "./remote-protocol.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A session's side of the epoch floor (brain/hand S35): an owner at `epoch` dispatches a scope lane's calls only after
|
|
4
|
+
* the hand acked exactly that epoch on the lane. An ack above it means a newer owner holds the session, and a refusal
|
|
5
|
+
* means this sender may not own it; either way the lane never dispatches again.
|
|
6
|
+
*/
|
|
7
|
+
export interface EpochGate {
|
|
8
|
+
/** Resolves `undefined` once `lane` may dispatch, or the reason it never will. The first ask sends the floor. */
|
|
9
|
+
open(lane: string): Promise<string | undefined>;
|
|
10
|
+
/** Counts only while the lane waits for an answer; a late or duplicate answer changes nothing. */
|
|
11
|
+
answer(lane: string, message: RemoteFloorAck | RemoteFloorRefused): void;
|
|
12
|
+
/**
|
|
13
|
+
* The hand restarted: sends the floor again on every lane not refused, and each of them waits for its new answer
|
|
14
|
+
* before anything dispatches there again, re-sent calls included.
|
|
15
|
+
*/
|
|
16
|
+
resend(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function createEpochGate(epoch: number, send: (lane: string, floor: RemoteFloor) => Promise<void>): EpochGate;
|
|
19
|
+
//# sourceMappingURL=remote-epoch-gate.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function createEpochGate(epoch, send) {
|
|
2
|
+
const lanes = new Map();
|
|
3
|
+
const decide = (state, refusal) => {
|
|
4
|
+
state.verdict = { refusal };
|
|
5
|
+
state.decided.resolve(refusal);
|
|
6
|
+
};
|
|
7
|
+
const ask = (lane, state) => {
|
|
8
|
+
if (state.verdict !== undefined) {
|
|
9
|
+
state.verdict = undefined;
|
|
10
|
+
state.decided = Promise.withResolvers();
|
|
11
|
+
}
|
|
12
|
+
const asked = state.decided;
|
|
13
|
+
send(lane, { kind: "floor", epoch }).catch((error) => {
|
|
14
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
15
|
+
if (state.decided === asked && state.verdict === undefined)
|
|
16
|
+
decide(state, `hand_unreachable: ${reason}`);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
open(lane) {
|
|
21
|
+
const known = lanes.get(lane);
|
|
22
|
+
if (known !== undefined)
|
|
23
|
+
return known.verdict === undefined ? known.decided.promise : Promise.resolve(known.verdict.refusal);
|
|
24
|
+
const state = { decided: Promise.withResolvers(), verdict: undefined };
|
|
25
|
+
lanes.set(lane, state);
|
|
26
|
+
ask(lane, state);
|
|
27
|
+
return state.decided.promise;
|
|
28
|
+
},
|
|
29
|
+
answer(lane, message) {
|
|
30
|
+
const state = lanes.get(lane);
|
|
31
|
+
if (state === undefined || state.verdict !== undefined)
|
|
32
|
+
return;
|
|
33
|
+
if (message.kind === "floor_refused")
|
|
34
|
+
return decide(state, message.reason);
|
|
35
|
+
if (message.floor === epoch)
|
|
36
|
+
return decide(state, undefined);
|
|
37
|
+
decide(state, message.floor > epoch ? "epoch_superseded" : "epoch_floor_mismatch");
|
|
38
|
+
},
|
|
39
|
+
resend() {
|
|
40
|
+
for (const [lane, state] of lanes)
|
|
41
|
+
if (state.verdict?.refusal === undefined)
|
|
42
|
+
ask(lane, state);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=remote-epoch-gate.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AdmissionLine } from "../durable/store-admission.ts";
|
|
2
|
+
import type { DurableStore } from "../durable/store.ts";
|
|
3
|
+
import type { EpochRefusal, RemoteHandMessage } from "./remote-protocol.ts";
|
|
4
|
+
/** A raise moves a scope's floor by at most one epoch, counted from 0 (relay design 4.4, SP6 `EPOCH_FLOOR_MAX_STEP`). */
|
|
5
|
+
export declare const EPOCH_FLOOR_MAX_STEP = 1;
|
|
6
|
+
/** The hand-store documents holding each scope's floor: this prefix, then the scope ID. */
|
|
7
|
+
export declare const EPOCH_FLOOR_PREFIX = "hand.epoch-floor:";
|
|
8
|
+
/** The sender a self link (fused, split-local) presents to the fence; a peer link presents its authenticated peer. */
|
|
9
|
+
export declare const HAND_SELF_SENDER = "self";
|
|
10
|
+
export type FloorRaise = {
|
|
11
|
+
readonly kind: "acked";
|
|
12
|
+
readonly floor: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "refused";
|
|
15
|
+
readonly reason: Exclude<EpochRefusal, "epoch_unsupported">;
|
|
16
|
+
};
|
|
17
|
+
export interface HandEpochFence {
|
|
18
|
+
/** Settles once the floors persisted by an earlier process are in force; nothing is admitted before. */
|
|
19
|
+
readonly ready: Promise<void>;
|
|
20
|
+
/** Raises `scope`'s floor to `epoch` for `sender`, or says why not; a raise below the floor answers the floor. */
|
|
21
|
+
raise(scope: string, epoch: number, sender: string): Promise<FloorRaise>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether a message from `sender` at `epoch` (none: from before epochs) may act on `scope`: anything above the floor,
|
|
24
|
+
* or the floor's own owner at the floor's epoch. Synchronous, so it can run inside a ledger step's admission slot.
|
|
25
|
+
*/
|
|
26
|
+
admits(scope: string, epoch: number | undefined, sender: string): boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface HandEpochFenceOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The brain principal that owns each scope's session now: the embedder's placement record, which changes when the
|
|
31
|
+
* session moves. Only that owner raises the scope's floor; any other sender is refused, whatever grant it holds.
|
|
32
|
+
*/
|
|
33
|
+
readonly ownerOf: (scope: string) => string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Where floors persist: the hand's store, under its owner epoch, on the execution ledger's admission line, so a floor
|
|
36
|
+
* and every ledger step are ordered and a restarted hand keeps the floors it acked. Without it, floors live as long
|
|
37
|
+
* as the process.
|
|
38
|
+
*/
|
|
39
|
+
readonly durable?: {
|
|
40
|
+
readonly store: DurableStore;
|
|
41
|
+
readonly epoch: number;
|
|
42
|
+
readonly admission: AdmissionLine;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A hand's epoch floors, one per execution scope (brain/hand S35): the hand side of SP6's `EpochFence`. The floor
|
|
47
|
+
* never lowers and remembers its owner, so after a move the old owner's delayed invoke, abort or ack is refused and a
|
|
48
|
+
* rival at the new owner's epoch is fenced.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createHandEpochFence(options: HandEpochFenceOptions): HandEpochFence;
|
|
51
|
+
/** The hand's answer to a floor on `scope`: a hand with no fence refuses it, so its session never dispatches unfenced. */
|
|
52
|
+
export declare function answerFloor(fence: HandEpochFence | undefined, scope: string, epoch: number, sender: string): Promise<RemoteHandMessage>;
|
|
53
|
+
//# sourceMappingURL=remote-epoch.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** A raise moves a scope's floor by at most one epoch, counted from 0 (relay design 4.4, SP6 `EPOCH_FLOOR_MAX_STEP`). */
|
|
2
|
+
export const EPOCH_FLOOR_MAX_STEP = 1;
|
|
3
|
+
/** The hand-store documents holding each scope's floor: this prefix, then the scope ID. */
|
|
4
|
+
export const EPOCH_FLOOR_PREFIX = "hand.epoch-floor:";
|
|
5
|
+
/** The sender a self link (fused, split-local) presents to the fence; a peer link presents its authenticated peer. */
|
|
6
|
+
export const HAND_SELF_SENDER = "self";
|
|
7
|
+
function decodeFloor(data) {
|
|
8
|
+
if (typeof data === "object" && data !== null && !Array.isArray(data) && "epoch" in data && "owner" in data) {
|
|
9
|
+
const { epoch, owner } = data;
|
|
10
|
+
if (typeof epoch === "number" && Number.isSafeInteger(epoch) && epoch >= 1 && typeof owner === "string")
|
|
11
|
+
return { epoch, owner };
|
|
12
|
+
}
|
|
13
|
+
throw new Error("A stored epoch floor is malformed");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A hand's epoch floors, one per execution scope (brain/hand S35): the hand side of SP6's `EpochFence`. The floor
|
|
17
|
+
* never lowers and remembers its owner, so after a move the old owner's delayed invoke, abort or ack is refused and a
|
|
18
|
+
* rival at the new owner's epoch is fenced.
|
|
19
|
+
*/
|
|
20
|
+
export function createHandEpochFence(options) {
|
|
21
|
+
const { durable, ownerOf } = options;
|
|
22
|
+
const floors = new Map();
|
|
23
|
+
const ready = (async () => {
|
|
24
|
+
if (durable === undefined)
|
|
25
|
+
return;
|
|
26
|
+
for (const document of await durable.store.scanDocuments(EPOCH_FLOOR_PREFIX))
|
|
27
|
+
floors.set(document.key.slice(EPOCH_FLOOR_PREFIX.length), decodeFloor(document.data));
|
|
28
|
+
})();
|
|
29
|
+
const raiseNow = async (scope, epoch, sender) => {
|
|
30
|
+
if (ownerOf(scope) !== sender)
|
|
31
|
+
return { kind: "refused", reason: "peer_unauthorized" };
|
|
32
|
+
const current = floors.get(scope);
|
|
33
|
+
const floor = current?.epoch ?? 0;
|
|
34
|
+
if (epoch < floor)
|
|
35
|
+
return { kind: "acked", floor };
|
|
36
|
+
if (current !== undefined && epoch === floor)
|
|
37
|
+
return current.owner === sender ? { kind: "acked", floor } : { kind: "refused", reason: "epoch_fenced" };
|
|
38
|
+
if (epoch - floor > EPOCH_FLOOR_MAX_STEP)
|
|
39
|
+
return { kind: "refused", reason: "epoch_step_exceeded" };
|
|
40
|
+
const next = { epoch, owner: sender };
|
|
41
|
+
if (durable === undefined)
|
|
42
|
+
floors.set(scope, next);
|
|
43
|
+
else {
|
|
44
|
+
const write = { op: "put", key: `${EPOCH_FLOOR_PREFIX}${scope}`, data: { ...next } };
|
|
45
|
+
await durable.store.commit(durable.epoch, [write], () => floors.set(scope, next));
|
|
46
|
+
}
|
|
47
|
+
return { kind: "acked", floor: epoch };
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
ready,
|
|
51
|
+
async raise(scope, epoch, sender) {
|
|
52
|
+
await ready;
|
|
53
|
+
const run = () => raiseNow(scope, epoch, sender);
|
|
54
|
+
return durable === undefined ? run() : durable.admission.admit(run);
|
|
55
|
+
},
|
|
56
|
+
admits(scope, epoch, sender) {
|
|
57
|
+
const floor = floors.get(scope);
|
|
58
|
+
if (floor === undefined)
|
|
59
|
+
return true;
|
|
60
|
+
const at = epoch ?? 0;
|
|
61
|
+
return at > floor.epoch || (at === floor.epoch && floor.owner === sender);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** The hand's answer to a floor on `scope`: a hand with no fence refuses it, so its session never dispatches unfenced. */
|
|
66
|
+
export async function answerFloor(fence, scope, epoch, sender) {
|
|
67
|
+
if (fence === undefined)
|
|
68
|
+
return { kind: "floor_refused", reason: "epoch_unsupported" };
|
|
69
|
+
const raised = await fence.raise(scope, epoch, sender);
|
|
70
|
+
return raised.kind === "acked"
|
|
71
|
+
? { kind: "floor_ack", floor: raised.floor }
|
|
72
|
+
: { kind: "floor_refused", reason: raised.reason };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=remote-epoch.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Transport } from "../transport/transport.ts";
|
|
2
2
|
import type { AgentToolResult } from "../types.ts";
|
|
3
|
+
import { type NestedRequest } from "./plane.ts";
|
|
3
4
|
import { type HandAuthority } from "./grant-verify.ts";
|
|
5
|
+
import { type HandEpochFence } from "./remote-epoch.ts";
|
|
4
6
|
import type { HandLedger } from "./remote-hand-ledger.ts";
|
|
5
7
|
import type { ExecutionScope } from "./tool-host.ts";
|
|
6
8
|
/** One call as a hand runs it: the raw name and arguments, never anything about the session that sent it. */
|
|
@@ -9,6 +11,8 @@ export interface HandCall {
|
|
|
9
11
|
readonly name: string;
|
|
10
12
|
readonly arguments: unknown;
|
|
11
13
|
readonly signal: AbortSignal;
|
|
14
|
+
/** Asks the brain that owns this call (a model-backed tool's completion, S31); fails once the call has ended. */
|
|
15
|
+
readonly nested: NestedRequest;
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
14
18
|
* What a hand runs a scope's calls on. `run` owns the whole call: name resolution, argument preparation and
|
|
@@ -18,6 +22,11 @@ export interface HandScope {
|
|
|
18
22
|
run(call: HandCall): Promise<AgentToolResult<unknown>>;
|
|
19
23
|
/** A tool that must not overlap other calls of its scope (`executionMode: "sequential"`). */
|
|
20
24
|
isSequential(name: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Runs one device file operation (S40) after its grant was checked: the scope's `tool_call` handlers, filesystem
|
|
27
|
+
* policy and the operation itself, the outcome in `details.file`. Absent: the scope serves no file channel.
|
|
28
|
+
*/
|
|
29
|
+
file?(op: string, args: unknown, signal: AbortSignal, nested: NestedRequest): Promise<AgentToolResult<unknown>>;
|
|
21
30
|
dispose(): Promise<void>;
|
|
22
31
|
}
|
|
23
32
|
export type OpenHandScope = (scope: ExecutionScope) => Promise<HandScope>;
|
|
@@ -37,8 +46,16 @@ export interface RemoteExecutorOptions {
|
|
|
37
46
|
* recorded outcome. Without it, the hand remembers execution IDs only while it lives.
|
|
38
47
|
*/
|
|
39
48
|
readonly ledger?: HandLedger;
|
|
49
|
+
/**
|
|
50
|
+
* The hand's epoch floors (S35), shared by every link's executor in this process. With it, a scope's owner raises the
|
|
51
|
+
* floor before it dispatches, and an invoke, abort or ack below the floor is refused or ignored. Without it, a floor
|
|
52
|
+
* is refused `epoch_unsupported`, so a session that moves never dispatches to this hand.
|
|
53
|
+
*/
|
|
54
|
+
readonly fence?: HandEpochFence;
|
|
40
55
|
/** This hand process's identity in its `hello`; a fresh one per start by default. */
|
|
41
56
|
readonly instance?: string;
|
|
57
|
+
/** Announce the device file channel (S40) in `hello`; its scopes then serve `HandScope.file`. */
|
|
58
|
+
readonly fileChannel?: boolean;
|
|
42
59
|
/**
|
|
43
60
|
* A call the hand could not record or answer (its durable record failed): the call gets no reply from this process,
|
|
44
61
|
* as from a hand that died, and a restarted hand answers it from the record. A failed restart recovery is reported
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { FILE_CHANNEL, RUN_CHANNEL } from "./device-files.js";
|
|
2
|
+
import { createPlaneClient, decodePlaneMessage } from "./plane.js";
|
|
3
|
+
import { fileCall, fileRefusal, fileStopped } from "./remote-file-call.js";
|
|
1
4
|
import { decodeRemoteMessage, encodeRemoteMessage, HAND_CONTROL_LANE, toRemoteToolResult, } from "./remote-protocol.js";
|
|
2
5
|
import { authorize } from "./grant-verify.js";
|
|
6
|
+
import { answerFloor, HAND_SELF_SENDER } from "./remote-epoch.js";
|
|
3
7
|
/**
|
|
4
8
|
* The hand's side of remote tool execution (brain/hand split, S27a). Each scope keeps its own state, opened lazily and
|
|
5
9
|
* bound to the root it was opened with: a later call naming the same scope with another root is refused, as is any
|
|
@@ -7,11 +11,14 @@ import { authorize } from "./grant-verify.js";
|
|
|
7
11
|
* passed on: the hand keys on the scope and does not know the session (R16).
|
|
8
12
|
*/
|
|
9
13
|
export function createRemoteExecutor(options) {
|
|
10
|
-
const { transport, openScope, ledger, authority } = options;
|
|
14
|
+
const { transport, openScope, ledger, authority, fence } = options;
|
|
15
|
+
const sender = authority.kind === "peer" ? authority.peer : HAND_SELF_SENDER;
|
|
16
|
+
const admits = (lane, epoch) => fence === undefined || fence.admits(lane, epoch, sender);
|
|
11
17
|
const scopes = new Map();
|
|
12
18
|
const accepted = [];
|
|
13
19
|
const seen = new Set();
|
|
14
20
|
const running = new Map();
|
|
21
|
+
const planes = createPlaneClient({ transport });
|
|
15
22
|
let closed = false;
|
|
16
23
|
const stopWatching = authority.kind === "peer"
|
|
17
24
|
? authority.verifier.onReplace(() => {
|
|
@@ -34,7 +41,7 @@ export function createRemoteExecutor(options) {
|
|
|
34
41
|
scopes.set(scope.id, state);
|
|
35
42
|
return state;
|
|
36
43
|
};
|
|
37
|
-
const invoke = async (lane, call) => {
|
|
44
|
+
const invoke = async (lane, call, file) => {
|
|
38
45
|
if (closed)
|
|
39
46
|
return refuse(lane, call.executionId, "hand_closed");
|
|
40
47
|
if (lane !== call.scope.id)
|
|
@@ -42,6 +49,8 @@ export function createRemoteExecutor(options) {
|
|
|
42
49
|
const verdict = authorize(authority, call.scope.root);
|
|
43
50
|
if (!verdict.ok)
|
|
44
51
|
return refuse(lane, call.executionId, verdict.reason);
|
|
52
|
+
if (!admits(lane, call.epoch))
|
|
53
|
+
return refuse(lane, call.executionId, "epoch_fenced");
|
|
45
54
|
if (ledger === undefined && seen.has(call.executionId))
|
|
46
55
|
return refuse(lane, call.executionId, "duplicate_execution");
|
|
47
56
|
seen.add(call.executionId);
|
|
@@ -57,7 +66,7 @@ export function createRemoteExecutor(options) {
|
|
|
57
66
|
return refuse(lane, call.executionId, `scope_unavailable: ${reason}`);
|
|
58
67
|
}
|
|
59
68
|
if (ledger !== undefined) {
|
|
60
|
-
const admission = await ledger.admit(call);
|
|
69
|
+
const admission = await ledger.admit(call, () => admits(lane, call.epoch));
|
|
61
70
|
if (admission.kind === "reply")
|
|
62
71
|
return reply(lane, admission.message);
|
|
63
72
|
if (admission.kind === "in_flight")
|
|
@@ -66,7 +75,7 @@ export function createRemoteExecutor(options) {
|
|
|
66
75
|
accepted.push(call.executionId);
|
|
67
76
|
const controller = new AbortController();
|
|
68
77
|
running.set(call.executionId, { controller, root: verdict.root });
|
|
69
|
-
const sequential = scope.isSequential(call.name);
|
|
78
|
+
const sequential = file !== undefined || scope.isSequential(call.name);
|
|
70
79
|
const dependencies = sequential
|
|
71
80
|
? [...(state.lastSequential ? [state.lastSequential] : []), ...state.wave]
|
|
72
81
|
: state.lastSequential
|
|
@@ -74,25 +83,52 @@ export function createRemoteExecutor(options) {
|
|
|
74
83
|
: [];
|
|
75
84
|
const done = (async () => {
|
|
76
85
|
await Promise.allSettled(dependencies);
|
|
86
|
+
// Without a ledger this is the call's dispatch point: a floor raised while its scope opened or it waited on
|
|
87
|
+
// earlier calls fences it here. With a ledger, the guarded `dispatch` step already decided it atomically.
|
|
88
|
+
if (ledger === undefined && !admits(lane, call.epoch)) {
|
|
89
|
+
running.delete(call.executionId);
|
|
90
|
+
return refuse(lane, call.executionId, "epoch_fenced");
|
|
91
|
+
}
|
|
77
92
|
let result;
|
|
78
93
|
try {
|
|
79
94
|
// The grant must still hold when the call starts: a snapshot installed while it waited (scope opening,
|
|
80
95
|
// durable admission, earlier calls of its scope) may have revoked it, and then the tool never runs.
|
|
81
96
|
if (controller.signal.aborted || !authorize(authority, call.scope.root).ok)
|
|
82
97
|
throw new Error("The call's grant was revoked before it ran");
|
|
83
|
-
result =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
result =
|
|
99
|
+
file === undefined
|
|
100
|
+
? await scope.run({
|
|
101
|
+
toolCallId: call.toolCallId,
|
|
102
|
+
name: call.name,
|
|
103
|
+
arguments: call.arguments,
|
|
104
|
+
signal: controller.signal,
|
|
105
|
+
nested: planes.requestFor(call.executionId, lane, controller.signal),
|
|
106
|
+
})
|
|
107
|
+
: scope.file === undefined
|
|
108
|
+
? fileRefusal("unsupported", "this hand serves no file channel")
|
|
109
|
+
: await scope.file(file.op, call.arguments, controller.signal,
|
|
110
|
+
// Only planes the brain lets file operations host answer it (a two-sided extension's forwarded tool events).
|
|
111
|
+
planes.requestFor(call.executionId, lane, controller.signal));
|
|
112
|
+
// A file operation that ended aborted ships no payload: a revoked grant is a refusal (R7), never data.
|
|
113
|
+
if (file !== undefined && controller.signal.aborted)
|
|
114
|
+
result = fileStopped(authorize(authority, call.scope.root).ok);
|
|
89
115
|
}
|
|
90
116
|
catch (error) {
|
|
91
|
-
|
|
92
|
-
|
|
117
|
+
if (file !== undefined) {
|
|
118
|
+
const granted = authorize(authority, call.scope.root).ok;
|
|
119
|
+
result =
|
|
120
|
+
controller.signal.aborted || !granted
|
|
121
|
+
? fileStopped(granted)
|
|
122
|
+
: fileRefusal("io", error instanceof Error ? error.message : String(error));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
126
|
+
result = { content: [{ type: "text", text }], details: {}, isError: true };
|
|
127
|
+
}
|
|
93
128
|
}
|
|
94
129
|
finally {
|
|
95
130
|
running.delete(call.executionId);
|
|
131
|
+
planes.parentEnded(call.executionId);
|
|
96
132
|
}
|
|
97
133
|
const settled = toRemoteToolResult(result);
|
|
98
134
|
reply(lane, ledger === undefined
|
|
@@ -107,12 +143,19 @@ export function createRemoteExecutor(options) {
|
|
|
107
143
|
else
|
|
108
144
|
state.wave.push(done);
|
|
109
145
|
};
|
|
146
|
+
// The connect hook: one `hello` per hand start, after recovery. The reliable transport re-delivers it across carrier
|
|
147
|
+
// re-attaches, so only a new hand process announces a new identity.
|
|
110
148
|
const ready = (async () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
reply(HAND_CONTROL_LANE, {
|
|
149
|
+
await fence?.ready;
|
|
150
|
+
if (ledger !== undefined)
|
|
151
|
+
for (const { lane, message } of await ledger.recover())
|
|
152
|
+
reply(lane, message);
|
|
153
|
+
reply(HAND_CONTROL_LANE, {
|
|
154
|
+
kind: "hello",
|
|
155
|
+
instance: options.instance ?? crypto.randomUUID(),
|
|
156
|
+
durable: ledger !== undefined,
|
|
157
|
+
ops: options.fileChannel === true ? [FILE_CHANNEL, RUN_CHANNEL] : [],
|
|
158
|
+
});
|
|
116
159
|
})();
|
|
117
160
|
ready.catch((error) => options.onFault(error));
|
|
118
161
|
transport.onFrame(async (frame) => {
|
|
@@ -122,6 +165,9 @@ export function createRemoteExecutor(options) {
|
|
|
122
165
|
catch {
|
|
123
166
|
return;
|
|
124
167
|
}
|
|
168
|
+
const nested = decodePlaneMessage(frame.payload);
|
|
169
|
+
if (nested !== undefined)
|
|
170
|
+
return planes.receive(nested);
|
|
125
171
|
let message;
|
|
126
172
|
try {
|
|
127
173
|
message = decodeRemoteMessage(frame.payload);
|
|
@@ -132,10 +178,16 @@ export function createRemoteExecutor(options) {
|
|
|
132
178
|
try {
|
|
133
179
|
if (message.kind === "invoke")
|
|
134
180
|
await invoke(frame.lane, message);
|
|
181
|
+
else if (message.kind === "floor")
|
|
182
|
+
reply(frame.lane, await answerFloor(fence, frame.lane, message.epoch, sender));
|
|
183
|
+
else if ((message.kind === "abort" || message.kind === "ack") && !admits(frame.lane, message.epoch))
|
|
184
|
+
return;
|
|
185
|
+
else if (message.kind === "file")
|
|
186
|
+
await invoke(frame.lane, fileCall(message), { op: message.op });
|
|
135
187
|
else if (message.kind === "abort")
|
|
136
188
|
running.get(message.executionId)?.controller.abort();
|
|
137
189
|
else if (message.kind === "ack")
|
|
138
|
-
await ledger?.ack(message.executionId);
|
|
190
|
+
await ledger?.ack(message.executionId, () => admits(frame.lane, message.epoch));
|
|
139
191
|
}
|
|
140
192
|
catch (error) {
|
|
141
193
|
options.onFault(error);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentToolResult } from "../types.ts";
|
|
2
|
+
import type { DeviceFileErrorCode, DeviceFileOutcome } from "./device-files.ts";
|
|
3
|
+
import type { RemoteFile, RemoteInvoke } from "./remote-protocol.ts";
|
|
4
|
+
/**
|
|
5
|
+
* A device file operation as the hand's admission sees it (S40): the same record an invoke has, so the operation goes
|
|
6
|
+
* through the same lane, grant, scope binding, execution ID and durable-ledger checks. The name is never a tool's: the
|
|
7
|
+
* hand chose the file path from the message kind, and an invoke carrying this name is an unknown tool.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fileCall(message: RemoteFile): RemoteInvoke;
|
|
10
|
+
export declare function fileResult(outcome: DeviceFileOutcome): AgentToolResult<unknown>;
|
|
11
|
+
export declare function fileRefusal(code: DeviceFileErrorCode, message: string): AgentToolResult<unknown>;
|
|
12
|
+
/** An operation that ended aborted: a refusal when its grant no longer holds, never any data. */
|
|
13
|
+
export declare function fileStopped(granted: boolean): AgentToolResult<unknown>;
|
|
14
|
+
//# sourceMappingURL=remote-file-call.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A device file operation as the hand's admission sees it (S40): the same record an invoke has, so the operation goes
|
|
3
|
+
* through the same lane, grant, scope binding, execution ID and durable-ledger checks. The name is never a tool's: the
|
|
4
|
+
* hand chose the file path from the message kind, and an invoke carrying this name is an unknown tool.
|
|
5
|
+
*/
|
|
6
|
+
export function fileCall(message) {
|
|
7
|
+
return {
|
|
8
|
+
kind: "invoke",
|
|
9
|
+
executionId: message.executionId,
|
|
10
|
+
batchId: message.executionId,
|
|
11
|
+
index: 0,
|
|
12
|
+
scope: message.scope,
|
|
13
|
+
toolCallId: message.executionId,
|
|
14
|
+
name: `file.${message.op}`,
|
|
15
|
+
arguments: message.args,
|
|
16
|
+
...(message.epoch === undefined ? {} : { epoch: message.epoch }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function fileResult(outcome) {
|
|
20
|
+
return { content: [], details: { file: outcome }, isError: !outcome.ok };
|
|
21
|
+
}
|
|
22
|
+
export function fileRefusal(code, message) {
|
|
23
|
+
return fileResult({ ok: false, code, message });
|
|
24
|
+
}
|
|
25
|
+
/** An operation that ended aborted: a refusal when its grant no longer holds, never any data. */
|
|
26
|
+
export function fileStopped(granted) {
|
|
27
|
+
return granted
|
|
28
|
+
? fileRefusal("aborted", "the operation was aborted")
|
|
29
|
+
: fileRefusal("refused_by_grant", "the grant was revoked");
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=remote-file-call.js.map
|