maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.32.20260914
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/THIRD_PARTY_NOTICES.txt +392 -0
- package/dist/acp/maka-acp-agent.js +8 -2
- package/dist/acp/prompt-content.js +225 -0
- package/dist/acp/session-event-mapper.js +103 -0
- package/dist/acp/session-registry.js +654 -17
- package/dist/acp/stdio-server.js +10 -1
- package/dist/cli-core.js +1 -1
- package/dist/pi-transcript-tools.js +3 -2
- package/dist/pi-transcript.js +15 -6
- package/dist/runtime-host-session-channel.js +63 -9
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/agent-graph-schedule.js +15 -4
- package/node_modules/@maka/core/dist/artifacts.js +6 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -2
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
- package/node_modules/@maka/core/dist/events.js +21 -0
- package/node_modules/@maka/core/dist/executor-id.js +22 -0
- package/node_modules/@maka/core/dist/external-session.js +18 -0
- package/node_modules/@maka/core/dist/goal.js +44 -2
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -13
- package/node_modules/@maka/core/dist/permission.js +0 -1
- package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
- package/node_modules/@maka/core/dist/runtime-event.js +25 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
- package/node_modules/@maka/core/dist/session-send-projection.js +6 -3
- package/node_modules/@maka/core/dist/session.js +8 -2
- package/node_modules/@maka/core/dist/shell-run-result.js +1 -0
- package/node_modules/@maka/core/dist/shell-run.js +4 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/unified-diff.js +33 -26
- package/node_modules/@maka/core/dist/work-board.js +94 -1
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/eval/dist/fleet-simulation.js +270 -0
- package/node_modules/@maka/eval/dist/fleet-store.js +243 -0
- package/node_modules/@maka/eval/dist/fleet-worker.js +125 -0
- package/node_modules/@maka/eval/dist/fleet.js +329 -0
- package/node_modules/@maka/eval/dist/index.js +3 -0
- package/node_modules/@maka/runtime/dist/agent-run.js +2 -17
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +55 -180
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +43 -26
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +271 -382
- package/node_modules/@maka/runtime/dist/background-task-health-tool.js +104 -0
- package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
- package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
- package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
- package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
- package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
- package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
- package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
- package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
- package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
- package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
- package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
- package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
- package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
- package/node_modules/@maka/runtime/dist/history-compaction.js +3 -1
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +1 -1
- package/node_modules/@maka/runtime/dist/model-adapter.js +62 -53
- package/node_modules/@maka/runtime/dist/model-history.js +26 -8
- package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +311 -0
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +344 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +7 -1
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -8
- package/node_modules/@maka/runtime/dist/read-page.js +231 -0
- package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
- package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
- package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +7 -1
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +188 -20
- package/node_modules/@maka/runtime/dist/runtime-invocation-route.js +49 -0
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +72 -150
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -3
- package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +106 -64
- package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
- package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +10 -4
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +2 -1
- package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +1 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +26 -4
- package/node_modules/@maka/runtime/dist/subagent-tools.js +7 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
- package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
- package/node_modules/@maka/runtime/dist/tool-runtime.js +52 -471
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
- package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
- package/node_modules/@maka/runtime/package.json +5 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -2
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +24 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +42 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +31 -3
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +8 -2
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
- package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +3 -30
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +56 -8
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +14 -1
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
- package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +56 -16
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -5
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +37 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
- package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +450 -234
- package/node_modules/@maka/storage/dist/claude-code-transcript-lineage.js +106 -77
- package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
- package/node_modules/@maka/storage/dist/legacy-run-header.js +2 -2
- package/node_modules/@maka/storage/dist/model-call-usage-sql.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
- package/node_modules/@maka/storage/dist/session-store.js +12 -2
- package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +86 -12
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
- package/node_modules/@maka/storage/dist/work-board-store.js +40 -1
- package/node_modules/balanced-match/LICENSE.md +23 -0
- package/node_modules/balanced-match/README.md +57 -0
- package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
- package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
- package/node_modules/balanced-match/dist/esm/index.js +54 -0
- package/node_modules/balanced-match/dist/esm/package.json +3 -0
- package/node_modules/balanced-match/package.json +68 -0
- package/node_modules/brace-expansion/LICENSE +23 -0
- package/node_modules/brace-expansion/README.md +105 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
- package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
- package/node_modules/brace-expansion/dist/esm/index.js +285 -0
- package/node_modules/brace-expansion/dist/esm/package.json +3 -0
- package/node_modules/brace-expansion/package.json +64 -0
- package/node_modules/glob/LICENSE.md +63 -0
- package/node_modules/glob/README.md +1203 -0
- package/node_modules/glob/dist/commonjs/glob.js +248 -0
- package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
- package/node_modules/glob/dist/commonjs/ignore.js +119 -0
- package/node_modules/glob/dist/commonjs/index.js +68 -0
- package/node_modules/glob/dist/commonjs/index.min.js +4 -0
- package/node_modules/glob/dist/commonjs/package.json +3 -0
- package/node_modules/glob/dist/commonjs/pattern.js +223 -0
- package/node_modules/glob/dist/commonjs/processor.js +301 -0
- package/node_modules/glob/dist/commonjs/walker.js +387 -0
- package/node_modules/glob/dist/esm/glob.js +244 -0
- package/node_modules/glob/dist/esm/has-magic.js +23 -0
- package/node_modules/glob/dist/esm/ignore.js +115 -0
- package/node_modules/glob/dist/esm/index.js +55 -0
- package/node_modules/glob/dist/esm/index.min.js +4 -0
- package/node_modules/glob/dist/esm/package.json +3 -0
- package/node_modules/glob/dist/esm/pattern.js +219 -0
- package/node_modules/glob/dist/esm/processor.js +294 -0
- package/node_modules/glob/dist/esm/walker.js +381 -0
- package/node_modules/glob/package.json +98 -0
- package/node_modules/minimatch/LICENSE.md +55 -0
- package/node_modules/minimatch/README.md +528 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/ast.js +841 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
- package/node_modules/minimatch/dist/esm/escape.js +26 -0
- package/node_modules/minimatch/dist/esm/index.js +1114 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.js +34 -0
- package/node_modules/minimatch/package.json +73 -0
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/README.md +825 -0
- package/node_modules/minipass/dist/commonjs/index.js +1038 -0
- package/node_modules/minipass/dist/commonjs/package.json +3 -0
- package/node_modules/minipass/dist/esm/index.js +1020 -0
- package/node_modules/minipass/dist/esm/package.json +3 -0
- package/node_modules/minipass/package.json +77 -0
- package/node_modules/path-scurry/LICENSE.md +55 -0
- package/node_modules/path-scurry/README.md +636 -0
- package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
- package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/dist/esm/index.js +1983 -0
- package/node_modules/path-scurry/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
- package/node_modules/path-scurry/package.json +72 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
- package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
|
@@ -0,0 +1,104 @@
|
|
|
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 { z } from 'zod';
|
|
20
|
+
/**
|
|
21
|
+
* Produces an explicit two-axis result. A tracked process is never described
|
|
22
|
+
* as endpoint-ready unless the caller supplied a URL and the probe succeeded.
|
|
23
|
+
*/
|
|
24
|
+
export function buildBackgroundTaskHealthTool(reader, probe) {
|
|
25
|
+
return {
|
|
26
|
+
name: 'BackgroundTaskHealth',
|
|
27
|
+
displayName: 'Background task health',
|
|
28
|
+
categoryHint: 'web_read',
|
|
29
|
+
description: 'Check a tracked background task and an optional HTTP endpoint. Uses HEAD with one GET fallback for 405/501; discards the body. Reports HTTP status only, not browser loading or ownership of the listener. Redirects are not followed. Logs are omitted by default; use Read(ref) for full logs.',
|
|
30
|
+
parameters: z
|
|
31
|
+
.object({
|
|
32
|
+
ref: z.string().describe('The maka://runtime/background-tasks/<id> ref returned by Bash'),
|
|
33
|
+
include_logs: z.boolean().optional().describe('Include captured task logs in this report'),
|
|
34
|
+
url: z
|
|
35
|
+
.string()
|
|
36
|
+
.url()
|
|
37
|
+
.refine((value) => ['http:', 'https:'].includes(new URL(value).protocol), 'Health endpoint must use HTTP or HTTPS')
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('The HTTP or HTTPS endpoint to probe'),
|
|
40
|
+
})
|
|
41
|
+
.strict(),
|
|
42
|
+
impl: async ({ ref, url, include_logs }, context) => {
|
|
43
|
+
const resource = await reader.readRuntimeResource(context.sessionId, ref, context.abortSignal);
|
|
44
|
+
if (!resource ||
|
|
45
|
+
typeof resource !== 'object' ||
|
|
46
|
+
Array.isArray(resource) ||
|
|
47
|
+
resource.kind !== 'shell_run') {
|
|
48
|
+
throw new Error('BackgroundTaskHealth requires a shell_run runtime resource');
|
|
49
|
+
}
|
|
50
|
+
const shell = resource;
|
|
51
|
+
const process = {
|
|
52
|
+
status: shell.status,
|
|
53
|
+
tracked: true,
|
|
54
|
+
startedAt: shell.startedAt,
|
|
55
|
+
updatedAt: shell.updatedAt,
|
|
56
|
+
...(shell.pid !== undefined ? { pid: shell.pid } : {}),
|
|
57
|
+
...(shell.completedAt !== undefined ? { completedAt: shell.completedAt } : {}),
|
|
58
|
+
...(shell.failureMessage !== undefined ? { failureMessage: shell.failureMessage } : {}),
|
|
59
|
+
...(include_logs && shell.output
|
|
60
|
+
? {
|
|
61
|
+
logs: shell.output.mode === 'pipes'
|
|
62
|
+
? { stdout: shell.output.stdout, stderr: shell.output.stderr }
|
|
63
|
+
: { screen: shell.output.screen, scrollback: shell.output.scrollback },
|
|
64
|
+
}
|
|
65
|
+
: {}),
|
|
66
|
+
};
|
|
67
|
+
if (!url)
|
|
68
|
+
return JSON.stringify({ process, endpoint: { state: 'not_checked' } });
|
|
69
|
+
let endpoint;
|
|
70
|
+
try {
|
|
71
|
+
endpoint = await probe.probe({
|
|
72
|
+
url,
|
|
73
|
+
sessionId: context.sessionId,
|
|
74
|
+
abortSignal: context.abortSignal,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
context.abortSignal.throwIfAborted();
|
|
79
|
+
return JSON.stringify({
|
|
80
|
+
process,
|
|
81
|
+
endpoint: {
|
|
82
|
+
state: 'unknown',
|
|
83
|
+
target: new URL(url).href,
|
|
84
|
+
error: error instanceof Error ? error.message : String(error),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return JSON.stringify({
|
|
89
|
+
process,
|
|
90
|
+
endpoint: {
|
|
91
|
+
state: 'checked',
|
|
92
|
+
httpStatus: endpoint.status,
|
|
93
|
+
elapsedMs: endpoint.elapsedMs,
|
|
94
|
+
target: new URL(url).href,
|
|
95
|
+
health: endpoint.status >= 200 && endpoint.status < 300
|
|
96
|
+
? 'healthy'
|
|
97
|
+
: endpoint.status < 400
|
|
98
|
+
? 'unknown'
|
|
99
|
+
: 'unhealthy',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -32,5 +32,11 @@ export function projectBashToolResultForModel(output) {
|
|
|
32
32
|
return projected;
|
|
33
33
|
}
|
|
34
34
|
export function bashToolResultToModelOutput(output) {
|
|
35
|
-
|
|
35
|
+
const isError = output !== null &&
|
|
36
|
+
typeof output === 'object' &&
|
|
37
|
+
'kind' in output &&
|
|
38
|
+
output.kind === 'terminal' &&
|
|
39
|
+
'status' in output &&
|
|
40
|
+
output.status !== 'completed';
|
|
41
|
+
return toolResultOutput(projectBashToolResultForModel(output), isError);
|
|
36
42
|
}
|
|
@@ -21,48 +21,17 @@
|
|
|
21
21
|
// Memory-bounded tail accumulator for streaming shell output. A runaway command
|
|
22
22
|
// must not be able to grow the captured result without limit (the old Bash path
|
|
23
23
|
// instead discarded ALL output past a hard cap), so we retain only the last
|
|
24
|
-
// `cap` characters.
|
|
25
|
-
//
|
|
26
|
-
// SECURITY: the retained tail is later passed through redactSecrets before it
|
|
27
|
-
// reaches the model / UI. redactSecrets matches on full tokens and their
|
|
28
|
-
// prefixes (e.g. `Authorization: Bearer …`, `sk-…`), so a tail that begins in
|
|
29
|
-
// the MIDDLE of a secret-bearing line would defeat redaction and leak the
|
|
30
|
-
// suffix. To prevent that, when the buffer actually drops content it also drops
|
|
31
|
-
// the (partial) leading line, so the retained tail always starts at a line
|
|
32
|
-
// boundary and redaction sees whole lines.
|
|
24
|
+
// `cap` characters. Trimming avoids splitting a UTF-16 surrogate pair.
|
|
33
25
|
export class BashTailBuffer {
|
|
34
26
|
cap;
|
|
35
27
|
chunks = [];
|
|
36
28
|
retained = 0;
|
|
37
|
-
// True when we dropped an unterminated oversized line: subsequent chunks are
|
|
38
|
-
// still part of that compromised line and must be discarded until the next
|
|
39
|
-
// newline, otherwise a continuation chunk (a secret's severed suffix) would
|
|
40
|
-
// be retained as if it were a clean line and defeat downstream redaction.
|
|
41
|
-
insideDroppedLine = false;
|
|
42
|
-
// Latches true once we drop an oversized no-newline line entirely (the case
|
|
43
|
-
// above). Callers surface a marker so a result that looks empty is not
|
|
44
|
-
// mistaken for "the command produced nothing" — content existed but could not
|
|
45
|
-
// be safely truncated.
|
|
46
|
-
droppedUnsafe = false;
|
|
47
29
|
constructor(cap) {
|
|
48
30
|
this.cap = cap;
|
|
49
31
|
}
|
|
50
|
-
/** Whether an oversized, unsafe-to-truncate line was dropped from the tail. */
|
|
51
|
-
hasDroppedUnsafe() {
|
|
52
|
-
return this.droppedUnsafe;
|
|
53
|
-
}
|
|
54
32
|
push(chunk) {
|
|
55
33
|
if (!chunk)
|
|
56
34
|
return;
|
|
57
|
-
if (this.insideDroppedLine) {
|
|
58
|
-
const nl = chunk.indexOf('\n');
|
|
59
|
-
if (nl < 0)
|
|
60
|
-
return; // whole chunk is still the dropped line — discard it
|
|
61
|
-
this.insideDroppedLine = false;
|
|
62
|
-
chunk = chunk.slice(nl + 1); // resume from the first clean line boundary
|
|
63
|
-
if (!chunk)
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
35
|
this.chunks.push(chunk);
|
|
67
36
|
this.retained += chunk.length;
|
|
68
37
|
// Amortize: allow growth to 2x cap before compacting back to cap so appends
|
|
@@ -78,28 +47,20 @@ export class BashTailBuffer {
|
|
|
78
47
|
if (this.chunks.length <= 1 && this.retained <= this.cap)
|
|
79
48
|
return;
|
|
80
49
|
const joined = this.chunks.join('');
|
|
81
|
-
let
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// whole tail is one partial line we cannot make safe — drop it entirely
|
|
87
|
-
// rather than risk leaking a severed secret. (A single line larger than
|
|
88
|
-
// the cap is pathological; the common single-line case is <= cap and is
|
|
89
|
-
// never sliced here.)
|
|
90
|
-
const nl = kept.indexOf('\n');
|
|
91
|
-
if (nl >= 0) {
|
|
92
|
-
kept = kept.slice(nl + 1);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// No line boundary in the retained tail: drop it and stay "inside" the
|
|
96
|
-
// dropped line so its continuation chunks are discarded until a newline.
|
|
97
|
-
kept = '';
|
|
98
|
-
this.insideDroppedLine = true;
|
|
99
|
-
this.droppedUnsafe = true;
|
|
100
|
-
}
|
|
50
|
+
let start = Math.max(0, joined.length - this.cap);
|
|
51
|
+
if (start > 0 &&
|
|
52
|
+
isLowSurrogate(joined.charCodeAt(start)) &&
|
|
53
|
+
isHighSurrogate(joined.charCodeAt(start - 1))) {
|
|
54
|
+
start += 1;
|
|
101
55
|
}
|
|
56
|
+
const kept = joined.slice(start);
|
|
102
57
|
this.chunks = kept ? [kept] : [];
|
|
103
58
|
this.retained = kept.length;
|
|
104
59
|
}
|
|
105
60
|
}
|
|
61
|
+
function isHighSurrogate(code) {
|
|
62
|
+
return code >= 0xd800 && code <= 0xdbff;
|
|
63
|
+
}
|
|
64
|
+
function isLowSurrogate(code) {
|
|
65
|
+
return code >= 0xdc00 && code <= 0xdfff;
|
|
66
|
+
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// execution facts, while the active session ExecutionBoundary constrains local
|
|
22
22
|
// filesystem, shell, and network effects.
|
|
23
23
|
import { z } from 'zod';
|
|
24
|
-
import {
|
|
24
|
+
import { READ_DESCRIPTION, readParameters, readToolResultPage, resolveReadInput, } from './read-page.js';
|
|
25
25
|
import { closeSync, constants, fstatSync, futimesSync, lstatSync, openSync, realpathSync, unlinkSync, } from 'node:fs';
|
|
26
26
|
import { tmpdir } from 'node:os';
|
|
27
27
|
import { basename, dirname } from 'node:path';
|
|
@@ -30,6 +30,8 @@ import { parseAttachmentResourceRef } from '@maka/core/attachments';
|
|
|
30
30
|
import { isStorageRef } from '@maka/core/events';
|
|
31
31
|
import { bashToolResultToModelOutput } from './bash-model-output.js';
|
|
32
32
|
import { fileWriteToolResultToModelOutput } from './file-tool-model-output.js';
|
|
33
|
+
import { toolResultOutput } from './tool-result-output.js';
|
|
34
|
+
import { GREP_MAX_LINES, GREP_MAX_LINES_PER_FILE, GREP_MAX_MATCH_BYTES } from './grep-search.js';
|
|
33
35
|
import { openAiApplyPatchInputSchema } from './openai-apply-patch.js';
|
|
34
36
|
import { parseCodexV4aPatch } from './codex-v4a-patch.js';
|
|
35
37
|
import { executeApplyPatchOperations } from './apply-patch-batch.js';
|
|
@@ -104,87 +106,6 @@ export function buildBuiltinTools(options = {}) {
|
|
|
104
106
|
...(options.permissionProfile ? { permissionProfile: options.permissionProfile } : {}),
|
|
105
107
|
});
|
|
106
108
|
const executionFacts = executor.facts;
|
|
107
|
-
const acceptsResourceRefs = Boolean(options.runtimeResources || options.attachmentResources);
|
|
108
|
-
const readDescription = `Read a text file${options.snapshotImage ? ' or supported image' : ''} from disk${acceptsResourceRefs ? ', or read a whole runtime resource using ref' : ''}.`;
|
|
109
|
-
const pathField = z
|
|
110
|
-
.string()
|
|
111
|
-
.describe('A file path; relative paths are resolved from the session cwd');
|
|
112
|
-
const offsetField = z
|
|
113
|
-
.number()
|
|
114
|
-
.int()
|
|
115
|
-
.nonnegative()
|
|
116
|
-
.describe('Zero-based text file line offset')
|
|
117
|
-
.optional();
|
|
118
|
-
const limitField = z
|
|
119
|
-
.number()
|
|
120
|
-
.int()
|
|
121
|
-
.positive()
|
|
122
|
-
.describe('Maximum text file lines to read')
|
|
123
|
-
.optional();
|
|
124
|
-
const refField = z
|
|
125
|
-
.string()
|
|
126
|
-
.describe('A runtime resource ref provided in the conversation or returned by another tool');
|
|
127
|
-
const fileReadParameters = z
|
|
128
|
-
.object({
|
|
129
|
-
path: pathField,
|
|
130
|
-
offset: offsetField,
|
|
131
|
-
limit: limitField,
|
|
132
|
-
})
|
|
133
|
-
.strict();
|
|
134
|
-
const runtimeResourceReadParameters = z
|
|
135
|
-
.object({
|
|
136
|
-
ref: refField,
|
|
137
|
-
})
|
|
138
|
-
.strict();
|
|
139
|
-
// Some providers serialize every optional field with a default. Normalize
|
|
140
|
-
// only empty fields that cannot carry intent, then let the strict union keep
|
|
141
|
-
// rejecting genuinely ambiguous file-and-resource requests.
|
|
142
|
-
const normalizeProviderReadInput = (value) => {
|
|
143
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
144
|
-
return value;
|
|
145
|
-
const input = value;
|
|
146
|
-
const ref = input.ref;
|
|
147
|
-
const path = input.path;
|
|
148
|
-
if (typeof ref === 'string' && ref.trim() !== '') {
|
|
149
|
-
if (typeof path !== 'string' || path.trim() !== '')
|
|
150
|
-
return value;
|
|
151
|
-
return Object.fromEntries(Object.entries(input).filter(([key]) => key !== 'path' && key !== 'offset' && key !== 'limit'));
|
|
152
|
-
}
|
|
153
|
-
if (typeof ref !== 'string' || ref.trim() !== '')
|
|
154
|
-
return value;
|
|
155
|
-
return Object.fromEntries(Object.entries(input).filter(([key]) => key !== 'ref'));
|
|
156
|
-
};
|
|
157
|
-
const strictReadParameters = z.preprocess(normalizeProviderReadInput, z
|
|
158
|
-
.union([fileReadParameters, runtimeResourceReadParameters])
|
|
159
|
-
.describe('Read a file with path, or a whole runtime resource with ref; provide exactly one'));
|
|
160
|
-
// Provider-facing schema: a single top-level object with every field optional.
|
|
161
|
-
// Anthropic rejects a tool definition whose input schema carries a top-level
|
|
162
|
-
// `anyOf`, so the file-vs-ref exclusivity is stated in the field descriptions
|
|
163
|
-
// here and enforced authoritatively by the strict union in `validate` below
|
|
164
|
-
// (see #1228 — a union-generated `anyOf` had been leaking onto the wire).
|
|
165
|
-
const providerReadParameters = z
|
|
166
|
-
.object({
|
|
167
|
-
path: pathField
|
|
168
|
-
.describe('A file path; relative paths are resolved from the session cwd. Provide either path (optionally with offset/limit) or ref, never both.')
|
|
169
|
-
.optional(),
|
|
170
|
-
offset: offsetField,
|
|
171
|
-
limit: limitField,
|
|
172
|
-
ref: refField
|
|
173
|
-
.describe('A runtime resource ref provided in the conversation or returned by another tool. Provide ref on its own, without path/offset/limit; omit it (or leave it empty) when reading a file.')
|
|
174
|
-
.optional(),
|
|
175
|
-
})
|
|
176
|
-
.describe('Read a file with path (optionally offset/limit), or a whole runtime resource with ref; provide exactly one of path or ref.');
|
|
177
|
-
const providerReadSchema = zodSchema(providerReadParameters);
|
|
178
|
-
const readParameters = acceptsResourceRefs
|
|
179
|
-
? jsonSchema(async () => await providerReadSchema.jsonSchema, {
|
|
180
|
-
validate: async (value) => {
|
|
181
|
-
const result = await strictReadParameters.safeParseAsync(value);
|
|
182
|
-
return result.success
|
|
183
|
-
? { success: true, value: result.data }
|
|
184
|
-
: { success: false, error: result.error };
|
|
185
|
-
},
|
|
186
|
-
})
|
|
187
|
-
: fileReadParameters;
|
|
188
109
|
const shell = options.shell ?? { plan: defaultShellPlan() };
|
|
189
110
|
const sandboxPlatform = options.sandboxPlatform ?? process.platform;
|
|
190
111
|
const bashTools = options.shellRuns
|
|
@@ -253,9 +174,29 @@ export function buildBuiltinTools(options = {}) {
|
|
|
253
174
|
{
|
|
254
175
|
name: 'Read',
|
|
255
176
|
activityKind: 'read',
|
|
256
|
-
description:
|
|
177
|
+
description: READ_DESCRIPTION,
|
|
257
178
|
parameters: readParameters,
|
|
258
179
|
executionFacts,
|
|
180
|
+
toModelOutput: ({ input, output }) => {
|
|
181
|
+
const args = input;
|
|
182
|
+
const { path } = resolveReadInput(args);
|
|
183
|
+
if (classifyRuntimeResourceRef(path) !== 'runtime' ||
|
|
184
|
+
path.startsWith('maka://runtime/tool-results/'))
|
|
185
|
+
return undefined;
|
|
186
|
+
if (output && typeof output === 'object' && 'kind' in output && output.kind === 'image')
|
|
187
|
+
return undefined;
|
|
188
|
+
try {
|
|
189
|
+
return toolResultOutput(readToolResultPage(JSON.stringify(output), args), false);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
return {
|
|
193
|
+
type: 'error-text',
|
|
194
|
+
value: error instanceof Error
|
|
195
|
+
? error.message
|
|
196
|
+
: 'This Read page could not be generated. Read the original path again.',
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
},
|
|
259
200
|
...(options.releaseImageSnapshot
|
|
260
201
|
? {
|
|
261
202
|
compensateDurableOutcomeCommitFailure: async (input) => {
|
|
@@ -280,35 +221,35 @@ export function buildBuiltinTools(options = {}) {
|
|
|
280
221
|
: {}),
|
|
281
222
|
impl: async (input, ctx) => {
|
|
282
223
|
const { cwd, sessionId, abortSignal } = ctx;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
224
|
+
const resolved = resolveReadInput(input);
|
|
225
|
+
const path = resolved.path;
|
|
226
|
+
const runtimeRef = classifyRuntimeResourceRef(path);
|
|
227
|
+
if (runtimeRef === 'unsupported')
|
|
228
|
+
throw new Error(`Unsupported Maka address: ${path}. Use a path returned by a tool.`);
|
|
229
|
+
if (runtimeRef === 'runtime') {
|
|
230
|
+
const attachment = parseAttachmentResourceRef(path);
|
|
289
231
|
if (attachment) {
|
|
290
|
-
if (!options.attachmentResources)
|
|
232
|
+
if (!options.attachmentResources)
|
|
291
233
|
throw new Error('Attachment resources are not available in this toolset');
|
|
292
|
-
|
|
293
|
-
return
|
|
234
|
+
const result = await options.attachmentResources.readAttachmentResource(sessionId, attachment.artifactId, abortSignal);
|
|
235
|
+
return result;
|
|
294
236
|
}
|
|
295
237
|
if (!options.runtimeResources)
|
|
296
238
|
throw new Error('Runtime resources are not available in this toolset');
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const { path, offset, limit } = input;
|
|
300
|
-
const runtimeRef = classifyRuntimeResourceRef(path);
|
|
301
|
-
if (runtimeRef === 'unsupported')
|
|
302
|
-
throw new Error(`Unsupported runtime resource ref: ${path}`);
|
|
303
|
-
if (runtimeRef === 'runtime') {
|
|
304
|
-
throw new Error('Runtime resources must be read with the ref parameter, not path');
|
|
239
|
+
const result = await options.runtimeResources.readRuntimeResource(sessionId, path, abortSignal);
|
|
240
|
+
return result;
|
|
305
241
|
}
|
|
306
242
|
const result = await filesystem.execute({
|
|
307
243
|
operation: {
|
|
308
244
|
kind: 'read',
|
|
309
245
|
path,
|
|
310
|
-
...(offset
|
|
311
|
-
...(limit
|
|
246
|
+
...(input.offset === undefined ? {} : { offset: input.offset }),
|
|
247
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
248
|
+
...(resolved.position === undefined
|
|
249
|
+
? {}
|
|
250
|
+
: {
|
|
251
|
+
continuation: { position: resolved.position, digest: resolved.digest },
|
|
252
|
+
}),
|
|
312
253
|
},
|
|
313
254
|
...filesystemCall(ctx),
|
|
314
255
|
});
|
|
@@ -328,7 +269,8 @@ export function buildBuiltinTools(options = {}) {
|
|
|
328
269
|
}
|
|
329
270
|
if (result.kind !== 'read')
|
|
330
271
|
throw internalFilesystemReadFailure('Read', 'no file content came back', 'the file is empty or missing');
|
|
331
|
-
|
|
272
|
+
const { kind: _kind, ...page } = result;
|
|
273
|
+
return page;
|
|
332
274
|
},
|
|
333
275
|
},
|
|
334
276
|
...(executor.applyPatch ? [applyPatchTool] : []),
|
|
@@ -461,11 +403,16 @@ export function buildBuiltinTools(options = {}) {
|
|
|
461
403
|
{
|
|
462
404
|
name: 'Grep',
|
|
463
405
|
activityKind: 'search',
|
|
464
|
-
description:
|
|
406
|
+
description: `Search file contents with a ripgrep regex. Scans files as text, including binary files; directory traversal respects ripgrep ignore rules and glob filters. Returns path:line:content matches and exact matchedLines, returnedLines, omittedLines, and truncated from one completed search. Keeps at most ${GREP_MAX_LINES_PER_FILE} lines per file, ${GREP_MAX_LINES} total, and ${GREP_MAX_MATCH_BYTES / 1024} KiB of JSON matches; oversized or non-UTF8 lines/paths may be omitted. Narrow path, glob, or pattern for more matches, or use Read to inspect a file. Failed searches have unknown totals.`,
|
|
465
407
|
parameters: z.object({
|
|
466
|
-
pattern: z
|
|
467
|
-
|
|
468
|
-
|
|
408
|
+
pattern: z
|
|
409
|
+
.string()
|
|
410
|
+
.describe('Ripgrep regular expression; use an empty pattern to match every line.'),
|
|
411
|
+
path: z
|
|
412
|
+
.string()
|
|
413
|
+
.optional()
|
|
414
|
+
.describe('File or directory to search; defaults to the session working directory.'),
|
|
415
|
+
glob: z.string().optional().describe('Optional ripgrep file glob, for example **/*.ts.'),
|
|
469
416
|
}),
|
|
470
417
|
executionFacts,
|
|
471
418
|
impl: async ({ pattern, path, glob }, ctx) => {
|
|
@@ -476,18 +423,19 @@ export function buildBuiltinTools(options = {}) {
|
|
|
476
423
|
const result = await filesystem.execute({
|
|
477
424
|
operation: {
|
|
478
425
|
kind: 'grep',
|
|
479
|
-
path: path
|
|
426
|
+
path: path || '.',
|
|
480
427
|
pattern,
|
|
481
428
|
...(glob ? { glob } : {}),
|
|
482
|
-
maxCountPerFile:
|
|
483
|
-
limit:
|
|
429
|
+
maxCountPerFile: GREP_MAX_LINES_PER_FILE,
|
|
430
|
+
limit: GREP_MAX_LINES,
|
|
484
431
|
timeoutMs: GREP_TIMEOUT_MS,
|
|
485
432
|
},
|
|
486
433
|
...filesystemCall(ctx),
|
|
487
434
|
});
|
|
488
435
|
if (result.kind !== 'grep')
|
|
489
436
|
throw internalFilesystemReadFailure('Grep', 'no search result came back', 'the pattern is absent');
|
|
490
|
-
|
|
437
|
+
const { kind: _kind, ...searchResult } = result;
|
|
438
|
+
return searchResult;
|
|
491
439
|
},
|
|
492
440
|
},
|
|
493
441
|
];
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { closeSync } from 'node:fs';
|
|
20
|
+
export const MAX_CHILD_FD = 64;
|
|
20
21
|
export function buildSpawnStdio(fdInputs, stdin = 'ignore') {
|
|
21
22
|
const stdio = [stdin, 'pipe', 'pipe'];
|
|
22
23
|
for (const input of fdInputs ?? []) {
|
|
23
|
-
if (!Number.isInteger(input.fd) || input.fd < 3 || input.fd >
|
|
24
|
-
throw new Error(`Child fd input must use an integer fd between 3 and
|
|
24
|
+
if (!Number.isInteger(input.fd) || input.fd < 3 || input.fd > MAX_CHILD_FD) {
|
|
25
|
+
throw new Error(`Child fd input must use an integer fd between 3 and ${MAX_CHILD_FD}; received ${input.fd}`);
|
|
25
26
|
}
|
|
26
27
|
if ('sourceFd' in input && (!Number.isInteger(input.sourceFd) || input.sourceFd < 0)) {
|
|
27
28
|
throw new Error(`Child fd input source must be a non-negative integer; received ${input.sourceFd}`);
|
|
@@ -29,22 +29,12 @@ export function buildDefaultContextBudgetPolicy(options = {}) {
|
|
|
29
29
|
const surfaceName = (options.name ?? 'default-history-budget').replace(/-default-history-budget$/, '');
|
|
30
30
|
return {
|
|
31
31
|
name: options.name ?? 'default-history-budget',
|
|
32
|
-
|
|
33
|
-
enabled: true,
|
|
34
|
-
maxResultEstimatedTokens: 2_048,
|
|
35
|
-
minRecentTurnsFull: 2,
|
|
36
|
-
},
|
|
32
|
+
toolResultPrune: { enabled: true },
|
|
37
33
|
historyCompact: {
|
|
38
34
|
enabled: true,
|
|
39
35
|
highWaterName: `${surfaceName}-history-compact`,
|
|
40
36
|
midTurn: { enabled: true },
|
|
41
37
|
},
|
|
42
|
-
activeToolResultPrune: {
|
|
43
|
-
enabled: true,
|
|
44
|
-
maxCurrentResultEstimatedTokens: 2_048,
|
|
45
|
-
minSupersededResultEstimatedTokens: 256,
|
|
46
|
-
minStepNumber: 1,
|
|
47
|
-
},
|
|
48
38
|
};
|
|
49
39
|
}
|
|
50
40
|
/**
|
|
@@ -24,7 +24,7 @@ export { estimateRuntimeEventsTokens } from './model-history.js';
|
|
|
24
24
|
export { ARCHIVED_TOOL_RESULT_PLACEHOLDER_KIND, ARCHIVED_TOOL_RESULT_REWRITE_VERSION, isArchivedToolResultPlaceholder, deserializeToolResultArchive, serializeToolResultForArchive, } from './tool-result-archive.js';
|
|
25
25
|
import { applyRuntimeEventHistoryCompact as applyRuntimeEventHistoryCompactNarrow, } from './history-compaction.js';
|
|
26
26
|
export function applyRuntimeEventContextBudget(events, policy) {
|
|
27
|
-
const prunePolicy = policy?.
|
|
27
|
+
const prunePolicy = policy?.toolResultPrune;
|
|
28
28
|
const pruneEnabled = prunePolicy?.enabled === true;
|
|
29
29
|
const historyCompactEnabled = policy?.historyCompact?.enabled === true;
|
|
30
30
|
const enabled = pruneEnabled || historyCompactEnabled;
|
|
@@ -110,6 +110,17 @@ export function mergeContextBudgetDiagnostic(base, patch) {
|
|
|
110
110
|
...mergeCompactionDecisionDiagnostics(base.compactionDecisions, patch.compactionDecisions),
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
+
export function addToolResultPruneStats(snapshot, delta) {
|
|
114
|
+
return {
|
|
115
|
+
...snapshot,
|
|
116
|
+
prunedToolResults: (snapshot.prunedToolResults ?? 0) + delta.prunedToolResults,
|
|
117
|
+
archiveWriteFailures: (snapshot.archiveWriteFailures ?? 0) + delta.archiveWriteFailures,
|
|
118
|
+
prunedToolResultEstimatedTokensBefore: (snapshot.prunedToolResultEstimatedTokensBefore ?? 0) +
|
|
119
|
+
delta.prunedToolResultEstimatedTokensBefore,
|
|
120
|
+
prunedToolResultEstimatedTokensAfter: (snapshot.prunedToolResultEstimatedTokensAfter ?? 0) +
|
|
121
|
+
delta.prunedToolResultEstimatedTokensAfter,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
113
124
|
export function mergeContextBudgetDiagnosticPatches(left, right) {
|
|
114
125
|
if (!left && !right)
|
|
115
126
|
return undefined;
|