musememory 3.0.0 → 3.0.1

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/index.js CHANGED
@@ -3366,6 +3366,33 @@ var init_js_yaml = __esm(() => {
3366
3366
  } = yaml);
3367
3367
  });
3368
3368
 
3369
+ // src/types.ts
3370
+ var STATUS_PENALTY, VERIFICATION_BONUS, DEFAULT_STALE_DAYS = 90, DEFAULT_CONTEXT_LIMIT = 5, MAX_TITLE_LENGTH = 120, MAX_TAGS = 8, MAX_DRAFT_TITLE_LENGTH = 140;
3371
+ var init_types = __esm(() => {
3372
+ STATUS_PENALTY = {
3373
+ candidate: -0.6,
3374
+ active: 0,
3375
+ confirmed: 0.4,
3376
+ superseded: -1,
3377
+ stale: -0.3,
3378
+ disputed: -0.5,
3379
+ rejected: -1,
3380
+ conflicted: -0.8,
3381
+ cold: -0.2,
3382
+ dormant: -0.5,
3383
+ archived: -0.9,
3384
+ expired: -1
3385
+ };
3386
+ VERIFICATION_BONUS = {
3387
+ "independently-verified": 0.15,
3388
+ authoritative: 0.12,
3389
+ "user-confirmed": 0.1,
3390
+ reproducible: 0.08,
3391
+ observed: 0.05,
3392
+ unverified: 0
3393
+ };
3394
+ });
3395
+
3369
3396
  // src/lock.ts
3370
3397
  import {
3371
3398
  openSync,
@@ -3707,33 +3734,6 @@ var init_core = __esm(() => {
3707
3734
  CORE_TIERS = ["identity", "directives", "conventions", "context"];
3708
3735
  });
3709
3736
 
3710
- // src/types.ts
3711
- var STATUS_PENALTY, VERIFICATION_BONUS, DEFAULT_STALE_DAYS = 90, DEFAULT_CONTEXT_LIMIT = 5;
3712
- var init_types = __esm(() => {
3713
- STATUS_PENALTY = {
3714
- candidate: -0.6,
3715
- active: 0,
3716
- confirmed: 0.4,
3717
- superseded: -1,
3718
- stale: -0.3,
3719
- disputed: -0.5,
3720
- rejected: -1,
3721
- conflicted: -0.8,
3722
- cold: -0.2,
3723
- dormant: -0.5,
3724
- archived: -0.9,
3725
- expired: -1
3726
- };
3727
- VERIFICATION_BONUS = {
3728
- "independently-verified": 0.15,
3729
- authoritative: 0.12,
3730
- "user-confirmed": 0.1,
3731
- reproducible: 0.08,
3732
- observed: 0.05,
3733
- unverified: 0
3734
- };
3735
- });
3736
-
3737
3737
  // src/graph.ts
3738
3738
  import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync5, writeFileSync as writeFileSync5, mkdirSync as mkdirSync5 } from "node:fs";
3739
3739
  import { join as join5, isAbsolute } from "node:path";
@@ -5683,6 +5683,14 @@ var init_ladder = __esm(() => {
5683
5683
  });
5684
5684
 
5685
5685
  // src/retrieval/tier_budgets.ts
5686
+ function resolveTierBudget(tier = 2, customBudget) {
5687
+ const normTier = tier === 0 ? 0 : tier === 1 ? 1 : 2;
5688
+ const def = TIER_BUDGET_PROVENANCE[`TIER_${normTier}`];
5689
+ if (customBudget !== undefined && customBudget > 0) {
5690
+ return Math.min(customBudget, def.maxTokens);
5691
+ }
5692
+ return def.defaultTokens;
5693
+ }
5686
5694
  var TIER_BUDGET_PROVENANCE, TIER_0_DEFAULT_BUDGET, TIER_0_MAX_BUDGET, TIER_1_DEFAULT_BUDGET, TIER_1_MAX_BUDGET, TIER_2_DEFAULT_BUDGET, TIER_2_MAX_BUDGET, USER_PROFILE_DEFAULT_BUDGET, USER_PROFILE_MAX_BUDGET, USER_PROFILE_BUDGET_RATIO;
