@octopi-agent/engine 0.102.10 → 0.121.15
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/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/console-access-key.d.ts +46 -0
- package/dist/config-admin/console-access-key.js +47 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +8 -2
- package/dist/config-admin/index.js +4 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +83 -0
- package/dist/config-admin/onboarding-apply.js +259 -0
- package/dist/config-admin/onboarding.d.ts +160 -0
- package/dist/config-admin/onboarding.js +298 -0
- package/dist/config-admin/password-policy.d.ts +24 -0
- package/dist/config-admin/password-policy.js +31 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +5 -1
- package/dist/config-schema/agent.js +20 -2
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +6 -3
- package/dist/config-schema/engine.d.ts +86 -7
- package/dist/config-schema/engine.js +9 -2
- package/dist/config-schema/governance.d.ts +12 -1
- package/dist/config-schema/governance.js +10 -2
- package/dist/config-schema/models.d.ts +12 -8
- package/dist/config-schema/models.js +16 -1
- package/dist/config-schema/run.d.ts +4 -0
- package/dist/config-schema/run.js +10 -0
- package/dist/config-schema/shared.d.ts +1 -0
- package/dist/config-schema/shared.js +4 -2
- package/dist/config-schema/substrate.d.ts +5 -0
- package/dist/config-schema/substrate.js +8 -0
- package/dist/config.d.ts +116 -10
- package/dist/config.js +109 -13
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +4 -0
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +119 -28
- package/dist/harness/activation/types.d.ts +19 -2
- package/dist/harness/agent/builder.d.ts +12 -0
- package/dist/harness/agent/builder.js +78 -22
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +15 -3
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
- package/dist/harness/agent/wire-agent-builder.js +9 -2
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
- package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +34 -2
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +9 -4
- package/dist/harness/collaboration/delegation/service.js +33 -12
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +1 -0
- package/dist/harness/collaboration/delegation/types.d.ts +11 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +1 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
- package/dist/harness/context/capabilities/compact/engine.js +127 -39
- package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
- package/dist/harness/context/capabilities/compact/index.js +1 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
- package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.js +8 -1
- package/dist/harness/context/default-context-engine.d.ts +100 -6
- package/dist/harness/context/default-context-engine.js +382 -89
- package/dist/harness/context/index.d.ts +2 -1
- package/dist/harness/context/index.js +1 -0
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +57 -0
- package/dist/harness/context/layer-types.js +73 -1
- package/dist/harness/context/layers.d.ts +3 -0
- package/dist/harness/context/layers.js +13 -6
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.js +18 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +5 -2
- package/dist/harness/context/tool-result-aging.d.ts +104 -16
- package/dist/harness/context/tool-result-aging.js +211 -57
- package/dist/harness/context/types.d.ts +71 -4
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +5 -3
- package/dist/harness/index.js +2 -2
- package/dist/harness/knowledge/boot-config.d.ts +2 -0
- package/dist/harness/knowledge/boot-config.js +2 -0
- package/dist/harness/knowledge/client.d.ts +53 -7
- package/dist/harness/knowledge/client.js +77 -20
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +107 -41
- package/dist/harness/knowledge/engine-thread.js +5 -7
- package/dist/harness/knowledge/grounding.js +4 -1
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +82 -21
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
- package/dist/harness/knowledge/query-service.d.ts +12 -2
- package/dist/harness/knowledge/query-service.js +75 -41
- package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -1
- package/dist/harness/knowledge/query-worker.js +5 -3
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +9 -2
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +6 -1
- package/dist/harness/knowledge/serve.js +5 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +297 -71
- package/dist/harness/knowledge/start-service-process.d.ts +27 -8
- package/dist/harness/knowledge/start-service-process.js +49 -90
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/writer-service.d.ts +18 -2
- package/dist/harness/knowledge/writer-service.js +80 -16
- package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
- package/dist/harness/knowledge/writer-worker-client.js +20 -3
- package/dist/harness/knowledge/writer-worker.js +11 -4
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/types.d.ts +18 -2
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +95 -2
- package/dist/harness/run/agent/agent.js +3 -2
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/reliability/run-agent.d.ts +22 -0
- package/dist/harness/run/reliability/run-agent.js +79 -10
- package/dist/harness/run/run-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +11 -0
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +149 -22
- package/dist/harness/run/runner.js +352 -35
- package/dist/harness/session/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/types.d.ts +10 -14
- package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
- package/dist/harness/shared/types/agent-definition.d.ts +6 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +27 -2
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +41 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +56 -2
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +14 -2
- package/dist/integration/storage/archive-manager.js +24 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +9 -0
- package/dist/integration/storage/jsonl.js +137 -38
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +5 -3
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* 历史工具结果批量冻结老化(F1-B2)— 视图级、零 LLM、write-once
|
|
3
3
|
*
|
|
4
4
|
* 语义(arch/long-session-latency.md §5 B2 + arch/b0-cache-stable-context.md §4):
|
|
5
|
-
* - **当前 run
|
|
6
|
-
*
|
|
5
|
+
* - **当前 run 永不老化**:当前 run 起点(`currentRunStartAnchorIndex`——同 run 的
|
|
6
|
+
* 插话 / 接续 turn 不推进边界)以来的工具结果全原文;
|
|
7
|
+
* - **近 `rawWindow` 条跨 run 工具结果**保留原文;
|
|
7
8
|
* - 更旧的候选按 **`freezeBatch` 批量**降级为结构化指针(工具名 + 参数要点 + 结果轮廓 + re-run 提示);
|
|
8
9
|
* - **批量冻结(禁渐进老化)**:老化边界只以 `freezeBatch` 为步长成批推进,段间轮次视图
|
|
9
10
|
* 逐字节稳定——每轮在 recency 边界改写 1 条 = 把边界→尾部整段烧前缀缓存(B0 稿 §4);
|
|
@@ -15,21 +16,64 @@
|
|
|
15
16
|
* 红线(§4 能力红线):user / assistant **正文**永不降级;**error 结果永不降级**(错误可追溯性优先,
|
|
16
17
|
* 字段保真);不膨胀守卫——只有指针严格小于原文时才降级。
|
|
17
18
|
*
|
|
18
|
-
* tool_call 参数(`ageToolArgs
|
|
19
|
+
* tool_call 参数(`ageToolArgs`,总开关,默认开;**逐工具 opt-in** `RegisteredTool.ageArgs`):
|
|
19
20
|
* (长值换成长度标记,键名全保)。原因:参数是上下文中唯一无界增长的成分——结果老化成指针后
|
|
20
21
|
* 参数仍留原文,实测其总量可达指针本体的 1.1 倍,且随 session 线性增长。
|
|
21
22
|
* 降级不改变 tool_call ↔ tool_result 配对结构(`id`/`name` 不动,`arguments` 仍是合法 JSON)。
|
|
22
23
|
*
|
|
23
24
|
* @module harness/context/tool-result-aging
|
|
24
25
|
*/
|
|
25
|
-
import {
|
|
26
|
+
import { AGED_POINTER_PREFIX, TRUNCATED_MARK, elidedValueMarker, isElisionToken } from '@octopi-agent/core/elision.js';
|
|
27
|
+
import { currentRunStartAnchorIndex } from './layer-types.js';
|
|
26
28
|
import { toolResultBody } from './tool-result-body.js';
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* 从工具面收集「工具名 → 老化函数」表
|
|
31
|
+
*
|
|
32
|
+
* 供装配层把 `AgentTool.ageResult` 传给老化计划。只收有声明的工具——
|
|
33
|
+
* 未声明者不进表 = 走默认规则(长度判据 + 机械指针)。
|
|
34
|
+
*
|
|
35
|
+
* @param tools - 本 run 实际发送的工具面(`RunScope.tools` / `AgentContext.tools`)
|
|
36
|
+
* @returns 名字→函数表;无任何声明时返回 undefined(省去空表分配)
|
|
37
|
+
*/
|
|
38
|
+
export function collectToolAgers(tools) {
|
|
39
|
+
if (!tools?.length)
|
|
40
|
+
return undefined;
|
|
41
|
+
let out;
|
|
42
|
+
for (const t of tools) {
|
|
43
|
+
if (!t.ageResult)
|
|
44
|
+
continue;
|
|
45
|
+
out ??= new Map();
|
|
46
|
+
out.set(t.name, t.ageResult);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 收集「参数可老化」的工具名(`AgentTool.ageArgs` → 集合)
|
|
52
|
+
*
|
|
53
|
+
* 与 {@link collectToolAgers} 分开:两者语义独立(有结果策略不代表参数可老化,
|
|
54
|
+
* 反之亦然),混成一张表会让「只声明了 ageArgs」的工具误走结果默认规则。
|
|
55
|
+
*
|
|
56
|
+
* @param tools - 本次 run 的工具面
|
|
57
|
+
* @returns 工具名集合;空表返回 undefined(装配侧据此跳过)
|
|
58
|
+
*/
|
|
59
|
+
export function collectToolArgAgers(tools) {
|
|
60
|
+
if (!tools?.length)
|
|
61
|
+
return undefined;
|
|
62
|
+
let out;
|
|
63
|
+
for (const t of tools) {
|
|
64
|
+
if (!t.ageArgs)
|
|
65
|
+
continue;
|
|
66
|
+
out ??= new Set();
|
|
67
|
+
out.add(t.name);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/** 结果轮廓占 maxPointerChars 的比例(0.45;固定骨架 ≈ 70 字符) */
|
|
29
72
|
const RESULT_OUTLINE_RATIO = 0.45;
|
|
30
73
|
/** 轮廓下限(小旋钮下仍可读) */
|
|
31
|
-
const MIN_ARGS_OUTLINE_CHARS = 24;
|
|
32
74
|
const MIN_RESULT_OUTLINE_CHARS = 48;
|
|
75
|
+
/** 指针在结果正文之后的短提示(旧文案 81 字符 × 每条指针,纯重复噪音) */
|
|
76
|
+
const AGED_POINTER_HINT = ' (re-run to see full output)';
|
|
33
77
|
/**
|
|
34
78
|
* 参数摘要中「原样保留」的单个值上限
|
|
35
79
|
*
|
|
@@ -37,7 +81,8 @@ const MIN_RESULT_OUTLINE_CHARS = 48;
|
|
|
37
81
|
* 64 足以容纳常见路径,又远小于任何文件内容。
|
|
38
82
|
*/
|
|
39
83
|
const ARG_VALUE_KEEP_CHARS = 64;
|
|
40
|
-
|
|
84
|
+
/** 已降级值在预算账目里的固定成本(标记是结构噪声,不按字面长度计费) */
|
|
85
|
+
const ELIDED_VALUE_BUDGET_COST = '…';
|
|
41
86
|
/**
|
|
42
87
|
* 解析老化配置(缺省 = 拍板参数起点:40 条原文 / 批 20 / 指针 400 字符)
|
|
43
88
|
*
|
|
@@ -45,8 +90,8 @@ const TRUNCATION_MARK = '…[truncated]';
|
|
|
45
90
|
* @returns 全字段解析结果(非法值/0 步长回落缺省——0 或负步长等同禁用批量冻结)
|
|
46
91
|
*/
|
|
47
92
|
export function resolveToolResultAgingOptions(input) {
|
|
48
|
-
const rawWindow = Number.isInteger(input?.rawWindow) && (input?.rawWindow ?? -1) >= 0 ? input.rawWindow :
|
|
49
|
-
const freezeBatch = Number.isInteger(input?.freezeBatch) && (input?.freezeBatch ?? -1) >= 1 ? input.freezeBatch :
|
|
93
|
+
const rawWindow = Number.isInteger(input?.rawWindow) && (input?.rawWindow ?? -1) >= 0 ? input.rawWindow : 20;
|
|
94
|
+
const freezeBatch = Number.isInteger(input?.freezeBatch) && (input?.freezeBatch ?? -1) >= 1 ? input.freezeBatch : 60;
|
|
50
95
|
const maxPointerChars = Number.isInteger(input?.maxPointerChars) && (input?.maxPointerChars ?? -1) > 0 ? input.maxPointerChars : 400;
|
|
51
96
|
const maxAgedArgChars = Number.isInteger(input?.maxAgedArgChars) && (input?.maxAgedArgChars ?? -1) > 0
|
|
52
97
|
? input.maxAgedArgChars
|
|
@@ -63,8 +108,8 @@ export function resolveToolResultAgingOptions(input) {
|
|
|
63
108
|
/**
|
|
64
109
|
* 计算老化计划:批量冻结边界 + 工具调用参数索引
|
|
65
110
|
*
|
|
66
|
-
*
|
|
67
|
-
* `
|
|
111
|
+
* 边界语义:跨 run 工具结果(位于当前 run 起点之前)中,最旧的
|
|
112
|
+
* `crossRun - rawWindow` 条为候选;候选前 `freezeBatch` 整批部分「过冻结线」。
|
|
68
113
|
* 过线条目再过三道守卫才降级:error 永不降级;正文 ≤ 指针目标不降级;
|
|
69
114
|
* 实际指针不比原文短不降级(不膨胀)。历史只增不减时边界单调推进、
|
|
70
115
|
* 已降级条目永不回原文——满足 write-once(须以完整历史为输入,见模块头注)。
|
|
@@ -72,19 +117,15 @@ export function resolveToolResultAgingOptions(input) {
|
|
|
72
117
|
* @param messages - **完整**历史消息(按时间序;勿传裁剪后的装配视图)
|
|
73
118
|
* @param opts - 老化配置(已解析)
|
|
74
119
|
* @param override - overflow 收敛阶梯第 0 轮(2026-11-08):ignoreTurnBoundary=true 时
|
|
75
|
-
* 豁免
|
|
120
|
+
* 豁免 run 起点限定(不限 crossRun、rawWindow 归 0)——守门兜底语境下「发得出去」
|
|
76
121
|
* 优先于「保护 turn 内工作数据/缓存前缀」;阈值(maxPointerChars/freezeBatch)不动
|
|
77
122
|
* @returns 老化计划(enabled=false 或无候选时 agedIds 为空)
|
|
78
123
|
*/
|
|
79
124
|
export function computeToolResultAgingPlan(messages, opts, override) {
|
|
80
125
|
const argsById = new Map();
|
|
81
126
|
const ordered = [];
|
|
82
|
-
let lastGenuineUserIdx = -1;
|
|
83
127
|
for (let i = 0; i < messages.length; i++) {
|
|
84
128
|
const msg = messages[i];
|
|
85
|
-
if (isTurnAnchor(msg)) {
|
|
86
|
-
lastGenuineUserIdx = i;
|
|
87
|
-
}
|
|
88
129
|
for (const tc of msg.toolCalls ?? []) {
|
|
89
130
|
argsById.set(tc.id, tc.arguments);
|
|
90
131
|
}
|
|
@@ -98,25 +139,46 @@ export function computeToolResultAgingPlan(messages, opts, override) {
|
|
|
98
139
|
});
|
|
99
140
|
}
|
|
100
141
|
}
|
|
142
|
+
const agesByCallId = new Map();
|
|
101
143
|
const agedIds = new Set();
|
|
102
144
|
if (!opts.enabled)
|
|
103
|
-
return { agedIds, argsById };
|
|
104
|
-
// 边界 =
|
|
145
|
+
return { agedIds, argsById, agersByCallId: agesByCallId, argAgedIds: new Set() };
|
|
146
|
+
// 边界 = 当前 run 起点(currentRunStartAnchorIndex,完整历史口径):同 run 的
|
|
147
|
+
// 插话/接续 turn 不推进边界(2026-11-20 拍板)——任务中途的工作数据不因插话
|
|
148
|
+
// 被降级。旧实现取「最近一条真实 user」,插话一落库就把同 run 先前的工具结果
|
|
149
|
+
// 整体划入跨轮候选(插话即触发老化)。
|
|
105
150
|
// overflow 第 0 轮豁免(ignoreTurnBoundary):全历史候选、rawWindow 归 0——
|
|
106
|
-
//
|
|
151
|
+
// run 内工作数据的保护让位于「装得下去」(arch/overflow-redesign.md §3 第 0 轮细则)
|
|
107
152
|
const ignoreTurnBoundary = override?.ignoreTurnBoundary === true;
|
|
108
|
-
const
|
|
153
|
+
const runStartIdx = currentRunStartAnchorIndex(messages);
|
|
154
|
+
const crossRun = ignoreTurnBoundary
|
|
109
155
|
? ordered
|
|
110
|
-
: ordered.filter((e) => e.msgIndex <
|
|
156
|
+
: ordered.filter((e) => e.msgIndex < runStartIdx);
|
|
111
157
|
const rawWindow = ignoreTurnBoundary ? 0 : opts.rawWindow;
|
|
112
|
-
// freezeBatch(冻结批次防抖)同属
|
|
158
|
+
// freezeBatch(冻结批次防抖)同属 run 内保护——守门语境豁免:发不出去了不等批次
|
|
113
159
|
const freezeBatch = ignoreTurnBoundary ? 1 : opts.freezeBatch;
|
|
114
|
-
const candidates =
|
|
160
|
+
const candidates = crossRun.slice(0, Math.max(0, crossRun.length - rawWindow));
|
|
115
161
|
const covered = candidates.length - (candidates.length % freezeBatch);
|
|
162
|
+
const toolAgers = override?.toolAgers;
|
|
116
163
|
for (let i = 0; i < covered; i++) {
|
|
117
164
|
const cand = candidates[i];
|
|
118
165
|
if (cand.isError)
|
|
119
166
|
continue; // 红线:error 结果永不降级(错误可追溯性优先)
|
|
167
|
+
const ager = cand.tr.name ? toolAgers?.get(cand.tr.name) : undefined;
|
|
168
|
+
if (ager) {
|
|
169
|
+
// 工具自定策略:跳过长度的预筛(作者决定什么是「该丢的」,与结果大小无关——
|
|
170
|
+
// task_list 470 字符也该丢)。仍保留不膨胀守卫:替换文本必须真的更短。
|
|
171
|
+
const replacement = ager({
|
|
172
|
+
args: argsById.get(cand.toolCallId) ?? {},
|
|
173
|
+
result: cand.tr.result,
|
|
174
|
+
chars: cand.bodyLength,
|
|
175
|
+
});
|
|
176
|
+
if (replacement !== undefined && replacement.length < cand.bodyLength) {
|
|
177
|
+
agedIds.add(cand.toolCallId);
|
|
178
|
+
agesByCallId.set(cand.toolCallId, ager);
|
|
179
|
+
}
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
120
182
|
if (cand.bodyLength <= opts.maxPointerChars)
|
|
121
183
|
continue; // 预筛:小于指针目标不值得
|
|
122
184
|
const pointer = agedToolResultPointer(cand.tr, argsById.get(cand.toolCallId), opts);
|
|
@@ -124,11 +186,67 @@ export function computeToolResultAgingPlan(messages, opts, override) {
|
|
|
124
186
|
agedIds.add(cand.toolCallId);
|
|
125
187
|
}
|
|
126
188
|
}
|
|
127
|
-
|
|
189
|
+
// 参数老化集合:**冻结区内 + 工具 opt-in**,与「结果是否成指针」解耦。
|
|
190
|
+
//
|
|
191
|
+
// 早期实现让它与 agedIds 锁步,被 file_write 证伪:该工具结果只有
|
|
192
|
+
// `{path, bytesWritten, mode}` 约 120 字符,永远小于 maxPointerChars 而不会被
|
|
193
|
+
// 老化,于是它 10k 级的 `content` 参数也就永远不会被裁——恰好放走了唯一需要
|
|
194
|
+
// 参数老化的场景。参数老化本就独立于结果大小:判据是「这条调用已经旧到冻结区」
|
|
195
|
+
// +「该工具声明参数会成为污染源」。
|
|
196
|
+
const toolArgAgers = override?.toolArgAgers;
|
|
197
|
+
const argAgedIds = new Set();
|
|
198
|
+
if (toolArgAgers?.size) {
|
|
199
|
+
for (let i = 0; i < covered; i++) {
|
|
200
|
+
const cand = candidates[i];
|
|
201
|
+
if (cand.isError)
|
|
202
|
+
continue; // 红线同结果侧:错误调用参数保留现场
|
|
203
|
+
if (cand.tr.name && toolArgAgers.has(cand.tr.name))
|
|
204
|
+
argAgedIds.add(cand.toolCallId);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { agedIds, argsById, agersByCallId: agesByCallId, argAgedIds };
|
|
128
208
|
}
|
|
129
209
|
// 指针 write-once 缓存:同 `tr` 对象 + 同配置指纹 → 同字节(toolResultBody 同款 WeakMap 先例;
|
|
130
210
|
// 消息内容写入后不可变,对象身份稳定;即便对象重建,纯函数定形也保证字节一致)。
|
|
131
211
|
const pointerCache = new WeakMap();
|
|
212
|
+
/**
|
|
213
|
+
* 单条工具结果 → 老化后的文本(**唯一裁决点**)
|
|
214
|
+
*
|
|
215
|
+
* 顺序:工具自带 ager → 默认机械指针。两处视图构建(`applyAgingToMessages`
|
|
216
|
+
* 与 `buildLlmMessages`)都必须走这里:历史上它们各写一份内联逻辑,
|
|
217
|
+
* 结果 per-tool ager 只在其中一份生效(2026-11-13 实测发现——wire dump 里
|
|
218
|
+
* file_edit 仍是默认指针,而单测覆盖的却是另一份实现)。
|
|
219
|
+
*
|
|
220
|
+
* @param tr - 工具结果条目
|
|
221
|
+
* @param args - 对应调用参数
|
|
222
|
+
* @param plan - 老化计划(提供 per-tool ager 与参数表)
|
|
223
|
+
* @param opts - 老化配置
|
|
224
|
+
* @returns 供模型读取的文本
|
|
225
|
+
*/
|
|
226
|
+
export function ageOneToolResult(tr, args, plan, opts) {
|
|
227
|
+
const ager = plan.agersByCallId.get(tr.toolCallId);
|
|
228
|
+
const viaAger = ager?.({
|
|
229
|
+
args: args ?? {},
|
|
230
|
+
result: tr.result,
|
|
231
|
+
chars: toolResultBody(tr).length,
|
|
232
|
+
});
|
|
233
|
+
return viaAger ?? agedToolResultPointer(tr, args, opts);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 单条工具调用 → 是否应降级其参数(**唯一裁决点**)
|
|
237
|
+
*
|
|
238
|
+
* 只看 `plan.argAgedIds`(冻结区 ∩ 工具 opt-in)。不要再回退到 `agedIds`:
|
|
239
|
+
* 那会让「结果恰好够大」的工具绕过 opt-in 白名单,正是 file_edit 参数在
|
|
240
|
+
* 2026-11-13 仍被全局降级的原因。
|
|
241
|
+
*
|
|
242
|
+
* @param toolCallId - 调用 id
|
|
243
|
+
* @param plan - 老化计划
|
|
244
|
+
* @param opts - 老化配置(含总开关 `ageToolArgs`)
|
|
245
|
+
* @returns 是否降级
|
|
246
|
+
*/
|
|
247
|
+
export function shouldAgeArgs(toolCallId, plan, opts) {
|
|
248
|
+
return opts.ageToolArgs && plan.argAgedIds.has(toolCallId);
|
|
249
|
+
}
|
|
132
250
|
/**
|
|
133
251
|
* 把老化计划物化为消息视图副本(新建对象,不改原消息)
|
|
134
252
|
*
|
|
@@ -142,15 +260,17 @@ const pointerCache = new WeakMap();
|
|
|
142
260
|
* @returns 消息副本(老化条目的正文替换为指针;无老化条目时原样返回同一数组)
|
|
143
261
|
*/
|
|
144
262
|
export function applyAgingToMessages(messages, plan, opts) {
|
|
145
|
-
|
|
263
|
+
// 提前返回必须同时看两个集合:file_write 这类「结果小、参数大」的调用只会在
|
|
264
|
+
// argAgedIds 里出现(结果永远够不到 maxPointerChars),只看 agedIds 会整段跳过。
|
|
265
|
+
if (plan.agedIds.size === 0 && plan.argAgedIds.size === 0)
|
|
146
266
|
return messages;
|
|
147
267
|
return messages.map((msg) => {
|
|
148
268
|
let next = msg;
|
|
149
269
|
// 参数与结果同步老化:只动「结果已老化」的那条调用,配对结构不变
|
|
150
|
-
if (opts.ageToolArgs && msg.toolCalls?.length) {
|
|
270
|
+
if (opts.ageToolArgs && plan.argAgedIds.size > 0 && msg.toolCalls?.length) {
|
|
151
271
|
let callsChanged = false;
|
|
152
272
|
const toolCalls = msg.toolCalls.map((tc) => {
|
|
153
|
-
if (!
|
|
273
|
+
if (!shouldAgeArgs(tc.id, plan, opts))
|
|
154
274
|
return tc;
|
|
155
275
|
callsChanged = true;
|
|
156
276
|
return { ...tc, arguments: agedToolArgDigest(tc.name, tc.arguments, opts) };
|
|
@@ -165,10 +285,9 @@ export function applyAgingToMessages(messages, plan, opts) {
|
|
|
165
285
|
if (!plan.agedIds.has(tr.toolCallId))
|
|
166
286
|
return tr;
|
|
167
287
|
changed = true;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
288
|
+
// 统一裁决点(与 buildLlmMessages 同一实现,防两份逻辑漂移)
|
|
289
|
+
const replacement = ageOneToolResult(tr, plan.argsById.get(tr.toolCallId), plan, opts);
|
|
290
|
+
return { ...tr, result: replacement };
|
|
172
291
|
});
|
|
173
292
|
return changed ? { ...next, toolResults: results } : next;
|
|
174
293
|
});
|
|
@@ -176,12 +295,17 @@ export function applyAgingToMessages(messages, plan, opts) {
|
|
|
176
295
|
/**
|
|
177
296
|
* 生成结构化摘要指针(机械、零 LLM、确定性)
|
|
178
297
|
*
|
|
179
|
-
* 布局:工具名 +
|
|
180
|
-
*
|
|
298
|
+
* 布局:工具名 + 结果长度 + 结果轮廓 + 短提示。
|
|
299
|
+
*
|
|
300
|
+
* 不含参数轮廓(2026-11-13 实测):指针里的 args 是**机械截断**产物(130 条指针
|
|
301
|
+
* 全部恰好 98 字符 = 预算 80 + 截断标记),从不承载有效信息;对应的 tool_use 就在
|
|
302
|
+
* 前一条 assistant 消息里,`ageToolArgs` 还额外全保 path/command/id。留着是纯重复。
|
|
303
|
+
* 连同旧尾句(81 字符/条)一并去掉——它把「不要重跑」重复 130 遍,反而在提示重跑。
|
|
304
|
+
*
|
|
181
305
|
* error 分支为防御性保真(计划永不选中 error 结果)。
|
|
182
306
|
*
|
|
183
307
|
* @param tr - 工具结果(error / result 至少其一)
|
|
184
|
-
* @param args -
|
|
308
|
+
* @param args - 对应工具调用参数(保留入参供策略复用;默认指针不再消费)
|
|
185
309
|
* @param opts - 老化配置(已解析)
|
|
186
310
|
* @returns 指针文本(write-once:同输入恒同字节)
|
|
187
311
|
*/
|
|
@@ -190,17 +314,13 @@ export function agedToolResultPointer(tr, args, opts) {
|
|
|
190
314
|
const cached = pointerCache.get(tr);
|
|
191
315
|
if (cached && cached.fingerprint === fingerprint)
|
|
192
316
|
return cached.text;
|
|
193
|
-
const argsBudget = Math.max(MIN_ARGS_OUTLINE_CHARS, Math.floor(opts.maxPointerChars * ARGS_OUTLINE_RATIO));
|
|
194
317
|
const resultBudget = Math.max(MIN_RESULT_OUTLINE_CHARS, Math.floor(opts.maxPointerChars * RESULT_OUTLINE_RATIO));
|
|
195
|
-
const argsOutline = truncateOutline(safeJson(args ?? {}), argsBudget);
|
|
196
318
|
// 结果轮廓只保留头部,若不给总量,读方会把「头部那几条」误当成全部(file_search 尤甚)
|
|
197
319
|
const resultBody = toolResultOutline(tr);
|
|
198
320
|
const errorOrResult = tr.error !== undefined
|
|
199
321
|
? `error: ${tr.error}` // 防御性保真:错误文案不截断、不改写
|
|
200
322
|
: `result ${resultBody.length} chars: ${truncateOutline(resultBody, resultBudget)}`;
|
|
201
|
-
const text =
|
|
202
|
-
`args: ${argsOutline}; ${errorOrResult}; ` +
|
|
203
|
-
'full output kept in session log — do NOT re-run unless the output is needed again';
|
|
323
|
+
const text = `${AGED_POINTER_PREFIX} ${tr.name ?? 'unknown'}; ${errorOrResult}${AGED_POINTER_HINT}`;
|
|
204
324
|
pointerCache.set(tr, { fingerprint, text });
|
|
205
325
|
return text;
|
|
206
326
|
}
|
|
@@ -209,7 +329,7 @@ export function agedToolResultPointer(tr, args, opts) {
|
|
|
209
329
|
*
|
|
210
330
|
* 规则(机械、确定性、无 LLM):
|
|
211
331
|
* 1. **键名全保**——LLM 需要知道调用了哪个路径/命令才能在必要时重跑;
|
|
212
|
-
* 2. 序列化长度超过 {@link ARG_VALUE_KEEP_CHARS}
|
|
332
|
+
* 2. 序列化长度超过 {@link ARG_VALUE_KEEP_CHARS} 的值替换为对象形标记 `{"$octopi_elided": {"chars": N}}`(锚点类——定位字段与命令——全保不降级);
|
|
213
333
|
* 3. 若仍是超预算,按「值从大到小、同大小按键名」顺序继续替换,保证确定性;
|
|
214
334
|
* 4. 兜底:键名太多装不下时退化为整体轮廓截断。
|
|
215
335
|
*
|
|
@@ -242,7 +362,12 @@ export function agedToolArgDigest(name, args, opts) {
|
|
|
242
362
|
// 预算只约束「内容值」,定位字段不计入:
|
|
243
363
|
// 否则一条绝对路径就能吃掉整个预算,反而先把唯一锚点挤掉(实测 path 均长 79,
|
|
244
364
|
// 若计入预算,file_edit 这类调用会退化成「看不到改了哪个文件」)。
|
|
245
|
-
|
|
365
|
+
// 已降级值按固定小成本计费:标记串是不可再压的结构噪声,按字面长度计费会让
|
|
366
|
+
// 标记变长把多键调用挤进 _aged 兜底、反而丢键名(OP-TOOL-1 评审 M2:
|
|
367
|
+
// 命名空间标记 +12 字符曾把「键名全保」阈值从 ~17 键压到 10 键)。
|
|
368
|
+
const contentChars = () => safeJson(Object.fromEntries(Object.entries(out)
|
|
369
|
+
.filter(([k]) => !ANCHOR_FIELDS.has(k))
|
|
370
|
+
.map(([k, v]) => [k, isElisionToken(v) ? ELIDED_VALUE_BUDGET_COST : v]))).length;
|
|
246
371
|
const contentEntries = entries
|
|
247
372
|
.filter((e) => !ANCHOR_FIELDS.has(e.k))
|
|
248
373
|
.sort((a, b) => b.size - a.size || (a.k < b.k ? -1 : a.k > b.k ? 1 : 0));
|
|
@@ -251,34 +376,60 @@ export function agedToolArgDigest(name, args, opts) {
|
|
|
251
376
|
break;
|
|
252
377
|
out[e.k] = elidedMarker(e.size);
|
|
253
378
|
}
|
|
379
|
+
// 兜底(键名过多装不下)也必须带上 purpose:它是任务逻辑的可读记录,
|
|
380
|
+
// 整体轮廓截断只保留头部,purpose 很可能不在其中。purpose 不是内容载荷,
|
|
381
|
+
// 不参与预算,因此这里无条件回附。
|
|
382
|
+
const rawPurpose = args[PURPOSE_FIELD];
|
|
254
383
|
const value = contentChars() > opts.maxAgedArgChars
|
|
255
|
-
? {
|
|
384
|
+
? {
|
|
385
|
+
_aged: `${name} arguments elided`,
|
|
386
|
+
outline: truncateOutline(safeJson(args), opts.maxAgedArgChars),
|
|
387
|
+
...(typeof rawPurpose === 'string' ? { [PURPOSE_FIELD]: rawPurpose } : {}),
|
|
388
|
+
}
|
|
256
389
|
: out;
|
|
257
390
|
argDigestCache.set(args, { fingerprint, value });
|
|
258
391
|
return value;
|
|
259
392
|
}
|
|
260
|
-
/**
|
|
393
|
+
/** 值被省略时的长度标记(对象形,词汇表单一来源:core/elision)
|
|
394
|
+
*
|
|
395
|
+
* 对象形而非文本形:文本标记与真实内容同形,会被模型当内容回抄进 tool call
|
|
396
|
+
* (OP-TOOL-1 实证污染源);对象形语法类别上就不是内容,抄入 string 参数即
|
|
397
|
+
* schema 违规,执行边界守卫再兜底拒收。
|
|
398
|
+
*/
|
|
261
399
|
function elidedMarker(chars) {
|
|
262
|
-
return
|
|
400
|
+
return elidedValueMarker(chars);
|
|
263
401
|
}
|
|
264
402
|
/**
|
|
265
403
|
* 定位字段:它们短、且是「这条调用到底碰了哪里」的唯一锚点,优先全保
|
|
266
404
|
*
|
|
267
|
-
* 实测:`path` 均长 79 字符(全保仅 +1.5%
|
|
268
|
-
* (全保 +8.6
|
|
405
|
+
* 实测:`path` 均长 79 字符(全保仅 +1.5% 请求体),`command` 均长 414
|
|
406
|
+
* (全保 +8.6%)。路径类全保;命令类同样全保不截断(2026-11-12 拍板:截断
|
|
407
|
+
* 收益有限、文本尾标记却是回抄污染源——OP-TOOL-1 sed/grep 案半数案例)。
|
|
269
408
|
*/
|
|
270
409
|
const LOCATOR_FIELDS = new Set(['path', 'file', 'glob', 'pattern', 'cwd']);
|
|
410
|
+
/**
|
|
411
|
+
* purpose 字段:**永不因内容预算或长度被降级**(2026-11-13 拍板)
|
|
412
|
+
*
|
|
413
|
+
* purpose 是「这次调用做了什么、为什么」的唯一人类可读记录,是后续读方重建
|
|
414
|
+
* 整个任务逻辑的关键信息(arch/tool-call-purpose.md)。它作为普通参数进入
|
|
415
|
+
* `tool_call.arguments`,若按常规阈值处理会被直接替换成
|
|
416
|
+
* `{"$octopi:elided":{"chars":N}}`——实测生产会话 424 条 purpose 里有 14 条
|
|
417
|
+
* (3.3%)如此,长度 66–77,正是「说清一件事」的常见区间。
|
|
418
|
+
*
|
|
419
|
+
* 因此这里**不设长度上限**:老化只做「信息取舍」,不做「长度治理」。长度约束
|
|
420
|
+
* 属于调用入口的职责(schema 声明 + 工具总线校验),在视图侧截断既管不住入口、
|
|
421
|
+
* 又会永久毁掉已发生调用的可读性。
|
|
422
|
+
*/
|
|
423
|
+
const PURPOSE_FIELD = 'purpose';
|
|
271
424
|
/**
|
|
272
425
|
* 锚点字段:不占用内容预算(否则定位信息会被内容载荷挤出)
|
|
273
426
|
*
|
|
274
|
-
* 定位字段与命令字段都属锚点——`command`
|
|
275
|
-
* 若让它和 `old_text`
|
|
427
|
+
* 定位字段与命令字段都属锚点——`command` 全文回答「跑了什么」,
|
|
428
|
+
* 若让它和 `old_text` 之类抢同一个预算,多条命令一累加就会把命令整体省略掉。
|
|
276
429
|
*/
|
|
277
|
-
const ANCHOR_FIELDS = new Set([...LOCATOR_FIELDS, 'command', 'cmd']);
|
|
430
|
+
const ANCHOR_FIELDS = new Set([...LOCATOR_FIELDS, 'command', 'cmd', PURPOSE_FIELD]);
|
|
278
431
|
/** 定位字段全保上限(超长的罕见路径才会退化为标记) */
|
|
279
432
|
const LOCATOR_KEEP_CHARS = 200;
|
|
280
|
-
/** 命令类字段保留的头部长度(其余用长度标记收尾) */
|
|
281
|
-
const COMMAND_HEAD_CHARS = 100;
|
|
282
433
|
/** 命令类字段名 */
|
|
283
434
|
const COMMAND_FIELDS = new Set(['command', 'cmd']);
|
|
284
435
|
function isLocatorField(key) {
|
|
@@ -293,15 +444,18 @@ function isLocatorField(key) {
|
|
|
293
444
|
* @returns 保留原值、头部摘录或长度标记
|
|
294
445
|
*/
|
|
295
446
|
function digestArgValue(key, value, size) {
|
|
447
|
+
// purpose 无条件全保:它是任务逻辑的可读记录,不是可牺牲的内容载荷
|
|
448
|
+
if (key === PURPOSE_FIELD)
|
|
449
|
+
return value;
|
|
296
450
|
if (size <= ARG_VALUE_KEEP_CHARS)
|
|
297
451
|
return value;
|
|
298
452
|
if (isLocatorField(key) && size <= LOCATOR_KEEP_CHARS)
|
|
299
453
|
return value;
|
|
300
454
|
if (COMMAND_FIELDS.has(key) && typeof value === 'string') {
|
|
301
|
-
//
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return
|
|
455
|
+
// 命令不截断、全保(2026-11-12 拍板):截断省的量有限(锚点本就不占内容预算),
|
|
456
|
+
// 文本尾标记却是模型回抄污染源(OP-TOOL-1 sed/grep 案半数案例)。digest
|
|
457
|
+
// 恒 ≤ 原始 args(本字段与原值相同、其余字段只减不增),不引入新的无界增长。
|
|
458
|
+
return value;
|
|
305
459
|
}
|
|
306
460
|
return elidedMarker(size);
|
|
307
461
|
}
|
|
@@ -338,5 +492,5 @@ function safeJson(value) {
|
|
|
338
492
|
* @returns 轮廓文本
|
|
339
493
|
*/
|
|
340
494
|
function truncateOutline(text, maxChars) {
|
|
341
|
-
return text.length <= maxChars ? text : `${text.slice(0, maxChars)}${
|
|
495
|
+
return text.length <= maxChars ? text : `${text.slice(0, maxChars)}${TRUNCATED_MARK}`;
|
|
342
496
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Message } from '@octopi-agent/core/types.js';
|
|
10
10
|
import type { LLMMessage, LLMToolDefinition } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
11
|
+
import type { RequestView } from '@octopi-agent/core/loop/types.js';
|
|
11
12
|
import type { SummarizeFunction } from './capabilities/compact/types.js';
|
|
12
13
|
export type { LLMMessage, LLMToolDefinition };
|
|
13
14
|
/** 族 A 摘要执行契约:单源定义在 capabilities/compact/types.ts(此处再导出保持域内引用面稳定)。 */
|
|
@@ -51,13 +52,16 @@ export type ContextCompactReason = 'proactive' | 'overflow' | 'manual';
|
|
|
51
52
|
* 避免 LLM 摘要耗时被误判为会话卡死。失败不中断本轮(引擎回退截断)。
|
|
52
53
|
*/
|
|
53
54
|
export interface ContextCompactEvent {
|
|
54
|
-
type: 'context.compact.start' | 'context.compact.progress' | 'context.compact.end' | 'context.compact.error' | 'context.compact.summarize_fallback';
|
|
55
|
+
type: 'context.compact.start' | 'context.compact.progress' | 'context.compact.end' | 'context.compact.error' | 'context.compact.summarize_fallback' | 'context.compact.contamination';
|
|
55
56
|
sessionId: string;
|
|
56
57
|
reason?: ContextCompactReason;
|
|
57
58
|
/** 压缩前估算 token */
|
|
58
59
|
tokensBefore?: number;
|
|
59
60
|
/** 压缩后估算 token(end) */
|
|
60
61
|
tokensAfter?: number;
|
|
62
|
+
/** 当前上下文大小快照(显示槽;tokens 与 tokensAfter 同值同源,报告尺)。
|
|
63
|
+
* 只在真压缩完成时携带——0/0(无新压缩)与 cancelled 不带 = 显示不动 */
|
|
64
|
+
contextSize?: ContextSizeSnapshot;
|
|
61
65
|
/** 触发阈值(proactive) */
|
|
62
66
|
threshold?: number;
|
|
63
67
|
/** 耗时 ms(end/error) */
|
|
@@ -73,13 +77,63 @@ export interface ContextCompactEvent {
|
|
|
73
77
|
kind?: 'denied' | 'failed';
|
|
74
78
|
/** progress:当前阶段(summarize = 摘要请求已发出、等 provider 返回) */
|
|
75
79
|
phase?: 'summarize';
|
|
76
|
-
/** progress:摘要请求体量(JSON
|
|
80
|
+
/** progress:摘要请求体量(JSON 字符数,内部诊断用) */
|
|
77
81
|
requestChars?: number;
|
|
82
|
+
/** progress:摘要请求 token 估算(与会话请求同口径,UI 显示此值) */
|
|
83
|
+
requestTokens?: number;
|
|
78
84
|
/** progress:摘要请求消息条数 */
|
|
79
85
|
requestMessages?: number;
|
|
80
86
|
/** progress:本次摘要调用预算(ms);缺失 = 不设预算 */
|
|
81
87
|
timeoutMs?: number;
|
|
88
|
+
/** contamination:闸门判定结论(clean = 通过) */
|
|
89
|
+
verdict?: 'clean' | 'canned_refusal' | 'transcript_shape' | 'verbatim_echo';
|
|
90
|
+
/** contamination:第几次尝试(1=首次,2=strict 重试) */
|
|
91
|
+
attempt?: number;
|
|
92
|
+
/** contamination:是否因此丢弃本输出并重试 */
|
|
93
|
+
retryTriggered?: boolean;
|
|
94
|
+
/** contamination:回声命中行数 */
|
|
95
|
+
echoHits?: number;
|
|
96
|
+
/** contamination:回声命中字符数 */
|
|
97
|
+
echoHitChars?: number;
|
|
98
|
+
/** contamination:被判定的输出字符数 */
|
|
99
|
+
textChars?: number;
|
|
82
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* 当前上下文大小(显示槽,持久化取数源——web 顶栏「xxx / xxx」前段只从这里取)。
|
|
103
|
+
*
|
|
104
|
+
* 语义(as-of,不猜增长):`tokens` = 最近一次**测量/压缩**时点的全请求口径大小;
|
|
105
|
+
* `source` 标注是哪把尺(R3 显示标注硬规则):'usage' = provider 实测(step.end 真实用量),
|
|
106
|
+
* 'compact-est' = 压缩后估算(报告尺 rawRequestViewTokens)。消息增长导致的偏差停在
|
|
107
|
+
* 上次测量点,由 `asOf` 标注时点,不引入第三把尺。
|
|
108
|
+
*
|
|
109
|
+
* 写点(写入即持久化 session.metadata.contextSize):
|
|
110
|
+
* ① 真实用量到达(runner step.end,writer=usage)——stale 回填不写(不冒名新实测);
|
|
111
|
+
* ② 压缩完成(manual=runner.compactSession 持久化 / auto=compact.end 事件携带、随
|
|
112
|
+
* 该步 usage 或 run 收尾落盘)。其余情况不写:0/0(无新压缩)与 cancelled(中止零
|
|
113
|
+
* 写入)事件不带本字段 = 不动显示。
|
|
114
|
+
*/
|
|
115
|
+
export interface ContextSizeSnapshot {
|
|
116
|
+
tokens: number;
|
|
117
|
+
source: 'usage' | 'compact-est';
|
|
118
|
+
/** 写入时点(epoch ms) */
|
|
119
|
+
asOf: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 构造 contextSize 快照(唯一构造点:source/asOf 语义一致,禁止手抄字面量)。
|
|
123
|
+
*
|
|
124
|
+
* @param source - 读数来源(usage=provider 实测 / compact-est=压缩后估算)
|
|
125
|
+
* @param tokens - 全请求口径 token 数
|
|
126
|
+
* @returns 快照
|
|
127
|
+
*/
|
|
128
|
+
export declare function contextSizeSnapshot(source: ContextSizeSnapshot['source'], tokens: number): ContextSizeSnapshot;
|
|
129
|
+
/**
|
|
130
|
+
* ContextSizeSnapshot 形状守卫(所有摄入点共用,禁止各处手抄校验强度不一——评审 F-4)。
|
|
131
|
+
* metadata 是自由 JSON、事件/REST 是跨进程边界,脏值不得当读数显示。
|
|
132
|
+
*
|
|
133
|
+
* @param v - 待校验值
|
|
134
|
+
* @returns 是否合法快照
|
|
135
|
+
*/
|
|
136
|
+
export declare function isContextSizeSnapshot(v: unknown): v is ContextSizeSnapshot;
|
|
83
137
|
/** 事件回调(Builder 注入 → EventBus) */
|
|
84
138
|
export type ContextEmitFn = (event: ContextCompactEvent | OverflowAlertEvent) => void;
|
|
85
139
|
/**
|
|
@@ -118,6 +172,15 @@ export interface AssembleParams {
|
|
|
118
172
|
systemPrompt: string;
|
|
119
173
|
/** 可用工具定义 */
|
|
120
174
|
tools: LLMToolDefinition[];
|
|
175
|
+
/**
|
|
176
|
+
* 工具名 → 结果老化函数(来自 `AgentTool.ageResult`,经 `collectToolAgers` 收集)。
|
|
177
|
+
*
|
|
178
|
+
* 与 `tools` 分开传:`tools` 是发给 LLM 的 wire 投影(用于 toolsHash 与摘要前缀比对),
|
|
179
|
+
* 而老化函数只在装配视图里用,不能混进 wire 面。未提供 = 全部走默认规则。
|
|
180
|
+
*/
|
|
181
|
+
toolAgers?: ReadonlyMap<string, import('@octopi-agent/core/types.js').ToolResultAger>;
|
|
182
|
+
/** 参数可老化的工具名(缺省 = 参数一律原样保留,见 RegisteredTool.ageArgs) */
|
|
183
|
+
toolArgAgers?: ReadonlySet<string>;
|
|
121
184
|
/**
|
|
122
185
|
* Token 预算(可用空间)。
|
|
123
186
|
* 未配置 contextWindow 时应省略:跳过基于窗口的自动压缩与预算截断。
|
|
@@ -173,8 +236,12 @@ export interface ContextCompactSnapshot {
|
|
|
173
236
|
/** 上次主动压缩后的视图 token 估算 */
|
|
174
237
|
lastProactiveTokens?: number;
|
|
175
238
|
}
|
|
176
|
-
export interface AssembleResult {
|
|
177
|
-
/**
|
|
239
|
+
export interface AssembleResult extends RequestView {
|
|
240
|
+
/**
|
|
241
|
+
* 组装好的 LLM 消息(来自 {@link RequestView})
|
|
242
|
+
*
|
|
243
|
+
* 与 `tools` 一起构成缓存前缀的原子单位;调用方不得只转发一半。
|
|
244
|
+
*/
|
|
178
245
|
messages: LLMMessage[];
|
|
179
246
|
/** 实际 token 数(由 TokenEstimator 提供) */
|
|
180
247
|
estimatedTokens: number;
|
|
@@ -6,4 +6,28 @@
|
|
|
6
6
|
*
|
|
7
7
|
* 接入:Builder 经 convertToLlm 调用 assemble;Loop 不依赖本类型。
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 构造 contextSize 快照(唯一构造点:source/asOf 语义一致,禁止手抄字面量)。
|
|
11
|
+
*
|
|
12
|
+
* @param source - 读数来源(usage=provider 实测 / compact-est=压缩后估算)
|
|
13
|
+
* @param tokens - 全请求口径 token 数
|
|
14
|
+
* @returns 快照
|
|
15
|
+
*/
|
|
16
|
+
export function contextSizeSnapshot(source, tokens) {
|
|
17
|
+
return { tokens, source, asOf: Date.now() };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* ContextSizeSnapshot 形状守卫(所有摄入点共用,禁止各处手抄校验强度不一——评审 F-4)。
|
|
21
|
+
* metadata 是自由 JSON、事件/REST 是跨进程边界,脏值不得当读数显示。
|
|
22
|
+
*
|
|
23
|
+
* @param v - 待校验值
|
|
24
|
+
* @returns 是否合法快照
|
|
25
|
+
*/
|
|
26
|
+
export function isContextSizeSnapshot(v) {
|
|
27
|
+
if (!v || typeof v !== 'object')
|
|
28
|
+
return false;
|
|
29
|
+
const s = v;
|
|
30
|
+
return (typeof s.tokens === 'number' &&
|
|
31
|
+
(s.source === 'usage' || s.source === 'compact-est') &&
|
|
32
|
+
typeof s.asOf === 'number');
|
|
33
|
+
}
|
|
@@ -12,8 +12,8 @@ import { type ProcessIsolationProfile } from './process-isolation.js';
|
|
|
12
12
|
export type EffectRunMode = 'workspace' | 'project' | 'host' | 'untrusted';
|
|
13
13
|
/**
|
|
14
14
|
* Engine default when `effectPolicy.mode` is omitted (secure-by-default).
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* `octopi init` scaffolds `mode: "project"` (coding-agent profile);
|
|
16
|
+
* `octopi.example.json` sets `mode: "host"` explicitly for full local capability.
|
|
17
17
|
* See `docs/process-isolation.md`.
|
|
18
18
|
*/
|
|
19
19
|
export declare const DEFAULT_EFFECT_RUN_MODE: EffectRunMode;
|
|
@@ -101,7 +101,8 @@ export type SecurityDegradation = 'no_process_jail' | 'network_open' | 'env_inhe
|
|
|
101
101
|
export interface EffectPolicyConfig {
|
|
102
102
|
/**
|
|
103
103
|
* Omitted = `DEFAULT_EFFECT_RUN_MODE` (**workspace**, secure-by-default).
|
|
104
|
-
*
|
|
104
|
+
* `octopi init` scaffolds `"mode": "project"` (coding-agent profile);
|
|
105
|
+
* `octopi.example.json` demonstrates `"mode": "host"` explicitly for full local capability.
|
|
105
106
|
*/
|
|
106
107
|
mode?: EffectRunMode;
|
|
107
108
|
/**
|
|
@@ -14,8 +14,8 @@ import { resolveHitlOutcome } from '../../governance/human-in-the-loop/decision-
|
|
|
14
14
|
import { getRunSessionId, getRunScope } from '../../run/run-scope.js';
|
|
15
15
|
/**
|
|
16
16
|
* Engine default when `effectPolicy.mode` is omitted (secure-by-default).
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* `octopi init` scaffolds `mode: "project"` (coding-agent profile);
|
|
18
|
+
* `octopi.example.json` sets `mode: "host"` explicitly for full local capability.
|
|
19
19
|
* See `docs/process-isolation.md`.
|
|
20
20
|
*/
|
|
21
21
|
export const DEFAULT_EFFECT_RUN_MODE = 'workspace';
|