musememory 1.8.0 → 1.9.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 (3) hide show
  1. package/README.md +58 -3
  2. package/dist/index.js +539 -179
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9028,6 +9028,297 @@ var init_hook = __esm(() => {
9028
9028
  init_audit();
9029
9029
  });
9030
9030
 
9031
+ // src/cli/upgrade.ts
9032
+ var exports_upgrade = {};
9033
+ __export(exports_upgrade, {
9034
+ detectPackageManager: () => detectPackageManager,
9035
+ executePackageUpgrade: () => executePackageUpgrade,
9036
+ formatProgressBar: () => formatProgressBar,
9037
+ getLatestNpmVersion: () => getLatestNpmVersion,
9038
+ getUpgradeMilestones: () => getUpgradeMilestones,
9039
+ handleUpgradeCommand: () => handleUpgradeCommand,
9040
+ playGamifiedLoader: () => playGamifiedLoader,
9041
+ repairInstallation: () => repairInstallation
9042
+ });
9043
+ import { execSync as execSync2 } from "node:child_process";
9044
+ import { existsSync as existsSync22, mkdirSync as mkdirSync13, writeFileSync as writeFileSync11 } from "node:fs";
9045
+ import { join as join19 } from "node:path";
9046
+ function formatProgressBar(percent, width = 20) {
9047
+ const p = Math.max(0, Math.min(100, percent));
9048
+ const filledCount = Math.round(p / 100 * width);
9049
+ const emptyCount = Math.max(0, width - filledCount);
9050
+ const filled = "█".repeat(filledCount);
9051
+ const empty = "░".repeat(emptyCount);
9052
+ return `[${filled}${empty}] ${Math.round(p)}%`;
9053
+ }
9054
+ function detectPackageManager() {
9055
+ try {
9056
+ if (typeof process.isBun !== "undefined" || process.versions.bun) {
9057
+ return "bun";
9058
+ }
9059
+ } catch {}
9060
+ try {
9061
+ execSync2("bun --version", { stdio: "ignore" });
9062
+ return "bun";
9063
+ } catch {}
9064
+ try {
9065
+ execSync2("pnpm --version", { stdio: "ignore" });
9066
+ return "pnpm";
9067
+ } catch {}
9068
+ try {
9069
+ execSync2("yarn --version", { stdio: "ignore" });
9070
+ return "yarn";
9071
+ } catch {}
9072
+ return "npm";
9073
+ }
9074
+ async function getLatestNpmVersion(packageName = "musememory") {
9075
+ try {
9076
+ const res = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
9077
+ headers: { Accept: "application/json" },
9078
+ signal: AbortSignal.timeout(3000)
9079
+ });
9080
+ if (res.ok) {
9081
+ const data = await res.json();
9082
+ if (data && typeof data.version === "string") {
9083
+ return data.version;
9084
+ }
9085
+ }
9086
+ } catch {}
9087
+ try {
9088
+ const out = execSync2(`npm show ${packageName} version`, {
9089
+ encoding: "utf8",
9090
+ stdio: ["ignore", "pipe", "ignore"]
9091
+ }).trim();
9092
+ if (out && !out.includes("error"))
9093
+ return out;
9094
+ } catch {}
9095
+ return null;
9096
+ }
9097
+ function getUpgradeMilestones() {
9098
+ return [
9099
+ {
9100
+ level: 1,
9101
+ stage: "LEVEL 1 [\uD83D\uDEE1️ Vibeguard Pre-Flight Check]",
9102
+ description: "Auditing environment credentials & storage integrity"
9103
+ },
9104
+ {
9105
+ level: 2,
9106
+ stage: "LEVEL 2 [\uD83D\uDCE6 Package Manager Synchronization]",
9107
+ description: "Querying package registry and pulling latest release binaries"
9108
+ },
9109
+ {
9110
+ level: 3,
9111
+ stage: "LEVEL 3 [\uD83E\uDDE0 Synaptic Database & Schema Alignment]",
9112
+ description: "Validating SQLite tables, CURRENT.md constraints & USER.md profiles"
9113
+ },
9114
+ {
9115
+ level: 4,
9116
+ stage: "LEVEL 4 [\uD83E\uDD16 80+ Agent Auto-Wiring Matrix]",
9117
+ description: "Scanning workstation platforms and auto-wiring newly detected agents"
9118
+ },
9119
+ {
9120
+ level: 5,
9121
+ stage: "LEVEL 5 [✨ Cognitive Ascendance Complete]",
9122
+ description: "Upgraded to latest version! All agent skills synchronized"
9123
+ }
9124
+ ];
9125
+ }
9126
+ async function playGamifiedLoader(steps, options = {}) {
9127
+ const isTTY = process.stdout.isTTY;
9128
+ const total = steps.length;
9129
+ console.log(`
9130
+ ┌──────────────────────────────────────────────────────────────────┐`);
9131
+ console.log(`│ \uD83E\uDDE0 MUSE MEMORY · ${options.title || "SYSTEM LEVEL-UP & RECOVERY MATRIX"} │`);
9132
+ console.log(`└──────────────────────────────────────────────────────────────────┘
9133
+ `);
9134
+ for (let i = 0;i < total; i++) {
9135
+ const step = steps[i];
9136
+ const percent = Math.round((i + 1) / total * 100);
9137
+ const bar = formatProgressBar(percent, 24);
9138
+ if (isTTY) {
9139
+ process.stdout.write(` ${bar} ⚡ LEVEL ${step.level}: ${step.title}...\r`);
9140
+ } else {
9141
+ console.log(` ${bar} ⚡ LEVEL ${step.level}: ${step.title}`);
9142
+ }
9143
+ try {
9144
+ await step.action();
9145
+ } catch (err) {
9146
+ console.log(`
9147
+ [!] Warning during step "${step.title}": ${err.message || err}`);
9148
+ }
9149
+ if (isTTY) {
9150
+ await new Promise((r) => setTimeout(r, 60));
9151
+ process.stdout.write(` ${bar} ✓ LEVEL ${step.level}: ${step.title} [OK]
9152
+ `);
9153
+ }
9154
+ }
9155
+ console.log();
9156
+ }
9157
+ async function repairInstallation(options = {}) {
9158
+ const root = options.workspaceRoot || process.cwd();
9159
+ const isGlobal = options.global === true;
9160
+ const memoryDir = options.memoryDir || (isGlobal ? getGlobalMemoryDir() : resolveMemoryDir({ root }));
9161
+ const actionsTaken = [];
9162
+ const memoriesDir = join19(memoryDir, "memories");
9163
+ if (!existsSync22(memoriesDir)) {
9164
+ mkdirSync13(memoriesDir, { recursive: true });
9165
+ actionsTaken.push(`Created missing memories directory: ${memoriesDir}`);
9166
+ }
9167
+ const currentPath = join19(memoryDir, "CURRENT.md");
9168
+ if (!existsSync22(currentPath)) {
9169
+ writeFileSync11(currentPath, `# Active Project Constraints
9170
+
9171
+ - [ ] Initial session constraints initialized.
9172
+ `, "utf8");
9173
+ actionsTaken.push(`Recovered missing CURRENT.md at ${currentPath}`);
9174
+ }
9175
+ const uPath = userFilePath(memoryDir);
9176
+ if (!existsSync22(uPath)) {
9177
+ initUserProfile(memoryDir, "developer", false, !isGlobal);
9178
+ actionsTaken.push(`Recovered missing USER.md profile at ${uPath}`);
9179
+ }
9180
+ let agentsConnected = 0;
9181
+ if (!options.skipAgentConnect) {
9182
+ try {
9183
+ const reports = connectAgent("all", undefined, { dryRun: false, force: false });
9184
+ agentsConnected = reports.filter((r) => r.updated || r.installed).length;
9185
+ if (agentsConnected > 0) {
9186
+ actionsTaken.push(`Auto-wired ${agentsConnected} detected agent platform(s)`);
9187
+ }
9188
+ } catch {}
9189
+ }
9190
+ if (!isGlobal && existsSync22(root)) {
9191
+ try {
9192
+ const index = indexGraph(root, memoryDir);
9193
+ if (index.symbolCount > 0) {
9194
+ actionsTaken.push(`Indexed ${index.symbolCount} AST symbols from ${index.provider}`);
9195
+ }
9196
+ } catch {}
9197
+ if (existsSync22(join19(root, ".git"))) {
9198
+ try {
9199
+ const hookRes = installGitHook(root);
9200
+ if (hookRes.installed) {
9201
+ actionsTaken.push(`Installed Git pre-commit transcript harvester hook`);
9202
+ }
9203
+ } catch {}
9204
+ }
9205
+ }
9206
+ return {
9207
+ repaired: true,
9208
+ actionsTaken,
9209
+ agentsConnected,
9210
+ memoryDir
9211
+ };
9212
+ }
9213
+ function executePackageUpgrade(pm, dryRun = false) {
9214
+ let cmd = "";
9215
+ switch (pm) {
9216
+ case "bun":
9217
+ cmd = "bun add -g musememory@latest";
9218
+ break;
9219
+ case "pnpm":
9220
+ cmd = "pnpm add -g musememory@latest";
9221
+ break;
9222
+ case "yarn":
9223
+ cmd = "yarn global add musememory@latest";
9224
+ break;
9225
+ default:
9226
+ cmd = "npm install -g musememory@latest";
9227
+ break;
9228
+ }
9229
+ if (!dryRun) {
9230
+ try {
9231
+ execSync2(cmd, { stdio: "inherit" });
9232
+ } catch (err) {
9233
+ throw new Error(`Failed running upgrade command "${cmd}": ${err.message || err}`);
9234
+ }
9235
+ }
9236
+ return cmd;
9237
+ }
9238
+ async function handleUpgradeCommand({ flags }) {
9239
+ const isGlobal = flags["global"] === "true" || flags["g"] === "true";
9240
+ const dryRun = flags["dry-run"] === "true";
9241
+ const force = flags["force"] === "true";
9242
+ const checkOnly = flags["check"] === "true";
9243
+ const pm = detectPackageManager();
9244
+ const currentVersion = "1.8.0";
9245
+ console.log(`[Upgrade] Checking for updates (detected package manager: ${pm})...`);
9246
+ const latestVersion = await getLatestNpmVersion();
9247
+ if (latestVersion) {
9248
+ console.log(` * Installed version: v${currentVersion}`);
9249
+ console.log(` * Latest release: v${latestVersion}`);
9250
+ }
9251
+ if (checkOnly) {
9252
+ if (latestVersion && latestVersion !== currentVersion) {
9253
+ console.log(`
9254
+ \uD83D\uDCA1 Update available: v${currentVersion} ➔ v${latestVersion}`);
9255
+ console.log(` Run 'memory upgrade' or '${pm === "bun" ? "bun add -g" : "npm install -g"} musememory@latest' to update.`);
9256
+ } else {
9257
+ console.log(`
9258
+ ✓ Muse Memory is up to date (v${currentVersion}).`);
9259
+ }
9260
+ return 0;
9261
+ }
9262
+ let repairInfo;
9263
+ const steps = [
9264
+ {
9265
+ level: 1,
9266
+ title: "Vibeguard Security & Credential Audit",
9267
+ action: async () => {}
9268
+ },
9269
+ {
9270
+ level: 2,
9271
+ title: `Package Manager Sync (${pm})`,
9272
+ action: async () => {
9273
+ if (!dryRun) {
9274
+ executePackageUpgrade(pm, dryRun);
9275
+ }
9276
+ }
9277
+ },
9278
+ {
9279
+ level: 3,
9280
+ title: "Synaptic Storage & Schema Alignment",
9281
+ action: async () => {
9282
+ repairInfo = await repairInstallation({ global: isGlobal });
9283
+ }
9284
+ },
9285
+ {
9286
+ level: 4,
9287
+ title: "80+ Agent Platforms & Skills Auto-Wiring",
9288
+ action: async () => {}
9289
+ },
9290
+ {
9291
+ level: 5,
9292
+ title: "Cognitive Ascendance Complete",
9293
+ action: async () => {}
9294
+ }
9295
+ ];
9296
+ await playGamifiedLoader(steps, { title: "SYSTEM LEVEL-UP & UPGRADE MATRIX" });
9297
+ console.log(`\uD83C\uDFC6 [LEVEL-UP COMPLETE] Muse Memory is now fully armed and up to date!`);
9298
+ if (repairInfo && repairInfo.actionsTaken.length > 0) {
9299
+ console.log(`
9300
+ \uD83D\uDD27 Self-Healing Actions Applied:`);
9301
+ for (const act of repairInfo.actionsTaken) {
9302
+ console.log(` ✓ ${act}`);
9303
+ }
9304
+ }
9305
+ console.log(`
9306
+ \uD83D\uDE80 Available Upgrade Commands for Reference:`);
9307
+ console.log(` • Bun: bun add -g musememory@latest`);
9308
+ console.log(` • NPM: npm install -g musememory@latest`);
9309
+ console.log(` • NPX: npx musememory@latest`);
9310
+ console.log(` • Auto: memory upgrade
9311
+ `);
9312
+ return 0;
9313
+ }
9314
+ var init_upgrade = __esm(() => {
9315
+ init_root();
9316
+ init_user();
9317
+ init_connect();
9318
+ init_graph();
9319
+ init_hook();
9320
+ });
9321
+
9031
9322
  // node_modules/ajv/dist/compile/codegen/code.js
