chad-code 1.3.1 → 1.3.2

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 (337) hide show
  1. package/README.md +55 -6
  2. package/package.json +36 -98
  3. package/AGENTS.md +0 -27
  4. package/Dockerfile +0 -18
  5. package/README.npm.md +0 -64
  6. package/bunfig.toml +0 -7
  7. package/eslint.config.js +0 -29
  8. package/parsers-config.ts +0 -253
  9. package/script/build.ts +0 -167
  10. package/script/publish-registries.ts +0 -187
  11. package/script/publish.ts +0 -93
  12. package/script/schema.ts +0 -47
  13. package/src/acp/README.md +0 -164
  14. package/src/acp/agent.ts +0 -1086
  15. package/src/acp/session.ts +0 -101
  16. package/src/acp/types.ts +0 -22
  17. package/src/agent/agent.ts +0 -253
  18. package/src/agent/generate.txt +0 -75
  19. package/src/agent/prompt/compaction.txt +0 -12
  20. package/src/agent/prompt/explore.txt +0 -18
  21. package/src/agent/prompt/summary.txt +0 -11
  22. package/src/agent/prompt/title.txt +0 -36
  23. package/src/auth/index.ts +0 -70
  24. package/src/bun/index.ts +0 -130
  25. package/src/bus/bus-event.ts +0 -43
  26. package/src/bus/global.ts +0 -10
  27. package/src/bus/index.ts +0 -105
  28. package/src/cli/bootstrap.ts +0 -17
  29. package/src/cli/cmd/acp.ts +0 -69
  30. package/src/cli/cmd/agent.ts +0 -257
  31. package/src/cli/cmd/auth.ts +0 -132
  32. package/src/cli/cmd/cmd.ts +0 -7
  33. package/src/cli/cmd/debug/agent.ts +0 -28
  34. package/src/cli/cmd/debug/config.ts +0 -15
  35. package/src/cli/cmd/debug/file.ts +0 -91
  36. package/src/cli/cmd/debug/index.ts +0 -45
  37. package/src/cli/cmd/debug/lsp.ts +0 -48
  38. package/src/cli/cmd/debug/ripgrep.ts +0 -83
  39. package/src/cli/cmd/debug/scrap.ts +0 -15
  40. package/src/cli/cmd/debug/skill.ts +0 -15
  41. package/src/cli/cmd/debug/snapshot.ts +0 -48
  42. package/src/cli/cmd/export.ts +0 -88
  43. package/src/cli/cmd/generate.ts +0 -38
  44. package/src/cli/cmd/github.ts +0 -32
  45. package/src/cli/cmd/import.ts +0 -98
  46. package/src/cli/cmd/mcp.ts +0 -670
  47. package/src/cli/cmd/models.ts +0 -42
  48. package/src/cli/cmd/pr.ts +0 -112
  49. package/src/cli/cmd/run.ts +0 -374
  50. package/src/cli/cmd/serve.ts +0 -16
  51. package/src/cli/cmd/session.ts +0 -135
  52. package/src/cli/cmd/stats.ts +0 -402
  53. package/src/cli/cmd/tui/app.tsx +0 -705
  54. package/src/cli/cmd/tui/attach.ts +0 -32
  55. package/src/cli/cmd/tui/component/border.tsx +0 -21
  56. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  57. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -124
  58. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  59. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -232
  60. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -228
  61. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -115
  62. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  63. package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -86
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -162
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  67. package/src/cli/cmd/tui/component/did-you-know.tsx +0 -85
  68. package/src/cli/cmd/tui/component/logo.tsx +0 -43
  69. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -654
  70. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
  71. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1078
  72. package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
  73. package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
  74. package/src/cli/cmd/tui/component/tips.ts +0 -92
  75. package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
  76. package/src/cli/cmd/tui/context/args.tsx +0 -14
  77. package/src/cli/cmd/tui/context/directory.ts +0 -13
  78. package/src/cli/cmd/tui/context/exit.tsx +0 -23
  79. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  80. package/src/cli/cmd/tui/context/keybind.tsx +0 -101
  81. package/src/cli/cmd/tui/context/kv.tsx +0 -49
  82. package/src/cli/cmd/tui/context/local.tsx +0 -392
  83. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  84. package/src/cli/cmd/tui/context/route.tsx +0 -46
  85. package/src/cli/cmd/tui/context/sdk.tsx +0 -75
  86. package/src/cli/cmd/tui/context/sync.tsx +0 -384
  87. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  88. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  89. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
  90. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  91. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  92. package/src/cli/cmd/tui/context/theme/chad.json +0 -245
  93. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  94. package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
  95. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  96. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  97. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  98. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  99. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
  100. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  101. package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -227
  102. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  103. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  104. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  105. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  106. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  107. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  108. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  109. package/src/cli/cmd/tui/context/theme/orng.json +0 -245
  110. package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
  111. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  112. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  113. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  114. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  115. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  116. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  117. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  118. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  119. package/src/cli/cmd/tui/context/theme.tsx +0 -1137
  120. package/src/cli/cmd/tui/event.ts +0 -46
  121. package/src/cli/cmd/tui/routes/home.tsx +0 -138
  122. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
  123. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
  124. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
  125. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
  126. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -88
  127. package/src/cli/cmd/tui/routes/session/header.tsx +0 -125
  128. package/src/cli/cmd/tui/routes/session/index.tsx +0 -1814
  129. package/src/cli/cmd/tui/routes/session/permission.tsx +0 -416
  130. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -318
  131. package/src/cli/cmd/tui/spawn.ts +0 -48
  132. package/src/cli/cmd/tui/thread.ts +0 -111
  133. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
  134. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
  135. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
  136. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
  137. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
  138. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -345
  139. package/src/cli/cmd/tui/ui/dialog.tsx +0 -171
  140. package/src/cli/cmd/tui/ui/link.tsx +0 -28
  141. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  142. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  143. package/src/cli/cmd/tui/util/clipboard.ts +0 -127
  144. package/src/cli/cmd/tui/util/editor.ts +0 -32
  145. package/src/cli/cmd/tui/util/signal.ts +0 -7
  146. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  147. package/src/cli/cmd/tui/util/transcript.ts +0 -98
  148. package/src/cli/cmd/tui/worker.ts +0 -68
  149. package/src/cli/cmd/uninstall.ts +0 -344
  150. package/src/cli/cmd/upgrade.ts +0 -67
  151. package/src/cli/cmd/web.ts +0 -73
  152. package/src/cli/error.ts +0 -56
  153. package/src/cli/network.ts +0 -53
  154. package/src/cli/ui.ts +0 -87
  155. package/src/cli/upgrade.ts +0 -25
  156. package/src/command/index.ts +0 -131
  157. package/src/command/template/initialize.txt +0 -10
  158. package/src/command/template/review.txt +0 -97
  159. package/src/config/config.ts +0 -1124
  160. package/src/config/markdown.ts +0 -41
  161. package/src/env/index.ts +0 -26
  162. package/src/file/ignore.ts +0 -83
  163. package/src/file/index.ts +0 -411
  164. package/src/file/ripgrep.ts +0 -402
  165. package/src/file/time.ts +0 -64
  166. package/src/file/watcher.ts +0 -117
  167. package/src/flag/flag.ts +0 -52
  168. package/src/format/formatter.ts +0 -359
  169. package/src/format/index.ts +0 -137
  170. package/src/global/index.ts +0 -55
  171. package/src/id/id.ts +0 -73
  172. package/src/ide/index.ts +0 -77
  173. package/src/index.ts +0 -159
  174. package/src/installation/index.ts +0 -198
  175. package/src/lsp/client.ts +0 -252
  176. package/src/lsp/index.ts +0 -485
  177. package/src/lsp/language.ts +0 -119
  178. package/src/lsp/server.ts +0 -2023
  179. package/src/mcp/auth.ts +0 -135
  180. package/src/mcp/index.ts +0 -874
  181. package/src/mcp/oauth-callback.ts +0 -200
  182. package/src/mcp/oauth-provider.ts +0 -154
  183. package/src/patch/index.ts +0 -622
  184. package/src/permission/arity.ts +0 -163
  185. package/src/permission/index.ts +0 -210
  186. package/src/permission/next.ts +0 -268
  187. package/src/plugin/index.ts +0 -106
  188. package/src/project/bootstrap.ts +0 -31
  189. package/src/project/instance.ts +0 -78
  190. package/src/project/project.ts +0 -263
  191. package/src/project/state.ts +0 -65
  192. package/src/project/vcs.ts +0 -76
  193. package/src/provider/auth.ts +0 -143
  194. package/src/provider/models-macro.ts +0 -4
  195. package/src/provider/models.ts +0 -77
  196. package/src/provider/provider.ts +0 -516
  197. package/src/provider/transform.ts +0 -114
  198. package/src/pty/index.ts +0 -212
  199. package/src/server/error.ts +0 -36
  200. package/src/server/mdns.ts +0 -57
  201. package/src/server/project.ts +0 -79
  202. package/src/server/server.ts +0 -2866
  203. package/src/server/tui.ts +0 -71
  204. package/src/session/compaction.ts +0 -225
  205. package/src/session/index.ts +0 -469
  206. package/src/session/llm.ts +0 -213
  207. package/src/session/message-v2.ts +0 -742
  208. package/src/session/message.ts +0 -189
  209. package/src/session/processor.ts +0 -402
  210. package/src/session/prompt/anthropic-20250930.txt +0 -166
  211. package/src/session/prompt/anthropic.txt +0 -105
  212. package/src/session/prompt/anthropic_spoof.txt +0 -1
  213. package/src/session/prompt/beast.txt +0 -147
  214. package/src/session/prompt/build-switch.txt +0 -5
  215. package/src/session/prompt/codex.txt +0 -318
  216. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  217. package/src/session/prompt/gemini.txt +0 -155
  218. package/src/session/prompt/max-steps.txt +0 -16
  219. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  220. package/src/session/prompt/plan.txt +0 -26
  221. package/src/session/prompt/qwen.txt +0 -109
  222. package/src/session/prompt.ts +0 -1621
  223. package/src/session/retry.ts +0 -90
  224. package/src/session/revert.ts +0 -108
  225. package/src/session/status.ts +0 -76
  226. package/src/session/summary.ts +0 -194
  227. package/src/session/system.ts +0 -108
  228. package/src/session/todo.ts +0 -37
  229. package/src/share/share-next.ts +0 -194
  230. package/src/share/share.ts +0 -23
  231. package/src/shell/shell.ts +0 -67
  232. package/src/skill/index.ts +0 -1
  233. package/src/skill/skill.ts +0 -124
  234. package/src/snapshot/index.ts +0 -197
  235. package/src/storage/storage.ts +0 -226
  236. package/src/tool/bash.ts +0 -262
  237. package/src/tool/bash.txt +0 -116
  238. package/src/tool/batch.ts +0 -175
  239. package/src/tool/batch.txt +0 -24
  240. package/src/tool/codesearch.ts +0 -132
  241. package/src/tool/codesearch.txt +0 -12
  242. package/src/tool/edit.ts +0 -655
  243. package/src/tool/edit.txt +0 -10
  244. package/src/tool/glob.ts +0 -75
  245. package/src/tool/glob.txt +0 -6
  246. package/src/tool/grep.ts +0 -132
  247. package/src/tool/grep.txt +0 -8
  248. package/src/tool/invalid.ts +0 -17
  249. package/src/tool/ls.ts +0 -119
  250. package/src/tool/ls.txt +0 -1
  251. package/src/tool/lsp.ts +0 -94
  252. package/src/tool/lsp.txt +0 -19
  253. package/src/tool/multiedit.ts +0 -46
  254. package/src/tool/multiedit.txt +0 -41
  255. package/src/tool/patch.ts +0 -210
  256. package/src/tool/patch.txt +0 -1
  257. package/src/tool/read.ts +0 -191
  258. package/src/tool/read.txt +0 -12
  259. package/src/tool/registry.ts +0 -137
  260. package/src/tool/skill.ts +0 -77
  261. package/src/tool/task.ts +0 -167
  262. package/src/tool/task.txt +0 -60
  263. package/src/tool/todo.ts +0 -53
  264. package/src/tool/todoread.txt +0 -14
  265. package/src/tool/todowrite.txt +0 -167
  266. package/src/tool/tool.ts +0 -73
  267. package/src/tool/webfetch.ts +0 -182
  268. package/src/tool/webfetch.txt +0 -13
  269. package/src/tool/websearch.ts +0 -144
  270. package/src/tool/websearch.txt +0 -11
  271. package/src/tool/write.ts +0 -84
  272. package/src/tool/write.txt +0 -8
  273. package/src/util/archive.ts +0 -16
  274. package/src/util/color.ts +0 -19
  275. package/src/util/context.ts +0 -25
  276. package/src/util/defer.ts +0 -12
  277. package/src/util/eventloop.ts +0 -20
  278. package/src/util/filesystem.ts +0 -83
  279. package/src/util/fn.ts +0 -11
  280. package/src/util/iife.ts +0 -3
  281. package/src/util/keybind.ts +0 -102
  282. package/src/util/lazy.ts +0 -18
  283. package/src/util/locale.ts +0 -81
  284. package/src/util/lock.ts +0 -98
  285. package/src/util/log.ts +0 -180
  286. package/src/util/queue.ts +0 -32
  287. package/src/util/rpc.ts +0 -42
  288. package/src/util/scrap.ts +0 -10
  289. package/src/util/signal.ts +0 -12
  290. package/src/util/timeout.ts +0 -14
  291. package/src/util/token.ts +0 -7
  292. package/src/util/wildcard.ts +0 -54
  293. package/src/worktree/index.ts +0 -217
  294. package/sst-env.d.ts +0 -9
  295. package/test/agent/agent.test.ts +0 -448
  296. package/test/bun.test.ts +0 -53
  297. package/test/cli/github-action.test.ts +0 -129
  298. package/test/cli/github-remote.test.ts +0 -80
  299. package/test/cli/tui/transcript.test.ts +0 -297
  300. package/test/config/agent-color.test.ts +0 -66
  301. package/test/config/config.test.ts +0 -870
  302. package/test/config/markdown.test.ts +0 -89
  303. package/test/file/ignore.test.ts +0 -10
  304. package/test/file/path-traversal.test.ts +0 -115
  305. package/test/fixture/fixture.ts +0 -45
  306. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  307. package/test/ide/ide.test.ts +0 -82
  308. package/test/keybind.test.ts +0 -421
  309. package/test/lsp/client.test.ts +0 -95
  310. package/test/mcp/headers.test.ts +0 -153
  311. package/test/patch/patch.test.ts +0 -348
  312. package/test/permission/arity.test.ts +0 -33
  313. package/test/permission/next.test.ts +0 -652
  314. package/test/preload.ts +0 -63
  315. package/test/project/project.test.ts +0 -120
  316. package/test/provider/amazon-bedrock.test.ts +0 -236
  317. package/test/provider/provider.test.ts +0 -2127
  318. package/test/provider/transform.test.ts +0 -980
  319. package/test/server/session-select.test.ts +0 -78
  320. package/test/session/compaction.test.ts +0 -251
  321. package/test/session/message-v2.test.ts +0 -570
  322. package/test/session/retry.test.ts +0 -131
  323. package/test/session/revert-compact.test.ts +0 -285
  324. package/test/session/session.test.ts +0 -71
  325. package/test/skill/skill.test.ts +0 -185
  326. package/test/snapshot/snapshot.test.ts +0 -939
  327. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  328. package/test/tool/bash.test.ts +0 -232
  329. package/test/tool/grep.test.ts +0 -109
  330. package/test/tool/patch.test.ts +0 -261
  331. package/test/tool/read.test.ts +0 -167
  332. package/test/util/iife.test.ts +0 -36
  333. package/test/util/lazy.test.ts +0 -50
  334. package/test/util/timeout.test.ts +0 -21
  335. package/test/util/wildcard.test.ts +0 -55
  336. package/tsconfig.json +0 -16
  337. /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
