@zq-silk/yui 0.15.7 → 0.15.9

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 (308) hide show
  1. package/ARCHITECTURE.md +194 -399
  2. package/ARCHITECTURE.zh-CN.md +151 -0
  3. package/README.md +306 -1131
  4. package/dist/agent/adapterCatalog.js +15 -2
  5. package/dist/agent/agent.js +23 -3
  6. package/dist/agent/argumentPolicy.js +7 -1
  7. package/dist/agent/connectionPlan.js +62 -0
  8. package/dist/agent/executionComponents.js +158 -0
  9. package/dist/agent/launchEnvironment.js +31 -3
  10. package/dist/agent/managedRuntimeEnvironment.js +3 -5
  11. package/dist/{turn/turn.js → agentRun/agentRun.js} +166 -109
  12. package/dist/{turn/turnIdentity.js → agentRun/runIdentity.js} +4 -4
  13. package/dist/artifacts/artifactCapability.js +74 -0
  14. package/dist/artifacts/artifactCommitLock.js +249 -0
  15. package/dist/artifacts/artifactPaths.js +151 -0
  16. package/dist/artifacts/gitArtifactRef.js +146 -0
  17. package/dist/artifacts/managedGit.js +332 -0
  18. package/dist/artifacts/taskArtifactRepository.js +277 -0
  19. package/dist/brief/taskBrief.js +12 -0
  20. package/dist/cli/agentConfigurationPicker.js +13 -0
  21. package/dist/cli/commandCatalog.js +165 -74
  22. package/dist/cli/interactionCandidates.js +5 -5
  23. package/dist/cli/interactionPolicy.js +38 -8
  24. package/dist/cli/invocationRouter.js +1 -1
  25. package/dist/cli/managedDiagnostics.js +28 -0
  26. package/dist/cli/operatorWizard.js +1 -7
  27. package/dist/cli/roleOptionOrder.js +27 -0
  28. package/dist/cli/roleWizard.js +50 -14
  29. package/dist/cli/updateOrchestrator.js +1 -1
  30. package/dist/cli/updatePorts.js +3 -4
  31. package/dist/cli.js +245 -95
  32. package/dist/commands/agentCommands.js +72 -14
  33. package/dist/commands/capabilityCommands.js +9 -6
  34. package/dist/commands/configCommands.js +20 -20
  35. package/dist/commands/deliveryGuardPreflight.js +2 -2
  36. package/dist/commands/executionAuditCommands.js +24 -24
  37. package/dist/commands/globalRoleCommands.js +1 -1
  38. package/dist/commands/grantCommands.js +4 -4
  39. package/dist/commands/operatorCommands.js +34 -9
  40. package/dist/commands/projectCommands.js +4 -4
  41. package/dist/commands/resourcesCommands.js +2 -2
  42. package/dist/commands/roleConfiguration.js +25 -5
  43. package/dist/commands/roleRuntimeGuard.js +4 -5
  44. package/dist/commands/sessionCommands.js +3 -7
  45. package/dist/commands/taskActivationCommands.js +281 -0
  46. package/dist/commands/taskActor.js +28 -49
  47. package/dist/commands/taskCommands.js +1461 -720
  48. package/dist/commands/taskContextCommand.js +39 -583
  49. package/dist/commands/taskExecutionCommands.js +32 -32
  50. package/dist/commands/taskInputCommands.js +40 -104
  51. package/dist/commands/taskIntegrationCommands.js +3 -2
  52. package/dist/commands/taskIntegrationQueueCommands.js +1 -1
  53. package/dist/commands/taskNextActionCommand.js +8 -8
  54. package/dist/commands/taskOverviewCommand.js +33 -45
  55. package/dist/commands/taskRemoteDeliveryCommand.js +2 -2
  56. package/dist/commands/taskRoleRuntimeStatus.js +133 -102
  57. package/dist/commands/telemetryCommands.js +36 -38
  58. package/dist/config/configCatalog.js +4 -4
  59. package/dist/config/yuiConfig.js +8 -8
  60. package/dist/context/contextSnapshot.js +10 -10
  61. package/dist/context/dispatchContext.js +11 -11
  62. package/dist/context/roleSessionContext.js +6 -3
  63. package/dist/context/{turnContextPack.js → runContextPack.js} +158 -81
  64. package/dist/context/{turnInputContract.js → runInputContract.js} +73 -60
  65. package/dist/context/sessionBootstrapManifest.js +21 -2
  66. package/dist/context/sourceRunContext.js +30 -0
  67. package/dist/context/taskContext.js +481 -0
  68. package/dist/context/wakeNotification.js +27 -27
  69. package/dist/controller/agentRuntimeObserver.js +21 -24
  70. package/dist/controller/capabilityBridge.js +17 -6
  71. package/dist/controller/clientRuntime.js +65 -92
  72. package/dist/controller/controller.js +120 -188
  73. package/dist/controller/fileSchedulerStoreAdapter.js +787 -887
  74. package/dist/controller/jobControl.js +54 -85
  75. package/dist/controller/resourceInventory.js +8 -27
  76. package/dist/controller/resourceInventoryLinux.js +12 -13
  77. package/dist/controller/runtime.js +529 -479
  78. package/dist/controller/runtimeEventInbox.js +55 -25
  79. package/dist/controller/runtimeEventProcessor.js +22 -31
  80. package/dist/controller/{runtimeHookTurnFence.js → runtimeHookRunFence.js} +91 -115
  81. package/dist/controller/runtimeLaunchCoordinator.js +80 -426
  82. package/dist/controller/runtimeObservationHook.js +14 -18
  83. package/dist/controller/sessionNotify.js +16 -24
  84. package/dist/controller/sessionOwnerReconciliation.js +168 -50
  85. package/dist/controller/structuredProviderObservation.js +138 -99
  86. package/dist/coordination/workMailbox.js +3 -3
  87. package/dist/coordination/workMailboxQueue.js +36 -33
  88. package/dist/core/boundedRpc.js +8 -1
  89. package/dist/core/controllerClient.js +20 -1
  90. package/dist/core/controllerServer.js +4 -4
  91. package/dist/doctor/doctor.js +13 -2
  92. package/dist/domain/agentResultTransport.js +9 -9
  93. package/dist/execution/codexThreadNaming.js +2 -8
  94. package/dist/execution/executionHealth.js +51 -63
  95. package/dist/execution/reviewMainRun.js +137 -0
  96. package/dist/execution/workItemExecution.js +28 -29
  97. package/dist/execution/workItemExecutionProjection.js +99 -107
  98. package/dist/execution/workItemMainRun.js +141 -0
  99. package/dist/executor/agentAdapter.js +227 -20
  100. package/dist/executor/agentConfigurationCatalog.js +126 -4
  101. package/dist/executor/agentConfigurationProbe.js +162 -4
  102. package/dist/executor/agentExecutor.js +79 -78
  103. package/dist/executor/effectiveLaunch.js +105 -18
  104. package/dist/executor/executorRegistry.js +29 -44
  105. package/dist/executor/fileRoleLaunchPlanner.js +229 -154
  106. package/dist/executor/workspacePreflightClassification.js +16 -16
  107. package/dist/grant/capabilityGrant.js +6 -3
  108. package/dist/input/inputRequest.js +12 -10
  109. package/dist/integration/gitIntegrationService.js +4 -11
  110. package/dist/integration/integrationQueueService.js +4 -4
  111. package/dist/interaction/operatorPresentation.js +1 -1
  112. package/dist/kernel/builtinCapabilities.js +255 -12
  113. package/dist/kernel/capabilityRegistry.js +64 -18
  114. package/dist/kernel/instanceHost.js +12 -1
  115. package/dist/kernel/kernelPorts.js +2 -2
  116. package/dist/lifecycle/canonicalLifecycleEvent.js +44 -49
  117. package/dist/lifecycle/exactRunTerminalization.js +449 -0
  118. package/dist/message/message.js +118 -6
  119. package/dist/message/messageContinuation.js +204 -0
  120. package/dist/observability/executionAudit.js +70 -72
  121. package/dist/observability/faultClassification.js +2 -2
  122. package/dist/observability/orchestrationMetrics.js +8 -8
  123. package/dist/operator/operatorSessionHistory.js +1 -7
  124. package/dist/output/agentConfigurationPresentation.js +8 -3
  125. package/dist/output/agentRunConfigurationPresentation.js +128 -0
  126. package/dist/output/rolePresentation.js +54 -3
  127. package/dist/plugins/pluginChild.js +104 -0
  128. package/dist/plugins/pluginIntent.js +26 -0
  129. package/dist/plugins/pluginInterpreter.js +43 -0
  130. package/dist/plugins/pluginPackage.js +101 -0
  131. package/dist/plugins/pluginProcess.js +112 -0
  132. package/dist/plugins/pluginService.js +388 -0
  133. package/dist/profile/agentProfile.js +1 -1
  134. package/dist/repository/gitWorkspace.js +26 -4
  135. package/dist/repository/project.js +19 -4
  136. package/dist/repository/taskBaseFreshness.js +13 -13
  137. package/dist/repository/taskWorkspaceCoordinator.js +20 -27
  138. package/dist/repository/taskWorkspacePreparer.js +344 -83
  139. package/dist/resources/autoResourceGc.js +3 -3
  140. package/dist/resources/liveReferences.js +3 -3
  141. package/dist/resources/projectResource.js +75 -0
  142. package/dist/resources/projectResourceService.js +343 -0
  143. package/dist/resources/resourceDiscovery.js +6 -6
  144. package/dist/resources/resourceGc.js +1 -1
  145. package/dist/resources/resourceRegistrar.js +1 -1
  146. package/dist/resources/resourceTypes.js +1 -1
  147. package/dist/review/deltaRecheck.js +3 -3
  148. package/dist/review/reviewAcceptance.js +16 -16
  149. package/dist/review/reviewDecision.js +7 -7
  150. package/dist/review/reviewRound.js +21 -20
  151. package/dist/review/reviewerAvailability.js +2 -2
  152. package/dist/role/role.js +51 -7
  153. package/dist/role/taskRoleUpdate.js +30 -0
  154. package/dist/runtime/acpProtocol.js +425 -0
  155. package/dist/runtime/acpSession.js +731 -0
  156. package/dist/runtime/acpSessionConfiguration.js +260 -0
  157. package/dist/runtime/agentDriver.js +30 -11
  158. package/dist/runtime/agentEndpoint.js +278 -0
  159. package/dist/runtime/agentEndpointIdentity.js +86 -0
  160. package/dist/runtime/agentEndpointOwnership.js +239 -0
  161. package/dist/runtime/agentError.js +2 -10
  162. package/dist/runtime/agentHost.js +565 -314
  163. package/dist/runtime/agentRunConfiguration.js +258 -0
  164. package/dist/runtime/builtinAgentDrivers.js +134 -18
  165. package/dist/runtime/builtinAgentErrorMappers.js +55 -3
  166. package/dist/runtime/builtinTranscriptUsage.js +1 -1
  167. package/dist/runtime/claude-process-owner +0 -0
  168. package/dist/runtime/codexAppServerRuntime.js +38 -30
  169. package/dist/runtime/codexInteractiveHost.js +41 -6
  170. package/dist/runtime/continuationManager.js +2 -6
  171. package/dist/runtime/executionEnvironment.js +30 -0
  172. package/dist/runtime/firstProgressAdvisory.js +11 -11
  173. package/dist/runtime/index.js +4 -3
  174. package/dist/runtime/jsonLineChannel.js +109 -0
  175. package/dist/runtime/launchBroker.js +91 -16
  176. package/dist/runtime/launchDiagnostics.js +2 -2
  177. package/dist/runtime/lifecycleReservation.js +10 -18
  178. package/dist/runtime/managedCaller.js +61 -17
  179. package/dist/runtime/nativeSessionControl.js +102 -0
  180. package/dist/runtime/ports.js +6 -21
  181. package/dist/runtime/processExitObservation.js +8 -7
  182. package/dist/runtime/promptEnvelope.js +17 -6
  183. package/dist/runtime/providerContinuation.js +3 -9
  184. package/dist/runtime/providerContinuationReconciliationService.js +4 -13
  185. package/dist/runtime/providerControl.js +2 -7
  186. package/dist/runtime/providerRuntimeIdentity.js +110 -222
  187. package/dist/runtime/providerRuntimeReconciler.js +5 -9
  188. package/dist/runtime/runtimeBinding.js +0 -1
  189. package/dist/runtime/runtimeContinuationProjection.js +4 -7
  190. package/dist/runtime/runtimeDeadlines.js +9 -0
  191. package/dist/runtime/runtimeHealthPolicy.js +1 -1
  192. package/dist/runtime/runtimeObservation.js +29 -65
  193. package/dist/runtime/runtimeProjection.js +43 -51
  194. package/dist/runtime/runtimeSessionCandidate.js +1 -3
  195. package/dist/runtime/sessionLaunchRequest.js +3 -7
  196. package/dist/runtime/sessionOwnerIdentity.js +7 -54
  197. package/dist/runtime/sessionOwnerRegistry.js +22 -17
  198. package/dist/runtime/sessionReconciliation.js +4 -8
  199. package/dist/runtime/sessionTerminationGuard.js +70 -259
  200. package/dist/runtime/sessionTokenMetrics.js +5 -16
  201. package/dist/runtime/structuredProviderHost.js +237 -117
  202. package/dist/runtime/taskRuntimeIsolation.js +39 -122
  203. package/dist/runtime/tmuxAdapters.js +39 -86
  204. package/dist/scheduler/activeRoleRunDelivery.js +354 -0
  205. package/dist/scheduler/leaderWakeupProcessor.js +75 -266
  206. package/dist/scheduler/operatorInputNotificationProcessor.js +1 -1
  207. package/dist/scheduler/ports.js +80 -9
  208. package/dist/scheduler/{roleTurnLiveness.js → roleRunLiveness.js} +26 -30
  209. package/dist/scheduler/{roleTurnStall.js → roleRunStall.js} +128 -139
  210. package/dist/scheduler/taskExecutionProjection.js +120 -124
  211. package/dist/scheduler/taskObservabilityProjection.js +29 -29
  212. package/dist/scheduler/taskWake.js +11 -4
  213. package/dist/scheduler/wakeReason.js +9 -1
  214. package/dist/setup/setupCommand.js +3 -7
  215. package/dist/storage/migrations/agentRunContract.js +159 -0
  216. package/dist/storage/migrations/artifactsToGit.js +338 -0
  217. package/dist/storage/migrations/removeRuntimeGeneration.js +207 -0
  218. package/dist/storage/migrations/submitIntent.js +126 -0
  219. package/dist/storage/sqliteSchema.js +467 -7
  220. package/dist/storage/sqliteStore.js +355 -220
  221. package/dist/storage/storageVersions.js +1 -1
  222. package/dist/storage/storeRpc.js +10 -5
  223. package/dist/storage/taskStore.js +13 -11
  224. package/dist/storage/upgrade/upgradeOrchestrator.js +5 -7
  225. package/dist/surface/surfaceContributions.js +102 -0
  226. package/dist/task/completionReadiness.js +32 -6
  227. package/dist/task/deliveryGuard.js +16 -16
  228. package/dist/task/draftPlan.js +72 -12
  229. package/dist/task/nextAction.js +144 -128
  230. package/dist/task/remoteDelivery.js +6 -6
  231. package/dist/task/task.js +184 -18
  232. package/dist/task/taskActivation.js +327 -0
  233. package/dist/task/taskActivationService.js +408 -0
  234. package/dist/task/taskRecordReference.js +5 -4
  235. package/dist/task/taskRecordRetirement.js +1 -1
  236. package/dist/task/taskSubmission.js +236 -0
  237. package/dist/telemetry/sqliteTelemetryStore.js +55 -68
  238. package/dist/telemetry/telemetryConfig.js +14 -14
  239. package/dist/telemetry/telemetryWiring.js +2 -2
  240. package/dist/web/assets/assetManifest.js +2 -0
  241. package/dist/web/assets/client/app.js +121 -20
  242. package/dist/web/assets/client/components.js +87 -54
  243. package/dist/web/assets/client/i18n.js +83 -41
  244. package/dist/web/assets/client/markdown.js +1 -1
  245. package/dist/web/assets/client/taskSurface.js +442 -0
  246. package/dist/web/assets/client/view.js +49 -44
  247. package/dist/web/assets/shell.js +1 -1
  248. package/dist/web/assets/styles/cards.js +22 -4
  249. package/dist/web/controllerWeb.js +60 -0
  250. package/dist/web/webMutation.js +28 -0
  251. package/dist/web/webServer.js +133 -8
  252. package/dist/web/webSnapshot.js +81 -74
  253. package/dist/web/webTaskSurface.js +64 -0
  254. package/dist/workItem/dependencyGate.js +1 -1
  255. package/dist/workItem/workItem.js +84 -48
  256. package/dist/workspace/workItemChangeSetManager.js +16 -9
  257. package/docs/agent-result-consumption.md +96 -0
  258. package/docs/agent-result-consumption.zh-CN.md +81 -0
  259. package/docs/agent-runtime-drivers.md +93 -0
  260. package/docs/agent-runtime-drivers.zh-CN.md +77 -0
  261. package/docs/architecture/README.md +50 -0
  262. package/docs/architecture/README.zh-CN.md +43 -0
  263. package/docs/architecture/capabilities-and-resources.md +118 -0
  264. package/docs/architecture/capabilities-and-resources.zh-CN.md +83 -0
  265. package/docs/managed-turn-and-session-runtime.md +224 -0
  266. package/docs/managed-turn-and-session-runtime.zh-CN.md +180 -0
  267. package/docs/observability/README.md +83 -0
  268. package/docs/observability/README.zh-CN.md +71 -0
  269. package/docs/plugin-sdk.md +393 -0
  270. package/docs/plugin-sdk.zh-CN.md +293 -0
  271. package/docs/provider-runtime.md +165 -0
  272. package/docs/provider-runtime.zh-CN.md +132 -0
  273. package/docs/release-workflow.md +305 -0
  274. package/docs/release-workflow.zh-CN.md +237 -0
  275. package/docs/roles-and-configuration.md +115 -0
  276. package/docs/roles-and-configuration.zh-CN.md +96 -0
  277. package/docs/sqlite-control-plane-design.md +78 -0
  278. package/docs/sqlite-control-plane-design.zh-CN.md +62 -0
  279. package/docs/task-dag-semantics.md +80 -0
  280. package/docs/task-dag-semantics.zh-CN.md +59 -0
  281. package/docs/task-delivery.md +105 -0
  282. package/docs/task-delivery.zh-CN.md +82 -0
  283. package/docs/task-local-identity.md +8 -6
  284. package/docs/task-local-identity.zh-CN.md +58 -0
  285. package/docs/testing/verification-levels.md +88 -0
  286. package/docs/testing/verification-levels.zh-CN.md +69 -0
  287. package/i18n/README.zh-CN.md +270 -722
  288. package/package.json +3 -2
  289. package/skills/yui-leader/SKILL.md +88 -304
  290. package/skills/yui-leader/references/execution.md +303 -0
  291. package/skills/yui-leader/references/integration.md +39 -0
  292. package/skills/yui-leader/references/planning.md +109 -0
  293. package/skills/yui-leader/references/replicated-execution.md +42 -0
  294. package/skills/yui-leader/references/task-plugins.md +37 -0
  295. package/skills/yui-operator/SKILL.md +46 -62
  296. package/skills/yui-reviewer/SKILL.md +35 -36
  297. package/skills/yui-runtime/SKILL.md +88 -24
  298. package/skills/yui-runtime/references/publication.md +22 -0
  299. package/skills/yui-runtime/references/recovery.md +64 -0
  300. package/skills/yui-worker/SKILL.md +37 -39
  301. package/dist/cli/roleOptionCatalog.js +0 -68
  302. package/dist/context/sourceTurnContext.js +0 -30
  303. package/dist/execution/reviewMainTurn.js +0 -161
  304. package/dist/execution/workItemMainTurn.js +0 -164
  305. package/dist/lifecycle/exactTurnTerminalization.js +0 -407
  306. package/dist/runtime/preallocatedNativeSession.js +0 -13
  307. package/dist/runtime/runtimeStopReceipt.js +0 -42
  308. package/dist/scheduler/activeRoleTurnDelivery.js +0 -315
