@octopi-agent/engine 0.98.4 → 0.121.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/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +6 -2
- package/dist/config-admin/index.js +3 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +71 -0
- package/dist/config-admin/onboarding-apply.js +235 -0
- package/dist/config-admin/onboarding.d.ts +154 -0
- package/dist/config-admin/onboarding.js +270 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +40 -6
- package/dist/config-schema/agent.js +44 -6
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +12 -37
- package/dist/config-schema/context.js +10 -31
- package/dist/config-schema/engine.d.ts +140 -164
- package/dist/config-schema/engine.js +10 -7
- package/dist/config-schema/governance.d.ts +20 -2
- package/dist/config-schema/governance.js +18 -3
- package/dist/config-schema/models.d.ts +10 -12
- package/dist/config-schema/models.js +16 -3
- package/dist/config-schema/run.d.ts +6 -2
- package/dist/config-schema/run.js +12 -2
- package/dist/config-schema/shared.d.ts +1 -3
- package/dist/config-schema/shared.js +4 -4
- package/dist/config-schema/substrate.d.ts +19 -88
- package/dist/config-schema/substrate.js +30 -107
- package/dist/config.d.ts +161 -123
- package/dist/config.js +109 -7
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +11 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +130 -31
- package/dist/harness/activation/types.d.ts +20 -3
- package/dist/harness/agent/builder.d.ts +36 -3
- package/dist/harness/agent/builder.js +206 -46
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +24 -5
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +13 -3
- package/dist/harness/agent/wire-agent-builder.js +35 -9
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- 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/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +2 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +14 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +50 -41
- 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/executor.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +7 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +10 -1
- package/dist/harness/collaboration/delegation/child-run.js +38 -6
- 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/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +11 -4
- package/dist/harness/collaboration/delegation/service.js +35 -13
- package/dist/harness/collaboration/delegation/store.d.ts +4 -0
- package/dist/harness/collaboration/delegation/store.js +3 -1
- package/dist/harness/collaboration/delegation/types.d.ts +34 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +12 -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 +44 -11
- package/dist/harness/context/capabilities/compact/engine.js +296 -160
- 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 +7 -2
- package/dist/harness/context/capabilities/compact/index.js +5 -1
- 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 +134 -19
- 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/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +19 -6
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +243 -0
- package/dist/harness/context/default-context-engine.d.ts +290 -120
- package/dist/harness/context/default-context-engine.js +1555 -764
- package/dist/harness/context/index.d.ts +3 -2
- package/dist/harness/context/index.js +2 -1
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +72 -0
- package/dist/harness/context/layer-types.js +87 -2
- package/dist/harness/context/layers.d.ts +17 -15
- package/dist/harness/context/layers.js +54 -17
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +27 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +7 -3
- 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 +109 -16
- package/dist/harness/context/tool-result-aging.js +220 -55
- 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 +196 -119
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- 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/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +28 -2
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/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/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +223 -222
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +218 -203
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +78 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +80 -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 +57 -114
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +279 -282
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +46 -484
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +123 -345
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +50 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +144 -20
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +17 -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/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +36 -8
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/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 +19 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/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/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +17 -15
- package/dist/harness/index.js +9 -9
- package/dist/harness/knowledge/boot-config.d.ts +57 -0
- package/dist/harness/knowledge/boot-config.js +52 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +77 -9
- package/dist/harness/knowledge/client.js +95 -24
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +112 -41
- 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 +11 -7
- package/dist/harness/knowledge/grounding.js +7 -2
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +117 -25
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- 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 +5 -3
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +25 -4
- package/dist/harness/knowledge/query-service.js +79 -43
- package/dist/harness/knowledge/query-worker-client.d.ts +14 -2
- package/dist/harness/knowledge/query-worker-client.js +8 -3
- package/dist/harness/knowledge/query-worker.js +9 -5
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +14 -3
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +14 -8
- package/dist/harness/knowledge/serve.js +14 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +323 -74
- package/dist/harness/knowledge/start-service-process.d.ts +41 -14
- package/dist/harness/knowledge/start-service-process.js +67 -96
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +55 -11
- package/dist/harness/knowledge/writer-service.js +200 -30
- package/dist/harness/knowledge/writer-worker-client.d.ts +19 -11
- package/dist/harness/knowledge/writer-worker-client.js +40 -5
- package/dist/harness/knowledge/writer-worker.js +20 -5
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +24 -6
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +120 -17
- 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 +67 -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/concurrency/tool-validator.js +4 -3
- 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 +32 -4
- package/dist/harness/run/reliability/run-agent.js +216 -63
- 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-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +48 -4
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +181 -39
- package/dist/harness/run/runner.js +654 -119
- 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/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +11 -15
- package/dist/harness/shared/events/agent-event-map.d.ts +75 -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/types/agent-definition.d.ts +7 -2
- package/dist/index.d.ts +16 -18
- package/dist/index.js +9 -10
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/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-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +41 -3
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +48 -2
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +57 -3
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +20 -2
- package/dist/integration/storage/archive-manager.js +34 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +10 -1
- package/dist/integration/storage/jsonl.js +155 -54
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +4 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +14 -15
- 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
|
@@ -50,6 +50,10 @@ export class SqliteMemoryStore {
|
|
|
50
50
|
// sqlite-vec 已加载时建/验 vec 表;auto 且扩展未加载则保持 false,走 JS hybrid
|
|
51
51
|
if (db.sqliteVecEnabled || this.vectorEngine === 'sqlite-vec') {
|
|
52
52
|
this.vecReady = ensureMemoryVecTable(db.raw, dims);
|
|
53
|
+
// require 档(vectorEngine='sqlite-vec')覆盖建表失败:不许静默退回 JS(M4)
|
|
54
|
+
if (!this.vecReady && this.vectorEngine === 'sqlite-vec') {
|
|
55
|
+
throw new Error("sqlite_vec_table_failed: memory_vec table creation failed under vectorEngine='sqlite-vec'");
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* sqlite-vec 集成 — 可选原生向量索引
|
|
3
3
|
*
|
|
4
|
-
* 扩展未安装或加载失败时返回 false
|
|
4
|
+
* 扩展未安装或加载失败时返回 false;降级/拒启语义由 loadSqliteVecOrDegrade 统一处理。
|
|
5
5
|
* 向量同时冗余写入 memories.embedding(JSON),便于审计与引擎切换。
|
|
6
6
|
*/
|
|
7
7
|
/** 记忆向量虚拟表名 */
|
|
@@ -43,3 +43,26 @@ export declare function searchMemoryVectors(db: any, queryVec: number[], k: numb
|
|
|
43
43
|
* 同步 memories.embedding 列到 vec 表(单条)。
|
|
44
44
|
*/
|
|
45
45
|
export declare function syncMemoryVectorFromBlob(db: any, memoryId: string, embeddingJson: string | null): boolean;
|
|
46
|
+
/** sqlite-vec 加载请求(建库点选项;false = 显式不加载) */
|
|
47
|
+
export type SqliteVecOption = boolean | {
|
|
48
|
+
extensionPath?: string;
|
|
49
|
+
require?: boolean;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* vectorEngine 模式 → sqlite-vec 加载请求(配置边界单源换算;各 hop 只透传选项)。
|
|
53
|
+
*
|
|
54
|
+
* @param mode - 'auto'(默认)=尝试加载、失败显式降级;'js'=不加载;'sqlite-vec'=必须加载成功
|
|
55
|
+
* @param extensionPath - 可选显式扩展路径(缺省用 npm 包内置二进制)
|
|
56
|
+
* @returns 加载请求;'js' 返回 false
|
|
57
|
+
*/
|
|
58
|
+
export declare function sqliteVecOption(mode?: 'auto' | 'js' | 'sqlite-vec', extensionPath?: string): SqliteVecOption;
|
|
59
|
+
/**
|
|
60
|
+
* 加载 sqlite-vec 并统一降级语义(所有建库点的唯一入口)。
|
|
61
|
+
*
|
|
62
|
+
* @param db - node:sqlite DatabaseSync
|
|
63
|
+
* @param option - 加载请求(false / undefined = 不加载)
|
|
64
|
+
* @param label - 库标签(用于错误/告警,如 'knowledge.db')
|
|
65
|
+
* @returns 是否加载成功
|
|
66
|
+
* @throws `require` 且加载失败时抛 `sqlite_vec_load_failed`(fail-loud)
|
|
67
|
+
*/
|
|
68
|
+
export declare function loadSqliteVecOrDegrade(db: unknown, option: SqliteVecOption | undefined, label: string): Promise<boolean>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* sqlite-vec 集成 — 可选原生向量索引
|
|
3
3
|
*
|
|
4
|
-
* 扩展未安装或加载失败时返回 false
|
|
4
|
+
* 扩展未安装或加载失败时返回 false;降级/拒启语义由 loadSqliteVecOrDegrade 统一处理。
|
|
5
5
|
* 向量同时冗余写入 memories.embedding(JSON),便于审计与引擎切换。
|
|
6
6
|
*/
|
|
7
7
|
/** 记忆向量虚拟表名 */
|
|
@@ -157,3 +157,39 @@ export function syncMemoryVectorFromBlob(db, memoryId, embeddingJson) {
|
|
|
157
157
|
return false;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* vectorEngine 模式 → sqlite-vec 加载请求(配置边界单源换算;各 hop 只透传选项)。
|
|
162
|
+
*
|
|
163
|
+
* @param mode - 'auto'(默认)=尝试加载、失败显式降级;'js'=不加载;'sqlite-vec'=必须加载成功
|
|
164
|
+
* @param extensionPath - 可选显式扩展路径(缺省用 npm 包内置二进制)
|
|
165
|
+
* @returns 加载请求;'js' 返回 false
|
|
166
|
+
*/
|
|
167
|
+
export function sqliteVecOption(mode, extensionPath) {
|
|
168
|
+
if (mode === 'js')
|
|
169
|
+
return false;
|
|
170
|
+
return { ...(extensionPath ? { extensionPath } : {}), require: mode === 'sqlite-vec' };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 加载 sqlite-vec 并统一降级语义(所有建库点的唯一入口)。
|
|
174
|
+
*
|
|
175
|
+
* @param db - node:sqlite DatabaseSync
|
|
176
|
+
* @param option - 加载请求(false / undefined = 不加载)
|
|
177
|
+
* @param label - 库标签(用于错误/告警,如 'knowledge.db')
|
|
178
|
+
* @returns 是否加载成功
|
|
179
|
+
* @throws `require` 且加载失败时抛 `sqlite_vec_load_failed`(fail-loud)
|
|
180
|
+
*/
|
|
181
|
+
export async function loadSqliteVecOrDegrade(db, option, label) {
|
|
182
|
+
if (option === false || option === undefined)
|
|
183
|
+
return false;
|
|
184
|
+
const extensionPath = typeof option === 'object' ? option.extensionPath : undefined;
|
|
185
|
+
const required = typeof option === 'object' && option.require === true;
|
|
186
|
+
const loaded = await tryLoadSqliteVec(db, extensionPath);
|
|
187
|
+
if (!loaded) {
|
|
188
|
+
if (required) {
|
|
189
|
+
throw new Error(`sqlite_vec_load_failed: vectorEngine='sqlite-vec' but the sqlite-vec extension failed to load for ${label} — check the sqlite-vec npm package / models.embedding.sqliteVecExtensionPath`);
|
|
190
|
+
}
|
|
191
|
+
// 显式降级(不静默):大库会退化为 JS 邻桶扫描(docs/KNOWN-ISSUES.md)
|
|
192
|
+
console.warn(`[octopi] ${label}: sqlite-vec unavailable — falling back to the JS vector path; large corpora will degrade`);
|
|
193
|
+
}
|
|
194
|
+
return loaded;
|
|
195
|
+
}
|
|
@@ -31,6 +31,15 @@ export class SqliteWisdomStore {
|
|
|
31
31
|
const now = Date.now();
|
|
32
32
|
const status = resolveInitialWisdomStatus(input);
|
|
33
33
|
const id = AgentDatabase.generateId('wis');
|
|
34
|
+
const insertRow = () => {
|
|
35
|
+
this.db.raw
|
|
36
|
+
.prepare(`INSERT INTO wisdom (
|
|
37
|
+
id, statement, rationale, scenario_json, effect_json, status, confidence, priority,
|
|
38
|
+
derived_from_json, exceptions_json, counterevidence_json, outcomes_json,
|
|
39
|
+
origin, kind, superseded_by, created_at, updated_at
|
|
40
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
41
|
+
.run(id, input.statement.trim(), input.rationale?.trim() || null, JSON.stringify(input.scenario), JSON.stringify(input.effect), status, clamp01(input.confidence ?? defaultConfidence(status, input.origin ?? 'distilled')), input.priority ?? defaultPriority(status, input.origin ?? 'distilled'), JSON.stringify(input.derivedFrom), JSON.stringify(input.exceptions ?? []), JSON.stringify([]), JSON.stringify(emptyOutcomes()), input.origin ?? 'distilled', input.kind, null, now, now);
|
|
42
|
+
};
|
|
34
43
|
if (input.supersedesId) {
|
|
35
44
|
const prev = this.getSync(input.supersedesId);
|
|
36
45
|
if (!prev) {
|
|
@@ -40,17 +49,32 @@ export class SqliteWisdomStore {
|
|
|
40
49
|
message: `supersedesId=${input.supersedesId}`,
|
|
41
50
|
};
|
|
42
51
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
// 取代目标必须存活(retired/superseded 已退出主题);factory 是人格级预设,
|
|
53
|
+
// 只经人工通道更换,不许炼制回路静默取代(否则 govern 的出厂保护被绕过)
|
|
54
|
+
if (prev.status === 'retired' || prev.status === 'superseded' || prev.origin === 'factory') {
|
|
55
|
+
return {
|
|
56
|
+
action: 'rejected',
|
|
57
|
+
reason: 'supersedes_target_invalid',
|
|
58
|
+
message: `supersedes_target=${prev.status}/${prev.origin}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// 旧条目改写与新条目写入同事务:避免 INSERT 失败留下「已 superseded 但无继任者」悬挂链
|
|
62
|
+
this.db.raw.exec('BEGIN IMMEDIATE');
|
|
63
|
+
try {
|
|
64
|
+
this.db.raw
|
|
65
|
+
.prepare(`UPDATE wisdom SET status = 'superseded', superseded_by = ?, updated_at = ? WHERE id = ?`)
|
|
66
|
+
.run(id, now, prev.id);
|
|
67
|
+
insertRow();
|
|
68
|
+
this.db.raw.exec('COMMIT');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
this.db.raw.exec('ROLLBACK');
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
insertRow();
|
|
46
77
|
}
|
|
47
|
-
this.db.raw
|
|
48
|
-
.prepare(`INSERT INTO wisdom (
|
|
49
|
-
id, statement, rationale, scenario_json, effect_json, status, confidence, priority,
|
|
50
|
-
derived_from_json, exceptions_json, counterevidence_json, outcomes_json,
|
|
51
|
-
origin, kind, superseded_by, created_at, updated_at
|
|
52
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
53
|
-
.run(id, input.statement.trim(), input.rationale?.trim() || null, JSON.stringify(input.scenario), JSON.stringify(input.effect), status, clamp01(input.confidence ?? defaultConfidence(status, input.origin ?? 'distilled')), input.priority ?? defaultPriority(status, input.origin ?? 'distilled'), JSON.stringify(input.derivedFrom), JSON.stringify(input.exceptions ?? []), JSON.stringify([]), JSON.stringify(emptyOutcomes()), input.origin ?? 'distilled', input.kind, null, now, now);
|
|
54
78
|
return {
|
|
55
79
|
action: input.supersedesId ? 'superseded' : 'created',
|
|
56
80
|
id,
|
|
@@ -68,6 +92,7 @@ export class SqliteWisdomStore {
|
|
|
68
92
|
return pickForInjection(entries, query.text ?? '', {
|
|
69
93
|
coreMaxItems: query.coreMaxItems,
|
|
70
94
|
scenarioMaxItems: query.scenarioMaxItems,
|
|
95
|
+
trialMaxItems: query.trialMaxItems,
|
|
71
96
|
includeTrial: query.includeTrial,
|
|
72
97
|
});
|
|
73
98
|
}
|
|
@@ -206,7 +206,7 @@ export interface WisdomEntry {
|
|
|
206
206
|
updatedAt: number;
|
|
207
207
|
}
|
|
208
208
|
/** 出生门控 reason */
|
|
209
|
-
export type WisdomGateReason = 'ok' | 'empty_statement' | 'statement_too_long' | 'empty_problem_types' | 'empty_effect' | 'secret_like' | 'persona_overwrite' | 'insufficient_support' | 'duplicate_statement' | 'semantic_conflict' | 'capacity_admit_stop' | 'invalid_status' | 'invalid_origin' | 'invalid_kind' | 'missing_derived_from' | 'unknown_derived_id' | 'supersedes_target_missing';
|
|
209
|
+
export type WisdomGateReason = 'ok' | 'empty_statement' | 'statement_too_long' | 'empty_problem_types' | 'empty_effect' | 'secret_like' | 'persona_overwrite' | 'insufficient_support' | 'duplicate_statement' | 'semantic_conflict' | 'capacity_admit_stop' | 'invalid_status' | 'invalid_origin' | 'invalid_kind' | 'missing_derived_from' | 'unknown_derived_id' | 'supersedes_target_missing' | 'supersedes_target_invalid';
|
|
210
210
|
export interface WisdomGateOutcome {
|
|
211
211
|
ok: boolean;
|
|
212
212
|
reason: WisdomGateReason;
|
|
@@ -244,14 +244,16 @@ export interface WisdomInjectQuery {
|
|
|
244
244
|
coreMaxItems?: number;
|
|
245
245
|
/** 场景条数硬顶 */
|
|
246
246
|
scenarioMaxItems?: number;
|
|
247
|
+
/** trial 轮转试用名额硬顶(默认 2——保证 trial 有机会积累 applied 以晋升;0 关闭轮转) */
|
|
248
|
+
trialMaxItems?: number;
|
|
247
249
|
/** 是否包含 trial(默认 true——trial 的意义就是被试用;显式 false 只注入已站稳条目) */
|
|
248
250
|
includeTrial?: boolean;
|
|
249
251
|
}
|
|
250
252
|
export interface WisdomInjectPick {
|
|
251
253
|
entry: WisdomEntry;
|
|
252
|
-
/** core = 常备小核心;scenario =
|
|
253
|
-
bucket: 'core' | 'scenario';
|
|
254
|
-
/** 场景匹配分(core 为 1) */
|
|
254
|
+
/** core = 常备小核心;scenario = 本轮匹配;trial = 轮转试用名额 */
|
|
255
|
+
bucket: 'core' | 'scenario' | 'trial';
|
|
256
|
+
/** 场景匹配分(core 为 1;trial 轮转为场景分,可为 0) */
|
|
255
257
|
score: number;
|
|
256
258
|
}
|
|
257
259
|
export type WisdomOutcomeSignal = 'applied' | 'cited' | 'assisted' | 'contested' | 'ignored';
|
|
@@ -366,7 +368,7 @@ export interface ConceptNode {
|
|
|
366
368
|
description?: string;
|
|
367
369
|
frequency: number;
|
|
368
370
|
memoryIds: string[];
|
|
369
|
-
/**
|
|
371
|
+
/** 论域标签(多值;不参与义项判定——义项只看 kind,合并时取并集) */
|
|
370
372
|
domain: string[];
|
|
371
373
|
status: ConceptStatus;
|
|
372
374
|
embedding?: number[] | null;
|
|
@@ -438,6 +440,7 @@ export interface AdmitConceptInput {
|
|
|
438
440
|
name: string;
|
|
439
441
|
kind: ConceptKind;
|
|
440
442
|
description?: string;
|
|
443
|
+
/** 论域标签(多值;不参与义项判定,合并时取并集) */
|
|
441
444
|
domain?: string[];
|
|
442
445
|
memoryIds?: string[];
|
|
443
446
|
/** 提出该概念的命题条数(MDL);缺省用 memoryIds.length */
|
|
@@ -501,7 +504,22 @@ export interface ConceptGraphStore {
|
|
|
501
504
|
note?: string;
|
|
502
505
|
}): Promise<void>;
|
|
503
506
|
listMergeCandidates(limit?: number): Promise<MergeCandidate[]>;
|
|
504
|
-
resolveMerge(id: string, action: 'merge' | 'keep_split' | 'drop'
|
|
507
|
+
resolveMerge(id: string, action: 'merge' | 'keep_split' | 'drop',
|
|
508
|
+
/** merge 时可指定规范 kind(LLM 裁决 kind≠ 对合并后落规范义项) */
|
|
509
|
+
options?: {
|
|
510
|
+
canonicalKind?: ConceptKind;
|
|
511
|
+
}): Promise<void>;
|
|
512
|
+
/** 语义种子能力:已注入 embeddingProvider 可做查询向量近邻;false 时 CognitionLayer 降级纯词面 */
|
|
513
|
+
readonly supportsSemanticSeeds: boolean;
|
|
514
|
+
/**
|
|
515
|
+
* 查询语义种子:向量近邻概念名(近者优先,距离 ≤ candidateBandHi)。
|
|
516
|
+
* 由 store 自有 embeddingProvider 嵌入查询文本——与写入侧同源同维,调用方无需持 provider。
|
|
517
|
+
*
|
|
518
|
+
* @param query - 查询文本
|
|
519
|
+
* @param k - 种子上限(缺省 4)
|
|
520
|
+
* @returns 概念名列表;provider 缺失/嵌入失败/无近邻/维度失配 → 空数组(增强路径不 fail)
|
|
521
|
+
*/
|
|
522
|
+
semanticSeeds(query: string, k?: number): Promise<string[]>;
|
|
505
523
|
/** Hebbian 加强(使用痕迹 / 新证据) */
|
|
506
524
|
reinforce(input: {
|
|
507
525
|
nodeIds?: string[];
|
|
@@ -24,6 +24,8 @@ export interface ParsedWisdomItem {
|
|
|
24
24
|
conceptIds?: string[];
|
|
25
25
|
exceptions?: string[];
|
|
26
26
|
kind: WisdomKind;
|
|
27
|
+
/** 取代已有范式(LLM 对照库内已有范式后给出;指向被取代条目 id) */
|
|
28
|
+
supersedesId?: string;
|
|
27
29
|
}
|
|
28
30
|
export interface ParsedWisdomFormation {
|
|
29
31
|
items: ParsedWisdomItem[];
|
|
@@ -72,15 +74,23 @@ export declare function formAndAdmit(llmText: string, store: WisdomStore, option
|
|
|
72
74
|
droppedNotes: string[];
|
|
73
75
|
}>;
|
|
74
76
|
/**
|
|
75
|
-
* 关键词/字面场景匹配分 +
|
|
77
|
+
* 关键词/字面场景匹配分 + 全字面命中标记 + anti 排除标记。
|
|
78
|
+
*
|
|
79
|
+
* 匹配单位是**分段**(长描述句切短语后逐段匹配):任一段全字面命中记 2 分,
|
|
80
|
+
* 仅 2-gram 弱重叠记 1 分。fullHit = 存在长度 ≥3 的分段全字面命中——
|
|
81
|
+
* trial 的 scenario 入场券只认 fullHit(弱重叠不算,2 字通用词也不够格)。
|
|
82
|
+
*
|
|
83
|
+
* antiScenarios 是排除条件(误触发会静默丢范式),要求更强证据才触发:
|
|
84
|
+
* 整串命中,或长度 ≥3 的分段命中(2 字碎片歧义大,如「越权」不应压制修越权 bug 的任务)。
|
|
76
85
|
*
|
|
77
86
|
* @param entry - 条目
|
|
78
87
|
* @param text - 本轮查询/任务文本
|
|
79
|
-
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals
|
|
88
|
+
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals ≥3 字分段全字面命中;excluded=anti 命中
|
|
80
89
|
*/
|
|
81
90
|
export declare function scenarioMatchDetail(entry: WisdomEntry, text: string): {
|
|
82
91
|
score: number;
|
|
83
92
|
fullHit: boolean;
|
|
93
|
+
excluded: boolean;
|
|
84
94
|
};
|
|
85
95
|
/**
|
|
86
96
|
* 关键词/字面场景匹配分。
|
|
@@ -103,12 +113,13 @@ export declare function isCoreEligible(entry: Pick<WisdomEntry, 'status' | 'orig
|
|
|
103
113
|
*
|
|
104
114
|
* @param entries - 可注入条目(store 已滤状态)
|
|
105
115
|
* @param text - 本轮文本
|
|
106
|
-
* @param options - 条数硬顶;includeTrial 缺省 true(trial 的意义就是被试用)
|
|
116
|
+
* @param options - 条数硬顶;trialMaxItems 缺省 2(trial 轮转保底曝光,打破晋升死锁);includeTrial 缺省 true(trial 的意义就是被试用)
|
|
107
117
|
* @returns 排序后的注入选择
|
|
108
118
|
*/
|
|
109
119
|
export declare function pickForInjection(entries: WisdomEntry[], text: string, options?: {
|
|
110
120
|
coreMaxItems?: number;
|
|
111
121
|
scenarioMaxItems?: number;
|
|
122
|
+
trialMaxItems?: number;
|
|
112
123
|
includeTrial?: boolean;
|
|
113
124
|
}): WisdomInjectPick[];
|
|
114
125
|
/**
|
|
@@ -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,42 +165,84 @@ 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 score∈[0,1](无命中为 0);fullHit=problemTypes/signals
|
|
225
|
+
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals ≥3 字分段全字面命中;excluded=anti 命中
|
|
189
226
|
*/
|
|
190
227
|
export function scenarioMatchDetail(entry, text) {
|
|
191
228
|
const q = text.toLowerCase();
|
|
192
229
|
if (!q.trim())
|
|
193
|
-
return { score: 0, fullHit: false };
|
|
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 { score: 0, fullHit: false };
|
|
245
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
202
246
|
let hit = 0;
|
|
203
247
|
let fullHit = false;
|
|
204
248
|
for (const w of words) {
|
|
@@ -206,14 +250,15 @@ export function scenarioMatchDetail(entry, text) {
|
|
|
206
250
|
continue;
|
|
207
251
|
if (q.includes(w)) {
|
|
208
252
|
hit += 2;
|
|
209
|
-
|
|
253
|
+
if (w.length >= 3)
|
|
254
|
+
fullHit = true;
|
|
210
255
|
}
|
|
211
256
|
else if (overlapChars(q, w))
|
|
212
257
|
hit += 1;
|
|
213
258
|
}
|
|
214
259
|
if (hit === 0)
|
|
215
|
-
return { score: 0, fullHit: false };
|
|
216
|
-
return { score: Math.min(1, hit / (words.length * 2)), fullHit };
|
|
260
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
261
|
+
return { score: Math.min(1, hit / (words.length * 2)), fullHit, excluded: false };
|
|
217
262
|
}
|
|
218
263
|
/**
|
|
219
264
|
* 关键词/字面场景匹配分。
|
|
@@ -255,12 +300,13 @@ export function isCoreEligible(entry) {
|
|
|
255
300
|
*
|
|
256
301
|
* @param entries - 可注入条目(store 已滤状态)
|
|
257
302
|
* @param text - 本轮文本
|
|
258
|
-
* @param options - 条数硬顶;includeTrial 缺省 true(trial 的意义就是被试用)
|
|
303
|
+
* @param options - 条数硬顶;trialMaxItems 缺省 2(trial 轮转保底曝光,打破晋升死锁);includeTrial 缺省 true(trial 的意义就是被试用)
|
|
259
304
|
* @returns 排序后的注入选择
|
|
260
305
|
*/
|
|
261
306
|
export function pickForInjection(entries, text, options) {
|
|
262
307
|
const coreMax = options?.coreMaxItems ?? 8;
|
|
263
308
|
const scenarioMax = options?.scenarioMaxItems ?? 8;
|
|
309
|
+
const trialMax = options?.trialMaxItems ?? 2;
|
|
264
310
|
const includeTrial = options?.includeTrial ?? true;
|
|
265
311
|
const usable = entries.filter((e) => {
|
|
266
312
|
if (e.status === 'retired' || e.status === 'superseded' || e.status === 'candidate')
|
|
@@ -277,6 +323,7 @@ export function pickForInjection(entries, text, options) {
|
|
|
277
323
|
entry: e,
|
|
278
324
|
match: m.score,
|
|
279
325
|
fullHit: m.fullHit,
|
|
326
|
+
excluded: m.excluded,
|
|
280
327
|
score: wisdomInjectScore(e, 1),
|
|
281
328
|
scenarioScore: wisdomInjectScore(e, m.score),
|
|
282
329
|
};
|
|
@@ -295,7 +342,21 @@ export function pickForInjection(entries, text, options) {
|
|
|
295
342
|
.sort((a, b) => b.scenarioScore - a.scenarioScore)
|
|
296
343
|
.slice(0, scenarioMax)
|
|
297
344
|
.map((s) => ({ entry: s.entry, bucket: 'scenario', score: s.match }));
|
|
298
|
-
|
|
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];
|
|
299
360
|
}
|
|
300
361
|
// ── 注入排版 ──
|
|
301
362
|
/**
|
|
@@ -311,19 +372,21 @@ export function formatWisdomBody(picks) {
|
|
|
311
372
|
for (const p of picks) {
|
|
312
373
|
const key = p.entry.scenario.problemTypes[0] ?? '通用';
|
|
313
374
|
const list = byType.get(key) ?? [];
|
|
314
|
-
list.push(p.entry);
|
|
375
|
+
list.push({ entry: p.entry, bucket: p.bucket });
|
|
315
376
|
byType.set(key, list);
|
|
316
377
|
}
|
|
317
378
|
const blocks = [];
|
|
318
379
|
blocks.push('> 归因:若某条范式实质影响了你的决策,可在回复中引用其 id(如 [wis_xxx])以便事后验证。');
|
|
319
380
|
for (const [type, list] of byType) {
|
|
320
|
-
const lines = list.map((e) => formatWisdomBullet(e));
|
|
381
|
+
const lines = list.map((e) => formatWisdomBullet(e.entry, e.bucket));
|
|
321
382
|
blocks.push(`## 面对「${type}」\n\n${lines.join('\n\n')}`);
|
|
322
383
|
}
|
|
323
384
|
return blocks.join('\n\n');
|
|
324
385
|
}
|
|
325
|
-
function formatWisdomBullet(e) {
|
|
326
|
-
|
|
386
|
+
function formatWisdomBullet(e, bucket) {
|
|
387
|
+
// trial 轮转注入的条目未经场景验证,显式标记供模型降权采信
|
|
388
|
+
const marker = bucket === 'trial' ? '[试用] ' : '';
|
|
389
|
+
const parts = [`- ${marker}[${e.id}] ${e.statement}`];
|
|
327
390
|
const effectBits = [];
|
|
328
391
|
if (e.effect.posture)
|
|
329
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
|
*
|
|
@@ -35,6 +35,14 @@ export class InMemoryWisdomStore {
|
|
|
35
35
|
message: `supersedesId=${input.supersedesId}`,
|
|
36
36
|
};
|
|
37
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
|
+
}
|
|
38
46
|
this.entries.set(prev.id, {
|
|
39
47
|
...prev,
|
|
40
48
|
status: 'superseded',
|
|
@@ -70,6 +78,7 @@ export class InMemoryWisdomStore {
|
|
|
70
78
|
return pickForInjection(entries, query.text ?? '', {
|
|
71
79
|
coreMaxItems: query.coreMaxItems,
|
|
72
80
|
scenarioMaxItems: query.scenarioMaxItems,
|
|
81
|
+
trialMaxItems: query.trialMaxItems,
|
|
73
82
|
includeTrial: query.includeTrial,
|
|
74
83
|
});
|
|
75
84
|
}
|
|
@@ -51,6 +51,16 @@ export declare class ObserverHub {
|
|
|
51
51
|
endReason?: string;
|
|
52
52
|
error?: string;
|
|
53
53
|
}): void;
|
|
54
|
+
/**
|
|
55
|
+
* 跨进程镜像面补建 run 记录:run.scope.ready 事件自带 scope View(recordRunStart
|
|
56
|
+
* 的产物投影),gateway 侧 hub 只收到事件流时以此为据建 record,使后续
|
|
57
|
+
* timeline/guard 事件有归属。单进程 recordRunStart 已建记录时不会走到这里
|
|
58
|
+
* (ingestEvent 先命中既有 record)。
|
|
59
|
+
*
|
|
60
|
+
* @param event - run.scope.ready 事件(data: { runId, sessionId, agentId, scope, messages })
|
|
61
|
+
* @returns 补建的记录;事件形状不符返回 undefined
|
|
62
|
+
*/
|
|
63
|
+
private adoptRunScopeReady;
|
|
54
64
|
/**
|
|
55
65
|
* ContextEngine assemble 出口:LLM 实际输入
|
|
56
66
|
*/
|