@octopi-agent/engine 0.97.15 → 0.102.10
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/dist/config-schema/agent.d.ts +37 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +61 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +10 -1
- package/dist/config-schema/governance.js +38 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +34 -2
- package/dist/harness/agent/builder.js +189 -58
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.d.ts +66 -0
- package/dist/harness/agent/config-integrity.js +108 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +31 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +21 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +12 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -9
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +4 -7
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +16 -19
- package/dist/harness/context/layers.js +42 -14
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +3 -3
- package/dist/harness/context/summarize.js +11 -4
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +3 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
- package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +7 -3
- package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +17 -24
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- package/dist/harness/governance/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +86 -12
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +47 -7
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +31 -1
- package/dist/harness/memory/wisdom-formation.js +130 -33
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +49 -2
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +41 -4
- package/dist/harness/run/runner.d.ts +71 -31
- package/dist/harness/run/runner.js +368 -106
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +13 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +39 -23
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +16 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -255,6 +255,7 @@ export function evaluateShellCommand(command, cwd) {
|
|
|
255
255
|
level: 'unknown',
|
|
256
256
|
factors: [{ source: 'method', description: '命令解析失败', level: 'unknown' }],
|
|
257
257
|
reason: '命令结构过于复杂,无法确定性解析',
|
|
258
|
+
uncertain: true,
|
|
258
259
|
};
|
|
259
260
|
}
|
|
260
261
|
// 1. 检测特殊模式(管道到解释器、内联代码、子 shell)
|
|
@@ -306,12 +307,24 @@ export function evaluateShellCommand(command, cwd) {
|
|
|
306
307
|
});
|
|
307
308
|
}
|
|
308
309
|
}
|
|
310
|
+
// 4.5 解析不确定(tree-sitter 报错回退 fallback 引擎):
|
|
311
|
+
// 结构可能被低估,显式计入 unknown 因子——有确定性高风险仍照常抬升,
|
|
312
|
+
// 全低风险时整体落 unknown 通道(放行 + 事件),不把不确定静默当安全。
|
|
313
|
+
if (parsed.uncertain) {
|
|
314
|
+
factors.push({
|
|
315
|
+
source: 'method',
|
|
316
|
+
description: '命令结构不确定(存在解析器无法确定性解析的片段)',
|
|
317
|
+
level: 'unknown',
|
|
318
|
+
});
|
|
319
|
+
}
|
|
309
320
|
// 5. 计算整体风险等级
|
|
310
321
|
const level = computeOverallRisk(factors);
|
|
311
322
|
return {
|
|
312
323
|
level,
|
|
313
324
|
factors,
|
|
314
325
|
reason: buildReason(level, factors),
|
|
326
|
+
// 强不确定与等级正交:无论等级高低都标记,供守卫上报安全智能体
|
|
327
|
+
...(parsed.uncertain ? { uncertain: true } : {}),
|
|
315
328
|
};
|
|
316
329
|
}
|
|
317
330
|
// ── 段评估 ──
|
|
@@ -42,6 +42,13 @@ export interface ParsedCommand {
|
|
|
42
42
|
hasSubshell: boolean;
|
|
43
43
|
/** 是否包含后台执行(&) */
|
|
44
44
|
hasBackground: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 解析不确定:tree-sitter 无法确定性解析(语法树含 ERROR)后回退 fallback 引擎。
|
|
47
|
+
* 风险分档应附加「结构不确定」因子,不允许静默当正常结果。
|
|
48
|
+
*/
|
|
49
|
+
uncertain?: boolean;
|
|
50
|
+
/** 未挂载到命令段的重定向(如 `> file` 单独成句):目标仍参与路径风险评估 */
|
|
51
|
+
orphanRedirects?: Redirect[];
|
|
45
52
|
}
|
|
46
53
|
export type RiskLevel = 'low' | 'medium' | 'high' | 'critical' | 'unknown';
|
|
47
54
|
export interface RiskFactor {
|
|
@@ -69,6 +76,11 @@ export interface RiskDecision {
|
|
|
69
76
|
alternative?: SafeAlternative;
|
|
70
77
|
/** 决策理由(人类可读) */
|
|
71
78
|
reason: string;
|
|
79
|
+
/**
|
|
80
|
+
* 强不确定(解析结构性不确定等):需安全智能体过目。
|
|
81
|
+
* 与等级正交——始终触发 risk_unknown 事件上报,但不改变等级判定与拦截行为。
|
|
82
|
+
*/
|
|
83
|
+
uncertain?: boolean;
|
|
72
84
|
}
|
|
73
85
|
export type PathRisk = 'safe' | 'normal' | 'sensitive' | 'protected';
|
|
74
86
|
export type ToolCategory = 'shell' | 'file' | 'http' | 'eval' | 'other';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Parser (fallback) — 轻量级 Shell 命令解析器(回退引擎)
|
|
3
|
+
*
|
|
4
|
+
* 纯字符串解析。主引擎是 tree-sitter 适配层(shell-parser-treesitter.ts);
|
|
5
|
+
* 本解析器在 tree-sitter 不可用或解析报错时回退使用。
|
|
6
|
+
* 入口统一走 shell-parser.ts 的 parseShellCommand。
|
|
7
|
+
*
|
|
8
|
+
* 四层解析:
|
|
9
|
+
* 1. 按 |, &&, ||, ; 拆分 → 命令段
|
|
10
|
+
* 2. 每个命令段 → [wrapper...] + [command, ...args]
|
|
11
|
+
* 3. 识别 >, >>, < 重定向 → 提取目标路径
|
|
12
|
+
* 4. 识别 sudo, env, exec 等 wrapper → 解包实际命令
|
|
13
|
+
*
|
|
14
|
+
* 设计原则:宁可解析不完整,不可解析错误。
|
|
15
|
+
* 遇到无法解析的复杂结构,标记为 parsed: false,交给 LLM 判断。
|
|
16
|
+
*/
|
|
17
|
+
import type { ParsedCommand } from './risk-types.js';
|
|
18
|
+
/**
|
|
19
|
+
* 解析 Shell 命令(fallback 引擎)
|
|
20
|
+
*
|
|
21
|
+
* @param raw - 原始命令字符串
|
|
22
|
+
* @returns 解析结果(parsed: true/false 表示解析是否成功)
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseShellCommandFallback(raw: string): ParsedCommand & {
|
|
25
|
+
parsed: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 检测内联代码执行(共享实现,见 shell-parser-shared.ts)
|
|
29
|
+
*/
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Parser (fallback) — 轻量级 Shell 命令解析器(回退引擎)
|
|
3
|
+
*
|
|
4
|
+
* 纯字符串解析。主引擎是 tree-sitter 适配层(shell-parser-treesitter.ts);
|
|
5
|
+
* 本解析器在 tree-sitter 不可用或解析报错时回退使用。
|
|
6
|
+
* 入口统一走 shell-parser.ts 的 parseShellCommand。
|
|
7
|
+
*
|
|
8
|
+
* 四层解析:
|
|
9
|
+
* 1. 按 |, &&, ||, ; 拆分 → 命令段
|
|
10
|
+
* 2. 每个命令段 → [wrapper...] + [command, ...args]
|
|
11
|
+
* 3. 识别 >, >>, < 重定向 → 提取目标路径
|
|
12
|
+
* 4. 识别 sudo, env, exec 等 wrapper → 解包实际命令
|
|
13
|
+
*
|
|
14
|
+
* 设计原则:宁可解析不完整,不可解析错误。
|
|
15
|
+
* 遇到无法解析的复杂结构,标记为 parsed: false,交给 LLM 判断。
|
|
16
|
+
*/
|
|
17
|
+
import { INTERPRETER_NAMES, BASH_ESCAPE_TARGETS, mergeSplitWindowsPaths, unwrapWrapperTokens, detectBackground, detectInlineCode, } from './shell-parser-shared.js';
|
|
18
|
+
// ── 解析入口 ──
|
|
19
|
+
/**
|
|
20
|
+
* 解析 Shell 命令(fallback 引擎)
|
|
21
|
+
*
|
|
22
|
+
* @param raw - 原始命令字符串
|
|
23
|
+
* @returns 解析结果(parsed: true/false 表示解析是否成功)
|
|
24
|
+
*/
|
|
25
|
+
export function parseShellCommandFallback(raw) {
|
|
26
|
+
const trimmed = raw.trim();
|
|
27
|
+
if (!trimmed) {
|
|
28
|
+
return {
|
|
29
|
+
parsed: true,
|
|
30
|
+
raw,
|
|
31
|
+
segments: [],
|
|
32
|
+
connectors: [],
|
|
33
|
+
hasShellPipe: false,
|
|
34
|
+
hasInlineCode: false,
|
|
35
|
+
hasSubshell: false,
|
|
36
|
+
hasBackground: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// 检测子 shell 和后台执行
|
|
40
|
+
const hasSubshell = detectSubshell(trimmed);
|
|
41
|
+
const hasBackground = detectBackground(trimmed);
|
|
42
|
+
// 第一层:按连接符拆分
|
|
43
|
+
const { parts, connectors } = splitByConnectors(trimmed);
|
|
44
|
+
// 第二、三层:解析每个命令段
|
|
45
|
+
const segments = [];
|
|
46
|
+
let parsed = true;
|
|
47
|
+
for (const part of parts) {
|
|
48
|
+
const seg = parseSegment(part);
|
|
49
|
+
if (!seg) {
|
|
50
|
+
parsed = false;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
segments.push(seg);
|
|
54
|
+
}
|
|
55
|
+
// 第四层:检测特殊模式
|
|
56
|
+
const hasShellPipe = detectPipeToInterpreter(segments, connectors);
|
|
57
|
+
const hasInlineCode = detectInlineCode(segments);
|
|
58
|
+
return {
|
|
59
|
+
parsed,
|
|
60
|
+
raw,
|
|
61
|
+
segments,
|
|
62
|
+
connectors,
|
|
63
|
+
hasShellPipe,
|
|
64
|
+
hasInlineCode,
|
|
65
|
+
hasSubshell,
|
|
66
|
+
hasBackground,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// ── 第一层:按连接符拆分 ──
|
|
70
|
+
/**
|
|
71
|
+
* 按连接符拆分命令
|
|
72
|
+
*
|
|
73
|
+
* 注意处理引号内的连接符。
|
|
74
|
+
*/
|
|
75
|
+
function splitByConnectors(cmd) {
|
|
76
|
+
const parts = [];
|
|
77
|
+
const connectors = [];
|
|
78
|
+
let current = '';
|
|
79
|
+
let inSingleQuote = false;
|
|
80
|
+
let inDoubleQuote = false;
|
|
81
|
+
let escape = false;
|
|
82
|
+
let i = 0;
|
|
83
|
+
while (i < cmd.length) {
|
|
84
|
+
const ch = cmd[i];
|
|
85
|
+
// 转义字符
|
|
86
|
+
if (escape) {
|
|
87
|
+
current += ch;
|
|
88
|
+
escape = false;
|
|
89
|
+
i++;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (ch === '\\') {
|
|
93
|
+
escape = true;
|
|
94
|
+
current += ch;
|
|
95
|
+
i++;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// 引号状态
|
|
99
|
+
if (ch === "'" && !inDoubleQuote) {
|
|
100
|
+
inSingleQuote = !inSingleQuote;
|
|
101
|
+
current += ch;
|
|
102
|
+
i++;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (ch === '"' && !inSingleQuote) {
|
|
106
|
+
inDoubleQuote = !inDoubleQuote;
|
|
107
|
+
current += ch;
|
|
108
|
+
i++;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
// 在引号内,直接追加
|
|
112
|
+
if (inSingleQuote || inDoubleQuote) {
|
|
113
|
+
current += ch;
|
|
114
|
+
i++;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// 检测连接符
|
|
118
|
+
if (ch === '|') {
|
|
119
|
+
if (cmd[i + 1] === '|') {
|
|
120
|
+
// ||
|
|
121
|
+
pushPart(parts, current);
|
|
122
|
+
current = '';
|
|
123
|
+
connectors.push('||');
|
|
124
|
+
i += 2;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// |
|
|
129
|
+
pushPart(parts, current);
|
|
130
|
+
current = '';
|
|
131
|
+
connectors.push('|');
|
|
132
|
+
i++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (ch === '&') {
|
|
137
|
+
if (cmd[i + 1] === '&') {
|
|
138
|
+
// &&
|
|
139
|
+
pushPart(parts, current);
|
|
140
|
+
current = '';
|
|
141
|
+
connectors.push('&&');
|
|
142
|
+
i += 2;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// `>&` / `N>&M`:文件描述符重定向(2>&1、>&2),不是命令分隔
|
|
146
|
+
if (i > 0 && cmd[i - 1] === '>') {
|
|
147
|
+
current += ch;
|
|
148
|
+
i++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// `&>` / `&>>`:bash 重定向合一,不是命令分隔
|
|
152
|
+
if (cmd[i + 1] === '>') {
|
|
153
|
+
current += ch;
|
|
154
|
+
i++;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// 单 `&` 既是后台标记也是命令分隔:`true & rm -rf /` 必须拆段
|
|
158
|
+
pushPart(parts, current);
|
|
159
|
+
current = '';
|
|
160
|
+
connectors.push('&');
|
|
161
|
+
i++;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (ch === ';') {
|
|
165
|
+
pushPart(parts, current);
|
|
166
|
+
current = '';
|
|
167
|
+
connectors.push(';');
|
|
168
|
+
i++;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (ch === '\n') {
|
|
172
|
+
pushPart(parts, current);
|
|
173
|
+
current = '';
|
|
174
|
+
connectors.push('\n');
|
|
175
|
+
i++;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
current += ch;
|
|
179
|
+
i++;
|
|
180
|
+
}
|
|
181
|
+
// 最后一段
|
|
182
|
+
pushPart(parts, current);
|
|
183
|
+
return { parts, connectors };
|
|
184
|
+
}
|
|
185
|
+
function pushPart(parts, current) {
|
|
186
|
+
const trimmed = current.trim();
|
|
187
|
+
if (trimmed) {
|
|
188
|
+
parts.push(trimmed);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ── 第二、三层:解析命令段 ──
|
|
192
|
+
/**
|
|
193
|
+
* 解析单个命令段
|
|
194
|
+
*
|
|
195
|
+
* 提取 wrapper、命令、参数、重定向。
|
|
196
|
+
* 遇到无法解析的结构返回 null。
|
|
197
|
+
*/
|
|
198
|
+
function parseSegment(raw) {
|
|
199
|
+
const rawTokens = tokenize(raw);
|
|
200
|
+
if (rawTokens.length === 0)
|
|
201
|
+
return null;
|
|
202
|
+
// 提取重定向(在 Windows 路径合并之前:目标语义按原始 token 粒度判定)
|
|
203
|
+
const redirects = [];
|
|
204
|
+
const cleanTokens = [];
|
|
205
|
+
let i = 0;
|
|
206
|
+
while (i < rawTokens.length) {
|
|
207
|
+
const token = rawTokens[i];
|
|
208
|
+
// 独立重定向操作符(`> file`):操作符与目标都必须是未引号字面量
|
|
209
|
+
if (isUnquotedToken(token) &&
|
|
210
|
+
(token.text === '>' || token.text === '>>' || token.text === '<')) {
|
|
211
|
+
const target = rawTokens[i + 1];
|
|
212
|
+
if (!target || !isUnquotedToken(target))
|
|
213
|
+
return null; // 重定向后没有目标,解析失败
|
|
214
|
+
redirects.push({
|
|
215
|
+
type: token.text === '>' ? 'overwrite' : token.text === '>>' ? 'append' : 'input',
|
|
216
|
+
target: target.text,
|
|
217
|
+
});
|
|
218
|
+
i += 2;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
// 检测 >file 格式(无空格)
|
|
222
|
+
const redirectMatch = matchRedirect(token);
|
|
223
|
+
if (redirectMatch) {
|
|
224
|
+
redirects.push(redirectMatch);
|
|
225
|
+
i++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
cleanTokens.push(token.text);
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
if (cleanTokens.length === 0)
|
|
232
|
+
return null;
|
|
233
|
+
// 提取 wrapper(共享拆壳逻辑:sudo/env/exec 等)
|
|
234
|
+
const unwrapped = unwrapWrapperTokens(mergeSplitWindowsPaths(cleanTokens));
|
|
235
|
+
if (!unwrapped)
|
|
236
|
+
return null;
|
|
237
|
+
return {
|
|
238
|
+
command: unwrapped.command,
|
|
239
|
+
args: unwrapped.args,
|
|
240
|
+
redirects,
|
|
241
|
+
isSudo: unwrapped.isSudo,
|
|
242
|
+
wrappers: unwrapped.wrappers,
|
|
243
|
+
raw,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/** token 是否整体未引号 */
|
|
247
|
+
function isUnquotedToken(token) {
|
|
248
|
+
return token.quoted.every((q) => !q);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 简单的 tokenizer
|
|
252
|
+
*
|
|
253
|
+
* 处理引号和转义字符,逐字符记录引号来源。
|
|
254
|
+
* Windows 路径(`C:\Windows`、`\\server\share`)中的 `\` 不会被吃掉——
|
|
255
|
+
* 否则保护路径判定会拿到被拆坏的字符串。
|
|
256
|
+
*/
|
|
257
|
+
function tokenize(raw) {
|
|
258
|
+
const tokens = [];
|
|
259
|
+
let current = '';
|
|
260
|
+
let mask = [];
|
|
261
|
+
let inSingleQuote = false;
|
|
262
|
+
let inDoubleQuote = false;
|
|
263
|
+
const pushChar = (ch, fromQuote) => {
|
|
264
|
+
current += ch;
|
|
265
|
+
mask.push(fromQuote);
|
|
266
|
+
};
|
|
267
|
+
const flush = () => {
|
|
268
|
+
if (current) {
|
|
269
|
+
tokens.push({ text: current, quoted: mask });
|
|
270
|
+
current = '';
|
|
271
|
+
mask = [];
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
for (let i = 0; i < raw.length; i++) {
|
|
275
|
+
const ch = raw[i];
|
|
276
|
+
const inQuote = inSingleQuote || inDoubleQuote;
|
|
277
|
+
if (ch === '\\' && !inSingleQuote) {
|
|
278
|
+
const next = raw[i + 1];
|
|
279
|
+
if (next === undefined) {
|
|
280
|
+
pushChar(ch, inQuote);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
// 经典 bash 转义:吃掉 `\`,保留下一字符字面量
|
|
284
|
+
if (BASH_ESCAPE_TARGETS.has(next)) {
|
|
285
|
+
pushChar(next, inQuote);
|
|
286
|
+
i++;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
// Windows 路径分隔符 / UNC:保留 `\`
|
|
290
|
+
pushChar(ch, inQuote);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (ch === "'" && !inDoubleQuote) {
|
|
294
|
+
inSingleQuote = !inSingleQuote;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (ch === '"' && !inSingleQuote) {
|
|
298
|
+
inDoubleQuote = !inDoubleQuote;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if ((ch === ' ' || ch === '\t') && !inQuote) {
|
|
302
|
+
flush();
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
pushChar(ch, inQuote);
|
|
306
|
+
}
|
|
307
|
+
flush();
|
|
308
|
+
return tokens;
|
|
309
|
+
}
|
|
310
|
+
// ── 重定向识别(matchRedirect,含引号来源判定) ──
|
|
311
|
+
/**
|
|
312
|
+
* 匹配 >file 或 >>file 格式(无空格的重定向)
|
|
313
|
+
*
|
|
314
|
+
* 同时识别文件描述符重定向(`2>&1`、`>&2`、`&>file`)。
|
|
315
|
+
* 只在未引号区域识别:引号内的 `<`/`>` 是字面量(bash 语义)——
|
|
316
|
+
* 引号串被压成单 token 后,中缀启发式曾把引号内 `2>/dev/null` 误认成重定向、
|
|
317
|
+
* 其后整段捏造成目标(2026-10 假 critical 误拦的根因),按引号来源精确排除。
|
|
318
|
+
*
|
|
319
|
+
* @param token - token 文本与逐字符引号来源
|
|
320
|
+
* @returns 重定向信息;操作符或目标来自引号内时返回 null(宁可解析不完整,不可解析错误)
|
|
321
|
+
*/
|
|
322
|
+
function matchRedirect(token) {
|
|
323
|
+
const { text, quoted } = token;
|
|
324
|
+
/** [from, to) 是否全部未引号 */
|
|
325
|
+
const opAt = (from, to) => {
|
|
326
|
+
for (let k = from; k < to; k++) {
|
|
327
|
+
if (quoted[k])
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
};
|
|
332
|
+
/** 构造重定向;目标区域含引号内容则放弃(目标可能被引号串拼接污染) */
|
|
333
|
+
const make = (type, targetFrom) => {
|
|
334
|
+
if (!opAt(targetFrom, text.length))
|
|
335
|
+
return null;
|
|
336
|
+
return { type, target: text.slice(targetFrom) };
|
|
337
|
+
};
|
|
338
|
+
// `&>` / `&>>`:bash 重定向合一
|
|
339
|
+
if (text.startsWith('&>>') && opAt(0, 3)) {
|
|
340
|
+
return make('append', 3);
|
|
341
|
+
}
|
|
342
|
+
if (text.startsWith('&>') && text.length > 2 && opAt(0, 2)) {
|
|
343
|
+
return make('overwrite', 2);
|
|
344
|
+
}
|
|
345
|
+
// 文件描述符重定向:`2>&1`、`>&2`、`1>&2` 等
|
|
346
|
+
// target 用 fd: 标记,避免被当成路径做风险分类;整个 token 必须未引号
|
|
347
|
+
const fdDup = text.match(/^(\d*)>{1,2}&(\d+)$/);
|
|
348
|
+
if (fdDup && opAt(0, text.length)) {
|
|
349
|
+
return {
|
|
350
|
+
type: text.includes('>>') ? 'append' : 'overwrite',
|
|
351
|
+
target: `fd:${fdDup[2]}`,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
// 先检查开头的重定向
|
|
355
|
+
if (text.startsWith('>>') && opAt(0, 2)) {
|
|
356
|
+
return make('append', 2);
|
|
357
|
+
}
|
|
358
|
+
if (text.startsWith('>') && text.length > 1 && opAt(0, 1)) {
|
|
359
|
+
return make('overwrite', 1);
|
|
360
|
+
}
|
|
361
|
+
if (text.startsWith('<') && text.length > 1 && opAt(0, 1)) {
|
|
362
|
+
return make('input', 1);
|
|
363
|
+
}
|
|
364
|
+
// 检查 token 中间的重定向(如 hello>/tmp/out.txt);`>&N` 已由 fdDup 覆盖
|
|
365
|
+
const gtIdx = text.indexOf('>');
|
|
366
|
+
if (gtIdx > 0 && gtIdx < text.length - 1 && opAt(gtIdx, gtIdx + 1)) {
|
|
367
|
+
if (text[gtIdx + 1] === '&') {
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
if (text[gtIdx + 1] === '>') {
|
|
371
|
+
return make('append', gtIdx + 2);
|
|
372
|
+
}
|
|
373
|
+
return make('overwrite', gtIdx + 1);
|
|
374
|
+
}
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
// ── 第四层:检测特殊模式 ──
|
|
378
|
+
/**
|
|
379
|
+
* 检测子 shell($(...) 或反引号)
|
|
380
|
+
*/
|
|
381
|
+
function detectSubshell(cmd) {
|
|
382
|
+
// $(...) 模式
|
|
383
|
+
if (cmd.includes('$('))
|
|
384
|
+
return true;
|
|
385
|
+
// 反引号模式
|
|
386
|
+
if (cmd.includes('`'))
|
|
387
|
+
return true;
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* 检测管道到解释器
|
|
392
|
+
*
|
|
393
|
+
* 不止 sh/bash,python/ruby/perl/node 等也是解释器。
|
|
394
|
+
* curl ... | python3 和 curl ... | sh 本质相同(执行外部代码)。
|
|
395
|
+
*/
|
|
396
|
+
function detectPipeToInterpreter(segments, connectors) {
|
|
397
|
+
for (let i = 0; i < connectors.length; i++) {
|
|
398
|
+
if (connectors[i] === '|') {
|
|
399
|
+
const nextSeg = segments[i + 1];
|
|
400
|
+
if (nextSeg && INTERPRETER_NAMES.has(nextSeg.command) && nextSeg.args.length === 0) {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* 检测内联代码执行(共享实现,见 shell-parser-shared.ts)
|
|
409
|
+
*/
|
|
410
|
+
// ── 导出工具函数移至 shell-parser.ts facade ──
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Parser Shared — 解析引擎共享常量与命令拆壳
|
|
3
|
+
*
|
|
4
|
+
* tree-sitter 适配层与 fallback 字符串解析器共用:
|
|
5
|
+
* 解释器名单、内联代码 flag、wrapper 命令拆壳、转义处理。
|
|
6
|
+
* 两个解析引擎必须保持同一套语义,否则风险分档会在引擎切换时漂移。
|
|
7
|
+
*/
|
|
8
|
+
/** 已知的解释器名称(管道到解释器 = 执行外部代码) */
|
|
9
|
+
export declare const INTERPRETER_NAMES: Set<string>;
|
|
10
|
+
/**
|
|
11
|
+
* 已知的内联代码执行参数
|
|
12
|
+
*
|
|
13
|
+
* python -c "...", node -e "...", ruby -e "...", perl -e "..."
|
|
14
|
+
*/
|
|
15
|
+
export declare const INLINE_CODE_FLAGS: Record<string, string[]>;
|
|
16
|
+
/**
|
|
17
|
+
* 仅对真正的 wrapper 剥壳。
|
|
18
|
+
*
|
|
19
|
+
* 不要把 cmd/start 放进来:它们的选项(/c、/b)会被误当成命令名,
|
|
20
|
+
* 且 cmd /c 本身就是内联执行,应保留原命令以便 INLINE_CODE_FLAGS 识别。
|
|
21
|
+
*/
|
|
22
|
+
export declare const WRAPPER_COMMANDS: Set<string>;
|
|
23
|
+
/** bash 需要被 `\` 转义的元字符。其余字符前的 `\` 视为 Windows 路径分隔符并原样保留。 */
|
|
24
|
+
export declare const BASH_ESCAPE_TARGETS: Set<string>;
|
|
25
|
+
/**
|
|
26
|
+
* 合并被空格切开的 Windows 绝对路径
|
|
27
|
+
*
|
|
28
|
+
* `del C:\Program Files\App\x.exe` → `C:\Program` + `Files\App\x.exe`
|
|
29
|
+
* → `C:\Program Files\App\x.exe`
|
|
30
|
+
*
|
|
31
|
+
* 规则:当前 token 是盘符/UNC 绝对路径,下一段含路径分隔符,
|
|
32
|
+
* 且当前最后一段无文件扩展名时合并。
|
|
33
|
+
* 已知局限:`cp C:\data backup\old` 也可能被误合并。
|
|
34
|
+
*/
|
|
35
|
+
export declare function mergeSplitWindowsPaths(tokens: string[]): string[];
|
|
36
|
+
/**
|
|
37
|
+
* 去除单个 token 的 bash 反斜杠转义(引号已由解析层剥除)。
|
|
38
|
+
*
|
|
39
|
+
* `\` 仅在 BASH_ESCAPE_TARGETS 前被吃掉;其余位置的 `\`
|
|
40
|
+
* 按 Windows 路径分隔符保留(保护路径判定依赖完整路径串)。
|
|
41
|
+
*
|
|
42
|
+
* @param text - token 文本
|
|
43
|
+
* @returns 去转义后的值
|
|
44
|
+
*/
|
|
45
|
+
export declare function unescapeToken(text: string): string;
|
|
46
|
+
/** 拆壳结果 */
|
|
47
|
+
export interface UnwrappedCommand {
|
|
48
|
+
/** 真实命令名 */
|
|
49
|
+
command: string;
|
|
50
|
+
/** 真实参数 */
|
|
51
|
+
args: string[];
|
|
52
|
+
/** 剥下的 wrapper 链(如 ['sudo', 'env']) */
|
|
53
|
+
wrappers: string[];
|
|
54
|
+
/** 是否通过 sudo 执行 */
|
|
55
|
+
isSudo: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 剥掉 sudo/env/exec 等 wrapper,定位真实命令。
|
|
59
|
+
*
|
|
60
|
+
* @param tokens - 已去除重定向的 token 序列
|
|
61
|
+
* @returns 拆壳结果;wrapper 后无命令残留时返回 null
|
|
62
|
+
*/
|
|
63
|
+
export declare function unwrapWrapperTokens(tokens: string[]): UnwrappedCommand | null;
|
|
64
|
+
/**
|
|
65
|
+
* 检测后台执行
|
|
66
|
+
*
|
|
67
|
+
* @param cmd - 原始命令字符串
|
|
68
|
+
* @returns 是否以单个 `&` 结尾
|
|
69
|
+
*/
|
|
70
|
+
export declare function detectBackground(cmd: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 检测内联代码执行(按已拆壳的命令段)
|
|
73
|
+
*
|
|
74
|
+
* python -c "...", node -e "...", bash -c "...",
|
|
75
|
+
* powershell -Command "...", cmd /c "..." 等。命令名大小写不敏感(Windows shell)。
|
|
76
|
+
*
|
|
77
|
+
* @param segments - 已拆壳的命令段列表
|
|
78
|
+
* @returns 是否存在内联代码形态
|
|
79
|
+
*/
|
|
80
|
+
export declare function detectInlineCode(segments: Array<{
|
|
81
|
+
command: string;
|
|
82
|
+
args: string[];
|
|
83
|
+
}>): boolean;
|