@zq-silk/yui 0.15.7 → 0.15.8

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 (281) hide show
  1. package/ARCHITECTURE.md +192 -399
  2. package/README.md +127 -1149
  3. package/dist/agent/adapterCatalog.js +15 -2
  4. package/dist/agent/agent.js +23 -3
  5. package/dist/agent/argumentPolicy.js +7 -1
  6. package/dist/agent/connectionPlan.js +62 -0
  7. package/dist/agent/executionComponents.js +158 -0
  8. package/dist/agent/launchEnvironment.js +31 -3
  9. package/dist/agent/managedRuntimeEnvironment.js +3 -5
  10. package/dist/{turn/turn.js → agentRun/agentRun.js} +166 -109
  11. package/dist/{turn/turnIdentity.js → agentRun/runIdentity.js} +4 -4
  12. package/dist/brief/taskBrief.js +12 -0
  13. package/dist/cli/agentConfigurationPicker.js +13 -0
  14. package/dist/cli/commandCatalog.js +157 -70
  15. package/dist/cli/interactionCandidates.js +5 -5
  16. package/dist/cli/interactionPolicy.js +38 -8
  17. package/dist/cli/invocationRouter.js +1 -1
  18. package/dist/cli/managedDiagnostics.js +28 -0
  19. package/dist/cli/operatorWizard.js +1 -7
  20. package/dist/cli/roleOptionOrder.js +27 -0
  21. package/dist/cli/roleWizard.js +50 -14
  22. package/dist/cli/updateOrchestrator.js +1 -1
  23. package/dist/cli/updatePorts.js +3 -4
  24. package/dist/cli.js +178 -95
  25. package/dist/commands/agentCommands.js +72 -14
  26. package/dist/commands/capabilityCommands.js +9 -6
  27. package/dist/commands/configCommands.js +20 -20
  28. package/dist/commands/deliveryGuardPreflight.js +2 -2
  29. package/dist/commands/executionAuditCommands.js +24 -24
  30. package/dist/commands/globalRoleCommands.js +1 -1
  31. package/dist/commands/grantCommands.js +4 -4
  32. package/dist/commands/operatorCommands.js +1 -7
  33. package/dist/commands/projectCommands.js +4 -4
  34. package/dist/commands/resourcesCommands.js +2 -2
  35. package/dist/commands/roleConfiguration.js +25 -5
  36. package/dist/commands/roleRuntimeGuard.js +4 -5
  37. package/dist/commands/sessionCommands.js +3 -7
  38. package/dist/commands/taskActivationCommands.js +259 -0
  39. package/dist/commands/taskActor.js +28 -49
  40. package/dist/commands/taskCommands.js +1188 -710
  41. package/dist/commands/taskContextCommand.js +39 -583
  42. package/dist/commands/taskExecutionCommands.js +32 -32
  43. package/dist/commands/taskInputCommands.js +40 -104
  44. package/dist/commands/taskIntegrationCommands.js +3 -2
  45. package/dist/commands/taskIntegrationQueueCommands.js +1 -1
  46. package/dist/commands/taskNextActionCommand.js +8 -8
  47. package/dist/commands/taskOverviewCommand.js +33 -45
  48. package/dist/commands/taskRemoteDeliveryCommand.js +2 -2
  49. package/dist/commands/taskRoleRuntimeStatus.js +133 -102
  50. package/dist/commands/telemetryCommands.js +36 -38
  51. package/dist/config/configCatalog.js +4 -4
  52. package/dist/config/yuiConfig.js +8 -8
  53. package/dist/context/contextSnapshot.js +10 -10
  54. package/dist/context/dispatchContext.js +11 -11
  55. package/dist/context/roleSessionContext.js +6 -3
  56. package/dist/context/{turnContextPack.js → runContextPack.js} +146 -81
  57. package/dist/context/{turnInputContract.js → runInputContract.js} +73 -60
  58. package/dist/context/sessionBootstrapManifest.js +21 -2
  59. package/dist/context/sourceRunContext.js +30 -0
  60. package/dist/context/taskContext.js +458 -0
  61. package/dist/context/wakeNotification.js +27 -27
  62. package/dist/controller/agentRuntimeObserver.js +21 -24
  63. package/dist/controller/capabilityBridge.js +17 -6
  64. package/dist/controller/clientRuntime.js +65 -92
  65. package/dist/controller/controller.js +114 -188
  66. package/dist/controller/fileSchedulerStoreAdapter.js +787 -887
  67. package/dist/controller/jobControl.js +54 -85
  68. package/dist/controller/resourceInventory.js +8 -27
  69. package/dist/controller/resourceInventoryLinux.js +12 -13
  70. package/dist/controller/runtime.js +529 -479
  71. package/dist/controller/runtimeEventInbox.js +55 -25
  72. package/dist/controller/runtimeEventProcessor.js +22 -31
  73. package/dist/controller/{runtimeHookTurnFence.js → runtimeHookRunFence.js} +91 -115
  74. package/dist/controller/runtimeLaunchCoordinator.js +80 -426
  75. package/dist/controller/runtimeObservationHook.js +14 -18
  76. package/dist/controller/sessionNotify.js +16 -24
  77. package/dist/controller/sessionOwnerReconciliation.js +168 -50
  78. package/dist/controller/structuredProviderObservation.js +138 -99
  79. package/dist/coordination/workMailbox.js +3 -3
  80. package/dist/coordination/workMailboxQueue.js +36 -33
  81. package/dist/core/boundedRpc.js +8 -1
  82. package/dist/core/controllerClient.js +20 -1
  83. package/dist/core/controllerServer.js +4 -4
  84. package/dist/doctor/doctor.js +13 -2
  85. package/dist/domain/agentResultTransport.js +9 -9
  86. package/dist/execution/codexThreadNaming.js +2 -8
  87. package/dist/execution/executionHealth.js +51 -63
  88. package/dist/execution/reviewMainRun.js +137 -0
  89. package/dist/execution/workItemExecution.js +28 -29
  90. package/dist/execution/workItemExecutionProjection.js +99 -107
  91. package/dist/execution/workItemMainRun.js +141 -0
  92. package/dist/executor/agentAdapter.js +227 -20
  93. package/dist/executor/agentConfigurationCatalog.js +126 -4
  94. package/dist/executor/agentConfigurationProbe.js +162 -4
  95. package/dist/executor/agentExecutor.js +79 -78
  96. package/dist/executor/effectiveLaunch.js +105 -18
  97. package/dist/executor/executorRegistry.js +29 -44
  98. package/dist/executor/fileRoleLaunchPlanner.js +229 -154
  99. package/dist/executor/workspacePreflightClassification.js +16 -16
  100. package/dist/grant/capabilityGrant.js +6 -3
  101. package/dist/input/inputRequest.js +12 -10
  102. package/dist/integration/gitIntegrationService.js +4 -11
  103. package/dist/integration/integrationQueueService.js +4 -4
  104. package/dist/interaction/operatorPresentation.js +1 -1
  105. package/dist/kernel/builtinCapabilities.js +247 -12
  106. package/dist/kernel/capabilityRegistry.js +64 -18
  107. package/dist/kernel/instanceHost.js +12 -1
  108. package/dist/kernel/kernelPorts.js +2 -2
  109. package/dist/lifecycle/canonicalLifecycleEvent.js +44 -49
  110. package/dist/lifecycle/exactRunTerminalization.js +449 -0
  111. package/dist/message/message.js +62 -6
  112. package/dist/message/messageContinuation.js +204 -0
  113. package/dist/observability/executionAudit.js +70 -72
  114. package/dist/observability/faultClassification.js +2 -2
  115. package/dist/observability/orchestrationMetrics.js +8 -8
  116. package/dist/operator/operatorSessionHistory.js +1 -7
  117. package/dist/output/agentConfigurationPresentation.js +8 -3
  118. package/dist/output/agentRunConfigurationPresentation.js +128 -0
  119. package/dist/output/rolePresentation.js +54 -3
  120. package/dist/plugins/pluginChild.js +104 -0
  121. package/dist/plugins/pluginIntent.js +26 -0
  122. package/dist/plugins/pluginInterpreter.js +43 -0
  123. package/dist/plugins/pluginPackage.js +101 -0
  124. package/dist/plugins/pluginProcess.js +112 -0
  125. package/dist/plugins/pluginService.js +380 -0
  126. package/dist/profile/agentProfile.js +1 -1
  127. package/dist/repository/gitWorkspace.js +26 -4
  128. package/dist/repository/project.js +19 -4
  129. package/dist/repository/taskBaseFreshness.js +13 -13
  130. package/dist/repository/taskWorkspaceCoordinator.js +20 -27
  131. package/dist/repository/taskWorkspacePreparer.js +344 -83
  132. package/dist/resources/autoResourceGc.js +3 -3
  133. package/dist/resources/liveReferences.js +3 -3
  134. package/dist/resources/projectResource.js +123 -0
  135. package/dist/resources/projectResourceService.js +421 -0
  136. package/dist/resources/resourceDiscovery.js +6 -6
  137. package/dist/resources/resourceGc.js +1 -1
  138. package/dist/resources/resourceRegistrar.js +1 -1
  139. package/dist/resources/resourceTypes.js +1 -1
  140. package/dist/review/deltaRecheck.js +3 -3
  141. package/dist/review/reviewAcceptance.js +16 -16
  142. package/dist/review/reviewDecision.js +7 -7
  143. package/dist/review/reviewRound.js +21 -20
  144. package/dist/review/reviewerAvailability.js +2 -2
  145. package/dist/role/role.js +51 -7
  146. package/dist/role/taskRoleUpdate.js +30 -0
  147. package/dist/runtime/acpProtocol.js +425 -0
  148. package/dist/runtime/acpSession.js +731 -0
  149. package/dist/runtime/acpSessionConfiguration.js +260 -0
  150. package/dist/runtime/agentDriver.js +30 -11
  151. package/dist/runtime/agentEndpoint.js +278 -0
  152. package/dist/runtime/agentEndpointIdentity.js +86 -0
  153. package/dist/runtime/agentEndpointOwnership.js +239 -0
  154. package/dist/runtime/agentError.js +2 -10
  155. package/dist/runtime/agentHost.js +565 -314
  156. package/dist/runtime/agentRunConfiguration.js +258 -0
  157. package/dist/runtime/builtinAgentDrivers.js +134 -18
  158. package/dist/runtime/builtinAgentErrorMappers.js +55 -3
  159. package/dist/runtime/builtinTranscriptUsage.js +1 -1
  160. package/dist/runtime/claude-process-owner +0 -0
  161. package/dist/runtime/codexAppServerRuntime.js +38 -30
  162. package/dist/runtime/codexInteractiveHost.js +41 -6
  163. package/dist/runtime/continuationManager.js +2 -6
  164. package/dist/runtime/executionEnvironment.js +30 -0
  165. package/dist/runtime/firstProgressAdvisory.js +11 -11
  166. package/dist/runtime/index.js +4 -3
  167. package/dist/runtime/jsonLineChannel.js +109 -0
  168. package/dist/runtime/launchBroker.js +91 -16
  169. package/dist/runtime/launchDiagnostics.js +2 -2
  170. package/dist/runtime/lifecycleReservation.js +10 -18
  171. package/dist/runtime/managedCaller.js +61 -17
  172. package/dist/runtime/nativeSessionControl.js +102 -0
  173. package/dist/runtime/ports.js +6 -21
  174. package/dist/runtime/processExitObservation.js +8 -7
  175. package/dist/runtime/promptEnvelope.js +17 -6
  176. package/dist/runtime/providerContinuation.js +3 -9
  177. package/dist/runtime/providerContinuationReconciliationService.js +4 -13
  178. package/dist/runtime/providerControl.js +2 -7
  179. package/dist/runtime/providerRuntimeIdentity.js +110 -222
  180. package/dist/runtime/providerRuntimeReconciler.js +5 -9
  181. package/dist/runtime/runtimeBinding.js +0 -1
  182. package/dist/runtime/runtimeContinuationProjection.js +4 -7
  183. package/dist/runtime/runtimeDeadlines.js +9 -0
  184. package/dist/runtime/runtimeHealthPolicy.js +1 -1
  185. package/dist/runtime/runtimeObservation.js +29 -65
  186. package/dist/runtime/runtimeProjection.js +43 -51
  187. package/dist/runtime/runtimeSessionCandidate.js +1 -3
  188. package/dist/runtime/sessionLaunchRequest.js +3 -7
  189. package/dist/runtime/sessionOwnerIdentity.js +7 -54
  190. package/dist/runtime/sessionOwnerRegistry.js +22 -17
  191. package/dist/runtime/sessionReconciliation.js +4 -8
  192. package/dist/runtime/sessionTerminationGuard.js +70 -259
  193. package/dist/runtime/sessionTokenMetrics.js +5 -16
  194. package/dist/runtime/structuredProviderHost.js +237 -117
  195. package/dist/runtime/taskRuntimeIsolation.js +39 -122
  196. package/dist/runtime/tmuxAdapters.js +39 -86
  197. package/dist/scheduler/activeRoleRunDelivery.js +354 -0
  198. package/dist/scheduler/leaderWakeupProcessor.js +75 -266
  199. package/dist/scheduler/operatorInputNotificationProcessor.js +1 -1
  200. package/dist/scheduler/ports.js +80 -9
  201. package/dist/scheduler/{roleTurnLiveness.js → roleRunLiveness.js} +26 -30
  202. package/dist/scheduler/{roleTurnStall.js → roleRunStall.js} +128 -139
  203. package/dist/scheduler/taskExecutionProjection.js +120 -124
  204. package/dist/scheduler/taskObservabilityProjection.js +29 -29
  205. package/dist/scheduler/taskWake.js +11 -4
  206. package/dist/scheduler/wakeReason.js +9 -1
  207. package/dist/setup/setupCommand.js +1 -0
  208. package/dist/storage/migrations/agentRunContract.js +159 -0
  209. package/dist/storage/migrations/removeRuntimeGeneration.js +207 -0
  210. package/dist/storage/sqliteSchema.js +431 -5
  211. package/dist/storage/sqliteStore.js +375 -220
  212. package/dist/storage/storageVersions.js +1 -1
  213. package/dist/storage/storeRpc.js +10 -5
  214. package/dist/storage/taskStore.js +13 -11
  215. package/dist/storage/upgrade/upgradeOrchestrator.js +5 -7
  216. package/dist/surface/surfaceContributions.js +102 -0
  217. package/dist/task/completionReadiness.js +32 -6
  218. package/dist/task/deliveryGuard.js +16 -16
  219. package/dist/task/draftPlan.js +72 -12
  220. package/dist/task/nextAction.js +144 -128
  221. package/dist/task/remoteDelivery.js +6 -6
  222. package/dist/task/task.js +184 -18
  223. package/dist/task/taskActivation.js +301 -0
  224. package/dist/task/taskActivationService.js +392 -0
  225. package/dist/task/taskRecordReference.js +5 -4
  226. package/dist/task/taskRecordRetirement.js +1 -1
  227. package/dist/telemetry/sqliteTelemetryStore.js +55 -68
  228. package/dist/telemetry/telemetryConfig.js +14 -14
  229. package/dist/telemetry/telemetryWiring.js +2 -2
  230. package/dist/web/assets/assetManifest.js +2 -0
  231. package/dist/web/assets/client/app.js +120 -20
  232. package/dist/web/assets/client/components.js +87 -54
  233. package/dist/web/assets/client/i18n.js +83 -41
  234. package/dist/web/assets/client/markdown.js +1 -1
  235. package/dist/web/assets/client/taskSurface.js +353 -0
  236. package/dist/web/assets/client/view.js +49 -44
  237. package/dist/web/assets/shell.js +1 -1
  238. package/dist/web/assets/styles/cards.js +22 -4
  239. package/dist/web/controllerWeb.js +60 -0
  240. package/dist/web/webMutation.js +28 -0
  241. package/dist/web/webServer.js +118 -8
  242. package/dist/web/webSnapshot.js +81 -74
  243. package/dist/web/webTaskSurface.js +64 -0
  244. package/dist/workItem/dependencyGate.js +1 -1
  245. package/dist/workItem/workItem.js +80 -48
  246. package/dist/workspace/workItemChangeSetManager.js +16 -9
  247. package/docs/agent-result-consumption.md +94 -0
  248. package/docs/agent-runtime-drivers.md +91 -0
  249. package/docs/architecture/README.md +38 -0
  250. package/docs/architecture/capabilities-and-resources.md +79 -0
  251. package/docs/managed-turn-and-session-runtime.md +222 -0
  252. package/docs/observability/README.md +81 -0
  253. package/docs/plugin-sdk.md +290 -0
  254. package/docs/provider-runtime.md +163 -0
  255. package/docs/release-workflow.md +303 -0
  256. package/docs/roles-and-configuration.md +113 -0
  257. package/docs/sqlite-control-plane-design.md +76 -0
  258. package/docs/task-dag-semantics.md +57 -0
  259. package/docs/task-delivery.md +103 -0
  260. package/docs/task-local-identity.md +6 -6
  261. package/docs/testing/verification-levels.md +86 -0
  262. package/i18n/README.zh-CN.md +98 -739
  263. package/package.json +2 -2
  264. package/skills/yui-leader/SKILL.md +130 -103
  265. package/skills/yui-leader/references/integration.md +39 -0
  266. package/skills/yui-leader/references/replicated-execution.md +42 -0
  267. package/skills/yui-leader/references/task-plugins.md +33 -0
  268. package/skills/yui-operator/SKILL.md +30 -59
  269. package/skills/yui-reviewer/SKILL.md +35 -36
  270. package/skills/yui-runtime/SKILL.md +88 -24
  271. package/skills/yui-runtime/references/publication.md +22 -0
  272. package/skills/yui-runtime/references/recovery.md +64 -0
  273. package/skills/yui-worker/SKILL.md +37 -39
  274. package/dist/cli/roleOptionCatalog.js +0 -68
  275. package/dist/context/sourceTurnContext.js +0 -30
  276. package/dist/execution/reviewMainTurn.js +0 -161
  277. package/dist/execution/workItemMainTurn.js +0 -164
  278. package/dist/lifecycle/exactTurnTerminalization.js +0 -407
  279. package/dist/runtime/preallocatedNativeSession.js +0 -13
  280. package/dist/runtime/runtimeStopReceipt.js +0 -42
  281. package/dist/scheduler/activeRoleTurnDelivery.js +0 -315
