bincode-cli 1.0.1

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 (300) hide show
  1. package/AGENTS.md +27 -0
  2. package/README.md +15 -0
  3. package/bin/bincode +98 -0
  4. package/bunfig.toml +4 -0
  5. package/package.json +124 -0
  6. package/parsers-config.ts +239 -0
  7. package/script/build.ts +167 -0
  8. package/script/postinstall.mjs +206 -0
  9. package/script/publish.ts +99 -0
  10. package/script/schema.ts +47 -0
  11. package/src/acp/README.md +164 -0
  12. package/src/acp/agent.ts +1051 -0
  13. package/src/acp/session.ts +101 -0
  14. package/src/acp/types.ts +22 -0
  15. package/src/agent/agent.ts +398 -0
  16. package/src/agent/generate.txt +75 -0
  17. package/src/agent/prompt/compaction.txt +12 -0
  18. package/src/agent/prompt/explore.txt +18 -0
  19. package/src/agent/prompt/summary.txt +10 -0
  20. package/src/agent/prompt/title.txt +36 -0
  21. package/src/auth/bineric-login.ts +506 -0
  22. package/src/auth/index.ts +70 -0
  23. package/src/bun/index.ts +114 -0
  24. package/src/bus/bus-event.ts +43 -0
  25. package/src/bus/global.ts +10 -0
  26. package/src/bus/index.ts +105 -0
  27. package/src/cli/auth-check.ts +61 -0
  28. package/src/cli/bootstrap.ts +21 -0
  29. package/src/cli/cmd/acp.ts +88 -0
  30. package/src/cli/cmd/agent.ts +256 -0
  31. package/src/cli/cmd/auth.ts +436 -0
  32. package/src/cli/cmd/cmd.ts +7 -0
  33. package/src/cli/cmd/debug/config.ts +15 -0
  34. package/src/cli/cmd/debug/file.ts +91 -0
  35. package/src/cli/cmd/debug/index.ts +43 -0
  36. package/src/cli/cmd/debug/lsp.ts +48 -0
  37. package/src/cli/cmd/debug/ripgrep.ts +83 -0
  38. package/src/cli/cmd/debug/scrap.ts +15 -0
  39. package/src/cli/cmd/debug/skill.ts +15 -0
  40. package/src/cli/cmd/debug/snapshot.ts +48 -0
  41. package/src/cli/cmd/export.ts +88 -0
  42. package/src/cli/cmd/generate.ts +38 -0
  43. package/src/cli/cmd/github.ts +1399 -0
  44. package/src/cli/cmd/import.ts +98 -0
  45. package/src/cli/cmd/login.ts +112 -0
  46. package/src/cli/cmd/logout.ts +38 -0
  47. package/src/cli/cmd/mcp.ts +654 -0
  48. package/src/cli/cmd/models.ts +77 -0
  49. package/src/cli/cmd/pr.ts +112 -0
  50. package/src/cli/cmd/run.ts +368 -0
  51. package/src/cli/cmd/serve.ts +31 -0
  52. package/src/cli/cmd/session.ts +106 -0
  53. package/src/cli/cmd/stats.ts +298 -0
  54. package/src/cli/cmd/tui/app.tsx +669 -0
  55. package/src/cli/cmd/tui/attach.ts +30 -0
  56. package/src/cli/cmd/tui/component/border.tsx +21 -0
  57. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  58. package/src/cli/cmd/tui/component/dialog-command.tsx +123 -0
  59. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  60. package/src/cli/cmd/tui/component/dialog-model.tsx +223 -0
  61. package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
  62. package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
  63. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  67. package/src/cli/cmd/tui/component/logo.tsx +32 -0
  68. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +560 -0
  69. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  70. package/src/cli/cmd/tui/component/prompt/index.tsx +1052 -0
  71. package/src/cli/cmd/tui/context/args.tsx +14 -0
  72. package/src/cli/cmd/tui/context/directory.ts +13 -0
  73. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  74. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  75. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  76. package/src/cli/cmd/tui/context/kv.tsx +49 -0
  77. package/src/cli/cmd/tui/context/local.tsx +339 -0
  78. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  79. package/src/cli/cmd/tui/context/route.tsx +46 -0
  80. package/src/cli/cmd/tui/context/sdk.tsx +74 -0
  81. package/src/cli/cmd/tui/context/sync.tsx +372 -0
  82. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  83. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  84. package/src/cli/cmd/tui/context/theme/bincode.json +245 -0
  85. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  86. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  87. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  88. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  89. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  90. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  91. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  92. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  93. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  94. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  95. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  96. package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
  97. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  98. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  99. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  100. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  101. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  102. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  103. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  104. package/src/cli/cmd/tui/context/theme/orng.json +245 -0
  105. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  106. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  107. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  108. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  109. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  110. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  111. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  112. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  113. package/src/cli/cmd/tui/context/theme.tsx +1109 -0
  114. package/src/cli/cmd/tui/event.ts +40 -0
  115. package/src/cli/cmd/tui/routes/home.tsx +105 -0
  116. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  117. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  118. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  119. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  120. package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
  121. package/src/cli/cmd/tui/routes/session/header.tsx +141 -0
  122. package/src/cli/cmd/tui/routes/session/index.tsx +1888 -0
  123. package/src/cli/cmd/tui/routes/session/sidebar.tsx +321 -0
  124. package/src/cli/cmd/tui/spawn.ts +60 -0
  125. package/src/cli/cmd/tui/thread.ts +120 -0
  126. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  127. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  128. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  129. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  130. package/src/cli/cmd/tui/ui/dialog-select.tsx +330 -0
  131. package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
  132. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  133. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  134. package/src/cli/cmd/tui/util/clipboard.ts +127 -0
  135. package/src/cli/cmd/tui/util/editor.ts +32 -0
  136. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  137. package/src/cli/cmd/tui/worker.ts +63 -0
  138. package/src/cli/cmd/uninstall.ts +344 -0
  139. package/src/cli/cmd/upgrade.ts +67 -0
  140. package/src/cli/cmd/web.ts +84 -0
  141. package/src/cli/error.ts +55 -0
  142. package/src/cli/ui.ts +84 -0
  143. package/src/cli/upgrade.ts +25 -0
  144. package/src/command/index.ts +80 -0
  145. package/src/command/template/initialize.txt +10 -0
  146. package/src/command/template/review.txt +97 -0
  147. package/src/config/config.ts +995 -0
  148. package/src/config/markdown.ts +41 -0
  149. package/src/env/index.ts +26 -0
  150. package/src/file/ignore.ts +83 -0
  151. package/src/file/index.ts +328 -0
  152. package/src/file/ripgrep.ts +393 -0
  153. package/src/file/time.ts +64 -0
  154. package/src/file/watcher.ts +103 -0
  155. package/src/flag/flag.ts +46 -0
  156. package/src/format/formatter.ts +315 -0
  157. package/src/format/index.ts +137 -0
  158. package/src/global/index.ts +52 -0
  159. package/src/id/id.ts +73 -0
  160. package/src/ide/index.ts +76 -0
  161. package/src/index.ts +217 -0
  162. package/src/installation/index.ts +196 -0
  163. package/src/lsp/client.ts +229 -0
  164. package/src/lsp/index.ts +485 -0
  165. package/src/lsp/language.ts +116 -0
  166. package/src/lsp/server.ts +1895 -0
  167. package/src/mcp/auth.ts +135 -0
  168. package/src/mcp/index.ts +654 -0
  169. package/src/mcp/oauth-callback.ts +200 -0
  170. package/src/mcp/oauth-provider.ts +154 -0
  171. package/src/patch/index.ts +622 -0
  172. package/src/permission/index.ts +199 -0
  173. package/src/plugin/index.ts +101 -0
  174. package/src/project/bootstrap.ts +31 -0
  175. package/src/project/instance.ts +78 -0
  176. package/src/project/project.ts +221 -0
  177. package/src/project/state.ts +65 -0
  178. package/src/project/vcs.ts +76 -0
  179. package/src/provider/auth.ts +143 -0
  180. package/src/provider/models-macro.ts +11 -0
  181. package/src/provider/models.ts +106 -0
  182. package/src/provider/provider.ts +1071 -0
  183. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  184. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  185. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +101 -0
  186. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  187. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  188. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  189. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  190. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  191. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  192. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  193. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  194. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  195. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  196. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  197. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  198. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  199. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  200. package/src/provider/transform.ts +455 -0
  201. package/src/pty/index.ts +231 -0
  202. package/src/server/error.ts +36 -0
  203. package/src/server/project.ts +79 -0
  204. package/src/server/server.ts +2642 -0
  205. package/src/server/tui.ts +71 -0
  206. package/src/session/compaction.ts +223 -0
  207. package/src/session/index.ts +458 -0
  208. package/src/session/llm.ts +201 -0
  209. package/src/session/message-v2.ts +659 -0
  210. package/src/session/message.ts +189 -0
  211. package/src/session/processor.ts +409 -0
  212. package/src/session/prompt/anthropic-20250930.txt +166 -0
  213. package/src/session/prompt/anthropic.txt +104 -0
  214. package/src/session/prompt/anthropic_spoof.txt +1 -0
  215. package/src/session/prompt/beast.txt +147 -0
  216. package/src/session/prompt/build-switch.txt +5 -0
  217. package/src/session/prompt/codex.txt +318 -0
  218. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  219. package/src/session/prompt/gemini.txt +155 -0
  220. package/src/session/prompt/max-steps.txt +16 -0
  221. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  222. package/src/session/prompt/plan.txt +26 -0
  223. package/src/session/prompt/polaris.txt +106 -0
  224. package/src/session/prompt/qwen.txt +109 -0
  225. package/src/session/prompt.ts +1446 -0
  226. package/src/session/retry.ts +86 -0
  227. package/src/session/revert.ts +108 -0
  228. package/src/session/status.ts +76 -0
  229. package/src/session/summary.ts +194 -0
  230. package/src/session/system.ts +120 -0
  231. package/src/session/todo.ts +37 -0
  232. package/src/share/share-next.ts +194 -0
  233. package/src/share/share.ts +87 -0
  234. package/src/shell/shell.ts +67 -0
  235. package/src/skill/index.ts +1 -0
  236. package/src/skill/skill.ts +83 -0
  237. package/src/snapshot/index.ts +197 -0
  238. package/src/storage/storage.ts +226 -0
  239. package/src/tool/bash.ts +306 -0
  240. package/src/tool/bash.txt +158 -0
  241. package/src/tool/batch.ts +175 -0
  242. package/src/tool/batch.txt +24 -0
  243. package/src/tool/codesearch.ts +138 -0
  244. package/src/tool/codesearch.txt +12 -0
  245. package/src/tool/edit.ts +675 -0
  246. package/src/tool/edit.txt +10 -0
  247. package/src/tool/glob.ts +65 -0
  248. package/src/tool/glob.txt +6 -0
  249. package/src/tool/grep.ts +121 -0
  250. package/src/tool/grep.txt +8 -0
  251. package/src/tool/invalid.ts +17 -0
  252. package/src/tool/ls.ts +110 -0
  253. package/src/tool/ls.txt +1 -0
  254. package/src/tool/lsp-diagnostics.ts +26 -0
  255. package/src/tool/lsp-diagnostics.txt +1 -0
  256. package/src/tool/lsp-hover.ts +31 -0
  257. package/src/tool/lsp-hover.txt +1 -0
  258. package/src/tool/lsp.ts +87 -0
  259. package/src/tool/lsp.txt +19 -0
  260. package/src/tool/multiedit.ts +46 -0
  261. package/src/tool/multiedit.txt +41 -0
  262. package/src/tool/patch.ts +233 -0
  263. package/src/tool/patch.txt +1 -0
  264. package/src/tool/read.ts +219 -0
  265. package/src/tool/read.txt +12 -0
  266. package/src/tool/registry.ts +162 -0
  267. package/src/tool/skill.ts +100 -0
  268. package/src/tool/task.ts +136 -0
  269. package/src/tool/task.txt +60 -0
  270. package/src/tool/todo.ts +39 -0
  271. package/src/tool/todoread.txt +14 -0
  272. package/src/tool/todowrite.txt +167 -0
  273. package/src/tool/tool.ts +71 -0
  274. package/src/tool/webfetch.ts +187 -0
  275. package/src/tool/webfetch.txt +13 -0
  276. package/src/tool/websearch.ts +150 -0
  277. package/src/tool/websearch.txt +11 -0
  278. package/src/tool/write.ts +110 -0
  279. package/src/tool/write.txt +8 -0
  280. package/src/util/archive.ts +16 -0
  281. package/src/util/color.ts +19 -0
  282. package/src/util/context.ts +25 -0
  283. package/src/util/defer.ts +12 -0
  284. package/src/util/eventloop.ts +20 -0
  285. package/src/util/filesystem.ts +83 -0
  286. package/src/util/fn.ts +11 -0
  287. package/src/util/iife.ts +3 -0
  288. package/src/util/keybind.ts +102 -0
  289. package/src/util/lazy.ts +11 -0
  290. package/src/util/locale.ts +81 -0
  291. package/src/util/lock.ts +98 -0
  292. package/src/util/log.ts +180 -0
  293. package/src/util/queue.ts +32 -0
  294. package/src/util/rpc.ts +42 -0
  295. package/src/util/scrap.ts +10 -0
  296. package/src/util/signal.ts +12 -0
  297. package/src/util/timeout.ts +14 -0
  298. package/src/util/token.ts +7 -0
  299. package/src/util/wildcard.ts +54 -0
  300. 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 { BincodeClient } from "@bincode-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: BincodeClient
