maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.25.20260908

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 (215) hide show
  1. package/README.md +38 -19
  2. package/README.zh-CN.md +34 -19
  3. package/dist/acp/maka-acp-agent.js +2 -1
  4. package/dist/acp/session-configuration.js +143 -0
  5. package/dist/acp/session-registry.js +90 -4
  6. package/dist/cli-core.js +2 -0
  7. package/dist/pi-transcript-tools.js +6 -0
  8. package/dist/pi-transcript.js +5 -12
  9. package/dist/pi-tui-layout.js +56 -10
  10. package/dist/pi-tui-pickers.js +102 -1
  11. package/dist/pi-tui-runner.js +230 -46
  12. package/dist/pi-tui-todo.js +221 -0
  13. package/dist/pi-tui-transcript-viewer.js +134 -7
  14. package/dist/runtime-host-cli-context.js +224 -78
  15. package/dist/runtime-host-cli-installation.js +8 -2
  16. package/dist/runtime-host-cli.js +31 -1
  17. package/dist/runtime-host-handoff-surface.js +106 -0
  18. package/dist/runtime-host-installed-update-bootstrap.js +13 -0
  19. package/dist/runtime-host-installed-update-coordinator.js +33 -0
  20. package/dist/runtime-host-lifecycle-transaction.js +9 -1
  21. package/dist/runtime-host-local-handoff.js +48 -5
  22. package/dist/runtime-host-local-managed-activation.js +84 -0
  23. package/dist/runtime-host-local-source-retirement.js +18 -2
  24. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  25. package/dist/runtime-host-operator-retirement.js +50 -0
  26. package/dist/runtime-host-service-manager.js +3 -3
  27. package/dist/runtime-host-session-channel.js +13 -0
  28. package/dist/runtime-host-session-driver.js +46 -26
  29. package/dist/runtime-host-session-update.js +62 -0
  30. package/dist/runtime-host-tui-command.js +38 -73
  31. package/dist/runtime-host-tui-context.js +1 -0
  32. package/dist/runtime-host-tui-owner.js +226 -0
  33. package/dist/tui-copy-catalog.js +219 -6
  34. package/dist/tui-host-owner-copy.js +24 -0
  35. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  36. package/node_modules/@maka/core/dist/agent-run.js +1 -0
  37. package/node_modules/@maka/core/dist/attachments.js +3 -0
  38. package/node_modules/@maka/core/dist/canonical-json.js +27 -0
  39. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  40. package/node_modules/@maka/core/dist/capabilities.js +35 -0
  41. package/node_modules/@maka/core/dist/computer-use.js +0 -1
  42. package/node_modules/@maka/core/dist/display-redaction.js +18 -0
  43. package/node_modules/@maka/core/dist/llm-connections.js +13 -0
  44. package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
  45. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  46. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  47. package/node_modules/@maka/core/dist/model-metadata.js +7 -3
  48. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  49. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  50. package/node_modules/@maka/core/dist/record-schema.js +9 -2
  51. package/node_modules/@maka/core/dist/redaction.js +35 -0
  52. package/node_modules/@maka/core/dist/run-composition.js +77 -2
  53. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  54. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  55. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  56. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  57. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  58. package/node_modules/@maka/core/dist/session.js +84 -56
  59. package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
  60. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  61. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  62. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  63. package/node_modules/@maka/core/package.json +5 -0
  64. package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
  65. package/node_modules/@maka/mcp/dist/index.js +131 -1
  66. package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
  67. package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
  68. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
  69. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  70. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
  71. package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
  72. package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
  73. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  74. package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
  75. package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
  76. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  77. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  78. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  79. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  80. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
  81. package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
  82. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  83. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  84. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  85. package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
  86. package/node_modules/@maka/runtime/dist/model-history.js +0 -112
  87. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  88. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  89. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  90. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  91. package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
  92. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
  93. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  94. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
  95. package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
  96. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  97. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
  98. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
  99. package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
  100. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  101. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  102. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  103. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  104. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  105. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  106. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
  107. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
  108. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  109. package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
  110. package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
  111. package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
  112. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  113. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
  114. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
  115. package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
  116. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  117. package/node_modules/@maka/runtime/package.json +2 -0
  118. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  119. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  120. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  121. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
  122. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
  123. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  124. package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  126. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  127. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
  128. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
  129. package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
  130. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  131. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
  132. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  133. package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
  134. package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
  135. package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
  136. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
  137. package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  139. package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
  140. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
  141. package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
  142. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  143. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  144. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  145. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  146. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
  147. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
  148. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
  149. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  150. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  151. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
  152. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
  153. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
  155. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  156. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
  157. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  158. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  159. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  160. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
  161. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
  162. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
  164. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
  165. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  166. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  167. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
  168. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  169. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
  170. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
  171. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  172. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  173. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  174. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  175. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  176. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
  177. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
  178. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
  179. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  180. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  181. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
  182. package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
  183. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  184. package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
  185. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  186. package/node_modules/@maka/storage/dist/git-exec.js +61 -0
  187. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
  188. package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
  189. package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
  190. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  191. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  192. package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
  193. package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
  194. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  195. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
  196. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  197. package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
  198. package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
  199. package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
  200. package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  202. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  203. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  204. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  205. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  206. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
  207. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  208. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
  209. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  210. package/node_modules/@maka/storage/dist/storage-id.js +28 -0
  211. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
  212. package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
  213. package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
  214. package/node_modules/@maka/storage/package.json +2 -0
  215. package/package.json +1 -1
