nemoris 0.1.9 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemoris",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "description": "Personal AI agent runtime — persistent memory, delivery guarantees, task contracts, self-healing. Local-first, no cloud.",
6
6
  "license": "MIT",
@@ -193,6 +193,87 @@ export async function validateApiKey(provider, key, options = {}) {
193
193
  }
194
194
  }
195
195
 
196
+ /**
197
+ * Validate that a specific model ID exists and is accessible with the given key.
198
+ * Uses lightweight endpoints per provider to avoid token spend.
199
+ *
200
+ * @param {"anthropic"|"openai"|"openrouter"} provider
201
+ * @param {string} modelId - The full model ID to validate
202
+ * @param {string} key - API key
203
+ * @param {object} [options]
204
+ * @param {Function} [options.fetchImpl]
205
+ * @param {Array} [options.fetchedModels] - Pre-fetched model list (avoids extra API call for OpenRouter)
206
+ * @returns {Promise<{ ok: boolean, error?: string }>}
207
+ */
208
+ export async function validateModelId(provider, modelId, key, options = {}) {
209
+ const fetch = options.fetchImpl || globalThis.fetch;
210
+
211
+ // OpenRouter / pre-fetched list: check against known models without an API call
212
+ if (options.fetchedModels && options.fetchedModels.length > 0) {
213
+ const found = options.fetchedModels.some((m) => m.id === modelId);
214
+ if (found) return { ok: true };
215
+ // Not in list — could be a very new model, fall through to API check
216
+ }
217
+
218
+ try {
219
+ if (provider === "anthropic") {
220
+ // count_tokens is zero-cost and validates the model exists
221
+ const resp = await fetch("https://api.anthropic.com/v1/messages/count_tokens", {
222
+ method: "POST",
223
+ headers: {
224
+ "content-type": "application/json",
225
+ ...buildAnthropicAuthHeaders(key),
226
+ },
227
+ body: JSON.stringify({
228
+ model: modelId,
229
+ messages: [{ role: "user", content: "ping" }],
230
+ }),
231
+ signal: AbortSignal.timeout(10000),
232
+ });
233
+ if (resp.ok) return { ok: true };
234
+ const body = await resp.json().catch(() => ({}));
235
+ if (resp.status === 404 || (body.error?.type === "not_found_error")) {
236
+ return { ok: false, error: `Model "${modelId}" not found.` };
237
+ }
238
+ return { ok: false, error: body.error?.message || `API returned ${resp.status}` };
239
+ }
240
+
241
+ if (provider === "openai") {
242
+ const resp = await fetch(`https://api.openai.com/v1/models/${encodeURIComponent(modelId)}`, {
243
+ method: "GET",
244
+ headers: { Authorization: `Bearer ${key}` },
245
+ signal: AbortSignal.timeout(10000),
246
+ });
247
+ if (resp.ok) return { ok: true };
248
+ if (resp.status === 404) {
249
+ return { ok: false, error: `Model "${modelId}" not found.` };
250
+ }
251
+ return { ok: false, error: `API returned ${resp.status}` };
252
+ }
253
+
254
+ if (provider === "openrouter") {
255
+ // OpenRouter has no per-model endpoint — fetch full list and check
256
+ const resp = await fetch("https://openrouter.ai/api/v1/models", {
257
+ method: "GET",
258
+ headers: { Authorization: `Bearer ${key}` },
259
+ signal: AbortSignal.timeout(10000),
260
+ });
261
+ if (!resp.ok) {
262
+ return { ok: false, error: `API returned ${resp.status}` };
263
+ }
264
+ const body = await resp.json().catch(() => ({ data: [] }));
265
+ const found = (body.data || []).some((m) => m.id === modelId);
266
+ return found
267
+ ? { ok: true }
268
+ : { ok: false, error: `Model "${modelId}" not found on OpenRouter.` };
269
+ }
270
+
271
+ return { ok: true }; // Unknown provider — skip validation
272
+ } catch (error) {
273
+ return { ok: false, error: error.message };
274
+ }
275
+ }
276
+
196
277
  /**
197
278
  * Write or merge keys into an .env file at installDir/.env.
198
279
  * Existing keys not being overwritten are preserved.
@@ -13,6 +13,7 @@ import {
13
13
  detectExistingKeys,
14
14
  validateApiKey,
15
15
  validateApiKeyFormat,
16
+ validateModelId,
16
17
  writeEnvFile,
17
18
  resolveProviders
18
19
  } from "../auth/api-key.js";
@@ -424,8 +425,34 @@ async function promptForProviderModels(provider, key, tui, { fetchImpl = globalT
424
425
 
425
426
  let modelId = picked;
426
427
  if (picked === manualOptionValue) {
427
- const custom = await prompt("Model id", stripProviderPrefix(provider, defaultModelValue));
428
- modelId = ensureProviderModelPrefix(provider, custom);
428
+ let validated = false;
429
+ while (!validated) {
430
+ const custom = await prompt("Model id", stripProviderPrefix(provider, defaultModelValue));
431
+ modelId = ensureProviderModelPrefix(provider, custom);
432
+ if (!modelId) {
433
+ break;
434
+ }
435
+ const check = await validateModelId(provider, modelId, key, { fetchImpl, fetchedModels });
436
+ if (check.ok) {
437
+ validated = true;
438
+ } else {
439
+ console.log(` \u274c ${check.error || "Model not found."} Try again or press Enter to skip.`);
440
+ const retry = await prompt("Model id (or empty to cancel)", "");
441
+ if (!retry) {
442
+ modelId = null;
443
+ break;
444
+ }
445
+ modelId = ensureProviderModelPrefix(provider, retry);
446
+ const recheck = await validateModelId(provider, modelId, key, { fetchImpl, fetchedModels });
447
+ if (recheck.ok) {
448
+ validated = true;
449
+ } else {
450
+ console.log(` \u274c ${recheck.error || "Model not found."}`);
451
+ modelId = null;
452
+ break;
453
+ }
454
+ }
455
+ }
429
456
  if (!modelId) {
430
457
  continue;
431
458
  }
@@ -156,7 +156,7 @@ export async function installAndStartOllama(exec, { platform = process.platform,
156
156
  }
157
157
  }
158
158
 
159
- async function chooseOllamaModels(availableModels = []) {
159
+ async function chooseOllamaModels(availableModels = [], { fetchImpl = globalThis.fetch, ollamaBaseUrl = "http://localhost:11434" } = {}) {
160
160
  const curated = [];
161
161
  const addChoice = (value, description) => {
162
162
  if (!curated.some((item) => item.value === value)) {
@@ -199,7 +199,32 @@ async function chooseOllamaModels(availableModels = []) {
199
199
 
200
200
  let model = picked;
201
201
  if (picked === "__custom__") {
202
- model = await prompt("Model name", DEFAULT_PRIMARY_MODEL);
202
+ let validated = false;
203
+ while (!validated) {
204
+ model = await prompt("Model name", DEFAULT_PRIMARY_MODEL);
205
+ model = String(model || "").trim();
206
+ if (!model) break;
207
+ // Validate model exists via Ollama /api/show
208
+ try {
209
+ const resp = await fetchImpl(`${ollamaBaseUrl}/api/show`, {
210
+ method: "POST",
211
+ headers: { "content-type": "application/json" },
212
+ body: JSON.stringify({ name: model }),
213
+ signal: AbortSignal.timeout(5000),
214
+ });
215
+ if (resp.ok) {
216
+ validated = true;
217
+ } else {
218
+ console.log(` \u274c Model "${model}" not found locally. Pull it first with: ollama pull ${model}`);
219
+ model = null;
220
+ break;
221
+ }
222
+ } catch {
223
+ // Ollama unreachable — accept on faith, user already got past detection
224
+ validated = true;
225
+ }
226
+ }
227
+ if (!model) continue;
203
228
  }
204
229
 
205
230
  model = String(model || "").trim();
@@ -314,7 +339,7 @@ export async function runOllamaPhase({ installDir, nonInteractive = false, execI
314
339
  } catch { /* no models listed */ }