11
+
12
+ constructor(sdk: BincodeClient) {
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 { BincodeClient } from "@bincode-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: BincodeClient
18
+ defaultModel?: {
19
+ providerID: string
20
+ modelID: string
21
+ }
22
+ }
@@ -0,0 +1,398 @@
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_EXPLORE from "./prompt/explore.txt"
15
+ import PROMPT_SUMMARY from "./prompt/summary.txt"
16
+ import PROMPT_TITLE from "./prompt/title.txt"
17
+
18
+ export namespace Agent {
19
+ export const Info = z
20
+ .object({
21
+ name: z.string(),
22
+ description: z.string().optional(),
23
+ mode: z.enum(["subagent", "primary", "all"]),
24
+ native: z.boolean().optional(),
25
+ hidden: z.boolean().optional(),
26
+ default: z.boolean().optional(),
27
+ topP: z.number().optional(),
28
+ temperature: z.number().optional(),
29
+ color: z.string().optional(),
30
+ permission: z.object({
31
+ edit: Config.Permission,
32
+ bash: z.record(z.string(), Config.Permission),
33
+ skill: z.record(z.string(), Config.Permission),
34
+ webfetch: Config.Permission.optional(),
35
+ doom_loop: Config.Permission.optional(),
36
+ external_directory: Config.Permission.optional(),
37
+ }),
38
+ model: z
39
+ .object({
40
+ modelID: z.string(),
41
+ providerID: z.string(),
42
+ })
43
+ .optional(),
44
+ prompt: z.string().optional(),
45
+ tools: z.record(z.string(), z.boolean()),
46
+ options: z.record(z.string(), z.any()),
47
+ maxSteps: z.number().int().positive().optional(),
48
+ })
49
+ .meta({
50
+ ref: "Agent",
51
+ })
52
+ export type Info = z.infer<typeof Info>
53
+
54
+ const state = Instance.state(async () => {
55
+ const cfg = await Config.get()
56
+ const defaultTools = cfg.tools ?? {}
57
+ const defaultPermission: Info["permission"] = {
58
+ edit: "allow",
59
+ bash: {
60
+ "*": "allow",
61
+ },
62
+ skill: {
63
+ "*": "allow",
64
+ },
65
+ webfetch: "allow",
66
+ doom_loop: "ask",
67
+ external_directory: "ask",
68
+ }
69
+ const agentPermission = mergeAgentPermissions(defaultPermission, cfg.permission ?? {})
70
+
71
+ const planPermission = mergeAgentPermissions(
72
+ {
73
+ edit: "deny",
74
+ bash: {
75
+ "cut*": "allow",
76
+ "diff*": "allow",
77
+ "du*": "allow",
78
+ "file *": "allow",
79
+ "find * -delete*": "ask",
80
+ "find * -exec*": "ask",
81
+ "find * -fprint*": "ask",
82
+ "find * -fls*": "ask",
83
+ "find * -fprintf*": "ask",
84
+ "find * -ok*": "ask",
85
+ "find *": "allow",
86
+ "git diff*": "allow",
87
+ "git log*": "allow",
88
+ "git show*": "allow",
89
+ "git status*": "allow",
90
+ "git branch": "allow",
91
+ "git branch -v": "allow",
92
+ "grep*": "allow",
93
+ "head*": "allow",
94
+ "less*": "allow",
95
+ "ls*": "allow",
96
+ "more*": "allow",
97
+ "pwd*": "allow",
98
+ "rg*": "allow",
99
+ "sort --output=*": "ask",
100
+ "sort -o *": "ask",
101
+ "sort*": "allow",
102
+ "stat*": "allow",
103
+ "tail*": "allow",
104
+ "tree -o *": "ask",
105
+ "tree*": "allow",
106
+ "uniq*": "allow",
107
+ "wc*": "allow",
108
+ "whereis*": "allow",
109
+ "which*": "allow",
110
+ "*": "ask",
111
+ },
112
+ webfetch: "allow",
113
+ },
114
+ cfg.permission ?? {},
115
+ )
116
+
117
+ const result: Record<string, Info> = {
118
+ build: {
119
+ name: "build",
120
+ tools: { ...defaultTools },
121
+ options: {},
122
+ permission: agentPermission,
123
+ mode: "primary",
124
+ native: true,
125
+ },
126
+ plan: {
127
+ name: "plan",
128
+ options: {},
129
+ permission: planPermission,
130
+ tools: {
131
+ ...defaultTools,
132
+ },
133
+ mode: "primary",
134
+ native: true,
135
+ },
136
+ general: {
137
+ name: "general",
138
+ description: `General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel.`,
139
+ tools: {
140
+ todoread: false,
141
+ todowrite: false,
142
+ ...defaultTools,
143
+ },
144
+ options: {},
145
+ permission: agentPermission,
146
+ mode: "subagent",
147
+ native: true,
148
+ hidden: true,
149
+ },
150
+ explore: {
151
+ name: "explore",
152
+ tools: {
153
+ todoread: false,
154
+ todowrite: false,
155
+ edit: false,
156
+ write: false,
157
+ ...defaultTools,
158
+ },
159
+ description: `Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.`,
160
+ prompt: PROMPT_EXPLORE,
161
+ options: {},
162
+ permission: agentPermission,
163
+ mode: "subagent",
164
+ native: true,
165
+ },
166
+ compaction: {
167
+ name: "compaction",
168
+ mode: "primary",
169
+ native: true,
170
+ hidden: true,
171
+ prompt: PROMPT_COMPACTION,
172
+ tools: {
173
+ "*": false,
174
+ },
175
+ options: {},
176
+ permission: agentPermission,
177
+ },
178
+ title: {
179
+ name: "title",
180
+ mode: "primary",
181
+ options: {},
182
+ native: true,
183
+ hidden: true,
184
+ permission: agentPermission,
185
+ prompt: PROMPT_TITLE,
186
+ tools: {},
187
+ },
188
+ summary: {
189
+ name: "summary",
190
+ mode: "primary",
191
+ options: {},
192
+ native: true,
193
+ hidden: true,
194
+ permission: agentPermission,
195
+ prompt: PROMPT_SUMMARY,
196
+ tools: {},
197
+ },
198
+ }
199
+ for (const [key, value] of Object.entries(cfg.agent ?? {})) {
200
+ if (value.disable) {
201
+ delete result[key]
202
+ continue
203
+ }
204
+ let item = result[key]
205
+ if (!item)
206
+ item = result[key] = {
207
+ name: key,
208
+ mode: "all",
209
+ permission: agentPermission,
210
+ options: {},
211
+ tools: {},
212
+ native: false,
213
+ }
214
+ const {
215
+ name,
216
+ model,
217
+ prompt,
218
+ tools,
219
+ description,
220
+ temperature,
221
+ top_p,
222
+ mode,
223
+ permission,
224
+ color,
225
+ maxSteps,
226
+ ...extra
227
+ } = value
228
+ item.options = {
229
+ ...item.options,
230
+ ...extra,
231
+ }
232
+ if (model) item.model = Provider.parseModel(model)
233
+ if (prompt) item.prompt = prompt
234
+ if (tools)
235
+ item.tools = {
236
+ ...item.tools,
237
+ ...tools,
238
+ }
239
+ item.tools = {
240
+ ...defaultTools,
241
+ ...item.tools,
242
+ }
243
+ if (description) item.description = description
244
+ if (temperature != undefined) item.temperature = temperature
245
+ if (top_p != undefined) item.topP = top_p
246
+ if (mode) item.mode = mode
247
+ if (color) item.color = color
248
+ // just here for consistency & to prevent it from being added as an option
249
+ if (name) item.name = name
250
+ if (maxSteps != undefined) item.maxSteps = maxSteps
251
+
252
+ if (permission ?? cfg.permission) {
253
+ item.permission = mergeAgentPermissions(cfg.permission ?? {}, permission ?? {})
254
+ }
255
+ }
256
+
257
+ // Mark the default agent
258
+ const defaultName = cfg.default_agent ?? "build"
259
+ const defaultCandidate = result[defaultName]
260
+ if (defaultCandidate && defaultCandidate.mode !== "subagent") {
261
+ defaultCandidate.default = true
262
+ } else {
263
+ // Fall back to "build" if configured default is invalid
264
+ if (result["build"]) {
265
+ result["build"].default = true
266
+ }
267
+ }
268
+
269
+ const hasPrimaryAgents = Object.values(result).filter((a) => a.mode !== "subagent" && !a.hidden).length > 0
270
+ if (!hasPrimaryAgents) {
271
+ throw new Config.InvalidError({
272
+ path: "config",
273
+ message: "No primary agents are available. Please configure at least one agent with mode 'primary' or 'all'.",
274
+ })
275
+ }
276
+
277
+ return result
278
+ })
279
+
280
+ export async function get(agent: string) {
281
+ return state().then((x) => x[agent])
282
+ }
283
+
284
+ export async function list() {
285
+ return state().then((x) => Object.values(x))
286
+ }
287
+
288
+ export async function defaultAgent(): Promise<string> {
289
+ const agents = await state()
290
+ const defaultCandidate = Object.values(agents).find((a) => a.default)
291
+ return defaultCandidate?.name ?? "build"
292
+ }
293
+
294
+ export async function generate(input: { description: string; model?: { providerID: string; modelID: string } }) {
295
+ const cfg = await Config.get()
296
+ const defaultModel = input.model ?? (await Provider.defaultModel())
297
+ const model = await Provider.getModel(defaultModel.providerID, defaultModel.modelID)
298
+ const language = await Provider.getLanguage(model)
299
+ const system = SystemPrompt.header(defaultModel.providerID)
300
+ system.push(PROMPT_GENERATE)
301
+ const existing = await list()
302
+ const result = await generateObject({
303
+ experimental_telemetry: {
304
+ isEnabled: cfg.experimental?.openTelemetry,
305
+ metadata: {
306
+ userId: cfg.username ?? "unknown",
307
+ },
308
+ },
309
+ temperature: 0.3,
310
+ messages: [
311
+ ...system.map(
312
+ (item): ModelMessage => ({
313
+ role: "system",
314
+ content: item,
315
+ }),
316
+ ),
317
+ {
318
+ role: "user",
319
+ 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`,
320
+ },
321
+ ],
322
+ model: language,
323
+ schema: z.object({
324
+ identifier: z.string(),
325
+ whenToUse: z.string(),
326
+ systemPrompt: z.string(),
327
+ }),
328
+ })
329
+ return result.object
330
+ }
331
+ }
332
+
333
+ function mergeAgentPermissions(basePermission: any, overridePermission: any): Agent.Info["permission"] {
334
+ if (typeof basePermission.bash === "string") {
335
+ basePermission.bash = {
336
+ "*": basePermission.bash,
337
+ }
338
+ }
339
+ if (typeof overridePermission.bash === "string") {
340
+ overridePermission.bash = {
341
+ "*": overridePermission.bash,
342
+ }
343
+ }
344
+
345
+ if (typeof basePermission.skill === "string") {
346
+ basePermission.skill = {
347
+ "*": basePermission.skill,
348
+ }
349
+ }
350
+ if (typeof overridePermission.skill === "string") {
351
+ overridePermission.skill = {
352
+ "*": overridePermission.skill,
353
+ }
354
+ }
355
+ const merged = mergeDeep(basePermission ?? {}, overridePermission ?? {}) as any
356
+ let mergedBash
357
+ if (merged.bash) {
358
+ if (typeof merged.bash === "string") {
359
+ mergedBash = {
360
+ "*": merged.bash,
361
+ }
362
+ } else if (typeof merged.bash === "object") {
363
+ mergedBash = mergeDeep(
364
+ {
365
+ "*": "allow",
366
+ },
367
+ merged.bash,
368
+ )
369
+ }
370
+ }
371
+
372
+ let mergedSkill
373
+ if (merged.skill) {
374
+ if (typeof merged.skill === "string") {
375
+ mergedSkill = {
376
+ "*": merged.skill,
377
+ }
378
+ } else if (typeof merged.skill === "object") {
379
+ mergedSkill = mergeDeep(
380
+ {
381
+ "*": "allow",
382
+ },
383
+ merged.skill,
384
+ )
385
+ }
386
+ }
387
+
388
+ const result: Agent.Info["permission"] = {
389
+ edit: merged.edit ?? "allow",
390
+ webfetch: merged.webfetch ?? "allow",
391
+ bash: mergedBash ?? { "*": "allow" },
392
+ skill: mergedSkill ?? { "*": "allow" },
393
+ doom_loop: merged.doom_loop,
394
+ external_directory: merged.external_directory,
395
+ }
396
+
397
+ return result
398
+ }
@@ -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 CLAUDE.md files and other context that may include coding 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 CLAUDE.md files. For agents that are meant to review code, you should assume that the user is asking to review recently written code 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 coding standards and patterns from CLAUDE.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 code-review agent that should be called after a logical chunk of code is written.
40
+ user: "Please write a function that checks if a number is prime"
41
+ assistant: "Here is the relevant function: "
42
+ <function call omitted for brevity only for this example>
43
+ <commentary>
44
+ Since the user is greeting, use the Task tool to launch the greeting-responder agent to respond with a friendly joke.
45
+ </commentary>
46
+ assistant: "Now let me use the code-reviewer agent to review the code"
47
+ </example>
48
+ - <example>
49
+ Context: User is creating an agent to respond to the word "hello" with a friendly jok.
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., 'code-reviewer', 'api-docs-writer', 'test-generator')",
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 pull request description.
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>