9032
9323
  var require_code = __commonJS(function(exports) {
9033
9324
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -15329,8 +15620,8 @@ var require_ajv = __commonJS(function(exports, module) {
15329
15620
  });
15330
15621
 
15331
15622
  // src/schema.ts
15332
- import { existsSync as existsSync22, readFileSync as readFileSync18 } from "node:fs";
15333
- import { join as join19 } from "node:path";
15623
+ import { existsSync as existsSync23, readFileSync as readFileSync19 } from "node:fs";
15624
+ import { join as join20 } from "node:path";
15334
15625
  function getValidator() {
15335
15626
  if (cachedValidate)
15336
15627
  return cachedValidate;
@@ -15341,14 +15632,14 @@ function getValidator() {
15341
15632
  return !Number.isNaN(Date.parse(value));
15342
15633
  });
15343
15634
  const candidates = [
15344
- join19(import.meta.dir, "..", "schema.json"),
15345
- join19(import.meta.dir, "schema.json"),
15346
- join19(process.cwd(), "schema.json")
15635
+ join20(import.meta.dir, "..", "schema.json"),
15636
+ join20(import.meta.dir, "schema.json"),
15637
+ join20(process.cwd(), "schema.json")
15347
15638
  ];
15348
15639
  let schemaContent = null;
15349
15640
  for (const p of candidates) {
15350
- if (existsSync22(p)) {
15351
- schemaContent = readFileSync18(p, "utf8");
15641
+ if (existsSync23(p)) {
15642
+ schemaContent = readFileSync19(p, "utf8");
15352
15643
  break;
15353
15644
  }
15354
15645
  }
@@ -15461,13 +15752,13 @@ __export(exports_doctor, {
15461
15752
  printDoctorReport: () => printDoctorReport,
15462
15753
  runDoctor: () => runDoctor
15463
15754
  });
15464
- import { existsSync as existsSync23, statSync as statSync8, readFileSync as readFileSync19 } from "node:fs";
15465
- import { join as join20 } from "node:path";
15755
+ import { existsSync as existsSync24, statSync as statSync8, readFileSync as readFileSync20 } from "node:fs";
15756
+ import { join as join21 } from "node:path";
15466
15757
  import { homedir as homedir5 } from "node:os";
15467
15758
  async function runDoctor(targetDir, options = {}) {
15468
15759
  const home = homedir5();
15469
- const storagePath = options.global ? getGlobalMemoryDir() : findOrCreateProjectRoot(targetDir || process.cwd())?.memoryDir || join20(home, ".memory");
15470
- const isInitialized = existsSync23(storagePath);
15760
+ const storagePath = options.global ? getGlobalMemoryDir() : findOrCreateProjectRoot(targetDir || process.cwd())?.memoryDir || join21(home, ".memory");
15761
+ const isInitialized = existsSync24(storagePath);
15471
15762
  let currentMdExists = false;
15472
15763
  let currentMdLines = 0;
15473
15764
  let totalEntries = 0;
@@ -15485,10 +15776,10 @@ async function runDoctor(targetDir, options = {}) {
15485
15776
  let secretLeaksCount = 0;
15486
15777
  let brokenLinksCount = 0;
15487
15778
  if (isInitialized) {
15488
- const currentPath = join20(storagePath, "CURRENT.md");
15489
- if (existsSync23(currentPath)) {
15779
+ const currentPath = join21(storagePath, "CURRENT.md");
15780
+ if (existsSync24(currentPath)) {
15490
15781
  currentMdExists = true;
15491
- const content = readFileSync19(currentPath, "utf8");
15782
+ const content = readFileSync20(currentPath, "utf8");
15492
15783
  currentMdLines = content.split(`
15493
15784
  `).filter((l) => l.trim().length > 0).length;
15494
15785
  }
@@ -15509,12 +15800,12 @@ async function runDoctor(targetDir, options = {}) {
15509
15800
  valid = false;
15510
15801
  }
15511
15802
  }
15512
- const auditPath = join20(storagePath, "audit.jsonl");
15803
+ const auditPath = join21(storagePath, "audit.jsonl");
15513
15804
  let auditExists = false;
15514
15805
  let auditCount = 0;
15515
15806
  let auditSize = 0;
15516
15807
  let lastEvent;
15517
- if (existsSync23(auditPath)) {
15808
+ if (existsSync24(auditPath)) {
15518
15809
  auditExists = true;
15519
15810
  try {
15520
15811
  const stat = statSync8(auditPath);
@@ -15523,7 +15814,7 @@ async function runDoctor(targetDir, options = {}) {
15523
15814
  if (trail.length > 0) {
15524
15815
  lastEvent = `${trail[0].operation} on ${trail[0].entry_id} (${trail[0].timestamp})`;
15525
15816
  }
15526
- const raw = readFileSync19(auditPath, "utf8");
15817
+ const raw = readFileSync20(auditPath, "utf8");
15527
15818
  auditCount = raw.split(`
15528
15819
  `).filter((l) => l.trim().length > 0).length;
15529
15820
  } catch {}
@@ -15649,27 +15940,27 @@ var init_doctor = __esm(() => {
15649
15940
  });
15650
15941
 
15651
15942
  // src/retrieval/tree-index.ts
15652
- import { existsSync as existsSync24, readFileSync as readFileSync20, writeFileSync as writeFileSync11, mkdirSync as mkdirSync13, rmSync } from "node:fs";
15653
- import { join as join21 } from "node:path";
15943
+ import { existsSync as existsSync25, readFileSync as readFileSync21, writeFileSync as writeFileSync12, mkdirSync as mkdirSync14, rmSync } from "node:fs";
15944
+ import { join as join22 } from "node:path";
15654
15945
  function tokenize2(text) {
15655
15946
  if (!text || typeof text !== "string")
15656
15947
  return [];
15657
15948
  return text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
15658
15949
  }
15659
15950
  function indexDir(memoryDir) {
15660
- return join21(memoryDir, "tree-index");
15951
+ return join22(memoryDir, "tree-index");
15661
15952
  }
15662
15953
  function partitionDir(idxDir, project, type2) {
15663
- return join21(idxDir, project, type2);
15954
+ return join22(idxDir, project, type2);
15664
15955
  }
15665
15956
  function shardFilePath(pDir, shardId) {
15666
- return join21(pDir, `${shardId}.json`);
15957
+ return join22(pDir, `${shardId}.json`);
15667
15958
  }
15668
15959
  function partitionIndexFilePath(pDir) {
15669
- return join21(pDir, "index.json");
15960
+ return join22(pDir, "index.json");
15670
15961
  }
15671
15962
  function globalIndexFilePath(idxDir) {
15672
- return join21(idxDir, "index.json");
15963
+ return join22(idxDir, "index.json");
15673
15964
  }
15674
15965
  function nowIso3() {
15675
15966
  return new Date().toISOString();
@@ -15759,7 +16050,7 @@ function countNodes(node) {
15759
16050
  function buildTreeIndex(store, memoryDir, config = {}) {
15760
16051
  const cfg = { ...DEFAULT_CONFIG, ...config };
15761
16052
  const allMemories = list(store).filter((e) => e.status === "confirmed");
15762
- mkdirSync13(indexDir(memoryDir), { recursive: true });
16053
+ mkdirSync14(indexDir(memoryDir), { recursive: true });
15763
16054
  if (allMemories.length === 0) {
15764
16055
  const emptyIndex = {
15765
16056
  version: 1,
@@ -15768,7 +16059,7 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15768
16059
  totalMemories: 0,
15769
16060
  builtAt: nowIso3()
15770
16061
  };
15771
- writeFileSync11(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(emptyIndex, null, 2), "utf8");
16062
+ writeFileSync12(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(emptyIndex, null, 2), "utf8");
15772
16063
  return emptyIndex;
15773
16064
  }
15774
16065
  const groups = new Map;
@@ -15786,7 +16077,7 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15786
16077
  for (const [key, memories] of groups) {
15787
16078
  const [project, type2] = key.split("|");
15788
16079
  const pDir = partitionDir(indexDir(memoryDir), project, type2);
15789
- mkdirSync13(pDir, { recursive: true });
16080
+ mkdirSync14(pDir, { recursive: true });
15790
16081
  const maxShardSize = cfg.shardThreshold || 1e4;
15791
16082
  const finalShards = [];
15792
16083
  const memoryChunks = [];
@@ -15847,9 +16138,9 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15847
16138
  partitions[`${project}|${type2}`] = partition;
15848
16139
  totalIndexNodes += partitionNodes;
15849
16140
  totalIndexMemories += partitionMemories;
15850
- writeFileSync11(partitionIndexFilePath(pDir), JSON.stringify(partition, null, 2), "utf8");
16141
+ writeFileSync12(partitionIndexFilePath(pDir), JSON.stringify(partition, null, 2), "utf8");
15851
16142
  for (const shard of finalShards) {
15852
- writeFileSync11(shardFilePath(pDir, shard.id), JSON.stringify(shard, null, 2), "utf8");
16143
+ writeFileSync12(shardFilePath(pDir, shard.id), JSON.stringify(shard, null, 2), "utf8");
15853
16144
  }
15854
16145
  }
15855
16146
  const index = {
@@ -15859,15 +16150,15 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15859
16150
  totalMemories: totalIndexMemories,
15860
16151
  builtAt: nowIso3()
15861
16152
  };
15862
- writeFileSync11(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(index, null, 2), "utf8");
16153
+ writeFileSync12(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(index, null, 2), "utf8");
15863
16154
  return index;
15864
16155
  }
15865
16156
  function loadTreeIndex(memoryDir) {
15866
16157
  const path = globalIndexFilePath(indexDir(memoryDir));
15867
- if (!existsSync24(path))
16158
+ if (!existsSync25(path))
15868
16159
  return null;
15869
16160
  try {
15870
- const data = JSON.parse(readFileSync20(path, "utf8"));
16161
+ const data = JSON.parse(readFileSync21(path, "utf8"));
15871
16162
  return data.version === 1 ? data : null;
15872
16163
  } catch {
15873
16164
  return null;
@@ -16012,10 +16303,10 @@ __export(exports_vector, {
16012
16303
  saveIndex: () => saveIndex,
16013
16304
  termFrequencies: () => termFrequencies
16014
16305
  });
16015
- import { existsSync as existsSync25, readFileSync as readFileSync21, writeFileSync as writeFileSync12, mkdirSync as mkdirSync14 } from "node:fs";
16016
- import { join as join22 } from "node:path";
16306
+ import { existsSync as existsSync26, readFileSync as readFileSync22, writeFileSync as writeFileSync13, mkdirSync as mkdirSync15 } from "node:fs";
16307
+ import { join as join23 } from "node:path";
16017
16308
  function indexFilePath(memoryDir) {
16018
- return join22(memoryDir, "index.json");
16309
+ return join23(memoryDir, "index.json");
16019
16310
  }
16020
16311
  function hashTrigram(tri) {
16021
16312
  let h = 2166136261;
@@ -16062,16 +16353,16 @@ function rebuildIndex(store) {
16062
16353
  return index;
16063
16354
  }
16064
16355
  function saveIndex(index, memoryDir) {
16065
- if (!existsSync25(memoryDir))
16066
- mkdirSync14(memoryDir, { recursive: true });
16067
- writeFileSync12(indexFilePath(memoryDir), JSON.stringify(index), "utf8");
16356
+ if (!existsSync26(memoryDir))
16357
+ mkdirSync15(memoryDir, { recursive: true });
16358
+ writeFileSync13(indexFilePath(memoryDir), JSON.stringify(index), "utf8");
16068
16359
  }
16069
16360
  function loadIndex(memoryDir) {
16070
16361
  const p = indexFilePath(memoryDir);
16071
- if (!existsSync25(p))
16362
+ if (!existsSync26(p))
16072
16363
  return null;
16073
16364
  try {
16074
- const parsed = JSON.parse(readFileSync21(p, "utf8"));
16365
+ const parsed = JSON.parse(readFileSync22(p, "utf8"));
16075
16366
  return parsed.version === 1 ? parsed : null;
16076
16367
  } catch {
16077
16368
  return null;
@@ -16143,8 +16434,8 @@ var init_vector = __esm(() => {
16143
16434
  });
16144
16435
 
16145
16436
  // src/pageindex/engine.ts
16146
- import { existsSync as existsSync26, mkdirSync as mkdirSync15, readFileSync as readFileSync22, writeFileSync as writeFileSync13, rmSync as rmSync2, readdirSync as readdirSync9 } from "node:fs";
16147
- import { join as join23 } from "node:path";
16437
+ import { existsSync as existsSync27, mkdirSync as mkdirSync16, readFileSync as readFileSync23, writeFileSync as writeFileSync14, rmSync as rmSync2, readdirSync as readdirSync9 } from "node:fs";
16438
+ import { join as join24 } from "node:path";
16148
16439
  function slugify2(text) {
16149
16440
  return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 50);
16150
16441
  }
@@ -16221,9 +16512,9 @@ function buildPageIndex(content, options) {
16221
16512
  root: rootNode
16222
16513
  };
16223
16514
  if (options.memoryDir && !options.dryRun) {
16224
- const dir = join23(options.memoryDir, "pageindex", project);
16225
- mkdirSync15(dir, { recursive: true });
16226
- writeFileSync13(join23(dir, `${indexId}.json`), JSON.stringify(doc, null, 2), "utf8");
16515
+ const dir = join24(options.memoryDir, "pageindex", project);
16516
+ mkdirSync16(dir, { recursive: true });
16517
+ writeFileSync14(join24(dir, `${indexId}.json`), JSON.stringify(doc, null, 2), "utf8");
16227
16518
  }
16228
16519
  return doc;
16229
16520
  }
@@ -16287,29 +16578,29 @@ function searchPageIndex(doc, options) {
16287
16578
  };
16288
16579
  }
16289
16580
  function loadPageIndex(memoryDir, project, indexId) {
16290
- const filePath = join23(memoryDir, "pageindex", project, `${indexId}.json`);
16291
- if (!existsSync26(filePath))
16581
+ const filePath = join24(memoryDir, "pageindex", project, `${indexId}.json`);
16582
+ if (!existsSync27(filePath))
16292
16583
  return null;
16293
16584
  try {
16294
- return JSON.parse(readFileSync22(filePath, "utf8"));
16585
+ return JSON.parse(readFileSync23(filePath, "utf8"));
16295
16586
  } catch {
16296
16587
  return null;
16297
16588
  }
16298
16589
  }
16299
16590
  function listPageIndexes(memoryDir, project) {
16300
- const base = join23(memoryDir, "pageindex");
16301
- if (!existsSync26(base))
16591
+ const base = join24(memoryDir, "pageindex");
16592
+ if (!existsSync27(base))
16302
16593
  return [];
16303
16594
  const results = [];
16304
16595
  const projects = project ? [project] : readdirSync9(base);
16305
16596
  for (const p of projects) {
16306
- const pDir = join23(base, p);
16307
- if (!existsSync26(pDir))
16597
+ const pDir = join24(base, p);
16598
+ if (!existsSync27(pDir))
16308
16599
  continue;
16309
16600
  for (const f of readdirSync9(pDir)) {
16310
16601
  if (f.endsWith(".json")) {
16311
16602
  try {
16312
- results.push(JSON.parse(readFileSync22(join23(pDir, f), "utf8")));
16603
+ results.push(JSON.parse(readFileSync23(join24(pDir, f), "utf8")));
16313
16604
  } catch {}
16314
16605
  }
16315
16606
  }
@@ -16317,8 +16608,8 @@ function listPageIndexes(memoryDir, project) {
16317
16608
  return results;
16318
16609
  }
16319
16610
  function deletePageIndex(memoryDir, project, indexId) {
16320
- const base = join23(memoryDir, "pageindex");
16321
- if (!existsSync26(base))
16611
+ const base = join24(memoryDir, "pageindex");
16612
+ if (!existsSync27(base))
16322
16613
  return { deletedCount: 0 };
16323
16614
  let count = 0;
16324
16615
  if (!project && !indexId) {
@@ -16326,14 +16617,14 @@ function deletePageIndex(memoryDir, project, indexId) {
16326
16617
  return { deletedCount: 1 };
16327
16618
  }
16328
16619
  if (project && !indexId) {
16329
- const pDir = join23(base, project);
16330
- if (existsSync26(pDir)) {
16620
+ const pDir = join24(base, project);
16621
+ if (existsSync27(pDir)) {
16331
16622
  rmSync2(pDir, { recursive: true, force: true });
16332
16623
  count++;
16333
16624
  }
16334
16625
  } else if (project && indexId) {
16335
- const file = join23(base, project, `${indexId}.json`);
16336
- if (existsSync26(file)) {
16626
+ const file = join24(base, project, `${indexId}.json`);
16627
+ if (existsSync27(file)) {
16337
16628
  rmSync2(file, { force: true });
16338
16629
  count++;
16339
16630
  }
@@ -16346,13 +16637,13 @@ var init_engine2 = __esm(() => {
16346
16637
  });
16347
16638
 
16348
16639
  // src/retrieval/engine.ts
16349
- import { existsSync as existsSync27 } from "node:fs";
16350
- import { join as join24 } from "node:path";
16640
+ import { existsSync as existsSync28 } from "node:fs";
16641
+ import { join as join25 } from "node:path";
16351
16642
 
16352
16643
  class RetrievalEngine {
16353
16644
  static search(store, memoryDir, query, options = {}) {
16354
16645
  const mode = options.mode ?? "auto";
16355
- if (mode === "pageindex" || options.docPath && existsSync27(options.docPath)) {
16646
+ if (mode === "pageindex" || options.docPath && existsSync28(options.docPath)) {
16356
16647
  try {
16357
16648
  const docs = listPageIndexes(memoryDir, options.project);
16358
16649
  if (docs.length > 0) {
@@ -16379,8 +16670,8 @@ class RetrievalEngine {
16379
16670
  }
16380
16671
  } catch {}
16381
16672
  }
16382
- const treeDir = join24(memoryDir, "tree");
16383
- const hasTree = existsSync27(treeDir);
16673
+ const treeDir = join25(memoryDir, "tree");
16674
+ const hasTree = existsSync28(treeDir);
16384
16675
  const allEntries = list(store);
16385
16676
  if (mode === "tree" || mode === "auto" && hasTree && allEntries.length >= 500) {
16386
16677
  try {
@@ -16418,7 +16709,7 @@ class RetrievalEngine {
16418
16709
  } catch {}
16419
16710
  }
16420
16711
  const vecPath = indexFilePath(memoryDir);
16421
- const hasVec = existsSync27(vecPath);
16712
+ const hasVec = existsSync28(vecPath);
16422
16713
  if (mode === "hybrid" || mode === "auto" && hasVec && allEntries.length > 100) {
16423
16714
  try {
16424
16715
  const hybridResults = hybridSearch(store, memoryDir, query, {
@@ -26114,8 +26405,8 @@ var init_loops = __esm(() => {
26114
26405
  });
26115
26406
 
26116
26407
  // src/distill.ts
26117
- import { existsSync as existsSync28, mkdirSync as mkdirSync16, writeFileSync as writeFileSync14 } from "node:fs";
26118
- import { join as join25 } from "node:path";
26408
+ import { existsSync as existsSync29, mkdirSync as mkdirSync17, writeFileSync as writeFileSync15 } from "node:fs";
26409
+ import { join as join26 } from "node:path";
26119
26410
  function fixTokens(e) {
26120
26411
  const bag = tokenBag(e.title, 2);
26121
26412
  mergeBag(bag, tokenBag((e.tags ?? []).join(" "), 2));
@@ -26126,7 +26417,7 @@ function distillSkills(store, workspaceRoot, options = {}) {
26126
26417
  const report = { created: [], skippedExisting: [], clustersBelowThreshold: 0 };
26127
26418
  const fixes = list(store).filter((e) => e.status === "confirmed" && e.type === "fix").sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at));
26128
26419
  const clusters = clusterByTokenOverlap(fixes, fixTokens, 0.5);
26129
- const skillsDir = options.skillsDir ?? join25(workspaceRoot, ".agents", "skills");
26420
+ const skillsDir = options.skillsDir ?? join26(workspaceRoot, ".agents", "skills");
26130
26421
  for (const cluster of clusters) {
26131
26422
  if (cluster.length < minCount) {
26132
26423
  report.clustersBelowThreshold++;
@@ -26134,9 +26425,9 @@ function distillSkills(store, workspaceRoot, options = {}) {
26134
26425
  }
26135
26426
  const topic = dominantTopicTokens(cluster.map((e) => e.title));
26136
26427
  const slug = slugifyId(topic.join("-") || "skill");
26137
- const dir = join25(skillsDir, slug);
26428
+ const dir = join26(skillsDir, slug);
26138
26429
  const memberIds = cluster.map((e) => e.id);
26139
- if (existsSync28(dir)) {
26430
+ if (existsSync29(dir)) {
26140
26431
  report.skippedExisting.push({ slug, members: memberIds });
26141
26432
  continue;
26142
26433
  }
@@ -26146,10 +26437,10 @@ function distillSkills(store, workspaceRoot, options = {}) {
26146
26437
  throw new Error(`Secret detected in generated SKILL.md for '${slug}': ${secrets.join(", ")}`);
26147
26438
  }
26148
26439
  if (!options.dryRun) {
26149
- mkdirSync16(dir, { recursive: true });
26150
- writeFileSync14(join25(dir, "SKILL.md"), md, "utf8");
26440
+ mkdirSync17(dir, { recursive: true });
26441
+ writeFileSync15(join26(dir, "SKILL.md"), md, "utf8");
26151
26442
  }
26152
- report.created.push({ slug, path: join25(dir, "SKILL.md"), members: memberIds });
26443
+ report.created.push({ slug, path: join26(dir, "SKILL.md"), members: memberIds });
26153
26444
  }
26154
26445
  return report;
26155
26446
  }
@@ -26487,14 +26778,14 @@ var init_schema2 = __esm(() => {
26487
26778
  });
26488
26779
 
26489
26780
  // src/settings/loader.ts
26490
- import { existsSync as existsSync29, mkdirSync as mkdirSync17, readFileSync as readFileSync23, writeFileSync as writeFileSync15 } from "node:fs";
26491
- import { join as join26 } from "node:path";
26781
+ import { existsSync as existsSync30, mkdirSync as mkdirSync18, readFileSync as readFileSync24, writeFileSync as writeFileSync16 } from "node:fs";
26782
+ import { join as join27 } from "node:path";
26492
26783
  function getSettingsFilePath(memoryDir) {
26493
- return join26(memoryDir, "settings.json");
26784
+ return join27(memoryDir, "settings.json");
26494
26785
  }
26495
26786
  function loadSettings(memoryDir) {
26496
26787
  const filePath = getSettingsFilePath(memoryDir);
26497
- if (!existsSync29(filePath)) {
26788
+ if (!existsSync30(filePath)) {
26498
26789
  return {
26499
26790
  version: 1,
26500
26791
  global: JSON.parse(JSON.stringify(DEFAULT_SETTINGS)),
@@ -26502,7 +26793,7 @@ function loadSettings(memoryDir) {
26502
26793
  };
26503
26794
  }
26504
26795
  try {
26505
- const raw = readFileSync23(filePath, "utf8");
26796
+ const raw = readFileSync24(filePath, "utf8");
26506
26797
  const parsed = JSON.parse(raw);
26507
26798
  return {
26508
26799
  version: parsed.version || 1,
@@ -26518,9 +26809,9 @@ function loadSettings(memoryDir) {
26518
26809
  }
26519
26810
  }
26520
26811
  function saveSettings(store, memoryDir) {
26521
- mkdirSync17(memoryDir, { recursive: true });
26812
+ mkdirSync18(memoryDir, { recursive: true });
26522
26813
  const filePath = getSettingsFilePath(memoryDir);
26523
- writeFileSync15(filePath, JSON.stringify(store, null, 2), "utf8");
26814
+ writeFileSync16(filePath, JSON.stringify(store, null, 2), "utf8");
26524
26815
  }
26525
26816
  function getSettings(memoryDir) {
26526
26817
  return loadSettings(memoryDir).global;
@@ -26636,17 +26927,17 @@ __export(exports_plasticity, {
26636
26927
  recordCoActivation: () => recordCoActivation,
26637
26928
  saveHebbianGraph: () => saveHebbianGraph
26638
26929
  });
26639
- import { existsSync as existsSync30, readFileSync as readFileSync24, writeFileSync as writeFileSync16 } from "node:fs";
26640
- import { join as join27 } from "node:path";
26930
+ import { existsSync as existsSync31, readFileSync as readFileSync25, writeFileSync as writeFileSync17 } from "node:fs";
26931
+ import { join as join28 } from "node:path";
26641
26932
  function getPlasticityPath(memoryDir) {
26642
- return join27(memoryDir, "hebbian-plasticity.json");
26933
+ return join28(memoryDir, "hebbian-plasticity.json");
26643
26934
  }
26644
26935
  function loadHebbianGraph(memoryDir) {
26645
26936
  const p = getPlasticityPath(memoryDir);
26646
- if (!existsSync30(p))
26937
+ if (!existsSync31(p))
26647
26938
  return {};
26648
26939
  try {
26649
- return JSON.parse(readFileSync24(p, "utf8"));
26940
+ return JSON.parse(readFileSync25(p, "utf8"));
26650
26941
  } catch {
26651
26942
  return {};
26652
26943
  }
@@ -26654,7 +26945,7 @@ function loadHebbianGraph(memoryDir) {
26654
26945
  function saveHebbianGraph(memoryDir, graph) {
26655
26946
  const p = getPlasticityPath(memoryDir);
26656
26947
  try {
26657
- writeFileSync16(p, JSON.stringify(graph, null, 2), "utf8");
26948
+ writeFileSync17(p, JSON.stringify(graph, null, 2), "utf8");
26658
26949
  } catch {}
26659
26950
  }
26660
26951
  function recordCoActivation(memoryIds, memoryDir) {
@@ -26744,9 +27035,9 @@ __export(exports_drift, {
26744
27035
  scanCodeDrift: () => scanCodeDrift,
26745
27036
  scanCodeDriftFromDiff: () => scanCodeDriftFromDiff
26746
27037
  });
26747
- import { execSync as execSync2 } from "node:child_process";
26748
- import { existsSync as existsSync31 } from "node:fs";
26749
- import { join as join28, isAbsolute as isAbsolute2 } from "node:path";
27038
+ import { execSync as execSync3 } from "node:child_process";
27039
+ import { existsSync as existsSync32 } from "node:fs";
27040
+ import { join as join29, isAbsolute as isAbsolute2 } from "node:path";
26750
27041
  function scanCodeDriftFromDiff(entries, changedFiles, workspaceRoot) {
26751
27042
  const root = workspaceRoot || process.cwd();
26752
27043
  const normalizedChanged = new Set(changedFiles.map((f) => f.trim().replace(/^[\.\/]+/, "")).filter(Boolean));
@@ -26760,8 +27051,8 @@ function scanCodeDriftFromDiff(entries, changedFiles, workspaceRoot) {
26760
27051
  const norm = p.trim().replace(/^[\.\/]+/, "");
26761
27052
  const matched = Array.from(normalizedChanged).find((cf) => cf === norm || cf.endsWith(`/${norm}`) || norm.endsWith(`/${cf}`));
26762
27053
  if (matched) {
26763
- const fullPath = isAbsolute2(p) ? p : join28(root, p);
26764
- const exists = existsSync31(fullPath);
27054
+ const fullPath = isAbsolute2(p) ? p : join29(root, p);
27055
+ const exists = existsSync32(fullPath);
26765
27056
  drifted.push({
26766
27057
  memoryId: entry.id,
26767
27058
  title: entry.title,
@@ -26785,7 +27076,7 @@ function scanCodeDriftFromDiff(entries, changedFiles, workspaceRoot) {
26785
27076
  function getGitChangedFiles(workspaceRoot) {
26786
27077
  const root = workspaceRoot || process.cwd();
26787
27078
  try {
26788
- const stdout = execSync2("git status --porcelain", {
27079
+ const stdout = execSync3("git status --porcelain", {
26789
27080
  cwd: root,
26790
27081
  encoding: "utf8",
26791
27082
  stdio: ["ignore", "pipe", "ignore"]
@@ -26802,7 +27093,7 @@ function getGitChangedFiles(workspaceRoot) {
26802
27093
  files.push(filePath);
26803
27094
  }
26804
27095
  try {
26805
- const diffOut = execSync2("git diff --name-only HEAD", {
27096
+ const diffOut = execSync3("git diff --name-only HEAD", {
26806
27097
  cwd: root,
26807
27098
  encoding: "utf8",
26808
27099
  stdio: ["ignore", "pipe", "ignore"]
@@ -28023,8 +28314,8 @@ __export(exports_daemon, {
28023
28314
  startHub: () => startHub
28024
28315
  });
28025
28316
  import { createServer as createServer2 } from "node:http";
28026
- import { existsSync as existsSync32 } from "node:fs";
28027
- import { join as join29 } from "node:path";
28317
+ import { existsSync as existsSync33 } from "node:fs";
28318
+ import { join as join30 } from "node:path";
28028
28319
  import { watch } from "node:fs";
28029
28320
  function startHub(port, memoryDir) {
28030
28321
  const clients = new Set;
@@ -28090,7 +28381,7 @@ data: ${JSON.stringify(event)}
28090
28381
  return clients.size;
28091
28382
  }
28092
28383
  if (memoryDir) {
28093
- const memoriesDir = join29(memoryDir, "memories");
28384
+ const memoriesDir = join30(memoryDir, "memories");
28094
28385
  const armDebounced = (type2) => {
28095
28386
  if (debounceTimer)
28096
28387
  clearTimeout(debounceTimer);
@@ -28099,11 +28390,11 @@ data: ${JSON.stringify(event)}
28099
28390
  }, DEBOUNCE_MS);
28100
28391
  };
28101
28392
  try {
28102
- if (existsSync32(memoriesDir)) {
28393
+ if (existsSync33(memoriesDir)) {
28103
28394
  watchers.push(watch(memoriesDir, () => armDebounced("memory.changed")));
28104
28395
  }
28105
- const currentMd = join29(memoryDir, "CURRENT.md");
28106
- if (existsSync32(currentMd)) {
28396
+ const currentMd = join30(memoryDir, "CURRENT.md");
28397
+ if (existsSync33(currentMd)) {
28107
28398
  watchers.push(watch(currentMd, () => armDebounced("constraints.changed")));
28108
28399
  }
28109
28400
  } catch {}
@@ -28136,19 +28427,19 @@ var DEBOUNCE_MS = 300;
28136
28427
  var init_daemon = () => {};
28137
28428
 
28138
28429
  // src/cli/ecosystem.ts
28139
- import { join as join30 } from "node:path";
28140
- import { existsSync as existsSync33, mkdirSync as mkdirSync18, writeFileSync as writeFileSync17, readFileSync as readFileSync25 } from "node:fs";
28430
+ import { join as join31 } from "node:path";
28431
+ import { existsSync as existsSync34, mkdirSync as mkdirSync19, writeFileSync as writeFileSync18, readFileSync as readFileSync26 } from "node:fs";
28141
28432
  import { homedir as homedir6 } from "node:os";
28142
28433
  function ensureProjectAgentInstructions(targetDir) {
28143
- const agentsMdPath = join30(targetDir, "AGENTS.md");
28144
- if (existsSync33(agentsMdPath)) {
28434
+ const agentsMdPath = join31(targetDir, "AGENTS.md");
28435
+ if (existsSync34(agentsMdPath)) {
28145
28436
  try {
28146
- const existing = readFileSync25(agentsMdPath, "utf8");
28437
+ const existing = readFileSync26(agentsMdPath, "utf8");
28147
28438
  if (existing.includes("<!-- agentmemory:start -->")) {
28148
28439
  const updated = existing.replace(/<!-- agentmemory:start -->[\s\S]*?<!-- agentmemory:end -->/, MUSE_MEMORY_DIRECTIVE);
28149
- writeFileSync17(agentsMdPath, updated, "utf8");
28440
+ writeFileSync18(agentsMdPath, updated, "utf8");
28150
28441
  } else if (!existing.includes("<!-- musememory:start -->") && !existing.includes("Muse Memory")) {
28151
- writeFileSync17(agentsMdPath, `${existing.trim()}
28442
+ writeFileSync18(agentsMdPath, `${existing.trim()}
28152
28443
 
28153
28444
  ${MUSE_MEMORY_DIRECTIVE}
28154
28445
  `, "utf8");
@@ -28159,23 +28450,23 @@ ${MUSE_MEMORY_DIRECTIVE}
28159
28450
 
28160
28451
  ${MUSE_MEMORY_DIRECTIVE}
28161
28452
  `;
28162
- writeFileSync17(agentsMdPath, initialContent, "utf8");
28453
+ writeFileSync18(agentsMdPath, initialContent, "utf8");
28163
28454
  }
28164
28455
  }
28165
28456
  async function handleInstallCommand({ positional, flags }) {
28166
28457
  const isGlobal = flags["global"] === "true" || flags["g"] === "true";
28167
- const targetDir = positional[0] ? join30(process.cwd(), positional[0]) : process.cwd();
28168
- const memoryDir = isGlobal ? getGlobalMemoryDir() : join30(targetDir, ".memory");
28458
+ const targetDir = positional[0] ? join31(process.cwd(), positional[0]) : process.cwd();
28459
+ const memoryDir = isGlobal ? getGlobalMemoryDir() : join31(targetDir, ".memory");
28169
28460
  const globalDir = getGlobalMemoryDir();
28170
- mkdirSync18(join30(memoryDir, "memories"), { recursive: true });
28171
- mkdirSync18(join30(globalDir, "memories"), { recursive: true });
28172
- const currentPath = join30(memoryDir, "CURRENT.md");
28173
- if (!existsSync33(currentPath)) {
28174
- writeFileSync17(currentPath, `# Active Project Constraints
28461
+ mkdirSync19(join31(memoryDir, "memories"), { recursive: true });
28462
+ mkdirSync19(join31(globalDir, "memories"), { recursive: true });
28463
+ const currentPath = join31(memoryDir, "CURRENT.md");
28464
+ if (!existsSync34(currentPath)) {
28465
+ writeFileSync18(currentPath, `# Active Project Constraints
28175
28466
  `, "utf8");
28176
28467
  }
28177
28468
  const globalUserPath = userFilePath(globalDir);
28178
- if (!existsSync33(globalUserPath)) {
28469
+ if (!existsSync34(globalUserPath)) {
28179
28470
  const { promptSingleSelect: promptSingleSelect2 } = await Promise.resolve().then(() => (init_prompt(), exports_prompt));
28180
28471
  const archetypeOptions = [
28181
28472
  { id: "developer", label: "Software Engineer / Developer", hint: "Code-first, direct, strict typing" },
@@ -28191,45 +28482,78 @@ async function handleInstallCommand({ positional, flags }) {
28191
28482
  if (!isGlobal) {
28192
28483
  ensureProjectAgentInstructions(targetDir);
28193
28484
  }
28194
- const globalAgentsMd = join30(homedir6(), ".agents", "AGENTS.md");
28195
- if (existsSync33(globalAgentsMd)) {
28485
+ const globalAgentsMd = join31(homedir6(), ".agents", "AGENTS.md");
28486
+ if (existsSync34(globalAgentsMd)) {
28196
28487
  try {
28197
- const existing = readFileSync25(globalAgentsMd, "utf8");
28488
+ const existing = readFileSync26(globalAgentsMd, "utf8");
28198
28489
  if (existing.includes("<!-- agentmemory:start -->")) {
28199
28490
  const updated = existing.replace(/<!-- agentmemory:start -->[\s\S]*?<!-- agentmemory:end -->/, MUSE_MEMORY_DIRECTIVE);
28200
- writeFileSync17(globalAgentsMd, updated, "utf8");
28491
+ writeFileSync18(globalAgentsMd, updated, "utf8");
28201
28492
  }
28202
28493
  } catch {}
28203
28494
  }
28495
+ const { playGamifiedLoader: playGamifiedLoader2 } = await Promise.resolve().then(() => (init_upgrade(), exports_upgrade));
28496
+ let reports = [];
28497
+ let detected = [];
28498
+ const installSteps = [
28499
+ {
28500
+ level: 1,
28501
+ title: "Storage Layout & Memory Directory Scaffold",
28502
+ action: async () => {}
28503
+ },
28504
+ {
28505
+ level: 2,
28506
+ title: "80+ Coding Agent Auto-Wiring Matrix",
28507
+ action: async () => {
28508
+ const { connectAgent: connectAgent2 } = await Promise.resolve().then(() => (init_connect(), exports_connect));
28509
+ reports = connectAgent2("all", undefined, { dryRun: false, force: false });
28510
+ }
28511
+ },
28512
+ {
28513
+ level: 3,
28514
+ title: "External Memory Provider Probe (24+ Formats)",
28515
+ action: async () => {
28516
+ detected = detectProviders(targetDir).filter((p) => p.detected);
28517
+ }
28518
+ },
28519
+ {
28520
+ level: 4,
28521
+ title: "Git Pre-Commit Harvester Verification",
28522
+ action: async () => {
28523
+ if (!isGlobal) {
28524
+ await promptOrNotifyGitHook(targetDir, flags["auto"] === "true" || flags["yes"] === "true");
28525
+ }
28526
+ }
28527
+ },
28528
+ {
28529
+ level: 5,
28530
+ title: "Cognitive Onboarding Ready",
28531
+ action: async () => {}
28532
+ }
28533
+ ];
28204
28534
  console.log(`[+] Initialized Muse Memory in ${memoryDir}`);
28205
- const { connectAgent: connectAgent2 } = await Promise.resolve().then(() => (init_connect(), exports_connect));
28206
- const reports = connectAgent2("all", undefined, { dryRun: false, force: false });
28535
+ await playGamifiedLoader2(installSteps, { title: "AUTONOMOUS ONBOARDING MATRIX" });
28207
28536
  if (reports.length > 0) {
28208
- console.log(`
28209
- [+] Auto-wired ${reports.length} detected coding agent(s) with zero permissions:`);
28537
+ console.log(`[+] Auto-wired ${reports.length} detected coding agent(s) with zero permissions:`);
28210
28538
  for (const r of reports) {
28211
28539
  console.log(` * ${r.agentName}: ${r.message}`);
28212
28540
  }
28213
28541
  }
28214
- const detected = detectProviders(targetDir).filter((p) => p.detected);
28215
28542
  if (detected.length > 0) {
28216
28543
  console.log(`
28217
28544
  [!] Detected ${detected.length} external memory provider(s): ${detected.map((d) => d.name).join(", ")}`);
28218
28545
  console.log(` -> Run 'memory migrate' to auto-import legacy memories.`);
28219
28546
  }
28220
- if (!isGlobal) {
28221
- await promptOrNotifyGitHook(targetDir, flags["auto"] === "true" || flags["yes"] === "true");
28222
- }
28223
28547
  console.log(`
28224
- [OK] Muse Memory is ready! Use 'memory doctor' to verify system health.`);
28548
+ [OK] Muse Memory is initialized and ready! Use 'memory doctor' to verify health.`);
28225
28549
  return 0;
28226
28550
  }
28227
28551
  async function promptOrNotifyGitHook(targetDir, autoInstall = false) {
28228
- const gitDir = join30(targetDir, ".git");
28229
- if (!existsSync33(gitDir))
28552
+ const gitDir = join31(targetDir, ".git");
28553
+ if (!existsSync34(gitDir))
28230
28554
  return false;
28231
- const hookPath = join30(gitDir, "hooks", "pre-commit");
28232
- const isInstalled = existsSync33(hookPath) && readFileSync25(hookPath, "utf8").includes("memory harvest-auto");
28555
+ const hookPath = join31(gitDir, "hooks", "pre-commit");
28556
+ const isInstalled = existsSync34(hookPath) && readFileSync26(hookPath, "utf8").includes("memory harvest-auto");
28233
28557
  if (isInstalled)
28234
28558
  return true;
28235
28559
  if (autoInstall) {
@@ -28255,44 +28579,75 @@ async function handleDoctorCommand({ positional, flags }) {
28255
28579
  return report.validation.valid ? 0 : 1;
28256
28580
  }
28257
28581
  async function handleUninstallCommand({ positional, flags }) {
28582
+ const { playGamifiedLoader: playGamifiedLoader2 } = await Promise.resolve().then(() => (init_upgrade(), exports_upgrade));
28258
28583
  const { disconnectAllAgents: disconnectAllAgents2, disconnectSingleAgent: disconnectSingleAgent2 } = await Promise.resolve().then(() => (init_connect(), exports_connect));
28259
28584
  const agent = positional[0];
28260
28585
  const purge = flags["purge"] === "true";
28261
28586
  const dryRun = flags["dry-run"] === "true";
28587
+ let unwiredReports = [];
28588
+ const uninstallSteps = [
28589
+ {
28590
+ level: 1,
28591
+ title: "Agent Platform Discovery & Configuration Lock",
28592
+ action: async () => {}
28593
+ },
28594
+ {
28595
+ level: 2,
28596
+ title: `Unwiring Agent Platforms (${agent || "all"})`,
28597
+ action: async () => {
28598
+ if (agent && agent !== "all") {
28599
+ const report = disconnectSingleAgent2(agent, undefined, { dryRun });
28600
+ unwiredReports = [report];
28601
+ } else {
28602
+ unwiredReports = disconnectAllAgents2(undefined, { dryRun });
28603
+ }
28604
+ }
28605
+ },
28606
+ {
28607
+ level: 3,
28608
+ title: purge ? "Purging Memory Store (.memory/)" : "Preserving Cognitive Memory Store (.memory/)",
28609
+ action: async () => {
28610
+ if (purge) {
28611
+ const ctx = requireRoot(flags);
28612
+ if (ctx && existsSync34(ctx.memoryDir) && !dryRun) {
28613
+ const { rmSync: rmSync3 } = await import("node:fs");
28614
+ rmSync3(ctx.memoryDir, { recursive: true, force: true });
28615
+ }
28616
+ }
28617
+ }
28618
+ },
28619
+ {
28620
+ level: 4,
28621
+ title: "Clean Teardown Verification",
28622
+ action: async () => {}
28623
+ }
28624
+ ];
28262
28625
  console.log(`[CLEAN] Running Muse Memory Uninstaller${dryRun ? " [DRY RUN]" : ""}...`);
28263
- if (agent && agent !== "all") {
28264
- const report = disconnectSingleAgent2(agent, undefined, { dryRun });
28265
- console.log(` * ${report.agentName}: ${report.message}`);
28266
- } else {
28267
- const reports = disconnectAllAgents2(undefined, { dryRun });
28268
- console.log(`
28269
- [+] Unwired ${reports.length} coding agent(s):`);
28270
- for (const r of reports) {
28626
+ await playGamifiedLoader2(uninstallSteps, { title: `SYSTEM UNINSTALL MATRIX${dryRun ? " [DRY RUN]" : ""}` });
28627
+ if (unwiredReports.length > 0) {
28628
+ console.log(`[+] Unwired ${unwiredReports.length} coding agent(s):`);
28629
+ for (const r of unwiredReports) {
28271
28630
  console.log(` * ${r.agentName}: ${r.message}`);
28272
28631
  }
28273
28632
  }
28274
28633
  if (purge) {
28275
- const ctx = requireRoot(flags);
28276
- if (ctx && existsSync33(ctx.memoryDir) && !dryRun) {
28277
- const { rmSync: rmSync3 } = await import("node:fs");
28278
- rmSync3(ctx.memoryDir, { recursive: true, force: true });
28279
- console.log(` [PURGED] Memory directory removed: ${ctx.memoryDir}`);
28280
- }
28634
+ console.log(`
28635
+ [PURGED] Memory directory removed successfully.`);
28281
28636
  } else {
28282
28637
  console.log(`
28283
- [INFO] Memory files preserved in .memory/. Use 'memory uninstall --purge' to remove data.`);
28638
+ [INFO] Memory files preserved in .memory/. (Use 'memory uninstall --purge' to remove data).`);
28284
28639
  }
28285
28640
  return 0;
28286
28641
  }
28287
28642
  async function handleInitCommand({ positional, flags }) {
28288
28643
  const isGlobal = flags["global"] === "true";
28289
- const targetDir = positional[0] ? join30(process.cwd(), positional[0]) : process.cwd();
28644
+ const targetDir = positional[0] ? join31(process.cwd(), positional[0]) : process.cwd();
28290
28645
  const memoryDirName = flags["legacy"] === "true" ? ".musememory" : ".memory";
28291
- const memoryDir = isGlobal ? getGlobalMemoryDir() : join30(targetDir, memoryDirName);
28292
- mkdirSync18(join30(memoryDir, "memories"), { recursive: true });
28293
- const currentPath = join30(memoryDir, "CURRENT.md");
28294
- if (!existsSync33(currentPath)) {
28295
- writeFileSync17(currentPath, `# Active Project Constraints
28646
+ const memoryDir = isGlobal ? getGlobalMemoryDir() : join31(targetDir, memoryDirName);
28647
+ mkdirSync19(join31(memoryDir, "memories"), { recursive: true });
28648
+ const currentPath = join31(memoryDir, "CURRENT.md");
28649
+ if (!existsSync34(currentPath)) {
28650
+ writeFileSync18(currentPath, `# Active Project Constraints
28296
28651
  `, "utf8");
28297
28652
  }
28298
28653
  if (!isGlobal) {
@@ -28576,8 +28931,8 @@ var init_ecosystem = __esm(() => {
28576
28931
  });
28577
28932
 
28578
28933
  // src/agentcontract.ts
28579
- import { existsSync as existsSync34 } from "node:fs";
28580
- import { join as join31 } from "node:path";
28934
+ import { existsSync as existsSync35 } from "node:fs";
28935
+ import { join as join32 } from "node:path";
28581
28936
  function parseAgentMemoryContract(markdown) {
28582
28937
  if (!markdown || !markdown.startsWith("---"))
28583
28938
  return null;
@@ -28609,17 +28964,17 @@ function parseAgentMemoryContract(markdown) {
28609
28964
  function resolveAgentFile(nameOrPath, workspaceRoot) {
28610
28965
  if (!nameOrPath)
28611
28966
  return null;
28612
- if (existsSync34(nameOrPath))
28967
+ if (existsSync35(nameOrPath))
28613
28968
  return nameOrPath;
28614
28969
  const candidates = [
28615
- join31(workspaceRoot, ".agents", `${nameOrPath}.md`),
28616
- join31(workspaceRoot, ".memory", "agents", `${nameOrPath}.md`)
28970
+ join32(workspaceRoot, ".agents", `${nameOrPath}.md`),
28971
+ join32(workspaceRoot, ".memory", "agents", `${nameOrPath}.md`)
28617
28972
  ];
28618
28973
  const home = process.env.HOME;
28619
28974
  if (home)
28620
- candidates.push(join31(home, ".config", "opencode", "agents", `${nameOrPath}.md`));
28975
+ candidates.push(join32(home, ".config", "opencode", "agents", `${nameOrPath}.md`));
28621
28976
  for (const c of candidates) {
28622
- if (existsSync34(c))
28977
+ if (existsSync35(c))
28623
28978
  return c;
28624
28979
  }
28625
28980
  return null;
@@ -28629,8 +28984,8 @@ var init_agentcontract = __esm(() => {
28629
28984
  });
28630
28985
 
28631
28986
  // src/cli/retrieval.ts
28632
- import { existsSync as existsSync35, readFileSync as readFileSync26 } from "node:fs";
28633
- import { join as join32 } from "node:path";
28987
+ import { existsSync as existsSync36, readFileSync as readFileSync27 } from "node:fs";
28988
+ import { join as join33 } from "node:path";
28634
28989
  async function handleContextCommand({ positional, flags }) {
28635
28990
  let agentTypes;
28636
28991
  let agentTags;
@@ -28638,7 +28993,7 @@ async function handleContextCommand({ positional, flags }) {
28638
28993
  const file = resolveAgentFile(flags["for-agent"], flags["dir"] ?? process.cwd());
28639
28994
  if (!file)
28640
28995
  return usageError(`--for-agent: cannot resolve agent '${flags["for-agent"]}'`);
28641
- const contract = parseAgentMemoryContract(readFileSync26(file, "utf8"));
28996
+ const contract = parseAgentMemoryContract(readFileSync27(file, "utf8"));
28642
28997
  if (contract) {
28643
28998
  agentTypes = contract.types;
28644
28999
  agentTags = contract.tags;
@@ -28778,7 +29133,7 @@ async function handleHarvestCommand({ positional, flags }) {
28778
29133
  const project = flags["project"];
28779
29134
  if (!project)
28780
29135
  return usageError("harvest requires --project");
28781
- const rawText = existsSync35(target) ? readFileSync26(target, "utf8") : target;
29136
+ const rawText = existsSync36(target) ? readFileSync27(target, "utf8") : target;
28782
29137
  const created = harvestMemories(ctx.store, {
28783
29138
  text: rawText,
28784
29139
  project,
@@ -28814,8 +29169,8 @@ async function handleSearchTranscriptCommand({ positional, flags }) {
28814
29169
  const filePath = positional[1];
28815
29170
  if (!query)
28816
29171
  return usageError("search-transcript requires <query> [file.jsonl]");
28817
- const targetFile = filePath ? filePath.startsWith("/") ? filePath : join32(process.cwd(), filePath) : join32(process.cwd(), "transcript.jsonl");
28818
- if (!existsSync35(targetFile)) {
29172
+ const targetFile = filePath ? filePath.startsWith("/") ? filePath : join33(process.cwd(), filePath) : join33(process.cwd(), "transcript.jsonl");
29173
+ if (!existsSync36(targetFile)) {
28819
29174
  return fail(`error: transcript file not found: ${targetFile}`);
28820
29175
  }
28821
29176
  const windowSize = flags["window"] ? parseInt(flags["window"], 10) : 2;
@@ -28831,7 +29186,7 @@ async function handleReindexCommand({ flags }) {
28831
29186
  const { rebuildIndex: rebuildIndex2, saveIndex: saveIndex2 } = await Promise.resolve().then(() => (init_vector(), exports_vector));
28832
29187
  const index = rebuildIndex2(ctx.store);
28833
29188
  saveIndex2(index, ctx.memoryDir);
28834
- console.log(`indexed ${Object.keys(index.entries).length} entries -> ${join32(ctx.memoryDir, "index.json")}`);
29189
+ console.log(`indexed ${Object.keys(index.entries).length} entries -> ${join33(ctx.memoryDir, "index.json")}`);
28835
29190
  return 0;
28836
29191
  }
28837
29192
  async function handleHookCommand({ positional, flags }) {
@@ -29222,7 +29577,7 @@ var init_entities2 = __esm(() => {
29222
29577
  });
29223
29578
 
29224
29579
  // src/cli/settings.ts
29225
- import { writeFileSync as writeFileSync18, readFileSync as readFileSync27 } from "node:fs";
29580
+ import { writeFileSync as writeFileSync19, readFileSync as readFileSync28 } from "node:fs";
29226
29581
  function handleSettingsCommand(parsed) {
29227
29582
  const ctx = requireRoot(parsed.flags);
29228
29583
  if (!ctx)
@@ -29304,7 +29659,7 @@ function handleSettingsCommand(parsed) {
29304
29659
  const out = parsed.flags.out;
29305
29660
  const json2 = exportSettings(memoryDir);
29306
29661
  if (out) {
29307
- writeFileSync18(out, json2, "utf8");
29662
+ writeFileSync19(out, json2, "utf8");
29308
29663
  console.log(`Exported settings to ${out}`);
29309
29664
  } else {
29310
29665
  console.log(json2);
@@ -29318,7 +29673,7 @@ function handleSettingsCommand(parsed) {
29318
29673
  return 2;
29319
29674
  }
29320
29675
  try {
29321
- const raw = readFileSync27(file, "utf8");
29676
+ const raw = readFileSync28(file, "utf8");
29322
29677
  importSettings(memoryDir, raw);
29323
29678
  console.log(`Successfully imported settings from ${file}`);
29324
29679
  return 0;
@@ -29341,16 +29696,16 @@ var init_nudge = __esm(() => {
29341
29696
  });
29342
29697
 
29343
29698
  // src/routines.ts
29344
- import { readFileSync as readFileSync28, existsSync as existsSync36 } from "node:fs";
29345
- import { join as join33 } from "node:path";
29699
+ import { readFileSync as readFileSync29, existsSync as existsSync37 } from "node:fs";
29700
+ import { join as join34 } from "node:path";
29346
29701
  function routinesPath(memoryDir) {
29347
- return join33(memoryDir, "routines.yaml");
29702
+ return join34(memoryDir, "routines.yaml");
29348
29703
  }
29349
29704
  function loadRoutines(memoryDir) {
29350
29705
  const p = routinesPath(memoryDir);
29351
- if (!existsSync36(p))
29706
+ if (!existsSync37(p))
29352
29707
  return { routines: {} };
29353
- const doc2 = yaml.load(readFileSync28(p, "utf8"), { schema: yaml.JSON_SCHEMA }) ?? {};
29708
+ const doc2 = yaml.load(readFileSync29(p, "utf8"), { schema: yaml.JSON_SCHEMA }) ?? {};
29354
29709
  const routines = doc2.routines ?? {};
29355
29710
  for (const [name, r] of Object.entries(routines)) {
29356
29711
  if (!r || typeof r.schedule !== "string" || !r.schedule.trim()) {
@@ -29388,7 +29743,7 @@ var init_routines = __esm(() => {
29388
29743
  });
29389
29744
 
29390
29745
  // src/cli/lifecycle.ts
29391
- import { writeFileSync as writeFileSync19, readFileSync as readFileSync29, existsSync as existsSync37 } from "node:fs";
29746
+ import { writeFileSync as writeFileSync20, readFileSync as readFileSync30, existsSync as existsSync38 } from "node:fs";
29392
29747
  async function handleProposeCommand({ positional, flags }) {
29393
29748
  const ctx = requireRoot(flags);
29394
29749
  if (!ctx)
@@ -29537,7 +29892,7 @@ async function handleExportCommand({ flags }) {
29537
29892
  const snapshot = exportSnapshot(ctx.store);
29538
29893
  const outPath = flags["out"];
29539
29894
  if (outPath) {
29540
- writeFileSync19(outPath, JSON.stringify(snapshot, null, 2), "utf8");
29895
+ writeFileSync20(outPath, JSON.stringify(snapshot, null, 2), "utf8");
29541
29896
  console.log(`exported ${snapshot.total} memories to ${outPath}`);
29542
29897
  } else {
29543
29898
  console.log(JSON.stringify(snapshot, null, 2));
@@ -29551,9 +29906,9 @@ async function handleImportCommand({ positional, flags }) {
29551
29906
  const file = positional[0];
29552
29907
  if (!file)
29553
29908
  return usageError("import requires <file.json>");
29554
- if (!existsSync37(file))
29909
+ if (!existsSync38(file))
29555
29910
  return fail(`error: file ${file} does not exist`);
29556
- const raw = JSON.parse(readFileSync29(file, "utf8"));
29911
+ const raw = JSON.parse(readFileSync30(file, "utf8"));
29557
29912
  const res = importSnapshot(ctx.store, raw, { overwrite: flags["overwrite"] === "true" });
29558
29913
  if (res.errors.length > 0) {
29559
29914
  console.error(`import encountered errors:`);
@@ -29918,6 +30273,9 @@ async function main(argv) {
29918
30273
  switch (cmd) {
29919
30274
  case "install":
29920
30275
  return handleInstallCommand(parsed);
30276
+ case "upgrade":
30277
+ case "update":
30278
+ return handleUpgradeCommand(parsed);
29921
30279
  case "doctor":
29922
30280
  return handleDoctorCommand(parsed);
29923
30281
  case "uninstall":
@@ -30043,6 +30401,7 @@ Usage:
30043
30401
 
30044
30402
  Core Memory Lifecycle Commands:
30045
30403
  install [dir] Run interactive onboarding wizard & auto-wire installed agents
30404
+ upgrade / update [--check] Auto-fetch latest release, self-heal, and sync agent platforms
30046
30405
  doctor [dir] Run comprehensive ecosystem health diagnostic
30047
30406
  uninstall [agent] [--purge] Disconnect agents and optionally purge .memory data
30048
30407
  init [dir] Initialize .memory/ in workspace or current dir
@@ -30105,6 +30464,7 @@ Ecosystem, Migration & Connectivity:
30105
30464
  var init_cli = __esm(() => {
30106
30465
  init_shared();
30107
30466
  init_ecosystem();
30467
+ init_upgrade();
30108
30468
  init_retrieval3();
30109
30469
  init_persona();
30110
30470
  init_wiki2();