@octopi-agent/engine 0.65.0 → 0.86.38
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/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +69 -0
- package/dist/config-schema/context.d.ts +23 -4
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +285 -9
- package/dist/config-schema/engine.js +35 -3
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +91 -0
- package/dist/config-schema/models.d.ts +1 -1
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +10 -0
- package/dist/config-schema/shared.js +10 -0
- package/dist/config-schema/substrate.d.ts +87 -1
- package/dist/config-schema/substrate.js +114 -0
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +249 -7
- package/dist/config.js +113 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +48 -4
- package/dist/harness/agent/builder.js +206 -55
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +83 -280
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +38 -0
- package/dist/harness/agent/tool-purpose.js +118 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +363 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/gate.js +2 -2
- package/dist/harness/context/capabilities/summary/policies.js +5 -5
- package/dist/harness/context/capabilities/summary/registry.js +39 -24
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-health.js +3 -2
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +49 -1
- package/dist/harness/context/layer-types.js +72 -4
- package/dist/harness/context/layers.d.ts +32 -15
- package/dist/harness/context/layers.js +87 -71
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +33 -0
- package/dist/harness/context/system-prompt-assembler.js +78 -7
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +248 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +334 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +493 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +118 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -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/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +45 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +278 -82
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +239 -61
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +39 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +18 -15
- package/dist/harness/index.js +11 -7
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +6 -3
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.js +4 -1
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/query-service.js +8 -8
- package/dist/harness/knowledge/retriever.js +1 -1
- package/dist/harness/knowledge/source-store.d.ts +17 -2
- package/dist/harness/knowledge/source-store.js +6 -5
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/cognition-decay.d.ts +36 -0
- package/dist/harness/memory/cognition-decay.js +55 -0
- package/dist/harness/memory/cognition-gates.d.ts +60 -0
- package/dist/harness/memory/cognition-gates.js +191 -0
- package/dist/harness/memory/cognition-trigger.d.ts +30 -0
- package/dist/harness/memory/cognition-trigger.js +41 -0
- package/dist/harness/memory/cognition-types.d.ts +1 -1
- package/dist/harness/memory/cognition.d.ts +40 -8
- package/dist/harness/memory/cognition.js +432 -79
- package/dist/harness/memory/conceptualizer.d.ts +66 -0
- package/dist/harness/memory/conceptualizer.js +246 -0
- package/dist/harness/memory/index.d.ts +17 -2
- package/dist/harness/memory/index.js +12 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
- package/dist/harness/memory/sqlite/agent-db.js +120 -15
- package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
- package/dist/harness/memory/sqlite/cognition-store.js +591 -144
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
- package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +343 -16
- package/dist/harness/memory/types.js +49 -0
- package/dist/harness/memory/wisdom-formation.d.ts +101 -0
- package/dist/harness/memory/wisdom-formation.js +304 -0
- package/dist/harness/memory/wisdom-gates.d.ts +50 -0
- package/dist/harness/memory/wisdom-gates.js +204 -0
- package/dist/harness/memory/wisdom-policy.d.ts +107 -0
- package/dist/harness/memory/wisdom-policy.js +220 -0
- package/dist/harness/memory/wisdom-types.d.ts +3 -2
- package/dist/harness/memory/wisdom-types.js +2 -2
- package/dist/harness/memory/wisdom.d.ts +27 -0
- package/dist/harness/memory/wisdom.js +181 -0
- package/dist/harness/observability/observer/hub.js +23 -1
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +57 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +27 -0
- package/dist/harness/run/agent/agent.js +45 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +116 -20
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +101 -16
- package/dist/harness/run/runner.js +557 -158
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +1 -0
- package/dist/harness/session/in-memory-store.d.ts +1 -0
- package/dist/harness/session/in-memory-store.js +22 -1
- package/dist/harness/session/index.d.ts +1 -0
- package/dist/harness/session/index.js +1 -0
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.d.ts +86 -0
- package/dist/harness/session/title.js +268 -0
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +21 -0
- package/dist/harness/shared/events/agent-event-map.js +1 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +11 -0
- package/dist/integration/storage/jsonl.js +148 -39
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
- package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
- package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
- package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wisdom formation — 炼制解析、场景匹配、注入排版
|
|
3
|
+
*
|
|
4
|
+
* LLM 判「是不是范式、适用域」;本模块做结构解析 + admit 门控 + 关键词场景匹配。
|
|
5
|
+
* 禁止 session 全文 ETL。规范:arch/wisdom-layer-formation.md §6 / §9。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/wisdom-formation
|
|
8
|
+
*/
|
|
9
|
+
import { WISDOM_KINDS } from './types.js';
|
|
10
|
+
import { wisdomInjectScore } from './wisdom-policy.js';
|
|
11
|
+
import { evaluateWisdomGate } from './wisdom-gates.js';
|
|
12
|
+
function asString(v) {
|
|
13
|
+
return typeof v === 'string' ? v.trim() : '';
|
|
14
|
+
}
|
|
15
|
+
function asStringArray(v) {
|
|
16
|
+
if (!Array.isArray(v))
|
|
17
|
+
return [];
|
|
18
|
+
return v.map((x) => asString(x)).filter(Boolean);
|
|
19
|
+
}
|
|
20
|
+
function parseKind(v) {
|
|
21
|
+
const s = asString(v);
|
|
22
|
+
return WISDOM_KINDS.includes(s) ? s : null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 从 LLM 文本提取 `{items, droppedNotes}`。
|
|
26
|
+
*
|
|
27
|
+
* @param text - LLM 输出
|
|
28
|
+
* @returns 解析结果或 null
|
|
29
|
+
*/
|
|
30
|
+
export function parseWisdomFormationJson(text) {
|
|
31
|
+
const start = text.indexOf('{');
|
|
32
|
+
if (start === -1)
|
|
33
|
+
return null;
|
|
34
|
+
const end = text.lastIndexOf('}');
|
|
35
|
+
if (end <= start)
|
|
36
|
+
return null;
|
|
37
|
+
try {
|
|
38
|
+
const obj = JSON.parse(text.slice(start, end + 1));
|
|
39
|
+
if (!obj || typeof obj !== 'object')
|
|
40
|
+
return null;
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 归一化 raw → 严格 Parsed(丢弃残缺项,不半写)。
|
|
49
|
+
*
|
|
50
|
+
* @param raw - 解析后的 JSON
|
|
51
|
+
* @returns 有效 items 与丢弃说明
|
|
52
|
+
*/
|
|
53
|
+
export function normalizeWisdomFormation(raw) {
|
|
54
|
+
const items = [];
|
|
55
|
+
const droppedNotes = asStringArray(raw.droppedNotes);
|
|
56
|
+
const list = Array.isArray(raw.items) ? raw.items : [];
|
|
57
|
+
for (const it of list) {
|
|
58
|
+
if (!it || typeof it !== 'object') {
|
|
59
|
+
droppedNotes.push('non_object_item');
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const o = it;
|
|
63
|
+
const statement = asString(o.statement);
|
|
64
|
+
const scenarioObj = typeof o.scenario === 'object' && o.scenario && !Array.isArray(o.scenario)
|
|
65
|
+
? o.scenario
|
|
66
|
+
: {};
|
|
67
|
+
const pts = asStringArray(o.problemTypes).length
|
|
68
|
+
? asStringArray(o.problemTypes)
|
|
69
|
+
: asStringArray(scenarioObj.problemTypes);
|
|
70
|
+
const signals = asStringArray(o.signals ?? scenarioObj.signals);
|
|
71
|
+
const antiScenarios = asStringArray(o.antiScenarios ?? scenarioObj.antiScenarios);
|
|
72
|
+
const effect = (typeof o.effect === 'object' && o.effect ? o.effect : o);
|
|
73
|
+
const questions = asStringArray(effect.questions ?? o.questions);
|
|
74
|
+
const biases = asStringArray(effect.biases ?? o.biases);
|
|
75
|
+
const posture = asString(effect.posture ?? o.posture);
|
|
76
|
+
const derived = (typeof o.derivedFrom === 'object' && o.derivedFrom
|
|
77
|
+
? o.derivedFrom
|
|
78
|
+
: o);
|
|
79
|
+
const memoryIds = asStringArray(derived.memoryIds ?? o.memoryIds);
|
|
80
|
+
const conceptIds = asStringArray(derived.conceptIds ?? o.conceptIds);
|
|
81
|
+
const kind = parseKind(o.kind);
|
|
82
|
+
if (!statement || pts.length === 0) {
|
|
83
|
+
droppedNotes.push(`incomplete:${statement.slice(0, 24) || 'empty'}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (!questions.length && !biases.length && !posture) {
|
|
87
|
+
droppedNotes.push(`no_effect:${statement.slice(0, 24)}`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (memoryIds.length === 0 && conceptIds.length === 0) {
|
|
91
|
+
droppedNotes.push(`no_derived:${statement.slice(0, 24)}`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (!kind) {
|
|
95
|
+
droppedNotes.push(`invalid_kind:${asString(o.kind).slice(0, 16)}`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
items.push({
|
|
99
|
+
statement,
|
|
100
|
+
rationale: asString(o.rationale) || undefined,
|
|
101
|
+
problemTypes: pts,
|
|
102
|
+
signals: signals.length ? signals : undefined,
|
|
103
|
+
antiScenarios: antiScenarios.length ? antiScenarios : undefined,
|
|
104
|
+
questions: questions.length ? questions : undefined,
|
|
105
|
+
biases: biases.length ? biases : undefined,
|
|
106
|
+
posture: posture || undefined,
|
|
107
|
+
memoryIds,
|
|
108
|
+
conceptIds: conceptIds.length ? conceptIds : undefined,
|
|
109
|
+
exceptions: asStringArray(o.exceptions).length
|
|
110
|
+
? asStringArray(o.exceptions)
|
|
111
|
+
: undefined,
|
|
112
|
+
kind,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return { items, droppedNotes };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Parsed → AdmitWisdomInput(distilled 默认)。
|
|
119
|
+
*
|
|
120
|
+
* @param item - 已归一项
|
|
121
|
+
* @param options - origin / supersedesId
|
|
122
|
+
* @returns admit 入参
|
|
123
|
+
*/
|
|
124
|
+
export function toAdmitWisdomInput(item, options) {
|
|
125
|
+
return {
|
|
126
|
+
statement: item.statement,
|
|
127
|
+
rationale: item.rationale,
|
|
128
|
+
scenario: {
|
|
129
|
+
problemTypes: item.problemTypes,
|
|
130
|
+
signals: item.signals,
|
|
131
|
+
antiScenarios: item.antiScenarios,
|
|
132
|
+
},
|
|
133
|
+
effect: {
|
|
134
|
+
questions: item.questions,
|
|
135
|
+
biases: item.biases,
|
|
136
|
+
posture: item.posture,
|
|
137
|
+
},
|
|
138
|
+
derivedFrom: {
|
|
139
|
+
memoryIds: item.memoryIds,
|
|
140
|
+
conceptIds: item.conceptIds,
|
|
141
|
+
},
|
|
142
|
+
kind: item.kind,
|
|
143
|
+
origin: options?.origin ?? 'distilled',
|
|
144
|
+
exceptions: item.exceptions,
|
|
145
|
+
supersedesId: options?.supersedesId,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 炼制解析并逐条 admit。
|
|
150
|
+
*
|
|
151
|
+
* @param llmText - LLM 原文
|
|
152
|
+
* @param store - WisdomStore
|
|
153
|
+
* @param options - origin / maxItems
|
|
154
|
+
* @returns admit 结果与丢弃笔记
|
|
155
|
+
*/
|
|
156
|
+
export async function formAndAdmit(llmText, store, options) {
|
|
157
|
+
const raw = parseWisdomFormationJson(llmText);
|
|
158
|
+
if (!raw) {
|
|
159
|
+
return {
|
|
160
|
+
results: [{ action: 'rejected', reason: 'empty_statement', message: 'parse_failed' }],
|
|
161
|
+
droppedNotes: ['parse_failed'],
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const { items, droppedNotes } = normalizeWisdomFormation(raw);
|
|
165
|
+
const maxItems = options?.maxItems ?? 3;
|
|
166
|
+
const results = [];
|
|
167
|
+
for (const item of items.slice(0, maxItems)) {
|
|
168
|
+
const input = toAdmitWisdomInput(item, { origin: options?.origin });
|
|
169
|
+
if (options?.dryRun) {
|
|
170
|
+
const gate = evaluateWisdomGate(input, {
|
|
171
|
+
allowedMemoryIds: options.allowedMemoryIds,
|
|
172
|
+
});
|
|
173
|
+
results.push(gate.ok
|
|
174
|
+
? { action: 'created', message: 'dry_run' }
|
|
175
|
+
: { action: 'rejected', reason: gate.reason, message: gate.message });
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
results.push(await store.admit(input, { allowedMemoryIds: options?.allowedMemoryIds }));
|
|
179
|
+
}
|
|
180
|
+
return { results, droppedNotes };
|
|
181
|
+
}
|
|
182
|
+
// ── 场景匹配(P0 keyword;embedding/llm 留给后续,不假装已实现) ──
|
|
183
|
+
/**
|
|
184
|
+
* 关键词/字面场景匹配分。
|
|
185
|
+
*
|
|
186
|
+
* @param entry - 条目
|
|
187
|
+
* @param text - 本轮查询/任务文本
|
|
188
|
+
* @returns [0,1];无命中为 0
|
|
189
|
+
*/
|
|
190
|
+
export function scenarioMatchScore(entry, text) {
|
|
191
|
+
const q = text.toLowerCase();
|
|
192
|
+
if (!q.trim())
|
|
193
|
+
return 0;
|
|
194
|
+
const anti = (entry.scenario.antiScenarios ?? []).map((s) => s.toLowerCase());
|
|
195
|
+
if (anti.some((a) => a && q.includes(a)))
|
|
196
|
+
return 0;
|
|
197
|
+
const types = entry.scenario.problemTypes.map((s) => s.toLowerCase());
|
|
198
|
+
const signals = (entry.scenario.signals ?? []).map((s) => s.toLowerCase());
|
|
199
|
+
const words = types.concat(signals);
|
|
200
|
+
if (words.length === 0)
|
|
201
|
+
return 0;
|
|
202
|
+
let hit = 0;
|
|
203
|
+
for (const w of words) {
|
|
204
|
+
if (!w)
|
|
205
|
+
continue;
|
|
206
|
+
if (q.includes(w))
|
|
207
|
+
hit += 2;
|
|
208
|
+
else if (overlapChars(q, w))
|
|
209
|
+
hit += 1;
|
|
210
|
+
}
|
|
211
|
+
if (hit === 0)
|
|
212
|
+
return 0;
|
|
213
|
+
return Math.min(1, hit / (words.length * 2));
|
|
214
|
+
}
|
|
215
|
+
function overlapChars(q, w) {
|
|
216
|
+
// CJK 友好:词全字面出现在 q 已由 includes 覆盖;此处做 2-gram 弱重叠
|
|
217
|
+
if (w.length < 2)
|
|
218
|
+
return false;
|
|
219
|
+
for (let i = 0; i < w.length - 1; i++) {
|
|
220
|
+
const g = w.slice(i, i + 2);
|
|
221
|
+
if (q.includes(g))
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 选择注入集:小核心 + 场景匹配。
|
|
228
|
+
*
|
|
229
|
+
* @param entries - 可注入条目(store 已滤状态)
|
|
230
|
+
* @param text - 本轮文本
|
|
231
|
+
* @param options - 条数硬顶
|
|
232
|
+
* @returns 排序后的注入选择
|
|
233
|
+
*/
|
|
234
|
+
export function pickForInjection(entries, text, options) {
|
|
235
|
+
const coreMax = options?.coreMaxItems ?? 8;
|
|
236
|
+
const scenarioMax = options?.scenarioMaxItems ?? 8;
|
|
237
|
+
const includeTrial = options?.includeTrial ?? false;
|
|
238
|
+
const usable = entries.filter((e) => {
|
|
239
|
+
if (e.status === 'retired' || e.status === 'superseded' || e.status === 'candidate')
|
|
240
|
+
return false;
|
|
241
|
+
if (e.status === 'contested')
|
|
242
|
+
return false;
|
|
243
|
+
if (e.status === 'trial' && !includeTrial)
|
|
244
|
+
return false;
|
|
245
|
+
return true;
|
|
246
|
+
});
|
|
247
|
+
const scored = usable.map((e) => ({
|
|
248
|
+
entry: e,
|
|
249
|
+
match: scenarioMatchScore(e, text),
|
|
250
|
+
score: wisdomInjectScore(e, 1),
|
|
251
|
+
scenarioScore: wisdomInjectScore(e, scenarioMatchScore(e, text)),
|
|
252
|
+
}));
|
|
253
|
+
// core:宽覆盖(多 problemTypes 或 strengthened/factory)优先
|
|
254
|
+
const coreCandidates = scored
|
|
255
|
+
.filter((s) => s.entry.origin === 'factory' || s.entry.status === 'strengthened' || s.entry.scenario.problemTypes.length >= 2)
|
|
256
|
+
.sort((a, b) => b.score - a.score)
|
|
257
|
+
.slice(0, coreMax)
|
|
258
|
+
.map((s) => ({ entry: s.entry, bucket: 'core', score: 1 }));
|
|
259
|
+
const coreIds = new Set(coreCandidates.map((c) => c.entry.id));
|
|
260
|
+
const scenario = scored
|
|
261
|
+
.filter((s) => s.match > 0 && !coreIds.has(s.entry.id))
|
|
262
|
+
.sort((a, b) => b.scenarioScore - a.scenarioScore)
|
|
263
|
+
.slice(0, scenarioMax)
|
|
264
|
+
.map((s) => ({ entry: s.entry, bucket: 'scenario', score: s.match }));
|
|
265
|
+
return [...coreCandidates, ...scenario];
|
|
266
|
+
}
|
|
267
|
+
// ── 注入排版 ──
|
|
268
|
+
/**
|
|
269
|
+
* 按 problemTypes 分组渲染 system 片段(不含 # 思维框架 头,由 WisdomLayer 加)。
|
|
270
|
+
*
|
|
271
|
+
* @param picks - 注入选择
|
|
272
|
+
* @returns 正文
|
|
273
|
+
*/
|
|
274
|
+
export function formatWisdomBody(picks) {
|
|
275
|
+
if (picks.length === 0)
|
|
276
|
+
return '';
|
|
277
|
+
const byType = new Map();
|
|
278
|
+
for (const p of picks) {
|
|
279
|
+
const key = p.entry.scenario.problemTypes[0] ?? '通用';
|
|
280
|
+
const list = byType.get(key) ?? [];
|
|
281
|
+
list.push(p.entry);
|
|
282
|
+
byType.set(key, list);
|
|
283
|
+
}
|
|
284
|
+
const blocks = [];
|
|
285
|
+
for (const [type, list] of byType) {
|
|
286
|
+
const lines = list.map((e) => formatWisdomBullet(e));
|
|
287
|
+
blocks.push(`## 面对「${type}」\n\n${lines.join('\n\n')}`);
|
|
288
|
+
}
|
|
289
|
+
return blocks.join('\n\n');
|
|
290
|
+
}
|
|
291
|
+
function formatWisdomBullet(e) {
|
|
292
|
+
const parts = [`- ${e.statement}`];
|
|
293
|
+
const effectBits = [];
|
|
294
|
+
if (e.effect.posture)
|
|
295
|
+
effectBits.push(`推理姿态:${e.effect.posture}`);
|
|
296
|
+
if (e.effect.questions?.length)
|
|
297
|
+
effectBits.push(`先问:${e.effect.questions.join(';')}`);
|
|
298
|
+
if (effectBits.length)
|
|
299
|
+
parts.push(` ${effectBits.join('。')}。`);
|
|
300
|
+
const anti = e.scenario.antiScenarios?.[0];
|
|
301
|
+
if (anti)
|
|
302
|
+
parts.push(` 不适用:${anti}`);
|
|
303
|
+
return parts.join('\n');
|
|
304
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wisdom gates — 范式准入执法(结构,不猜语义)
|
|
3
|
+
*
|
|
4
|
+
* 意图判断(是不是思维范式、适用域)归 LLM;本模块只做:
|
|
5
|
+
* 结构完整性、W2 多源、密钥形态、人格/宪法改写句、容量、对立冲突启发。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/wisdom-gates
|
|
8
|
+
*/
|
|
9
|
+
import type { AdmitWisdomInput, WisdomEntry, WisdomGateOutcome, WisdomStatus } from './types.js';
|
|
10
|
+
export declare const WISDOM_DEFAULT_MIN_SUPPORT = 2;
|
|
11
|
+
/**
|
|
12
|
+
* 结构 + W2 出生门控。
|
|
13
|
+
*
|
|
14
|
+
* @param input - 候选 maxim
|
|
15
|
+
* @param options - capacityAdmitStop / minSupport / allowedMemoryIds / 与库内条目的冲突样本
|
|
16
|
+
* @returns 是否准入与 reason code
|
|
17
|
+
*/
|
|
18
|
+
export declare function evaluateWisdomGate(input: AdmitWisdomInput, options?: {
|
|
19
|
+
capacityAdmitStop?: boolean;
|
|
20
|
+
minSupport?: number;
|
|
21
|
+
/**
|
|
22
|
+
* 允许的 memoryId 白名单(炼制证据包)。
|
|
23
|
+
* 提供时 derivedFrom 中出现未知 id 即拒(防 LLM 幻觉溯源)。
|
|
24
|
+
*/
|
|
25
|
+
allowedMemoryIds?: ReadonlySet<string>;
|
|
26
|
+
/** 库内已条目(查重与对立);缺省跳过冲突启发 */
|
|
27
|
+
existing?: Pick<WisdomEntry, 'id' | 'statement' | 'status' | 'kind'>[];
|
|
28
|
+
}): WisdomGateOutcome;
|
|
29
|
+
/**
|
|
30
|
+
* resolve 初始状态。
|
|
31
|
+
*
|
|
32
|
+
* distilled 一律 trial(挣得 confidence);factory 可 active;agent_write 可 trial|active。
|
|
33
|
+
* initialStatus 不得把 distilled 送进 active(门控已拦,此处兜底)。
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveInitialWisdomStatus(input: AdmitWisdomInput): WisdomStatus;
|
|
36
|
+
/**
|
|
37
|
+
* 归一化陈述用于查重。
|
|
38
|
+
*
|
|
39
|
+
* @param s - 原文
|
|
40
|
+
* @returns 去标点空白的小写串
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeStatement(s: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* 保守对立启发:同主题词重叠 + 互斥义务词。宁可漏拦,不可误杀。
|
|
45
|
+
*
|
|
46
|
+
* @param a - 新陈述
|
|
47
|
+
* @param b - 既有陈述
|
|
48
|
+
* @returns 是否疑似对立
|
|
49
|
+
*/
|
|
50
|
+
export declare function looksOpposed(a: string, b: string): boolean;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wisdom gates — 范式准入执法(结构,不猜语义)
|
|
3
|
+
*
|
|
4
|
+
* 意图判断(是不是思维范式、适用域)归 LLM;本模块只做:
|
|
5
|
+
* 结构完整性、W2 多源、密钥形态、人格/宪法改写句、容量、对立冲突启发。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/wisdom-gates
|
|
8
|
+
*/
|
|
9
|
+
import { WISDOM_KINDS, WISDOM_ORIGINS, WISDOM_STATUSES } from './types.js';
|
|
10
|
+
const SECRET_LIKE = /(?:api[_-]?key|secret|password|token|credential)\s*[:=]\s*\S{8,}/i;
|
|
11
|
+
/** 人格/宪法改写句:禁止用 Wisdom 覆盖身份或安全边界 */
|
|
12
|
+
const PERSONA_OVERWRITE = /(?:你必须|我是|本人是|改写(?:身份|人格|安全)|忽略(?:安全|宪法|政策)|disable\s+(?:safety|guard))/i;
|
|
13
|
+
const STATEMENT_MAX_LEN = 240;
|
|
14
|
+
export const WISDOM_DEFAULT_MIN_SUPPORT = 2;
|
|
15
|
+
/**
|
|
16
|
+
* 结构 + W2 出生门控。
|
|
17
|
+
*
|
|
18
|
+
* @param input - 候选 maxim
|
|
19
|
+
* @param options - capacityAdmitStop / minSupport / allowedMemoryIds / 与库内条目的冲突样本
|
|
20
|
+
* @returns 是否准入与 reason code
|
|
21
|
+
*/
|
|
22
|
+
export function evaluateWisdomGate(input, options) {
|
|
23
|
+
const statement = (input.statement ?? '').trim();
|
|
24
|
+
if (!statement)
|
|
25
|
+
return { ok: false, reason: 'empty_statement' };
|
|
26
|
+
if (statement.length > STATEMENT_MAX_LEN) {
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
reason: 'statement_too_long',
|
|
30
|
+
message: `len=${statement.length} max=${STATEMENT_MAX_LEN}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (SECRET_LIKE.test(statement) || SECRET_LIKE.test(input.rationale ?? '')) {
|
|
34
|
+
return { ok: false, reason: 'secret_like' };
|
|
35
|
+
}
|
|
36
|
+
if (PERSONA_OVERWRITE.test(statement)) {
|
|
37
|
+
return { ok: false, reason: 'persona_overwrite' };
|
|
38
|
+
}
|
|
39
|
+
const problemTypes = (input.scenario?.problemTypes ?? []).map((s) => s.trim()).filter(Boolean);
|
|
40
|
+
if (problemTypes.length === 0) {
|
|
41
|
+
return { ok: false, reason: 'empty_problem_types' };
|
|
42
|
+
}
|
|
43
|
+
const effect = input.effect ?? {};
|
|
44
|
+
const hasEffect = (effect.questions?.some((q) => q.trim())) ||
|
|
45
|
+
(effect.biases?.some((b) => b.trim())) ||
|
|
46
|
+
Boolean(effect.posture?.trim());
|
|
47
|
+
if (!hasEffect) {
|
|
48
|
+
return { ok: false, reason: 'empty_effect', message: 'need questions|biases|posture' };
|
|
49
|
+
}
|
|
50
|
+
if (!WISDOM_KINDS.includes(input.kind)) {
|
|
51
|
+
return { ok: false, reason: 'invalid_kind', message: `kind=${input.kind}` };
|
|
52
|
+
}
|
|
53
|
+
const origin = input.origin ?? 'distilled';
|
|
54
|
+
if (!WISDOM_ORIGINS.includes(origin)) {
|
|
55
|
+
return { ok: false, reason: 'invalid_origin', message: `origin=${origin}` };
|
|
56
|
+
}
|
|
57
|
+
if (input.initialStatus) {
|
|
58
|
+
if (!WISDOM_STATUSES.includes(input.initialStatus)) {
|
|
59
|
+
return { ok: false, reason: 'invalid_status', message: `status=${input.initialStatus}` };
|
|
60
|
+
}
|
|
61
|
+
// 出生不得 strengthened / contested / retired / superseded
|
|
62
|
+
const allowedInitial = ['candidate', 'trial', 'active'];
|
|
63
|
+
if (!allowedInitial.includes(input.initialStatus)) {
|
|
64
|
+
return {
|
|
65
|
+
ok: false,
|
|
66
|
+
reason: 'invalid_status',
|
|
67
|
+
message: `initialStatus=${input.initialStatus} not in ${allowedInitial.join('|')}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// distilled 一律不得直达 active(挣得 confidence)
|
|
71
|
+
if (origin === 'distilled' && input.initialStatus === 'active') {
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
reason: 'invalid_status',
|
|
75
|
+
message: 'distilled must start at trial',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const memoryIds = input.derivedFrom?.memoryIds ?? [];
|
|
80
|
+
const supportCount = memoryIds.length +
|
|
81
|
+
(input.derivedFrom?.conceptIds?.length ?? 0) +
|
|
82
|
+
(input.derivedFrom?.communityId ? 1 : 0);
|
|
83
|
+
const minSupport = options?.minSupport ?? WISDOM_DEFAULT_MIN_SUPPORT;
|
|
84
|
+
// factory 可零源(出厂预设);显式取代允许单源;distilled 坚持 MDL 多源
|
|
85
|
+
const supportFloor = origin === 'factory' ? 0 : input.supersedesId ? 1 : minSupport;
|
|
86
|
+
if (supportCount < supportFloor) {
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
reason: 'insufficient_support',
|
|
90
|
+
message: `support=${supportCount} min=${supportFloor} origin=${origin}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (supportCount === 0 && origin !== 'factory') {
|
|
94
|
+
return { ok: false, reason: 'missing_derived_from' };
|
|
95
|
+
}
|
|
96
|
+
// 溯源必须落在证据包内(防 LLM 幻觉 id)
|
|
97
|
+
if (options?.allowedMemoryIds) {
|
|
98
|
+
const unknown = memoryIds.filter((id) => !options.allowedMemoryIds.has(id));
|
|
99
|
+
if (unknown.length > 0) {
|
|
100
|
+
return {
|
|
101
|
+
ok: false,
|
|
102
|
+
reason: 'unknown_derived_id',
|
|
103
|
+
message: `unknown=${unknown.slice(0, 5).join(',')}`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (options?.capacityAdmitStop && origin !== 'factory' && !input.supersedesId) {
|
|
108
|
+
return { ok: false, reason: 'capacity_admit_stop' };
|
|
109
|
+
}
|
|
110
|
+
if (options?.existing?.length) {
|
|
111
|
+
const norm = normalizeStatement(statement);
|
|
112
|
+
for (const ex of options.existing) {
|
|
113
|
+
// 只与已站稳的范式冲突检测;candidate/trial 不挡新条
|
|
114
|
+
if (ex.status !== 'active' && ex.status !== 'strengthened')
|
|
115
|
+
continue;
|
|
116
|
+
const exNorm = normalizeStatement(ex.statement);
|
|
117
|
+
if (exNorm === norm && !input.supersedesId) {
|
|
118
|
+
return {
|
|
119
|
+
ok: false,
|
|
120
|
+
reason: 'duplicate_statement',
|
|
121
|
+
message: `dup_of=${ex.id}`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// 字面-语义对立启发:同一宾语 + 互斥谓词(不做全文 NLI)
|
|
125
|
+
if (!input.supersedesId && looksOpposed(statement, ex.statement)) {
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
reason: 'semantic_conflict',
|
|
129
|
+
message: `conflict_with=${ex.id}`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, reason: 'ok' };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* resolve 初始状态。
|
|
138
|
+
*
|
|
139
|
+
* distilled 一律 trial(挣得 confidence);factory 可 active;agent_write 可 trial|active。
|
|
140
|
+
* initialStatus 不得把 distilled 送进 active(门控已拦,此处兜底)。
|
|
141
|
+
*/
|
|
142
|
+
export function resolveInitialWisdomStatus(input) {
|
|
143
|
+
const origin = input.origin ?? 'distilled';
|
|
144
|
+
if (input.initialStatus) {
|
|
145
|
+
if (origin === 'distilled' && input.initialStatus === 'active')
|
|
146
|
+
return 'trial';
|
|
147
|
+
return input.initialStatus;
|
|
148
|
+
}
|
|
149
|
+
if (origin === 'factory')
|
|
150
|
+
return 'active';
|
|
151
|
+
return 'trial';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 归一化陈述用于查重。
|
|
155
|
+
*
|
|
156
|
+
* @param s - 原文
|
|
157
|
+
* @returns 去标点空白的小写串
|
|
158
|
+
*/
|
|
159
|
+
export function normalizeStatement(s) {
|
|
160
|
+
return s
|
|
161
|
+
.toLowerCase()
|
|
162
|
+
.replace(/[\s\p{P}\p{S}]+/gu, '')
|
|
163
|
+
.trim();
|
|
164
|
+
}
|
|
165
|
+
const OPPOSITE_PAIRS = [
|
|
166
|
+
[/(必须|应该|应当)/, /(禁止|不得|不要|不应)/],
|
|
167
|
+
[/(禁止|不得|不要|不应)/, /(必须|应该|应当)/],
|
|
168
|
+
[/(优先|先)/, /(禁止|不得)/],
|
|
169
|
+
];
|
|
170
|
+
/**
|
|
171
|
+
* 保守对立启发:同主题词重叠 + 互斥义务词。宁可漏拦,不可误杀。
|
|
172
|
+
*
|
|
173
|
+
* @param a - 新陈述
|
|
174
|
+
* @param b - 既有陈述
|
|
175
|
+
* @returns 是否疑似对立
|
|
176
|
+
*/
|
|
177
|
+
export function looksOpposed(a, b) {
|
|
178
|
+
const pair = OPPOSITE_PAIRS.find(([pos, neg]) => (pos.test(a) && neg.test(b)) || (neg.test(a) && pos.test(b)));
|
|
179
|
+
if (!pair)
|
|
180
|
+
return false;
|
|
181
|
+
// 需要足够共享字面,避免「必须备份」vs「禁止提交密钥」误报
|
|
182
|
+
return sharedBigramRatio(a, b) >= 0.22;
|
|
183
|
+
}
|
|
184
|
+
function sharedBigramRatio(a, b) {
|
|
185
|
+
const na = normalizeStatement(a);
|
|
186
|
+
const nb = normalizeStatement(b);
|
|
187
|
+
if (!na || !nb)
|
|
188
|
+
return 0;
|
|
189
|
+
const setA = bigrams(na);
|
|
190
|
+
const setB = bigrams(nb);
|
|
191
|
+
if (setA.size === 0 || setB.size === 0)
|
|
192
|
+
return 0;
|
|
193
|
+
let hit = 0;
|
|
194
|
+
for (const g of setA)
|
|
195
|
+
if (setB.has(g))
|
|
196
|
+
hit++;
|
|
197
|
+
return hit / Math.min(setA.size, setB.size);
|
|
198
|
+
}
|
|
199
|
+
function bigrams(s) {
|
|
200
|
+
const out = new Set();
|
|
201
|
+
for (let i = 0; i < s.length - 1; i++)
|
|
202
|
+
out.add(s.slice(i, i + 2));
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wisdom policy — 评估/治理确定性策略
|
|
3
|
+
*
|
|
4
|
+
* 弱归因贝叶斯更新、utility 淘汰、priority 衰减、状态迁移规划。
|
|
5
|
+
* 代码执法;不调用 LLM。规范:arch/wisdom-layer-formation.md §5–§8。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/wisdom-policy
|
|
8
|
+
*/
|
|
9
|
+
import type { WisdomEntry, WisdomOutcomeEvent, WisdomStatus } from './types.js';
|
|
10
|
+
export interface WisdomEvaluationConfig {
|
|
11
|
+
/** trial 期正向学习率 */
|
|
12
|
+
trialAlpha?: number;
|
|
13
|
+
/** trial 期负向学习率 */
|
|
14
|
+
trialBeta?: number;
|
|
15
|
+
/** active 期 */
|
|
16
|
+
activeAlpha?: number;
|
|
17
|
+
activeBeta?: number;
|
|
18
|
+
/** strengthened 期(更钝,防单次戏剧事件翻盘) */
|
|
19
|
+
strongAlpha?: number;
|
|
20
|
+
strongBeta?: number;
|
|
21
|
+
/** trial→active 最少 applied */
|
|
22
|
+
minAppliesForActive?: number;
|
|
23
|
+
/** contested 触发:窗口内 contested/applied 比例 */
|
|
24
|
+
contestRate?: number;
|
|
25
|
+
/** contested 触发:counterevidence 权重和 */
|
|
26
|
+
counterevidenceWeight?: number;
|
|
27
|
+
/** active→strengthened:最低 applied + 低 contest */
|
|
28
|
+
strengthenMinApplies?: number;
|
|
29
|
+
strengthenMaxContestRate?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare const DEFAULT_WISDOM_EVALUATION: Required<WisdomEvaluationConfig>;
|
|
32
|
+
export interface WisdomGovernConfig {
|
|
33
|
+
/** active+trial+strengthened 软顶 */
|
|
34
|
+
softCap?: number;
|
|
35
|
+
/** 硬顶(admit stop) */
|
|
36
|
+
hardCap?: number;
|
|
37
|
+
/** 零应用衰减 idle(ms) */
|
|
38
|
+
zeroApplyIdleMs?: number;
|
|
39
|
+
/** priority 衰减步长 */
|
|
40
|
+
priorityDecayStep?: number;
|
|
41
|
+
/** priority 触底 → retired */
|
|
42
|
+
priorityFloor?: number;
|
|
43
|
+
dryRun?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const DEFAULT_WISDOM_GOVERN: Required<Omit<WisdomGovernConfig, 'dryRun'>> & {
|
|
46
|
+
dryRun: boolean;
|
|
47
|
+
};
|
|
48
|
+
export interface WisdomConfidenceUpdate {
|
|
49
|
+
id: string;
|
|
50
|
+
confidence: number;
|
|
51
|
+
status: WisdomStatus;
|
|
52
|
+
reason: string;
|
|
53
|
+
/** 写回水位,防止终身累计被重复折进 confidence */
|
|
54
|
+
evalAssisted: number;
|
|
55
|
+
evalContested: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 结局事件折叠到条目计数。
|
|
59
|
+
*
|
|
60
|
+
* @param entry - 当前条目(不修改)
|
|
61
|
+
* @param events - 该条相关信号
|
|
62
|
+
* @returns 更新后的 outcomes 计数与时间戳
|
|
63
|
+
*/
|
|
64
|
+
export declare function foldOutcomeEvents(entry: Pick<WisdomEntry, 'outcomes'>, events: Array<Pick<WisdomOutcomeEvent, 'signal' | 'at'>>): Pick<WisdomEntry, 'outcomes'>;
|
|
65
|
+
/**
|
|
66
|
+
* 贝叶斯风格 confidence 弱更新 + 状态迁移规划。
|
|
67
|
+
*
|
|
68
|
+
* **只对增量生效**:`outcomes.assisted/contested` 终身累计,与水位
|
|
69
|
+
* `evalAssisted/evalContested` 之差才是本轮增量。空跑 pulse 不得再拉 confidence。
|
|
70
|
+
* applied=0 只影响 priority(govern),不减 confidence。
|
|
71
|
+
*
|
|
72
|
+
* @param entry - 条目
|
|
73
|
+
* @param cfg - 评估参数
|
|
74
|
+
* @param now - 当前时间
|
|
75
|
+
* @returns 是否需要写回与新值(含水位);无需写回时 null
|
|
76
|
+
*/
|
|
77
|
+
export declare function planConfidenceUpdate(entry: WisdomEntry, cfg?: WisdomEvaluationConfig, now?: number): WisdomConfidenceUpdate | null;
|
|
78
|
+
export interface WisdomGoverPlanItem {
|
|
79
|
+
id: string;
|
|
80
|
+
action: 'decay_priority' | 'retire';
|
|
81
|
+
reason: string;
|
|
82
|
+
priority?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 容量演化 + 零应用衰减规划。
|
|
86
|
+
*
|
|
87
|
+
* @param entries - 存活条目(不含 retired/superseded)
|
|
88
|
+
* @param cfg - 治理参数
|
|
89
|
+
* @param now - 当前时间
|
|
90
|
+
* @returns 治理动作列表
|
|
91
|
+
*/
|
|
92
|
+
export declare function planWisdomGovern(entries: WisdomEntry[], cfg?: WisdomGovernConfig, now?: number): WisdomGoverPlanItem[];
|
|
93
|
+
/**
|
|
94
|
+
* utility = confidence × (0.5 + 0.5·normalizedApplies) × (priority/100)
|
|
95
|
+
*
|
|
96
|
+
* @param e - 条目
|
|
97
|
+
* @returns 淘汰排序分
|
|
98
|
+
*/
|
|
99
|
+
export declare function wisdomUtility(e: WisdomEntry): number;
|
|
100
|
+
/**
|
|
101
|
+
* 注入选择打分。
|
|
102
|
+
*
|
|
103
|
+
* @param entry - 条目
|
|
104
|
+
* @param matchScore - 场景匹配分 [0,1];core 用 1
|
|
105
|
+
* @returns 注入排序分
|
|
106
|
+
*/
|
|
107
|
+
export declare function wisdomInjectScore(entry: WisdomEntry, matchScore: number): number;
|