@octopi-agent/engine 0.70.7 → 0.86.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +69 -0
- package/dist/config-schema/context.d.ts +23 -4
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +201 -9
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +91 -0
- package/dist/config-schema/models.d.ts +1 -1
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +10 -0
- package/dist/config-schema/shared.js +10 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +178 -7
- package/dist/config.js +113 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +47 -3
- package/dist/harness/agent/builder.js +180 -54
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +81 -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 +38 -0
- package/dist/harness/agent/tool-purpose.js +118 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +363 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/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 +49 -1
- package/dist/harness/context/layer-types.js +72 -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 +67 -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 +248 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +334 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +493 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +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 +45 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +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 +239 -61
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.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 +14 -12
- package/dist/harness/index.js +9 -6
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +6 -3
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.js +4 -1
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/query-service.js +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-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 +23 -1
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +57 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +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 +101 -16
- package/dist/harness/run/runner.js +556 -158
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +1 -0
- package/dist/harness/session/in-memory-store.d.ts +1 -0
- package/dist/harness/session/in-memory-store.js +22 -1
- package/dist/harness/session/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/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +13 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.js +10 -2
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +11 -0
- package/dist/integration/storage/jsonl.js +148 -39
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -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/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,50 @@ 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
52
|
'Provide `pattern` (one term) or `patterns` (any-of literals). ' +
|
|
36
53
|
'Default pattern_mode=auto compiles as regex only on strong signals: ' +
|
|
37
|
-
'anchors (^…$), escapes (\\d \\w \\s), `.*`/`.+`, `{n}` quantifiers
|
|
54
|
+
'anchors (^…$), escapes (\\d \\w \\s), `.*`/`.+`, `{n}` quantifiers. ' +
|
|
55
|
+
'In auto, `a|b` is a literal OR of trimmed branches (`.` is a literal dot, not a wildcard); ' +
|
|
56
|
+
'an empty branch (`foo|`, `|`) falls back to whole-term literal. ' +
|
|
38
57
|
'Code tokens stay literal: `arr[0]`, `useState()`, `a+b`, `C++`, `foo.bar`, `memory*`. ' +
|
|
39
58
|
'Set pattern_mode="regex" or "literal" to force. ' +
|
|
40
59
|
"Glob filters by root-relative path (always case-insensitive): '*.md' (any depth), 'src/**/*.ts', '**/memory*.md'. " +
|
|
41
60
|
"`**` crosses directories, `*` does not. " +
|
|
61
|
+
'Path: a directory to walk recursively, or a single file path to search just that file. ' +
|
|
42
62
|
'Empty results include diagnostics.hints for how to retry. ' +
|
|
43
63
|
'Default case-insensitive content match; set case_sensitive=true for exact case. ' +
|
|
44
|
-
'Files are read as line streams; max_file_bytes (default 50MB) skips oversized files.'
|
|
64
|
+
'Files are read as line streams; max_file_bytes (default 50MB) skips oversized files. ' +
|
|
65
|
+
'Files whose first 4KB contains a NUL byte are treated as binary and skipped.',
|
|
45
66
|
parameters: {
|
|
46
67
|
pattern: {
|
|
47
68
|
type: 'string',
|
|
48
|
-
description: 'Single search term. Auto: regex only for ^ $ \\d .* {n}
|
|
69
|
+
description: 'Single search term. Auto: regex only for ^ $ \\d .* {n}; ' +
|
|
70
|
+
'`a|b` = literal OR of trimmed branches (empty branch → whole-term literal); ' +
|
|
71
|
+
'everything else is literal text.',
|
|
49
72
|
},
|
|
50
73
|
patterns: {
|
|
51
74
|
type: 'array',
|
|
52
|
-
description: 'Multiple terms; a line matches if ANY term matches.
|
|
75
|
+
description: 'Multiple terms; a line matches if ANY term matches.',
|
|
53
76
|
items: { type: 'string', description: 'search term' },
|
|
54
77
|
minItems: 1,
|
|
55
78
|
},
|
|
@@ -97,11 +120,14 @@ export function createFileSearchTool() {
|
|
|
97
120
|
timeoutMs: 30_000,
|
|
98
121
|
},
|
|
99
122
|
handler: async (args, context) => {
|
|
100
|
-
const { readdir, stat } = await import('node:fs/promises');
|
|
101
|
-
const { join, relative
|
|
123
|
+
const { open, readdir, stat } = await import('node:fs/promises');
|
|
124
|
+
const { basename, extname, join, relative } = await import('node:path');
|
|
102
125
|
const rawRoot = args.path;
|
|
103
126
|
const rootPath = rawRoot
|
|
104
|
-
? resolveToolPath(rawRoot, context.cwd ?? process.cwd()
|
|
127
|
+
? resolveToolPath(rawRoot, context.cwd ?? process.cwd(), {
|
|
128
|
+
allowRoots: context.pathRoots,
|
|
129
|
+
containment: context.pathContainment,
|
|
130
|
+
})
|
|
105
131
|
: (context.cwd ?? process.cwd());
|
|
106
132
|
const terms = collectPatternTerms(args);
|
|
107
133
|
const patternMode = resolvePatternMode(args);
|
|
@@ -128,7 +154,76 @@ export function createFileSearchTool() {
|
|
|
128
154
|
let filesSearched = 0;
|
|
129
155
|
let filesSkipped = 0;
|
|
130
156
|
let filesSkippedOversize = 0;
|
|
157
|
+
let filesSkippedBinary = 0;
|
|
158
|
+
const perFileCounts = new Map();
|
|
131
159
|
let truncated = false;
|
|
160
|
+
async function considerFile(fullPath, relPath) {
|
|
161
|
+
if (truncated)
|
|
162
|
+
return;
|
|
163
|
+
filesSeen += 1;
|
|
164
|
+
// glob 过滤:root 相对路径(无 `/` 的模式等价于任意深度 globstar)
|
|
165
|
+
if (fileFilter && !fileFilter.test(relPath))
|
|
166
|
+
return;
|
|
167
|
+
filesMatchedByGlob += 1;
|
|
168
|
+
// 扩展名粗判二进制,避免把不可读内容塞进结果
|
|
169
|
+
const ext = extname(fullPath).toLowerCase();
|
|
170
|
+
if (BINARY_EXTENSIONS.has(ext)) {
|
|
171
|
+
filesSkipped += 1;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
let size = 0;
|
|
175
|
+
try {
|
|
176
|
+
size = (await stat(fullPath)).size;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// stat 失败(竞态删除/无权限)→ 跳过该文件
|
|
180
|
+
filesSkipped += 1;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (size > maxFileBytes) {
|
|
184
|
+
filesSkipped += 1;
|
|
185
|
+
filesSkippedOversize += 1;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// 内容嗅探:头 4KB 含 NUL 视为二进制(扩展名粗判覆盖不到的 .bin/.dat/无后缀二进制)。
|
|
189
|
+
// NUL 在 UTF-8/UTF-16 文本中不出现,误判面可忽略;吞掉读失败并按可读处理(下行扫描自会兜底)。
|
|
190
|
+
if (size > 0) {
|
|
191
|
+
let handle;
|
|
192
|
+
try {
|
|
193
|
+
handle = await open(fullPath, 'r');
|
|
194
|
+
const buf = Buffer.alloc(Math.min(4096, size));
|
|
195
|
+
const { bytesRead } = await handle.read(buf, 0, buf.length, 0);
|
|
196
|
+
if (buf.subarray(0, bytesRead).includes(0)) {
|
|
197
|
+
filesSkipped += 1;
|
|
198
|
+
filesSkippedBinary += 1;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
// 读失败:不计二进制,交由下方行扫描决定(其失败路径计 filesSkipped)
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
await handle?.close().catch(() => {
|
|
207
|
+
// 关闭失败不影响搜索结果;句柄随进程回收
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
filesSearched += 1;
|
|
212
|
+
await searchFileLines({
|
|
213
|
+
fullPath,
|
|
214
|
+
relPath,
|
|
215
|
+
matchers: content.matchers,
|
|
216
|
+
contextLines,
|
|
217
|
+
onMatch: (match) => {
|
|
218
|
+
allMatches.push(match);
|
|
219
|
+
perFileCounts.set(match.file, (perFileCounts.get(match.file) ?? 0) + 1);
|
|
220
|
+
if (allMatches.length >= maxResults) {
|
|
221
|
+
truncated = true;
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
shouldStop: () => truncated,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
132
227
|
async function walk(dir) {
|
|
133
228
|
if (truncated)
|
|
134
229
|
return;
|
|
@@ -151,51 +246,21 @@ export function createFileSearchTool() {
|
|
|
151
246
|
}
|
|
152
247
|
if (!entry.isFile())
|
|
153
248
|
continue;
|
|
154
|
-
filesSeen += 1;
|
|
155
249
|
// 统一为 `/`,保证 Windows 相对路径也能过 glob
|
|
156
250
|
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
|
-
});
|
|
251
|
+
await considerFile(fullPath, relPath);
|
|
195
252
|
}
|
|
196
253
|
}
|
|
197
|
-
|
|
254
|
+
// path 可为目录(递归)或单文件(只搜该文件)
|
|
255
|
+
const rootInfo = await stat(rootPath).catch(() => null);
|
|
256
|
+
if (rootInfo?.isFile()) {
|
|
257
|
+
await considerFile(rootPath, basename(rootPath).split('\\').join('/'));
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
await walk(rootPath);
|
|
261
|
+
}
|
|
198
262
|
const diagnostics = {
|
|
263
|
+
root: rootPath,
|
|
199
264
|
patternMode: content.mode,
|
|
200
265
|
patterns: content.sources,
|
|
201
266
|
compiledPatterns: content.compiled,
|
|
@@ -206,8 +271,13 @@ export function createFileSearchTool() {
|
|
|
206
271
|
filesSearched,
|
|
207
272
|
filesSkipped,
|
|
208
273
|
filesSkippedOversize,
|
|
274
|
+
filesSkippedBinary,
|
|
209
275
|
maxFileBytes,
|
|
210
276
|
};
|
|
277
|
+
// 每文件命中聚合:降序(命中多的优先),同数按文件名升序
|
|
278
|
+
const matchedFiles = [...perFileCounts.entries()]
|
|
279
|
+
.map(([file, matches]) => ({ file, matches }))
|
|
280
|
+
.sort((a, b) => b.matches - a.matches || (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
|
|
211
281
|
const hints = buildHints({
|
|
212
282
|
totalMatches: allMatches.length,
|
|
213
283
|
content,
|
|
@@ -220,10 +290,30 @@ export function createFileSearchTool() {
|
|
|
220
290
|
filesSkippedOversize,
|
|
221
291
|
maxFileBytes,
|
|
222
292
|
});
|
|
293
|
+
// F1-B1:L1 结构化硬顶(零 LLM)。定位符(file+line)永远全保,只收缩预览体;
|
|
294
|
+
// 不走字符串 gate,避免截断 JSON 丢掉尾部定位符。
|
|
295
|
+
// 注:预算只约束 matches 清单体;matchedFiles/diagnostics/hints 不进预算。
|
|
296
|
+
// file_search 不经过外层 applyToolOutputGate(否则会按字符腰斩 JSON),
|
|
297
|
+
// 因此超出预算是安全的——设计上定位符优先于预算。
|
|
298
|
+
const binding = resolveSupportBinding('file_search', options?.summary, DEFAULT_MAX_RETURN_CHARS);
|
|
299
|
+
const shrunk = shrinkMatchesForBudget(allMatches, binding.maxReturnChars);
|
|
300
|
+
if (shrunk.cap) {
|
|
301
|
+
hints.push(buildOutputCapHint(shrunk.cap));
|
|
302
|
+
}
|
|
303
|
+
const truncatedReason = truncated && shrunk.cap
|
|
304
|
+
? 'max_results+l1_cap'
|
|
305
|
+
: truncated
|
|
306
|
+
? 'max_results'
|
|
307
|
+
: shrunk.cap
|
|
308
|
+
? 'l1_cap'
|
|
309
|
+
: undefined;
|
|
223
310
|
return {
|
|
224
|
-
matches:
|
|
311
|
+
matches: shrunk.matches,
|
|
225
312
|
totalMatches: allMatches.length,
|
|
226
|
-
|
|
313
|
+
matchedFiles,
|
|
314
|
+
truncated: truncated || Boolean(shrunk.cap),
|
|
315
|
+
truncatedReason,
|
|
316
|
+
outputCap: shrunk.cap,
|
|
227
317
|
searchedFiles: filesSearched,
|
|
228
318
|
diagnostics,
|
|
229
319
|
hints,
|
|
@@ -292,7 +382,7 @@ function resolveMaxFileBytes(args) {
|
|
|
292
382
|
*
|
|
293
383
|
* 只认强信号。代码字面量保持 literal:
|
|
294
384
|
* `arr[0]` / `useState()` / `a+b` / `C++` / `foo.bar` / `memory*` 均不为正则。
|
|
295
|
-
*
|
|
385
|
+
* `|` 不是正则信号:`a|b` 走 compileAlternationLiteral 的分支字面 OR。
|
|
296
386
|
*
|
|
297
387
|
* @param term - 搜索词
|
|
298
388
|
* @returns 是否像正则
|
|
@@ -307,20 +397,24 @@ function looksLikeRegex(term) {
|
|
|
307
397
|
return true;
|
|
308
398
|
if (/\{\d+(?:,\d*)?\}/.test(term))
|
|
309
399
|
return true;
|
|
310
|
-
if (term.includes('|')) {
|
|
311
|
-
const branches = term.split('|');
|
|
312
|
-
return branches.length >= 2 && branches.every(isWordLikeBranch);
|
|
313
|
-
}
|
|
314
400
|
return false;
|
|
315
401
|
}
|
|
316
402
|
/**
|
|
317
|
-
*
|
|
403
|
+
* auto 模式下把 `a|b|c` 编译为「分支字面 OR」
|
|
318
404
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
405
|
+
* 分支各自 trim + 转义后以 `|` 连接(`.` 是字面点,不是通配),
|
|
406
|
+
* 对应模型自然写法 `foo()|a+b`。任一分支为空(`foo|`、`|`、`a||b`)
|
|
407
|
+
* 则放弃(返回 null),整词按字面搜——竖线在正则里是空分支语义,代码里几乎从不想要。
|
|
408
|
+
*
|
|
409
|
+
* @param term - 含 `|` 的搜索词
|
|
410
|
+
* @param flags - 正则标志(大小写敏感性由调用方给)
|
|
411
|
+
* @returns 分支字面 OR 正则;不适合作交替时 null(调用方按整词字面处理)
|
|
321
412
|
*/
|
|
322
|
-
function
|
|
323
|
-
|
|
413
|
+
function compileAlternationLiteral(term, flags) {
|
|
414
|
+
const branches = term.split('|').map((b) => b.trim());
|
|
415
|
+
if (branches.length < 2 || branches.some((b) => b.length === 0))
|
|
416
|
+
return null;
|
|
417
|
+
return new RegExp(branches.map((b) => escapeRegex(b)).join('|'), flags);
|
|
324
418
|
}
|
|
325
419
|
/**
|
|
326
420
|
* 转义正则特殊字符
|
|
@@ -357,6 +451,7 @@ function compileContentMatchers(terms, requested, caseSensitive) {
|
|
|
357
451
|
else
|
|
358
452
|
asRegex = looksLikeRegex(term);
|
|
359
453
|
let re = null;
|
|
454
|
+
let forcedLiteral = false;
|
|
360
455
|
if (asRegex) {
|
|
361
456
|
try {
|
|
362
457
|
re = new RegExp(term, flags);
|
|
@@ -366,10 +461,15 @@ function compileContentMatchers(terms, requested, caseSensitive) {
|
|
|
366
461
|
throw new Error(`Invalid pattern: ${error instanceof Error ? error.message : String(error)}`);
|
|
367
462
|
}
|
|
368
463
|
// auto 下像正则但编译失败 → 回退字面量
|
|
464
|
+
forcedLiteral = true;
|
|
369
465
|
autoForcedLiteral = true;
|
|
370
466
|
asRegex = false;
|
|
371
467
|
}
|
|
372
468
|
}
|
|
469
|
+
if (!re && requested === 'auto' && !forcedLiteral && term.includes('|')) {
|
|
470
|
+
// auto 的 `a|b`:分支字面 OR(分支 trim + 转义,`.` 是字面点);空分支 → 整词字面
|
|
471
|
+
re = compileAlternationLiteral(term, flags);
|
|
472
|
+
}
|
|
373
473
|
if (!re) {
|
|
374
474
|
re = new RegExp(escapeRegex(term), flags);
|
|
375
475
|
}
|
|
@@ -606,6 +706,84 @@ function splitBraceAlts(body) {
|
|
|
606
706
|
alts.push(current);
|
|
607
707
|
return alts;
|
|
608
708
|
}
|
|
709
|
+
// ── L1 输出收缩(F1-B1:结构化硬顶,零 LLM) ──
|
|
710
|
+
/**
|
|
711
|
+
* L1 结构化收缩:把 matches 清单体压进预算,定位符(file+line)永远全保
|
|
712
|
+
*
|
|
713
|
+
* 收缩顺序(arch/long-session-latency.md §5 B1):
|
|
714
|
+
* 1. 剥 before/after 上下文行;
|
|
715
|
+
* 2. content 行截到 `contentPreviewChars`(显式截断标记);
|
|
716
|
+
* 3. 预览只留前 K 条,其余保留 file+line + 省略占位。
|
|
717
|
+
* 即使 K=0 仍超预算,file+line 清单也全保(定位符零损失优先于预算)。
|
|
718
|
+
*
|
|
719
|
+
* @param matches - 原始命中列表
|
|
720
|
+
* @param budgetChars - matches 清单体的 JSON 字符预算
|
|
721
|
+
* @param contentPreviewChars - content 预览行字符上限
|
|
722
|
+
* @returns 收缩后的 matches 与收缩记录(未收缩时无 cap)
|
|
723
|
+
*/
|
|
724
|
+
function shrinkMatchesForBudget(matches, budgetChars, contentPreviewChars = CONTENT_PREVIEW_CHARS) {
|
|
725
|
+
const rawLength = JSON.stringify(matches).length;
|
|
726
|
+
if (rawLength <= budgetChars)
|
|
727
|
+
return { matches };
|
|
728
|
+
const stages = [];
|
|
729
|
+
const makeCap = (previewKept) => ({
|
|
730
|
+
applied: true,
|
|
731
|
+
stages,
|
|
732
|
+
rawLength,
|
|
733
|
+
budgetChars,
|
|
734
|
+
contentPreviewChars,
|
|
735
|
+
previewKept,
|
|
736
|
+
});
|
|
737
|
+
// 阶段 1:剥 before/after 上下文行
|
|
738
|
+
const hadContext = matches.some((m) => (m.before?.length ?? 0) > 0 || (m.after?.length ?? 0) > 0);
|
|
739
|
+
let current = matches.map((m) => ({ file: m.file, line: m.line, content: m.content }));
|
|
740
|
+
if (hadContext)
|
|
741
|
+
stages.push('context_lines');
|
|
742
|
+
if (JSON.stringify(current).length <= budgetChars) {
|
|
743
|
+
return { matches: current, cap: makeCap(current.length) };
|
|
744
|
+
}
|
|
745
|
+
// 阶段 2:content 行截到 contentPreviewChars(超长行是单条膨胀元凶)
|
|
746
|
+
// 只在真的截断了行时才计入 stages:否则 hint 会谎报 content_lines,
|
|
747
|
+
// 让调用方误以为要重跑窄命令拿回完整行(实际是被省略的预览,应 file_read)。
|
|
748
|
+
const contentTruncated = current.some((m) => m.content.length > contentPreviewChars);
|
|
749
|
+
if (contentTruncated) {
|
|
750
|
+
current = current.map((m) => m.content.length > contentPreviewChars
|
|
751
|
+
? {
|
|
752
|
+
file: m.file,
|
|
753
|
+
line: m.line,
|
|
754
|
+
content: `${m.content.slice(0, contentPreviewChars)}${CONTENT_TRUNCATED_MARK}`,
|
|
755
|
+
}
|
|
756
|
+
: m);
|
|
757
|
+
stages.push('content_lines');
|
|
758
|
+
if (JSON.stringify(current).length <= budgetChars) {
|
|
759
|
+
return { matches: current, cap: makeCap(current.length) };
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
// 阶段 3:预览只留前 K 条;file+line 紧凑清单全保
|
|
763
|
+
stages.push('preview_cap');
|
|
764
|
+
for (let kept = current.length - 1; kept >= 0; kept--) {
|
|
765
|
+
const trial = current.map((m, i) => i < kept ? m : { file: m.file, line: m.line, content: PREVIEW_OMITTED });
|
|
766
|
+
if (JSON.stringify(trial).length <= budgetChars) {
|
|
767
|
+
return { matches: trial, cap: makeCap(kept) };
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
// 全部省略预览仍超预算:定位符清单按设计全保,接受超出
|
|
771
|
+
return {
|
|
772
|
+
matches: current.map((m) => ({ file: m.file, line: m.line, content: PREVIEW_OMITTED })),
|
|
773
|
+
cap: makeCap(0),
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* 构建 L1 收缩后的自纠提示
|
|
778
|
+
*
|
|
779
|
+
* @param cap - 收缩记录
|
|
780
|
+
* @returns 可操作提示(如何拿回完整内容)
|
|
781
|
+
*/
|
|
782
|
+
function buildOutputCapHint(cap) {
|
|
783
|
+
return (`L1 output cap applied (${cap.stages.join('+')}): match bodies shrunk to fit maxReturnChars=${cap.budgetChars}; ` +
|
|
784
|
+
'the file+line list is complete. Narrow the glob/path or lower max_results for full lines, ' +
|
|
785
|
+
'or file_read the specific files.');
|
|
786
|
+
}
|
|
609
787
|
// ── hints ──
|
|
610
788
|
/**
|
|
611
789
|
* 构建零结果 / 异常检索的自纠提示
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git_* dedicated tools 鈥?local VCS porcelain without a shell.
|
|
3
|
+
*
|
|
4
|
+
* Spawn `git` with a fixed argv allowlist (never a command string). Isolation:
|
|
5
|
+
* nonexistent `core.hooksPath`, `--no-verify`/`--no-gpg-sign` on commit,
|
|
6
|
+
* `--no-ext-diff`, command-line `-c` overrides (diff.external/gpg/pager/ssh),
|
|
7
|
+
* `GIT_CONFIG_GLOBAL/SYSTEM` at NUL//dev/null, and filter.* pinned to `cat`.
|
|
8
|
+
* User `-c`/alias flags are rejected. Capability tag is `vcs` (allowed on reduced surface) so
|
|
9
|
+
* workspace/untrusted agents can still status/diff/commit without `shell`.
|
|
10
|
+
*/
|
|
11
|
+
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
12
|
+
/** git_status 鈥?porcelain working tree status */
|
|
13
|
+
export declare function createGitStatusTool(): RegisteredTool;
|
|
14
|
+
/** git_diff 鈥?unstaged / staged / vs-ref diff */
|
|
15
|
+
export declare function createGitDiffTool(): RegisteredTool;
|
|
16
|
+
/** git_log 鈥?commit history */
|
|
17
|
+
export declare function createGitLogTool(): RegisteredTool;
|
|
18
|
+
/** git_show 鈥?show a commit / tree / blob */
|
|
19
|
+
export declare function createGitShowTool(): RegisteredTool;
|
|
20
|
+
/** git_commit 鈥?add paths + commit (hooks disabled) */
|
|
21
|
+
export declare function createGitCommitTool(): RegisteredTool;
|
|
22
|
+
/** git_branch 鈥?list / create / switch / delete */
|
|
23
|
+
export declare function createGitBranchTool(): RegisteredTool;
|
|
24
|
+
/** git_restore 鈥?restore working tree / index paths */
|
|
25
|
+
export declare function createGitRestoreTool(): RegisteredTool;
|
|
26
|
+
/** All git_* tools (read + write). */
|
|
27
|
+
export declare function createGitTools(): RegisteredTool[];
|