@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
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* 各层质量打磨后续替换 assemble 实现即可,契约不变。
|
|
7
7
|
*/
|
|
8
8
|
import { LAYER_DEFAULT_SHARE, LAYER_ORDER, LAYER_PRIORITY, } from './layer-types.js';
|
|
9
|
+
import { formatWisdomBody } from '../memory/wisdom-formation.js';
|
|
10
|
+
import { formatMemoryTimeSuffix } from '../memory/time-format.js';
|
|
9
11
|
// ── 基类 ──
|
|
10
12
|
class BaseLayer {
|
|
11
13
|
id;
|
|
@@ -13,12 +15,14 @@ class BaseLayer {
|
|
|
13
15
|
defaultShare;
|
|
14
16
|
droppable;
|
|
15
17
|
order;
|
|
18
|
+
placement;
|
|
16
19
|
constructor(id, overrides) {
|
|
17
20
|
this.id = id;
|
|
18
21
|
this.priority = overrides?.priority ?? LAYER_PRIORITY[id];
|
|
19
22
|
this.defaultShare = overrides?.defaultShare ?? LAYER_DEFAULT_SHARE[id];
|
|
20
23
|
this.droppable = overrides?.droppable ?? id !== 'persona';
|
|
21
24
|
this.order = overrides?.order ?? LAYER_ORDER[id];
|
|
25
|
+
this.placement = overrides?.placement ?? 'system';
|
|
22
26
|
}
|
|
23
27
|
content(text, extra) {
|
|
24
28
|
const trimmed = text.trim();
|
|
@@ -101,7 +105,7 @@ export class SkillLayer extends BaseLayer {
|
|
|
101
105
|
export class RuntimeLayer extends BaseLayer {
|
|
102
106
|
getText;
|
|
103
107
|
constructor(options) {
|
|
104
|
-
super('runtime', { order: options.order });
|
|
108
|
+
super('runtime', { order: options.order, placement: options.placement ?? 'system' });
|
|
105
109
|
this.getText = options.getText;
|
|
106
110
|
}
|
|
107
111
|
async assemble(ctx) {
|
|
@@ -220,7 +224,7 @@ export class MemoryLayer extends BaseLayer {
|
|
|
220
224
|
/** 向量相关性地板;默认见 retrieval-rank(与 search 工具相比更严) */
|
|
221
225
|
minSimilarity;
|
|
222
226
|
constructor(options) {
|
|
223
|
-
super('memory', { order: options.order });
|
|
227
|
+
super('memory', { order: options.order, placement: 'snapshot' });
|
|
224
228
|
this.store = options.store;
|
|
225
229
|
this.limit = options.limit ?? 5;
|
|
226
230
|
this.minSimilarity = options.minSimilarity;
|
|
@@ -241,7 +245,10 @@ export class MemoryLayer extends BaseLayer {
|
|
|
241
245
|
if (injectable.length === 0)
|
|
242
246
|
return null;
|
|
243
247
|
const body = injectable
|
|
244
|
-
.map((m) =>
|
|
248
|
+
.map((m) => {
|
|
249
|
+
const when = m.futureUse ? ` (when: ${m.futureUse})` : '';
|
|
250
|
+
return `- [${m.type}] ${m.content}${when}${formatMemoryTimeSuffix(m)}`;
|
|
251
|
+
})
|
|
245
252
|
.join('\n');
|
|
246
253
|
const text = `# 相关记忆\n\n${body}`;
|
|
247
254
|
const { text: truncated, dropped } = this.truncateToBudget(text, ctx.tokenBudget);
|
|
@@ -251,37 +258,57 @@ export class MemoryLayer extends BaseLayer {
|
|
|
251
258
|
});
|
|
252
259
|
}
|
|
253
260
|
}
|
|
254
|
-
// ── Cognition
|
|
261
|
+
// ── Cognition(扩散激活子图;强弱边分列) ──
|
|
255
262
|
export class CognitionLayer extends BaseLayer {
|
|
256
263
|
store;
|
|
257
264
|
depth;
|
|
258
265
|
constructor(options) {
|
|
259
|
-
super('cognition', { order: options.order });
|
|
266
|
+
super('cognition', { order: options.order, placement: 'snapshot' });
|
|
260
267
|
this.store = options.store;
|
|
261
|
-
this.depth = options.depth ??
|
|
268
|
+
this.depth = options.depth ?? 2;
|
|
262
269
|
}
|
|
263
270
|
async assemble(ctx) {
|
|
264
271
|
if (!ctx.query?.trim())
|
|
265
272
|
return null;
|
|
266
|
-
const
|
|
273
|
+
const queryTokens = ctx.query
|
|
274
|
+
.split(/\s+/)
|
|
275
|
+
.map((t) => t.trim())
|
|
276
|
+
.filter((t) => t.length >= 2)
|
|
277
|
+
.slice(0, 8);
|
|
278
|
+
const seeds = queryTokens.length ? queryTokens : [ctx.query.trim()];
|
|
279
|
+
const graph = await this.store.spreadingActivate(seeds, {
|
|
280
|
+
depth: this.depth,
|
|
281
|
+
limit: 40,
|
|
282
|
+
});
|
|
267
283
|
if (!graph.nodes.length)
|
|
268
284
|
return null;
|
|
269
|
-
const
|
|
285
|
+
const nameOf = new Map(graph.nodes.map((n) => [n.id, n.name]));
|
|
286
|
+
const strong = [];
|
|
287
|
+
const weakNames = new Set();
|
|
270
288
|
for (const edge of graph.edges) {
|
|
271
|
-
const source =
|
|
272
|
-
const target =
|
|
273
|
-
if (source
|
|
274
|
-
|
|
275
|
-
|
|
289
|
+
const source = nameOf.get(edge.sourceId);
|
|
290
|
+
const target = nameOf.get(edge.targetId);
|
|
291
|
+
if (!source || !target)
|
|
292
|
+
continue;
|
|
293
|
+
if (edge.relationType === 'related' || edge.status === 'shadow') {
|
|
294
|
+
weakNames.add(source);
|
|
295
|
+
weakNames.add(target);
|
|
296
|
+
continue;
|
|
276
297
|
}
|
|
298
|
+
const desc = edge.description ? ` (${edge.description})` : '';
|
|
299
|
+
strong.push(`- ${source} —[${edge.relationType}]→ ${target}${desc}`);
|
|
277
300
|
}
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
lines.push(`- ${node.name}${desc}`);
|
|
301
|
+
// 弱边只作折叠相关,不伪造成因果格式
|
|
302
|
+
for (const n of graph.nodes) {
|
|
303
|
+
if (!weakNames.has(n.name) && !strong.some((l) => l.includes(n.name))) {
|
|
304
|
+
weakNames.add(n.name);
|
|
283
305
|
}
|
|
284
306
|
}
|
|
307
|
+
const lines = [...strong];
|
|
308
|
+
const weak = [...weakNames].filter((name) => !strong.some((l) => l.includes(name)));
|
|
309
|
+
if (weak.length) {
|
|
310
|
+
lines.push(`相关:${weak.join('、')}`);
|
|
311
|
+
}
|
|
285
312
|
if (lines.length === 0)
|
|
286
313
|
return null;
|
|
287
314
|
const text = `# 相关概念\n\n${lines.join('\n')}`;
|
|
@@ -292,70 +319,46 @@ export class CognitionLayer extends BaseLayer {
|
|
|
292
319
|
});
|
|
293
320
|
}
|
|
294
321
|
}
|
|
295
|
-
/**
|
|
296
|
-
* 解析认知图:先 store.queryRelated,失败则从全图按「概念名 ⊆ query」筛种子再扩边
|
|
297
|
-
*
|
|
298
|
-
* @param store - ConceptGraphStore
|
|
299
|
-
* @param query - 检索文本(通常为最近用户消息)
|
|
300
|
-
* @param depth - 扩展深度
|
|
301
|
-
* @returns 命中的子图(可能为空)
|
|
302
|
-
*/
|
|
303
|
-
async function resolveCognitionGraph(store, query, depth) {
|
|
304
|
-
const direct = await store.queryRelated(query, depth);
|
|
305
|
-
if (direct.nodes.length)
|
|
306
|
-
return direct;
|
|
307
|
-
const full = await store.getFullGraph();
|
|
308
|
-
const q = query.toLowerCase();
|
|
309
|
-
const seeds = full.nodes.filter((n) => n.name && q.includes(n.name.toLowerCase()));
|
|
310
|
-
if (!seeds.length)
|
|
311
|
-
return { nodes: [], edges: [] };
|
|
312
|
-
const collected = new Map(seeds.map((n) => [n.id, n]));
|
|
313
|
-
const nodeById = new Map(full.nodes.map((n) => [n.id, n]));
|
|
314
|
-
const visited = new Set(seeds.map((n) => n.id));
|
|
315
|
-
const queue = seeds.map((n) => ({ id: n.id, d: 0 }));
|
|
316
|
-
while (queue.length > 0) {
|
|
317
|
-
const { id, d } = queue.shift();
|
|
318
|
-
if (d >= depth)
|
|
319
|
-
continue;
|
|
320
|
-
for (const e of full.edges) {
|
|
321
|
-
const neighborId = e.sourceId === id ? e.targetId : e.targetId === id ? e.sourceId : null;
|
|
322
|
-
if (!neighborId || visited.has(neighborId))
|
|
323
|
-
continue;
|
|
324
|
-
const node = nodeById.get(neighborId);
|
|
325
|
-
if (!node)
|
|
326
|
-
continue;
|
|
327
|
-
visited.add(neighborId);
|
|
328
|
-
collected.set(neighborId, node);
|
|
329
|
-
queue.push({ id: neighborId, d: d + 1 });
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
const edges = full.edges.filter((e) => collected.has(e.sourceId) && collected.has(e.targetId));
|
|
333
|
-
return { nodes: [...collected.values()], edges };
|
|
334
|
-
}
|
|
335
322
|
// ── Wisdom(静态/半静态) ──
|
|
336
323
|
/**
|
|
337
|
-
* Wisdom 层 —
|
|
324
|
+
* Wisdom 层 — 小核心 + 场景匹配注入判断范式
|
|
338
325
|
*
|
|
339
|
-
*
|
|
340
|
-
* 后续可改为场景匹配 / applicableScenarios 过滤。
|
|
326
|
+
* 不做全量 dump。匹配失败只注入 core(宁缺毋滥)。
|
|
341
327
|
*/
|
|
342
328
|
export class WisdomLayer extends BaseLayer {
|
|
343
|
-
|
|
329
|
+
select;
|
|
330
|
+
onInjected;
|
|
331
|
+
coreMaxItems;
|
|
332
|
+
scenarioMaxItems;
|
|
344
333
|
constructor(options) {
|
|
345
|
-
super('wisdom', { order: options.order });
|
|
346
|
-
this.
|
|
334
|
+
super('wisdom', { order: options.order, placement: 'snapshot' });
|
|
335
|
+
this.select = options.select;
|
|
336
|
+
this.onInjected = options.onInjected;
|
|
337
|
+
this.coreMaxItems = options.coreMaxItems;
|
|
338
|
+
this.scenarioMaxItems = options.scenarioMaxItems;
|
|
347
339
|
}
|
|
348
340
|
async assemble(ctx) {
|
|
349
|
-
const
|
|
350
|
-
if (
|
|
341
|
+
const picks = await this.select(ctx.query ?? '');
|
|
342
|
+
if (picks.length === 0)
|
|
343
|
+
return null;
|
|
344
|
+
const body = formatWisdomBody(picks);
|
|
345
|
+
if (!body)
|
|
351
346
|
return null;
|
|
352
|
-
const sorted = [...entries].sort((a, b) => b.priority - a.priority);
|
|
353
|
-
const body = sorted.map((w) => w.content).join('\n\n');
|
|
354
347
|
const text = `# 思维框架\n\n${body}`;
|
|
355
348
|
const { text: truncated, dropped } = this.truncateToBudget(text, ctx.tokenBudget);
|
|
349
|
+
const sources = picks.map((p) => p.entry.id);
|
|
350
|
+
// S1:实际进入 system 的条目记 applied(轻量,不跑 confidence)
|
|
351
|
+
if (this.onInjected && sources.length) {
|
|
352
|
+
try {
|
|
353
|
+
await this.onInjected(sources);
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
// 入账失败不拖垮装配;结局环可由 evaluate 兜
|
|
357
|
+
}
|
|
358
|
+
}
|
|
356
359
|
return this.content(truncated, {
|
|
357
360
|
dropped,
|
|
358
|
-
sources
|
|
361
|
+
sources,
|
|
359
362
|
});
|
|
360
363
|
}
|
|
361
364
|
}
|
|
@@ -367,8 +370,21 @@ export class WisdomLayer extends BaseLayer {
|
|
|
367
370
|
*/
|
|
368
371
|
export function createDefaultLayers(options) {
|
|
369
372
|
const layers = [];
|
|
370
|
-
if (options.
|
|
371
|
-
|
|
373
|
+
if (options.wisdomStore) {
|
|
374
|
+
const store = options.wisdomStore;
|
|
375
|
+
layers.push(new WisdomLayer({
|
|
376
|
+
select: async (query) => {
|
|
377
|
+
const picks = await store.selectForInjection({
|
|
378
|
+
text: query,
|
|
379
|
+
coreMaxItems: options.wisdomCoreMaxItems,
|
|
380
|
+
scenarioMaxItems: options.wisdomScenarioMaxItems,
|
|
381
|
+
});
|
|
382
|
+
return picks.map((p) => ({ entry: p.entry, bucket: p.bucket }));
|
|
383
|
+
},
|
|
384
|
+
onInjected: (ids) => store.touchApplied(ids),
|
|
385
|
+
coreMaxItems: options.wisdomCoreMaxItems,
|
|
386
|
+
scenarioMaxItems: options.wisdomScenarioMaxItems,
|
|
387
|
+
}));
|
|
372
388
|
}
|
|
373
389
|
if (options.personaText) {
|
|
374
390
|
layers.push(new PersonaLayer({ getText: options.personaText }));
|
|
@@ -9,7 +9,15 @@
|
|
|
9
9
|
* 2. 调用 LLM 生成结构化摘要
|
|
10
10
|
* 3. 摘要 token 预算:contentTokens × 0.20(上下限:2000 - 12000)
|
|
11
11
|
*/
|
|
12
|
+
import type { Message } from '@octopi-agent/core/types.js';
|
|
12
13
|
import type { Compressor, CompressParams, CompressResult } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* 工具调用账本(name+args 紧凑清单)——降级时的「做过什么」无损索引
|
|
16
|
+
*
|
|
17
|
+
* @param messages - 被降级丢弃的消息
|
|
18
|
+
* @returns 账本文本(可为空串)
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildToolCallLedger(messages: Message[]): string;
|
|
13
21
|
export declare class LLMSummaryCompressor implements Compressor {
|
|
14
22
|
/**
|
|
15
23
|
* 压缩消息
|
|
@@ -29,10 +37,16 @@ export declare class LLMSummaryCompressor implements Compressor {
|
|
|
29
37
|
private calculateSummaryBudget;
|
|
30
38
|
/**
|
|
31
39
|
* 格式化消息为 LLM 可读的上下文
|
|
40
|
+
*
|
|
41
|
+
* 归因保留(模型 2):多 agent 共线的摘要不得张冠李戴
|
|
42
|
+
* (惯例出处 session/history/port.ts renderMessage 的 role(agentId);此处大写仅排版差异)。
|
|
32
43
|
*/
|
|
33
44
|
private formatMessagesForSummary;
|
|
34
45
|
/**
|
|
35
|
-
* 回退截断(当 LLM
|
|
46
|
+
* 回退截断(当 LLM 摘要不可用时)——保守降级
|
|
47
|
+
*
|
|
48
|
+
* 作为 **middle 替换体**:账本说明 + 近尾若干条。
|
|
49
|
+
* 外层 head/tail 由调用方(applyProactiveCompact)拼接,此处不得重复携带。
|
|
36
50
|
*/
|
|
37
51
|
private fallbackTruncate;
|
|
38
52
|
}
|
|
@@ -11,17 +11,51 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { getTextContent } from '@octopi-agent/core/types.js';
|
|
13
13
|
import { HeuristicTokenEstimator } from './token-estimator.js';
|
|
14
|
+
import { toolResultBody } from './tool-result-body.js';
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* 工具调用账本(name+args 紧凑清单)——降级时的「做过什么」无损索引
|
|
17
|
+
*
|
|
18
|
+
* @param messages - 被降级丢弃的消息
|
|
19
|
+
* @returns 账本文本(可为空串)
|
|
20
|
+
*/
|
|
21
|
+
export function buildToolCallLedger(messages) {
|
|
22
|
+
const lines = [];
|
|
23
|
+
for (const msg of messages) {
|
|
24
|
+
for (const tc of msg.toolCalls ?? []) {
|
|
25
|
+
let args;
|
|
26
|
+
try {
|
|
27
|
+
args = JSON.stringify(tc.arguments ?? {});
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
args = '[unserializable]';
|
|
31
|
+
}
|
|
32
|
+
if (args.length > 160)
|
|
33
|
+
args = `${args.slice(0, 160)}…`;
|
|
34
|
+
lines.push(`- ${tc.name}(${args})`);
|
|
35
|
+
}
|
|
36
|
+
for (const tr of msg.toolResults ?? []) {
|
|
37
|
+
if (tr.error !== undefined) {
|
|
38
|
+
const err = tr.error.length > 120 ? `${tr.error.slice(0, 120)}…` : tr.error;
|
|
39
|
+
lines.push(` ! ${tr.name ?? tr.toolCallId}: ${err}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return lines.join('\n');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 结构化摘要模板(F-d 硬约束:Done 逐条可核验 + 交接语防重做)
|
|
16
47
|
*/
|
|
17
48
|
const SUMMARY_TEMPLATE = `## Conversation Summary
|
|
18
49
|
|
|
50
|
+
> HANDOFF: Your working memory was compacted. First check Done/ToDo and the session task list (task_*). DO NOT redo work listed under Done.
|
|
51
|
+
|
|
19
52
|
### Goal
|
|
20
53
|
[What the user is trying to accomplish]
|
|
21
54
|
|
|
22
55
|
### Progress
|
|
23
|
-
####
|
|
24
|
-
[
|
|
56
|
+
#### Done
|
|
57
|
+
- [each item MUST be] what was done + artifact path(s) / exact identifiers
|
|
58
|
+
- ...
|
|
25
59
|
|
|
26
60
|
#### In Progress
|
|
27
61
|
[What is currently being worked on]
|
|
@@ -33,37 +67,36 @@ const SUMMARY_TEMPLATE = `## Conversation Summary
|
|
|
33
67
|
[Important technical decisions and reasons]
|
|
34
68
|
|
|
35
69
|
### Relevant Files
|
|
36
|
-
[Files read, modified, or created]
|
|
70
|
+
[Files read, modified, or created — absolute or workspace-relative paths]
|
|
37
71
|
|
|
38
72
|
### Next Steps
|
|
39
|
-
[What needs to be done next]
|
|
73
|
+
[What needs to be done next; align with task_* list when present]
|
|
40
74
|
|
|
41
75
|
### Key Context
|
|
42
76
|
[Specific values, error messages, configuration details]`;
|
|
43
77
|
/**
|
|
44
|
-
*
|
|
78
|
+
* 摘要指令(缓存友好:只作 **user 尾部** 追加,绝不改写 system/历史)。
|
|
79
|
+
* 规则与旧 SUMMARIZE_INSTRUCTION 对齐;模板不变。
|
|
45
80
|
*/
|
|
46
|
-
|
|
81
|
+
function buildSummarizeTailInstruction(params) {
|
|
82
|
+
const header = params.previousSummary
|
|
83
|
+
? `You are updating an existing conversation summary. Merge the conversation above into the summary below.\n\nPrevious Summary:\n${params.previousSummary}`
|
|
84
|
+
: `You are a conversation summarizer. Create a concise, structured summary of the conversation above.`;
|
|
85
|
+
return `${header}
|
|
47
86
|
|
|
48
87
|
Rules:
|
|
49
88
|
1. Focus on factual information, not pleasantries
|
|
50
89
|
2. Preserve specific details (file paths, error messages, code snippets)
|
|
51
90
|
3. Use the exact structure provided in the template
|
|
52
91
|
4. If updating a previous summary, merge new information rather than replacing everything
|
|
53
|
-
5. Keep the summary under {maxTokens} tokens
|
|
92
|
+
5. Keep the summary under ${params.maxTokens} tokens
|
|
93
|
+
6. HARD: Every Done item must state what was completed AND the artifact path or exact identifier
|
|
94
|
+
7. HARD: Keep the HANDOFF line at the top unchanged in meaning — it prevents redoing finished work
|
|
95
|
+
8. HARD: Do not invent paths or claim work that is not evidenced in the history
|
|
54
96
|
|
|
55
97
|
Template:
|
|
56
98
|
${SUMMARY_TEMPLATE}`;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Rules:
|
|
60
|
-
1. Merge new information into the existing summary
|
|
61
|
-
2. Remove outdated information
|
|
62
|
-
3. Preserve the structure
|
|
63
|
-
4. Keep the summary under {maxTokens} tokens
|
|
64
|
-
|
|
65
|
-
Previous Summary:
|
|
66
|
-
{previousSummary}`;
|
|
99
|
+
}
|
|
67
100
|
export class LLMSummaryCompressor {
|
|
68
101
|
/**
|
|
69
102
|
* 压缩消息
|
|
@@ -89,8 +122,9 @@ export class LLMSummaryCompressor {
|
|
|
89
122
|
}
|
|
90
123
|
// 计算当前 token 数
|
|
91
124
|
const currentTokens = estimator.estimateMessages(messages);
|
|
92
|
-
//
|
|
93
|
-
|
|
125
|
+
// 如果已经在预算内,不需要压缩。
|
|
126
|
+
// requireSummary 除外:调用方要求语义摘要,不能以机械返回冒充已摘要。
|
|
127
|
+
if (currentTokens <= targetTokens && !params.requireSummary) {
|
|
94
128
|
return {
|
|
95
129
|
result: [...messages],
|
|
96
130
|
estimatedTokens: currentTokens,
|
|
@@ -98,36 +132,43 @@ export class LLMSummaryCompressor {
|
|
|
98
132
|
}
|
|
99
133
|
// 计算摘要 token 预算
|
|
100
134
|
const summaryTokens = this.calculateSummaryBudget(currentTokens);
|
|
101
|
-
// 格式化消息为 LLM
|
|
135
|
+
// 格式化消息为 LLM 可读的上下文(仅无 llmPrefix 时的旁路)
|
|
102
136
|
const formattedContext = this.formatMessagesForSummary(messages);
|
|
103
137
|
// 构建 LLM 消息
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
138
|
+
// 缓存优先:llmPrefix(会话 system+history 同形)+ 尾部 user 指令。
|
|
139
|
+
// 禁止改写 system / 重排历史——否则打穿 provider 前缀缓存。
|
|
140
|
+
let llmMessages;
|
|
141
|
+
if (params.llmPrefix && params.llmPrefix.length > 0) {
|
|
142
|
+
llmMessages = [
|
|
143
|
+
...params.llmPrefix,
|
|
144
|
+
{
|
|
145
|
+
role: 'user',
|
|
146
|
+
content: buildSummarizeTailInstruction({
|
|
147
|
+
previousSummary,
|
|
148
|
+
maxTokens: summaryTokens,
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
151
|
+
];
|
|
113
152
|
}
|
|
114
153
|
else {
|
|
115
|
-
llmMessages
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
154
|
+
llmMessages = [
|
|
155
|
+
{
|
|
156
|
+
role: 'system',
|
|
157
|
+
content: buildSummarizeTailInstruction({ previousSummary, maxTokens: summaryTokens }),
|
|
158
|
+
},
|
|
159
|
+
{ role: 'user', content: formattedContext },
|
|
160
|
+
];
|
|
119
161
|
}
|
|
120
|
-
// 用户消息(要摘要的内容)
|
|
121
|
-
llmMessages.push({
|
|
122
|
-
role: 'user',
|
|
123
|
-
content: formattedContext,
|
|
124
|
-
});
|
|
125
162
|
try {
|
|
126
163
|
// 调用 LLM 生成摘要
|
|
127
164
|
const summary = await summarize(llmMessages, {
|
|
128
165
|
previousSummary,
|
|
129
166
|
maxTokens: summaryTokens,
|
|
130
167
|
});
|
|
168
|
+
// 空摘要(拒答/内容过滤)按失败处理:不得用空正文替换中间段、更不得冒充语义摘要
|
|
169
|
+
if (!summary || !summary.trim()) {
|
|
170
|
+
return this.fallbackTruncate(messages, targetTokens, estimator);
|
|
171
|
+
}
|
|
131
172
|
// 摘要用 user 角色:中段 system 会被部分网关拒绝
|
|
132
173
|
const summaryMessage = {
|
|
133
174
|
role: 'user',
|
|
@@ -161,12 +202,15 @@ export class LLMSummaryCompressor {
|
|
|
161
202
|
}
|
|
162
203
|
/**
|
|
163
204
|
* 格式化消息为 LLM 可读的上下文
|
|
205
|
+
*
|
|
206
|
+
* 归因保留(模型 2):多 agent 共线的摘要不得张冠李戴
|
|
207
|
+
* (惯例出处 session/history/port.ts renderMessage 的 role(agentId);此处大写仅排版差异)。
|
|
164
208
|
*/
|
|
165
209
|
formatMessagesForSummary(messages) {
|
|
166
210
|
const parts = [];
|
|
167
211
|
for (const msg of messages) {
|
|
168
|
-
const role = msg.role.toUpperCase();
|
|
169
|
-
const content = getTextContent(msg.content);
|
|
212
|
+
const role = msg.agentId ? `${msg.role.toUpperCase()}(${msg.agentId})` : msg.role.toUpperCase();
|
|
213
|
+
const content = getTextContent(msg.content ?? '');
|
|
170
214
|
if (msg.role === 'assistant' && msg.toolCalls?.length) {
|
|
171
215
|
// 带工具调用的 assistant 消息
|
|
172
216
|
const toolCallsStr = msg.toolCalls
|
|
@@ -177,14 +221,7 @@ export class LLMSummaryCompressor {
|
|
|
177
221
|
else if (msg.role === 'tool' && msg.toolResults?.length) {
|
|
178
222
|
// 工具结果消息(含 error,避免摘要丢失失败信息)
|
|
179
223
|
const resultsStr = msg.toolResults
|
|
180
|
-
.map(tr => {
|
|
181
|
-
const body = tr.error !== undefined
|
|
182
|
-
? JSON.stringify({ error: tr.error })
|
|
183
|
-
: typeof tr.result === 'string'
|
|
184
|
-
? tr.result
|
|
185
|
-
: JSON.stringify(tr.result ?? null);
|
|
186
|
-
return ` - ${tr.name}: ${body}`;
|
|
187
|
-
})
|
|
224
|
+
.map(tr => ` - ${tr.name}: ${toolResultBody(tr)}`)
|
|
188
225
|
.join('\n');
|
|
189
226
|
parts.push(`[${role}]\nTool Results:\n${resultsStr}`);
|
|
190
227
|
}
|
|
@@ -195,17 +232,31 @@ export class LLMSummaryCompressor {
|
|
|
195
232
|
return parts.join('\n\n---\n\n');
|
|
196
233
|
}
|
|
197
234
|
/**
|
|
198
|
-
* 回退截断(当 LLM
|
|
235
|
+
* 回退截断(当 LLM 摘要不可用时)——保守降级
|
|
236
|
+
*
|
|
237
|
+
* 作为 **middle 替换体**:账本说明 + 近尾若干条。
|
|
238
|
+
* 外层 head/tail 由调用方(applyProactiveCompact)拼接,此处不得重复携带。
|
|
199
239
|
*/
|
|
200
|
-
fallbackTruncate(messages,
|
|
201
|
-
//
|
|
202
|
-
const keepCount = Math.min(
|
|
240
|
+
fallbackTruncate(messages, _targetTokens, estimator) {
|
|
241
|
+
// 近尾保留工具步上下文;更早的换成「账本」——禁止只留 4 条且无索引
|
|
242
|
+
const keepCount = Math.min(Math.max(6, Math.ceil(messages.length * 0.15)), messages.length);
|
|
203
243
|
const kept = messages.slice(-keepCount);
|
|
204
|
-
const
|
|
244
|
+
const dropped = messages.slice(0, messages.length - keepCount);
|
|
245
|
+
// 无可丢弃:原样返回(禁止用「0 removed」假通知撑长视图)
|
|
246
|
+
if (dropped.length === 0) {
|
|
247
|
+
return {
|
|
248
|
+
result: [...messages],
|
|
249
|
+
estimatedTokens: estimator.estimateMessages(messages),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const ledger = buildToolCallLedger(dropped);
|
|
253
|
+
const notice = ledger
|
|
254
|
+
? `[Context truncated: ${dropped.length} earlier messages removed to fit context window]\n[Tool call ledger — do NOT redo these unless explicitly asked]\n${ledger}\n[Check session task list via task_* before continuing]`
|
|
255
|
+
: `[Context truncated: ${dropped.length} earlier messages removed to fit context window]\n[Check session task list via task_* before continuing]`;
|
|
205
256
|
// 插入截断说明(user 角色,避免中段 system)
|
|
206
257
|
const summaryMessage = {
|
|
207
258
|
role: 'user',
|
|
208
|
-
content:
|
|
259
|
+
content: notice,
|
|
209
260
|
timestamp: Date.now(),
|
|
210
261
|
metadata: { source: 'contextSummary' },
|
|
211
262
|
};
|
|
@@ -214,7 +265,7 @@ export class LLMSummaryCompressor {
|
|
|
214
265
|
return {
|
|
215
266
|
result,
|
|
216
267
|
estimatedTokens,
|
|
217
|
-
droppedSummary: `${
|
|
268
|
+
droppedSummary: `${dropped.length} messages truncated`,
|
|
218
269
|
};
|
|
219
270
|
}
|
|
220
271
|
}
|
|
@@ -109,6 +109,7 @@ export class DefaultMessageSelector {
|
|
|
109
109
|
*/
|
|
110
110
|
selectByTokenBudget(messages, budget, estimator) {
|
|
111
111
|
const selected = [];
|
|
112
|
+
const selectedSet = new Set();
|
|
112
113
|
let usedTokens = 0;
|
|
113
114
|
for (let i = 0; i < messages.length; i++) {
|
|
114
115
|
const msg = messages[i];
|
|
@@ -119,7 +120,7 @@ export class DefaultMessageSelector {
|
|
|
119
120
|
const prevMsg = messages[i - 1];
|
|
120
121
|
if (this.hasToolCall(prevMsg)) {
|
|
121
122
|
// 确保 tool_call 已被选中
|
|
122
|
-
const prevInSelected =
|
|
123
|
+
const prevInSelected = selectedSet.has(prevMsg);
|
|
123
124
|
if (!prevInSelected) {
|
|
124
125
|
// tool_call 未被选中,跳过 tool_result
|
|
125
126
|
continue;
|
|
@@ -130,6 +131,7 @@ export class DefaultMessageSelector {
|
|
|
130
131
|
break;
|
|
131
132
|
}
|
|
132
133
|
selected.push(msg);
|
|
134
|
+
selectedSet.add(msg);
|
|
133
135
|
usedTokens += msgTokens;
|
|
134
136
|
}
|
|
135
137
|
return selected;
|
|
@@ -141,6 +143,7 @@ export class DefaultMessageSelector {
|
|
|
141
143
|
*/
|
|
142
144
|
selectByTokenBudgetFromEnd(messages, budget, estimator) {
|
|
143
145
|
const selected = [];
|
|
146
|
+
const selectedSet = new Set();
|
|
144
147
|
let usedTokens = 0;
|
|
145
148
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
146
149
|
const msg = messages[i];
|
|
@@ -150,7 +153,7 @@ export class DefaultMessageSelector {
|
|
|
150
153
|
const nextMsg = messages[i + 1];
|
|
151
154
|
if (this.isToolResult(nextMsg)) {
|
|
152
155
|
// 确保 tool_result 已被选中
|
|
153
|
-
const nextInSelected =
|
|
156
|
+
const nextInSelected = selectedSet.has(nextMsg);
|
|
154
157
|
if (!nextInSelected) {
|
|
155
158
|
// tool_result 未被选中,跳过 tool_call
|
|
156
159
|
continue;
|
|
@@ -161,6 +164,7 @@ export class DefaultMessageSelector {
|
|
|
161
164
|
break;
|
|
162
165
|
}
|
|
163
166
|
selected.unshift(msg);
|
|
167
|
+
selectedSet.add(msg);
|
|
164
168
|
usedTokens += msgTokens;
|
|
165
169
|
}
|
|
166
170
|
return selected;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root 级项目工作约定注入 — 各 allowRoot 下的 AGENTS.md / CLAUDE.md
|
|
3
|
+
*
|
|
4
|
+
* 仓库根目录常见的 AGENTS.md / CLAUDE.md 约束该目录树内的工作方式
|
|
5
|
+
* (命令、风格、目录约定、评审步骤),与 agent 人格(agents/<id>/AGENTS.md)
|
|
6
|
+
* 不同:它们是项目本地约定,按 root 作用域生效。
|
|
7
|
+
*
|
|
8
|
+
* 职责:从 allowRoots 读取这两份文档 → 带作用域说明与标签格式化 →
|
|
9
|
+
* 由 Runtime 注入(`withRuntimeEnvironmentInjection`)拼进 system prompt。
|
|
10
|
+
*/
|
|
11
|
+
/** 识别的约定文件名(同 root 时 AGENTS.md 在前,CLAUDE.md 追加) */
|
|
12
|
+
declare const INSTRUCTION_FILES: readonly ["AGENTS.md", "CLAUDE.md"];
|
|
13
|
+
/** 一份已加载的 root 约定文档 */
|
|
14
|
+
export interface RootInstructionDoc {
|
|
15
|
+
/** 所属 root(绝对路径) */
|
|
16
|
+
root: string;
|
|
17
|
+
/** 来源文件名 */
|
|
18
|
+
source: (typeof INSTRUCTION_FILES)[number];
|
|
19
|
+
/** 文件绝对路径(截断提示用) */
|
|
20
|
+
path: string;
|
|
21
|
+
/** 正文(已 trim;空文件不会进入列表) */
|
|
22
|
+
content: string;
|
|
23
|
+
/** 是否因单文件/合计上限被截断 */
|
|
24
|
+
truncated: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 丢弃指令文件缓存(测试或外部强制刷新)
|
|
28
|
+
*
|
|
29
|
+
* @returns 无
|
|
30
|
+
*/
|
|
31
|
+
export declare function clearRootInstructionCache(): void;
|
|
32
|
+
/**
|
|
33
|
+
* 加载各 root 下的 AGENTS.md / CLAUDE.md
|
|
34
|
+
*
|
|
35
|
+
* - 只读 root 目录这一层,不递归子目录
|
|
36
|
+
* - 同 root 两份都在时:AGENTS.md 在前,CLAUDE.md 追加(各自成块)
|
|
37
|
+
* - 块顺序:cwd 所属 root 优先,其余按传入顺序;root 去重
|
|
38
|
+
* - 单文件 / 合计字节双上限;首份可截到合计上限,其后装不下的整份跳过
|
|
39
|
+
* (继续尝试更小的后续文件,不浪费剩余预算)
|
|
40
|
+
*
|
|
41
|
+
* @param roots - allowRoots(L2/事务根)
|
|
42
|
+
* @param options - cwd(用于排序);maxFileBytes / maxTotalBytes 覆盖默认上限
|
|
43
|
+
* @returns 约定文档列表(无任何文件时为空数组)
|
|
44
|
+
*/
|
|
45
|
+
export declare function loadRootInstructionDocs(roots: string[] | undefined, options?: {
|
|
46
|
+
cwd?: string;
|
|
47
|
+
maxFileBytes?: number;
|
|
48
|
+
maxTotalBytes?: number;
|
|
49
|
+
}): Promise<RootInstructionDoc[]>;
|
|
50
|
+
/**
|
|
51
|
+
* 将约定文档格式化为 root_instructions 注入块
|
|
52
|
+
*
|
|
53
|
+
* 开头是作用域与优先级说明,随后每个文档一个带 root/source 的标签块。
|
|
54
|
+
* 无文档时返回空串(调用方直接跳过拼接)。
|
|
55
|
+
*
|
|
56
|
+
* @param docs - loadRootInstructionDocs 的结果
|
|
57
|
+
* @returns 注入字符串
|
|
58
|
+
*/
|
|
59
|
+
export declare function formatRootInstructionsInjection(docs: RootInstructionDoc[]): string;
|
|
60
|
+
/**
|
|
61
|
+
* 加载并格式化 root 约定注入(便捷入口)
|
|
62
|
+
*
|
|
63
|
+
* @param roots - allowRoots
|
|
64
|
+
* @param options - 同 loadRootInstructionDocs
|
|
65
|
+
* @returns 注入字符串(无约定时为空串)
|
|
66
|
+
*/
|
|
67
|
+
export declare function loadRootInstructionsInjection(roots: string[] | undefined, options?: {
|
|
68
|
+
cwd?: string;
|
|
69
|
+
maxFileBytes?: number;
|
|
70
|
+
maxTotalBytes?: number;
|
|
71
|
+
}): Promise<string>;
|
|
72
|
+
export {};
|