@caupulican/pi-adaptative 0.91.4 → 0.93.0

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.
Files changed (208) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/cli/args.d.ts +2 -0
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +24 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli.js +6 -1
  7. package/dist/cli.js.map +1 -1
  8. package/dist/core/agent-session-contracts.d.ts +1 -0
  9. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  10. package/dist/core/agent-session-contracts.js.map +1 -1
  11. package/dist/core/agent-session-services.d.ts +1 -0
  12. package/dist/core/agent-session-services.d.ts.map +1 -1
  13. package/dist/core/agent-session-services.js +1 -0
  14. package/dist/core/agent-session-services.js.map +1 -1
  15. package/dist/core/agent-session.d.ts +1 -6
  16. package/dist/core/agent-session.d.ts.map +1 -1
  17. package/dist/core/agent-session.js +15 -13
  18. package/dist/core/agent-session.js.map +1 -1
  19. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  20. package/dist/core/autonomy/lane-tool-surface.js +7 -1
  21. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  22. package/dist/core/background-lane-controller.d.ts +2 -4
  23. package/dist/core/background-lane-controller.d.ts.map +1 -1
  24. package/dist/core/background-lane-controller.js +0 -1
  25. package/dist/core/background-lane-controller.js.map +1 -1
  26. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  27. package/dist/core/bash-execution-controller.js +1 -0
  28. package/dist/core/bash-execution-controller.js.map +1 -1
  29. package/dist/core/bash-executor.d.ts +2 -0
  30. package/dist/core/bash-executor.d.ts.map +1 -1
  31. package/dist/core/bash-executor.js +13 -4
  32. package/dist/core/bash-executor.js.map +1 -1
  33. package/dist/core/compaction-controller.d.ts.map +1 -1
  34. package/dist/core/compaction-controller.js +2 -1
  35. package/dist/core/compaction-controller.js.map +1 -1
  36. package/dist/core/context/context-composition.d.ts +1 -1
  37. package/dist/core/context/context-composition.d.ts.map +1 -1
  38. package/dist/core/context/context-composition.js +1 -1
  39. package/dist/core/context/context-composition.js.map +1 -1
  40. package/dist/core/default-tool-surface.d.ts +0 -10
  41. package/dist/core/default-tool-surface.d.ts.map +1 -1
  42. package/dist/core/default-tool-surface.js +3 -1
  43. package/dist/core/default-tool-surface.js.map +1 -1
  44. package/dist/core/extensions/bundled-virtual-modules.js +8 -0
  45. package/dist/core/extensions/bundled-virtual-modules.js.map +1 -1
  46. package/dist/core/extensions/runner.d.ts +1 -1
  47. package/dist/core/extensions/runner.d.ts.map +1 -1
  48. package/dist/core/extensions/runner.js +1 -1
  49. package/dist/core/extensions/runner.js.map +1 -1
  50. package/dist/core/extensions/virtual-modules.d.ts +4 -0
  51. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  52. package/dist/core/extensions/virtual-modules.js +4 -0
  53. package/dist/core/extensions/virtual-modules.js.map +1 -1
  54. package/dist/core/goal-loop-controller.d.ts +6 -2
  55. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  56. package/dist/core/goal-loop-controller.js +15 -4
  57. package/dist/core/goal-loop-controller.js.map +1 -1
  58. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  59. package/dist/core/goals/compact-goal-context.js +10 -14
  60. package/dist/core/goals/compact-goal-context.js.map +1 -1
  61. package/dist/core/goals/goal-auto-continue-controller.d.ts +0 -2
  62. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
  63. package/dist/core/goals/goal-auto-continue-controller.js +0 -2
  64. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  65. package/dist/core/goals/goal-session-controller.d.ts +7 -7
  66. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  67. package/dist/core/goals/goal-session-controller.js +27 -5
  68. package/dist/core/goals/goal-session-controller.js.map +1 -1
  69. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  70. package/dist/core/goals/goal-tool-core.js +7 -0
  71. package/dist/core/goals/goal-tool-core.js.map +1 -1
  72. package/dist/core/goals/goal-tool-names.d.ts +7 -0
  73. package/dist/core/goals/goal-tool-names.d.ts.map +1 -0
  74. package/dist/core/goals/goal-tool-names.js +8 -0
  75. package/dist/core/goals/goal-tool-names.js.map +1 -0
  76. package/dist/core/model-capability.d.ts +1 -1
  77. package/dist/core/model-capability.d.ts.map +1 -1
  78. package/dist/core/model-capability.js +3 -1
  79. package/dist/core/model-capability.js.map +1 -1
  80. package/dist/core/models/perf-profile.d.ts +2 -1
  81. package/dist/core/models/perf-profile.d.ts.map +1 -1
  82. package/dist/core/models/perf-profile.js +1 -1
  83. package/dist/core/models/perf-profile.js.map +1 -1
  84. package/dist/core/provider-request-context-controller.d.ts.map +1 -1
  85. package/dist/core/provider-request-context-controller.js +6 -5
  86. package/dist/core/provider-request-context-controller.js.map +1 -1
  87. package/dist/core/provider-request-runtime-controller.d.ts.map +1 -1
  88. package/dist/core/provider-request-runtime-controller.js +3 -2
  89. package/dist/core/provider-request-runtime-controller.js.map +1 -1
  90. package/dist/core/runtime-builder.d.ts.map +1 -1
  91. package/dist/core/runtime-builder.js +13 -4
  92. package/dist/core/runtime-builder.js.map +1 -1
  93. package/dist/core/sdk.d.ts +3 -1
  94. package/dist/core/sdk.d.ts.map +1 -1
  95. package/dist/core/sdk.js +3 -1
  96. package/dist/core/sdk.js.map +1 -1
  97. package/dist/core/session-analytics.d.ts +2 -2
  98. package/dist/core/session-analytics.d.ts.map +1 -1
  99. package/dist/core/session-analytics.js +3 -2
  100. package/dist/core/session-analytics.js.map +1 -1
  101. package/dist/core/session-manager-factory.d.ts +1 -1
  102. package/dist/core/session-manager-factory.d.ts.map +1 -1
  103. package/dist/core/session-manager-factory.js +1 -1
  104. package/dist/core/session-manager-factory.js.map +1 -1
  105. package/dist/core/session-role.d.ts.map +1 -1
  106. package/dist/core/session-role.js +2 -0
  107. package/dist/core/session-role.js.map +1 -1
  108. package/dist/core/session-tree-navigator.d.ts +2 -2
  109. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  110. package/dist/core/session-tree-navigator.js +1 -1
  111. package/dist/core/session-tree-navigator.js.map +1 -1
  112. package/dist/core/skill-vault.d.ts +6 -7
  113. package/dist/core/skill-vault.d.ts.map +1 -1
  114. package/dist/core/skill-vault.js +12 -12
  115. package/dist/core/skill-vault.js.map +1 -1
  116. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  117. package/dist/core/tool-capability-policy.js +2 -1
  118. package/dist/core/tool-capability-policy.js.map +1 -1
  119. package/dist/core/tools/bash.d.ts +2 -0
  120. package/dist/core/tools/bash.d.ts.map +1 -1
  121. package/dist/core/tools/bash.js +27 -12
  122. package/dist/core/tools/bash.js.map +1 -1
  123. package/dist/core/tools/early-powershell-session.d.ts +21 -0
  124. package/dist/core/tools/early-powershell-session.d.ts.map +1 -0
  125. package/dist/core/tools/early-powershell-session.js +137 -0
  126. package/dist/core/tools/early-powershell-session.js.map +1 -0
  127. package/dist/core/tools/edit.d.ts +1 -1
  128. package/dist/core/tools/edit.d.ts.map +1 -1
  129. package/dist/core/tools/edit.js +1 -1
  130. package/dist/core/tools/edit.js.map +1 -1
  131. package/dist/core/tools/file-failure-recovery.d.ts +1 -1
  132. package/dist/core/tools/file-failure-recovery.d.ts.map +1 -1
  133. package/dist/core/tools/file-failure-recovery.js +1 -1
  134. package/dist/core/tools/file-failure-recovery.js.map +1 -1
  135. package/dist/core/tools/goal.d.ts +9 -2
  136. package/dist/core/tools/goal.d.ts.map +1 -1
  137. package/dist/core/tools/goal.js +64 -1
  138. package/dist/core/tools/goal.js.map +1 -1
  139. package/dist/core/tools/grep.d.ts +2 -2
  140. package/dist/core/tools/grep.d.ts.map +1 -1
  141. package/dist/core/tools/grep.js +1 -1
  142. package/dist/core/tools/grep.js.map +1 -1
  143. package/dist/core/tools/output-accumulator.d.ts +2 -0
  144. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  145. package/dist/core/tools/output-accumulator.js +2 -1
  146. package/dist/core/tools/output-accumulator.js.map +1 -1
  147. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -1
  148. package/dist/core/tools/persistent-process-coordinator.js +2 -11
  149. package/dist/core/tools/persistent-process-coordinator.js.map +1 -1
  150. package/dist/core/tools/read.d.ts +2 -2
  151. package/dist/core/tools/read.d.ts.map +1 -1
  152. package/dist/core/tools/read.js +1 -1
  153. package/dist/core/tools/read.js.map +1 -1
  154. package/dist/core/tools/render-utils.d.ts +1 -0
  155. package/dist/core/tools/render-utils.d.ts.map +1 -1
  156. package/dist/core/tools/render-utils.js +11 -9
  157. package/dist/core/tools/render-utils.js.map +1 -1
  158. package/dist/core/tools/shell-output-decoder.d.ts +7 -0
  159. package/dist/core/tools/shell-output-decoder.d.ts.map +1 -0
  160. package/dist/core/tools/shell-output-decoder.js +135 -0
  161. package/dist/core/tools/shell-output-decoder.js.map +1 -0
  162. package/dist/core/tools/shell-session.d.ts +23 -6
  163. package/dist/core/tools/shell-session.d.ts.map +1 -1
  164. package/dist/core/tools/shell-session.js +275 -88
  165. package/dist/core/tools/shell-session.js.map +1 -1
  166. package/dist/core/tools/skill.js +2 -2
  167. package/dist/core/tools/skill.js.map +1 -1
  168. package/dist/core/tools/write.d.ts +1 -1
  169. package/dist/core/tools/write.d.ts.map +1 -1
  170. package/dist/core/tools/write.js +1 -1
  171. package/dist/core/tools/write.js.map +1 -1
  172. package/dist/index.d.ts +1 -1
  173. package/dist/index.d.ts.map +1 -1
  174. package/dist/index.js +1 -1
  175. package/dist/index.js.map +1 -1
  176. package/dist/main.d.ts.map +1 -1
  177. package/dist/main.js +2 -0
  178. package/dist/main.js.map +1 -1
  179. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  180. package/dist/modes/interactive/components/bash-execution.js +4 -33
  181. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  182. package/dist/modes/interactive/components/tool-execution.d.ts +3 -0
  183. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  184. package/dist/modes/interactive/components/tool-execution.js +63 -27
  185. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  186. package/dist/utils/child-process-ref.d.ts +4 -0
  187. package/dist/utils/child-process-ref.d.ts.map +1 -0
  188. package/dist/utils/child-process-ref.js +15 -0
  189. package/dist/utils/child-process-ref.js.map +1 -0
  190. package/dist/utils/powershell-session-protocol.d.ts +16 -0
  191. package/dist/utils/powershell-session-protocol.d.ts.map +1 -0
  192. package/dist/utils/powershell-session-protocol.js +63 -0
  193. package/dist/utils/powershell-session-protocol.js.map +1 -0
  194. package/dist/utils/shell.d.ts +7 -4
  195. package/dist/utils/shell.d.ts.map +1 -1
  196. package/dist/utils/shell.js +38 -23
  197. package/dist/utils/shell.js.map +1 -1
  198. package/docs/settings.md +2 -2
  199. package/docs/windows.md +9 -8
  200. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  201. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  202. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  203. package/examples/extensions/sandbox/package-lock.json +2 -2
  204. package/examples/extensions/sandbox/package.json +2 -2
  205. package/examples/extensions/with-deps/package-lock.json +2 -2
  206. package/examples/extensions/with-deps/package.json +1 -1
  207. package/npm-shrinkwrap.json +318 -332
  208. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EAEjB,qBAAqB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,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,CAAC;YACtE,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype TruncationResult,\n\ttruncateKnownHeadTail,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate headLines: string[] = [];\n\tprivate headStoredBytes = 0;\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean; persistAlways?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildModelSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistAlways || (options.persistIfTruncated && snapshot.truncation.truncated)) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tprivate withPersistenceState(snapshot: OutputSnapshot): OutputSnapshot {\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.recordHeadLine(this.currentLineText, this.currentLineStoredBytes);\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate recordHeadLine(text: string, storedBytes: number): void {\n\t\tif (this.headLines.length >= this.maxLines) return;\n\t\tconst separatorBytes = this.headLines.length > 0 ? 1 : 0;\n\t\tif (this.headStoredBytes + storedBytes + separatorBytes > this.maxBytes) return;\n\t\tthis.headLines.push(text);\n\t\tthis.headStoredBytes += storedBytes + separatorBytes;\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate retainedTailLines(): string[] {\n\t\tconst lines = this.tailLines.slice(this.tailStart);\n\t\tif (this.hasOpenLine) lines.push(this.currentLineText);\n\t\treturn lines;\n\t}\n\n\tprivate buildModelSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst tailSnapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (!tailSnapshot.truncation.truncated || this.headLines.length === 0) {\n\t\t\treturn tailSnapshot;\n\t\t}\n\n\t\tconst truncation = truncateKnownHeadTail(\n\t\t\tthis.headLines,\n\t\t\tthis.retainedTailLines(),\n\t\t\t{ totalLines: this.totalLines, totalBytes: this.totalDecodedBytes },\n\t\t\t{ maxLines, maxBytes },\n\t\t);\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EAEjB,qBAAqB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAA2B,MAAM,2BAA2B,CAAC;AA6B9F,SAAS,mBAAmB,C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F,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype TruncationResult,\n\ttruncateKnownHeadTail,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport { createShellOutputDecoder, type ShellOutputDecoder } from \"./shell-output-decoder.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n\t/** Decode valid UTF-8 plus isolated Windows-1252 bytes from native Windows programs. */\n\twindowsCompatibleEncoding?: boolean;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder: ShellOutputDecoder;\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate headLines: string[] = [];\n\tprivate headStoredBytes = 0;\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t\tthis.decoder = createShellOutputDecoder(options.windowsCompatibleEncoding);\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean; persistAlways?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildModelSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistAlways || (options.persistIfTruncated && snapshot.truncation.truncated)) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tprivate withPersistenceState(snapshot: OutputSnapshot): OutputSnapshot {\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.recordHeadLine(this.currentLineText, this.currentLineStoredBytes);\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate recordHeadLine(text: string, storedBytes: number): void {\n\t\tif (this.headLines.length >= this.maxLines) return;\n\t\tconst separatorBytes = this.headLines.length > 0 ? 1 : 0;\n\t\tif (this.headStoredBytes + storedBytes + separatorBytes > this.maxBytes) return;\n\t\tthis.headLines.push(text);\n\t\tthis.headStoredBytes += storedBytes + separatorBytes;\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate retainedTailLines(): string[] {\n\t\tconst lines = this.tailLines.slice(this.tailStart);\n\t\tif (this.hasOpenLine) lines.push(this.currentLineText);\n\t\treturn lines;\n\t}\n\n\tprivate buildModelSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst tailSnapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (!tailSnapshot.truncation.truncated || this.headLines.length === 0) {\n\t\t\treturn tailSnapshot;\n\t\t}\n\n\t\tconst truncation = truncateKnownHeadTail(\n\t\t\tthis.headLines,\n\t\t\tthis.retainedTailLines(),\n\t\t\t{ totalLines: this.totalLines, totalBytes: this.totalDecodedBytes },\n\t\t\t{ maxLines, maxBytes },\n\t\t);\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"persistent-process-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACnC;AAaD,qBAAa,4BAA4B;IACxC,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,cAGC;IAED,IAAI,KAAK,IAAI,YAAY,GAAG,IAAI,CAE/B;IAED,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOnD;IAED,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAiCnE;IAED,IAAI,IAAI,IAAI,CAKX;IAED,OAAO,IAAI,IAAI,CAKd;IAED,mEAAmE;IACnE,kBAAkB,IAAI,IAAI,CAEzB;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAchC;IAED,OAAO,CAAC,KAAK;CAMb"}
1
+ {"version":3,"file":"persistent-process-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACnC;AAaD,qBAAa,4BAA4B;IACxC,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,cAGC;IAED,IAAI,KAAK,IAAI,YAAY,GAAG,IAAI,CAE/B;IAED,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOnD;IAED,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAiCnE;IAED,IAAI,IAAI,IAAI,CAKX;IAED,OAAO,IAAI,IAAI,CAKd;IAED,mEAAmE;IACnE,kBAAkB,IAAI,IAAI,CAEzB;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAIhC;IAED,OAAO,CAAC,KAAK;CAMb"}
@@ -5,6 +5,7 @@
5
5
  * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale
6
6
  * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.
7
7
  */
8
+ import { setChildProcessLoopRef } from "../../utils/child-process-ref.js";
8
9
  import { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from "../../utils/shell.js";
9
10
  const liveCoordinators = new Set();
10
11
  let exitHookInstalled = false;
@@ -99,17 +100,7 @@ export class PersistentProcessCoordinator {
99
100
  const child = this.currentChild;
100
101
  if (!child)
101
102
  return;
102
- const streams = [child.stdin, child.stdout, child.stderr];
103
- if (active) {
104
- child.ref();
105
- for (const stream of streams)
106
- stream?.ref?.();
107
- }
108
- else {
109
- child.unref();
110
- for (const stream of streams)
111
- stream?.unref?.();
112
- }
103
+ setChildProcessLoopRef(child, active);
113
104
  }
114
105
  clear(child) {
115
106
  if (this.currentChild !== child)
@@ -1 +1 @@
1
- {"version":3,"file":"persistent-process-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AASvG,MAAM,gBAAgB,GAAG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KAAK;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,GAAG;YAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/**\n * Shared lifecycle owner for one serialized, persistent child process.\n *\n * Wire protocols, state projection, and respawn policy stay with their concrete shell adapters.\n * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale\n * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.\n */\n\nimport type { ChildProcess } from \"node:child_process\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\n\nexport interface PersistentChildHandlers {\n\tonStdout(data: Buffer): void;\n\tonStderr(data: Buffer): void;\n\tonError(error: Error): void;\n\tonClose(code: number | null): void;\n}\n\nconst liveCoordinators = new Set<PersistentProcessCoordinator>();\nlet exitHookInstalled = false;\n\nfunction installExitHook(): void {\n\tif (exitHookInstalled) return;\n\texitHookInstalled = true;\n\tprocess.on(\"exit\", () => {\n\t\tfor (const coordinator of liveCoordinators) coordinator.killForProcessExit();\n\t});\n}\n\nexport class PersistentProcessCoordinator {\n\tprivate currentChild: ChildProcess | null = null;\n\tprivate queue: Promise<void> = Promise.resolve();\n\tprivate disposed = false;\n\n\tconstructor() {\n\t\tinstallExitHook();\n\t\tliveCoordinators.add(this);\n\t}\n\n\tget child(): ChildProcess | null {\n\t\treturn this.currentChild;\n\t}\n\n\trunSerialized<T>(task: () => Promise<T>): Promise<T> {\n\t\tconst run = this.queue.then(task);\n\t\tthis.queue = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\tattach(child: ChildProcess, handlers: PersistentChildHandlers): void {\n\t\tif (this.disposed) {\n\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\tthrow new Error(\"Persistent process coordinator is disposed\");\n\t\t}\n\t\tif (this.currentChild) throw new Error(\"Persistent process coordinator already owns a child\");\n\t\tthis.currentChild = child;\n\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\t\tchild.stdout?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStdout(data);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStderr(data);\n\t\t});\n\t\tchild.on(\"error\", (error) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onError(error instanceof Error ? error : new Error(String(error)));\n\t\t});\n\t\t// Process death is authoritative. Defer one check phase so stream data already delivered\n\t\t// by the kernel reaches the active protocol handler before the terminal callback.\n\t\tchild.on(\"exit\", (code) => {\n\t\t\tif (this.currentChild !== child) return;\n\t\t\tsetImmediate(() => {\n\t\t\t\tif (!this.clear(child)) return;\n\t\t\t\thandlers.onClose(code);\n\t\t\t});\n\t\t});\n\t\t// A genuine close may arrive first; `clear` makes exit/close settlement idempotent.\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onClose(code);\n\t\t});\n\t}\n\n\tkill(): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tthis.clear(child);\n\t\tif (child.pid) killProcessTree(child.pid);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tliveCoordinators.delete(this);\n\t\tthis.kill();\n\t}\n\n\t/** Synchronous best-effort tree kill for the process exit hook. */\n\tkillForProcessExit(): void {\n\t\tthis.kill();\n\t}\n\n\t/** Idle coordinators must not keep one-shot Node modes alive; active commands must. */\n\tsetLoopRef(active: boolean): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tconst streams = [child.stdin, child.stdout, child.stderr] as unknown as Array<{\n\t\t\tref?: () => void;\n\t\t\tunref?: () => void;\n\t\t} | null>;\n\t\tif (active) {\n\t\t\tchild.ref();\n\t\t\tfor (const stream of streams) stream?.ref?.();\n\t\t} else {\n\t\t\tchild.unref();\n\t\t\tfor (const stream of streams) stream?.unref?.();\n\t\t}\n\t}\n\n\tprivate clear(child: ChildProcess): boolean {\n\t\tif (this.currentChild !== child) return false;\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tthis.currentChild = null;\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"persistent-process-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AASvG,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAgC,CAAC;AACjE,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,SAAS,eAAe;IACvB,IAAI,iBAAiB;QAAE,OAAO;IAC9B,iBAAiB,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACvB,KAAK,MAAM,WAAW,IAAI,gBAAgB;YAAE,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC9E,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,4BAA4B;IAKxC;QAJQ,iBAAY,GAAwB,IAAI,CAAC;QACzC,UAAK,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;QACzC,aAAQ,GAAG,KAAK,CAAC;QAGxB,eAAe,EAAE,CAAC;QAClB,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED,aAAa,CAAI,IAAsB;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;Q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C,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAEO,KAAK,CAAC,KAAmB;QAChC,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,GAAG;YAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/**\n * Shared lifecycle owner for one serialized, persistent child process.\n *\n * Wire protocols, state projection, and respawn policy stay with their concrete shell adapters.\n * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale\n * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.\n */\n\nimport type { ChildProcess } from \"node:child_process\";\nimport { setChildProcessLoopRef } from \"../../utils/child-process-ref.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\n\nexport interface PersistentChildHandlers {\n\tonStdout(data: Buffer): void;\n\tonStderr(data: Buffer): void;\n\tonError(error: Error): void;\n\tonClose(code: number | null): void;\n}\n\nconst liveCoordinators = new Set<PersistentProcessCoordinator>();\nlet exitHookInstalled = false;\n\nfunction installExitHook(): void {\n\tif (exitHookInstalled) return;\n\texitHookInstalled = true;\n\tprocess.on(\"exit\", () => {\n\t\tfor (const coordinator of liveCoordinators) coordinator.killForProcessExit();\n\t});\n}\n\nexport class PersistentProcessCoordinator {\n\tprivate currentChild: ChildProcess | null = null;\n\tprivate queue: Promise<void> = Promise.resolve();\n\tprivate disposed = false;\n\n\tconstructor() {\n\t\tinstallExitHook();\n\t\tliveCoordinators.add(this);\n\t}\n\n\tget child(): ChildProcess | null {\n\t\treturn this.currentChild;\n\t}\n\n\trunSerialized<T>(task: () => Promise<T>): Promise<T> {\n\t\tconst run = this.queue.then(task);\n\t\tthis.queue = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\tattach(child: ChildProcess, handlers: PersistentChildHandlers): void {\n\t\tif (this.disposed) {\n\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\tthrow new Error(\"Persistent process coordinator is disposed\");\n\t\t}\n\t\tif (this.currentChild) throw new Error(\"Persistent process coordinator already owns a child\");\n\t\tthis.currentChild = child;\n\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\t\tchild.stdout?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStdout(data);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStderr(data);\n\t\t});\n\t\tchild.on(\"error\", (error) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onError(error instanceof Error ? error : new Error(String(error)));\n\t\t});\n\t\t// Process death is authoritative. Defer one check phase so stream data already delivered\n\t\t// by the kernel reaches the active protocol handler before the terminal callback.\n\t\tchild.on(\"exit\", (code) => {\n\t\t\tif (this.currentChild !== child) return;\n\t\t\tsetImmediate(() => {\n\t\t\t\tif (!this.clear(child)) return;\n\t\t\t\thandlers.onClose(code);\n\t\t\t});\n\t\t});\n\t\t// A genuine close may arrive first; `clear` makes exit/close settlement idempotent.\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onClose(code);\n\t\t});\n\t}\n\n\tkill(): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tthis.clear(child);\n\t\tif (child.pid) killProcessTree(child.pid);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tliveCoordinators.delete(this);\n\t\tthis.kill();\n\t}\n\n\t/** Synchronous best-effort tree kill for the process exit hook. */\n\tkillForProcessExit(): void {\n\t\tthis.kill();\n\t}\n\n\t/** Idle coordinators must not keep one-shot Node modes alive; active commands must. */\n\tsetLoopRef(active: boolean): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tsetChildProcessLoopRef(child, active);\n\t}\n\n\tprivate clear(child: ChildProcess): boolean {\n\t\tif (this.currentChild !== child) return false;\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tthis.currentChild = null;\n\t\treturn true;\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { AgentTool } from "@caupulican/pi-agent-core";
2
- import { type TruncationResult } from "@caupulican/pi-agent-core/node";
1
+ import { type TruncationResult } from "@caupulican/pi-agent-core/truncate";
2
+ import type { AgentTool } from "@caupulican/pi-agent-core/types";
3
3
  import { type Static, Type } from "typebox";
4
4
  import type { ToolDefinition } from "../extensions/types.ts";
5
5
  import { type FileFailureRecoveryAuthority } from "./file-failure-recovery.ts";
@@ -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;AAMxC,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAQ5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAGN,KAAK,4BAA4B,EAGjC,MAAM,4BAA4B,CAAC;AAMpC,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;IACpD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Absolute, join, relative, resolve as resolvePath, sep } from "node:path";
2
2
  import { StringDecoder } from "node:string_decoder";
3
- import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, } from "@caupulican/pi-agent-core/node";
3
+ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, } from "@caupulican/pi-agent-core/truncate";
4
4
  import { StreamingLineDecoder } from "@caupulican/pi-ai/streaming-lines";
5
5
  import { Text } from "@caupulican/pi-tui";
6
6
  import { constants } from "fs";
@@ -1 +1 @@
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;AAExC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,IAAI,IAAI,MAAM,EAAE,QAAQ,IAAI,UAAU,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,wCAAwC,CAAC;AACxG,OAAO,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C3C,CAAC;YACF,OAAO,IAAI,CAAC;QACb,CAAC;QACD,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO;YAC3C,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CACX,gBAAgB,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;QACb,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","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 { StreamingLineDecoder } from \"@caupulican/pi-ai/streaming-lines\";\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 {\n\tFILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,\n\tFILE_EXISTS_RECOVERY_TARGET_KIND,\n\ttype FileFailureRecoveryAuthority,\n\tfileRecoveryTarget,\n\tselectFileFailureRecoveryAuthority,\n} from \"./file-failure-recovery.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { isPiSessionJsonlPath, projectPiSessionJsonlLine } from \"./session-transcript-read.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 byteDecoder = new StringDecoder(\"utf8\");\n\t\tconst lineDecoder = new StreamingLineDecoder(Number.MAX_SAFE_INTEGER, { lineEndings: \"lf\" });\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\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\tconst lines = lineDecoder.push(byteDecoder.write(buffer.subarray(0, bytesRead)));\n\t\t\tfor (const line of lines) {\n\t\t\t\temittedAnyLine = true;\n\t\t\t\tif (!onLine(line, index++)) return;\n\t\t\t}\n\t\t}\n\t\tfor (const line of lineDecoder.push(byteDecoder.end())) {\n\t\t\temittedAnyLine = true;\n\t\t\tif (!onLine(line, index++)) return;\n\t\t}\n\t\tconst finalLine = lineDecoder.finish();\n\t\tif (finalLine !== undefined || !emittedAnyLine) {\n\t\t\tonLine(finalLine ?? \"\", 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/** Shared backend identity for exact cross-tool recovery with custom operations. */\n\tfailureRecoveryAuthority?: FileFailureRecoveryAuthority;\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 failureRecoveryAuthority = selectFileFailureRecoveryAuthority(\n\t\toptions?.operations !== undefined,\n\t\toptions?.failureRecoveryAuthority,\n\t);\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\tconst configuredSessionDirectory = join(getAgentDir(), \"sessions\");\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\tfailureRecovery: {\n\t\t\tgetFailureTargets: (params, failure) =>\n\t\t\t\tfailure.failureCode === \"file_not_found\" && failureRecoveryAuthority\n\t\t\t\t\t? [fileRecoveryTarget(failureRecoveryAuthority, FILE_EXISTS_RECOVERY_TARGET_KIND, params.path, cwd)]\n\t\t\t\t\t: [],\n\t\t\tactions: failureRecoveryAuthority\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkind: \"correct\",\n\t\t\t\t\t\t\tauthority: failureRecoveryAuthority.contractAuthority,\n\t\t\t\t\t\t\ttargetKind: FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,\n\t\t\t\t\t\t\tinstruction:\n\t\t\t\t\t\t\t\t\"Use read on the failed edit path to obtain current text, then submit a changed edit with exact current text.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t},\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 projectSessionTranscript = isPiSessionJsonlPath(absolutePath, configuredSessionDirectory);\n\t\t\t\t\t\t\t\tif (projectSessionTranscript) {\n\t\t\t\t\t\t\t\t\tslicedLines = slicedLines.map((item) => ({\n\t\t\t\t\t\t\t\t\t\ttext: projectPiSessionJsonlLine(item.text),\n\t\t\t\t\t\t\t\t\t\toriginalIndex: item.originalIndex,\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\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 = !projectSessionTranscript;\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\tif (projectSessionTranscript) {\n\t\t\t\t\t\t\t\t\toutputText = `Pi session transcript (user/assistant/summary/tool labels only; thinking and payloads omitted).\\n${outputText}`;\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"]}
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;AACpD,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAEV,YAAY,GACZ,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,IAAI,IAAI,MAAM,EAAE,QAAQ,IAAI,UAAU,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,wCAAwC,CAAC;AACxG,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EA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EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CACX,gBAAgB,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;QACb,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core/types\";\nimport type { Api, ImageContent, Model, TextContent } from \"@caupulican/pi-ai\";\nimport { StreamingLineDecoder } from \"@caupulican/pi-ai/streaming-lines\";\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 {\n\tFILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,\n\tFILE_EXISTS_RECOVERY_TARGET_KIND,\n\ttype FileFailureRecoveryAuthority,\n\tfileRecoveryTarget,\n\tselectFileFailureRecoveryAuthority,\n} from \"./file-failure-recovery.ts\";\nimport { resolveReadPathAsync, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, replaceTabs, str } from \"./render-utils.ts\";\nimport { isPiSessionJsonlPath, projectPiSessionJsonlLine } from \"./session-transcript-read.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 byteDecoder = new StringDecoder(\"utf8\");\n\t\tconst lineDecoder = new StreamingLineDecoder(Number.MAX_SAFE_INTEGER, { lineEndings: \"lf\" });\n\t\tconst buffer = Buffer.allocUnsafe(SLICE_SCAN_CHUNK_BYTES);\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\tconst lines = lineDecoder.push(byteDecoder.write(buffer.subarray(0, bytesRead)));\n\t\t\tfor (const line of lines) {\n\t\t\t\temittedAnyLine = true;\n\t\t\t\tif (!onLine(line, index++)) return;\n\t\t\t}\n\t\t}\n\t\tfor (const line of lineDecoder.push(byteDecoder.end())) {\n\t\t\temittedAnyLine = true;\n\t\t\tif (!onLine(line, index++)) return;\n\t\t}\n\t\tconst finalLine = lineDecoder.finish();\n\t\tif (finalLine !== undefined || !emittedAnyLine) {\n\t\t\tonLine(finalLine ?? \"\", 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/** Shared backend identity for exact cross-tool recovery with custom operations. */\n\tfailureRecoveryAuthority?: FileFailureRecoveryAuthority;\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 failureRecoveryAuthority = selectFileFailureRecoveryAuthority(\n\t\toptions?.operations !== undefined,\n\t\toptions?.failureRecoveryAuthority,\n\t);\n\tconst maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;\n\tconst maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;\n\tconst configuredSessionDirectory = join(getAgentDir(), \"sessions\");\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\tfailureRecovery: {\n\t\t\tgetFailureTargets: (params, failure) =>\n\t\t\t\tfailure.failureCode === \"file_not_found\" && failureRecoveryAuthority\n\t\t\t\t\t? [fileRecoveryTarget(failureRecoveryAuthority, FILE_EXISTS_RECOVERY_TARGET_KIND, params.path, cwd)]\n\t\t\t\t\t: [],\n\t\t\tactions: failureRecoveryAuthority\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkind: \"correct\",\n\t\t\t\t\t\t\tauthority: failureRecoveryAuthority.contractAuthority,\n\t\t\t\t\t\t\ttargetKind: FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,\n\t\t\t\t\t\t\tinstruction:\n\t\t\t\t\t\t\t\t\"Use read on the failed edit path to obtain current text, then submit a changed edit with exact current text.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t},\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 projectSessionTranscript = isPiSessionJsonlPath(absolutePath, configuredSessionDirectory);\n\t\t\t\t\t\t\t\tif (projectSessionTranscript) {\n\t\t\t\t\t\t\t\t\tslicedLines = slicedLines.map((item) => ({\n\t\t\t\t\t\t\t\t\t\ttext: projectPiSessionJsonlLine(item.text),\n\t\t\t\t\t\t\t\t\t\toriginalIndex: item.originalIndex,\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\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 = !projectSessionTranscript;\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\tif (projectSessionTranscript) {\n\t\t\t\t\t\t\t\t\toutputText = `Pi session transcript (user/assistant/summary/tool labels only; thinking and payloads omitted).\\n${outputText}`;\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"]}
@@ -15,6 +15,7 @@ export declare function getTextOutput(result: {
15
15
  mimeType?: string;
16
16
  }>;
17
17
  } | undefined, showImages: boolean): string;
