@bastani/atomic 0.8.4 → 0.8.5

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 +12 -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":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAoGA,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAsB5D;AAwQD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n createWriteStream,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { Readable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.js\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n const fileStream = createWriteStream(dest);\n await pipeline(Readable.fromWeb(response.body as any), fileStream);\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAoGA,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAsB5D;AAwQD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n createWriteStream,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { Readable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.js\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n const fileStream = createWriteStream(dest);\n await pipeline(Readable.fromWeb(response.body), fileStream);\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tools-manager.js","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAyB,SAAS,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,GACP,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,IAA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Y,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CACV,sBAAsB,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAC3E,CACF,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n createWriteStream,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { Readable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.js\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n const fileStream = createWriteStream(dest);\n await pipeline(Readable.fromWeb(response.body as any), fileStream);\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
1
+ {"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AAG,MAAM,CAAC,IAAI,yCAAyC,OAAO,EAAE,CACjE,CACF,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,+BAA+B;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,4BAA4B,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CACV,sBAAsB,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAC3E,CACF,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n createWriteStream,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { Readable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.js\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n const fileStream = createWriteStream(dest);\n await pipeline(Readable.fromWeb(response.body), fileStream);\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
@@ -25,14 +25,14 @@ Configure via `package.json`:
25
25
 
26
26
  ```json
27
27
  {
28
- "piConfig": {
28
+ "atomicConfig": {
29
29
  "name": "atomic",
30
30
  "configDir": ".atomic"
31
31
  }
32
32
  }
33
33
  ```
34
34
 
35
- Change `name`, `configDir`, and the `bin` field for your fork. Atomic sets these to `atomic`, `.atomic`, and the `atomic` executable. Affects CLI banner, config paths, and environment variable names.
35
+ Change `name`, `configDir`, and the `bin` field for your fork. The app-specific `<appName>Config` key is preferred; legacy `piConfig` remains a backwards-compatible shim. Atomic sets these to `atomic`, `.atomic`, and the `atomic` executable. Affects CLI banner, config paths, and environment variable names.
36
36
 
37
37
  ## Path Resolution
38
38
 
@@ -255,13 +255,13 @@ This pattern makes the fetched models available during normal startup and to `pi
255
255
  "zod": "^3.0.0",
256
256
  "chalk": "^5.0.0"
257
257
  },
258
- "pi": {
258
+ "atomic": {
259
259
  "extensions": ["./src/index.ts"]
260
260
  }
261
261
  }
262
262
  ```
263
263
 
264
- Run `npm install` in the extension directory, then imports from `node_modules/` work automatically.
264
+ The manifest key is the app name from `package.json` (`atomic` here); the legacy `pi` key is still accepted as a compatibility shim. Run `npm install` in the extension directory, then imports from `node_modules/` work automatically.
265
265
 
266
266
  ## Events
267
267
 
@@ -323,14 +323,14 @@ user sends another prompt ◄─────────────────
323
323
  ├─► session_before_tree (can cancel or customize)
324
324
  └─► session_tree
325
325
 
326
- /model or Ctrl+P (model selection/cycling)
326
+ /model or CTRL+P (model selection/cycling)
327
327
  ├─► thinking_level_select (if model change changes/clamps thinking level)
328
328
  └─► model_select
329
329
 
330
330
  thinking level changes (settings, keybinding, pi.setThinkingLevel())
331
331
  └─► thinking_level_select
332
332
 
333
- exit (Ctrl+C, Ctrl+D, SIGHUP, SIGTERM)
333
+ exit (CTRL+C, CTRL+D, SIGHUP, SIGTERM)
334
334
  └─► session_shutdown
335
335
  ```
336
336
 
@@ -635,7 +635,7 @@ Header availability depends on provider and transport. Providers that abstract H
635
635
 
636
636
  #### model_select
637
637
 
638
- Fired when the model changes via `/model` command, model cycling (`Ctrl+P`), or session restore.
638
+ Fired when the model changes via `/model` command, model cycling (`CTRL+P`), or session restore.
639
639
 
640
640
  ```typescript
641
641
  pi.on("model_select", async (event, ctx) => {
@@ -745,7 +745,7 @@ In parallel tool mode, `tool_result` and `tool_execution_end` may interleave in
745
745
  - Each handler sees the latest result after previous handler changes
746
746
  - Handlers can return partial patches (`content`, `details`, or `isError`); omitted fields keep their current values
747
747
 
748
- Use `ctx.signal` for nested async work inside the handler. This lets Esc cancel model calls, `fetch()`, and other abort-aware operations started by the extension.
748
+ Use `ctx.signal` for nested async work inside the handler. This lets Escape cancel model calls, `fetch()`, and other abort-aware operations started by the extension.
749
749
 
750
750
  ```typescript
751
751
  import { isBashToolResult } from "@bastani/atomic";
@@ -2332,7 +2332,7 @@ For complex UI, use `ctx.ui.custom()`. This temporarily replaces the editor with
2332
2332
  import { Text, Component } from "@earendil-works/pi-tui";
2333
2333
 
2334
2334
  const result = await ctx.ui.custom<boolean>((tui, theme, keybindings, done) => {
2335
- const text = new Text("Press Enter to confirm, Escape to cancel", 1, 1);
2335
+ const text = new Text("Enter Confirm · Escape Cancel", 1, 1);
2336
2336
 
2337
2337
  text.onKey = (key) => {
2338
2338
  if (key === "return") done(true);
package/docs/packages.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Pi Packages
4
4
 
5
- Pi packages bundle extensions, skills, prompt templates, and themes so you can share them through npm or git. A package can declare resources in `package.json` under the `pi` key, or use conventional directories.
5
+ Pi packages bundle extensions, skills, prompt templates, themes, and workflow definitions so you can share them through npm or git. A package can declare resources in `package.json` under the `pi` key, or use conventional directories.
6
6
 
7
7
  ## Table of Contents
8
8
 
@@ -110,17 +110,18 @@ Local paths point to files or directories on disk and are added to settings with
110
110
 
111
111
  ## Creating a Pi Package
112
112
 
113
- Add a `pi` manifest to `package.json` or use conventional directories. Include the `pi-package` keyword for discoverability.
113
+ Add an app manifest to `package.json` or use conventional directories. The manifest key is the configured app name (`atomic` here, from `atomicConfig.name`; legacy `piConfig.name` is also read). The legacy `pi` key remains supported as a backwards-compatible shim. Include the `pi-package` keyword for discoverability.
114
114
 
115
115
  ```json
116
116
  {
117
117
  "name": "my-package",
118
118
  "keywords": ["pi-package"],
119
- "pi": {
119
+ "atomic": {
120
120
  "extensions": ["./extensions"],
121
121
  "skills": ["./skills"],
122
122
  "prompts": ["./prompts"],
123
- "themes": ["./themes"]
123
+ "themes": ["./themes"],
124
+ "workflows": ["./workflows"]
124
125
  }
125
126
  }
126
127
  ```
@@ -135,7 +136,7 @@ The [package gallery](https://pi.dev/packages) displays packages tagged with `pi
135
136
  {
136
137
  "name": "my-package",
137
138
  "keywords": ["pi-package"],
138
- "pi": {
139
+ "atomic": {
139
140
  "extensions": ["./extensions"],
140
141
  "video": "https://example.com/demo.mp4",
141
142
  "image": "https://example.com/screenshot.png"
@@ -158,6 +159,7 @@ If no `pi` manifest is present, pi auto-discovers resources from these directori
158
159
  - `skills/` recursively finds `SKILL.md` folders and loads top-level `.md` files as skills
159
160
  - `prompts/` loads `.md` files
160
161
  - `themes/` loads `.json` files
162
+ - `workflows/` loads workflow SDK files (`.ts`, `.js`, `.mjs`, `.cjs`); `workflow/` is also accepted as a singular alias
161
163
 
162
164
  ## Dependencies
163
165
 
@@ -175,7 +177,7 @@ Example:
175
177
  "shitty-extensions": "^1.0.1"
176
178
  },
177
179
  "bundledDependencies": ["shitty-extensions"],
178
- "pi": {
180
+ "atomic": {
179
181
  "extensions": ["extensions", "node_modules/shitty-extensions/extensions"],
180
182
  "skills": ["skills", "node_modules/shitty-extensions/skills"]
181
183
  }
@@ -195,7 +197,8 @@ Filter what a package loads using the object form in settings:
195
197
  "extensions": ["extensions/*.ts", "!extensions/legacy.ts"],
196
198
  "skills": [],
197
199
  "prompts": ["prompts/review.md"],
198
- "themes": ["+themes/legacy.json"]
200
+ "themes": ["+themes/legacy.json"],
201
+ "workflows": ["workflows/*.ts"]
199
202
  }
200
203
  ]
201
204
  }
@@ -212,7 +215,7 @@ Filter what a package loads using the object form in settings:
212
215
 
213
216
  ## Enable and Disable Resources
214
217
 
215
- Use `pi config` to enable or disable extensions, skills, prompt templates, and themes from installed packages and local directories. Works for both global (`~/.pi/agent`) and project (`.pi/`) scopes.
218
+ Use `pi config` to enable or disable extensions, skills, prompt templates, and themes from installed packages and local directories. Works for both global (`~/.pi/agent`) and project (`.pi/`) scopes. Workflow package filters can be configured in settings with `workflows` patterns.
216
219
 
217
220
  ## Scope and Deduplication
218
221
 
@@ -91,7 +91,7 @@ pi @README.md "Summarize this"
91
91
  pi @src/app.ts @src/app.test.ts "Review these together"
92
92
  ```
93
93
 
94
- Images can be pasted with Ctrl+V (Alt+V on Windows) or dragged into supported terminals.
94
+ Images can be pasted with CTRL+V (ALT+V on Windows) or dragged into supported terminals.
95
95
 
96
96
  ### Run shell commands
97
97
 
@@ -105,7 +105,7 @@ The command output is sent to the model. Use `!!command` to run a command withou
105
105
 
106
106
  ### Switch models
107
107
 
108
- Use `/model` or Ctrl+L to choose a model. Use Shift+Tab to cycle thinking level. Use Ctrl+P / Shift+Ctrl+P to cycle through scoped models.
108
+ Use `/model` or CTRL+L to choose a model. Use SHIFT+Tab to cycle thinking level. Use CTRL+P / SHIFT+CTRL+P to cycle through scoped models.
109
109
 
110
110
  ### Continue later
111
111
 
package/docs/rpc.md CHANGED
@@ -1400,7 +1400,7 @@ attachJsonlReader(agent.stdout, (line) => {
1400
1400
  // Send prompt
1401
1401
  agent.stdin.write(JSON.stringify({ type: "prompt", message: "Hello" }) + "\n");
1402
1402
 
1403
- // Abort on Ctrl+C
1403
+ // Abort on CTRL+C
1404
1404
  process.on("SIGINT", () => {
1405
1405
  agent.stdin.write(JSON.stringify({ type: "abort" }) + "\n");
1406
1406
  });
package/docs/sdk.md CHANGED
@@ -338,23 +338,25 @@ const { session } = await createAgentSession({
338
338
  cwd: process.cwd(), // default
339
339
 
340
340
  // Global config directory
341
- agentDir: "~/.pi/agent", // default (expands ~)
341
+ agentDir: "~/.atomic/agent", // default (expands ~)
342
342
  });
343
343
  ```
344
344
 
345
+ Atomic reads primary `.atomic` locations first and legacy `.pi` locations for compatibility when multiple config directories are supported. Passing an explicit `agentDir` makes that directory the user override.
346
+
345
347
  `cwd` is used by `DefaultResourceLoader` for:
346
- - Project extensions (`.pi/extensions/`)
348
+ - Project extensions (`.atomic/extensions/`, then legacy `.pi/extensions/`)
347
349
  - Project skills:
348
- - `.pi/skills/`
350
+ - `.atomic/skills/`, then legacy `.pi/skills/`
349
351
  - `.agents/skills/` in `cwd` and ancestor directories (up to git repo root, or filesystem root when not in a repo)
350
- - Project prompts (`.pi/prompts/`)
352
+ - Project prompts (`.atomic/prompts/`, then legacy `.pi/prompts/`)
351
353
  - Context files (`AGENTS.md` walking up from cwd)
352
354
  - Session directory naming
353
355
 
354
356
  `agentDir` is used by `DefaultResourceLoader` for:
355
357
  - Global extensions (`extensions/`)
356
358
  - Global skills:
357
- - `skills/` under `agentDir` (for example `~/.pi/agent/skills/`)
359
+ - `skills/` under `agentDir` (for example `~/.atomic/agent/skills/`; legacy `~/.pi/agent/skills/` is also considered by default)
358
360
  - `~/.agents/skills/`
359
361
  - Global prompts (`prompts/`)
360
362
  - Global context file (`AGENTS.md`)
@@ -389,7 +391,7 @@ const { session } = await createAgentSession({
389
391
  model: opus,
390
392
  thinkingLevel: "medium", // off, minimal, low, medium, high, xhigh
391
393
 
392
- // Models for cycling (Ctrl+P in interactive mode)
394
+ // Models for cycling (CTRL+P in interactive mode)
393
395
  scopedModels: [
394
396
  { model: opus, thinkingLevel: "high" },
395
397
  { model: haiku, thinkingLevel: "off" },
@@ -418,7 +420,8 @@ API key resolution priority (handled by AuthStorage):
418
420
  ```typescript
419
421
  import { AuthStorage, ModelRegistry } from "@bastani/atomic";
420
422
 
421
- // Default: uses ~/.pi/agent/auth.json and ~/.pi/agent/models.json
423
+ // Default: uses ~/.atomic/agent/auth.json and ~/.atomic/agent/models.json,
424
+ // with legacy ~/.pi/agent/* compatibility reads when available.
422
425
  const authStorage = AuthStorage.create();
423
426
  const modelRegistry = ModelRegistry.create(authStorage);
424
427
 
@@ -548,7 +551,7 @@ If you pass `tools`, include each custom or extension tool name you want enabled
548
551
 
549
552
  ### Extensions
550
553
 
551
- Extensions are loaded by the `ResourceLoader`. `DefaultResourceLoader` discovers extensions from `~/.pi/agent/extensions/`, `.pi/extensions/`, and settings.json extension sources.
554
+ Extensions are loaded by the `ResourceLoader`. `DefaultResourceLoader` discovers extensions from `~/.atomic/agent/extensions/` and `.atomic/extensions/` first, then legacy `~/.pi/agent/extensions/` and `.pi/extensions/`, plus settings.json extension sources.
552
555
 
553
556
  ```typescript
554
557
  import { createAgentSession, DefaultResourceLoader } from "@bastani/atomic";
@@ -805,9 +808,9 @@ const { session } = await createAgentSession({
805
808
 
806
809
  **Project-specific settings:**
807
810
 
808
- Settings load from two locations and merge:
809
- 1. Global: `~/.pi/agent/settings.json`
810
- 2. Project: `<cwd>/.pi/settings.json`
811
+ Settings load from Atomic-first locations and merge:
812
+ 1. Global: `~/.atomic/agent/settings.json`, then legacy `~/.pi/agent/settings.json`
813
+ 2. Project: `<cwd>/.atomic/settings.json`, then legacy `<cwd>/.pi/settings.json`
811
814
 
812
815
  Project overrides global. Nested objects merge keys. Setters modify global settings by default.
813
816
 
@@ -14,7 +14,7 @@ Where `<path>` is the working directory with `/` replaced by `-`.
14
14
 
15
15
  Sessions can be removed by deleting their `.jsonl` files under `~/.pi/agent/sessions/`.
16
16
 
17
- Pi also supports deleting sessions interactively from `/resume` (select a session and press `Ctrl+D`, then confirm). When available, pi uses the `trash` CLI to avoid permanent deletion.
17
+ Pi also supports deleting sessions interactively from `/resume` (select a session and press `CTRL+D`, then confirm). When available, pi uses the `trash` CLI to avoid permanent deletion.
18
18
 
19
19
  ## Session Version
20
20
 
package/docs/sessions.md CHANGED
@@ -40,11 +40,11 @@ For the JSONL file format and SessionManager API, see [Session Format](session-f
40
40
  In the picker you can:
41
41
 
42
42
  - search by typing
43
- - toggle path display with Ctrl+P
44
- - toggle sort mode with Ctrl+S
45
- - filter to named sessions with Ctrl+N
46
- - rename with Ctrl+R
47
- - delete with Ctrl+D, then confirm
43
+ - toggle path display with CTRL+P
44
+ - toggle sort mode with CTRL+S
45
+ - filter to named sessions with CTRL+N
46
+ - rename with CTRL+R
47
+ - delete with CTRL+D, then confirm
48
48
 
49
49
  When available, pi uses the `trash` CLI for deletion instead of permanently removing files.
50
50
 
@@ -82,12 +82,12 @@ Example shape:
82
82
  |-----|--------|
83
83
  | ↑/↓ | Navigate visible entries |
84
84
  | ←/→ | Page up/down |
85
- | Ctrl+←/Ctrl+→ or Alt+←/Alt+→ | Fold/unfold or jump between branch segments |
86
- | Shift+L | Set or clear a label on the selected entry |
87
- | Shift+T | Toggle label timestamps |
85
+ | CTRL+←/CTRL+→ or ALT+←/ALT+→ | Fold/unfold or jump between branch segments |
86
+ | SHIFT+L | Set or clear a label on the selected entry |
87
+ | SHIFT+T | Toggle label timestamps |
88
88
  | Enter | Select entry |
89
- | Escape/Ctrl+C | Cancel |
90
- | Ctrl+O | Cycle filter mode |
89
+ | Escape/CTRL+C | Cancel |
90
+ | CTRL+O | Cycle filter mode |
91
91
 
92
92
  Filter modes are: default, no-tools, user-only, labeled-only, and all. Configure the default with `treeFilterMode` in [Settings](settings.md).
93
93
 
package/docs/settings.md CHANGED
@@ -173,7 +173,7 @@ When multiple sources specify a session directory, precedence is `--session-dir`
173
173
 
174
174
  | Setting | Type | Default | Description |
175
175
  |---------|------|---------|-------------|
176
- | `enabledModels` | string[] | - | Model patterns for Ctrl+P cycling (same format as `--models` CLI flag) |
176
+ | `enabledModels` | string[] | - | Model patterns for CTRL+P cycling (same format as `--models` CLI flag) |
177
177
 
178
178
  ```json
179
179
  {
@@ -20,11 +20,11 @@ Older Claude Code versions may have added this Ghostty mapping:
20
20
  keybind = shift+enter=text:\n
21
21
  ```
22
22
 
23
- That mapping sends a raw linefeed byte. Inside pi, that is indistinguishable from `Ctrl+J`, so tmux and pi no longer see a real `shift+enter` key event.
23
+ That mapping sends a raw linefeed byte. Inside pi, that is indistinguishable from `CTRL+J`, so tmux and pi no longer see a real `shift+enter` key event.
24
24
 
25
25
  If Claude Code 2.x or newer is the only reason you added that mapping, you can remove it, unless you want to use Claude Code in tmux, where it still requires that Ghostty mapping.
26
26
 
27
- If you want `Shift+Enter` to keep working in tmux via that remap, add `ctrl+j` to your pi `newLine` keybinding in `~/.pi/agent/keybindings.json`:
27
+ If you want `SHIFT+Enter` to keep working in tmux via that remap, add `ctrl+j` to your pi `newLine` keybinding in `~/.pi/agent/keybindings.json`:
28
28
 
29
29
  ```json
30
30
  {
@@ -50,7 +50,7 @@ return config
50
50
  - Linux: `~/.config/Code/User/keybindings.json`
51
51
  - Windows: `%APPDATA%\\Code\\User\\keybindings.json`
52
52
 
53
- Add to `keybindings.json` to enable `Shift+Enter` for multi-line input:
53
+ Add to `keybindings.json` to enable `SHIFT+Enter` for multi-line input:
54
54
 
55
55
  ```json
56
56
  {
@@ -63,7 +63,7 @@ Add to `keybindings.json` to enable `Shift+Enter` for multi-line input:
63
63
 
64
64
  ## Windows Terminal
65
65
 
66
- Add to `settings.json` (Ctrl+Shift+, or Settings → Open JSON file) to forward the modified Enter keys pi uses:
66
+ Add to `settings.json` (CTRL+SHIFT+, or Settings → Open JSON file) to forward the modified Enter keys pi uses:
67
67
 
68
68
  ```json
69
69
  {
@@ -80,15 +80,15 @@ Add to `settings.json` (Ctrl+Shift+, or Settings → Open JSON file) to forward
80
80
  }
81
81
  ```
82
82
 
83
- - `Shift+Enter` inserts a new line.
84
- - Windows Terminal binds `Alt+Enter` to fullscreen by default. That prevents pi from receiving `Alt+Enter` for follow-up queueing.
85
- - Remapping `Alt+Enter` to `sendInput` forwards the real key chord to pi instead.
83
+ - `SHIFT+Enter` inserts a new line.
84
+ - Windows Terminal binds `ALT+Enter` to fullscreen by default. That prevents pi from receiving `ALT+Enter` for follow-up queueing.
85
+ - Remapping `ALT+Enter` to `sendInput` forwards the real key chord to pi instead.
86
86
 
87
87
  If you already have an `actions` array, add the objects to it. If the old fullscreen behavior persists, fully close and reopen Windows Terminal.
88
88
 
89
89
  ## xfce4-terminal, terminator
90
90
 
91
- These terminals have limited escape sequence support. Modified Enter keys like `Ctrl+Enter` and `Shift+Enter` cannot be distinguished from plain `Enter`, preventing custom keybindings such as `submit: ["ctrl+enter"]` from working.
91
+ These terminals have limited escape sequence support. Modified Enter keys like `CTRL+Enter` and `SHIFT+Enter` cannot be distinguished from plain `Enter`, preventing custom keybindings such as `submit: ["ctrl+enter"]` from working.
92
92
 
93
93
  For the best experience, use a terminal that supports the Kitty keyboard protocol:
94
94
  - [Kitty](https://sw.kovidgoyal.net/kitty/)
@@ -99,7 +99,7 @@ For the best experience, use a terminal that supports the Kitty keyboard protoco
99
99
 
100
100
  ## IntelliJ IDEA (Integrated Terminal)
101
101
 
102
- The built-in terminal has limited escape sequence support. Shift+Enter cannot be distinguished from Enter in IntelliJ's terminal.
102
+ The built-in terminal has limited escape sequence support. SHIFT+Enter cannot be distinguished from Enter in IntelliJ's terminal.
103
103
 
104
104
  If you want the hardware cursor visible, set `PI_HARDWARE_CURSOR=1` before running pi (disabled by default for compatibility).
105
105
 
package/docs/tmux.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # tmux Setup
2
2
 
3
- Pi works inside tmux, but tmux strips modifier information from certain keys by default. Without configuration, `Shift+Enter` and `Ctrl+Enter` are usually indistinguishable from plain `Enter`.
3
+ Pi works inside tmux, but tmux strips modifier information from certain keys by default. Without configuration, `SHIFT+Enter` and `CTRL+Enter` are usually indistinguishable from plain `Enter`.
4
4
 
5
5
  ## Recommended Configuration
6
6
 
@@ -30,15 +30,15 @@ set -g extended-keys on
30
30
 
31
31
  tmux defaults to `extended-keys-format xterm`. When an application requests extended key reporting, modified keys are forwarded in xterm `modifyOtherKeys` format such as:
32
32
 
33
- - `Ctrl+C` → `\x1b[27;5;99~`
34
- - `Ctrl+D` → `\x1b[27;5;100~`
35
- - `Ctrl+Enter` → `\x1b[27;5;13~`
33
+ - `CTRL+C` → `\x1b[27;5;99~`
34
+ - `CTRL+D` → `\x1b[27;5;100~`
35
+ - `CTRL+Enter` → `\x1b[27;5;13~`
36
36
 
37
37
  With `extended-keys-format csi-u`, the same keys are forwarded as:
38
38
 
39
- - `Ctrl+C` → `\x1b[99;5u`
40
- - `Ctrl+D` → `\x1b[100;5u`
41
- - `Ctrl+Enter` → `\x1b[13;5u`
39
+ - `CTRL+C` → `\x1b[99;5u`
40
+ - `CTRL+D` → `\x1b[100;5u`
41
+ - `CTRL+Enter` → `\x1b[13;5u`
42
42
 
43
43
  Pi supports both formats, but `csi-u` is the recommended tmux setup.
44
44
 
@@ -49,11 +49,11 @@ Without tmux extended keys, modified Enter keys collapse to legacy sequences:
49
49
  | Key | Without extkeys | With `csi-u` |
50
50
  |-----|-----------------|--------------|
51
51
  | Enter | `\r` | `\r` |
52
- | Shift+Enter | `\r` | `\x1b[13;2u` |
53
- | Ctrl+Enter | `\r` | `\x1b[13;5u` |
52
+ | SHIFT+Enter | `\r` | `\x1b[13;2u` |
53
+ | CTRL+Enter | `\r` | `\x1b[13;5u` |
54
54
  | Alt/Option+Enter | `\x1b\r` | `\x1b[13;3u` |
55
55
 
56
- This affects the default keybindings (`Enter` to submit, `Shift+Enter` for newline) and any custom keybindings using modified Enter.
56
+ This affects the default keybindings (`Enter` to submit, `SHIFT+Enter` for newline) and any custom keybindings using modified Enter.
57
57
 
58
58
  ## Requirements
59
59
 
package/docs/tui.md CHANGED
@@ -274,7 +274,7 @@ handleInput(data: string) {
274
274
  } else if (matchesKey(data, Key.escape)) {
275
275
  this.onCancel?.();
276
276
  } else if (matchesKey(data, Key.ctrl("c"))) {
277
- // Ctrl+C
277
+ // CTRL+C
278
278
  }
279
279
  }
280
280
  ```
@@ -624,7 +624,7 @@ pi.registerCommand("pick", {
624
624
  container.addChild(selectList);
625
625
 
626
626
  // Help text
627
- container.addChild(new Text(theme.fg("dim", "↑↓ navigateenter selectesc cancel"), 1, 0));
627
+ container.addChild(new Text(theme.fg("dim", "↑↓ NavigateEnter SelectEscape Cancel"), 1, 0));
628
628
 
629
629
  // Bottom border
630
630
  container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));