@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.
Files changed (167) hide show
  1. package/dist/agent-loop.js +20 -186
  2. package/dist/agent.d.ts +4 -0
  3. package/dist/agent.js +4 -0
  4. package/dist/conformance/index.d.ts +30 -0
  5. package/dist/conformance/index.js +21 -0
  6. package/dist/conformance/loop-core-manifest.d.ts +1 -1
  7. package/dist/conformance/loop-core-manifest.js +18 -0
  8. package/dist/conformance/registry.js +20 -18
  9. package/dist/egress/types.d.ts +102 -0
  10. package/dist/egress/types.js +7 -0
  11. package/dist/execution/canonical-digest.d.ts +10 -0
  12. package/dist/execution/canonical-digest.js +20 -0
  13. package/dist/execution/canonical-json.d.ts +3 -0
  14. package/dist/execution/canonical-json.js +12 -0
  15. package/dist/execution/chain-count.d.ts +26 -0
  16. package/dist/execution/chain-count.js +45 -0
  17. package/dist/execution/coordinator-codec.js +13 -2
  18. package/dist/execution/coordinator-consent.d.ts +29 -0
  19. package/dist/execution/coordinator-consent.js +63 -0
  20. package/dist/execution/coordinator-plan.d.ts +1 -2
  21. package/dist/execution/coordinator-plan.js +4 -17
  22. package/dist/execution/coordinator-sequential.d.ts +15 -0
  23. package/dist/execution/coordinator-sequential.js +34 -0
  24. package/dist/execution/coordinator-types.d.ts +45 -0
  25. package/dist/execution/coordinator.d.ts +3 -1
  26. package/dist/execution/coordinator.js +35 -3
  27. package/dist/execution/device-files-node.d.ts +8 -0
  28. package/dist/execution/device-files-node.js +150 -0
  29. package/dist/execution/device-files.d.ts +109 -0
  30. package/dist/execution/device-files.js +124 -0
  31. package/dist/execution/ledger-types.d.ts +3 -1
  32. package/dist/execution/ledger.d.ts +9 -3
  33. package/dist/execution/ledger.js +8 -2
  34. package/dist/execution/loop-hook-host-hand.d.ts +33 -0
  35. package/dist/execution/loop-hook-host-hand.js +71 -0
  36. package/dist/execution/loop-hook-host-protocol.d.ts +46 -0
  37. package/dist/execution/loop-hook-host-protocol.js +47 -0
  38. package/dist/execution/loop-hook-host.d.ts +40 -0
  39. package/dist/execution/loop-hook-host.js +87 -0
  40. package/dist/execution/nested-codec.d.ts +5 -0
  41. package/dist/execution/nested-codec.js +41 -0
  42. package/dist/execution/nested-types.d.ts +92 -0
  43. package/dist/execution/nested-types.js +3 -0
  44. package/dist/execution/nested.d.ts +48 -0
  45. package/dist/execution/nested.js +206 -0
  46. package/dist/execution/plane-model.d.ts +33 -0
  47. package/dist/execution/plane-model.js +80 -0
  48. package/dist/execution/plane-session.d.ts +56 -0
  49. package/dist/execution/plane-session.js +178 -0
  50. package/dist/execution/plane.d.ts +75 -0
  51. package/dist/execution/plane.js +172 -0
  52. package/dist/execution/prepared/executor-body.d.ts +22 -0
  53. package/dist/execution/prepared/executor-body.js +73 -0
  54. package/dist/execution/prepared/executor-freeze.d.ts +17 -0
  55. package/dist/execution/prepared/executor-freeze.js +42 -0
  56. package/dist/execution/prepared/executor-pipeline.d.ts +11 -0
  57. package/dist/execution/prepared/executor-pipeline.js +26 -0
  58. package/dist/execution/prepared/executor-types.d.ts +131 -0
  59. package/dist/execution/prepared/executor-types.js +2 -0
  60. package/dist/execution/prepared/executor.d.ts +8 -0
  61. package/dist/execution/prepared/executor.js +261 -0
  62. package/dist/execution/prepared/memory-batch-store.d.ts +4 -0
  63. package/dist/execution/prepared/memory-batch-store.js +4 -0
  64. package/dist/execution/prepared/pipeline-prepared-batch.d.ts +27 -0
  65. package/dist/execution/prepared/pipeline-prepared-batch.js +175 -0
  66. package/dist/execution/prepared/pipeline-prepared.d.ts +10 -0
  67. package/dist/execution/prepared/pipeline-prepared.js +54 -0
  68. package/dist/execution/remote-device-files.d.ts +12 -0
  69. package/dist/execution/remote-device-files.js +113 -0
  70. package/dist/execution/remote-epoch-gate.d.ts +19 -0
  71. package/dist/execution/remote-epoch-gate.js +46 -0
  72. package/dist/execution/remote-epoch.d.ts +53 -0
  73. package/dist/execution/remote-epoch.js +74 -0
  74. package/dist/execution/remote-executor.d.ts +17 -0
  75. package/dist/execution/remote-executor.js +70 -18
  76. package/dist/execution/remote-file-call.d.ts +14 -0
  77. package/dist/execution/remote-file-call.js +31 -0
  78. package/dist/execution/remote-hand-ledger.d.ts +11 -3
  79. package/dist/execution/remote-hand-ledger.js +31 -15
  80. package/dist/execution/remote-link.d.ts +41 -0
  81. package/dist/execution/remote-link.js +153 -0
  82. package/dist/execution/remote-protocol.d.ts +50 -4
  83. package/dist/execution/remote-protocol.js +48 -2
  84. package/dist/execution/remote-tool-host.d.ts +23 -3
  85. package/dist/execution/remote-tool-host.js +25 -64
  86. package/dist/execution/scope-lifecycle.d.ts +81 -0
  87. package/dist/execution/scope-lifecycle.js +173 -0
  88. package/dist/execution/testing/batch-executor.js +32 -3
  89. package/dist/execution/testing/batch-harness.d.ts +25 -3
  90. package/dist/execution/testing/batch-harness.js +83 -5
  91. package/dist/execution/testing/cancel-cases.d.ts +8 -0
  92. package/dist/execution/testing/cancel-cases.js +64 -0
  93. package/dist/execution/testing/consent-cases.d.ts +14 -0
  94. package/dist/execution/testing/consent-cases.js +66 -0
  95. package/dist/execution/testing/epoch-cases.d.ts +8 -0
  96. package/dist/execution/testing/epoch-cases.js +84 -0
  97. package/dist/execution/testing/epoch-harness.d.ts +47 -0
  98. package/dist/execution/testing/epoch-harness.js +172 -0
  99. package/dist/execution/testing/epoch-registry.d.ts +3 -0
  100. package/dist/execution/testing/epoch-registry.js +17 -0
  101. package/dist/execution/testing/hand-harness.d.ts +3 -0
  102. package/dist/execution/testing/hand-harness.js +27 -22
  103. package/dist/execution/testing/hand-registry.d.ts +3 -0
  104. package/dist/execution/testing/hand-registry.js +20 -0
  105. package/dist/execution/testing/kill-epoch.d.ts +9 -0
  106. package/dist/execution/testing/kill-epoch.js +71 -0
  107. package/dist/execution/testing/kill-hook.d.ts +14 -0
  108. package/dist/execution/testing/kill-hook.js +117 -0
  109. package/dist/execution/testing/kill-nest.d.ts +6 -0
  110. package/dist/execution/testing/kill-nest.js +55 -0
  111. package/dist/execution/testing/kill-wakex.d.ts +6 -0
  112. package/dist/execution/testing/kill-wakex.js +81 -0
  113. package/dist/execution/testing/lifecycle-cases.d.ts +9 -0
  114. package/dist/execution/testing/lifecycle-cases.js +60 -0
  115. package/dist/execution/testing/lifecycle-registry.d.ts +3 -0
  116. package/dist/execution/testing/lifecycle-registry.js +19 -0
  117. package/dist/execution/testing/multi-epoch-cases.d.ts +4 -0
  118. package/dist/execution/testing/multi-epoch-cases.js +29 -0
  119. package/dist/execution/testing/multi-lifecycle-cases.d.ts +4 -0
  120. package/dist/execution/testing/multi-lifecycle-cases.js +34 -0
  121. package/dist/execution/testing/multi-seq-cases.d.ts +4 -0
  122. package/dist/execution/testing/multi-seq-cases.js +46 -0
  123. package/dist/execution/testing/nest-cases.d.ts +39 -0
  124. package/dist/execution/testing/nest-cases.js +181 -0
  125. package/dist/execution/testing/nest-registry.d.ts +3 -0
  126. package/dist/execution/testing/nest-registry.js +27 -0
  127. package/dist/execution/testing/scope-cases.d.ts +6 -0
  128. package/dist/execution/testing/scope-cases.js +49 -0
  129. package/dist/execution/testing/seq-cases.d.ts +6 -0
  130. package/dist/execution/testing/seq-cases.js +71 -0
  131. package/dist/execution/testing/seq-registry.d.ts +3 -0
  132. package/dist/execution/testing/seq-registry.js +32 -0
  133. package/dist/execution/testing/wake-exec-cases.d.ts +20 -0
  134. package/dist/execution/testing/wake-exec-cases.js +147 -0
  135. package/dist/execution/testing/wake-registry.d.ts +3 -0
  136. package/dist/execution/testing/wake-registry.js +26 -0
  137. package/dist/execution/tool-host.d.ts +23 -3
  138. package/dist/execution/tool-host.js +18 -1
  139. package/dist/execution/tool-outcome-events.d.ts +11 -0
  140. package/dist/execution/tool-outcome-events.js +47 -0
  141. package/dist/execution/wake-inbox.d.ts +25 -0
  142. package/dist/execution/wake-inbox.js +85 -0
  143. package/dist/execution/wake-outbox.d.ts +30 -0
  144. package/dist/execution/wake-outbox.js +87 -0
  145. package/dist/execution/wake-types.d.ts +45 -0
  146. package/dist/execution/wake-types.js +3 -0
  147. package/dist/harness/agent-harness.d.ts +6 -0
  148. package/dist/harness/execution/tool-host-call.d.ts +13 -0
  149. package/dist/harness/execution/tool-host-call.js +55 -0
  150. package/dist/harness/execution/tools.d.ts +2 -1
  151. package/dist/harness/execution/tools.js +32 -17
  152. package/dist/harness/runtime/drive/tools.js +1 -1
  153. package/dist/harness/runtime/harness.js +1 -0
  154. package/dist/harness/runtime/types.d.ts +1 -0
  155. package/dist/index.d.ts +27 -2
  156. package/dist/index.js +24 -1
  157. package/dist/node.d.ts +1 -0
  158. package/dist/node.js +1 -0
  159. package/dist/public-entry.d.ts +10 -0
  160. package/dist/public-entry.js +23 -0
  161. package/dist/step-commit.d.ts +24 -0
  162. package/dist/step-commit.js +24 -0
  163. package/dist/tool-name-alias.d.ts +1 -7
  164. package/dist/tool-name-alias.js +0 -17
  165. package/dist/transport/testing/multi-cases.js +8 -8
  166. package/dist/types.d.ts +37 -1
  167. package/package.json +3 -3