18
+ export declare function formatCollapsedToolOutputHint(currentTheme: Theme): string;
18
19
  export type ToolRenderResultLike<TDetails> = {
19
20
  content: (TextContent | ImageContent)[];
20
21
  details: TDetails;
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAiE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAEzG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAGpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAetE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAsB/D;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjF;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,SAAS,EACzG,UAAU,EAAE,OAAO,GACjB,MAAM,CAsBR;AAED,MAAM,MAAM,oBAAoB,CA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"}
@@ -77,20 +77,22 @@ export function getTextOutput(result, showImages) {
77
77
  }
78
78
  return output;
79
79
  }
80
+ export function formatCollapsedToolOutputHint(currentTheme) {
81
+ return `\n${currentTheme.fg("muted", "...")} ${keyHint("app.tools.expand", "to expand")}`;
82
+ }
80
83
  export function formatCollapsibleToolResult(args) {
81
84
  const output = getTextOutput(args.result, args.showImages).trim();
85
+ const warnings = args.warnings(args.result.details);
86
+ if (!args.options.expanded) {
87
+ return output || warnings.length > 0 ? formatCollapsedToolOutputHint(args.theme) : "";
88
+ }
82
89
  let text = "";
83
90
  if (output) {
84
- const lines = output.split("\n");
85
- const maxLines = args.options.expanded ? lines.length : args.collapsedLineLimit;
86
- const displayLines = lines.slice(0, maxLines);
87
- const remaining = lines.length - maxLines;
88
- text += `\n${displayLines.map((line) => args.theme.fg("toolOutput", line)).join("\n")}`;
89
- if (remaining > 0) {
90
- text += `${args.theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
91
- }
91
+ text += `\n${output
92
+ .split("\n")
93
+ .map((line) => args.theme.fg("toolOutput", line))
94
+ .join("\n")}`;
92
95
  }
93
- const warnings = args.warnings(args.result.details);
94
96
  if (warnings.length > 0)
95
97
  text += `\n${args.theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
96
98
  return text;