@octopi-agent/engine 0.55.0
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 -0
- package/NOTICE +7 -0
- package/README.md +26 -0
- package/dist/builtin-model-info.d.ts +30 -0
- package/dist/builtin-model-info.js +118 -0
- package/dist/config-schema/agent.d.ts +72 -0
- package/dist/config-schema/agent.js +38 -0
- package/dist/config-schema/context.d.ts +122 -0
- package/dist/config-schema/context.js +100 -0
- package/dist/config-schema/engine.d.ts +665 -0
- package/dist/config-schema/engine.js +55 -0
- package/dist/config-schema/governance.d.ts +81 -0
- package/dist/config-schema/governance.js +55 -0
- package/dist/config-schema/models.d.ts +159 -0
- package/dist/config-schema/models.js +92 -0
- package/dist/config-schema/observability.d.ts +57 -0
- package/dist/config-schema/observability.js +59 -0
- package/dist/config-schema/run.d.ts +102 -0
- package/dist/config-schema/run.js +99 -0
- package/dist/config-schema/shared.d.ts +54 -0
- package/dist/config-schema/shared.js +43 -0
- package/dist/config-schema/substrate.d.ts +156 -0
- package/dist/config-schema/substrate.js +191 -0
- package/dist/config-schema/subsystems.d.ts +11 -0
- package/dist/config-schema/subsystems.js +13 -0
- package/dist/config-schema/web-search.d.ts +32 -0
- package/dist/config-schema/web-search.js +38 -0
- package/dist/config.d.ts +840 -0
- package/dist/config.js +161 -0
- package/dist/harness/activation/coalesce.d.ts +38 -0
- package/dist/harness/activation/coalesce.js +80 -0
- package/dist/harness/activation/compiler.d.ts +15 -0
- package/dist/harness/activation/compiler.js +136 -0
- package/dist/harness/activation/dispatcher.d.ts +19 -0
- package/dist/harness/activation/dispatcher.js +31 -0
- package/dist/harness/activation/event-source-types.d.ts +63 -0
- package/dist/harness/activation/event-source-types.js +13 -0
- package/dist/harness/activation/index.d.ts +20 -0
- package/dist/harness/activation/index.js +14 -0
- package/dist/harness/activation/router.d.ts +16 -0
- package/dist/harness/activation/router.js +28 -0
- package/dist/harness/activation/runtime.d.ts +78 -0
- package/dist/harness/activation/runtime.js +310 -0
- package/dist/harness/activation/sources/agent-signal.d.ts +34 -0
- package/dist/harness/activation/sources/agent-signal.js +93 -0
- package/dist/harness/activation/sources/escalate-bridge.d.ts +43 -0
- package/dist/harness/activation/sources/escalate-bridge.js +85 -0
- package/dist/harness/activation/sources/index.d.ts +6 -0
- package/dist/harness/activation/sources/index.js +3 -0
- package/dist/harness/activation/sources/schedule.d.ts +43 -0
- package/dist/harness/activation/sources/schedule.js +102 -0
- package/dist/harness/activation/types.d.ts +166 -0
- package/dist/harness/activation/types.js +15 -0
- package/dist/harness/agent/builder.d.ts +456 -0
- package/dist/harness/agent/builder.js +1414 -0
- package/dist/harness/agent/config-bridge.d.ts +80 -0
- package/dist/harness/agent/config-bridge.js +424 -0
- package/dist/harness/agent/index.d.ts +15 -0
- package/dist/harness/agent/index.js +12 -0
- package/dist/harness/agent/persona.d.ts +52 -0
- package/dist/harness/agent/persona.js +166 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/index.d.ts +4 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/index.js +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +18 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +83 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +36 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +54 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +24 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +142 -0
- package/dist/harness/collaboration/autonomous-subsystem/errors.d.ts +8 -0
- package/dist/harness/collaboration/autonomous-subsystem/errors.js +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +25 -0
- package/dist/harness/collaboration/autonomous-subsystem/index.js +28 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +34 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +368 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +131 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +531 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +116 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +551 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/index.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/index.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +128 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +46 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +57 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +48 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +108 -0
- package/dist/harness/collaboration/autonomous-subsystem/session/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/session/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/session/manager.d.ts +26 -0
- package/dist/harness/collaboration/autonomous-subsystem/session/manager.js +78 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +110 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +190 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +107 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +405 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +65 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +116 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +64 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +89 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +559 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.js +21 -0
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +144 -0
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +25 -0
- package/dist/harness/collaboration/multi-agent/index.d.ts +17 -0
- package/dist/harness/collaboration/multi-agent/index.js +15 -0
- package/dist/harness/collaboration/multi-agent/message-channel-types.d.ts +69 -0
- package/dist/harness/collaboration/multi-agent/message-channel-types.js +16 -0
- package/dist/harness/collaboration/multi-agent/process.d.ts +167 -0
- package/dist/harness/collaboration/multi-agent/process.js +256 -0
- package/dist/harness/collaboration/multi-agent/registry.d.ts +36 -0
- package/dist/harness/collaboration/multi-agent/registry.js +137 -0
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +135 -0
- package/dist/harness/collaboration/multi-agent/swarm.js +317 -0
- package/dist/harness/collaboration/multi-agent/types.d.ts +66 -0
- package/dist/harness/collaboration/multi-agent/types.js +15 -0
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +107 -0
- package/dist/harness/collaboration/orchestration/async-task-store.js +12 -0
- package/dist/harness/collaboration/orchestration/async-task.d.ts +156 -0
- package/dist/harness/collaboration/orchestration/async-task.js +359 -0
- package/dist/harness/collaboration/orchestration/cognitive-loop.d.ts +93 -0
- package/dist/harness/collaboration/orchestration/cognitive-loop.js +6 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +19 -0
- package/dist/harness/collaboration/orchestration/index.js +16 -0
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +47 -0
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +61 -0
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +9 -0
- package/dist/harness/collaboration/orchestration/planner/index.js +6 -0
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +54 -0
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +167 -0
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +85 -0
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +175 -0
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +21 -0
- package/dist/harness/collaboration/orchestration/quality/classifier.js +235 -0
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +29 -0
- package/dist/harness/collaboration/orchestration/quality/gate.js +409 -0
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +9 -0
- package/dist/harness/collaboration/orchestration/quality/index.js +8 -0
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +159 -0
- package/dist/harness/collaboration/orchestration/quality/types.js +33 -0
- package/dist/harness/collaboration/orchestration/reflector/index.d.ts +5 -0
- package/dist/harness/collaboration/orchestration/reflector/index.js +4 -0
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +41 -0
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +142 -0
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +5 -0
- package/dist/harness/collaboration/orchestration/scheduler/index.js +4 -0
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +143 -0
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +297 -0
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +12 -0
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +81 -0
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +3 -0
- package/dist/harness/collaboration/orchestration/strategy/index.js +2 -0
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +28 -0
- package/dist/harness/collaboration/orchestration/strategy/router.js +105 -0
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +49 -0
- package/dist/harness/collaboration/orchestration/strategy/types.js +4 -0
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +86 -0
- package/dist/harness/collaboration/orchestration/workflow/engine.js +298 -0
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +9 -0
- package/dist/harness/collaboration/orchestration/workflow/index.js +7 -0
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +143 -0
- package/dist/harness/collaboration/orchestration/workflow/types.js +7 -0
- package/dist/harness/context/assembler.d.ts +74 -0
- package/dist/harness/context/assembler.js +315 -0
- package/dist/harness/context/budget-allocator.d.ts +41 -0
- package/dist/harness/context/budget-allocator.js +80 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +15 -0
- package/dist/harness/context/capabilities/compact/engine.js +320 -0
- package/dist/harness/context/capabilities/compact/index.d.ts +7 -0
- package/dist/harness/context/capabilities/compact/index.js +6 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +78 -0
- package/dist/harness/context/capabilities/compact/types.js +6 -0
- package/dist/harness/context/capabilities/index.d.ts +10 -0
- package/dist/harness/context/capabilities/index.js +10 -0
- package/dist/harness/context/capabilities/summary/budget.d.ts +23 -0
- package/dist/harness/context/capabilities/summary/budget.js +26 -0
- package/dist/harness/context/capabilities/summary/executor.d.ts +37 -0
- package/dist/harness/context/capabilities/summary/executor.js +189 -0
- package/dist/harness/context/capabilities/summary/gate.d.ts +43 -0
- package/dist/harness/context/capabilities/summary/gate.js +69 -0
- package/dist/harness/context/capabilities/summary/index.d.ts +17 -0
- package/dist/harness/context/capabilities/summary/index.js +15 -0
- package/dist/harness/context/capabilities/summary/memory-cache.d.ts +16 -0
- package/dist/harness/context/capabilities/summary/memory-cache.js +42 -0
- package/dist/harness/context/capabilities/summary/oversized.d.ts +51 -0
- package/dist/harness/context/capabilities/summary/oversized.js +80 -0
- package/dist/harness/context/capabilities/summary/policies.d.ts +12 -0
- package/dist/harness/context/capabilities/summary/policies.js +139 -0
- package/dist/harness/context/capabilities/summary/port.d.ts +29 -0
- package/dist/harness/context/capabilities/summary/port.js +124 -0
- package/dist/harness/context/capabilities/summary/registry.d.ts +50 -0
- package/dist/harness/context/capabilities/summary/registry.js +182 -0
- package/dist/harness/context/capabilities/summary/resolver.d.ts +35 -0
- package/dist/harness/context/capabilities/summary/resolver.js +145 -0
- package/dist/harness/context/capabilities/summary/structured.d.ts +35 -0
- package/dist/harness/context/capabilities/summary/structured.js +163 -0
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +86 -0
- package/dist/harness/context/capabilities/summary/tool-binding.js +166 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +171 -0
- package/dist/harness/context/capabilities/summary/types.js +6 -0
- package/dist/harness/context/compact-key.d.ts +13 -0
- package/dist/harness/context/compact-key.js +17 -0
- package/dist/harness/context/constitution/default-agents.md +227 -0
- package/dist/harness/context/constitution/load-constitution.d.ts +30 -0
- package/dist/harness/context/constitution/load-constitution.js +66 -0
- package/dist/harness/context/default-context-engine.d.ts +171 -0
- package/dist/harness/context/default-context-engine.js +836 -0
- package/dist/harness/context/hybrid-compressor.d.ts +41 -0
- package/dist/harness/context/hybrid-compressor.js +158 -0
- package/dist/harness/context/index.d.ts +26 -0
- package/dist/harness/context/index.js +17 -0
- package/dist/harness/context/layer-health.d.ts +58 -0
- package/dist/harness/context/layer-health.js +160 -0
- package/dist/harness/context/layer-snapshot.d.ts +69 -0
- package/dist/harness/context/layer-snapshot.js +133 -0
- package/dist/harness/context/layer-types.d.ts +184 -0
- package/dist/harness/context/layer-types.js +79 -0
- package/dist/harness/context/layers.d.ts +146 -0
- package/dist/harness/context/layers.js +371 -0
- package/dist/harness/context/llm-summarizer.d.ts +38 -0
- package/dist/harness/context/llm-summarizer.js +220 -0
- package/dist/harness/context/message-selector.d.ts +44 -0
- package/dist/harness/context/message-selector.js +180 -0
- package/dist/harness/context/runtime-datetime.d.ts +49 -0
- package/dist/harness/context/runtime-datetime.js +74 -0
- package/dist/harness/context/smart-router.d.ts +75 -0
- package/dist/harness/context/smart-router.js +118 -0
- package/dist/harness/context/summarize.d.ts +39 -0
- package/dist/harness/context/summarize.js +50 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +56 -0
- package/dist/harness/context/system-prompt-assembler.js +122 -0
- package/dist/harness/context/token-constants.d.ts +24 -0
- package/dist/harness/context/token-constants.js +27 -0
- package/dist/harness/context/token-estimate-fns.d.ts +70 -0
- package/dist/harness/context/token-estimate-fns.js +117 -0
- package/dist/harness/context/token-estimator.d.ts +63 -0
- package/dist/harness/context/token-estimator.js +126 -0
- package/dist/harness/context/truncate-compressor.d.ts +28 -0
- package/dist/harness/context/truncate-compressor.js +100 -0
- package/dist/harness/context/types.d.ts +316 -0
- package/dist/harness/context/types.js +9 -0
- package/dist/harness/extension/execution-environment/index.d.ts +10 -0
- package/dist/harness/extension/execution-environment/index.js +8 -0
- package/dist/harness/extension/execution-environment/isolation.d.ts +56 -0
- package/dist/harness/extension/execution-environment/isolation.js +56 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +12 -0
- package/dist/harness/extension/execution-environment/sandbox.js +87 -0
- package/dist/harness/extension/execution-environment/types.d.ts +157 -0
- package/dist/harness/extension/execution-environment/types.js +6 -0
- package/dist/harness/extension/execution-environment/workspace.d.ts +26 -0
- package/dist/harness/extension/execution-environment/workspace.js +171 -0
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +34 -0
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +12 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.d.ts +34 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +185 -0
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +11 -0
- package/dist/harness/extension/plugin-ecosystem/commands/parse.d.ts +17 -0
- package/dist/harness/extension/plugin-ecosystem/commands/parse.js +41 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +49 -0
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +71 -0
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +302 -0
- package/dist/harness/extension/plugin-ecosystem/commands/skill-bridge.d.ts +10 -0
- package/dist/harness/extension/plugin-ecosystem/commands/skill-bridge.js +59 -0
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +126 -0
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +7 -0
- package/dist/harness/extension/plugin-ecosystem/commands/user-source.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/commands/user-source.js +102 -0
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +10 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.d.ts +42 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +88 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/discovery.d.ts +39 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/discovery.js +117 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/index.d.ts +10 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/index.js +8 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/manager.d.ts +74 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/manager.js +146 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/types.d.ts +149 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/types.js +12 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +294 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +270 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +100 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +158 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +101 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +65 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +7 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +26 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +26 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +86 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +135 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +353 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +504 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +368 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +261 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +44 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +123 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +210 -0
- package/dist/harness/extension/plugin-ecosystem/skills/types.d.ts +29 -0
- package/dist/harness/extension/plugin-ecosystem/skills/types.js +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +92 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +101 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +570 -0
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +49 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.d.ts +14 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +126 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +23 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +659 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +28 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +14 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +12 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.d.ts +25 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +164 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +19 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +82 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +251 -0
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.d.ts +21 -0
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +165 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +65 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +262 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +30 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search-types.d.ts +66 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search-types.js +12 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.d.ts +23 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +84 -0
- package/dist/harness/governance/accounting/index.d.ts +5 -0
- package/dist/harness/governance/accounting/index.js +3 -0
- package/dist/harness/governance/accounting/session-ledger.d.ts +67 -0
- package/dist/harness/governance/accounting/session-ledger.js +84 -0
- package/dist/harness/governance/accounting/usage-ledger.d.ts +107 -0
- package/dist/harness/governance/accounting/usage-ledger.js +137 -0
- package/dist/harness/governance/credentials/crypto.d.ts +34 -0
- package/dist/harness/governance/credentials/crypto.js +79 -0
- package/dist/harness/governance/credentials/db.d.ts +32 -0
- package/dist/harness/governance/credentials/db.js +87 -0
- package/dist/harness/governance/credentials/index.d.ts +9 -0
- package/dist/harness/governance/credentials/index.js +7 -0
- package/dist/harness/governance/credentials/store.d.ts +47 -0
- package/dist/harness/governance/credentials/store.js +228 -0
- package/dist/harness/governance/credentials/types.d.ts +67 -0
- package/dist/harness/governance/credentials/types.js +30 -0
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +32 -0
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +93 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +9 -0
- package/dist/harness/governance/human-in-the-loop/index.js +7 -0
- package/dist/harness/governance/human-in-the-loop/types.d.ts +66 -0
- package/dist/harness/governance/human-in-the-loop/types.js +6 -0
- package/dist/harness/governance/index.d.ts +10 -0
- package/dist/harness/governance/index.js +10 -0
- package/dist/harness/governance/security/capability-enforcer.d.ts +56 -0
- package/dist/harness/governance/security/capability-enforcer.js +132 -0
- package/dist/harness/governance/security/default-risk-policy.d.ts +66 -0
- package/dist/harness/governance/security/default-risk-policy.js +75 -0
- package/dist/harness/governance/security/default-security-guard.d.ts +105 -0
- package/dist/harness/governance/security/default-security-guard.js +578 -0
- package/dist/harness/governance/security/degradation.d.ts +14 -0
- package/dist/harness/governance/security/degradation.js +208 -0
- package/dist/harness/governance/security/index.d.ts +10 -0
- package/dist/harness/governance/security/index.js +10 -0
- package/dist/harness/governance/security/risk-evaluator.d.ts +68 -0
- package/dist/harness/governance/security/risk-evaluator.js +1043 -0
- package/dist/harness/governance/security/risk-types.d.ts +74 -0
- package/dist/harness/governance/security/risk-types.js +7 -0
- package/dist/harness/governance/security/shell-parser.d.ts +35 -0
- package/dist/harness/governance/security/shell-parser.js +525 -0
- package/dist/harness/governance/security/tool-call-risk-policy.d.ts +6 -0
- package/dist/harness/governance/security/tool-call-risk-policy.js +6 -0
- package/dist/harness/governance/session-acl/index.d.ts +11 -0
- package/dist/harness/governance/session-acl/index.js +7 -0
- package/dist/harness/governance/session-acl/rights.d.ts +78 -0
- package/dist/harness/governance/session-acl/rights.js +142 -0
- package/dist/harness/governance/session-acl/seed-roles.d.ts +16 -0
- package/dist/harness/governance/session-acl/seed-roles.js +85 -0
- package/dist/harness/governance/session-acl/service.d.ts +136 -0
- package/dist/harness/governance/session-acl/service.js +407 -0
- package/dist/harness/governance/session-acl/types.d.ts +102 -0
- package/dist/harness/governance/session-acl/types.js +5 -0
- package/dist/harness/index.d.ts +137 -0
- package/dist/harness/index.js +106 -0
- package/dist/harness/knowledge/adapters.d.ts +68 -0
- package/dist/harness/knowledge/adapters.js +421 -0
- package/dist/harness/knowledge/catalog-index.d.ts +7 -0
- package/dist/harness/knowledge/catalog-index.js +7 -0
- package/dist/harness/knowledge/catalog-types.d.ts +33 -0
- package/dist/harness/knowledge/catalog-types.js +10 -0
- package/dist/harness/knowledge/connector-fetcher.d.ts +13 -0
- package/dist/harness/knowledge/connector-fetcher.js +27 -0
- package/dist/harness/knowledge/connectors.d.ts +55 -0
- package/dist/harness/knowledge/connectors.js +181 -0
- package/dist/harness/knowledge/db.d.ts +26 -0
- package/dist/harness/knowledge/db.js +235 -0
- package/dist/harness/knowledge/describe.d.ts +40 -0
- package/dist/harness/knowledge/describe.js +52 -0
- package/dist/harness/knowledge/fetchers.d.ts +66 -0
- package/dist/harness/knowledge/fetchers.js +342 -0
- package/dist/harness/knowledge/grounding.d.ts +98 -0
- package/dist/harness/knowledge/grounding.js +208 -0
- package/dist/harness/knowledge/hit-log.d.ts +74 -0
- package/dist/harness/knowledge/hit-log.js +99 -0
- package/dist/harness/knowledge/html.d.ts +20 -0
- package/dist/harness/knowledge/html.js +103 -0
- package/dist/harness/knowledge/index-store.d.ts +150 -0
- package/dist/harness/knowledge/index-store.js +394 -0
- package/dist/harness/knowledge/index.d.ts +38 -0
- package/dist/harness/knowledge/index.js +24 -0
- package/dist/harness/knowledge/ingest.d.ts +162 -0
- package/dist/harness/knowledge/ingest.js +814 -0
- package/dist/harness/knowledge/network-guard.d.ts +57 -0
- package/dist/harness/knowledge/network-guard.js +242 -0
- package/dist/harness/knowledge/paths.d.ts +14 -0
- package/dist/harness/knowledge/paths.js +17 -0
- package/dist/harness/knowledge/purge.d.ts +34 -0
- package/dist/harness/knowledge/purge.js +51 -0
- package/dist/harness/knowledge/retriever.d.ts +83 -0
- package/dist/harness/knowledge/retriever.js +184 -0
- package/dist/harness/knowledge/secret-scan.d.ts +11 -0
- package/dist/harness/knowledge/secret-scan.js +32 -0
- package/dist/harness/knowledge/source-store.d.ts +107 -0
- package/dist/harness/knowledge/source-store.js +516 -0
- package/dist/harness/knowledge/types.d.ts +129 -0
- package/dist/harness/knowledge/types.js +14 -0
- package/dist/harness/memory/backfill-coverage.d.ts +80 -0
- package/dist/harness/memory/backfill-coverage.js +146 -0
- package/dist/harness/memory/backfill-trigger.d.ts +83 -0
- package/dist/harness/memory/backfill-trigger.js +247 -0
- package/dist/harness/memory/cognition-types.d.ts +4 -0
- package/dist/harness/memory/cognition-types.js +4 -0
- package/dist/harness/memory/cognition.d.ts +16 -0
- package/dist/harness/memory/cognition.js +107 -0
- package/dist/harness/memory/confidence.d.ts +63 -0
- package/dist/harness/memory/confidence.js +157 -0
- package/dist/harness/memory/decay-policy.d.ts +22 -0
- package/dist/harness/memory/decay-policy.js +28 -0
- package/dist/harness/memory/gates.d.ts +39 -0
- package/dist/harness/memory/gates.js +176 -0
- package/dist/harness/memory/health-probe.d.ts +36 -0
- package/dist/harness/memory/health-probe.js +78 -0
- package/dist/harness/memory/index.d.ts +32 -0
- package/dist/harness/memory/index.js +26 -0
- package/dist/harness/memory/similarity.d.ts +33 -0
- package/dist/harness/memory/similarity.js +69 -0
- package/dist/harness/memory/sqlite/agent-db.d.ts +73 -0
- package/dist/harness/memory/sqlite/agent-db.js +277 -0
- package/dist/harness/memory/sqlite/backfill-coverage.d.ts +13 -0
- package/dist/harness/memory/sqlite/backfill-coverage.js +57 -0
- package/dist/harness/memory/sqlite/cognition-store.d.ts +34 -0
- package/dist/harness/memory/sqlite/cognition-store.js +188 -0
- package/dist/harness/memory/sqlite/embedding-from-models.d.ts +47 -0
- package/dist/harness/memory/sqlite/embedding-from-models.js +90 -0
- package/dist/harness/memory/sqlite/embedding.d.ts +93 -0
- package/dist/harness/memory/sqlite/embedding.js +268 -0
- package/dist/harness/memory/sqlite/index.d.ts +22 -0
- package/dist/harness/memory/sqlite/index.js +17 -0
- package/dist/harness/memory/sqlite/keyword-search.d.ts +37 -0
- package/dist/harness/memory/sqlite/keyword-search.js +113 -0
- package/dist/harness/memory/sqlite/knowledge-registry.d.ts +45 -0
- package/dist/harness/memory/sqlite/knowledge-registry.js +59 -0
- package/dist/harness/memory/sqlite/memory-store.d.ts +80 -0
- package/dist/harness/memory/sqlite/memory-store.js +548 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +45 -0
- package/dist/harness/memory/sqlite/sqlite-vec.js +159 -0
- package/dist/harness/memory/sqlite/vector-search.d.ts +41 -0
- package/dist/harness/memory/sqlite/vector-search.js +72 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +23 -0
- package/dist/harness/memory/sqlite/wisdom-store.js +64 -0
- package/dist/harness/memory/steward-policy.d.ts +122 -0
- package/dist/harness/memory/steward-policy.js +369 -0
- package/dist/harness/memory/store.d.ts +33 -0
- package/dist/harness/memory/store.js +173 -0
- package/dist/harness/memory/types.d.ts +170 -0
- package/dist/harness/memory/types.js +7 -0
- package/dist/harness/memory/wisdom-types.d.ts +4 -0
- package/dist/harness/memory/wisdom-types.js +4 -0
- package/dist/harness/observability/diagnostics/index.d.ts +5 -0
- package/dist/harness/observability/diagnostics/index.js +4 -0
- package/dist/harness/observability/diagnostics/registry.d.ts +19 -0
- package/dist/harness/observability/diagnostics/registry.js +74 -0
- package/dist/harness/observability/diagnostics/types.d.ts +42 -0
- package/dist/harness/observability/diagnostics/types.js +6 -0
- package/dist/harness/observability/observer/hub.d.ts +107 -0
- package/dist/harness/observability/observer/hub.js +907 -0
- package/dist/harness/observability/observer/index.d.ts +4 -0
- package/dist/harness/observability/observer/index.js +3 -0
- package/dist/harness/observability/observer/run-snapshot.d.ts +47 -0
- package/dist/harness/observability/observer/run-snapshot.js +65 -0
- package/dist/harness/observability/observer/types.d.ts +370 -0
- package/dist/harness/observability/observer/types.js +379 -0
- package/dist/harness/observability/run-telemetry.d.ts +51 -0
- package/dist/harness/observability/run-telemetry.js +28 -0
- package/dist/harness/run/agent/agent.d.ts +142 -0
- package/dist/harness/run/agent/agent.js +192 -0
- package/dist/harness/run/agent/index.d.ts +8 -0
- package/dist/harness/run/agent/index.js +7 -0
- package/dist/harness/run/budget/budget.d.ts +94 -0
- package/dist/harness/run/budget/budget.js +124 -0
- package/dist/harness/run/budget/index.d.ts +7 -0
- package/dist/harness/run/budget/index.js +6 -0
- package/dist/harness/run/concurrency/index.d.ts +18 -0
- package/dist/harness/run/concurrency/index.js +14 -0
- package/dist/harness/run/concurrency/provider-pool.d.ts +128 -0
- package/dist/harness/run/concurrency/provider-pool.js +329 -0
- package/dist/harness/run/concurrency/rate-limiter.d.ts +109 -0
- package/dist/harness/run/concurrency/rate-limiter.js +233 -0
- package/dist/harness/run/concurrency/session-gate.d.ts +85 -0
- package/dist/harness/run/concurrency/session-gate.js +176 -0
- package/dist/harness/run/concurrency/session-lease.d.ts +79 -0
- package/dist/harness/run/concurrency/session-lease.js +100 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +41 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +239 -0
- package/dist/harness/run/concurrency/tool-loop-detection.d.ts +8 -0
- package/dist/harness/run/concurrency/tool-loop-detection.js +7 -0
- package/dist/harness/run/concurrency/tool-validator.d.ts +96 -0
- package/dist/harness/run/concurrency/tool-validator.js +195 -0
- package/dist/harness/run/index.d.ts +14 -0
- package/dist/harness/run/index.js +14 -0
- package/dist/harness/run/model/index.d.ts +9 -0
- package/dist/harness/run/model/index.js +7 -0
- package/dist/harness/run/model/resolver.d.ts +111 -0
- package/dist/harness/run/model/resolver.js +192 -0
- package/dist/harness/run/model/run-scope.d.ts +43 -0
- package/dist/harness/run/model/run-scope.js +64 -0
- package/dist/harness/run/model/types.d.ts +47 -0
- package/dist/harness/run/model/types.js +9 -0
- package/dist/harness/run/reliability/circuit-breaker.d.ts +87 -0
- package/dist/harness/run/reliability/circuit-breaker.js +130 -0
- package/dist/harness/run/reliability/fallback-provider.d.ts +40 -0
- package/dist/harness/run/reliability/fallback-provider.js +118 -0
- package/dist/harness/run/reliability/harness-events.d.ts +109 -0
- package/dist/harness/run/reliability/harness-events.js +7 -0
- package/dist/harness/run/reliability/index.d.ts +12 -0
- package/dist/harness/run/reliability/index.js +7 -0
- package/dist/harness/run/reliability/model-binding.d.ts +22 -0
- package/dist/harness/run/reliability/model-binding.js +27 -0
- package/dist/harness/run/reliability/provider-wrapper.d.ts +26 -0
- package/dist/harness/run/reliability/provider-wrapper.js +61 -0
- package/dist/harness/run/reliability/run-agent.d.ts +86 -0
- package/dist/harness/run/reliability/run-agent.js +932 -0
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +80 -0
- package/dist/harness/run/reliability/run-metrics-collector.js +194 -0
- package/dist/harness/run/reliability/run-model-context.d.ts +19 -0
- package/dist/harness/run/reliability/run-model-context.js +32 -0
- package/dist/harness/run/run-guard/default-run-guard.d.ts +75 -0
- package/dist/harness/run/run-guard/default-run-guard.js +347 -0
- package/dist/harness/run/run-guard/index.d.ts +9 -0
- package/dist/harness/run/run-guard/index.js +8 -0
- package/dist/harness/run/run-scope.d.ts +81 -0
- package/dist/harness/run/run-scope.js +58 -0
- package/dist/harness/run/runner.d.ts +362 -0
- package/dist/harness/run/runner.js +1290 -0
- package/dist/harness/session/attachments/extract.d.ts +35 -0
- package/dist/harness/session/attachments/extract.js +72 -0
- package/dist/harness/session/attachments/index.d.ts +11 -0
- package/dist/harness/session/attachments/index.js +11 -0
- package/dist/harness/session/attachments/inject.d.ts +71 -0
- package/dist/harness/session/attachments/inject.js +142 -0
- package/dist/harness/session/attachments/intent.d.ts +32 -0
- package/dist/harness/session/attachments/intent.js +69 -0
- package/dist/harness/session/attachments/llm-intent.d.ts +17 -0
- package/dist/harness/session/attachments/llm-intent.js +74 -0
- package/dist/harness/session/attachments/paths.d.ts +15 -0
- package/dist/harness/session/attachments/paths.js +18 -0
- package/dist/harness/session/attachments/sanitize.d.ts +23 -0
- package/dist/harness/session/attachments/sanitize.js +55 -0
- package/dist/harness/session/attachments/service.d.ts +105 -0
- package/dist/harness/session/attachments/service.js +320 -0
- package/dist/harness/session/attachments/types.d.ts +64 -0
- package/dist/harness/session/attachments/types.js +17 -0
- package/dist/harness/session/compact.d.ts +23 -0
- package/dist/harness/session/compact.js +53 -0
- package/dist/harness/session/history/index.d.ts +4 -0
- package/dist/harness/session/history/index.js +3 -0
- package/dist/harness/session/history/port.d.ts +51 -0
- package/dist/harness/session/history/port.js +480 -0
- package/dist/harness/session/history/score.d.ts +71 -0
- package/dist/harness/session/history/score.js +225 -0
- package/dist/harness/session/history/types.d.ts +157 -0
- package/dist/harness/session/history/types.js +29 -0
- package/dist/harness/session/in-memory-store.d.ts +21 -0
- package/dist/harness/session/in-memory-store.js +48 -0
- package/dist/harness/session/index.d.ts +12 -0
- package/dist/harness/session/index.js +12 -0
- package/dist/harness/session/state-machine.d.ts +18 -0
- package/dist/harness/session/state-machine.js +31 -0
- package/dist/harness/session/tasks/index.d.ts +11 -0
- package/dist/harness/session/tasks/index.js +9 -0
- package/dist/harness/session/tasks/render.d.ts +12 -0
- package/dist/harness/session/tasks/render.js +57 -0
- package/dist/harness/session/tasks/service.d.ts +69 -0
- package/dist/harness/session/tasks/service.js +327 -0
- package/dist/harness/session/tasks/tools.d.ts +17 -0
- package/dist/harness/session/tasks/tools.js +210 -0
- package/dist/harness/session/tasks/types.d.ts +29 -0
- package/dist/harness/session/tasks/types.js +11 -0
- package/dist/harness/session/types.d.ts +88 -0
- package/dist/harness/session/types.js +7 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +264 -0
- package/dist/harness/shared/events/agent-event-map.js +51 -0
- package/dist/harness/shared/events/index.d.ts +6 -0
- package/dist/harness/shared/events/index.js +4 -0
- package/dist/harness/shared/events/scenario-events.d.ts +96 -0
- package/dist/harness/shared/events/scenario-events.js +7 -0
- package/dist/harness/shared/types/agent-definition.d.ts +51 -0
- package/dist/harness/shared/types/agent-definition.js +8 -0
- package/dist/harness/shared/types/hook-context.d.ts +10 -0
- package/dist/harness/shared/types/hook-context.js +6 -0
- package/dist/harness/shared/types/index.d.ts +7 -0
- package/dist/harness/shared/types/index.js +4 -0
- package/dist/harness/shared/types/queue-mode.d.ts +4 -0
- package/dist/harness/shared/types/queue-mode.js +1 -0
- package/dist/harness/shared/types/thinking-level.d.ts +4 -0
- package/dist/harness/shared/types/thinking-level.js +1 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +80 -0
- package/dist/integration/agent-runtime/channel-message-source.d.ts +27 -0
- package/dist/integration/agent-runtime/channel-message-source.js +58 -0
- package/dist/integration/agent-runtime/file-watch-source.d.ts +31 -0
- package/dist/integration/agent-runtime/file-watch-source.js +63 -0
- package/dist/integration/agent-runtime/index.d.ts +6 -0
- package/dist/integration/agent-runtime/index.js +3 -0
- package/dist/integration/agent-runtime/webhook-source.d.ts +39 -0
- package/dist/integration/agent-runtime/webhook-source.js +112 -0
- package/dist/integration/index.d.ts +23 -0
- package/dist/integration/index.js +23 -0
- package/dist/integration/mcp/index.d.ts +6 -0
- package/dist/integration/mcp/index.js +6 -0
- package/dist/integration/mcp/sdk-client.d.ts +39 -0
- package/dist/integration/mcp/sdk-client.js +157 -0
- package/dist/integration/observability/exporters.d.ts +111 -0
- package/dist/integration/observability/exporters.js +167 -0
- package/dist/integration/observability/index.d.ts +21 -0
- package/dist/integration/observability/index.js +16 -0
- package/dist/integration/observability/log-observer.d.ts +12 -0
- package/dist/integration/observability/log-observer.js +59 -0
- package/dist/integration/observability/metrics.d.ts +116 -0
- package/dist/integration/observability/metrics.js +237 -0
- package/dist/integration/observability/noop-observer.d.ts +12 -0
- package/dist/integration/observability/noop-observer.js +22 -0
- package/dist/integration/observability/observer-bridge.d.ts +56 -0
- package/dist/integration/observability/observer-bridge.js +195 -0
- package/dist/integration/observability/run-telemetry.d.ts +28 -0
- package/dist/integration/observability/run-telemetry.js +83 -0
- package/dist/integration/observability/trace-collector.d.ts +124 -0
- package/dist/integration/observability/trace-collector.js +253 -0
- package/dist/integration/observability/trace-events.d.ts +69 -0
- package/dist/integration/observability/trace-events.js +83 -0
- package/dist/integration/observability/trace-logger.d.ts +110 -0
- package/dist/integration/observability/trace-logger.js +219 -0
- package/dist/integration/providers/anthropic.d.ts +92 -0
- package/dist/integration/providers/anthropic.js +432 -0
- package/dist/integration/providers/index.d.ts +4 -0
- package/dist/integration/providers/index.js +2 -0
- package/dist/integration/providers/openai.d.ts +120 -0
- package/dist/integration/providers/openai.js +429 -0
- package/dist/integration/providers/usage.d.ts +20 -0
- package/dist/integration/providers/usage.js +69 -0
- package/dist/integration/storage/archive-manager.d.ts +79 -0
- package/dist/integration/storage/archive-manager.js +223 -0
- package/dist/integration/storage/jsonl.d.ts +51 -0
- package/dist/integration/storage/jsonl.js +246 -0
- package/dist/integration/storage/memory.d.ts +7 -0
- package/dist/integration/storage/memory.js +7 -0
- package/dist/integration/storage/session-index.d.ts +57 -0
- package/dist/integration/storage/session-index.js +379 -0
- package/dist/integration/web-search/brave.d.ts +13 -0
- package/dist/integration/web-search/brave.js +64 -0
- package/dist/integration/web-search/duckduckgo.d.ts +12 -0
- package/dist/integration/web-search/duckduckgo.js +102 -0
- package/dist/integration/web-search/factory.d.ts +91 -0
- package/dist/integration/web-search/factory.js +166 -0
- package/dist/integration/web-search/http.d.ts +22 -0
- package/dist/integration/web-search/http.js +94 -0
- package/dist/integration/web-search/index.d.ts +16 -0
- package/dist/integration/web-search/index.js +9 -0
- package/dist/integration/web-search/mimo.d.ts +57 -0
- package/dist/integration/web-search/mimo.js +226 -0
- package/dist/integration/web-search/serper.d.ts +13 -0
- package/dist/integration/web-search/serper.js +59 -0
- package/dist/integration/web-search/tavily.d.ts +16 -0
- package/dist/integration/web-search/tavily.js +56 -0
- package/dist/paths.d.ts +14 -0
- package/dist/paths.js +22 -0
- package/dist/subsystems/memory-steward/backfill/SUBSYSTEM.md +30 -0
- package/dist/subsystems/memory-steward/backfill/config.yaml +51 -0
- package/dist/subsystems/memory-steward/backfill/handler.d.ts +18 -0
- package/dist/subsystems/memory-steward/backfill/handler.js +343 -0
- package/dist/subsystems/memory-steward/govern/SUBSYSTEM.md +12 -0
- package/dist/subsystems/memory-steward/govern/config.yaml +65 -0
- package/dist/subsystems/memory-steward/govern/handler.d.ts +19 -0
- package/dist/subsystems/memory-steward/govern/handler.js +79 -0
- package/dist/subsystems/safety-guard/SUBSYSTEM.md +60 -0
- package/dist/subsystems/safety-guard/config.yaml +40 -0
- package/package.json +110 -0
|
@@ -0,0 +1,1043 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk Evaluator — 风险评估引擎
|
|
3
|
+
*
|
|
4
|
+
* 基于规则的风险评估,覆盖 90%+ 的常见操作。
|
|
5
|
+
* 确定性:给定相同的输入,永远产生相同的输出。
|
|
6
|
+
*
|
|
7
|
+
* 设计原则(避免误判):
|
|
8
|
+
* 1. 评估"操作 + 目标"的组合,不是单独评估操作
|
|
9
|
+
* 2. 不确定时走 lower risk,交给 LLM 判断(emit unknown)
|
|
10
|
+
* 3. 每条规则可独立测试
|
|
11
|
+
* 4. 路径分类:系统路径 > 用户数据 > 项目目录 > 临时目录
|
|
12
|
+
*/
|
|
13
|
+
import { homedir } from 'node:os';
|
|
14
|
+
import { resolve } from 'node:path';
|
|
15
|
+
import { parseShellCommand, getRedirectTargets } from './shell-parser.js';
|
|
16
|
+
// ── 路径分类 ──
|
|
17
|
+
let cachedProtectedPaths = null;
|
|
18
|
+
let cachedTempPrefixes = null;
|
|
19
|
+
/** 仅测试用:环境变量变更后清空路径缓存 */
|
|
20
|
+
export function resetSecurityPathCache() {
|
|
21
|
+
cachedProtectedPaths = null;
|
|
22
|
+
cachedTempPrefixes = null;
|
|
23
|
+
}
|
|
24
|
+
function ensureTrailingSep(p) {
|
|
25
|
+
let n = p.replace(/\//g, '\\');
|
|
26
|
+
if (!n.endsWith('\\'))
|
|
27
|
+
n += '\\';
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
/** 硬保护路径(不可逆损坏)—— 含动态 SystemRoot */
|
|
31
|
+
function getProtectedPaths() {
|
|
32
|
+
if (cachedProtectedPaths)
|
|
33
|
+
return cachedProtectedPaths;
|
|
34
|
+
const paths = [
|
|
35
|
+
'/System/', '/usr/', '/bin/', '/sbin/', '/Library/',
|
|
36
|
+
'/etc/',
|
|
37
|
+
'/dev/',
|
|
38
|
+
'C:\\Windows\\', 'C:\\Program Files\\', 'C:\\Program Files (x86)\\',
|
|
39
|
+
];
|
|
40
|
+
const systemRoot = process.env.SystemRoot ?? process.env.windir;
|
|
41
|
+
if (systemRoot) {
|
|
42
|
+
const root = ensureTrailingSep(systemRoot);
|
|
43
|
+
if (!paths.some((p) => p.toLowerCase() === root.toLowerCase())) {
|
|
44
|
+
paths.push(root);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
cachedProtectedPaths = paths;
|
|
48
|
+
return paths;
|
|
49
|
+
}
|
|
50
|
+
/** 凭证目录 */
|
|
51
|
+
const CREDENTIAL_DIRS = [
|
|
52
|
+
'.ssh', '.gnupg', '.aws', '.config/gcloud',
|
|
53
|
+
'.openclaw', '.octopi/config',
|
|
54
|
+
];
|
|
55
|
+
/** 安全伪设备(/dev/ 下的安全目标) */
|
|
56
|
+
const SAFE_PSEUDO_DEVICES = new Set([
|
|
57
|
+
'/dev/null', '/dev/zero', '/dev/random', '/dev/urandom',
|
|
58
|
+
'/dev/stdin', '/dev/stdout', '/dev/stderr', '/dev/tty',
|
|
59
|
+
]);
|
|
60
|
+
/**
|
|
61
|
+
* 临时目录前缀
|
|
62
|
+
*
|
|
63
|
+
* 必须在 PROTECTED 之前匹配:`C:\Windows\Temp` 虽在 `C:\Windows\` 下,
|
|
64
|
+
* 但是可清空的临时区,应归 safe 而非 protected。
|
|
65
|
+
*/
|
|
66
|
+
function getTempPrefixes() {
|
|
67
|
+
if (cachedTempPrefixes)
|
|
68
|
+
return cachedTempPrefixes;
|
|
69
|
+
const prefixes = ['/tmp/', '/var/tmp/', '/private/var/tmp/'];
|
|
70
|
+
const userTemp = process.env.TEMP ?? process.env.TMP ?? process.env.Tmp;
|
|
71
|
+
if (userTemp) {
|
|
72
|
+
prefixes.push(ensureTrailingSep(userTemp));
|
|
73
|
+
}
|
|
74
|
+
prefixes.push('C:\\Windows\\Temp\\');
|
|
75
|
+
const systemRoot = process.env.SystemRoot ?? process.env.windir;
|
|
76
|
+
if (systemRoot) {
|
|
77
|
+
prefixes.push(ensureTrailingSep(systemRoot) + 'Temp\\');
|
|
78
|
+
}
|
|
79
|
+
// 用户 AppData Temp 回退(无 TEMP 环境变量时的静态路径)
|
|
80
|
+
const userProfile = process.env.USERPROFILE ?? process.env.HOME;
|
|
81
|
+
const home = userProfile ? userProfile.replace(/\//g, '\\') : homedir().replace(/\//g, '\\');
|
|
82
|
+
if (home) {
|
|
83
|
+
const base = home.endsWith('\\') ? home : home + '\\';
|
|
84
|
+
prefixes.push(base + 'AppData\\Local\\Temp\\');
|
|
85
|
+
prefixes.push(base + 'AppData\\Local\\Microsoft\\Windows\\Temp\\');
|
|
86
|
+
}
|
|
87
|
+
cachedTempPrefixes = prefixes;
|
|
88
|
+
return prefixes;
|
|
89
|
+
}
|
|
90
|
+
/** Windows 风格路径:盘符或 UNC */
|
|
91
|
+
function isWindowsStylePath(p) {
|
|
92
|
+
return /^[A-Za-z]:[\\/]/.test(p) || /^[A-Za-z]:$/.test(p) || p.includes('\\') || p.startsWith('\\\\');
|
|
93
|
+
}
|
|
94
|
+
/** 盘符根:`C:` / `C:\` / `D:/` */
|
|
95
|
+
function isDriveRoot(p) {
|
|
96
|
+
return /^[A-Za-z]:[\\/]?$/i.test(p);
|
|
97
|
+
}
|
|
98
|
+
/** 绝对路径(POSIX + Windows 盘符/UNC),跨平台评估时用 */
|
|
99
|
+
function isAbsolutePath(p) {
|
|
100
|
+
return (p.startsWith('/') ||
|
|
101
|
+
/^[A-Za-z]:[\\/]/.test(p) ||
|
|
102
|
+
/^[A-Za-z]:$/.test(p) ||
|
|
103
|
+
p.startsWith('\\\\'));
|
|
104
|
+
}
|
|
105
|
+
/** 去掉末尾分隔符(保留根 `/` 或 `C:\`) */
|
|
106
|
+
function stripTrailingSep(p) {
|
|
107
|
+
if (p.length > 1 && (p.endsWith('/') || p.endsWith('\\'))) {
|
|
108
|
+
// `C:\` 保留
|
|
109
|
+
if (/^[A-Za-z]:[\\/]$/.test(p))
|
|
110
|
+
return p;
|
|
111
|
+
return p.slice(0, -1);
|
|
112
|
+
}
|
|
113
|
+
return p;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 路径前缀匹配(路径段边界,拒绝 project 前缀绕过 project-evil)
|
|
117
|
+
*
|
|
118
|
+
* 要求 path === base 或 path 以 base + 分隔符 开头。
|
|
119
|
+
* Windows 风格路径大小写不敏感、分隔符归一为 `\`。
|
|
120
|
+
*/
|
|
121
|
+
function startsWithPathPrefix(path, prefix) {
|
|
122
|
+
const isWin = isWindowsStylePath(path) || isWindowsStylePath(prefix);
|
|
123
|
+
if (isWin) {
|
|
124
|
+
const p = stripTrailingSep(path.replace(/\//g, '\\')).toLowerCase();
|
|
125
|
+
const b = stripTrailingSep(prefix.replace(/\//g, '\\')).toLowerCase();
|
|
126
|
+
if (p === b)
|
|
127
|
+
return true;
|
|
128
|
+
return p.startsWith(b + '\\');
|
|
129
|
+
}
|
|
130
|
+
const p = stripTrailingSep(path);
|
|
131
|
+
const b = stripTrailingSep(prefix);
|
|
132
|
+
if (p === b)
|
|
133
|
+
return true;
|
|
134
|
+
return p.startsWith(b + '/');
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 路径段包含匹配:同时识别 `/` 与 `\`,要求段边界
|
|
138
|
+
*
|
|
139
|
+
* `.ssh` 匹配 `/home/x/.ssh` 与 `/home/x/.ssh/id_rsa`,
|
|
140
|
+
* 不匹配 `/home/x/.sshrc`。
|
|
141
|
+
* 支持多段模式如 `.config/gcloud`。
|
|
142
|
+
*/
|
|
143
|
+
function pathContainsSegment(path, segment) {
|
|
144
|
+
const unified = path.replace(/\\/g, '/');
|
|
145
|
+
const seg = segment.replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
|
|
146
|
+
if (!seg)
|
|
147
|
+
return false;
|
|
148
|
+
if (unified === seg)
|
|
149
|
+
return true;
|
|
150
|
+
if (unified.endsWith(`/${seg}`))
|
|
151
|
+
return true;
|
|
152
|
+
if (unified.includes(`/${seg}/`))
|
|
153
|
+
return true;
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 根级通配:`/` + `*`、`/` + `*`/`*`、`C:\*` — 与根/盘符根同级的不可逆损坏
|
|
158
|
+
* (注释避开字面 star-slash,避免提前闭合块注释)
|
|
159
|
+
*/
|
|
160
|
+
function isRootGlob(p) {
|
|
161
|
+
if (/^\/+\*(?:\/\*)*$/.test(p))
|
|
162
|
+
return true;
|
|
163
|
+
if (/^[A-Za-z]:[\\/]\*(?:[\\/]\*)*$/.test(p))
|
|
164
|
+
return true;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 分类目标路径的风险
|
|
169
|
+
*/
|
|
170
|
+
function classifyPath(path, cwd) {
|
|
171
|
+
// 规范化路径
|
|
172
|
+
const normalized = normalizePath(path, cwd);
|
|
173
|
+
// 根路径 / 盘符根 / 根级通配(不可逆损坏)
|
|
174
|
+
if (normalized === '/' || isDriveRoot(normalized) || isRootGlob(normalized)) {
|
|
175
|
+
return 'protected';
|
|
176
|
+
}
|
|
177
|
+
// 安全伪设备白名单(/dev/null 等)
|
|
178
|
+
if (SAFE_PSEUDO_DEVICES.has(normalized)) {
|
|
179
|
+
return 'safe';
|
|
180
|
+
}
|
|
181
|
+
// macOS APFS: /Users 是 firmlink → /System/Volumes/Data/Users
|
|
182
|
+
// 必须在 PROTECTED_PATHS('/System/') 检查之前豁免
|
|
183
|
+
if (normalized.startsWith('/System/Volumes/Data/Users/') ||
|
|
184
|
+
normalized.startsWith('/System/Volumes/Data/home/')) {
|
|
185
|
+
return 'normal';
|
|
186
|
+
}
|
|
187
|
+
// 临时目录 —— 必须在 PROTECTED 之前:
|
|
188
|
+
// C:\Windows\Temp 落在 C:\Windows\ 前缀内,若先判 protected 则 TEMP 白名单成死代码
|
|
189
|
+
if (getTempPrefixes().some(p => startsWithPathPrefix(normalized, p))) {
|
|
190
|
+
return 'safe';
|
|
191
|
+
}
|
|
192
|
+
// 系统保护路径
|
|
193
|
+
if (getProtectedPaths().some(p => startsWithPathPrefix(normalized, p))) {
|
|
194
|
+
return 'protected';
|
|
195
|
+
}
|
|
196
|
+
// 凭证目录
|
|
197
|
+
if (CREDENTIAL_DIRS.some(p => pathContainsSegment(normalized, p))) {
|
|
198
|
+
return 'sensitive';
|
|
199
|
+
}
|
|
200
|
+
// 项目目录(相对路径,或在 cwd 内)—— 段边界比较
|
|
201
|
+
if (!isAbsolutePath(normalized) || (cwd && startsWithPathPrefix(normalized, cwd))) {
|
|
202
|
+
return 'safe';
|
|
203
|
+
}
|
|
204
|
+
// 用户 home 目录(POSIX + Windows)
|
|
205
|
+
if (normalized.startsWith('/Users/') ||
|
|
206
|
+
normalized.startsWith('/home/') ||
|
|
207
|
+
/^[A-Za-z]:[\\/]Users[\\/]/i.test(normalized)) {
|
|
208
|
+
return 'normal';
|
|
209
|
+
}
|
|
210
|
+
// 其他绝对路径
|
|
211
|
+
return 'normal';
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 规范化路径(处理相对路径;折叠重复分隔符,拒绝 `//etc` 绕过)
|
|
215
|
+
*/
|
|
216
|
+
function normalizePath(path, cwd) {
|
|
217
|
+
// ~ 展开(POSIX ~/ 与 Windows ~\)
|
|
218
|
+
if (path === '~' || path.startsWith('~/') || path.startsWith('~\\')) {
|
|
219
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? homedir() ?? '/Users/unknown';
|
|
220
|
+
if (path === '~')
|
|
221
|
+
return home;
|
|
222
|
+
return resolve(home, path.slice(2));
|
|
223
|
+
}
|
|
224
|
+
let p = path;
|
|
225
|
+
if (p.startsWith('\\\\')) {
|
|
226
|
+
// UNC:只折叠 share 之后的重复分隔符
|
|
227
|
+
p = '\\\\' + p.slice(2).replace(/[\\/]{2,}/g, (m) => (m.includes('\\') ? '\\' : '/'));
|
|
228
|
+
}
|
|
229
|
+
else if (/^[A-Za-z]:/.test(p)) {
|
|
230
|
+
// 盘符路径:折叠重复 `\` 或 `/`
|
|
231
|
+
p = p.replace(/\\{2,}/g, '\\').replace(/\/{2,}/g, '/');
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
// POSIX:`//etc` → `/etc`
|
|
235
|
+
p = p.replace(/\/{2,}/g, '/');
|
|
236
|
+
}
|
|
237
|
+
if (isAbsolutePath(p) || !cwd) {
|
|
238
|
+
return p;
|
|
239
|
+
}
|
|
240
|
+
return resolve(cwd, p);
|
|
241
|
+
}
|
|
242
|
+
// ── 操作风险分类 ──
|
|
243
|
+
/** 命令名统一小写 + basename(`/bin/rm`、`RM.EXE` → `rm`) */
|
|
244
|
+
function cmdKey(cmd) {
|
|
245
|
+
const base = cmd.split(/[\\/]/).pop() ?? cmd;
|
|
246
|
+
return base.toLowerCase().replace(/\.exe$/i, '');
|
|
247
|
+
}
|
|
248
|
+
/** 只读命令 */
|
|
249
|
+
const READ_ONLY_COMMANDS = new Set([
|
|
250
|
+
'cat', 'head', 'tail', 'less', 'more',
|
|
251
|
+
'ls', 'dir', 'tree', 'find', 'locate',
|
|
252
|
+
'grep', 'egrep', 'fgrep', 'rg', 'ag',
|
|
253
|
+
'wc', 'diff', 'file', 'stat', 'du', 'df',
|
|
254
|
+
'echo', 'printf', 'date', 'whoami', 'id',
|
|
255
|
+
'pwd', 'which', 'whereis', 'type',
|
|
256
|
+
'env', 'printenv',
|
|
257
|
+
'uname', 'hostname', 'uptime', 'ps', 'top',
|
|
258
|
+
'man', 'info', 'help',
|
|
259
|
+
// Windows
|
|
260
|
+
'where', 'fc', 'comp',
|
|
261
|
+
]);
|
|
262
|
+
/** 删除命令 */
|
|
263
|
+
const DELETE_COMMANDS = new Set([
|
|
264
|
+
'rm', 'rmdir', 'unlink', 'shred',
|
|
265
|
+
// Windows / PowerShell
|
|
266
|
+
'del', 'erase', 'rd', 'remove-item', 'ri',
|
|
267
|
+
]);
|
|
268
|
+
/** 写入命令 */
|
|
269
|
+
const WRITE_COMMANDS = new Set([
|
|
270
|
+
'touch', 'mkdir', 'cp', 'mv', 'ln',
|
|
271
|
+
'install', 'chmod', 'chown', 'chgrp',
|
|
272
|
+
'tee', 'truncate',
|
|
273
|
+
// Windows / PowerShell
|
|
274
|
+
'copy', 'move', 'xcopy', 'robocopy', 'ren', 'rename',
|
|
275
|
+
'new-item', 'ni', 'set-content', 'add-content', 'out-file',
|
|
276
|
+
'echo.', 'md',
|
|
277
|
+
]);
|
|
278
|
+
/** 网络命令 */
|
|
279
|
+
const NETWORK_COMMANDS = new Set([
|
|
280
|
+
'curl', 'wget', 'http', 'https',
|
|
281
|
+
'nc', 'ncat', 'netcat',
|
|
282
|
+
'ssh', 'scp', 'rsync', 'sftp',
|
|
283
|
+
]);
|
|
284
|
+
/** 包管理命令 */
|
|
285
|
+
const PACKAGE_COMMANDS = new Set([
|
|
286
|
+
'npm', 'yarn', 'pnpm', 'pip', 'pip3',
|
|
287
|
+
'brew', 'apt', 'apt-get', 'yum', 'dnf',
|
|
288
|
+
'gem', 'cargo', 'go',
|
|
289
|
+
]);
|
|
290
|
+
/** 构建/执行命令(需要关注参数) */
|
|
291
|
+
const BUILD_COMMANDS = new Set([
|
|
292
|
+
'make', 'cmake', 'gradle', 'mvn', 'ant',
|
|
293
|
+
'docker', 'podman',
|
|
294
|
+
]);
|
|
295
|
+
/** 解释器命令(内联代码执行) */
|
|
296
|
+
const INTERPRETER_COMMANDS = new Set([
|
|
297
|
+
'python', 'python3', 'ruby', 'perl', 'node', 'php',
|
|
298
|
+
'lua', 'tclsh', 'rscript', 'scala', 'groovy',
|
|
299
|
+
'bash', 'sh', 'zsh',
|
|
300
|
+
// Windows
|
|
301
|
+
'powershell', 'powershell.exe', 'pwsh', 'pwsh.exe',
|
|
302
|
+
'cmd', 'cmd.exe',
|
|
303
|
+
]);
|
|
304
|
+
/** 提权命令 — 通过 seg.isSudo 判断,此 Set 保留备用 */
|
|
305
|
+
// const PRIVILEGE_COMMANDS = new Set(['sudo', 'su']);
|
|
306
|
+
// ── 风险评估 ──
|
|
307
|
+
/**
|
|
308
|
+
* 评估工具调用的风险
|
|
309
|
+
*
|
|
310
|
+
* @param call - 工具调用
|
|
311
|
+
* @param context - 上下文信息(可选)
|
|
312
|
+
* @returns 风险决策
|
|
313
|
+
*/
|
|
314
|
+
export function evaluateRisk(call, context) {
|
|
315
|
+
// 只有 shell 工具需要深度评估
|
|
316
|
+
if (!isShellTool(call.name)) {
|
|
317
|
+
return evaluateNonShellTool(call);
|
|
318
|
+
}
|
|
319
|
+
const command = getCommandString(call);
|
|
320
|
+
if (!command) {
|
|
321
|
+
return { level: 'unknown', factors: [], reason: '无法提取命令字符串' };
|
|
322
|
+
}
|
|
323
|
+
return evaluateShellCommand(command, context?.cwd);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* 评估 Shell 命令的风险
|
|
327
|
+
*/
|
|
328
|
+
export function evaluateShellCommand(command, cwd) {
|
|
329
|
+
const parsed = parseShellCommand(command);
|
|
330
|
+
const factors = [];
|
|
331
|
+
if (!parsed.parsed) {
|
|
332
|
+
return {
|
|
333
|
+
level: 'unknown',
|
|
334
|
+
factors: [{ source: 'method', description: '命令解析失败', level: 'unknown' }],
|
|
335
|
+
reason: '命令结构过于复杂,无法确定性解析',
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
// 1. 检测特殊模式(管道到解释器、内联代码、子 shell)
|
|
339
|
+
if (parsed.hasShellPipe) {
|
|
340
|
+
factors.push({
|
|
341
|
+
source: 'method',
|
|
342
|
+
description: '管道到解释器(执行外部代码)',
|
|
343
|
+
level: 'high',
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (parsed.hasSubshell) {
|
|
347
|
+
factors.push({
|
|
348
|
+
source: 'method',
|
|
349
|
+
description: '子 shell 执行',
|
|
350
|
+
level: 'medium',
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
// 内联代码:按载荷内容分档,不再「见到 -c 就 high」
|
|
354
|
+
// python -c "print(1)" 与写脚本再执行能力等价,应同档;
|
|
355
|
+
// 真正危险的是载荷里的系统调用/破坏/外联,由 evaluateInlineCodeRisk 抬升。
|
|
356
|
+
if (parsed.hasInlineCode) {
|
|
357
|
+
factors.push(...evaluateInlineCodeRisk(parsed, cwd));
|
|
358
|
+
}
|
|
359
|
+
// 2. 评估每个命令段
|
|
360
|
+
for (const seg of parsed.segments) {
|
|
361
|
+
const segRisk = evaluateSegment(seg, cwd);
|
|
362
|
+
factors.push(...segRisk);
|
|
363
|
+
}
|
|
364
|
+
// 3. 评估重定向目标
|
|
365
|
+
const redirectTargets = getRedirectTargets(parsed);
|
|
366
|
+
for (const target of redirectTargets) {
|
|
367
|
+
const pathRisk = classifyPath(target, cwd);
|
|
368
|
+
const pathFactor = evaluatePathRisk(target, pathRisk);
|
|
369
|
+
if (pathFactor) {
|
|
370
|
+
factors.push(pathFactor);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
// 4. 评估组合风险(多个高风险命令串联)
|
|
374
|
+
if (parsed.segments.length > 1) {
|
|
375
|
+
const highRiskSegments = parsed.segments.filter(s => {
|
|
376
|
+
const k = cmdKey(s.command);
|
|
377
|
+
return DELETE_COMMANDS.has(k) || k === 'chmod' || k === 'chown';
|
|
378
|
+
});
|
|
379
|
+
if (highRiskSegments.length > 1) {
|
|
380
|
+
factors.push({
|
|
381
|
+
source: 'combination',
|
|
382
|
+
description: `多个高风险命令串联: ${highRiskSegments.map(s => s.command).join(', ')}`,
|
|
383
|
+
level: 'high',
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
// 5. 计算整体风险等级
|
|
388
|
+
const level = computeOverallRisk(factors);
|
|
389
|
+
return {
|
|
390
|
+
level,
|
|
391
|
+
factors,
|
|
392
|
+
reason: buildReason(level, factors),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
// ── 段评估 ──
|
|
396
|
+
/** 递归/子树删除标记:rm -r/-rf、PowerShell -Recurse[=…]、cmd del /s */
|
|
397
|
+
function hasRecursiveFlag(args) {
|
|
398
|
+
return args.some((a) => {
|
|
399
|
+
const lower = a.toLowerCase();
|
|
400
|
+
return (lower === '-r' || lower === '-rf' || lower === '-fr' ||
|
|
401
|
+
lower === '--recursive' || lower === '-recurse' ||
|
|
402
|
+
lower.startsWith('-recurse:') || lower.startsWith('--recursive:') ||
|
|
403
|
+
lower === '/s' || lower === '-s');
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/** 是否为 chmod/chown 类权限变更 */
|
|
407
|
+
function isPermChange(cmd) {
|
|
408
|
+
const k = cmdKey(cmd);
|
|
409
|
+
return k === 'chmod' || k === 'chown';
|
|
410
|
+
}
|
|
411
|
+
function evaluateSegment(seg, cwd) {
|
|
412
|
+
const factors = [];
|
|
413
|
+
const cmd = seg.command;
|
|
414
|
+
const key = cmdKey(cmd);
|
|
415
|
+
// 提权
|
|
416
|
+
if (seg.isSudo) {
|
|
417
|
+
factors.push({
|
|
418
|
+
source: 'operation',
|
|
419
|
+
description: `提权执行: sudo ${cmd}`,
|
|
420
|
+
level: 'high',
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
// 只读命令 → 低风险
|
|
424
|
+
if (READ_ONLY_COMMANDS.has(key)) {
|
|
425
|
+
factors.push({
|
|
426
|
+
source: 'operation',
|
|
427
|
+
description: `只读操作: ${cmd}`,
|
|
428
|
+
level: 'low',
|
|
429
|
+
});
|
|
430
|
+
return factors; // 只读不需要进一步评估目标
|
|
431
|
+
}
|
|
432
|
+
// 删除命令
|
|
433
|
+
if (DELETE_COMMANDS.has(key)) {
|
|
434
|
+
const recursive = hasRecursiveFlag(seg.args);
|
|
435
|
+
// 过滤选项;Windows 选项以 / 开头但路径也可能是 /(POSIX),保留绝对路径
|
|
436
|
+
const targets = seg.args.filter((a) => {
|
|
437
|
+
if (a.startsWith('-'))
|
|
438
|
+
return false;
|
|
439
|
+
// cmd/PowerShell 选项:/s /q /f 等(单字母或短选项),排除看起来像路径的
|
|
440
|
+
if (/^\/[a-zA-Z?]$/.test(a) || /^\/(recurse|force|quiet)$/i.test(a))
|
|
441
|
+
return false;
|
|
442
|
+
return true;
|
|
443
|
+
});
|
|
444
|
+
for (const target of targets) {
|
|
445
|
+
const pathRisk = classifyPath(target, cwd);
|
|
446
|
+
factors.push({
|
|
447
|
+
source: 'target',
|
|
448
|
+
description: `删除 ${recursive ? '(递归) ' : ''}目标: ${target} (${pathRisk})`,
|
|
449
|
+
level: evaluateDeleteRisk(pathRisk, recursive),
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return factors;
|
|
453
|
+
}
|
|
454
|
+
// 写入命令 — 与删除同构:评估目标路径(protected→critical, sensitive→high)
|
|
455
|
+
if (WRITE_COMMANDS.has(key)) {
|
|
456
|
+
const recursive = hasRecursiveFlag(seg.args);
|
|
457
|
+
const targets = seg.args.filter((a) => {
|
|
458
|
+
if (a.startsWith('-'))
|
|
459
|
+
return false;
|
|
460
|
+
if (/^\/[a-zA-Z?]$/.test(a) || /^\/(recurse|force|quiet|y)$/i.test(a))
|
|
461
|
+
return false;
|
|
462
|
+
// chmod 模式数字不是路径
|
|
463
|
+
if (/^\d{3,4}$/.test(a))
|
|
464
|
+
return false;
|
|
465
|
+
return true;
|
|
466
|
+
});
|
|
467
|
+
for (const target of targets) {
|
|
468
|
+
const pathRisk = classifyPath(target, cwd);
|
|
469
|
+
factors.push({
|
|
470
|
+
source: 'target',
|
|
471
|
+
description: `写入 ${recursive ? '(递归) ' : ''}目标: ${target} (${pathRisk})`,
|
|
472
|
+
level: evaluateDeleteRisk(pathRisk, recursive),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
factors.push({
|
|
476
|
+
source: 'operation',
|
|
477
|
+
description: `写入操作: ${cmd}`,
|
|
478
|
+
level: 'low',
|
|
479
|
+
});
|
|
480
|
+
return factors;
|
|
481
|
+
}
|
|
482
|
+
// 网络命令
|
|
483
|
+
if (NETWORK_COMMANDS.has(key)) {
|
|
484
|
+
if (key === 'curl' || key === 'wget') {
|
|
485
|
+
// 检查是否有 POST 数据
|
|
486
|
+
const hasPost = seg.args.some(a => a === '-X' || a === '--request' || a === '-d' || a === '--data' || a === '--data-binary');
|
|
487
|
+
if (hasPost) {
|
|
488
|
+
factors.push({
|
|
489
|
+
source: 'operation',
|
|
490
|
+
description: `网络外发: ${cmd} (POST)`,
|
|
491
|
+
level: 'medium',
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
factors.push({
|
|
496
|
+
source: 'operation',
|
|
497
|
+
description: `网络请求: ${cmd} (GET)`,
|
|
498
|
+
level: 'low',
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
factors.push({
|
|
504
|
+
source: 'operation',
|
|
505
|
+
description: `网络操作: ${cmd}`,
|
|
506
|
+
level: 'medium',
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
return factors;
|
|
510
|
+
}
|
|
511
|
+
// 包管理命令
|
|
512
|
+
if (PACKAGE_COMMANDS.has(key)) {
|
|
513
|
+
if (seg.isSudo) {
|
|
514
|
+
factors.push({
|
|
515
|
+
source: 'operation',
|
|
516
|
+
description: `提权包管理: sudo ${cmd}`,
|
|
517
|
+
level: 'high',
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
factors.push({
|
|
522
|
+
source: 'operation',
|
|
523
|
+
description: `包管理: ${cmd}`,
|
|
524
|
+
level: 'low',
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
return factors;
|
|
528
|
+
}
|
|
529
|
+
// Git 命令
|
|
530
|
+
if (key === 'git') {
|
|
531
|
+
const subcmd = seg.args[0];
|
|
532
|
+
if (subcmd === 'push' && seg.args.includes('--force')) {
|
|
533
|
+
factors.push({
|
|
534
|
+
source: 'operation',
|
|
535
|
+
description: 'Git force push(建议用 --force-with-lease)',
|
|
536
|
+
level: 'medium',
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
else if (subcmd === 'clean' && seg.args.includes('-f')) {
|
|
540
|
+
factors.push({
|
|
541
|
+
source: 'operation',
|
|
542
|
+
description: 'Git clean -f(删除未跟踪文件)',
|
|
543
|
+
level: 'medium',
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
factors.push({
|
|
548
|
+
source: 'operation',
|
|
549
|
+
description: `Git 操作: git ${subcmd}`,
|
|
550
|
+
level: 'low',
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return factors;
|
|
554
|
+
}
|
|
555
|
+
// 构建/容器命令(需要关注参数)
|
|
556
|
+
if (BUILD_COMMANDS.has(key)) {
|
|
557
|
+
if (key === 'docker' && seg.args[0] === 'run') {
|
|
558
|
+
factors.push({
|
|
559
|
+
source: 'operation',
|
|
560
|
+
description: 'Docker run(容器执行)',
|
|
561
|
+
level: 'medium',
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
factors.push({
|
|
566
|
+
source: 'operation',
|
|
567
|
+
description: `构建/容器操作: ${cmd}`,
|
|
568
|
+
level: 'low',
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
return factors;
|
|
572
|
+
}
|
|
573
|
+
// 解释器命令(无 -c/-e 时视为低风险,有内联代码时由 hasInlineCode 处理)
|
|
574
|
+
if (INTERPRETER_COMMANDS.has(key)) {
|
|
575
|
+
factors.push({
|
|
576
|
+
source: 'operation',
|
|
577
|
+
description: `解释器执行: ${cmd}`,
|
|
578
|
+
level: 'low',
|
|
579
|
+
});
|
|
580
|
+
return factors;
|
|
581
|
+
}
|
|
582
|
+
// 未知命令 → 交给 LLM
|
|
583
|
+
factors.push({
|
|
584
|
+
source: 'operation',
|
|
585
|
+
description: `未知命令: ${cmd}`,
|
|
586
|
+
level: 'unknown',
|
|
587
|
+
});
|
|
588
|
+
return factors;
|
|
589
|
+
}
|
|
590
|
+
// ── 路径风险评估 ──
|
|
591
|
+
function evaluateDeleteRisk(pathRisk, recursive) {
|
|
592
|
+
switch (pathRisk) {
|
|
593
|
+
case 'protected': return 'critical';
|
|
594
|
+
case 'sensitive': return 'high';
|
|
595
|
+
case 'safe': return 'low';
|
|
596
|
+
case 'normal': return recursive ? 'medium' : 'low';
|
|
597
|
+
default: return 'medium';
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function evaluatePathRisk(path, pathRisk) {
|
|
601
|
+
if (pathRisk === 'safe')
|
|
602
|
+
return null; // 安全路径不需要额外标记
|
|
603
|
+
const levels = {
|
|
604
|
+
safe: 'low',
|
|
605
|
+
normal: 'low',
|
|
606
|
+
sensitive: 'high',
|
|
607
|
+
protected: 'critical',
|
|
608
|
+
};
|
|
609
|
+
return {
|
|
610
|
+
source: 'target',
|
|
611
|
+
description: `目标路径: ${path} (${pathRisk})`,
|
|
612
|
+
level: levels[pathRisk],
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
// ── 硬边界探测(DefaultSecurityGuard 调用;不受 enforce 影响) ──
|
|
616
|
+
/**
|
|
617
|
+
* 路径是否落在保护区(根 / 盘符根 / 系统核心目录)
|
|
618
|
+
*
|
|
619
|
+
* @param path - 目标路径
|
|
620
|
+
* @param cwd - 可选工作目录(解析相对路径)
|
|
621
|
+
* @returns 是否为 protected 路径
|
|
622
|
+
*/
|
|
623
|
+
export function isProtectedPath(path, cwd) {
|
|
624
|
+
return classifyPath(path, cwd) === 'protected';
|
|
625
|
+
}
|
|
626
|
+
/** 删除命令目标参数(过滤选项;保留路径) */
|
|
627
|
+
function extractDeleteTargets(args) {
|
|
628
|
+
return args.filter((a) => {
|
|
629
|
+
if (a.startsWith('-'))
|
|
630
|
+
return false;
|
|
631
|
+
// cmd/PowerShell 选项:/s /q /f 等(单字母或短选项),排除看起来像路径的
|
|
632
|
+
if (/^\/[a-zA-Z?]$/.test(a) || /^\/(recurse|force|quiet)$/i.test(a))
|
|
633
|
+
return false;
|
|
634
|
+
return true;
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* 解释器内联脚本参数(python -c / node -e / powershell -Command / cmd /c / bash -c …)
|
|
639
|
+
*
|
|
640
|
+
* 这些形态下真实代码在参数串里,而不是 seg.command。
|
|
641
|
+
* 必须覆盖 skill 常用的 python -c,否则载荷探测会漏掉。
|
|
642
|
+
*/
|
|
643
|
+
const INTERPRETER_INLINE_FLAGS = {
|
|
644
|
+
'python': ['-c'],
|
|
645
|
+
'python3': ['-c'],
|
|
646
|
+
'node': ['-e', '--eval'],
|
|
647
|
+
'ruby': ['-e'],
|
|
648
|
+
'perl': ['-e'],
|
|
649
|
+
'php': ['-r'],
|
|
650
|
+
'powershell': ['-command', '-c'],
|
|
651
|
+
'powershell.exe': ['-command', '-c'],
|
|
652
|
+
'pwsh': ['-command', '-c'],
|
|
653
|
+
'pwsh.exe': ['-command', '-c'],
|
|
654
|
+
'cmd': ['/c', '/k'],
|
|
655
|
+
'cmd.exe': ['/c', '/k'],
|
|
656
|
+
'bash': ['-c'],
|
|
657
|
+
'sh': ['-c'],
|
|
658
|
+
'zsh': ['-c'],
|
|
659
|
+
};
|
|
660
|
+
/** 无法确定性解码的内联形态(-EncodedCommand 等)— 载荷不可审计 → 保持 high */
|
|
661
|
+
const UNINSPECTABLE_INLINE_FLAGS = new Set([
|
|
662
|
+
'-encodedcommand',
|
|
663
|
+
'-encodedcommand'.toUpperCase(),
|
|
664
|
+
'-e', // pwsh -e 与 node -e 歧义;Encod 语义下保守
|
|
665
|
+
]);
|
|
666
|
+
/**
|
|
667
|
+
* 内联载荷中的危险 API / 破坏 / 外联模式(确定性子串/词界匹配,不引入 LLM)
|
|
668
|
+
*
|
|
669
|
+
* 原则:与「写脚本再执行」同权——脚本文件里的这些调用同样是 high,
|
|
670
|
+
* 只是当前对脚本文件不做内容扫描;内联形态因载荷在参数里,可以廉价探测。
|
|
671
|
+
*/
|
|
672
|
+
const INLINE_DANGEROUS_PATTERNS = [
|
|
673
|
+
// 进程 / 任意命令执行
|
|
674
|
+
{ re: /\bos\.system\b/i, description: 'os.system', level: 'high' },
|
|
675
|
+
{ re: /\bsubprocess\b/i, description: 'subprocess', level: 'high' },
|
|
676
|
+
{ re: /\b(eval|exec)\s*\(/i, description: 'eval/exec', level: 'high' },
|
|
677
|
+
{ re: /\b__import__\s*\(/i, description: '__import__', level: 'high' },
|
|
678
|
+
{ re: /\b(shell\s*=\s*True)\b/i, description: 'shell=True', level: 'high' },
|
|
679
|
+
{ re: /\b(Invoke-Expression|IEX)\b/i, description: 'Invoke-Expression', level: 'high' },
|
|
680
|
+
// 破坏性文件操作
|
|
681
|
+
{ re: /\bshutil\.rmtree\b/i, description: 'shutil.rmtree', level: 'high' },
|
|
682
|
+
{ re: /\bos\.(remove|unlink|rmdir)\b/i, description: 'os.remove/unlink/rmdir', level: 'high' },
|
|
683
|
+
{ re: /\bRemove-Item\b/i, description: 'Remove-Item', level: 'high' },
|
|
684
|
+
{ re: /\b(rm|del|rd)\s+(-[a-zA-Z]+\s+)*[/\\]/, description: 'absolute-path delete', level: 'high' },
|
|
685
|
+
// 外联 / 数据外带
|
|
686
|
+
{ re: /\b(socket|requests|urllib|httpx|aiohttp)\b/i, description: 'network library', level: 'medium' },
|
|
687
|
+
{ re: /\b(curl|wget)\b/i, description: 'download helper', level: 'medium' },
|
|
688
|
+
// 写系统路径
|
|
689
|
+
{ re: /(?:C:\\\\Windows|C:\/Windows|\/etc\/|\/usr\/|C:\\\\Program\s+Files)/i, description: 'system path in payload', level: 'high' },
|
|
690
|
+
];
|
|
691
|
+
/**
|
|
692
|
+
* 内联代码风险分档
|
|
693
|
+
*
|
|
694
|
+
* - 载荷可提取:基线 medium(与脚本文件同权);命中危险模式按模式抬升
|
|
695
|
+
* - 载荷不可审计(-EncodedCommand):保持 high
|
|
696
|
+
* - 载荷含保护路径 + 破坏语义:critical(由 detectCatastrophic 之外的组合判定)
|
|
697
|
+
*
|
|
698
|
+
* @param parsed - 解析后的命令
|
|
699
|
+
* @param cwd - 可选工作目录(保护路径判定)
|
|
700
|
+
* @returns 风险因子列表
|
|
701
|
+
*/
|
|
702
|
+
function evaluateInlineCodeRisk(parsed, cwd) {
|
|
703
|
+
const factors = [];
|
|
704
|
+
let sawInspectable = false;
|
|
705
|
+
let maxLevel = 'low';
|
|
706
|
+
const hitDescriptions = [];
|
|
707
|
+
for (const seg of parsed.segments) {
|
|
708
|
+
// 不可审计形态(-EncodedCommand 等)
|
|
709
|
+
const uninspectable = seg.args.some((a) => {
|
|
710
|
+
const lower = a.toLowerCase();
|
|
711
|
+
if (lower === '-encodedcommand' || lower === '-enc')
|
|
712
|
+
return true;
|
|
713
|
+
// pwsh -e <base64> 且载荷无法确定性解码
|
|
714
|
+
if (UNINSPECTABLE_INLINE_FLAGS.has(lower) && cmdKey(seg.command).includes('pwsh')) {
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
717
|
+
return false;
|
|
718
|
+
});
|
|
719
|
+
if (uninspectable) {
|
|
720
|
+
factors.push({
|
|
721
|
+
source: 'method',
|
|
722
|
+
description: '内联代码不可审计(EncodedCommand 等)',
|
|
723
|
+
level: 'high',
|
|
724
|
+
});
|
|
725
|
+
maxLevel = 'high';
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
for (const payload of extractInlinePayloads(seg)) {
|
|
729
|
+
sawInspectable = true;
|
|
730
|
+
for (const pattern of INLINE_DANGEROUS_PATTERNS) {
|
|
731
|
+
if (pattern.re.test(payload)) {
|
|
732
|
+
hitDescriptions.push(pattern.description);
|
|
733
|
+
if (RISK_ORDER[pattern.level] > RISK_ORDER[maxLevel]) {
|
|
734
|
+
maxLevel = pattern.level;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
// 载荷内保护路径 + 删除语义 → critical
|
|
739
|
+
if (/\b(rm|Remove-Item|del|rd|shutil\.rmtree|os\.remove)\b/i.test(payload)) {
|
|
740
|
+
for (const m of payload.matchAll(/[A-Za-z]:[\\/][^\s"']+|\/(?:etc|usr|bin|sbin|System)[^\s"']*/g)) {
|
|
741
|
+
if (isProtectedPath(m[0], cwd)) {
|
|
742
|
+
hitDescriptions.push(`destructive op on protected path: ${m[0]}`);
|
|
743
|
+
maxLevel = 'critical';
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
if (!sawInspectable && maxLevel === 'low') {
|
|
750
|
+
// hasInlineCode 为真但没能抽出载荷:保守 medium(不是 high)
|
|
751
|
+
factors.push({
|
|
752
|
+
source: 'method',
|
|
753
|
+
description: '内联代码执行(载荷未能完整提取)',
|
|
754
|
+
level: 'medium',
|
|
755
|
+
});
|
|
756
|
+
return factors;
|
|
757
|
+
}
|
|
758
|
+
if (hitDescriptions.length > 0) {
|
|
759
|
+
factors.push({
|
|
760
|
+
source: 'method',
|
|
761
|
+
description: `内联代码载荷命中危险模式: ${hitDescriptions.join(', ')}`,
|
|
762
|
+
level: maxLevel,
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
// 可审计且无危险模式:与 python script.py 同权
|
|
767
|
+
factors.push({
|
|
768
|
+
source: 'method',
|
|
769
|
+
description: '内联代码执行(载荷已审计,无危险模式)',
|
|
770
|
+
level: 'medium',
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
return factors;
|
|
774
|
+
}
|
|
775
|
+
/** 提取解释器内联脚本文本(跳过 -EncodedCommand 等无法确定性解码的形态) */
|
|
776
|
+
function extractInlinePayloads(seg) {
|
|
777
|
+
const flags = INTERPRETER_INLINE_FLAGS[cmdKey(seg.command)];
|
|
778
|
+
if (!flags)
|
|
779
|
+
return [];
|
|
780
|
+
for (let i = 0; i < seg.args.length; i++) {
|
|
781
|
+
const arg = seg.args[i].toLowerCase();
|
|
782
|
+
if (!flags.includes(arg))
|
|
783
|
+
continue;
|
|
784
|
+
// 脚本可能是单 token(引号包一串),也可能是 flag 后其余参数:cmd /c rd /s /q C:\
|
|
785
|
+
const rest = seg.args.slice(i + 1).join(' ').trim();
|
|
786
|
+
return rest ? [rest] : [];
|
|
787
|
+
}
|
|
788
|
+
return [];
|
|
789
|
+
}
|
|
790
|
+
function detectCatastrophicRecursiveDeleteInSegments(segments, cwd, depth) {
|
|
791
|
+
for (const seg of segments) {
|
|
792
|
+
// 解释器内联:powershell -Command "Remove-Item -Recurse C:\Windows"
|
|
793
|
+
if (depth < 3) {
|
|
794
|
+
for (const payload of extractInlinePayloads(seg)) {
|
|
795
|
+
const inner = parseShellCommand(payload);
|
|
796
|
+
if (inner.parsed) {
|
|
797
|
+
const hit = detectCatastrophicRecursiveDeleteInSegments(inner.segments, cwd, depth + 1);
|
|
798
|
+
if (hit)
|
|
799
|
+
return hit;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
const key = cmdKey(seg.command);
|
|
804
|
+
if (!DELETE_COMMANDS.has(key))
|
|
805
|
+
continue;
|
|
806
|
+
if (!hasRecursiveFlag(seg.args))
|
|
807
|
+
continue;
|
|
808
|
+
for (const target of extractDeleteTargets(seg.args)) {
|
|
809
|
+
if (isProtectedPath(target, cwd)) {
|
|
810
|
+
return `递归删除保护路径: ${target}`;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* 硬边界:递归删除根 / 盘符根 / 系统保护路径
|
|
818
|
+
*
|
|
819
|
+
* 确定灾难、不可逆,无论上下文都应拦;不受 `enforce: audit` 影响。
|
|
820
|
+
* 覆盖 POSIX rm 与 Windows:rd/del/Remove-Item/ri,以及
|
|
821
|
+
* `powershell -Command` / `cmd /c` 内联形态。
|
|
822
|
+
* 项目内目录、临时区、非递归删单文件仍归 RiskPolicy 分档。
|
|
823
|
+
*
|
|
824
|
+
* @param command - shell 命令串
|
|
825
|
+
* @param cwd - 可选工作目录
|
|
826
|
+
* @returns 命中时返回描述,否则 null
|
|
827
|
+
*/
|
|
828
|
+
export function detectCatastrophicRecursiveDelete(command, cwd) {
|
|
829
|
+
const parsed = parseShellCommand(command);
|
|
830
|
+
if (!parsed.parsed)
|
|
831
|
+
return null;
|
|
832
|
+
return detectCatastrophicRecursiveDeleteInSegments(parsed.segments, cwd, 0);
|
|
833
|
+
}
|
|
834
|
+
/** 管道/链上的解释器(basename) */
|
|
835
|
+
const INTERPRETER_BASES = new Set([
|
|
836
|
+
'sh', 'bash', 'zsh', 'dash', 'ksh', 'fish', 'ash',
|
|
837
|
+
'python', 'python3', 'ruby', 'perl', 'node', 'php',
|
|
838
|
+
'lua', 'tclsh', 'rscript', 'scala', 'groovy',
|
|
839
|
+
'powershell', 'pwsh', 'cmd',
|
|
840
|
+
]);
|
|
841
|
+
/** 下载源命令 basename */
|
|
842
|
+
const DOWNLOAD_BASES = new Set(['curl', 'wget', 'http', 'https']);
|
|
843
|
+
/** 解释器前的合法 wrapper(不改变 RCE 语义) */
|
|
844
|
+
const EXEC_WRAPPER_BASES = new Set(['sudo', 'env', 'nice', 'nohup', 'exec', 'xargs', 'time']);
|
|
845
|
+
/**
|
|
846
|
+
* 硬边界:下载并执行(管道链上同时出现下载源与解释器)
|
|
847
|
+
*
|
|
848
|
+
* 覆盖 `curl|bash`、`curl|/bin/bash`、`curl|env bash`、`curl|tee x|bash`。
|
|
849
|
+
* 仅下载(`curl -o file`)或普通管道(`cat|grep`)不命中。
|
|
850
|
+
*/
|
|
851
|
+
export function detectDownloadToInterpreter(command) {
|
|
852
|
+
const parsed = parseShellCommand(command);
|
|
853
|
+
if (!parsed.parsed || parsed.segments.length < 2)
|
|
854
|
+
return null;
|
|
855
|
+
let hasDownload = false;
|
|
856
|
+
let hasInterpreter = false;
|
|
857
|
+
for (const seg of parsed.segments) {
|
|
858
|
+
// 包装链:env / nice / xargs 后的真实命令
|
|
859
|
+
let key = cmdKey(seg.command);
|
|
860
|
+
if (EXEC_WRAPPER_BASES.has(key) && seg.args.length > 0) {
|
|
861
|
+
const next = seg.args.find((a) => !a.startsWith('-') && !a.includes('='));
|
|
862
|
+
if (next)
|
|
863
|
+
key = cmdKey(next);
|
|
864
|
+
}
|
|
865
|
+
if (DOWNLOAD_BASES.has(key))
|
|
866
|
+
hasDownload = true;
|
|
867
|
+
if (INTERPRETER_BASES.has(key))
|
|
868
|
+
hasInterpreter = true;
|
|
869
|
+
}
|
|
870
|
+
if (hasDownload && hasInterpreter) {
|
|
871
|
+
return 'download pipe to interpreter (remote code execution)';
|
|
872
|
+
}
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
/** 格式化 / 清盘命令 basename */
|
|
876
|
+
function isDiskWipeCommand(cmd, args) {
|
|
877
|
+
const key = cmdKey(cmd);
|
|
878
|
+
if (key.startsWith('mkfs'))
|
|
879
|
+
return true;
|
|
880
|
+
if (key === 'format-volume' || key === 'clear-disk')
|
|
881
|
+
return true;
|
|
882
|
+
if (key === 'format') {
|
|
883
|
+
// Windows `format C:` — 盘符目标
|
|
884
|
+
return args.some((a) => /^[a-z]:/i.test(a));
|
|
885
|
+
}
|
|
886
|
+
if (key === 'diskutil') {
|
|
887
|
+
return args.some((a) => /^erase(disk|volume)$/i.test(a));
|
|
888
|
+
}
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* 硬边界:格式化 / 清盘(命令位判定,避免 `echo format C:` 误杀)
|
|
893
|
+
*/
|
|
894
|
+
export function detectDiskWipe(command) {
|
|
895
|
+
const parsed = parseShellCommand(command);
|
|
896
|
+
if (!parsed.parsed)
|
|
897
|
+
return null;
|
|
898
|
+
for (const seg of parsed.segments) {
|
|
899
|
+
if (isDiskWipeCommand(seg.command, seg.args)) {
|
|
900
|
+
return `disk wipe: ${seg.command}`;
|
|
901
|
+
}
|
|
902
|
+
if (detectDiskWipeInInline(seg)) {
|
|
903
|
+
return `disk wipe in inline script: ${seg.command}`;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
function detectDiskWipeInInline(seg) {
|
|
909
|
+
const payloads = extractInlinePayloads(seg);
|
|
910
|
+
for (const payload of payloads) {
|
|
911
|
+
const inner = parseShellCommand(payload);
|
|
912
|
+
if (!inner.parsed)
|
|
913
|
+
continue;
|
|
914
|
+
for (const s of inner.segments) {
|
|
915
|
+
if (isDiskWipeCommand(s.command, s.args))
|
|
916
|
+
return true;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
// ── 非 Shell 工具评估 ──
|
|
922
|
+
export function evaluateNonShellTool(call) {
|
|
923
|
+
// 文件工具(读写分档:写保护路径 critical,读保护路径 high)
|
|
924
|
+
if (isFileTool(call.name)) {
|
|
925
|
+
const path = (call.arguments?.path ?? call.arguments?.file ?? call.arguments?.filename ?? '');
|
|
926
|
+
if (path) {
|
|
927
|
+
const pathRisk = classifyPath(path);
|
|
928
|
+
const isWrite = isFileWriteTool(call.name);
|
|
929
|
+
if (pathRisk === 'protected') {
|
|
930
|
+
// 写系统路径 = 不可逆损坏;读/列目录 = 高风险但非破坏
|
|
931
|
+
const level = isWrite ? 'critical' : 'high';
|
|
932
|
+
return {
|
|
933
|
+
level,
|
|
934
|
+
factors: [{
|
|
935
|
+
source: 'target',
|
|
936
|
+
description: `${isWrite ? '写入' : '读取'}保护路径: ${path}`,
|
|
937
|
+
level,
|
|
938
|
+
}],
|
|
939
|
+
reason: `${isWrite ? '写入' : '读取'}保护路径 ${path}`,
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
if (pathRisk === 'sensitive') {
|
|
943
|
+
return {
|
|
944
|
+
level: 'high',
|
|
945
|
+
factors: [{
|
|
946
|
+
source: 'target',
|
|
947
|
+
description: `${isWrite ? '写入' : '读取'}凭证目录: ${path}`,
|
|
948
|
+
level: 'high',
|
|
949
|
+
}],
|
|
950
|
+
reason: `访问凭证目录 ${path},可能泄露敏感信息`,
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return { level: 'low', factors: [], reason: '文件操作,目标路径安全' };
|
|
955
|
+
}
|
|
956
|
+
// HTTP 工具
|
|
957
|
+
if (isHttpTool(call.name)) {
|
|
958
|
+
const method = (call.arguments?.method ?? 'GET').toUpperCase();
|
|
959
|
+
if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
|
|
960
|
+
return {
|
|
961
|
+
level: 'medium',
|
|
962
|
+
factors: [{ source: 'operation', description: `${method} 请求`, level: 'medium' }],
|
|
963
|
+
reason: `${method} 请求可能发送数据`,
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
return { level: 'low', factors: [], reason: 'GET 请求' };
|
|
967
|
+
}
|
|
968
|
+
// 其他工具
|
|
969
|
+
return { level: 'low', factors: [], reason: '非 shell 工具' };
|
|
970
|
+
}
|
|
971
|
+
// ── 整体风险计算 ──
|
|
972
|
+
const RISK_ORDER = {
|
|
973
|
+
low: 0,
|
|
974
|
+
medium: 1,
|
|
975
|
+
high: 2,
|
|
976
|
+
critical: 3,
|
|
977
|
+
unknown: 99,
|
|
978
|
+
};
|
|
979
|
+
function computeOverallRisk(factors) {
|
|
980
|
+
if (factors.length === 0)
|
|
981
|
+
return 'low';
|
|
982
|
+
let maxLevel = 'low';
|
|
983
|
+
let hasUnknown = false;
|
|
984
|
+
for (const factor of factors) {
|
|
985
|
+
if (factor.level === 'unknown') {
|
|
986
|
+
hasUnknown = true;
|
|
987
|
+
}
|
|
988
|
+
else if (RISK_ORDER[factor.level] > RISK_ORDER[maxLevel]) {
|
|
989
|
+
maxLevel = factor.level;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
// 如果有任何 unknown 因素,整体降级为 unknown
|
|
993
|
+
// 原因:我们无法确定性地评估所有因素
|
|
994
|
+
if (hasUnknown && maxLevel === 'low') {
|
|
995
|
+
return 'unknown';
|
|
996
|
+
}
|
|
997
|
+
return maxLevel;
|
|
998
|
+
}
|
|
999
|
+
function buildReason(level, factors) {
|
|
1000
|
+
if (factors.length === 0)
|
|
1001
|
+
return '无风险因素';
|
|
1002
|
+
const descriptions = factors.map(f => f.description);
|
|
1003
|
+
const prefix = level === 'unknown' ? '存在未知风险因素' : `风险等级: ${level}`;
|
|
1004
|
+
return `${prefix} — ${descriptions.join('; ')}`;
|
|
1005
|
+
}
|
|
1006
|
+
// ── 工具分类 ──
|
|
1007
|
+
const SHELL_TOOLS = new Set(['shell', 'exec', 'bash', 'terminal', 'run_command', 'execute']);
|
|
1008
|
+
/** 写类文件工具 — 保护路径 → critical */
|
|
1009
|
+
const FILE_WRITE_TOOLS = new Set([
|
|
1010
|
+
'file_write', 'file_edit', 'file_delete', 'delete_file',
|
|
1011
|
+
'write_file', 'write', 'edit',
|
|
1012
|
+
]);
|
|
1013
|
+
/** 读类文件工具 — 保护路径 → high(只读,非不可逆) */
|
|
1014
|
+
const FILE_READ_TOOLS = new Set([
|
|
1015
|
+
'file_read', 'file_list', 'file_search',
|
|
1016
|
+
'read_file', 'read',
|
|
1017
|
+
]);
|
|
1018
|
+
const FILE_TOOLS = new Set([...FILE_WRITE_TOOLS, ...FILE_READ_TOOLS]);
|
|
1019
|
+
const HTTP_TOOLS = new Set([
|
|
1020
|
+
'http_get', 'http_post', 'http_put', 'http_delete',
|
|
1021
|
+
'http_request', 'fetch', 'web_fetch', 'curl',
|
|
1022
|
+
]);
|
|
1023
|
+
function isShellTool(name) {
|
|
1024
|
+
return SHELL_TOOLS.has(name);
|
|
1025
|
+
}
|
|
1026
|
+
function isFileTool(name) {
|
|
1027
|
+
return FILE_TOOLS.has(name);
|
|
1028
|
+
}
|
|
1029
|
+
function isFileWriteTool(name) {
|
|
1030
|
+
return FILE_WRITE_TOOLS.has(name);
|
|
1031
|
+
}
|
|
1032
|
+
function isHttpTool(name) {
|
|
1033
|
+
return HTTP_TOOLS.has(name);
|
|
1034
|
+
}
|
|
1035
|
+
function getCommandString(call) {
|
|
1036
|
+
if (typeof call.arguments?.command === 'string')
|
|
1037
|
+
return call.arguments.command;
|
|
1038
|
+
if (typeof call.arguments?.cmd === 'string')
|
|
1039
|
+
return call.arguments.cmd;
|
|
1040
|
+
if (typeof call.arguments?.script === 'string')
|
|
1041
|
+
return call.arguments.script;
|
|
1042
|
+
return null;
|
|
1043
|
+
}
|