terminal-pilot 0.0.30 → 0.0.31

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 (328) hide show
  1. package/dist/cli.js +1375 -435
  2. package/dist/cli.js.map +4 -4
  3. package/dist/commands/close-session.js +485 -6
  4. package/dist/commands/close-session.js.map +4 -4
  5. package/dist/commands/create-session.js +485 -6
  6. package/dist/commands/create-session.js.map +4 -4
  7. package/dist/commands/fill.js +485 -6
  8. package/dist/commands/fill.js.map +4 -4
  9. package/dist/commands/get-session.js +485 -6
  10. package/dist/commands/get-session.js.map +4 -4
  11. package/dist/commands/index.js +626 -44
  12. package/dist/commands/index.js.map +4 -4
  13. package/dist/commands/install.js +622 -40
  14. package/dist/commands/install.js.map +4 -4
  15. package/dist/commands/installer.js +68 -17
  16. package/dist/commands/installer.js.map +4 -4
  17. package/dist/commands/list-sessions.js +485 -6
  18. package/dist/commands/list-sessions.js.map +4 -4
  19. package/dist/commands/press-key.js +485 -6
  20. package/dist/commands/press-key.js.map +4 -4
  21. package/dist/commands/read-history.js +485 -6
  22. package/dist/commands/read-history.js.map +4 -4
  23. package/dist/commands/read-screen.js +485 -6
  24. package/dist/commands/read-screen.js.map +4 -4
  25. package/dist/commands/resize.js +485 -6
  26. package/dist/commands/resize.js.map +4 -4
  27. package/dist/commands/screenshot.js +485 -6
  28. package/dist/commands/screenshot.js.map +4 -4
  29. package/dist/commands/send-signal.js +485 -6
  30. package/dist/commands/send-signal.js.map +4 -4
  31. package/dist/commands/type.js +485 -6
  32. package/dist/commands/type.js.map +4 -4
  33. package/dist/commands/uninstall.js +550 -20
  34. package/dist/commands/uninstall.js.map +4 -4
  35. package/dist/commands/wait-for-exit.js +485 -6
  36. package/dist/commands/wait-for-exit.js.map +4 -4
  37. package/dist/commands/wait-for.js +485 -6
  38. package/dist/commands/wait-for.js.map +4 -4
  39. package/dist/testing/cli-repl.js +1375 -435
  40. package/dist/testing/cli-repl.js.map +4 -4
  41. package/dist/testing/qa-cli.js +1385 -445
  42. package/dist/testing/qa-cli.js.map +4 -4
  43. package/node_modules/@poe-code/agent-defs/README.md +35 -0
  44. package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.d.ts +2 -0
  45. package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.js +21 -0
  46. package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.d.ts +2 -0
  47. package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.js +18 -0
  48. package/node_modules/@poe-code/agent-defs/dist/agents/codex.d.ts +2 -0
  49. package/node_modules/@poe-code/agent-defs/dist/agents/codex.js +25 -0
  50. package/node_modules/@poe-code/agent-defs/dist/agents/cursor.d.ts +2 -0
  51. package/node_modules/@poe-code/agent-defs/dist/agents/cursor.js +15 -0
  52. package/node_modules/@poe-code/agent-defs/dist/agents/gemini-cli.d.ts +2 -0
  53. package/node_modules/@poe-code/agent-defs/dist/agents/gemini-cli.js +16 -0
  54. package/node_modules/@poe-code/agent-defs/dist/agents/goose.d.ts +2 -0
  55. package/node_modules/@poe-code/agent-defs/dist/agents/goose.js +16 -0
  56. package/node_modules/@poe-code/agent-defs/dist/agents/index.d.ts +9 -0
  57. package/node_modules/@poe-code/agent-defs/dist/agents/index.js +9 -0
  58. package/node_modules/@poe-code/agent-defs/dist/agents/kimi.d.ts +2 -0
  59. package/node_modules/@poe-code/agent-defs/dist/agents/kimi.js +16 -0
  60. package/node_modules/@poe-code/agent-defs/dist/agents/opencode.d.ts +2 -0
  61. package/node_modules/@poe-code/agent-defs/dist/agents/opencode.js +20 -0
  62. package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.d.ts +2 -0
  63. package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.js +14 -0
  64. package/node_modules/@poe-code/agent-defs/dist/index.d.ts +5 -0
  65. package/node_modules/@poe-code/agent-defs/dist/index.js +3 -0
  66. package/node_modules/@poe-code/agent-defs/dist/registry.d.ts +3 -0
  67. package/node_modules/@poe-code/agent-defs/dist/registry.js +45 -0
  68. package/node_modules/@poe-code/agent-defs/dist/specifier.d.ts +7 -0
  69. package/node_modules/@poe-code/agent-defs/dist/specifier.js +40 -0
  70. package/node_modules/@poe-code/agent-defs/dist/types.d.ts +28 -0
  71. package/node_modules/@poe-code/agent-defs/dist/types.js +1 -0
  72. package/node_modules/@poe-code/agent-defs/package.json +20 -0
  73. package/node_modules/@poe-code/agent-skill-config/dist/apply.js +2 -1
  74. package/node_modules/@poe-code/agent-skill-config/dist/bridge-active-skills.d.ts +1 -0
  75. package/node_modules/@poe-code/agent-skill-config/dist/bridge-active-skills.js +37 -18
  76. package/node_modules/@poe-code/agent-skill-config/dist/resolve-skill-reference.js +8 -4
  77. package/node_modules/@poe-code/agent-skill-config/package.json +1 -5
  78. package/node_modules/@poe-code/config-mutations/README.md +55 -0
  79. package/node_modules/@poe-code/config-mutations/dist/error-codes.d.ts +1 -0
  80. package/node_modules/@poe-code/config-mutations/dist/error-codes.js +6 -0
  81. package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.d.ts +6 -0
  82. package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +829 -0
  83. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +17 -0
  84. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +64 -0
  85. package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.d.ts +7 -0
  86. package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.js +39 -0
  87. package/node_modules/@poe-code/config-mutations/dist/formats/index.d.ts +13 -0
  88. package/node_modules/@poe-code/config-mutations/dist/formats/index.js +49 -0
  89. package/node_modules/@poe-code/config-mutations/dist/formats/json.d.ts +32 -0
  90. package/node_modules/@poe-code/config-mutations/dist/formats/json.js +171 -0
  91. package/node_modules/@poe-code/config-mutations/dist/formats/object.d.ts +4 -0
  92. package/node_modules/@poe-code/config-mutations/dist/formats/object.js +27 -0
  93. package/node_modules/@poe-code/config-mutations/dist/formats/toml.d.ts +2 -0
  94. package/node_modules/@poe-code/config-mutations/dist/formats/toml.js +75 -0
  95. package/node_modules/@poe-code/config-mutations/dist/formats/yaml.d.ts +2 -0
  96. package/node_modules/@poe-code/config-mutations/dist/formats/yaml.js +76 -0
  97. package/node_modules/@poe-code/config-mutations/dist/fs-utils.d.ts +18 -0
  98. package/node_modules/@poe-code/config-mutations/dist/fs-utils.js +43 -0
  99. package/node_modules/@poe-code/config-mutations/dist/index.d.ts +8 -0
  100. package/node_modules/@poe-code/config-mutations/dist/index.js +8 -0
  101. package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.d.ts +47 -0
  102. package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.js +34 -0
  103. package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.d.ts +62 -0
  104. package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.js +55 -0
  105. package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.d.ts +40 -0
  106. package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.js +32 -0
  107. package/node_modules/@poe-code/config-mutations/dist/template/render.d.ts +6 -0
  108. package/node_modules/@poe-code/config-mutations/dist/template/render.js +8 -0
  109. package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.d.ts +7 -0
  110. package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.js +21 -0
  111. package/node_modules/@poe-code/config-mutations/dist/testing/index.d.ts +3 -0
  112. package/node_modules/@poe-code/config-mutations/dist/testing/index.js +2 -0
  113. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +25 -0
  114. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +194 -0
  115. package/node_modules/@poe-code/config-mutations/dist/types.d.ts +168 -0
  116. package/node_modules/@poe-code/config-mutations/dist/types.js +6 -0
  117. package/node_modules/@poe-code/config-mutations/package.json +29 -0
  118. package/node_modules/@poe-code/frontmatter/README.md +35 -0
  119. package/node_modules/@poe-code/frontmatter/dist/fences.d.ts +25 -0
  120. package/node_modules/@poe-code/frontmatter/dist/fences.js +100 -0
  121. package/node_modules/@poe-code/frontmatter/dist/index.d.ts +3 -0
  122. package/node_modules/@poe-code/frontmatter/dist/index.js +3 -0
  123. package/node_modules/@poe-code/frontmatter/dist/parse.d.ts +20 -0
  124. package/node_modules/@poe-code/frontmatter/dist/parse.js +209 -0
  125. package/node_modules/@poe-code/frontmatter/dist/stringify.d.ts +1 -0
  126. package/node_modules/@poe-code/frontmatter/dist/stringify.js +48 -0
  127. package/node_modules/@poe-code/frontmatter/package.json +25 -0
  128. package/node_modules/toolcraft-design/README.md +160 -0
  129. package/node_modules/toolcraft-design/dist/acp/components.d.ts +12 -0
  130. package/node_modules/toolcraft-design/dist/acp/components.js +137 -0
  131. package/node_modules/toolcraft-design/dist/acp/index.d.ts +3 -0
  132. package/node_modules/toolcraft-design/dist/acp/index.js +2 -0
  133. package/node_modules/toolcraft-design/dist/acp/writer.d.ts +13 -0
  134. package/node_modules/toolcraft-design/dist/acp/writer.js +21 -0
  135. package/node_modules/toolcraft-design/dist/components/browser.d.ts +15 -0
  136. package/node_modules/toolcraft-design/dist/components/browser.js +31 -0
  137. package/node_modules/toolcraft-design/dist/components/catalog.d.ts +26 -0
  138. package/node_modules/toolcraft-design/dist/components/catalog.js +95 -0
  139. package/node_modules/toolcraft-design/dist/components/color.d.ts +31 -0
  140. package/node_modules/toolcraft-design/dist/components/color.js +102 -0
  141. package/node_modules/toolcraft-design/dist/components/command-errors.d.ts +16 -0
  142. package/node_modules/toolcraft-design/dist/components/command-errors.js +23 -0
  143. package/node_modules/toolcraft-design/dist/components/detail-card.d.ts +22 -0
  144. package/node_modules/toolcraft-design/dist/components/detail-card.js +45 -0
  145. package/node_modules/toolcraft-design/dist/components/help-formatter-plain.d.ts +5 -0
  146. package/node_modules/toolcraft-design/dist/components/help-formatter-plain.js +132 -0
  147. package/node_modules/toolcraft-design/dist/components/help-formatter.d.ts +33 -0
  148. package/node_modules/toolcraft-design/dist/components/help-formatter.js +213 -0
  149. package/node_modules/toolcraft-design/dist/components/index.d.ts +16 -0
  150. package/node_modules/toolcraft-design/dist/components/index.js +10 -0
  151. package/node_modules/toolcraft-design/dist/components/logger.d.ts +11 -0
  152. package/node_modules/toolcraft-design/dist/components/logger.js +60 -0
  153. package/node_modules/toolcraft-design/dist/components/symbols.d.ts +12 -0
  154. package/node_modules/toolcraft-design/dist/components/symbols.js +71 -0
  155. package/node_modules/toolcraft-design/dist/components/table.d.ts +15 -0
  156. package/node_modules/toolcraft-design/dist/components/table.js +302 -0
  157. package/node_modules/toolcraft-design/dist/components/template.d.ts +10 -0
  158. package/node_modules/toolcraft-design/dist/components/template.js +437 -0
  159. package/node_modules/toolcraft-design/dist/components/text.d.ts +16 -0
  160. package/node_modules/toolcraft-design/dist/components/text.js +145 -0
  161. package/node_modules/toolcraft-design/dist/dashboard/ansi.d.ts +18 -0
  162. package/node_modules/toolcraft-design/dist/dashboard/ansi.js +343 -0
  163. package/node_modules/toolcraft-design/dist/dashboard/buffer.d.ts +25 -0
  164. package/node_modules/toolcraft-design/dist/dashboard/buffer.js +219 -0
  165. package/node_modules/toolcraft-design/dist/dashboard/components/border.d.ts +9 -0
  166. package/node_modules/toolcraft-design/dist/dashboard/components/border.js +123 -0
  167. package/node_modules/toolcraft-design/dist/dashboard/components/footer.d.ts +8 -0
  168. package/node_modules/toolcraft-design/dist/dashboard/components/footer.js +56 -0
  169. package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.d.ts +12 -0
  170. package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.js +268 -0
  171. package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.d.ts +7 -0
  172. package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.js +107 -0
  173. package/node_modules/toolcraft-design/dist/dashboard/dashboard.d.ts +20 -0
  174. package/node_modules/toolcraft-design/dist/dashboard/dashboard.js +167 -0
  175. package/node_modules/toolcraft-design/dist/dashboard/demo.d.ts +13 -0
  176. package/node_modules/toolcraft-design/dist/dashboard/demo.js +145 -0
  177. package/node_modules/toolcraft-design/dist/dashboard/index.d.ts +8 -0
  178. package/node_modules/toolcraft-design/dist/dashboard/index.js +4 -0
  179. package/node_modules/toolcraft-design/dist/dashboard/keymap.d.ts +8 -0
  180. package/node_modules/toolcraft-design/dist/dashboard/keymap.js +233 -0
  181. package/node_modules/toolcraft-design/dist/dashboard/layout.d.ts +25 -0
  182. package/node_modules/toolcraft-design/dist/dashboard/layout.js +79 -0
  183. package/node_modules/toolcraft-design/dist/dashboard/should-use-dashboard.d.ts +10 -0
  184. package/node_modules/toolcraft-design/dist/dashboard/should-use-dashboard.js +7 -0
  185. package/node_modules/toolcraft-design/dist/dashboard/snapshot.d.ts +10 -0
  186. package/node_modules/toolcraft-design/dist/dashboard/snapshot.js +68 -0
  187. package/node_modules/toolcraft-design/dist/dashboard/store.d.ts +8 -0
  188. package/node_modules/toolcraft-design/dist/dashboard/store.js +51 -0
  189. package/node_modules/toolcraft-design/dist/dashboard/terminal-width.d.ts +4 -0
  190. package/node_modules/toolcraft-design/dist/dashboard/terminal-width.js +71 -0
  191. package/node_modules/toolcraft-design/dist/dashboard/terminal.d.ts +37 -0
  192. package/node_modules/toolcraft-design/dist/dashboard/terminal.js +264 -0
  193. package/node_modules/toolcraft-design/dist/dashboard/types.d.ts +38 -0
  194. package/node_modules/toolcraft-design/dist/dashboard/types.js +1 -0
  195. package/node_modules/toolcraft-design/dist/explorer/actions.d.ts +16 -0
  196. package/node_modules/toolcraft-design/dist/explorer/actions.js +39 -0
  197. package/node_modules/toolcraft-design/dist/explorer/demo.d.ts +13 -0
  198. package/node_modules/toolcraft-design/dist/explorer/demo.js +297 -0
  199. package/node_modules/toolcraft-design/dist/explorer/events.d.ts +67 -0
  200. package/node_modules/toolcraft-design/dist/explorer/events.js +1 -0
  201. package/node_modules/toolcraft-design/dist/explorer/filter.d.ts +10 -0
  202. package/node_modules/toolcraft-design/dist/explorer/filter.js +95 -0
  203. package/node_modules/toolcraft-design/dist/explorer/index.d.ts +8 -0
  204. package/node_modules/toolcraft-design/dist/explorer/index.js +8 -0
  205. package/node_modules/toolcraft-design/dist/explorer/jobs.d.ts +7 -0
  206. package/node_modules/toolcraft-design/dist/explorer/jobs.js +59 -0
  207. package/node_modules/toolcraft-design/dist/explorer/keymap.d.ts +21 -0
  208. package/node_modules/toolcraft-design/dist/explorer/keymap.js +376 -0
  209. package/node_modules/toolcraft-design/dist/explorer/layout.d.ts +20 -0
  210. package/node_modules/toolcraft-design/dist/explorer/layout.js +73 -0
  211. package/node_modules/toolcraft-design/dist/explorer/reducer.d.ts +9 -0
  212. package/node_modules/toolcraft-design/dist/explorer/reducer.js +782 -0
  213. package/node_modules/toolcraft-design/dist/explorer/render/detail.d.ts +4 -0
  214. package/node_modules/toolcraft-design/dist/explorer/render/detail.js +97 -0
  215. package/node_modules/toolcraft-design/dist/explorer/render/footer.d.ts +4 -0
  216. package/node_modules/toolcraft-design/dist/explorer/render/footer.js +73 -0
  217. package/node_modules/toolcraft-design/dist/explorer/render/header.d.ts +4 -0
  218. package/node_modules/toolcraft-design/dist/explorer/render/header.js +49 -0
  219. package/node_modules/toolcraft-design/dist/explorer/render/index.d.ts +8 -0
  220. package/node_modules/toolcraft-design/dist/explorer/render/index.js +53 -0
  221. package/node_modules/toolcraft-design/dist/explorer/render/list.d.ts +4 -0
  222. package/node_modules/toolcraft-design/dist/explorer/render/list.js +116 -0
  223. package/node_modules/toolcraft-design/dist/explorer/render/modal.d.ts +3 -0
  224. package/node_modules/toolcraft-design/dist/explorer/render/modal.js +87 -0
  225. package/node_modules/toolcraft-design/dist/explorer/render/test-fixtures.d.ts +8 -0
  226. package/node_modules/toolcraft-design/dist/explorer/render/test-fixtures.js +156 -0
  227. package/node_modules/toolcraft-design/dist/explorer/render/text.d.ts +12 -0
  228. package/node_modules/toolcraft-design/dist/explorer/render/text.js +81 -0
  229. package/node_modules/toolcraft-design/dist/explorer/runtime.d.ts +2 -0
  230. package/node_modules/toolcraft-design/dist/explorer/runtime.js +340 -0
  231. package/node_modules/toolcraft-design/dist/explorer/runtime.test-helpers.d.ts +50 -0
  232. package/node_modules/toolcraft-design/dist/explorer/runtime.test-helpers.js +101 -0
  233. package/node_modules/toolcraft-design/dist/explorer/state.d.ts +137 -0
  234. package/node_modules/toolcraft-design/dist/explorer/state.js +86 -0
  235. package/node_modules/toolcraft-design/dist/explorer/theme.d.ts +27 -0
  236. package/node_modules/toolcraft-design/dist/explorer/theme.js +29 -0
  237. package/node_modules/toolcraft-design/dist/index.d.ts +50 -0
  238. package/node_modules/toolcraft-design/dist/index.js +43 -0
  239. package/node_modules/toolcraft-design/dist/internal/color-support.d.ts +9 -0
  240. package/node_modules/toolcraft-design/dist/internal/color-support.js +12 -0
  241. package/node_modules/toolcraft-design/dist/internal/output-format.d.ts +6 -0
  242. package/node_modules/toolcraft-design/dist/internal/output-format.js +22 -0
  243. package/node_modules/toolcraft-design/dist/internal/strip-ansi.d.ts +1 -0
  244. package/node_modules/toolcraft-design/dist/internal/strip-ansi.js +50 -0
  245. package/node_modules/toolcraft-design/dist/internal/theme-detect.d.ts +12 -0
  246. package/node_modules/toolcraft-design/dist/internal/theme-detect.js +71 -0
  247. package/node_modules/toolcraft-design/dist/internal/theme-state.d.ts +12 -0
  248. package/node_modules/toolcraft-design/dist/internal/theme-state.js +35 -0
  249. package/node_modules/toolcraft-design/dist/prompts/index.d.ts +91 -0
  250. package/node_modules/toolcraft-design/dist/prompts/index.js +137 -0
  251. package/node_modules/toolcraft-design/dist/prompts/interactive/cancel-symbol.d.ts +2 -0
  252. package/node_modules/toolcraft-design/dist/prompts/interactive/cancel-symbol.js +4 -0
  253. package/node_modules/toolcraft-design/dist/prompts/interactive/confirm.d.ts +9 -0
  254. package/node_modules/toolcraft-design/dist/prompts/interactive/confirm.js +47 -0
  255. package/node_modules/toolcraft-design/dist/prompts/interactive/core.d.ts +55 -0
  256. package/node_modules/toolcraft-design/dist/prompts/interactive/core.js +274 -0
  257. package/node_modules/toolcraft-design/dist/prompts/interactive/glyphs.d.ts +20 -0
  258. package/node_modules/toolcraft-design/dist/prompts/interactive/glyphs.js +53 -0
  259. package/node_modules/toolcraft-design/dist/prompts/interactive/index.d.ts +6 -0
  260. package/node_modules/toolcraft-design/dist/prompts/interactive/index.js +6 -0
  261. package/node_modules/toolcraft-design/dist/prompts/interactive/keys.d.ts +2 -0
  262. package/node_modules/toolcraft-design/dist/prompts/interactive/keys.js +28 -0
  263. package/node_modules/toolcraft-design/dist/prompts/interactive/multiselect.d.ts +13 -0
  264. package/node_modules/toolcraft-design/dist/prompts/interactive/multiselect.js +131 -0
  265. package/node_modules/toolcraft-design/dist/prompts/interactive/pagination.d.ts +10 -0
  266. package/node_modules/toolcraft-design/dist/prompts/interactive/pagination.js +52 -0
  267. package/node_modules/toolcraft-design/dist/prompts/interactive/password.d.ts +10 -0
  268. package/node_modules/toolcraft-design/dist/prompts/interactive/password.js +55 -0
  269. package/node_modules/toolcraft-design/dist/prompts/interactive/select.d.ts +18 -0
  270. package/node_modules/toolcraft-design/dist/prompts/interactive/select.js +89 -0
  271. package/node_modules/toolcraft-design/dist/prompts/interactive/test-helpers.d.ts +21 -0
  272. package/node_modules/toolcraft-design/dist/prompts/interactive/test-helpers.js +32 -0
  273. package/node_modules/toolcraft-design/dist/prompts/interactive/text.d.ts +12 -0
  274. package/node_modules/toolcraft-design/dist/prompts/interactive/text.js +60 -0
  275. package/node_modules/toolcraft-design/dist/prompts/interactive/wrap.d.ts +4 -0
  276. package/node_modules/toolcraft-design/dist/prompts/interactive/wrap.js +18 -0
  277. package/node_modules/toolcraft-design/dist/prompts/primitives/cancel.d.ts +2 -0
  278. package/node_modules/toolcraft-design/dist/prompts/primitives/cancel.js +9 -0
  279. package/node_modules/toolcraft-design/dist/prompts/primitives/intro.d.ts +1 -0
  280. package/node_modules/toolcraft-design/dist/prompts/primitives/intro.js +16 -0
  281. package/node_modules/toolcraft-design/dist/prompts/primitives/log.d.ts +18 -0
  282. package/node_modules/toolcraft-design/dist/prompts/primitives/log.js +104 -0
  283. package/node_modules/toolcraft-design/dist/prompts/primitives/note.d.ts +1 -0
  284. package/node_modules/toolcraft-design/dist/prompts/primitives/note.js +39 -0
  285. package/node_modules/toolcraft-design/dist/prompts/primitives/outro.d.ts +1 -0
  286. package/node_modules/toolcraft-design/dist/prompts/primitives/outro.js +16 -0
  287. package/node_modules/toolcraft-design/dist/prompts/primitives/spinner.d.ts +6 -0
  288. package/node_modules/toolcraft-design/dist/prompts/primitives/spinner.js +74 -0
  289. package/node_modules/toolcraft-design/dist/prompts/theme.d.ts +11 -0
  290. package/node_modules/toolcraft-design/dist/prompts/theme.js +15 -0
  291. package/node_modules/toolcraft-design/dist/static/index.d.ts +4 -0
  292. package/node_modules/toolcraft-design/dist/static/index.js +2 -0
  293. package/node_modules/toolcraft-design/dist/static/menu.d.ts +11 -0
  294. package/node_modules/toolcraft-design/dist/static/menu.js +42 -0
  295. package/node_modules/toolcraft-design/dist/static/spinner.d.ts +14 -0
  296. package/node_modules/toolcraft-design/dist/static/spinner.js +52 -0
  297. package/node_modules/toolcraft-design/dist/terminal-markdown/ast.d.ts +92 -0
  298. package/node_modules/toolcraft-design/dist/terminal-markdown/ast.js +1 -0
  299. package/node_modules/toolcraft-design/dist/terminal-markdown/demo-content.d.ts +2 -0
  300. package/node_modules/toolcraft-design/dist/terminal-markdown/demo-content.js +139 -0
  301. package/node_modules/toolcraft-design/dist/terminal-markdown/index.d.ts +6 -0
  302. package/node_modules/toolcraft-design/dist/terminal-markdown/index.js +8 -0
  303. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/block.d.ts +7 -0
  304. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/block.js +1495 -0
  305. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.d.ts +8 -0
  306. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +36 -0
  307. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.d.ts +10 -0
  308. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.js +1190 -0
  309. package/node_modules/toolcraft-design/dist/terminal-markdown/parser.d.ts +5 -0
  310. package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +42 -0
  311. package/node_modules/toolcraft-design/dist/terminal-markdown/renderer.d.ts +6 -0
  312. package/node_modules/toolcraft-design/dist/terminal-markdown/renderer.js +615 -0
  313. package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.d.ts +1 -0
  314. package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.js +27 -0
  315. package/node_modules/toolcraft-design/dist/tokens/brand.d.ts +5 -0
  316. package/node_modules/toolcraft-design/dist/tokens/brand.js +5 -0
  317. package/node_modules/toolcraft-design/dist/tokens/colors.d.ts +37 -0
  318. package/node_modules/toolcraft-design/dist/tokens/colors.js +85 -0
  319. package/node_modules/toolcraft-design/dist/tokens/index.d.ts +6 -0
  320. package/node_modules/toolcraft-design/dist/tokens/index.js +5 -0
  321. package/node_modules/toolcraft-design/dist/tokens/spacing.d.ts +6 -0
  322. package/node_modules/toolcraft-design/dist/tokens/spacing.js +6 -0
  323. package/node_modules/toolcraft-design/dist/tokens/typography.d.ts +7 -0
  324. package/node_modules/toolcraft-design/dist/tokens/typography.js +8 -0
  325. package/node_modules/toolcraft-design/dist/tokens/widths.d.ts +5 -0
  326. package/node_modules/toolcraft-design/dist/tokens/widths.js +5 -0
  327. package/node_modules/toolcraft-design/package.json +44 -0
  328. package/package.json +15 -5
