@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
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolEffectPolicy P3 — 运行模式预设与有效策略
|
|
3
|
+
*
|
|
4
|
+
* 命名模式(workspace / project / host / untrusted)展开为正交旋钮。
|
|
5
|
+
* 见 arch/tool-effect-policy.md §7。
|
|
6
|
+
*/
|
|
7
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
8
|
+
import { deniesReducedSurface, resolveToolCapabilities, } from './tool-capabilities.js';
|
|
9
|
+
import { assessL4ProcessMinimum, } from './process-isolation.js';
|
|
10
|
+
import { resolveHitlDecision } from '../../governance/human-in-the-loop/decision-cache.js';
|
|
11
|
+
import { getRunSessionId, getRunScope } from '../../run/run-scope.js';
|
|
12
|
+
/**
|
|
13
|
+
* Engine default when `effectPolicy.mode` is omitted (secure-by-default).
|
|
14
|
+
* Scaffold/`octopi init` / `octopi.example.json` set `mode: "host"` explicitly
|
|
15
|
+
* so evaluation gets full capability; embedders who omit `mode` get `workspace`.
|
|
16
|
+
* See `docs/process-isolation.md`.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_EFFECT_RUN_MODE = 'workspace';
|
|
19
|
+
const MODE_DEFAULTS = {
|
|
20
|
+
workspace: {
|
|
21
|
+
mode: 'workspace',
|
|
22
|
+
toolIsolation: 'session-subdir',
|
|
23
|
+
pathContainment: 'strict',
|
|
24
|
+
// 无 L4 时无法「只禁越界」:deny = 拒绝 shell 工具(fail-closed)
|
|
25
|
+
shellEscape: 'deny',
|
|
26
|
+
network: 'deny',
|
|
27
|
+
processLimits: true,
|
|
28
|
+
commit: 'auto',
|
|
29
|
+
onClose: 'commit',
|
|
30
|
+
effects: 'engine',
|
|
31
|
+
shellJournal: 'snapshot',
|
|
32
|
+
},
|
|
33
|
+
project: {
|
|
34
|
+
mode: 'project',
|
|
35
|
+
toolIsolation: 'session-subdir',
|
|
36
|
+
pathContainment: 'strict',
|
|
37
|
+
// 编码 agent 必须有 shell;文件侧靠 L2,shell FS 越界待 L4
|
|
38
|
+
shellEscape: 'allow',
|
|
39
|
+
network: 'open',
|
|
40
|
+
processLimits: true,
|
|
41
|
+
commit: 'auto',
|
|
42
|
+
onClose: 'commit',
|
|
43
|
+
effects: 'engine',
|
|
44
|
+
shellJournal: 'snapshot',
|
|
45
|
+
},
|
|
46
|
+
host: {
|
|
47
|
+
mode: 'host',
|
|
48
|
+
toolIsolation: 'none',
|
|
49
|
+
pathContainment: 'none',
|
|
50
|
+
shellEscape: 'allow',
|
|
51
|
+
network: 'open',
|
|
52
|
+
processLimits: true,
|
|
53
|
+
commit: 'auto',
|
|
54
|
+
onClose: 'commit',
|
|
55
|
+
effects: 'engine',
|
|
56
|
+
shellJournal: 'snapshot',
|
|
57
|
+
},
|
|
58
|
+
untrusted: {
|
|
59
|
+
mode: 'untrusted',
|
|
60
|
+
toolIsolation: 'session-subdir',
|
|
61
|
+
pathContainment: 'strict',
|
|
62
|
+
shellEscape: 'deny',
|
|
63
|
+
network: 'deny',
|
|
64
|
+
processLimits: true,
|
|
65
|
+
commit: 'auto',
|
|
66
|
+
onClose: 'discard',
|
|
67
|
+
effects: 'engine',
|
|
68
|
+
shellJournal: 'snapshot',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 展开 effectPolicy 为有效策略
|
|
73
|
+
*
|
|
74
|
+
* @param config - 用户配置(mode 可省略,缺省 `DEFAULT_EFFECT_RUN_MODE`)
|
|
75
|
+
* @param baseWorkspace - 工具基路径(agent.workspace / RunConfig.cwd)
|
|
76
|
+
* @returns 有效策略
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* Expand effectPolicy into an effective policy.
|
|
80
|
+
*
|
|
81
|
+
* `untrusted` requires an L4 process profile. When the host cannot offer it:
|
|
82
|
+
* - `untrustedAdmission: 'refuse'` (default) throws
|
|
83
|
+
* - `untrustedAdmission: 'degrade'` renames effectiveMode to workspace,
|
|
84
|
+
* sets toolSurface=reduced, and records securityDegraded[] (never silent)
|
|
85
|
+
*
|
|
86
|
+
* @param config - user config (mode optional)
|
|
87
|
+
* @param baseWorkspace - tool base path
|
|
88
|
+
* @param isolation - probed process isolation (optional; treated as supervised if absent)
|
|
89
|
+
* @returns effective policy with requested vs effective mode
|
|
90
|
+
* @throws Error when untrusted is refused
|
|
91
|
+
*/
|
|
92
|
+
export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
93
|
+
const requestedMode = config.mode ?? DEFAULT_EFFECT_RUN_MODE;
|
|
94
|
+
const untrustedAdmission = config.untrustedAdmission ?? 'refuse';
|
|
95
|
+
let mode = requestedMode;
|
|
96
|
+
let toolSurface = 'full';
|
|
97
|
+
const securityDegraded = [];
|
|
98
|
+
if (requestedMode === 'untrusted') {
|
|
99
|
+
const profile = isolation;
|
|
100
|
+
const l4 = profile ? assessL4ProcessMinimum(profile) : { ok: false, missing: ['processTree'] };
|
|
101
|
+
if (!l4.ok) {
|
|
102
|
+
if (untrustedAdmission === 'refuse') {
|
|
103
|
+
throw new Error(`untrusted_refused: L4 process jail unavailable (missing: ${l4.missing.join(', ')}). ` +
|
|
104
|
+
`Install bwrap/sandbox-exec or set effectPolicy.untrustedAdmission=degrade.`);
|
|
105
|
+
}
|
|
106
|
+
// degrade: rename + strip power, do not keep the untrusted label
|
|
107
|
+
mode = 'workspace';
|
|
108
|
+
toolSurface = 'reduced';
|
|
109
|
+
securityDegraded.push('no_process_jail');
|
|
110
|
+
if (profile?.filesystem === 'none' || profile?.filesystem === 'cwd-pin') {
|
|
111
|
+
securityDegraded.push('filesystem_not_jailed');
|
|
112
|
+
}
|
|
113
|
+
if (profile?.privilege === 'same')
|
|
114
|
+
securityDegraded.push('privilege_same');
|
|
115
|
+
if (profile?.envHygiene === 'inherit')
|
|
116
|
+
securityDegraded.push('env_inherit');
|
|
117
|
+
}
|
|
118
|
+
// Declare open egress whenever the host cannot close it — not only when
|
|
119
|
+
// effective mode is still named untrusted (degrade renames mode first).
|
|
120
|
+
if (isolation?.network === 'open') {
|
|
121
|
+
securityDegraded.push('network_open');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Path jail is part of the untrusted promise; never loosen it from config.
|
|
125
|
+
const d = MODE_DEFAULTS[mode];
|
|
126
|
+
const pathContainment = requestedMode === 'untrusted'
|
|
127
|
+
? 'strict'
|
|
128
|
+
: (config.pathContainment ?? d.pathContainment);
|
|
129
|
+
// untrusted intent residue: keep discard-on-close even when effectiveMode renames
|
|
130
|
+
const onClose = config.onClose ??
|
|
131
|
+
(requestedMode === 'untrusted' ? MODE_DEFAULTS.untrusted.onClose : d.onClose);
|
|
132
|
+
const extra = (config.transactionRoots ?? []).map((p) => p.trim()).filter(Boolean);
|
|
133
|
+
const allowRoots = [...(baseWorkspace?.trim() ? [baseWorkspace.trim()] : []), ...extra];
|
|
134
|
+
return {
|
|
135
|
+
requestedMode,
|
|
136
|
+
mode,
|
|
137
|
+
untrustedAdmission,
|
|
138
|
+
toolSurface,
|
|
139
|
+
securityDegraded,
|
|
140
|
+
toolIsolation: config.toolIsolation ?? d.toolIsolation,
|
|
141
|
+
pathContainment,
|
|
142
|
+
// degraded untrusted must not leave shell allow as a hole
|
|
143
|
+
shellEscape: toolSurface === 'reduced' ? 'deny' : (config.shellEscape ?? d.shellEscape),
|
|
144
|
+
// untrusted product promise: egress deny is not a config knob (like pathContainment)
|
|
145
|
+
network: requestedMode === 'untrusted' || toolSurface === 'reduced'
|
|
146
|
+
? 'deny'
|
|
147
|
+
: (config.network ?? d.network),
|
|
148
|
+
processLimits: config.processLimits ?? d.processLimits,
|
|
149
|
+
commit: config.commit ?? d.commit,
|
|
150
|
+
onClose,
|
|
151
|
+
effects: config.effects ?? d.effects,
|
|
152
|
+
allowRoots,
|
|
153
|
+
transactionRoots: [
|
|
154
|
+
'workspace',
|
|
155
|
+
'memory',
|
|
156
|
+
...extra.map(() => 'host'),
|
|
157
|
+
],
|
|
158
|
+
undoLimit: config.undoLimit,
|
|
159
|
+
shellJournal: config.shellJournal ?? 'snapshot',
|
|
160
|
+
shellJournalLimit: config.shellJournalLimit,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Whether a tool is on the reduced surface (untrusted degrade).
|
|
165
|
+
* Reduced keeps content tools inside L2; strips egress and code-exec power.
|
|
166
|
+
*
|
|
167
|
+
* @param toolName - registered tool name
|
|
168
|
+
* @param surface - full or reduced
|
|
169
|
+
* @returns whether the tool may run
|
|
170
|
+
*/
|
|
171
|
+
export function isToolAllowedOnSurface(toolName, surface, capabilities) {
|
|
172
|
+
if (surface === 'full')
|
|
173
|
+
return true;
|
|
174
|
+
// D5-a: capability tags, not names. Unknown on reduced = reject (unknown-reject).
|
|
175
|
+
const caps = resolveToolCapabilities(toolName, capabilities);
|
|
176
|
+
if (caps === null)
|
|
177
|
+
return false;
|
|
178
|
+
return !deniesReducedSurface(caps);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* L2:路径是否落在 allowRoots 内
|
|
182
|
+
*
|
|
183
|
+
* @param resolved - 已 resolve 的绝对路径
|
|
184
|
+
* @param allowRoots - 允许根
|
|
185
|
+
* @param containment - 级别;none 一律放行;soft 仅用于审计(由调用方记日志)
|
|
186
|
+
* @returns 是否允许
|
|
187
|
+
*/
|
|
188
|
+
export function isPathAllowed(resolved, allowRoots, containment) {
|
|
189
|
+
if (containment === 'none')
|
|
190
|
+
return true;
|
|
191
|
+
if (allowRoots.length === 0)
|
|
192
|
+
return containment !== 'strict';
|
|
193
|
+
const norm = (p) => p.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
194
|
+
const win = process.platform === 'win32';
|
|
195
|
+
const target = win ? norm(resolved).toLowerCase() : norm(resolved);
|
|
196
|
+
return allowRoots.some((root) => {
|
|
197
|
+
const r = win ? norm(root).toLowerCase() : norm(root);
|
|
198
|
+
return target === r || target.startsWith(r + '/');
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 效应闸(P4):事务内自动放行;host-gate 交给宿主;engine 通道按内置策略。
|
|
203
|
+
*
|
|
204
|
+
* @param intent - 效应意图
|
|
205
|
+
* @param options - 通道与回调
|
|
206
|
+
* @throws Error 当拒绝执行时
|
|
207
|
+
*/
|
|
208
|
+
export async function gateEffect(intent, options) {
|
|
209
|
+
// 可事务化(可 undo)→ 自动
|
|
210
|
+
if (intent.kind === 'memory.write' && intent.transactional)
|
|
211
|
+
return;
|
|
212
|
+
if (intent.kind === 'file.write' && intent.transactional)
|
|
213
|
+
return;
|
|
214
|
+
if (intent.kind === 'shell') {
|
|
215
|
+
const esc = options.shellEscape ?? 'allow';
|
|
216
|
+
// deny:无 L4 无法只禁越界,必须拒绝 shell(fail-closed,保策略语义)
|
|
217
|
+
if (esc === 'deny') {
|
|
218
|
+
throw new Error('shell_denied: shellEscape=deny (cannot contain shell escapes until L4; use mode=project|host or shellEscape=allow|confirm)');
|
|
219
|
+
}
|
|
220
|
+
// confirm:必须走 host-gate
|
|
221
|
+
if (esc === 'confirm' && options.effects !== 'host-gate') {
|
|
222
|
+
throw new Error('shell_confirm_required: shellEscape=confirm requires effectPolicy.effects=host-gate + confirmEffect');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// `runner` / `vcs` are dedicated allowlisted tools, not arbitrary shell.
|
|
226
|
+
// shellEscape gates the shell tool only — workspace stays capable of git/project scripts.
|
|
227
|
+
if (options.effects !== 'host-gate') {
|
|
228
|
+
// engine 通道:路径牢笼由 L2 承担;shell 已在上方按 shellEscape 处理
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// host-gate:非事务效应交给宿主(自动放行 / 宿主 UI / 策略引擎)
|
|
232
|
+
const decide = options.confirmEffect;
|
|
233
|
+
if (!decide) {
|
|
234
|
+
throw new Error('confirm_effect_missing: effectPolicy.effects=host-gate requires confirmEffect callback');
|
|
235
|
+
}
|
|
236
|
+
// SEC-7:HitlDecision + 引擎缓存;失败路径 fail-closed
|
|
237
|
+
const allowed = await resolveHitlDecision({
|
|
238
|
+
cache: options.hitlCache,
|
|
239
|
+
channel: 'effect',
|
|
240
|
+
key: intent.kind,
|
|
241
|
+
sessionId: options.sessionId ?? getRunSessionId(),
|
|
242
|
+
agentId: options.agentId ?? getRunScope()?.agentId,
|
|
243
|
+
ask: () => decide(intent),
|
|
244
|
+
});
|
|
245
|
+
if (!allowed) {
|
|
246
|
+
throw new Error(`effect_denied: ${intent.kind}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const EFFECT_OVERRIDES_META_KEY = 'effectOverrides';
|
|
250
|
+
/**
|
|
251
|
+
* Parse `session.metadata.effectOverrides` safely (read path).
|
|
252
|
+
*
|
|
253
|
+
* Invalid entries are **skipped**, not thrown: a poisoned/corrupt metadata bag
|
|
254
|
+
* must not abort run start. Strict validation belongs on the write API
|
|
255
|
+
* (`normalizeTransactionRoots`).
|
|
256
|
+
*
|
|
257
|
+
* @param metadata - session metadata bag
|
|
258
|
+
* @returns valid absolute roots only (empty when absent/invalid)
|
|
259
|
+
*/
|
|
260
|
+
export function readSessionEffectOverrides(metadata) {
|
|
261
|
+
const raw = metadata?.[EFFECT_OVERRIDES_META_KEY];
|
|
262
|
+
if (!raw || typeof raw !== 'object')
|
|
263
|
+
return {};
|
|
264
|
+
const bag = raw;
|
|
265
|
+
const list = bag.transactionRoots;
|
|
266
|
+
if (!Array.isArray(list))
|
|
267
|
+
return {};
|
|
268
|
+
const out = [];
|
|
269
|
+
const seen = new Set();
|
|
270
|
+
for (const item of list) {
|
|
271
|
+
if (typeof item !== 'string')
|
|
272
|
+
continue;
|
|
273
|
+
const t = item.trim();
|
|
274
|
+
if (!t || !isAbsolute(t))
|
|
275
|
+
continue;
|
|
276
|
+
const abs = resolve(t);
|
|
277
|
+
const key = process.platform === 'win32' ? abs.toLowerCase() : abs;
|
|
278
|
+
if (seen.has(key))
|
|
279
|
+
continue;
|
|
280
|
+
seen.add(key);
|
|
281
|
+
out.push(abs);
|
|
282
|
+
}
|
|
283
|
+
return { transactionRoots: out };
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Normalize and validate transaction root paths (absolute, non-empty).
|
|
287
|
+
*
|
|
288
|
+
* @param paths - raw paths
|
|
289
|
+
* @returns absolute normalized unique paths
|
|
290
|
+
* @throws Error when a path is empty or not absolute
|
|
291
|
+
*/
|
|
292
|
+
export function normalizeTransactionRoots(paths) {
|
|
293
|
+
const out = [];
|
|
294
|
+
const seen = new Set();
|
|
295
|
+
for (const raw of paths) {
|
|
296
|
+
const t = typeof raw === 'string' ? raw.trim() : '';
|
|
297
|
+
if (!t)
|
|
298
|
+
throw new Error('effect_root_empty: path must be a non-empty string');
|
|
299
|
+
// Require caller-supplied absolute paths (do not silently join cwd)
|
|
300
|
+
if (!isAbsolute(t)) {
|
|
301
|
+
throw new Error(`effect_root_not_absolute: ${t}`);
|
|
302
|
+
}
|
|
303
|
+
const abs = resolve(t);
|
|
304
|
+
const key = process.platform === 'win32' ? abs.toLowerCase() : abs;
|
|
305
|
+
if (seen.has(key))
|
|
306
|
+
continue;
|
|
307
|
+
seen.add(key);
|
|
308
|
+
out.push(abs);
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Append session roots to base allowRoots (dedupe; base wins on conflicts).
|
|
314
|
+
*
|
|
315
|
+
* @param baseRoots - roots from effectPolicy / workspace
|
|
316
|
+
* @param extraRoots - session temporary roots
|
|
317
|
+
* @returns combined unique list
|
|
318
|
+
*/
|
|
319
|
+
export function mergeTransactionRoots(baseRoots, extraRoots) {
|
|
320
|
+
const out = [...baseRoots];
|
|
321
|
+
const seen = new Set(out.map((p) => (process.platform === 'win32' ? p.toLowerCase() : p)));
|
|
322
|
+
for (const p of extraRoots ?? []) {
|
|
323
|
+
const key = process.platform === 'win32' ? p.toLowerCase() : p;
|
|
324
|
+
if (seen.has(key))
|
|
325
|
+
continue;
|
|
326
|
+
seen.add(key);
|
|
327
|
+
out.push(p);
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Metadata key used on SessionData.metadata / SessionStore.updateMetadata.
|
|
333
|
+
*/
|
|
334
|
+
export const SESSION_EFFECT_OVERRIDES_KEY = EFFECT_OVERRIDES_META_KEY;
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Execution Environment 领域 — 执行环境
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 职责:沙箱管理、工作区生命周期、文件操作、资源限制、turn 文件 undo(L3)。
|
|
5
5
|
* 契约见 ./types.ts。
|
|
6
6
|
*/
|
|
7
|
-
export { ProcessSandbox } from './sandbox.js';
|
|
7
|
+
export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, supervisedSpawnProfile, } from './sandbox.js';
|
|
8
|
+
export { probeProcessIsolation, scrubEnv, killProcessTree, L4_PROCESS_MINIMUM, } from './process-isolation.js';
|
|
9
|
+
export type { ProcessIsolationProfile, IsolationBackend, ProcessTreeIsolation, FilesystemIsolation, ResourceIsolation, NetworkIsolation, PrivilegeIsolation, EnvHygiene, L4ProcessAssessment, } from './process-isolation.js';
|
|
8
10
|
export { FileWorkspace } from './workspace.js';
|
|
9
11
|
export type { FileWorkspaceConfig } from './workspace.js';
|
|
12
|
+
export { DEFAULT_TOOL_ISOLATION, resolveToolIsolationCwd, safeSessionDirSegment, looksLikeAbsoluteSessionPath, } from './isolation.js';
|
|
13
|
+
export type { ToolIsolationMode, ResolveToolIsolationCwdInput, ResolveToolIsolationCwdResult, } from './isolation.js';
|
|
14
|
+
export { TurnFileUndoLog, commitSessionFileUndo, discardSessionFileUndo, resolveSessionUndoPaths, resolveSessionUndoOnClose, } from './undo-log.js';
|
|
15
|
+
export type { SessionUndoPaths, FileUndoEntry, DiscardFileEffectsResult, DiscardConflictReason, } from './undo-log.js';
|
|
16
|
+
export { isProbablyText, reverseAgentOverwrite, merge3Lines } from './undo-merge.js';
|
|
17
|
+
export { snapshotShellRoots, captureShellInventory, diffShellInventory, journalShellDiff, writeNotReversed, } from './shell-journal.js';
|
|
18
|
+
export { resolveEffectiveEffectPolicy, isPathAllowed, isToolAllowedOnSurface, gateEffect, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './effect-policy.js';
|
|
19
|
+
export type { UntrustedAdmission, ToolSurface, SecurityDegradation, EffectiveEffectPolicy, SessionEffectOverrides, } from './effect-policy.js';
|
|
20
|
+
export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './resource-limits.js';
|
|
21
|
+
export type { ToolRunLimits } from './resource-limits.js';
|
|
22
|
+
export { TurnMemoryJournal, JournaledMemoryStore, createMemoryRestorer, discardMemoryUndo, } from './memory-undo.js';
|
|
23
|
+
export type { MemoryUndoEntry, MemoryEffectRestorer, DiscardMemoryEffectsResult, } from './memory-undo.js';
|
|
10
24
|
export type { IsolationLevel, SandboxConfig, ResourceLimits, ResourceUsage, SandboxResult, SandboxProvider, WorkspaceConfig, WorkspaceSnapshot, Workspace, SearchOptions, FileMatch, } from './types.js';
|
|
25
|
+
export { resolveToolCapabilities, deniesReducedSurface, BUILTIN_TOOL_CAPABILITIES, REDUCED_DENIED_CAPABILITIES, } from './tool-capabilities.js';
|
|
26
|
+
export type { ToolCapability } from './tool-capabilities.js';
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Execution Environment 领域 — 执行环境
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 职责:沙箱管理、工作区生命周期、文件操作、资源限制、turn 文件 undo(L3)。
|
|
5
5
|
* 契约见 ./types.ts。
|
|
6
6
|
*/
|
|
7
|
-
export { ProcessSandbox } from './sandbox.js';
|
|
7
|
+
export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, supervisedSpawnProfile, } from './sandbox.js';
|
|
8
|
+
export { probeProcessIsolation, scrubEnv, killProcessTree, L4_PROCESS_MINIMUM, } from './process-isolation.js';
|
|
8
9
|
export { FileWorkspace } from './workspace.js';
|
|
10
|
+
export { DEFAULT_TOOL_ISOLATION, resolveToolIsolationCwd, safeSessionDirSegment, looksLikeAbsoluteSessionPath, } from './isolation.js';
|
|
11
|
+
export { TurnFileUndoLog, commitSessionFileUndo, discardSessionFileUndo, resolveSessionUndoPaths, resolveSessionUndoOnClose, } from './undo-log.js';
|
|
12
|
+
export { isProbablyText, reverseAgentOverwrite, merge3Lines } from './undo-merge.js';
|
|
13
|
+
export { snapshotShellRoots, captureShellInventory, diffShellInventory, journalShellDiff, writeNotReversed, } from './shell-journal.js';
|
|
14
|
+
export { resolveEffectiveEffectPolicy, isPathAllowed, isToolAllowedOnSurface, gateEffect, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './effect-policy.js';
|
|
15
|
+
export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './resource-limits.js';
|
|
16
|
+
export { TurnMemoryJournal, JournaledMemoryStore, createMemoryRestorer, discardMemoryUndo, } from './memory-undo.js';
|
|
17
|
+
export { resolveToolCapabilities, deniesReducedSurface, BUILTIN_TOOL_CAPABILITIES, REDUCED_DENIED_CAPABILITIES, } from './tool-capabilities.js';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn 记忆面 undo(ToolEffectPolicy L3 P2)
|
|
3
|
+
*
|
|
4
|
+
* 与文件 undo 同目录(`sessions/<sid>/undo/memory.jsonl`)。
|
|
5
|
+
* 只覆盖 **本轮 run 作用域内** 经 store 写口的效应;steward 异步写不进 journal。
|
|
6
|
+
* knowledge 不在此列(非事务)。
|
|
7
|
+
*/
|
|
8
|
+
import type { MemoryEffectDomain, MemoryEffectJournal } from '@octopi-agent/core/types/tools.js';
|
|
9
|
+
import type { MemoryEntry, MemoryStore } from '../../memory/types.js';
|
|
10
|
+
/** 记忆面 undo 条目 */
|
|
11
|
+
export type MemoryUndoEntry = {
|
|
12
|
+
op: 'insert';
|
|
13
|
+
domain: MemoryEffectDomain;
|
|
14
|
+
id: string;
|
|
15
|
+
} | {
|
|
16
|
+
op: 'update';
|
|
17
|
+
domain: MemoryEffectDomain;
|
|
18
|
+
id: string;
|
|
19
|
+
before: unknown;
|
|
20
|
+
} | {
|
|
21
|
+
op: 'delete';
|
|
22
|
+
domain: MemoryEffectDomain;
|
|
23
|
+
id: string;
|
|
24
|
+
before: unknown;
|
|
25
|
+
};
|
|
26
|
+
/** 记忆面逆放执行器(由 store 提供) */
|
|
27
|
+
export interface MemoryEffectRestorer {
|
|
28
|
+
/** 逆放 insert:按 id 删除 */
|
|
29
|
+
deleteById(domain: MemoryEffectDomain, id: string): Promise<void>;
|
|
30
|
+
/** 逆放 update/delete:恢复 before 整行(同 id) */
|
|
31
|
+
restoreRow(domain: MemoryEffectDomain, id: string, before: unknown): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface DiscardMemoryEffectsResult {
|
|
34
|
+
reversed: Array<{
|
|
35
|
+
domain: MemoryEffectDomain;
|
|
36
|
+
id: string;
|
|
37
|
+
op: MemoryUndoEntry['op'];
|
|
38
|
+
}>;
|
|
39
|
+
failed: Array<{
|
|
40
|
+
domain: MemoryEffectDomain;
|
|
41
|
+
id: string;
|
|
42
|
+
reason: string;
|
|
43
|
+
}>;
|
|
44
|
+
entries: number;
|
|
45
|
+
}
|
|
46
|
+
/** 本轮记忆 journal 写入端 */
|
|
47
|
+
export declare class TurnMemoryJournal implements MemoryEffectJournal {
|
|
48
|
+
private readonly entries;
|
|
49
|
+
private sealed;
|
|
50
|
+
private readonly logPath;
|
|
51
|
+
private flushChain;
|
|
52
|
+
constructor(undoRoot: string);
|
|
53
|
+
get size(): number;
|
|
54
|
+
recordInsert(domain: MemoryEffectDomain, id: string): Promise<void>;
|
|
55
|
+
recordUpdate(domain: MemoryEffectDomain, id: string, before: unknown): Promise<void>;
|
|
56
|
+
recordDelete(domain: MemoryEffectDomain, id: string, before: unknown): Promise<void>;
|
|
57
|
+
private append;
|
|
58
|
+
private flush;
|
|
59
|
+
private doFlush;
|
|
60
|
+
seal(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 逆放记忆效应(编辑重发)。按记录逆序执行。
|
|
64
|
+
*
|
|
65
|
+
* @param undoRoot - `sessions/<sid>/undo`
|
|
66
|
+
* @param restorer - store 逆放器;缺失时全部记 failed
|
|
67
|
+
* @returns 逆放结果
|
|
68
|
+
*/
|
|
69
|
+
export declare function discardMemoryUndo(undoRoot: string, restorer?: MemoryEffectRestorer): Promise<DiscardMemoryEffectsResult>;
|
|
70
|
+
/**
|
|
71
|
+
* MemoryStore 装饰器:写口记 journal(RunScope ALS 提供)。
|
|
72
|
+
* 无活跃 journal 时写入照常(steward / turn 外),不记 undo。
|
|
73
|
+
*/
|
|
74
|
+
export declare class JournaledMemoryStore implements MemoryStore {
|
|
75
|
+
private readonly inner;
|
|
76
|
+
private readonly journalSource;
|
|
77
|
+
readonly name: string;
|
|
78
|
+
constructor(inner: MemoryStore, journalSource: () => MemoryEffectJournal | undefined);
|
|
79
|
+
store(entry: Omit<MemoryEntry, 'id' | 'accessCount' | 'lastAccessedAt' | 'createdAt' | 'decayFactor'>): Promise<string>;
|
|
80
|
+
retrieve: MemoryStore['retrieve'];
|
|
81
|
+
get(id: string): Promise<MemoryEntry | null>;
|
|
82
|
+
update(id: string, patch: Partial<MemoryEntry>): Promise<void>;
|
|
83
|
+
delete(id: string): Promise<void>;
|
|
84
|
+
softDelete(id: string, meta: {
|
|
85
|
+
by: string;
|
|
86
|
+
reason: string;
|
|
87
|
+
winnerId?: string;
|
|
88
|
+
}): Promise<void>;
|
|
89
|
+
undelete(id: string): Promise<void>;
|
|
90
|
+
importEntry(entry: MemoryEntry): Promise<void>;
|
|
91
|
+
listForGovern: MemoryStore['listForGovern'];
|
|
92
|
+
decay: MemoryStore['decay'];
|
|
93
|
+
stats: MemoryStore['stats'];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 由 MemoryStore 实现 restorer(编辑重发逆放)。
|
|
97
|
+
*
|
|
98
|
+
* @param store - 记忆 store
|
|
99
|
+
* @returns restorer
|
|
100
|
+
*/
|
|
101
|
+
export declare function createMemoryRestorer(store: MemoryStore): MemoryEffectRestorer;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn 记忆面 undo(ToolEffectPolicy L3 P2)
|
|
3
|
+
*
|
|
4
|
+
* 与文件 undo 同目录(`sessions/<sid>/undo/memory.jsonl`)。
|
|
5
|
+
* 只覆盖 **本轮 run 作用域内** 经 store 写口的效应;steward 异步写不进 journal。
|
|
6
|
+
* knowledge 不在此列(非事务)。
|
|
7
|
+
*/
|
|
8
|
+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
function memoryLogPath(undoRoot) {
|
|
11
|
+
return join(undoRoot, 'memory.jsonl');
|
|
12
|
+
}
|
|
13
|
+
/** 本轮记忆 journal 写入端 */
|
|
14
|
+
export class TurnMemoryJournal {
|
|
15
|
+
entries = [];
|
|
16
|
+
sealed = false;
|
|
17
|
+
logPath;
|
|
18
|
+
flushChain = Promise.resolve();
|
|
19
|
+
constructor(undoRoot) {
|
|
20
|
+
this.logPath = memoryLogPath(undoRoot);
|
|
21
|
+
}
|
|
22
|
+
get size() {
|
|
23
|
+
return this.entries.length;
|
|
24
|
+
}
|
|
25
|
+
async recordInsert(domain, id) {
|
|
26
|
+
this.append({ op: 'insert', domain, id });
|
|
27
|
+
await this.flush();
|
|
28
|
+
}
|
|
29
|
+
async recordUpdate(domain, id, before) {
|
|
30
|
+
this.append({ op: 'update', domain, id, before });
|
|
31
|
+
await this.flush();
|
|
32
|
+
}
|
|
33
|
+
async recordDelete(domain, id, before) {
|
|
34
|
+
this.append({ op: 'delete', domain, id, before });
|
|
35
|
+
await this.flush();
|
|
36
|
+
}
|
|
37
|
+
append(entry) {
|
|
38
|
+
if (this.sealed) {
|
|
39
|
+
throw new Error('turn memory undo journal already sealed');
|
|
40
|
+
}
|
|
41
|
+
this.entries.push(entry);
|
|
42
|
+
}
|
|
43
|
+
flush() {
|
|
44
|
+
this.flushChain = this.flushChain.then(() => this.doFlush()).catch(() => undefined);
|
|
45
|
+
return this.flushChain;
|
|
46
|
+
}
|
|
47
|
+
async doFlush() {
|
|
48
|
+
await mkdir(join(this.logPath, '..'), { recursive: true });
|
|
49
|
+
const body = this.entries.map((e) => JSON.stringify(e)).join('\n');
|
|
50
|
+
await writeFile(this.logPath, body + (this.entries.length ? '\n' : ''), 'utf8');
|
|
51
|
+
}
|
|
52
|
+
seal() {
|
|
53
|
+
this.sealed = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 逆放记忆效应(编辑重发)。按记录逆序执行。
|
|
58
|
+
*
|
|
59
|
+
* @param undoRoot - `sessions/<sid>/undo`
|
|
60
|
+
* @param restorer - store 逆放器;缺失时全部记 failed
|
|
61
|
+
* @returns 逆放结果
|
|
62
|
+
*/
|
|
63
|
+
export async function discardMemoryUndo(undoRoot, restorer) {
|
|
64
|
+
const result = { reversed: [], failed: [], entries: 0 };
|
|
65
|
+
const path = memoryLogPath(undoRoot);
|
|
66
|
+
let raw;
|
|
67
|
+
try {
|
|
68
|
+
raw = await readFile(path, 'utf8');
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
const entries = raw
|
|
74
|
+
.split('\n')
|
|
75
|
+
.filter((l) => l.trim())
|
|
76
|
+
.map((l) => JSON.parse(l));
|
|
77
|
+
result.entries = entries.length;
|
|
78
|
+
for (const entry of [...entries].reverse()) {
|
|
79
|
+
if (!restorer) {
|
|
80
|
+
result.failed.push({ domain: entry.domain, id: entry.id, reason: 'memory_restorer_missing' });
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
if (entry.op === 'insert') {
|
|
85
|
+
await restorer.deleteById(entry.domain, entry.id);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await restorer.restoreRow(entry.domain, entry.id, entry.before);
|
|
89
|
+
}
|
|
90
|
+
result.reversed.push({ domain: entry.domain, id: entry.id, op: entry.op });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
result.failed.push({
|
|
94
|
+
domain: entry.domain,
|
|
95
|
+
id: entry.id,
|
|
96
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
await rm(path, { force: true });
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* MemoryStore 装饰器:写口记 journal(RunScope ALS 提供)。
|
|
105
|
+
* 无活跃 journal 时写入照常(steward / turn 外),不记 undo。
|
|
106
|
+
*/
|
|
107
|
+
export class JournaledMemoryStore {
|
|
108
|
+
inner;
|
|
109
|
+
journalSource;
|
|
110
|
+
name;
|
|
111
|
+
constructor(inner, journalSource) {
|
|
112
|
+
this.inner = inner;
|
|
113
|
+
this.journalSource = journalSource;
|
|
114
|
+
this.name = inner.name;
|
|
115
|
+
}
|
|
116
|
+
async store(entry) {
|
|
117
|
+
const id = await this.inner.store(entry);
|
|
118
|
+
await this.journalSource()?.recordInsert('memory', id);
|
|
119
|
+
return id;
|
|
120
|
+
}
|
|
121
|
+
retrieve = (query) => this.inner.retrieve(query);
|
|
122
|
+
get(id) {
|
|
123
|
+
return this.inner.get(id);
|
|
124
|
+
}
|
|
125
|
+
async update(id, patch) {
|
|
126
|
+
const before = await this.inner.get(id);
|
|
127
|
+
await this.inner.update(id, patch);
|
|
128
|
+
if (before)
|
|
129
|
+
await this.journalSource()?.recordUpdate('memory', id, before);
|
|
130
|
+
}
|
|
131
|
+
async delete(id) {
|
|
132
|
+
const before = await this.inner.get(id);
|
|
133
|
+
await this.inner.delete(id);
|
|
134
|
+
if (before)
|
|
135
|
+
await this.journalSource()?.recordDelete('memory', id, before);
|
|
136
|
+
}
|
|
137
|
+
async softDelete(id, meta) {
|
|
138
|
+
const before = await this.inner.get(id);
|
|
139
|
+
await this.inner.softDelete(id, meta);
|
|
140
|
+
if (before)
|
|
141
|
+
await this.journalSource()?.recordUpdate('memory', id, before);
|
|
142
|
+
}
|
|
143
|
+
async undelete(id) {
|
|
144
|
+
const before = await this.inner.get(id);
|
|
145
|
+
await this.inner.undelete(id);
|
|
146
|
+
if (before)
|
|
147
|
+
await this.journalSource()?.recordUpdate('memory', id, before);
|
|
148
|
+
}
|
|
149
|
+
async importEntry(entry) {
|
|
150
|
+
const withImport = this.inner;
|
|
151
|
+
if (withImport.importEntry) {
|
|
152
|
+
await withImport.importEntry(entry);
|
|
153
|
+
await this.journalSource()?.recordInsert('memory', entry.id);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
throw new Error('importEntry_not_supported');
|
|
157
|
+
}
|
|
158
|
+
listForGovern = (filter) => this.inner.listForGovern(filter);
|
|
159
|
+
decay = (options) => this.inner.decay(options);
|
|
160
|
+
stats = () => this.inner.stats();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 由 MemoryStore 实现 restorer(编辑重发逆放)。
|
|
164
|
+
*
|
|
165
|
+
* @param store - 记忆 store
|
|
166
|
+
* @returns restorer
|
|
167
|
+
*/
|
|
168
|
+
export function createMemoryRestorer(store) {
|
|
169
|
+
return {
|
|
170
|
+
async deleteById(_domain, id) {
|
|
171
|
+
await store.delete(id);
|
|
172
|
+
},
|
|
173
|
+
async restoreRow(_domain, id, before) {
|
|
174
|
+
const row = before;
|
|
175
|
+
const existing = await store.get(id);
|
|
176
|
+
if (existing) {
|
|
177
|
+
await store.update(id, row);
|
|
178
|
+
// softDelete 痕迹:before 未删而 current 已删 → undelete
|
|
179
|
+
if (!row.deleted && existing.deleted) {
|
|
180
|
+
await store.undelete(id);
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const withImport = store;
|
|
185
|
+
if (withImport.importEntry) {
|
|
186
|
+
await withImport.importEntry({ ...row, id });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
throw new Error(`cannot_restore_memory_row:${id}`);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|