dotmem 0.1.7 → 0.1.8
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/agent.cjs +0 -29
- package/agent.js +0 -29
- package/bin/cli.cjs +0 -5
- package/bin/cli.js +0 -5
- package/bin/mcp.cjs +0 -5
- package/bin/mcp.js +0 -5
- package/built-in-context.json +2 -2
- package/cli.cjs +622 -168
- package/cli.js +623 -169
- package/global.cjs +444 -97
- package/global.js +445 -97
- package/index.cjs +451 -99
- package/index.js +452 -99
- package/mcp.cjs +703 -101
- package/mcp.js +704 -102
- package/package.json +2 -2
- package/types/exports.d.ts +0 -2
- package/types/memory.d.ts +52 -1
package/cli.cjs
CHANGED
|
@@ -44,18 +44,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
44
44
|
};
|
|
45
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
46
|
|
|
47
|
-
// core/suppress-idb-warning.ts
|
|
48
|
-
var orig;
|
|
49
|
-
var init_suppress_idb_warning = __esm({
|
|
50
|
-
"core/suppress-idb-warning.ts"() {
|
|
51
|
-
orig = console.warn.bind(console);
|
|
52
|
-
console.warn = (...args) => {
|
|
53
|
-
if (typeof args[0] === "string" && args[0].includes("IndexedDB is not available")) return;
|
|
54
|
-
orig(...args);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
47
|
// core/env.ts
|
|
60
48
|
var DEV;
|
|
61
49
|
var init_env = __esm({
|
|
@@ -90,7 +78,6 @@ function configure(opts) {
|
|
|
90
78
|
var g, STORE_PREFIX, INDEX_KEY, journal, journal_default;
|
|
91
79
|
var init_journal = __esm({
|
|
92
80
|
"core/memory/journal.ts"() {
|
|
93
|
-
init_suppress_idb_warning();
|
|
94
81
|
init_env();
|
|
95
82
|
g = globalThis;
|
|
96
83
|
__name(namespace, "namespace");
|
|
@@ -338,6 +325,60 @@ var init_storage_paths = __esm({
|
|
|
338
325
|
}
|
|
339
326
|
});
|
|
340
327
|
|
|
328
|
+
// core/knowledge/text-encoding.ts
|
|
329
|
+
function detectBom(bytes) {
|
|
330
|
+
if (bytes.length >= 3 && bytes[0] === BOM_UTF8 && bytes[1] === 187 && bytes[2] === 191) {
|
|
331
|
+
return "utf-8";
|
|
332
|
+
}
|
|
333
|
+
if (bytes.length >= 2 && bytes[0] === BOM_UTF16LE_FIRST && bytes[1] === BOM_UTF16LE_SECOND) {
|
|
334
|
+
return "utf-16le";
|
|
335
|
+
}
|
|
336
|
+
if (bytes.length >= 2 && bytes[0] === BOM_UTF16BE_FIRST && bytes[1] === BOM_UTF16BE_SECOND) {
|
|
337
|
+
return "utf-16be";
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
function encodeText(value) {
|
|
342
|
+
return encoder.encode(value);
|
|
343
|
+
}
|
|
344
|
+
function decodeText(bytes, options = {}) {
|
|
345
|
+
const bom = detectBom(bytes);
|
|
346
|
+
if (bom === "utf-16le" || bom === "utf-16be") {
|
|
347
|
+
throw new UnsupportedEncodingError(
|
|
348
|
+
`UTF-16 encoded content detected in ${options.source ?? "unknown"}; dotmem persists UTF-8 only. Re-save the file as UTF-8 without BOM.`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
let content = bytes;
|
|
352
|
+
if (bom === "utf-8") {
|
|
353
|
+
content = bytes.subarray(3);
|
|
354
|
+
}
|
|
355
|
+
return strictDecoder.decode(content);
|
|
356
|
+
}
|
|
357
|
+
var encoder, strictDecoder, UnsupportedEncodingError, BOM_UTF8, BOM_UTF16LE_FIRST, BOM_UTF16LE_SECOND, BOM_UTF16BE_FIRST, BOM_UTF16BE_SECOND;
|
|
358
|
+
var init_text_encoding = __esm({
|
|
359
|
+
"core/knowledge/text-encoding.ts"() {
|
|
360
|
+
encoder = new TextEncoder();
|
|
361
|
+
strictDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
362
|
+
UnsupportedEncodingError = class extends Error {
|
|
363
|
+
static {
|
|
364
|
+
__name(this, "UnsupportedEncodingError");
|
|
365
|
+
}
|
|
366
|
+
constructor(message) {
|
|
367
|
+
super(message);
|
|
368
|
+
this.name = "UnsupportedEncodingError";
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
BOM_UTF8 = 239;
|
|
372
|
+
BOM_UTF16LE_FIRST = 255;
|
|
373
|
+
BOM_UTF16LE_SECOND = 254;
|
|
374
|
+
BOM_UTF16BE_FIRST = 254;
|
|
375
|
+
BOM_UTF16BE_SECOND = 255;
|
|
376
|
+
__name(detectBom, "detectBom");
|
|
377
|
+
__name(encodeText, "encodeText");
|
|
378
|
+
__name(decodeText, "decodeText");
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
341
382
|
// core/knowledge/storage-settings.ts
|
|
342
383
|
exports.DOTMEM_STORAGE_SETTINGS_FILE_NAME = void 0; exports.DOTMEM_STORAGE_SETTINGS_VERSION = void 0; var SETTINGS_MODES, projectRoot, findProjectSettingsFile; exports.resolveProjectSettingsFilePath = void 0; exports.discoverProjectSettingsFilePath = void 0; exports.resolveUserSettingsFilePath = void 0; var invalidSettings, parseSettings, resolveSettingsEntry, readTextFile; exports.readStorageSettings = void 0;
|
|
343
384
|
var init_storage_settings = __esm({
|
|
@@ -471,15 +512,19 @@ function readDotMemStorageLocator() {
|
|
|
471
512
|
const locatorFile = resolveLocatorFilePath(anchor);
|
|
472
513
|
let raw;
|
|
473
514
|
try {
|
|
474
|
-
raw = fs7.readFileSync(locatorFile,
|
|
515
|
+
raw = decodeText(fs7.readFileSync(locatorFile), { source: locatorFile });
|
|
475
516
|
} catch (error) {
|
|
517
|
+
if (error instanceof UnsupportedEncodingError) {
|
|
518
|
+
throw new exports.DotMemStorageLocationError(
|
|
519
|
+
`dotmem storage location cannot be resolved: the user locator file at ${locatorFile} is UTF-16 encoded; dotmem persists UTF-8 only. Re-save the locator as UTF-8 without BOM.`
|
|
520
|
+
);
|
|
521
|
+
}
|
|
476
522
|
const code = error?.code;
|
|
477
523
|
if (code === "ENOENT") return null;
|
|
478
524
|
throw new exports.DotMemStorageLocationError(
|
|
479
525
|
`dotmem storage location cannot be resolved: the user locator file at ${locatorFile} cannot be read (${describeAccessFailure(error)}). No alternative location was selected automatically.`
|
|
480
526
|
);
|
|
481
527
|
}
|
|
482
|
-
if (raw.charCodeAt(0) === 65279) raw = raw.slice(1);
|
|
483
528
|
let parsed;
|
|
484
529
|
try {
|
|
485
530
|
parsed = JSON.parse(raw);
|
|
@@ -765,6 +810,7 @@ var DOTMEM_USER_ANCHOR_DIR_NAME, DOTMEM_STORAGE_LOCATOR_FILE_NAME, DOTMEM_STORAG
|
|
|
765
810
|
var init_storage_location = __esm({
|
|
766
811
|
"core/knowledge/storage-location.ts"() {
|
|
767
812
|
init_storage_paths();
|
|
813
|
+
init_text_encoding();
|
|
768
814
|
init_storage_settings();
|
|
769
815
|
init_storage_paths();
|
|
770
816
|
DOTMEM_USER_ANCHOR_DIR_NAME = ".dotmem";
|
|
@@ -1966,6 +2012,12 @@ var init_state = __esm({
|
|
|
1966
2012
|
if (claim.sourceProject !== void 0 && !requiredText(claim.sourceProject)) {
|
|
1967
2013
|
throw new Error(`Claim ${claim.id} has an invalid sourceProject`);
|
|
1968
2014
|
}
|
|
2015
|
+
if (claim.check !== void 0) {
|
|
2016
|
+
const check = claim.check;
|
|
2017
|
+
if (!check || typeof check !== "object" || Array.isArray(check) || check.kind !== "regex" || !requiredText(check.pattern) || !["staged", "committed", "working-tree"].includes(check.on) || check.description !== void 0 && !requiredText(check.description)) {
|
|
2018
|
+
throw new Error(`Claim ${claim.id} has an invalid check`);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
1969
2021
|
return claim;
|
|
1970
2022
|
}, "validateClaim");
|
|
1971
2023
|
validateKnowledgeState = /* @__PURE__ */ __name((value) => {
|
|
@@ -2271,6 +2323,50 @@ var init_scope_eligibility = __esm({
|
|
|
2271
2323
|
}
|
|
2272
2324
|
});
|
|
2273
2325
|
|
|
2326
|
+
// core/knowledge/currentness.ts
|
|
2327
|
+
var asRecord, verifiedAtOf, findContestedIds, deriveCurrentness;
|
|
2328
|
+
var init_currentness = __esm({
|
|
2329
|
+
"core/knowledge/currentness.ts"() {
|
|
2330
|
+
asRecord = /* @__PURE__ */ __name((value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0, "asRecord");
|
|
2331
|
+
verifiedAtOf = /* @__PURE__ */ __name((claim) => {
|
|
2332
|
+
const value = asRecord(claim.knowledge)?.verifiedAt;
|
|
2333
|
+
if (typeof value !== "string") return void 0;
|
|
2334
|
+
const parsed = Date.parse(value);
|
|
2335
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
2336
|
+
}, "verifiedAtOf");
|
|
2337
|
+
findContestedIds = /* @__PURE__ */ __name((claims) => {
|
|
2338
|
+
const retracting = /* @__PURE__ */ new Map();
|
|
2339
|
+
for (const claim of claims) {
|
|
2340
|
+
if (claim.revision?.kind === "retracts" && claim.revision.claimIds.length > 0) {
|
|
2341
|
+
retracting.set(claim.id, new Set(claim.revision.claimIds));
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
const contested = /* @__PURE__ */ new Set();
|
|
2345
|
+
for (const [id, targets] of retracting) {
|
|
2346
|
+
for (const target of targets) {
|
|
2347
|
+
if (retracting.get(target)?.has(id)) {
|
|
2348
|
+
contested.add(id);
|
|
2349
|
+
contested.add(target);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
return contested;
|
|
2354
|
+
}, "findContestedIds");
|
|
2355
|
+
deriveCurrentness = /* @__PURE__ */ __name((claim, context2 = {}) => {
|
|
2356
|
+
const now2 = context2.now ?? Date.now();
|
|
2357
|
+
if (context2.contestedIds?.has(claim.id)) return "contested";
|
|
2358
|
+
if (claim.revision?.kind === "retracts") return "historical";
|
|
2359
|
+
if (context2.retractedIds?.has(claim.id)) return "historical";
|
|
2360
|
+
if (context2.supersededIds?.has(claim.id)) return "superseded";
|
|
2361
|
+
if (claim.expiresAt !== void 0 && now2 >= claim.expiresAt) return "expired";
|
|
2362
|
+
const verifiedAt = verifiedAtOf(claim);
|
|
2363
|
+
if (verifiedAt !== void 0) return "verified";
|
|
2364
|
+
if (claim.epistemicType === "verified") return "unverified";
|
|
2365
|
+
return "unknown-currentness";
|
|
2366
|
+
}, "deriveCurrentness");
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
|
|
2274
2370
|
// core/knowledge/discover.ts
|
|
2275
2371
|
var diagnostic, DEFAULT_LIMITS, FIELD_ORDER, FIELD_WEIGHT, normalize, discoveryTerms, jsonText, fieldText, acquiredTime, isExpired, rankCandidate, discoverAcquiredExperience;
|
|
2276
2372
|
var init_discover = __esm({
|
|
@@ -2278,6 +2374,7 @@ var init_discover = __esm({
|
|
|
2278
2374
|
init_state();
|
|
2279
2375
|
init_applicability();
|
|
2280
2376
|
init_scope_eligibility();
|
|
2377
|
+
init_currentness();
|
|
2281
2378
|
init_env();
|
|
2282
2379
|
diagnostic = /* @__PURE__ */ __name((message) => {
|
|
2283
2380
|
if (typeof process !== "undefined" && typeof process.stderr?.write === "function") {
|
|
@@ -2390,11 +2487,78 @@ var init_discover = __esm({
|
|
|
2390
2487
|
throw new Error("Discovery maxCandidates must be a positive integer");
|
|
2391
2488
|
}
|
|
2392
2489
|
const queryTerms = discoveryTerms(situation);
|
|
2490
|
+
const offset = options.cursor?.offset ?? 0;
|
|
2491
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
2492
|
+
throw new Error("Discovery cursor offset must be a non-negative integer");
|
|
2493
|
+
}
|
|
2494
|
+
if (options.cursor && options.cursor.knowledgeVersion !== validated.version) {
|
|
2495
|
+
return {
|
|
2496
|
+
knowledgeVersion: validated.version,
|
|
2497
|
+
depth,
|
|
2498
|
+
queryTerms,
|
|
2499
|
+
candidates: [],
|
|
2500
|
+
omissions: [],
|
|
2501
|
+
offset: 0,
|
|
2502
|
+
snapshotChanged: true
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2393
2505
|
const available = activeClaims(validated);
|
|
2506
|
+
const availableIds = new Set(available.map((claim) => claim.id));
|
|
2507
|
+
const retractedIds = /* @__PURE__ */ new Set();
|
|
2508
|
+
const supersededIds = /* @__PURE__ */ new Set();
|
|
2509
|
+
const contestedIds = findContestedIds(validated.claims);
|
|
2510
|
+
for (const claim of validated.claims) {
|
|
2511
|
+
if (claim.revision?.kind === "retracts") {
|
|
2512
|
+
for (const id of claim.revision.claimIds) retractedIds.add(id);
|
|
2513
|
+
}
|
|
2514
|
+
if (claim.revision?.kind === "supersedes") {
|
|
2515
|
+
for (const id of claim.revision.claimIds) supersededIds.add(id);
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
const revisionOmissions = validated.claims.filter((claim) => !availableIds.has(claim.id)).map((claim) => {
|
|
2519
|
+
const retracted = retractedIds.has(claim.id);
|
|
2520
|
+
const superseded = supersededIds.has(claim.id);
|
|
2521
|
+
return {
|
|
2522
|
+
id: claim.id,
|
|
2523
|
+
reason: retracted ? "retracted" : superseded ? "superseded" : "retracted",
|
|
2524
|
+
gate: "revision-resolution",
|
|
2525
|
+
...retracted || superseded ? {} : { detail: "the claim itself retracts prior knowledge and is kept as history" }
|
|
2526
|
+
};
|
|
2527
|
+
}).sort((left, right) => left.id.localeCompare(right.id));
|
|
2394
2528
|
const scopeEligible = options.currentProjectId === void 0 ? available : available.filter((claim) => isScopeEligible(claim, options.currentProjectId, sources.get(claim.id)));
|
|
2395
2529
|
const freshEligible = scopeEligible.filter((claim) => !isExpired(claim));
|
|
2530
|
+
const scopeEligibleIds = new Set(scopeEligible.map((claim) => claim.id));
|
|
2531
|
+
const scopeOmissions = available.filter((claim) => !scopeEligibleIds.has(claim.id)).map((claim) => {
|
|
2532
|
+
const owner = claimOwnerProject(claim, sources.get(claim.id));
|
|
2533
|
+
return {
|
|
2534
|
+
id: claim.id,
|
|
2535
|
+
reason: "scope",
|
|
2536
|
+
gate: "scope",
|
|
2537
|
+
detail: owner === void 0 ? "owner project could not be resolved" : `owned by project ${owner}`
|
|
2538
|
+
};
|
|
2539
|
+
}).sort((left, right) => left.id.localeCompare(right.id));
|
|
2540
|
+
const freshIds = new Set(freshEligible.map((claim) => claim.id));
|
|
2541
|
+
const freshnessOmissions = scopeEligible.filter((claim) => !freshIds.has(claim.id)).map((claim) => ({
|
|
2542
|
+
id: claim.id,
|
|
2543
|
+
reason: "expired",
|
|
2544
|
+
gate: "freshness",
|
|
2545
|
+
detail: `expired at ${new Date(claim.expiresAt).toISOString()}`
|
|
2546
|
+
})).sort((left, right) => left.id.localeCompare(right.id));
|
|
2396
2547
|
const situationApplicability = deriveSituationApplicability(situation, options.facts);
|
|
2397
|
-
const
|
|
2548
|
+
const applicabilityMatches = new Map(
|
|
2549
|
+
freshEligible.map((claim) => [claim.id, isEligibleByApplicability(claim, situationApplicability)])
|
|
2550
|
+
);
|
|
2551
|
+
const eligible = freshEligible.map((claim) => ({ claim, match: applicabilityMatches.get(claim.id) })).filter((candidate) => candidate.match.eligible);
|
|
2552
|
+
const applicabilityOmissions = freshEligible.filter((claim) => !applicabilityMatches.get(claim.id).eligible).map((claim) => {
|
|
2553
|
+
const match = applicabilityMatches.get(claim.id);
|
|
2554
|
+
const mismatched = Object.entries(match.dimensions).filter(([, state3]) => state3 === "MISMATCH").map(([dimension]) => dimension);
|
|
2555
|
+
return {
|
|
2556
|
+
id: claim.id,
|
|
2557
|
+
reason: "applicability-mismatch",
|
|
2558
|
+
gate: "applicability",
|
|
2559
|
+
detail: `mismatching dimensions: ${mismatched.length > 0 ? mismatched.join(", ") : "none recorded"}`
|
|
2560
|
+
};
|
|
2561
|
+
}).sort((left, right) => left.id.localeCompare(right.id));
|
|
2398
2562
|
if (DEV) {
|
|
2399
2563
|
diagnostic(
|
|
2400
2564
|
"[dotmem discovery] ACTIVE=" + JSON.stringify(
|
|
@@ -2406,12 +2570,15 @@ var init_discover = __esm({
|
|
|
2406
2570
|
)
|
|
2407
2571
|
);
|
|
2408
2572
|
}
|
|
2573
|
+
const currentnessOf = /* @__PURE__ */ __name((claim) => deriveCurrentness(claim, { retractedIds, supersededIds, contestedIds }), "currentnessOf");
|
|
2409
2574
|
if (queryTerms.length === 0) {
|
|
2410
|
-
const
|
|
2575
|
+
const baselineAll = eligible.filter((candidate) => candidate.claim.applicability?.baseline === true).map((candidate) => candidate.claim).sort((left, right) => {
|
|
2411
2576
|
const leftTime = acquiredTime(left);
|
|
2412
2577
|
const rightTime = acquiredTime(right);
|
|
2413
2578
|
return rightTime - leftTime || Number(right.scope === "project") - Number(left.scope === "project") || left.id.localeCompare(right.id);
|
|
2414
|
-
})
|
|
2579
|
+
});
|
|
2580
|
+
const baseline = baselineAll.slice(offset, offset + maxCandidates);
|
|
2581
|
+
const limitOmissions = baselineAll.slice(offset + maxCandidates).map((claim) => ({ id: claim.id, reason: "limit", gate: "ranking" })).sort((left, right) => left.id.localeCompare(right.id));
|
|
2415
2582
|
const baselineCandidates = baseline.map((claim) => {
|
|
2416
2583
|
const explanation = {
|
|
2417
2584
|
matchedTerms: [],
|
|
@@ -2424,7 +2591,8 @@ var init_discover = __esm({
|
|
|
2424
2591
|
}
|
|
2425
2592
|
return {
|
|
2426
2593
|
claim,
|
|
2427
|
-
explanation
|
|
2594
|
+
explanation,
|
|
2595
|
+
currentness: currentnessOf(claim)
|
|
2428
2596
|
};
|
|
2429
2597
|
});
|
|
2430
2598
|
if (DEV) {
|
|
@@ -2437,10 +2605,18 @@ var init_discover = __esm({
|
|
|
2437
2605
|
depth,
|
|
2438
2606
|
queryTerms,
|
|
2439
2607
|
situationApplicability,
|
|
2440
|
-
candidates: baselineCandidates
|
|
2608
|
+
candidates: baselineCandidates,
|
|
2609
|
+
offset,
|
|
2610
|
+
omissions: [
|
|
2611
|
+
...revisionOmissions,
|
|
2612
|
+
...scopeOmissions,
|
|
2613
|
+
...freshnessOmissions,
|
|
2614
|
+
...applicabilityOmissions,
|
|
2615
|
+
...limitOmissions
|
|
2616
|
+
]
|
|
2441
2617
|
};
|
|
2442
2618
|
}
|
|
2443
|
-
const
|
|
2619
|
+
const ranked = eligible.map(
|
|
2444
2620
|
(candidate) => rankCandidate(
|
|
2445
2621
|
candidate.claim,
|
|
2446
2622
|
situation,
|
|
@@ -2452,16 +2628,40 @@ var init_discover = __esm({
|
|
|
2452
2628
|
(candidate) => candidate !== null
|
|
2453
2629
|
).sort(
|
|
2454
2630
|
(left, right) => Number(right.directPhrase) - Number(left.directPhrase) || right.matchedTermCount - left.matchedTermCount || right.fieldWeight - left.fieldWeight || Number(right.claim.scope === "project") - Number(left.claim.scope === "project") || right.acquiredTime - left.acquiredTime || left.claim.id.localeCompare(right.claim.id)
|
|
2455
|
-
)
|
|
2631
|
+
);
|
|
2632
|
+
const rankedIds = new Set(ranked.map((candidate) => candidate.claim.id));
|
|
2633
|
+
const rankingOmissions = [
|
|
2634
|
+
...eligible.filter((candidate) => !rankedIds.has(candidate.claim.id)).map((candidate) => ({
|
|
2635
|
+
id: candidate.claim.id,
|
|
2636
|
+
reason: "no-term-match",
|
|
2637
|
+
gate: "ranking",
|
|
2638
|
+
detail: "passed every gate but shares no query term"
|
|
2639
|
+
})),
|
|
2640
|
+
...ranked.slice(offset + maxCandidates).map((candidate) => ({
|
|
2641
|
+
id: candidate.claim.id,
|
|
2642
|
+
reason: "limit",
|
|
2643
|
+
gate: "ranking"
|
|
2644
|
+
}))
|
|
2645
|
+
].sort((left, right) => left.id.localeCompare(right.id));
|
|
2646
|
+
const candidates = ranked.slice(offset, offset + maxCandidates).map(({ claim, explanation }) => ({
|
|
2456
2647
|
claim,
|
|
2457
|
-
explanation
|
|
2648
|
+
explanation,
|
|
2649
|
+
currentness: currentnessOf(claim)
|
|
2458
2650
|
}));
|
|
2459
2651
|
return {
|
|
2460
2652
|
knowledgeVersion: validated.version,
|
|
2461
2653
|
depth,
|
|
2462
2654
|
queryTerms,
|
|
2463
2655
|
situationApplicability,
|
|
2464
|
-
candidates
|
|
2656
|
+
candidates,
|
|
2657
|
+
offset,
|
|
2658
|
+
omissions: [
|
|
2659
|
+
...revisionOmissions,
|
|
2660
|
+
...scopeOmissions,
|
|
2661
|
+
...freshnessOmissions,
|
|
2662
|
+
...applicabilityOmissions,
|
|
2663
|
+
...rankingOmissions
|
|
2664
|
+
]
|
|
2465
2665
|
};
|
|
2466
2666
|
}, "discoverAcquiredExperience");
|
|
2467
2667
|
}
|
|
@@ -3518,7 +3718,7 @@ var init_policy_store = __esm({
|
|
|
3518
3718
|
});
|
|
3519
3719
|
|
|
3520
3720
|
// core/knowledge/acquisition-limits.ts
|
|
3521
|
-
var MEMORY_ACQUIRE_LIMITS, MEMORY_ACQUIRE_LIMITS_MCP, MEMORY_STORE_LIMITS, DOTMEM_ACQUIRE_ERROR_CODES, MemoryAcquireLimitError, MemoryAcquireConcurrencyError, MemoryAcquireDuplicateClaimError,
|
|
3721
|
+
var MEMORY_ACQUIRE_LIMITS, MEMORY_ACQUIRE_LIMITS_MCP, MEMORY_STORE_LIMITS, DOTMEM_ACQUIRE_ERROR_CODES, MemoryAcquireLimitError, MemoryAcquireConcurrencyError, MemoryAcquireDuplicateClaimError, encoder2, serializedBytes, measureKnowledge, checkAcquireLimits;
|
|
3522
3722
|
var init_acquisition_limits = __esm({
|
|
3523
3723
|
"core/knowledge/acquisition-limits.ts"() {
|
|
3524
3724
|
MEMORY_ACQUIRE_LIMITS = Object.freeze({
|
|
@@ -3577,10 +3777,10 @@ var init_acquisition_limits = __esm({
|
|
|
3577
3777
|
this.name = "MemoryAcquireDuplicateClaimError";
|
|
3578
3778
|
}
|
|
3579
3779
|
};
|
|
3580
|
-
|
|
3780
|
+
encoder2 = new TextEncoder();
|
|
3581
3781
|
serializedBytes = /* @__PURE__ */ __name((value) => {
|
|
3582
3782
|
const json = JSON.stringify(value);
|
|
3583
|
-
return json === void 0 ? 0 :
|
|
3783
|
+
return json === void 0 ? 0 : encoder2.encode(json).length;
|
|
3584
3784
|
}, "serializedBytes");
|
|
3585
3785
|
measureKnowledge = /* @__PURE__ */ __name((knowledge) => {
|
|
3586
3786
|
const claimBytes = serializedBytes(knowledge);
|
|
@@ -3675,7 +3875,7 @@ var init_context_constants = __esm({
|
|
|
3675
3875
|
});
|
|
3676
3876
|
|
|
3677
3877
|
// core/knowledge/project.ts
|
|
3678
|
-
var FORMAT, STATUS, NOTICE, DEFAULT_MAX_CANDIDATES, DEFAULT_MAX_CHARACTERS, MIN_MAX_CHARACTERS, projectCandidate, GIST_MAX_LENGTH, GIST_KEYS, deriveIndexTopic, deriveIndexStatus, deriveGist, renderHeader, renderExperience, renderText, projectDiscoveredExperience, renderContextIndex, renderSizeDisclosure, renderProfileDocuments;
|
|
3878
|
+
var FORMAT, STATUS, NOTICE, DEFAULT_MAX_CANDIDATES, DEFAULT_MAX_CHARACTERS, MIN_MAX_CHARACTERS, projectCandidate, GIST_MAX_LENGTH, GIST_KEYS, MANIFEST_ID_LIMIT, deriveIndexTopic, deriveIndexStatus, deriveGist, renderHeader, renderExperience, renderText, byteLength, summarizeOmissions, renderManifestFitting, renderCompactExperience, projectDiscoveredExperience, renderContextIndex, renderExpandedClaim, renderSizeDisclosure, renderProfileDocuments;
|
|
3679
3879
|
var init_project = __esm({
|
|
3680
3880
|
"core/knowledge/project.ts"() {
|
|
3681
3881
|
init_state();
|
|
@@ -3700,11 +3900,13 @@ var init_project = __esm({
|
|
|
3700
3900
|
...claim.provenance ? { provenance: claim.provenance } : {},
|
|
3701
3901
|
...claim.acquiredAt ? { acquiredAt: claim.acquiredAt } : {},
|
|
3702
3902
|
...claim.revision ? { revision: claim.revision } : {},
|
|
3703
|
-
...candidate.explanation.sourceId ? { sourceId: candidate.explanation.sourceId } : {}
|
|
3903
|
+
...candidate.explanation.sourceId ? { sourceId: candidate.explanation.sourceId } : {},
|
|
3904
|
+
...candidate.currentness ? { currentness: candidate.currentness } : {}
|
|
3704
3905
|
});
|
|
3705
3906
|
}, "projectCandidate");
|
|
3706
3907
|
GIST_MAX_LENGTH = 80;
|
|
3707
3908
|
GIST_KEYS = ["gist", "summary", "statement", "title", "reason", "principle", "finding", "detail"];
|
|
3909
|
+
MANIFEST_ID_LIMIT = 40;
|
|
3708
3910
|
deriveIndexTopic = /* @__PURE__ */ __name((applicability) => {
|
|
3709
3911
|
const topic = applicability.topic;
|
|
3710
3912
|
if (typeof topic === "string" && topic.length > 0) return topic;
|
|
@@ -3754,27 +3956,70 @@ var init_project = __esm({
|
|
|
3754
3956
|
evidence.supports ?? null
|
|
3755
3957
|
]),
|
|
3756
3958
|
...experience.epistemicType ? { epistemic: experience.epistemicType } : {},
|
|
3959
|
+
...experience.currentness ? { currentness: experience.currentness } : {},
|
|
3757
3960
|
...experience.provenance ? { provenance: [experience.provenance.source, experience.provenance.detail ?? null] } : {},
|
|
3758
3961
|
...experience.acquiredAt ? { acquiredAt: experience.acquiredAt } : {},
|
|
3759
3962
|
...experience.revision ? { revision: experience.revision } : {},
|
|
3760
3963
|
...experience.sourceId ? { source: experience.sourceId } : {}
|
|
3761
3964
|
}), "renderExperience");
|
|
3762
|
-
renderText = /* @__PURE__ */ __name((header, experiences, omittedCandidates) =>
|
|
3763
|
-
|
|
3764
|
-
|
|
3965
|
+
renderText = /* @__PURE__ */ __name((header, experiences, omittedCandidates, manifest, render = renderExperience, currentnessSummary) => {
|
|
3966
|
+
const lines = [header];
|
|
3967
|
+
if (experiences.length > 0) lines.push(...experiences.map(render));
|
|
3968
|
+
lines.push(`OMITTED:${omittedCandidates}`);
|
|
3969
|
+
if (manifest && manifest.byReason.length > 0) {
|
|
3970
|
+
lines.push(`OMITTED_BY_REASON:${manifest.byReason.map((entry) => `${entry.reason}=${entry.count}`).join(",")}`);
|
|
3971
|
+
}
|
|
3972
|
+
if (manifest && manifest.items.length > 0) {
|
|
3973
|
+
lines.push(`OMITTED_IDS:${manifest.items.slice(0, MANIFEST_ID_LIMIT).map((item) => item.id).join(",")}`);
|
|
3974
|
+
if (manifest.items.length > MANIFEST_ID_LIMIT) {
|
|
3975
|
+
lines.push(`OMITTED_IDS_TRUNCATED:${manifest.items.length - MANIFEST_ID_LIMIT}`);
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
if (currentnessSummary) {
|
|
3979
|
+
lines.push(`CURRENTNESS:${currentnessSummary}`);
|
|
3980
|
+
}
|
|
3981
|
+
return lines.join("\n");
|
|
3982
|
+
}, "renderText");
|
|
3983
|
+
byteLength = /* @__PURE__ */ __name((value) => new TextEncoder().encode(value).length, "byteLength");
|
|
3984
|
+
summarizeOmissions = /* @__PURE__ */ __name((items) => {
|
|
3985
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3986
|
+
for (const item of items) counts.set(item.reason, (counts.get(item.reason) ?? 0) + 1);
|
|
3987
|
+
return [...counts.entries()].map(([reason, count]) => ({ reason, count })).sort((left, right) => left.reason.localeCompare(right.reason));
|
|
3988
|
+
}, "summarizeOmissions");
|
|
3989
|
+
renderManifestFitting = /* @__PURE__ */ __name((header, experiences, omittedCandidates, manifest, maxCharacters, render, currentnessSummary) => {
|
|
3990
|
+
const full = renderText(header, experiences, omittedCandidates, manifest, render, currentnessSummary);
|
|
3991
|
+
if (byteLength(full) <= maxCharacters) return full;
|
|
3992
|
+
const withoutIds = { ...manifest, items: [] };
|
|
3993
|
+
return renderText(header, experiences, omittedCandidates, withoutIds, render, currentnessSummary);
|
|
3994
|
+
}, "renderManifestFitting");
|
|
3995
|
+
renderCompactExperience = /* @__PURE__ */ __name((experience) => JSON.stringify({
|
|
3996
|
+
id: experience.id,
|
|
3997
|
+
status: "candidate",
|
|
3998
|
+
gist: deriveGist(experience.experience),
|
|
3999
|
+
epistemic: experience.epistemicType ?? null,
|
|
4000
|
+
currentness: experience.currentness ?? null,
|
|
4001
|
+
...experience.revision ? { revision: experience.revision.kind } : {}
|
|
4002
|
+
}), "renderCompactExperience");
|
|
3765
4003
|
projectDiscoveredExperience = /* @__PURE__ */ __name((discovery, options = {}) => {
|
|
3766
4004
|
if (!discovery || !Number.isInteger(discovery.knowledgeVersion) || discovery.knowledgeVersion < 0 || !Array.isArray(discovery.candidates)) {
|
|
3767
4005
|
throw new Error("Valid DiscoveryResult is required for context projection");
|
|
3768
4006
|
}
|
|
3769
4007
|
const maxCandidates = options.maxCandidates ?? DEFAULT_MAX_CANDIDATES;
|
|
3770
4008
|
const maxCharacters = options.maxCharacters ?? DEFAULT_MAX_CHARACTERS;
|
|
4009
|
+
const format = options.format ?? "compact";
|
|
4010
|
+
if (format !== "compact" && format !== "standard" && format !== "full") {
|
|
4011
|
+
throw new Error("Projection format must be compact, standard or full");
|
|
4012
|
+
}
|
|
3771
4013
|
if (!Number.isInteger(maxCandidates) || maxCandidates < 1) throw new Error("Projection maxCandidates must be a positive integer");
|
|
3772
4014
|
if (!Number.isInteger(maxCharacters) || maxCharacters < MIN_MAX_CHARACTERS) {
|
|
3773
4015
|
throw new Error(`Projection maxCharacters must be an integer of at least ${MIN_MAX_CHARACTERS}`);
|
|
3774
4016
|
}
|
|
3775
|
-
const
|
|
4017
|
+
const render = /* @__PURE__ */ __name((experience) => format === "compact" ? renderCompactExperience(experience) : renderExperience(experience), "render");
|
|
4018
|
+
const gateOmissions = discovery.omissions ?? [];
|
|
4019
|
+
const totalCandidates = discovery.candidates.length + gateOmissions.length;
|
|
3776
4020
|
const header = renderHeader(discovery.knowledgeVersion, totalCandidates);
|
|
3777
|
-
|
|
4021
|
+
const emptyManifest = { considered: totalCandidates, included: 0, items: [], byReason: [] };
|
|
4022
|
+
if (byteLength(renderText(header, [], totalCandidates, emptyManifest)) > maxCharacters) {
|
|
3778
4023
|
throw new Error("Projection maxCharacters is too small for the projection envelope");
|
|
3779
4024
|
}
|
|
3780
4025
|
const experiences = [];
|
|
@@ -3783,12 +4028,49 @@ OMITTED:${omittedCandidates}`, "renderText");
|
|
|
3783
4028
|
const projected = projectCandidate(candidate);
|
|
3784
4029
|
const possibleExperiences = [...experiences, projected];
|
|
3785
4030
|
const possibleOmitted = totalCandidates - possibleExperiences.length;
|
|
3786
|
-
|
|
4031
|
+
const candidateManifest = {
|
|
4032
|
+
considered: totalCandidates,
|
|
4033
|
+
included: possibleExperiences.length,
|
|
4034
|
+
items: gateOmissions,
|
|
4035
|
+
byReason: summarizeOmissions(gateOmissions)
|
|
4036
|
+
};
|
|
4037
|
+
if (byteLength(renderText(header, possibleExperiences, possibleOmitted, candidateManifest, render)) <= maxCharacters) {
|
|
4038
|
+
experiences.push(projected);
|
|
4039
|
+
continue;
|
|
4040
|
+
}
|
|
4041
|
+
if (byteLength(renderText(header, possibleExperiences, possibleOmitted, void 0, render)) <= maxCharacters) {
|
|
3787
4042
|
experiences.push(projected);
|
|
3788
4043
|
}
|
|
3789
4044
|
}
|
|
4045
|
+
const projectedIds = new Set(experiences.map((experience) => experience.id));
|
|
4046
|
+
const budgetOmissions = discovery.candidates.filter((candidate) => !projectedIds.has(candidate.claim.id)).map((candidate) => ({ id: candidate.claim.id, reason: "budget", gate: "projection" }));
|
|
4047
|
+
const items = [...gateOmissions, ...budgetOmissions];
|
|
3790
4048
|
const omittedCandidates = totalCandidates - experiences.length;
|
|
3791
|
-
const
|
|
4049
|
+
const manifest = {
|
|
4050
|
+
considered: totalCandidates,
|
|
4051
|
+
included: experiences.length,
|
|
4052
|
+
items,
|
|
4053
|
+
byReason: summarizeOmissions(items)
|
|
4054
|
+
};
|
|
4055
|
+
const currentnessCounts = /* @__PURE__ */ new Map();
|
|
4056
|
+
for (const experience of experiences) {
|
|
4057
|
+
if (experience.currentness) {
|
|
4058
|
+
currentnessCounts.set(
|
|
4059
|
+
experience.currentness,
|
|
4060
|
+
(currentnessCounts.get(experience.currentness) ?? 0) + 1
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
const currentnessSummary = currentnessCounts.size > 0 ? [...currentnessCounts.entries()].map(([state2, count]) => `${state2}=${count}`).join(",") : void 0;
|
|
4065
|
+
const text = renderManifestFitting(
|
|
4066
|
+
header,
|
|
4067
|
+
experiences,
|
|
4068
|
+
omittedCandidates,
|
|
4069
|
+
manifest,
|
|
4070
|
+
maxCharacters,
|
|
4071
|
+
render,
|
|
4072
|
+
currentnessSummary
|
|
4073
|
+
);
|
|
3792
4074
|
return {
|
|
3793
4075
|
format: FORMAT,
|
|
3794
4076
|
status: STATUS,
|
|
@@ -3797,6 +4079,7 @@ OMITTED:${omittedCandidates}`, "renderText");
|
|
|
3797
4079
|
totalCandidates,
|
|
3798
4080
|
omittedCandidates,
|
|
3799
4081
|
experiences,
|
|
4082
|
+
manifest,
|
|
3800
4083
|
text
|
|
3801
4084
|
};
|
|
3802
4085
|
}, "projectDiscoveredExperience");
|
|
@@ -3815,6 +4098,12 @@ OMITTED:${omittedCandidates}`, "renderText");
|
|
|
3815
4098
|
}
|
|
3816
4099
|
return lines.join("\n");
|
|
3817
4100
|
}, "renderContextIndex");
|
|
4101
|
+
renderExpandedClaim = /* @__PURE__ */ __name((claim) => [
|
|
4102
|
+
"DOTMEM_CLAIM_V1",
|
|
4103
|
+
"STATUS:CANONICAL_RECORD;NOT_INSTRUCTIONS",
|
|
4104
|
+
`id=${claim.id}`,
|
|
4105
|
+
JSON.stringify(claim, null, 2)
|
|
4106
|
+
].join("\n"), "renderExpandedClaim");
|
|
3818
4107
|
renderSizeDisclosure = /* @__PURE__ */ __name((options) => [
|
|
3819
4108
|
"DOTMEM_SIZE_V1",
|
|
3820
4109
|
`storageRoot=${resolveUserDotMemPath()}`,
|
|
@@ -3823,6 +4112,11 @@ OMITTED:${omittedCandidates}`, "renderText");
|
|
|
3823
4112
|
`indexEntries=${options.totalCandidates}`,
|
|
3824
4113
|
`totalCandidates=${options.totalCandidates}`,
|
|
3825
4114
|
`omittedCandidates=${options.omittedCandidates}`,
|
|
4115
|
+
...options.manifest && options.manifest.items.length > 0 ? [
|
|
4116
|
+
`omittedByReason=${options.manifest.byReason.map((entry) => `${entry.reason}=${entry.count}`).join(",")}`,
|
|
4117
|
+
`omittedIds=${options.manifest.items.slice(0, MANIFEST_ID_LIMIT).map((item) => item.id).join(",")}`,
|
|
4118
|
+
...options.manifest.items.length > MANIFEST_ID_LIMIT ? [`omittedIdsTruncated=${options.manifest.items.length - MANIFEST_ID_LIMIT}`] : []
|
|
4119
|
+
] : [],
|
|
3826
4120
|
`maxCharacters=${Number.isFinite(options.maxCharacters) ? String(options.maxCharacters) : "unlimited"}`,
|
|
3827
4121
|
'fullTextCommand=npx dotmem context "<situation>" --full',
|
|
3828
4122
|
"DOTMEM_SIZE_END"
|
|
@@ -4006,7 +4300,7 @@ var init_language_detect = __esm({
|
|
|
4006
4300
|
var CANONICAL_KINDS, validateKind, buildClaimRecord;
|
|
4007
4301
|
var init_claim_record = __esm({
|
|
4008
4302
|
"core/knowledge/claim-record.ts"() {
|
|
4009
|
-
CANONICAL_KINDS = ["experience", "logic", "agent", "relationship", "note"];
|
|
4303
|
+
CANONICAL_KINDS = ["experience", "logic", "agent", "relationship", "note", "rule"];
|
|
4010
4304
|
validateKind = /* @__PURE__ */ __name((kind) => {
|
|
4011
4305
|
if (!CANONICAL_KINDS.includes(kind)) {
|
|
4012
4306
|
throw new Error(
|
|
@@ -5412,8 +5706,8 @@ var init_browser = __esm({
|
|
|
5412
5706
|
this.p = null;
|
|
5413
5707
|
}
|
|
5414
5708
|
};
|
|
5415
|
-
Unzip2.prototype.register = function(
|
|
5416
|
-
this.o[
|
|
5709
|
+
Unzip2.prototype.register = function(decoder) {
|
|
5710
|
+
this.o[decoder.compression] = decoder;
|
|
5417
5711
|
};
|
|
5418
5712
|
return Unzip2;
|
|
5419
5713
|
})();
|
|
@@ -5433,6 +5727,15 @@ function encodeMemFile(stateValue, preserved) {
|
|
|
5433
5727
|
if (!map.claim.includes("kind")) {
|
|
5434
5728
|
map.claim.push("kind");
|
|
5435
5729
|
}
|
|
5730
|
+
if (!map.claim.includes("expires-at")) {
|
|
5731
|
+
map.claim.push("expires-at");
|
|
5732
|
+
}
|
|
5733
|
+
if (!map.claim.includes("bootstrap-priority")) {
|
|
5734
|
+
map.claim.push("bootstrap-priority");
|
|
5735
|
+
}
|
|
5736
|
+
if (!map.claim.includes("check")) {
|
|
5737
|
+
map.claim.push("check");
|
|
5738
|
+
}
|
|
5436
5739
|
const indexes = Object.fromEntries(Object.keys(expectedFields).map((name) => [name, fieldIndexes(map, name)]));
|
|
5437
5740
|
validateVocabulary(map.epistemicType, epistemicTypes, "epistemicType");
|
|
5438
5741
|
validateVocabulary(map.revisionKind, revisionKinds, "revisionKind");
|
|
@@ -5482,6 +5785,15 @@ function encodeMemFile(stateValue, preserved) {
|
|
|
5482
5785
|
if (indexes.claim.has("kind")) {
|
|
5483
5786
|
putOptional(record, indexes.claim, "kind", claim.kind ?? void 0, original !== void 0);
|
|
5484
5787
|
}
|
|
5788
|
+
if (indexes.claim.has("expires-at")) {
|
|
5789
|
+
putOptional(record, indexes.claim, "expires-at", claim.expiresAt, original !== void 0);
|
|
5790
|
+
}
|
|
5791
|
+
if (indexes.claim.has("bootstrap-priority")) {
|
|
5792
|
+
putOptional(record, indexes.claim, "bootstrap-priority", claim.bootstrapPriority, original !== void 0);
|
|
5793
|
+
}
|
|
5794
|
+
if (indexes.claim.has("check")) {
|
|
5795
|
+
putOptional(record, indexes.claim, "check", claim.check, original !== void 0);
|
|
5796
|
+
}
|
|
5485
5797
|
return original ? record : trimRecord(record);
|
|
5486
5798
|
}, "encodeClaim");
|
|
5487
5799
|
const stateRecord = structuredClone(preserved?.data ?? []);
|
|
@@ -5550,8 +5862,37 @@ function decodeMemDocument(value) {
|
|
|
5550
5862
|
const scope = optionalGet(record, indexes.claim, "scope");
|
|
5551
5863
|
const sourceProject = optionalGet(record, indexes.claim, "source-project");
|
|
5552
5864
|
const kindValue = optionalGet(record, indexes.claim, "kind");
|
|
5865
|
+
const expiresAtValue = indexes.claim.has("expires-at") ? optionalGet(record, indexes.claim, "expires-at") : void 0;
|
|
5866
|
+
const bootstrapPriorityValue = indexes.claim.has("bootstrap-priority") ? optionalGet(record, indexes.claim, "bootstrap-priority") : void 0;
|
|
5867
|
+
const checkValue = indexes.claim.has("check") ? optionalGet(record, indexes.claim, "check") : void 0;
|
|
5553
5868
|
if (epistemicIndex !== void 0 && (!Number.isInteger(epistemicIndex) || epistemicIndex < 0 || epistemicIndex >= epistemic.length)) throw new Error("Invalid .mem epistemic value");
|
|
5554
5869
|
if (kindIndex !== void 0 && (!Number.isInteger(kindIndex) || kindIndex < 0 || kindIndex >= revisions.length)) throw new Error("Invalid .mem revision value");
|
|
5870
|
+
if (expiresAtValue !== void 0 && (!Number.isInteger(expiresAtValue) || expiresAtValue < 0)) {
|
|
5871
|
+
throw new Error("Invalid .mem expiresAt value");
|
|
5872
|
+
}
|
|
5873
|
+
if (bootstrapPriorityValue !== void 0 && !bootstrapPriorities.includes(bootstrapPriorityValue)) {
|
|
5874
|
+
throw new Error("Invalid .mem bootstrapPriority value");
|
|
5875
|
+
}
|
|
5876
|
+
let check;
|
|
5877
|
+
if (checkValue !== void 0) {
|
|
5878
|
+
if (!checkValue || typeof checkValue !== "object" || Array.isArray(checkValue)) {
|
|
5879
|
+
throw new Error("Invalid .mem check record");
|
|
5880
|
+
}
|
|
5881
|
+
const checkRecord = checkValue;
|
|
5882
|
+
const description = checkRecord.description;
|
|
5883
|
+
if (typeof description !== "undefined" && typeof description !== "string") {
|
|
5884
|
+
throw new Error("Invalid .mem check record");
|
|
5885
|
+
}
|
|
5886
|
+
if (checkRecord.kind !== "regex" || typeof checkRecord.pattern !== "string" || checkRecord.pattern.length === 0 || !checkTargets.includes(checkRecord.on)) {
|
|
5887
|
+
throw new Error("Invalid .mem check record");
|
|
5888
|
+
}
|
|
5889
|
+
check = {
|
|
5890
|
+
kind: "regex",
|
|
5891
|
+
pattern: checkRecord.pattern,
|
|
5892
|
+
on: checkRecord.on,
|
|
5893
|
+
...typeof description === "string" ? { description } : {}
|
|
5894
|
+
};
|
|
5895
|
+
}
|
|
5555
5896
|
const understoodEpistemic = typeof epistemicIndex === "number" && epistemicTypes.includes(epistemic[epistemicIndex]) ? epistemic[epistemicIndex] : void 0;
|
|
5556
5897
|
const understoodRevision = typeof kindIndex === "number" && revisionKinds.includes(revisions[kindIndex]);
|
|
5557
5898
|
const claim = {
|
|
@@ -5576,6 +5917,9 @@ function decodeMemDocument(value) {
|
|
|
5576
5917
|
} : {},
|
|
5577
5918
|
...scope === void 0 ? {} : { scope },
|
|
5578
5919
|
...sourceProject === void 0 ? {} : { sourceProject },
|
|
5920
|
+
...expiresAtValue === void 0 ? {} : { expiresAt: expiresAtValue },
|
|
5921
|
+
...bootstrapPriorityValue === void 0 ? {} : { bootstrapPriority: bootstrapPriorityValue },
|
|
5922
|
+
...check === void 0 ? {} : { check },
|
|
5579
5923
|
...claimKinds.includes(kindValue) ? { kind: kindValue } : {}
|
|
5580
5924
|
};
|
|
5581
5925
|
return validateClaim(claim);
|
|
@@ -5585,7 +5929,7 @@ function decodeMemDocument(value) {
|
|
|
5585
5929
|
preserved: { map: structuredClone(map), data: structuredClone(stateRecord) }
|
|
5586
5930
|
};
|
|
5587
5931
|
}
|
|
5588
|
-
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;
|
|
5932
|
+
var MEM_FORMAT, MEM_FORMAT_LEGACY, MEM_FORMAT_VERSION, MEM_FORMAT_VERSION_V1, expectedFields, epistemicTypes, revisionKinds, claimKinds, bootstrapPriorities, checkTargets, isJsonValue2, createMemInterpretationMap, validateSourceState, trimRecord, fieldIndexes, validateVocabulary, put, get, optionalGet, requireRecord, putOptional;
|
|
5589
5933
|
var init_mem_codec = __esm({
|
|
5590
5934
|
"core/knowledge/mem-codec.ts"() {
|
|
5591
5935
|
init_state();
|
|
@@ -5602,7 +5946,9 @@ var init_mem_codec = __esm({
|
|
|
5602
5946
|
};
|
|
5603
5947
|
epistemicTypes = ["observed", "inferred", "human-stated", "verified"];
|
|
5604
5948
|
revisionKinds = ["refines", "supersedes", "retracts"];
|
|
5605
|
-
claimKinds = ["experience", "agent", "relationship", "logic", "note"];
|
|
5949
|
+
claimKinds = ["experience", "agent", "relationship", "logic", "note", "rule"];
|
|
5950
|
+
bootstrapPriorities = ["P1", "P2", "P3", "P4", "P5", "unclassified"];
|
|
5951
|
+
checkTargets = ["staged", "committed", "working-tree"];
|
|
5606
5952
|
isJsonValue2 = /* @__PURE__ */ __name((value) => {
|
|
5607
5953
|
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
5608
5954
|
if (typeof value === "number") return Number.isFinite(value);
|
|
@@ -5706,14 +6052,14 @@ async function signMemPackage(input, privateKey, publicKey) {
|
|
|
5706
6052
|
});
|
|
5707
6053
|
}
|
|
5708
6054
|
async function decodeMemArtifact(input) {
|
|
5709
|
-
const bytes = typeof input === "string" ?
|
|
6055
|
+
const bytes = typeof input === "string" ? encoder3.encode(input) : input;
|
|
5710
6056
|
if (isZip(bytes)) {
|
|
5711
6057
|
const { parts: _parts, integrity: _integrity, ...artifact } = await decodePackage(bytes);
|
|
5712
6058
|
return artifact;
|
|
5713
6059
|
}
|
|
5714
6060
|
let value;
|
|
5715
6061
|
try {
|
|
5716
|
-
value = JSON.parse(
|
|
6062
|
+
value = JSON.parse(decodeText(bytes));
|
|
5717
6063
|
} catch (error) {
|
|
5718
6064
|
throw new MemArtifactError("corrupt", `Unsupported or corrupt MEM artifact: ${error.message}`);
|
|
5719
6065
|
}
|
|
@@ -5728,7 +6074,7 @@ async function decodeMemArtifact(input) {
|
|
|
5728
6074
|
}
|
|
5729
6075
|
async function inspectMem(input) {
|
|
5730
6076
|
try {
|
|
5731
|
-
const bytes = typeof input === "string" ?
|
|
6077
|
+
const bytes = typeof input === "string" ? encodeText(input) : input;
|
|
5732
6078
|
if (isZip(bytes)) {
|
|
5733
6079
|
const artifact2 = await decodePackage(bytes);
|
|
5734
6080
|
const knownMapKeys = /* @__PURE__ */ new Set(["state", "claim", "evidence", "provenance", "revision", "epistemicType", "revisionKind"]);
|
|
@@ -5769,11 +6115,12 @@ async function inspectMem(input) {
|
|
|
5769
6115
|
return { status: artifactError.code, representation: "unknown", message: artifactError.message, parts: [] };
|
|
5770
6116
|
}
|
|
5771
6117
|
}
|
|
5772
|
-
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,
|
|
6118
|
+
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, encoder3, MemArtifactError, stableValue, jsonBytes, sha256, parseJson, validEntryPath, concatenate, readZipParts, createManifest, digestTableIdentity, signaturePayload, base64UrlEncode, base64UrlDecode, keyIdentity, signaturePath, encodePackage, isZip, decodePackage, verifySignature;
|
|
5773
6119
|
var init_mem_package = __esm({
|
|
5774
6120
|
"core/knowledge/mem-package.ts"() {
|
|
5775
6121
|
init_browser();
|
|
5776
6122
|
init_mem_codec();
|
|
6123
|
+
init_text_encoding();
|
|
5777
6124
|
MEM_PACKAGE_FORMAT = "dotmem.package";
|
|
5778
6125
|
MEM_PACKAGE_FORMAT_LEGACY = "memorio.package";
|
|
5779
6126
|
MEM_PACKAGE_VERSION = 1;
|
|
@@ -5797,8 +6144,7 @@ var init_mem_package = __esm({
|
|
|
5797
6144
|
DATA_PATH = "memory/data.json";
|
|
5798
6145
|
INTEGRITY_PATH = "security/integrity.json";
|
|
5799
6146
|
requiredParts = [MANIFEST_PATH, MAP_PATH, DATA_PATH];
|
|
5800
|
-
|
|
5801
|
-
decoder = new TextDecoder("utf-8", { fatal: true });
|
|
6147
|
+
encoder3 = new TextEncoder();
|
|
5802
6148
|
MemArtifactError = class extends Error {
|
|
5803
6149
|
constructor(code, message) {
|
|
5804
6150
|
super(message);
|
|
@@ -5817,7 +6163,7 @@ var init_mem_package = __esm({
|
|
|
5817
6163
|
}
|
|
5818
6164
|
return value;
|
|
5819
6165
|
}, "stableValue");
|
|
5820
|
-
jsonBytes = /* @__PURE__ */ __name((value) =>
|
|
6166
|
+
jsonBytes = /* @__PURE__ */ __name((value) => encoder3.encode(`${JSON.stringify(stableValue(value), null, 2)}
|
|
5821
6167
|
`), "jsonBytes");
|
|
5822
6168
|
sha256 = /* @__PURE__ */ __name(async (data) => {
|
|
5823
6169
|
if (!globalThis.crypto?.subtle) throw new MemArtifactError("unsupported", "SHA-256 is unavailable in this runtime");
|
|
@@ -5826,7 +6172,7 @@ var init_mem_package = __esm({
|
|
|
5826
6172
|
}, "sha256");
|
|
5827
6173
|
parseJson = /* @__PURE__ */ __name((bytes, path5) => {
|
|
5828
6174
|
try {
|
|
5829
|
-
return JSON.parse(
|
|
6175
|
+
return JSON.parse(decodeText(bytes));
|
|
5830
6176
|
} catch (error) {
|
|
5831
6177
|
throw new MemArtifactError("invalid", `Invalid UTF-8 JSON in ${path5}: ${error.message}`);
|
|
5832
6178
|
}
|
|
@@ -5892,7 +6238,7 @@ var init_mem_package = __esm({
|
|
|
5892
6238
|
parts: { map: MAP_PATH, data: DATA_PATH, integrity: INTEGRITY_PATH }
|
|
5893
6239
|
}), "createManifest");
|
|
5894
6240
|
digestTableIdentity = /* @__PURE__ */ __name((files) => sha256(jsonBytes(files)), "digestTableIdentity");
|
|
5895
|
-
signaturePayload = /* @__PURE__ */ __name((contentId) =>
|
|
6241
|
+
signaturePayload = /* @__PURE__ */ __name((contentId) => encoder3.encode(`DOTMEM-PACKAGE-SIGNATURE-V1
|
|
5896
6242
|
${contentId}
|
|
5897
6243
|
`), "signaturePayload");
|
|
5898
6244
|
base64UrlEncode = /* @__PURE__ */ __name((value) => {
|
|
@@ -6082,10 +6428,12 @@ ${contentId}
|
|
|
6082
6428
|
});
|
|
6083
6429
|
|
|
6084
6430
|
// core/storage-coordinator/index.ts
|
|
6085
|
-
var nodeFs4, withStorageLock, readStorageGeneration, writeStorageGeneration;
|
|
6431
|
+
var nodeFs4, heldLocks, withStorageLock, readStorageGeneration, writeStorageGeneration;
|
|
6086
6432
|
var init_storage_coordinator = __esm({
|
|
6087
6433
|
"core/storage-coordinator/index.ts"() {
|
|
6434
|
+
init_text_encoding();
|
|
6088
6435
|
nodeFs4 = /* @__PURE__ */ __name(async () => import('fs/promises'), "nodeFs");
|
|
6436
|
+
heldLocks = /* @__PURE__ */ new Map();
|
|
6089
6437
|
withStorageLock = /* @__PURE__ */ __name(async (directoryPath, operationOrOptions, operation, _options = {}) => {
|
|
6090
6438
|
const opts = typeof operationOrOptions === "function" ? operation ?? {} : operationOrOptions ?? {};
|
|
6091
6439
|
const op = typeof operationOrOptions === "function" ? operationOrOptions : operation;
|
|
@@ -6095,6 +6443,15 @@ var init_storage_coordinator = __esm({
|
|
|
6095
6443
|
const lockPath = `${directoryPath}/${lockName}`;
|
|
6096
6444
|
const fs7 = await nodeFs4();
|
|
6097
6445
|
const started = Date.now();
|
|
6446
|
+
const heldDepth = heldLocks.get(lockPath) ?? 0;
|
|
6447
|
+
if (heldDepth > 0) {
|
|
6448
|
+
heldLocks.set(lockPath, heldDepth + 1);
|
|
6449
|
+
try {
|
|
6450
|
+
return await op();
|
|
6451
|
+
} finally {
|
|
6452
|
+
heldLocks.set(lockPath, heldDepth);
|
|
6453
|
+
}
|
|
6454
|
+
}
|
|
6098
6455
|
await fs7.mkdir(directoryPath, { recursive: true });
|
|
6099
6456
|
while (true) {
|
|
6100
6457
|
try {
|
|
@@ -6108,8 +6465,8 @@ var init_storage_coordinator = __esm({
|
|
|
6108
6465
|
let stale = false;
|
|
6109
6466
|
let processDead = false;
|
|
6110
6467
|
try {
|
|
6111
|
-
const raw = await fs7.readFile(`${lockPath}/owner.json
|
|
6112
|
-
const parsed = JSON.parse(raw);
|
|
6468
|
+
const raw = await fs7.readFile(`${lockPath}/owner.json`);
|
|
6469
|
+
const parsed = JSON.parse(decodeText(raw, { source: `${lockPath}/owner.json` }));
|
|
6113
6470
|
const ageStale = typeof parsed.createdAt === "number" && Date.now() - parsed.createdAt > staleMs;
|
|
6114
6471
|
if (typeof parsed.pid === "number") {
|
|
6115
6472
|
try {
|
|
@@ -6146,17 +6503,19 @@ var init_storage_coordinator = __esm({
|
|
|
6146
6503
|
}
|
|
6147
6504
|
let token = "";
|
|
6148
6505
|
try {
|
|
6149
|
-
const raw = await fs7.readFile(`${lockPath}/owner.json
|
|
6150
|
-
token = JSON.parse(raw).token ?? "";
|
|
6506
|
+
const raw = await fs7.readFile(`${lockPath}/owner.json`);
|
|
6507
|
+
token = JSON.parse(decodeText(raw, { source: `${lockPath}/owner.json` })).token ?? "";
|
|
6151
6508
|
} catch {
|
|
6152
6509
|
token = "";
|
|
6153
6510
|
}
|
|
6154
6511
|
try {
|
|
6512
|
+
heldLocks.set(lockPath, 1);
|
|
6155
6513
|
return await op();
|
|
6156
6514
|
} finally {
|
|
6515
|
+
heldLocks.delete(lockPath);
|
|
6157
6516
|
try {
|
|
6158
|
-
const raw = await fs7.readFile(`${lockPath}/owner.json
|
|
6159
|
-
const parsed = JSON.parse(raw);
|
|
6517
|
+
const raw = await fs7.readFile(`${lockPath}/owner.json`);
|
|
6518
|
+
const parsed = JSON.parse(decodeText(raw, { source: `${lockPath}/owner.json` }));
|
|
6160
6519
|
if (parsed.token === token && token) {
|
|
6161
6520
|
await fs7.rm(lockPath, { recursive: true, force: true });
|
|
6162
6521
|
}
|
|
@@ -6167,8 +6526,8 @@ var init_storage_coordinator = __esm({
|
|
|
6167
6526
|
readStorageGeneration = /* @__PURE__ */ __name(async (directoryPath) => {
|
|
6168
6527
|
const fs7 = await nodeFs4();
|
|
6169
6528
|
try {
|
|
6170
|
-
const raw = await fs7.readFile(`${directoryPath}/.storage.generation
|
|
6171
|
-
const value = Number(raw.trim());
|
|
6529
|
+
const raw = await fs7.readFile(`${directoryPath}/.storage.generation`);
|
|
6530
|
+
const value = Number(decodeText(raw, { source: `${directoryPath}/.storage.generation` }).trim());
|
|
6172
6531
|
return Number.isFinite(value) && value >= 0 ? value : 0;
|
|
6173
6532
|
} catch {
|
|
6174
6533
|
return 0;
|
|
@@ -6697,12 +7056,11 @@ function readJsonFile(path5) {
|
|
|
6697
7056
|
if (!fs7) return null;
|
|
6698
7057
|
let raw;
|
|
6699
7058
|
try {
|
|
6700
|
-
raw = fs7.readFileSync(path5,
|
|
7059
|
+
raw = decodeText(fs7.readFileSync(path5), { source: path5 });
|
|
6701
7060
|
} catch {
|
|
6702
7061
|
return null;
|
|
6703
7062
|
}
|
|
6704
7063
|
if (typeof raw !== "string") return null;
|
|
6705
|
-
if (raw.charCodeAt(0) === 65279) raw = raw.slice(1);
|
|
6706
7064
|
try {
|
|
6707
7065
|
return JSON.parse(raw);
|
|
6708
7066
|
} catch {
|
|
@@ -6826,6 +7184,7 @@ var init_user_language = __esm({
|
|
|
6826
7184
|
"core/knowledge/user-language.ts"() {
|
|
6827
7185
|
init_user_paths();
|
|
6828
7186
|
init_storage_paths();
|
|
7187
|
+
init_text_encoding();
|
|
6829
7188
|
USER_LANGUAGE_FILE_NAME = "language.json";
|
|
6830
7189
|
USER_LANGUAGE_PREFERENCE_FILE_NAME = "user-language.json";
|
|
6831
7190
|
LANGUAGE_PREFERENCE_FILE_NAME = "language-preference.json";
|
|
@@ -10981,10 +11340,13 @@ var init_staging = __esm({
|
|
|
10981
11340
|
epistemicType: sanitizedClaim.epistemicType,
|
|
10982
11341
|
provenance: sanitizedClaim.provenance,
|
|
10983
11342
|
acquiredAt: sanitizedClaim.acquiredAt,
|
|
11343
|
+
...sanitizedClaim.expiresAt === void 0 ? {} : { expiresAt: sanitizedClaim.expiresAt },
|
|
11344
|
+
...sanitizedClaim.bootstrapPriority === void 0 ? {} : { bootstrapPriority: sanitizedClaim.bootstrapPriority },
|
|
10984
11345
|
revision,
|
|
10985
11346
|
scope,
|
|
10986
11347
|
sourceProject,
|
|
10987
|
-
kind
|
|
11348
|
+
kind,
|
|
11349
|
+
...sanitizedClaim.check === void 0 ? {} : { check: sanitizedClaim.check }
|
|
10988
11350
|
});
|
|
10989
11351
|
await withStoreQueue(acquisitionStoreKey(kind, scope, sourceProject), async () => {
|
|
10990
11352
|
const state2 = await target.runtime.select([]);
|
|
@@ -12278,87 +12640,6 @@ var init_incidents = __esm({
|
|
|
12278
12640
|
}
|
|
12279
12641
|
});
|
|
12280
12642
|
|
|
12281
|
-
// core/knowledge/rules-loader.ts
|
|
12282
|
-
function isRuleClaim(claim) {
|
|
12283
|
-
const knowledge = claim.knowledge;
|
|
12284
|
-
return knowledge?.kind === "rule";
|
|
12285
|
-
}
|
|
12286
|
-
function isIronRule(claim) {
|
|
12287
|
-
return claim.epistemicType === "human-stated" && isRuleClaim(claim);
|
|
12288
|
-
}
|
|
12289
|
-
function extractIronRules(state2) {
|
|
12290
|
-
const validated = validateKnowledgeState(state2);
|
|
12291
|
-
const claims = activeClaims(validated);
|
|
12292
|
-
const rules = [];
|
|
12293
|
-
for (const claim of claims) {
|
|
12294
|
-
if (!isIronRule(claim)) continue;
|
|
12295
|
-
const knowledge = claim.knowledge;
|
|
12296
|
-
const applicability = claim.applicability;
|
|
12297
|
-
const iron = applicability.iron === true || applicability.priority === "iron";
|
|
12298
|
-
if (!iron) continue;
|
|
12299
|
-
rules.push({
|
|
12300
|
-
id: claim.id,
|
|
12301
|
-
text: String(knowledge.text ?? knowledge.rule ?? claim.id),
|
|
12302
|
-
why: String(knowledge.why ?? knowledge.reason ?? ""),
|
|
12303
|
-
appliesWhen: String(knowledge.appliesWhen ?? knowledge.when ?? ""),
|
|
12304
|
-
violatedOn: Array.isArray(knowledge.violatedOn) ? knowledge.violatedOn : void 0,
|
|
12305
|
-
lastViolation: typeof knowledge.lastViolation === "string" ? knowledge.lastViolation : void 0,
|
|
12306
|
-
frequency: typeof knowledge.frequency === "number" ? knowledge.frequency : 0
|
|
12307
|
-
});
|
|
12308
|
-
}
|
|
12309
|
-
return rules;
|
|
12310
|
-
}
|
|
12311
|
-
function sortRulesByViolationFrequency(rules) {
|
|
12312
|
-
return [...rules].sort((a, b) => {
|
|
12313
|
-
if (b.frequency !== a.frequency) return b.frequency - a.frequency;
|
|
12314
|
-
if (a.lastViolation && b.lastViolation) {
|
|
12315
|
-
return b.lastViolation.localeCompare(a.lastViolation);
|
|
12316
|
-
}
|
|
12317
|
-
return 0;
|
|
12318
|
-
});
|
|
12319
|
-
}
|
|
12320
|
-
function loadIronRules(state2) {
|
|
12321
|
-
const rules = sortRulesByViolationFrequency(extractIronRules(state2));
|
|
12322
|
-
return {
|
|
12323
|
-
rules,
|
|
12324
|
-
count: rules.length,
|
|
12325
|
-
sortedBy: "violation-frequency"
|
|
12326
|
-
};
|
|
12327
|
-
}
|
|
12328
|
-
function formatRulesForSessionStart(rules) {
|
|
12329
|
-
if (rules.length === 0) {
|
|
12330
|
-
return "";
|
|
12331
|
-
}
|
|
12332
|
-
const lines = ["---", "IRON RULES (must always arrive)", "---"];
|
|
12333
|
-
for (const rule of rules) {
|
|
12334
|
-
lines.push(`${rule.id}: ${rule.text}`);
|
|
12335
|
-
}
|
|
12336
|
-
return lines.join("\n");
|
|
12337
|
-
}
|
|
12338
|
-
function formatRuleWithExplanation(rule) {
|
|
12339
|
-
const parts = [];
|
|
12340
|
-
parts.push(`[${rule.id}] ${rule.text}`);
|
|
12341
|
-
if (rule.why) parts.push(` WHY: ${rule.why}`);
|
|
12342
|
-
if (rule.appliesWhen) parts.push(` APPLIES WHEN: ${rule.appliesWhen}`);
|
|
12343
|
-
if (rule.violatedOn && rule.violatedOn.length > 0) {
|
|
12344
|
-
parts.push(` VIOLATED ${rule.violatedOn.length} TIME(S)`);
|
|
12345
|
-
if (rule.lastViolation) parts.push(` Last: ${rule.lastViolation}`);
|
|
12346
|
-
}
|
|
12347
|
-
return parts.join("\n");
|
|
12348
|
-
}
|
|
12349
|
-
var init_rules_loader = __esm({
|
|
12350
|
-
"core/knowledge/rules-loader.ts"() {
|
|
12351
|
-
init_state();
|
|
12352
|
-
__name(isRuleClaim, "isRuleClaim");
|
|
12353
|
-
__name(isIronRule, "isIronRule");
|
|
12354
|
-
__name(extractIronRules, "extractIronRules");
|
|
12355
|
-
__name(sortRulesByViolationFrequency, "sortRulesByViolationFrequency");
|
|
12356
|
-
__name(loadIronRules, "loadIronRules");
|
|
12357
|
-
__name(formatRulesForSessionStart, "formatRulesForSessionStart");
|
|
12358
|
-
__name(formatRuleWithExplanation, "formatRuleWithExplanation");
|
|
12359
|
-
}
|
|
12360
|
-
});
|
|
12361
|
-
|
|
12362
12643
|
// core/knowledge/violations.ts
|
|
12363
12644
|
function joinPath8(base, child) {
|
|
12364
12645
|
const separator3 = process.platform === "win32" ? "\\" : "/";
|
|
@@ -12454,6 +12735,122 @@ var init_violations = __esm({
|
|
|
12454
12735
|
__name(clearViolations, "clearViolations");
|
|
12455
12736
|
}
|
|
12456
12737
|
});
|
|
12738
|
+
function isRuleClaim(claim) {
|
|
12739
|
+
const knowledge = claim.knowledge;
|
|
12740
|
+
return knowledge?.kind === "rule";
|
|
12741
|
+
}
|
|
12742
|
+
function isIronRule(claim) {
|
|
12743
|
+
return claim.epistemicType === "human-stated" && isRuleClaim(claim);
|
|
12744
|
+
}
|
|
12745
|
+
function extractIronRules(state2, violations = {}) {
|
|
12746
|
+
const validated = validateKnowledgeState(state2);
|
|
12747
|
+
const claims = activeClaims(validated);
|
|
12748
|
+
const rules = [];
|
|
12749
|
+
for (const claim of claims) {
|
|
12750
|
+
if (!isIronRule(claim)) continue;
|
|
12751
|
+
const knowledge = claim.knowledge;
|
|
12752
|
+
const applicability = claim.applicability;
|
|
12753
|
+
const iron = applicability.iron === true || applicability.priority === "iron";
|
|
12754
|
+
if (!iron) continue;
|
|
12755
|
+
rules.push({
|
|
12756
|
+
id: claim.id,
|
|
12757
|
+
text: String(knowledge.text ?? knowledge.rule ?? claim.id),
|
|
12758
|
+
why: String(knowledge.why ?? knowledge.reason ?? ""),
|
|
12759
|
+
appliesWhen: String(knowledge.appliesWhen ?? knowledge.when ?? ""),
|
|
12760
|
+
violatedOn: Array.isArray(knowledge.violatedOn) ? knowledge.violatedOn : void 0,
|
|
12761
|
+
lastViolation: typeof knowledge.lastViolation === "string" ? knowledge.lastViolation : void 0,
|
|
12762
|
+
frequency: typeof knowledge.frequency === "number" ? knowledge.frequency : violations[claim.id] ?? 0
|
|
12763
|
+
});
|
|
12764
|
+
}
|
|
12765
|
+
return rules;
|
|
12766
|
+
}
|
|
12767
|
+
function sortRulesByViolationFrequency(rules) {
|
|
12768
|
+
return [...rules].sort((a, b) => {
|
|
12769
|
+
if (b.frequency !== a.frequency) return b.frequency - a.frequency;
|
|
12770
|
+
if (a.lastViolation && b.lastViolation) {
|
|
12771
|
+
return b.lastViolation.localeCompare(a.lastViolation);
|
|
12772
|
+
}
|
|
12773
|
+
return 0;
|
|
12774
|
+
});
|
|
12775
|
+
}
|
|
12776
|
+
function loadIronRules(state2) {
|
|
12777
|
+
const rules = sortRulesByViolationFrequency(
|
|
12778
|
+
extractIronRules(state2, readViolationCounts(`${resolveUserDotMemPath()}/${VIOLATION_FILE_NAME}`))
|
|
12779
|
+
);
|
|
12780
|
+
return {
|
|
12781
|
+
rules,
|
|
12782
|
+
count: rules.length,
|
|
12783
|
+
sortedBy: "violation-frequency"
|
|
12784
|
+
};
|
|
12785
|
+
}
|
|
12786
|
+
function formatRulesForSessionStart(rules) {
|
|
12787
|
+
if (rules.length === 0) {
|
|
12788
|
+
return "";
|
|
12789
|
+
}
|
|
12790
|
+
const lines = ["---", "IRON RULES (must always arrive)", "---"];
|
|
12791
|
+
for (const rule of rules) {
|
|
12792
|
+
lines.push(`${rule.id}: ${rule.text}`);
|
|
12793
|
+
}
|
|
12794
|
+
return lines.join("\n");
|
|
12795
|
+
}
|
|
12796
|
+
function formatRuleWithExplanation(rule) {
|
|
12797
|
+
const parts = [];
|
|
12798
|
+
parts.push(`[${rule.id}] ${rule.text}`);
|
|
12799
|
+
if (rule.why) parts.push(` WHY: ${rule.why}`);
|
|
12800
|
+
if (rule.appliesWhen) parts.push(` APPLIES WHEN: ${rule.appliesWhen}`);
|
|
12801
|
+
if (rule.violatedOn && rule.violatedOn.length > 0) {
|
|
12802
|
+
parts.push(` VIOLATED ${rule.violatedOn.length} TIME(S)`);
|
|
12803
|
+
if (rule.lastViolation) parts.push(` Last: ${rule.lastViolation}`);
|
|
12804
|
+
}
|
|
12805
|
+
return parts.join("\n");
|
|
12806
|
+
}
|
|
12807
|
+
var readViolationCounts, ruleSetSignature, formatRulesReference;
|
|
12808
|
+
var init_rules_loader = __esm({
|
|
12809
|
+
"core/knowledge/rules-loader.ts"() {
|
|
12810
|
+
init_state();
|
|
12811
|
+
init_user_paths();
|
|
12812
|
+
init_violations();
|
|
12813
|
+
__name(isRuleClaim, "isRuleClaim");
|
|
12814
|
+
__name(isIronRule, "isIronRule");
|
|
12815
|
+
__name(extractIronRules, "extractIronRules");
|
|
12816
|
+
readViolationCounts = /* @__PURE__ */ __name((file) => {
|
|
12817
|
+
try {
|
|
12818
|
+
const parsed = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
12819
|
+
const counts = {};
|
|
12820
|
+
for (const violation of Array.isArray(parsed.violations) ? parsed.violations : []) {
|
|
12821
|
+
const ruleId = typeof violation?.ruleId === "string" ? violation.ruleId : "";
|
|
12822
|
+
if (!ruleId) continue;
|
|
12823
|
+
counts[ruleId] = (counts[ruleId] ?? 0) + 1;
|
|
12824
|
+
}
|
|
12825
|
+
return counts;
|
|
12826
|
+
} catch {
|
|
12827
|
+
return {};
|
|
12828
|
+
}
|
|
12829
|
+
}, "readViolationCounts");
|
|
12830
|
+
__name(sortRulesByViolationFrequency, "sortRulesByViolationFrequency");
|
|
12831
|
+
__name(loadIronRules, "loadIronRules");
|
|
12832
|
+
ruleSetSignature = /* @__PURE__ */ __name((rules) => {
|
|
12833
|
+
const material = rules.map((rule) => `${rule.id}\0${rule.text}`).join("");
|
|
12834
|
+
let hash = 2166136261;
|
|
12835
|
+
for (let index = 0; index < material.length; index += 1) {
|
|
12836
|
+
hash ^= material.charCodeAt(index);
|
|
12837
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
12838
|
+
}
|
|
12839
|
+
return hash.toString(16).padStart(8, "0");
|
|
12840
|
+
}, "ruleSetSignature");
|
|
12841
|
+
formatRulesReference = /* @__PURE__ */ __name((rules) => {
|
|
12842
|
+
if (rules.length === 0) return "DOTMEM_IRON_RULES_V1\ncount=0";
|
|
12843
|
+
return [
|
|
12844
|
+
"DOTMEM_IRON_RULES_V1",
|
|
12845
|
+
`count=${rules.length}`,
|
|
12846
|
+
`signature=${ruleSetSignature(rules)}`,
|
|
12847
|
+
`ids=${rules.map((rule) => rule.id).join(",")}`
|
|
12848
|
+
].join("\n");
|
|
12849
|
+
}, "formatRulesReference");
|
|
12850
|
+
__name(formatRulesForSessionStart, "formatRulesForSessionStart");
|
|
12851
|
+
__name(formatRuleWithExplanation, "formatRuleWithExplanation");
|
|
12852
|
+
}
|
|
12853
|
+
});
|
|
12457
12854
|
|
|
12458
12855
|
// core/knowledge/session.ts
|
|
12459
12856
|
function joinPath9(base, child) {
|
|
@@ -13149,8 +13546,8 @@ function loadBuiltInContext() {
|
|
|
13149
13546
|
for (const candidate of candidates) {
|
|
13150
13547
|
if (!fs2__default.default.existsSync(candidate)) continue;
|
|
13151
13548
|
try {
|
|
13152
|
-
const raw = fs2__default.default.readFileSync(candidate
|
|
13153
|
-
const parsed = JSON.parse(raw);
|
|
13549
|
+
const raw = fs2__default.default.readFileSync(candidate);
|
|
13550
|
+
const parsed = JSON.parse(decodeText(raw, { source: candidate }));
|
|
13154
13551
|
const artifact = validateArtifact(parsed);
|
|
13155
13552
|
cached = artifact;
|
|
13156
13553
|
cachedStatus = {
|
|
@@ -13233,6 +13630,7 @@ function resetBuiltInContextCache() {
|
|
|
13233
13630
|
var BUILT_IN_CONTEXT_FORMAT, BUILT_IN_CONTEXT_FORMAT_VERSION, cached, cachedStatus, _artifactPathOverride;
|
|
13234
13631
|
var init_built_in_context = __esm({
|
|
13235
13632
|
"core/knowledge/built-in-context.ts"() {
|
|
13633
|
+
init_text_encoding();
|
|
13236
13634
|
BUILT_IN_CONTEXT_FORMAT = "dotmem.built-in-context";
|
|
13237
13635
|
BUILT_IN_CONTEXT_FORMAT_VERSION = 1;
|
|
13238
13636
|
cached = null;
|
|
@@ -13432,6 +13830,7 @@ __export(knowledge_exports, {
|
|
|
13432
13830
|
defaultIdentityGovernance: () => defaultIdentityGovernance,
|
|
13433
13831
|
defaultOverrideId: () => defaultOverrideId,
|
|
13434
13832
|
defaultPolicyId: () => defaultPolicyId,
|
|
13833
|
+
deriveCurrentness: () => deriveCurrentness,
|
|
13435
13834
|
deriveSituationApplicability: () => deriveSituationApplicability,
|
|
13436
13835
|
describeDotMemStorage: () => describeDotMemStorage,
|
|
13437
13836
|
detectAuthorityEscalationAttempt: () => detectAuthorityEscalationAttempt,
|
|
@@ -13458,6 +13857,7 @@ __export(knowledge_exports, {
|
|
|
13458
13857
|
explainDiscovery: () => explainDiscovery,
|
|
13459
13858
|
explainIdentityResolution: () => explainIdentityResolution,
|
|
13460
13859
|
extractIronRules: () => extractIronRules,
|
|
13860
|
+
findContestedIds: () => findContestedIds,
|
|
13461
13861
|
findExemplar: () => findExemplar,
|
|
13462
13862
|
findIncidentById: () => findIncidentById,
|
|
13463
13863
|
fingerprintFromState: () => fingerprintFromState,
|
|
@@ -13533,6 +13933,7 @@ __export(knowledge_exports, {
|
|
|
13533
13933
|
relocateDotMemStorage: () => relocateDotMemStorage,
|
|
13534
13934
|
removeExemplar: () => removeExemplar,
|
|
13535
13935
|
renderAgentRules: () => renderAgentRules,
|
|
13936
|
+
renderExpandedClaim: () => renderExpandedClaim,
|
|
13536
13937
|
renderExplanation: () => renderExplanation,
|
|
13537
13938
|
renderMarkdownIndex: () => renderMarkdownIndex,
|
|
13538
13939
|
renderOperatorContract: () => renderOperatorContract,
|
|
@@ -13636,6 +14037,7 @@ var init_knowledge = __esm({
|
|
|
13636
14037
|
init_state();
|
|
13637
14038
|
init_select();
|
|
13638
14039
|
init_discover();
|
|
14040
|
+
init_currentness();
|
|
13639
14041
|
init_project();
|
|
13640
14042
|
init_applicability();
|
|
13641
14043
|
init_policy();
|
|
@@ -13743,7 +14145,6 @@ function _inferConfidence(claim) {
|
|
|
13743
14145
|
var LOGIC_MEM_FILE, nodeCwd2, cachedRuntime, LogicEngine, logic, logic_default;
|
|
13744
14146
|
var init_logic = __esm({
|
|
13745
14147
|
"core/logic/index.ts"() {
|
|
13746
|
-
init_suppress_idb_warning();
|
|
13747
14148
|
init_knowledge();
|
|
13748
14149
|
init_mem_repository();
|
|
13749
14150
|
init_acquisition_boundary();
|
|
@@ -14131,7 +14532,6 @@ async function loadCombinedKnowledgeState() {
|
|
|
14131
14532
|
var EmptyLogicRepository, KNOWLEDGE_STATE_KEY, knowledgeSaveQueue, StoreKnowledgeRepository, RuntimeSlot, projectSlot, userSlot, installDotMemReadme;
|
|
14132
14533
|
var init_knowledge_runtime = __esm({
|
|
14133
14534
|
"core/memory/knowledge-runtime.ts"() {
|
|
14134
|
-
init_suppress_idb_warning();
|
|
14135
14535
|
init_knowledge();
|
|
14136
14536
|
init_project_identity();
|
|
14137
14537
|
init_user_paths();
|
|
@@ -14512,6 +14912,7 @@ var init_durable_store = __esm({
|
|
|
14512
14912
|
"core/memory/durable-store.ts"() {
|
|
14513
14913
|
init_storage_coordinator();
|
|
14514
14914
|
init_store_queue();
|
|
14915
|
+
init_text_encoding();
|
|
14515
14916
|
DurableStorageUnavailableError = class extends Error {
|
|
14516
14917
|
static {
|
|
14517
14918
|
__name(this, "DurableStorageUnavailableError");
|
|
@@ -14566,11 +14967,11 @@ var init_durable_store = __esm({
|
|
|
14566
14967
|
}
|
|
14567
14968
|
let parsed;
|
|
14568
14969
|
try {
|
|
14569
|
-
parsed = JSON.parse(
|
|
14970
|
+
parsed = JSON.parse(decodeText(raw, { source: this.filePath }));
|
|
14570
14971
|
} catch {
|
|
14571
14972
|
try {
|
|
14572
14973
|
const bakRaw = await fs7.readFile(`${this.filePath}.bak`);
|
|
14573
|
-
parsed = JSON.parse(
|
|
14974
|
+
parsed = JSON.parse(decodeText(bakRaw, { source: `${this.filePath}.bak` }));
|
|
14574
14975
|
} catch {
|
|
14575
14976
|
throw new DurableStorageUnavailableError(
|
|
14576
14977
|
"Durable memory store is corrupt and no backup is available."
|
|
@@ -14987,7 +15388,6 @@ async function getEntry(key) {
|
|
|
14987
15388
|
var MEMORY_INDEX_KEY, SUPERSEDED_PREFIX, durableStoreInstance, entries;
|
|
14988
15389
|
var init_entries = __esm({
|
|
14989
15390
|
"core/memory/entries.ts"() {
|
|
14990
|
-
init_suppress_idb_warning();
|
|
14991
15391
|
init_env();
|
|
14992
15392
|
init_journal();
|
|
14993
15393
|
init_durable_store();
|
|
@@ -15365,7 +15765,6 @@ async function findClaimAcrossAllSources(claimId, scope, sourceProject) {
|
|
|
15365
15765
|
var acquire;
|
|
15366
15766
|
var init_acquire = __esm({
|
|
15367
15767
|
"core/memory/acquire.ts"() {
|
|
15368
|
-
init_suppress_idb_warning();
|
|
15369
15768
|
init_env();
|
|
15370
15769
|
init_built_in_context();
|
|
15371
15770
|
init_project_identity();
|
|
@@ -15486,15 +15885,15 @@ var init_profile2 = __esm({
|
|
|
15486
15885
|
|
|
15487
15886
|
// core/knowledge/note-types.ts
|
|
15488
15887
|
async function sha256HexOfText(text) {
|
|
15489
|
-
const
|
|
15490
|
-
const bytes =
|
|
15888
|
+
const encoder4 = new TextEncoder();
|
|
15889
|
+
const bytes = encoder4.encode(text);
|
|
15491
15890
|
const hashArray = await crypto.subtle.digest("SHA-256", bytes);
|
|
15492
15891
|
return Array.from(new Uint8Array(hashArray)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
15493
15892
|
}
|
|
15494
15893
|
async function buildNoteKnowledge(title, content, origin, tag) {
|
|
15495
15894
|
const sha2563 = await sha256HexOfText(content);
|
|
15496
|
-
const
|
|
15497
|
-
const size =
|
|
15895
|
+
const encoder4 = new TextEncoder();
|
|
15896
|
+
const size = encoder4.encode(content).byteLength;
|
|
15498
15897
|
return {
|
|
15499
15898
|
title,
|
|
15500
15899
|
content,
|
|
@@ -16972,7 +17371,6 @@ async function bootstrapProject() {
|
|
|
16972
17371
|
var pendingDetectionEvents, detectionFlushScheduled, flushDetectionEvents; exports.memory = void 0;
|
|
16973
17372
|
var init_memory = __esm({
|
|
16974
17373
|
"core/memory/index.ts"() {
|
|
16975
|
-
init_suppress_idb_warning();
|
|
16976
17374
|
init_journal();
|
|
16977
17375
|
init_brain();
|
|
16978
17376
|
init_knowledge_runtime();
|
|
@@ -17096,7 +17494,7 @@ var init_memory = __esm({
|
|
|
17096
17494
|
resetPolicyStoreCache();
|
|
17097
17495
|
},
|
|
17098
17496
|
// ----- namespaced surfaces -----
|
|
17099
|
-
/** Local operation journal (namespaced).
|
|
17497
|
+
/** Local operation journal (namespaced). Persisted on `store`. */
|
|
17100
17498
|
journal: journal_default,
|
|
17101
17499
|
/** Configure the optional cloud-sync layer (namespace + provider). Chainable. */
|
|
17102
17500
|
configure(opts) {
|
|
@@ -17231,7 +17629,7 @@ function readStdin() {
|
|
|
17231
17629
|
});
|
|
17232
17630
|
}
|
|
17233
17631
|
function parseContextArgs(args) {
|
|
17234
|
-
const options = { explain: false, json: false, full: false, claimsOnly: false };
|
|
17632
|
+
const options = { explain: false, json: false, full: false, claimsOnly: false, manifest: false };
|
|
17235
17633
|
const positional = [];
|
|
17236
17634
|
let i2 = 0;
|
|
17237
17635
|
while (i2 < args.length) {
|
|
@@ -17240,7 +17638,16 @@ function parseContextArgs(args) {
|
|
|
17240
17638
|
else if (arg === "--json") options.json = true;
|
|
17241
17639
|
else if (arg === "--full") options.full = true;
|
|
17242
17640
|
else if (arg === "--claims-only") options.claimsOnly = true;
|
|
17243
|
-
else if (arg === "--
|
|
17641
|
+
else if (arg === "--manifest") options.manifest = true;
|
|
17642
|
+
else if (arg === "--claim") {
|
|
17643
|
+
i2++;
|
|
17644
|
+
const value = args[i2];
|
|
17645
|
+
if (!value) {
|
|
17646
|
+
console.error("Missing value for --claim");
|
|
17647
|
+
process14__default.default.exit(1);
|
|
17648
|
+
}
|
|
17649
|
+
options.claimId = value;
|
|
17650
|
+
} else if (arg === "--limit") {
|
|
17244
17651
|
const value = args[i2 + 1];
|
|
17245
17652
|
if (value === void 0 || value.startsWith("--")) {
|
|
17246
17653
|
console.error("Missing value for --limit");
|
|
@@ -17255,6 +17662,21 @@ function parseContextArgs(args) {
|
|
|
17255
17662
|
}
|
|
17256
17663
|
options.limit = parsed;
|
|
17257
17664
|
i2++;
|
|
17665
|
+
} else if (arg === "--offset") {
|
|
17666
|
+
const value = args[i2 + 1];
|
|
17667
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
17668
|
+
console.error("Missing value for --offset");
|
|
17669
|
+
process14__default.default.exitCode = 1;
|
|
17670
|
+
process14__default.default.exit(1);
|
|
17671
|
+
}
|
|
17672
|
+
const parsed = parseInt(value, 10);
|
|
17673
|
+
if (Number.isNaN(parsed) || parsed < 0) {
|
|
17674
|
+
console.error(`Invalid --offset value: ${value}. Must be a non-negative integer.`);
|
|
17675
|
+
process14__default.default.exitCode = 1;
|
|
17676
|
+
process14__default.default.exit(1);
|
|
17677
|
+
}
|
|
17678
|
+
options.offset = parsed;
|
|
17679
|
+
i2++;
|
|
17258
17680
|
} else if (arg === "--format") {
|
|
17259
17681
|
const value = args[i2 + 1];
|
|
17260
17682
|
if (value === void 0 || value.startsWith("--")) {
|
|
@@ -17272,7 +17694,7 @@ function parseContextArgs(args) {
|
|
|
17272
17694
|
i2++;
|
|
17273
17695
|
} else if (arg.startsWith("--")) {
|
|
17274
17696
|
console.error(`Unknown context option: ${arg}`);
|
|
17275
|
-
console.error('Usage: npx dotmem context "<situation>" [--explain] [--json] [--full] [--claims-only] [--limit <N>] [--format brief]');
|
|
17697
|
+
console.error('Usage: npx dotmem context "<situation>" [--explain] [--json] [--full] [--claims-only] [--limit <N>] [--offset <N>] [--format brief] [--manifest] [--claim <id>]');
|
|
17276
17698
|
process14__default.default.exit(1);
|
|
17277
17699
|
} else positional.push(arg);
|
|
17278
17700
|
i2++;
|
|
@@ -17887,7 +18309,6 @@ var init_policy3 = __esm({
|
|
|
17887
18309
|
});
|
|
17888
18310
|
|
|
17889
18311
|
// core/cli/index.ts
|
|
17890
|
-
init_suppress_idb_warning();
|
|
17891
18312
|
init_memory();
|
|
17892
18313
|
|
|
17893
18314
|
// core/continuity/freshness.ts
|
|
@@ -19498,7 +19919,8 @@ async function runContext(situation, _cwd, options = {}) {
|
|
|
19498
19919
|
await getBrainDocument();
|
|
19499
19920
|
const discovery = discoverAcquiredExperience(combined, situation, {
|
|
19500
19921
|
currentProjectId: await resolveProjectIdentity(process.cwd()),
|
|
19501
|
-
...options.limit !== void 0 ? { maxCandidates: options.limit } : {}
|
|
19922
|
+
...options.limit !== void 0 ? { maxCandidates: options.limit } : {},
|
|
19923
|
+
...options.offset !== void 0 ? { cursor: { knowledgeVersion: combined.version, offset: options.offset } } : {}
|
|
19502
19924
|
}, sources);
|
|
19503
19925
|
if (options.explain) {
|
|
19504
19926
|
const report = explainDiscovery(combined, discovery, situation);
|
|
@@ -19627,6 +20049,20 @@ async function runContext(situation, _cwd, options = {}) {
|
|
|
19627
20049
|
claims: projection
|
|
19628
20050
|
}, null, 2);
|
|
19629
20051
|
}
|
|
20052
|
+
if (options.manifest) {
|
|
20053
|
+
return JSON.stringify({
|
|
20054
|
+
knowledgeVersion: projection.knowledgeVersion,
|
|
20055
|
+
totalCandidates: projection.totalCandidates,
|
|
20056
|
+
included: projection.experiences.length,
|
|
20057
|
+
omittedCandidates: projection.omittedCandidates,
|
|
20058
|
+
manifest: projection.manifest ?? {
|
|
20059
|
+
considered: projection.totalCandidates,
|
|
20060
|
+
included: projection.experiences.length,
|
|
20061
|
+
items: [],
|
|
20062
|
+
byReason: []
|
|
20063
|
+
}
|
|
20064
|
+
}, null, 2);
|
|
20065
|
+
}
|
|
19630
20066
|
if (options.format === "brief") {
|
|
19631
20067
|
const header = options.claimsOnly ? renderBriefClaimsHeader() : `${identityChannel.text}
|
|
19632
20068
|
${profileText}
|
|
@@ -19657,9 +20093,10 @@ ${projection.text}`;
|
|
|
19657
20093
|
const sizeText = renderSizeDisclosure({
|
|
19658
20094
|
totalCandidates: projection.totalCandidates,
|
|
19659
20095
|
omittedCandidates: projection.omittedCandidates,
|
|
19660
|
-
projectedBytes: projectedBody.length,
|
|
19661
|
-
maxCharacters: options.full ?
|
|
19662
|
-
hostCeilingBytes: DOTMEM_HOST_TRUNCATION_CEILING_BYTES
|
|
20096
|
+
projectedBytes: new TextEncoder().encode(projectedBody).length,
|
|
20097
|
+
maxCharacters: options.full ? Number.MAX_SAFE_INTEGER : DOTMEM_CONTEXT_DEFAULT_MAX_CHARACTERS,
|
|
20098
|
+
hostCeilingBytes: DOTMEM_HOST_TRUNCATION_CEILING_BYTES,
|
|
20099
|
+
manifest: projection.manifest
|
|
19663
20100
|
});
|
|
19664
20101
|
return `${identityChannel.text}
|
|
19665
20102
|
${profileText}
|
|
@@ -19757,6 +20194,8 @@ __name(topLevelUsage, "topLevelUsage");
|
|
|
19757
20194
|
|
|
19758
20195
|
// core/cli/commands/context.ts
|
|
19759
20196
|
init_memory();
|
|
20197
|
+
init_memory();
|
|
20198
|
+
init_project();
|
|
19760
20199
|
|
|
19761
20200
|
// core/functions/profile-request.ts
|
|
19762
20201
|
init_profile();
|
|
@@ -19819,6 +20258,17 @@ async function runContextCli(situation, options = {}) {
|
|
|
19819
20258
|
console.info(gate.text);
|
|
19820
20259
|
return;
|
|
19821
20260
|
}
|
|
20261
|
+
if (options.claimId) {
|
|
20262
|
+
const state2 = await loadCombinedKnowledgeState();
|
|
20263
|
+
const claim = state2.claims.find((candidate) => candidate.id === options.claimId);
|
|
20264
|
+
if (!claim) {
|
|
20265
|
+
console.error(`No claim with id ${options.claimId} is present in the loaded stores.`);
|
|
20266
|
+
process.exitCode = 1;
|
|
20267
|
+
return;
|
|
20268
|
+
}
|
|
20269
|
+
console.info(renderExpandedClaim(claim));
|
|
20270
|
+
return;
|
|
20271
|
+
}
|
|
19822
20272
|
const text = await runContext(situation ?? "", void 0, {
|
|
19823
20273
|
...options,
|
|
19824
20274
|
handshake: gate.record ?? void 0,
|
|
@@ -20830,6 +21280,7 @@ init_memory();
|
|
|
20830
21280
|
init_rules_loader();
|
|
20831
21281
|
async function runRulesCli(args) {
|
|
20832
21282
|
const json = args.includes("--json");
|
|
21283
|
+
const expand = args.includes("--expand");
|
|
20833
21284
|
try {
|
|
20834
21285
|
const state2 = await loadCombinedKnowledgeState();
|
|
20835
21286
|
const report = loadIronRules(state2);
|
|
@@ -20841,7 +21292,7 @@ async function runRulesCli(args) {
|
|
|
20841
21292
|
console.info("No iron rules found.");
|
|
20842
21293
|
return;
|
|
20843
21294
|
}
|
|
20844
|
-
console.info(formatRulesForSessionStart(report.rules));
|
|
21295
|
+
console.info(expand ? formatRulesForSessionStart(report.rules) : formatRulesReference(report.rules));
|
|
20845
21296
|
} catch (error) {
|
|
20846
21297
|
console.error(`Rules loading failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
20847
21298
|
process.exitCode = 1;
|
|
@@ -21663,9 +22114,12 @@ Record operator feedback about how an acquired claim performed.
|
|
|
21663
22114
|
}
|
|
21664
22115
|
if (command === "rules") {
|
|
21665
22116
|
if (args[0] === "--help" || args[0] === "-h") {
|
|
21666
|
-
console.info(`Usage: npx dotmem rules [--json]
|
|
22117
|
+
console.info(`Usage: npx dotmem rules [--json] [--expand]
|
|
22118
|
+
|
|
22119
|
+
Print iron rules (human-stated, kind: 'rule') sorted by violation frequency.
|
|
21667
22120
|
|
|
21668
|
-
|
|
22121
|
+
--json output structured report (count, signature, ids, rules)
|
|
22122
|
+
--expand print full rule bodies instead of the compact reference`);
|
|
21669
22123
|
process14__default.default.exit(0);
|
|
21670
22124
|
return;
|
|
21671
22125
|
}
|