@nexus-cortex/tui 4.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (409) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +2 -0
  3. package/README.md +13 -0
  4. package/bin/cli-full.js +23 -0
  5. package/bin/cortex-ui.js +26 -0
  6. package/bin/ink-ui.js +108 -0
  7. package/bin/launcher-dev.js +266 -0
  8. package/bin/launcher.js +516 -0
  9. package/dist/commands/agent/InteractiveAgentMenu.d.ts +100 -0
  10. package/dist/commands/agent/InteractiveAgentMenu.d.ts.map +1 -0
  11. package/dist/commands/agent/InteractiveAgentMenu.js +909 -0
  12. package/dist/commands/agent/InteractiveAgentMenu.js.map +1 -0
  13. package/dist/commands/agent/index.d.ts +55 -0
  14. package/dist/commands/agent/index.d.ts.map +1 -0
  15. package/dist/commands/agent/index.js +714 -0
  16. package/dist/commands/agent/index.js.map +1 -0
  17. package/dist/commands/chat/interactive.d.ts +13 -0
  18. package/dist/commands/chat/interactive.d.ts.map +1 -0
  19. package/dist/commands/chat/interactive.js +2055 -0
  20. package/dist/commands/chat/interactive.js.map +1 -0
  21. package/dist/commands/system-message/EditorLauncher.d.ts +65 -0
  22. package/dist/commands/system-message/EditorLauncher.d.ts.map +1 -0
  23. package/dist/commands/system-message/EditorLauncher.js +143 -0
  24. package/dist/commands/system-message/EditorLauncher.js.map +1 -0
  25. package/dist/commands/system-message/InlineEditor.d.ts +23 -0
  26. package/dist/commands/system-message/InlineEditor.d.ts.map +1 -0
  27. package/dist/commands/system-message/InlineEditor.js +225 -0
  28. package/dist/commands/system-message/InlineEditor.js.map +1 -0
  29. package/dist/commands/system-message/InteractiveMenu.d.ts +76 -0
  30. package/dist/commands/system-message/InteractiveMenu.d.ts.map +1 -0
  31. package/dist/commands/system-message/InteractiveMenu.js +979 -0
  32. package/dist/commands/system-message/InteractiveMenu.js.map +1 -0
  33. package/dist/commands/system-message/index.d.ts +56 -0
  34. package/dist/commands/system-message/index.d.ts.map +1 -0
  35. package/dist/commands/system-message/index.js +694 -0
  36. package/dist/commands/system-message/index.js.map +1 -0
  37. package/dist/commands/ui/artifacts.d.ts +14 -0
  38. package/dist/commands/ui/artifacts.d.ts.map +1 -0
  39. package/dist/commands/ui/artifacts.js +22 -0
  40. package/dist/commands/ui/artifacts.js.map +1 -0
  41. package/dist/commands/ui/config.d.ts +12 -0
  42. package/dist/commands/ui/config.d.ts.map +1 -0
  43. package/dist/commands/ui/config.js +26 -0
  44. package/dist/commands/ui/config.js.map +1 -0
  45. package/dist/commands/ui/context.d.ts +16 -0
  46. package/dist/commands/ui/context.d.ts.map +1 -0
  47. package/dist/commands/ui/context.js +28 -0
  48. package/dist/commands/ui/context.js.map +1 -0
  49. package/dist/commands/ui/middleware.d.ts +14 -0
  50. package/dist/commands/ui/middleware.d.ts.map +1 -0
  51. package/dist/commands/ui/middleware.js +22 -0
  52. package/dist/commands/ui/middleware.js.map +1 -0
  53. package/dist/commands/ui/models.d.ts +14 -0
  54. package/dist/commands/ui/models.d.ts.map +1 -0
  55. package/dist/commands/ui/models.js +50 -0
  56. package/dist/commands/ui/models.js.map +1 -0
  57. package/dist/commands/ui/permissions.d.ts +14 -0
  58. package/dist/commands/ui/permissions.d.ts.map +1 -0
  59. package/dist/commands/ui/permissions.js +22 -0
  60. package/dist/commands/ui/permissions.js.map +1 -0
  61. package/dist/commands/ui/sessions.d.ts +13 -0
  62. package/dist/commands/ui/sessions.d.ts.map +1 -0
  63. package/dist/commands/ui/sessions.js +45 -0
  64. package/dist/commands/ui/sessions.js.map +1 -0
  65. package/dist/commands/ui/system-messages.d.ts +5 -0
  66. package/dist/commands/ui/system-messages.d.ts.map +1 -0
  67. package/dist/commands/ui/system-messages.js +19 -0
  68. package/dist/commands/ui/system-messages.js.map +1 -0
  69. package/dist/commands/ui/themes.d.ts +12 -0
  70. package/dist/commands/ui/themes.d.ts.map +1 -0
  71. package/dist/commands/ui/themes.js +40 -0
  72. package/dist/commands/ui/themes.js.map +1 -0
  73. package/dist/commands/ui/tmux.d.ts +5 -0
  74. package/dist/commands/ui/tmux.d.ts.map +1 -0
  75. package/dist/commands/ui/tmux.js +19 -0
  76. package/dist/commands/ui/tmux.js.map +1 -0
  77. package/dist/cortex.d.ts +12 -0
  78. package/dist/cortex.d.ts.map +1 -0
  79. package/dist/cortex.js +320 -0
  80. package/dist/cortex.js.map +1 -0
  81. package/dist/index.d.ts +3 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +112 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/ink-ui/CortexApp.d.ts +28 -0
  86. package/dist/ink-ui/CortexApp.d.ts.map +1 -0
  87. package/dist/ink-ui/CortexApp.js +2291 -0
  88. package/dist/ink-ui/CortexApp.js.map +1 -0
  89. package/dist/ink-ui/SimpleInputBuffer.d.ts +63 -0
  90. package/dist/ink-ui/SimpleInputBuffer.d.ts.map +1 -0
  91. package/dist/ink-ui/SimpleInputBuffer.js +369 -0
  92. package/dist/ink-ui/SimpleInputBuffer.js.map +1 -0
  93. package/dist/ink-ui/commands/slashCommands.d.ts +40 -0
  94. package/dist/ink-ui/commands/slashCommands.d.ts.map +1 -0
  95. package/dist/ink-ui/commands/slashCommands.js +111 -0
  96. package/dist/ink-ui/commands/slashCommands.js.map +1 -0
  97. package/dist/ink-ui/commands/types.d.ts +161 -0
  98. package/dist/ink-ui/commands/types.d.ts.map +1 -0
  99. package/dist/ink-ui/commands/types.js +12 -0
  100. package/dist/ink-ui/commands/types.js.map +1 -0
  101. package/dist/ink-ui/components/ApprovalDialog.d.ts +21 -0
  102. package/dist/ink-ui/components/ApprovalDialog.d.ts.map +1 -0
  103. package/dist/ink-ui/components/ApprovalDialog.js +81 -0
  104. package/dist/ink-ui/components/ApprovalDialog.js.map +1 -0
  105. package/dist/ink-ui/components/CommandSuggestions.d.ts +19 -0
  106. package/dist/ink-ui/components/CommandSuggestions.d.ts.map +1 -0
  107. package/dist/ink-ui/components/CommandSuggestions.js +36 -0
  108. package/dist/ink-ui/components/CommandSuggestions.js.map +1 -0
  109. package/dist/ink-ui/components/DiffPreview.d.ts +60 -0
  110. package/dist/ink-ui/components/DiffPreview.d.ts.map +1 -0
  111. package/dist/ink-ui/components/DiffPreview.js +195 -0
  112. package/dist/ink-ui/components/DiffPreview.js.map +1 -0
  113. package/dist/ink-ui/components/DocumentPreview.d.ts +50 -0
  114. package/dist/ink-ui/components/DocumentPreview.d.ts.map +1 -0
  115. package/dist/ink-ui/components/DocumentPreview.js +92 -0
  116. package/dist/ink-ui/components/DocumentPreview.js.map +1 -0
  117. package/dist/ink-ui/components/MarkdownText.d.ts +27 -0
  118. package/dist/ink-ui/components/MarkdownText.d.ts.map +1 -0
  119. package/dist/ink-ui/components/MarkdownText.js +342 -0
  120. package/dist/ink-ui/components/MarkdownText.js.map +1 -0
  121. package/dist/ink-ui/components/MenuRenderer.d.ts +26 -0
  122. package/dist/ink-ui/components/MenuRenderer.d.ts.map +1 -0
  123. package/dist/ink-ui/components/MenuRenderer.js +264 -0
  124. package/dist/ink-ui/components/MenuRenderer.js.map +1 -0
  125. package/dist/ink-ui/components/ModelPickerDialog.d.ts +33 -0
  126. package/dist/ink-ui/components/ModelPickerDialog.d.ts.map +1 -0
  127. package/dist/ink-ui/components/ModelPickerDialog.js +98 -0
  128. package/dist/ink-ui/components/ModelPickerDialog.js.map +1 -0
  129. package/dist/ink-ui/components/StreamDisplay.d.ts +31 -0
  130. package/dist/ink-ui/components/StreamDisplay.d.ts.map +1 -0
  131. package/dist/ink-ui/components/StreamDisplay.js +573 -0
  132. package/dist/ink-ui/components/StreamDisplay.js.map +1 -0
  133. package/dist/ink-ui/components/SubAgentPanel.d.ts +98 -0
  134. package/dist/ink-ui/components/SubAgentPanel.d.ts.map +1 -0
  135. package/dist/ink-ui/components/SubAgentPanel.js +155 -0
  136. package/dist/ink-ui/components/SubAgentPanel.js.map +1 -0
  137. package/dist/ink-ui/components/ThinkingDisplay.d.ts +46 -0
  138. package/dist/ink-ui/components/ThinkingDisplay.d.ts.map +1 -0
  139. package/dist/ink-ui/components/ThinkingDisplay.js +176 -0
  140. package/dist/ink-ui/components/ThinkingDisplay.js.map +1 -0
  141. package/dist/ink-ui/components/ToolCallDisplay.d.ts +51 -0
  142. package/dist/ink-ui/components/ToolCallDisplay.d.ts.map +1 -0
  143. package/dist/ink-ui/components/ToolCallDisplay.js +378 -0
  144. package/dist/ink-ui/components/ToolCallDisplay.js.map +1 -0
  145. package/dist/ink-ui/components/WritePreview.d.ts +42 -0
  146. package/dist/ink-ui/components/WritePreview.d.ts.map +1 -0
  147. package/dist/ink-ui/components/WritePreview.js +100 -0
  148. package/dist/ink-ui/components/WritePreview.js.map +1 -0
  149. package/dist/ink-ui/contexts/KeypressContext.d.ts +32 -0
  150. package/dist/ink-ui/contexts/KeypressContext.d.ts.map +1 -0
  151. package/dist/ink-ui/contexts/KeypressContext.js +529 -0
  152. package/dist/ink-ui/contexts/KeypressContext.js.map +1 -0
  153. package/dist/ink-ui/contexts/SessionContext.d.ts +46 -0
  154. package/dist/ink-ui/contexts/SessionContext.d.ts.map +1 -0
  155. package/dist/ink-ui/contexts/SessionContext.js +162 -0
  156. package/dist/ink-ui/contexts/SessionContext.js.map +1 -0
  157. package/dist/ink-ui/core-stubs.d.ts +270 -0
  158. package/dist/ink-ui/core-stubs.d.ts.map +1 -0
  159. package/dist/ink-ui/core-stubs.js +276 -0
  160. package/dist/ink-ui/core-stubs.js.map +1 -0
  161. package/dist/ink-ui/cortex-types.d.ts +214 -0
  162. package/dist/ink-ui/cortex-types.d.ts.map +1 -0
  163. package/dist/ink-ui/cortex-types.js +52 -0
  164. package/dist/ink-ui/cortex-types.js.map +1 -0
  165. package/dist/ink-ui/hooks/useCortexStream.d.ts +75 -0
  166. package/dist/ink-ui/hooks/useCortexStream.d.ts.map +1 -0
  167. package/dist/ink-ui/hooks/useCortexStream.js +518 -0
  168. package/dist/ink-ui/hooks/useCortexStream.js.map +1 -0
  169. package/dist/ink-ui/hooks/useFocus.d.ts +11 -0
  170. package/dist/ink-ui/hooks/useFocus.d.ts.map +1 -0
  171. package/dist/ink-ui/hooks/useFocus.js +51 -0
  172. package/dist/ink-ui/hooks/useFocus.js.map +1 -0
  173. package/dist/ink-ui/hooks/useHistoryManager.d.ts +23 -0
  174. package/dist/ink-ui/hooks/useHistoryManager.d.ts.map +1 -0
  175. package/dist/ink-ui/hooks/useHistoryManager.js +63 -0
  176. package/dist/ink-ui/hooks/useHistoryManager.js.map +1 -0
  177. package/dist/ink-ui/hooks/useKeypress.d.ts +18 -0
  178. package/dist/ink-ui/hooks/useKeypress.d.ts.map +1 -0
  179. package/dist/ink-ui/hooks/useKeypress.js +27 -0
  180. package/dist/ink-ui/hooks/useKeypress.js.map +1 -0
  181. package/dist/ink-ui/hooks/useReactApprovalHandler.d.ts +74 -0
  182. package/dist/ink-ui/hooks/useReactApprovalHandler.d.ts.map +1 -0
  183. package/dist/ink-ui/hooks/useReactApprovalHandler.js +83 -0
  184. package/dist/ink-ui/hooks/useReactApprovalHandler.js.map +1 -0
  185. package/dist/ink-ui/hooks/useTerminalSize.d.ts +10 -0
  186. package/dist/ink-ui/hooks/useTerminalSize.d.ts.map +1 -0
  187. package/dist/ink-ui/hooks/useTerminalSize.js +28 -0
  188. package/dist/ink-ui/hooks/useTerminalSize.js.map +1 -0
  189. package/dist/ink-ui/semantic-colors.d.ts +8 -0
  190. package/dist/ink-ui/semantic-colors.d.ts.map +1 -0
  191. package/dist/ink-ui/semantic-colors.js +24 -0
  192. package/dist/ink-ui/semantic-colors.js.map +1 -0
  193. package/dist/ink-ui/state/extensions.d.ts +68 -0
  194. package/dist/ink-ui/state/extensions.d.ts.map +1 -0
  195. package/dist/ink-ui/state/extensions.js +97 -0
  196. package/dist/ink-ui/state/extensions.js.map +1 -0
  197. package/dist/ink-ui/themes/ansi-light.d.ts +8 -0
  198. package/dist/ink-ui/themes/ansi-light.d.ts.map +1 -0
  199. package/dist/ink-ui/themes/ansi-light.js +143 -0
  200. package/dist/ink-ui/themes/ansi-light.js.map +1 -0
  201. package/dist/ink-ui/themes/ansi.d.ts +8 -0
  202. package/dist/ink-ui/themes/ansi.d.ts.map +1 -0
  203. package/dist/ink-ui/themes/ansi.js +153 -0
  204. package/dist/ink-ui/themes/ansi.js.map +1 -0
  205. package/dist/ink-ui/themes/atom-one-dark.d.ts +8 -0
  206. package/dist/ink-ui/themes/atom-one-dark.d.ts.map +1 -0
  207. package/dist/ink-ui/themes/atom-one-dark.js +140 -0
  208. package/dist/ink-ui/themes/atom-one-dark.js.map +1 -0
  209. package/dist/ink-ui/themes/ayu-light.d.ts +8 -0
  210. package/dist/ink-ui/themes/ayu-light.d.ts.map +1 -0
  211. package/dist/ink-ui/themes/ayu-light.js +132 -0
  212. package/dist/ink-ui/themes/ayu-light.js.map +1 -0
  213. package/dist/ink-ui/themes/ayu.d.ts +8 -0
  214. package/dist/ink-ui/themes/ayu.d.ts.map +1 -0
  215. package/dist/ink-ui/themes/ayu.js +106 -0
  216. package/dist/ink-ui/themes/ayu.js.map +1 -0
  217. package/dist/ink-ui/themes/color-utils.d.ts +23 -0
  218. package/dist/ink-ui/themes/color-utils.d.ts.map +1 -0
  219. package/dist/ink-ui/themes/color-utils.js +237 -0
  220. package/dist/ink-ui/themes/color-utils.js.map +1 -0
  221. package/dist/ink-ui/themes/default-light.d.ts +8 -0
  222. package/dist/ink-ui/themes/default-light.d.ts.map +1 -0
  223. package/dist/ink-ui/themes/default-light.js +100 -0
  224. package/dist/ink-ui/themes/default-light.js.map +1 -0
  225. package/dist/ink-ui/themes/default.d.ts +8 -0
  226. package/dist/ink-ui/themes/default.d.ts.map +1 -0
  227. package/dist/ink-ui/themes/default.js +143 -0
  228. package/dist/ink-ui/themes/default.js.map +1 -0
  229. package/dist/ink-ui/themes/dracula.d.ts +8 -0
  230. package/dist/ink-ui/themes/dracula.d.ts.map +1 -0
  231. package/dist/ink-ui/themes/dracula.js +117 -0
  232. package/dist/ink-ui/themes/dracula.js.map +1 -0
  233. package/dist/ink-ui/themes/github-dark.d.ts +8 -0
  234. package/dist/ink-ui/themes/github-dark.d.ts.map +1 -0
  235. package/dist/ink-ui/themes/github-dark.js +140 -0
  236. package/dist/ink-ui/themes/github-dark.js.map +1 -0
  237. package/dist/ink-ui/themes/github-light.d.ts +8 -0
  238. package/dist/ink-ui/themes/github-light.d.ts.map +1 -0
  239. package/dist/ink-ui/themes/github-light.js +142 -0
  240. package/dist/ink-ui/themes/github-light.js.map +1 -0
  241. package/dist/ink-ui/themes/googlecode.d.ts +8 -0
  242. package/dist/ink-ui/themes/googlecode.d.ts.map +1 -0
  243. package/dist/ink-ui/themes/googlecode.js +139 -0
  244. package/dist/ink-ui/themes/googlecode.js.map +1 -0
  245. package/dist/ink-ui/themes/no-color.d.ts +8 -0
  246. package/dist/ink-ui/themes/no-color.d.ts.map +1 -0
  247. package/dist/ink-ui/themes/no-color.js +118 -0
  248. package/dist/ink-ui/themes/no-color.js.map +1 -0
  249. package/dist/ink-ui/themes/semantic-tokens.d.ts +40 -0
  250. package/dist/ink-ui/themes/semantic-tokens.d.ts.map +1 -0
  251. package/dist/ink-ui/themes/semantic-tokens.js +100 -0
  252. package/dist/ink-ui/themes/semantic-tokens.js.map +1 -0
  253. package/dist/ink-ui/themes/shades-of-purple.d.ts +12 -0
  254. package/dist/ink-ui/themes/shades-of-purple.d.ts.map +1 -0
  255. package/dist/ink-ui/themes/shades-of-purple.js +306 -0
  256. package/dist/ink-ui/themes/shades-of-purple.js.map +1 -0
  257. package/dist/ink-ui/themes/theme-manager.d.ts +67 -0
  258. package/dist/ink-ui/themes/theme-manager.d.ts.map +1 -0
  259. package/dist/ink-ui/themes/theme-manager.js +263 -0
  260. package/dist/ink-ui/themes/theme-manager.js.map +1 -0
  261. package/dist/ink-ui/themes/theme.d.ts +134 -0
  262. package/dist/ink-ui/themes/theme.d.ts.map +1 -0
  263. package/dist/ink-ui/themes/theme.js +390 -0
  264. package/dist/ink-ui/themes/theme.js.map +1 -0
  265. package/dist/ink-ui/themes/xcode.d.ts +8 -0
  266. package/dist/ink-ui/themes/xcode.d.ts.map +1 -0
  267. package/dist/ink-ui/themes/xcode.js +147 -0
  268. package/dist/ink-ui/themes/xcode.js.map +1 -0
  269. package/dist/ink-ui/types.d.ts +306 -0
  270. package/dist/ink-ui/types.d.ts.map +1 -0
  271. package/dist/ink-ui/types.js +65 -0
  272. package/dist/ink-ui/types.js.map +1 -0
  273. package/dist/ink-ui/utils/input.d.ts +18 -0
  274. package/dist/ink-ui/utils/input.d.ts.map +1 -0
  275. package/dist/ink-ui/utils/input.js +51 -0
  276. package/dist/ink-ui/utils/input.js.map +1 -0
  277. package/dist/ink-ui/utils/mouse.d.ts +33 -0
  278. package/dist/ink-ui/utils/mouse.d.ts.map +1 -0
  279. package/dist/ink-ui/utils/mouse.js +182 -0
  280. package/dist/ink-ui/utils/mouse.js.map +1 -0
  281. package/dist/services/BuiltinCommandLoader.d.ts +21 -0
  282. package/dist/services/BuiltinCommandLoader.d.ts.map +1 -0
  283. package/dist/services/BuiltinCommandLoader.js +182 -0
  284. package/dist/services/BuiltinCommandLoader.js.map +1 -0
  285. package/dist/services/CommandService.d.ts +39 -0
  286. package/dist/services/CommandService.d.ts.map +1 -0
  287. package/dist/services/CommandService.js +49 -0
  288. package/dist/services/CommandService.js.map +1 -0
  289. package/dist/services/FileCommandLoader.d.ts +16 -0
  290. package/dist/services/FileCommandLoader.d.ts.map +1 -0
  291. package/dist/services/FileCommandLoader.js +19 -0
  292. package/dist/services/FileCommandLoader.js.map +1 -0
  293. package/dist/services/McpPromptLoader.d.ts +16 -0
  294. package/dist/services/McpPromptLoader.d.ts.map +1 -0
  295. package/dist/services/McpPromptLoader.js +19 -0
  296. package/dist/services/McpPromptLoader.js.map +1 -0
  297. package/dist/services/index.d.ts +8 -0
  298. package/dist/services/index.d.ts.map +1 -0
  299. package/dist/services/index.js +8 -0
  300. package/dist/services/index.js.map +1 -0
  301. package/dist/ui/ChalkMenuRenderer.d.ts +22 -0
  302. package/dist/ui/ChalkMenuRenderer.d.ts.map +1 -0
  303. package/dist/ui/ChalkMenuRenderer.js +478 -0
  304. package/dist/ui/ChalkMenuRenderer.js.map +1 -0
  305. package/dist/ui/ChalkModelPicker.d.ts +20 -0
  306. package/dist/ui/ChalkModelPicker.d.ts.map +1 -0
  307. package/dist/ui/ChalkModelPicker.js +363 -0
  308. package/dist/ui/ChalkModelPicker.js.map +1 -0
  309. package/dist/ui/ChalkThemePicker.d.ts +20 -0
  310. package/dist/ui/ChalkThemePicker.d.ts.map +1 -0
  311. package/dist/ui/ChalkThemePicker.js +370 -0
  312. package/dist/ui/ChalkThemePicker.js.map +1 -0
  313. package/dist/ui/InkApprovalDialog.d.ts +8 -0
  314. package/dist/ui/InkApprovalDialog.d.ts.map +1 -0
  315. package/dist/ui/InkApprovalDialog.js +25 -0
  316. package/dist/ui/InkApprovalDialog.js.map +1 -0
  317. package/dist/ui/InkCommandPalette.d.ts +43 -0
  318. package/dist/ui/InkCommandPalette.d.ts.map +1 -0
  319. package/dist/ui/InkCommandPalette.js +105 -0
  320. package/dist/ui/InkCommandPalette.js.map +1 -0
  321. package/dist/ui/InkConfigMenu.d.ts +24 -0
  322. package/dist/ui/InkConfigMenu.d.ts.map +1 -0
  323. package/dist/ui/InkConfigMenu.js +259 -0
  324. package/dist/ui/InkConfigMenu.js.map +1 -0
  325. package/dist/ui/InkHelp.d.ts +25 -0
  326. package/dist/ui/InkHelp.d.ts.map +1 -0
  327. package/dist/ui/InkHelp.js +55 -0
  328. package/dist/ui/InkHelp.js.map +1 -0
  329. package/dist/ui/InkMenuPicker.d.ts +19 -0
  330. package/dist/ui/InkMenuPicker.d.ts.map +1 -0
  331. package/dist/ui/InkMenuPicker.js +33 -0
  332. package/dist/ui/InkMenuPicker.js.map +1 -0
  333. package/dist/ui/InkModelPicker.d.ts +23 -0
  334. package/dist/ui/InkModelPicker.d.ts.map +1 -0
  335. package/dist/ui/InkModelPicker.js +53 -0
  336. package/dist/ui/InkModelPicker.js.map +1 -0
  337. package/dist/ui/PersistentInput.d.ts +91 -0
  338. package/dist/ui/PersistentInput.d.ts.map +1 -0
  339. package/dist/ui/PersistentInput.js +283 -0
  340. package/dist/ui/PersistentInput.js.map +1 -0
  341. package/dist/ui/RawInput.d.ts +27 -0
  342. package/dist/ui/RawInput.d.ts.map +1 -0
  343. package/dist/ui/RawInput.js +731 -0
  344. package/dist/ui/RawInput.js.map +1 -0
  345. package/dist/ui/SlashCommandAutocomplete.d.ts +94 -0
  346. package/dist/ui/SlashCommandAutocomplete.d.ts.map +1 -0
  347. package/dist/ui/SlashCommandAutocomplete.js +274 -0
  348. package/dist/ui/SlashCommandAutocomplete.js.map +1 -0
  349. package/dist/ui/SplashScreen.d.ts +76 -0
  350. package/dist/ui/SplashScreen.d.ts.map +1 -0
  351. package/dist/ui/SplashScreen.js +316 -0
  352. package/dist/ui/SplashScreen.js.map +1 -0
  353. package/dist/ui/components/ArtifactDashboard.d.ts +16 -0
  354. package/dist/ui/components/ArtifactDashboard.d.ts.map +1 -0
  355. package/dist/ui/components/ArtifactDashboard.js +102 -0
  356. package/dist/ui/components/ArtifactDashboard.js.map +1 -0
  357. package/dist/ui/components/ChatInput.d.ts +36 -0
  358. package/dist/ui/components/ChatInput.d.ts.map +1 -0
  359. package/dist/ui/components/ChatInput.js +11 -0
  360. package/dist/ui/components/ChatInput.js.map +1 -0
  361. package/dist/ui/components/ConfigWizard.d.ts +17 -0
  362. package/dist/ui/components/ConfigWizard.d.ts.map +1 -0
  363. package/dist/ui/components/ConfigWizard.js +134 -0
  364. package/dist/ui/components/ConfigWizard.js.map +1 -0
  365. package/dist/ui/components/ContextViewer.d.ts +18 -0
  366. package/dist/ui/components/ContextViewer.d.ts.map +1 -0
  367. package/dist/ui/components/ContextViewer.js +85 -0
  368. package/dist/ui/components/ContextViewer.js.map +1 -0
  369. package/dist/ui/components/MiddlewareDashboard.d.ts +16 -0
  370. package/dist/ui/components/MiddlewareDashboard.d.ts.map +1 -0
  371. package/dist/ui/components/MiddlewareDashboard.js +98 -0
  372. package/dist/ui/components/MiddlewareDashboard.js.map +1 -0
  373. package/dist/ui/components/ModelPicker.d.ts +24 -0
  374. package/dist/ui/components/ModelPicker.d.ts.map +1 -0
  375. package/dist/ui/components/ModelPicker.js +96 -0
  376. package/dist/ui/components/ModelPicker.js.map +1 -0
  377. package/dist/ui/components/MultiLineInput.d.ts +27 -0
  378. package/dist/ui/components/MultiLineInput.d.ts.map +1 -0
  379. package/dist/ui/components/MultiLineInput.js +182 -0
  380. package/dist/ui/components/MultiLineInput.js.map +1 -0
  381. package/dist/ui/components/PermissionsBrowser.d.ts +16 -0
  382. package/dist/ui/components/PermissionsBrowser.d.ts.map +1 -0
  383. package/dist/ui/components/PermissionsBrowser.js +110 -0
  384. package/dist/ui/components/PermissionsBrowser.js.map +1 -0
  385. package/dist/ui/components/SessionBrowser.d.ts +19 -0
  386. package/dist/ui/components/SessionBrowser.d.ts.map +1 -0
  387. package/dist/ui/components/SessionBrowser.js +66 -0
  388. package/dist/ui/components/SessionBrowser.js.map +1 -0
  389. package/dist/ui/components/StatusBar.d.ts +32 -0
  390. package/dist/ui/components/StatusBar.d.ts.map +1 -0
  391. package/dist/ui/components/StatusBar.js +27 -0
  392. package/dist/ui/components/StatusBar.js.map +1 -0
  393. package/dist/ui/components/SystemMessageBrowser.d.ts +11 -0
  394. package/dist/ui/components/SystemMessageBrowser.d.ts.map +1 -0
  395. package/dist/ui/components/SystemMessageBrowser.js +106 -0
  396. package/dist/ui/components/SystemMessageBrowser.js.map +1 -0
  397. package/dist/ui/components/ThemePicker.d.ts +11 -0
  398. package/dist/ui/components/ThemePicker.d.ts.map +1 -0
  399. package/dist/ui/components/ThemePicker.js +62 -0
  400. package/dist/ui/components/ThemePicker.js.map +1 -0
  401. package/dist/ui/components/TmuxBrowser.d.ts +11 -0
  402. package/dist/ui/components/TmuxBrowser.d.ts.map +1 -0
  403. package/dist/ui/components/TmuxBrowser.js +85 -0
  404. package/dist/ui/components/TmuxBrowser.js.map +1 -0
  405. package/dist/ui/components/index.d.ts +22 -0
  406. package/dist/ui/components/index.d.ts.map +1 -0
  407. package/dist/ui/components/index.js +21 -0
  408. package/dist/ui/components/index.js.map +1 -0
  409. package/package.json +70 -0
