maka-agent 0.2.0-dev.77.20261009 → 0.2.0-dev.78.20261010
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/README.zh-CN.md +2 -2
- package/dist/pi-tui-pickers.js +5 -2
- package/dist/pi-tui-runner.js +211 -33
- package/dist/runtime-host-session-driver.js +91 -13
- package/dist/session-catalog-limits.js +22 -0
- package/dist/session-driver.js +10 -0
- package/dist/tui-copy-catalog.js +15 -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/bot-chat-settings.js +3 -0
- package/node_modules/@maka/core/dist/bot-events.js +1 -8
- package/node_modules/@maka/core/dist/local-memory.js +38 -1
- package/node_modules/@maka/core/dist/scheduled-task.js +14 -15
- package/node_modules/@maka/core/dist/session.js +3 -0
- package/node_modules/@maka/core/dist/text-sanitize.js +8 -3
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +11 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +13 -5
- package/node_modules/@maka/runtime/dist/bots/proxied-fetch.js +29 -1
- package/node_modules/@maka/runtime/dist/file-stable-write.js +15 -3
- package/node_modules/@maka/runtime/dist/model-adapter.js +20 -1
- package/node_modules/@maka/runtime/dist/network/proxy-test.js +28 -1
- package/node_modules/@maka/runtime/dist/network/scoped-fetch-transport.js +13 -2
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +92 -5
- package/node_modules/@maka/runtime/dist/sandbox-boundary-tool.js +12 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +31 -5
- package/node_modules/@maka/runtime/dist/tool-availability.js +22 -16
- package/node_modules/@maka/runtime/dist/tool-call-snapshot.js +142 -0
- package/node_modules/@maka/runtime/dist/tool-runtime.js +25 -83
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +12 -1
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +30 -6
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +4 -7
- package/node_modules/@maka/runtime-host/dist/server/archive-retention-coordinator.js +81 -105
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +17 -43
- package/node_modules/@maka/runtime-host/dist/server/host-maintenance-guards.js +95 -0
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +18 -8
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +32 -3
- package/node_modules/@maka/runtime-host/dist/server/project-catalog-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +68 -3
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +19 -24
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +74 -19
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +3 -98
- package/node_modules/@maka/runtime-host/dist/server/workhub-target-execution-authority.js +14 -126
- package/node_modules/@maka/storage/dist/git-entry.js +142 -5
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ import { PLAN_USER_ABANDON_REASON, PLAN_USER_CANCEL_REASON, PlanConflictError, a
|
|
|
27
27
|
import { DEFAULT_SESSION_NAME } from '@maka/core/session-name';
|
|
28
28
|
import { SUBAGENT_SESSION_RUNTIME_SCHEMA_VERSION, SUBAGENT_SESSION_SPAWN_SCHEMA_VERSION, childSessionsForParent, subagentSessionRuntimeSummary, } from '@maka/core/session';
|
|
29
29
|
import { decodeAgentGraphIntentClaim } from '@maka/core/agent-graph-control';
|
|
30
|
-
import { executionBoundaryContains } from '@maka/core/sandbox-boundary';
|
|
30
|
+
import { createGenesisExecutionBoundary, executionBoundaryContains, } from '@maka/core/sandbox-boundary';
|
|
31
31
|
import { failureClassFromCompleteStopReason } from '@maka/core/events';
|
|
32
32
|
import { isActiveShellRunStatus } from '@maka/core/shell-run';
|
|
33
33
|
import { isTerminalRuntimeEvent } from '@maka/core/runtime-event';
|
|
@@ -1436,6 +1436,22 @@ export class SessionManager {
|
|
|
1436
1436
|
async preflightContextCompaction(sessionId) {
|
|
1437
1437
|
await this.runtimeKernel.preflightContextCompaction(sessionId);
|
|
1438
1438
|
}
|
|
1439
|
+
returnExecutionQuestions(sessionId, runId) {
|
|
1440
|
+
if (!this.runtimeKernel.returnExecutionQuestions)
|
|
1441
|
+
throw new Error('Runtime does not support execution question policy');
|
|
1442
|
+
this.runtimeKernel.returnExecutionQuestions(sessionId, runId);
|
|
1443
|
+
}
|
|
1444
|
+
async readExecutionPolicy(sessionId, runId) {
|
|
1445
|
+
return (this.runtimeKernel.readExecutionPolicy?.(sessionId, runId) ??
|
|
1446
|
+
(await this.deps.resolveExecutionPolicy?.(sessionId, runId)));
|
|
1447
|
+
}
|
|
1448
|
+
async readExecutionBoundaryForRun(sessionId, runId) {
|
|
1449
|
+
const policy = await this.readExecutionPolicy(sessionId, runId);
|
|
1450
|
+
const boundary = await this.deps.store.readExecutionBoundary(sessionId);
|
|
1451
|
+
return policy && (policy.permissionMode === 'bypass' || boundary.kind === 'bypass')
|
|
1452
|
+
? createGenesisExecutionBoundary(policy.permissionMode)
|
|
1453
|
+
: boundary;
|
|
1454
|
+
}
|
|
1439
1455
|
/**
|
|
1440
1456
|
* Create and run a durable linked child Session.
|
|
1441
1457
|
*
|
|
@@ -1504,7 +1520,7 @@ export class SessionManager {
|
|
|
1504
1520
|
const [parentHeader, sourceRun, parentBoundary] = await Promise.all([
|
|
1505
1521
|
this.deps.store.readHeader(input.source.sessionId),
|
|
1506
1522
|
this.readInvocation(input.source.sessionId, input.source.runId),
|
|
1507
|
-
this.
|
|
1523
|
+
this.readExecutionBoundaryForRun(input.source.sessionId, input.source.runId),
|
|
1508
1524
|
]);
|
|
1509
1525
|
if (sourceRun.sessionId !== input.source.sessionId ||
|
|
1510
1526
|
sourceRun.runId !== input.source.runId ||
|
|
@@ -1530,7 +1546,10 @@ export class SessionManager {
|
|
|
1530
1546
|
const resolvedToolNames = executorId
|
|
1531
1547
|
? []
|
|
1532
1548
|
: await this.resolveChildToolNames(input.source.sessionId, parentHeader, definition);
|
|
1533
|
-
const childPermissionMode =
|
|
1549
|
+
const childPermissionMode = ((await this.readExecutionPolicy(input.source.sessionId, input.source.runId))
|
|
1550
|
+
?.permissionMode ?? parentHeader.permissionMode) === 'bypass'
|
|
1551
|
+
? 'bypass'
|
|
1552
|
+
: definition.permissionMode;
|
|
1534
1553
|
const initialTurnId = this.deps.newId();
|
|
1535
1554
|
const initialRunId = this.deps.newId();
|
|
1536
1555
|
const identityHash = stableHash({
|
|
@@ -1791,6 +1810,7 @@ export class SessionManager {
|
|
|
1791
1810
|
throw new Error('Claimed graph execution target must be a linked child session');
|
|
1792
1811
|
}
|
|
1793
1812
|
await this.assertLinkedChildBoundaryMatchesParent(child.subagentParent.parentSessionId, child.id);
|
|
1813
|
+
const executionPolicy = await this.readExecutionPolicy(child.subagentParent.parentSessionId, child.subagentParent.spawnedBy.parentRunId);
|
|
1794
1814
|
const rootExecution = {
|
|
1795
1815
|
kind: 'claimed_agent_graph_intent',
|
|
1796
1816
|
claim,
|
|
@@ -1933,6 +1953,7 @@ export class SessionManager {
|
|
|
1933
1953
|
: {}),
|
|
1934
1954
|
onRunStarted,
|
|
1935
1955
|
execution: runtimeExecution,
|
|
1956
|
+
...(executionPolicy ? { executionPolicy } : {}),
|
|
1936
1957
|
}),
|
|
1937
1958
|
onReady: notifyReady,
|
|
1938
1959
|
onEvent: (event) => {
|
|
@@ -2053,8 +2074,9 @@ export class SessionManager {
|
|
|
2053
2074
|
const [parentHeader, parentRun, parentBoundary] = await Promise.all([
|
|
2054
2075
|
this.deps.store.readHeader(parentSessionId),
|
|
2055
2076
|
this.readInvocation(parentSessionId, input.spawnedBy.parentRunId),
|
|
2056
|
-
this.
|
|
2077
|
+
this.readExecutionBoundaryForRun(parentSessionId, input.spawnedBy.parentRunId),
|
|
2057
2078
|
]);
|
|
2079
|
+
const executionPolicy = await this.readExecutionPolicy(parentSessionId, input.spawnedBy.parentRunId);
|
|
2058
2080
|
this.assertActiveParentRun(parentSessionId, parentRun, input.spawnedBy.parentTurnId);
|
|
2059
2081
|
const definition = requireBuiltinAgentDefinitionByProfile(input.agentProfile);
|
|
2060
2082
|
const executorId = input.executorId ?? (input.resolvedPreset ? undefined : parentHeader.executorId);
|
|
@@ -2214,6 +2236,7 @@ export class SessionManager {
|
|
|
2214
2236
|
durability: 'required',
|
|
2215
2237
|
onRunStarted,
|
|
2216
2238
|
execution: runtimeOwner.execution,
|
|
2239
|
+
...(executionPolicy ? { executionPolicy } : {}),
|
|
2217
2240
|
}),
|
|
2218
2241
|
onReady: notifyReady,
|
|
2219
2242
|
onEvent: (event) => {
|
|
@@ -2363,8 +2386,11 @@ export class SessionManager {
|
|
|
2363
2386
|
return target;
|
|
2364
2387
|
}
|
|
2365
2388
|
async assertLinkedChildBoundaryMatchesParent(parentSessionId, childSessionId) {
|
|
2389
|
+
const child = await this.deps.store.readHeader(childSessionId);
|
|
2390
|
+
if (!child.subagentParent)
|
|
2391
|
+
throw new Error('Linked child is missing parent provenance');
|
|
2366
2392
|
const [parentBoundary, childBoundary] = await Promise.all([
|
|
2367
|
-
this.
|
|
2393
|
+
this.readExecutionBoundaryForRun(parentSessionId, child.subagentParent.spawnedBy.parentRunId),
|
|
2368
2394
|
this.deps.store.readExecutionBoundary(childSessionId),
|
|
2369
2395
|
]);
|
|
2370
2396
|
if (!executionBoundaryContains(parentBoundary, childBoundary)) {
|
|
@@ -106,9 +106,9 @@ export function toolAvailabilityConnectorNames(tools, config) {
|
|
|
106
106
|
/**
|
|
107
107
|
* Immutable, backend-scoped bound-tool inventory and MiniSearch index.
|
|
108
108
|
*
|
|
109
|
-
* Mutable activation
|
|
110
|
-
*
|
|
111
|
-
*
|
|
109
|
+
* Mutable activation is passed into prepare(). One AiSdkBackend constructs one
|
|
110
|
+
* index; Turns on that backend share the Session activation map so later
|
|
111
|
+
* Turns keep previously activated schemas.
|
|
112
112
|
*/
|
|
113
113
|
export class ToolAvailabilityRuntime {
|
|
114
114
|
invalidTool;
|
|
@@ -249,7 +249,11 @@ export class ToolAvailabilityRuntime {
|
|
|
249
249
|
diagnostics: () => undefined,
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
const
|
|
252
|
+
const requiredNames = [...requiredToolNames].filter((name) => this.toolsByName.has(name));
|
|
253
|
+
const requiredNameSet = new Set(requiredNames);
|
|
254
|
+
// Required names are already on the provider list. Omit them from the
|
|
255
|
+
// search inventory so an exact-name search does not "activate" them again.
|
|
256
|
+
const connector = this.buildSearchConnector(activeTools, requiredNameSet);
|
|
253
257
|
const allTools = [...this.tools, connector];
|
|
254
258
|
const canonical = canonicalizeToolSet(allTools, this.invalidTool);
|
|
255
259
|
const knownNames = new Set(canonical.providerTools.map((tool) => tool.name));
|
|
@@ -260,7 +264,6 @@ export class ToolAvailabilityRuntime {
|
|
|
260
264
|
if (this.activationKeysByName.get(name) !== activatedKey)
|
|
261
265
|
activeTools.delete(name);
|
|
262
266
|
}
|
|
263
|
-
const requiredNames = [...requiredToolNames].filter((name) => knownNames.has(name));
|
|
264
267
|
const step = { active: new Set() };
|
|
265
268
|
const computeActive = () => {
|
|
266
269
|
const names = new Set([...this.directNames, TOOL_SEARCH_NAME]);
|
|
@@ -284,10 +287,10 @@ export class ToolAvailabilityRuntime {
|
|
|
284
287
|
diagnostics: (active, chars) => this.buildDiagnostic(allTools, active, chars),
|
|
285
288
|
};
|
|
286
289
|
}
|
|
287
|
-
buildSearchConnector(activeTools) {
|
|
290
|
+
buildSearchConnector(activeTools, requiredToolNames) {
|
|
288
291
|
return {
|
|
289
292
|
name: TOOL_SEARCH_NAME,
|
|
290
|
-
description: renderInventory(this.groups),
|
|
293
|
+
description: renderInventory(this.groups, requiredToolNames),
|
|
291
294
|
parameters: z.object({
|
|
292
295
|
query: z
|
|
293
296
|
.string()
|
|
@@ -304,7 +307,7 @@ export class ToolAvailabilityRuntime {
|
|
|
304
307
|
}),
|
|
305
308
|
impl: ({ query, limit = TOOL_SEARCH_DEFAULT_LIMIT }, context) => {
|
|
306
309
|
const normalizedQuery = query.trim();
|
|
307
|
-
const ranked = this.rankDeferredSearchHits(normalizedQuery, activeTools);
|
|
310
|
+
const ranked = this.rankDeferredSearchHits(normalizedQuery, activeTools, requiredToolNames);
|
|
308
311
|
const activated = [];
|
|
309
312
|
let blocked;
|
|
310
313
|
let schemaChars = 0;
|
|
@@ -361,14 +364,15 @@ export class ToolAvailabilityRuntime {
|
|
|
361
364
|
* naming one tool cannot invalidate the prompt-cache prefix with up to
|
|
362
365
|
* `TOOL_SEARCH_DEFAULT_LIMIT` extra schemas.
|
|
363
366
|
*/
|
|
364
|
-
rankDeferredSearchHits(query, activeTools) {
|
|
367
|
+
rankDeferredSearchHits(query, activeTools, requiredToolNames) {
|
|
368
|
+
const withheld = (name) => activeTools.has(name) || requiredToolNames.has(name);
|
|
365
369
|
const exactName = this.resolveExactCatalogName(query);
|
|
366
370
|
if (exactName !== undefined) {
|
|
367
|
-
return this.searchableNames.has(exactName) && !
|
|
371
|
+
return this.searchableNames.has(exactName) && !withheld(exactName) ? [exactName] : [];
|
|
368
372
|
}
|
|
369
373
|
return this.searchIndex.search(query)
|
|
370
374
|
.map((result) => String(result.id))
|
|
371
|
-
.filter((name) => !
|
|
375
|
+
.filter((name) => !withheld(name))
|
|
372
376
|
.slice(0, TOOL_SEARCH_MAX_LIMIT)
|
|
373
377
|
.filter((name) => this.searchableNames.has(name));
|
|
374
378
|
}
|
|
@@ -415,11 +419,13 @@ export class ToolAvailabilityRuntime {
|
|
|
415
419
|
};
|
|
416
420
|
}
|
|
417
421
|
}
|
|
418
|
-
function renderInventory(groups) {
|
|
419
|
-
const lines = groups.flatMap((group) =>
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
422
|
+
function renderInventory(groups, omitNames = new Set()) {
|
|
423
|
+
const lines = groups.flatMap((group) => {
|
|
424
|
+
const names = group.toolNames.filter((name) => !omitNames.has(name));
|
|
425
|
+
if (names.length === 0)
|
|
426
|
+
return [];
|
|
427
|
+
return [`${group.id}:`, ...names.map((name) => `- ${name}`)];
|
|
428
|
+
});
|
|
423
429
|
return [
|
|
424
430
|
'Search the deferred tools bound to this run. A successful search activates the',
|
|
425
431
|
'bounded top matches; their complete callable definitions become visible on the',
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The call-data boundary for one tool execution: the argument views a call
|
|
21
|
+
* produces.
|
|
22
|
+
*
|
|
23
|
+
* Extracted from `executeTool()` so the ownership of each rule is named
|
|
24
|
+
* instead of living inline in a thousand-line method. This module owns
|
|
25
|
+
* *construction only* — admission, dispatch identity, publication timing and
|
|
26
|
+
* persistence stay in `executeTool()`.
|
|
27
|
+
*/
|
|
28
|
+
import { computerUseModelCallArgs } from '@maka/core/computer-use';
|
|
29
|
+
/** The recursively frozen, cycle-rejecting argument snapshot. */
|
|
30
|
+
export function snapshotToolArgs(value) {
|
|
31
|
+
return snapshotJsonValue(value, new WeakSet());
|
|
32
|
+
}
|
|
33
|
+
function snapshotJsonValue(value, seen) {
|
|
34
|
+
if (value === null || typeof value !== 'object')
|
|
35
|
+
return value;
|
|
36
|
+
if (seen.has(value))
|
|
37
|
+
throw new Error('Tool arguments must not contain cycles');
|
|
38
|
+
seen.add(value);
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return Object.freeze(value.map((entry) => snapshotJsonValue(entry, seen)));
|
|
41
|
+
}
|
|
42
|
+
const output = {};
|
|
43
|
+
for (const key of Object.keys(value)) {
|
|
44
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
45
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
46
|
+
throw new Error(`Tool argument ${key} must be a plain data property`);
|
|
47
|
+
}
|
|
48
|
+
output[key] = snapshotJsonValue(descriptor.value, seen);
|
|
49
|
+
}
|
|
50
|
+
return Object.freeze(output);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validates call arguments against the tool's declared schema, accepting the
|
|
54
|
+
* schema shapes the runtime already supports (zod `safeParseAsync`/`safeParse`,
|
|
55
|
+
* a `validate` callable, or a standard-schema `~standard.validate`). A tool
|
|
56
|
+
* without a usable schema declares nothing and validates nothing.
|
|
57
|
+
*/
|
|
58
|
+
export async function validateDeclaredToolArgs(parameters, args) {
|
|
59
|
+
if (!parameters || (typeof parameters !== 'object' && typeof parameters !== 'function')) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const schema = parameters;
|
|
63
|
+
if (typeof schema.safeParseAsync === 'function') {
|
|
64
|
+
const parsed = await schema.safeParseAsync(args);
|
|
65
|
+
if (parsed.success)
|
|
66
|
+
return;
|
|
67
|
+
throw parsed.error;
|
|
68
|
+
}
|
|
69
|
+
if (typeof schema.safeParse === 'function') {
|
|
70
|
+
const parsed = schema.safeParse(args);
|
|
71
|
+
if (parsed.success)
|
|
72
|
+
return;
|
|
73
|
+
throw parsed.error;
|
|
74
|
+
}
|
|
75
|
+
if (typeof schema.validate === 'function') {
|
|
76
|
+
const parsed = await schema.validate(args);
|
|
77
|
+
if (parsed.success)
|
|
78
|
+
return;
|
|
79
|
+
throw parsed.error;
|
|
80
|
+
}
|
|
81
|
+
if (typeof schema['~standard']?.validate === 'function') {
|
|
82
|
+
const parsed = await schema['~standard'].validate(args);
|
|
83
|
+
if ('value' in parsed)
|
|
84
|
+
return;
|
|
85
|
+
throw new Error('Tool arguments failed declared schema validation', { cause: parsed.issues });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The named argument-view construction operation: validation, permission
|
|
90
|
+
* projection, and the persisted view, in the order and with the guards the
|
|
91
|
+
* inline region in `executeTool()` established.
|
|
92
|
+
*
|
|
93
|
+
* The args written into the `tool_start` event and the durable ledger are the
|
|
94
|
+
* record of the call the model reads back on its next turn
|
|
95
|
+
* (`model-history.ts` replays `event.content.args`).
|
|
96
|
+
*
|
|
97
|
+
* Computer Use used the host's approval summary there. That projection exists
|
|
98
|
+
* to decide and display a permission: it renames `window_id` to `windowId`,
|
|
99
|
+
* adds `approvalClass` and `rememberForTurnAllowed`, and drops every argument
|
|
100
|
+
* it does not need. On the real ToolRuntime a model that sent
|
|
101
|
+
* {action:'press_key', app, window_id, observation_id, element_id,
|
|
102
|
+
* text:'cmd+s'} read back {action, approvalClass, rememberForTurnAllowed,
|
|
103
|
+
* app, windowId, observationId} — a key the tool rejects, two fields it never
|
|
104
|
+
* sent, no element, and a press_key with no key. It then went on calling it
|
|
105
|
+
* that way.
|
|
106
|
+
*
|
|
107
|
+
* The permission prompt still reads the permission view, and the approval
|
|
108
|
+
* scope key is still computed from the raw call, so the projection only
|
|
109
|
+
* changes what is written down. `computerUseModelCallArgs` keeps the same
|
|
110
|
+
* privacy rule — screen-derived and user-typed values are reduced to a shape
|
|
111
|
+
* — and speaks the tool's own argument names.
|
|
112
|
+
*/
|
|
113
|
+
export async function buildToolCallArgs(input) {
|
|
114
|
+
let permissionArgs = input.executionArgs;
|
|
115
|
+
let permissionArgsError;
|
|
116
|
+
if (!input.directOnlyRejected) {
|
|
117
|
+
try {
|
|
118
|
+
if (!input.validationDeferred) {
|
|
119
|
+
await validateDeclaredToolArgs(input.parameters, input.executionArgs);
|
|
120
|
+
}
|
|
121
|
+
permissionArgs = input.permissionArgs
|
|
122
|
+
? snapshotToolArgs(input.permissionArgs(structuredClone(input.executionArgs), {
|
|
123
|
+
sessionId: input.sessionId,
|
|
124
|
+
turnId: input.turnId,
|
|
125
|
+
toolCallId: input.toolCallId,
|
|
126
|
+
}))
|
|
127
|
+
: input.executionArgs;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
permissionArgsError = error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const persistedArgs = input.categoryHint === 'computer_use'
|
|
134
|
+
? snapshotToolArgs(computerUseModelCallArgs(permissionArgs))
|
|
135
|
+
: permissionArgs;
|
|
136
|
+
return {
|
|
137
|
+
executionArgs: input.executionArgs,
|
|
138
|
+
permissionArgs,
|
|
139
|
+
permissionArgsError,
|
|
140
|
+
persistedArgs,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -23,7 +23,7 @@ import { resolveCollaborationPermissionMode } from '@maka/core/collaboration';
|
|
|
23
23
|
import { serializedByteLength } from '@maka/core/serialized-byte-length';
|
|
24
24
|
import { encodeToolStepProgress, ToolOutcomeUnknownError } from '@maka/core/events';
|
|
25
25
|
import { isInteractionAnswerValidForRequest, projectInteractionFormRequest, } from '@maka/core/interaction';
|
|
26
|
-
import {
|
|
26
|
+
import { buildToolCallArgs, snapshotToolArgs } from './tool-call-snapshot.js';
|
|
27
27
|
import { redactSecrets } from '@maka/core/redaction';
|
|
28
28
|
import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core/runtime-event';
|
|
29
29
|
import { recordToolArtifactsSafely } from './tool-artifacts.js';
|
|
@@ -544,36 +544,30 @@ export class ToolRuntime {
|
|
|
544
544
|
? `Tool ${tool.name} is direct-only and cannot run inside exec.`
|
|
545
545
|
: undefined;
|
|
546
546
|
const admissionFailure = directOnlyFailure ?? this.admitToolForStep(tool, stepId);
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
// Permission args are a policy/UI projection. Persistence and model replay
|
|
572
|
-
// share one canonical tool-dialect projection; Computer Use also strips
|
|
573
|
-
// screen-derived and user-typed values at this boundary.
|
|
574
|
-
const persistedArgs = tool.categoryHint === 'computer_use'
|
|
575
|
-
? snapshotToolArgs(computerUseModelCallArgs(permissionArgs))
|
|
576
|
-
: permissionArgs;
|
|
547
|
+
// An unavailable sandbox-boundary surface cannot carry the expansion the
|
|
548
|
+
// tool requests, and that availability contract holds even when an older
|
|
549
|
+
// caller sends a legacy shape — validation stays deferred for it.
|
|
550
|
+
const sandboxBoundaryUnavailable = tool.name === 'request_sandbox_boundary' &&
|
|
551
|
+
!this.interactionRun() &&
|
|
552
|
+
(!this.input.createSandboxBoundaryRequest || !this.input.settleSandboxBoundaryRequest);
|
|
553
|
+
const callArgs = await buildToolCallArgs({
|
|
554
|
+
toolName: tool.name,
|
|
555
|
+
parameters: tool.parameters,
|
|
556
|
+
categoryHint: tool.categoryHint,
|
|
557
|
+
permissionArgs: tool.permissionArgs,
|
|
558
|
+
// Upstream renamed rawExecutionArgs to executionArgs after this
|
|
559
|
+
// refactor; buildToolCallArgs passes it through unchanged, and the
|
|
560
|
+
// entry snapshot above already holds that same value.
|
|
561
|
+
executionArgs,
|
|
562
|
+
sessionId: this.input.sessionId,
|
|
563
|
+
turnId,
|
|
564
|
+
toolCallId: toolUseId,
|
|
565
|
+
directOnlyRejected: directOnlyFailure !== undefined,
|
|
566
|
+
validationDeferred: sandboxBoundaryUnavailable,
|
|
567
|
+
});
|
|
568
|
+
const permissionArgs = callArgs.permissionArgs;
|
|
569
|
+
const persistedArgs = callArgs.persistedArgs;
|
|
570
|
+
const permissionArgsError = callArgs.permissionArgsError;
|
|
577
571
|
const now = this.input.now();
|
|
578
572
|
const trace = this.input.getRunTrace?.() ?? null;
|
|
579
573
|
const runId = this.input.runId;
|
|
@@ -2068,36 +2062,6 @@ export class ToolRuntime {
|
|
|
2068
2062
|
});
|
|
2069
2063
|
}
|
|
2070
2064
|
}
|
|
2071
|
-
async function validateDeclaredToolArgs(parameters, args) {
|
|
2072
|
-
if (!parameters || (typeof parameters !== 'object' && typeof parameters !== 'function')) {
|
|
2073
|
-
return;
|
|
2074
|
-
}
|
|
2075
|
-
const schema = parameters;
|
|
2076
|
-
if (typeof schema.safeParseAsync === 'function') {
|
|
2077
|
-
const parsed = await schema.safeParseAsync(args);
|
|
2078
|
-
if (parsed.success)
|
|
2079
|
-
return;
|
|
2080
|
-
throw parsed.error;
|
|
2081
|
-
}
|
|
2082
|
-
if (typeof schema.safeParse === 'function') {
|
|
2083
|
-
const parsed = schema.safeParse(args);
|
|
2084
|
-
if (parsed.success)
|
|
2085
|
-
return;
|
|
2086
|
-
throw parsed.error;
|
|
2087
|
-
}
|
|
2088
|
-
if (typeof schema.validate === 'function') {
|
|
2089
|
-
const parsed = await schema.validate(args);
|
|
2090
|
-
if (parsed.success)
|
|
2091
|
-
return;
|
|
2092
|
-
throw parsed.error;
|
|
2093
|
-
}
|
|
2094
|
-
if (typeof schema['~standard']?.validate === 'function') {
|
|
2095
|
-
const parsed = await schema['~standard'].validate(args);
|
|
2096
|
-
if ('value' in parsed)
|
|
2097
|
-
return;
|
|
2098
|
-
throw new Error('Tool arguments failed declared schema validation', { cause: parsed.issues });
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
2065
|
function isInteractionControlError(error) {
|
|
2102
2066
|
return (error instanceof RuntimeInteractionAdmissionRejectedError ||
|
|
2103
2067
|
error instanceof RuntimeInteractionClosedError ||
|
|
@@ -2598,25 +2562,3 @@ function byteLength(value) {
|
|
|
2598
2562
|
const text = typeof value === 'string' ? value : JSON.stringify(value ?? null);
|
|
2599
2563
|
return Buffer.byteLength(text, 'utf8');
|
|
2600
2564
|
}
|
|
2601
|
-
function snapshotToolArgs(value) {
|
|
2602
|
-
return snapshotJsonValue(value, new WeakSet());
|
|
2603
|
-
}
|
|
2604
|
-
function snapshotJsonValue(value, seen) {
|
|
2605
|
-
if (value === null || typeof value !== 'object')
|
|
2606
|
-
return value;
|
|
2607
|
-
if (seen.has(value))
|
|
2608
|
-
throw new Error('Tool arguments must not contain cycles');
|
|
2609
|
-
seen.add(value);
|
|
2610
|
-
if (Array.isArray(value)) {
|
|
2611
|
-
return Object.freeze(value.map((entry) => snapshotJsonValue(entry, seen)));
|
|
2612
|
-
}
|
|
2613
|
-
const output = {};
|
|
2614
|
-
for (const key of Object.keys(value)) {
|
|
2615
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
2616
|
-
if (!descriptor || !('value' in descriptor)) {
|
|
2617
|
-
throw new Error(`Tool argument ${key} must be a plain data property`);
|
|
2618
|
-
}
|
|
2619
|
-
output[key] = snapshotJsonValue(descriptor.value, seen);
|
|
2620
|
-
}
|
|
2621
|
-
return Object.freeze(output);
|
|
2622
|
-
}
|
|
@@ -24203,9 +24203,20 @@ async function openExistingNoTruncate(path2) {
|
|
|
24203
24203
|
}
|
|
24204
24204
|
}
|
|
24205
24205
|
async function writeThroughHandle(handle, content) {
|
|
24206
|
+
const bytes = Buffer.from(content, "utf8");
|
|
24206
24207
|
try {
|
|
24207
24208
|
await handle.truncate(0);
|
|
24208
|
-
|
|
24209
|
+
let offset = 0;
|
|
24210
|
+
while (offset < bytes.length) {
|
|
24211
|
+
const { bytesWritten } = await handle.write(bytes, offset, bytes.length - offset, offset);
|
|
24212
|
+
if (bytesWritten <= 0) {
|
|
24213
|
+
throw new StableWriteFailure(
|
|
24214
|
+
"outcome_unknown",
|
|
24215
|
+
"The write stopped making progress; the file may be truncated. Re-read the file before writing to it again."
|
|
24216
|
+
);
|
|
24217
|
+
}
|
|
24218
|
+
offset += bytesWritten;
|
|
24219
|
+
}
|
|
24209
24220
|
} catch (error62) {
|
|
24210
24221
|
const code = error62.code;
|
|
24211
24222
|
if (code === "ENOSPC" || code === "EIO" || code === "EDQUOT" || code === "EFBIG") {
|
|
@@ -30,7 +30,7 @@ import { abortable, waitForRuntimeHostReady } from './wait-for-ready.js';
|
|
|
30
30
|
// Candidate readiness includes the Windows named-pipe ACL helper, whose
|
|
31
31
|
// fail-closed ceiling is 60s. Leave enough room for election and connection
|
|
32
32
|
// bookkeeping after that helper returns.
|
|
33
|
-
const DEFAULT_ELECTION_DEADLINE_MS = 75_000;
|
|
33
|
+
export const DEFAULT_ELECTION_DEADLINE_MS = 75_000;
|
|
34
34
|
const DEFAULT_BACKOFF_MIN_MS = 20;
|
|
35
35
|
const DEFAULT_BACKOFF_MAX_MS = 250;
|
|
36
36
|
const MIN_CANDIDATE_INTERVAL_MS = 250;
|
|
@@ -251,10 +251,24 @@ export async function connectOrSpawnRuntimeHostWithDependencies(input, dependenc
|
|
|
251
251
|
return result;
|
|
252
252
|
}
|
|
253
253
|
if (isPermanentCandidateStartupFailure(startupFailure) && pendingCandidateReports === 0) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
if (isLaunchElectionLoss(startupFailure)) {
|
|
255
|
+
// Losing the launch election is not a Host failure. It is proof that
|
|
256
|
+
// another candidate holds this root and is still coming up, so the
|
|
257
|
+
// only honest reading is "keep waiting for the one that won".
|
|
258
|
+
// Returning here is what made a slow first startup look permanently
|
|
259
|
+
// unavailable: the desktop saw a failure a second after it asked,
|
|
260
|
+
// while the candidate that owned the root was still loading its
|
|
261
|
+
// transcript store, and every retry looked the same (issue #5843).
|
|
262
|
+
// The loser's startup diagnostic stays on disk, because that trace is
|
|
263
|
+
// what made the storm visible at all; it is simply no longer terminal.
|
|
264
|
+
startupFailure = undefined;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
const selectedFailure = startupFailure;
|
|
268
|
+
electionSettled = true;
|
|
269
|
+
await selectCandidateStartupDiagnostic(capability.rootId, selectedFailure.startupAttemptId).catch(() => undefined);
|
|
270
|
+
return { kind: 'failed', reason: selectedFailure.reason };
|
|
271
|
+
}
|
|
258
272
|
}
|
|
259
273
|
const now = performance.now();
|
|
260
274
|
if (shouldLaunchCandidate(result) &&
|
|
@@ -362,7 +376,7 @@ export async function connectOrSpawnRuntimeHostWithDependencies(input, dependenc
|
|
|
362
376
|
await sleep(Math.min(remaining, Math.max(1, Math.round(backoffMs * jitter))), input.signal);
|
|
363
377
|
backoffMs = Math.min(DEFAULT_BACKOFF_MAX_MS, backoffMs * 2);
|
|
364
378
|
}
|
|
365
|
-
if (startupFailure) {
|
|
379
|
+
if (startupFailure && !isLaunchElectionLoss(startupFailure)) {
|
|
366
380
|
const selectedFailure = startupFailure;
|
|
367
381
|
electionSettled = true;
|
|
368
382
|
await selectCandidateStartupDiagnostic(capability.rootId, selectedFailure.startupAttemptId).catch(() => undefined);
|
|
@@ -387,6 +401,16 @@ export async function connectOrSpawnRuntimeHostWithDependencies(input, dependenc
|
|
|
387
401
|
electionSettled = true;
|
|
388
402
|
}
|
|
389
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* A Candidate that lost the launch election is evidence about *another*
|
|
406
|
+
* Candidate - it holds the root and is still coming up - so the loss must never
|
|
407
|
+
* decide how this election ends, whether the loop breaks on it or the window
|
|
408
|
+
* simply runs out. Failing on it made a slow first startup look like a
|
|
409
|
+
* permanently unavailable Host (issue #5843).
|
|
410
|
+
*/
|
|
411
|
+
function isLaunchElectionLoss(failure) {
|
|
412
|
+
return failure?.reason === 'launch_election_lost';
|
|
413
|
+
}
|
|
390
414
|
function recordElectionResult(result, observations) {
|
|
391
415
|
observations.totalResults += 1;
|
|
392
416
|
const registration = 'registration' in result ? result.registration : undefined;
|
|
@@ -34,7 +34,7 @@ export { RuntimeHostSubscriptionError, SessionRemovedSubscriptionError, subscrip
|
|
|
34
34
|
export { RuntimeHostStartupError, runtimeHostStartupError, } from './startup-error.js';
|
|
35
35
|
export { connectRuntimeHostWslEnvironment, listRuntimeHostWslDistributions, normalizeRuntimeHostWslDistribution, resolveSystemRuntimeHostWslExecutable, } from './wsl-environment.js';
|
|
36
36
|
export { RuntimeHostCatalogReadError, RuntimeHostSessionCatalogRevisionChangedError, readRuntimeHostConnectionCatalog, readRuntimeHostInvocableSkills, readRuntimeHostProjectDetails, readRuntimeHostResources, readRuntimeHostProjects, readRuntimeHostSessionCatalogPage, readRuntimeHostSessions, readRuntimeHostSkillCatalog, } from './catalog-reader.js';
|
|
37
|
-
export { IDLE_GRACE_MS_ENV_VAR, connectOrSpawnRuntimeHost, } from './connect-or-spawn.js';
|
|
37
|
+
export { DEFAULT_ELECTION_DEADLINE_MS, ELECTION_DEADLINE_MS_ENV_VAR, IDLE_GRACE_MS_ENV_VAR, connectOrSpawnRuntimeHost, electionDeadlineMsFromEnvironment, } from './connect-or-spawn.js';
|
|
38
38
|
export { abortable, waitForRuntimeHostReady } from './wait-for-ready.js';
|
|
39
39
|
export { createRuntimeHostCandidateLaunchBarrier, } from './candidate-launch-barrier.js';
|
|
40
40
|
export { runHostedExecution } from './hosted-execution.js';
|
|
@@ -65,7 +65,8 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
65
65
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
66
66
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
67
67
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
68
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
68
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 215;
|
|
69
|
+
// 215: WorkHub coordination uses canonical configuration and scoped delegated permissions.
|
|
69
70
|
// 212: Session catalogs carry `backgroundActivity` and `backgroundActivityVersion`
|
|
70
71
|
// for Host-owned activity and generation-scoped ordering independent of Session
|
|
71
72
|
// revisions and Turn epochs. Older closed decoders reject these fields.
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { invalidProtocolFrame } from './errors.js';
|
|
20
|
-
import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireId, requireRecord, requireShapedRecord, } from './codec.js';
|
|
20
|
+
import { assertExactKeys, requireCount, requireEncodedByteLimit, requireEntityId, requireExactRecord, requireId, requireRecord, requireShapedRecord, } from './codec.js';
|
|
21
21
|
import { defineOperation } from './operation-spec.js';
|
|
22
22
|
import { decodeMessageAdmissionContent, decodeSkillIds, decodeTurnOrchestration, decodeTurnSnapshot, } from './turn.js';
|
|
23
23
|
import { decodeSkillInvocationResult } from '@maka/core/skill-invocation';
|
|
@@ -377,15 +377,3 @@ function assertUniqueQueueEntries(entries, label) {
|
|
|
377
377
|
messageIds.add(entry.messageId);
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
function requireEncodedByteLimit(value, label, maxBytes) {
|
|
381
|
-
let encoded;
|
|
382
|
-
try {
|
|
383
|
-
encoded = JSON.stringify(value);
|
|
384
|
-
}
|
|
385
|
-
catch {
|
|
386
|
-
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
387
|
-
}
|
|
388
|
-
if (encoded === undefined || Buffer.byteLength(encoded, 'utf8') > maxBytes) {
|
|
389
|
-
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { TOOL_ACTIVITY_KINDS, TOOL_OUTPUT_DELTA_MAX_CHARS } from '@maka/core/events';
|
|
20
20
|
import { decodeToolResultPreviewContent } from '@maka/core/tool-result-preview';
|
|
21
|
-
import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireId, requireOpaqueIdentity, requireRecord, } from './codec.js';
|
|
21
|
+
import { assertExactKeys, requireCount, requireEncodedByteLimit, requireEntityId, requireExactRecord, requireId, requireOpaqueIdentity, requireRecord, } from './codec.js';
|
|
22
22
|
import { invalidProtocolFrame } from './errors.js';
|
|
23
23
|
import { decodeSessionStatus } from './session-status.js';
|
|
24
24
|
import { decodeSessionInteractionProjection, } from './interaction.js';
|
|
@@ -773,18 +773,6 @@ function requireUtf8BoundedString(value, label, maxBytes) {
|
|
|
773
773
|
}
|
|
774
774
|
return value;
|
|
775
775
|
}
|
|
776
|
-
function requireEncodedByteLimit(value, label, maxBytes) {
|
|
777
|
-
let encoded;
|
|
778
|
-
try {
|
|
779
|
-
encoded = JSON.stringify(value);
|
|
780
|
-
}
|
|
781
|
-
catch {
|
|
782
|
-
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
783
|
-
}
|
|
784
|
-
if (encoded === undefined || Buffer.byteLength(encoded, 'utf8') > maxBytes) {
|
|
785
|
-
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
776
|
/**
|
|
789
777
|
* Read against the one list rather than a copy of it.
|
|
790
778
|
*
|