@@ -1,12 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { governingWorkItemDeliveries, workItemDeliverySettled } from "../integration/deliveryObligation.js";
3
- import { isCompletedTaskReviewEvidenceFromTurns } from "../review/reviewAcceptance.js";
3
+ import { isCompletedTaskReviewEvidenceFromRuns } from "../review/reviewAcceptance.js";
4
4
  import { actionableExecutionLaneRecoveries } from "../execution/executionHealth.js";
5
5
  import { sameTaskFinalReviewContract } from "../review/taskFinalReviewContract.js";
6
6
  import { resolveRecordedTaskFinalReviewContract } from "../review/taskFinalReviewContractResolution.js";
7
7
  import { draftWorkItemDependencyIssue } from "./draftPlan.js";
8
- import { currentWorkItemCandidate, governingWorkItemCandidate } from "../workItem/workItem.js";
9
- const OPEN_WORK_ITEM_STATUSES = new Set(["pending", "running", "awaiting_acceptance"]);
8
+ import { currentWorkItemCandidate, currentWorkItemExecutionGroup, governingWorkItemCandidate } from "../workItem/workItem.js";
9
+ const OPEN_WORK_ITEM_STATUSES = new Set(["open"]);
10
10
  export function projectNextAction(facts) {
11
11
  const { task } = facts;
12
12
  const deliveryWorkItems = facts.workItems.filter(({ status }) => status !== "retired");
@@ -55,18 +55,18 @@ export function projectNextAction(facts) {
55
55
  });
