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,206 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+
12
+ function detectPlatformAndArch() {
13
+ // Map platform names
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ // Map architecture names
31
+ let arch
32
+ switch (os.arch()) {
33
+ case "x64":
34
+ arch = "x64"
35
+ break
36
+ case "arm64":
37
+ arch = "arm64"
38
+ break
39
+ case "arm":
40
+ arch = "arm"
41
+ break
42
+ default:
43
+ arch = os.arch()
44
+ break
45
+ }
46
+
47
+ return { platform, arch }
48
+ }
49
+
50
+ function installOptionalDependency(packageName) {
51
+ const { execSync } = require("child_process")
52
+
53
+ console.log(`Installing optional dependency: ${packageName}`)
54
+ try {
55
+ // Get the version from package.json optionalDependencies
56
+ const packageJsonPath = path.join(__dirname, "package.json")
57
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
58
+ const version = packageJson.optionalDependencies?.[packageName] || "latest"
59
+
60
+ // Find the parent node_modules directory
61
+ let installDir = __dirname
62
+ let parentNodeModules = path.join(__dirname, "..", "node_modules")
63
+
64
+ // Walk up to find node_modules directory
65
+ let current = __dirname
66
+ while (current !== path.dirname(current)) {
67
+ const nodeModulesPath = path.join(current, "node_modules")
68
+ if (fs.existsSync(nodeModulesPath)) {
69
+ parentNodeModules = nodeModulesPath
70
+ installDir = current
71
+ break
72
+ }
73
+ current = path.dirname(current)
74
+ }
75
+
76
+ // Install the package in the parent node_modules
77
+ execSync(`npm install ${packageName}@${version} --no-save --legacy-peer-deps`, {
78
+ cwd: installDir,
79
+ stdio: "inherit",
80
+ })
81
+ console.log(`✓ Installed ${packageName}@${version}`)
82
+ return true
83
+ } catch (error) {
84
+ console.error(`Failed to install ${packageName}:`, error.message)
85
+ return false
86
+ }
87
+ }
88
+
89
+ function findBinary() {
90
+ const { platform, arch } = detectPlatformAndArch()
91
+ const packageName = `bincode-cli-${platform}-${arch}`
92
+ const binaryName = platform === "windows" ? "bincode.exe" : "bincode"
93
+
94
+ // Try to find in node_modules (from optional dependencies)
95
+ try {
96
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
97
+ const packageDir = path.dirname(packageJsonPath)
98
+ const binaryPath = path.join(packageDir, "bin", binaryName)
99
+
100
+ if (fs.existsSync(binaryPath)) {
101
+ return { binaryPath, binaryName }
102
+ }
103
+ } catch (error) {
104
+ // Try to install the optional dependency
105
+ const installed = installOptionalDependency(packageName)
106
+ if (installed) {
107
+ try {
108
+ // Clear require cache to pick up newly installed package
109
+ delete require.cache[require.resolve(`${packageName}/package.json`)]
110
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
111
+ const packageDir = path.dirname(packageJsonPath)
112
+ const binaryPath = path.join(packageDir, "bin", binaryName)
113
+
114
+ if (fs.existsSync(binaryPath)) {
115
+ return { binaryPath, binaryName }
116
+ }
117
+ } catch (retryError) {
118
+ // Continue to baseline check
119
+ }
120
+ }
121
+
122
+ // Try baseline variant if main package not found
123
+ const baselinePackageName = packageName + "-baseline"
124
+ try {
125
+ const baselinePackageJsonPath = require.resolve(`${baselinePackageName}/package.json`)
126
+ const baselinePackageDir = path.dirname(baselinePackageJsonPath)
127
+ const baselineBinaryPath = path.join(baselinePackageDir, "bin", binaryName)
128
+
129
+ if (fs.existsSync(baselineBinaryPath)) {
130
+ return { binaryPath: baselineBinaryPath, binaryName }
131
+ }
132
+ } catch (baselineError) {
133
+ // Try to install baseline variant
134
+ const baselineInstalled = installOptionalDependency(baselinePackageName)
135
+ if (baselineInstalled) {
136
+ try {
137
+ delete require.cache[require.resolve(`${baselinePackageName}/package.json`)]
138
+ const baselinePackageJsonPath = require.resolve(`${baselinePackageName}/package.json`)
139
+ const baselinePackageDir = path.dirname(baselinePackageJsonPath)
140
+ const baselineBinaryPath = path.join(baselinePackageDir, "bin", binaryName)
141
+
142
+ if (fs.existsSync(baselineBinaryPath)) {
143
+ return { binaryPath: baselineBinaryPath, binaryName }
144
+ }
145
+ } catch (retryError) {
146
+ // Will throw below
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ throw new Error(`Could not find binary for ${packageName}. Please ensure the package was installed correctly. The platform-specific package should be installed automatically as an optional dependency.`)
153
+ }
154
+
155
+ function prepareBinDirectory(binaryName) {
156
+ const binDir = path.join(__dirname, "bin")
157
+ const targetPath = path.join(binDir, binaryName)
158
+
159
+ // Ensure bin directory exists
160
+ if (!fs.existsSync(binDir)) {
161
+ fs.mkdirSync(binDir, { recursive: true })
162
+ }
163
+
164
+ // Remove existing binary/symlink if it exists
165
+ if (fs.existsSync(targetPath)) {
166
+ fs.unlinkSync(targetPath)
167
+ }
168
+
169
+ return { binDir, targetPath }
170
+ }
171
+
172
+ function symlinkBinary(sourcePath, binaryName) {
173
+ const { targetPath } = prepareBinDirectory(binaryName)
174
+
175
+ fs.symlinkSync(sourcePath, targetPath)
176
+ console.log(`bincode binary symlinked: ${targetPath} -> ${sourcePath}`)
177
+
178
+ // Verify the file exists after operation
179
+ if (!fs.existsSync(targetPath)) {
180
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
181
+ }
182
+ }
183
+
184
+ function main() {
185
+ try {
186
+ if (os.platform() === "win32") {
187
+ // On Windows, the .exe is already included in the package and bin field points to it
188
+ // No postinstall setup needed
189
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
190
+ return
191
+ }
192
+
193
+ const { binaryPath, binaryName } = findBinary()
194
+ symlinkBinary(binaryPath, binaryName)
195
+ } catch (error) {
196
+ console.error("Failed to setup bincode binary:", error.message)
197
+ process.exit(1)
198
+ }
199
+ }
200
+
201
+ try {
202
+ main()
203
+ } catch (error) {
204
+ console.error("Postinstall script error:", error.message)
205
+ process.exit(0)
206
+ }
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { $ } from "bun"
4
+ import path from "path"
5
+ import { fileURLToPath } from "url"
6
+ import { existsSync } from "fs"
7
+
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = path.dirname(__filename)
10
+ const dir = path.resolve(__dirname, "..")
11
+
12
+ process.chdir(dir)
13
+
14
+ console.log("🚀 Starting publish process...\n")
15
+
16
+ // Step 1: Check if user is logged in to npm
17
+ console.log("📋 Checking npm login status...")
18
+ const whoamiResult = await $`npm whoami`.quiet()
19
+ if (whoamiResult.exitCode !== 0) {
20
+ console.error("❌ Error: You are not logged in to npm!")
21
+ console.error(" Please run: npm login")
22
+ process.exit(1)
23
+ }
24
+ const username = (await whoamiResult.text()).trim()
25
+ console.log(`✅ Logged in as: ${username}\n`)
26
+
27
+ // Step 2: Read package.json to get current version
28
+ const pkg = await Bun.file("package.json").json()
29
+ console.log(`📦 Package: ${pkg.name}`)
30
+ console.log(`📌 Current version: ${pkg.version}\n`)
31
+
32
+ // Step 3: Build binaries
33
+ console.log("🔨 Building binaries for all platforms...")
34
+ console.log(" This may take a few minutes...\n")
35
+ const buildResult = await $`bun run build`.quiet()
36
+ if (buildResult.exitCode !== 0) {
37
+ console.error("❌ Build failed!")
38
+ console.error(await buildResult.text())
39
+ process.exit(1)
40
+ }
41
+ console.log("✅ Build completed!\n")
42
+
43
+ // Step 4: Check if dist folder exists and has binaries
44
+ const distPath = path.join(dir, "dist")
45
+ if (!existsSync(distPath)) {
46
+ console.error("❌ Error: dist folder not found after build!")
47
+ console.error(` Expected path: ${distPath}`)
48
+ process.exit(1)
49
+ }
50
+
51
+ // Check if dist folder has any binaries
52
+ const distContents = await $`ls -1 ${distPath}`.quiet()
53
+ if (distContents.exitCode !== 0 || !(await distContents.text()).trim()) {
54
+ console.error("❌ Error: dist folder is empty!")
55
+ process.exit(1)
56
+ }
57
+ console.log("✅ Dist folder found with binaries\n")
58
+
59
+ // Step 5: Dry run to check what will be published
60
+ console.log("🔍 Checking what will be published (dry run)...\n")
61
+ const dryRunResult = await $`npm publish --dry-run`.quiet()
62
+ if (dryRunResult.exitCode !== 0) {
63
+ console.error("❌ Dry run failed!")
64
+ console.error(await dryRunResult.text())
65
+ process.exit(1)
66
+ }
67
+ console.log(await dryRunResult.text())
68
+ console.log()
69
+
70
+ // Step 6: Ask for confirmation
71
+ console.log("⚠️ Ready to publish!")
72
+ console.log(` Package: ${pkg.name}`)
73
+ console.log(` Version: ${pkg.version}`)
74
+ console.log(` Registry: npm (https://www.npmjs.com)`)
75
+ console.log()
76
+
77
+ // In non-interactive mode, skip confirmation
78
+ if (process.argv.includes("--yes") || process.argv.includes("-y")) {
79
+ console.log("🚀 Publishing (--yes flag detected)...\n")
80
+ } else {
81
+ console.log("Press Ctrl+C to cancel, or wait 5 seconds to continue...")
82
+ await new Promise((resolve) => setTimeout(resolve, 5000))
83
+ console.log()
84
+ }
85
+
86
+ // Step 7: Publish
87
+ console.log("📤 Publishing to npm...\n")
88
+ const publishResult = await $`npm publish`
89
+ if (publishResult.exitCode !== 0) {
90
+ console.error("❌ Publish failed!")
91
+ process.exit(1)
92
+ }
93
+
94
+ console.log("\n✅ Successfully published!")
95
+ console.log(`\n📥 Users can now install with:`)
96
+ console.log(` npm install -g ${pkg.name}`)
97
+ console.log(` bun install -g ${pkg.name}`)
98
+ console.log(` pnpm install -g ${pkg.name}`)
99
+ console.log(`\n🌐 Package URL: https://www.npmjs.com/package/${pkg.name}`)
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { z } from "zod"
4
+ import { Config } from "../src/config/config"
5
+
6
+ const file = process.argv[2]
7
+ console.log(file)
8
+
9
+ const result = z.toJSONSchema(Config.Info, {
10
+ io: "input", // Generate input shape (treats optional().default() as not required)
11
+ /**
12
+ * We'll use the `default` values of the field as the only value in `examples`.
13
+ * This will ensure no docs are needed to be read, as the configuration is
14
+ * self-documenting.
15
+ *
16
+ * See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.5
17
+ */
18
+ override(ctx) {
19
+ const schema = ctx.jsonSchema
20
+
21
+ // Preserve strictness: set additionalProperties: false for objects
22
+ if (schema && typeof schema === "object" && schema.type === "object" && schema.additionalProperties === undefined) {
23
+ schema.additionalProperties = false
24
+ }
25
+
26
+ // Add examples and default descriptions for string fields with defaults
27
+ if (schema && typeof schema === "object" && "type" in schema && schema.type === "string" && schema?.default) {
28
+ if (!schema.examples) {
29
+ schema.examples = [schema.default]
30
+ }
31
+
32
+ schema.description = [schema.description || "", `default: \`${schema.default}\``]
33
+ .filter(Boolean)
34
+ .join("\n\n")
35
+ .trim()
36
+ }
37
+ },
38
+ }) as Record<string, unknown> & {
39
+ allowComments?: boolean
40
+ allowTrailingCommas?: boolean
41
+ }
42
+
43
+ // used for json lsps since config supports jsonc
44
+ result.allowComments = true
45
+ result.allowTrailingCommas = true
46
+
47
+ await Bun.write(file, JSON.stringify(result, null, 2))
@@ -0,0 +1,164 @@
1
+ # ACP (Agent Client Protocol) Implementation
2
+
3
+ This directory contains a clean, protocol-compliant implementation of the [Agent Client Protocol](https://agentclientprotocol.com/) for bincode.
4
+
5
+ ## Architecture
6
+
7
+ The implementation follows a clean separation of concerns:
8
+
9
+ ### Core Components
10
+
11
+ - **`agent.ts`** - Implements the `Agent` interface from `@agentclientprotocol/sdk`
12
+ - Handles initialization and capability negotiation
13
+ - Manages session lifecycle (`session/new`, `session/load`)
14
+ - Processes prompts and returns responses
15
+ - Properly implements ACP protocol v1
16
+
17
+ - **`client.ts`** - Implements the `Client` interface for client-side capabilities
18
+ - File operations (`readTextFile`, `writeTextFile`)
19
+ - Permission requests (auto-approves for now)
20
+ - Terminal support (stub implementation)
21
+
22
+ - **`session.ts`** - Session state management
23
+ - Creates and tracks ACP sessions
24
+ - Maps ACP sessions to internal bincode sessions
25
+ - Maintains working directory context
26
+ - Handles MCP server configurations
27
+
28
+ - **`server.ts`** - ACP server startup and lifecycle
29
+ - Sets up JSON-RPC over stdio using the official library
30
+ - Manages graceful shutdown on SIGTERM/SIGINT
31
+ - Provides Instance context for the agent
32
+
33
+ - **`types.ts`** - Type definitions for internal use
34
+
35
+ ## Usage
36
+
37
+ ### Command Line
38
+
39
+ ```bash
40
+ # Start the ACP server in the current directory
41
+ bincode acp
42
+
43
+ # Start in a specific directory
44
+ bincode acp --cwd /path/to/project
45
+ ```
46
+
47
+ ### Programmatic
48
+
49
+ ```typescript
50
+ import { ACPServer } from "./acp/server"
51
+
52
+ await ACPServer.start()
53
+ ```
54
+
55
+ ### Integration with Zed
56
+
57
+ Add to your Zed configuration (`~/.config/zed/settings.json`):
58
+
59
+ ```json
60
+ {
61
+ "agent_servers": {
62
+ "Bincode": {
63
+ "command": "bincode",
64
+ "args": ["acp"]
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Protocol Compliance
71
+
72
+ This implementation follows the ACP specification v1:
73
+
74
+ ✅ **Initialization**
75
+
76
+ - Proper `initialize` request/response with protocol version negotiation
77
+ - Capability advertisement (`agentCapabilities`)
78
+ - Authentication support (stub)
79
+
80
+ ✅ **Session Management**
81
+
82
+ - `session/new` - Create new conversation sessions
83
+ - `session/load` - Resume existing sessions (basic support)
84
+ - Working directory context (`cwd`)
85
+ - MCP server configuration support
86
+
87
+ ✅ **Prompting**
88
+
89
+ - `session/prompt` - Process user messages
90
+ - Content block handling (text, resources)
91
+ - Response with stop reasons
92
+
93
+ ✅ **Client Capabilities**
94
+
95
+ - File read/write operations
96
+ - Permission requests
97
+ - Terminal support (stub for future)
98
+
99
+ ## Current Limitations
100
+
101
+ ### Not Yet Implemented
102
+
103
+ 1. **Streaming Responses** - Currently returns complete responses instead of streaming via `session/update` notifications
104
+ 2. **Tool Call Reporting** - Doesn't report tool execution progress
105
+ 3. **Session Modes** - No mode switching support yet
106
+ 4. **Authentication** - No actual auth implementation
107
+ 5. **Terminal Support** - Placeholder only
108
+ 6. **Session Persistence** - `session/load` doesn't restore actual conversation history
109
+
110
+ ### Future Enhancements
111
+
112
+ - **Real-time Streaming**: Implement `session/update` notifications for progressive responses
113
+ - **Tool Call Visibility**: Report tool executions as they happen
114
+ - **Session Persistence**: Save and restore full conversation history
115
+ - **Mode Support**: Implement different operational modes (ask, code, etc.)
116
+ - **Enhanced Permissions**: More sophisticated permission handling
117
+ - **Terminal Integration**: Full terminal support via bincode's bash tool
118
+
119
+ ## Testing
120
+
121
+ ```bash
122
+ # Run ACP tests
123
+ bun test test/acp.test.ts
124
+
125
+ # Test manually with stdio
126
+ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1}}' | bincode acp
127
+ ```
128
+
129
+ ## Design Decisions
130
+
131
+ ### Why the Official Library?
132
+
133
+ We use `@agentclientprotocol/sdk` instead of implementing JSON-RPC ourselves because:
134
+
135
+ - Ensures protocol compliance
136
+ - Handles edge cases and future protocol versions
137
+ - Reduces maintenance burden
138
+ - Works with other ACP clients automatically
139
+
140
+ ### Clean Architecture
141
+
142
+ Each component has a single responsibility:
143
+
144
+ - **Agent** = Protocol interface
145
+ - **Client** = Client-side operations
146
+ - **Session** = State management
147
+ - **Server** = Lifecycle and I/O
148
+
149
+ This makes the codebase maintainable and testable.
150
+
151
+ ### Mapping to Bincode
152
+
153
+ ACP sessions map cleanly to bincode's internal session model:
154
+
155
+ - ACP `session/new` → creates internal Session
156
+ - ACP `session/prompt` → uses SessionPrompt.prompt()
157
+ - Working directory context preserved per-session
158
+ - Tool execution uses existing ToolRegistry
159
+
160
+ ## References
161
+
162
+ - [ACP Specification](https://agentclientprotocol.com/)
163
+ - [TypeScript Library](https://github.com/agentclientprotocol/typescript-sdk)
164
+ - [Protocol Examples](https://github.com/agentclientprotocol/typescript-sdk/tree/main/src/examples)