@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,126 @@
1
+ /**
2
+ * useEventProjection: subscribes to the kernel EventStream and projects
3
+ * raw AgentEvents into the transcript records that App renders.
4
+ *
5
+ * Split out of App.tsx so the root component stays focused on layout.
6
+ * The projection rule set mirrors the v1 renderer: contiguous text
7
+ * deltas fold into a single TextSpan; thinking deltas into a
8
+ * ThinkingSpan; each tool invocation produces a ToolRecord that
9
+ * starts in 'running' and flips to 'done' or 'error' on exec_end.
10
+ */
11
+ import * as React from 'react';
12
+ import { randomUUID } from 'node:crypto';
13
+ export function useEventProjection(events) {
14
+ const [liveItems, setLiveItems] = React.useState([]);
15
+ const [totals, setTotals] = React.useState({
16
+ inputTokens: 0, outputTokens: 0, cachedTokens: 0, costUsd: 0,
17
+ });
18
+ React.useEffect(() => {
19
+ // Local ids used to attribute in-flight deltas to the right span.
20
+ let currentTextId = null;
21
+ let currentThinkingId = null;
22
+ const unsubscribe = events.subscribe((event) => {
23
+ switch (event.type) {
24
+ case 'text_start':
25
+ currentTextId = randomUUID();
26
+ currentThinkingId = null;
27
+ setLiveItems(prev => [...prev, { kind: 'text', id: currentTextId, content: '' }]);
28
+ return;
29
+ case 'text_delta': {
30
+ const id = currentTextId;
31
+ if (!id)
32
+ return;
33
+ setLiveItems(prev => prev.map(it => (it.kind === 'text' && it.id === id ? { ...it, content: it.content + event.delta } : it)));
34
+ return;
35
+ }
36
+ case 'text_end':
37
+ currentTextId = null;
38
+ return;
39
+ case 'thinking_start':
40
+ currentThinkingId = randomUUID();
41
+ setLiveItems(prev => [...prev, { kind: 'thinking', id: currentThinkingId, content: '' }]);
42
+ return;
43
+ case 'thinking_delta': {
44
+ const id = currentThinkingId;
45
+ if (!id)
46
+ return;
47
+ setLiveItems(prev => prev.map(it => (it.kind === 'thinking' && it.id === id ? { ...it, content: it.content + event.delta } : it)));
48
+ return;
49
+ }
50
+ case 'thinking_end':
51
+ currentThinkingId = null;
52
+ return;
53
+ case 'tool_exec_start': {
54
+ const item = {
55
+ kind: 'tool',
56
+ id: event.id,
57
+ name: event.name,
58
+ status: 'running',
59
+ argSummary: summariseInput(event.input),
60
+ outputPreview: '',
61
+ startedAt: Date.now(),
62
+ };
63
+ setLiveItems(prev => [...prev, item]);
64
+ return;
65
+ }
66
+ case 'tool_exec_end': {
67
+ const status = event.isError ? 'error' : 'done';
68
+ setLiveItems(prev => prev.map(it => (it.kind === 'tool' && it.id === event.id
69
+ ? { ...it, status, outputPreview: event.output.slice(0, 200), durationMs: event.durationMs }
70
+ : it)));
71
+ return;
72
+ }
73
+ case 'usage':
74
+ setTotals(prev => ({
75
+ inputTokens: prev.inputTokens + event.inputTokens,
76
+ outputTokens: prev.outputTokens + event.outputTokens,
77
+ cachedTokens: prev.cachedTokens + (event.cachedTokens ?? 0),
78
+ costUsd: prev.costUsd,
79
+ }));
80
+ return;
81
+ case 'error':
82
+ setLiveItems(prev => [...prev, { kind: 'error', id: randomUUID(), message: event.message }]);
83
+ return;
84
+ case 'turn_end':
85
+ currentTextId = null;
86
+ currentThinkingId = null;
87
+ return;
88
+ default:
89
+ return;
90
+ }
91
+ });
92
+ return unsubscribe;
93
+ }, [events]);
94
+ const commitLive = React.useCallback(() => {
95
+ let committed = [];
96
+ setLiveItems(prev => {
97
+ committed = prev;
98
+ return [];
99
+ });
100
+ return committed;
101
+ }, []);
102
+ const appendLive = React.useCallback((item) => {
103
+ setLiveItems(prev => [...prev, item]);
104
+ }, []);
105
+ const clear = React.useCallback(() => {
106
+ setLiveItems([]);
107
+ setTotals({ inputTokens: 0, outputTokens: 0, cachedTokens: 0, costUsd: 0 });
108
+ }, []);
109
+ return { liveItems, totals, commitLive, appendLive, clear };
110
+ }
111
+ function summariseInput(input, max = 60) {
112
+ if (input === undefined || input === null)
113
+ return '';
114
+ const s = typeof input === 'string' ? input : safeStringify(input);
115
+ const collapsed = s.replace(/\s+/g, ' ').trim();
116
+ return collapsed.length <= max ? collapsed : `${collapsed.slice(0, max - 1)}…`;
117
+ }
118
+ function safeStringify(value) {
119
+ try {
120
+ return JSON.stringify(value);
121
+ }
122
+ catch {
123
+ return String(value);
124
+ }
125
+ }
126
+ //# sourceMappingURL=use-event-projection.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Overlay + input-assist state hook for the Ink root component.
3
+ *
4
+ * Owns the four overlay channels (model picker, help, @-file completion)
5
+ * plus the `@` query and any other state that would otherwise bloat
6
+ * App.tsx. Extracted so App stays under 500 LOC as the feature surface
7
+ * grew (model picker, help, vim mode, paste-collapse, at-file complete).
8
+ */
9
+ export type OverlayKind = 'models' | 'help' | 'atfile' | null;
10
+ export interface OverlayApi {
11
+ active: OverlayKind;
12
+ setActive: (k: OverlayKind) => void;
13
+ atQuery: string | null;
14
+ setAtQuery: (q: string | null) => void;
15
+ openOverlay: (k: 'models' | 'help') => void;
16
+ closeOverlay: () => void;
17
+ /**
18
+ * Splice a selected @-file path back into `value`, replacing the
19
+ * trailing @-token. Returns the new buffer — callers must pipe this
20
+ * into their setInput hook.
21
+ */
22
+ spliceAtSelection: (value: string, selected: string) => string;
23
+ }
24
+ export declare function useOverlays(): OverlayApi;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Overlay + input-assist state hook for the Ink root component.
3
+ *
4
+ * Owns the four overlay channels (model picker, help, @-file completion)
5
+ * plus the `@` query and any other state that would otherwise bloat
6
+ * App.tsx. Extracted so App stays under 500 LOC as the feature surface
7
+ * grew (model picker, help, vim mode, paste-collapse, at-file complete).
8
+ */
9
+ import * as React from 'react';
10
+ export function useOverlays() {
11
+ const [active, setActive] = React.useState(null);
12
+ const [atQuery, setAtQuery] = React.useState(null);
13
+ // Keep the @-file overlay in sync with the input token.
14
+ React.useEffect(() => {
15
+ if (atQuery === null) {
16
+ if (active === 'atfile')
17
+ setActive(null);
18
+ return;
19
+ }
20
+ if (active === null)
21
+ setActive('atfile');
22
+ }, [atQuery, active]);
23
+ const openOverlay = React.useCallback((k) => {
24
+ setActive(k);
25
+ }, []);
26
+ const closeOverlay = React.useCallback(() => {
27
+ setActive(null);
28
+ setAtQuery(null);
29
+ }, []);
30
+ const spliceAtSelection = React.useCallback((value, selected) => {
31
+ const idx = value.lastIndexOf('@');
32
+ if (idx === -1)
33
+ return value;
34
+ // Replace `@query` (up to next whitespace or end) with the path.
35
+ let end = idx + 1;
36
+ while (end < value.length && !/\s/.test(value[end] ?? ''))
37
+ end += 1;
38
+ return `${value.slice(0, idx)}@${selected}${value.slice(end)}`;
39
+ }, []);
40
+ return {
41
+ active,
42
+ setActive,
43
+ atQuery,
44
+ setAtQuery,
45
+ openOverlay,
46
+ closeOverlay,
47
+ spliceAtSelection,
48
+ };
49
+ }
50
+ //# sourceMappingURL=use-overlays.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Streaming renderer.
3
+ *
4
+ * The v1 implementation is line-buffered rather than a full cell-level
5
+ * differential renderer: it writes assistant text deltas directly to
6
+ * stdout, emits newline-separated tool invocation banners, and prefixes
7
+ * status changes with ANSI-coloured tokens. It is intentionally simple
8
+ * and terminal-safe; a higher-fidelity differential renderer can be
9
+ * layered in later without changing this module's interface.
10
+ */
11
+ import type { AgentEvent } from '../kernel/types.js';
12
+ import { type Theme } from './theme.js';
13
+ export interface StreamRendererOptions {
14
+ theme?: Theme;
15
+ colour?: boolean;
16
+ showThinking?: boolean;
17
+ write?: (chunk: string) => void;
18
+ }
19
+ export declare function renderStreamingEvents(opts?: StreamRendererOptions): (event: AgentEvent) => void;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Streaming renderer.
3
+ *
4
+ * The v1 implementation is line-buffered rather than a full cell-level
5
+ * differential renderer: it writes assistant text deltas directly to
6
+ * stdout, emits newline-separated tool invocation banners, and prefixes
7
+ * status changes with ANSI-coloured tokens. It is intentionally simple
8
+ * and terminal-safe; a higher-fidelity differential renderer can be
9
+ * layered in later without changing this module's interface.
10
+ */
11
+ import { defaultTheme, noColour, style } from './theme.js';
12
+ export function renderStreamingEvents(opts = {}) {
13
+ const theme = opts.colour === false ? noColour() : opts.theme ?? defaultTheme;
14
+ const write = opts.write ?? ((chunk) => { process.stdout.write(chunk); });
15
+ const showThinking = opts.showThinking ?? false;
16
+ let thinkingBannerOpen = false;
17
+ return (event) => {
18
+ switch (event.type) {
19
+ case 'text_start':
20
+ thinkingBannerOpen && write('\n');
21
+ thinkingBannerOpen = false;
22
+ return;
23
+ case 'text_delta':
24
+ write(event.delta);
25
+ return;
26
+ case 'text_end':
27
+ return;
28
+ case 'thinking_start':
29
+ if (showThinking) {
30
+ thinkingBannerOpen = true;
31
+ write(style(theme.thinking, '\n• thinking… '));
32
+ }
33
+ return;
34
+ case 'thinking_delta':
35
+ if (showThinking)
36
+ write(style(theme.thinking, event.delta));
37
+ return;
38
+ case 'thinking_end':
39
+ if (showThinking && thinkingBannerOpen) {
40
+ thinkingBannerOpen = false;
41
+ write('\n');
42
+ }
43
+ return;
44
+ case 'tool_exec_start':
45
+ write(style(theme.tool, `\n→ ${event.name}`));
46
+ return;
47
+ case 'tool_exec_end': {
48
+ const token = event.isError ? theme.toolError : theme.tool;
49
+ const verdict = event.isError ? 'error' : 'done';
50
+ write(style(token, ` (${verdict}, ${event.durationMs}ms)\n`));
51
+ return;
52
+ }
53
+ case 'error':
54
+ write(style(theme.danger, `\n[error] ${event.message}\n`));
55
+ return;
56
+ case 'turn_end':
57
+ write('\n');
58
+ return;
59
+ case 'agent_end':
60
+ return;
61
+ }
62
+ };
63
+ }
64
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Status bar: rendered between turns. Shows model, session, turn count
3
+ * and cumulative cost/tokens.
4
+ */
5
+ import type { UsageTotal } from '../kernel/types.js';
6
+ export interface StatusBarState {
7
+ model: string;
8
+ sessionId: string;
9
+ turn: number;
10
+ usage: UsageTotal;
11
+ }
12
+ export declare function renderStatusBar(state: StatusBarState, width?: number): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Status bar: rendered between turns. Shows model, session, turn count
3
+ * and cumulative cost/tokens.
4
+ */
5
+ import { style, defaultTheme } from './theme.js';
6
+ export function renderStatusBar(state, width = 80) {
7
+ const short = state.sessionId.slice(0, 8);
8
+ const cost = state.usage.costUsd.toFixed(4);
9
+ const tokens = `${state.usage.inputTokens}/${state.usage.outputTokens}`;
10
+ const left = `[${state.model}] session:${short} turn:${state.turn}`;
11
+ const right = `tokens ${tokens} • $${cost}`;
12
+ const gap = Math.max(1, width - left.length - right.length);
13
+ const line = `${left}${' '.repeat(gap)}${right}`;
14
+ return style(defaultTheme.muted, line);
15
+ }
16
+ //# sourceMappingURL=status-bar.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * ANSI colour tokens. Scoped to what the TUI actually uses — no
3
+ * overreach into a full style system. Callers wrap strings via style().
4
+ */
5
+ export interface Theme {
6
+ userPrompt: string;
7
+ assistant: string;
8
+ thinking: string;
9
+ tool: string;
10
+ toolError: string;
11
+ systemNotice: string;
12
+ muted: string;
13
+ accent: string;
14
+ warning: string;
15
+ danger: string;
16
+ success: string;
17
+ }
18
+ export declare const darkTheme: Theme;
19
+ export declare const lightTheme: Theme;
20
+ export declare const defaultTheme: Theme;
21
+ export type ThemeName = 'dark' | 'light' | 'none';
22
+ export declare const themes: Record<ThemeName, Theme>;
23
+ /** Look up a theme by name; unknown names fall back to dark. */
24
+ export declare function getTheme(name: string | undefined): Theme;
25
+ export declare function style(token: string, text: string): string;
26
+ export declare function styleDim(text: string): string;
27
+ export declare function noColour(): Theme;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * ANSI colour tokens. Scoped to what the TUI actually uses — no
3
+ * overreach into a full style system. Callers wrap strings via style().
4
+ */
5
+ const RESET = '\x1b[0m';
6
+ // Dark palette — tuned for dark terminal backgrounds.
7
+ export const darkTheme = {
8
+ userPrompt: '\x1b[1;36m', // bold cyan
9
+ assistant: '\x1b[0m', // plain
10
+ thinking: '\x1b[2;37m', // dim grey
11
+ tool: '\x1b[35m', // magenta
12
+ toolError: '\x1b[31m', // red
13
+ systemNotice: '\x1b[33m', // yellow
14
+ muted: '\x1b[2m',
15
+ accent: '\x1b[1;34m',
16
+ warning: '\x1b[33m',
17
+ danger: '\x1b[31m',
18
+ success: '\x1b[32m',
19
+ };
20
+ // Light palette — swaps dim/bright so white terminals stay legible.
21
+ export const lightTheme = {
22
+ userPrompt: '\x1b[1;34m', // bold blue (cyan washes out on light)
23
+ assistant: '\x1b[0m',
24
+ thinking: '\x1b[2;30m', // dim black (not grey)
25
+ tool: '\x1b[35m',
26
+ toolError: '\x1b[1;31m', // bold red so it pops
27
+ systemNotice: '\x1b[33m',
28
+ muted: '\x1b[2;30m',
29
+ accent: '\x1b[1;34m',
30
+ warning: '\x1b[1;33m',
31
+ danger: '\x1b[1;31m',
32
+ success: '\x1b[1;32m',
33
+ };
34
+ // Backward-compat alias — existing call sites use `defaultTheme`.
35
+ export const defaultTheme = darkTheme;
36
+ export const themes = {
37
+ dark: darkTheme,
38
+ light: lightTheme,
39
+ none: Object.fromEntries(Object.keys(darkTheme).map(k => [k, ''])),
40
+ };
41
+ /** Look up a theme by name; unknown names fall back to dark. */
42
+ export function getTheme(name) {
43
+ if (name && name in themes)
44
+ return themes[name];
45
+ return darkTheme;
46
+ }
47
+ export function style(token, text) {
48
+ return `${token}${text}${RESET}`;
49
+ }
50
+ export function styleDim(text) {
51
+ return style(defaultTheme.muted, text);
52
+ }
53
+ export function noColour() {
54
+ return themes.none;
55
+ }
56
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Heuristic repair for partial or malformed JSON produced by streaming
3
+ * model output. Invoked when a JSON.parse fails on a tool-call argument
4
+ * blob or a chunked response. Best-effort — returns {} on total failure
5
+ * so callers never throw from a cosmetically bad payload.
6
+ */
7
+ export declare function repairJSON(raw: string): unknown;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Heuristic repair for partial or malformed JSON produced by streaming
3
+ * model output. Invoked when a JSON.parse fails on a tool-call argument
4
+ * blob or a chunked response. Best-effort — returns {} on total failure
5
+ * so callers never throw from a cosmetically bad payload.
6
+ */
7
+ export function repairJSON(raw) {
8
+ if (!raw || !raw.trim())
9
+ return {};
10
+ let trimmed = raw.trim();
11
+ try {
12
+ return JSON.parse(trimmed);
13
+ }
14
+ catch {
15
+ /* proceed to repairs */
16
+ }
17
+ const quoteCount = (trimmed.match(/"/g) || []).length;
18
+ if (quoteCount % 2 !== 0) {
19
+ trimmed += '"';
20
+ }
21
+ trimmed = trimmed.replace(/,\s*([}\]])/g, '$1');
22
+ const stack = [];
23
+ for (let i = 0; i < trimmed.length; i++) {
24
+ const char = trimmed[i];
25
+ if (char === '{')
26
+ stack.push('}');
27
+ else if (char === '[')
28
+ stack.push(']');
29
+ else if (char === '}' || char === ']') {
30
+ if (stack.length > 0 && stack[stack.length - 1] === char) {
31
+ stack.pop();
32
+ }
33
+ }
34
+ }
35
+ while (stack.length > 0) {
36
+ trimmed += stack.pop();
37
+ }
38
+ try {
39
+ return JSON.parse(trimmed);
40
+ }
41
+ catch {
42
+ return {};
43
+ }
44
+ }
45
+ //# sourceMappingURL=json-repair.js.map
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "@dirgha/code",
3
+ "version": "1.2.0",
4
+ "type": "module",
5
+ "main": "dist_v2/index.js",
6
+ "bin": {
7
+ "dirgha": "dist_v2/cli/main.js",
8
+ "d": "dist_v2/cli/main.js",
9
+ "dirgha-v1": "dist/dirgha.mjs"
10
+ },
11
+ "scripts": {
12
+ "build": "node build.mjs && npm run build:v2",
13
+ "build:v1": "node build.mjs",
14
+ "build:v2": "tsc -p tsconfig.v2.json",
15
+ "postbuild": "node scripts/gen-skill-md.mjs || echo '[skill-md] skipped'",
16
+ "skill:gen": "node scripts/gen-skill-md.mjs",
17
+ "build:public": "DIRGHA_BUILD_TYPE=public node build.mjs && npm run build:v2",
18
+ "build:private": "DIRGHA_BUILD_TYPE=private node build.mjs",
19
+ "build:dev": "node build.mjs --dev",
20
+ "build:analyze": "node build.mjs --analyze",
21
+ "dev": "tsx --watch src/index.ts",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "lint": "tsc --noEmit",
25
+ "typecheck:v2": "tsc -p tsconfig.v2.json --noEmit",
26
+ "prepublishOnly": "DIRGHA_BUILD_TYPE=public node build.mjs && npm run build:v2"
27
+ },
28
+ "files": [
29
+ "dist/dirgha.mjs",
30
+ "dist_v2/**/*.js",
31
+ "dist_v2/**/*.d.ts",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "registry": "https://registry.npmjs.org/"
38
+ },
39
+ "private": false,
40
+ "engines": {
41
+ "node": ">=20.0.0",
42
+ "pnpm": ">=8.0.0"
43
+ },
44
+ "packageManager": "pnpm@9.0.0",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/dirghaai/dirgha-code.git"
48
+ },
49
+ "homepage": "https://dirgha.ai",
50
+ "bugs": {
51
+ "url": "https://github.com/dirghaai/dirgha-code/issues"
52
+ },
53
+ "keywords": [
54
+ "ai",
55
+ "cli",
56
+ "coding-agent",
57
+ "dirgha",
58
+ "llm",
59
+ "terminal",
60
+ "developer-tools",
61
+ "code-generation",
62
+ "chatbot"
63
+ ],
64
+ "author": "Salik Shah <salik@dirgha.ai>",
65
+ "license": "FSL-1.1-MIT",
66
+ "description": "Dirgha CLI — AI coding agent for the terminal. Multi-provider LLM support, secure execution, browser automation, and persistent sessions.",
67
+ "dependencies": {
68
+ "@commander-js/extra-typings": "^14.0.0",
69
+ "@inkjs/ui": "^2.0.0",
70
+ "@types/node": "^25.2.3",
71
+ "better-sqlite3": "^12.9.0",
72
+ "chalk": "^5.6.2",
73
+ "cli-table3": "^0.6.5",
74
+ "commander": "^14.0.0",
75
+ "file-type": "^21.3.4",
76
+ "glob": "^11.0.0",
77
+ "ink": "^6.8.0",
78
+ "ink-gradient": "^4.0.0",
79
+ "ink-text-input": "^6.0.0",
80
+ "inquirer": "12.1.0",
81
+ "js-yaml": "^4.1.1",
82
+ "magika": "^1.0.0",
83
+ "marked": "^15.0.12",
84
+ "marked-terminal": "^7.3.0",
85
+ "ora": "^9.3.0",
86
+ "qrcode-terminal": "^0.12.0",
87
+ "react": "^19.2.4",
88
+ "rxjs": "^7.8.0",
89
+ "typescript": "^5.9.3",
90
+ "yaml": "^2.3.4"
91
+ },
92
+ "devDependencies": {
93
+ "@types/better-sqlite3": "^7.6.13",
94
+ "@types/inquirer": "^9.0.9",
95
+ "@types/qrcode-terminal": "^0.12.2",
96
+ "@types/react": "^19.2.14",
97
+ "@types/ws": "^8.18.1",
98
+ "esbuild": "^0.24.2",
99
+ "tsx": "^4.0.0",
100
+ "vitest": "^4.1.2"
101
+ },
102
+ "optionalDependencies": {
103
+ "playwright": "^1.47.0",
104
+ "libp2p": "2.2.1",
105
+ "@libp2p/gossipsub": "^15.0.17",
106
+ "@libp2p/kad-dht": "^16.2.0",
107
+ "@libp2p/mplex": "^12.0.16",
108
+ "@libp2p/noise": "^1.0.1",
109
+ "@libp2p/tcp": "^11.0.15",
110
+ "@libp2p/webrtc": "^6.0.16",
111
+ "@libp2p/websockets": "^10.1.8"
112
+ }
113
+ }