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