@@ -52,31 +52,41 @@ export function createInteractiveRunComposer(input) {
52
52
  : input.builtinTools;
53
53
  const inventorySnapshotFor = createTurnSkillInventorySnapshotResolver(input.skills);
54
54
  const inventoryFor = async (context) => (await inventorySnapshotFor(context)).inventory;
55
+ const hasToolCeiling = input.boundTools !== undefined || input.toolProfile !== undefined;
56
+ const activeExecution = input.plan ? activePlanExecution(input.plan.state) : undefined;
57
+ // The base Host binding is immutable for this backend. Only scoped plugin
58
+ // contributions are sampled at logical step boundaries.
55
59
  const defaultTools = input.boundTools
56
60
  ? input.boundTools
57
- : buildDefaultHostTools(input.sessionTodo, inventoryFor, builtinTools, input.hostTools, input.scheduledTaskTool, input.goalTools, input.parentAgentTools, input.plan, input.deepResearch?.tools);
58
- const hasToolCeiling = input.boundTools !== undefined || input.toolProfile !== undefined;
61
+ : buildDefaultHostTools(input.sessionTodo, inventoryFor, builtinTools, input.hostTools ?? [], input.scheduledTaskTool, input.goalTools, input.parentAgentTools, input.plan, input.deepResearch?.tools);
59
62
  const clientCapabilityTools = hasToolCeiling ? [] : (input.clientCapabilities?.tools ?? []);
60
- const unscopedCandidateTools = [...defaultTools, ...clientCapabilityTools];
61
- const routedCandidateTools = input.deepResearch
62
- ? unscopedCandidateTools.filter(isDeepResearchToolAllowed)
63
- : unscopedCandidateTools;
64
- const candidateTools = projectHostedExecutionTools(routedCandidateTools, input.toolProfile);
65
- const activeExecution = input.plan ? activePlanExecution(input.plan.state) : undefined;
66
- const selectedTools = input.plan
67
- ? selectCollaborationTools({
68
- mode: input.plan.mode,
69
- tools: candidateTools,
70
- hasActiveExecution: activeExecution !== undefined,
71
- fullAccess: input.plan.permissionMode === 'bypass',
72
- })
73
- : candidateTools;
74
- // A bound tool list is an exact child/local activation ceiling. Dynamic
75
- // capabilities must be included by the authority that constructs that
76
- // list. The ceiling is also an exact wire contract: no deferred search
77
- // groups inside it, so the bound tools stay fully visible.
78
- const tools = [...selectedTools];
79
- assertUniqueToolNames(tools);
63
+ const resolveTools = () => {
64
+ const stableHostTools = [...defaultTools, ...clientCapabilityTools];
65
+ const additionalTools = hasToolCeiling
66
+ ? []
67
+ : (input.resolveAdditionalTools?.(stableHostTools) ?? []);
68
+ const unscopedCandidateTools = [...stableHostTools, ...additionalTools];
69
+ const routedCandidateTools = input.deepResearch
70
+ ? unscopedCandidateTools.filter(isDeepResearchToolAllowed)
71
+ : unscopedCandidateTools;
72
+ const candidateTools = projectHostedExecutionTools(routedCandidateTools, input.toolProfile);
73
+ const selectedTools = input.plan
74
+ ? selectCollaborationTools({
75
+ mode: input.plan.mode,
76
+ tools: candidateTools,
77
+ hasActiveExecution: activeExecution !== undefined,
78
+ fullAccess: input.plan.permissionMode === 'bypass',
79
+ })
80
+ : candidateTools;
81
+ // A bound tool list is an exact child/local activation ceiling. Dynamic
82
+ // capabilities must be included by the authority that constructs that
83
+ // list. The ceiling is also an exact wire contract: no deferred search
84
+ // groups inside it, so the bound tools stay fully visible.
85
+ const resolved = [...selectedTools];
86
+ assertUniqueToolNames(resolved);
87
+ return Object.freeze(resolved);
88
+ };
89
+ const tools = resolveTools();
80
90
  const hostCapabilities = buildHostCapabilitiesFromBinding(tools.map(({ name }) => name));
81
91
  const toolAvailability = hasToolCeiling
82
92
  ? undefined
@@ -160,6 +170,7 @@ export function createInteractiveRunComposer(input) {
160
170
  composerId: INTERACTIVE_RUN_COMPOSER_ID,
161
171
  composerRevision: INTERACTIVE_RUN_COMPOSER_REVISION,
162
172
  tools,
173
+ resolveTools,
163
174
  toolAvailability,
164
175
  resolveSystemPrompt,
165
176
  });
