@botconnector/bccli 0.4.0-beta.4 → 0.4.0-beta.41

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 (46) hide show
  1. package/README.md +80 -1
  2. package/dist/acp-SZWZ5EE4.js +114 -0
  3. package/dist/args-4SMOHFN5.js +13 -0
  4. package/dist/chunk-3HCOAJEQ.js +190 -0
  5. package/dist/chunk-AS7VV7D3.js +195 -0
  6. package/dist/{chunk-NGLKANMD.js → chunk-AVB6M4JE.js} +24 -2
  7. package/dist/chunk-BUHWQU3V.js +231 -0
  8. package/dist/chunk-DBHDZ5EP.js +723 -0
  9. package/dist/{chunk-GW36UMHZ.js → chunk-DSFHN5CH.js} +2 -2
  10. package/dist/chunk-EQQTTE2K.js +8 -0
  11. package/dist/{chunk-ELML4KVQ.js → chunk-GAFJEQTJ.js} +32 -2
  12. package/dist/chunk-GGNXHJL6.js +884 -0
  13. package/dist/chunk-HE33XAPZ.js +341 -0
  14. package/dist/{chunk-UESQNU4A.js → chunk-ISCT3PN3.js} +14 -9
  15. package/dist/chunk-JROUQ5YS.js +76 -0
  16. package/dist/chunk-LN32JIZR.js +56 -0
  17. package/dist/chunk-M23QBX3V.js +419 -0
  18. package/dist/chunk-M4IYXI3V.js +2125 -0
  19. package/dist/chunk-M7LLJQ7M.js +310 -0
  20. package/dist/chunk-NI5JZUZ3.js +63 -0
  21. package/dist/chunk-PSO7R5AD.js +10 -0
  22. package/dist/{chunk-U7DLMVPZ.js → chunk-SESBH44L.js} +2 -1
  23. package/dist/{chunk-SJH3YLW4.js → chunk-VM7HYAJS.js} +4 -1
  24. package/dist/cli.js +94 -1278
  25. package/dist/{config-NPSYFAFD.js → config-C4KLLDC6.js} +5 -2
  26. package/dist/integrationCli-HR7CDUSI.js +685 -0
  27. package/dist/{login-F4G5QXOU.js → login-T5S6SPZA.js} +1 -1
  28. package/dist/{mcpCli-Q2H63ISP.js → mcpCli-5QTXH7XJ.js} +42 -9
  29. package/dist/modelsCli-DKTT3UZD.js +36 -0
  30. package/dist/providerCli-DDH4ZZUY.js +15 -0
  31. package/dist/sdk.js +5179 -0
  32. package/dist/serve-I2VQUTHR.js +178 -0
  33. package/dist/serve-KQ35P4W3.js +514 -0
  34. package/dist/session-H2YL5RSB.js +12 -0
  35. package/dist/setup-45WQXUBK.js +23 -0
  36. package/dist/ui-S4QFJJIB.js +2280 -0
  37. package/dist/update-VBDEHHMR.js +109 -0
  38. package/package.json +24 -3
  39. package/dist/args-FCLPQ7TO.js +0 -11
  40. package/dist/chunk-C5AFWX7H.js +0 -328
  41. package/dist/chunk-OSWQPSA4.js +0 -252
  42. package/dist/chunk-RZUJYAQV.js +0 -112
  43. package/dist/chunk-UN7QXPCB.js +0 -82
  44. package/dist/providerCli-MXV6PD6F.js +0 -11
  45. package/dist/session-7UB77CEG.js +0 -9
  46. package/dist/ui-7FXPXXGN.js +0 -1333
@@ -1,12 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  ConfigError
4
- } from "./chunk-RZUJYAQV.js";
4
+ } from "./chunk-M7LLJQ7M.js";
5
+ import {
6
+ t
7
+ } from "./chunk-M23QBX3V.js";
5
8
 
6
9
  // src/mcp/config.ts
7
10
  import { createHash } from "crypto";
8
11
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
9
12
  import { dirname, join, resolve } from "path";
