nastech-tui 0.0.1

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 (424) hide show
  1. package/.prettierrc +11 -0
  2. package/README.md +346 -0
  3. package/eslint.config.mjs +111 -0
  4. package/package.json +51 -0
  5. package/packages/nastech-ink/ambient.d.ts +83 -0
  6. package/packages/nastech-ink/index.d.ts +40 -0
  7. package/packages/nastech-ink/index.js +1 -0
  8. package/packages/nastech-ink/nastech-ink/ambient.d.ts +83 -0
  9. package/packages/nastech-ink/nastech-ink/index.d.ts +40 -0
  10. package/packages/nastech-ink/nastech-ink/index.js +1 -0
  11. package/packages/nastech-ink/nastech-ink/package.json +54 -0
  12. package/packages/nastech-ink/nastech-ink/src/bootstrap/state.ts +9 -0
  13. package/packages/nastech-ink/nastech-ink/src/entry-exports.ts +32 -0
  14. package/packages/nastech-ink/nastech-ink/src/hooks/use-stderr.ts +15 -0
  15. package/packages/nastech-ink/nastech-ink/src/hooks/use-stdout.ts +15 -0
  16. package/packages/nastech-ink/nastech-ink/src/ink/Ansi.tsx +435 -0
  17. package/packages/nastech-ink/nastech-ink/src/ink/app-mouse.test.ts +123 -0
  18. package/packages/nastech-ink/nastech-ink/src/ink/bidi.ts +145 -0
  19. package/packages/nastech-ink/nastech-ink/src/ink/cache-eviction.ts +45 -0
  20. package/packages/nastech-ink/nastech-ink/src/ink/clearTerminal.ts +68 -0
  21. package/packages/nastech-ink/nastech-ink/src/ink/colorize.test.ts +60 -0
  22. package/packages/nastech-ink/nastech-ink/src/ink/colorize.ts +277 -0
  23. package/packages/nastech-ink/nastech-ink/src/ink/components/AlternateScreen.tsx +133 -0
  24. package/packages/nastech-ink/nastech-ink/src/ink/components/App.tsx +830 -0
  25. package/packages/nastech-ink/nastech-ink/src/ink/components/AppContext.ts +20 -0
  26. package/packages/nastech-ink/nastech-ink/src/ink/components/Box.tsx +294 -0
  27. package/packages/nastech-ink/nastech-ink/src/ink/components/Button.tsx +236 -0
  28. package/packages/nastech-ink/nastech-ink/src/ink/components/ClockContext.tsx +133 -0
  29. package/packages/nastech-ink/nastech-ink/src/ink/components/CursorAdvanceContext.ts +35 -0
  30. package/packages/nastech-ink/nastech-ink/src/ink/components/CursorDeclarationContext.ts +28 -0
  31. package/packages/nastech-ink/nastech-ink/src/ink/components/ErrorOverview.tsx +130 -0
  32. package/packages/nastech-ink/nastech-ink/src/ink/components/Link.tsx +38 -0
  33. package/packages/nastech-ink/nastech-ink/src/ink/components/Newline.tsx +43 -0
  34. package/packages/nastech-ink/nastech-ink/src/ink/components/NoSelect.tsx +73 -0
  35. package/packages/nastech-ink/nastech-ink/src/ink/components/RawAnsi.tsx +61 -0
  36. package/packages/nastech-ink/nastech-ink/src/ink/components/ScrollBox.tsx +290 -0
  37. package/packages/nastech-ink/nastech-ink/src/ink/components/Spacer.tsx +23 -0
  38. package/packages/nastech-ink/nastech-ink/src/ink/components/StdinContext.ts +25 -0
  39. package/packages/nastech-ink/nastech-ink/src/ink/components/TerminalFocusContext.tsx +63 -0
  40. package/packages/nastech-ink/nastech-ink/src/ink/components/TerminalSizeContext.tsx +7 -0
  41. package/packages/nastech-ink/nastech-ink/src/ink/components/Text.test.ts +38 -0
  42. package/packages/nastech-ink/nastech-ink/src/ink/components/Text.tsx +336 -0
  43. package/packages/nastech-ink/nastech-ink/src/ink/constants.ts +6 -0
  44. package/packages/nastech-ink/nastech-ink/src/ink/cursor.ts +5 -0
  45. package/packages/nastech-ink/nastech-ink/src/ink/devtools.ts +2 -0
  46. package/packages/nastech-ink/nastech-ink/src/ink/dom.ts +495 -0
  47. package/packages/nastech-ink/nastech-ink/src/ink/events/click-event.ts +38 -0
  48. package/packages/nastech-ink/nastech-ink/src/ink/events/cmd-shortcuts.test.ts +65 -0
  49. package/packages/nastech-ink/nastech-ink/src/ink/events/dispatcher.ts +242 -0
  50. package/packages/nastech-ink/nastech-ink/src/ink/events/emitter.ts +40 -0
  51. package/packages/nastech-ink/nastech-ink/src/ink/events/event-handlers.ts +84 -0
  52. package/packages/nastech-ink/nastech-ink/src/ink/events/event.ts +11 -0
  53. package/packages/nastech-ink/nastech-ink/src/ink/events/focus-event.ts +18 -0
  54. package/packages/nastech-ink/nastech-ink/src/ink/events/input-event.ts +176 -0
  55. package/packages/nastech-ink/nastech-ink/src/ink/events/keyboard-event.ts +57 -0
  56. package/packages/nastech-ink/nastech-ink/src/ink/events/mouse-event.ts +18 -0
  57. package/packages/nastech-ink/nastech-ink/src/ink/events/paste-event.ts +10 -0
  58. package/packages/nastech-ink/nastech-ink/src/ink/events/resize-event.ts +12 -0
  59. package/packages/nastech-ink/nastech-ink/src/ink/events/terminal-event.ts +107 -0
  60. package/packages/nastech-ink/nastech-ink/src/ink/events/terminal-focus-event.ts +19 -0
  61. package/packages/nastech-ink/nastech-ink/src/ink/focus.ts +219 -0
  62. package/packages/nastech-ink/nastech-ink/src/ink/frame.ts +124 -0
  63. package/packages/nastech-ink/nastech-ink/src/ink/get-max-width.ts +27 -0
  64. package/packages/nastech-ink/nastech-ink/src/ink/global.d.ts +1 -0
  65. package/packages/nastech-ink/nastech-ink/src/ink/hit-test.test.ts +38 -0
  66. package/packages/nastech-ink/nastech-ink/src/ink/hit-test.ts +224 -0
  67. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-animation-frame.ts +62 -0
  68. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-app.ts +9 -0
  69. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-cursor-advance.ts +33 -0
  70. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-declared-cursor.ts +75 -0
  71. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-external-process.ts +27 -0
  72. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-input.ts +95 -0
  73. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-interval.ts +71 -0
  74. package/packages/nastech-ink/package.json +57 -0
  75. package/packages/nastech-ink/src/bootstrap/state.ts +9 -0
  76. package/packages/nastech-ink/src/entry-exports.ts +32 -0
  77. package/packages/nastech-ink/src/hooks/use-stderr.ts +15 -0
  78. package/packages/nastech-ink/src/hooks/use-stdout.ts +15 -0
  79. package/packages/nastech-ink/src/ink/Ansi.tsx +435 -0
  80. package/packages/nastech-ink/src/ink/app-mouse.test.ts +123 -0
  81. package/packages/nastech-ink/src/ink/app-rawmode-mouse.test.ts +91 -0
  82. package/packages/nastech-ink/src/ink/bidi.ts +145 -0
  83. package/packages/nastech-ink/src/ink/cache-eviction.ts +45 -0
  84. package/packages/nastech-ink/src/ink/clearTerminal.ts +68 -0
  85. package/packages/nastech-ink/src/ink/colorize.test.ts +60 -0
  86. package/packages/nastech-ink/src/ink/colorize.ts +277 -0
  87. package/packages/nastech-ink/src/ink/components/AlternateScreen.tsx +133 -0
  88. package/packages/nastech-ink/src/ink/components/App.tsx +855 -0
  89. package/packages/nastech-ink/src/ink/components/AppContext.ts +20 -0
  90. package/packages/nastech-ink/src/ink/components/Box.tsx +294 -0
  91. package/packages/nastech-ink/src/ink/components/Button.tsx +236 -0
  92. package/packages/nastech-ink/src/ink/components/ClockContext.tsx +133 -0
  93. package/packages/nastech-ink/src/ink/components/CursorAdvanceContext.ts +35 -0
  94. package/packages/nastech-ink/src/ink/components/CursorDeclarationContext.ts +28 -0
  95. package/packages/nastech-ink/src/ink/components/ErrorOverview.tsx +130 -0
  96. package/packages/nastech-ink/src/ink/components/Link.tsx +38 -0
  97. package/packages/nastech-ink/src/ink/components/Newline.tsx +43 -0
  98. package/packages/nastech-ink/src/ink/components/NoSelect.tsx +73 -0
  99. package/packages/nastech-ink/src/ink/components/RawAnsi.tsx +61 -0
  100. package/packages/nastech-ink/src/ink/components/ScrollBox.tsx +290 -0
  101. package/packages/nastech-ink/src/ink/components/Spacer.tsx +23 -0
  102. package/packages/nastech-ink/src/ink/components/StdinContext.ts +25 -0
  103. package/packages/nastech-ink/src/ink/components/TerminalFocusContext.tsx +63 -0
  104. package/packages/nastech-ink/src/ink/components/TerminalSizeContext.tsx +7 -0
  105. package/packages/nastech-ink/src/ink/components/Text.test.ts +38 -0
  106. package/packages/nastech-ink/src/ink/components/Text.tsx +336 -0
  107. package/packages/nastech-ink/src/ink/constants.ts +6 -0
  108. package/packages/nastech-ink/src/ink/cursor.ts +5 -0
  109. package/packages/nastech-ink/src/ink/devtools.ts +2 -0
  110. package/packages/nastech-ink/src/ink/dom.ts +495 -0
  111. package/packages/nastech-ink/src/ink/events/click-event.ts +38 -0
  112. package/packages/nastech-ink/src/ink/events/cmd-shortcuts.test.ts +65 -0
  113. package/packages/nastech-ink/src/ink/events/dispatcher.ts +242 -0
  114. package/packages/nastech-ink/src/ink/events/emitter.ts +40 -0
  115. package/packages/nastech-ink/src/ink/events/event-handlers.ts +84 -0
  116. package/packages/nastech-ink/src/ink/events/event.ts +11 -0
  117. package/packages/nastech-ink/src/ink/events/focus-event.ts +18 -0
  118. package/packages/nastech-ink/src/ink/events/input-event.ts +176 -0
  119. package/packages/nastech-ink/src/ink/events/keyboard-event.ts +57 -0
  120. package/packages/nastech-ink/src/ink/events/mouse-event.ts +18 -0
  121. package/packages/nastech-ink/src/ink/events/paste-event.ts +10 -0
  122. package/packages/nastech-ink/src/ink/events/resize-event.ts +12 -0
  123. package/packages/nastech-ink/src/ink/events/terminal-event.ts +107 -0
  124. package/packages/nastech-ink/src/ink/events/terminal-focus-event.ts +19 -0
  125. package/packages/nastech-ink/src/ink/focus.ts +219 -0
  126. package/packages/nastech-ink/src/ink/frame.ts +124 -0
  127. package/packages/nastech-ink/src/ink/get-max-width.ts +27 -0
  128. package/packages/nastech-ink/src/ink/global.d.ts +1 -0
  129. package/packages/nastech-ink/src/ink/hit-test.test.ts +38 -0
  130. package/packages/nastech-ink/src/ink/hit-test.ts +224 -0
  131. package/packages/nastech-ink/src/ink/hooks/use-animation-frame.ts +62 -0
  132. package/packages/nastech-ink/src/ink/hooks/use-app.ts +9 -0
  133. package/packages/nastech-ink/src/ink/hooks/use-cursor-advance.ts +33 -0
  134. package/packages/nastech-ink/src/ink/hooks/use-declared-cursor.ts +75 -0
  135. package/packages/nastech-ink/src/ink/hooks/use-external-process.ts +27 -0
  136. package/packages/nastech-ink/src/ink/hooks/use-input.ts +95 -0
  137. package/packages/nastech-ink/src/ink/hooks/use-interval.ts +71 -0
  138. package/packages/nastech-ink/src/ink/hooks/use-search-highlight.ts +56 -0
  139. package/packages/nastech-ink/src/ink/hooks/use-selection.ts +101 -0
  140. package/packages/nastech-ink/src/ink/hooks/use-stdin.ts +9 -0
  141. package/packages/nastech-ink/src/ink/hooks/use-tab-status.ts +71 -0
  142. package/packages/nastech-ink/src/ink/hooks/use-terminal-focus.ts +18 -0
  143. package/packages/nastech-ink/src/ink/hooks/use-terminal-title.ts +34 -0
  144. package/packages/nastech-ink/src/ink/hooks/use-terminal-viewport.ts +100 -0
  145. package/packages/nastech-ink/src/ink/hyperlinkHover.ts +52 -0
  146. package/packages/nastech-ink/src/ink/ink-cursor-advance.test.ts +234 -0
  147. package/packages/nastech-ink/src/ink/ink-resize.test.ts +50 -0
  148. package/packages/nastech-ink/src/ink/ink.tsx +2705 -0
  149. package/packages/nastech-ink/src/ink/instances.ts +10 -0
  150. package/packages/nastech-ink/src/ink/layout/engine.ts +6 -0
  151. package/packages/nastech-ink/src/ink/layout/geometry.ts +98 -0
  152. package/packages/nastech-ink/src/ink/layout/node.ts +145 -0
  153. package/packages/nastech-ink/src/ink/layout/yoga.ts +313 -0
  154. package/packages/nastech-ink/src/ink/line-width-cache.ts +38 -0
  155. package/packages/nastech-ink/src/ink/log-update.test.ts +223 -0
  156. package/packages/nastech-ink/src/ink/log-update.ts +752 -0
  157. package/packages/nastech-ink/src/ink/lru.ts +14 -0
  158. package/packages/nastech-ink/src/ink/measure-element.ts +23 -0
  159. package/packages/nastech-ink/src/ink/measure-text.ts +50 -0
  160. package/packages/nastech-ink/src/ink/node-cache.ts +53 -0
  161. package/packages/nastech-ink/src/ink/optimizer.ts +99 -0
  162. package/packages/nastech-ink/src/ink/output.ts +845 -0
  163. package/packages/nastech-ink/src/ink/parse-keypress.test.ts +133 -0
  164. package/packages/nastech-ink/src/ink/parse-keypress.ts +848 -0
  165. package/packages/nastech-ink/src/ink/reconciler.ts +382 -0
  166. package/packages/nastech-ink/src/ink/render-border.ts +206 -0
  167. package/packages/nastech-ink/src/ink/render-node-to-output.ts +1582 -0
  168. package/packages/nastech-ink/src/ink/render-to-screen.ts +236 -0
  169. package/packages/nastech-ink/src/ink/renderer.ts +169 -0
  170. package/packages/nastech-ink/src/ink/root.ts +204 -0
  171. package/packages/nastech-ink/src/ink/screen.ts +1590 -0
  172. package/packages/nastech-ink/src/ink/searchHighlight.ts +91 -0
  173. package/packages/nastech-ink/src/ink/selection.test.ts +82 -0
  174. package/packages/nastech-ink/src/ink/selection.ts +1143 -0
  175. package/packages/nastech-ink/src/ink/squash-text-nodes.ts +74 -0
  176. package/packages/nastech-ink/src/ink/stringWidth.ts +341 -0
  177. package/packages/nastech-ink/src/ink/styles.ts +750 -0
  178. package/packages/nastech-ink/src/ink/supports-hyperlinks.ts +51 -0
  179. package/packages/nastech-ink/src/ink/tabstops.ts +44 -0
  180. package/packages/nastech-ink/src/ink/terminal-focus-state.ts +52 -0
  181. package/packages/nastech-ink/src/ink/terminal-querier.ts +222 -0
  182. package/packages/nastech-ink/src/ink/terminal.test.ts +15 -0
  183. package/packages/nastech-ink/src/ink/terminal.ts +299 -0
  184. package/packages/nastech-ink/src/ink/termio/ansi.ts +75 -0
  185. package/packages/nastech-ink/src/ink/termio/csi.ts +334 -0
  186. package/packages/nastech-ink/src/ink/termio/dec.ts +99 -0
  187. package/packages/nastech-ink/src/ink/termio/esc.ts +69 -0
  188. package/packages/nastech-ink/src/ink/termio/osc.test.ts +191 -0
  189. package/packages/nastech-ink/src/ink/termio/osc.ts +724 -0
  190. package/packages/nastech-ink/src/ink/termio/parser.ts +467 -0
  191. package/packages/nastech-ink/src/ink/termio/sgr.ts +362 -0
  192. package/packages/nastech-ink/src/ink/termio/tokenize.test.ts +185 -0
  193. package/packages/nastech-ink/src/ink/termio/tokenize.ts +350 -0
  194. package/packages/nastech-ink/src/ink/termio/types.ts +230 -0
  195. package/packages/nastech-ink/src/ink/termio.ts +42 -0
  196. package/packages/nastech-ink/src/ink/useTerminalNotification.ts +110 -0
  197. package/packages/nastech-ink/src/ink/warn.ts +15 -0
  198. package/packages/nastech-ink/src/ink/widest-line.ts +22 -0
  199. package/packages/nastech-ink/src/ink/wrap-text.test.ts +17 -0
  200. package/packages/nastech-ink/src/ink/wrap-text.ts +144 -0
  201. package/packages/nastech-ink/src/ink/wrapAnsi.ts +13 -0
  202. package/packages/nastech-ink/src/native-ts/yoga-layout/enums.ts +112 -0
  203. package/packages/nastech-ink/src/native-ts/yoga-layout/index.ts +2326 -0
  204. package/packages/nastech-ink/src/utils/debug.ts +6 -0
  205. package/packages/nastech-ink/src/utils/earlyInput.ts +131 -0
  206. package/packages/nastech-ink/src/utils/env.ts +66 -0
  207. package/packages/nastech-ink/src/utils/envUtils.ts +13 -0
  208. package/packages/nastech-ink/src/utils/execFileNoThrow.test.ts +146 -0
  209. package/packages/nastech-ink/src/utils/execFileNoThrow.ts +115 -0
  210. package/packages/nastech-ink/src/utils/fullscreen.ts +3 -0
  211. package/packages/nastech-ink/src/utils/intl.ts +87 -0
  212. package/packages/nastech-ink/src/utils/log.ts +7 -0
  213. package/packages/nastech-ink/src/utils/semver.ts +57 -0
  214. package/packages/nastech-ink/src/utils/sliceAnsi.ts +106 -0
  215. package/packages/nastech-ink/text-input.d.ts +2 -0
  216. package/packages/nastech-ink/text-input.js +1 -0
  217. package/scripts/build.mjs +61 -0
  218. package/scripts/profile-tui.mjs +121 -0
  219. package/src/__tests__/activeSessionSwitcher.test.ts +157 -0
  220. package/src/__tests__/appChromeStatusRule.test.tsx +84 -0
  221. package/src/__tests__/appChromeStatusRuleDevCredits.test.tsx +73 -0
  222. package/src/__tests__/approvalAction.test.ts +50 -0
  223. package/src/__tests__/asCommandDispatch.test.ts +27 -0
  224. package/src/__tests__/blockLayout.test.ts +122 -0
  225. package/src/__tests__/clipboard.test.ts +369 -0
  226. package/src/__tests__/constants.test.ts +53 -0
  227. package/src/__tests__/createGatewayEventHandler.test.ts +1091 -0
  228. package/src/__tests__/createSlashHandler.test.ts +822 -0
  229. package/src/__tests__/creditsCommand.test.ts +144 -0
  230. package/src/__tests__/cursorDriftRegression.test.ts +114 -0
  231. package/src/__tests__/details.test.ts +115 -0
  232. package/src/__tests__/emoji.test.ts +64 -0
  233. package/src/__tests__/externalLink.test.ts +144 -0
  234. package/src/__tests__/forceTruecolor.test.ts +191 -0
  235. package/src/__tests__/gatewayClient.test.ts +394 -0
  236. package/src/__tests__/gatewayRecovery.test.ts +47 -0
  237. package/src/__tests__/markdown.test.ts +331 -0
  238. package/src/__tests__/mathUnicode.test.ts +293 -0
  239. package/src/__tests__/memoryMonitor.test.ts +102 -0
  240. package/src/__tests__/messageLine.test.ts +19 -0
  241. package/src/__tests__/messages.test.ts +92 -0
  242. package/src/__tests__/orchestratorPromptSession.test.ts +64 -0
  243. package/src/__tests__/osc52.test.ts +67 -0
  244. package/src/__tests__/parentLog.test.ts +75 -0
  245. package/src/__tests__/paths.test.ts +70 -0
  246. package/src/__tests__/platform.test.ts +556 -0
  247. package/src/__tests__/precisionWheel.test.ts +44 -0
  248. package/src/__tests__/prompt.test.ts +31 -0
  249. package/src/__tests__/providers.test.ts +65 -0
  250. package/src/__tests__/reasoning.test.ts +76 -0
  251. package/src/__tests__/rpc.test.ts +27 -0
  252. package/src/__tests__/scroll.test.ts +99 -0
  253. package/src/__tests__/slashParity.test.ts +123 -0
  254. package/src/__tests__/spawnHistoryStore.test.ts +46 -0
  255. package/src/__tests__/stateIsolation.test.ts +46 -0
  256. package/src/__tests__/statusBarTicker.test.ts +18 -0
  257. package/src/__tests__/statusRule.test.ts +32 -0
  258. package/src/__tests__/streamingMarkdown.test.ts +121 -0
  259. package/src/__tests__/subagentTree.test.ts +407 -0
  260. package/src/__tests__/syntax.test.ts +45 -0
  261. package/src/__tests__/terminalModes.test.ts +39 -0
  262. package/src/__tests__/terminalParity.test.ts +77 -0
  263. package/src/__tests__/terminalSetup.test.ts +386 -0
  264. package/src/__tests__/termux.test.ts +35 -0
  265. package/src/__tests__/termuxComposerLayout.test.ts +40 -0
  266. package/src/__tests__/text.test.ts +233 -0
  267. package/src/__tests__/textInputBurstInput.test.ts +40 -0
  268. package/src/__tests__/textInputCursorSourceOfTruth.test.ts +50 -0
  269. package/src/__tests__/textInputFastEcho.test.ts +200 -0
  270. package/src/__tests__/textInputLineNav.test.ts +55 -0
  271. package/src/__tests__/textInputPassThrough.test.ts +59 -0
  272. package/src/__tests__/textInputRightClick.test.ts +48 -0
  273. package/src/__tests__/textInputWrap.test.ts +151 -0
  274. package/src/__tests__/theme.test.ts +311 -0
  275. package/src/__tests__/turnControllerNotice.test.ts +43 -0
  276. package/src/__tests__/turnStore.test.ts +66 -0
  277. package/src/__tests__/useCompletion.test.ts +35 -0
  278. package/src/__tests__/useComposerState.test.ts +59 -0
  279. package/src/__tests__/useConfigSync.test.ts +460 -0
  280. package/src/__tests__/useInputHandlers.test.ts +77 -0
  281. package/src/__tests__/useQueue.test.ts +28 -0
  282. package/src/__tests__/useSessionLifecycle.test.ts +60 -0
  283. package/src/__tests__/useVirtualHistoryHeights.test.ts +39 -0
  284. package/src/__tests__/viewport.test.ts +58 -0
  285. package/src/__tests__/viewportStore.test.ts +85 -0
  286. package/src/__tests__/virtualHeights.test.ts +96 -0
  287. package/src/__tests__/virtualHistoryClamp.test.ts +19 -0
  288. package/src/__tests__/virtualHistoryOffsetCache.test.ts +282 -0
  289. package/src/__tests__/wheelAccel.test.ts +138 -0
  290. package/src/app/createGatewayEventHandler.ts +833 -0
  291. package/src/app/createSlashHandler.ts +130 -0
  292. package/src/app/delegationStore.ts +77 -0
  293. package/src/app/gatewayContext.tsx +19 -0
  294. package/src/app/gatewayRecovery.ts +35 -0
  295. package/src/app/inputSelectionStore.ts +15 -0
  296. package/src/app/interfaces.ts +394 -0
  297. package/src/app/overlayStore.ts +53 -0
  298. package/src/app/scroll.ts +71 -0
  299. package/src/app/setupHandoff.ts +54 -0
  300. package/src/app/slash/commands/core.ts +648 -0
  301. package/src/app/slash/commands/credits.ts +57 -0
  302. package/src/app/slash/commands/debug.ts +48 -0
  303. package/src/app/slash/commands/ops.ts +717 -0
  304. package/src/app/slash/commands/session.ts +554 -0
  305. package/src/app/slash/commands/setup.ts +20 -0
  306. package/src/app/slash/registry.ts +20 -0
  307. package/src/app/slash/types.ts +21 -0
  308. package/src/app/spawnHistoryStore.ts +159 -0
  309. package/src/app/turnController.ts +866 -0
  310. package/src/app/turnStore.ts +85 -0
  311. package/src/app/uiStore.ts +44 -0
  312. package/src/app/useComposerState.ts +367 -0
  313. package/src/app/useConfigSync.ts +288 -0
  314. package/src/app/useInputHandlers.ts +576 -0
  315. package/src/app/useLongRunToolCharms.ts +69 -0
  316. package/src/app/useMainApp.ts +1039 -0
  317. package/src/app/useSessionLifecycle.ts +366 -0
  318. package/src/app/useSubmission.ts +429 -0
  319. package/src/app.tsx +25 -0
  320. package/src/banner.ts +93 -0
  321. package/src/components/activeSessionSwitcher.tsx +635 -0
  322. package/src/components/agentsOverlay.tsx +1073 -0
  323. package/src/components/appChrome.tsx +554 -0
  324. package/src/components/appLayout.tsx +444 -0
  325. package/src/components/appOverlays.tsx +254 -0
  326. package/src/components/branding.tsx +466 -0
  327. package/src/components/fpsOverlay.tsx +30 -0
  328. package/src/components/helpHint.tsx +73 -0
  329. package/src/components/markdown.tsx +1119 -0
  330. package/src/components/maskedPrompt.tsx +34 -0
  331. package/src/components/messageLine.tsx +237 -0
  332. package/src/components/modelPicker.tsx +527 -0
  333. package/src/components/overlayControls.tsx +50 -0
  334. package/src/components/pluginsHub.tsx +238 -0
  335. package/src/components/prompts.tsx +276 -0
  336. package/src/components/queuedMessages.tsx +64 -0
  337. package/src/components/sessionPicker.tsx +227 -0
  338. package/src/components/skillsHub.tsx +308 -0
  339. package/src/components/streamingAssistant.tsx +110 -0
  340. package/src/components/streamingMarkdown.tsx +174 -0
  341. package/src/components/textInput.tsx +1340 -0
  342. package/src/components/themed.tsx +30 -0
  343. package/src/components/thinking.tsx +1224 -0
  344. package/src/components/todoPanel.tsx +93 -0
  345. package/src/config/env.ts +64 -0
  346. package/src/config/limits.ts +13 -0
  347. package/src/config/timing.ts +6 -0
  348. package/src/content/charms.ts +1 -0
  349. package/src/content/faces.ts +17 -0
  350. package/src/content/fortunes.ts +30 -0
  351. package/src/content/hotkeys.ts +37 -0
  352. package/src/content/placeholders.ts +13 -0
  353. package/src/content/setup.ts +17 -0
  354. package/src/content/verbs.ts +38 -0
  355. package/src/domain/blockLayout.ts +146 -0
  356. package/src/domain/details.ts +76 -0
  357. package/src/domain/messages.ts +91 -0
  358. package/src/domain/paths.ts +16 -0
  359. package/src/domain/providers.ts +11 -0
  360. package/src/domain/roles.ts +9 -0
  361. package/src/domain/slash.ts +10 -0
  362. package/src/domain/usage.ts +3 -0
  363. package/src/domain/viewport.ts +51 -0
  364. package/src/entry.tsx +104 -0
  365. package/src/gatewayClient.ts +730 -0
  366. package/src/gatewayTypes.ts +568 -0
  367. package/src/hooks/useCompletion.ts +112 -0
  368. package/src/hooks/useGitBranch.ts +72 -0
  369. package/src/hooks/useInputHistory.ts +11 -0
  370. package/src/hooks/useQueue.ts +76 -0
  371. package/src/hooks/useVirtualHistory.ts +554 -0
  372. package/src/lib/circularBuffer.ts +48 -0
  373. package/src/lib/clipboard.ts +182 -0
  374. package/src/lib/editor.test.ts +74 -0
  375. package/src/lib/editor.ts +47 -0
  376. package/src/lib/emoji.ts +55 -0
  377. package/src/lib/externalCli.ts +16 -0
  378. package/src/lib/externalLink.ts +435 -0
  379. package/src/lib/forceTruecolor.ts +60 -0
  380. package/src/lib/fpsStore.ts +51 -0
  381. package/src/lib/fuzzy.test.ts +109 -0
  382. package/src/lib/fuzzy.ts +177 -0
  383. package/src/lib/gracefulExit.ts +47 -0
  384. package/src/lib/history.ts +82 -0
  385. package/src/lib/inputMetrics.ts +203 -0
  386. package/src/lib/liveProgress.test.ts +116 -0
  387. package/src/lib/liveProgress.ts +79 -0
  388. package/src/lib/mathUnicode.ts +770 -0
  389. package/src/lib/memory.test.ts +155 -0
  390. package/src/lib/memory.ts +188 -0
  391. package/src/lib/memoryMonitor.ts +109 -0
  392. package/src/lib/messages.test.ts +29 -0
  393. package/src/lib/messages.ts +8 -0
  394. package/src/lib/openExternalUrl.test.ts +217 -0
  395. package/src/lib/openExternalUrl.ts +158 -0
  396. package/src/lib/osc52.ts +73 -0
  397. package/src/lib/parentLog.ts +57 -0
  398. package/src/lib/perfPane.tsx +107 -0
  399. package/src/lib/platform.ts +409 -0
  400. package/src/lib/precisionWheel.ts +48 -0
  401. package/src/lib/prompt.ts +35 -0
  402. package/src/lib/reasoning.ts +55 -0
  403. package/src/lib/rpc.ts +41 -0
  404. package/src/lib/subagentTree.ts +355 -0
  405. package/src/lib/syntax.ts +117 -0
  406. package/src/lib/terminalModes.ts +51 -0
  407. package/src/lib/terminalParity.ts +78 -0
  408. package/src/lib/terminalSetup.ts +444 -0
  409. package/src/lib/termux.ts +29 -0
  410. package/src/lib/text.test.ts +18 -0
  411. package/src/lib/text.ts +339 -0
  412. package/src/lib/todo.test.ts +21 -0
  413. package/src/lib/todo.ts +9 -0
  414. package/src/lib/viewportStore.ts +124 -0
  415. package/src/lib/virtualHeights.ts +145 -0
  416. package/src/lib/wheelAccel.ts +190 -0
  417. package/src/protocol/interpolation.ts +3 -0
  418. package/src/protocol/paste.ts +1 -0
  419. package/src/theme.ts +589 -0
  420. package/src/types/nastech-ink.d.ts +176 -0
  421. package/src/types.ts +212 -0
  422. package/tsconfig.build.json +9 -0
  423. package/tsconfig.json +19 -0
  424. package/vitest.config.ts +7 -0
