@bastani/atomic 0.8.4 → 0.8.5-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 (245) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +24 -23
  3. package/dist/builtin/intercom/README.md +5 -5
  4. package/dist/builtin/intercom/index.ts +1 -1
  5. package/dist/builtin/intercom/package.json +1 -1
  6. package/dist/builtin/intercom/ui/compose.ts +19 -1
  7. package/dist/builtin/intercom/ui/session-list.ts +19 -1
  8. package/dist/builtin/mcp/README.md +3 -3
  9. package/dist/builtin/mcp/commands.ts +1 -1
  10. package/dist/builtin/mcp/host-html-template.ts +1 -1
  11. package/dist/builtin/mcp/mcp-panel.ts +14 -14
  12. package/dist/builtin/mcp/mcp-setup-panel.ts +4 -4
  13. package/dist/builtin/mcp/package.json +1 -1
  14. package/dist/builtin/mcp/tool-result-renderer.ts +1 -1
  15. package/dist/builtin/subagents/README.md +3 -3
  16. package/dist/builtin/subagents/package.json +1 -1
  17. package/dist/builtin/subagents/src/tui/render.ts +1844 -1062
  18. package/dist/builtin/web-access/README.md +1 -1
  19. package/dist/builtin/web-access/curator-page.ts +2 -2
  20. package/dist/builtin/web-access/index.ts +1 -1
  21. package/dist/builtin/web-access/package.json +1 -1
  22. package/dist/builtin/workflows/README.md +34 -7
  23. package/dist/builtin/workflows/builtin/deep-research-codebase.ts +23 -4
  24. package/dist/builtin/workflows/builtin/ralph.ts +1 -1
  25. package/dist/builtin/workflows/package.json +1 -1
  26. package/dist/builtin/workflows/skills/workflow/SKILL.md +75 -16
  27. package/dist/builtin/workflows/skills/workflow/references/running-workflows.md +34 -11
  28. package/dist/builtin/workflows/skills/workflow/references/sdk-authoring.md +111 -20
  29. package/dist/builtin/workflows/src/extension/discovery.ts +32 -4
  30. package/dist/builtin/workflows/src/extension/index.ts +347 -63
  31. package/dist/builtin/workflows/src/extension/render-call.ts +3 -1
  32. package/dist/builtin/workflows/src/extension/render-result.ts +7 -0
  33. package/dist/builtin/workflows/src/extension/runtime.ts +4 -2
  34. package/dist/builtin/workflows/src/extension/wiring.ts +32 -8
  35. package/dist/builtin/workflows/src/extension/workflow-schema.ts +36 -14
  36. package/dist/builtin/workflows/src/runs/background/runner.ts +2 -2
  37. package/dist/builtin/workflows/src/runs/background/status.ts +89 -0
  38. package/dist/builtin/workflows/src/runs/foreground/executor.ts +338 -78
  39. package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +2 -0
  40. package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +55 -7
  41. package/dist/builtin/workflows/src/runs/shared/workflow-runner.ts +146 -10
  42. package/dist/builtin/workflows/src/shared/store.ts +29 -0
  43. package/dist/builtin/workflows/src/shared/types.ts +25 -4
  44. package/dist/builtin/workflows/src/tui/graph-canvas.ts +69 -2
  45. package/dist/builtin/workflows/src/tui/graph-view.ts +97 -182
  46. package/dist/builtin/workflows/src/tui/header.ts +36 -20
  47. package/dist/builtin/workflows/src/tui/inline-form-card.ts +129 -46
  48. package/dist/builtin/workflows/src/tui/inline-form-editor.ts +111 -36
  49. package/dist/builtin/workflows/src/tui/inputs-picker.ts +311 -91
  50. package/dist/builtin/workflows/src/tui/layout.ts +1 -1
  51. package/dist/builtin/workflows/src/tui/node-card.ts +66 -37
  52. package/dist/builtin/workflows/src/tui/overlay-adapter.ts +20 -6
  53. package/dist/builtin/workflows/src/tui/prompt-card.ts +262 -85
  54. package/dist/builtin/workflows/src/tui/run-detail.ts +50 -31
  55. package/dist/builtin/workflows/src/tui/session-confirm.ts +21 -14
  56. package/dist/builtin/workflows/src/tui/session-picker.ts +35 -26
  57. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +531 -960
  58. package/dist/builtin/workflows/src/tui/status-helpers.ts +6 -0
  59. package/dist/builtin/workflows/src/tui/status-list.ts +8 -4
  60. package/dist/builtin/workflows/src/tui/store-widget-installer.ts +7 -2
  61. package/dist/builtin/workflows/src/tui/switcher.ts +55 -25
  62. package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +33 -1
  63. package/dist/builtin/workflows/src/tui/workflow-list.ts +10 -6
  64. package/dist/cli/args.d.ts.map +1 -1
  65. package/dist/cli/args.js +1 -1
  66. package/dist/cli/args.js.map +1 -1
  67. package/dist/config.d.ts.map +1 -1
  68. package/dist/config.js +20 -6
  69. package/dist/config.js.map +1 -1
  70. package/dist/core/agent-session-services.d.ts +3 -3
  71. package/dist/core/agent-session-services.d.ts.map +1 -1
  72. package/dist/core/agent-session-services.js.map +1 -1
  73. package/dist/core/agent-session.d.ts +7 -7
  74. package/dist/core/agent-session.d.ts.map +1 -1
  75. package/dist/core/agent-session.js.map +1 -1
  76. package/dist/core/compaction/branch-summarization.d.ts +2 -2
  77. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  78. package/dist/core/compaction/branch-summarization.js.map +1 -1
  79. package/dist/core/compaction/compaction.d.ts +3 -3
  80. package/dist/core/compaction/compaction.d.ts.map +1 -1
  81. package/dist/core/compaction/compaction.js.map +1 -1
  82. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  83. package/dist/core/export-html/tool-renderer.js.map +1 -1
  84. package/dist/core/extensions/loader.d.ts +3 -2
  85. package/dist/core/extensions/loader.d.ts.map +1 -1
  86. package/dist/core/extensions/loader.js +24 -12
  87. package/dist/core/extensions/loader.js.map +1 -1
  88. package/dist/core/extensions/runner.d.ts.map +1 -1
  89. package/dist/core/extensions/runner.js +6 -0
  90. package/dist/core/extensions/runner.js.map +1 -1
  91. package/dist/core/extensions/types.d.ts +28 -17
  92. package/dist/core/extensions/types.d.ts.map +1 -1
  93. package/dist/core/extensions/types.js.map +1 -1
  94. package/dist/core/package-manager.d.ts +1 -0
  95. package/dist/core/package-manager.d.ts.map +1 -1
  96. package/dist/core/package-manager.js +65 -28
  97. package/dist/core/package-manager.js.map +1 -1
  98. package/dist/core/resource-loader.d.ts.map +1 -1
  99. package/dist/core/resource-loader.js +13 -5
  100. package/dist/core/resource-loader.js.map +1 -1
  101. package/dist/core/sdk.d.ts +3 -3
  102. package/dist/core/sdk.d.ts.map +1 -1
  103. package/dist/core/sdk.js.map +1 -1
  104. package/dist/core/session-manager.d.ts.map +1 -1
  105. package/dist/core/session-manager.js +1 -1
  106. package/dist/core/session-manager.js.map +1 -1
  107. package/dist/core/settings-manager.d.ts +2 -0
  108. package/dist/core/settings-manager.d.ts.map +1 -1
  109. package/dist/core/settings-manager.js.map +1 -1
  110. package/dist/core/slash-commands.d.ts.map +1 -1
  111. package/dist/core/slash-commands.js +1 -1
  112. package/dist/core/slash-commands.js.map +1 -1
  113. package/dist/core/system-prompt.d.ts.map +1 -1
  114. package/dist/core/system-prompt.js +5 -3
  115. package/dist/core/system-prompt.js.map +1 -1
  116. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +1 -1
  117. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
  118. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js +1 -1
  119. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
  120. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +8 -8
  121. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -1
  122. package/dist/core/tools/ask-user-question/view/dialog-builder.js +6 -6
  123. package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
  124. package/dist/core/tools/bash.d.ts.map +1 -1
  125. package/dist/core/tools/bash.js +1 -1
  126. package/dist/core/tools/bash.js.map +1 -1
  127. package/dist/core/tools/find.d.ts.map +1 -1
  128. package/dist/core/tools/find.js +1 -1
  129. package/dist/core/tools/find.js.map +1 -1
  130. package/dist/core/tools/grep.d.ts.map +1 -1
  131. package/dist/core/tools/grep.js +7 -4
  132. package/dist/core/tools/grep.js.map +1 -1
  133. package/dist/core/tools/index.d.ts +3 -2
  134. package/dist/core/tools/index.d.ts.map +1 -1
  135. package/dist/core/tools/index.js.map +1 -1
  136. package/dist/core/tools/ls.d.ts.map +1 -1
  137. package/dist/core/tools/ls.js +3 -2
  138. package/dist/core/tools/ls.js.map +1 -1
  139. package/dist/core/tools/read.d.ts.map +1 -1
  140. package/dist/core/tools/read.js +2 -2
  141. package/dist/core/tools/read.js.map +1 -1
  142. package/dist/core/tools/render-utils.d.ts +2 -1
  143. package/dist/core/tools/render-utils.d.ts.map +1 -1
  144. package/dist/core/tools/render-utils.js.map +1 -1
  145. package/dist/core/tools/todos.d.ts.map +1 -1
  146. package/dist/core/tools/todos.js +1 -1
  147. package/dist/core/tools/todos.js.map +1 -1
  148. package/dist/core/tools/tool-definition-wrapper.d.ts +4 -3
  149. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  150. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  151. package/dist/core/tools/write.d.ts.map +1 -1
  152. package/dist/core/tools/write.js +1 -1
  153. package/dist/core/tools/write.js.map +1 -1
  154. package/dist/index.d.ts +2 -1
  155. package/dist/index.d.ts.map +1 -1
  156. package/dist/index.js +2 -1
  157. package/dist/index.js.map +1 -1
  158. package/dist/main.d.ts.map +1 -1
  159. package/dist/main.js +2 -2
  160. package/dist/main.js.map +1 -1
  161. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  162. package/dist/modes/interactive/components/assistant-message.js +3 -3
  163. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  164. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  165. package/dist/modes/interactive/components/bash-execution.js +3 -3
  166. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  167. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  168. package/dist/modes/interactive/components/branch-summary-message.js +1 -1
  169. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  170. package/dist/modes/interactive/components/chat-message-renderer.d.ts +2 -1
  171. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  172. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  173. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  174. package/dist/modes/interactive/components/compaction-summary-message.js +1 -1
  175. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  176. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  177. package/dist/modes/interactive/components/config-selector.js +1 -1
  178. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  179. package/dist/modes/interactive/components/custom-editor.d.ts +3 -0
  180. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  181. package/dist/modes/interactive/components/custom-editor.js +13 -3
  182. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  183. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  184. package/dist/modes/interactive/components/footer.js +1 -1
  185. package/dist/modes/interactive/components/footer.js.map +1 -1
  186. package/dist/modes/interactive/components/index.d.ts +2 -1
  187. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  188. package/dist/modes/interactive/components/index.js +2 -1
  189. package/dist/modes/interactive/components/index.js.map +1 -1
  190. package/dist/modes/interactive/components/keybinding-hints.d.ts +1 -0
  191. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  192. package/dist/modes/interactive/components/keybinding-hints.js +47 -5
  193. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  194. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  195. package/dist/modes/interactive/components/login-dialog.js +5 -5
  196. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  197. package/dist/modes/interactive/components/model-selector.d.ts +3 -3
  198. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  199. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  200. package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
  201. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  202. package/dist/modes/interactive/components/scoped-models-selector.js +7 -7
  203. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  204. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  205. package/dist/modes/interactive/components/session-selector.js +8 -8
  206. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  207. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  208. package/dist/modes/interactive/components/settings-selector.js +3 -3
  209. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  210. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  211. package/dist/modes/interactive/components/skill-invocation-message.js +2 -2
  212. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  213. package/dist/modes/interactive/components/tool-execution.d.ts +10 -12
  214. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  215. package/dist/modes/interactive/components/tool-execution.js +3 -3
  216. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  217. package/dist/modes/interactive/components/working-status.d.ts +25 -0
  218. package/dist/modes/interactive/components/working-status.d.ts.map +1 -0
  219. package/dist/modes/interactive/components/working-status.js +28 -0
  220. package/dist/modes/interactive/components/working-status.js.map +1 -0
  221. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  222. package/dist/modes/interactive/interactive-mode.js +8 -7
  223. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  224. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  225. package/dist/modes/rpc/rpc-mode.js +8 -0
  226. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  227. package/dist/modes/rpc/rpc-types.d.ts +5 -5
  228. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  229. package/dist/modes/rpc/rpc-types.js.map +1 -1
  230. package/dist/utils/tools-manager.d.ts.map +1 -1
  231. package/dist/utils/tools-manager.js.map +1 -1
  232. package/docs/development.md +2 -2
  233. package/docs/extensions.md +7 -7
  234. package/docs/packages.md +11 -8
  235. package/docs/quickstart.md +2 -2
  236. package/docs/rpc.md +1 -1
  237. package/docs/sdk.md +14 -11
  238. package/docs/session-format.md +1 -1
  239. package/docs/sessions.md +10 -10
  240. package/docs/settings.md +1 -1
  241. package/docs/terminal-setup.md +9 -9
  242. package/docs/tmux.md +10 -10
  243. package/docs/tui.md +2 -2
  244. package/docs/usage.md +9 -9
  245. package/package.json +6 -1
