@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
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* package_edit / project_run / package_install — package-manager surface
|
|
3
|
+
* without a shell.
|
|
4
|
+
*
|
|
5
|
+
* - package_edit: structured package.json mutation via ToolFileEffects (undo).
|
|
6
|
+
* - project_run: run a named script from package.json#scripts (runner capability;
|
|
7
|
+
* stripped on reduced surface — it executes workspace code).
|
|
8
|
+
* - package_install: npm/pnpm/yarn install|add|remove. Tagged `egress`; refused
|
|
9
|
+
* when networkPolicy is not open (prompt the user to install manually).
|
|
10
|
+
*/
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { gateEffect } from '../../execution-environment/effect-policy.js';
|
|
14
|
+
import { isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, findExecutable, } from './platform.js';
|
|
15
|
+
import { runAllowlistedArgv } from './allowlisted-run.js';
|
|
16
|
+
import { resolveNodeToolCommand } from './platform.js';
|
|
17
|
+
function resolveCwd(context, raw) {
|
|
18
|
+
const cwd = raw ?? context?.cwd ?? process.cwd();
|
|
19
|
+
const abs = resolveToolPath(cwd, context?.cwd, {
|
|
20
|
+
allowRoots: context?.pathRoots,
|
|
21
|
+
containment: context?.pathContainment,
|
|
22
|
+
});
|
|
23
|
+
if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
|
|
24
|
+
throw new Error('session attachments are read-only; cannot run package tools under attachments root');
|
|
25
|
+
}
|
|
26
|
+
if (isUnderSessionUndoRoot(abs, context?.undoRoots)) {
|
|
27
|
+
throw new Error('session undo ledger is protected; cannot run package tools under sessions undo dir');
|
|
28
|
+
}
|
|
29
|
+
return abs;
|
|
30
|
+
}
|
|
31
|
+
function assertPathSafe(raw, context, label) {
|
|
32
|
+
const abs = resolveToolPath(raw, context?.cwd, {
|
|
33
|
+
allowRoots: context?.pathRoots,
|
|
34
|
+
containment: context?.pathContainment,
|
|
35
|
+
});
|
|
36
|
+
if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
|
|
37
|
+
throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
|
|
38
|
+
}
|
|
39
|
+
if (isUnderSessionUndoRoot(abs, context?.undoRoots)) {
|
|
40
|
+
throw new Error(`session undo ledger is protected; cannot ${label} under sessions undo dir`);
|
|
41
|
+
}
|
|
42
|
+
return abs;
|
|
43
|
+
}
|
|
44
|
+
async function readPackageJson(pkgPath) {
|
|
45
|
+
const { readFile } = await import('node:fs/promises');
|
|
46
|
+
const raw = await readFile(pkgPath, 'utf8');
|
|
47
|
+
const parsed = JSON.parse(raw);
|
|
48
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
49
|
+
throw new Error(`package_json_invalid: ${pkgPath} is not a JSON object`);
|
|
50
|
+
}
|
|
51
|
+
return { pkg: parsed, raw };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Preserve the file's existing EOL and trailing-newline so package.json does
|
|
55
|
+
* not flip CRLF↔LF when the agent edits it on any OS (git / editors care).
|
|
56
|
+
*/
|
|
57
|
+
function stringifyPreservingEol(value, original) {
|
|
58
|
+
const eol = original.includes('\r\n') ? '\r\n' : '\n';
|
|
59
|
+
const trailingEol = /\r?\n$/.test(original);
|
|
60
|
+
const indentMatch = /\n([\t ]+)"/.exec(original);
|
|
61
|
+
const indent = indentMatch ? indentMatch[1] : ' ';
|
|
62
|
+
const body = JSON.stringify(value, null, indent);
|
|
63
|
+
const normalized = body.split('\n').join(eol);
|
|
64
|
+
return trailingEol ? normalized + eol : normalized;
|
|
65
|
+
}
|
|
66
|
+
function getDotted(obj, path) {
|
|
67
|
+
const parts = path.split('.').filter(Boolean);
|
|
68
|
+
let cur = obj;
|
|
69
|
+
for (const p of parts) {
|
|
70
|
+
if (!cur || typeof cur !== 'object' || Array.isArray(cur))
|
|
71
|
+
return undefined;
|
|
72
|
+
cur = cur[p];
|
|
73
|
+
}
|
|
74
|
+
return cur;
|
|
75
|
+
}
|
|
76
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
77
|
+
function assertSafeDotted(path) {
|
|
78
|
+
const parts = path.split('.').filter(Boolean);
|
|
79
|
+
if (parts.length === 0)
|
|
80
|
+
throw new Error('package_edit: empty path');
|
|
81
|
+
for (const p of parts) {
|
|
82
|
+
if (FORBIDDEN_KEYS.has(p)) {
|
|
83
|
+
throw new Error(`package_edit_forbidden_key: "${path}" contains a prototype-polluting key`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return parts;
|
|
87
|
+
}
|
|
88
|
+
function setDotted(obj, path, value) {
|
|
89
|
+
const parts = assertSafeDotted(path);
|
|
90
|
+
let cur = obj;
|
|
91
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
92
|
+
const key = parts[i];
|
|
93
|
+
const next = cur[key];
|
|
94
|
+
if (!next || typeof next !== 'object' || Array.isArray(next)) {
|
|
95
|
+
cur[key] = {};
|
|
96
|
+
}
|
|
97
|
+
cur = cur[key];
|
|
98
|
+
}
|
|
99
|
+
cur[parts[parts.length - 1]] = value;
|
|
100
|
+
}
|
|
101
|
+
function deleteDotted(obj, path) {
|
|
102
|
+
const parts = assertSafeDotted(path);
|
|
103
|
+
let cur = obj;
|
|
104
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
105
|
+
const next = cur[parts[i]];
|
|
106
|
+
if (!next || typeof next !== 'object' || Array.isArray(next))
|
|
107
|
+
return false;
|
|
108
|
+
cur = next;
|
|
109
|
+
}
|
|
110
|
+
return delete cur[parts[parts.length - 1]];
|
|
111
|
+
}
|
|
112
|
+
/** Detect package manager from lockfile; fall back to npm. */
|
|
113
|
+
async function detectPm(cwd, explicit) {
|
|
114
|
+
if (explicit === 'npm' || explicit === 'pnpm' || explicit === 'yarn')
|
|
115
|
+
return explicit;
|
|
116
|
+
const { access } = await import('node:fs/promises');
|
|
117
|
+
const { join } = await import('node:path');
|
|
118
|
+
const has = async (f) => access(join(cwd, f)).then(() => true, () => false);
|
|
119
|
+
if (await has('pnpm-lock.yaml'))
|
|
120
|
+
return 'pnpm';
|
|
121
|
+
if (await has('yarn.lock'))
|
|
122
|
+
return 'yarn';
|
|
123
|
+
return 'npm';
|
|
124
|
+
}
|
|
125
|
+
function pmCommand(pm) {
|
|
126
|
+
return resolveNodeToolCommand(pm);
|
|
127
|
+
}
|
|
128
|
+
function toText(result) {
|
|
129
|
+
return {
|
|
130
|
+
stdout: result.stdout,
|
|
131
|
+
stderr: result.stderr,
|
|
132
|
+
exitCode: result.exitCode,
|
|
133
|
+
durationMs: result.durationMs,
|
|
134
|
+
truncated: result.truncated,
|
|
135
|
+
terminated: result.terminated,
|
|
136
|
+
terminateReason: result.terminateReason,
|
|
137
|
+
isolation: result.isolation,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** package_edit — structured package.json edit (undoable) */
|
|
141
|
+
export function createPackageEditTool() {
|
|
142
|
+
return {
|
|
143
|
+
definition: {
|
|
144
|
+
name: 'package_edit',
|
|
145
|
+
capabilities: ['fs-write', 'fs-read'],
|
|
146
|
+
description: 'Structurally edit package.json (scripts, dependencies, metadata) via dotted paths. Undoable. Prefer this over rewriting the whole file.',
|
|
147
|
+
parameters: {
|
|
148
|
+
path: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: 'Path to package.json (default: <cwd>/package.json)',
|
|
151
|
+
},
|
|
152
|
+
set: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
description: 'Map of dotted path → value, e.g. {"scripts.test":"vitest run","dependencies.lodash":"^4.0.0"}',
|
|
155
|
+
},
|
|
156
|
+
remove: {
|
|
157
|
+
type: 'array',
|
|
158
|
+
description: 'Dotted paths to delete, e.g. ["devDependencies.old"]',
|
|
159
|
+
items: { type: 'string', description: 'Dotted path' },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
// 整文件读改写无合并语义:所在 tool_call 批次整体串行,防同路径并发读改写互相覆盖
|
|
164
|
+
executionMode: 'sequential',
|
|
165
|
+
handler: async (args, context) => {
|
|
166
|
+
const cwd = resolveCwd(context);
|
|
167
|
+
const rawPath = args.path ?? 'package.json';
|
|
168
|
+
const pkgPath = assertPathSafe(rawPath, context, 'edit');
|
|
169
|
+
const { pkg, raw: originalText } = await readPackageJson(pkgPath);
|
|
170
|
+
const set = args.set ?? {};
|
|
171
|
+
const remove = Array.isArray(args.remove) ? args.remove : [];
|
|
172
|
+
const changed = [];
|
|
173
|
+
for (const [key, value] of Object.entries(set)) {
|
|
174
|
+
setDotted(pkg, key, value);
|
|
175
|
+
changed.push(`set:${key}`);
|
|
176
|
+
}
|
|
177
|
+
for (const key of remove) {
|
|
178
|
+
if (deleteDotted(pkg, key))
|
|
179
|
+
changed.push(`remove:${key}`);
|
|
180
|
+
}
|
|
181
|
+
if (changed.length === 0) {
|
|
182
|
+
return { path: pkgPath, changed: [], skipped: 'no set/remove provided' };
|
|
183
|
+
}
|
|
184
|
+
await gateEffect({ kind: 'file.write', path: pkgPath, mode: 'edit', transactional: true }, {
|
|
185
|
+
effects: context?.effectChannel ?? 'engine',
|
|
186
|
+
confirmEffect: context?.confirmEffect,
|
|
187
|
+
sessionId: context?.sessionId,
|
|
188
|
+
agentId: context?.agentId,
|
|
189
|
+
});
|
|
190
|
+
const effects = context?.fileEffects;
|
|
191
|
+
if (!effects) {
|
|
192
|
+
throw new Error('file_effects_not_configured: package_edit requires ToolExecutionContext.fileEffects');
|
|
193
|
+
}
|
|
194
|
+
const after = stringifyPreservingEol(pkg, originalText);
|
|
195
|
+
await effects.writeFile(pkgPath, after);
|
|
196
|
+
return { path: pkgPath, changed, packageManager: await detectPm(cwd) };
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** project_run — run a named package.json script (runner; stripped on reduced) */
|
|
201
|
+
export function createProjectRunTool() {
|
|
202
|
+
return {
|
|
203
|
+
definition: {
|
|
204
|
+
name: 'project_run',
|
|
205
|
+
capabilities: ['runner'],
|
|
206
|
+
description: 'Run a named script from package.json#scripts (e.g. test, lint, build). Pass the script name only — never an arbitrary command string. Executes workspace code; blocked when the tool surface is reduced.',
|
|
207
|
+
parameters: {
|
|
208
|
+
script: {
|
|
209
|
+
type: 'string',
|
|
210
|
+
description: 'Script name defined in package.json#scripts',
|
|
211
|
+
required: true,
|
|
212
|
+
},
|
|
213
|
+
cwd: { type: 'string', description: 'Project directory (default: workspace cwd)' },
|
|
214
|
+
args: {
|
|
215
|
+
type: 'array',
|
|
216
|
+
description: 'Extra args passed after the script (npm run <script> -- <args>)',
|
|
217
|
+
items: { type: 'string', description: 'Argument' },
|
|
218
|
+
},
|
|
219
|
+
packageManager: {
|
|
220
|
+
type: 'string',
|
|
221
|
+
description: 'Force package manager (default: detect from lockfile)',
|
|
222
|
+
enum: ['npm', 'pnpm', 'yarn'],
|
|
223
|
+
},
|
|
224
|
+
timeout: {
|
|
225
|
+
type: 'number',
|
|
226
|
+
description: 'Timeout in milliseconds (default 300000)',
|
|
227
|
+
minimum: 1000,
|
|
228
|
+
maximum: 1_800_000,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
handler: async (args, context) => {
|
|
233
|
+
const cwd = resolveCwd(context, args.cwd);
|
|
234
|
+
const script = String(args.script ?? '').trim();
|
|
235
|
+
if (!script || !/^[A-Za-z0-9][A-Za-z0-9:._-]*$/.test(script)) {
|
|
236
|
+
throw new Error(`project_run: invalid script name "${script}"`);
|
|
237
|
+
}
|
|
238
|
+
const pkgPath = resolveToolPath('package.json', cwd, {
|
|
239
|
+
allowRoots: context?.pathRoots,
|
|
240
|
+
containment: context?.pathContainment,
|
|
241
|
+
});
|
|
242
|
+
const { pkg } = await readPackageJson(pkgPath);
|
|
243
|
+
const scripts = (pkg.scripts ?? {});
|
|
244
|
+
if (typeof scripts[script] !== 'string') {
|
|
245
|
+
throw new Error(`project_run_unknown_script: "${script}" is not defined in package.json#scripts. Available: ${Object.keys(scripts).join(', ') || '(none)'}`);
|
|
246
|
+
}
|
|
247
|
+
await gateEffect({
|
|
248
|
+
kind: 'runner',
|
|
249
|
+
command: `run ${script}`,
|
|
250
|
+
cwd,
|
|
251
|
+
description: `project script "${script}"`,
|
|
252
|
+
}, {
|
|
253
|
+
effects: context?.effectChannel ?? 'engine',
|
|
254
|
+
confirmEffect: context?.confirmEffect,
|
|
255
|
+
sessionId: context?.sessionId,
|
|
256
|
+
agentId: context?.agentId,
|
|
257
|
+
});
|
|
258
|
+
const pm = await detectPm(cwd, args.packageManager);
|
|
259
|
+
const extra = Array.isArray(args.args) ? args.args.map(String) : [];
|
|
260
|
+
// Script body is defined by the project; we only pass its name as argv.
|
|
261
|
+
const pmArgs = pm === 'yarn' ? ['run', script, ...(extra.length ? ['--', ...extra] : [])] : ['run', script, ...(extra.length ? ['--', ...extra] : [])];
|
|
262
|
+
const { tmpdir } = await import('node:os');
|
|
263
|
+
const result = await runAllowlistedArgv({
|
|
264
|
+
executable: pmCommand(pm).executable,
|
|
265
|
+
args: [...pmCommand(pm).prefixArgs, ...pmArgs],
|
|
266
|
+
cwd,
|
|
267
|
+
context,
|
|
268
|
+
env: {
|
|
269
|
+
npm_config_cache: join(tmpdir(), 'octopi-npm-cache'),
|
|
270
|
+
npm_config_update_notifier: 'false',
|
|
271
|
+
},
|
|
272
|
+
timeoutMs: Number(args.timeout) > 0 ? Math.min(Number(args.timeout), 1_800_000) : 300_000,
|
|
273
|
+
journal: true,
|
|
274
|
+
});
|
|
275
|
+
return { ...toText(result), cwd, script, packageManager: pm, scriptBody: scripts[script] };
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/** package_install — install/add/remove deps (egress; network-gated) */
|
|
280
|
+
export function createPackageInstallTool() {
|
|
281
|
+
return {
|
|
282
|
+
definition: {
|
|
283
|
+
name: 'package_install',
|
|
284
|
+
capabilities: ['egress', 'runner'],
|
|
285
|
+
description: 'Install, add, or remove npm/pnpm/yarn dependencies. Requires open network (egress). When the network is denied, install dependencies manually and re-run.',
|
|
286
|
+
parameters: {
|
|
287
|
+
action: {
|
|
288
|
+
type: 'string',
|
|
289
|
+
description: 'Install action',
|
|
290
|
+
enum: ['install', 'add', 'remove', 'ci'],
|
|
291
|
+
required: true,
|
|
292
|
+
},
|
|
293
|
+
packages: {
|
|
294
|
+
type: 'array',
|
|
295
|
+
description: 'Package names for add/remove (e.g. lodash, vitest@^4)',
|
|
296
|
+
items: { type: 'string', description: 'Package spec' },
|
|
297
|
+
},
|
|
298
|
+
dev: { type: 'boolean', description: 'add as devDependency' },
|
|
299
|
+
cwd: { type: 'string', description: 'Project directory' },
|
|
300
|
+
packageManager: {
|
|
301
|
+
type: 'string',
|
|
302
|
+
description: 'Force package manager (default: detect from lockfile)',
|
|
303
|
+
enum: ['npm', 'pnpm', 'yarn'],
|
|
304
|
+
},
|
|
305
|
+
timeout: {
|
|
306
|
+
type: 'number',
|
|
307
|
+
description: 'Timeout in milliseconds (default 600000)',
|
|
308
|
+
minimum: 1000,
|
|
309
|
+
maximum: 1_800_000,
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
handler: async (args, context) => {
|
|
314
|
+
const action = String(args.action ?? '');
|
|
315
|
+
if (!['install', 'add', 'remove', 'ci'].includes(action)) {
|
|
316
|
+
throw new Error(`package_install: unsupported action "${action}"`);
|
|
317
|
+
}
|
|
318
|
+
const cwd = resolveCwd(context, args.cwd);
|
|
319
|
+
const packages = Array.isArray(args.packages) ? args.packages.map(String) : [];
|
|
320
|
+
if ((action === 'add' || action === 'remove') && packages.length === 0) {
|
|
321
|
+
throw new Error(`package_install: action=${action} requires packages`);
|
|
322
|
+
}
|
|
323
|
+
for (const p of packages) {
|
|
324
|
+
if (!/^[A-Za-z0-9@][A-Za-z0-9@/._+^~<>=*-]*$/.test(p)) {
|
|
325
|
+
throw new Error(`package_install: invalid package spec "${p}"`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// Network gate (D4): workspace/untrusted default deny — refuse before spawn.
|
|
329
|
+
const net = context?.networkPolicy ?? 'deny';
|
|
330
|
+
if (net !== 'open') {
|
|
331
|
+
throw new Error(`package_install_network_denied: networkPolicy=${net}. Install dependencies manually (e.g. run npm install on the host), then re-run. package_install only works when networkPolicy=open.`);
|
|
332
|
+
}
|
|
333
|
+
await gateEffect({
|
|
334
|
+
kind: 'runner',
|
|
335
|
+
command: `${action} ${packages.join(' ')}`.trim(),
|
|
336
|
+
cwd,
|
|
337
|
+
description: `package ${action}`,
|
|
338
|
+
}, {
|
|
339
|
+
effects: context?.effectChannel ?? 'engine',
|
|
340
|
+
confirmEffect: context?.confirmEffect,
|
|
341
|
+
sessionId: context?.sessionId,
|
|
342
|
+
agentId: context?.agentId,
|
|
343
|
+
});
|
|
344
|
+
const pm = await detectPm(cwd, args.packageManager);
|
|
345
|
+
const pmArgs = [];
|
|
346
|
+
if (action === 'ci') {
|
|
347
|
+
if (pm === 'npm')
|
|
348
|
+
pmArgs.push('ci');
|
|
349
|
+
else if (pm === 'yarn')
|
|
350
|
+
pmArgs.push('install', '--frozen-lockfile');
|
|
351
|
+
else
|
|
352
|
+
pmArgs.push('install', '--frozen-lockfile');
|
|
353
|
+
}
|
|
354
|
+
else if (action === 'install') {
|
|
355
|
+
pmArgs.push('install');
|
|
356
|
+
}
|
|
357
|
+
else if (action === 'add') {
|
|
358
|
+
pmArgs.push(pm === 'yarn' ? 'add' : 'add');
|
|
359
|
+
if (args.dev === true)
|
|
360
|
+
pmArgs.push(pm === 'yarn' ? '--dev' : '--save-dev');
|
|
361
|
+
pmArgs.push(...packages);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
pmArgs.push(pm === 'yarn' ? 'remove' : 'uninstall', ...packages);
|
|
365
|
+
}
|
|
366
|
+
const result = await runAllowlistedArgv({
|
|
367
|
+
executable: pmCommand(pm).executable,
|
|
368
|
+
args: [...pmCommand(pm).prefixArgs, ...pmArgs],
|
|
369
|
+
cwd,
|
|
370
|
+
context,
|
|
371
|
+
env: {
|
|
372
|
+
npm_config_cache: join(tmpdir(), 'octopi-npm-cache'),
|
|
373
|
+
npm_config_update_notifier: 'false',
|
|
374
|
+
npm_config_audit: 'false',
|
|
375
|
+
npm_config_fund: 'false',
|
|
376
|
+
},
|
|
377
|
+
timeoutMs: Number(args.timeout) > 0 ? Math.min(Number(args.timeout), 1_800_000) : 600_000,
|
|
378
|
+
journal: true,
|
|
379
|
+
});
|
|
380
|
+
return { ...toText(result), cwd, action, packages, packageManager: pm };
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/** package_edit + project_run + package_install */
|
|
385
|
+
export function createPackageTools() {
|
|
386
|
+
return [createPackageEditTool(), createProjectRunTool(), createPackageInstallTool()];
|
|
387
|
+
}
|
|
388
|
+
/** Unused helper kept for future package_ls (P1). */
|
|
389
|
+
export function findPackageManagerExecutable(pm) {
|
|
390
|
+
return findExecutable(pm);
|
|
391
|
+
}
|
|
@@ -26,7 +26,25 @@ export interface PlatformShell {
|
|
|
26
26
|
* @param cwd - 工作目录;缺省为 `process.cwd()`
|
|
27
27
|
* @returns 规范化后的绝对路径
|
|
28
28
|
*/
|
|
29
|
-
export
|
|
29
|
+
export interface ResolveToolPathOptions {
|
|
30
|
+
/** L2 允许根;containment 非 none 时必须落在其下 */
|
|
31
|
+
allowRoots?: string[];
|
|
32
|
+
/** L2 级别;省略 = 不限制 */
|
|
33
|
+
containment?: 'strict' | 'soft' | 'none';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
|
|
37
|
+
*
|
|
38
|
+
* 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
|
|
39
|
+
*
|
|
40
|
+
* @param rawPath - 工具入参路径
|
|
41
|
+
* @param cwd - 工作目录;缺省为 process.cwd()
|
|
42
|
+
* @param options - L2 路径包含(ToolEffectPolicy)
|
|
43
|
+
* @returns 规范化后的绝对路径
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveToolPath(rawPath: string, cwd?: string, options?: ResolveToolPathOptions): string;
|
|
46
|
+
/** 路径是否落在任一 root 之下(含 root 本身) */
|
|
47
|
+
export declare function isPathUnderRoots(absPath: string, roots: string[]): boolean;
|
|
30
48
|
/**
|
|
31
49
|
* 只读附件根内解析(OP-15):相对名优先贴到 attachmentRoots
|
|
32
50
|
*
|
|
@@ -35,7 +53,7 @@ export declare function resolveToolPath(rawPath: string, cwd?: string): string;
|
|
|
35
53
|
* @param attachmentRoots - 只读会话附件根
|
|
36
54
|
* @returns 规范化后的绝对路径
|
|
37
55
|
*/
|
|
38
|
-
export declare function resolveReadableToolPath(rawPath: string, cwd?: string, attachmentRoots?: string[]): string;
|
|
56
|
+
export declare function resolveReadableToolPath(rawPath: string, cwd?: string, attachmentRoots?: string[], options?: ResolveToolPathOptions): string;
|
|
39
57
|
/**
|
|
40
58
|
* 是否为会话附件根下的路径(写保护)
|
|
41
59
|
*
|
|
@@ -59,6 +77,27 @@ export declare function findExecutable(name: string): string | null;
|
|
|
59
77
|
* @returns 是否存在可执行文件
|
|
60
78
|
*/
|
|
61
79
|
export declare function commandExists(name: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve a Node-based CLI (npm / pnpm / yarn) to a spawnable argv head.
|
|
82
|
+
*
|
|
83
|
+
* Windows never spawns `.cmd`/`.bat` directly (Node ≥18.20 throws EINVAL,
|
|
84
|
+
* CVE-2024-27980). Prefer `node <package-cli.js>` when the shim layout is
|
|
85
|
+
* known; otherwise fall back to the resolved path only when it is a real PE.
|
|
86
|
+
*
|
|
87
|
+
* @param name - tool name (`npm` | `pnpm` | `yarn`)
|
|
88
|
+
* @returns executable + prefix args inserted before user args
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveNodeToolCommand(name: string): {
|
|
91
|
+
executable: string;
|
|
92
|
+
prefixArgs: string[];
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Minimal platform env for child processes (allowlist-shaped; no secret inherit).
|
|
96
|
+
* Only keys already accepted by `scrubEnv` are included.
|
|
97
|
+
*
|
|
98
|
+
* @returns env map with PATH plus OS essentials when present
|
|
99
|
+
*/
|
|
100
|
+
export declare function defaultChildEnv(): Record<string, string>;
|
|
62
101
|
/**
|
|
63
102
|
* 解析当前平台应使用的 shell(结果缓存)
|
|
64
103
|
*
|
|
@@ -80,3 +119,13 @@ export declare function resetPlatformShellCache(): void;
|
|
|
80
119
|
* @returns PATH 字符串;缺失时给出平台相关的安全回退
|
|
81
120
|
*/
|
|
82
121
|
export declare function defaultPathEnv(): string;
|
|
122
|
+
/**
|
|
123
|
+
* True when `target` is the session undo ledger root or under it (D6-a).
|
|
124
|
+
* Prefers real root comparison against injected `undoRoots`; falls back to an
|
|
125
|
+
* exact `sessions/<id>/undo` path-shape match when the runner did not inject.
|
|
126
|
+
*
|
|
127
|
+
* @param target - absolute or relative path under consideration
|
|
128
|
+
* @param undoRoots - resolveSessionUndoPaths roots (optional)
|
|
129
|
+
* @returns whether the path is protected undo ledger
|
|
130
|
+
*/
|
|
131
|
+
export declare function isUnderSessionUndoRoot(target: string, undoRoots?: string[]): boolean;
|
|
@@ -5,21 +5,50 @@
|
|
|
5
5
|
* 或硬编码 `/bin/bash` 导致 Windows 行为分裂。
|
|
6
6
|
*/
|
|
7
7
|
import { accessSync, constants, existsSync, statSync } from 'node:fs';
|
|
8
|
-
import { delimiter, isAbsolute, join, resolve, sep } from 'node:path';
|
|
8
|
+
import { delimiter, dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
9
9
|
/**
|
|
10
10
|
* 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
|
|
11
11
|
*
|
|
12
|
-
* 使用
|
|
13
|
-
* `C:\` / `C:/` 与 UNC `\\server\share`。
|
|
12
|
+
* 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
|
|
14
13
|
*
|
|
15
14
|
* @param rawPath - 工具入参路径
|
|
16
|
-
* @param cwd - 工作目录;缺省为
|
|
15
|
+
* @param cwd - 工作目录;缺省为 process.cwd()
|
|
16
|
+
* @param options - L2 路径包含(ToolEffectPolicy)
|
|
17
17
|
* @returns 规范化后的绝对路径
|
|
18
18
|
*/
|
|
19
|
-
export function resolveToolPath(rawPath, cwd) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
export function resolveToolPath(rawPath, cwd, options) {
|
|
20
|
+
const abs = isAbsolute(rawPath) ? resolve(rawPath) : resolve(cwd ?? process.cwd(), rawPath);
|
|
21
|
+
const containment = options?.containment ?? 'none';
|
|
22
|
+
if (containment !== 'none') {
|
|
23
|
+
const roots = options?.allowRoots ?? [];
|
|
24
|
+
if (roots.length === 0) {
|
|
25
|
+
// strict 无 root = fail-closed(与 isPathAllowed 一致);soft 仅审计
|
|
26
|
+
if (containment === 'strict') {
|
|
27
|
+
throw new Error(`path_forbidden: "${rawPath}" effect roots not configured`);
|
|
28
|
+
}
|
|
29
|
+
return abs;
|
|
30
|
+
}
|
|
31
|
+
if (!isPathUnderRoots(abs, roots)) {
|
|
32
|
+
if (containment === 'strict') {
|
|
33
|
+
throw new Error(`path_forbidden: "${rawPath}" escapes effect roots`);
|
|
34
|
+
}
|
|
35
|
+
// soft:放行(审计由调用方/Observer 负责)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return abs;
|
|
39
|
+
}
|
|
40
|
+
/** 路径是否落在任一 root 之下(含 root 本身) */
|
|
41
|
+
export function isPathUnderRoots(absPath, roots) {
|
|
42
|
+
const win = process.platform === 'win32';
|
|
43
|
+
const norm = (s) => {
|
|
44
|
+
const r = resolve(s);
|
|
45
|
+
return win ? r.toLowerCase() : r;
|
|
46
|
+
};
|
|
47
|
+
const p = norm(absPath);
|
|
48
|
+
return roots.some((root) => {
|
|
49
|
+
const r = norm(root);
|
|
50
|
+
return p === r || p.startsWith(r.endsWith(sep) ? r : r + sep);
|
|
51
|
+
});
|
|
23
52
|
}
|
|
24
53
|
/**
|
|
25
54
|
* 只读附件根内解析(OP-15):相对名优先贴到 attachmentRoots
|
|
@@ -29,7 +58,7 @@ export function resolveToolPath(rawPath, cwd) {
|
|
|
29
58
|
* @param attachmentRoots - 只读会话附件根
|
|
30
59
|
* @returns 规范化后的绝对路径
|
|
31
60
|
*/
|
|
32
|
-
export function resolveReadableToolPath(rawPath, cwd, attachmentRoots) {
|
|
61
|
+
export function resolveReadableToolPath(rawPath, cwd, attachmentRoots, options) {
|
|
33
62
|
const roots = attachmentRoots ?? [];
|
|
34
63
|
// 绝对路径原样;相对路径先试 attachments 根(文件名直呼)
|
|
35
64
|
if (!isAbsolute(rawPath) && roots.length > 0) {
|
|
@@ -44,7 +73,8 @@ export function resolveReadableToolPath(rawPath, cwd, attachmentRoots) {
|
|
|
44
73
|
}
|
|
45
74
|
}
|
|
46
75
|
}
|
|
47
|
-
|
|
76
|
+
// attachments 命中后返回;其余走 L2
|
|
77
|
+
return resolveToolPath(rawPath, cwd, options);
|
|
48
78
|
}
|
|
49
79
|
/**
|
|
50
80
|
* 是否为会话附件根下的路径(写保护)
|
|
@@ -102,8 +132,16 @@ export function findExecutable(name) {
|
|
|
102
132
|
const lower = name.toLowerCase();
|
|
103
133
|
const hasOwnExt = pathExt.some((e) => lower.endsWith(e.toLowerCase()));
|
|
104
134
|
for (const dir of dirs) {
|
|
105
|
-
|
|
106
|
-
|
|
135
|
+
// Prefer real PE via PATHEXT (.EXE/.COM) over extensionless shims and
|
|
136
|
+
// .CMD/.BAT (Node ≥18.20 refuses spawn of .cmd/.bat — CVE-2024-27980).
|
|
137
|
+
const ordered = hasOwnExt
|
|
138
|
+
? [name]
|
|
139
|
+
: [
|
|
140
|
+
...pathExt.filter((e) => !/^\.(cmd|bat)$/i.test(e)).map((e) => name + e),
|
|
141
|
+
...pathExt.filter((e) => /^\.(cmd|bat)$/i.test(e)).map((e) => name + e),
|
|
142
|
+
name,
|
|
143
|
+
];
|
|
144
|
+
for (const candidate of ordered) {
|
|
107
145
|
const full = join(dir, candidate);
|
|
108
146
|
if (isExecutableFile(full))
|
|
109
147
|
return full;
|
|
@@ -127,6 +165,83 @@ export function findExecutable(name) {
|
|
|
127
165
|
export function commandExists(name) {
|
|
128
166
|
return findExecutable(name) !== null;
|
|
129
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Resolve a Node-based CLI (npm / pnpm / yarn) to a spawnable argv head.
|
|
170
|
+
*
|
|
171
|
+
* Windows never spawns `.cmd`/`.bat` directly (Node ≥18.20 throws EINVAL,
|
|
172
|
+
* CVE-2024-27980). Prefer `node <package-cli.js>` when the shim layout is
|
|
173
|
+
* known; otherwise fall back to the resolved path only when it is a real PE.
|
|
174
|
+
*
|
|
175
|
+
* @param name - tool name (`npm` | `pnpm` | `yarn`)
|
|
176
|
+
* @returns executable + prefix args inserted before user args
|
|
177
|
+
*/
|
|
178
|
+
export function resolveNodeToolCommand(name) {
|
|
179
|
+
const found = findExecutable(name);
|
|
180
|
+
if (!found) {
|
|
181
|
+
throw new Error(`${name}_not_found: "${name}" is not on PATH. Install it on the host or use package_edit / file tools instead.`);
|
|
182
|
+
}
|
|
183
|
+
const lower = found.toLowerCase();
|
|
184
|
+
const isCmdShim = lower.endsWith('.cmd') || lower.endsWith('.bat');
|
|
185
|
+
// Extensionless shims on Windows (e.g. the bash `npm` script) are not spawnable as PE.
|
|
186
|
+
const looksLikeScript = process.platform === 'win32' && (isCmdShim || (!lower.endsWith('.exe') && !lower.endsWith('.com')));
|
|
187
|
+
if (!looksLikeScript) {
|
|
188
|
+
return { executable: found, prefixArgs: [] };
|
|
189
|
+
}
|
|
190
|
+
const dir = dirname(found);
|
|
191
|
+
const node = findExecutable('node') ?? process.execPath;
|
|
192
|
+
const jsCandidates = [
|
|
193
|
+
join(dir, 'node_modules', name, 'bin', `${name}-cli.js`),
|
|
194
|
+
join(dir, 'node_modules', name, 'bin', `${name}.js`),
|
|
195
|
+
join(dir, 'node_modules', name, 'bin', `${name}.cjs`),
|
|
196
|
+
join(dir, 'node_modules', name, 'lib', 'cli.js'),
|
|
197
|
+
join(dir, '..', 'node_modules', name, 'bin', `${name}-cli.js`),
|
|
198
|
+
join(dir, '..', 'lib', name, 'bin', `${name}-cli.js`),
|
|
199
|
+
];
|
|
200
|
+
for (const candidate of jsCandidates) {
|
|
201
|
+
if (existsSync(candidate)) {
|
|
202
|
+
return { executable: node, prefixArgs: [candidate] };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
throw new Error(`${name}_windows_spawn_unsupported: cannot resolve "${found}" to a node JS entry (CVE-2024-27980 forbids spawning .cmd). Run the install manually on the host, or use a ${name} installed as a real PE.`);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Minimal platform env for child processes (allowlist-shaped; no secret inherit).
|
|
209
|
+
* Only keys already accepted by `scrubEnv` are included.
|
|
210
|
+
*
|
|
211
|
+
* @returns env map with PATH plus OS essentials when present
|
|
212
|
+
*/
|
|
213
|
+
export function defaultChildEnv() {
|
|
214
|
+
const keys = [
|
|
215
|
+
'HOME',
|
|
216
|
+
'USERPROFILE',
|
|
217
|
+
'HOMEDRIVE',
|
|
218
|
+
'HOMEPATH',
|
|
219
|
+
'TMP',
|
|
220
|
+
'TEMP',
|
|
221
|
+
'TMPDIR',
|
|
222
|
+
'LANG',
|
|
223
|
+
'LC_ALL',
|
|
224
|
+
'LC_CTYPE',
|
|
225
|
+
'TZ',
|
|
226
|
+
'SHELL',
|
|
227
|
+
'TERM',
|
|
228
|
+
'COMSPEC',
|
|
229
|
+
'PATHEXT',
|
|
230
|
+
'SYSTEMROOT',
|
|
231
|
+
'SystemRoot',
|
|
232
|
+
'WINDIR',
|
|
233
|
+
'windir',
|
|
234
|
+
'USER',
|
|
235
|
+
'LOGNAME',
|
|
236
|
+
];
|
|
237
|
+
const out = { PATH: defaultPathEnv() };
|
|
238
|
+
for (const k of keys) {
|
|
239
|
+
const v = process.env[k];
|
|
240
|
+
if (v !== undefined)
|
|
241
|
+
out[k] = v;
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
130
245
|
function unixShell() {
|
|
131
246
|
for (const candidate of ['/bin/bash', 'bash']) {
|
|
132
247
|
const found = candidate.startsWith('/')
|
|
@@ -249,3 +364,27 @@ export function defaultPathEnv() {
|
|
|
249
364
|
}
|
|
250
365
|
return process.env.PATH ?? '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin';
|
|
251
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* True when `target` is the session undo ledger root or under it (D6-a).
|
|
369
|
+
* Prefers real root comparison against injected `undoRoots`; falls back to an
|
|
370
|
+
* exact `sessions/<id>/undo` path-shape match when the runner did not inject.
|
|
371
|
+
*
|
|
372
|
+
* @param target - absolute or relative path under consideration
|
|
373
|
+
* @param undoRoots - resolveSessionUndoPaths roots (optional)
|
|
374
|
+
* @returns whether the path is protected undo ledger
|
|
375
|
+
*/
|
|
376
|
+
export function isUnderSessionUndoRoot(target, undoRoots) {
|
|
377
|
+
const resolved = resolve(target);
|
|
378
|
+
const roots = (undoRoots ?? []).map((r) => r?.trim()).filter(Boolean);
|
|
379
|
+
const fold = (p) => process.platform === 'win32' ? p.toLowerCase() : p;
|
|
380
|
+
if (roots.length > 0) {
|
|
381
|
+
const norm = (p) => fold(resolve(p).replace(/\\/g, '/'));
|
|
382
|
+
const tNorm = norm(resolved);
|
|
383
|
+
return roots.some((root) => {
|
|
384
|
+
const r = norm(root);
|
|
385
|
+
return tNorm === r || tNorm.startsWith(r.endsWith('/') ? r : r + '/');
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
const norm = fold(resolved.replace(/\\/g, '/'));
|
|
389
|
+
return /\/sessions\/[^/]+\/undo(\/|$)/i.test(norm);
|
|
390
|
+
}
|