@@ -9,7 +9,10 @@ import { internalProgressSink } from "./internal-events.js";
9
9
  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
- import { resolveCallTool, withToolNameCorrection } from "./tool-name-alias.js";
12
+ import { withToolNameCorrection } from "./tool-name-alias.js";
13
+ import { createPreparedToolHost } from "./execution/prepared/pipeline-prepared.js";
14
+ import { BatchStoreMissingError, PreflightCarryMissingError } from "./execution/tool-host.js";
15
+ import { createErrorToolResult, createToolResultMessage, emitToolExecutionEnd, emitToolResultMessage, } from "./execution/tool-outcome-events.js";
13
16
  /**
14
17
  * Start an agent loop with a new prompt message.
15
18
  * The prompt is added to the context and events are emitted for it.
@@ -207,6 +210,8 @@ async function runLoop(initialContext, newMessages, initialConfig, signal, emit,
207
210
  newMessages.push(result);
208
211
  toolResults.push(result);
209
212
  }
213
+ if (config.commitStep)
214
+ await config.commitStep({ message, providerToolResults });
210
215
  if (shouldTerminateAssistantTurn(message)) {
211
216
  // Hard exit: the decision is ignored, but the hook still sees the finished turn before turn_end.
212
217
  await config.finishTurn?.({ message, toolResults, context: currentContext, newMessages }, signal);
@@ -925,153 +930,25 @@ async function executeToolCalls(currentContext, assistantMessage, config, signal
925
930
  // channel and its result buffered; running it again would duplicate a
926
931
  // side-effecting tool.
927
932
  const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall" && !isCursorExecResolved(c));
928
- const host = config.toolHost ?? {
929
- execute: async (call, options) => {
930
- // Only yield when a witness sink is configured and returns a promise: an unconditional `await` adds a
931
- // microtask per call and reorders lifecycle vs message events against today's fused path (EQ E03).
932
- const recordWitness = options.recordWitness;
933
- if (recordWitness) {
934
- for (const raw of call.calls) {
935
- const pending = recordWitness({ pipeline: "legacy", toolCallId: raw.id });
936
- if (pending)
937
- await pending;
938
- }
939
- }
940
- return call.mode === "sequential"
941
- ? executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, options.signal, options.emit)
942
- : executeToolCallsParallel(currentContext, assistantMessage, toolCalls, config, options.signal, options.emit);
943
- },
944
- };
933
+ const host = config.toolHost ?? defaultToolHost();
945
934
  return host.execute({
946
935
  scope: config.executionScope ?? { id: crypto.randomUUID(), root: "" },
947
936
  calls: toolCalls,
948
937
  mode: config.toolExecution ?? "parallel",
949
- }, { signal, emit, recordWitness: config.onExecutionPipeline });
950
- }
951
- async function executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit) {
952
- const finalizedCalls = [];
953
- const messages = [];
954
- for (const toolCall of toolCalls) {
955
- const tool = await resolveCallTool(currentContext, toolCall, config);
956
- await emit({
957
- type: "tool_execution_start",
958
- toolCallId: toolCall.id,
959
- toolName: tool?.name ?? toolCall.name,
960
- args: toolCall.arguments,
961
- });
962
- const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, tool, config, signal);
963
- let finalized;
964
- if (preparation.kind === "immediate") {
965
- finalized = {
966
- toolCall: preparation.toolCall,
967
- result: preparation.result,
968
- isError: preparation.isError,
969
- };
970
- }
971
- else {
972
- const executed = await executePreparedToolCall(preparation, signal, emitToolExecutionUpdate(preparation.toolCall, emit));
973
- finalized = await finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
974
- }
975
- await emitToolExecutionEnd(finalized, emit);
976
- const toolResultMessage = createToolResultMessage(finalized);
977
- await emitToolResultMessage(toolResultMessage, emit);
978
- finalizedCalls.push(finalized);
979
- messages.push(toolResultMessage);
980
- if (signal?.aborted) {
981
- break;
982
- }
983
- }
984
- return {
985
- messages,
986
- terminate: shouldTerminateToolBatch(finalizedCalls),
987
- };
988
- }
989
- async function executeToolCallsParallel(currentContext, assistantMessage, toolCalls, config, signal, emit) {
990
- const finalizedCalls = [];
991
- const preparedCalls = [];
992
- let lastSequentialCall;
993
- let currentParallelWave = [];
994
- for (const toolCall of toolCalls) {
995
- const tool = await resolveCallTool(currentContext, toolCall, config);
996
- await emit({
997
- type: "tool_execution_start",
998
- toolCallId: toolCall.id,
999
- toolName: tool?.name ?? toolCall.name,
1000
- args: toolCall.arguments,
1001
- });
1002
- const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, tool, config, signal);
1003
- const isSequential = isSequentialToolCall(currentContext, preparation.toolCall);
1004
- const dependencies = isSequential
1005
- ? [...(lastSequentialCall ? [lastSequentialCall] : []), ...currentParallelWave]
1006
- : lastSequentialCall
1007
- ? [lastSequentialCall]
1008
- : [];
1009
- preparedCalls.push({ preparation, isSequential, dependencies });
1010
- if (isSequential) {
1011
- // Dependencies are assigned in the second phase after all preflight hooks
1012
- // have completed, so a later preflight abort vetoes every execution.
1013
- lastSequentialCall = undefined;
1014
- currentParallelWave = [];
1015
- }
1016
- else {
1017
- currentParallelWave.push(Promise.resolve(undefined));
1018
- }
1019
- if (signal?.aborted) {
1020
- break;
1021
- }
1022
- }
1023
- let previousSequential;
1024
- let previousWave = [];
1025
- for (const { preparation, isSequential } of preparedCalls) {
1026
- const dependencies = isSequential
1027
- ? [...(previousSequential ? [previousSequential] : []), ...previousWave]
1028
- : previousSequential
1029
- ? [previousSequential]
1030
- : [];
1031
- const finalizedCall = (async () => {
1032
- await Promise.all(dependencies);
1033
- const finalized = signal?.aborted
1034
- ? { toolCall: preparation.toolCall, result: createErrorToolResult("Operation aborted"), isError: true }
1035
- : await runPreparedToolCall(currentContext, assistantMessage, preparation, config, signal, emit);
1036
- await emitToolExecutionEnd(finalized, emit);
1037
- return finalized;
1038
- })();
1039
- finalizedCalls.push(finalizedCall);
1040
- if (isSequential) {
1041
- previousSequential = finalizedCall;
1042
- previousWave = [];
1043
- }
1044
- else
1045
- previousWave.push(finalizedCall);
1046
- }
1047
- const orderedFinalizedCalls = await Promise.all(finalizedCalls);
1048
- const messages = [];
1049
- for (const finalized of orderedFinalizedCalls) {
1050
- const toolResultMessage = createToolResultMessage(finalized);
1051
- await emitToolResultMessage(toolResultMessage, emit);
1052
- messages.push(toolResultMessage);
1053
- }
1054
- return {
1055
- messages,
1056
- terminate: shouldTerminateToolBatch(orderedFinalizedCalls),
1057
- };
1058
- }
1059
- async function runPreparedToolCall(currentContext, assistantMessage, preparation, config, signal, emit) {
1060
- if (preparation.kind === "immediate") {
1061
- return {
1062
- toolCall: preparation.toolCall,
1063
- result: preparation.result,
1064
- isError: preparation.isError,
1065
- };
938
+ }, {
939
+ signal,
940
+ emit,
941
+ recordWitness: config.onExecutionPipeline,
942
+ local: { context: currentContext, assistantMessage },
943
+ });
944
+ function defaultToolHost() {
945
+ if (config.batchStoreFactory === undefined)
946
+ throw new BatchStoreMissingError();
947
+ const afterToolFreeze = config.afterToolFreeze;
948
+ if (afterToolFreeze === undefined)
949
+ throw new PreflightCarryMissingError();
950
+ return createPreparedToolHost({ ...config, afterToolFreeze }, config.batchStoreFactory);
1066
951
  }
1067
- const executed = await executePreparedToolCall(preparation, signal, emitToolExecutionUpdate(preparation.toolCall, emit));
1068
- return finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
1069
- }
1070
- function isSequentialToolCall(currentContext, toolCall) {
1071
- return currentContext.tools?.find((tool) => tool.name === toolCall.name)?.executionMode === "sequential";
1072
- }
1073
- function shouldTerminateToolBatch(finalizedCalls) {
1074
- return finalizedCalls.length > 0 && finalizedCalls.every((finalized) => finalized.result.terminate === true);
1075
952
  }
1076
953
  export { prepareAgentToolCallArguments };
1077
954
  export function prepareAgentToolCall(tool, toolCall) {
@@ -1181,15 +1058,6 @@ function abortReleasePromise(signal) {
1181
1058
  signal.addEventListener("abort", () => resolve(ABORTED), { once: true });
1182
1059
  });
1183
1060
  }
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
1061
  /**
1194
1062
  * Run one tool call through the same steps as a model-issued call: argument preparation, schema
1195
1063
  * validation, `beforeToolCall`, execution, and `afterToolCall`. Emits no events and adds no
@@ -1286,38 +1154,4 @@ async function finalizeExecutedToolCall(currentContext, assistantMessage, prepar
1286
1154
  isError,
1287
1155
  };
1288
1156
  }
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
1157
  //# sourceMappingURL=agent-loop.js.map
package/dist/agent.d.ts CHANGED
@@ -38,6 +38,8 @@ export interface AgentOptions {
38
38
  maxRetryDelayMs?: number;
39
39
  toolExecution?: ToolExecutionMode;
40
40
  toolHost?: AgentLoopConfig["toolHost"];
41
+ batchStoreFactory?: AgentLoopConfig["batchStoreFactory"];
42
+ afterToolFreeze?: AgentLoopConfig["afterToolFreeze"];
41
43
  executionScope?: AgentLoopConfig["executionScope"];
42
44
  onExecutionPipeline?: AgentLoopConfig["onExecutionPipeline"];
43
45
  removedToolHints?: Record<string, string>;
@@ -117,6 +119,8 @@ export declare class Agent {
117
119
  /** Tool execution strategy for assistant messages that contain multiple tool calls. */
