@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,103 @@
1
+ /**
2
+ * `dirgha doctor` — environment diagnostics.
3
+ *
4
+ * Checks Node version (≥ 20), that cwd is a git repo, that `~/.dirgha/`
5
+ * exists and is writable, which provider env vars are set, and whether
6
+ * each configured provider's base endpoint is reachable (HEAD/GET with a
7
+ * 3 s timeout). Prints a table by default; emits NDJSON when `--json`
8
+ * is passed. Exit code 0 when every check passes, 1 if any fails.
9
+ */
10
+ import { stat, access, mkdir } from 'node:fs/promises';
11
+ import { homedir } from 'node:os';
12
+ import { join } from 'node:path';
13
+ import { stdout } from 'node:process';
14
+ import { constants } from 'node:fs';
15
+ import { style, defaultTheme } from '../../tui/theme.js';
16
+ const PROVIDER_PROBES = [
17
+ { env: 'NVIDIA_API_KEY', label: 'NVIDIA NIM', healthUrl: 'https://integrate.api.nvidia.com/v1/models' },
18
+ { env: 'OPENROUTER_API_KEY', label: 'OpenRouter', healthUrl: 'https://openrouter.ai/api/v1/models' },
19
+ { env: 'ANTHROPIC_API_KEY', label: 'Anthropic', healthUrl: 'https://api.anthropic.com/v1/models' },
20
+ { env: 'OPENAI_API_KEY', label: 'OpenAI', healthUrl: 'https://api.openai.com/v1/models' },
21
+ { env: 'GEMINI_API_KEY', label: 'Google AI', healthUrl: 'https://generativelanguage.googleapis.com' },
22
+ ];
23
+ const TIMEOUT_MS = 3_000;
24
+ const MIN_NODE_MAJOR = 20;
25
+ async function checkNode() {
26
+ const major = Number.parseInt(process.version.slice(1).split('.')[0], 10);
27
+ if (Number.isNaN(major))
28
+ return { name: 'node', status: 'fail', detail: `cannot parse ${process.version}` };
29
+ if (major < MIN_NODE_MAJOR)
30
+ return { name: 'node', status: 'fail', detail: `${process.version} (need ≥ v${MIN_NODE_MAJOR})` };
31
+ return { name: 'node', status: 'pass', detail: process.version };
32
+ }
33
+ async function checkGit(cwd) {
34
+ const info = await stat(join(cwd, '.git')).catch(() => undefined);
35
+ if (info?.isDirectory())
36
+ return { name: 'git', status: 'pass', detail: cwd };
37
+ return { name: 'git', status: 'warn', detail: 'cwd is not a git repo' };
38
+ }
39
+ async function checkDirgaDir() {
40
+ const dir = join(homedir(), '.dirgha');
41
+ await mkdir(dir, { recursive: true }).catch(() => undefined);
42
+ try {
43
+ await access(dir, constants.W_OK);
44
+ return { name: 'dirgha-home', status: 'pass', detail: dir };
45
+ }
46
+ catch {
47
+ return { name: 'dirgha-home', status: 'fail', detail: `cannot write to ${dir}` };
48
+ }
49
+ }
50
+ async function probeProvider(probe) {
51
+ const envPresent = Boolean(process.env[probe.env]);
52
+ if (!envPresent)
53
+ return { name: probe.label, status: 'warn', detail: `${probe.env} unset` };
54
+ const controller = new AbortController();
55
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
56
+ try {
57
+ const res = await fetch(probe.healthUrl, { method: 'GET', signal: controller.signal });
58
+ clearTimeout(timer);
59
+ if (res.status < 500)
60
+ return { name: probe.label, status: 'pass', detail: `${probe.healthUrl} (${res.status})` };
61
+ return { name: probe.label, status: 'fail', detail: `HTTP ${res.status}` };
62
+ }
63
+ catch (err) {
64
+ clearTimeout(timer);
65
+ const msg = err instanceof Error ? err.message : String(err);
66
+ return { name: probe.label, status: 'fail', detail: `unreachable: ${msg}` };
67
+ }
68
+ }
69
+ function printTable(results) {
70
+ stdout.write(style(defaultTheme.accent, '\nDirgha doctor\n\n'));
71
+ for (const r of results) {
72
+ const icon = r.status === 'pass'
73
+ ? style(defaultTheme.success, '✓')
74
+ : r.status === 'warn'
75
+ ? style(defaultTheme.warning, '⚠')
76
+ : style(defaultTheme.danger, '✗');
77
+ stdout.write(` ${icon} ${r.name.padEnd(16)} ${r.detail}\n`);
78
+ }
79
+ stdout.write('\n');
80
+ }
81
+ function printNdjson(results) {
82
+ for (const r of results)
83
+ stdout.write(`${JSON.stringify(r)}\n`);
84
+ }
85
+ export const doctorSubcommand = {
86
+ name: 'doctor',
87
+ description: 'Environment diagnostics (node, git, providers)',
88
+ async run(argv) {
89
+ const json = argv.includes('--json');
90
+ const results = [];
91
+ results.push(await checkNode());
92
+ results.push(await checkGit(process.cwd()));
93
+ results.push(await checkDirgaDir());
94
+ const probes = await Promise.all(PROVIDER_PROBES.map(probeProvider));
95
+ results.push(...probes);
96
+ if (json)
97
+ printNdjson(results);
98
+ else
99
+ printTable(results);
100
+ return results.some(r => r.status === 'fail') ? 1 : 0;
101
+ },
102
+ };
103
+ //# sourceMappingURL=doctor.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `dirgha export-session <id> [path]` — dump a session to a JSON file.
3
+ *
4
+ * Reads the JSONL log for `<id>` from `~/.dirgha/sessions/`, reassembles
5
+ * it into a single JSON document with `{ id, entries, messages }`, and
6
+ * writes it to `path`. A path of `-` streams to stdout. The export is
7
+ * lossless enough that `dirgha import-session` can round-trip it.
8
+ */
9
+ import type { Subcommand } from './index.js';
10
+ export declare const exportSessionSubcommand: Subcommand;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `dirgha export-session <id> [path]` — dump a session to a JSON file.
3
+ *
4
+ * Reads the JSONL log for `<id>` from `~/.dirgha/sessions/`, reassembles
5
+ * it into a single JSON document with `{ id, entries, messages }`, and
6
+ * writes it to `path`. A path of `-` streams to stdout. The export is
7
+ * lossless enough that `dirgha import-session` can round-trip it.
8
+ */
9
+ import { writeFile } from 'node:fs/promises';
10
+ import { resolve } from 'node:path';
11
+ import { stdout, stderr } from 'node:process';
12
+ import { createSessionStore } from '../../context/session.js';
13
+ import { style, defaultTheme } from '../../tui/theme.js';
14
+ export const exportSessionSubcommand = {
15
+ name: 'export-session',
16
+ aliases: ['export'],
17
+ description: 'Dump a session JSONL to a JSON file (or stdout via -)',
18
+ async run(argv, ctx) {
19
+ const [id, pathArg] = argv;
20
+ if (!id) {
21
+ stderr.write('usage: dirgha export-session <id> [path|-]\n');
22
+ return 1;
23
+ }
24
+ const store = createSessionStore();
25
+ const session = await store.open(id);
26
+ if (!session) {
27
+ stderr.write(`session "${id}" not found\n`);
28
+ return 1;
29
+ }
30
+ const entries = [];
31
+ const messages = [];
32
+ for await (const entry of session.replay()) {
33
+ entries.push(entry);
34
+ if (entry.type === 'message')
35
+ messages.push(entry.message);
36
+ }
37
+ const payload = {
38
+ id,
39
+ exportedAt: new Date().toISOString(),
40
+ entries,
41
+ messages,
42
+ };
43
+ const serialized = JSON.stringify(payload, null, 2) + '\n';
44
+ if (!pathArg || pathArg === '-') {
45
+ stdout.write(serialized);
46
+ return 0;
47
+ }
48
+ const outPath = resolve(ctx.cwd, pathArg);
49
+ try {
50
+ await writeFile(outPath, serialized, 'utf8');
51
+ stdout.write(`${style(defaultTheme.success, '✓')} wrote ${outPath} (${entries.length} entries, ${messages.length} messages)\n`);
52
+ return 0;
53
+ }
54
+ catch (err) {
55
+ stderr.write(`failed to write ${outPath}: ${err instanceof Error ? err.message : String(err)}\n`);
56
+ return 1;
57
+ }
58
+ },
59
+ };
60
+ //# sourceMappingURL=export-session.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `dirgha import-session <path>` — load a session JSON into the store.
3
+ *
4
+ * Accepts both the native export format (`{ id, entries, messages }`
5
+ * from `dirgha export-session`) and a bare array of messages (legacy
6
+ * v1 exports). Writes a fresh session file under
7
+ * `~/.dirgha/sessions/<new-uuid>.jsonl` and prints the new id so the
8
+ * caller can `/session load <id>` from the REPL.
9
+ */
10
+ import type { Subcommand } from './index.js';
11
+ export declare const importSessionSubcommand: Subcommand;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * `dirgha import-session <path>` — load a session JSON into the store.
3
+ *
4
+ * Accepts both the native export format (`{ id, entries, messages }`
5
+ * from `dirgha export-session`) and a bare array of messages (legacy
6
+ * v1 exports). Writes a fresh session file under
7
+ * `~/.dirgha/sessions/<new-uuid>.jsonl` and prints the new id so the
8
+ * caller can `/session load <id>` from the REPL.
9
+ */
10
+ import { readFile } from 'node:fs/promises';
11
+ import { resolve } from 'node:path';
12
+ import { randomUUID } from 'node:crypto';
13
+ import { stdout, stderr } from 'node:process';
14
+ import { createSessionStore } from '../../context/session.js';
15
+ import { style, defaultTheme } from '../../tui/theme.js';
16
+ function isEntry(value) {
17
+ return !!value && typeof value === 'object' && typeof value.type === 'string';
18
+ }
19
+ function parse(raw) {
20
+ if (Array.isArray(raw)) {
21
+ // Legacy: bare message array.
22
+ const entries = [];
23
+ const ts = new Date().toISOString();
24
+ for (const message of raw) {
25
+ if (message && typeof message === 'object' && 'role' in message && 'content' in message) {
26
+ entries.push({ type: 'message', ts, message });
27
+ }
28
+ }
29
+ return { entries };
30
+ }
31
+ const obj = raw;
32
+ if (Array.isArray(obj.entries) && obj.entries.every(isEntry)) {
33
+ return { entries: obj.entries };
34
+ }
35
+ if (Array.isArray(obj.messages)) {
36
+ const ts = new Date().toISOString();
37
+ const entries = obj.messages.map(m => ({ type: 'message', ts, message: m }));
38
+ return { entries };
39
+ }
40
+ return { entries: [] };
41
+ }
42
+ export const importSessionSubcommand = {
43
+ name: 'import-session',
44
+ aliases: ['import'],
45
+ description: 'Load a session JSON file into ~/.dirgha/sessions',
46
+ async run(argv, ctx) {
47
+ const pathArg = argv[0];
48
+ if (!pathArg) {
49
+ stderr.write('usage: dirgha import-session <path>\n');
50
+ return 1;
51
+ }
52
+ const path = resolve(ctx.cwd, pathArg);
53
+ let raw;
54
+ try {
55
+ const text = await readFile(path, 'utf8');
56
+ raw = JSON.parse(text);
57
+ }
58
+ catch (err) {
59
+ stderr.write(`cannot read ${path}: ${err instanceof Error ? err.message : String(err)}\n`);
60
+ return 1;
61
+ }
62
+ const { entries } = parse(raw);
63
+ if (entries.length === 0) {
64
+ stderr.write('no entries found — expected { id?, entries|messages } or a bare message array\n');
65
+ return 1;
66
+ }
67
+ const store = createSessionStore();
68
+ const newId = randomUUID();
69
+ const session = await store.create(newId);
70
+ for (const entry of entries)
71
+ await session.append(entry);
72
+ stdout.write(`${style(defaultTheme.success, '✓')} imported ${entries.length} entries as session ${newId}\n`);
73
+ stdout.write(` resume in REPL: /session load ${newId}\n`);
74
+ return 0;
75
+ },
76
+ };
77
+ //# sourceMappingURL=import-session.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Subcommand barrel.
3
+ *
4
+ * Each subcommand is a `{ name, aliases?, run }` record. `run` receives
5
+ * the remaining positional argv (everything after the verb) plus a
6
+ * lightweight context bag with the shared CLI dependencies. It returns
7
+ * a POSIX-style exit code (0 = success).
8
+ *
9
+ * `main.ts` may dispatch directly to the `run*` helpers or iterate this
10
+ * list for generic dispatch — both patterns coexist so we can keep
11
+ * adding new verbs without stomping on the existing wiring.
12
+ */
13
+ export interface SubcommandCtx {
14
+ cwd: string;
15
+ }
16
+ export interface Subcommand {
17
+ name: string;
18
+ aliases?: string[];
19
+ description: string;
20
+ run(argv: string[], ctx: SubcommandCtx): Promise<number>;
21
+ }
22
+ import { doctorSubcommand } from './doctor.js';
23
+ import { loginSubcommand, runLogin } from './login.js';
24
+ import { logoutSubcommand, runLogout } from './logout.js';
25
+ import { setupSubcommand, runSetup } from './setup.js';
26
+ import { auditSubcommand } from './audit.js';
27
+ import { statsSubcommand } from './stats.js';
28
+ import { statusSubcommand } from './status.js';
29
+ import { initSubcommand } from './init.js';
30
+ import { keysSubcommand } from './keys.js';
31
+ import { modelsSubcommand } from './models.js';
32
+ import { chatSubcommand } from './chat.js';
33
+ import { askSubcommand } from './ask.js';
34
+ import { compactSubcommand } from './compact.js';
35
+ import { exportSessionSubcommand } from './export-session.js';
36
+ import { importSessionSubcommand } from './import-session.js';
37
+ export declare const subcommands: Subcommand[];
38
+ export declare function findSubcommand(verb: string): Subcommand | undefined;
39
+ export { runLogin, runLogout, runSetup };
40
+ export { loginSubcommand, logoutSubcommand, setupSubcommand, doctorSubcommand, auditSubcommand, statsSubcommand, statusSubcommand, initSubcommand, keysSubcommand, modelsSubcommand, chatSubcommand, askSubcommand, compactSubcommand, exportSessionSubcommand, importSessionSubcommand, };
@@ -0,0 +1,38 @@
1
+ import { doctorSubcommand } from './doctor.js';
2
+ import { loginSubcommand, runLogin } from './login.js';
3
+ import { logoutSubcommand, runLogout } from './logout.js';
4
+ import { setupSubcommand, runSetup } from './setup.js';
5
+ import { auditSubcommand } from './audit.js';
6
+ import { statsSubcommand } from './stats.js';
7
+ import { statusSubcommand } from './status.js';
8
+ import { initSubcommand } from './init.js';
9
+ import { keysSubcommand } from './keys.js';
10
+ import { modelsSubcommand } from './models.js';
11
+ import { chatSubcommand } from './chat.js';
12
+ import { askSubcommand } from './ask.js';
13
+ import { compactSubcommand } from './compact.js';
14
+ import { exportSessionSubcommand } from './export-session.js';
15
+ import { importSessionSubcommand } from './import-session.js';
16
+ export const subcommands = [
17
+ doctorSubcommand,
18
+ loginSubcommand,
19
+ logoutSubcommand,
20
+ setupSubcommand,
21
+ auditSubcommand,
22
+ statsSubcommand,
23
+ statusSubcommand,
24
+ initSubcommand,
25
+ keysSubcommand,
26
+ modelsSubcommand,
27
+ chatSubcommand,
28
+ askSubcommand,
29
+ compactSubcommand,
30
+ exportSessionSubcommand,
31
+ importSessionSubcommand,
32
+ ];
33
+ export function findSubcommand(verb) {
34
+ return subcommands.find(cmd => cmd.name === verb || (cmd.aliases ?? []).includes(verb));
35
+ }
36
+ export { runLogin, runLogout, runSetup };
37
+ export { loginSubcommand, logoutSubcommand, setupSubcommand, doctorSubcommand, auditSubcommand, statsSubcommand, statusSubcommand, initSubcommand, keysSubcommand, modelsSubcommand, chatSubcommand, askSubcommand, compactSubcommand, exportSessionSubcommand, importSessionSubcommand, };
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `dirgha init [path]` — scaffold DIRGHA.md in `path` (default: cwd).
3
+ *
4
+ * Refuses to overwrite an existing DIRGHA.md unless `--force` is
5
+ * passed, in which case it replaces the file and prints the old first
6
+ * line as a reference. Mirrors the REPL `/init` slash but lets the
7
+ * user target a subdirectory directly from the shell.
8
+ */
9
+ import type { Subcommand } from './index.js';
10
+ export declare const initSubcommand: Subcommand;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * `dirgha init [path]` — scaffold DIRGHA.md in `path` (default: cwd).
3
+ *
4
+ * Refuses to overwrite an existing DIRGHA.md unless `--force` is
5
+ * passed, in which case it replaces the file and prints the old first
6
+ * line as a reference. Mirrors the REPL `/init` slash but lets the
7
+ * user target a subdirectory directly from the shell.
8
+ */
9
+ import { readFile, writeFile, stat, mkdir } from 'node:fs/promises';
10
+ import { resolve, join, dirname } from 'node:path';
11
+ import { stdout, stderr } from 'node:process';
12
+ import { style, defaultTheme } from '../../tui/theme.js';
13
+ const TEMPLATE = `# DIRGHA.md
14
+
15
+ This file gives dirgha-cli persistent project context. Everything below
16
+ is read as a system primer on every run.
17
+
18
+ ## Project summary
19
+
20
+ <!-- describe what this repo is, top-level goals, who maintains it -->
21
+
22
+ ## Conventions
23
+
24
+ <!-- language, formatter, test command, branch naming, commit style -->
25
+
26
+ ## Gotchas
27
+
28
+ <!-- known flaky tests, tricky build steps, secrets-never-commit rules -->
29
+
30
+ ## Useful commands
31
+
32
+ \`\`\`bash
33
+ # tests
34
+ npm test
35
+
36
+ # type-check
37
+ npx tsc --noEmit
38
+ \`\`\`
39
+ `;
40
+ async function readFirstLine(path) {
41
+ const text = await readFile(path, 'utf8').catch(() => '');
42
+ return text.split('\n', 1)[0] ?? '';
43
+ }
44
+ export const initSubcommand = {
45
+ name: 'init',
46
+ description: 'Initialise DIRGHA.md in a project directory',
47
+ async run(argv, ctx) {
48
+ const force = argv.includes('--force') || argv.includes('-f');
49
+ const positional = argv.find(a => !a.startsWith('-'));
50
+ const targetDir = positional ? resolve(ctx.cwd, positional) : ctx.cwd;
51
+ const target = join(targetDir, 'DIRGHA.md');
52
+ const existing = await stat(target).then(() => true).catch(() => false);
53
+ if (existing && !force) {
54
+ const firstLine = await readFirstLine(target);
55
+ stdout.write(`${style(defaultTheme.warning, 'DIRGHA.md exists')} at ${target}\n`);
56
+ if (firstLine)
57
+ stdout.write(` first line: ${firstLine}\n`);
58
+ stdout.write(`Run with --force to overwrite.\n`);
59
+ return 0;
60
+ }
61
+ try {
62
+ await mkdir(dirname(target), { recursive: true });
63
+ await writeFile(target, TEMPLATE, 'utf8');
64
+ stdout.write(`${style(defaultTheme.success, '✓')} wrote ${target}\n`);
65
+ stdout.write(`Edit it to describe the project; dirgha reads it on every run.\n`);
66
+ return 0;
67
+ }
68
+ catch (err) {
69
+ stderr.write(`failed to write ${target}: ${err instanceof Error ? err.message : String(err)}\n`);
70
+ return 1;
71
+ }
72
+ },
73
+ };
74
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `dirgha keys <list|set|get|clear>` — BYOK key store at
3
+ * `~/.dirgha/keys.json` (mode 0600).
4
+ *
5
+ * Mirrors the `/keys` slash but is callable non-interactively from
6
+ * shells and scripts. `list` masks values; `get` prints the raw value
7
+ * (supported but noisy by design so nobody leans on it). `set` writes
8
+ * the file with a 0600 chmod. `clear` removes one key or everything
9
+ * when given `all`.
10
+ */
11
+ import type { Subcommand } from './index.js';
12
+ export declare const keysSubcommand: Subcommand;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * `dirgha keys <list|set|get|clear>` — BYOK key store at
3
+ * `~/.dirgha/keys.json` (mode 0600).
4
+ *
5
+ * Mirrors the `/keys` slash but is callable non-interactively from
6
+ * shells and scripts. `list` masks values; `get` prints the raw value
7
+ * (supported but noisy by design so nobody leans on it). `set` writes
8
+ * the file with a 0600 chmod. `clear` removes one key or everything
9
+ * when given `all`.
10
+ */
11
+ import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
12
+ import { homedir } from 'node:os';
13
+ import { join } from 'node:path';
14
+ import { stdout, stderr } from 'node:process';
15
+ import { style, defaultTheme } from '../../tui/theme.js';
16
+ const KNOWN_PROVIDERS = [
17
+ 'NVIDIA_API_KEY',
18
+ 'OPENROUTER_API_KEY',
19
+ 'ANTHROPIC_API_KEY',
20
+ 'OPENAI_API_KEY',
21
+ 'GEMINI_API_KEY',
22
+ 'FIREWORKS_API_KEY',
23
+ ];
24
+ function keyPath() {
25
+ return join(homedir(), '.dirgha', 'keys.json');
26
+ }
27
+ async function read() {
28
+ const text = await readFile(keyPath(), 'utf8').catch(() => '');
29
+ if (!text)
30
+ return {};
31
+ try {
32
+ return JSON.parse(text);
33
+ }
34
+ catch {
35
+ return {};
36
+ }
37
+ }
38
+ async function write(store) {
39
+ const path = keyPath();
40
+ await mkdir(join(homedir(), '.dirgha'), { recursive: true });
41
+ await writeFile(path, JSON.stringify(store, null, 2) + '\n', 'utf8');
42
+ try {
43
+ await chmod(path, 0o600);
44
+ }
45
+ catch { /* non-POSIX */ }
46
+ }
47
+ function mask(value) {
48
+ if (value.length < 10)
49
+ return '***';
50
+ return `${value.slice(0, 4)}…${value.slice(-4)}`;
51
+ }
52
+ function usage() {
53
+ return [
54
+ 'usage:',
55
+ ' dirgha keys list List stored keys (masked)',
56
+ ' dirgha keys set <ENV> <value> Set a provider key',
57
+ ' dirgha keys get <ENV> Print the raw value (avoid; use env vars)',
58
+ ' dirgha keys clear <ENV> Remove a key',
59
+ ' dirgha keys clear all Remove every key',
60
+ `known: ${KNOWN_PROVIDERS.join(', ')}`,
61
+ ].join('\n');
62
+ }
63
+ async function runList() {
64
+ const store = await read();
65
+ const all = new Set([...KNOWN_PROVIDERS, ...Object.keys(store)]);
66
+ stdout.write(`${style(defaultTheme.accent, 'Stored keys')}\n`);
67
+ for (const key of [...all].sort()) {
68
+ const stored = store[key];
69
+ const envInherit = process.env[key];
70
+ const state = stored
71
+ ? style(defaultTheme.success, `stored ${mask(stored)}`)
72
+ : envInherit
73
+ ? style(defaultTheme.muted, `env ${mask(envInherit)}`)
74
+ : style(defaultTheme.muted, 'unset');
75
+ stdout.write(` ${key.padEnd(22)} ${state}\n`);
76
+ }
77
+ stdout.write(`\n${style(defaultTheme.muted, `file: ${keyPath()}`)}\n`);
78
+ return 0;
79
+ }
80
+ export const keysSubcommand = {
81
+ name: 'keys',
82
+ description: 'Manage BYOK API keys at ~/.dirgha/keys.json',
83
+ async run(argv) {
84
+ const [op, envVar, value] = argv;
85
+ if (!op || op === 'list')
86
+ return runList();
87
+ if (op === 'set') {
88
+ if (!envVar || !value) {
89
+ stderr.write(`${usage()}\n`);
90
+ return 1;
91
+ }
92
+ const store = await read();
93
+ store[envVar] = value;
94
+ await write(store);
95
+ stdout.write(`${style(defaultTheme.success, '✓')} stored ${envVar} (${mask(value)})\n`);
96
+ return 0;
97
+ }
98
+ if (op === 'get') {
99
+ if (!envVar) {
100
+ stderr.write(`${usage()}\n`);
101
+ return 1;
102
+ }
103
+ const store = await read();
104
+ const v = store[envVar] ?? process.env[envVar];
105
+ if (!v) {
106
+ stderr.write(`${envVar} is not set.\n`);
107
+ return 1;
108
+ }
109
+ stdout.write(`${v}\n`);
110
+ return 0;
111
+ }
112
+ if (op === 'clear') {
113
+ if (!envVar) {
114
+ stderr.write(`${usage()}\n`);
115
+ return 1;
116
+ }
117
+ if (envVar === 'all') {
118
+ await write({});
119
+ stdout.write(`${style(defaultTheme.success, '✓')} cleared every stored key\n`);
120
+ return 0;
121
+ }
122
+ const store = await read();
123
+ if (!(envVar in store)) {
124
+ stderr.write(`${envVar} is not set.\n`);
125
+ return 1;
126
+ }
127
+ delete store[envVar];
128
+ await write(store);
129
+ stdout.write(`${style(defaultTheme.success, '✓')} cleared ${envVar}\n`);
130
+ return 0;
131
+ }
132
+ stderr.write(`unknown subcommand "${op}"\n${usage()}\n`);
133
+ return 1;
134
+ },
135
+ };
136
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `dirgha login` — interactive device-code sign-in.
3
+ *
4
+ * Non-REPL variant of the `/login` slash command. Prints the user code
5
+ * and verification URL to stdout, waits for the poll to complete, then
6
+ * persists the token via `saveToken`. Returns POSIX exit codes.
7
+ */
8
+ import type { Subcommand } from './index.js';
9
+ export declare function runLogin(argv: string[]): Promise<number>;
10
+ export declare const loginSubcommand: Subcommand;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `dirgha login` — interactive device-code sign-in.
3
+ *
4
+ * Non-REPL variant of the `/login` slash command. Prints the user code
5
+ * and verification URL to stdout, waits for the poll to complete, then
6
+ * persists the token via `saveToken`. Returns POSIX exit codes.
7
+ */
8
+ import { stdout } from 'node:process';
9
+ import { pollDeviceAuth, saveToken, startDeviceAuth, } from '../../integrations/device-auth.js';
10
+ import { defaultTheme, style } from '../../tui/theme.js';
11
+ function print(line) {
12
+ stdout.write(`${line}\n`);
13
+ }
14
+ function parseFlag(argv, name) {
15
+ const prefix = `--${name}=`;
16
+ for (let i = 0; i < argv.length; i += 1) {
17
+ const a = argv[i];
18
+ if (a === `--${name}` && i + 1 < argv.length)
19
+ return argv[i + 1];
20
+ if (a.startsWith(prefix))
21
+ return a.slice(prefix.length);
22
+ }
23
+ return undefined;
24
+ }
25
+ export async function runLogin(argv) {
26
+ const apiBase = parseFlag(argv, 'api-base') ?? process.env.DIRGHA_API_BASE;
27
+ print(style(defaultTheme.accent, '\ndirgha — device-code sign-in'));
28
+ let start;
29
+ try {
30
+ start = await startDeviceAuth(apiBase);
31
+ }
32
+ catch (err) {
33
+ print(style(defaultTheme.danger, `\n✗ device/start failed: ${err instanceof Error ? err.message : String(err)}`));
34
+ return 2;
35
+ }
36
+ print('');
37
+ print(` 1. Open: ${start.verifyUri}`);
38
+ print(` 2. Enter code: ${style(defaultTheme.accent, start.userCode)}`);
39
+ print('');
40
+ print(`Waiting for authorization (expires in ~${Math.round(start.expiresIn / 60_000)} min)...`);
41
+ try {
42
+ const result = await pollDeviceAuth(start.deviceCode, apiBase, {
43
+ intervalMs: start.interval,
44
+ timeoutMs: start.expiresIn,
45
+ });
46
+ await saveToken(result.token, result.userId, result.email);
47
+ print(style(defaultTheme.success, `\n✓ Signed in as ${result.email}`));
48
+ return 0;
49
+ }
50
+ catch (err) {
51
+ print(style(defaultTheme.danger, `\n✗ Login failed: ${err instanceof Error ? err.message : String(err)}`));
52
+ return 1;
53
+ }
54
+ }
55
+ export const loginSubcommand = {
56
+ name: 'login',
57
+ description: 'Sign in via device-code flow',
58
+ async run(argv) { return runLogin(argv); },
59
+ };
60
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `dirgha logout` — clear the cached credentials.
3
+ *
4
+ * Calls `clearToken()` (unlinks `~/.dirgha/credentials.json`) and
5
+ * prints a single confirmation line. Always exits 0, even when no
6
+ * token exists — idempotent sign-out matches curl/gh conventions.
7
+ */
8
+ import type { Subcommand } from './index.js';
9
+ export declare function runLogout(_argv: string[]): Promise<number>;
10
+ export declare const logoutSubcommand: Subcommand;