@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Harness Context 模块导出
|
|
3
3
|
*/
|
|
4
|
-
export type { ContextEngine, ContextEngineInfo, AssembleParams, AssembleResult, IngestParams, AfterStepParams, TokenEstimator, SummarizeFunction, MessageSelector, SelectResult, SelectOptions, BudgetAllocator, BudgetAllocateParams, BudgetAllocateResult, ContextCompactReason, ContextCompactEvent, ContextEmitFn, OverflowAlertEvent, ContextCompactSnapshot, } from './types.js';
|
|
4
|
+
export type { ContextEngine, ContextEngineInfo, AssembleParams, AssembleResult, IngestParams, AfterStepParams, TokenEstimator, SummarizeFunction, MessageSelector, SelectResult, SelectOptions, BudgetAllocator, BudgetAllocateParams, BudgetAllocateResult, ContextCompactReason, ContextCompactEvent, ContextEmitFn, ContextSizeSnapshot, OverflowAlertEvent, ContextCompactSnapshot, } from './types.js';
|
|
5
|
+
export { contextSizeSnapshot, isContextSizeSnapshot } from './types.js';
|
|
5
6
|
export { DefaultContextEngine } from './default-context-engine.js';
|
|
6
7
|
export type { DefaultContextEngineConfig } from './default-context-engine.js';
|
|
7
8
|
export { formatTurnId, formatTurnStartContent, formatTurnEndContent, formatTurnContextXml, extractUserMessageText, stripTurnContextXml, isTurnStartContent, isTurnEndContent, parseTurnIdFromContent, parseTurnEnvelope, joinSlotXml, unwrapUserText, messageText, escapeUserMessageText, } from './turn-envelope.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Harness Context 模块导出
|
|
3
3
|
*/
|
|
4
|
+
export { contextSizeSnapshot, isContextSizeSnapshot } from './types.js';
|
|
4
5
|
export { DefaultContextEngine } from './default-context-engine.js';
|
|
5
6
|
export { formatTurnId, formatTurnStartContent, formatTurnEndContent, formatTurnContextXml, extractUserMessageText, stripTurnContextXml, isTurnStartContent, isTurnEndContent, parseTurnIdFromContent, parseTurnEnvelope, joinSlotXml, unwrapUserText, messageText, escapeUserMessageText, } from './turn-envelope.js';
|
|
6
7
|
// ── Token 估算(跨域门面;浏览器侧可直连 token-estimator / token-constants) ──
|
|
@@ -15,6 +15,8 @@ export interface ContextLayerHealthEntry {
|
|
|
15
15
|
entries?: number;
|
|
16
16
|
/** 附加读数(如 cognition edges) */
|
|
17
17
|
extra?: Record<string, number>;
|
|
18
|
+
/** 显式降级注记(如语义种子不可用);无降级为空/缺省 */
|
|
19
|
+
degraded?: string[];
|
|
18
20
|
}
|
|
19
21
|
export interface ContextLayerHealth {
|
|
20
22
|
agentId: string;
|
|
@@ -34,6 +36,8 @@ export interface ContextLayerHealth {
|
|
|
34
36
|
}
|
|
35
37
|
export interface ProbeContextHealthDeps {
|
|
36
38
|
agentId: string;
|
|
39
|
+
/** 语义种子能力的装配事实:true/false=调用方确知(如实注记),缺省=未知(不冒充能力判定) */
|
|
40
|
+
semanticSeedsCapable?: boolean;
|
|
37
41
|
skillCount?: number;
|
|
38
42
|
memoryStore?: MemoryStore;
|
|
39
43
|
knowledgeCatalog?: KnowledgeCatalogProvider;
|
|
@@ -145,6 +145,10 @@ export async function probeContextLayerHealth(deps) {
|
|
|
145
145
|
...(id === 'cognition' && cognitionEdges !== undefined
|
|
146
146
|
? { extra: { edges: cognitionEdges } }
|
|
147
147
|
: {}),
|
|
148
|
+
// 显式降级:仅当调用方确知装配缺失时注记(home 探针无装配事实时不得冒充能力判定)
|
|
149
|
+
...(id === 'cognition' && deps.semanticSeedsCapable === false
|
|
150
|
+
? { degraded: ['semantic_seeds_unavailable'] }
|
|
151
|
+
: {}),
|
|
148
152
|
};
|
|
149
153
|
});
|
|
150
154
|
return {
|
|
@@ -237,6 +237,63 @@ export declare function isTurnAnchor(msg: {
|
|
|
237
237
|
delivery?: unknown;
|
|
238
238
|
};
|
|
239
239
|
}): boolean;
|
|
240
|
+
/**
|
|
241
|
+
* turn 边界锚点判定(边界类消费方共用:isMidTurn / compact / tool-result-aging)。
|
|
242
|
+
*
|
|
243
|
+
* isTurnAnchor 基础上剔除 **agentId 归因** 的 user 消息(appendCommandDiscourse:
|
|
244
|
+
* slash 命令话语、多 agent 共线记录)——它们不是主对话发言,不得推进任何 turn
|
|
245
|
+
* 边界。此前 tool-result-aging 用裸 isTurnAnchor 各自判边界,命令话语会误推进
|
|
246
|
+
* 老化边界(与 isMidTurn/compact 不一致,2026-11-20 收敛到本谓词)。
|
|
247
|
+
*
|
|
248
|
+
* 注意各消费方**边界语义有意不同**,只是共享锚点定义:aging 取 run 起点
|
|
249
|
+
* ({@link currentRunStartAnchorIndex},插话不推进);compact/isMidTurn 仍取
|
|
250
|
+
* 最近锚点(turn 语义——压缩门控本就是 turn 域)。勿把「谓词统一」误读为
|
|
251
|
+
* 「边界统一」(评审 del-5ca70159 P2-3)。
|
|
252
|
+
*
|
|
253
|
+
* @param msg - 消息(结构化入参,接受 Message 及其裁剪形态)
|
|
254
|
+
* @returns true = 可作为 turn 边界锚点
|
|
255
|
+
*/
|
|
256
|
+
export declare function isTurnBoundaryAnchor(msg: {
|
|
257
|
+
role?: string;
|
|
258
|
+
agentId?: string;
|
|
259
|
+
metadata?: Record<string, unknown>;
|
|
260
|
+
}): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* 当前 run 起点锚点下标(tool-result-aging 的保护边界)。
|
|
263
|
+
*
|
|
264
|
+
* 「当前 run 永不老化」按 **run 起点** 计(2026-11-20 拍板):同一 run 的
|
|
265
|
+
* 插话 / 接续注入(v0.95 起同 run 多 turn)不推进老化边界,任务中途的工具
|
|
266
|
+
* 工作数据不被降级。锚点携带 `metadata.runId`(runner 在 bakeTurnStart 打标):
|
|
267
|
+
* - 最后锚点无 runId(升级前历史)→ 回落 turn 语义(= 最后锚点,旧行为);
|
|
268
|
+
* - 回溯遇**无 runId 或不同 runId** 的锚点即停(无归因锚点作 run 分界)。
|
|
269
|
+
* 「即停」而非「跳过」是 write-once 的前提:跳过会让未打标锚点夹在同 run
|
|
270
|
+
* 打标锚点之间时把边界**拉回**(已降级条目回原文、批量段翻转,F1 事故形态;
|
|
271
|
+
* 评审 del-5ca70159 P1-1 反例)。即停保证边界随历史增长单调前进,
|
|
272
|
+
* 最坏只是多保护一段旧数据,永不回退。
|
|
273
|
+
*
|
|
274
|
+
* @param messages - 完整历史消息(按时间序)
|
|
275
|
+
* @returns 当前 run 起点锚点下标;无锚点时 -1
|
|
276
|
+
*/
|
|
277
|
+
export declare function currentRunStartAnchorIndex(messages: ReadonlyArray<{
|
|
278
|
+
role?: string;
|
|
279
|
+
agentId?: string;
|
|
280
|
+
metadata?: Record<string, unknown>;
|
|
281
|
+
}>): number;
|
|
282
|
+
/**
|
|
283
|
+
* 中止标记锚点 = 某 turn 的用户输入:开轮信封(含 wake 等机器输入),或定形前的
|
|
284
|
+
* 裸用户输入。abort / edit-resend 的截断锚点判定(view 与写路径同口径)。
|
|
285
|
+
*
|
|
286
|
+
* 历史:本谓词曾在 run-host 与 gateway 各存一份手抄(run-host 迁移时声称单一来源,
|
|
287
|
+
* gateway 副本未删)——2026-11-20 合并到本文件,turn 边界类谓词一处收口。
|
|
288
|
+
*
|
|
289
|
+
* @param msg - 待判定消息(abort 标记指向的历史条目)
|
|
290
|
+
* @returns true = 可作为中止 turn 的截断锚点
|
|
291
|
+
*/
|
|
292
|
+
export declare function isTurnInput(msg: {
|
|
293
|
+
role?: string;
|
|
294
|
+
content?: Message['content'];
|
|
295
|
+
metadata?: Record<string, unknown>;
|
|
296
|
+
} | undefined): boolean;
|
|
240
297
|
/**
|
|
241
298
|
* 人话判定(人类文本类消费方:title / grounding.latestUserText / backfill userTurns)。
|
|
242
299
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* 各层业务实现(检索、打分、落盘)可在后续迭代中逐个替换,
|
|
14
14
|
* 不改变本契约。
|
|
15
15
|
*/
|
|
16
|
-
import { extractUserMessageText } from './turn-envelope.js';
|
|
16
|
+
import { extractUserMessageText, isTurnStartContent } from './turn-envelope.js';
|
|
17
17
|
/**
|
|
18
18
|
* 默认层顺序(数字越小越靠 system prompt 前部)
|
|
19
19
|
*
|
|
@@ -124,6 +124,78 @@ export function isTurnAnchor(msg) {
|
|
|
124
124
|
return false;
|
|
125
125
|
return true;
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* turn 边界锚点判定(边界类消费方共用:isMidTurn / compact / tool-result-aging)。
|
|
129
|
+
*
|
|
130
|
+
* isTurnAnchor 基础上剔除 **agentId 归因** 的 user 消息(appendCommandDiscourse:
|
|
131
|
+
* slash 命令话语、多 agent 共线记录)——它们不是主对话发言,不得推进任何 turn
|
|
132
|
+
* 边界。此前 tool-result-aging 用裸 isTurnAnchor 各自判边界,命令话语会误推进
|
|
133
|
+
* 老化边界(与 isMidTurn/compact 不一致,2026-11-20 收敛到本谓词)。
|
|
134
|
+
*
|
|
135
|
+
* 注意各消费方**边界语义有意不同**,只是共享锚点定义:aging 取 run 起点
|
|
136
|
+
* ({@link currentRunStartAnchorIndex},插话不推进);compact/isMidTurn 仍取
|
|
137
|
+
* 最近锚点(turn 语义——压缩门控本就是 turn 域)。勿把「谓词统一」误读为
|
|
138
|
+
* 「边界统一」(评审 del-5ca70159 P2-3)。
|
|
139
|
+
*
|
|
140
|
+
* @param msg - 消息(结构化入参,接受 Message 及其裁剪形态)
|
|
141
|
+
* @returns true = 可作为 turn 边界锚点
|
|
142
|
+
*/
|
|
143
|
+
export function isTurnBoundaryAnchor(msg) {
|
|
144
|
+
return !msg.agentId && isTurnAnchor(msg);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 当前 run 起点锚点下标(tool-result-aging 的保护边界)。
|
|
148
|
+
*
|
|
149
|
+
* 「当前 run 永不老化」按 **run 起点** 计(2026-11-20 拍板):同一 run 的
|
|
150
|
+
* 插话 / 接续注入(v0.95 起同 run 多 turn)不推进老化边界,任务中途的工具
|
|
151
|
+
* 工作数据不被降级。锚点携带 `metadata.runId`(runner 在 bakeTurnStart 打标):
|
|
152
|
+
* - 最后锚点无 runId(升级前历史)→ 回落 turn 语义(= 最后锚点,旧行为);
|
|
153
|
+
* - 回溯遇**无 runId 或不同 runId** 的锚点即停(无归因锚点作 run 分界)。
|
|
154
|
+
* 「即停」而非「跳过」是 write-once 的前提:跳过会让未打标锚点夹在同 run
|
|
155
|
+
* 打标锚点之间时把边界**拉回**(已降级条目回原文、批量段翻转,F1 事故形态;
|
|
156
|
+
* 评审 del-5ca70159 P1-1 反例)。即停保证边界随历史增长单调前进,
|
|
157
|
+
* 最坏只是多保护一段旧数据,永不回退。
|
|
158
|
+
*
|
|
159
|
+
* @param messages - 完整历史消息(按时间序)
|
|
160
|
+
* @returns 当前 run 起点锚点下标;无锚点时 -1
|
|
161
|
+
*/
|
|
162
|
+
export function currentRunStartAnchorIndex(messages) {
|
|
163
|
+
let last = -1;
|
|
164
|
+
for (let i = 0; i < messages.length; i++) {
|
|
165
|
+
if (isTurnBoundaryAnchor(messages[i]))
|
|
166
|
+
last = i;
|
|
167
|
+
}
|
|
168
|
+
if (last < 0)
|
|
169
|
+
return -1;
|
|
170
|
+
const runId = messages[last].metadata?.runId;
|
|
171
|
+
if (typeof runId !== 'string' || runId === '')
|
|
172
|
+
return last;
|
|
173
|
+
let first = last;
|
|
174
|
+
for (let i = last - 1; i >= 0; i--) {
|
|
175
|
+
const m = messages[i];
|
|
176
|
+
if (!isTurnBoundaryAnchor(m))
|
|
177
|
+
continue;
|
|
178
|
+
if (m.metadata?.runId !== runId)
|
|
179
|
+
break; // 无归因或异 run:作 run 分界(单调性前提)
|
|
180
|
+
first = i;
|
|
181
|
+
}
|
|
182
|
+
return first;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 中止标记锚点 = 某 turn 的用户输入:开轮信封(含 wake 等机器输入),或定形前的
|
|
186
|
+
* 裸用户输入。abort / edit-resend 的截断锚点判定(view 与写路径同口径)。
|
|
187
|
+
*
|
|
188
|
+
* 历史:本谓词曾在 run-host 与 gateway 各存一份手抄(run-host 迁移时声称单一来源,
|
|
189
|
+
* gateway 副本未删)——2026-11-20 合并到本文件,turn 边界类谓词一处收口。
|
|
190
|
+
*
|
|
191
|
+
* @param msg - 待判定消息(abort 标记指向的历史条目)
|
|
192
|
+
* @returns true = 可作为中止 turn 的截断锚点
|
|
193
|
+
*/
|
|
194
|
+
export function isTurnInput(msg) {
|
|
195
|
+
return (!!msg &&
|
|
196
|
+
msg.role === 'user' &&
|
|
197
|
+
(isTurnStartContent(msg.content) || isTurnAnchor(msg)));
|
|
198
|
+
}
|
|
127
199
|
/**
|
|
128
200
|
* 人话判定(人类文本类消费方:title / grounding.latestUserText / backfill userTurns)。
|
|
129
201
|
*
|
|
@@ -112,10 +112,13 @@ export declare class MemoryLayer extends BaseLayer {
|
|
|
112
112
|
export declare class CognitionLayer extends BaseLayer {
|
|
113
113
|
private readonly store;
|
|
114
114
|
private readonly depth;
|
|
115
|
+
private readonly semanticSeedCount;
|
|
115
116
|
constructor(options: {
|
|
116
117
|
store: ConceptGraphStore;
|
|
117
118
|
depth?: number;
|
|
118
119
|
order?: number;
|
|
120
|
+
/** 语义种子上限(缺省 4;0 关闭语义种子) */
|
|
121
|
+
semanticSeedCount?: number;
|
|
119
122
|
});
|
|
120
123
|
assemble(ctx: LayerAssembleContext): Promise<LayerContent | null>;
|
|
121
124
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 各层质量打磨后续替换 assemble 实现即可,契约不变。
|
|
7
7
|
*/
|
|
8
8
|
import { LAYER_DEFAULT_SHARE, LAYER_ORDER, LAYER_PRIORITY, } from './layer-types.js';
|
|
9
|
+
import { deriveQuerySeeds, normName } from '../memory/cognition-seeds.js';
|
|
9
10
|
import { formatWisdomBody } from '../memory/wisdom-formation.js';
|
|
10
11
|
import { formatMemoryTimeSuffix } from '../memory/time-format.js';
|
|
11
12
|
// ── 基类 ──
|
|
@@ -290,20 +291,26 @@ export class MemoryLayer extends BaseLayer {
|
|
|
290
291
|
export class CognitionLayer extends BaseLayer {
|
|
291
292
|
store;
|
|
292
293
|
depth;
|
|
294
|
+
semanticSeedCount;
|
|
293
295
|
constructor(options) {
|
|
294
296
|
super('cognition', { order: options.order, placement: 'snapshot' });
|
|
295
297
|
this.store = options.store;
|
|
296
298
|
this.depth = options.depth ?? 2;
|
|
299
|
+
this.semanticSeedCount = options.semanticSeedCount ?? 4;
|
|
297
300
|
}
|
|
298
301
|
async assemble(ctx) {
|
|
299
302
|
if (!ctx.query?.trim())
|
|
300
303
|
return null;
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
.
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
const seeds = deriveQuerySeeds(ctx.query);
|
|
305
|
+
// 语义种子:向量近邻概念名补充(store 无向量能力/嵌入失败时为空 = 降级纯词面)
|
|
306
|
+
if (this.semanticSeedCount > 0 && this.store.supportsSemanticSeeds) {
|
|
307
|
+
const semantic = await this.store.semanticSeeds(ctx.query, this.semanticSeedCount);
|
|
308
|
+
for (const name of semantic) {
|
|
309
|
+
const key = normName(name);
|
|
310
|
+
if (key && !seeds.some((s) => normName(s) === key))
|
|
311
|
+
seeds.push(name);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
307
314
|
const graph = await this.store.spreadingActivate(seeds, {
|
|
308
315
|
depth: this.depth,
|
|
309
316
|
limit: 40,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 缓存前缀指纹(可观测护栏)
|
|
3
|
+
*
|
|
4
|
+
* 事故背景(2026-11-12):摘要请求的前缀与主请求"看起来同形",实际整包 tools 缺失,
|
|
5
|
+
* provider 只回报 `inputCachedTokens: 0`——从读数完全看不出**是谁变了**,只能靠人工
|
|
6
|
+
* 逐字节比对 wire dump 才定位。本模块把"前缀是否同形"变成可判定、可打印的事实。
|
|
7
|
+
*
|
|
8
|
+
* 指纹刻意只覆盖**前缀**(tools → system → messages 的保护段),不含尾部指令:
|
|
9
|
+
* 摘要请求本来就要在尾部追加一条指令,那一段不可能也不应该相同。
|
|
10
|
+
*
|
|
11
|
+
* @module harness/context/prefix-fingerprint
|
|
12
|
+
*/
|
|
13
|
+
import type { RequestView } from '@octopi-agent/core/loop/types.js';
|
|
14
|
+
/**
|
|
15
|
+
* 前缀指纹:三项独立哈希 + 前缀消息条数。
|
|
16
|
+
*
|
|
17
|
+
* 三项分开而不用一个大哈希——差异定位需要知道**是 tools 还是 system 还是 messages 变了**。
|
|
18
|
+
*/
|
|
19
|
+
export interface PrefixFingerprint {
|
|
20
|
+
/** 工具面哈希(provider 格式 JSON 的 sha1 前 16 位) */
|
|
21
|
+
toolsHash: string;
|
|
22
|
+
/** 托管 system 文本哈希(messages 中第一条 system) */
|
|
23
|
+
systemHash: string;
|
|
24
|
+
/** 前缀消息(不含尾部指令)整体哈希 */
|
|
25
|
+
prefixHash: string;
|
|
26
|
+
/** 参与前缀的消息条数 */
|
|
27
|
+
prefixCount: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 计算请求视图的前缀指纹
|
|
31
|
+
*
|
|
32
|
+
* @param view - 请求视图
|
|
33
|
+
* @param input.tailLength - 尾部追加的消息条数(摘要指令);从指纹范围中剔除
|
|
34
|
+
* @returns 前缀指纹
|
|
35
|
+
*/
|
|
36
|
+
export declare function fingerprintRequestView(view: RequestView, input?: {
|
|
37
|
+
tailLength?: number;
|
|
38
|
+
}): PrefixFingerprint;
|
|
39
|
+
/**
|
|
40
|
+
* 比对两个前缀指纹,返回**具体是哪一项不同**(同形时返回空数组)。
|
|
41
|
+
*
|
|
42
|
+
* @param a - 会话请求的前缀指纹
|
|
43
|
+
* @param b - 摘要请求的前缀指纹
|
|
44
|
+
* @returns 差异项名称列表(空 = 前缀同形,缓存可命中)
|
|
45
|
+
*/
|
|
46
|
+
export declare function diffPrefixFingerprint(a: PrefixFingerprint, b: PrefixFingerprint): Array<'tools' | 'system' | 'messages'>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 缓存前缀指纹(可观测护栏)
|
|
3
|
+
*
|
|
4
|
+
* 事故背景(2026-11-12):摘要请求的前缀与主请求"看起来同形",实际整包 tools 缺失,
|
|
5
|
+
* provider 只回报 `inputCachedTokens: 0`——从读数完全看不出**是谁变了**,只能靠人工
|
|
6
|
+
* 逐字节比对 wire dump 才定位。本模块把"前缀是否同形"变成可判定、可打印的事实。
|
|
7
|
+
*
|
|
8
|
+
* 指纹刻意只覆盖**前缀**(tools → system → messages 的保护段),不含尾部指令:
|
|
9
|
+
* 摘要请求本来就要在尾部追加一条指令,那一段不可能也不应该相同。
|
|
10
|
+
*
|
|
11
|
+
* @module harness/context/prefix-fingerprint
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
function sha1(text) {
|
|
15
|
+
return createHash('sha1').update(text, 'utf8').digest('hex').slice(0, 16);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 计算请求视图的前缀指纹
|
|
19
|
+
*
|
|
20
|
+
* @param view - 请求视图
|
|
21
|
+
* @param input.tailLength - 尾部追加的消息条数(摘要指令);从指纹范围中剔除
|
|
22
|
+
* @returns 前缀指纹
|
|
23
|
+
*/
|
|
24
|
+
export function fingerprintRequestView(view, input) {
|
|
25
|
+
const tailLength = Math.max(0, input?.tailLength ?? 0);
|
|
26
|
+
const prefix = tailLength > 0 ? view.messages.slice(0, -tailLength) : view.messages;
|
|
27
|
+
const system = prefix.find((m) => m.role === 'system');
|
|
28
|
+
return {
|
|
29
|
+
toolsHash: sha1(JSON.stringify(view.tools)),
|
|
30
|
+
systemHash: sha1(typeof system?.content === 'string' ? system.content : JSON.stringify(system?.content ?? '')),
|
|
31
|
+
prefixHash: sha1(JSON.stringify(prefix)),
|
|
32
|
+
prefixCount: prefix.length,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 比对两个前缀指纹,返回**具体是哪一项不同**(同形时返回空数组)。
|
|
37
|
+
*
|
|
38
|
+
* @param a - 会话请求的前缀指纹
|
|
39
|
+
* @param b - 摘要请求的前缀指纹
|
|
40
|
+
* @returns 差异项名称列表(空 = 前缀同形,缓存可命中)
|
|
41
|
+
*/
|
|
42
|
+
export function diffPrefixFingerprint(a, b) {
|
|
43
|
+
const out = [];
|
|
44
|
+
if (a.toolsHash !== b.toolsHash)
|
|
45
|
+
out.push('tools');
|
|
46
|
+
if (a.systemHash !== b.systemHash)
|
|
47
|
+
out.push('system');
|
|
48
|
+
// tools/system 不同必然导致整体不同,避免重复报告 messages
|
|
49
|
+
if (out.length === 0 && a.prefixHash !== b.prefixHash)
|
|
50
|
+
out.push('messages');
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
@@ -16,6 +16,11 @@ export function createProviderSummarize(provider, options) {
|
|
|
16
16
|
const response = await provider.chat({
|
|
17
17
|
messages,
|
|
18
18
|
model: options?.model,
|
|
19
|
+
// 摘要请求带会话同形工具面:前缀缓存是 tools → system → messages,缺 tools 会整段冷 prefill。
|
|
20
|
+
// 不带 toolChoice(2026-11-13 实测):'none' 在部分 provider(DeepSeek 系)会让服务端
|
|
21
|
+
// 把 tools 从 prompt 渲染中剔除,反而落到另一个缓存空间、前缀零重叠。「禁止调用」由
|
|
22
|
+
// 摘要指令 + summarize_tool_call_emitted fail-loud 守卫承担,不依赖 provider 的软提示。
|
|
23
|
+
...(opts?.tools && opts.tools.length > 0 ? { tools: opts.tools } : {}),
|
|
19
24
|
// 未显式配置即不发送:由模型配置(ModelInfo.temperature)或服务端默认决定
|
|
20
25
|
temperature: options?.temperature,
|
|
21
26
|
// P3:run 中止 / 摘要超时都靠这个 signal 取消在飞请求(provider 侧 fetch 已接 signal)
|
|
@@ -31,6 +36,19 @@ export function createProviderSummarize(provider, options) {
|
|
|
31
36
|
if (response.usage && response.usage.outputTokens > 0) {
|
|
32
37
|
opts?.onUsage?.({ outputTokens: response.usage.outputTokens });
|
|
33
38
|
}
|
|
39
|
+
// 撞 max_tokens 的摘要 = 半截交接书(2026-11-12 评审 MAJ-2)。压缩常在会话最满时
|
|
40
|
+
// 触发,窗口钳制会把 max_tokens 压到刚好放得下,撞顶概率不低;把它当成功会让
|
|
41
|
+
// "## Open items" 段凭空消失且无人知晓——本次带工具面后输出上限进一步被挤压,必须
|
|
42
|
+
// fail loud 交 onSummarizeFail 显式降级,禁止静默半截(capabilities/compact 的既有红线)。
|
|
43
|
+
if (response.finishReason === 'length') {
|
|
44
|
+
throw new Error('summarize_output_truncated: provider stopped at max_tokens');
|
|
45
|
+
}
|
|
46
|
+
// 工具面为重放缓存前缀而完整发送,摘要轮本不该产生 tool_call(指令已明确要求纯文本)。
|
|
47
|
+
// 不带 toolChoice 约束后,本守卫是唯一硬防线:若 provider 仍冒 tool_call,正文就不是
|
|
48
|
+
// 摘要——宁可失败,交 onSummarizeFail 显式降级(禁止静默半截/错型产物)。
|
|
49
|
+
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
50
|
+
throw new Error('summarize_tool_call_emitted: summary turn produced a tool call');
|
|
51
|
+
}
|
|
34
52
|
return response.content;
|
|
35
53
|
};
|
|
36
54
|
}
|
|
@@ -88,6 +88,8 @@ export declare function createDefaultSystemPromptAssembler(options?: {
|
|
|
88
88
|
knowledgeGroupByScope?: boolean;
|
|
89
89
|
knowledgeShowProgress?: 'off' | 'bucket' | 'exact';
|
|
90
90
|
cognitionDepth?: number;
|
|
91
|
+
/** 语义种子上限(缺省 4;0 关闭语义种子) */
|
|
92
|
+
cognitionSemanticSeedCount?: number;
|
|
91
93
|
/** 全局宪法;提供则 preamble 固定最前 */
|
|
92
94
|
constitution?: ConstitutionConfig | string | null;
|
|
93
95
|
/** 直接注入宪法正文(覆盖 constitution 配置) */
|
|
@@ -7,6 +7,7 @@ import { DefaultContextAssembler } from './assembler.js';
|
|
|
7
7
|
import { CognitionLayer, KnowledgeLayer, MemoryLayer, PersonaLayer, RuntimeLayer, SkillLayer, WisdomLayer, } from './layers.js';
|
|
8
8
|
import { extractLayerQuery } from './layer-types.js';
|
|
9
9
|
import { loadConstitution } from './constitution/load-constitution.js';
|
|
10
|
+
import { ELISION_MARKER_SYSTEM_NOTE } from '@octopi-agent/core/elision.js';
|
|
10
11
|
import { TOOL_PURPOSE_SYSTEM_NOTE } from '../agent/tool-purpose.js';
|
|
11
12
|
const DEFAULT_SYSTEM_BUDGET_RATIO = 0.22;
|
|
12
13
|
/**
|
|
@@ -26,12 +27,13 @@ export const TURN_SEMANTICS_MD = `## Turns (authoritative)
|
|
|
26
27
|
- If a tool needs old ephemeral detail, re-read the source (session log / files);
|
|
27
28
|
do not assume old picks are still true.`;
|
|
28
29
|
/**
|
|
29
|
-
* 缓存稳定固定块(永远拼进 system):Turn 信封阅读规则置首,purpose
|
|
30
|
+
* 缓存稳定固定块(永远拼进 system):Turn 信封阅读规则置首,purpose 全局说明随后,
|
|
31
|
+
* 降级标记禁令殿后(工具注记区)。
|
|
30
32
|
* purpose 详版+示例在此只写一次(方案 S)——schema 侧只留 TOOL_PURPOSE_PARAM 极短 stub。
|
|
31
33
|
*/
|
|
32
34
|
function withFixedProtocolBlocks(systemPrompt) {
|
|
33
35
|
const body = systemPrompt.trim();
|
|
34
|
-
const head = `${TURN_SEMANTICS_MD}\n\n---\n\n${TOOL_PURPOSE_SYSTEM_NOTE}`;
|
|
36
|
+
const head = `${TURN_SEMANTICS_MD}\n\n---\n\n${TOOL_PURPOSE_SYSTEM_NOTE}\n\n---\n\n${ELISION_MARKER_SYSTEM_NOTE}`;
|
|
35
37
|
return body ? `${head}\n\n---\n\n${body}` : head;
|
|
36
38
|
}
|
|
37
39
|
export function createDefaultSystemPromptAssembler(options) {
|
|
@@ -135,6 +137,7 @@ export function createDefaultSystemPromptAssembler(options) {
|
|
|
135
137
|
layers.push(new CognitionLayer({
|
|
136
138
|
store: cognitionStore,
|
|
137
139
|
depth: options?.cognitionDepth,
|
|
140
|
+
semanticSeedCount: options?.cognitionSemanticSeedCount,
|
|
138
141
|
}));
|
|
139
142
|
}
|
|
140
143
|
if (options?.memoryStore) {
|
|
@@ -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,26 +16,30 @@
|
|
|
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 type { Message } from '@octopi-agent/core/types.js';
|
|
26
|
+
import type { Message, ToolResultAger } from '@octopi-agent/core/types.js';
|
|
26
27
|
/** 老化配置(配置面输入;缺省见 {@link resolveToolResultAgingOptions}) */
|
|
27
28
|
export interface ToolResultAgingConfig {
|
|
28
29
|
/** 总开关(默认 true) */
|
|
29
30
|
enabled?: boolean;
|
|
30
|
-
/**
|
|
31
|
+
/** 跨 run 原文保留条数(默认 20) */
|
|
31
32
|
rawWindow?: number;
|
|
32
33
|
/**
|
|
33
|
-
* 批量冻结步长:老化边界只成批推进(默认
|
|
34
|
+
* 批量冻结步长:老化边界只成批推进(默认 60;最小 1)。
|
|
34
35
|
* ⚠️ 1 = 逐候选即降级(等同渐进老化、每轮烧前缀缓存,仅调试用);
|
|
35
36
|
* 生产取值应 ≥ 每轮工具结果数,使冻结事件隔数轮一次。
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* 默认值 40 → 60(2026-11-13):老化定位从「成本优化」改为「污染控制」后
|
|
38
|
+
* (见 arch/history-aging-economics.md),优化目标是**减少冻结事件次数**
|
|
39
|
+
* 而非尽早缩小视图——每次冻结都是常数级全价重算。
|
|
40
|
+
* 实测单轮工具结果数峰值 34、均值 15:批 40 仍会近乎每轮触发,
|
|
41
|
+
* 批 60 把冻结事件间隔拉到约 4 轮一次;配合 rawWindow 20 降低近窗的
|
|
42
|
+
* 常驻体积,同时让更多结果在变旧后一次成批让位。
|
|
38
43
|
*/
|
|
39
44
|
freezeBatch?: number;
|
|
40
45
|
/** 指针目标字符数(默认 400;是目标非硬顶——error/固定骨架可超出) */
|
|
@@ -48,7 +53,7 @@ export interface ToolResultAgingConfig {
|
|
|
48
53
|
/**
|
|
49
54
|
* 参数摘要的目标字符数(默认 320;**只约束内容值**,键名与定位字段不计入)
|
|
50
55
|
*
|
|
51
|
-
* 定位字段(path/file/glob/pattern/cwd)与 command
|
|
56
|
+
* 定位字段(path/file/glob/pattern/cwd)与 command 是「这条调用碰了哪里」的唯一锚点,
|
|
52
57
|
* 恒定保留;预算过小只会让内容值更快退化,不会丢锚点。
|
|
53
58
|
*/
|
|
54
59
|
maxAgedArgChars?: number;
|
|
@@ -62,12 +67,53 @@ export interface ToolResultAgingOptions {
|
|
|
62
67
|
ageToolArgs: boolean;
|
|
63
68
|
maxAgedArgChars: number;
|
|
64
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* 从工具面收集「工具名 → 老化函数」表
|
|
72
|
+
*
|
|
73
|
+
* 供装配层把 `AgentTool.ageResult` 传给老化计划。只收有声明的工具——
|
|
74
|
+
* 未声明者不进表 = 走默认规则(长度判据 + 机械指针)。
|
|
75
|
+
*
|
|
76
|
+
* @param tools - 本 run 实际发送的工具面(`RunScope.tools` / `AgentContext.tools`)
|
|
77
|
+
* @returns 名字→函数表;无任何声明时返回 undefined(省去空表分配)
|
|
78
|
+
*/
|
|
79
|
+
export declare function collectToolAgers(tools: ReadonlyArray<{
|
|
80
|
+
name: string;
|
|
81
|
+
ageResult?: ToolResultAger;
|
|
82
|
+
}> | undefined): ReadonlyMap<string, ToolResultAger> | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* 收集「参数可老化」的工具名(`AgentTool.ageArgs` → 集合)
|
|
85
|
+
*
|
|
86
|
+
* 与 {@link collectToolAgers} 分开:两者语义独立(有结果策略不代表参数可老化,
|
|
87
|
+
* 反之亦然),混成一张表会让「只声明了 ageArgs」的工具误走结果默认规则。
|
|
88
|
+
*
|
|
89
|
+
* @param tools - 本次 run 的工具面
|
|
90
|
+
* @returns 工具名集合;空表返回 undefined(装配侧据此跳过)
|
|
91
|
+
*/
|
|
92
|
+
export declare function collectToolArgAgers(tools: ReadonlyArray<{
|
|
93
|
+
name: string;
|
|
94
|
+
ageArgs?: boolean;
|
|
95
|
+
}> | undefined): ReadonlySet<string> | undefined;
|
|
65
96
|
/** 老化计划:一次装配内的降级判定(基于完整历史的纯函数结果,跨轮稳定) */
|
|
66
97
|
export interface ToolResultAgingPlan {
|
|
67
98
|
/** 要降级为指针的 toolCallId 集合 */
|
|
68
99
|
agedIds: ReadonlySet<string>;
|
|
69
100
|
/** toolCallId → 工具调用参数(指针的「参数要点」来源;取自完整历史,裁剪视图中的孤儿也有参数) */
|
|
70
101
|
argsById: ReadonlyMap<string, unknown>;
|
|
102
|
+
/**
|
|
103
|
+
* toolCallId → 工具自带老化函数(`AgentTool.ageResult`;未声明者不在表内 → 走默认规则)。
|
|
104
|
+
*
|
|
105
|
+
* 随计划传给 `applyAgingToMessages`,使该函数签名保持不变(5 个调用点零改动)。
|
|
106
|
+
*/
|
|
107
|
+
agersByCallId: ReadonlyMap<string, ToolResultAger>;
|
|
108
|
+
/**
|
|
109
|
+
* 启用了**参数**老化的 toolCallId 子集(`AgentTool.ageArgs === true`)。
|
|
110
|
+
*
|
|
111
|
+
* 参数老化不再全局默认开启(2026-11-13 拍板):会话视图里历史 `tool_calls`
|
|
112
|
+
* 上的降级标记会被模型模仿回抄(OP-TOOL-1 定案「主因=模型从老化视图模仿降级
|
|
113
|
+
* 标记形态」),因此只对「参数本身会变成污染源」的工具开启——当前仅
|
|
114
|
+
* `file_write`(整份文件正文,占空间且随文件后续改动变成过期副本)。
|
|
115
|
+
*/
|
|
116
|
+
argAgedIds: ReadonlySet<string>;
|
|
71
117
|
}
|
|
72
118
|
/**
|
|
73
119
|
* 解析老化配置(缺省 = 拍板参数起点:40 条原文 / 批 20 / 指针 400 字符)
|
|
@@ -79,8 +125,8 @@ export declare function resolveToolResultAgingOptions(input?: ToolResultAgingCon
|
|
|
79
125
|
/**
|
|
80
126
|
* 计算老化计划:批量冻结边界 + 工具调用参数索引
|
|
81
127
|
*
|
|
82
|
-
*
|
|
83
|
-
* `
|
|
128
|
+
* 边界语义:跨 run 工具结果(位于当前 run 起点之前)中,最旧的
|
|
129
|
+
* `crossRun - rawWindow` 条为候选;候选前 `freezeBatch` 整批部分「过冻结线」。
|
|
84
130
|
* 过线条目再过三道守卫才降级:error 永不降级;正文 ≤ 指针目标不降级;
|
|
85
131
|
* 实际指针不比原文短不降级(不膨胀)。历史只增不减时边界单调推进、
|
|
86
132
|
* 已降级条目永不回原文——满足 write-once(须以完整历史为输入,见模块头注)。
|
|
@@ -88,13 +134,50 @@ export declare function resolveToolResultAgingOptions(input?: ToolResultAgingCon
|
|
|
88
134
|
* @param messages - **完整**历史消息(按时间序;勿传裁剪后的装配视图)
|
|
89
135
|
* @param opts - 老化配置(已解析)
|
|
90
136
|
* @param override - overflow 收敛阶梯第 0 轮(2026-11-08):ignoreTurnBoundary=true 时
|
|
91
|
-
* 豁免
|
|
137
|
+
* 豁免 run 起点限定(不限 crossRun、rawWindow 归 0)——守门兜底语境下「发得出去」
|
|
92
138
|
* 优先于「保护 turn 内工作数据/缓存前缀」;阈值(maxPointerChars/freezeBatch)不动
|
|
93
139
|
* @returns 老化计划(enabled=false 或无候选时 agedIds 为空)
|
|
94
140
|
*/
|
|
95
141
|
export declare function computeToolResultAgingPlan(messages: Message[], opts: ToolResultAgingOptions, override?: {
|
|
96
142
|
ignoreTurnBoundary?: boolean;
|
|
143
|
+
/** 工具名字 → 自带老化函数(`AgentTool.ageResult`);未声明的工具走默认规则 */
|
|
144
|
+
toolAgers?: ReadonlyMap<string, ToolResultAger>;
|
|
145
|
+
/** 参数可老化的工具名(`AgentTool.ageArgs`);缺省 = 参数一律原样保留 */
|
|
146
|
+
toolArgAgers?: ReadonlySet<string>;
|
|
97
147
|
}): ToolResultAgingPlan;
|
|
148
|
+
/**
|
|
149
|
+
* 单条工具结果 → 老化后的文本(**唯一裁决点**)
|
|
150
|
+
*
|
|
151
|
+
* 顺序:工具自带 ager → 默认机械指针。两处视图构建(`applyAgingToMessages`
|
|
152
|
+
* 与 `buildLlmMessages`)都必须走这里:历史上它们各写一份内联逻辑,
|
|
153
|
+
* 结果 per-tool ager 只在其中一份生效(2026-11-13 实测发现——wire dump 里
|
|
154
|
+
* file_edit 仍是默认指针,而单测覆盖的却是另一份实现)。
|
|
155
|
+
*
|
|
156
|
+
* @param tr - 工具结果条目
|
|
157
|
+
* @param args - 对应调用参数
|
|
158
|
+
* @param plan - 老化计划(提供 per-tool ager 与参数表)
|
|
159
|
+
* @param opts - 老化配置
|
|
160
|
+
* @returns 供模型读取的文本
|
|
161
|
+
*/
|
|
162
|
+
export declare function ageOneToolResult(tr: {
|
|
163
|
+
toolCallId: string;
|
|
164
|
+
name?: string;
|
|
165
|
+
error?: string;
|
|
166
|
+
result?: unknown;
|
|
167
|
+
}, args: unknown, plan: Pick<ToolResultAgingPlan, 'agersByCallId'>, opts: ToolResultAgingOptions): string;
|
|
168
|
+
/**
|
|
169
|
+
* 单条工具调用 → 是否应降级其参数(**唯一裁决点**)
|
|
170
|
+
*
|
|
171
|
+
* 只看 `plan.argAgedIds`(冻结区 ∩ 工具 opt-in)。不要再回退到 `agedIds`:
|
|
172
|
+
* 那会让「结果恰好够大」的工具绕过 opt-in 白名单,正是 file_edit 参数在
|
|
173
|
+
* 2026-11-13 仍被全局降级的原因。
|
|
174
|
+
*
|
|
175
|
+
* @param toolCallId - 调用 id
|
|
176
|
+
* @param plan - 老化计划
|
|
177
|
+
* @param opts - 老化配置(含总开关 `ageToolArgs`)
|
|
178
|
+
* @returns 是否降级
|
|
179
|
+
*/
|
|
180
|
+
export declare function shouldAgeArgs(toolCallId: string, plan: Pick<ToolResultAgingPlan, 'argAgedIds'>, opts: ToolResultAgingOptions): boolean;
|
|
98
181
|
/**
|
|
99
182
|
* 把老化计划物化为消息视图副本(新建对象,不改原消息)
|
|
100
183
|
*
|
|
@@ -111,12 +194,17 @@ export declare function applyAgingToMessages(messages: Message[], plan: ToolResu
|
|
|
111
194
|
/**
|
|
112
195
|
* 生成结构化摘要指针(机械、零 LLM、确定性)
|
|
113
196
|
*
|
|
114
|
-
* 布局:工具名 +
|
|
115
|
-
*
|
|
197
|
+
* 布局:工具名 + 结果长度 + 结果轮廓 + 短提示。
|
|
198
|
+
*
|
|
199
|
+
* 不含参数轮廓(2026-11-13 实测):指针里的 args 是**机械截断**产物(130 条指针
|
|
200
|
+
* 全部恰好 98 字符 = 预算 80 + 截断标记),从不承载有效信息;对应的 tool_use 就在
|
|
201
|
+
* 前一条 assistant 消息里,`ageToolArgs` 还额外全保 path/command/id。留着是纯重复。
|
|
202
|
+
* 连同旧尾句(81 字符/条)一并去掉——它把「不要重跑」重复 130 遍,反而在提示重跑。
|
|
203
|
+
*
|
|
116
204
|
* error 分支为防御性保真(计划永不选中 error 结果)。
|
|
117
205
|
*
|
|
118
206
|
* @param tr - 工具结果(error / result 至少其一)
|
|
119
|
-
* @param args -
|
|
207
|
+
* @param args - 对应工具调用参数(保留入参供策略复用;默认指针不再消费)
|
|
120
208
|
* @param opts - 老化配置(已解析)
|
|
121
209
|
* @returns 指针文本(write-once:同输入恒同字节)
|
|
122
210
|
*/
|
|
@@ -131,7 +219,7 @@ export declare function agedToolResultPointer(tr: {
|
|
|
131
219
|
*
|
|
132
220
|
* 规则(机械、确定性、无 LLM):
|
|
133
221
|
* 1. **键名全保**——LLM 需要知道调用了哪个路径/命令才能在必要时重跑;
|
|
134
|
-
* 2. 序列化长度超过 {@link ARG_VALUE_KEEP_CHARS}
|
|
222
|
+
* 2. 序列化长度超过 {@link ARG_VALUE_KEEP_CHARS} 的值替换为对象形标记 `{"$octopi_elided": {"chars": N}}`(锚点类——定位字段与命令——全保不降级);
|
|
135
223
|
* 3. 若仍是超预算,按「值从大到小、同大小按键名」顺序继续替换,保证确定性;
|
|
136
224
|
* 4. 兜底:键名太多装不下时退化为整体轮廓截断。
|
|
137
225
|
*
|