rird 1.0.200

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 (350) hide show
  1. package/AGENTS.md +27 -0
  2. package/Dockerfile +18 -0
  3. package/README.md +15 -0
  4. package/bin/opencode +336 -0
  5. package/bin/pty-wrapper.js +285 -0
  6. package/bunfig.toml +4 -0
  7. package/facebook_ads_library.png +0 -0
  8. package/nul`nif +0 -0
  9. package/package.json +111 -0
  10. package/parsers-config.ts +239 -0
  11. package/rird-1.0.199.tgz +0 -0
  12. package/script/build-windows.ts +54 -0
  13. package/script/build.ts +167 -0
  14. package/script/postinstall.mjs +544 -0
  15. package/script/publish-registries.ts +187 -0
  16. package/script/publish.ts +72 -0
  17. package/script/schema.ts +47 -0
  18. package/src/acp/README.md +164 -0
  19. package/src/acp/agent.ts +1063 -0
  20. package/src/acp/session.ts +101 -0
  21. package/src/acp/types.ts +22 -0
  22. package/src/agent/agent.ts +367 -0
  23. package/src/agent/generate.txt +75 -0
  24. package/src/agent/prompt/compaction.txt +12 -0
  25. package/src/agent/prompt/explore.txt +18 -0
  26. package/src/agent/prompt/summary.txt +10 -0
  27. package/src/agent/prompt/title.txt +36 -0
  28. package/src/auth/index.ts +70 -0
  29. package/src/bun/index.ts +114 -0
  30. package/src/bus/bus-event.ts +43 -0
  31. package/src/bus/global.ts +10 -0
  32. package/src/bus/index.ts +105 -0
  33. package/src/cli/bootstrap.ts +17 -0
  34. package/src/cli/cmd/acp.ts +88 -0
  35. package/src/cli/cmd/agent.ts +256 -0
  36. package/src/cli/cmd/auth.ts +391 -0
  37. package/src/cli/cmd/cmd.ts +7 -0
  38. package/src/cli/cmd/debug/config.ts +15 -0
  39. package/src/cli/cmd/debug/file.ts +91 -0
  40. package/src/cli/cmd/debug/index.ts +43 -0
  41. package/src/cli/cmd/debug/lsp.ts +48 -0
  42. package/src/cli/cmd/debug/ripgrep.ts +83 -0
  43. package/src/cli/cmd/debug/scrap.ts +15 -0
  44. package/src/cli/cmd/debug/skill.ts +15 -0
  45. package/src/cli/cmd/debug/snapshot.ts +48 -0
  46. package/src/cli/cmd/export.ts +88 -0
  47. package/src/cli/cmd/generate.ts +38 -0
  48. package/src/cli/cmd/github.ts +1400 -0
  49. package/src/cli/cmd/import.ts +98 -0
  50. package/src/cli/cmd/mcp.ts +654 -0
  51. package/src/cli/cmd/models.ts +77 -0
  52. package/src/cli/cmd/pr.ts +112 -0
  53. package/src/cli/cmd/run.ts +368 -0
  54. package/src/cli/cmd/serve.ts +31 -0
  55. package/src/cli/cmd/session.ts +106 -0
  56. package/src/cli/cmd/stats.ts +298 -0
  57. package/src/cli/cmd/tui/app.tsx +696 -0
  58. package/src/cli/cmd/tui/attach.ts +30 -0
  59. package/src/cli/cmd/tui/component/border.tsx +21 -0
  60. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  61. package/src/cli/cmd/tui/component/dialog-command.tsx +124 -0
  62. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  63. package/src/cli/cmd/tui/component/dialog-model.tsx +245 -0
  64. package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
  65. package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
  66. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  67. package/src/cli/cmd/tui/component/dialog-stash.tsx +86 -0
  68. package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
  69. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  70. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  71. package/src/cli/cmd/tui/component/did-you-know.tsx +85 -0
  72. package/src/cli/cmd/tui/component/logo.tsx +35 -0
  73. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +574 -0
  74. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  75. package/src/cli/cmd/tui/component/prompt/index.tsx +1090 -0
  76. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  77. package/src/cli/cmd/tui/component/tips.ts +27 -0
  78. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  79. package/src/cli/cmd/tui/context/args.tsx +14 -0
  80. package/src/cli/cmd/tui/context/directory.ts +13 -0
  81. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  82. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  83. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  84. package/src/cli/cmd/tui/context/kv.tsx +49 -0
  85. package/src/cli/cmd/tui/context/local.tsx +354 -0
  86. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  87. package/src/cli/cmd/tui/context/route.tsx +46 -0
  88. package/src/cli/cmd/tui/context/sdk.tsx +74 -0
  89. package/src/cli/cmd/tui/context/sync.tsx +372 -0
  90. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  91. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  92. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  93. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  94. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  95. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  96. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  97. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  98. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  99. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  100. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  101. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  102. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  103. package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
  104. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  105. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  106. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  107. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  108. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  109. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  110. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  111. package/src/cli/cmd/tui/context/theme/orng.json +245 -0
  112. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  113. package/src/cli/cmd/tui/context/theme/rird.json +245 -0
  114. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  115. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  116. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  117. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  118. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  119. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  120. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  121. package/src/cli/cmd/tui/context/theme.tsx +1109 -0
  122. package/src/cli/cmd/tui/event.ts +40 -0
  123. package/src/cli/cmd/tui/routes/home.tsx +138 -0
  124. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  125. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  126. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  127. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  128. package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
  129. package/src/cli/cmd/tui/routes/session/header.tsx +125 -0
  130. package/src/cli/cmd/tui/routes/session/index.tsx +1864 -0
  131. package/src/cli/cmd/tui/routes/session/sidebar.tsx +318 -0
  132. package/src/cli/cmd/tui/spawn.ts +60 -0
  133. package/src/cli/cmd/tui/thread.ts +142 -0
  134. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  135. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  136. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  137. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  138. package/src/cli/cmd/tui/ui/dialog-select.tsx +332 -0
  139. package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
  140. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  141. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  142. package/src/cli/cmd/tui/util/clipboard.ts +127 -0
  143. package/src/cli/cmd/tui/util/editor.ts +32 -0
  144. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  145. package/src/cli/cmd/tui/worker.ts +63 -0
  146. package/src/cli/cmd/uninstall.ts +344 -0
  147. package/src/cli/cmd/upgrade.ts +100 -0
  148. package/src/cli/cmd/web.ts +84 -0
  149. package/src/cli/error.ts +56 -0
  150. package/src/cli/ui.ts +84 -0
  151. package/src/cli/upgrade.ts +25 -0
  152. package/src/command/index.ts +80 -0
  153. package/src/command/template/initialize.txt +10 -0
  154. package/src/command/template/review.txt +97 -0
  155. package/src/config/config.ts +995 -0
  156. package/src/config/markdown.ts +41 -0
  157. package/src/env/index.ts +26 -0
  158. package/src/file/ignore.ts +83 -0
  159. package/src/file/index.ts +328 -0
  160. package/src/file/ripgrep.ts +393 -0
  161. package/src/file/time.ts +64 -0
  162. package/src/file/watcher.ts +103 -0
  163. package/src/flag/flag.ts +46 -0
  164. package/src/format/formatter.ts +315 -0
  165. package/src/format/index.ts +137 -0
  166. package/src/global/index.ts +52 -0
  167. package/src/id/id.ts +73 -0
  168. package/src/ide/index.ts +76 -0
  169. package/src/index.ts +240 -0
  170. package/src/installation/index.ts +239 -0
  171. package/src/lsp/client.ts +229 -0
  172. package/src/lsp/index.ts +485 -0
  173. package/src/lsp/language.ts +116 -0
  174. package/src/lsp/server.ts +1895 -0
  175. package/src/mcp/auth.ts +135 -0
  176. package/src/mcp/index.ts +690 -0
  177. package/src/mcp/oauth-callback.ts +200 -0
  178. package/src/mcp/oauth-provider.ts +154 -0
  179. package/src/patch/index.ts +622 -0
  180. package/src/permission/index.ts +199 -0
  181. package/src/plugin/index.ts +91 -0
  182. package/src/project/bootstrap.ts +31 -0
  183. package/src/project/instance.ts +78 -0
  184. package/src/project/project.ts +221 -0
  185. package/src/project/state.ts +65 -0
  186. package/src/project/vcs.ts +76 -0
  187. package/src/provider/auth.ts +143 -0
  188. package/src/provider/models-macro.ts +11 -0
  189. package/src/provider/models.ts +106 -0
  190. package/src/provider/provider.ts +1071 -0
  191. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  192. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  193. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
  194. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  195. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  196. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  197. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  198. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  199. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  200. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  201. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  202. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  203. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  204. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  205. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  206. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  207. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  208. package/src/provider/transform.ts +455 -0
  209. package/src/pty/index.ts +231 -0
  210. package/src/security/guardrails.test.ts +341 -0
  211. package/src/security/guardrails.ts +558 -0
  212. package/src/security/index.ts +19 -0
  213. package/src/server/error.ts +36 -0
  214. package/src/server/project.ts +79 -0
  215. package/src/server/server.ts +2642 -0
  216. package/src/server/tui.ts +71 -0
  217. package/src/session/compaction.ts +223 -0
  218. package/src/session/index.ts +461 -0
  219. package/src/session/llm.ts +201 -0
  220. package/src/session/message-v2.ts +690 -0
  221. package/src/session/message.ts +189 -0
  222. package/src/session/processor.ts +409 -0
  223. package/src/session/prompt/act-switch.txt +5 -0
  224. package/src/session/prompt/anthropic-20250930.txt +166 -0
  225. package/src/session/prompt/anthropic.txt +85 -0
  226. package/src/session/prompt/anthropic_spoof.txt +1 -0
  227. package/src/session/prompt/beast.txt +103 -0
  228. package/src/session/prompt/codex.txt +304 -0
  229. package/src/session/prompt/copilot-gpt-5.txt +138 -0
  230. package/src/session/prompt/gemini.txt +85 -0
  231. package/src/session/prompt/max-steps.txt +16 -0
  232. package/src/session/prompt/plan-reminder-anthropic.txt +35 -0
  233. package/src/session/prompt/plan.txt +24 -0
  234. package/src/session/prompt/polaris.txt +84 -0
  235. package/src/session/prompt/qwen.txt +106 -0
  236. package/src/session/prompt.ts +1509 -0
  237. package/src/session/retry.ts +86 -0
  238. package/src/session/revert.ts +108 -0
  239. package/src/session/sensitive-filter.test.ts +327 -0
  240. package/src/session/sensitive-filter.ts +466 -0
  241. package/src/session/status.ts +76 -0
  242. package/src/session/summary.ts +194 -0
  243. package/src/session/system.ts +120 -0
  244. package/src/session/todo.ts +37 -0
  245. package/src/share/share-next.ts +194 -0
  246. package/src/share/share.ts +87 -0
  247. package/src/shell/shell.ts +67 -0
  248. package/src/skill/index.ts +1 -0
  249. package/src/skill/skill.ts +83 -0
  250. package/src/snapshot/index.ts +197 -0
  251. package/src/storage/storage.ts +226 -0
  252. package/src/tests/agent.test.ts +308 -0
  253. package/src/tests/build-guards.test.ts +267 -0
  254. package/src/tests/config.test.ts +664 -0
  255. package/src/tests/tool-registry.test.ts +589 -0
  256. package/src/tool/bash.ts +317 -0
  257. package/src/tool/bash.txt +158 -0
  258. package/src/tool/batch.ts +175 -0
  259. package/src/tool/batch.txt +24 -0
  260. package/src/tool/codesearch.ts +168 -0
  261. package/src/tool/codesearch.txt +12 -0
  262. package/src/tool/edit.ts +675 -0
  263. package/src/tool/edit.txt +10 -0
  264. package/src/tool/glob.ts +65 -0
  265. package/src/tool/glob.txt +6 -0
  266. package/src/tool/grep.ts +121 -0
  267. package/src/tool/grep.txt +8 -0
  268. package/src/tool/invalid.ts +17 -0
  269. package/src/tool/ls.ts +110 -0
  270. package/src/tool/ls.txt +1 -0
  271. package/src/tool/lsp-diagnostics.ts +26 -0
  272. package/src/tool/lsp-diagnostics.txt +1 -0
  273. package/src/tool/lsp-hover.ts +31 -0
  274. package/src/tool/lsp-hover.txt +1 -0
  275. package/src/tool/lsp.ts +87 -0
  276. package/src/tool/lsp.txt +19 -0
  277. package/src/tool/multiedit.ts +46 -0
  278. package/src/tool/multiedit.txt +41 -0
  279. package/src/tool/patch.ts +233 -0
  280. package/src/tool/patch.txt +1 -0
  281. package/src/tool/read.ts +219 -0
  282. package/src/tool/read.txt +12 -0
  283. package/src/tool/registry.ts +162 -0
  284. package/src/tool/skill.ts +100 -0
  285. package/src/tool/task.ts +136 -0
  286. package/src/tool/task.txt +51 -0
  287. package/src/tool/todo.ts +39 -0
  288. package/src/tool/todoread.txt +14 -0
  289. package/src/tool/todowrite.txt +167 -0
  290. package/src/tool/tool.ts +71 -0
  291. package/src/tool/webfetch.ts +198 -0
  292. package/src/tool/webfetch.txt +13 -0
  293. package/src/tool/websearch.ts +180 -0
  294. package/src/tool/websearch.txt +11 -0
  295. package/src/tool/write.ts +110 -0
  296. package/src/tool/write.txt +8 -0
  297. package/src/util/archive.ts +16 -0
  298. package/src/util/color.ts +19 -0
  299. package/src/util/context.ts +25 -0
  300. package/src/util/defer.ts +12 -0
  301. package/src/util/eventloop.ts +20 -0
  302. package/src/util/filesystem.ts +83 -0
  303. package/src/util/fn.ts +11 -0
  304. package/src/util/iife.ts +3 -0
  305. package/src/util/keybind.ts +102 -0
  306. package/src/util/lazy.ts +11 -0
  307. package/src/util/license.ts +325 -0
  308. package/src/util/locale.ts +81 -0
  309. package/src/util/lock.ts +98 -0
  310. package/src/util/log.ts +180 -0
  311. package/src/util/queue.ts +32 -0
  312. package/src/util/rpc.ts +42 -0
  313. package/src/util/scrap.ts +10 -0
  314. package/src/util/signal.ts +12 -0
  315. package/src/util/timeout.ts +14 -0
  316. package/src/util/token.ts +7 -0
  317. package/src/util/wildcard.ts +54 -0
  318. package/sst-env.d.ts +9 -0
  319. package/test/agent/agent.test.ts +146 -0
  320. package/test/bun.test.ts +53 -0
  321. package/test/cli/github-remote.test.ts +80 -0
  322. package/test/config/agent-color.test.ts +66 -0
  323. package/test/config/config.test.ts +535 -0
  324. package/test/config/markdown.test.ts +89 -0
  325. package/test/file/ignore.test.ts +10 -0
  326. package/test/fixture/fixture.ts +36 -0
  327. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  328. package/test/ide/ide.test.ts +82 -0
  329. package/test/keybind.test.ts +421 -0
  330. package/test/lsp/client.test.ts +95 -0
  331. package/test/mcp/headers.test.ts +153 -0
  332. package/test/patch/patch.test.ts +348 -0
  333. package/test/preload.ts +57 -0
  334. package/test/project/project.test.ts +72 -0
  335. package/test/provider/provider.test.ts +1809 -0
  336. package/test/provider/transform.test.ts +411 -0
  337. package/test/session/retry.test.ts +111 -0
  338. package/test/session/session.test.ts +71 -0
  339. package/test/skill/skill.test.ts +131 -0
  340. package/test/snapshot/snapshot.test.ts +939 -0
  341. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  342. package/test/tool/bash.test.ts +434 -0
  343. package/test/tool/grep.test.ts +108 -0
  344. package/test/tool/patch.test.ts +259 -0
  345. package/test/tool/read.test.ts +42 -0
  346. package/test/util/iife.test.ts +36 -0
  347. package/test/util/lazy.test.ts +50 -0
  348. package/test/util/timeout.test.ts +21 -0
  349. package/test/util/wildcard.test.ts +55 -0
  350. package/tsconfig.json +16 -0
@@ -0,0 +1,101 @@
1
+ import { RequestError, type McpServer } from "@agentclientprotocol/sdk"
2
+ import type { ACPSessionState } from "./types"
3
+ import { Log } from "@/util/log"
4
+ import type { OpencodeClient } from "@opencode-ai/sdk/v2"
5
+
6
+ const log = Log.create({ service: "acp-session-manager" })
7
+
8
+ export class ACPSessionManager {
9
+ private sessions = new Map<string, ACPSessionState>()
10
+ private sdk: OpencodeClient
11
+
12
+ constructor(sdk: OpencodeClient) {
13
+ this.sdk = sdk
14
+ }
15
+
16
+ async create(cwd: string, mcpServers: McpServer[], model?: ACPSessionState["model"]): Promise<ACPSessionState> {
17
+ const session = await this.sdk.session
18
+ .create(
19
+ {
20
+ title: `ACP Session ${crypto.randomUUID()}`,
21
+ directory: cwd,
22
+ },
23
+ { throwOnError: true },
24
+ )
25
+ .then((x) => x.data!)
26
+
27
+ const sessionId = session.id
28
+ const resolvedModel = model
29
+
30
+ const state: ACPSessionState = {
31
+ id: sessionId,
32
+ cwd,
33
+ mcpServers,
34
+ createdAt: new Date(),
35
+ model: resolvedModel,
36
+ }
37
+ log.info("creating_session", { state })
38
+
39
+ this.sessions.set(sessionId, state)
40
+ return state
41
+ }
42
+
43
+ async load(
44
+ sessionId: string,
45
+ cwd: string,
46
+ mcpServers: McpServer[],
47
+ model?: ACPSessionState["model"],
48
+ ): Promise<ACPSessionState> {
49
+ const session = await this.sdk.session
50
+ .get(
51
+ {
52
+ sessionID: sessionId,
53
+ directory: cwd,
54
+ },
55
+ { throwOnError: true },
56
+ )
57
+ .then((x) => x.data!)
58
+
59
+ const resolvedModel = model
60
+
61
+ const state: ACPSessionState = {
62
+ id: sessionId,
63
+ cwd,
64
+ mcpServers,
65
+ createdAt: new Date(session.time.created),
66
+ model: resolvedModel,
67
+ }
68
+ log.info("loading_session", { state })
69
+
70
+ this.sessions.set(sessionId, state)
71
+ return state
72
+ }
73
+
74
+ get(sessionId: string): ACPSessionState {
75
+ const session = this.sessions.get(sessionId)
76
+ if (!session) {
77
+ log.error("session not found", { sessionId })
78
+ throw RequestError.invalidParams(JSON.stringify({ error: `Session not found: ${sessionId}` }))
79
+ }
80
+ return session
81
+ }
82
+
83
+ getModel(sessionId: string) {
84
+ const session = this.get(sessionId)
85
+ return session.model
86
+ }
87
+
88
+ setModel(sessionId: string, model: ACPSessionState["model"]) {
89
+ const session = this.get(sessionId)
90
+ session.model = model
91
+ this.sessions.set(sessionId, session)
92
+ return session
93
+ }
94
+
95
+ setMode(sessionId: string, modeId: string) {
96
+ const session = this.get(sessionId)
97
+ session.modeId = modeId
98
+ this.sessions.set(sessionId, session)
99
+ return session
100
+ }
101
+ }
@@ -0,0 +1,22 @@
1
+ import type { McpServer } from "@agentclientprotocol/sdk"
2
+ import type { OpencodeClient } from "@opencode-ai/sdk/v2"
3
+
4
+ export interface ACPSessionState {
5
+ id: string
6
+ cwd: string
7
+ mcpServers: McpServer[]
8
+ createdAt: Date
9
+ model?: {
10
+ providerID: string
11
+ modelID: string
12
+ }
13
+ modeId?: string
14
+ }
15
+
16
+ export interface ACPConfig {
17
+ sdk: OpencodeClient
18
+ defaultModel?: {
19
+ providerID: string
20
+ modelID: string
21
+ }
22
+ }
@@ -0,0 +1,367 @@
1
+ import { Config } from "../config/config"
2
+ import z from "zod"
3
+ import { Provider } from "../provider/provider"
4
+ import { generateObject, type ModelMessage } from "ai"
5
+ import { SystemPrompt } from "../session/system"
6
+ import { Instance } from "../project/instance"
7
+ import { mergeDeep } from "remeda"
8
+ import { Log } from "../util/log"
9
+
10
+ const log = Log.create({ service: "agent" })
11
+
12
+ import PROMPT_GENERATE from "./generate.txt"
13
+ import PROMPT_COMPACTION from "./prompt/compaction.txt"
14
+ import PROMPT_SUMMARY from "./prompt/summary.txt"
15
+ import PROMPT_TITLE from "./prompt/title.txt"
16
+
17
+ export namespace Agent {
18
+ export const Info = z
19
+ .object({
20
+ name: z.string(),
21
+ description: z.string().optional(),
22
+ mode: z.enum(["subagent", "primary", "all"]),
23
+ native: z.boolean().optional(),
24
+ hidden: z.boolean().optional(),
25
+ default: z.boolean().optional(),
26
+ topP: z.number().optional(),
27
+ temperature: z.number().optional(),
28
+ color: z.string().optional(),
29
+ permission: z.object({
30
+ edit: Config.Permission,
31
+ bash: z.record(z.string(), Config.Permission),
32
+ skill: z.record(z.string(), Config.Permission),
33
+ webfetch: Config.Permission.optional(),
34
+ doom_loop: Config.Permission.optional(),
35
+ external_directory: Config.Permission.optional(),
36
+ }),
37
+ model: z
38
+ .object({
39
+ modelID: z.string(),
40
+ providerID: z.string(),
41
+ })
42
+ .optional(),
43
+ prompt: z.string().optional(),
44
+ tools: z.record(z.string(), z.boolean()),
45
+ options: z.record(z.string(), z.any()),
46
+ maxSteps: z.number().int().positive().optional(),
47
+ })
48
+ .meta({
49
+ ref: "Agent",
50
+ })
51
+ export type Info = z.infer<typeof Info>
52
+
53
+ const state = Instance.state(async () => {
54
+ const cfg = await Config.get()
55
+ const defaultTools = cfg.tools ?? {}
56
+ const defaultPermission: Info["permission"] = {
57
+ edit: "allow",
58
+ bash: {
59
+ "*": "allow",
60
+ },
61
+ skill: {
62
+ "*": "allow",
63
+ },
64
+ webfetch: "allow",
65
+ doom_loop: "ask",
66
+ external_directory: "ask",
67
+ }
68
+ const agentPermission = mergeAgentPermissions(defaultPermission, cfg.permission ?? {})
69
+
70
+ const planPermission = mergeAgentPermissions(
71
+ {
72
+ edit: "deny",
73
+ bash: {
74
+ "cut*": "allow",
75
+ "diff*": "allow",
76
+ "du*": "allow",
77
+ "file *": "allow",
78
+ "find * -delete*": "ask",
79
+ "find * -exec*": "ask",
80
+ "find * -fprint*": "ask",
81
+ "find * -fls*": "ask",
82
+ "find * -fprintf*": "ask",
83
+ "find * -ok*": "ask",
84
+ "find *": "allow",
85
+ "git diff*": "allow",
86
+ "git log*": "allow",
87
+ "git show*": "allow",
88
+ "git status*": "allow",
89
+ "git branch": "allow",
90
+ "git branch -v": "allow",
91
+ "grep*": "allow",
92
+ "head*": "allow",
93
+ "less*": "allow",
94
+ "ls*": "allow",
95
+ "more*": "allow",
96
+ "pwd*": "allow",
97
+ "rg*": "allow",
98
+ "sort --output=*": "ask",
99
+ "sort -o *": "ask",
100
+ "sort*": "allow",
101
+ "stat*": "allow",
102
+ "tail*": "allow",
103
+ "tree -o *": "ask",
104
+ "tree*": "allow",
105
+ "uniq*": "allow",
106
+ "wc*": "allow",
107
+ "whereis*": "allow",
108
+ "which*": "allow",
109
+ "*": "ask",
110
+ },
111
+ webfetch: "allow",
112
+ },
113
+ cfg.permission ?? {},
114
+ )
115
+
116
+ const result: Record<string, Info> = {
117
+ act: {
118
+ name: "act",
119
+ tools: { ...defaultTools },
120
+ options: {},
121
+ permission: agentPermission,
122
+ mode: "primary",
123
+ native: true,
124
+ },
125
+ plan: {
126
+ name: "plan",
127
+ options: {},
128
+ permission: planPermission,
129
+ tools: {
130
+ ...defaultTools,
131
+ },
132
+ mode: "primary",
133
+ native: true,
134
+ },
135
+ compaction: {
136
+ name: "compaction",
137
+ mode: "primary",
138
+ native: true,
139
+ hidden: true,
140
+ prompt: PROMPT_COMPACTION,
141
+ tools: {
142
+ "*": false,
143
+ },
144
+ options: {},
145
+ permission: agentPermission,
146
+ },
147
+ title: {
148
+ name: "title",
149
+ mode: "primary",
150
+ options: {},
151
+ native: true,
152
+ hidden: true,
153
+ permission: agentPermission,
154
+ prompt: PROMPT_TITLE,
155
+ tools: {},
156
+ },
157
+ summary: {
158
+ name: "summary",
159
+ mode: "primary",
160
+ options: {},
161
+ native: true,
162
+ hidden: true,
163
+ permission: agentPermission,
164
+ prompt: PROMPT_SUMMARY,
165
+ tools: {},
166
+ },
167
+ }
168
+ for (const [key, value] of Object.entries(cfg.agent ?? {})) {
169
+ if (value.disable) {
170
+ delete result[key]
171
+ continue
172
+ }
173
+ let item = result[key]
174
+ if (!item)
175
+ item = result[key] = {
176
+ name: key,
177
+ mode: "all",
178
+ permission: agentPermission,
179
+ options: {},
180
+ tools: {},
181
+ native: false,
182
+ }
183
+ const {
184
+ name,
185
+ model,
186
+ prompt,
187
+ tools,
188
+ description,
189
+ temperature,
190
+ top_p,
191
+ mode,
192
+ permission,
193
+ color,
194
+ maxSteps,
195
+ ...extra
196
+ } = value
197
+ item.options = {
198
+ ...item.options,
199
+ ...extra,
200
+ }
201
+ if (model) item.model = Provider.parseModel(model)
202
+ if (prompt) item.prompt = prompt
203
+ if (tools)
204
+ item.tools = {
205
+ ...item.tools,
206
+ ...tools,
207
+ }
208
+ item.tools = {
209
+ ...defaultTools,
210
+ ...item.tools,
211
+ }
212
+ if (description) item.description = description
213
+ if (temperature != undefined) item.temperature = temperature
214
+ if (top_p != undefined) item.topP = top_p
215
+ if (mode) item.mode = mode
216
+ if (color) item.color = color
217
+ // just here for consistency & to prevent it from being added as an option
218
+ if (name) item.name = name
219
+ if (maxSteps != undefined) item.maxSteps = maxSteps
220
+
221
+ if (permission ?? cfg.permission) {
222
+ item.permission = mergeAgentPermissions(cfg.permission ?? {}, permission ?? {})
223
+ }
224
+ }
225
+
226
+ // Mark the default agent
227
+ const defaultName = cfg.default_agent ?? "act"
228
+ const defaultCandidate = result[defaultName]
229
+ if (defaultCandidate && defaultCandidate.mode !== "subagent") {
230
+ defaultCandidate.default = true
231
+ } else {
232
+ // Fall back to "act" if configured default is invalid
233
+ if (result["act"]) {
234
+ result["act"].default = true
235
+ }
236
+ }
237
+
238
+ const hasPrimaryAgents = Object.values(result).filter((a) => a.mode !== "subagent" && !a.hidden).length > 0
239
+ if (!hasPrimaryAgents) {
240
+ throw new Config.InvalidError({
241
+ path: "config",
242
+ message: "No primary agents are available. Please configure at least one agent with mode 'primary' or 'all'.",
243
+ })
244
+ }
245
+
246
+ return result
247
+ })
248
+
249
+ export async function get(agent: string) {
250
+ return state().then((x) => x[agent])
251
+ }
252
+
253
+ export async function list() {
254
+ return state().then((x) => Object.values(x))
255
+ }
256
+
257
+ export async function defaultAgent(): Promise<string> {
258
+ const agents = await state()
259
+ const defaultCandidate = Object.values(agents).find((a) => a.default)
260
+ return defaultCandidate?.name ?? "act"
261
+ }
262
+
263
+ export async function generate(input: { description: string; model?: { providerID: string; modelID: string } }) {
264
+ const cfg = await Config.get()
265
+ const defaultModel = input.model ?? (await Provider.defaultModel())
266
+ const model = await Provider.getModel(defaultModel.providerID, defaultModel.modelID)
267
+ const language = await Provider.getLanguage(model)
268
+ const system = SystemPrompt.header(defaultModel.providerID)
269
+ system.push(PROMPT_GENERATE)
270
+ const existing = await list()
271
+ const result = await generateObject({
272
+ experimental_telemetry: {
273
+ isEnabled: cfg.experimental?.openTelemetry,
274
+ metadata: {
275
+ userId: cfg.username ?? "unknown",
276
+ },
277
+ },
278
+ temperature: 0.3,
279
+ messages: [
280
+ ...system.map(
281
+ (item): ModelMessage => ({
282
+ role: "system",
283
+ content: item,
284
+ }),
285
+ ),
286
+ {
287
+ role: "user",
288
+ content: `Create an agent configuration based on this request: \"${input.description}\".\n\nIMPORTANT: The following identifiers already exist and must NOT be used: ${existing.map((i) => i.name).join(", ")}\n Return ONLY the JSON object, no other text, do not wrap in backticks`,
289
+ },
290
+ ],
291
+ model: language,
292
+ schema: z.object({
293
+ identifier: z.string(),
294
+ whenToUse: z.string(),
295
+ systemPrompt: z.string(),
296
+ }),
297
+ })
298
+ return result.object
299
+ }
300
+ }
301
+
302
+ function mergeAgentPermissions(basePermission: any, overridePermission: any): Agent.Info["permission"] {
303
+ if (typeof basePermission.bash === "string") {
304
+ basePermission.bash = {
305
+ "*": basePermission.bash,
306
+ }
307
+ }
308
+ if (typeof overridePermission.bash === "string") {
309
+ overridePermission.bash = {
310
+ "*": overridePermission.bash,
311
+ }
312
+ }
313
+
314
+ if (typeof basePermission.skill === "string") {
315
+ basePermission.skill = {
316
+ "*": basePermission.skill,
317
+ }
318
+ }
319
+ if (typeof overridePermission.skill === "string") {
320
+ overridePermission.skill = {
321
+ "*": overridePermission.skill,
322
+ }
323
+ }
324
+ const merged = mergeDeep(basePermission ?? {}, overridePermission ?? {}) as any
325
+ let mergedBash
326
+ if (merged.bash) {
327
+ if (typeof merged.bash === "string") {
328
+ mergedBash = {
329
+ "*": merged.bash,
330
+ }
331
+ } else if (typeof merged.bash === "object") {
332
+ mergedBash = mergeDeep(
333
+ {
334
+ "*": "allow",
335
+ },
336
+ merged.bash,
337
+ )
338
+ }
339
+ }
340
+
341
+ let mergedSkill
342
+ if (merged.skill) {
343
+ if (typeof merged.skill === "string") {
344
+ mergedSkill = {
345
+ "*": merged.skill,
346
+ }
347
+ } else if (typeof merged.skill === "object") {
348
+ mergedSkill = mergeDeep(
349
+ {
350
+ "*": "allow",
351
+ },
352
+ merged.skill,
353
+ )
354
+ }
355
+ }
356
+
357
+ const result: Agent.Info["permission"] = {
358
+ edit: merged.edit ?? "allow",
359
+ webfetch: merged.webfetch ?? "allow",
360
+ bash: mergedBash ?? { "*": "allow" },
361
+ skill: mergedSkill ?? { "*": "allow" },
362
+ doom_loop: merged.doom_loop,
363
+ external_directory: merged.external_directory,
364
+ }
365
+
366
+ return result
367
+ }
@@ -0,0 +1,75 @@
1
+ You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.
2
+
3
+ **Important Context**: You may have access to project-specific instructions from RIRD.md files and other context that may include standards, project structure, and custom requirements. Consider this context when creating agents to ensure they align with the project's established patterns and practices.
4
+
5
+ When a user describes what they want an agent to do, you will:
6
+
7
+ 1. **Extract Core Intent**: Identify the fundamental purpose, key responsibilities, and success criteria for the agent. Look for both explicit requirements and implicit needs. Consider any project-specific context from RIRD.md files. For agents that are meant to review, you should assume that the user is asking to review recent work and not the whole codebase, unless the user has explicitly instructed you otherwise.
8
+
9
+ 2. **Design Expert Persona**: Create a compelling expert identity that embodies deep domain knowledge relevant to the task. The persona should inspire confidence and guide the agent's decision-making approach.
10
+
11
+ 3. **Architect Comprehensive Instructions**: Develop a system prompt that:
12
+
13
+ - Establishes clear behavioral boundaries and operational parameters
14
+ - Provides specific methodologies and best practices for task execution
15
+ - Anticipates edge cases and provides guidance for handling them
16
+ - Incorporates any specific requirements or preferences mentioned by the user
17
+ - Defines output format expectations when relevant
18
+ - Aligns with project-specific standards and patterns from RIRD.md
19
+
20
+ 4. **Optimize for Performance**: Include:
21
+
22
+ - Decision-making frameworks appropriate to the domain
23
+ - Quality control mechanisms and self-verification steps
24
+ - Efficient workflow patterns
25
+ - Clear escalation or fallback strategies
26
+
27
+ 5. **Create Identifier**: Design a concise, descriptive identifier that:
28
+ - Uses lowercase letters, numbers, and hyphens only
29
+ - Is typically 2-4 words joined by hyphens
30
+ - Clearly indicates the agent's primary function
31
+ - Is memorable and easy to type
32
+ - Avoids generic terms like "helper" or "assistant"
33
+
34
+ 6 **Example agent descriptions**:
35
+
36
+ - in the 'whenToUse' field of the JSON object, you should include examples of when this agent should be used.
37
+ - examples should be of the form:
38
+ - <example>
39
+ Context: The user is creating a task-review agent that should be called after completing a significant task.
40
+ user: "Please automate the form submission on that website"
41
+ assistant: "Here is what I did: "
42
+ <function call omitted for brevity only for this example>
43
+ <commentary>
44
+ Since a significant task was completed, use the Task tool to launch the task-reviewer agent to review the work.
45
+ </commentary>
46
+ assistant: "Now let me use the task-reviewer agent to review the work"
47
+ </example>
48
+ - <example>
49
+ Context: User is creating an agent to respond to the word "hello" with a friendly joke.
50
+ user: "Hello"
51
+ assistant: "I'm going to use the Task tool to launch the greeting-responder agent to respond with a friendly joke"
52
+ <commentary>
53
+ Since the user is greeting, use the greeting-responder agent to respond with a friendly joke.
54
+ </commentary>
55
+ </example>
56
+ - If the user mentioned or implied that the agent should be used proactively, you should include examples of this.
57
+ - NOTE: Ensure that in the examples, you are making the assistant use the Agent tool and not simply respond directly to the task.
58
+
59
+ Your output must be a valid JSON object with exactly these fields:
60
+ {
61
+ "identifier": "A unique, descriptive identifier using lowercase letters, numbers, and hyphens (e.g., 'task-reviewer', 'data-extractor', 'form-filler')",
62
+ "whenToUse": "A precise, actionable description starting with 'Use this agent when...' that clearly defines the triggering conditions and use cases. Ensure you include examples as described above.",
63
+ "systemPrompt": "The complete system prompt that will govern the agent's behavior, written in second person ('You are...', 'You will...') and structured for maximum clarity and effectiveness"
64
+ }
65
+
66
+ Key principles for your system prompts:
67
+
68
+ - Be specific rather than generic - avoid vague instructions
69
+ - Include concrete examples when they would clarify behavior
70
+ - Balance comprehensiveness with clarity - every instruction should add value
71
+ - Ensure the agent has enough context to handle variations of the core task
72
+ - Make the agent proactive in seeking clarification when needed
73
+ - Build in quality assurance and self-correction mechanisms
74
+
75
+ Remember: The agents you create should be autonomous experts capable of handling their designated tasks with minimal additional guidance. Your system prompts are their complete operational manual.
@@ -0,0 +1,12 @@
1
+ You are a helpful AI assistant tasked with summarizing conversations.
2
+
3
+ When asked to summarize, provide a detailed but concise summary of the conversation.
4
+ Focus on information that would be helpful for continuing the conversation, including:
5
+ - What was done
6
+ - What is currently being worked on
7
+ - Which files are being modified
8
+ - What needs to be done next
9
+ - Key user requests, constraints, or preferences that should persist
10
+ - Important technical decisions and why they were made
11
+
12
+ Your summary should be comprehensive enough to provide context but concise enough to be quickly understood.
@@ -0,0 +1,18 @@
1
+ You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
2
+
3
+ Your strengths:
4
+ - Rapidly finding files using glob patterns
5
+ - Searching code and text with powerful regex patterns
6
+ - Reading and analyzing file contents
7
+
8
+ Guidelines:
9
+ - Use Glob for broad file pattern matching
10
+ - Use Grep for searching file contents with regex
11
+ - Use Read when you know the specific file path you need to read
12
+ - Use Bash for file operations like copying, moving, or listing directory contents
13
+ - Adapt your search approach based on the thoroughness level specified by the caller
14
+ - Return file paths as absolute paths in your final response
15
+ - For clear communication, avoid using emojis
16
+ - Do not create any files, or run bash commands that modify the user's system state in any way
17
+
18
+ Complete the user's search request efficiently and report your findings clearly.
@@ -0,0 +1,10 @@
1
+ Summarize what was done in this conversation. Write like a task completion report.
2
+
3
+ Rules:
4
+ - 2-3 sentences max
5
+ - Describe the changes made, not the process
6
+ - Do not mention running tests, builds, or other validation steps
7
+ - Do not explain what the user asked for
8
+ - Write in first person (I added..., I fixed...)
9
+ - Never ask questions or add new questions
10
+ - Only exception: if the conversation ends with an unanswered question to the user, preserve that exact question
@@ -0,0 +1,36 @@
1
+ You are a title generator. You output ONLY a thread title. Nothing else.
2
+
3
+ <task>
4
+ Generate a brief title that would help the user find this conversation later.
5
+
6
+ Follow all rules in <rules>
7
+ Use the <examples> so you know what a good title looks like.
8
+ Your output must be:
9
+ - A single line
10
+ - ≤50 characters
11
+ - No explanations
12
+ </task>
13
+
14
+ <rules>
15
+ - Focus on the main topic or question the user needs to retrieve
16
+ - Use -ing verbs for actions (Debugging, Implementing, Analyzing)
17
+ - Keep exact: technical terms, numbers, filenames, HTTP codes
18
+ - Remove: the, this, my, a, an
19
+ - Never assume tech stack
20
+ - Never use tools
21
+ - NEVER respond to questions, just generate a title for the conversation
22
+ - The title should NEVER include "summarizing" or "generating" when generating a title
23
+ - DO NOT SAY YOU CANNOT GENERATE A TITLE OR COMPLAIN ABOUT THE INPUT
24
+ - Always output something meaningful, even if the input is minimal.
25
+ - If the user message is short or conversational (e.g. "hello", "lol", "whats up", "hey"):
26
+ → create a title that reflects the user's tone or intent (such as Greeting, Quick check-in, Light chat, Intro message, etc.)
27
+ </rules>
28
+
29
+ <examples>
30
+ "debug 500 errors in production" → Debugging production 500 errors
31
+ "refactor user service" → Refactoring user service
32
+ "why is app.js failing" → Analyzing app.js failure
33
+ "implement rate limiting" → Implementing rate limiting
34
+ "how do I connect postgres to my API" → Connecting Postgres to API
35
+ "best practices for React hooks" → React hooks best practices
36
+ </examples>