315
340
 
316
341
  console.log(`\n Which local models would you like to use? ${dim(`(${DEFAULT_PRIMARY_MODEL} is fastest, ${DEFAULT_FALLBACK_MODEL} is reliable)`)}`);
317
- const chosenModels = await chooseOllamaModels(availableModels);
342
+ const chosenModels = await chooseOllamaModels(availableModels, { fetchImpl });
318
343
  const localModels = chosenModels.length > 0 ? chosenModels : [DEFAULT_PRIMARY_MODEL];
319
344
 
320
345
  patchRouterLocalModels(installDir, localModels);
@@ -64,10 +64,13 @@ export function resolvePendingChatId(installDir, chatId) {
64
64
  );
65
65
  fs.writeFileSync(runtimePath, runtime);
66
66
 
67
- // Patch delivery.toml: replace YOUR_CHAT_ID with real chat_id
67
+ // Patch delivery.toml: replace pending placeholders with real chat_id
68
68
  const deliveryPath = path.join(installDir, "config", "delivery.toml");
69
69
  if (fs.existsSync(deliveryPath)) {
70
70
  let delivery = fs.readFileSync(deliveryPath, "utf8");
71
+ // Native telegram profiles use operator_chat_id = "auto_discover"
72
+ delivery = delivery.replace(/operator_chat_id\s*=\s*"auto_discover"/g, `operator_chat_id = "${chatId}"`);
73
+ // Legacy openclaw_cli profiles use chat_id = "YOUR_CHAT_ID"
71
74
  delivery = delivery.replace(/chat_id\s*=\s*"YOUR_CHAT_ID"/g, `chat_id = "${chatId}"`);
72
75
  fs.writeFileSync(deliveryPath, delivery);
73
76
  }
