@gilangranggaid/kilua-agent 0.0.0-stage → 1.0.0
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 +28 -2
- package/bin/kilua.mjs +234 -0
- package/package.json +25 -4
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# KILUA AI Agent CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Autonomous AI Coding Agent di terminal & VS Code kamu (seperti Claude Code).
|
|
4
|
+
|
|
5
|
+
## Fitur
|
|
6
|
+
- 🔍 Membaca & menelusuri file di project lokal.
|
|
7
|
+
- ✏️ Mengedit dan membuat file kode secara otomatis.
|
|
8
|
+
- ⚡ Mengeksekusi perintah shell lokal (`git`, `npm`, script).
|
|
9
|
+
- 🧠 Mendukung TokenHarbor, 9router, Gemini, dan OpenAI-compatible provider.
|
|
10
|
+
|
|
11
|
+
## Cara Menggunakan
|
|
12
|
+
|
|
13
|
+
### Tanpa Install (NPX):
|
|
14
|
+
```bash
|
|
15
|
+
npx @gilangranggaid/kilua-agent
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Install Global:
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @gilangranggaid/kilua-agent
|
|
21
|
+
kilua
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Konfigurasi API Key & Model:
|
|
25
|
+
Cukup jalankan, Kilua akan menanyakan API Key & Provider secara interaktif dan menyimpannya di `~/.kilua/settings.json`.
|
|
26
|
+
Atau ketik kapan saja:
|
|
27
|
+
```bash
|
|
28
|
+
kilua config
|
|
29
|
+
```
|
package/bin/kilua.mjs
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import readline from "node:readline";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
// ponytail: single file CLI for zero-dep npx distribution. Split to modules if exceeds 500 lines.
|
|
9
|
+
const KILUA_DIR = path.join(os.homedir(), ".kilua");
|
|
10
|
+
const SETTINGS_PATH = path.join(KILUA_DIR, "settings.json");
|
|
11
|
+
|
|
12
|
+
function ensureKiluaDir() {
|
|
13
|
+
if (!fs.existsSync(KILUA_DIR)) fs.mkdirSync(KILUA_DIR, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function loadSettings() {
|
|
17
|
+
ensureKiluaDir();
|
|
18
|
+
try { return JSON.parse(fs.readFileSync(SETTINGS_PATH, "utf8")); } catch { return {}; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function saveSettings(settings) {
|
|
22
|
+
ensureKiluaDir();
|
|
23
|
+
fs.writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2), "utf8");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const TOOLS = [
|
|
27
|
+
{
|
|
28
|
+
type: "function",
|
|
29
|
+
function: {
|
|
30
|
+
name: "read_file",
|
|
31
|
+
description: "Membaca isi file lokal.",
|
|
32
|
+
parameters: { type: "object", properties: { path: { type: "string" } }, required: ["path"] }
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "function",
|
|
37
|
+
function: {
|
|
38
|
+
name: "write_file",
|
|
39
|
+
description: "Menulis atau membuat file lokal.",
|
|
40
|
+
parameters: { type: "object", properties: { path: { type: "string" }, content: { type: "string" } }, required: ["path", "content"] }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: "function",
|
|
45
|
+
function: {
|
|
46
|
+
name: "edit_file",
|
|
47
|
+
description: "Mengganti teks persis di file lokal.",
|
|
48
|
+
parameters: { type: "object", properties: { path: { type: "string" }, old_string: { type: "string" }, new_string: { type: "string" } }, required: ["path", "old_string", "new_string"] }
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "function",
|
|
53
|
+
function: {
|
|
54
|
+
name: "list_dir",
|
|
55
|
+
description: "Melihat daftar file di folder.",
|
|
56
|
+
parameters: { type: "object", properties: { path: { type: "string" } } }
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: "function",
|
|
61
|
+
function: {
|
|
62
|
+
name: "run_cmd",
|
|
63
|
+
description: "Menjalankan perintah terminal lokal.",
|
|
64
|
+
parameters: { type: "object", properties: { command: { type: "string" } }, required: ["command"] }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
function executeLocalTool(name, args) {
|
|
70
|
+
const cwd = process.cwd();
|
|
71
|
+
try {
|
|
72
|
+
if (name === "read_file") {
|
|
73
|
+
const full = path.resolve(cwd, args.path);
|
|
74
|
+
return fs.existsSync(full) ? fs.readFileSync(full, "utf8").slice(0, 40000) : `Error: ${args.path} not found.`;
|
|
75
|
+
}
|
|
76
|
+
if (name === "write_file") {
|
|
77
|
+
const full = path.resolve(cwd, args.path);
|
|
78
|
+
fs.mkdirSync(path.dirname(full), { recursive: true });
|
|
79
|
+
fs.writeFileSync(full, args.content, "utf8");
|
|
80
|
+
return `✓ Written: ${args.path}`;
|
|
81
|
+
}
|
|
82
|
+
if (name === "edit_file") {
|
|
83
|
+
const full = path.resolve(cwd, args.path);
|
|
84
|
+
if (!fs.existsSync(full)) return `Error: ${args.path} not found.`;
|
|
85
|
+
const src = fs.readFileSync(full, "utf8");
|
|
86
|
+
if (!src.includes(args.old_string)) return `Error: old_string not matched in ${args.path}.`;
|
|
87
|
+
fs.writeFileSync(full, src.replace(args.old_string, args.new_string), "utf8");
|
|
88
|
+
return `✓ Edited: ${args.path}`;
|
|
89
|
+
}
|
|
90
|
+
if (name === "list_dir") {
|
|
91
|
+
const target = path.resolve(cwd, args.path || ".");
|
|
92
|
+
return fs.readdirSync(target, { withFileTypes: true }).map(it => `${it.isDirectory() ? "[DIR]" : "[FILE]"} ${it.name}`).join("\n");
|
|
93
|
+
}
|
|
94
|
+
if (name === "run_cmd") {
|
|
95
|
+
const out = execSync(args.command, { cwd, encoding: "utf8", timeout: 60000, stdio: ["pipe", "pipe", "pipe"] });
|
|
96
|
+
return out.trim() || "(Done)";
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
return `Error: ${err.stderr || err.message}`;
|
|
100
|
+
}
|
|
101
|
+
return `Error: Unknown tool ${name}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function promptQuestion(rl, query) {
|
|
105
|
+
return new Promise(res => rl.question(query, res));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function runInteractiveConfig() {
|
|
109
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
110
|
+
console.log("\x1b[35m=== KILUA CONFIG ===\x1b[0m\nPath: " + SETTINGS_PATH);
|
|
111
|
+
console.log("1) TokenHarbor / 9Router / OpenAI Compatible (Rekomendasi)\n2) Gemini AI Studio\n");
|
|
112
|
+
const choice = (await promptQuestion(rl, "Pilihan [1/2] (1): ")).trim() || "1";
|
|
113
|
+
let settings = {};
|
|
114
|
+
|
|
115
|
+
if (choice === "2") {
|
|
116
|
+
const key = (await promptQuestion(rl, "GEMINI_API_KEY: ")).trim();
|
|
117
|
+
const model = (await promptQuestion(rl, "Model (gemini-2.5-flash): ")).trim() || "gemini-2.5-flash";
|
|
118
|
+
settings = { provider: "gemini", api_key: key, base_url: "https://generativelanguage.googleapis.com/v1beta", model };
|
|
119
|
+
} else {
|
|
120
|
+
const baseUrl = (await promptQuestion(rl, "Base URL (https://tokenharbor.ai/v1): ")).trim() || "https://tokenharbor.ai/v1";
|
|
121
|
+
const key = (await promptQuestion(rl, "API Key: ")).trim();
|
|
122
|
+
const model = (await promptQuestion(rl, "Model (deepseek-v4.1-flash:free): ")).trim() || "deepseek-v4.1-flash:free";
|
|
123
|
+
settings = { provider: "openai", api_key: key, base_url: baseUrl.replace(/\/+$/, ""), model };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
saveSettings(settings);
|
|
127
|
+
rl.close();
|
|
128
|
+
console.log("\x1b[32m✓ Saved to " + SETTINGS_PATH + "\x1b[0m\n");
|
|
129
|
+
return settings;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function runAgent(settings, userPrompt, convo) {
|
|
133
|
+
const SYSTEM = `Kamu KILUA, AI Coding Agent di terminal lokal. Folder: ${process.cwd()}. Gunakan tools (read_file, write_file, edit_file, list_dir, run_cmd) untuk inspeksi dan eksekusi tugas coding mandiri. Respon ringkas to the point.`;
|
|
134
|
+
convo.push({ role: "user", content: userPrompt });
|
|
135
|
+
|
|
136
|
+
for (let step = 0; step < 12; step++) {
|
|
137
|
+
process.stdout.write("\r\x1b[2K\x1b[35m[KILUA Berpikir...]\x1b[0m ");
|
|
138
|
+
let res;
|
|
139
|
+
try {
|
|
140
|
+
res = await fetch(`${settings.base_url}/chat/completions`, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${settings.api_key}` },
|
|
143
|
+
body: JSON.stringify({ model: settings.model, messages: [{ role: "system", content: SYSTEM }, ...convo], tools: TOOLS, tool_choice: "auto" })
|
|
144
|
+
});
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error("\n[!] Connection error:", e.message);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!res.ok) {
|
|
151
|
+
const err = await res.json().catch(() => ({}));
|
|
152
|
+
console.error(`\n[!] Error (${res.status}):`, err.error?.message || err.message || res.statusText);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const data = await res.json();
|
|
157
|
+
const message = data.choices?.[0]?.message;
|
|
158
|
+
if (!message) break;
|
|
159
|
+
convo.push(message);
|
|
160
|
+
|
|
161
|
+
if (message.content) process.stdout.write(`\r\x1b[2KKILUA > ${message.content}\n`);
|
|
162
|
+
|
|
163
|
+
const toolCalls = message.tool_calls || [];
|
|
164
|
+
if (!toolCalls.length) break;
|
|
165
|
+
|
|
166
|
+
for (const tc of toolCalls) {
|
|
167
|
+
const name = tc.function.name;
|
|
168
|
+
let args = {};
|
|
169
|
+
try { args = JSON.parse(tc.function.arguments || "{}"); } catch {}
|
|
170
|
+
console.log(`\x1b[36m⚡ Tool: ${name}\x1b[0m(${JSON.stringify(args)})`);
|
|
171
|
+
const output = executeLocalTool(name, args);
|
|
172
|
+
console.log(`\x1b[90m↳ ${output.slice(0, 140).replace(/\n/g, " ")}${output.length > 140 ? "..." : ""}\x1b[0m`);
|
|
173
|
+
convo.push({ role: "tool", tool_call_id: tc.id, name, content: output });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
console.log();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function main() {
|
|
180
|
+
const args = process.argv.slice(2);
|
|
181
|
+
const oneShot = args.join(" ").trim();
|
|
182
|
+
|
|
183
|
+
if (args[0] === "config" || args[0] === "setup") {
|
|
184
|
+
await runInteractiveConfig();
|
|
185
|
+
process.exit(0);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let settings = loadSettings();
|
|
189
|
+
if (process.env.TOKEN_HARBOR_API_KEY) {
|
|
190
|
+
settings.api_key = process.env.TOKEN_HARBOR_API_KEY;
|
|
191
|
+
settings.base_url = process.env.TOKEN_HARBOR_BASE_URL || "https://tokenharbor.ai/v1";
|
|
192
|
+
settings.model = process.env.TOKEN_HARBOR_MODEL || "deepseek-v4.1-flash:free";
|
|
193
|
+
} else if (process.env.KILUA_API_KEY) {
|
|
194
|
+
settings.api_key = process.env.KILUA_API_KEY;
|
|
195
|
+
settings.base_url = process.env.KILUA_BASE_URL || settings.base_url || "https://tokenharbor.ai/v1";
|
|
196
|
+
settings.model = process.env.KILUA_MODEL || settings.model || "deepseek-v4.1-flash:free";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!settings.api_key) {
|
|
200
|
+
console.log("\x1b[33m[!] Belum ada API key terpasang.\x1b[0m");
|
|
201
|
+
settings = await runInteractiveConfig();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const convo = [];
|
|
205
|
+
if (oneShot) {
|
|
206
|
+
await runAgent(settings, oneShot, convo);
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
console.log("\x1b[1m\x1b[35m=== KILUA AI CLI AGENT ===\x1b[0m");
|
|
211
|
+
console.log(`CWD : \x1b[33m${process.cwd()}\x1b[0m`);
|
|
212
|
+
console.log(`Provider: \x1b[32m${settings.base_url}\x1b[0m (${settings.model})`);
|
|
213
|
+
console.log(`Config : \x1b[90m${SETTINGS_PATH}\x1b[0m (ketik 'config' untuk ganti key/provider)\n`);
|
|
214
|
+
|
|
215
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
216
|
+
const ask = () => {
|
|
217
|
+
rl.question("\x1b[1mKAMU > \x1b[0m", async input => {
|
|
218
|
+
const q = input.trim();
|
|
219
|
+
if (!q) return ask();
|
|
220
|
+
if (q === "exit" || q === "quit") { rl.close(); process.exit(0); }
|
|
221
|
+
if (q === "config" || q === "/config") {
|
|
222
|
+
rl.close();
|
|
223
|
+
await runInteractiveConfig();
|
|
224
|
+
settings = loadSettings();
|
|
225
|
+
return ask();
|
|
226
|
+
}
|
|
227
|
+
await runAgent(settings, q, convo);
|
|
228
|
+
ask();
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
ask();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gilangranggaid/kilua-agent",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Autonomous AI Coding Agent for your terminal and VS Code",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "bin/kilua.mjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"kilua": "bin/kilua.mjs",
|
|
9
|
+
"kilua-agent": "bin/kilua.mjs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"ai",
|
|
20
|
+
"agent",
|
|
21
|
+
"coding-assistant",
|
|
22
|
+
"terminal",
|
|
23
|
+
"vscode"
|
|
24
|
+
],
|
|
25
|
+
"author": "Gilang Rangga ID",
|
|
26
|
+
"license": "MIT"
|
|
27
|
+
}
|