@botconnector/bccli 0.4.0 → 0.4.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 (173) hide show
  1. package/README.en.md +13 -2
  2. package/README.md +13 -2
  3. package/dist/abort.d.ts +5 -0
  4. package/dist/{acp-ATIL4JOZ.js → acp-UYC6APR5.js} +30 -6
  5. package/dist/acp.d.ts +28 -0
  6. package/dist/agent.d.ts +147 -0
  7. package/dist/agents.d.ts +4 -0
  8. package/dist/args-NRTZWWEV.js +13 -0
  9. package/dist/args.d.ts +53 -0
  10. package/dist/budget.d.ts +23 -0
  11. package/dist/checkpoints.d.ts +35 -0
  12. package/dist/{chunk-6M5X2KZE.js → chunk-266SY3MC.js} +1 -1
  13. package/dist/{chunk-7F3IWBPQ.js → chunk-3I5BW3ZT.js} +20 -9
  14. package/dist/{chunk-UZWJQF67.js → chunk-3WHI4LN3.js} +2 -1
  15. package/dist/{chunk-PUN4HMAG.js → chunk-5YJ3ZQVR.js} +73 -10
  16. package/dist/{chunk-L7QI6JN2.js → chunk-6M55UPES.js} +7 -7
  17. package/dist/{chunk-KEMYIGCP.js → chunk-6UO5GX55.js} +26 -12
  18. package/dist/{chunk-TLPFQIS2.js → chunk-C64KM37J.js} +36 -6
  19. package/dist/{chunk-JL5ZCSP2.js → chunk-H7XJDKJY.js} +4 -4
  20. package/dist/{chunk-SPRNLS7K.js → chunk-HQW4BROS.js} +4 -5
  21. package/dist/{chunk-XBO5GACQ.js → chunk-IYR5PYA3.js} +4 -4
  22. package/dist/{chunk-45SDLMTV.js → chunk-JXM6REER.js} +1 -1
  23. package/dist/{chunk-BLOYFIAD.js → chunk-KPTML72Q.js} +1 -1
  24. package/dist/{chunk-BQ2IGPBR.js → chunk-NQOGVP3I.js} +2 -2
  25. package/dist/{chunk-QZKLZELZ.js → chunk-OK2USAXX.js} +28 -4
  26. package/dist/{chunk-TVALKHFB.js → chunk-R72OV7RF.js} +421 -108
  27. package/dist/{chunk-LACUWBWS.js → chunk-RX4UQX43.js} +25 -10
  28. package/dist/{chunk-QDQU6VY2.js → chunk-SVD4LHJC.js} +73 -3
  29. package/dist/{chunk-BNA74HPN.js → chunk-TIMSYZIR.js} +7 -7
  30. package/dist/{chunk-O7M3TGIW.js → chunk-WFZKJY3R.js} +43 -4
  31. package/dist/{chunk-M7CALSP3.js → chunk-ZEPTUKNW.js} +120 -32
  32. package/dist/cli.d.ts +1 -0
  33. package/dist/cli.js +61 -45
  34. package/dist/clipboardImage.d.ts +17 -0
  35. package/dist/commands.d.ts +16 -0
  36. package/dist/{completion-HPPFDAPB.js → completion-D2BSBTQO.js} +1 -1
  37. package/dist/completion.d.ts +14 -0
  38. package/dist/{config-COPNMMV6.js → config-ENDRMOTP.js} +3 -3
  39. package/dist/{config-RZ5JONMX.js → config-LAINORU5.js} +8 -4
  40. package/dist/config.d.ts +99 -0
  41. package/dist/context.d.ts +13 -0
  42. package/dist/contextWindow.d.ts +3 -0
  43. package/dist/diff.d.ts +7 -0
  44. package/dist/exit.d.ts +9 -0
  45. package/dist/extensions.d.ts +34 -0
  46. package/dist/{ghBotCli-IBCZIWT5.js → ghBotCli-TSLRORJJ.js} +21 -20
  47. package/dist/ghBotCli.d.ts +9 -0
  48. package/dist/ghBotDispatch.d.ts +68 -0
  49. package/dist/ghBotRunner.d.ts +82 -0
  50. package/dist/ghBotServe.d.ts +21 -0
  51. package/dist/ghBotWebhook.d.ts +45 -0
  52. package/dist/hooks.d.ts +27 -0
  53. package/dist/i18n/id.d.ts +1 -0
  54. package/dist/i18n.d.ts +16 -0
  55. package/dist/{integrationCli-P75R2VSC.js → integrationCli-HXCSEWH2.js} +2 -2
  56. package/dist/integrationCli.d.ts +9 -0
  57. package/dist/keybinds.d.ts +22 -0
  58. package/dist/{login-SYIQP46J.js → login-RYESFZG6.js} +4 -4
  59. package/dist/login.d.ts +19 -0
  60. package/dist/lsp.d.ts +50 -0
  61. package/dist/mcp/catalog.d.ts +14 -0
  62. package/dist/mcp/config.d.ts +36 -0
  63. package/dist/mcp/manager.d.ts +52 -0
  64. package/dist/mcp/oauth.d.ts +82 -0
  65. package/dist/{mcpCli-QUV5SD64.js → mcpCli-SETTCL3K.js} +6 -6
  66. package/dist/mcpCli.d.ts +3 -0
  67. package/dist/mcpServer/serve.d.ts +8 -0
  68. package/dist/mcpServer/server.d.ts +19 -0
  69. package/dist/models.d.ts +13 -0
  70. package/dist/{modelsCli-TRRB5LX4.js → modelsCli-OP7CDZC7.js} +6 -6
  71. package/dist/modelsCli.d.ts +15 -0
  72. package/dist/npmRunner.d.ts +21 -0
  73. package/dist/{oauthLogin-6FWQABJ7.js → oauthLogin-XWY7OHCG.js} +1 -1
  74. package/dist/oauthLogin.d.ts +47 -0
  75. package/dist/permissions.d.ts +30 -0
  76. package/dist/pluginSpec.d.ts +25 -0
  77. package/dist/plugins.d.ts +45 -0
  78. package/dist/{pluginsCli-GNW4TPVV.js → pluginsCli-ZQNKWZHJ.js} +2 -2
  79. package/dist/pluginsCli.d.ts +16 -0
  80. package/dist/{prCli-5IMV3VNQ.js → prCli-6PUWTMTP.js} +20 -4
  81. package/dist/prCli.d.ts +46 -0
  82. package/dist/presets.d.ts +8 -0
  83. package/dist/print.d.ts +16 -0
  84. package/dist/provider.d.ts +145 -0
  85. package/dist/providerCli-5OZI2GQQ.js +15 -0
  86. package/dist/providerCli.d.ts +17 -0
  87. package/dist/providers.d.ts +6 -0
  88. package/dist/reasoning.d.ts +12 -0
  89. package/dist/repomap.d.ts +10 -0
  90. package/dist/sdk.d.ts +61 -0
  91. package/dist/sdk.js +829 -191
  92. package/dist/{serve-JG7RLIUD.js → serve-4J7HA4JO.js} +24 -18
  93. package/dist/{serve-6QLBJUYW.js → serve-K5AH4MGO.js} +3 -3
  94. package/dist/serve.d.ts +37 -0
  95. package/dist/serveHeartbeat.d.ts +14 -0
  96. package/dist/serveProtocol.d.ts +47 -0
  97. package/dist/session-YQXCCKXI.js +12 -0
  98. package/dist/session.d.ts +33 -0
  99. package/dist/setup-S4AJT6XE.js +24 -0
  100. package/dist/setup.d.ts +74 -0
  101. package/dist/slash/copy.d.ts +1 -0
  102. package/dist/slash/diff.d.ts +1 -0
  103. package/dist/slash/doctor.d.ts +18 -0
  104. package/dist/slash/export.d.ts +2 -0
  105. package/dist/slash/info.d.ts +46 -0
  106. package/dist/slash/memory.d.ts +10 -0
  107. package/dist/{statsCli-CF3R7ATL.js → statsCli-XR6BEZQQ.js} +2 -2
  108. package/dist/statsCli.d.ts +62 -0
  109. package/dist/textToolCalls.d.ts +6 -0
  110. package/dist/thinking.d.ts +17 -0
  111. package/dist/tokenBudget.d.ts +22 -0
  112. package/dist/tools/bash.d.ts +52 -0
  113. package/dist/tools/diagnostics.d.ts +5 -0
  114. package/dist/tools/edit.d.ts +12 -0
  115. package/dist/tools/fetch.d.ts +41 -0
  116. package/dist/tools/glob.d.ts +5 -0
  117. package/dist/tools/globSafety.d.ts +7 -0
  118. package/dist/tools/grep.d.ts +25 -0
  119. package/dist/tools/ignore.d.ts +2 -0
  120. package/dist/tools/index.d.ts +12 -0
  121. package/dist/tools/memory.d.ts +13 -0
  122. package/dist/tools/paths.d.ts +4 -0
  123. package/dist/tools/plan.d.ts +10 -0
  124. package/dist/tools/read.d.ts +16 -0
  125. package/dist/tools/repomap.d.ts +2 -0
  126. package/dist/tools/sandbox.d.ts +12 -0
  127. package/dist/tools/shell.d.ts +18 -0
  128. package/dist/tools/skill.d.ts +3 -0
  129. package/dist/tools/task.d.ts +28 -0
  130. package/dist/tools/todo.d.ts +13 -0
  131. package/dist/tools/types.d.ts +52 -0
  132. package/dist/tools/websearch.d.ts +9 -0
  133. package/dist/tools/write.d.ts +5 -0
  134. package/dist/{transferCli-TK2GSVRK.js → transferCli-R2KEIWQR.js} +8 -6
  135. package/dist/transferCli.d.ts +23 -0
  136. package/dist/ui/App.d.ts +7 -0
  137. package/dist/ui/DiffView.d.ts +3 -0
  138. package/dist/ui/EditableText.d.ts +7 -0
  139. package/dist/ui/LinePrompt.d.ts +6 -0
  140. package/dist/ui/ListPicker.d.ts +11 -0
  141. package/dist/ui/Markdown.d.ts +8 -0
  142. package/dist/ui/McpMenu.d.ts +11 -0
  143. package/dist/ui/ModelPicker.d.ts +6 -0
  144. package/dist/ui/PermissionPrompt.d.ts +5 -0
  145. package/dist/ui/PlanApproval.d.ts +5 -0
  146. package/dist/ui/PromptInput.d.ts +18 -0
  147. package/dist/ui/ProviderMenu.d.ts +10 -0
  148. package/dist/ui/Spinner.d.ts +4 -0
  149. package/dist/ui/StatusBar.d.ts +9 -0
  150. package/dist/ui/TodoList.d.ts +4 -0
  151. package/dist/ui/ToolBlock.d.ts +14 -0
  152. package/dist/ui/complete.d.ts +6 -0
  153. package/dist/ui/focusReport.d.ts +1 -0
  154. package/dist/ui/index.d.ts +7 -0
  155. package/dist/ui/lineEdit.d.ts +42 -0
  156. package/dist/ui/replay.d.ts +4 -0
  157. package/dist/ui/table.d.ts +20 -0
  158. package/dist/ui/theme.d.ts +5 -0
  159. package/dist/ui/thinkingMouse.d.ts +33 -0
  160. package/dist/ui/transcript.d.ts +55 -0
  161. package/dist/ui/vim.d.ts +26 -0
  162. package/dist/{ui-B3CJ6TGE.js → ui-36ZEK65V.js} +179 -54
  163. package/dist/{update-K5IQ2MYR.js → update-FSS7X5WV.js} +2 -2
  164. package/dist/update.d.ts +30 -0
  165. package/dist/verify.d.ts +16 -0
  166. package/dist/version.d.ts +1 -0
  167. package/dist/webBudget.d.ts +25 -0
  168. package/dist/worktree.d.ts +12 -0
  169. package/package.json +26 -13
  170. package/dist/args-J5ONVGIF.js +0 -13
  171. package/dist/providerCli-FAOZHOKW.js +0 -15
  172. package/dist/session-KBAQ4BZ5.js +0 -12
  173. package/dist/setup-FJAWDWV4.js +0 -24