118
120
  toolExecution: ToolExecutionMode;
119
121
  toolHost?: AgentLoopConfig["toolHost"];
122
+ batchStoreFactory?: AgentLoopConfig["batchStoreFactory"];
123
+ afterToolFreeze?: AgentLoopConfig["afterToolFreeze"];
120
124
  executionScope: NonNullable<AgentLoopConfig["executionScope"]>;
121
125
  getExecutionScope?: () => NonNullable<AgentLoopConfig["executionScope"]>;
122
126
  onExecutionPipeline?: AgentLoopConfig["onExecutionPipeline"];
package/dist/agent.js CHANGED
@@ -168,6 +168,8 @@ export class Agent {
168
168
  this.maxRetryDelayMs = runtimeOptions.maxRetryDelayMs;
169
169
  this.toolExecution = runtimeOptions.toolExecution ?? "parallel";
170
170
  this.toolHost = runtimeOptions.toolHost;
171
+ this.batchStoreFactory = runtimeOptions.batchStoreFactory;
172
+ this.afterToolFreeze = runtimeOptions.afterToolFreeze;
171
173
  this.executionScope = runtimeOptions.executionScope ?? { id: crypto.randomUUID(), root: "" };
172
174
  this.onExecutionPipeline = runtimeOptions.onExecutionPipeline;
173
175
  this.removedToolHints = runtimeOptions.removedToolHints ?? {};
@@ -489,6 +491,8 @@ export class Agent {
489
491
  cursorExecHandlers: this.cursorExecHandlers,
490
492
  toolExecution: this.toolExecution,
491
493
  toolHost: this.toolHost,
494
+ batchStoreFactory: this.batchStoreFactory,
495
+ afterToolFreeze: this.afterToolFreeze,
492
496
  executionScope: this.getExecutionScope?.() ?? this.executionScope,
493
497
  onExecutionPipeline: this.onExecutionPipeline,
494
498
  removedToolHints: this.removedToolHints,
@@ -8,6 +8,7 @@ export type { SuiteHashEntry } from "./suite-hash.ts";
8
8
  export { computeSuiteHash, sha256Hex } from "./suite-hash.ts";
9
9
  export type { CommitResult, DurableStore, DurableStoreErrorCode, DurableStoreOptions, RecordScan, StoreDocument, StoreOperation, StoreRecord, StoreSnapshot, StoreValue, StoreWrite, StoreWritePoint, } from "../durable/store.ts";
10
10
  export { DurableStoreError } from "../durable/store.ts";
11
+ export type { AdmissionLine } from "../durable/store-admission.ts";
11
12
  export type { KillDeclaration } from "../durable/testing/kill-store.ts";
12
13
  export { KILL_STORE_CASES, KILL_STORE_DECLARATIONS } from "../durable/testing/kill-store.ts";
13
14
  export { STORE_CASES } from "../durable/testing/store-cases.ts";
@@ -44,10 +45,16 @@ export type { ExecutionLedger } from "../execution/ledger.ts";
44
45
  export type { ExecutionAdmission, ExecutionCommand, ExecutionEntry, ExecutionEvent, ExecutionKey, ExecutionOutcome, ExecutionProgress, FrozenCall, LedgerReply, } from "../execution/ledger-types.ts";
45
46
  export { LEDGER_CASES } from "../execution/testing/ledger-cases.ts";
46
47
  export { KILL_LEDGER_CASES, KILL_LEDGER_DECLARATIONS } from "../execution/testing/kill-ledger.ts";
48
+ export { EPOCH_CASES } from "../execution/testing/epoch-cases.ts";
47
49
  export { FAULT_HAND_CASES } from "../execution/testing/fault-hand-cases.ts";
48
50
  export type { HandCaseAdapters } from "../execution/testing/hand-harness.ts";
49
51
  export type { KillHandDeclaration } from "../execution/testing/kill-hand.ts";
50
52
  export { KILL_HAND_CASES, KILL_HAND_DECLARATIONS } from "../execution/testing/kill-hand.ts";
53
+ export type { KillEpochDeclaration } from "../execution/testing/kill-epoch.ts";
54
+ export { KILL_EPOCH_CASES, KILL_EPOCH_DECLARATIONS } from "../execution/testing/kill-epoch.ts";
55
+ export { MULTI_EPOCH_CASES } from "../execution/testing/multi-epoch-cases.ts";
56
+ export type { KillHookDeclaration } from "../execution/testing/kill-hook.ts";
57
+ export { KILL_HOOK_CASES, KILL_HOOK_DECLARATIONS } from "../execution/testing/kill-hook.ts";
51
58
  export { MULTI_HAND_CASES } from "../execution/testing/multi-hand-cases.ts";
52
59
  export type { KillLedgerDeclaration } from "../execution/testing/kill-ledger.ts";
53
60
  export type { BatchCoordinator, BatchCoordinatorOptions } from "../execution/coordinator.ts";
@@ -55,6 +62,29 @@ export { BatchManifestConflictError, createBatchCoordinator } from "../execution
55
62
  export { interruptedReplayText } from "../execution/coordinator-plan.ts";
56
63
  export type { BatchCallPlan, BatchDecision, BatchExecutor, BatchManifest, BatchPlan, BatchRecord, BatchResult, CallOutcome, ExecutionRef, ManifestCall, PrepareReply, PrepareRequest, SettleReply, } from "../execution/coordinator-types.ts";
57
64
  export { BATCH_CASES } from "../execution/testing/batch-cases.ts";
65
+ export type { SequentialCoordinator } from "../execution/coordinator-sequential.ts";
66
+ export { createSequentialCoordinator } from "../execution/coordinator-sequential.ts";
67
+ export { MULTI_SEQ_CASES } from "../execution/testing/multi-seq-cases.ts";
68
+ export { SEQ_CASES } from "../execution/testing/seq-cases.ts";
69
+ export { CONSENT_CASES } from "../execution/testing/consent-cases.ts";
70
+ export type { NestedAdmissionControl, NestedAdmissionOptions } from "../execution/nested.ts";
71
+ export { createNestedAdmission } from "../execution/nested.ts";
72
+ export { NEST_CASES } from "../execution/testing/nest-cases.ts";
73
+ export { CANCEL_CASES } from "../execution/testing/cancel-cases.ts";
74
+ export { KILL_NEST_CASES } from "../execution/testing/kill-nest.ts";
75
+ export type { WakeInbox, WakeInboxOptions } from "../execution/wake-inbox.ts";
76
+ export { createWakeInbox } from "../execution/wake-inbox.ts";
77
+ export type { WakeOutbox, WakeOutboxOptions } from "../execution/wake-outbox.ts";
78
+ export { createWakeOutbox } from "../execution/wake-outbox.ts";
79
+ export type { WakeEvent, WakeReceipt } from "../execution/wake-types.ts";
80
+ export { WAKE_RETENTION_MS } from "../execution/wake-types.ts";
81
+ export { WAKE_EXEC_CASES } from "../execution/testing/wake-exec-cases.ts";
82
+ export { KILL_WAKEX_CASES } from "../execution/testing/kill-wakex.ts";
83
+ export type { ScopeBinding, ScopeLifecycle, ScopeLifecycleOptions, ScopeRecord } from "../execution/scope-lifecycle.ts";
84
+ export { createScopeLifecycle } from "../execution/scope-lifecycle.ts";
85
+ export { LIFECYCLE_CASES } from "../execution/testing/lifecycle-cases.ts";
86
+ export { SCOPE_CASES } from "../execution/testing/scope-cases.ts";
87
+ export { MULTI_LIFECYCLE_CASES } from "../execution/testing/multi-lifecycle-cases.ts";
58
88
  export type { BatchCaseAdapters, BatchExecutorConformanceAdapter, ExecutorOpenOptions, PausePoint, } from "../execution/testing/batch-executor.ts";
59
89
  export { referenceBatchExecutor } from "../execution/testing/batch-executor.ts";
60
90
  export type { KillBatchDeclaration } from "../execution/testing/kill-batch.ts";
@@ -23,12 +23,33 @@ export { TransportClosedError } from "../transport/transport.js";
23
23
  export { createExecutionLedger } from "../execution/ledger.js";
24
24
  export { LEDGER_CASES } from "../execution/testing/ledger-cases.js";
25
25
  export { KILL_LEDGER_CASES, KILL_LEDGER_DECLARATIONS } from "../execution/testing/kill-ledger.js";
26
+ export { EPOCH_CASES } from "../execution/testing/epoch-cases.js";
26
27
  export { FAULT_HAND_CASES } from "../execution/testing/fault-hand-cases.js";
27
28
  export { KILL_HAND_CASES, KILL_HAND_DECLARATIONS } from "../execution/testing/kill-hand.js";
29
+ export { KILL_EPOCH_CASES, KILL_EPOCH_DECLARATIONS } from "../execution/testing/kill-epoch.js";
30
+ export { MULTI_EPOCH_CASES } from "../execution/testing/multi-epoch-cases.js";
31
+ export { KILL_HOOK_CASES, KILL_HOOK_DECLARATIONS } from "../execution/testing/kill-hook.js";
28
32
  export { MULTI_HAND_CASES } from "../execution/testing/multi-hand-cases.js";
29
33
  export { BatchManifestConflictError, createBatchCoordinator } from "../execution/coordinator.js";
30
34
  export { interruptedReplayText } from "../execution/coordinator-plan.js";
31
35
  export { BATCH_CASES } from "../execution/testing/batch-cases.js";
36
+ export { createSequentialCoordinator } from "../execution/coordinator-sequential.js";
37
+ export { MULTI_SEQ_CASES } from "../execution/testing/multi-seq-cases.js";
38
+ export { SEQ_CASES } from "../execution/testing/seq-cases.js";
39
+ export { CONSENT_CASES } from "../execution/testing/consent-cases.js";
40
+ export { createNestedAdmission } from "../execution/nested.js";
41
+ export { NEST_CASES } from "../execution/testing/nest-cases.js";
42
+ export { CANCEL_CASES } from "../execution/testing/cancel-cases.js";
43
+ export { KILL_NEST_CASES } from "../execution/testing/kill-nest.js";
44
+ export { createWakeInbox } from "../execution/wake-inbox.js";
45
+ export { createWakeOutbox } from "../execution/wake-outbox.js";
46
+ export { WAKE_RETENTION_MS } from "../execution/wake-types.js";
47
+ export { WAKE_EXEC_CASES } from "../execution/testing/wake-exec-cases.js";
48
+ export { KILL_WAKEX_CASES } from "../execution/testing/kill-wakex.js";
49
+ export { createScopeLifecycle } from "../execution/scope-lifecycle.js";
50
+ export { LIFECYCLE_CASES } from "../execution/testing/lifecycle-cases.js";
51
+ export { SCOPE_CASES } from "../execution/testing/scope-cases.js";
52
+ export { MULTI_LIFECYCLE_CASES } from "../execution/testing/multi-lifecycle-cases.js";
32
53
  export { referenceBatchExecutor } from "../execution/testing/batch-executor.js";
33
54
  export { KILL_BATCH_CASES, KILL_BATCH_DECLARATIONS } from "../execution/testing/kill-batch.js";
34
55
  //# 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", "execution/canonical-digest.ts", "execution/coordinator.ts", "execution/coordinator-codec.ts", "execution/coordinator-consent.ts", "execution/coordinator-plan.ts", "execution/coordinator-types.ts", "execution/ledger.ts", "execution/ledger-codec.ts", "execution/ledger-transition.ts", "execution/ledger-types.ts", "execution/prepared/executor.ts", "execution/prepared/executor-body.ts", "execution/prepared/executor-freeze.ts", "execution/prepared/executor-pipeline.ts", "execution/prepared/executor-types.ts", "execution/prepared/pipeline-prepared.ts", "execution/prepared/pipeline-prepared-batch.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.
@@ -19,6 +19,24 @@ export const LOOP_CORE_MODULES = [
19
19
  "types.ts",
20
20
  "durable/store.ts",
21
21
  "execution/tool-host.ts",
22
+ "execution/tool-outcome-events.ts",
23
+ "execution/canonical-digest.ts",
24
+ "execution/coordinator.ts",
25
+ "execution/coordinator-codec.ts",
26
+ "execution/coordinator-consent.ts",
27
+ "execution/coordinator-plan.ts",
28
+ "execution/coordinator-types.ts",
29
+ "execution/ledger.ts",
30
+ "execution/ledger-codec.ts",
31
+ "execution/ledger-transition.ts",
32
+ "execution/ledger-types.ts",
33
+ "execution/prepared/executor.ts",
34
+ "execution/prepared/executor-body.ts",
35
+ "execution/prepared/executor-freeze.ts",
36
+ "execution/prepared/executor-pipeline.ts",
37
+ "execution/prepared/executor-types.ts",
38
+ "execution/prepared/pipeline-prepared.ts",
39
+ "execution/prepared/pipeline-prepared-batch.ts",
22
40
  "durable/store-admission.ts",
23
41
  "durable/wake-host.ts",
24
42
  "transport/transport.ts",
@@ -1,6 +1,12 @@
1
- import { KILL_HAND_DECLARATIONS } from "../execution/testing/kill-hand.js";
1
+ import { EPOCH_REGISTRY } from "../execution/testing/epoch-registry.js";
2
+ import { HAND_REGISTRY } from "../execution/testing/hand-registry.js";
3
+ import { KILL_HOOK_DECLARATIONS } from "../execution/testing/kill-hook.js";
2
4
  import { BATCH_REGISTRY } from "../execution/testing/batch-registry.js";
3
5
  import { LEDGER_REGISTRY } from "../execution/testing/ledger-registry.js";
6
+ import { LIFECYCLE_REGISTRY } from "../execution/testing/lifecycle-registry.js";
7
+ import { NEST_REGISTRY } from "../execution/testing/nest-registry.js";
8
+ import { WAKE_EXEC_REGISTRY } from "../execution/testing/wake-registry.js";
9
+ import { SEQ_REGISTRY } from "../execution/testing/seq-registry.js";
4
10
  export const ADAPTER_KINDS = ["store", "wake", "transport", "executor", "host"];
5
11
  /**
6
12
  * Every case of the durable-core conformance suite (packages/agent/docs/durable-core-adr.md). A change that adds cases
@@ -29,24 +35,14 @@ const wakeCase = (id, impl, expected) => ({
29
35
  adapters: ["store", "wake"],
30
36
  expected,
31
37
  });
32
- const HAND_INTRO = "#5482";
33
- const handCase = (id, impl, expected) => ({
38
+ const KILL_HOOK_IMPL = "packages/agent/src/execution/testing/kill-hook.ts";
39
+ const HOOK_REGISTRY = KILL_HOOK_DECLARATIONS.map(({ id, expected }) => ({
34
40
  id,
35
- impl,
36
- intro: HAND_INTRO,
37
- adapters: ["store", "transport", "executor"],
41
+ impl: KILL_HOOK_IMPL,
42
+ intro: "#5726",
43
+ adapters: ["transport", "executor"],
38
44
  expected,
39
- });
40
- const KILL_HAND_IMPL = "packages/agent/src/execution/testing/kill-hand.ts";
41
- const MULTI_HAND_IMPL = "packages/agent/src/execution/testing/multi-hand-cases.ts";
42
- const FAULT_HAND_IMPL = "packages/agent/src/execution/testing/fault-hand-cases.ts";
43
- const HAND_REGISTRY = [
44
- ...KILL_HAND_DECLARATIONS.map(({ id, expected }) => handCase(id, KILL_HAND_IMPL, expected)),
45
- handCase("MULTI-HAND-01", MULTI_HAND_IMPL, "N scopes batch at once on one hand; each scope's calls start in lane order"),
46
- handCase("MULTI-KILL-01", MULTI_HAND_IMPL, "cross-machine: a hand killed with several scopes in flight; each ends hand_restarted, uncertain, never rerun"),
47
- ...["slow", "lossy", "laggy", "flap", "drop-reattach"].map((profile, index) => handCase(`FAULT-HAND-0${index + 1}`, FAULT_HAND_IMPL, `${profile} profile: every call settles with its unfaulted result, runs once, per-scope order kept`)),
48
- handCase("FAULT-HAND-MULTI-01", FAULT_HAND_IMPL, "hand unreachable past the resume window: dependent calls pause, then each scope resumes exactly once"),
49
- ];
45
+ }));
50
46
  const storeCase = (id, impl, expected) => ({
51
47
  id,
52
48
  impl,
@@ -57,6 +53,10 @@ const storeCase = (id, impl, expected) => ({
57
53
  export const CONFORMANCE_REGISTRY = [
58
54
  ...LEDGER_REGISTRY,
59
55
  ...BATCH_REGISTRY,
56
+ ...SEQ_REGISTRY,
57
+ ...NEST_REGISTRY,
58
+ ...WAKE_EXEC_REGISTRY,
59
+ ...LIFECYCLE_REGISTRY,
60
60
  storeCase("STORE-01", STORE_CASES_IMPL, "a commit adopts once, after its batch is durable; every instance sees each batch whole"),
61
61
  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
62
  storeCase("STORE-03", STORE_CASES_IMPL, "concurrent admissions run one at a time in admission order; a refused mutation releases the line"),
@@ -88,12 +88,14 @@ export const CONFORMANCE_REGISTRY = [
88
88
  transportCase("TRANSPORT-03", TRANSPORT_CASES_IMPL, "backpressure: a stalled receiver bounds its lane's senders; sends resolve in order once it drains"),
89
89
  transportCase("MULTI-LANE-01", MULTI_CASES_IMPL, "N scopes over one transport keep per-scope order and interleave"),
90
90
  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-02", 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"),
91
+ 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
92
  faultCase(1, "slow"),
93
93
  faultCase(2, "lossy"),
94
94
  faultCase(3, "laggy"),
95
95
  faultCase(4, "flap"),
96
96
  faultCase(5, "drop-reattach"),
97
97
  ...HAND_REGISTRY,
98
+ ...EPOCH_REGISTRY,
99
+ ...HOOK_REGISTRY,
98
100
  ];
99
101
  //# sourceMappingURL=registry.js.map
@@ -0,0 +1,102 @@
1
+ /**
2
+ * `ModelEgress`: one provider-pipeline layer that decides, per provider and per request, whether a model call
3
+ * is dialed directly (today's stream function, unchanged), with secrets released from sealed custody, or
4
+ * through a device the user owns. Only types and constants live here; implementations live with the
5
+ * provider pipeline, and the fused path passes today's stream function through untouched.
6
+ */
7
+ import type { StreamFn } from "../types.ts";
8
+ export type ProviderId = string;
9
+ export type DeviceId = string;
10
+ export type Epoch = number;
11
+ export type EgressRoute = "direct" | "sealed" | "device";
12
+ export type RouteReason = "fused" | "custody:sealed" | "custody:device" | "roster:unknown" | "custody:cwd-scoped" | "custody:unavailable" | "owner:revoked" | "definition:variant" | "address:private" | "address:self" | "address:unknown" | "capability:local-only" | "capability:ambient" | "capability:callback-stream" | "capability:callback-stream-undefined" | "api:no-fetch-injection" | "network:device-bound" | "provider:extension" | "provider:hand-local" | "provider:unknown" | "hook:stream" | "hook:stream-undefined" | "hook:unknown" | "hook:request-offline" | "redirect:cross-origin";
13
+ export type WaitCondition = {
14
+ readonly kind: "device-online";
15
+ readonly deviceId: DeviceId;
16
+ } | {
17
+ readonly kind: "custody-available";
18
+ } | {
19
+ readonly kind: "refresh-ack";
20
+ readonly providerId: ProviderId;
21
+ } | {
22
+ readonly kind: "roster-sync";
23
+ } | {
24
+ readonly kind: "hand-selected";
25
+ } | {
26
+ readonly kind: "hand-advertised";
27
+ readonly deviceId: DeviceId;
28
+ } | {
29
+ readonly kind: "config-head-change";
30
+ } | {
31
+ readonly kind: "live-digest-change";
32
+ readonly deviceId: DeviceId;
33
+ readonly providerId: ProviderId;
34
+ } | {
35
+ readonly kind: "storage-available";
36
+ } | {
37
+ readonly kind: "epoch-fresh";
38
+ } | {
39
+ readonly kind: "claim-renewed";
40
+ } | {
41
+ readonly kind: "user-choice";
42
+ readonly choiceId: string;
43
+ };
44
+ export interface EgressRouteDecision {
45
+ readonly route: EgressRoute;
46
+ readonly reason: RouteReason;
47
+ readonly deviceId?: DeviceId;
48
+ /** False: the call waits in the stream (never fails) until `waitFor` holds, showing `steer`. */
49
+ readonly servedNow: boolean;
50
+ readonly steer?: string;
51
+ readonly waitFor?: readonly WaitCondition[];
52
+ readonly requestHooksOn?: DeviceId;
53
+ readonly executorHooks?: "enabled" | "disabled";
54
+ readonly serveOwnDefinition?: true;
55
+ }
56
+ /** The durable admission fence; `generation` is the agent instance generation, and older generations are refused for good. */
57
+ export interface AdmissionFence {
58
+ readonly epoch: Epoch;
59
+ readonly admissionSeq: number;
60
+ readonly generation: number;
61
+ }
62
+ export interface StepRef {
63
+ readonly kind: "step";
64
+ readonly sessionId: string;
65
+ readonly stepId: string;
66
+ readonly attempt: number;
67
+ readonly fence: AdmissionFence;
68
+ }
69
+ export interface AuxRef {
70
+ readonly kind: "aux";
71
+ readonly sessionId: string;
72
+ readonly auxId: string;
73
+ readonly auxKey: string;
74
+ readonly streamKind: string;
75
+ readonly fence: AdmissionFence;
76
+ }
77
+ export type CallRef = StepRef | AuxRef;
78
+ export interface EgressWait {
79
+ readonly call: CallRef;
80
+ readonly reason: RouteReason | "device-offline" | "result-pending" | "refresh-pending" | "config-churn" | "epoch-stale" | "claim-expired";
81
+ readonly steer: string;
82
+ readonly waitFor: readonly WaitCondition[];
83
+ }
84
+ export interface EgressHostHooks {
85
+ currentStep(): StepRef;
86
+ admitAux(streamKind: string, auxKey: string): Promise<AuxRef>;
87
+ onWait(wait: EgressWait): Promise<void>;
88
+ onWaitEnd(callId: string): Promise<void>;
89
+ historyHasStep(stepId: string): Promise<boolean>;
90
+ }
91
+ /** Bound from a hosted session latching on a failed step commit to its rebuilt instance accepting work. */
92
+ export declare const HOSTED_REBUILD_DEADLINE_MS = 5000;
93
+ /** Maximum age of a registry epoch check accepted for a secret release, a step commit or a tool dispatch. */
94
+ export declare const EPOCH_FRESHNESS_MS = 5000;
95
+ /** Margin a new placement owner waits beyond `EPOCH_FRESHNESS_MS` before cutting over a moved session. */
96
+ export declare const MOVE_SKEW_MS = 2000;
97
+ export interface ModelEgress {
98
+ /** Pure and cheap: no I/O, safe to call from UI code. */
99
+ routeFor(providerId: ProviderId): EgressRouteDecision;
100
+ readonly stream: StreamFn;
101
+ }
102
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,7 @@
1
+ /** Bound from a hosted session latching on a failed step commit to its rebuilt instance accepting work. */
2
+ export const HOSTED_REBUILD_DEADLINE_MS = 5_000;
3
+ /** Maximum age of a registry epoch check accepted for a secret release, a step commit or a tool dispatch. */
4
+ export const EPOCH_FRESHNESS_MS = 5_000;
5
+ /** Margin a new placement owner waits beyond `EPOCH_FRESHNESS_MS` before cutting over a moved session. */
6
+ export const MOVE_SKEW_MS = 2_000;
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,10 @@
1
+ import type { StoreValue } from "../durable/store.ts";
2
+ /**
3
+ * The canonical JSON of a store value: object keys sorted by UTF-16 code unit, no whitespace. Every execution digest
4
+ * (a batch manifest, a call's request, a frozen call, a tool schema) hashes this form, so two sides that build the same
5
+ * value agree on its digest.
6
+ */
7
+ export declare function canonicalJson(value: StoreValue): string;
8
+ /** Lower-case hex SHA-256 of {@link canonicalJson}, through Web Crypto so the agent loop stays browser-safe. */
9
+ export declare function canonicalDigest(value: StoreValue): Promise<string>;
10
+ //# sourceMappingURL=canonical-digest.d.ts.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The canonical JSON of a store value: object keys sorted by UTF-16 code unit, no whitespace. Every execution digest
3
+ * (a batch manifest, a call's request, a frozen call, a tool schema) hashes this form, so two sides that build the same
4
+ * value agree on its digest.
5
+ */
6
+ export function canonicalJson(value) {
7
+ if (Array.isArray(value))
8
+ return `[${value.map(canonicalJson).join(",")}]`;
9
+ if (value !== null && typeof value === "object") {
10
+ const entries = Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
11
+ return `{${entries.map(([key, inner]) => `${JSON.stringify(key)}:${canonicalJson(inner)}`).join(",")}}`;
12
+ }
13
+ return JSON.stringify(value);
14
+ }
15
+ /** Lower-case hex SHA-256 of {@link canonicalJson}, through Web Crypto so the agent loop stays browser-safe. */
16
+ export async function canonicalDigest(value) {
17
+ const bytes = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonicalJson(value)));
18
+ return Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
19
+ }
20
+ //# sourceMappingURL=canonical-digest.js.map
@@ -0,0 +1,3 @@
1
+ /** JSON with object keys sorted, so two values with the same fields compare equal whatever their key order. */
2
+ export declare function canonicalJson(value: unknown): string;
3
+ //# sourceMappingURL=canonical-json.d.ts.map
@@ -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