56
56
  }
57
57
  const laneRecovery = actionableExecutionLaneRecoveries(facts.executionGroups ?? [])
58
- .find(hasExactTurn);
58
+ .find(hasExactRun);
59
59
  if (laneRecovery !== undefined) {
60
60
  return buildExecutionLaneRecoveryAction(facts, laneRecovery);
61
61
  }
62
- const activeLeader = facts.activeTurns.find((run) => run.roleName === "leader");
62
+ const activeLeader = facts.activeRuns.find((run) => run.roleName === "leader");
63
63
  if (activeLeader !== undefined) {
64
64
  return buildAction(facts, {
65
65
  kind: "wait-for-owned-execution",
66
- reason: `Leader Turn ${activeLeader.id} is active; the protocol position is being executed.`,
67
- refs: [ref("turn", activeLeader.id)],
66
+ reason: `Leader AgentRun ${activeLeader.id} is active; the protocol position is being executed.`,
67
+ refs: [ref("run", activeLeader.id)],
68
68
  preconditions: [
69
- { fact: "Leader Turn is active", satisfied: true, ref: ref("turn", activeLeader.id) }
69
+ { fact: "Leader AgentRun is active", satisfied: true, ref: ref("run", activeLeader.id) }
70
70
  ]
71
71
  });
72
72
  }
