@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
|
@@ -8,7 +8,9 @@ import { KnowledgeSourceStore } from './source-store.js';
|
|
|
8
8
|
import { KnowledgeIndexStore } from './index-store.js';
|
|
9
9
|
import { MembershipStore } from './membership-store.js';
|
|
10
10
|
import { KnowledgeIngest } from './ingest.js';
|
|
11
|
-
import { generateKnowledgeDescription } from './describe.js';
|
|
11
|
+
import { generateKnowledgeDescription, normalizeGeneratedDescription, } from './describe.js';
|
|
12
|
+
import { assembleDescribeSample, DESCRIBE_SAMPLE_MAX_CHARS } from './describe-sample.js';
|
|
13
|
+
import { scanSecretShapes } from './secret-scan.js';
|
|
12
14
|
/** 进程内唯一写者(测试 / :memory:)。 */
|
|
13
15
|
export class LocalKnowledgeWriteService {
|
|
14
16
|
deps;
|
|
@@ -29,6 +31,7 @@ export class LocalKnowledgeWriteService {
|
|
|
29
31
|
documentConfig: deps.documentConfig ?? null,
|
|
30
32
|
embeddingProvider: embed?.enabled === false ? null : (deps.embeddingProvider ?? null),
|
|
31
33
|
credentials: deps.credentials ?? null,
|
|
34
|
+
...(deps.ingest ?? {}),
|
|
32
35
|
...(embed?.embedBatch != null ? { embedBatch: embed.embedBatch } : {}),
|
|
33
36
|
...(embed?.embedMinIntervalMs != null ? { embedMinIntervalMs: embed.embedMinIntervalMs } : {}),
|
|
34
37
|
...(embed?.embedConcurrency != null ? { embedConcurrency: embed.embedConcurrency } : {}),
|
|
@@ -185,19 +188,68 @@ export class LocalKnowledgeWriteService {
|
|
|
185
188
|
this.sources.remove(sourceId);
|
|
186
189
|
return { id: sourceId, purgedFiles: purged.length };
|
|
187
190
|
}
|
|
188
|
-
async describeSource(identity, sourceId) {
|
|
191
|
+
async describeSource(identity, sourceId, input) {
|
|
189
192
|
await this.assertSourceOwner(identity, sourceId);
|
|
190
193
|
const src = this.sources.get(sourceId);
|
|
191
194
|
if (!src)
|
|
192
195
|
return null;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
if (input?.description != null) {
|
|
197
|
+
// 写入口(B 方案回写):调用方是 gateway 的 LLM describe 流程;内容在出 Service 前过密钥扫描,
|
|
198
|
+
// 但描述会进系统提示 catalog 行——写入侧强制单行归一(防多行注入伪造 catalog 行)
|
|
199
|
+
const text = normalizeGeneratedDescription(input.description);
|
|
200
|
+
if (!text) {
|
|
201
|
+
throw Object.assign(new Error('description empty'), { code: 'bad_request' });
|
|
202
|
+
}
|
|
203
|
+
const source = input.source === 'heuristic' ? 'heuristic' : 'llm';
|
|
204
|
+
this.sources.update(sourceId, {
|
|
205
|
+
generatedDescription: text,
|
|
206
|
+
generatedDescriptionSource: source,
|
|
207
|
+
});
|
|
208
|
+
return { generatedDescription: text, source };
|
|
209
|
+
}
|
|
210
|
+
const r = await this.describeWithSample(src);
|
|
211
|
+
this.sources.update(sourceId, {
|
|
212
|
+
generatedDescription: r.description,
|
|
213
|
+
generatedDescriptionSource: r.source === 'disabled' ? 'heuristic' : r.source,
|
|
214
|
+
});
|
|
199
215
|
return { generatedDescription: r.description, source: r.source };
|
|
200
216
|
}
|
|
217
|
+
async describeSample(identity, sourceId) {
|
|
218
|
+
await this.assertSourceOwner(identity, sourceId);
|
|
219
|
+
const src = this.sources.get(sourceId);
|
|
220
|
+
if (!src)
|
|
221
|
+
return null;
|
|
222
|
+
const sample = assembleDescribeSample(this.db, sourceId);
|
|
223
|
+
// 密钥形态封锁:命中即不外发样本(fail-safe,同 generateKnowledgeDescription 口径)
|
|
224
|
+
const secretHits = scanSecretShapes(sample);
|
|
225
|
+
if (secretHits.length > 0)
|
|
226
|
+
return { blocked: true, secretHits };
|
|
227
|
+
return {
|
|
228
|
+
blocked: false,
|
|
229
|
+
meta: { displayName: src.displayName, kind: src.kind, location: src.location },
|
|
230
|
+
sample,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async listDescribePending(identity) {
|
|
234
|
+
// 待升级 = 有启发式/legacy 自动描述、无人工描述、归因非 llm(legacy NULL 视为 heuristic)
|
|
235
|
+
const rows = this.db.raw
|
|
236
|
+
.prepare(`SELECT id FROM knowledge_sources
|
|
237
|
+
WHERE generated_description IS NOT NULL
|
|
238
|
+
AND description IS NULL
|
|
239
|
+
AND (generated_description_source IS NULL OR generated_description_source = 'heuristic')
|
|
240
|
+
AND status NOT IN ('removed', 'disabled')
|
|
241
|
+
AND (registered_by IS NULL OR registered_by = '' OR registered_by = ?)`)
|
|
242
|
+
.all(identity.gatewayId);
|
|
243
|
+
return rows.map((r) => r.id);
|
|
244
|
+
}
|
|
245
|
+
/** 启发式/封锁描述生成(无 describePort:Service 侧永不含 LLM 出网,B 方案拍板) */
|
|
246
|
+
describeWithSample(src) {
|
|
247
|
+
const sample = assembleDescribeSample(this.db, src.id);
|
|
248
|
+
return generateKnowledgeDescription(src, sample, {
|
|
249
|
+
enabled: true,
|
|
250
|
+
sampleChars: DESCRIBE_SAMPLE_MAX_CHARS,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
201
253
|
async assertSourceOwner(identity, sourceId) {
|
|
202
254
|
const row = this.db.raw
|
|
203
255
|
.prepare('SELECT registered_by FROM knowledge_sources WHERE id = ?')
|
|
@@ -311,17 +363,41 @@ export class LocalKnowledgeWriteService {
|
|
|
311
363
|
async startIngestRuntime() {
|
|
312
364
|
const { sources, ingest } = this;
|
|
313
365
|
ingest.onSourceSettled = (sourceId) => {
|
|
366
|
+
// catalog.autoDescribe=false:索引稳定后不自动生成 generatedDescription(v0.51.5 语义)
|
|
367
|
+
if (this.deps.autoDescribe === false)
|
|
368
|
+
return;
|
|
314
369
|
void (async () => {
|
|
315
370
|
try {
|
|
316
371
|
const src = sources.get(sourceId);
|
|
317
372
|
if (!src || src.description?.trim())
|
|
318
373
|
return;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
|
|
374
|
+
// llm 归因是更高信任档:settle 不降级、不重发(B 方案 2026-11-02)
|
|
375
|
+
if (src.generatedDescriptionSource === 'llm')
|
|
376
|
+
return;
|
|
377
|
+
const r = await this.describeWithSample(src);
|
|
378
|
+
const source = r.source === 'disabled' ? 'heuristic' : r.source;
|
|
379
|
+
// startReconciler 每 15s 对稳态源反复触发本钩子(ingest.ts):文本与归因都
|
|
380
|
+
// 无变化则不写不发,掐断「每 tick 重发 describe-pending → gateway 每 tick
|
|
381
|
+
// LLM 升级」成本环。归因必须参与比较——blocked_secret 与 heuristic 共享同一
|
|
382
|
+
// 启发式文本,只比文本会让「封锁→清洁」的归因回退永远卡死(评审 P1-1)
|
|
383
|
+
if (src.generatedDescription === r.description &&
|
|
384
|
+
src.generatedDescriptionSource === source) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
sources.update(sourceId, {
|
|
388
|
+
generatedDescription: r.description,
|
|
389
|
+
generatedDescriptionSource: source,
|
|
390
|
+
});
|
|
391
|
+
// B 方案(2026-11-02 拍板):LLM 描述由 gateway 代生成。
|
|
392
|
+
// 启发式落库即发升级信号;blocked_secret(抽样含密钥形态)不发——素材不得外发。
|
|
393
|
+
if (source === 'heuristic') {
|
|
394
|
+
this.emitProgress({
|
|
395
|
+
type: 'source',
|
|
396
|
+
sourceId,
|
|
397
|
+
status: 'describe-pending',
|
|
398
|
+
detail: 'llm upgrade eligible',
|
|
399
|
+
});
|
|
400
|
+
}
|
|
325
401
|
}
|
|
326
402
|
catch {
|
|
327
403
|
/* describe 失败不影响索引 */
|
|
@@ -349,6 +425,36 @@ export class LocalKnowledgeWriteService {
|
|
|
349
425
|
this.progressCbs.delete(cb);
|
|
350
426
|
};
|
|
351
427
|
}
|
|
428
|
+
/** Writer 自产事件(describe-pending 等);归属补齐口径与 IngestProgressEvent 一致 */
|
|
429
|
+
emitProgress(evt) {
|
|
430
|
+
let out = evt;
|
|
431
|
+
if (evt.sourceId && evt.registeredBy === undefined) {
|
|
432
|
+
try {
|
|
433
|
+
const row = this.db.raw
|
|
434
|
+
.prepare('SELECT tenant_id, registered_by, visibility FROM knowledge_sources WHERE id = ?')
|
|
435
|
+
.get(evt.sourceId);
|
|
436
|
+
if (row) {
|
|
437
|
+
out = {
|
|
438
|
+
...evt,
|
|
439
|
+
tenantId: row.tenant_id,
|
|
440
|
+
registeredBy: row.registered_by,
|
|
441
|
+
visibility: row.visibility,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
/* 源已删时保持原事件;SSE 侧按无归属放行到 fallback */
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
for (const cb of this.progressCbs) {
|
|
450
|
+
try {
|
|
451
|
+
cb(out);
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
/* SSE 订阅方异常不得打断 describe */
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
352
458
|
async dispose() {
|
|
353
459
|
this.progressCbs.clear();
|
|
354
460
|
this.ingest.dispose();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { KnowledgeWriteService, WriteIdentity, WriteAbortStats, WriteResumeStats, WriteRegisterResult, WriteDescribeResult, WriteReprocessResult } from './writer-service.js';
|
|
1
|
+
import type { KnowledgeWriteService, WriteIdentity, WriteAbortStats, WriteResumeStats, WriteRegisterResult, WriteDescribeResult, WriteDescribeInput, WriteDescribeSampleResult, WriteReprocessResult } from './writer-service.js';
|
|
2
2
|
import type { KnowledgeSource } from './types.js';
|
|
3
3
|
import type { KnowledgeJobControlState } from './job-control-state.js';
|
|
4
4
|
import type { IngestProgressEvent } from './ingest.js';
|
|
5
5
|
import type { DocumentCapabilityConfig } from '../capabilities/document/factory.js';
|
|
6
|
+
import type { KnowledgeBootEmbed, KnowledgeBootIngest } from './boot-config.js';
|
|
6
7
|
export interface WorkerWriteStartOptions {
|
|
7
8
|
dbPath: string;
|
|
8
9
|
documentConfig?: DocumentCapabilityConfig | null;
|
|
@@ -11,13 +12,11 @@ export interface WorkerWriteStartOptions {
|
|
|
11
12
|
providers?: Record<string, unknown>;
|
|
12
13
|
embedding?: unknown;
|
|
13
14
|
} | null;
|
|
14
|
-
embed?:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
embedSecretPolicy?: 'allow' | 'redact' | 'skip';
|
|
20
|
-
} | null;
|
|
15
|
+
embed?: KnowledgeBootEmbed | null;
|
|
16
|
+
/** Ingest 调参(knowledge.load / index.queue / index.files) */
|
|
17
|
+
ingest?: KnowledgeBootIngest | null;
|
|
18
|
+
/** false = 索引稳定后不自动生成 generatedDescription(knowledge.catalog.autoDescribe) */
|
|
19
|
+
autoDescribe?: boolean;
|
|
21
20
|
testEmbeddingStub?: boolean;
|
|
22
21
|
timeoutMs?: number;
|
|
23
22
|
}
|
|
@@ -64,7 +63,9 @@ export declare class WorkerWriteService implements KnowledgeWriteService {
|
|
|
64
63
|
id: string;
|
|
65
64
|
purgedFiles: number;
|
|
66
65
|
}>;
|
|
67
|
-
describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
|
|
66
|
+
describeSource(identity: WriteIdentity, sourceId: string, input?: WriteDescribeInput): Promise<WriteDescribeResult | null>;
|
|
67
|
+
describeSample(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeSampleResult | null>;
|
|
68
|
+
listDescribePending(identity: WriteIdentity): Promise<string[]>;
|
|
68
69
|
reindexSource(sourceId: string): Promise<void>;
|
|
69
70
|
reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
|
|
70
71
|
reprocessByFilter(sourceId: string, filter?: {
|
|
@@ -93,6 +93,8 @@ export class WorkerWriteService {
|
|
|
93
93
|
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
94
94
|
embeddingModels: opts.embeddingModels ?? null,
|
|
95
95
|
embed: opts.embed ?? null,
|
|
96
|
+
ingest: opts.ingest ?? null,
|
|
97
|
+
autoDescribe: opts.autoDescribe,
|
|
96
98
|
testEmbeddingStub: opts.testEmbeddingStub ?? false,
|
|
97
99
|
},
|
|
98
100
|
env: process.env,
|
|
@@ -225,9 +227,25 @@ export class WorkerWriteService {
|
|
|
225
227
|
this.rethrow(e);
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
|
-
async describeSource(identity, sourceId) {
|
|
230
|
+
async describeSource(identity, sourceId, input) {
|
|
229
231
|
try {
|
|
230
|
-
return (await this.call('describeSource', { identity, sourceId }));
|
|
232
|
+
return (await this.call('describeSource', { identity, sourceId, input }));
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
this.rethrow(e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async describeSample(identity, sourceId) {
|
|
239
|
+
try {
|
|
240
|
+
return (await this.call('describeSample', { identity, sourceId }));
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
this.rethrow(e);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async listDescribePending(identity) {
|
|
247
|
+
try {
|
|
248
|
+
return (await this.call('listDescribePending', { identity }));
|
|
231
249
|
}
|
|
232
250
|
catch (e) {
|
|
233
251
|
this.rethrow(e);
|
|
@@ -46,6 +46,8 @@ async function main() {
|
|
|
46
46
|
documentConfig: boot.documentConfig ?? null,
|
|
47
47
|
embeddingProvider: embeddingProvider,
|
|
48
48
|
embed: boot.embed ?? null,
|
|
49
|
+
ingest: boot.ingest ?? null,
|
|
50
|
+
autoDescribe: boot.autoDescribe,
|
|
49
51
|
});
|
|
50
52
|
write.onProgress((evt) => {
|
|
51
53
|
port.postMessage({ type: 'progress', evt });
|
|
@@ -105,7 +107,13 @@ async function main() {
|
|
|
105
107
|
data = await write.removeSource(identity, String(args.sourceId));
|
|
106
108
|
break;
|
|
107
109
|
case 'describeSource':
|
|
108
|
-
data = await write.describeSource(identity, String(args.sourceId));
|
|
110
|
+
data = await write.describeSource(identity, String(args.sourceId), args.input);
|
|
111
|
+
break;
|
|
112
|
+
case 'describeSample':
|
|
113
|
+
data = await write.describeSample(identity, String(args.sourceId));
|
|
114
|
+
break;
|
|
115
|
+
case 'listDescribePending':
|
|
116
|
+
data = await write.listDescribePending(identity);
|
|
109
117
|
break;
|
|
110
118
|
case 'reindexSource':
|
|
111
119
|
await write.reindexSource(String(args.sourceId));
|
|
@@ -4,13 +4,17 @@
|
|
|
4
4
|
* 价值模型:fact / method / norm(见 docs/memory.md、arch/memory-system-redesign.md)。
|
|
5
5
|
* system prompt ContextLayer 契约在 harness/context/。
|
|
6
6
|
*/
|
|
7
|
-
export type { MemoryType, MemoryChannel, MemoryStatus, SoftDeleteReason, MemoryEntry, MemoryQuery, MemoryStats, MemoryStore, MemoryWriteSlot, WisdomStatus, WisdomOrigin, WisdomKind, WisdomRetireReason, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomCounterevidence, WisdomOutcomes, WisdomEntry, WisdomGateReason, WisdomGateOutcome, AdmitWisdomInput, AdmitWisdomAction, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomOutcomeSignal, WisdomOutcomeEvent, WisdomStats, WisdomStore, ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, EdgeAux, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './types.js';
|
|
7
|
+
export type { MemoryType, MemoryChannel, MemoryStatus, SoftDeleteReason, MemoryEntry, MemoryQuery, MemoryStats, MemoryStore, MemoryWriteSlot, WisdomStatus, WisdomOrigin, WisdomKind, WisdomRetireReason, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomCounterevidence, WisdomOutcomes, WisdomEntry, WisdomGateReason, WisdomGateOutcome, AdmitWisdomInput, AdmitWisdomAction, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomOutcomeSignal, WisdomOutcomeEvent, WisdomAttributionCitation, WisdomAttributionWindowInput, WisdomAttributionWindow, WisdomStats, WisdomStore, ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, EdgeAux, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './types.js';
|
|
8
8
|
export { MEMORY_TYPES, WISDOM_STATUSES, WISDOM_INJECTABLE_STATUSES, WISDOM_ORIGINS, WISDOM_KINDS, CONCEPT_KINDS, CONCEPT_RELATION_TYPES, STRONG_RELATION_TYPES, } from './types.js';
|
|
9
9
|
export { evaluateWisdomGate, resolveInitialWisdomStatus, normalizeStatement, looksOpposed, WISDOM_DEFAULT_MIN_SUPPORT, } from './wisdom-gates.js';
|
|
10
10
|
export { DEFAULT_WISDOM_EVALUATION, DEFAULT_WISDOM_GOVERN, foldOutcomeEvents, planConfidenceUpdate, planWisdomGovern, wisdomUtility, wisdomInjectScore, } from './wisdom-policy.js';
|
|
11
11
|
export type { WisdomEvaluationConfig, WisdomGovernConfig, WisdomConfidenceUpdate, WisdomGoverPlanItem, } from './wisdom-policy.js';
|
|
12
|
-
export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
|
|
12
|
+
export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, scenarioMatchDetail, isCoreEligible, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
|
|
13
13
|
export type { RawWisdomFormationOutput, ParsedWisdomItem, ParsedWisdomFormation, } from './wisdom-formation.js';
|
|
14
|
+
export { extractCitations, collectRunAssistantTexts, recordWisdomRunWindow, selectAttributionCandidates, planAttributionBatch, buildAttributionDigest, parseAttributionVerdicts, verdictsToOutcomeEvents, } from './wisdom-attribution.js';
|
|
15
|
+
export type { WisdomRunWindowInfo, AttributionCandidate, AttributionBatch, AttributionVerdict, } from './wisdom-attribution.js';
|
|
16
|
+
export { emitWisdomEvaluateRequest, emitWisdomGoverned, WISDOM_EVALUATE_REQUEST_EVENT, WISDOM_GOVERNED_EVENT, } from './wisdom-events.js';
|
|
17
|
+
export type { WisdomEvaluateRequestPayload } from './wisdom-events.js';
|
|
14
18
|
export { evaluateConceptGate, licenseEdge, edgeBasisFromLicense, normalizeForCue, } from './cognition-gates.js';
|
|
15
19
|
export type { ConceptGateOutcome, EdgeLicenseInput, EdgeLicenseOutcome, } from './cognition-gates.js';
|
|
16
20
|
export { DEFAULT_EDGE_DECAY_PER_DAY, DEFAULT_EDGE_DECAY_FLOOR, DEFAULT_RETRIEVE_STATUSES, decayMultiplier, nextEdgeStrength, hebbianStrengthen, counterEvidenceWeaken, } from './cognition-decay.js';
|
|
@@ -8,7 +8,10 @@ export { MEMORY_TYPES, WISDOM_STATUSES, WISDOM_INJECTABLE_STATUSES, WISDOM_ORIGI
|
|
|
8
8
|
// ── Wisdom 门控 / 策略 / 形成 ──
|
|
9
9
|
export { evaluateWisdomGate, resolveInitialWisdomStatus, normalizeStatement, looksOpposed, WISDOM_DEFAULT_MIN_SUPPORT, } from './wisdom-gates.js';
|
|
10
10
|
export { DEFAULT_WISDOM_EVALUATION, DEFAULT_WISDOM_GOVERN, foldOutcomeEvents, planConfidenceUpdate, planWisdomGovern, wisdomUtility, wisdomInjectScore, } from './wisdom-policy.js';
|
|
11
|
-
export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
|
|
11
|
+
export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, scenarioMatchDetail, isCoreEligible, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
|
|
12
|
+
// ── Wisdom 归因窗口 / 判决事件 ──
|
|
13
|
+
export { extractCitations, collectRunAssistantTexts, recordWisdomRunWindow, selectAttributionCandidates, planAttributionBatch, buildAttributionDigest, parseAttributionVerdicts, verdictsToOutcomeEvents, } from './wisdom-attribution.js';
|
|
14
|
+
export { emitWisdomEvaluateRequest, emitWisdomGoverned, WISDOM_EVALUATE_REQUEST_EVENT, WISDOM_GOVERNED_EVENT, } from './wisdom-events.js';
|
|
12
15
|
// ── Cognition 门控 / 可塑 / 概念化 ──
|
|
13
16
|
export { evaluateConceptGate, licenseEdge, edgeBasisFromLicense, normalizeForCue, } from './cognition-gates.js';
|
|
14
17
|
export { DEFAULT_EDGE_DECAY_PER_DAY, DEFAULT_EDGE_DECAY_FLOOR, DEFAULT_RETRIEVE_STATUSES, decayMultiplier, nextEdgeStrength, hebbianStrengthen, counterEvidenceWeaken, } from './cognition-decay.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory 存量变化信号 — 每条命题落库后 emit `memory.stored`
|
|
3
|
+
*
|
|
4
|
+
* 消费方(sense.filter.events 订阅):wisdom.steward.formation 等增量触发的子系统。
|
|
5
|
+
* 事件类型必须真实存在于 EventBus;发射失败静默(不得阻断 memory 写路径)。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/memory-events
|
|
8
|
+
*/
|
|
9
|
+
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
10
|
+
/** 命题落库信号(每条一发;消费方按 minEvents 累积节流) */
|
|
11
|
+
export declare const MEMORY_STORED_EVENT = "memory.stored";
|
|
12
|
+
export interface MemoryStoredPayload {
|
|
13
|
+
memoryId: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
status?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
agentId?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 发射命题落库信号。失败静默(不得阻断 Memory 写入)。
|
|
21
|
+
*
|
|
22
|
+
* @param events - EventBus
|
|
23
|
+
* @param payload - 落库载荷
|
|
24
|
+
*/
|
|
25
|
+
export declare function emitMemoryStored(events: EventBus | undefined, payload: MemoryStoredPayload): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory 存量变化信号 — 每条命题落库后 emit `memory.stored`
|
|
3
|
+
*
|
|
4
|
+
* 消费方(sense.filter.events 订阅):wisdom.steward.formation 等增量触发的子系统。
|
|
5
|
+
* 事件类型必须真实存在于 EventBus;发射失败静默(不得阻断 memory 写路径)。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/memory-events
|
|
8
|
+
*/
|
|
9
|
+
/** 命题落库信号(每条一发;消费方按 minEvents 累积节流) */
|
|
10
|
+
export const MEMORY_STORED_EVENT = 'memory.stored';
|
|
11
|
+
/**
|
|
12
|
+
* 发射命题落库信号。失败静默(不得阻断 Memory 写入)。
|
|
13
|
+
*
|
|
14
|
+
* @param events - EventBus
|
|
15
|
+
* @param payload - 落库载荷
|
|
16
|
+
*/
|
|
17
|
+
export function emitMemoryStored(events, payload) {
|
|
18
|
+
if (!events)
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
events.emit({
|
|
22
|
+
type: MEMORY_STORED_EVENT,
|
|
23
|
+
timestamp: Date.now(),
|
|
24
|
+
agentId: payload.agentId,
|
|
25
|
+
sessionId: payload.sessionId,
|
|
26
|
+
data: {
|
|
27
|
+
memoryId: payload.memoryId,
|
|
28
|
+
type: payload.type,
|
|
29
|
+
status: payload.status,
|
|
30
|
+
sessionId: payload.sessionId,
|
|
31
|
+
agentId: payload.agentId,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// 总线异常不得拖垮 Memory 写入
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -297,6 +297,21 @@ export class AgentDatabase {
|
|
|
297
297
|
CREATE INDEX IF NOT EXISTS idx_wisdom_status ON wisdom(status);
|
|
298
298
|
CREATE INDEX IF NOT EXISTS idx_wisdom_priority ON wisdom(priority);
|
|
299
299
|
|
|
300
|
+
-- ── Wisdom 归因窗口(弱归因验证:run 收尾记账,判官批量判决)──
|
|
301
|
+
CREATE TABLE IF NOT EXISTS wisdom_attribution_windows (
|
|
302
|
+
id TEXT PRIMARY KEY,
|
|
303
|
+
session_id TEXT NOT NULL,
|
|
304
|
+
agent_id TEXT,
|
|
305
|
+
query TEXT NOT NULL DEFAULT '',
|
|
306
|
+
outcome TEXT NOT NULL DEFAULT '',
|
|
307
|
+
injected_ids TEXT NOT NULL DEFAULT '[]',
|
|
308
|
+
citations TEXT NOT NULL DEFAULT '[]',
|
|
309
|
+
created_at INTEGER NOT NULL,
|
|
310
|
+
judged_at INTEGER
|
|
311
|
+
);
|
|
312
|
+
CREATE INDEX IF NOT EXISTS idx_wisdom_windows_judged ON wisdom_attribution_windows(judged_at);
|
|
313
|
+
CREATE INDEX IF NOT EXISTS idx_wisdom_windows_created ON wisdom_attribution_windows(created_at);
|
|
314
|
+
|
|
300
315
|
-- ── Knowledge Sources 注册表 ──
|
|
301
316
|
CREATE TABLE IF NOT EXISTS knowledge_sources (
|
|
302
317
|
id TEXT PRIMARY KEY,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
|
-
import type { AdmitWisdomInput, AdmitWisdomResult, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomOutcomeEvent, WisdomRetireReason, WisdomStats, WisdomStore } from '../types.js';
|
|
8
|
+
import type { AdmitWisdomInput, AdmitWisdomResult, WisdomAttributionWindow, WisdomAttributionWindowInput, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomOutcomeEvent, WisdomRetireReason, WisdomStats, WisdomStore } from '../types.js';
|
|
9
9
|
import { AgentDatabase } from './agent-db.js';
|
|
10
10
|
export interface SqliteWisdomStoreOptions {
|
|
11
11
|
/** admit 硬顶(存活面);默认 80 */
|
|
@@ -29,8 +29,13 @@ export declare class SqliteWisdomStore implements WisdomStore {
|
|
|
29
29
|
by: string;
|
|
30
30
|
reason: WisdomRetireReason | string;
|
|
31
31
|
}): Promise<void>;
|
|
32
|
-
recordOutcomes(events: WisdomOutcomeEvent[]): Promise<void>;
|
|
32
|
+
recordOutcomes(events: WisdomOutcomeEvent[], config?: import('../wisdom-policy.js').WisdomEvaluationConfig): Promise<void>;
|
|
33
33
|
touchApplied(ids: string[]): Promise<void>;
|
|
34
|
+
recordAttributionWindow(input: WisdomAttributionWindowInput): Promise<string>;
|
|
35
|
+
listPendingWindows(limit?: number): Promise<WisdomAttributionWindow[]>;
|
|
36
|
+
markWindowsJudged(ids: string[], at?: number): Promise<string[]>;
|
|
37
|
+
pruneWindows(before: number): Promise<void>;
|
|
38
|
+
private rowToWindow;
|
|
34
39
|
stats(): Promise<WisdomStats>;
|
|
35
40
|
/** 存活面计数(candidate/trial/active/strengthened/contested) */
|
|
36
41
|
countLive(): number;
|
|
@@ -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
|
}
|
|
@@ -112,7 +137,7 @@ export class SqliteWisdomStore {
|
|
|
112
137
|
exceptions: [...(current.exceptions ?? []), `retired:${meta.reason}:${meta.by}`],
|
|
113
138
|
});
|
|
114
139
|
}
|
|
115
|
-
async recordOutcomes(events) {
|
|
140
|
+
async recordOutcomes(events, config) {
|
|
116
141
|
if (events.length === 0)
|
|
117
142
|
return;
|
|
118
143
|
const byId = new Map();
|
|
@@ -127,7 +152,7 @@ export class SqliteWisdomStore {
|
|
|
127
152
|
continue;
|
|
128
153
|
const folded = foldOutcomeEvents(current, evs);
|
|
129
154
|
let next = { ...current, ...folded, updatedAt: Date.now() };
|
|
130
|
-
const plan = planConfidenceUpdate(next);
|
|
155
|
+
const plan = planConfidenceUpdate(next, config);
|
|
131
156
|
if (plan) {
|
|
132
157
|
next = {
|
|
133
158
|
...next,
|
|
@@ -174,6 +199,55 @@ export class SqliteWisdomStore {
|
|
|
174
199
|
.run(JSON.stringify(outcomes), now, id);
|
|
175
200
|
}
|
|
176
201
|
}
|
|
202
|
+
async recordAttributionWindow(input) {
|
|
203
|
+
const id = AgentDatabase.generateId('waw');
|
|
204
|
+
this.db.raw
|
|
205
|
+
.prepare(`INSERT INTO wisdom_attribution_windows
|
|
206
|
+
(id, session_id, agent_id, query, outcome, injected_ids, citations, created_at)
|
|
207
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
208
|
+
.run(id, input.sessionId, input.agentId ?? null, input.query, input.outcome, JSON.stringify(input.injectedIds), JSON.stringify(input.citations), Date.now());
|
|
209
|
+
return id;
|
|
210
|
+
}
|
|
211
|
+
async listPendingWindows(limit) {
|
|
212
|
+
const rows = this.db.raw
|
|
213
|
+
.prepare(`SELECT * FROM wisdom_attribution_windows WHERE judged_at IS NULL
|
|
214
|
+
ORDER BY created_at ASC LIMIT ?`)
|
|
215
|
+
.all(limit && limit > 0 ? limit : 500);
|
|
216
|
+
return rows.map((r) => this.rowToWindow(r));
|
|
217
|
+
}
|
|
218
|
+
async markWindowsJudged(ids, at) {
|
|
219
|
+
if (ids.length === 0)
|
|
220
|
+
return [];
|
|
221
|
+
const now = at ?? Date.now();
|
|
222
|
+
const stmt = this.db.raw.prepare(`UPDATE wisdom_attribution_windows SET judged_at = ? WHERE id = ? AND judged_at IS NULL`);
|
|
223
|
+
const newlyJudged = [];
|
|
224
|
+
for (const id of ids) {
|
|
225
|
+
// 只有真正置上的才算本次标记(跨进程幂等:他方先标则不发事件)
|
|
226
|
+
const res = stmt.run(now, id);
|
|
227
|
+
if (Number(res.changes ?? 0) > 0)
|
|
228
|
+
newlyJudged.push(id);
|
|
229
|
+
}
|
|
230
|
+
return newlyJudged;
|
|
231
|
+
}
|
|
232
|
+
async pruneWindows(before) {
|
|
233
|
+
this.db.raw
|
|
234
|
+
.prepare(`DELETE FROM wisdom_attribution_windows WHERE judged_at IS NOT NULL AND judged_at < ?`)
|
|
235
|
+
.run(before);
|
|
236
|
+
}
|
|
237
|
+
rowToWindow(r) {
|
|
238
|
+
return {
|
|
239
|
+
id: String(r.id),
|
|
240
|
+
sessionId: String(r.session_id),
|
|
241
|
+
agentId: r.agent_id == null ? undefined : String(r.agent_id),
|
|
242
|
+
query: String(r.query ?? ''),
|
|
243
|
+
outcome: String(r.outcome ?? ''),
|
|
244
|
+
// 坏行不得毒化整批(手工损坏/半写 JSON 跳过字段而非抛错)
|
|
245
|
+
injectedIds: safeParse(String(r.injected_ids ?? ''), []),
|
|
246
|
+
citations: safeParse(String(r.citations ?? ''), []),
|
|
247
|
+
createdAt: Number(r.created_at),
|
|
248
|
+
judgedAt: r.judged_at == null ? undefined : Number(r.judged_at),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
177
251
|
async stats() {
|
|
178
252
|
const rows = this.db.raw.prepare(`SELECT * FROM wisdom`).all();
|
|
179
253
|
const byStatus = Object.fromEntries(WISDOM_STATUSES.map((s) => [s, 0]));
|
|
@@ -275,7 +275,7 @@ export async function admitCandidates(store, candidates, source) {
|
|
|
275
275
|
if (idx >= 0)
|
|
276
276
|
live.splice(idx, 1);
|
|
277
277
|
}
|
|
278
|
-
accepted.push({ id, type, status });
|
|
278
|
+
accepted.push({ id, type, status, proposition: c.proposition, channel: c.channel ?? 'model_inference', evidence: c.evidence });
|
|
279
279
|
sourceCount += 1;
|
|
280
280
|
// 同批后续候选可对刚写入条目判重
|
|
281
281
|
live.push({
|