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.js
CHANGED
|
@@ -17,6 +17,18 @@ var __export = (target, all) => {
|
|
|
17
17
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
// suppress-idb-warning.ts
|
|
21
|
+
var orig;
|
|
22
|
+
var init_suppress_idb_warning = __esm({
|
|
23
|
+
"suppress-idb-warning.ts"() {
|
|
24
|
+
orig = console.warn.bind(console);
|
|
25
|
+
console.warn = (...args) => {
|
|
26
|
+
if (typeof args[0] === "string" && args[0].includes("IndexedDB is not available")) return;
|
|
27
|
+
orig(...args);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
20
32
|
// core/env.ts
|
|
21
33
|
var DEV;
|
|
22
34
|
var init_env = __esm({
|
|
@@ -2401,6 +2413,7 @@ var init_policy_store = __esm({
|
|
|
2401
2413
|
if (entry.target !== void 0) built.target = entry.target;
|
|
2402
2414
|
if (entry.reason !== void 0) built.reason = entry.reason;
|
|
2403
2415
|
if (entry.detail !== void 0) built.detail = entry.detail;
|
|
2416
|
+
if (entry.mandatory !== void 0) built.mandatory = entry.mandatory;
|
|
2404
2417
|
return built;
|
|
2405
2418
|
}, "validatePolicyAuditEntry");
|
|
2406
2419
|
validatePolicyDocument = /* @__PURE__ */ __name((value) => {
|
|
@@ -2478,6 +2491,7 @@ var init_policy_store = __esm({
|
|
|
2478
2491
|
if (entry.target !== void 0) built.target = entry.target;
|
|
2479
2492
|
if (entry.reason !== void 0) built.reason = entry.reason;
|
|
2480
2493
|
if (entry.detail !== void 0) built.detail = entry.detail;
|
|
2494
|
+
if (entry.mandatory !== void 0) built.mandatory = entry.mandatory;
|
|
2481
2495
|
return built;
|
|
2482
2496
|
}, "buildAuditEntry");
|
|
2483
2497
|
boundedAudit = /* @__PURE__ */ __name((entries2, overrides) => {
|
|
@@ -2490,9 +2504,10 @@ var init_policy_store = __esm({
|
|
|
2490
2504
|
for (let index = entries2.length - 1; index >= 0; index--) {
|
|
2491
2505
|
const entry = entries2[index];
|
|
2492
2506
|
const activeLinked = entry.target !== void 0 && activeOverrideIds.has(entry.target) && (entry.action === "override" || entry.action === "revoke");
|
|
2493
|
-
|
|
2507
|
+
const mandatory = entry.mandatory === true;
|
|
2508
|
+
if (activeLinked || mandatory || budget > 0) {
|
|
2494
2509
|
kept.unshift(entry);
|
|
2495
|
-
if (!activeLinked) budget--;
|
|
2510
|
+
if (!activeLinked && !mandatory) budget--;
|
|
2496
2511
|
}
|
|
2497
2512
|
}
|
|
2498
2513
|
return kept;
|
|
@@ -2533,6 +2548,12 @@ var init_policy_store = __esm({
|
|
|
2533
2548
|
try {
|
|
2534
2549
|
await fs.writeFile(temporary, `${JSON.stringify(document, null, 2)}
|
|
2535
2550
|
`, "utf8");
|
|
2551
|
+
const handle = await fs.open(temporary, "r+");
|
|
2552
|
+
try {
|
|
2553
|
+
await handle.sync();
|
|
2554
|
+
} finally {
|
|
2555
|
+
await handle.close();
|
|
2556
|
+
}
|
|
2536
2557
|
await fs.rename(temporary, filePath);
|
|
2537
2558
|
} catch (error) {
|
|
2538
2559
|
await fs.rm(temporary, { force: true }).catch(() => void 0);
|
|
@@ -4451,7 +4472,7 @@ function encodeMemFile(stateValue, preserved) {
|
|
|
4451
4472
|
function decodeMemDocument(value) {
|
|
4452
4473
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid .mem file format");
|
|
4453
4474
|
const file = value;
|
|
4454
|
-
if (file.format !== MEM_FORMAT) throw new Error("Invalid .mem file format");
|
|
4475
|
+
if (file.format !== MEM_FORMAT && file.format !== MEM_FORMAT_LEGACY) throw new Error("Invalid .mem file format");
|
|
4455
4476
|
if (file.version === MEM_FORMAT_VERSION_V1) {
|
|
4456
4477
|
if (!file.knowledge) throw new Error("Invalid .mem file format");
|
|
4457
4478
|
return { state: validateSourceState(file.knowledge) };
|
|
@@ -4533,11 +4554,12 @@ function decodeMemDocument(value) {
|
|
|
4533
4554
|
preserved: { map: structuredClone(map), data: structuredClone(stateRecord) }
|
|
4534
4555
|
};
|
|
4535
4556
|
}
|
|
4536
|
-
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;
|
|
4557
|
+
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;
|
|
4537
4558
|
var init_mem_codec = __esm({
|
|
4538
4559
|
"core/knowledge/mem-codec.ts"() {
|
|
4539
4560
|
init_state();
|
|
4540
4561
|
MEM_FORMAT = "dotmem.knowledge";
|
|
4562
|
+
MEM_FORMAT_LEGACY = "memorio.knowledge";
|
|
4541
4563
|
MEM_FORMAT_VERSION = 2;
|
|
4542
4564
|
MEM_FORMAT_VERSION_V1 = 1;
|
|
4543
4565
|
expectedFields = {
|
|
@@ -4643,12 +4665,13 @@ async function decodeMemArtifact(input) {
|
|
|
4643
4665
|
throw new MemArtifactError(message.startsWith("Unsupported") ? "unsupported" : "invalid", message);
|
|
4644
4666
|
}
|
|
4645
4667
|
}
|
|
4646
|
-
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;
|
|
4668
|
+
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;
|
|
4647
4669
|
var init_mem_package = __esm({
|
|
4648
4670
|
"core/knowledge/mem-package.ts"() {
|
|
4649
4671
|
init_browser();
|
|
4650
4672
|
init_mem_codec();
|
|
4651
4673
|
MEM_PACKAGE_FORMAT = "dotmem.package";
|
|
4674
|
+
MEM_PACKAGE_FORMAT_LEGACY = "memorio.package";
|
|
4652
4675
|
MEM_PACKAGE_VERSION = 1;
|
|
4653
4676
|
MEM_PACKAGE_LIMITS = Object.freeze({
|
|
4654
4677
|
maximumPackageBytes: 10 * 1024 * 1024,
|
|
@@ -4822,10 +4845,10 @@ var init_mem_package = __esm({
|
|
|
4822
4845
|
if (!parts[path]) throw new MemArtifactError("invalid", `Missing MEM package part: ${path}`);
|
|
4823
4846
|
}
|
|
4824
4847
|
const manifest = parseJson(parts[MANIFEST_PATH], MANIFEST_PATH);
|
|
4825
|
-
if (manifest.format !== MEM_PACKAGE_FORMAT && manifest.format || manifest.version !== MEM_PACKAGE_VERSION) {
|
|
4848
|
+
if (manifest.format !== MEM_PACKAGE_FORMAT && manifest.format !== MEM_PACKAGE_FORMAT_LEGACY || manifest.version !== MEM_PACKAGE_VERSION) {
|
|
4826
4849
|
throw new MemArtifactError("unsupported", "Unsupported MEM package format or version");
|
|
4827
4850
|
}
|
|
4828
|
-
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) {
|
|
4851
|
+
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) {
|
|
4829
4852
|
throw new MemArtifactError("invalid", "Invalid MEM package manifest");
|
|
4830
4853
|
}
|
|
4831
4854
|
const integrity = parseJson(parts[INTEGRITY_PATH], INTEGRITY_PATH);
|
|
@@ -4868,6 +4891,109 @@ var init_mem_package = __esm({
|
|
|
4868
4891
|
}
|
|
4869
4892
|
});
|
|
4870
4893
|
|
|
4894
|
+
// core/storage-coordinator/index.ts
|
|
4895
|
+
var nodeFs4, withStorageLock, readStorageGeneration, writeStorageGeneration;
|
|
4896
|
+
var init_storage_coordinator = __esm({
|
|
4897
|
+
"core/storage-coordinator/index.ts"() {
|
|
4898
|
+
nodeFs4 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
|
|
4899
|
+
withStorageLock = /* @__PURE__ */ __name(async (directoryPath, operationOrOptions, operation, _options = {}) => {
|
|
4900
|
+
const opts = typeof operationOrOptions === "function" ? operation ?? {} : operationOrOptions ?? {};
|
|
4901
|
+
const op = typeof operationOrOptions === "function" ? operationOrOptions : operation;
|
|
4902
|
+
const timeoutMs = opts.timeoutMs ?? 3e4;
|
|
4903
|
+
const staleMs = opts.staleMs ?? 6e4;
|
|
4904
|
+
const lockName = opts.lockName ?? ".storage.lock";
|
|
4905
|
+
const lockPath = `${directoryPath}/${lockName}`;
|
|
4906
|
+
const fs = await nodeFs4();
|
|
4907
|
+
const started = Date.now();
|
|
4908
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
|
4909
|
+
while (true) {
|
|
4910
|
+
try {
|
|
4911
|
+
await fs.mkdir(lockPath);
|
|
4912
|
+
const token2 = `${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
4913
|
+
await fs.writeFile(`${lockPath}/owner.json`, JSON.stringify({ token: token2, pid: process.pid, createdAt: Date.now() }), { flag: "wx" });
|
|
4914
|
+
break;
|
|
4915
|
+
} catch (error) {
|
|
4916
|
+
const code = error.code;
|
|
4917
|
+
if (code !== "EEXIST" && code !== "ENOENT" && code !== "EPERM" && code !== "ENOTEMPTY") throw error;
|
|
4918
|
+
let stale = false;
|
|
4919
|
+
let processDead = false;
|
|
4920
|
+
try {
|
|
4921
|
+
const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
|
|
4922
|
+
const parsed = JSON.parse(raw);
|
|
4923
|
+
const ageStale = typeof parsed.createdAt === "number" && Date.now() - parsed.createdAt > staleMs;
|
|
4924
|
+
if (typeof parsed.pid === "number") {
|
|
4925
|
+
try {
|
|
4926
|
+
process.kill(parsed.pid, 0);
|
|
4927
|
+
} catch {
|
|
4928
|
+
processDead = true;
|
|
4929
|
+
}
|
|
4930
|
+
} else {
|
|
4931
|
+
processDead = true;
|
|
4932
|
+
}
|
|
4933
|
+
if (ageStale || processDead) stale = true;
|
|
4934
|
+
} catch {
|
|
4935
|
+
stale = true;
|
|
4936
|
+
}
|
|
4937
|
+
if (stale) {
|
|
4938
|
+
if (processDead) {
|
|
4939
|
+
try {
|
|
4940
|
+
await fs.rm(lockPath, { recursive: true, force: true });
|
|
4941
|
+
continue;
|
|
4942
|
+
} catch {
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
try {
|
|
4946
|
+
await fs.rmdir(lockPath);
|
|
4947
|
+
continue;
|
|
4948
|
+
} catch {
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
if (Date.now() - started > timeoutMs) {
|
|
4952
|
+
throw new Error(`Storage lock timeout for ${directoryPath}`);
|
|
4953
|
+
}
|
|
4954
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
let token = "";
|
|
4958
|
+
try {
|
|
4959
|
+
const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
|
|
4960
|
+
token = JSON.parse(raw).token ?? "";
|
|
4961
|
+
} catch {
|
|
4962
|
+
token = "";
|
|
4963
|
+
}
|
|
4964
|
+
try {
|
|
4965
|
+
return await op();
|
|
4966
|
+
} finally {
|
|
4967
|
+
try {
|
|
4968
|
+
const raw = await fs.readFile(`${lockPath}/owner.json`, "utf8");
|
|
4969
|
+
const parsed = JSON.parse(raw);
|
|
4970
|
+
if (parsed.token === token && token) {
|
|
4971
|
+
await fs.rm(lockPath, { recursive: true, force: true });
|
|
4972
|
+
}
|
|
4973
|
+
} catch {
|
|
4974
|
+
}
|
|
4975
|
+
}
|
|
4976
|
+
}, "withStorageLock");
|
|
4977
|
+
readStorageGeneration = /* @__PURE__ */ __name(async (directoryPath) => {
|
|
4978
|
+
const fs = await nodeFs4();
|
|
4979
|
+
try {
|
|
4980
|
+
const raw = await fs.readFile(`${directoryPath}/.storage.generation`, "utf8");
|
|
4981
|
+
const value = Number(raw.trim());
|
|
4982
|
+
return Number.isFinite(value) && value >= 0 ? value : 0;
|
|
4983
|
+
} catch {
|
|
4984
|
+
return 0;
|
|
4985
|
+
}
|
|
4986
|
+
}, "readStorageGeneration");
|
|
4987
|
+
writeStorageGeneration = /* @__PURE__ */ __name(async (directoryPath, value) => {
|
|
4988
|
+
const fs = await nodeFs4();
|
|
4989
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
|
4990
|
+
const temp = `${directoryPath}/.storage.generation.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
4991
|
+
await fs.writeFile(temp, String(value));
|
|
4992
|
+
await fs.rename(temp, `${directoryPath}/.storage.generation`);
|
|
4993
|
+
}, "writeStorageGeneration");
|
|
4994
|
+
}
|
|
4995
|
+
});
|
|
4996
|
+
|
|
4871
4997
|
// core/knowledge/mem-repository.ts
|
|
4872
4998
|
function resolveDuplicate(existing, existingSource, current, currentSource) {
|
|
4873
4999
|
const existingRetracts = existing.revision?.kind === "retracts";
|
|
@@ -4908,19 +5034,20 @@ async function parseMemFile(value, sourceId) {
|
|
|
4908
5034
|
throw new Error(`${message} in ${sourceId}`);
|
|
4909
5035
|
}
|
|
4910
5036
|
}
|
|
4911
|
-
var DOTMEM_DIRECTORY, DEFAULT_MEM_FILE,
|
|
5037
|
+
var DOTMEM_DIRECTORY, DEFAULT_MEM_FILE, nodeFs5, repositoryLoadCaches, separator2, normalizePath, isAbsolutePath, resolvePath, joinPath2, parentPath, uniqueSuffix, isMissingDirectory, sourcePriority, memFilePath, MemDirectoryKnowledgeRepository;
|
|
4912
5038
|
var init_mem_repository = __esm({
|
|
4913
5039
|
"core/knowledge/mem-repository.ts"() {
|
|
4914
5040
|
init_mem_codec();
|
|
4915
5041
|
init_mem_package();
|
|
4916
5042
|
init_state();
|
|
4917
5043
|
init_acquisition_limits();
|
|
5044
|
+
init_storage_coordinator();
|
|
4918
5045
|
DOTMEM_DIRECTORY = ".dotmem";
|
|
4919
5046
|
DEFAULT_MEM_FILE = "project.mem";
|
|
4920
|
-
|
|
4921
|
-
nodeFs4 = /* @__PURE__ */ __name(async () => {
|
|
5047
|
+
nodeFs5 = /* @__PURE__ */ __name(async () => {
|
|
4922
5048
|
return import('fs/promises');
|
|
4923
5049
|
}, "nodeFs");
|
|
5050
|
+
repositoryLoadCaches = /* @__PURE__ */ new Map();
|
|
4924
5051
|
separator2 = /* @__PURE__ */ __name(() => process.platform === "win32" ? "\\" : "/", "separator");
|
|
4925
5052
|
normalizePath = /* @__PURE__ */ __name((value) => value.replace(/[\\/]+/g, separator2()), "normalizePath");
|
|
4926
5053
|
isAbsolutePath = /* @__PURE__ */ __name((value) => /^(?:[A-Za-z]:[\\/]|[\\/])/.test(value), "isAbsolutePath");
|
|
@@ -4932,25 +5059,8 @@ var init_mem_repository = __esm({
|
|
|
4932
5059
|
return index <= 0 ? "." : normalized.slice(0, index);
|
|
4933
5060
|
}, "parentPath");
|
|
4934
5061
|
uniqueSuffix = /* @__PURE__ */ __name(() => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, "uniqueSuffix");
|
|
4935
|
-
withDirectoryLock = /* @__PURE__ */ __name(async (directoryPath, operation) => {
|
|
4936
|
-
const previous = directoryLocks.get(directoryPath) ?? Promise.resolve();
|
|
4937
|
-
let release = /* @__PURE__ */ __name(() => void 0, "release");
|
|
4938
|
-
const gate = new Promise((resolveGate) => {
|
|
4939
|
-
release = resolveGate;
|
|
4940
|
-
});
|
|
4941
|
-
const queued = previous.then(() => gate);
|
|
4942
|
-
directoryLocks.set(directoryPath, queued);
|
|
4943
|
-
await previous;
|
|
4944
|
-
try {
|
|
4945
|
-
return await operation();
|
|
4946
|
-
} finally {
|
|
4947
|
-
release();
|
|
4948
|
-
if (directoryLocks.get(directoryPath) === queued) directoryLocks.delete(directoryPath);
|
|
4949
|
-
}
|
|
4950
|
-
}, "withDirectoryLock");
|
|
4951
5062
|
isMissingDirectory = /* @__PURE__ */ __name((error) => error.code === "ENOENT", "isMissingDirectory");
|
|
4952
5063
|
sourcePriority = /* @__PURE__ */ __name((sourceId, scope) => {
|
|
4953
|
-
if (sourceId.endsWith(".mem") && sourceId !== "project.mem" && sourceId !== "user.mem" && sourceId !== "agent.mem") return 0;
|
|
4954
5064
|
if (scope === "project" || sourceId === "project.mem") return 4;
|
|
4955
5065
|
if (scope === "user" || sourceId === "user.mem") return 3;
|
|
4956
5066
|
if (sourceId === "agent.mem" || sourceId === "agent") return 2;
|
|
@@ -4978,7 +5088,7 @@ var init_mem_repository = __esm({
|
|
|
4978
5088
|
this.loadWritableOnly = loadWritableOnly;
|
|
4979
5089
|
}
|
|
4980
5090
|
async discover() {
|
|
4981
|
-
const { readdir } = await
|
|
5091
|
+
const { readdir } = await nodeFs5();
|
|
4982
5092
|
try {
|
|
4983
5093
|
const entries2 = await readdir(this.directoryPath, { withFileTypes: true });
|
|
4984
5094
|
return entries2.filter((entry) => entry.isFile() && entry.name.endsWith(".mem") && entry.name !== "@brain.mem").map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
@@ -4993,7 +5103,7 @@ var init_mem_repository = __esm({
|
|
|
4993
5103
|
* receive a clear failure instead of discovering corruption on first use.
|
|
4994
5104
|
*/
|
|
4995
5105
|
async initialize() {
|
|
4996
|
-
const { mkdir } = await
|
|
5106
|
+
const { mkdir } = await nodeFs5();
|
|
4997
5107
|
await mkdir(this.directoryPath, { recursive: true });
|
|
4998
5108
|
await this.load();
|
|
4999
5109
|
}
|
|
@@ -5008,7 +5118,7 @@ var init_mem_repository = __esm({
|
|
|
5008
5118
|
* that does not delete is not a delete.
|
|
5009
5119
|
*/
|
|
5010
5120
|
async clearWritable() {
|
|
5011
|
-
const { rm, readdir } = await
|
|
5121
|
+
const { rm, readdir } = await nodeFs5();
|
|
5012
5122
|
const filePath = memFilePath(this.directoryPath, this.writableSourceId);
|
|
5013
5123
|
await rm(filePath, { force: true });
|
|
5014
5124
|
await rm(`${filePath}.bak`, { force: true });
|
|
@@ -5025,15 +5135,28 @@ var init_mem_repository = __esm({
|
|
|
5025
5135
|
}
|
|
5026
5136
|
}
|
|
5027
5137
|
async load() {
|
|
5028
|
-
const
|
|
5029
|
-
|
|
5138
|
+
const cacheKey = `${this.directoryPath}:${this.writableSourceId}:${this.loadWritableOnly}`;
|
|
5139
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
5140
|
+
const generationBefore = await readStorageGeneration(this.directoryPath);
|
|
5141
|
+
const cached = repositoryLoadCaches.get(cacheKey);
|
|
5142
|
+
if (cached && cached.signature === String(generationBefore)) {
|
|
5143
|
+
return structuredClone(cached.state);
|
|
5144
|
+
}
|
|
5145
|
+
const loaded = this.loadWritableOnly ? await this.loadSources([this.writableSourceId]) : await this.loadSources();
|
|
5146
|
+
const state3 = this.combine(loaded);
|
|
5147
|
+
const generationAfter = await readStorageGeneration(this.directoryPath);
|
|
5148
|
+
if (generationBefore !== generationAfter && attempt < 4) continue;
|
|
5149
|
+
repositoryLoadCaches.set(cacheKey, { signature: String(generationAfter), state: structuredClone(state3) });
|
|
5150
|
+
return state3;
|
|
5151
|
+
}
|
|
5152
|
+
throw new Error("Unable to load stable repository state");
|
|
5030
5153
|
}
|
|
5031
|
-
async save(state3, expectedVersion) {
|
|
5154
|
+
async save(state3, expectedVersion, locked = false) {
|
|
5032
5155
|
const validated = validateKnowledgeState(state3);
|
|
5033
5156
|
if (!Number.isInteger(expectedVersion) || expectedVersion < 0 || validated.version !== expectedVersion + 1) {
|
|
5034
5157
|
throw new Error("Invalid expected persisted version");
|
|
5035
5158
|
}
|
|
5036
|
-
|
|
5159
|
+
const doWrite = /* @__PURE__ */ __name(async () => {
|
|
5037
5160
|
const loaded = await this.loadSources();
|
|
5038
5161
|
const writable = loaded.find((source) => source.id === this.writableSourceId) ?? {
|
|
5039
5162
|
id: this.writableSourceId,
|
|
@@ -5055,10 +5178,16 @@ var init_mem_repository = __esm({
|
|
|
5055
5178
|
claims: [...writable.state.claims, ...newClaims]
|
|
5056
5179
|
};
|
|
5057
5180
|
await this.writeSource(writable.filePath, nextWritable, writable.preserved, writable.package);
|
|
5058
|
-
|
|
5181
|
+
await writeStorageGeneration(this.directoryPath, await readStorageGeneration(this.directoryPath) + 1);
|
|
5182
|
+
}, "doWrite");
|
|
5183
|
+
if (locked) {
|
|
5184
|
+
await doWrite();
|
|
5185
|
+
} else {
|
|
5186
|
+
await withStorageLock(this.directoryPath, doWrite);
|
|
5187
|
+
}
|
|
5059
5188
|
}
|
|
5060
5189
|
async loadSources(sourceIds) {
|
|
5061
|
-
const { readFile: readFile4 } = await
|
|
5190
|
+
const { readFile: readFile4 } = await nodeFs5();
|
|
5062
5191
|
const ids = sourceIds ?? await this.discover();
|
|
5063
5192
|
const sources = [];
|
|
5064
5193
|
for (const sourceId of ids) {
|
|
@@ -5148,7 +5277,7 @@ var init_mem_repository = __esm({
|
|
|
5148
5277
|
* valid package, so the backup is always a version this library can read.
|
|
5149
5278
|
*/
|
|
5150
5279
|
async keepLastValidVersion(filePath) {
|
|
5151
|
-
const { readFile: readFile4, copyFile, rename, rm } = await
|
|
5280
|
+
const { readFile: readFile4, copyFile, rename, rm } = await nodeFs5();
|
|
5152
5281
|
let current;
|
|
5153
5282
|
try {
|
|
5154
5283
|
current = await readFile4(filePath);
|
|
@@ -5172,7 +5301,7 @@ var init_mem_repository = __esm({
|
|
|
5172
5301
|
}
|
|
5173
5302
|
/** Best-effort directory sync: the rename is durable once the directory is. */
|
|
5174
5303
|
async syncDirectory(directoryPath) {
|
|
5175
|
-
const { open } = await
|
|
5304
|
+
const { open } = await nodeFs5();
|
|
5176
5305
|
try {
|
|
5177
5306
|
const handle = await open(directoryPath, "r");
|
|
5178
5307
|
try {
|
|
@@ -5184,7 +5313,7 @@ var init_mem_repository = __esm({
|
|
|
5184
5313
|
}
|
|
5185
5314
|
}
|
|
5186
5315
|
async writeSource(filePath, state3, preserved, preservedPackage) {
|
|
5187
|
-
const { mkdir, rename, rm, open, readFile: readFile4 } = await
|
|
5316
|
+
const { mkdir, rename, rm, open, readFile: readFile4 } = await nodeFs5();
|
|
5188
5317
|
if (!Number.isInteger(state3.version) || state3.version < 0) throw new Error("Invalid writable .mem knowledge version");
|
|
5189
5318
|
for (const claim of state3.claims) validateClaim(claim);
|
|
5190
5319
|
await mkdir(parentPath(filePath), { recursive: true });
|
|
@@ -5671,7 +5800,7 @@ var init_project_identity = __esm({
|
|
|
5671
5800
|
});
|
|
5672
5801
|
|
|
5673
5802
|
// core/knowledge/staging.ts
|
|
5674
|
-
var DOTMEM_STAGE_FORMAT, DOTMEM_STAGE_VERSION, StageFileError, generateRequestId, nodeCwd, resolveStagingDirectory, stagePathFor,
|
|
5803
|
+
var DOTMEM_STAGE_FORMAT, DOTMEM_STAGE_VERSION, StageFileError, generateRequestId, nodeCwd, resolveStagingDirectory, stagePathFor, nodeFs6, normalizeClaimIds, revisionFromOptions, writeStageFile, readStageFile, validateStageFile, commitStageFile, cleanupStageFile;
|
|
5675
5804
|
var init_staging = __esm({
|
|
5676
5805
|
"core/knowledge/staging.ts"() {
|
|
5677
5806
|
init_claim_record();
|
|
@@ -5706,7 +5835,7 @@ var init_staging = __esm({
|
|
|
5706
5835
|
return `${base}/dotmem`;
|
|
5707
5836
|
}, "resolveStagingDirectory");
|
|
5708
5837
|
stagePathFor = /* @__PURE__ */ __name((requestId) => `${resolveStagingDirectory()}/${requestId}.stage`, "stagePathFor");
|
|
5709
|
-
|
|
5838
|
+
nodeFs6 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
|
|
5710
5839
|
normalizeClaimIds = /* @__PURE__ */ __name((value) => {
|
|
5711
5840
|
if (!value) return [];
|
|
5712
5841
|
return Array.isArray(value) ? value : [value];
|
|
@@ -5731,7 +5860,7 @@ var init_staging = __esm({
|
|
|
5731
5860
|
};
|
|
5732
5861
|
const requestId = generateRequestId();
|
|
5733
5862
|
const stagePath = stagePathFor(requestId);
|
|
5734
|
-
const fs = await
|
|
5863
|
+
const fs = await nodeFs6();
|
|
5735
5864
|
await fs.mkdir(resolveStagingDirectory(), { recursive: true });
|
|
5736
5865
|
const stageFile = {
|
|
5737
5866
|
format: DOTMEM_STAGE_FORMAT,
|
|
@@ -5751,7 +5880,7 @@ var init_staging = __esm({
|
|
|
5751
5880
|
}, "writeStageFile");
|
|
5752
5881
|
readStageFile = /* @__PURE__ */ __name(async (requestId) => {
|
|
5753
5882
|
const stagePath = stagePathFor(requestId);
|
|
5754
|
-
const fs = await
|
|
5883
|
+
const fs = await nodeFs6();
|
|
5755
5884
|
try {
|
|
5756
5885
|
const content = await fs.readFile(stagePath, "utf8");
|
|
5757
5886
|
return JSON.parse(content);
|
|
@@ -5862,7 +5991,7 @@ var init_staging = __esm({
|
|
|
5862
5991
|
}, "commitStageFile");
|
|
5863
5992
|
cleanupStageFile = /* @__PURE__ */ __name(async (requestId) => {
|
|
5864
5993
|
const stagePath = stagePathFor(requestId);
|
|
5865
|
-
const fs = await
|
|
5994
|
+
const fs = await nodeFs6();
|
|
5866
5995
|
try {
|
|
5867
5996
|
await fs.unlink(stagePath);
|
|
5868
5997
|
} catch (error) {
|
|
@@ -6587,6 +6716,7 @@ function _inferConfidence(claim) {
|
|
|
6587
6716
|
var LOGIC_MEM_FILE, nodeCwd2, cachedRuntime, LogicEngine, logic, logic_default;
|
|
6588
6717
|
var init_logic = __esm({
|
|
6589
6718
|
"core/logic/index.ts"() {
|
|
6719
|
+
init_suppress_idb_warning();
|
|
6590
6720
|
init_knowledge();
|
|
6591
6721
|
init_mem_repository();
|
|
6592
6722
|
init_acquisition_boundary();
|
|
@@ -6854,6 +6984,9 @@ Do not store secrets unless dotmem explicitly supports secure secret storage.
|
|
|
6854
6984
|
}
|
|
6855
6985
|
});
|
|
6856
6986
|
|
|
6987
|
+
// global.ts
|
|
6988
|
+
init_suppress_idb_warning();
|
|
6989
|
+
|
|
6857
6990
|
// core/idb.ts
|
|
6858
6991
|
var idb = {
|
|
6859
6992
|
db: {},
|
|
@@ -7123,7 +7256,11 @@ var security = {
|
|
|
7123
7256
|
createSanitizer
|
|
7124
7257
|
};
|
|
7125
7258
|
|
|
7259
|
+
// core/memory/index.ts
|
|
7260
|
+
init_suppress_idb_warning();
|
|
7261
|
+
|
|
7126
7262
|
// core/memory/journal.ts
|
|
7263
|
+
init_suppress_idb_warning();
|
|
7127
7264
|
init_env();
|
|
7128
7265
|
var g = globalThis;
|
|
7129
7266
|
function namespace() {
|
|
@@ -7330,6 +7467,7 @@ var journal_default = journal;
|
|
|
7330
7467
|
init_brain();
|
|
7331
7468
|
|
|
7332
7469
|
// core/memory/knowledge-runtime.ts
|
|
7470
|
+
init_suppress_idb_warning();
|
|
7333
7471
|
init_knowledge();
|
|
7334
7472
|
init_project_identity();
|
|
7335
7473
|
init_user_paths();
|
|
@@ -7678,6 +7816,7 @@ var policy = {
|
|
|
7678
7816
|
};
|
|
7679
7817
|
|
|
7680
7818
|
// core/memory/entries.ts
|
|
7819
|
+
init_suppress_idb_warning();
|
|
7681
7820
|
init_env();
|
|
7682
7821
|
var MEMORY_INDEX_KEY = "__dotmem_memory_index__";
|
|
7683
7822
|
var SUPERSEDED_PREFIX = "__dotmem_superseded__";
|
|
@@ -8222,15 +8361,18 @@ var context = {
|
|
|
8222
8361
|
};
|
|
8223
8362
|
|
|
8224
8363
|
// core/memory/acquire.ts
|
|
8364
|
+
init_suppress_idb_warning();
|
|
8225
8365
|
init_env();
|
|
8226
8366
|
init_project_identity();
|
|
8227
8367
|
init_project_anchor();
|
|
8228
8368
|
init_acquisition_boundary();
|
|
8229
8369
|
init_claim_record();
|
|
8370
|
+
init_state();
|
|
8230
8371
|
init_router();
|
|
8231
8372
|
init_store_queue();
|
|
8232
8373
|
init_staging();
|
|
8233
8374
|
init_user_paths();
|
|
8375
|
+
init_storage_coordinator();
|
|
8234
8376
|
init_mem_repository();
|
|
8235
8377
|
function normalizeClaimIds3(value) {
|
|
8236
8378
|
if (!value) return [];
|
|
@@ -8308,23 +8450,27 @@ var acquire = {
|
|
|
8308
8450
|
);
|
|
8309
8451
|
}
|
|
8310
8452
|
const revision = revisionFromAcquire2(opts);
|
|
8453
|
+
const repository = target.repository;
|
|
8311
8454
|
await withStoreQueue(acquisitionStoreKey(kind, scope, sourceProject), async () => {
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8455
|
+
await withStorageLock(repository.directoryPath, async () => {
|
|
8456
|
+
const state3 = await repository.load();
|
|
8457
|
+
const next = updateKnowledge(state3, {
|
|
8458
|
+
basedOnVersion: state3.version,
|
|
8459
|
+
claims: [buildClaimRecord({
|
|
8460
|
+
id: opts.id,
|
|
8461
|
+
knowledge: boundary.knowledge,
|
|
8462
|
+
applicability: opts.applicability,
|
|
8463
|
+
evidence: opts.evidence,
|
|
8464
|
+
epistemicType: opts.epistemicType,
|
|
8465
|
+
provenance: opts.provenance,
|
|
8466
|
+
acquiredAt: opts.acquiredAt,
|
|
8467
|
+
revision,
|
|
8468
|
+
scope,
|
|
8469
|
+
sourceProject,
|
|
8470
|
+
kind
|
|
8471
|
+
})]
|
|
8472
|
+
});
|
|
8473
|
+
await repository.save(next, state3.version, true);
|
|
8328
8474
|
});
|
|
8329
8475
|
});
|
|
8330
8476
|
const verification = await target.repository.load();
|