@@ -3,7 +3,7 @@ import { isDeepStrictEqual } from "node:util";
3
3
  import { closeSync, constants, existsSync, fchmodSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { createRuntimeObservation, isRuntimeTokenEvidence } from "../runtime/runtimeObservation.js";
6
- import { boundedTurnFailureDiagnostic, transportAgentResult } from "../domain/agentResultTransport.js";
6
+ import { boundedRunFailureDiagnostic, transportAgentResult } from "../domain/agentResultTransport.js";
7
7
  export const MAX_RUNTIME_EVENT_FILE_BYTES = 16 * 1024 * 1024;
8
8
  const RUNTIME_EVENT_DIRECTORY = join("runtime", "inbox");
9
9
  const INVALID_RUNTIME_EVENT_DIRECTORY = join("runtime", "inbox-invalid");
@@ -40,7 +40,7 @@ export class FileRuntimeEventInbox {
40
40
  });
41
41
  return this.publish(event);
42
42
  }
43
- enqueueTurnTerminal(input) {
43
+ enqueueRunTerminal(input) {
44
44
  const normalized = normalizeNativeTurnTerminalInput(input);
45
45
  return this.publish(Object.freeze({
46
46
  schemaVersion: 1,
@@ -111,7 +111,7 @@ export class FileRuntimeEventInbox {
111
111
  catch {
112
112
  throw invalidEvent(`Runtime event JSON is invalid: ${id}`);
113
113
  }
114
- const event = parseRuntimeEvent(value);
114
+ const event = parseRuntimeEvent(decodeInboxV1(value));
115
115
  if (event.id !== id || runtimeEventId(event.type, event) !== id) {
116
116
  throw invalidEvent(`Runtime event identity is invalid: ${id}`);
117
117
  }
@@ -169,7 +169,7 @@ export class FileRuntimeEventInbox {
169
169
  return this.publishUnlocked(event);
170
170
  }
171
171
  publishUnlocked(event) {
172
- const content = `${JSON.stringify(event)}\n`;
172
+ const content = `${JSON.stringify(encodeInboxV1(event))}\n`;
173
173
  if (Buffer.byteLength(content, "utf8") > MAX_RUNTIME_EVENT_FILE_BYTES) {
174
174
  throw new RuntimeEventInboxError("RUNTIME_EVENT_TOO_LARGE", "Runtime event exceeds the durable inbox limit.");
175
175
  }
@@ -276,10 +276,9 @@ function runtimeEventId(type, input) {
276
276
  provider.roleName,
277
277
  provider.agentId,
278
278
  provider.adapterId,
279
- provider.runtimeGenerationId ?? null,
280
279
  provider.nativeSessionId,
281
280
  provider.nativeTurnId,
282
- provider.turnId ?? null
281
+ provider.runId ?? null
283
282
  ];
284
283
  return `turn-${createHash("sha256").update(JSON.stringify(common)).digest("hex")}`;
285
284
  }
@@ -289,7 +288,7 @@ function normalizeNativeTurnTerminalInput(input) {
289
288
  throw invalidEvent();
290
289
  if (!["completed", "failed", "cancelled"].includes(input.providerStatus))
291
290
  throw invalidEvent();
292
- const outcome = normalizeRuntimeTurnTerminalOutcome(input.outcome);
291
+ const outcome = normalizeRuntimeRunTerminalOutcome(input.outcome);
293
292
  if (outcome.status === "completed" && input.providerStatus !== "completed") {
294
293
  throw invalidEvent("Only a completed Provider Turn may carry a completed Agent result.");
295
294
  }
@@ -298,14 +297,11 @@ function normalizeNativeTurnTerminalInput(input) {
298
297
  roleName: requireIdentityText(input.roleName, "Role name"),
299
298
  agentId: requireIdentityText(input.agentId, "Agent id"),
300
299
  adapterId: input.adapterId,
301
- ...(input.runtimeGenerationId === undefined
302
- ? {}
303
- : { runtimeGenerationId: requireIdentityText(input.runtimeGenerationId, "Runtime generation id") }),
304
300
  nativeSessionId: requireIdentityText(input.nativeSessionId, "Native session id"),
305
301
  nativeTurnId: requireIdentityText(input.nativeTurnId, "Provider native Turn id"),
306
- ...(input.turnId === undefined
302
+ ...(input.runId === undefined
307
303
  ? {}
308
- : { turnId: requireIdentityText(input.turnId, "Turn id") }),
304
+ : { runId: requireIdentityText(input.runId, "AgentRun id") }),
309
305
  ...(input.title === undefined
310
306
  ? {}
311
307
  : { title: requireIdentityText(input.title, "Session title") }),
@@ -318,9 +314,9 @@ function normalizeNativeTurnTerminalInput(input) {
318
314
  ? { ...common, taskId: requireIdentityText(input.taskId, "Task id") }
319
315
  : common;
320
316
  }
321
- function normalizeRuntimeTurnTerminalOutcome(input) {
317
+ function normalizeRuntimeRunTerminalOutcome(input) {
322
318
  if (!isObject(input)) {
323
- throw invalidEvent("Runtime Turn terminal outcome is invalid.");
319
+ throw invalidEvent("Runtime AgentRun terminal outcome is invalid.");
324
320
  }
325
321
  if (input.status === "completed")
326
322
  return transportAgentResult(input.output);
@@ -336,14 +332,52 @@ function normalizeRuntimeTurnTerminalOutcome(input) {
336
332
  "cancelled"
337
333
  ]
338
334
  .includes(input.failureReason)) {
339
- throw invalidEvent("Runtime Turn failure outcome is invalid.");
335
+ throw invalidEvent("Runtime AgentRun failure outcome is invalid.");
340
336
  }
341
337
  return {
342
338
  status: "failed",
343
- diagnostic: boundedTurnFailureDiagnostic(input.diagnostic),
344
- failureReason: input.failureReason
339
+ diagnostic: boundedRunFailureDiagnostic(input.diagnostic),
340
+ failureReason: input.failureReason,
341
+ ...(typeof input.output === "string" && transportAgentResult(input.output).status === "completed"
342
+ ? { output: input.output } : {})
345
343
  };
346
344
  }
345
+ /** The already deployed inbox v1 is a transport envelope, not a second domain
346
+ * schema. Keep its wire keys and opaque ids stable so pre-upgrade pending
347
+ * facts remain readable atomically. Public/in-process values use runId.
348
+ * Retire this codec only with a new inbox protocol after all v1 producers
349
+ * and pending files have drained; do not introduce dual domain-store reads.
350
+ */
351
+ function inboxReference(value, encode) {
352
+ const from = encode ? "runId" : "turnId";
353
+ const to = encode ? "turnId" : "runId";
354
+ if (Object.hasOwn(value, to))
355
+ throw invalidEvent("Inbox v1 reference uses the wrong wire shape.");
356
+ const { [from]: id, ...rest } = value;
357
+ return id === undefined ? rest : { ...rest, [to]: id };
358
+ }
359
+ function inboxEnvelope(value, encode) {
360
+ if (!isObject(value))
361
+ throw invalidEvent();
362
+ if (value.type === "native-turn-terminal")
363
+ return inboxReference(value, encode);
364
+ if (value.type !== "runtime-observation")
365
+ return value;
366
+ if (!isObject(value.observation) || !isObject(value.observation.fence))
367
+ throw invalidEvent();
368
+ const observation = value.observation;
369
+ let payload = observation.payload;
370
+ if (isObject(payload?.failure)) {
371
+ const from = encode ? "runTerminal" : "turnTerminal";
372
+ const to = encode ? "turnTerminal" : "runTerminal";
373
+ const { [from]: terminal, ...failure } = payload.failure;
374
+ payload = { ...payload, failure: terminal === undefined ? failure : { ...failure, [to]: terminal } };
375
+ }
376
+ return { ...value, observation: { ...observation, payload,
377
+ fence: inboxReference(observation.fence, encode) } };
378
+ }
379
+ function encodeInboxV1(value) { return inboxEnvelope(value, true); }
380
+ function decodeInboxV1(value) { return inboxEnvelope(value, false); }
347
381
  function normalizeDurableJobTerminalInput(input) {
348
382
  if (input.scope !== "task")
349
383
  throw invalidEvent();
@@ -418,16 +452,14 @@ function parseNativeTurnTerminalEvent(value) {
418
452
  "schemaVersion", "id", "type", "receivedAt", "scope", "taskId",
419
453
  "roleName", "agentId", "adapterId", "nativeSessionId", "nativeTurnId",
420
454
  "providerStatus", "outcome",
421
- ...(value.runtimeGenerationId === undefined ? [] : ["runtimeGenerationId"]),
422
- ...(value.turnId === undefined ? [] : ["turnId"]),
455
+ ...(value.runId === undefined ? [] : ["runId"]),
423
456
  ...(value.title === undefined ? [] : ["title"])
424
457
  ]
425
458
  : [
426
459
  "schemaVersion", "id", "type", "receivedAt", "scope",
427
460
  "roleName", "agentId", "adapterId", "nativeSessionId", "nativeTurnId",
428
461
  "providerStatus", "outcome",
429
- ...(value.runtimeGenerationId === undefined ? [] : ["runtimeGenerationId"]),
430
- ...(value.turnId === undefined ? [] : ["turnId"]),
462
+ ...(value.runId === undefined ? [] : ["runId"]),
431
463
  ...(value.title === undefined ? [] : ["title"])
432
464
  ];
433
465
  if ((scope !== "task" && scope !== "global")
@@ -441,10 +473,9 @@ function parseNativeTurnTerminalEvent(value) {
441
473
  roleName: value.roleName,
442
474
  agentId: value.agentId,
443
475
  adapterId: value.adapterId,
444
- ...(value.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: value.runtimeGenerationId }),
445
476
  nativeSessionId: value.nativeSessionId,
446
477
  nativeTurnId: value.nativeTurnId,
447
- ...(value.turnId === undefined ? {} : { turnId: value.turnId }),
478
+ ...(value.runId === undefined ? {} : { runId: value.runId }),
448
479
  ...(value.title === undefined ? {} : { title: value.title }),
449
480
  providerStatus: value.providerStatus,
450
481
  outcome: value.outcome
@@ -503,11 +534,10 @@ function hasSameIdentity(left, right) {
503
534
  && (!("roleName" in left) || !("roleName" in right) || left.roleName === right.roleName)
504
535
  && (!("agentId" in left) || !("agentId" in right) || left.agentId === right.agentId)
505
536
  && (!("adapterId" in left) || !("adapterId" in right) || left.adapterId === right.adapterId)
506
- && (!("runtimeGenerationId" in left) || !("runtimeGenerationId" in right) || left.runtimeGenerationId === right.runtimeGenerationId)
507
537
  && (!("nativeSessionId" in left)
508
538
  || !("nativeSessionId" in right)
509
539
  || left.nativeSessionId === right.nativeSessionId)
510
- && (!("turnId" in left) || !("turnId" in right) || left.turnId === right.turnId)
540
+ && (!("runId" in left) || !("runId" in right) || left.runId === right.runId)
511
541
  && (!("jobId" in left) || !("jobId" in right) || left.jobId === right.jobId);
512
542
  }
513
543
  function compareRuntimeEvents(left, right) {
@@ -189,10 +189,9 @@ export class FileRuntimeEventProcessor {
189
189
  roleName: event.roleName,
190
190
  agentId: event.agentId,
191
191
  adapterId: event.adapterId,
192
- ...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
193
192
  nativeSessionId: event.nativeSessionId,
194
193
  nativeTurnId: event.nativeTurnId,
195
- ...(event.turnId === undefined ? {} : { turnId: event.turnId }),
194
+ ...(event.runId === undefined ? {} : { runId: event.runId }),
196
195
  providerStatus: event.providerStatus,
197
196
  outcome: event.outcome
198
197
  };
@@ -202,15 +201,15 @@ export class FileRuntimeEventProcessor {
202
201
  this.recordObsolete(event, task.status === "archived" ? "task-archived" : "task-retired", now);
203
202
  return "obsolete";
204
203
  }
205
- const disposition = this.observer.classifyRuntimeTurnTerminal?.(input) ?? "apply";
204
+ const disposition = this.observer.classifyRuntimeRunTerminal?.(input) ?? "apply";
206
205
  if (disposition === "deferred")
207
206
  return disposition;
208
207
  if (disposition === "obsolete") {
209
208
  this.recordObsolete(event, "identity-mismatch-or-terminal", now);
210
209
  return disposition;
211
210
  }
212
- const observed = this.observer.observeRuntimeTurnTerminal(input, now);
213
- if (isObsoleteRuntimeTurnObservation(observed)) {
211
+ const observed = this.observer.observeRuntimeRunTerminal(input, now);
212
+ if (isObsoleteRuntimeRunObservation(observed)) {
214
213
  this.recordObsolete(event, "runtime-cleanup-or-stopped-session", now);
215
214
  return "obsolete";
216
215
  }
@@ -221,15 +220,14 @@ export class FileRuntimeEventProcessor {
221
220
  roleName: event.roleName,
222
221
  agentId: event.agentId,
223
222
  adapterId: event.adapterId,
224
- ...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
225
223
  nativeSessionId: event.nativeSessionId,
226
224
  nativeTurnId: event.nativeTurnId,
227
225
  ...(event.title === undefined ? {} : { title: event.title }),
228
226
  providerStatus: event.providerStatus,
229
227
  outcome: event.outcome
230
228
  };
231
- if (this.observer.classifyGlobalRuntimeTurnTerminal?.(input) !== "obsolete") {
232
- this.observer.observeGlobalRuntimeTurnTerminal(input, now);
229
+ if (this.observer.classifyGlobalRuntimeRunTerminal?.(input) !== "obsolete") {
230
+ this.observer.observeGlobalRuntimeRunTerminal(input, now);
233
231
  return "applied";
234
232
  }
235
233
  return "obsolete";
@@ -247,8 +245,7 @@ export class FileRuntimeEventProcessor {
247
245
  taskId: event.taskId,
248
246
  roleName: fence.roleName,
249
247
  agentId: fence.agentId,
250
- ...(fence.turnId === undefined ? {} : { turnId: fence.turnId }),
251
- runtimeGenerationId: fence.runtimeGenerationId,
248
+ ...(fence.runId === undefined ? {} : { runId: fence.runId }),
252
249
  nativeSessionId: fence.nativeSessionId,
253
250
  reason
254
251
  }, now);
@@ -264,8 +261,7 @@ export class FileRuntimeEventProcessor {
264
261
  taskId: event.taskId,
265
262
  roleName: event.roleName,
266
263
  agentId: event.agentId,
267
- ...(event.turnId === undefined ? {} : { turnId: event.turnId }),
268
- ...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
264
+ ...(event.runId === undefined ? {} : { runId: event.runId }),
269
265
  nativeSessionId: event.nativeSessionId,
270
266
  reason
271
267
  }, now);
@@ -396,9 +392,8 @@ function progressStreamKey(event) {
396
392
  fence.roleName,
397
393
  fence.agentId,
398
394
  fence.driverId,
399
- fence.runtimeGenerationId,
400
395
  fence.nativeSessionId ?? null,
401
- fence.turnId ?? null,
396
+ fence.runId ?? null,
402
397
  payload.activity,
403
398
  isRuntimeTokenEvidence(event.observation) ? "usage" : "signal"
404
399
  ]);
@@ -432,7 +427,7 @@ function positiveInteger(value, fallback) {
432
427
  }
433
428
  return resolved;
434
429
  }
435
- function isObsoleteRuntimeTurnObservation(value) {
430
+ function isObsoleteRuntimeRunObservation(value) {
436
431
  return typeof value === "object"
437
432
  && value !== null
438
433
  && value.disposition === "obsolete";
@@ -516,10 +511,10 @@ export function createAsyncRuntimeObserver(invoke) {
516
511
  return {
517
512
  getTask: (taskId) => call("getTask", [taskId]),
518
513
  observeRuntimeObservation: (input, now) => withNow("observeRuntimeObservation", input, now),
519
- observeRuntimeTurnTerminal: (input, now) => withNow("observeRuntimeTurnTerminal", input, now),
520
- observeGlobalRuntimeTurnTerminal: (input, now) => withNow("observeGlobalRuntimeTurnTerminal", input, now),
521
- classifyRuntimeTurnTerminal: (input) => call("classifyRuntimeTurnTerminal", [input]),
522
- classifyGlobalRuntimeTurnTerminal: (input) => call("classifyGlobalRuntimeTurnTerminal", [input]),
514
+ observeRuntimeRunTerminal: (input, now) => withNow("observeRuntimeRunTerminal", input, now),
515
+ observeGlobalRuntimeRunTerminal: (input, now) => withNow("observeGlobalRuntimeRunTerminal", input, now),
516
+ classifyRuntimeRunTerminal: (input) => call("classifyRuntimeRunTerminal", [input]),
517
+ classifyGlobalRuntimeRunTerminal: (input) => call("classifyGlobalRuntimeRunTerminal", [input]),
523
518
  observeObsoleteRuntimeEvent: (input, now) => withNow("observeObsoleteRuntimeEvent", input, now)
524
519
  };
525
520
  }
@@ -632,10 +627,9 @@ export class AsyncRuntimeEventProcessor {
632
627
  roleName: event.roleName,
633
628
  agentId: event.agentId,
634
629
  adapterId: event.adapterId,
635
- ...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
636
630
  nativeSessionId: event.nativeSessionId,
637
631
  nativeTurnId: event.nativeTurnId,
638
- ...(event.turnId === undefined ? {} : { turnId: event.turnId }),
632
+ ...(event.runId === undefined ? {} : { runId: event.runId }),
639
633
  providerStatus: event.providerStatus,
640
634
  outcome: event.outcome
641
635
  };
@@ -645,15 +639,15 @@ export class AsyncRuntimeEventProcessor {
645
639
  await this.recordObsolete(event, task.status === "archived" ? "task-archived" : "task-retired", now);
646
640
  return "obsolete";
647
641
  }
648
- const disposition = (await this.observer.classifyRuntimeTurnTerminal?.(input)) ?? "apply";
642
+ const disposition = (await this.observer.classifyRuntimeRunTerminal?.(input)) ?? "apply";
649
643
  if (disposition === "deferred")
650
644
  return disposition;
651
645
  if (disposition === "obsolete") {
652
646
  await this.recordObsolete(event, "identity-mismatch-or-terminal", now);
653
647
  return disposition;
654
648
  }
655
- const observed = await this.observer.observeRuntimeTurnTerminal(input, now);
656
- if (isObsoleteRuntimeTurnObservation(observed)) {
649
+ const observed = await this.observer.observeRuntimeRunTerminal(input, now);
650
+ if (isObsoleteRuntimeRunObservation(observed)) {
657
651
  await this.recordObsolete(event, "runtime-cleanup-or-stopped-session", now);
658
652
  return "obsolete";
659
653
  }
@@ -664,15 +658,14 @@ export class AsyncRuntimeEventProcessor {
664
658
  roleName: event.roleName,
665
659
  agentId: event.agentId,
666
660
  adapterId: event.adapterId,
667
- ...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
668
661
  nativeSessionId: event.nativeSessionId,
669
662
  nativeTurnId: event.nativeTurnId,
670
663
  ...(event.title === undefined ? {} : { title: event.title }),
671
664
  providerStatus: event.providerStatus,
672
665
  outcome: event.outcome
673
666
  };
674
- if ((await this.observer.classifyGlobalRuntimeTurnTerminal?.(input)) !== "obsolete") {
675
- await this.observer.observeGlobalRuntimeTurnTerminal(input, now);
667
+ if ((await this.observer.classifyGlobalRuntimeRunTerminal?.(input)) !== "obsolete") {
668
+ await this.observer.observeGlobalRuntimeRunTerminal(input, now);
676
669
  return "applied";
677
670
  }
678
671
  return "obsolete";
@@ -690,8 +683,7 @@ export class AsyncRuntimeEventProcessor {
690
683
  taskId: event.taskId,
691
684
  roleName: fence.roleName,
692
685
  agentId: fence.agentId,
693
- ...(fence.turnId === undefined ? {} : { turnId: fence.turnId }),
694
- runtimeGenerationId: fence.runtimeGenerationId,
686
+ ...(fence.runId === undefined ? {} : { runId: fence.runId }),
695
687
  nativeSessionId: fence.nativeSessionId,
696
688
  reason
697
689
  }, now);
@@ -703,8 +695,7 @@ export class AsyncRuntimeEventProcessor {
703
695
  taskId: event.taskId,
704
696
  roleName: event.roleName,
705
697
  agentId: event.agentId,
706
- ...(event.turnId === undefined ? {} : { turnId: event.turnId }),
707
- ...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
698
+ ...(event.runId === undefined ? {} : { runId: event.runId }),
708
699
  nativeSessionId: event.nativeSessionId,
709
700
  reason
710
701
  }, now);