@dirgha/code 1.2.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 (360) hide show
  1. package/LICENSE +101 -0
  2. package/README.md +674 -0
  3. package/dist/dirgha.mjs +2185 -0
  4. package/dist_v2/acp/index.d.ts +1 -0
  5. package/dist_v2/acp/index.js +2 -0
  6. package/dist_v2/acp/server.d.ts +31 -0
  7. package/dist_v2/acp/server.js +137 -0
  8. package/dist_v2/cli/auth-cmd.d.ts +10 -0
  9. package/dist_v2/cli/auth-cmd.js +69 -0
  10. package/dist_v2/cli/config.d.ts +46 -0
  11. package/dist_v2/cli/config.js +70 -0
  12. package/dist_v2/cli/flags.d.ts +10 -0
  13. package/dist_v2/cli/flags.js +49 -0
  14. package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
  15. package/dist_v2/cli/flows/full-cycle.js +39 -0
  16. package/dist_v2/cli/flows/index.d.ts +2 -0
  17. package/dist_v2/cli/flows/index.js +3 -0
  18. package/dist_v2/cli/flows/tarball.d.ts +10 -0
  19. package/dist_v2/cli/flows/tarball.js +47 -0
  20. package/dist_v2/cli/index.d.ts +4 -0
  21. package/dist_v2/cli/index.js +5 -0
  22. package/dist_v2/cli/interactive.d.ts +21 -0
  23. package/dist_v2/cli/interactive.js +207 -0
  24. package/dist_v2/cli/main.d.ts +10 -0
  25. package/dist_v2/cli/main.js +173 -0
  26. package/dist_v2/cli/models-cmd.d.ts +6 -0
  27. package/dist_v2/cli/models-cmd.js +50 -0
  28. package/dist_v2/cli/setup.d.ts +13 -0
  29. package/dist_v2/cli/setup.js +128 -0
  30. package/dist_v2/cli/slash/account.d.ts +10 -0
  31. package/dist_v2/cli/slash/account.js +59 -0
  32. package/dist_v2/cli/slash/clear.d.ts +8 -0
  33. package/dist_v2/cli/slash/clear.js +15 -0
  34. package/dist_v2/cli/slash/compact.d.ts +7 -0
  35. package/dist_v2/cli/slash/compact.js +13 -0
  36. package/dist_v2/cli/slash/config.d.ts +8 -0
  37. package/dist_v2/cli/slash/config.js +49 -0
  38. package/dist_v2/cli/slash/exit.d.ts +7 -0
  39. package/dist_v2/cli/slash/exit.js +16 -0
  40. package/dist_v2/cli/slash/fleet.d.ts +7 -0
  41. package/dist_v2/cli/slash/fleet.js +22 -0
  42. package/dist_v2/cli/slash/help.d.ts +9 -0
  43. package/dist_v2/cli/slash/help.js +31 -0
  44. package/dist_v2/cli/slash/history.d.ts +7 -0
  45. package/dist_v2/cli/slash/history.js +42 -0
  46. package/dist_v2/cli/slash/index.d.ts +30 -0
  47. package/dist_v2/cli/slash/index.js +52 -0
  48. package/dist_v2/cli/slash/init.d.ts +8 -0
  49. package/dist_v2/cli/slash/init.js +57 -0
  50. package/dist_v2/cli/slash/keys.d.ts +8 -0
  51. package/dist_v2/cli/slash/keys.js +101 -0
  52. package/dist_v2/cli/slash/login.d.ts +10 -0
  53. package/dist_v2/cli/slash/login.js +47 -0
  54. package/dist_v2/cli/slash/memory.d.ts +8 -0
  55. package/dist_v2/cli/slash/memory.js +101 -0
  56. package/dist_v2/cli/slash/mode.d.ts +8 -0
  57. package/dist_v2/cli/slash/mode.js +30 -0
  58. package/dist_v2/cli/slash/models.d.ts +8 -0
  59. package/dist_v2/cli/slash/models.js +73 -0
  60. package/dist_v2/cli/slash/resume.d.ts +8 -0
  61. package/dist_v2/cli/slash/resume.js +24 -0
  62. package/dist_v2/cli/slash/session.d.ts +8 -0
  63. package/dist_v2/cli/slash/session.js +74 -0
  64. package/dist_v2/cli/slash/setup.d.ts +8 -0
  65. package/dist_v2/cli/slash/setup.js +50 -0
  66. package/dist_v2/cli/slash/status.d.ts +7 -0
  67. package/dist_v2/cli/slash/status.js +37 -0
  68. package/dist_v2/cli/slash/theme.d.ts +9 -0
  69. package/dist_v2/cli/slash/theme.js +53 -0
  70. package/dist_v2/cli/slash/types.d.ts +14 -0
  71. package/dist_v2/cli/slash/types.js +9 -0
  72. package/dist_v2/cli/slash/upgrade.d.ts +9 -0
  73. package/dist_v2/cli/slash/upgrade.js +66 -0
  74. package/dist_v2/cli/slash.d.ts +72 -0
  75. package/dist_v2/cli/slash.js +77 -0
  76. package/dist_v2/cli/subcommands/ask.d.ts +17 -0
  77. package/dist_v2/cli/subcommands/ask.js +76 -0
  78. package/dist_v2/cli/subcommands/audit.d.ts +15 -0
  79. package/dist_v2/cli/subcommands/audit.js +128 -0
  80. package/dist_v2/cli/subcommands/chat.d.ts +13 -0
  81. package/dist_v2/cli/subcommands/chat.js +72 -0
  82. package/dist_v2/cli/subcommands/compact.d.ts +14 -0
  83. package/dist_v2/cli/subcommands/compact.js +114 -0
  84. package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
  85. package/dist_v2/cli/subcommands/doctor.js +103 -0
  86. package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
  87. package/dist_v2/cli/subcommands/export-session.js +60 -0
  88. package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
  89. package/dist_v2/cli/subcommands/import-session.js +77 -0
  90. package/dist_v2/cli/subcommands/index.d.ts +40 -0
  91. package/dist_v2/cli/subcommands/index.js +38 -0
  92. package/dist_v2/cli/subcommands/init.d.ts +10 -0
  93. package/dist_v2/cli/subcommands/init.js +74 -0
  94. package/dist_v2/cli/subcommands/keys.d.ts +12 -0
  95. package/dist_v2/cli/subcommands/keys.js +136 -0
  96. package/dist_v2/cli/subcommands/login.d.ts +10 -0
  97. package/dist_v2/cli/subcommands/login.js +60 -0
  98. package/dist_v2/cli/subcommands/logout.d.ts +10 -0
  99. package/dist_v2/cli/subcommands/logout.js +21 -0
  100. package/dist_v2/cli/subcommands/models.d.ts +14 -0
  101. package/dist_v2/cli/subcommands/models.js +144 -0
  102. package/dist_v2/cli/subcommands/setup.d.ts +11 -0
  103. package/dist_v2/cli/subcommands/setup.js +107 -0
  104. package/dist_v2/cli/subcommands/stats.d.ts +13 -0
  105. package/dist_v2/cli/subcommands/stats.js +148 -0
  106. package/dist_v2/cli/subcommands/status.d.ts +14 -0
  107. package/dist_v2/cli/subcommands/status.js +91 -0
  108. package/dist_v2/cli/submit-paper.d.ts +15 -0
  109. package/dist_v2/cli/submit-paper.js +68 -0
  110. package/dist_v2/context/_fts.d.ts +62 -0
  111. package/dist_v2/context/_fts.js +195 -0
  112. package/dist_v2/context/branch.d.ts +18 -0
  113. package/dist_v2/context/branch.js +66 -0
  114. package/dist_v2/context/compaction.d.ts +26 -0
  115. package/dist_v2/context/compaction.js +120 -0
  116. package/dist_v2/context/index.d.ts +5 -0
  117. package/dist_v2/context/index.js +6 -0
  118. package/dist_v2/context/knowledge.d.ts +38 -0
  119. package/dist_v2/context/knowledge.js +146 -0
  120. package/dist_v2/context/memory.d.ts +80 -0
  121. package/dist_v2/context/memory.js +276 -0
  122. package/dist_v2/context/mode.d.ts +25 -0
  123. package/dist_v2/context/mode.js +81 -0
  124. package/dist_v2/context/session.d.ts +56 -0
  125. package/dist_v2/context/session.js +108 -0
  126. package/dist_v2/daemon/index.d.ts +2 -0
  127. package/dist_v2/daemon/index.js +3 -0
  128. package/dist_v2/daemon/protocol.d.ts +73 -0
  129. package/dist_v2/daemon/protocol.js +6 -0
  130. package/dist_v2/daemon/server.d.ts +35 -0
  131. package/dist_v2/daemon/server.js +191 -0
  132. package/dist_v2/eval/index.d.ts +5 -0
  133. package/dist_v2/eval/index.js +6 -0
  134. package/dist_v2/eval/regression.d.ts +14 -0
  135. package/dist_v2/eval/regression.js +106 -0
  136. package/dist_v2/eval/reporter.d.ts +7 -0
  137. package/dist_v2/eval/reporter.js +34 -0
  138. package/dist_v2/eval/swe-bench.d.ts +18 -0
  139. package/dist_v2/eval/swe-bench.js +23 -0
  140. package/dist_v2/eval/terminal-bench.d.ts +13 -0
  141. package/dist_v2/eval/terminal-bench.js +19 -0
  142. package/dist_v2/eval/types.d.ts +36 -0
  143. package/dist_v2/eval/types.js +5 -0
  144. package/dist_v2/fleet/apply-back.d.ts +27 -0
  145. package/dist_v2/fleet/apply-back.js +191 -0
  146. package/dist_v2/fleet/cli-command.d.ts +61 -0
  147. package/dist_v2/fleet/cli-command.js +329 -0
  148. package/dist_v2/fleet/index.d.ts +21 -0
  149. package/dist_v2/fleet/index.js +21 -0
  150. package/dist_v2/fleet/runner.d.ts +28 -0
  151. package/dist_v2/fleet/runner.js +347 -0
  152. package/dist_v2/fleet/tripleshot.d.ts +21 -0
  153. package/dist_v2/fleet/tripleshot.js +222 -0
  154. package/dist_v2/fleet/types.d.ts +193 -0
  155. package/dist_v2/fleet/types.js +24 -0
  156. package/dist_v2/fleet/worktree.d.ts +51 -0
  157. package/dist_v2/fleet/worktree.js +176 -0
  158. package/dist_v2/hooks/index.d.ts +1 -0
  159. package/dist_v2/hooks/index.js +2 -0
  160. package/dist_v2/hooks/registry.d.ts +21 -0
  161. package/dist_v2/hooks/registry.js +40 -0
  162. package/dist_v2/index.d.ts +12 -0
  163. package/dist_v2/index.js +11 -0
  164. package/dist_v2/integrations/arniko-client.d.ts +42 -0
  165. package/dist_v2/integrations/arniko-client.js +86 -0
  166. package/dist_v2/integrations/auth.d.ts +45 -0
  167. package/dist_v2/integrations/auth.js +54 -0
  168. package/dist_v2/integrations/billing.d.ts +71 -0
  169. package/dist_v2/integrations/billing.js +107 -0
  170. package/dist_v2/integrations/bucky-client.d.ts +105 -0
  171. package/dist_v2/integrations/bucky-client.js +76 -0
  172. package/dist_v2/integrations/deploy-client.d.ts +60 -0
  173. package/dist_v2/integrations/deploy-client.js +87 -0
  174. package/dist_v2/integrations/device-auth.d.ts +48 -0
  175. package/dist_v2/integrations/device-auth.js +192 -0
  176. package/dist_v2/integrations/entitlements.d.ts +34 -0
  177. package/dist_v2/integrations/entitlements.js +43 -0
  178. package/dist_v2/integrations/http.d.ts +22 -0
  179. package/dist_v2/integrations/http.js +114 -0
  180. package/dist_v2/integrations/index.d.ts +8 -0
  181. package/dist_v2/integrations/index.js +15 -0
  182. package/dist_v2/intelligence/cost.d.ts +28 -0
  183. package/dist_v2/intelligence/cost.js +58 -0
  184. package/dist_v2/intelligence/error-classifier.d.ts +8 -0
  185. package/dist_v2/intelligence/error-classifier.js +71 -0
  186. package/dist_v2/intelligence/index.d.ts +5 -0
  187. package/dist_v2/intelligence/index.js +6 -0
  188. package/dist_v2/intelligence/prices.d.ts +13 -0
  189. package/dist_v2/intelligence/prices.js +26 -0
  190. package/dist_v2/intelligence/smart-router.d.ts +21 -0
  191. package/dist_v2/intelligence/smart-router.js +59 -0
  192. package/dist_v2/intelligence/telemetry.d.ts +22 -0
  193. package/dist_v2/intelligence/telemetry.js +31 -0
  194. package/dist_v2/kernel/agent-loop.d.ts +32 -0
  195. package/dist_v2/kernel/agent-loop.js +151 -0
  196. package/dist_v2/kernel/event-stream.d.ts +18 -0
  197. package/dist_v2/kernel/event-stream.js +102 -0
  198. package/dist_v2/kernel/index.d.ts +4 -0
  199. package/dist_v2/kernel/index.js +5 -0
  200. package/dist_v2/kernel/message.d.ts +29 -0
  201. package/dist_v2/kernel/message.js +118 -0
  202. package/dist_v2/kernel/types.d.ts +206 -0
  203. package/dist_v2/kernel/types.js +9 -0
  204. package/dist_v2/mcp/client.d.ts +44 -0
  205. package/dist_v2/mcp/client.js +63 -0
  206. package/dist_v2/mcp/index.d.ts +3 -0
  207. package/dist_v2/mcp/index.js +4 -0
  208. package/dist_v2/mcp/tool-bridge.d.ts +11 -0
  209. package/dist_v2/mcp/tool-bridge.js +33 -0
  210. package/dist_v2/mcp/transport.d.ts +29 -0
  211. package/dist_v2/mcp/transport.js +73 -0
  212. package/dist_v2/parity/index.d.ts +3 -0
  213. package/dist_v2/parity/index.js +4 -0
  214. package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
  215. package/dist_v2/parity/mock-openai-compat.js +35 -0
  216. package/dist_v2/parity/runner.d.ts +21 -0
  217. package/dist_v2/parity/runner.js +76 -0
  218. package/dist_v2/parity/scenarios.d.ts +20 -0
  219. package/dist_v2/parity/scenarios.js +70 -0
  220. package/dist_v2/providers/anthropic.d.ts +21 -0
  221. package/dist_v2/providers/anthropic.js +191 -0
  222. package/dist_v2/providers/dispatch.d.ts +11 -0
  223. package/dist_v2/providers/dispatch.js +45 -0
  224. package/dist_v2/providers/fireworks.d.ts +18 -0
  225. package/dist_v2/providers/fireworks.js +44 -0
  226. package/dist_v2/providers/gemini.d.ts +19 -0
  227. package/dist_v2/providers/gemini.js +188 -0
  228. package/dist_v2/providers/http.d.ts +41 -0
  229. package/dist_v2/providers/http.js +188 -0
  230. package/dist_v2/providers/iface.d.ts +18 -0
  231. package/dist_v2/providers/iface.js +18 -0
  232. package/dist_v2/providers/index.d.ts +39 -0
  233. package/dist_v2/providers/index.js +51 -0
  234. package/dist_v2/providers/nvidia.d.ts +27 -0
  235. package/dist_v2/providers/nvidia.js +142 -0
  236. package/dist_v2/providers/ollama.d.ts +15 -0
  237. package/dist_v2/providers/ollama.js +37 -0
  238. package/dist_v2/providers/openai-compat.d.ts +29 -0
  239. package/dist_v2/providers/openai-compat.js +239 -0
  240. package/dist_v2/providers/openai.d.ts +20 -0
  241. package/dist_v2/providers/openai.js +107 -0
  242. package/dist_v2/providers/openrouter.d.ts +24 -0
  243. package/dist_v2/providers/openrouter.js +69 -0
  244. package/dist_v2/safety/approval-bus.d.ts +26 -0
  245. package/dist_v2/safety/approval-bus.js +48 -0
  246. package/dist_v2/safety/audit-log.d.ts +27 -0
  247. package/dist_v2/safety/audit-log.js +71 -0
  248. package/dist_v2/safety/index.d.ts +4 -0
  249. package/dist_v2/safety/index.js +5 -0
  250. package/dist_v2/safety/policy.d.ts +32 -0
  251. package/dist_v2/safety/policy.js +131 -0
  252. package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
  253. package/dist_v2/safety/sandbox/bwrap.js +52 -0
  254. package/dist_v2/safety/sandbox/iface.d.ts +29 -0
  255. package/dist_v2/safety/sandbox/iface.js +8 -0
  256. package/dist_v2/safety/sandbox/index.d.ts +7 -0
  257. package/dist_v2/safety/sandbox/index.js +8 -0
  258. package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
  259. package/dist_v2/safety/sandbox/landlock.js +26 -0
  260. package/dist_v2/safety/sandbox/noop.d.ts +12 -0
  261. package/dist_v2/safety/sandbox/noop.js +52 -0
  262. package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
  263. package/dist_v2/safety/sandbox/seatbelt.js +49 -0
  264. package/dist_v2/safety/sandbox/select.d.ts +6 -0
  265. package/dist_v2/safety/sandbox/select.js +42 -0
  266. package/dist_v2/safety/sandbox/windows.d.ts +13 -0
  267. package/dist_v2/safety/sandbox/windows.js +22 -0
  268. package/dist_v2/skills/index.d.ts +3 -0
  269. package/dist_v2/skills/index.js +4 -0
  270. package/dist_v2/skills/loader.d.ts +38 -0
  271. package/dist_v2/skills/loader.js +102 -0
  272. package/dist_v2/skills/matcher.d.ts +14 -0
  273. package/dist_v2/skills/matcher.js +72 -0
  274. package/dist_v2/skills/runtime.d.ts +13 -0
  275. package/dist_v2/skills/runtime.js +40 -0
  276. package/dist_v2/subagents/delegator.d.ts +36 -0
  277. package/dist_v2/subagents/delegator.js +82 -0
  278. package/dist_v2/subagents/index.d.ts +2 -0
  279. package/dist_v2/subagents/index.js +3 -0
  280. package/dist_v2/subagents/pool.d.ts +18 -0
  281. package/dist_v2/subagents/pool.js +31 -0
  282. package/dist_v2/tools/browser.d.ts +27 -0
  283. package/dist_v2/tools/browser.js +179 -0
  284. package/dist_v2/tools/checkpoint.d.ts +25 -0
  285. package/dist_v2/tools/checkpoint.js +222 -0
  286. package/dist_v2/tools/cron.d.ts +32 -0
  287. package/dist_v2/tools/cron.js +160 -0
  288. package/dist_v2/tools/diff.d.ts +18 -0
  289. package/dist_v2/tools/diff.js +117 -0
  290. package/dist_v2/tools/exec.d.ts +19 -0
  291. package/dist_v2/tools/exec.js +49 -0
  292. package/dist_v2/tools/fs-edit.d.ts +11 -0
  293. package/dist_v2/tools/fs-edit.js +81 -0
  294. package/dist_v2/tools/fs-ls.d.ts +7 -0
  295. package/dist_v2/tools/fs-ls.js +57 -0
  296. package/dist_v2/tools/fs-read.d.ts +7 -0
  297. package/dist_v2/tools/fs-read.js +60 -0
  298. package/dist_v2/tools/fs-write.d.ts +8 -0
  299. package/dist_v2/tools/fs-write.js +46 -0
  300. package/dist_v2/tools/git.d.ts +8 -0
  301. package/dist_v2/tools/git.js +57 -0
  302. package/dist_v2/tools/index.d.ts +25 -0
  303. package/dist_v2/tools/index.js +39 -0
  304. package/dist_v2/tools/multimodal.d.ts +41 -0
  305. package/dist_v2/tools/multimodal.js +381 -0
  306. package/dist_v2/tools/permission.d.ts +27 -0
  307. package/dist_v2/tools/permission.js +43 -0
  308. package/dist_v2/tools/registry.d.ts +44 -0
  309. package/dist_v2/tools/registry.js +62 -0
  310. package/dist_v2/tools/search-glob.d.ts +7 -0
  311. package/dist_v2/tools/search-glob.js +98 -0
  312. package/dist_v2/tools/search-grep.d.ts +7 -0
  313. package/dist_v2/tools/search-grep.js +109 -0
  314. package/dist_v2/tools/shell.d.ts +10 -0
  315. package/dist_v2/tools/shell.js +76 -0
  316. package/dist_v2/tools/task.d.ts +8 -0
  317. package/dist_v2/tools/task.js +37 -0
  318. package/dist_v2/tui/approval.d.ts +7 -0
  319. package/dist_v2/tui/approval.js +55 -0
  320. package/dist_v2/tui/index.d.ts +4 -0
  321. package/dist_v2/tui/index.js +5 -0
  322. package/dist_v2/tui/ink/App.d.ts +39 -0
  323. package/dist_v2/tui/ink/App.js +206 -0
  324. package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
  325. package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
  326. package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
  327. package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
  328. package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
  329. package/dist_v2/tui/ink/components/InputBox.js +153 -0
  330. package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
  331. package/dist_v2/tui/ink/components/Logo.js +27 -0
  332. package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
  333. package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
  334. package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
  335. package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
  336. package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
  337. package/dist_v2/tui/ink/components/StatusBar.js +41 -0
  338. package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
  339. package/dist_v2/tui/ink/components/StreamingText.js +11 -0
  340. package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
  341. package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
  342. package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
  343. package/dist_v2/tui/ink/components/ToolBox.js +63 -0
  344. package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
  345. package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
  346. package/dist_v2/tui/ink/index.d.ts +39 -0
  347. package/dist_v2/tui/ink/index.js +47 -0
  348. package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
  349. package/dist_v2/tui/ink/use-event-projection.js +126 -0
  350. package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
  351. package/dist_v2/tui/ink/use-overlays.js +50 -0
  352. package/dist_v2/tui/renderer.d.ts +19 -0
  353. package/dist_v2/tui/renderer.js +64 -0
  354. package/dist_v2/tui/status-bar.d.ts +12 -0
  355. package/dist_v2/tui/status-bar.js +16 -0
  356. package/dist_v2/tui/theme.d.ts +27 -0
  357. package/dist_v2/tui/theme.js +56 -0
  358. package/dist_v2/utils/json-repair.d.ts +7 -0
  359. package/dist_v2/utils/json-repair.js +45 -0
  360. package/package.json +113 -0
