pi-mega-compact 0.7.9 → 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/dist/extensions/dashboard-server/html.js +333 -66
- package/dist/extensions/dashboard-server/html.test.js +41 -0
- package/dist/extensions/dashboard-server/server.js +161 -1
- package/dist/extensions/dashboard-server/server.test.js +120 -0
- package/dist/extensions/dashboard-server-s32.test.js +181 -0
- package/dist/extensions/mega-compact.js +3 -0
- package/dist/extensions/mega-events/agent-handlers.js +49 -0
- package/dist/extensions/mega-events/compact-handlers.js +29 -0
- package/dist/extensions/mega-game-cmds.js +106 -0
- package/dist/extensions/mega-game-cmds.test.js +113 -0
- package/dist/extensions/mega-runtime/state.js +167 -1
- package/dist/extensions/mega-runtime/state.test.js +171 -0
- package/dist/extensions/mega-runtime/widget.js +93 -20
- package/dist/extensions/mega-runtime/widget.test.js +160 -0
- 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/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/schema.js +44 -0
- package/dist/src/store/sqlite.js +3 -0
- package/extensions/dashboard-server/html.test.ts +50 -0
- package/extensions/dashboard-server/html.ts +334 -66
- package/extensions/dashboard-server/server.test.ts +131 -0
- package/extensions/dashboard-server/server.ts +148 -1
- package/extensions/dashboard-server-s32.test.ts +195 -0
- package/extensions/mega-compact.ts +3 -0
- package/extensions/mega-events/agent-handlers.ts +48 -0
- package/extensions/mega-events/compact-handlers.ts +28 -0
- package/extensions/mega-game-cmds.test.ts +137 -0
- package/extensions/mega-game-cmds.ts +122 -0
- package/extensions/mega-runtime/state.test.ts +171 -0
- package/extensions/mega-runtime/state.ts +170 -0
- package/extensions/mega-runtime/widget.test.ts +185 -0
- package/extensions/mega-runtime/widget.ts +119 -18
- package/package.json +1 -1
- 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/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/schema.ts +47 -0
- package/src/store/sqlite.ts +3 -0
- package/dist/extensions/dashboard-server/helpers.js +0 -37
- package/dist/extensions/dashboard-server/html/all-repos-tab.js +0 -26
- package/dist/extensions/dashboard-server/html/body-open.js +0 -23
- package/dist/extensions/dashboard-server/html/current-repo-tab.js +0 -130
- package/dist/extensions/dashboard-server/html/head-open.js +0 -16
- package/dist/extensions/dashboard-server/html/high-score-tab.js +0 -25
- package/dist/extensions/dashboard-server/html/repo-detail-modal.js +0 -26
- package/dist/extensions/dashboard-server/html/script.js +0 -259
- package/dist/extensions/dashboard-server/html/styles.js +0 -103
- package/dist/extensions/dashboard-server/html/summary-tab.js +0 -19
- package/dist/extensions/dashboard-server/html-template.js +0 -41
- package/dist/src/store/sqlite/connection.js +0 -35
- package/dist/src/store/sqlite/index-store.js +0 -167
- package/dist/src/store/sqlite/memory.js +0 -54
- package/dist/src/store/sqlite/minhash-lsh.js +0 -47
- package/dist/src/store/sqlite/sessions.js +0 -39
- package/dist/src/store/sqlite/transaction.js +0 -19
- package/dist/src/vectorStore/add.js +0 -260
- package/dist/src/vectorStore/dedup.js +0 -52
- package/dist/src/vectorStore/index.js +0 -10
- package/dist/src/vectorStore/queries.js +0 -83
- package/dist/src/vectorStore/search.js +0 -95
- package/dist/src/vectorStore/session.js +0 -19
- package/dist/src/vectorStore/store.js +0 -105
- package/dist/src/vectorStore/types.js +0 -6
- package/dist/src/vectorStore/utils.js +0 -23
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global machine-wide index store (Phase 5b).
|
|
3
|
-
*
|
|
4
|
-
* A single SQLite DB, separate from every per-repo store, that aggregates one
|
|
5
|
-
* row per repo this machine has run on. The multi-repo dashboard (Summary /
|
|
6
|
-
* All-repos tabs) reads it so ONE dashboard can show every repo's checkpoints,
|
|
7
|
-
* tokens saved, and active model — instead of a per-repo dashboard that only
|
|
8
|
-
* ever sees the repo it was launched from.
|
|
9
|
-
*
|
|
10
|
-
* Written by every pi process on repo-switch (bindRepo) + model capture; read by
|
|
11
|
-
* the dashboard server. Concurrency across 10+ pi processes is handled by WAL +
|
|
12
|
-
* infrequent idempotent upserts (ON CONFLICT). Fully local (PREVENT-PI-004).
|
|
13
|
-
*/
|
|
14
|
-
import { DatabaseSync } from "node:sqlite";
|
|
15
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
16
|
-
import { homedir, tmpdir } from "node:os";
|
|
17
|
-
import { join } from "node:path";
|
|
18
|
-
/** Resolve the machine-wide index directory (env-overridable). */
|
|
19
|
-
export function getIndexDir() {
|
|
20
|
-
const override = process.env.MEGACOMPACT_INDEX_DIR;
|
|
21
|
-
if (override && override.trim() !== "")
|
|
22
|
-
return override;
|
|
23
|
-
// homedir() can throw in exotic sandboxes; fall back to tmpdir.
|
|
24
|
-
try {
|
|
25
|
-
return join(homedir(), ".mega-compact-index");
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return join(tmpdir(), ".mega-compact-index");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
let indexCache;
|
|
32
|
-
let indexCacheDir;
|
|
33
|
-
/** Open (or reuse) the machine-wide index DB. WAL for concurrent writers. */
|
|
34
|
-
export function openIndexStore(indexDir = getIndexDir()) {
|
|
35
|
-
if (indexCache && indexCacheDir === indexDir)
|
|
36
|
-
return indexCache;
|
|
37
|
-
if (!existsSync(indexDir))
|
|
38
|
-
mkdirSync(indexDir, { recursive: true });
|
|
39
|
-
const iddb = new DatabaseSync(join(indexDir, "index.sqlite"));
|
|
40
|
-
iddb.exec("PRAGMA journal_mode = WAL");
|
|
41
|
-
iddb.exec("PRAGMA busy_timeout = 3000"); // tolerate brief cross-process write contention
|
|
42
|
-
iddb.exec(`
|
|
43
|
-
CREATE TABLE IF NOT EXISTS repo_registry (
|
|
44
|
-
repo_root TEXT PRIMARY KEY,
|
|
45
|
-
display_name TEXT,
|
|
46
|
-
state_dir TEXT NOT NULL,
|
|
47
|
-
first_seen INTEGER,
|
|
48
|
-
last_seen INTEGER,
|
|
49
|
-
last_compacted_at INTEGER,
|
|
50
|
-
checkpoint_count INTEGER DEFAULT 0,
|
|
51
|
-
tokens_saved INTEGER DEFAULT 0,
|
|
52
|
-
compressed_original_bytes INTEGER DEFAULT 0,
|
|
53
|
-
provider TEXT,
|
|
54
|
-
provider_name TEXT,
|
|
55
|
-
model_name TEXT,
|
|
56
|
-
input_rate REAL,
|
|
57
|
-
output_rate REAL,
|
|
58
|
-
model_captured_at INTEGER
|
|
59
|
-
);
|
|
60
|
-
CREATE INDEX IF NOT EXISTS idx_registry_last_seen ON repo_registry(last_seen DESC);
|
|
61
|
-
`);
|
|
62
|
-
indexCache = iddb;
|
|
63
|
-
indexCacheDir = indexDir;
|
|
64
|
-
return iddb;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Upsert a repo's aggregate stats into the global index. Called on repo-switch
|
|
68
|
-
* (infrequent). Preserves first_seen + the model columns on update (model is
|
|
69
|
-
* written separately by recordRepoModel so we never clobber it here with nulls).
|
|
70
|
-
*/
|
|
71
|
-
export function upsertRepoRegistry(row, indexDir = getIndexDir()) {
|
|
72
|
-
const db = openIndexStore(indexDir);
|
|
73
|
-
const now = Date.now();
|
|
74
|
-
db.prepare(`INSERT INTO repo_registry
|
|
75
|
-
(repo_root, display_name, state_dir, first_seen, last_seen, last_compacted_at,
|
|
76
|
-
checkpoint_count, tokens_saved, compressed_original_bytes)
|
|
77
|
-
VALUES (@repo_root, @display_name, @state_dir, @now, @now, @last_compacted_at,
|
|
78
|
-
@checkpoint_count, @tokens_saved, @compressed_original_bytes)
|
|
79
|
-
ON CONFLICT(repo_root) DO UPDATE SET
|
|
80
|
-
display_name = excluded.display_name,
|
|
81
|
-
state_dir = excluded.state_dir,
|
|
82
|
-
last_seen = excluded.last_seen,
|
|
83
|
-
last_compacted_at = COALESCE(excluded.last_compacted_at, repo_registry.last_compacted_at),
|
|
84
|
-
checkpoint_count = excluded.checkpoint_count,
|
|
85
|
-
tokens_saved = excluded.tokens_saved,
|
|
86
|
-
compressed_original_bytes = excluded.compressed_original_bytes`).run({
|
|
87
|
-
repo_root: row.repoRoot,
|
|
88
|
-
display_name: row.displayName,
|
|
89
|
-
state_dir: row.stateDir,
|
|
90
|
-
now,
|
|
91
|
-
last_compacted_at: row.lastCompactedAt ?? null,
|
|
92
|
-
checkpoint_count: row.checkpointCount,
|
|
93
|
-
tokens_saved: row.tokensSaved,
|
|
94
|
-
compressed_original_bytes: row.compressedOriginalBytes,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Record the active model/provider for a repo in the global index (denormalized
|
|
99
|
-
* so the All-repos table shows model without opening each repo's DB). Upserts a
|
|
100
|
-
* bare registry row if the repo isn't registered yet.
|
|
101
|
-
*/
|
|
102
|
-
export function recordRepoModel(repoRoot, model, indexDir = getIndexDir()) {
|
|
103
|
-
const db = openIndexStore(indexDir);
|
|
104
|
-
const now = Date.now();
|
|
105
|
-
db.prepare(`INSERT INTO repo_registry
|
|
106
|
-
(repo_root, display_name, state_dir, first_seen, last_seen,
|
|
107
|
-
provider, provider_name, model_name, input_rate, output_rate, model_captured_at)
|
|
108
|
-
VALUES (@repo_root, @display_name, @state_dir, @now, @now,
|
|
109
|
-
@provider, @provider_name, @model_name, @input_rate, @output_rate, @now)
|
|
110
|
-
ON CONFLICT(repo_root) DO UPDATE SET
|
|
111
|
-
last_seen = excluded.last_seen,
|
|
112
|
-
provider = excluded.provider,
|
|
113
|
-
provider_name = excluded.provider_name,
|
|
114
|
-
model_name = excluded.model_name,
|
|
115
|
-
input_rate = excluded.input_rate,
|
|
116
|
-
output_rate = excluded.output_rate,
|
|
117
|
-
model_captured_at = excluded.model_captured_at`).run({
|
|
118
|
-
repo_root: repoRoot,
|
|
119
|
-
display_name: model.displayName,
|
|
120
|
-
state_dir: model.stateDir,
|
|
121
|
-
now,
|
|
122
|
-
provider: model.provider,
|
|
123
|
-
provider_name: model.providerName,
|
|
124
|
-
model_name: model.modelName,
|
|
125
|
-
input_rate: model.inputRate,
|
|
126
|
-
output_rate: model.outputRate,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function mapRegistryRow(row) {
|
|
130
|
-
return {
|
|
131
|
-
repoRoot: row.repo_root,
|
|
132
|
-
displayName: row.display_name ?? "",
|
|
133
|
-
stateDir: row.state_dir,
|
|
134
|
-
firstSeen: row.first_seen ?? 0,
|
|
135
|
-
lastSeen: row.last_seen ?? 0,
|
|
136
|
-
lastCompactedAt: row.last_compacted_at ?? null,
|
|
137
|
-
checkpointCount: row.checkpoint_count ?? 0,
|
|
138
|
-
tokensSaved: row.tokens_saved ?? 0,
|
|
139
|
-
compressedOriginalBytes: row.compressed_original_bytes ?? 0,
|
|
140
|
-
provider: row.provider ?? null,
|
|
141
|
-
providerName: row.provider_name ?? null,
|
|
142
|
-
modelName: row.model_name ?? null,
|
|
143
|
-
inputRate: row.input_rate ?? null,
|
|
144
|
-
outputRate: row.output_rate ?? null,
|
|
145
|
-
modelCapturedAt: row.model_captured_at ?? null,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/** All registered repos, most-recently-seen first. */
|
|
149
|
-
export function listRepoRegistry(indexDir = getIndexDir()) {
|
|
150
|
-
const db = openIndexStore(indexDir);
|
|
151
|
-
const rows = db.prepare("SELECT * FROM repo_registry ORDER BY last_seen DESC").all();
|
|
152
|
-
return rows.map(mapRegistryRow);
|
|
153
|
-
}
|
|
154
|
-
/** A single repo's registry row, or undefined. */
|
|
155
|
-
export function getRepoRegistry(repoRoot, indexDir = getIndexDir()) {
|
|
156
|
-
const db = openIndexStore(indexDir);
|
|
157
|
-
const row = db.prepare("SELECT * FROM repo_registry WHERE repo_root = ?").get(repoRoot);
|
|
158
|
-
return row ? mapRegistryRow(row) : undefined;
|
|
159
|
-
}
|
|
160
|
-
/** Close the cached index connection (test teardown only). */
|
|
161
|
-
export function closeIndexStore() {
|
|
162
|
-
if (indexCache) {
|
|
163
|
-
indexCache.close();
|
|
164
|
-
indexCache = undefined;
|
|
165
|
-
indexCacheDir = undefined;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Durable "save to memory" store (taken over from memory extensions).
|
|
3
|
-
*
|
|
4
|
-
* One SQLite store for user-saved memories, scoped by repo. Mirrors the
|
|
5
|
-
* lessons/sessions pattern: all state lives in SQLite from day one. All queries
|
|
6
|
-
* are parameterized (PREVENT-002).
|
|
7
|
-
*/
|
|
8
|
-
import { getStateDir } from "../../store.js";
|
|
9
|
-
import { openStore } from "./connection.js";
|
|
10
|
-
/** Save a memory to the current repo's store. Returns the new row id. */
|
|
11
|
-
export function addMemory(memory, repo, stateDir = getStateDir()) {
|
|
12
|
-
const db = openStore(stateDir);
|
|
13
|
-
const now = Math.floor(Date.now() / 1000);
|
|
14
|
-
const res = db
|
|
15
|
-
.prepare(`INSERT INTO memories(repo, kind, content, tags, created_at, last_recalled_at)
|
|
16
|
-
VALUES(?, ?, ?, ?, ?, NULL)`)
|
|
17
|
-
.run(repo ?? null, memory.kind ?? "note", memory.content, JSON.stringify(memory.tags ?? []), now);
|
|
18
|
-
return Number(res.lastInsertRowid);
|
|
19
|
-
}
|
|
20
|
-
/** List recent memories for a repo (or all repos when repo is null). */
|
|
21
|
-
export function listMemories(repo, limit = 50, stateDir = getStateDir()) {
|
|
22
|
-
const db = openStore(stateDir);
|
|
23
|
-
const rows = repo
|
|
24
|
-
? db.prepare("SELECT * FROM memories WHERE repo = ? ORDER BY created_at DESC LIMIT ?").all(repo, limit)
|
|
25
|
-
: db.prepare("SELECT * FROM memories ORDER BY created_at DESC LIMIT ?").all(limit);
|
|
26
|
-
return rows.map(mapMemoryRow);
|
|
27
|
-
}
|
|
28
|
-
/** Substring search across content + tags. */
|
|
29
|
-
export function searchMemories(query, repo = null, limit = 50, stateDir = getStateDir()) {
|
|
30
|
-
const db = openStore(stateDir);
|
|
31
|
-
const like = `%${query}%`;
|
|
32
|
-
const rows = repo
|
|
33
|
-
? db.prepare("SELECT * FROM memories WHERE repo = ? AND (content LIKE ? OR tags LIKE ?) ORDER BY created_at DESC LIMIT ?").all(repo, like, like, limit)
|
|
34
|
-
: db.prepare("SELECT * FROM memories WHERE content LIKE ? OR tags LIKE ? ORDER BY created_at DESC LIMIT ?").all(like, like, limit);
|
|
35
|
-
return rows.map(mapMemoryRow);
|
|
36
|
-
}
|
|
37
|
-
/** Mark a memory as recalled (updates last_recalled_at). Returns true if found. */
|
|
38
|
-
export function recallMemory(id, stateDir = getStateDir()) {
|
|
39
|
-
const db = openStore(stateDir);
|
|
40
|
-
const now = Math.floor(Date.now() / 1000);
|
|
41
|
-
const res = db.prepare("UPDATE memories SET last_recalled_at = ? WHERE id = ?").run(now, id);
|
|
42
|
-
return res.changes > 0;
|
|
43
|
-
}
|
|
44
|
-
function mapMemoryRow(row) {
|
|
45
|
-
return {
|
|
46
|
-
id: row.id,
|
|
47
|
-
repo: row.repo ?? null,
|
|
48
|
-
kind: row.kind ?? "note",
|
|
49
|
-
content: row.content ?? "",
|
|
50
|
-
tags: row.tags ? JSON.parse(row.tags) : [],
|
|
51
|
-
createdAt: row.created_at ?? 0,
|
|
52
|
-
lastRecalledAt: row.last_recalled_at ?? null,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sprint 11: MinHash signatures + LSH bucket persistence and candidate lookup.
|
|
3
|
-
*
|
|
4
|
-
* All queries are parameterized (PREVENT-002) — never string-concatenated.
|
|
5
|
-
*/
|
|
6
|
-
import { getStateDir, normalizeSessionId } from "../../store.js";
|
|
7
|
-
import { openStore } from "./connection.js";
|
|
8
|
-
import { withTx } from "./transaction.js";
|
|
9
|
-
/** Persist a checkpoint's MinHash signature (idempotent by chunk_id + version). */
|
|
10
|
-
export function upsertMinhashSignature(chunkId, sessionId, signatureVersion, signatures, stateDir = getStateDir()) {
|
|
11
|
-
const db = openStore(stateDir);
|
|
12
|
-
const sid = normalizeSessionId(sessionId);
|
|
13
|
-
db.prepare(`INSERT INTO minhash_signatures(chunk_id, session_id, signature_version, signatures)
|
|
14
|
-
VALUES(?, ?, ?, ?)
|
|
15
|
-
ON CONFLICT(chunk_id, signature_version) DO UPDATE SET
|
|
16
|
-
session_id=excluded.session_id, signatures=excluded.signatures`).run(chunkId, sid, signatureVersion, JSON.stringify(signatures));
|
|
17
|
-
}
|
|
18
|
-
/** Persist LSH bucket memberships for a chunk (one row per bucket key). */
|
|
19
|
-
export function insertLshBuckets(chunkId, sessionId, signatureVersion, bucketKeys, stateDir = getStateDir()) {
|
|
20
|
-
const db = openStore(stateDir);
|
|
21
|
-
const sid = normalizeSessionId(sessionId);
|
|
22
|
-
const del = db.prepare("DELETE FROM dedup_lsh_buckets WHERE chunk_id = ?");
|
|
23
|
-
const ins = db.prepare("INSERT OR IGNORE INTO dedup_lsh_buckets(bucket_key, chunk_id, session_id, signature_version) VALUES(?, ?, ?, ?)");
|
|
24
|
-
withTx(db, () => {
|
|
25
|
-
del.run(chunkId);
|
|
26
|
-
for (const key of bucketKeys)
|
|
27
|
-
ins.run(key, chunkId, sid, signatureVersion);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Candidate chunk_ids sharing any LSH bucket with `bucketKeys`, scoped to the
|
|
32
|
-
* session, capped at `limit`. Single query (no N loops) — QA #15 amplification
|
|
33
|
-
* guard. Returns DISTINCT chunk_ids excluding `excludeChunkId` (the new row).
|
|
34
|
-
*/
|
|
35
|
-
export function lshCandidateChunks(bucketKeys, sessionId, excludeChunkId, stateDir = getStateDir(), limit = 100) {
|
|
36
|
-
if (bucketKeys.length === 0)
|
|
37
|
-
return [];
|
|
38
|
-
const db = openStore(stateDir);
|
|
39
|
-
const sid = normalizeSessionId(sessionId);
|
|
40
|
-
const placeholders = bucketKeys.map(() => "?").join(",");
|
|
41
|
-
const rows = db
|
|
42
|
-
.prepare(`SELECT DISTINCT chunk_id FROM dedup_lsh_buckets
|
|
43
|
-
WHERE bucket_key IN (${placeholders}) AND session_id = ? AND chunk_id != ?
|
|
44
|
-
LIMIT ?`)
|
|
45
|
-
.all(...bucketKeys, sid, excludeChunkId, limit);
|
|
46
|
-
return rows.map((r) => r.chunk_id);
|
|
47
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Future-feature foundation: resume sessions, daily activity log, lessons learned.
|
|
3
|
-
*
|
|
4
|
-
* Scaffolded tables + minimal helpers so all store data lives in SQLite from
|
|
5
|
-
* day one. Full UI/recall for these lands in later sprints. All queries are
|
|
6
|
-
* parameterized (PREVENT-002).
|
|
7
|
-
*/
|
|
8
|
-
import { getStateDir, normalizeSessionId } from "../../store.js";
|
|
9
|
-
import { openStore } from "./connection.js";
|
|
10
|
-
/** Upsert a `sessions` row (resume + per-repo session history). */
|
|
11
|
-
export function touchSession(sessionId, repo, stateDir = getStateDir()) {
|
|
12
|
-
const db = openStore(stateDir);
|
|
13
|
-
const sid = normalizeSessionId(sessionId);
|
|
14
|
-
const existing = db
|
|
15
|
-
.prepare("SELECT started_at FROM sessions WHERE session_id = ?")
|
|
16
|
-
.get(sid);
|
|
17
|
-
const now = Math.floor(Date.now() / 1000);
|
|
18
|
-
if (!existing) {
|
|
19
|
-
db.prepare(`INSERT INTO sessions(session_id, repo, started_at, last_compacted_at, status)
|
|
20
|
-
VALUES(?, ?, ?, ?, 'active')`).run(sid, repo ?? null, now, now);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
db.prepare("UPDATE sessions SET last_compacted_at = ?, repo = COALESCE(?, repo), status = 'active' WHERE session_id = ?").run(now, repo ?? null, sid);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** Append a `daily_log` entry (day = YYYY-MM-DD, local-naive from Date). */
|
|
27
|
-
export function logDaily(sessionId, event, detail, tokensSaved, stateDir = getStateDir()) {
|
|
28
|
-
const db = openStore(stateDir);
|
|
29
|
-
const day = new Date().toISOString().slice(0, 10);
|
|
30
|
-
const now = Math.floor(Date.now() / 1000);
|
|
31
|
-
db.prepare(`INSERT INTO daily_log(day, session_id, event, detail, tokens_saved, ts)
|
|
32
|
-
VALUES(?, ?, ?, ?, ?, ?)`).run(day, normalizeSessionId(sessionId), event, detail ?? null, tokensSaved, now);
|
|
33
|
-
}
|
|
34
|
-
/** Append a `lessons` entry (future lessons-learned browse/recall). */
|
|
35
|
-
export function addLesson(sessionId, repo, lesson, stateDir = getStateDir()) {
|
|
36
|
-
const db = openStore(stateDir);
|
|
37
|
-
const now = Math.floor(Date.now() / 1000);
|
|
38
|
-
db.prepare(`INSERT INTO lessons(session_id, repo, lesson, ts) VALUES(?, ?, ?, ?)`).run(normalizeSessionId(sessionId), repo ?? null, lesson, now);
|
|
39
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transaction wrapper using SAVEPOINT so it nests safely under an outer
|
|
3
|
-
* transaction (unlike `BEGIN`, which SQLite rejects when one is already open).
|
|
4
|
-
*
|
|
5
|
-
* Mirrors better-sqlite3's `db.transaction(fn)` semantics — callers that wrap a
|
|
6
|
-
* batch in withTx (e.g. backfill) can still call helpers that also use withTx.
|
|
7
|
-
*/
|
|
8
|
-
export function withTx(db, fn) {
|
|
9
|
-
db.exec("SAVEPOINT mc_tx");
|
|
10
|
-
try {
|
|
11
|
-
fn();
|
|
12
|
-
db.exec("RELEASE mc_tx");
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
db.exec("ROLLBACK TO mc_tx");
|
|
16
|
-
db.exec("RELEASE mc_tx");
|
|
17
|
-
throw e;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vectorStore/add.ts — Add/insert operations: the dedup cascade and L1 lookup.
|
|
3
|
-
*/
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
import { cosineSimilarity } from "../embedder.js";
|
|
6
|
-
import { normalizeSessionId, compressSmart } from "../store.js";
|
|
7
|
-
import { computeContentDigest } from "../dedup/digest.js";
|
|
8
|
-
import { minhashSignature, SIGNATURE_VERSION, NUM_HASHES } from "../dedup/l1-minhash.js";
|
|
9
|
-
import { lshBands } from "../dedup/l1-lsh.js";
|
|
10
|
-
import { isNearDuplicate } from "../dedup/l1-verify.js";
|
|
11
|
-
import { openBloom, saveBloom } from "../store/bloom.js";
|
|
12
|
-
import { listCheckpoints, nextCheckpointId, upsertCheckpoint, loadSessionState, saveSessionState, upsertMinhashSignature, insertLshBuckets, lshCandidateChunks, bumpDedupStats, addTokensSaved, } from "../store/sqlite.js";
|
|
13
|
-
import { computeRegionHash, recordDecision } from "./utils.js";
|
|
14
|
-
/**
|
|
15
|
-
* L1 near-duplicate lookup: MinHash → LSH candidate retrieval → trigram verify.
|
|
16
|
-
* Returns the matching checkpoint or undefined. Bounded by a 100-candidate cap
|
|
17
|
-
* and a 20ms verify budget (QA #7/#15) so it never hangs a large session.
|
|
18
|
-
*/
|
|
19
|
-
export function findL1Duplicate(ctx, sessionId, regionText, all) {
|
|
20
|
-
if (all.length === 0)
|
|
21
|
-
return undefined;
|
|
22
|
-
const sig = minhashSignature(regionText);
|
|
23
|
-
if (sig.length !== NUM_HASHES)
|
|
24
|
-
return undefined;
|
|
25
|
-
const bands = lshBands(sig, sessionId, SIGNATURE_VERSION);
|
|
26
|
-
// Cheap candidate retrieval (single query, capped). Exclude nothing yet —
|
|
27
|
-
// the new checkpoint has no id, so pass a sentinel that never matches.
|
|
28
|
-
const candidateIds = lshCandidateChunks(bands, sessionId, "__new__", ctx.stateDir, 100);
|
|
29
|
-
if (candidateIds.length === 0)
|
|
30
|
-
return undefined;
|
|
31
|
-
const byId = new Map(all.map((cp) => [cp.checkpointId, cp]));
|
|
32
|
-
const VERIFY_BUDGET_MS = 20;
|
|
33
|
-
const start = Date.now();
|
|
34
|
-
for (const id of candidateIds) {
|
|
35
|
-
if (Date.now() - start > VERIFY_BUDGET_MS)
|
|
36
|
-
break; // QA #15: abort → "not dup"
|
|
37
|
-
const cand = byId.get(id);
|
|
38
|
-
if (!cand)
|
|
39
|
-
continue;
|
|
40
|
-
const candText = cand.normalizedText ?? cand.summary ?? "";
|
|
41
|
-
if (isNearDuplicate(regionText, candText))
|
|
42
|
-
return cand;
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Add a checkpoint. Dedup cascade:
|
|
48
|
-
* 1. regionHash exact match (legacy, backward-compat)
|
|
49
|
-
* 2. summaryHash exact match (new: catches same-topic incremental compactions)
|
|
50
|
-
* 3. content similarity ≥ dedupSim (catches near-identical summaries)
|
|
51
|
-
* 4. If none match → create new checkpoint
|
|
52
|
-
*/
|
|
53
|
-
export function addToStore(ctx, input) {
|
|
54
|
-
const t0 = Date.now();
|
|
55
|
-
const sessionId = normalizeSessionId(input.sessionId);
|
|
56
|
-
const regionHash = computeRegionHash(input.regionText);
|
|
57
|
-
const all = listCheckpoints(sessionId, ctx.stateDir);
|
|
58
|
-
// Honest "tokens saved" base for this region. For a deduped add the whole
|
|
59
|
-
// original region is discarded (nothing new stored); for a new checkpoint
|
|
60
|
-
// we persist (orig − stored). Falls back to stored when orig is unknown.
|
|
61
|
-
const origTokens = input.originalTokenEstimate ?? input.tokenEstimate ?? 0;
|
|
62
|
-
const cfg = ctx.cfg;
|
|
63
|
-
// Live per-tier progress hook (Phase 1). Sync + optional; fired at each tier
|
|
64
|
-
// so the UI can paint "L0 ✓ → L1 ✓ → L2 0.91 → stored" during a compaction.
|
|
65
|
-
const onTier = input.onTier;
|
|
66
|
-
// Tracks whether a tier matched while in MARK_ONLY (record-but-don't-collapse),
|
|
67
|
-
// and which tier.
|
|
68
|
-
let markOnly = null;
|
|
69
|
-
// 0. L0 content-hash dedup (Sprint 9) — catches identical content arriving
|
|
70
|
-
// under different regionText. Normalization handles case/whitespace/ANSI so
|
|
71
|
-
// variants collapse to one row. Dual-hash guards a single-hash collision.
|
|
72
|
-
// Sprint 10: bloom is the accelerator — a miss means "definitely new" and
|
|
73
|
-
// skips the scan; a hit is only a candidate, confirmed against `all` below.
|
|
74
|
-
// Gated by L0_ENABLED (Sprint 14). MARK_ONLY_L0 records the decision but
|
|
75
|
-
// does not collapse — the new region is still stored.
|
|
76
|
-
onTier?.({ tier: "L0", status: "scanning" });
|
|
77
|
-
const digest = computeContentDigest(input.regionText);
|
|
78
|
-
const bloom = openBloom(ctx.stateDir);
|
|
79
|
-
if (cfg.L0_ENABLED && bloom.maybeHas(digest.contentHash)) {
|
|
80
|
-
const contentMatch = all.find((cp) => cp.contentHash === digest.contentHash &&
|
|
81
|
-
cp.contentHash2 === digest.contentHash2);
|
|
82
|
-
if (contentMatch) {
|
|
83
|
-
if (cfg.MARK_ONLY_L0) {
|
|
84
|
-
markOnly = "L0"; // Record-but-don't-collapse: fall through.
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
contentMatch.timestamp = input.timestamp;
|
|
88
|
-
upsertCheckpoint(contentMatch, ctx.stateDir);
|
|
89
|
-
bumpDedupStats(true, ctx.stateDir);
|
|
90
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
91
|
-
addTokensSaved(origTokens, ctx.stateDir);
|
|
92
|
-
const r = { checkpoint: contentMatch, deduped: true, reason: "contentHash" };
|
|
93
|
-
recordDecision(ctx, "L0", "deduped", "contentHash", Date.now() - t0);
|
|
94
|
-
onTier?.({ tier: "L0", status: "deduped", detail: "contentHash" });
|
|
95
|
-
return r;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// 1. Legacy regionHash dedup (backward-compat) — part of L0 tier gating.
|
|
100
|
-
if (cfg.L0_ENABLED) {
|
|
101
|
-
const regionMatch = all.find((cp) => cp.regionHash === regionHash);
|
|
102
|
-
if (regionMatch) {
|
|
103
|
-
if (cfg.MARK_ONLY_L0) {
|
|
104
|
-
markOnly = "L0"; // fall through
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
bumpDedupStats(true, ctx.stateDir);
|
|
108
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
109
|
-
addTokensSaved(origTokens, ctx.stateDir);
|
|
110
|
-
const r = { checkpoint: regionMatch, deduped: true, reason: "regionHash" };
|
|
111
|
-
recordDecision(ctx, "L0", "deduped", "regionHash", Date.now() - t0);
|
|
112
|
-
onTier?.({ tier: "L0", status: "deduped", detail: "regionHash" });
|
|
113
|
-
return r;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// 2. SummaryHash dedup — catches same-topic incremental compactions.
|
|
118
|
-
// Full 64-hex SHA-256 (was 16-hex in Sprint 8 — collision-prone).
|
|
119
|
-
const summaryHash = input.topicSummary
|
|
120
|
-
? createHash("sha256").update(input.topicSummary).digest("hex")
|
|
121
|
-
: undefined;
|
|
122
|
-
if (summaryHash && cfg.L0_ENABLED) {
|
|
123
|
-
const summaryMatch = all.find((cp) => cp.summaryHash === summaryHash);
|
|
124
|
-
if (summaryMatch) {
|
|
125
|
-
if (cfg.MARK_ONLY_L0) {
|
|
126
|
-
markOnly = "L0"; // fall through
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
summaryMatch.timestamp = input.timestamp;
|
|
130
|
-
upsertCheckpoint(summaryMatch, ctx.stateDir);
|
|
131
|
-
bumpDedupStats(true, ctx.stateDir);
|
|
132
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
133
|
-
addTokensSaved(origTokens, ctx.stateDir);
|
|
134
|
-
const r = { checkpoint: summaryMatch, deduped: true, reason: "summaryHash" };
|
|
135
|
-
recordDecision(ctx, "L0", "deduped", "summaryHash", Date.now() - t0);
|
|
136
|
-
onTier?.({ tier: "L0", status: "deduped", detail: "summaryHash" });
|
|
137
|
-
return r;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// L0 did not collapse this region.
|
|
142
|
-
onTier?.({ tier: "L0", status: "passed" });
|
|
143
|
-
// 2b. L1 MinHash/LSH near-duplicate dedup (Sprint 11) — catches one-word
|
|
144
|
-
// edits / rewordings that L0's exact hash misses. Cheap LSH bucket
|
|
145
|
-
// retrieval → trigram verification (pg_trgm-equivalent) as the final gate.
|
|
146
|
-
// Gated by L1_ENABLED (Sprint 14); MARK_ONLY_L1 records but doesn't collapse.
|
|
147
|
-
onTier?.({ tier: "L1", status: "scanning" });
|
|
148
|
-
if (cfg.L1_ENABLED) {
|
|
149
|
-
const l1 = findL1Duplicate(ctx, sessionId, input.regionText, all);
|
|
150
|
-
if (l1 && !cfg.MARK_ONLY_L1) {
|
|
151
|
-
l1.timestamp = input.timestamp;
|
|
152
|
-
upsertCheckpoint(l1, ctx.stateDir);
|
|
153
|
-
bumpDedupStats(true, ctx.stateDir);
|
|
154
|
-
const r = { checkpoint: l1, deduped: true, reason: "l1MinHash" };
|
|
155
|
-
recordDecision(ctx, "L1", "deduped", "l1MinHash", Date.now() - t0);
|
|
156
|
-
onTier?.({ tier: "L1", status: "deduped", detail: "l1MinHash" });
|
|
157
|
-
return r;
|
|
158
|
-
}
|
|
159
|
-
if (l1 && cfg.MARK_ONLY_L1)
|
|
160
|
-
markOnly = "L1";
|
|
161
|
-
}
|
|
162
|
-
onTier?.({ tier: "L1", status: "passed" });
|
|
163
|
-
// 3. L2 semantic dedup — catches near-identical / semantically-similar regions
|
|
164
|
-
// via cosine over the embedding. topicSummary is used for summaryHash dedup
|
|
165
|
-
// (tier 2); the vector index is keyed on the original region for backward-
|
|
166
|
-
// compat search semantics. Threshold from cfg (L2_COSINE trigram honest
|
|
167
|
-
// firing point). QA #13 timeout guard: if the O(n) scan exceeds the budget,
|
|
168
|
-
// degrade to "store without dedup this pass" so we never lose a checkpoint.
|
|
169
|
-
// Gated by L2_ENABLED (Sprint 14); MARK_ONLY_L2 records but doesn't collapse.
|
|
170
|
-
const SIMILARITY_BUDGET_MS = cfg.SIMILARITY_BUDGET_MS;
|
|
171
|
-
const simThreshold = ctx.l2Threshold; // from cfg.L2_COSINE (default 0.85 trigram)
|
|
172
|
-
const embedding = ctx.embedder.embed(input.regionText);
|
|
173
|
-
onTier?.({ tier: "L2", status: "scanning" });
|
|
174
|
-
if (cfg.L2_ENABLED && all.length > 0) {
|
|
175
|
-
const start = Date.now();
|
|
176
|
-
let timedOut = false;
|
|
177
|
-
const nearest = all.reduce((best, cp) => {
|
|
178
|
-
if (!timedOut && Date.now() - start > SIMILARITY_BUDGET_MS)
|
|
179
|
-
timedOut = true;
|
|
180
|
-
if (timedOut)
|
|
181
|
-
return best;
|
|
182
|
-
const sim = cosineSimilarity(embedding, cp.embedding);
|
|
183
|
-
return sim > best.sim ? { checkpoint: cp, sim } : best;
|
|
184
|
-
}, { checkpoint: all[0], sim: -1 });
|
|
185
|
-
if (!timedOut && nearest.sim >= simThreshold) {
|
|
186
|
-
if (!cfg.MARK_ONLY_L2) {
|
|
187
|
-
// Near-identical — update timestamp on existing checkpoint
|
|
188
|
-
nearest.checkpoint.timestamp = input.timestamp;
|
|
189
|
-
upsertCheckpoint(nearest.checkpoint, ctx.stateDir);
|
|
190
|
-
bumpDedupStats(true, ctx.stateDir);
|
|
191
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
192
|
-
addTokensSaved(origTokens, ctx.stateDir);
|
|
193
|
-
const r = { checkpoint: nearest.checkpoint, deduped: true, reason: "contentSimilarity" };
|
|
194
|
-
recordDecision(ctx, "L2", "deduped", "contentSimilarity", Date.now() - t0);
|
|
195
|
-
onTier?.({ tier: "L2", status: "deduped", detail: nearest.sim.toFixed(2) });
|
|
196
|
-
return r;
|
|
197
|
-
}
|
|
198
|
-
markOnly = "L2";
|
|
199
|
-
}
|
|
200
|
-
onTier?.({ tier: "L2", status: "passed", detail: `best ${nearest.sim.toFixed(2)}` });
|
|
201
|
-
}
|
|
202
|
-
// 4. Genuinely new — create checkpoint
|
|
203
|
-
const checkpointId = nextCheckpointId(sessionId, ctx.stateDir);
|
|
204
|
-
const checkpoint = {
|
|
205
|
-
checkpointId,
|
|
206
|
-
sessionId,
|
|
207
|
-
summary: input.summary,
|
|
208
|
-
topicSummary: input.topicSummary,
|
|
209
|
-
summaryHash,
|
|
210
|
-
keyDecisions: input.keyDecisions ?? [],
|
|
211
|
-
nextSteps: input.nextSteps ?? [],
|
|
212
|
-
filesModified: input.filesModified ?? [],
|
|
213
|
-
tokenEstimate: input.tokenEstimate ?? 0,
|
|
214
|
-
originalTokenEstimate: input.originalTokenEstimate,
|
|
215
|
-
regionHash,
|
|
216
|
-
contentHash: digest.contentHash,
|
|
217
|
-
contentHash2: digest.contentHash2,
|
|
218
|
-
contentHashVersion: digest.contentHashVersion,
|
|
219
|
-
normalizedText: digest.normalizedText,
|
|
220
|
-
compressedOriginal: compressSmart(Buffer.from(input.regionText, "utf-8"), input.compressionPressure),
|
|
221
|
-
embedding,
|
|
222
|
-
timestamp: input.timestamp,
|
|
223
|
-
};
|
|
224
|
-
// Persistence is SQLite (store/sqlite.ts). upsertCheckpoint keeps the
|
|
225
|
-
// idempotent-by-id semantics the old JSON append implied.
|
|
226
|
-
upsertCheckpoint(checkpoint, ctx.stateDir);
|
|
227
|
-
// Cumulative "tokens saved" counter (per-repo SQLite meta). For a NEW
|
|
228
|
-
// checkpoint the saved amount is (original − stored); for a deduped add the
|
|
229
|
-
// whole original region is discarded (handled in the deduped return paths
|
|
230
|
-
// below). Survives sessions and travels with the repo.
|
|
231
|
-
const stored = input.tokenEstimate ?? 0;
|
|
232
|
-
addTokensSaved(Math.max(0, origTokens - stored), ctx.stateDir);
|
|
233
|
-
// L1: persist this checkpoint's MinHash signature + LSH buckets so future
|
|
234
|
-
// near-duplicate inserts can find it. Deterministic given the seed.
|
|
235
|
-
const sig = minhashSignature(input.regionText);
|
|
236
|
-
upsertMinhashSignature(checkpointId, sessionId, SIGNATURE_VERSION, sig, ctx.stateDir);
|
|
237
|
-
insertLshBuckets(checkpointId, sessionId, SIGNATURE_VERSION, lshBands(sig, sessionId, SIGNATURE_VERSION), ctx.stateDir);
|
|
238
|
-
// Bloom accelerator: record the new content_hash so a future add() can short-
|
|
239
|
-
// circuit the scan on a hit (still confirmed by the SELECT-based `all` above).
|
|
240
|
-
bloom.add(digest.contentHash);
|
|
241
|
-
saveBloom(ctx.stateDir);
|
|
242
|
-
// Track the region hash in session state for fast sentinel checks.
|
|
243
|
-
const state = loadSessionState(sessionId, ctx.stateDir);
|
|
244
|
-
if (!state.storedRegionHashes.includes(regionHash)) {
|
|
245
|
-
state.storedRegionHashes.push(regionHash);
|
|
246
|
-
saveSessionState(sessionId, state, ctx.stateDir);
|
|
247
|
-
}
|
|
248
|
-
// A new checkpoint. If a tier matched while MARK_ONLY, record that (the
|
|
249
|
-
// decision fired but we intentionally did not collapse).
|
|
250
|
-
if (markOnly) {
|
|
251
|
-
recordDecision(ctx, markOnly, "mark_only", "mark_only", Date.now() - t0);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
recordDecision(ctx, "L0", "new", undefined, Date.now() - t0);
|
|
255
|
-
}
|
|
256
|
-
// Cumulative store-wide dedup accounting (attempt, not collapsed).
|
|
257
|
-
bumpDedupStats(false, ctx.stateDir);
|
|
258
|
-
onTier?.({ tier: "new", status: "stored" });
|
|
259
|
-
return { checkpoint, deduped: false };
|
|
260
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vectorStore/dedup.ts — SemDeDup cleanup and dedup sentinel check.
|
|
3
|
-
*/
|
|
4
|
-
import { cosineSimilarity } from "../embedder.js";
|
|
5
|
-
import { normalizeSessionId } from "../store.js";
|
|
6
|
-
import { listCheckpoints, setDedupStatus, loadSessionState } from "../store/sqlite.js";
|
|
7
|
-
import { computeRegionHash } from "./utils.js";
|
|
8
|
-
/**
|
|
9
|
-
* SemDeDup offline cleanup (Sprint 12, QA #17): within a session, mark the
|
|
10
|
-
* lower-quality row of any pair scoring cosine > `threshold` as
|
|
11
|
-
* `dedup_status='removed'` (kept, not deleted — retrieval excludes it). Keeps
|
|
12
|
-
* the row with the higher `tokenEstimate` (more context preserved). Runs as a
|
|
13
|
-
* single scan; idempotent (re-running skips already-removed rows).
|
|
14
|
-
*
|
|
15
|
-
* Returns the number of rows marked removed.
|
|
16
|
-
*/
|
|
17
|
-
export function semDedupStore(ctx, sessionId, threshold) {
|
|
18
|
-
const sid = normalizeSessionId(sessionId);
|
|
19
|
-
const cps = listCheckpoints(sid, ctx.stateDir).filter((c) => c.dedupStatus !== "removed");
|
|
20
|
-
let removed = 0;
|
|
21
|
-
for (let i = 0; i < cps.length; i++) {
|
|
22
|
-
for (let j = i + 1; j < cps.length; j++) {
|
|
23
|
-
const a = cps[i];
|
|
24
|
-
const b = cps[j];
|
|
25
|
-
if (a.dedupStatus === "removed" || b.dedupStatus === "removed")
|
|
26
|
-
continue;
|
|
27
|
-
if (cosineSimilarity(a.embedding, b.embedding) > threshold) {
|
|
28
|
-
// Keep the higher-tokenEstimate row; remove the other.
|
|
29
|
-
const keep = a.tokenEstimate >= b.tokenEstimate ? a : b;
|
|
30
|
-
const drop = keep === a ? b : a;
|
|
31
|
-
setDedupStatus(drop.checkpointId, sid, "removed", ctx.stateDir);
|
|
32
|
-
drop.dedupStatus = "removed";
|
|
33
|
-
removed++;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return removed;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Dedup sentinel check: has this region already been stored/represented?
|
|
41
|
-
* Consulted by both the persist path and the recall/inline path.
|
|
42
|
-
*/
|
|
43
|
-
export function dedupeCheck(ctx, sessionId, regionHashOrText, isText = false) {
|
|
44
|
-
const sid = normalizeSessionId(sessionId);
|
|
45
|
-
const hash = isText
|
|
46
|
-
? computeRegionHash(regionHashOrText)
|
|
47
|
-
: regionHashOrText;
|
|
48
|
-
const state = loadSessionState(sid, ctx.stateDir);
|
|
49
|
-
if (state.storedRegionHashes.includes(hash))
|
|
50
|
-
return true;
|
|
51
|
-
return listCheckpoints(sid, ctx.stateDir).some((c) => c.regionHash === hash);
|
|
52
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vectorStore/index.ts — Barrel re-export for the vector store sub-modules.
|
|
3
|
-
*
|
|
4
|
-
* All public symbols previously exported from the monolithic `vectorStore.ts`
|
|
5
|
-
* are re-exported here so existing imports (`from "./vectorStore.js"`) continue
|
|
6
|
-
* to work unchanged.
|
|
7
|
-
*/
|
|
8
|
-
export { L2_ENABLED } from "./types.js";
|
|
9
|
-
export { computeRegionHash } from "./utils.js";
|
|
10
|
-
export { VectorStore } from "./store.js";
|