@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
|
@@ -3,7 +3,7 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
3
3
|
import { closeSync, constants, existsSync, fchmodSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { createRuntimeObservation, isRuntimeTokenEvidence } from "../runtime/runtimeObservation.js";
|
|
6
|
-
import {
|
|
6
|
+
import { boundedRunFailureDiagnostic, transportAgentResult } from "../domain/agentResultTransport.js";
|
|
7
7
|
export const MAX_RUNTIME_EVENT_FILE_BYTES = 16 * 1024 * 1024;
|
|
8
8
|
const RUNTIME_EVENT_DIRECTORY = join("runtime", "inbox");
|
|
9
9
|
const INVALID_RUNTIME_EVENT_DIRECTORY = join("runtime", "inbox-invalid");
|
|
@@ -40,7 +40,7 @@ export class FileRuntimeEventInbox {
|
|
|
40
40
|
});
|
|
41
41
|
return this.publish(event);
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
enqueueRunTerminal(input) {
|
|
44
44
|
const normalized = normalizeNativeTurnTerminalInput(input);
|
|
45
45
|
return this.publish(Object.freeze({
|
|
46
46
|
schemaVersion: 1,
|
|
@@ -111,7 +111,7 @@ export class FileRuntimeEventInbox {
|
|
|
111
111
|
catch {
|
|
112
112
|
throw invalidEvent(`Runtime event JSON is invalid: ${id}`);
|
|
113
113
|
}
|
|
114
|
-
const event = parseRuntimeEvent(value);
|
|
114
|
+
const event = parseRuntimeEvent(decodeInboxV1(value));
|
|
115
115
|
if (event.id !== id || runtimeEventId(event.type, event) !== id) {
|
|
116
116
|
throw invalidEvent(`Runtime event identity is invalid: ${id}`);
|
|
117
117
|
}
|
|
@@ -169,7 +169,7 @@ export class FileRuntimeEventInbox {
|
|
|
169
169
|
return this.publishUnlocked(event);
|
|
170
170
|
}
|
|
171
171
|
publishUnlocked(event) {
|
|
172
|
-
const content = `${JSON.stringify(event)}\n`;
|
|
172
|
+
const content = `${JSON.stringify(encodeInboxV1(event))}\n`;
|
|
173
173
|
if (Buffer.byteLength(content, "utf8") > MAX_RUNTIME_EVENT_FILE_BYTES) {
|
|
174
174
|
throw new RuntimeEventInboxError("RUNTIME_EVENT_TOO_LARGE", "Runtime event exceeds the durable inbox limit.");
|
|
175
175
|
}
|
|
@@ -276,10 +276,9 @@ function runtimeEventId(type, input) {
|
|
|
276
276
|
provider.roleName,
|
|
277
277
|
provider.agentId,
|
|
278
278
|
provider.adapterId,
|
|
279
|
-
provider.runtimeGenerationId ?? null,
|
|
280
279
|
provider.nativeSessionId,
|
|
281
280
|
provider.nativeTurnId,
|
|
282
|
-
provider.
|
|
281
|
+
provider.runId ?? null
|
|
283
282
|
];
|
|
284
283
|
return `turn-${createHash("sha256").update(JSON.stringify(common)).digest("hex")}`;
|
|
285
284
|
}
|
|
@@ -289,7 +288,7 @@ function normalizeNativeTurnTerminalInput(input) {
|
|
|
289
288
|
throw invalidEvent();
|
|
290
289
|
if (!["completed", "failed", "cancelled"].includes(input.providerStatus))
|
|
291
290
|
throw invalidEvent();
|
|
292
|
-
const outcome =
|
|
291
|
+
const outcome = normalizeRuntimeRunTerminalOutcome(input.outcome);
|
|
293
292
|
if (outcome.status === "completed" && input.providerStatus !== "completed") {
|
|
294
293
|
throw invalidEvent("Only a completed Provider Turn may carry a completed Agent result.");
|
|
295
294
|
}
|
|
@@ -298,14 +297,11 @@ function normalizeNativeTurnTerminalInput(input) {
|
|
|
298
297
|
roleName: requireIdentityText(input.roleName, "Role name"),
|
|
299
298
|
agentId: requireIdentityText(input.agentId, "Agent id"),
|
|
300
299
|
adapterId: input.adapterId,
|
|
301
|
-
...(input.runtimeGenerationId === undefined
|
|
302
|
-
? {}
|
|
303
|
-
: { runtimeGenerationId: requireIdentityText(input.runtimeGenerationId, "Runtime generation id") }),
|
|
304
300
|
nativeSessionId: requireIdentityText(input.nativeSessionId, "Native session id"),
|
|
305
301
|
nativeTurnId: requireIdentityText(input.nativeTurnId, "Provider native Turn id"),
|
|
306
|
-
...(input.
|
|
302
|
+
...(input.runId === undefined
|
|
307
303
|
? {}
|
|
308
|
-
: {
|
|
304
|
+
: { runId: requireIdentityText(input.runId, "AgentRun id") }),
|
|
309
305
|
...(input.title === undefined
|
|
310
306
|
? {}
|
|
311
307
|
: { title: requireIdentityText(input.title, "Session title") }),
|
|
@@ -318,9 +314,9 @@ function normalizeNativeTurnTerminalInput(input) {
|
|
|
318
314
|
? { ...common, taskId: requireIdentityText(input.taskId, "Task id") }
|
|
319
315
|
: common;
|
|
320
316
|
}
|
|
321
|
-
function
|
|
317
|
+
function normalizeRuntimeRunTerminalOutcome(input) {
|
|
322
318
|
if (!isObject(input)) {
|
|
323
|
-
throw invalidEvent("Runtime
|
|
319
|
+
throw invalidEvent("Runtime AgentRun terminal outcome is invalid.");
|
|
324
320
|
}
|
|
325
321
|
if (input.status === "completed")
|
|
326
322
|
return transportAgentResult(input.output);
|
|
@@ -336,14 +332,52 @@ function normalizeRuntimeTurnTerminalOutcome(input) {
|
|
|
336
332
|
"cancelled"
|
|
337
333
|
]
|
|
338
334
|
.includes(input.failureReason)) {
|
|
339
|
-
throw invalidEvent("Runtime
|
|
335
|
+
throw invalidEvent("Runtime AgentRun failure outcome is invalid.");
|
|
340
336
|
}
|
|
341
337
|
return {
|
|
342
338
|
status: "failed",
|
|
343
|
-
diagnostic:
|
|
344
|
-
failureReason: input.failureReason
|
|
339
|
+
diagnostic: boundedRunFailureDiagnostic(input.diagnostic),
|
|
340
|
+
failureReason: input.failureReason,
|
|
341
|
+
...(typeof input.output === "string" && transportAgentResult(input.output).status === "completed"
|
|
342
|
+
? { output: input.output } : {})
|
|
345
343
|
};
|
|
346
344
|
}
|
|
345
|
+
/** The already deployed inbox v1 is a transport envelope, not a second domain
|
|
346
|
+
* schema. Keep its wire keys and opaque ids stable so pre-upgrade pending
|
|
347
|
+
* facts remain readable atomically. Public/in-process values use runId.
|
|
348
|
+
* Retire this codec only with a new inbox protocol after all v1 producers
|
|
349
|
+
* and pending files have drained; do not introduce dual domain-store reads.
|
|
350
|
+
*/
|
|
351
|
+
function inboxReference(value, encode) {
|
|
352
|
+
const from = encode ? "runId" : "turnId";
|
|
353
|
+
const to = encode ? "turnId" : "runId";
|
|
354
|
+
if (Object.hasOwn(value, to))
|
|
355
|
+
throw invalidEvent("Inbox v1 reference uses the wrong wire shape.");
|
|
356
|
+
const { [from]: id, ...rest } = value;
|
|
357
|
+
return id === undefined ? rest : { ...rest, [to]: id };
|
|
358
|
+
}
|
|
359
|
+
function inboxEnvelope(value, encode) {
|
|
360
|
+
if (!isObject(value))
|
|
361
|
+
throw invalidEvent();
|
|
362
|
+
if (value.type === "native-turn-terminal")
|
|
363
|
+
return inboxReference(value, encode);
|
|
364
|
+
if (value.type !== "runtime-observation")
|
|
365
|
+
return value;
|
|
366
|
+
if (!isObject(value.observation) || !isObject(value.observation.fence))
|
|
367
|
+
throw invalidEvent();
|
|
368
|
+
const observation = value.observation;
|
|
369
|
+
let payload = observation.payload;
|
|
370
|
+
if (isObject(payload?.failure)) {
|
|
371
|
+
const from = encode ? "runTerminal" : "turnTerminal";
|
|
372
|
+
const to = encode ? "turnTerminal" : "runTerminal";
|
|
373
|
+
const { [from]: terminal, ...failure } = payload.failure;
|
|
374
|
+
payload = { ...payload, failure: terminal === undefined ? failure : { ...failure, [to]: terminal } };
|
|
375
|
+
}
|
|
376
|
+
return { ...value, observation: { ...observation, payload,
|
|
377
|
+
fence: inboxReference(observation.fence, encode) } };
|
|
378
|
+
}
|
|
379
|
+
function encodeInboxV1(value) { return inboxEnvelope(value, true); }
|
|
380
|
+
function decodeInboxV1(value) { return inboxEnvelope(value, false); }
|
|
347
381
|
function normalizeDurableJobTerminalInput(input) {
|
|
348
382
|
if (input.scope !== "task")
|
|
349
383
|
throw invalidEvent();
|
|
@@ -418,16 +452,14 @@ function parseNativeTurnTerminalEvent(value) {
|
|
|
418
452
|
"schemaVersion", "id", "type", "receivedAt", "scope", "taskId",
|
|
419
453
|
"roleName", "agentId", "adapterId", "nativeSessionId", "nativeTurnId",
|
|
420
454
|
"providerStatus", "outcome",
|
|
421
|
-
...(value.
|
|
422
|
-
...(value.turnId === undefined ? [] : ["turnId"]),
|
|
455
|
+
...(value.runId === undefined ? [] : ["runId"]),
|
|
423
456
|
...(value.title === undefined ? [] : ["title"])
|
|
424
457
|
]
|
|
425
458
|
: [
|
|
426
459
|
"schemaVersion", "id", "type", "receivedAt", "scope",
|
|
427
460
|
"roleName", "agentId", "adapterId", "nativeSessionId", "nativeTurnId",
|
|
428
461
|
"providerStatus", "outcome",
|
|
429
|
-
...(value.
|
|
430
|
-
...(value.turnId === undefined ? [] : ["turnId"]),
|
|
462
|
+
...(value.runId === undefined ? [] : ["runId"]),
|
|
431
463
|
...(value.title === undefined ? [] : ["title"])
|
|
432
464
|
];
|
|
433
465
|
if ((scope !== "task" && scope !== "global")
|
|
@@ -441,10 +473,9 @@ function parseNativeTurnTerminalEvent(value) {
|
|
|
441
473
|
roleName: value.roleName,
|
|
442
474
|
agentId: value.agentId,
|
|
443
475
|
adapterId: value.adapterId,
|
|
444
|
-
...(value.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: value.runtimeGenerationId }),
|
|
445
476
|
nativeSessionId: value.nativeSessionId,
|
|
446
477
|
nativeTurnId: value.nativeTurnId,
|
|
447
|
-
...(value.
|
|
478
|
+
...(value.runId === undefined ? {} : { runId: value.runId }),
|
|
448
479
|
...(value.title === undefined ? {} : { title: value.title }),
|
|
449
480
|
providerStatus: value.providerStatus,
|
|
450
481
|
outcome: value.outcome
|
|
@@ -503,11 +534,10 @@ function hasSameIdentity(left, right) {
|
|
|
503
534
|
&& (!("roleName" in left) || !("roleName" in right) || left.roleName === right.roleName)
|
|
504
535
|
&& (!("agentId" in left) || !("agentId" in right) || left.agentId === right.agentId)
|
|
505
536
|
&& (!("adapterId" in left) || !("adapterId" in right) || left.adapterId === right.adapterId)
|
|
506
|
-
&& (!("runtimeGenerationId" in left) || !("runtimeGenerationId" in right) || left.runtimeGenerationId === right.runtimeGenerationId)
|
|
507
537
|
&& (!("nativeSessionId" in left)
|
|
508
538
|
|| !("nativeSessionId" in right)
|
|
509
539
|
|| left.nativeSessionId === right.nativeSessionId)
|
|
510
|
-
&& (!("
|
|
540
|
+
&& (!("runId" in left) || !("runId" in right) || left.runId === right.runId)
|
|
511
541
|
&& (!("jobId" in left) || !("jobId" in right) || left.jobId === right.jobId);
|
|
512
542
|
}
|
|
513
543
|
function compareRuntimeEvents(left, right) {
|
|
@@ -189,10 +189,9 @@ export class FileRuntimeEventProcessor {
|
|
|
189
189
|
roleName: event.roleName,
|
|
190
190
|
agentId: event.agentId,
|
|
191
191
|
adapterId: event.adapterId,
|
|
192
|
-
...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
|
|
193
192
|
nativeSessionId: event.nativeSessionId,
|
|
194
193
|
nativeTurnId: event.nativeTurnId,
|
|
195
|
-
...(event.
|
|
194
|
+
...(event.runId === undefined ? {} : { runId: event.runId }),
|
|
196
195
|
providerStatus: event.providerStatus,
|
|
197
196
|
outcome: event.outcome
|
|
198
197
|
};
|
|
@@ -202,15 +201,15 @@ export class FileRuntimeEventProcessor {
|
|
|
202
201
|
this.recordObsolete(event, task.status === "archived" ? "task-archived" : "task-retired", now);
|
|
203
202
|
return "obsolete";
|
|
204
203
|
}
|
|
205
|
-
const disposition = this.observer.
|
|
204
|
+
const disposition = this.observer.classifyRuntimeRunTerminal?.(input) ?? "apply";
|
|
206
205
|
if (disposition === "deferred")
|
|
207
206
|
return disposition;
|
|
208
207
|
if (disposition === "obsolete") {
|
|
209
208
|
this.recordObsolete(event, "identity-mismatch-or-terminal", now);
|
|
210
209
|
return disposition;
|
|
211
210
|
}
|
|
212
|
-
const observed = this.observer.
|
|
213
|
-
if (
|
|
211
|
+
const observed = this.observer.observeRuntimeRunTerminal(input, now);
|
|
212
|
+
if (isObsoleteRuntimeRunObservation(observed)) {
|
|
214
213
|
this.recordObsolete(event, "runtime-cleanup-or-stopped-session", now);
|
|
215
214
|
return "obsolete";
|
|
216
215
|
}
|
|
@@ -221,15 +220,14 @@ export class FileRuntimeEventProcessor {
|
|
|
221
220
|
roleName: event.roleName,
|
|
222
221
|
agentId: event.agentId,
|
|
223
222
|
adapterId: event.adapterId,
|
|
224
|
-
...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
|
|
225
223
|
nativeSessionId: event.nativeSessionId,
|
|
226
224
|
nativeTurnId: event.nativeTurnId,
|
|
227
225
|
...(event.title === undefined ? {} : { title: event.title }),
|
|
228
226
|
providerStatus: event.providerStatus,
|
|
229
227
|
outcome: event.outcome
|
|
230
228
|
};
|
|
231
|
-
if (this.observer.
|
|
232
|
-
this.observer.
|
|
229
|
+
if (this.observer.classifyGlobalRuntimeRunTerminal?.(input) !== "obsolete") {
|
|
230
|
+
this.observer.observeGlobalRuntimeRunTerminal(input, now);
|
|
233
231
|
return "applied";
|
|
234
232
|
}
|
|
235
233
|
return "obsolete";
|
|
@@ -247,8 +245,7 @@ export class FileRuntimeEventProcessor {
|
|
|
247
245
|
taskId: event.taskId,
|
|
248
246
|
roleName: fence.roleName,
|
|
249
247
|
agentId: fence.agentId,
|
|
250
|
-
...(fence.
|
|
251
|
-
runtimeGenerationId: fence.runtimeGenerationId,
|
|
248
|
+
...(fence.runId === undefined ? {} : { runId: fence.runId }),
|
|
252
249
|
nativeSessionId: fence.nativeSessionId,
|
|
253
250
|
reason
|
|
254
251
|
}, now);
|
|
@@ -264,8 +261,7 @@ export class FileRuntimeEventProcessor {
|
|
|
264
261
|
taskId: event.taskId,
|
|
265
262
|
roleName: event.roleName,
|
|
266
263
|
agentId: event.agentId,
|
|
267
|
-
...(event.
|
|
268
|
-
...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
|
|
264
|
+
...(event.runId === undefined ? {} : { runId: event.runId }),
|
|
269
265
|
nativeSessionId: event.nativeSessionId,
|
|
270
266
|
reason
|
|
271
267
|
}, now);
|
|
@@ -396,9 +392,8 @@ function progressStreamKey(event) {
|
|
|
396
392
|
fence.roleName,
|
|
397
393
|
fence.agentId,
|
|
398
394
|
fence.driverId,
|
|
399
|
-
fence.runtimeGenerationId,
|
|
400
395
|
fence.nativeSessionId ?? null,
|
|
401
|
-
fence.
|
|
396
|
+
fence.runId ?? null,
|
|
402
397
|
payload.activity,
|
|
403
398
|
isRuntimeTokenEvidence(event.observation) ? "usage" : "signal"
|
|
404
399
|
]);
|
|
@@ -432,7 +427,7 @@ function positiveInteger(value, fallback) {
|
|
|
432
427
|
}
|
|
433
428
|
return resolved;
|
|
434
429
|
}
|
|
435
|
-
function
|
|
430
|
+
function isObsoleteRuntimeRunObservation(value) {
|
|
436
431
|
return typeof value === "object"
|
|
437
432
|
&& value !== null
|
|
438
433
|
&& value.disposition === "obsolete";
|
|
@@ -516,10 +511,10 @@ export function createAsyncRuntimeObserver(invoke) {
|
|
|
516
511
|
return {
|
|
517
512
|
getTask: (taskId) => call("getTask", [taskId]),
|
|
518
513
|
observeRuntimeObservation: (input, now) => withNow("observeRuntimeObservation", input, now),
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
514
|
+
observeRuntimeRunTerminal: (input, now) => withNow("observeRuntimeRunTerminal", input, now),
|
|
515
|
+
observeGlobalRuntimeRunTerminal: (input, now) => withNow("observeGlobalRuntimeRunTerminal", input, now),
|
|
516
|
+
classifyRuntimeRunTerminal: (input) => call("classifyRuntimeRunTerminal", [input]),
|
|
517
|
+
classifyGlobalRuntimeRunTerminal: (input) => call("classifyGlobalRuntimeRunTerminal", [input]),
|
|
523
518
|
observeObsoleteRuntimeEvent: (input, now) => withNow("observeObsoleteRuntimeEvent", input, now)
|
|
524
519
|
};
|
|
525
520
|
}
|
|
@@ -632,10 +627,9 @@ export class AsyncRuntimeEventProcessor {
|
|
|
632
627
|
roleName: event.roleName,
|
|
633
628
|
agentId: event.agentId,
|
|
634
629
|
adapterId: event.adapterId,
|
|
635
|
-
...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
|
|
636
630
|
nativeSessionId: event.nativeSessionId,
|
|
637
631
|
nativeTurnId: event.nativeTurnId,
|
|
638
|
-
...(event.
|
|
632
|
+
...(event.runId === undefined ? {} : { runId: event.runId }),
|
|
639
633
|
providerStatus: event.providerStatus,
|
|
640
634
|
outcome: event.outcome
|
|
641
635
|
};
|
|
@@ -645,15 +639,15 @@ export class AsyncRuntimeEventProcessor {
|
|
|
645
639
|
await this.recordObsolete(event, task.status === "archived" ? "task-archived" : "task-retired", now);
|
|
646
640
|
return "obsolete";
|
|
647
641
|
}
|
|
648
|
-
const disposition = (await this.observer.
|
|
642
|
+
const disposition = (await this.observer.classifyRuntimeRunTerminal?.(input)) ?? "apply";
|
|
649
643
|
if (disposition === "deferred")
|
|
650
644
|
return disposition;
|
|
651
645
|
if (disposition === "obsolete") {
|
|
652
646
|
await this.recordObsolete(event, "identity-mismatch-or-terminal", now);
|
|
653
647
|
return disposition;
|
|
654
648
|
}
|
|
655
|
-
const observed = await this.observer.
|
|
656
|
-
if (
|
|
649
|
+
const observed = await this.observer.observeRuntimeRunTerminal(input, now);
|
|
650
|
+
if (isObsoleteRuntimeRunObservation(observed)) {
|
|
657
651
|
await this.recordObsolete(event, "runtime-cleanup-or-stopped-session", now);
|
|
658
652
|
return "obsolete";
|
|
659
653
|
}
|
|
@@ -664,15 +658,14 @@ export class AsyncRuntimeEventProcessor {
|
|
|
664
658
|
roleName: event.roleName,
|
|
665
659
|
agentId: event.agentId,
|
|
666
660
|
adapterId: event.adapterId,
|
|
667
|
-
...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
|
|
668
661
|
nativeSessionId: event.nativeSessionId,
|
|
669
662
|
nativeTurnId: event.nativeTurnId,
|
|
670
663
|
...(event.title === undefined ? {} : { title: event.title }),
|
|
671
664
|
providerStatus: event.providerStatus,
|
|
672
665
|
outcome: event.outcome
|
|
673
666
|
};
|
|
674
|
-
if ((await this.observer.
|
|
675
|
-
await this.observer.
|
|
667
|
+
if ((await this.observer.classifyGlobalRuntimeRunTerminal?.(input)) !== "obsolete") {
|
|
668
|
+
await this.observer.observeGlobalRuntimeRunTerminal(input, now);
|
|
676
669
|
return "applied";
|
|
677
670
|
}
|
|
678
671
|
return "obsolete";
|
|
@@ -690,8 +683,7 @@ export class AsyncRuntimeEventProcessor {
|
|
|
690
683
|
taskId: event.taskId,
|
|
691
684
|
roleName: fence.roleName,
|
|
692
685
|
agentId: fence.agentId,
|
|
693
|
-
...(fence.
|
|
694
|
-
runtimeGenerationId: fence.runtimeGenerationId,
|
|
686
|
+
...(fence.runId === undefined ? {} : { runId: fence.runId }),
|
|
695
687
|
nativeSessionId: fence.nativeSessionId,
|
|
696
688
|
reason
|
|
697
689
|
}, now);
|
|
@@ -703,8 +695,7 @@ export class AsyncRuntimeEventProcessor {
|
|
|
703
695
|
taskId: event.taskId,
|
|
704
696
|
roleName: event.roleName,
|
|
705
697
|
agentId: event.agentId,
|
|
706
|
-
...(event.
|
|
707
|
-
...(event.runtimeGenerationId === undefined ? {} : { runtimeGenerationId: event.runtimeGenerationId }),
|
|
698
|
+
...(event.runId === undefined ? {} : { runId: event.runId }),
|
|
708
699
|
nativeSessionId: event.nativeSessionId,
|
|
709
700
|
reason
|
|
710
701
|
}, now);
|