package/README.en.md CHANGED
@@ -19,6 +19,9 @@ edits files, and runs commands — with your permission.
19
19
  # one-line install (macOS / Linux / WSL2) — provisions a portable Node if needed, no sudo
20
20
  curl -fsSL https://raw.githubusercontent.com/farijarifriyanto-debug/bccli/main/install.sh | bash
21
21
 
22
+ # Windows (PowerShell 5.1+) — needs Node.js 22+ already installed
23
+ irm https://raw.githubusercontent.com/farijarifriyanto-debug/bccli/main/install.ps1 | iex
24
+
22
25
  # or manual, if you already have Node.js 22+
23
26
  npm i -g @botconnector/bccli # latest stable, requires Node.js 22+
24
27
  npm i -g @botconnector/bccli@next # …or the next prerelease
@@ -53,13 +56,18 @@ In-session commands (type `/` for suggestions, ↑↓ to select, Enter to run):
53
56
  | `/session` | info about this session |
54
57
  | `/status` | version, model, permission mode, MCP, context |
55
58
  | `/permissions` | view/revoke permissions |
59
+ | `/pr` | review a pull request (`/pr <n\|url\|branch>`) |
60
+ | `/worktree` | list git worktrees; create one with `bccli -w <name>` |
56
61
  | `/undo` | undo the last file-edit turn |