@@ -0,0 +1,12 @@
1
+ export interface ThemeConfig {
2
+ brand: string;
3
+ label: string;
4
+ }
5
+ export declare function configureTheme(patch: {
6
+ brand?: string;
7
+ label?: string;
8
+ }): void;
9
+ export declare function getThemeConfig(): ThemeConfig;
10
+ export declare function getThemeRevision(): number;
11
+ export declare function isThemeBrandConfigured(): boolean;
12
+ export declare function resetTheme(): void;
@@ -0,0 +1,35 @@
1
+ import { brands } from "../tokens/brand.js";
2
+ const defaults = {
3
+ brand: "purple",
4
+ label: "Poe"
5
+ };
6
+ let config = { ...defaults };
7
+ let revision = 0;
8
+ let brandConfigured = false;
9
+ export function configureTheme(patch) {
10
+ if (patch.brand !== undefined && !Object.hasOwn(brands, patch.brand)) {
11
+ throw new Error(`Unknown brand: ${patch.brand}`);
12
+ }
13
+ config = {
14
+ brand: patch.brand ?? config.brand,
15
+ label: patch.label ?? config.label
16
+ };
17
+ if (patch.brand !== undefined) {
18
+ brandConfigured = true;
19
+ }
20
+ revision += 1;
21
+ }
22
+ export function getThemeConfig() {
23
+ return { ...config };
24
+ }
25
+ export function getThemeRevision() {
26
+ return revision;
27
+ }
28
+ export function isThemeBrandConfigured() {
29
+ return brandConfigured;
30
+ }
31
+ export function resetTheme() {
32
+ config = { ...defaults };
33
+ brandConfigured = false;
34
+ revision += 1;
35
+ }
@@ -0,0 +1,91 @@
1
+ import type { CANCEL } from "./interactive/cancel-symbol.js";
2
+ import { type SelectOption } from "./interactive/select.js";
3
+ import { cancel, isCancel } from "./primitives/cancel.js";
4
+ import { intro } from "./primitives/intro.js";
5
+ import { log } from "./primitives/log.js";
6
+ import { note } from "./primitives/note.js";
7
+ import { outro } from "./primitives/outro.js";
8
+ import { spinner } from "./primitives/spinner.js";
9
+ export { isCancel, cancel, log };
10
+ export { intro, outro, note, spinner };
11
+ export declare function introPlain(title: string): void;
12
+ export interface SelectOptions<Value> {
13
+ message: string;
14
+ options: Array<SelectOption<Value>>;
15
+ initialValue?: Value;
16
+ maxItems?: number;
17
+ signal?: AbortSignal;
18
+ input?: NodeJS.ReadableStream;
19
+ output?: NodeJS.WritableStream;
20
+ }
21
+ export declare function select<Value>(opts: SelectOptions<Value>): Promise<Value | typeof CANCEL>;
22
+ export interface MultiselectOptions<Value> {
23
+ message: string;
24
+ options: Array<SelectOption<Value>>;
25
+ initialValues?: Value[];
26
+ required?: boolean;
27
+ maxItems?: number;
28
+ signal?: AbortSignal;
29
+ input?: NodeJS.ReadableStream;
30
+ output?: NodeJS.WritableStream;
31
+ }
32
+ /**
33
+ * Prompts the user to select one or more values from a list.
34
+ *
35
+ * Returns the selected values as an array, or a cancellation symbol if the
36
+ * user cancels. Use `isCancel` to check for cancellation.
37
+ *
38
+ * @example
39
+ * const result = await multiselect({
40
+ * message: "Pick workflows to run",
41
+ * options: [{ label: "Fix Vulnerabilities", value: "fix-vulnerabilities" }],
42
+ * required: true
43
+ * });
44
+ * if (!isCancel(result)) {
45
+ * // result is Value[]
46
+ * }
47
+ */
48
+ export declare function multiselect<Value>(opts: MultiselectOptions<Value>): Promise<Value[] | typeof CANCEL>;
49
+ export interface TextOptions {
50
+ message: string;
51
+ placeholder?: string;
52
+ defaultValue?: string;
53
+ initialValue?: string;
54
+ validate?: (value: string) => string | Error | undefined;
55
+ signal?: AbortSignal;
56
+ input?: NodeJS.ReadableStream;
57
+ output?: NodeJS.WritableStream;
58
+ }
59
+ export declare function text(opts: TextOptions): Promise<string | typeof CANCEL>;
60
+ export interface ConfirmOptions {
61
+ message: string;
62
+ initialValue?: boolean;
63
+ signal?: AbortSignal;
64
+ input?: NodeJS.ReadableStream;
65
+ output?: NodeJS.WritableStream;
66
+ }
67
+ export declare function confirm(opts: ConfirmOptions): Promise<boolean | typeof CANCEL>;
68
+ export declare class PromptCancelledError extends Error {
69
+ constructor(message?: string);
70
+ }
71
+ export declare function confirmOrCancel(opts: ConfirmOptions): Promise<boolean>;
72
+ export interface PasswordOptions {
73
+ message: string;
74
+ validate?: (value: string) => string | Error | undefined;
75
+ signal?: AbortSignal;
76
+ input?: NodeJS.ReadableStream;
77
+ output?: NodeJS.WritableStream;
78
+ }
79
+ export declare function password(opts: PasswordOptions): Promise<string | typeof CANCEL>;
80
+ export type SpinnerOptions = {
81
+ start: (message?: string) => void;
82
+ stop: (message?: string, code?: number) => void;
83
+ message: (message?: string) => void;
84
+ };
85
+ export interface WithSpinnerOptions<T> {
86
+ message: string | (() => string);
87
+ fn: () => Promise<T>;
88
+ stopMessage?: (result: T) => string;
89
+ subtext?: (result: T) => string | undefined;
90
+ }
91
+ export declare function withSpinner<T>(options: WithSpinnerOptions<T>): Promise<T>;
@@ -0,0 +1,137 @@
1
+ import { color } from "../components/color.js";
2
+ import { resolveOutputFormat } from "../internal/output-format.js";
3
+ import { stripAnsi } from "../internal/strip-ansi.js";
4
+ import { confirmPrompt } from "./interactive/confirm.js";
5
+ import { multiselectPrompt } from "./interactive/multiselect.js";
6
+ import { passwordPrompt } from "./interactive/password.js";
7
+ import { selectPrompt } from "./interactive/select.js";
8
+ import { textPrompt } from "./interactive/text.js";
9
+ import { cancel, isCancel } from "./primitives/cancel.js";
10
+ import { intro } from "./primitives/intro.js";
11
+ import { log } from "./primitives/log.js";
12
+ import { note } from "./primitives/note.js";
13
+ import { outro } from "./primitives/outro.js";
14
+ import { spinner } from "./primitives/spinner.js";
15
+ export { isCancel, cancel, log };
16
+ export { intro, outro, note, spinner };
17
+ export function introPlain(title) {
18
+ const format = resolveOutputFormat();
19
+ if (format === "markdown") {
20
+ process.stdout.write(`# ${stripAnsi(title)}\n\n`);
21
+ return;
22
+ }
23
+ if (format === "json") {
24
+ return;
25
+ }
26
+ process.stdout.write(`${color.gray("┌")} ${title}\n`);
27
+ }
28
+ export async function select(opts) {
29
+ return selectPrompt(opts);
30
+ }
31
+ /**
32
+ * Prompts the user to select one or more values from a list.
33
+ *
34
+ * Returns the selected values as an array, or a cancellation symbol if the
35
+ * user cancels. Use `isCancel` to check for cancellation.
36
+ *
37
+ * @example
38
+ * const result = await multiselect({
39
+ * message: "Pick workflows to run",
40
+ * options: [{ label: "Fix Vulnerabilities", value: "fix-vulnerabilities" }],
41
+ * required: true
42
+ * });
43
+ * if (!isCancel(result)) {
44
+ * // result is Value[]
45
+ * }
46
+ */
47
+ export async function multiselect(opts) {
48
+ return multiselectPrompt(opts);
49
+ }
50
+ export async function text(opts) {
51
+ return textPrompt(opts);
52
+ }
53
+ export async function confirm(opts) {
54
+ return confirmPrompt(opts);
55
+ }
56
+ export class PromptCancelledError extends Error {
57
+ constructor(message = "Operation cancelled.") {
58
+ super(message);
59
+ this.name = "PromptCancelledError";
60
+ if (Error.captureStackTrace) {
61
+ Error.captureStackTrace(this, this.constructor);
62
+ }
63
+ }
64
+ }
65
+ export async function confirmOrCancel(opts) {
66
+ const result = await confirm(opts);
67
+ if (isCancel(result)) {
68
+ cancel("Operation cancelled.");
69
+ throw new PromptCancelledError();
70
+ }
71
+ return result === true;
72
+ }
73
+ export async function password(opts) {
74
+ return passwordPrompt(opts);
75
+ }
76
+ function formatElapsed(ms) {
77
+ const totalSeconds = Math.floor(ms / 1000);
78
+ if (totalSeconds < 60) {
79
+ return `${totalSeconds}s`;
80
+ }
81
+ const minutes = Math.floor(totalSeconds / 60);
82
+ const seconds = totalSeconds % 60;
83
+ return `${minutes}m ${seconds}s`;
84
+ }
85
+ export async function withSpinner(options) {
86
+ const { message, fn, stopMessage, subtext } = options;
87
+ const readMessage = () => (typeof message === "function" ? message() : message);
88
+ if (resolveOutputFormat() === "json") {
89
+ const result = await fn();
90
+ const sub = subtext ? subtext(result) : undefined;
91
+ if (sub) {
92
+ process.stdout.write(sub + "\n");
93
+ }
94
+ return result;
95
+ }
96
+ const noSpinner = process.env.POE_NO_SPINNER === "1";
97
+ const isTTY = process.stdout.isTTY;
98
+ if (noSpinner || !isTTY) {
99
+ const result = await fn();
100
+ const msg = stopMessage ? stopMessage(result) : undefined;
101
+ if (msg) {
102
+ process.stdout.write(`${color.green("◆")} ${msg}\n`);
103
+ }
104
+ const sub = subtext ? subtext(result) : undefined;
105
+ if (sub) {
106
+ for (const line of sub.split("\n")) {
107
+ process.stdout.write(`${color.gray("│")} ${line}\n`);
108
+ }
109
+ }
110
+ return result;
111
+ }
112
+ const s = spinner();
113
+ const start = Date.now();
114
+ s.start(readMessage());
115
+ const timer = setInterval(() => {
116
+ s.message(`${readMessage()} [${formatElapsed(Date.now() - start)}]`);
117
+ }, 1000);
118
+ try {
119
+ const result = await fn();
120
+ clearInterval(timer);
121
+ const elapsed = formatElapsed(Date.now() - start);
122
+ const msg = stopMessage ? stopMessage(result) : undefined;
123
+ s.stop(msg ? `${msg} [${elapsed}]` : `Done [${elapsed}]`);
124
+ const sub = subtext ? subtext(result) : undefined;
125
+ if (sub) {
126
+ for (const line of sub.split("\n")) {
127
+ process.stdout.write(`${color.gray("│")} ${line}\n`);
128
+ }
129
+ }
130
+ return result;
131
+ }
132
+ catch (error) {
133
+ clearInterval(timer);
134
+ s.stop("", 1);
135
+ throw error;
136
+ }
137
+ }
@@ -0,0 +1,2 @@
1
+ export declare const CANCEL: unique symbol;
2
+ export declare function isCancel(value: unknown): value is typeof CANCEL;
@@ -0,0 +1,4 @@
1
+ export const CANCEL = Symbol.for("poe.cancel");
2
+ export function isCancel(value) {
3
+ return value === CANCEL;
4
+ }
@@ -0,0 +1,9 @@
1
+ import { CANCEL } from "./cancel-symbol.js";
2
+ export interface ConfirmOptions {
3
+ message: string;
4
+ initialValue?: boolean;
5
+ signal?: AbortSignal;
6
+ input?: NodeJS.ReadableStream;
7
+ output?: NodeJS.WritableStream;
8
+ }
9
+ export declare function confirmPrompt(opts: ConfirmOptions): Promise<boolean | typeof CANCEL>;
@@ -0,0 +1,47 @@
1
+ import { color } from "../../components/color.js";
2
+ import { GLYPHS, symbol, symbolBar } from "./glyphs.js";
3
+ import { Prompt } from "./core.js";
4
+ class ConfirmPrompt extends Prompt {
5
+ constructor(opts) {
6
+ super({
7
+ ...opts,
8
+ initialValue: opts.initialValue ?? true,
9
+ render: (prompt) => renderConfirmPrompt(prompt, opts)
10
+ }, false);
11
+ this.on("confirm", (value) => {
12
+ this.setValue(value);
13
+ this.state = "submit";
14
+ this.emit("finalize");
15
+ this.render();
16
+ this.close();
17
+ });
18
+ this.on("cursor", (action) => {
19
+ if (action === "up" || action === "down" || action === "left" || action === "right") {
20
+ this.setValue(!this.value);
21
+ }
22
+ });
23
+ }
24
+ promptNonTty() {
25
+ if (process.env.POE_NO_PROMPT === "1") {
26
+ return Promise.resolve(this.value ?? true);
27
+ }
28
+ return super.promptNonTty();
29
+ }
30
+ }
31
+ function choices(value) {
32
+ const yes = value ? `${color.green(GLYPHS.radioActive)} ${color.bold("Yes")}` : `${color.dim(GLYPHS.radioInactive)} ${color.dim("Yes")}`;
33
+ const no = value ? `${color.dim(GLYPHS.radioInactive)} ${color.dim("No")}` : `${color.green(GLYPHS.radioActive)} ${color.bold("No")}`;
34
+ return `${yes} ${color.dim("/")} ${no}`;
35
+ }
36
+ function renderConfirmPrompt(prompt, opts) {
37
+ if (prompt.state === "submit") {
38
+ return `${color.gray(GLYPHS.barStart)} ${symbol(prompt.state)} ${opts.message}\n${color.gray(GLYPHS.bar)} ${color.dim(prompt.value ? "Yes" : "No")}\n${color.green(GLYPHS.barEnd)}`;
39
+ }
40
+ if (prompt.state === "cancel") {
41
+ return `${color.gray(GLYPHS.barStart)} ${symbol(prompt.state)} ${opts.message}\n${color.gray(GLYPHS.bar)} ${color.dim.strikethrough(prompt.value ? "Yes" : "No")}\n${color.red(GLYPHS.barEnd)}`;
42
+ }
43
+ return `${color.gray(GLYPHS.barStart)} ${symbol(prompt.state)} ${opts.message}\n${symbolBar(prompt.state)} ${choices(prompt.value)}\n${color.cyan(GLYPHS.barEnd)}`;
44
+ }
45
+ export function confirmPrompt(opts) {
46
+ return new ConfirmPrompt(opts).prompt();
47
+ }
@@ -0,0 +1,55 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { CANCEL } from "./cancel-symbol.js";
3
+ export type PromptStateName = "initial" | "active" | "submit" | "cancel" | "error";
4
+ export interface PromptState<Value> {
5
+ state: PromptStateName;
6
+ value: Value | undefined;
7
+ error: string;
8
+ cursor: number;
9
+ userInput: string;
10
+ }
11
+ export interface PromptOptions<Value> {
12
+ render: (state: Prompt<Value>) => string;
13
+ initialValue?: Value;
14
+ initialUserInput?: string;
15
+ validate?: (value: Value | undefined) => string | Error | undefined;
16
+ signal?: AbortSignal;
17
+ input?: NodeJS.ReadableStream;
18
+ output?: NodeJS.WritableStream;
19
+ }
20
+ type InputStream = NodeJS.ReadableStream & {
21
+ isTTY?: boolean;
22
+ setRawMode?: (enabled: boolean) => void;
23
+ unpipe?: () => void;
24
+ };
25
+ export declare class Prompt<Value> extends EventEmitter {
26
+ state: PromptStateName;
27
+ value: Value | undefined;
28
+ error: string;
29
+ userInput: string;
30
+ protected _cursor: number;
31
+ protected input: InputStream;
32
+ protected output: NodeJS.WritableStream;
33
+ private readonly renderFrame;
34
+ private readonly validate?;
35
+ private readonly signal?;
36
+ private readonly trackValue;
37
+ private previousFrame;
38
+ private readlineInterface?;
39
+ private abortListener?;
40
+ private closed;
41
+ constructor(opts: PromptOptions<Value>, trackValue?: boolean);
42
+ get cursor(): number;
43
+ prompt(): Promise<Value | typeof CANCEL>;
44
+ protected promptNonTty(): Promise<Value | typeof CANCEL>;
45
+ protected readNonTtyLine(): Promise<string>;
46
+ protected setValue(value: Value | undefined): void;
47
+ protected setError(message: string): void;
48
+ protected setUserInput(value: string): void;
49
+ protected clearUserInput(): void;
50
+ private readonly onKeypress;
51
+ private updateTrackedInput;
52
+ protected readonly render: () => void;
53
+ protected close(): void;
54
+ }
55
+ export {};
@@ -0,0 +1,274 @@
1
+ import { EventEmitter } from "node:events";
2
+ import * as readline from "node:readline";
3
+ import { CANCEL } from "./cancel-symbol.js";
4
+ import { mapKey } from "./keys.js";
5
+ import { wrapFrame } from "./wrap.js";
6
+ const cursor = {
7
+ hide: "\x1b[?25l",
8
+ show: "\x1b[?25h",
9
+ move: (x, y) => {
10
+ let output = "";
11
+ if (x < 0)
12
+ output += `\x1b[${-x}D`;
13
+ if (x > 0)
14
+ output += `\x1b[${x}C`;
15
+ if (y < 0)
16
+ output += `\x1b[${-y}A`;
17
+ if (y > 0)
18
+ output += `\x1b[${y}B`;
19
+ return output;
20
+ }
21
+ };
22
+ const erase = {
23
+ down: "\x1b[J"
24
+ };
25
+ export class Prompt extends EventEmitter {
26
+ state = "initial";
27
+ value;
28
+ error = "";
29
+ userInput = "";
30
+ _cursor = 0;
31
+ input;
32
+ output;
33
+ renderFrame;
34
+ validate;
35
+ signal;
36
+ trackValue;
37
+ previousFrame = "";
38
+ readlineInterface;
39
+ abortListener;
40
+ closed = false;
41
+ constructor(opts, trackValue = true) {
42
+ super();
43
+ this.input = (opts.input ?? process.stdin);
44
+ this.output = opts.output ?? process.stdout;
45
+ this.renderFrame = opts.render;
46
+ this.validate = opts.validate;
47
+ this.signal = opts.signal;
48
+ this.value = opts.initialValue;
49
+ this.trackValue = trackValue;
50
+ this.userInput = opts.initialUserInput ?? "";
51
+ this._cursor = this.userInput.length;
52
+ }
53
+ get cursor() {
54
+ return this._cursor;
55
+ }
56
+ prompt() {
57
+ if (this.signal?.aborted) {
58
+ this.state = "cancel";
59
+ return Promise.resolve(CANCEL);
60
+ }
61
+ if (this.input.isTTY !== true) {
62
+ return this.promptNonTty();
63
+ }
64
+ return new Promise((resolve) => {
65
+ const onSubmit = (value) => resolve(value);
66
+ const onCancel = () => resolve(CANCEL);
67
+ this.once("submit", onSubmit);
68
+ this.once("cancel", onCancel);
69
+ this.abortListener = () => {
70
+ this.state = "cancel";
71
+ this.emit("finalize");
72
+ this.render();
73
+ this.close();
74
+ };
75
+ this.signal?.addEventListener("abort", this.abortListener, { once: true });
76
+ this.readlineInterface = readline.createInterface({
77
+ input: this.input,
78
+ output: undefined,
79
+ tabSize: 2,
80
+ prompt: "",
81
+ escapeCodeTimeout: 50,
82
+ terminal: true
83
+ });
84
+ readline.emitKeypressEvents(this.input, this.readlineInterface);
85
+ this.readlineInterface.prompt();
86
+ this.input.on("keypress", this.onKeypress);
87
+ if (this.input.setRawMode) {
88
+ this.input.setRawMode(true);
89
+ }
90
+ this.output.on("resize", this.render);
91
+ this.render();
92
+ });
93
+ }
94
+ promptNonTty() {
95
+ return Promise.reject(new Error("Interactive prompt requires a TTY. Set POE_NO_PROMPT=1 to accept defaults non-interactively."));
96
+ }
97
+ readNonTtyLine() {
98
+ return new Promise((resolve) => {
99
+ const rl = readline.createInterface({ input: this.input, terminal: false });
100
+ let settled = false;
101
+ const settle = (value) => {
102
+ if (settled) {
103
+ return;
104
+ }
105
+ settled = true;
106
+ rl.close();
107
+ resolve(value);
108
+ };
109
+ rl.once("line", settle);
110
+ rl.once("close", () => settle(rl.line));
111
+ });
112
+ }
113
+ setValue(value) {
114
+ this.value = value;
115
+ this.emit("value", value);
116
+ }
117
+ setError(message) {
118
+ this.error = message;
119
+ }
120
+ setUserInput(value) {
121
+ this.userInput = value;
122
+ this._cursor = Math.min(this._cursor, this.userInput.length);
123
+ this.emit("userInput", this.userInput);
124
+ }
125
+ clearUserInput() {
126
+ this.userInput = "";
127
+ this._cursor = 0;
128
+ this.emit("userInput", this.userInput);
129
+ }
130
+ onKeypress = (char, key = {}) => {
131
+ let action = mapKey(key.name, char);
132
+ if (this.trackValue && char && char >= " " && key.name !== "return" && key.name !== "enter" && key.name !== "escape") {
133
+ action = undefined;
134
+ }
135
+ if (this.trackValue && action !== "enter") {
136
+ this.updateTrackedInput(char, key, action);
137
+ }
138
+ if (this.state === "error") {
139
+ this.state = "active";
140
+ this.error = "";
141
+ }
142
+ if (!this.trackValue && action) {
143
+ this.emit("cursor", action);
144
+ }
145
+ else if (this.trackValue && action && action !== "enter") {
146
+ this.emit("cursor", action);
147
+ }
148
+ if (char && /^[yn]$/i.test(char)) {
149
+ this.emit("confirm", char.toLowerCase() === "y");
150
+ }
151
+ if (char) {
152
+ this.emit("key", char.toLowerCase(), key);
153
+ }
154
+ if (action === "enter") {
155
+ const error = this.validate?.(this.value);
156
+ if (error) {
157
+ this.error = error instanceof Error ? error.message : error;
158
+ this.state = "error";
159
+ }
160
+ else {
161
+ this.state = "submit";
162
+ }
163
+ }
164
+ if (action === "cancel") {
165
+ this.state = "cancel";
166
+ }
167
+ if (this.state === "submit" || this.state === "cancel") {
168
+ this.emit("finalize");
169
+ }
170
+ this.render();
171
+ if (this.state === "submit" || this.state === "cancel") {
172
+ this.close();
173
+ }
174
+ };
175
+ updateTrackedInput(char, key, action) {
176
+ if (key.ctrl) {
177
+ if (key.name === "a") {
178
+ this._cursor = 0;
179
+ return;
180
+ }
181
+ if (key.name === "e") {
182
+ this._cursor = this.userInput.length;
183
+ return;
184
+ }
185
+ if (key.name === "u") {
186
+ this.userInput = this.userInput.slice(this._cursor);
187
+ this._cursor = 0;
188
+ this.emit("userInput", this.userInput);
189
+ return;
190
+ }
191
+ if (key.name === "k") {
192
+ this.userInput = this.userInput.slice(0, this._cursor);
193
+ this.emit("userInput", this.userInput);
194
+ return;
195
+ }
196
+ }
197
+ if (action === "left") {
198
+ this._cursor = Math.max(0, this._cursor - 1);
199
+ return;
200
+ }
201
+ if (action === "right") {
202
+ this._cursor = Math.min(this.userInput.length, this._cursor + 1);
203
+ return;
204
+ }
205
+ if (action === "cancel" || action === "up" || action === "down" || action === "space") {
206
+ return;
207
+ }
208
+ if (key.name === "backspace" || char === "\b" || char === "\x7f") {
209
+ if (this._cursor > 0) {
210
+ this.userInput = `${this.userInput.slice(0, this._cursor - 1)}${this.userInput.slice(this._cursor)}`;
211
+ this._cursor -= 1;
212
+ this.emit("userInput", this.userInput);
213
+ }
214
+ return;
215
+ }
216
+ if (key.name === "delete") {
217
+ if (this._cursor < this.userInput.length) {
218
+ this.userInput = `${this.userInput.slice(0, this._cursor)}${this.userInput.slice(this._cursor + 1)}`;
219
+ this.emit("userInput", this.userInput);
220
+ }
221
+ return;
222
+ }
223
+ if (!char || char < " " || key.ctrl) {
224
+ return;
225
+ }
226
+ this.userInput = `${this.userInput.slice(0, this._cursor)}${char}${this.userInput.slice(this._cursor)}`;
227
+ this._cursor += char.length;
228
+ this.emit("userInput", this.userInput);
229
+ }
230
+ render = () => {
231
+ if (this.closed) {
232
+ return;
233
+ }
234
+ const frame = wrapFrame(this.output, this.renderFrame(this) ?? "");
235
+ if (frame === this.previousFrame) {
236
+ return;
237
+ }
238
+ if (!this.previousFrame) {
239
+ this.output.write(`${cursor.hide}${frame}`);
240
+ this.previousFrame = frame;
241
+ if (this.state === "initial") {
242
+ this.state = "active";
243
+ }
244
+ return;
245
+ }
246
+ const previousLineCount = this.previousFrame.split("\n").length - 1;
247
+ this.output.write(`${cursor.move(-999, -previousLineCount)}${erase.down}${frame}`);
248
+ this.previousFrame = frame;
249
+ };
250
+ close() {
251
+ if (this.closed) {
252
+ return;
253
+ }
254
+ this.closed = true;
255
+ this.input.removeListener("keypress", this.onKeypress);
256
+ this.output.removeListener("resize", this.render);
257
+ if (this.abortListener) {
258
+ this.signal?.removeEventListener("abort", this.abortListener);
259
+ }
260
+ this.output.write(`${cursor.show}\n`);
261
+ if (!process.platform.startsWith("win") && this.input.setRawMode) {
262
+ this.input.setRawMode(false);
263
+ }
264
+ this.readlineInterface?.close();
265
+ this.input.unpipe?.();
266
+ if (this.state === "cancel") {
267
+ this.emit("cancel");
268
+ }
269
+ else {
270
+ this.emit("submit", this.value);
271
+ }
272
+ this.removeAllListeners();
273
+ }
274
+ }