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/AGENTS.md +13 -1
- package/DOTMEM.md +538 -539
- package/JOY.md +55 -0
- package/MEMORY.md +4 -4
- package/PACKAGE.md +1 -1
- package/README.md +251 -417
- package/agent.cjs +13 -0
- package/agent.js +13 -0
- package/bin/cli.cjs +5 -0
- package/bin/cli.js +5 -0
- package/bin/mcp.cjs +5 -0
- package/bin/mcp.js +5 -0
- package/cli.cjs +207 -61
- package/cli.js +207 -61
- package/global.cjs +206 -60
- package/global.js +206 -60
- package/index.cjs +1897 -68
- package/index.js +1869 -61
- package/llms.txt +94 -10
- package/mcp.cjs +207 -61
- package/mcp.js +207 -61
- package/package.json +1 -1
package/global.cjs
CHANGED
|
@@ -21,6 +21,18 @@ var __export = (target, all) => {
|
|
|
21
21
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
// suppress-idb-warning.ts
|
|
25
|
+
var orig;
|
|
26
|
+
var init_suppress_idb_warning = __esm({
|
|
27
|
+
"suppress-idb-warning.ts"() {
|
|
28
|
+
orig = console.warn.bind(console);
|
|
29
|
+
console.warn = (...args) => {
|
|
30
|
+
if (typeof args[0] === "string" && args[0].includes("IndexedDB is not available")) return;
|
|
31
|
+
orig(...args);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
24
36
|
// core/env.ts
|
|
25
37
|
var DEV;
|
|
26
38
|
var init_env = __esm({
|
|
@@ -2405,6 +2417,7 @@ var init_policy_store = __esm({
|
|
|
2405
2417
|
if (entry.target !== void 0) built.target = entry.target;
|
|
2406
2418
|
if (entry.reason !== void 0) built.reason = entry.reason;
|
|
2407
2419
|
if (entry.detail !== void 0) built.detail = entry.detail;
|
|
2420
|
+
if (entry.mandatory !== void 0) built.mandatory = entry.mandatory;
|
|
2408
2421
|
return built;
|
|
2409
2422
|
}, "validatePolicyAuditEntry");
|
|
2410
2423
|
validatePolicyDocument = /* @__PURE__ */ __name((value) => {
|
|
@@ -2482,6 +2495,7 @@ var init_policy_store = __esm({
|
|
|
2482
2495
|
if (entry.target !== void 0) built.target = entry.target;
|
|
2483
2496
|
if (entry.reason !== void 0) built.reason = entry.reason;
|
|
2484
2497
|
if (entry.detail !== void 0) built.detail = entry.detail;
|
|
2498
|
+
if (entry.mandatory !== void 0) built.mandatory = entry.mandatory;
|
|
2485
2499
|
return built;
|
|
2486
2500
|
}, "buildAuditEntry");
|
|
2487
2501
|
boundedAudit = /* @__PURE__ */ __name((entries2, overrides) => {
|
|
@@ -2494,9 +2508,10 @@ var init_policy_store = __esm({
|
|
|
2494
2508
|
for (let index = entries2.length - 1; index >= 0; index--) {
|
|
2495
2509
|
const entry = entries2[index];
|
|
2496
2510
|
const activeLinked = entry.target !== void 0 && activeOverrideIds.has(entry.target) && (entry.action === "override" || entry.action === "revoke");
|
|
2497
|
-
|
|
2511
|
+
const mandatory = entry.mandatory === true;
|
|
2512
|
+
if (activeLinked || mandatory || budget > 0) {
|
|
2498
2513
|
kept.unshift(entry);
|
|
2499
|
-
if (!activeLinked) budget--;
|
|
2514
|
+
if (!activeLinked && !mandatory) budget--;
|
|
2500
2515
|
}
|
|
2501
2516
|
}
|
|
2502
2517
|
return kept;
|
|
@@ -2537,6 +2552,12 @@ var init_policy_store = __esm({
|
|
|
2537
2552
|
try {
|
|
2538
2553
|
await fs.writeFile(temporary, `${JSON.stringify(document, null, 2)}
|
|
2539
2554
|
`, "utf8");
|
|
2555
|
+
const handle = await fs.open(temporary, "r+");
|
|
2556
|
+
try {
|
|
2557
|
+
await handle.sync();
|
|
2558
|
+
} finally {
|
|
2559
|
+
await handle.close();
|
|
2560
|
+
}
|
|
2540
2561
|
await fs.rename(temporary, filePath);
|
|
2541
2562
|
} catch (error) {
|
|
2542
2563
|
await fs.rm(temporary, { force: true }).catch(() => void 0);
|
|
@@ -4455,7 +4476,7 @@ function encodeMemFile(stateValue, preserved) {
|
|
|
4455
4476
|
function decodeMemDocument(value) {
|
|
4456
4477
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid .mem file format");
|
|
4457
4478
|
const file = value;
|
|
4458
|
-
if (file.format !== MEM_FORMAT) throw new Error("Invalid .mem file format");
|
|
4479
|
+
if (file.format !== MEM_FORMAT && file.format !== MEM_FORMAT_LEGACY) throw new Error("Invalid .mem file format");
|
|
4459
4480
|
if (file.version === MEM_FORMAT_VERSION_V1) {
|
|
4460
4481
|
if (!file.knowledge) throw new Error("Invalid .mem file format");
|
|
4461
4482
|
return { state: validateSourceState(file.knowledge) };
|
|
@@ -4537,11 +4558,12 @@ function decodeMemDocument(value) {
|
|
|
4537
4558
|
preserved: { map: structuredClone(map), data: structuredClone(stateRecord) }
|
|
4538
4559
|
};
|
|
4539
4560
|
}
|
|
4540
|
-
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;
|
|
4561
|
+
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;
|
|
4541
4562
|
var init_mem_codec = __esm({
|
|
4542
4563
|
"core/knowledge/mem-codec.ts"() {
|
|
4543
4564
|
init_state();
|
|
4544
4565
|
MEM_FORMAT = "dotmem.knowledge";
|
|
4566
|
+
MEM_FORMAT_LEGACY = "memorio.knowledge";
|
|
4545
4567
|
MEM_FORMAT_VERSION = 2;
|
|
4546
4568
|
MEM_FORMAT_VERSION_V1 = 1;
|
|
4547
4569
|
expectedFields = {
|
|
@@ -4647,12 +4669,13 @@ async function decodeMemArtifact(input) {
|
|
|
4647
4669
|
throw new MemArtifactError(message.startsWith("Unsupported") ? "unsupported" : "invalid", message);
|
|
4648
4670
|
}
|
|
4649
4671
|
}
|
|
4650
|
-
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;
|
|
4672
|
+
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;
|
|
4651
4673
|
var init_mem_package = __esm({
|
|
4652
4674
|
"core/knowledge/mem-package.ts"() {
|
|
4653
4675
|
init_browser();
|
|
4654
4676
|
init_mem_codec();
|
|
4655
4677
|
MEM_PACKAGE_FORMAT = "dotmem.package";
|
|
4678
|
+
MEM_PACKAGE_FORMAT_LEGACY = "memorio.package";
|
|
4656
4679
|
MEM_PACKAGE_VERSION = 1;
|
|
4657
4680
|
MEM_PACKAGE_LIMITS = Object.freeze({
|
|
4658
4681
|
maximumPackageBytes: 10 * 1024 * 1024,
|
|
@@ -4826,10 +4849,10 @@ var init_mem_package = __esm({
|
|
|
4826
4849
|
if (!parts[path]) throw new MemArtifactError("invalid", `Missing MEM package part: ${path}`);
|
|
4827
4850
|
}
|
|
4828
4851
|
const manifest = parseJson(parts[MANIFEST_PATH], MANIFEST_PATH);
|
|
4829
|
-
if (manifest.format !== MEM_PACKAGE_FORMAT && manifest.format || manifest.version !== MEM_PACKAGE_VERSION) {
|
|
4852
|
+
if (manifest.format !== MEM_PACKAGE_FORMAT && manifest.format !== MEM_PACKAGE_FORMAT_LEGACY || manifest.version !== MEM_PACKAGE_VERSION) {
|
|
4830
4853
|
throw new MemArtifactError("unsupported", "Unsupported MEM package format or version");
|
|
4831
4854
|
}
|
|
4832
|
-
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) {
|
|
4855
|
+
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) {
|
|
4833
4856
|
throw new MemArtifactError("invalid", "Invalid MEM package manifest");
|
|
4834
4857
|
}
|
|
4835
4858
|
const integrity = parseJson(parts[INTEGRITY_PATH], INTEGRITY_PATH);
|
|
@@ -4872,6 +4895,109 @@ var init_mem_package = __esm({
|
|
|
4872
4895
|
}
|
|
4873
4896
|
});
|
|
4874
4897
|
|
|
4898
|
+
// core/storage-coordinator/index.ts
|
|
4899
|
+
var nodeFs4, withStorageLock, readStorageGeneration, writeStorageGeneration;
|
|
4900
|
+
var init_storage_coordinator = __esm({
|
|
4901
|
+
"core/storage-coordinator/index.ts"() {
|
|
4902
|
+
nodeFs4 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
|
|
4903
|
+
withStorageLock = /* @__PURE__ */ __name(async (directoryPath, operationOrOptions, operation, _options = {}) => {
|
|
4904
|
+
const opts = typeof operationOrOptions === "function" ? operation ?? {} : operationOrOptions ?? {};
|
|
4905
|
+
const op = typeof operationOrOptions === "function" ? operationOrOptions : operation;
|
|
4906
|
+
const timeoutMs = opts.timeoutMs ?? 3e4;
|
|
4907
|
+
const staleMs = opts.staleMs ?? 6e4;
|
|
4908
|
+
const lockName = opts.lockName ?? ".storage.lock";
|
|
4909
|
+
const lockPath = `${directoryPath}/${lockName}`;
|
|
4910
|
+
const fs = await nodeFs4();
|
|
4911
|
+
const started = Date.now();
|
|
4912
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
|
4913
|
+
while (true) {
|
|
4914
|
+
try {
|
|
4915
|
+
await fs.mkdir(lockPath);
|
|
4916
|
+
const token2 = `${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
4917
|
+
await fs.writeFile(`${lockPath}/owner.json`, JSON.stringify({ token: token2, pid: process.pid, createdAt: Date.now() }), { flag: "wx" });
|
|
4918
|
+
break;
|
|
4919
|
+
} catch (error) {
|
|
4920
|
+
const code = error.code;
|
|
4921
|
+
if (code !== "EEXIST" && code !== "ENOENT" && code !== "EPERM" && code !== "ENOTEMPTY") throw error;
|
|
4922
|
+
let stale = false;
|
|
4923
|
+
let processDead = false;
|
|
4924
|
+
try {
|
|
4925
|
+
const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
|
|
4926
|
+
const parsed = JSON.parse(raw);
|
|
4927
|
+
const ageStale = typeof parsed.createdAt === "number" && Date.now() - parsed.createdAt > staleMs;
|
|
4928
|
+
if (typeof parsed.pid === "number") {
|
|
4929
|
+
try {
|
|
4930
|
+
process.kill(parsed.pid, 0);
|
|
4931
|
+
} catch {
|
|
4932
|
+
processDead = true;
|
|
4933
|
+
}
|
|
4934
|
+
} else {
|
|
4935
|
+
processDead = true;
|
|
4936
|
+
}
|
|
4937
|
+
if (ageStale || processDead) stale = true;
|
|
4938
|
+
} catch {
|
|
4939
|
+
stale = true;
|
|
4940
|
+
}
|
|
4941
|
+
if (stale) {
|
|
4942
|
+
if (processDead) {
|
|
4943
|
+
try {
|
|
4944
|
+
await fs.rm(lockPath, { recursive: true, force: true });
|
|
4945
|
+
continue;
|
|
4946
|
+
} catch {
|
|
4947
|
+
}
|
|
4948
|
+
}
|
|
4949
|
+
try {
|
|
4950
|
+
await fs.rmdir(lockPath);
|
|
4951
|
+
continue;
|
|
4952
|
+
} catch {
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
if (Date.now() - started > timeoutMs) {
|
|
4956
|
+
throw new Error(`Storage lock timeout for ${directoryPath}`);
|
|
4957
|
+
}
|
|
4958
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4961
|
+
let token = "";
|
|
4962
|
+
try {
|
|
4963
|
+
const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
|
|
4964
|
+
token = JSON.parse(raw).token ?? "";
|
|
4965
|
+
} catch {
|
|
4966
|
+
token = "";
|
|
4967
|
+
}
|
|
4968
|
+
try {
|
|
4969
|
+
return await op();
|
|
4970
|
+
} finally {
|
|
4971
|
+
try {
|
|
4972
|
+
const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
|
|
4973
|
+
const parsed = JSON.parse(raw);
|
|
4974
|
+
if (parsed.token === token && token) {
|
|
4975
|
+
await fs.rm(lockPath, { recursive: true, force: true });
|
|
4976
|
+
}
|
|
4977
|
+
} catch {
|
|
4978
|
+
}
|
|
4979
|
+
}
|
|
4980
|
+
}, "withStorageLock");
|
|
4981
|
+
readStorageGeneration = /* @__PURE__ */ __name(async (directoryPath) => {
|
|
4982
|
+
const fs = await nodeFs4();
|
|
4983
|
+
try {
|
|
4984
|
+
const raw = await fs.readFile(`${directoryPath}/.storage.generation`, "utf8");
|
|
4985
|
+
const value = Number(raw.trim());
|
|
4986
|
+
return Number.isFinite(value) && value >= 0 ? value : 0;
|
|
4987
|
+
} catch {
|
|
4988
|
+
return 0;
|
|
4989
|
+
}
|
|
4990
|
+
}, "readStorageGeneration");
|
|
4991
|
+
writeStorageGeneration = /* @__PURE__ */ __name(async (directoryPath, value) => {
|
|
4992
|
+
const fs = await nodeFs4();
|
|
4993
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
|
4994
|
+
const temp = `${directoryPath}/.storage.generation.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
4995
|
+
await fs.writeFile(temp, String(value));
|
|
4996
|
+
await fs.rename(temp, `${directoryPath}/.storage.generation`);
|
|
4997
|
+
}, "writeStorageGeneration");
|
|
4998
|
+
}
|
|
4999
|
+
});
|
|
5000
|
+
|
|
4875
5001
|
// core/knowledge/mem-repository.ts
|
|
4876
5002
|
function resolveDuplicate(existing, existingSource, current, currentSource) {
|
|
4877
5003
|
const existingRetracts = existing.revision?.kind === "retracts";
|
|
@@ -4912,19 +5038,20 @@ async function parseMemFile(value, sourceId) {
|
|
|
4912
5038
|
throw new Error(`${message} in ${sourceId}`);
|
|
4913
5039
|
}
|
|
4914
5040
|
}
|
|
4915
|
-
var DOTMEM_DIRECTORY, DEFAULT_MEM_FILE,
|
|
5041
|
+
var DOTMEM_DIRECTORY, DEFAULT_MEM_FILE, nodeFs5, repositoryLoadCaches, separator2, normalizePath, isAbsolutePath, resolvePath, joinPath2, parentPath, uniqueSuffix, isMissingDirectory, sourcePriority, memFilePath, MemDirectoryKnowledgeRepository;
|
|
4916
5042
|
var init_mem_repository = __esm({
|
|
4917
5043
|
"core/knowledge/mem-repository.ts"() {
|
|
4918
5044
|
init_mem_codec();
|
|
4919
5045
|
init_mem_package();
|
|
4920
5046
|
init_state();
|
|
4921
5047
|
init_acquisition_limits();
|
|
5048
|
+
init_storage_coordinator();
|
|
4922
5049
|
DOTMEM_DIRECTORY = ".dotmem";
|
|
4923
5050
|
DEFAULT_MEM_FILE = "project.mem";
|
|
4924
|
-
|
|
4925
|
-
nodeFs4 = /* @__PURE__ */ __name(async () => {
|
|
5051
|
+
nodeFs5 = /* @__PURE__ */ __name(async () => {
|
|
4926
5052
|
return import('fs/promises');
|
|
4927
5053
|
}, "nodeFs");
|
|
5054
|
+
repositoryLoadCaches = /* @__PURE__ */ new Map();
|
|
4928
5055
|
separator2 = /* @__PURE__ */ __name(() => process.platform === "win32" ? "\\" : "/", "separator");
|
|
4929
5056
|
normalizePath = /* @__PURE__ */ __name((value) => value.replace(/[\\/]+/g, separator2()), "normalizePath");
|
|
4930
5057
|
isAbsolutePath = /* @__PURE__ */ __name((value) => /^(?:[A-Za-z]:[\\/]|[\\/])/.test(value), "isAbsolutePath");
|
|
@@ -4936,25 +5063,8 @@ var init_mem_repository = __esm({
|
|
|
4936
5063
|
return index <= 0 ? "." : normalized.slice(0, index);
|
|
4937
5064
|
}, "parentPath");
|
|
4938
5065
|
uniqueSuffix = /* @__PURE__ */ __name(() => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, "uniqueSuffix");
|
|
4939
|
-
withDirectoryLock = /* @__PURE__ */ __name(async (directoryPath, operation) => {
|
|
4940
|
-
const previous = directoryLocks.get(directoryPath) ?? Promise.resolve();
|
|
4941
|
-
let release = /* @__PURE__ */ __name(() => void 0, "release");
|
|
4942
|
-
const gate = new Promise((resolveGate) => {
|
|
4943
|
-
release = resolveGate;
|
|
4944
|
-
});
|
|
4945
|
-
const queued = previous.then(() => gate);
|
|
4946
|
-
directoryLocks.set(directoryPath, queued);
|
|
4947
|
-
await previous;
|
|
4948
|
-
try {
|
|
4949
|
-
return await operation();
|
|
4950
|
-
} finally {
|
|
4951
|
-
release();
|
|
4952
|
-
if (directoryLocks.get(directoryPath) === queued) directoryLocks.delete(directoryPath);
|
|
4953
|
-
}
|
|
4954
|
-
}, "withDirectoryLock");
|
|
4955
5066
|
isMissingDirectory = /* @__PURE__ */ __name((error) => error.code === "ENOENT", "isMissingDirectory");
|
|
4956
5067
|
sourcePriority = /* @__PURE__ */ __name((sourceId, scope) => {
|
|
4957
|
-
if (sourceId.endsWith(".mem") && sourceId !== "project.mem" && sourceId !== "user.mem" && sourceId !== "agent.mem") return 0;
|
|
4958
5068
|
if (scope === "project" || sourceId === "project.mem") return 4;
|
|
4959
5069
|
if (scope === "user" || sourceId === "user.mem") return 3;
|
|
4960
5070
|
if (sourceId === "agent.mem" || sourceId === "agent") return 2;
|
|
@@ -4982,7 +5092,7 @@ var init_mem_repository = __esm({
|
|
|
4982
5092
|
this.loadWritableOnly = loadWritableOnly;
|
|
4983
5093
|
}
|
|
4984
5094
|
async discover() {
|
|
4985
|
-
const { readdir } = await
|
|
5095
|
+
const { readdir } = await nodeFs5();
|
|
4986
5096
|
try {
|
|
4987
5097
|
const entries2 = await readdir(this.directoryPath, { withFileTypes: true });
|
|
4988
5098
|
return entries2.filter((entry) => entry.isFile() && entry.name.endsWith(".mem") && entry.name !== "@brain.mem").map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
@@ -4997,7 +5107,7 @@ var init_mem_repository = __esm({
|
|
|
4997
5107
|
* receive a clear failure instead of discovering corruption on first use.
|
|
4998
5108
|
*/
|
|
4999
5109
|
async initialize() {
|
|
5000
|
-
const { mkdir } = await
|
|
5110
|
+
const { mkdir } = await nodeFs5();
|
|
5001
5111
|
await mkdir(this.directoryPath, { recursive: true });
|
|
5002
5112
|
await this.load();
|
|
5003
5113
|
}
|
|
@@ -5012,7 +5122,7 @@ var init_mem_repository = __esm({
|
|
|
5012
5122
|
* that does not delete is not a delete.
|
|
5013
5123
|
*/
|
|
5014
5124
|
async clearWritable() {
|
|
5015
|
-
const { rm, readdir } = await
|
|
5125
|
+
const { rm, readdir } = await nodeFs5();
|
|
5016
5126
|
const filePath = memFilePath(this.directoryPath, this.writableSourceId);
|
|
5017
5127
|
await rm(filePath, { force: true });
|
|
5018
5128
|
await rm(`${filePath}.bak`, { force: true });
|
|
@@ -5029,15 +5139,28 @@ var init_mem_repository = __esm({
|
|
|
5029
5139
|
}
|
|
5030
5140
|
}
|
|
5031
5141
|
async load() {
|
|
5032
|
-
const
|
|
5033
|
-
|
|
5142
|
+
const cacheKey = `${this.directoryPath}:${this.writableSourceId}:${this.loadWritableOnly}`;
|
|
5143
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
5144
|
+
const generationBefore = await readStorageGeneration(this.directoryPath);
|
|
5145
|
+
const cached = repositoryLoadCaches.get(cacheKey);
|
|
5146
|
+
if (cached && cached.signature === String(generationBefore)) {
|
|
5147
|
+
return structuredClone(cached.state);
|
|
5148
|
+
}
|
|
5149
|
+
const loaded = this.loadWritableOnly ? await this.loadSources([this.writableSourceId]) : await this.loadSources();
|
|
5150
|
+
const state3 = this.combine(loaded);
|
|
5151
|
+
const generationAfter = await readStorageGeneration(this.directoryPath);
|
|
5152
|
+
if (generationBefore !== generationAfter && attempt < 4) continue;
|
|
5153
|
+
repositoryLoadCaches.set(cacheKey, { signature: String(generationAfter), state: structuredClone(state3) });
|
|
5154
|
+
return state3;
|
|
5155
|
+
}
|
|
5156
|
+
throw new Error("Unable to load stable repository state");
|
|
5034
5157
|
}
|
|
5035
|
-
async save(state3, expectedVersion) {
|
|
5158
|
+
async save(state3, expectedVersion, locked = false) {
|
|
5036
5159
|
const validated = validateKnowledgeState(state3);
|
|
5037
5160
|
if (!Number.isInteger(expectedVersion) || expectedVersion < 0 || validated.version !== expectedVersion + 1) {
|
|
5038
5161
|
throw new Error("Invalid expected persisted version");
|
|
5039
5162
|
}
|
|
5040
|
-
|
|
5163
|
+
const doWrite = /* @__PURE__ */ __name(async () => {
|
|
5041
5164
|
const loaded = await this.loadSources();
|
|
5042
5165
|
const writable = loaded.find((source) => source.id === this.writableSourceId) ?? {
|
|
5043
5166
|
id: this.writableSourceId,
|
|
@@ -5059,10 +5182,16 @@ var init_mem_repository = __esm({
|
|
|
5059
5182
|
claims: [...writable.state.claims, ...newClaims]
|
|
5060
5183
|
};
|
|
5061
5184
|
await this.writeSource(writable.filePath, nextWritable, writable.preserved, writable.package);
|
|
5062
|
-
|
|
5185
|
+
await writeStorageGeneration(this.directoryPath, await readStorageGeneration(this.directoryPath) + 1);
|
|
5186
|
+
}, "doWrite");
|
|
5187
|
+
if (locked) {
|
|
5188
|
+
await doWrite();
|
|
5189
|
+
} else {
|
|
5190
|
+
await withStorageLock(this.directoryPath, doWrite);
|
|
5191
|
+
}
|
|
5063
5192
|
}
|
|
5064
5193
|
async loadSources(sourceIds) {
|
|
5065
|
-
const { readFile: readFile4 } = await
|
|
5194
|
+
const { readFile: readFile4 } = await nodeFs5();
|
|
5066
5195
|
const ids = sourceIds ?? await this.discover();
|
|
5067
5196
|
const sources = [];
|
|
5068
5197
|
for (const sourceId of ids) {
|
|
@@ -5152,7 +5281,7 @@ var init_mem_repository = __esm({
|
|
|
5152
5281
|
* valid package, so the backup is always a version this library can read.
|
|
5153
5282
|
*/
|
|
5154
5283
|
async keepLastValidVersion(filePath) {
|
|
5155
|
-
const { readFile: readFile4, copyFile, rename, rm } = await
|
|
5284
|
+
const { readFile: readFile4, copyFile, rename, rm } = await nodeFs5();
|
|
5156
5285
|
let current;
|
|
5157
5286
|
try {
|
|
5158
5287
|
current = await readFile4(filePath);
|
|
@@ -5176,7 +5305,7 @@ var init_mem_repository = __esm({
|
|
|
5176
5305
|
}
|
|
5177
5306
|
/** Best-effort directory sync: the rename is durable once the directory is. */
|
|
5178
5307
|
async syncDirectory(directoryPath) {
|
|
5179
|
-
const { open } = await
|
|
5308
|
+
const { open } = await nodeFs5();
|
|
5180
5309
|
try {
|
|
5181
5310
|
const handle = await open(directoryPath, "r");
|
|
5182
5311
|
try {
|
|
@@ -5188,7 +5317,7 @@ var init_mem_repository = __esm({
|
|
|
5188
5317
|
}
|
|
5189
5318
|
}
|
|
5190
5319
|
async writeSource(filePath, state3, preserved, preservedPackage) {
|
|
5191
|
-
const { mkdir, rename, rm, open, readFile: readFile4 } = await
|
|
5320
|
+
const { mkdir, rename, rm, open, readFile: readFile4 } = await nodeFs5();
|
|
5192
5321
|
if (!Number.isInteger(state3.version) || state3.version < 0) throw new Error("Invalid writable .mem knowledge version");
|
|
5193
5322
|
for (const claim of state3.claims) validateClaim(claim);
|
|
5194
5323
|
await mkdir(parentPath(filePath), { recursive: true });
|
|
@@ -5675,7 +5804,7 @@ var init_project_identity = __esm({
|
|
|
5675
5804
|
});
|
|
5676
5805
|
|
|
5677
5806
|
// core/knowledge/staging.ts
|
|
5678
|
-
var DOTMEM_STAGE_FORMAT, DOTMEM_STAGE_VERSION, StageFileError, generateRequestId, nodeCwd, resolveStagingDirectory, stagePathFor,
|
|
5807
|
+
var DOTMEM_STAGE_FORMAT, DOTMEM_STAGE_VERSION, StageFileError, generateRequestId, nodeCwd, resolveStagingDirectory, stagePathFor, nodeFs6, normalizeClaimIds, revisionFromOptions, writeStageFile, readStageFile, validateStageFile, commitStageFile, cleanupStageFile;
|
|
5679
5808
|
var init_staging = __esm({
|
|
5680
5809
|
"core/knowledge/staging.ts"() {
|
|
5681
5810
|
init_claim_record();
|
|
@@ -5710,7 +5839,7 @@ var init_staging = __esm({
|
|
|
5710
5839
|
return `${base}/dotmem`;
|
|
5711
5840
|
}, "resolveStagingDirectory");
|
|
5712
5841
|
stagePathFor = /* @__PURE__ */ __name((requestId) => `${resolveStagingDirectory()}/${requestId}.stage`, "stagePathFor");
|
|
5713
|
-
|
|
5842
|
+
nodeFs6 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
|
|
5714
5843
|
normalizeClaimIds = /* @__PURE__ */ __name((value) => {
|
|
5715
5844
|
if (!value) return [];
|
|
5716
5845
|
return Array.isArray(value) ? value : [value];
|
|
@@ -5735,7 +5864,7 @@ var init_staging = __esm({
|
|
|
5735
5864
|
};
|
|
5736
5865
|
const requestId = generateRequestId();
|
|
5737
5866
|
const stagePath = stagePathFor(requestId);
|
|
5738
|
-
const fs = await
|
|
5867
|
+
const fs = await nodeFs6();
|
|
5739
5868
|
await fs.mkdir(resolveStagingDirectory(), { recursive: true });
|
|
5740
5869
|
const stageFile = {
|
|
5741
5870
|
format: DOTMEM_STAGE_FORMAT,
|
|
@@ -5755,7 +5884,7 @@ var init_staging = __esm({
|
|
|
5755
5884
|
}, "writeStageFile");
|
|
5756
5885
|
readStageFile = /* @__PURE__ */ __name(async (requestId) => {
|
|
5757
5886
|
const stagePath = stagePathFor(requestId);
|
|
5758
|
-
const fs = await
|
|
5887
|
+
const fs = await nodeFs6();
|
|
5759
5888
|
try {
|
|
5760
5889
|
const content = await fs.readFile(stagePath, "utf8");
|
|
5761
5890
|
return JSON.parse(content);
|
|
@@ -5866,7 +5995,7 @@ var init_staging = __esm({
|
|
|
5866
5995
|
}, "commitStageFile");
|
|
5867
5996
|
cleanupStageFile = /* @__PURE__ */ __name(async (requestId) => {
|
|
5868
5997
|
const stagePath = stagePathFor(requestId);
|
|
5869
|
-
const fs = await
|
|
5998
|
+
const fs = await nodeFs6();
|
|
5870
5999
|
try {
|
|
5871
6000
|
await fs.unlink(stagePath);
|
|
5872
6001
|
} catch (error) {
|
|
@@ -6591,6 +6720,7 @@ function _inferConfidence(claim) {
|
|
|
6591
6720
|
var LOGIC_MEM_FILE, nodeCwd2, cachedRuntime, LogicEngine, logic, logic_default;
|
|
6592
6721
|
var init_logic = __esm({
|
|
6593
6722
|
"core/logic/index.ts"() {
|
|
6723
|
+
init_suppress_idb_warning();
|
|
6594
6724
|
init_knowledge();
|
|
6595
6725
|
init_mem_repository();
|
|
6596
6726
|
init_acquisition_boundary();
|
|
@@ -6858,6 +6988,9 @@ Do not store secrets unless dotmem explicitly supports secure secret storage.
|
|
|
6858
6988
|
}
|
|
6859
6989
|
});
|
|
6860
6990
|
|
|
6991
|
+
// global.ts
|
|
6992
|
+
init_suppress_idb_warning();
|
|
6993
|
+
|
|
6861
6994
|
// core/idb.ts
|
|
6862
6995
|
var idb = {
|
|
6863
6996
|
db: {},
|
|
@@ -7127,7 +7260,11 @@ var security = {
|
|
|
7127
7260
|
createSanitizer
|
|
7128
7261
|
};
|
|
7129
7262
|
|
|
7263
|
+
// core/memory/index.ts
|
|
7264
|
+
init_suppress_idb_warning();
|
|
7265
|
+
|
|
7130
7266
|
// core/memory/journal.ts
|
|
7267
|
+
init_suppress_idb_warning();
|
|
7131
7268
|
init_env();
|
|
7132
7269
|
var g = globalThis;
|
|
7133
7270
|
function namespace() {
|
|
@@ -7334,6 +7471,7 @@ var journal_default = journal;
|
|
|
7334
7471
|
init_brain();
|
|
7335
7472
|
|
|
7336
7473
|
// core/memory/knowledge-runtime.ts
|
|
7474
|
+
init_suppress_idb_warning();
|
|
7337
7475
|
init_knowledge();
|
|
7338
7476
|
init_project_identity();
|
|
7339
7477
|
init_user_paths();
|
|
@@ -7682,6 +7820,7 @@ var policy = {
|
|
|
7682
7820
|
};
|
|
7683
7821
|
|
|
7684
7822
|
// core/memory/entries.ts
|
|
7823
|
+
init_suppress_idb_warning();
|
|
7685
7824
|
init_env();
|
|
7686
7825
|
var MEMORY_INDEX_KEY = "__dotmem_memory_index__";
|
|
7687
7826
|
var SUPERSEDED_PREFIX = "__dotmem_superseded__";
|
|
@@ -8226,15 +8365,18 @@ var context = {
|
|
|
8226
8365
|
};
|
|
8227
8366
|
|
|
8228
8367
|
// core/memory/acquire.ts
|
|
8368
|
+
init_suppress_idb_warning();
|
|
8229
8369
|
init_env();
|
|
8230
8370
|
init_project_identity();
|
|
8231
8371
|
init_project_anchor();
|
|
8232
8372
|
init_acquisition_boundary();
|
|
8233
8373
|
init_claim_record();
|
|
8374
|
+
init_state();
|
|
8234
8375
|
init_router();
|
|
8235
8376
|
init_store_queue();
|
|
8236
8377
|
init_staging();
|
|
8237
8378
|
init_user_paths();
|
|
8379
|
+
init_storage_coordinator();
|
|
8238
8380
|
init_mem_repository();
|
|
8239
8381
|
function normalizeClaimIds3(value) {
|
|
8240
8382
|
if (!value) return [];
|
|
@@ -8312,23 +8454,27 @@ var acquire = {
|
|
|
8312
8454
|
);
|
|
8313
8455
|
}
|
|
8314
8456
|
const revision = revisionFromAcquire2(opts);
|
|
8457
|
+
const repository = target.repository;
|
|
8315
8458
|
await withStoreQueue(acquisitionStoreKey(kind, scope, sourceProject), async () => {
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8459
|
+
await withStorageLock(repository.directoryPath, async () => {
|
|
8460
|
+
const state3 = await repository.load();
|
|
8461
|
+
const next = updateKnowledge(state3, {
|
|
8462
|
+
basedOnVersion: state3.version,
|
|
8463
|
+
claims: [buildClaimRecord({
|
|
8464
|
+
id: opts.id,
|
|
8465
|
+
knowledge: boundary.knowledge,
|
|
8466
|
+
applicability: opts.applicability,
|
|
8467
|
+
evidence: opts.evidence,
|
|
8468
|
+
epistemicType: opts.epistemicType,
|
|
8469
|
+
provenance: opts.provenance,
|
|
8470
|
+
acquiredAt: opts.acquiredAt,
|
|
8471
|
+
revision,
|
|
8472
|
+
scope,
|
|
8473
|
+
sourceProject,
|
|
8474
|
+
kind
|
|
8475
|
+
})]
|
|
8476
|
+
});
|
|
8477
|
+
await repository.save(next, state3.version, true);
|
|
8332
8478
|
});
|
|
8333
8479
|
});
|
|
8334
8480
|
const verification = await target.repository.load();
|