13
+ var ENV_REF = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
14
+ function expandEnvVars(config, env) {
15
+ const expand = (value) => value.replace(ENV_REF, (match, name, fallback) => {
16
+ const resolved = env[name];
17
+ if (resolved !== void 0) return resolved;
18
+ return fallback !== void 0 ? fallback : match;
19
+ });
20
+ const expandMap = (map) => Object.fromEntries(Object.entries(map).map(([k, v]) => [k, expand(v)]));
21
+ if (config.type === "http") {
22
+ return { ...config, url: expand(config.url), ...config.headers ? { headers: expandMap(config.headers) } : {} };
23
+ }
24
+ return {
25
+ ...config,
26
+ command: expand(config.command),
27
+ ...config.args ? { args: config.args.map(expand) } : {},
28
+ ...config.env ? { env: expandMap(config.env) } : {}
29
+ };
30
+ }
10
31
  var globalMcpPath = (home) => join(home, "mcp.json");
11
32
  var projectMcpPath = (cwd) => join(cwd, ".bccli", "mcp.json");
12
33
  var trustPath = (home) => join(home, "trusted-mcp.json");
@@ -15,7 +36,7 @@ function readJson(path, fallback) {
15
36
  try {
16
37
  return JSON.parse(readFileSync(path, "utf8"));
17
38
  } catch (error) {
18
- throw new ConfigError(`File MCP tidak valid: ${path} (${error.message})`);
39
+ throw new ConfigError(t("Invalid MCP file: {path} ({error})", { path, error: error.message }));
19
40
  }
20
41
  }
