@codedir/mimir-code 0.1.5 → 0.1.6

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/dist/cli.mjs CHANGED
@@ -3907,11 +3907,6 @@ import { readFileSync, existsSync } from "fs";
3907
3907
  function locateWasmFile() {
3908
3908
  const wasmFileName = "sql-wasm.wasm";
3909
3909
  const currentDir = dirname(fileURLToPath(import.meta.url));
3910
- console.log("WASM file search - debugging:", {
3911
- "import.meta.url": import.meta.url,
3912
- currentDir,
3913
- "process.cwd()": process.cwd()
3914
- });
3915
3910
  const nodeModulesPaths = [
3916
3911
  // Relative to the built module (bundled dist/cli.mjs)
3917
3912
  join(currentDir, "..", "node_modules", "sql.js", "dist", wasmFileName),
@@ -3921,10 +3916,8 @@ function locateWasmFile() {
3921
3916
  join(process.cwd(), "node_modules", "sql.js", "dist", wasmFileName)
3922
3917
  ];
3923
3918
  for (const modulePath of nodeModulesPaths) {
3924
- console.log(` Checking: ${modulePath} - ${existsSync(modulePath) ? "FOUND" : "not found"}`);
3925
3919
  if (existsSync(modulePath)) {
3926
3920
  const buffer = readFileSync(modulePath);
3927
- console.log(" \u2705 Loaded WASM from node_modules");
3928
3921
  return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
3929
3922
  }
3930
3923
  }
@@ -3939,12 +3932,8 @@ function locateWasmFile() {
3939
3932
  join(binaryDir, "..", "resources", wasmFileName)
3940
3933
  ];
3941
3934
  for (const resourcePath of resourcesPaths) {
3942
- console.log(
3943
- ` Checking: ${resourcePath} - ${existsSync(resourcePath) ? "FOUND" : "not found"}`
3944
- );
3945
3935
  if (existsSync(resourcePath)) {
3946
3936
  const buffer = readFileSync(resourcePath);
3947
- console.log(" \u2705 Loaded WASM from resources/");
3948
3937
  return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
3949
3938
  }
3950
3939
  }
@@ -4437,9 +4426,56 @@ var MimirInitializer = class {
4437
4426
  this.fs = fs4;
4438
4427
  this.configLoader = configLoader2;
4439
4428
  }
4429
+ /**
4430
+ * Initialize global user directory at ~/.mimir
4431
+ * Contains: global config, global commands, themes (shared resources)
4432
+ */
4433
+ async initializeGlobalDirectory(homeDir) {
4434
+ const result = {
4435
+ success: true,
4436
+ created: [],
4437
+ errors: [],
4438
+ dbInitialized: false,
4439
+ configCreated: false,
4440
+ globalCreated: false,
4441
+ localCreated: false
4442
+ };
4443
+ try {
4444
+ const globalMimirDir = path6.join(homeDir, ".mimir");
4445
+ if (!await this.fs.exists(globalMimirDir)) {
4446
+ await this.fs.mkdir(globalMimirDir, { recursive: true });
4447
+ result.created.push("~/.mimir/");
4448
+ result.globalCreated = true;
4449
+ logger.info("Created global .mimir directory", { path: globalMimirDir });
4450
+ }
4451
+ const globalSubdirs = [
4452
+ { name: "commands", purpose: "Global custom slash commands" },
4453
+ { name: "themes", purpose: "Global UI theme definitions" }
4454
+ ];
4455
+ for (const { name, purpose } of globalSubdirs) {
4456
+ const subdir = path6.join(globalMimirDir, name);
4457
+ if (!await this.fs.exists(subdir)) {
4458
+ await this.fs.mkdir(subdir, { recursive: true });
4459
+ result.created.push(`~/.mimir/${name}/`);
4460
+ logger.info(`Created global ${name} directory`, { path: subdir, purpose });
4461
+ }
4462
+ }
4463
+ await this.copyDefaultThemes(globalMimirDir, result);
4464
+ await this.copyExampleCommands(globalMimirDir, result);
4465
+ await this.createConfigIfNeeded(globalMimirDir, result);
4466
+ } catch (error) {
4467
+ result.success = false;
4468
+ result.errors.push(
4469
+ `Global directory initialization failed: ${error instanceof Error ? error.message : String(error)}`
4470
+ );
4471
+ logger.error("Global directory initialization failed", { error });
4472
+ }
4473
+ return result;
4474
+ }
4440
4475
  /**
4441
4476
  * Initialize workspace with full Mimir setup
4442
4477
  * Creates directories, database, config, and gitignore
4478
+ * This is for project-local configuration
4443
4479
  */
4444
4480
  async initializeWorkspace(workspaceRoot) {
4445
4481
  const result = {
@@ -4447,10 +4483,13 @@ var MimirInitializer = class {
4447
4483
  created: [],
4448
4484
  errors: [],
4449
4485
  dbInitialized: false,
4450
- configCreated: false
4486
+ configCreated: false,
4487
+ globalCreated: false,
4488
+ localCreated: false
4451
4489
  };
4452
4490
  try {
4453
4491
  const mimirDir = path6.join(workspaceRoot, ".mimir");
4492
+ result.localCreated = true;
4454
4493
  if (!await this.fs.exists(mimirDir)) {
4455
4494
  await this.fs.mkdir(mimirDir, { recursive: true });
4456
4495
  result.created.push(".mimir/");
@@ -4554,13 +4593,6 @@ checkpoints/
4554
4593
  const currentDir = dirname2(fileURLToPath2(import.meta.url));
4555
4594
  const executablePath = process.argv[0] || process.execPath;
4556
4595
  const binaryDir = dirname2(executablePath);
4557
- logger.info("Theme copy - path debugging", {
4558
- "import.meta.url": import.meta.url,
4559
- currentDir,
4560
- executablePath,
4561
- binaryDir,
4562
- "process.cwd()": process.cwd()
4563
- });
4564
4596
  const possibleSourceDirs = [
4565
4597
  // npm package (bundled CLI): <package-root>/src/cli/themes/
4566
4598
  path6.join(currentDir, "../src/cli/themes"),
@@ -4615,13 +4647,6 @@ checkpoints/
4615
4647
  const currentDir = dirname2(fileURLToPath2(import.meta.url));
4616
4648
  const executablePath = process.argv[0] || process.execPath;
4617
4649
  const binaryDir = dirname2(executablePath);
4618
- logger.info("Command copy - path debugging", {
4619
- "import.meta.url": import.meta.url,
4620
- currentDir,
4621
- executablePath,
4622
- binaryDir,
4623
- "process.cwd()": process.cwd()
4624
- });
4625
4650
  const possibleSourceDirs = [
4626
4651
  // npm package (bundled CLI): <package-root>/scripts/templates/commands/
4627
4652
  path6.join(currentDir, "../scripts/templates/commands"),
@@ -6166,6 +6191,8 @@ Available providers: deepseek, anthropic`
6166
6191
  };
6167
6192
 
6168
6193
  // src/cli/commands/InitCommand.ts
6194
+ import { join as join2 } from "path";
6195
+ import { homedir } from "os";
6169
6196
  var InitCommand = class {
6170
6197
  initializer;
6171
6198
  constructor(_fs, _configLoader) {
@@ -6173,24 +6200,81 @@ var InitCommand = class {
6173
6200
  }
6174
6201
  async execute(projectRoot, options = {}) {
6175
6202
  const root = projectRoot || process.cwd();
6203
+ const homeDir = process.env.HOME || process.env.USERPROFILE || homedir();
6176
6204
  if (!options.quiet) {
6177
- logger.info("Initializing Mimir workspace", { projectRoot: root });
6205
+ logger.info("Initializing Mimir", { projectRoot: root, homeDir });
6206
+ }
6207
+ const globalResult = await this.initializer.initializeGlobalDirectory(homeDir);
6208
+ if (!globalResult.success && !options.quiet) {
6209
+ logger.warn("Global directory initialization had errors", {
6210
+ errors: globalResult.errors
6211
+ });
6178
6212
  }
6179
6213
  if (await this.initializer.isWorkspaceInitialized(root)) {
6180
6214
  if (!options.quiet) {
6181
6215
  logger.info("Mimir workspace is already initialized in this directory.");
6182
6216
  logger.info('Run "mimir" to start an interactive chat session.');
6183
6217
  }
6218
+ if (globalResult.created.length > 0 && !options.quiet) {
6219
+ this.printGlobalSummary(globalResult, homeDir);
6220
+ }
6184
6221
  return;
6185
6222
  }
6186
- const result = await this.initializer.initializeWorkspace(root);
6223
+ const localResult = await this.initializer.initializeWorkspace(root);
6224
+ const combinedResult = {
6225
+ ...localResult,
6226
+ created: [...globalResult.created, ...localResult.created],
6227
+ errors: [...globalResult.errors, ...localResult.errors],
6228
+ globalCreated: globalResult.globalCreated,
6229
+ localCreated: localResult.localCreated
6230
+ };
6187
6231
  if (!options.quiet) {
6188
- this.initializer.printSummary(result, root);
6232
+ this.printCombinedSummary(combinedResult, homeDir, root);
6189
6233
  }
6190
- if (!result.success) {
6234
+ if (!globalResult.success || !localResult.success) {
6191
6235
  process.exit(1);
6192
6236
  }
6193
6237
  }
6238
+ printGlobalSummary(result, homeDir) {
6239
+ if (result.created.length > 0) {
6240
+ console.log("\n\u{1F30D} Global Mimir Directory:");
6241
+ result.created.forEach((item) => console.log(` \u2713 ${item}`));
6242
+ console.log(`
6243
+ \u{1F4C1} Location: ${join2(homeDir, ".mimir")}`);
6244
+ }
6245
+ }
6246
+ printCombinedSummary(result, homeDir, projectRoot) {
6247
+ console.log("\n\u{1F680} Mimir Initialized!\n");
6248
+ if (result.globalCreated) {
6249
+ console.log("\u{1F30D} Global Directory Created:");
6250
+ console.log(` ${join2(homeDir, ".mimir")}`);
6251
+ console.log(" \u251C\u2500\u2500 config.yml (user preferences)");
6252
+ console.log(" \u251C\u2500\u2500 commands/ (global custom commands)");
6253
+ console.log(" \u2514\u2500\u2500 themes/ (global UI themes)");
6254
+ console.log("");
6255
+ }
6256
+ if (result.localCreated) {
6257
+ console.log("\u{1F4C2} Project Workspace Created:");
6258
+ console.log(` ${join2(projectRoot, ".mimir")}`);
6259
+ console.log(" \u251C\u2500\u2500 mimir.db (conversation history - ignored)");
6260
+ console.log(" \u251C\u2500\u2500 logs/ (application logs - ignored)");
6261
+ console.log(" \u251C\u2500\u2500 commands/ (project commands - tracked)");
6262
+ console.log(" \u251C\u2500\u2500 themes/ (project themes - tracked)");
6263
+ console.log(" \u2514\u2500\u2500 checkpoints/ (undo/restore - ignored)");
6264
+ console.log("");
6265
+ }
6266
+ if (result.errors.length > 0) {
6267
+ console.log("\u26A0\uFE0F Warnings:");
6268
+ result.errors.forEach((error) => console.log(` ! ${error}`));
6269
+ console.log("");
6270
+ }
6271
+ console.log("\u{1F4A1} Configuration Hierarchy:");
6272
+ console.log(" 1. ~/.mimir/config.yml (user defaults)");
6273
+ console.log(" 2. ./.mimir/config.yml (project overrides)");
6274
+ console.log(" 3. .env (API keys)");
6275
+ console.log(" 4. CLI flags (runtime overrides)");
6276
+ console.log('\n\u2728 Ready to use! Run "mimir" to start an interactive chat session.\n');
6277
+ }
6194
6278
  };
6195
6279
 
6196
6280
  // src/cli/commands/UninstallCommand.ts