5687
5695
  var init_tier_budgets = __esm(() => {
5688
5696
  TIER_BUDGET_PROVENANCE = {
@@ -5756,6 +5764,7 @@ function queryTieredContext(store, memoryDir, query = "", options = {}) {
5756
5764
  const constraints = memoryDir ? syncConstraints(memoryDir, store) : [];
5757
5765
  const userProfile = getUserProfile(memoryDir, { query });
5758
5766
  const coreBlock = formatCoreBlock(memoryDir);
5767
+ const budgetTokens = resolveTierBudget(tier, options.tokenBudget);
5759
5768
  if (tier === 0) {
5760
5769
  const parts = [];
5761
5770
  if (queryResult.degraded && queryResult.degraded_notes && queryResult.degraded_notes.length > 0) {
@@ -5765,14 +5774,10 @@ function queryTieredContext(store, memoryDir, query = "", options = {}) {
5765
5774
  if (queryResult.results.length === 0) {
5766
5775
  parts.push("*(No matching memories)*");
5767
5776
  } else {
5768
- for (const item of queryResult.results) {
5769
- const t = item.entry.type ? `[${item.entry.type}] ` : "";
5770
- parts.push(`- \`${item.entry.id}\` ${t}${item.entry.title}`);
5771
- }
5777
+ const candidates = queryResult.results.map((item) => `- \`${item.entry.id}\` ${item.entry.type ? `[${item.entry.type}] ` : ""}${item.entry.title}`);
5778
+ parts.push(...fitToBudget(parts, candidates, budgetTokens));
5772
5779
  }
5773
- const markdown = parts.join(`
5774
- `);
5775
- const totalTokensUsed = Math.ceil(markdown.length / 4);
5780
+ const { markdown, totalTokensUsed } = clampMarkdown(parts, budgetTokens);
5776
5781
  return {
5777
5782
  markdown,
5778
5783
  entries: queryResult.results,
@@ -5815,15 +5820,14 @@ function queryTieredContext(store, memoryDir, query = "", options = {}) {
5815
5820
  if (queryResult.results.length === 0) {
5816
5821
  parts.push("*(No matching invariant routes)*");
5817
5822
  } else {
5818
- for (const item of queryResult.results) {
5823
+ const candidates = queryResult.results.map((item) => {
5819
5824
  const t = item.entry.type ? `[${item.entry.type}] ` : "";
5820
5825
  const tags = item.entry.tags && item.entry.tags.length > 0 ? ` (tags: ${item.entry.tags.join(", ")})` : "";
5821
- parts.push(`- \`${item.entry.id}\` ${t}${item.entry.title}${tags}`);
5822
- }
5826
+ return `- \`${item.entry.id}\` ${t}${item.entry.title}${tags}`;
5827
+ });
5828
+ parts.push(...fitToBudget(parts, candidates, budgetTokens));
5823
5829
  }
5824
- const markdown = parts.join(`
5825
- `);
5826
- const totalTokensUsed = Math.ceil(markdown.length / 4);
5830
+ const { markdown, totalTokensUsed } = clampMarkdown(parts, budgetTokens);
5827
5831
  return {
5828
5832
  markdown,
5829
5833
  entries: queryResult.results,
@@ -5841,6 +5845,41 @@ function queryTieredContext(store, memoryDir, query = "", options = {}) {
5841
5845
  draft_answers: queryResult.draft_answers
5842
5846
  };
5843
5847
  }
5848
+ function estimateTokens(text) {
5849
+ return Math.ceil(text.length / 4);
5850
+ }
5851
+ function fitToBudget(base, candidates, budgetTokens) {
5852
+ const used = estimateTokens(base.join(`
5853
+ `));
5854
+ const out = [];
5855
+ let current = used;
5856
+ for (const line of candidates) {
5857
+ const cost = estimateTokens(line) + 1;
5858
+ if (current + cost > budgetTokens) {
5859
+ const omitted = candidates.length - out.length;
5860
+ if (omitted > 0) {
5861
+ out.push(`- _… ${omitted} more entr${omitted === 1 ? "y" : "ies"} omitted (tier budget reached)_`);
5862
+ }
5863
+ break;
5864
+ }
5865
+ out.push(line);
5866
+ current += cost;
5867
+ }
5868
+ return out;
5869
+ }
5870
+ function clampMarkdown(parts, budgetTokens) {
5871
+ const markdown = parts.join(`
5872
+ `);
5873
+ const totalTokensUsed = estimateTokens(markdown);
5874
+ if (totalTokensUsed <= budgetTokens)
5875
+ return { markdown, totalTokensUsed };
5876
+ const maxChars = Math.max(0, budgetTokens * 4 - 40);
5877
+ const marker = `
5878
+
5879
+ _[truncated to fit the tier token budget]_`;
5880
+ const clipped = markdown.slice(0, maxChars) + marker;
5881
+ return { markdown: clipped, totalTokensUsed: estimateTokens(clipped) };
5882
+ }
5844
5883
  var init_tiered = __esm(() => {
5845
5884
  init_retrieval();
5846
5885
  init_governor();
@@ -5961,15 +6000,16 @@ function computeBayesianConfidence(n, discount = DEFAULT_CORROBORATION_DISCOUNT)
5961
6000
  const rawConfidence = 1 - Math.pow(clampedDiscount, n);
5962
6001
  return Number(Math.max(0, Math.min(1, rawConfidence)).toFixed(4));
5963
6002
  }
6003
+ function isSyntheticSource(source, type) {
6004
+ const s = (source ?? "").toLowerCase();
6005
+ const t = (type ?? "").toLowerCase();
6006
+ return s === "agent" || s === "transcript" || s === "assistant" || s === "inference" || s === "distillation" || s === "machine" || s === "synthetic" || t === "synthetic" || t === "infer";
6007
+ }
5964
6008
  function evaluateCorroboration(entry) {
5965
6009
  const dates = new Set;
5966
6010
  const sources = new Set;
5967
6011
  const reasons = [];
5968
- const isSynthetic = (source, type) => {
5969
- const s = (source ?? "").toLowerCase();
5970
- const t = (type ?? "").toLowerCase();
5971
- return s === "agent" || s === "transcript" || s === "assistant" || s === "inference" || s === "distillation" || s === "machine" || s === "synthetic" || t === "synthetic" || t === "infer";
5972
- };
6012
+ const isSynthetic = isSyntheticSource;
5973
6013
  if (entry.created_at)
5974
6014
  dates.add(entry.created_at.slice(0, 10));
5975
6015
  if (entry.last_confirmed_at)
@@ -6085,11 +6125,7 @@ function validateMemorySyntax(entry) {
6085
6125
  function checkCorroboration(entry) {
6086
6126
  const dates = new Set;
6087
6127
  const nonSyntheticSources = new Set;
6088
- const isSynthetic = (source, type) => {
6089
- const s = (source ?? "").toLowerCase();
6090
- const t = (type ?? "").toLowerCase();
6091
- return s === "agent" || s === "transcript" || s === "assistant" || s === "inference" || s === "distillation" || s === "machine" || s === "synthetic" || t === "synthetic" || t === "infer";
6092
- };
6128
+ const isSynthetic = isSyntheticSource;
6093
6129
  if (entry.evidence && entry.evidence.length > 0) {
6094
6130
  for (const ev of entry.evidence) {
6095
6131
  if (ev.timestamp) {
@@ -7804,7 +7840,7 @@ function searchTemporal(store, query, atTime, options = {}) {
7804
7840
  };
7805
7841
  }
7806
7842
  function formatPromptContext(store, memoryDir, query = "", options = {}) {
7807
- const cacheKey = store.cache ? `ctx:${query}:${options.project || ""}:${options.depth || "L2"}:${options.limit ?? 5}:${options.tokenBudget ?? ""}:${options.type || ""}:${options.status || ""}:${options.verified ? "1" : "0"}:${options.minVeracity ?? ""}` : undefined;
7843
+ const cacheKey = store.cache ? `ctx:${query}:${options.project || ""}:${options.depth || "L2"}:${options.limit ?? 5}:${options.tokenBudget ?? ""}:${options.type || ""}:${options.status || ""}:${options.verified ? "1" : "0"}:${options.minVeracity ?? ""}:${options.as_of || ""}:${options.includeSuperseded ? "1" : "0"}:${options.includeArchived ? "1" : "0"}:${options.includeUntrusted ? "1" : "0"}:${options.types?.join(",") || ""}:${options.tags?.join(",") || ""}` : undefined;
7808
7844
  if (cacheKey && store.cache) {
7809
7845
  const cached = store.cache.getContext(cacheKey);
7810
7846
  if (cached) {
@@ -8283,6 +8319,40 @@ var init_retrieval = __esm(() => {
8283
8319
  loggedRevalidationWarnings = new Set;
8284
8320
  });
8285
8321
 
8322
+ // src/security/strip.ts
8323
+ function stripInjectedContextBlocks(text) {
8324
+ if (!text || typeof text !== "string")
8325
+ return "";
8326
+ let cleaned = text;
8327
+ for (const regex of INJECTED_TAG_REGEXES) {
8328
+ regex.lastIndex = 0;
8329
+ cleaned = cleaned.replace(regex, "");
8330
+ }
8331
+ MARKDOWN_CONTEXT_PACK_REGEX.lastIndex = 0;
8332
+ cleaned = cleaned.replace(MARKDOWN_CONTEXT_PACK_REGEX, "");
8333
+ BASE64_DATA_URI_REGEX.lastIndex = 0;
8334
+ cleaned = cleaned.replace(BASE64_DATA_URI_REGEX, "[base64-payload-stripped]");
8335
+ BASE64_CODE_BLOCK_REGEX.lastIndex = 0;
8336
+ cleaned = cleaned.replace(BASE64_CODE_BLOCK_REGEX, "[base64-blob-stripped]");
8337
+ cleaned = cleaned.replace(/\n{3,}/g, `
8338
+
8339
+ `).trim();
8340
+ return cleaned;
8341
+ }
8342
+ var INJECTED_TAG_REGEXES, MARKDOWN_CONTEXT_PACK_REGEX, BASE64_DATA_URI_REGEX, BASE64_CODE_BLOCK_REGEX;
8343
+ var init_strip = __esm(() => {
8344
+ INJECTED_TAG_REGEXES = [
8345
+ /<memory-context[\s\S]*?>[\s\S]*?<\/memory-context>/gi,
8346
+ /<muse-memory[\s\S]*?>[\s\S]*?<\/muse-memory>/gi,
8347
+ /<context-pack[\s\S]*?>[\s\S]*?<\/context-pack>/gi,
8348
+ /<system-instructions[\s\S]*?>[\s\S]*?<\/system-instructions>/gi,
8349
+ /<!--\s*(?:memory-context|muse-context|context-pack|injected-context)\s*-->[\s\S]*?<!--\s*\/(?:memory-context|muse-context|context-pack|injected-context)\s*-->/gi
8350
+ ];
8351
+ MARKDOWN_CONTEXT_PACK_REGEX = /(?:^|\n)# 🧠 Muse Memory Context Pack[\s\S]*?(?=\n\n(?![#>*\-\s])|\n# [^#]|\n---|(?:\n\s*){3,}|$)/gi;
8352
+ BASE64_DATA_URI_REGEX = /data:[a-zA-Z0-9/+-]+;base64,[A-Za-z0-9+/=]{50,}/g;
8353
+ BASE64_CODE_BLOCK_REGEX = /```(?:base64|b64)?\s*\n(?:[A-Za-z0-9+/]{40,}=*\n?)+\s*```/g;
8354
+ });
8355
+
8286
8356
  // src/governor.ts
8287
8357
  import { existsSync as existsSync9, readFileSync as readFileSync7, writeFileSync as writeFileSync6, mkdirSync as mkdirSync7 } from "node:fs";
8288
8358
  import { join as join8 } from "node:path";
@@ -8592,7 +8662,8 @@ function getCurrent2(memoryDir) {
8592
8662
  return parseCurrentFile(memoryDir).constraints;
8593
8663
  }
8594
8664
  function setCurrent(memoryDir, text, project = "default") {
8595
- const trimmed = text.trim();
8665
+ const sanitized = stripInjectedContextBlocks(text);
8666
+ const trimmed = sanitized.trim();
8596
8667
  if (!trimmed)
8597
8668
  return getCurrent2(memoryDir);
8598
8669
  const current = parseCurrentFile(memoryDir);
@@ -8883,6 +8954,7 @@ var CANDIDATE_STALE_DAYS = 7, DUE_SOON_DAYS = 7;
8883
8954
  var init_governor = __esm(() => {
8884
8955
  init_store();
8885
8956
  init_retrieval();
8957
+ init_strip();
8886
8958
  });
8887
8959
 
8888
8960
  // src/current.ts
@@ -8890,40 +8962,6 @@ var init_current = __esm(() => {
8890
8962
  init_governor();
8891
8963
  });
8892
8964
 
8893
- // src/security/strip.ts
8894
- function stripInjectedContextBlocks(text) {
8895
- if (!text || typeof text !== "string")
8896
- return "";
8897
- let cleaned = text;
8898
- for (const regex of INJECTED_TAG_REGEXES) {
8899
- regex.lastIndex = 0;
8900
- cleaned = cleaned.replace(regex, "");
8901
- }
8902
- MARKDOWN_CONTEXT_PACK_REGEX.lastIndex = 0;
8903
- cleaned = cleaned.replace(MARKDOWN_CONTEXT_PACK_REGEX, "");
8904
- BASE64_DATA_URI_REGEX.lastIndex = 0;
8905
- cleaned = cleaned.replace(BASE64_DATA_URI_REGEX, "[base64-payload-stripped]");
8906
- BASE64_CODE_BLOCK_REGEX.lastIndex = 0;
8907
- cleaned = cleaned.replace(BASE64_CODE_BLOCK_REGEX, "[base64-blob-stripped]");
8908
- cleaned = cleaned.replace(/\n{3,}/g, `
8909
-
8910
- `).trim();
8911
- return cleaned;
8912
- }
8913
- var INJECTED_TAG_REGEXES, MARKDOWN_CONTEXT_PACK_REGEX, BASE64_DATA_URI_REGEX, BASE64_CODE_BLOCK_REGEX;
8914
- var init_strip = __esm(() => {
8915
- INJECTED_TAG_REGEXES = [
8916
- /<memory-context[\s\S]*?>[\s\S]*?<\/memory-context>/gi,
8917
- /<muse-memory[\s\S]*?>[\s\S]*?<\/muse-memory>/gi,
8918
- /<context-pack[\s\S]*?>[\s\S]*?<\/context-pack>/gi,
8919
- /<system-instructions[\s\S]*?>[\s\S]*?<\/system-instructions>/gi,
8920
- /<!--\s*(?:memory-context|muse-context|context-pack|injected-context)\s*-->[\s\S]*?<!--\s*\/(?:memory-context|muse-context|context-pack|injected-context)\s*-->/gi
8921
- ];
8922
- MARKDOWN_CONTEXT_PACK_REGEX = /(?:^|\n)# 🧠 Muse Memory Context Pack[\s\S]*?(?=\n\n(?![#>*\-\s])|\n# [^#]|\n---|(?:\n\s*){3,}|$)/gi;
8923
- BASE64_DATA_URI_REGEX = /data:[a-zA-Z0-9/+-]+;base64,[A-Za-z0-9+/=]{50,}/g;
8924
- BASE64_CODE_BLOCK_REGEX = /```(?:base64|b64)?\s*\n(?:[A-Za-z0-9+/]{40,}=*\n?)+\s*```/g;
8925
- });
8926
-
8927
8965
  // src/transcript.ts
8928
8966
  import { existsSync as existsSync10, readFileSync as readFileSync8 } from "node:fs";
8929
8967
  function parseJsonlTranscript(jsonlText) {
@@ -9070,7 +9108,7 @@ function extractHarvestUnits(text) {
9070
9108
  const title = currentTitle || content.slice(0, 80).replace(/^[#\-*\s]+/, "");
9071
9109
  const salience = defaultSalienceForType(currentType);
9072
9110
  units.push({
9073
- title: title.slice(0, 120),
9111
+ title: title.slice(0, MAX_TITLE_LENGTH),
9074
9112
  content,
9075
9113
  type: currentType,
9076
9114
  salience,
@@ -9281,6 +9319,7 @@ function importTranscript(store, transcriptPathOrContent, options = {}) {
9281
9319
  var COMMITMENT_PATTERNS;
9282
9320
  var init_harvest = __esm(() => {
9283
9321
  init_store();
9322
+ init_types();
9284
9323
  init_strip();
9285
9324
  init_transcript();
9286
9325
  COMMITMENT_PATTERNS = [
@@ -13739,7 +13778,8 @@ function getFromYaml(store, id) {
13739
13778
  }
13740
13779
  function recordAccess(store, entry) {
13741
13780
  const now = nowIso();
13742
- const currentCount = entry.access_count ?? 0;
13781
+ const dbCount = store.db ? getMemoryById(store.db, entry.id)?.access_count : undefined;
13782
+ const currentCount = dbCount ?? entry.access_count ?? 0;
13743
13783
  entry.last_accessed_at = now;
13744
13784
  entry.access_count = currentCount + 1;
13745
13785
  if (store.db) {
@@ -13788,7 +13828,13 @@ function readEntry(store, id) {
13788
13828
  }
13789
13829
  if (store.db) {
13790
13830
  try {
13791
- withTransaction(store.db, () => insertOrReplaceMemory(store.db, fromYaml));
13831
+ const existing = getMemoryById(store.db, id);
13832
+ const merged = {
13833
+ ...fromYaml,
13834
+ access_count: existing?.access_count ?? fromYaml.access_count,
13835
+ last_accessed_at: existing?.last_accessed_at ?? fromYaml.last_accessed_at
13836
+ };
13837
+ withTransaction(store.db, () => insertOrReplaceMemory(store.db, merged));
13792
13838
  } catch {}
13793
13839
  }
13794
13840
  if (store.cache) {
@@ -14034,8 +14080,8 @@ function propose(store, opts) {
14034
14080
  }
14035
14081
  }
14036
14082
  const isDraft = Boolean(opts.draft || opts.title && opts.title.startsWith("[DRAFT]"));
14037
- const rawTitle = opts.title ?? cleanContent.slice(0, 120);
14038
- const title = isDraft ? ensureDraftTitle(rawTitle).slice(0, 140) : rawTitle.slice(0, 120);
14083
+ const rawTitle = opts.title ?? cleanContent.slice(0, MAX_TITLE_LENGTH);
14084
+ const title = isDraft ? ensureDraftTitle(rawTitle).slice(0, MAX_DRAFT_TITLE_LENGTH) : rawTitle.slice(0, MAX_TITLE_LENGTH);
14039
14085
  const content_hash = opts.content_hash ?? computeContentHash(cleanContent);
14040
14086
  const retention = calculateRetentionScore(cleanContent, {
14041
14087
  title,
@@ -14186,7 +14232,7 @@ function propose(store, opts) {
14186
14232
  created_at: createdAt,
14187
14233
  updated_at: updatedAt,
14188
14234
  source: opts.source ?? "manual",
14189
- tags: opts.tags?.slice(0, 8) ?? [],
14235
+ tags: opts.tags?.slice(0, MAX_TAGS) ?? [],
14190
14236
  salience: typeof opts.salience === "number" ? opts.salience : undefined,
14191
14237
  valid_from: opts.validFrom ?? opts.valid_from,
14192
14238
  valid_to: opts.validTo ?? opts.valid_to,
@@ -14879,6 +14925,7 @@ function recordFactProvenance(store, entry) {
14879
14925
  var IdempotencyConflictError, openWriteTx, storeDirtyStateRegistry, lastGeneratedTs = 0, generatedSeq = 0, REPLAY_UNRECONSTRUCTABLE;
14880
14926
  var init_store = __esm(() => {
14881
14927
  init_js_yaml();
14928
+ init_types();
14882
14929
  init_secrets();
14883
14930
  init_audit();
14884
14931
  init_current();
@@ -18346,6 +18393,9 @@ var init_connect = __esm(() => {
18346
18393
  "search",
18347
18394
  "memory_capture",
18348
18395
  "memory_current",
18396
+ "memory_get_constraints",
18397
+ "memory_set_constraints",
18398
+ "memory_recall",
18349
18399
  "memory_harvest",
18350
18400
  "memory_confirm",
18351
18401
  "memory_supersede",
@@ -19072,7 +19122,7 @@ async function handleUpgradeCommand({ flags }) {
19072
19122
  },
19073
19123
  {
19074
19124
  level: 4,
19075
- title: "80+ Agent Platforms & Skills Auto-Wiring",
19125
+ title: "Agent Platforms & Skills Auto-Wiring",
19076
19126
  action: async () => {
19077
19127
  try {
19078
19128
  const reports = connectAgent("all", undefined, { dryRun, force: false });
@@ -28389,6 +28439,7 @@ var init_snapshot = __esm(() => {
28389
28439
  init_secrets();
28390
28440
  init_audit();
28391
28441
  init_settings2();
28442
+ init_paths();
28392
28443
  });
28393
28444
  // src/anchors/fingerprint.ts
28394
28445
  import { createHash as createHash7 } from "node:crypto";
@@ -43291,6 +43342,94 @@ var init_streamableHttp = __esm(() => {
43291
43342
  init_webStandardStreamableHttp();
43292
43343
  });
43293
43344
 
43345
+ // package.json
43346
+ var package_default;
43347
+ var init_package = __esm(() => {
43348
+ package_default = {
43349
+ name: "musememory",
43350
+ version: "3.0.1",
43351
+ description: "Autonomous, self-organizing cognitive memory system for AI agents and agency networks",
43352
+ main: "dist/index.js",
43353
+ type: "module",
43354
+ workspaces: [
43355
+ "apps/*",
43356
+ "packages/*"
43357
+ ],
43358
+ scripts: {
43359
+ "bench:graph": "bun scripts/bench-graph.ts",
43360
+ build: "bun build bin/musememory.ts --outfile dist/index.js --target node",
43361
+ "site:dev": "bun run --cwd apps/website dev",
43362
+ "site:build": "bun run --cwd apps/website build",
43363
+ "site:preview": "bun run --cwd apps/website preview",
43364
+ "site:showreel": "bun run --cwd apps/website scripts/build-showreel.ts",
43365
+ "site:brand": "bun run --cwd apps/website brand",
43366
+ "site:audit:a11y": "bun run --cwd apps/website scripts/audit-a11y.ts",
43367
+ "site:audit:visual": "bun run --cwd apps/website scripts/audit-visual.ts",
43368
+ "build:gif": "bun run --cwd apps/website scripts/build-readme-gif.ts",
43369
+ "claims:generate": "bun scripts/generate-claims.ts && bun scripts/generate-cli-reference.ts",
43370
+ "claims:check": "bun scripts/generate-claims.ts --check",
43371
+ "docs:check": "bun scripts/check-doc-links.ts",
43372
+ test: "bun test",
43373
+ typecheck: "tsc --noEmit",
43374
+ validate: "bun run dist/index.js validate --dry-run",
43375
+ start: "bun run dist/index.js mcp",
43376
+ prepublishOnly: "bun run build && bun test"
43377
+ },
43378
+ bin: {
43379
+ memory: "dist/index.js",
43380
+ musememory: "dist/index.js"
43381
+ },
43382
+ files: [
43383
+ "dist",
43384
+ "skills",
43385
+ ".agents",
43386
+ "schema.json",
43387
+ "claims.json",
43388
+ "docs/agent-reference.md",
43389
+ "docs/cli-reference.md",
43390
+ "docs/mcp-tool-matrix.json",
43391
+ "README.md",
43392
+ "LICENSE",
43393
+ "package.json"
43394
+ ],
43395
+ keywords: [
43396
+ "ai",
43397
+ "agent",
43398
+ "memory",
43399
+ "mcp",
43400
+ "model-context-protocol",
43401
+ "llm",
43402
+ "cognitive-architecture",
43403
+ "vibeguard",
43404
+ "agency"
43405
+ ],
43406
+ author: "Harsh Singh",
43407
+ repository: {
43408
+ type: "git",
43409
+ url: "git+ssh://git@github.com/harshsinghmp/musememory.git"
43410
+ },
43411
+ license: "MIT",
43412
+ dependencies: {
43413
+ "@modelcontextprotocol/sdk": "^1.0.0",
43414
+ ajv: "^8.17.1",
43415
+ "js-yaml": "^4.1.0"
43416
+ },
43417
+ devDependencies: {
43418
+ "@types/bun": "^1.1.0",
43419
+ "@types/js-yaml": "^4.0.9",
43420
+ typescript: "^5.6.0"
43421
+ }
43422
+ };
43423
+ });
43424
+
43425
+ // src/version.ts
43426
+ var PACKAGE_VERSION, PACKAGE_NAME;
43427
+ var init_version = __esm(() => {
43428
+ init_package();
43429
+ PACKAGE_VERSION = package_default.version;
43430
+ PACKAGE_NAME = package_default.name;
43431
+ });
43432
+
43294
43433
  // src/consolidate.ts
43295
43434
  function consolidateScenes(store, options = {}) {
43296
43435
  const minCluster = options.minCluster ?? 3;
@@ -45323,11 +45462,11 @@ var init_route_map = __esm(() => {
45323
45462
  // src/orchestrator/context.ts
45324
45463
  import { existsSync as existsSync58, readFileSync as readFileSync51 } from "node:fs";
45325
45464
  import { join as join54 } from "node:path";
45326
- function estimateTokens(text) {
45465
+ function estimateTokens2(text) {
45327
45466
  return dualMeasureTokens(text).conservativeTokens;
45328
45467
  }
45329
45468
  function estimateEntryTokens2(entry) {
45330
- return estimateTokens(`${entry.title}
45469
+ return estimateTokens2(`${entry.title}
45331
45470
  ${entry.content}
45332
45471
  ${entry.tags?.join(" ")}`);
45333
45472
  }
@@ -45365,7 +45504,7 @@ async function resolveMuseContext(store, workspaceRoot, input) {
45365
45504
  if (input.constitutional_rules !== undefined || input.include_constitution === true) {
45366
45505
  constitutionalRules = resolveConstitutionalRules(input.constitutional_rules);
45367
45506
  for (const rule of constitutionalRules) {
45368
- const cost = estimateTokens(`${rule.id} ${rule.title} ${rule.rule}`);
45507
+ const cost = estimateTokens2(`${rule.id} ${rule.title} ${rule.rule}`);
45369
45508
  usedBudget += cost;
45370
45509
  remainingBudget = Math.max(0, remainingBudget - cost);
45371
45510
  }
@@ -45424,7 +45563,7 @@ async function resolveMuseContext(store, workspaceRoot, input) {
45424
45563
  });
45425
45564
  }
45426
45565
  for (const c of activeConstraints) {
45427
- const cost = estimateTokens(`${c.title}
45566
+ const cost = estimateTokens2(`${c.title}
45428
45567
  ${c.content}`);
45429
45568
  if (cost <= remainingBudget) {
45430
45569
  usedBudget += cost;
@@ -46186,7 +46325,7 @@ var init_iterations = __esm(() => {
46186
46325
  });
46187
46326
 
46188
46327
  // src/compress.ts
46189
- function estimateTokens2(text) {
46328
+ function estimateTokens3(text) {
46190
46329
  if (!text || text.trim().length === 0)
46191
46330
  return 0;
46192
46331
  return Math.max(1, Math.ceil(text.length / 4));
@@ -46200,12 +46339,12 @@ function compressPromptContext(text, options = {}) {
46200
46339
  savingsPercent: 0
46201
46340
  };
46202
46341
  }
46203
- const originalTokens = estimateTokens2(text);
46342
+ const originalTokens = estimateTokens3(text);
46204
46343
  let cleaned = text.replace(/\n\s*\n\s*\n+/g, `
46205
46344
 
46206
46345
  `).replace(/### Active Working Constraints \(CURRENT\.md\)/gi, "### Active Constraints").replace(/### Active In-Flight Context & Session Handoff \(CURRENT\.md\)/gi, "### In-Flight Handoff").replace(/### User Profile & Preferences \(USER\.md\)/gi, "### User Profile").replace(/### Relevant Memories & Learned Patterns/gi, "### Memories").replace(/\n\s*---\s*\n/g, `
46207
46346
  `).replace(/\*Memory Directive: When learning durable facts[^\n]*\*/gi, "").replace(/[ \t]{2,}/g, " ").trim();
46208
- const compressedTokens = estimateTokens2(cleaned);
46347
+ const compressedTokens = estimateTokens3(cleaned);
46209
46348
  const diff = originalTokens - compressedTokens;
46210
46349
  const savingsPercent = originalTokens > 0 ? Math.round(Math.max(0, diff) / originalTokens * 100) : 0;
46211
46350
  return {
@@ -46343,7 +46482,7 @@ function createServer2(targetDir, requestedProfile) {
46343
46482
  }
46344
46483
  return { activeStore: store, activeMemoryDir: memoryDir, activeRoot: root };
46345
46484
  }
46346
- const server = new Server({ name: "musememory", version: "1.6.0" }, {
46485
+ const server = new Server({ name: PACKAGE_NAME, version: PACKAGE_VERSION }, {
46347
46486
  capabilities: { tools: {}, logging: {} },
46348
46487
  instructions: `MUSE MEMORY PROTOCOL:
46349
46488
  You are equipped with Muse Memory, an autonomous persistent cognitive memory system.
@@ -46481,6 +46620,49 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
46481
46620
  required: ["action"]
46482
46621
  }
46483
46622
  },
46623
+ {
46624
+ name: "memory_get_constraints",
46625
+ description: "Read the active working constraints and hard invariants recorded in CURRENT.md for the active project",
46626
+ inputSchema: {
46627
+ type: "object",
46628
+ properties: {
46629
+ project: { type: "string", description: "Project scope name (defaults to active project)" },
46630
+ dir: { type: "string", description: "Optional project workspace directory path" }
46631
+ }
46632
+ }
46633
+ },
46634
+ {
46635
+ name: "memory_set_constraints",
46636
+ description: "Append a working constraint or hard invariant to CURRENT.md for the active project",
46637
+ inputSchema: {
46638
+ type: "object",
46639
+ properties: {
46640
+ constraint: { type: "string", description: "The constraint text to append" },
46641
+ project: { type: "string", description: "Project scope name (defaults to active project)" },
46642
+ dir: { type: "string", description: "Optional project workspace directory path" }
46643
+ }
46644
+ }
46645
+ },
46646
+ {
46647
+ name: "memory_recall",
46648
+ description: "Recall active and confirmed memories for a query, with verification levels and related graph links",
46649
+ inputSchema: {
46650
+ type: "object",
46651
+ properties: {
46652
+ query: { type: "string" },
46653
+ project: { type: "string" },
46654
+ dir: { type: "string", description: "Optional project workspace directory path" },
46655
+ limit: { type: "number" },
46656
+ token_budget: { type: "number", description: "Maximum token budget to consume" },
46657
+ include_superseded: { type: "boolean" },
46658
+ type: { type: "string" },
46659
+ status: { type: "string" },
46660
+ verified: { type: "boolean" },
46661
+ min_veracity: { description: "Minimum provenance veracity class ('user', 'agent', 'external', 'system') or numerical threshold (1.0, 0.7, 0.5, 0.3)" }
46662
+ },
46663
+ required: ["query"]
46664
+ }
46665
+ },
46484
46666
  {
46485
46667
  name: "memory_harvest",
46486
46668
  description: "Distill conversation/text into structured outcome, fix, decision, and failure memories",
@@ -46645,7 +46827,7 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
46645
46827
  },
46646
46828
  {
46647
46829
  name: "memory_detect_agents",
46648
- description: "Scan the machine for 80+ coding agents (Claude Code, Cursor, Hermes, OpenCode, OpenClaw, Codex, etc.)",
46830
+ description: "Scan the machine for installed coding agents (Claude Code, Cursor, Hermes, OpenCode, OpenClaw, Codex, etc.)",
46649
46831
  inputSchema: {
46650
46832
  type: "object",
46651
46833
  properties: {}
@@ -47938,6 +48120,8 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
47938
48120
  status: a.status ? String(a.status) : undefined,
47939
48121
  verified: a.verified === true,
47940
48122
  tier: tierOpt,
48123
+ depth: a.depth ? String(a.depth) : undefined,
48124
+ as_of: a.as_of ? String(a.as_of) : undefined,
47941
48125
  minVeracity: a.min_veracity
47942
48126
  }) : formatPromptContext(activeStore, activeMemoryDir, queryStr, {
47943
48127
  limit: contextLimit,
@@ -48118,7 +48302,7 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
48118
48302
  if (activeMemoryDir) {
48119
48303
  try {
48120
48304
  updateSessionHandoff(activeMemoryDir, {
48121
- discoveries: [String(a.title || a.content || "")]
48305
+ discoveries: [stripInjectedContextBlocks(String(a.title || a.content || ""))]
48122
48306
  });
48123
48307
  } catch {}
48124
48308
  }
@@ -48260,7 +48444,7 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
48260
48444
  const entry = get(activeStore, id);
48261
48445
  if (!entry)
48262
48446
  return toolError(`no entry found with id ${id}`);
48263
- const isDryRun = a.dry_run !== false && a.confirm !== true && a.apply !== true && a.force !== true;
48447
+ const isDryRun = a.dry_run !== false && a.confirm !== true;
48264
48448
  if (isDryRun) {
48265
48449
  return toolResult({
48266
48450
  dry_run: true,
@@ -49403,6 +49587,8 @@ var init_mcp = __esm(() => {
49403
49587
  init_store();
49404
49588
  init_retrieval();
49405
49589
  init_governor();
49590
+ init_strip();
49591
+ init_version();
49406
49592
  init_consolidate();
49407
49593
  init_trace();
49408
49594
  init_loops();
@@ -49706,7 +49892,7 @@ async function handleInstallCommand({ positional, flags }) {
49706
49892
  },
49707
49893
  {
49708
49894
  level: 2,
49709
- title: "80+ Coding Agent Auto-Wiring Matrix",
49895
+ title: "Coding Agent Auto-Wiring Matrix",
49710
49896
  action: async () => {
49711
49897
  await Promise.resolve().then(() => init_connect());
49712
49898
  reports = connectAgent("all", undefined, { dryRun: false, force: false });
@@ -49951,7 +50137,7 @@ async function handleAgentsCommand() {
49951
50137
  const agents = detectAgents();
49952
50138
  const installed = agents.filter((a) => a.installed);
49953
50139
  const connected = installed.filter((a) => a.connected);
49954
- console.log(`[AGENTS] Workstation Coding Agents Scan (80+ Baseline):`);
50140
+ console.log(`[AGENTS] Workstation Coding Agents Scan:`);
49955
50141
  console.log(`------------------------------------------------`);
49956
50142
  for (const a of agents) {
49957
50143
  if (a.installed) {
@@ -52171,7 +52357,7 @@ var init_evolution = __esm(() => {
52171
52357
 
52172
52358
  // src/benchmark/suite.ts
52173
52359
  import { performance as performance2 } from "node:perf_hooks";
52174
- function estimateTokens3(text) {
52360
+ function estimateTokens4(text) {
52175
52361
  return Math.max(1, Math.ceil(text.length / 4));
52176
52362
  }
52177
52363
  function calculatePercentiles(samples, unit) {
@@ -52252,7 +52438,7 @@ async function runMemoryBenchmark(store, options = {}) {
52252
52438
  } catch {}
52253
52439
  let rawTokensTotal = 0;
52254
52440
  for (const e of allEntries) {
52255
- rawTokensTotal += estimateTokens3(`${e.title}
52441
+ rawTokensTotal += estimateTokens4(`${e.title}
52256
52442
  ${e.content}`);
52257
52443
  }
52258
52444
  const packedAvg = lastPackedTokens || Math.min(rawTokensTotal, tokenBudget);
@@ -53182,8 +53368,8 @@ Ecosystem, Migration & Connectivity:
53182
53368
  Auto-wire MCP into detected coding agents; --with-hooks also installs
53183
53369
  the lifecycle hook pack (SessionStart/PostToolUse/Stop) into .agents/hooks.json;
53184
53370
  --harness claude is the explicit opt-in for harness-specific paths like ~/.claude
53185
- agents / detect-agents Scan workstation for 80+ coding agent platforms
53186
- detect Scan machine for 24+ external memory formats
53371
+ agents / detect-agents Scan workstation for detected coding agent platforms
53372
+ detect Scan machine for external memory formats to migrate
53187
53373
  migrate [--from P] [--all] Ingest external memories with state preservation & secret scrubbing
53188
53374
  learn / sync-chats [--confirm] Auto-discover and harvest memories from all agent chats across machine
53189
53375
  harvest <file|text> --project P Distill conversation transcripts into structured memory units