@@ -85,11 +88,11 @@ export async function patchDeliveryToml(installDir, { chatId, botTokenEnv, chatI
85
88
  // Replace default_interactive_profile line if present
86
89
  let merged = existing.replace(
87
90
  /^default_interactive_profile\s*=\s*"[^"]*"/m,
88
- 'default_interactive_profile = "gateway_telegram_main"'
91
+ 'default_interactive_profile = "telegram_main"'
89
92
  );
90
93
 
91
- // Remove existing profile sections that will be replaced
92
- for (const profileName of ["gateway_telegram_main", "gateway_preview_main"]) {
94
+ // Remove existing profile sections that will be replaced (both old openclaw and new native names)
95
+ for (const profileName of ["gateway_telegram_main", "gateway_preview_main", "telegram_main", "telegram_preview"]) {
93
96
  const sectionRegex = new RegExp(
94
97
  `\\[profiles\\.${profileName}\\][\\s\\S]*?(?=\\n\\[|$)`,
95
98
  "g"
@@ -243,7 +246,10 @@ export async function runTelegramPhase({ installDir, agentId, nonInteractive = f
243
246
  let token = null;
244
247
  let botUsername = null;
245
248
 
246
- console.log(`\n ${dimImpl("Need a bot token? Open Telegram → search @BotFather send /newbot → follow the steps.")}`);
249
+ console.log(`\n ${yellowImpl("!")} Create a new bot in BotFather for Nemoris.`);
250
+ console.log(` ${dimImpl("If you're migrating from OpenClaw, don't reuse your existing bot tokens —")}`);
251
+ console.log(` ${dimImpl("each agent needs its own. Only one process can poll a bot at a time.")}`);
252
+ console.log(`\n ${dimImpl("Open Telegram → search @BotFather → send /newbot → follow the steps.")}`);
247
253
  console.log(` ${dimImpl("After creating your bot, open it in Telegram and tap Start before coming back here.")}`);
248
254
  console.log(` ${dimImpl("Your input will be hidden as you type — just paste and press Enter.")}\n`);
249
255
 
@@ -326,6 +332,21 @@ export async function runTelegramPhase({ installDir, agentId, nonInteractive = f
326
332
  chatIdPending: !chatId,
327
333
  });
328
334
 
335
+ // Persist bot_username to runtime.toml for finish screen / status
336
+ if (botUsername) {
337
+ const runtimePath = path.join(installDir, "config", "runtime.toml");
338
+ try {
339
+ let runtime = fs.readFileSync(runtimePath, "utf8");
340
+ if (runtime.includes("[telegram]") && !runtime.includes("bot_username")) {
341
+ runtime = runtime.replace(
342
+ /(\[telegram\][^\[]*)/s,
343
+ (section) => section.trimEnd() + `\nbot_username = "${botUsername}"\n`
344
+ );
345
+ fs.writeFileSync(runtimePath, runtime);
346
+ }
347
+ } catch { /* non-fatal */ }
348
+ }
349
+
329
350
  // Store chat_id in state for later phases (e.g. hatch)
330
351
  const result = { configured: true, verified: false, botUsername, botToken: token, operatorChatId: chatId || "" };
331
352
 
@@ -328,28 +328,23 @@ target = "peer_queue"
328
328
  * Generates a delivery.toml patch that wires the Telegram gateway profiles.
329
329
  */
330
330
  export function deliveryTelegramPatch({ chatId, botTokenEnv, chatIdPending }) {
331
- const chatIdValue = chatIdPending ? "YOUR_CHAT_ID" : (chatId || "YOUR_CHAT_ID");
331
+ const chatIdValue = chatIdPending ? "auto_discover" : (chatId || "YOUR_CHAT_ID");
332
332
  return `
333
- default_interactive_profile = "gateway_telegram_main"
333
+ default_interactive_profile = "telegram_main"
334
334
 
335
- [profiles.gateway_telegram_main]
336
- adapter = "openclaw_cli"
335
+ [profiles.telegram_main]
336
+ adapter = "telegram"
337
337
  enabled = true
338
- channel = "telegram"
339
- account_id = "default"
340
- chat_id = "${chatIdValue}"
341
338
  bot_token_env = "${botTokenEnv}"
342
- silent = true
343
- dry_run = false
339
+ operator_chat_id = "${chatIdValue}"
340
+ polling_mode = "long_poll"
344
341
 
345
- [profiles.gateway_preview_main]
346
- adapter = "openclaw_cli"
342
+ [profiles.telegram_preview]
343
+ adapter = "telegram"
347
344
  enabled = true
348
- channel = "telegram"
349
- account_id = "default"
350
- chat_id = "${chatIdValue}"
351
345
  bot_token_env = "${botTokenEnv}"
352
- silent = true
346
+ operator_chat_id = "${chatIdValue}"
347
+ polling_mode = "long_poll"
353
348
  dry_run = true
354
349
  `.trim();
355
350
  }
@@ -650,38 +645,41 @@ require_approval_for_network = false
650
645
  * Generates workspace/SOUL.md — who the agent is.
651
646
  * Based on the OpenClaw SOUL.md template pattern.
652
647
  */
653
- export function workspaceSoulTemplate({ agentName, userName }) {
654
- return `# SOUL.md - Who You Are
648
+ export function workspaceSoulTemplate({ agentName, userName, userGoal }) {
649
+ const purpose = userGoal || "General assistant";
650
+ return `# ${agentName}
655
651
 
656
- *You're not a chatbot. You're becoming someone.*
652
+ You are ${agentName}, a personal AI agent for ${userName}.
657
653
 
658
- ## Core Identity
654
+ ## Purpose
659
655
 
660
- - **Name:** ${agentName}
661
- - **Role:** Personal AI assistant for ${userName}
662
- - **Workspace:** This folder is home.
656
+ ${purpose}
663
657
 
664
- ## Core Truths
665
-
666
- **Be genuinely helpful, not performatively helpful.** Skip the filler — just help.
658
+ ## First Contact
667
659
 
668
- **Have opinions.** You're allowed to disagree, prefer things, find things interesting or boring.
660
+ When this is your first conversation (no prior memory):
661
+ - Introduce yourself by name and purpose
662
+ - Ask one question to understand what the user wants to focus on first
663
+ - 3\u20135 sentences, warm and direct, no capability dump
669
664
 
670
- **Be resourceful before asking.** Try to figure it out. Read the file. Check the context. Then ask if you're stuck.
671
-
672
- **Earn trust through competence.** Be careful with external actions. Be bold with internal ones.
665
+ ## Identity
673
666
 
674
- ## Boundaries
667
+ - **Human:** ${userName}
668
+ - You remember across sessions
669
+ - These workspace files are your memory \u2014 read them, update them
675
670
 
676
- - Private things stay private.
677
- - Ask before acting externally.
678
- - Never send half-baked replies.
671
+ ## Core Truths
679
672
 
680
- ## Continuity
673
+ - Be genuinely helpful, not performatively helpful
674
+ - Have opinions \u2014 disagree, prefer things, find things interesting or boring
675
+ - Be resourceful before asking \u2014 read the file, check the context, then ask
676
+ - Earn trust through competence \u2014 careful with external actions, bold with internal ones
681
677
 
682
- Each session, you wake up fresh. These workspace files are your memory. Read them. Update them.
678
+ ## Boundaries
683
679
 
684
- *Update this file as you learn who you are.*
680
+ - Private things stay private
681
+ - Ask before acting externally
682
+ - Never send half-baked replies
685
683
  `;
686
684
  }
687
685
 
@@ -800,12 +798,12 @@ Add whatever helps you do your job. This is your cheat sheet.
800
798
  * Skips files that already exist (writeIfMissing pattern).
801
799
  */
802
800
  import { existsSync, writeFileSync, mkdirSync } from "node:fs";
803
- export function writeWorkspaceContextFiles({ workspaceRoot, agentName, userName, agentId }) {
801
+ export function writeWorkspaceContextFiles({ workspaceRoot, agentName, userName, agentId, userGoal }) {
804
802
  mkdirSync(workspaceRoot, { recursive: true });
805
803
  mkdirSync(path.join(workspaceRoot, "memory"), { recursive: true });
806
804
 
807
805
  const files = [
808
- { name: "SOUL.md", content: workspaceSoulTemplate({ agentName, userName }) },
806
+ { name: "SOUL.md", content: workspaceSoulTemplate({ agentName, userName, userGoal }) },
809
807
  { name: "USER.md", content: workspaceUserTemplate({ userName }) },
810
808
  { name: "MEMORY.md", content: workspaceMemoryTemplate({ agentName }) },
811
809
  { name: "AGENTS.md", content: workspaceAgentsTemplate({ agentName }) },
@@ -824,3 +822,20 @@ export function writeWorkspaceContextFiles({ workspaceRoot, agentName, userName,
824
822
  }
825
823
  return results;
826
824
  }
825
+
826
+ /**
827
+ * Write SOUL.md and USER.md to workspace root. Always overwrites —
828
+ * re-running setup regenerates these from the latest answers.
829
+ * Other workspace files (MEMORY.md, AGENTS.md, TOOLS.md) are left untouched.
830
+ */
831
+ export function writeWorkspaceBootstrap({ workspaceRoot, agentName, userName, userGoal }) {
832
+ mkdirSync(workspaceRoot, { recursive: true });
833
+
834
+ const soulPath = path.join(workspaceRoot, "SOUL.md");
835
+ writeFileSync(soulPath, workspaceSoulTemplate({ agentName, userName, userGoal }), "utf8");
836
+
837
+ const userPath = path.join(workspaceRoot, "USER.md");
838
+ writeFileSync(userPath, workspaceUserTemplate({ userName }), "utf8");
839
+
840
+ return { soulPath, userPath };
841
+ }
@@ -7,6 +7,7 @@ import { parseToml } from "../config/toml-lite.js";
7
7
  import { detect } from "./phases/detect.js";
8
8
  import { scaffold } from "./phases/scaffold.js";
9
9
  import { resolveDefaultAgentName, writeIdentity } from "./phases/identity.js";
10
+ import { writeWorkspaceBootstrap } from "./templates.js";
10
11
  import { runAuthPhase } from "./phases/auth.js";
11
12
  import { runTelegramPhase } from "./phases/telegram.js";
12
13
  import { runOllamaPhase } from "./phases/ollama.js";
@@ -55,6 +56,21 @@ function createLegacyPromptAdapter(prompter) {
55
56
  };
56
57
  }
57
58
 
59
+ function readTelegramBotName(installDir) {
60
+ try {
61
+ const runtime = readRuntimeConfig(installDir);
62
+ const tokenEnv = runtime?.telegram?.bot_token_env;
63
+ if (!tokenEnv) return null;
64
+ const token = process.env[tokenEnv];
65
+ if (!token) return null;
66
+ // Bot username is cached in runtime.toml if available
67
+ if (runtime?.telegram?.bot_username) return runtime.telegram.bot_username;
68
+ return null;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
58
74
  function readRuntimeConfig(installDir) {
59
75
  const runtimePath = path.join(installDir, "config", "runtime.toml");
60
76
  try {
@@ -101,6 +117,95 @@ function readExistingIdentity(installDir) {
101
117
  return result;
102
118
  }
103
119
 
120
+ /**
121
+ * Detect an existing OpenClaw installation and offer to import API keys.
122
+ * Checks ~/.openclaw/openclaw.json for provider keys.
123
+ *
124
+ * @returns {{ imported: boolean, keys: Record<string,string> }}
125
+ */
126
+ async function detectOpenClawMigration(installDir, prompter) {
127
+ const result = { imported: false, keys: {} };
128
+ const openclawDir = path.join(os.homedir(), ".openclaw");
129
+ const openclawConfig = path.join(openclawDir, "openclaw.json");
130
+
131
+ if (!fs.existsSync(openclawConfig)) {
132
+ return result;
133
+ }
134
+
135
+ let config;
136
+ try {
137
+ config = JSON.parse(fs.readFileSync(openclawConfig, "utf8"));
138
+ } catch {
139
+ return result;
140
+ }
141
+
142
+ const wantImport = await prompter.confirm({
143
+ message: "OpenClaw detected \u2014 import your API keys?",
144
+ initialValue: true,
145
+ });
146
+ if (!wantImport) {
147
+ return result;
148
+ }
149
+
150
+ // Extract keys from openclaw.json — check common locations
151
+ const envKeys = {};
152
+
153
+ // Provider keys stored in openclaw env or config
154
+ const openclawEnvPath = path.join(openclawDir, ".env");
155
+ if (fs.existsSync(openclawEnvPath)) {
156
+ try {
157
+ const content = fs.readFileSync(openclawEnvPath, "utf8");
158
+ for (const line of content.split("\n")) {
159
+ const trimmed = line.trim();
160
+ if (!trimmed || trimmed.startsWith("#")) continue;
161
+ const eqIdx = trimmed.indexOf("=");
162
+ if (eqIdx < 1) continue;
163
+ const key = trimmed.slice(0, eqIdx).trim();
164
+ let value = trimmed.slice(eqIdx + 1).trim();
165
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
166
+ value = value.slice(1, -1);
167
+ }
168
+ // Map OpenClaw env var names to Nemoris names
169
+ const keyMap = {
170
+ OPENCLAW_ANTHROPIC_API_KEY: "NEMORIS_ANTHROPIC_API_KEY",
171
+ ANTHROPIC_API_KEY: "NEMORIS_ANTHROPIC_API_KEY",
172
+ OPENROUTER_API_KEY: "OPENROUTER_API_KEY",
173
+ OPENAI_API_KEY: "NEMORIS_OPENAI_API_KEY",
174
+ OPENCLAW_TELEGRAM_BOT_TOKEN: "NEMORIS_TELEGRAM_BOT_TOKEN",
175
+ };
176
+ if (keyMap[key]) {
177
+ envKeys[keyMap[key]] = value;
178
+ }
179
+ }
180
+ } catch { /* non-fatal */ }
181
+ }
182
+
183
+ // Also check process.env for OpenClaw-prefixed keys
184
+ const processKeyMap = {
185
+ OPENCLAW_ANTHROPIC_API_KEY: "NEMORIS_ANTHROPIC_API_KEY",
186
+ OPENCLAW_TELEGRAM_BOT_TOKEN: "NEMORIS_TELEGRAM_BOT_TOKEN",
187
+ };
188
+ for (const [ocKey, nemKey] of Object.entries(processKeyMap)) {
189
+ if (process.env[ocKey] && !envKeys[nemKey]) {
190
+ envKeys[nemKey] = process.env[ocKey];
191
+ }
192
+ }
193
+
194
+ if (Object.keys(envKeys).length > 0) {
195
+ // Write imported keys to nemoris .env
196
+ const { writeEnvFile } = await import("./auth/api-key.js");
197
+ writeEnvFile(installDir, envKeys);
198
+ result.imported = true;
199
+ result.keys = envKeys;
200
+ const count = Object.keys(envKeys).length;
201
+ console.log(` \u2705 Imported ${count} key${count > 1 ? "s" : ""} from OpenClaw`);
202
+ } else {
203
+ console.log(" No API keys found in OpenClaw config.");
204
+ }
205
+
206
+ return result;
207
+ }
208
+
104
209
  function summarizeExistingConfig(installDir) {
105
210
  const runtime = readRuntimeConfig(installDir);
106
211
  const providersDir = path.join(installDir, "config", "providers");
@@ -236,6 +341,9 @@ async function runFastPathWizard({ installDir }) {
236
341
  return runExistingConfigMenu({ installDir, existing, prompter });
237
342
  }
238
343
 
344
+ // Step 0: OpenClaw migration detection
345
+ const openclawMigration = await detectOpenClawMigration(installDir, prompter);
346
+
239
347
  // Step 1: Identity
240
348
  const userName = await prompter.text({
241
349
  message: "What's your name?",
@@ -246,6 +354,10 @@ async function runFastPathWizard({ installDir }) {
246
354
  message: "Name your agent?",
247
355
  initialValue: "Nemo",
248
356
  });
357
+ const userGoal = await prompter.text({
358
+ message: "What should your agent help with? (optional)",
359
+ initialValue: "",
360
+ });
249
361
  const agentId = String(agentName).toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-");
250
362
 
251
363
  // Step 2: Detect + scaffold (silent)
@@ -295,12 +407,19 @@ async function runFastPathWizard({ installDir }) {
295
407
  }
296
408
 
297
409
  // Step 4: Auth + model selection
410
+ const resolvedGoal = String(userGoal || "").trim() || "General assistant";
298
411
  writeIdentity({
299
412
  installDir,
300
413
  userName: userName || process.env.USER || "operator",
301
414
  agentName,
302
415
  agentId,
303
- userGoal: "build software",
416
+ userGoal: resolvedGoal,
417
+ });
418
+ writeWorkspaceBootstrap({
419
+ workspaceRoot: path.join(installDir, "workspace"),
420
+ agentName,
421
+ userName: userName || process.env.USER || "operator",
422
+ userGoal: resolvedGoal,
304
423
  });
305
424
 
306
425
  if (provider !== "skip" && provider !== "ollama") {
@@ -314,29 +433,10 @@ async function runFastPathWizard({ installDir }) {
314
433
  });
315
434
  }
316
435
 
317
- // Post-setup guidance
318
- const { buildSetupChecklist, formatSetupChecklist } = await import("./setup-checklist.js");
319
- const checklist = buildSetupChecklist(installDir);
320
- const allConfigured = Object.values(checklist).every((c) => c.configured);
321
-
322
- await prompter.note(
323
- [
324
- `Agent "${agentName}" is ready.`,
325
- "",
326
- "Next steps:",
327
- " nemoris start Start the daemon",
328
- " nemoris chat Open interactive chat",
329
- ...(allConfigured ? [] : [
330
- "",
331
- "Optional:",
332
- ...(!checklist.telegram.configured ? [" nemoris setup telegram Connect Telegram"] : []),
333
- ...(!checklist.ollama.configured ? [" nemoris setup ollama Add local models"] : []),
334
- ]),
335
- ].join("\n"),
336
- "Setup Complete"
337
- );
338
-
339
436
  // Offer Telegram setup inline
437
+ const { buildSetupChecklist } = await import("./setup-checklist.js");
438
+ let checklist = buildSetupChecklist(installDir);
439
+
340
440
  if (!checklist.telegram.configured) {
341
441
  const wantTelegram = await prompter.confirm({
342
442
  message: "Set up Telegram now?",
@@ -347,10 +447,46 @@ async function runFastPathWizard({ installDir }) {
347
447
  installDir,
348
448
  agentId,
349
449
  });
450
+ checklist = buildSetupChecklist(installDir);
350
451
  }
351
452
  }
352
453
 
353
- await prompter.outro("Run: nemoris start");
454
+ // Auto-start daemon
455
+ let daemonPid = null;
456
+ try {
457
+ const { startDaemonCommand } = await import("../cli/runtime-control.js");
458
+ const result = await startDaemonCommand({ projectRoot: installDir });
459
+ const pidMatch = String(result.message || "").match(/pid\s+(\d+)/);
460
+ daemonPid = pidMatch ? pidMatch[1] : "started";
461
+ } catch {
462
+ // Non-fatal — user can start manually
463
+ }
464
+
465
+ // Strong finish screen
466
+ const telegramConfigured = checklist.telegram.configured || checklist.telegram.pending;
467
+ const botName = readTelegramBotName(installDir);
468
+ const finishLines = [
469
+ `Your agent is live`,
470
+ "",
471
+ ...(daemonPid
472
+ ? [` \u2713 Daemon running (pid ${daemonPid})`]
473
+ : [" \u26a0 Daemon not started \u2014 run: nemoris start"]),
474
+ "",
475
+ ...(telegramConfigured && botName
476
+ ? [
477
+ ` \u2192 Open Telegram and message @${botName}`,
478
+ " Your agent will introduce itself",
479
+ ]
480
+ : [
481
+ " \u2192 Run: nemoris chat Start talking now",
482
+ ]),
483
+ "",
484
+ " Or: nemoris chat Open terminal chat",
485
+ " nemoris status Check agent health",
486
+ ];
487
+
488
+ await prompter.note(finishLines.join("\n"), "");
489
+ await prompter.outro("");
354
490
 
355
491
  try {
356
492
  const pkg = JSON.parse(fs.readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
@@ -632,13 +768,24 @@ async function runManualWizard({
632
768
  initialValue: defaultAgentName,
633
769
  validate: (value) => String(value || "").trim() ? undefined : "Agent name is required.",
634
770
  });
771
+ const userGoal = await prompter.text({
772
+ message: "What should your agent help with? (optional)",
773
+ initialValue: "",
774
+ });
635
775
  const agentId = String(agentName).toLowerCase().replace(/[^a-z0-9-]/g, "-");
776
+ const resolvedGoalManual = String(userGoal || "").trim() || "General assistant";
636
777
  writeIdentity({
637
778
  installDir,
638
779
  userName: userName || process.env.USER || "operator",
639
780
  agentName,
640
781
  agentId,
641
- userGoal: "build software",
782
+ userGoal: resolvedGoalManual,
783
+ });
784
+ writeWorkspaceBootstrap({
785
+ workspaceRoot: path.join(installDir, "workspace"),
786
+ agentName,
787
+ userName: userName || process.env.USER || "operator",
788
+ userGoal: resolvedGoalManual,
642
789
  });
643
790
 
644
791
  const provider = await prompter.select({