pi-mega-compact 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/extensions/mega-compact.test.js +48 -0
- package/dist/extensions/mega-conflict-cmds.js +17 -0
- package/dist/extensions/mega-events.js +110 -24
- package/dist/extensions/mega-pipeline.js +33 -18
- package/dist/extensions/mega-runtime.js +20 -0
- package/dist/extensions/mega-teamrun.test.js +143 -0
- package/dist/extensions/mega-trim.js +33 -2
- package/dist/src/memoryOps.js +42 -2
- package/dist/src/memoryOps.test.js +50 -27
- package/dist/src/memoryRecall.js +48 -0
- package/dist/src/memoryRecall.test.js +52 -0
- package/dist/src/recall.js +34 -8
- package/dist/src/store/memoryIndex.js +205 -0
- package/dist/src/store/memoryIndex.test.js +51 -0
- package/dist/src/store/sqlite.js +24 -5
- package/extensions/mega-compact.test.ts +50 -0
- package/extensions/mega-conflict-cmds.ts +15 -0
- package/extensions/mega-events.ts +104 -23
- package/extensions/mega-pipeline.ts +37 -17
- package/extensions/mega-runtime.ts +21 -0
- package/extensions/mega-teamrun.test.ts +164 -0
- package/extensions/mega-trim.ts +28 -1
- package/package.json +1 -1
- package/src/memoryOps.test.ts +47 -26
- package/src/memoryOps.ts +42 -2
- package/src/memoryRecall.test.ts +58 -0
- package/src/memoryRecall.ts +52 -0
- package/src/recall.ts +35 -10
- package/src/store/memoryIndex.test.ts +61 -0
- package/src/store/memoryIndex.ts +235 -0
- package/src/store/sqlite.ts +26 -5
package/src/store/sqlite.ts
CHANGED
|
@@ -718,14 +718,34 @@ export function addLesson(
|
|
|
718
718
|
// file-backed memory caps a single entry at ~5k chars). We truncate content at
|
|
719
719
|
// MEMORY_MAX_CHARS and evict the least-recently-referenced rows past
|
|
720
720
|
// MEMORY_MAX_ROWS per repo via LRU. Both are SQLite-only (PREVENT-PI-004): no
|
|
721
|
-
// file-backed memory is written anywhere.
|
|
721
|
+
// file-backed memory is written anywhere. Defaults are overridable via env
|
|
722
|
+
// (MEGACOMPACT_MEMORY_MAX_CHARS / MEGACOMPACT_MEMORY_MAX_ROWS).
|
|
722
723
|
export const MEMORY_MAX_CHARS = 4000;
|
|
723
|
-
export const MEMORY_MAX_ROWS =
|
|
724
|
+
export const MEMORY_MAX_ROWS = 500;
|
|
725
|
+
|
|
726
|
+
/** Read an env override as a positive int, falling back to `fallback`. */
|
|
727
|
+
function envInt(name: string, fallback: number): number {
|
|
728
|
+
const v = process.env[name];
|
|
729
|
+
if (v == null || v === "") return fallback;
|
|
730
|
+
const n = Number(v);
|
|
731
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : fallback;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/** Effective per-entry char cap (env-overridable, default MEMORY_MAX_CHARS). */
|
|
735
|
+
export function memoryMaxChars(): number {
|
|
736
|
+
return envInt("MEGACOMPACT_MEMORY_MAX_CHARS", MEMORY_MAX_CHARS);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** Effective per-repo row cap (env-overridable, default MEMORY_MAX_ROWS). */
|
|
740
|
+
export function memoryMaxRows(): number {
|
|
741
|
+
return envInt("MEGACOMPACT_MEMORY_MAX_ROWS", MEMORY_MAX_ROWS);
|
|
742
|
+
}
|
|
724
743
|
|
|
725
744
|
/** Truncate memory content to the per-entry cap, preserving a trailing marker. */
|
|
726
745
|
function capMemoryContent(content: string): string {
|
|
727
|
-
|
|
728
|
-
|
|
746
|
+
const cap = memoryMaxChars();
|
|
747
|
+
if (content.length <= cap) return content;
|
|
748
|
+
return content.slice(0, cap) + "…[truncated]";
|
|
729
749
|
}
|
|
730
750
|
|
|
731
751
|
/**
|
|
@@ -736,6 +756,7 @@ function capMemoryContent(content: string): string {
|
|
|
736
756
|
*/
|
|
737
757
|
function evictMemoryLru(repo: string | null, stateDir: string): void {
|
|
738
758
|
const db = openStore(stateDir);
|
|
759
|
+
const maxRows = memoryMaxRows();
|
|
739
760
|
// SQLite `= NULL` is never true, so the null-repo scope (memories are
|
|
740
761
|
// stateDir-scoped when repo is null — the applyMemoryOps path) needs `IS NULL`.
|
|
741
762
|
const where = repo == null ? "repo IS NULL" : "repo = ?";
|
|
@@ -743,7 +764,7 @@ function evictMemoryLru(repo: string | null, stateDir: string): void {
|
|
|
743
764
|
? db.prepare(`SELECT COUNT(*) AS n FROM memories WHERE ${where}`).get()
|
|
744
765
|
: db.prepare(`SELECT COUNT(*) AS n FROM memories WHERE ${where}`).get(repo);
|
|
745
766
|
const count = (countRow as { n: number }).n;
|
|
746
|
-
const over = count -
|
|
767
|
+
const over = count - maxRows;
|
|
747
768
|
if (over <= 0) return;
|
|
748
769
|
// Delete the `over` least-recently-used rows. ORDER BY the LRU key ASC, id ASC
|
|
749
770
|
// (id ASC breaks ties deterministically — oldest created first). The `where`
|