@octopi-agent/engine 0.65.0 → 0.86.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +69 -0
- package/dist/config-schema/context.d.ts +23 -4
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +285 -9
- package/dist/config-schema/engine.js +35 -3
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +91 -0
- package/dist/config-schema/models.d.ts +1 -1
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +10 -0
- package/dist/config-schema/shared.js +10 -0
- package/dist/config-schema/substrate.d.ts +87 -1
- package/dist/config-schema/substrate.js +114 -0
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +249 -7
- package/dist/config.js +113 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +48 -4
- package/dist/harness/agent/builder.js +206 -55
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +83 -280
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +38 -0
- package/dist/harness/agent/tool-purpose.js +118 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +363 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/gate.js +2 -2
- package/dist/harness/context/capabilities/summary/policies.js +5 -5
- package/dist/harness/context/capabilities/summary/registry.js +39 -24
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-health.js +3 -2
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +49 -1
- package/dist/harness/context/layer-types.js +72 -4
- package/dist/harness/context/layers.d.ts +32 -15
- package/dist/harness/context/layers.js +87 -71
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +33 -0
- package/dist/harness/context/system-prompt-assembler.js +78 -7
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +248 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +334 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +493 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +118 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +45 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +278 -82
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +239 -61
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +39 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +18 -15
- package/dist/harness/index.js +11 -7
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +6 -3
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.js +4 -1
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/query-service.js +8 -8
- package/dist/harness/knowledge/retriever.js +1 -1
- package/dist/harness/knowledge/source-store.d.ts +17 -2
- package/dist/harness/knowledge/source-store.js +6 -5
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/cognition-decay.d.ts +36 -0
- package/dist/harness/memory/cognition-decay.js +55 -0
- package/dist/harness/memory/cognition-gates.d.ts +60 -0
- package/dist/harness/memory/cognition-gates.js +191 -0
- package/dist/harness/memory/cognition-trigger.d.ts +30 -0
- package/dist/harness/memory/cognition-trigger.js +41 -0
- package/dist/harness/memory/cognition-types.d.ts +1 -1
- package/dist/harness/memory/cognition.d.ts +40 -8
- package/dist/harness/memory/cognition.js +432 -79
- package/dist/harness/memory/conceptualizer.d.ts +66 -0
- package/dist/harness/memory/conceptualizer.js +246 -0
- package/dist/harness/memory/index.d.ts +17 -2
- package/dist/harness/memory/index.js +12 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
- package/dist/harness/memory/sqlite/agent-db.js +120 -15
- package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
- package/dist/harness/memory/sqlite/cognition-store.js +591 -144
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
- package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +343 -16
- package/dist/harness/memory/types.js +49 -0
- package/dist/harness/memory/wisdom-formation.d.ts +101 -0
- package/dist/harness/memory/wisdom-formation.js +304 -0
- package/dist/harness/memory/wisdom-gates.d.ts +50 -0
- package/dist/harness/memory/wisdom-gates.js +204 -0
- package/dist/harness/memory/wisdom-policy.d.ts +107 -0
- package/dist/harness/memory/wisdom-policy.js +220 -0
- package/dist/harness/memory/wisdom-types.d.ts +3 -2
- package/dist/harness/memory/wisdom-types.js +2 -2
- package/dist/harness/memory/wisdom.d.ts +27 -0
- package/dist/harness/memory/wisdom.js +181 -0
- package/dist/harness/observability/observer/hub.js +23 -1
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +57 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +27 -0
- package/dist/harness/run/agent/agent.js +45 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +116 -20
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +101 -16
- package/dist/harness/run/runner.js +557 -158
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +1 -0
- package/dist/harness/session/in-memory-store.d.ts +1 -0
- package/dist/harness/session/in-memory-store.js +22 -1
- package/dist/harness/session/index.d.ts +1 -0
- package/dist/harness/session/index.js +1 -0
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.d.ts +86 -0
- package/dist/harness/session/title.js +268 -0
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +21 -0
- package/dist/harness/shared/events/agent-event-map.js +1 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +11 -0
- package/dist/integration/storage/jsonl.js +148 -39
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
- package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
- package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
- package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -1,87 +1,529 @@
|
|
|
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 { spawn } from 'node:child_process';
|
|
9
|
+
import { realpath, unlink, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { homedir, tmpdir } from 'node:os';
|
|
11
|
+
import { join, resolve } from 'node:path';
|
|
12
|
+
import { assessL4ProcessMinimum, killProcessTree, probeProcessIsolation, scrubEnv, supervisedSpawnProfile, } from './process-isolation.js';
|
|
13
|
+
/**
|
|
14
|
+
* Supervised process runner: tree-killable spawn with scrubbed env.
|
|
15
|
+
* This is NOT a filesystem jail — `isolation.filesystem` stays `cwd-pin`.
|
|
16
|
+
*/
|
|
8
17
|
export class ProcessSandbox {
|
|
9
18
|
level = 'process';
|
|
19
|
+
cachedProfile;
|
|
20
|
+
forceEnvKeys;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.cachedProfile = options?.profile ?? null;
|
|
23
|
+
this.forceEnvKeys = options?.forceEnvKeys;
|
|
24
|
+
}
|
|
25
|
+
async probe() {
|
|
26
|
+
if (this.cachedProfile)
|
|
27
|
+
return this.cachedProfile;
|
|
28
|
+
this.cachedProfile = await probeProcessIsolation();
|
|
29
|
+
return this.cachedProfile;
|
|
30
|
+
}
|
|
31
|
+
async isAvailable() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Execute a shell command line via the platform shell.
|
|
36
|
+
*
|
|
37
|
+
* @param command - shell command line
|
|
38
|
+
* @param config - cwd / env / limits
|
|
39
|
+
* @returns result with honest isolation profile
|
|
40
|
+
*/
|
|
10
41
|
async execute(command, config) {
|
|
42
|
+
const profile = await this.probe();
|
|
43
|
+
const shell = resolveShell();
|
|
44
|
+
return this.run(shell.executable, [...shell.args, command], config, profile);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Execute an argv vector (preferred).
|
|
48
|
+
*
|
|
49
|
+
* @param argv - executable + args
|
|
50
|
+
* @param config - cwd / env / limits
|
|
51
|
+
* @returns result with honest isolation profile
|
|
52
|
+
*/
|
|
53
|
+
async executeArgv(argv, config) {
|
|
54
|
+
const profile = await this.probe();
|
|
55
|
+
if (argv.length === 0) {
|
|
56
|
+
throw new Error('sandbox_argv_empty: executeArgv requires at least one token');
|
|
57
|
+
}
|
|
58
|
+
return this.run(argv[0], argv.slice(1), config, profile);
|
|
59
|
+
}
|
|
60
|
+
run(file, args, config, profile) {
|
|
11
61
|
const cwd = config?.cwd ?? process.cwd();
|
|
12
|
-
const env = {
|
|
13
|
-
const timeoutMs = config?.limits?.timeoutMs ??
|
|
14
|
-
const maxOutputBytes = config?.limits?.maxOutputBytes ?? 10 * 1024 * 1024;
|
|
15
|
-
|
|
62
|
+
const env = scrubEnv(config?.env, { forceKeys: this.forceEnvKeys });
|
|
63
|
+
const timeoutMs = config?.limits?.timeoutMs ?? 60_000;
|
|
64
|
+
const maxOutputBytes = config?.limits?.maxOutputBytes ?? 10 * 1024 * 1024;
|
|
65
|
+
// Jail backends wrap the spawn; fall back to supervised spawn.
|
|
66
|
+
if (profile.backend === 'linux-bwrap' && process.platform === 'linux') {
|
|
67
|
+
return this.runBwrap(file, args, config, profile, { cwd, env, timeoutMs, maxOutputBytes });
|
|
68
|
+
}
|
|
69
|
+
if (profile.backend === 'mac-seatbelt' && process.platform === 'darwin') {
|
|
70
|
+
return this.runSeatbelt(file, args, config, profile, { cwd, env, timeoutMs, maxOutputBytes });
|
|
71
|
+
}
|
|
72
|
+
if (config?.requireJail) {
|
|
73
|
+
return Promise.reject(new Error(`untrusted_jail_failed: no process jail backend (probe=${profile.backend}); refuse unsandboxed execute`));
|
|
74
|
+
}
|
|
75
|
+
return this.runSupervised(file, args, config, profile, { cwd, env, timeoutMs, maxOutputBytes });
|
|
76
|
+
}
|
|
77
|
+
runSupervised(file, args, config, profile, opts) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
16
79
|
const start = Date.now();
|
|
17
80
|
let stdout = '';
|
|
18
81
|
let stderr = '';
|
|
19
82
|
let terminated = false;
|
|
20
83
|
let terminateReason = '';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
84
|
+
let settled = false;
|
|
85
|
+
const spawnOpts = {
|
|
86
|
+
cwd: opts.cwd,
|
|
87
|
+
env: opts.env,
|
|
24
88
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
89
|
+
windowsHide: true,
|
|
90
|
+
// POSIX: own process group so we can kill the tree
|
|
91
|
+
...(process.platform === 'win32' ? {} : { detached: true }),
|
|
92
|
+
};
|
|
93
|
+
const proc = spawn(file, args, spawnOpts);
|
|
94
|
+
const finish = (result) => {
|
|
95
|
+
if (settled)
|
|
96
|
+
return;
|
|
97
|
+
settled = true;
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
config?.signal?.removeEventListener('abort', onAbort);
|
|
100
|
+
resolve(result);
|
|
101
|
+
};
|
|
102
|
+
/** Refusal path (requireJail contract: throw, never resolve-as-success). */
|
|
103
|
+
const fail = (err) => {
|
|
104
|
+
if (settled)
|
|
105
|
+
return;
|
|
106
|
+
settled = true;
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
config?.signal?.removeEventListener('abort', onAbort);
|
|
109
|
+
reject(err);
|
|
110
|
+
};
|
|
111
|
+
const kill = (reason) => {
|
|
112
|
+
terminated = true;
|
|
113
|
+
terminateReason = reason;
|
|
114
|
+
killProcessTree(proc);
|
|
115
|
+
};
|
|
116
|
+
const onAbort = () => kill('Aborted');
|
|
117
|
+
config?.signal?.addEventListener('abort', onAbort, { once: true });
|
|
118
|
+
proc.stdout?.on('data', (data) => {
|
|
119
|
+
if (stdout.length + data.length > opts.maxOutputBytes) {
|
|
120
|
+
kill('Output size limit exceeded');
|
|
32
121
|
return;
|
|
33
122
|
}
|
|
34
|
-
stdout += data.toString();
|
|
123
|
+
stdout += data.toString('utf8');
|
|
35
124
|
});
|
|
36
|
-
proc.stderr
|
|
37
|
-
if (stderr.length + data.length > maxOutputBytes) {
|
|
125
|
+
proc.stderr?.on('data', (data) => {
|
|
126
|
+
if (stderr.length + data.length > opts.maxOutputBytes) {
|
|
127
|
+
kill('Output size limit exceeded');
|
|
38
128
|
return;
|
|
39
129
|
}
|
|
40
|
-
stderr += data.toString();
|
|
130
|
+
stderr += data.toString('utf8');
|
|
41
131
|
});
|
|
42
|
-
// 超时保护
|
|
43
132
|
const timer = setTimeout(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
elapsedMs,
|
|
53
|
-
peakMemoryBytes: -1, // 需要平台特定实现
|
|
54
|
-
cpuTimeMs: -1,
|
|
55
|
-
outputBytes: stdout.length + stderr.length,
|
|
56
|
-
};
|
|
57
|
-
resolve({
|
|
58
|
-
exitCode: exitCode ?? -1,
|
|
133
|
+
kill(`Execution timeout (${opts.timeoutMs}ms)`);
|
|
134
|
+
}, opts.timeoutMs);
|
|
135
|
+
proc.on('close', (exitCode, signal) => {
|
|
136
|
+
const usage = this.usage(start, stdout, stderr);
|
|
137
|
+
// null exitCode = signal death; never report that as success (exit 0)
|
|
138
|
+
const code = typeof exitCode === 'number' ? exitCode : -1;
|
|
139
|
+
finish({
|
|
140
|
+
exitCode: code,
|
|
59
141
|
stdout,
|
|
60
|
-
stderr,
|
|
61
|
-
terminated,
|
|
62
|
-
terminateReason: terminated
|
|
142
|
+
stderr: signal && !terminated ? `${stderr}\n[signal ${signal}]`.trim() : stderr,
|
|
143
|
+
terminated: terminated || signal != null,
|
|
144
|
+
terminateReason: terminated
|
|
145
|
+
? terminateReason
|
|
146
|
+
: signal
|
|
147
|
+
? `signal ${signal}`
|
|
148
|
+
: undefined,
|
|
63
149
|
usage,
|
|
150
|
+
isolation: profile,
|
|
64
151
|
});
|
|
65
152
|
});
|
|
66
153
|
proc.on('error', (err) => {
|
|
67
|
-
|
|
68
|
-
|
|
154
|
+
const usage = this.usage(start, stdout, stderr);
|
|
155
|
+
const isJailWrapper = profile.backend === 'linux-bwrap' || profile.backend === 'mac-seatbelt';
|
|
156
|
+
if (config?.requireJail && isJailWrapper) {
|
|
157
|
+
fail(new Error(`untrusted_jail_failed: jail spawn failed: ${err.message} (requireJail=true; refuse unsandboxed execute)`));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const honest = isJailWrapper
|
|
161
|
+
? {
|
|
162
|
+
...profile,
|
|
163
|
+
filesystem: 'cwd-pin',
|
|
164
|
+
privilege: 'same',
|
|
165
|
+
notes: [...(profile.notes ?? []), `jail spawn failed: ${err.message}`],
|
|
166
|
+
}
|
|
167
|
+
: profile;
|
|
168
|
+
if (isJailWrapper)
|
|
169
|
+
config?.noteSecurityDegraded?.(`jail_spawn_failed: ${err.message}`);
|
|
170
|
+
finish({
|
|
69
171
|
exitCode: -1,
|
|
70
|
-
stdout
|
|
172
|
+
stdout,
|
|
71
173
|
stderr: err.message,
|
|
72
174
|
terminated: true,
|
|
73
175
|
terminateReason: `Process error: ${err.message}`,
|
|
74
|
-
usage
|
|
75
|
-
|
|
76
|
-
peakMemoryBytes: -1,
|
|
77
|
-
cpuTimeMs: -1,
|
|
78
|
-
outputBytes: 0,
|
|
79
|
-
},
|
|
176
|
+
usage,
|
|
177
|
+
isolation: honest,
|
|
80
178
|
});
|
|
81
179
|
});
|
|
82
180
|
});
|
|
83
181
|
}
|
|
84
|
-
async
|
|
85
|
-
|
|
182
|
+
async runBwrap(file, args, config, profile, opts) {
|
|
183
|
+
// D4-c: bind every allowRoot; default network deny (--unshare-all).
|
|
184
|
+
const roots = await resolveJailRoots(opts.cwd, config);
|
|
185
|
+
const network = resolveNetworkPolicy(config);
|
|
186
|
+
const bwrapArgs = [
|
|
187
|
+
'--die-with-parent',
|
|
188
|
+
'--unshare-all',
|
|
189
|
+
'--ro-bind',
|
|
190
|
+
'/usr',
|
|
191
|
+
'/usr',
|
|
192
|
+
'--ro-bind',
|
|
193
|
+
'/bin',
|
|
194
|
+
'/bin',
|
|
195
|
+
'--ro-bind',
|
|
196
|
+
'/lib',
|
|
197
|
+
'/lib',
|
|
198
|
+
'--ro-bind-try',
|
|
199
|
+
'/lib64',
|
|
200
|
+
'/lib64',
|
|
201
|
+
'--ro-bind-try',
|
|
202
|
+
'/etc',
|
|
203
|
+
'/etc',
|
|
204
|
+
];
|
|
205
|
+
if (network === 'open') {
|
|
206
|
+
bwrapArgs.push('--share-net');
|
|
207
|
+
}
|
|
208
|
+
for (const root of roots) {
|
|
209
|
+
// --bind-try: stale pathRoots must not abort the whole command
|
|
210
|
+
bwrapArgs.push('--bind-try', root, root);
|
|
211
|
+
}
|
|
212
|
+
bwrapArgs.push('--chdir', opts.cwd, '--', file, ...args);
|
|
213
|
+
const applied = {
|
|
214
|
+
...profile,
|
|
215
|
+
network,
|
|
216
|
+
privilege: 'dropped',
|
|
217
|
+
notes: [
|
|
218
|
+
...(profile.notes ?? []),
|
|
219
|
+
`bwrap roots=${roots.join(',')}`,
|
|
220
|
+
networkPolicyNote(config, network),
|
|
221
|
+
'privilege=dropped (userns)',
|
|
222
|
+
],
|
|
223
|
+
};
|
|
224
|
+
const result = await this.runSupervised('bwrap', bwrapArgs, config, applied, opts);
|
|
225
|
+
// D7 runtime case (post-execution): the wrapper failed to establish the
|
|
226
|
+
// jail even though the probe passed. Never re-execute the user command.
|
|
227
|
+
if (isJailWrapperSetupFailure(result, 'bwrap')) {
|
|
228
|
+
return this.jailWrapperRuntimeFailure(result, config, profile, `bwrap setup failed (exit=${result.exitCode}): ${result.stderr.slice(0, 200)}`);
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
async runSeatbelt(file, args, config, profile, opts) {
|
|
233
|
+
const roots = await resolveJailRoots(opts.cwd, config);
|
|
234
|
+
const network = resolveNetworkPolicy(config);
|
|
235
|
+
// Host override wins; otherwise generate a profile covering allowRoots (D3-b+).
|
|
236
|
+
let profilePath = process.env.OCTOPI_SB_PROFILE;
|
|
237
|
+
let generatedPath;
|
|
238
|
+
if (!profilePath) {
|
|
239
|
+
generatedPath = join(tmpdir(), `octopi-sb-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.sb`);
|
|
240
|
+
try {
|
|
241
|
+
await writeFile(generatedPath, buildSeatbeltProfile(roots, network), { encoding: 'utf8', mode: 0o600 });
|
|
242
|
+
profilePath = generatedPath;
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
return this.jailSetupFailed(file, args, config, profile, opts, `seatbelt profile generation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const applied = {
|
|
249
|
+
...profile,
|
|
250
|
+
filesystem: 'write-jailed',
|
|
251
|
+
privilege: 'dropped',
|
|
252
|
+
network,
|
|
253
|
+
notes: [
|
|
254
|
+
...(profile.notes ?? []),
|
|
255
|
+
`seatbelt profile=${profilePath}`,
|
|
256
|
+
`roots=${roots.join(',')}`,
|
|
257
|
+
networkPolicyNote(config, network),
|
|
258
|
+
'privilege=dropped (ops-denied; uid unchanged)',
|
|
259
|
+
'tmp writes not journaled (notReversed)',
|
|
260
|
+
],
|
|
261
|
+
};
|
|
262
|
+
try {
|
|
263
|
+
const result = await this.runSupervised('sandbox-exec', ['-f', profilePath, '--', file, ...args], config, applied, opts);
|
|
264
|
+
// D7 runtime case (post-execution): the wrapper failed to apply the
|
|
265
|
+
// jail even though the probe passed. Never re-execute the user command.
|
|
266
|
+
if (isJailWrapperSetupFailure(result, 'sandbox-exec')) {
|
|
267
|
+
return await this.jailWrapperRuntimeFailure(result, config, profile, `seatbelt apply failed (exit=${result.exitCode}): ${result.stderr.slice(0, 200)}`);
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
if (generatedPath) {
|
|
273
|
+
await unlink(generatedPath).catch(() => undefined);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
86
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* D7: jail was selected but cannot be applied.
|
|
279
|
+
* requireJail (untrusted) throws; otherwise supervised fallback of the real command + run-level note.
|
|
280
|
+
*/
|
|
281
|
+
jailSetupFailed(file, args, config, profile, opts, reason) {
|
|
282
|
+
if (config?.requireJail) {
|
|
283
|
+
return Promise.reject(new Error(`untrusted_jail_failed: ${reason} (requireJail=true; refuse unsandboxed execute)`));
|
|
284
|
+
}
|
|
285
|
+
const degraded = {
|
|
286
|
+
...profile,
|
|
287
|
+
backend: 'supervised-spawn',
|
|
288
|
+
processTree: 'killable',
|
|
289
|
+
filesystem: 'cwd-pin',
|
|
290
|
+
privilege: 'same',
|
|
291
|
+
network: 'open',
|
|
292
|
+
notes: [...(profile.notes ?? []), `jail_setup_failed: ${reason}; supervised fallback`],
|
|
293
|
+
};
|
|
294
|
+
config?.noteSecurityDegraded?.(`jail_setup_failed: ${reason}`);
|
|
295
|
+
return this.runSupervised(file, args, config, degraded, opts);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* D7 runtime case (after the wrapper has run): a jail setup failure is
|
|
299
|
+
* suspected. The user command is **never re-executed** — a forged wrapper
|
|
300
|
+
* error must not buy a second, unsandboxed run. `requireJail` refuses;
|
|
301
|
+
* other modes report the wrapper outcome with downgraded isolation and the
|
|
302
|
+
* run-level `securityDegraded` note (under-claiming is the safe direction).
|
|
303
|
+
*
|
|
304
|
+
* @param result - the wrapper's own outcome (command not re-run)
|
|
305
|
+
* @param config - execute config (requireJail / degradation hook)
|
|
306
|
+
* @param profile - probed isolation profile
|
|
307
|
+
* @param reason - wrapper failure summary for notes
|
|
308
|
+
* @returns the wrapper outcome with honestly downgraded isolation
|
|
309
|
+
*/
|
|
310
|
+
jailWrapperRuntimeFailure(result, config, profile, reason) {
|
|
311
|
+
if (config?.requireJail) {
|
|
312
|
+
return Promise.reject(new Error(`untrusted_jail_failed: ${reason} (requireJail=true; refuse unsandboxed execute)`));
|
|
313
|
+
}
|
|
314
|
+
config?.noteSecurityDegraded?.(`jail_setup_failed: ${reason}`);
|
|
315
|
+
return Promise.resolve({
|
|
316
|
+
...result,
|
|
317
|
+
isolation: {
|
|
318
|
+
...profile,
|
|
319
|
+
backend: 'supervised-spawn',
|
|
320
|
+
processTree: 'killable',
|
|
321
|
+
filesystem: 'cwd-pin',
|
|
322
|
+
privilege: 'same',
|
|
323
|
+
network: 'open',
|
|
324
|
+
notes: [
|
|
325
|
+
...(profile.notes ?? []),
|
|
326
|
+
`jail_setup_failed: ${reason}; command not re-executed`,
|
|
327
|
+
],
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
usage(start, stdout, stderr) {
|
|
332
|
+
return {
|
|
333
|
+
elapsedMs: Date.now() - start,
|
|
334
|
+
peakMemoryBytes: -1,
|
|
335
|
+
cpuTimeMs: -1,
|
|
336
|
+
outputBytes: Buffer.byteLength(stdout, 'utf8') + Buffer.byteLength(stderr, 'utf8'),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/** Network posture for this run (D4-c: default deny; allowlist enforced as deny). */
|
|
341
|
+
function resolveNetworkPolicy(config) {
|
|
342
|
+
const policy = config?.networkPolicy ?? 'deny';
|
|
343
|
+
return policy === 'open' ? 'open' : 'deny';
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Heuristic: the jail wrapper failed to establish the jail — the user command
|
|
347
|
+
* never ran. Detection only feeds refusal (`requireJail`) or an honest
|
|
348
|
+
* isolation downgrade; the user command is **never re-executed** on it, so a
|
|
349
|
+
* forged stderr cannot buy an unsandboxed run. Wrapper diagnostics carry the
|
|
350
|
+
* argv0 prefix at **line start** (bwrap's uid-map helpers report as
|
|
351
|
+
* `newuidmap:` / `newgidmap:`); bare substrings are not matched, and neither
|
|
352
|
+
* is "operation not permitted": a sandbox write denial of a real user command
|
|
353
|
+
* emits exactly that wording. A terminated run (timeout/abort) is never a
|
|
354
|
+
* setup failure.
|
|
355
|
+
*
|
|
356
|
+
* @param result - wrapper run result
|
|
357
|
+
* @param wrapper - which jail wrapper produced the result
|
|
358
|
+
* @returns true when the jail itself failed to apply
|
|
359
|
+
*/
|
|
360
|
+
export function isJailWrapperSetupFailure(result, wrapper) {
|
|
361
|
+
if (result.terminated)
|
|
362
|
+
return false;
|
|
363
|
+
if (result.exitCode === 0)
|
|
364
|
+
return false;
|
|
365
|
+
if (result.stdout.length > 0)
|
|
366
|
+
return false;
|
|
367
|
+
const prefixes = wrapper === 'bwrap' ? ['bwrap:', 'newuidmap:', 'newgidmap:'] : ['sandbox-exec:'];
|
|
368
|
+
return result.stderr.split('\n').some((line) => prefixes.some((p) => line.startsWith(p)));
|
|
87
369
|
}
|
|
370
|
+
/** Extra note when caller asked for allowlist (interface-only). */
|
|
371
|
+
function networkPolicyNote(config, applied) {
|
|
372
|
+
const requested = config?.networkPolicy;
|
|
373
|
+
if (requested === 'allowlist') {
|
|
374
|
+
return `network=${applied} (allowlist requested; interface-only, enforced as deny)`;
|
|
375
|
+
}
|
|
376
|
+
return `network=${applied}`;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Jail write mounts (2a/2b): allowRoots ∪ cwd ∪ tmpdir ∪ shared tmp on POSIX
|
|
380
|
+
* (`/tmp`, `/var/tmp` — always) ∪ home when `config.homeWrite` (project/host).
|
|
381
|
+
* tmp is not journaled (2c).
|
|
382
|
+
*
|
|
383
|
+
* Each root is emitted in its lexical form **and**, when resolvable, its
|
|
384
|
+
* canonical (`realpath`) form: jail backends match canonical paths, so a root
|
|
385
|
+
* given through a symlink alias (macOS `/var` → `/private/var`, `/tmp` →
|
|
386
|
+
* `/private/tmp`) must appear canonicalized or its subpath rule never matches.
|
|
387
|
+
* Roots that fail to resolve keep the lexical form only (stale allowRoots must
|
|
388
|
+
* not abort the command; bwrap uses `--bind-try`).
|
|
389
|
+
*
|
|
390
|
+
* @param cwd - working directory (always a root; also the relative base for root paths)
|
|
391
|
+
* @param config - sandbox config (allowRoots / homeWrite)
|
|
392
|
+
* @returns absolute, deduped root paths (lexical + canonical variants)
|
|
393
|
+
*/
|
|
394
|
+
export async function resolveJailRoots(cwd, config) {
|
|
395
|
+
const raw = [cwd, ...(config?.allowRoots ?? []), tmpdir()];
|
|
396
|
+
if (process.platform !== 'win32') {
|
|
397
|
+
// Tools that hardcode /tmp or /var/tmp (ignoring TMPDIR) must keep working
|
|
398
|
+
// inside the jail; the canonical twins (/private/tmp, /private/var/tmp) are
|
|
399
|
+
// emitted by the lexical+realpath loop below. Shared tmp writes stay
|
|
400
|
+
// notReversed (2c) like tmpdir().
|
|
401
|
+
raw.push('/tmp', '/var/tmp');
|
|
402
|
+
}
|
|
403
|
+
if (config?.homeWrite) {
|
|
404
|
+
raw.push(homedir());
|
|
405
|
+
}
|
|
406
|
+
const out = [];
|
|
407
|
+
const seen = new Set();
|
|
408
|
+
const push = (candidate) => {
|
|
409
|
+
// Relative roots resolve against the run cwd, not the host process cwd.
|
|
410
|
+
const s = resolve(cwd, candidate);
|
|
411
|
+
if (!s || s === '.')
|
|
412
|
+
return;
|
|
413
|
+
const key = process.platform === 'win32' ? s.toLowerCase() : s;
|
|
414
|
+
if (seen.has(key))
|
|
415
|
+
return;
|
|
416
|
+
seen.add(key);
|
|
417
|
+
out.push(s);
|
|
418
|
+
};
|
|
419
|
+
for (const p of raw) {
|
|
420
|
+
if (!p || p.trim() === '')
|
|
421
|
+
continue;
|
|
422
|
+
push(p);
|
|
423
|
+
const canonical = await realpathSafe(resolve(cwd, p));
|
|
424
|
+
if (canonical)
|
|
425
|
+
push(canonical);
|
|
426
|
+
}
|
|
427
|
+
return out.length > 0 ? out : [resolve(cwd), resolve(tmpdir())];
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Canonicalize a path; null when it cannot be resolved (e.g. stale root).
|
|
431
|
+
*
|
|
432
|
+
* @param p - path to canonicalize
|
|
433
|
+
* @returns realpath or null
|
|
434
|
+
*/
|
|
435
|
+
async function realpathSafe(p) {
|
|
436
|
+
try {
|
|
437
|
+
return await realpath(resolve(p));
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
// Missing/unreadable root: keep the lexical form (bind-try tolerates).
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Seatbelt profile: default allow, deny writes outside roots (stdio devices
|
|
446
|
+
* excepted), deny network unless open, and deny common privilege-gaining
|
|
447
|
+
* execs (1-B: privilege=dropped means ops-denied, uid unchanged).
|
|
448
|
+
* Paths are quote-escaped for the sb DSL.
|
|
449
|
+
*/
|
|
450
|
+
export function buildSeatbeltProfile(roots, network, extra) {
|
|
451
|
+
const esc = (p) => {
|
|
452
|
+
// A newline would break out of the profile's string literal; refuse loudly
|
|
453
|
+
// instead of silently deleting characters from a real path.
|
|
454
|
+
if (p.includes('\n') || p.includes('\r')) {
|
|
455
|
+
throw new Error(`seatbelt_path_invalid: path contains newline: ${JSON.stringify(p)}`);
|
|
456
|
+
}
|
|
457
|
+
// Quote-escape only. () and spaces are inert inside SBPL strings; stripping
|
|
458
|
+
// them would point subpath rules at a different directory.
|
|
459
|
+
return p.split('\\').join('\\\\').split('"').join('\\"');
|
|
460
|
+
};
|
|
461
|
+
const lines = ['(version 1)', '(allow default)'];
|
|
462
|
+
if (network === 'deny') {
|
|
463
|
+
lines.push('(deny network*)');
|
|
464
|
+
}
|
|
465
|
+
// 1-B: deny privilege-gaining helpers (path list is a best-effort allow-deny)
|
|
466
|
+
for (const bin of extra?.privilegeDenyExec ?? DEFAULT_PRIVILEGE_DENY_EXEC) {
|
|
467
|
+
lines.push(`(deny process-exec (literal "${esc(bin)}"))`);
|
|
468
|
+
}
|
|
469
|
+
lines.push('(deny file-write*)');
|
|
470
|
+
for (const root of roots) {
|
|
471
|
+
lines.push(`(allow file-write* (subpath "${esc(root)}"))`);
|
|
472
|
+
}
|
|
473
|
+
// stdio sinks must stay writable or basic tooling dies (git opens
|
|
474
|
+
// /dev/null O_RDWR; shells redirect > /dev/null). /dev/fd covers dup'd
|
|
475
|
+
// stdio paths (/dev/std{in,out,err} resolve there). Deliberately excludes
|
|
476
|
+
// /dev/ptmx — no TTY allocation inside the jail.
|
|
477
|
+
for (const dev of SEATBELT_DEVICE_WRITE_ALLOW) {
|
|
478
|
+
lines.push(`(allow file-write* (literal "${esc(dev)}"))`);
|
|
479
|
+
}
|
|
480
|
+
lines.push('(allow file-write* (subpath "/dev/fd"))');
|
|
481
|
+
return lines.join('\n') + '\n';
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* POSIX stdio devices the jail must keep writable (macOS Seatbelt only;
|
|
485
|
+
* bwrap supplies its own /dev). Character sinks cannot escape the jail.
|
|
486
|
+
*/
|
|
487
|
+
export const SEATBELT_DEVICE_WRITE_ALLOW = [
|
|
488
|
+
'/dev/null',
|
|
489
|
+
'/dev/zero',
|
|
490
|
+
'/dev/tty',
|
|
491
|
+
'/dev/stdin',
|
|
492
|
+
'/dev/stdout',
|
|
493
|
+
'/dev/stderr',
|
|
494
|
+
];
|
|
495
|
+
/** Common privilege-gaining binaries denied inside Seatbelt (1-B). */
|
|
496
|
+
const DEFAULT_PRIVILEGE_DENY_EXEC = [
|
|
497
|
+
'/usr/bin/sudo',
|
|
498
|
+
'/bin/su',
|
|
499
|
+
'/usr/bin/su',
|
|
500
|
+
'/usr/sbin/chroot',
|
|
501
|
+
'/usr/bin/login',
|
|
502
|
+
'/usr/bin/newgrp',
|
|
503
|
+
'/usr/bin/dscl',
|
|
504
|
+
];
|
|
505
|
+
function resolveShell() {
|
|
506
|
+
if (process.platform === 'win32') {
|
|
507
|
+
const comspec = process.env.COMSPEC || 'cmd.exe';
|
|
508
|
+
return { executable: comspec, args: ['/d', '/s', '/c'], kind: 'cmd' };
|
|
509
|
+
}
|
|
510
|
+
return { executable: '/bin/sh', args: ['-c'], kind: 'bash' };
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Create the best process sandbox this host can offer.
|
|
514
|
+
*
|
|
515
|
+
* @param options - profile override / force env keys
|
|
516
|
+
* @returns sandbox provider with probed isolation
|
|
517
|
+
*/
|
|
518
|
+
export async function createProcessSandbox(options) {
|
|
519
|
+
const sandbox = new ProcessSandbox(options);
|
|
520
|
+
await sandbox.probe();
|
|
521
|
+
return sandbox;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Does this profile meet the L4 process floor?
|
|
525
|
+
*
|
|
526
|
+
* @param profile - isolation profile
|
|
527
|
+
* @returns assessment
|
|
528
|
+
*/
|
|
529
|
+
export { assessL4ProcessMinimum, supervisedSpawnProfile };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell 账本(ToolEffectPolicy §5.6)
|
|
3
|
+
*
|
|
4
|
+
* 无 L4 时由 shell 工具在 spawn 前后制造记账边界:
|
|
5
|
+
* before 快照(内容寻址)→ 执行 → after diff → 注入 TurnFileUndoLog。
|
|
6
|
+
* 清点范围外不装懂;预算撞顶停采 before、业务跑完,标 truncated。
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolFileEffects } from '@octopi-agent/core/types/tools.js';
|
|
9
|
+
export interface ShellJournalLimit {
|
|
10
|
+
maxFiles?: number;
|
|
11
|
+
maxBytes?: number;
|
|
12
|
+
maxFileSize?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ShellJournalOptions {
|
|
15
|
+
/** 清点根(allowRoots);空 = 无法盘点 */
|
|
16
|
+
roots: string[];
|
|
17
|
+
limit?: ShellJournalLimit;
|
|
18
|
+
/** 排除目录名 */
|
|
19
|
+
excludeDirs?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface ShellInventoryEntry {
|
|
22
|
+
path: string;
|
|
23
|
+
hash: string;
|
|
24
|
+
size: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ShellJournalCapture {
|
|
27
|
+
/** 路径 → hash */
|
|
28
|
+
map: Map<string, ShellInventoryEntry>;
|
|
29
|
+
truncated: boolean;
|
|
30
|
+
scannedFiles: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 遍历 roots,收集文件内容哈希(供 before/after 对比)。
|
|
34
|
+
*
|
|
35
|
+
* @param options - 根与预算
|
|
36
|
+
* @returns 采集结果;truncated=true 表示撞顶未扫全
|
|
37
|
+
*/
|
|
38
|
+
export declare function captureShellInventory(options: ShellJournalOptions): Promise<ShellJournalCapture>;
|
|
39
|
+
export interface ShellDiff {
|
|
40
|
+
created: string[];
|
|
41
|
+
modified: string[];
|
|
42
|
+
deleted: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 对比 before/after 清单。
|
|
46
|
+
*
|
|
47
|
+
* @param before - shell 前
|
|
48
|
+
* @param after - shell 后
|
|
49
|
+
* @returns 变更集
|
|
50
|
+
*/
|
|
51
|
+
export declare function diffShellInventory(before: ShellJournalCapture, after: ShellJournalCapture): ShellDiff;
|
|
52
|
+
/**
|
|
53
|
+
* 采 before 时同时保留可恢复字节(内容寻址,去重)。
|
|
54
|
+
* 删除/修改的 before 从这里取,再交给 ToolFileEffects。
|
|
55
|
+
*/
|
|
56
|
+
export interface ShellSnapshotStore {
|
|
57
|
+
get(path: string): Promise<Buffer | undefined>;
|
|
58
|
+
put(path: string, data: Buffer): Promise<void>;
|
|
59
|
+
hashOf(path: string): string | undefined;
|
|
60
|
+
}
|
|
61
|
+
export declare function createShellSnapshotStore(): ShellSnapshotStore;
|
|
62
|
+
/**
|
|
63
|
+
* shell 前:快照 roots 内文件字节(供 undo)。
|
|
64
|
+
*
|
|
65
|
+
* @param options - roots + 预算
|
|
66
|
+
* @returns 采集 + 字节库
|
|
67
|
+
*/
|
|
68
|
+
export declare function snapshotShellRoots(options: ShellJournalOptions): Promise<{
|
|
69
|
+
capture: ShellJournalCapture;
|
|
70
|
+
store: ShellSnapshotStore;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* shell 后:diff 并写入效应账本。
|
|
74
|
+
*
|
|
75
|
+
* @param effects - undo log
|
|
76
|
+
* @param before - 前清单
|
|
77
|
+
* @param after - 后清单
|
|
78
|
+
* @param store - before 字节
|
|
79
|
+
* @returns 变更与是否已入账
|
|
80
|
+
*/
|
|
81
|
+
export declare function journalShellDiff(effects: ToolFileEffects, before: ShellJournalCapture, after: ShellJournalCapture, store: ShellSnapshotStore): Promise<ShellDiff & {
|
|
82
|
+
journaled: boolean;
|
|
83
|
+
notInventable: string[];
|
|
84
|
+
}>;
|
|
85
|
+
/** 相对路径辅助(诊断用) */
|
|
86
|
+
export declare function relToRoot(root: string, path: string): string;
|
|
87
|
+
/** 供 discard 读取的不可逆清单文件名 */
|
|
88
|
+
export declare const NOT_REVERSED_FILE = "not-reversed.json";
|
|
89
|
+
/**
|
|
90
|
+
* 落盘不可逆效应清单(不进 log.jsonl)。
|
|
91
|
+
*
|
|
92
|
+
* @param undoRoot - sessions/<sid>/undo
|
|
93
|
+
* @param payload - 原因 + 路径清单
|
|
94
|
+
*/
|
|
95
|
+
export declare function writeNotReversed(undoRoot: string, payload: {
|
|
96
|
+
reason: 'inventory_only' | 'budget_truncated' | 'no_roots' | 'shell_journal_off';
|
|
97
|
+
created?: string[];
|
|
98
|
+
modified?: string[];
|
|
99
|
+
deleted?: string[];
|
|
100
|
+
}): Promise<void>;
|