@botconnector/bccli 0.1.0-beta.3 → 0.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/chunk-SJH3YLW4.js +92 -0
- package/dist/chunk-WZYWKWPD.js +142 -0
- package/dist/cli.js +1156 -0
- package/dist/session-7UB77CEG.js +9 -0
- package/dist/ui-U6OMOINK.js +506 -0
- package/package.json +26 -22
- package/bin/bccli.js +0 -173
- package/default-config/botconnector-cloud.jsonc +0 -21
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BotConnector
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# BCCLI
|
|
2
|
+
|
|
3
|
+
Agent AI coding dari BotConnector yang bekerja di terminal: membaca kode, mengedit file,
|
|
4
|
+
dan menjalankan perintah — dengan izin kamu.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm i -g @botconnector/bccli@next # v0.2 beta, butuh Node.js 22+
|
|
8
|
+
bccli login # simpan API key BotConnector Cloud
|
|
9
|
+
cd project-kamu && bccli
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Pemakaian
|
|
13
|
+
|
|
14
|
+
| Perintah | Fungsi |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `bccli` | mode interaktif |
|
|
17
|
+
| `bccli -p "tugas"` | satu tugas tanpa interaksi (skrip/CI) |
|
|
18
|
+
| `bccli -c` / `bccli -r` | lanjutkan sesi terakhir / pilih sesi |
|
|
19
|
+
| `bccli -m provider/model` | pilih model |
|
|
20
|
+
| `bccli models` | daftar model |
|
|
21
|
+
|
|
22
|
+
Di dalam sesi: `/help`, `/model`, `/clear`, `/compact`, `/cost`, `/exit`.
|
|
23
|
+
Shift+Tab ganti mode izin: `default` → `acceptEdits` → `plan` → `allowAll`.
|
|
24
|
+
|
|
25
|
+
Mode `-p` tidak pernah bertanya: alat yang butuh izin ditolak, kecuali memakai
|
|
26
|
+
`--allow-all` atau `--allowed-tools bash,edit,fetch`.
|
|
27
|
+
|
|
28
|
+
## Provider lain (OpenAI-compatible)
|
|
29
|
+
|
|
30
|
+
`~/.bccli/config.json`:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"model": "openrouter/qwen/qwen3-coder",
|
|
35
|
+
"providers": {
|
|
36
|
+
"openrouter": { "baseURL": "https://openrouter.ai/api/v1", "apiKeyEnv": "OPENROUTER_API_KEY" },
|
|
37
|
+
"local": { "baseURL": "http://127.0.0.1:11434/v1" }
|
|
38
|
+
},
|
|
39
|
+
"allow": ["bash(npm test)"]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`.bccli/config.json` di dalam project hanya boleh memilih `model` dan menambah provider baru tanpa API key —
|
|
44
|
+
izin (`permissionMode`, `allow`) dan provider yang sudah ada hanya diatur dari `~/.bccli/config.json`,
|
|
45
|
+
supaya repo yang kamu clone tidak bisa memberi dirinya izin penuh atau mencuri API key.
|
|
46
|
+
|
|
47
|
+
Instruksi project dibaca dari `AGENTS.md` dan `BCCLI.md`.
|
|
48
|
+
|
|
49
|
+
## Pengembangan
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install
|
|
53
|
+
npm test && npm run typecheck && npm run lint && npm run build
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
CI (`ci.yml`) menjalankan hal yang sama di Linux, macOS, dan Windows.
|
|
57
|
+
Rilis: naikkan `version` di `package.json`, lalu push tag `v<version>` — `release.yml`
|
|
58
|
+
menjalankan test, smoke test ke BotConnector Cloud, dan `npm publish --provenance`.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/session.ts
|
|
4
|
+
import { randomBytes } from "crypto";
|
|
5
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
function projectDir(home, cwd) {
|
|
8
|
+
const slug = cwd.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(-100) || "root";
|
|
9
|
+
return join(home, "sessions", slug);
|
|
10
|
+
}
|
|
11
|
+
function repairTail(messages) {
|
|
12
|
+
const out = [...messages];
|
|
13
|
+
for (let i = out.length - 1; i >= 0; i--) {
|
|
14
|
+
const m = out[i];
|
|
15
|
+
if (m.role !== "assistant" || !m.tool_calls?.length) continue;
|
|
16
|
+
const answered = new Set(out.slice(i + 1).flatMap((x) => x.role === "tool" ? [x.tool_call_id] : []));
|
|
17
|
+
if (!m.tool_calls.every((c) => answered.has(c.id))) out.length = i;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
var Session = class _Session {
|
|
23
|
+
constructor(file) {
|
|
24
|
+
this.file = file;
|
|
25
|
+
}
|
|
26
|
+
file;
|
|
27
|
+
static create(home, cwd, now = /* @__PURE__ */ new Date()) {
|
|
28
|
+
const dir = projectDir(home, cwd);
|
|
29
|
+
mkdirSync(dir, { recursive: true });
|
|
30
|
+
const stamp = now.toISOString().replace(/[:.]/g, "-");
|
|
31
|
+
return new _Session(join(dir, `${stamp}-${randomBytes(3).toString("hex")}.jsonl`));
|
|
32
|
+
}
|
|
33
|
+
static list(home, cwd) {
|
|
34
|
+
const dir = projectDir(home, cwd);
|
|
35
|
+
if (!existsSync(dir)) return [];
|
|
36
|
+
return readdirSync(dir).filter((f) => f.endsWith(".jsonl")).map((f) => {
|
|
37
|
+
const session = new _Session(join(dir, f));
|
|
38
|
+
const first = session.load().find((m) => m.role === "user");
|
|
39
|
+
return { session, mtime: statSync(session.file).mtime, preview: first ? String(first.content).slice(0, 80) : "" };
|
|
40
|
+
}).sort((a, b) => b.mtime.getTime() - a.mtime.getTime() || b.session.file.localeCompare(a.session.file));
|
|
41
|
+
}
|
|
42
|
+
static latest(home, cwd) {
|
|
43
|
+
return _Session.list(home, cwd)[0]?.session;
|
|
44
|
+
}
|
|
45
|
+
write(record) {
|
|
46
|
+
appendFileSync(this.file, `${JSON.stringify(record)}
|
|
47
|
+
`);
|
|
48
|
+
}
|
|
49
|
+
append(message) {
|
|
50
|
+
this.write({ t: "msg", m: message });
|
|
51
|
+
}
|
|
52
|
+
reset() {
|
|
53
|
+
this.write({ t: "reset" });
|
|
54
|
+
}
|
|
55
|
+
load() {
|
|
56
|
+
if (!existsSync(this.file)) return [];
|
|
57
|
+
let messages = [];
|
|
58
|
+
for (const line of readFileSync(this.file, "utf8").split("\n")) {
|
|
59
|
+
if (!line.trim()) continue;
|
|
60
|
+
let record;
|
|
61
|
+
try {
|
|
62
|
+
record = JSON.parse(line);
|
|
63
|
+
} catch {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (record.t === "reset") messages = [];
|
|
67
|
+
else if (record.t === "msg") messages.push(record.m);
|
|
68
|
+
}
|
|
69
|
+
return repairTail(messages);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function pruneSessions(home, now = Date.now(), maxAgeDays = 30) {
|
|
73
|
+
const root = join(home, "sessions");
|
|
74
|
+
if (!existsSync(root)) return 0;
|
|
75
|
+
let removed = 0;
|
|
76
|
+
for (const project of readdirSync(root)) {
|
|
77
|
+
const dir = join(root, project);
|
|
78
|
+
for (const file of readdirSync(dir)) {
|
|
79
|
+
const path = join(dir, file);
|
|
80
|
+
if (now - statSync(path).mtimeMs > maxAgeDays * 864e5) {
|
|
81
|
+
rmSync(path);
|
|
82
|
+
removed++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return removed;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
Session,
|
|
91
|
+
pruneSessions
|
|
92
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
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 }) {
|
|
8
|
+
let failed = false;
|
|
9
|
+
let wroteText = false;
|
|
10
|
+
rt.agent.onEvent = (event) => {
|
|
11
|
+
switch (event.type) {
|
|
12
|
+
case "text":
|
|
13
|
+
io.out.write(event.delta);
|
|
14
|
+
wroteText = true;
|
|
15
|
+
break;
|
|
16
|
+
case "toolStart":
|
|
17
|
+
io.err.write(`\u23BF ${toolLabel(event.tool)} ${event.target}
|
|
18
|
+
`);
|
|
19
|
+
break;
|
|
20
|
+
case "toolEnd":
|
|
21
|
+
if (event.isError) io.err.write(` \u2717 ${event.output.split("\n")[0]}
|
|
22
|
+
`);
|
|
23
|
+
break;
|
|
24
|
+
case "stepLimit":
|
|
25
|
+
io.err.write("Batas langkah tercapai.\n");
|
|
26
|
+
failed = true;
|
|
27
|
+
break;
|
|
28
|
+
case "aborted":
|
|
29
|
+
io.err.write("Dibatalkan.\n");
|
|
30
|
+
failed = true;
|
|
31
|
+
break;
|
|
32
|
+
case "error":
|
|
33
|
+
io.err.write(`Error: ${event.message}
|
|
34
|
+
`);
|
|
35
|
+
failed = true;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
rt.agent.askPermission = async (req) => {
|
|
40
|
+
io.err.write(` Butuh izin untuk ${req.tool}. Jalankan dengan --allow-all atau --allowed-tools ${req.kind}.
|
|
41
|
+
`);
|
|
42
|
+
return "no";
|
|
43
|
+
};
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const onSigint = () => controller.abort();
|
|
46
|
+
process.once("SIGINT", onSigint);
|
|
47
|
+
try {
|
|
48
|
+
await rt.agent.run(prompt, controller.signal);
|
|
49
|
+
} finally {
|
|
50
|
+
process.off("SIGINT", onSigint);
|
|
51
|
+
}
|
|
52
|
+
if (wroteText) io.out.write("\n");
|
|
53
|
+
return failed ? 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/permissions.ts
|
|
57
|
+
import { isAbsolute, relative, resolve, sep } from "path";
|
|
58
|
+
var MODE_ORDER = ["default", "acceptEdits", "plan", "allowAll"];
|
|
59
|
+
function nextMode(mode) {
|
|
60
|
+
return MODE_ORDER[(MODE_ORDER.indexOf(mode) + 1) % MODE_ORDER.length];
|
|
61
|
+
}
|
|
62
|
+
var TWO_WORD = /* @__PURE__ */ new Set(["npm", "npx", "pnpm", "yarn", "bun", "git", "cargo", "go", "docker", "python", "python3", "uv", "make"]);
|
|
63
|
+
function commandKey(segment) {
|
|
64
|
+
const words = segment.trim().split(/\s+/);
|
|
65
|
+
return TWO_WORD.has(words[0]) && words[1] ? `${words[0]} ${words[1]}` : words[0];
|
|
66
|
+
}
|
|
67
|
+
var Permissions = class {
|
|
68
|
+
constructor(mode, rules = [], cwd = process.cwd()) {
|
|
69
|
+
this.mode = mode;
|
|
70
|
+
this.cwd = cwd;
|
|
71
|
+
this.rules = new Set(rules);
|
|
72
|
+
}
|
|
73
|
+
mode;
|
|
74
|
+
cwd;
|
|
75
|
+
rules;
|
|
76
|
+
/** Edits may only be auto-allowed inside the project and outside .git. */
|
|
77
|
+
editInProject(target) {
|
|
78
|
+
const rel = relative(this.cwd, resolve(this.cwd, target));
|
|
79
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) return false;
|
|
80
|
+
return !rel.split(sep).includes(".git") && !rel.split("/").includes(".git");
|
|
81
|
+
}
|
|
82
|
+
/** Rules that "[a] allow for this session" would add; undefined when it must always be asked. */
|
|
83
|
+
rulesFor(req) {
|
|
84
|
+
if (req.kind === "edit") return this.editInProject(req.target) ? ["edit(project)"] : void 0;
|
|
85
|
+
if (req.kind === "fetch") {
|
|
86
|
+
try {
|
|
87
|
+
return [`fetch(${new URL(req.target).hostname})`];
|
|
88
|
+
} catch {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (req.kind === "bash") {
|
|
93
|
+
if (/`|\$\(|[<>]|^\s*[({]/.test(req.target)) return void 0;
|
|
94
|
+
const segments = req.target.split(/&&|\|\||[;&|\n]/).map((s) => s.trim()).filter(Boolean);
|
|
95
|
+
if (!segments.length) return void 0;
|
|
96
|
+
return [...new Set(segments.map((s) => `bash(${commandKey(s)})`))];
|
|
97
|
+
}
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
check(req) {
|
|
101
|
+
if (req.kind === "read") return "allow";
|
|
102
|
+
if (this.mode === "allowAll") return "allow";
|
|
103
|
+
if (this.mode === "plan") return "deny";
|
|
104
|
+
if (this.rules.has(req.kind)) return "allow";
|
|
105
|
+
const needed = this.rulesFor(req);
|
|
106
|
+
if (!needed) return "ask";
|
|
107
|
+
if (req.kind === "edit" && this.mode === "acceptEdits") return "allow";
|
|
108
|
+
return needed.every((rule) => this.rules.has(rule)) ? "allow" : "ask";
|
|
109
|
+
}
|
|
110
|
+
allowForSession(req) {
|
|
111
|
+
for (const rule of this.rulesFor(req) ?? []) this.rules.add(rule);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/tools/ignore.ts
|
|
116
|
+
import { readFileSync } from "fs";
|
|
117
|
+
import { join } from "path";
|
|
118
|
+
function ignorePatterns(root) {
|
|
119
|
+
const patterns = ["**/node_modules/**", "**/.git/**"];
|
|
120
|
+
let lines = [];
|
|
121
|
+
try {
|
|
122
|
+
lines = readFileSync(join(root, ".gitignore"), "utf8").split(/\r?\n/);
|
|
123
|
+
} catch {
|
|
124
|
+
return patterns;
|
|
125
|
+
}
|
|
126
|
+
for (const raw of lines) {
|
|
127
|
+
const line = raw.trim();
|
|
128
|
+
if (!line || line.startsWith("#") || line.startsWith("!")) continue;
|
|
129
|
+
const p = line.replace(/^\//, "").replace(/\/$/, "");
|
|
130
|
+
patterns.push(`**/${p}`, `**/${p}/**`);
|
|
131
|
+
}
|
|
132
|
+
return patterns;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export {
|
|
136
|
+
MODE_ORDER,
|
|
137
|
+
nextMode,
|
|
138
|
+
Permissions,
|
|
139
|
+
toolLabel,
|
|
140
|
+
runPrint,
|
|
141
|
+
ignorePatterns
|
|
142
|
+
};
|