dotmem 0.0.8 → 0.1.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.
package/mcp.js CHANGED
@@ -19,6 +19,18 @@ var __export = (target, all) => {
19
19
  __defProp(target, name, { get: all[name], enumerable: true });
20
20
  };
21
21
 
22
+ // suppress-idb-warning.ts
23
+ var orig;
24
+ var init_suppress_idb_warning = __esm({
25
+ "suppress-idb-warning.ts"() {
26
+ orig = console.warn.bind(console);
27
+ console.warn = (...args) => {
28
+ if (typeof args[0] === "string" && args[0].includes("IndexedDB is not available")) return;
29
+ orig(...args);
30
+ };
31
+ }
32
+ });
33
+
22
34
  // core/env.ts
23
35
  var DEV;
24
36
  var init_env = __esm({
@@ -2403,6 +2415,7 @@ var init_policy_store = __esm({
2403
2415
  if (entry.target !== void 0) built.target = entry.target;
2404
2416
  if (entry.reason !== void 0) built.reason = entry.reason;
2405
2417
  if (entry.detail !== void 0) built.detail = entry.detail;
2418
+ if (entry.mandatory !== void 0) built.mandatory = entry.mandatory;
2406
2419
  return built;
2407
2420
  }, "validatePolicyAuditEntry");
2408
2421
  validatePolicyDocument = /* @__PURE__ */ __name((value) => {
@@ -2480,6 +2493,7 @@ var init_policy_store = __esm({
2480
2493
  if (entry.target !== void 0) built.target = entry.target;
2481
2494
  if (entry.reason !== void 0) built.reason = entry.reason;
2482
2495
  if (entry.detail !== void 0) built.detail = entry.detail;
2496
+ if (entry.mandatory !== void 0) built.mandatory = entry.mandatory;
2483
2497
  return built;
2484
2498
  }, "buildAuditEntry");
2485
2499
  boundedAudit = /* @__PURE__ */ __name((entries2, overrides) => {
@@ -2492,9 +2506,10 @@ var init_policy_store = __esm({
2492
2506
  for (let index = entries2.length - 1; index >= 0; index--) {
2493
2507
  const entry = entries2[index];
2494
2508
  const activeLinked = entry.target !== void 0 && activeOverrideIds.has(entry.target) && (entry.action === "override" || entry.action === "revoke");
2495
- if (activeLinked || budget > 0) {
2509
+ const mandatory = entry.mandatory === true;
2510
+ if (activeLinked || mandatory || budget > 0) {
2496
2511
  kept.unshift(entry);
2497
- if (!activeLinked) budget--;
2512
+ if (!activeLinked && !mandatory) budget--;
2498
2513
  }
2499
2514
  }
2500
2515
  return kept;
@@ -2535,6 +2550,12 @@ var init_policy_store = __esm({
2535
2550
  try {
2536
2551
  await fs.writeFile(temporary, `${JSON.stringify(document, null, 2)}
2537
2552
  `, "utf8");
2553
+ const handle = await fs.open(temporary, "r+");
2554
+ try {
2555
+ await handle.sync();
2556
+ } finally {
2557
+ await handle.close();
2558
+ }
2538
2559
  await fs.rename(temporary, filePath);
2539
2560
  } catch (error) {
2540
2561
  await fs.rm(temporary, { force: true }).catch(() => void 0);
@@ -4454,7 +4475,7 @@ function encodeMemFile(stateValue, preserved) {
4454
4475
  function decodeMemDocument(value) {
4455
4476
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid .mem file format");
4456
4477
  const file = value;
4457
- if (file.format !== MEM_FORMAT) throw new Error("Invalid .mem file format");
4478
+ if (file.format !== MEM_FORMAT && file.format !== MEM_FORMAT_LEGACY) throw new Error("Invalid .mem file format");
4458
4479
  if (file.version === MEM_FORMAT_VERSION_V1) {
4459
4480
  if (!file.knowledge) throw new Error("Invalid .mem file format");
4460
4481
  return { state: validateSourceState(file.knowledge) };
@@ -4536,11 +4557,12 @@ function decodeMemDocument(value) {
4536
4557
  preserved: { map: structuredClone(map), data: structuredClone(stateRecord) }
4537
4558
  };
4538
4559
  }
4539
- var MEM_FORMAT, MEM_FORMAT_VERSION, MEM_FORMAT_VERSION_V1, expectedFields, epistemicTypes, revisionKinds, claimKinds, isJsonValue2, createMemInterpretationMap, validateSourceState, trimRecord, fieldIndexes, validateVocabulary, put, get, optionalGet, requireRecord, putOptional;
4560
+ var MEM_FORMAT, MEM_FORMAT_LEGACY, MEM_FORMAT_VERSION, MEM_FORMAT_VERSION_V1, expectedFields, epistemicTypes, revisionKinds, claimKinds, isJsonValue2, createMemInterpretationMap, validateSourceState, trimRecord, fieldIndexes, validateVocabulary, put, get, optionalGet, requireRecord, putOptional;
4540
4561
  var init_mem_codec = __esm({
4541
4562
  "core/knowledge/mem-codec.ts"() {
4542
4563
  init_state();
4543
4564
  MEM_FORMAT = "dotmem.knowledge";
4565
+ MEM_FORMAT_LEGACY = "memorio.knowledge";
4544
4566
  MEM_FORMAT_VERSION = 2;
4545
4567
  MEM_FORMAT_VERSION_V1 = 1;
4546
4568
  expectedFields = {
@@ -4646,12 +4668,13 @@ async function decodeMemArtifact(input) {
4646
4668
  throw new MemArtifactError(message.startsWith("Unsupported") ? "unsupported" : "invalid", message);
4647
4669
  }
4648
4670
  }
4649
- var MEM_PACKAGE_FORMAT, MEM_PACKAGE_VERSION, MEM_PACKAGE_LIMITS, MEM_PACKAGE_WRITE_MARGIN_BYTES, MEM_PACKAGE_WRITE_LIMITS, MANIFEST_PATH, MAP_PATH, DATA_PATH, INTEGRITY_PATH, requiredParts, encoder2, decoder, MemArtifactError, stableValue, jsonBytes, sha256, parseJson, validEntryPath, concatenate, readZipParts, createManifest, digestTableIdentity, encodePackage, isZip, decodePackage;
4671
+ var MEM_PACKAGE_FORMAT, MEM_PACKAGE_FORMAT_LEGACY, MEM_PACKAGE_VERSION, MEM_PACKAGE_LIMITS, MEM_PACKAGE_WRITE_MARGIN_BYTES, MEM_PACKAGE_WRITE_LIMITS, MANIFEST_PATH, MAP_PATH, DATA_PATH, INTEGRITY_PATH, requiredParts, encoder2, decoder, MemArtifactError, stableValue, jsonBytes, sha256, parseJson, validEntryPath, concatenate, readZipParts, createManifest, digestTableIdentity, encodePackage, isZip, decodePackage;
4650
4672
  var init_mem_package = __esm({
4651
4673
  "core/knowledge/mem-package.ts"() {
4652
4674
  init_browser();
4653
4675
  init_mem_codec();
4654
4676
  MEM_PACKAGE_FORMAT = "dotmem.package";
4677
+ MEM_PACKAGE_FORMAT_LEGACY = "memorio.package";
4655
4678
  MEM_PACKAGE_VERSION = 1;
4656
4679
  MEM_PACKAGE_LIMITS = Object.freeze({
4657
4680
  maximumPackageBytes: 10 * 1024 * 1024,
@@ -4825,10 +4848,10 @@ var init_mem_package = __esm({
4825
4848
  if (!parts[path]) throw new MemArtifactError("invalid", `Missing MEM package part: ${path}`);
4826
4849
  }
4827
4850
  const manifest = parseJson(parts[MANIFEST_PATH], MANIFEST_PATH);
4828
- if (manifest.format !== MEM_PACKAGE_FORMAT && manifest.format || manifest.version !== MEM_PACKAGE_VERSION) {
4851
+ if (manifest.format !== MEM_PACKAGE_FORMAT && manifest.format !== MEM_PACKAGE_FORMAT_LEGACY || manifest.version !== MEM_PACKAGE_VERSION) {
4829
4852
  throw new MemArtifactError("unsupported", "Unsupported MEM package format or version");
4830
4853
  }
4831
- if (manifest.memory?.format !== MEM_FORMAT && manifest.memory?.format || manifest.memory.version !== MEM_FORMAT_VERSION || manifest.parts?.map !== MAP_PATH || manifest.parts?.data !== DATA_PATH || manifest.parts?.integrity !== INTEGRITY_PATH) {
4854
+ if (manifest.memory?.format !== MEM_FORMAT && manifest.memory?.format !== MEM_FORMAT_LEGACY || manifest.memory.version !== MEM_FORMAT_VERSION || manifest.parts?.map !== MAP_PATH || manifest.parts?.data !== DATA_PATH || manifest.parts?.integrity !== INTEGRITY_PATH) {
4832
4855
  throw new MemArtifactError("invalid", "Invalid MEM package manifest");
4833
4856
  }
4834
4857
  const integrity = parseJson(parts[INTEGRITY_PATH], INTEGRITY_PATH);
@@ -4871,6 +4894,109 @@ var init_mem_package = __esm({
4871
4894
  }
4872
4895
  });
4873
4896
 
4897
+ // core/storage-coordinator/index.ts
4898
+ var nodeFs4, withStorageLock, readStorageGeneration, writeStorageGeneration;
4899
+ var init_storage_coordinator = __esm({
4900
+ "core/storage-coordinator/index.ts"() {
4901
+ nodeFs4 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
4902
+ withStorageLock = /* @__PURE__ */ __name(async (directoryPath, operationOrOptions, operation, _options = {}) => {
4903
+ const opts = typeof operationOrOptions === "function" ? operation ?? {} : operationOrOptions ?? {};
4904
+ const op = typeof operationOrOptions === "function" ? operationOrOptions : operation;
4905
+ const timeoutMs = opts.timeoutMs ?? 3e4;
4906
+ const staleMs = opts.staleMs ?? 6e4;
4907
+ const lockName = opts.lockName ?? ".storage.lock";
4908
+ const lockPath = `${directoryPath}/${lockName}`;
4909
+ const fs = await nodeFs4();
4910
+ const started = Date.now();
4911
+ await fs.mkdir(directoryPath, { recursive: true });
4912
+ while (true) {
4913
+ try {
4914
+ await fs.mkdir(lockPath);
4915
+ const token2 = `${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
4916
+ await fs.writeFile(`${lockPath}/owner.json`, JSON.stringify({ token: token2, pid: process.pid, createdAt: Date.now() }), { flag: "wx" });
4917
+ break;
4918
+ } catch (error) {
4919
+ const code = error.code;
4920
+ if (code !== "EEXIST" && code !== "ENOENT" && code !== "EPERM" && code !== "ENOTEMPTY") throw error;
4921
+ let stale = false;
4922
+ let processDead = false;
4923
+ try {
4924
+ const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
4925
+ const parsed = JSON.parse(raw);
4926
+ const ageStale = typeof parsed.createdAt === "number" && Date.now() - parsed.createdAt > staleMs;
4927
+ if (typeof parsed.pid === "number") {
4928
+ try {
4929
+ process.kill(parsed.pid, 0);
4930
+ } catch {
4931
+ processDead = true;
4932
+ }
4933
+ } else {
4934
+ processDead = true;
4935
+ }
4936
+ if (ageStale || processDead) stale = true;
4937
+ } catch {
4938
+ stale = true;
4939
+ }
4940
+ if (stale) {
4941
+ if (processDead) {
4942
+ try {
4943
+ await fs.rm(lockPath, { recursive: true, force: true });
4944
+ continue;
4945
+ } catch {
4946
+ }
4947
+ }
4948
+ try {
4949
+ await fs.rmdir(lockPath);
4950
+ continue;
4951
+ } catch {
4952
+ }
4953
+ }
4954
+ if (Date.now() - started > timeoutMs) {
4955
+ throw new Error(`Storage lock timeout for ${directoryPath}`);
4956
+ }
4957
+ await new Promise((resolve) => setTimeout(resolve, 25));
4958
+ }
4959
+ }
4960
+ let token = "";
4961
+ try {
4962
+ const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
4963
+ token = JSON.parse(raw).token ?? "";
4964
+ } catch {
4965
+ token = "";
4966
+ }
4967
+ try {
4968
+ return await op();
4969
+ } finally {
4970
+ try {
4971
+ const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
4972
+ const parsed = JSON.parse(raw);
4973
+ if (parsed.token === token && token) {
4974
+ await fs.rm(lockPath, { recursive: true, force: true });
4975
+ }
4976
+ } catch {
4977
+ }
4978
+ }
4979
+ }, "withStorageLock");
4980
+ readStorageGeneration = /* @__PURE__ */ __name(async (directoryPath) => {
4981
+ const fs = await nodeFs4();
4982
+ try {
4983
+ const raw = await fs.readFile(`${directoryPath}/.storage.generation`, "utf8");
4984
+ const value = Number(raw.trim());
4985
+ return Number.isFinite(value) && value >= 0 ? value : 0;
4986
+ } catch {
4987
+ return 0;
4988
+ }
4989
+ }, "readStorageGeneration");
4990
+ writeStorageGeneration = /* @__PURE__ */ __name(async (directoryPath, value) => {
4991
+ const fs = await nodeFs4();
4992
+ await fs.mkdir(directoryPath, { recursive: true });
4993
+ const temp = `${directoryPath}/.storage.generation.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
4994
+ await fs.writeFile(temp, String(value));
4995
+ await fs.rename(temp, `${directoryPath}/.storage.generation`);
4996
+ }, "writeStorageGeneration");
4997
+ }
4998
+ });
4999
+
4874
5000
  // core/knowledge/mem-repository.ts
4875
5001
  function resolveDuplicate(existing, existingSource, current, currentSource) {
4876
5002
  const existingRetracts = existing.revision?.kind === "retracts";
@@ -4911,19 +5037,20 @@ async function parseMemFile(value, sourceId) {
4911
5037
  throw new Error(`${message} in ${sourceId}`);
4912
5038
  }
4913
5039
  }
4914
- var DOTMEM_DIRECTORY, DEFAULT_MEM_FILE, directoryLocks, nodeFs4, separator2, normalizePath, isAbsolutePath, resolvePath, joinPath2, parentPath, uniqueSuffix, withDirectoryLock, isMissingDirectory, sourcePriority, memFilePath, MemDirectoryKnowledgeRepository;
5040
+ var DOTMEM_DIRECTORY, DEFAULT_MEM_FILE, nodeFs5, repositoryLoadCaches, separator2, normalizePath, isAbsolutePath, resolvePath, joinPath2, parentPath, uniqueSuffix, isMissingDirectory, sourcePriority, memFilePath, MemDirectoryKnowledgeRepository;
4915
5041
  var init_mem_repository = __esm({
4916
5042
  "core/knowledge/mem-repository.ts"() {
4917
5043
  init_mem_codec();
4918
5044
  init_mem_package();
4919
5045
  init_state();
4920
5046
  init_acquisition_limits();
5047
+ init_storage_coordinator();
4921
5048
  DOTMEM_DIRECTORY = ".dotmem";
4922
5049
  DEFAULT_MEM_FILE = "project.mem";
4923
- directoryLocks = /* @__PURE__ */ new Map();
4924
- nodeFs4 = /* @__PURE__ */ __name(async () => {
5050
+ nodeFs5 = /* @__PURE__ */ __name(async () => {
4925
5051
  return import('fs/promises');
4926
5052
  }, "nodeFs");
5053
+ repositoryLoadCaches = /* @__PURE__ */ new Map();
4927
5054
  separator2 = /* @__PURE__ */ __name(() => process.platform === "win32" ? "\\" : "/", "separator");
4928
5055
  normalizePath = /* @__PURE__ */ __name((value) => value.replace(/[\\/]+/g, separator2()), "normalizePath");
4929
5056
  isAbsolutePath = /* @__PURE__ */ __name((value) => /^(?:[A-Za-z]:[\\/]|[\\/])/.test(value), "isAbsolutePath");
@@ -4935,25 +5062,8 @@ var init_mem_repository = __esm({
4935
5062
  return index <= 0 ? "." : normalized.slice(0, index);
4936
5063
  }, "parentPath");
4937
5064
  uniqueSuffix = /* @__PURE__ */ __name(() => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, "uniqueSuffix");
4938
- withDirectoryLock = /* @__PURE__ */ __name(async (directoryPath, operation) => {
4939
- const previous = directoryLocks.get(directoryPath) ?? Promise.resolve();
4940
- let release = /* @__PURE__ */ __name(() => void 0, "release");
4941
- const gate = new Promise((resolveGate) => {
4942
- release = resolveGate;
4943
- });
4944
- const queued = previous.then(() => gate);
4945
- directoryLocks.set(directoryPath, queued);
4946
- await previous;
4947
- try {
4948
- return await operation();
4949
- } finally {
4950
- release();
4951
- if (directoryLocks.get(directoryPath) === queued) directoryLocks.delete(directoryPath);
4952
- }
4953
- }, "withDirectoryLock");
4954
5065
  isMissingDirectory = /* @__PURE__ */ __name((error) => error.code === "ENOENT", "isMissingDirectory");
4955
5066
  sourcePriority = /* @__PURE__ */ __name((sourceId, scope) => {
4956
- if (sourceId.endsWith(".mem") && sourceId !== "project.mem" && sourceId !== "user.mem" && sourceId !== "agent.mem") return 0;
4957
5067
  if (scope === "project" || sourceId === "project.mem") return 4;
4958
5068
  if (scope === "user" || sourceId === "user.mem") return 3;
4959
5069
  if (sourceId === "agent.mem" || sourceId === "agent") return 2;
@@ -4981,7 +5091,7 @@ var init_mem_repository = __esm({
4981
5091
  this.loadWritableOnly = loadWritableOnly;
4982
5092
  }
4983
5093
  async discover() {
4984
- const { readdir } = await nodeFs4();
5094
+ const { readdir } = await nodeFs5();
4985
5095
  try {
4986
5096
  const entries2 = await readdir(this.directoryPath, { withFileTypes: true });
4987
5097
  return entries2.filter((entry) => entry.isFile() && entry.name.endsWith(".mem") && entry.name !== "@brain.mem").map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
@@ -4996,7 +5106,7 @@ var init_mem_repository = __esm({
4996
5106
  * receive a clear failure instead of discovering corruption on first use.
4997
5107
  */
4998
5108
  async initialize() {
4999
- const { mkdir } = await nodeFs4();
5109
+ const { mkdir } = await nodeFs5();
5000
5110
  await mkdir(this.directoryPath, { recursive: true });
5001
5111
  await this.load();
5002
5112
  }
@@ -5011,7 +5121,7 @@ var init_mem_repository = __esm({
5011
5121
  * that does not delete is not a delete.
5012
5122
  */
5013
5123
  async clearWritable() {
5014
- const { rm, readdir } = await nodeFs4();
5124
+ const { rm, readdir } = await nodeFs5();
5015
5125
  const filePath = memFilePath(this.directoryPath, this.writableSourceId);
5016
5126
  await rm(filePath, { force: true });
5017
5127
  await rm(`${filePath}.bak`, { force: true });
@@ -5028,15 +5138,28 @@ var init_mem_repository = __esm({
5028
5138
  }
5029
5139
  }
5030
5140
  async load() {
5031
- const loaded = this.loadWritableOnly ? await this.loadSources([this.writableSourceId]) : await this.loadSources();
5032
- return this.combine(loaded);
5141
+ const cacheKey = `${this.directoryPath}:${this.writableSourceId}:${this.loadWritableOnly}`;
5142
+ for (let attempt = 0; attempt < 5; attempt += 1) {
5143
+ const generationBefore = await readStorageGeneration(this.directoryPath);
5144
+ const cached = repositoryLoadCaches.get(cacheKey);
5145
+ if (cached && cached.signature === String(generationBefore)) {
5146
+ return structuredClone(cached.state);
5147
+ }
5148
+ const loaded = this.loadWritableOnly ? await this.loadSources([this.writableSourceId]) : await this.loadSources();
5149
+ const state2 = this.combine(loaded);
5150
+ const generationAfter = await readStorageGeneration(this.directoryPath);
5151
+ if (generationBefore !== generationAfter && attempt < 4) continue;
5152
+ repositoryLoadCaches.set(cacheKey, { signature: String(generationAfter), state: structuredClone(state2) });
5153
+ return state2;
5154
+ }
5155
+ throw new Error("Unable to load stable repository state");
5033
5156
  }
5034
- async save(state2, expectedVersion) {
5157
+ async save(state2, expectedVersion, locked = false) {
5035
5158
  const validated = validateKnowledgeState(state2);
5036
5159
  if (!Number.isInteger(expectedVersion) || expectedVersion < 0 || validated.version !== expectedVersion + 1) {
5037
5160
  throw new Error("Invalid expected persisted version");
5038
5161
  }
5039
- await withDirectoryLock(this.directoryPath, async () => {
5162
+ const doWrite = /* @__PURE__ */ __name(async () => {
5040
5163
  const loaded = await this.loadSources();
5041
5164
  const writable = loaded.find((source) => source.id === this.writableSourceId) ?? {
5042
5165
  id: this.writableSourceId,
@@ -5058,10 +5181,16 @@ var init_mem_repository = __esm({
5058
5181
  claims: [...writable.state.claims, ...newClaims]
5059
5182
  };
5060
5183
  await this.writeSource(writable.filePath, nextWritable, writable.preserved, writable.package);
5061
- });
5184
+ await writeStorageGeneration(this.directoryPath, await readStorageGeneration(this.directoryPath) + 1);
5185
+ }, "doWrite");
5186
+ if (locked) {
5187
+ await doWrite();
5188
+ } else {
5189
+ await withStorageLock(this.directoryPath, doWrite);
5190
+ }
5062
5191
  }
5063
5192
  async loadSources(sourceIds) {
5064
- const { readFile: readFile5 } = await nodeFs4();
5193
+ const { readFile: readFile5 } = await nodeFs5();
5065
5194
  const ids = sourceIds ?? await this.discover();
5066
5195
  const sources = [];
5067
5196
  for (const sourceId of ids) {
@@ -5151,7 +5280,7 @@ var init_mem_repository = __esm({
5151
5280
  * valid package, so the backup is always a version this library can read.
5152
5281
  */
5153
5282
  async keepLastValidVersion(filePath) {
5154
- const { readFile: readFile5, copyFile, rename, rm } = await nodeFs4();
5283
+ const { readFile: readFile5, copyFile, rename, rm } = await nodeFs5();
5155
5284
  let current;
5156
5285
  try {
5157
5286
  current = await readFile5(filePath);
@@ -5175,7 +5304,7 @@ var init_mem_repository = __esm({
5175
5304
  }
5176
5305
  /** Best-effort directory sync: the rename is durable once the directory is. */
5177
5306
  async syncDirectory(directoryPath) {
5178
- const { open } = await nodeFs4();
5307
+ const { open } = await nodeFs5();
5179
5308
  try {
5180
5309
  const handle = await open(directoryPath, "r");
5181
5310
  try {
@@ -5187,7 +5316,7 @@ var init_mem_repository = __esm({
5187
5316
  }
5188
5317
  }
5189
5318
  async writeSource(filePath, state2, preserved, preservedPackage) {
5190
- const { mkdir, rename, rm, open, readFile: readFile5 } = await nodeFs4();
5319
+ const { mkdir, rename, rm, open, readFile: readFile5 } = await nodeFs5();
5191
5320
  if (!Number.isInteger(state2.version) || state2.version < 0) throw new Error("Invalid writable .mem knowledge version");
5192
5321
  for (const claim of state2.claims) validateClaim(claim);
5193
5322
  await mkdir(parentPath(filePath), { recursive: true });
@@ -5674,7 +5803,7 @@ var init_project_identity = __esm({
5674
5803
  });
5675
5804
 
5676
5805
  // core/knowledge/staging.ts
5677
- var DOTMEM_STAGE_FORMAT, DOTMEM_STAGE_VERSION, StageFileError, generateRequestId, nodeCwd, resolveStagingDirectory, stagePathFor, nodeFs5, normalizeClaimIds, revisionFromOptions, writeStageFile, readStageFile, validateStageFile, commitStageFile, cleanupStageFile;
5806
+ var DOTMEM_STAGE_FORMAT, DOTMEM_STAGE_VERSION, StageFileError, generateRequestId, nodeCwd, resolveStagingDirectory, stagePathFor, nodeFs6, normalizeClaimIds, revisionFromOptions, writeStageFile, readStageFile, validateStageFile, commitStageFile, cleanupStageFile;
5678
5807
  var init_staging = __esm({
5679
5808
  "core/knowledge/staging.ts"() {
5680
5809
  init_claim_record();
@@ -5709,7 +5838,7 @@ var init_staging = __esm({
5709
5838
  return `${base}/dotmem`;
5710
5839
  }, "resolveStagingDirectory");
5711
5840
  stagePathFor = /* @__PURE__ */ __name((requestId) => `${resolveStagingDirectory()}/${requestId}.stage`, "stagePathFor");
5712
- nodeFs5 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
5841
+ nodeFs6 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
5713
5842
  normalizeClaimIds = /* @__PURE__ */ __name((value) => {
5714
5843
  if (!value) return [];
5715
5844
  return Array.isArray(value) ? value : [value];
@@ -5734,7 +5863,7 @@ var init_staging = __esm({
5734
5863
  };
5735
5864
  const requestId = generateRequestId();
5736
5865
  const stagePath = stagePathFor(requestId);
5737
- const fs = await nodeFs5();
5866
+ const fs = await nodeFs6();
5738
5867
  await fs.mkdir(resolveStagingDirectory(), { recursive: true });
5739
5868
  const stageFile = {
5740
5869
  format: DOTMEM_STAGE_FORMAT,
@@ -5754,7 +5883,7 @@ var init_staging = __esm({
5754
5883
  }, "writeStageFile");
5755
5884
  readStageFile = /* @__PURE__ */ __name(async (requestId) => {
5756
5885
  const stagePath = stagePathFor(requestId);
5757
- const fs = await nodeFs5();
5886
+ const fs = await nodeFs6();
5758
5887
  try {
5759
5888
  const content = await fs.readFile(stagePath, "utf8");
5760
5889
  return JSON.parse(content);
@@ -5865,7 +5994,7 @@ var init_staging = __esm({
5865
5994
  }, "commitStageFile");
5866
5995
  cleanupStageFile = /* @__PURE__ */ __name(async (requestId) => {
5867
5996
  const stagePath = stagePathFor(requestId);
5868
- const fs = await nodeFs5();
5997
+ const fs = await nodeFs6();
5869
5998
  try {
5870
5999
  await fs.unlink(stagePath);
5871
6000
  } catch (error) {
@@ -6687,6 +6816,7 @@ function _inferConfidence(claim) {
6687
6816
  var LOGIC_MEM_FILE, nodeCwd2, cachedRuntime, LogicEngine, logic, logic_default;
6688
6817
  var init_logic = __esm({
6689
6818
  "core/logic/index.ts"() {
6819
+ init_suppress_idb_warning();
6690
6820
  init_knowledge();
6691
6821
  init_mem_repository();
6692
6822
  init_acquisition_boundary();
@@ -7050,11 +7180,18 @@ var init_note_types = __esm({
7050
7180
  }
7051
7181
  });
7052
7182
 
7183
+ // core/mcp/index.ts
7184
+ init_suppress_idb_warning();
7185
+
7053
7186
  // package.json
7054
7187
  var package_default = {
7055
- version: "0.0.8"};
7188
+ version: "0.1.0"};
7189
+
7190
+ // core/memory/index.ts
7191
+ init_suppress_idb_warning();
7056
7192
 
7057
7193
  // core/memory/journal.ts
7194
+ init_suppress_idb_warning();
7058
7195
  init_env();
7059
7196
  var g = globalThis;
7060
7197
  function namespace() {
@@ -7261,6 +7398,7 @@ var journal_default = journal;
7261
7398
  init_brain();
7262
7399
 
7263
7400
  // core/memory/knowledge-runtime.ts
7401
+ init_suppress_idb_warning();
7264
7402
  init_knowledge();
7265
7403
  init_project_identity();
7266
7404
  init_user_paths();
@@ -7658,6 +7796,7 @@ var policy = {
7658
7796
  };
7659
7797
 
7660
7798
  // core/memory/entries.ts
7799
+ init_suppress_idb_warning();
7661
7800
  init_env();
7662
7801
  var MEMORY_INDEX_KEY = "__dotmem_memory_index__";
7663
7802
  var SUPERSEDED_PREFIX = "__dotmem_superseded__";
@@ -8202,15 +8341,18 @@ var context = {
8202
8341
  };
8203
8342
 
8204
8343
  // core/memory/acquire.ts
8344
+ init_suppress_idb_warning();
8205
8345
  init_env();
8206
8346
  init_project_identity();
8207
8347
  init_project_anchor();
8208
8348
  init_acquisition_boundary();
8209
8349
  init_claim_record();
8350
+ init_state();
8210
8351
  init_router();
8211
8352
  init_store_queue();
8212
8353
  init_staging();
8213
8354
  init_user_paths();
8355
+ init_storage_coordinator();
8214
8356
  init_mem_repository();
8215
8357
  function normalizeClaimIds3(value) {
8216
8358
  if (!value) return [];
@@ -8288,23 +8430,27 @@ var acquire = {
8288
8430
  );
8289
8431
  }
8290
8432
  const revision = revisionFromAcquire2(opts);
8433
+ const repository = target.repository;
8291
8434
  await withStoreQueue(acquisitionStoreKey(kind, scope, sourceProject), async () => {
8292
- const state2 = await target.runtime.select([]);
8293
- await target.runtime.update({
8294
- basedOnVersion: state2.context.knowledgeVersion,
8295
- claims: [buildClaimRecord({
8296
- id: opts.id,
8297
- knowledge: boundary.knowledge,
8298
- applicability: opts.applicability,
8299
- evidence: opts.evidence,
8300
- epistemicType: opts.epistemicType,
8301
- provenance: opts.provenance,
8302
- acquiredAt: opts.acquiredAt,
8303
- revision,
8304
- scope,
8305
- sourceProject,
8306
- kind
8307
- })]
8435
+ await withStorageLock(repository.directoryPath, async () => {
8436
+ const state2 = await repository.load();
8437
+ const next = updateKnowledge(state2, {
8438
+ basedOnVersion: state2.version,
8439
+ claims: [buildClaimRecord({
8440
+ id: opts.id,
8441
+ knowledge: boundary.knowledge,
8442
+ applicability: opts.applicability,
8443
+ evidence: opts.evidence,
8444
+ epistemicType: opts.epistemicType,
8445
+ provenance: opts.provenance,
8446
+ acquiredAt: opts.acquiredAt,
8447
+ revision,
8448
+ scope,
8449
+ sourceProject,
8450
+ kind
8451
+ })]
8452
+ });
8453
+ await repository.save(next, state2.version, true);
8308
8454
  });
8309
8455
  });
8310
8456
  const verification = await target.repository.load();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dotmem",
3
3
  "codeName": "dotmem",
4
- "version": "0.0.8",
4
+ "version": "0.1.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "description": "The AI memory layer for agents and apps: acquired experience, discovery, context projection, continuity, and logic engine. Built on Memorio's state+store foundation.",