maka-agent 0.2.0-dev.26.20260909 → 0.2.0-dev.27.20260910
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/dist/cli-core.js +21 -0
- package/dist/runtime-host-cli.js +43 -3
- package/dist/runtime-host-handoff-surface.js +10 -8
- package/dist/runtime-host-lifecycle-transaction.js +28 -3
- package/dist/runtime-host-local-source-retirement.js +1 -1
- package/dist/runtime-host-setup-command.js +29 -6
- package/dist/runtime-host-update-command.js +49 -5
- package/dist/session-export-command.js +72 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/usage-stats/types.js +2 -0
- package/node_modules/@maka/core/dist/workhub-routing.js +126 -0
- package/node_modules/@maka/core/package.json +2 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +7 -3
- package/node_modules/@maka/runtime/dist/builtin-tools.js +21 -2
- package/node_modules/@maka/runtime/dist/plugin-agent-service.js +131 -0
- package/node_modules/@maka/runtime/dist/plugin-approval-service.js +33 -0
- package/node_modules/@maka/runtime/dist/plugin-attachment-service.js +53 -0
- package/node_modules/@maka/runtime/dist/plugin-command-service.js +100 -0
- package/node_modules/@maka/runtime/dist/plugin-data-services.js +332 -0
- package/node_modules/@maka/runtime/dist/plugin-fs-service.js +62 -0
- package/node_modules/@maka/runtime/dist/plugin-goal-service.js +61 -0
- package/node_modules/@maka/runtime/dist/plugin-invocation-signal.js +24 -0
- package/node_modules/@maka/runtime/dist/plugin-llm-service.js +85 -0
- package/node_modules/@maka/runtime/dist/plugin-lsp-service.js +94 -0
- package/node_modules/@maka/runtime/dist/plugin-scope-registry.js +91 -0
- package/node_modules/@maka/runtime/dist/plugin-session-query-service.js +71 -0
- package/node_modules/@maka/runtime/dist/plugin-shell-env-service.js +87 -0
- package/node_modules/@maka/runtime/dist/plugin-shell-service.js +74 -0
- package/node_modules/@maka/runtime/dist/plugin-skill-service.js +93 -0
- package/node_modules/@maka/runtime/dist/plugin-system-prompt-service.js +346 -0
- package/node_modules/@maka/runtime/dist/plugin-tool-service.js +18 -52
- package/node_modules/@maka/runtime/dist/plugin-user-question-service.js +43 -0
- package/node_modules/@maka/runtime/dist/plugin-web-service.js +69 -0
- package/node_modules/@maka/runtime/dist/session-export.js +177 -0
- package/node_modules/@maka/runtime/package.json +18 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +67 -18
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +46 -12
- package/node_modules/@maka/runtime-host/dist/operator/setup-frame.js +31 -21
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +9 -1
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +30 -5
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +25 -23
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +62 -4
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +452 -7
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +74 -0
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +2 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +30 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +79 -16
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +25 -4
- package/node_modules/@maka/runtime-host/dist/server/plugin-data-runtime.js +234 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +12 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +189 -92
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -35
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +92 -10
- package/node_modules/@maka/storage/dist/agent-run-store.js +54 -10
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +13 -6
- package/node_modules/@maka/storage/dist/execution-stores.js +1 -1
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +333 -30
- package/node_modules/@maka/storage/dist/session-store.js +2 -2
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +12 -5
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -32,6 +32,7 @@ import { RuntimeOwnerCleanupError } from '@maka/runtime/runtime-kernel';
|
|
|
32
32
|
import { parseSkillInvocationTokens, } from '@maka/runtime/skill-invocation';
|
|
33
33
|
import { skillInvocationInlineReferences } from '@maka/runtime/skill-invocation-receipt';
|
|
34
34
|
import { authenticateExecutionStoresWriter, isSessionNotFoundError, normalizeRootTurnAdmissionPayload, } from '@maka/storage/execution-stores';
|
|
35
|
+
import { hostedExecutionRunProfile } from './hosted-execution-tool-profile.js';
|
|
35
36
|
import { runtimeHostExecutionUnavailableReason, runtimeHostExternalTurnUnavailableReason, runtimeHostSafeBoundaryContinuationUnavailableReason, WORKHUB_COORDINATION_EXECUTION_UNAVAILABLE_REASON, } from './host-session-availability.js';
|
|
36
37
|
import { completedHostedExecutionAdmission } from './hosted-execution-authority.js';
|
|
37
38
|
import { HostedExecutionProjectionReader } from './hosted-execution-projection.js';
|
|
@@ -54,6 +55,7 @@ export class RootTurnCoordinator {
|
|
|
54
55
|
agentGraphEpochs;
|
|
55
56
|
nameSessionFromRootMessage;
|
|
56
57
|
directoryHostId;
|
|
58
|
+
prepareWorkHubRoutingDecision;
|
|
57
59
|
handlers = {
|
|
58
60
|
'turn.resume.query': (input, context) => this.queryTurnResume(input, context),
|
|
59
61
|
'turn.resume.start': (input, context) => this.startTurnResume(input, context),
|
|
@@ -67,7 +69,7 @@ export class RootTurnCoordinator {
|
|
|
67
69
|
executionProjection;
|
|
68
70
|
attachmentValidator;
|
|
69
71
|
prepareSkillInvocation;
|
|
70
|
-
constructor(manager, stores, sessionAdmission, rootAdmissionOwner, interactions, messages, continuity, acquireRecoveryResidency, requestHostDrain, clientCapabilities, resolveExecutionObserver, assertScheduledTaskRecoveryAdmission, attachmentValidator, prepareSkillInvocation, agentGraphEpochs, nameSessionFromRootMessage, directoryHostId) {
|
|
72
|
+
constructor(manager, stores, sessionAdmission, rootAdmissionOwner, interactions, messages, continuity, acquireRecoveryResidency, requestHostDrain, clientCapabilities, resolveExecutionObserver, assertScheduledTaskRecoveryAdmission, attachmentValidator, prepareSkillInvocation, agentGraphEpochs, nameSessionFromRootMessage, directoryHostId, prepareWorkHubRoutingDecision) {
|
|
71
73
|
this.manager = manager;
|
|
72
74
|
this.sessionAdmission = sessionAdmission;
|
|
73
75
|
this.rootAdmissionOwner = rootAdmissionOwner;
|
|
@@ -82,6 +84,7 @@ export class RootTurnCoordinator {
|
|
|
82
84
|
this.agentGraphEpochs = agentGraphEpochs;
|
|
83
85
|
this.nameSessionFromRootMessage = nameSessionFromRootMessage;
|
|
84
86
|
this.directoryHostId = directoryHostId;
|
|
87
|
+
this.prepareWorkHubRoutingDecision = prepareWorkHubRoutingDecision;
|
|
85
88
|
this.stores = authenticateExecutionStoresWriter(stores, 'interactive');
|
|
86
89
|
this.executionProjection = new HostedExecutionProjectionReader(this.stores);
|
|
87
90
|
this.#admissions = new HostedExecutionAdmissionRegistry((sessionId) => this.#executions.has(sessionId));
|
|
@@ -104,79 +107,98 @@ export class RootTurnCoordinator {
|
|
|
104
107
|
}
|
|
105
108
|
async recover() {
|
|
106
109
|
for (const [sessionId, plan] of this.#recoveryPlansBySession) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (admission.sourceMessages.length > 0) {
|
|
115
|
-
await this.messages.materializeMessageHandoffsForRun({
|
|
116
|
-
sessionId,
|
|
117
|
-
turnId: admission.turnId,
|
|
118
|
-
runId: admission.runId,
|
|
119
|
-
messageIds: admission.sourceMessages.map((source) => source.messageId),
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
if (plan.rootReplayAdmission === admission)
|
|
110
|
+
if (plan.rootReplayAdmission &&
|
|
111
|
+
!(await this.bindRecoveryCapabilities(sessionId, plan.rootReplayAdmission.execution)))
|
|
112
|
+
continue;
|
|
113
|
+
try {
|
|
114
|
+
for (const admission of plan.admissions) {
|
|
115
|
+
const run = await this.readRunIfPresent(sessionId, admission.runId);
|
|
116
|
+
if (!run)
|
|
125
117
|
continue;
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
await this.assertRunMatchesDurableExecution(run, admission.turnId, admission.execution);
|
|
119
|
+
const snapshot = await this.readCanonicalSnapshot(sessionId, admission.turnId, admission.runId, run);
|
|
120
|
+
if (isTerminalSnapshot(snapshot)) {
|
|
121
|
+
if (admission.sourceMessages.length > 0) {
|
|
122
|
+
await this.messages.materializeMessageHandoffsForRun({
|
|
123
|
+
sessionId,
|
|
124
|
+
turnId: admission.turnId,
|
|
125
|
+
runId: admission.runId,
|
|
126
|
+
messageIds: admission.sourceMessages.map((source) => source.messageId),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Session recovery may have materialized this Run after the replay plan was prepared.
|
|
136
|
-
const existingRun = await this.readRunIfPresent(sessionId, admission.runId);
|
|
137
|
-
const pendingHandoff = existingRun &&
|
|
138
|
-
(await readLogicalRuntimeExecution(this.stores.runtimeEventStore, admission, existingRun))
|
|
139
|
-
?.pendingHandoff;
|
|
140
|
-
if (existingRun && !pendingHandoff)
|
|
141
|
-
continue;
|
|
142
|
-
const input = activationInputForAdmission(admission);
|
|
143
|
-
const disposition = await this.sessionAdmission.run(sessionId, async (lease) => {
|
|
144
|
-
if (admission.execution.kind === 'safe_boundary_continuation') {
|
|
145
|
-
const header = await this.stores.sessionStore.readHeaderSnapshot(sessionId);
|
|
146
|
-
if (runtimeHostSafeBoundaryContinuationUnavailableReason(header)) {
|
|
130
|
+
else {
|
|
131
|
+
if (plan.rootReplayAdmission === admission)
|
|
132
|
+
continue;
|
|
133
|
+
if (admission.execution.kind !== 'safe_boundary_continuation') {
|
|
134
|
+
throw new Error(`Startup recovery left Turn ${admission.turnId} non-terminal`);
|
|
135
|
+
}
|
|
147
136
|
this.parkContinuationAdmission(admission);
|
|
148
|
-
return undefined;
|
|
149
137
|
}
|
|
150
138
|
}
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
139
|
+
const admission = plan.rootReplayAdmission;
|
|
140
|
+
if (!admission)
|
|
141
|
+
continue;
|
|
142
|
+
// Session recovery may have materialized this Run after the replay plan was prepared.
|
|
143
|
+
const existingRun = await this.readRunIfPresent(sessionId, admission.runId);
|
|
144
|
+
const pendingHandoff = existingRun &&
|
|
145
|
+
(await readLogicalRuntimeExecution(this.stores.runtimeEventStore, admission, existingRun))
|
|
146
|
+
?.pendingHandoff;
|
|
147
|
+
if (existingRun && !pendingHandoff)
|
|
148
|
+
continue;
|
|
149
|
+
const input = activationInputForAdmission(admission);
|
|
150
|
+
const disposition = await this.sessionAdmission.run(sessionId, async (lease) => {
|
|
151
|
+
if (admission.execution.kind === 'safe_boundary_continuation') {
|
|
152
|
+
const header = await this.stores.sessionStore.readHeaderSnapshot(sessionId);
|
|
153
|
+
if (runtimeHostSafeBoundaryContinuationUnavailableReason(header)) {
|
|
154
|
+
this.parkContinuationAdmission(admission);
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
161
157
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
const continuation = admission.execution.kind === 'safe_boundary_continuation' && !pendingHandoff
|
|
159
|
+
? await this.reconstructAdmittedContinuation(admission)
|
|
160
|
+
: undefined;
|
|
161
|
+
if (continuation?.disposition === 'parked') {
|
|
162
|
+
if (continuation.plan.reason === 'safety_check_failed' ||
|
|
163
|
+
continuation.plan.reason === 'resume_feature_disabled' ||
|
|
164
|
+
continuation.plan.reason === 'continuation_authority_unavailable' ||
|
|
165
|
+
continuation.plan.reason === 'safety_observation_unavailable') {
|
|
166
|
+
this.parkContinuationAdmission(admission);
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`Unable to recover admitted Turn ${admission.turnId}: ${continuation.plan.reason}`);
|
|
170
|
+
}
|
|
171
|
+
await this.messages.handoffRootSources({
|
|
172
|
+
sessionId,
|
|
173
|
+
turnId: admission.turnId,
|
|
174
|
+
runId: admission.runId,
|
|
175
|
+
messageIds: admission.sourceMessages.map((source) => source.messageId),
|
|
176
|
+
});
|
|
177
|
+
return this.prepareAdmittedTurn(input, admission, this.acquireRecoveryResidency, lease, undefined, undefined, undefined, continuation?.continuation);
|
|
169
178
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
if (!disposition)
|
|
180
|
+
continue;
|
|
181
|
+
const outcome = await this.resolveStartDisposition(input, disposition);
|
|
182
|
+
if (!outcome.ok) {
|
|
183
|
+
throw new Error(`Unable to recover admitted Turn ${admission.turnId}: ${outcome.error.code}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
this.#recoveryPlansBySession.delete(sessionId);
|
|
177
188
|
}
|
|
178
189
|
}
|
|
179
|
-
|
|
190
|
+
}
|
|
191
|
+
async bindRecoveryCapabilities(sessionId, execution) {
|
|
192
|
+
const header = await this.stores.sessionStore.readHeaderSnapshot(sessionId);
|
|
193
|
+
if (header.toolProfile !== 'workhub-coordination-v2')
|
|
194
|
+
return true;
|
|
195
|
+
// Older admissions without authenticated provider evidence stay pending.
|
|
196
|
+
// Neither registration order nor a tool name can establish Desktop ownership.
|
|
197
|
+
if (execution.kind !== 'workhub_coordination' ||
|
|
198
|
+
!execution.capabilityBinding ||
|
|
199
|
+
!this.clientCapabilities)
|
|
200
|
+
return false;
|
|
201
|
+
return this.clientCapabilities.bindRecoveredSession(sessionId, execution.capabilityBinding, hostedExecutionRunProfile(header.toolProfile).toolNames.filter((name) => name.startsWith('mcp__')));
|
|
180
202
|
}
|
|
181
203
|
async close() {
|
|
182
204
|
this.#cancelHandoff?.();
|
|
@@ -202,6 +224,15 @@ export class RootTurnCoordinator {
|
|
|
202
224
|
}
|
|
203
225
|
async readSessionHeader(sessionId) {
|
|
204
226
|
if (isWorkHubCoordinationSessionId(sessionId)) {
|
|
227
|
+
const active = this.#executions.get(sessionId);
|
|
228
|
+
if (active?.descriptor.kind === 'workhub_coordination' &&
|
|
229
|
+
!active.descriptor.operation &&
|
|
230
|
+
!active.stopRequested) {
|
|
231
|
+
const header = await this.stores.sessionStore.readHeaderSnapshot(sessionId);
|
|
232
|
+
if (header.toolProfile === 'workhub-coordination-v2') {
|
|
233
|
+
return { isArchived: header.isArchived, activeTurnOnly: true };
|
|
234
|
+
}
|
|
235
|
+
}
|
|
205
236
|
return {
|
|
206
237
|
isArchived: false,
|
|
207
238
|
unavailableReason: WORKHUB_COORDINATION_EXECUTION_UNAVAILABLE_REASON,
|
|
@@ -236,7 +267,9 @@ export class RootTurnCoordinator {
|
|
|
236
267
|
runId: active.runId,
|
|
237
268
|
};
|
|
238
269
|
}
|
|
239
|
-
return this.#handoffHold ||
|
|
270
|
+
return this.#handoffHold ||
|
|
271
|
+
this.#admissions.has(sessionId) ||
|
|
272
|
+
this.#recoveryPlansBySession.get(sessionId)?.rootReplayAdmission
|
|
240
273
|
? { kind: 'reserved' }
|
|
241
274
|
: { kind: 'idle' };
|
|
242
275
|
}
|
|
@@ -270,7 +303,7 @@ export class RootTurnCoordinator {
|
|
|
270
303
|
}, context);
|
|
271
304
|
}
|
|
272
305
|
reserveRootTurn(sessionId) {
|
|
273
|
-
if (this.#handoffHold)
|
|
306
|
+
if (this.#handoffHold || this.#recoveryPlansBySession.get(sessionId)?.rootReplayAdmission)
|
|
274
307
|
return undefined;
|
|
275
308
|
return this.#admissions.reserve(sessionId);
|
|
276
309
|
}
|
|
@@ -920,14 +953,27 @@ export class RootTurnCoordinator {
|
|
|
920
953
|
return { error: 'A root Turn is still active' };
|
|
921
954
|
}
|
|
922
955
|
const header = await this.stores.sessionStore.readHeaderSnapshot(input.sessionId);
|
|
923
|
-
const
|
|
956
|
+
const turnId = input.rootIdentity?.turnId ?? randomUUID();
|
|
957
|
+
const previous = this.rootAdmissionOwner.latestAdmission(input.sessionId)?.execution;
|
|
958
|
+
let execution = {
|
|
959
|
+
kind: isWorkHubCoordinationSessionId(header.id)
|
|
960
|
+
? 'workhub_coordination'
|
|
961
|
+
: 'external_message',
|
|
962
|
+
inputDigest: messageContentDigest(input.submittedContent),
|
|
963
|
+
...(previous?.kind === 'workhub_coordination' && previous.capabilityBinding
|
|
964
|
+
? { capabilityBinding: previous.capabilityBinding }
|
|
965
|
+
: {}),
|
|
966
|
+
};
|
|
967
|
+
if (!(await this.bindRecoveryCapabilities(input.sessionId, execution)))
|
|
968
|
+
return { deferred: true };
|
|
969
|
+
execution = await this.prepareFreshWorkHubExecution(header, turnId, input.content, execution);
|
|
970
|
+
const unavailableReason = runtimeHostExecutionUnavailableReason(header, execution);
|
|
924
971
|
if (unavailableReason)
|
|
925
972
|
return { error: unavailableReason };
|
|
926
973
|
const reservation = this.reserveRootTurn(input.sessionId);
|
|
927
974
|
if (!reservation)
|
|
928
975
|
return { error: 'Another root Turn is being admitted' };
|
|
929
976
|
try {
|
|
930
|
-
const turnId = input.rootIdentity?.turnId ?? randomUUID();
|
|
931
977
|
// The recovered Message asked for this mode before the Host stopped;
|
|
932
978
|
// admitting without it would run a different Turn than was requested.
|
|
933
979
|
const turnOrchestration = input.submittedIntent?.turnOrchestration;
|
|
@@ -937,10 +983,7 @@ export class RootTurnCoordinator {
|
|
|
937
983
|
turnId,
|
|
938
984
|
proposedRunId: input.rootIdentity?.runId ?? randomUUID(),
|
|
939
985
|
proposedUserMessageId: input.sources.length === 1 ? input.sources[0].messageId : null,
|
|
940
|
-
execution
|
|
941
|
-
kind: 'external_message',
|
|
942
|
-
inputDigest: messageContentDigest(input.submittedContent),
|
|
943
|
-
},
|
|
986
|
+
execution,
|
|
944
987
|
normalizedInput: input.content,
|
|
945
988
|
...(turnOrchestration ? { turnOrchestration } : {}),
|
|
946
989
|
sourceMessages: input.sources,
|
|
@@ -967,6 +1010,20 @@ export class RootTurnCoordinator {
|
|
|
967
1010
|
}
|
|
968
1011
|
});
|
|
969
1012
|
}
|
|
1013
|
+
async prepareFreshWorkHubExecution(header, turnId, content, execution, inputClosedSignal) {
|
|
1014
|
+
if (execution.kind !== 'workhub_coordination' || !this.prepareWorkHubRoutingDecision) {
|
|
1015
|
+
return execution;
|
|
1016
|
+
}
|
|
1017
|
+
return {
|
|
1018
|
+
...execution,
|
|
1019
|
+
routingDecision: await this.prepareWorkHubRoutingDecision({
|
|
1020
|
+
header,
|
|
1021
|
+
turnId,
|
|
1022
|
+
content,
|
|
1023
|
+
...(inputClosedSignal ? { inputClosedSignal } : {}),
|
|
1024
|
+
}),
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
970
1027
|
prepareMessage(input) {
|
|
971
1028
|
return this.runCommand(async () => {
|
|
972
1029
|
const content = normalizeMessageContent(input.content);
|
|
@@ -1167,7 +1224,11 @@ export class RootTurnCoordinator {
|
|
|
1167
1224
|
};
|
|
1168
1225
|
}
|
|
1169
1226
|
/** Accepts a model action against the exact live WorkHub root and its durable user input. */
|
|
1170
|
-
readActiveWorkHubRequest(turnId) {
|
|
1227
|
+
async readActiveWorkHubRequest(turnId) {
|
|
1228
|
+
return (await this.readActiveWorkHubRoutingRequest(turnId))?.content;
|
|
1229
|
+
}
|
|
1230
|
+
/** Reads both user authority and the advisory routing decision of the exact live WorkHub Turn. */
|
|
1231
|
+
readActiveWorkHubRoutingRequest(turnId) {
|
|
1171
1232
|
const sessionId = WORKHUB_COORDINATION_SESSION_ID;
|
|
1172
1233
|
return this.sessionAdmission.run(sessionId, async () => {
|
|
1173
1234
|
const active = this.#executions.get(sessionId);
|
|
@@ -1182,7 +1243,12 @@ export class RootTurnCoordinator {
|
|
|
1182
1243
|
admission.execution.kind !== 'workhub_coordination' ||
|
|
1183
1244
|
header.toolProfile !== 'workhub-coordination-v2')
|
|
1184
1245
|
return undefined;
|
|
1185
|
-
return
|
|
1246
|
+
return {
|
|
1247
|
+
content: requireHostedExecutionMessageContent(admission),
|
|
1248
|
+
...(admission.execution.routingDecision
|
|
1249
|
+
? { decision: admission.execution.routingDecision }
|
|
1250
|
+
: {}),
|
|
1251
|
+
};
|
|
1186
1252
|
});
|
|
1187
1253
|
}
|
|
1188
1254
|
startRootMessage(request, context) {
|
|
@@ -1271,15 +1337,30 @@ export class RootTurnCoordinator {
|
|
|
1271
1337
|
const attachmentError = await this.attachmentValidator?.validateTurnAttachments(request.sessionId, attachments);
|
|
1272
1338
|
if (attachmentError)
|
|
1273
1339
|
return completedStart(operationConflict(attachmentError));
|
|
1274
|
-
const
|
|
1275
|
-
header.toolProfile === 'workhub-coordination-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1340
|
+
const isWorkHubV2 = request.execution.kind === 'workhub_coordination' &&
|
|
1341
|
+
header.toolProfile === 'workhub-coordination-v2';
|
|
1342
|
+
const workHubBinding = isWorkHubV2
|
|
1343
|
+
? await this.clientCapabilities?.bindSession(request.sessionId, context.connectionId, hostedExecutionRunProfile(header.toolProfile).toolNames.filter((name) => name.startsWith('mcp__')))
|
|
1344
|
+
: undefined;
|
|
1345
|
+
const binding = isWorkHubV2
|
|
1346
|
+
? workHubBinding
|
|
1347
|
+
: request.execution.kind === 'workhub_coordination' &&
|
|
1348
|
+
header.toolProfile === 'workhub-coordination-v1'
|
|
1349
|
+
? undefined
|
|
1350
|
+
: prepared.commitCapabilityBinding
|
|
1351
|
+
? await prepared.commitCapabilityBinding()
|
|
1352
|
+
: await this.clientCapabilities?.bindSession(request.sessionId, context.connectionId);
|
|
1280
1353
|
if (binding && !binding.ok) {
|
|
1281
1354
|
return completedStart(operationConflict(binding.message));
|
|
1282
1355
|
}
|
|
1356
|
+
const capabilityBinding = workHubBinding?.ok ? workHubBinding.capabilityBinding : undefined;
|
|
1357
|
+
if (isWorkHubV2 && !capabilityBinding) {
|
|
1358
|
+
return completedStart(operationUnavailable('WorkHub Desktop capability binding is unavailable'));
|
|
1359
|
+
}
|
|
1360
|
+
const freshExecution = await this.prepareFreshWorkHubExecution(header, request.turnId, canonicalContent.content, {
|
|
1361
|
+
...request.execution,
|
|
1362
|
+
...(capabilityBinding ? { capabilityBinding } : {}),
|
|
1363
|
+
}, context.inputClosedSignal);
|
|
1283
1364
|
if (!this.beginRootAdmission(reservation)) {
|
|
1284
1365
|
return completedStart(sessionBusy('Root Turn reservation is no longer current'));
|
|
1285
1366
|
}
|
|
@@ -1296,7 +1377,7 @@ export class RootTurnCoordinator {
|
|
|
1296
1377
|
// Turn kinds do not carry a user message and retain their own
|
|
1297
1378
|
// generated admission identity.
|
|
1298
1379
|
proposedUserMessageId: request.execution.kind === 'external_message' ? request.turnId : randomUUID(),
|
|
1299
|
-
execution:
|
|
1380
|
+
execution: freshExecution,
|
|
1300
1381
|
normalizedInput: canonicalContent.content,
|
|
1301
1382
|
...(request.turnOrchestration ? { turnOrchestration: request.turnOrchestration } : {}),
|
|
1302
1383
|
...(prepared.skillInvocation ? { skillInvocation: prepared.skillInvocation } : {}),
|
|
@@ -2143,15 +2224,22 @@ export class RootTurnCoordinator {
|
|
|
2143
2224
|
const turnId = randomUUID();
|
|
2144
2225
|
const header = await this.stores.sessionStore.readHeaderSnapshot(batch.sessionId);
|
|
2145
2226
|
await this.prepareFreshAgentGraphEpoch(header);
|
|
2227
|
+
const execution = await this.prepareFreshWorkHubExecution(header, turnId, batch.content, {
|
|
2228
|
+
kind: previous.descriptor.kind === 'workhub_coordination'
|
|
2229
|
+
? 'workhub_coordination'
|
|
2230
|
+
: 'external_message',
|
|
2231
|
+
inputDigest: messageContentDigest(batch.submittedContent),
|
|
2232
|
+
...(previous.descriptor.kind === 'workhub_coordination' &&
|
|
2233
|
+
previous.descriptor.capabilityBinding
|
|
2234
|
+
? { capabilityBinding: previous.descriptor.capabilityBinding }
|
|
2235
|
+
: {}),
|
|
2236
|
+
});
|
|
2146
2237
|
const admitted = await this.rootAdmissionOwner.admitRootTurn({
|
|
2147
2238
|
sessionId: batch.sessionId,
|
|
2148
2239
|
turnId,
|
|
2149
2240
|
proposedRunId: randomUUID(),
|
|
2150
2241
|
proposedUserMessageId: batch.sources.length === 1 ? batch.sources[0].messageId : null,
|
|
2151
|
-
execution
|
|
2152
|
-
kind: 'external_message',
|
|
2153
|
-
inputDigest: messageContentDigest(batch.submittedContent),
|
|
2154
|
-
},
|
|
2242
|
+
execution,
|
|
2155
2243
|
normalizedInput: batch.content,
|
|
2156
2244
|
sourceMessages: batch.sources,
|
|
2157
2245
|
admittedAt: Date.now(),
|
|
@@ -2284,13 +2372,22 @@ function throwHostedStopError(sessionId, outcome) {
|
|
|
2284
2372
|
throw new RuntimeHostedRootUnavailableError(sessionId, outcome.error.message);
|
|
2285
2373
|
}
|
|
2286
2374
|
}
|
|
2287
|
-
/**
|
|
2375
|
+
/** Compare the request identity separately from its Host-selected capability binding. */
|
|
2288
2376
|
function rootExecutionMatches(stored, incoming) {
|
|
2289
|
-
if (stored.kind === 'workhub_coordination' &&
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2377
|
+
if (stored.kind === 'workhub_coordination' && incoming.kind === 'workhub_coordination') {
|
|
2378
|
+
const { capabilityBinding: _storedBinding, routingDecision: _storedDecision, ...storedIdentity } = stored;
|
|
2379
|
+
const { capabilityBinding: _incomingBinding, routingDecision: _incomingDecision, actionId, ...incomingIdentity } = incoming;
|
|
2380
|
+
if (incoming.routingDecision === undefined) {
|
|
2381
|
+
return isDeepStrictEqual(storedIdentity, {
|
|
2382
|
+
...incomingIdentity,
|
|
2383
|
+
...(stored.actionId === undefined ? {} : { actionId }),
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
return isDeepStrictEqual({ ...storedIdentity, routingDecision: stored.routingDecision }, {
|
|
2387
|
+
...incomingIdentity,
|
|
2388
|
+
...(actionId === undefined ? {} : { actionId }),
|
|
2389
|
+
routingDecision: incoming.routingDecision,
|
|
2390
|
+
});
|
|
2294
2391
|
}
|
|
2295
2392
|
return isDeepStrictEqual(stored, incoming);
|
|
2296
2393
|
}
|
|
@@ -54,17 +54,19 @@ export class WorkHubCoordinationActionGate {
|
|
|
54
54
|
return candidateSet(await this.#effects.listSessions());
|
|
55
55
|
}
|
|
56
56
|
act(input, context, admittedTurnId) {
|
|
57
|
+
const proposal = input.proposal;
|
|
57
58
|
if (!input.userText.trim()) {
|
|
58
59
|
return Promise.reject(new WorkHubActionGateFailure('action_conflict', 'WorkHub action text is empty'));
|
|
59
60
|
}
|
|
60
61
|
if (input.delegationText !== undefined &&
|
|
61
62
|
(!input.delegationText.trim() ||
|
|
62
|
-
(
|
|
63
|
-
|
|
64
|
-
input.proposal.disposition !== 'replace'))) {
|
|
63
|
+
!('disposition' in proposal ||
|
|
64
|
+
('operation' in proposal && proposal.operation === 'correct')))) {
|
|
65
65
|
return Promise.reject(new WorkHubActionGateFailure('action_conflict', 'Invalid WorkHub delegation text'));
|
|
66
66
|
}
|
|
67
|
-
if (
|
|
67
|
+
if ('disposition' in proposal &&
|
|
68
|
+
proposal.disposition === 'create_new' &&
|
|
69
|
+
!proposal.title.trim()) {
|
|
68
70
|
return Promise.reject(new WorkHubActionGateFailure('action_conflict', 'WorkHub creation title is empty'));
|
|
69
71
|
}
|
|
70
72
|
const fingerprint = actionFingerprint(input);
|
|
@@ -106,7 +108,7 @@ export class WorkHubCoordinationActionGate {
|
|
|
106
108
|
}
|
|
107
109
|
return this.#assign(assignmentInputFromRecord(durable), context);
|
|
108
110
|
}
|
|
109
|
-
if (proposal.
|
|
111
|
+
if ('operation' in proposal && proposal.operation === 'stop') {
|
|
110
112
|
const source = await this.#stopSource(input.actionId, proposal.expects.targetSessionId);
|
|
111
113
|
const stopFingerprint = stopActionFingerprint(input, source);
|
|
112
114
|
await this.#claimAction(input.actionId, 'stop', stopFingerprint, source.delegationId);
|
|
@@ -159,7 +161,7 @@ export class WorkHubCoordinationActionGate {
|
|
|
159
161
|
});
|
|
160
162
|
return this.#stop(requested, source);
|
|
161
163
|
}
|
|
162
|
-
if (proposal.
|
|
164
|
+
if ('operation' in proposal && proposal.operation === 'resume') {
|
|
163
165
|
const source = await this.#effects.readAssignment(proposal.resumesActionId);
|
|
164
166
|
if (!source || source.targetSessionId !== proposal.expects.targetSessionId) {
|
|
165
167
|
throw new WorkHubActionGateFailure('action_conflict', 'WorkHub resume target delegation changed');
|
|
@@ -179,14 +181,14 @@ export class WorkHubCoordinationActionGate {
|
|
|
179
181
|
};
|
|
180
182
|
return this.#effects.resume({ actionId: input.actionId, source, validateFreshTarget }, context);
|
|
181
183
|
}
|
|
182
|
-
if (proposal.disposition === 'create_new') {
|
|
184
|
+
if ('disposition' in proposal && proposal.disposition === 'create_new') {
|
|
183
185
|
if (!input.create) {
|
|
184
186
|
throw new WorkHubActionGateFailure('action_conflict', 'WorkHub creation context is unavailable');
|
|
185
187
|
}
|
|
186
188
|
const sessionId = workHubCreatedSessionId(input.actionId);
|
|
187
189
|
return this.#assign(delegationAssignment(input, fingerprint, sessionId, proposal.title), context);
|
|
188
190
|
}
|
|
189
|
-
if (proposal.
|
|
191
|
+
if ('operation' in proposal && proposal.operation === 'correct') {
|
|
190
192
|
const replaced = await this.#effects.readAssignment(proposal.replacesActionId);
|
|
191
193
|
if (!replaced) {
|
|
192
194
|
throw new WorkHubActionGateFailure('action_conflict', 'WorkHub can replace only a durable delegation it owns');
|
|
@@ -341,7 +343,7 @@ export class WorkHubCoordinationActionGate {
|
|
|
341
343
|
}
|
|
342
344
|
}
|
|
343
345
|
async #replacementAssignment(input, replaced) {
|
|
344
|
-
if (input.proposal.
|
|
346
|
+
if (!('operation' in input.proposal) || input.proposal.operation !== 'correct') {
|
|
345
347
|
throw new WorkHubActionGateFailure('action_conflict', 'Invalid WorkHub replacement');
|
|
346
348
|
}
|
|
347
349
|
const target = input.proposal.target;
|
|
@@ -465,7 +467,8 @@ export class WorkHubCoordinationActionGate {
|
|
|
465
467
|
}
|
|
466
468
|
}
|
|
467
469
|
async #assertReplacementReplayTarget(input, targetSessionId) {
|
|
468
|
-
if (input.proposal
|
|
470
|
+
if (!('operation' in input.proposal) ||
|
|
471
|
+
input.proposal.operation !== 'correct' ||
|
|
469
472
|
input.proposal.target.disposition !== 'delegate_existing' ||
|
|
470
473
|
input.candidateSetId === undefined) {
|
|
471
474
|
return;
|
|
@@ -581,8 +584,7 @@ function candidateRef(candidateSetId, sessionId) {
|
|
|
581
584
|
}
|
|
582
585
|
function delegationAssignment(input, actionFingerprint, targetSessionId, targetSessionName) {
|
|
583
586
|
const create = input.create;
|
|
584
|
-
if (input.proposal
|
|
585
|
-
input.proposal.disposition !== 'create_new') {
|
|
587
|
+
if (!('disposition' in input.proposal)) {
|
|
586
588
|
throw new WorkHubActionGateFailure('action_conflict', 'WorkHub local action cannot create a delegation intent');
|
|
587
589
|
}
|
|
588
590
|
const base = {
|
|
@@ -636,34 +638,41 @@ function digest(value) {
|
|
|
636
638
|
return `sha256:${hash(JSON.stringify(value))}`;
|
|
637
639
|
}
|
|
638
640
|
function actionFingerprint(input) {
|
|
639
|
-
|
|
641
|
+
const common = {
|
|
640
642
|
userText: input.userText,
|
|
641
643
|
...(input.attachments ? { attachments: input.attachments } : {}),
|
|
642
644
|
...(input.newWorkDefaults ? { newWorkDefaults: input.newWorkDefaults } : {}),
|
|
643
645
|
...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
646
|
+
};
|
|
647
|
+
const proposal = input.proposal;
|
|
648
|
+
if ('disposition' in proposal) {
|
|
649
|
+
return digest({
|
|
650
|
+
...common,
|
|
651
|
+
disposition: proposal.disposition,
|
|
652
|
+
...(proposal.disposition === 'delegate_existing'
|
|
653
|
+
? { candidateRef: proposal.candidateRef }
|
|
654
|
+
: { title: proposal.title, workspace: input.create?.workspace }),
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
if (proposal.operation === 'correct') {
|
|
658
|
+
return digest({
|
|
659
|
+
...common,
|
|
660
|
+
disposition: 'replace',
|
|
661
|
+
replacesActionId: proposal.replacesActionId,
|
|
662
|
+
target: proposal.target,
|
|
663
|
+
...(proposal.target.disposition === 'create_new'
|
|
664
|
+
? { workspace: input.create?.workspace }
|
|
665
|
+
: {}),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
// Preserve durable action fingerprints across the transient proposal rename.
|
|
669
|
+
return digest({
|
|
670
|
+
...common,
|
|
671
|
+
disposition: proposal.operation === 'stop' ? 'stop_work' : 'resume_work',
|
|
663
672
|
});
|
|
664
673
|
}
|
|
665
674
|
function replacementActionFingerprint(input, targetSessionId) {
|
|
666
|
-
if (input.proposal.
|
|
675
|
+
if (!('operation' in input.proposal) || input.proposal.operation !== 'correct') {
|
|
667
676
|
throw new WorkHubActionGateFailure('action_conflict', 'Invalid WorkHub replacement replay');
|
|
668
677
|
}
|
|
669
678
|
return digest({
|
|
@@ -671,7 +680,7 @@ function replacementActionFingerprint(input, targetSessionId) {
|
|
|
671
680
|
...(input.attachments ? { attachments: input.attachments } : {}),
|
|
672
681
|
...(input.newWorkDefaults ? { newWorkDefaults: input.newWorkDefaults } : {}),
|
|
673
682
|
...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
|
|
674
|
-
disposition:
|
|
683
|
+
disposition: 'replace',
|
|
675
684
|
replacesActionId: input.proposal.replacesActionId,
|
|
676
685
|
target: {
|
|
677
686
|
disposition: input.proposal.target.disposition,
|
|
@@ -683,7 +692,7 @@ function replacementActionFingerprint(input, targetSessionId) {
|
|
|
683
692
|
});
|
|
684
693
|
}
|
|
685
694
|
function stopActionFingerprint(input, source) {
|
|
686
|
-
if (input.proposal.
|
|
695
|
+
if (!('operation' in input.proposal) || input.proposal.operation !== 'stop') {
|
|
687
696
|
throw new WorkHubActionGateFailure('action_conflict', 'Invalid WorkHub stop replay');
|
|
688
697
|
}
|
|
689
698
|
return digest({
|