@code-yeongyu/senpi-agent-core 2026.11.3-3 → 2026.11.4-2
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 +7 -47
- package/dist/conformance/index.d.ts +23 -0
- package/dist/conformance/index.js +17 -0
- package/dist/conformance/loop-core-manifest.d.ts +1 -1
- package/dist/conformance/loop-core-manifest.js +1 -0
- package/dist/conformance/registry.js +9 -1
- package/dist/execution/canonical-json.d.ts +3 -0
- package/dist/execution/canonical-json.js +12 -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-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 +112 -0
- package/dist/execution/device-files.d.ts +80 -0
- package/dist/execution/device-files.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.d.ts +72 -0
- package/dist/execution/plane.js +172 -0
- package/dist/execution/remote-device-files.d.ts +12 -0
- package/dist/execution/remote-device-files.js +84 -0
- package/dist/execution/remote-executor.d.ts +10 -0
- package/dist/execution/remote-executor.js +49 -15
- package/dist/execution/remote-file-call.d.ts +14 -0
- package/dist/execution/remote-file-call.js +30 -0
- package/dist/execution/remote-link.d.ts +36 -0
- package/dist/execution/remote-link.js +117 -0
- package/dist/execution/remote-protocol.d.ts +21 -4
- package/dist/execution/remote-protocol.js +18 -2
- package/dist/execution/remote-tool-host.d.ts +11 -3
- package/dist/execution/remote-tool-host.js +23 -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/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-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 +10 -2
- 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/index.d.ts +13 -2
- package/dist/index.js +11 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.js +1 -0
- package/dist/transport/testing/multi-cases.js +8 -8
- package/package.json +3 -3
package/dist/agent-loop.js
CHANGED
|
@@ -10,6 +10,7 @@ import { getDefaultStreamFn, withEmptyAssistantRecovery } from "./stream-fn.js";
|
|
|
10
10
|
import { createTransportLiveness, StreamKeepAliveTimeoutError } from "./stream-keepalive.js";
|
|
11
11
|
import { prepareAgentToolCallArguments } from "./tool-arguments.js";
|
|
12
12
|
import { resolveCallTool, withToolNameCorrection } from "./tool-name-alias.js";
|
|
13
|
+
import { createErrorToolResult, createToolResultMessage, emitToolExecutionEnd, emitToolExecutionUpdate, emitToolResultMessage, shouldTerminateToolBatch, } from "./execution/tool-outcome-events.js";
|
|
13
14
|
/**
|
|
14
15
|
* Start an agent loop with a new prompt message.
|
|
15
16
|
* The prompt is added to the context and events are emitted for it.
|
|
@@ -946,7 +947,12 @@ async function executeToolCalls(currentContext, assistantMessage, config, signal
|
|
|
946
947
|
scope: config.executionScope ?? { id: crypto.randomUUID(), root: "" },
|
|
947
948
|
calls: toolCalls,
|
|
948
949
|
mode: config.toolExecution ?? "parallel",
|
|
949
|
-
}, {
|
|
950
|
+
}, {
|
|
951
|
+
signal,
|
|
952
|
+
emit,
|
|
953
|
+
recordWitness: config.onExecutionPipeline,
|
|
954
|
+
local: { context: currentContext, assistantMessage },
|
|
955
|
+
});
|
|
950
956
|
}
|
|
951
957
|
async function executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit) {
|
|
952
958
|
const finalizedCalls = [];
|
|
@@ -1070,9 +1076,6 @@ async function runPreparedToolCall(currentContext, assistantMessage, preparation
|
|
|
1070
1076
|
function isSequentialToolCall(currentContext, toolCall) {
|
|
1071
1077
|
return currentContext.tools?.find((tool) => tool.name === toolCall.name)?.executionMode === "sequential";
|
|
1072
1078
|
}
|
|
1073
|
-
function shouldTerminateToolBatch(finalizedCalls) {
|
|
1074
|
-
return finalizedCalls.length > 0 && finalizedCalls.every((finalized) => finalized.result.terminate === true);
|
|
1075
|
-
}
|
|
1076
1079
|
export { prepareAgentToolCallArguments };
|
|
1077
1080
|
export function prepareAgentToolCall(tool, toolCall) {
|
|
1078
1081
|
const preparedToolCall = prepareAgentToolCallArguments(tool, toolCall);
|
|
@@ -1181,15 +1184,6 @@ function abortReleasePromise(signal) {
|
|
|
1181
1184
|
signal.addEventListener("abort", () => resolve(ABORTED), { once: true });
|
|
1182
1185
|
});
|
|
1183
1186
|
}
|
|
1184
|
-
function emitToolExecutionUpdate(toolCall, emit) {
|
|
1185
|
-
return (partialResult) => emit({
|
|
1186
|
-
type: "tool_execution_update",
|
|
1187
|
-
toolCallId: toolCall.id,
|
|
1188
|
-
toolName: toolCall.name,
|
|
1189
|
-
args: toolCall.arguments,
|
|
1190
|
-
partialResult,
|
|
1191
|
-
});
|
|
1192
|
-
}
|
|
1193
1187
|
/**
|
|
1194
1188
|
* Run one tool call through the same steps as a model-issued call: argument preparation, schema
|
|
1195
1189
|
* validation, `beforeToolCall`, execution, and `afterToolCall`. Emits no events and adds no
|
|
@@ -1286,38 +1280,4 @@ async function finalizeExecutedToolCall(currentContext, assistantMessage, prepar
|
|
|
1286
1280
|
isError,
|
|
1287
1281
|
};
|
|
1288
1282
|
}
|
|
1289
|
-
function createErrorToolResult(message) {
|
|
1290
|
-
return {
|
|
1291
|
-
content: [{ type: "text", text: message }],
|
|
1292
|
-
details: {},
|
|
1293
|
-
};
|
|
1294
|
-
}
|
|
1295
|
-
async function emitToolExecutionEnd(finalized, emit) {
|
|
1296
|
-
await emit({
|
|
1297
|
-
type: "tool_execution_end",
|
|
1298
|
-
toolCallId: finalized.toolCall.id,
|
|
1299
|
-
toolName: finalized.toolCall.name,
|
|
1300
|
-
result: finalized.result,
|
|
1301
|
-
isError: finalized.isError,
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
function createToolResultMessage(finalized) {
|
|
1305
|
-
return {
|
|
1306
|
-
role: "toolResult",
|
|
1307
|
-
toolCallId: finalized.toolCall.id,
|
|
1308
|
-
toolName: finalized.toolCall.name,
|
|
1309
|
-
// Untyped tools (JS extensions) can return results without content; normalize
|
|
1310
|
-
// so the null never enters session history or provider payloads.
|
|
1311
|
-
content: finalized.result.content ?? [],
|
|
1312
|
-
details: finalized.result.details,
|
|
1313
|
-
usage: finalized.result.usage,
|
|
1314
|
-
...(finalized.result.addedToolNames?.length ? { addedToolNames: finalized.result.addedToolNames } : {}),
|
|
1315
|
-
isError: finalized.isError,
|
|
1316
|
-
timestamp: Date.now(),
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
async function emitToolResultMessage(toolResultMessage, emit) {
|
|
1320
|
-
await emit({ type: "message_start", message: toolResultMessage });
|
|
1321
|
-
await emit({ type: "message_end", message: toolResultMessage });
|
|
1322
|
-
}
|
|
1323
1283
|
//# sourceMappingURL=agent-loop.js.map
|
|
@@ -55,6 +55,29 @@ export { BatchManifestConflictError, createBatchCoordinator } from "../execution
|
|
|
55
55
|
export { interruptedReplayText } from "../execution/coordinator-plan.ts";
|
|
56
56
|
export type { BatchCallPlan, BatchDecision, BatchExecutor, BatchManifest, BatchPlan, BatchRecord, BatchResult, CallOutcome, ExecutionRef, ManifestCall, PrepareReply, PrepareRequest, SettleReply, } from "../execution/coordinator-types.ts";
|
|
57
57
|
export { BATCH_CASES } from "../execution/testing/batch-cases.ts";
|
|
58
|
+
export type { SequentialCoordinator } from "../execution/coordinator-sequential.ts";
|
|
59
|
+
export { createSequentialCoordinator } from "../execution/coordinator-sequential.ts";
|
|
60
|
+
export { MULTI_SEQ_CASES } from "../execution/testing/multi-seq-cases.ts";
|
|
61
|
+
export { SEQ_CASES } from "../execution/testing/seq-cases.ts";
|
|
62
|
+
export { CONSENT_CASES } from "../execution/testing/consent-cases.ts";
|
|
63
|
+
export type { NestedAdmissionControl, NestedAdmissionOptions } from "../execution/nested.ts";
|
|
64
|
+
export { createNestedAdmission } from "../execution/nested.ts";
|
|
65
|
+
export { NEST_CASES } from "../execution/testing/nest-cases.ts";
|
|
66
|
+
export { CANCEL_CASES } from "../execution/testing/cancel-cases.ts";
|
|
67
|
+
export { KILL_NEST_CASES } from "../execution/testing/kill-nest.ts";
|
|
68
|
+
export type { WakeInbox, WakeInboxOptions } from "../execution/wake-inbox.ts";
|
|
69
|
+
export { createWakeInbox } from "../execution/wake-inbox.ts";
|
|
70
|
+
export type { WakeOutbox, WakeOutboxOptions } from "../execution/wake-outbox.ts";
|
|
71
|
+
export { createWakeOutbox } from "../execution/wake-outbox.ts";
|
|
72
|
+
export type { WakeEvent, WakeReceipt } from "../execution/wake-types.ts";
|
|
73
|
+
export { WAKE_RETENTION_MS } from "../execution/wake-types.ts";
|
|
74
|
+
export { WAKE_EXEC_CASES } from "../execution/testing/wake-exec-cases.ts";
|
|
75
|
+
export { KILL_WAKEX_CASES } from "../execution/testing/kill-wakex.ts";
|
|
76
|
+
export type { ScopeBinding, ScopeLifecycle, ScopeLifecycleOptions, ScopeRecord } from "../execution/scope-lifecycle.ts";
|
|
77
|
+
export { createScopeLifecycle } from "../execution/scope-lifecycle.ts";
|
|
78
|
+
export { LIFECYCLE_CASES } from "../execution/testing/lifecycle-cases.ts";
|
|
79
|
+
export { SCOPE_CASES } from "../execution/testing/scope-cases.ts";
|
|
80
|
+
export { MULTI_LIFECYCLE_CASES } from "../execution/testing/multi-lifecycle-cases.ts";
|
|
58
81
|
export type { BatchCaseAdapters, BatchExecutorConformanceAdapter, ExecutorOpenOptions, PausePoint, } from "../execution/testing/batch-executor.ts";
|
|
59
82
|
export { referenceBatchExecutor } from "../execution/testing/batch-executor.ts";
|
|
60
83
|
export type { KillBatchDeclaration } from "../execution/testing/kill-batch.ts";
|
|
@@ -29,6 +29,23 @@ export { MULTI_HAND_CASES } from "../execution/testing/multi-hand-cases.js";
|
|
|
29
29
|
export { BatchManifestConflictError, createBatchCoordinator } from "../execution/coordinator.js";
|
|
30
30
|
export { interruptedReplayText } from "../execution/coordinator-plan.js";
|
|
31
31
|
export { BATCH_CASES } from "../execution/testing/batch-cases.js";
|
|
32
|
+
export { createSequentialCoordinator } from "../execution/coordinator-sequential.js";
|
|
33
|
+
export { MULTI_SEQ_CASES } from "../execution/testing/multi-seq-cases.js";
|
|
34
|
+
export { SEQ_CASES } from "../execution/testing/seq-cases.js";
|
|
35
|
+
export { CONSENT_CASES } from "../execution/testing/consent-cases.js";
|
|
36
|
+
export { createNestedAdmission } from "../execution/nested.js";
|
|
37
|
+
export { NEST_CASES } from "../execution/testing/nest-cases.js";
|
|
38
|
+
export { CANCEL_CASES } from "../execution/testing/cancel-cases.js";
|
|
39
|
+
export { KILL_NEST_CASES } from "../execution/testing/kill-nest.js";
|
|
40
|
+
export { createWakeInbox } from "../execution/wake-inbox.js";
|
|
41
|
+
export { createWakeOutbox } from "../execution/wake-outbox.js";
|
|
42
|
+
export { WAKE_RETENTION_MS } from "../execution/wake-types.js";
|
|
43
|
+
export { WAKE_EXEC_CASES } from "../execution/testing/wake-exec-cases.js";
|
|
44
|
+
export { KILL_WAKEX_CASES } from "../execution/testing/kill-wakex.js";
|
|
45
|
+
export { createScopeLifecycle } from "../execution/scope-lifecycle.js";
|
|
46
|
+
export { LIFECYCLE_CASES } from "../execution/testing/lifecycle-cases.js";
|
|
47
|
+
export { SCOPE_CASES } from "../execution/testing/scope-cases.js";
|
|
48
|
+
export { MULTI_LIFECYCLE_CASES } from "../execution/testing/multi-lifecycle-cases.js";
|
|
32
49
|
export { referenceBatchExecutor } from "../execution/testing/batch-executor.js";
|
|
33
50
|
export { KILL_BATCH_CASES, KILL_BATCH_DECLARATIONS } from "../execution/testing/kill-batch.js";
|
|
34
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Host adapters, carriers, persistence implementations and the Node harness stay outside.
|
|
5
5
|
* Extend this closure when adding loop modules; never add a host implementation to it.
|
|
6
6
|
*/
|
|
7
|
-
export declare const LOOP_CORE_MODULES: readonly ["agent.ts", "agent-loop.ts", "assistant-terminal-state.ts", "empty-assistant-recovery.ts", "internal-events.ts", "local-failure.ts", "response-timing.ts", "stream-fn.ts", "stream-keepalive.ts", "tool-arguments.ts", "tool-name-alias.ts", "types.ts", "durable/store.ts", "execution/tool-host.ts", "durable/store-admission.ts", "durable/wake-host.ts", "transport/transport.ts"];
|
|
7
|
+
export declare const LOOP_CORE_MODULES: readonly ["agent.ts", "agent-loop.ts", "assistant-terminal-state.ts", "empty-assistant-recovery.ts", "internal-events.ts", "local-failure.ts", "response-timing.ts", "stream-fn.ts", "stream-keepalive.ts", "tool-arguments.ts", "tool-name-alias.ts", "types.ts", "durable/store.ts", "execution/tool-host.ts", "execution/tool-outcome-events.ts", "durable/store-admission.ts", "durable/wake-host.ts", "transport/transport.ts"];
|
|
8
8
|
/**
|
|
9
9
|
* Existing portable model/message utilities and schema types, not provider runtimes.
|
|
10
10
|
* Exact specifiers deliberately exclude compat, OAuth, SDKs and host-specific subpaths.
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { KILL_HAND_DECLARATIONS } from "../execution/testing/kill-hand.js";
|
|
2
2
|
import { BATCH_REGISTRY } from "../execution/testing/batch-registry.js";
|
|
3
3
|
import { LEDGER_REGISTRY } from "../execution/testing/ledger-registry.js";
|
|
4
|
+
import { LIFECYCLE_REGISTRY } from "../execution/testing/lifecycle-registry.js";
|
|
5
|
+
import { NEST_REGISTRY } from "../execution/testing/nest-registry.js";
|
|
6
|
+
import { WAKE_EXEC_REGISTRY } from "../execution/testing/wake-registry.js";
|
|
7
|
+
import { SEQ_REGISTRY } from "../execution/testing/seq-registry.js";
|
|
4
8
|
export const ADAPTER_KINDS = ["store", "wake", "transport", "executor", "host"];
|
|
5
9
|
/**
|
|
6
10
|
* Every case of the durable-core conformance suite (packages/agent/docs/durable-core-adr.md). A change that adds cases
|
|
@@ -57,6 +61,10 @@ const storeCase = (id, impl, expected) => ({
|
|
|
57
61
|
export const CONFORMANCE_REGISTRY = [
|
|
58
62
|
...LEDGER_REGISTRY,
|
|
59
63
|
...BATCH_REGISTRY,
|
|
64
|
+
...SEQ_REGISTRY,
|
|
65
|
+
...NEST_REGISTRY,
|
|
66
|
+
...WAKE_EXEC_REGISTRY,
|
|
67
|
+
...LIFECYCLE_REGISTRY,
|
|
60
68
|
storeCase("STORE-01", STORE_CASES_IMPL, "a commit adopts once, after its batch is durable; every instance sees each batch whole"),
|
|
61
69
|
storeCase("STORE-02", STORE_CASES_IMPL, "a cut at every write point of a commit leaves nothing of it durable, with no adopt and no seq burned"),
|
|
62
70
|
storeCase("STORE-03", STORE_CASES_IMPL, "concurrent admissions run one at a time in admission order; a refused mutation releases the line"),
|
|
@@ -88,7 +96,7 @@ export const CONFORMANCE_REGISTRY = [
|
|
|
88
96
|
transportCase("TRANSPORT-03", TRANSPORT_CASES_IMPL, "backpressure: a stalled receiver bounds its lane's senders; sends resolve in order once it drains"),
|
|
89
97
|
transportCase("MULTI-LANE-01", MULTI_CASES_IMPL, "N scopes over one transport keep per-scope order and interleave"),
|
|
90
98
|
transportCase("MULTI-FAIR-01", MULTI_CASES_IMPL, "a stalled or long lane in A does not starve B: B is delivered within a bounded number of A's frames"),
|
|
91
|
-
transportCase("MULTI-FAIR-
|
|
99
|
+
transportCase("MULTI-FAIR-03", MULTI_CASES_IMPL, "a frame lost on one lane is resent on that lane's own deadline: another lane's ACK progress never postpones it"),
|
|
92
100
|
faultCase(1, "slow"),
|
|
93
101
|
faultCase(2, "lossy"),
|
|
94
102
|
faultCase(3, "laggy"),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** JSON with object keys sorted, so two values with the same fields compare equal whatever their key order. */
|
|
2
|
+
export function canonicalJson(value) {
|
|
3
|
+
if (Array.isArray(value))
|
|
4
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
5
|
+
if (value !== null && typeof value === "object")
|
|
6
|
+
return `{${Object.keys(value)
|
|
7
|
+
.sort()
|
|
8
|
+
.map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`)
|
|
9
|
+
.join(",")}}`;
|
|
10
|
+
return JSON.stringify(value);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=canonical-json.js.map
|
|
@@ -35,6 +35,7 @@ function prepareReply(value) {
|
|
|
35
35
|
return false;
|
|
36
36
|
switch (value.kind) {
|
|
37
37
|
case "prepared":
|
|
38
|
+
case "prepared_awaiting_consent":
|
|
38
39
|
return typeof value.frozenDigest === "string";
|
|
39
40
|
case "blocked":
|
|
40
41
|
return value.result !== undefined;
|
|
@@ -62,12 +63,22 @@ function callOutcome(value) {
|
|
|
62
63
|
return false;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
function consentRecord(value) {
|
|
67
|
+
return (object(value) &&
|
|
68
|
+
(value.gate === "raw" || value.gate === "frozen") &&
|
|
69
|
+
typeof value.digest === "string" &&
|
|
70
|
+
(value.answer === "approved" || value.answer === "denied" || value.answer === "expired"));
|
|
71
|
+
}
|
|
65
72
|
function record(value) {
|
|
66
73
|
if (!object(value) || !manifest(value.manifest))
|
|
67
74
|
return false;
|
|
68
75
|
const size = value.manifest.calls.length;
|
|
69
|
-
const { prepares, released, outcomes, decision } = value;
|
|
70
|
-
return ((
|
|
76
|
+
const { prepares, released, outcomes, decision, consents } = value;
|
|
77
|
+
return ((consents === undefined ||
|
|
78
|
+
(Array.isArray(consents) &&
|
|
79
|
+
consents.length === size &&
|
|
80
|
+
consents.every((entry) => entry === null || consentRecord(entry)))) &&
|
|
81
|
+
(decision === null || decision === "RELEASE" || decision === "ABORT") &&
|
|
71
82
|
Array.isArray(prepares) &&
|
|
72
83
|
prepares.length === size &&
|
|
73
84
|
prepares.every((reply) => reply === null || prepareReply(reply)) &&
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BatchConsent, BatchExecutor, ConsentRecord, ExecutionRef, ManifestCall, PrepareReply } from "./coordinator-types.ts";
|
|
2
|
+
/** What a call needs from the consent port, and how an answer is recorded before the step it decides. */
|
|
3
|
+
export interface ConsentStep {
|
|
4
|
+
readonly consent: BatchConsent;
|
|
5
|
+
readonly executor: BatchExecutor;
|
|
6
|
+
readonly ref: ExecutionRef;
|
|
7
|
+
readonly call: ManifestCall;
|
|
8
|
+
readonly leaseUntil: number;
|
|
9
|
+
/** The call's answered consent, if one is durable. */
|
|
10
|
+
readonly recorded: ConsentRecord | null;
|
|
11
|
+
readonly record: (answer: ConsentRecord) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Gate A, before preparation: a raw call that needs consent is prepared only after an approval of its request digest,
|
|
15
|
+
* which the executor then treats as authorized. A refusal ran nothing, so it is a blocked per-call result.
|
|
16
|
+
*/
|
|
17
|
+
export declare function gateRawCall(step: ConsentStep): Promise<{
|
|
18
|
+
readonly blocked: PrepareReply;
|
|
19
|
+
} | {
|
|
20
|
+
readonly authorizedDigest?: string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Gate B, after preparation: the approval binds the frozen digest and the executor releases without rerunning hooks.
|
|
24
|
+
* A denial is a blocked per-call result; an expiry (or an approval the lease already outran) settles the call
|
|
25
|
+
* `lease_expired` at the endpoint, which ABORTs the batch's unreleased calls. Nothing is ever prepared again: no
|
|
26
|
+
* automatic successor.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveFrozenConsent(step: ConsentStep, frozenDigest: string): Promise<PrepareReply>;
|
|
29
|
+
//# sourceMappingURL=coordinator-consent.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const denied = (gate, answer) => ({
|
|
2
|
+
kind: "blocked",
|
|
3
|
+
result: { reason: "consent_denied", gate, answer },
|
|
4
|
+
});
|
|
5
|
+
/** The executor no longer knows a call it prepared (design 5.6.2 "a lost prepared execution"): uncertain, never rerun. */
|
|
6
|
+
const lost = { reason: "uncertain", hooksRan: true, uncertain: true };
|
|
7
|
+
/**
|
|
8
|
+
* The approver reports the lease ran out while the call awaited Gate B. Nothing is sent to the executor: its own lease
|
|
9
|
+
* clock settles the call `lease_expired` (an abort would record `cancelled` while its clock is behind the brain's).
|
|
10
|
+
*/
|
|
11
|
+
const expired = { reason: "lease_expired", hooksRan: true, uncertain: true };
|
|
12
|
+
async function answer(step, gate, digest) {
|
|
13
|
+
const { recorded } = step;
|
|
14
|
+
if (recorded !== null && recorded.gate === gate && recorded.digest === digest)
|
|
15
|
+
return recorded.answer;
|
|
16
|
+
const given = await step.consent.approve({
|
|
17
|
+
...step.ref,
|
|
18
|
+
gate,
|
|
19
|
+
digest,
|
|
20
|
+
name: step.call.name,
|
|
21
|
+
leaseUntil: step.leaseUntil,
|
|
22
|
+
});
|
|
23
|
+
await step.record({ gate, digest, answer: given });
|
|
24
|
+
return given;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gate A, before preparation: a raw call that needs consent is prepared only after an approval of its request digest,
|
|
28
|
+
* which the executor then treats as authorized. A refusal ran nothing, so it is a blocked per-call result.
|
|
29
|
+
*/
|
|
30
|
+
export async function gateRawCall(step) {
|
|
31
|
+
const { call } = step;
|
|
32
|
+
if (!step.consent.needsConsent({ name: call.name, args: call.args }))
|
|
33
|
+
return {};
|
|
34
|
+
const given = await answer(step, "raw", call.requestDigest);
|
|
35
|
+
return given === "approved" ? { authorizedDigest: call.requestDigest } : { blocked: denied("raw", given) };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gate B, after preparation: the approval binds the frozen digest and the executor releases without rerunning hooks.
|
|
39
|
+
* A denial is a blocked per-call result; an expiry (or an approval the lease already outran) settles the call
|
|
40
|
+
* `lease_expired` at the endpoint, which ABORTs the batch's unreleased calls. Nothing is ever prepared again: no
|
|
41
|
+
* automatic successor.
|
|
42
|
+
*/
|
|
43
|
+
export async function resolveFrozenConsent(step, frozenDigest) {
|
|
44
|
+
const given = await answer(step, "frozen", frozenDigest);
|
|
45
|
+
if (given === "denied") {
|
|
46
|
+
await step.executor.abort(step.ref);
|
|
47
|
+
return denied("frozen", given);
|
|
48
|
+
}
|
|
49
|
+
if (given === "expired")
|
|
50
|
+
return { kind: "settled", outcome: expired };
|
|
51
|
+
const reply = await consentOn(step.executor, step.ref, frozenDigest);
|
|
52
|
+
if (reply.kind === "prepared")
|
|
53
|
+
return { kind: "prepared", frozenDigest };
|
|
54
|
+
if (reply.kind === "unknown_execution")
|
|
55
|
+
return { kind: "settled", outcome: lost };
|
|
56
|
+
return { kind: "settled", outcome: reply.outcome };
|
|
57
|
+
}
|
|
58
|
+
function consentOn(executor, ref, frozenDigest) {
|
|
59
|
+
if (executor.consent === undefined)
|
|
60
|
+
throw new Error(`executor answered prepared_awaiting_consent for ${ref.executionId} but cannot take consent`);
|
|
61
|
+
return executor.consent(ref, frozenDigest);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=coordinator-consent.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BatchCoordinator } from "./coordinator.ts";
|
|
2
|
+
import type { BatchPlan, BatchResult } from "./coordinator-types.ts";
|
|
3
|
+
/** `toolExecution: "sequential"` on the coordinator (design 5.6.1 scheduler modes, S11). */
|
|
4
|
+
export interface SequentialCoordinator {
|
|
5
|
+
/**
|
|
6
|
+
* Runs each call as its own one-call batch, in source order: a call is prepared and run to its final outcome before
|
|
7
|
+
* the next is prepared, as today's sequential scheduler interleaves them. The one-call batches are durable, so running
|
|
8
|
+
* the same plan again after a crash returns the finished calls' stored outcomes and resumes the one in flight. A
|
|
9
|
+
* call whose batch ABORTs (its preparation was stopped) ends the run: the calls after it are never prepared and are
|
|
10
|
+
* reported `not_run`.
|
|
11
|
+
*/
|
|
12
|
+
run(plan: BatchPlan): Promise<BatchResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createSequentialCoordinator(coordinator: BatchCoordinator): SequentialCoordinator;
|
|
15
|
+
//# sourceMappingURL=coordinator-sequential.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The durable batch id of call `index` of `batchId`; stable across runs, so a resumed run finds it. */
|
|
2
|
+
const sequentialBatchId = (batchId, index) => `${batchId}#${index}`;
|
|
3
|
+
/**
|
|
4
|
+
* The cause the calls after an ABORTed call inherit, as one batch gives its unrun calls the batch's own cause: after an
|
|
5
|
+
* interrupted preparation they replay with today's placeholder (X12), after a stop as an aborted batch. A one-call batch
|
|
6
|
+
* ABORTs only on its call's preparation, so an aborting call that is not `not_run` settled at preparation, and one batch
|
|
7
|
+
* fails that closed as an interrupted preparation whatever the stored reason (`blocked` included, `abortCause`).
|
|
8
|
+
*/
|
|
9
|
+
function inheritedCause(aborting) {
|
|
10
|
+
if (aborting === undefined)
|
|
11
|
+
return "batch_abort";
|
|
12
|
+
return aborting.kind === "not_run" ? aborting.cause : "interrupted_preparation";
|
|
13
|
+
}
|
|
14
|
+
export function createSequentialCoordinator(coordinator) {
|
|
15
|
+
return {
|
|
16
|
+
run: async (plan) => {
|
|
17
|
+
const outcomes = [];
|
|
18
|
+
for (const [index, call] of plan.calls.entries()) {
|
|
19
|
+
const single = await coordinator.run({
|
|
20
|
+
...plan,
|
|
21
|
+
batchId: sequentialBatchId(plan.batchId, index),
|
|
22
|
+
calls: [call],
|
|
23
|
+
});
|
|
24
|
+
outcomes.push(...single.outcomes);
|
|
25
|
+
if (single.decision === "ABORT") {
|
|
26
|
+
const notRun = { kind: "not_run", cause: inheritedCause(single.outcomes[0]) };
|
|
27
|
+
return { decision: "ABORT", outcomes: [...outcomes, ...plan.calls.slice(index + 1).map(() => notRun)] };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { decision: "RELEASE", outcomes };
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=coordinator-sequential.js.map
|
|
@@ -45,6 +45,8 @@ export type PrepareRequest = {
|
|
|
45
45
|
readonly name: string;
|
|
46
46
|
readonly args: StoreValue;
|
|
47
47
|
};
|
|
48
|
+
/** Gate A approved this raw request digest (design 5.6.1); the executor asks again only for a different frozen call. */
|
|
49
|
+
readonly authorizedDigest?: string;
|
|
48
50
|
};
|
|
49
51
|
export type ExecutionRef = {
|
|
50
52
|
readonly issuer: string;
|
|
@@ -61,6 +63,11 @@ export type ExecutionRef = {
|
|
|
61
63
|
export type PrepareReply = {
|
|
62
64
|
readonly kind: "prepared";
|
|
63
65
|
readonly frozenDigest: string;
|
|
66
|
+
}
|
|
67
|
+
/** Gate B: the frozen call differs from what Gate A authorized and needs consent; the approval binds this digest. */
|
|
68
|
+
| {
|
|
69
|
+
readonly kind: "prepared_awaiting_consent";
|
|
70
|
+
readonly frozenDigest: string;
|
|
64
71
|
} | {
|
|
65
72
|
readonly kind: "blocked";
|
|
66
73
|
readonly result: StoreValue;
|
|
@@ -83,7 +90,43 @@ export interface BatchExecutor {
|
|
|
83
90
|
/** Resolves once the released call has settled. */
|
|
84
91
|
release(ref: ExecutionRef): Promise<SettleReply>;
|
|
85
92
|
abort(ref: ExecutionRef): Promise<SettleReply>;
|
|
93
|
+
/**
|
|
94
|
+
* Applies an approval to a call awaiting consent on `frozenDigest`: `prepared`, or the call's terminal outcome (a
|
|
95
|
+
* lease that expired while it waited rejects the approval). Only cross-machine executors gate consent.
|
|
96
|
+
*/
|
|
97
|
+
consent?(ref: ExecutionRef, frozenDigest: string): Promise<{
|
|
98
|
+
readonly kind: "prepared";
|
|
99
|
+
} | SettleReply>;
|
|
100
|
+
}
|
|
101
|
+
/** What an approver answered; `expired` is the call's lease running out first. */
|
|
102
|
+
export type ConsentAnswer = "approved" | "denied" | "expired";
|
|
103
|
+
export type ConsentRequest = ExecutionRef & {
|
|
104
|
+
readonly gate: "raw" | "frozen";
|
|
105
|
+
readonly digest: string;
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly leaseUntil: number;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Consent for cross-machine executions (design 5.6.1 Gate A and Gate B). Any RPC-authorized party may answer through
|
|
111
|
+
* `approve`; the device is not the only approver (K2). Fused and split-local sessions configure none (K3).
|
|
112
|
+
*/
|
|
113
|
+
export interface BatchConsent {
|
|
114
|
+
/**
|
|
115
|
+
* Gate A: the engine's built-in permission classification of the raw call, before any extension callback. A call that
|
|
116
|
+
* classifies as denied is not consent: it is prepared and the hand's own `tool_call` chain refuses it, as today.
|
|
117
|
+
*/
|
|
118
|
+
needsConsent(call: {
|
|
119
|
+
readonly name: string;
|
|
120
|
+
readonly args: StoreValue;
|
|
121
|
+
}): boolean;
|
|
122
|
+
approve(request: ConsentRequest): Promise<ConsentAnswer>;
|
|
86
123
|
}
|
|
124
|
+
/** One answered consent of a call, durable before the step it decides. */
|
|
125
|
+
export type ConsentRecord = {
|
|
126
|
+
readonly gate: "raw" | "frozen";
|
|
127
|
+
readonly digest: string;
|
|
128
|
+
readonly answer: ConsentAnswer;
|
|
129
|
+
};
|
|
87
130
|
export type BatchDecision = "RELEASE" | "ABORT";
|
|
88
131
|
export type CallOutcome = {
|
|
89
132
|
readonly kind: "result";
|
|
@@ -108,6 +151,8 @@ export type BatchRecord = {
|
|
|
108
151
|
readonly decision: BatchDecision | null;
|
|
109
152
|
readonly released: readonly boolean[];
|
|
110
153
|
readonly outcomes: readonly (CallOutcome | null)[];
|
|
154
|
+
/** Answered consents per call; absent on a record written before consent gating. */
|
|
155
|
+
readonly consents?: readonly (ConsentRecord | null)[];
|
|
111
156
|
};
|
|
112
157
|
export type BatchResult = {
|
|
113
158
|
readonly decision: BatchDecision;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DurableStore } from "../durable/store.ts";
|
|
2
2
|
import type { AdmissionLine } from "../durable/store-admission.ts";
|
|
3
|
-
import type { BatchExecutor, BatchPlan, BatchRecord, BatchResult } from "./coordinator-types.ts";
|
|
3
|
+
import type { BatchConsent, BatchExecutor, BatchPlan, BatchRecord, BatchResult } from "./coordinator-types.ts";
|
|
4
4
|
export declare class BatchManifestConflictError extends Error {
|
|
5
5
|
constructor(batchId: string);
|
|
6
6
|
}
|
|
@@ -11,6 +11,8 @@ export interface BatchCoordinatorOptions {
|
|
|
11
11
|
/** The single admission line of the store's writable epoch, shared with every other writer on it. */
|
|
12
12
|
readonly admission: AdmissionLine;
|
|
13
13
|
readonly executor: (id: string) => BatchExecutor;
|
|
14
|
+
/** Gate A/B consent for cross-machine executors; absent (fused, split-local) means no consent step (K3). */
|
|
15
|
+
readonly consent?: BatchConsent;
|
|
14
16
|
}
|
|
15
17
|
export interface BatchCoordinator {
|
|
16
18
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { decodeBatchRecord } from "./coordinator-codec.js";
|
|
2
|
+
import { gateRawCall, resolveFrozenConsent } from "./coordinator-consent.js";
|
|
2
3
|
import { abortCause, buildBatchManifest, finished, settledOutcome } from "./coordinator-plan.js";
|
|
3
4
|
const PREFIX = "execution.batch:";
|
|
4
5
|
const keyOf = (issuer, batchId) => `${PREFIX}${JSON.stringify([issuer, batchId])}`;
|
|
@@ -10,7 +11,7 @@ export class BatchManifestConflictError extends Error {
|
|
|
10
11
|
}
|
|
11
12
|
const replace = (items, index, value) => items.map((item, at) => (at === index ? value : item));
|
|
12
13
|
export function createBatchCoordinator(options) {
|
|
13
|
-
const { issuer, store, epoch, admission, executor } = options;
|
|
14
|
+
const { issuer, store, epoch, admission, executor, consent } = options;
|
|
14
15
|
const read = async (batchId) => {
|
|
15
16
|
const value = await store.getDocument(keyOf(issuer, batchId));
|
|
16
17
|
return value === undefined ? undefined : decodeBatchRecord(value);
|
|
@@ -53,11 +54,32 @@ export function createBatchCoordinator(options) {
|
|
|
53
54
|
else if (record.manifest.manifestDigest !== manifest.manifestDigest) {
|
|
54
55
|
throw new BatchManifestConflictError(plan.batchId);
|
|
55
56
|
}
|
|
57
|
+
const consentStep = (gate, call) => ({
|
|
58
|
+
consent: gate,
|
|
59
|
+
executor: executor(call.executor),
|
|
60
|
+
ref: ref(call),
|
|
61
|
+
call,
|
|
62
|
+
leaseUntil: manifest.leaseUntil,
|
|
63
|
+
recorded: current().consents?.[call.sourceIndex] ?? null,
|
|
64
|
+
record: (answered) => persist({
|
|
65
|
+
...current(),
|
|
66
|
+
consents: replace(current().consents ?? manifest.calls.map(() => null), call.sourceIndex, answered),
|
|
67
|
+
}, "consent", call),
|
|
68
|
+
});
|
|
69
|
+
const setPrepare = (call, reply) => persist({ ...current(), prepares: replace(current().prepares, call.sourceIndex, reply) }, "prepare", call);
|
|
56
70
|
if (current().decision === null) {
|
|
57
71
|
for (const call of manifest.calls) {
|
|
58
72
|
let reply = current().prepares[call.sourceIndex] ?? null;
|
|
59
|
-
|
|
73
|
+
const gate = reply === null && consent !== undefined ? await gateRawCall(consentStep(consent, call)) : {};
|
|
74
|
+
if (reply === null && "blocked" in gate) {
|
|
75
|
+
reply = gate.blocked;
|
|
76
|
+
await setPrepare(call, reply);
|
|
77
|
+
}
|
|
78
|
+
else if (reply === null) {
|
|
60
79
|
reply = await executor(call.executor).prepare({
|
|
80
|
+
...("authorizedDigest" in gate && gate.authorizedDigest !== undefined
|
|
81
|
+
? { authorizedDigest: gate.authorizedDigest }
|
|
82
|
+
: {}),
|
|
61
83
|
...ref(call),
|
|
62
84
|
batchId: manifest.batchId,
|
|
63
85
|
manifestDigest: manifest.manifestDigest,
|
|
@@ -68,11 +90,21 @@ export function createBatchCoordinator(options) {
|
|
|
68
90
|
requestDigest: call.requestDigest,
|
|
69
91
|
call: { name: call.name, args: call.args },
|
|
70
92
|
});
|
|
71
|
-
await
|
|
93
|
+
await setPrepare(call, reply);
|
|
72
94
|
}
|
|
73
95
|
if (abortCause(reply) !== undefined)
|
|
74
96
|
break;
|
|
75
97
|
}
|
|
98
|
+
for (const call of manifest.calls) {
|
|
99
|
+
if (current().prepares.some((reply) => reply !== null && abortCause(reply) !== undefined))
|
|
100
|
+
break;
|
|
101
|
+
const reply = current().prepares[call.sourceIndex] ?? null;
|
|
102
|
+
if (reply?.kind !== "prepared_awaiting_consent")
|
|
103
|
+
continue;
|
|
104
|
+
if (consent === undefined)
|
|
105
|
+
throw new Error(`batch ${plan.batchId}: a call awaits consent but none is configured`);
|
|
106
|
+
await setPrepare(call, await resolveFrozenConsent(consentStep(consent, call), reply.frozenDigest));
|
|
107
|
+
}
|
|
76
108
|
const aborted = current().prepares.some((reply) => reply !== null && abortCause(reply) !== undefined);
|
|
77
109
|
await persist({ ...current(), decision: aborted ? "ABORT" : "RELEASE" }, "decision");
|
|
78
110
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DeviceFiles } from "./device-files.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The local filesystem as {@link DeviceFiles}: what a fused session's extension code uses, called directly, and what a
|
|
4
|
+
* hand runs a channel operation on once its grant, handlers and policy have allowed it. Reads and writes are bounded
|
|
5
|
+
* by {@link FILE_CHANNEL_MAX_BYTES} before any data is in memory, so both sides of a split session agree on the limit.
|
|
6
|
+
*/
|
|
7
|
+
export declare function localDeviceFiles(): DeviceFiles;
|
|
8
|
+
//# sourceMappingURL=device-files-node.d.ts.map
|