@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
|
@@ -79,6 +79,7 @@ export declare class SqliteMemoryStore implements MemoryStore {
|
|
|
79
79
|
winnerId?: string;
|
|
80
80
|
}): Promise<void>;
|
|
81
81
|
undelete(id: string): Promise<void>;
|
|
82
|
+
importEntry(entry: MemoryEntry): Promise<void>;
|
|
82
83
|
listForGovern(filter?: {
|
|
83
84
|
includeDeleted?: boolean;
|
|
84
85
|
}): Promise<MemoryEntry[]>;
|
|
@@ -90,9 +90,9 @@ export class SqliteMemoryStore {
|
|
|
90
90
|
INSERT INTO memories (
|
|
91
91
|
id, type, content, source, confidence, importance,
|
|
92
92
|
access_count, last_accessed_at, created_at, decay_factor, tags, embedding,
|
|
93
|
-
status, channel, future_use, anchors, evidence, deleted
|
|
94
|
-
) VALUES (?, ?, ?, ?, ?, ?, 0, ?, ?, 1.0, ?, ?, ?, ?, ?, ?, ?, 0)
|
|
95
|
-
`).run(id, mapLegacyType(entry.type), entry.content, entry.source, entry.confidence, entry.importance, now, now, JSON.stringify(entry.tags ?? []), embeddingStr, entry.status ?? 'active', entry.channel ?? 'model_inference', entry.futureUse ?? null, JSON.stringify(entry.anchors ?? []), entry.evidence ?? null);
|
|
93
|
+
status, channel, future_use, anchors, evidence, deleted, as_of
|
|
94
|
+
) VALUES (?, ?, ?, ?, ?, ?, 0, ?, ?, 1.0, ?, ?, ?, ?, ?, ?, ?, 0, ?)
|
|
95
|
+
`).run(id, mapLegacyType(entry.type), entry.content, entry.source, entry.confidence, entry.importance, now, now, JSON.stringify(entry.tags ?? []), embeddingStr, entry.status ?? 'active', entry.channel ?? 'model_inference', entry.futureUse ?? null, JSON.stringify(entry.anchors ?? []), entry.evidence ?? null, entry.asOf ?? null);
|
|
96
96
|
if (embeddingStr && this.vecReady) {
|
|
97
97
|
try {
|
|
98
98
|
const vec = parseEmbedding(embeddingStr);
|
|
@@ -207,7 +207,7 @@ export class SqliteMemoryStore {
|
|
|
207
207
|
const vis = this.visibilityWhere(query);
|
|
208
208
|
const cap = this.candidateCap;
|
|
209
209
|
const minSim = query.minSimilarity ?? this.defaultMinSimilarity;
|
|
210
|
-
let sql = `SELECT id, type, content, source, confidence, importance, access_count, last_accessed_at, created_at, decay_factor, tags, embedding, status, channel, future_use, anchors, evidence, deleted, deleted_at, deleted_by, deleted_reason, deleted_meta, reinforced_at
|
|
210
|
+
let sql = `SELECT id, type, content, source, confidence, importance, access_count, last_accessed_at, created_at, decay_factor, tags, embedding, status, channel, future_use, anchors, evidence, deleted, deleted_at, deleted_by, deleted_reason, deleted_meta, reinforced_at, as_of
|
|
211
211
|
FROM memories WHERE embedding IS NOT NULL${vis.sql}`;
|
|
212
212
|
const params = [...vis.params];
|
|
213
213
|
if (query.type) {
|
|
@@ -460,6 +460,8 @@ export class SqliteMemoryStore {
|
|
|
460
460
|
set('evidence', patch.evidence);
|
|
461
461
|
if (patch.reinforcedAt !== undefined)
|
|
462
462
|
set('reinforced_at', patch.reinforcedAt);
|
|
463
|
+
if (patch.asOf !== undefined)
|
|
464
|
+
set('as_of', patch.asOf);
|
|
463
465
|
if (patch.deleted !== undefined)
|
|
464
466
|
set('deleted', patch.deleted ? 1 : 0);
|
|
465
467
|
if (patch.deletedAt !== undefined)
|
|
@@ -524,6 +526,13 @@ export class SqliteMemoryStore {
|
|
|
524
526
|
WHERE id = ?
|
|
525
527
|
`).run(id);
|
|
526
528
|
}
|
|
529
|
+
async importEntry(entry) {
|
|
530
|
+
this.db.raw.prepare(`INSERT OR REPLACE INTO memories (
|
|
531
|
+
id, type, content, source, confidence, importance,
|
|
532
|
+
access_count, last_accessed_at, created_at, decay_factor, tags, embedding,
|
|
533
|
+
status, channel, future_use, anchors, evidence, deleted, as_of
|
|
534
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(entry.id, mapLegacyType(entry.type), entry.content, entry.source, entry.confidence, entry.importance, entry.accessCount ?? 0, entry.lastAccessedAt ?? Date.now(), entry.createdAt ?? Date.now(), entry.decayFactor ?? 1, JSON.stringify(entry.tags ?? []), null, entry.status ?? 'active', entry.channel ?? 'model_inference', entry.futureUse ?? null, JSON.stringify(entry.anchors ?? []), entry.evidence ?? null, entry.deleted ? 1 : 0, entry.asOf ?? null);
|
|
535
|
+
}
|
|
527
536
|
async listForGovern(filter) {
|
|
528
537
|
const sql = filter?.includeDeleted
|
|
529
538
|
? 'SELECT * FROM memories'
|
|
@@ -588,6 +597,7 @@ export class SqliteMemoryStore {
|
|
|
588
597
|
anchors: row.anchors ? JSON.parse(row.anchors) : [],
|
|
589
598
|
evidence: row.evidence ?? undefined,
|
|
590
599
|
reinforcedAt: row.reinforced_at ?? undefined,
|
|
600
|
+
asOf: row.as_of ?? undefined,
|
|
591
601
|
deleted: !!row.deleted,
|
|
592
602
|
deletedAt: row.deleted_at ?? undefined,
|
|
593
603
|
deletedBy: row.deleted_by ?? undefined,
|
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SqliteWisdomStore — SQLite
|
|
2
|
+
* SqliteWisdomStore — 判断范式(maxim)SQLite 存储
|
|
3
|
+
*
|
|
4
|
+
* 写入只经 admit(门控在 wisdom-gates)。无旧 content 形态兼容。
|
|
3
5
|
*
|
|
4
6
|
* @module
|
|
5
7
|
*/
|
|
6
|
-
import type {
|
|
8
|
+
import type { AdmitWisdomInput, AdmitWisdomResult, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomOutcomeEvent, WisdomRetireReason, WisdomStats, WisdomStore } from '../types.js';
|
|
7
9
|
import { AgentDatabase } from './agent-db.js';
|
|
10
|
+
export interface SqliteWisdomStoreOptions {
|
|
11
|
+
/** admit 硬顶(存活面);默认 80 */
|
|
12
|
+
hardCap?: number;
|
|
13
|
+
}
|
|
8
14
|
export declare class SqliteWisdomStore implements WisdomStore {
|
|
15
|
+
readonly name = "sqlite-wisdom";
|
|
9
16
|
private db;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
private readonly hardCapLimit;
|
|
18
|
+
constructor(db: AgentDatabase, options?: SqliteWisdomStoreOptions);
|
|
19
|
+
admit(input: AdmitWisdomInput, options?: {
|
|
20
|
+
allowedMemoryIds?: ReadonlySet<string>;
|
|
21
|
+
}): Promise<AdmitWisdomResult>;
|
|
22
|
+
get(id: string): Promise<WisdomEntry | null>;
|
|
23
|
+
selectForInjection(query: WisdomInjectQuery): Promise<WisdomInjectPick[]>;
|
|
24
|
+
listForGovern(filter?: {
|
|
25
|
+
includeRetired?: boolean;
|
|
26
|
+
}): Promise<WisdomEntry[]>;
|
|
27
|
+
update(id: string, patch: Partial<WisdomEntry>): Promise<void>;
|
|
28
|
+
softRetire(id: string, meta: {
|
|
29
|
+
by: string;
|
|
30
|
+
reason: WisdomRetireReason | string;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
recordOutcomes(events: WisdomOutcomeEvent[]): Promise<void>;
|
|
33
|
+
touchApplied(ids: string[]): Promise<void>;
|
|
34
|
+
stats(): Promise<WisdomStats>;
|
|
35
|
+
/** 存活面计数(candidate/trial/active/strengthened/contested) */
|
|
36
|
+
countLive(): number;
|
|
37
|
+
private hardCap;
|
|
38
|
+
private livingCount;
|
|
39
|
+
private listMinimal;
|
|
40
|
+
private getSync;
|
|
22
41
|
private rowToEntry;
|
|
23
42
|
}
|
|
@@ -1,64 +1,277 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SqliteWisdomStore — SQLite
|
|
2
|
+
* SqliteWisdomStore — 判断范式(maxim)SQLite 存储
|
|
3
|
+
*
|
|
4
|
+
* 写入只经 admit(门控在 wisdom-gates)。无旧 content 形态兼容。
|
|
3
5
|
*
|
|
4
6
|
* @module
|
|
5
7
|
*/
|
|
8
|
+
import { WISDOM_STATUSES } from '../types.js';
|
|
9
|
+
import { evaluateWisdomGate, resolveInitialWisdomStatus, } from '../wisdom-gates.js';
|
|
10
|
+
import { foldOutcomeEvents, planConfidenceUpdate } from '../wisdom-policy.js';
|
|
11
|
+
import { pickForInjection } from '../wisdom-formation.js';
|
|
6
12
|
import { AgentDatabase } from './agent-db.js';
|
|
7
13
|
export class SqliteWisdomStore {
|
|
14
|
+
name = 'sqlite-wisdom';
|
|
8
15
|
db;
|
|
9
|
-
|
|
16
|
+
hardCapLimit;
|
|
17
|
+
constructor(db, options) {
|
|
10
18
|
this.db = db;
|
|
19
|
+
this.hardCapLimit = options?.hardCap ?? 80;
|
|
11
20
|
}
|
|
12
|
-
async
|
|
21
|
+
async admit(input, options) {
|
|
22
|
+
const existing = this.listMinimal();
|
|
23
|
+
const gate = evaluateWisdomGate(input, {
|
|
24
|
+
existing,
|
|
25
|
+
allowedMemoryIds: options?.allowedMemoryIds,
|
|
26
|
+
capacityAdmitStop: this.livingCount() >= this.hardCap(),
|
|
27
|
+
});
|
|
28
|
+
if (!gate.ok) {
|
|
29
|
+
return { action: 'rejected', reason: gate.reason, message: gate.message };
|
|
30
|
+
}
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const status = resolveInitialWisdomStatus(input);
|
|
13
33
|
const id = AgentDatabase.generateId('wis');
|
|
34
|
+
if (input.supersedesId) {
|
|
35
|
+
const prev = this.getSync(input.supersedesId);
|
|
36
|
+
if (!prev) {
|
|
37
|
+
return {
|
|
38
|
+
action: 'rejected',
|
|
39
|
+
reason: 'supersedes_target_missing',
|
|
40
|
+
message: `supersedesId=${input.supersedesId}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
this.db.raw
|
|
44
|
+
.prepare(`UPDATE wisdom SET status = 'superseded', superseded_by = ?, updated_at = ? WHERE id = ?`)
|
|
45
|
+
.run(id, now, prev.id);
|
|
46
|
+
}
|
|
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
|
+
return {
|
|
55
|
+
action: input.supersedesId ? 'superseded' : 'created',
|
|
56
|
+
id,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async get(id) {
|
|
60
|
+
const row = this.db.raw.prepare(`SELECT * FROM wisdom WHERE id = ?`).get(id);
|
|
61
|
+
return row ? this.rowToEntry(row) : null;
|
|
62
|
+
}
|
|
63
|
+
async selectForInjection(query) {
|
|
64
|
+
const rows = this.db.raw
|
|
65
|
+
.prepare(`SELECT * FROM wisdom WHERE status IN ('trial','active','strengthened') ORDER BY priority DESC, confidence DESC`)
|
|
66
|
+
.all();
|
|
67
|
+
const entries = rows.map((r) => this.rowToEntry(r));
|
|
68
|
+
return pickForInjection(entries, query.text ?? '', {
|
|
69
|
+
coreMaxItems: query.coreMaxItems,
|
|
70
|
+
scenarioMaxItems: query.scenarioMaxItems,
|
|
71
|
+
includeTrial: query.includeTrial,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async listForGovern(filter) {
|
|
75
|
+
const includeRetired = filter?.includeRetired ?? false;
|
|
76
|
+
const rows = (includeRetired
|
|
77
|
+
? this.db.raw.prepare(`SELECT * FROM wisdom ORDER BY updated_at DESC`).all()
|
|
78
|
+
: this.db.raw
|
|
79
|
+
.prepare(`SELECT * FROM wisdom WHERE status NOT IN ('retired') ORDER BY updated_at DESC`)
|
|
80
|
+
.all());
|
|
81
|
+
return rows.map((r) => this.rowToEntry(r));
|
|
82
|
+
}
|
|
83
|
+
async update(id, patch) {
|
|
84
|
+
const current = this.getSync(id);
|
|
85
|
+
if (!current)
|
|
86
|
+
throw new Error(`wisdom_update_not_found: ${id}`);
|
|
87
|
+
const merged = {
|
|
88
|
+
...current,
|
|
89
|
+
...patch,
|
|
90
|
+
id: current.id,
|
|
91
|
+
createdAt: current.createdAt,
|
|
92
|
+
updatedAt: Date.now(),
|
|
93
|
+
outcomes: { ...current.outcomes, ...(patch.outcomes ?? {}) },
|
|
94
|
+
};
|
|
95
|
+
this.db.raw
|
|
96
|
+
.prepare(`UPDATE wisdom SET
|
|
97
|
+
statement = ?, rationale = ?, scenario_json = ?, effect_json = ?,
|
|
98
|
+
status = ?, confidence = ?, priority = ?, derived_from_json = ?,
|
|
99
|
+
exceptions_json = ?, counterevidence_json = ?, outcomes_json = ?,
|
|
100
|
+
origin = ?, kind = ?, superseded_by = ?, updated_at = ?
|
|
101
|
+
WHERE id = ?`)
|
|
102
|
+
.run(merged.statement, merged.rationale ?? null, JSON.stringify(merged.scenario), JSON.stringify(merged.effect), merged.status, clamp01(merged.confidence), merged.priority, JSON.stringify(merged.derivedFrom), JSON.stringify(merged.exceptions ?? []), JSON.stringify(merged.counterevidence ?? []), JSON.stringify(merged.outcomes), merged.origin, merged.kind, merged.supersededBy ?? null, merged.updatedAt, id);
|
|
103
|
+
}
|
|
104
|
+
async softRetire(id, meta) {
|
|
105
|
+
const current = this.getSync(id);
|
|
106
|
+
if (!current)
|
|
107
|
+
return;
|
|
108
|
+
if (current.status === 'superseded')
|
|
109
|
+
return;
|
|
110
|
+
await this.update(id, {
|
|
111
|
+
status: 'retired',
|
|
112
|
+
exceptions: [...(current.exceptions ?? []), `retired:${meta.reason}:${meta.by}`],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
async recordOutcomes(events) {
|
|
116
|
+
if (events.length === 0)
|
|
117
|
+
return;
|
|
118
|
+
const byId = new Map();
|
|
119
|
+
for (const e of events) {
|
|
120
|
+
const list = byId.get(e.wisdomId) ?? [];
|
|
121
|
+
list.push(e);
|
|
122
|
+
byId.set(e.wisdomId, list);
|
|
123
|
+
}
|
|
124
|
+
for (const [id, evs] of byId) {
|
|
125
|
+
const current = this.getSync(id);
|
|
126
|
+
if (!current)
|
|
127
|
+
continue;
|
|
128
|
+
const folded = foldOutcomeEvents(current, evs);
|
|
129
|
+
let next = { ...current, ...folded, updatedAt: Date.now() };
|
|
130
|
+
const plan = planConfidenceUpdate(next);
|
|
131
|
+
if (plan) {
|
|
132
|
+
next = {
|
|
133
|
+
...next,
|
|
134
|
+
confidence: plan.confidence,
|
|
135
|
+
status: plan.status,
|
|
136
|
+
outcomes: {
|
|
137
|
+
...next.outcomes,
|
|
138
|
+
evalAssisted: plan.evalAssisted,
|
|
139
|
+
evalContested: plan.evalContested,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const counter = evs.filter((e) => e.signal === 'contested' && (e.ref || e.note));
|
|
144
|
+
if (counter.length) {
|
|
145
|
+
const ce = [...(next.counterevidence ?? [])];
|
|
146
|
+
for (const c of counter) {
|
|
147
|
+
ce.push({
|
|
148
|
+
ref: c.ref ?? c.wisdomId,
|
|
149
|
+
note: c.note ?? 'contested',
|
|
150
|
+
at: c.at ?? Date.now(),
|
|
151
|
+
weight: 1,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
next = { ...next, counterevidence: ce };
|
|
155
|
+
}
|
|
156
|
+
await this.update(id, next);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async touchApplied(ids) {
|
|
160
|
+
if (ids.length === 0)
|
|
161
|
+
return;
|
|
14
162
|
const now = Date.now();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
163
|
+
for (const id of ids) {
|
|
164
|
+
const cur = this.getSync(id);
|
|
165
|
+
if (!cur)
|
|
166
|
+
continue;
|
|
167
|
+
const outcomes = {
|
|
168
|
+
...cur.outcomes,
|
|
169
|
+
applied: cur.outcomes.applied + 1,
|
|
170
|
+
lastAppliedAt: now,
|
|
171
|
+
};
|
|
172
|
+
this.db.raw
|
|
173
|
+
.prepare(`UPDATE wisdom SET outcomes_json = ?, updated_at = ? WHERE id = ?`)
|
|
174
|
+
.run(JSON.stringify(outcomes), now, id);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async stats() {
|
|
178
|
+
const rows = this.db.raw.prepare(`SELECT * FROM wisdom`).all();
|
|
179
|
+
const byStatus = Object.fromEntries(WISDOM_STATUSES.map((s) => [s, 0]));
|
|
180
|
+
let confSum = 0;
|
|
181
|
+
let prioSum = 0;
|
|
182
|
+
let applied = 0;
|
|
183
|
+
let contested = 0;
|
|
184
|
+
for (const r of rows) {
|
|
185
|
+
const st = r.status ?? 'active';
|
|
186
|
+
byStatus[st] = (byStatus[st] ?? 0) + 1;
|
|
187
|
+
confSum += r.confidence;
|
|
188
|
+
prioSum += r.priority;
|
|
189
|
+
const o = safeParse(r.outcomes_json, emptyOutcomes());
|
|
190
|
+
applied += o.applied;
|
|
191
|
+
contested += o.contested;
|
|
192
|
+
}
|
|
193
|
+
const n = rows.length || 1;
|
|
194
|
+
return {
|
|
195
|
+
total: rows.length,
|
|
196
|
+
byStatus,
|
|
197
|
+
avgConfidence: confSum / n,
|
|
198
|
+
avgPriority: prioSum / n,
|
|
199
|
+
totalApplied: applied,
|
|
200
|
+
totalContested: contested,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** 存活面计数(candidate/trial/active/strengthened/contested) */
|
|
204
|
+
countLive() {
|
|
205
|
+
return this.livingCount();
|
|
206
|
+
}
|
|
207
|
+
hardCap() {
|
|
208
|
+
return this.hardCapLimit;
|
|
209
|
+
}
|
|
210
|
+
livingCount() {
|
|
211
|
+
const row = this.db.raw
|
|
212
|
+
.prepare(`SELECT COUNT(*) as c FROM wisdom WHERE status IN ('candidate','trial','active','strengthened','contested')`)
|
|
213
|
+
.get();
|
|
214
|
+
return row.c;
|
|
215
|
+
}
|
|
216
|
+
listMinimal() {
|
|
217
|
+
const rows = this.db.raw
|
|
218
|
+
.prepare(`SELECT id, statement, status, kind FROM wisdom WHERE status NOT IN ('retired')`)
|
|
219
|
+
.all();
|
|
220
|
+
return rows;
|
|
221
|
+
}
|
|
222
|
+
getSync(id) {
|
|
223
|
+
const row = this.db.raw.prepare(`SELECT * FROM wisdom WHERE id = ?`).get(id);
|
|
224
|
+
return row ? this.rowToEntry(row) : null;
|
|
53
225
|
}
|
|
54
226
|
rowToEntry(row) {
|
|
55
227
|
return {
|
|
56
228
|
id: row.id,
|
|
57
|
-
|
|
58
|
-
|
|
229
|
+
statement: row.statement,
|
|
230
|
+
rationale: row.rationale ?? undefined,
|
|
231
|
+
scenario: safeParse(row.scenario_json, { problemTypes: [] }),
|
|
232
|
+
effect: safeParse(row.effect_json, {}),
|
|
233
|
+
status: (WISDOM_STATUSES.includes(row.status)
|
|
234
|
+
? row.status
|
|
235
|
+
: 'active'),
|
|
236
|
+
confidence: row.confidence,
|
|
59
237
|
priority: row.priority,
|
|
238
|
+
derivedFrom: safeParse(row.derived_from_json, { memoryIds: [] }),
|
|
239
|
+
exceptions: safeParse(row.exceptions_json, []),
|
|
240
|
+
counterevidence: safeParse(row.counterevidence_json, []),
|
|
241
|
+
outcomes: safeParse(row.outcomes_json, emptyOutcomes()),
|
|
242
|
+
origin: row.origin,
|
|
243
|
+
kind: row.kind,
|
|
244
|
+
supersededBy: row.superseded_by ?? undefined,
|
|
60
245
|
createdAt: row.created_at,
|
|
61
|
-
|
|
246
|
+
updatedAt: row.updated_at,
|
|
62
247
|
};
|
|
63
248
|
}
|
|
64
249
|
}
|
|
250
|
+
function emptyOutcomes() {
|
|
251
|
+
return { applied: 0, cited: 0, assisted: 0, contested: 0, evalAssisted: 0, evalContested: 0 };
|
|
252
|
+
}
|
|
253
|
+
function clamp01(n) {
|
|
254
|
+
return Math.min(1, Math.max(0, n));
|
|
255
|
+
}
|
|
256
|
+
function defaultConfidence(status, origin) {
|
|
257
|
+
if (origin === 'factory' || status === 'active')
|
|
258
|
+
return 0.7;
|
|
259
|
+
return 0.5;
|
|
260
|
+
}
|
|
261
|
+
function defaultPriority(status, origin) {
|
|
262
|
+
if (origin === 'factory')
|
|
263
|
+
return 80;
|
|
264
|
+
if (status === 'active')
|
|
265
|
+
return 50;
|
|
266
|
+
return 30;
|
|
267
|
+
}
|
|
268
|
+
function safeParse(raw, fallback) {
|
|
269
|
+
if (!raw)
|
|
270
|
+
return fallback;
|
|
271
|
+
try {
|
|
272
|
+
return JSON.parse(raw);
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
return fallback;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -18,6 +18,7 @@ export declare class InMemoryMemoryStore implements MemoryStore {
|
|
|
18
18
|
winnerId?: string;
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
undelete(id: string): Promise<void>;
|
|
21
|
+
importEntry(entry: MemoryEntry): Promise<void>;
|
|
21
22
|
listForGovern(filter?: {
|
|
22
23
|
includeDeleted?: boolean;
|
|
23
24
|
}): Promise<MemoryEntry[]>;
|
|
@@ -150,6 +150,9 @@ export class InMemoryMemoryStore {
|
|
|
150
150
|
entry.deletedReason = undefined;
|
|
151
151
|
entry.deletedMeta = undefined;
|
|
152
152
|
}
|
|
153
|
+
async importEntry(entry) {
|
|
154
|
+
this.entries.set(entry.id, { ...entry });
|
|
155
|
+
}
|
|
153
156
|
async listForGovern(filter) {
|
|
154
157
|
return Array.from(this.entries.values()).filter((e) => filter?.includeDeleted || !e.deleted);
|
|
155
158
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记忆时间戳的 LLM 可读格式 — 与 Runtime `Current datetime` 同为本地墙上时钟
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 格式化 epoch ms 为 `YYYY-MM-DD HH:mm`(本地时区)
|
|
6
|
+
*
|
|
7
|
+
* @param ms - epoch 毫秒
|
|
8
|
+
* @returns 本地时钟字符串(分钟精度)
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatMemoryClock(ms: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* 解析 memory_store 的 as_of 入参(epoch ms / 数字串 / 可被 Date.parse 的日期串)
|
|
13
|
+
*
|
|
14
|
+
* @param raw - 工具入参
|
|
15
|
+
* @returns epoch ms;缺省返回 undefined
|
|
16
|
+
* @throws 无法解析为时刻时抛出
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseAsOf(raw: unknown): number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* 召回条目的时间后缀 — 显式标注 recorded / as of
|
|
21
|
+
*
|
|
22
|
+
* @param entry - 含 createdAt 与可选 asOf 的条目
|
|
23
|
+
* @returns 以 ` · ` 开头的时间后缀;createdAt 缺失时返回空串
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatMemoryTimeSuffix(entry: {
|
|
26
|
+
createdAt?: number;
|
|
27
|
+
asOf?: number;
|
|
28
|
+
}): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记忆时间戳的 LLM 可读格式 — 与 Runtime `Current datetime` 同为本地墙上时钟
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 格式化 epoch ms 为 `YYYY-MM-DD HH:mm`(本地时区)
|
|
6
|
+
*
|
|
7
|
+
* @param ms - epoch 毫秒
|
|
8
|
+
* @returns 本地时钟字符串(分钟精度)
|
|
9
|
+
*/
|
|
10
|
+
export function formatMemoryClock(ms) {
|
|
11
|
+
const d = new Date(ms);
|
|
12
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
13
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 解析 memory_store 的 as_of 入参(epoch ms / 数字串 / 可被 Date.parse 的日期串)
|
|
17
|
+
*
|
|
18
|
+
* @param raw - 工具入参
|
|
19
|
+
* @returns epoch ms;缺省返回 undefined
|
|
20
|
+
* @throws 无法解析为时刻时抛出
|
|
21
|
+
*/
|
|
22
|
+
export function parseAsOf(raw) {
|
|
23
|
+
if (raw == null || raw === '')
|
|
24
|
+
return undefined;
|
|
25
|
+
if (typeof raw === 'number' && Number.isFinite(raw))
|
|
26
|
+
return raw;
|
|
27
|
+
const s = String(raw).trim();
|
|
28
|
+
if (!s)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (/^\d+$/.test(s))
|
|
31
|
+
return Number(s);
|
|
32
|
+
const t = Date.parse(s);
|
|
33
|
+
if (!Number.isFinite(t)) {
|
|
34
|
+
throw new Error(`invalid_as_of: ${s} is not a date (use YYYY-MM-DD or epoch ms)`);
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 召回条目的时间后缀 — 显式标注 recorded / as of
|
|
40
|
+
*
|
|
41
|
+
* @param entry - 含 createdAt 与可选 asOf 的条目
|
|
42
|
+
* @returns 以 ` · ` 开头的时间后缀;createdAt 缺失时返回空串
|
|
43
|
+
*/
|
|
44
|
+
export function formatMemoryTimeSuffix(entry) {
|
|
45
|
+
if (entry.createdAt == null)
|
|
46
|
+
return '';
|
|
47
|
+
const recorded = formatMemoryClock(entry.createdAt);
|
|
48
|
+
if (entry.asOf != null) {
|
|
49
|
+
return ` · as of ${formatMemoryClock(entry.asOf)} · recorded ${recorded}`;
|
|
50
|
+
}
|
|
51
|
+
return ` · recorded ${recorded}`;
|
|
52
|
+
}
|