@@ -248,6 +259,20 @@ export function createInteractiveRunComposerFactory(input) {
248
259
  ...(clientCapabilities ? { clientCapabilities } : {}),
249
260
  ...(input.builtinTools ? { builtinTools: input.builtinTools } : {}),
250
261
  ...(hostTools.length > 0 ? { hostTools } : {}),
262
+ ...(input.resolvePluginTools && !backendContext.tools
263
+ ? {
264
+ resolveAdditionalTools: (hostTools) => {
265
+ return routeInteractiveRunToolSurface({
266
+ runtimePolicy,
267
+ connection,
268
+ modelId,
269
+ hostTools: input.resolvePluginTools(backendContext.sessionId, hostTools).tools,
270
+ worktreePatchWriteBackAvailable: input.worktreePatchWriteBackAvailable,
271
+ tavilyReady,
272
+ }).hostTools;
273
+ },
274
+ }
275
+ : {}),
251
276
  ...(input.scheduledTaskTool ? { scheduledTaskTool: input.scheduledTaskTool } : {}),
252
277
  ...(input.goalTools ? { goalTools: input.goalTools } : {}),
253
278
  ...(parentAgentTools ? { parentAgentTools } : {}),
@@ -246,11 +246,16 @@ export class HostMessageCoordinator {
246
246
  }
247
247
  bindRun(identity) {
248
248
  const state = this.#state(identity.sessionId);
249
- const exactPreStartStop = state.stopFence !== undefined && sameRun(state.stopFence.identity, identity);
249
+ const exactPreStartStop = state.stopFence !== undefined &&
250
+ state.reservedRoot !== undefined &&
251
+ sameRun(state.stopFence.identity, state.reservedRoot);
250
252
  if (state.phase !== 'open' && !exactPreStartStop) {
251
253
  throw new RuntimeMessageAuthorityInvariantError('Message Run bound while admission was closed');
252
254
  }
253
- if (!state.reservedRoot || !sameRun(state.reservedRoot, identity) || state.run) {
255
+ if (!state.reservedRoot ||
256
+ state.reservedRoot.turnId !== identity.turnId ||
257
+ state.reservedRoot.expectedRunId !== identity.runId ||
258
+ state.run) {
254
259
  throw new RuntimeMessageAuthorityInvariantError(`Message Run ${identity.runId} was not the exact reserved root identity`);
255
260
  }
256
261
  const run = { ...identity, generation: state.generation, released: false };
@@ -273,9 +278,66 @@ export class HostMessageCoordinator {
273
278
  if (state.run || state.transition) {
274
279
  throw new RuntimeMessageAuthorityInvariantError('Cannot reserve a root Turn during live ownership');
275
280
  }
276
- state.reservedRoot = { ...identity };
281
+ state.reservedRoot = { ...identity, expectedRunId: identity.runId };
277
282
  state.phase = 'open';
278
283
  }
284
+ /** Change physical ownership, not the logical queue generation or Stop identity. */
285
+ async advanceHandoffRun(identity, successorRunId, admission) {
286
+ await this.#sessionAdmission.runAdmitted(identity.sessionId, admission, async () => {
287
+ const logical = await this.#durableProof.readLogicalExecution(identity);
288
+ const state = this.#requireState(identity.sessionId);
289
+ if (!logical?.pendingHandoff ||
290
+ logical.pendingHandoff.successorRunId !== successorRunId ||
291
+ !state.reservedRoot ||
292
+ !sameRun(state.reservedRoot, identity) ||
293
+ state.transition ||
294
+ (state.phase !== 'open' && !state.stopFence) ||
295
+ state.inFlight.size !== 0 ||
296
+ (state.run
297
+ ? !state.run.released || state.run.runId !== logical.tip.runId
298
+ : state.reservedRoot.expectedRunId !== identity.runId)) {
299
+ throw new RuntimeMessageAuthorityInvariantError('Physical handoff lacks a sealed released root owner');
300
+ }
301
+ state.run = undefined;
302
+ state.reservedRoot.expectedRunId = successorRunId;
303
+ });
304
+ }
305
+ async #readDetachableHandoff(identity) {
306
+ const logical = await this.#durableProof.readLogicalExecution(identity);
307
+ const state = this.#requireState(identity.sessionId);
308
+ if (state.stopFence || state.pendingInterrupts.size !== 0)
309
+ return undefined;
310
+ if (!logical?.pendingHandoff ||
311
+ !state.reservedRoot ||
312
+ !sameRun(state.reservedRoot, identity) ||
313
+ !state.run?.released ||
314
+ state.run.runId !== logical.tip.runId ||
315
+ state.inFlight.size !== 0 ||
316
+ state.transition) {
317
+ throw new RuntimeMessageAuthorityInvariantError('Handoff cannot detach unsettled Message ownership');
318
+ }
319
+ return state;
320
+ }
321
+ async handoffResidencies(identity, admission) {
322
+ return this.#sessionAdmission.runAdmitted(identity.sessionId, admission, async () => {
323
+ const state = await this.#readDetachableHandoff(identity);
324
+ return state && allLiveEntries(state).map((entry) => entry.residency);
325
+ });
326
+ }
327
+ async detachHandoffRoot(identity, admission) {
328
+ await this.#sessionAdmission.runAdmitted(identity.sessionId, admission, async () => {
329
+ const state = await this.#readDetachableHandoff(identity);
330
+ if (!state)
331
+ throw new RuntimeMessageAuthorityInvariantError('Stop took ownership before handoff detach');
332
+ // Confirmed admissions remain durable for the next Host. Only local leases
333
+ // and handles retire; do not write cancellation receipts or a queue fence.
334
+ this.#retractQueued(state);
335
+ state.run = undefined;
336
+ state.reservedRoot = undefined;
337
+ state.phase = 'closed';
338
+ this.#maybeReclaim(identity.sessionId, state);
339
+ });
340
+ }
279
341
  abandonRootReservation(identity) {
280
342
  const state = this.#requireState(identity.sessionId);
281
343
  if (!state.reservedRoot || !sameRun(state.reservedRoot, identity) || state.run) {
@@ -296,7 +358,8 @@ export class HostMessageCoordinator {
296
358
  if (!state.reservedRoot ||
297
359
  !sameRun(state.reservedRoot, identity) ||
298
360
  !run ||
299
- !sameRun(run, identity) ||
361
+ run.turnId !== identity.turnId ||
362
+ run.runId !== state.reservedRoot.expectedRunId ||
300
363
  !run.released) {
301
364
  throw new RuntimeMessageAuthorityInvariantError('Terminal transition requires a released exact root owner');
302
365
  }
@@ -344,7 +407,7 @@ export class HostMessageCoordinator {
344
407
  state.generation += 1;
345
408
  for (const entry of allLiveEntries(state))
346
409
  entry.generation = state.generation;
347
- state.reservedRoot = { ...identity };
410
+ state.reservedRoot = { ...identity, expectedRunId: identity.runId };
348
411
  state.phase = 'open';
349
412
  this.#mutated(state);
350
413
  }
@@ -387,6 +450,7 @@ export class HostMessageCoordinator {
387
450
  const provenRootMessages = [];
388
451
  const provenSteeringMessages = [];
389
452
  const admissions = await this.#admissions.listMessageAdmissions(input.sessionId);
453
+ let logicalRunIds;
390
454
  for (const messageId of new Set(input.messageIds)) {
391
455
  messageIds.add(messageId);
392
456
  provenRootMessages.push(await this.#readProvenRootMessage(input, messageId));
@@ -396,7 +460,13 @@ export class HostMessageCoordinator {
396
460
  continue;
397
461
  }
398
462
  const proof = await this.#durableProof.readImmutableSteeringMessageProof(input.sessionId, admission.messageId);
399
- if (proof?.event.turnId === input.turnId && proof.event.runId === input.runId) {
463
+ if (proof?.event.turnId === input.turnId &&
464
+ proof.event.runId !== input.runId &&
465
+ !logicalRunIds) {
466
+ logicalRunIds = (await this.#durableProof.readLogicalExecution(input))?.runIds ?? [];
467
+ }
468
+ if (proof?.event.turnId === input.turnId &&
469
+ (proof.event.runId === input.runId || logicalRunIds?.includes(proof.event.runId))) {
400
470
  messageIds.add(admission.messageId);
401
471
  provenSteeringMessages.push({
402
472
  messageId: admission.messageId,
@@ -56,6 +56,12 @@ export class HostPluginPlatformCoordinator {
56
56
  const inspections = flattenInspections(this.platform.inspect(input.rootId));
57
57
  return { ok: true, result: boundedPage('entries', inspections, input) };
58
58
  }
59
+ if (input.view === 'tools') {
60
+ return {
61
+ ok: true,
62
+ result: boundedPage('tools', this.platform.inspectTools(input.rootId), input),
63
+ };
64
+ }
59
65
  if (input.view === 'failures') {
60
66
  return { ok: true, result: boundedPage('failures', failures, input) };
61
67
  }
@@ -42,6 +42,7 @@ export class HostPluginPlatform {
42
42
  #packages;
43
43
  #packageLoader;
44
44
  #store;
45
+ #tools;
45
46
  #authority = emptyCompositionAuthority();
46
47
  #desired = emptyCompositionState();
47
48
  #mutation = Promise.resolve();
@@ -62,6 +63,7 @@ export class HostPluginPlatform {
62
63
  this.#packageLoader =
63
64
  options.packageLoader ?? new TrustedPluginPackageLoader(controlDirectory, this.#packages);
64
65
  this.#store = options.store ?? new HostPluginCompositionStore(controlDirectory);
66
+ this.#tools = options.tools;
65
67
  }
66
68
  async recover() {
67
69
  if (this.#recoveryStarted ||
@@ -338,6 +340,10 @@ export class HostPluginPlatform {
338
340
  this.#assertReadable();
339
341
  return this.#composition.inspectTree(rootId);
340
342
  }
343
+ inspectTools(rootId) {
344
+ this.#assertReadable();
345
+ return this.#tools?.inspect(rootId) ?? Object.freeze([]);
346
+ }
341
347
  async status() {
342
348
  this.#assertReadable();
343
349
  return Object.freeze({