62
+ | `/redo` | re-apply the file edits that /undo just reverted |
63
+ | `/rewind` | step back turns: conversation + file edits (`/rewind 2`) |
57
64
  | `/diff` | git diff of the project |
58
65
  | `/copy` | copy the last answer |
59
66
  | `/export` | save the conversation to markdown |
60
67
  | `/memory` | project instructions (/memory <text>, /memory global <text>) |
61
68
  | `/init` | create/update AGENTS.md for this project |
62
69
  | `/agents` | list subagents |
70
+ | `/tasks` | list background tasks |
63
71
  | `/skills` | list skills and custom commands |
64
72
  | `/doctor` | check installation health |
65
73
  | `/login` | store the active provider's API key |
@@ -125,6 +133,8 @@ the `reasoning` preference is read only from the user config `~/.bccli/config.js
125
133
  cloned repo — permissions (`permissionMode`, `allow`) and existing providers are configured only
126
134
  from `~/.bccli/config.json`, so a cloned repo cannot grant itself full permissions or steal API keys.
127
135
 
136
+ Every key of `~/.bccli/config.json` with its values and scope: [`docs/config.md`](docs/config.md).
137
+
128
138
  ## External agent integrations
129
139
 
130
140
  BCCLI can set up BotConnector as a provider for other agents:
@@ -221,16 +231,17 @@ Tasks with ≥ 3 steps show a checklist above the input box. In plan mode (Shift
221
231
  the agent only reads and then proposes a plan; `[a]` approves with automatic edits,
222
232
  `[y]` approves asking at each step, `[n]` asks for revisions.
223
233
 
224
- Project instructions are read from `AGENTS.md` and `BCCLI.md`.
234
+ Project instructions are read from `AGENTS.md`, `CLAUDE.md`, and `BCCLI.md`.
225
235
 
226
236
  ## Development
227
237
 
228
238
  ```bash
229
239
  npm install
230
240
  npm test && npm run typecheck && npm run lint && npm run build
