@botconnector/bccli 0.3.0-beta.3 → 0.4.0-beta.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.
- package/README.md +30 -1
- package/dist/{args-EVIFNGPQ.js → args-FCLPQ7TO.js} +3 -3
- package/dist/{chunk-5ISYVAXI.js → chunk-2JBRLGKD.js} +2 -2
- package/dist/{chunk-5XN44Q55.js → chunk-ELML4KVQ.js} +7 -1
- package/dist/{chunk-R37QWDTL.js → chunk-L7L4RGKG.js} +2 -2
- package/dist/{chunk-XQLXE666.js → chunk-NGLKANMD.js} +1 -1
- package/dist/chunk-OSWQPSA4.js +252 -0
- package/dist/{chunk-Z5JM76EL.js → chunk-RZUJYAQV.js} +2 -1
- package/dist/{chunk-5C6NQFSI.js → chunk-U7DLMVPZ.js} +1 -1
- package/dist/{chunk-TV6LEHOH.js → chunk-UESQNU4A.js} +1 -1
- package/dist/{chunk-RDQ7HPWS.js → chunk-UN7QXPCB.js} +2 -2
- package/dist/cli.js +119 -110
- package/dist/{config-XPWPGNZJ.js → config-NPSYFAFD.js} +2 -2
- package/dist/{login-WJMGVDRM.js → login-KHU7ONSR.js} +1 -1
- package/dist/{mcpCli-BV3IGR47.js → mcpCli-Q2H63ISP.js} +3 -3
- package/dist/{providerCli-SJRCBSRE.js → providerCli-G3X7KENO.js} +3 -3
- package/dist/{ui-HAW5NMFA.js → ui-A32PTF4F.js} +575 -162
- package/package.json +1 -1
- package/dist/chunk-TBPPXOOZ.js +0 -165
package/README.md
CHANGED
|
@@ -19,7 +19,36 @@ cd project-kamu && bccli
|
|
|
19
19
|
| `bccli -m provider/model` | pilih model |
|
|
20
20
|
| `bccli models` | daftar model |
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Perintah di dalam sesi (ketik `/` untuk saran, ↑↓ pilih, Enter jalankan):
|
|
23
|
+
|
|
24
|
+
| Perintah | Fungsi |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `/help` | daftar perintah dan pintasan |
|
|
27
|
+
| `/model` | ganti model |
|
|
28
|
+
| `/provider` | tambah/pilih provider AI |
|
|
29
|
+
| `/mcp` | pasang/kelola server MCP |
|
|
30
|
+
| `/new` | sesi baru (sesi lama tetap tersimpan) |
|
|
31
|
+
| `/resume` | lanjutkan sesi lain di folder ini |
|
|
32
|
+
| `/session` | info sesi ini |
|
|
33
|
+
| `/status` | versi, model, mode izin, MCP, konteks |
|
|
34
|
+
| `/permissions` | lihat/cabut izin |
|
|
35
|
+
| `/undo` | batalkan edit file giliran terakhir |
|
|
36
|
+
| `/diff` | git diff project |
|
|
37
|
+
| `/copy` | salin jawaban terakhir |
|
|
38
|
+
| `/export` | simpan percakapan ke markdown |
|
|
39
|
+
| `/memory` | instruksi project (/memory <teks>, /memory global <teks>) |
|
|
40
|
+
| `/init` | buat/perbarui AGENTS.md untuk project ini |
|
|
41
|
+
| `/agents` | daftar subagent |
|
|
42
|
+
| `/skills` | daftar skill dan perintah custom |
|
|
43
|
+
| `/doctor` | cek kesehatan instalasi |
|
|
44
|
+
| `/login` | simpan API key provider aktif |
|
|
45
|
+
| `/logout` | hapus API key provider aktif |
|
|
46
|
+
| `/clear` | mulai percakapan baru |
|
|
47
|
+
| `/compact` | ringkas percakapan |
|
|
48
|
+
| `/cost` | pemakaian token sesi ini |
|
|
49
|
+
| `/exit` | keluar |
|
|
50
|
+
|
|
51
|
+
`/undo` hanya membatalkan perubahan lewat alat edit/tulis (bukan perintah bash), per giliran, sampai 20 giliran ke belakang.
|
|
23
52
|
Shift+Tab ganti mode izin: `default` → `acceptEdits` → `plan` → `allowAll`.
|
|
24
53
|
|
|
25
54
|
Mode `-p` tidak pernah bertanya: alat yang butuh izin ditolak, kecuali memakai
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
HELP_TEXT,
|
|
4
4
|
parseCliArgs
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-UN7QXPCB.js";
|
|
6
|
+
import "./chunk-ELML4KVQ.js";
|
|
7
|
+
import "./chunk-RZUJYAQV.js";
|
|
8
8
|
export {
|
|
9
9
|
HELP_TEXT,
|
|
10
10
|
parseCliArgs
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
providerName,
|
|
5
5
|
removeGlobalProvider,
|
|
6
6
|
writeGlobalConfig
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-U7DLMVPZ.js";
|
|
8
8
|
import {
|
|
9
9
|
PRESETS,
|
|
10
10
|
loadConfig,
|
|
11
11
|
readCredentials,
|
|
12
12
|
saveCredential
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-RZUJYAQV.js";
|
|
14
14
|
|
|
15
15
|
// src/provider.ts
|
|
16
16
|
var ProviderError = class extends Error {
|
|
@@ -16,10 +16,12 @@ var Permissions = class {
|
|
|
16
16
|
this.mode = mode;
|
|
17
17
|
this.cwd = cwd;
|
|
18
18
|
this.rules = new Set(rules);
|
|
19
|
+
this.configRules = new Set(rules);
|
|
19
20
|
}
|
|
20
21
|
mode;
|
|
21
22
|
cwd;
|
|
22
23
|
rules;
|
|
24
|
+
configRules;
|
|
23
25
|
/** Edits may only be auto-allowed inside the project and outside .git. */
|
|
24
26
|
editInProject(target) {
|
|
25
27
|
const rel = relative(this.cwd, resolve(this.cwd, target));
|
|
@@ -55,8 +57,12 @@ var Permissions = class {
|
|
|
55
57
|
if (req.kind === "edit" && this.mode === "acceptEdits") return "allow";
|
|
56
58
|
return needed.every((rule) => this.rules.has(rule)) ? "allow" : "ask";
|
|
57
59
|
}
|
|
60
|
+
list() {
|
|
61
|
+
return [...this.rules].map((rule) => ({ rule, source: this.configRules.has(rule) ? "config" : "session" }));
|
|
62
|
+
}
|
|
63
|
+
/** Removes a session grant; rules from config/flags stay until the user edits them. */
|
|
58
64
|
revoke(rule) {
|
|
59
|
-
this.rules.delete(rule);
|
|
65
|
+
if (!this.configRules.has(rule)) this.rules.delete(rule);
|
|
60
66
|
}
|
|
61
67
|
allowForSession(req) {
|
|
62
68
|
for (const rule of this.rulesFor(req) ?? []) this.rules.add(rule);
|
|
@@ -35,8 +35,8 @@ function readSecret(prompt) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
async function runLogin(providerId, cwd) {
|
|
38
|
-
const { runProviderCommand } = await import("./providerCli-
|
|
39
|
-
const { parseCliArgs } = await import("./args-
|
|
38
|
+
const { runProviderCommand } = await import("./providerCli-G3X7KENO.js");
|
|
39
|
+
const { parseCliArgs } = await import("./args-FCLPQ7TO.js");
|
|
40
40
|
return runProviderCommand(parseCliArgs(["provider", "add", providerId]), {
|
|
41
41
|
env: process.env,
|
|
42
42
|
cwd,
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/print.ts
|
|
4
|
+
function toolLabel(tool) {
|
|
5
|
+
return tool.charAt(0).toUpperCase() + tool.slice(1);
|
|
6
|
+
}
|
|
7
|
+
async function runPrint(rt, prompt, io = { out: process.stdout, err: process.stderr }, opts = {}) {
|
|
8
|
+
rt.interaction.approvePlan = async () => {
|
|
9
|
+
if (opts.allowAll) return "allowAll";
|
|
10
|
+
io.err.write("Rencana butuh persetujuan; jalankan dengan --allow-all.\n");
|
|
11
|
+
return "no";
|
|
12
|
+
};
|
|
13
|
+
let failed = false;
|
|
14
|
+
let wroteText = false;
|
|
15
|
+
rt.agent.onEvent = (event) => {
|
|
16
|
+
switch (event.type) {
|
|
17
|
+
case "text":
|
|
18
|
+
io.out.write(event.delta);
|
|
19
|
+
wroteText = true;
|
|
20
|
+
break;
|
|
21
|
+
case "toolStart":
|
|
22
|
+
io.err.write(`\u23BF ${toolLabel(event.tool)} ${event.target}
|
|
23
|
+
`);
|
|
24
|
+
break;
|
|
25
|
+
case "toolEnd":
|
|
26
|
+
if (event.isError) io.err.write(` \u2717 ${event.output.split("\n")[0]}
|
|
27
|
+
`);
|
|
28
|
+
break;
|
|
29
|
+
case "stepLimit":
|
|
30
|
+
io.err.write("Batas langkah tercapai.\n");
|
|
31
|
+
failed = true;
|
|
32
|
+
break;
|
|
33
|
+
case "aborted":
|
|
34
|
+
io.err.write("Dibatalkan.\n");
|
|
35
|
+
failed = true;
|
|
36
|
+
break;
|
|
37
|
+
case "error":
|
|
38
|
+
io.err.write(`Error: ${event.message}
|
|
39
|
+
`);
|
|
40
|
+
failed = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
rt.agent.askPermission = async (req) => {
|
|
45
|
+
io.err.write(` Butuh izin untuk ${req.tool}. Jalankan dengan --allow-all atau --allowed-tools ${req.kind}.
|
|
46
|
+
`);
|
|
47
|
+
return "no";
|
|
48
|
+
};
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const onSigint = () => controller.abort();
|
|
51
|
+
process.once("SIGINT", onSigint);
|
|
52
|
+
try {
|
|
53
|
+
await rt.agent.run(prompt, controller.signal);
|
|
54
|
+
} finally {
|
|
55
|
+
process.off("SIGINT", onSigint);
|
|
56
|
+
}
|
|
57
|
+
if (wroteText) io.out.write("\n");
|
|
58
|
+
return failed ? 1 : 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/agents.ts
|
|
62
|
+
var 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.";
|
|
63
|
+
var 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.";
|
|
64
|
+
var BUILTIN_AGENTS = [
|
|
65
|
+
{
|
|
66
|
+
name: "explore",
|
|
67
|
+
description: "Read-only: search and read code to answer a question (fast, safe, can run in parallel).",
|
|
68
|
+
tools: ["read", "grep", "glob"],
|
|
69
|
+
prompt: EXPLORE_PROMPT,
|
|
70
|
+
maxSteps: 30
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "general",
|
|
74
|
+
description: "Full tools: carry out a self-contained sub-task (edits and commands still need user permission).",
|
|
75
|
+
prompt: GENERAL_PROMPT,
|
|
76
|
+
maxSteps: 50
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
// src/context.ts
|
|
81
|
+
import { existsSync, readFileSync } from "fs";
|
|
82
|
+
import { dirname, join } from "path";
|
|
83
|
+
var FILES = ["AGENTS.md", "BCCLI.md"];
|
|
84
|
+
function readIf(path) {
|
|
85
|
+
try {
|
|
86
|
+
return existsSync(path) ? readFileSync(path, "utf8").trim() : void 0;
|
|
87
|
+
} catch {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function instructionPaths(cwd, home) {
|
|
92
|
+
const dirs2 = [];
|
|
93
|
+
for (let dir = cwd; ; dir = dirname(dir)) {
|
|
94
|
+
dirs2.unshift(dir);
|
|
95
|
+
if (dirname(dir) === dir) break;
|
|
96
|
+
}
|
|
97
|
+
return [join(home, "BCCLI.md"), ...dirs2.flatMap((dir) => FILES.map((name) => join(dir, name)))];
|
|
98
|
+
}
|
|
99
|
+
function loadInstructions(cwd, home) {
|
|
100
|
+
const parts = [];
|
|
101
|
+
for (const path of instructionPaths(cwd, home)) {
|
|
102
|
+
const text = readIf(path);
|
|
103
|
+
if (text) parts.push(`# ${path}
|
|
104
|
+
${text}`);
|
|
105
|
+
}
|
|
106
|
+
return parts.join("\n\n");
|
|
107
|
+
}
|
|
108
|
+
function isGitRepo(cwd) {
|
|
109
|
+
for (let dir = cwd; ; dir = dirname(dir)) {
|
|
110
|
+
if (existsSync(join(dir, ".git"))) return true;
|
|
111
|
+
if (dirname(dir) === dir) return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function buildSystemPrompt(opts) {
|
|
115
|
+
const instructions = loadInstructions(opts.cwd, opts.home);
|
|
116
|
+
const skills = (opts.skills ?? []).slice(0, 50);
|
|
117
|
+
const skillText = skills.length ? `
|
|
118
|
+
|
|
119
|
+
Skills (load one with the skill tool when it matches the task):
|
|
120
|
+
${skills.map((s) => `- ${s.name}: ${s.description.slice(0, 200)}`).join("\n")}` : "";
|
|
121
|
+
return `You are BCCLI, a coding agent by BotConnector running in the user's terminal. You help with software engineering tasks by reading code, editing files, and running commands with the tools provided.
|
|
122
|
+
|
|
123
|
+
How to work:
|
|
124
|
+
- Understand before changing: read the relevant files and search the codebase first. Never guess file contents.
|
|
125
|
+
- Always read a file before editing it. Make the smallest correct change; match the existing style.
|
|
126
|
+
- For tasks with 3 or more steps, keep a todo list with todo_write and update it as you go.
|
|
127
|
+
- In plan mode you can only read and search. When the plan is ready, call exit_plan with it and wait for approval.
|
|
128
|
+
- Verify your work: run the tests, build or the command that proves the change works, and report the real result.
|
|
129
|
+
- The user must approve edits and commands. If they decline, ask what they want instead of retrying.
|
|
130
|
+
- Be concise. Reply in the user's language. No preamble; lead with the answer or the action.
|
|
131
|
+
- Never expose secrets, never run destructive commands (rm -rf, force push, dropping data) unless the user explicitly asks.
|
|
132
|
+
|
|
133
|
+
Environment:
|
|
134
|
+
- Working directory: ${opts.cwd}
|
|
135
|
+
- Git repository: ${isGitRepo(opts.cwd) ? "yes" : "no"}
|
|
136
|
+
- Platform: ${opts.platform ?? process.platform}
|
|
137
|
+
- Date: ${opts.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}
|
|
138
|
+
- Model: ${opts.model}${skillText}${instructions ? `
|
|
139
|
+
|
|
140
|
+
Project and user instructions (follow them):
|
|
141
|
+
|
|
142
|
+
${instructions}` : ""}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/extensions.ts
|
|
146
|
+
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
|
|
147
|
+
import { basename, join as join2 } from "path";
|
|
148
|
+
function parseFrontmatter(text) {
|
|
149
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
|
|
150
|
+
if (!match) return { data: {}, body: text };
|
|
151
|
+
const data = {};
|
|
152
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
153
|
+
const kv = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
|
|
154
|
+
if (!kv) continue;
|
|
155
|
+
let value = kv[2].trim();
|
|
156
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
157
|
+
data[kv[1]] = value.slice(1, -1).split(",").map((s) => s.trim().replace(/^["']|["']$/g, "")).filter(Boolean);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (/^(["']).*\1$/.test(value)) value = value.slice(1, -1);
|
|
161
|
+
data[kv[1]] = value;
|
|
162
|
+
}
|
|
163
|
+
return { data, body: text.slice(match[0].length) };
|
|
164
|
+
}
|
|
165
|
+
var str = (v) => Array.isArray(v) ? v.join(", ") : v;
|
|
166
|
+
function dirs(r, kind) {
|
|
167
|
+
return [join2(r.userHome, ".claude", kind), join2(r.home, kind), join2(r.cwd, ".claude", kind), join2(r.cwd, ".bccli", kind)];
|
|
168
|
+
}
|
|
169
|
+
function list(dir) {
|
|
170
|
+
try {
|
|
171
|
+
return readdirSync(dir).sort();
|
|
172
|
+
} catch {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function loadSkills(r) {
|
|
177
|
+
const byName = /* @__PURE__ */ new Map();
|
|
178
|
+
for (const dir of dirs(r, "skills")) {
|
|
179
|
+
for (const entry of list(dir)) {
|
|
180
|
+
const file = join2(dir, entry, "SKILL.md");
|
|
181
|
+
if (!existsSync2(file)) continue;
|
|
182
|
+
const { data } = parseFrontmatter(readFileSync2(file, "utf8"));
|
|
183
|
+
const name = str(data.name) || entry;
|
|
184
|
+
byName.set(name, { name, description: str(data.description) ?? "", dir: join2(dir, entry), file });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return [...byName.values()];
|
|
188
|
+
}
|
|
189
|
+
function loadCommands(r) {
|
|
190
|
+
const byName = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const dir of dirs(r, "commands")) {
|
|
192
|
+
for (const entry of list(dir)) {
|
|
193
|
+
const file = join2(dir, entry);
|
|
194
|
+
if (!entry.endsWith(".md") || !statSync(file).isFile()) continue;
|
|
195
|
+
const { data, body } = parseFrontmatter(readFileSync2(file, "utf8"));
|
|
196
|
+
const def = { name: basename(entry, ".md"), body: body.trim() };
|
|
197
|
+
if (data.description) def.description = str(data.description);
|
|
198
|
+
if (data["argument-hint"]) def.argumentHint = str(data["argument-hint"]);
|
|
199
|
+
byName.set(def.name, def);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return [...byName.values()];
|
|
203
|
+
}
|
|
204
|
+
function loadAgentDefs(r) {
|
|
205
|
+
const byName = /* @__PURE__ */ new Map();
|
|
206
|
+
for (const dir of dirs(r, "agents")) {
|
|
207
|
+
for (const entry of list(dir)) {
|
|
208
|
+
if (!entry.endsWith(".md")) continue;
|
|
209
|
+
const { data, body } = parseFrontmatter(readFileSync2(join2(dir, entry), "utf8"));
|
|
210
|
+
const name = str(data.name) || basename(entry, ".md");
|
|
211
|
+
const def = { name, description: str(data.description) ?? "", prompt: body.trim() };
|
|
212
|
+
if (data.tools)
|
|
213
|
+
def.tools = Array.isArray(data.tools) ? data.tools : String(data.tools).split(",").map((s) => s.trim()).filter(Boolean);
|
|
214
|
+
if (data.model) def.model = str(data.model);
|
|
215
|
+
byName.set(name, def);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return [...byName.values()];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/tools/ignore.ts
|
|
222
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
223
|
+
import { join as join3 } from "path";
|
|
224
|
+
function ignorePatterns(root) {
|
|
225
|
+
const patterns = ["**/node_modules/**", "**/.git/**"];
|
|
226
|
+
let lines = [];
|
|
227
|
+
try {
|
|
228
|
+
lines = readFileSync3(join3(root, ".gitignore"), "utf8").split(/\r?\n/);
|
|
229
|
+
} catch {
|
|
230
|
+
return patterns;
|
|
231
|
+
}
|
|
232
|
+
for (const raw of lines) {
|
|
233
|
+
const line = raw.trim();
|
|
234
|
+
if (!line || line.startsWith("#") || line.startsWith("!")) continue;
|
|
235
|
+
const p = line.replace(/^\//, "").replace(/\/$/, "");
|
|
236
|
+
patterns.push(`**/${p}`, `**/${p}/**`);
|
|
237
|
+
}
|
|
238
|
+
return patterns;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
toolLabel,
|
|
243
|
+
runPrint,
|
|
244
|
+
ignorePatterns,
|
|
245
|
+
BUILTIN_AGENTS,
|
|
246
|
+
instructionPaths,
|
|
247
|
+
buildSystemPrompt,
|
|
248
|
+
parseFrontmatter,
|
|
249
|
+
loadSkills,
|
|
250
|
+
loadCommands,
|
|
251
|
+
loadAgentDefs
|
|
252
|
+
};
|
|
@@ -91,11 +91,12 @@ function resolveModel(config, modelRef, env = process.env) {
|
|
|
91
91
|
}
|
|
92
92
|
function removeCredential(providerId, env = process.env) {
|
|
93
93
|
const creds = readCredentials(env);
|
|
94
|
-
if (!(providerId in creds)) return;
|
|
94
|
+
if (!(providerId in creds)) return false;
|
|
95
95
|
delete creds[providerId];
|
|
96
96
|
const path = join(bccliHome(env), "credentials");
|
|
97
97
|
writeFileSync(path, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
98
98
|
chmodSync(path, 384);
|
|
99
|
+
return true;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
export {
|