@caupulican/pi-adaptative 0.81.39 → 0.81.41
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/CHANGELOG.md +77 -0
- package/README.md +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +3 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +4 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
- package/dist/cli/args.d.ts +4 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +31 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts +15 -0
- package/dist/core/agent-directory-layout.d.ts.map +1 -0
- package/dist/core/agent-directory-layout.js +72 -0
- package/dist/core/agent-directory-layout.js.map +1 -0
- package/dist/core/agent-paths.d.ts +25 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +79 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +293 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -0
- package/dist/core/agent-session-contracts.js +26 -0
- package/dist/core/agent-session-contracts.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +52 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +400 -79
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +74 -518
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +370 -1432
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +3 -2
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +6 -28
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +20 -12
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js +8 -25
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +8 -10
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
- package/dist/core/autonomy/lane-private-paths.js +16 -0
- package/dist/core/autonomy/lane-private-paths.js.map +1 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +48 -9
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +14 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +38 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts +1 -2
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/risk-assessment.js +1 -123
- package/dist/core/autonomy/risk-assessment.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +4 -4
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js +16 -29
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +7 -7
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +9 -9
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +56 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +141 -1273
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bedrock-sso-login.d.ts +16 -0
- package/dist/core/bedrock-sso-login.d.ts.map +1 -0
- package/dist/core/bedrock-sso-login.js +98 -0
- package/dist/core/bedrock-sso-login.js.map +1 -0
- package/dist/core/capability-contract.d.ts +4 -0
- package/dist/core/capability-contract.d.ts.map +1 -0
- package/dist/core/capability-contract.js +28 -0
- package/dist/core/capability-contract.js.map +1 -0
- package/dist/core/compaction-controller.d.ts +90 -0
- package/dist/core/compaction-controller.d.ts.map +1 -0
- package/dist/core/compaction-controller.js +452 -0
- package/dist/core/compaction-controller.js.map +1 -0
- package/dist/core/compaction-support.d.ts +13 -17
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +3 -3
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -2
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +34 -2
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +8 -2
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +158 -35
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js +9 -11
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js +6 -8
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context-gc.d.ts +3 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +10 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +16 -37
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +5 -3
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +4 -5
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +2 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
- package/dist/core/delegation/managed-lane-controller.js +217 -0
- package/dist/core/delegation/managed-lane-controller.js.map +1 -0
- package/dist/core/delegation/session-worker-claim.d.ts +44 -0
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-claim.js +98 -0
- package/dist/core/delegation/session-worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +7 -5
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +20 -4
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
- package/dist/core/delegation/worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
- package/dist/core/delegation/worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.js +861 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
- package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-request.js +2 -0
- package/dist/core/delegation/worker-delegation-request.js.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
- package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-execution-policy.js +160 -0
- package/dist/core/delegation/worker-execution-policy.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
- package/dist/core/delegation/worker-lane-projection.js +100 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
- package/dist/core/delegation/worker-lifecycle.js +339 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.js +90 -0
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.js +113 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +25 -14
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +122 -53
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts +3 -0
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-label.js +11 -0
- package/dist/core/delegation/worker-task-label.js.map +1 -0
- package/dist/core/doctor.d.ts +8 -0
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +32 -1
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/extension-import-authority.d.ts +6 -0
- package/dist/core/extension-import-authority.d.ts.map +1 -0
- package/dist/core/extension-import-authority.js +10 -0
- package/dist/core/extension-import-authority.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +5 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +52 -18
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +20 -5
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/stale-context.d.ts +2 -0
- package/dist/core/extensions/stale-context.d.ts.map +1 -0
- package/dist/core/extensions/stale-context.js +2 -0
- package/dist/core/extensions/stale-context.js.map +1 -0
- package/dist/core/extensions/storage.d.ts +8 -0
- package/dist/core/extensions/storage.d.ts.map +1 -0
- package/dist/core/extensions/storage.js +28 -0
- package/dist/core/extensions/storage.js.map +1 -0
- package/dist/core/extensions/types.d.ts +78 -21
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +1 -15
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +9 -37
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +53 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
- package/dist/core/foreground-recovery-controller.js +111 -0
- package/dist/core/foreground-recovery-controller.js.map +1 -0
- package/dist/core/gateways/channel-provider.d.ts +3 -0
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +31 -6
- package/dist/core/gateways/channel-provider.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts +14 -9
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +47 -75
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +11 -0
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
- package/dist/core/goals/compact-goal-context.js +59 -0
- package/dist/core/goals/compact-goal-context.js.map +1 -0
- package/dist/core/goals/goal-acceptance.d.ts +11 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
- package/dist/core/goals/goal-acceptance.js +27 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +28 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +90 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +52 -11
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.js +4 -32
- package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +9 -179
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +43 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +102 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- package/dist/core/goals/goal-record.d.ts +17 -0
- package/dist/core/goals/goal-record.d.ts.map +1 -0
- package/dist/core/goals/goal-record.js +31 -0
- package/dist/core/goals/goal-record.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js +10 -8
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +42 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-session-controller.js +128 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -0
- package/dist/core/goals/goal-state.d.ts +46 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +91 -24
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +9 -10
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +60 -75
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +20 -12
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +133 -33
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input-controller.d.ts +47 -0
- package/dist/core/human-input-controller.d.ts.map +1 -0
- package/dist/core/human-input-controller.js +181 -0
- package/dist/core/human-input-controller.js.map +1 -0
- package/dist/core/human-input.d.ts +100 -0
- package/dist/core/human-input.d.ts.map +1 -0
- package/dist/core/human-input.js +362 -0
- package/dist/core/human-input.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -0
- package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
- package/dist/core/install-telemetry.js.map +1 -0
- package/dist/core/keybindings.d.ts +17 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +2 -4
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js +9 -29
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js +1 -6
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +2 -4
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js +9 -29
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/local-runtime-controller.d.ts +1 -1
- package/dist/core/local-runtime-controller.d.ts.map +1 -1
- package/dist/core/local-runtime-controller.js.map +1 -1
- package/dist/core/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +4 -4
- package/dist/core/memory-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts +0 -19
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -19
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts +6 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -5
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +17 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +38 -25
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +1 -4
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +1 -156
- package/dist/core/model-router/intent-classifier.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +5 -5
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +23 -0
- package/dist/core/model-tool-protocol.d.ts.map +1 -0
- package/dist/core/model-tool-protocol.js +43 -0
- package/dist/core/model-tool-protocol.js.map +1 -0
- package/dist/core/models/adaptation-store.d.ts +4 -6
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +95 -83
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +2 -12
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +84 -57
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts +34 -0
- package/dist/core/models/host-state-store.d.ts.map +1 -0
- package/dist/core/models/host-state-store.js +86 -0
- package/dist/core/models/host-state-store.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +24 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
- package/dist/core/orchestration/agent-resume.js +90 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +61 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
- package/dist/core/orchestration/capability-gateway.js +152 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -0
- package/dist/core/orchestration/contracts.d.ts +343 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -0
- package/dist/core/orchestration/contracts.js +135 -0
- package/dist/core/orchestration/contracts.js.map +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
- package/dist/core/orchestration/delegation-ledger.js +200 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -0
- package/dist/core/orchestration/event-store.d.ts +83 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -0
- package/dist/core/orchestration/event-store.js +560 -0
- package/dist/core/orchestration/event-store.js.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.js +37 -0
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
- package/dist/core/orchestration/model-binding.d.ts +15 -0
- package/dist/core/orchestration/model-binding.d.ts.map +1 -0
- package/dist/core/orchestration/model-binding.js +29 -0
- package/dist/core/orchestration/model-binding.js.map +1 -0
- package/dist/core/orchestration/policy-compiler.d.ts +49 -0
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
- package/dist/core/orchestration/policy-compiler.js +191 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -0
- package/dist/core/orchestration/policy-gate.d.ts +18 -0
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
- package/dist/core/orchestration/policy-gate.js +24 -0
- package/dist/core/orchestration/policy-gate.js.map +1 -0
- package/dist/core/orchestration/profile-registry.d.ts +51 -0
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
- package/dist/core/orchestration/profile-registry.js +393 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -0
- package/dist/core/orchestration/profile-store.d.ts +31 -0
- package/dist/core/orchestration/profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/profile-store.js +136 -0
- package/dist/core/orchestration/profile-store.js.map +1 -0
- package/dist/core/orchestration/risk-budget.d.ts +9 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
- package/dist/core/orchestration/risk-budget.js +48 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +168 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime.js +1600 -0
- package/dist/core/orchestration/task-runtime.js.map +1 -0
- package/dist/core/orchestration/work-state-projection.d.ts +32 -0
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
- package/dist/core/orchestration/work-state-projection.js +116 -0
- package/dist/core/orchestration/work-state-projection.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.js +179 -0
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.js +109 -0
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +20 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/process-identity.d.ts +11 -0
- package/dist/core/process-identity.d.ts.map +1 -0
- package/dist/core/process-identity.js +26 -0
- package/dist/core/process-identity.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts +14 -3
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/codes.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
- package/dist/core/process-matrix/resume-launcher.js +62 -0
- package/dist/core/process-matrix/resume-launcher.js.map +1 -0
- package/dist/core/process-matrix/runtime.d.ts +37 -22
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +399 -76
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts +5 -2
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js +123 -14
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts +10 -7
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js +45 -14
- package/dist/core/process-matrix/supervisor.js.map +1 -1
- package/dist/core/profile-filter-controller.d.ts +8 -1
- package/dist/core/profile-filter-controller.d.ts.map +1 -1
- package/dist/core/profile-filter-controller.js +23 -5
- package/dist/core/profile-filter-controller.js.map +1 -1
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +6 -8
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +18 -29
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +5 -5
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +5 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -8
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/request-auth.d.ts +7 -0
- package/dist/core/request-auth.d.ts.map +1 -0
- package/dist/core/request-auth.js +8 -0
- package/dist/core/request-auth.js.map +1 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +1 -6
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts +33 -0
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
- package/dist/core/research/lane-model-resolver.js +65 -0
- package/dist/core/research/lane-model-resolver.js.map +1 -0
- package/dist/core/research/model-fitness-controller.d.ts +38 -0
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
- package/dist/core/research/model-fitness-controller.js +106 -0
- package/dist/core/research/model-fitness-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -4
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js +7 -7
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +62 -0
- package/dist/core/research/research-lane-controller.d.ts.map +1 -0
- package/dist/core/research/research-lane-controller.js +292 -0
- package/dist/core/research/research-lane-controller.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +2 -4
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js +10 -46
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +23 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts +6 -0
- package/dist/core/risk-classifier.d.ts.map +1 -0
- package/dist/core/risk-classifier.js +233 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +41 -23
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +365 -253
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +68 -25
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.js +241 -0
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +27 -0
- package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
- package/dist/core/secrets/secret-dotenv.js +183 -0
- package/dist/core/secrets/secret-dotenv.js.map +1 -0
- package/dist/core/secrets/secret-vault-format.d.ts +112 -0
- package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault-format.js +397 -0
- package/dist/core/secrets/secret-vault-format.js.map +1 -0
- package/dist/core/secrets/secret-vault.d.ts +72 -0
- package/dist/core/secrets/secret-vault.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault.js +671 -0
- package/dist/core/secrets/secret-vault.js.map +1 -0
- package/dist/core/session-analytics.d.ts +4 -23
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +67 -70
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-image-store.d.ts +33 -0
- package/dist/core/session-image-store.d.ts.map +1 -0
- package/dist/core/session-image-store.js +283 -0
- package/dist/core/session-image-store.js.map +1 -0
- package/dist/core/session-role.d.ts +11 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +24 -5
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts +34 -0
- package/dist/core/session-snapshot.d.ts.map +1 -0
- package/dist/core/session-snapshot.js +68 -0
- package/dist/core/session-snapshot.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +31 -0
- package/dist/core/session-supervision-runtime.d.ts.map +1 -0
- package/dist/core/session-supervision-runtime.js +97 -0
- package/dist/core/session-supervision-runtime.js.map +1 -0
- package/dist/core/session-tree-navigator.d.ts +4 -6
- package/dist/core/session-tree-navigator.d.ts.map +1 -1
- package/dist/core/session-tree-navigator.js +4 -1
- package/dist/core/session-tree-navigator.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +81 -29
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tasks/session-task-state.d.ts +2 -4
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js +10 -28
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +20 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -0
- package/dist/core/tasks/task-projection.js +47 -0
- package/dist/core/tasks/task-projection.js.map +1 -0
- package/dist/core/tasks/task-state.d.ts +4 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +28 -11
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -0
- package/dist/core/tool-capability-policy.js +86 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +8 -2
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +89 -0
- package/dist/core/tool-protocol-controller.d.ts.map +1 -0
- package/dist/core/tool-protocol-controller.js +512 -0
- package/dist/core/tool-protocol-controller.js.map +1 -0
- package/dist/core/tool-recovery-log-records.d.ts +2 -3
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +9 -35
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-recovery-stats.d.ts +21 -1
- package/dist/core/tool-recovery-stats.d.ts.map +1 -1
- package/dist/core/tool-recovery-stats.js.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +97 -138
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +124 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +693 -0
- package/dist/core/tools/ask-question.js.map +1 -0
- package/dist/core/tools/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +59 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +31 -3
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +148 -29
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -13
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +106 -23
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +1 -0
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +1 -8
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +2 -63
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts +10 -8
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +106 -28
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js +2 -2
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +40 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +124 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +11 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +36 -3
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/python.d.ts +2 -0
- package/dist/core/tools/python.d.ts.map +1 -1
- package/dist/core/tools/python.js +3 -1
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +26 -0
- package/dist/core/tools/run-process.d.ts.map +1 -0
- package/dist/core/tools/run-process.js +138 -0
- package/dist/core/tools/run-process.js.map +1 -0
- package/dist/core/tools/search-command-guard.d.ts +14 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -0
- package/dist/core/tools/search-command-guard.js +333 -0
- package/dist/core/tools/search-command-guard.js.map +1 -0
- package/dist/core/tools/secret-store.d.ts +38 -0
- package/dist/core/tools/secret-store.d.ts.map +1 -0
- package/dist/core/tools/secret-store.js +412 -0
- package/dist/core/tools/secret-store.js.map +1 -0
- package/dist/core/tools/shell-command-parser.d.ts +16 -0
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
- package/dist/core/tools/shell-command-parser.js +113 -0
- package/dist/core/tools/shell-command-parser.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts +2 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +99 -0
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +3 -5
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +4 -4
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +4 -6
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +6 -2
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +4 -4
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/bounded-jsonl.d.ts +10 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
- package/dist/core/util/bounded-jsonl.js +75 -0
- package/dist/core/util/bounded-jsonl.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +5 -0
- package/dist/core/util/value-guards.d.ts.map +1 -0
- package/dist/core/util/value-guards.js +12 -0
- package/dist/core/util/value-guards.js.map +1 -0
- package/dist/core/worktree-sync/store.d.ts +3 -3
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js +10 -5
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +149 -51
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +4 -6
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +186 -28
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/clipboard-input.d.ts +7 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +44 -6
- package/dist/modes/interactive/clipboard-input.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
- package/dist/modes/interactive/components/activity-lane.js +304 -0
- package/dist/modes/interactive/components/activity-lane.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +19 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
- package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/expandable-text.js +17 -0
- package/dist/modes/interactive/components/expandable-text.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +30 -21
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +6 -6
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +53 -20
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +3 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
- package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/usage-action-selector.js +46 -0
- package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +5 -4
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +77 -15
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +15 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +27 -19
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/history-reload-math.d.ts +6 -2
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
- package/dist/modes/interactive/history-reload-math.js +10 -5
- package/dist/modes/interactive/history-reload-math.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-event-controller.js +328 -0
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +22 -24
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +245 -595
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -1
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
- package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
- package/dist/modes/interactive/loaded-resources-view.js +147 -0
- package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +7 -7
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +21 -0
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/resource-display.d.ts.map +1 -1
- package/dist/modes/interactive/resource-display.js +8 -2
- package/dist/modes/interactive/resource-display.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +0 -5
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +27 -8
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +150 -64
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +16 -6
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
- package/dist/modes/interactive/session-replacement-errors.js +15 -0
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +1 -1
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/interactive/usage-commands.d.ts +34 -0
- package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
- package/dist/modes/interactive/usage-commands.js +225 -0
- package/dist/modes/interactive/usage-commands.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +82 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +138 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -13
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +52 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +8 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +5 -3
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/work-directory.d.ts +11 -0
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js +30 -9
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +38 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +28 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +62 -2
- package/docs/harness-architecture.md +156 -0
- package/docs/keybindings.md +11 -1
- package/docs/process-matrix.md +59 -26
- package/docs/providers.md +9 -1
- package/docs/rpc.md +45 -2
- package/docs/sessions.md +15 -0
- package/docs/settings.md +125 -11
- package/docs/task-steps.md +8 -0
- package/docs/telemetry.md +19 -0
- package/docs/tmux-agent-manager.md +10 -3
- package/docs/ui-reference/README.md +9 -0
- package/docs/ui-reference/orchestration-after.txt +14 -0
- package/docs/ui-reference/orchestration-before.txt +13 -0
- package/docs/ui-reference/orchestration-reference.txt +16 -0
- package/docs/usage.md +22 -2
- package/docs/work-directory.md +19 -8
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/question.ts +34 -245
- package/examples/extensions/questionnaire.ts +41 -407
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +13 -13
- package/package.json +4 -4
- package/dist/core/delegation/session-worker-result.d.ts +0 -46
- package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
- package/dist/core/delegation/session-worker-result.js +0 -113
- package/dist/core/delegation/session-worker-result.js.map +0 -1
- package/dist/core/delegation/worker-result.d.ts.map +0 -1
- package/dist/core/delegation/worker-result.js.map +0 -1
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAQ5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAKtF,QAAA,MAAM,UAAU;;;;;;;EAWd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAgBD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC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,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA0ThE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, open as fsOpen, readFile as fsReadFile, stat as fsStat } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getAgentDir, getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n\tlineNumbers: Type.Optional(Type.Boolean({ description: \"Include line numbers in the output\" })),\n\ttail: Type.Optional(Type.Number({ description: \"Number of lines to read from the end of the file\" })),\n\tfilter: Type.Optional(\n\t\tType.Union([Type.Literal(\"none\"), Type.Literal(\"minimal\"), Type.Literal(\"aggressive\")], {\n\t\t\tdescription: \"Safe text filtering level (none, minimal, aggressive)\",\n\t\t}),\n\t),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n\t\"GEMINI.md\",\n\t\"GEMINI.MD\",\n]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n\t/** File size in bytes, used to decide between whole-file and sliced reads. */\n\tstat?: (absolutePath: string) => Promise<{ size: number }>;\n\t/**\n\t * Stream a slice of lines out of the file with bounded memory. Any region of an\n\t * arbitrarily large file stays reachable in batches via offset continuation.\n\t */\n\treadLineSlice?: (absolutePath: string, options: LineSliceOptions) => Promise<LineSlice>;\n\t/** Count lines by streaming (bounded memory); used to resolve tail reads on oversized files. */\n\tcountLines?: (absolutePath: string) => Promise<number>;\n}\n\nexport interface LineSliceOptions {\n\t/** 0-based line to start collecting at. */\n\tstartLine: number;\n\t/** Maximum number of lines to collect. */\n\tmaxLines: number;\n\t/** Maximum total characters to collect across lines. */\n\tmaxChars: number;\n}\n\nexport interface LineSlice {\n\tlines: { text: string; originalIndex: number }[];\n\t/** True when the end of the file was reached while collecting. */\n\treachedEnd: boolean;\n}\n\nconst SLICE_SCAN_CHUNK_BYTES = 1024 * 1024;\n\nasync function scanLines(\n\tabsolutePath: string,\n\tonLine: (text: string | undefined, index: number) => boolean,\n): Promise<void> {\n\tconst handle = await fsOpen(absolutePath, \"r\");\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\n\t\tlet pending = \"\";\n\t\tlet index = 0;\n\t\tlet emittedAnyLine = false;\n\t\twhile (true) {\n\t\t\tconst { bytesRead } = await handle.read(buffer, 0, buffer.length, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tpending += decoder.write(buffer.subarray(0, bytesRead));\n\t\t\tlet lineStart = 0;\n\t\t\tlet newlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\twhile (newlineIndex !== -1) {\n\t\t\t\temittedAnyLine = true;\n\t\t\t\tif (!onLine(pending.slice(lineStart, newlineIndex), index++)) return;\n\t\t\t\tlineStart = newlineIndex + 1;\n\t\t\t\tnewlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\t}\n\t\t\tpending = pending.slice(lineStart);\n\t\t}\n\t\tpending += decoder.end();\n\t\tif (pending.length > 0 || !emittedAnyLine) {\n\t\t\tonLine(pending, index);\n\t\t}\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function readLocalLineSlice(absolutePath: string, options: LineSliceOptions): Promise<LineSlice> {\n\tconst lines: { text: string; originalIndex: number }[] = [];\n\tlet collectedChars = 0;\n\tlet sawMore = false;\n\tawait scanLines(absolutePath, (text, index) => {\n\t\tif (text === undefined) return false;\n\t\tif (index < options.startLine) return true;\n\t\tif (lines.length >= options.maxLines || collectedChars > options.maxChars) {\n\t\t\tsawMore = true;\n\t\t\treturn false;\n\t\t}\n\t\tlines.push({ text, originalIndex: index + 1 });\n\t\tcollectedChars += text.length;\n\t\treturn true;\n\t});\n\treturn { lines, reachedEnd: !sawMore };\n}\n\nasync function countLocalLines(absolutePath: string): Promise<number> {\n\tlet count = 0;\n\tawait scanLines(absolutePath, () => {\n\t\tcount++;\n\t\treturn true;\n\t});\n\treturn count;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n\tstat: async (path) => ({ size: (await fsStat(path)).size }),\n\treadLineSlice: readLocalLineSlice,\n\tcountLines: countLocalLines,\n};\n\n// Loading a whole file before truncation lets a single giant file spike the heap\n// to its full size. Beyond these budgets, text reads stream line slices (every\n// region stays reachable in batches — lossless). The image budget is deliberately\n// far above any real screenshot/photo so quality-degrading workarounds are never\n// needed in practice; it only guards against pathological files.\nconst DEFAULT_MAX_TEXT_READ_BYTES = 16 * 1024 * 1024;\nconst DEFAULT_MAX_IMAGE_READ_BYTES = 128 * 1024 * 1024;\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\t/** Whole-file load budget for text reads; larger files stream line slices instead. Default 16 MiB. */\n\tmaxTextReadBytes?: number;\n\t/** Pathology guard for image reads; larger images return downscale guidance. Default 128 MiB. */\n\tmaxImageReadBytes?: number;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction splitContentLines(text: string): string[] {\n\tconst lines = text.split(\"\\n\");\n\tif (text.endsWith(\"\\n\")) lines.pop();\n\treturn lines;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getPiDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getPiDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tlineNumbers,\n\t\t\t\ttail,\n\t\t\t\tfilter,\n\t\t\t}: {\n\t\t\t\tpath: string;\n\t\t\t\toffset?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tlineNumbers?: boolean;\n\t\t\t\ttail?: number;\n\t\t\t\tfilter?: \"none\" | \"minimal\" | \"aggressive\";\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tconst fileSize = ops.stat ? (await ops.stat(absolutePath)).size : undefined;\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\tif (fileSize !== undefined && fileSize > maxImageReadBytes) {\n\t\t\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\t\t\ttext: `Image file is ${formatSize(fileSize)} (${formatSize(maxImageReadBytes)} inline decode limit). Downscale it first, e.g. with bash (ImageMagick: magick \"${path}\" -resize 2000x2000 \"${join(getProcessWorkRun(getAgentDir(), \"images\", \"previews\").path, \"preview.png\")}\") and read the result.`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content. Oversized files are streamed as line slices so\n\t\t\t\t\t\t\t\t// any region stays reachable in batches without loading the whole file.\n\t\t\t\t\t\t\t\tconst useSlicedRead =\n\t\t\t\t\t\t\t\t\tfileSize !== undefined && fileSize > maxTextReadBytes && ops.readLineSlice !== undefined;\n\t\t\t\t\t\t\t\tlet startLine = 0;\n\t\t\t\t\t\t\t\tlet userLimitedLines = limit;\n\t\t\t\t\t\t\t\tlet totalFileLines: number | undefined;\n\t\t\t\t\t\t\t\tlet moreContentRemains = false;\n\t\t\t\t\t\t\t\tlet textContentForJsonCheck: string | undefined;\n\t\t\t\t\t\t\t\tlet slicedLines: { text: string; originalIndex: number }[];\n\t\t\t\t\t\t\t\tif (useSlicedRead && ops.readLineSlice) {\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst counted = ops.countLines ? await ops.countLines(absolutePath) : undefined;\n\t\t\t\t\t\t\t\t\t\tif (counted !== undefined) {\n\t\t\t\t\t\t\t\t\t\t\ttotalFileLines = counted;\n\t\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, counted - tail);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst slice = await ops.readLineSlice(absolutePath, {\n\t\t\t\t\t\t\t\t\t\tstartLine,\n\t\t\t\t\t\t\t\t\t\tmaxLines: userLimitedLines ?? DEFAULT_MAX_LINES,\n\t\t\t\t\t\t\t\t\t\tmaxChars: DEFAULT_MAX_BYTES * 4,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (slice.lines.length === 0 && startLine > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${startLine + 1} is beyond end of file`);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines = slice.lines;\n\t\t\t\t\t\t\t\t\tmoreContentRemains = !slice.reachedEnd;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\t\ttextContentForJsonCheck = textContent;\n\t\t\t\t\t\t\t\t\tconst allLines = splitContentLines(textContent);\n\t\t\t\t\t\t\t\t\ttotalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t\t// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, totalFileLines - tail);\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\t\tif (startLine >= allLines.length && allLines.length > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t\t`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`,\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine, startLine + userLimitedLines)\n\t\t\t\t\t\t\t\t\t\t\t: allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine);\n\t\t\t\t\t\t\t\t\tmoreContentRemains =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\tconst firstSelectedLineText = slicedLines[0]?.text ?? \"\";\n\n\t\t\t\t\t\t\t\t// Safe text filtering\n\t\t\t\t\t\t\t\tlet canFilter = true;\n\t\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst fileNameLower = path.toLowerCase();\n\t\t\t\t\t\t\t\t\tconst unsafeExtensions = [\n\t\t\t\t\t\t\t\t\t\t\".json\",\n\t\t\t\t\t\t\t\t\t\t\".jsonl\",\n\t\t\t\t\t\t\t\t\t\t\".yml\",\n\t\t\t\t\t\t\t\t\t\t\".yaml\",\n\t\t\t\t\t\t\t\t\t\t\".toml\",\n\t\t\t\t\t\t\t\t\t\t\".xml\",\n\t\t\t\t\t\t\t\t\t\t\".csv\",\n\t\t\t\t\t\t\t\t\t\t\".tsv\",\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\tif (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {\n\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t} else if (textContentForJsonCheck !== undefined) {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tJSON.parse(textContentForJsonCheck);\n\t\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (canFilter && filter && filter !== \"none\") {\n\t\t\t\t\t\t\t\t\tconst filtered: typeof slicedLines = [];\n\t\t\t\t\t\t\t\t\tif (filter === \"minimal\") {\n\t\t\t\t\t\t\t\t\t\tlet consecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmed === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank++;\n\t\t\t\t\t\t\t\t\t\t\t\tif (consecutiveBlank <= 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: \"\", originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twhile (filtered.length > 0 && filtered[filtered.length - 1].text === \"\") {\n\t\t\t\t\t\t\t\t\t\t\tfiltered.pop();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else if (filter === \"aggressive\") {\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tconst trimmedStart = trimmed.trimStart();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmedStart === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"//\") ||\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"#\") ||\n\t\t\t\t\t\t\t\t\t\t\t\t(trimmedStart.startsWith(\"/*\") && trimmedStart.endsWith(\"*/\"))\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// If filtering would empty a non-empty list, keep original\n\t\t\t\t\t\t\t\t\tconst isOriginalNotEmpty = slicedLines.some((item) => item.text.trim().length > 0);\n\t\t\t\t\t\t\t\t\tconst isFilteredEmpty = filtered.every((item) => item.text.trim().length === 0);\n\t\t\t\t\t\t\t\t\tif (isOriginalNotEmpty && isFilteredEmpty) {\n\t\t\t\t\t\t\t\t\t\t// Fallback to slicedLines\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tslicedLines = filtered;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst finalLines = slicedLines.map((item) =>\n\t\t\t\t\t\t\t\t\tlineNumbers ? `${item.originalIndex}: ${item.text}` : item.text,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst selectedContent = finalLines.join(\"\\n\");\n\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tconst totalDisplay =\n\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined\n\t\t\t\t\t\t\t\t\t\t? String(totalFileLines)\n\t\t\t\t\t\t\t\t\t\t: `a ${fileSize !== undefined ? formatSize(fileSize) : \"large\"} file`;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(firstSelectedLineText, \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (moreContentRemains) {\n\t\t\t\t\t\t\t\t\t// More content exists beyond this slice; hand the model a continuation pointer.\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + slicedLines.length + 1;\n\t\t\t\t\t\t\t\t\tconst remaining =\n\t\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined && userLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? `${totalFileLines - (startLine + userLimitedLines)} more lines in file`\n\t\t\t\t\t\t\t\t\t\t\t: \"More content remains\";\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAQ5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAKtF,QAAA,MAAM,UAAU;;;;;;;EAWd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAgBD;;;GAGG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AAiG;IACjG,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAkJD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA0ThE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, open as fsOpen, readFile as fsReadFile, stat as fsStat } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getAgentDir, getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n\tlineNumbers: Type.Optional(Type.Boolean({ description: \"Include line numbers in the output\" })),\n\ttail: Type.Optional(Type.Number({ description: \"Number of lines to read from the end of the file\" })),\n\tfilter: Type.Optional(\n\t\tType.Union([Type.Literal(\"none\"), Type.Literal(\"minimal\"), Type.Literal(\"aggressive\")], {\n\t\t\tdescription: \"Safe text filtering level (none, minimal, aggressive)\",\n\t\t}),\n\t),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n\t\"GEMINI.md\",\n\t\"GEMINI.MD\",\n]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n\t/** File size in bytes, used to decide between whole-file and sliced reads. */\n\tstat?: (absolutePath: string) => Promise<{ size: number }>;\n\t/**\n\t * Stream a slice of lines out of the file with bounded memory. Any region of an\n\t * arbitrarily large file stays reachable in batches via offset continuation.\n\t */\n\treadLineSlice?: (absolutePath: string, options: LineSliceOptions) => Promise<LineSlice>;\n\t/** Count lines by streaming (bounded memory); used to resolve tail reads on oversized files. */\n\tcountLines?: (absolutePath: string) => Promise<number>;\n}\n\nexport interface LineSliceOptions {\n\t/** 0-based line to start collecting at. */\n\tstartLine: number;\n\t/** Maximum number of lines to collect. */\n\tmaxLines: number;\n\t/** Maximum total characters to collect across lines. */\n\tmaxChars: number;\n}\n\nexport interface LineSlice {\n\tlines: { text: string; originalIndex: number }[];\n\t/** True when the end of the file was reached while collecting. */\n\treachedEnd: boolean;\n}\n\nconst SLICE_SCAN_CHUNK_BYTES = 1024 * 1024;\n\nasync function scanLines(\n\tabsolutePath: string,\n\tonLine: (text: string | undefined, index: number) => boolean,\n): Promise<void> {\n\tconst handle = await fsOpen(absolutePath, \"r\");\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\n\t\tlet pending = \"\";\n\t\tlet index = 0;\n\t\tlet emittedAnyLine = false;\n\t\twhile (true) {\n\t\t\tconst { bytesRead } = await handle.read(buffer, 0, buffer.length, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tpending += decoder.write(buffer.subarray(0, bytesRead));\n\t\t\tlet lineStart = 0;\n\t\t\tlet newlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\twhile (newlineIndex !== -1) {\n\t\t\t\temittedAnyLine = true;\n\t\t\t\tif (!onLine(pending.slice(lineStart, newlineIndex), index++)) return;\n\t\t\t\tlineStart = newlineIndex + 1;\n\t\t\t\tnewlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\t}\n\t\t\tpending = pending.slice(lineStart);\n\t\t}\n\t\tpending += decoder.end();\n\t\tif (pending.length > 0 || !emittedAnyLine) {\n\t\t\tonLine(pending, index);\n\t\t}\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function readLocalLineSlice(absolutePath: string, options: LineSliceOptions): Promise<LineSlice> {\n\tconst lines: { text: string; originalIndex: number }[] = [];\n\tlet collectedChars = 0;\n\tlet sawMore = false;\n\tawait scanLines(absolutePath, (text, index) => {\n\t\tif (text === undefined) return false;\n\t\tif (index < options.startLine) return true;\n\t\tif (lines.length >= options.maxLines || collectedChars > options.maxChars) {\n\t\t\tsawMore = true;\n\t\t\treturn false;\n\t\t}\n\t\tlines.push({ text, originalIndex: index + 1 });\n\t\tcollectedChars += text.length;\n\t\treturn true;\n\t});\n\treturn { lines, reachedEnd: !sawMore };\n}\n\nasync function countLocalLines(absolutePath: string): Promise<number> {\n\tlet count = 0;\n\tawait scanLines(absolutePath, () => {\n\t\tcount++;\n\t\treturn true;\n\t});\n\treturn count;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n\tstat: async (path) => ({ size: (await fsStat(path)).size }),\n\treadLineSlice: readLocalLineSlice,\n\tcountLines: countLocalLines,\n};\n\n// Loading a whole file before truncation lets a single giant file spike the heap\n// to its full size. Beyond these budgets, text reads stream line slices (every\n// region stays reachable in batches — lossless). The image budget is deliberately\n// far above any real screenshot/photo so quality-degrading workarounds are never\n// needed in practice; it only guards against pathological files.\nconst DEFAULT_MAX_TEXT_READ_BYTES = 16 * 1024 * 1024;\nconst DEFAULT_MAX_IMAGE_READ_BYTES = 128 * 1024 * 1024;\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\t/** Whole-file load budget for text reads; larger files stream line slices instead. Default 16 MiB. */\n\tmaxTextReadBytes?: number;\n\t/** Pathology guard for image reads; larger images return downscale guidance. Default 128 MiB. */\n\tmaxImageReadBytes?: number;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction splitContentLines(text: string): string[] {\n\tconst lines = text.split(\"\\n\");\n\tif (text.endsWith(\"\\n\")) lines.pop();\n\treturn lines;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getPiDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getPiDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = !isError && rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tlineNumbers,\n\t\t\t\ttail,\n\t\t\t\tfilter,\n\t\t\t}: {\n\t\t\t\tpath: string;\n\t\t\t\toffset?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tlineNumbers?: boolean;\n\t\t\t\ttail?: number;\n\t\t\t\tfilter?: \"none\" | \"minimal\" | \"aggressive\";\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tconst fileSize = ops.stat ? (await ops.stat(absolutePath)).size : undefined;\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\tif (fileSize !== undefined && fileSize > maxImageReadBytes) {\n\t\t\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\t\t\ttext: `Image file is ${formatSize(fileSize)} (${formatSize(maxImageReadBytes)} inline decode limit). Downscale it first, e.g. with bash (ImageMagick: magick \"${path}\" -resize 2000x2000 \"${join(getProcessWorkRun(getAgentDir(), \"images\", \"previews\").path, \"preview.png\")}\") and read the result.`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content. Oversized files are streamed as line slices so\n\t\t\t\t\t\t\t\t// any region stays reachable in batches without loading the whole file.\n\t\t\t\t\t\t\t\tconst useSlicedRead =\n\t\t\t\t\t\t\t\t\tfileSize !== undefined && fileSize > maxTextReadBytes && ops.readLineSlice !== undefined;\n\t\t\t\t\t\t\t\tlet startLine = 0;\n\t\t\t\t\t\t\t\tlet userLimitedLines = limit;\n\t\t\t\t\t\t\t\tlet totalFileLines: number | undefined;\n\t\t\t\t\t\t\t\tlet moreContentRemains = false;\n\t\t\t\t\t\t\t\tlet textContentForJsonCheck: string | undefined;\n\t\t\t\t\t\t\t\tlet slicedLines: { text: string; originalIndex: number }[];\n\t\t\t\t\t\t\t\tif (useSlicedRead && ops.readLineSlice) {\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst counted = ops.countLines ? await ops.countLines(absolutePath) : undefined;\n\t\t\t\t\t\t\t\t\t\tif (counted !== undefined) {\n\t\t\t\t\t\t\t\t\t\t\ttotalFileLines = counted;\n\t\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, counted - tail);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst slice = await ops.readLineSlice(absolutePath, {\n\t\t\t\t\t\t\t\t\t\tstartLine,\n\t\t\t\t\t\t\t\t\t\tmaxLines: userLimitedLines ?? DEFAULT_MAX_LINES,\n\t\t\t\t\t\t\t\t\t\tmaxChars: DEFAULT_MAX_BYTES * 4,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (slice.lines.length === 0 && startLine > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${startLine + 1} is beyond end of file`);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines = slice.lines;\n\t\t\t\t\t\t\t\t\tmoreContentRemains = !slice.reachedEnd;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\t\ttextContentForJsonCheck = textContent;\n\t\t\t\t\t\t\t\t\tconst allLines = splitContentLines(textContent);\n\t\t\t\t\t\t\t\t\ttotalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t\t// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, totalFileLines - tail);\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\t\tif (startLine >= allLines.length && allLines.length > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t\t`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`,\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine, startLine + userLimitedLines)\n\t\t\t\t\t\t\t\t\t\t\t: allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine);\n\t\t\t\t\t\t\t\t\tmoreContentRemains =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\tconst firstSelectedLineText = slicedLines[0]?.text ?? \"\";\n\n\t\t\t\t\t\t\t\t// Safe text filtering\n\t\t\t\t\t\t\t\tlet canFilter = true;\n\t\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst fileNameLower = path.toLowerCase();\n\t\t\t\t\t\t\t\t\tconst unsafeExtensions = [\n\t\t\t\t\t\t\t\t\t\t\".json\",\n\t\t\t\t\t\t\t\t\t\t\".jsonl\",\n\t\t\t\t\t\t\t\t\t\t\".yml\",\n\t\t\t\t\t\t\t\t\t\t\".yaml\",\n\t\t\t\t\t\t\t\t\t\t\".toml\",\n\t\t\t\t\t\t\t\t\t\t\".xml\",\n\t\t\t\t\t\t\t\t\t\t\".csv\",\n\t\t\t\t\t\t\t\t\t\t\".tsv\",\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\tif (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {\n\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t} else if (textContentForJsonCheck !== undefined) {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tJSON.parse(textContentForJsonCheck);\n\t\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (canFilter && filter && filter !== \"none\") {\n\t\t\t\t\t\t\t\t\tconst filtered: typeof slicedLines = [];\n\t\t\t\t\t\t\t\t\tif (filter === \"minimal\") {\n\t\t\t\t\t\t\t\t\t\tlet consecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmed === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank++;\n\t\t\t\t\t\t\t\t\t\t\t\tif (consecutiveBlank <= 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: \"\", originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twhile (filtered.length > 0 && filtered[filtered.length - 1].text === \"\") {\n\t\t\t\t\t\t\t\t\t\t\tfiltered.pop();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else if (filter === \"aggressive\") {\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tconst trimmedStart = trimmed.trimStart();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmedStart === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"//\") ||\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"#\") ||\n\t\t\t\t\t\t\t\t\t\t\t\t(trimmedStart.startsWith(\"/*\") && trimmedStart.endsWith(\"*/\"))\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// If filtering would empty a non-empty list, keep original\n\t\t\t\t\t\t\t\t\tconst isOriginalNotEmpty = slicedLines.some((item) => item.text.trim().length > 0);\n\t\t\t\t\t\t\t\t\tconst isFilteredEmpty = filtered.every((item) => item.text.trim().length === 0);\n\t\t\t\t\t\t\t\t\tif (isOriginalNotEmpty && isFilteredEmpty) {\n\t\t\t\t\t\t\t\t\t\t// Fallback to slicedLines\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tslicedLines = filtered;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst finalLines = slicedLines.map((item) =>\n\t\t\t\t\t\t\t\t\tlineNumbers ? `${item.originalIndex}: ${item.text}` : item.text,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst selectedContent = finalLines.join(\"\\n\");\n\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tconst totalDisplay =\n\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined\n\t\t\t\t\t\t\t\t\t\t? String(totalFileLines)\n\t\t\t\t\t\t\t\t\t\t: `a ${fileSize !== undefined ? formatSize(fileSize) : \"large\"} file`;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(firstSelectedLineText, \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (moreContentRemains) {\n\t\t\t\t\t\t\t\t\t// More content exists beyond this slice; hand the model a continuation pointer.\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + slicedLines.length + 1;\n\t\t\t\t\t\t\t\t\tconst remaining =\n\t\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined && userLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? `${totalFileLines - (startLine + userLimitedLines)} more lines in file`\n\t\t\t\t\t\t\t\t\t\t\t: \"More content remains\";\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
|
package/dist/core/tools/read.js
CHANGED
|
@@ -194,7 +194,7 @@ function formatReadResult(args, result, options, theme, showImages, _cwd, isErro
|
|
|
194
194
|
}
|
|
195
195
|
const rawPath = str(args?.file_path ?? args?.path);
|
|
196
196
|
const output = getTextOutput(result, showImages);
|
|
197
|
-
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
197
|
+
const lang = !isError && rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
198
198
|
const renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split("\n");
|
|
199
199
|
const lines = trimTrailingEmptyLines(renderedLines);
|
|
200
200
|
const maxLines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BAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CACxG,CAAC;YACF,OAAO,IAAI,CAAC;QAAA,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, open as fsOpen, readFile as fsReadFile, stat as fsStat } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getAgentDir, getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n\tlineNumbers: Type.Optional(Type.Boolean({ description: \"Include line numbers in the output\" })),\n\ttail: Type.Optional(Type.Number({ description: \"Number of lines to read from the end of the file\" })),\n\tfilter: Type.Optional(\n\t\tType.Union([Type.Literal(\"none\"), Type.Literal(\"minimal\"), Type.Literal(\"aggressive\")], {\n\t\t\tdescription: \"Safe text filtering level (none, minimal, aggressive)\",\n\t\t}),\n\t),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n\t\"GEMINI.md\",\n\t\"GEMINI.MD\",\n]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n\t/** File size in bytes, used to decide between whole-file and sliced reads. */\n\tstat?: (absolutePath: string) => Promise<{ size: number }>;\n\t/**\n\t * Stream a slice of lines out of the file with bounded memory. Any region of an\n\t * arbitrarily large file stays reachable in batches via offset continuation.\n\t */\n\treadLineSlice?: (absolutePath: string, options: LineSliceOptions) => Promise<LineSlice>;\n\t/** Count lines by streaming (bounded memory); used to resolve tail reads on oversized files. */\n\tcountLines?: (absolutePath: string) => Promise<number>;\n}\n\nexport interface LineSliceOptions {\n\t/** 0-based line to start collecting at. */\n\tstartLine: number;\n\t/** Maximum number of lines to collect. */\n\tmaxLines: number;\n\t/** Maximum total characters to collect across lines. */\n\tmaxChars: number;\n}\n\nexport interface LineSlice {\n\tlines: { text: string; originalIndex: number }[];\n\t/** True when the end of the file was reached while collecting. */\n\treachedEnd: boolean;\n}\n\nconst SLICE_SCAN_CHUNK_BYTES = 1024 * 1024;\n\nasync function scanLines(\n\tabsolutePath: string,\n\tonLine: (text: string | undefined, index: number) => boolean,\n): Promise<void> {\n\tconst handle = await fsOpen(absolutePath, \"r\");\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\n\t\tlet pending = \"\";\n\t\tlet index = 0;\n\t\tlet emittedAnyLine = false;\n\t\twhile (true) {\n\t\t\tconst { bytesRead } = await handle.read(buffer, 0, buffer.length, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tpending += decoder.write(buffer.subarray(0, bytesRead));\n\t\t\tlet lineStart = 0;\n\t\t\tlet newlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\twhile (newlineIndex !== -1) {\n\t\t\t\temittedAnyLine = true;\n\t\t\t\tif (!onLine(pending.slice(lineStart, newlineIndex), index++)) return;\n\t\t\t\tlineStart = newlineIndex + 1;\n\t\t\t\tnewlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\t}\n\t\t\tpending = pending.slice(lineStart);\n\t\t}\n\t\tpending += decoder.end();\n\t\tif (pending.length > 0 || !emittedAnyLine) {\n\t\t\tonLine(pending, index);\n\t\t}\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function readLocalLineSlice(absolutePath: string, options: LineSliceOptions): Promise<LineSlice> {\n\tconst lines: { text: string; originalIndex: number }[] = [];\n\tlet collectedChars = 0;\n\tlet sawMore = false;\n\tawait scanLines(absolutePath, (text, index) => {\n\t\tif (text === undefined) return false;\n\t\tif (index < options.startLine) return true;\n\t\tif (lines.length >= options.maxLines || collectedChars > options.maxChars) {\n\t\t\tsawMore = true;\n\t\t\treturn false;\n\t\t}\n\t\tlines.push({ text, originalIndex: index + 1 });\n\t\tcollectedChars += text.length;\n\t\treturn true;\n\t});\n\treturn { lines, reachedEnd: !sawMore };\n}\n\nasync function countLocalLines(absolutePath: string): Promise<number> {\n\tlet count = 0;\n\tawait scanLines(absolutePath, () => {\n\t\tcount++;\n\t\treturn true;\n\t});\n\treturn count;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n\tstat: async (path) => ({ size: (await fsStat(path)).size }),\n\treadLineSlice: readLocalLineSlice,\n\tcountLines: countLocalLines,\n};\n\n// Loading a whole file before truncation lets a single giant file spike the heap\n// to its full size. Beyond these budgets, text reads stream line slices (every\n// region stays reachable in batches — lossless). The image budget is deliberately\n// far above any real screenshot/photo so quality-degrading workarounds are never\n// needed in practice; it only guards against pathological files.\nconst DEFAULT_MAX_TEXT_READ_BYTES = 16 * 1024 * 1024;\nconst DEFAULT_MAX_IMAGE_READ_BYTES = 128 * 1024 * 1024;\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\t/** Whole-file load budget for text reads; larger files stream line slices instead. Default 16 MiB. */\n\tmaxTextReadBytes?: number;\n\t/** Pathology guard for image reads; larger images return downscale guidance. Default 128 MiB. */\n\tmaxImageReadBytes?: number;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction splitContentLines(text: string): string[] {\n\tconst lines = text.split(\"\\n\");\n\tif (text.endsWith(\"\\n\")) lines.pop();\n\treturn lines;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getPiDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getPiDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tlineNumbers,\n\t\t\t\ttail,\n\t\t\t\tfilter,\n\t\t\t}: {\n\t\t\t\tpath: string;\n\t\t\t\toffset?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tlineNumbers?: boolean;\n\t\t\t\ttail?: number;\n\t\t\t\tfilter?: \"none\" | \"minimal\" | \"aggressive\";\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tconst fileSize = ops.stat ? (await ops.stat(absolutePath)).size : undefined;\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\tif (fileSize !== undefined && fileSize > maxImageReadBytes) {\n\t\t\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\t\t\ttext: `Image file is ${formatSize(fileSize)} (${formatSize(maxImageReadBytes)} inline decode limit). Downscale it first, e.g. with bash (ImageMagick: magick \"${path}\" -resize 2000x2000 \"${join(getProcessWorkRun(getAgentDir(), \"images\", \"previews\").path, \"preview.png\")}\") and read the result.`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content. Oversized files are streamed as line slices so\n\t\t\t\t\t\t\t\t// any region stays reachable in batches without loading the whole file.\n\t\t\t\t\t\t\t\tconst useSlicedRead =\n\t\t\t\t\t\t\t\t\tfileSize !== undefined && fileSize > maxTextReadBytes && ops.readLineSlice !== undefined;\n\t\t\t\t\t\t\t\tlet startLine = 0;\n\t\t\t\t\t\t\t\tlet userLimitedLines = limit;\n\t\t\t\t\t\t\t\tlet totalFileLines: number | undefined;\n\t\t\t\t\t\t\t\tlet moreContentRemains = false;\n\t\t\t\t\t\t\t\tlet textContentForJsonCheck: string | undefined;\n\t\t\t\t\t\t\t\tlet slicedLines: { text: string; originalIndex: number }[];\n\t\t\t\t\t\t\t\tif (useSlicedRead && ops.readLineSlice) {\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst counted = ops.countLines ? await ops.countLines(absolutePath) : undefined;\n\t\t\t\t\t\t\t\t\t\tif (counted !== undefined) {\n\t\t\t\t\t\t\t\t\t\t\ttotalFileLines = counted;\n\t\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, counted - tail);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst slice = await ops.readLineSlice(absolutePath, {\n\t\t\t\t\t\t\t\t\t\tstartLine,\n\t\t\t\t\t\t\t\t\t\tmaxLines: userLimitedLines ?? DEFAULT_MAX_LINES,\n\t\t\t\t\t\t\t\t\t\tmaxChars: DEFAULT_MAX_BYTES * 4,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (slice.lines.length === 0 && startLine > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${startLine + 1} is beyond end of file`);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines = slice.lines;\n\t\t\t\t\t\t\t\t\tmoreContentRemains = !slice.reachedEnd;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\t\ttextContentForJsonCheck = textContent;\n\t\t\t\t\t\t\t\t\tconst allLines = splitContentLines(textContent);\n\t\t\t\t\t\t\t\t\ttotalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t\t// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, totalFileLines - tail);\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\t\tif (startLine >= allLines.length && allLines.length > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t\t`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`,\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine, startLine + userLimitedLines)\n\t\t\t\t\t\t\t\t\t\t\t: allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine);\n\t\t\t\t\t\t\t\t\tmoreContentRemains =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\tconst firstSelectedLineText = slicedLines[0]?.text ?? \"\";\n\n\t\t\t\t\t\t\t\t// Safe text filtering\n\t\t\t\t\t\t\t\tlet canFilter = true;\n\t\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst fileNameLower = path.toLowerCase();\n\t\t\t\t\t\t\t\t\tconst unsafeExtensions = [\n\t\t\t\t\t\t\t\t\t\t\".json\",\n\t\t\t\t\t\t\t\t\t\t\".jsonl\",\n\t\t\t\t\t\t\t\t\t\t\".yml\",\n\t\t\t\t\t\t\t\t\t\t\".yaml\",\n\t\t\t\t\t\t\t\t\t\t\".toml\",\n\t\t\t\t\t\t\t\t\t\t\".xml\",\n\t\t\t\t\t\t\t\t\t\t\".csv\",\n\t\t\t\t\t\t\t\t\t\t\".tsv\",\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\tif (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {\n\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t} else if (textContentForJsonCheck !== undefined) {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tJSON.parse(textContentForJsonCheck);\n\t\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (canFilter && filter && filter !== \"none\") {\n\t\t\t\t\t\t\t\t\tconst filtered: typeof slicedLines = [];\n\t\t\t\t\t\t\t\t\tif (filter === \"minimal\") {\n\t\t\t\t\t\t\t\t\t\tlet consecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmed === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank++;\n\t\t\t\t\t\t\t\t\t\t\t\tif (consecutiveBlank <= 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: \"\", originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twhile (filtered.length > 0 && filtered[filtered.length - 1].text === \"\") {\n\t\t\t\t\t\t\t\t\t\t\tfiltered.pop();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else if (filter === \"aggressive\") {\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tconst trimmedStart = trimmed.trimStart();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmedStart === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"//\") ||\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"#\") ||\n\t\t\t\t\t\t\t\t\t\t\t\t(trimmedStart.startsWith(\"/*\") && trimmedStart.endsWith(\"*/\"))\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// If filtering would empty a non-empty list, keep original\n\t\t\t\t\t\t\t\t\tconst isOriginalNotEmpty = slicedLines.some((item) => item.text.trim().length > 0);\n\t\t\t\t\t\t\t\t\tconst isFilteredEmpty = filtered.every((item) => item.text.trim().length === 0);\n\t\t\t\t\t\t\t\t\tif (isOriginalNotEmpty && isFilteredEmpty) {\n\t\t\t\t\t\t\t\t\t\t// Fallback to slicedLines\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tslicedLines = filtered;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst finalLines = slicedLines.map((item) =>\n\t\t\t\t\t\t\t\t\tlineNumbers ? `${item.originalIndex}: ${item.text}` : item.text,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst selectedContent = finalLines.join(\"\\n\");\n\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tconst totalDisplay =\n\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined\n\t\t\t\t\t\t\t\t\t\t? String(totalFileLines)\n\t\t\t\t\t\t\t\t\t\t: `a ${fileSize !== undefined ? formatSize(fileSize) : \"large\"} file`;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(firstSelectedLineText, \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (moreContentRemains) {\n\t\t\t\t\t\t\t\t\t// More content exists beyond this slice; hand the model a continuation pointer.\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + slicedLines.length + 1;\n\t\t\t\t\t\t\t\t\tconst remaining =\n\t\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined && userLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? `${totalFileLines - (startLine + userLimitedLines)} more lines in file`\n\t\t\t\t\t\t\t\t\t\t\t: \"More content remains\";\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACvG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAEV,YAAY,GACZ,MAAM,gCAAgC,CAAC;AA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isAbsolute, join, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"@caupulican/pi-agent-core/node\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, open as fsOpen, readFile as fsReadFile, stat as fsStat } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getAgentDir, getReadmePath } from \"../../config.ts\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n\tlineNumbers: Type.Optional(Type.Boolean({ description: \"Include line numbers in the output\" })),\n\ttail: Type.Optional(Type.Number({ description: \"Number of lines to read from the end of the file\" })),\n\tfilter: Type.Optional(\n\t\tType.Union([Type.Literal(\"none\"), Type.Literal(\"minimal\"), Type.Literal(\"aggressive\")], {\n\t\t\tdescription: \"Safe text filtering level (none, minimal, aggressive)\",\n\t\t}),\n\t),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\ninterface CompactReadClassification {\n\tkind: \"docs\" | \"resource\" | \"skill\";\n\tlabel: string;\n}\n\nconst COMPACT_RESOURCE_FILE_NAMES = new Set([\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n\t\"GEMINI.md\",\n\t\"GEMINI.MD\",\n]);\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n\t/** File size in bytes, used to decide between whole-file and sliced reads. */\n\tstat?: (absolutePath: string) => Promise<{ size: number }>;\n\t/**\n\t * Stream a slice of lines out of the file with bounded memory. Any region of an\n\t * arbitrarily large file stays reachable in batches via offset continuation.\n\t */\n\treadLineSlice?: (absolutePath: string, options: LineSliceOptions) => Promise<LineSlice>;\n\t/** Count lines by streaming (bounded memory); used to resolve tail reads on oversized files. */\n\tcountLines?: (absolutePath: string) => Promise<number>;\n}\n\nexport interface LineSliceOptions {\n\t/** 0-based line to start collecting at. */\n\tstartLine: number;\n\t/** Maximum number of lines to collect. */\n\tmaxLines: number;\n\t/** Maximum total characters to collect across lines. */\n\tmaxChars: number;\n}\n\nexport interface LineSlice {\n\tlines: { text: string; originalIndex: number }[];\n\t/** True when the end of the file was reached while collecting. */\n\treachedEnd: boolean;\n}\n\nconst SLICE_SCAN_CHUNK_BYTES = 1024 * 1024;\n\nasync function scanLines(\n\tabsolutePath: string,\n\tonLine: (text: string | undefined, index: number) => boolean,\n): Promise<void> {\n\tconst handle = await fsOpen(absolutePath, \"r\");\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\n\t\tlet pending = \"\";\n\t\tlet index = 0;\n\t\tlet emittedAnyLine = false;\n\t\twhile (true) {\n\t\t\tconst { bytesRead } = await handle.read(buffer, 0, buffer.length, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tpending += decoder.write(buffer.subarray(0, bytesRead));\n\t\t\tlet lineStart = 0;\n\t\t\tlet newlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\twhile (newlineIndex !== -1) {\n\t\t\t\temittedAnyLine = true;\n\t\t\t\tif (!onLine(pending.slice(lineStart, newlineIndex), index++)) return;\n\t\t\t\tlineStart = newlineIndex + 1;\n\t\t\t\tnewlineIndex = pending.indexOf(\"\\n\", lineStart);\n\t\t\t}\n\t\t\tpending = pending.slice(lineStart);\n\t\t}\n\t\tpending += decoder.end();\n\t\tif (pending.length > 0 || !emittedAnyLine) {\n\t\t\tonLine(pending, index);\n\t\t}\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function readLocalLineSlice(absolutePath: string, options: LineSliceOptions): Promise<LineSlice> {\n\tconst lines: { text: string; originalIndex: number }[] = [];\n\tlet collectedChars = 0;\n\tlet sawMore = false;\n\tawait scanLines(absolutePath, (text, index) => {\n\t\tif (text === undefined) return false;\n\t\tif (index < options.startLine) return true;\n\t\tif (lines.length >= options.maxLines || collectedChars > options.maxChars) {\n\t\t\tsawMore = true;\n\t\t\treturn false;\n\t\t}\n\t\tlines.push({ text, originalIndex: index + 1 });\n\t\tcollectedChars += text.length;\n\t\treturn true;\n\t});\n\treturn { lines, reachedEnd: !sawMore };\n}\n\nasync function countLocalLines(absolutePath: string): Promise<number> {\n\tlet count = 0;\n\tawait scanLines(absolutePath, () => {\n\t\tcount++;\n\t\treturn true;\n\t});\n\treturn count;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n\tstat: async (path) => ({ size: (await fsStat(path)).size }),\n\treadLineSlice: readLocalLineSlice,\n\tcountLines: countLocalLines,\n};\n\n// Loading a whole file before truncation lets a single giant file spike the heap\n// to its full size. Beyond these budgets, text reads stream line slices (every\n// region stays reachable in batches — lossless). The image budget is deliberately\n// far above any real screenshot/photo so quality-degrading workarounds are never\n// needed in practice; it only guards against pathological files.\nconst DEFAULT_MAX_TEXT_READ_BYTES = 16 * 1024 * 1024;\nconst DEFAULT_MAX_IMAGE_READ_BYTES = 128 * 1024 * 1024;\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n\t/** Whole-file load budget for text reads; larger files stream line slices instead. Default 16 MiB. */\n\tmaxTextReadBytes?: number;\n\t/** Pathology guard for image reads; larger images return downscale guidance. Default 128 MiB. */\n\tmaxImageReadBytes?: number;\n}\n\ntype ReadRenderArgs = { path?: string; file_path?: string; offset?: number; limit?: number };\n\nfunction formatReadLineRange(args: ReadRenderArgs | undefined, theme: Theme): string {\n\tif (args?.offset === undefined && args?.limit === undefined) return \"\";\n\tconst startLine = args.offset ?? 1;\n\tconst endLine = args.limit !== undefined ? startLine + args.limit - 1 : \"\";\n\treturn theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n}\n\nfunction formatReadCall(args: ReadRenderArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}${formatReadLineRange(args, theme)}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction splitContentLines(text: string): string[] {\n\tconst lines = text.split(\"\\n\");\n\tif (text.endsWith(\"\\n\")) lines.pop();\n\treturn lines;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nfunction toPosixPath(filePath: string): string {\n\treturn filePath.split(sep).join(\"/\");\n}\n\nfunction getPiDocsClassification(absolutePath: string): CompactReadClassification | undefined {\n\tconst packageRoot = dirname(getReadmePath());\n\tconst relativePath = relative(resolvePath(packageRoot), resolvePath(absolutePath));\n\tif (\n\t\trelativePath === \"\" ||\n\t\trelativePath === \"..\" ||\n\t\trelativePath.startsWith(`..${sep}`) ||\n\t\tisAbsolute(relativePath)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst label = toPosixPath(relativePath);\n\tif (label === \"README.md\" || label.startsWith(\"docs/\") || label.startsWith(\"examples/\")) {\n\t\treturn { kind: \"docs\", label };\n\t}\n\treturn undefined;\n}\n\nfunction getCompactReadClassification(\n\targs: ReadRenderArgs | undefined,\n\tcwd: string,\n): CompactReadClassification | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tif (!rawPath) return undefined;\n\n\tconst absolutePath = resolveToCwd(rawPath, cwd);\n\tconst fileName = basename(absolutePath);\n\tif (fileName === \"SKILL.md\") {\n\t\treturn { kind: \"skill\", label: basename(dirname(absolutePath)) || fileName };\n\t}\n\n\tconst docsClassification = getPiDocsClassification(absolutePath);\n\tif (docsClassification) return docsClassification;\n\n\tif (COMPACT_RESOURCE_FILE_NAMES.has(fileName)) {\n\t\treturn { kind: \"resource\", label: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd) };\n\t}\n\n\treturn undefined;\n}\n\nfunction formatCompactReadCall(\n\tclassification: CompactReadClassification,\n\targs: ReadRenderArgs | undefined,\n\ttheme: Theme,\n): string {\n\tconst expandHint = theme.fg(\"dim\", ` (${keyText(\"app.tools.expand\")} to expand)`);\n\tif (classification.kind === \"skill\") {\n\t\treturn (\n\t\t\ttheme.fg(\"customMessageLabel\", `\\x1b[1m[skill]\\x1b[22m `) +\n\t\t\ttheme.fg(\"customMessageText\", classification.label) +\n\t\t\tformatReadLineRange(args, theme) +\n\t\t\texpandHint\n\t\t);\n\t}\n\n\treturn (\n\t\ttheme.fg(\"toolTitle\", theme.bold(`read ${classification.kind}`)) +\n\t\t\" \" +\n\t\ttheme.fg(\"accent\", classification.label) +\n\t\tformatReadLineRange(args, theme) +\n\t\texpandHint\n\t);\n}\n\nfunction formatReadResult(\n\targs: ReadRenderArgs | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n\t_cwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = !isError && rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\toffset,\n\t\t\t\tlimit,\n\t\t\t\tlineNumbers,\n\t\t\t\ttail,\n\t\t\t\tfilter,\n\t\t\t}: {\n\t\t\t\tpath: string;\n\t\t\t\toffset?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tlineNumbers?: boolean;\n\t\t\t\ttail?: number;\n\t\t\t\tfilter?: \"none\" | \"minimal\" | \"aggressive\";\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tconst fileSize = ops.stat ? (await ops.stat(absolutePath)).size : undefined;\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\tif (fileSize !== undefined && fileSize > maxImageReadBytes) {\n\t\t\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\t\t\ttext: `Image file is ${formatSize(fileSize)} (${formatSize(maxImageReadBytes)} inline decode limit). Downscale it first, e.g. with bash (ImageMagick: magick \"${path}\" -resize 2000x2000 \"${join(getProcessWorkRun(getAgentDir(), \"images\", \"previews\").path, \"preview.png\")}\") and read the result.`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage(buffer, mimeType);\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: buffer.toString(\"base64\"), mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content. Oversized files are streamed as line slices so\n\t\t\t\t\t\t\t\t// any region stays reachable in batches without loading the whole file.\n\t\t\t\t\t\t\t\tconst useSlicedRead =\n\t\t\t\t\t\t\t\t\tfileSize !== undefined && fileSize > maxTextReadBytes && ops.readLineSlice !== undefined;\n\t\t\t\t\t\t\t\tlet startLine = 0;\n\t\t\t\t\t\t\t\tlet userLimitedLines = limit;\n\t\t\t\t\t\t\t\tlet totalFileLines: number | undefined;\n\t\t\t\t\t\t\t\tlet moreContentRemains = false;\n\t\t\t\t\t\t\t\tlet textContentForJsonCheck: string | undefined;\n\t\t\t\t\t\t\t\tlet slicedLines: { text: string; originalIndex: number }[];\n\t\t\t\t\t\t\t\tif (useSlicedRead && ops.readLineSlice) {\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst counted = ops.countLines ? await ops.countLines(absolutePath) : undefined;\n\t\t\t\t\t\t\t\t\t\tif (counted !== undefined) {\n\t\t\t\t\t\t\t\t\t\t\ttotalFileLines = counted;\n\t\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, counted - tail);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst slice = await ops.readLineSlice(absolutePath, {\n\t\t\t\t\t\t\t\t\t\tstartLine,\n\t\t\t\t\t\t\t\t\t\tmaxLines: userLimitedLines ?? DEFAULT_MAX_LINES,\n\t\t\t\t\t\t\t\t\t\tmaxChars: DEFAULT_MAX_BYTES * 4,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (slice.lines.length === 0 && startLine > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${startLine + 1} is beyond end of file`);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines = slice.lines;\n\t\t\t\t\t\t\t\t\tmoreContentRemains = !slice.reachedEnd;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\t\ttextContentForJsonCheck = textContent;\n\t\t\t\t\t\t\t\t\tconst allLines = splitContentLines(textContent);\n\t\t\t\t\t\t\t\t\ttotalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t\t// Apply offset/tail if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\t\tif (offset !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, offset - 1);\n\t\t\t\t\t\t\t\t\t} else if (tail !== undefined) {\n\t\t\t\t\t\t\t\t\t\tstartLine = Math.max(0, totalFileLines - tail);\n\t\t\t\t\t\t\t\t\t\tif (limit === undefined) {\n\t\t\t\t\t\t\t\t\t\t\tuserLimitedLines = tail;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\t\tif (startLine >= allLines.length && allLines.length > 0) {\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t\t`Offset ${startLine + 1} is beyond end of file (${allLines.length} lines total)`,\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tslicedLines =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine, startLine + userLimitedLines)\n\t\t\t\t\t\t\t\t\t\t\t: allLines\n\t\t\t\t\t\t\t\t\t\t\t\t\t.map((line, idx) => ({ text: line, originalIndex: idx + 1 }))\n\t\t\t\t\t\t\t\t\t\t\t\t\t.slice(startLine);\n\t\t\t\t\t\t\t\t\tmoreContentRemains =\n\t\t\t\t\t\t\t\t\t\tuserLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\tconst firstSelectedLineText = slicedLines[0]?.text ?? \"\";\n\n\t\t\t\t\t\t\t\t// Safe text filtering\n\t\t\t\t\t\t\t\tlet canFilter = true;\n\t\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst fileNameLower = path.toLowerCase();\n\t\t\t\t\t\t\t\t\tconst unsafeExtensions = [\n\t\t\t\t\t\t\t\t\t\t\".json\",\n\t\t\t\t\t\t\t\t\t\t\".jsonl\",\n\t\t\t\t\t\t\t\t\t\t\".yml\",\n\t\t\t\t\t\t\t\t\t\t\".yaml\",\n\t\t\t\t\t\t\t\t\t\t\".toml\",\n\t\t\t\t\t\t\t\t\t\t\".xml\",\n\t\t\t\t\t\t\t\t\t\t\".csv\",\n\t\t\t\t\t\t\t\t\t\t\".tsv\",\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\tif (unsafeExtensions.some((ext) => fileNameLower.endsWith(ext))) {\n\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t} else if (textContentForJsonCheck !== undefined) {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tJSON.parse(textContentForJsonCheck);\n\t\t\t\t\t\t\t\t\t\t\tcanFilter = false;\n\t\t\t\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (canFilter && filter && filter !== \"none\") {\n\t\t\t\t\t\t\t\t\tconst filtered: typeof slicedLines = [];\n\t\t\t\t\t\t\t\t\tif (filter === \"minimal\") {\n\t\t\t\t\t\t\t\t\t\tlet consecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmed === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank++;\n\t\t\t\t\t\t\t\t\t\t\t\tif (consecutiveBlank <= 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: \"\", originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tconsecutiveBlank = 0;\n\t\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twhile (filtered.length > 0 && filtered[filtered.length - 1].text === \"\") {\n\t\t\t\t\t\t\t\t\t\t\tfiltered.pop();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else if (filter === \"aggressive\") {\n\t\t\t\t\t\t\t\t\t\tfor (const item of slicedLines) {\n\t\t\t\t\t\t\t\t\t\t\tconst trimmed = item.text.trimEnd();\n\t\t\t\t\t\t\t\t\t\t\tconst trimmedStart = trimmed.trimStart();\n\t\t\t\t\t\t\t\t\t\t\tif (trimmedStart === \"\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"//\") ||\n\t\t\t\t\t\t\t\t\t\t\t\ttrimmedStart.startsWith(\"#\") ||\n\t\t\t\t\t\t\t\t\t\t\t\t(trimmedStart.startsWith(\"/*\") && trimmedStart.endsWith(\"*/\"))\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tfiltered.push({ text: trimmed, originalIndex: item.originalIndex });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// If filtering would empty a non-empty list, keep original\n\t\t\t\t\t\t\t\t\tconst isOriginalNotEmpty = slicedLines.some((item) => item.text.trim().length > 0);\n\t\t\t\t\t\t\t\t\tconst isFilteredEmpty = filtered.every((item) => item.text.trim().length === 0);\n\t\t\t\t\t\t\t\t\tif (isOriginalNotEmpty && isFilteredEmpty) {\n\t\t\t\t\t\t\t\t\t\t// Fallback to slicedLines\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tslicedLines = filtered;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst finalLines = slicedLines.map((item) =>\n\t\t\t\t\t\t\t\t\tlineNumbers ? `${item.originalIndex}: ${item.text}` : item.text,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst selectedContent = finalLines.join(\"\\n\");\n\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tconst totalDisplay =\n\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined\n\t\t\t\t\t\t\t\t\t\t? String(totalFileLines)\n\t\t\t\t\t\t\t\t\t\t: `a ${fileSize !== undefined ? formatSize(fileSize) : \"large\"} file`;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(firstSelectedLineText, \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalDisplay} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (moreContentRemains) {\n\t\t\t\t\t\t\t\t\t// More content exists beyond this slice; hand the model a continuation pointer.\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + slicedLines.length + 1;\n\t\t\t\t\t\t\t\t\tconst remaining =\n\t\t\t\t\t\t\t\t\t\ttotalFileLines !== undefined && userLimitedLines !== undefined\n\t\t\t\t\t\t\t\t\t\t\t? `${totalFileLines - (startLine + userLimitedLines)} more lines in file`\n\t\t\t\t\t\t\t\t\t\t\t: \"More content remains\";\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification\n\t\t\t\t\t? formatCompactReadCall(classification, args, theme)\n\t\t\t\t\t: formatReadCall(args, theme, context.cwd),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(\n\t\t\t\tformatReadResult(context.args, result, options, theme, context.showImages, context.cwd, context.isError),\n\t\t\t);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgentTool } from "@caupulican/pi-agent-core";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import { spawnProcess } from "../../utils/child-process.ts";
|
|
4
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
5
|
+
import type { OrchestrationExecutionPolicy } from "../orchestration/contracts.ts";
|
|
6
|
+
declare const runProcessSchema: Type.TObject<{
|
|
7
|
+
executable: Type.TString;
|
|
8
|
+
args: Type.TOptional<Type.TArray<Type.TString>>;
|
|
9
|
+
}>;
|
|
10
|
+
export type RunProcessInput = Static<typeof runProcessSchema>;
|
|
11
|
+
export interface RunProcessDetails {
|
|
12
|
+
outcome: "exited" | "failed" | "aborted" | "timeout" | "output_limit";
|
|
13
|
+
executable: string;
|
|
14
|
+
exitCode: number | null;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
truncated: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface RunProcessToolOptions {
|
|
19
|
+
policy: OrchestrationExecutionPolicy;
|
|
20
|
+
maxWallClockMs: number;
|
|
21
|
+
spawn?: typeof spawnProcess;
|
|
22
|
+
}
|
|
23
|
+
export declare function createRunProcessToolDefinition(cwd: string, options: RunProcessToolOptions): ToolDefinition;
|
|
24
|
+
export declare function createRunProcessTool(cwd: string, options: RunProcessToolOptions): AgentTool;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=run-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-process.d.ts","sourceRoot":"","sources":["../../../src/core/tools/run-process.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAsC,MAAM,8BAA8B,CAAC;AAChG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAGlF,QAAA,MAAM,gBAAgB;;;EAMrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,cAAc,CAAC;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,4BAA4B,CAAC;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,YAAY,CAAC;CAC5B;AAuDD,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,cAAc,CA8E1G;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAE3F","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { OrchestrationExecutionPolicy } from \"../orchestration/contracts.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst runProcessSchema = Type.Object(\n\t{\n\t\texecutable: Type.String({ description: \"Exact owner-allowed executable name or path.\" }),\n\t\targs: Type.Optional(Type.Array(Type.String(), { description: \"Direct argv entries. No shell parsing occurs.\" })),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type RunProcessInput = Static<typeof runProcessSchema>;\n\nexport interface RunProcessDetails {\n\toutcome: \"exited\" | \"failed\" | \"aborted\" | \"timeout\" | \"output_limit\";\n\texecutable: string;\n\texitCode: number | null;\n\tdurationMs: number;\n\ttruncated: boolean;\n}\n\nexport interface RunProcessToolOptions {\n\tpolicy: OrchestrationExecutionPolicy;\n\tmaxWallClockMs: number;\n\tspawn?: typeof spawnProcess;\n}\n\nconst SAFE_ENVIRONMENT_VARIABLES = [\n\t\"PATH\",\n\t\"PATHEXT\",\n\t\"SystemRoot\",\n\t\"WINDIR\",\n\t\"COMSPEC\",\n\t\"TMPDIR\",\n\t\"TMP\",\n\t\"TEMP\",\n] as const;\n\nfunction scopedEnvironment(allowedNames: readonly string[]): NodeJS.ProcessEnv {\n\tconst names = new Set<string>([...SAFE_ENVIRONMENT_VARIABLES, ...allowedNames]);\n\tconst environment: NodeJS.ProcessEnv = {};\n\tfor (const name of names) {\n\t\tconst value = process.env[name];\n\t\tif (value !== undefined) environment[name] = value;\n\t}\n\treturn environment;\n}\n\nfunction collectBoundedOutput(\n\tchild: ChildProcess,\n\tmaxBytes: number,\n\tabort: () => void,\n): {\n\tread(): { stdout: string; stderr: string; truncated: boolean };\n} {\n\tlet remaining = maxBytes;\n\tlet truncated = false;\n\tconst stdout: Buffer[] = [];\n\tconst stderr: Buffer[] = [];\n\tconst collect = (target: Buffer[]) => (chunk: Buffer) => {\n\t\tif (remaining <= 0) return;\n\t\tconst retained = chunk.subarray(0, remaining);\n\t\ttarget.push(retained);\n\t\tremaining -= retained.length;\n\t\tif (retained.length < chunk.length || remaining === 0) {\n\t\t\ttruncated = true;\n\t\t\tabort();\n\t\t}\n\t};\n\tchild.stdout?.on(\"data\", collect(stdout));\n\tchild.stderr?.on(\"data\", collect(stderr));\n\treturn {\n\t\tread: () => ({\n\t\t\tstdout: Buffer.concat(stdout).toString(\"utf-8\"),\n\t\t\tstderr: Buffer.concat(stderr).toString(\"utf-8\"),\n\t\t\ttruncated,\n\t\t}),\n\t};\n}\n\nexport function createRunProcessToolDefinition(cwd: string, options: RunProcessToolOptions): ToolDefinition {\n\tconst allowedExecutables = new Set(options.policy.allowedExecutables);\n\treturn {\n\t\tname: \"run_process\",\n\t\tlabel: \"Run Process\",\n\t\tdescription: `Run one owner-allowed executable using direct argv without a shell. Allowed: ${options.policy.allowedExecutables.join(\", \")}.`,\n\t\tpromptSnippet: \"Run an owner-allowed executable through a constrained direct-argv launcher (not OS isolation).\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use only an executable listed by the profile. Arguments are passed literally; shell operators and interpolation are unavailable.\",\n\t\t\t\"Treat a non-zero exit code, timeout, abort, or output-limit termination as failure.\",\n\t\t],\n\t\tparameters: runProcessSchema,\n\t\tasync execute(_toolCallId, input: RunProcessInput, signal) {\n\t\t\tif (!allowedExecutables.has(input.executable)) {\n\t\t\t\tthrow new Error(`process_executable_denied: '${input.executable}' is not owner-allowed.`);\n\t\t\t}\n\t\t\tconst args = input.args ?? [];\n\t\t\tif (input.executable.includes(\"\\0\") || args.some((argument) => argument.includes(\"\\0\"))) {\n\t\t\t\tthrow new Error(\"process_argument_invalid: executable and argv must not contain NUL bytes.\");\n\t\t\t}\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst outputLimitAbort = new AbortController();\n\t\t\tlet outputLimitReached = false;\n\t\t\tconst child = (options.spawn ?? spawnProcess)(input.executable, [...args], {\n\t\t\t\tcwd,\n\t\t\t\tenv: scopedEnvironment(options.policy.allowedEnvironmentVariables),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tconst output = collectBoundedOutput(child, options.policy.maxOutputBytes, () => {\n\t\t\t\toutputLimitReached = true;\n\t\t\t\toutputLimitAbort.abort();\n\t\t\t});\n\t\t\tconst combinedAbort = new AbortController();\n\t\t\tconst abort = () => combinedAbort.abort();\n\t\t\tif (signal?.aborted || outputLimitAbort.signal.aborted) abort();\n\t\t\telse {\n\t\t\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\toutputLimitAbort.signal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal: combinedAbort.signal,\n\t\t\t\t\ttimeoutMs: options.maxWallClockMs > 0 ? options.maxWallClockMs : undefined,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tconst captured = output.read();\n\t\t\t\tconst outcome: RunProcessDetails[\"outcome\"] = outputLimitReached\n\t\t\t\t\t? \"output_limit\"\n\t\t\t\t\t: terminal.reason === \"timeout\"\n\t\t\t\t\t\t? \"timeout\"\n\t\t\t\t\t\t: terminal.reason === \"aborted\"\n\t\t\t\t\t\t\t? \"aborted\"\n\t\t\t\t\t\t\t: terminal.code === 0\n\t\t\t\t\t\t\t\t? \"exited\"\n\t\t\t\t\t\t\t\t: \"failed\";\n\t\t\t\tconst body = [\n\t\t\t\t\t`outcome: ${outcome}`,\n\t\t\t\t\t`exitCode: ${terminal.code ?? \"null\"}`,\n\t\t\t\t\tcaptured.stdout ? `stdout:\\n${captured.stdout}` : \"stdout: (empty)\",\n\t\t\t\t\tcaptured.stderr ? `stderr:\\n${captured.stderr}` : \"stderr: (empty)\",\n\t\t\t\t].join(\"\\n\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: body }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\texecutable: input.executable,\n\t\t\t\t\t\texitCode: terminal.code,\n\t\t\t\t\t\tdurationMs: Date.now() - startedAt,\n\t\t\t\t\t\ttruncated: captured.truncated,\n\t\t\t\t\t} satisfies RunProcessDetails,\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\toutputLimitAbort.signal.removeEventListener(\"abort\", abort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function createRunProcessTool(cwd: string, options: RunProcessToolOptions): AgentTool {\n\treturn wrapToolDefinition(createRunProcessToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { spawnProcess, waitForChildProcessWithTermination } from "../../utils/child-process.js";
|
|
3
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
4
|
+
const runProcessSchema = Type.Object({
|
|
5
|
+
executable: Type.String({ description: "Exact owner-allowed executable name or path." }),
|
|
6
|
+
args: Type.Optional(Type.Array(Type.String(), { description: "Direct argv entries. No shell parsing occurs." })),
|
|
7
|
+
}, { additionalProperties: false });
|
|
8
|
+
const SAFE_ENVIRONMENT_VARIABLES = [
|
|
9
|
+
"PATH",
|
|
10
|
+
"PATHEXT",
|
|
11
|
+
"SystemRoot",
|
|
12
|
+
"WINDIR",
|
|
13
|
+
"COMSPEC",
|
|
14
|
+
"TMPDIR",
|
|
15
|
+
"TMP",
|
|
16
|
+
"TEMP",
|
|
17
|
+
];
|
|
18
|
+
function scopedEnvironment(allowedNames) {
|
|
19
|
+
const names = new Set([...SAFE_ENVIRONMENT_VARIABLES, ...allowedNames]);
|
|
20
|
+
const environment = {};
|
|
21
|
+
for (const name of names) {
|
|
22
|
+
const value = process.env[name];
|
|
23
|
+
if (value !== undefined)
|
|
24
|
+
environment[name] = value;
|
|
25
|
+
}
|
|
26
|
+
return environment;
|
|
27
|
+
}
|
|
28
|
+
function collectBoundedOutput(child, maxBytes, abort) {
|
|
29
|
+
let remaining = maxBytes;
|
|
30
|
+
let truncated = false;
|
|
31
|
+
const stdout = [];
|
|
32
|
+
const stderr = [];
|
|
33
|
+
const collect = (target) => (chunk) => {
|
|
34
|
+
if (remaining <= 0)
|
|
35
|
+
return;
|
|
36
|
+
const retained = chunk.subarray(0, remaining);
|
|
37
|
+
target.push(retained);
|
|
38
|
+
remaining -= retained.length;
|
|
39
|
+
if (retained.length < chunk.length || remaining === 0) {
|
|
40
|
+
truncated = true;
|
|
41
|
+
abort();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
child.stdout?.on("data", collect(stdout));
|
|
45
|
+
child.stderr?.on("data", collect(stderr));
|
|
46
|
+
return {
|
|
47
|
+
read: () => ({
|
|
48
|
+
stdout: Buffer.concat(stdout).toString("utf-8"),
|
|
49
|
+
stderr: Buffer.concat(stderr).toString("utf-8"),
|
|
50
|
+
truncated,
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function createRunProcessToolDefinition(cwd, options) {
|
|
55
|
+
const allowedExecutables = new Set(options.policy.allowedExecutables);
|
|
56
|
+
return {
|
|
57
|
+
name: "run_process",
|
|
58
|
+
label: "Run Process",
|
|
59
|
+
description: `Run one owner-allowed executable using direct argv without a shell. Allowed: ${options.policy.allowedExecutables.join(", ")}.`,
|
|
60
|
+
promptSnippet: "Run an owner-allowed executable through a constrained direct-argv launcher (not OS isolation).",
|
|
61
|
+
promptGuidelines: [
|
|
62
|
+
"Use only an executable listed by the profile. Arguments are passed literally; shell operators and interpolation are unavailable.",
|
|
63
|
+
"Treat a non-zero exit code, timeout, abort, or output-limit termination as failure.",
|
|
64
|
+
],
|
|
65
|
+
parameters: runProcessSchema,
|
|
66
|
+
async execute(_toolCallId, input, signal) {
|
|
67
|
+
if (!allowedExecutables.has(input.executable)) {
|
|
68
|
+
throw new Error(`process_executable_denied: '${input.executable}' is not owner-allowed.`);
|
|
69
|
+
}
|
|
70
|
+
const args = input.args ?? [];
|
|
71
|
+
if (input.executable.includes("\0") || args.some((argument) => argument.includes("\0"))) {
|
|
72
|
+
throw new Error("process_argument_invalid: executable and argv must not contain NUL bytes.");
|
|
73
|
+
}
|
|
74
|
+
const startedAt = Date.now();
|
|
75
|
+
const outputLimitAbort = new AbortController();
|
|
76
|
+
let outputLimitReached = false;
|
|
77
|
+
const child = (options.spawn ?? spawnProcess)(input.executable, [...args], {
|
|
78
|
+
cwd,
|
|
79
|
+
env: scopedEnvironment(options.policy.allowedEnvironmentVariables),
|
|
80
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
81
|
+
windowsHide: true,
|
|
82
|
+
});
|
|
83
|
+
const output = collectBoundedOutput(child, options.policy.maxOutputBytes, () => {
|
|
84
|
+
outputLimitReached = true;
|
|
85
|
+
outputLimitAbort.abort();
|
|
86
|
+
});
|
|
87
|
+
const combinedAbort = new AbortController();
|
|
88
|
+
const abort = () => combinedAbort.abort();
|
|
89
|
+
if (signal?.aborted || outputLimitAbort.signal.aborted)
|
|
90
|
+
abort();
|
|
91
|
+
else {
|
|
92
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
93
|
+
outputLimitAbort.signal.addEventListener("abort", abort, { once: true });
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const terminal = await waitForChildProcessWithTermination(child, {
|
|
97
|
+
signal: combinedAbort.signal,
|
|
98
|
+
timeoutMs: options.maxWallClockMs > 0 ? options.maxWallClockMs : undefined,
|
|
99
|
+
killGraceMs: 2_000,
|
|
100
|
+
});
|
|
101
|
+
const captured = output.read();
|
|
102
|
+
const outcome = outputLimitReached
|
|
103
|
+
? "output_limit"
|
|
104
|
+
: terminal.reason === "timeout"
|
|
105
|
+
? "timeout"
|
|
106
|
+
: terminal.reason === "aborted"
|
|
107
|
+
? "aborted"
|
|
108
|
+
: terminal.code === 0
|
|
109
|
+
? "exited"
|
|
110
|
+
: "failed";
|
|
111
|
+
const body = [
|
|
112
|
+
`outcome: ${outcome}`,
|
|
113
|
+
`exitCode: ${terminal.code ?? "null"}`,
|
|
114
|
+
captured.stdout ? `stdout:\n${captured.stdout}` : "stdout: (empty)",
|
|
115
|
+
captured.stderr ? `stderr:\n${captured.stderr}` : "stderr: (empty)",
|
|
116
|
+
].join("\n");
|
|
117
|
+
return {
|
|
118
|
+
content: [{ type: "text", text: body }],
|
|
119
|
+
details: {
|
|
120
|
+
outcome,
|
|
121
|
+
executable: input.executable,
|
|
122
|
+
exitCode: terminal.code,
|
|
123
|
+
durationMs: Date.now() - startedAt,
|
|
124
|
+
truncated: captured.truncated,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
signal?.removeEventListener("abort", abort);
|
|
130
|
+
outputLimitAbort.signal.removeEventListener("abort", abort);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function createRunProcessTool(cwd, options) {
|
|
136
|
+
return wrapToolDefinition(createRunProcessToolDefinition(cwd, options));
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=run-process.js.map
|