maka-agent 0.2.0-dev.43.20260919 → 0.2.0-dev.44.20260920
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/LICENSE +12 -6
- package/dist/mcp-capability-provider.js +7 -0
- package/dist/runtime-host-tui-command.js +1 -1
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/chat-model-choice.js +3 -0
- package/node_modules/@maka/core/dist/llm-connections.js +3 -21
- package/node_modules/@maka/core/dist/model-catalog.js +8 -20
- package/node_modules/@maka/core/dist/model-metadata.generated.js +304 -304
- package/node_modules/@maka/core/dist/model-thinking.js +16 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +0 -1
- package/node_modules/@maka/core/dist/provider-registry.js +7 -51
- package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +7 -0
- package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +14 -1
- package/node_modules/@maka/core/dist/settings.js +2 -3
- package/node_modules/@maka/mcp/dist/index.js +22 -0
- package/node_modules/@maka/mcp/dist/oauth.js +4 -2
- package/node_modules/@maka/mcp/dist/tool-progress.js +45 -0
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +2 -3
- package/node_modules/@maka/runtime/dist/session-manager.js +1 -44
- package/node_modules/@maka/runtime/dist/test-connection.js +3 -66
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +44 -9
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +33 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +10 -0
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +0 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +0 -33
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +31 -104
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +0 -2
- package/node_modules/@maka/runtime-host/dist/server/interactive-turn-coordinator.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +46 -28
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +5 -16
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +21 -12
- package/node_modules/@maka/runtime-host/dist/server/session-turn-access-request-coordinator.js +7 -17
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +0 -62
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +0 -3
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +0 -1
- package/package.json +1 -1
|
@@ -28,6 +28,18 @@ export class RuntimeHostSubscriptionError extends Error {
|
|
|
28
28
|
this.name = 'RuntimeHostSubscriptionError';
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
export class SessionRemovedSubscriptionError extends Error {
|
|
32
|
+
name = 'SessionRemovedSubscriptionError';
|
|
33
|
+
}
|
|
34
|
+
export function subscriptionClosedError(reason) {
|
|
35
|
+
if (reason === 'session_removed') {
|
|
36
|
+
return new SessionRemovedSubscriptionError('Runtime Host Session was removed while it was observed');
|
|
37
|
+
}
|
|
38
|
+
if (reason === 'access_revoked') {
|
|
39
|
+
return new SessionRemovedSubscriptionError('Access to the shared Runtime Host Session was revoked');
|
|
40
|
+
}
|
|
41
|
+
return new RuntimeHostSubscriptionError('slow_consumer', 'Runtime Host Session subscription closed for a slow consumer');
|
|
42
|
+
}
|
|
31
43
|
function errorMessage(error) {
|
|
32
44
|
return error instanceof Error ? error.message : String(error);
|
|
33
45
|
}
|
|
@@ -42,6 +54,16 @@ export class ClientSessionSubscription {
|
|
|
42
54
|
#readyTask;
|
|
43
55
|
#readTranscriptPage;
|
|
44
56
|
#expectedSessionId;
|
|
57
|
+
get transcriptWatermark() {
|
|
58
|
+
return this.#latestTranscriptThroughSequence;
|
|
59
|
+
}
|
|
60
|
+
get deathCause() {
|
|
61
|
+
// #closedReason is recorded at accept()-time, before #terminalError can
|
|
62
|
+
// exist — it is always the authoritative death statement.
|
|
63
|
+
return this.#closedReason === undefined
|
|
64
|
+
? this.#terminalError
|
|
65
|
+
: subscriptionClosedError(this.#closedReason);
|
|
66
|
+
}
|
|
45
67
|
#queue = [];
|
|
46
68
|
#ptyListeners = new Set();
|
|
47
69
|
#sessionDomainListeners = new Set();
|
|
@@ -50,6 +72,7 @@ export class ClientSessionSubscription {
|
|
|
50
72
|
#latestProjectionRevision;
|
|
51
73
|
#waiting;
|
|
52
74
|
#terminalError;
|
|
75
|
+
#closedReason;
|
|
53
76
|
#done = false;
|
|
54
77
|
#doneAfterQueue = false;
|
|
55
78
|
#closing = false;
|
|
@@ -237,7 +260,9 @@ export class ClientSessionSubscription {
|
|
|
237
260
|
}
|
|
238
261
|
}
|
|
239
262
|
#assertTranscriptReadable() {
|
|
240
|
-
if (this.#
|
|
263
|
+
if (this.#terminalError)
|
|
264
|
+
throw this.#terminalError;
|
|
265
|
+
if (this.#closing || this.#done) {
|
|
241
266
|
throw new RuntimeHostSubscriptionError('connection_closed', 'Session subscription closed during transcript loading');
|
|
242
267
|
}
|
|
243
268
|
}
|
|
@@ -318,9 +343,14 @@ export class ClientSessionSubscription {
|
|
|
318
343
|
}
|
|
319
344
|
}
|
|
320
345
|
}
|
|
321
|
-
|
|
322
|
-
|
|
346
|
+
if (frame.kind === 'subscription.closed') {
|
|
347
|
+
// Record the reason before the offer: a full client queue makes #offer
|
|
348
|
+
// throw 'slow_consumer', which would otherwise discard the real reason
|
|
349
|
+
// the Host gave for closing this subscription.
|
|
350
|
+
this.#closedReason = frame.reason;
|
|
323
351
|
this.#doneAfterQueue = true;
|
|
352
|
+
}
|
|
353
|
+
this.#offer(frame);
|
|
324
354
|
}
|
|
325
355
|
finish() {
|
|
326
356
|
this.#ptyListeners.clear();
|
|
@@ -62,7 +62,13 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
62
62
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
63
63
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
64
64
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
65
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
65
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 169;
|
|
66
|
+
// 169: The message execution query reports an identity the Host can prove was
|
|
67
|
+
// never admitted as a positive `not_admitted` resolution instead of omitting
|
|
68
|
+
// it, so silence stops meaning both "not admitted" and "cannot say yet".
|
|
69
|
+
// Epoch-168 peers reject the new state as an invalid frame.
|
|
70
|
+
// 167: Removed the turn.regenerate operation. Older peers can no longer
|
|
71
|
+
// safely interoperate because they may submit or advertise that operation.
|
|
66
72
|
// 166: Connection usage reads add an operation, an accepted availability reason
|
|
67
73
|
// (`unauthorized`), a report field (`partiallyUnauthorized`), and a bounded
|
|
68
74
|
// window list. Peers older than this epoch take the added operation for an
|
|
@@ -200,6 +200,16 @@ function decodeTurnMessageExecutionQueryResult(value) {
|
|
|
200
200
|
state: 'cancelled',
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
|
+
if (resolution.state === 'not_admitted') {
|
|
204
|
+
assertExactKeys(resolution, 'turn.message.execution.query not_admitted resolution', [
|
|
205
|
+
'messageId',
|
|
206
|
+
'state',
|
|
207
|
+
]);
|
|
208
|
+
return {
|
|
209
|
+
messageId: requireEntityId(resolution.messageId, 'messageId'),
|
|
210
|
+
state: 'not_admitted',
|
|
211
|
+
};
|
|
212
|
+
}
|
|
203
213
|
if (resolution.state === 'owned') {
|
|
204
214
|
assertExactKeys(resolution, 'turn.message.execution.query owned resolution', [
|
|
205
215
|
'messageId',
|
|
@@ -273,7 +273,7 @@ export function decodeSessionCreateInput(value) {
|
|
|
273
273
|
...(target ? { modelTarget: target } : {}),
|
|
274
274
|
...(executorId ? { executorId } : {}),
|
|
275
275
|
...(Object.hasOwn(input, 'thinkingLevel')
|
|
276
|
-
? { thinkingLevel: thinkingLevel(input.thinkingLevel) }
|
|
276
|
+
? { thinkingLevel: input.thinkingLevel === null ? null : thinkingLevel(input.thinkingLevel) }
|
|
277
277
|
: {}),
|
|
278
278
|
...(Object.hasOwn(input, 'toolProfile')
|
|
279
279
|
? { toolProfile: sessionToolProfile(input.toolProfile) }
|
|
@@ -96,27 +96,6 @@ export const TURN_OPERATION_SPECS = {
|
|
|
96
96
|
decodeInput: decodeTurnStopInput,
|
|
97
97
|
decodeOutput: decodeTurnSnapshot,
|
|
98
98
|
}),
|
|
99
|
-
'turn.regenerate': defineOperation({
|
|
100
|
-
mode: 'command',
|
|
101
|
-
availability: 'ready',
|
|
102
|
-
errors: [
|
|
103
|
-
'host_not_ready',
|
|
104
|
-
'host_draining',
|
|
105
|
-
'operation_unavailable',
|
|
106
|
-
'not_found',
|
|
107
|
-
'session_archived',
|
|
108
|
-
'session_busy',
|
|
109
|
-
'operation_conflict',
|
|
110
|
-
'internal_failure',
|
|
111
|
-
],
|
|
112
|
-
decodeInput: decodeTurnRegenerateInput,
|
|
113
|
-
decodeOutput: decodeTurnSnapshot,
|
|
114
|
-
assertOutputForInput: (input, output) => {
|
|
115
|
-
if (input.sessionId !== output.sessionId || input.turnId !== output.turnId) {
|
|
116
|
-
throw invalidProtocolFrame('Turn regenerate changed operation identity');
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
}),
|
|
120
99
|
'turn.resume.query': defineOperation({
|
|
121
100
|
mode: 'query',
|
|
122
101
|
availability: 'ready',
|
|
@@ -317,18 +296,6 @@ function decodeTurnStopInput(value) {
|
|
|
317
296
|
runId: requireEntityId(record.runId, 'runId'),
|
|
318
297
|
};
|
|
319
298
|
}
|
|
320
|
-
function decodeTurnRegenerateInput(value) {
|
|
321
|
-
const record = requireExactRecord(value, 'turn.regenerate input', [
|
|
322
|
-
'sessionId',
|
|
323
|
-
'sourceTurnId',
|
|
324
|
-
'turnId',
|
|
325
|
-
]);
|
|
326
|
-
return {
|
|
327
|
-
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
328
|
-
sourceTurnId: requireEntityId(record.sourceTurnId, 'sourceTurnId'),
|
|
329
|
-
turnId: requireEntityId(record.turnId, 'turnId'),
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
299
|
function decodeTurnResumeQueryInput(value) {
|
|
333
300
|
const record = requireShapedRecord(value, 'turn.resume.query input', ['sessionId'], ['sourceRunId', 'expectedRuntimeEventHighWater']);
|
|
334
301
|
if (record.expectedRuntimeEventHighWater !== undefined && record.sourceRunId === undefined) {
|
|
@@ -48,6 +48,8 @@ const PERSISTED_GRANT_MIGRATIONS = new Map([
|
|
|
48
48
|
// Retired with the second execution-inspection contract; no shipped surface
|
|
49
49
|
// called execution.inspect.resolve.
|
|
50
50
|
['execution.inspect.resolve', { kind: 'release' }],
|
|
51
|
+
// Retired in favor of editing and resending the original user message.
|
|
52
|
+
['turn.regenerate', { kind: 'release' }],
|
|
51
53
|
// Direct WorkHub actions and record writes were retired. Their grants do not
|
|
52
54
|
// authorize actFromTurn, which requires the active coordination Turn.
|
|
53
55
|
['workhub.coordination.act', { kind: 'release' }],
|
|
@@ -19,70 +19,43 @@
|
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
20
|
import { readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
21
21
|
import { join } from 'node:path';
|
|
22
|
-
import { OPENCODE_FREE_DEFAULT_MODEL, defaultEnabledModelIdsWhenOmitted, } from '@maka/core/llm-connections';
|
|
23
22
|
const JOURNAL_FILE = '.runtime-host-bootstrap.json';
|
|
24
|
-
/**
|
|
25
|
-
* What the seeded OpenCode Free connection starts with — the provider's own
|
|
26
|
-
* declaration of the models a fresh connection to it enables, so the seed and
|
|
27
|
-
* a hand-added connection cannot drift apart.
|
|
28
|
-
*/
|
|
29
|
-
const OPENCODE_FREE_SEED_MODEL_IDS = defaultEnabledModelIdsWhenOmitted('opencode-free') ?? [];
|
|
30
|
-
/** Establishes a usable first target before Runtime Host accepts clients. */
|
|
23
|
+
/** Imports a user's environment credential on first start, before accepting clients. */
|
|
31
24
|
export async function ensureBootstrapRuntimePolicy(input) {
|
|
32
25
|
if (input.initialization)
|
|
33
26
|
await initializeHostedPolicy(input.stores, input.initialization);
|
|
34
27
|
const journalPath = join(input.workspaceRoot, JOURNAL_FILE);
|
|
35
28
|
const resuming = await readJournal(journalPath);
|
|
36
29
|
const initialCatalog = await input.stores.connectionCatalog.getSnapshot();
|
|
37
|
-
if (initialCatalog.connections.length > 0)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
slug: 'opencode-free',
|
|
44
|
-
providerType: 'opencode-free',
|
|
45
|
-
legacyEnabledModelIds: LEGACY_OPENCODE_FREE_SEEDS,
|
|
46
|
-
enabledModelIds: OPENCODE_FREE_SEED_MODEL_IDS,
|
|
47
|
-
defaultModelId: OPENCODE_FREE_DEFAULT_MODEL,
|
|
48
|
-
retiredModelIds: retiredOpencodeFreeModelIds(),
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
input.onDeferredError?.(error);
|
|
53
|
-
}
|
|
30
|
+
if (!resuming && initialCatalog.connections.length > 0)
|
|
31
|
+
return;
|
|
32
|
+
const seed = bootstrapSeed(input.environment ?? process.env);
|
|
33
|
+
if (!seed || initialCatalog.connections.some((connection) => connection.slug !== seed.slug)) {
|
|
34
|
+
await rm(journalPath, { force: true });
|
|
35
|
+
return;
|
|
54
36
|
}
|
|
55
|
-
if (!resuming)
|
|
56
|
-
if (initialCatalog.connections.length > 0)
|
|
57
|
-
return;
|
|
37
|
+
if (!resuming)
|
|
58
38
|
await writeJournal(journalPath);
|
|
59
|
-
|
|
60
|
-
const seeds = bootstrapSeeds(input.environment ?? process.env);
|
|
61
|
-
const { connection: free } = await ensureConnection(input.stores, seeds[0]);
|
|
62
|
-
await setDefaultIfMissing(input.stores, free);
|
|
63
|
-
await rm(journalPath, { force: true });
|
|
39
|
+
let connection;
|
|
64
40
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (ensured.created)
|
|
75
|
-
await removeFailedBootstrapConnection(input.stores, connection);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
preferred = connection;
|
|
41
|
+
const ensured = await ensureConnection(input.stores, seed);
|
|
42
|
+
connection = ensured.connection;
|
|
43
|
+
try {
|
|
44
|
+
await ensureCredential(input.stores, connection, seed.secret);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (ensured.created)
|
|
48
|
+
await removeFailedBootstrapConnection(input.stores, ensured.connection);
|
|
49
|
+
throw error;
|
|
80
50
|
}
|
|
81
|
-
await replaceBootstrapDefault(input.stores, free, preferred);
|
|
82
51
|
}
|
|
83
52
|
catch (error) {
|
|
84
53
|
input.onDeferredError?.(error);
|
|
54
|
+
await rm(journalPath, { force: true });
|
|
55
|
+
return;
|
|
85
56
|
}
|
|
57
|
+
await setDefaultIfMissing(input.stores, connection);
|
|
58
|
+
await rm(journalPath, { force: true });
|
|
86
59
|
}
|
|
87
60
|
async function initializeHostedPolicy(stores, input) {
|
|
88
61
|
if (input.incognito !== true ||
|
|
@@ -147,47 +120,39 @@ async function initializeHostedPolicy(stores, input) {
|
|
|
147
120
|
if (result.kind !== 'committed')
|
|
148
121
|
throw new Error('Hosted proxy initialization failed');
|
|
149
122
|
}
|
|
150
|
-
function
|
|
151
|
-
const seeds = [
|
|
152
|
-
{
|
|
153
|
-
slug: 'opencode-free',
|
|
154
|
-
name: 'OpenCode Free',
|
|
155
|
-
providerType: 'opencode-free',
|
|
156
|
-
enabledModelIds: OPENCODE_FREE_SEED_MODEL_IDS,
|
|
157
|
-
},
|
|
158
|
-
];
|
|
123
|
+
function bootstrapSeed(environment) {
|
|
159
124
|
const deepseek = environment.DEEPSEEK_API_KEY?.trim();
|
|
160
125
|
const anthropic = environment.ANTHROPIC_API_KEY?.trim();
|
|
161
126
|
const openai = environment.OPENAI_API_KEY?.trim();
|
|
162
127
|
if (deepseek) {
|
|
163
|
-
|
|
128
|
+
return {
|
|
164
129
|
slug: 'env-deepseek',
|
|
165
130
|
name: 'DeepSeek (env)',
|
|
166
131
|
providerType: 'deepseek',
|
|
167
132
|
enabledModelIds: ['deepseek-v4-flash'],
|
|
168
133
|
baseUrl: environment.DEEPSEEK_BASE_URL?.trim() || 'https://api.deepseek.com',
|
|
169
134
|
secret: deepseek,
|
|
170
|
-
}
|
|
135
|
+
};
|
|
171
136
|
}
|
|
172
137
|
else if (anthropic) {
|
|
173
|
-
|
|
138
|
+
return {
|
|
174
139
|
slug: 'env-anthropic',
|
|
175
140
|
name: 'Anthropic (env)',
|
|
176
141
|
providerType: 'anthropic',
|
|
177
142
|
enabledModelIds: ['claude-sonnet-4-5-20250929'],
|
|
178
143
|
secret: anthropic,
|
|
179
|
-
}
|
|
144
|
+
};
|
|
180
145
|
}
|
|
181
146
|
else if (openai) {
|
|
182
|
-
|
|
147
|
+
return {
|
|
183
148
|
slug: 'env-openai',
|
|
184
149
|
name: 'OpenAI (env)',
|
|
185
150
|
providerType: 'openai',
|
|
186
151
|
enabledModelIds: ['gpt-4o-mini'],
|
|
187
152
|
secret: openai,
|
|
188
|
-
}
|
|
153
|
+
};
|
|
189
154
|
}
|
|
190
|
-
return
|
|
155
|
+
return undefined;
|
|
191
156
|
}
|
|
192
157
|
async function ensureConnection(stores, seed) {
|
|
193
158
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
@@ -219,24 +184,6 @@ async function ensureConnection(stores, seed) {
|
|
|
219
184
|
}
|
|
220
185
|
throw new Error(`Bootstrap Connection could not be created: ${seed.slug}`);
|
|
221
186
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Every opencode-free inventory a past release seeded, verbatim. A row still
|
|
224
|
-
* equal to one of these is provably system-owned and may follow the current
|
|
225
|
-
* seed; any other value is a user selection and is never touched. Every
|
|
226
|
-
* release that changes the derived seed must append the previous value here,
|
|
227
|
-
* or rows it planted read as user selections forever. (This exact-match
|
|
228
|
-
* enumeration is deliberately lossy; the versioned seed policy discussed in
|
|
229
|
-
* #3354 is the durable replacement.)
|
|
230
|
-
*/
|
|
231
|
-
const LEGACY_OPENCODE_FREE_SEEDS = [
|
|
232
|
-
['big-pickle'],
|
|
233
|
-
['nemotron-3-ultra-free'],
|
|
234
|
-
['nemotron-3-ultra-free', 'mimo-v2.5-free', 'deepseek-v4-flash-free'],
|
|
235
|
-
];
|
|
236
|
-
function retiredOpencodeFreeModelIds() {
|
|
237
|
-
const current = new Set(OPENCODE_FREE_SEED_MODEL_IDS);
|
|
238
|
-
return [...new Set(LEGACY_OPENCODE_FREE_SEEDS.flat())].filter((id) => !current.has(id));
|
|
239
|
-
}
|
|
240
187
|
async function removeFailedBootstrapConnection(stores, connection) {
|
|
241
188
|
const removed = await stores.connectionCatalog.remove({
|
|
242
189
|
expected: { connectionId: connection.connectionId, revision: connection.revision },
|
|
@@ -270,33 +217,13 @@ async function setDefaultIfMissing(stores, connection) {
|
|
|
270
217
|
expectedCatalogRevision: catalog.revision,
|
|
271
218
|
target: {
|
|
272
219
|
connectionId: connection.connectionId,
|
|
273
|
-
modelId:
|
|
220
|
+
modelId: connection.enabledModelIds[0],
|
|
274
221
|
},
|
|
275
222
|
});
|
|
276
223
|
if (committed.kind !== 'committed') {
|
|
277
224
|
throw new Error(`Bootstrap default target could not be stored: ${committed.kind}`);
|
|
278
225
|
}
|
|
279
226
|
}
|
|
280
|
-
async function replaceBootstrapDefault(stores, free, preferred) {
|
|
281
|
-
if (preferred.connectionId === free.connectionId || !preferred.enabled)
|
|
282
|
-
return;
|
|
283
|
-
const catalog = await stores.connectionCatalog.getSnapshot();
|
|
284
|
-
const current = catalog.defaultTarget;
|
|
285
|
-
if (current !== null &&
|
|
286
|
-
(current.connectionId !== free.connectionId || current.modelId !== OPENCODE_FREE_DEFAULT_MODEL)) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
const modelId = preferred.enabledModelIds[0];
|
|
290
|
-
if (!modelId)
|
|
291
|
-
return;
|
|
292
|
-
const committed = await stores.connectionCatalog.setDefaultTarget({
|
|
293
|
-
expectedCatalogRevision: catalog.revision,
|
|
294
|
-
target: { connectionId: preferred.connectionId, modelId },
|
|
295
|
-
});
|
|
296
|
-
if (committed.kind !== 'committed') {
|
|
297
|
-
throw new Error(`Bootstrap preferred target could not be stored: ${committed.kind}`);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
227
|
async function readJournal(path) {
|
|
301
228
|
let contents;
|
|
302
229
|
try {
|
|
@@ -1484,7 +1484,6 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1484
1484
|
const interactiveTurns = new HostInteractiveTurnCoordinator({
|
|
1485
1485
|
executions: coordinator,
|
|
1486
1486
|
turns: stores.agentRunStore,
|
|
1487
|
-
runtime: manager,
|
|
1488
1487
|
});
|
|
1489
1488
|
// Compile-time guarantee that the three Turn coordinators together cover
|
|
1490
1489
|
// every key in TURN_OPERATION_SPECS. Domain composition seeds all domain
|
|
@@ -1500,7 +1499,6 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1500
1499
|
? new SessionTurnAccessRequestCoordinator({
|
|
1501
1500
|
authority: context.sessionAccessAuthority,
|
|
1502
1501
|
startTurn: interactiveTurns.handlers['turn.start'],
|
|
1503
|
-
regenerateTurn: interactiveTurns.handlers['turn.regenerate'],
|
|
1504
1502
|
hostEpoch: context.hostEpoch,
|
|
1505
1503
|
acquireResidency: () => context.acquireResidency('collaboration-turn-request'),
|
|
1506
1504
|
requestDrain: context.requestDrain,
|
|
@@ -26,19 +26,16 @@ const EMPTY_SKILL_INVOCATION = {
|
|
|
26
26
|
failed: [],
|
|
27
27
|
receipts: [],
|
|
28
28
|
};
|
|
29
|
-
/** Owns Interactive Turn start
|
|
29
|
+
/** Owns Interactive Turn start wire semantics. */
|
|
30
30
|
export class HostInteractiveTurnCoordinator {
|
|
31
31
|
handlers = {
|
|
32
32
|
'turn.start': (input, context) => this.#start(input, context),
|
|
33
|
-
'turn.regenerate': (input, context) => this.#regenerate(input, context),
|
|
34
33
|
};
|
|
35
34
|
#executions;
|
|
36
35
|
#turns;
|
|
37
|
-
#runtime;
|
|
38
36
|
constructor(options) {
|
|
39
37
|
this.#executions = options.executions;
|
|
40
38
|
this.#turns = options.turns;
|
|
41
|
-
this.#runtime = options.runtime;
|
|
42
39
|
}
|
|
43
40
|
async #start(input, context) {
|
|
44
41
|
const content = normalizeMessageContent(input.content);
|
|
@@ -128,18 +125,6 @@ export class HostInteractiveTurnCoordinator {
|
|
|
128
125
|
},
|
|
129
126
|
};
|
|
130
127
|
}
|
|
131
|
-
#regenerate(input, context) {
|
|
132
|
-
if (input.sourceTurnId === input.turnId) {
|
|
133
|
-
return Promise.resolve(operationConflict('Regenerate source and target Turn identities must differ'));
|
|
134
|
-
}
|
|
135
|
-
return this.#executions.startInteractiveRootMessage({
|
|
136
|
-
sessionId: input.sessionId,
|
|
137
|
-
turnId: input.turnId,
|
|
138
|
-
execution: { kind: 'regenerate', sourceTurnId: input.sourceTurnId },
|
|
139
|
-
archivedMessage: 'Cannot regenerate a Turn in an archived Session',
|
|
140
|
-
prepareContent: async () => (await this.#runtime.prepareRegenerateTurn(input.sessionId, input.sourceTurnId)).content,
|
|
141
|
-
}, context);
|
|
142
|
-
}
|
|
143
128
|
}
|
|
144
129
|
function rejected(message) {
|
|
145
130
|
return { kind: 'rejected', outcome: operationConflict(message) };
|
|
@@ -107,35 +107,53 @@ export class HostMessageCoordinator {
|
|
|
107
107
|
}
|
|
108
108
|
return success({ cancelledMessageIds });
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
queryMessageExecutions(input) {
|
|
111
|
+
// Enter the Session admission the way every other admission reader does.
|
|
112
|
+
// `not_admitted` claims that no epoch ever admitted this identity, and it
|
|
113
|
+
// is only sound while no admission write can be in flight. WorkHub writes
|
|
114
|
+
// admission rows without an in-memory submit to observe, so the gate —
|
|
115
|
+
// not `#pendingSubmits` alone — is what makes the read atomic.
|
|
116
|
+
return this.#sessionAdmission.runOrJoin(input.sessionId, async () => {
|
|
117
|
+
const resolutions = [];
|
|
118
|
+
for (const messageId of input.messageIds) {
|
|
119
|
+
const disposition = await this.#resolveMessageExecution(input.sessionId, messageId);
|
|
120
|
+
if (disposition.kind === 'owned_root' || disposition.kind === 'shared_turn') {
|
|
121
|
+
// This read projects current execution, including safe-boundary
|
|
122
|
+
// continuations. The Message's durable admission ownership is unchanged.
|
|
123
|
+
const latest = await this.#root.readLatestRootTurnLineage({
|
|
124
|
+
sessionId: input.sessionId,
|
|
125
|
+
turnId: disposition.turnId,
|
|
126
|
+
runId: disposition.runId,
|
|
127
|
+
});
|
|
128
|
+
resolutions.push({
|
|
129
|
+
messageId,
|
|
130
|
+
state: 'owned',
|
|
131
|
+
turnId: latest.turnId,
|
|
132
|
+
runId: latest.runId,
|
|
133
|
+
});
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (disposition.kind === 'cancelled') {
|
|
137
|
+
resolutions.push({ messageId, state: 'cancelled' });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (disposition.kind === 'pending') {
|
|
141
|
+
resolutions.push({ messageId, state: 'pending' });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
// `recovering` means no durable receipt, steering proof, cancellation
|
|
145
|
+
// tombstone, or pending admission names this identity. Under the
|
|
146
|
+
// Session gate no admission write is in flight, so that silence is
|
|
147
|
+
// itself the proof: nothing in this epoch — or any prior one, since a
|
|
148
|
+
// stale epoch's submit can never commit here — ever admitted it.
|
|
149
|
+
// Report that fact positively instead of omitting the identity, so a
|
|
150
|
+
// missing entry stops meaning both "not admitted" and "cannot say yet".
|
|
151
|
+
if (this.#pendingSubmits.has(operationKey(input.sessionId, messageId)))
|
|
152
|
+
continue;
|
|
153
|
+
resolutions.push({ messageId, state: 'not_admitted' });
|
|
136
154
|
}
|
|
137
|
-
|
|
138
|
-
|
|
155
|
+
return success({ resolutions });
|
|
156
|
+
});
|
|
139
157
|
}
|
|
140
158
|
/**
|
|
141
159
|
* Cancels exactly one durable pending Message, or returns the Turn that has
|
|
@@ -27,7 +27,7 @@ import { decodeSkillInvocationResult, } from '@maka/core/skill-invocation';
|
|
|
27
27
|
import { agentGraphIdForRootSession } from '@maka/runtime/stream-graph-coordinator';
|
|
28
28
|
import { RuntimeHostedRootConflictError, RuntimeHostedRootUnavailableError, RuntimeMessageAuthorityInvariantError, } from '@maka/runtime/message-authority';
|
|
29
29
|
import { isShutdownCancelledInteractionAdmission, RuntimeInteractionAdmissionRejectedError, RuntimeInteractionFailStopError, RuntimeInteractionInvariantError, } from '@maka/runtime/interaction-authority';
|
|
30
|
-
import { normalizeStopSessionSource,
|
|
30
|
+
import { normalizeStopSessionSource, } from '@maka/runtime/session-manager';
|
|
31
31
|
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';
|
|
@@ -1422,21 +1422,10 @@ export class RootTurnCoordinator {
|
|
|
1422
1422
|
return { kind: 'ready', content: request.content };
|
|
1423
1423
|
if ('prepareFreshContent' in request)
|
|
1424
1424
|
return request.prepareFreshContent(lease);
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
catch (error) {
|
|
1432
|
-
if (error instanceof RuntimeRegenerateTurnError) {
|
|
1433
|
-
return {
|
|
1434
|
-
kind: 'rejected',
|
|
1435
|
-
outcome: error.code === 'not_found' ? notFound(error.message) : operationConflict(error.message),
|
|
1436
|
-
};
|
|
1437
|
-
}
|
|
1438
|
-
throw error;
|
|
1439
|
-
}
|
|
1425
|
+
return {
|
|
1426
|
+
kind: 'ready',
|
|
1427
|
+
content: normalizeMessageContent(await request.prepareContent()),
|
|
1428
|
+
};
|
|
1440
1429
|
}
|
|
1441
1430
|
async queryTurnResume(input, context) {
|
|
1442
1431
|
if (isWorkHubCoordinationSessionId(input.sessionId)) {
|