@@ -0,0 +1,554 @@
1
+ import { attachedImageNotice, introMsg, toTranscriptMessages } from '../../../domain/messages.js'
2
+ import { TUI_SESSION_MODEL_FLAG } from '../../../domain/slash.js'
3
+ import type {
4
+ BackgroundStartResponse,
5
+ ConfigGetValueResponse,
6
+ ConfigSetResponse,
7
+ ImageAttachResponse,
8
+ SessionBranchResponse,
9
+ SessionCompressResponse,
10
+ SessionUsageResponse,
11
+ VoiceToggleResponse
12
+ } from '../../../gatewayTypes.js'
13
+ import { formatVoiceRecordKey, parseVoiceRecordKey } from '../../../lib/platform.js'
14
+ import { fmtK } from '../../../lib/text.js'
15
+ import type { PanelSection } from '../../../types.js'
16
+ import { DEFAULT_INDICATOR_STYLE, INDICATOR_STYLES, type IndicatorStyle } from '../../interfaces.js'
17
+ import { patchOverlayState } from '../../overlayStore.js'
18
+ import { patchUiState } from '../../uiStore.js'
19
+ import type { SlashCommand } from '../types.js'
20
+
21
+ const TUI_SESSION_MODEL_RE = new RegExp(`(?:^|\\s)${TUI_SESSION_MODEL_FLAG}(?:\\s|$)`)
22
+ const TUI_SESSION_STRIP_RE = new RegExp(`\\s*${TUI_SESSION_MODEL_FLAG}\\b\\s*`, 'g')
23
+
24
+ const stripTuiSessionFlag = (trimmed: string) => trimmed.replace(TUI_SESSION_STRIP_RE, ' ').replace(/\s+/g, ' ').trim()
25
+
26
+ const modelValueForConfigSet = (arg: string) => {
27
+ const trimmed = arg.trim()
28
+
29
+ if (!trimmed) {
30
+ return trimmed
31
+ }
32
+
33
+ if (TUI_SESSION_MODEL_RE.test(trimmed)) {
34
+ return stripTuiSessionFlag(trimmed)
35
+ }
36
+
37
+ return trimmed
38
+ }
39
+
40
+ export const sessionCommands: SlashCommand[] = [
41
+ {
42
+ aliases: ['bg', 'btw'],
43
+ help: 'launch a background prompt',
44
+ name: 'background',
45
+ run: (arg, ctx) => {
46
+ if (!arg) {
47
+ return ctx.transcript.sys('/background <prompt>')
48
+ }
49
+
50
+ ctx.gateway.rpc<BackgroundStartResponse>('prompt.background', { session_id: ctx.sid, text: arg }).then(
51
+ ctx.guarded<BackgroundStartResponse>(r => {
52
+ if (!r.task_id) {
53
+ return
54
+ }
55
+
56
+ patchUiState(state => ({ ...state, bgTasks: new Set(state.bgTasks).add(r.task_id!) }))
57
+ ctx.transcript.sys(`bg ${r.task_id} started`)
58
+ })
59
+ )
60
+ }
61
+ },
62
+
63
+ {
64
+ help: 'change or show model',
65
+ name: 'model',
66
+ run: (arg, ctx) => {
67
+ if (ctx.session.guardBusySessionSwitch('change models')) {
68
+ return
69
+ }
70
+
71
+ if (!arg.trim()) {
72
+ return patchOverlayState({ modelPicker: true })
73
+ }
74
+
75
+ ctx.gateway
76
+ .rpc<ConfigSetResponse>('config.set', { key: 'model', session_id: ctx.sid, value: modelValueForConfigSet(arg) })
77
+ .then(
78
+ ctx.guarded<ConfigSetResponse>(r => {
79
+ if (!r.value) {
80
+ return ctx.transcript.sys('error: invalid response: model switch')
81
+ }
82
+
83
+ ctx.transcript.sys(`model → ${r.value}`)
84
+ ctx.local.maybeWarn(r)
85
+
86
+ patchUiState(state => ({
87
+ ...state,
88
+ info: state.info ? { ...state.info, model: r.value! } : { model: r.value!, skills: {}, tools: {} }
89
+ }))
90
+ })
91
+ )
92
+ }
93
+ },
94
+
95
+ {
96
+ aliases: ['switch'],
97
+ help: 'switch between live TUI sessions',
98
+ name: 'sessions',
99
+ run: (arg, ctx) => {
100
+ if (arg.trim().toLowerCase() === 'new') {
101
+ return ctx.session.newLiveSession()
102
+ }
103
+
104
+ patchOverlayState({ sessions: true })
105
+ }
106
+ },
107
+
108
+ {
109
+ help: 'attach an image',
110
+ name: 'image',
111
+ run: (arg, ctx) => {
112
+ ctx.gateway.rpc<ImageAttachResponse>('image.attach', { path: arg, session_id: ctx.sid }).then(
113
+ ctx.guarded<ImageAttachResponse>(r => {
114
+ ctx.transcript.sys(attachedImageNotice(r))
115
+
116
+ if (r.remainder) {
117
+ ctx.composer.setInput(r.remainder)
118
+ }
119
+ })
120
+ )
121
+ }
122
+ },
123
+
124
+ {
125
+ help: 'switch personality for this session',
126
+ name: 'personality',
127
+ run: (arg, ctx) => {
128
+ if (!arg) {
129
+ return
130
+ }
131
+
132
+ ctx.gateway.rpc<ConfigSetResponse>('config.set', { key: 'personality', session_id: ctx.sid, value: arg }).then(
133
+ ctx.guarded<ConfigSetResponse>(r => {
134
+ if (r.history_reset) {
135
+ ctx.session.resetVisibleHistory(r.info ?? null)
136
+ }
137
+
138
+ ctx.transcript.sys(`personality: ${r.value || 'default'}${r.history_reset ? ' · transcript cleared' : ''}`)
139
+ ctx.local.maybeWarn(r)
140
+ })
141
+ )
142
+ }
143
+ },
144
+
145
+ {
146
+ help: 'compress transcript',
147
+ name: 'compress',
148
+ run: (arg, ctx) => {
149
+ ctx.gateway
150
+ .rpc<SessionCompressResponse>('session.compress', {
151
+ session_id: ctx.sid,
152
+ ...(arg ? { focus_topic: arg } : {})
153
+ })
154
+ .then(
155
+ ctx.guarded<SessionCompressResponse>(r => {
156
+ if (Array.isArray(r.messages)) {
157
+ const rows = toTranscriptMessages(r.messages)
158
+
159
+ ctx.transcript.setHistoryItems(r.info ? [introMsg(r.info), ...rows] : rows)
160
+ }
161
+
162
+ if (r.info) {
163
+ patchUiState({ info: r.info })
164
+ }
165
+
166
+ if (r.usage) {
167
+ patchUiState(state => ({ ...state, usage: { ...state.usage, ...r.usage } }))
168
+ }
169
+
170
+ if (r.summary?.headline) {
171
+ const prefix = r.summary.noop ? '' : '✓ '
172
+
173
+ ctx.transcript.sys(`${prefix}${r.summary.headline}`)
174
+
175
+ if (r.summary.token_line) {
176
+ ctx.transcript.sys(` ${r.summary.token_line}`)
177
+ }
178
+
179
+ if (r.summary.note) {
180
+ ctx.transcript.sys(` ${r.summary.note}`)
181
+ }
182
+
183
+ return
184
+ }
185
+
186
+ if ((r.removed ?? 0) <= 0) {
187
+ return ctx.transcript.sys('nothing to compress')
188
+ }
189
+
190
+ ctx.transcript.sys(
191
+ `compressed ${r.removed} messages${r.usage?.total ? ` · ${fmtK(r.usage.total)} tok` : ''}`
192
+ )
193
+ })
194
+ )
195
+ .catch(ctx.guardedErr)
196
+ }
197
+ },
198
+
199
+ {
200
+ aliases: ['fork'],
201
+ help: 'branch the session',
202
+ name: 'branch',
203
+ run: (arg, ctx) => {
204
+ const prevSid = ctx.sid
205
+
206
+ ctx.gateway.rpc<SessionBranchResponse>('session.branch', { name: arg, session_id: ctx.sid }).then(
207
+ ctx.guarded<SessionBranchResponse>(r => {
208
+ if (!r.session_id) {
209
+ return
210
+ }
211
+
212
+ void ctx.session.closeSession(prevSid)
213
+ patchUiState({ sid: r.session_id })
214
+ ctx.session.setSessionStartedAt(Date.now())
215
+ ctx.transcript.sys(`branched → ${r.title ?? ''}`)
216
+ })
217
+ )
218
+ }
219
+ },
220
+
221
+ {
222
+ help: 'voice mode: [on|off|tts|status]',
223
+ name: 'voice',
224
+ run: (arg, ctx) => {
225
+ const normalized = (arg ?? '').trim().toLowerCase()
226
+
227
+ const action =
228
+ normalized === 'on' || normalized === 'off' || normalized === 'tts' || normalized === 'status'
229
+ ? normalized
230
+ : 'status'
231
+
232
+ ctx.gateway.rpc<VoiceToggleResponse>('voice.toggle', { action }).then(
233
+ ctx.guarded<VoiceToggleResponse>(r => {
234
+ ctx.voice.setVoiceEnabled(!!r.enabled)
235
+ ctx.voice.setVoiceTts(!!r.tts)
236
+
237
+ // Render the configured record key (config.yaml ``voice.record_key``)
238
+ // instead of hardcoded "Ctrl+B" — the gateway response carries the
239
+ // current value so /voice status and /voice on stay in sync with
240
+ // both the CLI and the TUI's actual binding (#18994).
241
+ //
242
+ // Copilot review on #19835 caught that rendering from the fresh
243
+ // backend response WITHOUT updating the frontend ``voice.recordKey``
244
+ // state would skew display and binding between config-edit and
245
+ // the next ``mtime`` poll (~5s). Parse once, push into state so
246
+ // ``useInputHandlers()`` picks up the new binding immediately.
247
+ //
248
+ // Round-2 follow-up: only push state when the response actually
249
+ // carries ``record_key`` — otherwise an older gateway (or a future
250
+ // branch that forgets to include it) would clobber a custom user
251
+ // binding back to the default on every /voice invocation. The
252
+ // label still falls back to the documented default for display.
253
+ const parsed = r.record_key ? parseVoiceRecordKey(r.record_key) : undefined
254
+
255
+ if (parsed) {
256
+ ctx.voice.setVoiceRecordKey(parsed)
257
+ }
258
+
259
+ const recordKeyLabel = formatVoiceRecordKey(parsed ?? parseVoiceRecordKey('ctrl+b'))
260
+
261
+ // Match CLI's _show_voice_status / _enable_voice_mode /
262
+ // _toggle_voice_tts output shape so users don't have to learn
263
+ // two vocabularies.
264
+ if (action === 'status') {
265
+ const mode = r.enabled ? 'ON' : 'OFF'
266
+ const tts = r.tts ? 'ON' : 'OFF'
267
+ ctx.transcript.sys('Voice Mode Status')
268
+ ctx.transcript.sys(` Mode: ${mode}`)
269
+ ctx.transcript.sys(` TTS: ${tts}`)
270
+ ctx.transcript.sys(` Record key: ${recordKeyLabel}`)
271
+
272
+ // CLI's "Requirements:" block — surfaces STT/audio setup issues
273
+ // so the user sees "STT provider: MISSING ..." instead of
274
+ // silently failing on every record-key press.
275
+ if (r.details) {
276
+ ctx.transcript.sys('')
277
+ ctx.transcript.sys(' Requirements:')
278
+
279
+ for (const line of r.details.split('\n')) {
280
+ if (line.trim()) {
281
+ ctx.transcript.sys(` ${line}`)
282
+ }
283
+ }
284
+ }
285
+
286
+ return
287
+ }
288
+
289
+ if (action === 'tts') {
290
+ ctx.transcript.sys(`Voice TTS ${r.tts ? 'enabled' : 'disabled'}.`)
291
+
292
+ return
293
+ }
294
+
295
+ // on/off — mirror cli.py:_enable_voice_mode's 3-line output
296
+ if (r.enabled) {
297
+ const tts = r.tts ? ' (TTS enabled)' : ''
298
+ ctx.transcript.sys(`Voice mode enabled${tts}`)
299
+ ctx.transcript.sys(` ${recordKeyLabel} to start/stop recording`)
300
+ ctx.transcript.sys(' /voice tts to toggle speech output')
301
+ ctx.transcript.sys(' /voice off to disable voice mode')
302
+ } else {
303
+ ctx.transcript.sys('Voice mode disabled.')
304
+ }
305
+ })
306
+ )
307
+ }
308
+ },
309
+
310
+ {
311
+ help: 'switch theme skin (fires skin.changed)',
312
+ name: 'skin',
313
+ run: (arg, ctx) => {
314
+ if (!arg) {
315
+ return ctx.gateway
316
+ .rpc<ConfigGetValueResponse>('config.get', { key: 'skin' })
317
+ .then(ctx.guarded<ConfigGetValueResponse>(r => ctx.transcript.sys(`skin: ${r.value || 'default'}`)))
318
+ }
319
+
320
+ ctx.gateway
321
+ .rpc<ConfigSetResponse>('config.set', { key: 'skin', value: arg })
322
+ .then(ctx.guarded<ConfigSetResponse>(r => r.value && ctx.transcript.sys(`skin → ${r.value}`)))
323
+ }
324
+ },
325
+
326
+ {
327
+ help: 'pick the busy indicator: kaomoji (default), emoji, unicode (braille), or ascii',
328
+ name: 'indicator',
329
+ usage: `/indicator [${INDICATOR_STYLES.join('|')}]`,
330
+ run: (arg, ctx) => {
331
+ const value = arg.trim().toLowerCase()
332
+
333
+ if (!value) {
334
+ return ctx.gateway
335
+ .rpc<ConfigGetValueResponse>('config.get', { key: 'indicator' })
336
+ .then(
337
+ ctx.guarded<ConfigGetValueResponse>(r =>
338
+ ctx.transcript.sys(`indicator: ${r.value || DEFAULT_INDICATOR_STYLE}`)
339
+ )
340
+ )
341
+ }
342
+
343
+ if (!(INDICATOR_STYLES as readonly string[]).includes(value)) {
344
+ return ctx.transcript.sys(`usage: /indicator [${INDICATOR_STYLES.join('|')}]`)
345
+ }
346
+
347
+ ctx.gateway.rpc<ConfigSetResponse>('config.set', { key: 'indicator', value }).then(
348
+ ctx.guarded<ConfigSetResponse>(r => {
349
+ if (!r.value) {
350
+ return
351
+ }
352
+
353
+ // Hot-swap the running TUI immediately so the next render
354
+ // uses the new style without waiting for the 5s mtime poll
355
+ // to re-apply config.full.
356
+ patchUiState({ indicatorStyle: value as IndicatorStyle })
357
+ ctx.transcript.sys(`indicator → ${r.value}`)
358
+ })
359
+ )
360
+ }
361
+ },
362
+
363
+ {
364
+ help: 'toggle yolo mode (per-session approvals)',
365
+ name: 'yolo',
366
+ run: (_arg, ctx) => {
367
+ ctx.gateway
368
+ .rpc<ConfigSetResponse>('config.set', { key: 'yolo', session_id: ctx.sid })
369
+ .then(ctx.guarded<ConfigSetResponse>(r => ctx.transcript.sys(`yolo ${r.value === '1' ? 'on' : 'off'}`)))
370
+ }
371
+ },
372
+
373
+ {
374
+ help: 'inspect or set reasoning effort (updates live agent)',
375
+ name: 'reasoning',
376
+ run: (arg, ctx) => {
377
+ if (!arg) {
378
+ return ctx.gateway
379
+ .rpc<ConfigGetValueResponse>('config.get', { key: 'reasoning' })
380
+ .then(
381
+ ctx.guarded<ConfigGetValueResponse>(
382
+ r => r.value && ctx.transcript.sys(`reasoning: ${r.value} · display ${r.display || 'hide'}`)
383
+ )
384
+ )
385
+ }
386
+
387
+ ctx.gateway
388
+ .rpc<ConfigSetResponse>('config.set', { key: 'reasoning', session_id: ctx.sid, value: arg })
389
+ .then(
390
+ ctx.guarded<ConfigSetResponse>(r => {
391
+ if (!r.value) {
392
+ return
393
+ }
394
+
395
+ if (r.value === 'hide') {
396
+ patchUiState(state => ({
397
+ ...state,
398
+ sections: { ...state.sections, thinking: 'hidden' },
399
+ showReasoning: false
400
+ }))
401
+ } else if (r.value === 'show') {
402
+ patchUiState(state => ({
403
+ ...state,
404
+ sections: { ...state.sections, thinking: 'expanded' },
405
+ showReasoning: true
406
+ }))
407
+ }
408
+
409
+ ctx.transcript.sys(`reasoning: ${r.value}`)
410
+ })
411
+ )
412
+ }
413
+ },
414
+
415
+ {
416
+ help: 'toggle fast mode [normal|fast|status|on|off|toggle]',
417
+ name: 'fast',
418
+ run: (arg, ctx) => {
419
+ const mode = arg.trim().toLowerCase()
420
+ const valid = new Set(['', 'status', 'normal', 'fast', 'on', 'off', 'toggle'])
421
+
422
+ if (!valid.has(mode)) {
423
+ return ctx.transcript.sys('usage: /fast [normal|fast|status|on|off|toggle]')
424
+ }
425
+
426
+ if (!mode || mode === 'status') {
427
+ return ctx.gateway
428
+ .rpc<ConfigGetValueResponse>('config.get', { key: 'fast', session_id: ctx.sid })
429
+ .then(
430
+ ctx.guarded<ConfigGetValueResponse>(r =>
431
+ ctx.transcript.sys(`fast mode: ${r.value === 'fast' ? 'fast' : 'normal'}`)
432
+ )
433
+ )
434
+ .catch(ctx.guardedErr)
435
+ }
436
+
437
+ ctx.gateway
438
+ .rpc<ConfigSetResponse>('config.set', { key: 'fast', session_id: ctx.sid, value: mode })
439
+ .then(
440
+ ctx.guarded<ConfigSetResponse>(r => {
441
+ const next = r.value === 'fast' ? 'fast' : 'normal'
442
+ ctx.transcript.sys(`fast mode: ${next}`)
443
+ patchUiState(state => ({
444
+ ...state,
445
+ info: state.info
446
+ ? {
447
+ ...state.info,
448
+ fast: next === 'fast',
449
+ service_tier: next === 'fast' ? 'priority' : ''
450
+ }
451
+ : state.info
452
+ }))
453
+ })
454
+ )
455
+ .catch(ctx.guardedErr)
456
+ }
457
+ },
458
+
459
+ {
460
+ help: 'control busy enter mode [queue|steer|interrupt|status]',
461
+ name: 'busy',
462
+ run: (arg, ctx) => {
463
+ const mode = arg.trim().toLowerCase()
464
+ const valid = new Set(['', 'status', 'queue', 'steer', 'interrupt'])
465
+
466
+ if (!valid.has(mode)) {
467
+ return ctx.transcript.sys('usage: /busy [queue|steer|interrupt|status]')
468
+ }
469
+
470
+ if (!mode || mode === 'status') {
471
+ return ctx.gateway
472
+ .rpc<ConfigGetValueResponse>('config.get', { key: 'busy' })
473
+ .then(
474
+ ctx.guarded<ConfigGetValueResponse>(r => {
475
+ const current = r.value || 'interrupt'
476
+ ctx.transcript.sys(`busy input mode: ${current}`)
477
+ })
478
+ )
479
+ .catch(ctx.guardedErr)
480
+ }
481
+
482
+ ctx.gateway
483
+ .rpc<ConfigSetResponse>('config.set', { key: 'busy', value: mode })
484
+ .then(
485
+ ctx.guarded<ConfigSetResponse>(r => {
486
+ const next = r.value || mode
487
+ ctx.transcript.sys(`busy input mode: ${next}`)
488
+ })
489
+ )
490
+ .catch(ctx.guardedErr)
491
+ }
492
+ },
493
+
494
+ {
495
+ help: 'cycle verbose tool-output mode (updates live agent)',
496
+ name: 'verbose',
497
+ run: (arg, ctx) => {
498
+ ctx.gateway
499
+ .rpc<ConfigSetResponse>('config.set', { key: 'verbose', session_id: ctx.sid, value: arg || 'cycle' })
500
+ .then(ctx.guarded<ConfigSetResponse>(r => r.value && ctx.transcript.sys(`verbose: ${r.value}`)))
501
+ }
502
+ },
503
+
504
+ {
505
+ help: 'session usage (live counts — worker sees zeros)',
506
+ name: 'usage',
507
+ run: (_arg, ctx) => {
508
+ ctx.gateway.rpc<SessionUsageResponse>('session.usage', { session_id: ctx.sid }).then(r => {
509
+ if (ctx.stale()) {
510
+ return
511
+ }
512
+
513
+ if (r) {
514
+ patchUiState({
515
+ usage: { calls: r.calls ?? 0, input: r.input ?? 0, output: r.output ?? 0, total: r.total ?? 0 }
516
+ })
517
+ }
518
+
519
+ if (!r?.calls) {
520
+ return ctx.transcript.sys('no API calls yet')
521
+ }
522
+
523
+ const f = (v: number | undefined) => (v ?? 0).toLocaleString()
524
+ const cost = r.cost_usd != null ? `${r.cost_status === 'estimated' ? '~' : ''}$${r.cost_usd.toFixed(4)}` : null
525
+
526
+ const rows: [string, string][] = [
527
+ ['Model', r.model ?? ''],
528
+ ['Input tokens', f(r.input)],
529
+ ['Cache read tokens', f(r.cache_read)],
530
+ ['Cache write tokens', f(r.cache_write)],
531
+ ['Output tokens', f(r.output)],
532
+ ['Total tokens', f(r.total)],
533
+ ['API calls', f(r.calls)]
534
+ ]
535
+
536
+ if (cost) {
537
+ rows.push(['Cost', cost])
538
+ }
539
+
540
+ const sections: PanelSection[] = [{ rows }]
541
+
542
+ if (r.context_max) {
543
+ sections.push({ text: `Context: ${f(r.context_used)} / ${f(r.context_max)} (${r.context_percent}%)` })
544
+ }
545
+
546
+ if (r.compressions) {
547
+ sections.push({ text: `Compressions: ${r.compressions}` })
548
+ }
549
+
550
+ ctx.transcript.panel('Usage', sections)
551
+ })
552
+ }
553
+ }
554
+ ]
@@ -0,0 +1,20 @@
1
+ import { withInkSuspended } from '@nastechai/ink'
2
+
3
+ import { launchNasTechCommand } from '../../../lib/externalCli.js'
4
+ import { runExternalSetup } from '../../setupHandoff.js'
5
+ import type { SlashCommand } from '../types.js'
6
+
7
+ export const setupCommands: SlashCommand[] = [
8
+ {
9
+ help: 'run full setup wizard (launches `nastech setup`)',
10
+ name: 'setup',
11
+ run: (arg, ctx) =>
12
+ void runExternalSetup({
13
+ args: ['setup', ...arg.split(/\s+/).filter(Boolean)],
14
+ ctx,
15
+ done: 'setup complete — starting session…',
16
+ launcher: launchNasTechCommand,
17
+ suspend: withInkSuspended
18
+ })
19
+ }
20
+ ]
@@ -0,0 +1,20 @@
1
+ import { coreCommands } from './commands/core.js'
2
+ import { debugCommands } from './commands/debug.js'
3
+ import { opsCommands } from './commands/ops.js'
4
+ import { sessionCommands } from './commands/session.js'
5
+ import { setupCommands } from './commands/setup.js'
6
+ import type { SlashCommand } from './types.js'
7
+
8
+ export const SLASH_COMMANDS: SlashCommand[] = [
9
+ ...coreCommands,
10
+ ...sessionCommands,
11
+ ...opsCommands,
12
+ ...setupCommands,
13
+ ...debugCommands
14
+ ]
15
+
16
+ const byName = new Map<string, SlashCommand>(
17
+ SLASH_COMMANDS.flatMap(cmd => [cmd.name, ...(cmd.aliases ?? [])].map(name => [name, cmd] as const))
18
+ )
19
+
20
+ export const findSlashCommand = (name: string) => byName.get(name.toLowerCase())
@@ -0,0 +1,21 @@
1
+ import type { MutableRefObject } from 'react'
2
+
3
+ import type { SlashHandlerContext, UiState } from '../interfaces.js'
4
+
5
+ export interface SlashRunCtx extends SlashHandlerContext {
6
+ flight: number
7
+ guarded: <T>(fn: (r: T) => void) => (r: null | T) => void
8
+ guardedErr: (e: unknown) => void
9
+ sid: null | string
10
+ slashFlightRef: MutableRefObject<number>
11
+ stale: () => boolean
12
+ ui: UiState
13
+ }
14
+
15
+ export interface SlashCommand {
16
+ aliases?: string[]
17
+ help?: string
18
+ name: string
19
+ run: (arg: string, ctx: SlashRunCtx, cmd: string) => void
20
+ usage?: string
21
+ }