@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.
- package/ARCHITECTURE.md +192 -399
- package/README.md +127 -1149
- 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/brief/taskBrief.js +12 -0
- package/dist/cli/agentConfigurationPicker.js +13 -0
- package/dist/cli/commandCatalog.js +157 -70
- 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 +178 -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 +1 -7
- 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 +259 -0
- package/dist/commands/taskActor.js +28 -49
- package/dist/commands/taskCommands.js +1188 -710
- 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} +146 -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 +458 -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 +114 -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 +247 -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 +62 -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 +380 -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 +123 -0
- package/dist/resources/projectResourceService.js +421 -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 +1 -0
- package/dist/storage/migrations/agentRunContract.js +159 -0
- package/dist/storage/migrations/removeRuntimeGeneration.js +207 -0
- package/dist/storage/sqliteSchema.js +431 -5
- package/dist/storage/sqliteStore.js +375 -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 +301 -0
- package/dist/task/taskActivationService.js +392 -0
- package/dist/task/taskRecordReference.js +5 -4
- package/dist/task/taskRecordRetirement.js +1 -1
- 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 +120 -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 +353 -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 +118 -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 +80 -48
- package/dist/workspace/workItemChangeSetManager.js +16 -9
- package/docs/agent-result-consumption.md +94 -0
- package/docs/agent-runtime-drivers.md +91 -0
- package/docs/architecture/README.md +38 -0
- package/docs/architecture/capabilities-and-resources.md +79 -0
- package/docs/managed-turn-and-session-runtime.md +222 -0
- package/docs/observability/README.md +81 -0
- package/docs/plugin-sdk.md +290 -0
- package/docs/provider-runtime.md +163 -0
- package/docs/release-workflow.md +303 -0
- package/docs/roles-and-configuration.md +113 -0
- package/docs/sqlite-control-plane-design.md +76 -0
- package/docs/task-dag-semantics.md +57 -0
- package/docs/task-delivery.md +103 -0
- package/docs/task-local-identity.md +6 -6
- package/docs/testing/verification-levels.md +86 -0
- package/i18n/README.zh-CN.md +98 -739
- package/package.json +2 -2
- package/skills/yui-leader/SKILL.md +130 -103
- package/skills/yui-leader/references/integration.md +39 -0
- package/skills/yui-leader/references/replicated-execution.md +42 -0
- package/skills/yui-leader/references/task-plugins.md +33 -0
- package/skills/yui-operator/SKILL.md +30 -59
- 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
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { serializeTurnInputEnvelope } from "../context/turnInputContract.js";
|
|
2
|
-
import { roleSessionMayContinue, sameEffectiveLaunch } from "../executor/effectiveLaunch.js";
|
|
3
|
-
import { RuntimeLifecycleBusyError } from "../runtime/lifecycleReservation.js";
|
|
4
|
-
import { managedProviderTurnId } from "../runtime/providerRuntimeIdentity.js";
|
|
5
|
-
import { formatProviderDeliveryFailure, providerDeliveryFailureFacts, innermostCauseName, serializeAgentErrorRaw } from "../runtime/agentError.js";
|
|
6
|
-
import { RuntimeLaunchFailure } from "../runtime/launchDiagnostics.js";
|
|
7
|
-
import { RuntimeGenerationMismatchError, RuntimeLaunchError } from "../runtime/ports.js";
|
|
8
|
-
import { formatTurnReceiptId } from "../task/taskRecordReference.js";
|
|
9
|
-
import { turnInputEnvelope } from "../turn/turn.js";
|
|
10
|
-
import { captureRoleTurnDispatch } from "../coordination/workMailboxQueue.js";
|
|
11
|
-
import { isSchedulerTaskWorkspaceReady, selectedActiveSchedulerTasks, selectedSchedulerRoles } from "./ports.js";
|
|
12
|
-
/**
|
|
13
|
-
* Sole managed Provider write path. A Turn is durable workflow intent;
|
|
14
|
-
* each invocation here is an ordinary Provider-native Turn on the Role's
|
|
15
|
-
* shared conversation. Stable request ids make a repeated submit idempotent
|
|
16
|
-
* without copying Provider delivery state into Turn or WorkMailbox.
|
|
17
|
-
*/
|
|
18
|
-
export async function processActiveRoleTurnDeliveries(store, delivery, now, selection) {
|
|
19
|
-
const results = [];
|
|
20
|
-
for (const task of selectedActiveSchedulerTasks(store, selection)) {
|
|
21
|
-
for (const role of selectedSchedulerRoles(store, task.id, selection)) {
|
|
22
|
-
const turn = store.getActiveTurn(task.id, role.name);
|
|
23
|
-
if (turn === null)
|
|
24
|
-
continue;
|
|
25
|
-
results.push(await deliverActiveTurn(store, delivery, task, role, turn, now));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return results;
|
|
29
|
-
}
|
|
30
|
-
async function deliverActiveTurn(store, delivery, task, role, turn, now) {
|
|
31
|
-
const base = { taskId: task.id, roleName: role.name, turnId: turn.id };
|
|
32
|
-
if (!isSchedulerTaskWorkspaceReady(task, store.getTaskWorkspace(task.id))) {
|
|
33
|
-
return { ...base, status: "skipped", reason: "workspace-not-ready" };
|
|
34
|
-
}
|
|
35
|
-
const dispatchToken = captureRoleTurnDispatch(store.getWorkMailbox({
|
|
36
|
-
kind: "role",
|
|
37
|
-
taskId: task.id,
|
|
38
|
-
roleName: role.name
|
|
39
|
-
}), {
|
|
40
|
-
taskId: task.id,
|
|
41
|
-
roleName: role.name,
|
|
42
|
-
turnId: turn.id
|
|
43
|
-
});
|
|
44
|
-
const sessionSet = store.getTaskRoleSessionSet?.(task.id, role.name) ?? null;
|
|
45
|
-
const binding = sessionSet?.providerBinding ?? null;
|
|
46
|
-
const observedTurn = binding?.turn ?? null;
|
|
47
|
-
const initialAttemptId = formatTurnReceiptId(task.id, turn.id);
|
|
48
|
-
const currentProviderTurn = managedProviderTurnId(observedTurn) === turn.id ? observedTurn : null;
|
|
49
|
-
if (binding?.authority.owner === "human"
|
|
50
|
-
|| binding?.authority.owner === "unknown") {
|
|
51
|
-
return { ...base, status: "skipped", reason: "writer-attached" };
|
|
52
|
-
}
|
|
53
|
-
if (currentProviderTurn?.status === "accepted") {
|
|
54
|
-
settleAcceptedRoleTurnDispatch(store, turn, dispatchToken);
|
|
55
|
-
return { ...base, status: "skipped", reason: "not-ready" };
|
|
56
|
-
}
|
|
57
|
-
if (currentProviderTurn?.status === "submitting") {
|
|
58
|
-
return { ...base, status: "skipped", reason: "not-ready" };
|
|
59
|
-
}
|
|
60
|
-
if (currentProviderTurn?.status === "delivery-unknown") {
|
|
61
|
-
return failTurnDelivery(store, turn, now, "delivery-unknown", currentProviderTurn.terminalReason ?? "Provider could not determine whether the Turn was accepted.");
|
|
62
|
-
}
|
|
63
|
-
if (currentProviderTurn !== null) {
|
|
64
|
-
const reason = currentProviderTurn.terminalReason
|
|
65
|
-
?? `Provider Turn ended with status ${currentProviderTurn.status} without recording its Turn result.`;
|
|
66
|
-
// A terminal Provider projection without an application result is a
|
|
67
|
-
// framework consistency failure, not evidence that the Agent omitted its
|
|
68
|
-
// report. Keep the exact input fenced; never submit it again.
|
|
69
|
-
return { ...base, status: "skipped", reason: "delivery-uncertain", error: reason };
|
|
70
|
-
}
|
|
71
|
-
const attemptId = initialAttemptId;
|
|
72
|
-
const mode = turn.mode;
|
|
73
|
-
const existingSession = store.getRoleSession(task.id, role.name, turn.effective.agentId);
|
|
74
|
-
let prepared;
|
|
75
|
-
let submitted = false;
|
|
76
|
-
try {
|
|
77
|
-
const nativeSessionId = mode === "resume"
|
|
78
|
-
? requireResumeSession(role, turn, existingSession)
|
|
79
|
-
: undefined;
|
|
80
|
-
prepared = await delivery.prepareRoleSession({
|
|
81
|
-
taskId: task.id,
|
|
82
|
-
roleName: role.name,
|
|
83
|
-
agentId: turn.effective.agentId,
|
|
84
|
-
adapterId: turn.effective.adapterId,
|
|
85
|
-
effective: turn.effective,
|
|
86
|
-
workspace: turn.effective.workspace.root,
|
|
87
|
-
...(turn.workspace === undefined ? {} : { managedWorkspace: turn.workspace }),
|
|
88
|
-
mode,
|
|
89
|
-
turnId: turn.id,
|
|
90
|
-
...(nativeSessionId === undefined ? {} : { nativeSessionId }),
|
|
91
|
-
...(mode !== "resume" || existingSession?.runtimeGenerationId === undefined
|
|
92
|
-
? {}
|
|
93
|
-
: { hostActivationId: existingSession.runtimeGenerationId }),
|
|
94
|
-
beforeHostStart: (preflight) => persistPreStartSession(store, task, role, turn, existingSession, mode, preflight, now)
|
|
95
|
-
});
|
|
96
|
-
const preparedSession = prepared.session === undefined
|
|
97
|
-
? existingSession
|
|
98
|
-
: validateRoleSession(role, turn, existingSession, mode, prepared.session);
|
|
99
|
-
store.saveRoleTurnPrepared({
|
|
100
|
-
task,
|
|
101
|
-
role,
|
|
102
|
-
turn,
|
|
103
|
-
session: preparedSession,
|
|
104
|
-
...(prepared.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: prepared.runtimeGenerationId }),
|
|
105
|
-
now
|
|
106
|
-
});
|
|
107
|
-
const ready = await delivery.waitUntilReady(prepared);
|
|
108
|
-
const readySession = validateRoleSession(role, turn, existingSession, mode, ready.session);
|
|
109
|
-
store.saveRoleTurnPrepared({
|
|
110
|
-
task,
|
|
111
|
-
role,
|
|
112
|
-
turn,
|
|
113
|
-
session: readySession,
|
|
114
|
-
...(ready.prepared.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: ready.prepared.runtimeGenerationId }),
|
|
115
|
-
now
|
|
116
|
-
});
|
|
117
|
-
submitted = true;
|
|
118
|
-
const outcome = await delivery.sendOnce({
|
|
119
|
-
delivery: ready,
|
|
120
|
-
receiptId: attemptId,
|
|
121
|
-
text: serializeTurnInputEnvelope(turnInputEnvelope(turn))
|
|
122
|
-
});
|
|
123
|
-
if (outcome.status === "busy" || outcome.status === "unavailable") {
|
|
124
|
-
forget(delivery, task.id, role.name, turn.id, ready.prepared.runtimeGenerationId);
|
|
125
|
-
return {
|
|
126
|
-
...base,
|
|
127
|
-
status: "skipped",
|
|
128
|
-
reason: outcome.status === "busy" ? "not-ready" : "runtime-unavailable"
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
if (outcome.status === "rejected" || outcome.status === "delivery-unknown") {
|
|
132
|
-
forget(delivery, task.id, role.name, turn.id, ready.prepared.runtimeGenerationId);
|
|
133
|
-
const unknown = outcome.status === "delivery-unknown";
|
|
134
|
-
const failure = outcome.failure;
|
|
135
|
-
// The Host's own account of the failure. Without it the only honest
|
|
136
|
-
// statement is that delivery did not complete — never that the Provider
|
|
137
|
-
// rejected the input, which is one specific cause among many.
|
|
138
|
-
const cause = failure === undefined
|
|
139
|
-
? `The Agent Host did not deliver the managed Turn (${outcome.status}) and reported no cause.`
|
|
140
|
-
: formatProviderDeliveryFailure(failure);
|
|
141
|
-
// This path is the common Provider write failure and previously left no
|
|
142
|
-
// durable fact at all, so the cause was unrecoverable after the fact.
|
|
143
|
-
store.recordAgentError?.({
|
|
144
|
-
taskId: task.id,
|
|
145
|
-
roleName: role.name,
|
|
146
|
-
turnId: turn.id,
|
|
147
|
-
source: "host",
|
|
148
|
-
phase: failure?.phase ?? "turn-submit",
|
|
149
|
-
message: cause,
|
|
150
|
-
// The Host already serialized the complete redacted chain. Re-serializing
|
|
151
|
-
// the failure object here would persist this layer's wrapper instead of
|
|
152
|
-
// the original cause, which is the detail an authorized reader needs.
|
|
153
|
-
raw: failure?.raw ?? serializeAgentErrorRaw(failure ?? cause),
|
|
154
|
-
inputDisposition: failure?.inputDisposition ?? (unknown ? "unknown" : "not-accepted"),
|
|
155
|
-
...providerDeliveryFailureFacts(failure)
|
|
156
|
-
}, now);
|
|
157
|
-
return failTurnDelivery(store, turn, now, unknown ? "delivery-unknown" : "runtime-failed", unknown
|
|
158
|
-
? `Provider Turn delivery is ambiguous; Yui will not replay it automatically. ${cause}`
|
|
159
|
-
: cause);
|
|
160
|
-
}
|
|
161
|
-
forget(delivery, task.id, role.name, turn.id, ready.prepared.runtimeGenerationId);
|
|
162
|
-
settleAcceptedRoleTurnDispatch(store, turn, dispatchToken);
|
|
163
|
-
return {
|
|
164
|
-
...base,
|
|
165
|
-
status: outcome.status === "sent" ? "delivered" : "already-delivered"
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
170
|
-
// A launch failure carries its own structure — the class that threw, the
|
|
171
|
-
// innermost cause, and for a generation mismatch both generations. Recording
|
|
172
|
-
// only `message` flattened all of it into prose that no reader could
|
|
173
|
-
// reliably parse back.
|
|
174
|
-
const causeName = innermostCauseName(error);
|
|
175
|
-
const mismatch = error instanceof RuntimeGenerationMismatchError ? error : undefined;
|
|
176
|
-
store.recordAgentError?.({
|
|
177
|
-
taskId: task.id,
|
|
178
|
-
roleName: role.name,
|
|
179
|
-
turnId: turn.id,
|
|
180
|
-
source: error instanceof RuntimeLaunchError || error instanceof RuntimeLaunchFailure ? "host" : "yui",
|
|
181
|
-
phase: submitted ? "turn-submit" : mode === "new" ? "session-start" : "session-restore",
|
|
182
|
-
message,
|
|
183
|
-
raw: serializeAgentErrorRaw(error),
|
|
184
|
-
inputDisposition: submitted ? "unknown" : "not-accepted",
|
|
185
|
-
// Nothing was submitted, so the Provider provably holds no registration
|
|
186
|
-
// for this attempt; after a submit the Host owns that fact, not this layer.
|
|
187
|
-
...(submitted ? {} : { registrationDisposition: "not-committed" }),
|
|
188
|
-
...(error instanceof Error ? { errorName: error.name } : {}),
|
|
189
|
-
...(causeName === undefined ? {} : { causeName }),
|
|
190
|
-
...(mismatch === undefined ? {} : {
|
|
191
|
-
expectedRuntimeGenerationId: mismatch.expectedRuntimeGenerationId,
|
|
192
|
-
...(mismatch.observedRuntimeGenerationId === undefined
|
|
193
|
-
? {}
|
|
194
|
-
: { observedRuntimeGenerationId: mismatch.observedRuntimeGenerationId })
|
|
195
|
-
}),
|
|
196
|
-
...(error instanceof RuntimeLaunchError
|
|
197
|
-
? { expectedRuntimeGenerationId: error.runtimeGenerationId }
|
|
198
|
-
: {}),
|
|
199
|
-
attemptId
|
|
200
|
-
}, now);
|
|
201
|
-
if (error instanceof RuntimeLifecycleBusyError
|
|
202
|
-
|| (error instanceof RuntimeLaunchError && error.retryable)) {
|
|
203
|
-
return {
|
|
204
|
-
...base,
|
|
205
|
-
status: "skipped",
|
|
206
|
-
reason: error instanceof RuntimeLaunchError && error.reason === "writable-client"
|
|
207
|
-
? "writer-attached"
|
|
208
|
-
: "runtime-unavailable",
|
|
209
|
-
error: message
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
forget(delivery, task.id, role.name, turn.id, prepared?.runtimeGenerationId);
|
|
213
|
-
return failTurnDelivery(store, turn, now, submitted ? "delivery-unknown" : "startup-failed", message);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
function failTurnDelivery(store, turn, now, failureReason, summary) {
|
|
217
|
-
const disposition = store.saveRoleTurnDeliveryFailure({
|
|
218
|
-
taskId: turn.taskId,
|
|
219
|
-
roleName: turn.roleName,
|
|
220
|
-
agentId: turn.effective.agentId,
|
|
221
|
-
adapterId: turn.effective.adapterId,
|
|
222
|
-
turnId: turn.id,
|
|
223
|
-
failureReason,
|
|
224
|
-
summary,
|
|
225
|
-
now
|
|
226
|
-
});
|
|
227
|
-
return {
|
|
228
|
-
taskId: turn.taskId,
|
|
229
|
-
roleName: turn.roleName,
|
|
230
|
-
turnId: turn.id,
|
|
231
|
-
status: disposition === "failed" ? "failed" : "skipped",
|
|
232
|
-
reason: failureReason === "delivery-unknown" ? "delivery-uncertain" : "launch-failed",
|
|
233
|
-
error: summary,
|
|
234
|
-
...(disposition === "failed" ? { terminalized: true } : {})
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function settleAcceptedRoleTurnDispatch(store, turn, expected) {
|
|
238
|
-
store.settleRoleTurnDispatch({
|
|
239
|
-
taskId: turn.taskId,
|
|
240
|
-
roleName: turn.roleName,
|
|
241
|
-
turnId: turn.id,
|
|
242
|
-
...(expected === undefined ? {} : { expected })
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
function persistPreStartSession(store, task, role, turn, existing, mode, preflight, now) {
|
|
246
|
-
if (preflight.owner.scope !== "task"
|
|
247
|
-
|| preflight.owner.taskId !== task.id
|
|
248
|
-
|| preflight.owner.roleName !== role.name
|
|
249
|
-
|| preflight.turnId !== turn.id
|
|
250
|
-
|| preflight.runtimeGenerationId.trim().length === 0) {
|
|
251
|
-
throw new Error(`Pre-start launch fence changed the active Role Turn: ${task.id}/${role.name}.`);
|
|
252
|
-
}
|
|
253
|
-
const session = preflight.nativeSessionId === undefined ? null : {
|
|
254
|
-
agentId: preflight.agentId,
|
|
255
|
-
adapterId: preflight.adapterId,
|
|
256
|
-
nativeSessionId: preflight.nativeSessionId,
|
|
257
|
-
runtimeGenerationId: preflight.runtimeGenerationId,
|
|
258
|
-
...(preflight.sessionTitle === undefined ? {} : { title: preflight.sessionTitle }),
|
|
259
|
-
status: "active",
|
|
260
|
-
effective: preflight.effective
|
|
261
|
-
};
|
|
262
|
-
store.saveRoleTurnPrepared({
|
|
263
|
-
task,
|
|
264
|
-
role,
|
|
265
|
-
turn,
|
|
266
|
-
session: validateRoleSession(role, turn, existing, mode, session),
|
|
267
|
-
runtimeGenerationId: preflight.runtimeGenerationId,
|
|
268
|
-
now
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
function validateRoleSession(role, turn, existing, mode, session) {
|
|
272
|
-
if (mode === "new" && session === null)
|
|
273
|
-
return null;
|
|
274
|
-
if (session === null || !hasText(session.nativeSessionId)) {
|
|
275
|
-
throw new Error(`Ready Role session has no native session id: ${role.taskId}/${role.name}.`);
|
|
276
|
-
}
|
|
277
|
-
if (session.agentId !== turn.effective.agentId
|
|
278
|
-
|| session.adapterId !== turn.effective.adapterId) {
|
|
279
|
-
throw new Error(`Ready Role session identity changed: ${role.taskId}/${role.name}.`);
|
|
280
|
-
}
|
|
281
|
-
const compatible = mode === "resume"
|
|
282
|
-
? roleSessionMayContinue(session.effective, turn.effective)
|
|
283
|
-
: sameEffectiveLaunch(session.effective, turn.effective);
|
|
284
|
-
if (!compatible) {
|
|
285
|
-
throw new Error(`Ready Role session effective snapshot changed: ${role.taskId}/${role.name}.`);
|
|
286
|
-
}
|
|
287
|
-
if (mode === "resume" && session.nativeSessionId !== existing?.nativeSessionId) {
|
|
288
|
-
throw new Error(`Role resume changed the fixed native session id: ${role.taskId}/${role.name}.`);
|
|
289
|
-
}
|
|
290
|
-
return {
|
|
291
|
-
...session,
|
|
292
|
-
status: "active",
|
|
293
|
-
...(mode === "resume" && existing !== null ? { effective: existing.effective } : {})
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
function requireResumeSession(role, turn, session) {
|
|
297
|
-
if (session === null || !hasText(session.nativeSessionId)) {
|
|
298
|
-
throw new Error(`Role resume has no fixed native session: ${role.taskId}/${role.name}.`);
|
|
299
|
-
}
|
|
300
|
-
if (!roleSessionMayContinue(session.effective, turn.effective)) {
|
|
301
|
-
throw new Error(`Role resume effective snapshot drifted: ${role.taskId}/${role.name}.`);
|
|
302
|
-
}
|
|
303
|
-
return session.nativeSessionId;
|
|
304
|
-
}
|
|
305
|
-
function forget(delivery, taskId, roleName, turnId, runtimeGenerationId) {
|
|
306
|
-
delivery.forgetPrepared?.({
|
|
307
|
-
taskId,
|
|
308
|
-
roleName,
|
|
309
|
-
turnId,
|
|
310
|
-
...(runtimeGenerationId === undefined ? {} : { runtimeGenerationId })
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
function hasText(value) {
|
|
314
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
315
|
-
}
|