@octopi-agent/engine 0.97.15 → 0.102.10
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/config-schema/agent.d.ts +37 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +61 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +10 -1
- package/dist/config-schema/governance.js +38 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +34 -2
- package/dist/harness/agent/builder.js +189 -58
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.d.ts +66 -0
- package/dist/harness/agent/config-integrity.js +108 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +31 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +21 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +12 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -9
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +4 -7
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +16 -19
- package/dist/harness/context/layers.js +42 -14
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +3 -3
- package/dist/harness/context/summarize.js +11 -4
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +3 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
- package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +7 -3
- package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +17 -24
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- package/dist/harness/governance/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +86 -12
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +47 -7
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +31 -1
- package/dist/harness/memory/wisdom-formation.js +130 -33
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +49 -2
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +41 -4
- package/dist/harness/run/runner.d.ts +71 -31
- package/dist/harness/run/runner.js +368 -106
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +13 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +39 -23
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +16 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Harness Context 模块导出
|
|
3
3
|
*/
|
|
4
|
-
export type { ContextEngine, ContextEngineInfo, AssembleParams, AssembleResult, IngestParams,
|
|
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';
|
|
5
5
|
export { DefaultContextEngine } from './default-context-engine.js';
|
|
6
6
|
export type { DefaultContextEngineConfig } from './default-context-engine.js';
|
|
7
7
|
export { formatTurnId, formatTurnStartContent, formatTurnEndContent, formatTurnContextXml, extractUserMessageText, stripTurnContextXml, isTurnStartContent, isTurnEndContent, parseTurnIdFromContent, parseTurnEnvelope, joinSlotXml, unwrapUserText, messageText, escapeUserMessageText, } from './turn-envelope.js';
|
|
8
8
|
export type { TurnEnvelopeSlot, TurnEnvelopeParts } from './turn-envelope.js';
|
|
9
9
|
export { HeuristicTokenEstimator, estimateTextTokens, estimateLLMMessages } from './token-estimator.js';
|
|
10
|
-
export { CHARS_PER_TOKEN, TOOL_RESULT_CHARS_PER_TOKEN, JSON_CHARS_PER_TOKEN, MESSAGE_OVERHEAD_TOKENS, SAFETY_MARGIN, IMAGE_TOKEN_ESTIMATE, AUDIO_TOKEN_ESTIMATE, VIDEO_TOKEN_ESTIMATE,
|
|
10
|
+
export { CHARS_PER_TOKEN, TOOL_RESULT_CHARS_PER_TOKEN, JSON_CHARS_PER_TOKEN, MESSAGE_OVERHEAD_TOKENS, SAFETY_MARGIN, IMAGE_TOKEN_ESTIMATE, AUDIO_TOKEN_ESTIMATE, VIDEO_TOKEN_ESTIMATE, } from './token-constants.js';
|
|
11
11
|
export { LAYER_ORDER, LAYER_PRIORITY, LAYER_DEFAULT_SHARE, extractLayerQuery, isThinLayerQuery, hasLayerText, } from './layer-types.js';
|
|
12
12
|
export type { ContextLayerId, LayerAssembleContext, LayerContent, ContextLayer, LayerManifestEntry, AssembleManifest, SystemAssembleResult, ContextAssembler, ContextAssembleParams, ExtractLayerQueryOptions, } from './layer-types.js';
|
|
13
13
|
export { DefaultContextAssembler, truncateTextToTokens } from './assembler.js';
|
|
@@ -5,7 +5,7 @@ export { DefaultContextEngine } from './default-context-engine.js';
|
|
|
5
5
|
export { formatTurnId, formatTurnStartContent, formatTurnEndContent, formatTurnContextXml, extractUserMessageText, stripTurnContextXml, isTurnStartContent, isTurnEndContent, parseTurnIdFromContent, parseTurnEnvelope, joinSlotXml, unwrapUserText, messageText, escapeUserMessageText, } from './turn-envelope.js';
|
|
6
6
|
// ── Token 估算(跨域门面;浏览器侧可直连 token-estimator / token-constants) ──
|
|
7
7
|
export { HeuristicTokenEstimator, estimateTextTokens, estimateLLMMessages } from './token-estimator.js';
|
|
8
|
-
export { CHARS_PER_TOKEN, TOOL_RESULT_CHARS_PER_TOKEN, JSON_CHARS_PER_TOKEN, MESSAGE_OVERHEAD_TOKENS, SAFETY_MARGIN, IMAGE_TOKEN_ESTIMATE, AUDIO_TOKEN_ESTIMATE, VIDEO_TOKEN_ESTIMATE,
|
|
8
|
+
export { CHARS_PER_TOKEN, TOOL_RESULT_CHARS_PER_TOKEN, JSON_CHARS_PER_TOKEN, MESSAGE_OVERHEAD_TOKENS, SAFETY_MARGIN, IMAGE_TOKEN_ESTIMATE, AUDIO_TOKEN_ESTIMATE, VIDEO_TOKEN_ESTIMATE, } from './token-constants.js';
|
|
9
9
|
// ── 七层内容契约与装配 ──
|
|
10
10
|
export { LAYER_ORDER, LAYER_PRIORITY, LAYER_DEFAULT_SHARE, extractLayerQuery, isThinLayerQuery, hasLayerText, } from './layer-types.js';
|
|
11
11
|
export { DefaultContextAssembler, truncateTextToTokens } from './assembler.js';
|
|
@@ -204,6 +204,21 @@ export interface ContextAssembleParams {
|
|
|
204
204
|
* @returns true 表示机器插槽(快照/grounding/附件/摘要)
|
|
205
205
|
*/
|
|
206
206
|
export declare function isEngineCarrierSource(source: unknown): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* schedule notify 便签判定(turn 锚点与 LLM 视图打标共用单源)。
|
|
209
|
+
*
|
|
210
|
+
* producer 见 gateway `setNotify`:借 user 通道落库的机器留言,不开轮、
|
|
211
|
+
* 不跑模型;LLM 视图必须以 `<schedule_notice>` 信封包裹(convertMessage),
|
|
212
|
+
* 不得冒充人话(宪法 Confusables「Machine content vs human speech」)。
|
|
213
|
+
*
|
|
214
|
+
* @param msg - 消息(结构化入参)
|
|
215
|
+
* @returns true = schedule notify 便签
|
|
216
|
+
*/
|
|
217
|
+
export declare function isScheduleNotice(msg: {
|
|
218
|
+
metadata?: {
|
|
219
|
+
delivery?: unknown;
|
|
220
|
+
};
|
|
221
|
+
}): boolean;
|
|
207
222
|
/**
|
|
208
223
|
* 轮次锚点判定(turn 边界类消费方:isMidTurn / compact / tool-result-aging)。
|
|
209
224
|
*
|
|
@@ -90,6 +90,19 @@ const ENGINE_CARRIER_SOURCES = new Set([
|
|
|
90
90
|
export function isEngineCarrierSource(source) {
|
|
91
91
|
return ENGINE_CARRIER_SOURCES.has(source);
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* schedule notify 便签判定(turn 锚点与 LLM 视图打标共用单源)。
|
|
95
|
+
*
|
|
96
|
+
* producer 见 gateway `setNotify`:借 user 通道落库的机器留言,不开轮、
|
|
97
|
+
* 不跑模型;LLM 视图必须以 `<schedule_notice>` 信封包裹(convertMessage),
|
|
98
|
+
* 不得冒充人话(宪法 Confusables「Machine content vs human speech」)。
|
|
99
|
+
*
|
|
100
|
+
* @param msg - 消息(结构化入参)
|
|
101
|
+
* @returns true = schedule notify 便签
|
|
102
|
+
*/
|
|
103
|
+
export function isScheduleNotice(msg) {
|
|
104
|
+
return msg.metadata?.delivery === 'notify';
|
|
105
|
+
}
|
|
93
106
|
/**
|
|
94
107
|
* 轮次锚点判定(turn 边界类消费方:isMidTurn / compact / tool-result-aging)。
|
|
95
108
|
*
|
|
@@ -107,7 +120,7 @@ export function isTurnAnchor(msg) {
|
|
|
107
120
|
if (isEngineCarrierSource(msg.metadata?.source))
|
|
108
121
|
return false;
|
|
109
122
|
// schedule notify 是机器便签(producer 见 gateway setNotify),不是用户输入
|
|
110
|
-
if (msg
|
|
123
|
+
if (isScheduleNotice(msg))
|
|
111
124
|
return false;
|
|
112
125
|
return true;
|
|
113
126
|
}
|
|
@@ -70,6 +70,17 @@ export declare class RuntimeLayer extends BaseLayer {
|
|
|
70
70
|
});
|
|
71
71
|
assemble(ctx: LayerAssembleContext): Promise<LayerContent | null>;
|
|
72
72
|
}
|
|
73
|
+
/** Plugin Collect is a budgeted Runtime snapshot, never a systemPrompt override. */
|
|
74
|
+
export declare class PluginRuntimeSnapshotLayer extends BaseLayer {
|
|
75
|
+
private readonly contributions;
|
|
76
|
+
constructor(contributions: readonly {
|
|
77
|
+
pluginId: string;
|
|
78
|
+
value: {
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
}[]);
|
|
82
|
+
assemble(ctx: LayerAssembleContext): Promise<LayerContent | null>;
|
|
83
|
+
}
|
|
73
84
|
export declare class KnowledgeLayer extends BaseLayer {
|
|
74
85
|
private readonly getCatalog;
|
|
75
86
|
private readonly maxEntries;
|
|
@@ -116,28 +127,10 @@ export declare class CognitionLayer extends BaseLayer {
|
|
|
116
127
|
export declare class WisdomLayer extends BaseLayer {
|
|
117
128
|
private readonly select;
|
|
118
129
|
private readonly onInjected?;
|
|
119
|
-
private readonly coreMaxItems?;
|
|
120
|
-
private readonly scenarioMaxItems?;
|
|
121
130
|
constructor(options: {
|
|
122
|
-
select: (query: string) => Promise<
|
|
123
|
-
entry: {
|
|
124
|
-
id: string;
|
|
125
|
-
statement: string;
|
|
126
|
-
scenario: {
|
|
127
|
-
problemTypes: string[];
|
|
128
|
-
antiScenarios?: string[];
|
|
129
|
-
};
|
|
130
|
-
effect: {
|
|
131
|
-
posture?: string;
|
|
132
|
-
questions?: string[];
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
bucket: 'core' | 'scenario';
|
|
136
|
-
}>>;
|
|
131
|
+
select: (query: string) => Promise<import('../memory/types.js').WisdomInjectPick[]>;
|
|
137
132
|
/** S1 applied 入账(注入命中) */
|
|
138
133
|
onInjected?: (ids: string[]) => void | Promise<void>;
|
|
139
|
-
coreMaxItems?: number;
|
|
140
|
-
scenarioMaxItems?: number;
|
|
141
134
|
order?: number;
|
|
142
135
|
});
|
|
143
136
|
assemble(ctx: LayerAssembleContext): Promise<LayerContent | null>;
|
|
@@ -155,6 +148,10 @@ export interface CreateDefaultLayersOptions {
|
|
|
155
148
|
wisdomStore?: import('../memory/types.js').WisdomStore;
|
|
156
149
|
wisdomCoreMaxItems?: number;
|
|
157
150
|
wisdomScenarioMaxItems?: number;
|
|
151
|
+
/** trial 轮转试用名额(wisdom.injection.trialMaxItems;缺省 2——保底曝光打破晋升死锁;0 关闭) */
|
|
152
|
+
wisdomTrialMaxItems?: number;
|
|
153
|
+
/** trial 可见性(wisdom.injection.trialVisible;缺省 true——trial 的意义就是被试用) */
|
|
154
|
+
wisdomIncludeTrial?: boolean;
|
|
158
155
|
}
|
|
159
156
|
/**
|
|
160
157
|
* 按可用依赖创建启用层列表
|
|
@@ -114,6 +114,31 @@ export class RuntimeLayer extends BaseLayer {
|
|
|
114
114
|
return this.content(body, { dropped, sources: ['runtime'] });
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
/** Plugin Collect is a budgeted Runtime snapshot, never a systemPrompt override. */
|
|
118
|
+
export class PluginRuntimeSnapshotLayer extends BaseLayer {
|
|
119
|
+
contributions;
|
|
120
|
+
constructor(contributions) {
|
|
121
|
+
super('runtime', { placement: 'snapshot', order: 75 });
|
|
122
|
+
this.contributions = contributions;
|
|
123
|
+
}
|
|
124
|
+
async assemble(ctx) {
|
|
125
|
+
const body = this.contributions
|
|
126
|
+
.map(({ pluginId, value }) => `<plugin-contribution plugin="${escapeXmlAttribute(pluginId)}">\n${escapeXmlText(value.text)}\n</plugin-contribution>`)
|
|
127
|
+
.join('\n\n');
|
|
128
|
+
const { text, dropped } = this.truncateToBudget(body, ctx.tokenBudget);
|
|
129
|
+
return this.content(text, {
|
|
130
|
+
dropped,
|
|
131
|
+
sources: this.contributions.map(({ pluginId }) => `plugin:${pluginId}`),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function escapeXmlAttribute(value) {
|
|
136
|
+
return value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<');
|
|
137
|
+
}
|
|
138
|
+
/** Contribution text is data, not markup: escape it so a plugin cannot forge sibling tags or close the slot. */
|
|
139
|
+
function escapeXmlText(value) {
|
|
140
|
+
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
141
|
+
}
|
|
117
142
|
// ── Knowledge(Tier 0 catalog;内容命中不进 system) ──
|
|
118
143
|
function resolveCatalogList(provider, ctx) {
|
|
119
144
|
if (typeof provider !== 'function')
|
|
@@ -162,8 +187,11 @@ export class KnowledgeLayer extends BaseLayer {
|
|
|
162
187
|
const head = `- ${tags.join(' ')}`;
|
|
163
188
|
const lines = [head];
|
|
164
189
|
const desc = item.description?.trim();
|
|
165
|
-
|
|
166
|
-
|
|
190
|
+
// 强制标注(2026-11-02):LLM 生成的描述会注入 prompt,必须可溯源;
|
|
191
|
+
// heuristic 文本自带 "derived:" 前缀、human 为权威默认,均不加标
|
|
192
|
+
if (desc) {
|
|
193
|
+
lines.push(item.descriptionSource === 'llm' ? ` purpose: [llm] ${desc}` : ` purpose: ${desc}`);
|
|
194
|
+
}
|
|
167
195
|
if (item.topics?.length)
|
|
168
196
|
lines.push(` topics: ${item.topics.join(' · ')}`);
|
|
169
197
|
return lines.join('\n');
|
|
@@ -328,14 +356,10 @@ export class CognitionLayer extends BaseLayer {
|
|
|
328
356
|
export class WisdomLayer extends BaseLayer {
|
|
329
357
|
select;
|
|
330
358
|
onInjected;
|
|
331
|
-
coreMaxItems;
|
|
332
|
-
scenarioMaxItems;
|
|
333
359
|
constructor(options) {
|
|
334
360
|
super('wisdom', { order: options.order, placement: 'snapshot' });
|
|
335
361
|
this.select = options.select;
|
|
336
362
|
this.onInjected = options.onInjected;
|
|
337
|
-
this.coreMaxItems = options.coreMaxItems;
|
|
338
|
-
this.scenarioMaxItems = options.scenarioMaxItems;
|
|
339
363
|
}
|
|
340
364
|
async assemble(ctx) {
|
|
341
365
|
const picks = await this.select(ctx.query ?? '');
|
|
@@ -346,11 +370,15 @@ export class WisdomLayer extends BaseLayer {
|
|
|
346
370
|
return null;
|
|
347
371
|
const text = `# 思维框架\n\n${body}`;
|
|
348
372
|
const { text: truncated, dropped } = this.truncateToBudget(text, ctx.tokenBudget);
|
|
349
|
-
|
|
350
|
-
//
|
|
351
|
-
|
|
373
|
+
// S1:只对实际留在文本里的条目报 sources——truncate 粗滤会裁掉尾部条目,被裁掉的不入账。
|
|
374
|
+
// applied 只记 core/scenario 命中:trial 轮转是保底曝光(bucket='trial'),入账 applied 会
|
|
375
|
+
// 稀释 contestRate、废掉 zero-apply 淘汰、抬高 utility——曝光与「被使用」是两件事。
|
|
376
|
+
// sources 仍含 trial(归因窗口需要真实注入清单,判官才能裁 assisted)。
|
|
377
|
+
const kept = picks.filter((p) => truncated.includes(p.entry.statement));
|
|
378
|
+
const appliedIds = kept.filter((p) => p.bucket !== 'trial').map((p) => p.entry.id);
|
|
379
|
+
if (this.onInjected && appliedIds.length) {
|
|
352
380
|
try {
|
|
353
|
-
await this.onInjected(
|
|
381
|
+
await this.onInjected(appliedIds);
|
|
354
382
|
}
|
|
355
383
|
catch {
|
|
356
384
|
// 入账失败不拖垮装配;结局环可由 evaluate 兜
|
|
@@ -358,7 +386,7 @@ export class WisdomLayer extends BaseLayer {
|
|
|
358
386
|
}
|
|
359
387
|
return this.content(truncated, {
|
|
360
388
|
dropped,
|
|
361
|
-
sources,
|
|
389
|
+
sources: kept.map((p) => p.entry.id),
|
|
362
390
|
});
|
|
363
391
|
}
|
|
364
392
|
}
|
|
@@ -378,12 +406,12 @@ export function createDefaultLayers(options) {
|
|
|
378
406
|
text: query,
|
|
379
407
|
coreMaxItems: options.wisdomCoreMaxItems,
|
|
380
408
|
scenarioMaxItems: options.wisdomScenarioMaxItems,
|
|
409
|
+
trialMaxItems: options.wisdomTrialMaxItems,
|
|
410
|
+
includeTrial: options.wisdomIncludeTrial,
|
|
381
411
|
});
|
|
382
|
-
return picks
|
|
412
|
+
return picks;
|
|
383
413
|
},
|
|
384
414
|
onInjected: (ids) => store.touchApplied(ids),
|
|
385
|
-
coreMaxItems: options.wisdomCoreMaxItems,
|
|
386
|
-
scenarioMaxItems: options.wisdomScenarioMaxItems,
|
|
387
415
|
}));
|
|
388
416
|
}
|
|
389
417
|
if (options.personaText) {
|
|
@@ -25,20 +25,22 @@ export declare class DefaultMessageSelector implements MessageSelector {
|
|
|
25
25
|
* 从头部开始选择消息,直到达到 token 预算
|
|
26
26
|
*
|
|
27
27
|
* 边界对齐:不拆分 tool_call/tool_result 对。
|
|
28
|
+
*
|
|
29
|
+
* @param messages - 候选消息(原文)
|
|
30
|
+
* @param budget - token 预算
|
|
31
|
+
* @param estimator - 估算器
|
|
32
|
+
* @param measure - 与 messages 等长同序的度量视图(省略时量原文)
|
|
28
33
|
*/
|
|
29
34
|
private selectByTokenBudget;
|
|
30
35
|
/**
|
|
31
36
|
* 从尾部开始选择消息,直到达到 token 预算
|
|
32
37
|
*
|
|
33
38
|
* 边界对齐:不拆分 tool_call/tool_result 对。
|
|
39
|
+
*
|
|
40
|
+
* @param messages - 候选消息(原文)
|
|
41
|
+
* @param budget - token 预算
|
|
42
|
+
* @param estimator - 估算器
|
|
43
|
+
* @param measure - 与 messages 等长同序的度量视图(省略时量原文)
|
|
34
44
|
*/
|
|
35
45
|
private selectByTokenBudgetFromEnd;
|
|
36
|
-
/**
|
|
37
|
-
* 检查消息是否是工具结果
|
|
38
|
-
*/
|
|
39
|
-
private isToolResult;
|
|
40
|
-
/**
|
|
41
|
-
* 检查消息是否包含工具调用
|
|
42
|
-
*/
|
|
43
|
-
private hasToolCall;
|
|
44
46
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* 边界对齐:不拆分 tool_call/tool_result 对。
|
|
11
11
|
*/
|
|
12
12
|
import { HeuristicTokenEstimator } from './token-estimator.js';
|
|
13
|
+
import { hasToolCall, isToolResultMessage } from './capabilities/compact/messages.js';
|
|
13
14
|
export class DefaultMessageSelector {
|
|
14
15
|
/**
|
|
15
16
|
* 选择要保留的消息
|
|
@@ -22,6 +23,19 @@ export class DefaultMessageSelector {
|
|
|
22
23
|
select(messages, options, tokenEstimator) {
|
|
23
24
|
const estimator = tokenEstimator ?? new HeuristicTokenEstimator();
|
|
24
25
|
const { maxTokens, protectFirstN, protectLastN } = options;
|
|
26
|
+
// 度量视图(可选):与 messages 等长同序,仅用于估算;切分仍按原文。
|
|
27
|
+
// 不传时退化为原行为(量原文)。
|
|
28
|
+
const measure = options.measureMessages ?? messages;
|
|
29
|
+
/**
|
|
30
|
+
* 估算字节区间 [start, end) 的 token 数(按度量视图的同下标取值)
|
|
31
|
+
*/
|
|
32
|
+
const estimateRange = (start, end) => {
|
|
33
|
+
let tokens = 0;
|
|
34
|
+
for (let i = start; i < end; i++) {
|
|
35
|
+
tokens += estimator.estimateMessage(measure[i] ?? messages[i]);
|
|
36
|
+
}
|
|
37
|
+
return tokens;
|
|
38
|
+
};
|
|
25
39
|
// 空消息列表
|
|
26
40
|
if (messages.length === 0) {
|
|
27
41
|
return {
|
|
@@ -43,10 +57,11 @@ export class DefaultMessageSelector {
|
|
|
43
57
|
const tailMessages = tailCount > 0 ? remainingAfterHead.slice(-tailCount) : [];
|
|
44
58
|
// 3. 中间区域(可压缩/丢弃)
|
|
45
59
|
const middleMessages = tailCount > 0 ? remainingAfterHead.slice(0, -tailCount) : remainingAfterHead;
|
|
46
|
-
// 4. 计算各区域 token
|
|
47
|
-
const headTokens =
|
|
48
|
-
const
|
|
49
|
-
const
|
|
60
|
+
// 4. 计算各区域 token 数(按度量视图;区域下标以原文为准)
|
|
61
|
+
const headTokens = estimateRange(0, headCount);
|
|
62
|
+
const tailStartIdx = messages.length - tailMessages.length;
|
|
63
|
+
const tailTokens = estimateRange(tailStartIdx, messages.length);
|
|
64
|
+
const middleTokens = estimateRange(headCount, tailStartIdx);
|
|
50
65
|
// 5. 计算可用预算
|
|
51
66
|
const fixedTokens = headTokens + tailTokens;
|
|
52
67
|
// 如果固定区域已超预算,需要截断尾部
|
|
@@ -65,7 +80,7 @@ export class DefaultMessageSelector {
|
|
|
65
80
|
}
|
|
66
81
|
// 保留头部 + 部分尾部
|
|
67
82
|
const availableForTail = maxTokens - headTokens;
|
|
68
|
-
const selectedTail = this.selectByTokenBudget(tailMessages, availableForTail, estimator);
|
|
83
|
+
const selectedTail = this.selectByTokenBudget(tailMessages, availableForTail, estimator, measure.slice(tailStartIdx));
|
|
69
84
|
return {
|
|
70
85
|
kept: [...headMessages, ...selectedTail],
|
|
71
86
|
overflow: middleMessages,
|
|
@@ -90,8 +105,17 @@ export class DefaultMessageSelector {
|
|
|
90
105
|
};
|
|
91
106
|
}
|
|
92
107
|
// 7. 中间区域需要压缩:从尾部开始保留(越新的越重要)
|
|
93
|
-
const selectedMiddle = this.selectByTokenBudgetFromEnd(middleMessages, middleBudget, estimator);
|
|
94
|
-
|
|
108
|
+
const selectedMiddle = this.selectByTokenBudgetFromEnd(middleMessages, middleBudget, estimator, measure.slice(headCount, tailStartIdx));
|
|
109
|
+
// 选中段可能因配对对齐而不连续(跳过孤立 tool_call/result),
|
|
110
|
+
// 所以按成员精确累加,不能用「长度差」推算起点。
|
|
111
|
+
const selectedMiddleSet = new Set(selectedMiddle);
|
|
112
|
+
let selectedMiddleTokens = 0;
|
|
113
|
+
for (let i = headCount; i < tailStartIdx; i++) {
|
|
114
|
+
const m = messages[i];
|
|
115
|
+
if (selectedMiddleSet.has(m)) {
|
|
116
|
+
selectedMiddleTokens += estimator.estimateMessage(measure[i] ?? m);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
95
119
|
const kept = [...headMessages, ...selectedMiddle, ...tailMessages];
|
|
96
120
|
const overflow = middleMessages.slice(0, middleMessages.length - selectedMiddle.length);
|
|
97
121
|
return {
|
|
@@ -107,19 +131,24 @@ export class DefaultMessageSelector {
|
|
|
107
131
|
* 从头部开始选择消息,直到达到 token 预算
|
|
108
132
|
*
|
|
109
133
|
* 边界对齐:不拆分 tool_call/tool_result 对。
|
|
134
|
+
*
|
|
135
|
+
* @param messages - 候选消息(原文)
|
|
136
|
+
* @param budget - token 预算
|
|
137
|
+
* @param estimator - 估算器
|
|
138
|
+
* @param measure - 与 messages 等长同序的度量视图(省略时量原文)
|
|
110
139
|
*/
|
|
111
|
-
selectByTokenBudget(messages, budget, estimator) {
|
|
140
|
+
selectByTokenBudget(messages, budget, estimator, measure) {
|
|
112
141
|
const selected = [];
|
|
113
142
|
const selectedSet = new Set();
|
|
114
143
|
let usedTokens = 0;
|
|
115
144
|
for (let i = 0; i < messages.length; i++) {
|
|
116
145
|
const msg = messages[i];
|
|
117
|
-
const msgTokens = estimator.estimateMessage(msg);
|
|
146
|
+
const msgTokens = estimator.estimateMessage(measure?.[i] ?? msg);
|
|
118
147
|
// 检查是否需要边界对齐
|
|
119
|
-
if (
|
|
148
|
+
if (isToolResultMessage(msg) && i > 0) {
|
|
120
149
|
// tool_result 消息必须和前面的 tool_call 消息一起保留
|
|
121
150
|
const prevMsg = messages[i - 1];
|
|
122
|
-
if (
|
|
151
|
+
if (hasToolCall(prevMsg)) {
|
|
123
152
|
// 确保 tool_call 已被选中
|
|
124
153
|
const prevInSelected = selectedSet.has(prevMsg);
|
|
125
154
|
if (!prevInSelected) {
|
|
@@ -141,18 +170,23 @@ export class DefaultMessageSelector {
|
|
|
141
170
|
* 从尾部开始选择消息,直到达到 token 预算
|
|
142
171
|
*
|
|
143
172
|
* 边界对齐:不拆分 tool_call/tool_result 对。
|
|
173
|
+
*
|
|
174
|
+
* @param messages - 候选消息(原文)
|
|
175
|
+
* @param budget - token 预算
|
|
176
|
+
* @param estimator - 估算器
|
|
177
|
+
* @param measure - 与 messages 等长同序的度量视图(省略时量原文)
|
|
144
178
|
*/
|
|
145
|
-
selectByTokenBudgetFromEnd(messages, budget, estimator) {
|
|
179
|
+
selectByTokenBudgetFromEnd(messages, budget, estimator, measure) {
|
|
146
180
|
const selected = [];
|
|
147
181
|
const selectedSet = new Set();
|
|
148
182
|
let usedTokens = 0;
|
|
149
183
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
150
184
|
const msg = messages[i];
|
|
151
|
-
const msgTokens = estimator.estimateMessage(msg);
|
|
185
|
+
const msgTokens = estimator.estimateMessage(measure?.[i] ?? msg);
|
|
152
186
|
// 边界对齐:如果这是 tool_call 消息,检查后面的 tool_result
|
|
153
|
-
if (
|
|
187
|
+
if (hasToolCall(msg) && i < messages.length - 1) {
|
|
154
188
|
const nextMsg = messages[i + 1];
|
|
155
|
-
if (
|
|
189
|
+
if (isToolResultMessage(nextMsg)) {
|
|
156
190
|
// 确保 tool_result 已被选中
|
|
157
191
|
const nextInSelected = selectedSet.has(nextMsg);
|
|
158
192
|
if (!nextInSelected) {
|
|
@@ -170,16 +204,4 @@ export class DefaultMessageSelector {
|
|
|
170
204
|
}
|
|
171
205
|
return selected;
|
|
172
206
|
}
|
|
173
|
-
/**
|
|
174
|
-
* 检查消息是否是工具结果
|
|
175
|
-
*/
|
|
176
|
-
isToolResult(msg) {
|
|
177
|
-
return msg.role === 'tool' || (msg.toolResults !== undefined && msg.toolResults.length > 0);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 检查消息是否包含工具调用
|
|
181
|
-
*/
|
|
182
|
-
hasToolCall(msg) {
|
|
183
|
-
return msg.role === 'assistant' && msg.toolCalls !== undefined && msg.toolCalls.length > 0;
|
|
184
|
-
}
|
|
185
207
|
}
|
|
@@ -17,15 +17,15 @@ export interface CreateProviderSummarizeOptions {
|
|
|
17
17
|
/**
|
|
18
18
|
* 创建基于 ModelProvider 的摘要函数
|
|
19
19
|
*
|
|
20
|
-
* @param provider -
|
|
20
|
+
* @param provider - 用于调用的模型提供者
|
|
21
21
|
* @param options - 模型名与温度
|
|
22
|
-
* @returns SummarizeFunction;调用失败向上抛出,由
|
|
22
|
+
* @returns SummarizeFunction;调用失败向上抛出,由 compact 能力机械降级阶梯兜底
|
|
23
23
|
*/
|
|
24
24
|
export declare function createProviderSummarize(provider: ModelProvider, options?: CreateProviderSummarizeOptions): SummarizeFunction;
|
|
25
25
|
/**
|
|
26
26
|
* 从 model level 映射中挑摘要用 provider
|
|
27
27
|
*
|
|
28
|
-
* 优先级:
|
|
28
|
+
* 优先级:mini → standard → 传入的 fallbackProvider(通常是主模型)
|
|
29
29
|
*
|
|
30
30
|
* @param providers - 可用 provider 映射
|
|
31
31
|
* @param levelMap - models.level 配置(primary 为 provider/model)
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* 创建基于 ModelProvider 的摘要函数
|
|
9
9
|
*
|
|
10
|
-
* @param provider -
|
|
10
|
+
* @param provider - 用于调用的模型提供者
|
|
11
11
|
* @param options - 模型名与温度
|
|
12
|
-
* @returns SummarizeFunction;调用失败向上抛出,由
|
|
12
|
+
* @returns SummarizeFunction;调用失败向上抛出,由 compact 能力机械降级阶梯兜底
|
|
13
13
|
*/
|
|
14
14
|
export function createProviderSummarize(provider, options) {
|
|
15
15
|
return async (messages, opts) => {
|
|
@@ -18,19 +18,26 @@ export function createProviderSummarize(provider, options) {
|
|
|
18
18
|
model: options?.model,
|
|
19
19
|
// 未显式配置即不发送:由模型配置(ModelInfo.temperature)或服务端默认决定
|
|
20
20
|
temperature: options?.temperature,
|
|
21
|
+
// P3:run 中止 / 摘要超时都靠这个 signal 取消在飞请求(provider 侧 fetch 已接 signal)
|
|
22
|
+
...(opts?.signal ? { signal: opts.signal } : {}),
|
|
21
23
|
// 源头钳制(评审 F6):三条摘要路径(manual/proactive/overflow)共用本闭包,
|
|
22
24
|
// 硬顶不得越过模型实际输出上限,否则窗口钳制在大窗口下仍会顶穿被 provider 400
|
|
23
25
|
maxTokens: options?.maxOutputTokens && options.maxOutputTokens > 0
|
|
24
26
|
? Math.min(opts?.maxTokens ?? options.maxOutputTokens, options.maxOutputTokens)
|
|
25
27
|
: opts?.maxTokens,
|
|
26
28
|
});
|
|
29
|
+
// usage 回传(2026-11-08 outputTokens 真值):摘要产物体量的真值通道,
|
|
30
|
+
// 供压缩计量以真值替代估算(契约见 SummarizeFunction.onUsage)
|
|
31
|
+
if (response.usage && response.usage.outputTokens > 0) {
|
|
32
|
+
opts?.onUsage?.({ outputTokens: response.usage.outputTokens });
|
|
33
|
+
}
|
|
27
34
|
return response.content;
|
|
28
35
|
};
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
31
38
|
* 从 model level 映射中挑摘要用 provider
|
|
32
39
|
*
|
|
33
|
-
* 优先级:
|
|
40
|
+
* 优先级:mini → standard → 传入的 fallbackProvider(通常是主模型)
|
|
34
41
|
*
|
|
35
42
|
* @param providers - 可用 provider 映射
|
|
36
43
|
* @param levelMap - models.level 配置(primary 为 provider/model)
|
|
@@ -38,7 +45,7 @@ export function createProviderSummarize(provider, options) {
|
|
|
38
45
|
* @returns 选中的 provider + 建议模型名
|
|
39
46
|
*/
|
|
40
47
|
export function pickSummarizeProvider(providers, levelMap, fallbackProvider) {
|
|
41
|
-
for (const levelName of ['
|
|
48
|
+
for (const levelName of ['mini', 'standard']) {
|
|
42
49
|
const primary = levelMap?.[levelName]?.primary;
|
|
43
50
|
if (!primary)
|
|
44
51
|
continue;
|
|
@@ -78,6 +78,10 @@ export declare function createDefaultSystemPromptAssembler(options?: {
|
|
|
78
78
|
/** Wisdom 注入条数硬顶 */
|
|
79
79
|
wisdomCoreMaxItems?: number;
|
|
80
80
|
wisdomScenarioMaxItems?: number;
|
|
81
|
+
/** trial 轮转试用名额(wisdom.injection.trialMaxItems;缺省 2——保底曝光打破晋升死锁;0 关闭) */
|
|
82
|
+
wisdomTrialMaxItems?: number;
|
|
83
|
+
/** trial 可见性(wisdom.injection.trialVisible;缺省 true——trial 的意义就是被试用) */
|
|
84
|
+
wisdomIncludeTrial?: boolean;
|
|
81
85
|
cognitionStore?: ConceptGraphStore;
|
|
82
86
|
memoryLimit?: number;
|
|
83
87
|
knowledgeMaxEntries?: number;
|
|
@@ -115,8 +115,10 @@ export function createDefaultSystemPromptAssembler(options) {
|
|
|
115
115
|
text: query,
|
|
116
116
|
coreMaxItems: options?.wisdomCoreMaxItems,
|
|
117
117
|
scenarioMaxItems: options?.wisdomScenarioMaxItems,
|
|
118
|
+
trialMaxItems: options?.wisdomTrialMaxItems,
|
|
119
|
+
includeTrial: options?.wisdomIncludeTrial,
|
|
118
120
|
});
|
|
119
|
-
return picks
|
|
121
|
+
return picks;
|
|
120
122
|
},
|
|
121
123
|
onInjected: (ids) => wisdomStore.touchApplied(ids),
|
|
122
124
|
}));
|
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/** 通用文本:英文约 4 chars/token,中文约 1 char/token */
|
|
8
8
|
export declare const CHARS_PER_TOKEN = 4;
|
|
9
|
-
/** 工具结果:结构化输出更密集,约
|
|
10
|
-
export declare const TOOL_RESULT_CHARS_PER_TOKEN =
|
|
11
|
-
/** JSON
|
|
12
|
-
export declare const JSON_CHARS_PER_TOKEN =
|
|
9
|
+
/** 工具结果:结构化输出更密集,约 1.7 chars/token(2026-11-08 生产样本拟合:原 2 系统低估 ~40%) */
|
|
10
|
+
export declare const TOOL_RESULT_CHARS_PER_TOKEN = 1.7;
|
|
11
|
+
/** JSON 负载(schema / arguments):结构符号多,约 2 chars/token(2026-11-08 样本拟合调低;与 tr 档共线,取业界密度区间居中,勿硬拟合) */
|
|
12
|
+
export declare const JSON_CHARS_PER_TOKEN = 2;
|
|
13
|
+
/** 中文等 CJK:1 token/字 */
|
|
14
|
+
export declare const TEXT_CJK_CHARS_PER_TOKEN = 1;
|
|
15
|
+
/** 代码 / 标识符:约 3 chars/token */
|
|
16
|
+
export declare const CODE_CHARS_PER_TOKEN = 3;
|
|
13
17
|
/** 消息结构开销(role + 分隔符 + 边界标记) */
|
|
14
18
|
export declare const MESSAGE_OVERHEAD_TOKENS = 12;
|
|
15
19
|
/** 安全余量系数:补偿估算不准 */
|
|
@@ -20,5 +24,3 @@ export declare const IMAGE_TOKEN_ESTIMATE = 1200;
|
|
|
20
24
|
export declare const AUDIO_TOKEN_ESTIMATE = 30;
|
|
21
25
|
/** 视频 token 估算(抽帧处理,假设 10 帧 × 85 token) */
|
|
22
26
|
export declare const VIDEO_TOKEN_ESTIMATE = 850;
|
|
23
|
-
/** 超长文本采样阈值(字符数) */
|
|
24
|
-
export declare const SAMPLE_THRESHOLD = 2000;
|
|
@@ -7,10 +7,14 @@
|
|
|
7
7
|
// ── 字符/token 比率 ──
|
|
8
8
|
/** 通用文本:英文约 4 chars/token,中文约 1 char/token */
|
|
9
9
|
export const CHARS_PER_TOKEN = 4;
|
|
10
|
-
/** 工具结果:结构化输出更密集,约
|
|
11
|
-
export const TOOL_RESULT_CHARS_PER_TOKEN =
|
|
12
|
-
/** JSON
|
|
13
|
-
export const JSON_CHARS_PER_TOKEN =
|
|
10
|
+
/** 工具结果:结构化输出更密集,约 1.7 chars/token(2026-11-08 生产样本拟合:原 2 系统低估 ~40%) */
|
|
11
|
+
export const TOOL_RESULT_CHARS_PER_TOKEN = 1.7;
|
|
12
|
+
/** JSON 负载(schema / arguments):结构符号多,约 2 chars/token(2026-11-08 样本拟合调低;与 tr 档共线,取业界密度区间居中,勿硬拟合) */
|
|
13
|
+
export const JSON_CHARS_PER_TOKEN = 2;
|
|
14
|
+
/** 中文等 CJK:1 token/字 */
|
|
15
|
+
export const TEXT_CJK_CHARS_PER_TOKEN = 1;
|
|
16
|
+
/** 代码 / 标识符:约 3 chars/token */
|
|
17
|
+
export const CODE_CHARS_PER_TOKEN = 3;
|
|
14
18
|
/** 消息结构开销(role + 分隔符 + 边界标记) */
|
|
15
19
|
export const MESSAGE_OVERHEAD_TOKENS = 12;
|
|
16
20
|
/** 安全余量系数:补偿估算不准 */
|
|
@@ -22,6 +26,3 @@ export const IMAGE_TOKEN_ESTIMATE = 1200;
|
|
|
22
26
|
export const AUDIO_TOKEN_ESTIMATE = 30;
|
|
23
27
|
/** 视频 token 估算(抽帧处理,假设 10 帧 × 85 token) */
|
|
24
28
|
export const VIDEO_TOKEN_ESTIMATE = 850;
|
|
25
|
-
// ── 采样策略 ──
|
|
26
|
-
/** 超长文本采样阈值(字符数) */
|
|
27
|
-
export const SAMPLE_THRESHOLD = 2000;
|