hyperclaw 5.2.9 โ†’ 5.3.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.
Files changed (48) hide show
  1. package/dist/banner-7G-bEcQg.js +143 -0
  2. package/dist/banner-BbUkjcoX.js +7 -0
  3. package/dist/banner-DXWl0t8M.js +7 -0
  4. package/dist/banner-DupxNjxh.js +143 -0
  5. package/dist/chat-2cf--psT.js +545 -0
  6. package/dist/chat-TGA-UO46.js +536 -0
  7. package/dist/daemon-BgT541y-.js +421 -0
  8. package/dist/daemon-CckV-o_V.js +421 -0
  9. package/dist/daemon-OqS7Ohda.js +7 -0
  10. package/dist/daemon-iM7U3tDr.js +7 -0
  11. package/dist/engine-BUqmNzOL.js +7 -0
  12. package/dist/engine-BrDEACit.js +327 -0
  13. package/dist/engine-Co38wljj.js +327 -0
  14. package/dist/engine-DrsMsoLZ.js +7 -0
  15. package/dist/hyperclawbot-CZ4DjvO-.js +516 -0
  16. package/dist/hyperclawbot-ukhzbWGk.js +516 -0
  17. package/dist/mcp-loader-CVhiejBN.js +93 -0
  18. package/dist/mcp-loader-u-tt6BEx.js +93 -0
  19. package/dist/onboard-CSJuvkMN.js +14 -0
  20. package/dist/onboard-D6afaGWd.js +3812 -0
  21. package/dist/onboard-eIxjVYKi.js +3812 -0
  22. package/dist/onboard-gr80CpYU.js +14 -0
  23. package/dist/orchestrator-BwBZ5iON.js +189 -0
  24. package/dist/orchestrator-Cgj-8BbJ.js +189 -0
  25. package/dist/orchestrator-CjZos0wH.js +6 -0
  26. package/dist/orchestrator-PLHfNTD6.js +6 -0
  27. package/dist/osint-B6mHZP10.js +283 -0
  28. package/dist/osint-CMyamX3_.js +283 -0
  29. package/dist/osint-chat-DPHec6BB.js +789 -0
  30. package/dist/osint-chat-D_6Fb27C.js +789 -0
  31. package/dist/run-main.js +37 -32
  32. package/dist/server-B9rMYJwV.js +4 -0
  33. package/dist/server-CrZ_WVSf.js +1365 -0
  34. package/dist/server-DMC1wOsc.js +1365 -0
  35. package/dist/server-zXVY2lfd.js +4 -0
  36. package/dist/skill-runtime-CxDPbEuj.js +104 -0
  37. package/dist/skill-runtime-CzsUymMA.js +104 -0
  38. package/dist/skill-runtime-DAP0Gs_7.js +5 -0
  39. package/dist/skill-runtime-DXEKaHRd.js +5 -0
  40. package/dist/src-CSriPfaE.js +63 -0
  41. package/dist/src-CYUaLsXl.js +458 -0
  42. package/dist/src-CvJOtJlj.js +458 -0
  43. package/dist/src-cowbRb9x.js +63 -0
  44. package/dist/sub-agent-tools-CFlCWrhp.js +39 -0
  45. package/dist/sub-agent-tools-CIA8mqjv.js +39 -0
  46. package/dist/update-check-CApy4DTc.js +117 -0
  47. package/dist/update-check-CCMXnjxr.js +7 -0
  48. package/package.json +1 -1
