rird 2.1.231 → 2.3.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 (381) hide show
  1. package/AGENTS.md +86 -0
  2. package/COMPLETED_TEST_SUITE.txt +280 -0
  3. package/Dockerfile +18 -0
  4. package/README.md +397 -6
  5. package/RIRD_ERROR_HANDLING_SUMMARY.md +307 -0
  6. package/TESTING.md +512 -0
  7. package/TEST_IMPLEMENTATION_REPORT.md +463 -0
  8. package/TEST_SUITE.md +307 -0
  9. package/TEST_SUMMARY.txt +380 -0
  10. package/bin/rird-perf.js +37 -0
  11. package/bin/rird.js +43 -8
  12. package/bunfig.toml +4 -0
  13. package/create-wrapper.ps1 +51 -0
  14. package/docs/ARCHITECTURE.md +768 -0
  15. package/docs/CLI_REFERENCE.md +681 -0
  16. package/docs/DOCUMENTATION_MANIFEST.md +392 -0
  17. package/docs/INDEX.md +295 -0
  18. package/docs/PRODUCTION_SETUP.md +633 -0
  19. package/docs/TROUBLESHOOTING.md +914 -0
  20. package/facebook_ads_library.png +0 -0
  21. package/nul +0 -0
  22. package/nul`nif +0 -0
  23. package/package.json +104 -15
  24. package/parsers-config.ts +239 -0
  25. package/rird-1.0.199.tgz +0 -0
  26. package/rird-1.0.205.tgz +0 -0
  27. package/script/build-windows.ts +56 -0
  28. package/script/build.ts +165 -0
  29. package/{postinstall.mjs → script/postinstall.mjs} +47 -68
  30. package/script/publish-registries.ts +187 -0
  31. package/script/publish.ts +85 -0
  32. package/script/schema.ts +47 -0
  33. package/src/acp/README.md +164 -0
  34. package/src/acp/agent.ts +1063 -0
  35. package/src/acp/session.ts +101 -0
  36. package/src/acp/types.ts +22 -0
  37. package/src/agent/agent.ts +367 -0
  38. package/src/agent/generate.txt +75 -0
  39. package/src/agent/prompt/compaction.txt +12 -0
  40. package/src/agent/prompt/explore.txt +18 -0
  41. package/src/agent/prompt/summary.txt +10 -0
  42. package/src/agent/prompt/title.txt +36 -0
  43. package/src/auth/index.ts +70 -0
  44. package/src/bun/index.ts +114 -0
  45. package/src/bus/bus-event.ts +43 -0
  46. package/src/bus/global.ts +10 -0
  47. package/src/bus/index.ts +105 -0
  48. package/src/cli/bootstrap.ts +17 -0
  49. package/src/cli/cmd/acp.ts +104 -0
  50. package/src/cli/cmd/activate.ts +50 -0
  51. package/src/cli/cmd/agent.ts +256 -0
  52. package/src/cli/cmd/auth.ts +412 -0
  53. package/src/cli/cmd/cmd.ts +7 -0
  54. package/src/cli/cmd/debug/config.ts +15 -0
  55. package/src/cli/cmd/debug/file.ts +91 -0
  56. package/src/cli/cmd/debug/index.ts +43 -0
  57. package/src/cli/cmd/debug/lsp.ts +48 -0
  58. package/src/cli/cmd/debug/ripgrep.ts +83 -0
  59. package/src/cli/cmd/debug/scrap.ts +15 -0
  60. package/src/cli/cmd/debug/skill.ts +15 -0
  61. package/src/cli/cmd/debug/snapshot.ts +48 -0
  62. package/src/cli/cmd/export.ts +88 -0
  63. package/src/cli/cmd/generate.ts +38 -0
  64. package/src/cli/cmd/github.ts +1400 -0
  65. package/src/cli/cmd/import.ts +98 -0
  66. package/src/cli/cmd/mcp.ts +654 -0
  67. package/src/cli/cmd/models.ts +68 -0
  68. package/src/cli/cmd/pr.ts +112 -0
  69. package/src/cli/cmd/run.ts +434 -0
  70. package/src/cli/cmd/serve.ts +31 -0
  71. package/src/cli/cmd/session.ts +106 -0
  72. package/src/cli/cmd/stats.ts +298 -0
  73. package/src/cli/cmd/tui/app.tsx +694 -0
  74. package/src/cli/cmd/tui/attach.ts +30 -0
  75. package/src/cli/cmd/tui/component/border.tsx +21 -0
  76. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  77. package/src/cli/cmd/tui/component/dialog-command.tsx +124 -0
  78. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  79. package/src/cli/cmd/tui/component/dialog-model.tsx +236 -0
  80. package/src/cli/cmd/tui/component/dialog-provider.tsx +240 -0
  81. package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
  82. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  83. package/src/cli/cmd/tui/component/dialog-stash.tsx +86 -0
  84. package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
  85. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  86. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  87. package/src/cli/cmd/tui/component/did-you-know.tsx +85 -0
  88. package/src/cli/cmd/tui/component/logo.tsx +48 -0
  89. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +574 -0
  90. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  91. package/src/cli/cmd/tui/component/prompt/index.tsx +1087 -0
  92. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  93. package/src/cli/cmd/tui/component/tips.ts +27 -0
  94. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  95. package/src/cli/cmd/tui/context/args.tsx +14 -0
  96. package/src/cli/cmd/tui/context/directory.ts +13 -0
  97. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  98. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  99. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  100. package/src/cli/cmd/tui/context/kv.tsx +49 -0
  101. package/src/cli/cmd/tui/context/local.tsx +345 -0
  102. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  103. package/src/cli/cmd/tui/context/route.tsx +46 -0
  104. package/src/cli/cmd/tui/context/sdk.tsx +74 -0
  105. package/src/cli/cmd/tui/context/sync.tsx +372 -0
  106. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  107. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  108. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  109. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  110. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  111. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  112. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  113. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  114. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  115. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  116. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  117. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  118. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  119. package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
  120. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  121. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  122. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  123. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  124. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  125. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  126. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  127. package/src/cli/cmd/tui/context/theme/orng.json +245 -0
  128. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  129. package/src/cli/cmd/tui/context/theme/rird.json +245 -0
  130. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  131. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  132. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  133. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  134. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  135. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  136. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  137. package/src/cli/cmd/tui/context/theme.tsx +1109 -0
  138. package/src/cli/cmd/tui/event.ts +40 -0
  139. package/src/cli/cmd/tui/hooks/use-safe-terminal-dimensions.ts +12 -0
  140. package/src/cli/cmd/tui/routes/home.tsx +138 -0
  141. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  142. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  143. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  144. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  145. package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
  146. package/src/cli/cmd/tui/routes/session/header.tsx +125 -0
  147. package/src/cli/cmd/tui/routes/session/index.tsx +1876 -0
  148. package/src/cli/cmd/tui/routes/session/sidebar.tsx +320 -0
  149. package/src/cli/cmd/tui/spawn.ts +60 -0
  150. package/src/cli/cmd/tui/thread.ts +142 -0
  151. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  152. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  153. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  154. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  155. package/src/cli/cmd/tui/ui/dialog-select.tsx +333 -0
  156. package/src/cli/cmd/tui/ui/dialog.tsx +171 -0
  157. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  158. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  159. package/src/cli/cmd/tui/util/clipboard.ts +127 -0
  160. package/src/cli/cmd/tui/util/editor.ts +32 -0
  161. package/src/cli/cmd/tui/util/terminal.ts +146 -0
  162. package/src/cli/cmd/tui/worker.ts +63 -0
  163. package/src/cli/cmd/uninstall.ts +344 -0
  164. package/src/cli/cmd/upgrade.ts +127 -0
  165. package/src/cli/cmd/web.ts +84 -0
  166. package/src/cli/error.ts +69 -0
  167. package/src/cli/ui.ts +101 -0
  168. package/src/cli/upgrade.ts +28 -0
  169. package/src/command/index.ts +80 -0
  170. package/src/command/template/initialize.txt +10 -0
  171. package/src/command/template/review.txt +97 -0
  172. package/src/config/config.ts +994 -0
  173. package/src/config/markdown.ts +41 -0
  174. package/src/env/index.ts +26 -0
  175. package/src/file/ignore.ts +83 -0
  176. package/src/file/index.ts +328 -0
  177. package/src/file/ripgrep.ts +393 -0
  178. package/src/file/time.ts +64 -0
  179. package/src/file/watcher.ts +103 -0
  180. package/src/flag/flag.ts +84 -0
  181. package/src/format/formatter.ts +315 -0
  182. package/src/format/index.ts +137 -0
  183. package/src/global/index.ts +101 -0
  184. package/src/id/id.ts +73 -0
  185. package/src/ide/index.ts +76 -0
  186. package/src/index.ts +297 -0
  187. package/src/index.ts.backup +271 -0
  188. package/src/installation/index.ts +258 -0
  189. package/src/lib/IMPLEMENTATION_NOTES.md +345 -0
  190. package/src/lib/error-handler.ts +225 -0
  191. package/src/lib/error-testing-guide.md +258 -0
  192. package/src/lib/errors.ts +285 -0
  193. package/src/lib/performance.ts +70 -0
  194. package/src/lib/telemetry.ts +282 -0
  195. package/src/lsp/client.ts +229 -0
  196. package/src/lsp/index.ts +485 -0
  197. package/src/lsp/language.ts +116 -0
  198. package/src/lsp/server.ts +1895 -0
  199. package/src/mcp/auth.ts +135 -0
  200. package/src/mcp/index.ts +1117 -0
  201. package/src/mcp/intent-analyzer.ts +376 -0
  202. package/src/mcp/oauth-callback.ts +200 -0
  203. package/src/mcp/oauth-provider.ts +154 -0
  204. package/src/patch/index.ts +632 -0
  205. package/src/permission/index.ts +199 -0
  206. package/src/plugin/index.ts +91 -0
  207. package/src/project/bootstrap.ts +33 -0
  208. package/src/project/instance.ts +78 -0
  209. package/src/project/project.ts +236 -0
  210. package/src/project/state.ts +65 -0
  211. package/src/project/vcs.ts +76 -0
  212. package/src/provider/auth.ts +143 -0
  213. package/src/provider/models-macro.ts +55 -0
  214. package/src/provider/models.ts +161 -0
  215. package/src/provider/provider.ts +1109 -0
  216. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  217. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  218. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
  219. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  220. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  221. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  222. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  223. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  224. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  225. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  226. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  227. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  228. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  229. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  230. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  231. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  232. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  233. package/src/provider/transform.ts +455 -0
  234. package/src/pty/index.ts +231 -0
  235. package/src/security/guardrails.test.ts +341 -0
  236. package/src/security/guardrails.ts +570 -0
  237. package/src/security/index.ts +19 -0
  238. package/src/server/error.ts +36 -0
  239. package/src/server/project.ts +79 -0
  240. package/src/server/server.ts +2641 -0
  241. package/src/server/tui.ts +71 -0
  242. package/src/session/compaction.ts +228 -0
  243. package/src/session/index.ts +464 -0
  244. package/src/session/llm.ts +201 -0
  245. package/src/session/message-v2.ts +695 -0
  246. package/src/session/message.ts +189 -0
  247. package/src/session/processor.ts +409 -0
  248. package/src/session/prompt/act-switch.txt +5 -0
  249. package/src/session/prompt/anthropic-20250930.txt +166 -0
  250. package/src/session/prompt/anthropic.txt +63 -0
  251. package/src/session/prompt/anthropic_spoof.txt +1 -0
  252. package/src/session/prompt/beast.txt +76 -0
  253. package/src/session/prompt/codex.txt +304 -0
  254. package/src/session/prompt/copilot-gpt-5.txt +137 -0
  255. package/src/session/prompt/gemini.txt +62 -0
  256. package/src/session/prompt/max-steps.txt +16 -0
  257. package/src/session/prompt/plan-reminder-anthropic.txt +35 -0
  258. package/src/session/prompt/plan.txt +24 -0
  259. package/src/session/prompt/polaris.txt +88 -0
  260. package/src/session/prompt/qwen.txt +59 -0
  261. package/src/session/prompt.ts +1552 -0
  262. package/src/session/retry.ts +86 -0
  263. package/src/session/revert.ts +108 -0
  264. package/src/session/sensitive-filter.test.ts +327 -0
  265. package/src/session/sensitive-filter.ts +466 -0
  266. package/src/session/status.ts +76 -0
  267. package/src/session/summary.ts +209 -0
  268. package/src/session/system.ts +122 -0
  269. package/src/session/todo.ts +37 -0
  270. package/src/share/share-next.ts +222 -0
  271. package/src/share/share.ts +87 -0
  272. package/src/shell/shell.ts +67 -0
  273. package/src/skill/index.ts +1 -0
  274. package/src/skill/skill.ts +83 -0
  275. package/src/snapshot/index.ts +197 -0
  276. package/src/storage/storage.ts +226 -0
  277. package/src/tests/agent.test.ts +308 -0
  278. package/src/tests/build-guards.test.ts +267 -0
  279. package/src/tests/config.test.ts +664 -0
  280. package/src/tests/tool-registry.test.ts +589 -0
  281. package/src/tool/bash.ts +314 -0
  282. package/src/tool/bash.txt +158 -0
  283. package/src/tool/batch.ts +175 -0
  284. package/src/tool/batch.txt +24 -0
  285. package/src/tool/codesearch.ts +184 -0
  286. package/src/tool/codesearch.txt +12 -0
  287. package/src/tool/edit.ts +675 -0
  288. package/src/tool/edit.txt +10 -0
  289. package/src/tool/glob.ts +65 -0
  290. package/src/tool/glob.txt +6 -0
  291. package/src/tool/grep.ts +121 -0
  292. package/src/tool/grep.txt +8 -0
  293. package/src/tool/invalid.ts +17 -0
  294. package/src/tool/ls.ts +110 -0
  295. package/src/tool/ls.txt +1 -0
  296. package/src/tool/lsp-diagnostics.ts +26 -0
  297. package/src/tool/lsp-diagnostics.txt +1 -0
  298. package/src/tool/lsp-hover.ts +31 -0
  299. package/src/tool/lsp-hover.txt +1 -0
  300. package/src/tool/lsp.ts +87 -0
  301. package/src/tool/lsp.txt +19 -0
  302. package/src/tool/multiedit.ts +46 -0
  303. package/src/tool/multiedit.txt +41 -0
  304. package/src/tool/patch.ts +233 -0
  305. package/src/tool/patch.txt +1 -0
  306. package/src/tool/read.ts +219 -0
  307. package/src/tool/read.txt +12 -0
  308. package/src/tool/registry.ts +162 -0
  309. package/src/tool/skill.ts +100 -0
  310. package/src/tool/task.ts +136 -0
  311. package/src/tool/task.txt +51 -0
  312. package/src/tool/todo.ts +39 -0
  313. package/src/tool/todoread.txt +14 -0
  314. package/src/tool/todowrite.txt +167 -0
  315. package/src/tool/tool.ts +71 -0
  316. package/src/tool/webfetch.ts +198 -0
  317. package/src/tool/webfetch.txt +13 -0
  318. package/src/tool/websearch.ts +268 -0
  319. package/src/tool/websearch.txt +13 -0
  320. package/src/tool/write.ts +110 -0
  321. package/src/tool/write.txt +8 -0
  322. package/src/util/archive.ts +16 -0
  323. package/src/util/color.ts +19 -0
  324. package/src/util/context.ts +25 -0
  325. package/src/util/defer.ts +12 -0
  326. package/src/util/eventloop.ts +20 -0
  327. package/src/util/filesystem.ts +83 -0
  328. package/src/util/fn.ts +11 -0
  329. package/src/util/iife.ts +3 -0
  330. package/src/util/keybind.ts +102 -0
  331. package/src/util/lazy.ts +11 -0
  332. package/src/util/license.ts +362 -0
  333. package/src/util/locale.ts +81 -0
  334. package/src/util/lock.ts +98 -0
  335. package/src/util/log.ts +180 -0
  336. package/src/util/queue.ts +32 -0
  337. package/src/util/rpc.ts +42 -0
  338. package/src/util/scrap.ts +10 -0
  339. package/src/util/signal.ts +12 -0
  340. package/src/util/timeout.ts +14 -0
  341. package/src/util/token.ts +7 -0
  342. package/src/util/wildcard.ts +54 -0
  343. package/sst-env.d.ts +9 -0
  344. package/test/agent/agent.test.ts +146 -0
  345. package/test/bun.test.ts +53 -0
  346. package/test/cli/cmd/acp.test.ts +144 -0
  347. package/test/cli/cmd/run.test.ts +250 -0
  348. package/test/cli/github-remote.test.ts +80 -0
  349. package/test/config/agent-color.test.ts +66 -0
  350. package/test/config/config.test.ts +536 -0
  351. package/test/config/markdown.test.ts +89 -0
  352. package/test/file/ignore.test.ts +10 -0
  353. package/test/fixture/fixture.ts +37 -0
  354. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  355. package/test/helpers.ts +172 -0
  356. package/test/ide/ide.test.ts +82 -0
  357. package/test/installation/installation.test.ts +143 -0
  358. package/test/keybind.test.ts +421 -0
  359. package/test/lsp/client.test.ts +95 -0
  360. package/test/mcp/headers.test.ts +153 -0
  361. package/test/patch/patch.test.ts +348 -0
  362. package/test/preload.ts +57 -0
  363. package/test/project/project.test.ts +74 -0
  364. package/test/provider/provider.test.ts +74 -0
  365. package/test/provider/transform.test.ts +411 -0
  366. package/test/session/retry.test.ts +111 -0
  367. package/test/session/session.test.ts +71 -0
  368. package/test/skill/skill.test.ts +131 -0
  369. package/test/snapshot/snapshot.test.ts +940 -0
  370. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  371. package/test/tool/bash.test.ts +434 -0
  372. package/test/tool/grep.test.ts +108 -0
  373. package/test/tool/patch.test.ts +259 -0
  374. package/test/tool/read.test.ts +42 -0
  375. package/test/util/iife.test.ts +36 -0
  376. package/test/util/lazy.test.ts +50 -0
  377. package/test/util/license.test.ts +235 -0
  378. package/test/util/timeout.test.ts +21 -0
  379. package/test/util/wildcard.test.ts +55 -0
  380. package/tsconfig.json +16 -0
  381. package/update-versions.ps1 +65 -0
@@ -0,0 +1,536 @@
1
+ import { test, expect } from "bun:test"
2
+ import { Config } from "../../src/config/config"
3
+ import { Instance } from "../../src/project/instance"
4
+ import { tmpdir } from "../fixture/fixture"
5
+ import path from "path"
6
+ import fs from "fs/promises"
7
+ import { pathToFileURL } from "url"
8
+
9
+ test("loads config with defaults when no files exist", async () => {
10
+ await using tmp = await tmpdir()
11
+ await Instance.provide({
12
+ directory: tmp.path,
13
+ fn: async () => {
14
+ const config = await Config.get()
15
+ expect(config.username).toBeDefined()
16
+ },
17
+ })
18
+ })
19
+
20
+ test("loads JSON config file", async () => {
21
+ await using tmp = await tmpdir({
22
+ init: async (dir) => {
23
+ await Bun.write(
24
+ path.join(dir, "opencode.json"),
25
+ JSON.stringify({
26
+ $schema: "https://rird.ai/config.json",
27
+ model: "test/model",
28
+ username: "testuser",
29
+ }),
30
+ )
31
+ },
32
+ })
33
+ await Instance.provide({
34
+ directory: tmp.path,
35
+ fn: async () => {
36
+ const config = await Config.get()
37
+ expect(config.model).toBe("test/model")
38
+ expect(config.username).toBe("testuser")
39
+ },
40
+ })
41
+ })
42
+
43
+ test("loads JSONC config file", async () => {
44
+ await using tmp = await tmpdir({
45
+ init: async (dir) => {
46
+ await Bun.write(
47
+ path.join(dir, "opencode.jsonc"),
48
+ `{
49
+ // This is a comment
50
+ "$schema": "https://rird.ai/config.json",
51
+ "model": "test/model",
52
+ "username": "testuser"
53
+ }`,
54
+ )
55
+ },
56
+ })
57
+ await Instance.provide({
58
+ directory: tmp.path,
59
+ fn: async () => {
60
+ const config = await Config.get()
61
+ expect(config.model).toBe("test/model")
62
+ expect(config.username).toBe("testuser")
63
+ },
64
+ })
65
+ })
66
+
67
+ test("merges multiple config files with correct precedence", async () => {
68
+ await using tmp = await tmpdir({
69
+ init: async (dir) => {
70
+ await Bun.write(
71
+ path.join(dir, "opencode.jsonc"),
72
+ JSON.stringify({
73
+ $schema: "https://rird.ai/config.json",
74
+ model: "base",
75
+ username: "base",
76
+ }),
77
+ )
78
+ await Bun.write(
79
+ path.join(dir, "opencode.json"),
80
+ JSON.stringify({
81
+ $schema: "https://rird.ai/config.json",
82
+ model: "override",
83
+ }),
84
+ )
85
+ },
86
+ })
87
+ await Instance.provide({
88
+ directory: tmp.path,
89
+ fn: async () => {
90
+ const config = await Config.get()
91
+ expect(config.model).toBe("override")
92
+ expect(config.username).toBe("base")
93
+ },
94
+ })
95
+ })
96
+
97
+ test("handles environment variable substitution", async () => {
98
+ const originalEnv = process.env["TEST_VAR"]
99
+ process.env["TEST_VAR"] = "test_theme"
100
+
101
+ try {
102
+ await using tmp = await tmpdir({
103
+ init: async (dir) => {
104
+ await Bun.write(
105
+ path.join(dir, "opencode.json"),
106
+ JSON.stringify({
107
+ $schema: "https://rird.ai/config.json",
108
+ theme: "{env:TEST_VAR}",
109
+ }),
110
+ )
111
+ },
112
+ })
113
+ await Instance.provide({
114
+ directory: tmp.path,
115
+ fn: async () => {
116
+ const config = await Config.get()
117
+ expect(config.theme).toBe("test_theme")
118
+ },
119
+ })
120
+ } finally {
121
+ if (originalEnv !== undefined) {
122
+ process.env["TEST_VAR"] = originalEnv
123
+ } else {
124
+ delete process.env["TEST_VAR"]
125
+ }
126
+ }
127
+ })
128
+
129
+ test("handles file inclusion substitution", async () => {
130
+ await using tmp = await tmpdir({
131
+ init: async (dir) => {
132
+ await Bun.write(path.join(dir, "included.txt"), "test_theme")
133
+ await Bun.write(
134
+ path.join(dir, "opencode.json"),
135
+ JSON.stringify({
136
+ $schema: "https://rird.ai/config.json",
137
+ theme: "{file:included.txt}",
138
+ }),
139
+ )
140
+ },
141
+ })
142
+ await Instance.provide({
143
+ directory: tmp.path,
144
+ fn: async () => {
145
+ const config = await Config.get()
146
+ expect(config.theme).toBe("test_theme")
147
+ },
148
+ })
149
+ })
150
+
151
+ test("config ignores unknown fields", async () => {
152
+ await using tmp = await tmpdir({
153
+ init: async (dir) => {
154
+ await Bun.write(
155
+ path.join(dir, "opencode.json"),
156
+ JSON.stringify({
157
+ $schema: "https://rird.ai/config.json",
158
+ invalid_field: "should cause error",
159
+ }),
160
+ )
161
+ },
162
+ })
163
+ await Instance.provide({
164
+ directory: tmp.path,
165
+ fn: async () => {
166
+ const config = await Config.get()
167
+ // Unknown fields are allowed at the top level; they should not prevent parsing.
168
+ expect((config as any).invalid_field).toBe("should cause error")
169
+ },
170
+ })
171
+ })
172
+
173
+ test("throws error for invalid JSON", async () => {
174
+ await using tmp = await tmpdir({
175
+ init: async (dir) => {
176
+ await Bun.write(path.join(dir, "opencode.json"), "{ invalid json }")
177
+ },
178
+ })
179
+ await Instance.provide({
180
+ directory: tmp.path,
181
+ fn: async () => {
182
+ await expect(Config.get()).rejects.toThrow()
183
+ },
184
+ })
185
+ })
186
+
187
+ test("handles agent configuration", async () => {
188
+ await using tmp = await tmpdir({
189
+ init: async (dir) => {
190
+ await Bun.write(
191
+ path.join(dir, "opencode.json"),
192
+ JSON.stringify({
193
+ $schema: "https://rird.ai/config.json",
194
+ agent: {
195
+ test_agent: {
196
+ model: "test/model",
197
+ temperature: 0.7,
198
+ description: "test agent",
199
+ },
200
+ },
201
+ }),
202
+ )
203
+ },
204
+ })
205
+ await Instance.provide({
206
+ directory: tmp.path,
207
+ fn: async () => {
208
+ const config = await Config.get()
209
+ expect(config.agent?.["test_agent"]).toEqual({
210
+ model: "test/model",
211
+ temperature: 0.7,
212
+ description: "test agent",
213
+ })
214
+ },
215
+ })
216
+ })
217
+
218
+ test("handles command configuration", async () => {
219
+ await using tmp = await tmpdir({
220
+ init: async (dir) => {
221
+ await Bun.write(
222
+ path.join(dir, "opencode.json"),
223
+ JSON.stringify({
224
+ $schema: "https://rird.ai/config.json",
225
+ command: {
226
+ test_command: {
227
+ template: "test template",
228
+ description: "test command",
229
+ agent: "test_agent",
230
+ },
231
+ },
232
+ }),
233
+ )
234
+ },
235
+ })
236
+ await Instance.provide({
237
+ directory: tmp.path,
238
+ fn: async () => {
239
+ const config = await Config.get()
240
+ expect(config.command?.["test_command"]).toEqual({
241
+ template: "test template",
242
+ description: "test command",
243
+ agent: "test_agent",
244
+ })
245
+ },
246
+ })
247
+ })
248
+
249
+ test("migrates autoshare to share field", async () => {
250
+ await using tmp = await tmpdir({
251
+ init: async (dir) => {
252
+ await Bun.write(
253
+ path.join(dir, "opencode.json"),
254
+ JSON.stringify({
255
+ $schema: "https://rird.ai/config.json",
256
+ autoshare: true,
257
+ }),
258
+ )
259
+ },
260
+ })
261
+ await Instance.provide({
262
+ directory: tmp.path,
263
+ fn: async () => {
264
+ const config = await Config.get()
265
+ expect(config.share).toBe("auto")
266
+ expect(config.autoshare).toBe(true)
267
+ },
268
+ })
269
+ })
270
+
271
+ test("migrates mode field to agent field", async () => {
272
+ await using tmp = await tmpdir({
273
+ init: async (dir) => {
274
+ await Bun.write(
275
+ path.join(dir, "opencode.json"),
276
+ JSON.stringify({
277
+ $schema: "https://rird.ai/config.json",
278
+ mode: {
279
+ test_mode: {
280
+ model: "test/model",
281
+ temperature: 0.5,
282
+ },
283
+ },
284
+ }),
285
+ )
286
+ },
287
+ })
288
+ await Instance.provide({
289
+ directory: tmp.path,
290
+ fn: async () => {
291
+ const config = await Config.get()
292
+ expect(config.agent?.["test_mode"]).toEqual({
293
+ model: "test/model",
294
+ temperature: 0.5,
295
+ mode: "primary",
296
+ })
297
+ },
298
+ })
299
+ })
300
+
301
+ test("loads config from .opencode directory", async () => {
302
+ await using tmp = await tmpdir({
303
+ init: async (dir) => {
304
+ const opencodeDir = path.join(dir, ".opencode")
305
+ await fs.mkdir(opencodeDir, { recursive: true })
306
+ const agentDir = path.join(opencodeDir, "agent")
307
+ await fs.mkdir(agentDir, { recursive: true })
308
+
309
+ await Bun.write(
310
+ path.join(agentDir, "test.md"),
311
+ `---
312
+ model: test/model
313
+ ---
314
+ Test agent prompt`,
315
+ )
316
+ },
317
+ })
318
+ await Instance.provide({
319
+ directory: tmp.path,
320
+ fn: async () => {
321
+ const config = await Config.get()
322
+ expect(config.agent?.["test"]).toEqual({
323
+ name: "test",
324
+ model: "test/model",
325
+ prompt: "Test agent prompt",
326
+ })
327
+ },
328
+ })
329
+ })
330
+
331
+ test("updates config and writes to file", async () => {
332
+ await using tmp = await tmpdir()
333
+ await Instance.provide({
334
+ directory: tmp.path,
335
+ fn: async () => {
336
+ const newConfig = { model: "updated/model" }
337
+ await Config.update(newConfig as any)
338
+
339
+ const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "config.json")).text())
340
+ expect(writtenConfig.model).toBe("updated/model")
341
+ },
342
+ })
343
+ })
344
+
345
+ test("gets config directories", async () => {
346
+ await using tmp = await tmpdir()
347
+ await Instance.provide({
348
+ directory: tmp.path,
349
+ fn: async () => {
350
+ const dirs = await Config.directories()
351
+ expect(dirs.length).toBeGreaterThanOrEqual(1)
352
+ },
353
+ })
354
+ })
355
+
356
+ test.if(process.platform !== "win32")("resolves scoped npm plugins in config", async () => {
357
+ await using tmp = await tmpdir({
358
+ init: async (dir) => {
359
+ const pluginDir = path.join(dir, "node_modules", "@scope", "plugin")
360
+ await fs.mkdir(pluginDir, { recursive: true })
361
+
362
+ await Bun.write(
363
+ path.join(dir, "package.json"),
364
+ JSON.stringify({ name: "config-fixture", version: "1.0.0", type: "module" }, null, 2),
365
+ )
366
+
367
+ await Bun.write(
368
+ path.join(pluginDir, "package.json"),
369
+ JSON.stringify(
370
+ {
371
+ name: "@scope/plugin",
372
+ version: "1.0.0",
373
+ type: "module",
374
+ main: "./index.js",
375
+ },
376
+ null,
377
+ 2,
378
+ ),
379
+ )
380
+
381
+ await Bun.write(path.join(pluginDir, "index.js"), "export default {}\n")
382
+
383
+ await Bun.write(
384
+ path.join(dir, "opencode.json"),
385
+ JSON.stringify({ $schema: "https://rird.ai/config.json", plugin: ["@scope/plugin"] }, null, 2),
386
+ )
387
+ },
388
+ })
389
+
390
+ await Instance.provide({
391
+ directory: tmp.path,
392
+ fn: async () => {
393
+ const config = await Config.get()
394
+ const pluginEntries = config.plugin ?? []
395
+
396
+ const baseUrl = pathToFileURL(path.join(tmp.path, "opencode.json")).href
397
+ const expected = import.meta.resolve("@scope/plugin", baseUrl)
398
+
399
+ expect(pluginEntries.includes(expected)).toBe(true)
400
+
401
+ const scopedEntry = pluginEntries.find((entry) => entry === expected)
402
+ expect(scopedEntry).toBeDefined()
403
+ expect(scopedEntry?.includes("/node_modules/@scope/plugin/")).toBe(true)
404
+ },
405
+ })
406
+ })
407
+
408
+ test("merges plugin arrays from global and local configs", async () => {
409
+ await using tmp = await tmpdir({
410
+ init: async (dir) => {
411
+ // Create a nested project structure with local .opencode config
412
+ const projectDir = path.join(dir, "project")
413
+ const opencodeDir = path.join(projectDir, ".opencode")
414
+ await fs.mkdir(opencodeDir, { recursive: true })
415
+
416
+ // Global config with plugins
417
+ await Bun.write(
418
+ path.join(dir, "opencode.json"),
419
+ JSON.stringify({
420
+ $schema: "https://rird.ai/config.json",
421
+ plugin: ["global-plugin-1", "global-plugin-2"],
422
+ }),
423
+ )
424
+
425
+ // Local .opencode config with different plugins
426
+ await Bun.write(
427
+ path.join(opencodeDir, "opencode.json"),
428
+ JSON.stringify({
429
+ $schema: "https://rird.ai/config.json",
430
+ plugin: ["local-plugin-1"],
431
+ }),
432
+ )
433
+ },
434
+ })
435
+
436
+ await Instance.provide({
437
+ directory: path.join(tmp.path, "project"),
438
+ fn: async () => {
439
+ const config = await Config.get()
440
+ const plugins = config.plugin ?? []
441
+
442
+ // Should contain both global and local plugins
443
+ expect(plugins.some((p) => p.includes("global-plugin-1"))).toBe(true)
444
+ expect(plugins.some((p) => p.includes("global-plugin-2"))).toBe(true)
445
+ expect(plugins.some((p) => p.includes("local-plugin-1"))).toBe(true)
446
+
447
+ // Should have all 3 plugins (not replaced, but merged)
448
+ const pluginNames = plugins.filter((p) => p.includes("global-plugin") || p.includes("local-plugin"))
449
+ expect(pluginNames.length).toBeGreaterThanOrEqual(3)
450
+ },
451
+ })
452
+ })
453
+
454
+ test("does not error when only custom agent is a subagent", async () => {
455
+ await using tmp = await tmpdir({
456
+ init: async (dir) => {
457
+ const opencodeDir = path.join(dir, ".opencode")
458
+ await fs.mkdir(opencodeDir, { recursive: true })
459
+ const agentDir = path.join(opencodeDir, "agent")
460
+ await fs.mkdir(agentDir, { recursive: true })
461
+
462
+ await Bun.write(
463
+ path.join(agentDir, "helper.md"),
464
+ `---
465
+ model: test/model
466
+ mode: subagent
467
+ ---
468
+ Helper subagent prompt`,
469
+ )
470
+ },
471
+ })
472
+ await Instance.provide({
473
+ directory: tmp.path,
474
+ fn: async () => {
475
+ const config = await Config.get()
476
+ expect(config.agent?.["helper"]).toEqual({
477
+ name: "helper",
478
+ model: "test/model",
479
+ mode: "subagent",
480
+ prompt: "Helper subagent prompt",
481
+ })
482
+ },
483
+ })
484
+ })
485
+
486
+ test("deduplicates duplicate plugins from global and local configs", async () => {
487
+ await using tmp = await tmpdir({
488
+ init: async (dir) => {
489
+ // Create a nested project structure with local .opencode config
490
+ const projectDir = path.join(dir, "project")
491
+ const opencodeDir = path.join(projectDir, ".opencode")
492
+ await fs.mkdir(opencodeDir, { recursive: true })
493
+
494
+ // Global config with plugins
495
+ await Bun.write(
496
+ path.join(dir, "opencode.json"),
497
+ JSON.stringify({
498
+ $schema: "https://rird.ai/config.json",
499
+ plugin: ["duplicate-plugin", "global-plugin-1"],
500
+ }),
501
+ )
502
+
503
+ // Local .opencode config with some overlapping plugins
504
+ await Bun.write(
505
+ path.join(opencodeDir, "opencode.json"),
506
+ JSON.stringify({
507
+ $schema: "https://rird.ai/config.json",
508
+ plugin: ["duplicate-plugin", "local-plugin-1"],
509
+ }),
510
+ )
511
+ },
512
+ })
513
+
514
+ await Instance.provide({
515
+ directory: path.join(tmp.path, "project"),
516
+ fn: async () => {
517
+ const config = await Config.get()
518
+ const plugins = config.plugin ?? []
519
+
520
+ // Should contain all unique plugins
521
+ expect(plugins.some((p) => p.includes("global-plugin-1"))).toBe(true)
522
+ expect(plugins.some((p) => p.includes("local-plugin-1"))).toBe(true)
523
+ expect(plugins.some((p) => p.includes("duplicate-plugin"))).toBe(true)
524
+
525
+ // Should deduplicate the duplicate plugin
526
+ const duplicatePlugins = plugins.filter((p) => p.includes("duplicate-plugin"))
527
+ expect(duplicatePlugins.length).toBe(1)
528
+
529
+ // Should have exactly 3 unique plugins
530
+ const pluginNames = plugins.filter(
531
+ (p) => p.includes("global-plugin") || p.includes("local-plugin") || p.includes("duplicate-plugin"),
532
+ )
533
+ expect(pluginNames.length).toBe(3)
534
+ },
535
+ })
536
+ })
@@ -0,0 +1,89 @@
1
+ import { expect, test } from "bun:test"
2
+ import { ConfigMarkdown } from "../../src/config/markdown"
3
+
4
+ const template = `This is a @valid/path/to/a/file and it should also match at
5
+ the beginning of a line:
6
+
7
+ @another-valid/path/to/a/file
8
+
9
+ but this is not:
10
+
11
+ - Adds a "Co-authored-by:" footer which clarifies which AI agent
12
+ helped create this commit, using an appropriate \`noreply@...\`
13
+ or \`noreply@anthropic.com\` email address.
14
+
15
+ We also need to deal with files followed by @commas, ones
16
+ with @file-extensions.md, even @multiple.extensions.bak,
17
+ hidden directorys like @.config/ or files like @.bashrc
18
+ and ones at the end of a sentence like @foo.md.
19
+
20
+ Also shouldn't forget @/absolute/paths.txt with and @/without/extensions,
21
+ as well as @~/home-files and @~/paths/under/home.txt.
22
+
23
+ If the reference is \`@quoted/in/backticks\` then it shouldn't match at all.`
24
+
25
+ const matches = ConfigMarkdown.files(template)
26
+
27
+ test("should extract exactly 12 file references", () => {
28
+ expect(matches.length).toBe(12)
29
+ })
30
+
31
+ test("should extract valid/path/to/a/file", () => {
32
+ expect(matches[0][1]).toBe("valid/path/to/a/file")
33
+ })
34
+
35
+ test("should extract another-valid/path/to/a/file", () => {
36
+ expect(matches[1][1]).toBe("another-valid/path/to/a/file")
37
+ })
38
+
39
+ test("should extract paths ignoring comma after", () => {
40
+ expect(matches[2][1]).toBe("commas")
41
+ })
42
+
43
+ test("should extract a path with a file extension and comma after", () => {
44
+ expect(matches[3][1]).toBe("file-extensions.md")
45
+ })
46
+
47
+ test("should extract a path with multiple dots and comma after", () => {
48
+ expect(matches[4][1]).toBe("multiple.extensions.bak")
49
+ })
50
+
51
+ test("should extract hidden directory", () => {
52
+ expect(matches[5][1]).toBe(".config/")
53
+ })
54
+
55
+ test("should extract hidden file", () => {
56
+ expect(matches[6][1]).toBe(".bashrc")
57
+ })
58
+
59
+ test("should extract a file ignoring period at end of sentence", () => {
60
+ expect(matches[7][1]).toBe("foo.md")
61
+ })
62
+
63
+ test("should extract an absolute path with an extension", () => {
64
+ expect(matches[8][1]).toBe("/absolute/paths.txt")
65
+ })
66
+
67
+ test("should extract an absolute path without an extension", () => {
68
+ expect(matches[9][1]).toBe("/without/extensions")
69
+ })
70
+
71
+ test("should extract an absolute path in home directory", () => {
72
+ expect(matches[10][1]).toBe("~/home-files")
73
+ })
74
+
75
+ test("should extract an absolute path under home directory", () => {
76
+ expect(matches[11][1]).toBe("~/paths/under/home.txt")
77
+ })
78
+
79
+ test("should not match when preceded by backtick", () => {
80
+ const backtickTest = "This `@should/not/match` should be ignored"
81
+ const backtickMatches = ConfigMarkdown.files(backtickTest)
82
+ expect(backtickMatches.length).toBe(0)
83
+ })
84
+
85
+ test("should not match email addresses", () => {
86
+ const emailTest = "Contact user@example.com for help"
87
+ const emailMatches = ConfigMarkdown.files(emailTest)
88
+ expect(emailMatches.length).toBe(0)
89
+ })
@@ -0,0 +1,10 @@
1
+ import { test, expect } from "bun:test"
2
+ import { FileIgnore } from "../../src/file/ignore"
3
+
4
+ test("match nested and non-nested", () => {
5
+ expect(FileIgnore.match("node_modules/index.js")).toBe(true)
6
+ expect(FileIgnore.match("node_modules")).toBe(true)
7
+ expect(FileIgnore.match("node_modules/")).toBe(true)
8
+ expect(FileIgnore.match("node_modules/bar")).toBe(true)
9
+ expect(FileIgnore.match("node_modules/bar/")).toBe(true)
10
+ })
@@ -0,0 +1,37 @@
1
+ import { $ } from "bun"
2
+ import * as fs from "fs/promises"
3
+ import os from "os"
4
+ import path from "path"
5
+
6
+ // Strip null bytes and non-printable characters from paths
7
+ function sanitizePath(p: string): string {
8
+ if (!p) return ""
9
+ return p.split("\0")[0].replace(/[\x00-\x1F\x7F-\x9F]/g, "").trim()
10
+ }
11
+
12
+ type TmpDirOptions<T> = {
13
+ git?: boolean
14
+ init?: (dir: string) => Promise<T>
15
+ dispose?: (dir: string) => Promise<T>
16
+ }
17
+ export async function tmpdir<T>(options?: TmpDirOptions<T>) {
18
+ const dirpath = sanitizePath(path.join(os.tmpdir(), "opencode-test-" + Math.random().toString(36).slice(2)))
19
+ await fs.mkdir(dirpath, { recursive: true })
20
+ if (options?.git) {
21
+ await $`git init`.cwd(dirpath).quiet()
22
+ await $`git config user.email "test@test.com"`.cwd(dirpath).quiet()
23
+ await $`git config user.name "Test User"`.cwd(dirpath).quiet()
24
+ await $`git commit --allow-empty -m "root commit ${dirpath}"`.cwd(dirpath).quiet()
25
+ }
26
+ const extra = await options?.init?.(dirpath)
27
+ const realpath = sanitizePath(await fs.realpath(dirpath))
28
+ const result = {
29
+ [Symbol.asyncDispose]: async () => {
30
+ await options?.dispose?.(dirpath)
31
+ // await fs.rm(dirpath, { recursive: true, force: true })
32
+ },
33
+ path: realpath,
34
+ extra: extra as T,
35
+ }
36
+ return result
37
+ }