@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,17 +1,15 @@
|
|
|
1
1
|
import { openCurrentTaskStore } from "../storage/currentTaskStore.js";
|
|
2
|
-
import { hasRuntimeCleanupObligation,
|
|
3
|
-
import { nativeSessionIdForLaunch } from "../runtime/preallocatedNativeSession.js";
|
|
2
|
+
import { hasRuntimeCleanupObligation, runtimeLifecycleTarget } from "../runtime/lifecycleReservation.js";
|
|
4
3
|
import { runtimeObservationFromTaskEvent } from "../runtime/runtimeObservation.js";
|
|
5
|
-
import {
|
|
6
|
-
import { managedProviderTurnId } from "../runtime/providerRuntimeIdentity.js";
|
|
4
|
+
import { formatRunReceiptId } from "../task/taskRecordReference.js";
|
|
5
|
+
import { currentProviderConversation, managedProviderTurnId } from "../runtime/providerRuntimeIdentity.js";
|
|
6
|
+
import { taskRoleRuntimeIdentity } from "../runtime/managedCaller.js";
|
|
7
|
+
import { runPurposeAdmitsTaskState } from "../agentRun/agentRun.js";
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Session projection and is fenced by the exact Turn-bound launch reservation.
|
|
11
|
-
* Preallocated identities are additionally checked against Yui's deterministic
|
|
12
|
-
* runtime generation identity. The immutable event is revalidated by the inbox fold.
|
|
9
|
+
* Resolve observations by Session and exact input identity. A startup Hook
|
|
10
|
+
* may introduce a Session for an explicit new-Session AgentRun.
|
|
13
11
|
*/
|
|
14
|
-
export function
|
|
12
|
+
export function resolveRuntimeHookRunFence(environment, adapterId, payloadNativeSessionId, options = {}) {
|
|
15
13
|
if (environment.YUI_SESSION_SCOPE !== "task") {
|
|
16
14
|
throw new Error("Runtime observation Hook requires a Task session scope.");
|
|
17
15
|
}
|
|
@@ -35,76 +33,68 @@ export function resolveRuntimeHookTurnFence(environment, adapterId, payloadNativ
|
|
|
35
33
|
const executionSession = session?.nativeSessionId === nativeSessionId
|
|
36
34
|
? session
|
|
37
35
|
: sessions?.history?.find((entry) => (entry.agentId === agentId && entry.nativeSessionId === nativeSessionId));
|
|
38
|
-
const
|
|
39
|
-
const providerTurn = sessions?.providerBinding?.
|
|
40
|
-
// An input belongs to the Activation recorded at registration, even after
|
|
41
|
-
// detach or a successor Host launch. "Current activation" is not its owner.
|
|
42
|
-
const activation = providerTurn?.activationId === undefined
|
|
43
|
-
? undefined
|
|
44
|
-
: sessions?.providerBinding?.activations.find((entry) => entry.activationId === providerTurn.activationId);
|
|
36
|
+
const activeRun = store.getActiveRun(taskId, roleName);
|
|
37
|
+
const providerTurn = sessions?.providerBinding?.run;
|
|
45
38
|
const matchesProviderTurn = providerTurn !== null
|
|
46
39
|
&& providerTurn !== undefined
|
|
40
|
+
&& providerTurn.status !== "rejected" && providerTurn.status !== "deferred"
|
|
47
41
|
&& executionSession?.adapterId === adapterId
|
|
48
42
|
&& executionSession.effective.workspace.root === workspace
|
|
49
|
-
&&
|
|
43
|
+
&& sessions?.providerBinding != null
|
|
44
|
+
&& currentProviderConversation(sessions.providerBinding).conversationId === nativeSessionId
|
|
50
45
|
&& ((options.attemptId !== undefined && providerTurn.attemptId === options.attemptId)
|
|
51
46
|
|| (options.nativeTurnId !== undefined && providerTurn.nativeTurnId === options.nativeTurnId))
|
|
52
47
|
&& (options.attemptId === undefined || providerTurn.attemptId === options.attemptId)
|
|
53
48
|
&& (options.nativeTurnId === undefined || providerTurn.nativeTurnId === undefined
|
|
54
49
|
|| providerTurn.nativeTurnId === options.nativeTurnId);
|
|
55
|
-
const
|
|
50
|
+
const acceptedRun = acceptedRunBinding(store.listEvents(taskId), {
|
|
56
51
|
taskId, roleName, agentId, nativeSessionId,
|
|
57
52
|
...(options.nativeTurnId === undefined ? {} : { nativeTurnId: options.nativeTurnId }),
|
|
58
53
|
...(options.attemptId === undefined ? {} : { attemptId: options.attemptId })
|
|
59
54
|
});
|
|
60
|
-
const acceptedBinding =
|
|
55
|
+
const acceptedBinding = acceptedRun ?? (options.continuationId === undefined ? null : knownContinuationBinding(store.listEvents(taskId), {
|
|
61
56
|
taskId, roleName, agentId, nativeSessionId,
|
|
62
57
|
continuationId: options.continuationId,
|
|
63
|
-
continuationGeneration: options.continuationGeneration ?? 1
|
|
64
58
|
}));
|
|
65
59
|
// Collection of an exactly accepted terminal fact is not a new action by
|
|
66
60
|
// the Role. A successor's active Agent or revoked execution permission
|
|
67
|
-
// cannot erase the original
|
|
61
|
+
// cannot erase the original AgentRun's evidence.
|
|
68
62
|
const existingExecutionObservation = (options.terminal === true || options.attemptId !== undefined)
|
|
69
63
|
&& (acceptedBinding !== null || matchesProviderTurn);
|
|
64
|
+
// A Draft's planning Turn runs before activation by design, so it never has an
|
|
65
|
+
// active execution lifecycle to admit it here. Admission is delegated to the
|
|
66
|
+
// one shared invariant that already pairs a Turn purpose with a Task state, so
|
|
67
|
+
// a Draft still cannot produce execution observations while the planning
|
|
68
|
+
// conversation can report its own runtime.
|
|
69
|
+
const planningObservation = activeRun !== null
|
|
70
|
+
&& activeRun.purpose === "planning"
|
|
71
|
+
&& activeRun.roleName === roleName
|
|
72
|
+
&& runPurposeAdmitsTaskState(activeRun.purpose, task);
|
|
70
73
|
if (!(task.status === "active" && task.executionGate.state === "enabled")
|
|
71
74
|
&& !(task.status === "completed" && options.sessionOnly === true)
|
|
75
|
+
&& !planningObservation
|
|
72
76
|
&& !existingExecutionObservation) {
|
|
73
77
|
throw new Error("Runtime observation Hook Task does not accept this lifecycle boundary.");
|
|
74
78
|
}
|
|
75
|
-
|
|
79
|
+
const runtimeIdentity = role === null ? null : taskRoleRuntimeIdentity(role, activeRun);
|
|
80
|
+
if (!existingExecutionObservation && (runtimeIdentity === null || runtimeIdentity.agentId !== agentId
|
|
81
|
+
|| runtimeIdentity.adapterId !== adapterId
|
|
76
82
|
|| (sessions !== null && sessions.activeAgentId !== agentId))) {
|
|
77
83
|
throw new Error("Runtime observation Hook Role or Agent is not current.");
|
|
78
84
|
}
|
|
79
|
-
// Launch generation and Turn are durable facts, never envelope facts. A
|
|
80
|
-
// native pane outlives both, so anything it inherited at launch is stale for
|
|
81
|
-
// every later generation; the Session's own record (or the in-flight launch
|
|
82
|
-
// reservation during startup) is the only current answer.
|
|
83
85
|
const lifecycleMailbox = store.getWorkMailbox(runtimeLifecycleTarget({
|
|
84
86
|
scope: "task",
|
|
85
87
|
taskId,
|
|
86
88
|
roleName
|
|
87
89
|
}));
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// launch. Existing/late execution events instead retain their old binding.
|
|
93
|
-
const reservedStartup = options.startupSession !== undefined
|
|
94
|
-
&& activeTurn !== null
|
|
95
|
-
&& reservedRuntimeGenerationId !== undefined
|
|
96
|
-
&& environment.YUI_RUNTIME_GENERATION_ID === reservedRuntimeGenerationId
|
|
97
|
-
&& !hasRuntimeCleanupObligation(lifecycleMailbox);
|
|
98
|
-
const runtimeGenerationId = requireIdentity(acceptedBinding?.fence.runtimeGenerationId
|
|
99
|
-
?? (matchesProviderTurn ? activation.activationId : undefined)
|
|
100
|
-
?? (reservedStartup ? reservedRuntimeGenerationId : session?.runtimeGenerationId), "Runtime generation id");
|
|
101
|
-
const directProviderTurn = matchesProviderTurn && providerTurn.turnId === undefined;
|
|
102
|
-
const sessionOnlyObservation = options.sessionOnly === true && activeTurn === null;
|
|
90
|
+
const directProviderTurn = matchesProviderTurn && providerTurn.runId === undefined;
|
|
91
|
+
const sessionOnlyObservation = options.sessionOnly === true
|
|
92
|
+
|| (options.startupSession === undefined && options.terminal !== true
|
|
93
|
+
&& acceptedBinding === null && !matchesProviderTurn);
|
|
103
94
|
if (acceptedBinding === null && (directProviderTurn || sessionOnlyObservation)) {
|
|
104
95
|
const observedSession = directProviderTurn ? executionSession : session;
|
|
105
96
|
if (observedSession === undefined
|
|
106
97
|
|| observedSession.adapterId !== adapterId
|
|
107
|
-
|| (!directProviderTurn && observedSession.runtimeGenerationId !== runtimeGenerationId)
|
|
108
98
|
|| observedSession.nativeSessionId !== nativeSessionId
|
|
109
99
|
|| observedSession.effective.workspace.root !== workspace) {
|
|
110
100
|
throw new Error("Runtime observation Hook Session does not match durable state.");
|
|
@@ -113,119 +103,108 @@ export function resolveRuntimeHookTurnFence(environment, adapterId, payloadNativ
|
|
|
113
103
|
taskId,
|
|
114
104
|
roleName,
|
|
115
105
|
agentId,
|
|
116
|
-
runtimeGenerationId,
|
|
117
106
|
...(directProviderTurn ? { receiptId: providerTurn.attemptId } : {}),
|
|
118
107
|
nativeSessionId,
|
|
119
108
|
workspace
|
|
120
109
|
};
|
|
121
110
|
}
|
|
122
|
-
const
|
|
111
|
+
const inputReceiptId = matchesProviderTurn
|
|
123
112
|
? providerTurn.attemptId
|
|
124
113
|
: providerTurn !== null
|
|
125
114
|
&& providerTurn !== undefined
|
|
126
|
-
&& managedProviderTurnId(providerTurn) ===
|
|
115
|
+
&& managedProviderTurnId(providerTurn) === activeRun?.id
|
|
127
116
|
? providerTurn.attemptId
|
|
128
|
-
:
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
&& !hasRuntimeCleanupObligation(
|
|
132
|
-
const
|
|
133
|
-
const startupReservation = startupTurnId !== undefined
|
|
134
|
-
&& reservedStartup
|
|
135
|
-
&& exactReservation
|
|
136
|
-
&& !hasRuntimeCleanupObligation(mailbox);
|
|
137
|
-
const startupTurn = startupTurnId === undefined
|
|
117
|
+
: activeRun === null ? undefined : formatRunReceiptId(taskId, activeRun.id);
|
|
118
|
+
const startupRunId = options.startupSession === undefined ? undefined : activeRun?.id;
|
|
119
|
+
const startupIntent = startupRunId !== undefined
|
|
120
|
+
&& !hasRuntimeCleanupObligation(lifecycleMailbox);
|
|
121
|
+
const startupRun = startupRunId === undefined
|
|
138
122
|
? null
|
|
139
|
-
: store.
|
|
123
|
+
: store.getRun(taskId, startupRunId);
|
|
140
124
|
const replacementStartup = options.startupSession !== undefined
|
|
141
125
|
&& session !== undefined
|
|
142
126
|
&& sessions !== null
|
|
143
|
-
&&
|
|
144
|
-
&&
|
|
127
|
+
&& startupIntent
|
|
128
|
+
&& startupRun?.mode === "new"
|
|
145
129
|
&& session.status === "ended";
|
|
146
|
-
const resumedStartup =
|
|
147
|
-
&&
|
|
130
|
+
const resumedStartup = startupIntent
|
|
131
|
+
&& startupRun?.mode === "resume"
|
|
148
132
|
&& session !== undefined
|
|
149
133
|
&& session.adapterId === adapterId
|
|
150
134
|
&& session.nativeSessionId === nativeSessionId
|
|
151
135
|
&& session.effective.workspace.root === workspace;
|
|
152
|
-
//
|
|
153
|
-
// id or the Provider reports it. A preallocated startup is proven against
|
|
154
|
-
// Yui's deterministic runtime generation identity, which is stronger than comparing a
|
|
155
|
-
// value the launch envelope carried.
|
|
136
|
+
// New Session identity is provided by the native adapter, not a launch token.
|
|
156
137
|
const preallocatedStartup = options.startupSession === "preallocated"
|
|
157
138
|
&& (session === undefined || replacementStartup)
|
|
158
|
-
&&
|
|
159
|
-
&&
|
|
139
|
+
&& startupIntent
|
|
140
|
+
&& startupRun?.mode === "new";
|
|
160
141
|
const discoveredStartup = options.startupSession === "discovered"
|
|
161
142
|
&& (session === undefined || replacementStartup)
|
|
162
|
-
&&
|
|
163
|
-
|
|
143
|
+
&& startupIntent
|
|
144
|
+
&& startupRun?.mode === "new";
|
|
145
|
+
const registeredRunId = acceptedBinding === null && matchesProviderTurn
|
|
164
146
|
? managedProviderTurnId(providerTurn) ?? undefined
|
|
165
147
|
: undefined;
|
|
166
|
-
if (options.terminal === true && acceptedBinding === null &&
|
|
148
|
+
if (options.terminal === true && acceptedBinding === null && registeredRunId === undefined) {
|
|
167
149
|
throw new Error("Runtime observation Hook terminal has no exact accepted execution binding.");
|
|
168
150
|
}
|
|
169
|
-
const
|
|
170
|
-
? store.
|
|
171
|
-
:
|
|
151
|
+
const terminalRun = acceptedBinding !== null
|
|
152
|
+
? store.getRun(taskId, acceptedBinding.fence.runId)
|
|
153
|
+
: registeredRunId === undefined
|
|
172
154
|
? null
|
|
173
|
-
: store.
|
|
174
|
-
const exactTerminal =
|
|
175
|
-
&&
|
|
176
|
-
&&
|
|
177
|
-
&&
|
|
178
|
-
&&
|
|
155
|
+
: store.getRun(taskId, registeredRunId);
|
|
156
|
+
const exactTerminal = terminalRun !== null
|
|
157
|
+
&& terminalRun.status !== "active"
|
|
158
|
+
&& terminalRun.roleName === roleName
|
|
159
|
+
&& terminalRun.effective.agentId === agentId
|
|
160
|
+
&& terminalRun.effective.adapterId === adapterId
|
|
179
161
|
&& session !== undefined;
|
|
180
|
-
if (
|
|
162
|
+
if (activeRun === null
|
|
181
163
|
&& !preallocatedStartup
|
|
182
164
|
&& !discoveredStartup
|
|
183
165
|
&& !resumedStartup
|
|
184
166
|
&& !exactTerminal
|
|
185
|
-
&&
|
|
167
|
+
&& registeredRunId === undefined
|
|
186
168
|
&& acceptedBinding === null) {
|
|
187
|
-
throw new Error("Runtime observation Hook has no matching durable in-flight
|
|
169
|
+
throw new Error("Runtime observation Hook has no matching durable in-flight AgentRun.");
|
|
188
170
|
}
|
|
189
|
-
const
|
|
190
|
-
??
|
|
191
|
-
??
|
|
192
|
-
??
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
||
|
|
199
|
-
||
|
|
200
|
-
||
|
|
201
|
-
||
|
|
202
|
-
|
|
203
|
-
throw new Error("Runtime observation Hook Turn does not match durable active state.");
|
|
171
|
+
const runId = acceptedBinding?.fence.runId
|
|
172
|
+
?? registeredRunId
|
|
173
|
+
?? activeRun?.id
|
|
174
|
+
?? startupRunId;
|
|
175
|
+
const run = acceptedBinding !== null || registeredRunId !== undefined
|
|
176
|
+
? terminalRun
|
|
177
|
+
: store.getActiveRun(taskId, roleName);
|
|
178
|
+
if (run === null
|
|
179
|
+
|| run.id !== runId
|
|
180
|
+
|| (acceptedBinding === null && registeredRunId === undefined && !exactTerminal && run.status !== "active")
|
|
181
|
+
|| run.roleName !== roleName
|
|
182
|
+
|| run.effective.agentId !== agentId
|
|
183
|
+
|| run.effective.adapterId !== adapterId) {
|
|
184
|
+
throw new Error("Runtime observation Hook AgentRun does not match durable active state.");
|
|
204
185
|
}
|
|
205
|
-
if (
|
|
206
|
-
throw new Error("Runtime observation Hook workspace does not match the durable
|
|
186
|
+
if (run.effective.workspace.root !== workspace) {
|
|
187
|
+
throw new Error("Runtime observation Hook workspace does not match the durable AgentRun snapshot.");
|
|
207
188
|
}
|
|
208
189
|
if (session !== undefined && acceptedBinding === null && !matchesProviderTurn && !replacementStartup && !resumedStartup) {
|
|
209
190
|
if (session.adapterId !== adapterId
|
|
210
|
-
|| session.runtimeGenerationId !== effectiveRuntimeGenerationId
|
|
211
191
|
|| session.nativeSessionId !== nativeSessionId
|
|
212
192
|
|| session.effective.workspace.root !== workspace) {
|
|
213
|
-
throw new Error("Runtime observation Hook Session does not match
|
|
193
|
+
throw new Error("Runtime observation Hook Session does not match durable state.");
|
|
214
194
|
}
|
|
215
195
|
}
|
|
216
196
|
else if (acceptedBinding === null && !matchesProviderTurn && (session === undefined || replacementStartup)) {
|
|
217
197
|
if (!discoveredStartup && !preallocatedStartup) {
|
|
218
|
-
throw new Error("Runtime observation Hook
|
|
198
|
+
throw new Error("Runtime observation Hook has no matching new-Session intent.");
|
|
219
199
|
}
|
|
220
200
|
}
|
|
221
201
|
return {
|
|
222
202
|
taskId,
|
|
223
203
|
roleName,
|
|
224
204
|
agentId,
|
|
225
|
-
|
|
226
|
-
turnId,
|
|
205
|
+
runId,
|
|
227
206
|
...(acceptedBinding?.fence.receiptId === undefined
|
|
228
|
-
?
|
|
207
|
+
? inputReceiptId === undefined ? {} : { receiptId: inputReceiptId }
|
|
229
208
|
: { receiptId: acceptedBinding.fence.receiptId }),
|
|
230
209
|
nativeSessionId,
|
|
231
210
|
workspace
|
|
@@ -241,8 +220,7 @@ function knownContinuationBinding(events, expected) {
|
|
|
241
220
|
&& observation.fence.agentId === expected.agentId
|
|
242
221
|
&& observation.fence.nativeSessionId === expected.nativeSessionId
|
|
243
222
|
&& observation.fence.continuationId === expected.continuationId
|
|
244
|
-
&& observation.fence.
|
|
245
|
-
&& observation.fence.turnId !== undefined)
|
|
223
|
+
&& observation.fence.runId !== undefined)
|
|
246
224
|
.sort((left, right) => (left.receivedAt.localeCompare(right.receivedAt)
|
|
247
225
|
|| (left.sequence ?? -1) - (right.sequence ?? -1)
|
|
248
226
|
|| (left.ordinal ?? -1) - (right.ordinal ?? -1)
|
|
@@ -250,14 +228,13 @@ function knownContinuationBinding(events, expected) {
|
|
|
250
228
|
const binding = matches.at(-1) ?? null;
|
|
251
229
|
if (binding === null)
|
|
252
230
|
return null;
|
|
253
|
-
if (matches.some((candidate) => candidate.fence.
|
|
254
|
-
|| candidate.fence.runtimeGenerationId !== binding.fence.runtimeGenerationId
|
|
231
|
+
if (matches.some((candidate) => candidate.fence.runId !== binding.fence.runId
|
|
255
232
|
|| candidate.fence.receiptId !== binding.fence.receiptId)) {
|
|
256
|
-
throw new Error("Runtime observation Hook continuation has conflicting durable
|
|
233
|
+
throw new Error("Runtime observation Hook continuation has conflicting durable AgentRun bindings.");
|
|
257
234
|
}
|
|
258
235
|
return binding;
|
|
259
236
|
}
|
|
260
|
-
function
|
|
237
|
+
function acceptedRunBinding(events, expected) {
|
|
261
238
|
if (expected.nativeTurnId === undefined && expected.attemptId === undefined)
|
|
262
239
|
return null;
|
|
263
240
|
const matches = events
|
|
@@ -270,7 +247,7 @@ function acceptedTurnBinding(events, expected) {
|
|
|
270
247
|
&& observation.fence.nativeSessionId === expected.nativeSessionId
|
|
271
248
|
&& ((expected.attemptId !== undefined && observation.fence.receiptId === expected.attemptId)
|
|
272
249
|
|| (expected.nativeTurnId !== undefined && observation.fence.nativeTurnId === expected.nativeTurnId))
|
|
273
|
-
&& observation.fence.
|
|
250
|
+
&& observation.fence.runId !== undefined)
|
|
274
251
|
.sort((left, right) => (left.receivedAt.localeCompare(right.receivedAt)
|
|
275
252
|
|| (left.sequence ?? -1) - (right.sequence ?? -1)
|
|
276
253
|
|| (left.ordinal ?? -1) - (right.ordinal ?? -1)
|
|
@@ -281,10 +258,9 @@ function acceptedTurnBinding(events, expected) {
|
|
|
281
258
|
if (matches.some((candidate) => ((expected.attemptId !== undefined && candidate.fence.receiptId !== expected.attemptId)
|
|
282
259
|
|| (expected.nativeTurnId !== undefined && candidate.fence.nativeTurnId !== undefined
|
|
283
260
|
&& candidate.fence.nativeTurnId !== expected.nativeTurnId)
|
|
284
|
-
|| candidate.fence.
|
|
285
|
-
|| candidate.fence.runtimeGenerationId !== binding.fence.runtimeGenerationId
|
|
261
|
+
|| candidate.fence.runId !== binding.fence.runId
|
|
286
262
|
|| candidate.fence.receiptId !== binding.fence.receiptId))) {
|
|
287
|
-
throw new Error("Runtime observation Hook native Turn has conflicting durable
|
|
263
|
+
throw new Error("Runtime observation Hook native Turn has conflicting durable AgentRun bindings.");
|
|
288
264
|
}
|
|
289
265
|
return binding;
|
|
290
266
|
}
|