hyperclaw 5.1.8 โ†’ 5.2.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.
Files changed (44) hide show
  1. package/dist/chat-B85Qnmv1.js +310 -0
  2. package/dist/chat-BQMPVq39.js +310 -0
  3. package/dist/chat-DGUj_NDO.js +310 -0
  4. package/dist/daemon-DbWcGYXq.js +5 -0
  5. package/dist/daemon-DkdMP-kQ.js +316 -0
  6. package/dist/daemon-RoGBr7z8.js +316 -0
  7. package/dist/daemon-XtFu-VzD.js +5 -0
  8. package/dist/engine-BY0XLiQ1.js +7 -0
  9. package/dist/engine-CaG7uwkg.js +305 -0
  10. package/dist/engine-Ccmpd_MH.js +305 -0
  11. package/dist/engine-DeQdDkFO.js +7 -0
  12. package/dist/hyperclawbot-BD5gNWO8.js +505 -0
  13. package/dist/hyperclawbot-D6cmZ6Bg.js +505 -0
  14. package/dist/mcp-loader-CbcyUzpM.js +94 -0
  15. package/dist/onboard-0RpraIyZ.js +11 -0
  16. package/dist/onboard-B8zjN52U.js +4149 -0
  17. package/dist/onboard-CGGZRH3J.js +4149 -0
  18. package/dist/onboard-UOJHCkZj.js +11 -0
  19. package/dist/onboard-ksEah5jB.js +4149 -0
  20. package/dist/onboard-xgJmy17T.js +11 -0
  21. package/dist/orchestrator-BeK8XyJY.js +6 -0
  22. package/dist/orchestrator-Cj5XWVVe.js +189 -0
  23. package/dist/orchestrator-TsNkrbVG.js +6 -0
  24. package/dist/orchestrator-zS6Manjk.js +189 -0
  25. package/dist/providers-Bk6Y_v9m.js +681 -0
  26. package/dist/providers-BvScOYvt.js +5 -0
  27. package/dist/providers-DEJ8Jtml.js +1089 -0
  28. package/dist/providers-EyJsZ-sr.js +5 -0
  29. package/dist/run-main.js +27 -27
  30. package/dist/server-CeZNKjAL.js +4 -0
  31. package/dist/server-DBUnNWZY.js +1255 -0
  32. package/dist/server-DUVnyXaR.js +1255 -0
  33. package/dist/server-Dy7Q-YLx.js +4 -0
  34. package/dist/skill-runtime-Bsf3CXxL.js +102 -0
  35. package/dist/skill-runtime-C_54rn66.js +5 -0
  36. package/dist/skill-runtime-Do7NLtoa.js +5 -0
  37. package/dist/skill-runtime-fDLfk3m3.js +102 -0
  38. package/dist/src-CQOQRIzS.js +458 -0
  39. package/dist/src-DQ9Q89FM.js +458 -0
  40. package/dist/src-DXaT-nxD.js +63 -0
  41. package/dist/src-DrDuFPKq.js +63 -0
  42. package/dist/sub-agent-tools-Bfk5uqJo.js +39 -0
  43. package/dist/sub-agent-tools-XeiuvDg5.js +39 -0
  44. package/package.json +1 -1
