@octopi-agent/engine 0.70.7 → 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 +201 -9
- package/dist/config-schema/engine.js +31 -2
- 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 +1 -1
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +178 -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 +47 -3
- package/dist/harness/agent/builder.js +180 -54
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +81 -291
- 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/registry.js +10 -0
- 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-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 +5 -2
- package/dist/harness/context/layers.js +11 -5
- 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 +30 -0
- package/dist/harness/context/system-prompt-assembler.js +67 -6
- 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 +1 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -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 +277 -81
- 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.js +25 -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 +14 -12
- package/dist/harness/index.js +9 -6
- 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 +3 -3
- 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/index.d.ts +1 -0
- package/dist/harness/memory/index.js +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +2 -0
- 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.js +9 -9
- 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 +12 -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 +18 -0
- package/dist/harness/run/agent/agent.js +26 -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 +110 -18
- 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 +556 -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/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/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +13 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.js +10 -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 -43
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
- 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
|
@@ -20,6 +20,7 @@ export function createSessionSearchTool(options) {
|
|
|
20
20
|
return {
|
|
21
21
|
definition: {
|
|
22
22
|
name: 'session_search',
|
|
23
|
+
capabilities: ['fs-read'],
|
|
23
24
|
description: 'Search past session conversations (Information layer, not memory propositions). Returns session-grouped hits with snippet + `ref` for session_read. Prefer concrete entities (paths, error strings, names). Default excludes tool I/O and archived cold storage. Use memory_search for distilled conclusions; use this for original wording / what happened.',
|
|
24
25
|
parameters: {
|
|
25
26
|
query: {
|
|
@@ -98,6 +99,7 @@ export function createSessionReadTool(options) {
|
|
|
98
99
|
return {
|
|
99
100
|
definition: {
|
|
100
101
|
name: 'session_read',
|
|
102
|
+
capabilities: ['fs-read'],
|
|
101
103
|
description: 'Open a window of past session messages around a hit (`ref` from session_search) or index. Returns transcript lines. Read-only. Use after session_search to recover original context.',
|
|
102
104
|
parameters: {
|
|
103
105
|
session_id: { type: 'string', description: 'Session id', required: true },
|
|
@@ -29,7 +29,16 @@ import type { LLMToolDefinition } from '@octopi-agent/core/interfaces/model-prov
|
|
|
29
29
|
export declare class DefaultToolBus implements ToolBus {
|
|
30
30
|
private globalTools;
|
|
31
31
|
private agentTools;
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Register a global tool.
|
|
34
|
+
*
|
|
35
|
+
* Duplicate names throw by default: silent replace lets a later plugin
|
|
36
|
+
* shadow `file_write`/`shell` and bypass L2/undo. Intentional reload uses
|
|
37
|
+
* `{ replace: true }` (audited via console.warn).
|
|
38
|
+
*/
|
|
39
|
+
register(tool: RegisteredTool, options?: {
|
|
40
|
+
replace?: boolean;
|
|
41
|
+
}): void;
|
|
33
42
|
registerAll(tools: RegisteredTool[]): void;
|
|
34
43
|
registerForAgent(agentId: string, tool: RegisteredTool): void;
|
|
35
44
|
unregister(name: string, agentId?: string): boolean;
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @module harness/extension/plugin-ecosystem/tools/tool-bus
|
|
18
18
|
*/
|
|
19
|
+
import { registerToolCapabilities } from '../../execution-environment/tool-capabilities.js';
|
|
20
|
+
import { buildToolLlmParameters } from '../../../agent/tool-purpose.js';
|
|
19
21
|
/**
|
|
20
22
|
* DefaultToolBus — 工具总线实现
|
|
21
23
|
*
|
|
@@ -27,12 +29,24 @@ export class DefaultToolBus {
|
|
|
27
29
|
globalTools = new Map();
|
|
28
30
|
agentTools = new Map();
|
|
29
31
|
// ── 注册 ──
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Register a global tool.
|
|
34
|
+
*
|
|
35
|
+
* Duplicate names throw by default: silent replace lets a later plugin
|
|
36
|
+
* shadow `file_write`/`shell` and bypass L2/undo. Intentional reload uses
|
|
37
|
+
* `{ replace: true }` (audited via console.warn).
|
|
38
|
+
*/
|
|
39
|
+
register(tool, options) {
|
|
31
40
|
const { name } = tool.definition;
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
const exists = this.globalTools.has(name);
|
|
42
|
+
if (exists && !options?.replace) {
|
|
43
|
+
throw new Error(`Global tool "${name}" already registered (pass replace:true to override)`);
|
|
44
|
+
}
|
|
45
|
+
if (exists && options?.replace) {
|
|
46
|
+
console.warn(`[ToolBus] global tool "${name}" explicitly replaced`);
|
|
34
47
|
}
|
|
35
48
|
this.globalTools.set(name, tool);
|
|
49
|
+
registerToolCapabilities(name, tool.definition.capabilities);
|
|
36
50
|
}
|
|
37
51
|
registerAll(tools) {
|
|
38
52
|
for (const tool of tools) {
|
|
@@ -44,6 +58,7 @@ export class DefaultToolBus {
|
|
|
44
58
|
this.agentTools.set(agentId, new Map());
|
|
45
59
|
}
|
|
46
60
|
this.agentTools.get(agentId).set(tool.definition.name, tool);
|
|
61
|
+
registerToolCapabilities(tool.definition.name, tool.definition.capabilities);
|
|
47
62
|
}
|
|
48
63
|
unregister(name, agentId) {
|
|
49
64
|
if (agentId) {
|
|
@@ -87,7 +102,13 @@ export class DefaultToolBus {
|
|
|
87
102
|
}
|
|
88
103
|
if (policy.deny && policy.deny.length > 0) {
|
|
89
104
|
const denySet = new Set(policy.deny);
|
|
90
|
-
|
|
105
|
+
// deny '*' = deny every tool (mirror allow '*')
|
|
106
|
+
if (denySet.has('*')) {
|
|
107
|
+
tools = [];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
tools = tools.filter(t => !denySet.has(t.definition.name));
|
|
111
|
+
}
|
|
91
112
|
}
|
|
92
113
|
}
|
|
93
114
|
return tools;
|
|
@@ -98,20 +119,8 @@ export class DefaultToolBus {
|
|
|
98
119
|
function: {
|
|
99
120
|
name: definition.definition.name,
|
|
100
121
|
description: definition.definition.description,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
properties: Object.fromEntries(Object.entries(definition.definition.parameters).map(([key, param]) => [
|
|
104
|
-
key,
|
|
105
|
-
{
|
|
106
|
-
type: param.type,
|
|
107
|
-
description: param.description,
|
|
108
|
-
...(param.enum && { enum: param.enum }),
|
|
109
|
-
},
|
|
110
|
-
])),
|
|
111
|
-
required: Object.entries(definition.definition.parameters)
|
|
112
|
-
.filter(([, param]) => param.required)
|
|
113
|
-
.map(([key]) => key),
|
|
114
|
-
},
|
|
122
|
+
// 与 convertToAgentTool 同构:purpose 统一装配
|
|
123
|
+
parameters: buildToolLlmParameters(definition.definition.parameters),
|
|
115
124
|
},
|
|
116
125
|
}));
|
|
117
126
|
}
|
|
@@ -151,7 +160,14 @@ export class DefaultToolBus {
|
|
|
151
160
|
throw new Error(`Tool "${name}" not found`);
|
|
152
161
|
}
|
|
153
162
|
this.validateArgs(name, args, tool.definition);
|
|
154
|
-
|
|
163
|
+
const { runWithToolLimits, resolveToolTimeoutMs } = await import('../../execution-environment/resource-limits.js');
|
|
164
|
+
return runWithToolLimits((signal) => tool.handler(args, { ...context, abortSignal: signal }), {
|
|
165
|
+
timeoutMs: context.processLimits !== false
|
|
166
|
+
? resolveToolTimeoutMs(tool.definition)
|
|
167
|
+
: undefined,
|
|
168
|
+
abortSignal: context.abortSignal,
|
|
169
|
+
toolName: tool.definition.name,
|
|
170
|
+
});
|
|
155
171
|
}
|
|
156
172
|
/**
|
|
157
173
|
* 获取全局注册的工具名集合(用于 SecurityGuard 的 registeredTools 校验)
|
|
@@ -23,10 +23,18 @@ export interface ToolSetConfig {
|
|
|
23
23
|
};
|
|
24
24
|
/** Summary 公用能力(http_request / file_read L1/L2) */
|
|
25
25
|
summary?: import('../../../context/capabilities/summary/index.js').ToolSummarySupport;
|
|
26
|
+
/** CredentialStore — http_request.credential(绑定强制见 store.resolve) */
|
|
27
|
+
credentials?: import('../../../governance/credentials/store.js').CredentialStore | null;
|
|
28
|
+
/** http_request 网络门禁(默认拒私网) */
|
|
29
|
+
network?: import('../../../knowledge/network-guard.js').NetworkGuardOptions;
|
|
30
|
+
/** 无绑定凭证拒绝(credentials.requireBindings / untrusted) */
|
|
31
|
+
requireCredentialBindings?: boolean;
|
|
26
32
|
/** DocumentPort(document_read / document_probe) */
|
|
27
33
|
documentPort?: import('./document-tools.js').DocumentToolOptions['documentPort'];
|
|
28
34
|
/** Information 历史检索(session_search / session_read) */
|
|
29
35
|
sessionHistory?: SessionHistoryPort;
|
|
36
|
+
/** DelegateService — 委派编排(delegate_* 工具) */
|
|
37
|
+
delegation?: import('../../../collaboration/delegation/service.js').DelegateService;
|
|
30
38
|
}
|
|
31
39
|
export interface ToolSet {
|
|
32
40
|
builtin: RegisteredTool[];
|
|
@@ -4,11 +4,15 @@ import { createSessionTaskTools } from '../../../session/tasks/tools.js';
|
|
|
4
4
|
import { createAskUserTool } from './ask-user.js';
|
|
5
5
|
import { createWebSearchTool } from './web-search.js';
|
|
6
6
|
import { createSessionHistoryTools } from './session-history.js';
|
|
7
|
+
import { createDelegationTools } from './delegation.js';
|
|
7
8
|
export function createToolSet(config) {
|
|
8
9
|
const taskService = config?.sessionTaskService ?? config?.taskTracker;
|
|
9
10
|
const builtin = getBuiltinTools({
|
|
10
11
|
summary: config?.summary,
|
|
11
12
|
documentPort: config?.documentPort,
|
|
13
|
+
credentials: config?.credentials,
|
|
14
|
+
network: config?.network,
|
|
15
|
+
requireCredentialBindings: config?.requireCredentialBindings,
|
|
12
16
|
});
|
|
13
17
|
const extensions = [
|
|
14
18
|
...(config?.memoryStore ? createMemoryTools(config.memoryStore, config?.memory) : []),
|
|
@@ -28,6 +32,7 @@ export function createToolSet(config) {
|
|
|
28
32
|
summary: config?.summary,
|
|
29
33
|
})
|
|
30
34
|
: []),
|
|
35
|
+
...(config?.delegation ? createDelegationTools(config.delegation) : []),
|
|
31
36
|
];
|
|
32
37
|
return { builtin, extensions, all: [...builtin, ...extensions] };
|
|
33
38
|
}
|
|
@@ -17,6 +17,7 @@ export function createWebSearchTool(provider, options = {}) {
|
|
|
17
17
|
return {
|
|
18
18
|
definition: {
|
|
19
19
|
name: 'web_search',
|
|
20
|
+
capabilities: ['egress'],
|
|
20
21
|
description: 'Search the web for current information. Returns titles, URLs, and snippets. ' +
|
|
21
22
|
'Use when you need up-to-date facts, documentation, news, or sources outside the local workspace.',
|
|
22
23
|
parameters: {
|
|
@@ -6,4 +6,4 @@ export type { CredentialDatabaseOptions, CredentialPaths } from './db.js';
|
|
|
6
6
|
export { CredentialStore } from './store.js';
|
|
7
7
|
export { loadCredentialMasterKey, encryptSecret, decryptSecret, } from './crypto.js';
|
|
8
8
|
export { defaultCredentialHeaders } from './types.js';
|
|
9
|
-
export type { CredentialKind, CredentialScopeLevel, CredentialScopeRef, CredentialConsumerKind, CredentialConsumerRef, CredentialMeta, CredentialWrite, ResolvedCredential, SecretMode, } from './types.js';
|
|
9
|
+
export type { CredentialKind, CredentialScopeLevel, CredentialScopeRef, CredentialConsumerKind, CredentialConsumerRef, CredentialMeta, CredentialWrite, ResolvedCredential, ResolveCredentialOptions, SecretMode, } from './types.js';
|
|
@@ -8,14 +8,21 @@ import { CredentialDatabase } from './db.js';
|
|
|
8
8
|
import { type CredentialConsumerRef, type CredentialMeta, type CredentialWrite, type ResolvedCredential } from './types.js';
|
|
9
9
|
export declare class CredentialStore {
|
|
10
10
|
private db;
|
|
11
|
-
|
|
11
|
+
/** true 时无绑定的凭证不可 resolve(部署拧紧 / untrusted) */
|
|
12
|
+
private readonly requireBindings;
|
|
13
|
+
constructor(db: CredentialDatabase, options?: {
|
|
14
|
+
requireBindings?: boolean;
|
|
15
|
+
});
|
|
12
16
|
static open(options?: {
|
|
13
17
|
dbPath?: string;
|
|
18
|
+
requireBindings?: boolean;
|
|
14
19
|
}): Promise<CredentialStore>;
|
|
15
20
|
/**
|
|
16
21
|
* 按 OCTOPI_HOME 打开默认 credentials.db
|
|
17
22
|
*/
|
|
18
|
-
static openDefault(octopiHome: string
|
|
23
|
+
static openDefault(octopiHome: string, options?: {
|
|
24
|
+
requireBindings?: boolean;
|
|
25
|
+
}): Promise<CredentialStore>;
|
|
19
26
|
get database(): CredentialDatabase;
|
|
20
27
|
/**
|
|
21
28
|
* 登记/轮换凭证(元数据 + 密钥引用;不回传密文)
|
|
@@ -32,12 +39,17 @@ export declare class CredentialStore {
|
|
|
32
39
|
list(): CredentialMeta[];
|
|
33
40
|
delete(name: string): boolean;
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
42
|
+
* 用时解析为请求头(短命;调用方禁止日志)。
|
|
43
|
+
* 消费侧强制 `credential_bindings`(SEC-3c):绑定非空须命中 consumer;
|
|
44
|
+
* 绑定为空且 requireBindings 时拒绝。
|
|
36
45
|
*
|
|
37
46
|
* @param name - 凭证名
|
|
47
|
+
* @param consumer - 消费方;绑定非空时必填
|
|
48
|
+
* @param options - requireBindings 覆盖
|
|
38
49
|
* @returns 解析结果;无档或无密钥材料时 null
|
|
50
|
+
* @throws 绑定策略拒绝时抛错(勿静默降级)
|
|
39
51
|
*/
|
|
40
|
-
resolve(name: string): Promise<ResolvedCredential | null>;
|
|
52
|
+
resolve(name: string, consumer?: import('./types.js').CredentialConsumerRef | null, options?: import('./types.js').ResolveCredentialOptions): Promise<ResolvedCredential | null>;
|
|
41
53
|
bind(consumer: CredentialConsumerRef, name: string): void;
|
|
42
54
|
unbind(consumer: CredentialConsumerRef, name: string): void;
|
|
43
55
|
listBindings(name: string): Array<{
|
|
@@ -38,19 +38,25 @@ function rowToMeta(row) {
|
|
|
38
38
|
}
|
|
39
39
|
export class CredentialStore {
|
|
40
40
|
db;
|
|
41
|
-
|
|
41
|
+
/** true 时无绑定的凭证不可 resolve(部署拧紧 / untrusted) */
|
|
42
|
+
requireBindings;
|
|
43
|
+
constructor(db, options) {
|
|
42
44
|
this.db = db;
|
|
45
|
+
this.requireBindings = options?.requireBindings === true;
|
|
43
46
|
}
|
|
44
47
|
static async open(options) {
|
|
45
48
|
const db = await CredentialDatabase.create(options);
|
|
46
|
-
return new CredentialStore(db);
|
|
49
|
+
return new CredentialStore(db, { requireBindings: options?.requireBindings });
|
|
47
50
|
}
|
|
48
51
|
/**
|
|
49
52
|
* 按 OCTOPI_HOME 打开默认 credentials.db
|
|
50
53
|
*/
|
|
51
|
-
static async openDefault(octopiHome) {
|
|
54
|
+
static async openDefault(octopiHome, options) {
|
|
52
55
|
const paths = resolveCredentialPaths(octopiHome);
|
|
53
|
-
return CredentialStore.open({
|
|
56
|
+
return CredentialStore.open({
|
|
57
|
+
dbPath: paths.dbPath,
|
|
58
|
+
requireBindings: options?.requireBindings,
|
|
59
|
+
});
|
|
54
60
|
}
|
|
55
61
|
get database() {
|
|
56
62
|
return this.db;
|
|
@@ -141,12 +147,17 @@ export class CredentialStore {
|
|
|
141
147
|
return Number(res.changes ?? 0) > 0;
|
|
142
148
|
}
|
|
143
149
|
/**
|
|
144
|
-
*
|
|
150
|
+
* 用时解析为请求头(短命;调用方禁止日志)。
|
|
151
|
+
* 消费侧强制 `credential_bindings`(SEC-3c):绑定非空须命中 consumer;
|
|
152
|
+
* 绑定为空且 requireBindings 时拒绝。
|
|
145
153
|
*
|
|
146
154
|
* @param name - 凭证名
|
|
155
|
+
* @param consumer - 消费方;绑定非空时必填
|
|
156
|
+
* @param options - requireBindings 覆盖
|
|
147
157
|
* @returns 解析结果;无档或无密钥材料时 null
|
|
158
|
+
* @throws 绑定策略拒绝时抛错(勿静默降级)
|
|
148
159
|
*/
|
|
149
|
-
async resolve(name) {
|
|
160
|
+
async resolve(name, consumer, options) {
|
|
150
161
|
const row = this.db.raw
|
|
151
162
|
.prepare(`SELECT * FROM credentials WHERE name = ?`)
|
|
152
163
|
.get(name);
|
|
@@ -156,6 +167,22 @@ export class CredentialStore {
|
|
|
156
167
|
if (meta.expiresAt != null && meta.expiresAt < Date.now()) {
|
|
157
168
|
return null;
|
|
158
169
|
}
|
|
170
|
+
// 只紧不松:显式 true 可收紧;false/undefined 不得覆盖 store 级 requireBindings
|
|
171
|
+
const require = options?.requireBindings === true || this.requireBindings === true;
|
|
172
|
+
const bindings = this.listBindings(name);
|
|
173
|
+
if (require && bindings.length === 0) {
|
|
174
|
+
throw new Error(`credential "${name}" has no bindings and requireBindings is enabled`);
|
|
175
|
+
}
|
|
176
|
+
if (bindings.length > 0) {
|
|
177
|
+
const ref = consumer ?? options?.consumer ?? null;
|
|
178
|
+
if (!ref) {
|
|
179
|
+
throw new Error(`credential "${name}" is bound; consumer required to resolve`);
|
|
180
|
+
}
|
|
181
|
+
const hit = bindings.some((b) => b.kind === ref.kind && b.id === ref.id);
|
|
182
|
+
if (!hit) {
|
|
183
|
+
throw new Error(`credential "${name}" is not bound to consumer ${ref.kind}:${ref.id}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
159
186
|
const kind = meta.kind;
|
|
160
187
|
let secret = null;
|
|
161
188
|
if (meta.secretMode === 'env' && meta.secretEnv) {
|
|
@@ -58,6 +58,17 @@ export interface ResolvedCredential {
|
|
|
58
58
|
name: string;
|
|
59
59
|
headers: Record<string, string>;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* resolve 消费约束(SEC-3c)。
|
|
63
|
+
* - 绑定表非空 → consumer 必须命中,否则拒绝
|
|
64
|
+
* - 绑定表为空 → 默认可解析(兼容);requireBindings=true 时拒绝
|
|
65
|
+
*/
|
|
66
|
+
export interface ResolveCredentialOptions {
|
|
67
|
+
/** 消费方(knowledge_source / tool / …);绑定非空时必填 */
|
|
68
|
+
consumer?: CredentialConsumerRef | null;
|
|
69
|
+
/** 覆盖 store 级 requireBindings(untrusted 严档 / 配置) */
|
|
70
|
+
requireBindings?: boolean;
|
|
71
|
+
}
|
|
61
72
|
export declare function defaultCredentialHeaders(input: {
|
|
62
73
|
kind: CredentialKind;
|
|
63
74
|
username?: string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HITL decision cache (SEC-7 single model).
|
|
3
|
+
*
|
|
4
|
+
* Hosts only *express* a {@link HitlDecision}; the engine remembers
|
|
5
|
+
* `approve_session` / `approve_always` so the confirm hook is not re-entered.
|
|
6
|
+
* `deny` and one-shot `approve` are never cached.
|
|
7
|
+
*
|
|
8
|
+
* Scoping (narrow-only):
|
|
9
|
+
* - `approve_session` → per `sessionId` + tool/effect key
|
|
10
|
+
* - `approve_always` → per `agentId` + tool/effect key(agent 信任级不同则分桶)
|
|
11
|
+
* Missing scope id → degrade to one-shot (never over-grant).
|
|
12
|
+
*/
|
|
13
|
+
import type { HitlDecision } from '@octopi-agent/core/types/tools.js';
|
|
14
|
+
/** Which confirm surface produced the decision */
|
|
15
|
+
export type HitlChannel = 'high_risk' | 'effect';
|
|
16
|
+
/** Cached scope of a remembered approval */
|
|
17
|
+
export type HitlCacheScope = 'session' | 'always';
|
|
18
|
+
/**
|
|
19
|
+
* In-memory HITL approval cache.
|
|
20
|
+
*
|
|
21
|
+
* Session-scoped approvals are keyed by `sessionId` and expire after
|
|
22
|
+
* {@link HitlDecisionCache.sessionTtlMs}. Always-scoped approvals are keyed by
|
|
23
|
+
* `agentId` and live for the process lifetime (not persisted).
|
|
24
|
+
*/
|
|
25
|
+
export declare class HitlDecisionCache {
|
|
26
|
+
/** Session-scope TTL in ms (default 24h) */
|
|
27
|
+
readonly sessionTtlMs: number;
|
|
28
|
+
private session;
|
|
29
|
+
private always;
|
|
30
|
+
/** In-flight resolves, so concurrent same-key confirms share one ask() */
|
|
31
|
+
private inflight;
|
|
32
|
+
/**
|
|
33
|
+
* @param sessionTtlMs - how long `approve_session` stays valid (default 24h)
|
|
34
|
+
*/
|
|
35
|
+
constructor(sessionTtlMs?: number);
|
|
36
|
+
/**
|
|
37
|
+
* Look up a remembered approval.
|
|
38
|
+
*
|
|
39
|
+
* @param channel - high_risk | effect
|
|
40
|
+
* @param key - tool name or effect kind
|
|
41
|
+
* @param options - sessionId (session scope) and/or agentId (always scope)
|
|
42
|
+
* @returns `'approve'` if cached, otherwise `null`
|
|
43
|
+
*/
|
|
44
|
+
get(channel: HitlChannel, key: string, options?: {
|
|
45
|
+
sessionId?: string;
|
|
46
|
+
agentId?: string;
|
|
47
|
+
}): 'approve' | null;
|
|
48
|
+
/**
|
|
49
|
+
* Remember an approval decision. Only `approve_session` / `approve_always`
|
|
50
|
+
* are stored; `deny` and one-shot `approve` are ignored.
|
|
51
|
+
*
|
|
52
|
+
* `approve_session` requires `sessionId`; `approve_always` requires `agentId`.
|
|
53
|
+
* Missing scope id → silently one-shot (fail-safe, never over-grant).
|
|
54
|
+
*
|
|
55
|
+
* @param decision - host decision
|
|
56
|
+
* @param channel - high_risk | effect
|
|
57
|
+
* @param key - tool name or effect kind
|
|
58
|
+
* @param options - sessionId and/or agentId
|
|
59
|
+
*/
|
|
60
|
+
remember(decision: HitlDecision, channel: HitlChannel, key: string, options?: {
|
|
61
|
+
sessionId?: string;
|
|
62
|
+
agentId?: string;
|
|
63
|
+
}): void;
|
|
64
|
+
/**
|
|
65
|
+
* Drop session-scoped approvals for one session (always-scope kept).
|
|
66
|
+
*
|
|
67
|
+
* @param sessionId - session to clear
|
|
68
|
+
*/
|
|
69
|
+
clearSession(sessionId: string): void;
|
|
70
|
+
/** Drop always-scoped approvals for one agent. */
|
|
71
|
+
clearAgent(agentId: string): void;
|
|
72
|
+
/** Drop all cached approvals (tests / host reset). */
|
|
73
|
+
clear(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Resolve through cache + host hook with in-flight de-dup.
|
|
76
|
+
* Concurrent callers for the same key share one `ask()`.
|
|
77
|
+
*/
|
|
78
|
+
resolve(options: {
|
|
79
|
+
channel: HitlChannel;
|
|
80
|
+
key: string;
|
|
81
|
+
sessionId?: string;
|
|
82
|
+
agentId?: string;
|
|
83
|
+
ask: () => Promise<HitlDecision>;
|
|
84
|
+
}): Promise<boolean>;
|
|
85
|
+
private resolveUncached;
|
|
86
|
+
}
|
|
87
|
+
/** Process-wide default cache (keys include sessionId / agentId). */
|
|
88
|
+
export declare const defaultHitlCache: HitlDecisionCache;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve a HITL confirm through cache + host hook (SEC-7).
|
|
91
|
+
*
|
|
92
|
+
* Fail-closed: missing hook, thrown error, or non-approve decision → false.
|
|
93
|
+
* Concurrent same-key callers share one host prompt (in-flight de-dup).
|
|
94
|
+
*
|
|
95
|
+
* @param options - cache, channel, key, sessionId, agentId, and the host ask callback
|
|
96
|
+
* @returns true only when the call is approved (cached or live)
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolveHitlDecision(options: {
|
|
99
|
+
cache?: HitlDecisionCache;
|
|
100
|
+
channel: HitlChannel;
|
|
101
|
+
key: string;
|
|
102
|
+
sessionId?: string;
|
|
103
|
+
agentId?: string;
|
|
104
|
+
ask: () => Promise<HitlDecision>;
|
|
105
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HITL decision cache (SEC-7 single model).
|
|
3
|
+
*
|
|
4
|
+
* Hosts only *express* a {@link HitlDecision}; the engine remembers
|
|
5
|
+
* `approve_session` / `approve_always` so the confirm hook is not re-entered.
|
|
6
|
+
* `deny` and one-shot `approve` are never cached.
|
|
7
|
+
*
|
|
8
|
+
* Scoping (narrow-only):
|
|
9
|
+
* - `approve_session` → per `sessionId` + tool/effect key
|
|
10
|
+
* - `approve_always` → per `agentId` + tool/effect key(agent 信任级不同则分桶)
|
|
11
|
+
* Missing scope id → degrade to one-shot (never over-grant).
|
|
12
|
+
*/
|
|
13
|
+
function channelKey(channel, key) {
|
|
14
|
+
return `${channel}\0${key}`;
|
|
15
|
+
}
|
|
16
|
+
function sessionKey(channel, sessionId, key) {
|
|
17
|
+
return `${sessionId}\0${channelKey(channel, key)}`;
|
|
18
|
+
}
|
|
19
|
+
/** always is agent-scoped: different trust domains do not share grants */
|
|
20
|
+
function alwaysKey(agentId, channel, key) {
|
|
21
|
+
return `${agentId}\0${channelKey(channel, key)}`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* In-memory HITL approval cache.
|
|
25
|
+
*
|
|
26
|
+
* Session-scoped approvals are keyed by `sessionId` and expire after
|
|
27
|
+
* {@link HitlDecisionCache.sessionTtlMs}. Always-scoped approvals are keyed by
|
|
28
|
+
* `agentId` and live for the process lifetime (not persisted).
|
|
29
|
+
*/
|
|
30
|
+
export class HitlDecisionCache {
|
|
31
|
+
/** Session-scope TTL in ms (default 24h) */
|
|
32
|
+
sessionTtlMs;
|
|
33
|
+
session = new Map();
|
|
34
|
+
always = new Map();
|
|
35
|
+
/** In-flight resolves, so concurrent same-key confirms share one ask() */
|
|
36
|
+
inflight = new Map();
|
|
37
|
+
/**
|
|
38
|
+
* @param sessionTtlMs - how long `approve_session` stays valid (default 24h)
|
|
39
|
+
*/
|
|
40
|
+
constructor(sessionTtlMs = 24 * 60 * 60 * 1000) {
|
|
41
|
+
this.sessionTtlMs = sessionTtlMs;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Look up a remembered approval.
|
|
45
|
+
*
|
|
46
|
+
* @param channel - high_risk | effect
|
|
47
|
+
* @param key - tool name or effect kind
|
|
48
|
+
* @param options - sessionId (session scope) and/or agentId (always scope)
|
|
49
|
+
* @returns `'approve'` if cached, otherwise `null`
|
|
50
|
+
*/
|
|
51
|
+
get(channel, key, options = {}) {
|
|
52
|
+
const { sessionId, agentId } = options;
|
|
53
|
+
if (agentId) {
|
|
54
|
+
const always = this.always.get(alwaysKey(agentId, channel, key));
|
|
55
|
+
if (always)
|
|
56
|
+
return always;
|
|
57
|
+
}
|
|
58
|
+
if (!sessionId)
|
|
59
|
+
return null;
|
|
60
|
+
const entry = this.session.get(sessionKey(channel, sessionId, key));
|
|
61
|
+
if (!entry)
|
|
62
|
+
return null;
|
|
63
|
+
if (entry.expiresAt < Date.now()) {
|
|
64
|
+
this.session.delete(sessionKey(channel, sessionId, key));
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return entry.decision;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Remember an approval decision. Only `approve_session` / `approve_always`
|
|
71
|
+
* are stored; `deny` and one-shot `approve` are ignored.
|
|
72
|
+
*
|
|
73
|
+
* `approve_session` requires `sessionId`; `approve_always` requires `agentId`.
|
|
74
|
+
* Missing scope id → silently one-shot (fail-safe, never over-grant).
|
|
75
|
+
*
|
|
76
|
+
* @param decision - host decision
|
|
77
|
+
* @param channel - high_risk | effect
|
|
78
|
+
* @param key - tool name or effect kind
|
|
79
|
+
* @param options - sessionId and/or agentId
|
|
80
|
+
*/
|
|
81
|
+
remember(decision, channel, key, options = {}) {
|
|
82
|
+
const { sessionId, agentId } = options;
|
|
83
|
+
if (decision === 'approve_always') {
|
|
84
|
+
if (!agentId)
|
|
85
|
+
return;
|
|
86
|
+
this.always.set(alwaysKey(agentId, channel, key), 'approve');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (decision === 'approve_session') {
|
|
90
|
+
if (!sessionId)
|
|
91
|
+
return;
|
|
92
|
+
this.session.set(sessionKey(channel, sessionId, key), {
|
|
93
|
+
decision: 'approve',
|
|
94
|
+
expiresAt: Date.now() + this.sessionTtlMs,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Drop session-scoped approvals for one session (always-scope kept).
|
|
100
|
+
*
|
|
101
|
+
* @param sessionId - session to clear
|
|
102
|
+
*/
|
|
103
|
+
clearSession(sessionId) {
|
|
104
|
+
const prefix = `${sessionId}\0`;
|
|
105
|
+
for (const k of this.session.keys()) {
|
|
106
|
+
if (k.startsWith(prefix))
|
|
107
|
+
this.session.delete(k);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Drop always-scoped approvals for one agent. */
|
|
111
|
+
clearAgent(agentId) {
|
|
112
|
+
const prefix = `${agentId}\0`;
|
|
113
|
+
for (const k of this.always.keys()) {
|
|
114
|
+
if (k.startsWith(prefix))
|
|
115
|
+
this.always.delete(k);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Drop all cached approvals (tests / host reset). */
|
|
119
|
+
clear() {
|
|
120
|
+
this.session.clear();
|
|
121
|
+
this.always.clear();
|
|
122
|
+
this.inflight.clear();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve through cache + host hook with in-flight de-dup.
|
|
126
|
+
* Concurrent callers for the same key share one `ask()`.
|
|
127
|
+
*/
|
|
128
|
+
resolve(options) {
|
|
129
|
+
const inflightKey = options.sessionId
|
|
130
|
+
? sessionKey(options.channel, options.sessionId, options.key)
|
|
131
|
+
: options.agentId
|
|
132
|
+
? alwaysKey(options.agentId, options.channel, options.key)
|
|
133
|
+
: channelKey(options.channel, options.key);
|
|
134
|
+
const existing = this.inflight.get(inflightKey);
|
|
135
|
+
if (existing)
|
|
136
|
+
return existing;
|
|
137
|
+
const pending = this.resolveUncached(options).finally(() => {
|
|
138
|
+
this.inflight.delete(inflightKey);
|
|
139
|
+
});
|
|
140
|
+
this.inflight.set(inflightKey, pending);
|
|
141
|
+
return pending;
|
|
142
|
+
}
|
|
143
|
+
async resolveUncached(options) {
|
|
144
|
+
const cached = this.get(options.channel, options.key, {
|
|
145
|
+
sessionId: options.sessionId,
|
|
146
|
+
agentId: options.agentId,
|
|
147
|
+
});
|
|
148
|
+
if (cached === 'approve')
|
|
149
|
+
return true;
|
|
150
|
+
let decision;
|
|
151
|
+
try {
|
|
152
|
+
decision = await options.ask();
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// 审批通道异常按拒绝处理(fail-safe);此处吞掉仅因「异常不改变不放行」结论
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (decision === 'approve' ||
|
|
159
|
+
decision === 'approve_session' ||
|
|
160
|
+
decision === 'approve_always') {
|
|
161
|
+
this.remember(decision, options.channel, options.key, {
|
|
162
|
+
sessionId: options.sessionId,
|
|
163
|
+
agentId: options.agentId,
|
|
164
|
+
});
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** Process-wide default cache (keys include sessionId / agentId). */
|
|
171
|
+
export const defaultHitlCache = new HitlDecisionCache();
|
|
172
|
+
/**
|
|
173
|
+
* Resolve a HITL confirm through cache + host hook (SEC-7).
|
|
174
|
+
*
|
|
175
|
+
* Fail-closed: missing hook, thrown error, or non-approve decision → false.
|
|
176
|
+
* Concurrent same-key callers share one host prompt (in-flight de-dup).
|
|
177
|
+
*
|
|
178
|
+
* @param options - cache, channel, key, sessionId, agentId, and the host ask callback
|
|
179
|
+
* @returns true only when the call is approved (cached or live)
|
|
180
|
+
*/
|
|
181
|
+
export async function resolveHitlDecision(options) {
|
|
182
|
+
const cache = options.cache ?? defaultHitlCache;
|
|
183
|
+
return cache.resolve(options);
|
|
184
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Human-in-the-Loop 领域 — 人机交互
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 职责:确认决策缓存(session / always)+ 统一 resolve(SEC-7 单模型)。
|
|
5
|
+
* 强制面在 `confirmHighRisk` / `confirmEffect` 两条钩子,不在本目录另起生命周期。
|
|
6
6
|
*/
|
|
7
|
-
export {
|
|
8
|
-
export type {
|
|
9
|
-
export type {
|
|
7
|
+
export { HitlDecisionCache, defaultHitlCache, resolveHitlDecision, } from './decision-cache.js';
|
|
8
|
+
export type { HitlChannel, HitlCacheScope } from './decision-cache.js';
|
|
9
|
+
export type { HitlDecision } from './types.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Human-in-the-Loop 领域 — 人机交互
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 职责:确认决策缓存(session / always)+ 统一 resolve(SEC-7 单模型)。
|
|
5
|
+
* 强制面在 `confirmHighRisk` / `confirmEffect` 两条钩子,不在本目录另起生命周期。
|
|
6
6
|
*/
|
|
7
|
-
export {
|
|
7
|
+
export { HitlDecisionCache, defaultHitlCache, resolveHitlDecision, } from './decision-cache.js';
|