@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.
- package/ARCHITECTURE.md +194 -399
- package/ARCHITECTURE.zh-CN.md +151 -0
- package/README.md +306 -1131
- package/dist/agent/adapterCatalog.js +15 -2
- package/dist/agent/agent.js +23 -3
- package/dist/agent/argumentPolicy.js +7 -1
- package/dist/agent/connectionPlan.js +62 -0
- package/dist/agent/executionComponents.js +158 -0
- package/dist/agent/launchEnvironment.js +31 -3
- package/dist/agent/managedRuntimeEnvironment.js +3 -5
- package/dist/{turn/turn.js → agentRun/agentRun.js} +166 -109
- package/dist/{turn/turnIdentity.js → agentRun/runIdentity.js} +4 -4
- package/dist/artifacts/artifactCapability.js +74 -0
- package/dist/artifacts/artifactCommitLock.js +249 -0
- package/dist/artifacts/artifactPaths.js +151 -0
- package/dist/artifacts/gitArtifactRef.js +146 -0
- package/dist/artifacts/managedGit.js +332 -0
- package/dist/artifacts/taskArtifactRepository.js +277 -0
- package/dist/brief/taskBrief.js +12 -0
- package/dist/cli/agentConfigurationPicker.js +13 -0
- package/dist/cli/commandCatalog.js +165 -74
- package/dist/cli/interactionCandidates.js +5 -5
- package/dist/cli/interactionPolicy.js +38 -8
- package/dist/cli/invocationRouter.js +1 -1
- package/dist/cli/managedDiagnostics.js +28 -0
- package/dist/cli/operatorWizard.js +1 -7
- package/dist/cli/roleOptionOrder.js +27 -0
- package/dist/cli/roleWizard.js +50 -14
- package/dist/cli/updateOrchestrator.js +1 -1
- package/dist/cli/updatePorts.js +3 -4
- package/dist/cli.js +245 -95
- package/dist/commands/agentCommands.js +72 -14
- package/dist/commands/capabilityCommands.js +9 -6
- package/dist/commands/configCommands.js +20 -20
- package/dist/commands/deliveryGuardPreflight.js +2 -2
- package/dist/commands/executionAuditCommands.js +24 -24
- package/dist/commands/globalRoleCommands.js +1 -1
- package/dist/commands/grantCommands.js +4 -4
- package/dist/commands/operatorCommands.js +34 -9
- package/dist/commands/projectCommands.js +4 -4
- package/dist/commands/resourcesCommands.js +2 -2
- package/dist/commands/roleConfiguration.js +25 -5
- package/dist/commands/roleRuntimeGuard.js +4 -5
- package/dist/commands/sessionCommands.js +3 -7
- package/dist/commands/taskActivationCommands.js +281 -0
- package/dist/commands/taskActor.js +28 -49
- package/dist/commands/taskCommands.js +1461 -720
- package/dist/commands/taskContextCommand.js +39 -583
- package/dist/commands/taskExecutionCommands.js +32 -32
- package/dist/commands/taskInputCommands.js +40 -104
- package/dist/commands/taskIntegrationCommands.js +3 -2
- package/dist/commands/taskIntegrationQueueCommands.js +1 -1
- package/dist/commands/taskNextActionCommand.js +8 -8
- package/dist/commands/taskOverviewCommand.js +33 -45
- package/dist/commands/taskRemoteDeliveryCommand.js +2 -2
- package/dist/commands/taskRoleRuntimeStatus.js +133 -102
- package/dist/commands/telemetryCommands.js +36 -38
- package/dist/config/configCatalog.js +4 -4
- package/dist/config/yuiConfig.js +8 -8
- package/dist/context/contextSnapshot.js +10 -10
- package/dist/context/dispatchContext.js +11 -11
- package/dist/context/roleSessionContext.js +6 -3
- package/dist/context/{turnContextPack.js → runContextPack.js} +158 -81
- package/dist/context/{turnInputContract.js → runInputContract.js} +73 -60
- package/dist/context/sessionBootstrapManifest.js +21 -2
- package/dist/context/sourceRunContext.js +30 -0
- package/dist/context/taskContext.js +481 -0
- package/dist/context/wakeNotification.js +27 -27
- package/dist/controller/agentRuntimeObserver.js +21 -24
- package/dist/controller/capabilityBridge.js +17 -6
- package/dist/controller/clientRuntime.js +65 -92
- package/dist/controller/controller.js +120 -188
- package/dist/controller/fileSchedulerStoreAdapter.js +787 -887
- package/dist/controller/jobControl.js +54 -85
- package/dist/controller/resourceInventory.js +8 -27
- package/dist/controller/resourceInventoryLinux.js +12 -13
- package/dist/controller/runtime.js +529 -479
- package/dist/controller/runtimeEventInbox.js +55 -25
- package/dist/controller/runtimeEventProcessor.js +22 -31
- package/dist/controller/{runtimeHookTurnFence.js → runtimeHookRunFence.js} +91 -115
- package/dist/controller/runtimeLaunchCoordinator.js +80 -426
- package/dist/controller/runtimeObservationHook.js +14 -18
- package/dist/controller/sessionNotify.js +16 -24
- package/dist/controller/sessionOwnerReconciliation.js +168 -50
- package/dist/controller/structuredProviderObservation.js +138 -99
- package/dist/coordination/workMailbox.js +3 -3
- package/dist/coordination/workMailboxQueue.js +36 -33
- package/dist/core/boundedRpc.js +8 -1
- package/dist/core/controllerClient.js +20 -1
- package/dist/core/controllerServer.js +4 -4
- package/dist/doctor/doctor.js +13 -2
- package/dist/domain/agentResultTransport.js +9 -9
- package/dist/execution/codexThreadNaming.js +2 -8
- package/dist/execution/executionHealth.js +51 -63
- package/dist/execution/reviewMainRun.js +137 -0
- package/dist/execution/workItemExecution.js +28 -29
- package/dist/execution/workItemExecutionProjection.js +99 -107
- package/dist/execution/workItemMainRun.js +141 -0
- package/dist/executor/agentAdapter.js +227 -20
- package/dist/executor/agentConfigurationCatalog.js +126 -4
- package/dist/executor/agentConfigurationProbe.js +162 -4
- package/dist/executor/agentExecutor.js +79 -78
- package/dist/executor/effectiveLaunch.js +105 -18
- package/dist/executor/executorRegistry.js +29 -44
- package/dist/executor/fileRoleLaunchPlanner.js +229 -154
- package/dist/executor/workspacePreflightClassification.js +16 -16
- package/dist/grant/capabilityGrant.js +6 -3
- package/dist/input/inputRequest.js +12 -10
- package/dist/integration/gitIntegrationService.js +4 -11
- package/dist/integration/integrationQueueService.js +4 -4
- package/dist/interaction/operatorPresentation.js +1 -1
- package/dist/kernel/builtinCapabilities.js +255 -12
- package/dist/kernel/capabilityRegistry.js +64 -18
- package/dist/kernel/instanceHost.js +12 -1
- package/dist/kernel/kernelPorts.js +2 -2
- package/dist/lifecycle/canonicalLifecycleEvent.js +44 -49
- package/dist/lifecycle/exactRunTerminalization.js +449 -0
- package/dist/message/message.js +118 -6
- package/dist/message/messageContinuation.js +204 -0
- package/dist/observability/executionAudit.js +70 -72
- package/dist/observability/faultClassification.js +2 -2
- package/dist/observability/orchestrationMetrics.js +8 -8
- package/dist/operator/operatorSessionHistory.js +1 -7
- package/dist/output/agentConfigurationPresentation.js +8 -3
- package/dist/output/agentRunConfigurationPresentation.js +128 -0
- package/dist/output/rolePresentation.js +54 -3
- package/dist/plugins/pluginChild.js +104 -0
- package/dist/plugins/pluginIntent.js +26 -0
- package/dist/plugins/pluginInterpreter.js +43 -0
- package/dist/plugins/pluginPackage.js +101 -0
- package/dist/plugins/pluginProcess.js +112 -0
- package/dist/plugins/pluginService.js +388 -0
- package/dist/profile/agentProfile.js +1 -1
- package/dist/repository/gitWorkspace.js +26 -4
- package/dist/repository/project.js +19 -4
- package/dist/repository/taskBaseFreshness.js +13 -13
- package/dist/repository/taskWorkspaceCoordinator.js +20 -27
- package/dist/repository/taskWorkspacePreparer.js +344 -83
- package/dist/resources/autoResourceGc.js +3 -3
- package/dist/resources/liveReferences.js +3 -3
- package/dist/resources/projectResource.js +75 -0
- package/dist/resources/projectResourceService.js +343 -0
- package/dist/resources/resourceDiscovery.js +6 -6
- package/dist/resources/resourceGc.js +1 -1
- package/dist/resources/resourceRegistrar.js +1 -1
- package/dist/resources/resourceTypes.js +1 -1
- package/dist/review/deltaRecheck.js +3 -3
- package/dist/review/reviewAcceptance.js +16 -16
- package/dist/review/reviewDecision.js +7 -7
- package/dist/review/reviewRound.js +21 -20
- package/dist/review/reviewerAvailability.js +2 -2
- package/dist/role/role.js +51 -7
- package/dist/role/taskRoleUpdate.js +30 -0
- package/dist/runtime/acpProtocol.js +425 -0
- package/dist/runtime/acpSession.js +731 -0
- package/dist/runtime/acpSessionConfiguration.js +260 -0
- package/dist/runtime/agentDriver.js +30 -11
- package/dist/runtime/agentEndpoint.js +278 -0
- package/dist/runtime/agentEndpointIdentity.js +86 -0
- package/dist/runtime/agentEndpointOwnership.js +239 -0
- package/dist/runtime/agentError.js +2 -10
- package/dist/runtime/agentHost.js +565 -314
- package/dist/runtime/agentRunConfiguration.js +258 -0
- package/dist/runtime/builtinAgentDrivers.js +134 -18
- package/dist/runtime/builtinAgentErrorMappers.js +55 -3
- package/dist/runtime/builtinTranscriptUsage.js +1 -1
- package/dist/runtime/claude-process-owner +0 -0
- package/dist/runtime/codexAppServerRuntime.js +38 -30
- package/dist/runtime/codexInteractiveHost.js +41 -6
- package/dist/runtime/continuationManager.js +2 -6
- package/dist/runtime/executionEnvironment.js +30 -0
- package/dist/runtime/firstProgressAdvisory.js +11 -11
- package/dist/runtime/index.js +4 -3
- package/dist/runtime/jsonLineChannel.js +109 -0
- package/dist/runtime/launchBroker.js +91 -16
- package/dist/runtime/launchDiagnostics.js +2 -2
- package/dist/runtime/lifecycleReservation.js +10 -18
- package/dist/runtime/managedCaller.js +61 -17
- package/dist/runtime/nativeSessionControl.js +102 -0
- package/dist/runtime/ports.js +6 -21
- package/dist/runtime/processExitObservation.js +8 -7
- package/dist/runtime/promptEnvelope.js +17 -6
- package/dist/runtime/providerContinuation.js +3 -9
- package/dist/runtime/providerContinuationReconciliationService.js +4 -13
- package/dist/runtime/providerControl.js +2 -7
- package/dist/runtime/providerRuntimeIdentity.js +110 -222
- package/dist/runtime/providerRuntimeReconciler.js +5 -9
- package/dist/runtime/runtimeBinding.js +0 -1
- package/dist/runtime/runtimeContinuationProjection.js +4 -7
- package/dist/runtime/runtimeDeadlines.js +9 -0
- package/dist/runtime/runtimeHealthPolicy.js +1 -1
- package/dist/runtime/runtimeObservation.js +29 -65
- package/dist/runtime/runtimeProjection.js +43 -51
- package/dist/runtime/runtimeSessionCandidate.js +1 -3
- package/dist/runtime/sessionLaunchRequest.js +3 -7
- package/dist/runtime/sessionOwnerIdentity.js +7 -54
- package/dist/runtime/sessionOwnerRegistry.js +22 -17
- package/dist/runtime/sessionReconciliation.js +4 -8
- package/dist/runtime/sessionTerminationGuard.js +70 -259
- package/dist/runtime/sessionTokenMetrics.js +5 -16
- package/dist/runtime/structuredProviderHost.js +237 -117
- package/dist/runtime/taskRuntimeIsolation.js +39 -122
- package/dist/runtime/tmuxAdapters.js +39 -86
- package/dist/scheduler/activeRoleRunDelivery.js +354 -0
- package/dist/scheduler/leaderWakeupProcessor.js +75 -266
- package/dist/scheduler/operatorInputNotificationProcessor.js +1 -1
- package/dist/scheduler/ports.js +80 -9
- package/dist/scheduler/{roleTurnLiveness.js → roleRunLiveness.js} +26 -30
- package/dist/scheduler/{roleTurnStall.js → roleRunStall.js} +128 -139
- package/dist/scheduler/taskExecutionProjection.js +120 -124
- package/dist/scheduler/taskObservabilityProjection.js +29 -29
- package/dist/scheduler/taskWake.js +11 -4
- package/dist/scheduler/wakeReason.js +9 -1
- package/dist/setup/setupCommand.js +3 -7
- package/dist/storage/migrations/agentRunContract.js +159 -0
- package/dist/storage/migrations/artifactsToGit.js +338 -0
- package/dist/storage/migrations/removeRuntimeGeneration.js +207 -0
- package/dist/storage/migrations/submitIntent.js +126 -0
- package/dist/storage/sqliteSchema.js +467 -7
- package/dist/storage/sqliteStore.js +355 -220
- package/dist/storage/storageVersions.js +1 -1
- package/dist/storage/storeRpc.js +10 -5
- package/dist/storage/taskStore.js +13 -11
- package/dist/storage/upgrade/upgradeOrchestrator.js +5 -7
- package/dist/surface/surfaceContributions.js +102 -0
- package/dist/task/completionReadiness.js +32 -6
- package/dist/task/deliveryGuard.js +16 -16
- package/dist/task/draftPlan.js +72 -12
- package/dist/task/nextAction.js +144 -128
- package/dist/task/remoteDelivery.js +6 -6
- package/dist/task/task.js +184 -18
- package/dist/task/taskActivation.js +327 -0
- package/dist/task/taskActivationService.js +408 -0
- package/dist/task/taskRecordReference.js +5 -4
- package/dist/task/taskRecordRetirement.js +1 -1
- package/dist/task/taskSubmission.js +236 -0
- package/dist/telemetry/sqliteTelemetryStore.js +55 -68
- package/dist/telemetry/telemetryConfig.js +14 -14
- package/dist/telemetry/telemetryWiring.js +2 -2
- package/dist/web/assets/assetManifest.js +2 -0
- package/dist/web/assets/client/app.js +121 -20
- package/dist/web/assets/client/components.js +87 -54
- package/dist/web/assets/client/i18n.js +83 -41
- package/dist/web/assets/client/markdown.js +1 -1
- package/dist/web/assets/client/taskSurface.js +442 -0
- package/dist/web/assets/client/view.js +49 -44
- package/dist/web/assets/shell.js +1 -1
- package/dist/web/assets/styles/cards.js +22 -4
- package/dist/web/controllerWeb.js +60 -0
- package/dist/web/webMutation.js +28 -0
- package/dist/web/webServer.js +133 -8
- package/dist/web/webSnapshot.js +81 -74
- package/dist/web/webTaskSurface.js +64 -0
- package/dist/workItem/dependencyGate.js +1 -1
- package/dist/workItem/workItem.js +84 -48
- package/dist/workspace/workItemChangeSetManager.js +16 -9
- package/docs/agent-result-consumption.md +96 -0
- package/docs/agent-result-consumption.zh-CN.md +81 -0
- package/docs/agent-runtime-drivers.md +93 -0
- package/docs/agent-runtime-drivers.zh-CN.md +77 -0
- package/docs/architecture/README.md +50 -0
- package/docs/architecture/README.zh-CN.md +43 -0
- package/docs/architecture/capabilities-and-resources.md +118 -0
- package/docs/architecture/capabilities-and-resources.zh-CN.md +83 -0
- package/docs/managed-turn-and-session-runtime.md +224 -0
- package/docs/managed-turn-and-session-runtime.zh-CN.md +180 -0
- package/docs/observability/README.md +83 -0
- package/docs/observability/README.zh-CN.md +71 -0
- package/docs/plugin-sdk.md +393 -0
- package/docs/plugin-sdk.zh-CN.md +293 -0
- package/docs/provider-runtime.md +165 -0
- package/docs/provider-runtime.zh-CN.md +132 -0
- package/docs/release-workflow.md +305 -0
- package/docs/release-workflow.zh-CN.md +237 -0
- package/docs/roles-and-configuration.md +115 -0
- package/docs/roles-and-configuration.zh-CN.md +96 -0
- package/docs/sqlite-control-plane-design.md +78 -0
- package/docs/sqlite-control-plane-design.zh-CN.md +62 -0
- package/docs/task-dag-semantics.md +80 -0
- package/docs/task-dag-semantics.zh-CN.md +59 -0
- package/docs/task-delivery.md +105 -0
- package/docs/task-delivery.zh-CN.md +82 -0
- package/docs/task-local-identity.md +8 -6
- package/docs/task-local-identity.zh-CN.md +58 -0
- package/docs/testing/verification-levels.md +88 -0
- package/docs/testing/verification-levels.zh-CN.md +69 -0
- package/i18n/README.zh-CN.md +270 -722
- package/package.json +3 -2
- package/skills/yui-leader/SKILL.md +88 -304
- package/skills/yui-leader/references/execution.md +303 -0
- package/skills/yui-leader/references/integration.md +39 -0
- package/skills/yui-leader/references/planning.md +109 -0
- package/skills/yui-leader/references/replicated-execution.md +42 -0
- package/skills/yui-leader/references/task-plugins.md +37 -0
- package/skills/yui-operator/SKILL.md +46 -62
- package/skills/yui-reviewer/SKILL.md +35 -36
- package/skills/yui-runtime/SKILL.md +88 -24
- package/skills/yui-runtime/references/publication.md +22 -0
- package/skills/yui-runtime/references/recovery.md +64 -0
- package/skills/yui-worker/SKILL.md +37 -39
- package/dist/cli/roleOptionCatalog.js +0 -68
- package/dist/context/sourceTurnContext.js +0 -30
- package/dist/execution/reviewMainTurn.js +0 -161
- package/dist/execution/workItemMainTurn.js +0 -164
- package/dist/lifecycle/exactTurnTerminalization.js +0 -407
- package/dist/runtime/preallocatedNativeSession.js +0 -13
- package/dist/runtime/runtimeStopReceipt.js +0 -42
- package/dist/scheduler/activeRoleTurnDelivery.js +0 -315
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { serializeRunInputEnvelope } from "../context/runInputContract.js";
|
|
3
|
+
import { roleSessionMayContinue, sameEffectiveLaunch } from "../executor/effectiveLaunch.js";
|
|
4
|
+
import { RuntimeLifecycleBusyError } from "../runtime/lifecycleReservation.js";
|
|
5
|
+
import { managedProviderTurnId } from "../runtime/providerRuntimeIdentity.js";
|
|
6
|
+
import { formatProviderDeliveryFailure, providerDeliveryFailureFacts, innermostCauseName, serializeAgentErrorRaw } from "../runtime/agentError.js";
|
|
7
|
+
import { RuntimeLaunchFailure } from "../runtime/launchDiagnostics.js";
|
|
8
|
+
import { RuntimeLaunchError } from "../runtime/ports.js";
|
|
9
|
+
import { formatRunReceiptId } from "../task/taskRecordReference.js";
|
|
10
|
+
import { taskOwnsManagedWorkspace } from "../task/task.js";
|
|
11
|
+
import { runInputEnvelope } from "../agentRun/agentRun.js";
|
|
12
|
+
import { captureRoleRunDispatch } from "../coordination/workMailboxQueue.js";
|
|
13
|
+
import { isSchedulerPlanningDraft, isSchedulerTaskWorkspaceReady, selectedActiveSchedulerTasks, selectedSchedulerRoles } from "./ports.js";
|
|
14
|
+
/**
|
|
15
|
+
* Sole managed Provider write path. A AgentRun is durable workflow intent;
|
|
16
|
+
* each invocation here is an ordinary Provider-native Turn on the Role's
|
|
17
|
+
* shared conversation. Stable request ids make a repeated submit idempotent
|
|
18
|
+
* without copying Provider delivery state into AgentRun or WorkMailbox.
|
|
19
|
+
*/
|
|
20
|
+
export async function processActiveRoleRunDeliveries(store, delivery, now, selection) {
|
|
21
|
+
const results = [];
|
|
22
|
+
// Planning Turns are admitted on a Draft, so delivery must be able to see
|
|
23
|
+
// that Draft or an admitted planning Turn would never be delivered, resumed
|
|
24
|
+
// or terminalized. Selection still admits it only on its durable Turn.
|
|
25
|
+
for (const task of selectedActiveSchedulerTasks(store, selection, {
|
|
26
|
+
includePlanningDrafts: true
|
|
27
|
+
})) {
|
|
28
|
+
store.prepareMessageContinuations?.(task.id, now);
|
|
29
|
+
for (const role of selectedSchedulerRoles(store, task.id, selection)) {
|
|
30
|
+
const run = store.getActiveRun(task.id, role.name);
|
|
31
|
+
if (run === null)
|
|
32
|
+
continue;
|
|
33
|
+
results.push(await deliverActiveRun(store, delivery, task, role, run, now));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
async function deliverActiveRun(store, delivery, task, role, run, now) {
|
|
39
|
+
const base = { taskId: task.id, roleName: role.name, runId: run.id };
|
|
40
|
+
if (!isSchedulerTaskWorkspaceReady(task, store.getTaskWorkspace(task.id), run.purpose)) {
|
|
41
|
+
return { ...base, status: "skipped", reason: "workspace-not-ready" };
|
|
42
|
+
}
|
|
43
|
+
const dispatchToken = captureRoleRunDispatch(store.getWorkMailbox({
|
|
44
|
+
kind: "role",
|
|
45
|
+
taskId: task.id,
|
|
46
|
+
roleName: role.name
|
|
47
|
+
}), {
|
|
48
|
+
taskId: task.id,
|
|
49
|
+
roleName: role.name,
|
|
50
|
+
runId: run.id
|
|
51
|
+
});
|
|
52
|
+
const sessionSet = store.getTaskRoleSessionSet?.(task.id, role.name) ?? null;
|
|
53
|
+
const binding = sessionSet?.providerBinding ?? null;
|
|
54
|
+
const observedRun = binding?.run ?? null;
|
|
55
|
+
const initialAttemptId = formatRunReceiptId(task.id, run.id);
|
|
56
|
+
const currentProviderTurn = managedProviderTurnId(observedRun) === run.id ? observedRun : null;
|
|
57
|
+
if (binding?.authority.owner === "human"
|
|
58
|
+
|| binding?.authority.owner === "unknown") {
|
|
59
|
+
return { ...base, status: "skipped", reason: "writer-attached" };
|
|
60
|
+
}
|
|
61
|
+
if (currentProviderTurn === null && observedRun !== null
|
|
62
|
+
&& ["submitting", "accepted", "delivery-unknown"].includes(observedRun.status)) {
|
|
63
|
+
return { ...base, status: "skipped",
|
|
64
|
+
reason: observedRun.status === "delivery-unknown" ? "delivery-uncertain" : "not-ready" };
|
|
65
|
+
}
|
|
66
|
+
if (currentProviderTurn?.status === "accepted") {
|
|
67
|
+
settleAcceptedRoleRunDispatch(store, run, dispatchToken);
|
|
68
|
+
return { ...base, status: "skipped", reason: "not-ready" };
|
|
69
|
+
}
|
|
70
|
+
if (currentProviderTurn?.status === "submitting") {
|
|
71
|
+
return { ...base, status: "skipped", reason: "not-ready" };
|
|
72
|
+
}
|
|
73
|
+
if (currentProviderTurn?.status === "delivery-unknown") {
|
|
74
|
+
return { ...base, status: "skipped", reason: "delivery-uncertain",
|
|
75
|
+
error: currentProviderTurn.terminalReason ?? "Provider acceptance is unknown; no replay is permitted." };
|
|
76
|
+
}
|
|
77
|
+
if (currentProviderTurn?.status === "rejected") {
|
|
78
|
+
return failRunDelivery(store, run, now, "runtime-failed", currentProviderTurn.terminalReason ?? "Provider rejected the input.");
|
|
79
|
+
}
|
|
80
|
+
if (currentProviderTurn !== null && currentProviderTurn.status !== "deferred") {
|
|
81
|
+
const reason = currentProviderTurn.terminalReason
|
|
82
|
+
?? `Provider Turn ended with status ${currentProviderTurn.status} without recording its AgentRun result.`;
|
|
83
|
+
// A terminal Provider projection without an application result is a
|
|
84
|
+
// framework consistency failure, not evidence that the Agent omitted its
|
|
85
|
+
// report. Keep the exact input fenced; never submit it again.
|
|
86
|
+
return { ...base, status: "skipped", reason: "delivery-uncertain", error: reason };
|
|
87
|
+
}
|
|
88
|
+
const lastSubmitError = (store.listEvents?.(task.id) ?? []).filter((event) => event.type === "runtime.agent-error" && event.payload.runId === run.id
|
|
89
|
+
&& event.payload.roleName === role.name && event.payload.phase === "turn-submit").at(-1);
|
|
90
|
+
if (currentProviderTurn === null && lastSubmitError?.payload.inputDisposition === "unknown") {
|
|
91
|
+
return { ...base, status: "skipped", reason: "delivery-uncertain", error: lastSubmitError.payload.message };
|
|
92
|
+
}
|
|
93
|
+
const deferredBeforeRegistration = lastSubmitError?.payload.inputDisposition === "not-accepted"
|
|
94
|
+
&& lastSubmitError.payload.registrationDisposition === "not-committed"
|
|
95
|
+
&& lastSubmitError.payload.errorName === "ProviderTurnBusyError";
|
|
96
|
+
// Only a durable, exact busy/not-accepted disposition permits a new
|
|
97
|
+
// transport attempt. Keep the business input and every earlier receipt.
|
|
98
|
+
const attemptId = currentProviderTurn?.status === "deferred" || deferredBeforeRegistration
|
|
99
|
+
? `${initialAttemptId}/attempt/${randomUUID()}`
|
|
100
|
+
: initialAttemptId;
|
|
101
|
+
const existingSession = store.getRoleSession(task.id, role.name, run.effective.agentId);
|
|
102
|
+
// The first attempted admission may already have opened this fixed native
|
|
103
|
+
// Session. A busy retry resumes it; it does not repeat the original launch.
|
|
104
|
+
const preparedHere = existingSession?.nativeSessionId !== undefined
|
|
105
|
+
&& (store.listEvents?.(task.id) ?? []).some((event) => event.type === "run.session-prepared"
|
|
106
|
+
&& event.payload.runId === run.id && event.payload.nativeSessionId === existingSession.nativeSessionId);
|
|
107
|
+
const mode = (currentProviderTurn?.status === "deferred" || preparedHere) && existingSession?.nativeSessionId !== undefined
|
|
108
|
+
? "resume" : run.mode;
|
|
109
|
+
let prepared;
|
|
110
|
+
let submitted = false;
|
|
111
|
+
try {
|
|
112
|
+
const nativeSessionId = mode === "resume"
|
|
113
|
+
? requireResumeSession(role, run, existingSession)
|
|
114
|
+
: undefined;
|
|
115
|
+
prepared = await delivery.prepareRoleSession({
|
|
116
|
+
taskId: task.id,
|
|
117
|
+
roleName: role.name,
|
|
118
|
+
agentId: run.effective.agentId,
|
|
119
|
+
adapterId: run.effective.adapterId,
|
|
120
|
+
effective: run.effective,
|
|
121
|
+
workspace: run.effective.workspace.root,
|
|
122
|
+
...(run.workspace === undefined ? {} : { managedWorkspace: run.workspace }),
|
|
123
|
+
// A Task owning no workspace by design states that explicitly, so the
|
|
124
|
+
// launch does not read the absent workspace as a missing one and fail
|
|
125
|
+
// closed (S27). Two distinct cases qualify: a Task activated with an
|
|
126
|
+
// empty plan and binding no Project, and a Draft planning conversation,
|
|
127
|
+
// which may already bind a Project but has not activated, so no worktree
|
|
128
|
+
// exists or is owed yet. Declaring it free is what keeps the isolation
|
|
129
|
+
// fence honest instead of letting it fail on a workspace nobody promised.
|
|
130
|
+
...(run.workspace === undefined
|
|
131
|
+
&& (isSchedulerPlanningDraft(task, run.purpose)
|
|
132
|
+
|| !taskOwnsManagedWorkspace(task))
|
|
133
|
+
? { workspaceFree: true }
|
|
134
|
+
: {}),
|
|
135
|
+
mode,
|
|
136
|
+
runId: run.id,
|
|
137
|
+
...(nativeSessionId === undefined ? {} : { nativeSessionId }),
|
|
138
|
+
beforeHostStart: (preflight) => persistPreStartSession(store, task, role, run, existingSession, mode, preflight, now)
|
|
139
|
+
});
|
|
140
|
+
const preparedSession = prepared.session === undefined
|
|
141
|
+
? existingSession
|
|
142
|
+
: validateRoleSession(role, run, existingSession, mode, prepared.session);
|
|
143
|
+
store.saveRoleRunPrepared({
|
|
144
|
+
task,
|
|
145
|
+
role,
|
|
146
|
+
run,
|
|
147
|
+
session: preparedSession,
|
|
148
|
+
now
|
|
149
|
+
});
|
|
150
|
+
const ready = await delivery.waitUntilReady(prepared);
|
|
151
|
+
const readySession = validateRoleSession(role, run, existingSession, mode, ready.session);
|
|
152
|
+
store.saveRoleRunPrepared({
|
|
153
|
+
task,
|
|
154
|
+
role,
|
|
155
|
+
run,
|
|
156
|
+
session: readySession,
|
|
157
|
+
now
|
|
158
|
+
});
|
|
159
|
+
submitted = true;
|
|
160
|
+
const outcome = await delivery.sendOnce({
|
|
161
|
+
delivery: ready,
|
|
162
|
+
receiptId: attemptId,
|
|
163
|
+
text: serializeRunInputEnvelope(runInputEnvelope(run))
|
|
164
|
+
});
|
|
165
|
+
if (outcome.status === "pending") {
|
|
166
|
+
// The original Host request is still in flight. Its durable submitting
|
|
167
|
+
// attempt prevents another write; only the eventual receipt consumes
|
|
168
|
+
// this mailbox input. A normal wait is neither failure nor acceptance.
|
|
169
|
+
forget(delivery, task.id, role.name, run.id);
|
|
170
|
+
return { ...base, status: "skipped", reason: "not-ready" };
|
|
171
|
+
}
|
|
172
|
+
if (outcome.status === "busy" || outcome.status === "unavailable") {
|
|
173
|
+
if (outcome.status === "busy" && outcome.failure?.inputDisposition === "not-accepted") {
|
|
174
|
+
store.recordAgentError?.({ taskId: task.id, roleName: role.name, runId: run.id,
|
|
175
|
+
source: "host", phase: "turn-submit", message: outcome.failure.detail,
|
|
176
|
+
raw: outcome.failure.raw ?? serializeAgentErrorRaw(outcome.failure),
|
|
177
|
+
inputDisposition: "not-accepted", ...providerDeliveryFailureFacts(outcome.failure),
|
|
178
|
+
attemptId }, now);
|
|
179
|
+
}
|
|
180
|
+
forget(delivery, task.id, role.name, run.id);
|
|
181
|
+
return {
|
|
182
|
+
...base,
|
|
183
|
+
status: "skipped",
|
|
184
|
+
reason: outcome.status === "busy" ? "not-ready" : "runtime-unavailable"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (outcome.status === "rejected" || outcome.status === "delivery-unknown") {
|
|
188
|
+
forget(delivery, task.id, role.name, run.id);
|
|
189
|
+
const unknown = outcome.status === "delivery-unknown";
|
|
190
|
+
const failure = outcome.failure;
|
|
191
|
+
// The Host's own account of the failure. Without it the only honest
|
|
192
|
+
// statement is that delivery did not complete — never that the Provider
|
|
193
|
+
// rejected the input, which is one specific cause among many.
|
|
194
|
+
const cause = failure === undefined
|
|
195
|
+
? `The Agent Host did not deliver the managed AgentRun (${outcome.status}) and reported no cause.`
|
|
196
|
+
: formatProviderDeliveryFailure(failure);
|
|
197
|
+
// This path is the common Provider write failure and previously left no
|
|
198
|
+
// durable fact at all, so the cause was unrecoverable after the fact.
|
|
199
|
+
store.recordAgentError?.({
|
|
200
|
+
taskId: task.id,
|
|
201
|
+
roleName: role.name,
|
|
202
|
+
runId: run.id,
|
|
203
|
+
source: "host",
|
|
204
|
+
phase: failure?.phase ?? "turn-submit",
|
|
205
|
+
message: cause,
|
|
206
|
+
// The Host already serialized the complete redacted chain. Re-serializing
|
|
207
|
+
// the failure object here would persist this layer's wrapper instead of
|
|
208
|
+
// the original cause, which is the detail an authorized reader needs.
|
|
209
|
+
raw: failure?.raw ?? serializeAgentErrorRaw(failure ?? cause),
|
|
210
|
+
inputDisposition: failure?.inputDisposition ?? (unknown ? "unknown" : "not-accepted"),
|
|
211
|
+
...providerDeliveryFailureFacts(failure),
|
|
212
|
+
attemptId
|
|
213
|
+
}, now);
|
|
214
|
+
if (unknown)
|
|
215
|
+
return { ...base, status: "skipped", reason: "delivery-uncertain", error: cause };
|
|
216
|
+
return failRunDelivery(store, run, now, "runtime-failed", cause);
|
|
217
|
+
}
|
|
218
|
+
forget(delivery, task.id, role.name, run.id);
|
|
219
|
+
settleAcceptedRoleRunDispatch(store, run, dispatchToken);
|
|
220
|
+
return {
|
|
221
|
+
...base,
|
|
222
|
+
status: outcome.status === "sent" ? "delivered" : "already-delivered"
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
+
// Preserve the structured cause alongside the readable diagnosis.
|
|
228
|
+
const causeName = innermostCauseName(error);
|
|
229
|
+
store.recordAgentError?.({
|
|
230
|
+
taskId: task.id,
|
|
231
|
+
roleName: role.name,
|
|
232
|
+
runId: run.id,
|
|
233
|
+
source: error instanceof RuntimeLaunchError || error instanceof RuntimeLaunchFailure ? "host" : "yui",
|
|
234
|
+
phase: submitted ? "turn-submit" : mode === "new" ? "session-start" : "session-restore",
|
|
235
|
+
message,
|
|
236
|
+
raw: serializeAgentErrorRaw(error),
|
|
237
|
+
inputDisposition: submitted ? "unknown" : "not-accepted",
|
|
238
|
+
// Nothing was submitted, so the Provider provably holds no registration
|
|
239
|
+
// for this attempt; after a submit the Host owns that fact, not this layer.
|
|
240
|
+
...(submitted ? {} : { registrationDisposition: "not-committed" }),
|
|
241
|
+
...(error instanceof Error ? { errorName: error.name } : {}),
|
|
242
|
+
...(causeName === undefined ? {} : { causeName }),
|
|
243
|
+
attemptId
|
|
244
|
+
}, now);
|
|
245
|
+
if (error instanceof RuntimeLifecycleBusyError
|
|
246
|
+
|| (error instanceof RuntimeLaunchError && error.retryable)) {
|
|
247
|
+
return {
|
|
248
|
+
...base,
|
|
249
|
+
status: "skipped",
|
|
250
|
+
reason: error instanceof RuntimeLaunchError && error.reason === "writable-client"
|
|
251
|
+
? "writer-attached"
|
|
252
|
+
: "runtime-unavailable",
|
|
253
|
+
error: message
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
forget(delivery, task.id, role.name, run.id);
|
|
257
|
+
if (submitted)
|
|
258
|
+
return { ...base, status: "skipped", reason: "delivery-uncertain", error: message };
|
|
259
|
+
return failRunDelivery(store, run, now, "startup-failed", message);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function failRunDelivery(store, run, now, failureReason, summary) {
|
|
263
|
+
const disposition = store.saveRoleRunDeliveryFailure({
|
|
264
|
+
taskId: run.taskId,
|
|
265
|
+
roleName: run.roleName,
|
|
266
|
+
agentId: run.effective.agentId,
|
|
267
|
+
adapterId: run.effective.adapterId,
|
|
268
|
+
runId: run.id,
|
|
269
|
+
failureReason,
|
|
270
|
+
summary,
|
|
271
|
+
now
|
|
272
|
+
});
|
|
273
|
+
return {
|
|
274
|
+
taskId: run.taskId,
|
|
275
|
+
roleName: run.roleName,
|
|
276
|
+
runId: run.id,
|
|
277
|
+
status: disposition === "failed" ? "failed" : "skipped",
|
|
278
|
+
reason: failureReason === "delivery-unknown" ? "delivery-uncertain" : "launch-failed",
|
|
279
|
+
error: summary,
|
|
280
|
+
...(disposition === "failed" ? { terminalized: true } : {})
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function settleAcceptedRoleRunDispatch(store, run, expected) {
|
|
284
|
+
store.settleRoleRunDispatch({
|
|
285
|
+
taskId: run.taskId,
|
|
286
|
+
roleName: run.roleName,
|
|
287
|
+
runId: run.id,
|
|
288
|
+
...(expected === undefined ? {} : { expected })
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
function persistPreStartSession(store, task, role, run, existing, mode, preflight, now) {
|
|
292
|
+
if (preflight.owner.scope !== "task" || preflight.owner.taskId !== task.id || preflight.owner.roleName !== role.name || preflight.runId !== run.id) {
|
|
293
|
+
throw new Error(`Pre-start launch fence changed the active Role AgentRun: ${task.id}/${role.name}.`);
|
|
294
|
+
}
|
|
295
|
+
const session = preflight.nativeSessionId === undefined ? null : {
|
|
296
|
+
agentId: preflight.agentId,
|
|
297
|
+
adapterId: preflight.adapterId,
|
|
298
|
+
nativeSessionId: preflight.nativeSessionId,
|
|
299
|
+
...(preflight.sessionTitle === undefined ? {} : { title: preflight.sessionTitle }),
|
|
300
|
+
status: "active",
|
|
301
|
+
effective: preflight.effective
|
|
302
|
+
};
|
|
303
|
+
store.saveRoleRunPrepared({
|
|
304
|
+
task,
|
|
305
|
+
role,
|
|
306
|
+
run,
|
|
307
|
+
session: validateRoleSession(role, run, existing, mode, session),
|
|
308
|
+
now
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function validateRoleSession(role, run, existing, mode, session) {
|
|
312
|
+
if (mode === "new" && session === null)
|
|
313
|
+
return null;
|
|
314
|
+
if (session === null || !hasText(session.nativeSessionId)) {
|
|
315
|
+
throw new Error(`Ready Role session has no native session id: ${role.taskId}/${role.name}.`);
|
|
316
|
+
}
|
|
317
|
+
if (session.agentId !== run.effective.agentId
|
|
318
|
+
|| session.adapterId !== run.effective.adapterId) {
|
|
319
|
+
throw new Error(`Ready Role session identity changed: ${role.taskId}/${role.name}.`);
|
|
320
|
+
}
|
|
321
|
+
const compatible = mode === "resume"
|
|
322
|
+
? roleSessionMayContinue(session.effective, run.effective)
|
|
323
|
+
: sameEffectiveLaunch(session.effective, run.effective);
|
|
324
|
+
if (!compatible) {
|
|
325
|
+
throw new Error(`Ready Role session effective snapshot changed: ${role.taskId}/${role.name}.`);
|
|
326
|
+
}
|
|
327
|
+
if (mode === "resume" && session.nativeSessionId !== existing?.nativeSessionId) {
|
|
328
|
+
throw new Error(`Role resume changed the fixed native session id: ${role.taskId}/${role.name}.`);
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
...session,
|
|
332
|
+
status: "active",
|
|
333
|
+
...(mode === "resume" && existing !== null ? { effective: existing.effective } : {})
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function requireResumeSession(role, run, session) {
|
|
337
|
+
if (session === null || !hasText(session.nativeSessionId)) {
|
|
338
|
+
throw new Error(`Role resume has no fixed native session: ${role.taskId}/${role.name}.`);
|
|
339
|
+
}
|
|
340
|
+
if (!roleSessionMayContinue(session.effective, run.effective)) {
|
|
341
|
+
throw new Error(`Role resume effective snapshot drifted: ${role.taskId}/${role.name}.`);
|
|
342
|
+
}
|
|
343
|
+
return session.nativeSessionId;
|
|
344
|
+
}
|
|
345
|
+
function forget(delivery, taskId, roleName, runId) {
|
|
346
|
+
delivery.forgetPrepared?.({
|
|
347
|
+
taskId,
|
|
348
|
+
roleName,
|
|
349
|
+
runId,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
function hasText(value) {
|
|
353
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
354
|
+
}
|