@code-yeongyu/senpi-agent-core 2026.11.4-2 → 2026.11.6-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 (111) hide show
  1. package/dist/agent-loop.js +14 -140
  2. package/dist/agent.d.ts +4 -0
  3. package/dist/agent.js +4 -0
  4. package/dist/conformance/index.d.ts +12 -1
  5. package/dist/conformance/index.js +6 -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 +11 -17
  9. package/dist/durable/session-store.d.ts +42 -0
  10. package/dist/durable/session-store.js +124 -0
  11. package/dist/durable/store-memory.d.ts +2 -2
  12. package/dist/durable/store-memory.js +36 -34
  13. package/dist/durable/store.d.ts +9 -0
  14. package/dist/durable/testing/store-harness.d.ts +1 -0
  15. package/dist/durable/testing/store-harness.js +1 -0
  16. package/dist/durable/testing/sync-commit-cases.d.ts +20 -0
  17. package/dist/durable/testing/sync-commit-cases.js +89 -0
  18. package/dist/egress/types.d.ts +102 -0
  19. package/dist/egress/types.js +7 -0
  20. package/dist/execution/canonical-digest.d.ts +10 -0
  21. package/dist/execution/canonical-digest.js +20 -0
  22. package/dist/execution/chain-count.d.ts +26 -0
  23. package/dist/execution/chain-count.js +45 -0
  24. package/dist/execution/coordinator-plan.d.ts +1 -2
  25. package/dist/execution/coordinator-plan.js +4 -17
  26. package/dist/execution/device-files-node.js +40 -1
  27. package/dist/execution/device-files.d.ts +39 -1
  28. package/dist/execution/device-files.js +48 -1
  29. package/dist/execution/ledger-types.d.ts +3 -1
  30. package/dist/execution/ledger.d.ts +9 -3
  31. package/dist/execution/ledger.js +8 -2
  32. package/dist/execution/loop-hook-host-hand.d.ts +33 -0
  33. package/dist/execution/loop-hook-host-hand.js +71 -0
  34. package/dist/execution/loop-hook-host-protocol.d.ts +46 -0
  35. package/dist/execution/loop-hook-host-protocol.js +47 -0
  36. package/dist/execution/loop-hook-host.d.ts +40 -0
  37. package/dist/execution/loop-hook-host.js +87 -0
  38. package/dist/execution/plane-session.d.ts +56 -0
  39. package/dist/execution/plane-session.js +178 -0
  40. package/dist/execution/plane.d.ts +5 -2
  41. package/dist/execution/plane.js +1 -1
  42. package/dist/execution/prepared/executor-body.d.ts +22 -0
  43. package/dist/execution/prepared/executor-body.js +73 -0
  44. package/dist/execution/prepared/executor-freeze.d.ts +22 -0
  45. package/dist/execution/prepared/executor-freeze.js +55 -0
  46. package/dist/execution/prepared/executor-pipeline.d.ts +11 -0
  47. package/dist/execution/prepared/executor-pipeline.js +26 -0
  48. package/dist/execution/prepared/executor-types.d.ts +131 -0
  49. package/dist/execution/prepared/executor-types.js +2 -0
  50. package/dist/execution/prepared/executor.d.ts +8 -0
  51. package/dist/execution/prepared/executor.js +260 -0
  52. package/dist/execution/prepared/memory-batch-store.d.ts +4 -0
  53. package/dist/execution/prepared/memory-batch-store.js +4 -0
  54. package/dist/execution/prepared/pipeline-prepared-batch.d.ts +27 -0
  55. package/dist/execution/prepared/pipeline-prepared-batch.js +175 -0
  56. package/dist/execution/prepared/pipeline-prepared.d.ts +10 -0
  57. package/dist/execution/prepared/pipeline-prepared.js +54 -0
  58. package/dist/execution/remote-device-files.js +33 -4
  59. package/dist/execution/remote-epoch-gate.d.ts +19 -0
  60. package/dist/execution/remote-epoch-gate.js +46 -0
  61. package/dist/execution/remote-epoch.d.ts +53 -0
  62. package/dist/execution/remote-epoch.js +74 -0
  63. package/dist/execution/remote-executor.d.ts +8 -1
  64. package/dist/execution/remote-executor.js +24 -6
  65. package/dist/execution/remote-file-call.js +1 -0
  66. package/dist/execution/remote-hand-ledger.d.ts +11 -3
  67. package/dist/execution/remote-hand-ledger.js +31 -15
  68. package/dist/execution/remote-link.d.ts +6 -1
  69. package/dist/execution/remote-link.js +50 -14
  70. package/dist/execution/remote-protocol.d.ts +30 -1
  71. package/dist/execution/remote-protocol.js +30 -0
  72. package/dist/execution/remote-tool-host.d.ts +12 -0
  73. package/dist/execution/remote-tool-host.js +3 -1
  74. package/dist/execution/testing/epoch-cases.d.ts +8 -0
  75. package/dist/execution/testing/epoch-cases.js +84 -0
  76. package/dist/execution/testing/epoch-harness.d.ts +47 -0
  77. package/dist/execution/testing/epoch-harness.js +172 -0
  78. package/dist/execution/testing/epoch-registry.d.ts +3 -0
  79. package/dist/execution/testing/epoch-registry.js +17 -0
  80. package/dist/execution/testing/hand-harness.d.ts +5 -0
  81. package/dist/execution/testing/hand-harness.js +57 -24
  82. package/dist/execution/testing/hand-registry.d.ts +3 -0
  83. package/dist/execution/testing/hand-registry.js +20 -0
  84. package/dist/execution/testing/kill-epoch.d.ts +9 -0
  85. package/dist/execution/testing/kill-epoch.js +71 -0
  86. package/dist/execution/testing/kill-hook.d.ts +14 -0
  87. package/dist/execution/testing/kill-hook.js +117 -0
  88. package/dist/execution/testing/multi-epoch-cases.d.ts +4 -0
  89. package/dist/execution/testing/multi-epoch-cases.js +29 -0
  90. package/dist/execution/testing/multi-hand-cases.js +1 -1
  91. package/dist/execution/tool-host.d.ts +16 -1
  92. package/dist/execution/tool-host.js +18 -1
  93. package/dist/harness/agent-harness.d.ts +6 -0
  94. package/dist/harness/execution/tool-host-call.d.ts +14 -0
  95. package/dist/harness/execution/tool-host-call.js +56 -0
  96. package/dist/harness/execution/tools.d.ts +2 -1
  97. package/dist/harness/execution/tools.js +45 -17
  98. package/dist/harness/runtime/drive/tools.js +1 -1
  99. package/dist/harness/runtime/harness.js +1 -0
  100. package/dist/harness/runtime/types.d.ts +1 -0
  101. package/dist/harness/tools/read.js +1 -1
  102. package/dist/index.d.ts +19 -2
  103. package/dist/index.js +15 -1
  104. package/dist/public-entry.d.ts +10 -0
  105. package/dist/public-entry.js +23 -0
  106. package/dist/step-commit.d.ts +24 -0
  107. package/dist/step-commit.js +24 -0
  108. package/dist/tool-name-alias.d.ts +1 -7
  109. package/dist/tool-name-alias.js +0 -17
  110. package/dist/types.d.ts +37 -1
  111. package/package.json +3 -3
