@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
package/dist/index.js CHANGED
@@ -2,13 +2,36 @@ export { uuidv7 } from "@earendil-works/pi-ai";
2
2
  export { createTypedSpanStarter, defineTelemetrySchema, InMemoryTelemetryContext, NOOP_TELEMETRY_CONTEXT, } from "@earendil-works/pi-telemetry";
3
3
  export * from "./agent.js";
4
4
  export * from "./agent-loop.js";
5
+ export * from "./egress/types.js";
6
+ export { isStepCommitError, StepCommitError } from "./step-commit.js";
7
+ export { Agent, agentLoop, agentLoopContinue, runAgentLoop, runAgentLoopContinue } from "./public-entry.js";
5
8
  export { createInternalAgentChannel } from "./internal-events.js";
6
9
  export { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from "./assistant-terminal-state.js";
7
10
  export { createRemoteExecutor, } from "./execution/remote-executor.js";
8
11
  export { createHandLedger, } from "./execution/remote-hand-ledger.js";
9
12
  export { decodeRemoteMessage, encodeRemoteMessage, HAND_CONTROL_LANE, RemoteProtocolError, } from "./execution/remote-protocol.js";
13
+ export { createErrorToolResult, createToolResultMessage, emitToolExecutionEnd, emitToolExecutionUpdate, emitToolResultMessage, shouldTerminateToolBatch, } from "./execution/tool-outcome-events.js";
14
+ export { createAdmissionLine } from "./durable/store-admission.js";
15
+ export { createMemoryStoreMedium, openMemoryStore } from "./durable/store-memory.js";
16
+ export { createBatchCoordinator } from "./execution/coordinator.js";
17
+ export { createExecutionLedger } from "./execution/ledger.js";
10
18
  export { authorize, createGrantVerifier, DEFAULT_WORKSPACE, HAND_CAPABILITY, } from "./execution/grant-verify.js";
19
+ export { createHandEpochFence, EPOCH_FLOOR_MAX_STEP, HAND_SELF_SENDER, } from "./execution/remote-epoch.js";
20
+ export { base64Length, DEVICE_FILE_OPS, DeviceFileError, decodeBase64, decodeDeviceFileArgs, encodeBase64, FILE_CHANNEL, FILE_CHANNEL_MAX_BYTES, RUN_CHANNEL, fileOutcomeOf, } from "./execution/device-files.js";
21
+ export { HELLO_WAIT_MS } from "./execution/remote-device-files.js";
22
+ export { fileRefusal, fileResult } from "./execution/remote-file-call.js";
23
+ export { createModelPlaneClient, decodeModelPlaneRequest, MODEL_PLANE, serveModelPlane, } from "./execution/plane-model.js";
24
+ export { createLoopToolHost, createSessionPlaneClient, createSplitToolHost, decodeSessionPlaneRequest, loopSideToolNames, SESSION_PLANE, serveSessionPlane, } from "./execution/plane-session.js";
25
+ export { admitChainCall, CHAIN_COUNT_LIMIT, CHAIN_ORIGIN, ChainCountLimitError, decodeChainCount, nextChainCount, } from "./execution/chain-count.js";
26
+ export { decodePlaneMessage, encodePlaneMessage, PlaneRefusedError, } from "./execution/plane.js";
27
+ export { createLoopHookHost, LoopHookFailedError, LoopHookRestartedError, } from "./execution/loop-hook-host.js";
28
+ export { serveLoopHooks, } from "./execution/loop-hook-host-hand.js";
11
29
  export { createRemoteToolHost } from "./execution/remote-tool-host.js";
30
+ export { canonicalJson } from "./execution/canonical-digest.js";
31
+ export { toStoreValue } from "./execution/prepared/executor-freeze.js";
32
+ export { openMemoryBatchStore } from "./execution/prepared/memory-batch-store.js";
33
+ export { BatchStoreMissingError, noPreflightCarry, PreflightCarryMissingError } from "./execution/tool-host.js";
34
+ export { createPreparedToolHost } from "./execution/prepared/pipeline-prepared.js";
12
35
  export { createInProcessNetwork } from "./transport/in-process-carrier.js";
13
36
  export { localEndpoint } from "./transport/local-endpoint.js";
14
37
  export { createReliableTransport } from "./transport/reliable-transport.js";
@@ -37,6 +60,6 @@ export * from "./response-timing.js";
37
60
  export * from "./search/index.js";
38
61
  export { setDefaultStreamFn } from "./stream-fn.js";
39
62
  export { prepareToolArguments } from "./tool-arguments.js";
40
- export { resolveToolNameAlias } from "./tool-name-alias.js";
63
+ export { resolveToolNameAlias, withToolNameCorrection } from "./tool-name-alias.js";
41
64
  export * from "./types.js";
42
65
  //# sourceMappingURL=index.js.map
package/dist/node.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { NodeExecutionEnv } from "./harness/env/nodejs.ts";
2
2
  export { listWindowsProcessRowsSync, parseWindowsProcessTreeRows, type WindowsProcessRow, type WindowsTreeKillPlan, windowsTreeKillArgs, windowsTreeKillPlan, } from "./harness/env/windows-process-tree.ts";
3
+ export { localDeviceFiles } from "./execution/device-files-node.ts";
3
4
  export * from "./index.ts";
4
5
  //# sourceMappingURL=node.d.ts.map
package/dist/node.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { NodeExecutionEnv } from "./harness/env/nodejs.js";
2
2
  export { listWindowsProcessRowsSync, parseWindowsProcessTreeRows, windowsTreeKillArgs, windowsTreeKillPlan, } from "./harness/env/windows-process-tree.js";
3
+ export { localDeviceFiles } from "./execution/device-files-node.js";
3
4
  export * from "./index.js";
4
5
  //# sourceMappingURL=node.js.map
@@ -0,0 +1,10 @@
1
+ import { Agent as LoopAgent, type AgentOptions } from "./agent.ts";
2
+ import { agentLoop as loopAgentLoop, agentLoopContinue as loopAgentLoopContinue, runAgentLoop as loopRunAgentLoop, runAgentLoopContinue as loopRunAgentLoopContinue } from "./agent-loop.ts";
3
+ export declare class Agent extends LoopAgent {
4
+ constructor(options: AgentOptions);
5
+ }
6
+ export declare const agentLoop: typeof loopAgentLoop;
7
+ export declare const agentLoopContinue: typeof loopAgentLoopContinue;
8
+ export declare const runAgentLoop: typeof loopRunAgentLoop;
9
+ export declare const runAgentLoopContinue: typeof loopRunAgentLoopContinue;
10
+ //# sourceMappingURL=public-entry.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { Agent as LoopAgent } from "./agent.js";
2
+ import { agentLoop as loopAgentLoop, agentLoopContinue as loopAgentLoopContinue, runAgentLoop as loopRunAgentLoop, runAgentLoopContinue as loopRunAgentLoopContinue, } from "./agent-loop.js";
3
+ import { openMemoryBatchStore } from "./execution/prepared/memory-batch-store.js";
4
+ import { noPreflightCarry } from "./execution/tool-host.js";
5
+ // The package entry's loop and Agent: the loop core builds no store (senpi#4996), so the entry supplies a fresh in-memory
6
+ // store per batch unless the caller passes its own factory or ToolHost. External callers need no new argument.
7
+ function withBatchStore(config) {
8
+ return {
9
+ ...config,
10
+ batchStoreFactory: config.batchStoreFactory ?? openMemoryBatchStore,
11
+ afterToolFreeze: config.afterToolFreeze ?? noPreflightCarry,
12
+ };
13
+ }
14
+ export class Agent extends LoopAgent {
15
+ constructor(options) {
16
+ super(withBatchStore(options));
17
+ }
18
+ }
19
+ export const agentLoop = (prompts, context, config, signal, streamFn) => loopAgentLoop(prompts, context, withBatchStore(config), signal, streamFn);
20
+ export const agentLoopContinue = (context, config, signal, streamFn) => loopAgentLoopContinue(context, withBatchStore(config), signal, streamFn);
21
+ export const runAgentLoop = (prompts, context, config, emit, signal, streamFn) => loopRunAgentLoop(prompts, context, withBatchStore(config), emit, signal, streamFn);
22
+ export const runAgentLoopContinue = (context, config, emit, signal, streamFn) => loopRunAgentLoopContinue(context, withBatchStore(config), emit, signal, streamFn);
23
+ //# sourceMappingURL=public-entry.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The durable step commit a hosted brain host installs through `AgentLoopConfig.commitStep`.
3
+ *
4
+ * Fused and split-local assemblies never set `commitStep` and never construct a `StepCommitError`;
5
+ * only a hosted host's commit implementation (and its conformance harness) does. The error is branded
6
+ * with a registry symbol so a value built by a second copy of this package (version skew, a bundler
7
+ * duplicate) is still recognised: callers check it with `isStepCommitError`, never `instanceof`.
8
+ */
9
+ export type StepCommitFailure = "already_committed" | "fenced" | "generation" | "epoch_unverified" | "storage_unavailable" | "ambiguous_unresolved";
10
+ declare const STEP_COMMIT_BRAND: unique symbol;
11
+ /** A hosted step commit failed; the step's message is not durable and must not be acted on. */
12
+ export declare class StepCommitError extends Error {
13
+ readonly name: "StepCommitError";
14
+ readonly [STEP_COMMIT_BRAND]: true;
15
+ readonly stepId: string;
16
+ readonly code: StepCommitFailure;
17
+ constructor(stepId: string, code: StepCommitFailure, options?: {
18
+ readonly cause?: unknown;
19
+ });
20
+ }
21
+ /** True for a `StepCommitError` from any copy of this package; false for look-alikes without the brand. */
22
+ export declare function isStepCommitError(value: unknown): value is StepCommitError;
23
+ export {};
24
+ //# sourceMappingURL=step-commit.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The durable step commit a hosted brain host installs through `AgentLoopConfig.commitStep`.
3
+ *
4
+ * Fused and split-local assemblies never set `commitStep` and never construct a `StepCommitError`;
5
+ * only a hosted host's commit implementation (and its conformance harness) does. The error is branded
6
+ * with a registry symbol so a value built by a second copy of this package (version skew, a bundler
7
+ * duplicate) is still recognised: callers check it with `isStepCommitError`, never `instanceof`.
8
+ */
9
+ const STEP_COMMIT_BRAND = Symbol.for("senpi.StepCommitError");
10
+ /** A hosted step commit failed; the step's message is not durable and must not be acted on. */
11
+ export class StepCommitError extends Error {
12
+ constructor(stepId, code, options) {
13
+ super(`step commit failed: ${code}`, options);
14
+ this.name = "StepCommitError";
15
+ this.stepId = stepId;
16
+ this.code = code;
17
+ Object.defineProperty(this, STEP_COMMIT_BRAND, { value: true, enumerable: false, writable: false });
18
+ }
19
+ }
20
+ /** True for a `StepCommitError` from any copy of this package; false for look-alikes without the brand. */
21
+ export function isStepCommitError(value) {
22
+ return typeof value === "object" && value !== null && Reflect.get(value, STEP_COMMIT_BRAND) === true;
23
+ }
24
+ //# sourceMappingURL=step-commit.js.map
@@ -1,4 +1,4 @@
1
- import type { AgentContext, AgentLoopConfig, AgentTool, AgentToolCall, AgentToolResult } from "./types.ts";
1
+ import type { AgentToolResult } from "./types.ts";
2
2
  /**
3
3
  * A model can call a tool by a name it was never registered under: recased,
4
4
  * under a gateway namespace (`mcp__<id>__<Name>`, any case), or without the
@@ -7,11 +7,5 @@ import type { AgentContext, AgentLoopConfig, AgentTool, AgentToolCall, AgentTool
7
7
  */
8
8
  export declare function resolveToolNameAlias(requested: string, available: Iterable<string>): string | undefined;
9
9
  export declare function toolNameCorrectionNotice(requested: string, resolved: string): string;
10
- /**
11
- * Find the tool a call will run, resolving an unknown name through the host
12
- * resolver and then the alias rule. Runs before `tool_execution_start` so every
13
- * event names the tool that executes, never the name the model mistyped.
14
- */
15
- export declare function resolveCallTool(currentContext: AgentContext, toolCall: AgentToolCall, config: AgentLoopConfig): Promise<AgentTool | undefined>;
16
10
  export declare function withToolNameCorrection(result: AgentToolResult<unknown>, requestedName: string, resolvedName: string): AgentToolResult<unknown>;
17
11
  //# sourceMappingURL=tool-name-alias.d.ts.map
@@ -11,23 +11,6 @@ export function resolveToolNameAlias(requested, available) {
11
11
  export function toolNameCorrectionNotice(requested, resolved) {
12
12
  return `[auto-corrected] no tool is named "${requested}"; ran "${resolved}". Call tools by their exact listed name.`;
13
13
  }
14
- /**
15
- * Find the tool a call will run, resolving an unknown name through the host
16
- * resolver and then the alias rule. Runs before `tool_execution_start` so every
17
- * event names the tool that executes, never the name the model mistyped.
18
- */
19
- export async function resolveCallTool(currentContext, toolCall, config) {
20
- if (toolCall.incomplete === true)
21
- return undefined;
22
- const exact = currentContext.tools?.find((candidate) => candidate.name === toolCall.name);
23
- if (exact)
24
- return exact;
25
- const resolved = await config.resolveUnknownToolCall?.(toolCall.name, currentContext);
26
- if (resolved)
27
- return resolved;
28
- const aliasedName = resolveToolNameAlias(toolCall.name, (currentContext.tools ?? []).map((candidate) => candidate.name));
29
- return currentContext.tools?.find((candidate) => candidate.name === aliasedName);
30
- }
31
14
  export function withToolNameCorrection(result, requestedName, resolvedName) {
32
15
  return {
33
16
  ...result,
@@ -90,24 +90,24 @@ const lossOnOneLaneIsNotHeldByAnother = async (adapters) => {
90
90
  const link = openLink(adapters, () => loseOnce(decode, "B", 1, stats));
91
91
  link.pace("A", LONG_LANE_PACE_MS);
92
92
  const aSends = range(1, LONG_LANE_FRAMES).map((n) => link.send("A", n));
93
- await link.runUntil(() => link.delivered("A").length >= 10, "MULTI-FAIR-02 A's long lane under way");
93
+ await link.runUntil(() => link.delivered("A").length >= 10, "MULTI-FAIR-03 A's long lane under way");
94
94
  const before = link.delivered("A").length;
95
95
  const bSend = link.send("B", 1);
96
- await link.runUntil(allDelivered(link, { B: 1 }), "MULTI-FAIR-02 B delivered after its loss", 600_000);
96
+ await link.runUntil(allDelivered(link, { B: 1 }), "MULTI-FAIR-03 B delivered after its loss", 600_000);
97
97
  if (stats.lost !== 1)
98
- throw new Error(`MULTI-FAIR-02: B#1 was not lost on the carrier (${JSON.stringify(stats)})`);
98
+ throw new Error(`MULTI-FAIR-03: B#1 was not lost on the carrier (${JSON.stringify(stats)})`);
99
99
  const aheadOfB = link.delivered("A").length - before;
100
100
  if (aheadOfB >= LONG_LANE_FRAMES / 2) {
101
- throw new Error(`MULTI-FAIR-02: B's lost frame was resent only after ${aheadOfB} of A's frames (fewer than ${LONG_LANE_FRAMES / 2})`);
101
+ throw new Error(`MULTI-FAIR-03: B's lost frame was resent only after ${aheadOfB} of A's frames (fewer than ${LONG_LANE_FRAMES / 2})`);
102
102
  }
103
- await link.runUntil(allDelivered(link, { A: LONG_LANE_FRAMES }), "MULTI-FAIR-02 A delivered", 600_000);
104
- await link.awaitAll([...aSends, bSend], "MULTI-FAIR-02");
103
+ await link.runUntil(allDelivered(link, { A: LONG_LANE_FRAMES }), "MULTI-FAIR-03 A delivered", 600_000);
104
+ await link.awaitAll([...aSends, bSend], "MULTI-FAIR-03");
105
105
  await link.advance(2000);
106
- expectExactDelivery(link, { A: LONG_LANE_FRAMES, B: 1 }, "MULTI-FAIR-02");
106
+ expectExactDelivery(link, { A: LONG_LANE_FRAMES, B: 1 }, "MULTI-FAIR-03");
107
107
  };
108
108
  export const MULTI_CASES = new Map([
109
109
  ["MULTI-LANE-01", manyLanes],
110
110
  ["MULTI-FAIR-01", fairness],
111
- ["MULTI-FAIR-02", lossOnOneLaneIsNotHeldByAnother],
111
+ ["MULTI-FAIR-03", lossOnOneLaneIsNotHeldByAnother],
112
112
  ]);
113
113
  //# sourceMappingURL=multi-cases.js.map
package/dist/types.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type { Api, AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, CursorExecHandlers, ImageContent, JsonValue, Message, Model, ProviderDiagnostic, SimpleStreamOptions, TextContent, ThinkingSelection, Tool, ToolResultMessage, TranscriptContext, Usage } from "@earendil-works/pi-ai";
2
2
  import type { Static, TSchema } from "typebox";
3
+ import type { DurableStore } from "./durable/store.ts";
3
4
  import type { ExecutionPipelineWitness, ExecutionScope, ToolHost } from "./execution/tool-host.ts";
5
+ /**
6
+ * Opens a new, empty store for one tool batch, which the batch claims at epoch 1. A batch never reuses another's
7
+ * store: a call's command ID is the model's call ID, and providers reuse those across turns.
8
+ */
9
+ export type BatchStoreFactory = () => DurableStore;
4
10
  export type { ExecutionPipelineWitness, ExecutionScope, ToolHost, ToolHostCall, ToolHostOptions, ToolHostResult, } from "./execution/tool-host.ts";
5
11
  /**
6
12
  * Stream function used by the agent loop. `Models.streamSimple` satisfies
@@ -135,6 +141,16 @@ export type AgentTurnDecision = {
135
141
  * with the current context. Error and aborted responses remain hard exits.
136
142
  */
137
143
  export type FinishTurn = (turn: AgentTurnContext, signal?: AbortSignal) => AgentTurnDecision | void | Promise<AgentTurnDecision | undefined> | Promise<void>;
144
+ /** One model step as the loop finished it: its terminal assistant message and the provider tool results emitted for it. */
145
+ export interface StepCommit {
146
+ readonly message: AssistantMessage;
147
+ readonly providerToolResults: readonly ToolResultMessage[];
148
+ }
149
+ /**
150
+ * Makes one finished model step durable before the loop acts on it. A rejection leaves the loop with no further
151
+ * events and no tool dispatch for that step.
152
+ */
153
+ export type StepCommitFn = (step: StepCommit) => Promise<void>;
138
154
  /** Replacement runtime state used by the agent loop before starting another provider request. */
139
155
  export interface AgentLoopTurnUpdate {
140
156
  /** Context for the next provider request. */
@@ -263,6 +279,12 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
263
279
  * hard exits.
264
280
  */
265
281
  finishTurn?: FinishTurn;
282
+ /**
283
+ * Called once per model step, after the step's provider tool results are emitted and before the loop decides
284
+ * whether the turn ends or dispatches tools; it covers success and terminal-failure messages alike. Unset on
285
+ * every local assembly; a hosted brain host sets it to commit the step durably.
286
+ */
287
+ commitStep?: StepCommitFn;
266
288
  /**
267
289
  * Called immediately before every conversational provider request, including the first.
268
290
  * Pending messages have already been appended. The returned context, model, and thinking level
@@ -324,8 +346,22 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
324
346
  * Default: "parallel"
325
347
  */
326
348
  toolExecution?: ToolExecutionMode;
327
- /** Unprepared batch boundary. Omitted selects the existing in-process legacy scheduler. */
349
+ /** Unprepared batch boundary. Omitted selects the prepared pipeline (batch coordinator + prepared executor) in this process. */
328
350
  toolHost?: ToolHost;
351
+ /**
352
+ * Opens each batch's execution ledger for the default (prepared) pipeline. The loop builds no store itself: with no
353
+ * `toolHost` and no factory, a tool batch fails closed with `BatchStoreMissingError`. The package entry's `Agent` and
354
+ * `agentLoop` default it to `openMemoryBatchStore`.
355
+ */
356
+ batchStoreFactory?: BatchStoreFactory;
357
+ /**
358
+ * Runs once per call on the prepared pipeline, after the call is frozen and before it executes, with the arguments
359
+ * object `beforeToolCall` saw and the frozen copy the tool will receive. A host whose `beforeToolCall` binds facts to
360
+ * that object (an approval, a symbol property) moves them here. Synchronous and must not throw. With no `toolHost`
361
+ * and no hook, a tool batch fails closed with `PreflightCarryMissingError`; the package entry's `Agent` and
362
+ * `agentLoop` default it to `noPreflightCarry` (senpi#5795).
363
+ */
364
+ afterToolFreeze?: (prepared: unknown, frozen: unknown) => void;
329
365
  executionScope?: ExecutionScope;
330
366
  onExecutionPipeline?: (witness: ExecutionPipelineWitness) => Promise<void> | void;
331
367
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-agent-core",
3
- "version": "2026.11.3-3",
3
+ "version": "2026.11.5-1",
4
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -72,8 +72,8 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@earendil-works/chord": "0.99.1",
75
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-3",
76
- "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.3-3",
75
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.5-1",
76
+ "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.5-1",
77
77
  "diff": "9.0.0",
78
78
  "ignore": "7.0.9",
79
79
  "typebox": "1.3.34",