@@ -1,670 +0,0 @@
1
- import { cmd } from "./cmd"
2
- import { Client } from "@modelcontextprotocol/sdk/client/index.js"
3
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
4
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
5
- import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
6
- import * as prompts from "@clack/prompts"
7
- import { UI } from "../ui"
8
- import { MCP } from "../../mcp"
9
- import { McpAuth } from "../../mcp/auth"
10
- import { McpOAuthProvider } from "../../mcp/oauth-provider"
11
- import { Config } from "../../config/config"
12
- import { Instance } from "../../project/instance"
13
- import { Installation } from "../../installation"
14
- import path from "path"
15
- import { Global } from "../../global"
16
-
17
- function getAuthStatusIcon(status: MCP.AuthStatus): string {
18
- switch (status) {
19
- case "authenticated":
20
- return "✓"
21
- case "expired":
22
- return "⚠"
23
- case "not_authenticated":
24
- return "○"
25
- }
26
- }
27
-
28
- function getAuthStatusText(status: MCP.AuthStatus): string {
29
- switch (status) {
30
- case "authenticated":
31
- return "authenticated"
32
- case "expired":
33
- return "expired"
34
- case "not_authenticated":
35
- return "not authenticated"
36
- }
37
- }
38
-
39
- type McpEntry = NonNullable<Config.Info["mcp"]>[string]
40
-
41
- type McpConfigured = Config.Mcp
42
- function isMcpConfigured(config: McpEntry): config is McpConfigured {
43
- return typeof config === "object" && config !== null && "type" in config
44
- }
45
-
46
- type McpRemote = Extract<McpConfigured, { type: "remote" }>
47
- function isMcpRemote(config: McpEntry): config is McpRemote {
48
- return isMcpConfigured(config) && config.type === "remote"
49
- }
50
-
51
- export const McpCommand = cmd({
52
- command: "mcp",
53
- builder: (yargs) =>
54
- yargs
55
- .command(McpAddCommand)
56
- .command(McpListCommand)
57
- .command(McpAuthCommand)
58
- .command(McpLogoutCommand)
59
- .command(McpDebugCommand)
60
- .demandCommand(),
61
- async handler() {},
62
- })
63
-
64
- export const McpListCommand = cmd({
65
- command: "list",
66
- aliases: ["ls"],
67
- describe: "list MCP servers and their status",
68
- async handler() {
69
- await Instance.provide({
70
- directory: process.cwd(),
71
- async fn() {
72
- UI.empty()
73
- prompts.intro("MCP Servers")
74
-
75
- const config = await Config.get()
76
- const mcpServers = config.mcp ?? {}
77
- const statuses = await MCP.status()
78
-
79
- const servers = Object.entries(mcpServers).filter((entry): entry is [string, McpConfigured] =>
80
- isMcpConfigured(entry[1]),
81
- )
82
-
83
- if (servers.length === 0) {
84
- prompts.log.warn("No MCP servers configured")
85
- prompts.outro("Add servers with: opencode mcp add")
86
- return
87
- }
88
-
89
- for (const [name, serverConfig] of servers) {
90
- const status = statuses[name]
91
- const hasOAuth = isMcpRemote(serverConfig) && !!serverConfig.oauth
92
- const hasStoredTokens = await MCP.hasStoredTokens(name)
93
-
94
- let statusIcon: string
95
- let statusText: string
96
- let hint = ""
97
-
98
- if (!status) {
99
- statusIcon = "○"
100
- statusText = "not initialized"
101
- } else if (status.status === "connected") {
102
- statusIcon = "✓"
103
- statusText = "connected"
104
- if (hasOAuth && hasStoredTokens) {
105
- hint = " (OAuth)"
106
- }
107
- } else if (status.status === "disabled") {
108
- statusIcon = "○"
109
- statusText = "disabled"
110
- } else if (status.status === "needs_auth") {
111
- statusIcon = "⚠"
112
- statusText = "needs authentication"
113
- } else if (status.status === "needs_client_registration") {
114
- statusIcon = "✗"
115
- statusText = "needs client registration"
116
- hint = "\n " + status.error
117
- } else {
118
- statusIcon = "✗"
119
- statusText = "failed"
120
- hint = "\n " + status.error
121
- }
122
-
123
- const typeHint = serverConfig.type === "remote" ? serverConfig.url : serverConfig.command.join(" ")
124
- prompts.log.info(
125
- `${statusIcon} ${name} ${UI.Style.TEXT_DIM}${statusText}${hint}\n ${UI.Style.TEXT_DIM}${typeHint}`,
126
- )
127
- }
128
-
129
- prompts.outro(`${servers.length} server(s)`)
130
- },
131
- })
132
- },
133
- })
134
-
135
- export const McpAuthCommand = cmd({
136
- command: "auth [name]",
137
- describe: "authenticate with an OAuth-enabled MCP server",
138
- builder: (yargs) =>
139
- yargs
140
- .positional("name", {
141
- describe: "name of the MCP server",
142
- type: "string",
143
- })
144
- .command(McpAuthListCommand),
145
- async handler(args) {
146
- await Instance.provide({
147
- directory: process.cwd(),
148
- async fn() {
149
- UI.empty()
150
- prompts.intro("MCP OAuth Authentication")
151
-
152
- const config = await Config.get()
153
- const mcpServers = config.mcp ?? {}
154
-
155
- // Get OAuth-capable servers (remote servers with oauth not explicitly disabled)
156
- const oauthServers = Object.entries(mcpServers).filter(
157
- (entry): entry is [string, McpRemote] => isMcpRemote(entry[1]) && entry[1].oauth !== false,
158
- )
159
-
160
- if (oauthServers.length === 0) {
161
- prompts.log.warn("No OAuth-capable MCP servers configured")
162
- prompts.log.info("Remote MCP servers support OAuth by default. Add a remote server in chad-code.json:")
163
- prompts.log.info(`
164
- "mcp": {
165
- "my-server": {
166
- "type": "remote",
167
- "url": "https://example.com/mcp"
168
- }
169
- }`)
170
- prompts.outro("Done")
171
- return
172
- }
173
-
174
- let serverName = args.name
175
- if (!serverName) {
176
- // Build options with auth status
177
- const options = await Promise.all(
178
- oauthServers.map(async ([name, cfg]) => {
179
- const authStatus = await MCP.getAuthStatus(name)
180
- const icon = getAuthStatusIcon(authStatus)
181
- const statusText = getAuthStatusText(authStatus)
182
- const url = cfg.url
183
- return {
184
- label: `${icon} ${name} (${statusText})`,
185
- value: name,
186
- hint: url,
187
- }
188
- }),
189
- )
190
-
191
- const selected = await prompts.select({
192
- message: "Select MCP server to authenticate",
193
- options,
194
- })
195
- if (prompts.isCancel(selected)) throw new UI.CancelledError()
196
- serverName = selected
197
- }
198
-
199
- const serverConfig = mcpServers[serverName]
200
- if (!serverConfig) {
201
- prompts.log.error(`MCP server not found: ${serverName}`)
202
- prompts.outro("Done")
203
- return
204
- }
205
-
206
- if (!isMcpRemote(serverConfig) || serverConfig.oauth === false) {
207
- prompts.log.error(`MCP server ${serverName} is not an OAuth-capable remote server`)
208
- prompts.outro("Done")
209
- return
210
- }
211
-
212
- // Check if already authenticated
213
- const authStatus = await MCP.getAuthStatus(serverName)
214
- if (authStatus === "authenticated") {
215
- const confirm = await prompts.confirm({
216
- message: `${serverName} already has valid credentials. Re-authenticate?`,
217
- })
218
- if (prompts.isCancel(confirm) || !confirm) {
219
- prompts.outro("Cancelled")
220
- return
221
- }
222
- } else if (authStatus === "expired") {
223
- prompts.log.warn(`${serverName} has expired credentials. Re-authenticating...`)
224
- }
225
-
226
- const spinner = prompts.spinner()
227
- spinner.start("Starting OAuth flow...")
228
-
229
- try {
230
- const status = await MCP.authenticate(serverName)
231
-
232
- if (status.status === "connected") {
233
- spinner.stop("Authentication successful!")
234
- } else if (status.status === "needs_client_registration") {
235
- spinner.stop("Authentication failed", 1)
236
- prompts.log.error(status.error)
237
- prompts.log.info("Add clientId to your MCP server config:")
238
- prompts.log.info(`
239
- "mcp": {
240
- "${serverName}": {
241
- "type": "remote",
242
- "url": "${serverConfig.url}",
243
- "oauth": {
244
- "clientId": "your-client-id",
245
- "clientSecret": "your-client-secret"
246
- }
247
- }
248
- }`)
249
- } else if (status.status === "failed") {
250
- spinner.stop("Authentication failed", 1)
251
- prompts.log.error(status.error)
252
- } else {
253
- spinner.stop("Unexpected status: " + status.status, 1)
254
- }
255
- } catch (error) {
256
- spinner.stop("Authentication failed", 1)
257
- prompts.log.error(error instanceof Error ? error.message : String(error))
258
- }
259
-
260
- prompts.outro("Done")
261
- },
262
- })
263
- },
264
- })
265
-
266
- export const McpAuthListCommand = cmd({
267
- command: "list",
268
- aliases: ["ls"],
269
- describe: "list OAuth-capable MCP servers and their auth status",
270
- async handler() {
271
- await Instance.provide({
272
- directory: process.cwd(),
273
- async fn() {
274
- UI.empty()
275
- prompts.intro("MCP OAuth Status")
276
-
277
- const config = await Config.get()
278
- const mcpServers = config.mcp ?? {}
279
-
280
- // Get OAuth-capable servers
281
- const oauthServers = Object.entries(mcpServers).filter(
282
- (entry): entry is [string, McpRemote] => isMcpRemote(entry[1]) && entry[1].oauth !== false,
283
- )
284
-
285
- if (oauthServers.length === 0) {
286
- prompts.log.warn("No OAuth-capable MCP servers configured")
287
- prompts.outro("Done")
288
- return
289
- }
290
-
291
- for (const [name, serverConfig] of oauthServers) {
292
- const authStatus = await MCP.getAuthStatus(name)
293
- const icon = getAuthStatusIcon(authStatus)
294
- const statusText = getAuthStatusText(authStatus)
295
- const url = serverConfig.url
296
-
297
- prompts.log.info(`${icon} ${name} ${UI.Style.TEXT_DIM}${statusText}\n ${UI.Style.TEXT_DIM}${url}`)
298
- }
299
-
300
- prompts.outro(`${oauthServers.length} OAuth-capable server(s)`)
301
- },
302
- })
303
- },
304
- })
305
-
306
- export const McpLogoutCommand = cmd({
307
- command: "logout [name]",
308
- describe: "remove OAuth credentials for an MCP server",
309
- builder: (yargs) =>
310
- yargs.positional("name", {
311
- describe: "name of the MCP server",
312
- type: "string",
313
- }),
314
- async handler(args) {
315
- await Instance.provide({
316
- directory: process.cwd(),
317
- async fn() {
318
- UI.empty()
319
- prompts.intro("MCP OAuth Logout")
320
-
321
- const authPath = path.join(Global.Path.data, "mcp-auth.json")
322
- const credentials = await McpAuth.all()
323
- const serverNames = Object.keys(credentials)
324
-
325
- if (serverNames.length === 0) {
326
- prompts.log.warn("No MCP OAuth credentials stored")
327
- prompts.outro("Done")
328
- return
329
- }
330
-
331
- let serverName = args.name
332
- if (!serverName) {
333
- const selected = await prompts.select({
334
- message: "Select MCP server to logout",
335
- options: serverNames.map((name) => {
336
- const entry = credentials[name]
337
- const hasTokens = !!entry.tokens
338
- const hasClient = !!entry.clientInfo
339
- let hint = ""
340
- if (hasTokens && hasClient) hint = "tokens + client"
341
- else if (hasTokens) hint = "tokens"
342
- else if (hasClient) hint = "client registration"
343
- return {
344
- label: name,
345
- value: name,
346
- hint,
347
- }
348
- }),
349
- })
350
- if (prompts.isCancel(selected)) throw new UI.CancelledError()
351
- serverName = selected
352
- }
353
-
354
- if (!credentials[serverName]) {
355
- prompts.log.error(`No credentials found for: ${serverName}`)
356
- prompts.outro("Done")
357
- return
358
- }
359
-
360
- await MCP.removeAuth(serverName)
361
- prompts.log.success(`Removed OAuth credentials for ${serverName}`)
362
- prompts.outro("Done")
363
- },
364
- })
365
- },
366
- })
367
-
368
- export const McpAddCommand = cmd({
369
- command: "add",
370
- describe: "add an MCP server",
371
- async handler() {
372
- UI.empty()
373
- prompts.intro("Add MCP server")
374
-
375
- const name = await prompts.text({
376
- message: "Enter MCP server name",
377
- validate: (x) => (x && x.length > 0 ? undefined : "Required"),
378
- })
379
- if (prompts.isCancel(name)) throw new UI.CancelledError()
380
-
381
- const type = await prompts.select({
382
- message: "Select MCP server type",
383
- options: [
384
- {
385
- label: "Local",
386
- value: "local",
387
- hint: "Run a local command",
388
- },
389
- {
390
- label: "Remote",
391
- value: "remote",
392
- hint: "Connect to a remote URL",
393
- },
394
- ],
395
- })
396
- if (prompts.isCancel(type)) throw new UI.CancelledError()
397
-
398
- if (type === "local") {
399
- const command = await prompts.text({
400
- message: "Enter command to run",
401
- placeholder: "e.g., opencode x @modelcontextprotocol/server-filesystem",
402
- validate: (x) => (x && x.length > 0 ? undefined : "Required"),
403
- })
404
- if (prompts.isCancel(command)) throw new UI.CancelledError()
405
-
406
- prompts.log.info(`Local MCP server "${name}" configured with command: ${command}`)
407
- prompts.outro("MCP server added successfully")
408
- return
409
- }
410
-
411
- if (type === "remote") {
412
- const url = await prompts.text({
413
- message: "Enter MCP server URL",
414
- placeholder: "e.g., https://example.com/mcp",
415
- validate: (x) => {
416
- if (!x) return "Required"
417
- if (x.length === 0) return "Required"
418
- const isValid = URL.canParse(x)
419
- return isValid ? undefined : "Invalid URL"
420
- },
421
- })
422
- if (prompts.isCancel(url)) throw new UI.CancelledError()
423
-
424
- const useOAuth = await prompts.confirm({
425
- message: "Does this server require OAuth authentication?",
426
- initialValue: false,
427
- })
428
- if (prompts.isCancel(useOAuth)) throw new UI.CancelledError()
429
-
430
- if (useOAuth) {
431
- const hasClientId = await prompts.confirm({
432
- message: "Do you have a pre-registered client ID?",
433
- initialValue: false,
434
- })
435
- if (prompts.isCancel(hasClientId)) throw new UI.CancelledError()
436
-
437
- if (hasClientId) {
438
- const clientId = await prompts.text({
439
- message: "Enter client ID",
440
- validate: (x) => (x && x.length > 0 ? undefined : "Required"),
441
- })
442
- if (prompts.isCancel(clientId)) throw new UI.CancelledError()
443
-
444
- const hasSecret = await prompts.confirm({
445
- message: "Do you have a client secret?",
446
- initialValue: false,
447
- })
448
- if (prompts.isCancel(hasSecret)) throw new UI.CancelledError()
449
-
450
- let clientSecret: string | undefined
451
- if (hasSecret) {
452
- const secret = await prompts.password({
453
- message: "Enter client secret",
454
- })
455
- if (prompts.isCancel(secret)) throw new UI.CancelledError()
456
- clientSecret = secret
457
- }
458
-
459
- prompts.log.info(`Remote MCP server "${name}" configured with OAuth (client ID: ${clientId})`)
460
- prompts.log.info("Add this to your chad-code.json:")
461
- prompts.log.info(`
462
- "mcp": {
463
- "${name}": {
464
- "type": "remote",
465
- "url": "${url}",
466
- "oauth": {
467
- "clientId": "${clientId}"${clientSecret ? `,\n "clientSecret": "${clientSecret}"` : ""}
468
- }
469
- }
470
- }`)
471
- } else {
472
- prompts.log.info(`Remote MCP server "${name}" configured with OAuth (dynamic registration)`)
473
- prompts.log.info("Add this to your chad-code.json:")
474
- prompts.log.info(`
475
- "mcp": {
476
- "${name}": {
477
- "type": "remote",
478
- "url": "${url}",
479
- "oauth": {}
480
- }
481
- }`)
482
- }
483
- } else {
484
- const client = new Client({
485
- name: "opencode",
486
- version: "1.0.0",
487
- })
488
- const transport = new StreamableHTTPClientTransport(new URL(url))
489
- await client.connect(transport)
490
- prompts.log.info(`Remote MCP server "${name}" configured with URL: ${url}`)
491
- }
492
- }
493
-
494
- prompts.outro("MCP server added successfully")
495
- },
496
- })
497
-
498
- export const McpDebugCommand = cmd({
499
- command: "debug <name>",
500
- describe: "debug OAuth connection for an MCP server",
501
- builder: (yargs) =>
502
- yargs.positional("name", {
503
- describe: "name of the MCP server",
504
- type: "string",
505
- demandOption: true,
506
- }),
507
- async handler(args) {
508
- await Instance.provide({
509
- directory: process.cwd(),
510
- async fn() {
511
- UI.empty()
512
- prompts.intro("MCP OAuth Debug")
513
-
514
- const config = await Config.get()
515
- const mcpServers = config.mcp ?? {}
516
- const serverName = args.name
517
-
518
- const serverConfig = mcpServers[serverName]
519
- if (!serverConfig) {
520
- prompts.log.error(`MCP server not found: ${serverName}`)
521
- prompts.outro("Done")
522
- return
523
- }
524
-
525
- if (!isMcpRemote(serverConfig)) {
526
- prompts.log.error(`MCP server ${serverName} is not a remote server`)
527
- prompts.outro("Done")
528
- return
529
- }
530
-
531
- if (serverConfig.oauth === false) {
532
- prompts.log.warn(`MCP server ${serverName} has OAuth explicitly disabled`)
533
- prompts.outro("Done")
534
- return
535
- }
536
-
537
- prompts.log.info(`Server: ${serverName}`)
538
- prompts.log.info(`URL: ${serverConfig.url}`)
539
-
540
- // Check stored auth status
541
- const authStatus = await MCP.getAuthStatus(serverName)
542
- prompts.log.info(`Auth status: ${getAuthStatusIcon(authStatus)} ${getAuthStatusText(authStatus)}`)
543
-
544
- const entry = await McpAuth.get(serverName)
545
- if (entry?.tokens) {
546
- prompts.log.info(` Access token: ${entry.tokens.accessToken.substring(0, 20)}...`)
547
- if (entry.tokens.expiresAt) {
548
- const expiresDate = new Date(entry.tokens.expiresAt * 1000)
549
- const isExpired = entry.tokens.expiresAt < Date.now() / 1000
550
- prompts.log.info(` Expires: ${expiresDate.toISOString()} ${isExpired ? "(EXPIRED)" : ""}`)
551
- }
552
- if (entry.tokens.refreshToken) {
553
- prompts.log.info(` Refresh token: present`)
554
- }
555
- }
556
- if (entry?.clientInfo) {
557
- prompts.log.info(` Client ID: ${entry.clientInfo.clientId}`)
558
- if (entry.clientInfo.clientSecretExpiresAt) {
559
- const expiresDate = new Date(entry.clientInfo.clientSecretExpiresAt * 1000)
560
- prompts.log.info(` Client secret expires: ${expiresDate.toISOString()}`)
561
- }
562
- }
563
-
564
- const spinner = prompts.spinner()
565
- spinner.start("Testing connection...")
566
-
567
- // Test basic HTTP connectivity first
568
- try {
569
- const response = await fetch(serverConfig.url, {
570
- method: "POST",
571
- headers: {
572
- "Content-Type": "application/json",
573
- Accept: "application/json, text/event-stream",
574
- },
575
- body: JSON.stringify({
576
- jsonrpc: "2.0",
577
- method: "initialize",
578
- params: {
579
- protocolVersion: "2024-11-05",
580
- capabilities: {},
581
- clientInfo: { name: "opencode-debug", version: Installation.VERSION },
582
- },
583
- id: 1,
584
- }),
585
- })
586
-
587
- spinner.stop(`HTTP response: ${response.status} ${response.statusText}`)
588
-
589
- // Check for WWW-Authenticate header
590
- const wwwAuth = response.headers.get("www-authenticate")
591
- if (wwwAuth) {
592
- prompts.log.info(`WWW-Authenticate: ${wwwAuth}`)
593
- }
594
-
595
- if (response.status === 401) {
596
- prompts.log.warn("Server returned 401 Unauthorized")
597
-
598
- // Try to discover OAuth metadata
599
- const oauthConfig = typeof serverConfig.oauth === "object" ? serverConfig.oauth : undefined
600
- const authProvider = new McpOAuthProvider(
601
- serverName,
602
- serverConfig.url,
603
- {
604
- clientId: oauthConfig?.clientId,
605
- clientSecret: oauthConfig?.clientSecret,
606
- scope: oauthConfig?.scope,
607
- },
608
- {
609
- onRedirect: async () => {},
610
- },
611
- )
612
-
613
- prompts.log.info("Testing OAuth flow (without completing authorization)...")
614
-
615
- // Try creating transport with auth provider to trigger discovery
616
- const transport = new StreamableHTTPClientTransport(new URL(serverConfig.url), {
617
- authProvider,
618
- })
619
-
620
- try {
621
- const client = new Client({
622
- name: "opencode-debug",
623
- version: Installation.VERSION,
624
- })
625
- await client.connect(transport)
626
- prompts.log.success("Connection successful (already authenticated)")
627
- await client.close()
628
- } catch (error) {
629
- if (error instanceof UnauthorizedError) {
630
- prompts.log.info(`OAuth flow triggered: ${error.message}`)
631
-
632
- // Check if dynamic registration would be attempted
633
- const clientInfo = await authProvider.clientInformation()
634
- if (clientInfo) {
635
- prompts.log.info(`Client ID available: ${clientInfo.client_id}`)
636
- } else {
637
- prompts.log.info("No client ID - dynamic registration will be attempted")
638
- }
639
- } else {
640
- prompts.log.error(`Connection error: ${error instanceof Error ? error.message : String(error)}`)
641
- }
642
- }
643
- } else if (response.status >= 200 && response.status < 300) {
644
- prompts.log.success("Server responded successfully (no auth required or already authenticated)")
645
- const body = await response.text()
646
- try {
647
- const json = JSON.parse(body)
648
- if (json.result?.serverInfo) {
649
- prompts.log.info(`Server info: ${JSON.stringify(json.result.serverInfo)}`)
650
- }
651
- } catch {
652
- // Not JSON, ignore
653
- }
654
- } else {
655
- prompts.log.warn(`Unexpected status: ${response.status}`)
656
- const body = await response.text().catch(() => "")
657
- if (body) {
658
- prompts.log.info(`Response body: ${body.substring(0, 500)}`)
659
- }
660
- }
661
- } catch (error) {
662
- spinner.stop("Connection failed", 1)
663
- prompts.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`)
664
- }
665
-
666
- prompts.outro("Debug complete")
667
- },
668
- })
669
- },
670
- })
@@ -1,42 +0,0 @@
1
- import type { Argv } from "yargs"
2
- import { Instance } from "../../project/instance"
3
- import { Provider } from "../../provider/provider"
4
- import { cmd } from "./cmd"
5
- import { UI } from "../ui"
6
- import { EOL } from "os"
7
-
8
- export const ModelsCommand = cmd({
9
- command: "models",
10
- describe: "list available Chad models",
11
- builder: (yargs: Argv) => {
12
- return yargs.option("verbose", {
13
- describe: "use more verbose model output (includes metadata like costs)",
14
- type: "boolean",
15
- })
16
- },
17
- handler: async (args) => {
18
- await Instance.provide({
19
- directory: process.cwd(),
20
- async fn() {
21
- const providers = await Provider.list()
22
-
23
- if (Object.keys(providers).length === 0) {
24
- UI.error("No providers available. Please set CORETHINK_API_KEY environment variable.")
25
- return
26
- }
27
-
28
- for (const [providerID, provider] of Object.entries(providers)) {
29
- const sortedModels = Object.entries(provider.models).sort(([a], [b]) => a.localeCompare(b))
30
- for (const [modelID, model] of sortedModels) {
31
- process.stdout.write(`${providerID}/${modelID}`)
32
- process.stdout.write(EOL)
33
- if (args.verbose) {
34
- process.stdout.write(JSON.stringify(model, null, 2))
35
- process.stdout.write(EOL)
36
- }
37
- }
38
- }
39
- },
40
- })
41
- },
42
- })