21
42
  function writePrivate(path, data) {
@@ -58,6 +79,7 @@ function serversToStart(home, cwd) {
58
79
  }
59
80
 
60
81
  export {
82
+ expandEnvVars,
61
83
  globalMcpPath,
62
84
  projectMcpPath,
63
85
  readMcpFile,
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ runCommand,
4
+ runHooks
5
+ } from "./chunk-DBHDZ5EP.js";
6
+ import {
7
+ ConfigError
8
+ } from "./chunk-M7LLJQ7M.js";
9
+ import {
10
+ t
11
+ } from "./chunk-M23QBX3V.js";
12
+
13
+ // src/verify.ts
14
+ var MAX_VERIFY_ROUNDS = 2;
15
+ async function runVerify(commands, opts) {
16
+ const run = opts.run ?? runCommand;
17
+ const failures = [];
18
+ for (const cmd of commands) {
19
+ const r = await run(cmd, { cwd: opts.cwd, timeoutMs: opts.timeoutMs ?? 3e5, signal: opts.signal, env: opts.env });
20
+ const exitCode = r.exitCode ?? -1;
21
+ if (exitCode !== 0) failures.push({ cmd, exitCode, output: r.output });
22
+ }
23
+ return failures;
24
+ }
25
+ function verifyFollowup(failures, maxBytes = 8e3) {
26
+ const blocks = failures.map((f) => {
27
+ const output = f.output.length > maxBytes ? `${f.output.slice(0, maxBytes)}
28
+ [truncated]` : f.output;
29
+ return `$ ${f.cmd}
30
+ [exit code ${f.exitCode}]
31
+ ${output}`;
32
+ });
33
+ return t("Automatic verification after your edits failed. Fix the problems so these commands pass, then stop.\n\n{blocks}", {
34
+ blocks: blocks.join("\n\n")
35
+ });
36
+ }
37
+
38
+ // src/print.ts
39
+ function toolLabel(tool) {
40
+ if (tool === "web_search") return "Search";
41
+ return tool.charAt(0).toUpperCase() + tool.slice(1);
42
+ }
43
+ async function runPrint(rt, prompt, io = { out: process.stdout, err: process.stderr }, opts = {}) {
44
+ const format = opts.outputFormat ?? "text";
45
+ const emit = (line) => io.out.write(`${JSON.stringify(line)}
46
+ `);
47
+ let result = "";
48
+ const toolNames = /* @__PURE__ */ new Map();
49
+ rt.interaction.approvePlan = async () => {
50
+ if (opts.allowAll) return "allowAll";
51
+ io.err.write(`${t("Plan needs approval; run with --allow-all.")}
52
+ `);
53
+ return "no";
54
+ };
55
+ let failed = false;
56
+ let wroteText = false;
57
+ let edited = false;
58
+ rt.agent.onEvent = (event) => {
59
+ switch (event.type) {
60
+ case "text":
61
+ if (format === "text") {
62
+ io.out.write(event.delta);
63
+ wroteText = true;
64
+ } else {
65
+ result += event.delta;
66
+ }
67
+ break;
68
+ case "toolStart":
69
+ toolNames.set(event.id, event.tool);
70
+ io.err.write(`\u23BF ${toolLabel(event.tool)} ${event.target}
71
+ `);
72
+ if (format === "stream-json") emit({ type: "tool_use", tool: event.tool, target: event.target });
73
+ break;
74
+ case "toolEnd":
75
+ if (event.isError) io.err.write(` \u2717 ${event.output.split("\n")[0]}
76
+ `);
77
+ if ((event.tool === "edit" || event.tool === "write") && !event.isError) edited = true;
78
+ if (format === "stream-json") emit({ type: "tool_result", tool: toolNames.get(event.id), isError: !!event.isError, output: event.output });
79
+ break;
80
+ case "stepLimit":
81
+ io.err.write(`${t("Step limit reached.")}
82
+ `);
83
+ failed = true;
84
+ break;
85
+ case "budgetExceeded":
86
+ io.err.write(`${t("Budget exceeded ({kind}): {used} of {limit}. Further model calls are blocked; raise usageCap in ~/.bccli/config.json.", { kind: event.kind, used: Math.round(event.used * 100) / 100, limit: event.limit })}
87
+ `);
88
+ if (format === "stream-json") emit({ type: "error", message: "budgetExceeded" });
89
+ failed = true;
90
+ break;
91
+ case "aborted":
92
+ io.err.write(`${t("Cancelled.")}
93
+ `);
94
+ failed = true;
95
+ break;
96
+ case "error":
97
+ io.err.write(`Error: ${event.message}
98
+ `);
99
+ if (format === "stream-json") emit({ type: "error", message: event.message });
100
+ failed = true;
101
+ break;
102
+ }
103
+ };
104
+ rt.agent.askPermission = async (req) => {
105
+ io.err.write(` ${t("Needs permission for {tool}. Run with --allow-all or --allowed-tools {kind}.", { tool: req.tool, kind: req.kind })}
106
+ `);
107
+ return "no";
108
+ };
109
+ const controller = new AbortController();
110
+ const onSigint = () => controller.abort();
111
+ process.once("SIGINT", onSigint);
112
+ const start = await runHooks(rt.config.hooks, "SessionStart", {}, { env: rt.env, cwd: rt.cwd });
113
+ for (const warning of start.warnings) io.err.write(`${warning}
114
+ `);
115
+ await rt.emitPlugins("SessionStart");
116
+ try {
117
+ await rt.agent.run(prompt, controller.signal);
118
+ const commands = rt.config.verifyCommands;
119
+ if (edited && commands.length && !controller.signal.aborted) {
120
+ for (let round = 0; round < MAX_VERIFY_ROUNDS; round++) {
121
+ io.err.write(`${t("Verifying edits: {cmds}", { cmds: commands.join(", ") })}
122
+ `);
123
+ const failures = await runVerify(commands, { cwd: rt.cwd, env: rt.env, signal: controller.signal });
124
+ if (!failures.length) {
125
+ io.err.write(`${t("Verification passed.")}
126
+ `);
127
+ break;
128
+ }
129
+ if (round === MAX_VERIFY_ROUNDS - 1 || controller.signal.aborted) {
130
+ io.err.write(`${t("Verification still failing after {n} fix round(s). Run the commands manually to see why.", { n: MAX_VERIFY_ROUNDS })}
131
+ `);
132
+ failed = true;
133
+ break;
134
+ }
135
+ await rt.agent.run(verifyFollowup(failures), controller.signal);
136
+ }
137
+ }
138
+ } finally {
139
+ process.off("SIGINT", onSigint);
140
+ }
141
+ const stop = await runHooks(rt.config.hooks, "Stop", {}, { env: rt.env, cwd: rt.cwd });
142
+ for (const warning of stop.warnings) io.err.write(`${warning}
143
+ `);
144
+ await rt.emitPlugins("Stop");
145
+ if (format === "json") {
146
+ io.out.write(`${JSON.stringify({ status: failed ? "failed" : "ok", model: rt.modelRef, result })}
147
+ `);
148
+ } else if (format === "stream-json") {
149
+ if (result) emit({ type: "message", text: result });
150
+ emit({ type: "result", status: failed ? "failed" : "ok", model: rt.modelRef });
151
+ } else if (wroteText) {
152
+ io.out.write("\n");
153
+ }
154
+ return failed ? 1 : 0;
155
+ }
156
+
157
+ // src/worktree.ts
158
+ import { execFile } from "child_process";
159
+ import { existsSync } from "fs";
160
+ import { basename, dirname, join } from "path";
161
+ function git(cwd, args, bin = "git") {
162
+ return new Promise((resolve) => {
163
+ execFile(
164
+ bin,
165
+ args,
166
+ { cwd, maxBuffer: 20 * 1024 * 1024 },
167
+ (error, stdout, stderr) => resolve({ ok: !error, out: error ? stderr : stdout, missing: error?.code === "ENOENT" })
168
+ );
169
+ });
170
+ }
171
+ var NAME_RE = /^[A-Za-z0-9._-]+$/;
172
+ function samePath(a, b) {
173
+ const norm = (p) => process.platform === "win32" ? p.replace(/\//g, "\\").toLowerCase() : p.replace(/\\/g, "/");
174
+ return norm(a) === norm(b);
175
+ }
176
+ function worktreeEntries(porcelain) {
177
+ return porcelain.split(/\r?\n\r?\n/).map((block) => {
178
+ const path = /^worktree (.+)$/m.exec(block)?.[1]?.trim();
179
+ if (!path) return void 0;
180
+ const branch = /^branch refs\/heads\/(.+)$/m.exec(block)?.[1];
181
+ return branch ? { path, branch } : { path };
182
+ }).filter((entry) => !!entry);
183
+ }
184
+ async function resolveWorktree(cwd, name, bin = "git") {
185
+ if (!NAME_RE.test(name)) {
186
+ throw new ConfigError(t('Invalid worktree name "{name}": use letters, digits, dot, dash, or underscore (no slashes).', { name }));
187
+ }
188
+ const inside = await git(cwd, ["rev-parse", "--is-inside-work-tree"], bin);
189
+ if (inside.missing) throw new ConfigError(t("git is not installed or not on PATH, so -w cannot be used."));
190
+ if (!inside.ok || inside.out.trim() !== "true") throw new ConfigError(t("This folder is not a git repository, so -w cannot create a worktree."));
191
+ const list = await git(cwd, ["worktree", "list", "--porcelain"], bin);
192
+ if (!list.ok) throw new ConfigError(t("This folder is not a git repository, so -w cannot create a worktree."));
193
+ const entries = worktreeEntries(list.out);
194
+ const main = entries[0]?.path;
195
+ if (!main) throw new ConfigError(t("This folder is not a git repository, so -w cannot create a worktree."));
196
+ const path = join(dirname(main), `${basename(main)}.worktrees`, name);
197
+ if (entries.some((entry) => samePath(entry.path, path))) return { path, created: false };
198
+ if (existsSync(path)) {
199
+ throw new ConfigError(t("Worktree path {path} already exists but is not a registered worktree; remove or rename it first.", { path }));
200
+ }
201
+ const branch = `bccli/${name}`;
202
+ const hasBranch = (await git(main, ["rev-parse", "--verify", "-q", `refs/heads/${branch}`], bin)).ok;
203
+ const add = hasBranch ? await git(main, ["worktree", "add", path, branch], bin) : await git(main, ["worktree", "add", "-b", branch, path], bin);
204
+ if (!add.ok) throw new ConfigError(add.out.trim() || t("This folder is not a git repository, so -w cannot create a worktree."));
205
+ return { path, created: true };
206
+ }
207
+ async function worktreeListText(cwd, bin = "git") {
208
+ const inside = await git(cwd, ["rev-parse", "--is-inside-work-tree"], bin);
209
+ if (inside.missing) return t("git is not installed or not on PATH, so /worktree cannot be used.");
210
+ if (!inside.ok || inside.out.trim() !== "true") return t("This folder is not a git repository, so there is no diff.");
211
+ const list = await git(cwd, ["worktree", "list", "--porcelain"], bin);
212
+ if (!list.ok) return t("This folder is not a git repository, so there is no diff.");
213
+ const rows = worktreeEntries(list.out).map((entry) => ` ${entry.path}${entry.branch ? ` (${entry.branch})` : ""}`);
214
+ return [
215
+ t("Git worktrees:"),
216
+ ...rows,
217
+ "",
218
+ t("Create one with: bccli -w <name>"),
219
+ t("Remove with: git worktree remove <path>")
220
+ ].join("\n");
221
+ }
222
+
223
+ export {
224
+ MAX_VERIFY_ROUNDS,
225
+ runVerify,
226
+ verifyFollowup,
227
+ toolLabel,
228
+ runPrint,
229
+ resolveWorktree,
230
+ worktreeListText
231
+ };