blun-king-cli 2.7.0 → 2.9.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/bin/blun.js +96 -10
- package/package.json +1 -1
package/bin/blun.js
CHANGED
|
@@ -158,6 +158,33 @@ function checkForUpdates() {
|
|
|
158
158
|
} catch(e) { /* silent */ }
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
// Inline markdown: **bold**, `code`, *italic*
|
|
162
|
+
function renderInline(text) {
|
|
163
|
+
return text
|
|
164
|
+
.replace(/\*\*(.+?)\*\*/g, C.bold + C.brightWhite + "$1" + C.reset)
|
|
165
|
+
.replace(/`(.+?)`/g, C.cyan + "$1" + C.reset)
|
|
166
|
+
.replace(/\*(.+?)\*/g, C.italic + "$1" + C.reset);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Word-wrap text to terminal width
|
|
170
|
+
function wordWrap(text, indent) {
|
|
171
|
+
var maxW = (process.stdout.columns || 80) - indent - 2;
|
|
172
|
+
if (text.length <= maxW) return [text];
|
|
173
|
+
var words = text.split(" ");
|
|
174
|
+
var lines = [];
|
|
175
|
+
var current = "";
|
|
176
|
+
for (var i = 0; i < words.length; i++) {
|
|
177
|
+
if (current.length + words[i].length + 1 > maxW && current.length > 0) {
|
|
178
|
+
lines.push(current);
|
|
179
|
+
current = words[i];
|
|
180
|
+
} else {
|
|
181
|
+
current = current ? current + " " + words[i] : words[i];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (current) lines.push(current);
|
|
185
|
+
return lines;
|
|
186
|
+
}
|
|
187
|
+
|
|
161
188
|
function printAnswer(answer, meta) {
|
|
162
189
|
console.log("");
|
|
163
190
|
console.log(C.green + C.bold + " " + BOX.bot + " BLUN King" + C.reset + (meta ? C.gray + " " + BOX.dot + " " + meta + C.reset : ""));
|
|
@@ -178,19 +205,29 @@ function printAnswer(answer, meta) {
|
|
|
178
205
|
} else if (inCode) {
|
|
179
206
|
console.log(C.cyan + " " + BOX.v + " " + line + C.reset);
|
|
180
207
|
} else if (line.startsWith("# ")) {
|
|
181
|
-
console.log(
|
|
208
|
+
console.log("");
|
|
209
|
+
console.log(C.bold + C.yellow + " \u2588 " + line.slice(2) + C.reset);
|
|
210
|
+
console.log("");
|
|
182
211
|
} else if (line.startsWith("## ")) {
|
|
183
|
-
console.log(
|
|
212
|
+
console.log("");
|
|
213
|
+
console.log(C.bold + C.magenta + " \u25B6 " + line.slice(3) + C.reset);
|
|
184
214
|
} else if (line.startsWith("### ")) {
|
|
185
|
-
console.log(C.bold + " " + line + C.reset);
|
|
186
|
-
} else if (line.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
console.log(C.
|
|
190
|
-
|
|
191
|
-
|
|
215
|
+
console.log(C.bold + C.brightWhite + " \u25AA " + line.slice(4) + C.reset);
|
|
216
|
+
} else if (line.match(/^\s*[-*] /)) {
|
|
217
|
+
var bulletText = line.replace(/^\s*[-*] /, "");
|
|
218
|
+
var wrapped = wordWrap(bulletText, 8);
|
|
219
|
+
console.log(" " + C.green + "\u2022 " + C.reset + renderInline(wrapped[0]));
|
|
220
|
+
for (var w = 1; w < wrapped.length; w++) console.log(" " + renderInline(wrapped[w]));
|
|
221
|
+
} else if (line.match(/^\s*\d+\.\s/)) {
|
|
222
|
+
var numMatch = line.match(/^(\s*\d+\.)\s(.*)/);
|
|
223
|
+
var wrapped = wordWrap(numMatch[2], 8);
|
|
224
|
+
console.log(" " + C.yellow + numMatch[1] + C.reset + " " + renderInline(wrapped[0]));
|
|
225
|
+
for (var w = 1; w < wrapped.length; w++) console.log(" " + renderInline(wrapped[w]));
|
|
226
|
+
} else if (line.trim() === "") {
|
|
227
|
+
console.log("");
|
|
192
228
|
} else {
|
|
193
|
-
|
|
229
|
+
var wrapped = wordWrap(line, 2);
|
|
230
|
+
for (var w = 0; w < wrapped.length; w++) console.log(" " + renderInline(wrapped[w]));
|
|
194
231
|
}
|
|
195
232
|
}
|
|
196
233
|
console.log("");
|
|
@@ -2400,6 +2437,52 @@ async function main() {
|
|
|
2400
2437
|
printInfo("Run: blun setup — to configure");
|
|
2401
2438
|
}
|
|
2402
2439
|
|
|
2440
|
+
// Mode selection at startup
|
|
2441
|
+
var sessionMode = "chat"; // chat or agent
|
|
2442
|
+
if (!process.argv.includes("--agent") && !process.argv.includes("--chat")) {
|
|
2443
|
+
console.log("");
|
|
2444
|
+
console.log(C.brightWhite + C.bold + " How do you want to work?" + C.reset);
|
|
2445
|
+
console.log("");
|
|
2446
|
+
var modeOptions = [
|
|
2447
|
+
{ label: "Chat — talk back and forth", mode: "chat" },
|
|
2448
|
+
{ label: "Agent — give a goal, I do the rest autonomously", mode: "agent" }
|
|
2449
|
+
];
|
|
2450
|
+
var modeSel = 0;
|
|
2451
|
+
var modeChoice = await new Promise(function(resolve) {
|
|
2452
|
+
function renderModeMenu() {
|
|
2453
|
+
process.stdout.write("\x1b[2A\r");
|
|
2454
|
+
modeOptions.forEach(function(opt, i) {
|
|
2455
|
+
var prefix = i === modeSel ? C.green + C.bold + " \u276F " : " ";
|
|
2456
|
+
var color = i === modeSel ? C.brightWhite + C.bold : C.gray;
|
|
2457
|
+
process.stdout.write("\x1b[2K" + prefix + color + (i + 1) + ". " + opt.label + C.reset + "\n");
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
console.log(""); console.log("");
|
|
2461
|
+
renderModeMenu();
|
|
2462
|
+
process.stdin.setRawMode(true);
|
|
2463
|
+
process.stdin.resume();
|
|
2464
|
+
process.stdin.setEncoding("utf8");
|
|
2465
|
+
function onKey(key) {
|
|
2466
|
+
if (key === "\x1b[A") { modeSel = 0; renderModeMenu(); return; }
|
|
2467
|
+
if (key === "\x1b[B") { modeSel = 1; renderModeMenu(); return; }
|
|
2468
|
+
if (key === "1") { process.stdin.removeListener("data", onKey); process.stdin.setRawMode(false); resolve("chat"); return; }
|
|
2469
|
+
if (key === "2") { process.stdin.removeListener("data", onKey); process.stdin.setRawMode(false); resolve("agent"); return; }
|
|
2470
|
+
if (key === "\r" || key === "\n") {
|
|
2471
|
+
process.stdin.removeListener("data", onKey);
|
|
2472
|
+
process.stdin.setRawMode(false);
|
|
2473
|
+
resolve(modeOptions[modeSel].mode);
|
|
2474
|
+
return;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
process.stdin.on("data", onKey);
|
|
2478
|
+
});
|
|
2479
|
+
sessionMode = modeChoice;
|
|
2480
|
+
printSuccess("Mode: " + (sessionMode === "agent" ? "Agent (autonomous)" : "Chat (interactive)"));
|
|
2481
|
+
console.log("");
|
|
2482
|
+
} else {
|
|
2483
|
+
sessionMode = process.argv.includes("--agent") ? "agent" : "chat";
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2403
2486
|
var ALL_COMMANDS = [
|
|
2404
2487
|
"/help", "/clear", "/skills", "/skill", "/search", "/learn", "/learn-url",
|
|
2405
2488
|
"/generate", "/analyze", "/score", "/eval", "/settings", "/set",
|
|
@@ -2635,6 +2718,9 @@ async function main() {
|
|
|
2635
2718
|
runHook("pre", detected.split(/\s+/)[0].slice(1));
|
|
2636
2719
|
await handleCommand(detected);
|
|
2637
2720
|
runHook("post", detected.split(/\s+/)[0].slice(1));
|
|
2721
|
+
} else if (sessionMode === "agent") {
|
|
2722
|
+
// Agent mode: auto-route to autonomous agent
|
|
2723
|
+
await cmdAgent(input);
|
|
2638
2724
|
} else {
|
|
2639
2725
|
await sendChat(input);
|
|
2640
2726
|
}
|