@@ -9,8 +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";
13
- import { createErrorToolResult, createToolResultMessage, emitToolExecutionEnd, emitToolExecutionUpdate, emitToolResultMessage, shouldTerminateToolBatch, } from "./execution/tool-outcome-events.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";
14
16
  /**
15
17
  * Start an agent loop with a new prompt message.
16
18
  * The prompt is added to the context and events are emitted for it.
@@ -208,6 +210,8 @@ async function runLoop(initialContext, newMessages, initialConfig, signal, emit,
208
210
  newMessages.push(result);
209
211
  toolResults.push(result);
210
212
  }
213
+ if (config.commitStep)
214
+ await config.commitStep({ message, providerToolResults });
211
215
  if (shouldTerminateAssistantTurn(message)) {
212
216
  // Hard exit: the decision is ignored, but the hook still sees the finished turn before turn_end.
213
217
  await config.finishTurn?.({ message, toolResults, context: currentContext, newMessages }, signal);
@@ -926,23 +930,7 @@ async function executeToolCalls(currentContext, assistantMessage, config, signal
926
930
  // channel and its result buffered; running it again would duplicate a
927
931
  // side-effecting tool.
928
932
  const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall" && !isCursorExecResolved(c));
929
- const host = config.toolHost ?? {
930
- execute: async (call, options) => {
931
- // Only yield when a witness sink is configured and returns a promise: an unconditional `await` adds a
932
- // microtask per call and reorders lifecycle vs message events against today's fused path (EQ E03).
933
- const recordWitness = options.recordWitness;
934
- if (recordWitness) {
935
- for (const raw of call.calls) {
936
- const pending = recordWitness({ pipeline: "legacy", toolCallId: raw.id });
937
- if (pending)
938
- await pending;
939
- }
940
- }
941
- return call.mode === "sequential"
942
- ? executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, options.signal, options.emit)
943
- : executeToolCallsParallel(currentContext, assistantMessage, toolCalls, config, options.signal, options.emit);
944
- },
945
- };
933
+ const host = config.toolHost ?? defaultToolHost();
946
934
  return host.execute({
947
935
  scope: config.executionScope ?? { id: crypto.randomUUID(), root: "" },
948
936
  calls: toolCalls,
@@ -953,128 +941,14 @@ async function executeToolCalls(currentContext, assistantMessage, config, signal
953
941
  recordWitness: config.onExecutionPipeline,
954
942
  local: { context: currentContext, assistantMessage },
955
943
  });
956
- }
957
- async function executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit) {
958
- const finalizedCalls = [];
959
- const messages = [];
960
- for (const toolCall of toolCalls) {
961
- const tool = await resolveCallTool(currentContext, toolCall, config);
962
- await emit({
963
- type: "tool_execution_start",
964
- toolCallId: toolCall.id,
965
- toolName: tool?.name ?? toolCall.name,
966
- args: toolCall.arguments,
967
- });
968
- const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, tool, config, signal);
969
- let finalized;
970
- if (preparation.kind === "immediate") {
971
- finalized = {
972
- toolCall: preparation.toolCall,
973
- result: preparation.result,
974
- isError: preparation.isError,
975
- };
976
- }
977
- else {
978
- const executed = await executePreparedToolCall(preparation, signal, emitToolExecutionUpdate(preparation.toolCall, emit));
979
- finalized = await finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
980
- }
981
- await emitToolExecutionEnd(finalized, emit);
982
- const toolResultMessage = createToolResultMessage(finalized);
983
- await emitToolResultMessage(toolResultMessage, emit);
984
- finalizedCalls.push(finalized);
985
- messages.push(toolResultMessage);
986
- if (signal?.aborted) {
987
- break;
988
- }
989
- }
990
- return {
991
- messages,
992
- terminate: shouldTerminateToolBatch(finalizedCalls),
993
- };
994
- }
995
- async function executeToolCallsParallel(currentContext, assistantMessage, toolCalls, config, signal, emit) {
996
- const finalizedCalls = [];
997
- const preparedCalls = [];
998
- let lastSequentialCall;
999
- let currentParallelWave = [];
1000
- for (const toolCall of toolCalls) {
1001
- const tool = await resolveCallTool(currentContext, toolCall, config);
1002
- await emit({
1003
- type: "tool_execution_start",
1004
- toolCallId: toolCall.id,
1005
- toolName: tool?.name ?? toolCall.name,
1006
- args: toolCall.arguments,
1007
- });
1008
- const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, tool, config, signal);
1009
- const isSequential = isSequentialToolCall(currentContext, preparation.toolCall);
1010
- const dependencies = isSequential
1011
- ? [...(lastSequentialCall ? [lastSequentialCall] : []), ...currentParallelWave]
1012
- : lastSequentialCall
1013
- ? [lastSequentialCall]
1014
- : [];
1015
- preparedCalls.push({ preparation, isSequential, dependencies });
1016
- if (isSequential) {
1017
- // Dependencies are assigned in the second phase after all preflight hooks
1018
- // have completed, so a later preflight abort vetoes every execution.
1019
- lastSequentialCall = undefined;
1020
- currentParallelWave = [];
1021
- }
1022
- else {
1023
- currentParallelWave.push(Promise.resolve(undefined));
1024
- }
1025
- if (signal?.aborted) {
1026
- break;
1027
- }
1028
- }
1029
- let previousSequential;
1030
- let previousWave = [];
1031
- for (const { preparation, isSequential } of preparedCalls) {
1032
- const dependencies = isSequential
1033
- ? [...(previousSequential ? [previousSequential] : []), ...previousWave]
1034
- : previousSequential
1035
- ? [previousSequential]
1036
- : [];
1037
- const finalizedCall = (async () => {
1038
- await Promise.all(dependencies);
1039
- const finalized = signal?.aborted
1040
- ? { toolCall: preparation.toolCall, result: createErrorToolResult("Operation aborted"), isError: true }
1041
- : await runPreparedToolCall(currentContext, assistantMessage, preparation, config, signal, emit);
1042
- await emitToolExecutionEnd(finalized, emit);
1043
- return finalized;
1044
- })();
1045
- finalizedCalls.push(finalizedCall);
1046
- if (isSequential) {
1047
- previousSequential = finalizedCall;
1048
- previousWave = [];
1049
- }
1050
- else
1051
- previousWave.push(finalizedCall);
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);
1052
951
  }
1053
- const orderedFinalizedCalls = await Promise.all(finalizedCalls);
1054
- const messages = [];
1055
- for (const finalized of orderedFinalizedCalls) {
1056
- const toolResultMessage = createToolResultMessage(finalized);
1057
- await emitToolResultMessage(toolResultMessage, emit);
1058
- messages.push(toolResultMessage);
1059
- }
1060
- return {
1061
- messages,
1062
- terminate: shouldTerminateToolBatch(orderedFinalizedCalls),
1063
- };
1064
- }
1065
- async function runPreparedToolCall(currentContext, assistantMessage, preparation, config, signal, emit) {
1066
- if (preparation.kind === "immediate") {
1067
- return {
1068
- toolCall: preparation.toolCall,
1069
- result: preparation.result,
1070
- isError: preparation.isError,
1071
- };
1072
- }
1073
- const executed = await executePreparedToolCall(preparation, signal, emitToolExecutionUpdate(preparation.toolCall, emit));
1074
- return finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
1075
- }
1076
- function isSequentialToolCall(currentContext, toolCall) {
1077
- return currentContext.tools?.find((tool) => tool.name === toolCall.name)?.executionMode === "sequential";
1078
952
  }
1079
953
  export { prepareAgentToolCallArguments };
1080
954
  export function prepareAgentToolCall(tool, toolCall) {
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,
@@ -6,12 +6,17 @@ export type { CaseImplementation, CaseResult, ConformanceHost, HostReport } from
6
6
  export { runSuite } from "./runner.ts";
7
7
  export type { SuiteHashEntry } from "./suite-hash.ts";
8
8
  export { computeSuiteHash, sha256Hex } from "./suite-hash.ts";
9
- export type { CommitResult, DurableStore, DurableStoreErrorCode, DurableStoreOptions, RecordScan, StoreDocument, StoreOperation, StoreRecord, StoreSnapshot, StoreValue, StoreWrite, StoreWritePoint, } from "../durable/store.ts";
9
+ export type { CommitResult, DurableStore, DurableStoreErrorCode, DurableStoreOptions, RecordScan, StoreDocument, StoreOperation, StoreRecord, StoreSnapshot, StoreValue, StoreWrite, StoreWritePoint, SyncCommit, SyncCommitStore, } from "../durable/store.ts";
10
10
  export { DurableStoreError } from "../durable/store.ts";
11
+ export type { SessionHandle, SessionHeader, SessionStoreErrorCode, StoredEntry, StoredSession, SyncSessionHandle, } from "../durable/session-store.ts";
12
+ export { openSessionStore, openSyncSessionStore, SessionStoreError } from "../durable/session-store.ts";
13
+ export type { AdmissionLine } from "../durable/store-admission.ts";
11
14
  export type { KillDeclaration } from "../durable/testing/kill-store.ts";
12
15
  export { KILL_STORE_CASES, KILL_STORE_DECLARATIONS } from "../durable/testing/kill-store.ts";
13
16
  export { STORE_CASES } from "../durable/testing/store-cases.ts";
14
17
  export type { StoreCaseAdapters, StoreConformanceAdapter } from "../durable/testing/store-harness.ts";
18
+ export type { SyncCommitCaseAdapters, SyncCommitConformanceAdapter } from "../durable/testing/sync-commit-cases.ts";
19
+ export { SYNC_COMMIT_CASES, SYNC_COMMIT_REGISTRY } from "../durable/testing/sync-commit-cases.ts";
15
20
  export type { KillWakeDeclaration } from "../durable/testing/kill-wake.ts";
16
21
  export { KILL_WAKE_CASES, KILL_WAKE_DECLARATIONS } from "../durable/testing/kill-wake.ts";
17
22
  export type { ManualTimers } from "../durable/testing/manual-timers.ts";
@@ -44,10 +49,16 @@ export type { ExecutionLedger } from "../execution/ledger.ts";
44
49
  export type { ExecutionAdmission, ExecutionCommand, ExecutionEntry, ExecutionEvent, ExecutionKey, ExecutionOutcome, ExecutionProgress, FrozenCall, LedgerReply, } from "../execution/ledger-types.ts";
45
50
  export { LEDGER_CASES } from "../execution/testing/ledger-cases.ts";
46
51
  export { KILL_LEDGER_CASES, KILL_LEDGER_DECLARATIONS } from "../execution/testing/kill-ledger.ts";
52
+ export { EPOCH_CASES } from "../execution/testing/epoch-cases.ts";
47
53
  export { FAULT_HAND_CASES } from "../execution/testing/fault-hand-cases.ts";
48
54
  export type { HandCaseAdapters } from "../execution/testing/hand-harness.ts";
49
55
  export type { KillHandDeclaration } from "../execution/testing/kill-hand.ts";
50
56
  export { KILL_HAND_CASES, KILL_HAND_DECLARATIONS } from "../execution/testing/kill-hand.ts";
57
+ export type { KillEpochDeclaration } from "../execution/testing/kill-epoch.ts";
58
+ export { KILL_EPOCH_CASES, KILL_EPOCH_DECLARATIONS } from "../execution/testing/kill-epoch.ts";
59
+ export { MULTI_EPOCH_CASES } from "../execution/testing/multi-epoch-cases.ts";
60
+ export type { KillHookDeclaration } from "../execution/testing/kill-hook.ts";
61
+ export { KILL_HOOK_CASES, KILL_HOOK_DECLARATIONS } from "../execution/testing/kill-hook.ts";
51
62
  export { MULTI_HAND_CASES } from "../execution/testing/multi-hand-cases.ts";
52
63
  export type { KillLedgerDeclaration } from "../execution/testing/kill-ledger.ts";
53
64
  export type { BatchCoordinator, BatchCoordinatorOptions } from "../execution/coordinator.ts";
@@ -3,8 +3,10 @@ export { ADAPTER_KINDS, CONFORMANCE_REGISTRY } from "./registry.js";
3
3
  export { runSuite } from "./runner.js";
4
4
  export { computeSuiteHash, sha256Hex } from "./suite-hash.js";
5
5
  export { DurableStoreError } from "../durable/store.js";
6
+ export { openSessionStore, openSyncSessionStore, SessionStoreError } from "../durable/session-store.js";
6
7
  export { KILL_STORE_CASES, KILL_STORE_DECLARATIONS } from "../durable/testing/kill-store.js";
7
8
  export { STORE_CASES } from "../durable/testing/store-cases.js";
9
+ export { SYNC_COMMIT_CASES, SYNC_COMMIT_REGISTRY } from "../durable/testing/sync-commit-cases.js";
8
10
  export { KILL_WAKE_CASES, KILL_WAKE_DECLARATIONS } from "../durable/testing/kill-wake.js";
9
11
  export { createManualTimers } from "../durable/testing/manual-timers.js";
10
12
  export { MULTI_HOST_CASES } from "../durable/testing/multi-host-cases.js";
@@ -23,8 +25,12 @@ export { TransportClosedError } from "../transport/transport.js";
23
25
  export { createExecutionLedger } from "../execution/ledger.js";
24
26
  export { LEDGER_CASES } from "../execution/testing/ledger-cases.js";
25
27
  export { KILL_LEDGER_CASES, KILL_LEDGER_DECLARATIONS } from "../execution/testing/kill-ledger.js";
28
+ export { EPOCH_CASES } from "../execution/testing/epoch-cases.js";
26
29
  export { FAULT_HAND_CASES } from "../execution/testing/fault-hand-cases.js";
27
30
  export { KILL_HAND_CASES, KILL_HAND_DECLARATIONS } from "../execution/testing/kill-hand.js";
31
+ export { KILL_EPOCH_CASES, KILL_EPOCH_DECLARATIONS } from "../execution/testing/kill-epoch.js";
32
+ export { MULTI_EPOCH_CASES } from "../execution/testing/multi-epoch-cases.js";
33
+ export { KILL_HOOK_CASES, KILL_HOOK_DECLARATIONS } from "../execution/testing/kill-hook.js";
28
34
  export { MULTI_HAND_CASES } from "../execution/testing/multi-hand-cases.js";
29
35
  export { BatchManifestConflictError, createBatchCoordinator } from "../execution/coordinator.js";
30
36
  export { interruptedReplayText } from "../execution/coordinator-plan.js";
@@ -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", "execution/tool-outcome-events.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/device-files.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,7 +19,25 @@ export const LOOP_CORE_MODULES = [
19
19
  "types.ts",
20
20
  "durable/store.ts",
21
21
  "execution/tool-host.ts",
22
+ "execution/device-files.ts",
22
23
  "execution/tool-outcome-events.ts",
24
+ "execution/canonical-digest.ts",
25
+ "execution/coordinator.ts",
26
+ "execution/coordinator-codec.ts",
27
+ "execution/coordinator-consent.ts",
28
+ "execution/coordinator-plan.ts",
29
+ "execution/coordinator-types.ts",
30
+ "execution/ledger.ts",
31
+ "execution/ledger-codec.ts",
32
+ "execution/ledger-transition.ts",
33
+ "execution/ledger-types.ts",
34
+ "execution/prepared/executor.ts",
35
+ "execution/prepared/executor-body.ts",
36
+ "execution/prepared/executor-freeze.ts",
37
+ "execution/prepared/executor-pipeline.ts",
38
+ "execution/prepared/executor-types.ts",
39
+ "execution/prepared/pipeline-prepared.ts",
40
+ "execution/prepared/pipeline-prepared-batch.ts",
23
41
  "durable/store-admission.ts",
24
42
  "durable/wake-host.ts",
25
43
  "transport/transport.ts",
@@ -1,4 +1,6 @@
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";
4
6
  import { LIFECYCLE_REGISTRY } from "../execution/testing/lifecycle-registry.js";
@@ -33,24 +35,14 @@ const wakeCase = (id, impl, expected) => ({
33
35
  adapters: ["store", "wake"],
34
36
  expected,
35
37
  });
36
- const HAND_INTRO = "#5482";
37
- 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 }) => ({
38
40
  id,
39
- impl,
40
- intro: HAND_INTRO,
41
- adapters: ["store", "transport", "executor"],
41
+ impl: KILL_HOOK_IMPL,
42
+ intro: "#5726",
43
+ adapters: ["transport", "executor"],
42
44
  expected,
43
- });
44
- const KILL_HAND_IMPL = "packages/agent/src/execution/testing/kill-hand.ts";
45
- const MULTI_HAND_IMPL = "packages/agent/src/execution/testing/multi-hand-cases.ts";
46
- const FAULT_HAND_IMPL = "packages/agent/src/execution/testing/fault-hand-cases.ts";
47
- const HAND_REGISTRY = [
48
- ...KILL_HAND_DECLARATIONS.map(({ id, expected }) => handCase(id, KILL_HAND_IMPL, expected)),
49
- handCase("MULTI-HAND-01", MULTI_HAND_IMPL, "N scopes batch at once on one hand; each scope's calls start in lane order"),
50
- handCase("MULTI-KILL-01", MULTI_HAND_IMPL, "cross-machine: a hand killed with several scopes in flight; each ends hand_restarted, uncertain, never rerun"),
51
- ...["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`)),
52
- handCase("FAULT-HAND-MULTI-01", FAULT_HAND_IMPL, "hand unreachable past the resume window: dependent calls pause, then each scope resumes exactly once"),
53
- ];
45
+ }));
54
46
  const storeCase = (id, impl, expected) => ({
55
47
  id,
56
48
  impl,
@@ -103,5 +95,7 @@ export const CONFORMANCE_REGISTRY = [
103
95
  faultCase(4, "flap"),
104
96
  faultCase(5, "drop-reattach"),
105
97
  ...HAND_REGISTRY,
98
+ ...EPOCH_REGISTRY,
99
+ ...HOOK_REGISTRY,
106
100
  ];
107
101
  //# sourceMappingURL=registry.js.map
@@ -0,0 +1,42 @@
1
+ import type { DurableStore, StoreValue, SyncCommitStore } from "./store.ts";
2
+ export interface StoredEntry {
3
+ readonly key: string;
4
+ readonly line: string;
5
+ }
6
+ export type SessionHeader = {
7
+ readonly [key: string]: StoreValue;
8
+ };
9
+ export interface StoredSession {
10
+ readonly id: string;
11
+ readonly header: SessionHeader;
12
+ readonly entries: readonly StoredEntry[];
13
+ }
14
+ export type SessionStoreErrorCode = "duplicate-entry" | "corrupt-session";
15
+ export declare class SessionStoreError extends Error {
16
+ readonly code: SessionStoreErrorCode;
17
+ constructor(code: SessionStoreErrorCode, message: string);
18
+ }
19
+ export interface SessionHandle {
20
+ header(): SessionHeader;
21
+ entries(): readonly StoredEntry[];
22
+ append(entries: readonly StoredEntry[]): Promise<void>;
23
+ rewrite(header: SessionHeader, entries: readonly StoredEntry[]): Promise<void>;
24
+ }
25
+ /** A session on any DurableStore (Durable Object included): every write is one async atomic commit. */
26
+ export declare function openSessionStore(store: DurableStore, epoch: number): {
27
+ load: (id: string) => Promise<StoredSession | undefined>;
28
+ open: (id: string, header: SessionHeader) => Promise<SessionHandle>;
29
+ };
30
+ export interface SyncSessionHandle {
31
+ header(): SessionHeader;
32
+ entries(): readonly StoredEntry[];
33
+ /** Durable when it returns; a refusal throws on this call and leaves the session and the store unchanged. */
34
+ appendSync(entries: readonly StoredEntry[]): void;
35
+ rewriteSync(header: SessionHeader, entries: readonly StoredEntry[]): void;
36
+ }
37
+ /** A session whose writes commit synchronously: only a backend with `commitSync` (memory, Bun SQLite) can build one. */
38
+ export declare function openSyncSessionStore(store: SyncCommitStore, epoch: number): {
39
+ load: (id: string) => Promise<StoredSession | undefined>;
40
+ open: (id: string, header: SessionHeader) => Promise<SyncSessionHandle>;
41
+ };
42
+ //# sourceMappingURL=session-store.d.ts.map
@@ -0,0 +1,124 @@
1
+ export class SessionStoreError extends Error {
2
+ constructor(code, message) {
3
+ super(message);
4
+ this.name = "SessionStoreError";
5
+ this.code = code;
6
+ }
7
+ }
8
+ // The S07 JSONL importer's key schema (coding-agent session-import/jsonl-import.ts): one format for both writers.
9
+ const SESSION = "session-import/session/";
10
+ const ENTRY = "session-import/entry/";
11
+ const sessionKey = (id) => SESSION + encodeURIComponent(id);
12
+ const entryKey = (sessionId, key) => `${ENTRY}${encodeURIComponent(sessionId)}/${encodeURIComponent(key)}`;
13
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
14
+ async function readState(store, id) {
15
+ const manifest = await store.getDocument(sessionKey(id));
16
+ if (manifest === undefined)
17
+ return undefined;
18
+ const entryIds = isRecord(manifest) ? manifest.entryIds : undefined;
19
+ if (!isRecord(manifest) || !isRecord(manifest.header) || !Array.isArray(entryIds)) {
20
+ throw new SessionStoreError("corrupt-session", `session ${id} has no readable manifest`);
21
+ }
22
+ const entries = [];
23
+ for (const key of entryIds) {
24
+ const line = typeof key === "string" ? await store.getDocument(entryKey(id, key)) : undefined;
25
+ if (typeof key !== "string" || typeof line !== "string") {
26
+ throw new SessionStoreError("corrupt-session", `session ${id} is missing entry ${String(key)}`);
27
+ }
28
+ entries.push({ key, line });
29
+ }
30
+ return { id, header: manifest.header, entries, divergence: manifest.divergence ?? null };
31
+ }
32
+ const manifestWrite = (state) => ({
33
+ op: "put",
34
+ key: sessionKey(state.id),
35
+ data: {
36
+ id: state.id,
37
+ header: state.header,
38
+ entryIds: state.entries.map((entry) => entry.key),
39
+ divergence: state.divergence,
40
+ },
41
+ });
42
+ function planAppend(state, added) {
43
+ const held = new Set(state.entries.map((entry) => entry.key));
44
+ for (const entry of added) {
45
+ if (held.has(entry.key))
46
+ throw new SessionStoreError("duplicate-entry", `session ${state.id} already holds ${entry.key}`);
47
+ held.add(entry.key);
48
+ }
49
+ const next = { ...state, entries: [...state.entries, ...added] };
50
+ const puts = added.map((entry) => ({ op: "put", key: entryKey(state.id, entry.key), data: entry.line }));
51
+ return { writes: [...puts, manifestWrite(next)], next };
52
+ }
53
+ function planRewrite(state, header, entries) {
54
+ const kept = new Set();
55
+ for (const entry of entries) {
56
+ if (kept.has(entry.key))
57
+ throw new SessionStoreError("duplicate-entry", `rewrite of ${state.id} repeats ${entry.key}`);
58
+ kept.add(entry.key);
59
+ }
60
+ const next = { ...state, header, entries: [...entries] };
61
+ const deletes = state.entries
62
+ .filter((entry) => !kept.has(entry.key))
63
+ .map((entry) => ({ op: "delete", key: entryKey(state.id, entry.key) }));
64
+ const puts = entries.map((entry) => ({
65
+ op: "put",
66
+ key: entryKey(state.id, entry.key),
67
+ data: entry.line,
68
+ }));
69
+ return { writes: [...deletes, ...puts, manifestWrite(next)], next };
70
+ }
71
+ const stored = ({ id, header, entries }) => ({ id, header, entries });
72
+ /** An existing session keeps its stored header; `header` only seeds a session the store does not hold yet. */
73
+ async function openState(store, id, header) {
74
+ return (await readState(store, id)) ?? { id, header, entries: [], divergence: null };
75
+ }
76
+ /** A session on any DurableStore (Durable Object included): every write is one async atomic commit. */
77
+ export function openSessionStore(store, epoch) {
78
+ return {
79
+ load: async (id) => {
80
+ const state = await readState(store, id);
81
+ return state === undefined ? undefined : stored(state);
82
+ },
83
+ open: async (id, header) => {
84
+ let state = await openState(store, id, header);
85
+ // One write at a time, each planned from the state the previous one committed.
86
+ let tail = Promise.resolve();
87
+ const enqueue = (plan) => {
88
+ const run = tail.then(async () => {
89
+ const next = plan();
90
+ await store.commit(epoch, next.writes, () => { });
91
+ state = next.next;
92
+ });
93
+ tail = run.catch(() => undefined);
94
+ return run;
95
+ };
96
+ return {
97
+ header: () => state.header,
98
+ entries: () => state.entries,
99
+ append: (entries) => enqueue(() => planAppend(state, entries)),
100
+ rewrite: (header2, entries) => enqueue(() => planRewrite(state, header2, entries)),
101
+ };
102
+ },
103
+ };
104
+ }
105
+ /** A session whose writes commit synchronously: only a backend with `commitSync` (memory, Bun SQLite) can build one. */
106
+ export function openSyncSessionStore(store, epoch) {
107
+ return {
108
+ load: openSessionStore(store, epoch).load,
109
+ open: async (id, header) => {
110
+ let state = await openState(store, id, header);
111
+ const commit = (plan) => {
112
+ store.commitSync(epoch, plan.writes, () => { });
113
+ state = plan.next;
114
+ };
115
+ return {
116
+ header: () => state.header,
117
+ entries: () => state.entries,
118
+ appendSync: (entries) => commit(planAppend(state, entries)),
119
+ rewriteSync: (header2, entries) => commit(planRewrite(state, header2, entries)),
120
+ };
121
+ },
122
+ };
123
+ }
124
+ //# sourceMappingURL=session-store.js.map
@@ -1,4 +1,4 @@
1
- import { type DurableStore, type DurableStoreOptions, type StoreRecord, type StoreValue } from "./store.ts";
1
+ import { type DurableStoreOptions, type StoreRecord, type StoreValue, type SyncCommitStore } from "./store.ts";
2
2
  interface MediumState {
3
3
  readonly epoch: number;
4
4
  readonly records: readonly StoreRecord[];
@@ -10,6 +10,6 @@ export interface MemoryStoreMedium {
10
10
  }
11
11
  export declare function createMemoryStoreMedium(): MemoryStoreMedium;
12
12
  /** A DurableStore over `medium`. Each operation stages its writes and publishes them in one assignment: atomic. */
13
- export declare function openMemoryStore(medium: MemoryStoreMedium, options?: DurableStoreOptions): DurableStore;
13
+ export declare function openMemoryStore(medium: MemoryStoreMedium, options?: DurableStoreOptions): SyncCommitStore;
14
14
  export {};
15
15
  //# sourceMappingURL=store-memory.d.ts.map
@@ -49,6 +49,40 @@ const documentsOf = (state, prefix) => [...state.documents]
49
49
  /** A DurableStore over `medium`. Each operation stages its writes and publishes them in one assignment: atomic. */
50
50
  export function openMemoryStore(medium, options = {}) {
51
51
  const point = (at) => options.onWritePoint?.(at);
52
+ const commitSync = (epoch, writes, adopt) => {
53
+ point({ op: "commit", at: "before" });
54
+ const state = medium.current;
55
+ requireOwner(state, epoch);
56
+ const records = [...state.records];
57
+ const ids = new Set(records.map((record) => record.id));
58
+ const documents = new Map(state.documents);
59
+ const seqs = [];
60
+ writes.forEach((write, index) => {
61
+ point({ op: "commit", at: "write", index });
62
+ switch (write.op) {
63
+ case "append": {
64
+ if (ids.has(write.id))
65
+ throw new DurableStoreError("duplicate-record-id", `record ${write.id} exists`);
66
+ ids.add(write.id);
67
+ const seq = records.length + 1;
68
+ records.push({ seq, id: write.id, kind: write.kind, data: copy(write.data) });
69
+ seqs.push(seq);
70
+ break;
71
+ }
72
+ case "put":
73
+ documents.set(write.key, copy(write.data));
74
+ break;
75
+ case "delete":
76
+ documents.delete(write.key);
77
+ break;
78
+ }
79
+ });
80
+ medium.current = { epoch: state.epoch, records, documents };
81
+ point({ op: "commit", at: "durable" });
82
+ const result = { seqs, head: records.length };
83
+ adopt(result);
84
+ return result;
85
+ };
52
86
  return {
53
87
  readEpoch: async () => medium.current.epoch,
54
88
  readHead: async () => medium.current.records.length,
@@ -64,40 +98,8 @@ export function openMemoryStore(medium, options = {}) {
64
98
  medium.current = { ...state, epoch: nextEpoch };
65
99
  point({ op: "claim", at: "durable" });
66
100
  },
67
- async commit(epoch, writes, adopt) {
68
- point({ op: "commit", at: "before" });
69
- const state = medium.current;
70
- requireOwner(state, epoch);
71
- const records = [...state.records];
72
- const ids = new Set(records.map((record) => record.id));
73
- const documents = new Map(state.documents);
74
- const seqs = [];
75
- writes.forEach((write, index) => {
76
- point({ op: "commit", at: "write", index });
77
- switch (write.op) {
78
- case "append": {
79
- if (ids.has(write.id))
80
- throw new DurableStoreError("duplicate-record-id", `record ${write.id} exists`);
81
- ids.add(write.id);
82
- const seq = records.length + 1;
83
- records.push({ seq, id: write.id, kind: write.kind, data: copy(write.data) });
84
- seqs.push(seq);
85
- break;
86
- }
87
- case "put":
88
- documents.set(write.key, copy(write.data));
89
- break;
90
- case "delete":
91
- documents.delete(write.key);
92
- break;
93
- }
94
- });
95
- medium.current = { epoch: state.epoch, records, documents };
96
- point({ op: "commit", at: "durable" });
97
- const result = { seqs, head: records.length };
98
- adopt(result);
99
- return result;
100
- },
101
+ commit: async (epoch, writes, adopt) => commitSync(epoch, writes, adopt),
102
+ commitSync,
101
103
  mintId: () => crypto.randomUUID(),
102
104
  scanRecords: async (query = {}) => scan(medium.current.records, query),
103
105
  getDocument: async (key) => {
@@ -113,4 +113,13 @@ export interface DurableStore {
113
113
  */
114
114
  importSnapshot(epoch: number, snapshot: StoreSnapshot): Promise<void>;
115
115
  }
116
+ /**
117
+ * A backend whose commit is durable when it returns (memory; Bun SQLite with `synchronous=FULL`). `commitSync` keeps the
118
+ * `commit` contract on the same call: a refusal throws before it returns and leaves the store unchanged. A Durable Object
119
+ * store confirms durability only asynchronously, so it does not offer this.
120
+ */
121
+ export interface SyncCommit {
122
+ commitSync(epoch: number, writes: readonly StoreWrite[], adopt: (result: CommitResult) => void): CommitResult;
123
+ }
124
+ export type SyncCommitStore = DurableStore & SyncCommit;
116
125
  //# sourceMappingURL=store.d.ts.map