@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,220 @@
|
|
|
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
|
+
export const DEFAULT_WISDOM_EVALUATION = {
|
|
10
|
+
trialAlpha: 0.18,
|
|
11
|
+
trialBeta: 0.22,
|
|
12
|
+
activeAlpha: 0.1,
|
|
13
|
+
activeBeta: 0.14,
|
|
14
|
+
strongAlpha: 0.05,
|
|
15
|
+
strongBeta: 0.07,
|
|
16
|
+
minAppliesForActive: 3,
|
|
17
|
+
contestRate: 0.5,
|
|
18
|
+
counterevidenceWeight: 2.5,
|
|
19
|
+
strengthenMinApplies: 12,
|
|
20
|
+
strengthenMaxContestRate: 0.15,
|
|
21
|
+
};
|
|
22
|
+
export const DEFAULT_WISDOM_GOVERN = {
|
|
23
|
+
softCap: 50,
|
|
24
|
+
hardCap: 80,
|
|
25
|
+
zeroApplyIdleMs: 30 * 24 * 3600_000,
|
|
26
|
+
priorityDecayStep: 5,
|
|
27
|
+
priorityFloor: 5,
|
|
28
|
+
dryRun: false,
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 结局事件折叠到条目计数。
|
|
32
|
+
*
|
|
33
|
+
* @param entry - 当前条目(不修改)
|
|
34
|
+
* @param events - 该条相关信号
|
|
35
|
+
* @returns 更新后的 outcomes 计数与时间戳
|
|
36
|
+
*/
|
|
37
|
+
export function foldOutcomeEvents(entry, events) {
|
|
38
|
+
const o = {
|
|
39
|
+
applied: entry.outcomes.applied,
|
|
40
|
+
cited: entry.outcomes.cited,
|
|
41
|
+
assisted: entry.outcomes.assisted,
|
|
42
|
+
contested: entry.outcomes.contested,
|
|
43
|
+
lastAppliedAt: entry.outcomes.lastAppliedAt,
|
|
44
|
+
lastOutcomeAt: entry.outcomes.lastOutcomeAt,
|
|
45
|
+
evalAssisted: entry.outcomes.evalAssisted ?? 0,
|
|
46
|
+
evalContested: entry.outcomes.evalContested ?? 0,
|
|
47
|
+
};
|
|
48
|
+
let maxAt = o.lastOutcomeAt;
|
|
49
|
+
for (const e of events) {
|
|
50
|
+
const at = e.at ?? Date.now();
|
|
51
|
+
if (maxAt == null || at > maxAt)
|
|
52
|
+
maxAt = at;
|
|
53
|
+
switch (e.signal) {
|
|
54
|
+
case 'applied':
|
|
55
|
+
o.applied += 1;
|
|
56
|
+
o.lastAppliedAt = at;
|
|
57
|
+
break;
|
|
58
|
+
case 'cited':
|
|
59
|
+
o.cited += 1;
|
|
60
|
+
break;
|
|
61
|
+
case 'assisted':
|
|
62
|
+
o.assisted += 1;
|
|
63
|
+
break;
|
|
64
|
+
case 'contested':
|
|
65
|
+
o.contested += 1;
|
|
66
|
+
break;
|
|
67
|
+
case 'ignored':
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
o.lastOutcomeAt = maxAt;
|
|
74
|
+
return { outcomes: o };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 贝叶斯风格 confidence 弱更新 + 状态迁移规划。
|
|
78
|
+
*
|
|
79
|
+
* **只对增量生效**:`outcomes.assisted/contested` 终身累计,与水位
|
|
80
|
+
* `evalAssisted/evalContested` 之差才是本轮增量。空跑 pulse 不得再拉 confidence。
|
|
81
|
+
* applied=0 只影响 priority(govern),不减 confidence。
|
|
82
|
+
*
|
|
83
|
+
* @param entry - 条目
|
|
84
|
+
* @param cfg - 评估参数
|
|
85
|
+
* @param now - 当前时间
|
|
86
|
+
* @returns 是否需要写回与新值(含水位);无需写回时 null
|
|
87
|
+
*/
|
|
88
|
+
export function planConfidenceUpdate(entry, cfg = {}, now = Date.now()) {
|
|
89
|
+
const c = { ...DEFAULT_WISDOM_EVALUATION, ...cfg };
|
|
90
|
+
const { assisted, contested, applied } = entry.outcomes;
|
|
91
|
+
const trial = entry.status === 'trial';
|
|
92
|
+
const strong = entry.status === 'strengthened';
|
|
93
|
+
const alpha = trial ? c.trialAlpha : strong ? c.strongAlpha : c.activeAlpha;
|
|
94
|
+
const beta = trial ? c.trialBeta : strong ? c.strongBeta : c.activeBeta;
|
|
95
|
+
// 增量:只吃尚未并入 confidence 的部分
|
|
96
|
+
const dPos = Math.max(0, assisted - (entry.outcomes.evalAssisted ?? 0));
|
|
97
|
+
const dNeg = Math.max(0, contested - (entry.outcomes.evalContested ?? 0));
|
|
98
|
+
let confidence = entry.confidence;
|
|
99
|
+
if (dPos > 0) {
|
|
100
|
+
confidence = confidence + alpha * (1 - confidence) * Math.min(dPos, 5);
|
|
101
|
+
}
|
|
102
|
+
if (dNeg > 0) {
|
|
103
|
+
confidence = confidence - beta * confidence * Math.min(dNeg, 5);
|
|
104
|
+
}
|
|
105
|
+
confidence = Math.min(1, Math.max(0, confidence));
|
|
106
|
+
let status = entry.status;
|
|
107
|
+
let reason = 'noop';
|
|
108
|
+
const ceWeight = (entry.counterevidence ?? []).reduce((s, x) => s + (x.weight || 0), 0);
|
|
109
|
+
const contestRate = applied > 0 ? contested / applied : 0;
|
|
110
|
+
if (status !== 'superseded' && status !== 'retired') {
|
|
111
|
+
if (ceWeight >= c.counterevidenceWeight || (applied >= 3 && contestRate >= c.contestRate && contested >= 2)) {
|
|
112
|
+
if (status !== 'contested') {
|
|
113
|
+
status = 'contested';
|
|
114
|
+
reason = 'contest_threshold';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (status === 'trial' && applied >= c.minAppliesForActive && assisted > contested) {
|
|
118
|
+
status = 'active';
|
|
119
|
+
reason = 'trial_to_active';
|
|
120
|
+
}
|
|
121
|
+
else if ((status === 'active' || status === 'strengthened') &&
|
|
122
|
+
applied >= c.strengthenMinApplies &&
|
|
123
|
+
contestRate <= c.strengthenMaxContestRate &&
|
|
124
|
+
assisted > contested) {
|
|
125
|
+
if (status !== 'strengthened') {
|
|
126
|
+
status = 'strengthened';
|
|
127
|
+
reason = 'strengthened';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (status === 'contested' && contestRate < c.contestRate / 2 && assisted > contested) {
|
|
131
|
+
status = 'trial';
|
|
132
|
+
reason = 'contested_repair';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const nextEvalAssisted = assisted;
|
|
136
|
+
const nextEvalContested = contested;
|
|
137
|
+
const watermarkMoved = (entry.outcomes.evalAssisted ?? 0) !== nextEvalAssisted ||
|
|
138
|
+
(entry.outcomes.evalContested ?? 0) !== nextEvalContested;
|
|
139
|
+
const changed = Math.abs(confidence - entry.confidence) > 1e-6 || status !== entry.status || watermarkMoved;
|
|
140
|
+
if (!changed)
|
|
141
|
+
return null;
|
|
142
|
+
return {
|
|
143
|
+
id: entry.id,
|
|
144
|
+
confidence,
|
|
145
|
+
status,
|
|
146
|
+
reason,
|
|
147
|
+
evalAssisted: nextEvalAssisted,
|
|
148
|
+
evalContested: nextEvalContested,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 容量演化 + 零应用衰减规划。
|
|
153
|
+
*
|
|
154
|
+
* @param entries - 存活条目(不含 retired/superseded)
|
|
155
|
+
* @param cfg - 治理参数
|
|
156
|
+
* @param now - 当前时间
|
|
157
|
+
* @returns 治理动作列表
|
|
158
|
+
*/
|
|
159
|
+
export function planWisdomGovern(entries, cfg = {}, now = Date.now()) {
|
|
160
|
+
const c = { ...DEFAULT_WISDOM_GOVERN, ...cfg };
|
|
161
|
+
const plan = [];
|
|
162
|
+
const alive = entries.filter((e) => e.status !== 'retired' && e.status !== 'superseded');
|
|
163
|
+
// 零应用衰减(保护 strengthened / factory 不轻易退休,但仍降 priority)
|
|
164
|
+
for (const e of alive) {
|
|
165
|
+
const last = e.outcomes.lastAppliedAt ?? e.updatedAt;
|
|
166
|
+
const idle = now - last;
|
|
167
|
+
if (idle >= c.zeroApplyIdleMs && e.outcomes.applied === 0) {
|
|
168
|
+
const next = Math.max(c.priorityFloor, e.priority - c.priorityDecayStep);
|
|
169
|
+
if (next < e.priority) {
|
|
170
|
+
plan.push({
|
|
171
|
+
id: e.id,
|
|
172
|
+
action: 'decay_priority',
|
|
173
|
+
reason: 'zero_apply_idle',
|
|
174
|
+
priority: next,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// factory 核心不因零应用退休
|
|
178
|
+
if (e.origin !== 'factory' && e.status !== 'strengthened' && next <= c.priorityFloor) {
|
|
179
|
+
plan.push({ id: e.id, action: 'retire', reason: 'zero_apply_floor' });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// 容量:超 softCap 淘汰最低 utility(保护 factory / strengthened)
|
|
184
|
+
const living = alive.filter((e) => !plan.some((p) => p.id === e.id && p.action === 'retire'));
|
|
185
|
+
if (living.length > c.softCap) {
|
|
186
|
+
const ranked = [...living].sort((a, b) => wisdomUtility(a) - wisdomUtility(b));
|
|
187
|
+
const excess = living.length - c.softCap;
|
|
188
|
+
let dropped = 0;
|
|
189
|
+
for (const e of ranked) {
|
|
190
|
+
if (dropped >= excess)
|
|
191
|
+
break;
|
|
192
|
+
if (e.origin === 'factory' || e.status === 'strengthened')
|
|
193
|
+
continue;
|
|
194
|
+
plan.push({ id: e.id, action: 'retire', reason: 'capacity' });
|
|
195
|
+
dropped++;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return plan;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* utility = confidence × (0.5 + 0.5·normalizedApplies) × (priority/100)
|
|
202
|
+
*
|
|
203
|
+
* @param e - 条目
|
|
204
|
+
* @returns 淘汰排序分
|
|
205
|
+
*/
|
|
206
|
+
export function wisdomUtility(e) {
|
|
207
|
+
const applies = Math.min(1, e.outcomes.applied / 20);
|
|
208
|
+
return e.confidence * (0.5 + 0.5 * applies) * (e.priority / 100);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 注入选择打分。
|
|
212
|
+
*
|
|
213
|
+
* @param entry - 条目
|
|
214
|
+
* @param matchScore - 场景匹配分 [0,1];core 用 1
|
|
215
|
+
* @returns 注入排序分
|
|
216
|
+
*/
|
|
217
|
+
export function wisdomInjectScore(entry, matchScore) {
|
|
218
|
+
const statusBoost = entry.status === 'strengthened' ? 1.15 : entry.status === 'active' ? 1 : 0.75;
|
|
219
|
+
return wisdomUtility(entry) * statusBoost * (0.35 + 0.65 * matchScore);
|
|
220
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Wisdom 类型 — 规范定义在 ./types.ts
|
|
2
|
+
* Wisdom 类型 — 规范定义在 ./types.ts(maxim;见 arch/wisdom-layer-formation.md)
|
|
3
3
|
*/
|
|
4
|
-
export type { WisdomEntry, WisdomStore, } from './types.js';
|
|
4
|
+
export type { WisdomStatus, WisdomOrigin, WisdomKind, WisdomRetireReason, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomCounterevidence, WisdomOutcomes, WisdomEntry, WisdomGateReason, WisdomGateOutcome, AdmitWisdomInput, AdmitWisdomAction, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomOutcomeSignal, WisdomOutcomeEvent, WisdomStats, WisdomStore, } from './types.js';
|
|
5
|
+
export { WISDOM_STATUSES, WISDOM_INJECTABLE_STATUSES, WISDOM_ORIGINS, WISDOM_KINDS, } from './types.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InMemoryWisdomStore — 测试/开发用内存实现
|
|
3
|
+
*
|
|
4
|
+
* @module harness/memory/wisdom
|
|
5
|
+
*/
|
|
6
|
+
import type { AdmitWisdomInput, AdmitWisdomResult, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomRetireReason, WisdomStats, WisdomStore, WisdomOutcomeEvent } from './types.js';
|
|
7
|
+
export declare class InMemoryWisdomStore implements WisdomStore {
|
|
8
|
+
readonly name = "in-memory-wisdom";
|
|
9
|
+
private entries;
|
|
10
|
+
private seq;
|
|
11
|
+
admit(input: AdmitWisdomInput, options?: {
|
|
12
|
+
allowedMemoryIds?: ReadonlySet<string>;
|
|
13
|
+
}): Promise<AdmitWisdomResult>;
|
|
14
|
+
get(id: string): Promise<WisdomEntry | null>;
|
|
15
|
+
selectForInjection(query: WisdomInjectQuery): Promise<WisdomInjectPick[]>;
|
|
16
|
+
listForGovern(filter?: {
|
|
17
|
+
includeRetired?: boolean;
|
|
18
|
+
}): Promise<WisdomEntry[]>;
|
|
19
|
+
update(id: string, patch: Partial<WisdomEntry>): Promise<void>;
|
|
20
|
+
softRetire(id: string, meta: {
|
|
21
|
+
by: string;
|
|
22
|
+
reason: WisdomRetireReason | string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
recordOutcomes(events: WisdomOutcomeEvent[]): Promise<void>;
|
|
25
|
+
touchApplied(ids: string[]): Promise<void>;
|
|
26
|
+
stats(): Promise<WisdomStats>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InMemoryWisdomStore — 测试/开发用内存实现
|
|
3
|
+
*
|
|
4
|
+
* @module harness/memory/wisdom
|
|
5
|
+
*/
|
|
6
|
+
import { WISDOM_STATUSES } from './types.js';
|
|
7
|
+
import { evaluateWisdomGate, resolveInitialWisdomStatus } from './wisdom-gates.js';
|
|
8
|
+
import { foldOutcomeEvents, planConfidenceUpdate } from './wisdom-policy.js';
|
|
9
|
+
import { pickForInjection } from './wisdom-formation.js';
|
|
10
|
+
export class InMemoryWisdomStore {
|
|
11
|
+
name = 'in-memory-wisdom';
|
|
12
|
+
entries = new Map();
|
|
13
|
+
seq = 0;
|
|
14
|
+
async admit(input, options) {
|
|
15
|
+
const existing = [...this.entries.values()]
|
|
16
|
+
.filter((e) => e.status !== 'retired')
|
|
17
|
+
.map((e) => ({ id: e.id, statement: e.statement, status: e.status, kind: e.kind }));
|
|
18
|
+
const gate = evaluateWisdomGate(input, {
|
|
19
|
+
existing,
|
|
20
|
+
allowedMemoryIds: options?.allowedMemoryIds,
|
|
21
|
+
});
|
|
22
|
+
if (!gate.ok) {
|
|
23
|
+
return { action: 'rejected', reason: gate.reason, message: gate.message };
|
|
24
|
+
}
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
const status = resolveInitialWisdomStatus(input);
|
|
27
|
+
const id = `wis_${++this.seq}`;
|
|
28
|
+
if (input.supersedesId) {
|
|
29
|
+
const prev = this.entries.get(input.supersedesId);
|
|
30
|
+
if (!prev) {
|
|
31
|
+
return {
|
|
32
|
+
action: 'rejected',
|
|
33
|
+
reason: 'supersedes_target_missing',
|
|
34
|
+
message: `supersedesId=${input.supersedesId}`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
this.entries.set(prev.id, {
|
|
38
|
+
...prev,
|
|
39
|
+
status: 'superseded',
|
|
40
|
+
supersededBy: id,
|
|
41
|
+
updatedAt: now,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
this.entries.set(id, {
|
|
45
|
+
id,
|
|
46
|
+
statement: input.statement.trim(),
|
|
47
|
+
rationale: input.rationale,
|
|
48
|
+
scenario: input.scenario,
|
|
49
|
+
effect: input.effect,
|
|
50
|
+
status,
|
|
51
|
+
confidence: input.confidence ?? (status === 'active' ? 0.7 : 0.5),
|
|
52
|
+
priority: input.priority ?? (status === 'active' ? 50 : 30),
|
|
53
|
+
derivedFrom: input.derivedFrom,
|
|
54
|
+
exceptions: input.exceptions,
|
|
55
|
+
counterevidence: [],
|
|
56
|
+
outcomes: emptyOutcomes(),
|
|
57
|
+
origin: input.origin ?? 'distilled',
|
|
58
|
+
kind: input.kind,
|
|
59
|
+
createdAt: now,
|
|
60
|
+
updatedAt: now,
|
|
61
|
+
});
|
|
62
|
+
return { action: input.supersedesId ? 'superseded' : 'created', id };
|
|
63
|
+
}
|
|
64
|
+
async get(id) {
|
|
65
|
+
return this.entries.get(id) ?? null;
|
|
66
|
+
}
|
|
67
|
+
async selectForInjection(query) {
|
|
68
|
+
const entries = [...this.entries.values()];
|
|
69
|
+
return pickForInjection(entries, query.text ?? '', {
|
|
70
|
+
coreMaxItems: query.coreMaxItems,
|
|
71
|
+
scenarioMaxItems: query.scenarioMaxItems,
|
|
72
|
+
includeTrial: query.includeTrial,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async listForGovern(filter) {
|
|
76
|
+
return [...this.entries.values()].filter((e) => filter?.includeRetired || e.status !== 'retired');
|
|
77
|
+
}
|
|
78
|
+
async update(id, patch) {
|
|
79
|
+
const cur = this.entries.get(id);
|
|
80
|
+
if (!cur)
|
|
81
|
+
throw new Error(`wisdom_update_not_found: ${id}`);
|
|
82
|
+
this.entries.set(id, {
|
|
83
|
+
...cur,
|
|
84
|
+
...patch,
|
|
85
|
+
id: cur.id,
|
|
86
|
+
createdAt: cur.createdAt,
|
|
87
|
+
updatedAt: Date.now(),
|
|
88
|
+
outcomes: { ...cur.outcomes, ...(patch.outcomes ?? {}) },
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async softRetire(id, meta) {
|
|
92
|
+
const cur = this.entries.get(id);
|
|
93
|
+
if (!cur || cur.status === 'superseded')
|
|
94
|
+
return;
|
|
95
|
+
await this.update(id, {
|
|
96
|
+
status: 'retired',
|
|
97
|
+
exceptions: [...(cur.exceptions ?? []), `retired:${meta.reason}:${meta.by}`],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async recordOutcomes(events) {
|
|
101
|
+
const byId = new Map();
|
|
102
|
+
for (const e of events) {
|
|
103
|
+
const list = byId.get(e.wisdomId) ?? [];
|
|
104
|
+
list.push(e);
|
|
105
|
+
byId.set(e.wisdomId, list);
|
|
106
|
+
}
|
|
107
|
+
for (const [id, evs] of byId) {
|
|
108
|
+
const cur = this.entries.get(id);
|
|
109
|
+
if (!cur)
|
|
110
|
+
continue;
|
|
111
|
+
const folded = foldOutcomeEvents(cur, evs);
|
|
112
|
+
let next = { ...cur, ...folded, updatedAt: Date.now() };
|
|
113
|
+
const plan = planConfidenceUpdate(next);
|
|
114
|
+
if (plan) {
|
|
115
|
+
next = {
|
|
116
|
+
...next,
|
|
117
|
+
confidence: plan.confidence,
|
|
118
|
+
status: plan.status,
|
|
119
|
+
outcomes: {
|
|
120
|
+
...next.outcomes,
|
|
121
|
+
evalAssisted: plan.evalAssisted,
|
|
122
|
+
evalContested: plan.evalContested,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const counter = evs.filter((e) => e.signal === 'contested' && (e.ref || e.note));
|
|
127
|
+
if (counter.length) {
|
|
128
|
+
const ce = [...(next.counterevidence ?? [])];
|
|
129
|
+
for (const c of counter) {
|
|
130
|
+
ce.push({ ref: c.ref ?? c.wisdomId, note: c.note ?? 'contested', at: c.at ?? Date.now(), weight: 1 });
|
|
131
|
+
}
|
|
132
|
+
next = { ...next, counterevidence: ce };
|
|
133
|
+
}
|
|
134
|
+
await this.update(id, next);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async touchApplied(ids) {
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
for (const id of ids) {
|
|
140
|
+
const cur = this.entries.get(id);
|
|
141
|
+
if (!cur)
|
|
142
|
+
continue;
|
|
143
|
+
this.entries.set(id, {
|
|
144
|
+
...cur,
|
|
145
|
+
outcomes: {
|
|
146
|
+
...cur.outcomes,
|
|
147
|
+
applied: cur.outcomes.applied + 1,
|
|
148
|
+
lastAppliedAt: now,
|
|
149
|
+
},
|
|
150
|
+
updatedAt: now,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async stats() {
|
|
155
|
+
const list = [...this.entries.values()];
|
|
156
|
+
const byStatus = Object.fromEntries(WISDOM_STATUSES.map((s) => [s, 0]));
|
|
157
|
+
let conf = 0;
|
|
158
|
+
let prio = 0;
|
|
159
|
+
let applied = 0;
|
|
160
|
+
let contested = 0;
|
|
161
|
+
for (const e of list) {
|
|
162
|
+
byStatus[e.status] = (byStatus[e.status] ?? 0) + 1;
|
|
163
|
+
conf += e.confidence;
|
|
164
|
+
prio += e.priority;
|
|
165
|
+
applied += e.outcomes.applied;
|
|
166
|
+
contested += e.outcomes.contested;
|
|
167
|
+
}
|
|
168
|
+
const n = list.length || 1;
|
|
169
|
+
return {
|
|
170
|
+
total: list.length,
|
|
171
|
+
byStatus,
|
|
172
|
+
avgConfidence: conf / n,
|
|
173
|
+
avgPriority: prio / n,
|
|
174
|
+
totalApplied: applied,
|
|
175
|
+
totalContested: contested,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function emptyOutcomes() {
|
|
180
|
+
return { applied: 0, cited: 0, assisted: 0, contested: 0, evalAssisted: 0, evalContested: 0 };
|
|
181
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 为 Web/测试提供「当前/最近 Run」可检视现场。
|
|
6
6
|
* 观测失败 fail-open,不打断业务路径。
|
|
7
7
|
*/
|
|
8
|
-
import { resolveObserverConfig, buildRunMessagesDiff, summarizeLlmMessages, } from './types.js';
|
|
8
|
+
import { resolveObserverConfig, attributeRunMessage, buildRunMessagesDiff, summarizeLlmMessages, } from './types.js';
|
|
9
9
|
import { buildRunMessagesSnapshot, buildRunScopeView } from './run-snapshot.js';
|
|
10
10
|
import { buildContextLayersSnapshot } from '../../context/layer-snapshot.js';
|
|
11
11
|
const SECURITY_EVENT_TYPES = new Set([
|
|
@@ -271,6 +271,11 @@ export class ObserverHub {
|
|
|
271
271
|
return {
|
|
272
272
|
index,
|
|
273
273
|
role: (m.role || 'unknown'),
|
|
274
|
+
// 归因与 summary.byKind 同源(attributeRunMessage),LLM 视图条目与汇总口径一致
|
|
275
|
+
attribution: attributeRunMessage({
|
|
276
|
+
role: m.role,
|
|
277
|
+
content: (m.content ?? ''),
|
|
278
|
+
}),
|
|
274
279
|
content: text,
|
|
275
280
|
contentChars: text.length,
|
|
276
281
|
contentPreview: text.slice(0, 200),
|
|
@@ -378,6 +383,18 @@ export class ObserverHub {
|
|
|
378
383
|
record.updatedAt = Date.now();
|
|
379
384
|
// 继续落入 timeline(若启用)
|
|
380
385
|
}
|
|
386
|
+
if (event.type === 'tool.effect.ledger') {
|
|
387
|
+
const d = (event.data ?? {});
|
|
388
|
+
const nr = d.notReversed;
|
|
389
|
+
record.toolEffect.undo = {
|
|
390
|
+
entries: Number(d.entries ?? 0),
|
|
391
|
+
truncated: d.truncated === true,
|
|
392
|
+
notReversedReason: nr?.reason,
|
|
393
|
+
notReversedPaths: (nr?.created?.length ?? 0) + (nr?.modified?.length ?? 0) + (nr?.deleted?.length ?? 0),
|
|
394
|
+
};
|
|
395
|
+
record.updatedAt = Date.now();
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
381
398
|
// memory / tool.effect:从 tool.exec.end 投影
|
|
382
399
|
if (event.type === 'tool.exec.end' &&
|
|
383
400
|
(this.config.channels.memory || this.config.channels['tool.effect'])) {
|
|
@@ -604,6 +621,7 @@ export class ObserverHub {
|
|
|
604
621
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
605
622
|
consecutiveErrors: record.guardMetrics?.consecutiveErrors ?? 0,
|
|
606
623
|
consecutiveSameTool: record.guardMetrics?.consecutiveSameTool ?? 0,
|
|
624
|
+
consecutiveIdenticalFailures: record.guardMetrics?.consecutiveIdenticalFailures ?? 0,
|
|
607
625
|
noopStreak: record.guardMetrics?.noopStreak ?? 0,
|
|
608
626
|
hasProgress: record.guardMetrics?.hasProgress ?? true,
|
|
609
627
|
uniqueTools: record.guardMetrics?.uniqueTools ?? [],
|
|
@@ -624,6 +642,7 @@ export class ObserverHub {
|
|
|
624
642
|
elapsedMs: record.lifecycle.durationMs ?? 0,
|
|
625
643
|
consecutiveErrors: record.guardMetrics?.consecutiveErrors ?? 0,
|
|
626
644
|
consecutiveSameTool: record.guardMetrics?.consecutiveSameTool ?? 0,
|
|
645
|
+
consecutiveIdenticalFailures: record.guardMetrics?.consecutiveIdenticalFailures ?? 0,
|
|
627
646
|
noopStreak: record.guardMetrics?.noopStreak ?? 0,
|
|
628
647
|
hasProgress: record.guardMetrics?.hasProgress ?? true,
|
|
629
648
|
uniqueTools: record.guardMetrics?.uniqueTools ?? [],
|
|
@@ -642,6 +661,7 @@ export class ObserverHub {
|
|
|
642
661
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
643
662
|
consecutiveErrors: record.guardMetrics?.consecutiveErrors ?? 0,
|
|
644
663
|
consecutiveSameTool: record.guardMetrics?.consecutiveSameTool ?? 0,
|
|
664
|
+
consecutiveIdenticalFailures: record.guardMetrics?.consecutiveIdenticalFailures ?? 0,
|
|
645
665
|
noopStreak: record.guardMetrics?.noopStreak ?? 0,
|
|
646
666
|
hasProgress: record.guardMetrics?.hasProgress ?? false,
|
|
647
667
|
uniqueTools: record.guardMetrics?.uniqueTools ?? [],
|
|
@@ -660,6 +680,7 @@ export class ObserverHub {
|
|
|
660
680
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
661
681
|
consecutiveErrors: record.guardMetrics?.consecutiveErrors ?? 0,
|
|
662
682
|
consecutiveSameTool: record.guardMetrics?.consecutiveSameTool ?? 0,
|
|
683
|
+
consecutiveIdenticalFailures: record.guardMetrics?.consecutiveIdenticalFailures ?? 0,
|
|
663
684
|
noopStreak: record.guardMetrics?.noopStreak ?? 0,
|
|
664
685
|
hasProgress: record.guardMetrics?.hasProgress ?? true,
|
|
665
686
|
uniqueTools: record.guardMetrics?.uniqueTools ?? [],
|
|
@@ -786,6 +807,7 @@ export class ObserverHub {
|
|
|
786
807
|
? {
|
|
787
808
|
...record.toolEffect,
|
|
788
809
|
tools: record.toolEffect.tools.map((t) => ({ ...t })),
|
|
810
|
+
undo: record.toolEffect.undo ? { ...record.toolEffect.undo } : undefined,
|
|
789
811
|
notes: record.toolEffect.notes ? [...record.toolEffect.notes] : undefined,
|
|
790
812
|
}
|
|
791
813
|
: undefined,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_OBSERVER_CONFIG, resolveObserverConfig, isChannelEnabled, shouldCaptureMessageFullText, summarizeMessages, summarizeLlmMessages, buildRunMessagesDiff, isHiddenFromChat, attachFullContent, cloneMessages, } from './types.js';
|
|
2
|
-
export type { ObserverChannelId, ObserverConfig, ObserverLevel, ResolvedObserverConfig, RunGuardMetricsView, RunLifecycleView, RunMemoryActivityView, RunMessageView, RunMessagesDiff, RunMessagesPhase, RunMessagesSnapshot, RunMessagesSummary, RunMessagesView, RunObservatorySnapshot, RunScopeView, RunSecurityEventView, RunTimelineEventView, RunToolEffectView, RunToolRuntimeView, } from './types.js';
|
|
1
|
+
export { DEFAULT_OBSERVER_CONFIG, resolveObserverConfig, isChannelEnabled, shouldCaptureMessageFullText, summarizeMessages, summarizeLlmMessages, attributeRunMessage, buildRunMessagesDiff, isHiddenFromChat, attachFullContent, cloneMessages, } from './types.js';
|
|
2
|
+
export type { ObserverChannelId, ObserverConfig, ObserverLevel, ResolvedObserverConfig, RunGuardMetricsView, RunLifecycleView, RunMemoryActivityView, RunMessageAttribution, RunMessageView, RunMessagesDiff, RunMessagesPhase, RunMessagesSnapshot, RunMessagesSummary, RunMessagesView, RunObservatorySnapshot, RunScopeView, RunSecurityEventView, RunTimelineEventView, RunToolEffectView, RunToolRuntimeView, } from './types.js';
|
|
3
3
|
export { buildRunScopeView, buildRunMessagesSnapshot } from './run-snapshot.js';
|
|
4
4
|
export { ObserverHub } from './hub.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { DEFAULT_OBSERVER_CONFIG, resolveObserverConfig, isChannelEnabled, shouldCaptureMessageFullText, summarizeMessages, summarizeLlmMessages, buildRunMessagesDiff, isHiddenFromChat, attachFullContent, cloneMessages, } from './types.js';
|
|
1
|
+
export { DEFAULT_OBSERVER_CONFIG, resolveObserverConfig, isChannelEnabled, shouldCaptureMessageFullText, summarizeMessages, summarizeLlmMessages, attributeRunMessage, buildRunMessagesDiff, isHiddenFromChat, attachFullContent, cloneMessages, } from './types.js';
|
|
2
2
|
export { buildRunScopeView, buildRunMessagesSnapshot } from './run-snapshot.js';
|
|
3
3
|
export { ObserverHub } from './hub.js';
|
|
@@ -108,6 +108,32 @@ export declare function isChannelEnabled(cfg: ResolvedObserverConfig, channel: O
|
|
|
108
108
|
*/
|
|
109
109
|
export declare function shouldCaptureMessageFullText(cfg: ResolvedObserverConfig): boolean;
|
|
110
110
|
export type RunMessageViewRole = 'user' | 'assistant' | 'system' | 'tool';
|
|
111
|
+
/**
|
|
112
|
+
* Run message 归因(G2/G4):区分用户真实发言与引擎载体机器插槽。
|
|
113
|
+
*
|
|
114
|
+
* 机器插槽(turn 信封槽位 / 载体消息 / 摘要 / 引擎提示 / turn 闭标)**不是用户发言**——
|
|
115
|
+
* 本字段是检查器归因的唯一真源,UI 只渲染不自行判定。
|
|
116
|
+
*/
|
|
117
|
+
export interface RunMessageAttribution {
|
|
118
|
+
/** 发言方:human=用户真实发言(含 turn 信封内的用户原文);engine=机器生成;llm=模型输出;tool=工具结果 */
|
|
119
|
+
speaker: 'human' | 'engine' | 'llm' | 'tool';
|
|
120
|
+
/** 细类 */
|
|
121
|
+
kind: 'user_speech' | 'turn_envelope' | 'carrier' | 'context_summary' | 'engine_hint' | 'turn_end' | 'hosted_system' | 'system' | 'assistant' | 'tool';
|
|
122
|
+
/** 信封/闭标的 turn id(可解析出时) */
|
|
123
|
+
turnId?: string;
|
|
124
|
+
/** `metadata.source` 原值(carrier / summary / hint 等溯源) */
|
|
125
|
+
source?: string;
|
|
126
|
+
/** turn_envelope 内嵌槽位(机器生成块);摘要视图只带 chars,正文由 attachFullContent 补 */
|
|
127
|
+
slots?: Array<{
|
|
128
|
+
tag: string;
|
|
129
|
+
chars: number;
|
|
130
|
+
body?: string;
|
|
131
|
+
}>;
|
|
132
|
+
/** turn_envelope 中真实用户正文字符数(无 user_message 块 = 0) */
|
|
133
|
+
userChars?: number;
|
|
134
|
+
/** turn_envelope 是否含 `<user_message>` 块(false = 信封不完整,UI 应标注而非把整封当用户原文) */
|
|
135
|
+
hasUserMessage?: boolean;
|
|
136
|
+
}
|
|
111
137
|
/** 单条 Run message 的 UI 视图 */
|
|
112
138
|
export interface RunMessageView {
|
|
113
139
|
index: number;
|
|
@@ -120,6 +146,8 @@ export interface RunMessageView {
|
|
|
120
146
|
metadata?: Record<string, unknown>;
|
|
121
147
|
/** 中栏对话是否会隐藏本条 */
|
|
122
148
|
hiddenFromChat?: boolean;
|
|
149
|
+
/** 归因(机器插槽 vs 用户发言;见 RunMessageAttribution) */
|
|
150
|
+
attribution?: RunMessageAttribution;
|
|
123
151
|
contentChars?: number;
|
|
124
152
|
/** 摘要模式下的截断预览 */
|
|
125
153
|
contentPreview?: string;
|
|
@@ -129,6 +157,8 @@ export type RunMessagesView = 'workspace' | 'llm';
|
|
|
129
157
|
export interface RunMessagesSummary {
|
|
130
158
|
count: number;
|
|
131
159
|
byRole: Record<string, number>;
|
|
160
|
+
/** 按归因 kind 计数(RunMessageAttribution.kind)——机器插槽与用户发言在汇总层即分开 */
|
|
161
|
+
byKind: Record<string, number>;
|
|
132
162
|
systemPromptCount: number;
|
|
133
163
|
contextSummaryCount: number;
|
|
134
164
|
hiddenFromChatCount: number;
|
|
@@ -145,7 +175,11 @@ export interface RunGuardMetricsView {
|
|
|
145
175
|
nominalTotalTokens: number;
|
|
146
176
|
elapsedMs: number;
|
|
147
177
|
consecutiveErrors: number;
|
|
178
|
+
/** 连续同一错误(名+参数+错误内容一致)——「卡住」的强信号 */
|
|
179
|
+
consecutiveIdenticalFailures?: number;
|
|
148
180
|
consecutiveSameTool: number;
|
|
181
|
+
/** 连续相同调用(名+参数+结果一致)——无进展循环的强信号 */
|
|
182
|
+
consecutiveIdenticalCalls?: number;
|
|
149
183
|
noopStreak: number;
|
|
150
184
|
hasProgress: boolean;
|
|
151
185
|
uniqueTools: string[];
|
|
@@ -288,6 +322,13 @@ export interface RunToolEffectView {
|
|
|
288
322
|
errors: number;
|
|
289
323
|
lastDurationMs?: number;
|
|
290
324
|
}>;
|
|
325
|
+
/** L3 效应账本(§5.6) */
|
|
326
|
+
undo?: {
|
|
327
|
+
entries: number;
|
|
328
|
+
truncated?: boolean;
|
|
329
|
+
notReversedReason?: string;
|
|
330
|
+
notReversedPaths?: number;
|
|
331
|
+
};
|
|
291
332
|
notes?: string[];
|
|
292
333
|
}
|
|
293
334
|
/** 单次 Run 的观测投影(WS/REST 摘要;全文经 messages REST) */
|
|
@@ -319,6 +360,22 @@ export interface RunObservatorySnapshot {
|
|
|
319
360
|
webPanel: boolean;
|
|
320
361
|
};
|
|
321
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Run message 归因(G2/G4 唯一判定处)。
|
|
365
|
+
*
|
|
366
|
+
* 判定次序:**source 优先、内容兜底**——
|
|
367
|
+
* ① role 二值(assistant/tool)→ ② 引擎载体 source(turnEnd / 载体插槽 / contextSummary / engineHint,
|
|
368
|
+
* 语义真源 `harness/context/layer-types.ts` ENGINE_CARRIER_SOURCES)→ ③ system role →
|
|
369
|
+
* ④ 无 source + user role + 正文以信封开标签起头 = turn_envelope → ⑤ 其余 user_speech。
|
|
370
|
+
*
|
|
371
|
+
* source 优先是审计面的可靠性要求:载体消息正文来自不可信语料(知识/grounding/附件),
|
|
372
|
+
* 含信封字面量也不得被内容嗅探抢走归因(否则机器插槽挂上「用户发言」徽章)。
|
|
373
|
+
* turn_end 的内容兜底仅作 legacy 降级:无 source 且整条正文就是闭标形状才认。
|
|
374
|
+
*
|
|
375
|
+
* @param msg - 消息(role/content/metadata)
|
|
376
|
+
* @returns 归因
|
|
377
|
+
*/
|
|
378
|
+
export declare function attributeRunMessage(msg: Pick<Message, 'role' | 'content' | 'metadata'>): RunMessageAttribution;
|
|
322
379
|
/** message 摘要统计 */
|
|
323
380
|
export declare function summarizeMessages(messages: Message[], opts?: {
|
|
324
381
|
maxPreviewChars?: number;
|