@@ -0,0 +1,101 @@
1
+ /**
2
+ * /memory — operate on the long-term memory store at ~/.dirgha/memory.
3
+ * Subcommands: list, show <id>, add <id> <description>, remove <id>,
4
+ * search <query>. Bodies for `add` come from the args after the
5
+ * description and are stored as markdown.
6
+ */
7
+ import { createMemoryStore } from '../../context/memory.js';
8
+ const VALID_TYPES = ['user', 'feedback', 'project', 'reference'];
9
+ function usage() {
10
+ return [
11
+ 'Usage:',
12
+ ' /memory List memories',
13
+ ' /memory list Same as above',
14
+ ' /memory show <id> Dump a single memory',
15
+ ' /memory search <query> Full-text search',
16
+ ' /memory add <id> <description> Add a note (body = stdin later; for now, empty)',
17
+ ' /memory remove <id> Delete a memory',
18
+ ' /memory type <id> <type> Set type (user|feedback|project|reference)',
19
+ ].join('\n');
20
+ }
21
+ export const memoryCommand = {
22
+ name: 'memory',
23
+ description: 'Inspect or edit long-term memory in ~/.dirgha/memory',
24
+ async execute(args) {
25
+ const store = createMemoryStore();
26
+ const op = args[0] ?? 'list';
27
+ if (op === 'list') {
28
+ const all = await store.list();
29
+ if (all.length === 0)
30
+ return '(no memories yet — add one with `/memory add <id> <desc>`)';
31
+ return all.map(m => ` ${m.id.padEnd(30)} ${m.type.padEnd(10)} ${m.name}`).join('\n');
32
+ }
33
+ if (op === 'show') {
34
+ const id = args[1];
35
+ if (!id)
36
+ return `Missing id.\n${usage()}`;
37
+ const entry = await store.get(id);
38
+ if (!entry)
39
+ return `Memory "${id}" not found.`;
40
+ return [
41
+ `# ${entry.name}`,
42
+ `id: ${entry.id}`,
43
+ `type: ${entry.type}`,
44
+ `description: ${entry.description}`,
45
+ `updatedAt: ${entry.updatedAt}`,
46
+ '',
47
+ entry.body.trim() || '(empty body)',
48
+ ].join('\n');
49
+ }
50
+ if (op === 'search') {
51
+ const q = args.slice(1).join(' ');
52
+ if (!q)
53
+ return `Missing query.\n${usage()}`;
54
+ const hits = await store.search(q);
55
+ if (hits.length === 0)
56
+ return `No memories match "${q}".`;
57
+ return hits.map(m => ` ${m.id} — ${m.name}`).join('\n');
58
+ }
59
+ if (op === 'add') {
60
+ const [, id, ...descParts] = args;
61
+ if (!id)
62
+ return `Missing id.\n${usage()}`;
63
+ const now = new Date().toISOString();
64
+ await store.upsert({
65
+ id,
66
+ type: 'user',
67
+ name: id,
68
+ description: descParts.join(' ') || '(no description)',
69
+ body: '',
70
+ createdAt: now,
71
+ updatedAt: now,
72
+ });
73
+ return `Added memory "${id}". Edit ~/.dirgha/memory/${id}.md to fill the body.`;
74
+ }
75
+ if (op === 'remove' || op === 'rm') {
76
+ const id = args[1];
77
+ if (!id)
78
+ return `Missing id.\n${usage()}`;
79
+ const existing = await store.get(id);
80
+ if (!existing)
81
+ return `Memory "${id}" not found.`;
82
+ await store.remove(id);
83
+ return `Removed "${id}".`;
84
+ }
85
+ if (op === 'type') {
86
+ const [, id, typeArg] = args;
87
+ if (!id || !typeArg)
88
+ return `Missing args.\n${usage()}`;
89
+ if (!VALID_TYPES.includes(typeArg)) {
90
+ return `Type must be one of: ${VALID_TYPES.join(', ')}`;
91
+ }
92
+ const entry = await store.get(id);
93
+ if (!entry)
94
+ return `Memory "${id}" not found.`;
95
+ await store.upsert({ ...entry, type: typeArg });
96
+ return `Memory "${id}" now has type ${typeArg}.`;
97
+ }
98
+ return `Unknown subcommand "${op}".\n${usage()}`;
99
+ },
100
+ };
101
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * /mode — switch the REPL's execution mode. The mode is prepended to
3
+ * the system prompt of every subsequent turn via the interactive loop,
4
+ * which reads ctx.mode / ctx.setMode on each submit. Preference
5
+ * persists to ~/.dirgha/config.json so new sessions honour it.
6
+ */
7
+ import type { SlashCommand } from './types.js';
8
+ export declare const modeCommand: SlashCommand;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * /mode — switch the REPL's execution mode. The mode is prepended to
3
+ * the system prompt of every subsequent turn via the interactive loop,
4
+ * which reads ctx.mode / ctx.setMode on each submit. Preference
5
+ * persists to ~/.dirgha/config.json so new sessions honour it.
6
+ */
7
+ import { MODES, saveMode, modePreamble } from '../../context/mode.js';
8
+ export const modeCommand = {
9
+ name: 'mode',
10
+ description: 'Show or switch execution mode (plan|act|verify)',
11
+ async execute(args, ctx) {
12
+ const current = ctx.getMode();
13
+ if (args.length === 0) {
14
+ return [
15
+ `Current mode: ${current}`,
16
+ `Available: ${MODES.join(' · ')}`,
17
+ '',
18
+ modePreamble(current),
19
+ ].join('\n');
20
+ }
21
+ const next = args[0];
22
+ if (!MODES.includes(next)) {
23
+ return `Unknown mode "${next}". Choose one of: ${MODES.join(', ')}`;
24
+ }
25
+ await saveMode(next);
26
+ ctx.setMode(next);
27
+ return `Mode set to ${next}. ${next === 'plan' ? '(Read-only — no writes or shells.)' : next === 'verify' ? '(Read-only audit — no modifications.)' : '(Normal execution.)'}`;
28
+ },
29
+ };
30
+ //# sourceMappingURL=mode.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * /models — list every model in the v2 price catalogue grouped by
3
+ * provider, mark which providers are configured (env var present), and
4
+ * allow picking one as the current model for the REPL. Accepts either
5
+ * a numeric index or a full `provider/model` id.
6
+ */
7
+ import type { SlashCommand } from './types.js';
8
+ export declare const modelsCommand: SlashCommand;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * /models — list every model in the v2 price catalogue grouped by
3
+ * provider, mark which providers are configured (env var present), and
4
+ * allow picking one as the current model for the REPL. Accepts either
5
+ * a numeric index or a full `provider/model` id.
6
+ */
7
+ import { PRICES } from '../../intelligence/prices.js';
8
+ const ENV_FOR_PROVIDER = {
9
+ anthropic: 'ANTHROPIC_API_KEY',
10
+ openai: 'OPENAI_API_KEY',
11
+ gemini: 'GEMINI_API_KEY',
12
+ nvidia: 'NVIDIA_API_KEY',
13
+ openrouter: 'OPENROUTER_API_KEY',
14
+ ollama: '',
15
+ };
16
+ function priceText(value) {
17
+ return value === 0 ? 'free' : `$${value.toFixed(2)}/M`;
18
+ }
19
+ function configured(provider) {
20
+ const env = ENV_FOR_PROVIDER[provider];
21
+ if (!env)
22
+ return true;
23
+ return Boolean(process.env[env] && process.env[env].length > 0);
24
+ }
25
+ export const modelsCommand = {
26
+ name: 'models',
27
+ description: 'List models and optionally switch the current one',
28
+ async execute(args, ctx) {
29
+ const ordered = [...PRICES];
30
+ if (args.length > 0) {
31
+ const first = args[0];
32
+ if (/^\d+$/.test(first)) {
33
+ const idx = Number.parseInt(first, 10) - 1;
34
+ if (idx >= 0 && idx < ordered.length) {
35
+ const chosen = ordered[idx];
36
+ ctx.setModel(chosen.model);
37
+ return `Model set to ${chosen.model} (${chosen.provider}).`;
38
+ }
39
+ return `Index out of range. There are ${ordered.length} models.`;
40
+ }
41
+ const match = ordered.find(p => p.model === first);
42
+ if (match) {
43
+ ctx.setModel(match.model);
44
+ return `Model set to ${match.model} (${match.provider}).`;
45
+ }
46
+ ctx.setModel(first);
47
+ return `Model set to ${first} (not in catalogue — will only work if the provider accepts it).`;
48
+ }
49
+ const lines = ['Model catalogue (current: ' + ctx.model + '):'];
50
+ let i = 1;
51
+ const byProvider = new Map();
52
+ for (const row of ordered) {
53
+ const bucket = byProvider.get(row.provider) ?? [];
54
+ bucket.push(row);
55
+ byProvider.set(row.provider, bucket);
56
+ }
57
+ for (const [provider, rows] of byProvider) {
58
+ const env = ENV_FOR_PROVIDER[provider] ?? '';
59
+ const marker = configured(provider)
60
+ ? 'configured'
61
+ : env ? `set ${env} to enable` : 'no key required';
62
+ lines.push(`\n${provider} (${marker})`);
63
+ for (const row of rows) {
64
+ const mark = row.model === ctx.model ? '*' : ' ';
65
+ lines.push(` ${mark} ${String(i).padStart(2)}. ${row.model.padEnd(42)} in ${priceText(row.inputPerM).padEnd(10)} out ${priceText(row.outputPerM)}`);
66
+ i++;
67
+ }
68
+ }
69
+ lines.push('\nPick with `/models <number>` or `/models <model-id>`.');
70
+ return lines.join('\n');
71
+ },
72
+ };
73
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * /resume <sessionId> — load a previous session's transcript into the
3
+ * current REPL context. Defers to SlashContext.loadSession, which
4
+ * reads ~/.dirgha/sessions/<id>.jsonl and reports how many messages
5
+ * were replayed. Without an id, lists available sessions.
6
+ */
7
+ import type { SlashCommand } from './types.js';
8
+ export declare const resumeCommand: SlashCommand;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * /resume <sessionId> — load a previous session's transcript into the
3
+ * current REPL context. Defers to SlashContext.loadSession, which
4
+ * reads ~/.dirgha/sessions/<id>.jsonl and reports how many messages
5
+ * were replayed. Without an id, lists available sessions.
6
+ */
7
+ export const resumeCommand = {
8
+ name: 'resume',
9
+ description: 'Resume a prior session by id (or list them)',
10
+ async execute(args, ctx) {
11
+ const id = args[0];
12
+ if (!id) {
13
+ const list = await ctx.listSessions();
14
+ return [
15
+ 'Usage: /resume <session-id>',
16
+ '',
17
+ 'Available sessions:',
18
+ list,
19
+ ].join('\n');
20
+ }
21
+ return ctx.loadSession(id);
22
+ },
23
+ };
24
+ //# sourceMappingURL=resume.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * /session — list sessions, load, rename, or branch. Branching is
3
+ * wired through `context/branch.ts`, which takes a provider pointer +
4
+ * a summary model; the SlashContext exposes `getProvider()` +
5
+ * `getSummaryModel()` + `getSession()` + `getSessionStore()` for this.
6
+ */
7
+ import type { SlashCommand } from './types.js';
8
+ export declare const sessionCommand: SlashCommand;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * /session — list sessions, load, rename, or branch. Branching is
3
+ * wired through `context/branch.ts`, which takes a provider pointer +
4
+ * a summary model; the SlashContext exposes `getProvider()` +
5
+ * `getSummaryModel()` + `getSession()` + `getSessionStore()` for this.
6
+ */
7
+ import { rename, stat } from 'node:fs/promises';
8
+ import { homedir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ import { branchSession } from '../../context/branch.js';
11
+ function sessionPath(id) {
12
+ return join(homedir(), '.dirgha', 'sessions', `${id}.jsonl`);
13
+ }
14
+ function usage() {
15
+ return [
16
+ 'Usage:',
17
+ ' /session list List saved sessions',
18
+ ' /session load <id> Resume a session',
19
+ ' /session rename <old> <new> Rename a session file',
20
+ ' /session branch <name> Branch the current session with a summary',
21
+ ].join('\n');
22
+ }
23
+ export const sessionCommand = {
24
+ name: 'session',
25
+ description: 'Session management: list / load / rename / branch',
26
+ async execute(args, ctx) {
27
+ const op = args[0];
28
+ if (!op || op === 'list')
29
+ return ctx.listSessions();
30
+ if (op === 'load' && args[1])
31
+ return ctx.loadSession(args[1]);
32
+ if (op === 'rename') {
33
+ const [, oldId, newId] = args;
34
+ if (!oldId || !newId)
35
+ return `Missing argument.\n${usage()}`;
36
+ const fromPath = sessionPath(oldId);
37
+ const toPath = sessionPath(newId);
38
+ const oldExists = await stat(fromPath).then(() => true).catch(() => false);
39
+ if (!oldExists)
40
+ return `Session "${oldId}" not found.`;
41
+ const newExists = await stat(toPath).then(() => true).catch(() => false);
42
+ if (newExists)
43
+ return `Session "${newId}" already exists — refusing to overwrite.`;
44
+ await rename(fromPath, toPath);
45
+ return `Renamed ${oldId} → ${newId}.`;
46
+ }
47
+ if (op === 'branch') {
48
+ const name = args.slice(1).join('-');
49
+ if (!name)
50
+ return `Missing branch name.\n${usage()}`;
51
+ const parent = ctx.getSession();
52
+ const store = ctx.getSessionStore();
53
+ const provider = ctx.getProvider();
54
+ const summaryModel = ctx.getSummaryModel();
55
+ if (!parent || !store)
56
+ return 'No active session to branch from.';
57
+ if (!provider)
58
+ return 'No provider configured — cannot summarise parent context.';
59
+ const { child, summary } = await branchSession(parent, store, {
60
+ name,
61
+ summarizer: provider,
62
+ summaryModel,
63
+ });
64
+ return [
65
+ `Branched → ${child.id}`,
66
+ '',
67
+ 'Summary carried into child:',
68
+ summary.split('\n').map(l => ` ${l}`).join('\n'),
69
+ ].join('\n');
70
+ }
71
+ return `Unknown subcommand "${op}".\n${usage()}`;
72
+ },
73
+ };
74
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * /setup — minimal first-run wizard accessible from inside the REPL.
3
+ * The full wizard (../setup.ts) uses readline and takes over stdin,
4
+ * which is incompatible with the REPL loop. Instead, /setup shows the
5
+ * status of each provider + points to `dirgha setup` on the CLI.
6
+ */
7
+ import type { SlashCommand } from './types.js';
8
+ export declare const setupCommand: SlashCommand;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * /setup — minimal first-run wizard accessible from inside the REPL.
3
+ * The full wizard (../setup.ts) uses readline and takes over stdin,
4
+ * which is incompatible with the REPL loop. Instead, /setup shows the
5
+ * status of each provider + points to `dirgha setup` on the CLI.
6
+ */
7
+ import { readFile } from 'node:fs/promises';
8
+ import { homedir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ const PROVIDERS = [
11
+ { label: 'NVIDIA NIM', env: 'NVIDIA_API_KEY' },
12
+ { label: 'OpenRouter', env: 'OPENROUTER_API_KEY' },
13
+ { label: 'Anthropic', env: 'ANTHROPIC_API_KEY' },
14
+ { label: 'OpenAI', env: 'OPENAI_API_KEY' },
15
+ { label: 'Google AI', env: 'GEMINI_API_KEY' },
16
+ ];
17
+ async function readStoredKeys() {
18
+ const path = join(homedir(), '.dirgha', 'keys.json');
19
+ const text = await readFile(path, 'utf8').catch(() => '');
20
+ if (!text)
21
+ return {};
22
+ try {
23
+ return JSON.parse(text);
24
+ }
25
+ catch {
26
+ return {};
27
+ }
28
+ }
29
+ export const setupCommand = {
30
+ name: 'setup',
31
+ description: 'Show provider key status and point at the full wizard',
32
+ async execute(_args, ctx) {
33
+ const stored = await readStoredKeys();
34
+ const lines = ['Provider status:'];
35
+ for (const p of PROVIDERS) {
36
+ const fromEnv = process.env[p.env] && process.env[p.env].length > 0;
37
+ const fromStore = stored[p.env] && stored[p.env].length > 0;
38
+ const state = fromEnv ? 'env' : fromStore ? 'stored' : 'missing';
39
+ lines.push(` ${p.label.padEnd(14)} ${p.env.padEnd(22)} ${state}`);
40
+ }
41
+ lines.push('');
42
+ lines.push(`Current model: ${ctx.model}`);
43
+ lines.push('');
44
+ lines.push('Full interactive wizard: exit the REPL and run `dirgha setup`.');
45
+ lines.push('Quick key add inside the REPL: `/keys set <ENV> <value>`.');
46
+ lines.push('Pick a default model: `/models` then `/models <n>`.');
47
+ return lines.join('\n');
48
+ },
49
+ };
50
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * /status — compact summary of the current REPL session: session id,
3
+ * model, cumulative token usage, and a quick project-profile readout
4
+ * pulled from DIRGHA.md if present.
5
+ */
6
+ import type { SlashCommand } from './types.js';
7
+ export declare const statusCommand: SlashCommand;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * /status — compact summary of the current REPL session: session id,
3
+ * model, cumulative token usage, and a quick project-profile readout
4
+ * pulled from DIRGHA.md if present.
5
+ */
6
+ import { readFile, stat } from 'node:fs/promises';
7
+ import { join } from 'node:path';
8
+ async function dirghaSummary(cwd) {
9
+ const path = join(cwd, 'DIRGHA.md');
10
+ const info = await stat(path).catch(() => undefined);
11
+ if (!info)
12
+ return undefined;
13
+ const text = await readFile(path, 'utf8').catch(() => '');
14
+ const firstPara = text.split(/\n\s*\n/, 2)[1] ?? text.split('\n', 3).slice(1).join(' ');
15
+ return firstPara.trim().slice(0, 240);
16
+ }
17
+ export const statusCommand = {
18
+ name: 'status',
19
+ description: 'Session summary: model, token usage, project profile',
20
+ async execute(_args, ctx) {
21
+ const lines = [
22
+ 'Session status',
23
+ ` session id : ${ctx.sessionId}`,
24
+ ` model : ${ctx.model}`,
25
+ ` usage : ${ctx.showCost()}`,
26
+ ];
27
+ const summary = await dirghaSummary(process.cwd());
28
+ if (summary) {
29
+ lines.push('', 'DIRGHA.md:', ' ' + summary.replace(/\n/g, '\n '));
30
+ }
31
+ else {
32
+ lines.push('', 'DIRGHA.md: not found (run /init to create one)');
33
+ }
34
+ return lines.join('\n');
35
+ },
36
+ };
37
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * /theme — switch the readline TUI theme. Writes the preference to
3
+ * `~/.dirgha/config.json` (consumed by future sessions) and flips the
4
+ * live theme via `ctx.setTheme()`. The Ink TUI uses a static Ink
5
+ * render tree and won't re-colourise live; a restart picks up the
6
+ * new theme there.
7
+ */
8
+ import type { SlashCommand } from './types.js';
9
+ export declare const themeCommand: SlashCommand;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * /theme — switch the readline TUI theme. Writes the preference to
3
+ * `~/.dirgha/config.json` (consumed by future sessions) and flips the
4
+ * live theme via `ctx.setTheme()`. The Ink TUI uses a static Ink
5
+ * render tree and won't re-colourise live; a restart picks up the
6
+ * new theme there.
7
+ */
8
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
9
+ import { homedir } from 'node:os';
10
+ import { join } from 'node:path';
11
+ const THEMES = ['dark', 'light', 'none'];
12
+ function configPath() {
13
+ return join(homedir(), '.dirgha', 'config.json');
14
+ }
15
+ async function readConfig() {
16
+ const text = await readFile(configPath(), 'utf8').catch(() => '');
17
+ if (!text)
18
+ return {};
19
+ try {
20
+ return JSON.parse(text);
21
+ }
22
+ catch {
23
+ return {};
24
+ }
25
+ }
26
+ async function writeConfig(cfg) {
27
+ await mkdir(join(homedir(), '.dirgha'), { recursive: true });
28
+ await writeFile(configPath(), JSON.stringify(cfg, null, 2) + '\n', 'utf8');
29
+ }
30
+ export const themeCommand = {
31
+ name: 'theme',
32
+ description: 'Show or pick TUI theme (dark|light|none)',
33
+ async execute(args, ctx) {
34
+ const current = ctx.getTheme();
35
+ if (args.length === 0) {
36
+ return [
37
+ `Current theme: ${current}`,
38
+ `Available: ${THEMES.join(' · ')}`,
39
+ ].join('\n');
40
+ }
41
+ const next = args[0];
42
+ if (!THEMES.includes(next)) {
43
+ return `Unknown theme "${next}". Choose one of: ${THEMES.join(', ')}`;
44
+ }
45
+ process.env['DIRGHA_THEME'] = next;
46
+ const cfg = await readConfig();
47
+ cfg.theme = next;
48
+ await writeConfig(cfg);
49
+ ctx.setTheme(next);
50
+ return `Theme set to ${next}. Readline REPL applies immediately; Ink TUI picks it up on restart.`;
51
+ },
52
+ };
53
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Shared `SlashCommand` shape used by the built-in command files in
3
+ * this folder. The slash registry in `../slash.ts` accepts raw handler
4
+ * functions; `SlashCommand` wraps them with a name, description, and
5
+ * optional aliases so a consumer can bulk-register the lot from
6
+ * `builtinSlashCommands` in `./index.ts`.
7
+ */
8
+ import type { SlashHandler } from '../slash.js';
9
+ export interface SlashCommand {
10
+ name: string;
11
+ description: string;
12
+ aliases?: string[];
13
+ execute: SlashHandler;
14
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared `SlashCommand` shape used by the built-in command files in
3
+ * this folder. The slash registry in `../slash.ts` accepts raw handler
4
+ * functions; `SlashCommand` wraps them with a name, description, and
5
+ * optional aliases so a consumer can bulk-register the lot from
6
+ * `builtinSlashCommands` in `./index.ts`.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * /upgrade — show current plan and the upgrade URL.
3
+ *
4
+ * Uses `getAccountStatus` to report the active tier, then prints the
5
+ * upgrade link (configurable via `DIRGHA_UPGRADE_URL`). A referral code
6
+ * is appended when the gateway returns one.
7
+ */
8
+ import type { SlashCommand } from './types.js';
9
+ export declare const upgradeCommand: SlashCommand;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * /upgrade — show current plan and the upgrade URL.
3
+ *
4
+ * Uses `getAccountStatus` to report the active tier, then prints the
5
+ * upgrade link (configurable via `DIRGHA_UPGRADE_URL`). A referral code
6
+ * is appended when the gateway returns one.
7
+ */
8
+ import { getAccountStatus } from '../../integrations/billing.js';
9
+ import { loadToken } from '../../integrations/device-auth.js';
10
+ import { IntegrationError, jsonRequest } from '../../integrations/http.js';
11
+ async function fetchReferralCode(token, apiBase) {
12
+ try {
13
+ const res = await jsonRequest({
14
+ baseUrl: apiBase,
15
+ path: '/api/billing/account',
16
+ token,
17
+ timeoutMs: 5_000,
18
+ });
19
+ return res.referralCode ?? res.referral_code;
20
+ }
21
+ catch (err) {
22
+ if (err instanceof IntegrationError)
23
+ return undefined;
24
+ return undefined;
25
+ }
26
+ }
27
+ export const upgradeCommand = {
28
+ name: 'upgrade',
29
+ description: 'Show current plan and upgrade URL',
30
+ async execute(_args, ctx) {
31
+ const upgradeBase = ctx.upgradeUrl();
32
+ let token = ctx.getToken();
33
+ if (!token) {
34
+ token = await loadToken();
35
+ if (token)
36
+ ctx.setToken(token);
37
+ }
38
+ if (!token) {
39
+ return [
40
+ 'Not signed in. Sign in first with /login, then /upgrade.',
41
+ '',
42
+ `Upgrade: ${upgradeBase}`,
43
+ ].join('\n');
44
+ }
45
+ try {
46
+ const status = await getAccountStatus(token.token, ctx.apiBase());
47
+ const referral = await fetchReferralCode(token.token, ctx.apiBase());
48
+ const upgradeUrl = referral ? `${upgradeBase}?ref=${encodeURIComponent(referral)}` : upgradeBase;
49
+ return [
50
+ `Current plan: ${status.tier}`,
51
+ `Balance: $${status.balanceUsd.toFixed(2)}`,
52
+ '',
53
+ `Upgrade: ${upgradeUrl}`,
54
+ ...(referral ? [`Referral : ${referral}`] : []),
55
+ ].join('\n');
56
+ }
57
+ catch (err) {
58
+ return [
59
+ `Could not fetch plan: ${err instanceof Error ? err.message : String(err)}`,
60
+ '',
61
+ `Upgrade: ${upgradeBase}`,
62
+ ].join('\n');
63
+ }
64
+ },
65
+ };
66
+ //# sourceMappingURL=upgrade.js.map