@@ -121,29 +121,58 @@ export function projectNextAction(facts) {
121
121
  recommendedCommand: `yui task activate ${task.id}`
122
122
  });
123
123
  }
124
+ const checkingIntegration = facts.integrations.find(attempt => attempt.status === "running" && attempt.jobId !== undefined);
125
+ if (checkingIntegration !== undefined) {
126
+ const job = facts.integrationJobs?.find(job => job.id === checkingIntegration.jobId);
127
+ const refs = [ref("integration", checkingIntegration.id), ref("job", checkingIntegration.jobId)];
128
+ if (job?.status === "queued" || job?.status === "running") {
129
+ return buildAction(facts, {
130
+ kind: "wait-for-owned-execution",
131
+ reason: `Integration ${checkingIntegration.id} check Job ${job.id} is ${job.status}.`,
132
+ refs,
133
+ preconditions: [{ fact: "Check Job is still executing", satisfied: true, ref: refs[1] }],
134
+ alternatives: [{
135
+ kind: "continue-integration",
136
+ reason: "When the check Job settles, continue this exact Integration to consume its result.",
137
+ recommendedCommand: `yui task integration continue ${task.id}/${checkingIntegration.id}`
138
+ }]
139
+ });
140
+ }
141
+ return buildAction(facts, {
142
+ kind: "integrate-work-item",
143
+ reason: `Integration ${checkingIntegration.id} awaits check-result consumption (${job?.status ?? "read current Job"}); an empty integration queue does not finalize this direct attempt.`,
144
+ refs,
145
+ preconditions: [{ fact: "The Integration retains its exact check Job", satisfied: true, ref: refs[0] }],
146
+ recommendedCommand: `yui task integration continue ${task.id}/${checkingIntegration.id}`
147
+ });
148
+ }
124
149
  const candidateReady = facts.workItems
