@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
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* delegate_* 工具 — 经 DelegateService 委派任务给子 agent
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/extension/plugin-ecosystem/tools
|
|
5
|
+
* 设计权威:`arch/delegation.md` §7 / §14。
|
|
6
|
+
*
|
|
7
|
+
* **非阻塞**(§7):`delegate_dispatch` 立即返回 `delegationId`,不等子 Run 结束。
|
|
8
|
+
* 结果回收走 `delegate_get`(poll)或 notify 通道(P3)。
|
|
9
|
+
*
|
|
10
|
+
* 工具与 `DelegateService` 分离:服务可被嵌入方直接用,不经 LLM 工具面。
|
|
11
|
+
*/
|
|
12
|
+
import { DelegateResolutionError } from '../../../collaboration/delegation/service.js';
|
|
13
|
+
import { isTerminalDelegationStatus } from '../../../collaboration/delegation/types.js';
|
|
14
|
+
/** 委派单摘要(进 LLM 结果,字段名 snake_case 对齐其他工具) */
|
|
15
|
+
function delegationSummary(d) {
|
|
16
|
+
return {
|
|
17
|
+
delegation_id: d.id,
|
|
18
|
+
status: d.status,
|
|
19
|
+
target: d.target.agentId ?? d.resolvedAgentId ?? d.target.trait,
|
|
20
|
+
resolved_agent_id: d.resolvedAgentId,
|
|
21
|
+
task: d.task,
|
|
22
|
+
depth: d.depth,
|
|
23
|
+
child_session_id: d.childSessionId,
|
|
24
|
+
output: d.output,
|
|
25
|
+
artifacts: d.artifacts,
|
|
26
|
+
error: d.error,
|
|
27
|
+
usage: d.usage,
|
|
28
|
+
created_at: d.createdAt,
|
|
29
|
+
started_at: d.startedAt,
|
|
30
|
+
completed_at: d.completedAt,
|
|
31
|
+
deadline_at: d.deadlineAt,
|
|
32
|
+
cancelable: d.cancelable,
|
|
33
|
+
cascade: d.cascade,
|
|
34
|
+
// surfaced = 结果已**送达**父:notify 投递成功或 delegate_get 全文取回。
|
|
35
|
+
// list/cancel 只见概览(可能截断)不计送达;delivering(投递进行中)也不算。
|
|
36
|
+
surfaced: d.deliveryState === 'surfaced',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 读取**本 Run** 的 effective session rights(D3:权限随调用传播)
|
|
41
|
+
*
|
|
42
|
+
* 经 RunScope ALS 取,保证并发 session 下拿到的是本 Run 的权威值(I1)。
|
|
43
|
+
* 不在 Run 中(或未启用 ACL)时返回 undefined —— 不叠加父约束。
|
|
44
|
+
*
|
|
45
|
+
* @returns 本 Run 的有效权限
|
|
46
|
+
*/
|
|
47
|
+
async function readRunSessionRights() {
|
|
48
|
+
const { getRunScope } = await import('../../../run/run-scope.js');
|
|
49
|
+
return getRunScope()?.toolRuntime?.sessionRights;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 把服务层解析错误转成 LLM 可读的失败结果(不抛栈)
|
|
53
|
+
*
|
|
54
|
+
* 解析失败时**一并回传可用目标**(traits / agents),
|
|
55
|
+
* 让调用方一次就能改对(改用 `agent:` 或换个 trait),而不是瞎猜重试。
|
|
56
|
+
*/
|
|
57
|
+
function resolutionFailure(err) {
|
|
58
|
+
if (err instanceof DelegateResolutionError) {
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
reason: err.reason,
|
|
62
|
+
error: err.message,
|
|
63
|
+
...(err.available ? { available_targets: err.available } : {}),
|
|
64
|
+
hint: err.reason === 'not_found'
|
|
65
|
+
? 'No agent matched. Retry with `agent: <id>` using an id from available_targets, or use a trait that exists.'
|
|
66
|
+
: undefined,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
+
return { ok: false, error: message };
|
|
71
|
+
}
|
|
72
|
+
/** 创建 delegate_* 工具集 */
|
|
73
|
+
export function createDelegationTools(service) {
|
|
74
|
+
return [
|
|
75
|
+
createDelegateDispatchTool(service),
|
|
76
|
+
createDelegateListTool(service),
|
|
77
|
+
createDelegateGetTool(service),
|
|
78
|
+
createDelegateCancelTool(service),
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `delegate_dispatch` — 非阻塞派发委派
|
|
83
|
+
*/
|
|
84
|
+
export function createDelegateDispatchTool(service) {
|
|
85
|
+
return {
|
|
86
|
+
definition: {
|
|
87
|
+
name: 'delegate_dispatch',
|
|
88
|
+
// 委派不写文件:不借用 fs-* 能力标签,避免 denyCapabilities:['fs-write'] 误禁委派
|
|
89
|
+
capabilities: [],
|
|
90
|
+
description: 'Delegate a task to another agent and return IMMEDIATELY with a delegation_id. ' +
|
|
91
|
+
'Non-blocking: the child runs in its own session and this call does NOT wait for the result. ' +
|
|
92
|
+
'Use delegate_get later (or wait for a delegation_status notice) to collect the result. ' +
|
|
93
|
+
'Specify exactly one of `agent` (explicit id) or `trait` (resolve by trait tag).',
|
|
94
|
+
parameters: {
|
|
95
|
+
agent: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
description: 'Target agentId (mutually exclusive with `trait`)',
|
|
98
|
+
},
|
|
99
|
+
trait: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
description: 'Trait tag to resolve the target (mutually exclusive with `agent`)',
|
|
102
|
+
},
|
|
103
|
+
task: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
description: 'What the child should accomplish (goes into the child user message)',
|
|
106
|
+
required: true,
|
|
107
|
+
},
|
|
108
|
+
input: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
description: 'Explicit input material for the task. The child does NOT inherit your context.',
|
|
111
|
+
required: true,
|
|
112
|
+
},
|
|
113
|
+
context: {
|
|
114
|
+
type: 'string',
|
|
115
|
+
enum: ['clean', 'fork'],
|
|
116
|
+
description: "Context mode. 'clean' (default) starts the child with no parent history; 'fork' passes your message history for background.",
|
|
117
|
+
},
|
|
118
|
+
max_turns: {
|
|
119
|
+
type: 'number',
|
|
120
|
+
description: 'Turn budget for the child run (intersected with the target ceiling)',
|
|
121
|
+
},
|
|
122
|
+
max_tokens: {
|
|
123
|
+
type: 'number',
|
|
124
|
+
description: 'Token budget for the child run (intersected with the target ceiling)',
|
|
125
|
+
},
|
|
126
|
+
timeout_ms: {
|
|
127
|
+
type: 'number',
|
|
128
|
+
description: 'Delegation timeout in milliseconds',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
handler: async (args, context) => {
|
|
133
|
+
const agent = args.agent ? String(args.agent) : undefined;
|
|
134
|
+
const trait = args.trait ? String(args.trait) : undefined;
|
|
135
|
+
if ((agent && trait) || (!agent && !trait)) {
|
|
136
|
+
return {
|
|
137
|
+
ok: false,
|
|
138
|
+
error: 'delegate_dispatch requires exactly one of `agent` or `trait`',
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const contextMode = args.context === 'fork' ? 'fork' : 'clean';
|
|
142
|
+
const timeoutMs = args.timeout_ms != null ? Number(args.timeout_ms) : undefined;
|
|
143
|
+
const maxTurns = args.max_turns != null ? Number(args.max_turns) : undefined;
|
|
144
|
+
const maxTokens = args.max_tokens != null ? Number(args.max_tokens) : undefined;
|
|
145
|
+
try {
|
|
146
|
+
const { delegation, resolvedAgentId } = await service.dispatch({
|
|
147
|
+
parent: {
|
|
148
|
+
agentId: context.agentId,
|
|
149
|
+
sessionId: context.sessionId,
|
|
150
|
+
runId: context.runId ?? '',
|
|
151
|
+
},
|
|
152
|
+
// D3 权限随调用传播:父的有效权限作为子的天花板,不得借委派提权
|
|
153
|
+
parentRights: await readRunSessionRights(),
|
|
154
|
+
target: agent ? { agentId: agent } : { trait },
|
|
155
|
+
task: String(args.task ?? ''),
|
|
156
|
+
input: String(args.input ?? ''),
|
|
157
|
+
context: contextMode,
|
|
158
|
+
// D1:传快照而非活数组引用——父 run 在子起跑后仍会 append
|
|
159
|
+
parentMessages: contextMode === 'fork' ? context.messages.map((m) => ({ ...m })) : undefined,
|
|
160
|
+
budget: maxTurns != null || maxTokens != null || timeoutMs != null
|
|
161
|
+
? { maxTurns, maxTokens, timeoutMs }
|
|
162
|
+
: undefined,
|
|
163
|
+
timeoutMs,
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
ok: true,
|
|
167
|
+
delegation_id: delegation.id,
|
|
168
|
+
resolved_agent_id: resolvedAgentId,
|
|
169
|
+
status: delegation.status,
|
|
170
|
+
note: 'Non-blocking: use delegate_get to collect the result later.',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
return resolutionFailure(err);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* `delegate_list` — 列出委派单(poll 通道 / 全景)
|
|
181
|
+
*/
|
|
182
|
+
export function createDelegateListTool(service) {
|
|
183
|
+
return {
|
|
184
|
+
definition: {
|
|
185
|
+
name: 'delegate_list',
|
|
186
|
+
capabilities: [],
|
|
187
|
+
description: 'List delegations issued from this session. Use to check progress of child agents ' +
|
|
188
|
+
'you dispatched, or to find delegation ids to collect with delegate_get.',
|
|
189
|
+
parameters: {
|
|
190
|
+
status: {
|
|
191
|
+
type: 'string',
|
|
192
|
+
enum: ['queued', 'running', 'completed', 'failed', 'cancelled', 'timeout'],
|
|
193
|
+
description: 'Filter by status',
|
|
194
|
+
},
|
|
195
|
+
active_only: {
|
|
196
|
+
type: 'boolean',
|
|
197
|
+
description: 'Only un-closed delegations (queued + running). Default false',
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
handler: async (args, context) => {
|
|
202
|
+
const status = args.status;
|
|
203
|
+
const activeOnly = Boolean(args.active_only);
|
|
204
|
+
const items = service.list({
|
|
205
|
+
parentSessionId: context.sessionId,
|
|
206
|
+
status,
|
|
207
|
+
activeOnly,
|
|
208
|
+
});
|
|
209
|
+
// 列表是只读概览:不 markSurfaced。结果可能被 ToolResultValidator 截断,
|
|
210
|
+
// 「标已送达」只留给明确取回单条全文的 delegate_get,宁可提示多留也不误消音
|
|
211
|
+
return {
|
|
212
|
+
delegations: items.map(delegationSummary),
|
|
213
|
+
total: items.length,
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* `delegate_get` — 取委派单详情 / 结果
|
|
220
|
+
*/
|
|
221
|
+
export function createDelegateGetTool(service) {
|
|
222
|
+
return {
|
|
223
|
+
definition: {
|
|
224
|
+
name: 'delegate_get',
|
|
225
|
+
capabilities: [],
|
|
226
|
+
description: 'Get one delegation by id, including its result when finished. ' +
|
|
227
|
+
'Returns status immediately if still running (this call does not block).',
|
|
228
|
+
parameters: {
|
|
229
|
+
delegation_id: {
|
|
230
|
+
type: 'string',
|
|
231
|
+
description: 'Delegation id from delegate_dispatch',
|
|
232
|
+
required: true,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
handler: async (args, context) => {
|
|
237
|
+
const id = String(args.delegation_id ?? '');
|
|
238
|
+
const record = service.get(id);
|
|
239
|
+
if (!record) {
|
|
240
|
+
return { ok: false, error: `Delegation not found: ${id}` };
|
|
241
|
+
}
|
|
242
|
+
// 归属校验:只能取本 session 发起的委派单
|
|
243
|
+
if (record.parent.sessionId !== context.sessionId) {
|
|
244
|
+
return { ok: false, error: `Delegation not owned by this session: ${id}` };
|
|
245
|
+
}
|
|
246
|
+
// 终态结果经本工具进入父上下文即视为已送达(§7.3 状态提示消音)
|
|
247
|
+
const surfaced = isTerminalDelegationStatus(record.status) ? service.markSurfaced(id) : record;
|
|
248
|
+
return { ok: true, ...delegationSummary(surfaced) };
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* `delegate_cancel` — 取消委派
|
|
254
|
+
*/
|
|
255
|
+
export function createDelegateCancelTool(service) {
|
|
256
|
+
return {
|
|
257
|
+
definition: {
|
|
258
|
+
name: 'delegate_cancel',
|
|
259
|
+
capabilities: [],
|
|
260
|
+
description: 'Cancel a running or queued delegation. Fails if the delegation already reached a terminal state.',
|
|
261
|
+
parameters: {
|
|
262
|
+
delegation_id: {
|
|
263
|
+
type: 'string',
|
|
264
|
+
description: 'Delegation id to cancel',
|
|
265
|
+
required: true,
|
|
266
|
+
},
|
|
267
|
+
reason: {
|
|
268
|
+
type: 'string',
|
|
269
|
+
description: 'Why it is being cancelled (recorded on the delegation)',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
handler: async (args, context) => {
|
|
274
|
+
const id = String(args.delegation_id ?? '');
|
|
275
|
+
const existing = service.get(id);
|
|
276
|
+
if (!existing) {
|
|
277
|
+
return { ok: false, error: `Delegation not found: ${id}` };
|
|
278
|
+
}
|
|
279
|
+
if (existing.parent.sessionId !== context.sessionId) {
|
|
280
|
+
return { ok: false, error: `Delegation not owned by this session: ${id}` };
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const record = service.cancel(id, String(args.reason ?? 'cancelled by parent'));
|
|
284
|
+
return { ok: true, ...delegationSummary(record) };
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
@@ -14,6 +14,7 @@ export function createDocumentReadTool(options) {
|
|
|
14
14
|
return {
|
|
15
15
|
definition: {
|
|
16
16
|
name: 'document_read',
|
|
17
|
+
capabilities: ['fs-read'],
|
|
17
18
|
description: 'Extract PDF/Office (docx/xlsx/pptx/legacy) to Markdown for reading. Prefer this over shell converters.',
|
|
18
19
|
parameters: {
|
|
19
20
|
path: {
|
|
@@ -43,7 +44,10 @@ export function createDocumentReadTool(options) {
|
|
|
43
44
|
}
|
|
44
45
|
const rawPath = String(args.path ?? '');
|
|
45
46
|
const cwd = context?.cwd ?? process.cwd();
|
|
46
|
-
const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots
|
|
47
|
+
const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, {
|
|
48
|
+
allowRoots: context?.pathRoots,
|
|
49
|
+
containment: context?.pathContainment,
|
|
50
|
+
});
|
|
47
51
|
try {
|
|
48
52
|
const result = await port.extract({
|
|
49
53
|
path,
|
|
@@ -111,6 +115,7 @@ export function createDocumentProbeTool(options) {
|
|
|
111
115
|
return {
|
|
112
116
|
definition: {
|
|
113
117
|
name: 'document_probe',
|
|
118
|
+
capabilities: ['fs-read'],
|
|
114
119
|
description: 'Detect document format and whether this deployment can extract it (without full parse).',
|
|
115
120
|
parameters: {
|
|
116
121
|
path: {
|
|
@@ -130,7 +135,10 @@ export function createDocumentProbeTool(options) {
|
|
|
130
135
|
}
|
|
131
136
|
const rawPath = String(args.path ?? '');
|
|
132
137
|
const cwd = context?.cwd ?? process.cwd();
|
|
133
|
-
const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots
|
|
138
|
+
const path = resolveReadableToolPath(rawPath, cwd, context?.attachmentRoots, {
|
|
139
|
+
allowRoots: context?.pathRoots,
|
|
140
|
+
containment: context?.pathContainment,
|
|
141
|
+
});
|
|
134
142
|
try {
|
|
135
143
|
const probe = await port.probe({ path, name: path });
|
|
136
144
|
const caps = await port.capabilities();
|
|
@@ -9,6 +9,7 @@ export function createEnvInfoTool() {
|
|
|
9
9
|
return {
|
|
10
10
|
definition: {
|
|
11
11
|
name: 'env_info',
|
|
12
|
+
capabilities: ['fs-read'],
|
|
12
13
|
description: 'Get runtime environment information including OS, Node.js version, working directory, PATH, platform shell, and available package managers.',
|
|
13
14
|
parameters: {},
|
|
14
15
|
},
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 行尾(EOL)工具 — file 工具行尾感知
|
|
3
|
+
*
|
|
4
|
+
* 背景:file 工具按字节处理文本时,多行 old_text(`\n` 书写)在 CRLF 文件上
|
|
5
|
+
* 永远匹配不上(静默 old_text not found),插入的新行又会把 LF 混进 CRLF 文件,
|
|
6
|
+
* 造成混杂行尾并在 git 提交时产生整文件 churn。
|
|
7
|
+
*
|
|
8
|
+
* 约定:
|
|
9
|
+
* - 编辑已有文件时跟随该文件的**主导行尾**(保持字节稳定,最小 diff);
|
|
10
|
+
* - 覆写/追加已有文件时把内容换算成文件主导行尾;
|
|
11
|
+
* - 新建文件保持内容原样(模型输出默认 LF)。
|
|
12
|
+
*/
|
|
13
|
+
export type Eol = '\r\n' | '\n';
|
|
14
|
+
/**
|
|
15
|
+
* 检测文本的主导行尾。
|
|
16
|
+
*
|
|
17
|
+
* @param content - 文本内容
|
|
18
|
+
* @returns CRLF 行数多于纯 LF 行数时 `\r\n`,否则 `\n`(空文本默认 `\n`)
|
|
19
|
+
*/
|
|
20
|
+
export declare function detectEol(content: string): Eol;
|
|
21
|
+
/**
|
|
22
|
+
* 把 text 中的所有行尾(CRLF / LF)统一成 eol。
|
|
23
|
+
*
|
|
24
|
+
* @param text - 原文本
|
|
25
|
+
* @param eol - 目标行尾
|
|
26
|
+
* @returns 行尾统一后的文本
|
|
27
|
+
*/
|
|
28
|
+
export declare function toEol(text: string, eol: Eol): string;
|
|
29
|
+
/**
|
|
30
|
+
* 生成 old_text 的行尾候选项(原样优先),供匹配降级尝试。
|
|
31
|
+
*
|
|
32
|
+
* @param oldText - 调用方提供的匹配文本
|
|
33
|
+
* @returns 去重后的候选项列表(按尝试顺序)
|
|
34
|
+
*/
|
|
35
|
+
export declare function oldTextCandidates(oldText: string): string[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 行尾(EOL)工具 — file 工具行尾感知
|
|
3
|
+
*
|
|
4
|
+
* 背景:file 工具按字节处理文本时,多行 old_text(`\n` 书写)在 CRLF 文件上
|
|
5
|
+
* 永远匹配不上(静默 old_text not found),插入的新行又会把 LF 混进 CRLF 文件,
|
|
6
|
+
* 造成混杂行尾并在 git 提交时产生整文件 churn。
|
|
7
|
+
*
|
|
8
|
+
* 约定:
|
|
9
|
+
* - 编辑已有文件时跟随该文件的**主导行尾**(保持字节稳定,最小 diff);
|
|
10
|
+
* - 覆写/追加已有文件时把内容换算成文件主导行尾;
|
|
11
|
+
* - 新建文件保持内容原样(模型输出默认 LF)。
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* 检测文本的主导行尾。
|
|
15
|
+
*
|
|
16
|
+
* @param content - 文本内容
|
|
17
|
+
* @returns CRLF 行数多于纯 LF 行数时 `\r\n`,否则 `\n`(空文本默认 `\n`)
|
|
18
|
+
*/
|
|
19
|
+
export function detectEol(content) {
|
|
20
|
+
const crlf = content.split('\r\n').length - 1;
|
|
21
|
+
const lfOnly = content.split('\n').length - 1 - crlf;
|
|
22
|
+
return crlf > lfOnly ? '\r\n' : '\n';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 把 text 中的所有行尾(CRLF / LF)统一成 eol。
|
|
26
|
+
*
|
|
27
|
+
* @param text - 原文本
|
|
28
|
+
* @param eol - 目标行尾
|
|
29
|
+
* @returns 行尾统一后的文本
|
|
30
|
+
*/
|
|
31
|
+
export function toEol(text, eol) {
|
|
32
|
+
return text.replace(/\r\n|\n/g, eol);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 生成 old_text 的行尾候选项(原样优先),供匹配降级尝试。
|
|
36
|
+
*
|
|
37
|
+
* @param oldText - 调用方提供的匹配文本
|
|
38
|
+
* @returns 去重后的候选项列表(按尝试顺序)
|
|
39
|
+
*/
|
|
40
|
+
export function oldTextCandidates(oldText) {
|
|
41
|
+
const candidates = [oldText, toEol(oldText, '\n'), toEol(oldText, '\r\n')];
|
|
42
|
+
return candidates.filter((c, i) => candidates.indexOf(c) === i);
|
|
43
|
+
}
|
|
@@ -10,12 +10,15 @@
|
|
|
10
10
|
* - dry-run 预览模式
|
|
11
11
|
* - 编辑后自动返回周围上下文
|
|
12
12
|
*/
|
|
13
|
-
import { isUnderAttachmentRoot, resolveToolPath } from './platform.js';
|
|
13
|
+
import { isPathUnderRoots, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
|
|
14
|
+
import { gateEffect } from '../../execution-environment/effect-policy.js';
|
|
15
|
+
import { detectEol, oldTextCandidates, toEol } from './eol.js';
|
|
14
16
|
export function createFileEditTool() {
|
|
15
17
|
return {
|
|
16
18
|
definition: {
|
|
17
19
|
name: 'file_edit',
|
|
18
|
-
|
|
20
|
+
capabilities: ['fs-write', 'fs-read'],
|
|
21
|
+
description: 'Edit a file by replacing specific text. More precise than file_write for targeted changes. Supports selecting which occurrence to replace and dry-run preview. old_text must match the CURRENT file content — if your view of the file is stale, re-read before editing; do not batch several edits against the same file in one turn (each edit builds on the previous result, stale batches lose changes).',
|
|
19
22
|
parameters: {
|
|
20
23
|
path: {
|
|
21
24
|
type: 'string',
|
|
@@ -42,14 +45,22 @@ export function createFileEditTool() {
|
|
|
42
45
|
},
|
|
43
46
|
},
|
|
44
47
|
},
|
|
48
|
+
// 同文件并发读改写互相覆盖(丢编辑):所在 tool_call 批次整体串行
|
|
49
|
+
executionMode: 'sequential',
|
|
45
50
|
handler: async (args, context) => {
|
|
46
|
-
const { readFile
|
|
51
|
+
const { readFile } = await import('node:fs/promises');
|
|
47
52
|
const rawPath = args.path;
|
|
48
53
|
const cwd = context.cwd ?? process.cwd();
|
|
49
|
-
const path = resolveToolPath(rawPath, cwd
|
|
54
|
+
const path = resolveToolPath(rawPath, cwd, {
|
|
55
|
+
allowRoots: context.pathRoots,
|
|
56
|
+
containment: context.pathContainment,
|
|
57
|
+
});
|
|
50
58
|
if (isUnderAttachmentRoot(path, context.attachmentRoots)) {
|
|
51
59
|
throw new Error('session attachments are read-only; cannot edit attachments root');
|
|
52
60
|
}
|
|
61
|
+
if (isUnderSessionUndoRoot(path, context.undoRoots)) {
|
|
62
|
+
throw new Error('session undo ledger is protected; cannot write to sessions undo dir');
|
|
63
|
+
}
|
|
53
64
|
const oldText = args.old_text;
|
|
54
65
|
const newText = args.new_text;
|
|
55
66
|
const occurrence = args.occurrence ?? 'first';
|
|
@@ -61,11 +72,18 @@ export function createFileEditTool() {
|
|
|
61
72
|
catch (error) {
|
|
62
73
|
throw new Error(`Failed to read file "${path}": ${error instanceof Error ? error.message : String(error)}`);
|
|
63
74
|
}
|
|
75
|
+
// 行尾自适应匹配:多行 old_text(\n 书写)在 CRLF 文件上按字节匹配必然落空
|
|
76
|
+
const fileEol = detectEol(content);
|
|
77
|
+
const matchedOldText = oldTextCandidates(oldText).find((c) => content.includes(c));
|
|
78
|
+
if (matchedOldText === undefined) {
|
|
79
|
+
throw new Error(`old_text not found in "${path}". Ensure the text matches exactly including whitespace and indentation.`);
|
|
80
|
+
}
|
|
81
|
+
const insertText = toEol(newText, fileEol);
|
|
64
82
|
// 查找所有匹配位置
|
|
65
83
|
const positions = [];
|
|
66
84
|
let searchFrom = 0;
|
|
67
85
|
while (true) {
|
|
68
|
-
const idx = content.indexOf(
|
|
86
|
+
const idx = content.indexOf(matchedOldText, searchFrom);
|
|
69
87
|
if (idx === -1)
|
|
70
88
|
break;
|
|
71
89
|
positions.push(idx);
|
|
@@ -97,15 +115,28 @@ export function createFileEditTool() {
|
|
|
97
115
|
let newContent = content;
|
|
98
116
|
const sortedIndices = [...indicesToReplace].sort((a, b) => b - a);
|
|
99
117
|
for (const idx of sortedIndices) {
|
|
100
|
-
newContent = newContent.slice(0, idx) +
|
|
118
|
+
newContent = newContent.slice(0, idx) + insertText + newContent.slice(idx + matchedOldText.length);
|
|
101
119
|
}
|
|
102
120
|
// 生成上下文预览(第一个替换点周围)
|
|
103
121
|
const firstIdx = indicesToReplace[0];
|
|
104
122
|
const before = content.slice(Math.max(0, firstIdx - 80), firstIdx);
|
|
105
|
-
const match = content.slice(firstIdx, firstIdx +
|
|
106
|
-
const after = content.slice(firstIdx +
|
|
123
|
+
const match = content.slice(firstIdx, firstIdx + matchedOldText.length);
|
|
124
|
+
const after = content.slice(firstIdx + matchedOldText.length, firstIdx + matchedOldText.length + 80);
|
|
107
125
|
if (!dryRun) {
|
|
108
|
-
await
|
|
126
|
+
await gateEffect({
|
|
127
|
+
kind: 'file.write',
|
|
128
|
+
path,
|
|
129
|
+
mode: 'edit',
|
|
130
|
+
transactional: isPathUnderRoots(path, context.pathRoots ?? []),
|
|
131
|
+
}, {
|
|
132
|
+
effects: context.effectChannel ?? 'engine',
|
|
133
|
+
confirmEffect: context.confirmEffect,
|
|
134
|
+
});
|
|
135
|
+
const effects = context.fileEffects;
|
|
136
|
+
if (!effects) {
|
|
137
|
+
throw new Error('file_effects_not_configured: file_edit requires ToolExecutionContext.fileEffects');
|
|
138
|
+
}
|
|
139
|
+
await effects.writeFile(path, newContent);
|
|
109
140
|
}
|
|
110
141
|
return {
|
|
111
142
|
path,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* file_mkdir / file_rename / file_copy / file_stat / file_rmdir
|
|
3
|
+
*
|
|
4
|
+
* Cross-platform (Windows / macOS / Linux) file & folder tools.
|
|
5
|
+
* Path rules match file_write: L2 resolveToolPath, attachment/undo self-protection.
|
|
6
|
+
* Destructive ops go through ToolFileEffects where a reversible journal is possible.
|
|
7
|
+
*/
|
|
8
|
+
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* file_mkdir — create a directory (optionally parents)
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFileMkdirTool(): RegisteredTool;
|
|
13
|
+
/**
|
|
14
|
+
* file_rename — rename/move a file or directory
|
|
15
|
+
*
|
|
16
|
+
* Files: journaled via recordRename (edit-resend undo).
|
|
17
|
+
* Directories: fs.rename; tree undo is not journaled (reversible:false).
|
|
18
|
+
*/
|
|
19
|
+
export declare function createFileRenameTool(): RegisteredTool;
|
|
20
|
+
/**
|
|
21
|
+
* file_copy — copy a file (not a directory)
|
|
22
|
+
*/
|
|
23
|
+
export declare function createFileCopyTool(): RegisteredTool;
|
|
24
|
+
/**
|
|
25
|
+
* file_stat — file/directory metadata
|
|
26
|
+
*/
|
|
27
|
+
export declare function createFileStatTool(): RegisteredTool;
|
|
28
|
+
/**
|
|
29
|
+
* file_rmdir — remove an empty directory
|
|
30
|
+
*/
|
|
31
|
+
export declare function createFileRmdirTool(): RegisteredTool;
|
|
32
|
+
/** File/folder operation tools (built-in, zero deps) */
|
|
33
|
+
export declare function createFileOpsTools(): RegisteredTool[];
|