musememory 3.0.0 → 3.0.2

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,95 @@ 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.2",
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
+ "site:qa": "bun run --cwd apps/website scripts/qa-gate.ts"
43378
+ },
43379
+ bin: {
43380
+ memory: "dist/index.js",
43381
+ musememory: "dist/index.js"
43382
+ },
43383
+ files: [
43384
+ "dist",
43385
+ "skills",
43386
+ ".agents",
43387
+ "schema.json",
43388
+ "claims.json",
43389
+ "docs/agent-reference.md",
43390
+ "docs/cli-reference.md",
43391
+ "docs/mcp-tool-matrix.json",
43392
+ "README.md",
43393
+ "LICENSE",
43394
+ "package.json"
43395
+ ],
43396
+ keywords: [
43397
+ "ai",
43398
+ "agent",
43399
+ "memory",
43400
+ "mcp",
43401
+ "model-context-protocol",
43402
+ "llm",
43403
+ "cognitive-architecture",
43404
+ "vibeguard",
43405
+ "agency"
43406
+ ],
43407
+ author: "Harsh Singh",
43408
+ repository: {
43409
+ type: "git",
43410
+ url: "git+ssh://git@github.com/harshsinghmp/musememory.git"
43411
+ },
43412
+ license: "MIT",
43413
+ dependencies: {
43414
+ "@modelcontextprotocol/sdk": "^1.0.0",
43415
+ ajv: "^8.17.1",
43416
+ "js-yaml": "^4.1.0"
43417
+ },
43418
+ devDependencies: {
43419
+ "@types/bun": "^1.1.0",
43420
+ "@types/js-yaml": "^4.0.9",
43421
+ typescript: "^5.6.0"
43422
+ }
43423
+ };
43424
+ });
43425
+
43426
+ // src/version.ts
43427
+ var PACKAGE_VERSION, PACKAGE_NAME;
43428
+ var init_version = __esm(() => {
43429
+ init_package();
43430
+ PACKAGE_VERSION = package_default.version;
43431
+ PACKAGE_NAME = package_default.name;
43432
+ });
43433
+
43294
43434
  // src/consolidate.ts