125
- .find((item) => item.status === "awaiting_acceptance");
150
+ .find((item) => (item.status === "open" && item.currentCandidateId !== undefined));
126
151
  if (candidateReady !== undefined) {
127
152
  const candidate = currentWorkItemCandidate(candidateReady);
128
153
  const activeReview = latestActiveWorkItemReview(facts.reviewRounds, candidateReady, candidate);
129
154
  if (activeReview !== undefined) {
130
155
  const reviewRef = ref("review-round", activeReview.id);
131
156
  if (activeReview.status === "running") {
132
- if (activeReview.reviewerTurnId === undefined
157
+ if (activeReview.reviewerRunId === undefined
133
158
  && activeReview.executionGroup === undefined) {
134
159
  return buildAction(facts, {
135
160
  kind: "repair-protocol-inconsistency",
136
- reason: `ReviewRound ${activeReview.id} is running but has no Reviewer Turn.`,
161
+ reason: `ReviewRound ${activeReview.id} is running but has no Reviewer AgentRun.`,
137
162
  refs: [reviewRef],
138
163
  conflicts: [reviewRef],
139
164
  preconditions: [
140
- { fact: "Running ReviewRound has an exact Reviewer Turn", satisfied: false, ref: reviewRef }
165
+ { fact: "Running ReviewRound has an exact Reviewer AgentRun", satisfied: false, ref: reviewRef }
141
166
  ]
142
167
  });
143
168
  }
144
- const reviewRun = activeReviewRoundRun(activeReview, facts.activeTurns);
169
+ const reviewRun = activeReviewRoundRun(activeReview, facts.activeRuns);
145
170
  if (reviewRun === undefined) {
146
- if (reviewGroupNeedsDispatch(activeReview, facts.activeTurns)) {
171
+ if (activeReview.executionGroup !== undefined && activeReview.reviewerRunId === undefined
172
+ && !reviewGroupNeedsDispatch(activeReview, facts.activeRuns)) {
173
+ return synthesisSelectionAction(facts, "review", activeReview.id);
174
+ }
175
+ if (reviewGroupNeedsDispatch(activeReview, facts.activeRuns)) {
147
176
  return buildAction(facts, {
148
177
  kind: "resume-review",
149
178
  reason: `ReviewRound ${activeReview.id} has Review Producer Lanes ready for dispatch or retry.`,
@@ -155,12 +184,12 @@ export function projectNextAction(facts) {
155
184
  + reviewLaneRoleOptions(activeReview)
156
185
  });
157
186
  }
158
- const runRef = activeReview.reviewerTurnId === undefined
187
+ const runRef = activeReview.reviewerRunId === undefined
159
188
  ? reviewRef
160
- : ref("turn", activeReview.reviewerTurnId);
189
+ : ref("run", activeReview.reviewerRunId);
161
190
  return buildAction(facts, {
162
191
  kind: "repair-protocol-inconsistency",
163
- reason: `ReviewRound ${activeReview.id} has no active Producer or main Reviewer Turn.`,
192
+ reason: `ReviewRound ${activeReview.id} has no active Producer or main Reviewer AgentRun.`,
164
193
  refs: [reviewRef, runRef],
165
194
  conflicts: [reviewRef, runRef],
166
195
  preconditions: [
@@ -170,23 +199,23 @@ export function projectNextAction(facts) {
170
199
  }
171
200
  return buildAction(facts, {
172
201
  kind: "wait-for-owned-execution",
173
- reason: `Reviewer Turn ${reviewRun.id} is evaluating Candidate ${candidateReady.id}/${candidate?.id ?? "unknown"}.`,
174
- refs: [reviewRef, ref("turn", reviewRun.id)],
202
+ reason: `Reviewer AgentRun ${reviewRun.id} is evaluating Candidate ${candidateReady.id}/${candidate?.id ?? "unknown"}.`,
203
+ refs: [reviewRef, ref("run", reviewRun.id)],
175
204
  preconditions: [
176
205
  { fact: "ReviewRound is running", satisfied: true, ref: reviewRef },
177
- { fact: "Reviewer Turn is active", satisfied: true, ref: ref("turn", reviewRun.id) }
206
+ { fact: "Reviewer AgentRun is active", satisfied: true, ref: ref("run", reviewRun.id) }
178
207
  ]
179
208
  });
180
209
  }
181
- if (activeReview.reviewerTurnId !== undefined) {
182
- const runRef = ref("turn", activeReview.reviewerTurnId);
210
+ if (activeReview.reviewerRunId !== undefined) {
211
+ const runRef = ref("run", activeReview.reviewerRunId);
183
212
  return buildAction(facts, {
184
213
  kind: "repair-protocol-inconsistency",
185
- reason: `Pending ReviewRound ${activeReview.id} already references Reviewer Turn ${activeReview.reviewerTurnId}.`,
214
+ reason: `Pending ReviewRound ${activeReview.id} already references Reviewer AgentRun ${activeReview.reviewerRunId}.`,
186
215
  refs: [reviewRef, runRef],
187
216
  conflicts: [reviewRef, runRef],
188
217
  preconditions: [
189
- { fact: "Pending ReviewRound has no Reviewer Turn", satisfied: false, ref: runRef }
218
+ { fact: "Pending ReviewRound has no Reviewer AgentRun", satisfied: false, ref: runRef }
190
219
  ]
191
220
  });
192
221
  }
@@ -196,7 +225,7 @@ export function projectNextAction(facts) {
196
225
  refs: [reviewRef],
197
226
  preconditions: [
198
227
  { fact: "ReviewRound is pending", satisfied: true, ref: reviewRef },
199
- { fact: "Reviewer Turn exists", satisfied: false }
228
+ { fact: "Reviewer AgentRun exists", satisfied: false }
200
229
  ],
201
230
  recommendedCommand: `yui task work review ${task.id}/${candidateReady.id}`
202
231
  + reviewLaneRoleOptions(activeReview)
@@ -256,35 +285,15 @@ export function projectNextAction(facts) {
256
285
  judgmentRequired: `Leader must judge Candidate ${candidateReady.id}/${candidate?.id ?? "unknown"} against the Task objective, acceptance criteria, and delivery risk.`
257
286
  });
258
287
  }
259
- // Turn purpose owns routing. Review Turns remain attached to their exact
288
+ // AgentRun purpose owns routing. Review AgentRuns remain attached to their exact
260
289
  // ReviewRound branches below instead of being mistaken for Worker delivery.
261
- const activeDelegatedExecutions = facts.activeTurns.filter((run) => (run.purpose === "execution" && run.roleName !== "leader"));
290
+ const activeDelegatedExecutions = facts.activeRuns.filter((run) => (run.purpose === "execution" && run.roleName !== "leader"));
262
291
  if (activeDelegatedExecutions.length > 0) {
263
292
  return buildAction(facts, {
264
293
  kind: "wait-for-owned-execution",
265
- reason: `${activeDelegatedExecutions.length} delegated execution Turn(s) are active; wait for their completion.`,
266
- refs: activeDelegatedExecutions.map((run) => ref("turn", run.id)),
267
- preconditions: activeDelegatedExecutions.map((run) => ({ fact: `Execution Turn ${run.id} is active`, satisfied: true, ref: ref("turn", run.id) }))
268
- });
269
- }
270
- const failedWork = facts.workItems.find((item) => item.status === "failed");
271
- if (failedWork !== undefined) {
272
- const failedReview = latestFailedReviewFor(facts.reviewRounds, failedWork.id);
273
- return buildAction(facts, {
274
- kind: "implement-current-work-item",
275
- reason: failedReview === undefined
276
- ? `Work Item ${failedWork.id} failed; retry implementation after Leader diagnosis.`
277
- : `Work Item ${failedWork.id} failed after Review ${failedReview.id}; the Leader must read its exact Reviewer Turn result and choose the repair.`,
278
- refs: [
279
- ref("work-item", failedWork.id),
280
- ...(failedReview === undefined ? [] : [ref("review-round", failedReview.id)])
281
- ],
282
- preconditions: [
283
- { fact: "Work Item is failed", satisfied: true, ref: ref("work-item", failedWork.id) }
284
- ],
285
- recommendedCommand: failedWork.assignee === undefined
286
- ? `yui task work update ${task.id}/${failedWork.id} running`
287
- : `yui task work dispatch ${task.id}/${failedWork.id}`
294
+ reason: `${activeDelegatedExecutions.length} delegated execution AgentRun(s) are active; wait for their completion.`,
295
+ refs: activeDelegatedExecutions.map((run) => ref("run", run.id)),
296
+ preconditions: activeDelegatedExecutions.map((run) => ({ fact: `Execution AgentRun ${run.id} is active`, satisfied: true, ref: ref("run", run.id) }))
288
297
  });
289
298
  }
290
299
  const openWork = selectOpenWorkItem(facts.workItems);
@@ -305,6 +314,11 @@ export function projectNextAction(facts) {
305
314
  }
306
315
  if (openWork?.kind === "ready") {
307
316
  const item = openWork.item;
317
+ const group = currentWorkItemExecutionGroup(item);
318
+ if (item.status === "open" && group !== undefined
319
+ && !facts.activeRuns.some((run) => run.sourceExecutionGroupId === group.id)) {
320
+ return synthesisSelectionAction(facts, "work", item.id);
321
+ }
308
322
  const refs = [ref("work-item", item.id)];
309
323
  return buildAction(facts, {
310
324
  kind: "implement-current-work-item",
@@ -342,24 +356,20 @@ export function projectNextAction(facts) {
342
356
  refs: [ref("task", task.id)]
343
357
  }];
344
358
  return buildAction(facts, {
345
- kind: "complete-task",
346
- reason: task.type === "bugfix"
347
- ? `Task ${task.id} is a Leader-owned bugfix; implement and verify it on Task main without manufacturing a WorkItem.`
348
- : task.type === "feature"
349
- ? `Feature ${task.id} has no independent delivery units; the Leader may implement it on Task main or create WorkItems only if separate ownership is genuinely useful.`
350
- : `Task ${task.id} has no independent delivery units; the Leader decides whether to own it on Task main or create WorkItems only if separate ownership is genuinely useful.`,
359
+ kind: "advance-task",
360
+ reason: `Task ${task.id} has no recorded WorkItems. This does not determine its required topology or prove completion; advance the user's persisted requirements and Brief.`,
351
361
  refs: [ref("task", task.id)],
352
362
  preconditions: [
353
363
  { fact: "Task is active", satisfied: task.status === "active", ref: ref("task", task.id) },
354
364
  { fact: "Task main is clean, committed, and verified", satisfied: false }
355
365
  ],
356
- recommendedCommand: `yui task complete ${task.id} --summary-file -`,
357
- ...(reviewAlternative.length === 0 ? {} : { alternatives: reviewAlternative }),
358
- judgmentRequired: task.type === "bugfix"
359
- ? "Leader must judge whether the bugfix risk warrants one optional final Review."
360
- : task.type === "feature"
361
- ? "Leader must judge whether this feature is small enough to own directly or needs independently owned WorkItems, and whether the final result warrants Review."
362
- : "Leader must choose the smallest useful topology from the Project-defined Task intent, then decide whether the frozen result warrants Review."
366
+ recommendedCommand: `yui task context ${task.id} --json`,
367
+ alternatives: [...reviewAlternative, {
368
+ kind: "complete-task",
369
+ reason: "Complete only after every requested outcome, delegation and Review requirement is satisfied and verified; record counts and a clean commit alone do not prove that.",
370
+ recommendedCommand: `yui task complete ${task.id} --summary-file -`
371
+ }],
372
+ judgmentRequired: "Honor explicit user/Project requirements first. Otherwise choose direct work or independently owned WorkItems and proportionate Review. This projection does not authorize weakening the Task Contract."
363
373
  });
364
374
  }
365
375
  const unintegrated = governingWorkItemDeliveries(facts.workItems)
@@ -386,24 +396,24 @@ export function projectNextAction(facts) {
386
396
  const failedFinal = latestTaskFinalReview(facts.reviewRounds, finalReviewContract);
387
397
  if (finalReviewRequired
388
398
  && failedFinal?.status === "failed") {
389
- const reviewerTurn = failedFinal.reviewerTurnId === undefined
399
+ const reviewerRun = failedFinal.reviewerRunId === undefined
390
400
  ? undefined
391
- : facts.reviewOutcomeEvidence?.turns.find(({ id }) => id === failedFinal.reviewerTurnId);
392
- const sameRoundCommand = failedFinal.reviewerTurnId === undefined
401
+ : facts.reviewOutcomeEvidence?.runs.find(({ id }) => id === failedFinal.reviewerRunId);
402
+ const sameRoundCommand = failedFinal.reviewerRunId === undefined
393
403
  ? `yui task review retry ${task.id}/${failedFinal.id}`
394
- : reviewerTurn?.status === "failed"
395
- ? `yui task turn retry ${task.id}/${reviewerTurn.id}`
404
+ : reviewerRun?.status === "failed"
405
+ ? `yui task run retry ${task.id}/${reviewerRun.id}`
396
406
  : undefined;
397
407
  return buildAction(facts, {
398
408
  kind: "resume-review",
399
409
  reason: `Task-final Review ${failedFinal.id} failed during execution: ${failedFinal.failure?.message ?? "unknown Core failure"}.`,
400
410
  refs: [
401
411
  ref("review-round", failedFinal.id),
402
- ...(reviewerTurn?.status === "failed" ? [ref("turn", reviewerTurn.id)] : [])
412
+ ...(reviewerRun?.status === "failed" ? [ref("run", reviewerRun.id)] : [])
403
413
  ],
404
414
  preconditions: [
405
415
  {
406
- fact: "Task-final Review has one exact completed Reviewer Turn",
416
+ fact: "Task-final Review has one exact completed Reviewer AgentRun",
407
417
  satisfied: false,
408
418
  ref: ref("review-round", failedFinal.id)
409
419
  }
@@ -413,15 +423,15 @@ export function projectNextAction(facts) {
413
423
  }
414
424
  if (finalReviewRequired
415
425
  && failedFinal?.status === "completed"
416
- && !isCompletedTaskReviewEvidenceFromTurns(failedFinal, facts.reviewOutcomeEvidence?.turns ?? [])) {
426
+ && !isCompletedTaskReviewEvidenceFromRuns(failedFinal, facts.reviewOutcomeEvidence?.runs ?? [])) {
417
427
  return buildAction(facts, {
418
428
  kind: "repair-protocol-inconsistency",
419
- reason: `Task-final Review ${failedFinal.id} is completed without one exact completed main Reviewer Turn.`,
429
+ reason: `Task-final Review ${failedFinal.id} is completed without one exact completed main Reviewer AgentRun.`,
420
430
  refs: [ref("review-round", failedFinal.id)],
421
431
  conflicts: [ref("review-round", failedFinal.id)],
422
432
  preconditions: [
423
433
  {
424
- fact: "ReviewRound and exact main Reviewer Turn agree",
434
+ fact: "ReviewRound and exact main Reviewer AgentRun agree",
425
435
  satisfied: false,
426
436
  ref: ref("review-round", failedFinal.id)
427
437
  }
@@ -433,21 +443,25 @@ export function projectNextAction(facts) {
433
443
  && (activeFinal.status === "pending" || activeFinal.status === "running")) {
434
444
  const reviewRef = ref("review-round", activeFinal.id);
435
445
  if (activeFinal.status === "running") {
436
- if (activeFinal.reviewerTurnId === undefined
446
+ if (activeFinal.reviewerRunId === undefined
437
447
  && activeFinal.executionGroup === undefined) {
438
448
  return buildAction(facts, {
439
449
  kind: "repair-protocol-inconsistency",
440
- reason: `Task-final ReviewRound ${activeFinal.id} is running but has no Reviewer Turn.`,
450
+ reason: `Task-final ReviewRound ${activeFinal.id} is running but has no Reviewer AgentRun.`,
441
451
  refs: [reviewRef],
442
452
  conflicts: [reviewRef],
443
453
  preconditions: [
444
- { fact: "Running Task-final ReviewRound has an exact Reviewer Turn", satisfied: false, ref: reviewRef }
454
+ { fact: "Running Task-final ReviewRound has an exact Reviewer AgentRun", satisfied: false, ref: reviewRef }
445
455
  ]
446
456
  });
447
457
  }
448
- const reviewRun = activeReviewRoundRun(activeFinal, facts.activeTurns);
458
+ const reviewRun = activeReviewRoundRun(activeFinal, facts.activeRuns);
449
459
  if (reviewRun === undefined) {
450
- if (reviewGroupNeedsDispatch(activeFinal, facts.activeTurns)) {
460
+ if (activeFinal.executionGroup !== undefined && activeFinal.reviewerRunId === undefined
461
+ && !reviewGroupNeedsDispatch(activeFinal, facts.activeRuns)) {
462
+ return synthesisSelectionAction(facts, "review", activeFinal.id);
463
+ }
464
+ if (reviewGroupNeedsDispatch(activeFinal, facts.activeRuns)) {
451
465
  return buildAction(facts, {
452
466
  kind: "resume-review",
453
467
  reason: `Task-final ReviewRound ${activeFinal.id} has Review Producer Lanes ready for dispatch or retry.`,
@@ -459,12 +473,12 @@ export function projectNextAction(facts) {
459
473
  + reviewLaneRoleOptions(activeFinal)
460
474
  });
461
475
  }
462
- const runRef = activeFinal.reviewerTurnId === undefined
476
+ const runRef = activeFinal.reviewerRunId === undefined
463
477
  ? reviewRef
464
- : ref("turn", activeFinal.reviewerTurnId);
478
+ : ref("run", activeFinal.reviewerRunId);
465
479
  return buildAction(facts, {
466
480
  kind: "repair-protocol-inconsistency",
467
- reason: `Task-final ReviewRound ${activeFinal.id} has no active Producer or main Reviewer Turn.`,
481
+ reason: `Task-final ReviewRound ${activeFinal.id} has no active Producer or main Reviewer AgentRun.`,
468
482
  refs: [reviewRef, runRef],
469
483
  conflicts: [reviewRef, runRef],
470
484
  preconditions: [
@@ -474,11 +488,11 @@ export function projectNextAction(facts) {
474
488
  }
475
489
  return buildAction(facts, {
476
490
  kind: "wait-for-owned-execution",
477
- reason: `Reviewer Turn ${reviewRun.id} is executing frozen Task-final Review ${activeFinal.id}; this Review does not globally pause Leader decisions on newer facts.`,
478
- refs: [reviewRef, ref("turn", reviewRun.id)],
491
+ reason: `Reviewer AgentRun ${reviewRun.id} is executing frozen Task-final Review ${activeFinal.id}; this Review does not globally pause Leader decisions on newer facts.`,
492
+ refs: [reviewRef, ref("run", reviewRun.id)],
479
493
  preconditions: [
480
494
  { fact: "Task-final ReviewRound is running", satisfied: true, ref: reviewRef },
481
- { fact: "Reviewer Turn is active", satisfied: true, ref: ref("turn", reviewRun.id) }
495
+ { fact: "Reviewer AgentRun is active", satisfied: true, ref: ref("run", reviewRun.id) }
482
496
  ],
483
497
  alternatives: [
484
498
  {
@@ -496,15 +510,15 @@ export function projectNextAction(facts) {
496
510
  judgmentRequired: "Leader decides whether the current facts justify waiting, continuing development, direct review, or another Reviewer."
497
511
  });
498
512
  }
499
- if (activeFinal.reviewerTurnId !== undefined) {
500
- const runRef = ref("turn", activeFinal.reviewerTurnId);
513
+ if (activeFinal.reviewerRunId !== undefined) {
514
+ const runRef = ref("run", activeFinal.reviewerRunId);
501
515
  return buildAction(facts, {
502
516
  kind: "repair-protocol-inconsistency",
503
- reason: `Pending Task-final ReviewRound ${activeFinal.id} already references Reviewer Turn ${activeFinal.reviewerTurnId}.`,
517
+ reason: `Pending Task-final ReviewRound ${activeFinal.id} already references Reviewer AgentRun ${activeFinal.reviewerRunId}.`,
504
518
  refs: [reviewRef, runRef],
505
519
  conflicts: [reviewRef, runRef],
506
520
  preconditions: [
507
- { fact: "Pending Task-final ReviewRound has no Reviewer Turn", satisfied: false, ref: runRef }
521
+ { fact: "Pending Task-final ReviewRound has no Reviewer AgentRun", satisfied: false, ref: runRef }
508
522
  ]
509
523
  });
510
524
  }
@@ -514,7 +528,7 @@ export function projectNextAction(facts) {
514
528
  refs: [reviewRef],
515
529
  preconditions: [
516
530
  { fact: "Task-final ReviewRound is pending", satisfied: true, ref: reviewRef },
517
- { fact: "Reviewer Turn exists", satisfied: false }
531
+ { fact: "Reviewer AgentRun exists", satisfied: false }
518
532
  ],
519
533
  recommendedCommand: `yui task review request ${task.id} --role ${activeFinal.reviewerRoleName}`
520
534
  + reviewLaneRoleOptions(activeFinal)
@@ -585,24 +599,36 @@ export function projectNextAction(facts) {
585
599
  recommendedCommand: `yui task complete ${task.id} --summary-file -`
586
600
  });
587
601
  }
588
- function hasExactTurn(lane) {
589
- return lane.turnId !== undefined;
602
+ function synthesisSelectionAction(facts, subject, id) {
603
+ return buildAction(facts, {
604
+ kind: "resolve-execution-stage",
605
+ reason: `Replicated ${subject} ${id} needs Leader judgment over original results and synthesis.`,
606
+ refs: [ref(subject === "work" ? "work-item" : "review-round", id)],
607
+ preconditions: [],
608
+ recommendedCommand: subject === "work"
609
+ ? `yui task work show ${facts.task.id}/${id}`
610
+ : `yui task review synthesize ${facts.task.id}/${id} --source-run <task>/<run>`,
611
+ judgmentRequired: "Inspect original results and any existing main AgentRun. Retry a failed main AgentRun or explicitly select synthesis sources; Core does not enforce a success count or voting rule."
612
+ });
613
+ }
614
+ function hasExactRun(lane) {
615
+ return lane.runId !== undefined;
590
616
  }
591
617
  function buildExecutionLaneRecoveryAction(facts, lane) {
592
618
  const refs = [
593
619
  ref("execution-group", lane.groupId),
594
620
  ref("execution-lane", lane.laneId),
595
- ref("turn", lane.turnId)
621
+ ref("run", lane.runId)
596
622
  ];
597
623
  return buildAction(facts, {
598
624
  kind: "retry-execution-lane",
599
- reason: `Execution Lane ${lane.laneId} is durably failed; retry only exact Turn ${lane.turnId} and retain sibling results.`,
625
+ reason: `Execution Lane ${lane.laneId} is durably failed; retry only exact AgentRun ${lane.runId} and retain sibling results.`,
600
626
  refs,
601
627
  preconditions: [
602
628
  { fact: "Execution Lane is failed and unresolved", satisfied: true, ref: refs[1] },
603
- { fact: "Exact failed Turn is retained", satisfied: true, ref: refs[2] }
629
+ { fact: "Exact failed AgentRun is retained", satisfied: true, ref: refs[2] }
604
630
  ],
605
- recommendedCommand: `yui task turn retry ${facts.task.id}/${lane.turnId}`
631
+ recommendedCommand: `yui task run retry ${facts.task.id}/${lane.runId}`
606
632
  });
607
633
  }
608
634
  /**
@@ -654,16 +680,16 @@ function latestActiveWorkItemReview(rounds, item, candidate) {
654
680
  && round.candidateId === candidate.id
655
681
  && (round.status === "pending" || round.status === "running")));
656
682
  }
657
- function activeReviewRoundRun(round, activeTurns) {
658
- if (round.reviewerTurnId !== undefined) {
659
- const main = activeTurns.find((run) => (run.id === round.reviewerTurnId && run.roleName === round.reviewerRoleName));
683
+ function activeReviewRoundRun(round, activeRuns) {
684
+ if (round.reviewerRunId !== undefined) {
685
+ const main = activeRuns.find((run) => (run.id === round.reviewerRunId && run.roleName === round.reviewerRoleName));
660
686
  if (main !== undefined)
661
687
  return main;
662
688
  }
663
689
  for (const lane of round.executionGroup?.lanes ?? []) {
664
- if (lane.disposition !== "open" || lane.currentTurnId === undefined)
690
+ if (lane.disposition !== "open" || lane.currentRunId === undefined)
665
691
  continue;
666
- const run = activeTurns.find((candidate) => (candidate.id === lane.currentTurnId && candidate.roleName === lane.roleName));
692
+ const run = activeRuns.find((candidate) => (candidate.id === lane.currentRunId && candidate.roleName === lane.roleName));
667
693
  if (run !== undefined)
668
694
  return run;
669
695
  }
@@ -674,37 +700,37 @@ function reviewLaneRoleOptions(round) {
674
700
  .map(({ roleName }) => ` --lane-role ${roleName}`)
675
701
  .join("") ?? "";
676
702
  }
677
- function reviewGroupNeedsDispatch(round, turns) {
703
+ function reviewGroupNeedsDispatch(round, runs) {
678
704
  return round.executionGroup?.lanes.some((lane) => (lane.disposition === "open"
679
- && (lane.currentTurnId === undefined
680
- || turns.find(({ id }) => id === lane.currentTurnId)?.status === "failed"))) === true;
705
+ && (lane.currentRunId === undefined
706
+ || runs.find(({ id }) => id === lane.currentRunId)?.status === "failed"))) === true;
681
707
  }
682
- function reviewRoundConflict(round, activeTurns) {
708
+ function reviewRoundConflict(round, activeRuns) {
683
709
  const reviewRef = ref("review-round", round.id);
684
710
  if (round.status === "running") {
685
- if (round.reviewerTurnId === undefined && round.executionGroup === undefined) {
711
+ if (round.reviewerRunId === undefined && round.executionGroup === undefined) {
686
712
  return {
687
713
  reason: `ReviewRound ${round.id} is running but has no execution unit.`,
688
714
  conflicts: [reviewRef]
689
715
  };
690
716
  }
691
- if (activeReviewRoundRun(round, activeTurns) === undefined) {
692
- if (round.reviewerTurnId === undefined && round.executionGroup !== undefined)
717
+ if (activeReviewRoundRun(round, activeRuns) === undefined) {
718
+ if (round.reviewerRunId === undefined && round.executionGroup !== undefined)
693
719
  return null;
694
- const runRef = ref("turn", round.reviewerTurnId);
720
+ const runRef = ref("run", round.reviewerRunId);
695
721
  return {
696
- reason: `ReviewRound ${round.id} references Reviewer Turn ${round.reviewerTurnId}, but that Turn is not active.`,
722
+ reason: `ReviewRound ${round.id} references Reviewer AgentRun ${round.reviewerRunId}, but that AgentRun is not active.`,
697
723
  conflicts: [reviewRef, runRef]
698
724
  };
699
725
  }
700
726
  }
701
727
  if (round.status === "pending") {
702
- const launchedTurnId = round.reviewerTurnId
703
- ?? round.executionGroup?.lanes.find((lane) => lane.currentTurnId !== undefined)?.currentTurnId;
704
- if (launchedTurnId !== undefined) {
705
- const runRef = ref("turn", launchedTurnId);
728
+ const launchedRunId = round.reviewerRunId
729
+ ?? round.executionGroup?.lanes.find((lane) => lane.currentRunId !== undefined)?.currentRunId;
730
+ if (launchedRunId !== undefined) {
731
+ const runRef = ref("run", launchedRunId);
706
732
  return {
707
- reason: `Pending ReviewRound ${round.id} already references Reviewer Turn ${launchedTurnId}.`,
733
+ reason: `Pending ReviewRound ${round.id} already references Reviewer AgentRun ${launchedRunId}.`,
708
734
  conflicts: [reviewRef, runRef]
709
735
  };
710
736
  }
@@ -718,7 +744,7 @@ function selectOpenWorkItem(workItems) {
718
744
  return { kind: "none" };
719
745
  const eligible = openItems.find((item) => (item.dependsOn.every((dependencyId) => {
720
746
  const status = byId.get(dependencyId)?.status;
721
- return status === "completed";
747
+ return status === "accepted";
722
748
  })));
723
749
  if (eligible !== undefined)
724
750
  return { kind: "ready", item: eligible };
@@ -731,7 +757,7 @@ function selectOpenWorkItem(workItems) {
731
757
  visited.add(current.id);
732
758
  const blockedBy = current.dependsOn.find((dependencyId) => {
733
759
  const status = byId.get(dependencyId)?.status;
734
- return status !== "completed";
760
+ return status !== "accepted";
735
761
  });
736
762
  if (blockedBy === undefined)
737
763
  return { kind: "ready", item: current };
@@ -777,7 +803,7 @@ function hasValidFinalReview(facts) {
777
803
  .reverse()
778
804
  .find((round) => ((round.scope ?? "work-item") === "task"
779
805
  && (contract === undefined || sameTaskFinalReviewContract(round.taskFinalReviewContract, contract))));
780
- if (final === undefined || !isCompletedTaskReviewEvidenceFromTurns(final, facts.reviewOutcomeEvidence?.turns ?? []))
806
+ if (final === undefined || !isCompletedTaskReviewEvidenceFromRuns(final, facts.reviewOutcomeEvidence?.runs ?? []))
781
807
  return false;
782
808
  return final.taskCandidate !== undefined;
783
809
  }
@@ -804,7 +830,7 @@ function detectProtocolInconsistency(facts) {
804
830
  };
805
831
  }
806
832
  for (const round of facts.reviewRounds) {
807
- const reviewConflict = reviewRoundConflict(round, facts.activeTurns);
833
+ const reviewConflict = reviewRoundConflict(round, facts.activeRuns);
808
834
  if (reviewConflict !== null)
809
835
  return reviewConflict;
810
836
  }
@@ -835,15 +861,5 @@ function detectProtocolInconsistency(facts) {
835
861
  };
836
862
  }
837
863
  }
838
- for (const item of facts.workItems) {
839
- if (item.status !== "awaiting_acceptance")
840
- continue;
841
- if (item.candidates.length === 0) {
842
- return {
843
- reason: `Work Item ${item.id} is awaiting acceptance but has no Candidate record.`,
844
- conflicts: [ref("work-item", item.id)]
845
- };
846
- }
847
- }
848
864
  return null;
849
865
  }
@@ -98,7 +98,7 @@ function expectedDelivery(facts) {
98
98
  ...(event === undefined ? {} : { event })
99
99
  };
100
100
  }
101
- if (task.status === "active" || task.status === "retired") {
101
+ if (task.status === "active" || task.status === "cancelled") {
102
102
  return {
103
103
  source: "current-task-main",
104
104
  provisional: true,
@@ -135,13 +135,13 @@ function projectBaseCommits(facts, event) {
135
135
  if (!result.has(entry.projectId))
136
136
  result.set(entry.projectId, entry.baseCommit);
137
137
  }
138
- const taskTurns = facts.turns
139
- .filter((turn) => (turn.workspace?.owner.type === "task"
140
- && turn.workspace.owner.taskId === facts.task.id))
138
+ const taskRuns = facts.runs
139
+ .filter((run) => (run.workspace?.owner.type === "task"
140
+ && run.workspace.owner.taskId === facts.task.id))
141
141
  .slice()
142
142
  .sort(compareCreated);
143
- for (const turn of taskTurns) {
144
- for (const entry of turn.workspace?.entries ?? []) {
143
+ for (const run of taskRuns) {
144
+ for (const entry of run.workspace?.entries ?? []) {
145
145
  if (!result.has(entry.projectId))
146
146
  result.set(entry.projectId, entry.baseCommit);
147
147
  }