241
+ npm run coverage # coverage gate (also enforced on Linux CI)
231
242
  ```
232
243
 
233
- CI (`ci.yml`) runs the same on Linux, macOS, and Windows.
244
+ CI (`ci.yml`) runs the same on Linux, macOS, and Windows, plus the coverage gate on Linux.
234
245
  Releases: bump `version` in `package.json`, then push a `v<version>` tag — `release.yml`
235
246
  runs tests, a smoke test against BotConnector Cloud, and `npm publish --provenance`.
236
247
 
package/README.md CHANGED
@@ -19,6 +19,9 @@ dan menjalankan perintah — dengan izin kamu.
19
19
  # install satu baris (macOS / Linux / WSL2) — pasang Node portable bila perlu, tanpa sudo
20
20
  curl -fsSL https://raw.githubusercontent.com/farijarifriyanto-debug/bccli/main/install.sh | bash
21
21
 
22
+ # Windows (PowerShell 5.1+) — butuh Node.js 22+ terpasang lebih dulu
23
+ irm https://raw.githubusercontent.com/farijarifriyanto-debug/bccli/main/install.ps1 | iex
24
+
22
25
  # atau manual, bila Node.js 22+ sudah terpasang
23
26
  npm i -g @botconnector/bccli # rilis stabil terbaru, butuh Node.js 22+
24
27
  npm i -g @botconnector/bccli@next # …atau pra-rilis berikutnya
@@ -53,13 +56,18 @@ Perintah di dalam sesi (ketik `/` untuk saran, ↑↓ pilih, Enter jalankan):
53
56
  | `/session` | info sesi ini |
54
57
  | `/status` | versi, model, mode izin, MCP, konteks |
55
58
  | `/permissions` | lihat/cabut izin |
59
+ | `/pr` | review pull request (`/pr <n\|url\|branch>`) |
60
+ | `/worktree` | daftar git worktree; buat dengan `bccli -w <nama>` |
56
61
  | `/undo` | batalkan edit file giliran terakhir |
62
+ | `/redo` | terapkan ulang edit file yang baru dibatalkan `/undo` |
63
+ | `/rewind` | mundur beberapa giliran: percakapan + edit file (`/rewind 2`) |
57
64
  | `/diff` | git diff project |
58
65
  | `/copy` | salin jawaban terakhir |
59
66
  | `/export` | simpan percakapan ke markdown |
60
67
  | `/memory` | instruksi project (/memory <teks>, /memory global <teks>) |
61
68
  | `/init` | buat/perbarui AGENTS.md untuk project ini |
62
69
  | `/agents` | daftar subagent |
70
+ | `/tasks` | daftar tugas latar belakang |
63
71
  | `/skills` | daftar skill dan perintah custom |
64
72
  | `/doctor` | cek kesehatan instalasi |
65
73
  | `/login` | simpan API key provider aktif |
@@ -124,6 +132,8 @@ preference `reasoning` hanya dibaca dari config user `~/.bccli/config.json`, buk
124
132
  izin (`permissionMode`, `allow`) dan provider yang sudah ada hanya diatur dari `~/.bccli/config.json`,
125
133
  supaya repo yang kamu clone tidak bisa memberi dirinya izin penuh atau mencuri API key.
126
134
 
135
+ Daftar lengkap kunci `~/.bccli/config.json` beserta nilai dan cakupannya: [`docs/config.md`](docs/config.md).
136
+
127
137
  ## Integrasi agent eksternal
128
138
 
129
139
  BCCLI dapat memasang BotConnector sebagai provider untuk agent lain:
@@ -218,16 +228,17 @@ Tugas ≥ 3 langkah menampilkan checklist di atas kotak input. Di mode plan (Shi
218
228
  agent hanya membaca lalu mengajukan rencana; `[a]` setujui dengan edit otomatis,
219
229
  `[y]` setujui dengan tanya tiap langkah, `[n]` minta perbaikan.
220
230
 
221
- Instruksi project dibaca dari `AGENTS.md` dan `BCCLI.md`.
231
+ Instruksi project dibaca dari `AGENTS.md`, `CLAUDE.md`, dan `BCCLI.md`.
222
232
 
223
233
  ## Pengembangan
224
234
 
225
235
  ```bash
226
236
  npm install
227
237
  npm test && npm run typecheck && npm run lint && npm run build
