@phren/cli 0.1.39 → 0.1.41
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/auth/profiles.js +59 -5
- package/dist/cli/actions.js +11 -3
- package/dist/cli/config-access.js +8 -1
- package/dist/cli/extract.d.ts +27 -1
- package/dist/cli/extract.js +243 -9
- package/dist/cli/govern.js +6 -87
- package/dist/cli/hooks-context.d.ts +1 -1
- package/dist/cli/hooks-context.js +1 -1
- package/dist/cli/namespaces-review.js +14 -1
- package/dist/cli/session-background.js +4 -0
- package/dist/cli/session-git.d.ts +18 -0
- package/dist/cli/session-git.js +47 -0
- package/dist/cli/session-start.js +2 -2
- package/dist/cli/session-stop.d.ts +11 -0
- package/dist/cli/session-stop.js +157 -33
- package/dist/cli/session-tool-hook.js +17 -5
- package/dist/cli-handlers.d.ts +2 -0
- package/dist/cli-handlers.js +40 -0
- package/dist/cli-registry.d.ts +1 -1
- package/dist/cli-registry.js +16 -1
- package/dist/content/dedup.d.ts +1 -4
- package/dist/content/dedup.js +7 -63
- package/dist/content/learning.d.ts +20 -2
- package/dist/content/learning.js +21 -3
- package/dist/content/quality.d.ts +23 -0
- package/dist/content/quality.js +123 -0
- package/dist/content/secrets.d.ts +52 -0
- package/dist/content/secrets.js +193 -0
- package/dist/data/access.d.ts +56 -2
- package/dist/data/access.js +246 -24
- package/dist/entrypoint.js +5 -1
- package/dist/finding/impact.js +170 -43
- package/dist/finding/lifecycle.d.ts +19 -2
- package/dist/finding/lifecycle.js +15 -3
- package/dist/git-worktree.d.ts +19 -0
- package/dist/git-worktree.js +117 -0
- package/dist/governance/policy.d.ts +84 -4
- package/dist/governance/policy.js +209 -14
- package/dist/governance/rbac.d.ts +8 -0
- package/dist/governance/rbac.js +26 -0
- package/dist/hooks.d.ts +26 -0
- package/dist/hooks.js +119 -6
- package/dist/index.js +5 -1
- package/dist/init/guard-globals.d.ts +20 -0
- package/dist/init/guard-globals.js +72 -6
- package/dist/init/init-configure.d.ts +7 -2
- package/dist/init/init-configure.js +42 -16
- package/dist/init/init-preset.d.ts +3 -0
- package/dist/init/init-preset.js +122 -0
- package/dist/init/init-uninstall.js +9 -0
- package/dist/init/init-walkthrough.d.ts +2 -0
- package/dist/init/init-walkthrough.js +42 -17
- package/dist/init/init.d.ts +5 -0
- package/dist/init/init.js +71 -19
- package/dist/init/management-preset.d.ts +42 -0
- package/dist/init/management-preset.js +122 -0
- package/dist/init/preferences.d.ts +17 -0
- package/dist/init/preferences.js +3 -0
- package/dist/init/self-wiring.d.ts +5 -0
- package/dist/init/self-wiring.js +52 -0
- package/dist/init/setup.d.ts +9 -4
- package/dist/init/setup.js +139 -23
- package/dist/init/store-gitignore.d.ts +29 -0
- package/dist/init/store-gitignore.js +48 -0
- package/dist/init/teardown.d.ts +15 -0
- package/dist/init/teardown.js +241 -0
- package/dist/link/doctor.js +127 -34
- package/dist/link/link.js +49 -26
- package/dist/phren-core.d.ts +35 -8
- package/dist/phren-core.js +35 -8
- package/dist/phren-paths.d.ts +90 -1
- package/dist/phren-paths.js +150 -5
- package/dist/proactivity.js +1 -1
- package/dist/shared/embedding-cache.d.ts +16 -0
- package/dist/shared/embedding-cache.js +24 -0
- package/dist/shared/fragment-graph.js +10 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.js +523 -138
- package/dist/shared/ollama.d.ts +14 -2
- package/dist/shared/ollama.js +84 -5
- package/dist/shared/retrieval.d.ts +22 -1
- package/dist/shared/retrieval.js +30 -1
- package/dist/shared/search-fallback.js +15 -3
- package/dist/shared/vector-index.d.ts +20 -1
- package/dist/shared/vector-index.js +18 -4
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +1 -1
- package/dist/status.js +31 -2
- package/dist/store-registry.d.ts +22 -0
- package/dist/store-registry.js +36 -3
- package/dist/task/lifecycle.js +31 -0
- package/dist/tools/config.js +16 -7
- package/dist/tools/data.js +1 -1
- package/dist/tools/extract.js +2 -2
- package/dist/tools/finding.js +14 -3
- package/dist/tools/graph.js +9 -1
- package/dist/tools/memory.js +1 -1
- package/dist/tools/notes.js +3 -3
- package/dist/tools/ops.js +19 -18
- package/dist/tools/search.js +2 -2
- package/dist/tools/session.js +2 -2
- package/dist/tools/tasks.js +2 -2
- package/dist/tools/types.d.ts +32 -2
- package/dist/tools/types.js +41 -8
- package/dist/ui/scripts.js +2 -2
- package/dist/ui/server.js +5 -0
- package/package.json +1 -1
- package/dist/cli-hooks-git.d.ts +0 -50
- package/dist/cli-hooks-git.js +0 -288
- package/starter/my-api/.claude/skills/README.md +0 -7
- package/starter/my-api/CLAUDE.md +0 -33
- package/starter/my-api/FINDINGS.md +0 -9
- package/starter/my-api/summary.md +0 -7
- package/starter/my-api/tasks.md +0 -7
- package/starter/my-first-project/.claude/skills/README.md +0 -7
- package/starter/my-first-project/CLAUDE.md +0 -49
- package/starter/my-first-project/FINDINGS.md +0 -24
- package/starter/my-first-project/summary.md +0 -11
- package/starter/my-first-project/tasks.md +0 -25
- package/starter/my-frontend/.claude/skills/README.md +0 -7
- package/starter/my-frontend/CLAUDE.md +0 -33
- package/starter/my-frontend/FINDINGS.md +0 -9
- package/starter/my-frontend/summary.md +0 -7
- package/starter/my-frontend/tasks.md +0 -7
package/dist/phren-paths.js
CHANGED
|
@@ -32,11 +32,16 @@ export function defaultPhrenPath() {
|
|
|
32
32
|
export function rootManifestPath(phrenPath) {
|
|
33
33
|
return path.join(phrenPath, ROOT_MANIFEST_FILENAME);
|
|
34
34
|
}
|
|
35
|
-
export function atomicWriteText(filePath, content) {
|
|
35
|
+
export function atomicWriteText(filePath, content, opts = {}) {
|
|
36
36
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
37
37
|
const tmpPath = `${filePath}.tmp-${crypto.randomUUID()}`;
|
|
38
|
-
fs.writeFileSync(tmpPath, content);
|
|
38
|
+
fs.writeFileSync(tmpPath, content, opts.mode !== undefined ? { mode: opts.mode } : undefined);
|
|
39
39
|
try {
|
|
40
|
+
// writeFileSync's mode is masked by umask, so re-assert it explicitly. The
|
|
41
|
+
// temp name is unguessable and freshly created, so this happens before any
|
|
42
|
+
// other process can have the file open under its final name.
|
|
43
|
+
if (opts.mode !== undefined && process.platform !== "win32")
|
|
44
|
+
fs.chmodSync(tmpPath, opts.mode);
|
|
40
45
|
fs.renameSync(tmpPath, filePath);
|
|
41
46
|
}
|
|
42
47
|
catch (err) {
|
|
@@ -47,6 +52,37 @@ export function atomicWriteText(filePath, content) {
|
|
|
47
52
|
throw err;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Create (or tighten) a directory that holds per-user private data — runtime
|
|
57
|
+
* logs, session transcripts, credential stores.
|
|
58
|
+
*
|
|
59
|
+
* Plain `fs.mkdirSync(dir, { recursive: true })` yields 0755 under the stock
|
|
60
|
+
* 0022 umask, which makes every file inside world-listable and world-readable
|
|
61
|
+
* on a shared machine. Passing `mode` to mkdirSync is not enough on its own:
|
|
62
|
+
* mkdirSync's mode applies only to directories it actually *creates*, so a
|
|
63
|
+
* directory that some earlier code path already made at 0755 keeps that mode
|
|
64
|
+
* forever. That is not hypothetical — `runtimeFile()` created `~/.phren/.runtime`
|
|
65
|
+
* with no mode long before `auth/profiles.ts` ever asked for 0700, so the
|
|
66
|
+
* credential directory shipped world-readable in practice.
|
|
67
|
+
*
|
|
68
|
+
* Only ever narrows: if the directory is already 0700 or tighter it is left
|
|
69
|
+
* alone. Best-effort — a chmod failure (foreign filesystem, Windows) must not
|
|
70
|
+
* break the caller, since the directory itself is usable either way.
|
|
71
|
+
*/
|
|
72
|
+
export function ensurePrivateDir(dir) {
|
|
73
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
+
if (process.platform === "win32")
|
|
75
|
+
return dir;
|
|
76
|
+
try {
|
|
77
|
+
const current = fs.statSync(dir).mode & 0o777;
|
|
78
|
+
if ((current & 0o077) !== 0)
|
|
79
|
+
fs.chmodSync(dir, 0o700);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// best-effort hardening; the directory is still usable
|
|
83
|
+
}
|
|
84
|
+
return dir;
|
|
85
|
+
}
|
|
50
86
|
export function isInstallMode(value) {
|
|
51
87
|
return value === "shared" || value === "project-local";
|
|
52
88
|
}
|
|
@@ -238,15 +274,75 @@ export function tryUnlink(filePath) {
|
|
|
238
274
|
export function sessionsDir(phrenPath) {
|
|
239
275
|
return path.join(phrenPath, ".sessions");
|
|
240
276
|
}
|
|
277
|
+
// `.runtime` holds debug.log, hook-errors.log, memory-usage.log,
|
|
278
|
+
// lookup-events.jsonl and the auth profile store — i.e. verbatim knowledge-base
|
|
279
|
+
// content plus plaintext API keys. It is per-user runtime state, never shared,
|
|
280
|
+
// so it gets 0700. Because ensurePrivateDir also tightens a directory that
|
|
281
|
+
// already exists, this repairs the 0755 `.runtime` that shipped installs have.
|
|
241
282
|
const runtimeDirsMade = new Set();
|
|
242
283
|
export function runtimeFile(phrenPath, name) {
|
|
243
284
|
const dir = runtimeDir(phrenPath);
|
|
244
285
|
if (!runtimeDirsMade.has(dir)) {
|
|
245
|
-
|
|
286
|
+
ensurePrivateDir(dir);
|
|
246
287
|
runtimeDirsMade.add(dir);
|
|
247
288
|
}
|
|
248
289
|
return path.join(dir, name);
|
|
249
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Per-user root for the FTS snapshot cache: `os.tmpdir()/phren-fts-<uid>`.
|
|
293
|
+
*
|
|
294
|
+
* Canonical definition of the path lives here, with every other phren path
|
|
295
|
+
* helper. `shared/index.ts` currently has its own private copy — see
|
|
296
|
+
* ensureFtsCacheRootPrivate() for why that matters and what still needs to
|
|
297
|
+
* change there.
|
|
298
|
+
*/
|
|
299
|
+
export function ftsCacheRoot() {
|
|
300
|
+
let userSuffix;
|
|
301
|
+
try {
|
|
302
|
+
userSuffix = String(os.userInfo().uid);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
userSuffix = crypto.createHash("sha1").update(homeDir()).digest("hex").slice(0, 12);
|
|
306
|
+
}
|
|
307
|
+
return path.join(os.tmpdir(), `phren-fts-${userSuffix}`);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Make the FTS snapshot cache root private, creating it if needed.
|
|
311
|
+
*
|
|
312
|
+
* The snapshot is a SQLite export of the *entire* indexed store — the full
|
|
313
|
+
* text of every finding, note, task and reference doc. It was being written
|
|
314
|
+
* as an 0644 file inside an 0755 directory:
|
|
315
|
+
*
|
|
316
|
+
* drwxr-xr-x $TMPDIR/phren-fts-501
|
|
317
|
+
* -rw-r--r-- $TMPDIR/phren-fts-501/<storeKey>/<hash>.db
|
|
318
|
+
*
|
|
319
|
+
* On macOS `os.tmpdir()` is a per-user `/var/folders/…/T` at 0700, which is
|
|
320
|
+
* the only reason this is not already a leak there. On Linux and WSL
|
|
321
|
+
* `os.tmpdir()` is `/tmp` — mode 1777, world-readable — so any local account
|
|
322
|
+
* can read another user's whole knowledge base. phren ships cross-platform on
|
|
323
|
+
* npm, so that is a live exposure, not a theoretical one.
|
|
324
|
+
*
|
|
325
|
+
* A 0700 root closes it completely: POSIX denies traversal into the directory,
|
|
326
|
+
* so the modes of the per-store subdirectory and the .db files inside it stop
|
|
327
|
+
* being reachable at all. Called once per process from the CLI and MCP-server
|
|
328
|
+
* entrypoints, which both creates it correctly on a clean machine and repairs
|
|
329
|
+
* the 0755 root on machines that already have one.
|
|
330
|
+
*
|
|
331
|
+
* Still worth doing for defence in depth, in the file that actually writes
|
|
332
|
+
* them: `shared/index.ts` should pass `{ recursive: true, mode: 0o700 }` to
|
|
333
|
+
* the `fs.mkdirSync(cacheDir, …)` calls and `{ mode: 0o600 }` to the
|
|
334
|
+
* `fs.writeFileSync(cacheFile, db.export())` calls. That file is owned by
|
|
335
|
+
* another change in flight, so it is reported rather than edited here.
|
|
336
|
+
*/
|
|
337
|
+
export function ensureFtsCacheRootPrivate() {
|
|
338
|
+
try {
|
|
339
|
+
return ensurePrivateDir(ftsCacheRoot());
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
// Never let cache hardening break startup; the cache itself is optional.
|
|
343
|
+
return ftsCacheRoot();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
250
346
|
export function installPreferencesFile(phrenPath) {
|
|
251
347
|
return path.join(runtimeDir(phrenPath), "install-preferences.json");
|
|
252
348
|
}
|
|
@@ -273,9 +369,10 @@ export function memoryUsageLogFile(phrenPath) {
|
|
|
273
369
|
export function lookupEventsLogFile(phrenPath) {
|
|
274
370
|
return path.join(runtimeDir(phrenPath), "lookup-events.jsonl");
|
|
275
371
|
}
|
|
372
|
+
// `.sessions` holds session transcripts and per-session message artifacts —
|
|
373
|
+
// raw conversation content. Same treatment as `.runtime`.
|
|
276
374
|
export function sessionMarker(phrenPath, name) {
|
|
277
|
-
const dir = sessionsDir(phrenPath);
|
|
278
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
375
|
+
const dir = ensurePrivateDir(sessionsDir(phrenPath));
|
|
279
376
|
return path.join(dir, name);
|
|
280
377
|
}
|
|
281
378
|
// Debug logging is best-effort and only writes when a phren root already exists.
|
|
@@ -371,6 +468,30 @@ export function listInvalidProjectDirs(phrenPath) {
|
|
|
371
468
|
export function normalizeProjectNameForCreate(name) {
|
|
372
469
|
return name.trim().toLowerCase();
|
|
373
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* The single source of truth for turning a source directory into a project
|
|
473
|
+
* slug. Previously copy-pasted at five call sites, which is how the same repo
|
|
474
|
+
* could end up registered twice under near-identical names.
|
|
475
|
+
*
|
|
476
|
+
* Runs of non-slug characters collapse to one hyphen and leading/trailing
|
|
477
|
+
* hyphens are trimmed, so `My.App`, `My..App` and `My App` all yield `my-app`
|
|
478
|
+
* instead of the old `my-app` / `my--app` / `my-app` split.
|
|
479
|
+
*/
|
|
480
|
+
export function projectSlugFromPath(sourcePath) {
|
|
481
|
+
return path.basename(path.resolve(sourcePath))
|
|
482
|
+
.toLowerCase()
|
|
483
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
484
|
+
.replace(/^-+|-+$/g, "");
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Collapse a project name to the key used for duplicate detection: lowercase
|
|
488
|
+
* with every separator removed. `Max4LivePlugins`, `max4liveplugins` and
|
|
489
|
+
* `max4live-plugins` all map to `max4liveplugins`, so the second spelling of a
|
|
490
|
+
* repo can be recognized as the project that already exists.
|
|
491
|
+
*/
|
|
492
|
+
export function canonicalProjectKey(name) {
|
|
493
|
+
return name.trim().toLowerCase().replace(/[\s_-]+/g, "");
|
|
494
|
+
}
|
|
374
495
|
export function findProjectNameCaseInsensitive(phrenPath, name) {
|
|
375
496
|
const needle = name.toLowerCase();
|
|
376
497
|
try {
|
|
@@ -387,6 +508,30 @@ export function findProjectNameCaseInsensitive(phrenPath, name) {
|
|
|
387
508
|
}
|
|
388
509
|
return null;
|
|
389
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Existing project directories whose name canonicalizes to the same key as
|
|
513
|
+
* `name` (see {@link canonicalProjectKey}). Exact matches are returned first so
|
|
514
|
+
* callers can prefer them.
|
|
515
|
+
*/
|
|
516
|
+
export function findProjectNamesByCanonicalKey(phrenPath, name) {
|
|
517
|
+
const needle = canonicalProjectKey(name);
|
|
518
|
+
if (!needle)
|
|
519
|
+
return [];
|
|
520
|
+
const matches = [];
|
|
521
|
+
try {
|
|
522
|
+
for (const entry of fs.readdirSync(phrenPath, { withFileTypes: true })) {
|
|
523
|
+
if (!isProjectDirEntry(entry))
|
|
524
|
+
continue;
|
|
525
|
+
if (canonicalProjectKey(entry.name) === needle)
|
|
526
|
+
matches.push(entry.name);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
catch (err) {
|
|
530
|
+
if ((process.env.PHREN_DEBUG))
|
|
531
|
+
stderrLog(`findProjectNamesByCanonicalKey: ${errorMessage(err)}`);
|
|
532
|
+
}
|
|
533
|
+
return matches.sort((a, b) => (a === name ? -1 : b === name ? 1 : a.localeCompare(b)));
|
|
534
|
+
}
|
|
390
535
|
export function findArchivedProjectNameCaseInsensitive(phrenPath, name) {
|
|
391
536
|
const needle = name.toLowerCase();
|
|
392
537
|
try {
|
package/dist/proactivity.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getWorkflowPolicy } from "./governance/policy.js";
|
|
|
7
7
|
export const PROACTIVITY_LEVELS = ["high", "medium", "low"];
|
|
8
8
|
const DEFAULT_PROACTIVITY_LEVEL = "high";
|
|
9
9
|
const EXPLICIT_FINDING_SIGNAL_PATTERN = /\b(add finding|worth remembering)\b/i;
|
|
10
|
-
const EXPLICIT_FINDING_TAG_PATTERN = /\[(pitfall|decision|pattern|
|
|
10
|
+
const EXPLICIT_FINDING_TAG_PATTERN = /\[(pitfall|decision|pattern|bug|workaround|context)\]/i;
|
|
11
11
|
const EXPLICIT_TASK_SIGNAL_PATTERN = /\b(?:add(?:\s+(?:this|that|it))?\s+(?:to\s+(?:the\s+)?)?(?:task|todo(?:\s+list)?|task(?:\s+list)?)|add\s+(?:a\s+)?task|put(?:\s+(?:this|that|it))?\s+(?:in|on)\s+(?:the\s+)?(?:task|todo(?:\s+list)?|task(?:\s+list)?))\b/i;
|
|
12
12
|
export function parseProactivityLevel(raw) {
|
|
13
13
|
if (!raw)
|
|
@@ -6,14 +6,30 @@ export interface EmbeddingCoverage {
|
|
|
6
6
|
missingPct: number;
|
|
7
7
|
state: "empty" | "cold" | "warming" | "warm";
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* `[mtimeMs, size]` of the embeddings.json the in-memory map was last built
|
|
11
|
+
* from. Derived caches (the LSH vector index) stamp *this*, not a fresh stat of
|
|
12
|
+
* the file, so an index can never claim to describe bytes it never saw.
|
|
13
|
+
*/
|
|
14
|
+
export interface EmbeddingSourceMarker {
|
|
15
|
+
mtimeMs: number;
|
|
16
|
+
size: number;
|
|
17
|
+
}
|
|
9
18
|
export declare class EmbeddingCache {
|
|
10
19
|
private phrenPath;
|
|
11
20
|
private cache;
|
|
12
21
|
private dirty;
|
|
13
22
|
private dirtyUpserts;
|
|
14
23
|
private dirtyDeletes;
|
|
24
|
+
private source;
|
|
15
25
|
constructor(phrenPath: string);
|
|
16
26
|
load(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Marker for the embeddings.json revision this in-memory map reflects, or
|
|
29
|
+
* null when it was never loaded from a file. Pass it to anything that
|
|
30
|
+
* persists a derived view of `getAllEntries()`.
|
|
31
|
+
*/
|
|
32
|
+
sourceMarker(): EmbeddingSourceMarker | null;
|
|
17
33
|
get(docPath: string, model: string): number[] | null;
|
|
18
34
|
set(docPath: string, model: string, vec: number[]): void;
|
|
19
35
|
delete(docPath: string): void;
|
|
@@ -3,6 +3,15 @@ import * as crypto from "crypto";
|
|
|
3
3
|
import { runtimeFile, debugLog } from "../shared.js";
|
|
4
4
|
import { withFileLock } from "./governance.js";
|
|
5
5
|
import { errorMessage } from "../utils.js";
|
|
6
|
+
function statSourceMarker(filePath) {
|
|
7
|
+
try {
|
|
8
|
+
const stat = fs.statSync(filePath);
|
|
9
|
+
return { mtimeMs: stat.mtimeMs, size: stat.size };
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
6
15
|
function isEmbeddingEntry(value) {
|
|
7
16
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
8
17
|
return false;
|
|
@@ -31,6 +40,7 @@ export class EmbeddingCache {
|
|
|
31
40
|
dirty = false;
|
|
32
41
|
dirtyUpserts = new Set();
|
|
33
42
|
dirtyDeletes = new Set();
|
|
43
|
+
source = null;
|
|
34
44
|
constructor(phrenPath) {
|
|
35
45
|
this.phrenPath = phrenPath;
|
|
36
46
|
}
|
|
@@ -38,20 +48,33 @@ export class EmbeddingCache {
|
|
|
38
48
|
if (this.dirty)
|
|
39
49
|
return;
|
|
40
50
|
const filePath = runtimeFile(this.phrenPath, "embeddings.json");
|
|
51
|
+
// Stat before the read: if the file is rewritten mid-read, the recorded
|
|
52
|
+
// marker is the older one, so derived caches report stale rather than fresh.
|
|
53
|
+
const marker = statSourceMarker(filePath);
|
|
41
54
|
try {
|
|
42
55
|
const data = readEmbeddingMapFromDisk(filePath);
|
|
43
56
|
this.cache = new Map(Object.entries(data));
|
|
57
|
+
this.source = marker;
|
|
44
58
|
debugLog(`EmbeddingCache loaded: ${this.cache.size} entries`);
|
|
45
59
|
}
|
|
46
60
|
catch (err) {
|
|
47
61
|
const code = err instanceof Error && "code" in err ? String(err.code ?? "") : "";
|
|
48
62
|
if (code === "ENOENT") {
|
|
49
63
|
this.cache.clear();
|
|
64
|
+
this.source = null;
|
|
50
65
|
return;
|
|
51
66
|
}
|
|
52
67
|
debugLog(`EmbeddingCache load failed for ${filePath}: ${errorMessage(err)}`);
|
|
53
68
|
}
|
|
54
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Marker for the embeddings.json revision this in-memory map reflects, or
|
|
72
|
+
* null when it was never loaded from a file. Pass it to anything that
|
|
73
|
+
* persists a derived view of `getAllEntries()`.
|
|
74
|
+
*/
|
|
75
|
+
sourceMarker() {
|
|
76
|
+
return this.source;
|
|
77
|
+
}
|
|
55
78
|
get(docPath, model) {
|
|
56
79
|
const entry = this.cache.get(docPath);
|
|
57
80
|
if (!entry || entry.model !== model)
|
|
@@ -95,6 +118,7 @@ export class EmbeddingCache {
|
|
|
95
118
|
fs.writeFileSync(tmp, JSON.stringify(data));
|
|
96
119
|
fs.renameSync(tmp, filePath);
|
|
97
120
|
this.cache = new Map(Object.entries(data));
|
|
121
|
+
this.source = statSourceMarker(filePath);
|
|
98
122
|
});
|
|
99
123
|
this.dirty = false;
|
|
100
124
|
this.dirtyUpserts.clear();
|
|
@@ -4,6 +4,16 @@ import { runtimeFile } from "../shared.js";
|
|
|
4
4
|
import { logger } from "../logger.js";
|
|
5
5
|
import { UNIVERSAL_TECH_TERMS_RE } from "../phren-core.js";
|
|
6
6
|
import { errorMessage } from "../utils.js";
|
|
7
|
+
// NOTE on naming: "entity" was renamed to "fragment" everywhere user-facing
|
|
8
|
+
// (CHANGELOG 0.0.5) — tool names, titles, and descriptions in tools/graph.ts
|
|
9
|
+
// all say "fragment" now. The underlying SQLite tables (`entities`,
|
|
10
|
+
// `entity_links`, `global_entities`, created in shared/index.ts) and the
|
|
11
|
+
// on-disk `.runtime/manual-links.json` format (`{entity, entityType, ...}`)
|
|
12
|
+
// were never renamed to match. Both are effectively rebuilt/local-runtime
|
|
13
|
+
// state rather than synced source-of-truth files, so a rename would not need
|
|
14
|
+
// a store migration in the git-history sense, but it does require touching
|
|
15
|
+
// shared/index.ts (which creates the tables and reads manual-links.json) —
|
|
16
|
+
// out of scope for a change confined to this file.
|
|
7
17
|
/** @internal Exported for tests. */
|
|
8
18
|
export function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
|
|
9
19
|
/** Escape SQL LIKE wildcard characters so user input is treated literally.
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ export declare function normalizeIndexedContent(content: string, type: string, p
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function updateFileInIndex(db: SqlJsDatabase, filePath: string, phrenPath: string): void;
|
|
25
25
|
export declare function buildIndex(phrenPath: string, profile?: string): Promise<SqlJsDatabase>;
|
|
26
|
+
/**
|
|
27
|
+
* @internal Exported for tests. The prune is a one-shot per process, so a test
|
|
28
|
+
* that needs to set up state *after* a build (which consumes it) has no other
|
|
29
|
+
* way to exercise the pruning logic a second time.
|
|
30
|
+
*/
|
|
31
|
+
export declare function __resetFtsCachePruneGuardForTests(): void;
|
|
26
32
|
/**
|
|
27
33
|
* Non-blocking index loader for the UserPromptSubmit / PostToolUse hooks.
|
|
28
34
|
* Unlike buildIndex(), this NEVER blocks a hook on a 2-12s rebuild:
|