@@ -0,0 +1,310 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_paths = require('./paths-AIyBxIzm.js');
3
+ require('./browser-tools-Cukagp9Y.js');
4
+ require('./src-vs5NrFUT.js');
5
+ const require_engine = require('./engine-BZ0sqwBY.js');
6
+ require('./extraction-tools-CJmm9JKf.js');
7
+ const require_inference = require('./inference-BsqEdbNE.js');
8
+ require('./memory-auto-B8xvdZ1N.js');
9
+ require('./orchestrator-Cean1Z4Y.js');
10
+ require('./pc-access-ZuTL5vIJ.js');
11
+ require('./session-store-BXYhjfpX.js');
12
+ require('./sessions-tools-B1XBgIQ1.js');
13
+ require('./skill-loader-VBTm7jrq.js');
14
+ require('./skill-runtime-CiaQKxFq.js');
15
+ require('./vision-tools-BrEobMj1.js');
16
+ require('./website-watch-tools-x9FemTkB.js');
17
+ const require_src$1 = require('./src-CJ7xyKBY.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 readline = require_chunk.__toESM(require("readline"));
22
+
23
+ //#region src/cli/chat.ts
24
+ require_src$1.init_src();
25
+ const DIVIDER = chalk.default.gray(" " + "โ”€".repeat(56));
26
+ function printHeader(model, sessionId) {
27
+ console.log();
28
+ console.log(DIVIDER);
29
+ console.log(chalk.default.bold.cyan(" ๐Ÿฆ… HYPERCLAW CHAT"));
30
+ console.log(chalk.default.gray(` Model: ${model} ยท Session: ${sessionId}`));
31
+ console.log(DIVIDER);
32
+ console.log(chalk.default.gray(" Type your message and press Enter."));
33
+ console.log(chalk.default.gray(" Commands: /exit /clear /model [id] /skills /help"));
34
+ console.log(DIVIDER);
35
+ console.log();
36
+ }
37
+ function printHelp() {
38
+ console.log();
39
+ console.log(chalk.default.bold(" Commands:"));
40
+ console.log(` ${chalk.default.cyan("/exit")} โ€” quit the chat`);
41
+ console.log(` ${chalk.default.cyan("/clear")} โ€” clear conversation history`);
42
+ console.log(` ${chalk.default.cyan("/model")} โ€” show current model & available models`);
43
+ console.log(` ${chalk.default.cyan("/model <id>")} โ€” switch to a different model`);
44
+ console.log(` ${chalk.default.cyan("/skills")} โ€” list installed skills + how to add more`);
45
+ console.log(` ${chalk.default.cyan("/help")} โ€” show this help`);
46
+ console.log();
47
+ console.log(chalk.default.gray(" Tip: you can also tell the agent to install a skill:"));
48
+ console.log(chalk.default.gray(" \"Install the web-search skill\" or paste a clawhub.ai link"));
49
+ console.log();
50
+ }
51
+ async function printSkills() {
52
+ console.log();
53
+ try {
54
+ const { loadSkills } = await Promise.resolve().then(() => require("./skill-loader-CX2TsYWR.js"));
55
+ const skills = await loadSkills();
56
+ if (skills.length === 0) console.log(chalk.default.gray(" No skills installed yet."));
57
+ else {
58
+ console.log(chalk.default.bold(" Installed skills:"));
59
+ for (const s of skills) {
60
+ console.log(` ${chalk.default.cyan("โ€ข")} ${chalk.default.bold(s.title || s.id)} ${chalk.default.gray(`(${s.id})`)}`);
61
+ if (s.capabilities) console.log(chalk.default.gray(` ${s.capabilities}`));
62
+ }
63
+ }
64
+ } catch {
65
+ console.log(chalk.default.gray(" Could not load skills list."));
66
+ }
67
+ console.log();
68
+ console.log(chalk.default.bold(" How to add a skill:"));
69
+ console.log(` ${chalk.default.gray("1.")} Tell the agent: ${chalk.default.cyan("\"Install the web-search skill\"")}`);
70
+ console.log(` ${chalk.default.gray("2.")} Paste a link: ${chalk.default.cyan("\"Install this: https://clawhub.ai/user/skill-name\"")}`);
71
+ console.log(` ${chalk.default.gray("3.")} CLI (outside chat): ${chalk.default.cyan("hyperclaw skill install <name>")}`);
72
+ console.log(` ${chalk.default.gray("4.")} Re-run wizard: ${chalk.default.cyan("hyperclaw onboard")}`);
73
+ console.log();
74
+ }
75
+ function makeSessionId() {
76
+ return Math.random().toString(36).slice(2, 9);
77
+ }
78
+ async function runChat(opts) {
79
+ const cfg = await fs_extra.default.readJson(require_paths.getConfigPath()).catch(() => null);
80
+ if (!cfg) {
81
+ console.log(chalk.default.red("\n No configuration found. Run: hyperclaw onboard\n"));
82
+ return;
83
+ }
84
+ const { getProviderCredentialAsync } = await Promise.resolve().then(() => require("./env-resolve-ATMFgCR0.js"));
85
+ const apiKey = await getProviderCredentialAsync(cfg).catch(() => null);
86
+ const isLocal = [
87
+ "local",
88
+ "ollama",
89
+ "lmstudio"
90
+ ].includes(cfg?.provider?.providerId ?? "");
91
+ if (!apiKey && !isLocal) {
92
+ console.log(chalk.default.red("\n No API key configured. Run: hyperclaw config set-key\n"));
93
+ return;
94
+ }
95
+ const { getProvider } = await Promise.resolve().then(() => require("./providers-v_cyyxUu.js"));
96
+ const providerMeta = getProvider(cfg?.provider?.providerId ?? "");
97
+ const CUSTOM_IDS = new Set([
98
+ "groq",
99
+ "mistral",
100
+ "deepseek",
101
+ "perplexity",
102
+ "huggingface",
103
+ "ollama",
104
+ "lmstudio",
105
+ "local",
106
+ "xai",
107
+ "openai",
108
+ "google",
109
+ "minimax",
110
+ "moonshot",
111
+ "qwen",
112
+ "zai",
113
+ "litellm",
114
+ "cloudflare",
115
+ "copilot",
116
+ "vercel-ai",
117
+ "opencode-zen"
118
+ ]);
119
+ const isAnthropicVariant = [
120
+ "anthropic",
121
+ "anthropic-oauth",
122
+ "anthropic-setup-token"
123
+ ].includes(cfg?.provider?.providerId ?? "");
124
+ const provider = isAnthropicVariant ? "anthropic" : cfg?.provider?.providerId === "custom" || isLocal || CUSTOM_IDS.has(cfg?.provider?.providerId ?? "") ? "custom" : "openrouter";
125
+ let rawModel = opts.model || cfg?.provider?.modelId || "claude-sonnet-4-5";
126
+ const model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
127
+ const resolvedBaseUrl = cfg?.provider?.baseUrl || providerMeta?.baseUrl || (isLocal ? "http://localhost:11434/v1" : void 0);
128
+ const THINKING_BUDGET = {
129
+ high: 1e4,
130
+ medium: 4e3,
131
+ low: 1e3,
132
+ none: 0
133
+ };
134
+ const thinkingBudget = THINKING_BUDGET[opts.thinking ?? "none"] ?? 0;
135
+ const maxTokens = thinkingBudget > 0 ? thinkingBudget + 4096 : 4096;
136
+ const context = await require_engine.loadWorkspaceContext(opts.workspace) + await require_engine.loadSkillsContext();
137
+ const tools = await require_engine.resolveTools({
138
+ config: cfg,
139
+ source: "cli",
140
+ elevated: true,
141
+ daemonMode: false
142
+ });
143
+ const engineOpts = {
144
+ model,
145
+ apiKey,
146
+ provider,
147
+ system: context || void 0,
148
+ tools,
149
+ maxTokens,
150
+ onToken: () => {},
151
+ ...provider === "custom" ? { baseUrl: resolvedBaseUrl || "" } : {},
152
+ ...thinkingBudget > 0 && model.includes("claude") ? { thinking: { budget_tokens: thinkingBudget } } : {}
153
+ };
154
+ const sessionId = opts.sessionId ?? makeSessionId();
155
+ const messages = [];
156
+ let autoMem = null;
157
+ try {
158
+ const { AutoMemory } = await Promise.resolve().then(() => require("./memory-auto-Hz7VQp04.js"));
159
+ autoMem = new AutoMemory({ extractEveryNTurns: 3 });
160
+ } catch {}
161
+ printHeader(rawModel, sessionId);
162
+ try {
163
+ const { maybeShowUpdateNotice } = await Promise.resolve().then(() => require("./update-check-DSazWOCY.js"));
164
+ maybeShowUpdateNotice();
165
+ } catch {}
166
+ const rl = readline.default.createInterface({
167
+ input: process.stdin,
168
+ output: process.stdout,
169
+ terminal: true
170
+ });
171
+ rl.on("SIGINT", () => {
172
+ console.log(chalk.default.gray("\n\n Bye!\n"));
173
+ rl.close();
174
+ process.exit(0);
175
+ });
176
+ await new Promise((resolve) => {
177
+ rl.on("close", resolve);
178
+ const prompt = () => {
179
+ rl.question(chalk.default.bold.green(" You โ€บ "), async (input) => {
180
+ const text = input.trim();
181
+ if (!text) {
182
+ prompt();
183
+ return;
184
+ }
185
+ if ([
186
+ "/exit",
187
+ "/quit",
188
+ "/bye",
189
+ "exit",
190
+ "quit",
191
+ "bye"
192
+ ].includes(text.toLowerCase())) {
193
+ console.log(chalk.default.gray("\n Bye!\n"));
194
+ rl.close();
195
+ process.exit(0);
196
+ }
197
+ if (text === "/help") {
198
+ printHelp();
199
+ prompt();
200
+ return;
201
+ }
202
+ if (text === "/skills") {
203
+ await printSkills();
204
+ prompt();
205
+ return;
206
+ }
207
+ if (text === "/model" || text.startsWith("/model ")) {
208
+ const newModelArg = text.slice(7).trim().replace(/^<|>$/g, "");
209
+ if (newModelArg) {
210
+ rawModel = newModelArg;
211
+ engineOpts.model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
212
+ console.log(chalk.default.green(`\n โœ” Model switched to: ${chalk.default.bold(rawModel)}\n`));
213
+ } else if (providerMeta?.models?.length) {
214
+ rl.pause();
215
+ try {
216
+ const inquirer = (await import("inquirer")).default;
217
+ const defaultIdx = Math.max(0, providerMeta.models.findIndex((m) => m.id === rawModel));
218
+ const { selected } = await inquirer.prompt([{
219
+ type: "list",
220
+ name: "selected",
221
+ message: chalk.default.cyan("Select model") + chalk.default.gray(" (โ†‘โ†“ arrows, Enter to confirm):"),
222
+ choices: providerMeta.models.map((m) => ({
223
+ name: `${m.id} ${chalk.default.gray(m.name)}`,
224
+ value: m.id,
225
+ short: m.id
226
+ })),
227
+ default: defaultIdx,
228
+ prefix: " "
229
+ }]);
230
+ rawModel = selected;
231
+ engineOpts.model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
232
+ console.log(chalk.default.green(`\n โœ” Model switched to: ${chalk.default.bold(rawModel)}\n`));
233
+ } catch {
234
+ console.log(chalk.default.gray("\n Use: /model <model-id>\n"));
235
+ } finally {
236
+ rl.resume();
237
+ }
238
+ } else {
239
+ console.log(chalk.default.gray(`\n Current model: ${chalk.default.bold(rawModel)}`));
240
+ console.log(chalk.default.gray(" Use: /model <model-id>\n"));
241
+ }
242
+ prompt();
243
+ return;
244
+ }
245
+ if (text === "/clear") {
246
+ messages.length = 0;
247
+ console.log(chalk.default.gray("\n Conversation cleared.\n"));
248
+ prompt();
249
+ return;
250
+ }
251
+ messages.push({
252
+ role: "user",
253
+ content: text
254
+ });
255
+ const spinner = (0, ora.default)({
256
+ text: chalk.default.gray("Thinking..."),
257
+ color: "cyan",
258
+ prefixText: " "
259
+ }).start();
260
+ let responseText = "";
261
+ try {
262
+ let prefixPrinted = false;
263
+ const engine = new require_inference.InferenceEngine({
264
+ ...engineOpts,
265
+ onToken: (token) => {
266
+ if (spinner.isSpinning) spinner.stop();
267
+ if (!prefixPrinted) {
268
+ process.stdout.write(chalk.default.bold.blue("\n Agent โ€บ "));
269
+ prefixPrinted = true;
270
+ }
271
+ process.stdout.write(token);
272
+ },
273
+ onToolCall: (name) => {
274
+ if (spinner.isSpinning) spinner.stop();
275
+ console.log(chalk.default.gray(`\n [tool: ${name}]`));
276
+ prefixPrinted = false;
277
+ }
278
+ });
279
+ const result = await engine.run(messages);
280
+ responseText = result.text || "";
281
+ spinner.stop();
282
+ if (!prefixPrinted) {
283
+ process.stdout.write(chalk.default.bold.blue("\n Agent โ€บ "));
284
+ process.stdout.write(responseText || chalk.default.gray("(empty)"));
285
+ } else if (!responseText) process.stdout.write(chalk.default.gray("(empty)"));
286
+ console.log("\n");
287
+ if (result.usage) console.log(chalk.default.gray(` Tokens โ€” in: ${result.usage.input} out: ${result.usage.output}\n`));
288
+ } catch (e) {
289
+ spinner.stop();
290
+ responseText = `Error: ${e.message}`;
291
+ console.log(chalk.default.red(`\n Error: ${e.message}\n`));
292
+ }
293
+ if (responseText) messages.push({
294
+ role: "assistant",
295
+ content: responseText
296
+ });
297
+ if (autoMem) {
298
+ autoMem.addTurn("user", text);
299
+ if (responseText) autoMem.addTurn("assistant", responseText);
300
+ autoMem.extract().catch(() => {});
301
+ }
302
+ prompt();
303
+ });
304
+ };
305
+ prompt();
306
+ });
307
+ }
308
+
309
+ //#endregion
310
+ exports.runChat = runChat;
@@ -0,0 +1,310 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_paths = require('./paths-AIyBxIzm.js');
3
+ require('./browser-tools-Cukagp9Y.js');
4
+ require('./src-vs5NrFUT.js');
5
+ const require_engine = require('./engine-CaG7uwkg.js');
6
+ require('./extraction-tools-CJmm9JKf.js');
7
+ const require_inference = require('./inference-BsqEdbNE.js');
8
+ require('./memory-auto-B8xvdZ1N.js');
9
+ require('./orchestrator-zS6Manjk.js');
10
+ require('./pc-access-ZuTL5vIJ.js');
11
+ require('./session-store-BXYhjfpX.js');
12
+ require('./sessions-tools-B1XBgIQ1.js');
13
+ require('./skill-loader-VBTm7jrq.js');
14
+ require('./skill-runtime-fDLfk3m3.js');
15
+ require('./vision-tools-BrEobMj1.js');
16
+ require('./website-watch-tools-x9FemTkB.js');
17
+ const require_src$1 = require('./src-CQOQRIzS.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 readline = require_chunk.__toESM(require("readline"));
22
+
23
+ //#region src/cli/chat.ts
24
+ require_src$1.init_src();
25
+ const DIVIDER = chalk.default.gray(" " + "โ”€".repeat(56));
26
+ function printHeader(model, sessionId) {
27
+ console.log();
28
+ console.log(DIVIDER);
29
+ console.log(chalk.default.bold.cyan(" ๐Ÿฆ… HYPERCLAW CHAT"));
30
+ console.log(chalk.default.gray(` Model: ${model} ยท Session: ${sessionId}`));
31
+ console.log(DIVIDER);
32
+ console.log(chalk.default.gray(" Type your message and press Enter."));
33
+ console.log(chalk.default.gray(" Commands: /exit /clear /model [id] /skills /help"));
34
+ console.log(DIVIDER);
35
+ console.log();
36
+ }
37
+ function printHelp() {
38
+ console.log();
39
+ console.log(chalk.default.bold(" Commands:"));
40
+ console.log(` ${chalk.default.cyan("/exit")} โ€” quit the chat`);
41
+ console.log(` ${chalk.default.cyan("/clear")} โ€” clear conversation history`);
42
+ console.log(` ${chalk.default.cyan("/model")} โ€” show current model & available models`);
43
+ console.log(` ${chalk.default.cyan("/model <id>")} โ€” switch to a different model`);
44
+ console.log(` ${chalk.default.cyan("/skills")} โ€” list installed skills + how to add more`);
45
+ console.log(` ${chalk.default.cyan("/help")} โ€” show this help`);
46
+ console.log();
47
+ console.log(chalk.default.gray(" Tip: you can also tell the agent to install a skill:"));
48
+ console.log(chalk.default.gray(" \"Install the web-search skill\" or paste a clawhub.ai link"));
49
+ console.log();
50
+ }
51
+ async function printSkills() {
52
+ console.log();
53
+ try {
54
+ const { loadSkills } = await Promise.resolve().then(() => require("./skill-loader-CX2TsYWR.js"));
55
+ const skills = await loadSkills();
56
+ if (skills.length === 0) console.log(chalk.default.gray(" No skills installed yet."));
57
+ else {
58
+ console.log(chalk.default.bold(" Installed skills:"));
59
+ for (const s of skills) {
60
+ console.log(` ${chalk.default.cyan("โ€ข")} ${chalk.default.bold(s.title || s.id)} ${chalk.default.gray(`(${s.id})`)}`);
61
+ if (s.capabilities) console.log(chalk.default.gray(` ${s.capabilities}`));
62
+ }
63
+ }
64
+ } catch {
65
+ console.log(chalk.default.gray(" Could not load skills list."));
66
+ }
67
+ console.log();
68
+ console.log(chalk.default.bold(" How to add a skill:"));
69
+ console.log(` ${chalk.default.gray("1.")} Tell the agent: ${chalk.default.cyan("\"Install the web-search skill\"")}`);
70
+ console.log(` ${chalk.default.gray("2.")} Paste a link: ${chalk.default.cyan("\"Install this: https://clawhub.ai/user/skill-name\"")}`);
71
+ console.log(` ${chalk.default.gray("3.")} CLI (outside chat): ${chalk.default.cyan("hyperclaw skill install <name>")}`);
72
+ console.log(` ${chalk.default.gray("4.")} Re-run wizard: ${chalk.default.cyan("hyperclaw onboard")}`);
73
+ console.log();
74
+ }
75
+ function makeSessionId() {
76
+ return Math.random().toString(36).slice(2, 9);
77
+ }
78
+ async function runChat(opts) {
79
+ const cfg = await fs_extra.default.readJson(require_paths.getConfigPath()).catch(() => null);
80
+ if (!cfg) {
81
+ console.log(chalk.default.red("\n No configuration found. Run: hyperclaw onboard\n"));
82
+ return;
83
+ }
84
+ const { getProviderCredentialAsync } = await Promise.resolve().then(() => require("./env-resolve-ATMFgCR0.js"));
85
+ const apiKey = await getProviderCredentialAsync(cfg).catch(() => null);
86
+ const isLocal = [
87
+ "local",
88
+ "ollama",
89
+ "lmstudio"
90
+ ].includes(cfg?.provider?.providerId ?? "");
91
+ if (!apiKey && !isLocal) {
92
+ console.log(chalk.default.red("\n No API key configured. Run: hyperclaw config set-key\n"));
93
+ return;
94
+ }
95
+ const { getProvider } = await Promise.resolve().then(() => require("./providers-BvScOYvt.js"));
96
+ const providerMeta = getProvider(cfg?.provider?.providerId ?? "");
97
+ const CUSTOM_IDS = new Set([
98
+ "groq",
99
+ "mistral",
100
+ "deepseek",
101
+ "perplexity",
102
+ "huggingface",
103
+ "ollama",
104
+ "lmstudio",
105
+ "local",
106
+ "xai",
107
+ "openai",
108
+ "google",
109
+ "minimax",
110
+ "moonshot",
111
+ "qwen",
112
+ "zai",
113
+ "litellm",
114
+ "cloudflare",
115
+ "copilot",
116
+ "vercel-ai",
117
+ "opencode-zen"
118
+ ]);
119
+ const isAnthropicVariant = [
120
+ "anthropic",
121
+ "anthropic-oauth",
122
+ "anthropic-setup-token"
123
+ ].includes(cfg?.provider?.providerId ?? "");
124
+ const provider = isAnthropicVariant ? "anthropic" : cfg?.provider?.providerId === "custom" || isLocal || CUSTOM_IDS.has(cfg?.provider?.providerId ?? "") ? "custom" : "openrouter";
125
+ let rawModel = opts.model || cfg?.provider?.modelId || "claude-sonnet-4-5";
126
+ const model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
127
+ const resolvedBaseUrl = cfg?.provider?.baseUrl || providerMeta?.baseUrl || (isLocal ? "http://localhost:11434/v1" : void 0);
128
+ const THINKING_BUDGET = {
129
+ high: 1e4,
130
+ medium: 4e3,
131
+ low: 1e3,
132
+ none: 0
133
+ };
134
+ const thinkingBudget = THINKING_BUDGET[opts.thinking ?? "none"] ?? 0;
135
+ const maxTokens = thinkingBudget > 0 ? thinkingBudget + 4096 : 4096;
136
+ const context = await require_engine.loadWorkspaceContext(opts.workspace) + await require_engine.loadSkillsContext();
137
+ const tools = await require_engine.resolveTools({
138
+ config: cfg,
139
+ source: "cli",
140
+ elevated: true,
141
+ daemonMode: false
142
+ });
143
+ const engineOpts = {
144
+ model,
145
+ apiKey,
146
+ provider,
147
+ system: context || void 0,
148
+ tools,
149
+ maxTokens,
150
+ onToken: () => {},
151
+ ...provider === "custom" ? { baseUrl: resolvedBaseUrl || "" } : {},
152
+ ...thinkingBudget > 0 && model.includes("claude") ? { thinking: { budget_tokens: thinkingBudget } } : {}
153
+ };
154
+ const sessionId = opts.sessionId ?? makeSessionId();
155
+ const messages = [];
156
+ let autoMem = null;
157
+ try {
158
+ const { AutoMemory } = await Promise.resolve().then(() => require("./memory-auto-Hz7VQp04.js"));
159
+ autoMem = new AutoMemory({ extractEveryNTurns: 3 });
160
+ } catch {}
161
+ printHeader(rawModel, sessionId);
162
+ try {
163
+ const { maybeShowUpdateNotice } = await Promise.resolve().then(() => require("./update-check-DSazWOCY.js"));
164
+ maybeShowUpdateNotice();
165
+ } catch {}
166
+ const rl = readline.default.createInterface({
167
+ input: process.stdin,
168
+ output: process.stdout,
169
+ terminal: true
170
+ });
171
+ rl.on("SIGINT", () => {
172
+ console.log(chalk.default.gray("\n\n Bye!\n"));
173
+ rl.close();
174
+ process.exit(0);
175
+ });
176
+ await new Promise((resolve) => {
177
+ rl.on("close", resolve);
178
+ const prompt = () => {
179
+ rl.question(chalk.default.bold.green(" You โ€บ "), async (input) => {
180
+ const text = input.trim();
181
+ if (!text) {
182
+ prompt();
183
+ return;
184
+ }
185
+ if ([
186
+ "/exit",
187
+ "/quit",
188
+ "/bye",
189
+ "exit",
190
+ "quit",
191
+ "bye"
192
+ ].includes(text.toLowerCase())) {
193
+ console.log(chalk.default.gray("\n Bye!\n"));
194
+ rl.close();
195
+ process.exit(0);
196
+ }
197
+ if (text === "/help") {
198
+ printHelp();
199
+ prompt();
200
+ return;
201
+ }
202
+ if (text === "/skills") {
203
+ await printSkills();
204
+ prompt();
205
+ return;
206
+ }
207
+ if (text === "/model" || text.startsWith("/model ")) {
208
+ const newModelArg = text.slice(7).trim().replace(/^<|>$/g, "");
209
+ if (newModelArg) {
210
+ rawModel = newModelArg;
211
+ engineOpts.model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
212
+ console.log(chalk.default.green(`\n โœ” Model switched to: ${chalk.default.bold(rawModel)}\n`));
213
+ } else if (providerMeta?.models?.length) {
214
+ rl.pause();
215
+ try {
216
+ const inquirer = (await import("inquirer")).default;
217
+ const defaultIdx = Math.max(0, providerMeta.models.findIndex((m) => m.id === rawModel));
218
+ const { selected } = await inquirer.prompt([{
219
+ type: "list",
220
+ name: "selected",
221
+ message: chalk.default.cyan("Select model") + chalk.default.gray(" (โ†‘โ†“ arrows, Enter to confirm):"),
222
+ choices: providerMeta.models.map((m) => ({
223
+ name: `${m.id} ${chalk.default.gray(m.name)}`,
224
+ value: m.id,
225
+ short: m.id
226
+ })),
227
+ default: defaultIdx,
228
+ prefix: " "
229
+ }]);
230
+ rawModel = selected;
231
+ engineOpts.model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
232
+ console.log(chalk.default.green(`\n โœ” Model switched to: ${chalk.default.bold(rawModel)}\n`));
233
+ } catch {
234
+ console.log(chalk.default.gray("\n Use: /model <model-id>\n"));
235
+ } finally {
236
+ rl.resume();
237
+ }
238
+ } else {
239
+ console.log(chalk.default.gray(`\n Current model: ${chalk.default.bold(rawModel)}`));
240
+ console.log(chalk.default.gray(" Use: /model <model-id>\n"));
241
+ }
242
+ prompt();
243
+ return;
244
+ }
245
+ if (text === "/clear") {
246
+ messages.length = 0;
247
+ console.log(chalk.default.gray("\n Conversation cleared.\n"));
248
+ prompt();
249
+ return;
250
+ }
251
+ messages.push({
252
+ role: "user",
253
+ content: text
254
+ });
255
+ const spinner = (0, ora.default)({
256
+ text: chalk.default.gray("Thinking..."),
257
+ color: "cyan",
258
+ prefixText: " "
259
+ }).start();
260
+ let responseText = "";
261
+ try {
262
+ let prefixPrinted = false;
263
+ const engine = new require_inference.InferenceEngine({
264
+ ...engineOpts,
265
+ onToken: (token) => {
266
+ if (spinner.isSpinning) spinner.stop();
267
+ if (!prefixPrinted) {
268
+ process.stdout.write(chalk.default.bold.blue("\n Agent โ€บ "));
269
+ prefixPrinted = true;
270
+ }
271
+ process.stdout.write(token);
272
+ },
273
+ onToolCall: (name) => {
274
+ if (spinner.isSpinning) spinner.stop();
275
+ console.log(chalk.default.gray(`\n [tool: ${name}]`));
276
+ prefixPrinted = false;
277
+ }
278
+ });
279
+ const result = await engine.run(messages);
280
+ responseText = result.text || "";
281
+ spinner.stop();
282
+ if (!prefixPrinted) {
283
+ process.stdout.write(chalk.default.bold.blue("\n Agent โ€บ "));
284
+ process.stdout.write(responseText || chalk.default.gray("(empty)"));
285
+ } else if (!responseText) process.stdout.write(chalk.default.gray("(empty)"));
286
+ console.log("\n");
287
+ if (result.usage) console.log(chalk.default.gray(` Tokens โ€” in: ${result.usage.input} out: ${result.usage.output}\n`));
288
+ } catch (e) {
289
+ spinner.stop();
290
+ responseText = `Error: ${e.message}`;
291
+ console.log(chalk.default.red(`\n Error: ${e.message}\n`));
292
+ }
293
+ if (responseText) messages.push({
294
+ role: "assistant",
295
+ content: responseText
296
+ });
297
+ if (autoMem) {
298
+ autoMem.addTurn("user", text);
299
+ if (responseText) autoMem.addTurn("assistant", responseText);
300
+ autoMem.extract().catch(() => {});
301
+ }
302
+ prompt();
303
+ });
304
+ };
305
+ prompt();
306
+ });
307
+ }
308
+
309
+ //#endregion
310
+ exports.runChat = runChat;