@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
|
@@ -79,6 +79,7 @@ export function normalizeWisdomFormation(raw) {
|
|
|
79
79
|
const memoryIds = asStringArray(derived.memoryIds ?? o.memoryIds);
|
|
80
80
|
const conceptIds = asStringArray(derived.conceptIds ?? o.conceptIds);
|
|
81
81
|
const kind = parseKind(o.kind);
|
|
82
|
+
const supersedesId = asString(o.supersedesId) || undefined;
|
|
82
83
|
if (!statement || pts.length === 0) {
|
|
83
84
|
droppedNotes.push(`incomplete:${statement.slice(0, 24) || 'empty'}`);
|
|
84
85
|
continue;
|
|
@@ -87,7 +88,7 @@ export function normalizeWisdomFormation(raw) {
|
|
|
87
88
|
droppedNotes.push(`no_effect:${statement.slice(0, 24)}`);
|
|
88
89
|
continue;
|
|
89
90
|
}
|
|
90
|
-
if (memoryIds.length === 0 && conceptIds.length === 0) {
|
|
91
|
+
if (memoryIds.length === 0 && conceptIds.length === 0 && !supersedesId) {
|
|
91
92
|
droppedNotes.push(`no_derived:${statement.slice(0, 24)}`);
|
|
92
93
|
continue;
|
|
93
94
|
}
|
|
@@ -110,6 +111,7 @@ export function normalizeWisdomFormation(raw) {
|
|
|
110
111
|
? asStringArray(o.exceptions)
|
|
111
112
|
: undefined,
|
|
112
113
|
kind,
|
|
114
|
+
supersedesId,
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
return { items, droppedNotes };
|
|
@@ -163,54 +165,110 @@ export async function formAndAdmit(llmText, store, options) {
|
|
|
163
165
|
}
|
|
164
166
|
const { items, droppedNotes } = normalizeWisdomFormation(raw);
|
|
165
167
|
const maxItems = options?.maxItems ?? 3;
|
|
168
|
+
// M4:dryRun 与真实 admit 的查重口径一致(全部存活条目参与 duplicate/near-dup/对立)
|
|
169
|
+
const existing = options?.dryRun
|
|
170
|
+
? (await store.listForGovern()).filter((w) => w.status !== 'retired' && w.status !== 'superseded')
|
|
171
|
+
: undefined;
|
|
166
172
|
const results = [];
|
|
167
173
|
for (const item of items.slice(0, maxItems)) {
|
|
168
|
-
|
|
174
|
+
let allowedIds = options?.allowedMemoryIds;
|
|
175
|
+
if (item.supersedesId) {
|
|
176
|
+
// supersede 继承被取代者的溯源:已覆盖语料被排除出证据包后,「同源精炼」
|
|
177
|
+
// 的自然溯源不在白名单里——并入目标 derivedFrom,取代主路径才通
|
|
178
|
+
const target = await store.get(item.supersedesId);
|
|
179
|
+
const inherited = target?.derivedFrom?.memoryIds ?? [];
|
|
180
|
+
if (!item.memoryIds.length && inherited.length) {
|
|
181
|
+
item.memoryIds = [...inherited];
|
|
182
|
+
}
|
|
183
|
+
if (options?.allowedMemoryIds && inherited.length) {
|
|
184
|
+
allowedIds = new Set([...options.allowedMemoryIds, ...inherited]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const input = toAdmitWisdomInput(item, {
|
|
188
|
+
origin: options?.origin,
|
|
189
|
+
supersedesId: item.supersedesId,
|
|
190
|
+
});
|
|
169
191
|
if (options?.dryRun) {
|
|
170
192
|
const gate = evaluateWisdomGate(input, {
|
|
171
|
-
allowedMemoryIds:
|
|
193
|
+
allowedMemoryIds: allowedIds,
|
|
194
|
+
existing,
|
|
172
195
|
});
|
|
173
196
|
results.push(gate.ok
|
|
174
197
|
? { action: 'created', message: 'dry_run' }
|
|
175
198
|
: { action: 'rejected', reason: gate.reason, message: gate.message });
|
|
176
199
|
continue;
|
|
177
200
|
}
|
|
178
|
-
results.push(await store.admit(input, { allowedMemoryIds:
|
|
201
|
+
results.push(await store.admit(input, { allowedMemoryIds: allowedIds }));
|
|
179
202
|
}
|
|
180
203
|
return { results, droppedNotes };
|
|
181
204
|
}
|
|
182
205
|
// ── 场景匹配(P0 keyword;embedding/llm 留给后续,不假装已实现) ──
|
|
206
|
+
/** 场景词分段:按空白/标点/符号(含 。.!?-_ 等)切碎成长描述句的短语碎片(≥2 字),使「任务快照」「system」等片段可独立命中。 */
|
|
207
|
+
function segmentScenarioWord(w) {
|
|
208
|
+
return w
|
|
209
|
+
.split(/[\s\p{P}\p{S}\\]+/u)
|
|
210
|
+
.map((s) => s.trim())
|
|
211
|
+
.filter((s) => s.length >= 2);
|
|
212
|
+
}
|
|
183
213
|
/**
|
|
184
|
-
*
|
|
214
|
+
* 关键词/字面场景匹配分 + 全字面命中标记 + anti 排除标记。
|
|
215
|
+
*
|
|
216
|
+
* 匹配单位是**分段**(长描述句切短语后逐段匹配):任一段全字面命中记 2 分,
|
|
217
|
+
* 仅 2-gram 弱重叠记 1 分。fullHit = 存在长度 ≥3 的分段全字面命中——
|
|
218
|
+
* trial 的 scenario 入场券只认 fullHit(弱重叠不算,2 字通用词也不够格)。
|
|
219
|
+
*
|
|
220
|
+
* antiScenarios 是排除条件(误触发会静默丢范式),要求更强证据才触发:
|
|
221
|
+
* 整串命中,或长度 ≥3 的分段命中(2 字碎片歧义大,如「越权」不应压制修越权 bug 的任务)。
|
|
185
222
|
*
|
|
186
223
|
* @param entry - 条目
|
|
187
224
|
* @param text - 本轮查询/任务文本
|
|
188
|
-
* @returns [0,1]
|
|
225
|
+
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals ≥3 字分段全字面命中;excluded=anti 命中
|
|
189
226
|
*/
|
|
190
|
-
export function
|
|
227
|
+
export function scenarioMatchDetail(entry, text) {
|
|
191
228
|
const q = text.toLowerCase();
|
|
192
229
|
if (!q.trim())
|
|
193
|
-
return 0;
|
|
230
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
194
231
|
const anti = (entry.scenario.antiScenarios ?? []).map((s) => s.toLowerCase());
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
232
|
+
for (const a of anti) {
|
|
233
|
+
if (!a)
|
|
234
|
+
continue;
|
|
235
|
+
if (q.includes(a))
|
|
236
|
+
return { score: 0, fullHit: false, excluded: true };
|
|
237
|
+
if (segmentScenarioWord(a).some((seg) => seg.length >= 3 && q.includes(seg))) {
|
|
238
|
+
return { score: 0, fullHit: false, excluded: true };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const words = entry.scenario.problemTypes
|
|
242
|
+
.concat(entry.scenario.signals ?? [])
|
|
243
|
+
.flatMap((w) => segmentScenarioWord(w.toLowerCase()));
|
|
200
244
|
if (words.length === 0)
|
|
201
|
-
return 0;
|
|
245
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
202
246
|
let hit = 0;
|
|
247
|
+
let fullHit = false;
|
|
203
248
|
for (const w of words) {
|
|
204
249
|
if (!w)
|
|
205
250
|
continue;
|
|
206
|
-
if (q.includes(w))
|
|
251
|
+
if (q.includes(w)) {
|
|
207
252
|
hit += 2;
|
|
253
|
+
if (w.length >= 3)
|
|
254
|
+
fullHit = true;
|
|
255
|
+
}
|
|
208
256
|
else if (overlapChars(q, w))
|
|
209
257
|
hit += 1;
|
|
210
258
|
}
|
|
211
259
|
if (hit === 0)
|
|
212
|
-
return 0;
|
|
213
|
-
return Math.min(1, hit / (words.length * 2));
|
|
260
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
261
|
+
return { score: Math.min(1, hit / (words.length * 2)), fullHit, excluded: false };
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 关键词/字面场景匹配分。
|
|
265
|
+
*
|
|
266
|
+
* @param entry - 条目
|
|
267
|
+
* @param text - 本轮查询/任务文本
|
|
268
|
+
* @returns [0,1];无命中为 0
|
|
269
|
+
*/
|
|
270
|
+
export function scenarioMatchScore(entry, text) {
|
|
271
|
+
return scenarioMatchDetail(entry, text).score;
|
|
214
272
|
}
|
|
215
273
|
function overlapChars(q, w) {
|
|
216
274
|
// CJK 友好:词全字面出现在 q 已由 includes 覆盖;此处做 2-gram 弱重叠
|
|
@@ -223,18 +281,33 @@ function overlapChars(q, w) {
|
|
|
223
281
|
}
|
|
224
282
|
return false;
|
|
225
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* core 桶资格:宽覆盖(多 problemTypes 或 strengthened/factory);
|
|
286
|
+
* trial 永不进 core——未验证的假设只走场景匹配命中,不常驻刷屏。
|
|
287
|
+
*
|
|
288
|
+
* @param entry - 条目(状态已过 usable 过滤或可独立断言)
|
|
289
|
+
* @returns 是否可进 core 桶
|
|
290
|
+
*/
|
|
291
|
+
export function isCoreEligible(entry) {
|
|
292
|
+
if (entry.status === 'trial')
|
|
293
|
+
return false;
|
|
294
|
+
return (entry.origin === 'factory' ||
|
|
295
|
+
entry.status === 'strengthened' ||
|
|
296
|
+
entry.scenario.problemTypes.length >= 2);
|
|
297
|
+
}
|
|
226
298
|
/**
|
|
227
299
|
* 选择注入集:小核心 + 场景匹配。
|
|
228
300
|
*
|
|
229
301
|
* @param entries - 可注入条目(store 已滤状态)
|
|
230
302
|
* @param text - 本轮文本
|
|
231
|
-
* @param options -
|
|
303
|
+
* @param options - 条数硬顶;trialMaxItems 缺省 2(trial 轮转保底曝光,打破晋升死锁);includeTrial 缺省 true(trial 的意义就是被试用)
|
|
232
304
|
* @returns 排序后的注入选择
|
|
233
305
|
*/
|
|
234
306
|
export function pickForInjection(entries, text, options) {
|
|
235
307
|
const coreMax = options?.coreMaxItems ?? 8;
|
|
236
308
|
const scenarioMax = options?.scenarioMaxItems ?? 8;
|
|
237
|
-
const
|
|
309
|
+
const trialMax = options?.trialMaxItems ?? 2;
|
|
310
|
+
const includeTrial = options?.includeTrial ?? true;
|
|
238
311
|
const usable = entries.filter((e) => {
|
|
239
312
|
if (e.status === 'retired' || e.status === 'superseded' || e.status === 'candidate')
|
|
240
313
|
return false;
|
|
@@ -244,25 +317,46 @@ export function pickForInjection(entries, text, options) {
|
|
|
244
317
|
return false;
|
|
245
318
|
return true;
|
|
246
319
|
});
|
|
247
|
-
const scored = usable.map((e) =>
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
320
|
+
const scored = usable.map((e) => {
|
|
321
|
+
const m = scenarioMatchDetail(e, text);
|
|
322
|
+
return {
|
|
323
|
+
entry: e,
|
|
324
|
+
match: m.score,
|
|
325
|
+
fullHit: m.fullHit,
|
|
326
|
+
excluded: m.excluded,
|
|
327
|
+
score: wisdomInjectScore(e, 1),
|
|
328
|
+
scenarioScore: wisdomInjectScore(e, m.score),
|
|
329
|
+
};
|
|
330
|
+
});
|
|
254
331
|
const coreCandidates = scored
|
|
255
|
-
.filter((s) => s.entry
|
|
332
|
+
.filter((s) => isCoreEligible(s.entry))
|
|
256
333
|
.sort((a, b) => b.score - a.score)
|
|
257
334
|
.slice(0, coreMax)
|
|
258
335
|
.map((s) => ({ entry: s.entry, bucket: 'core', score: 1 }));
|
|
259
336
|
const coreIds = new Set(coreCandidates.map((c) => c.entry.id));
|
|
337
|
+
// scenario:trial 须全字面命中(bigram 弱重叠不算数——未验证假设不给模糊入场券)
|
|
260
338
|
const scenario = scored
|
|
261
|
-
.filter((s) => s.match > 0 &&
|
|
339
|
+
.filter((s) => s.match > 0 &&
|
|
340
|
+
(s.entry.status !== 'trial' || s.fullHit) &&
|
|
341
|
+
!coreIds.has(s.entry.id))
|
|
262
342
|
.sort((a, b) => b.scenarioScore - a.scenarioScore)
|
|
263
343
|
.slice(0, scenarioMax)
|
|
264
344
|
.map((s) => ({ entry: s.entry, bucket: 'scenario', score: s.match }));
|
|
265
|
-
|
|
345
|
+
// trial 轮转试用名额:trial 进不了 core、scenario 又只有全字面命中一张入场券,
|
|
346
|
+
// 没有保底曝光就攒不出场景命中、永不晋升(trial→active 需 applied≥3+assisted)。
|
|
347
|
+
// 轮转规则:最少被试用者优先(applied 升序),同分旧者先出(createdAt 升序),逐轮清队列。
|
|
348
|
+
// anti 命中的条目不轮转(范式自陈不适用的任务不硬塞);轮转注入不计 applied
|
|
349
|
+
//(applied 语义保持「场景命中被使用」,防曝光污染 contest/zero-apply 治理)。
|
|
350
|
+
const pickedIds = new Set([...coreIds, ...scenario.map((s) => s.entry.id)]);
|
|
351
|
+
const trialRotation = trialMax > 0
|
|
352
|
+
? scored
|
|
353
|
+
.filter((s) => s.entry.status === 'trial' && !pickedIds.has(s.entry.id) && !s.excluded)
|
|
354
|
+
.sort((a, b) => a.entry.outcomes.applied - b.entry.outcomes.applied ||
|
|
355
|
+
a.entry.createdAt - b.entry.createdAt)
|
|
356
|
+
.slice(0, trialMax)
|
|
357
|
+
.map((s) => ({ entry: s.entry, bucket: 'trial', score: s.match }))
|
|
358
|
+
: [];
|
|
359
|
+
return [...coreCandidates, ...scenario, ...trialRotation];
|
|
266
360
|
}
|
|
267
361
|
// ── 注入排版 ──
|
|
268
362
|
/**
|
|
@@ -278,18 +372,21 @@ export function formatWisdomBody(picks) {
|
|
|
278
372
|
for (const p of picks) {
|
|
279
373
|
const key = p.entry.scenario.problemTypes[0] ?? '通用';
|
|
280
374
|
const list = byType.get(key) ?? [];
|
|
281
|
-
list.push(p.entry);
|
|
375
|
+
list.push({ entry: p.entry, bucket: p.bucket });
|
|
282
376
|
byType.set(key, list);
|
|
283
377
|
}
|
|
284
378
|
const blocks = [];
|
|
379
|
+
blocks.push('> 归因:若某条范式实质影响了你的决策,可在回复中引用其 id(如 [wis_xxx])以便事后验证。');
|
|
285
380
|
for (const [type, list] of byType) {
|
|
286
|
-
const lines = list.map((e) => formatWisdomBullet(e));
|
|
381
|
+
const lines = list.map((e) => formatWisdomBullet(e.entry, e.bucket));
|
|
287
382
|
blocks.push(`## 面对「${type}」\n\n${lines.join('\n\n')}`);
|
|
288
383
|
}
|
|
289
384
|
return blocks.join('\n\n');
|
|
290
385
|
}
|
|
291
|
-
function formatWisdomBullet(e) {
|
|
292
|
-
|
|
386
|
+
function formatWisdomBullet(e, bucket) {
|
|
387
|
+
// trial 轮转注入的条目未经场景验证,显式标记供模型降权采信
|
|
388
|
+
const marker = bucket === 'trial' ? '[试用] ' : '';
|
|
389
|
+
const parts = [`- ${marker}[${e.id}] ${e.statement}`];
|
|
293
390
|
const effectBits = [];
|
|
294
391
|
if (e.effect.posture)
|
|
295
392
|
effectBits.push(`推理姿态:${e.effect.posture}`);
|
|
@@ -40,6 +40,20 @@ export declare function resolveInitialWisdomStatus(input: AdmitWisdomInput): Wis
|
|
|
40
40
|
* @returns 去标点空白的小写串
|
|
41
41
|
*/
|
|
42
42
|
export declare function normalizeStatement(s: string): string;
|
|
43
|
+
/** 近重复 bigram 相似度阈值(真实重复对标定:同主题对最高 0.38/中位 0.16,跨主题对最高 0.06) */
|
|
44
|
+
export declare const NEAR_DUPLICATE_RATIO = 0.3;
|
|
45
|
+
/**
|
|
46
|
+
* 近重复兜底:陈述文本 bigram 相似度 ≥ 阈值视为重度换词复述。
|
|
47
|
+
*
|
|
48
|
+
* 双方陈述都必须 ≥ NEAR_DUPLICATE_MIN_CHARS(短陈述公式化重叠不可判语义);
|
|
49
|
+
* 阈值取保守高位(0.30)——语义去重主责在 formation LLM,此启发宁可漏拦不可误杀。
|
|
50
|
+
*
|
|
51
|
+
* @param a - 新陈述
|
|
52
|
+
* @param b - 既有陈述
|
|
53
|
+
* @param threshold - 相似度阈值(缺省 NEAR_DUPLICATE_RATIO)
|
|
54
|
+
* @returns 是否疑似近重复
|
|
55
|
+
*/
|
|
56
|
+
export declare function looksNearDuplicate(a: string, b: string, threshold?: number): boolean;
|
|
43
57
|
/**
|
|
44
58
|
* 保守对立启发:同主题词重叠 + 互斥义务词。宁可漏拦,不可误杀。
|
|
45
59
|
*
|
|
@@ -110,24 +110,38 @@ export function evaluateWisdomGate(input, options) {
|
|
|
110
110
|
if (options?.existing?.length) {
|
|
111
111
|
const norm = normalizeStatement(statement);
|
|
112
112
|
for (const ex of options.existing) {
|
|
113
|
-
//
|
|
114
|
-
if (ex.status
|
|
113
|
+
// 已被取代/退役的条目不参与查重(继任者已接管其主题)
|
|
114
|
+
if (ex.status === 'superseded' || ex.status === 'retired')
|
|
115
115
|
continue;
|
|
116
116
|
const exNorm = normalizeStatement(ex.statement);
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
117
|
+
if (!input.supersedesId) {
|
|
118
|
+
// 查重覆盖全部存活条目(含 trial——distilled 出生即 trial,同主题重复的主战场)
|
|
119
|
+
if (exNorm === norm) {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
reason: 'duplicate_statement',
|
|
123
|
+
message: `dup_of=${ex.id}`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// 对立检测先于近重:同词面但义务互斥是矛盾而非重复(reason 要区分两种处置)。
|
|
127
|
+
// 维持只对已站稳的范式检测;trial 不因疑似对立挡新条(两条都未验证时留给试用裁决)。
|
|
128
|
+
if ((ex.status === 'active' || ex.status === 'strengthened') &&
|
|
129
|
+
looksOpposed(statement, ex.statement)) {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
reason: 'semantic_conflict',
|
|
133
|
+
message: `conflict_with=${ex.id}`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// 近重复兜底(bigram 相似度,阈值 0.30 经真实重复对标定:同主题最高 0.38、跨主题最高 0.06)。
|
|
137
|
+
// 语义去重主责在 formation LLM(证据包附库内范式清单),此处只拦重度换词复述。
|
|
138
|
+
if (looksNearDuplicate(statement, ex.statement)) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
reason: 'duplicate_statement',
|
|
142
|
+
message: `near_dup_of=${ex.id}`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
147
|
}
|
|
@@ -163,10 +177,36 @@ export function normalizeStatement(s) {
|
|
|
163
177
|
.trim();
|
|
164
178
|
}
|
|
165
179
|
const OPPOSITE_PAIRS = [
|
|
166
|
-
[/(必须|应该|应当)/, /(
|
|
167
|
-
[/(
|
|
168
|
-
[/(优先|先)/, /(
|
|
180
|
+
[/(必须|应该|应当)/, /(禁止|不得|不要|不应|不必|无需)/],
|
|
181
|
+
[/(禁止|不得|不要|不应|不必|无需)/, /(必须|应该|应当)/],
|
|
182
|
+
[/(优先|先)/, /(禁止|不得|不必)/],
|
|
169
183
|
];
|
|
184
|
+
/** 近重复 bigram 相似度阈值(真实重复对标定:同主题对最高 0.38/中位 0.16,跨主题对最高 0.06) */
|
|
185
|
+
export const NEAR_DUPLICATE_RATIO = 0.3;
|
|
186
|
+
/**
|
|
187
|
+
* 近重复 bigram 长度下限(归一化后的大约字符数)。
|
|
188
|
+
* 短陈述共享公式化开头(「先验证」「面对 X 时先问」)时相似度虚高(可达 1.0),
|
|
189
|
+
* 会误杀同模板不同判断的合法范式——短陈述只走字面全等查重。
|
|
190
|
+
*/
|
|
191
|
+
const NEAR_DUPLICATE_MIN_CHARS = 12;
|
|
192
|
+
/**
|
|
193
|
+
* 近重复兜底:陈述文本 bigram 相似度 ≥ 阈值视为重度换词复述。
|
|
194
|
+
*
|
|
195
|
+
* 双方陈述都必须 ≥ NEAR_DUPLICATE_MIN_CHARS(短陈述公式化重叠不可判语义);
|
|
196
|
+
* 阈值取保守高位(0.30)——语义去重主责在 formation LLM,此启发宁可漏拦不可误杀。
|
|
197
|
+
*
|
|
198
|
+
* @param a - 新陈述
|
|
199
|
+
* @param b - 既有陈述
|
|
200
|
+
* @param threshold - 相似度阈值(缺省 NEAR_DUPLICATE_RATIO)
|
|
201
|
+
* @returns 是否疑似近重复
|
|
202
|
+
*/
|
|
203
|
+
export function looksNearDuplicate(a, b, threshold = NEAR_DUPLICATE_RATIO) {
|
|
204
|
+
const na = normalizeStatement(a);
|
|
205
|
+
const nb = normalizeStatement(b);
|
|
206
|
+
if (na.length < NEAR_DUPLICATE_MIN_CHARS || nb.length < NEAR_DUPLICATE_MIN_CHARS)
|
|
207
|
+
return false;
|
|
208
|
+
return sharedBigramRatio(a, b) >= threshold;
|
|
209
|
+
}
|
|
170
210
|
/**
|
|
171
211
|
* 保守对立启发:同主题词重叠 + 互斥义务词。宁可漏拦,不可误杀。
|
|
172
212
|
*
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module harness/memory/wisdom
|
|
5
5
|
*/
|
|
6
|
-
import type { AdmitWisdomInput, AdmitWisdomResult, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomRetireReason, WisdomStats, WisdomStore, WisdomOutcomeEvent } from './types.js';
|
|
6
|
+
import type { AdmitWisdomInput, AdmitWisdomResult, WisdomAttributionWindow, WisdomAttributionWindowInput, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomRetireReason, WisdomStats, WisdomStore, WisdomOutcomeEvent } from './types.js';
|
|
7
7
|
export declare class InMemoryWisdomStore implements WisdomStore {
|
|
8
8
|
readonly name = "in-memory-wisdom";
|
|
9
9
|
private entries;
|
|
10
|
+
private windows;
|
|
10
11
|
private seq;
|
|
11
12
|
admit(input: AdmitWisdomInput, options?: {
|
|
12
13
|
allowedMemoryIds?: ReadonlySet<string>;
|
|
@@ -21,7 +22,11 @@ export declare class InMemoryWisdomStore implements WisdomStore {
|
|
|
21
22
|
by: string;
|
|
22
23
|
reason: WisdomRetireReason | string;
|
|
23
24
|
}): Promise<void>;
|
|
24
|
-
recordOutcomes(events: WisdomOutcomeEvent[]): Promise<void>;
|
|
25
|
+
recordOutcomes(events: WisdomOutcomeEvent[], config?: import('./wisdom-policy.js').WisdomEvaluationConfig): Promise<void>;
|
|
25
26
|
touchApplied(ids: string[]): Promise<void>;
|
|
27
|
+
recordAttributionWindow(input: WisdomAttributionWindowInput): Promise<string>;
|
|
28
|
+
listPendingWindows(limit?: number): Promise<WisdomAttributionWindow[]>;
|
|
29
|
+
markWindowsJudged(ids: string[], at?: number): Promise<string[]>;
|
|
30
|
+
pruneWindows(before: number): Promise<void>;
|
|
26
31
|
stats(): Promise<WisdomStats>;
|
|
27
32
|
}
|
|
@@ -10,6 +10,7 @@ import { pickForInjection } from './wisdom-formation.js';
|
|
|
10
10
|
export class InMemoryWisdomStore {
|
|
11
11
|
name = 'in-memory-wisdom';
|
|
12
12
|
entries = new Map();
|
|
13
|
+
windows = new Map();
|
|
13
14
|
seq = 0;
|
|
14
15
|
async admit(input, options) {
|
|
15
16
|
const existing = [...this.entries.values()]
|
|
@@ -34,6 +35,14 @@ export class InMemoryWisdomStore {
|
|
|
34
35
|
message: `supersedesId=${input.supersedesId}`,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
// 与 SqliteWisdomStore 同规:目标必须存活;factory 出厂预设不许炼制回路静默取代
|
|
39
|
+
if (prev.status === 'retired' || prev.status === 'superseded' || prev.origin === 'factory') {
|
|
40
|
+
return {
|
|
41
|
+
action: 'rejected',
|
|
42
|
+
reason: 'supersedes_target_invalid',
|
|
43
|
+
message: `supersedes_target=${prev.status}/${prev.origin}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
37
46
|
this.entries.set(prev.id, {
|
|
38
47
|
...prev,
|
|
39
48
|
status: 'superseded',
|
|
@@ -69,6 +78,7 @@ export class InMemoryWisdomStore {
|
|
|
69
78
|
return pickForInjection(entries, query.text ?? '', {
|
|
70
79
|
coreMaxItems: query.coreMaxItems,
|
|
71
80
|
scenarioMaxItems: query.scenarioMaxItems,
|
|
81
|
+
trialMaxItems: query.trialMaxItems,
|
|
72
82
|
includeTrial: query.includeTrial,
|
|
73
83
|
});
|
|
74
84
|
}
|
|
@@ -97,7 +107,7 @@ export class InMemoryWisdomStore {
|
|
|
97
107
|
exceptions: [...(cur.exceptions ?? []), `retired:${meta.reason}:${meta.by}`],
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
|
-
async recordOutcomes(events) {
|
|
110
|
+
async recordOutcomes(events, config) {
|
|
101
111
|
const byId = new Map();
|
|
102
112
|
for (const e of events) {
|
|
103
113
|
const list = byId.get(e.wisdomId) ?? [];
|
|
@@ -110,7 +120,7 @@ export class InMemoryWisdomStore {
|
|
|
110
120
|
continue;
|
|
111
121
|
const folded = foldOutcomeEvents(cur, evs);
|
|
112
122
|
let next = { ...cur, ...folded, updatedAt: Date.now() };
|
|
113
|
-
const plan = planConfidenceUpdate(next);
|
|
123
|
+
const plan = planConfidenceUpdate(next, config);
|
|
114
124
|
if (plan) {
|
|
115
125
|
next = {
|
|
116
126
|
...next,
|
|
@@ -151,6 +161,43 @@ export class InMemoryWisdomStore {
|
|
|
151
161
|
});
|
|
152
162
|
}
|
|
153
163
|
}
|
|
164
|
+
async recordAttributionWindow(input) {
|
|
165
|
+
const id = `waw_${++this.seq}`;
|
|
166
|
+
this.windows.set(id, {
|
|
167
|
+
...input,
|
|
168
|
+
injectedIds: [...input.injectedIds],
|
|
169
|
+
citations: input.citations.map((c) => ({ ...c })),
|
|
170
|
+
id,
|
|
171
|
+
createdAt: Date.now(),
|
|
172
|
+
});
|
|
173
|
+
return id;
|
|
174
|
+
}
|
|
175
|
+
async listPendingWindows(limit) {
|
|
176
|
+
const pending = [...this.windows.values()]
|
|
177
|
+
.filter((w) => w.judgedAt === undefined)
|
|
178
|
+
.sort((a, b) => a.createdAt - b.createdAt);
|
|
179
|
+
// 缺省上限 500(与 Sqlite 对齐,防 pending 无界增长拖垮判官)
|
|
180
|
+
return pending.slice(0, limit && limit > 0 ? limit : 500);
|
|
181
|
+
}
|
|
182
|
+
async markWindowsJudged(ids, at) {
|
|
183
|
+
const now = at ?? Date.now();
|
|
184
|
+
const newlyJudged = [];
|
|
185
|
+
for (const id of ids) {
|
|
186
|
+
const w = this.windows.get(id);
|
|
187
|
+
// 只有真正置上的才算本次标记(跨进程幂等:他方先标则不发事件)
|
|
188
|
+
if (!w || w.judgedAt !== undefined)
|
|
189
|
+
continue;
|
|
190
|
+
w.judgedAt = now;
|
|
191
|
+
newlyJudged.push(id);
|
|
192
|
+
}
|
|
193
|
+
return newlyJudged;
|
|
194
|
+
}
|
|
195
|
+
async pruneWindows(before) {
|
|
196
|
+
for (const [id, w] of this.windows) {
|
|
197
|
+
if (w.judgedAt !== undefined && w.judgedAt < before)
|
|
198
|
+
this.windows.delete(id);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
154
201
|
async stats() {
|
|
155
202
|
const list = [...this.entries.values()];
|
|
156
203
|
const byStatus = Object.fromEntries(WISDOM_STATUSES.map((s) => [s, 0]));
|
|
@@ -52,8 +52,8 @@ const TIMELINE_TYPES = new Set([
|
|
|
52
52
|
'engine.error',
|
|
53
53
|
// 模型重试:排查「为什么等了这么久」时,时间线必须能看出重试发生与次数
|
|
54
54
|
'engine.model_retry',
|
|
55
|
-
'
|
|
56
|
-
'
|
|
55
|
+
'step.start',
|
|
56
|
+
'step.end',
|
|
57
57
|
'tool.exec.start',
|
|
58
58
|
'tool.exec.end',
|
|
59
59
|
'budget.exceeded',
|
|
@@ -63,6 +63,11 @@ const TIMELINE_TYPES = new Set([
|
|
|
63
63
|
'context.compact.end',
|
|
64
64
|
'context.compact.error',
|
|
65
65
|
'context.compact.summarize_fallback',
|
|
66
|
+
// m-2:progress 必须落 timeline——manual/慢请求的「已发出多少、等了多久」是
|
|
67
|
+
// 卡死归因的唯一线索(丢弃 = 观测静默失明)
|
|
68
|
+
'context.compact.progress',
|
|
69
|
+
// P3 红线 7:overflow 症状告警(proactive 失效 / 配置漂移缺失)——罕见异常信号必须落 timeline
|
|
70
|
+
'context.overflow.alert',
|
|
66
71
|
'context.layers.assembled',
|
|
67
72
|
'persona.resolve.failed',
|
|
68
73
|
'injection.detected',
|
|
@@ -191,7 +196,7 @@ export class ObserverHub {
|
|
|
191
196
|
? endedAt - record.lifecycle.startedAt
|
|
192
197
|
: undefined,
|
|
193
198
|
// timeline 事件缺失时从 Guard / messages 摘要回填,避免面板全空
|
|
194
|
-
|
|
199
|
+
steps: record.lifecycle.steps ?? g?.steps,
|
|
195
200
|
toolCalls: record.lifecycle.toolCalls ?? g?.totalToolCalls,
|
|
196
201
|
};
|
|
197
202
|
if (input.messages && this.config.channels['run.messages']) {
|
|
@@ -207,8 +212,8 @@ export class ObserverHub {
|
|
|
207
212
|
if (built.cloned) {
|
|
208
213
|
record.messageClones = { ...record.messageClones, final: built.cloned };
|
|
209
214
|
}
|
|
210
|
-
if (record.lifecycle.
|
|
211
|
-
record.lifecycle.
|
|
215
|
+
if (record.lifecycle.steps == null && record.guardMetrics?.steps != null) {
|
|
216
|
+
record.lifecycle.steps = record.guardMetrics.steps;
|
|
212
217
|
}
|
|
213
218
|
if (record.lifecycle.toolCalls == null && record.guardMetrics?.totalToolCalls != null) {
|
|
214
219
|
record.lifecycle.toolCalls = record.guardMetrics.totalToolCalls;
|
|
@@ -473,8 +478,8 @@ export class ObserverHub {
|
|
|
473
478
|
}
|
|
474
479
|
}
|
|
475
480
|
const life = record.lifecycle;
|
|
476
|
-
if (event.type === '
|
|
477
|
-
life.
|
|
481
|
+
if (event.type === 'step.end') {
|
|
482
|
+
life.steps = (life.steps ?? 0) + 1;
|
|
478
483
|
}
|
|
479
484
|
else if (event.type === 'tool.exec.end') {
|
|
480
485
|
life.toolCalls = (life.toolCalls ?? 0) + 1;
|
|
@@ -616,7 +621,7 @@ export class ObserverHub {
|
|
|
616
621
|
}
|
|
617
622
|
else if (d?.usageLedger) {
|
|
618
623
|
record.guardMetrics = {
|
|
619
|
-
|
|
624
|
+
steps: 0,
|
|
620
625
|
totalToolCalls: 0,
|
|
621
626
|
nominalTotalTokens: 0,
|
|
622
627
|
elapsedMs: 0,
|
|
@@ -636,7 +641,7 @@ export class ObserverHub {
|
|
|
636
641
|
if (event.type === 'budget.wrap_up') {
|
|
637
642
|
const d = event.data;
|
|
638
643
|
record.guardMetrics = {
|
|
639
|
-
|
|
644
|
+
steps: record.guardMetrics?.steps ?? 0,
|
|
640
645
|
totalToolCalls: record.guardMetrics?.totalToolCalls ?? 0,
|
|
641
646
|
nominalTotalTokens: record.guardMetrics?.nominalTotalTokens ?? 0,
|
|
642
647
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
@@ -651,13 +656,13 @@ export class ObserverHub {
|
|
|
651
656
|
...record.guardMetrics,
|
|
652
657
|
wrapUpActive: true,
|
|
653
658
|
wrapUpReason: d.reason,
|
|
654
|
-
|
|
659
|
+
wrapUpStepsRemaining: d.stepsRemaining,
|
|
655
660
|
};
|
|
656
661
|
}
|
|
657
662
|
if (event.type === 'budget.exceeded') {
|
|
658
663
|
const reason = event.data?.reason;
|
|
659
664
|
record.guardMetrics = {
|
|
660
|
-
|
|
665
|
+
steps: 0,
|
|
661
666
|
totalToolCalls: record.lifecycle.toolCalls ?? 0,
|
|
662
667
|
nominalTotalTokens: 0,
|
|
663
668
|
elapsedMs: record.lifecycle.durationMs ?? 0,
|
|
@@ -676,7 +681,7 @@ export class ObserverHub {
|
|
|
676
681
|
else if (event.type === 'run_guard.stopped') {
|
|
677
682
|
const reason = event.data?.reason;
|
|
678
683
|
record.guardMetrics = {
|
|
679
|
-
|
|
684
|
+
steps: record.guardMetrics?.steps ?? 0,
|
|
680
685
|
totalToolCalls: record.guardMetrics?.totalToolCalls ?? 0,
|
|
681
686
|
nominalTotalTokens: record.guardMetrics?.nominalTotalTokens ?? 0,
|
|
682
687
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
@@ -695,7 +700,7 @@ export class ObserverHub {
|
|
|
695
700
|
else if (event.type === 'run_guard.recovered') {
|
|
696
701
|
const d = event.data;
|
|
697
702
|
record.guardMetrics = {
|
|
698
|
-
|
|
703
|
+
steps: record.guardMetrics?.steps ?? 0,
|
|
699
704
|
totalToolCalls: record.guardMetrics?.totalToolCalls ?? 0,
|
|
700
705
|
nominalTotalTokens: record.guardMetrics?.nominalTotalTokens ?? 0,
|
|
701
706
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
@@ -797,7 +802,7 @@ export class ObserverHub {
|
|
|
797
802
|
const g = record.guardMetrics;
|
|
798
803
|
const lifecycle = {
|
|
799
804
|
...record.lifecycle,
|
|
800
|
-
|
|
805
|
+
steps: record.lifecycle.steps ?? g?.steps,
|
|
801
806
|
toolCalls: record.lifecycle.toolCalls ?? g?.totalToolCalls,
|
|
802
807
|
durationMs: record.lifecycle.durationMs ?? g?.elapsedMs,
|
|
803
808
|
};
|
|
@@ -936,7 +941,10 @@ function stripLayerPayload(snapshot, payload) {
|
|
|
936
941
|
}
|
|
937
942
|
function toTimelineNode(event) {
|
|
938
943
|
const data = (event.data ?? {});
|
|
939
|
-
//
|
|
944
|
+
// P3 告警可见性:symptom/message 原样带出(红线 7 展示层不得只剩裸 type)
|
|
945
|
+
const symptom = typeof data.symptom === 'string' ? data.symptom : undefined;
|
|
946
|
+
const message = typeof data.message === 'string' ? data.message : undefined;
|
|
947
|
+
// F3 计时段:step.end 带 llmTiming(LLM 调用计时);run.timing 带 wait/build/run_end 分段
|
|
940
948
|
const timing = data.llmTiming ??
|
|
941
949
|
(event.type === 'run.timing'
|
|
942
950
|
? {
|
|
@@ -962,5 +970,7 @@ function toTimelineNode(event) {
|
|
|
962
970
|
reason: (data.reason ?? data.fallbackError),
|
|
963
971
|
usage: data.usage,
|
|
964
972
|
timing,
|
|
973
|
+
symptom,
|
|
974
|
+
message,
|
|
965
975
|
};
|
|
966
976
|
}
|