@@ -0,0 +1,694 @@
1
+ /**
2
+ * System Message Management Command
3
+ *
4
+ * Entry point for /system-message slash command
5
+ * Launches interactive menu for managing system messages
6
+ * with AI-powered message creation and editing assistance
7
+ */
8
+ import React from 'react';
9
+ import { render } from 'ink';
10
+ import { SystemMessageStore } from '@nexus-cortex/core/system-messages/SystemMessageStore.js';
11
+ import { InteractiveMenu, } from './InteractiveMenu.js';
12
+ import * as path from 'path';
13
+ import * as fs from 'fs/promises';
14
+ /**
15
+ * System prompt for generating system message profiles
16
+ */
17
+ const SYSTEM_MESSAGE_GENERATOR_PROMPT = `You are an expert at designing system messages for an AI CLI assistant.
18
+
19
+ Given a user's description of what they want a system message to do, generate a complete system message.
20
+
21
+ IMPORTANT: Your response must be ONLY valid JSON with no markdown code fences or other text.
22
+
23
+ The JSON must have exactly these fields:
24
+ {
25
+ "id": "message-id-in-kebab-case",
26
+ "type": "instruction|constraint|context|template",
27
+ "displayName": "Human Readable Name",
28
+ "description": "A clear, concise description of what this message does (max 200 chars)",
29
+ "priority": 50,
30
+ "content": "The full markdown content of the system message"
31
+ }
32
+
33
+ Message Types:
34
+ - instruction: Guidance on how to approach tasks, methodologies, best practices
35
+ - constraint: Boundaries, limitations, what NOT to do, safety guidelines
36
+ - context: Background information, project context, domain knowledge
37
+ - template: Reusable patterns, formats, structures for outputs
38
+
39
+ Guidelines for the content:
40
+ 1. Use clear markdown formatting with headers and bullet points
41
+ 2. Be specific and actionable
42
+ 3. Include examples where helpful
43
+ 4. Use appropriate structure for the message type
44
+ 5. Keep instructions focused and non-redundant
45
+ 6. For constraints, be clear about what is NOT allowed
46
+ 7. For context, provide relevant background that guides behavior
47
+ 8. For templates, include clear placeholders and usage examples
48
+
49
+ Priority Guidelines:
50
+ - 90-100: Critical constraints and safety rules (loaded first)
51
+ - 70-89: Core behavioral instructions
52
+ - 50-69: General guidance and context
53
+ - 30-49: Preferences and style guides
54
+ - 10-29: Optional enhancements
55
+ - 1-9: Low priority additions
56
+
57
+ The id should be:
58
+ - Lowercase, hyphenated (kebab-case)
59
+ - Descriptive but concise (max 48 chars)
60
+ - No special characters except hyphens`;
61
+ const SYSTEM_MESSAGE_DOMAINS = [
62
+ {
63
+ domainName: 'coding-style',
64
+ keywords: ['code', 'style', 'format', 'naming', 'convention', 'lint', 'prettier', 'eslint', 'syntax'],
65
+ suggestedType: 'instruction',
66
+ suggestedPriority: 60,
67
+ followUpQuestions: [
68
+ 'What programming languages should this style guide cover?',
69
+ 'Should it enforce specific naming conventions (camelCase, snake_case, etc.)?',
70
+ 'Are there specific patterns to encourage or avoid?',
71
+ ],
72
+ },
73
+ {
74
+ domainName: 'safety',
75
+ keywords: ['safe', 'security', 'danger', 'restrict', 'block', 'prevent', 'limit', 'careful', 'warning'],
76
+ suggestedType: 'constraint',
77
+ suggestedPriority: 95,
78
+ followUpQuestions: [
79
+ 'What specific actions or behaviors should be restricted?',
80
+ 'Should it be a hard block or a warning with confirmation?',
81
+ 'Are there any exceptions where the restriction should not apply?',
82
+ ],
83
+ },
84
+ {
85
+ domainName: 'output-format',
86
+ keywords: ['output', 'format', 'response', 'template', 'structure', 'json', 'markdown', 'report'],
87
+ suggestedType: 'template',
88
+ suggestedPriority: 50,
89
+ followUpQuestions: [
90
+ 'What format should the output be in? (JSON, markdown, structured text)',
91
+ 'Should it include specific sections or fields?',
92
+ 'Are there examples of ideal output you want to match?',
93
+ ],
94
+ },
95
+ {
96
+ domainName: 'project-context',
97
+ keywords: ['project', 'codebase', 'context', 'background', 'about', 'describe', 'understand', 'architecture'],
98
+ suggestedType: 'context',
99
+ suggestedPriority: 55,
100
+ followUpQuestions: [
101
+ 'What are the key components or modules the AI should understand?',
102
+ 'Are there specific patterns or conventions unique to this project?',
103
+ 'What external dependencies or APIs should be documented?',
104
+ ],
105
+ },
106
+ {
107
+ domainName: 'behavior',
108
+ keywords: ['behave', 'act', 'persona', 'tone', 'voice', 'personality', 'manner', 'approach', 'style'],
109
+ suggestedType: 'instruction',
110
+ suggestedPriority: 70,
111
+ followUpQuestions: [
112
+ 'What tone should the AI use? (professional, casual, technical, friendly)',
113
+ 'Should it have a specific persona or character?',
114
+ 'Are there communication styles to adopt or avoid?',
115
+ ],
116
+ },
117
+ {
118
+ domainName: 'task-specific',
119
+ keywords: ['task', 'workflow', 'process', 'procedure', 'step', 'guide', 'how to', 'method'],
120
+ suggestedType: 'instruction',
121
+ suggestedPriority: 65,
122
+ followUpQuestions: [
123
+ 'What specific task or workflow should this guide the AI through?',
124
+ 'Are there checkpoints or validations during the process?',
125
+ 'What defines success for this task?',
126
+ ],
127
+ },
128
+ {
129
+ domainName: 'testing',
130
+ keywords: ['test', 'testing', 'spec', 'verification', 'validation', 'check', 'coverage', 'quality'],
131
+ suggestedType: 'instruction',
132
+ suggestedPriority: 60,
133
+ followUpQuestions: [
134
+ 'What testing framework or patterns should be followed?',
135
+ 'What types of tests are most important? (unit, integration, e2e)',
136
+ 'Are there specific coverage goals or quality metrics?',
137
+ ],
138
+ },
139
+ {
140
+ domainName: 'documentation',
141
+ keywords: ['document', 'doc', 'comment', 'readme', 'explain', 'jsdoc', 'docstring', 'api doc'],
142
+ suggestedType: 'instruction',
143
+ suggestedPriority: 55,
144
+ followUpQuestions: [
145
+ 'What documentation format is preferred? (JSDoc, TypeDoc, inline comments)',
146
+ 'What should always be documented vs. left implicit?',
147
+ 'Are there templates or examples to follow?',
148
+ ],
149
+ },
150
+ {
151
+ domainName: 'error-handling',
152
+ keywords: ['error', 'exception', 'handle', 'catch', 'fail', 'fallback', 'retry', 'recover'],
153
+ suggestedType: 'instruction',
154
+ suggestedPriority: 70,
155
+ followUpQuestions: [
156
+ 'What error handling patterns should be followed?',
157
+ 'Should errors be logged, reported, or silently handled?',
158
+ 'Are there specific error messages or formats to use?',
159
+ ],
160
+ },
161
+ {
162
+ domainName: 'performance',
163
+ keywords: ['performance', 'optimize', 'fast', 'efficient', 'cache', 'memory', 'speed', 'benchmark'],
164
+ suggestedType: 'instruction',
165
+ suggestedPriority: 60,
166
+ followUpQuestions: [
167
+ 'What performance metrics are most important? (latency, memory, CPU)',
168
+ 'Are there specific optimization patterns to use or avoid?',
169
+ 'Should there be performance budgets or thresholds?',
170
+ ],
171
+ },
172
+ ];
173
+ /**
174
+ * Analyze user description to detect domain and context
175
+ */
176
+ function analyzeMessageDescription(description) {
177
+ const lowerDesc = description.toLowerCase();
178
+ const detectedDomains = [];
179
+ // Find matching domains
180
+ for (const domain of SYSTEM_MESSAGE_DOMAINS) {
181
+ const matchCount = domain.keywords.filter((kw) => lowerDesc.includes(kw)).length;
182
+ if (matchCount > 0) {
183
+ detectedDomains.push(domain);
184
+ }
185
+ }
186
+ // Sort by relevance (more keyword matches = more relevant)
187
+ detectedDomains.sort((a, b) => {
188
+ const aMatches = a.keywords.filter((kw) => lowerDesc.includes(kw)).length;
189
+ const bMatches = b.keywords.filter((kw) => lowerDesc.includes(kw)).length;
190
+ return bMatches - aMatches;
191
+ });
192
+ // Determine suggested type and priority from most relevant domain
193
+ let suggestedType = 'instruction';
194
+ let suggestedPriority = 50;
195
+ if (detectedDomains.length > 0) {
196
+ const primaryDomain = detectedDomains[0];
197
+ if (primaryDomain) {
198
+ suggestedType = primaryDomain.suggestedType;
199
+ suggestedPriority = primaryDomain.suggestedPriority;
200
+ }
201
+ }
202
+ // Build contextual questions based on detected domains
203
+ const contextualQuestions = [];
204
+ if (detectedDomains.length > 0) {
205
+ const primaryDomain = detectedDomains[0];
206
+ if (primaryDomain) {
207
+ contextualQuestions.push(...primaryDomain.followUpQuestions);
208
+ }
209
+ }
210
+ // Add generic but useful questions if we don't have domain-specific ones
211
+ if (contextualQuestions.length === 0) {
212
+ contextualQuestions.push(`What type of system message should this be? (instruction for how-to, constraint for limitations, context for background info, template for output formats)`, 'What priority should this message have relative to other system messages?', 'Are there specific examples or scenarios you want to guide behavior for?');
213
+ }
214
+ return {
215
+ detectedDomains,
216
+ suggestedType,
217
+ suggestedPriority,
218
+ contextualQuestions,
219
+ };
220
+ }
221
+ /**
222
+ * System prompt for generating the final system message profile
223
+ */
224
+ const PROFILE_GENERATOR_PROMPT = `You are an expert at designing system messages for an AI CLI assistant.
225
+
226
+ Based on the conversation below, generate a complete system message profile.
227
+
228
+ Your response must be ONLY valid JSON with this exact structure:
229
+ {
230
+ "id": "message-id-kebab-case",
231
+ "type": "instruction|constraint|context|template",
232
+ "displayName": "Human Readable Name",
233
+ "description": "A clear, concise description (max 200 chars)",
234
+ "priority": 50,
235
+ "content": "# Message Title\\n\\nFull markdown content with proper formatting, headers, bullet points, and examples..."
236
+ }
237
+
238
+ Message Types:
239
+ - instruction: How-to guidance, methodologies, best practices
240
+ - constraint: Boundaries, limitations, safety rules
241
+ - context: Background info, project context, domain knowledge
242
+ - template: Reusable output patterns and formats
243
+
244
+ Priority levels (1-100, higher = loaded first):
245
+ - 90-100: Critical constraints
246
+ - 70-89: Core instructions
247
+ - 50-69: General guidance
248
+ - 30-49: Preferences
249
+ - 10-29: Optional
250
+
251
+ Guidelines:
252
+ - The id should be lowercase, hyphenated, max 48 chars
253
+ - The content should be well-formatted markdown
254
+ - Include clear structure with headers and bullet points
255
+ - Be specific and actionable
256
+ - Add examples where helpful
257
+
258
+ IMPORTANT: Return ONLY valid JSON. No markdown, no explanation, just the JSON object.`;
259
+ /**
260
+ * System prompt for AI-assisted editing
261
+ */
262
+ const EDIT_ASSISTANT_PROMPT = `You are an expert at improving and refining system messages for an AI CLI assistant.
263
+
264
+ You will be given the current content of a system message and the user's request for how to modify it.
265
+
266
+ Your response must be ONLY valid JSON with this exact structure:
267
+ {
268
+ "content": "The complete updated markdown content of the system message",
269
+ "summary": "A brief 1-2 sentence summary of what was changed"
270
+ }
271
+
272
+ Guidelines for modifications:
273
+ 1. Preserve the overall structure and purpose of the message
274
+ 2. Make the requested changes clearly and precisely
275
+ 3. Maintain proper markdown formatting
276
+ 4. Keep the content focused and non-redundant
277
+ 5. If adding new sections, integrate them naturally
278
+ 6. If removing content, ensure remaining content is coherent
279
+ 7. Improve clarity and specificity when possible
280
+
281
+ IMPORTANT: Return ONLY valid JSON. The "content" should be the full updated message, not just the changes.`;
282
+ /**
283
+ * Create an AI profile generator using the orchestrator
284
+ */
285
+ function createProfileGenerator(orchestratorClient) {
286
+ return async (description) => {
287
+ const prompt = `Create a system message for the following description:
288
+
289
+ "${description}"
290
+
291
+ Remember: Respond with ONLY valid JSON, no markdown code fences.`;
292
+ try {
293
+ const response = await orchestratorClient.sendMessage(prompt, {
294
+ system: SYSTEM_MESSAGE_GENERATOR_PROMPT,
295
+ temperature: 0.7,
296
+ });
297
+ // Extract the response text
298
+ let responseText = '';
299
+ if (typeof response === 'string') {
300
+ responseText = response;
301
+ }
302
+ else if (response && typeof response === 'object') {
303
+ if ('text' in response) {
304
+ responseText = response.text;
305
+ }
306
+ else if ('content' in response && Array.isArray(response.content)) {
307
+ for (const block of response.content) {
308
+ if (block && typeof block === 'object' && 'text' in block) {
309
+ responseText += block.text;
310
+ }
311
+ }
312
+ }
313
+ }
314
+ // Try to extract JSON from the response
315
+ let jsonStr = responseText.trim();
316
+ // Remove markdown code fences if present
317
+ const jsonMatch = jsonStr.match(/```(?:json)?\s*([\s\S]*?)```/);
318
+ if (jsonMatch) {
319
+ jsonStr = jsonMatch[1]?.trim() || jsonStr;
320
+ }
321
+ // Find JSON object boundaries
322
+ const startBrace = jsonStr.indexOf('{');
323
+ const endBrace = jsonStr.lastIndexOf('}');
324
+ if (startBrace !== -1 && endBrace !== -1) {
325
+ jsonStr = jsonStr.slice(startBrace, endBrace + 1);
326
+ }
327
+ // Parse the JSON
328
+ const profile = JSON.parse(jsonStr);
329
+ // Validate required fields
330
+ if (!profile.id || typeof profile.id !== 'string') {
331
+ throw new Error('Invalid profile: missing or invalid id');
332
+ }
333
+ if (!profile.type || !['instruction', 'constraint', 'context', 'template'].includes(profile.type)) {
334
+ throw new Error('Invalid profile: missing or invalid type');
335
+ }
336
+ if (!profile.content || typeof profile.content !== 'string') {
337
+ throw new Error('Invalid profile: missing or invalid content');
338
+ }
339
+ // Sanitize id
340
+ const safeId = profile.id
341
+ .toLowerCase()
342
+ .replace(/[^a-z0-9-]/g, '-')
343
+ .replace(/--+/g, '-')
344
+ .replace(/^-|-$/g, '')
345
+ .slice(0, 48);
346
+ return {
347
+ id: safeId || `message-${Date.now()}`,
348
+ type: profile.type,
349
+ displayName: profile.displayName || safeId,
350
+ description: (profile.description || description).slice(0, 200),
351
+ priority: typeof profile.priority === 'number' ? profile.priority : 50,
352
+ content: profile.content,
353
+ };
354
+ }
355
+ catch (error) {
356
+ // If JSON parsing fails, create a fallback profile
357
+ console.error('Failed to parse AI response:', error.message);
358
+ const analysis = analyzeMessageDescription(description);
359
+ const safeId = description
360
+ .toLowerCase()
361
+ .replace(/[^a-z0-9]+/g, '-')
362
+ .replace(/^-|-$/g, '')
363
+ .slice(0, 48) || `message-${Date.now()}`;
364
+ return {
365
+ id: safeId,
366
+ type: analysis.suggestedType,
367
+ displayName: description.slice(0, 50),
368
+ description: description.slice(0, 200),
369
+ priority: analysis.suggestedPriority,
370
+ content: `# ${description.slice(0, 50)}\n\n${description}\n\n## Guidelines\n\n- Follow the instructions above\n- Be thorough and consistent\n- Ask for clarification when needed`,
371
+ };
372
+ }
373
+ };
374
+ }
375
+ /**
376
+ * Create a conversational message creator using the orchestrator
377
+ */
378
+ function createConversationalCreator(orchestratorClient) {
379
+ return async (messages) => {
380
+ const userMessages = messages.filter((m) => m.role === 'user');
381
+ const exchangeCount = Math.floor(messages.length / 2);
382
+ // First message - analyze and ask first contextual question
383
+ if (messages.length === 1 && userMessages[0]) {
384
+ const initialDescription = userMessages[0].content;
385
+ const analysis = analyzeMessageDescription(initialDescription);
386
+ // Pick the most relevant question based on domain analysis
387
+ if (analysis.contextualQuestions.length > 0) {
388
+ const firstQuestion = analysis.contextualQuestions[0];
389
+ return {
390
+ type: 'question',
391
+ question: firstQuestion || `What specific behavior should this system message guide?`,
392
+ };
393
+ }
394
+ }
395
+ // Second exchange - ask another contextual question
396
+ if (exchangeCount === 1 && userMessages[0]) {
397
+ const initialDescription = userMessages[0].content;
398
+ const analysis = analyzeMessageDescription(initialDescription);
399
+ // Get the second question
400
+ if (analysis.contextualQuestions.length > 1) {
401
+ const secondQuestion = analysis.contextualQuestions[1];
402
+ return {
403
+ type: 'question',
404
+ question: secondQuestion || 'What priority should this message have relative to other system messages?',
405
+ };
406
+ }
407
+ }
408
+ // Third exchange or more - generate the profile using AI
409
+ if (exchangeCount >= 2 || messages.length >= 4) {
410
+ // Build conversation summary for AI
411
+ const conversationSummary = messages
412
+ .map((m) => `${m.role === 'user' ? 'User' : 'AI'}: ${m.content}`)
413
+ .join('\n\n');
414
+ const prompt = `Based on this conversation, generate a complete system message profile:
415
+
416
+ ${conversationSummary}
417
+
418
+ Generate the JSON profile now. Remember: ONLY valid JSON, no other text.`;
419
+ try {
420
+ const response = await orchestratorClient.sendMessage(prompt, {
421
+ system: PROFILE_GENERATOR_PROMPT,
422
+ temperature: 0.7,
423
+ });
424
+ // Extract the response text
425
+ let responseText = '';
426
+ if (typeof response === 'string') {
427
+ responseText = response;
428
+ }
429
+ else if (response && typeof response === 'object') {
430
+ if ('text' in response) {
431
+ responseText = response.text;
432
+ }
433
+ else if ('content' in response && Array.isArray(response.content)) {
434
+ for (const block of response.content) {
435
+ if (block && typeof block === 'object' && 'text' in block) {
436
+ responseText += block.text;
437
+ }
438
+ }
439
+ }
440
+ }
441
+ // Extract JSON from response
442
+ let jsonStr = responseText.trim();
443
+ // Remove markdown code fences if present
444
+ const jsonMatch = jsonStr.match(/```(?:json)?\s*([\s\S]*?)```/);
445
+ if (jsonMatch) {
446
+ jsonStr = jsonMatch[1]?.trim() || jsonStr;
447
+ }
448
+ // Find JSON object
449
+ const startBrace = jsonStr.indexOf('{');
450
+ const endBrace = jsonStr.lastIndexOf('}');
451
+ if (startBrace !== -1 && endBrace !== -1) {
452
+ jsonStr = jsonStr.slice(startBrace, endBrace + 1);
453
+ }
454
+ const profile = JSON.parse(jsonStr);
455
+ // Validate and sanitize
456
+ if (!profile.id || !profile.type || !profile.content) {
457
+ throw new Error('Missing required profile fields');
458
+ }
459
+ const safeId = String(profile.id)
460
+ .toLowerCase()
461
+ .replace(/[^a-z0-9-]/g, '-')
462
+ .replace(/--+/g, '-')
463
+ .replace(/^-|-$/g, '')
464
+ .slice(0, 48);
465
+ return {
466
+ type: 'profile',
467
+ profile: {
468
+ id: safeId || `message-${Date.now()}`,
469
+ type: profile.type,
470
+ displayName: profile.displayName || safeId,
471
+ description: String(profile.description || '').slice(0, 200),
472
+ priority: typeof profile.priority === 'number' ? profile.priority : 50,
473
+ content: String(profile.content),
474
+ },
475
+ };
476
+ }
477
+ catch (error) {
478
+ // Fallback: generate a reasonable profile from conversation
479
+ console.error('AI profile generation failed:', error.message);
480
+ const initialDescription = userMessages[0]?.content || 'custom message';
481
+ const allUserInput = userMessages.map((m) => m.content).join(' ');
482
+ const analysis = analyzeMessageDescription(allUserInput);
483
+ const safeId = initialDescription
484
+ .toLowerCase()
485
+ .replace(/[^a-z0-9]+/g, '-')
486
+ .replace(/^-|-$/g, '')
487
+ .slice(0, 48) || `message-${Date.now()}`;
488
+ return {
489
+ type: 'profile',
490
+ profile: {
491
+ id: safeId,
492
+ type: analysis.suggestedType,
493
+ displayName: initialDescription.slice(0, 50),
494
+ description: initialDescription.slice(0, 200),
495
+ priority: analysis.suggestedPriority,
496
+ content: `# ${initialDescription.slice(0, 50)}
497
+
498
+ ## Overview
499
+
500
+ ${allUserInput}
501
+
502
+ ## Guidelines
503
+
504
+ - Follow the instructions described above
505
+ - Be thorough and consistent in applying these guidelines
506
+ - Ask for clarification when the situation is ambiguous
507
+
508
+ ## Examples
509
+
510
+ Consider these scenarios when applying this guidance:
511
+ - Standard cases should follow the main guidelines
512
+ - Edge cases may require additional consideration`,
513
+ },
514
+ };
515
+ }
516
+ }
517
+ // Fallback - ask a contextual question based on what we know
518
+ const allText = userMessages.map((m) => m.content).join(' ');
519
+ const analysis = analyzeMessageDescription(allText);
520
+ // Try to find an unused question
521
+ const questionIndex = Math.min(exchangeCount, analysis.contextualQuestions.length - 1);
522
+ const question = analysis.contextualQuestions[questionIndex] ||
523
+ 'What examples or scenarios should this system message address?';
524
+ return {
525
+ type: 'question',
526
+ question,
527
+ };
528
+ };
529
+ }
530
+ /**
531
+ * Create an AI edit assistant using the orchestrator
532
+ */
533
+ function createEditAssistant(orchestratorClient) {
534
+ return async (currentContent, editRequest) => {
535
+ const prompt = `Current system message content:
536
+
537
+ \`\`\`markdown
538
+ ${currentContent}
539
+ \`\`\`
540
+
541
+ User's modification request: "${editRequest}"
542
+
543
+ Generate the updated content as JSON. Remember: ONLY valid JSON, no other text.`;
544
+ try {
545
+ const response = await orchestratorClient.sendMessage(prompt, {
546
+ system: EDIT_ASSISTANT_PROMPT,
547
+ temperature: 0.7,
548
+ });
549
+ // Extract the response text
550
+ let responseText = '';
551
+ if (typeof response === 'string') {
552
+ responseText = response;
553
+ }
554
+ else if (response && typeof response === 'object') {
555
+ if ('text' in response) {
556
+ responseText = response.text;
557
+ }
558
+ else if ('content' in response && Array.isArray(response.content)) {
559
+ for (const block of response.content) {
560
+ if (block && typeof block === 'object' && 'text' in block) {
561
+ responseText += block.text;
562
+ }
563
+ }
564
+ }
565
+ }
566
+ // Extract JSON from response
567
+ let jsonStr = responseText.trim();
568
+ // Remove markdown code fences if present
569
+ const jsonMatch = jsonStr.match(/```(?:json)?\s*([\s\S]*?)```/);
570
+ if (jsonMatch) {
571
+ jsonStr = jsonMatch[1]?.trim() || jsonStr;
572
+ }
573
+ // Find JSON object
574
+ const startBrace = jsonStr.indexOf('{');
575
+ const endBrace = jsonStr.lastIndexOf('}');
576
+ if (startBrace !== -1 && endBrace !== -1) {
577
+ jsonStr = jsonStr.slice(startBrace, endBrace + 1);
578
+ }
579
+ const result = JSON.parse(jsonStr);
580
+ if (!result.content || typeof result.content !== 'string') {
581
+ throw new Error('Invalid response: missing content');
582
+ }
583
+ return {
584
+ content: result.content,
585
+ summary: result.summary || 'Content updated based on your request',
586
+ };
587
+ }
588
+ catch (error) {
589
+ console.error('AI edit failed:', error.message);
590
+ throw new Error(`AI edit failed: ${error.message}`);
591
+ }
592
+ };
593
+ }
594
+ /**
595
+ * Run system message management command
596
+ *
597
+ * @param config - Command configuration
598
+ */
599
+ export async function runSystemMessageCommand(config) {
600
+ // Ensure runtime directory exists
601
+ await fs.mkdir(config.runtimeDir, { recursive: true });
602
+ await fs.mkdir(path.join(config.runtimeDir, 'messages'), { recursive: true });
603
+ // Initialize store
604
+ const store = new SystemMessageStore({
605
+ builtinDir: config.builtinDir,
606
+ runtimeDir: config.runtimeDir,
607
+ workspaceDir: config.workspaceDir,
608
+ enableWatching: true,
609
+ debug: config.debug || false,
610
+ });
611
+ await store.initialize();
612
+ // Create AI generators if orchestrator is available
613
+ let generateProfile;
614
+ let conversationalCreator;
615
+ let editAssistant;
616
+ if (config.orchestratorClient) {
617
+ generateProfile = createProfileGenerator(config.orchestratorClient);
618
+ conversationalCreator = createConversationalCreator(config.orchestratorClient);
619
+ editAssistant = createEditAssistant(config.orchestratorClient);
620
+ }
621
+ // Render interactive menu
622
+ const { unmount, waitUntilExit } = render(React.createElement(InteractiveMenu, {
623
+ store,
624
+ runtimeDir: config.runtimeDir,
625
+ builtinDir: config.builtinDir,
626
+ initialMessageId: config.initialMessageId,
627
+ generateProfile,
628
+ conversationalCreator,
629
+ editAssistant,
630
+ onExit: () => {
631
+ // Use unmount for graceful return to CLI instead of exit() which kills the process
632
+ unmount();
633
+ },
634
+ }));
635
+ // Wait for user to exit
636
+ await waitUntilExit();
637
+ // Cleanup
638
+ await store.destroy();
639
+ }
640
+ /**
641
+ * Create and run system message command with context-aware paths
642
+ *
643
+ * Uses the core library's ContextResolver to determine where to store/read customizations:
644
+ * - Workspace context: {workspaceRoot}/.cortex/system-messages/
645
+ * - Project context: {projectDir}/.cortex/system-messages/
646
+ * - Global context: ~/.cortex/system-messages/
647
+ *
648
+ * Built-in messages always come from the installed package location.
649
+ *
650
+ * @param cwd - Current working directory (typically process.cwd())
651
+ * @param options - Additional options
652
+ */
653
+ export async function createSystemMessageCommand(cwd, options = {}) {
654
+ // Use core library's ContextResolver for consistent context-aware path resolution
655
+ const { resolveContext } = await import('@nexus-cortex/core/utils/ContextResolver.js');
656
+ const context = resolveContext({ cwd, debug: options.debug });
657
+ // Runtime directory from context resolver (systemMessagesDir is the full path)
658
+ const runtimeDir = context.systemMessagesDir;
659
+ // Builtin directory: find relative to installed package using import.meta.url
660
+ const { fileURLToPath } = await import('url');
661
+ const { dirname, join } = await import('path');
662
+ const currentFile = fileURLToPath(import.meta.url);
663
+ // From packages/cli/dist/commands/system-message, go to packages/core/dist/system-messages
664
+ const cliDistDir = dirname(dirname(dirname(currentFile))); // packages/cli/dist
665
+ const packagesDir = dirname(dirname(cliDistDir)); // packages/
666
+ const builtinDir = join(packagesDir, 'core', 'dist', 'system-messages');
667
+ // Check if builtin directory exists
668
+ try {
669
+ await fs.access(builtinDir);
670
+ }
671
+ catch {
672
+ throw new Error(`Builtin messages directory not found at ${builtinDir}. ` +
673
+ `Please build the core package first: npm run build`);
674
+ }
675
+ if (options.debug) {
676
+ console.log(`[SystemMessage] Context level: ${context.contextLevel}`);
677
+ console.log(`[SystemMessage] Context root: ${context.contextRoot}`);
678
+ console.log(`[SystemMessage] Runtime dir: ${runtimeDir}`);
679
+ console.log(`[SystemMessage] Builtin dir: ${builtinDir}`);
680
+ }
681
+ await runSystemMessageCommand({
682
+ runtimeDir,
683
+ builtinDir,
684
+ debug: options.debug,
685
+ initialMessageId: options.initialMessageId,
686
+ orchestratorClient: options.orchestratorClient,
687
+ });
688
+ }
689
+ /**
690
+ * Export components for external use
691
+ */
692
+ export { InteractiveMenu } from './InteractiveMenu.js';
693
+ export { EditorLauncher } from './EditorLauncher.js';
694
+ //# sourceMappingURL=index.js.map