@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
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Quality Gate - 输出质量检测
|
|
3
|
-
*
|
|
4
|
-
* 检测 LLM 输出的质量问题:
|
|
5
|
-
* - 模型崩溃(token 序列混乱)
|
|
6
|
-
* - 截断
|
|
7
|
-
* - 重复循环
|
|
8
|
-
* - 格式错误
|
|
9
|
-
*/
|
|
10
|
-
import type { QualityCheckResult } from './types.js';
|
|
11
|
-
/**
|
|
12
|
-
* 输出质量检测器
|
|
13
|
-
*/
|
|
14
|
-
export declare class OutputQualityGate {
|
|
15
|
-
/**
|
|
16
|
-
* 检测文本输出质量
|
|
17
|
-
*/
|
|
18
|
-
checkTextOutput(text: unknown, config: unknown): QualityCheckResult;
|
|
19
|
-
/**
|
|
20
|
-
* 检测流式 chunk 质量(增量检测)
|
|
21
|
-
*
|
|
22
|
-
* 当累积文本较长时开始检测,避免误判正常输出
|
|
23
|
-
*/
|
|
24
|
-
checkStreamChunk(chunk: unknown, accumulated: unknown, config: unknown): QualityCheckResult;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 创建输出质量检测器
|
|
28
|
-
*/
|
|
29
|
-
export declare function createOutputQualityGate(): OutputQualityGate;
|
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Quality Gate - 输出质量检测
|
|
3
|
-
*
|
|
4
|
-
* 检测 LLM 输出的质量问题:
|
|
5
|
-
* - 模型崩溃(token 序列混乱)
|
|
6
|
-
* - 截断
|
|
7
|
-
* - 重复循环
|
|
8
|
-
* - 格式错误
|
|
9
|
-
*/
|
|
10
|
-
// ================================================================
|
|
11
|
-
// 辅助函数
|
|
12
|
-
// ================================================================
|
|
13
|
-
/**
|
|
14
|
-
* 检测文本语言
|
|
15
|
-
*/
|
|
16
|
-
function detectLanguage(text) {
|
|
17
|
-
const chineseChars = text.match(/[\u4e00-\u9fa5]/g)?.length ?? 0;
|
|
18
|
-
return chineseChars / text.length > 0.3 ? 'zh' : 'en';
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 简单哈希函数(用于 Rabin-Karp)
|
|
22
|
-
*/
|
|
23
|
-
function simpleHash(str) {
|
|
24
|
-
let hash = 0;
|
|
25
|
-
for (let i = 0; i < str.length; i++) {
|
|
26
|
-
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
|
27
|
-
hash |= 0;
|
|
28
|
-
}
|
|
29
|
-
return hash;
|
|
30
|
-
}
|
|
31
|
-
// ================================================================
|
|
32
|
-
// 语法碎片检测模式(重构:只检测真正的碎片)
|
|
33
|
-
// ================================================================
|
|
34
|
-
/**
|
|
35
|
-
* 语法碎片检测模式
|
|
36
|
-
*
|
|
37
|
-
* 检测不完整的代码块特征(真正的碎片,不是完整语法)
|
|
38
|
-
*/
|
|
39
|
-
const SYNTAX_FRAGMENT_PATTERNS = [
|
|
40
|
-
// 悬空的 if(没有闭合括号或代码块)
|
|
41
|
-
/if\s*\([^)]*$/gm,
|
|
42
|
-
// 悬空的箭头函数(没有函数体)
|
|
43
|
-
/=>\s*\{[^}]*$/gm,
|
|
44
|
-
/=>\s*$/gm,
|
|
45
|
-
// 不完整的函数声明(没有闭合)
|
|
46
|
-
/function\s+\w*\s*\([^)]*\)\s*\{[^}]*$/gm,
|
|
47
|
-
// 不完整的模板字符串(没有闭合反引号)
|
|
48
|
-
/`[^`]*$/gm,
|
|
49
|
-
// 不完整的对象/数组字面量
|
|
50
|
-
/\{[^}]*$/gm,
|
|
51
|
-
/\[[^\]]*$/gm,
|
|
52
|
-
// 不完整的字符串(没有闭合引号)
|
|
53
|
-
/"[^"]*$/gm,
|
|
54
|
-
/'[^']*$/gm,
|
|
55
|
-
// 不完整的注释
|
|
56
|
-
/\/\*[^*]*\*([^/]|$)/gm,
|
|
57
|
-
/\/\/[^\n]*$/gm,
|
|
58
|
-
// 异常的括号组合(不匹配)
|
|
59
|
-
/\([^)]*\)/g, // 用于计数,实际检查在函数中
|
|
60
|
-
];
|
|
61
|
-
/**
|
|
62
|
-
* 崩溃特征模式
|
|
63
|
-
*
|
|
64
|
-
* 检测典型的崩溃输出特征
|
|
65
|
-
*/
|
|
66
|
-
const COLLAPSE_PATTERNS = [
|
|
67
|
-
// 中英混杂的代码片段(真正的崩溃特征)
|
|
68
|
-
/[\u4e00-\u9fa5]+\s*\{[\u4e00-\u9fa5]+\s*:/gi,
|
|
69
|
-
/[\u4e00-\u9fa5]+\s*=>[\u4e00-\u9fa5]+/gi,
|
|
70
|
-
// 无意义的字符组合
|
|
71
|
-
/\w+\s*\?\s*\w+\s*\|\|/gi, // 异常的条件表达式
|
|
72
|
-
/\w+\s*\|\|\s*\w+\s*::/gi, // 异常的类型表达式
|
|
73
|
-
// 异常的标记组合
|
|
74
|
-
/```.*?```.*?```.*?```/gi, // 多个不完整代码块
|
|
75
|
-
];
|
|
76
|
-
// ================================================================
|
|
77
|
-
// 核心检测函数
|
|
78
|
-
// ================================================================
|
|
79
|
-
/**
|
|
80
|
-
* 计算字符熵值(语言感知版本)
|
|
81
|
-
*
|
|
82
|
-
* 过低的熵值表示输出异常(字符分布过于集中)
|
|
83
|
-
*/
|
|
84
|
-
function calculateEntropy(text) {
|
|
85
|
-
if (text.length === 0)
|
|
86
|
-
return 0;
|
|
87
|
-
const charFreq = new Map();
|
|
88
|
-
for (const char of text) {
|
|
89
|
-
charFreq.set(char, (charFreq.get(char) ?? 0) + 1);
|
|
90
|
-
}
|
|
91
|
-
let entropy = 0;
|
|
92
|
-
const len = text.length;
|
|
93
|
-
for (const [, freq] of charFreq) {
|
|
94
|
-
const p = freq / len;
|
|
95
|
-
entropy -= p * Math.log2(p);
|
|
96
|
-
}
|
|
97
|
-
return entropy;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 计算相对熵值(考虑语言特性)
|
|
101
|
-
*
|
|
102
|
-
* 返回 0-1 之间的值,越低越异常
|
|
103
|
-
*/
|
|
104
|
-
function calculateRelativeEntropy(text) {
|
|
105
|
-
if (text.length === 0)
|
|
106
|
-
return 1;
|
|
107
|
-
const entropy = calculateEntropy(text);
|
|
108
|
-
const lang = detectLanguage(text);
|
|
109
|
-
// 中文文本熵值通常在 3-4 之间,英文在 4-5 之间
|
|
110
|
-
const expectedEntropy = lang === 'zh' ? 3.5 : 4.5;
|
|
111
|
-
// 相对熵 = 实际熵 / 期望熵
|
|
112
|
-
return Math.min(1, entropy / expectedEntropy);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 检测重复片段(优化版本 - Rabin-Karp 算法)
|
|
116
|
-
*
|
|
117
|
-
* 检测文本中的重复模式
|
|
118
|
-
*/
|
|
119
|
-
function detectRepetition(text) {
|
|
120
|
-
if (text.length < 50)
|
|
121
|
-
return 0;
|
|
122
|
-
// 对于超长文本,采样检测
|
|
123
|
-
const maxSampleSize = 10000;
|
|
124
|
-
const sampleText = text.length > maxSampleSize
|
|
125
|
-
? text.slice(0, maxSampleSize / 2) + text.slice(text.length - maxSampleSize / 2)
|
|
126
|
-
: text;
|
|
127
|
-
const windowSize = 20;
|
|
128
|
-
const seen = new Map();
|
|
129
|
-
let repeatCount = 0;
|
|
130
|
-
// 使用 Rabin-Karp 算法检测重复
|
|
131
|
-
for (let i = 0; i <= sampleText.length - windowSize; i++) {
|
|
132
|
-
const hash = simpleHash(sampleText.slice(i, i + windowSize));
|
|
133
|
-
const lastSeen = seen.get(hash);
|
|
134
|
-
if (lastSeen !== undefined && i - lastSeen < windowSize * 2) {
|
|
135
|
-
repeatCount++;
|
|
136
|
-
}
|
|
137
|
-
seen.set(hash, i);
|
|
138
|
-
}
|
|
139
|
-
// 检测模式重复(相似的句子结构)
|
|
140
|
-
const sentences = sampleText.split(/[。!?.\n]/).filter(s => s.trim().length > 10);
|
|
141
|
-
if (sentences.length > 3) {
|
|
142
|
-
const uniqueSentences = new Set(sentences.map(s => s.trim().slice(0, 30)));
|
|
143
|
-
const repetitionRatio = 1 - (uniqueSentences.size / sentences.length);
|
|
144
|
-
return Math.max(repeatCount * 0.1, repetitionRatio);
|
|
145
|
-
}
|
|
146
|
-
return Math.min(1, repeatCount * 0.1);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 移除 Markdown 代码块
|
|
150
|
-
*
|
|
151
|
-
* 代码块中的语法结构不应该被误判为碎片
|
|
152
|
-
*/
|
|
153
|
-
function removeCodeBlocks(text) {
|
|
154
|
-
// 移除围栏代码块 (```...```)
|
|
155
|
-
let result = text.replace(/```[\s\S]*?```/g, '');
|
|
156
|
-
// 移除行内代码 (`...`)
|
|
157
|
-
result = result.replace(/`[^`]+`/g, '');
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* 计算语法碎片密度
|
|
162
|
-
*
|
|
163
|
-
* 每100字符的语法碎片数量
|
|
164
|
-
*/
|
|
165
|
-
function calculateSyntaxFragmentDensity(text) {
|
|
166
|
-
if (text.length === 0)
|
|
167
|
-
return 0;
|
|
168
|
-
// 移除代码块(代码块中的语法不应被检测)
|
|
169
|
-
const cleanedText = removeCodeBlocks(text);
|
|
170
|
-
// 对于超长文本,采样检测
|
|
171
|
-
const maxSampleSize = 5000;
|
|
172
|
-
const sampleText = cleanedText.length > maxSampleSize
|
|
173
|
-
? cleanedText.slice(0, maxSampleSize / 2) + cleanedText.slice(cleanedText.length - maxSampleSize / 2)
|
|
174
|
-
: cleanedText;
|
|
175
|
-
// 如果清理后的文本太短,返回 0
|
|
176
|
-
if (sampleText.length < 10)
|
|
177
|
-
return 0;
|
|
178
|
-
let fragmentCount = 0;
|
|
179
|
-
// 检测悬空的语法结构
|
|
180
|
-
const danglingPatterns = [
|
|
181
|
-
/if\s*\([^)]*$/gm, // 悬空的 if
|
|
182
|
-
/=>\s*\{[^}]*$/gm, // 悬空的箭头函数
|
|
183
|
-
/=>\s*$/gm, // 悬空的 =>
|
|
184
|
-
/function\s+\w*\s*\([^)]*\)\s*\{[^}]*$/gm, // 不完整的函数
|
|
185
|
-
/`[^`]*$/gm, // 不完整的模板字符串
|
|
186
|
-
/"[^"]*$/gm, // 不完整的字符串
|
|
187
|
-
/'[^']*$/gm, // 不完整的字符串
|
|
188
|
-
];
|
|
189
|
-
for (const pattern of danglingPatterns) {
|
|
190
|
-
const matches = sampleText.match(pattern) ?? [];
|
|
191
|
-
fragmentCount += matches.length;
|
|
192
|
-
}
|
|
193
|
-
// 检测括号不匹配
|
|
194
|
-
const openBraces = (sampleText.match(/\{/g) ?? []).length;
|
|
195
|
-
const closeBraces = (sampleText.match(/\}/g) ?? []).length;
|
|
196
|
-
const openParens = (sampleText.match(/\(/g) ?? []).length;
|
|
197
|
-
const closeParens = (sampleText.match(/\)/g) ?? []).length;
|
|
198
|
-
const openBrackets = (sampleText.match(/\[/g) ?? []).length;
|
|
199
|
-
const closeBrackets = (sampleText.match(/\]/g) ?? []).length;
|
|
200
|
-
// 括号不匹配也视为碎片
|
|
201
|
-
const braceMismatch = Math.abs(openBraces - closeBraces);
|
|
202
|
-
const parenMismatch = Math.abs(openParens - closeParens);
|
|
203
|
-
const bracketMismatch = Math.abs(openBrackets - closeBrackets);
|
|
204
|
-
fragmentCount += braceMismatch + parenMismatch + bracketMismatch;
|
|
205
|
-
// 密度 = 碎片数 / (文本长度 / 100)
|
|
206
|
-
return fragmentCount / (sampleText.length / 100);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* 检测崩溃特征
|
|
210
|
-
*
|
|
211
|
-
* 返回崩溃提示列表
|
|
212
|
-
*/
|
|
213
|
-
function detectCollapseFeatures(text) {
|
|
214
|
-
const hints = [];
|
|
215
|
-
// 对于超长文本,采样检测
|
|
216
|
-
const maxSampleSize = 5000;
|
|
217
|
-
const sampleText = text.length > maxSampleSize
|
|
218
|
-
? text.slice(0, maxSampleSize / 2) + text.slice(text.length - maxSampleSize / 2)
|
|
219
|
-
: text;
|
|
220
|
-
for (const pattern of COLLAPSE_PATTERNS) {
|
|
221
|
-
const matches = sampleText.match(pattern) ?? [];
|
|
222
|
-
if (matches.length > 0) {
|
|
223
|
-
hints.push({
|
|
224
|
-
type: 'model_collapse',
|
|
225
|
-
confidence: Math.min(1, matches.length * 0.3),
|
|
226
|
-
evidence: matches[0]?.slice(0, 100) ?? 'unknown',
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return hints;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* 计算平均句子长度
|
|
234
|
-
*/
|
|
235
|
-
function calculateAvgSentenceLength(text) {
|
|
236
|
-
const sentences = text.split(/[。!?.!?\n]/).filter(s => s.trim().length > 0);
|
|
237
|
-
if (sentences.length === 0)
|
|
238
|
-
return text.length;
|
|
239
|
-
const totalLen = sentences.reduce((sum, s) => sum + s.length, 0);
|
|
240
|
-
return totalLen / sentences.length;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* 综合质量评分计算
|
|
244
|
-
*/
|
|
245
|
-
function calculateQualityScore(details, config) {
|
|
246
|
-
// 基础评分 = 1.0
|
|
247
|
-
let score = 1.0;
|
|
248
|
-
// 语法碎片密度惩罚
|
|
249
|
-
if (details.syntaxFragmentDensity > config.syntaxFragmentThreshold) {
|
|
250
|
-
const penalty = (details.syntaxFragmentDensity - config.syntaxFragmentThreshold) * 0.5;
|
|
251
|
-
score -= Math.min(penalty, 0.4);
|
|
252
|
-
}
|
|
253
|
-
// 熵值惩罚(使用相对熵)
|
|
254
|
-
if (details.entropy < config.entropyThreshold) {
|
|
255
|
-
const penalty = (config.entropyThreshold - details.entropy) * 0.1;
|
|
256
|
-
score -= Math.min(penalty, 0.3);
|
|
257
|
-
}
|
|
258
|
-
// 重复惩罚
|
|
259
|
-
score -= details.repetitionRatio * 0.3;
|
|
260
|
-
// 平均句子长度惩罚(异常短表示碎片化)
|
|
261
|
-
if (details.avgSentenceLength < 10 && details.avgSentenceLength > 0) {
|
|
262
|
-
score -= 0.2;
|
|
263
|
-
}
|
|
264
|
-
return Math.max(0, Math.min(1, score));
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* 验证配置参数
|
|
268
|
-
*/
|
|
269
|
-
function validateConfig(config) {
|
|
270
|
-
if (typeof config !== 'object' || config === null) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
const c = config;
|
|
274
|
-
// 检查必需字段
|
|
275
|
-
if (typeof c.enabled !== 'boolean')
|
|
276
|
-
return false;
|
|
277
|
-
if (typeof c.anomalyThreshold !== 'number')
|
|
278
|
-
return false;
|
|
279
|
-
if (typeof c.syntaxFragmentThreshold !== 'number')
|
|
280
|
-
return false;
|
|
281
|
-
if (typeof c.entropyThreshold !== 'number')
|
|
282
|
-
return false;
|
|
283
|
-
// 检查数值范围
|
|
284
|
-
if (c.anomalyThreshold < 0 || c.anomalyThreshold > 1)
|
|
285
|
-
return false;
|
|
286
|
-
if (c.syntaxFragmentThreshold < 0)
|
|
287
|
-
return false;
|
|
288
|
-
if (c.entropyThreshold < 0)
|
|
289
|
-
return false;
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* 创建默认结果
|
|
294
|
-
*/
|
|
295
|
-
function createDefaultResult() {
|
|
296
|
-
return {
|
|
297
|
-
isAnomalous: false,
|
|
298
|
-
qualityScore: 1.0,
|
|
299
|
-
anomalyHints: [],
|
|
300
|
-
details: {
|
|
301
|
-
syntaxFragmentDensity: 0,
|
|
302
|
-
repetitionRatio: 0,
|
|
303
|
-
entropy: 0,
|
|
304
|
-
avgSentenceLength: 0,
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
// ================================================================
|
|
309
|
-
// OutputQualityGate 实现
|
|
310
|
-
// ================================================================
|
|
311
|
-
/**
|
|
312
|
-
* 输出质量检测器
|
|
313
|
-
*/
|
|
314
|
-
export class OutputQualityGate {
|
|
315
|
-
/**
|
|
316
|
-
* 检测文本输出质量
|
|
317
|
-
*/
|
|
318
|
-
checkTextOutput(text, config) {
|
|
319
|
-
// 输入验证
|
|
320
|
-
if (typeof text !== 'string') {
|
|
321
|
-
return createDefaultResult();
|
|
322
|
-
}
|
|
323
|
-
if (!validateConfig(config)) {
|
|
324
|
-
throw new TypeError('Invalid QualityGateConfig: must have enabled (boolean), anomalyThreshold (0-1), syntaxFragmentThreshold (number), entropyThreshold (number)');
|
|
325
|
-
}
|
|
326
|
-
if (!config.enabled) {
|
|
327
|
-
return createDefaultResult();
|
|
328
|
-
}
|
|
329
|
-
// 空字符串返回默认结果
|
|
330
|
-
if (text.length === 0) {
|
|
331
|
-
return createDefaultResult();
|
|
332
|
-
}
|
|
333
|
-
// 计算各项指标
|
|
334
|
-
const syntaxFragmentDensity = calculateSyntaxFragmentDensity(text);
|
|
335
|
-
const entropy = calculateEntropy(text);
|
|
336
|
-
const repetitionRatio = detectRepetition(text);
|
|
337
|
-
const avgSentenceLength = calculateAvgSentenceLength(text);
|
|
338
|
-
const details = {
|
|
339
|
-
syntaxFragmentDensity,
|
|
340
|
-
entropy,
|
|
341
|
-
repetitionRatio,
|
|
342
|
-
avgSentenceLength,
|
|
343
|
-
};
|
|
344
|
-
// 检测崩溃特征
|
|
345
|
-
const collapseHints = detectCollapseFeatures(text);
|
|
346
|
-
// 综合评分
|
|
347
|
-
const qualityScore = calculateQualityScore(details, config);
|
|
348
|
-
// 判断是否异常
|
|
349
|
-
const isAnomalous = qualityScore < config.anomalyThreshold || collapseHints.length > 0;
|
|
350
|
-
// 构建异常提示
|
|
351
|
-
const anomalyHints = [...collapseHints];
|
|
352
|
-
// 根据各项指标添加提示
|
|
353
|
-
if (syntaxFragmentDensity > config.syntaxFragmentThreshold) {
|
|
354
|
-
anomalyHints.push({
|
|
355
|
-
type: 'model_collapse',
|
|
356
|
-
confidence: Math.min(1, syntaxFragmentDensity * 0.5),
|
|
357
|
-
evidence: `High syntax fragment density: ${syntaxFragmentDensity.toFixed(2)}`,
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
if (entropy < config.entropyThreshold) {
|
|
361
|
-
anomalyHints.push({
|
|
362
|
-
type: 'model_collapse',
|
|
363
|
-
confidence: Math.min(1, (config.entropyThreshold - entropy) * 0.3),
|
|
364
|
-
evidence: `Low entropy: ${entropy.toFixed(2)}`,
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
if (repetitionRatio > 0.3) {
|
|
368
|
-
anomalyHints.push({
|
|
369
|
-
type: 'repetition_loop',
|
|
370
|
-
confidence: Math.min(1, repetitionRatio),
|
|
371
|
-
evidence: `High repetition ratio: ${repetitionRatio.toFixed(2)}`,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
return {
|
|
375
|
-
isAnomalous,
|
|
376
|
-
qualityScore,
|
|
377
|
-
anomalyHints,
|
|
378
|
-
details,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* 检测流式 chunk 质量(增量检测)
|
|
383
|
-
*
|
|
384
|
-
* 当累积文本较长时开始检测,避免误判正常输出
|
|
385
|
-
*/
|
|
386
|
-
checkStreamChunk(chunk, accumulated, config) {
|
|
387
|
-
// 输入验证
|
|
388
|
-
if (typeof chunk !== 'string' || typeof accumulated !== 'string') {
|
|
389
|
-
return createDefaultResult();
|
|
390
|
-
}
|
|
391
|
-
if (!validateConfig(config)) {
|
|
392
|
-
throw new TypeError('Invalid QualityGateConfig');
|
|
393
|
-
}
|
|
394
|
-
// 累积文本足够长才开始检测(至少500字符)
|
|
395
|
-
if (accumulated.length < 500) {
|
|
396
|
-
return createDefaultResult();
|
|
397
|
-
}
|
|
398
|
-
return this.checkTextOutput(accumulated, config);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
// ================================================================
|
|
402
|
-
// 工厂函数
|
|
403
|
-
// ================================================================
|
|
404
|
-
/**
|
|
405
|
-
* 创建输出质量检测器
|
|
406
|
-
*/
|
|
407
|
-
export function createOutputQualityGate() {
|
|
408
|
-
return new OutputQualityGate();
|
|
409
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Quality — 输出质量检测
|
|
3
|
-
*
|
|
4
|
-
* 从旧 loop/ 迁移到 Harness 层。
|
|
5
|
-
* 通过 Agent 的 afterToolCall 回调槽集成。
|
|
6
|
-
*/
|
|
7
|
-
export { OutputQualityGate, createOutputQualityGate } from './gate.js';
|
|
8
|
-
export { OutputErrorClassifier, createOutputErrorClassifier } from './classifier.js';
|
|
9
|
-
export type { QualityCheckResult, QualityGateConfig, AnomalyHint, QualityCheckDetails, AnomalyType, AnomalySeverity, RecoveryStrategyType, ErrorClassification, RecoveryConfig, RecoveryResult, } from './types.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Quality — 输出质量检测
|
|
3
|
-
*
|
|
4
|
-
* 从旧 loop/ 迁移到 Harness 层。
|
|
5
|
-
* 通过 Agent 的 afterToolCall 回调槽集成。
|
|
6
|
-
*/
|
|
7
|
-
export { OutputQualityGate, createOutputQualityGate } from './gate.js';
|
|
8
|
-
export { OutputErrorClassifier, createOutputErrorClassifier } from './classifier.js';
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Quality Gate 类型定义
|
|
3
|
-
*
|
|
4
|
-
* 用于检测 LLM 输出的质量问题(崩溃、截断、重复等)
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* 异常输出类型
|
|
8
|
-
*/
|
|
9
|
-
export type AnomalyType = 'model_collapse' | 'truncation' | 'repetition_loop' | 'format_error' | 'unknown';
|
|
10
|
-
/**
|
|
11
|
-
* 异常严重程度
|
|
12
|
-
*/
|
|
13
|
-
export type AnomalySeverity = 'minor' | 'moderate' | 'severe';
|
|
14
|
-
/**
|
|
15
|
-
* 恢复策略类型
|
|
16
|
-
*/
|
|
17
|
-
export type RecoveryStrategyType = 'retry' | 'fallback' | 'abort' | 'degrade';
|
|
18
|
-
/**
|
|
19
|
-
* 异常提示(供分类器使用)
|
|
20
|
-
*/
|
|
21
|
-
export interface AnomalyHint {
|
|
22
|
-
/** 异常类型 */
|
|
23
|
-
type: AnomalyType;
|
|
24
|
-
/** 置信度 (0-1) */
|
|
25
|
-
confidence: number;
|
|
26
|
-
/** 具体证据片段 */
|
|
27
|
-
evidence: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 检测详情
|
|
31
|
-
*/
|
|
32
|
-
export interface QualityCheckDetails {
|
|
33
|
-
/** 代码语法碎片密度(每100字符的碎片数) */
|
|
34
|
-
syntaxFragmentDensity: number;
|
|
35
|
-
/** 重复片段比例 */
|
|
36
|
-
repetitionRatio: number;
|
|
37
|
-
/** 字符熵值(过低表示异常) */
|
|
38
|
-
entropy: number;
|
|
39
|
-
/** 平均句子长度(异常低表示碎片化) */
|
|
40
|
-
avgSentenceLength: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* 输出质量检测结果
|
|
44
|
-
*/
|
|
45
|
-
export interface QualityCheckResult {
|
|
46
|
-
/** 是否检测到异常 */
|
|
47
|
-
isAnomalous: boolean;
|
|
48
|
-
/** 质量评分 (0-1, 越低越异常) */
|
|
49
|
-
qualityScore: number;
|
|
50
|
-
/** 异常类型提示 */
|
|
51
|
-
anomalyHints: AnomalyHint[];
|
|
52
|
-
/** 检测详情 */
|
|
53
|
-
details: QualityCheckDetails;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 检测级别
|
|
57
|
-
*/
|
|
58
|
-
export type CheckLevel = 'basic' | 'strict' | 'semantic';
|
|
59
|
-
/**
|
|
60
|
-
* 语言类型
|
|
61
|
-
*/
|
|
62
|
-
export type Language = 'en' | 'zh' | 'auto';
|
|
63
|
-
/**
|
|
64
|
-
* 输出质量检测配置
|
|
65
|
-
*/
|
|
66
|
-
export interface QualityGateConfig {
|
|
67
|
-
/** 是否启用检测 */
|
|
68
|
-
enabled: boolean;
|
|
69
|
-
/** 检测级别 */
|
|
70
|
-
checkLevel: CheckLevel;
|
|
71
|
-
/** 异常阈值(低于此值判定为异常) */
|
|
72
|
-
anomalyThreshold: number;
|
|
73
|
-
/** 语法碎片密度阈值 */
|
|
74
|
-
syntaxFragmentThreshold: number;
|
|
75
|
-
/** 熵值阈值(过低表示异常) */
|
|
76
|
-
entropyThreshold: number;
|
|
77
|
-
/** 语言设置(auto 为自动检测) */
|
|
78
|
-
language?: Language;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 默认配置
|
|
82
|
-
*/
|
|
83
|
-
export declare const DEFAULT_QUALITY_GATE_CONFIG: QualityGateConfig;
|
|
84
|
-
/**
|
|
85
|
-
* 异常分类结果
|
|
86
|
-
*/
|
|
87
|
-
export interface ErrorClassification {
|
|
88
|
-
/** 异常类型 */
|
|
89
|
-
type: AnomalyType;
|
|
90
|
-
/** 分类置信度 */
|
|
91
|
-
confidence: number;
|
|
92
|
-
/** 严重程度 */
|
|
93
|
-
severity: AnomalySeverity;
|
|
94
|
-
/** 推荐恢复策略 */
|
|
95
|
-
recommendedStrategy: RecoveryStrategyType;
|
|
96
|
-
/** 分类依据 */
|
|
97
|
-
evidence: string[];
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 分类上下文
|
|
101
|
-
*/
|
|
102
|
-
export interface ClassificationContext {
|
|
103
|
-
/** LLM finish_reason */
|
|
104
|
-
finishReason?: string;
|
|
105
|
-
/** 工具调用列表 */
|
|
106
|
-
toolCalls?: unknown[];
|
|
107
|
-
/** 当前迭代次数 */
|
|
108
|
-
iterationCount: number;
|
|
109
|
-
/** 之前的错误分类 */
|
|
110
|
-
previousErrors: ErrorClassification[];
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* 恢复策略配置
|
|
114
|
-
*/
|
|
115
|
-
export interface RecoveryConfig {
|
|
116
|
-
/** 最大重试次数 */
|
|
117
|
-
maxRetries: number;
|
|
118
|
-
/** 备用模型列表(按优先级) */
|
|
119
|
-
fallbackModels: string[];
|
|
120
|
-
/** 策略优先级配置 */
|
|
121
|
-
strategyPriority: Partial<Record<AnomalyType, RecoveryStrategyType[]>>;
|
|
122
|
-
/** 降级模式配置 */
|
|
123
|
-
degradeConfig: {
|
|
124
|
-
disableTools: boolean;
|
|
125
|
-
maxTokens?: number;
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* 默认恢复配置
|
|
130
|
-
*/
|
|
131
|
-
export declare const DEFAULT_RECOVERY_CONFIG: RecoveryConfig;
|
|
132
|
-
/**
|
|
133
|
-
* 恢复执行结果
|
|
134
|
-
*/
|
|
135
|
-
export interface RecoveryResult {
|
|
136
|
-
/** 是否成功恢复 */
|
|
137
|
-
success: boolean;
|
|
138
|
-
/** 使用的策略 */
|
|
139
|
-
strategyUsed: RecoveryStrategyType;
|
|
140
|
-
/** 重试次数 */
|
|
141
|
-
retryCount: number;
|
|
142
|
-
/** 最终输出(如果成功) */
|
|
143
|
-
finalOutput?: unknown;
|
|
144
|
-
/** 错误信息(如果失败) */
|
|
145
|
-
error?: Error;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* 恢复上下文
|
|
149
|
-
*/
|
|
150
|
-
export interface RecoveryContext {
|
|
151
|
-
/** 原始请求 */
|
|
152
|
-
request: unknown;
|
|
153
|
-
/** 当前模型 */
|
|
154
|
-
currentModel: string;
|
|
155
|
-
/** Agent 配置 */
|
|
156
|
-
agentConfig: unknown;
|
|
157
|
-
/** 会话上下文 */
|
|
158
|
-
sessionContext: unknown;
|
|
159
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Quality Gate 类型定义
|
|
3
|
-
*
|
|
4
|
-
* 用于检测 LLM 输出的质量问题(崩溃、截断、重复等)
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* 默认配置
|
|
8
|
-
*/
|
|
9
|
-
export const DEFAULT_QUALITY_GATE_CONFIG = {
|
|
10
|
-
enabled: true,
|
|
11
|
-
checkLevel: 'basic',
|
|
12
|
-
anomalyThreshold: 0.6,
|
|
13
|
-
syntaxFragmentThreshold: 0.5,
|
|
14
|
-
entropyThreshold: 3.0,
|
|
15
|
-
language: 'auto',
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* 默认恢复配置
|
|
19
|
-
*/
|
|
20
|
-
export const DEFAULT_RECOVERY_CONFIG = {
|
|
21
|
-
maxRetries: 2,
|
|
22
|
-
fallbackModels: [],
|
|
23
|
-
strategyPriority: {
|
|
24
|
-
model_collapse: ['fallback', 'retry', 'abort'],
|
|
25
|
-
truncation: ['retry', 'abort'],
|
|
26
|
-
repetition_loop: ['retry', 'fallback', 'degrade'],
|
|
27
|
-
format_error: ['retry', 'abort'],
|
|
28
|
-
},
|
|
29
|
-
degradeConfig: {
|
|
30
|
-
disableTools: true,
|
|
31
|
-
maxTokens: 500,
|
|
32
|
-
},
|
|
33
|
-
};
|