@botconnector/bccli 0.4.0-beta.5 → 0.4.0-beta.51
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.
- package/README.md +97 -2
- package/dist/acp-NWP4FFTG.js +182 -0
- package/dist/args-2R45YZ42.js +13 -0
- package/dist/{chunk-U7DLMVPZ.js → chunk-2QYHSESB.js} +2 -1
- package/dist/{chunk-UESQNU4A.js → chunk-4WVIPZFV.js} +14 -9
- package/dist/chunk-7F3IWBPQ.js +191 -0
- package/dist/chunk-DP7EBW53.js +341 -0
- package/dist/{chunk-SJH3YLW4.js → chunk-F6ACN47V.js} +60 -6
- package/dist/chunk-FTFVW7XD.js +235 -0
- package/dist/{chunk-ELML4KVQ.js → chunk-GAFJEQTJ.js} +32 -2
- package/dist/{chunk-NGLKANMD.js → chunk-H73FO5YK.js} +24 -2
- package/dist/chunk-KD2LMIS4.js +145 -0
- package/dist/chunk-KIZC5XV4.js +2141 -0
- package/dist/chunk-N7KP6RNP.js +76 -0
- package/dist/chunk-NDEJUL44.js +361 -0
- package/dist/chunk-PSO7R5AD.js +10 -0
- package/dist/chunk-QXOV4DUZ.js +56 -0
- package/dist/chunk-QZKLZELZ.js +64 -0
- package/dist/chunk-R4BJBTWC.js +940 -0
- package/dist/chunk-SNKVS26H.js +63 -0
- package/dist/chunk-TQWCM5RO.js +231 -0
- package/dist/chunk-VU5HNQHX.js +8 -0
- package/dist/chunk-XLC6T4SX.js +500 -0
- package/dist/chunk-YIYX3FFS.js +733 -0
- package/dist/cli.js +157 -1281
- package/dist/completion-OV3MW2N4.js +125 -0
- package/dist/{config-NPSYFAFD.js → config-AZZFOXKV.js} +5 -2
- package/dist/config-H5A7XHHK.js +30 -0
- package/dist/ghBotCli-7WDYF4L7.js +677 -0
- package/dist/integrationCli-ZMTSILYF.js +685 -0
- package/dist/login-W4Y6WHLV.js +16 -0
- package/dist/{mcpCli-Q2H63ISP.js → mcpCli-5QISTOFK.js} +42 -9
- package/dist/modelsCli-FZMBD4OE.js +36 -0
- package/dist/npmRunner-LU43GM3W.js +46 -0
- package/dist/oauthLogin-VESMXG4M.js +210 -0
- package/dist/pluginsCli-GEHR7FQR.js +284 -0
- package/dist/prCli-JXA7DJW4.js +72 -0
- package/dist/providerCli-EUZGKP5F.js +15 -0
- package/dist/sdk.js +5486 -0
- package/dist/serve-6KX4MXHC.js +178 -0
- package/dist/serve-YSUJD57D.js +515 -0
- package/dist/session-F6MG3UCU.js +12 -0
- package/dist/setup-LLWREJQH.js +24 -0
- package/dist/statsCli-H4HEY5ID.js +353 -0
- package/dist/transferCli-2XUKBG2L.js +71 -0
- package/dist/ui-6HJVYI46.js +2370 -0
- package/dist/update-O4WCLKOO.js +109 -0
- package/package.json +24 -3
- package/dist/args-FCLPQ7TO.js +0 -11
- package/dist/chunk-5O4HD7IU.js +0 -253
- package/dist/chunk-C5AFWX7H.js +0 -328
- package/dist/chunk-GW36UMHZ.js +0 -52
- package/dist/chunk-RZUJYAQV.js +0 -112
- package/dist/chunk-UN7QXPCB.js +0 -82
- package/dist/login-F4G5QXOU.js +0 -9
- package/dist/providerCli-MXV6PD6F.js +0 -11
- package/dist/session-7UB77CEG.js +0 -9
- package/dist/ui-RYTSKEIA.js +0 -1344
package/README.md
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
# BCCLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@botconnector/bccli)
|
|
4
|
+
[](https://www.npmjs.com/package/@botconnector/bccli)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://botconnector.id/id/download)
|
|
8
|
+
|
|
9
|
+
Agent AI coding dari [BotConnector](https://botconnector.id/) yang bekerja di terminal: membaca kode, mengedit file,
|
|
4
10
|
dan menjalankan perintah — dengan izin kamu.
|
|
5
11
|
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
*Rekaman sesi asli: BCCLI membuat file `hello.js` lalu menjalankannya dengan `node`.*
|
|
15
|
+
|
|
6
16
|
```bash
|
|
7
|
-
npm i -g @botconnector/bccli@next #
|
|
17
|
+
npm i -g @botconnector/bccli@next # beta terbaru, butuh Node.js 22+
|
|
8
18
|
bccli login # simpan API key BotConnector Cloud
|
|
9
19
|
cd project-kamu && bccli
|
|
10
20
|
```
|
|
@@ -15,8 +25,10 @@ cd project-kamu && bccli
|
|
|
15
25
|
|---|---|
|
|
16
26
|
| `bccli` | mode interaktif |
|
|
17
27
|
| `bccli -p "tugas"` | satu tugas tanpa interaksi (skrip/CI) |
|
|
28
|
+
| `bccli -p "tugas" --output-format json` | hasil akhir sebagai satu objek JSON; `stream-json` = event JSONL per tahap (tool_use/tool_result/message/result) untuk CI |
|
|
18
29
|
| `bccli -c` / `bccli -r` | lanjutkan sesi terakhir / pilih sesi |
|
|
19
30
|
| `bccli -m provider/model` | pilih model |
|
|
31
|
+
| `bccli --reasoning <auto|off|low|medium|high|max>` | pilih level reasoning untuk invocation ini |
|
|
20
32
|
| `bccli models` | daftar model |
|
|
21
33
|
|
|
22
34
|
Perintah di dalam sesi (ketik `/` untuk saran, ↑↓ pilih, Enter jalankan):
|
|
@@ -25,7 +37,9 @@ Perintah di dalam sesi (ketik `/` untuk saran, ↑↓ pilih, Enter jalankan):
|
|
|
25
37
|
|---|---|
|
|
26
38
|
| `/help` | daftar perintah dan pintasan |
|
|
27
39
|
| `/model` | ganti model |
|
|
40
|
+
| `/reasoning` | pilih Auto / Off / Low / Medium / High / Max |
|
|
28
41
|
| `/provider` | tambah/pilih provider AI |
|
|
42
|
+
| `/language` | ganti bahasa tampilan (`en` / `id`) |
|
|
29
43
|
| `/mcp` | pasang/kelola server MCP |
|
|
30
44
|
| `/new` | sesi baru (sesi lama tetap tersimpan) |
|
|
31
45
|
| `/resume` | lanjutkan sesi lain di folder ini |
|
|
@@ -54,6 +68,19 @@ Shift+Tab ganti mode izin: `default` → `acceptEdits` → `plan` → `allowAll`
|
|
|
54
68
|
Mode `-p` tidak pernah bertanya: alat yang butuh izin ditolak, kecuali memakai
|
|
55
69
|
`--allow-all` atau `--allowed-tools bash,edit,fetch`.
|
|
56
70
|
|
|
71
|
+
## Bahasa
|
|
72
|
+
|
|
73
|
+
Tampilan BCCLI (bantuan, pesan, prompt izin) memakai **bahasa Inggris secara default**. Bahasa Indonesia tetap tersedia:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
bccli --lang id # hanya untuk satu kali jalan
|
|
77
|
+
BCCLI_LANG=id bccli # lewat environment
|
|
78
|
+
/language id # di dalam sesi; disimpan di ~/.bccli/config.json ("language")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Urutan prioritas: `--lang`, lalu `BCCLI_LANG`, lalu `language` di config, lalu Inggris. Bahasa jawaban model mengikuti bahasa yang kamu tulis, dan
|
|
82
|
+
pesan alat yang dibaca model (hasil tool, galat) selalu berbahasa Inggris supaya tidak mengganggu bahasa jawabannya.
|
|
83
|
+
|
|
57
84
|
## Provider
|
|
58
85
|
|
|
59
86
|
`/provider` di dalam sesi (atau `bccli provider add <id>`) memasang provider hanya dengan API key:
|
|
@@ -76,10 +103,64 @@ Provider lain yang OpenAI-compatible: pilih **Custom…** di `/provider`, atau
|
|
|
76
103
|
`/model` menampilkan model dari **semua** provider yang sudah punya key, dikelompokkan
|
|
77
104
|
per provider; ketik untuk menyaring. Pilihan tersimpan sebagai default.
|
|
78
105
|
|
|
106
|
+
Reasoning dapat dipilih lewat `bccli --reasoning <auto|off|low|medium|high|max>` atau `/reasoning`.
|
|
107
|
+
**Auto** memakai default model/provider dan BCCLI tidak mengirim override reasoning apa pun. BCCLI tidak
|
|
108
|
+
otomatis menurunkan atau menaikkan reasoning effort. Level manual diteruskan bila kontrak provider/model
|
|
109
|
+
mendukungnya; level yang tidak didukung menghasilkan error yang jelas dan tidak di-downgrade diam-diam.
|
|
110
|
+
|
|
79
111
|
`.bccli/config.json` di dalam project hanya boleh memilih `model` dan menambah provider baru tanpa API key —
|
|
112
|
+
preference `reasoning` hanya dibaca dari config user `~/.bccli/config.json`, bukan dari repo yang di-clone —
|
|
80
113
|
izin (`permissionMode`, `allow`) dan provider yang sudah ada hanya diatur dari `~/.bccli/config.json`,
|
|
81
114
|
supaya repo yang kamu clone tidak bisa memberi dirinya izin penuh atau mencuri API key.
|
|
82
115
|
|
|
116
|
+
## Integrasi agent eksternal
|
|
117
|
+
|
|
118
|
+
BCCLI dapat memasang BotConnector sebagai provider untuk agent lain:
|
|
119
|
+
|
|
120
|
+
| Perintah | Fungsi |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `bccli integrations` | lihat status integrasi |
|
|
123
|
+
| `bccli connect opencode` | hubungkan OpenCode ke BotConnector |
|
|
124
|
+
| `bccli connect aider` | hubungkan Aider ke BotConnector |
|
|
125
|
+
| `bccli connect cline` | hubungkan Cline CLI ke BotConnector |
|
|
126
|
+
| `bccli connect deepseek-harness` / `bccli connect dsh` | hubungkan DeepSeek Harness ke BotConnector |
|
|
127
|
+
| `bccli connect codex` | buat profile Codex Responses API + launcher BotConnector |
|
|
128
|
+
| `bccli connect claude-code` | buat launcher Claude Code via Anthropic Messages compatibility |
|
|
129
|
+
| `bccli connect cursor` | buat guided setup Cursor + warning override Base URL |
|
|
130
|
+
| `bccli connect openai-cli` | buat launcher OpenAI CLI khusus BotConnector |
|
|
131
|
+
| `bccli connect openai-sdk` | buat env profile untuk OpenAI Python/Node SDK |
|
|
132
|
+
| `bccli connect openai-compatible` | buat env profile universal OpenAI-compatible |
|
|
133
|
+
| `bccli disconnect <agent>` | pulihkan config sebelum integrasi |
|
|
134
|
+
|
|
135
|
+
OpenCode memakai config global `~/.config/opencode/opencode.json`. BCCLI mengambil katalog model BotConnector saat connect,
|
|
136
|
+
menjaga config provider lain, dan menyimpan secret di file terpisah di `~/.bccli/integrations/`.
|
|
137
|
+
Aider memakai `~/.aider.conf.yml` yang menunjuk ke env file BCCLI terpisah; BCCLI menolak menimpa setting
|
|
138
|
+
OpenAI/env-file Aider yang sudah ada.
|
|
139
|
+
|
|
140
|
+
Cline memakai provider `openai-compatible` di `~/.cline/data/settings/providers.json`. Jika slot itu sudah dipakai
|
|
141
|
+
endpoint lain, BCCLI menolak menimpanya. Cline sendiri menyimpan API key provider di file tersebut.
|
|
142
|
+
|
|
143
|
+
DeepSeek Harness memakai custom provider `botconnector` di `$DSH_HOME/settings.yaml` dengan
|
|
144
|
+
`api: openai-completions` dan `apiKeyEnv: BOTCONNECTOR_API_KEY`; key diletakkan pada blok BCCLI di
|
|
145
|
+
`$DSH_HOME/.env`. Provider DSH lain tetap dipertahankan. Setelah connect, jalankan profile web dengan
|
|
146
|
+
`dsh web` (setara dengan `dsh --profile web`); `dsh` tanpa profile memang ditolak oleh DSH 0.1.x.
|
|
147
|
+
|
|
148
|
+
Codex memakai profile `$CODEX_HOME/botconnector.config.toml` dengan `wire_api = "responses"` dan launcher
|
|
149
|
+
BCCLI yang membaca key dari storage BCCLI saat dijalankan. Claude Code memakai launcher terisolasi dengan
|
|
150
|
+
`ANTHROPIC_BASE_URL=https://api.botconnector.id` dan endpoint kompatibilitas `/v1/messages` + token counting.
|
|
151
|
+
Login/config utama Codex dan Claude Code tidak ditimpa.
|
|
152
|
+
|
|
153
|
+
External agent memanggil BotConnector langsung, jadi discovery model tidak memakai identitas khusus BCCLI.
|
|
154
|
+
Akses yang memang dibatasi ke BCCLI/Web App (misalnya Luna launch access) tidak otomatis diwariskan.
|
|
155
|
+
Sebelum mengubah config eksternal, BCCLI membuat backup agar disconnect dapat memulihkannya.
|
|
156
|
+
|
|
157
|
+
## Internet
|
|
158
|
+
|
|
159
|
+
- `web_search`: mencari di web tanpa perlu izin. Memakai akun BotConnector Cloud
|
|
160
|
+
bila ada key, kalau tidak langsung ke Keenable (gratis, tanpa key). Hasilnya
|
|
161
|
+
judul, URL, dan cuplikan singkat, jadi hemat token.
|
|
162
|
+
- `fetch`: membuka satu URL dari komputer ini (butuh izin per host).
|
|
163
|
+
|
|
83
164
|
## MCP
|
|
84
165
|
|
|
85
166
|
`/mcp` (atau `bccli mcp add <nama>`) memasang server dari katalog:
|
|
@@ -89,6 +170,14 @@ seperti Claude Code). Semua alat MCP selalu minta izin.
|
|
|
89
170
|
|
|
90
171
|
`.bccli/mcp.json` di dalam repo tidak dijalankan sebelum kamu setujui (ditanya sekali per folder).
|
|
91
172
|
|
|
173
|
+
`bccli mcp serve` menjalankan MCP server stdio dengan tools BotConnector milikmu
|
|
174
|
+
(`bc_search`, `bc_fetch`, `bc_models`, `bc_chat`) untuk dipakai Claude Code, Cursor,
|
|
175
|
+
opencode, dan host MCP lain. Butuh `bccli login` (atau `BOTCONNECTOR_API_KEY`):
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
claude mcp add botconnector -- npx -y @botconnector/bccli mcp serve
|
|
179
|
+
```
|
|
180
|
+
|
|
92
181
|
## Subagent
|
|
93
182
|
|
|
94
183
|
Agent bisa mendelegasikan pekerjaan lewat alat `task`:
|
|
@@ -130,3 +219,9 @@ npm test && npm run typecheck && npm run lint && npm run build
|
|
|
130
219
|
CI (`ci.yml`) menjalankan hal yang sama di Linux, macOS, dan Windows.
|
|
131
220
|
Rilis: naikkan `version` di `package.json`, lalu push tag `v<version>` — `release.yml`
|
|
132
221
|
menjalankan test, smoke test ke BotConnector Cloud, dan `npm publish --provenance`.
|
|
222
|
+
|
|
223
|
+
## Pelajari lebih lanjut
|
|
224
|
+
|
|
225
|
+
- [Unduh & panduan BCCLI](https://botconnector.id/id/download)
|
|
226
|
+
- [Developer API BotConnector](https://botconnector.id/id/developers/api) — endpoint kompatibel OpenAI SDK
|
|
227
|
+
- [Switchboard](https://github.com/farijarifriyanto-debug/switchboard) — harness agent open source dari BotConnector
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/acp.ts
|
|
4
|
+
var ACP_PROTOCOL_VERSION = 1;
|
|
5
|
+
var TOOL_KINDS = {
|
|
6
|
+
read: "read",
|
|
7
|
+
repo_map: "read",
|
|
8
|
+
edit: "edit",
|
|
9
|
+
write: "edit",
|
|
10
|
+
grep: "search",
|
|
11
|
+
glob: "search",
|
|
12
|
+
bash: "execute",
|
|
13
|
+
powershell: "execute",
|
|
14
|
+
fetch: "fetch",
|
|
15
|
+
web_search: "fetch"
|
|
16
|
+
};
|
|
17
|
+
var kindOf = (tool) => TOOL_KINDS[tool] ?? "other";
|
|
18
|
+
var titleOf = (tool, target) => (target ? `${tool}: ${target}` : tool).slice(0, 200);
|
|
19
|
+
var MAX_OUTPUT = 4e3;
|
|
20
|
+
var PERMISSION_OPTIONS = [
|
|
21
|
+
{ optionId: "allow", name: "Allow", kind: "allow_once" },
|
|
22
|
+
{ optionId: "allow_session", name: "Allow for this session", kind: "allow_always" },
|
|
23
|
+
{ optionId: "reject", name: "Reject", kind: "reject_once" }
|
|
24
|
+
];
|
|
25
|
+
var ANSWERS = { allow: "yes", allow_session: "session", reject: "no" };
|
|
26
|
+
function runAcp(input, output, opts) {
|
|
27
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
28
|
+
const awaiting = /* @__PURE__ */ new Map();
|
|
29
|
+
let nextSession = 1;
|
|
30
|
+
let nextRequest = 1;
|
|
31
|
+
const write = (msg) => {
|
|
32
|
+
output.write(`${JSON.stringify(msg)}
|
|
33
|
+
`);
|
|
34
|
+
};
|
|
35
|
+
const reply = (id, result) => write({ jsonrpc: "2.0", id, result });
|
|
36
|
+
const replyError = (id, code, message) => write({ jsonrpc: "2.0", id, error: { code, message } });
|
|
37
|
+
const update = (sessionId, body) => write({ jsonrpc: "2.0", method: "session/update", params: { sessionId, update: body } });
|
|
38
|
+
const ioFor = (sid, session) => ({
|
|
39
|
+
toolStart(id, tool, target) {
|
|
40
|
+
session.open.push({ id, tool, target });
|
|
41
|
+
update(sid, { sessionUpdate: "tool_call", toolCallId: id, title: titleOf(tool, target), kind: kindOf(tool), status: "in_progress", rawInput: { target } });
|
|
42
|
+
},
|
|
43
|
+
toolEnd(id, output2, isError) {
|
|
44
|
+
session.open = session.open.filter((c) => c.id !== id);
|
|
45
|
+
const text = output2.length > MAX_OUTPUT ? `${output2.slice(0, MAX_OUTPUT)}
|
|
46
|
+
[truncated]` : output2;
|
|
47
|
+
update(sid, {
|
|
48
|
+
sessionUpdate: "tool_call_update",
|
|
49
|
+
toolCallId: id,
|
|
50
|
+
status: isError ? "failed" : "completed",
|
|
51
|
+
...text ? { content: [{ type: "content", content: { type: "text", text } }] } : {}
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
askPermission(req) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const requestId = nextRequest++;
|
|
57
|
+
const call = [...session.open].reverse().find((c) => c.tool === req.tool && c.target === req.target);
|
|
58
|
+
const settle = (answer) => {
|
|
59
|
+
session.pending.delete(settle);
|
|
60
|
+
awaiting.delete(requestId);
|
|
61
|
+
resolve(answer);
|
|
62
|
+
};
|
|
63
|
+
session.pending.add(settle);
|
|
64
|
+
awaiting.set(requestId, (message) => {
|
|
65
|
+
const outcome = message.result?.outcome;
|
|
66
|
+
settle(outcome?.outcome === "selected" ? ANSWERS[outcome.optionId ?? ""] ?? "no" : "no");
|
|
67
|
+
});
|
|
68
|
+
write({
|
|
69
|
+
jsonrpc: "2.0",
|
|
70
|
+
id: requestId,
|
|
71
|
+
method: "session/request_permission",
|
|
72
|
+
params: {
|
|
73
|
+
sessionId: sid,
|
|
74
|
+
toolCall: { toolCallId: call?.id ?? `permission-${requestId}`, title: titleOf(req.tool, req.target), kind: kindOf(req.tool), status: "pending" },
|
|
75
|
+
options: PERMISSION_OPTIONS
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const handle = async (msg) => {
|
|
82
|
+
const { id, method, params } = msg ?? {};
|
|
83
|
+
if (method === void 0 && id !== void 0 && (msg.result !== void 0 || msg.error !== void 0)) {
|
|
84
|
+
awaiting.get(id)?.(msg);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (method === "initialize") {
|
|
88
|
+
return reply(id, {
|
|
89
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
90
|
+
agentCapabilities: {
|
|
91
|
+
loadSession: false,
|
|
92
|
+
promptCapabilities: { image: false, audio: false, embeddedContext: false }
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (method === "session/new") {
|
|
97
|
+
const sessionId = `s${nextSession++}`;
|
|
98
|
+
sessions.set(sessionId, { controller: null, pending: /* @__PURE__ */ new Set(), open: [] });
|
|
99
|
+
return reply(id, { sessionId });
|
|
100
|
+
}
|
|
101
|
+
if (method === "session/cancel") {
|
|
102
|
+
const session = sessions.get(params?.sessionId ?? "");
|
|
103
|
+
session?.controller?.abort();
|
|
104
|
+
for (const settle of [...session?.pending ?? []]) settle("no");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (method === "session/prompt") {
|
|
108
|
+
const sid = params?.sessionId ?? "";
|
|
109
|
+
const session = sessions.get(sid);
|
|
110
|
+
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");
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
session.controller = controller;
|
|
114
|
+
let cancelled = false;
|
|
115
|
+
controller.signal.addEventListener("abort", () => {
|
|
116
|
+
cancelled = true;
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
session.agent ??= opts.newAgent(params?.cwd ?? opts.cwd);
|
|
120
|
+
await session.agent.run(text, (chunk) => update(sid, { sessionUpdate: "agent_message_chunk", content: { type: "text", text: chunk } }), controller.signal, ioFor(sid, session));
|
|
121
|
+
} catch (e) {
|
|
122
|
+
if (cancelled) return reply(id, { stopReason: "cancelled" });
|
|
123
|
+
return replyError(id, -32603, e.message);
|
|
124
|
+
} finally {
|
|
125
|
+
session.controller = null;
|
|
126
|
+
session.open = [];
|
|
127
|
+
}
|
|
128
|
+
return reply(id, { stopReason: cancelled ? "cancelled" : "end_turn" });
|
|
129
|
+
}
|
|
130
|
+
if (id !== void 0) return replyError(id, -32601, "Method not found");
|
|
131
|
+
};
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
let buf = "";
|
|
134
|
+
const onData = (chunk) => {
|
|
135
|
+
buf += chunk.toString();
|
|
136
|
+
let idx = buf.indexOf("\n");
|
|
137
|
+
while (idx >= 0) {
|
|
138
|
+
const line = buf.slice(0, idx);
|
|
139
|
+
buf = buf.slice(idx + 1);
|
|
140
|
+
idx = buf.indexOf("\n");
|
|
141
|
+
if (!line.trim()) continue;
|
|
142
|
+
let msg;
|
|
143
|
+
try {
|
|
144
|
+
msg = JSON.parse(line);
|
|
145
|
+
} catch {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
void handle(msg);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const onEnd = () => {
|
|
152
|
+
input.removeListener("data", onData);
|
|
153
|
+
resolve();
|
|
154
|
+
};
|
|
155
|
+
input.on("data", onData);
|
|
156
|
+
input.on("end", onEnd);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function runtimeAgent(cwd, allowAll = false) {
|
|
160
|
+
let rt;
|
|
161
|
+
return {
|
|
162
|
+
async run(text, onChunk, signal, io) {
|
|
163
|
+
if (!rt) {
|
|
164
|
+
const { parseCliArgs } = await import("./args-2R45YZ42.js");
|
|
165
|
+
const { createRuntime } = await import("./setup-LLWREJQH.js");
|
|
166
|
+
rt = createRuntime({ cwd, args: { ...parseCliArgs([]), allowAll } });
|
|
167
|
+
}
|
|
168
|
+
if (io && !allowAll) rt.agent.askPermission = (req) => io.askPermission(req);
|
|
169
|
+
rt.agent.onEvent = (event) => {
|
|
170
|
+
if (event.type === "text") onChunk(event.delta);
|
|
171
|
+
else if (event.type === "toolStart") io?.toolStart(event.id, event.tool, event.target);
|
|
172
|
+
else if (event.type === "toolEnd") io?.toolEnd(event.id, event.output, event.isError);
|
|
173
|
+
};
|
|
174
|
+
await rt.agent.run(text, signal);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
ACP_PROTOCOL_VERSION,
|
|
180
|
+
runAcp,
|
|
181
|
+
runtimeAgent
|
|
182
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
helpText,
|
|
4
|
+
parseCliArgs
|
|
5
|
+
} from "./chunk-FTFVW7XD.js";
|
|
6
|
+
import "./chunk-GAFJEQTJ.js";
|
|
7
|
+
import "./chunk-SNKVS26H.js";
|
|
8
|
+
import "./chunk-NDEJUL44.js";
|
|
9
|
+
import "./chunk-XLC6T4SX.js";
|
|
10
|
+
export {
|
|
11
|
+
helpText,
|
|
12
|
+
parseCliArgs
|
|
13
|
+
};
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
readCredentials,
|
|
6
6
|
readJsonConfig,
|
|
7
7
|
removeCredential
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NDEJUL44.js";
|
|
9
9
|
|
|
10
10
|
// src/providers.ts
|
|
11
11
|
import { mkdirSync, writeFileSync } from "fs";
|
|
@@ -45,6 +45,7 @@ function removeGlobalProvider(id, env = process.env) {
|
|
|
45
45
|
export {
|
|
46
46
|
providerName,
|
|
47
47
|
hasKey,
|
|
48
|
+
readGlobalConfigFile,
|
|
48
49
|
writeGlobalConfig,
|
|
49
50
|
removeGlobalProvider
|
|
50
51
|
};
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ConfigError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NDEJUL44.js";
|
|
5
|
+
import {
|
|
6
|
+
t
|
|
7
|
+
} from "./chunk-XLC6T4SX.js";
|
|
5
8
|
|
|
6
9
|
// src/mcp/catalog.ts
|
|
7
10
|
var CATALOG = [
|
|
8
|
-
{ name: "playwright", description: "
|
|
9
|
-
{ name: "context7", description: "
|
|
10
|
-
{ name: "fetch", description: "
|
|
11
|
+
{ name: "playwright", description: "control a browser (open pages, click, fill forms, screenshot)", config: { command: "npx", args: ["-y", "@playwright/mcp@latest"] } },
|
|
12
|
+
{ name: "context7", description: "up-to-date library documentation", config: { type: "http", url: "https://mcp.context7.com/mcp" } },
|
|
13
|
+
{ name: "fetch", description: "fetch web pages as markdown (needs uv)", config: { command: "uvx", args: ["mcp-server-fetch"] } },
|
|
11
14
|
{
|
|
12
15
|
name: "filesystem",
|
|
13
|
-
description: "
|
|
16
|
+
description: "access folders outside the project",
|
|
17
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: ${dir} is filled by fillTemplate, not a template literal
|
|
14
18
|
config: { command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", "${dir}"] },
|
|
15
|
-
inputs: [{ key: "dir", label: "Folder
|
|
19
|
+
inputs: [{ key: "dir", label: "Folder the server may access" }]
|
|
16
20
|
},
|
|
17
|
-
{ name: "git", description: "
|
|
21
|
+
{ name: "git", description: "structured git operations (needs uv)", config: { command: "uvx", args: ["mcp-server-git"] } },
|
|
18
22
|
{
|
|
19
23
|
name: "github",
|
|
20
|
-
description: "
|
|
24
|
+
description: "GitHub issues, PRs, and repos",
|
|
25
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: ${token} is filled by fillTemplate, not a template literal
|
|
21
26
|
config: { type: "http", url: "https://api.githubcopilot.com/mcp/", headers: { Authorization: "Bearer ${token}" } },
|
|
22
27
|
inputs: [{ key: "token", label: "GitHub Personal Access Token", secret: true }]
|
|
23
28
|
}
|
|
@@ -35,7 +40,7 @@ function fillTemplate(config, values) {
|
|
|
35
40
|
...config.args ? { args: config.args.map(fill) } : {},
|
|
36
41
|
...config.env ? { env: mapValues(config.env) } : {}
|
|
37
42
|
};
|
|
38
|
-
if (missing.size) throw new ConfigError(
|
|
43
|
+
if (missing.size) throw new ConfigError(t("Missing MCP fields: {fields}", { fields: [...missing].join(", ") }));
|
|
39
44
|
return out;
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/mcp/oauth.ts
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
6
|
+
import { createServer } from "http";
|
|
7
|
+
import { dirname, join } from "path";
|
|
8
|
+
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
9
|
+
var oauthStorePath = (home) => join(home, "mcp-oauth.json");
|
|
10
|
+
function readStore(home) {
|
|
11
|
+
const path = oauthStorePath(home);
|
|
12
|
+
if (!existsSync(path)) return {};
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function writeStore(home, store) {
|
|
20
|
+
const path = oauthStorePath(home);
|
|
21
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
22
|
+
writeFileSync(path, `${JSON.stringify(store, null, 2)}
|
|
23
|
+
`, { mode: 384 });
|
|
24
|
+
chmodSync(path, 384);
|
|
25
|
+
}
|
|
26
|
+
function hasStoredTokens(home, serverUrl) {
|
|
27
|
+
return Boolean(readStore(home)[serverUrl]?.tokens);
|
|
28
|
+
}
|
|
29
|
+
function clearTokens(home, serverUrl) {
|
|
30
|
+
const store = readStore(home);
|
|
31
|
+
const entry = store[serverUrl];
|
|
32
|
+
if (!entry?.tokens && !entry?.client && !entry?.codeVerifier && !entry?.discovery) return false;
|
|
33
|
+
delete store[serverUrl];
|
|
34
|
+
writeStore(home, store);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
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" });
|
|
40
|
+
child.unref();
|
|
41
|
+
child.on("error", () => {
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var FileOAuthProvider = class {
|
|
45
|
+
opts;
|
|
46
|
+
constructor(opts) {
|
|
47
|
+
this.opts = opts;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Always defined: MCP SDK treats a missing redirectUrl as a non-interactive
|
|
51
|
+
* (client_credentials) flow and would try a token exchange without a code.
|
|
52
|
+
*/
|
|
53
|
+
get redirectUrl() {
|
|
54
|
+
return this.opts.redirectUrl ?? "http://127.0.0.1:1/callback";
|
|
55
|
+
}
|
|
56
|
+
get clientMetadata() {
|
|
57
|
+
return {
|
|
58
|
+
client_name: "BCCLI",
|
|
59
|
+
redirect_uris: [String(this.redirectUrl)],
|
|
60
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
61
|
+
response_types: ["code"],
|
|
62
|
+
token_endpoint_auth_method: "none"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
entry() {
|
|
66
|
+
return readStore(this.opts.home)[this.opts.serverUrl] ?? {};
|
|
67
|
+
}
|
|
68
|
+
patch(patch) {
|
|
69
|
+
const store = readStore(this.opts.home);
|
|
70
|
+
const next = { ...store[this.opts.serverUrl], ...patch };
|
|
71
|
+
for (const key of Object.keys(next)) {
|
|
72
|
+
if (next[key] === void 0) delete next[key];
|
|
73
|
+
}
|
|
74
|
+
store[this.opts.serverUrl] = next;
|
|
75
|
+
if (Object.keys(next).length === 0) delete store[this.opts.serverUrl];
|
|
76
|
+
writeStore(this.opts.home, store);
|
|
77
|
+
}
|
|
78
|
+
clientInformation() {
|
|
79
|
+
return this.entry().client;
|
|
80
|
+
}
|
|
81
|
+
saveClientInformation(clientInformation) {
|
|
82
|
+
this.patch({ client: clientInformation });
|
|
83
|
+
}
|
|
84
|
+
tokens() {
|
|
85
|
+
return this.entry().tokens;
|
|
86
|
+
}
|
|
87
|
+
saveTokens(tokens) {
|
|
88
|
+
this.patch({ tokens });
|
|
89
|
+
}
|
|
90
|
+
saveCodeVerifier(codeVerifier) {
|
|
91
|
+
this.patch({ codeVerifier });
|
|
92
|
+
}
|
|
93
|
+
codeVerifier() {
|
|
94
|
+
return this.entry().codeVerifier ?? "";
|
|
95
|
+
}
|
|
96
|
+
redirectToAuthorization(authorizationUrl) {
|
|
97
|
+
return (this.opts.open ?? defaultOpen)(authorizationUrl);
|
|
98
|
+
}
|
|
99
|
+
saveDiscoveryState(state) {
|
|
100
|
+
this.patch({ discovery: state });
|
|
101
|
+
}
|
|
102
|
+
discoveryState() {
|
|
103
|
+
return this.entry().discovery;
|
|
104
|
+
}
|
|
105
|
+
invalidateCredentials(scope) {
|
|
106
|
+
if (scope === "all") {
|
|
107
|
+
this.patch({ client: void 0, tokens: void 0, codeVerifier: void 0, discovery: void 0 });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (scope === "client") this.patch({ client: void 0 });
|
|
111
|
+
if (scope === "tokens") this.patch({ tokens: void 0 });
|
|
112
|
+
if (scope === "verifier") this.patch({ codeVerifier: void 0 });
|
|
113
|
+
if (scope === "discovery") this.patch({ discovery: void 0 });
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
function parseCallback(input) {
|
|
117
|
+
const url = typeof input === "string" ? new URL(input) : input;
|
|
118
|
+
const error = url.searchParams.get("error");
|
|
119
|
+
if (error) {
|
|
120
|
+
const description = url.searchParams.get("error_description");
|
|
121
|
+
throw new Error(description ? `OAuth ${error}: ${description}` : `OAuth ${error}`);
|
|
122
|
+
}
|
|
123
|
+
const code = url.searchParams.get("code");
|
|
124
|
+
if (!code) throw new Error("OAuth callback is missing the code parameter.");
|
|
125
|
+
const state = url.searchParams.get("state") ?? void 0;
|
|
126
|
+
return { code, state };
|
|
127
|
+
}
|
|
128
|
+
var CALLBACK_TIMEOUT_MS = 18e4;
|
|
129
|
+
async function authorizeMcpServer(spec, deps) {
|
|
130
|
+
let settle;
|
|
131
|
+
const codeReceived = new Promise((resolve, reject) => {
|
|
132
|
+
settle = { resolve, reject };
|
|
133
|
+
});
|
|
134
|
+
codeReceived.catch(() => {
|
|
135
|
+
});
|
|
136
|
+
const server = createServer((req, res) => {
|
|
137
|
+
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
138
|
+
if (url.pathname !== "/callback") {
|
|
139
|
+
res.writeHead(404);
|
|
140
|
+
res.end();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const { code } = parseCallback(url);
|
|
145
|
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
146
|
+
res.end("<html><body><p>BCCLI is connected. You can close this tab.</p></body></html>");
|
|
147
|
+
settle.resolve(code);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
res.writeHead(400, { "content-type": "text/html; charset=utf-8" });
|
|
150
|
+
res.end(`<html><body><p>${error.message}</p></body></html>`);
|
|
151
|
+
settle.reject(error);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const port = await new Promise((resolve, reject) => {
|
|
155
|
+
server.once("error", reject);
|
|
156
|
+
server.listen(0, "127.0.0.1", () => {
|
|
157
|
+
const address = server.address();
|
|
158
|
+
resolve(typeof address === "object" && address ? address.port : 0);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
const provider = new FileOAuthProvider({
|
|
163
|
+
home: deps.home,
|
|
164
|
+
serverUrl: spec.config.url,
|
|
165
|
+
redirectUrl: `http://127.0.0.1:${port}/callback`,
|
|
166
|
+
open: deps.open
|
|
167
|
+
});
|
|
168
|
+
const serverUrl = new URL(spec.config.url);
|
|
169
|
+
const result = await auth(provider, { serverUrl, fetchFn: deps.fetchFn });
|
|
170
|
+
if (result === "AUTHORIZED") return;
|
|
171
|
+
const timer = setTimeout(() => settle.reject(new Error("Timed out waiting for the OAuth callback.")), CALLBACK_TIMEOUT_MS);
|
|
172
|
+
let code;
|
|
173
|
+
try {
|
|
174
|
+
code = await codeReceived;
|
|
175
|
+
} finally {
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
}
|
|
178
|
+
const second = await auth(provider, { serverUrl, authorizationCode: code, fetchFn: deps.fetchFn });
|
|
179
|
+
if (second !== "AUTHORIZED") throw new Error("OAuth authorization did not complete.");
|
|
180
|
+
} finally {
|
|
181
|
+
server.close();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export {
|
|
186
|
+
hasStoredTokens,
|
|
187
|
+
clearTokens,
|
|
188
|
+
defaultOpen,
|
|
189
|
+
FileOAuthProvider,
|
|
190
|
+
authorizeMcpServer
|
|
191
|
+
};
|