@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,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process isolation capability contract (L4 process tier).
|
|
3
|
+
*
|
|
4
|
+
* A process jail is a capability profile, not a single OS API. Backends declare
|
|
5
|
+
* what they actually enforce; consumers must trust the profile, never the name.
|
|
6
|
+
* Public contract: `docs/process-isolation.md`.
|
|
7
|
+
*/
|
|
8
|
+
import { type ChildProcess } from 'node:child_process';
|
|
9
|
+
/** Kill semantics for the process tree */
|
|
10
|
+
export type ProcessTreeIsolation = 'supervised' | 'killable' | 'contained';
|
|
11
|
+
/** Filesystem confinement for writes */
|
|
12
|
+
export type FilesystemIsolation = 'none' | 'cwd-pin' | 'write-jailed' | 'write-jailed-best-effort' | 'root-jailed';
|
|
13
|
+
/** Resource enforcement quality */
|
|
14
|
+
export type ResourceIsolation = 'none' | 'best-effort' | 'os-enforced';
|
|
15
|
+
/** Egress posture (not part of L4 process minimum) */
|
|
16
|
+
export type NetworkIsolation = 'open' | 'deny' | 'allowlist';
|
|
17
|
+
/**
|
|
18
|
+
* Privilege of the child.
|
|
19
|
+
* `dropped` = the jail **denies privilege-gaining OS operations**
|
|
20
|
+
* (user namespace and/or Seatbelt `process-exec` denials for sudo/su/…).
|
|
21
|
+
* This does **not** require a different uid — `notes` must record which
|
|
22
|
+
* mechanism applies (`userns` vs `ops-denied`).
|
|
23
|
+
*/
|
|
24
|
+
export type PrivilegeIsolation = 'same' | 'dropped';
|
|
25
|
+
/** Whether host secrets can ride along in the environment */
|
|
26
|
+
export type EnvHygiene = 'inherit' | 'scrubbed';
|
|
27
|
+
/** Which backend produced the profile */
|
|
28
|
+
export type IsolationBackend = 'supervised-spawn' | 'linux-bwrap' | 'mac-seatbelt' | 'win-job' | 'container';
|
|
29
|
+
/** Honest isolation report for one execute/probe */
|
|
30
|
+
export interface ProcessIsolationProfile {
|
|
31
|
+
backend: IsolationBackend;
|
|
32
|
+
processTree: ProcessTreeIsolation;
|
|
33
|
+
filesystem: FilesystemIsolation;
|
|
34
|
+
resources: ResourceIsolation;
|
|
35
|
+
network: NetworkIsolation;
|
|
36
|
+
privilege: PrivilegeIsolation;
|
|
37
|
+
envHygiene: EnvHygiene;
|
|
38
|
+
/** Free-form capability notes for operators (e.g. missing bwrap) */
|
|
39
|
+
notes?: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* L4 process minimum (network is intentionally NOT required).
|
|
43
|
+
* `filesystem: write-jailed-best-effort` counts as meeting the floor (Windows).
|
|
44
|
+
*/
|
|
45
|
+
export declare const L4_PROCESS_MINIMUM: {
|
|
46
|
+
readonly processTree: ProcessTreeIsolation[];
|
|
47
|
+
readonly filesystem: FilesystemIsolation[];
|
|
48
|
+
readonly resources: ResourceIsolation[];
|
|
49
|
+
readonly envHygiene: EnvHygiene[];
|
|
50
|
+
readonly privilege: PrivilegeIsolation[];
|
|
51
|
+
};
|
|
52
|
+
export interface L4ProcessAssessment {
|
|
53
|
+
ok: boolean;
|
|
54
|
+
missing: Array<'processTree' | 'filesystem' | 'resources' | 'envHygiene' | 'privilege'>;
|
|
55
|
+
}
|
|
56
|
+
/** @param profile - isolation profile to assess */
|
|
57
|
+
export declare function assessL4ProcessMinimum(profile: ProcessIsolationProfile): L4ProcessAssessment;
|
|
58
|
+
/**
|
|
59
|
+
* Environment allowlist. Deny-by-default: only listed keys pass through.
|
|
60
|
+
* Secrets (API keys, tokens) must never inherit via `...process.env`.
|
|
61
|
+
*
|
|
62
|
+
* @param extra - explicit env for this run (still filtered against allowlist unless force)
|
|
63
|
+
* @param options - allow forcing extra keys (host responsibility)
|
|
64
|
+
* @returns scrubbed environment
|
|
65
|
+
*/
|
|
66
|
+
export declare function scrubEnv(extra?: Record<string, string>, options?: {
|
|
67
|
+
forceKeys?: string[];
|
|
68
|
+
}): Record<string, string>;
|
|
69
|
+
/**
|
|
70
|
+
* Best-effort process-tree kill. POSIX uses the process group; Windows uses taskkill /T.
|
|
71
|
+
*
|
|
72
|
+
* @param child - spawned child
|
|
73
|
+
* @returns whether a kill signal was issued
|
|
74
|
+
*/
|
|
75
|
+
export declare function killProcessTree(child: ChildProcess): boolean;
|
|
76
|
+
/** Reset probe cache (tests). */
|
|
77
|
+
export declare function resetProcessIsolationProbeCache(): void;
|
|
78
|
+
export declare function probeProcessIsolation(): Promise<ProcessIsolationProfile>;
|
|
79
|
+
/**
|
|
80
|
+
* Synthetic supervised profile (L1 only). Used when no probe has run yet.
|
|
81
|
+
*
|
|
82
|
+
* @returns baseline profile for supervised spawn
|
|
83
|
+
*/
|
|
84
|
+
export declare function supervisedSpawnProfile(): ProcessIsolationProfile;
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process isolation capability contract (L4 process tier).
|
|
3
|
+
*
|
|
4
|
+
* A process jail is a capability profile, not a single OS API. Backends declare
|
|
5
|
+
* what they actually enforce; consumers must trust the profile, never the name.
|
|
6
|
+
* Public contract: `docs/process-isolation.md`.
|
|
7
|
+
*/
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import { access, constants } from 'node:fs/promises';
|
|
10
|
+
import { delimiter, join } from 'node:path';
|
|
11
|
+
/**
|
|
12
|
+
* L4 process minimum (network is intentionally NOT required).
|
|
13
|
+
* `filesystem: write-jailed-best-effort` counts as meeting the floor (Windows).
|
|
14
|
+
*/
|
|
15
|
+
export const L4_PROCESS_MINIMUM = {
|
|
16
|
+
processTree: ['killable', 'contained'],
|
|
17
|
+
filesystem: [
|
|
18
|
+
'write-jailed',
|
|
19
|
+
'write-jailed-best-effort',
|
|
20
|
+
'root-jailed',
|
|
21
|
+
],
|
|
22
|
+
resources: ['best-effort', 'os-enforced'],
|
|
23
|
+
envHygiene: ['scrubbed'],
|
|
24
|
+
privilege: ['dropped'],
|
|
25
|
+
};
|
|
26
|
+
/** @param profile - isolation profile to assess */
|
|
27
|
+
export function assessL4ProcessMinimum(profile) {
|
|
28
|
+
const missing = [];
|
|
29
|
+
if (!L4_PROCESS_MINIMUM.processTree.includes(profile.processTree))
|
|
30
|
+
missing.push('processTree');
|
|
31
|
+
if (!L4_PROCESS_MINIMUM.filesystem.includes(profile.filesystem))
|
|
32
|
+
missing.push('filesystem');
|
|
33
|
+
if (!L4_PROCESS_MINIMUM.resources.includes(profile.resources))
|
|
34
|
+
missing.push('resources');
|
|
35
|
+
if (profile.envHygiene !== 'scrubbed')
|
|
36
|
+
missing.push('envHygiene');
|
|
37
|
+
if (profile.privilege !== 'dropped')
|
|
38
|
+
missing.push('privilege');
|
|
39
|
+
return { ok: missing.length === 0, missing };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Environment allowlist. Deny-by-default: only listed keys pass through.
|
|
43
|
+
* Secrets (API keys, tokens) must never inherit via `...process.env`.
|
|
44
|
+
*
|
|
45
|
+
* @param extra - explicit env for this run (still filtered against allowlist unless force)
|
|
46
|
+
* @param options - allow forcing extra keys (host responsibility)
|
|
47
|
+
* @returns scrubbed environment
|
|
48
|
+
*/
|
|
49
|
+
export function scrubEnv(extra, options) {
|
|
50
|
+
const allow = new Set([
|
|
51
|
+
'PATH',
|
|
52
|
+
'Path',
|
|
53
|
+
'HOME',
|
|
54
|
+
'USERPROFILE',
|
|
55
|
+
'HOMEDRIVE',
|
|
56
|
+
'HOMEPATH',
|
|
57
|
+
'TMP',
|
|
58
|
+
'TEMP',
|
|
59
|
+
'TMPDIR',
|
|
60
|
+
'LANG',
|
|
61
|
+
'LC_ALL',
|
|
62
|
+
'LC_CTYPE',
|
|
63
|
+
'TZ',
|
|
64
|
+
'SHELL',
|
|
65
|
+
'TERM',
|
|
66
|
+
'COMSPEC',
|
|
67
|
+
'PATHEXT',
|
|
68
|
+
'SYSTEMROOT',
|
|
69
|
+
'SystemRoot',
|
|
70
|
+
'WINDIR',
|
|
71
|
+
'windir',
|
|
72
|
+
'USER',
|
|
73
|
+
'LOGNAME',
|
|
74
|
+
'PWD',
|
|
75
|
+
'OLDPWD',
|
|
76
|
+
'NODE_ENV',
|
|
77
|
+
].map((k) => k.toLowerCase()));
|
|
78
|
+
for (const k of options?.forceKeys ?? [])
|
|
79
|
+
allow.add(k.toLowerCase());
|
|
80
|
+
const out = {};
|
|
81
|
+
for (const [k, v] of Object.entries(extra ?? {})) {
|
|
82
|
+
if (allow.has(k.toLowerCase()))
|
|
83
|
+
out[k] = v;
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Best-effort process-tree kill. POSIX uses the process group; Windows uses taskkill /T.
|
|
89
|
+
*
|
|
90
|
+
* @param child - spawned child
|
|
91
|
+
* @returns whether a kill signal was issued
|
|
92
|
+
*/
|
|
93
|
+
export function killProcessTree(child) {
|
|
94
|
+
const pid = child.pid;
|
|
95
|
+
if (typeof pid !== 'number' || pid <= 0)
|
|
96
|
+
return false;
|
|
97
|
+
try {
|
|
98
|
+
if (process.platform === 'win32') {
|
|
99
|
+
spawn('taskkill', ['/pid', String(pid), '/T', '/F'], {
|
|
100
|
+
stdio: 'ignore',
|
|
101
|
+
windowsHide: true,
|
|
102
|
+
}).unref();
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// Negative pid = process group (child spawned with detached/setpgid)
|
|
106
|
+
try {
|
|
107
|
+
process.kill(-pid, 'SIGKILL');
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
child.kill('SIGKILL');
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function canExecute(file) {
|
|
120
|
+
try {
|
|
121
|
+
await access(file, constants.X_OK);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function which(cmd) {
|
|
129
|
+
const exts = process.platform === 'win32'
|
|
130
|
+
? (process.env.PATHEXT ?? '.EXE;.CMD;.BAT').split(';').filter(Boolean)
|
|
131
|
+
: [''];
|
|
132
|
+
const paths = (process.env.PATH ?? '').split(delimiter).filter(Boolean);
|
|
133
|
+
for (const dir of paths) {
|
|
134
|
+
for (const ext of exts) {
|
|
135
|
+
const candidate = join(dir, cmd + ext);
|
|
136
|
+
if (await canExecute(candidate))
|
|
137
|
+
return candidate;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Probe the current host for the strongest available process backend.
|
|
144
|
+
* Never invents isolation: if nothing is available, returns supervised-spawn.
|
|
145
|
+
*
|
|
146
|
+
* @returns isolation profile this process can offer
|
|
147
|
+
*/
|
|
148
|
+
let cachedProbe = null;
|
|
149
|
+
/** Reset probe cache (tests). */
|
|
150
|
+
export function resetProcessIsolationProbeCache() {
|
|
151
|
+
cachedProbe = null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* One-shot bwrap usability smoke (user namespaces may be disabled in containers).
|
|
155
|
+
*
|
|
156
|
+
* @returns true when bwrap can actually spawn a jailed no-op
|
|
157
|
+
*/
|
|
158
|
+
async function bwrapUsable(bwrap) {
|
|
159
|
+
return new Promise((resolve) => {
|
|
160
|
+
const child = spawn(bwrap, ['--die-with-parent', '--unshare-all', '--ro-bind', '/', '/', '--', 'true'], {
|
|
161
|
+
stdio: 'ignore',
|
|
162
|
+
timeout: 2000,
|
|
163
|
+
});
|
|
164
|
+
child.on('error', () => resolve(false));
|
|
165
|
+
child.on('close', (code) => resolve(code === 0));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* One-shot Seatbelt usability smoke (`sandbox_apply` may be denied inside
|
|
170
|
+
* another sandbox). Probe and execute must agree: when no profile can be
|
|
171
|
+
* applied, the honest backend is supervised spawn from the start — never a
|
|
172
|
+
* wrapper run that then has to "recover".
|
|
173
|
+
*
|
|
174
|
+
* @param sandboxExec - resolved path to sandbox-exec
|
|
175
|
+
* @returns true when sandbox-exec can actually apply a profile
|
|
176
|
+
*/
|
|
177
|
+
async function sandboxExecUsable(sandboxExec) {
|
|
178
|
+
return new Promise((resolve) => {
|
|
179
|
+
const child = spawn(sandboxExec, ['-p', '(version 1)(allow default)', '--', '/usr/bin/true'], {
|
|
180
|
+
stdio: 'pipe',
|
|
181
|
+
timeout: 2000,
|
|
182
|
+
});
|
|
183
|
+
child.on('error', () => resolve(false));
|
|
184
|
+
child.on('close', (code) => resolve(code === 0));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
export async function probeProcessIsolation() {
|
|
188
|
+
if (cachedProbe)
|
|
189
|
+
return cachedProbe;
|
|
190
|
+
const notes = [];
|
|
191
|
+
if (process.platform === 'linux') {
|
|
192
|
+
const bwrap = await which('bwrap');
|
|
193
|
+
if (bwrap) {
|
|
194
|
+
if (await bwrapUsable(bwrap)) {
|
|
195
|
+
cachedProbe = {
|
|
196
|
+
backend: 'linux-bwrap',
|
|
197
|
+
processTree: 'contained',
|
|
198
|
+
filesystem: 'root-jailed',
|
|
199
|
+
resources: 'best-effort',
|
|
200
|
+
// Default jail posture (D4-c); execute() honors SandboxConfig.networkPolicy
|
|
201
|
+
network: 'deny',
|
|
202
|
+
privilege: 'dropped',
|
|
203
|
+
envHygiene: 'scrubbed',
|
|
204
|
+
notes: [`bwrap=${bwrap}`, 'privilege=dropped (userns)'],
|
|
205
|
+
};
|
|
206
|
+
return cachedProbe;
|
|
207
|
+
}
|
|
208
|
+
notes.push(`bwrap=${bwrap} present but unusable (userns denied?); no process jail`);
|
|
209
|
+
cachedProbe = {
|
|
210
|
+
backend: 'supervised-spawn',
|
|
211
|
+
processTree: 'killable',
|
|
212
|
+
filesystem: 'cwd-pin',
|
|
213
|
+
resources: 'best-effort',
|
|
214
|
+
network: 'open',
|
|
215
|
+
privilege: 'same',
|
|
216
|
+
envHygiene: 'scrubbed',
|
|
217
|
+
notes,
|
|
218
|
+
};
|
|
219
|
+
return cachedProbe;
|
|
220
|
+
}
|
|
221
|
+
notes.push('linux: bwrap not found; no process jail');
|
|
222
|
+
cachedProbe = {
|
|
223
|
+
backend: 'supervised-spawn',
|
|
224
|
+
processTree: 'killable',
|
|
225
|
+
filesystem: 'cwd-pin',
|
|
226
|
+
resources: 'best-effort',
|
|
227
|
+
network: 'open',
|
|
228
|
+
privilege: 'same',
|
|
229
|
+
envHygiene: 'scrubbed',
|
|
230
|
+
notes,
|
|
231
|
+
};
|
|
232
|
+
return cachedProbe;
|
|
233
|
+
}
|
|
234
|
+
if (process.platform === 'darwin') {
|
|
235
|
+
const sandboxExec = await which('sandbox-exec');
|
|
236
|
+
if (sandboxExec && (await sandboxExecUsable(sandboxExec))) {
|
|
237
|
+
// D3-b+: we generate a Seatbelt profile at execute time (allowRoots + network).
|
|
238
|
+
// write-jailed is therefore honest without OCTOPI_SB_PROFILE.
|
|
239
|
+
cachedProbe = {
|
|
240
|
+
backend: 'mac-seatbelt',
|
|
241
|
+
processTree: 'killable',
|
|
242
|
+
filesystem: 'write-jailed',
|
|
243
|
+
resources: 'best-effort',
|
|
244
|
+
network: 'deny',
|
|
245
|
+
privilege: 'dropped',
|
|
246
|
+
envHygiene: 'scrubbed',
|
|
247
|
+
notes: [
|
|
248
|
+
`sandbox-exec=${sandboxExec}`,
|
|
249
|
+
'privilege=dropped (ops-denied; uid unchanged)',
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
return cachedProbe;
|
|
253
|
+
}
|
|
254
|
+
if (sandboxExec) {
|
|
255
|
+
notes.push(`sandbox-exec=${sandboxExec} present but sandbox_apply denied (nested sandbox?); no write jail`);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
notes.push('darwin: sandbox-exec not found; no write jail');
|
|
259
|
+
}
|
|
260
|
+
cachedProbe = {
|
|
261
|
+
backend: 'supervised-spawn',
|
|
262
|
+
processTree: 'killable',
|
|
263
|
+
filesystem: 'cwd-pin',
|
|
264
|
+
resources: 'best-effort',
|
|
265
|
+
network: 'open',
|
|
266
|
+
privilege: 'same',
|
|
267
|
+
envHygiene: 'scrubbed',
|
|
268
|
+
notes,
|
|
269
|
+
};
|
|
270
|
+
return cachedProbe;
|
|
271
|
+
}
|
|
272
|
+
if (process.platform === 'win32') {
|
|
273
|
+
// Job Object / restricted token need a native helper (future). Pure Node = supervised.
|
|
274
|
+
notes.push('win32: Job Object + restricted token not bundled; processTree via taskkill /T only');
|
|
275
|
+
cachedProbe = {
|
|
276
|
+
backend: 'supervised-spawn',
|
|
277
|
+
processTree: 'killable',
|
|
278
|
+
filesystem: 'cwd-pin',
|
|
279
|
+
resources: 'best-effort',
|
|
280
|
+
network: 'open',
|
|
281
|
+
privilege: 'same',
|
|
282
|
+
envHygiene: 'scrubbed',
|
|
283
|
+
notes,
|
|
284
|
+
};
|
|
285
|
+
return cachedProbe;
|
|
286
|
+
}
|
|
287
|
+
notes.push(`${process.platform}: generic supervised spawn only`);
|
|
288
|
+
cachedProbe = {
|
|
289
|
+
backend: 'supervised-spawn',
|
|
290
|
+
processTree: 'killable',
|
|
291
|
+
filesystem: 'cwd-pin',
|
|
292
|
+
resources: 'best-effort',
|
|
293
|
+
network: 'open',
|
|
294
|
+
privilege: 'same',
|
|
295
|
+
envHygiene: 'scrubbed',
|
|
296
|
+
notes,
|
|
297
|
+
};
|
|
298
|
+
return cachedProbe;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Synthetic supervised profile (L1 only). Used when no probe has run yet.
|
|
302
|
+
*
|
|
303
|
+
* @returns baseline profile for supervised spawn
|
|
304
|
+
*/
|
|
305
|
+
export function supervisedSpawnProfile() {
|
|
306
|
+
return {
|
|
307
|
+
backend: 'supervised-spawn',
|
|
308
|
+
processTree: 'killable',
|
|
309
|
+
filesystem: 'cwd-pin',
|
|
310
|
+
resources: 'best-effort',
|
|
311
|
+
network: 'open',
|
|
312
|
+
privilege: 'same',
|
|
313
|
+
envHygiene: 'scrubbed',
|
|
314
|
+
};
|
|
315
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1 资源限制 — 工具执行看门狗(ToolEffectPolicy / OP-17)
|
|
3
|
+
*
|
|
4
|
+
* 统一强制 `definition.timeoutMs`;与 abortSignal 联动。
|
|
5
|
+
* run 级硬停(token/iteration)仍归 Budget/Run,不在此域。
|
|
6
|
+
*/
|
|
7
|
+
export declare class ToolTimeoutError extends Error {
|
|
8
|
+
readonly timedOut = true;
|
|
9
|
+
readonly toolName: string;
|
|
10
|
+
readonly timeoutMs: number;
|
|
11
|
+
constructor(toolName: string, timeoutMs: number);
|
|
12
|
+
}
|
|
13
|
+
export interface ToolRunLimits {
|
|
14
|
+
/** 硬顶;省略则不限时(仅受 abortSignal) */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
/** 外部中止 */
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
toolName?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 在资源限制下执行工具体
|
|
22
|
+
*
|
|
23
|
+
* @param fn - 工具逻辑;接收内部 AbortSignal(超时/外部中止时触发)
|
|
24
|
+
* @param limits - L1 限制
|
|
25
|
+
* @returns 工具结果
|
|
26
|
+
*/
|
|
27
|
+
export declare function runWithToolLimits<T>(fn: (signal: AbortSignal) => Promise<T>, limits: ToolRunLimits): Promise<T>;
|
|
28
|
+
/**
|
|
29
|
+
* 从工具定义解析 timeoutMs
|
|
30
|
+
*
|
|
31
|
+
* @param definition - 工具定义
|
|
32
|
+
* @returns 硬顶毫秒;未声明则 undefined
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveToolTimeoutMs(definition?: {
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
}): number | undefined;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1 资源限制 — 工具执行看门狗(ToolEffectPolicy / OP-17)
|
|
3
|
+
*
|
|
4
|
+
* 统一强制 `definition.timeoutMs`;与 abortSignal 联动。
|
|
5
|
+
* run 级硬停(token/iteration)仍归 Budget/Run,不在此域。
|
|
6
|
+
*/
|
|
7
|
+
export class ToolTimeoutError extends Error {
|
|
8
|
+
timedOut = true;
|
|
9
|
+
toolName;
|
|
10
|
+
timeoutMs;
|
|
11
|
+
constructor(toolName, timeoutMs) {
|
|
12
|
+
super(`tool_timeout: "${toolName}" timed out after ${timeoutMs}ms`);
|
|
13
|
+
this.name = 'ToolTimeoutError';
|
|
14
|
+
this.toolName = toolName;
|
|
15
|
+
this.timeoutMs = timeoutMs;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 在资源限制下执行工具体
|
|
20
|
+
*
|
|
21
|
+
* @param fn - 工具逻辑;接收内部 AbortSignal(超时/外部中止时触发)
|
|
22
|
+
* @param limits - L1 限制
|
|
23
|
+
* @returns 工具结果
|
|
24
|
+
*/
|
|
25
|
+
export async function runWithToolLimits(fn, limits) {
|
|
26
|
+
const toolName = limits.toolName ?? 'tool';
|
|
27
|
+
const timeoutMs = limits.timeoutMs;
|
|
28
|
+
const outer = limits.abortSignal;
|
|
29
|
+
if (outer?.aborted) {
|
|
30
|
+
throw new Error(`tool_aborted: "${toolName}"`);
|
|
31
|
+
}
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const onOuterAbort = () => controller.abort();
|
|
34
|
+
outer?.addEventListener('abort', onOuterAbort, { once: true });
|
|
35
|
+
let timer;
|
|
36
|
+
let timedOut = false;
|
|
37
|
+
let timeoutReject;
|
|
38
|
+
let timeoutPromise;
|
|
39
|
+
if (typeof timeoutMs === 'number' && timeoutMs > 0) {
|
|
40
|
+
timeoutPromise = new Promise((_, reject) => {
|
|
41
|
+
timeoutReject = reject;
|
|
42
|
+
timer = setTimeout(() => {
|
|
43
|
+
timedOut = true;
|
|
44
|
+
controller.abort();
|
|
45
|
+
reject(new ToolTimeoutError(toolName, timeoutMs));
|
|
46
|
+
}, timeoutMs);
|
|
47
|
+
timer.unref?.();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const running = fn(controller.signal);
|
|
52
|
+
// 防 timeout 胜出后 running 的 reject 变成 unhandled
|
|
53
|
+
running.catch(() => undefined);
|
|
54
|
+
// race:handler 可能不尊重 abort,仍须在 timeoutMs 拒绝
|
|
55
|
+
return timeoutPromise
|
|
56
|
+
? await Promise.race([running, timeoutPromise])
|
|
57
|
+
: await running;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (timedOut) {
|
|
61
|
+
throw new ToolTimeoutError(toolName, timeoutMs);
|
|
62
|
+
}
|
|
63
|
+
if (outer?.aborted) {
|
|
64
|
+
throw new Error(`tool_aborted: "${toolName}"`);
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
if (timer)
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
timeoutReject = undefined;
|
|
72
|
+
outer?.removeEventListener('abort', onOuterAbort);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 从工具定义解析 timeoutMs
|
|
77
|
+
*
|
|
78
|
+
* @param definition - 工具定义
|
|
79
|
+
* @returns 硬顶毫秒;未声明则 undefined
|
|
80
|
+
*/
|
|
81
|
+
export function resolveToolTimeoutMs(definition) {
|
|
82
|
+
const t = definition?.timeoutMs;
|
|
83
|
+
return typeof t === 'number' && t > 0 ? t : undefined;
|
|
84
|
+
}
|
|
@@ -1,12 +1,133 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Process sandbox — supervised spawn (L1) + optional OS jails (L4 process).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Never claims isolation it does not enforce. `SupervisedSpawn` is process-tree
|
|
5
|
+
* kill + env scrub + limits only; real jails are `linux-bwrap` / `mac-seatbelt`.
|
|
6
|
+
* Public contract: `docs/process-isolation.md`.
|
|
6
7
|
*/
|
|
7
8
|
import type { SandboxProvider, SandboxConfig, SandboxResult, IsolationLevel } from './types.js';
|
|
9
|
+
import { assessL4ProcessMinimum, supervisedSpawnProfile, type ProcessIsolationProfile } from './process-isolation.js';
|
|
10
|
+
export interface ProcessSandboxOptions {
|
|
11
|
+
/** Force a profile (tests). Otherwise probes on construct. */
|
|
12
|
+
profile?: ProcessIsolationProfile;
|
|
13
|
+
/** Allow listing PATH etc. Force-injected env keys beyond allowlist */
|
|
14
|
+
forceEnvKeys?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Supervised process runner: tree-killable spawn with scrubbed env.
|
|
18
|
+
* This is NOT a filesystem jail — `isolation.filesystem` stays `cwd-pin`.
|
|
19
|
+
*/
|
|
8
20
|
export declare class ProcessSandbox implements SandboxProvider {
|
|
9
21
|
readonly level: IsolationLevel;
|
|
10
|
-
|
|
22
|
+
private cachedProfile;
|
|
23
|
+
private readonly forceEnvKeys;
|
|
24
|
+
constructor(options?: ProcessSandboxOptions);
|
|
25
|
+
probe(): Promise<ProcessIsolationProfile>;
|
|
11
26
|
isAvailable(): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Execute a shell command line via the platform shell.
|
|
29
|
+
*
|
|
30
|
+
* @param command - shell command line
|
|
31
|
+
* @param config - cwd / env / limits
|
|
32
|
+
* @returns result with honest isolation profile
|
|
33
|
+
*/
|
|
34
|
+
execute(command: string, config?: SandboxConfig): Promise<SandboxResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Execute an argv vector (preferred).
|
|
37
|
+
*
|
|
38
|
+
* @param argv - executable + args
|
|
39
|
+
* @param config - cwd / env / limits
|
|
40
|
+
* @returns result with honest isolation profile
|
|
41
|
+
*/
|
|
42
|
+
executeArgv(argv: string[], config?: SandboxConfig): Promise<SandboxResult>;
|
|
43
|
+
private run;
|
|
44
|
+
private runSupervised;
|
|
45
|
+
private runBwrap;
|
|
46
|
+
private runSeatbelt;
|
|
47
|
+
/**
|
|
48
|
+
* D7: jail was selected but cannot be applied.
|
|
49
|
+
* requireJail (untrusted) throws; otherwise supervised fallback of the real command + run-level note.
|
|
50
|
+
*/
|
|
51
|
+
private jailSetupFailed;
|
|
52
|
+
/**
|
|
53
|
+
* D7 runtime case (after the wrapper has run): a jail setup failure is
|
|
54
|
+
* suspected. The user command is **never re-executed** — a forged wrapper
|
|
55
|
+
* error must not buy a second, unsandboxed run. `requireJail` refuses;
|
|
56
|
+
* other modes report the wrapper outcome with downgraded isolation and the
|
|
57
|
+
* run-level `securityDegraded` note (under-claiming is the safe direction).
|
|
58
|
+
*
|
|
59
|
+
* @param result - the wrapper's own outcome (command not re-run)
|
|
60
|
+
* @param config - execute config (requireJail / degradation hook)
|
|
61
|
+
* @param profile - probed isolation profile
|
|
62
|
+
* @param reason - wrapper failure summary for notes
|
|
63
|
+
* @returns the wrapper outcome with honestly downgraded isolation
|
|
64
|
+
*/
|
|
65
|
+
private jailWrapperRuntimeFailure;
|
|
66
|
+
private usage;
|
|
12
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Heuristic: the jail wrapper failed to establish the jail — the user command
|
|
70
|
+
* never ran. Detection only feeds refusal (`requireJail`) or an honest
|
|
71
|
+
* isolation downgrade; the user command is **never re-executed** on it, so a
|
|
72
|
+
* forged stderr cannot buy an unsandboxed run. Wrapper diagnostics carry the
|
|
73
|
+
* argv0 prefix at **line start** (bwrap's uid-map helpers report as
|
|
74
|
+
* `newuidmap:` / `newgidmap:`); bare substrings are not matched, and neither
|
|
75
|
+
* is "operation not permitted": a sandbox write denial of a real user command
|
|
76
|
+
* emits exactly that wording. A terminated run (timeout/abort) is never a
|
|
77
|
+
* setup failure.
|
|
78
|
+
*
|
|
79
|
+
* @param result - wrapper run result
|
|
80
|
+
* @param wrapper - which jail wrapper produced the result
|
|
81
|
+
* @returns true when the jail itself failed to apply
|
|
82
|
+
*/
|
|
83
|
+
export declare function isJailWrapperSetupFailure(result: {
|
|
84
|
+
exitCode: number;
|
|
85
|
+
stdout: string;
|
|
86
|
+
stderr: string;
|
|
87
|
+
terminated?: boolean;
|
|
88
|
+
}, wrapper: 'bwrap' | 'sandbox-exec'): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Jail write mounts (2a/2b): allowRoots ∪ cwd ∪ tmpdir ∪ shared tmp on POSIX
|
|
91
|
+
* (`/tmp`, `/var/tmp` — always) ∪ home when `config.homeWrite` (project/host).
|
|
92
|
+
* tmp is not journaled (2c).
|
|
93
|
+
*
|
|
94
|
+
* Each root is emitted in its lexical form **and**, when resolvable, its
|
|
95
|
+
* canonical (`realpath`) form: jail backends match canonical paths, so a root
|
|
96
|
+
* given through a symlink alias (macOS `/var` → `/private/var`, `/tmp` →
|
|
97
|
+
* `/private/tmp`) must appear canonicalized or its subpath rule never matches.
|
|
98
|
+
* Roots that fail to resolve keep the lexical form only (stale allowRoots must
|
|
99
|
+
* not abort the command; bwrap uses `--bind-try`).
|
|
100
|
+
*
|
|
101
|
+
* @param cwd - working directory (always a root; also the relative base for root paths)
|
|
102
|
+
* @param config - sandbox config (allowRoots / homeWrite)
|
|
103
|
+
* @returns absolute, deduped root paths (lexical + canonical variants)
|
|
104
|
+
*/
|
|
105
|
+
export declare function resolveJailRoots(cwd: string, config: SandboxConfig | undefined): Promise<string[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Seatbelt profile: default allow, deny writes outside roots (stdio devices
|
|
108
|
+
* excepted), deny network unless open, and deny common privilege-gaining
|
|
109
|
+
* execs (1-B: privilege=dropped means ops-denied, uid unchanged).
|
|
110
|
+
* Paths are quote-escaped for the sb DSL.
|
|
111
|
+
*/
|
|
112
|
+
export declare function buildSeatbeltProfile(roots: string[], network: 'open' | 'deny', extra?: {
|
|
113
|
+
privilegeDenyExec?: string[];
|
|
114
|
+
}): string;
|
|
115
|
+
/**
|
|
116
|
+
* POSIX stdio devices the jail must keep writable (macOS Seatbelt only;
|
|
117
|
+
* bwrap supplies its own /dev). Character sinks cannot escape the jail.
|
|
118
|
+
*/
|
|
119
|
+
export declare const SEATBELT_DEVICE_WRITE_ALLOW: readonly ["/dev/null", "/dev/zero", "/dev/tty", "/dev/stdin", "/dev/stdout", "/dev/stderr"];
|
|
120
|
+
/**
|
|
121
|
+
* Create the best process sandbox this host can offer.
|
|
122
|
+
*
|
|
123
|
+
* @param options - profile override / force env keys
|
|
124
|
+
* @returns sandbox provider with probed isolation
|
|
125
|
+
*/
|
|
126
|
+
export declare function createProcessSandbox(options?: ProcessSandboxOptions): Promise<ProcessSandbox>;
|
|
127
|
+
/**
|
|
128
|
+
* Does this profile meet the L4 process floor?
|
|
129
|
+
*
|
|
130
|
+
* @param profile - isolation profile
|
|
131
|
+
* @returns assessment
|
|
132
|
+
*/
|
|
133
|
+
export { assessL4ProcessMinimum, supervisedSpawnProfile };
|