238
+ npm run coverage # gerbang coverage (juga dijalankan di CI Linux)
228
239
  ```
229
240
 
230
- CI (`ci.yml`) menjalankan hal yang sama di Linux, macOS, dan Windows.
241
+ CI (`ci.yml`) menjalankan hal yang sama di Linux, macOS, dan Windows, plus gerbang coverage di Linux.
231
242
  Rilis: naikkan `version` di `package.json`, lalu push tag `v<version>` — `release.yml`
232
243
  menjalankan test, smoke test ke BotConnector Cloud, dan `npm publish --provenance`.
233
244
 
@@ -0,0 +1,5 @@
1
+ export declare const ABORTED: unique symbol;
2
+ /** Resolves with the promise's value, or with ABORTED as soon as the signal fires. */
3
+ export declare function raceAbort<T>(promise: Promise<T>, signal: AbortSignal): Promise<T | typeof ABORTED>;
4
+ /** Collects an async iterable, giving up (and telling the iterator to stop) as soon as the signal fires. */
5
+ export declare function collectUntilAbort<T>(iterable: AsyncIterable<T>, signal: AbortSignal | undefined, onItem: (item: T) => void): Promise<boolean>;
@@ -36,6 +36,9 @@ function runAcp(input, output, opts) {
36
36
  const replyError = (id, code, message) => write({ jsonrpc: "2.0", id, error: { code, message } });
37
37
  const update = (sessionId, body) => write({ jsonrpc: "2.0", method: "session/update", params: { sessionId, update: body } });
38
38
  const ioFor = (sid, session) => ({
39
+ onThinking(delta) {
40
+ update(sid, { sessionUpdate: "agent_thought_chunk", content: { type: "text", text: delta } });
41
+ },
39
42
  toolStart(id, tool, target) {
40
43
  session.open.push({ id, tool, target });
41
44
  update(sid, { sessionUpdate: "tool_call", toolCallId: id, title: titleOf(tool, target), kind: kindOf(tool), status: "in_progress", rawInput: { target } });
@@ -89,7 +92,7 @@ function runAcp(input, output, opts) {
89
92
  protocolVersion: ACP_PROTOCOL_VERSION,
90
93
  agentCapabilities: {
91
94
  loadSession: false,
92
- promptCapabilities: { image: false, audio: false, embeddedContext: false }
95
+ promptCapabilities: { image: false, audio: false, embeddedContext: true }
93
96
  }
94
97
  });
95
98
  }
@@ -108,7 +111,17 @@ function runAcp(input, output, opts) {
108
111
  const sid = params?.sessionId ?? "";
109
112
  const session = sessions.get(sid);
110
113
  if (!session) return replyError(id, -32602, "Unknown session");
111
- const text = (params?.prompt ?? []).filter((p) => p?.type === "text").map((p) => String(p.text ?? "")).join("\n");
114
+ if (session.controller) return replyError(id, -32e3, "Session is busy");
115
+ const text = (params?.prompt ?? []).map((p) => {
116
+ if (p?.type === "text") return String(p.text ?? "");
117
+ if ((p?.type === "resource" || p?.type === "embeddedContext") && p.resource?.text) {
118
+ const label = p.resource.uri ? `
119
+ [${p.resource.uri}]
120
+ ` : "\n";
121
+ return `${label}${p.resource.text}`;
122
+ }
123
+ return "";
124
+ }).filter(Boolean).join("\n");
112
125
  const controller = new AbortController();
113
126
  session.controller = controller;
114
127
  let cancelled = false;
@@ -122,8 +135,10 @@ function runAcp(input, output, opts) {
122
135
  if (cancelled) return reply(id, { stopReason: "cancelled" });
123
136
  return replyError(id, -32603, e.message);
124
137
  } finally {
125
- session.controller = null;
126
- session.open = [];
138
+ if (session.controller === controller) {
139
+ session.controller = null;
140
+ session.open = [];
141
+ }
127
142
  }
128
143
  return reply(id, { stopReason: cancelled ? "cancelled" : "end_turn" });
129
144
  }
@@ -150,6 +165,10 @@ function runAcp(input, output, opts) {
150
165
  };
151
166
  const onEnd = () => {
152
167
  input.removeListener("data", onData);
168
+ for (const session of sessions.values()) {
169
+ session.controller?.abort();
170
+ for (const settle of [...session.pending]) settle("no");
171
+ }
153
172
  resolve();
154
173
  };
155
174
  input.on("data", onData);
@@ -161,17 +180,22 @@ function runtimeAgent(cwd, allowAll = false) {
161
180
  return {
162
181
  async run(text, onChunk, signal, io) {
163
182
  if (!rt) {
164
- const { parseCliArgs } = await import("./args-J5ONVGIF.js");
165
- const { createRuntime } = await import("./setup-FJAWDWV4.js");
183
+ const { parseCliArgs } = await import("./args-NRTZWWEV.js");
184
+ const { createRuntime } = await import("./setup-S4AJT6XE.js");
166
185
  rt = createRuntime({ cwd, args: { ...parseCliArgs([]), allowAll } });
167
186
  }
168
187
  if (io && !allowAll) rt.agent.askPermission = (req) => io.askPermission(req);
188
+ let turnError;
169
189
  rt.agent.onEvent = (event) => {
170
190
  if (event.type === "text") onChunk(event.delta);
191
+ else if (event.type === "thinking") io?.onThinking?.(event.delta);
171
192
  else if (event.type === "toolStart") io?.toolStart(event.id, event.tool, event.target);
172
193
  else if (event.type === "toolEnd") io?.toolEnd(event.id, event.output, event.isError);
194
+ else if (event.type === "error") turnError = event.message;
195
+ else if (event.type === "budgetExceeded") turnError = `Budget exceeded (${event.kind})`;
173
196
  };
174
197
  await rt.agent.run(text, signal);
198
+ if (turnError) throw new Error(turnError);
175
199
  }
176
200
  };
177
201
  }
package/dist/acp.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { PermissionAnswer, PermissionAsk } from './agent';
2
+ export declare const ACP_PROTOCOL_VERSION = 1;
3
+ /** What the agent reports to the editor besides text: tool calls, and permission questions the editor answers. */
4
+ export interface AcpIo {
5
+ toolStart(id: string, tool: string, target: string): void;
6
+ toolEnd(id: string, output: string, isError: boolean): void;
7
+ askPermission(req: PermissionAsk): Promise<PermissionAnswer>;
8
+ onThinking?(delta: string): void;
9
+ }
10
+ /** The minimum an ACP client needs: run one prompt, stream text chunks, allow cancellation. */
11
+ export interface AcpAgent {
12
+ run(text: string, onChunk: (text: string) => void, signal: AbortSignal, io?: AcpIo): Promise<void>;
13
+ }
14
+ /**
15
+ * Agent Client Protocol over newline-delimited JSON-RPC (the transport editors like Zed use).
16
+ * Implements the subset: initialize, session/new, session/prompt (streaming session/update
17
+ * notifications: text chunks and tool calls), session/request_permission, session/cancel;
18
+ * anything else with an id gets -32601.
19
+ */
20
+ export declare function runAcp(input: NodeJS.ReadableStream, output: NodeJS.WritableStream, opts: {
21
+ cwd: string;
22
+ newAgent: (cwd: string) => AcpAgent;
23
+ }): Promise<void>;
24
+ /**
25
+ * Production agent: one bccli runtime per ACP session. Permission questions go to the editor
26
+ * (session/request_permission); `allowAll` skips them and runs everything unasked.
27
+ */
28
+ export declare function runtimeAgent(cwd: string, allowAll?: boolean): AcpAgent;
@@ -0,0 +1,147 @@
1
+ import type { PermissionRequest, Permissions } from './permissions';
2
+ import { type ChatMessage, type Provider, type Usage } from './provider';
3
+ import type { ReasoningLevel } from './reasoning';
4
+ import { type HookEvent, type HooksConfig } from './hooks';
5
+ import type { Tool } from './tools/types';
6
+ import { type UsageCap } from './budget';
7
+ export type AgentEvent = {
8
+ type: 'text';
9
+ delta: string;
10
+ } | {
11
+ type: 'thinking';
12
+ delta: string;
13
+ } | {
14
+ type: 'textReplace';
15
+ text: string;
16
+ } | {
17
+ type: 'toolStart';
18
+ id: string;
19
+ tool: string;
20
+ target: string;
21
+ } | {
22
+ type: 'toolEnd';
23
+ id: string;
24
+ tool: string;
25
+ output: string;
26
+ display?: string;
27
+ isError: boolean;
28
+ } | {
29
+ type: 'usage';
30
+ inputTokens: number;
31
+ outputTokens: number;
32
+ cachedInputTokens?: number;
33
+ cacheWriteTokens?: number;
34
+ } | {
35
+ type: 'compacted';
36
+ } | {
37
+ type: 'stepLimit';
38
+ maxSteps: number;
39
+ } | {
40
+ type: 'budgetExceeded';
41
+ kind: 'tokens' | 'usd';
42
+ used: number;
43
+ limit: number;
44
+ } | {
45
+ type: 'aborted';
46
+ } | {
47
+ type: 'error';
48
+ message: string;
49
+ } | {
50
+ type: 'done';
51
+ } | {
52
+ type: 'subagent';
53
+ parentId: string;
54
+ agent: string;
55
+ event: AgentEvent;
56
+ };
57
+ export type PermissionAnswer = 'yes' | 'session' | 'all' | 'no';
58
+ export type PermissionAsk = PermissionRequest & {
59
+ preview?: string;
60
+ sessionRules?: string[];
61
+ agent?: string;
62
+ };
63
+ export type AskPermission = (req: PermissionAsk) => Promise<PermissionAnswer>;
64
+ export interface AgentOptions {
65
+ provider: Provider;
66
+ tools: Tool[];
67
+ permissions: Permissions;
68
+ systemPrompt: string;
69
+ cwd: string;
70
+ history?: ChatMessage[];
71
+ maxSteps?: number | null;
72
+ contextWindow?: number;
73
+ onMessage?: (message: ChatMessage) => void;
74
+ onReset?: () => void;
75
+ /** Per-turn token usage delta (provider-reported or estimated); the session persists it for stats. */
76
+ onUsage?: (usage: Usage) => void;
77
+ /** Marks the start of a user turn (undo boundary). */
78
+ onTurnStart?: () => void;
79
+ checkpoint?: (absPath: string) => Promise<void>;
80
+ /** Subagent name, shown on its permission prompts. */
81
+ label?: string;
82
+ reasoning?: ReasoningLevel;
83
+ /** Tool/session hooks (global config only). */
84
+ hooks?: HooksConfig;
85
+ /** In-process plugin observers fired alongside the shell hooks (global config plugins). */
86
+ pluginEmit?: (event: HookEvent, payload?: {
87
+ tool?: string;
88
+ input?: unknown;
89
+ output?: string;
90
+ }) => Promise<void>;
91
+ /** Base environment handed to hook processes (defaults to the process env at spawn). */
92
+ env?: NodeJS.ProcessEnv;
93
+ /** Per-session token/USD budget (global config usageCap); blocks model calls once exceeded. */
94
+ usageCap?: UsageCap;
95
+ /** Model ref used to match usageCap.prices keys. */
96
+ budgetModel?: string;
97
+ }
98
+ export declare class Agent {
99
+ private readonly opts;
100
+ provider: Provider;
101
+ permissions: Permissions;
102
+ messages: ChatMessage[];
103
+ totalUsage: Usage;
104
+ lastInputTokens: number;
105
+ onEvent: (event: AgentEvent) => void;
106
+ reasoning: ReasoningLevel;
107
+ askPermission: AskPermission;
108
+ tools: Tool[];
109
+ private definitions;
110
+ private turnTools;
111
+ private turnDefinitions;
112
+ readonly readFiles: Set<string>;
113
+ private readonly webBudget;
114
+ private readonly maxSteps?;
115
+ private contextWindow;
116
+ private budgetModel;
117
+ private systemPrompt;
118
+ constructor(opts: AgentOptions);
119
+ setSystemPrompt(text: string): void;
120
+ setContextWindow(window: number): void;
121
+ getContextWindow(): number;
122
+ setBudgetModel(model: string): void;
123
+ getBudgetModel(): string;
124
+ setTools(tools: Tool[]): void;
125
+ private isParallelSafe;
126
+ private push;
127
+ /** Swaps in another conversation (resume, new session) without writing to the session log. */
128
+ load(messages: ChatMessage[]): void;
129
+ clear(): void;
130
+ compact(signal: AbortSignal): Promise<void>;
131
+ /**
132
+ * Events of one tool execution. A cancelled turn gives up on a tool that does not stop, and whatever that tool
133
+ * reports later must not reach the screen or a newer turn, so this is per execution and not per call id (ids repeat).
134
+ */
135
+ private report;
136
+ run(text: string, signal: AbortSignal): Promise<void>;
137
+ /** Current cap status; undefined means the budget is not exhausted. */
138
+ private overBudget;
139
+ /** Every tool call needs an answer in the history, or the next request to the model is rejected. */
140
+ private cancelCalls;
141
+ /**
142
+ * Every tool call must resolve with text: a rejected one would leave the assistant tool_calls
143
+ * without answers, and the next request to the model would be rejected until a restart.
144
+ */
145
+ private runTool;
146
+ private executeTool;
147
+ }
@@ -0,0 +1,4 @@
1
+ import type { AgentDef } from './extensions';
2
+ export declare const EXPLORE_PROMPT = "You are a read-only research agent working for another agent. Search and read the codebase to answer the request. You cannot edit files or run commands. Reply with a concise report: the answer, the relevant file paths with line numbers, and nothing else.";
3
+ export declare const GENERAL_PROMPT = "You are an agent handling a delegated task for another agent. Complete the task end to end with the tools you have, verify the result, and reply with a short report of what you did and what you found.";
4
+ export declare const BUILTIN_AGENTS: AgentDef[];
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ helpText,
4
+ parseCliArgs
5
+ } from "./chunk-6UO5GX55.js";
6
+ import "./chunk-WFZKJY3R.js";
7
+ import "./chunk-KPTML72Q.js";
8
+ import "./chunk-RX4UQX43.js";
9
+ import "./chunk-3WHI4LN3.js";
10
+ export {
11
+ helpText,
12
+ parseCliArgs
13
+ };
package/dist/args.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { type PermissionMode } from './config';
2
+ import { type ReasoningLevel } from './reasoning';
3
+ import { type Lang } from './i18n';
4
+ export interface CliArgs {
5
+ command: 'run' | 'login' | 'models' | 'update' | 'acp' | 'serve' | 'plugins' | 'gh-bot' | 'provider' | 'mcp' | 'connect' | 'disconnect' | 'integrations' | 'completion' | 'stats' | 'export' | 'import' | 'pr';
6
+ subArgs: string[];
7
+ url?: string;
8
+ name?: string;
9
+ keyEnv?: string;
10
+ values: string[];
11
+ prompt?: string;
12
+ print: boolean;
13
+ model?: string;
14
+ reasoning?: ReasoningLevel;
15
+ lang?: Lang;
16
+ continue: boolean;
17
+ resume: boolean;
18
+ allowAll: boolean;
19
+ allowedTools: string[];
20
+ worktree?: string;
21
+ outputFormat?: 'text' | 'json' | 'stream-json';
22
+ permissionMode?: PermissionMode;
23
+ help: boolean;
24
+ version: boolean;
25
+ loginProvider?: string;
26
+ /** `bccli login` — pakai prompt API key lama, bukan OAuth. */
27
+ key: boolean;
28
+ /** `bccli login` — hapus credential tersimpan (hanya openrouter via OAuth path). */
29
+ logout: boolean;
30
+ /** `bccli serve` listener port (0 = ephemeral). */
31
+ port?: number;
32
+ /** `bccli serve` bind address — loopback only. */
33
+ host?: string;
34
+ /** `bccli serve` bearer token override. */
35
+ token?: string;
36
+ /** Base URL override for `bccli mcp serve`. */
37
+ baseUrl?: string;
38
+ /** `bccli stats` — only count sessions from the last N days (default 7). */
39
+ days?: number;
40
+ /** `bccli stats` - cap the tool-usage list to the top N tools. */
41
+ tools?: number;
42
+ /** `bccli stats [--models [N|all]]` - show per-model token usage (top N or all). */
43
+ models?: string;
44
+ /** `bccli stats --project <slug>` - filter rows; empty string = current project. */
45
+ project?: string;
46
+ /** `bccli pr` — explicit owner/name repo when cwd is not a git checkout of the PR. */
47
+ repo?: string;
48
+ /** Automatic fallback model ref when the primary model fails with 429 or 5xx. */
49
+ fallbackModel?: string;
50
+ }
51
+ /** Help text in the current language (call it after the language is set). */
52
+ export declare const helpText: () => string;
53
+ export declare function parseCliArgs(argv: string[]): CliArgs;
@@ -0,0 +1,23 @@
1
+ export interface UsageCap {
2
+ /** Total tokens (input + output) per session. */
3
+ tokens?: number;
4
+ /** Total USD per session; requires `prices`. */
5
+ usd?: number;
6
+ /** USD per 1M tokens, keyed by a substring of the model ref (first match wins). */
7
+ prices?: Record<string, {
8
+ input: number;
9
+ output: number;
10
+ }>;
11
+ }
12
+ export declare function priceFor(cap: UsageCap, model: string): {
13
+ input: number;
14
+ output: number;
15
+ } | undefined;
16
+ export declare function budgetStatus(usage: {
17
+ inputTokens: number;
18
+ outputTokens: number;
19
+ }, cap: UsageCap | undefined, model: string): {
20
+ kind: 'tokens' | 'usd';
21
+ used: number;
22
+ limit: number;
23
+ } | undefined;
@@ -0,0 +1,35 @@
1
+ interface UndoResult {
2
+ restored: string[];
3
+ deleted: string[];
4
+ skipped: string[];
5
+ failed: string[];
6
+ }
7
+ export declare class CheckpointStore {
8
+ private readonly history;
9
+ private current;
10
+ private pendingRedo;
11
+ private offset;
12
+ beginTurn(): void;
13
+ /** Call before writing a file; only the first snapshot per file per turn is kept. */
14
+ snapshot(path: string): Promise<void>;
15
+ turns(): number;
16
+ /** Total entries including empty ones; used to align file snapshots with conversation turns. */
17
+ entries(): number;
18
+ undo(): Promise<UndoResult | undefined>;
19
+ /**
20
+ * Revert every snapshot taken at or after the `keep`-th entry, newest first, so the files
21
+ * end in the state from before the turn that created entry `keep`. Used by /rewind, which
22
+ * pairs conversation turns with the entry count recorded when each turn started.
23
+ */
24
+ undoTo(keep: number): Promise<UndoResult | undefined>;
25
+ /**
26
+ * Re-apply the file state captured right before the last undo/undoTo.
27
+ * Only file edits are redone, never conversation history. Invalidated by
28
+ * any new snapshot turn or clear(), so redo can't resurrect stale content.
29
+ */
30
+ redo(): Promise<UndoResult | undefined>;
31
+ /** Records the on-disk state of a turn's paths so redo() can put it back. */
32
+ private captureFor;
33
+ clear(): void;
34
+ }
35
+ export {};
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/version.ts
4
- var VERSION = true ? "0.4.0" : "0.0.0-dev";
4
+ var VERSION = true ? "0.4.2" : "0.0.0-dev";
5
5
 
6
6
  export {
7
7
  VERSION
@@ -1,8 +1,12 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ quarantineCorruptFile,
4
+ writeFileAtomic
5
+ } from "./chunk-RX4UQX43.js";
2
6
 
3
7
  // src/mcp/oauth.ts
4
8
  import { spawn } from "child_process";
5
- import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
9
+ import { existsSync, mkdirSync, readFileSync } from "fs";
6
10
  import { createServer } from "http";
7
11
  import { dirname, join } from "path";
8
12
  import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
@@ -12,16 +16,16 @@ function readStore(home) {
12
16
  if (!existsSync(path)) return {};
13
17
  try {
14
18
  return JSON.parse(readFileSync(path, "utf8"));
15
- } catch {
19
+ } catch (error) {
20
+ quarantineCorruptFile(path, error);
16
21
  return {};
17
22
  }
18
23
  }
19
24
  function writeStore(home, store) {
20
25
  const path = oauthStorePath(home);
21
26
  mkdirSync(dirname(path), { recursive: true });
22
- writeFileSync(path, `${JSON.stringify(store, null, 2)}
23
- `, { mode: 384 });
24
- chmodSync(path, 384);
27
+ writeFileAtomic(path, `${JSON.stringify(store, null, 2)}
28
+ `, 384);
25
29
  }
26
30
  function hasStoredTokens(home, serverUrl) {
27
31
  return Boolean(readStore(home)[serverUrl]?.tokens);
@@ -34,9 +38,15 @@ function clearTokens(home, serverUrl) {
34
38
  writeStore(home, store);
35
39
  return true;
36
40
  }
37
- function defaultOpen(url) {
38
- const target = url.href;
39
- const child = process.platform === "win32" ? spawn("cmd", ["/c", "start", "", target], { detached: true, stdio: "ignore" }) : spawn(process.platform === "darwin" ? "open" : "xdg-open", [target], { detached: true, stdio: "ignore" });
41
+ function openCommand(url, platform) {
42
+ if (url.protocol !== "http:" && url.protocol !== "https:") return void 0;
43
+ if (platform === "win32") return { command: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url.href] };
44
+ return { command: platform === "darwin" ? "open" : "xdg-open", args: [url.href] };
45
+ }
46
+ function defaultOpen(url, deps = {}) {
47
+ const plan = openCommand(url, deps.platform ?? process.platform);
48
+ if (!plan) return;
49
+ const child = (deps.spawn ?? spawn)(plan.command, plan.args, { detached: true, stdio: "ignore" });
40
50
  child.unref();
41
51
  child.on("error", () => {
42
52
  });
@@ -146,8 +156,9 @@ async function authorizeMcpServer(spec, deps) {
146
156
  res.end("<html><body><p>BCCLI is connected. You can close this tab.</p></body></html>");
147
157
  settle.resolve(code);
148
158
  } catch (error) {
159
+ const escaped = error.message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
149
160
  res.writeHead(400, { "content-type": "text/html; charset=utf-8" });
150
- res.end(`<html><body><p>${error.message}</p></body></html>`);
161
+ res.end(`<html><body><p>${escaped}</p></body></html>`);
151
162
  settle.reject(error);
152
163
  }
153
164
  });
@@ -458,7 +458,8 @@ Opsi:
458
458
  "gh is not available ({error}); install GitHub CLI first": "gh tidak tersedia ({error}); pasang GitHub CLI dulu",
459
459
  "gh pr checkout {n} failed (exit {code})": "gh pr checkout {n} gagal (exit {code})",
460
460
  "checked out PR #{n}": "checkout PR #{n} selesai",
461
- "--allow-all: the PR task runs every tool without asking": "--allow-all: tugas PR menjalankan semua alat tanpa bertanya"
461
+ "--allow-all: the PR task runs every tool without asking": "--allow-all: tugas PR menjalankan semua alat tanpa bertanya",
462
+ "view or change configuration settings": "lihat atau ubah pengaturan konfigurasi"
462
463
  };
463
464
 
464
465
  // src/i18n.ts