@octopi-agent/engine 0.70.7 → 0.90.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +81 -5
- package/dist/config-schema/context.d.ts +24 -5
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +205 -13
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +93 -1
- package/dist/config-schema/models.d.ts +3 -3
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +13 -0
- package/dist/config-schema/shared.js +22 -0
- package/dist/config-schema/substrate.d.ts +2 -2
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +201 -8
- package/dist/config.js +105 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +50 -5
- package/dist/harness/agent/builder.js +189 -59
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +84 -291
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +46 -0
- package/dist/harness/agent/tool-purpose.js +127 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +370 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +8 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -9
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/registry.js +10 -0
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +85 -1
- package/dist/harness/context/layer-types.js +110 -4
- package/dist/harness/context/layers.d.ts +5 -2
- package/dist/harness/context/layers.js +11 -5
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +30 -0
- package/dist/harness/context/system-prompt-assembler.js +73 -6
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +258 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +358 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +521 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +51 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +153 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +277 -81
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +241 -70
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +463 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +25 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +16 -12
- package/dist/harness/index.js +10 -6
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +8 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +121 -39
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +154 -151
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/knowledge/query-service.js +3 -3
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/index.d.ts +1 -0
- package/dist/harness/memory/index.js +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +2 -0
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.js +9 -9
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +12 -0
- package/dist/harness/observability/observer/hub.js +53 -2
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +80 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +18 -0
- package/dist/harness/run/agent/agent.js +26 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +110 -18
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +117 -16
- package/dist/harness/run/runner.js +668 -157
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +16 -5
- package/dist/harness/session/in-memory-store.d.ts +6 -0
- package/dist/harness/session/in-memory-store.js +55 -3
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +39 -0
- package/dist/harness/shared/events/agent-event-map.js +2 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +29 -0
- package/dist/integration/storage/jsonl.js +243 -41
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -43
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -6,14 +6,21 @@
|
|
|
6
6
|
*
|
|
7
7
|
* 特性:
|
|
8
8
|
* - pattern_mode: auto(默认)/ literal / regex;`patterns[]` 多词任一命中
|
|
9
|
-
* - auto 仅认强信号(锚点/转义类/`.*`/`{n}
|
|
9
|
+
* - auto 仅认强信号(锚点/转义类/`.*`/`{n}`),代码字面量保持 literal
|
|
10
|
+
* - auto 下 `a|b` 恒为「分支字面 OR」:分支 trim + 转义后以 `|` 连接(`.` 是字面点,非通配);
|
|
11
|
+
* 任一分支为空(`foo|`、`|`)则整词按字面搜;要搜含竖线的字面文本用 pattern_mode=literal
|
|
12
|
+
* - 二进制嗅探:文件头 4KB 含 NUL 判为二进制跳过(无扩展名二进制如 .DS_Store 不漏入结果)
|
|
13
|
+
* - 结果含 matchedFiles 聚合(每文件命中数)与 diagnostics.root(实际搜索根,便于发现 path 传错)
|
|
10
14
|
* - 路径感知 glob(支持 `**` / `*` / `?` / `{a,b}`,匹配 root 相对路径;`\` 转义)
|
|
11
15
|
* - 逐行流式扫描;`max_file_bytes` 安全阀(默认 50MB)跳过异常巨文件
|
|
12
16
|
* - 上下文行(before/after)
|
|
13
17
|
* - 结果数量限制
|
|
18
|
+
* - L1 输出硬顶(F1-B1):结构化收缩、零 LLM,file+line 清单永远全保;
|
|
19
|
+
* 预算经 `summary.tools.file_search.maxReturnChars` 可调(缺省 8000)
|
|
14
20
|
* - 忽略常见无关目录(node_modules, .git 等)
|
|
15
21
|
* - 零结果时返回 diagnostics + hints,便于调用方自纠
|
|
16
22
|
*/
|
|
23
|
+
import { resolveSupportBinding, } from '../../../context/capabilities/summary/index.js';
|
|
17
24
|
import { resolveToolPath } from './platform.js';
|
|
18
25
|
/** 需要忽略的目录 */
|
|
19
26
|
const IGNORED_DIRS = new Set([
|
|
@@ -22,34 +29,43 @@ const IGNORED_DIRS = new Set([
|
|
|
22
29
|
]);
|
|
23
30
|
/** 单文件读取安全阀默认值(50MB;可经 max_file_bytes 调整) */
|
|
24
31
|
const DEFAULT_MAX_FILE_BYTES = 50_000_000;
|
|
32
|
+
/** L1 收缩后 content 预览行的字符上限(超长行是单条膨胀元凶;定位符不受影响) */
|
|
33
|
+
const CONTENT_PREVIEW_CHARS = 200;
|
|
34
|
+
/** content 行机械截断标记(机械截断 ≠ 摘要改写) */
|
|
35
|
+
const CONTENT_TRUNCATED_MARK = '…[truncated]';
|
|
36
|
+
/** 预览整条省略占位(file+line 永远全保) */
|
|
37
|
+
const PREVIEW_OMITTED = '…[preview omitted]';
|
|
38
|
+
/** file_search L1 缺省预算(与 summary registry 缺省一致;可经 summary.tools.file_search.maxReturnChars 覆盖) */
|
|
39
|
+
const DEFAULT_MAX_RETURN_CHARS = 8000;
|
|
25
40
|
/**
|
|
26
41
|
* 创建 file_search 工具
|
|
27
42
|
*
|
|
43
|
+
* @param options - 可选 summary support(L1 预算 binding;file_search 恒不跑 L2)
|
|
28
44
|
* @returns RegisteredTool
|
|
29
45
|
*/
|
|
30
|
-
export function createFileSearchTool() {
|
|
46
|
+
export function createFileSearchTool(options) {
|
|
31
47
|
return {
|
|
32
48
|
definition: {
|
|
33
49
|
name: 'file_search',
|
|
50
|
+
capabilities: ['fs-read'],
|
|
34
51
|
description: 'Search file contents (like grep/rg) with structured results. ' +
|
|
35
|
-
'Provide `pattern` (one term) or `patterns` (any-of literals). ' +
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'Code tokens stay literal: `arr[0]`, `useState()`, `a+b`, `C++`, `foo.bar`, `memory*`. ' +
|
|
39
|
-
'Set pattern_mode="regex" or "literal" to force. ' +
|
|
40
|
-
"Glob filters by root-relative path (always case-insensitive): '*.md' (any depth), 'src/**/*.ts', '**/memory*.md'. " +
|
|
41
|
-
"`**` crosses directories, `*` does not. " +
|
|
52
|
+
'Provide `pattern` (one term) or `patterns` (any-of literals) — match semantics on those params. ' +
|
|
53
|
+
'`glob` filters by relative path (always case-insensitive; `**` crosses directories, `*` does not). ' +
|
|
54
|
+
'`path` = root dir to walk recursively, or one file to search. ' +
|
|
42
55
|
'Empty results include diagnostics.hints for how to retry. ' +
|
|
43
|
-
'Default case-insensitive content match
|
|
44
|
-
'Files
|
|
56
|
+
'Default case-insensitive content match (`case_sensitive=true` for exact). ' +
|
|
57
|
+
'Files scanned as line streams; `max_file_bytes` skips larger files; first 4KB NUL ⇒ treated as binary.',
|
|
45
58
|
parameters: {
|
|
46
59
|
pattern: {
|
|
47
60
|
type: 'string',
|
|
48
|
-
description: 'Single search term. Auto: regex only
|
|
61
|
+
description: 'Single search term. Auto: regex only on strong signals — anchors (^…$), ' +
|
|
62
|
+
'escapes (\\d \\w \\s \\b …) or escaped metachars, `.*`/`.+`, `{n}`; ' +
|
|
63
|
+
'`a|b` = literal OR of trimmed branches (empty branch → whole-term literal); ' +
|
|
64
|
+
'everything else is literal text (e.g. `arr[0]`, `C++`, `foo.bar`).',
|
|
49
65
|
},
|
|
50
66
|
patterns: {
|
|
51
67
|
type: 'array',
|
|
52
|
-
description: 'Multiple terms; a line matches if ANY term matches.
|
|
68
|
+
description: 'Multiple terms; a line matches if ANY term matches.',
|
|
53
69
|
items: { type: 'string', description: 'search term' },
|
|
54
70
|
minItems: 1,
|
|
55
71
|
},
|
|
@@ -60,11 +76,11 @@ export function createFileSearchTool() {
|
|
|
60
76
|
glob: {
|
|
61
77
|
type: 'string',
|
|
62
78
|
description: "Path glob relative to root (case-insensitive), e.g. '*.md', 'src/**/*.ts', '**/memory*.md'. " +
|
|
63
|
-
'Matches relative path; bare `*` does not cross directories.',
|
|
79
|
+
'Matches relative path; bare name (no `/`) matches at any depth; `*` does not cross directories.',
|
|
64
80
|
},
|
|
65
81
|
pattern_mode: {
|
|
66
82
|
type: 'string',
|
|
67
|
-
description: 'How to compile pattern/patterns (default: auto)',
|
|
83
|
+
description: 'How to compile pattern/patterns (default: auto; set "regex"/"literal" to force)',
|
|
68
84
|
enum: ['auto', 'literal', 'regex'],
|
|
69
85
|
},
|
|
70
86
|
regex: {
|
|
@@ -97,11 +113,14 @@ export function createFileSearchTool() {
|
|
|
97
113
|
timeoutMs: 30_000,
|
|
98
114
|
},
|
|
99
115
|
handler: async (args, context) => {
|
|
100
|
-
const { readdir, stat } = await import('node:fs/promises');
|
|
101
|
-
const { join, relative
|
|
116
|
+
const { open, readdir, stat } = await import('node:fs/promises');
|
|
117
|
+
const { basename, extname, join, relative } = await import('node:path');
|
|
102
118
|
const rawRoot = args.path;
|
|
103
119
|
const rootPath = rawRoot
|
|
104
|
-
? resolveToolPath(rawRoot, context.cwd ?? process.cwd()
|
|
120
|
+
? resolveToolPath(rawRoot, context.cwd ?? process.cwd(), {
|
|
121
|
+
allowRoots: context.pathRoots,
|
|
122
|
+
containment: context.pathContainment,
|
|
123
|
+
})
|
|
105
124
|
: (context.cwd ?? process.cwd());
|
|
106
125
|
const terms = collectPatternTerms(args);
|
|
107
126
|
const patternMode = resolvePatternMode(args);
|
|
@@ -128,7 +147,76 @@ export function createFileSearchTool() {
|
|
|
128
147
|
let filesSearched = 0;
|
|
129
148
|
let filesSkipped = 0;
|
|
130
149
|
let filesSkippedOversize = 0;
|
|
150
|
+
let filesSkippedBinary = 0;
|
|
151
|
+
const perFileCounts = new Map();
|
|
131
152
|
let truncated = false;
|
|
153
|
+
async function considerFile(fullPath, relPath) {
|
|
154
|
+
if (truncated)
|
|
155
|
+
return;
|
|
156
|
+
filesSeen += 1;
|
|
157
|
+
// glob 过滤:root 相对路径(无 `/` 的模式等价于任意深度 globstar)
|
|
158
|
+
if (fileFilter && !fileFilter.test(relPath))
|
|
159
|
+
return;
|
|
160
|
+
filesMatchedByGlob += 1;
|
|
161
|
+
// 扩展名粗判二进制,避免把不可读内容塞进结果
|
|
162
|
+
const ext = extname(fullPath).toLowerCase();
|
|
163
|
+
if (BINARY_EXTENSIONS.has(ext)) {
|
|
164
|
+
filesSkipped += 1;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
let size = 0;
|
|
168
|
+
try {
|
|
169
|
+
size = (await stat(fullPath)).size;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// stat 失败(竞态删除/无权限)→ 跳过该文件
|
|
173
|
+
filesSkipped += 1;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (size > maxFileBytes) {
|
|
177
|
+
filesSkipped += 1;
|
|
178
|
+
filesSkippedOversize += 1;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
// 内容嗅探:头 4KB 含 NUL 视为二进制(扩展名粗判覆盖不到的 .bin/.dat/无后缀二进制)。
|
|
182
|
+
// NUL 在 UTF-8/UTF-16 文本中不出现,误判面可忽略;吞掉读失败并按可读处理(下行扫描自会兜底)。
|
|
183
|
+
if (size > 0) {
|
|
184
|
+
let handle;
|
|
185
|
+
try {
|
|
186
|
+
handle = await open(fullPath, 'r');
|
|
187
|
+
const buf = Buffer.alloc(Math.min(4096, size));
|
|
188
|
+
const { bytesRead } = await handle.read(buf, 0, buf.length, 0);
|
|
189
|
+
if (buf.subarray(0, bytesRead).includes(0)) {
|
|
190
|
+
filesSkipped += 1;
|
|
191
|
+
filesSkippedBinary += 1;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// 读失败:不计二进制,交由下方行扫描决定(其失败路径计 filesSkipped)
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
await handle?.close().catch(() => {
|
|
200
|
+
// 关闭失败不影响搜索结果;句柄随进程回收
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
filesSearched += 1;
|
|
205
|
+
await searchFileLines({
|
|
206
|
+
fullPath,
|
|
207
|
+
relPath,
|
|
208
|
+
matchers: content.matchers,
|
|
209
|
+
contextLines,
|
|
210
|
+
onMatch: (match) => {
|
|
211
|
+
allMatches.push(match);
|
|
212
|
+
perFileCounts.set(match.file, (perFileCounts.get(match.file) ?? 0) + 1);
|
|
213
|
+
if (allMatches.length >= maxResults) {
|
|
214
|
+
truncated = true;
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
shouldStop: () => truncated,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
132
220
|
async function walk(dir) {
|
|
133
221
|
if (truncated)
|
|
134
222
|
return;
|
|
@@ -151,51 +239,21 @@ export function createFileSearchTool() {
|
|
|
151
239
|
}
|
|
152
240
|
if (!entry.isFile())
|
|
153
241
|
continue;
|
|
154
|
-
filesSeen += 1;
|
|
155
242
|
// 统一为 `/`,保证 Windows 相对路径也能过 glob
|
|
156
243
|
const relPath = relative(rootPath, fullPath).split('\\').join('/');
|
|
157
|
-
|
|
158
|
-
if (fileFilter && !fileFilter.test(relPath))
|
|
159
|
-
continue;
|
|
160
|
-
filesMatchedByGlob += 1;
|
|
161
|
-
// 扩展名粗判二进制,避免把不可读内容塞进结果
|
|
162
|
-
const ext = extname(entry.name).toLowerCase();
|
|
163
|
-
if (BINARY_EXTENSIONS.has(ext)) {
|
|
164
|
-
filesSkipped += 1;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
let size = 0;
|
|
168
|
-
try {
|
|
169
|
-
size = (await stat(fullPath)).size;
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
// stat 失败(竞态删除/无权限)→ 跳过该文件
|
|
173
|
-
filesSkipped += 1;
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (size > maxFileBytes) {
|
|
177
|
-
filesSkipped += 1;
|
|
178
|
-
filesSkippedOversize += 1;
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
filesSearched += 1;
|
|
182
|
-
await searchFileLines({
|
|
183
|
-
fullPath,
|
|
184
|
-
relPath,
|
|
185
|
-
matchers: content.matchers,
|
|
186
|
-
contextLines,
|
|
187
|
-
onMatch: (match) => {
|
|
188
|
-
allMatches.push(match);
|
|
189
|
-
if (allMatches.length >= maxResults) {
|
|
190
|
-
truncated = true;
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
shouldStop: () => truncated,
|
|
194
|
-
});
|
|
244
|
+
await considerFile(fullPath, relPath);
|
|
195
245
|
}
|
|
196
246
|
}
|
|
197
|
-
|
|
247
|
+
// path 可为目录(递归)或单文件(只搜该文件)
|
|
248
|
+
const rootInfo = await stat(rootPath).catch(() => null);
|
|
249
|
+
if (rootInfo?.isFile()) {
|
|
250
|
+
await considerFile(rootPath, basename(rootPath).split('\\').join('/'));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
await walk(rootPath);
|
|
254
|
+
}
|
|
198
255
|
const diagnostics = {
|
|
256
|
+
root: rootPath,
|
|
199
257
|
patternMode: content.mode,
|
|
200
258
|
patterns: content.sources,
|
|
201
259
|
compiledPatterns: content.compiled,
|
|
@@ -206,8 +264,13 @@ export function createFileSearchTool() {
|
|
|
206
264
|
filesSearched,
|
|
207
265
|
filesSkipped,
|
|
208
266
|
filesSkippedOversize,
|
|
267
|
+
filesSkippedBinary,
|
|
209
268
|
maxFileBytes,
|
|
210
269
|
};
|
|
270
|
+
// 每文件命中聚合:降序(命中多的优先),同数按文件名升序
|
|
271
|
+
const matchedFiles = [...perFileCounts.entries()]
|
|
272
|
+
.map(([file, matches]) => ({ file, matches }))
|
|
273
|
+
.sort((a, b) => b.matches - a.matches || (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
|
|
211
274
|
const hints = buildHints({
|
|
212
275
|
totalMatches: allMatches.length,
|
|
213
276
|
content,
|
|
@@ -220,10 +283,30 @@ export function createFileSearchTool() {
|
|
|
220
283
|
filesSkippedOversize,
|
|
221
284
|
maxFileBytes,
|
|
222
285
|
});
|
|
286
|
+
// F1-B1:L1 结构化硬顶(零 LLM)。定位符(file+line)永远全保,只收缩预览体;
|
|
287
|
+
// 不走字符串 gate,避免截断 JSON 丢掉尾部定位符。
|
|
288
|
+
// 注:预算只约束 matches 清单体;matchedFiles/diagnostics/hints 不进预算。
|
|
289
|
+
// file_search 不经过外层 applyToolOutputGate(否则会按字符腰斩 JSON),
|
|
290
|
+
// 因此超出预算是安全的——设计上定位符优先于预算。
|
|
291
|
+
const binding = resolveSupportBinding('file_search', options?.summary, DEFAULT_MAX_RETURN_CHARS);
|
|
292
|
+
const shrunk = shrinkMatchesForBudget(allMatches, binding.maxReturnChars);
|
|
293
|
+
if (shrunk.cap) {
|
|
294
|
+
hints.push(buildOutputCapHint(shrunk.cap));
|
|
295
|
+
}
|
|
296
|
+
const truncatedReason = truncated && shrunk.cap
|
|
297
|
+
? 'max_results+l1_cap'
|
|
298
|
+
: truncated
|
|
299
|
+
? 'max_results'
|
|
300
|
+
: shrunk.cap
|
|
301
|
+
? 'l1_cap'
|
|
302
|
+
: undefined;
|
|
223
303
|
return {
|
|
224
|
-
matches:
|
|
304
|
+
matches: shrunk.matches,
|
|
225
305
|
totalMatches: allMatches.length,
|
|
226
|
-
|
|
306
|
+
matchedFiles,
|
|
307
|
+
truncated: truncated || Boolean(shrunk.cap),
|
|
308
|
+
truncatedReason,
|
|
309
|
+
outputCap: shrunk.cap,
|
|
227
310
|
searchedFiles: filesSearched,
|
|
228
311
|
diagnostics,
|
|
229
312
|
hints,
|
|
@@ -292,7 +375,7 @@ function resolveMaxFileBytes(args) {
|
|
|
292
375
|
*
|
|
293
376
|
* 只认强信号。代码字面量保持 literal:
|
|
294
377
|
* `arr[0]` / `useState()` / `a+b` / `C++` / `foo.bar` / `memory*` 均不为正则。
|
|
295
|
-
*
|
|
378
|
+
* `|` 不是正则信号:`a|b` 走 compileAlternationLiteral 的分支字面 OR。
|
|
296
379
|
*
|
|
297
380
|
* @param term - 搜索词
|
|
298
381
|
* @returns 是否像正则
|
|
@@ -307,20 +390,24 @@ function looksLikeRegex(term) {
|
|
|
307
390
|
return true;
|
|
308
391
|
if (/\{\d+(?:,\d*)?\}/.test(term))
|
|
309
392
|
return true;
|
|
310
|
-
if (term.includes('|')) {
|
|
311
|
-
const branches = term.split('|');
|
|
312
|
-
return branches.length >= 2 && branches.every(isWordLikeBranch);
|
|
313
|
-
}
|
|
314
393
|
return false;
|
|
315
394
|
}
|
|
316
395
|
/**
|
|
317
|
-
*
|
|
396
|
+
* auto 模式下把 `a|b|c` 编译为「分支字面 OR」
|
|
318
397
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
398
|
+
* 分支各自 trim + 转义后以 `|` 连接(`.` 是字面点,不是通配),
|
|
399
|
+
* 对应模型自然写法 `foo()|a+b`。任一分支为空(`foo|`、`|`、`a||b`)
|
|
400
|
+
* 则放弃(返回 null),整词按字面搜——竖线在正则里是空分支语义,代码里几乎从不想要。
|
|
401
|
+
*
|
|
402
|
+
* @param term - 含 `|` 的搜索词
|
|
403
|
+
* @param flags - 正则标志(大小写敏感性由调用方给)
|
|
404
|
+
* @returns 分支字面 OR 正则;不适合作交替时 null(调用方按整词字面处理)
|
|
321
405
|
*/
|
|
322
|
-
function
|
|
323
|
-
|
|
406
|
+
function compileAlternationLiteral(term, flags) {
|
|
407
|
+
const branches = term.split('|').map((b) => b.trim());
|
|
408
|
+
if (branches.length < 2 || branches.some((b) => b.length === 0))
|
|
409
|
+
return null;
|
|
410
|
+
return new RegExp(branches.map((b) => escapeRegex(b)).join('|'), flags);
|
|
324
411
|
}
|
|
325
412
|
/**
|
|
326
413
|
* 转义正则特殊字符
|
|
@@ -357,6 +444,7 @@ function compileContentMatchers(terms, requested, caseSensitive) {
|
|
|
357
444
|
else
|
|
358
445
|
asRegex = looksLikeRegex(term);
|
|
359
446
|
let re = null;
|
|
447
|
+
let forcedLiteral = false;
|
|
360
448
|
if (asRegex) {
|
|
361
449
|
try {
|
|
362
450
|
re = new RegExp(term, flags);
|
|
@@ -366,10 +454,15 @@ function compileContentMatchers(terms, requested, caseSensitive) {
|
|
|
366
454
|
throw new Error(`Invalid pattern: ${error instanceof Error ? error.message : String(error)}`);
|
|
367
455
|
}
|
|
368
456
|
// auto 下像正则但编译失败 → 回退字面量
|
|
457
|
+
forcedLiteral = true;
|
|
369
458
|
autoForcedLiteral = true;
|
|
370
459
|
asRegex = false;
|
|
371
460
|
}
|
|
372
461
|
}
|
|
462
|
+
if (!re && requested === 'auto' && !forcedLiteral && term.includes('|')) {
|
|
463
|
+
// auto 的 `a|b`:分支字面 OR(分支 trim + 转义,`.` 是字面点);空分支 → 整词字面
|
|
464
|
+
re = compileAlternationLiteral(term, flags);
|
|
465
|
+
}
|
|
373
466
|
if (!re) {
|
|
374
467
|
re = new RegExp(escapeRegex(term), flags);
|
|
375
468
|
}
|
|
@@ -606,6 +699,84 @@ function splitBraceAlts(body) {
|
|
|
606
699
|
alts.push(current);
|
|
607
700
|
return alts;
|
|
608
701
|
}
|
|
702
|
+
// ── L1 输出收缩(F1-B1:结构化硬顶,零 LLM) ──
|
|
703
|
+
/**
|
|
704
|
+
* L1 结构化收缩:把 matches 清单体压进预算,定位符(file+line)永远全保
|
|
705
|
+
*
|
|
706
|
+
* 收缩顺序(arch/long-session-latency.md §5 B1):
|
|
707
|
+
* 1. 剥 before/after 上下文行;
|
|
708
|
+
* 2. content 行截到 `contentPreviewChars`(显式截断标记);
|
|
709
|
+
* 3. 预览只留前 K 条,其余保留 file+line + 省略占位。
|
|
710
|
+
* 即使 K=0 仍超预算,file+line 清单也全保(定位符零损失优先于预算)。
|
|
711
|
+
*
|
|
712
|
+
* @param matches - 原始命中列表
|
|
713
|
+
* @param budgetChars - matches 清单体的 JSON 字符预算
|
|
714
|
+
* @param contentPreviewChars - content 预览行字符上限
|
|
715
|
+
* @returns 收缩后的 matches 与收缩记录(未收缩时无 cap)
|
|
716
|
+
*/
|
|
717
|
+
function shrinkMatchesForBudget(matches, budgetChars, contentPreviewChars = CONTENT_PREVIEW_CHARS) {
|
|
718
|
+
const rawLength = JSON.stringify(matches).length;
|
|
719
|
+
if (rawLength <= budgetChars)
|
|
720
|
+
return { matches };
|
|
721
|
+
const stages = [];
|
|
722
|
+
const makeCap = (previewKept) => ({
|
|
723
|
+
applied: true,
|
|
724
|
+
stages,
|
|
725
|
+
rawLength,
|
|
726
|
+
budgetChars,
|
|
727
|
+
contentPreviewChars,
|
|
728
|
+
previewKept,
|
|
729
|
+
});
|
|
730
|
+
// 阶段 1:剥 before/after 上下文行
|
|
731
|
+
const hadContext = matches.some((m) => (m.before?.length ?? 0) > 0 || (m.after?.length ?? 0) > 0);
|
|
732
|
+
let current = matches.map((m) => ({ file: m.file, line: m.line, content: m.content }));
|
|
733
|
+
if (hadContext)
|
|
734
|
+
stages.push('context_lines');
|
|
735
|
+
if (JSON.stringify(current).length <= budgetChars) {
|
|
736
|
+
return { matches: current, cap: makeCap(current.length) };
|
|
737
|
+
}
|
|
738
|
+
// 阶段 2:content 行截到 contentPreviewChars(超长行是单条膨胀元凶)
|
|
739
|
+
// 只在真的截断了行时才计入 stages:否则 hint 会谎报 content_lines,
|
|
740
|
+
// 让调用方误以为要重跑窄命令拿回完整行(实际是被省略的预览,应 file_read)。
|
|
741
|
+
const contentTruncated = current.some((m) => m.content.length > contentPreviewChars);
|
|
742
|
+
if (contentTruncated) {
|
|
743
|
+
current = current.map((m) => m.content.length > contentPreviewChars
|
|
744
|
+
? {
|
|
745
|
+
file: m.file,
|
|
746
|
+
line: m.line,
|
|
747
|
+
content: `${m.content.slice(0, contentPreviewChars)}${CONTENT_TRUNCATED_MARK}`,
|
|
748
|
+
}
|
|
749
|
+
: m);
|
|
750
|
+
stages.push('content_lines');
|
|
751
|
+
if (JSON.stringify(current).length <= budgetChars) {
|
|
752
|
+
return { matches: current, cap: makeCap(current.length) };
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
// 阶段 3:预览只留前 K 条;file+line 紧凑清单全保
|
|
756
|
+
stages.push('preview_cap');
|
|
757
|
+
for (let kept = current.length - 1; kept >= 0; kept--) {
|
|
758
|
+
const trial = current.map((m, i) => i < kept ? m : { file: m.file, line: m.line, content: PREVIEW_OMITTED });
|
|
759
|
+
if (JSON.stringify(trial).length <= budgetChars) {
|
|
760
|
+
return { matches: trial, cap: makeCap(kept) };
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
// 全部省略预览仍超预算:定位符清单按设计全保,接受超出
|
|
764
|
+
return {
|
|
765
|
+
matches: current.map((m) => ({ file: m.file, line: m.line, content: PREVIEW_OMITTED })),
|
|
766
|
+
cap: makeCap(0),
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* 构建 L1 收缩后的自纠提示
|
|
771
|
+
*
|
|
772
|
+
* @param cap - 收缩记录
|
|
773
|
+
* @returns 可操作提示(如何拿回完整内容)
|
|
774
|
+
*/
|
|
775
|
+
function buildOutputCapHint(cap) {
|
|
776
|
+
return (`L1 output cap applied (${cap.stages.join('+')}): match bodies shrunk to fit maxReturnChars=${cap.budgetChars}; ` +
|
|
777
|
+
'the file+line list is complete. Narrow the glob/path or lower max_results for full lines, ' +
|
|
778
|
+
'or file_read the specific files.');
|
|
779
|
+
}
|
|
609
780
|
// ── hints ──
|
|
610
781
|
/**
|
|
611
782
|
* 构建零结果 / 异常检索的自纠提示
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared safe-git runner — the single hardened `git` execution path used by the
|
|
3
|
+
* git_* dedicated tools and the UI git-status snapshot.
|
|
4
|
+
*
|
|
5
|
+
* Not a shell: fixed argv allowlist (never a command string). Isolation here:
|
|
6
|
+
* nonexistent `core.hooksPath`, `--no-ext-diff`, command-line `-c` overrides
|
|
7
|
+
* (diff.external/gpg/pager/ssh), `GIT_CONFIG_GLOBAL/SYSTEM` at NUL//dev/null,
|
|
8
|
+
* and filter.* pinned to `cat`. Mutating callers add their own flags (e.g.
|
|
9
|
+
* `--no-verify`/`--no-gpg-sign` on commit, in git-tools.ts).
|
|
10
|
+
* User `-c`/alias flags are rejected. `--no-optional-locks` keeps polling
|
|
11
|
+
* readers from fighting real git operations over the index lock.
|
|
12
|
+
*/
|
|
13
|
+
import type { ToolExecutionContext } from '@octopi-agent/core/types.js';
|
|
14
|
+
import { type AllowlistedRunResult } from './allowlisted-run.js';
|
|
15
|
+
export interface RunGitOptions {
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/** Journal write effects via shell-journal (default true for mutating tools) */
|
|
18
|
+
journal?: boolean;
|
|
19
|
+
/** Apply the tool output gate (default true). Structured consumers pass false. */
|
|
20
|
+
applyOutputGate?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Run one fixed git argv vector through the hardened runner.
|
|
24
|
+
*
|
|
25
|
+
* @param context - tool context (optional; gates journalling/limits)
|
|
26
|
+
* @param cwd - repository directory (caller has resolved/contained it)
|
|
27
|
+
* @param args - git argv after the safety prefix
|
|
28
|
+
* @param options - timeout / journal / output-gate controls
|
|
29
|
+
* @returns capped stdout/stderr + honest isolation
|
|
30
|
+
*/
|
|
31
|
+
export declare function runGit(context: ToolExecutionContext | undefined, cwd: string, args: string[], options?: RunGitOptions): Promise<AllowlistedRunResult>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { tmpdir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { requireExecutable, runAllowlistedArgv, } from './allowlisted-run.js';
|
|
4
|
+
/**
|
|
5
|
+
* Nonexistent hooks dir (empty core.hooksPath is version-fragile: some gits
|
|
6
|
+
* treat it as `./` and still run cwd hooks).
|
|
7
|
+
*/
|
|
8
|
+
function noHooksDir() {
|
|
9
|
+
return join(tmpdir(), 'octopi-nohooks');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fixed git safety prefix. Command-line `-c` outranks local `.git/config`, so
|
|
13
|
+
* these neutralize repo-config RCE vectors (diff.external, gpg.program, …).
|
|
14
|
+
* `--no-optional-locks` avoids index lock fights. Never pass user `-c`.
|
|
15
|
+
*/
|
|
16
|
+
function gitSafePrefix() {
|
|
17
|
+
const hooks = noHooksDir();
|
|
18
|
+
return [
|
|
19
|
+
'--no-optional-locks',
|
|
20
|
+
'-c', `core.hooksPath=${hooks}`,
|
|
21
|
+
'-c', 'core.fsmonitor=',
|
|
22
|
+
'-c', 'core.pager=cat',
|
|
23
|
+
'-c', 'diff.external=',
|
|
24
|
+
'-c', 'diff.tool=',
|
|
25
|
+
'-c', 'merge.tool=',
|
|
26
|
+
'-c', 'merge.prompt=false',
|
|
27
|
+
'-c', 'gpg.program=true',
|
|
28
|
+
'-c', 'commit.gpgsign=false',
|
|
29
|
+
'-c', 'core.sshCommand=',
|
|
30
|
+
'-c', 'core.askpass=',
|
|
31
|
+
'-c', 'credential.helper=',
|
|
32
|
+
'-c', 'core.attributesFile=',
|
|
33
|
+
'-c', 'core.excludesFile=',
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Isolate global/system gitconfig. Local `.git/config` is still read; dangerous
|
|
38
|
+
* keys there are overridden by the `-c` prefix above (command line wins).
|
|
39
|
+
* On Windows use `NUL`, elsewhere `/dev/null` — a missing file is also fine.
|
|
40
|
+
*/
|
|
41
|
+
function gitIsolationEnv() {
|
|
42
|
+
const nullPath = process.platform === 'win32' ? 'NUL' : '/dev/null';
|
|
43
|
+
return {
|
|
44
|
+
GIT_CONFIG_NOSYSTEM: '1',
|
|
45
|
+
GIT_CONFIG_SYSTEM: nullPath,
|
|
46
|
+
GIT_CONFIG_GLOBAL: nullPath,
|
|
47
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
48
|
+
GIT_OPTIONAL_LOCKS: '0',
|
|
49
|
+
GIT_ASKPASS: '',
|
|
50
|
+
SSH_ASKPASS: '',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Discover filter.* drivers from repo/user config and pin them to `cat`.
|
|
55
|
+
* Command-line `-c` outranks local `.git/config`, so a malicious
|
|
56
|
+
* .gitattributes cannot run clean/smudge/process during `git add` — nor while
|
|
57
|
+
* `git status` re-hashes dirty stat entries through the clean filter.
|
|
58
|
+
*/
|
|
59
|
+
async function filterNeutralizers(context, cwd) {
|
|
60
|
+
const git = requireExecutable('git');
|
|
61
|
+
const res = await runAllowlistedArgv({
|
|
62
|
+
executable: git,
|
|
63
|
+
args: [...gitSafePrefix(), 'config', '--name-only', '--get-regexp', '^filter\\.'],
|
|
64
|
+
cwd,
|
|
65
|
+
context,
|
|
66
|
+
env: gitIsolationEnv(),
|
|
67
|
+
journal: false,
|
|
68
|
+
});
|
|
69
|
+
if (res.exitCode !== 0)
|
|
70
|
+
return [];
|
|
71
|
+
const names = new Set();
|
|
72
|
+
for (const line of res.stdout.split(/\r?\n/)) {
|
|
73
|
+
const m = /^filter\.(.+)\.(clean|smudge|process)$/.exec(line.trim());
|
|
74
|
+
if (m && /^[A-Za-z0-9._-]+$/.test(m[1]))
|
|
75
|
+
names.add(m[1]);
|
|
76
|
+
}
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const n of names) {
|
|
79
|
+
out.push('-c', `filter.${n}.clean=cat`, '-c', `filter.${n}.smudge=cat`, '-c', `filter.${n}.process=cat`);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Run one fixed git argv vector through the hardened runner.
|
|
85
|
+
*
|
|
86
|
+
* @param context - tool context (optional; gates journalling/limits)
|
|
87
|
+
* @param cwd - repository directory (caller has resolved/contained it)
|
|
88
|
+
* @param args - git argv after the safety prefix
|
|
89
|
+
* @param options - timeout / journal / output-gate controls
|
|
90
|
+
* @returns capped stdout/stderr + honest isolation
|
|
91
|
+
*/
|
|
92
|
+
export async function runGit(context, cwd, args, options) {
|
|
93
|
+
const git = requireExecutable('git');
|
|
94
|
+
return runAllowlistedArgv({
|
|
95
|
+
executable: git,
|
|
96
|
+
args: [...gitSafePrefix(), ...(await filterNeutralizers(context, cwd)), ...args],
|
|
97
|
+
cwd,
|
|
98
|
+
context,
|
|
99
|
+
env: gitIsolationEnv(),
|
|
100
|
+
timeoutMs: options?.timeoutMs ?? 60_000,
|
|
101
|
+
journal: options?.journal ?? false,
|
|
102
|
+
applyOutputGate: options?.applyOutputGate,
|
|
103
|
+
});
|
|
104
|
+
}
|