@@ -0,0 +1,545 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_paths = require('./paths-AIyBxIzm.js');
3
+ require('./browser-tools-CJ9M9o22.js');
4
+ require('./src-DjTtmSRg.js');
5
+ const require_engine = require('./engine-Co38wljj.js');
6
+ require('./extraction-tools-BE6z_Yw5.js');
7
+ const require_inference = require('./inference-CFBkvLpE.js');
8
+ require('./memory-auto-BupvVwNd.js');
9
+ require('./orchestrator-BwBZ5iON.js');
10
+ require('./pc-access-BLnc-DYp.js');
11
+ require('./session-store-Ce2QMSL_.js');
12
+ require('./sessions-tools-DKVu9aIN.js');
13
+ require('./skill-loader-Dfs9VNM-.js');
14
+ require('./skill-runtime-CxDPbEuj.js');
15
+ require('./vision-tools-DieVQp6s.js');
16
+ require('./website-watch-tools-Drm5HjIX.js');
17
+ const require_src$1 = require('./src-CYUaLsXl.js');
18
+ const chalk = require_chunk.__toESM(require("chalk"));
19
+ const ora = require_chunk.__toESM(require("ora"));
20
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
21
+ const child_process = require_chunk.__toESM(require("child_process"));
22
+ const readline = require_chunk.__toESM(require("readline"));
23
+ const marked = require_chunk.__toESM(require("marked"));
24
+ const marked_terminal = require_chunk.__toESM(require("marked-terminal"));
25
+
26
+ //#region src/cli/chat.ts
27
+ require_src$1.init_src();
28
+ marked.marked.setOptions({ renderer: new marked_terminal.default({ emoji: true }) });
29
+ function renderMarkdown(text) {
30
+ try {
31
+ const rendered = (0, marked.marked)(text);
32
+ return rendered.split("\n").map((l) => " " + l).join("\n").trimEnd();
33
+ } catch {
34
+ return " " + text;
35
+ }
36
+ }
37
+ const DIVIDER = chalk.default.gray(" " + "โ”€".repeat(56));
38
+ function printHeader(model, sessionId) {
39
+ console.log();
40
+ console.log(DIVIDER);
41
+ console.log(chalk.default.bold.cyan(" ๐Ÿฆ… HYPERCLAW CHAT"));
42
+ console.log(chalk.default.gray(` Model: ${model} ยท Session: ${sessionId}`));
43
+ console.log(DIVIDER);
44
+ console.log(chalk.default.gray(" Type your message and press Enter."));
45
+ console.log(chalk.default.gray(" Commands: /exit /clear /model /prompt /skill add|remove|list /help"));
46
+ console.log(DIVIDER);
47
+ console.log();
48
+ }
49
+ function printHelp() {
50
+ console.log();
51
+ console.log(chalk.default.bold(" Commands:"));
52
+ console.log(` ${chalk.default.cyan("/exit")} โ€” ๐Ÿšช quit the chat`);
53
+ console.log(` ${chalk.default.cyan("/clear")} โ€” ๐Ÿ—‘๏ธ clear conversation history`);
54
+ console.log(` ${chalk.default.cyan("/model")} โ€” ๐Ÿค– show / switch model`);
55
+ console.log(` ${chalk.default.cyan("/model <id>")} โ€” ๐Ÿค– switch model (e.g. /model claude-sonnet-4-5)`);
56
+ console.log(` ${chalk.default.cyan("/prompt")} โ€” ๐Ÿ“ show current session prompt`);
57
+ console.log(` ${chalk.default.cyan("/prompt <text>")} โ€” ๐Ÿ“ add extra instructions for this session`);
58
+ console.log(` ${chalk.default.cyan("/prompt clear")} โ€” ๐Ÿงน remove extra instructions`);
59
+ console.log(` ${chalk.default.cyan("/skills")} โ€” ๐Ÿงฉ list installed skills`);
60
+ console.log(` ${chalk.default.cyan("/skill add <id>")} โ€” โž• activate a skill for this session`);
61
+ console.log(` ${chalk.default.cyan("/skill remove <id>")} โ€” โž– deactivate a skill`);
62
+ console.log(` ${chalk.default.cyan("/help")} โ€” โ“ show this help`);
63
+ console.log();
64
+ console.log(chalk.default.gray(" ๐Ÿ’ก Tips:"));
65
+ console.log(chalk.default.gray(" โ€ข Tell the agent: \"Install the web-search skill\""));
66
+ console.log(chalk.default.gray(" โ€ข Paste a skill link: \"Install this: https://clawhub.ai/user/skill-name\""));
67
+ console.log(chalk.default.gray(" โ€ข Set a session goal: /prompt You are a senior backend engineer. Be concise."));
68
+ console.log(chalk.default.gray(" โ€ข Add to memory: \"Remember that I prefer TypeScript\""));
69
+ console.log();
70
+ }
71
+ async function printSkills() {
72
+ console.log();
73
+ try {
74
+ const { loadSkills } = await Promise.resolve().then(() => require("./skill-loader-DK19Jm4e.js"));
75
+ const skills = await loadSkills();
76
+ if (skills.length === 0) console.log(chalk.default.gray(" No skills installed yet."));
77
+ else {
78
+ console.log(chalk.default.bold(" ๐Ÿงฉ Installed skills:"));
79
+ for (const s of skills) {
80
+ console.log(` ${chalk.default.cyan("๐Ÿ”น")} ${chalk.default.bold(s.title || s.id)} ${chalk.default.gray(`(${s.id})`)}`);
81
+ if (s.capabilities) console.log(chalk.default.gray(` ${s.capabilities}`));
82
+ }
83
+ }
84
+ } catch (e) {
85
+ console.log(chalk.default.gray(" Could not load skills list."));
86
+ console.log(chalk.default.gray(` ${(e?.message || String(e)).slice(0, 80)}`));
87
+ console.log(chalk.default.gray(" Run: hyperclaw doctor or hyperclaw hub to check setup."));
88
+ }
89
+ console.log();
90
+ console.log(chalk.default.bold(" How to add a skill:"));
91
+ console.log(` ${chalk.default.gray("1.")} Tell the agent: ${chalk.default.cyan("\"Install the web-search skill\"")}`);
92
+ console.log(` ${chalk.default.gray("2.")} Paste a link: ${chalk.default.cyan("\"Install this: https://clawhub.ai/user/skill-name\"")}`);
93
+ console.log(` ${chalk.default.gray("3.")} CLI (outside chat): ${chalk.default.cyan("hyperclaw skill install <name>")}`);
94
+ console.log(` ${chalk.default.gray("4.")} Re-run wizard: ${chalk.default.cyan("hyperclaw onboard")}`);
95
+ console.log();
96
+ }
97
+ async function interactiveChatUpdateCheck() {
98
+ try {
99
+ const { checkForUpdates, getCurrentVersion } = await Promise.resolve().then(() => require("./update-check-CCMXnjxr.js"));
100
+ const current = await getCurrentVersion();
101
+ const result = await checkForUpdates(current);
102
+ if (!result?.available) return;
103
+ const isWindows = process.platform === "win32";
104
+ const updateCmd = isWindows ? "npm install -g hyperclaw@latest" : "sudo npm install -g hyperclaw@latest";
105
+ console.log();
106
+ console.log(chalk.default.yellow(` ๐Ÿฆ… New version available! `) + chalk.default.bold.white(result.latest) + chalk.default.gray(` (you have ${current})`));
107
+ console.log(chalk.default.gray(` ๐Ÿ“ฆ ${updateCmd}`));
108
+ console.log();
109
+ const inquirer = (await import("inquirer")).default;
110
+ const { choice } = await inquirer.prompt([{
111
+ type: "list",
112
+ name: "choice",
113
+ message: chalk.default.cyan("What would you like to do?"),
114
+ choices: [{
115
+ name: `๐Ÿš€ Update now & restart chat ${chalk.default.gray("(recommended)")}`,
116
+ value: "update"
117
+ }, {
118
+ name: `โญ๏ธ Skip โ€” continue to chat`,
119
+ value: "skip"
120
+ }],
121
+ prefix: " โœจ"
122
+ }]);
123
+ process.stdout.write("\n");
124
+ if (choice === "skip") {
125
+ console.log(chalk.default.gray(` โญ๏ธ Skipping โ€” run: ${updateCmd} when ready.\n`));
126
+ return;
127
+ }
128
+ console.log(chalk.default.cyan(" โณ Updating HyperClaw...\n"));
129
+ const updateArgs = isWindows ? [
130
+ "install",
131
+ "-g",
132
+ "hyperclaw@latest"
133
+ ] : [
134
+ "npm",
135
+ "install",
136
+ "-g",
137
+ "hyperclaw@latest"
138
+ ];
139
+ const updateBin = isWindows ? "npm" : "sudo";
140
+ await new Promise((resolve) => {
141
+ const proc = (0, child_process.spawn)(updateBin, updateArgs, {
142
+ stdio: "inherit",
143
+ shell: true
144
+ });
145
+ proc.on("close", (code) => {
146
+ if (code === 0) {
147
+ console.log(chalk.default.green(`\n โœ… Updated to ${result.latest}! Restarting chat...\n`));
148
+ const newProc = (0, child_process.spawn)(process.argv[0], process.argv.slice(1), {
149
+ stdio: "inherit",
150
+ shell: false,
151
+ detached: false
152
+ });
153
+ newProc.on("close", (c) => process.exit(c ?? 0));
154
+ newProc.on("error", () => {
155
+ console.log(chalk.default.yellow(" โš ๏ธ Could not auto-restart. Run: hyperclaw chat\n"));
156
+ process.exit(0);
157
+ });
158
+ } else {
159
+ console.log(chalk.default.red(`\n โŒ Update failed (exit ${code}). Continuing with current version...\n`));
160
+ if (!isWindows) console.log(chalk.default.gray(" ๐Ÿ’ก If you use nvm/fnm, try without sudo: npm install -g hyperclaw@latest\n"));
161
+ resolve();
162
+ }
163
+ });
164
+ proc.on("error", () => resolve());
165
+ });
166
+ } catch {}
167
+ }
168
+ function makeSessionId() {
169
+ const { randomBytes } = require("crypto");
170
+ return randomBytes(5).toString("hex");
171
+ }
172
+ async function runChat(opts) {
173
+ const cfg = await fs_extra.default.readJson(require_paths.getConfigPath()).catch(() => null);
174
+ if (!cfg) {
175
+ console.log(chalk.default.red("\n No configuration found.\n"));
176
+ console.log(chalk.default.gray(" Chat works without the gateway. Run: hyperclaw onboard\n"));
177
+ return;
178
+ }
179
+ const { getProviderCredentialAsync } = await Promise.resolve().then(() => require("./env-resolve-pIETNTpQ.js"));
180
+ const apiKey = await getProviderCredentialAsync(cfg).catch(() => null);
181
+ const isLocal = [
182
+ "local",
183
+ "ollama",
184
+ "lmstudio"
185
+ ].includes(cfg?.provider?.providerId ?? "");
186
+ if (!apiKey && !isLocal) {
187
+ console.log(chalk.default.red("\n No API key configured.\n"));
188
+ console.log(chalk.default.gray(" Chat uses your AI provider directly (no gateway needed). Run: hyperclaw config set-key\n"));
189
+ return;
190
+ }
191
+ const { getProvider } = await Promise.resolve().then(() => require("./providers-CFQC39vg.js"));
192
+ const providerMeta = getProvider(cfg?.provider?.providerId ?? "");
193
+ const CUSTOM_IDS = new Set([
194
+ "groq",
195
+ "mistral",
196
+ "deepseek",
197
+ "perplexity",
198
+ "huggingface",
199
+ "ollama",
200
+ "lmstudio",
201
+ "local",
202
+ "xai",
203
+ "openai",
204
+ "google",
205
+ "minimax",
206
+ "moonshot",
207
+ "qwen",
208
+ "zai",
209
+ "litellm",
210
+ "cloudflare",
211
+ "copilot",
212
+ "vercel-ai",
213
+ "opencode-zen"
214
+ ]);
215
+ const isAnthropicVariant = [
216
+ "anthropic",
217
+ "anthropic-oauth",
218
+ "anthropic-setup-token"
219
+ ].includes(cfg?.provider?.providerId ?? "");
220
+ const provider = isAnthropicVariant ? "anthropic" : cfg?.provider?.providerId === "custom" || isLocal || CUSTOM_IDS.has(cfg?.provider?.providerId ?? "") ? "custom" : "openrouter";
221
+ let rawModel = opts.model || cfg?.provider?.modelId || "claude-sonnet-4-5";
222
+ const model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
223
+ const resolvedBaseUrl = cfg?.provider?.baseUrl || providerMeta?.baseUrl || (isLocal ? "http://localhost:11434/v1" : void 0);
224
+ const THINKING_BUDGET = {
225
+ high: 1e4,
226
+ medium: 4e3,
227
+ low: 1e3,
228
+ none: 0
229
+ };
230
+ const thinkingBudget = THINKING_BUDGET[opts.thinking ?? "none"] ?? 0;
231
+ const maxTokens = thinkingBudget > 0 ? thinkingBudget + 4096 : 4096;
232
+ const baseContext = await require_engine.loadWorkspaceContext(opts.workspace) + await require_engine.loadSkillsContext();
233
+ const tools = await require_engine.resolveTools({
234
+ config: cfg,
235
+ source: "cli",
236
+ elevated: true,
237
+ daemonMode: false
238
+ });
239
+ let sessionExtraPrompt = "";
240
+ const sessionActiveSkills = /* @__PURE__ */ new Map();
241
+ function buildSystemPrompt() {
242
+ let sys = baseContext;
243
+ if (sessionExtraPrompt) sys += `\n\n## Session Instructions\n${sessionExtraPrompt}`;
244
+ if (sessionActiveSkills.size > 0) {
245
+ sys += `\n\n## Session Skills\n`;
246
+ for (const [id, ctx] of sessionActiveSkills) sys += `### ${id}\n${ctx}\n\n`;
247
+ }
248
+ return sys || "";
249
+ }
250
+ const engineOpts = {
251
+ model,
252
+ apiKey,
253
+ provider,
254
+ system: buildSystemPrompt() || void 0,
255
+ tools,
256
+ maxTokens,
257
+ onToken: () => {},
258
+ ...provider === "custom" ? { baseUrl: resolvedBaseUrl || "" } : {},
259
+ ...thinkingBudget > 0 && model.includes("claude") ? { thinking: { budget_tokens: thinkingBudget } } : {}
260
+ };
261
+ const sessionId = opts.sessionId ?? makeSessionId();
262
+ const messages = [];
263
+ let autoMem = null;
264
+ try {
265
+ const { AutoMemory } = await Promise.resolve().then(() => require("./memory-auto-Bh52cQJP.js"));
266
+ autoMem = new AutoMemory({ extractEveryNTurns: 3 });
267
+ } catch {}
268
+ printHeader(rawModel, sessionId);
269
+ await interactiveChatUpdateCheck();
270
+ process.stdout.write("\x1B[0m");
271
+ if (process.stdin.isTTY) process.stdin.resume();
272
+ const rl = readline.default.createInterface({
273
+ input: process.stdin,
274
+ output: process.stdout,
275
+ terminal: true
276
+ });
277
+ rl.on("SIGINT", () => {
278
+ console.log(chalk.default.gray("\n\n Bye!\n"));
279
+ rl.close();
280
+ process.exit(0);
281
+ });
282
+ const daemonMode = opts.daemonMode ?? false;
283
+ const t = (await Promise.resolve().then(() => require("./theme-DdZT-Bq4.js"))).getTheme(daemonMode);
284
+ await new Promise((resolve) => {
285
+ rl.on("close", resolve);
286
+ const BOX_W = 60;
287
+ const INNER_W = BOX_W - 6;
288
+ const TOP = t.a(" โ•ญ" + "โ”€".repeat(BOX_W) + "โ•ฎ");
289
+ const BOT = t.a(" โ•ฐ" + "โ”€".repeat(BOX_W) + "โ•ฏ");
290
+ const PLACEHOLDER_TEXT = "Say something to HyperClaw, press Enter";
291
+ const PAD = Math.max(0, INNER_W - 2 - PLACEHOLDER_TEXT.length);
292
+ const MIDDLE_LINE = t.a(" โ”‚ ") + t.bold("โฏ ") + t.muted(PLACEHOLDER_TEXT) + " ".repeat(PAD) + t.a(" โ”‚");
293
+ const INPUT_PROMPT = t.a(" โ”‚ ") + t.bold("โฏ ");
294
+ const prompt = () => {
295
+ process.stdout.write("\n" + TOP + "\n");
296
+ process.stdout.write(MIDDLE_LINE + "\n");
297
+ process.stdout.write(BOT + "\n");
298
+ process.stdout.write("\x1B[1A\x1B[1A");
299
+ process.stdout.write("\x1B[6C");
300
+ let placeholderCleared = false;
301
+ const rlInput = rl.input;
302
+ const clearPlaceholder = (chunk) => {
303
+ if (placeholderCleared) return;
304
+ placeholderCleared = true;
305
+ process.stdout.write("\x1B[K");
306
+ if (rlInput) rlInput.removeListener("data", onData);
307
+ if (chunk !== void 0 && rlInput && typeof rlInput.unshift === "function") rlInput.unshift(chunk);
308
+ };
309
+ const onData = (chunk) => {
310
+ clearPlaceholder(chunk);
311
+ };
312
+ if (rlInput) rlInput.once("data", onData);
313
+ rl.question("", (input) => {
314
+ if (rlInput) rlInput.removeListener("data", onData);
315
+ process.stdout.write("\n");
316
+ if (input === null || input === void 0) {
317
+ prompt();
318
+ return;
319
+ }
320
+ (async () => {
321
+ const text = input.trim();
322
+ if (!text) {
323
+ prompt();
324
+ return;
325
+ }
326
+ if ([
327
+ "/exit",
328
+ "/quit",
329
+ "/bye",
330
+ "exit",
331
+ "quit",
332
+ "bye"
333
+ ].includes(text.toLowerCase())) {
334
+ console.log(chalk.default.gray("\n Bye!\n"));
335
+ rl.close();
336
+ process.exit(0);
337
+ }
338
+ if (text === "/help") {
339
+ printHelp();
340
+ prompt();
341
+ return;
342
+ }
343
+ if (text === "/skills") {
344
+ await printSkills();
345
+ prompt();
346
+ return;
347
+ }
348
+ if (text === "/model" || text.startsWith("/model ")) {
349
+ const newModelArg = text.slice(7).trim().replace(/^<|>$/g, "");
350
+ if (newModelArg) {
351
+ rawModel = newModelArg;
352
+ engineOpts.model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
353
+ console.log(chalk.default.green(`\n ๐Ÿค– Model switched to: ${chalk.default.bold(rawModel)}\n`));
354
+ } else if (providerMeta?.models?.length) {
355
+ rl.pause();
356
+ try {
357
+ const inquirer = (await import("inquirer")).default;
358
+ const defaultIdx = Math.max(0, providerMeta.models.findIndex((m) => m.id === rawModel));
359
+ const { selected } = await inquirer.prompt([{
360
+ type: "list",
361
+ name: "selected",
362
+ message: chalk.default.cyan("Select model") + chalk.default.gray(" (โ†‘โ†“ arrows, Enter to confirm):"),
363
+ choices: providerMeta.models.map((m) => ({
364
+ name: `${m.id} ${chalk.default.gray(m.name)}`,
365
+ value: m.id,
366
+ short: m.id
367
+ })),
368
+ default: defaultIdx,
369
+ prefix: " "
370
+ }]);
371
+ rawModel = selected;
372
+ engineOpts.model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
373
+ console.log(chalk.default.green(`\n ๐Ÿค– Model switched to: ${chalk.default.bold(rawModel)}\n`));
374
+ } catch {
375
+ console.log(chalk.default.gray("\n Selection failed. Use: /model <model-id> (e.g. claude-sonnet-4-5)\n"));
376
+ } finally {
377
+ rl.resume();
378
+ }
379
+ } else {
380
+ console.log(chalk.default.gray(`\n Current model: ${chalk.default.bold(rawModel)}`));
381
+ console.log(chalk.default.gray(" Use: /model <model-id>\n"));
382
+ }
383
+ prompt();
384
+ return;
385
+ }
386
+ if (text === "/clear") {
387
+ messages.length = 0;
388
+ console.log(chalk.default.gray("\n ๐Ÿ—‘๏ธ Conversation cleared.\n"));
389
+ prompt();
390
+ return;
391
+ }
392
+ if (text === "/prompt" || text.startsWith("/prompt ")) {
393
+ const arg = text.slice(7).trim();
394
+ if (!arg) {
395
+ console.log();
396
+ if (sessionExtraPrompt) {
397
+ console.log(chalk.default.bold(" ๐Ÿ“ Session prompt:"));
398
+ console.log(chalk.default.white(` ${sessionExtraPrompt.slice(0, 400)}${sessionExtraPrompt.length > 400 ? "โ€ฆ" : ""}`));
399
+ } else console.log(chalk.default.gray(" ๐Ÿ“ No extra prompt set. Use: /prompt <text>"));
400
+ console.log();
401
+ } else if (arg === "clear") {
402
+ sessionExtraPrompt = "";
403
+ engineOpts.system = buildSystemPrompt() || void 0;
404
+ console.log(chalk.default.green("\n ๐Ÿงน Extra prompt cleared.\n"));
405
+ } else {
406
+ sessionExtraPrompt = arg;
407
+ engineOpts.system = buildSystemPrompt() || void 0;
408
+ console.log(chalk.default.green(`\n โœ… Session prompt set: ${chalk.default.white(arg.slice(0, 60))}${arg.length > 60 ? "โ€ฆ" : ""}\n`));
409
+ }
410
+ prompt();
411
+ return;
412
+ }
413
+ if (text === "/skill" || text.startsWith("/skill ")) {
414
+ const arg = text.slice(6).trim();
415
+ const [subCmd, ...rest] = arg.split(/\s+/);
416
+ const skillId = rest.join(" ").trim();
417
+ if (!subCmd || subCmd === "list") {
418
+ await printSkills();
419
+ prompt();
420
+ return;
421
+ }
422
+ if (subCmd === "add") {
423
+ if (!skillId) {
424
+ console.log(chalk.default.gray("\n Usage: /skill add <skill-id>\n"));
425
+ prompt();
426
+ return;
427
+ }
428
+ try {
429
+ const { loadSkills } = await Promise.resolve().then(() => require("./skill-loader-DK19Jm4e.js"));
430
+ const allSkills = await loadSkills();
431
+ const found = allSkills.find((s) => s.id === skillId || (s.title ?? "").toLowerCase() === skillId.toLowerCase());
432
+ if (!found) console.log(chalk.default.yellow(`\n โš ๏ธ Skill "${skillId}" not found. Use /skills to list installed.\n`));
433
+ else {
434
+ const ctx = [
435
+ found.title ? `**${found.title}**` : found.id,
436
+ found.capabilities ? found.capabilities : "",
437
+ found.description ? found.description : ""
438
+ ].filter(Boolean).join("\n");
439
+ sessionActiveSkills.set(found.id, ctx);
440
+ engineOpts.system = buildSystemPrompt() || void 0;
441
+ console.log(chalk.default.green(`\n โœ… Skill activated: ${chalk.default.bold(found.title || found.id)}\n`));
442
+ }
443
+ } catch (e) {
444
+ console.log(chalk.default.red(`\n โŒ Error loading skills: ${e?.message || String(e)}\n`));
445
+ }
446
+ prompt();
447
+ return;
448
+ }
449
+ if (subCmd === "remove") {
450
+ if (!skillId) {
451
+ console.log(chalk.default.gray("\n Usage: /skill remove <skill-id>\n"));
452
+ prompt();
453
+ return;
454
+ }
455
+ if (sessionActiveSkills.has(skillId)) {
456
+ sessionActiveSkills.delete(skillId);
457
+ engineOpts.system = buildSystemPrompt() || void 0;
458
+ console.log(chalk.default.green(`\n โœ… Skill deactivated: ${skillId}\n`));
459
+ } else console.log(chalk.default.gray(`\n โ„น๏ธ Skill "${skillId}" is not active in this session.\n`));
460
+ prompt();
461
+ return;
462
+ }
463
+ console.log(chalk.default.gray("\n โ„น๏ธ Usage: /skill list | /skill add <id> | /skill remove <id>\n"));
464
+ prompt();
465
+ return;
466
+ }
467
+ messages.push({
468
+ role: "user",
469
+ content: text
470
+ });
471
+ console.log(chalk.default.gray(" " + "โ”€".repeat(56)));
472
+ console.log(chalk.default.bold.green(" ๐Ÿ’ฌ You โ€บ ") + chalk.default.white(text));
473
+ console.log(chalk.default.gray(" " + "โ”€".repeat(56)));
474
+ let responseText = "";
475
+ let elapsed = 0;
476
+ let ticker;
477
+ const spinner = (0, ora.default)({
478
+ text: chalk.default.cyan(` ๐Ÿค” Thinking... (${elapsed}s โ€ข Ctrl+C to cancel)`),
479
+ prefixText: ""
480
+ }).start();
481
+ ticker = setInterval(() => {
482
+ elapsed++;
483
+ spinner.text = chalk.default.cyan(` ๐Ÿค” Thinking... (${elapsed}s โ€ข Ctrl+C to cancel)`);
484
+ }, 1e3);
485
+ try {
486
+ const engine = new require_inference.InferenceEngine({
487
+ ...engineOpts,
488
+ onToken: () => {
489
+ if (spinner.isSpinning) spinner.text = chalk.default.cyan(` ๐Ÿ“ฅ Receiving... (${elapsed}s โ€ข Ctrl+C to cancel)`);
490
+ },
491
+ onToolCall: (name) => {
492
+ spinner.stop();
493
+ console.log(chalk.default.yellow(`\n ๐Ÿ”ง ${chalk.default.bold(name)}`));
494
+ spinner.start(chalk.default.cyan(` โš™๏ธ Working (${elapsed}s โ€ข Ctrl+C to cancel)`));
495
+ }
496
+ });
497
+ const result = await engine.run(messages);
498
+ responseText = result.text || "";
499
+ if (ticker) clearInterval(ticker);
500
+ spinner.stop();
501
+ console.log(chalk.default.bold.blue("\n ๐Ÿฆ… Agent โ€บ"));
502
+ if (responseText) process.stdout.write(renderMarkdown(responseText));
503
+ else process.stdout.write(chalk.default.gray(" (empty โ€” try rephrasing or check model/tools)"));
504
+ console.log("\n");
505
+ console.log(chalk.default.gray(" " + "โ”€".repeat(56)));
506
+ if (result.usage) console.log(chalk.default.gray(` ๐Ÿ“Š Tokens in: ${result.usage.input} out: ${result.usage.output} ยท ${rawModel}\n`));
507
+ else console.log();
508
+ } catch (e) {
509
+ if (ticker) clearInterval(ticker);
510
+ spinner.stop();
511
+ const msg = e?.message || String(e);
512
+ responseText = `Error: ${msg}`;
513
+ console.log(chalk.default.red(`\n Error: ${msg}\n`));
514
+ const hint = (() => {
515
+ if (/401|unauthorized|invalid.*key|authentication/i.test(msg)) return "๐Ÿ”‘ Check API key: hyperclaw config set-key";
516
+ if (/429|rate.?limit|quota/i.test(msg)) return "โฑ๏ธ Rate limited. Wait a moment and retry.";
517
+ if (/500|503|service.?unavailable/i.test(msg)) return "๐Ÿ”Œ Provider temporarily down. Try again later.";
518
+ if (/network|ECONNREFUSED|ETIMEDOUT|fetch failed/i.test(msg)) return "๐ŸŒ Network error. Check connection and base URL.";
519
+ if (/model|not found|invalid model/i.test(msg)) return "๐Ÿค– Try: /model <id> to switch model.";
520
+ return "๐Ÿฉบ Run: hyperclaw doctor for setup checks.";
521
+ })();
522
+ console.log(chalk.default.gray(` ${hint}\n`));
523
+ }
524
+ if (responseText) messages.push({
525
+ role: "assistant",
526
+ content: responseText
527
+ });
528
+ if (autoMem) {
529
+ autoMem.addTurn("user", text);
530
+ if (responseText) autoMem.addTurn("assistant", responseText);
531
+ autoMem.extract().catch(() => {});
532
+ }
533
+ prompt();
534
+ })().catch((err) => {
535
+ console.error(chalk.default.red("\n Unexpected error:"), err?.message || err);
536
+ prompt();
537
+ });
538
+ });
539
+ };
540
+ prompt();
541
+ });
542
+ }
543
+
544
+ //#endregion
545
+ exports.runChat = runChat;