maka-agent 0.2.0-dev.6.20260830 → 0.2.0-dev.9.20260831
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-core.js +11 -0
- package/dist/runtime-host-cli.js +44 -0
- package/dist/runtime-host-installed-update-activator.js +70 -33
- package/dist/runtime-host-installed-update-coordinator.js +11 -96
- package/dist/runtime-host-lifecycle-transaction.js +2 -0
- package/dist/runtime-host-local-handoff.js +169 -38
- package/dist/runtime-host-local-source-retirement.js +103 -0
- package/dist/runtime-host-local-target-activation.js +141 -0
- package/dist/runtime-host-peer-management-command.js +10 -4
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/node_modules/@maka/core/dist/agent-run.js +0 -2
- package/node_modules/@maka/core/dist/artifacts.js +23 -15
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +124 -0
- package/node_modules/@maka/core/dist/foreign-session.js +1 -1
- package/node_modules/@maka/core/dist/llm-connections.js +20 -0
- package/node_modules/@maka/core/dist/runtime-event.js +28 -3
- package/node_modules/@maka/core/dist/session-name.js +0 -1
- package/node_modules/@maka/core/dist/task-ledger.js +6 -134
- package/node_modules/@maka/core/dist/usage-record-schema.js +1 -0
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +97 -133
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +4 -18
- package/node_modules/@maka/runtime/dist/context-budget.js +0 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +67 -0
- package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +390 -0
- package/node_modules/@maka/runtime/dist/model-history.js +12 -39
- package/node_modules/@maka/runtime/dist/plan-mode.js +0 -65
- package/node_modules/@maka/runtime/dist/recovery-resolver.js +18 -14
- package/node_modules/@maka/runtime/dist/run-trace.js +0 -10
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +0 -1
- package/node_modules/@maka/runtime/dist/sandbox/index.js +0 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +0 -12
- package/node_modules/@maka/runtime/dist/sandbox/macos-seatbelt.js +0 -12
- package/node_modules/@maka/runtime/dist/sandbox/sandbox-manager.js +0 -35
- package/node_modules/@maka/runtime/dist/sandbox/windows-sandbox.js +0 -12
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +20 -11
- package/node_modules/@maka/runtime/dist/session-manager.js +0 -170
- package/node_modules/@maka/runtime/dist/shell-detect.js +3 -7
- package/node_modules/@maka/runtime/dist/shell-run-contract.js +0 -1
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +1 -39
- package/node_modules/@maka/runtime/dist/shell-tools.js +1 -1
- package/node_modules/@maka/runtime/dist/task-ledger-tools.js +2 -2
- package/node_modules/@maka/runtime/dist/tool-runtime.js +118 -71
- package/node_modules/@maka/runtime/package.json +1 -1
- package/node_modules/@maka/runtime-host/dist/candidate-entry.js +6 -1
- package/node_modules/@maka/runtime-host/dist/candidate-launch-owner-guard.js +13 -0
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +4 -1
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +27 -1
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +8 -2
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +11 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +394 -113
- package/node_modules/@maka/runtime-host/dist/peer-mesh/store.js +90 -21
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/oauth.js +60 -7
- package/node_modules/@maka/runtime-host/dist/protocol/usage-pricing.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/artifact-coordinator.js +2 -4
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/client-capability-recovery.js +10 -7
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +6 -9
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +9 -7
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +10 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +2 -58
- package/node_modules/@maka/runtime-host/dist/server/oauth-coordinator.js +91 -42
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +10 -1
- package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +45 -5
- package/node_modules/@maka/storage/dist/artifact-attachments.js +62 -11
- package/node_modules/@maka/storage/dist/artifact-store.js +11 -0
- package/node_modules/@maka/storage/dist/artifact-stores.js +4 -1
- package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1154 -0
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +36 -0
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +213 -46
- package/node_modules/@maka/storage/dist/runtime-policy/document-io.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-policy/oauth-login-receipt-document.js +186 -0
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +120 -1
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +2 -1
- package/node_modules/@maka/storage/dist/session-bundle-ustar.js +12 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +5 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/sandbox/diagnostics.js +0 -285
- package/node_modules/@maka/runtime/dist/system-prompt/sandbox-context-prompt.js +0 -77
- package/node_modules/@maka/runtime/dist/system-prompt/session-environment-prompt.js +0 -47
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
import { isCanonicalStorageRef } from './events.js';
|
|
20
|
+
import { isCanonicalArtifactEntityId, normalizeArtifactImagePreviewMime } from './artifacts.js';
|
|
21
|
+
import { hasExactShape, isRecord } from './record-schema.js';
|
|
22
|
+
import { serializedByteLength } from './serialized-byte-length.js';
|
|
23
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_VERSION = 1;
|
|
24
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_MAX_BYTES = 256 * 1024;
|
|
25
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_MAX_PARTS = 64;
|
|
26
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_DEPTH = 32;
|
|
27
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_NODES = 20_000;
|
|
28
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_FAILURE_MESSAGE = 'The tool completed, but its model-visible result could not be projected safely.';
|
|
29
|
+
export const DURABLE_TOOL_RESULT_PROJECTION_FAILURE = Object.freeze({
|
|
30
|
+
version: DURABLE_TOOL_RESULT_PROJECTION_VERSION,
|
|
31
|
+
kind: 'failure',
|
|
32
|
+
reason: 'projection_failed',
|
|
33
|
+
message: DURABLE_TOOL_RESULT_PROJECTION_FAILURE_MESSAGE,
|
|
34
|
+
});
|
|
35
|
+
export function decodeDurableToolResultProjection(value) {
|
|
36
|
+
if (!isDurableToolResultProjection(value) ||
|
|
37
|
+
serializedByteLength(value, DURABLE_TOOL_RESULT_PROJECTION_MAX_BYTES) >
|
|
38
|
+
DURABLE_TOOL_RESULT_PROJECTION_MAX_BYTES) {
|
|
39
|
+
throw new Error('Invalid durable Tool Result projection');
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function isDurableToolResultProjection(value) {
|
|
44
|
+
if (!isRecord(value) || value.version !== DURABLE_TOOL_RESULT_PROJECTION_VERSION)
|
|
45
|
+
return false;
|
|
46
|
+
switch (value.kind) {
|
|
47
|
+
case 'text':
|
|
48
|
+
return (hasExactShape(value, {
|
|
49
|
+
required: ['version', 'kind', 'text'],
|
|
50
|
+
allowed: new Set(['version', 'kind', 'text', 'isError']),
|
|
51
|
+
}) &&
|
|
52
|
+
typeof value.text === 'string' &&
|
|
53
|
+
(value.isError === undefined || value.isError === true));
|
|
54
|
+
case 'json':
|
|
55
|
+
return (hasExactShape(value, {
|
|
56
|
+
required: ['version', 'kind', 'value'],
|
|
57
|
+
allowed: new Set(['version', 'kind', 'value', 'isError']),
|
|
58
|
+
}) &&
|
|
59
|
+
isDurableProjectionJson(value.value, { nodes: 0 }, 0) &&
|
|
60
|
+
(value.isError === undefined || value.isError === true));
|
|
61
|
+
case 'content':
|
|
62
|
+
return (hasExactShape(value, {
|
|
63
|
+
required: ['version', 'kind', 'parts'],
|
|
64
|
+
allowed: new Set(['version', 'kind', 'parts']),
|
|
65
|
+
}) &&
|
|
66
|
+
Array.isArray(value.parts) &&
|
|
67
|
+
value.parts.length > 0 &&
|
|
68
|
+
value.parts.length <= DURABLE_TOOL_RESULT_PROJECTION_MAX_PARTS &&
|
|
69
|
+
value.parts.every(isProjectionPart));
|
|
70
|
+
case 'execution_denied':
|
|
71
|
+
return (hasExactShape(value, {
|
|
72
|
+
required: ['version', 'kind'],
|
|
73
|
+
allowed: new Set(['version', 'kind', 'reason']),
|
|
74
|
+
}) &&
|
|
75
|
+
(value.reason === undefined || typeof value.reason === 'string'));
|
|
76
|
+
case 'failure':
|
|
77
|
+
return (hasExactShape(value, {
|
|
78
|
+
required: ['version', 'kind', 'reason', 'message'],
|
|
79
|
+
allowed: new Set(['version', 'kind', 'reason', 'message']),
|
|
80
|
+
}) &&
|
|
81
|
+
value.reason === 'projection_failed' &&
|
|
82
|
+
value.message === DURABLE_TOOL_RESULT_PROJECTION_FAILURE_MESSAGE);
|
|
83
|
+
default:
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function isProjectionPart(value) {
|
|
88
|
+
if (!isRecord(value))
|
|
89
|
+
return false;
|
|
90
|
+
if (value.kind === 'text') {
|
|
91
|
+
return (hasExactShape(value, {
|
|
92
|
+
required: ['kind', 'text'],
|
|
93
|
+
allowed: new Set(['kind', 'text']),
|
|
94
|
+
}) && typeof value.text === 'string');
|
|
95
|
+
}
|
|
96
|
+
return (value.kind === 'artifact' &&
|
|
97
|
+
hasExactShape(value, {
|
|
98
|
+
required: ['kind', 'mediaType', 'ref'],
|
|
99
|
+
allowed: new Set(['kind', 'mediaType', 'ref']),
|
|
100
|
+
}) &&
|
|
101
|
+
typeof value.mediaType === 'string' &&
|
|
102
|
+
normalizeArtifactImagePreviewMime(value.mediaType) === value.mediaType &&
|
|
103
|
+
isCanonicalStorageRef(value.ref) &&
|
|
104
|
+
(value.ref.kind === 'session_context' ||
|
|
105
|
+
(value.ref.kind === 'session_file' && isCanonicalArtifactEntityId(value.ref.relativePath))));
|
|
106
|
+
}
|
|
107
|
+
function isDurableProjectionJson(value, state, depth) {
|
|
108
|
+
state.nodes += 1;
|
|
109
|
+
if (state.nodes > DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_NODES ||
|
|
110
|
+
depth > DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_DEPTH) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (value === null ||
|
|
114
|
+
typeof value === 'string' ||
|
|
115
|
+
typeof value === 'boolean' ||
|
|
116
|
+
(typeof value === 'number' && Number.isFinite(value))) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(value)) {
|
|
120
|
+
return value.every((item) => isDurableProjectionJson(item, state, depth + 1));
|
|
121
|
+
}
|
|
122
|
+
return (isRecord(value) &&
|
|
123
|
+
Object.values(value).every((item) => isDurableProjectionJson(item, state, depth + 1)));
|
|
124
|
+
}
|
|
@@ -518,7 +518,7 @@ export function stripEnvelopeTags(text) {
|
|
|
518
518
|
}
|
|
519
519
|
/**
|
|
520
520
|
* Render a digest as an explicitly-untrusted data block for the handoff
|
|
521
|
-
* prompt. The envelope wording mirrors the
|
|
521
|
+
* prompt. The envelope wording mirrors the untrusted-context discipline:
|
|
522
522
|
* contents are reference data, never instructions. `safe()` is the
|
|
523
523
|
* authoritative gate every foreign-authored scalar passes through here —
|
|
524
524
|
* regardless of how the digest was built — sanitizing (NFC, control/bidi/
|
|
@@ -296,6 +296,26 @@ export function deriveConnectionSlug(providerType, existingSlugs = []) {
|
|
|
296
296
|
return candidate;
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
|
+
/** Stable human-facing slug base for one interactive OAuth Connection. */
|
|
300
|
+
export function interactiveOAuthConnectionSlugBase(providerType) {
|
|
301
|
+
switch (providerType) {
|
|
302
|
+
case 'openai-codex':
|
|
303
|
+
return 'codex-subscription';
|
|
304
|
+
case 'xai-oauth':
|
|
305
|
+
return 'xai-oauth';
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/** Derive an unused OAuth Connection slug without moving allocation into a surface. */
|
|
309
|
+
export function deriveInteractiveOAuthConnectionSlug(providerType, existingSlugs = []) {
|
|
310
|
+
const base = interactiveOAuthConnectionSlugBase(providerType);
|
|
311
|
+
if (!existingSlugs.includes(base))
|
|
312
|
+
return base;
|
|
313
|
+
for (let suffix = 2;; suffix += 1) {
|
|
314
|
+
const candidate = `${base}-${suffix}`;
|
|
315
|
+
if (!existingSlugs.includes(candidate))
|
|
316
|
+
return candidate;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
299
319
|
/**
|
|
300
320
|
* PR-UI-IPC-1 (@kenji msg 35260e29 + 2e495eb7): connection `baseUrl`
|
|
301
321
|
* scheme allowlist gate.
|
|
@@ -39,6 +39,7 @@ import { isPermissionDecisionFields, isPermissionRequestPayload, isUserQuestionR
|
|
|
39
39
|
import { isTokenUsageFields } from './usage-record-schema.js';
|
|
40
40
|
import { isToolRecoveryFactEnvelope } from './tool-recovery-fact.js';
|
|
41
41
|
import { isRuntimeEventWorkspaceFactEnvelope, } from './workspace-version-authority.js';
|
|
42
|
+
import { decodeDurableToolResultProjection, } from './durable-tool-result-projection.js';
|
|
42
43
|
// ============================================================================
|
|
43
44
|
// Role / Author / Status
|
|
44
45
|
// ============================================================================
|
|
@@ -170,7 +171,7 @@ const TEXT_CONTENT_SHAPE = defineObjectShape()(['kind', 'text'], [
|
|
|
170
171
|
]);
|
|
171
172
|
const THINKING_CONTENT_SHAPE = defineObjectShape()(['kind', 'text'], ['signature', 'providerOptions']);
|
|
172
173
|
const FUNCTION_CALL_CONTENT_SHAPE = defineObjectShape()(['kind', 'id', 'name', 'args'], ['providerOptions', 'providerExecuted']);
|
|
173
|
-
const FUNCTION_RESPONSE_CONTENT_SHAPE = defineObjectShape()(['kind', 'id', 'name', 'result'], ['isError', 'providerExecuted', 'providerOutput']);
|
|
174
|
+
const FUNCTION_RESPONSE_CONTENT_SHAPE = defineObjectShape()(['kind', 'id', 'name', 'result'], ['isError', 'providerExecuted', 'providerOutput', 'modelProjection']);
|
|
174
175
|
const ERROR_CONTENT_SHAPE = defineObjectShape()(['kind', 'message'], ['code', 'reason', 'details']);
|
|
175
176
|
const RUNTIME_ACTIONS_SHAPE = defineObjectShape()([], [
|
|
176
177
|
'stateDelta',
|
|
@@ -203,7 +204,7 @@ const RUNTIME_TOOL_DISPATCH_SHAPE = defineObjectShape()([
|
|
|
203
204
|
'toolName',
|
|
204
205
|
'canonicalArgsHash',
|
|
205
206
|
'recoveryMode',
|
|
206
|
-
], ['managedMutation']);
|
|
207
|
+
], ['managedMutation', 'resultProjectionVersion']);
|
|
207
208
|
const RUNTIME_MANAGED_WORKSPACE_MUTATION_SHAPE = defineObjectShape()([
|
|
208
209
|
'protocol',
|
|
209
210
|
'repositoryId',
|
|
@@ -293,6 +294,7 @@ export function decodeRuntimeEvent(value) {
|
|
|
293
294
|
!isOptionalMember(value.modelVisibility, RUNTIME_EVENT_MODEL_VISIBILITIES) ||
|
|
294
295
|
(value.status !== undefined && !isRuntimeEventStatus(value.status)) ||
|
|
295
296
|
(value.content !== undefined && !isRuntimeEventContent(value.content)) ||
|
|
297
|
+
!hasOwnedModelProjection(value.content, value.sessionId) ||
|
|
296
298
|
(value.actions !== undefined && !isRuntimeEventActions(value.actions)) ||
|
|
297
299
|
(value.refs !== undefined && !isRuntimeEventRefs(value.refs))) {
|
|
298
300
|
throw new Error('Invalid RuntimeEvent schema');
|
|
@@ -312,6 +314,17 @@ export function decodeRuntimeEvent(value) {
|
|
|
312
314
|
}
|
|
313
315
|
return value;
|
|
314
316
|
}
|
|
317
|
+
function hasOwnedModelProjection(content, sessionId) {
|
|
318
|
+
if (!isRecord(content) || content.kind !== 'function_response')
|
|
319
|
+
return true;
|
|
320
|
+
const projection = content.modelProjection;
|
|
321
|
+
if (!isRecord(projection) || projection.kind !== 'content' || !Array.isArray(projection.parts)) {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
return projection.parts.every((part) => !isRecord(part) ||
|
|
325
|
+
part.kind !== 'artifact' ||
|
|
326
|
+
(isRecord(part.ref) && part.ref.sessionId === sessionId));
|
|
327
|
+
}
|
|
315
328
|
function isRuntimeEventContent(value) {
|
|
316
329
|
if (!isRecord(value))
|
|
317
330
|
return false;
|
|
@@ -350,7 +363,9 @@ function isRuntimeEventContent(value) {
|
|
|
350
363
|
typeof value.name === 'string' &&
|
|
351
364
|
Object.hasOwn(value, 'result') &&
|
|
352
365
|
(value.isError === undefined || typeof value.isError === 'boolean') &&
|
|
353
|
-
(value.providerExecuted === undefined || typeof value.providerExecuted === 'boolean')
|
|
366
|
+
(value.providerExecuted === undefined || typeof value.providerExecuted === 'boolean') &&
|
|
367
|
+
(value.modelProjection === undefined ||
|
|
368
|
+
decodesDurableToolResultProjection(value.modelProjection)));
|
|
354
369
|
case 'error':
|
|
355
370
|
return (hasExactShape(value, ERROR_CONTENT_SHAPE) &&
|
|
356
371
|
isOptionalString(value.code) &&
|
|
@@ -361,6 +376,15 @@ function isRuntimeEventContent(value) {
|
|
|
361
376
|
return false;
|
|
362
377
|
}
|
|
363
378
|
}
|
|
379
|
+
function decodesDurableToolResultProjection(value) {
|
|
380
|
+
try {
|
|
381
|
+
decodeDurableToolResultProjection(value);
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
364
388
|
function isTurnOrigin(value) {
|
|
365
389
|
return decodeTurnOrigin(value) !== undefined;
|
|
366
390
|
}
|
|
@@ -439,6 +463,7 @@ function isRuntimeToolDispatch(value) {
|
|
|
439
463
|
return (isRecord(value) &&
|
|
440
464
|
hasExactShape(value, RUNTIME_TOOL_DISPATCH_SHAPE) &&
|
|
441
465
|
value.protocol === TOOL_BOUNDARY_PROTOCOL_V1 &&
|
|
466
|
+
(value.resultProjectionVersion === undefined || value.resultProjectionVersion === 1) &&
|
|
442
467
|
typeof value.operationId === 'string' &&
|
|
443
468
|
typeof value.providerToolCallId === 'string' &&
|
|
444
469
|
typeof value.toolName === 'string' &&
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
* module so every write path can call it:
|
|
31
31
|
* - `sessions:create` IPC → runtime.create → store.create
|
|
32
32
|
* - `sessions:rename` IPC → runtime.renameSession → store.rename
|
|
33
|
-
* - `sessions:branchFromTurn` IPC → runtime.branchFromTurn → store.create
|
|
34
33
|
*
|
|
35
34
|
* Pipeline (applied in order):
|
|
36
35
|
* 1. **Runtime type guard**: `typeof input !== 'string'` → typed
|
|
@@ -17,31 +17,24 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
// Session-scoped task ledger primitive for the main agent. The model manages a
|
|
20
|
-
// flat task list via task_create/task_update
|
|
21
|
-
//
|
|
20
|
+
// flat task list via task_create/task_update and reads it through task_list/task_get.
|
|
21
|
+
// The durable contract is intentionally narrow: task status,
|
|
22
22
|
// compact evidence/reason fields, append-only task events, and conservative
|
|
23
23
|
// resume trust diagnostics. Priority, dependencies, and assignee fields remain
|
|
24
24
|
// out of scope.
|
|
25
25
|
import { redactSecrets } from './redaction.js';
|
|
26
26
|
export const TASK_SUBJECT_MAX_CHARS = 200;
|
|
27
27
|
export const TASK_EVIDENCE_MAX_CHARS = 1000;
|
|
28
|
-
/**
|
|
29
|
-
* Hard cap on total tasks per session ledger (any status). The full ledger is
|
|
30
|
-
* re-injected into every turn tail, so an unbounded ledger burns context on
|
|
31
|
-
* every turn; this is a runaway guard on the total count, not a workflow quota
|
|
32
|
-
* — completing or cancelling tasks does not free capacity.
|
|
33
|
-
*/
|
|
28
|
+
/** Hard cap on total tasks per session ledger (any status). */
|
|
34
29
|
export const TASK_LEDGER_MAX_TASKS = 200;
|
|
35
30
|
export const TASK_ARCHIVE_AFTER_MS = 7 * 24 * 60 * 60 * 1000;
|
|
36
31
|
/**
|
|
37
32
|
* Max length of a task id accepted on both the write and read paths. The write
|
|
38
33
|
* path generates randomUUID (36 chars); the bound leaves headroom for a future
|
|
39
|
-
* id format while keeping
|
|
34
|
+
* id format while keeping model-visible fielded renders bounded.
|
|
40
35
|
*/
|
|
41
36
|
export const TASK_ID_MAX_CHARS = 64;
|
|
42
37
|
export const TASK_KEY_MAX_CHARS = 64;
|
|
43
|
-
export const TASK_LEDGER_PROMPT_MAX_CHARS = 8_000;
|
|
44
|
-
export const TASK_LEDGER_PROMPT_RECENT_TERMINAL = 3;
|
|
45
38
|
export const TASK_STATUSES = [
|
|
46
39
|
'pending',
|
|
47
40
|
'in_progress',
|
|
@@ -74,7 +67,7 @@ export function isResumeTrust(value) {
|
|
|
74
67
|
* ever rendered it: no angle brackets/slashes/quotes/parens/equals (a past
|
|
75
68
|
* whole-string tag strip would have eaten them; even the fielded renderer
|
|
76
69
|
* emits the id bare), no whitespace (would break the list-line structure), no
|
|
77
|
-
* huge length (would bloat
|
|
70
|
+
* huge length (would bloat model-visible results), and redaction-stable (a renderer
|
|
78
71
|
* that runs redactSecrets must not turn the id into [redacted] while the store
|
|
79
72
|
* keeps the real id -- a later task_update would miss). The whitelist
|
|
80
73
|
* (alphanumeric plus . _ : -, 1-64 chars) plus redactSecrets(id) === id enforces
|
|
@@ -95,19 +88,6 @@ export function isTaskKey(value) {
|
|
|
95
88
|
value.length <= TASK_KEY_MAX_CHARS &&
|
|
96
89
|
/^T[1-9]\d*(?:\.[1-9]\d*)*$/.test(value));
|
|
97
90
|
}
|
|
98
|
-
export function compareTaskKeys(left, right) {
|
|
99
|
-
const a = left.slice(1).split('.').map(Number);
|
|
100
|
-
const b = right.slice(1).split('.').map(Number);
|
|
101
|
-
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
102
|
-
if (a[index] === undefined)
|
|
103
|
-
return -1;
|
|
104
|
-
if (b[index] === undefined)
|
|
105
|
-
return 1;
|
|
106
|
-
if (a[index] !== b[index])
|
|
107
|
-
return a[index] - b[index];
|
|
108
|
-
}
|
|
109
|
-
return 0;
|
|
110
|
-
}
|
|
111
91
|
export function findTaskByRef(tasks, ref) {
|
|
112
92
|
return tasks.find((task) => task.id === ref || task.key === ref);
|
|
113
93
|
}
|
|
@@ -398,7 +378,7 @@ function validateTaskLedgerEventType(event, current) {
|
|
|
398
378
|
}
|
|
399
379
|
/**
|
|
400
380
|
* Safe-render the task ledger for any face that persists into history or is
|
|
401
|
-
*
|
|
381
|
+
* included in a model-visible tool result. Two invariants:
|
|
402
382
|
* - the canonical id is rendered verbatim, and the subject is a safe
|
|
403
383
|
* (redacted, tag-stripped) rendered payload of what the store holds; and
|
|
404
384
|
* - the model can unambiguously recover each task's id from what it sees, so
|
|
@@ -456,114 +436,6 @@ export function sanitizeTaskLedgerTask(task) {
|
|
|
456
436
|
: {}),
|
|
457
437
|
};
|
|
458
438
|
}
|
|
459
|
-
export function renderTaskLedgerPromptText(tasks, maxChars = TASK_LEDGER_PROMPT_MAX_CHARS) {
|
|
460
|
-
const byId = new Map(tasks.map((task) => [task.id, task]));
|
|
461
|
-
const selected = new Set();
|
|
462
|
-
const addWithAncestors = (task) => {
|
|
463
|
-
const chain = [];
|
|
464
|
-
let current = task;
|
|
465
|
-
const seen = new Set();
|
|
466
|
-
while (current && !seen.has(current.id)) {
|
|
467
|
-
seen.add(current.id);
|
|
468
|
-
chain.unshift(current);
|
|
469
|
-
current = current.parentId ? byId.get(current.parentId) : undefined;
|
|
470
|
-
}
|
|
471
|
-
for (const item of chain)
|
|
472
|
-
selected.add(item.id);
|
|
473
|
-
};
|
|
474
|
-
const active = tasks
|
|
475
|
-
.filter((task) => !isTerminalTaskStatus(task.status))
|
|
476
|
-
.sort(compareTaskPromptPriority);
|
|
477
|
-
for (const task of active)
|
|
478
|
-
addWithAncestors(task);
|
|
479
|
-
const recentTerminal = tasks
|
|
480
|
-
.filter((task) => isTerminalTaskStatus(task.status) && task.status !== 'cancelled')
|
|
481
|
-
.sort((a, b) => (b.endedAt ?? b.updatedAt) - (a.endedAt ?? a.updatedAt) || compareTaskKeys(a.key, b.key))
|
|
482
|
-
.slice(0, TASK_LEDGER_PROMPT_RECENT_TERMINAL);
|
|
483
|
-
for (const task of recentTerminal)
|
|
484
|
-
addWithAncestors(task);
|
|
485
|
-
const chosen = tasks.filter((task) => selected.has(task.id));
|
|
486
|
-
const ordered = orderTaskTree(chosen);
|
|
487
|
-
const lines = [];
|
|
488
|
-
const included = [];
|
|
489
|
-
const includedIds = new Set();
|
|
490
|
-
for (const task of ordered) {
|
|
491
|
-
if (task.parentId && !includedIds.has(task.parentId))
|
|
492
|
-
continue;
|
|
493
|
-
const depth = task.key.split('.').length - 1;
|
|
494
|
-
const fields = [
|
|
495
|
-
`key=${task.key}`,
|
|
496
|
-
`status=${task.status}`,
|
|
497
|
-
`subject=${JSON.stringify(safeTaskLedgerField(task.subject))}`,
|
|
498
|
-
];
|
|
499
|
-
if (task.blockedReason)
|
|
500
|
-
fields.push(`blockedReason=${JSON.stringify(safeTaskLedgerField(task.blockedReason))}`);
|
|
501
|
-
if (task.failureReason)
|
|
502
|
-
fields.push(`failureReason=${JSON.stringify(safeTaskLedgerField(task.failureReason))}`);
|
|
503
|
-
if (task.completionEvidence)
|
|
504
|
-
fields.push(`completionEvidence=${JSON.stringify(safeTaskLedgerField(task.completionEvidence))}`);
|
|
505
|
-
if (task.owner)
|
|
506
|
-
fields.push(`owner=${JSON.stringify(task.owner)}`);
|
|
507
|
-
const line = `${' '.repeat(depth)}${fields.join(' ')}`;
|
|
508
|
-
const nextLength = lines.length === 0 ? line.length : lines.join('\n').length + 1 + line.length;
|
|
509
|
-
if (nextLength > maxChars)
|
|
510
|
-
continue;
|
|
511
|
-
lines.push(line);
|
|
512
|
-
included.push(task);
|
|
513
|
-
includedIds.add(task.id);
|
|
514
|
-
}
|
|
515
|
-
return {
|
|
516
|
-
text: lines.join('\n'),
|
|
517
|
-
included,
|
|
518
|
-
omittedCount: tasks.length - included.length,
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
function compareTaskPromptPriority(left, right) {
|
|
522
|
-
return (taskStatusRank(left.status) - taskStatusRank(right.status) ||
|
|
523
|
-
compareTaskKeys(left.key, right.key));
|
|
524
|
-
}
|
|
525
|
-
function orderTaskTree(tasks) {
|
|
526
|
-
const byParent = new Map();
|
|
527
|
-
for (const task of tasks) {
|
|
528
|
-
const bucket = byParent.get(task.parentId) ?? [];
|
|
529
|
-
bucket.push(task);
|
|
530
|
-
byParent.set(task.parentId, bucket);
|
|
531
|
-
}
|
|
532
|
-
const branchRanks = new Map();
|
|
533
|
-
const branchRank = (task) => {
|
|
534
|
-
const cached = branchRanks.get(task.id);
|
|
535
|
-
if (cached !== undefined)
|
|
536
|
-
return cached;
|
|
537
|
-
const rank = Math.min(taskStatusRank(task.status), ...(byParent.get(task.id) ?? []).map(branchRank));
|
|
538
|
-
branchRanks.set(task.id, rank);
|
|
539
|
-
return rank;
|
|
540
|
-
};
|
|
541
|
-
const out = [];
|
|
542
|
-
const visit = (parentId) => {
|
|
543
|
-
for (const task of (byParent.get(parentId) ?? []).sort((left, right) => branchRank(left) - branchRank(right) || compareTaskKeys(left.key, right.key))) {
|
|
544
|
-
out.push(task);
|
|
545
|
-
visit(task.id);
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
visit(undefined);
|
|
549
|
-
return out;
|
|
550
|
-
}
|
|
551
|
-
function taskStatusRank(status) {
|
|
552
|
-
switch (status) {
|
|
553
|
-
case 'in_progress':
|
|
554
|
-
return 0;
|
|
555
|
-
case 'pending':
|
|
556
|
-
return 1;
|
|
557
|
-
case 'blocked':
|
|
558
|
-
return 2;
|
|
559
|
-
case 'completed':
|
|
560
|
-
return 3;
|
|
561
|
-
case 'failed':
|
|
562
|
-
return 4;
|
|
563
|
-
case 'cancelled':
|
|
564
|
-
return 5;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
439
|
export function renderTaskLedgerDebugText(tasks) {
|
|
568
440
|
if (tasks.length === 0)
|
|
569
441
|
return '';
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"exports": {
|
|
9
|
+
"./durable-tool-result-projection": "./dist/durable-tool-result-projection.js",
|
|
9
10
|
"./canonical-runtime-event": "./dist/canonical-runtime-event.js",
|
|
10
11
|
"./runtime-boundary": "./dist/runtime-boundary.js",
|
|
11
12
|
"./runtime-event": "./dist/runtime-event.js",
|