43295
43435
  function consolidateScenes(store, options = {}) {
43296
43436
  const minCluster = options.minCluster ?? 3;
@@ -45323,11 +45463,11 @@ var init_route_map = __esm(() => {
45323
45463
  // src/orchestrator/context.ts
45324
45464
  import { existsSync as existsSync58, readFileSync as readFileSync51 } from "node:fs";
45325
45465
  import { join as join54 } from "node:path";
45326
- function estimateTokens(text) {
45466
+ function estimateTokens2(text) {
45327
45467
  return dualMeasureTokens(text).conservativeTokens;
45328
45468
  }
45329
45469
  function estimateEntryTokens2(entry) {
45330
- return estimateTokens(`${entry.title}
45470
+ return estimateTokens2(`${entry.title}
45331
45471
  ${entry.content}
45332
45472
  ${entry.tags?.join(" ")}`);
45333
45473
  }
@@ -45365,7 +45505,7 @@ async function resolveMuseContext(store, workspaceRoot, input) {
45365
45505
  if (input.constitutional_rules !== undefined || input.include_constitution === true) {
45366
45506
  constitutionalRules = resolveConstitutionalRules(input.constitutional_rules);
45367
45507
  for (const rule of constitutionalRules) {
45368
- const cost = estimateTokens(`${rule.id} ${rule.title} ${rule.rule}`);
45508
+ const cost = estimateTokens2(`${rule.id} ${rule.title} ${rule.rule}`);
45369
45509
  usedBudget += cost;
45370
45510
  remainingBudget = Math.max(0, remainingBudget - cost);
45371
45511
  }
@@ -45424,7 +45564,7 @@ async function resolveMuseContext(store, workspaceRoot, input) {
45424
45564
  });
45425
45565
  }
45426
45566
  for (const c of activeConstraints) {
45427
- const cost = estimateTokens(`${c.title}
45567
+ const cost = estimateTokens2(`${c.title}
45428
45568
  ${c.content}`);
45429
45569
  if (cost <= remainingBudget) {
45430
45570
  usedBudget += cost;
@@ -46186,7 +46326,7 @@ var init_iterations = __esm(() => {
46186
46326
  });
46187
46327
 
46188
46328
  // src/compress.ts
46189
- function estimateTokens2(text) {
46329
+ function estimateTokens3(text) {
46190
46330
  if (!text || text.trim().length === 0)
46191
46331
  return 0;
46192
46332
  return Math.max(1, Math.ceil(text.length / 4));
@@ -46200,12 +46340,12 @@ function compressPromptContext(text, options = {}) {
46200
46340
  savingsPercent: 0
46201
46341
  };
46202
46342
  }
46203
- const originalTokens = estimateTokens2(text);
46343
+ const originalTokens = estimateTokens3(text);
46204
46344
  let cleaned = text.replace(/\n\s*\n\s*\n+/g, `
46205
46345
 
46206
46346
  `).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
46347
  `).replace(/\*Memory Directive: When learning durable facts[^\n]*\*/gi, "").replace(/[ \t]{2,}/g, " ").trim();
46208
- const compressedTokens = estimateTokens2(cleaned);
46348
+ const compressedTokens = estimateTokens3(cleaned);
46209
46349
  const diff = originalTokens - compressedTokens;
46210
46350
  const savingsPercent = originalTokens > 0 ? Math.round(Math.max(0, diff) / originalTokens * 100) : 0;
46211
46351
  return {
@@ -46343,7 +46483,7 @@ function createServer2(targetDir, requestedProfile) {
46343
46483
  }
46344
46484
  return { activeStore: store, activeMemoryDir: memoryDir, activeRoot: root };
46345
46485
  }
46346
- const server = new Server({ name: "musememory", version: "1.6.0" }, {
46486
+ const server = new Server({ name: PACKAGE_NAME, version: PACKAGE_VERSION }, {
46347
46487
  capabilities: { tools: {}, logging: {} },
46348
46488
  instructions: `MUSE MEMORY PROTOCOL:
46349
46489
  You are equipped with Muse Memory, an autonomous persistent cognitive memory system.
@@ -46481,6 +46621,49 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
46481
46621
  required: ["action"]
46482
46622
  }
46483
46623
  },
46624
+ {
46625
+ name: "memory_get_constraints",
46626
+ description: "Read the active working constraints and hard invariants recorded in CURRENT.md for the active project",
46627
+ inputSchema: {
46628
+ type: "object",
46629
+ properties: {
46630
+ project: { type: "string", description: "Project scope name (defaults to active project)" },
46631
+ dir: { type: "string", description: "Optional project workspace directory path" }
46632
+ }
46633
+ }
46634
+ },
46635
+ {
46636
+ name: "memory_set_constraints",
46637
+ description: "Append a working constraint or hard invariant to CURRENT.md for the active project",
46638
+ inputSchema: {
46639
+ type: "object",
46640
+ properties: {
46641
+ constraint: { type: "string", description: "The constraint text to append" },
46642
+ project: { type: "string", description: "Project scope name (defaults to active project)" },
46643
+ dir: { type: "string", description: "Optional project workspace directory path" }
46644
+ }
46645
+ }
46646
+ },
46647
+ {
46648
+ name: "memory_recall",
46649
+ description: "Recall active and confirmed memories for a query, with verification levels and related graph links",
46650
+ inputSchema: {
46651
+ type: "object",
46652
+ properties: {
46653
+ query: { type: "string" },
46654
+ project: { type: "string" },
46655
+ dir: { type: "string", description: "Optional project workspace directory path" },
46656
+ limit: { type: "number" },
46657
+ token_budget: { type: "number", description: "Maximum token budget to consume" },
46658
+ include_superseded: { type: "boolean" },
46659
+ type: { type: "string" },
46660
+ status: { type: "string" },
46661
+ verified: { type: "boolean" },
46662
+ min_veracity: { description: "Minimum provenance veracity class ('user', 'agent', 'external', 'system') or numerical threshold (1.0, 0.7, 0.5, 0.3)" }
46663
+ },
46664
+ required: ["query"]
46665
+ }
46666
+ },
46484
46667
  {
46485
46668
  name: "memory_harvest",
46486
46669
  description: "Distill conversation/text into structured outcome, fix, decision, and failure memories",
@@ -46645,7 +46828,7 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
46645
46828
  },
46646
46829
  {
46647
46830
  name: "memory_detect_agents",
46648
- description: "Scan the machine for 80+ coding agents (Claude Code, Cursor, Hermes, OpenCode, OpenClaw, Codex, etc.)",
46831
+ description: "Scan the machine for installed coding agents (Claude Code, Cursor, Hermes, OpenCode, OpenClaw, Codex, etc.)",
46649
46832
  inputSchema: {
46650
46833
  type: "object",
46651
46834
  properties: {}
@@ -47938,6 +48121,8 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
47938
48121
  status: a.status ? String(a.status) : undefined,
47939
48122
  verified: a.verified === true,
47940
48123
  tier: tierOpt,
48124
+ depth: a.depth ? String(a.depth) : undefined,
48125
+ as_of: a.as_of ? String(a.as_of) : undefined,
47941
48126
  minVeracity: a.min_veracity
47942
48127
  }) : formatPromptContext(activeStore, activeMemoryDir, queryStr, {
47943
48128
  limit: contextLimit,
@@ -48118,7 +48303,7 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
48118
48303
  if (activeMemoryDir) {
48119
48304
  try {
48120
48305
  updateSessionHandoff(activeMemoryDir, {
48121
- discoveries: [String(a.title || a.content || "")]
48306
+ discoveries: [stripInjectedContextBlocks(String(a.title || a.content || ""))]
48122
48307
  });
48123
48308
  } catch {}
48124
48309
  }
@@ -48260,7 +48445,7 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
48260
48445
  const entry = get(activeStore, id);
48261
48446
  if (!entry)
48262
48447
  return toolError(`no entry found with id ${id}`);
48263
- const isDryRun = a.dry_run !== false && a.confirm !== true && a.apply !== true && a.force !== true;
48448
+ const isDryRun = a.dry_run !== false && a.confirm !== true;
48264
48449
  if (isDryRun) {
48265
48450
  return toolResult({
48266
48451
  dry_run: true,
@@ -49403,6 +49588,8 @@ var init_mcp = __esm(() => {
49403
49588
  init_store();
49404
49589
  init_retrieval();
49405
49590
  init_governor();
49591
+ init_strip();
49592
+ init_version();
49406
49593
  init_consolidate();
49407
49594
  init_trace();
49408
49595
  init_loops();
@@ -49706,7 +49893,7 @@ async function handleInstallCommand({ positional, flags }) {
49706
49893
  },
49707
49894
  {
49708
49895
  level: 2,
49709
- title: "80+ Coding Agent Auto-Wiring Matrix",
49896
+ title: "Coding Agent Auto-Wiring Matrix",
49710
49897
  action: async () => {
49711
49898
  await Promise.resolve().then(() => init_connect());
49712
49899
  reports = connectAgent("all", undefined, { dryRun: false, force: false });
@@ -49951,7 +50138,7 @@ async function handleAgentsCommand() {
49951
50138
  const agents = detectAgents();
49952
50139
  const installed = agents.filter((a) => a.installed);
49953
50140
  const connected = installed.filter((a) => a.connected);
49954
- console.log(`[AGENTS] Workstation Coding Agents Scan (80+ Baseline):`);
50141
+ console.log(`[AGENTS] Workstation Coding Agents Scan:`);
49955
50142
  console.log(`------------------------------------------------`);
49956
50143
  for (const a of agents) {
49957
50144
  if (a.installed) {
@@ -52171,7 +52358,7 @@ var init_evolution = __esm(() => {
52171
52358
 
52172
52359
  // src/benchmark/suite.ts
52173
52360
  import { performance as performance2 } from "node:perf_hooks";
52174
- function estimateTokens3(text) {
52361
+ function estimateTokens4(text) {
52175
52362
  return Math.max(1, Math.ceil(text.length / 4));
52176
52363
  }
52177
52364
  function calculatePercentiles(samples, unit) {
@@ -52252,7 +52439,7 @@ async function runMemoryBenchmark(store, options = {}) {
52252
52439
  } catch {}
52253
52440
  let rawTokensTotal = 0;
52254
52441
  for (const e of allEntries) {
52255
- rawTokensTotal += estimateTokens3(`${e.title}
52442
+ rawTokensTotal += estimateTokens4(`${e.title}
52256
52443
  ${e.content}`);
52257
52444
  }
52258
52445
  const packedAvg = lastPackedTokens || Math.min(rawTokensTotal, tokenBudget);
@@ -53182,8 +53369,8 @@ Ecosystem, Migration & Connectivity:
53182
53369
  Auto-wire MCP into detected coding agents; --with-hooks also installs
53183
53370
  the lifecycle hook pack (SessionStart/PostToolUse/Stop) into .agents/hooks.json;
53184
53371
  --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
53372
+ agents / detect-agents Scan workstation for detected coding agent platforms
53373
+ detect Scan machine for external memory formats to migrate
53187
53374
  migrate [--from P] [--all] Ingest external memories with state preservation & secret scrubbing
53188
53375
  learn / sync-chats [--confirm] Auto-discover and harvest memories from all agent chats across machine
53189
53376
  harvest <file|text> --project P Distill conversation transcripts into structured memory units