maka-agent 0.2.0-dev.52.20260926 → 0.2.0-dev.53.20260927
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/activation-command.js +11 -3
- package/dist/pi-tui-mcp-status.js +73 -5
- package/dist/pi-tui-runner.js +1 -1
- package/dist/runtime-host-run-command.js +39 -6
- package/dist/runtime-host-run-mcp.js +161 -0
- package/dist/runtime-host-session-driver.js +22 -2
- package/dist/tui-copy-catalog.js +6 -0
- package/dist/tui-mcp-control.js +11 -2
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -0
- package/node_modules/@maka/core/dist/events.js +11 -0
- package/node_modules/@maka/core/dist/provider-registry.js +11 -2
- package/node_modules/@maka/core/dist/turn-origin.js +6 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +1 -5
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +80 -24
- package/node_modules/@maka/runtime/dist/bots/proxied-fetch.js +5 -4
- package/node_modules/@maka/runtime/dist/computer-use-tools.js +136 -100
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +4 -0
- package/node_modules/@maka/runtime/dist/conversation-copy.js +51 -205
- package/node_modules/@maka/runtime/dist/edit-replace.js +7 -7
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +4 -20
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +17 -28
- package/node_modules/@maka/runtime/dist/format-json.js +39 -0
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +1 -6
- package/node_modules/@maka/runtime/dist/image-file.js +22 -14
- package/node_modules/@maka/runtime/dist/model-adapter.js +18 -2
- package/node_modules/@maka/runtime/dist/model-history.js +201 -3
- package/node_modules/@maka/runtime/dist/network/abortable-connector.js +55 -0
- package/node_modules/@maka/runtime/dist/network/proxy-dispatcher.js +72 -37
- package/node_modules/@maka/runtime/dist/network/proxy-test.js +1 -1
- package/node_modules/@maka/runtime/dist/network/scoped-fetch-transport.js +7 -2
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -3
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +36 -8
- package/node_modules/@maka/runtime/dist/recovery-resolver.js +1 -91
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +44 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +54 -58
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +84 -2
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +63 -51
- package/node_modules/@maka/runtime/dist/workspace-executor.js +5 -6
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +27 -6
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +4 -1
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +9 -9
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +9 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +12 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +28 -6
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +12 -2
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +10 -7
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-turn-coordinator.js +4 -1
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +6 -5
- package/node_modules/@maka/runtime-host/dist/server/safe-boundary-resume-policy.js +27 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +5 -3
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +7 -2
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +11 -141
- package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +46 -75
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +18 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +33 -3
- package/node_modules/@maka/runtime-host/dist/transport/framed-byte-stream-transport.js +39 -5
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +7 -1
- package/node_modules/@maka/storage/dist/artifact-store.js +1 -5
- package/node_modules/@maka/storage/dist/artifact-stores.js +0 -3
- package/node_modules/@maka/storage/dist/atomic-file-write.js +1 -0
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +107 -57
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +227 -19
- package/node_modules/@maka/storage/dist/external-session-importer.js +1 -1
- package/node_modules/@maka/storage/dist/mcp-config-store.js +22 -3
- package/node_modules/@maka/storage/dist/settings-store.js +281 -13
- package/package.json +1 -1
|
@@ -3167,9 +3167,9 @@ async function globFiles(input2) {
|
|
|
3167
3167
|
promises: {
|
|
3168
3168
|
async lstat(path2) {
|
|
3169
3169
|
try {
|
|
3170
|
-
const
|
|
3171
|
-
if (
|
|
3172
|
-
return
|
|
3170
|
+
const stat2 = await fs2.lstat(path2);
|
|
3171
|
+
if (stat2.isDirectory()) directories.add(resolve(path2));
|
|
3172
|
+
return stat2;
|
|
3173
3173
|
} catch (error62) {
|
|
3174
3174
|
record2(error62, path2);
|
|
3175
3175
|
throw error62;
|
|
@@ -3991,13 +3991,13 @@ function computeEditedSource(source, oldString, newString, where) {
|
|
|
3991
3991
|
if (oldString === "") {
|
|
3992
3992
|
throw new Error(`old_string must not be empty in ${where}`);
|
|
3993
3993
|
}
|
|
3994
|
-
const
|
|
3995
|
-
if (
|
|
3994
|
+
const exactIndex = source.indexOf(oldString);
|
|
3995
|
+
if (exactIndex !== -1) {
|
|
3996
|
+
if (source.indexOf(oldString, exactIndex + 1) !== -1) {
|
|
3997
|
+
throw new Error(`old_string is not unique in ${where} (at least 2 matches)`);
|
|
3998
|
+
}
|
|
3996
3999
|
return finish(source, oldString, newString, "exact");
|
|
3997
4000
|
}
|
|
3998
|
-
if (exactCount > 1) {
|
|
3999
|
-
throw new Error(`old_string is not unique in ${where} (${exactCount} matches)`);
|
|
4000
|
-
}
|
|
4001
4001
|
if (oldString.trim().length < MIN_FUZZY_OLD_STRING_LENGTH) {
|
|
4002
4002
|
throw new Error(
|
|
4003
4003
|
`old_string is too short for a non-exact match in ${where}; provide a longer, exact snippet`
|
|
@@ -23950,6 +23950,27 @@ function readPage(content, input2, maxBytes = READ_PAGE_MAX_BYTES, continuation)
|
|
|
23950
23950
|
return makePage(low);
|
|
23951
23951
|
}
|
|
23952
23952
|
|
|
23953
|
+
// src/format-json.ts
|
|
23954
|
+
var sourceJson = JSON;
|
|
23955
|
+
function formatJsonText(source, sortKeys) {
|
|
23956
|
+
const value = JSON.parse(
|
|
23957
|
+
source,
|
|
23958
|
+
(_key, value2, context) => {
|
|
23959
|
+
if (typeof value2 === "number") {
|
|
23960
|
+
if (context?.source === void 0) throw new Error("JSON number source is unavailable");
|
|
23961
|
+
return sourceJson.rawJSON(context.source);
|
|
23962
|
+
}
|
|
23963
|
+
if (sortKeys && value2 !== null && typeof value2 === "object" && !Array.isArray(value2)) {
|
|
23964
|
+
return Object.fromEntries(
|
|
23965
|
+
Object.keys(value2).sort().map((key) => [key, value2[key]])
|
|
23966
|
+
);
|
|
23967
|
+
}
|
|
23968
|
+
return value2;
|
|
23969
|
+
}
|
|
23970
|
+
);
|
|
23971
|
+
return JSON.stringify(value, null, 2);
|
|
23972
|
+
}
|
|
23973
|
+
|
|
23953
23974
|
// src/unified-diff.ts
|
|
23954
23975
|
var MAX_DIFF_SOURCE_LINES = 800;
|
|
23955
23976
|
var MAX_DIFF_SOURCE_BYTES = 32 * 1024;
|
|
@@ -24313,7 +24334,7 @@ async function restoreTombstoneNoReplace(tombstone, path2) {
|
|
|
24313
24334
|
}
|
|
24314
24335
|
|
|
24315
24336
|
// src/image-file.ts
|
|
24316
|
-
import {
|
|
24337
|
+
import { open as open3 } from "node:fs/promises";
|
|
24317
24338
|
import { extname } from "node:path";
|
|
24318
24339
|
|
|
24319
24340
|
// ../../node_modules/image-dimensions/utilities.js
|
|
@@ -24701,16 +24722,21 @@ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif",
|
|
|
24701
24722
|
function isSupportedImagePath(path2) {
|
|
24702
24723
|
return IMAGE_EXTENSIONS.has(extname(path2).toLowerCase());
|
|
24703
24724
|
}
|
|
24704
|
-
async function
|
|
24705
|
-
const
|
|
24706
|
-
|
|
24707
|
-
|
|
24708
|
-
|
|
24709
|
-
|
|
24710
|
-
|
|
24711
|
-
|
|
24712
|
-
|
|
24713
|
-
|
|
24725
|
+
async function readWorkspaceFile(path2) {
|
|
24726
|
+
const file2 = await open3(path2, "r");
|
|
24727
|
+
try {
|
|
24728
|
+
const prefix = Buffer.alloc(ATTACHMENT_MIME_SNIFF_BYTES);
|
|
24729
|
+
const { bytesRead } = await file2.read(prefix, 0, prefix.length, 0);
|
|
24730
|
+
if (isSupportedImagePath(path2) || sniffImageMime(prefix.subarray(0, bytesRead))) {
|
|
24731
|
+
const size = await file2.stat();
|
|
24732
|
+
if (!size.isFile()) throw new Error("Image path is not a file.");
|
|
24733
|
+
if (size.size > MAX_READ_IMAGE_BYTES) throw imageTooLargeError();
|
|
24734
|
+
return validateImageBytes(await file2.readFile());
|
|
24735
|
+
}
|
|
24736
|
+
return { content: await file2.readFile("utf8") };
|
|
24737
|
+
} finally {
|
|
24738
|
+
await file2.close();
|
|
24739
|
+
}
|
|
24714
24740
|
}
|
|
24715
24741
|
function validateImageBytes(bytes) {
|
|
24716
24742
|
if (bytes.length > MAX_READ_IMAGE_BYTES) throw imageTooLargeError();
|
|
@@ -24976,24 +25002,24 @@ async function executeFilesystemOperation(operation, operationBoundary, dependen
|
|
|
24976
25002
|
"read",
|
|
24977
25003
|
operationBoundary
|
|
24978
25004
|
);
|
|
24979
|
-
|
|
24980
|
-
|
|
24981
|
-
|
|
24982
|
-
|
|
24983
|
-
|
|
24984
|
-
|
|
24985
|
-
|
|
24986
|
-
|
|
24987
|
-
|
|
24988
|
-
|
|
24989
|
-
|
|
24990
|
-
|
|
24991
|
-
);
|
|
24992
|
-
}
|
|
25005
|
+
const file2 = await readWorkspaceFile(path2).catch((error62) => {
|
|
25006
|
+
throw operationError(
|
|
25007
|
+
"filesystem_error",
|
|
25008
|
+
error62 instanceof Error ? error62.message : "File could not be read."
|
|
25009
|
+
);
|
|
25010
|
+
});
|
|
25011
|
+
if ("bytes" in file2) {
|
|
25012
|
+
return {
|
|
25013
|
+
kind: "read_image",
|
|
25014
|
+
base64: Buffer.from(file2.bytes).toString("base64"),
|
|
25015
|
+
mimeType: file2.mimeType
|
|
25016
|
+
};
|
|
24993
25017
|
}
|
|
24994
|
-
const content = await fs5.readFile(path2, "utf8");
|
|
24995
25018
|
try {
|
|
24996
|
-
return {
|
|
25019
|
+
return {
|
|
25020
|
+
kind: "read",
|
|
25021
|
+
...readPage(file2.content, operation, void 0, operation.continuation)
|
|
25022
|
+
};
|
|
24997
25023
|
} catch (error62) {
|
|
24998
25024
|
throw operationError(
|
|
24999
25025
|
"invalid_request",
|
|
@@ -25142,9 +25168,9 @@ async function executeFilesystemOperation(operation, operationBoundary, dependen
|
|
|
25142
25168
|
try {
|
|
25143
25169
|
const original = await handle.readFile("utf8");
|
|
25144
25170
|
const bytesBefore = Buffer.byteLength(original, "utf8");
|
|
25145
|
-
let
|
|
25171
|
+
let formatted;
|
|
25146
25172
|
try {
|
|
25147
|
-
|
|
25173
|
+
formatted = formatJsonText(original, operation.sortKeys ?? false);
|
|
25148
25174
|
} catch (error62) {
|
|
25149
25175
|
return {
|
|
25150
25176
|
kind: "format_json",
|
|
@@ -25157,11 +25183,6 @@ async function executeFilesystemOperation(operation, operationBoundary, dependen
|
|
|
25157
25183
|
changed: false
|
|
25158
25184
|
};
|
|
25159
25185
|
}
|
|
25160
|
-
const formatted = JSON.stringify(
|
|
25161
|
-
operation.sortKeys ? sortKeysDeep(parsed) : parsed,
|
|
25162
|
-
null,
|
|
25163
|
-
2
|
|
25164
|
-
);
|
|
25165
25186
|
if (formatted !== original) {
|
|
25166
25187
|
await writeThroughHandle(handle, formatted);
|
|
25167
25188
|
}
|
|
@@ -25255,15 +25276,6 @@ var FilesystemOperationError = class extends Error {
|
|
|
25255
25276
|
function operationError(code, message) {
|
|
25256
25277
|
return new FilesystemOperationError(code, message);
|
|
25257
25278
|
}
|
|
25258
|
-
function sortKeysDeep(value) {
|
|
25259
|
-
if (Array.isArray(value)) return value.map(sortKeysDeep);
|
|
25260
|
-
if (value !== null && typeof value === "object" && !(value instanceof Date)) {
|
|
25261
|
-
return Object.fromEntries(
|
|
25262
|
-
Object.keys(value).sort().map((key) => [key, sortKeysDeep(value[key])])
|
|
25263
|
-
);
|
|
25264
|
-
}
|
|
25265
|
-
return value;
|
|
25266
|
-
}
|
|
25267
25279
|
function normalizeOperationError(error62) {
|
|
25268
25280
|
if (error62 instanceof FilesystemOperationError) return error62;
|
|
25269
25281
|
if (error62 instanceof StableWriteFailure) {
|
|
@@ -26,7 +26,7 @@ import { compareAndDeleteEntry, hostVisibilityAfterWrite, openStableTarget, writ
|
|
|
26
26
|
import { promisify } from 'node:util';
|
|
27
27
|
import { currentRipgrepEnvironment, RipgrepUnavailableError, ripgrepMissingOnPathMessage, } from './ripgrep-guidance.js';
|
|
28
28
|
import { runProcessWithBoundedTail, runShellWithBoundedTail } from './shell-exec.js';
|
|
29
|
-
import { isSupportedImagePath,
|
|
29
|
+
import { isSupportedImagePath, readWorkspaceFile } from './image-file.js';
|
|
30
30
|
import { readTextLineWindow } from './text-line-window.js';
|
|
31
31
|
import { searchFiles } from './grep-search.js';
|
|
32
32
|
import { defaultRipgrepCandidates, resolveRipgrepExecutable } from './ripgrep-executable.js';
|
|
@@ -68,11 +68,10 @@ export class LocalWorkspaceExecutor {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
async readFile(input) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return { content: readTextLineWindow(content, input.offset, input.limit) };
|
|
71
|
+
const file = await readWorkspaceFile(input.path);
|
|
72
|
+
if ('bytes' in file)
|
|
73
|
+
return file;
|
|
74
|
+
return { content: readTextLineWindow(file.content, input.offset, input.limit) };
|
|
76
75
|
}
|
|
77
76
|
async writeFile(input) {
|
|
78
77
|
await fs.writeFile(input.path, input.content, 'utf8');
|
|
@@ -89,12 +89,29 @@ export class RuntimeHostSessionProjector {
|
|
|
89
89
|
enableMessageAdmissions() {
|
|
90
90
|
this.#projectMessageAdmissions = true;
|
|
91
91
|
}
|
|
92
|
-
seedActive(includeAssistantText) {
|
|
92
|
+
seedActive(includeAssistantText, options = {}) {
|
|
93
93
|
const root = this.#snapshot.rootTurn;
|
|
94
|
-
if (!root)
|
|
95
|
-
|
|
94
|
+
if (!root) {
|
|
95
|
+
// A Session whose root Turn is gone still owns an authoritative queue:
|
|
96
|
+
// a client resubscribing after navigating away may hold a stale queued
|
|
97
|
+
// card that only this seed can retire, because no live drain will run
|
|
98
|
+
// while it is the active view (apache/maka#5520 review). Snapshots that
|
|
99
|
+
// carry no queue at all project as empty.
|
|
100
|
+
const queue = this.#snapshot.queue ?? {
|
|
101
|
+
hostEpoch: '',
|
|
102
|
+
queueRevision: 0,
|
|
103
|
+
steering: [],
|
|
104
|
+
followup: [],
|
|
105
|
+
};
|
|
106
|
+
return [projectQueueUpdate(this.#unplacedQueue(queue), '', this.#now())];
|
|
107
|
+
}
|
|
96
108
|
const events = [];
|
|
97
|
-
|
|
109
|
+
// A queue-rendering client needs the empty seed to clear entries it saw
|
|
110
|
+
// before re-observing. ACP ignores queue_update, and delivering one after
|
|
111
|
+
// an output failure would stop the Host Turn it restored.
|
|
112
|
+
const queueEvents = options.includeEmptyQueue ||
|
|
113
|
+
this.#projectMessageAdmissions ||
|
|
114
|
+
queueHasEntries(this.#snapshot.queue)
|
|
98
115
|
? [projectQueueUpdate(this.#unplacedQueue(this.#snapshot.queue), root.turnId, this.#now())]
|
|
99
116
|
: [];
|
|
100
117
|
if (this.#projectMessageAdmissions) {
|
|
@@ -330,8 +347,12 @@ export class RuntimeHostSessionProjector {
|
|
|
330
347
|
for (const interaction of newlyPendingInteractions(previousSnapshot, next)) {
|
|
331
348
|
events.push(...projectRuntimeHostInteractionRequest(interaction, this.#now()));
|
|
332
349
|
}
|
|
333
|
-
if (
|
|
334
|
-
|
|
350
|
+
if (queueChanged(previousSnapshot.queue, next.queue)) {
|
|
351
|
+
// Project the authoritative queue even with no live Turn: a drain that
|
|
352
|
+
// lands after the root Turn is gone must still reach observers, or a
|
|
353
|
+
// queued card survives as a phantom whose retract fails with not_found
|
|
354
|
+
// (apache/maka#5520).
|
|
355
|
+
events.push(projectQueueUpdate(this.#unplacedQueue(next.queue), root?.turnId ?? previousRoot?.turnId ?? '', this.#now()));
|
|
335
356
|
}
|
|
336
357
|
if (startedTurn)
|
|
337
358
|
this.#accumulators.clear();
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { isHostActivityIdle } from '../protocol/host-status.js';
|
|
19
20
|
const COPY = {
|
|
20
21
|
'zh-CN': {
|
|
21
22
|
titles: {
|
|
@@ -210,7 +211,9 @@ export function formatHostHandoff(view, locale) {
|
|
|
210
211
|
if (view.recoveryBlocker && view.reason === 'operator_required') {
|
|
211
212
|
description = copy.recoveryGuidance[view.recoveryBlocker];
|
|
212
213
|
}
|
|
213
|
-
|
|
214
|
+
// An idle snapshot is only projected as busy after the Host refused safe retirement.
|
|
215
|
+
if (view.reason === 'busy' &&
|
|
216
|
+
(view.manualRecheck || (view.activity && isHostActivityIdle(view.activity)))) {
|
|
214
217
|
description = copy.manualBusy;
|
|
215
218
|
}
|
|
216
219
|
if (view.manualRecheck && view.reason === 'operator_required') {
|
|
@@ -255,15 +255,15 @@ function projectBlocker(blocker, revision, recovery, activeWorkRefused = false)
|
|
|
255
255
|
? 'repair_required'
|
|
256
256
|
: !replacement
|
|
257
257
|
? 'operator_required'
|
|
258
|
-
:
|
|
259
|
-
?
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
258
|
+
: activeWorkRefused
|
|
259
|
+
? 'busy'
|
|
260
|
+
: replacement.requiresExplicitSelection
|
|
261
|
+
? 'replacement_required'
|
|
262
|
+
: !blocker.activity
|
|
263
|
+
? 'activity_unknown'
|
|
264
|
+
: isHostActivityIdle(blocker.activity)
|
|
265
|
+
? 'retry_required'
|
|
266
|
+
: 'busy',
|
|
267
267
|
...(blocker.activity ? { activity: blocker.activity } : {}),
|
|
268
268
|
mayExitNaturally: blocker.mayExitNaturally,
|
|
269
269
|
...(blocker.manualRecheck ? { manualRecheck: true } : {}),
|
|
@@ -38,7 +38,15 @@ export function projectSessionCatalogSummary(session) {
|
|
|
38
38
|
...(session.statusUpdatedAt === undefined ? {} : { statusUpdatedAt: session.statusUpdatedAt }),
|
|
39
39
|
...(session.liveRunState === undefined
|
|
40
40
|
? {}
|
|
41
|
-
: {
|
|
41
|
+
: {
|
|
42
|
+
runningTurnIds: [...session.liveRunState.runningTurnIds],
|
|
43
|
+
...(session.liveRunState.runEpoch === undefined
|
|
44
|
+
? {}
|
|
45
|
+
: { runEpoch: session.liveRunState.runEpoch }),
|
|
46
|
+
...(session.liveRunState.hostGeneration === undefined
|
|
47
|
+
? {}
|
|
48
|
+
: { runHostGeneration: session.liveRunState.hostGeneration }),
|
|
49
|
+
}),
|
|
42
50
|
...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),
|
|
43
51
|
...(session.branchOfTurnId === undefined ? {} : { branchOfTurnId: session.branchOfTurnId }),
|
|
44
52
|
...(session.subagent === undefined ? {} : { subagent: session.subagent }),
|
|
@@ -64,7 +64,18 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
64
64
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
65
65
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
66
66
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
67
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
67
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 196;
|
|
68
|
+
// 196: `turn.start` carries an optional durable external-message origin; older
|
|
69
|
+
// peers would drop activation provenance and misclassify automated turns.
|
|
70
|
+
// 195: Session catalog live run state may carry the host generation that
|
|
71
|
+
// produced it, so clients can tell same-revision reads of a restarted Host
|
|
72
|
+
// apart from its predecessor's instead of ordering them by a per-process
|
|
73
|
+
// epoch. Epoch-194 peers reject the unknown key.
|
|
74
|
+
// 194: Session catalog live run state may carry the runtime's run epoch, which
|
|
75
|
+
// lets clients order same-revision reads. Epoch-193 peers reject the unknown
|
|
76
|
+
// key, so a newer Desktop against an older Host loses session catalog reads.
|
|
77
|
+
// 192: Message quotes carry an optional annotation written by the user, which
|
|
78
|
+
// the model reads beside the excerpt. An epoch-191 peer rejects the field.
|
|
68
79
|
// 191: Session catalog change frames can carry attention events.
|
|
69
80
|
// 190: ScheduledTask execution templates preserve toolMode; older peers reject it.
|
|
70
81
|
// 189: Remove form_interaction transcript messages and the transcript_changed close reason.
|
|
@@ -41,6 +41,7 @@ export const SESSION_CATALOG_MODEL_MAX_BYTES = SESSION_MODEL_ID_MAX_BYTES;
|
|
|
41
41
|
export const SESSION_CATALOG_CONNECTION_SLUG_MAX_BYTES = 256;
|
|
42
42
|
export const SESSION_CATALOG_LIVE_RUN_STATE_SCHEMA_VERSION = 1;
|
|
43
43
|
export const SESSION_CATALOG_RUNNING_TURN_MAX_ITEMS = 64;
|
|
44
|
+
export const SESSION_CATALOG_HOST_GENERATION_MAX_CHARS = 128;
|
|
44
45
|
const QUERY_ERRORS = [
|
|
45
46
|
'host_not_ready',
|
|
46
47
|
'host_draining',
|
|
@@ -630,28 +631,49 @@ function optionalBlockedReason(record) {
|
|
|
630
631
|
function optionalLiveRunState(record) {
|
|
631
632
|
if (record.liveRunState === undefined)
|
|
632
633
|
return {};
|
|
633
|
-
const
|
|
634
|
+
const liveRunState = requireRecord(record.liveRunState, 'Session catalog live run state');
|
|
635
|
+
assertAllowedKeys(liveRunState, 'Session catalog live run state', [
|
|
634
636
|
'schemaVersion',
|
|
635
637
|
'runningTurnIds',
|
|
638
|
+
'runEpoch',
|
|
639
|
+
'hostGeneration',
|
|
636
640
|
]);
|
|
637
|
-
if (
|
|
641
|
+
if (liveRunState.schemaVersion !== SESSION_CATALOG_LIVE_RUN_STATE_SCHEMA_VERSION) {
|
|
638
642
|
throw invalidProtocolFrame('Unsupported Session catalog live run state schema version');
|
|
639
643
|
}
|
|
640
|
-
if (!
|
|
641
|
-
|
|
644
|
+
if (!Object.hasOwn(liveRunState, 'runningTurnIds') ||
|
|
645
|
+
!Array.isArray(liveRunState.runningTurnIds) ||
|
|
646
|
+
liveRunState.runningTurnIds.length > SESSION_CATALOG_RUNNING_TURN_MAX_ITEMS) {
|
|
642
647
|
throw invalidProtocolFrame('Invalid Session catalog running turn ids');
|
|
643
648
|
}
|
|
644
649
|
const runningTurnIds = [];
|
|
645
|
-
for (let index = 0; index <
|
|
646
|
-
runningTurnIds.push(requireEntityId(
|
|
650
|
+
for (let index = 0; index < liveRunState.runningTurnIds.length; index += 1) {
|
|
651
|
+
runningTurnIds.push(requireEntityId(liveRunState.runningTurnIds[index], 'Session running turn id'));
|
|
647
652
|
}
|
|
648
653
|
if (new Set(runningTurnIds).size !== runningTurnIds.length) {
|
|
649
654
|
throw invalidProtocolFrame('Duplicate Session catalog running turn id');
|
|
650
655
|
}
|
|
656
|
+
if (liveRunState.runEpoch !== undefined &&
|
|
657
|
+
(typeof liveRunState.runEpoch !== 'number' ||
|
|
658
|
+
!Number.isSafeInteger(liveRunState.runEpoch) ||
|
|
659
|
+
liveRunState.runEpoch < 0)) {
|
|
660
|
+
throw invalidProtocolFrame('Invalid Session catalog run epoch');
|
|
661
|
+
}
|
|
662
|
+
if (liveRunState.hostGeneration !== undefined &&
|
|
663
|
+
(typeof liveRunState.hostGeneration !== 'string' ||
|
|
664
|
+
liveRunState.hostGeneration.length === 0 ||
|
|
665
|
+
liveRunState.hostGeneration.length > SESSION_CATALOG_HOST_GENERATION_MAX_CHARS ||
|
|
666
|
+
/[\u0000-\u001f\u007f]/.test(liveRunState.hostGeneration))) {
|
|
667
|
+
throw invalidProtocolFrame('Invalid Session catalog host generation');
|
|
668
|
+
}
|
|
651
669
|
return {
|
|
652
670
|
liveRunState: {
|
|
653
671
|
schemaVersion: SESSION_CATALOG_LIVE_RUN_STATE_SCHEMA_VERSION,
|
|
654
672
|
runningTurnIds,
|
|
673
|
+
...(liveRunState.runEpoch === undefined ? {} : { runEpoch: liveRunState.runEpoch }),
|
|
674
|
+
...(liveRunState.hostGeneration === undefined
|
|
675
|
+
? {}
|
|
676
|
+
: { hostGeneration: liveRunState.hostGeneration }),
|
|
655
677
|
},
|
|
656
678
|
};
|
|
657
679
|
}
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { MAX_ATTACHMENT_BYTES, MAX_ATTACHMENT_COUNT } from '@maka/core/attachments';
|
|
20
|
-
import { decodeMessageContent as decodeCanonicalMessageContent, DIRECTORY_REFERENCE_MAX_COUNT, hasMeaningfulMessageContent, isCanonicalAttachmentRef, } from '@maka/core/events';
|
|
20
|
+
import { decodeMessageContent as decodeCanonicalMessageContent, DIRECTORY_REFERENCE_MAX_COUNT, hasMeaningfulMessageContent, isCanonicalAttachmentRef, QUOTE_COMMENT_MAX_LENGTH, } from '@maka/core/events';
|
|
21
21
|
import { isOrchestrationMode, isTurnOrchestrationSource, } from '@maka/core/orchestration';
|
|
22
22
|
import { decodeSkillInvocationResult, } from '@maka/core/skill-invocation';
|
|
23
|
+
import { decodeTurnOrigin } from '@maka/core/turn-origin';
|
|
23
24
|
import { invalidProtocolFrame } from './errors.js';
|
|
24
25
|
import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireShapedRecord, requireId, requireRecord, requireString, } from './codec.js';
|
|
25
26
|
import { defineOperation } from './operation-spec.js';
|
|
@@ -152,8 +153,13 @@ export const TURN_OPERATION_SPECS = {
|
|
|
152
153
|
}),
|
|
153
154
|
};
|
|
154
155
|
export function decodeTurnStartInput(value) {
|
|
155
|
-
const record = requireShapedRecord(value, 'turn.start input', ['sessionId', 'turnId', 'content'], ['skillIds', 'turnOrchestration', 'maxSteps']);
|
|
156
|
+
const record = requireShapedRecord(value, 'turn.start input', ['sessionId', 'turnId', 'content'], ['skillIds', 'turnOrchestration', 'maxSteps', 'origin']);
|
|
156
157
|
const skillIds = decodeSkillIds(record.skillIds);
|
|
158
|
+
const decodedOrigin = record.origin === undefined ? undefined : decodeTurnOrigin(record.origin);
|
|
159
|
+
const origin = decodedOrigin?.kind === 'cloud_activation' ? decodedOrigin : undefined;
|
|
160
|
+
if (record.origin !== undefined && origin === undefined) {
|
|
161
|
+
throw invalidProtocolFrame('Invalid turn.start origin');
|
|
162
|
+
}
|
|
157
163
|
return {
|
|
158
164
|
sessionId: requireEntityId(record.sessionId, 'sessionId'),
|
|
159
165
|
turnId: requireEntityId(record.turnId, 'turnId'),
|
|
@@ -165,6 +171,7 @@ export function decodeTurnStartInput(value) {
|
|
|
165
171
|
...(record.maxSteps !== undefined
|
|
166
172
|
? { maxSteps: requirePositiveSafeInteger(record.maxSteps, 'maxSteps') }
|
|
167
173
|
: {}),
|
|
174
|
+
...(origin !== undefined ? { origin } : {}),
|
|
168
175
|
};
|
|
169
176
|
}
|
|
170
177
|
function requirePositiveSafeInteger(value, label) {
|
|
@@ -238,6 +245,9 @@ export function decodeMessageContent(value, allowEmptyText = false) {
|
|
|
238
245
|
if (quote.label !== undefined) {
|
|
239
246
|
requireString(quote.label, 'QuoteRef label', TURN_MESSAGE_QUOTE_LABEL_MAX_LENGTH);
|
|
240
247
|
}
|
|
248
|
+
if (quote.comment !== undefined) {
|
|
249
|
+
requireString(quote.comment, 'QuoteRef comment', QUOTE_COMMENT_MAX_LENGTH);
|
|
250
|
+
}
|
|
241
251
|
if (quote.sourceTurnId !== undefined) {
|
|
242
252
|
requireEntityId(quote.sourceTurnId, 'QuoteRef sourceTurnId');
|
|
243
253
|
}
|
|
@@ -40,6 +40,8 @@ const DESKTOP_BROWSER_TOOLS = new Set([
|
|
|
40
40
|
'browser_extract',
|
|
41
41
|
]);
|
|
42
42
|
const DESKTOP_SETTINGS_TOOLS = new Set(['MakaClientSettingsGet', 'MakaClientSettingsUpdate']);
|
|
43
|
+
// Provider IDs are `cc_` digests. This cannot match a registered provider.
|
|
44
|
+
const UNATTACHED_INITIATING_PROVIDER_ID = 'unattached_client';
|
|
43
45
|
export { ClientCapabilityInvocationError };
|
|
44
46
|
/**
|
|
45
47
|
* Host-owned registry, selection authority, and reverse-call lifecycle for
|
|
@@ -254,13 +256,12 @@ export class HostClientCapabilityCoordinator {
|
|
|
254
256
|
};
|
|
255
257
|
}
|
|
256
258
|
const selectedInitiatingProvider = directProvider ?? associatedProviders[0];
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
259
|
+
// An explicit initiating Client may use only its own publication (or its
|
|
260
|
+
// authenticated companion). Provider-independent selection is reserved
|
|
261
|
+
// for Host-originated recovery, which has no initiating connection.
|
|
260
262
|
const initiatingProviderId = selectedInitiatingProvider?.providerId ??
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
: undefined);
|
|
263
|
+
initiatingProvider?.providerId ??
|
|
264
|
+
(initiatingConnectionId ? UNATTACHED_INITIATING_PROVIDER_ID : undefined);
|
|
264
265
|
const previousState = this.#sessions.get(sessionId);
|
|
265
266
|
const serviceProviderId = previousState?.serviceProviderId ??
|
|
266
267
|
(selectedInitiatingProvider?.current &&
|
|
@@ -1211,6 +1212,7 @@ export class HostClientCapabilityCoordinator {
|
|
|
1211
1212
|
if (state.sessionBindings.size === 0 &&
|
|
1212
1213
|
state.turnBindings.size === 0 &&
|
|
1213
1214
|
!state.serviceProviderId &&
|
|
1215
|
+
state.initiatingProviderId === undefined &&
|
|
1214
1216
|
!this.#hasCallOffers()) {
|
|
1215
1217
|
this.#sessions.delete(sessionId);
|
|
1216
1218
|
return;
|
|
@@ -1223,7 +1225,8 @@ export class HostClientCapabilityCoordinator {
|
|
|
1223
1225
|
for (const [sessionId, state] of this.#sessions) {
|
|
1224
1226
|
if (state.sessionBindings.size === 0 &&
|
|
1225
1227
|
state.turnBindings.size === 0 &&
|
|
1226
|
-
!state.serviceProviderId
|
|
1228
|
+
!state.serviceProviderId &&
|
|
1229
|
+
state.initiatingProviderId === undefined) {
|
|
1227
1230
|
this.#sessions.delete(sessionId);
|
|
1228
1231
|
}
|
|
1229
1232
|
}
|
|
@@ -141,6 +141,7 @@ import { HostPluginPlatformCoordinator } from './plugin-platform-coordinator.js'
|
|
|
141
141
|
import { HostPluginPlatform } from './plugin-platform.js';
|
|
142
142
|
import { RootAdmissionOwner } from './root-admission-owner.js';
|
|
143
143
|
import { RootTurnCoordinator } from './root-turn-coordinator.js';
|
|
144
|
+
import { resolveSafeBoundaryResumePolicy } from './safe-boundary-resume-policy.js';
|
|
144
145
|
import { RuntimePolicyActivationGate } from './runtime-policy-activation-gate.js';
|
|
145
146
|
import { resolveSandboxBoundaryRootSession } from './sandbox-boundary-graph-wake.js';
|
|
146
147
|
import { HostRuntimePolicyCoordinator } from './runtime-policy-coordinator.js';
|
|
@@ -1179,6 +1180,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1179
1180
|
getPresets: async () => (await runtimePolicyStores.runtimePolicy.getSnapshot()).policy.subagents.presets,
|
|
1180
1181
|
getConnection: async (slug) => (await runtimePolicyStores.connectionCatalog.getSnapshot()).connections.find((connection) => connection.slug === slug) ?? null,
|
|
1181
1182
|
});
|
|
1183
|
+
const safeBoundaryResumePolicy = resolveSafeBoundaryResumePolicy(process.env.MAKA_RUNTIME_SAFE_BOUNDARY_RESUME);
|
|
1182
1184
|
manager = new SessionManager({
|
|
1183
1185
|
store: stores.sessionStore,
|
|
1184
1186
|
runStore: stores.agentRunStore,
|
|
@@ -1194,7 +1196,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1194
1196
|
},
|
|
1195
1197
|
newId: randomUUID,
|
|
1196
1198
|
now: Date.now,
|
|
1197
|
-
safeBoundaryResumeEnabled:
|
|
1199
|
+
safeBoundaryResumeEnabled: safeBoundaryResumePolicy.interactive,
|
|
1198
1200
|
inspectContinuationSafety: createLocalContinuationSafetyInspector({
|
|
1199
1201
|
readSessionCwd: async (sessionId) => (await stores.sessionStore.readHeaderSnapshot(sessionId)).cwd,
|
|
1200
1202
|
resolveWorkspaceIdentity: async (cwd) => resolveWorkspaceIdentity({ path: cwd }),
|
|
@@ -1872,6 +1874,9 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1872
1874
|
}
|
|
1873
1875
|
return { outcome: 'resume_started', targetTurnId };
|
|
1874
1876
|
}
|
|
1877
|
+
if (!safeBoundaryResumePolicy.automated) {
|
|
1878
|
+
throw new WorkHubActionEffectFailure('operation_unavailable', 'Safe-boundary resume is disabled for this Runtime Host');
|
|
1879
|
+
}
|
|
1875
1880
|
await validateFreshTarget();
|
|
1876
1881
|
await prepareTargetExecution?.();
|
|
1877
1882
|
// A model-repair form can remain open while another action changes
|
|
@@ -2609,6 +2614,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2609
2614
|
const goalHold = goal?.holdForHandoff();
|
|
2610
2615
|
const scheduleHold = scheduledTasks?.holdForHandoff();
|
|
2611
2616
|
const dailyReviewHold = dailyReview?.holdForHandoff();
|
|
2617
|
+
const workHubResultHold = workHubResults?.coordinator.holdForHandoff();
|
|
2612
2618
|
let root;
|
|
2613
2619
|
let detached = false;
|
|
2614
2620
|
const cancel = () => {
|
|
@@ -2618,11 +2624,12 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2618
2624
|
goalHold?.release();
|
|
2619
2625
|
scheduleHold?.release();
|
|
2620
2626
|
dailyReviewHold?.release();
|
|
2627
|
+
workHubResultHold?.release();
|
|
2621
2628
|
signal.removeEventListener('abort', cancel);
|
|
2622
2629
|
};
|
|
2623
2630
|
signal.addEventListener('abort', cancel, { once: true });
|
|
2624
2631
|
try {
|
|
2625
|
-
if (!goalHold || !scheduleHold || !dailyReviewHold) {
|
|
2632
|
+
if (!goalHold || !scheduleHold || !dailyReviewHold || !workHubResultHold) {
|
|
2626
2633
|
cancel();
|
|
2627
2634
|
return undefined;
|
|
2628
2635
|
}
|
|
@@ -2630,6 +2637,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2630
2637
|
goalHold.settled(),
|
|
2631
2638
|
scheduleHold.settled(),
|
|
2632
2639
|
dailyReviewHold.settled(),
|
|
2640
|
+
workHubResultHold.settled(),
|
|
2633
2641
|
]).then(() => undefined), signal);
|
|
2634
2642
|
root = await requireRootCoordinator(coordinator).prepareHandoff(hostEpoch, signal);
|
|
2635
2643
|
if (!root) {
|
|
@@ -276,6 +276,8 @@ export function requireHostedExecutionMessageContent(admission) {
|
|
|
276
276
|
}
|
|
277
277
|
export function hostedExecutionMessageOrigin(execution) {
|
|
278
278
|
switch (execution.kind) {
|
|
279
|
+
case 'external_message':
|
|
280
|
+
return execution.origin;
|
|
279
281
|
case 'workhub_coordination':
|
|
280
282
|
return execution.feedback;
|
|
281
283
|
case 'scheduled_task':
|
|
@@ -21,6 +21,7 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
21
21
|
import { normalizeMessageContent } from '@maka/core/events';
|
|
22
22
|
import { RuntimeMessageAuthorityInvariantError } from '@maka/runtime/message-authority';
|
|
23
23
|
import { parseSkillInvocationTokens } from '@maka/runtime/skill-invocation';
|
|
24
|
+
import { capabilityInitiatingConnectionId, } from './operation-dispatcher.js';
|
|
24
25
|
const EMPTY_SKILL_INVOCATION = {
|
|
25
26
|
loaded: [],
|
|
26
27
|
failed: [],
|
|
@@ -45,6 +46,7 @@ export class HostInteractiveTurnCoordinator {
|
|
|
45
46
|
kind: 'external_message',
|
|
46
47
|
inputDigest: hostedExternalInputDigest(content, skillIds),
|
|
47
48
|
...(input.maxSteps !== undefined ? { maxSteps: input.maxSteps } : {}),
|
|
49
|
+
...(input.origin !== undefined ? { origin: input.origin } : {}),
|
|
48
50
|
}, context);
|
|
49
51
|
}
|
|
50
52
|
const outcome = await this.#executions.startInteractiveRootMessage({
|
|
@@ -53,6 +55,7 @@ export class HostInteractiveTurnCoordinator {
|
|
|
53
55
|
execution: {
|
|
54
56
|
kind: 'external_message',
|
|
55
57
|
...(input.maxSteps !== undefined ? { maxSteps: input.maxSteps } : {}),
|
|
58
|
+
...(input.origin !== undefined ? { origin: input.origin } : {}),
|
|
56
59
|
},
|
|
57
60
|
...(input.turnOrchestration ? { turnOrchestration: { ...input.turnOrchestration } } : {}),
|
|
58
61
|
archivedMessage: 'Cannot start a new Turn in an archived Session',
|
|
@@ -87,7 +90,7 @@ export class HostInteractiveTurnCoordinator {
|
|
|
87
90
|
skillInvocation: existing.skillInvocation,
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
|
-
const prepared = await this.#executions.prepareHostedSkillInvocationContent(input.sessionId, input.turnId, content, skillIds, context
|
|
93
|
+
const prepared = await this.#executions.prepareHostedSkillInvocationContent(input.sessionId, input.turnId, content, skillIds, capabilityInitiatingConnectionId(context));
|
|
91
94
|
if (prepared.kind === 'ready' || !prepared.skillInvocation)
|
|
92
95
|
return prepared;
|
|
93
96
|
const committed = await this.#turns.commitRootTurnStartRejection({
|
|
@@ -24,6 +24,7 @@ import { normalizeRootTurnAdmissionPayload, rootTurnAdmissionRecordFits, submitt
|
|
|
24
24
|
import { MESSAGE_QUEUE_MAX_ENTRIES, MESSAGE_QUEUE_PROJECTION_MAX_BYTES, MESSAGE_OPERATION_RESULT_MAX_BYTES, MESSAGE_OPERATION_SPECS, } from '../protocol/index.js';
|
|
25
25
|
import { worstCaseFailedTurnSnapshot } from './canonical-turn-snapshot.js';
|
|
26
26
|
import { worstCaseMessageQueueProjection } from './message-queue-capacity.js';
|
|
27
|
+
import { capabilityInitiatingConnectionId, } from './operation-dispatcher.js';
|
|
27
28
|
const EMPTY_SKILL_INVOCATION = {
|
|
28
29
|
loaded: [],
|
|
29
30
|
failed: [],
|
|
@@ -660,6 +661,7 @@ export class HostMessageCoordinator {
|
|
|
660
661
|
}
|
|
661
662
|
submit(input, context, admission) {
|
|
662
663
|
const payload = canonicalSubmitPayload(input);
|
|
664
|
+
const initiatingConnectionId = capabilityInitiatingConnectionId(context);
|
|
663
665
|
const isCurrentEpoch = input.originHostEpoch === this.#hostEpoch;
|
|
664
666
|
if (isCurrentEpoch) {
|
|
665
667
|
const pending = this.#pendingSubmits.get(operationKey(input.sessionId, input.messageId));
|
|
@@ -673,10 +675,10 @@ export class HostMessageCoordinator {
|
|
|
673
675
|
return Promise.resolve(failure('host_draining', 'Runtime Host message authority has failed'));
|
|
674
676
|
}
|
|
675
677
|
if (!isCurrentEpoch) {
|
|
676
|
-
return this.#submitAdmitted(input, payload,
|
|
678
|
+
return this.#submitAdmitted(input, payload, initiatingConnectionId, admission);
|
|
677
679
|
}
|
|
678
680
|
const key = operationKey(input.sessionId, input.messageId);
|
|
679
|
-
const result = this.#submitAdmitted(input, payload,
|
|
681
|
+
const result = this.#submitAdmitted(input, payload, initiatingConnectionId, admission);
|
|
680
682
|
this.#pendingSubmits.set(key, { payload, result });
|
|
681
683
|
void result.then(() => this.#deletePendingSubmit(key, result), () => this.#deletePendingSubmit(key, result));
|
|
682
684
|
return result;
|