memorix 0.10.3 → 0.10.4

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/index.js CHANGED
@@ -18708,13 +18708,13 @@ var init_status = __esm({
18708
18708
  const { getProjectDataDir: getProjectDataDir2 } = await Promise.resolve().then(() => (init_persistence(), persistence_exports));
18709
18709
  const { getEmbeddingProvider: getEmbeddingProvider2 } = await Promise.resolve().then(() => (init_provider(), provider_exports));
18710
18710
  const { existsSync: existsSync6, readFileSync: readFileSync5 } = await import("fs");
18711
- const { join: join16 } = await import("path");
18711
+ const { join: join17 } = await import("path");
18712
18712
  we("memorix status");
18713
18713
  const project = detectProject2();
18714
18714
  const dataDir = await getProjectDataDir2(project.id);
18715
18715
  let obsCount = 0;
18716
18716
  try {
18717
- const obsFile = join16(dataDir, "observations.json");
18717
+ const obsFile = join17(dataDir, "observations.json");
18718
18718
  if (existsSync6(obsFile)) {
18719
18719
  const data = JSON.parse(readFileSync5(obsFile, "utf-8"));
18720
18720
  obsCount = Array.isArray(data) ? data.length : 0;
@@ -45289,11 +45289,11 @@ ${json}
45289
45289
  try {
45290
45290
  let autoInstall = true;
45291
45291
  try {
45292
- const { homedir: homedir15 } = await import("os");
45293
- const { join: join16 } = await import("path");
45294
- const { readFile: readFile4 } = await import("fs/promises");
45295
- const settingsPath = join16(homedir15(), ".memorix", "settings.json");
45296
- const raw = await readFile4(settingsPath, "utf-8");
45292
+ const { homedir: homedir16 } = await import("os");
45293
+ const { join: join17 } = await import("path");
45294
+ const { readFile: readFile5 } = await import("fs/promises");
45295
+ const settingsPath = join17(homedir16(), ".memorix", "settings.json");
45296
+ const raw = await readFile5(settingsPath, "utf-8");
45297
45297
  const settings = JSON.parse(raw);
45298
45298
  if (settings.autoInstallHooks === false) {
45299
45299
  autoInstall = false;
@@ -45429,6 +45429,137 @@ var init_server4 = __esm({
45429
45429
  }
45430
45430
  });
45431
45431
 
45432
+ // src/cli/update-checker.ts
45433
+ var update_checker_exports = {};
45434
+ __export(update_checker_exports, {
45435
+ checkForUpdates: () => checkForUpdates
45436
+ });
45437
+ import { execFile } from "child_process";
45438
+ import { readFile as readFile4, writeFile as writeFile4, mkdir as mkdir4 } from "fs/promises";
45439
+ import { join as join16 } from "path";
45440
+ import { homedir as homedir15 } from "os";
45441
+ import { createRequire } from "module";
45442
+ function getCurrentVersion() {
45443
+ try {
45444
+ const require3 = createRequire(import.meta.url);
45445
+ const pkg2 = require3("../../package.json");
45446
+ return pkg2.version;
45447
+ } catch {
45448
+ return "0.0.0";
45449
+ }
45450
+ }
45451
+ function isNewer(remote, local) {
45452
+ const r4 = remote.split(".").map(Number);
45453
+ const l3 = local.split(".").map(Number);
45454
+ for (let i2 = 0; i2 < 3; i2++) {
45455
+ if ((r4[i2] ?? 0) > (l3[i2] ?? 0)) return true;
45456
+ if ((r4[i2] ?? 0) < (l3[i2] ?? 0)) return false;
45457
+ }
45458
+ return false;
45459
+ }
45460
+ async function readCache() {
45461
+ try {
45462
+ const data = await readFile4(CACHE_FILE3, "utf-8");
45463
+ return JSON.parse(data);
45464
+ } catch {
45465
+ return null;
45466
+ }
45467
+ }
45468
+ async function writeCache(cache4) {
45469
+ try {
45470
+ await mkdir4(CACHE_DIR3, { recursive: true });
45471
+ await writeFile4(CACHE_FILE3, JSON.stringify(cache4), "utf-8");
45472
+ } catch {
45473
+ }
45474
+ }
45475
+ async function fetchLatestVersion() {
45476
+ try {
45477
+ const { default: https } = await import("https");
45478
+ return new Promise((resolve) => {
45479
+ const req = https.get(REGISTRY_URL, { timeout: 5e3 }, (res) => {
45480
+ if (res.statusCode !== 200) {
45481
+ resolve(null);
45482
+ return;
45483
+ }
45484
+ let body = "";
45485
+ res.on("data", (chunk) => {
45486
+ body += chunk.toString();
45487
+ });
45488
+ res.on("end", () => {
45489
+ try {
45490
+ const data = JSON.parse(body);
45491
+ resolve(data.version ?? null);
45492
+ } catch {
45493
+ resolve(null);
45494
+ }
45495
+ });
45496
+ });
45497
+ req.on("error", () => resolve(null));
45498
+ req.on("timeout", () => {
45499
+ req.destroy();
45500
+ resolve(null);
45501
+ });
45502
+ });
45503
+ } catch {
45504
+ return null;
45505
+ }
45506
+ }
45507
+ function installUpdateInBackground(targetVersion) {
45508
+ try {
45509
+ const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
45510
+ const child = execFile(
45511
+ npmCmd,
45512
+ ["install", "-g", `${PACKAGE_NAME}@${targetVersion}`],
45513
+ { timeout: 6e4 },
45514
+ (error2) => {
45515
+ if (error2) {
45516
+ console.error(`[memorix] Auto-update failed: ${error2.message}`);
45517
+ } else {
45518
+ console.error(`[memorix] \u2705 Auto-updated to v${targetVersion} \u2014 takes effect on next restart`);
45519
+ }
45520
+ }
45521
+ );
45522
+ child.unref();
45523
+ } catch (err) {
45524
+ console.error(`[memorix] Auto-update spawn failed:`, err);
45525
+ }
45526
+ }
45527
+ async function checkForUpdates() {
45528
+ try {
45529
+ const cache4 = await readCache();
45530
+ const now = Date.now();
45531
+ if (cache4 && now - cache4.lastCheck < CHECK_INTERVAL_MS) {
45532
+ return;
45533
+ }
45534
+ const latestVersion = await fetchLatestVersion();
45535
+ if (!latestVersion) return;
45536
+ const currentVersion = getCurrentVersion();
45537
+ await writeCache({
45538
+ lastCheck: now,
45539
+ latestVersion,
45540
+ lastAutoUpdate: cache4?.lastAutoUpdate
45541
+ });
45542
+ if (isNewer(latestVersion, currentVersion)) {
45543
+ console.error(`[memorix] New version available: v${currentVersion} \u2192 v${latestVersion}`);
45544
+ console.error(`[memorix] Auto-updating in background...`);
45545
+ installUpdateInBackground(latestVersion);
45546
+ }
45547
+ } catch {
45548
+ }
45549
+ }
45550
+ var PACKAGE_NAME, CHECK_INTERVAL_MS, REGISTRY_URL, CACHE_DIR3, CACHE_FILE3;
45551
+ var init_update_checker = __esm({
45552
+ "src/cli/update-checker.ts"() {
45553
+ "use strict";
45554
+ init_esm_shims();
45555
+ PACKAGE_NAME = "memorix";
45556
+ CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
45557
+ REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
45558
+ CACHE_DIR3 = join16(homedir15(), ".memorix");
45559
+ CACHE_FILE3 = join16(CACHE_DIR3, "update-check.json");
45560
+ }
45561
+ });
45562
+
45432
45563
  // src/cli/commands/serve.ts
45433
45564
  var serve_exports = {};
45434
45565
  __export(serve_exports, {
@@ -45458,7 +45589,7 @@ var init_serve = __esm({
45458
45589
  const { createMemorixServer: createMemorixServer2 } = await Promise.resolve().then(() => (init_server4(), server_exports2));
45459
45590
  const { detectProject: detectProject2 } = await Promise.resolve().then(() => (init_detector(), detector_exports));
45460
45591
  const { existsSync: existsSync6 } = await import("fs");
45461
- const { join: join16 } = await import("path");
45592
+ const { join: join17 } = await import("path");
45462
45593
  process.stdin.on("end", () => {
45463
45594
  console.error("[memorix] stdin closed \u2014 exiting");
45464
45595
  process.exit(0);
@@ -45471,7 +45602,7 @@ var init_serve = __esm({
45471
45602
  }
45472
45603
  let projectRoot = args.cwd || process.env.MEMORIX_PROJECT_ROOT || process.env.INIT_CWD || safeCwd;
45473
45604
  console.error(`[memorix] Starting with cwd: ${projectRoot}`);
45474
- const looksValid = existsSync6(join16(projectRoot, ".git")) || existsSync6(join16(projectRoot, "package.json")) || existsSync6(join16(projectRoot, "Cargo.toml")) || existsSync6(join16(projectRoot, "go.mod")) || existsSync6(join16(projectRoot, "pyproject.toml"));
45605
+ const looksValid = existsSync6(join17(projectRoot, ".git")) || existsSync6(join17(projectRoot, "package.json")) || existsSync6(join17(projectRoot, "Cargo.toml")) || existsSync6(join17(projectRoot, "go.mod")) || existsSync6(join17(projectRoot, "pyproject.toml"));
45475
45606
  if (!looksValid) {
45476
45607
  const earlyDetect = detectProject2(projectRoot);
45477
45608
  const isDegraded = earlyDetect.id.startsWith("placeholder/");
@@ -45483,6 +45614,8 @@ var init_serve = __esm({
45483
45614
  console.error(`[memorix] MCP Server running on stdio (project: ${projectId})`);
45484
45615
  console.error(`[memorix] Project root: ${projectRoot}`);
45485
45616
  deferredInit().catch((e3) => console.error(`[memorix] Deferred init error:`, e3));
45617
+ Promise.resolve().then(() => (init_update_checker(), update_checker_exports)).then((m4) => m4.checkForUpdates()).catch(() => {
45618
+ });
45486
45619
  } else {
45487
45620
  console.error(`[memorix] cwd may not be a valid project, trying MCP roots protocol...`);
45488
45621
  const mcpServer = new McpServer2({ name: "memorix", version: "0.1.0" });
@@ -45515,6 +45648,8 @@ var init_serve = __esm({
45515
45648
  console.error(`[memorix] MCP Server running on stdio (project: ${projectId})`);
45516
45649
  console.error(`[memorix] Project root: ${projectRoot}`);
45517
45650
  deferredInit().catch((e3) => console.error(`[memorix] Deferred init error:`, e3));
45651
+ Promise.resolve().then(() => (init_update_checker(), update_checker_exports)).then((m4) => m4.checkForUpdates()).catch(() => {
45652
+ });
45518
45653
  }
45519
45654
  } else {
45520
45655
  const { server, projectId, deferredInit } = await createMemorixServer2(projectRoot);
@@ -45523,6 +45658,8 @@ var init_serve = __esm({
45523
45658
  console.error(`[memorix] MCP Server running on stdio (project: ${projectId})`);
45524
45659
  console.error(`[memorix] Project root: ${projectRoot}`);
45525
45660
  deferredInit().catch((e3) => console.error(`[memorix] Deferred init error:`, e3));
45661
+ Promise.resolve().then(() => (init_update_checker(), update_checker_exports)).then((m4) => m4.checkForUpdates()).catch(() => {
45662
+ });
45526
45663
  }
45527
45664
  }
45528
45665
  });
@@ -46680,9 +46817,9 @@ var init_hooks2 = __esm({
46680
46817
  init_esm_shims();
46681
46818
  init_dist2();
46682
46819
  init_dist4();
46683
- import { createRequire } from "module";
46820
+ import { createRequire as createRequire2 } from "module";
46684
46821
  import "child_process";
46685
- var require2 = createRequire(import.meta.url);
46822
+ var require2 = createRequire2(import.meta.url);
46686
46823
  var pkg = require2("../../package.json");
46687
46824
  async function interactiveMenu() {
46688
46825
  we(`Memorix v${pkg.version}`);