@unbrained/pm-cli 2026.5.30 → 2026.5.31
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/CHANGELOG.md +25 -0
- package/dist/cli/commands/calendar.js +81 -9
- package/dist/cli/commands/calendar.js.map +1 -1
- package/dist/cli/commands/create.js +34 -4
- package/dist/cli/commands/create.js.map +1 -1
- package/dist/cli/commands/extension/install-sources.d.ts +2 -0
- package/dist/cli/commands/extension/install-sources.js +11 -4
- package/dist/cli/commands/extension/install-sources.js.map +1 -1
- package/dist/cli/commands/reindex.js +3 -3
- package/dist/cli/commands/reindex.js.map +1 -1
- package/dist/cli/commands/search.d.ts +17 -0
- package/dist/cli/commands/search.js +40 -10
- package/dist/cli/commands/search.js.map +1 -1
- package/dist/cli/register-list-query.js +9 -11
- package/dist/cli/register-list-query.js.map +1 -1
- package/dist/cli/register-mutation.js +20 -22
- package/dist/cli/register-mutation.js.map +1 -1
- package/dist/cli/register-operations.js +32 -25
- package/dist/cli/register-operations.js.map +1 -1
- package/dist/cli/register-setup.js +6 -8
- package/dist/cli/register-setup.js.map +1 -1
- package/dist/cli/registration-helpers.js +6 -3
- package/dist/cli/registration-helpers.js.map +1 -1
- package/dist/cli/search-refresh.d.ts +2 -0
- package/dist/cli/search-refresh.js +13 -0
- package/dist/cli/search-refresh.js.map +1 -0
- package/dist/cli-bundle/chunks/activity-OWYSUZOY.js +17 -0
- package/dist/cli-bundle/chunks/activity-OWYSUZOY.js.map +7 -0
- package/dist/cli-bundle/chunks/aggregate-ADUOSFRO.js +209 -0
- package/dist/cli-bundle/chunks/aggregate-ADUOSFRO.js.map +7 -0
- package/dist/cli-bundle/chunks/append-JD2DETU7.js +73 -0
- package/dist/cli-bundle/chunks/append-JD2DETU7.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-3HUE7XOF.js +27 -0
- package/dist/cli-bundle/chunks/chunk-3HUE7XOF.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-3M73P3G6.js +1636 -0
- package/dist/cli-bundle/chunks/chunk-3M73P3G6.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-4AEZR5EJ.js +189 -0
- package/dist/cli-bundle/chunks/chunk-4AEZR5EJ.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-5HSEP75M.js +330 -0
- package/dist/cli-bundle/chunks/chunk-5HSEP75M.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-6HT2F4TK.js +1770 -0
- package/dist/cli-bundle/chunks/chunk-6HT2F4TK.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-6YCV7WSL.js +552 -0
- package/dist/cli-bundle/chunks/chunk-6YCV7WSL.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-7Y53ZJIQ.js +202 -0
- package/dist/cli-bundle/chunks/chunk-7Y53ZJIQ.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-A7E7PUVX.js +157 -0
- package/dist/cli-bundle/chunks/chunk-A7E7PUVX.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-AKOOMO3T.js +90 -0
- package/dist/cli-bundle/chunks/chunk-AKOOMO3T.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-BUPWJ3IJ.js +950 -0
- package/dist/cli-bundle/chunks/chunk-BUPWJ3IJ.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-CEFIVZPG.js +79 -0
- package/dist/cli-bundle/chunks/chunk-CEFIVZPG.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-D7AOMPRH.js +349 -0
- package/dist/cli-bundle/chunks/chunk-D7AOMPRH.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-EAOG77HM.js +56 -0
- package/dist/cli-bundle/chunks/chunk-EAOG77HM.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-EGUGFSNX.js +47 -0
- package/dist/cli-bundle/chunks/chunk-EGUGFSNX.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-FM26RGSU.js +56 -0
- package/dist/cli-bundle/chunks/chunk-FM26RGSU.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-FQE6XZDB.js +435 -0
- package/dist/cli-bundle/chunks/chunk-FQE6XZDB.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-G57E5D7T.js +185 -0
- package/dist/cli-bundle/chunks/chunk-G57E5D7T.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-GN7IJPCD.js +3621 -0
- package/dist/cli-bundle/chunks/chunk-GN7IJPCD.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-JFWUHHS2.js +233 -0
- package/dist/cli-bundle/chunks/chunk-JFWUHHS2.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-JTWRXG4B.js +1861 -0
- package/dist/cli-bundle/chunks/chunk-JTWRXG4B.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-JULRTHJQ.js +648 -0
- package/dist/cli-bundle/chunks/chunk-JULRTHJQ.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-PB2YU2E3.js → chunk-KBQY3YG5.js} +28 -70
- package/dist/cli-bundle/chunks/chunk-KBQY3YG5.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-L2FXEKDB.js +185 -0
- package/dist/cli-bundle/chunks/chunk-L2FXEKDB.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-LRBOHPUE.js +189 -0
- package/dist/cli-bundle/chunks/chunk-LRBOHPUE.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-LSXGH6NE.js +5153 -0
- package/dist/cli-bundle/chunks/chunk-LSXGH6NE.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-MD7K4JYF.js +1345 -0
- package/dist/cli-bundle/chunks/chunk-MD7K4JYF.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-NGN7UV5K.js +341 -0
- package/dist/cli-bundle/chunks/chunk-NGN7UV5K.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-O7IWB35H.js +18 -0
- package/dist/cli-bundle/chunks/chunk-O7IWB35H.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-OGZEG5TT.js +2929 -0
- package/dist/cli-bundle/chunks/chunk-OGZEG5TT.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-RJONRNXN.js → chunk-P53TN6IA.js} +22 -30
- package/dist/cli-bundle/chunks/chunk-P53TN6IA.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-PVNQLCIS.js +176 -0
- package/dist/cli-bundle/chunks/chunk-PVNQLCIS.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-PXUAZUUY.js +1680 -0
- package/dist/cli-bundle/chunks/chunk-PXUAZUUY.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-QAJBIGRA.js +20 -0
- package/dist/cli-bundle/chunks/chunk-QAJBIGRA.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-SEXQN4KL.js +60 -0
- package/dist/cli-bundle/chunks/chunk-SEXQN4KL.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-U7FMKRXH.js +362 -0
- package/dist/cli-bundle/chunks/chunk-U7FMKRXH.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-VGICHR7D.js +141 -0
- package/dist/cli-bundle/chunks/chunk-VGICHR7D.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-WDPXDQFG.js +632 -0
- package/dist/cli-bundle/chunks/chunk-WDPXDQFG.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-WJ2NAC37.js +252 -0
- package/dist/cli-bundle/chunks/chunk-WJ2NAC37.js.map +7 -0
- package/dist/cli-bundle/chunks/claim-EE4TKKCV.js +133 -0
- package/dist/cli-bundle/chunks/claim-EE4TKKCV.js.map +7 -0
- package/dist/cli-bundle/chunks/close-XY4CSAYF.js +14 -0
- package/dist/cli-bundle/chunks/close-XY4CSAYF.js.map +7 -0
- package/dist/cli-bundle/chunks/comments-AAKJQ6LW.js +104 -0
- package/dist/cli-bundle/chunks/comments-AAKJQ6LW.js.map +7 -0
- package/dist/cli-bundle/chunks/config-V3FZOKLI.js +1577 -0
- package/dist/cli-bundle/chunks/config-V3FZOKLI.js.map +7 -0
- package/dist/cli-bundle/chunks/context-RZ5QPNJB.js +1458 -0
- package/dist/cli-bundle/chunks/context-RZ5QPNJB.js.map +7 -0
- package/dist/cli-bundle/chunks/contracts-YLMH33VU.js +1245 -0
- package/dist/cli-bundle/chunks/contracts-YLMH33VU.js.map +7 -0
- package/dist/cli-bundle/chunks/create-PZVHRIZQ.js +28 -0
- package/dist/cli-bundle/chunks/create-PZVHRIZQ.js.map +7 -0
- package/dist/cli-bundle/chunks/delete-RHCTEORS.js +59 -0
- package/dist/cli-bundle/chunks/delete-RHCTEORS.js.map +7 -0
- package/dist/cli-bundle/chunks/deps-MZYCMLAO.js +229 -0
- package/dist/cli-bundle/chunks/deps-MZYCMLAO.js.map +7 -0
- package/dist/cli-bundle/chunks/docs-FXXUCZYU.js +35 -0
- package/dist/cli-bundle/chunks/docs-FXXUCZYU.js.map +7 -0
- package/dist/cli-bundle/chunks/extension-B4WL7BQU.js +25 -0
- package/dist/cli-bundle/chunks/extension-B4WL7BQU.js.map +7 -0
- package/dist/cli-bundle/chunks/files-WVOX67PE.js +286 -0
- package/dist/cli-bundle/chunks/files-WVOX67PE.js.map +7 -0
- package/dist/cli-bundle/chunks/gc-JWNF66EC.js +181 -0
- package/dist/cli-bundle/chunks/gc-JWNF66EC.js.map +7 -0
- package/dist/cli-bundle/chunks/get-LTK3HOCQ.js +198 -0
- package/dist/cli-bundle/chunks/get-LTK3HOCQ.js.map +7 -0
- package/dist/cli-bundle/chunks/health-TCWL55KM.js +1233 -0
- package/dist/cli-bundle/chunks/health-TCWL55KM.js.map +7 -0
- package/dist/cli-bundle/chunks/history-A2JUDXUE.js +21 -0
- package/dist/cli-bundle/chunks/history-A2JUDXUE.js.map +7 -0
- package/dist/cli-bundle/chunks/history-redact-ED6RFCPL.js +20 -0
- package/dist/cli-bundle/chunks/history-redact-ED6RFCPL.js.map +7 -0
- package/dist/cli-bundle/chunks/history-repair-ZWSTDRH2.js +198 -0
- package/dist/cli-bundle/chunks/history-repair-ZWSTDRH2.js.map +7 -0
- package/dist/cli-bundle/chunks/init-M2WUB4YH.js +16 -0
- package/dist/cli-bundle/chunks/init-M2WUB4YH.js.map +7 -0
- package/dist/cli-bundle/chunks/learnings-NXTWE3FR.js +48 -0
- package/dist/cli-bundle/chunks/learnings-NXTWE3FR.js.map +7 -0
- package/dist/cli-bundle/chunks/list-OGWQPC26.js +20 -0
- package/dist/cli-bundle/chunks/list-OGWQPC26.js.map +7 -0
- package/dist/cli-bundle/chunks/notes-DFS5ZGOO.js +48 -0
- package/dist/cli-bundle/chunks/notes-DFS5ZGOO.js.map +7 -0
- package/dist/cli-bundle/chunks/plan-67AB2PLM.js +1175 -0
- package/dist/cli-bundle/chunks/plan-67AB2PLM.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-list-query-EIVQ5FMR.js → register-list-query-UP3VRUFS.js} +24 -15
- package/dist/cli-bundle/chunks/register-list-query-UP3VRUFS.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-mutation-RSZNPSGI.js → register-mutation-YWSBF545.js} +38 -28
- package/dist/cli-bundle/chunks/register-mutation-YWSBF545.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-operations-APUSYDMR.js → register-operations-3BDTGSDH.js} +49 -30
- package/dist/cli-bundle/chunks/register-operations-3BDTGSDH.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-setup-OZOKSMPJ.js → register-setup-V56GDRUS.js} +21 -12
- package/dist/cli-bundle/chunks/register-setup-V56GDRUS.js.map +7 -0
- package/dist/cli-bundle/chunks/restore-MB2ISME7.js +18 -0
- package/dist/cli-bundle/chunks/restore-MB2ISME7.js.map +7 -0
- package/dist/cli-bundle/chunks/schema-Q622KC46.js +119 -0
- package/dist/cli-bundle/chunks/schema-Q622KC46.js.map +7 -0
- package/dist/cli-bundle/chunks/search-HENBL456.js +1135 -0
- package/dist/cli-bundle/chunks/search-HENBL456.js.map +7 -0
- package/dist/cli-bundle/chunks/stats-N6H3YP2F.js +124 -0
- package/dist/cli-bundle/chunks/stats-N6H3YP2F.js.map +7 -0
- package/dist/cli-bundle/chunks/test-VNBDRJ4Z.js +32 -0
- package/dist/cli-bundle/chunks/test-VNBDRJ4Z.js.map +7 -0
- package/dist/cli-bundle/chunks/test-all-G2AZOHXI.js +332 -0
- package/dist/cli-bundle/chunks/test-all-G2AZOHXI.js.map +7 -0
- package/dist/cli-bundle/chunks/test-runs-GX5HTPSF.js +939 -0
- package/dist/cli-bundle/chunks/test-runs-GX5HTPSF.js.map +7 -0
- package/dist/cli-bundle/chunks/update-H6SCWNMA.js +22 -0
- package/dist/cli-bundle/chunks/update-H6SCWNMA.js.map +7 -0
- package/dist/cli-bundle/chunks/update-many-46HRSP2Q.js +676 -0
- package/dist/cli-bundle/chunks/update-many-46HRSP2Q.js.map +7 -0
- package/dist/cli-bundle/chunks/upgrade-H5HHM5UV.js +271 -0
- package/dist/cli-bundle/chunks/upgrade-H5HHM5UV.js.map +7 -0
- package/dist/cli-bundle/chunks/validate-TMCVKIGZ.js +1110 -0
- package/dist/cli-bundle/chunks/validate-TMCVKIGZ.js.map +7 -0
- package/dist/cli-bundle/main.js +146 -90
- package/dist/cli-bundle/main.js.map +4 -4
- package/dist/core/item/item-type-definition.js +6 -2
- package/dist/core/item/item-type-definition.js.map +1 -1
- package/dist/core/item/type-registry.d.ts +4 -0
- package/dist/core/item/type-registry.js +10 -2
- package/dist/core/item/type-registry.js.map +1 -1
- package/dist/core/search/background-refresh.d.ts +53 -0
- package/dist/core/search/background-refresh.js +286 -0
- package/dist/core/search/background-refresh.js.map +1 -0
- package/dist/core/search/cache.d.ts +20 -1
- package/dist/core/search/cache.js +33 -4
- package/dist/core/search/cache.js.map +1 -1
- package/dist/core/search/vector-stores.js +7 -3
- package/dist/core/search/vector-stores.js.map +1 -1
- package/dist/core/shared/constants.d.ts +2 -2
- package/dist/core/shared/constants.js +2 -3
- package/dist/core/shared/constants.js.map +1 -1
- package/dist/core/store/item-format-migration.js +25 -15
- package/dist/core/store/item-format-migration.js.map +1 -1
- package/dist/core/store/settings-validator.js +6 -2
- package/dist/core/store/settings-validator.js.map +1 -1
- package/dist/core/telemetry/runtime.d.ts +10 -0
- package/dist/core/telemetry/runtime.js +86 -2
- package/dist/core/telemetry/runtime.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +4 -4
- package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
- package/dist/sdk/cli-contracts.js +26 -5
- package/dist/sdk/cli-contracts.js.map +1 -1
- package/dist/types.d.ts +7 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/docs/RELEASING.md +1 -1
- package/package.json +1 -2
- package/dist/cli-bundle/chunks/chunk-PB2YU2E3.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-RJONRNXN.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-SW5BMMCU.js +0 -13864
- package/dist/cli-bundle/chunks/chunk-SW5BMMCU.js.map +0 -7
- package/dist/cli-bundle/chunks/commands-XJ4TJ5UN.js +0 -24225
- package/dist/cli-bundle/chunks/commands-XJ4TJ5UN.js.map +0 -7
- package/dist/cli-bundle/chunks/register-list-query-EIVQ5FMR.js.map +0 -7
- package/dist/cli-bundle/chunks/register-mutation-RSZNPSGI.js.map +0 -7
- package/dist/cli-bundle/chunks/register-operations-APUSYDMR.js.map +0 -7
- package/dist/cli-bundle/chunks/register-setup-OZOKSMPJ.js.map +0 -7
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d8990236-9b78-570d-bafa-5da0ce621293")}catch(e){}}();
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { mkdirSync, rmSync, statSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { pathExists, readFileIfExists, writeFileAtomic } from "../fs/fs-utils.js";
|
|
7
|
+
import { acquireLock } from "../lock/lock.js";
|
|
8
|
+
import { resolvePmPackageRootFromModule } from "../packages/root.js";
|
|
9
|
+
import { readSettings } from "../store/settings.js";
|
|
10
|
+
import { toErrorMessage } from "../shared/primitives.js";
|
|
11
|
+
import { resolveSettingsWithSemanticRuntimeDefaults } from "./semantic-defaults.js";
|
|
12
|
+
/**
|
|
13
|
+
* Shared lock id for any process that rewrites the local vector store. Reindex
|
|
14
|
+
* and the background mutation-refresh worker both acquire this so they never
|
|
15
|
+
* write concurrently and corrupt the store. Exported so `pm reindex` reuses the
|
|
16
|
+
* same id rather than duplicating the literal.
|
|
17
|
+
*/
|
|
18
|
+
export const REINDEX_LOCK_ID = "reindex";
|
|
19
|
+
const PENDING_QUEUE_REL_PATH = "search/pending-refresh.json";
|
|
20
|
+
const PENDING_QUEUE_GATE_REL_PATH = "search/pending-refresh.gate.lock";
|
|
21
|
+
const PENDING_QUEUE_GATE_STALE_MS = 30_000;
|
|
22
|
+
// Bounded reindex-lock retry for the background worker (~3.2s worst case).
|
|
23
|
+
const LOCK_ACQUIRE_ATTEMPTS = 8;
|
|
24
|
+
const LOCK_ACQUIRE_BACKOFF_MS = 400;
|
|
25
|
+
const SEARCH_REFRESH_INLINE_ENV = "PM_SEARCH_REFRESH_INLINE";
|
|
26
|
+
const SEARCH_REFRESH_CHILD_ENV = "PM_SEARCH_REFRESH_CHILD";
|
|
27
|
+
function parseBooleanTrueLike(value) {
|
|
28
|
+
if (typeof value !== "string") {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const normalized = value.trim().toLowerCase();
|
|
32
|
+
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Mutation search refresh runs inline (blocking) under test runners, inside the
|
|
36
|
+
* background worker child itself, or when explicitly requested. Otherwise the
|
|
37
|
+
* semantic refresh is dispatched to a detached child so mutations return without
|
|
38
|
+
* waiting on embeddings. Mirrors the telemetry-flush inline gate so the full test
|
|
39
|
+
* suite stays deterministic.
|
|
40
|
+
*/
|
|
41
|
+
export function shouldRunSearchRefreshInForeground() {
|
|
42
|
+
if (parseBooleanTrueLike(process.env[SEARCH_REFRESH_INLINE_ENV])) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (parseBooleanTrueLike(process.env[SEARCH_REFRESH_CHILD_ENV])) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const nodeEnv = (process.env.NODE_ENV ?? "").trim().toLowerCase();
|
|
49
|
+
return (typeof process.env.VITEST === "string" ||
|
|
50
|
+
typeof process.env.VITEST_WORKER_ID === "string" ||
|
|
51
|
+
nodeEnv === "test");
|
|
52
|
+
}
|
|
53
|
+
function pendingQueuePath(pmRoot) {
|
|
54
|
+
return path.join(pmRoot, PENDING_QUEUE_REL_PATH);
|
|
55
|
+
}
|
|
56
|
+
function pendingQueueGatePath(pmRoot) {
|
|
57
|
+
return path.join(pmRoot, PENDING_QUEUE_GATE_REL_PATH);
|
|
58
|
+
}
|
|
59
|
+
function acquireQueueGate(pmRoot) {
|
|
60
|
+
const gatePath = pendingQueueGatePath(pmRoot);
|
|
61
|
+
try {
|
|
62
|
+
if (Date.now() - statSync(gatePath).mtimeMs < PENDING_QUEUE_GATE_STALE_MS) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
rmSync(gatePath, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Missing gate is the common case; fall through to create it.
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
mkdirSync(path.dirname(gatePath), { recursive: true });
|
|
72
|
+
mkdirSync(gatePath);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function releaseQueueGate(pmRoot) {
|
|
80
|
+
try {
|
|
81
|
+
rmSync(pendingQueueGatePath(pmRoot), { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Best effort; a stale gate self-heals after PENDING_QUEUE_GATE_STALE_MS.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function withQueueGate(pmRoot, fn, fallback) {
|
|
88
|
+
// Briefly serialize read-modify-write access to the pending queue across the
|
|
89
|
+
// mutation process and the worker child. Acquisition is best effort; if a
|
|
90
|
+
// healthy gate is held we skip rather than risk a torn queue.
|
|
91
|
+
for (let attempt = 0; attempt < 50; attempt += 1) {
|
|
92
|
+
if (acquireQueueGate(pmRoot)) {
|
|
93
|
+
try {
|
|
94
|
+
return await fn();
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
releaseQueueGate(pmRoot);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
await delay(20);
|
|
101
|
+
}
|
|
102
|
+
return fallback;
|
|
103
|
+
}
|
|
104
|
+
function delay(ms) {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
setTimeout(resolve, ms).unref?.();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function readPendingQueueIds(pmRoot) {
|
|
110
|
+
const raw = await readFileIfExists(pendingQueuePath(pmRoot));
|
|
111
|
+
if (!raw || raw.trim().length === 0) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(raw);
|
|
116
|
+
if (!Array.isArray(parsed.ids)) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
return parsed.ids.filter((id) => typeof id === "string" && id.length > 0);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function writePendingQueueIds(pmRoot, ids) {
|
|
126
|
+
await writeFileAtomic(pendingQueuePath(pmRoot), `${JSON.stringify({ ids })}\n`);
|
|
127
|
+
}
|
|
128
|
+
/** Merge mutated item ids into the persistent pending-refresh queue. */
|
|
129
|
+
export async function enqueuePendingRefreshIds(pmRoot, itemIds) {
|
|
130
|
+
const incoming = itemIds.filter((id) => typeof id === "string" && id.trim().length > 0);
|
|
131
|
+
if (incoming.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const mergeIncoming = async () => {
|
|
135
|
+
const existing = await readPendingQueueIds(pmRoot);
|
|
136
|
+
const merged = [...new Set([...existing, ...incoming])].sort((left, right) => left.localeCompare(right));
|
|
137
|
+
await writePendingQueueIds(pmRoot, merged);
|
|
138
|
+
};
|
|
139
|
+
const gated = await withQueueGate(pmRoot, async () => {
|
|
140
|
+
await mergeIncoming();
|
|
141
|
+
return true;
|
|
142
|
+
}, false);
|
|
143
|
+
if (!gated) {
|
|
144
|
+
// The gate stayed contended past the retry budget. Never silently drop a
|
|
145
|
+
// mutation's refresh work: fall back to a best-effort unguarded merge.
|
|
146
|
+
// writeFileAtomic keeps the file valid; the only risk is losing a concurrent
|
|
147
|
+
// writer's delta, which its own next dispatch and the vector_index_stale
|
|
148
|
+
// warning both recover.
|
|
149
|
+
await mergeIncoming();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Atomically read and clear the pending-refresh queue, returning drained ids. */
|
|
153
|
+
export async function drainPendingRefreshIds(pmRoot) {
|
|
154
|
+
return withQueueGate(pmRoot, async () => {
|
|
155
|
+
const ids = await readPendingQueueIds(pmRoot);
|
|
156
|
+
if (ids.length > 0) {
|
|
157
|
+
await writePendingQueueIds(pmRoot, []);
|
|
158
|
+
}
|
|
159
|
+
return ids;
|
|
160
|
+
}, []);
|
|
161
|
+
}
|
|
162
|
+
function searchRefreshRunnerPath() {
|
|
163
|
+
return path.join(resolvePmPackageRootFromModule(import.meta.url, ["../../.."]), "dist", "cli", "search-refresh.js");
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Spawn the detached refresh worker child for this pm root. Best effort: a
|
|
167
|
+
* failed dispatch must never keep the CLI alive or fail a mutation; the next
|
|
168
|
+
* mutation re-dispatches and `vector_index_stale` warns about the catch-up
|
|
169
|
+
* window in the meantime.
|
|
170
|
+
*/
|
|
171
|
+
function dispatchRefreshChild(pmRoot) {
|
|
172
|
+
try {
|
|
173
|
+
const child = spawn(process.execPath, [searchRefreshRunnerPath()], {
|
|
174
|
+
detached: true,
|
|
175
|
+
stdio: "ignore",
|
|
176
|
+
env: {
|
|
177
|
+
...process.env,
|
|
178
|
+
PM_PATH: pmRoot,
|
|
179
|
+
[SEARCH_REFRESH_CHILD_ENV]: "1",
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
// A detached child can emit an async 'error' event (e.g. spawn EAGAIN/ENOENT,
|
|
183
|
+
// resource limits). Swallow it so it never becomes an unhandled error that
|
|
184
|
+
// crashes the parent CLI; dispatch is best effort.
|
|
185
|
+
child.on("error", () => { });
|
|
186
|
+
child.unref();
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
// Best effort — see doc comment above.
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Enqueue mutated ids and dispatch a detached worker child to refresh semantic
|
|
194
|
+
* embeddings without blocking the mutation. The reindex lock the worker acquires
|
|
195
|
+
* serializes concurrent refreshes, so the spawn itself stays unconditional and
|
|
196
|
+
* cheap; a worker that loses the lock exits and its ids are drained by the holder.
|
|
197
|
+
*/
|
|
198
|
+
export async function scheduleBackgroundSemanticRefresh(pmRoot, itemIds) {
|
|
199
|
+
await enqueuePendingRefreshIds(pmRoot, itemIds);
|
|
200
|
+
dispatchRefreshChild(pmRoot);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Drain the pending queue and refresh semantic vectors under the reindex lock so
|
|
204
|
+
* the local vector store is never rewritten concurrently. If the lock is held by
|
|
205
|
+
* another worker we exit immediately — that holder drains our enqueued ids. After
|
|
206
|
+
* releasing we re-check the queue once and re-dispatch if a sibling enqueued ids
|
|
207
|
+
* during our final window, guaranteeing eventual processing.
|
|
208
|
+
*/
|
|
209
|
+
export async function runSemanticRefreshWorker(pmRoot, refresh) {
|
|
210
|
+
const warnings = [];
|
|
211
|
+
const processed = [];
|
|
212
|
+
if (!(await pathExists(pmRoot))) {
|
|
213
|
+
return { processed, rounds: 0, warnings };
|
|
214
|
+
}
|
|
215
|
+
let settings;
|
|
216
|
+
try {
|
|
217
|
+
settings = resolveSettingsWithSemanticRuntimeDefaults(await readSettings(pmRoot)).settings;
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return { processed, rounds: 0, warnings: [`search_background_refresh_settings_read_failed:${toErrorMessage(error)}`] };
|
|
221
|
+
}
|
|
222
|
+
// Retry the reindex lock with backoff rather than exiting on the first
|
|
223
|
+
// conflict: a sibling refresh worker holds it only briefly (~one embed), so a
|
|
224
|
+
// few retries pick up the queued ids in this run instead of stranding them
|
|
225
|
+
// until the next mutation. If a long `pm reindex` keeps it, we give up — that
|
|
226
|
+
// full pass re-embeds everything anyway and the next dispatch retries.
|
|
227
|
+
let release = null;
|
|
228
|
+
for (let attempt = 0; attempt < LOCK_ACQUIRE_ATTEMPTS && !release; attempt += 1) {
|
|
229
|
+
try {
|
|
230
|
+
release = await acquireLock(pmRoot, REINDEX_LOCK_ID, settings.locks.ttl_seconds, process.env.PM_AUTHOR ?? "pm-search-refresh", false, settings.governance.force_required_for_stale_lock);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
if (attempt < LOCK_ACQUIRE_ATTEMPTS - 1) {
|
|
234
|
+
await delay(LOCK_ACQUIRE_BACKOFF_MS);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!release) {
|
|
239
|
+
return { processed, rounds: 0, warnings };
|
|
240
|
+
}
|
|
241
|
+
let rounds = 0;
|
|
242
|
+
let failed = false;
|
|
243
|
+
try {
|
|
244
|
+
for (;;) {
|
|
245
|
+
const ids = await drainPendingRefreshIds(pmRoot);
|
|
246
|
+
if (ids.length === 0) {
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
rounds += 1;
|
|
250
|
+
try {
|
|
251
|
+
const result = await refresh(pmRoot, ids);
|
|
252
|
+
processed.push(...result.refreshed);
|
|
253
|
+
warnings.push(...result.warnings);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
warnings.push(`search_background_refresh_failed:${toErrorMessage(error)}`);
|
|
257
|
+
// Re-enqueue so the work is retried by a later dispatch rather than lost.
|
|
258
|
+
await enqueuePendingRefreshIds(pmRoot, ids);
|
|
259
|
+
failed = true;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
await release?.();
|
|
266
|
+
}
|
|
267
|
+
// Close the race where a sibling enqueued ids between our last empty drain and
|
|
268
|
+
// releasing the lock: re-dispatch so those ids are eventually processed. Skip
|
|
269
|
+
// this after a refresh failure — the failed ids were re-enqueued and an
|
|
270
|
+
// immediate respawn would just fail again, spinning indefinitely. They wait
|
|
271
|
+
// for the next mutation's dispatch instead.
|
|
272
|
+
const remaining = failed ? [] : await readPendingQueueIds(pmRoot);
|
|
273
|
+
if (remaining.length > 0) {
|
|
274
|
+
dispatchRefreshChild(pmRoot);
|
|
275
|
+
}
|
|
276
|
+
return { processed: [...new Set(processed)].sort((a, b) => a.localeCompare(b)), rounds, warnings };
|
|
277
|
+
}
|
|
278
|
+
// Expose internals for focused tests without widening the production surface
|
|
279
|
+
// used by the mutation hot path.
|
|
280
|
+
export const _backgroundRefreshInternals = {
|
|
281
|
+
pendingQueuePath,
|
|
282
|
+
acquireQueueGate,
|
|
283
|
+
releaseQueueGate,
|
|
284
|
+
};
|
|
285
|
+
//# sourceMappingURL=background-refresh.js.map
|
|
286
|
+
//# debugId=d8990236-9b78-570d-bafa-5da0ce621293
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-refresh.js","sources":["core/search/background-refresh.ts"],"sourceRoot":"/","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { mkdirSync, rmSync, statSync } from \"node:fs\";\nimport path from \"node:path\";\n\nimport { pathExists, readFileIfExists, writeFileAtomic } from \"../fs/fs-utils.js\";\nimport { acquireLock } from \"../lock/lock.js\";\nimport { resolvePmPackageRootFromModule } from \"../packages/root.js\";\nimport { readSettings } from \"../store/settings.js\";\nimport { toErrorMessage } from \"../shared/primitives.js\";\nimport { resolveSettingsWithSemanticRuntimeDefaults } from \"./semantic-defaults.js\";\n\n/**\n * Shared lock id for any process that rewrites the local vector store. Reindex\n * and the background mutation-refresh worker both acquire this so they never\n * write concurrently and corrupt the store. Exported so `pm reindex` reuses the\n * same id rather than duplicating the literal.\n */\nexport const REINDEX_LOCK_ID = \"reindex\";\n\nconst PENDING_QUEUE_REL_PATH = \"search/pending-refresh.json\";\nconst PENDING_QUEUE_GATE_REL_PATH = \"search/pending-refresh.gate.lock\";\nconst PENDING_QUEUE_GATE_STALE_MS = 30_000;\n\n// Bounded reindex-lock retry for the background worker (~3.2s worst case).\nconst LOCK_ACQUIRE_ATTEMPTS = 8;\nconst LOCK_ACQUIRE_BACKOFF_MS = 400;\n\nconst SEARCH_REFRESH_INLINE_ENV = \"PM_SEARCH_REFRESH_INLINE\";\nconst SEARCH_REFRESH_CHILD_ENV = \"PM_SEARCH_REFRESH_CHILD\";\n\nfunction parseBooleanTrueLike(value: string | undefined): boolean {\n if (typeof value !== \"string\") {\n return false;\n }\n const normalized = value.trim().toLowerCase();\n return normalized === \"1\" || normalized === \"true\" || normalized === \"yes\" || normalized === \"on\";\n}\n\n/**\n * Mutation search refresh runs inline (blocking) under test runners, inside the\n * background worker child itself, or when explicitly requested. Otherwise the\n * semantic refresh is dispatched to a detached child so mutations return without\n * waiting on embeddings. Mirrors the telemetry-flush inline gate so the full test\n * suite stays deterministic.\n */\nexport function shouldRunSearchRefreshInForeground(): boolean {\n if (parseBooleanTrueLike(process.env[SEARCH_REFRESH_INLINE_ENV])) {\n return true;\n }\n if (parseBooleanTrueLike(process.env[SEARCH_REFRESH_CHILD_ENV])) {\n return true;\n }\n const nodeEnv = (process.env.NODE_ENV ?? \"\").trim().toLowerCase();\n return (\n typeof process.env.VITEST === \"string\" ||\n typeof process.env.VITEST_WORKER_ID === \"string\" ||\n nodeEnv === \"test\"\n );\n}\n\nfunction pendingQueuePath(pmRoot: string): string {\n return path.join(pmRoot, PENDING_QUEUE_REL_PATH);\n}\n\nfunction pendingQueueGatePath(pmRoot: string): string {\n return path.join(pmRoot, PENDING_QUEUE_GATE_REL_PATH);\n}\n\nfunction acquireQueueGate(pmRoot: string): boolean {\n const gatePath = pendingQueueGatePath(pmRoot);\n try {\n if (Date.now() - statSync(gatePath).mtimeMs < PENDING_QUEUE_GATE_STALE_MS) {\n return false;\n }\n rmSync(gatePath, { recursive: true, force: true });\n } catch {\n // Missing gate is the common case; fall through to create it.\n }\n try {\n mkdirSync(path.dirname(gatePath), { recursive: true });\n mkdirSync(gatePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction releaseQueueGate(pmRoot: string): void {\n try {\n rmSync(pendingQueueGatePath(pmRoot), { recursive: true, force: true });\n } catch {\n // Best effort; a stale gate self-heals after PENDING_QUEUE_GATE_STALE_MS.\n }\n}\n\nasync function withQueueGate<T>(pmRoot: string, fn: () => Promise<T>, fallback: T): Promise<T> {\n // Briefly serialize read-modify-write access to the pending queue across the\n // mutation process and the worker child. Acquisition is best effort; if a\n // healthy gate is held we skip rather than risk a torn queue.\n for (let attempt = 0; attempt < 50; attempt += 1) {\n if (acquireQueueGate(pmRoot)) {\n try {\n return await fn();\n } finally {\n releaseQueueGate(pmRoot);\n }\n }\n await delay(20);\n }\n return fallback;\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, ms).unref?.();\n });\n}\n\nasync function readPendingQueueIds(pmRoot: string): Promise<string[]> {\n const raw = await readFileIfExists(pendingQueuePath(pmRoot));\n if (!raw || raw.trim().length === 0) {\n return [];\n }\n try {\n const parsed = JSON.parse(raw) as { ids?: unknown };\n if (!Array.isArray(parsed.ids)) {\n return [];\n }\n return parsed.ids.filter((id): id is string => typeof id === \"string\" && id.length > 0);\n } catch {\n return [];\n }\n}\n\nasync function writePendingQueueIds(pmRoot: string, ids: string[]): Promise<void> {\n await writeFileAtomic(pendingQueuePath(pmRoot), `${JSON.stringify({ ids })}\\n`);\n}\n\n/** Merge mutated item ids into the persistent pending-refresh queue. */\nexport async function enqueuePendingRefreshIds(pmRoot: string, itemIds: string[]): Promise<void> {\n const incoming = itemIds.filter((id) => typeof id === \"string\" && id.trim().length > 0);\n if (incoming.length === 0) {\n return;\n }\n const mergeIncoming = async (): Promise<void> => {\n const existing = await readPendingQueueIds(pmRoot);\n const merged = [...new Set([...existing, ...incoming])].sort((left, right) => left.localeCompare(right));\n await writePendingQueueIds(pmRoot, merged);\n };\n const gated = await withQueueGate(\n pmRoot,\n async () => {\n await mergeIncoming();\n return true;\n },\n false,\n );\n if (!gated) {\n // The gate stayed contended past the retry budget. Never silently drop a\n // mutation's refresh work: fall back to a best-effort unguarded merge.\n // writeFileAtomic keeps the file valid; the only risk is losing a concurrent\n // writer's delta, which its own next dispatch and the vector_index_stale\n // warning both recover.\n await mergeIncoming();\n }\n}\n\n/** Atomically read and clear the pending-refresh queue, returning drained ids. */\nexport async function drainPendingRefreshIds(pmRoot: string): Promise<string[]> {\n return withQueueGate(\n pmRoot,\n async () => {\n const ids = await readPendingQueueIds(pmRoot);\n if (ids.length > 0) {\n await writePendingQueueIds(pmRoot, []);\n }\n return ids;\n },\n [],\n );\n}\n\nfunction searchRefreshRunnerPath(): string {\n return path.join(\n resolvePmPackageRootFromModule(import.meta.url, [\"../../..\"]),\n \"dist\",\n \"cli\",\n \"search-refresh.js\",\n );\n}\n\n/**\n * Spawn the detached refresh worker child for this pm root. Best effort: a\n * failed dispatch must never keep the CLI alive or fail a mutation; the next\n * mutation re-dispatches and `vector_index_stale` warns about the catch-up\n * window in the meantime.\n */\nfunction dispatchRefreshChild(pmRoot: string): void {\n try {\n const child = spawn(process.execPath, [searchRefreshRunnerPath()], {\n detached: true,\n stdio: \"ignore\",\n env: {\n ...process.env,\n PM_PATH: pmRoot,\n [SEARCH_REFRESH_CHILD_ENV]: \"1\",\n },\n });\n // A detached child can emit an async 'error' event (e.g. spawn EAGAIN/ENOENT,\n // resource limits). Swallow it so it never becomes an unhandled error that\n // crashes the parent CLI; dispatch is best effort.\n child.on(\"error\", () => {});\n child.unref();\n } catch {\n // Best effort — see doc comment above.\n }\n}\n\n/**\n * Enqueue mutated ids and dispatch a detached worker child to refresh semantic\n * embeddings without blocking the mutation. The reindex lock the worker acquires\n * serializes concurrent refreshes, so the spawn itself stays unconditional and\n * cheap; a worker that loses the lock exits and its ids are drained by the holder.\n */\nexport async function scheduleBackgroundSemanticRefresh(pmRoot: string, itemIds: string[]): Promise<void> {\n await enqueuePendingRefreshIds(pmRoot, itemIds);\n dispatchRefreshChild(pmRoot);\n}\n\nexport interface SemanticRefreshWorkerResult {\n processed: string[];\n rounds: number;\n warnings: string[];\n}\n\ntype SemanticRefreshFn = (\n pmRoot: string,\n itemIds: string[],\n) => Promise<{ refreshed: string[]; skipped: string[]; warnings: string[] }>;\n\n/**\n * Drain the pending queue and refresh semantic vectors under the reindex lock so\n * the local vector store is never rewritten concurrently. If the lock is held by\n * another worker we exit immediately — that holder drains our enqueued ids. After\n * releasing we re-check the queue once and re-dispatch if a sibling enqueued ids\n * during our final window, guaranteeing eventual processing.\n */\nexport async function runSemanticRefreshWorker(\n pmRoot: string,\n refresh: SemanticRefreshFn,\n): Promise<SemanticRefreshWorkerResult> {\n const warnings: string[] = [];\n const processed: string[] = [];\n if (!(await pathExists(pmRoot))) {\n return { processed, rounds: 0, warnings };\n }\n\n let settings: Awaited<ReturnType<typeof readSettings>>;\n try {\n settings = resolveSettingsWithSemanticRuntimeDefaults(await readSettings(pmRoot)).settings;\n } catch (error: unknown) {\n return { processed, rounds: 0, warnings: [`search_background_refresh_settings_read_failed:${toErrorMessage(error)}`] };\n }\n\n // Retry the reindex lock with backoff rather than exiting on the first\n // conflict: a sibling refresh worker holds it only briefly (~one embed), so a\n // few retries pick up the queued ids in this run instead of stranding them\n // until the next mutation. If a long `pm reindex` keeps it, we give up — that\n // full pass re-embeds everything anyway and the next dispatch retries.\n let release: (() => Promise<void>) | null = null;\n for (let attempt = 0; attempt < LOCK_ACQUIRE_ATTEMPTS && !release; attempt += 1) {\n try {\n release = await acquireLock(\n pmRoot,\n REINDEX_LOCK_ID,\n settings.locks.ttl_seconds,\n process.env.PM_AUTHOR ?? \"pm-search-refresh\",\n false,\n settings.governance.force_required_for_stale_lock,\n );\n } catch {\n if (attempt < LOCK_ACQUIRE_ATTEMPTS - 1) {\n await delay(LOCK_ACQUIRE_BACKOFF_MS);\n }\n }\n }\n if (!release) {\n return { processed, rounds: 0, warnings };\n }\n\n let rounds = 0;\n let failed = false;\n try {\n for (;;) {\n const ids = await drainPendingRefreshIds(pmRoot);\n if (ids.length === 0) {\n break;\n }\n rounds += 1;\n try {\n const result = await refresh(pmRoot, ids);\n processed.push(...result.refreshed);\n warnings.push(...result.warnings);\n } catch (error: unknown) {\n warnings.push(`search_background_refresh_failed:${toErrorMessage(error)}`);\n // Re-enqueue so the work is retried by a later dispatch rather than lost.\n await enqueuePendingRefreshIds(pmRoot, ids);\n failed = true;\n break;\n }\n }\n } finally {\n await release?.();\n }\n\n // Close the race where a sibling enqueued ids between our last empty drain and\n // releasing the lock: re-dispatch so those ids are eventually processed. Skip\n // this after a refresh failure — the failed ids were re-enqueued and an\n // immediate respawn would just fail again, spinning indefinitely. They wait\n // for the next mutation's dispatch instead.\n const remaining = failed ? [] : await readPendingQueueIds(pmRoot);\n if (remaining.length > 0) {\n dispatchRefreshChild(pmRoot);\n }\n\n return { processed: [...new Set(processed)].sort((a, b) => a.localeCompare(b)), rounds, warnings };\n}\n\n// Expose internals for focused tests without widening the production surface\n// used by the mutation hot path.\nexport const _backgroundRefreshInternals = {\n pendingQueuePath,\n acquireQueueGate,\n releaseQueueGate,\n};\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,0CAA0C,EAAE,MAAM,wBAAwB,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC;AAEzC,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AAC7D,MAAM,2BAA2B,GAAG,kCAAkC,CAAC;AACvE,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAE3C,2EAA2E;AAC3E,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AAC7D,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAE3D,SAAS,oBAAoB,CAAC,KAAyB;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC9C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utationRefreshResult {
|
|
|
13
13
|
export interface SearchMutationArtifactRefreshResult extends SearchCacheInvalidationResult {
|
|
14
14
|
refreshed: string[];
|
|
15
15
|
skipped: string[];
|
|
16
|
+
/** True when the semantic refresh was dispatched to a detached background worker. */
|
|
17
|
+
scheduled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface RefreshSearchArtifactsForMutationOptions {
|
|
20
|
+
/**
|
|
21
|
+
* When true and semantic search is active, the (slow) embedding refresh is
|
|
22
|
+
* dispatched to a detached background worker instead of awaited inline so the
|
|
23
|
+
* mutation returns immediately. The synchronous keyword-cache invalidation
|
|
24
|
+
* still runs first. Callers pass this only outside test runners.
|
|
25
|
+
*/
|
|
26
|
+
background?: boolean;
|
|
16
27
|
}
|
|
17
28
|
export interface SemanticRefreshOptions {
|
|
18
29
|
settings?: Awaited<ReturnType<typeof readSettings>>;
|
|
@@ -26,4 +37,12 @@ export declare function readVectorizationStatusLedger(pmRoot: string): Promise<V
|
|
|
26
37
|
export declare function writeVectorizationStatusLedger(pmRoot: string, entries: Record<string, string>): Promise<void>;
|
|
27
38
|
export declare function invalidateSearchCacheArtifacts(pmRoot: string): Promise<SearchCacheInvalidationResult>;
|
|
28
39
|
export declare function refreshSemanticEmbeddingsForMutatedItems(pmRoot: string, itemIds: string[], options?: SemanticRefreshOptions): Promise<SemanticMutationRefreshResult>;
|
|
29
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Returns true when a semantic embedding refresh would do real work for these
|
|
42
|
+
* settings (an embedding provider AND a vector store both resolve). Used to
|
|
43
|
+
* decide whether a mutation's refresh is worth dispatching to a background
|
|
44
|
+
* worker — when semantic search is not configured the inline path is already a
|
|
45
|
+
* fast no-op and no child is spawned.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isSemanticRefreshActive(settings: Awaited<ReturnType<typeof readSettings>>, applyRuntimeDefaults: boolean): boolean;
|
|
48
|
+
export declare function refreshSearchArtifactsForMutation(pmRoot: string, itemIds: string[], options?: RefreshSearchArtifactsForMutationOptions): Promise<SearchMutationArtifactRefreshResult>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d04073fd-fa5a-5454-8e71-11bc477005b0")}catch(e){}}();
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { getActiveExtensionRegistrations } from "../extensions/index.js";
|
|
5
5
|
import { pathExists, readFileIfExists, removeFileIfExists, writeFileAtomic } from "../fs/fs-utils.js";
|
|
@@ -12,6 +12,7 @@ import { executeEmbeddingBatchesWithRetry } from "./embedding-batches.js";
|
|
|
12
12
|
import { buildSemanticCorpusInput } from "./corpus.js";
|
|
13
13
|
import { resolveEmbeddingProviders } from "./providers.js";
|
|
14
14
|
import { resolveSettingsWithSemanticRuntimeDefaults } from "./semantic-defaults.js";
|
|
15
|
+
import { scheduleBackgroundSemanticRefresh } from "./background-refresh.js";
|
|
15
16
|
import { executeVectorDelete, executeVectorUpsert, resolveVectorStores } from "./vector-stores.js";
|
|
16
17
|
import { nowIso } from "../shared/time.js";
|
|
17
18
|
export const SEARCH_CACHE_ARTIFACT_PATHS = ["index/manifest.json", "search/embeddings.jsonl"];
|
|
@@ -290,7 +291,20 @@ export async function refreshSemanticEmbeddingsForMutatedItems(pmRoot, itemIds,
|
|
|
290
291
|
warnings: [...workload.warnings, ...refreshedResult.warnings, ...pruneResult.warnings, ...ledgerWarnings],
|
|
291
292
|
};
|
|
292
293
|
}
|
|
293
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Returns true when a semantic embedding refresh would do real work for these
|
|
296
|
+
* settings (an embedding provider AND a vector store both resolve). Used to
|
|
297
|
+
* decide whether a mutation's refresh is worth dispatching to a background
|
|
298
|
+
* worker — when semantic search is not configured the inline path is already a
|
|
299
|
+
* fast no-op and no child is spawned.
|
|
300
|
+
*/
|
|
301
|
+
export function isSemanticRefreshActive(settings, applyRuntimeDefaults) {
|
|
302
|
+
const effectiveSettings = applyRuntimeDefaults
|
|
303
|
+
? resolveSettingsWithSemanticRuntimeDefaults(settings).settings
|
|
304
|
+
: settings;
|
|
305
|
+
return Boolean(resolveEmbeddingProviders(effectiveSettings).active && resolveVectorStores(effectiveSettings).active);
|
|
306
|
+
}
|
|
307
|
+
export async function refreshSearchArtifactsForMutation(pmRoot, itemIds, options = {}) {
|
|
294
308
|
const invalidation = await invalidateSearchCacheArtifacts(pmRoot);
|
|
295
309
|
const normalizedItemIds = toUniqueSorted(itemIds);
|
|
296
310
|
if (normalizedItemIds.length === 0) {
|
|
@@ -333,9 +347,24 @@ export async function refreshSearchArtifactsForMutation(pmRoot, itemIds) {
|
|
|
333
347
|
warnings: invalidation.warnings,
|
|
334
348
|
};
|
|
335
349
|
}
|
|
350
|
+
const applyRuntimeDefaults = settings.search.mutation_refresh_policy === "semantic_auto";
|
|
351
|
+
// Keyword cache is already invalidated synchronously above (so keyword search
|
|
352
|
+
// stays immediately correct). When requested, dispatch the slow embedding
|
|
353
|
+
// refresh to a detached worker so the mutation returns instantly; the
|
|
354
|
+
// vector_index_stale health/search warning covers the catch-up window.
|
|
355
|
+
if (options.background && isSemanticRefreshActive(settings, applyRuntimeDefaults)) {
|
|
356
|
+
await scheduleBackgroundSemanticRefresh(pmRoot, normalizedItemIds);
|
|
357
|
+
return {
|
|
358
|
+
invalidated: invalidation.invalidated,
|
|
359
|
+
refreshed: [],
|
|
360
|
+
skipped: [],
|
|
361
|
+
warnings: [...invalidation.warnings, "search_semantic_refresh_scheduled_background"],
|
|
362
|
+
scheduled: true,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
336
365
|
const semanticRefresh = await refreshSemanticEmbeddingsForMutatedItems(pmRoot, normalizedItemIds, {
|
|
337
366
|
settings,
|
|
338
|
-
apply_runtime_defaults:
|
|
367
|
+
apply_runtime_defaults: applyRuntimeDefaults,
|
|
339
368
|
});
|
|
340
369
|
return {
|
|
341
370
|
invalidated: invalidation.invalidated,
|
|
@@ -345,4 +374,4 @@ export async function refreshSearchArtifactsForMutation(pmRoot, itemIds) {
|
|
|
345
374
|
};
|
|
346
375
|
}
|
|
347
376
|
//# sourceMappingURL=cache.js.map
|
|
348
|
-
//# debugId=
|
|
377
|
+
//# debugId=d04073fd-fa5a-5454-8e71-11bc477005b0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sources":["core/search/cache.ts"],"sourceRoot":"/","sourcesContent":["import path from \"node:path\";\nimport { getActiveExtensionRegistrations } from \"../extensions/index.js\";\nimport { pathExists, readFileIfExists, removeFileIfExists, writeFileAtomic } from \"../fs/fs-utils.js\";\nimport { resolveItemTypeRegistry } from \"../item/type-registry.js\";\nimport { toErrorMessage } from \"../shared/primitives.js\";\nimport { locateItem, readLocatedItem } from \"../store/item-store.js\";\nimport { getSettingsPath } from \"../store/paths.js\";\nimport { readSettings } from \"../store/settings.js\";\nimport { executeEmbeddingBatchesWithRetry } from \"./embedding-batches.js\";\nimport { buildSemanticCorpusInput } from \"./corpus.js\";\nimport { resolveEmbeddingProviders } from \"./providers.js\";\nimport type { EmbeddingProviderConfig } from \"./providers.js\";\nimport { resolveSettingsWithSemanticRuntimeDefaults } from \"./semantic-defaults.js\";\nimport { executeVectorDelete, executeVectorUpsert, resolveVectorStores } from \"./vector-stores.js\";\nimport type { VectorStoreConfig } from \"./vector-stores.js\";\nimport { nowIso } from \"../shared/time.js\";\nimport type { ItemDocument, ItemFrontMatter } from \"../../types/index.js\";\n\nexport const SEARCH_CACHE_ARTIFACT_PATHS = [\"index/manifest.json\", \"search/embeddings.jsonl\"] as const;\nexport const VECTORIZATION_STATUS_LEDGER_PATH = \"search/vectorization-status.json\";\n\nexport interface SearchCacheInvalidationResult {\n invalidated: string[];\n warnings: string[];\n}\n\nexport interface SemanticMutationRefreshResult {\n refreshed: string[];\n skipped: string[];\n warnings: string[];\n}\n\nexport interface SearchMutationArtifactRefreshResult extends SearchCacheInvalidationResult {\n refreshed: string[];\n skipped: string[];\n}\n\nexport interface SemanticRefreshOptions {\n settings?: Awaited<ReturnType<typeof readSettings>>;\n apply_runtime_defaults?: boolean;\n}\n\nexport interface VectorizationStatusLedgerReadResult {\n entries: Record<string, string>;\n warnings: string[];\n}\n\nfunction formatInvalidationWarning(relativePath: string, error: unknown): string {\n return `search_cache_invalidation_failed:${relativePath}:${String(error)}`;\n}\n\n\nfunction toUniqueSorted(values: Iterable<string>): string[] {\n return [...new Set([...values].map((value) => value.trim()).filter((value) => value.length > 0))]\n .sort((left, right) => left.localeCompare(right));\n}\n\nfunction isValidUpdatedAt(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0 && Number.isFinite(Date.parse(value));\n}\n\nfunction normalizeVectorizationLedgerEntries(entries: Record<string, string>): Record<string, string> {\n const normalized = new Map<string, string>();\n for (const [rawId, rawUpdatedAt] of Object.entries(entries)) {\n const id = rawId.trim();\n if (id.length === 0 || !isValidUpdatedAt(rawUpdatedAt)) {\n continue;\n }\n normalized.set(id, rawUpdatedAt);\n }\n return Object.fromEntries([...normalized.entries()].sort((left, right) => left[0].localeCompare(right[0])));\n}\n\nexport async function readVectorizationStatusLedger(pmRoot: string): Promise<VectorizationStatusLedgerReadResult> {\n const ledgerPath = path.join(pmRoot, VECTORIZATION_STATUS_LEDGER_PATH);\n const raw = await readFileIfExists(ledgerPath);\n if (raw === null || raw.trim().length === 0) {\n return {\n entries: {},\n warnings: [],\n };\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw) as unknown;\n } catch {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n (parsed as { version?: unknown }).version !== 1 ||\n !Array.isArray((parsed as { items?: unknown }).items)\n ) {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n\n const mapped = new Map<string, string>();\n for (const entry of (parsed as { items: unknown[] }).items) {\n if (typeof entry !== \"object\" || entry === null) {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n const id = (entry as { id?: unknown }).id;\n const updatedAt = (entry as { updated_at?: unknown }).updated_at;\n if (typeof id !== \"string\" || id.trim().length === 0 || !isValidUpdatedAt(updatedAt)) {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n mapped.set(id.trim(), updatedAt);\n }\n\n return {\n entries: Object.fromEntries([...mapped.entries()].sort((left, right) => left[0].localeCompare(right[0]))),\n warnings: [],\n };\n}\n\nexport async function writeVectorizationStatusLedger(pmRoot: string, entries: Record<string, string>): Promise<void> {\n const normalizedEntries = normalizeVectorizationLedgerEntries(entries);\n const ledgerPath = path.join(pmRoot, VECTORIZATION_STATUS_LEDGER_PATH);\n const serialized = `${JSON.stringify(\n {\n version: 1,\n generated_at: nowIso(),\n items: Object.entries(normalizedEntries).map(([id, updated_at]) => ({\n id,\n updated_at,\n })),\n },\n null,\n 2,\n )}\\n`;\n await writeFileAtomic(ledgerPath, serialized);\n}\n\nfunction buildVectorPayload(item: ItemFrontMatter): Record<string, unknown> {\n return {\n id: item.id,\n type: item.type,\n status: item.status,\n priority: item.priority,\n updated_at: item.updated_at,\n };\n}\n\ninterface SemanticRefreshRuntimeContext {\n settings: Awaited<ReturnType<typeof readSettings>>;\n provider: EmbeddingProviderConfig;\n vectorStore: VectorStoreConfig;\n}\n\ninterface SemanticRefreshWorkload {\n documents: Array<{ id: string; document: ItemDocument }>;\n missingIds: string[];\n skippedIds: string[];\n warnings: string[];\n}\n\ninterface SemanticRefreshOperationResult {\n refreshed: string[];\n skipped: string[];\n warnings: string[];\n}\n\nfunction buildSkippedSemanticRefreshResult(itemIds: string[], warning: string): SemanticMutationRefreshResult {\n return {\n refreshed: [],\n skipped: itemIds,\n warnings: [warning],\n };\n}\n\nasync function resolveSemanticRefreshRuntimeContext(\n pmRoot: string,\n normalizedItemIds: string[],\n options: SemanticRefreshOptions,\n): Promise<SemanticRefreshRuntimeContext | SemanticMutationRefreshResult> {\n if (!options.settings && !(await pathExists(getSettingsPath(pmRoot)))) {\n return buildSkippedSemanticRefreshResult(normalizedItemIds, \"search_semantic_refresh_skipped:settings_not_initialized\");\n }\n\n let settings: Awaited<ReturnType<typeof readSettings>>;\n try {\n settings = options.settings ?? (await readSettings(pmRoot));\n } catch (error: unknown) {\n return buildSkippedSemanticRefreshResult(\n normalizedItemIds,\n `search_semantic_refresh_skipped:settings_read_failed:${toErrorMessage(error)}`,\n );\n }\n const effectiveSettings = options.apply_runtime_defaults\n ? resolveSettingsWithSemanticRuntimeDefaults(settings).settings\n : settings;\n\n const provider = resolveEmbeddingProviders(effectiveSettings).active;\n if (!provider) {\n return buildSkippedSemanticRefreshResult(normalizedItemIds, \"search_semantic_refresh_skipped:provider_unconfigured\");\n }\n const vectorStore = resolveVectorStores(effectiveSettings).active;\n if (!vectorStore) {\n return buildSkippedSemanticRefreshResult(normalizedItemIds, \"search_semantic_refresh_skipped:vector_store_unconfigured\");\n }\n\n return {\n settings: effectiveSettings,\n provider,\n vectorStore,\n };\n}\n\nasync function collectSemanticRefreshWorkload(\n pmRoot: string,\n idPrefix: string,\n preferredFormat: \"toon\" | \"json_markdown\",\n normalizedItemIds: string[],\n typeToFolder: Record<string, string>,\n schema: Awaited<ReturnType<typeof readSettings>>[\"schema\"],\n): Promise<SemanticRefreshWorkload> {\n const warnings: string[] = [];\n const skipped = new Set<string>();\n const missing = new Set<string>();\n const documents: Array<{ id: string; document: ItemDocument }> = [];\n\n for (const itemId of normalizedItemIds) {\n const located = await locateItem(pmRoot, itemId, idPrefix, preferredFormat, typeToFolder);\n if (!located) {\n missing.add(itemId);\n continue;\n }\n\n try {\n const loaded = await readLocatedItem(located, { schema });\n documents.push({\n id: loaded.document.metadata.id,\n document: loaded.document,\n });\n } catch (error: unknown) {\n skipped.add(located.id);\n warnings.push(`search_semantic_refresh_item_read_failed:${located.id}:${toErrorMessage(error)}`);\n }\n }\n\n documents.sort((left, right) => left.id.localeCompare(right.id));\n return {\n documents,\n missingIds: toUniqueSorted(missing),\n skippedIds: toUniqueSorted(skipped),\n warnings,\n };\n}\n\nasync function refreshLocatedSemanticVectors(\n settings: Awaited<ReturnType<typeof readSettings>>,\n provider: EmbeddingProviderConfig,\n vectorStore: VectorStoreConfig,\n documents: Array<{ id: string; document: ItemDocument }>,\n): Promise<SemanticRefreshOperationResult> {\n if (documents.length === 0) {\n return { refreshed: [], skipped: [], warnings: [] };\n }\n\n try {\n const corpusInputs = documents.map((entry) =>\n buildSemanticCorpusInput(entry.document, {\n providerName: provider.name,\n }),\n );\n const embeddingResult = await executeEmbeddingBatchesWithRetry(provider, settings, corpusInputs);\n await executeVectorUpsert(\n vectorStore,\n documents.map((entry, index) => ({\n id: entry.id,\n vector: embeddingResult.vectors[index],\n payload: buildVectorPayload(entry.document.metadata),\n })),\n );\n return {\n refreshed: documents.map((entry) => entry.id),\n skipped: [],\n warnings: embeddingResult.warnings,\n };\n } catch (error: unknown) {\n return {\n refreshed: [],\n skipped: documents.map((entry) => entry.id),\n warnings: [`search_semantic_refresh_failed:${toErrorMessage(error)}`],\n };\n }\n}\n\nasync function pruneMissingSemanticVectors(\n vectorStore: VectorStoreConfig,\n missingIds: string[],\n): Promise<SemanticRefreshOperationResult> {\n if (missingIds.length === 0) {\n return { refreshed: [], skipped: [], warnings: [] };\n }\n try {\n await executeVectorDelete(vectorStore, missingIds);\n return {\n refreshed: [],\n skipped: [],\n warnings: [],\n };\n } catch (error: unknown) {\n return {\n refreshed: [],\n skipped: missingIds,\n warnings: [`search_semantic_refresh_delete_failed:${toErrorMessage(error)}`],\n };\n }\n}\n\nexport async function invalidateSearchCacheArtifacts(pmRoot: string): Promise<SearchCacheInvalidationResult> {\n const invalidated: string[] = [];\n const warnings: string[] = [];\n\n for (const relativePath of SEARCH_CACHE_ARTIFACT_PATHS) {\n const artifactPath = path.join(pmRoot, relativePath);\n try {\n if (!(await pathExists(artifactPath))) {\n continue;\n }\n await removeFileIfExists(artifactPath);\n invalidated.push(relativePath);\n } catch (error: unknown) {\n warnings.push(formatInvalidationWarning(relativePath, error));\n }\n }\n\n return {\n invalidated,\n warnings,\n };\n}\n\nexport async function refreshSemanticEmbeddingsForMutatedItems(\n pmRoot: string,\n itemIds: string[],\n options: SemanticRefreshOptions = {},\n): Promise<SemanticMutationRefreshResult> {\n const normalizedItemIds = toUniqueSorted(itemIds);\n if (normalizedItemIds.length === 0) {\n return {\n refreshed: [],\n skipped: [],\n warnings: [],\n };\n }\n\n const runtimeContext = await resolveSemanticRefreshRuntimeContext(pmRoot, normalizedItemIds, options);\n if (!(\"settings\" in runtimeContext)) {\n return runtimeContext;\n }\n const typeRegistry = resolveItemTypeRegistry(runtimeContext.settings, getActiveExtensionRegistrations());\n const workload = await collectSemanticRefreshWorkload(\n pmRoot,\n runtimeContext.settings.id_prefix,\n runtimeContext.settings.item_format,\n normalizedItemIds,\n typeRegistry.type_to_folder,\n runtimeContext.settings.schema,\n );\n const refreshedResult = await refreshLocatedSemanticVectors(\n runtimeContext.settings,\n runtimeContext.provider,\n runtimeContext.vectorStore,\n workload.documents,\n );\n const pruneResult = await pruneMissingSemanticVectors(runtimeContext.vectorStore, workload.missingIds);\n const refreshedIdSet = new Set(refreshedResult.refreshed);\n const refreshedEntries = Object.fromEntries(\n workload.documents\n .filter((entry) => refreshedIdSet.has(entry.id))\n .map((entry) => [entry.id, entry.document.metadata.updated_at]),\n );\n const ledgerWarnings: string[] = [];\n if (Object.keys(refreshedEntries).length > 0 || workload.missingIds.length > 0) {\n const ledgerRead = await readVectorizationStatusLedger(pmRoot);\n const nextEntries = {\n ...ledgerRead.entries,\n ...normalizeVectorizationLedgerEntries(refreshedEntries),\n };\n for (const missingId of workload.missingIds) {\n delete nextEntries[missingId];\n }\n try {\n await writeVectorizationStatusLedger(pmRoot, nextEntries);\n } catch (error: unknown) {\n ledgerWarnings.push(`search_vectorization_status_ledger_write_failed:${toErrorMessage(error)}`);\n }\n ledgerWarnings.push(...ledgerRead.warnings);\n }\n\n return {\n refreshed: toUniqueSorted([...refreshedResult.refreshed, ...pruneResult.refreshed]),\n skipped: toUniqueSorted([...workload.skippedIds, ...refreshedResult.skipped, ...pruneResult.skipped]),\n warnings: [...workload.warnings, ...refreshedResult.warnings, ...pruneResult.warnings, ...ledgerWarnings],\n };\n}\n\nexport async function refreshSearchArtifactsForMutation(\n pmRoot: string,\n itemIds: string[],\n): Promise<SearchMutationArtifactRefreshResult> {\n const invalidation = await invalidateSearchCacheArtifacts(pmRoot);\n const normalizedItemIds = toUniqueSorted(itemIds);\n if (normalizedItemIds.length === 0) {\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: [],\n warnings: invalidation.warnings,\n };\n }\n\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n const semanticRefresh = await refreshSemanticEmbeddingsForMutatedItems(pmRoot, normalizedItemIds);\n return {\n invalidated: invalidation.invalidated,\n refreshed: semanticRefresh.refreshed,\n skipped: semanticRefresh.skipped,\n warnings: [...invalidation.warnings, ...semanticRefresh.warnings],\n };\n }\n\n let settings: Awaited<ReturnType<typeof readSettings>>;\n try {\n settings = await readSettings(pmRoot);\n } catch (error: unknown) {\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: normalizedItemIds,\n warnings: [\n ...invalidation.warnings,\n `search_semantic_refresh_skipped:settings_read_failed:${toErrorMessage(error)}`,\n ],\n };\n }\n\n if (settings.search.mutation_refresh_policy === \"cache_only\") {\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: normalizedItemIds,\n warnings: invalidation.warnings,\n };\n }\n\n const semanticRefresh = await refreshSemanticEmbeddingsForMutatedItems(pmRoot, normalizedItemIds, {\n settings,\n apply_runtime_defaults: settings.search.mutation_refresh_policy === \"semantic_auto\",\n });\n return {\n invalidated: invalidation.invalidated,\n refreshed: semanticRefresh.refreshed,\n skipped: semanticRefresh.skipped,\n warnings: [...invalidation.warnings, ...semanticRefresh.warnings],\n };\n}\n"],"names":[],"mappings":";;AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,0CAA0C,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEnG,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,qBAAqB,EAAE,yBAAyB,CAAU,CAAC;AACvG,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAC;AA4BnF,SAAS,yBAAyB,CAAC,YAAoB,EAAE,KA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AQ,CAAC;KAClE,CAAC;AACJ,CAAC","debugId":"4a4a71bc-457b-5496-a2e8-e3e3537d01ae"}
|
|
1
|
+
{"version":3,"file":"cache.js","sources":["core/search/cache.ts"],"sourceRoot":"/","sourcesContent":["import path from \"node:path\";\nimport { getActiveExtensionRegistrations } from \"../extensions/index.js\";\nimport { pathExists, readFileIfExists, removeFileIfExists, writeFileAtomic } from \"../fs/fs-utils.js\";\nimport { resolveItemTypeRegistry } from \"../item/type-registry.js\";\nimport { toErrorMessage } from \"../shared/primitives.js\";\nimport { locateItem, readLocatedItem } from \"../store/item-store.js\";\nimport { getSettingsPath } from \"../store/paths.js\";\nimport { readSettings } from \"../store/settings.js\";\nimport { executeEmbeddingBatchesWithRetry } from \"./embedding-batches.js\";\nimport { buildSemanticCorpusInput } from \"./corpus.js\";\nimport { resolveEmbeddingProviders } from \"./providers.js\";\nimport type { EmbeddingProviderConfig } from \"./providers.js\";\nimport { resolveSettingsWithSemanticRuntimeDefaults } from \"./semantic-defaults.js\";\nimport { scheduleBackgroundSemanticRefresh } from \"./background-refresh.js\";\nimport { executeVectorDelete, executeVectorUpsert, resolveVectorStores } from \"./vector-stores.js\";\nimport type { VectorStoreConfig } from \"./vector-stores.js\";\nimport { nowIso } from \"../shared/time.js\";\nimport type { ItemDocument, ItemFrontMatter } from \"../../types/index.js\";\n\nexport const SEARCH_CACHE_ARTIFACT_PATHS = [\"index/manifest.json\", \"search/embeddings.jsonl\"] as const;\nexport const VECTORIZATION_STATUS_LEDGER_PATH = \"search/vectorization-status.json\";\n\nexport interface SearchCacheInvalidationResult {\n invalidated: string[];\n warnings: string[];\n}\n\nexport interface SemanticMutationRefreshResult {\n refreshed: string[];\n skipped: string[];\n warnings: string[];\n}\n\nexport interface SearchMutationArtifactRefreshResult extends SearchCacheInvalidationResult {\n refreshed: string[];\n skipped: string[];\n /** True when the semantic refresh was dispatched to a detached background worker. */\n scheduled?: boolean;\n}\n\nexport interface RefreshSearchArtifactsForMutationOptions {\n /**\n * When true and semantic search is active, the (slow) embedding refresh is\n * dispatched to a detached background worker instead of awaited inline so the\n * mutation returns immediately. The synchronous keyword-cache invalidation\n * still runs first. Callers pass this only outside test runners.\n */\n background?: boolean;\n}\n\nexport interface SemanticRefreshOptions {\n settings?: Awaited<ReturnType<typeof readSettings>>;\n apply_runtime_defaults?: boolean;\n}\n\nexport interface VectorizationStatusLedgerReadResult {\n entries: Record<string, string>;\n warnings: string[];\n}\n\nfunction formatInvalidationWarning(relativePath: string, error: unknown): string {\n return `search_cache_invalidation_failed:${relativePath}:${String(error)}`;\n}\n\n\nfunction toUniqueSorted(values: Iterable<string>): string[] {\n return [...new Set([...values].map((value) => value.trim()).filter((value) => value.length > 0))]\n .sort((left, right) => left.localeCompare(right));\n}\n\nfunction isValidUpdatedAt(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0 && Number.isFinite(Date.parse(value));\n}\n\nfunction normalizeVectorizationLedgerEntries(entries: Record<string, string>): Record<string, string> {\n const normalized = new Map<string, string>();\n for (const [rawId, rawUpdatedAt] of Object.entries(entries)) {\n const id = rawId.trim();\n if (id.length === 0 || !isValidUpdatedAt(rawUpdatedAt)) {\n continue;\n }\n normalized.set(id, rawUpdatedAt);\n }\n return Object.fromEntries([...normalized.entries()].sort((left, right) => left[0].localeCompare(right[0])));\n}\n\nexport async function readVectorizationStatusLedger(pmRoot: string): Promise<VectorizationStatusLedgerReadResult> {\n const ledgerPath = path.join(pmRoot, VECTORIZATION_STATUS_LEDGER_PATH);\n const raw = await readFileIfExists(ledgerPath);\n if (raw === null || raw.trim().length === 0) {\n return {\n entries: {},\n warnings: [],\n };\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw) as unknown;\n } catch {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n (parsed as { version?: unknown }).version !== 1 ||\n !Array.isArray((parsed as { items?: unknown }).items)\n ) {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n\n const mapped = new Map<string, string>();\n for (const entry of (parsed as { items: unknown[] }).items) {\n if (typeof entry !== \"object\" || entry === null) {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n const id = (entry as { id?: unknown }).id;\n const updatedAt = (entry as { updated_at?: unknown }).updated_at;\n if (typeof id !== \"string\" || id.trim().length === 0 || !isValidUpdatedAt(updatedAt)) {\n return {\n entries: {},\n warnings: [\"search_vectorization_status_ledger_invalid\"],\n };\n }\n mapped.set(id.trim(), updatedAt);\n }\n\n return {\n entries: Object.fromEntries([...mapped.entries()].sort((left, right) => left[0].localeCompare(right[0]))),\n warnings: [],\n };\n}\n\nexport async function writeVectorizationStatusLedger(pmRoot: string, entries: Record<string, string>): Promise<void> {\n const normalizedEntries = normalizeVectorizationLedgerEntries(entries);\n const ledgerPath = path.join(pmRoot, VECTORIZATION_STATUS_LEDGER_PATH);\n const serialized = `${JSON.stringify(\n {\n version: 1,\n generated_at: nowIso(),\n items: Object.entries(normalizedEntries).map(([id, updated_at]) => ({\n id,\n updated_at,\n })),\n },\n null,\n 2,\n )}\\n`;\n await writeFileAtomic(ledgerPath, serialized);\n}\n\nfunction buildVectorPayload(item: ItemFrontMatter): Record<string, unknown> {\n return {\n id: item.id,\n type: item.type,\n status: item.status,\n priority: item.priority,\n updated_at: item.updated_at,\n };\n}\n\ninterface SemanticRefreshRuntimeContext {\n settings: Awaited<ReturnType<typeof readSettings>>;\n provider: EmbeddingProviderConfig;\n vectorStore: VectorStoreConfig;\n}\n\ninterface SemanticRefreshWorkload {\n documents: Array<{ id: string; document: ItemDocument }>;\n missingIds: string[];\n skippedIds: string[];\n warnings: string[];\n}\n\ninterface SemanticRefreshOperationResult {\n refreshed: string[];\n skipped: string[];\n warnings: string[];\n}\n\nfunction buildSkippedSemanticRefreshResult(itemIds: string[], warning: string): SemanticMutationRefreshResult {\n return {\n refreshed: [],\n skipped: itemIds,\n warnings: [warning],\n };\n}\n\nasync function resolveSemanticRefreshRuntimeContext(\n pmRoot: string,\n normalizedItemIds: string[],\n options: SemanticRefreshOptions,\n): Promise<SemanticRefreshRuntimeContext | SemanticMutationRefreshResult> {\n if (!options.settings && !(await pathExists(getSettingsPath(pmRoot)))) {\n return buildSkippedSemanticRefreshResult(normalizedItemIds, \"search_semantic_refresh_skipped:settings_not_initialized\");\n }\n\n let settings: Awaited<ReturnType<typeof readSettings>>;\n try {\n settings = options.settings ?? (await readSettings(pmRoot));\n } catch (error: unknown) {\n return buildSkippedSemanticRefreshResult(\n normalizedItemIds,\n `search_semantic_refresh_skipped:settings_read_failed:${toErrorMessage(error)}`,\n );\n }\n const effectiveSettings = options.apply_runtime_defaults\n ? resolveSettingsWithSemanticRuntimeDefaults(settings).settings\n : settings;\n\n const provider = resolveEmbeddingProviders(effectiveSettings).active;\n if (!provider) {\n return buildSkippedSemanticRefreshResult(normalizedItemIds, \"search_semantic_refresh_skipped:provider_unconfigured\");\n }\n const vectorStore = resolveVectorStores(effectiveSettings).active;\n if (!vectorStore) {\n return buildSkippedSemanticRefreshResult(normalizedItemIds, \"search_semantic_refresh_skipped:vector_store_unconfigured\");\n }\n\n return {\n settings: effectiveSettings,\n provider,\n vectorStore,\n };\n}\n\nasync function collectSemanticRefreshWorkload(\n pmRoot: string,\n idPrefix: string,\n preferredFormat: \"toon\" | \"json_markdown\",\n normalizedItemIds: string[],\n typeToFolder: Record<string, string>,\n schema: Awaited<ReturnType<typeof readSettings>>[\"schema\"],\n): Promise<SemanticRefreshWorkload> {\n const warnings: string[] = [];\n const skipped = new Set<string>();\n const missing = new Set<string>();\n const documents: Array<{ id: string; document: ItemDocument }> = [];\n\n for (const itemId of normalizedItemIds) {\n const located = await locateItem(pmRoot, itemId, idPrefix, preferredFormat, typeToFolder);\n if (!located) {\n missing.add(itemId);\n continue;\n }\n\n try {\n const loaded = await readLocatedItem(located, { schema });\n documents.push({\n id: loaded.document.metadata.id,\n document: loaded.document,\n });\n } catch (error: unknown) {\n skipped.add(located.id);\n warnings.push(`search_semantic_refresh_item_read_failed:${located.id}:${toErrorMessage(error)}`);\n }\n }\n\n documents.sort((left, right) => left.id.localeCompare(right.id));\n return {\n documents,\n missingIds: toUniqueSorted(missing),\n skippedIds: toUniqueSorted(skipped),\n warnings,\n };\n}\n\nasync function refreshLocatedSemanticVectors(\n settings: Awaited<ReturnType<typeof readSettings>>,\n provider: EmbeddingProviderConfig,\n vectorStore: VectorStoreConfig,\n documents: Array<{ id: string; document: ItemDocument }>,\n): Promise<SemanticRefreshOperationResult> {\n if (documents.length === 0) {\n return { refreshed: [], skipped: [], warnings: [] };\n }\n\n try {\n const corpusInputs = documents.map((entry) =>\n buildSemanticCorpusInput(entry.document, {\n providerName: provider.name,\n }),\n );\n const embeddingResult = await executeEmbeddingBatchesWithRetry(provider, settings, corpusInputs);\n await executeVectorUpsert(\n vectorStore,\n documents.map((entry, index) => ({\n id: entry.id,\n vector: embeddingResult.vectors[index],\n payload: buildVectorPayload(entry.document.metadata),\n })),\n );\n return {\n refreshed: documents.map((entry) => entry.id),\n skipped: [],\n warnings: embeddingResult.warnings,\n };\n } catch (error: unknown) {\n return {\n refreshed: [],\n skipped: documents.map((entry) => entry.id),\n warnings: [`search_semantic_refresh_failed:${toErrorMessage(error)}`],\n };\n }\n}\n\nasync function pruneMissingSemanticVectors(\n vectorStore: VectorStoreConfig,\n missingIds: string[],\n): Promise<SemanticRefreshOperationResult> {\n if (missingIds.length === 0) {\n return { refreshed: [], skipped: [], warnings: [] };\n }\n try {\n await executeVectorDelete(vectorStore, missingIds);\n return {\n refreshed: [],\n skipped: [],\n warnings: [],\n };\n } catch (error: unknown) {\n return {\n refreshed: [],\n skipped: missingIds,\n warnings: [`search_semantic_refresh_delete_failed:${toErrorMessage(error)}`],\n };\n }\n}\n\nexport async function invalidateSearchCacheArtifacts(pmRoot: string): Promise<SearchCacheInvalidationResult> {\n const invalidated: string[] = [];\n const warnings: string[] = [];\n\n for (const relativePath of SEARCH_CACHE_ARTIFACT_PATHS) {\n const artifactPath = path.join(pmRoot, relativePath);\n try {\n if (!(await pathExists(artifactPath))) {\n continue;\n }\n await removeFileIfExists(artifactPath);\n invalidated.push(relativePath);\n } catch (error: unknown) {\n warnings.push(formatInvalidationWarning(relativePath, error));\n }\n }\n\n return {\n invalidated,\n warnings,\n };\n}\n\nexport async function refreshSemanticEmbeddingsForMutatedItems(\n pmRoot: string,\n itemIds: string[],\n options: SemanticRefreshOptions = {},\n): Promise<SemanticMutationRefreshResult> {\n const normalizedItemIds = toUniqueSorted(itemIds);\n if (normalizedItemIds.length === 0) {\n return {\n refreshed: [],\n skipped: [],\n warnings: [],\n };\n }\n\n const runtimeContext = await resolveSemanticRefreshRuntimeContext(pmRoot, normalizedItemIds, options);\n if (!(\"settings\" in runtimeContext)) {\n return runtimeContext;\n }\n const typeRegistry = resolveItemTypeRegistry(runtimeContext.settings, getActiveExtensionRegistrations());\n const workload = await collectSemanticRefreshWorkload(\n pmRoot,\n runtimeContext.settings.id_prefix,\n runtimeContext.settings.item_format,\n normalizedItemIds,\n typeRegistry.type_to_folder,\n runtimeContext.settings.schema,\n );\n const refreshedResult = await refreshLocatedSemanticVectors(\n runtimeContext.settings,\n runtimeContext.provider,\n runtimeContext.vectorStore,\n workload.documents,\n );\n const pruneResult = await pruneMissingSemanticVectors(runtimeContext.vectorStore, workload.missingIds);\n const refreshedIdSet = new Set(refreshedResult.refreshed);\n const refreshedEntries = Object.fromEntries(\n workload.documents\n .filter((entry) => refreshedIdSet.has(entry.id))\n .map((entry) => [entry.id, entry.document.metadata.updated_at]),\n );\n const ledgerWarnings: string[] = [];\n if (Object.keys(refreshedEntries).length > 0 || workload.missingIds.length > 0) {\n const ledgerRead = await readVectorizationStatusLedger(pmRoot);\n const nextEntries = {\n ...ledgerRead.entries,\n ...normalizeVectorizationLedgerEntries(refreshedEntries),\n };\n for (const missingId of workload.missingIds) {\n delete nextEntries[missingId];\n }\n try {\n await writeVectorizationStatusLedger(pmRoot, nextEntries);\n } catch (error: unknown) {\n ledgerWarnings.push(`search_vectorization_status_ledger_write_failed:${toErrorMessage(error)}`);\n }\n ledgerWarnings.push(...ledgerRead.warnings);\n }\n\n return {\n refreshed: toUniqueSorted([...refreshedResult.refreshed, ...pruneResult.refreshed]),\n skipped: toUniqueSorted([...workload.skippedIds, ...refreshedResult.skipped, ...pruneResult.skipped]),\n warnings: [...workload.warnings, ...refreshedResult.warnings, ...pruneResult.warnings, ...ledgerWarnings],\n };\n}\n\n/**\n * Returns true when a semantic embedding refresh would do real work for these\n * settings (an embedding provider AND a vector store both resolve). Used to\n * decide whether a mutation's refresh is worth dispatching to a background\n * worker — when semantic search is not configured the inline path is already a\n * fast no-op and no child is spawned.\n */\nexport function isSemanticRefreshActive(\n settings: Awaited<ReturnType<typeof readSettings>>,\n applyRuntimeDefaults: boolean,\n): boolean {\n const effectiveSettings = applyRuntimeDefaults\n ? resolveSettingsWithSemanticRuntimeDefaults(settings).settings\n : settings;\n return Boolean(resolveEmbeddingProviders(effectiveSettings).active && resolveVectorStores(effectiveSettings).active);\n}\n\nexport async function refreshSearchArtifactsForMutation(\n pmRoot: string,\n itemIds: string[],\n options: RefreshSearchArtifactsForMutationOptions = {},\n): Promise<SearchMutationArtifactRefreshResult> {\n const invalidation = await invalidateSearchCacheArtifacts(pmRoot);\n const normalizedItemIds = toUniqueSorted(itemIds);\n if (normalizedItemIds.length === 0) {\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: [],\n warnings: invalidation.warnings,\n };\n }\n\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n const semanticRefresh = await refreshSemanticEmbeddingsForMutatedItems(pmRoot, normalizedItemIds);\n return {\n invalidated: invalidation.invalidated,\n refreshed: semanticRefresh.refreshed,\n skipped: semanticRefresh.skipped,\n warnings: [...invalidation.warnings, ...semanticRefresh.warnings],\n };\n }\n\n let settings: Awaited<ReturnType<typeof readSettings>>;\n try {\n settings = await readSettings(pmRoot);\n } catch (error: unknown) {\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: normalizedItemIds,\n warnings: [\n ...invalidation.warnings,\n `search_semantic_refresh_skipped:settings_read_failed:${toErrorMessage(error)}`,\n ],\n };\n }\n\n if (settings.search.mutation_refresh_policy === \"cache_only\") {\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: normalizedItemIds,\n warnings: invalidation.warnings,\n };\n }\n\n const applyRuntimeDefaults = settings.search.mutation_refresh_policy === \"semantic_auto\";\n\n // Keyword cache is already invalidated synchronously above (so keyword search\n // stays immediately correct). When requested, dispatch the slow embedding\n // refresh to a detached worker so the mutation returns instantly; the\n // vector_index_stale health/search warning covers the catch-up window.\n if (options.background && isSemanticRefreshActive(settings, applyRuntimeDefaults)) {\n await scheduleBackgroundSemanticRefresh(pmRoot, normalizedItemIds);\n return {\n invalidated: invalidation.invalidated,\n refreshed: [],\n skipped: [],\n warnings: [...invalidation.warnings, \"search_semantic_refresh_scheduled_background\"],\n scheduled: true,\n };\n }\n\n const semanticRefresh = await refreshSemanticEmbeddingsForMutatedItems(pmRoot, normalizedItemIds, {\n settings,\n apply_runtime_defaults: applyRuntimeDefaults,\n });\n return {\n invalidated: invalidation.invalidated,\n refreshed: semanticRefresh.refreshed,\n skipped: semanticRefresh.skipped,\n warnings: [...invalidation.warnings, ...semanticRefresh.warnings],\n };\n}\n"],"names":[],"mappings":";;AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,C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AAiB,EAAE;QAChG,QAAQ;QACR,sBAAsB,EAAE,oBAAoB;KAC7C,CAAC,CAAC;IACH,OAAO;QACL,WAAW,EAAE,YAAY,CAAC,WAAW;QACrC,SAAS,EAAE,eAAe,CAAC,SAAS;QACpC,OAAO,EAAE,eAAe,CAAC,OAAO;QAChC,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC;KAClE,CAAC;AACJ,CAAC","debugId":"d04073fd-fa5a-5454-8e71-11bc477005b0"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="630033f0-5ded-54a9-b9c4-8c28d7c4dd44")}catch(e){}}();
|
|
3
3
|
import { mkdir, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import { executeSearchJsonRequest, normalizeSearchHttpTimeoutMs, resolveSearchHttpFetcher, } from "./http-client.js";
|
|
@@ -281,11 +281,15 @@ async function persistLanceDbLocalTable(storePath, tableName, table) {
|
|
|
281
281
|
throw new Error(`LanceDB local snapshot directory create failed at '${snapshotDir}': ${toErrorMessage(error)}`);
|
|
282
282
|
}
|
|
283
283
|
const tempPath = join(snapshotDir, `${basename(snapshotPath)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
284
|
+
// Serialize compactly: the snapshot is an internal, gitignored cache re-read via
|
|
285
|
+
// JSON.parse (whitespace-agnostic). Pretty-printing put every embedding float on its
|
|
286
|
+
// own indented line, roughly doubling file size and parse/serialize cost — a real
|
|
287
|
+
// per-mutation latency tax on large indexes. Compact JSON keeps it instant.
|
|
284
288
|
const serialized = `${JSON.stringify({
|
|
285
289
|
version: LANCE_DB_LOCAL_SNAPSHOT_VERSION,
|
|
286
290
|
table: tableName,
|
|
287
291
|
records: buildSnapshotRecords(table),
|
|
288
|
-
}
|
|
292
|
+
})}\n`;
|
|
289
293
|
try {
|
|
290
294
|
await writeFile(tempPath, serialized, "utf8");
|
|
291
295
|
await rename(tempPath, snapshotPath);
|
|
@@ -541,4 +545,4 @@ export async function executeVectorDelete(store, ids, options = {}) {
|
|
|
541
545
|
return normalizeQdrantUpsertResponse(payload);
|
|
542
546
|
}
|
|
543
547
|
//# sourceMappingURL=vector-stores.js.map
|
|
544
|
-
//# debugId=
|
|
548
|
+
//# debugId=630033f0-5ded-54a9-b9c4-8c28d7c4dd44
|