@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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy compact-snapshot migration — one-shot conversion of the old
|
|
3
|
+
* `ContextCompactSnapshot` (previousSummary + coverEnd cursor) into initial
|
|
4
|
+
* transform records.
|
|
5
|
+
*
|
|
6
|
+
* Mapping: the legacy sticky view rendered `head + summary + [coverEnd..tailStart)
|
|
7
|
+
* + tail`, i.e. the summary replaced the raw originals in `[headEnd, coverEnd)`
|
|
8
|
+
* while the head stayed verbatim (cache-prefix anchor). The migrated record
|
|
9
|
+
* therefore covers exactly `[headEnd, coverEnd)`, reproducing the legacy view
|
|
10
|
+
* byte-for-byte through the fold.
|
|
11
|
+
*
|
|
12
|
+
* Counter-only legacy states ("compacted, no summary") migrate to a `degrade`
|
|
13
|
+
* gate-anchor record with empty covers: the legacy behavior covered nothing
|
|
14
|
+
* (products refilled), so no coverage may be claimed. The growth-gate **count**
|
|
15
|
+
* base carries over; the token base does **not** — legacy `lastProactiveTokens`
|
|
16
|
+
* is a stale calibrated quantity and, without its write-time ratio, cannot be
|
|
17
|
+
* converted to the raw unit the gate now stores (M-3, review del-e1ee43ef N3).
|
|
18
|
+
*
|
|
19
|
+
* Idempotence is owned by the caller: migrate only when the ledger is empty.
|
|
20
|
+
*
|
|
21
|
+
* @module harness/context/transform/migrate
|
|
22
|
+
*/
|
|
23
|
+
import type { Message } from '@octopi-agent/core/types.js';
|
|
24
|
+
import type { ContextCompactSnapshot } from '../types.js';
|
|
25
|
+
import type { NewTransformRecord } from './types.js';
|
|
26
|
+
export interface LegacyMigrateParams {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
agentId: string;
|
|
29
|
+
snapshot: ContextCompactSnapshot;
|
|
30
|
+
messages: Message[];
|
|
31
|
+
protectFirstN: number;
|
|
32
|
+
protectLastN: number;
|
|
33
|
+
now?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert a legacy snapshot into initial transform records.
|
|
37
|
+
*
|
|
38
|
+
* @param params - migration inputs
|
|
39
|
+
* @returns records to append, or undefined when the snapshot holds nothing migratable
|
|
40
|
+
*/
|
|
41
|
+
export declare function legacySnapshotToRecords(params: LegacyMigrateParams): NewTransformRecord[] | undefined;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy compact-snapshot migration — one-shot conversion of the old
|
|
3
|
+
* `ContextCompactSnapshot` (previousSummary + coverEnd cursor) into initial
|
|
4
|
+
* transform records.
|
|
5
|
+
*
|
|
6
|
+
* Mapping: the legacy sticky view rendered `head + summary + [coverEnd..tailStart)
|
|
7
|
+
* + tail`, i.e. the summary replaced the raw originals in `[headEnd, coverEnd)`
|
|
8
|
+
* while the head stayed verbatim (cache-prefix anchor). The migrated record
|
|
9
|
+
* therefore covers exactly `[headEnd, coverEnd)`, reproducing the legacy view
|
|
10
|
+
* byte-for-byte through the fold.
|
|
11
|
+
*
|
|
12
|
+
* Counter-only legacy states ("compacted, no summary") migrate to a `degrade`
|
|
13
|
+
* gate-anchor record with empty covers: the legacy behavior covered nothing
|
|
14
|
+
* (products refilled), so no coverage may be claimed. The growth-gate **count**
|
|
15
|
+
* base carries over; the token base does **not** — legacy `lastProactiveTokens`
|
|
16
|
+
* is a stale calibrated quantity and, without its write-time ratio, cannot be
|
|
17
|
+
* converted to the raw unit the gate now stores (M-3, review del-e1ee43ef N3).
|
|
18
|
+
*
|
|
19
|
+
* Idempotence is owned by the caller: migrate only when the ledger is empty.
|
|
20
|
+
*
|
|
21
|
+
* @module harness/context/transform/migrate
|
|
22
|
+
*/
|
|
23
|
+
import { alignViewSplit } from '../capabilities/compact/index.js';
|
|
24
|
+
import { anchorRange } from './anchors.js';
|
|
25
|
+
/**
|
|
26
|
+
* Convert a legacy snapshot into initial transform records.
|
|
27
|
+
*
|
|
28
|
+
* @param params - migration inputs
|
|
29
|
+
* @returns records to append, or undefined when the snapshot holds nothing migratable
|
|
30
|
+
*/
|
|
31
|
+
export function legacySnapshotToRecords(params) {
|
|
32
|
+
const { sessionId, agentId, snapshot, messages, protectFirstN, protectLastN } = params;
|
|
33
|
+
const hasSummary = Boolean(snapshot.summary);
|
|
34
|
+
const hasCounters = snapshot.lastProactiveMessageCount != null;
|
|
35
|
+
if (!hasSummary && !hasCounters)
|
|
36
|
+
return undefined;
|
|
37
|
+
const meta = {
|
|
38
|
+
reason: 'manual',
|
|
39
|
+
fresh: hasSummary,
|
|
40
|
+
summarizeAttempted: false,
|
|
41
|
+
messageCount: snapshot.lastProactiveMessageCount ?? messages.length,
|
|
42
|
+
// M-3(评审 del-e1ee43ef N3):不迁移 viewTokens——旧值是校准存量(缺写入时 ratio 无法
|
|
43
|
+
// 换算成 raw),迁移过去也会被恢复端的口径版本守卫丢弃;计数基数照常带。
|
|
44
|
+
};
|
|
45
|
+
const covers = [];
|
|
46
|
+
if (hasSummary && (snapshot.lastProactiveCoverEnd ?? 0) > 0 && messages.length > 0) {
|
|
47
|
+
// legacy coverage: [headEnd, coverEnd); head stays verbatim (see module doc)
|
|
48
|
+
const { headEnd } = alignViewSplit(messages, protectFirstN, protectLastN);
|
|
49
|
+
const coverEnd = Math.min(snapshot.lastProactiveCoverEnd, messages.length);
|
|
50
|
+
const run = coverEnd > headEnd ? anchorRange(messages, headEnd, coverEnd - 1) : undefined;
|
|
51
|
+
if (run)
|
|
52
|
+
covers.push(run);
|
|
53
|
+
}
|
|
54
|
+
// 残缺快照(summary 但覆盖未知/无计数):照样迁移——零覆盖 summary 记录在 fold
|
|
55
|
+
// 渲染为无覆盖行的摘要占位(legacy 视图同样注入该摘要;信息等价,评审 F9)
|
|
56
|
+
const record = {
|
|
57
|
+
sessionId,
|
|
58
|
+
agentId,
|
|
59
|
+
type: hasSummary ? 'summary' : 'degrade',
|
|
60
|
+
createdAt: params.now ?? Date.now(),
|
|
61
|
+
covers,
|
|
62
|
+
...(hasSummary ? { text: snapshot.summary } : {}),
|
|
63
|
+
placeholder: hasSummary
|
|
64
|
+
? { role: 'user', source: 'contextSummary' }
|
|
65
|
+
: { role: 'user', source: 'contextLedger' },
|
|
66
|
+
meta,
|
|
67
|
+
};
|
|
68
|
+
return [record];
|
|
69
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform records — persistent compaction products.
|
|
3
|
+
*
|
|
4
|
+
* Model (arch/context-size-accounting.md §10.18「持久转换记录」拍板):
|
|
5
|
+
* a compaction product is a **fact**, not a temporary view. Once a record is
|
|
6
|
+
* appended it is permanently effective; the original text only returns to the
|
|
7
|
+
* view on an explicit revocation entry. Assembly = deterministic application
|
|
8
|
+
* of effective records over the append-only original messages (fold).
|
|
9
|
+
*
|
|
10
|
+
* - Per-agent ledger: records are keyed (sessionId, agentId) (E4 shape); agents
|
|
11
|
+
* never see each other's compaction views.
|
|
12
|
+
* - Coordinates are message content anchors (hash + occurrence), never array
|
|
13
|
+
* indices — indices survive neither fork/copy nor re-indexing.
|
|
14
|
+
* - `type` is honest: `summary` only for fresh semantic summaries (the fresh
|
|
15
|
+
* gate's sole remaining job); mechanical products are `degrade`.
|
|
16
|
+
*
|
|
17
|
+
* @module harness/context/transform/types
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Stable coordinate of one original message.
|
|
21
|
+
*
|
|
22
|
+
* `hash` is the canonical identity hash of the persisted message; `occurrence`
|
|
23
|
+
* disambiguates byte-identical duplicates in stream order; `indexHint` is the
|
|
24
|
+
* raw index at creation time (fast path only — never authoritative).
|
|
25
|
+
*/
|
|
26
|
+
export interface MessageAnchor {
|
|
27
|
+
/** sha256 hex of the canonical message identity */
|
|
28
|
+
hash: string;
|
|
29
|
+
/** 0-based occurrence of this hash in the message stream at creation */
|
|
30
|
+
occurrence: number;
|
|
31
|
+
/** raw index at creation (resolution fast path) */
|
|
32
|
+
indexHint: number;
|
|
33
|
+
}
|
|
34
|
+
/** One covered run: inclusive original-message range `[from, to]`. */
|
|
35
|
+
export interface TransformRun {
|
|
36
|
+
from: MessageAnchor;
|
|
37
|
+
to: MessageAnchor;
|
|
38
|
+
}
|
|
39
|
+
export type TransformRecordType = 'summary' | 'degrade';
|
|
40
|
+
/** Rendering shape of the replacement placeholder message. */
|
|
41
|
+
export interface TransformPlaceholder {
|
|
42
|
+
role: 'user' | 'system' | 'assistant';
|
|
43
|
+
/** Message.metadata.source marker (e.g. 'contextSummary' / 'contextLedger') */
|
|
44
|
+
source?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One compaction product. Created only by compaction paths (proactive /
|
|
48
|
+
* overflow / manual); appended durably before the compacted view is returned.
|
|
49
|
+
*
|
|
50
|
+
* `covers` may be empty: a pure growth-gate anchor (a completed compaction
|
|
51
|
+
* round that produced no durable coverage — legacy migrate / counters-only).
|
|
52
|
+
*/
|
|
53
|
+
export interface TransformRecord {
|
|
54
|
+
/** per-(sessionId, agentId) monotonic sequence, assigned by the store */
|
|
55
|
+
seq: number;
|
|
56
|
+
sessionId: string;
|
|
57
|
+
agentId: string;
|
|
58
|
+
type: TransformRecordType;
|
|
59
|
+
createdAt: number;
|
|
60
|
+
/** covered original-message runs (inclusive; usually exactly one run) */
|
|
61
|
+
covers: TransformRun[];
|
|
62
|
+
/** content-addressed replacement text ref (`sha256:<hex>`); undefined iff covers is empty */
|
|
63
|
+
blobRef?: string;
|
|
64
|
+
/** replacement text (hydrated at load / consumed at append; persisted via blobRef) */
|
|
65
|
+
text?: string;
|
|
66
|
+
/** replacement message shape (text comes from the blob) */
|
|
67
|
+
placeholder: TransformPlaceholder;
|
|
68
|
+
/** appended revocation entry flipped this flag at load (append-only ledger) */
|
|
69
|
+
revoked: boolean;
|
|
70
|
+
meta: TransformRecordMeta;
|
|
71
|
+
}
|
|
72
|
+
export interface TransformRecordMeta {
|
|
73
|
+
reason: 'proactive' | 'overflow' | 'manual';
|
|
74
|
+
/** fresh semantic summary at creation (record type gate) */
|
|
75
|
+
fresh: boolean;
|
|
76
|
+
/** a summarize LLM call was actually issued (success or failure) */
|
|
77
|
+
summarizeAttempted: boolean;
|
|
78
|
+
/** messages.length at creation (growth-gate base) */
|
|
79
|
+
messageCount: number;
|
|
80
|
+
/** raw-history token estimate at creation — 仅诊断口径(有多段历史时远大于实际请求)
|
|
81
|
+
* :**不作增长门基数**(2026-11-07 起,改用 viewTokens) */
|
|
82
|
+
fullTokens?: number;
|
|
83
|
+
/** post-compaction view token estimate = 实际请求口径(fold + 老化);单位 raw(M-3) */
|
|
84
|
+
viewTokens?: number;
|
|
85
|
+
/** viewTokens 的计量口径版本:缺省 = 旧口径(fold 视图未老化、且非请求形状)。
|
|
86
|
+
* 增长门只认 'request-raw'(请求形状 + raw 单位);'request' 是历史存量(校准单位、
|
|
87
|
+
* 缺写入时 ratio 无法换算)只读不写,与更旧记录一律视为无基数(允许一次压缩自愈),
|
|
88
|
+
* 否则两种口径/单位互比会永久压制压缩。 */
|
|
89
|
+
viewTokensSource?: 'request' | 'request-raw';
|
|
90
|
+
}
|
|
91
|
+
/** Record as handed to the store (seq assigned by the store; text goes to a blob). */
|
|
92
|
+
export type NewTransformRecord = Omit<TransformRecord, 'seq' | 'blobRef' | 'revoked'>;
|
|
93
|
+
export interface TransformLedger {
|
|
94
|
+
/** ordered by seq;`revoked` 已折叠 */
|
|
95
|
+
records: TransformRecord[];
|
|
96
|
+
/**
|
|
97
|
+
* 账本文件曾有任何条目(含损坏行 / blob 丢失被丢弃的)。
|
|
98
|
+
* 迁移幂等门用它而不是 records.length——「行在 blob 全丢」不得被当成空账本
|
|
99
|
+
* 而重放旧快照迁移(评审 F7)。
|
|
100
|
+
*/
|
|
101
|
+
hadEntries?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Persistence port for transform records.
|
|
105
|
+
*
|
|
106
|
+
* Appends are durable-before-return: a compaction product must hit the store
|
|
107
|
+
* before the compacted view is sent (otherwise a crash refills the raw text —
|
|
108
|
+
* exactly the defect this model exists to remove).
|
|
109
|
+
*/
|
|
110
|
+
export interface TransformStore {
|
|
111
|
+
/**
|
|
112
|
+
* Load the ledger for (sessionId, agentId).
|
|
113
|
+
*
|
|
114
|
+
* @param sessionId - session id
|
|
115
|
+
* @param agentId - agent id ("" for legacy single-agent)
|
|
116
|
+
* @returns ledger (empty when none)
|
|
117
|
+
*/
|
|
118
|
+
load(sessionId: string, agentId: string): Promise<TransformLedger>;
|
|
119
|
+
/**
|
|
120
|
+
* Durably append records (and optional revocations).
|
|
121
|
+
*
|
|
122
|
+
* @param sessionId - session id
|
|
123
|
+
* @param agentId - agent id
|
|
124
|
+
* @param records - new records (seq assigned by the store)
|
|
125
|
+
* @param revokeSeqs - seqs of existing records to revoke (explicit revocation)
|
|
126
|
+
* @returns the appended records with seq assigned
|
|
127
|
+
*/
|
|
128
|
+
append(sessionId: string, agentId: string, records: NewTransformRecord[], revokeSeqs?: number[]): Promise<TransformRecord[]>;
|
|
129
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform records — persistent compaction products.
|
|
3
|
+
*
|
|
4
|
+
* Model (arch/context-size-accounting.md §10.18「持久转换记录」拍板):
|
|
5
|
+
* a compaction product is a **fact**, not a temporary view. Once a record is
|
|
6
|
+
* appended it is permanently effective; the original text only returns to the
|
|
7
|
+
* view on an explicit revocation entry. Assembly = deterministic application
|
|
8
|
+
* of effective records over the append-only original messages (fold).
|
|
9
|
+
*
|
|
10
|
+
* - Per-agent ledger: records are keyed (sessionId, agentId) (E4 shape); agents
|
|
11
|
+
* never see each other's compaction views.
|
|
12
|
+
* - Coordinates are message content anchors (hash + occurrence), never array
|
|
13
|
+
* indices — indices survive neither fork/copy nor re-indexing.
|
|
14
|
+
* - `type` is honest: `summary` only for fresh semantic summaries (the fresh
|
|
15
|
+
* gate's sole remaining job); mechanical products are `degrade`.
|
|
16
|
+
*
|
|
17
|
+
* @module harness/context/transform/types
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
* 定形后字节冻结。正文经 XML 转义嵌入,用户原文不得截断信封。
|
|
11
11
|
*/
|
|
12
12
|
import type { Message } from '@octopi-agent/core/types.js';
|
|
13
|
+
import type { LLMMessage } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
14
|
+
type EnvelopeContent = Message['content'] | LLMMessage['content'];
|
|
13
15
|
/** turn_start 元素的 id 形态(会话内单调 t1,t2,…) */
|
|
14
16
|
export declare function formatTurnId(seq: number): string;
|
|
15
17
|
/** 归一化 Message.content → 纯文本(多模态取 text 块拼接;空 content → '') */
|
|
16
|
-
export declare function messageText(content:
|
|
18
|
+
export declare function messageText(content: EnvelopeContent | undefined): string;
|
|
17
19
|
/** user 原文嵌入 XML 前的最小转义(防伪影标签截断信封) */
|
|
18
20
|
export declare function escapeUserMessageText(text: string): string;
|
|
19
21
|
/** 解转义(extractUserMessageText 出口) */
|
|
@@ -44,7 +46,7 @@ export declare function formatTurnContextXml(params: {
|
|
|
44
46
|
* 非 turn_start 正文原样返回。
|
|
45
47
|
* 取**最后一个** user_message 块(boilerplate 禁止再写该标签字面量)。
|
|
46
48
|
*/
|
|
47
|
-
export declare function extractUserMessageText(content:
|
|
49
|
+
export declare function extractUserMessageText(content: EnvelopeContent | undefined): string;
|
|
48
50
|
/**
|
|
49
51
|
* 剥掉 `<turn_context>…</turn_context>`(摘要语义输入 / UI)。
|
|
50
52
|
* 保留 `<user_message>` 与 turn_start/turn_end 骨架(或在 UI 场景配合 extractUserMessageText)。
|
|
@@ -109,7 +111,7 @@ export declare function escapeSlotBody(tag: string, body: string): string;
|
|
|
109
111
|
* @param content - 消息正文(string 或 Message.content)
|
|
110
112
|
* @returns 信封解析结果;非 turn_start 正文返回 null
|
|
111
113
|
*/
|
|
112
|
-
export declare function parseTurnEnvelope(content:
|
|
114
|
+
export declare function parseTurnEnvelope(content: EnvelopeContent | undefined): TurnEnvelopeParts | null;
|
|
113
115
|
/**
|
|
114
116
|
* 拼 turn_context 内的槽位 XML(runner 注入)。
|
|
115
117
|
* 正文经 escapeSlotBody 定向转义(D7 A′):语料同名字面量不得产出解析器眼里的标签,
|
|
@@ -122,3 +124,4 @@ export declare function joinSlotXml(parts: Array<{
|
|
|
122
124
|
}>): string;
|
|
123
125
|
/** 任意 content 归一化后的用户正文(UI / 载体扫描共用) */
|
|
124
126
|
export declare function unwrapUserText(content: string | Message['content'] | undefined | null): string;
|
|
127
|
+
export {};
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Message } from '@octopi-agent/core/types.js';
|
|
10
10
|
import type { LLMMessage, LLMToolDefinition } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
11
|
+
import type { SummarizeFunction } from './capabilities/compact/types.js';
|
|
11
12
|
export type { LLMMessage, LLMToolDefinition };
|
|
13
|
+
/** 族 A 摘要执行契约:单源定义在 capabilities/compact/types.ts(此处再导出保持域内引用面稳定)。 */
|
|
14
|
+
export type { SummarizeFunction };
|
|
12
15
|
export interface ContextEngineInfo {
|
|
13
16
|
/** 引擎唯一标识 */
|
|
14
17
|
id: string;
|
|
@@ -39,8 +42,8 @@ export interface TokenEstimator {
|
|
|
39
42
|
/** 估算工具定义的 token 数 */
|
|
40
43
|
estimateTools(tools: LLMToolDefinition[]): number;
|
|
41
44
|
}
|
|
42
|
-
/** 压缩原因:主动摘要 vs 硬溢出 */
|
|
43
|
-
export type ContextCompactReason = 'proactive' | 'overflow';
|
|
45
|
+
/** 压缩原因:主动摘要 vs 硬溢出 vs 手动(m-2:manual 事件显式带 reason,防 store 沿用旧标签) */
|
|
46
|
+
export type ContextCompactReason = 'proactive' | 'overflow' | 'manual';
|
|
44
47
|
/**
|
|
45
48
|
* 上下文压缩可观测事件
|
|
46
49
|
*
|
|
@@ -48,7 +51,7 @@ export type ContextCompactReason = 'proactive' | 'overflow';
|
|
|
48
51
|
* 避免 LLM 摘要耗时被误判为会话卡死。失败不中断本轮(引擎回退截断)。
|
|
49
52
|
*/
|
|
50
53
|
export interface ContextCompactEvent {
|
|
51
|
-
type: 'context.compact.start' | 'context.compact.end' | 'context.compact.error' | 'context.compact.summarize_fallback';
|
|
54
|
+
type: 'context.compact.start' | 'context.compact.progress' | 'context.compact.end' | 'context.compact.error' | 'context.compact.summarize_fallback';
|
|
52
55
|
sessionId: string;
|
|
53
56
|
reason?: ContextCompactReason;
|
|
54
57
|
/** 压缩前估算 token */
|
|
@@ -61,17 +64,54 @@ export interface ContextCompactEvent {
|
|
|
61
64
|
durationMs?: number;
|
|
62
65
|
/** 走缓存摘要重建,未调 LLM */
|
|
63
66
|
cached?: boolean;
|
|
67
|
+
/** 中止收尾(本轮作废、零写入)——不是「压缩完成」,UI 不得显示 compacted */
|
|
68
|
+
cancelled?: boolean;
|
|
64
69
|
/** summarize_fallback:cache-miss 旁路原因(no_prefix | window_guard | window_exhausted,F22) */
|
|
65
70
|
fallback?: string;
|
|
66
71
|
error?: string;
|
|
72
|
+
/** error 的性质:denied = before_compaction 策略拒绝(不是故障);failed = 压缩失败 */
|
|
73
|
+
kind?: 'denied' | 'failed';
|
|
74
|
+
/** progress:当前阶段(summarize = 摘要请求已发出、等 provider 返回) */
|
|
75
|
+
phase?: 'summarize';
|
|
76
|
+
/** progress:摘要请求体量(JSON 字符数) */
|
|
77
|
+
requestChars?: number;
|
|
78
|
+
/** progress:摘要请求消息条数 */
|
|
79
|
+
requestMessages?: number;
|
|
80
|
+
/** progress:本次摘要调用预算(ms);缺失 = 不设预算 */
|
|
81
|
+
timeoutMs?: number;
|
|
67
82
|
}
|
|
68
83
|
/** 事件回调(Builder 注入 → EventBus) */
|
|
69
|
-
export type ContextEmitFn = (event: ContextCompactEvent) => void;
|
|
84
|
+
export type ContextEmitFn = (event: ContextCompactEvent | OverflowAlertEvent) => void;
|
|
85
|
+
/**
|
|
86
|
+
* overflow 症状告警(P3,arch/overflow-redesign.md §2.3 + 红线 7)
|
|
87
|
+
*
|
|
88
|
+
* 守门人触发 = 罕见异常信号,每次触发打告警(不当日常):
|
|
89
|
+
* - `proactive_failed`(A 类症状):前馈溢出——proactive 本该在到达窗口前压缩
|
|
90
|
+
* - `config_drift` / `config_missing`(F 类,有实证):contextWindow 配置漂移/缺失
|
|
91
|
+
* - `structural_over_budget`(D 类):保护段超限——窗口连固定面都放不下
|
|
92
|
+
* - `window_mismatch`(F 类,归因未定):请求超真窗口但未提取到数字,配置或尺子偏差待查
|
|
93
|
+
*/
|
|
94
|
+
export interface OverflowAlertEvent {
|
|
95
|
+
type: 'context.overflow.alert';
|
|
96
|
+
sessionId: string;
|
|
97
|
+
/** 症状语义(红线 7:前馈溢出必须含 proactive 失效语义) */
|
|
98
|
+
symptom: 'proactive_failed' | 'config_drift' | 'config_missing' | 'structural_over_budget' | 'window_mismatch';
|
|
99
|
+
/** 人类可读告警(含症状语义关键词,UI/日志直接展示) */
|
|
100
|
+
message: string;
|
|
101
|
+
/** 触发时的估算 token(可选) */
|
|
102
|
+
estimatedTokens?: number;
|
|
103
|
+
/** 窗口值(配置或真值,可选) */
|
|
104
|
+
contextWindow?: number;
|
|
105
|
+
/** 触发入口:T1 前馈溢出 / T2 反馈溢出(F 类回填)/ T3 保护段超限 */
|
|
106
|
+
trigger?: 'T1' | 'T2' | 'T3';
|
|
107
|
+
}
|
|
70
108
|
export interface AssembleParams {
|
|
71
109
|
/** Session ID */
|
|
72
110
|
sessionId: string;
|
|
73
111
|
/** Agent ID(E4 compact 键分量;缺省时引擎状态退化为纯 sessionId) */
|
|
74
112
|
agentId?: string;
|
|
113
|
+
/** provider/model 标识(P1-a 校准 ratio 分键,如 `mock/m`;缺省时校准归入 'unknown') */
|
|
114
|
+
modelKey?: string;
|
|
75
115
|
/** 当前消息历史 */
|
|
76
116
|
messages: Message[];
|
|
77
117
|
/** 系统提示词 */
|
|
@@ -92,17 +132,25 @@ export interface AssembleParams {
|
|
|
92
132
|
* 与 contextWindow 无关;未知窗口时仍可作手动/结构压缩的目标。
|
|
93
133
|
*/
|
|
94
134
|
compactTargetTokens?: number;
|
|
95
|
-
/**
|
|
135
|
+
/** 中止信号(run 中止 → 取消在飞摘要;P3 起由 Loop 经 convertToLlm 透传) */
|
|
96
136
|
signal?: AbortSignal;
|
|
97
|
-
/** Token
|
|
137
|
+
/** Token 估算器(可选,未提供时使用默认实现)。**必须是未校准的原始估算器**——
|
|
138
|
+
* 校准由引擎 ContextSizeLedger 统一施加,传入已校准包装会造成双重校准 */
|
|
98
139
|
tokenEstimator?: TokenEstimator;
|
|
99
140
|
/** LLM 摘要调用函数(可选,用于压缩阶段) */
|
|
100
141
|
summarize?: SummarizeFunction;
|
|
142
|
+
/**
|
|
143
|
+
* 交接式摘要素材:当前会话 task 快照(B0:易变块走 content 尾部指令)。
|
|
144
|
+
* 手动/自动(proactive/overflow)压缩路径统一透传给摘要请求(F8R-05),
|
|
145
|
+
* 使自动路径不再依赖注入历史里的旧快照副本。
|
|
146
|
+
*/
|
|
147
|
+
taskSnapshot?: string;
|
|
101
148
|
/** 压缩进度回调(可选;UI / 可观测) */
|
|
102
149
|
emit?: ContextEmitFn;
|
|
103
150
|
/**
|
|
104
|
-
|
|
105
|
-
*
|
|
151
|
+
/**
|
|
152
|
+
* 旧压缩快照读口(ContextCompactSnapshot,迁移输入):转换记录账本为空且快照
|
|
153
|
+
* 存在时一次性迁移为初始记录(幂等)。迁移后快照不再更新。
|
|
106
154
|
*/
|
|
107
155
|
loadCompactState?: (sessionId: string) => Promise<ContextCompactSnapshot | undefined> | ContextCompactSnapshot | undefined;
|
|
108
156
|
}
|
|
@@ -125,28 +173,6 @@ export interface ContextCompactSnapshot {
|
|
|
125
173
|
/** 上次主动压缩后的视图 token 估算 */
|
|
126
174
|
lastProactiveTokens?: number;
|
|
127
175
|
}
|
|
128
|
-
/**
|
|
129
|
-
* 摘要调用函数
|
|
130
|
-
*
|
|
131
|
-
* 由 Harness 层注入,ContextEngine 用它调用 LLM 生成摘要。
|
|
132
|
-
* 这样 ContextEngine 不直接依赖 ModelProvider,保持解耦。
|
|
133
|
-
*
|
|
134
|
-
* 契约(迭代式更新):`options.previousSummary` 已按约定嵌入 `messages` 正文
|
|
135
|
-
* ("Previous summary: …" 段),实现方无需再读 opts 拼 prompt;**返回值即完整
|
|
136
|
-
* 更新后的摘要**,调用方不得再与旧摘要拼接。
|
|
137
|
-
*
|
|
138
|
-
* @param messages - 摘要请求消息(system 指令 + 用户正文;非原始对话序列)
|
|
139
|
-
* @param options - 摘要选项
|
|
140
|
-
* @returns 完整更新后的摘要文本
|
|
141
|
-
*/
|
|
142
|
-
export type SummarizeFunction = (messages: LLMMessage[], options?: {
|
|
143
|
-
/** 上次摘要(已嵌入 messages 正文;仅作元信息回传) */
|
|
144
|
-
previousSummary?: string;
|
|
145
|
-
/** 摘要 token 预算 */
|
|
146
|
-
maxTokens?: number;
|
|
147
|
-
/** 自定义指令 */
|
|
148
|
-
instructions?: string;
|
|
149
|
-
}) => Promise<string>;
|
|
150
176
|
export interface AssembleResult {
|
|
151
177
|
/** 组装好的 LLM 消息 */
|
|
152
178
|
messages: LLMMessage[];
|
|
@@ -157,12 +183,12 @@ export interface AssembleResult {
|
|
|
157
183
|
/** 被丢弃/压缩的信息摘要(告诉模型"你失去了什么") */
|
|
158
184
|
droppedSummary?: string;
|
|
159
185
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
186
|
+
* 当前会话压缩摘要正文(最新 summary 型转换记录的文本)。
|
|
187
|
+
* 供调用方展示;无摘要时为 undefined。
|
|
162
188
|
*/
|
|
163
189
|
summary?: string;
|
|
164
|
-
/**
|
|
165
|
-
|
|
190
|
+
/** estimatedTokens 的读数来源(pressure 快照可观测,评审 F5):calibrated/anchored/raw */
|
|
191
|
+
readingSource?: 'calibrated' | 'anchored' | 'raw';
|
|
166
192
|
/** 不可信内容范围 */
|
|
167
193
|
untrustedRanges?: Array<{
|
|
168
194
|
start: number;
|
|
@@ -174,27 +200,14 @@ export interface IngestParams {
|
|
|
174
200
|
sessionId: string;
|
|
175
201
|
message: Message;
|
|
176
202
|
}
|
|
177
|
-
export interface
|
|
178
|
-
ok: boolean;
|
|
179
|
-
compacted: boolean;
|
|
180
|
-
reason?: string;
|
|
181
|
-
tokensBefore: number;
|
|
182
|
-
tokensAfter?: number;
|
|
183
|
-
summary?: string;
|
|
184
|
-
/**
|
|
185
|
-
* 摘要覆盖终点(下标,**不含**)= tailStart。
|
|
186
|
-
* sticky 重建的增量起点;写 `messages.length` 会把 tail 误算进覆盖 → 滑出后丢消息。
|
|
187
|
-
*/
|
|
188
|
-
coveredMessageCount?: number;
|
|
189
|
-
}
|
|
190
|
-
export interface AfterTurnParams {
|
|
203
|
+
export interface AfterStepParams {
|
|
191
204
|
sessionId: string;
|
|
192
205
|
/** E4: compact key component; engine state key falls back to sessionId when omitted */
|
|
193
206
|
agentId?: string;
|
|
194
207
|
/** 本轮消息 */
|
|
195
|
-
|
|
208
|
+
step: Message[];
|
|
196
209
|
/** 本轮 token 使用(cache-aware) */
|
|
197
|
-
usage?: import('@octopi-agent/core/types/
|
|
210
|
+
usage?: import('@octopi-agent/core/types/step.js').TokenUsage;
|
|
198
211
|
}
|
|
199
212
|
/**
|
|
200
213
|
* ContextEngine — 上下文管理引擎
|
|
@@ -206,11 +219,36 @@ export interface AfterTurnParams {
|
|
|
206
219
|
*
|
|
207
220
|
* 可选方法:
|
|
208
221
|
* - ingest(): 存储消息
|
|
209
|
-
* -
|
|
222
|
+
* - afterStep(): 更新状态(step 为**本轮增量**消息)
|
|
210
223
|
*
|
|
211
224
|
* 本域契约(@layer harness/context);Harness 提供 DefaultContextEngine。
|
|
212
225
|
*/
|
|
213
226
|
export interface ContextEngine {
|
|
227
|
+
/**
|
|
228
|
+
* 校准状态快照(可选,持久化配套):锚+样本计数导出——restore 后回填消除冷启动。
|
|
229
|
+
* @returns per-key 样本计数与锚
|
|
230
|
+
*/
|
|
231
|
+
exportCalibration?(): {
|
|
232
|
+
samples: Record<string, {
|
|
233
|
+
samples: number;
|
|
234
|
+
}>;
|
|
235
|
+
anchors: Record<string, {
|
|
236
|
+
actual: number;
|
|
237
|
+
raw: number;
|
|
238
|
+
modelKey: string;
|
|
239
|
+
}>;
|
|
240
|
+
};
|
|
241
|
+
/** 校准状态恢复(可选):importCalibration 配对使用 */
|
|
242
|
+
importCalibration?(data: {
|
|
243
|
+
samples?: Record<string, {
|
|
244
|
+
samples: number;
|
|
245
|
+
}>;
|
|
246
|
+
anchors?: Record<string, {
|
|
247
|
+
actual: number;
|
|
248
|
+
raw: number;
|
|
249
|
+
modelKey: string;
|
|
250
|
+
}>;
|
|
251
|
+
}): void;
|
|
214
252
|
readonly info: ContextEngineInfo;
|
|
215
253
|
/**
|
|
216
254
|
* 组装上下文
|
|
@@ -233,14 +271,15 @@ export interface ContextEngine {
|
|
|
233
271
|
*
|
|
234
272
|
* 用于更新内部统计、触发异步压缩等。
|
|
235
273
|
*/
|
|
236
|
-
|
|
274
|
+
afterStep?(params: AfterStepParams): Promise<void>;
|
|
237
275
|
}
|
|
238
276
|
export interface SelectResult {
|
|
239
|
-
/**
|
|
277
|
+
/** 要保留的消息。**身份契约**:必须是入参数组的同引用对象(转换记录按对象身份
|
|
278
|
+
* 把产物翻译回原始区间;返回拷贝会让翻译失锚) */
|
|
240
279
|
kept: Message[];
|
|
241
|
-
/**
|
|
280
|
+
/** 溢出的消息(需要压缩)。同上:同引用 */
|
|
242
281
|
overflow: Message[];
|
|
243
|
-
/**
|
|
282
|
+
/** 尾部保护的消息。同上:同引用 */
|
|
244
283
|
tail: Message[];
|
|
245
284
|
/** 尾部 token 数 */
|
|
246
285
|
tailTokens: number;
|
|
@@ -253,83 +292,54 @@ export interface SelectOptions {
|
|
|
253
292
|
maxTokens: number;
|
|
254
293
|
protectFirstN: number;
|
|
255
294
|
protectLastN: number;
|
|
256
|
-
}
|
|
257
|
-
export interface MessageSelector {
|
|
258
|
-
select(messages: Message[], options: SelectOptions, tokenEstimator?: TokenEstimator): SelectResult;
|
|
259
|
-
}
|
|
260
|
-
export interface CompressParams {
|
|
261
|
-
messages: Message[];
|
|
262
|
-
targetTokens: number;
|
|
263
|
-
previousSummary?: string;
|
|
264
|
-
summarize?: SummarizeFunction;
|
|
265
|
-
tokenEstimator?: TokenEstimator;
|
|
266
295
|
/**
|
|
267
|
-
*
|
|
268
|
-
* 也不得就此短路返回——必须尝试摘要级。主动摘要路径(applyProactiveCompact)使用:
|
|
269
|
-
* 否则压缩成功但永不产摘要,状态机的复用分支永远无法启用。
|
|
296
|
+
* 度量视图(可选):与 `messages` **等长同序**,只用于 token 估算。
|
|
270
297
|
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
298
|
+
* 存在的理由(尺子与作用域同源):实际请求发的是**老化视图**,而压缩必须吃
|
|
299
|
+
* **原文**(F-b)。若用原文估算,老化越有效误判越大——原文 middle 797k /
|
|
300
|
+
* 视图 76k 时会每请求判溢出、每请求触发一次摘要,把前缀缓存整段烧掉。
|
|
301
|
+
* 切分仍按 `messages`(原文),仅估算看这里。
|
|
274
302
|
*/
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* 缓存前缀:与会话 LLM 请求**同形**的 system+history(buildLlmMessages 产物)。
|
|
278
|
-
* 摘要请求只许在其**尾部**追加指令;禁止改 system / 历史字节——否则打穿 provider 前缀缓存。
|
|
279
|
-
*/
|
|
280
|
-
llmPrefix?: LLMMessage[];
|
|
281
|
-
/** 摘要软目标预算(P1c clamp(2%, 2k, 8k) 的可配置 ratio/min/max) */
|
|
282
|
-
summaryBudget?: {
|
|
283
|
-
ratioPct?: number;
|
|
284
|
-
minTokens?: number;
|
|
285
|
-
maxTokens?: number;
|
|
286
|
-
};
|
|
287
|
-
/** 折叠区间(评审 F7):交接书替换范围与原样保留尾部——计数语义 */
|
|
288
|
-
foldRange?: {
|
|
289
|
-
replacedCount: number;
|
|
290
|
-
total: number;
|
|
291
|
-
preservedTail: number;
|
|
292
|
-
};
|
|
293
|
-
/** task 快照(B0:易变块走 content 尾部,不进 system) */
|
|
294
|
-
taskSnapshot?: string;
|
|
295
|
-
/** 会话模型窗口/输出上限(评审 F5):摘要硬顶按窗口钳制 */
|
|
296
|
-
contextWindow?: number;
|
|
297
|
-
maxOutputTokens?: number;
|
|
298
|
-
/** 事件回调(F22:cache-miss 旁路可观测) */
|
|
299
|
-
emit?: (e: {
|
|
300
|
-
type: 'compact.summarize_fallback';
|
|
301
|
-
reason?: string;
|
|
302
|
-
cached?: boolean;
|
|
303
|
-
}) => void;
|
|
303
|
+
measureMessages?: Message[];
|
|
304
304
|
}
|
|
305
|
-
export interface
|
|
306
|
-
|
|
307
|
-
result: Message[];
|
|
308
|
-
/** 估算 token 数 */
|
|
309
|
-
estimatedTokens: number;
|
|
310
|
-
/** 本次产出**新的**语义摘要(评审 F8-F1):仅 true 时调用方才可推进覆盖点/previousSummary。
|
|
311
|
-
* 机械降级(截断/兜底/占位说明)必须显式 false——占位说明不得冒充语义摘要(fail-closed,F8R-01)。 */
|
|
312
|
-
fresh: boolean;
|
|
313
|
-
/** LLM 摘要调用是否真正发起过(成功/失败均算):只在 true 时推进冷却时间戳(F8R-01)。 */
|
|
314
|
-
summarizeAttempted: boolean;
|
|
315
|
-
/** 被丢弃的信息摘要 */
|
|
316
|
-
droppedSummary?: string;
|
|
317
|
-
}
|
|
318
|
-
export interface Compressor {
|
|
319
|
-
compress(params: CompressParams): Promise<CompressResult>;
|
|
305
|
+
export interface MessageSelector {
|
|
306
|
+
select(messages: Message[], options: SelectOptions, tokenEstimator?: TokenEstimator): SelectResult;
|
|
320
307
|
}
|
|
321
308
|
export interface BudgetAllocateParams {
|
|
322
309
|
/** 可用 token 预算;未知窗口时可省略(见 budget-allocator) */
|
|
323
310
|
tokenBudget?: number;
|
|
324
311
|
contextWindow?: number;
|
|
312
|
+
/**
|
|
313
|
+
* 模型单次输出上限(= 请求实际携带的 max_tokens 上界)。
|
|
314
|
+
* 提供且物理窗口已知时,按硬预留计入 `outputReserve`——这是
|
|
315
|
+
* `input + max_tokens ≤ contextWindow` 不变量的唯一保证。
|
|
316
|
+
* 窗口未知(仅有 compactTargetTokens 等策略目标)时忽略:目标不是物理边界。
|
|
317
|
+
*/
|
|
318
|
+
maxOutputTokens?: number;
|
|
325
319
|
systemPromptTokens: number;
|
|
326
320
|
toolTokens: number;
|
|
327
321
|
}
|
|
328
322
|
export interface BudgetAllocateResult {
|
|
329
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* 输入侧硬上限(不变量):`system + tools + messages ≤ inputLimit`。
|
|
325
|
+
* 恒有 `inputLimit + outputReserve ≤ effectiveLimit`。
|
|
326
|
+
*/
|
|
327
|
+
inputLimit: number;
|
|
328
|
+
/**
|
|
329
|
+
* 消息侧硬上限 = `inputLimit − system − tools − 请求信封`。
|
|
330
|
+
* `MessageSelector` / overflow 目标等**强制点**必须用这个值。
|
|
331
|
+
*/
|
|
332
|
+
messagesLimit: number;
|
|
333
|
+
/**
|
|
334
|
+
* 消息侧软目标(压缩策略提示值,≤ messagesLimit)。
|
|
335
|
+
* 触发压缩的阈值挂这里;它允许小于 messagesLimit(提前压缩),
|
|
336
|
+
* 但任何强制点不得用它当作边界。
|
|
337
|
+
*/
|
|
330
338
|
messagesBudget: number;
|
|
331
|
-
/** 预留给模型输出的 token */
|
|
339
|
+
/** 预留给模型输出的 token(有 maxOutputTokens 时即其值) */
|
|
332
340
|
outputReserve: number;
|
|
341
|
+
/** 预算不可行:固定开销 + 输出预留已吃掉窗口(messagesLimit ≤ 0) */
|
|
342
|
+
infeasible?: boolean;
|
|
333
343
|
}
|
|
334
344
|
export interface BudgetAllocator {
|
|
335
345
|
allocate(params: BudgetAllocateParams): BudgetAllocateResult;
|