agent-recall-core 3.4.46 → 3.4.48
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/helpers/handoff.d.ts.map +1 -1
- package/dist/helpers/handoff.js +17 -9
- package/dist/helpers/handoff.js.map +1 -1
- package/dist/helpers/journal-files.d.ts +24 -1
- package/dist/helpers/journal-files.d.ts.map +1 -1
- package/dist/helpers/journal-files.js +29 -10
- package/dist/helpers/journal-files.js.map +1 -1
- package/dist/helpers/journal-filter.d.ts +25 -0
- package/dist/helpers/journal-filter.d.ts.map +1 -1
- package/dist/helpers/journal-filter.js +12 -1
- package/dist/helpers/journal-filter.js.map +1 -1
- package/dist/index.d.ts +18 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -6
- package/dist/index.js.map +1 -1
- package/dist/retrieval/candidates.d.ts +339 -0
- package/dist/retrieval/candidates.d.ts.map +1 -0
- package/dist/retrieval/candidates.js +473 -0
- package/dist/retrieval/candidates.js.map +1 -0
- package/dist/retrieval/contradiction.d.ts +284 -0
- package/dist/retrieval/contradiction.d.ts.map +1 -0
- package/dist/retrieval/contradiction.js +343 -0
- package/dist/retrieval/contradiction.js.map +1 -0
- package/dist/retrieval/query-memory.d.ts +464 -0
- package/dist/retrieval/query-memory.d.ts.map +1 -0
- package/dist/retrieval/query-memory.js +1189 -0
- package/dist/retrieval/query-memory.js.map +1 -0
- package/dist/retrieval/scope.d.ts +75 -0
- package/dist/retrieval/scope.d.ts.map +1 -0
- package/dist/retrieval/scope.js +91 -0
- package/dist/retrieval/scope.js.map +1 -0
- package/dist/storage/corrections.d.ts +163 -2
- package/dist/storage/corrections.d.ts.map +1 -1
- package/dist/storage/corrections.js +147 -3
- package/dist/storage/corrections.js.map +1 -1
- package/dist/storage/lifecycle-telemetry.d.ts +20 -5
- package/dist/storage/lifecycle-telemetry.d.ts.map +1 -1
- package/dist/storage/lifecycle-telemetry.js +16 -5
- package/dist/storage/lifecycle-telemetry.js.map +1 -1
- package/dist/storage/session.d.ts +28 -1
- package/dist/storage/session.d.ts.map +1 -1
- package/dist/storage/session.js +41 -8
- package/dist/storage/session.js.map +1 -1
- package/dist/supabase/recall-backend.d.ts +26 -2
- package/dist/supabase/recall-backend.d.ts.map +1 -1
- package/dist/supabase/recall-backend.js +233 -27
- package/dist/supabase/recall-backend.js.map +1 -1
- package/dist/supabase/sync.d.ts +41 -0
- package/dist/supabase/sync.d.ts.map +1 -1
- package/dist/supabase/sync.js +46 -0
- package/dist/supabase/sync.js.map +1 -1
- package/dist/tools-logic/check.d.ts.map +1 -1
- package/dist/tools-logic/check.js +62 -36
- package/dist/tools-logic/check.js.map +1 -1
- package/dist/tools-logic/drill-down.d.ts +24 -0
- package/dist/tools-logic/drill-down.d.ts.map +1 -1
- package/dist/tools-logic/drill-down.js +36 -0
- package/dist/tools-logic/drill-down.js.map +1 -1
- package/dist/tools-logic/journal-cold-start.d.ts.map +1 -1
- package/dist/tools-logic/journal-cold-start.js +48 -9
- package/dist/tools-logic/journal-cold-start.js.map +1 -1
- package/dist/tools-logic/journal-list.d.ts +42 -0
- package/dist/tools-logic/journal-list.d.ts.map +1 -1
- package/dist/tools-logic/journal-list.js +60 -10
- package/dist/tools-logic/journal-list.js.map +1 -1
- package/dist/tools-logic/journal-read.d.ts.map +1 -1
- package/dist/tools-logic/journal-read.js +22 -13
- package/dist/tools-logic/journal-read.js.map +1 -1
- package/dist/tools-logic/journal-search.d.ts +58 -0
- package/dist/tools-logic/journal-search.d.ts.map +1 -1
- package/dist/tools-logic/journal-search.js +123 -92
- package/dist/tools-logic/journal-search.js.map +1 -1
- package/dist/tools-logic/palace-search.d.ts.map +1 -1
- package/dist/tools-logic/palace-search.js +30 -11
- package/dist/tools-logic/palace-search.js.map +1 -1
- package/dist/tools-logic/palace-walk.d.ts +10 -0
- package/dist/tools-logic/palace-walk.d.ts.map +1 -1
- package/dist/tools-logic/palace-walk.js +25 -16
- package/dist/tools-logic/palace-walk.js.map +1 -1
- package/dist/tools-logic/recall-insight.d.ts +20 -0
- package/dist/tools-logic/recall-insight.d.ts.map +1 -1
- package/dist/tools-logic/recall-insight.js +12 -1
- package/dist/tools-logic/recall-insight.js.map +1 -1
- package/dist/tools-logic/session-end.d.ts.map +1 -1
- package/dist/tools-logic/session-end.js +23 -7
- package/dist/tools-logic/session-end.js.map +1 -1
- package/dist/tools-logic/session-start.d.ts +85 -0
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +245 -108
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/tools-logic/smart-recall.d.ts +87 -62
- package/dist/tools-logic/smart-recall.d.ts.map +1 -1
- package/dist/tools-logic/smart-recall.js +183 -508
- package/dist/tools-logic/smart-recall.js.map +1 -1
- package/dist/tools-logic/supersession.d.ts +63 -2
- package/dist/tools-logic/supersession.d.ts.map +1 -1
- package/dist/tools-logic/supersession.js +153 -48
- package/dist/tools-logic/supersession.js.map +1 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/storage/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/storage/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAajF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED,wCAAwC;AACxC,MAAM,MAAM,QAAQ,GAChB,QAAQ,GACR,WAAW,GACX,U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
|
|
28
28
|
import { sanitizeName } from "./sanitize.js";
|
|
29
29
|
import { getRoot } from "../types.js";
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* 6-char hex fallback ID for hosts with no real session identity available.
|
|
32
|
+
* Generated once on import (module-load time), so it is stable for the life
|
|
33
|
+
* of THIS process — but a fresh random id every time, which is exactly the
|
|
34
|
+
* bug this module's session-id pairing fix (below) exists to route around.
|
|
35
|
+
*/
|
|
36
|
+
const FALLBACK_SESSION_ID = crypto.randomBytes(3).toString("hex");
|
|
32
37
|
/** Track which files this session has claimed (owns). */
|
|
33
38
|
const ownedFiles = new Set();
|
|
34
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Get the current session's identity.
|
|
41
|
+
*
|
|
42
|
+
* Wave 0 measurement fix (2026-08-29): Claude Code's SessionStart and Stop
|
|
43
|
+
* hooks each fire `ar hook-start` / `ar hook-end` as a SEPARATE CLI
|
|
44
|
+
* subprocess. The old implementation returned a per-process random id
|
|
45
|
+
* (`crypto.randomBytes` evaluated once at module-import time) — since each
|
|
46
|
+
* hook invocation is a fresh Node process, session_start and session_end
|
|
47
|
+
* telemetry/outcome events for the SAME real user session were stamped with
|
|
48
|
+
* two DIFFERENT random ids and could never be paired.
|
|
49
|
+
*
|
|
50
|
+
* Fix: prefer `process.env["CLAUDE_CODE_SESSION_ID"]` — the REAL session id
|
|
51
|
+
* Claude Code sets in every subprocess it spawns (verified live on this
|
|
52
|
+
* machine, see reports/2026-08-12-trainc-fix-report.md's env probe; also the
|
|
53
|
+
* id `host-profile.ts`'s doc comments already call "the REAL
|
|
54
|
+
* `CLAUDE_CODE_SESSION_ID`", and the SAME env var `isHookOwnedHost()`'s
|
|
55
|
+
* CLAUDE_CODE_* signal detection already keys off). This id is STABLE across
|
|
56
|
+
* every subprocess Claude Code spawns for one real session, so hook-start and
|
|
57
|
+
* hook-end now stamp the SAME id. Read fresh on every call (not cached at
|
|
58
|
+
* module-load time) so a test that sets/clears the env var mid-process sees
|
|
59
|
+
* the change immediately — required for the "two calls, same env, same
|
|
60
|
+
* process" pairing proof, and harmless in production since a real process's
|
|
61
|
+
* env is constant for its whole lifetime anyway.
|
|
62
|
+
*
|
|
63
|
+
* Falls back to the per-process random id when the env var is absent (non-
|
|
64
|
+
* hook hosts, e.g. Codex/raw MCP/SDK/CLI) — unchanged behavior for those
|
|
65
|
+
* hosts: still unique per process, exactly as before this fix.
|
|
66
|
+
*/
|
|
35
67
|
export function getSessionId() {
|
|
36
|
-
|
|
68
|
+
const real = process.env["CLAUDE_CODE_SESSION_ID"];
|
|
69
|
+
return real && real.trim() ? real.trim() : FALLBACK_SESSION_ID;
|
|
37
70
|
}
|
|
38
71
|
/**
|
|
39
72
|
* Generate a semantic slug from content, byte-capped at 35 bytes (naming-v2
|
|
@@ -129,13 +162,13 @@ export function journalFileName(date, baseExists, opts, dir) {
|
|
|
129
162
|
if (ownedFiles.has(`${baseKey}:base`))
|
|
130
163
|
return `${date}.md`;
|
|
131
164
|
if (ownedFiles.has(`${baseKey}:session`))
|
|
132
|
-
return `${date}-${
|
|
165
|
+
return `${date}-${FALLBACK_SESSION_ID}.md`;
|
|
133
166
|
if (!baseExists) {
|
|
134
167
|
ownedFiles.add(`${baseKey}:base`);
|
|
135
168
|
return `${date}.md`;
|
|
136
169
|
}
|
|
137
170
|
ownedFiles.add(`${baseKey}:session`);
|
|
138
|
-
return `${date}-${
|
|
171
|
+
return `${date}-${FALLBACK_SESSION_ID}.md`;
|
|
139
172
|
}
|
|
140
173
|
/**
|
|
141
174
|
* Generate a session-scoped log filename for captures.
|
|
@@ -165,13 +198,13 @@ export function captureLogFileName(date, baseExists, opts, dir) {
|
|
|
165
198
|
if (ownedFiles.has(`${baseKey}:base`))
|
|
166
199
|
return `${date}-log.md`;
|
|
167
200
|
if (ownedFiles.has(`${baseKey}:session`))
|
|
168
|
-
return `${date}-${
|
|
201
|
+
return `${date}-${FALLBACK_SESSION_ID}-log.md`;
|
|
169
202
|
if (!baseExists) {
|
|
170
203
|
ownedFiles.add(`${baseKey}:base`);
|
|
171
204
|
return `${date}-log.md`;
|
|
172
205
|
}
|
|
173
206
|
ownedFiles.add(`${baseKey}:session`);
|
|
174
|
-
return `${date}-${
|
|
207
|
+
return `${date}-${FALLBACK_SESSION_ID}-log.md`;
|
|
175
208
|
}
|
|
176
209
|
/** Reset owned files tracking (call at session boundaries). */
|
|
177
210
|
export function resetOwnedFiles() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/storage/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/storage/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAElE,yDAAyD;AACzD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MA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,SAAS,CAAC;AACtF,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,WAAmB,EAAE,MAAe;IACvF,kBAAkB,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,qBAAqB;IACnC,mBAAmB,CAAC,KAAK,EAAE,CAAC;IAC5B,kBAAkB,CAAC,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,iBAAiB;IAC/B,eAAe,EAAE,CAAC;IAClB,qBAAqB,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SupabaseConfig } from "./config.js";
|
|
2
|
-
interface RecallResultItem {
|
|
2
|
+
export interface RecallResultItem {
|
|
3
3
|
id: string;
|
|
4
4
|
source: "palace" | "journal" | "insight" | "archive";
|
|
5
5
|
title: string;
|
|
@@ -11,6 +11,31 @@ interface RecallResultItem {
|
|
|
11
11
|
date?: string;
|
|
12
12
|
severity?: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Pure row -> RecallResultItem mapper for pgvector-similarity rows
|
|
16
|
+
* (`ar_semantic_search` RPC results). Identity-trust filtered via
|
|
17
|
+
* `isRescueRow` (drops a rescue-tagged row before mapping — never
|
|
18
|
+
* surfaces it, at any rank).
|
|
19
|
+
*
|
|
20
|
+
* Extracted out of `SupabaseRecallBackend.search()` (P0 independent-review
|
|
21
|
+
* FIX 2, 2026-08-30) so this rescue-tag drop is destination-proof testable
|
|
22
|
+
* WITHOUT a live Supabase client + embedding provider — `search()` itself
|
|
23
|
+
* requires both, and this class has no dependency-injection seam for either
|
|
24
|
+
* (see recall-backend.test.mjs's own comment on why constructing a live
|
|
25
|
+
* `SupabaseRecallBackend` is out of scope for that test file). Behavior is
|
|
26
|
+
* IDENTICAL to the inline code this replaces — same filter, same field
|
|
27
|
+
* mapping — just callable directly with a hand-built row array.
|
|
28
|
+
*/
|
|
29
|
+
export declare function mapSemanticRows(rows: Array<Record<string, unknown>>): RecallResultItem[];
|
|
30
|
+
/**
|
|
31
|
+
* Pure row -> RecallResultItem mapper for PostgreSQL FTS rows (the FTS
|
|
32
|
+
* keyword-backup query's results). Same identity-trust filter as
|
|
33
|
+
* `mapSemanticRows` above — see that function's own doc comment for why
|
|
34
|
+
* this is extracted, and `isRescueRow`'s for why the check is on
|
|
35
|
+
* `metadata.source`, not `body`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mapFtsRows(rows: Array<Record<string, unknown>>): RecallResultItem[];
|
|
38
|
+
export declare function buildFtsQuery(query: string): string | null;
|
|
14
39
|
export declare class SupabaseRecallBackend {
|
|
15
40
|
private config;
|
|
16
41
|
private embedding;
|
|
@@ -18,5 +43,4 @@ export declare class SupabaseRecallBackend {
|
|
|
18
43
|
available(): boolean;
|
|
19
44
|
search(query: string, project: string | undefined, limit: number): Promise<RecallResultItem[]>;
|
|
20
45
|
}
|
|
21
|
-
export {};
|
|
22
46
|
//# sourceMappingURL=recall-backend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recall-backend.d.ts","sourceRoot":"","sources":["../../src/supabase/recall-backend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"recall-backend.d.ts","sourceRoot":"","sources":["../../src/supabase/recall-backend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAkBlD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IAOX,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAqBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,gBAAgB,EAAE,CAexF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,gBAAgB,EAAE,CAenF;AAkGD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI1D;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,SAAS,CAA2B;gBAEhC,MAAM,EAAE,cAAc;IAOlC,SAAS,IAAI,OAAO;IAId,MAAM,CACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAiJ/B"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { getSupabaseClient } from "./client.js";
|
|
3
3
|
import { createEmbeddingProvider } from "./embedding.js";
|
|
4
4
|
import { calibratedConfidence } from "../tools-logic/confidence.js";
|
|
5
|
+
import { isRescueSourceTag } from "../helpers/journal-filter.js";
|
|
6
|
+
import { tokenizeWords } from "../helpers/tokenize.js";
|
|
5
7
|
// Import the interface type — we can't import directly from recall-backend.ts
|
|
6
8
|
// because it would create a circular dependency (it dynamically imports us).
|
|
7
9
|
// Instead, we define the same shape and the getRecallBackend() factory casts.
|
|
@@ -12,6 +14,175 @@ function label(score, scale) {
|
|
|
12
14
|
const c = calibratedConfidence(score, scale);
|
|
13
15
|
return { confidence: c.label, calibrated: c.calibrated };
|
|
14
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* True iff a raw Supabase row (ar_semantic_search RPC result or FTS query
|
|
19
|
+
* result — both `.select(...)` `metadata`) carries the rescue-quarantine
|
|
20
|
+
* provenance tag. IMPORTANT: the check is on `r.metadata?.source`, NOT
|
|
21
|
+
* `r.body` — `doSync()`'s own `parseMemoryFile()` SPLITS a file's
|
|
22
|
+
* frontmatter from its body before upload (`body = content.slice(endIdx + 3)
|
|
23
|
+
* .trim()`), so `ar_entries.body` NEVER carries the `source:` frontmatter
|
|
24
|
+
* line by the time it reaches this query; a check on
|
|
25
|
+
* `isRescueSourcedContent(r.body)` would be silently vacuous (always false,
|
|
26
|
+
* since the tag is structurally absent from `body`). `metadata` is the
|
|
27
|
+
* field `parseMemoryFile` actually preserves the frontmatter into
|
|
28
|
+
* (`metadata.source`), and both the `ar_semantic_search` RPC and the FTS
|
|
29
|
+
* query select it — see `migration.sql`'s `ar_semantic_search` `RETURNS
|
|
30
|
+
* TABLE` definition.
|
|
31
|
+
*/
|
|
32
|
+
function isRescueRow(r) {
|
|
33
|
+
return isRescueSourceTag(r.metadata?.source);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pure row -> RecallResultItem mapper for pgvector-similarity rows
|
|
37
|
+
* (`ar_semantic_search` RPC results). Identity-trust filtered via
|
|
38
|
+
* `isRescueRow` (drops a rescue-tagged row before mapping — never
|
|
39
|
+
* surfaces it, at any rank).
|
|
40
|
+
*
|
|
41
|
+
* Extracted out of `SupabaseRecallBackend.search()` (P0 independent-review
|
|
42
|
+
* FIX 2, 2026-08-30) so this rescue-tag drop is destination-proof testable
|
|
43
|
+
* WITHOUT a live Supabase client + embedding provider — `search()` itself
|
|
44
|
+
* requires both, and this class has no dependency-injection seam for either
|
|
45
|
+
* (see recall-backend.test.mjs's own comment on why constructing a live
|
|
46
|
+
* `SupabaseRecallBackend` is out of scope for that test file). Behavior is
|
|
47
|
+
* IDENTICAL to the inline code this replaces — same filter, same field
|
|
48
|
+
* mapping — just callable directly with a hand-built row array.
|
|
49
|
+
*/
|
|
50
|
+
export function mapSemanticRows(rows) {
|
|
51
|
+
return rows
|
|
52
|
+
.filter((r) => !isRescueRow(r))
|
|
53
|
+
.map((r) => ({
|
|
54
|
+
id: r.id,
|
|
55
|
+
source: (r.store === "journal" ? "journal" : "palace"),
|
|
56
|
+
title: (r.title ?? r.slug),
|
|
57
|
+
excerpt: (r.body ?? "").slice(0, 300),
|
|
58
|
+
score: r.similarity ?? 0,
|
|
59
|
+
// cosine similarity is already 0..1.
|
|
60
|
+
...label(r.similarity ?? 0, "cosine"),
|
|
61
|
+
room: r.room ?? undefined,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Pure row -> RecallResultItem mapper for PostgreSQL FTS rows (the FTS
|
|
66
|
+
* keyword-backup query's results). Same identity-trust filter as
|
|
67
|
+
* `mapSemanticRows` above — see that function's own doc comment for why
|
|
68
|
+
* this is extracted, and `isRescueRow`'s for why the check is on
|
|
69
|
+
* `metadata.source`, not `body`.
|
|
70
|
+
*/
|
|
71
|
+
export function mapFtsRows(rows) {
|
|
72
|
+
return rows
|
|
73
|
+
.filter((r) => !isRescueRow(r))
|
|
74
|
+
.map((r, idx) => ({
|
|
75
|
+
id: r.id,
|
|
76
|
+
source: (r.store === "journal" ? "journal" : "palace"),
|
|
77
|
+
title: (r.title ?? r.slug),
|
|
78
|
+
excerpt: (r.body ?? "").slice(0, 300),
|
|
79
|
+
score: 1 / (idx + 1),
|
|
80
|
+
// reciprocal-rank 1/(idx+1) is already 0..1.
|
|
81
|
+
...label(1 / (idx + 1), "cosine"),
|
|
82
|
+
room: r.room ?? undefined,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build the PostgreSQL FTS query string for the `ar_entries.body` `.textSearch(...,
|
|
87
|
+
* { type: "plain" })` leg — pure, testable in isolation (Wave 4 W4b FIX 1,
|
|
88
|
+
* 2026-09-08).
|
|
89
|
+
*
|
|
90
|
+
* BUG this replaces: the query was built as `query.split(/\s+/).join(" & ")`
|
|
91
|
+
* — a bare whitespace split. Chinese/Japanese text is normally written with
|
|
92
|
+
* NO spaces between words, so an unspaced CJK query (e.g. `"分析报告"`) finds
|
|
93
|
+
* zero whitespace, stays ONE segment, and gets handed to
|
|
94
|
+
* `plainto_tsquery('english', …)` as one opaque blob — the exact same
|
|
95
|
+
* "one giant token never matches" class that caused the v3.4.44 local-search
|
|
96
|
+
* CJK fix (`../helpers/tokenize.ts`'s header; L1 eval CJK hit@5 was 0/6
|
|
97
|
+
* before that fix). This Supabase-remote leg was never swept when that fix
|
|
98
|
+
* landed, even though `SupabaseRecallBackend` is the backend the owner's
|
|
99
|
+
* REAL `smart_recall` traffic resolves to (remote replaces local output when
|
|
100
|
+
* non-empty within 2500ms) — so CJK FTS has been silently broken on the
|
|
101
|
+
* actual production path.
|
|
102
|
+
*
|
|
103
|
+
* FIX: tokenize with the SAME shared CJK-aware tokenizer every local
|
|
104
|
+
* recall/search site already uses (`tokenizeWords` — imported, not forked;
|
|
105
|
+
* see that module's own header on why forking it recreated this exact bug
|
|
106
|
+
* class 7 times before v3.4.44). `tokenizeWords` extracts Han-script runs
|
|
107
|
+
* and segments them with `Intl.Segmenter` independently of ASCII
|
|
108
|
+
* whitespace-splitting, so `"分析报告"` (no internal whitespace at all)
|
|
109
|
+
* becomes `["分析", "报告"]` instead of one token.
|
|
110
|
+
*
|
|
111
|
+
* WHY joining segmented tokens with real whitespace still works under
|
|
112
|
+
* `{ type: "plain" }` (verified, not assumed): `.textSearch(..., { type:
|
|
113
|
+
* "plain" })` sends the string through Postgres's `plainto_tsquery`, which
|
|
114
|
+
* re-tokenizes the WHOLE string itself and ANDs together whatever "words" it
|
|
115
|
+
* finds (any `&` we insert is treated as punctuation-noise and dropped, not
|
|
116
|
+
* parsed as a boolean operator — that only applies to the default/`to_tsquery`
|
|
117
|
+
* mode). `plainto_tsquery` uses Postgres's OWN whitespace/punctuation-based
|
|
118
|
+
* parser, which — like the pre-fix JS `\s+` split — cannot itself segment an
|
|
119
|
+
* unspaced Han run into separate words. What it CAN do is treat any run
|
|
120
|
+
* already delimited by whitespace as one atomic token. So the fix's actual
|
|
121
|
+
* job is upstream of Postgres: pre-insert real whitespace at the CJK word
|
|
122
|
+
* boundaries `tokenizeWords` finds, so `plainto_tsquery` receives
|
|
123
|
+
* `"分析 & 报告"` and naturally isolates `分析` and `报告` as two lexemes
|
|
124
|
+
* instead of receiving `"分析报告"` and being unable to split it.
|
|
125
|
+
*
|
|
126
|
+
* RESIDUAL LIMITATION (out of scope for this fix, documented honestly): this
|
|
127
|
+
* only fixes the QUERY side. The INDEXED side — `idx_ar_entries_fts`'s
|
|
128
|
+
* `to_tsvector('english', …)` in migration.sql — has the identical inability
|
|
129
|
+
* to auto-segment CJK at write time (no CJK-aware text-search
|
|
130
|
+
* config/dictionary such as `zhparser`/`pg_jieba` is installed). For body
|
|
131
|
+
* content that is itself one long unpunctuated CJK run with no natural
|
|
132
|
+
* breaks, matching still fails, because the indexed side never produced the
|
|
133
|
+
* separate `分析`/`报告` lexemes to match against in the first place. In
|
|
134
|
+
* practice this owner's real memory content is heavily CJK+ASCII+punctuation
|
|
135
|
+
* mixed (see e.g. this very file's own commit-message/report conventions),
|
|
136
|
+
* which DOES naturally break into separate indexed tokens at punctuation/
|
|
137
|
+
* script boundaries — so this fix closes the common case (unspaced CJK
|
|
138
|
+
* QUERIES against naturally-punctuated stored content) without needing an
|
|
139
|
+
* index/schema change. A full write-side fix would require a CJK-aware
|
|
140
|
+
* `to_tsvector` config — a migration.sql/schema change, explicitly out of
|
|
141
|
+
* this task's scope.
|
|
142
|
+
*
|
|
143
|
+
* Returns `null` when tokenization yields zero tokens (pure
|
|
144
|
+
* stopword/punctuation query) — callers MUST skip the FTS leg entirely in
|
|
145
|
+
* that case rather than pass an empty string to `.textSearch(...)`, so an
|
|
146
|
+
* edge-case query can never reach Postgres as a malformed/empty tsquery
|
|
147
|
+
* input.
|
|
148
|
+
*
|
|
149
|
+
* v4 PRE-SHIP GATE FIX (2026-09-08, reports/2026-09-08-v4-gatefix-report.md
|
|
150
|
+
* FIX 2) — "zero tokens" above was not actually true for CJK PUNCTUATION:
|
|
151
|
+
* `HAN_RUN_RE` (`tokenize.ts`) only matches `\p{Script=Han}` — CJK
|
|
152
|
+
* punctuation (fullwidth/ideographic marks like "。!?,、" or the Chinese
|
|
153
|
+
* double-ellipsis "……") carries Unicode script `Common`, not `Han`, so it is
|
|
154
|
+
* NEVER captured by the Han-run path and falls through to the plain
|
|
155
|
+
* ASCII/whitespace path unmodified (this call passes no `asciiStripRegex`).
|
|
156
|
+
* With no internal whitespace, a punctuation run becomes ONE token whose
|
|
157
|
+
* length can exceed `minLength` (e.g. "。!?,、" is 5 characters) and
|
|
158
|
+
* survives as a garbage FTS clause; mixed with real Han content (e.g.
|
|
159
|
+
* "什么???" → Han run "什么" plus a leftover "???" ASCII-path token,
|
|
160
|
+
* itself long enough to survive `minLength`), it produces a spurious
|
|
161
|
+
* `& ???`-shaped AND-clause alongside the real query terms.
|
|
162
|
+
*
|
|
163
|
+
* FIX: after tokenizing, drop any token containing NO letter or digit
|
|
164
|
+
* (Unicode-aware — `\p{L}` covers Han ideographs the same as Latin letters,
|
|
165
|
+
* so no separate CJK case is needed). A pure-punctuation query now
|
|
166
|
+
* tokenizes to nothing (this leg's existing `tokens.length === 0` guard
|
|
167
|
+
* above returns `null`, so search() skips the FTS leg entirely, matching
|
|
168
|
+
* the ASCII punctuation-only case `recall-backend.test.mjs` already
|
|
169
|
+
* covered). A mixed query loses ONLY the punctuation-only token(s) — a real
|
|
170
|
+
* Han run like "什么" is unaffected (Han characters ARE `\p{L}`), so
|
|
171
|
+
* `"什么???"` now segments to just `"什么"`, no spurious `& ???` clause.
|
|
172
|
+
* Filtering post-tokenize (rather than passing an `asciiStripRegex` into
|
|
173
|
+
* `tokenizeWords`, the approach `palace/skills.ts` uses) keeps this
|
|
174
|
+
* call the only one that changes — `tokenizeWords` itself, and every OTHER
|
|
175
|
+
* call site's behavior, is untouched.
|
|
176
|
+
*/
|
|
177
|
+
function hasWordChar(token) {
|
|
178
|
+
return /[\p{L}\p{N}]/u.test(token);
|
|
179
|
+
}
|
|
180
|
+
export function buildFtsQuery(query) {
|
|
181
|
+
const tokens = tokenizeWords(query).filter(hasWordChar);
|
|
182
|
+
if (tokens.length === 0)
|
|
183
|
+
return null;
|
|
184
|
+
return tokens.join(" & ");
|
|
185
|
+
}
|
|
15
186
|
export class SupabaseRecallBackend {
|
|
16
187
|
config;
|
|
17
188
|
embedding;
|
|
@@ -40,6 +211,13 @@ export class SupabaseRecallBackend {
|
|
|
40
211
|
const { localRecallSearch } = await import("../tools-logic/smart-recall.js");
|
|
41
212
|
return localRecallSearch(query, project, limit);
|
|
42
213
|
}
|
|
214
|
+
// FIX 1 (Wave 4 W4b, 2026-09-08): CJK-aware query segmentation — see
|
|
215
|
+
// `buildFtsQuery`'s own doc comment for the bug, the fix mechanism, and
|
|
216
|
+
// the documented residual (index-side) limitation. `null` means
|
|
217
|
+
// tokenization found nothing to search on (pure stopword/punctuation
|
|
218
|
+
// query) — skip the FTS leg entirely rather than hand Postgres an empty
|
|
219
|
+
// or malformed tsquery input.
|
|
220
|
+
const ftsQuery = buildFtsQuery(query);
|
|
43
221
|
// Three parallel queries
|
|
44
222
|
const [semanticResults, insightResults, ftsResults] = await Promise.all([
|
|
45
223
|
// 1. pgvector cosine similarity on ar_entries
|
|
@@ -54,24 +232,61 @@ export class SupabaseRecallBackend {
|
|
|
54
232
|
match_limit: limit,
|
|
55
233
|
}),
|
|
56
234
|
// 3. PostgreSQL FTS (keyword backup)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
235
|
+
ftsQuery
|
|
236
|
+
? client
|
|
237
|
+
.from("ar_entries")
|
|
238
|
+
.select("id, project, store, room, slug, title, body, tags, metadata")
|
|
239
|
+
.eq("project", project)
|
|
240
|
+
.textSearch("body", ftsQuery, { type: "plain" })
|
|
241
|
+
.limit(limit)
|
|
242
|
+
: Promise.resolve({ data: [], error: null }),
|
|
63
243
|
]);
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
244
|
+
// Identity-trust (P0 trust-class closure, 2026-08-30, wave/pipe-p0-trustclass,
|
|
245
|
+
// gap #6 defense-in-depth): the ROOT CAUSE (rescue-tagged content entering
|
|
246
|
+
// ar_entries via backfill/doSync) is closed at the write side by gap #5's
|
|
247
|
+
// fix (gatherProjectBackfillFiles routes through readTierCandidates), but
|
|
248
|
+
// this is the READ-side surfacing boundary, so it gets its own independent
|
|
249
|
+
// check rather than relying solely on the write side staying correct
|
|
250
|
+
// forever. The actual filter+map logic lives in `mapSemanticRows`/
|
|
251
|
+
// `mapFtsRows` below (P0 independent-review FIX 2, 2026-08-30) — extracted
|
|
252
|
+
// out of this method so it is destination-proof testable with a
|
|
253
|
+
// hand-constructed row, without a live Supabase client + embedding
|
|
254
|
+
// provider (this class has no DI seam for either).
|
|
255
|
+
const semanticItems = mapSemanticRows(semanticResults.data ?? []);
|
|
256
|
+
// FIX 2 (Wave 4 W4b, 2026-09-08) — VERIFIED, not applied: this leg has NO
|
|
257
|
+
// rescue-provenance filter analogous to `isRescueRow` above, and after
|
|
258
|
+
// checking the actual schema it CANNOT get one the same way.
|
|
259
|
+
// - `ar_insights` (migration.sql) has no `metadata` column at all
|
|
260
|
+
// (unlike `ar_entries`, which does) — there is no jsonb field to
|
|
261
|
+
// carry a `source:` provenance tag on this table, full stop.
|
|
262
|
+
// - Even the one column that could theoretically double for this
|
|
263
|
+
// (`ar_insights.tags text[]`) is not selected by the `ar_insight_search`
|
|
264
|
+
// RPC's `RETURNS TABLE` (migration.sql): it returns only
|
|
265
|
+
// `id, title, severity, confirmed, projects, similarity` — no body,
|
|
266
|
+
// no metadata, no tags reach this code at all.
|
|
267
|
+
// - A best-effort content-level check
|
|
268
|
+
// (`isRescueSourcedContent`/`journal-filter.ts`) would be VACUOUS
|
|
269
|
+
// here, not just weak: it parses a `---\nsource: …\n---` frontmatter
|
|
270
|
+
// block out of raw file content, and `title`/`severity` are plain
|
|
271
|
+
// short text fields, never frontmatter-delimited content — the
|
|
272
|
+
// `content.startsWith("---")` guard would be false for every
|
|
273
|
+
// realistic row, so the filter could never fire. Shipping it would
|
|
274
|
+
// be exactly the "vacuous filter that looks fixed but never runs"
|
|
275
|
+
// trap w5fix already caught once (body-vs-metadata, same file).
|
|
276
|
+
// - Also verified structurally unreachable today regardless: `grep -rn
|
|
277
|
+
// "ar_insights"` across `packages/*/src` finds zero writers to this
|
|
278
|
+
// Supabase table (only a same-named but unrelated LOCAL
|
|
279
|
+
// `palace/insights-index.ts` file index) — nothing in this codebase
|
|
280
|
+
// inserts rows into `ar_insights` at all, so a rescue-tagged row
|
|
281
|
+
// cannot reach this leg through any currently-shipped path.
|
|
282
|
+
// Net: this residual gap is real (a future writer to `ar_insights` that
|
|
283
|
+
// doesn't sanitize provenance would surface unfiltered here) but it is
|
|
284
|
+
// UNFILTERABLE BY THE CURRENT SCHEMA from this file alone — closing it
|
|
285
|
+
// requires a migration.sql change (add a metadata/source column, thread
|
|
286
|
+
// it through the RPC's RETURNS TABLE) and/or a real writer that respects
|
|
287
|
+
// it, both out of this task's scope (target file is
|
|
288
|
+
// `supabase/recall-backend.ts`, not `migration.sql`). Left as a
|
|
289
|
+
// documented gap rather than a filter that can never fire.
|
|
75
290
|
const insightItemsList = (insightResults.data ?? []).map((r) => ({
|
|
76
291
|
id: r.id,
|
|
77
292
|
source: "insight",
|
|
@@ -82,16 +297,7 @@ export class SupabaseRecallBackend {
|
|
|
82
297
|
...label(r.similarity ?? 0, "cosine"),
|
|
83
298
|
severity: r.severity,
|
|
84
299
|
}));
|
|
85
|
-
const ftsItems = (ftsResults.data ?? [])
|
|
86
|
-
id: r.id,
|
|
87
|
-
source: (r.store === "journal" ? "journal" : "palace"),
|
|
88
|
-
title: (r.title ?? r.slug),
|
|
89
|
-
excerpt: (r.body ?? "").slice(0, 300),
|
|
90
|
-
score: 1 / (idx + 1),
|
|
91
|
-
// reciprocal-rank 1/(idx+1) is already 0..1.
|
|
92
|
-
...label(1 / (idx + 1), "cosine"),
|
|
93
|
-
room: r.room ?? undefined,
|
|
94
|
-
}));
|
|
300
|
+
const ftsItems = mapFtsRows(ftsResults.data ?? []);
|
|
95
301
|
// RRF merge across all three
|
|
96
302
|
semanticItems.sort((a, b) => b.score - a.score);
|
|
97
303
|
insightItemsList.sort((a, b) => b.score - a.score);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recall-backend.js","sourceRoot":"","sources":["../../src/supabase/recall-backend.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAA0B,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAwB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"recall-backend.js","sourceRoot":"","sources":["../../src/supabase/recall-backend.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAA0B,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAAE,oBAAoB,EAAwB,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8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AK,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;CACF"}
|
package/dist/supabase/sync.d.ts
CHANGED
|
@@ -9,6 +9,47 @@ export declare function parseMemoryFile(content: string): ParsedMemoryFile;
|
|
|
9
9
|
export declare function deriveSlug(filePath: string): string;
|
|
10
10
|
export declare function logSyncError(message: string): void;
|
|
11
11
|
export declare function syncToSupabase(filePath: string, content: string, project: string, store: "journal" | "palace" | "awareness" | "digest" | "corrections", room?: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Gather a project's journal + palace-room files for backfill(), sourced
|
|
14
|
+
* EXCLUSIVELY through readTierCandidates (P0 trust-class closure,
|
|
15
|
+
* 2026-08-30, wave/pipe-p0-trustclass, gap #5/#6's root) — never a raw
|
|
16
|
+
* readFileSync scan. This is the SHARED implementation both autoBackfill
|
|
17
|
+
* (session-start.ts, run on every session_start) and the CLI's
|
|
18
|
+
* `ar setup supabase --backfill` admin command call, closing the class of
|
|
19
|
+
* gap (a hand-rolled directory scan bypassing the rescue-quarantine choke,
|
|
20
|
+
* previously duplicated independently in BOTH call sites, discovered while
|
|
21
|
+
* auditing gap #5) in ONE place — class-not-instance, not two parallel
|
|
22
|
+
* bolt-on fixes. readTierCandidates' safe-by-default posture means a
|
|
23
|
+
* rescue-tagged file is never included here, so it can never reach
|
|
24
|
+
* `ar_entries.body` via backfill()/doSync() — closing gap #6's root cause
|
|
25
|
+
* (recall-backend.ts's `search()` also gets an independent defense-in-depth
|
|
26
|
+
* check on `metadata.source`, since `body` itself never carries the
|
|
27
|
+
* frontmatter tag once parseMemoryFile strips it at write time).
|
|
28
|
+
*
|
|
29
|
+
* P0 independent-review FIX 4 (2026-08-30) — DISCLOSED, INTENTIONAL scope
|
|
30
|
+
* narrowing (assessed, not accidental): the journal side inherits
|
|
31
|
+
* `readTierCandidates("journal", ...)`'s own `listJournalFiles(project,
|
|
32
|
+
* false)` reader, which requires a leading `^\d{4}-\d{2}-\d{2}` filename
|
|
33
|
+
* match — this naturally EXCLUDES `journal/_index.md` (the machine-readable
|
|
34
|
+
* index artifact, not memory content; see `helpers/journal-filter.ts`'s
|
|
35
|
+
* `isJournalFile` doc comment for why an index file must never be treated
|
|
36
|
+
* as a journal entry anywhere in this codebase). The palace side inherits
|
|
37
|
+
* `listRooms()`'s own requirement that a room directory carry a
|
|
38
|
+
* `_room.json` file — this excludes an unregistered "remnant" room
|
|
39
|
+
* directory (`palace/rooms.ts`'s own `listRooms()` comment already names
|
|
40
|
+
* this exact case: "not real rooms, e.g. remnant 'unnamed/' dirs"). BOTH
|
|
41
|
+
* exclusions are correct for backfill's purpose (syncing genuine MEMORY
|
|
42
|
+
* CONTENT to Supabase, not index/orphan artifacts) and are the SAME
|
|
43
|
+
* narrowing every other consumer of these two readers already gets —
|
|
44
|
+
* verified here, not silently inherited, because backfill is the one
|
|
45
|
+
* surface whose OUTPUT leaves this machine.
|
|
46
|
+
*/
|
|
47
|
+
export declare function gatherProjectBackfillFiles(project: string): Array<{
|
|
48
|
+
path: string;
|
|
49
|
+
content: string;
|
|
50
|
+
store: "journal" | "palace";
|
|
51
|
+
room?: string;
|
|
52
|
+
}>;
|
|
12
53
|
export declare function backfill(project: string, files: Array<{
|
|
13
54
|
path: string;
|
|
14
55
|
content: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/supabase/sync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/supabase/sync.ts"],"names":[],"mappings":"AAiBA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,C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CAAA;CAAE,CAAC,CAsC9D"}
|
package/dist/supabase/sync.js
CHANGED
|
@@ -9,6 +9,7 @@ import { classifyStore } from "../storage/classification.js";
|
|
|
9
9
|
import { scrubForCloud } from "../storage/content-guard.js";
|
|
10
10
|
import { exportCorrections } from "../tools-logic/export-corrections.js";
|
|
11
11
|
import { getRoot } from "../types.js";
|
|
12
|
+
import { readTierCandidates } from "../retrieval/candidates.js";
|
|
12
13
|
// ---------------------------------------------------------------------------
|
|
13
14
|
// Utilities (exported for testing)
|
|
14
15
|
// ---------------------------------------------------------------------------
|
|
@@ -234,6 +235,51 @@ async function syncCorrectionRecord(filePath, correctionId, project) {
|
|
|
234
235
|
logSyncError(`syncCorrectionRecord failed for ${filePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
235
236
|
}
|
|
236
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Gather a project's journal + palace-room files for backfill(), sourced
|
|
240
|
+
* EXCLUSIVELY through readTierCandidates (P0 trust-class closure,
|
|
241
|
+
* 2026-08-30, wave/pipe-p0-trustclass, gap #5/#6's root) — never a raw
|
|
242
|
+
* readFileSync scan. This is the SHARED implementation both autoBackfill
|
|
243
|
+
* (session-start.ts, run on every session_start) and the CLI's
|
|
244
|
+
* `ar setup supabase --backfill` admin command call, closing the class of
|
|
245
|
+
* gap (a hand-rolled directory scan bypassing the rescue-quarantine choke,
|
|
246
|
+
* previously duplicated independently in BOTH call sites, discovered while
|
|
247
|
+
* auditing gap #5) in ONE place — class-not-instance, not two parallel
|
|
248
|
+
* bolt-on fixes. readTierCandidates' safe-by-default posture means a
|
|
249
|
+
* rescue-tagged file is never included here, so it can never reach
|
|
250
|
+
* `ar_entries.body` via backfill()/doSync() — closing gap #6's root cause
|
|
251
|
+
* (recall-backend.ts's `search()` also gets an independent defense-in-depth
|
|
252
|
+
* check on `metadata.source`, since `body` itself never carries the
|
|
253
|
+
* frontmatter tag once parseMemoryFile strips it at write time).
|
|
254
|
+
*
|
|
255
|
+
* P0 independent-review FIX 4 (2026-08-30) — DISCLOSED, INTENTIONAL scope
|
|
256
|
+
* narrowing (assessed, not accidental): the journal side inherits
|
|
257
|
+
* `readTierCandidates("journal", ...)`'s own `listJournalFiles(project,
|
|
258
|
+
* false)` reader, which requires a leading `^\d{4}-\d{2}-\d{2}` filename
|
|
259
|
+
* match — this naturally EXCLUDES `journal/_index.md` (the machine-readable
|
|
260
|
+
* index artifact, not memory content; see `helpers/journal-filter.ts`'s
|
|
261
|
+
* `isJournalFile` doc comment for why an index file must never be treated
|
|
262
|
+
* as a journal entry anywhere in this codebase). The palace side inherits
|
|
263
|
+
* `listRooms()`'s own requirement that a room directory carry a
|
|
264
|
+
* `_room.json` file — this excludes an unregistered "remnant" room
|
|
265
|
+
* directory (`palace/rooms.ts`'s own `listRooms()` comment already names
|
|
266
|
+
* this exact case: "not real rooms, e.g. remnant 'unnamed/' dirs"). BOTH
|
|
267
|
+
* exclusions are correct for backfill's purpose (syncing genuine MEMORY
|
|
268
|
+
* CONTENT to Supabase, not index/orphan artifacts) and are the SAME
|
|
269
|
+
* narrowing every other consumer of these two readers already gets —
|
|
270
|
+
* verified here, not silently inherited, because backfill is the one
|
|
271
|
+
* surface whose OUTPUT leaves this machine.
|
|
272
|
+
*/
|
|
273
|
+
export function gatherProjectBackfillFiles(project) {
|
|
274
|
+
const files = [];
|
|
275
|
+
for (const c of readTierCandidates("journal", project)) {
|
|
276
|
+
files.push({ path: c.sourcePath, content: c.content, store: "journal" });
|
|
277
|
+
}
|
|
278
|
+
for (const c of readTierCandidates("palace-room", project)) {
|
|
279
|
+
files.push({ path: c.sourcePath, content: c.content, store: "palace", room: c.room });
|
|
280
|
+
}
|
|
281
|
+
return files;
|
|
282
|
+
}
|
|
237
283
|
export async function backfill(project, files) {
|
|
238
284
|
const client = getSupabaseClient();
|
|
239
285
|
if (!client)
|