pi-mega-compact 0.7.8 → 0.8.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/README.md +11 -12
- package/dist/extensions/dashboard-server/html.js +1023 -0
- package/dist/extensions/dashboard-server/html.test.js +41 -0
- package/dist/extensions/dashboard-server/index-reader.js +133 -0
- package/dist/extensions/dashboard-server/server.js +530 -0
- package/dist/extensions/dashboard-server/server.test.js +120 -0
- package/dist/extensions/dashboard-server/snapshot.js +43 -0
- package/dist/extensions/dashboard-server/state.js +30 -0
- package/dist/extensions/dashboard-server/types.js +5 -0
- package/dist/extensions/dashboard-server-s32.test.js +181 -0
- package/dist/extensions/dashboard-server.js +7 -1315
- package/dist/extensions/mega-commands.js +162 -134
- package/dist/extensions/mega-compact.js +3 -0
- package/dist/extensions/mega-compact.test.js +90 -21
- package/dist/extensions/mega-conflict-cmds.js +5 -1
- package/dist/extensions/mega-dashboard-cmds.js +29 -22
- package/dist/extensions/mega-db-cmds.js +11 -2
- package/dist/extensions/mega-events/agent-handlers.js +222 -0
- package/dist/extensions/mega-events/compact-handlers.js +162 -0
- package/dist/extensions/mega-events/context-handler.js +249 -0
- package/dist/extensions/mega-events/register.js +21 -0
- package/dist/extensions/mega-events/session-handlers.js +142 -0
- package/dist/extensions/mega-events.js +15 -699
- package/dist/extensions/mega-game-cmds.js +106 -0
- package/dist/extensions/mega-game-cmds.test.js +113 -0
- package/dist/extensions/mega-pipeline/compact.js +324 -0
- package/dist/extensions/mega-pipeline/memory-review.js +38 -0
- package/dist/extensions/mega-pipeline/recall.js +147 -0
- package/dist/extensions/mega-pipeline.js +9 -480
- package/dist/extensions/mega-runtime/helpers.js +40 -0
- package/dist/extensions/mega-runtime/query.js +29 -0
- package/dist/extensions/mega-runtime/state.js +877 -0
- package/dist/extensions/mega-runtime/state.test.js +171 -0
- package/dist/extensions/mega-runtime/widget.js +270 -0
- package/dist/extensions/mega-runtime/widget.test.js +160 -0
- package/dist/extensions/mega-runtime.js +15 -947
- package/dist/src/config/themes.js +84 -0
- package/dist/src/config/themes.test.js +94 -0
- package/dist/src/game/scoring.js +105 -0
- package/dist/src/game/scoring.test.js +98 -0
- package/dist/src/store/sqlite/checkpoints.js +145 -0
- package/dist/src/store/sqlite/dedup-mirror.js +64 -0
- package/dist/src/store/sqlite/foundation.js +38 -0
- package/dist/src/store/sqlite/game-achievements.js +111 -0
- package/dist/src/store/sqlite/game-achievements.test.js +67 -0
- package/dist/src/store/sqlite/game-scores.js +105 -0
- package/dist/src/store/sqlite/game-scores.test.js +106 -0
- package/dist/src/store/sqlite/game-state.js +54 -0
- package/dist/src/store/sqlite/game-state.test.js +76 -0
- package/dist/src/store/sqlite/global-index.js +224 -0
- package/dist/src/store/sqlite/maintenance.js +235 -0
- package/dist/src/store/sqlite/memories.js +164 -0
- package/dist/src/store/sqlite/meta.js +82 -0
- package/dist/src/store/sqlite/model-snapshots.js +47 -0
- package/dist/src/store/sqlite/raptor.js +57 -0
- package/dist/src/store/sqlite/raw-transcript.js +134 -0
- package/dist/src/store/sqlite/schema.js +294 -0
- package/dist/src/store/sqlite/session-state.js +28 -0
- package/dist/src/store/sqlite/stats.js +66 -0
- package/dist/src/store/sqlite/utils.js +120 -0
- package/dist/src/store/sqlite.js +23 -1607
- package/extensions/dashboard-server/html.test.ts +50 -0
- package/extensions/dashboard-server/html.ts +1026 -0
- package/extensions/dashboard-server/index-reader.ts +130 -0
- package/extensions/dashboard-server/server.test.ts +131 -0
- package/extensions/dashboard-server/server.ts +505 -0
- package/extensions/dashboard-server/snapshot.ts +44 -0
- package/extensions/dashboard-server/state.ts +33 -0
- package/extensions/dashboard-server/types.ts +134 -0
- package/extensions/dashboard-server-s32.test.ts +195 -0
- package/extensions/dashboard-server.ts +7 -1431
- package/extensions/mega-commands.ts +33 -10
- package/extensions/mega-compact.test.ts +198 -43
- package/extensions/mega-compact.ts +3 -0
- package/extensions/mega-conflict-cmds.ts +6 -2
- package/extensions/mega-dashboard-cmds.ts +30 -23
- package/extensions/mega-db-cmds.ts +11 -3
- package/extensions/mega-events/agent-handlers.ts +262 -0
- package/extensions/mega-events/compact-handlers.ts +192 -0
- package/extensions/mega-events/context-handler.ts +290 -0
- package/extensions/mega-events/register.ts +37 -0
- package/extensions/mega-events/session-handlers.ts +165 -0
- package/extensions/mega-events.ts +15 -780
- package/extensions/mega-game-cmds.test.ts +137 -0
- package/extensions/mega-game-cmds.ts +122 -0
- package/extensions/mega-pipeline/compact.ts +366 -0
- package/extensions/mega-pipeline/memory-review.ts +46 -0
- package/extensions/mega-pipeline/recall.ts +165 -0
- package/extensions/mega-pipeline.ts +9 -537
- package/extensions/mega-runtime/helpers.ts +68 -0
- package/extensions/mega-runtime/query.ts +29 -0
- package/extensions/mega-runtime/state.test.ts +171 -0
- package/extensions/mega-runtime/state.ts +967 -0
- package/extensions/mega-runtime/widget.test.ts +185 -0
- package/extensions/mega-runtime/widget.ts +359 -0
- package/extensions/mega-runtime.ts +15 -1093
- package/package.json +4 -3
- package/src/config/themes.test.ts +116 -0
- package/src/config/themes.ts +124 -0
- package/src/game/scoring.test.ts +103 -0
- package/src/game/scoring.ts +158 -0
- package/src/store/sqlite/checkpoints.ts +204 -0
- package/src/store/sqlite/dedup-mirror.ts +114 -0
- package/src/store/sqlite/foundation.ts +63 -0
- package/src/store/sqlite/game-achievements.test.ts +80 -0
- package/src/store/sqlite/game-achievements.ts +147 -0
- package/src/store/sqlite/game-scores.test.ts +132 -0
- package/src/store/sqlite/game-scores.ts +168 -0
- package/src/store/sqlite/game-state.test.ts +89 -0
- package/src/store/sqlite/game-state.ts +87 -0
- package/src/store/sqlite/global-index.ts +305 -0
- package/src/store/sqlite/maintenance.ts +294 -0
- package/src/store/sqlite/memories.ts +217 -0
- package/src/store/sqlite/meta.ts +108 -0
- package/src/store/sqlite/model-snapshots.ts +83 -0
- package/src/store/sqlite/raptor.ts +107 -0
- package/src/store/sqlite/raw-transcript.ts +221 -0
- package/src/store/sqlite/schema.ts +305 -0
- package/src/store/sqlite/session-state.ts +38 -0
- package/src/store/sqlite/stats.ts +127 -0
- package/src/store/sqlite/utils.ts +125 -0
- package/src/store/sqlite.ts +23 -2204
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* state.test.ts — S31 MegaRuntime game-state cache round-trip.
|
|
3
|
+
*
|
|
4
|
+
* getCachedGameState() lazily reads the game_state row; bumpGameState()
|
|
5
|
+
* evicts so the next read re-queries. Uses MEGACOMPACT_STATE_DIR + mkdtemp
|
|
6
|
+
* (G7). A minimal MegaRuntime is constructed directly (no pi runtime).
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, after } from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { execSync } from "node:child_process";
|
|
15
|
+
import { closeStore, getGameState, setGameState } from "../../src/store/sqlite.js";
|
|
16
|
+
import { DEFAULT_GAME_STATE } from "../../src/store/sqlite/game-state.js";
|
|
17
|
+
|
|
18
|
+
const require = createRequire(import.meta.url);
|
|
19
|
+
// Require the compiled JS (build output) so ESM import of pi-tui etc. resolves.
|
|
20
|
+
const { MegaRuntime } = require("./state.js") as {
|
|
21
|
+
MegaRuntime: new (config: any) => any;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Minimal MegaConfig — enough fields for the constructor; the snapshot path
|
|
25
|
+
* isn't exercised here, only getCachedGameState/bumpGameState. */
|
|
26
|
+
function minimalConfig(stateDir: string): any {
|
|
27
|
+
return {
|
|
28
|
+
tier: "custom",
|
|
29
|
+
tierPct: null,
|
|
30
|
+
thresholdTokens: 100_000,
|
|
31
|
+
stateDir,
|
|
32
|
+
fastGatePct: 70,
|
|
33
|
+
anchorUserMessages: 3,
|
|
34
|
+
preserveRecent: 4,
|
|
35
|
+
preserveRecentMin: 2,
|
|
36
|
+
auto: false,
|
|
37
|
+
autoInline: false,
|
|
38
|
+
autoContinueLengthStop: false,
|
|
39
|
+
autoPctTrigger: null,
|
|
40
|
+
dedupSim: 0.9,
|
|
41
|
+
raptorEnabled: false,
|
|
42
|
+
legacyDurableTrim: false,
|
|
43
|
+
dbMirror: false,
|
|
44
|
+
crossRepoEnabled: false,
|
|
45
|
+
crossRepoCosine: 0.9,
|
|
46
|
+
memoryAutoReview: false,
|
|
47
|
+
memoryReviewInterval: 10,
|
|
48
|
+
recallMaxTokens: 1500,
|
|
49
|
+
windowDedupe: false,
|
|
50
|
+
debug: false,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Fresh isolated state dir per test — the game_state row is global and
|
|
55
|
+
* persists across cases in a shared dir, so each case gets its own mkdtemp to
|
|
56
|
+
* avoid cross-test contamination. */
|
|
57
|
+
function freshDir(): string {
|
|
58
|
+
return mkdtempSync(join(tmpdir(), "mc-state-"));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("MegaRuntime game-state cache (S31)", () => {
|
|
62
|
+
const dirs: string[] = [];
|
|
63
|
+
after(() => {
|
|
64
|
+
for (const d of dirs) {
|
|
65
|
+
try { closeStore(d); } catch { /* */ }
|
|
66
|
+
}
|
|
67
|
+
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
68
|
+
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("getCachedGameState returns defaults on a fresh install", () => {
|
|
72
|
+
const dir = freshDir(); dirs.push(dir);
|
|
73
|
+
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
74
|
+
const rt = new MegaRuntime(minimalConfig(dir));
|
|
75
|
+
const gs = rt.getCachedGameState();
|
|
76
|
+
assert.deepEqual(gs, { ...DEFAULT_GAME_STATE });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("getCachedGameState memoizes (same ref across calls)", () => {
|
|
80
|
+
const dir = freshDir(); dirs.push(dir);
|
|
81
|
+
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
82
|
+
const rt = new MegaRuntime(minimalConfig(dir));
|
|
83
|
+
const a = rt.getCachedGameState();
|
|
84
|
+
const b = rt.getCachedGameState();
|
|
85
|
+
assert.equal(a, b, "memoized — same object ref");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("bumpGameState evicts so the next read reflects a setGameState write", () => {
|
|
89
|
+
const dir = freshDir(); dirs.push(dir);
|
|
90
|
+
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
91
|
+
const rt = new MegaRuntime(minimalConfig(dir));
|
|
92
|
+
const before = rt.getCachedGameState();
|
|
93
|
+
assert.equal(before.game_mode_on, false);
|
|
94
|
+
|
|
95
|
+
// Write out-of-band (as /mega-game would).
|
|
96
|
+
setGameState({ game_mode_on: true, theme: "retro", tui_display_mode: "minimal" }, dir);
|
|
97
|
+
|
|
98
|
+
// Without bump, the stale memo is returned.
|
|
99
|
+
const stale = rt.getCachedGameState();
|
|
100
|
+
assert.equal(stale.game_mode_on, false, "stale cache before bump");
|
|
101
|
+
|
|
102
|
+
// After bump, the next read re-queries and reflects the write.
|
|
103
|
+
rt.bumpGameState();
|
|
104
|
+
const fresh = rt.getCachedGameState();
|
|
105
|
+
assert.equal(fresh.game_mode_on, true);
|
|
106
|
+
assert.equal(fresh.theme, "retro");
|
|
107
|
+
assert.equal(fresh.tui_display_mode, "minimal");
|
|
108
|
+
// And matches the authoritative getGameState read.
|
|
109
|
+
assert.deepEqual(fresh, getGameState(dir));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("bumpGameState is idempotent (safe to call when cache is empty)", () => {
|
|
113
|
+
const dir = freshDir(); dirs.push(dir);
|
|
114
|
+
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
115
|
+
const rt = new MegaRuntime(minimalConfig(dir));
|
|
116
|
+
rt.bumpGameState(); // no cached state yet — must not throw
|
|
117
|
+
const gs = rt.getCachedGameState();
|
|
118
|
+
assert.deepEqual(gs, { ...DEFAULT_GAME_STATE });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("bindRepo evicts cachedGameState so a repo switch reflects the new repo's game_state", () => {
|
|
122
|
+
// Two fresh git repos A and B simulate a real repo switch. Each holds its
|
|
123
|
+
// own per-repo state dir at <root>/.pi/mega-compact (what repoStateDir
|
|
124
|
+
// returns for a git cwd), and each holds its own game_state row, so a repo
|
|
125
|
+
// switch (bindRepo) must evict the cached memo or the widget shows A's
|
|
126
|
+
// theme/mode/toggle after moving to B. Uses MEGACOMPACT_STATE_DIR + mkdtemp
|
|
127
|
+
// + closeStore (G7); the global state dir stays separate.
|
|
128
|
+
const globalDir = freshDir(); dirs.push(globalDir);
|
|
129
|
+
const repoA = freshDir(); dirs.push(repoA);
|
|
130
|
+
const repoB = freshDir(); dirs.push(repoB);
|
|
131
|
+
const stateA = join(repoA, ".pi", "mega-compact");
|
|
132
|
+
const stateB = join(repoB, ".pi", "mega-compact");
|
|
133
|
+
|
|
134
|
+
// Make A and B real git roots so resolveRepoRoot(cwd) returns the root and
|
|
135
|
+
// repoStateDir produces <root>/.pi/mega-compact (the per-repo store).
|
|
136
|
+
execSync("git init -q", { cwd: repoA });
|
|
137
|
+
execSync("git init -q", { cwd: repoB });
|
|
138
|
+
|
|
139
|
+
// Seed A and B with distinct game_state rows in their per-repo dirs.
|
|
140
|
+
setGameState({ game_mode_on: true, theme: "retro", tui_display_mode: "minimal" }, stateA);
|
|
141
|
+
setGameState({ game_mode_on: false, theme: "cyan-neon", tui_display_mode: "full" }, stateB);
|
|
142
|
+
|
|
143
|
+
// Construct the runtime against the GLOBAL dir (the non-git fallback so a
|
|
144
|
+
// real bindRepo switch occurs once we point it at a git root).
|
|
145
|
+
process.env.MEGACOMPACT_STATE_DIR = globalDir;
|
|
146
|
+
const rt = new MegaRuntime(minimalConfig(globalDir));
|
|
147
|
+
|
|
148
|
+
// Point the runtime at repo A and prime the cache.
|
|
149
|
+
rt.bindRepo(repoA);
|
|
150
|
+
assert.equal(rt.currentStateDir, stateA, "bindRepo(A) switched to A's per-repo dir");
|
|
151
|
+
const a = rt.getCachedGameState();
|
|
152
|
+
assert.equal(a.game_mode_on, true, "A: game_mode_on primed");
|
|
153
|
+
assert.equal(a.theme, "retro", "A: theme primed");
|
|
154
|
+
assert.equal(a.tui_display_mode, "minimal", "A: tui_display_mode primed");
|
|
155
|
+
|
|
156
|
+
// Switch to repo B: bindRepo must evict cachedGameState so the next read
|
|
157
|
+
// re-queries B's row instead of returning A's stale memo.
|
|
158
|
+
rt.bindRepo(repoB);
|
|
159
|
+
assert.equal(rt.currentStateDir, stateB, "bindRepo(B) switched to B's per-repo dir");
|
|
160
|
+
const b = rt.getCachedGameState();
|
|
161
|
+
assert.equal(b.game_mode_on, false, "B: game_mode_on after switch (not A's stale true)");
|
|
162
|
+
assert.equal(b.theme, "cyan-neon", "B: theme after switch (not A's stale retro)");
|
|
163
|
+
assert.equal(b.tui_display_mode, "full", "B: tui_display_mode after switch (not A's stale minimal)");
|
|
164
|
+
assert.deepEqual(b, getGameState(stateB), "B matches authoritative getGameState read");
|
|
165
|
+
|
|
166
|
+
// Cleanup the per-repo DB handles.
|
|
167
|
+
try { closeStore(globalDir); } catch { /* */ }
|
|
168
|
+
try { closeStore(stateA); } catch { /* */ }
|
|
169
|
+
try { closeStore(stateB); } catch { /* */ }
|
|
170
|
+
});
|
|
171
|
+
});
|