@@ -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,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGjG,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,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;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAEtH,MAAM,UAA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AAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CACjG,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, relative, resolve as resolvePath, sep } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"@earendil-works/pi-ai\";\nimport { Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getReadmePath } from \"../../config.js\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.js\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.js\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.js\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { resolveReadPath } from \"./path-utils.js\";\nimport { getTextOutput, invalidArgText, replaceTabs, shortenPath, str } from \"./render-utils.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\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});\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([\"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"]);\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}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\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}\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): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\tconst invalidArg = invalidArgText(theme);\n\tconst pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\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 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 = resolveReadPath(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\tcwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError && getCompactReadClassification(args, cwd)) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveReadPath(path, cwd);\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\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\tif (mimeType) {\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\tconst base64 = buffer.toString(\"base64\");\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({ type: \"image\", data: base64, 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: 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.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\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\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(allLines[startLine], \"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 ${totalFileLines}. 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 ${totalFileLines} (${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 (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. 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 user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification ? formatCompactReadCall(classification, args, theme) : formatReadCall(args, theme),\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,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGjG,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAC1F,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ative, resolve as resolvePath, sep } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"@earendil-works/pi-ai\";\nimport { Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { getReadmePath } from \"../../config.js\";\nimport { keyHint, keyText } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../modes/interactive/theme/theme.js\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.js\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.js\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { resolveReadPath } from \"./path-utils.js\";\nimport { getTextOutput, invalidArgText, replaceTabs, shortenPath, str } from \"./render-utils.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\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});\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([\"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"]);\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}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\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}\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): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\tconst invalidArg = invalidArgText(theme);\n\tconst pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\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 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 = resolveReadPath(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\")} 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\tcwd: string,\n\tisError: boolean,\n): string {\n\tif (!options.expanded && !isError && getCompactReadClassification(args, cwd)) {\n\t\treturn \"\";\n\t}\n\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"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\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveReadPath(path, cwd);\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\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\tif (mimeType) {\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\tconst base64 = buffer.toString(\"base64\");\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({ type: \"image\", data: base64, 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: 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.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\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\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(allLines[startLine], \"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 ${totalFileLines}. 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 ${totalFileLines} (${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 (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. 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 user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst classification = !context.expanded ? getCompactReadClassification(args, context.cwd) : undefined;\n\t\t\ttext.setText(\n\t\t\t\tclassification ? formatCompactReadCall(classification, args, theme) : formatReadCall(args, theme),\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,4 +1,5 @@
1
1
  import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
2
+ import type { ThemeColor } from "../../modes/interactive/theme/theme.js";
2
3
  export declare function shortenPath(path: unknown): string;
3
4
  export declare function str(value: unknown): string | null;
4
5
  export declare function replaceTabs(text: string): string;
@@ -16,6 +17,6 @@ export type ToolRenderResultLike<TDetails> = {
16
17
  details: TDetails;
17
18
  };
18
19
  export declare function invalidArgText(theme: {
19
- fg: (name: any, text: string) => string;
20
+ fg: (name: ThemeColor, text: string) => string;
20
21
  }): string;
21
22
  //# sourceMappingURL=render-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKvE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOjD;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,CAAC,QAAQ,IAAI;IAC5C,OAAO,EAAE,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,GAAG,MAAM,CAEzF","sourcesContent":["import * as os from \"node:os\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { getCapabilities, getImageDimensions, imageFallback } from \"@earendil-works/pi-tui\";\nimport { stripAnsi } from \"../../utils/ansi.js\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.js\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: { fg: (name: any, text: string) => string }): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n"]}
1
+ {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAIzE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOjD;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,CAAC,QAAQ,IAAI;IAC5C,OAAO,EAAE,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,GAAG,MAAM,CAEhG","sourcesContent":["import * as os from \"node:os\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { getCapabilities, getImageDimensions, imageFallback } from \"@earendil-works/pi-tui\";\nimport type { ThemeColor } from \"../../modes/interactive/theme/theme.js\";\nimport { stripAnsi } from \"../../utils/ansi.js\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.js\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: { fg: (name: ThemeColor, text: string) => string }): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,UAAU,WAAW,CAAC,IAAa;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAChD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,E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ACb,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAOD,MAAM,UAAU,cAAc,CAAC,KAAkD;IAChF,OAAO,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import * as os from \"node:os\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { getCapabilities, getImageDimensions, imageFallback } from \"@earendil-works/pi-tui\";\nimport { stripAnsi } from \"../../utils/ansi.js\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.js\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: { fg: (name: any, text: string) => string }): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n"]}
1
+ {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,UAAU,WAAW,CAAC,IAAa;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,O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CAAC,CAAC,CAAC,SAAS,CAAC;YAClG,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAOD,MAAM,UAAU,cAAc,CAAC,KAAyD;IACvF,OAAO,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import * as os from \"node:os\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport { getCapabilities, getImageDimensions, imageFallback } from \"@earendil-works/pi-tui\";\nimport type { ThemeColor } from \"../../modes/interactive/theme/theme.js\";\nimport { stripAnsi } from \"../../utils/ansi.js\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.js\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: { fg: (name: ThemeColor, text: string) => string }): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"todos.d.ts","sourceRoot":"","sources":["../../../src/core/tools/todos.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAU/E,UAAU,eAAe;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,UAAW,SAAQ,eAAe;IAC3C,IAAI,EAAE,MAAM,CAAC;CACb;AASD,QAAA,MAAM,UAAU;;;;;;;;EAsBd,CAAC;AAaH,KAAK,eAAe,GACjB;IACA,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CACd,GACD;IACA,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAymBL,wBAAgB,wBAAwB,CACvC,GAAG,GAAE,MAAsB,GACzB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,CAAC,CA4WpD","sourcesContent":["/**\n * This tool stores todo items as files under <todo-dir> (defaults to\n * <CONFIG_DIR_NAME>/todos, or the path in <APP_NAME>_TODO_PATH). Each todo is\n * a standalone markdown file named <id>.md and an optional <id>.lock file is\n * used while a session is editing it.\n *\n * File format in <CONFIG_DIR_NAME>/todos:\n * - The file starts with a JSON object (not YAML) containing the front matter:\n * { id, title, tags, status, created_at, assigned_to_session }\n * - After the JSON block comes optional markdown body text separated by a blank line.\n * - Example:\n * {\n * \"id\": \"deadbeef\",\n * \"title\": \"Add tests\",\n * \"tags\": [\"qa\"],\n * \"status\": \"open\",\n * \"created_at\": \"2026-01-25T17:00:00.000Z\",\n * \"assigned_to_session\": \"session.json\"\n * }\n *\n * Notes about the work go here.\n */\nimport { StringEnum } from \"@earendil-works/pi-ai\";\nimport { Text } from \"@earendil-works/pi-tui\";\nimport crypto from \"node:crypto\";\nimport { existsSync } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Type } from \"typebox\";\nimport { APP_NAME, CONFIG_DIR_NAME, getEnvValue } from \"../../config.js\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.js\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\n\nconst TODO_DIR_NAME = `${CONFIG_DIR_NAME}/todos`;\nconst TODO_PATH_ENV = `${APP_NAME.toUpperCase()}_TODO_PATH`;\nconst TODO_ID_PREFIX = \"TODO-\";\nconst TODO_ID_PATTERN = /^[a-f0-9]{8}$/i;\nconst LOCK_TTL_MS = 30 * 60 * 1000;\n\ninterface TodoFrontMatter {\n\tid: string;\n\ttitle: string;\n\ttags: string[];\n\tstatus: string;\n\tcreated_at: string;\n\tassigned_to_session?: string;\n}\n\ninterface TodoRecord extends TodoFrontMatter {\n\tbody: string;\n}\n\ninterface LockInfo {\n\tid: string;\n\tpid: number;\n\tsession?: string | null;\n\tcreated_at: string;\n}\n\nconst TodoParams = Type.Object({\n\taction: StringEnum([\n\t\t\"list\",\n\t\t\"list-all\",\n\t\t\"get\",\n\t\t\"create\",\n\t\t\"update\",\n\t\t\"append\",\n\t\t\"delete\",\n\t\t\"claim\",\n\t\t\"release\",\n\t] as const),\n\tid: Type.Optional(Type.String({ description: \"Todo id (TODO-<hex> or raw hex filename)\" })),\n\ttitle: Type.Optional(Type.String({ description: \"Short summary shown in lists\" })),\n\tstatus: Type.Optional(Type.String({ description: \"Todo status\" })),\n\ttags: Type.Optional(Type.Array(Type.String({ description: \"Todo tag\" }))),\n\tbody: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Long-form details (markdown). Update replaces; append adds.\",\n\t\t}),\n\t),\n\tforce: Type.Optional(Type.Boolean({ description: \"Override another session's assignment\" })),\n});\n\ntype TodoAction =\n\t| \"list\"\n\t| \"list-all\"\n\t| \"get\"\n\t| \"create\"\n\t| \"update\"\n\t| \"append\"\n\t| \"delete\"\n\t| \"claim\"\n\t| \"release\";\n\ntype TodoToolDetails =\n\t| {\n\t\t\taction: \"list\" | \"list-all\";\n\t\t\ttodos: TodoFrontMatter[];\n\t\t\tcurrentSessionId?: string;\n\t\t\terror?: string;\n\t }\n\t| {\n\t\t\taction: \"get\" | \"create\" | \"update\" | \"append\" | \"delete\" | \"claim\" | \"release\";\n\t\t\ttodo?: TodoRecord;\n\t\t\terror?: string;\n\t };\n\nfunction formatTodoId(id: string): string {\n\treturn `${TODO_ID_PREFIX}${id}`;\n}\n\nfunction normalizeTodoId(id: string): string {\n\tlet trimmed = id.trim();\n\tif (trimmed.startsWith(\"#\")) {\n\t\ttrimmed = trimmed.slice(1);\n\t}\n\tif (trimmed.toUpperCase().startsWith(TODO_ID_PREFIX)) {\n\t\ttrimmed = trimmed.slice(TODO_ID_PREFIX.length);\n\t}\n\treturn trimmed;\n}\n\nfunction validateTodoId(id: string): { id: string } | { error: string } {\n\tconst normalized = normalizeTodoId(id);\n\tif (!normalized || !TODO_ID_PATTERN.test(normalized)) {\n\t\treturn { error: \"Invalid todo id. Expected TODO-<hex>.\" };\n\t}\n\treturn { id: normalized.toLowerCase() };\n}\n\nfunction displayTodoId(id: string): string {\n\treturn formatTodoId(normalizeTodoId(id));\n}\n\nfunction isTodoClosed(status: string): boolean {\n\treturn [\"closed\", \"done\"].includes(status.toLowerCase());\n}\n\nfunction clearAssignmentIfClosed(todo: TodoFrontMatter): void {\n\tif (isTodoClosed(getTodoStatus(todo))) {\n\t\ttodo.assigned_to_session = undefined;\n\t}\n}\n\nfunction sortTodos(todos: TodoFrontMatter[]): TodoFrontMatter[] {\n\treturn [...todos].sort((a, b) => {\n\t\tconst aClosed = isTodoClosed(a.status);\n\t\tconst bClosed = isTodoClosed(b.status);\n\t\tif (aClosed !== bClosed) return aClosed ? 1 : -1;\n\t\tconst aAssigned = !aClosed && Boolean(a.assigned_to_session);\n\t\tconst bAssigned = !bClosed && Boolean(b.assigned_to_session);\n\t\tif (aAssigned !== bAssigned) return aAssigned ? -1 : 1;\n\t\treturn (a.created_at || \"\").localeCompare(b.created_at || \"\");\n\t});\n}\n\nfunction getTodosDir(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath && overridePath.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn path.resolve(cwd, TODO_DIR_NAME);\n}\n\nfunction getTodosDirLabel(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath && overridePath.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn TODO_DIR_NAME;\n}\n\nfunction getTodoPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.md`);\n}\n\nfunction getLockPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.lock`);\n}\n\nfunction parseFrontMatter(text: string, idFallback: string): TodoFrontMatter {\n\tconst data: TodoFrontMatter = {\n\t\tid: idFallback,\n\t\ttitle: \"\",\n\t\ttags: [],\n\t\tstatus: \"open\",\n\t\tcreated_at: \"\",\n\t\tassigned_to_session: undefined,\n\t};\n\n\tconst trimmed = text.trim();\n\tif (!trimmed) return data;\n\n\ttry {\n\t\tconst parsed = JSON.parse(trimmed) as Partial<TodoFrontMatter> | null;\n\t\tif (!parsed || typeof parsed !== \"object\") return data;\n\t\tif (typeof parsed.id === \"string\" && parsed.id) data.id = parsed.id;\n\t\tif (typeof parsed.title === \"string\") data.title = parsed.title;\n\t\tif (typeof parsed.status === \"string\" && parsed.status) data.status = parsed.status;\n\t\tif (typeof parsed.created_at === \"string\") data.created_at = parsed.created_at;\n\t\tif (\n\t\t\ttypeof parsed.assigned_to_session === \"string\" &&\n\t\t\tparsed.assigned_to_session.trim()\n\t\t) {\n\t\t\tdata.assigned_to_session = parsed.assigned_to_session;\n\t\t}\n\t\tif (Array.isArray(parsed.tags)) {\n\t\t\tdata.tags = parsed.tags.filter((tag): tag is string => typeof tag === \"string\");\n\t\t}\n\t} catch {\n\t\treturn data;\n\t}\n\n\treturn data;\n}\n\nfunction findJsonObjectEnd(content: string): number {\n\tlet depth = 0;\n\tlet inString = false;\n\tlet escaped = false;\n\n\tfor (let i = 0; i < content.length; i += 1) {\n\t\tconst char = content[i];\n\n\t\tif (inString) {\n\t\t\tif (escaped) {\n\t\t\t\tescaped = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"\\\\\") {\n\t\t\t\tescaped = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === '\"') {\n\t\t\t\tinString = false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\"') {\n\t\t\tinString = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tdepth += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"}\") {\n\t\t\tdepth -= 1;\n\t\t\tif (depth === 0) return i;\n\t\t}\n\t}\n\n\treturn -1;\n}\n\nfunction splitFrontMatter(content: string): { frontMatter: string; body: string } {\n\tif (!content.startsWith(\"{\")) {\n\t\treturn { frontMatter: \"\", body: content };\n\t}\n\n\tconst endIndex = findJsonObjectEnd(content);\n\tif (endIndex === -1) {\n\t\treturn { frontMatter: \"\", body: content };\n\t}\n\n\tconst frontMatter = content.slice(0, endIndex + 1);\n\tconst body = content.slice(endIndex + 1).replace(/^\\r?\\n+/, \"\");\n\treturn { frontMatter, body };\n}\n\nfunction parseTodoContent(content: string, idFallback: string): TodoRecord {\n\tconst { frontMatter, body } = splitFrontMatter(content);\n\tconst parsed = parseFrontMatter(frontMatter, idFallback);\n\treturn {\n\t\tid: idFallback,\n\t\ttitle: parsed.title,\n\t\ttags: parsed.tags ?? [],\n\t\tstatus: parsed.status,\n\t\tcreated_at: parsed.created_at,\n\t\tassigned_to_session: parsed.assigned_to_session,\n\t\tbody: body ?? \"\",\n\t};\n}\n\nfunction serializeTodo(todo: TodoRecord): string {\n\tconst frontMatter = JSON.stringify(\n\t\t{\n\t\t\tid: todo.id,\n\t\t\ttitle: todo.title,\n\t\t\ttags: todo.tags ?? [],\n\t\t\tstatus: todo.status,\n\t\t\tcreated_at: todo.created_at,\n\t\t\tassigned_to_session: todo.assigned_to_session || undefined,\n\t\t},\n\t\tnull,\n\t\t2,\n\t);\n\n\tconst body = todo.body ?? \"\";\n\tconst trimmedBody = body.replace(/^\\n+/, \"\").replace(/\\s+$/, \"\");\n\tif (!trimmedBody) return `${frontMatter}\\n`;\n\treturn `${frontMatter}\\n\\n${trimmedBody}\\n`;\n}\n\nasync function ensureTodosDir(todosDir: string) {\n\tawait fs.mkdir(todosDir, { recursive: true });\n}\n\nasync function readTodoFile(filePath: string, idFallback: string): Promise<TodoRecord> {\n\tconst content = await fs.readFile(filePath, \"utf8\");\n\treturn parseTodoContent(content, idFallback);\n}\n\nasync function writeTodoFile(filePath: string, todo: TodoRecord) {\n\tawait fs.writeFile(filePath, serializeTodo(todo), \"utf8\");\n}\n\nasync function generateTodoId(todosDir: string): Promise<string> {\n\tfor (let attempt = 0; attempt < 10; attempt += 1) {\n\t\tconst id = crypto.randomBytes(4).toString(\"hex\");\n\t\tconst todoPath = getTodoPath(todosDir, id);\n\t\tif (!existsSync(todoPath)) return id;\n\t}\n\tthrow new Error(\"Failed to generate unique todo id\");\n}\n\nasync function readLockInfo(lockPath: string): Promise<LockInfo | null> {\n\ttry {\n\t\tconst raw = await fs.readFile(lockPath, \"utf8\");\n\t\treturn JSON.parse(raw) as LockInfo;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function acquireLock(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n): Promise<(() => Promise<void>) | { error: string }> {\n\tconst lockPath = getLockPath(todosDir, id);\n\tconst now = Date.now();\n\tconst session = ctx.sessionManager.getSessionFile();\n\n\tfor (let attempt = 0; attempt < 2; attempt += 1) {\n\t\ttry {\n\t\t\tconst handle = await fs.open(lockPath, \"wx\");\n\t\t\tconst info: LockInfo = {\n\t\t\t\tid,\n\t\t\t\tpid: process.pid,\n\t\t\t\tsession,\n\t\t\t\tcreated_at: new Date(now).toISOString(),\n\t\t\t};\n\t\t\tawait handle.writeFile(JSON.stringify(info, null, 2), \"utf8\");\n\t\t\tawait handle.close();\n\t\t\treturn async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait fs.unlink(lockPath);\n\t\t\t\t} catch {\n\t\t\t\t\t// ignore\n\t\t\t\t}\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconst fsError = error as { code?: string; message?: string };\n\t\t\tif (fsError.code !== \"EEXIST\") {\n\t\t\t\treturn {\n\t\t\t\t\terror: `Failed to acquire lock: ${fsError.message ?? \"unknown error\"}`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst stats = await fs.stat(lockPath).catch(() => null);\n\t\t\tconst lockAge = stats ? now - stats.mtimeMs : LOCK_TTL_MS + 1;\n\t\t\tif (lockAge <= LOCK_TTL_MS) {\n\t\t\t\tconst info = await readLockInfo(lockPath);\n\t\t\t\tconst owner = info?.session ? ` (session ${info.session})` : \"\";\n\t\t\t\treturn {\n\t\t\t\t\terror: `Todo ${displayTodoId(id)} is locked${owner}. Try again later.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\treturn {\n\t\t\t\t\terror: `Todo ${displayTodoId(id)} lock is stale; rerun in interactive mode to steal it.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst ok = await ctx.ui.confirm(\n\t\t\t\t\"Todo locked\",\n\t\t\t\t`Todo ${displayTodoId(id)} appears locked. Steal the lock?`,\n\t\t\t);\n\t\t\tif (!ok) {\n\t\t\t\treturn { error: `Todo ${displayTodoId(id)} remains locked.` };\n\t\t\t}\n\t\t\tawait fs.unlink(lockPath).catch(() => undefined);\n\t\t}\n\t}\n\n\treturn { error: `Failed to acquire lock for todo ${displayTodoId(id)}.` };\n}\n\nasync function withTodoLock<T>(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n\tfn: () => Promise<T>,\n): Promise<T | { error: string }> {\n\tconst lock = await acquireLock(todosDir, id, ctx);\n\tif (typeof lock === \"object\" && \"error\" in lock) return lock;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\tawait lock();\n\t}\n}\n\nasync function listTodos(todosDir: string): Promise<TodoFrontMatter[]> {\n\tlet entries: string[] = [];\n\ttry {\n\t\tentries = await fs.readdir(todosDir);\n\t} catch {\n\t\treturn [];\n\t}\n\n\tconst todos: TodoFrontMatter[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.endsWith(\".md\")) continue;\n\t\tconst id = entry.slice(0, -3);\n\t\tconst filePath = path.join(todosDir, entry);\n\t\ttry {\n\t\t\tconst content = await fs.readFile(filePath, \"utf8\");\n\t\t\tconst { frontMatter } = splitFrontMatter(content);\n\t\t\tconst parsed = parseFrontMatter(frontMatter, id);\n\t\t\ttodos.push({\n\t\t\t\tid,\n\t\t\t\ttitle: parsed.title,\n\t\t\t\ttags: parsed.tags ?? [],\n\t\t\t\tstatus: parsed.status,\n\t\t\t\tcreated_at: parsed.created_at,\n\t\t\t\tassigned_to_session: parsed.assigned_to_session,\n\t\t\t});\n\t\t} catch {\n\t\t\t// ignore unreadable todo\n\t\t}\n\t}\n\n\treturn sortTodos(todos);\n}\n\nfunction getTodoTitle(todo: TodoFrontMatter): string {\n\treturn todo.title || \"(untitled)\";\n}\n\nfunction getTodoStatus(todo: TodoFrontMatter): string {\n\treturn todo.status || \"open\";\n}\n\nfunction renderAssignmentSuffix(\n\ttheme: Theme,\n\ttodo: TodoFrontMatter,\n\tcurrentSessionId?: string,\n): string {\n\tif (!todo.assigned_to_session) return \"\";\n\tconst isCurrent = todo.assigned_to_session === currentSessionId;\n\tconst color = isCurrent ? \"success\" : \"dim\";\n\tconst suffix = isCurrent ? \", current\" : \"\";\n\treturn theme.fg(color, ` (assigned: ${todo.assigned_to_session}${suffix})`);\n}\n\nfunction splitTodosByAssignment(todos: TodoFrontMatter[]): {\n\tassignedTodos: TodoFrontMatter[];\n\topenTodos: TodoFrontMatter[];\n\tclosedTodos: TodoFrontMatter[];\n} {\n\tconst assignedTodos: TodoFrontMatter[] = [];\n\tconst openTodos: TodoFrontMatter[] = [];\n\tconst closedTodos: TodoFrontMatter[] = [];\n\tfor (const todo of todos) {\n\t\tif (isTodoClosed(getTodoStatus(todo))) {\n\t\t\tclosedTodos.push(todo);\n\t\t\tcontinue;\n\t\t}\n\t\tif (todo.assigned_to_session) {\n\t\t\tassignedTodos.push(todo);\n\t\t} else {\n\t\t\topenTodos.push(todo);\n\t\t}\n\t}\n\treturn { assignedTodos, openTodos, closedTodos };\n}\n\nfunction serializeTodoForAgent(todo: TodoRecord): string {\n\tconst payload = { ...todo, id: formatTodoId(todo.id) };\n\treturn JSON.stringify(payload, null, 2);\n}\n\nfunction serializeTodoListForAgent(todos: TodoFrontMatter[]): string {\n\tconst { assignedTodos, openTodos, closedTodos } = splitTodosByAssignment(todos);\n\tconst mapTodo = (todo: TodoFrontMatter) => ({\n\t\t...todo,\n\t\tid: formatTodoId(todo.id),\n\t});\n\treturn JSON.stringify(\n\t\t{\n\t\t\tassigned: assignedTodos.map(mapTodo),\n\t\t\topen: openTodos.map(mapTodo),\n\t\t\tclosed: closedTodos.map(mapTodo),\n\t\t},\n\t\tnull,\n\t\t2,\n\t);\n}\n\nfunction renderTodoHeading(\n\ttheme: Theme,\n\ttodo: TodoFrontMatter,\n\tcurrentSessionId?: string,\n): string {\n\tconst closed = isTodoClosed(getTodoStatus(todo));\n\tconst titleColor = closed ? \"dim\" : \"text\";\n\tconst tagText = todo.tags.length ? theme.fg(\"dim\", ` [${todo.tags.join(\", \")}]`) : \"\";\n\tconst assignmentText = renderAssignmentSuffix(theme, todo, currentSessionId);\n\treturn (\n\t\ttheme.fg(\"accent\", formatTodoId(todo.id)) +\n\t\t\" \" +\n\t\ttheme.fg(titleColor, getTodoTitle(todo)) +\n\t\ttagText +\n\t\tassignmentText\n\t);\n}\n\nfunction renderTodoList(\n\ttheme: Theme,\n\ttodos: TodoFrontMatter[],\n\texpanded: boolean,\n\tcurrentSessionId?: string,\n): string {\n\tif (!todos.length) return theme.fg(\"dim\", \"No todos\");\n\n\tconst { assignedTodos, openTodos, closedTodos } = splitTodosByAssignment(todos);\n\tconst lines: string[] = [];\n\tconst pushSection = (label: string, sectionTodos: TodoFrontMatter[]) => {\n\t\tlines.push(theme.fg(\"muted\", `${label} (${sectionTodos.length})`));\n\t\tif (!sectionTodos.length) {\n\t\t\tlines.push(theme.fg(\"dim\", \" none\"));\n\t\t\treturn;\n\t\t}\n\t\tconst maxItems = expanded ? sectionTodos.length : Math.min(sectionTodos.length, 3);\n\t\tfor (let i = 0; i < maxItems; i++) {\n\t\t\tlines.push(` ${renderTodoHeading(theme, sectionTodos[i], currentSessionId)}`);\n\t\t}\n\t\tif (!expanded && sectionTodos.length > maxItems) {\n\t\t\tlines.push(theme.fg(\"dim\", ` ... ${sectionTodos.length - maxItems} more`));\n\t\t}\n\t};\n\n\tconst sections: Array<{ label: string; todos: TodoFrontMatter[] }> = [\n\t\t{ label: \"Assigned todos\", todos: assignedTodos },\n\t\t{ label: \"Open todos\", todos: openTodos },\n\t\t{ label: \"Closed todos\", todos: closedTodos },\n\t];\n\n\tsections.forEach((section, index) => {\n\t\tif (index > 0) lines.push(\"\");\n\t\tpushSection(section.label, section.todos);\n\t});\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction renderTodoDetail(theme: Theme, todo: TodoRecord, expanded: boolean): string {\n\tconst summary = renderTodoHeading(theme, todo);\n\tif (!expanded) return summary;\n\n\tconst tags = todo.tags.length ? todo.tags.join(\", \") : \"none\";\n\tconst createdAt = todo.created_at || \"unknown\";\n\tconst bodyText = todo.body?.trim() ? todo.body.trim() : \"No details yet.\";\n\tconst bodyLines = bodyText.split(\"\\n\");\n\n\tconst lines = [\n\t\tsummary,\n\t\ttheme.fg(\"muted\", `Status: ${getTodoStatus(todo)}`),\n\t\ttheme.fg(\"muted\", `Tags: ${tags}`),\n\t\ttheme.fg(\"muted\", `Created: ${createdAt}`),\n\t\t\"\",\n\t\ttheme.fg(\"muted\", \"Body:\"),\n\t\t...bodyLines.map((line) => theme.fg(\"text\", ` ${line}`)),\n\t];\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction appendExpandHint(theme: Theme, text: string): string {\n\treturn `${text}\\n${theme.fg(\"dim\", `(${keyHint(\"app.tools.expand\", \"to expand\")})`)}`;\n}\n\nasync function ensureTodoExists(filePath: string, id: string): Promise<TodoRecord | null> {\n\tif (!existsSync(filePath)) return null;\n\treturn readTodoFile(filePath, id);\n}\n\nasync function appendTodoBody(\n\tfilePath: string,\n\ttodo: TodoRecord,\n\ttext: string,\n): Promise<TodoRecord> {\n\tconst spacer = todo.body.trim().length ? \"\\n\\n\" : \"\";\n\ttodo.body = `${todo.body.replace(/\\s+$/, \"\")}${spacer}${text.trim()}\\n`;\n\tawait writeTodoFile(filePath, todo);\n\treturn todo;\n}\n\nasync function claimTodoAssignment(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n\tforce = false,\n): Promise<TodoRecord | { error: string }> {\n\tconst validated = validateTodoId(id);\n\tif (\"error\" in validated) {\n\t\treturn { error: validated.error };\n\t}\n\tconst normalizedId = validated.id;\n\tconst filePath = getTodoPath(todosDir, normalizedId);\n\tif (!existsSync(filePath)) {\n\t\treturn { error: `Todo ${displayTodoId(id)} not found` };\n\t}\n\tconst sessionId = ctx.sessionManager.getSessionId();\n\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\tif (!existing) return { error: `Todo ${displayTodoId(id)} not found` } as const;\n\t\tif (isTodoClosed(existing.status)) {\n\t\t\treturn { error: `Todo ${displayTodoId(id)} is closed` } as const;\n\t\t}\n\t\tconst assigned = existing.assigned_to_session;\n\t\tif (assigned && assigned !== sessionId && !force) {\n\t\t\treturn {\n\t\t\t\terror: `Todo ${displayTodoId(id)} is already assigned to session ${assigned}. Use force to override.`,\n\t\t\t} as const;\n\t\t}\n\t\tif (assigned !== sessionId) {\n\t\t\texisting.assigned_to_session = sessionId;\n\t\t\tawait writeTodoFile(filePath, existing);\n\t\t}\n\t\treturn existing;\n\t});\n\n\tif (typeof result === \"object\" && \"error\" in result) {\n\t\treturn { error: result.error };\n\t}\n\n\treturn result;\n}\n\nasync function releaseTodoAssignment(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n\tforce = false,\n): Promise<TodoRecord | { error: string }> {\n\tconst validated = validateTodoId(id);\n\tif (\"error\" in validated) {\n\t\treturn { error: validated.error };\n\t}\n\tconst normalizedId = validated.id;\n\tconst filePath = getTodoPath(todosDir, normalizedId);\n\tif (!existsSync(filePath)) {\n\t\treturn { error: `Todo ${displayTodoId(id)} not found` };\n\t}\n\tconst sessionId = ctx.sessionManager.getSessionId();\n\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\tif (!existing) return { error: `Todo ${displayTodoId(id)} not found` } as const;\n\t\tconst assigned = existing.assigned_to_session;\n\t\tif (!assigned) {\n\t\t\treturn existing;\n\t\t}\n\t\tif (assigned !== sessionId && !force) {\n\t\t\treturn {\n\t\t\t\terror: `Todo ${displayTodoId(id)} is assigned to session ${assigned}. Use force to release.`,\n\t\t\t} as const;\n\t\t}\n\t\texisting.assigned_to_session = undefined;\n\t\tawait writeTodoFile(filePath, existing);\n\t\treturn existing;\n\t});\n\n\tif (typeof result === \"object\" && \"error\" in result) {\n\t\treturn { error: result.error };\n\t}\n\n\treturn result;\n}\n\nasync function deleteTodo(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n): Promise<TodoRecord | { error: string }> {\n\tconst validated = validateTodoId(id);\n\tif (\"error\" in validated) {\n\t\treturn { error: validated.error };\n\t}\n\tconst normalizedId = validated.id;\n\tconst filePath = getTodoPath(todosDir, normalizedId);\n\tif (!existsSync(filePath)) {\n\t\treturn { error: `Todo ${displayTodoId(id)} not found` };\n\t}\n\n\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\tif (!existing) return { error: `Todo ${displayTodoId(id)} not found` } as const;\n\t\tawait fs.unlink(filePath);\n\t\treturn existing;\n\t});\n\n\tif (typeof result === \"object\" && \"error\" in result) {\n\t\treturn { error: result.error };\n\t}\n\n\treturn result;\n}\n\nexport function createTodoToolDefinition(\n\tcwd: string = process.cwd(),\n): ToolDefinition<typeof TodoParams, TodoToolDetails> {\n\tconst todosDirLabel = getTodosDirLabel(cwd);\n\n\treturn {\n\t\tname: \"todo\",\n\t\tlabel: \"Todo\",\n\t\tdescription:\n\t\t\t`Manage file-based todos in ${todosDirLabel} (list, list-all, get, create, update, append, delete, claim, release). ` +\n\t\t\t\"Title is the short summary; body is long-form markdown notes (update replaces, append adds). \" +\n\t\t\t\"Todo ids are shown as TODO-<hex>; id parameters accept TODO-<hex> or the raw hex filename. \" +\n\t\t\t\"Claim tasks before working on them to avoid conflicts, and close them when complete.\",\n\t\tparameters: TodoParams,\n\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst todosDir = getTodosDir(ctx.cwd);\n\t\t\tconst action: TodoAction = params.action;\n\n\t\t\tswitch (action) {\n\t\t\t\tcase \"list\": {\n\t\t\t\t\tconst todos = await listTodos(todosDir);\n\t\t\t\t\tconst { assignedTodos, openTodos } = splitTodosByAssignment(todos);\n\t\t\t\t\tconst listedTodos = [...assignedTodos, ...openTodos];\n\t\t\t\t\tconst currentSessionId = ctx.sessionManager.getSessionId();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoListForAgent(listedTodos) }],\n\t\t\t\t\t\tdetails: { action: \"list\", todos: listedTodos, currentSessionId },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"list-all\": {\n\t\t\t\t\tconst todos = await listTodos(todosDir);\n\t\t\t\t\tconst currentSessionId = ctx.sessionManager.getSessionId();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoListForAgent(todos) }],\n\t\t\t\t\t\tdetails: { action: \"list-all\", todos, currentSessionId },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"get\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"get\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"get\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst normalizedId = validated.id;\n\t\t\t\t\tconst displayId = formatTodoId(normalizedId);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, normalizedId);\n\t\t\t\t\tconst todo = await ensureTodoExists(filePath, normalizedId);\n\t\t\t\t\tif (!todo) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Todo ${displayId} not found` }],\n\t\t\t\t\t\t\tdetails: { action: \"get\", error: \"not found\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(todo) }],\n\t\t\t\t\t\tdetails: { action: \"get\", todo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"create\": {\n\t\t\t\t\tif (!params.title) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: title required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"create\", error: \"title required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tawait ensureTodosDir(todosDir);\n\t\t\t\t\tconst id = await generateTodoId(todosDir);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, id);\n\t\t\t\t\tconst todo: TodoRecord = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\ttitle: params.title,\n\t\t\t\t\t\ttags: params.tags ?? [],\n\t\t\t\t\t\tstatus: params.status ?? \"open\",\n\t\t\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t\t\t\tbody: params.body ?? \"\",\n\t\t\t\t\t};\n\n\t\t\t\t\tconst result = await withTodoLock(todosDir, id, ctx, async () => {\n\t\t\t\t\t\tawait writeTodoFile(filePath, todo);\n\t\t\t\t\t\treturn todo;\n\t\t\t\t\t});\n\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"create\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(todo) }],\n\t\t\t\t\t\tdetails: { action: \"create\", todo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"update\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst normalizedId = validated.id;\n\t\t\t\t\tconst displayId = formatTodoId(normalizedId);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, normalizedId);\n\t\t\t\t\tif (!existsSync(filePath)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Todo ${displayId} not found` }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: \"not found\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\t\t\t\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\t\t\t\t\tif (!existing) return { error: `Todo ${displayId} not found` } as const;\n\n\t\t\t\t\t\texisting.id = normalizedId;\n\t\t\t\t\t\tif (params.title !== undefined) existing.title = params.title;\n\t\t\t\t\t\tif (params.status !== undefined) existing.status = params.status;\n\t\t\t\t\t\tif (params.tags !== undefined) existing.tags = params.tags;\n\t\t\t\t\t\tif (params.body !== undefined) existing.body = params.body;\n\t\t\t\t\t\tif (!existing.created_at) existing.created_at = new Date().toISOString();\n\t\t\t\t\t\tclearAssignmentIfClosed(existing);\n\n\t\t\t\t\t\tawait writeTodoFile(filePath, existing);\n\t\t\t\t\t\treturn existing;\n\t\t\t\t\t});\n\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"update\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"append\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst normalizedId = validated.id;\n\t\t\t\t\tconst displayId = formatTodoId(normalizedId);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, normalizedId);\n\t\t\t\t\tif (!existsSync(filePath)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Todo ${displayId} not found` }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: \"not found\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\t\t\t\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\t\t\t\t\tif (!existing) return { error: `Todo ${displayId} not found` } as const;\n\t\t\t\t\t\tif (!params.body || !params.body.trim()) {\n\t\t\t\t\t\t\treturn existing;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst updated = await appendTodoBody(filePath, existing, params.body);\n\t\t\t\t\t\treturn updated;\n\t\t\t\t\t});\n\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"append\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"claim\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"claim\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await claimTodoAssignment(\n\t\t\t\t\t\ttodosDir,\n\t\t\t\t\t\tparams.id,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tBoolean(params.force),\n\t\t\t\t\t);\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"claim\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"claim\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"release\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"release\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await releaseTodoAssignment(\n\t\t\t\t\t\ttodosDir,\n\t\t\t\t\t\tparams.id,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tBoolean(params.force),\n\t\t\t\t\t);\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"release\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"release\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"delete\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"delete\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"delete\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await deleteTodo(todosDir, validated.id, ctx);\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"delete\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: serializeTodoForAgent(result as TodoRecord),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { action: \"delete\", todo: result as TodoRecord },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst action = typeof args.action === \"string\" ? args.action : \"\";\n\t\t\tconst id = typeof args.id === \"string\" ? args.id : \"\";\n\t\t\tconst normalizedId = id ? normalizeTodoId(id) : \"\";\n\t\t\tconst title = typeof args.title === \"string\" ? args.title : \"\";\n\t\t\tlet text = theme.fg(\"toolTitle\", theme.bold(\"todo \")) + theme.fg(\"muted\", action);\n\t\t\tif (normalizedId) {\n\t\t\t\ttext += \" \" + theme.fg(\"accent\", formatTodoId(normalizedId));\n\t\t\t}\n\t\t\tif (title) {\n\t\t\t\ttext += \" \" + theme.fg(\"dim\", `\"${title}\"`);\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tconst details = result.details as TodoToolDetails | undefined;\n\t\t\tif (isPartial) {\n\t\t\t\treturn new Text(theme.fg(\"warning\", \"Processing...\"), 0, 0);\n\t\t\t}\n\t\t\tif (!details) {\n\t\t\t\tconst text = result.content[0];\n\t\t\t\treturn new Text(text?.type === \"text\" ? text.text : \"\", 0, 0);\n\t\t\t}\n\n\t\t\tif (details.error) {\n\t\t\t\treturn new Text(theme.fg(\"error\", `Error: ${details.error}`), 0, 0);\n\t\t\t}\n\n\t\t\tif (details.action === \"list\" || details.action === \"list-all\") {\n\t\t\t\tlet text = renderTodoList(theme, details.todos, expanded, details.currentSessionId);\n\t\t\t\tif (!expanded) {\n\t\t\t\t\tconst { closedTodos } = splitTodosByAssignment(details.todos);\n\t\t\t\t\tif (closedTodos.length) {\n\t\t\t\t\t\ttext = appendExpandHint(theme, text);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn new Text(text, 0, 0);\n\t\t\t}\n\n\t\t\tif (!(\"todo\" in details) || !details.todo) {\n\t\t\t\tconst text = result.content[0];\n\t\t\t\treturn new Text(text?.type === \"text\" ? text.text : \"\", 0, 0);\n\t\t\t}\n\n\t\t\tlet text = renderTodoDetail(theme, details.todo, expanded);\n\t\t\tconst actionLabel =\n\t\t\t\tdetails.action === \"create\"\n\t\t\t\t\t? \"Created\"\n\t\t\t\t\t: details.action === \"update\"\n\t\t\t\t\t\t? \"Updated\"\n\t\t\t\t\t\t: details.action === \"append\"\n\t\t\t\t\t\t\t? \"Appended to\"\n\t\t\t\t\t\t\t: details.action === \"delete\"\n\t\t\t\t\t\t\t\t? \"Deleted\"\n\t\t\t\t\t\t\t\t: details.action === \"claim\"\n\t\t\t\t\t\t\t\t\t? \"Claimed\"\n\t\t\t\t\t\t\t\t\t: details.action === \"release\"\n\t\t\t\t\t\t\t\t\t\t? \"Released\"\n\t\t\t\t\t\t\t\t\t\t: null;\n\t\t\tif (actionLabel) {\n\t\t\t\tconst lines = text.split(\"\\n\");\n\t\t\t\tlines[0] = theme.fg(\"success\", \"✓ \") + theme.fg(\"muted\", `${actionLabel} `) + lines[0];\n\t\t\t\ttext = lines.join(\"\\n\");\n\t\t\t}\n\t\t\tif (!expanded) {\n\t\t\t\ttext = appendExpandHint(theme, text);\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"todos.d.ts","sourceRoot":"","sources":["../../../src/core/tools/todos.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAU/E,UAAU,eAAe;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,UAAW,SAAQ,eAAe;IAC3C,IAAI,EAAE,MAAM,CAAC;CACb;AASD,QAAA,MAAM,UAAU;;;;;;;;EAsBd,CAAC;AAaH,KAAK,eAAe,GACjB;IACA,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CACd,GACD;IACA,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAymBL,wBAAgB,wBAAwB,CACvC,GAAG,GAAE,MAAsB,GACzB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,CAAC,CA4WpD","sourcesContent":["/**\n * This tool stores todo items as files under <todo-dir> (defaults to\n * <CONFIG_DIR_NAME>/todos, or the path in <APP_NAME>_TODO_PATH). Each todo is\n * a standalone markdown file named <id>.md and an optional <id>.lock file is\n * used while a session is editing it.\n *\n * File format in <CONFIG_DIR_NAME>/todos:\n * - The file starts with a JSON object (not YAML) containing the front matter:\n * { id, title, tags, status, created_at, assigned_to_session }\n * - After the JSON block comes optional markdown body text separated by a blank line.\n * - Example:\n * {\n * \"id\": \"deadbeef\",\n * \"title\": \"Add tests\",\n * \"tags\": [\"qa\"],\n * \"status\": \"open\",\n * \"created_at\": \"2026-01-25T17:00:00.000Z\",\n * \"assigned_to_session\": \"session.json\"\n * }\n *\n * Notes about the work go here.\n */\nimport { StringEnum } from \"@earendil-works/pi-ai\";\nimport { Text } from \"@earendil-works/pi-tui\";\nimport crypto from \"node:crypto\";\nimport { existsSync } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Type } from \"typebox\";\nimport { APP_NAME, CONFIG_DIR_NAME, getEnvValue } from \"../../config.js\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.js\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\n\nconst TODO_DIR_NAME = `${CONFIG_DIR_NAME}/todos`;\nconst TODO_PATH_ENV = `${APP_NAME.toUpperCase()}_TODO_PATH`;\nconst TODO_ID_PREFIX = \"TODO-\";\nconst TODO_ID_PATTERN = /^[a-f0-9]{8}$/i;\nconst LOCK_TTL_MS = 30 * 60 * 1000;\n\ninterface TodoFrontMatter {\n\tid: string;\n\ttitle: string;\n\ttags: string[];\n\tstatus: string;\n\tcreated_at: string;\n\tassigned_to_session?: string;\n}\n\ninterface TodoRecord extends TodoFrontMatter {\n\tbody: string;\n}\n\ninterface LockInfo {\n\tid: string;\n\tpid: number;\n\tsession?: string | null;\n\tcreated_at: string;\n}\n\nconst TodoParams = Type.Object({\n\taction: StringEnum([\n\t\t\"list\",\n\t\t\"list-all\",\n\t\t\"get\",\n\t\t\"create\",\n\t\t\"update\",\n\t\t\"append\",\n\t\t\"delete\",\n\t\t\"claim\",\n\t\t\"release\",\n\t] as const),\n\tid: Type.Optional(Type.String({ description: \"Todo id (TODO-<hex> or raw hex filename)\" })),\n\ttitle: Type.Optional(Type.String({ description: \"Short summary shown in lists\" })),\n\tstatus: Type.Optional(Type.String({ description: \"Todo status\" })),\n\ttags: Type.Optional(Type.Array(Type.String({ description: \"Todo tag\" }))),\n\tbody: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Long-form details (markdown). Update replaces; append adds.\",\n\t\t}),\n\t),\n\tforce: Type.Optional(Type.Boolean({ description: \"Override another session's assignment\" })),\n});\n\ntype TodoAction =\n\t| \"list\"\n\t| \"list-all\"\n\t| \"get\"\n\t| \"create\"\n\t| \"update\"\n\t| \"append\"\n\t| \"delete\"\n\t| \"claim\"\n\t| \"release\";\n\ntype TodoToolDetails =\n\t| {\n\t\t\taction: \"list\" | \"list-all\";\n\t\t\ttodos: TodoFrontMatter[];\n\t\t\tcurrentSessionId?: string;\n\t\t\terror?: string;\n\t }\n\t| {\n\t\t\taction: \"get\" | \"create\" | \"update\" | \"append\" | \"delete\" | \"claim\" | \"release\";\n\t\t\ttodo?: TodoRecord;\n\t\t\terror?: string;\n\t };\n\nfunction formatTodoId(id: string): string {\n\treturn `${TODO_ID_PREFIX}${id}`;\n}\n\nfunction normalizeTodoId(id: string): string {\n\tlet trimmed = id.trim();\n\tif (trimmed.startsWith(\"#\")) {\n\t\ttrimmed = trimmed.slice(1);\n\t}\n\tif (trimmed.toUpperCase().startsWith(TODO_ID_PREFIX)) {\n\t\ttrimmed = trimmed.slice(TODO_ID_PREFIX.length);\n\t}\n\treturn trimmed;\n}\n\nfunction validateTodoId(id: string): { id: string } | { error: string } {\n\tconst normalized = normalizeTodoId(id);\n\tif (!normalized || !TODO_ID_PATTERN.test(normalized)) {\n\t\treturn { error: \"Invalid todo id. Expected TODO-<hex>.\" };\n\t}\n\treturn { id: normalized.toLowerCase() };\n}\n\nfunction displayTodoId(id: string): string {\n\treturn formatTodoId(normalizeTodoId(id));\n}\n\nfunction isTodoClosed(status: string): boolean {\n\treturn [\"closed\", \"done\"].includes(status.toLowerCase());\n}\n\nfunction clearAssignmentIfClosed(todo: TodoFrontMatter): void {\n\tif (isTodoClosed(getTodoStatus(todo))) {\n\t\ttodo.assigned_to_session = undefined;\n\t}\n}\n\nfunction sortTodos(todos: TodoFrontMatter[]): TodoFrontMatter[] {\n\treturn [...todos].sort((a, b) => {\n\t\tconst aClosed = isTodoClosed(a.status);\n\t\tconst bClosed = isTodoClosed(b.status);\n\t\tif (aClosed !== bClosed) return aClosed ? 1 : -1;\n\t\tconst aAssigned = !aClosed && Boolean(a.assigned_to_session);\n\t\tconst bAssigned = !bClosed && Boolean(b.assigned_to_session);\n\t\tif (aAssigned !== bAssigned) return aAssigned ? -1 : 1;\n\t\treturn (a.created_at || \"\").localeCompare(b.created_at || \"\");\n\t});\n}\n\nfunction getTodosDir(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath && overridePath.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn path.resolve(cwd, TODO_DIR_NAME);\n}\n\nfunction getTodosDirLabel(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath && overridePath.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn TODO_DIR_NAME;\n}\n\nfunction getTodoPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.md`);\n}\n\nfunction getLockPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.lock`);\n}\n\nfunction parseFrontMatter(text: string, idFallback: string): TodoFrontMatter {\n\tconst data: TodoFrontMatter = {\n\t\tid: idFallback,\n\t\ttitle: \"\",\n\t\ttags: [],\n\t\tstatus: \"open\",\n\t\tcreated_at: \"\",\n\t\tassigned_to_session: undefined,\n\t};\n\n\tconst trimmed = text.trim();\n\tif (!trimmed) return data;\n\n\ttry {\n\t\tconst parsed = JSON.parse(trimmed) as Partial<TodoFrontMatter> | null;\n\t\tif (!parsed || typeof parsed !== \"object\") return data;\n\t\tif (typeof parsed.id === \"string\" && parsed.id) data.id = parsed.id;\n\t\tif (typeof parsed.title === \"string\") data.title = parsed.title;\n\t\tif (typeof parsed.status === \"string\" && parsed.status) data.status = parsed.status;\n\t\tif (typeof parsed.created_at === \"string\") data.created_at = parsed.created_at;\n\t\tif (\n\t\t\ttypeof parsed.assigned_to_session === \"string\" &&\n\t\t\tparsed.assigned_to_session.trim()\n\t\t) {\n\t\t\tdata.assigned_to_session = parsed.assigned_to_session;\n\t\t}\n\t\tif (Array.isArray(parsed.tags)) {\n\t\t\tdata.tags = parsed.tags.filter((tag): tag is string => typeof tag === \"string\");\n\t\t}\n\t} catch {\n\t\treturn data;\n\t}\n\n\treturn data;\n}\n\nfunction findJsonObjectEnd(content: string): number {\n\tlet depth = 0;\n\tlet inString = false;\n\tlet escaped = false;\n\n\tfor (let i = 0; i < content.length; i += 1) {\n\t\tconst char = content[i];\n\n\t\tif (inString) {\n\t\t\tif (escaped) {\n\t\t\t\tescaped = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === \"\\\\\") {\n\t\t\t\tescaped = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === '\"') {\n\t\t\t\tinString = false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\"') {\n\t\t\tinString = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tdepth += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"}\") {\n\t\t\tdepth -= 1;\n\t\t\tif (depth === 0) return i;\n\t\t}\n\t}\n\n\treturn -1;\n}\n\nfunction splitFrontMatter(content: string): { frontMatter: string; body: string } {\n\tif (!content.startsWith(\"{\")) {\n\t\treturn { frontMatter: \"\", body: content };\n\t}\n\n\tconst endIndex = findJsonObjectEnd(content);\n\tif (endIndex === -1) {\n\t\treturn { frontMatter: \"\", body: content };\n\t}\n\n\tconst frontMatter = content.slice(0, endIndex + 1);\n\tconst body = content.slice(endIndex + 1).replace(/^\\r?\\n+/, \"\");\n\treturn { frontMatter, body };\n}\n\nfunction parseTodoContent(content: string, idFallback: string): TodoRecord {\n\tconst { frontMatter, body } = splitFrontMatter(content);\n\tconst parsed = parseFrontMatter(frontMatter, idFallback);\n\treturn {\n\t\tid: idFallback,\n\t\ttitle: parsed.title,\n\t\ttags: parsed.tags ?? [],\n\t\tstatus: parsed.status,\n\t\tcreated_at: parsed.created_at,\n\t\tassigned_to_session: parsed.assigned_to_session,\n\t\tbody: body ?? \"\",\n\t};\n}\n\nfunction serializeTodo(todo: TodoRecord): string {\n\tconst frontMatter = JSON.stringify(\n\t\t{\n\t\t\tid: todo.id,\n\t\t\ttitle: todo.title,\n\t\t\ttags: todo.tags ?? [],\n\t\t\tstatus: todo.status,\n\t\t\tcreated_at: todo.created_at,\n\t\t\tassigned_to_session: todo.assigned_to_session || undefined,\n\t\t},\n\t\tnull,\n\t\t2,\n\t);\n\n\tconst body = todo.body ?? \"\";\n\tconst trimmedBody = body.replace(/^\\n+/, \"\").replace(/\\s+$/, \"\");\n\tif (!trimmedBody) return `${frontMatter}\\n`;\n\treturn `${frontMatter}\\n\\n${trimmedBody}\\n`;\n}\n\nasync function ensureTodosDir(todosDir: string) {\n\tawait fs.mkdir(todosDir, { recursive: true });\n}\n\nasync function readTodoFile(filePath: string, idFallback: string): Promise<TodoRecord> {\n\tconst content = await fs.readFile(filePath, \"utf8\");\n\treturn parseTodoContent(content, idFallback);\n}\n\nasync function writeTodoFile(filePath: string, todo: TodoRecord) {\n\tawait fs.writeFile(filePath, serializeTodo(todo), \"utf8\");\n}\n\nasync function generateTodoId(todosDir: string): Promise<string> {\n\tfor (let attempt = 0; attempt < 10; attempt += 1) {\n\t\tconst id = crypto.randomBytes(4).toString(\"hex\");\n\t\tconst todoPath = getTodoPath(todosDir, id);\n\t\tif (!existsSync(todoPath)) return id;\n\t}\n\tthrow new Error(\"Failed to generate unique todo id\");\n}\n\nasync function readLockInfo(lockPath: string): Promise<LockInfo | null> {\n\ttry {\n\t\tconst raw = await fs.readFile(lockPath, \"utf8\");\n\t\treturn JSON.parse(raw) as LockInfo;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function acquireLock(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n): Promise<(() => Promise<void>) | { error: string }> {\n\tconst lockPath = getLockPath(todosDir, id);\n\tconst now = Date.now();\n\tconst session = ctx.sessionManager.getSessionFile();\n\n\tfor (let attempt = 0; attempt < 2; attempt += 1) {\n\t\ttry {\n\t\t\tconst handle = await fs.open(lockPath, \"wx\");\n\t\t\tconst info: LockInfo = {\n\t\t\t\tid,\n\t\t\t\tpid: process.pid,\n\t\t\t\tsession,\n\t\t\t\tcreated_at: new Date(now).toISOString(),\n\t\t\t};\n\t\t\tawait handle.writeFile(JSON.stringify(info, null, 2), \"utf8\");\n\t\t\tawait handle.close();\n\t\t\treturn async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait fs.unlink(lockPath);\n\t\t\t\t} catch {\n\t\t\t\t\t// ignore\n\t\t\t\t}\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconst fsError = error as { code?: string; message?: string };\n\t\t\tif (fsError.code !== \"EEXIST\") {\n\t\t\t\treturn {\n\t\t\t\t\terror: `Failed to acquire lock: ${fsError.message ?? \"unknown error\"}`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst stats = await fs.stat(lockPath).catch(() => null);\n\t\t\tconst lockAge = stats ? now - stats.mtimeMs : LOCK_TTL_MS + 1;\n\t\t\tif (lockAge <= LOCK_TTL_MS) {\n\t\t\t\tconst info = await readLockInfo(lockPath);\n\t\t\t\tconst owner = info?.session ? ` (session ${info.session})` : \"\";\n\t\t\t\treturn {\n\t\t\t\t\terror: `Todo ${displayTodoId(id)} is locked${owner}. Try again later.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\treturn {\n\t\t\t\t\terror: `Todo ${displayTodoId(id)} lock is stale; rerun in interactive mode to steal it.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst ok = await ctx.ui.confirm(\n\t\t\t\t\"Todo locked\",\n\t\t\t\t`Todo ${displayTodoId(id)} appears locked. Steal the lock?`,\n\t\t\t);\n\t\t\tif (!ok) {\n\t\t\t\treturn { error: `Todo ${displayTodoId(id)} remains locked.` };\n\t\t\t}\n\t\t\tawait fs.unlink(lockPath).catch(() => undefined);\n\t\t}\n\t}\n\n\treturn { error: `Failed to acquire lock for todo ${displayTodoId(id)}.` };\n}\n\nasync function withTodoLock<T>(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n\tfn: () => Promise<T>,\n): Promise<T | { error: string }> {\n\tconst lock = await acquireLock(todosDir, id, ctx);\n\tif (typeof lock === \"object\" && \"error\" in lock) return lock;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\tawait lock();\n\t}\n}\n\nasync function listTodos(todosDir: string): Promise<TodoFrontMatter[]> {\n\tlet entries: string[] = [];\n\ttry {\n\t\tentries = await fs.readdir(todosDir);\n\t} catch {\n\t\treturn [];\n\t}\n\n\tconst todos: TodoFrontMatter[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.endsWith(\".md\")) continue;\n\t\tconst id = entry.slice(0, -3);\n\t\tconst filePath = path.join(todosDir, entry);\n\t\ttry {\n\t\t\tconst content = await fs.readFile(filePath, \"utf8\");\n\t\t\tconst { frontMatter } = splitFrontMatter(content);\n\t\t\tconst parsed = parseFrontMatter(frontMatter, id);\n\t\t\ttodos.push({\n\t\t\t\tid,\n\t\t\t\ttitle: parsed.title,\n\t\t\t\ttags: parsed.tags ?? [],\n\t\t\t\tstatus: parsed.status,\n\t\t\t\tcreated_at: parsed.created_at,\n\t\t\t\tassigned_to_session: parsed.assigned_to_session,\n\t\t\t});\n\t\t} catch {\n\t\t\t// ignore unreadable todo\n\t\t}\n\t}\n\n\treturn sortTodos(todos);\n}\n\nfunction getTodoTitle(todo: TodoFrontMatter): string {\n\treturn todo.title || \"(untitled)\";\n}\n\nfunction getTodoStatus(todo: TodoFrontMatter): string {\n\treturn todo.status || \"open\";\n}\n\nfunction renderAssignmentSuffix(\n\ttheme: Theme,\n\ttodo: TodoFrontMatter,\n\tcurrentSessionId?: string,\n): string {\n\tif (!todo.assigned_to_session) return \"\";\n\tconst isCurrent = todo.assigned_to_session === currentSessionId;\n\tconst color = isCurrent ? \"success\" : \"dim\";\n\tconst suffix = isCurrent ? \", current\" : \"\";\n\treturn theme.fg(color, ` (assigned: ${todo.assigned_to_session}${suffix})`);\n}\n\nfunction splitTodosByAssignment(todos: TodoFrontMatter[]): {\n\tassignedTodos: TodoFrontMatter[];\n\topenTodos: TodoFrontMatter[];\n\tclosedTodos: TodoFrontMatter[];\n} {\n\tconst assignedTodos: TodoFrontMatter[] = [];\n\tconst openTodos: TodoFrontMatter[] = [];\n\tconst closedTodos: TodoFrontMatter[] = [];\n\tfor (const todo of todos) {\n\t\tif (isTodoClosed(getTodoStatus(todo))) {\n\t\t\tclosedTodos.push(todo);\n\t\t\tcontinue;\n\t\t}\n\t\tif (todo.assigned_to_session) {\n\t\t\tassignedTodos.push(todo);\n\t\t} else {\n\t\t\topenTodos.push(todo);\n\t\t}\n\t}\n\treturn { assignedTodos, openTodos, closedTodos };\n}\n\nfunction serializeTodoForAgent(todo: TodoRecord): string {\n\tconst payload = { ...todo, id: formatTodoId(todo.id) };\n\treturn JSON.stringify(payload, null, 2);\n}\n\nfunction serializeTodoListForAgent(todos: TodoFrontMatter[]): string {\n\tconst { assignedTodos, openTodos, closedTodos } = splitTodosByAssignment(todos);\n\tconst mapTodo = (todo: TodoFrontMatter) => ({\n\t\t...todo,\n\t\tid: formatTodoId(todo.id),\n\t});\n\treturn JSON.stringify(\n\t\t{\n\t\t\tassigned: assignedTodos.map(mapTodo),\n\t\t\topen: openTodos.map(mapTodo),\n\t\t\tclosed: closedTodos.map(mapTodo),\n\t\t},\n\t\tnull,\n\t\t2,\n\t);\n}\n\nfunction renderTodoHeading(\n\ttheme: Theme,\n\ttodo: TodoFrontMatter,\n\tcurrentSessionId?: string,\n): string {\n\tconst closed = isTodoClosed(getTodoStatus(todo));\n\tconst titleColor = closed ? \"dim\" : \"text\";\n\tconst tagText = todo.tags.length ? theme.fg(\"dim\", ` [${todo.tags.join(\", \")}]`) : \"\";\n\tconst assignmentText = renderAssignmentSuffix(theme, todo, currentSessionId);\n\treturn (\n\t\ttheme.fg(\"accent\", formatTodoId(todo.id)) +\n\t\t\" \" +\n\t\ttheme.fg(titleColor, getTodoTitle(todo)) +\n\t\ttagText +\n\t\tassignmentText\n\t);\n}\n\nfunction renderTodoList(\n\ttheme: Theme,\n\ttodos: TodoFrontMatter[],\n\texpanded: boolean,\n\tcurrentSessionId?: string,\n): string {\n\tif (!todos.length) return theme.fg(\"dim\", \"No todos\");\n\n\tconst { assignedTodos, openTodos, closedTodos } = splitTodosByAssignment(todos);\n\tconst lines: string[] = [];\n\tconst pushSection = (label: string, sectionTodos: TodoFrontMatter[]) => {\n\t\tlines.push(theme.fg(\"muted\", `${label} (${sectionTodos.length})`));\n\t\tif (!sectionTodos.length) {\n\t\t\tlines.push(theme.fg(\"dim\", \" none\"));\n\t\t\treturn;\n\t\t}\n\t\tconst maxItems = expanded ? sectionTodos.length : Math.min(sectionTodos.length, 3);\n\t\tfor (let i = 0; i < maxItems; i++) {\n\t\t\tlines.push(` ${renderTodoHeading(theme, sectionTodos[i], currentSessionId)}`);\n\t\t}\n\t\tif (!expanded && sectionTodos.length > maxItems) {\n\t\t\tlines.push(theme.fg(\"dim\", ` ... ${sectionTodos.length - maxItems} more`));\n\t\t}\n\t};\n\n\tconst sections: Array<{ label: string; todos: TodoFrontMatter[] }> = [\n\t\t{ label: \"Assigned todos\", todos: assignedTodos },\n\t\t{ label: \"Open todos\", todos: openTodos },\n\t\t{ label: \"Closed todos\", todos: closedTodos },\n\t];\n\n\tsections.forEach((section, index) => {\n\t\tif (index > 0) lines.push(\"\");\n\t\tpushSection(section.label, section.todos);\n\t});\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction renderTodoDetail(theme: Theme, todo: TodoRecord, expanded: boolean): string {\n\tconst summary = renderTodoHeading(theme, todo);\n\tif (!expanded) return summary;\n\n\tconst tags = todo.tags.length ? todo.tags.join(\", \") : \"none\";\n\tconst createdAt = todo.created_at || \"unknown\";\n\tconst bodyText = todo.body?.trim() ? todo.body.trim() : \"No details yet.\";\n\tconst bodyLines = bodyText.split(\"\\n\");\n\n\tconst lines = [\n\t\tsummary,\n\t\ttheme.fg(\"muted\", `Status: ${getTodoStatus(todo)}`),\n\t\ttheme.fg(\"muted\", `Tags: ${tags}`),\n\t\ttheme.fg(\"muted\", `Created: ${createdAt}`),\n\t\t\"\",\n\t\ttheme.fg(\"muted\", \"Body:\"),\n\t\t...bodyLines.map((line) => theme.fg(\"text\", ` ${line}`)),\n\t];\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction appendExpandHint(theme: Theme, text: string): string {\n\treturn `${text}\\n${theme.fg(\"dim\", `(${keyHint(\"app.tools.expand\", \"Expand\")})`)}`;\n}\n\nasync function ensureTodoExists(filePath: string, id: string): Promise<TodoRecord | null> {\n\tif (!existsSync(filePath)) return null;\n\treturn readTodoFile(filePath, id);\n}\n\nasync function appendTodoBody(\n\tfilePath: string,\n\ttodo: TodoRecord,\n\ttext: string,\n): Promise<TodoRecord> {\n\tconst spacer = todo.body.trim().length ? \"\\n\\n\" : \"\";\n\ttodo.body = `${todo.body.replace(/\\s+$/, \"\")}${spacer}${text.trim()}\\n`;\n\tawait writeTodoFile(filePath, todo);\n\treturn todo;\n}\n\nasync function claimTodoAssignment(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n\tforce = false,\n): Promise<TodoRecord | { error: string }> {\n\tconst validated = validateTodoId(id);\n\tif (\"error\" in validated) {\n\t\treturn { error: validated.error };\n\t}\n\tconst normalizedId = validated.id;\n\tconst filePath = getTodoPath(todosDir, normalizedId);\n\tif (!existsSync(filePath)) {\n\t\treturn { error: `Todo ${displayTodoId(id)} not found` };\n\t}\n\tconst sessionId = ctx.sessionManager.getSessionId();\n\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\tif (!existing) return { error: `Todo ${displayTodoId(id)} not found` } as const;\n\t\tif (isTodoClosed(existing.status)) {\n\t\t\treturn { error: `Todo ${displayTodoId(id)} is closed` } as const;\n\t\t}\n\t\tconst assigned = existing.assigned_to_session;\n\t\tif (assigned && assigned !== sessionId && !force) {\n\t\t\treturn {\n\t\t\t\terror: `Todo ${displayTodoId(id)} is already assigned to session ${assigned}. Use force to override.`,\n\t\t\t} as const;\n\t\t}\n\t\tif (assigned !== sessionId) {\n\t\t\texisting.assigned_to_session = sessionId;\n\t\t\tawait writeTodoFile(filePath, existing);\n\t\t}\n\t\treturn existing;\n\t});\n\n\tif (typeof result === \"object\" && \"error\" in result) {\n\t\treturn { error: result.error };\n\t}\n\n\treturn result;\n}\n\nasync function releaseTodoAssignment(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n\tforce = false,\n): Promise<TodoRecord | { error: string }> {\n\tconst validated = validateTodoId(id);\n\tif (\"error\" in validated) {\n\t\treturn { error: validated.error };\n\t}\n\tconst normalizedId = validated.id;\n\tconst filePath = getTodoPath(todosDir, normalizedId);\n\tif (!existsSync(filePath)) {\n\t\treturn { error: `Todo ${displayTodoId(id)} not found` };\n\t}\n\tconst sessionId = ctx.sessionManager.getSessionId();\n\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\tif (!existing) return { error: `Todo ${displayTodoId(id)} not found` } as const;\n\t\tconst assigned = existing.assigned_to_session;\n\t\tif (!assigned) {\n\t\t\treturn existing;\n\t\t}\n\t\tif (assigned !== sessionId && !force) {\n\t\t\treturn {\n\t\t\t\terror: `Todo ${displayTodoId(id)} is assigned to session ${assigned}. Use force to release.`,\n\t\t\t} as const;\n\t\t}\n\t\texisting.assigned_to_session = undefined;\n\t\tawait writeTodoFile(filePath, existing);\n\t\treturn existing;\n\t});\n\n\tif (typeof result === \"object\" && \"error\" in result) {\n\t\treturn { error: result.error };\n\t}\n\n\treturn result;\n}\n\nasync function deleteTodo(\n\ttodosDir: string,\n\tid: string,\n\tctx: ExtensionContext,\n): Promise<TodoRecord | { error: string }> {\n\tconst validated = validateTodoId(id);\n\tif (\"error\" in validated) {\n\t\treturn { error: validated.error };\n\t}\n\tconst normalizedId = validated.id;\n\tconst filePath = getTodoPath(todosDir, normalizedId);\n\tif (!existsSync(filePath)) {\n\t\treturn { error: `Todo ${displayTodoId(id)} not found` };\n\t}\n\n\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\tif (!existing) return { error: `Todo ${displayTodoId(id)} not found` } as const;\n\t\tawait fs.unlink(filePath);\n\t\treturn existing;\n\t});\n\n\tif (typeof result === \"object\" && \"error\" in result) {\n\t\treturn { error: result.error };\n\t}\n\n\treturn result;\n}\n\nexport function createTodoToolDefinition(\n\tcwd: string = process.cwd(),\n): ToolDefinition<typeof TodoParams, TodoToolDetails> {\n\tconst todosDirLabel = getTodosDirLabel(cwd);\n\n\treturn {\n\t\tname: \"todo\",\n\t\tlabel: \"Todo\",\n\t\tdescription:\n\t\t\t`Manage file-based todos in ${todosDirLabel} (list, list-all, get, create, update, append, delete, claim, release). ` +\n\t\t\t\"Title is the short summary; body is long-form markdown notes (update replaces, append adds). \" +\n\t\t\t\"Todo ids are shown as TODO-<hex>; id parameters accept TODO-<hex> or the raw hex filename. \" +\n\t\t\t\"Claim tasks before working on them to avoid conflicts, and close them when complete.\",\n\t\tparameters: TodoParams,\n\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst todosDir = getTodosDir(ctx.cwd);\n\t\t\tconst action: TodoAction = params.action;\n\n\t\t\tswitch (action) {\n\t\t\t\tcase \"list\": {\n\t\t\t\t\tconst todos = await listTodos(todosDir);\n\t\t\t\t\tconst { assignedTodos, openTodos } = splitTodosByAssignment(todos);\n\t\t\t\t\tconst listedTodos = [...assignedTodos, ...openTodos];\n\t\t\t\t\tconst currentSessionId = ctx.sessionManager.getSessionId();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoListForAgent(listedTodos) }],\n\t\t\t\t\t\tdetails: { action: \"list\", todos: listedTodos, currentSessionId },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"list-all\": {\n\t\t\t\t\tconst todos = await listTodos(todosDir);\n\t\t\t\t\tconst currentSessionId = ctx.sessionManager.getSessionId();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoListForAgent(todos) }],\n\t\t\t\t\t\tdetails: { action: \"list-all\", todos, currentSessionId },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"get\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"get\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"get\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst normalizedId = validated.id;\n\t\t\t\t\tconst displayId = formatTodoId(normalizedId);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, normalizedId);\n\t\t\t\t\tconst todo = await ensureTodoExists(filePath, normalizedId);\n\t\t\t\t\tif (!todo) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Todo ${displayId} not found` }],\n\t\t\t\t\t\t\tdetails: { action: \"get\", error: \"not found\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(todo) }],\n\t\t\t\t\t\tdetails: { action: \"get\", todo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"create\": {\n\t\t\t\t\tif (!params.title) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: title required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"create\", error: \"title required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tawait ensureTodosDir(todosDir);\n\t\t\t\t\tconst id = await generateTodoId(todosDir);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, id);\n\t\t\t\t\tconst todo: TodoRecord = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\ttitle: params.title,\n\t\t\t\t\t\ttags: params.tags ?? [],\n\t\t\t\t\t\tstatus: params.status ?? \"open\",\n\t\t\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t\t\t\tbody: params.body ?? \"\",\n\t\t\t\t\t};\n\n\t\t\t\t\tconst result = await withTodoLock(todosDir, id, ctx, async () => {\n\t\t\t\t\t\tawait writeTodoFile(filePath, todo);\n\t\t\t\t\t\treturn todo;\n\t\t\t\t\t});\n\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"create\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(todo) }],\n\t\t\t\t\t\tdetails: { action: \"create\", todo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"update\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst normalizedId = validated.id;\n\t\t\t\t\tconst displayId = formatTodoId(normalizedId);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, normalizedId);\n\t\t\t\t\tif (!existsSync(filePath)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Todo ${displayId} not found` }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: \"not found\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\t\t\t\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\t\t\t\t\tif (!existing) return { error: `Todo ${displayId} not found` } as const;\n\n\t\t\t\t\t\texisting.id = normalizedId;\n\t\t\t\t\t\tif (params.title !== undefined) existing.title = params.title;\n\t\t\t\t\t\tif (params.status !== undefined) existing.status = params.status;\n\t\t\t\t\t\tif (params.tags !== undefined) existing.tags = params.tags;\n\t\t\t\t\t\tif (params.body !== undefined) existing.body = params.body;\n\t\t\t\t\t\tif (!existing.created_at) existing.created_at = new Date().toISOString();\n\t\t\t\t\t\tclearAssignmentIfClosed(existing);\n\n\t\t\t\t\t\tawait writeTodoFile(filePath, existing);\n\t\t\t\t\t\treturn existing;\n\t\t\t\t\t});\n\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"update\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"update\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"append\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst normalizedId = validated.id;\n\t\t\t\t\tconst displayId = formatTodoId(normalizedId);\n\t\t\t\t\tconst filePath = getTodoPath(todosDir, normalizedId);\n\t\t\t\t\tif (!existsSync(filePath)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `Todo ${displayId} not found` }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: \"not found\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await withTodoLock(todosDir, normalizedId, ctx, async () => {\n\t\t\t\t\t\tconst existing = await ensureTodoExists(filePath, normalizedId);\n\t\t\t\t\t\tif (!existing) return { error: `Todo ${displayId} not found` } as const;\n\t\t\t\t\t\tif (!params.body || !params.body.trim()) {\n\t\t\t\t\t\t\treturn existing;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst updated = await appendTodoBody(filePath, existing, params.body);\n\t\t\t\t\t\treturn updated;\n\t\t\t\t\t});\n\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"append\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"append\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"claim\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"claim\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await claimTodoAssignment(\n\t\t\t\t\t\ttodosDir,\n\t\t\t\t\t\tparams.id,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tBoolean(params.force),\n\t\t\t\t\t);\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"claim\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"claim\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"release\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"release\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await releaseTodoAssignment(\n\t\t\t\t\t\ttodosDir,\n\t\t\t\t\t\tparams.id,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tBoolean(params.force),\n\t\t\t\t\t);\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"release\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst updatedTodo = result as TodoRecord;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: serializeTodoForAgent(updatedTodo) }],\n\t\t\t\t\t\tdetails: { action: \"release\", todo: updatedTodo },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tcase \"delete\": {\n\t\t\t\t\tif (!params.id) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Error: id required\" }],\n\t\t\t\t\t\t\tdetails: { action: \"delete\", error: \"id required\" },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst validated = validateTodoId(params.id);\n\t\t\t\t\tif (\"error\" in validated) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: validated.error }],\n\t\t\t\t\t\t\tdetails: { action: \"delete\", error: validated.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await deleteTodo(todosDir, validated.id, ctx);\n\t\t\t\t\tif (typeof result === \"object\" && \"error\" in result) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: result.error }],\n\t\t\t\t\t\t\tdetails: { action: \"delete\", error: result.error },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: serializeTodoForAgent(result as TodoRecord),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { action: \"delete\", todo: result as TodoRecord },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst action = typeof args.action === \"string\" ? args.action : \"\";\n\t\t\tconst id = typeof args.id === \"string\" ? args.id : \"\";\n\t\t\tconst normalizedId = id ? normalizeTodoId(id) : \"\";\n\t\t\tconst title = typeof args.title === \"string\" ? args.title : \"\";\n\t\t\tlet text = theme.fg(\"toolTitle\", theme.bold(\"todo \")) + theme.fg(\"muted\", action);\n\t\t\tif (normalizedId) {\n\t\t\t\ttext += \" \" + theme.fg(\"accent\", formatTodoId(normalizedId));\n\t\t\t}\n\t\t\tif (title) {\n\t\t\t\ttext += \" \" + theme.fg(\"dim\", `\"${title}\"`);\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tconst details = result.details as TodoToolDetails | undefined;\n\t\t\tif (isPartial) {\n\t\t\t\treturn new Text(theme.fg(\"warning\", \"Processing...\"), 0, 0);\n\t\t\t}\n\t\t\tif (!details) {\n\t\t\t\tconst text = result.content[0];\n\t\t\t\treturn new Text(text?.type === \"text\" ? text.text : \"\", 0, 0);\n\t\t\t}\n\n\t\t\tif (details.error) {\n\t\t\t\treturn new Text(theme.fg(\"error\", `Error: ${details.error}`), 0, 0);\n\t\t\t}\n\n\t\t\tif (details.action === \"list\" || details.action === \"list-all\") {\n\t\t\t\tlet text = renderTodoList(theme, details.todos, expanded, details.currentSessionId);\n\t\t\t\tif (!expanded) {\n\t\t\t\t\tconst { closedTodos } = splitTodosByAssignment(details.todos);\n\t\t\t\t\tif (closedTodos.length) {\n\t\t\t\t\t\ttext = appendExpandHint(theme, text);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn new Text(text, 0, 0);\n\t\t\t}\n\n\t\t\tif (!(\"todo\" in details) || !details.todo) {\n\t\t\t\tconst text = result.content[0];\n\t\t\t\treturn new Text(text?.type === \"text\" ? text.text : \"\", 0, 0);\n\t\t\t}\n\n\t\t\tlet text = renderTodoDetail(theme, details.todo, expanded);\n\t\t\tconst actionLabel =\n\t\t\t\tdetails.action === \"create\"\n\t\t\t\t\t? \"Created\"\n\t\t\t\t\t: details.action === \"update\"\n\t\t\t\t\t\t? \"Updated\"\n\t\t\t\t\t\t: details.action === \"append\"\n\t\t\t\t\t\t\t? \"Appended to\"\n\t\t\t\t\t\t\t: details.action === \"delete\"\n\t\t\t\t\t\t\t\t? \"Deleted\"\n\t\t\t\t\t\t\t\t: details.action === \"claim\"\n\t\t\t\t\t\t\t\t\t? \"Claimed\"\n\t\t\t\t\t\t\t\t\t: details.action === \"release\"\n\t\t\t\t\t\t\t\t\t\t? \"Released\"\n\t\t\t\t\t\t\t\t\t\t: null;\n\t\t\tif (actionLabel) {\n\t\t\t\tconst lines = text.split(\"\\n\");\n\t\t\t\tlines[0] = theme.fg(\"success\", \"✓ \") + theme.fg(\"muted\", `${actionLabel} `) + lines[0];\n\t\t\t\ttext = lines.join(\"\\n\");\n\t\t\t}\n\t\t\tif (!expanded) {\n\t\t\t\ttext = appendExpandHint(theme, text);\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n"]}
@@ -468,7 +468,7 @@ function renderTodoDetail(theme, todo, expanded) {
468
468
  return lines.join("\n");
469
469
  }
470
470
  function appendExpandHint(theme, text) {
471
- return `${text}\n${theme.fg("dim", `(${keyHint("app.tools.expand", "to expand")})`)}`;
471
+ return `${text}\n${theme.fg("dim", `(${keyHint("app.tools.expand", "Expand")})`)}`;
472
472
  }
473
473
  async function ensureTodoExists(filePath, id) {
474
474
  if (!existsSync(filePath))