codesift-mcp 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/cli/commands.d.ts.map +1 -1
  2. package/dist/cli/commands.js +14 -1
  3. package/dist/cli/commands.js.map +1 -1
  4. package/dist/cli/hooks/pre-tool-use.d.ts +1 -0
  5. package/dist/cli/hooks/pre-tool-use.d.ts.map +1 -1
  6. package/dist/cli/hooks/pre-tool-use.js +11 -2
  7. package/dist/cli/hooks/pre-tool-use.js.map +1 -1
  8. package/dist/config.d.ts +13 -0
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/config.js +21 -0
  11. package/dist/config.js.map +1 -1
  12. package/dist/formatters-core.d.ts +7 -0
  13. package/dist/formatters-core.d.ts.map +1 -1
  14. package/dist/formatters-core.js +14 -3
  15. package/dist/formatters-core.js.map +1 -1
  16. package/dist/parser/extractors/hono-inline-analyzer.js +2 -2
  17. package/dist/parser/extractors/hono-inline-analyzer.js.map +1 -1
  18. package/dist/register-tool-groups/core/search.d.ts.map +1 -1
  19. package/dist/register-tool-groups/core/search.js +14 -0
  20. package/dist/register-tool-groups/core/search.js.map +1 -1
  21. package/dist/register-tool-groups/core/symbols.d.ts.map +1 -1
  22. package/dist/register-tool-groups/core/symbols.js +50 -5
  23. package/dist/register-tool-groups/core/symbols.js.map +1 -1
  24. package/dist/server.d.ts.map +1 -1
  25. package/dist/server.js +54 -2
  26. package/dist/server.js.map +1 -1
  27. package/dist/storage/_shared.d.ts +21 -0
  28. package/dist/storage/_shared.d.ts.map +1 -1
  29. package/dist/storage/_shared.js +36 -0
  30. package/dist/storage/_shared.js.map +1 -1
  31. package/dist/storage/index-footprint.d.ts +12 -0
  32. package/dist/storage/index-footprint.d.ts.map +1 -0
  33. package/dist/storage/index-footprint.js +41 -0
  34. package/dist/storage/index-footprint.js.map +1 -0
  35. package/dist/storage/index-store.d.ts +30 -3
  36. package/dist/storage/index-store.d.ts.map +1 -1
  37. package/dist/storage/index-store.js +122 -9
  38. package/dist/storage/index-store.js.map +1 -1
  39. package/dist/storage/registry.d.ts.map +1 -1
  40. package/dist/storage/registry.js +64 -1
  41. package/dist/storage/registry.js.map +1 -1
  42. package/dist/storage/sqlite/accessors.d.ts +34 -0
  43. package/dist/storage/sqlite/accessors.d.ts.map +1 -0
  44. package/dist/storage/sqlite/accessors.js +178 -0
  45. package/dist/storage/sqlite/accessors.js.map +1 -0
  46. package/dist/storage/sqlite/connection.d.ts +43 -0
  47. package/dist/storage/sqlite/connection.d.ts.map +1 -0
  48. package/dist/storage/sqlite/connection.js +241 -0
  49. package/dist/storage/sqlite/connection.js.map +1 -0
  50. package/dist/storage/sqlite/errors.d.ts +38 -0
  51. package/dist/storage/sqlite/errors.d.ts.map +1 -0
  52. package/dist/storage/sqlite/errors.js +150 -0
  53. package/dist/storage/sqlite/errors.js.map +1 -0
  54. package/dist/storage/sqlite/index-io.d.ts +49 -0
  55. package/dist/storage/sqlite/index-io.d.ts.map +1 -0
  56. package/dist/storage/sqlite/index-io.js +268 -0
  57. package/dist/storage/sqlite/index-io.js.map +1 -0
  58. package/dist/storage/sqlite/meta.d.ts +41 -0
  59. package/dist/storage/sqlite/meta.d.ts.map +1 -0
  60. package/dist/storage/sqlite/meta.js +28 -0
  61. package/dist/storage/sqlite/meta.js.map +1 -0
  62. package/dist/storage/sqlite/rows.d.ts +64 -0
  63. package/dist/storage/sqlite/rows.d.ts.map +1 -0
  64. package/dist/storage/sqlite/rows.js +186 -0
  65. package/dist/storage/sqlite/rows.js.map +1 -0
  66. package/dist/storage/sqlite/runtime.d.ts +6 -0
  67. package/dist/storage/sqlite/runtime.d.ts.map +1 -0
  68. package/dist/storage/sqlite/runtime.js +31 -0
  69. package/dist/storage/sqlite/runtime.js.map +1 -0
  70. package/dist/storage/sqlite/schema.d.ts +34 -0
  71. package/dist/storage/sqlite/schema.d.ts.map +1 -0
  72. package/dist/storage/sqlite/schema.js +98 -0
  73. package/dist/storage/sqlite/schema.js.map +1 -0
  74. package/dist/storage/sqlite-index-store.d.ts +40 -80
  75. package/dist/storage/sqlite-index-store.d.ts.map +1 -1
  76. package/dist/storage/sqlite-index-store.js +32 -577
  77. package/dist/storage/sqlite-index-store.js.map +1 -1
  78. package/dist/storage/telemetry/config.d.ts.map +1 -1
  79. package/dist/storage/telemetry/config.js +14 -3
  80. package/dist/storage/telemetry/config.js.map +1 -1
  81. package/dist/storage/telemetry/payload.d.ts.map +1 -1
  82. package/dist/storage/telemetry/payload.js +4 -1
  83. package/dist/storage/telemetry/payload.js.map +1 -1
  84. package/dist/storage/telemetry/retro-aggregator.d.ts +27 -0
  85. package/dist/storage/telemetry/retro-aggregator.d.ts.map +1 -0
  86. package/dist/storage/telemetry/retro-aggregator.js +179 -0
  87. package/dist/storage/telemetry/retro-aggregator.js.map +1 -0
  88. package/dist/storage/telemetry/sanitizer.d.ts +30 -0
  89. package/dist/storage/telemetry/sanitizer.d.ts.map +1 -1
  90. package/dist/storage/telemetry/sanitizer.js +23 -0
  91. package/dist/storage/telemetry/sanitizer.js.map +1 -1
  92. package/dist/storage/telemetry/uploader.d.ts.map +1 -1
  93. package/dist/storage/telemetry/uploader.js +6 -0
  94. package/dist/storage/telemetry/uploader.js.map +1 -1
  95. package/dist/storage/workspace-resolver.js +1 -1
  96. package/dist/storage/workspace-resolver.js.map +1 -1
  97. package/dist/tools/index-tools/folder-indexer.d.ts.map +1 -1
  98. package/dist/tools/index-tools/folder-indexer.js +4 -1
  99. package/dist/tools/index-tools/folder-indexer.js.map +1 -1
  100. package/dist/tools/index-tools/registry.d.ts +16 -0
  101. package/dist/tools/index-tools/registry.d.ts.map +1 -1
  102. package/dist/tools/index-tools/registry.js +79 -1
  103. package/dist/tools/index-tools/registry.js.map +1 -1
  104. package/dist/tools/index-tools.d.ts +2 -2
  105. package/dist/tools/index-tools.d.ts.map +1 -1
  106. package/dist/tools/index-tools.js +2 -2
  107. package/dist/tools/index-tools.js.map +1 -1
  108. package/dist/tools/plan-turn/stale-index.d.ts +32 -0
  109. package/dist/tools/plan-turn/stale-index.d.ts.map +1 -1
  110. package/dist/tools/plan-turn/stale-index.js +42 -5
  111. package/dist/tools/plan-turn/stale-index.js.map +1 -1
  112. package/dist/tools/search-tools/types.d.ts +20 -0
  113. package/dist/tools/search-tools/types.d.ts.map +1 -1
  114. package/dist/tools/search-tools/zero-hit.d.ts.map +1 -1
  115. package/dist/tools/search-tools/zero-hit.js +0 -0
  116. package/dist/tools/search-tools/zero-hit.js.map +1 -1
  117. package/dist/tools/status-tools.d.ts +10 -0
  118. package/dist/tools/status-tools.d.ts.map +1 -1
  119. package/dist/tools/status-tools.js +14 -4
  120. package/dist/tools/status-tools.js.map +1 -1
  121. package/dist/tools/symbol-tools.d.ts +95 -1
  122. package/dist/tools/symbol-tools.d.ts.map +1 -1
  123. package/dist/tools/symbol-tools.js +182 -26
  124. package/dist/tools/symbol-tools.js.map +1 -1
  125. package/dist/types.d.ts +6 -0
  126. package/dist/types.d.ts.map +1 -1
  127. package/dist/utils/git-head.d.ts +12 -0
  128. package/dist/utils/git-head.d.ts.map +1 -1
  129. package/dist/utils/git-head.js +25 -0
  130. package/dist/utils/git-head.js.map +1 -1
  131. package/package.json +6 -4
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Runtime availability of `node:sqlite`.
3
+ *
4
+ * The memoised constructor lives HERE and nowhere else. ESM gives one instance per module, so a
5
+ * second copy of `sqliteCtor` (say, re-declared in the barrel rather than re-exported) would fork
6
+ * the memo: `setSqliteCtorForTesting` would pin one copy while the code under test read the other,
7
+ * and nothing about that failure looks like a wiring bug.
8
+ */
9
+ /** `node:sqlite` landed in Node 22.5. The engines floor is still >=20, so its absence is a
10
+ * supported state, not an error — callers fall back to the JSON backend. */
11
+ let sqliteCtor;
12
+ export async function loadSqliteCtor() {
13
+ if (sqliteCtor !== undefined)
14
+ return sqliteCtor;
15
+ try {
16
+ const mod = await import("node:sqlite");
17
+ sqliteCtor = mod.DatabaseSync;
18
+ }
19
+ catch {
20
+ sqliteCtor = null;
21
+ }
22
+ return sqliteCtor;
23
+ }
24
+ export async function isSqliteAvailable() {
25
+ return (await loadSqliteCtor()) !== null;
26
+ }
27
+ /** Tests need to prove the JSON fallback still works on a runtime that has sqlite. */
28
+ export function setSqliteCtorForTesting(ctor) {
29
+ sqliteCtor = ctor;
30
+ }
31
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/storage/sqlite/runtime.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH;6EAC6E;AAC7E,IAAI,UAAsD,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC;IAChD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;QACxC,UAAU,GAAG,GAAG,CAAC,YAAY,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,OAAO,CAAC,MAAM,cAAc,EAAE,CAAC,KAAK,IAAI,CAAC;AAC3C,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,uBAAuB,CAAC,IAAgD;IACtF,UAAU,GAAG,IAAI,CAAC;AACpB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Table definitions and the v1 -> v2 migration, as SQL text only.
3
+ *
4
+ * No behaviour here on purpose: `connection.ts` decides WHEN to run these, under which lock, and
5
+ * what to record afterwards. Keeping the statements inert makes the schema readable as a schema.
6
+ */
7
+ /**
8
+ * v2 dropped the PRIMARY KEY on `symbols.id`.
9
+ *
10
+ * `id` is `repo:file:name:line`, which is NOT unique: a minified bundle puts hundreds of
11
+ * distinct symbols on line 1 of one file, and PHPDoc `@method` synthesis emits a `field`
12
+ * and a `method` at the same line. As a PRIMARY KEY with `ON CONFLICT DO UPDATE`, every
13
+ * such collision silently overwrote the previous row — so the store quietly held fewer
14
+ * symbols than it was given, and re-indexing reproduced the loss instead of repairing it.
15
+ *
16
+ * Measured over the 16 indexes that failed the migration's count check: 73,165 dropped
17
+ * rows, every one carrying content different from the row that survived, and 7,514 of them
18
+ * in real source rather than minified or vendored output.
19
+ *
20
+ * JSON never enforced uniqueness here, so this is parity, not a new tolerance. Lookups by
21
+ * id return the first match exactly as the array scan did.
22
+ */
23
+ export declare const SCHEMA_VERSION = 2;
24
+ export declare const SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS files (\n path TEXT PRIMARY KEY,\n language TEXT NOT NULL,\n symbol_count INTEGER NOT NULL,\n last_modified INTEGER NOT NULL,\n mtime_ms INTEGER,\n stale INTEGER\n);\n\nCREATE TABLE IF NOT EXISTS symbols (\n id TEXT NOT NULL,\n file TEXT NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n start_line INTEGER NOT NULL,\n end_line INTEGER NOT NULL,\n start_col INTEGER,\n end_col INTEGER,\n start_byte INTEGER,\n end_byte INTEGER,\n signature TEXT,\n docstring TEXT,\n source TEXT,\n parent TEXT,\n is_async INTEGER,\n is_exported INTEGER,\n extras TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(file);\nCREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);\nCREATE INDEX IF NOT EXISTS idx_symbols_id ON symbols(id);\n";
25
+ /**
26
+ * v1 -> v2: rebuild `symbols` without the PRIMARY KEY, keeping every row already stored.
27
+ *
28
+ * Rebuilt in place rather than by re-importing: for most repos the JSON source is gone, so
29
+ * the db IS the index — dropping it to force a reindex would trade a store that is merely
30
+ * incomplete for no store at all. This recovers nothing on its own; rows lost under v1 come
31
+ * back when the repo is next indexed from source, which now keeps them.
32
+ */
33
+ export declare const MIGRATE_V1_TO_V2_SQL = "\nALTER TABLE symbols RENAME TO symbols_v1;\nCREATE TABLE symbols (\n id TEXT NOT NULL,\n file TEXT NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n start_line INTEGER NOT NULL,\n end_line INTEGER NOT NULL,\n start_col INTEGER,\n end_col INTEGER,\n start_byte INTEGER,\n end_byte INTEGER,\n signature TEXT,\n docstring TEXT,\n source TEXT,\n parent TEXT,\n is_async INTEGER,\n is_exported INTEGER,\n extras TEXT\n);\nINSERT INTO symbols SELECT * FROM symbols_v1;\nDROP TABLE symbols_v1;\nCREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(file);\nCREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);\nCREATE INDEX IF NOT EXISTS idx_symbols_id ON symbols(id);\n";
34
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,eAAO,MAAM,UAAU,+9BAsCtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,gwBA0BhC,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Table definitions and the v1 -> v2 migration, as SQL text only.
3
+ *
4
+ * No behaviour here on purpose: `connection.ts` decides WHEN to run these, under which lock, and
5
+ * what to record afterwards. Keeping the statements inert makes the schema readable as a schema.
6
+ */
7
+ /**
8
+ * v2 dropped the PRIMARY KEY on `symbols.id`.
9
+ *
10
+ * `id` is `repo:file:name:line`, which is NOT unique: a minified bundle puts hundreds of
11
+ * distinct symbols on line 1 of one file, and PHPDoc `@method` synthesis emits a `field`
12
+ * and a `method` at the same line. As a PRIMARY KEY with `ON CONFLICT DO UPDATE`, every
13
+ * such collision silently overwrote the previous row — so the store quietly held fewer
14
+ * symbols than it was given, and re-indexing reproduced the loss instead of repairing it.
15
+ *
16
+ * Measured over the 16 indexes that failed the migration's count check: 73,165 dropped
17
+ * rows, every one carrying content different from the row that survived, and 7,514 of them
18
+ * in real source rather than minified or vendored output.
19
+ *
20
+ * JSON never enforced uniqueness here, so this is parity, not a new tolerance. Lookups by
21
+ * id return the first match exactly as the array scan did.
22
+ */
23
+ export const SCHEMA_VERSION = 2;
24
+ export const SCHEMA_SQL = `
25
+ CREATE TABLE IF NOT EXISTS meta (
26
+ key TEXT PRIMARY KEY,
27
+ value TEXT NOT NULL
28
+ );
29
+
30
+ CREATE TABLE IF NOT EXISTS files (
31
+ path TEXT PRIMARY KEY,
32
+ language TEXT NOT NULL,
33
+ symbol_count INTEGER NOT NULL,
34
+ last_modified INTEGER NOT NULL,
35
+ mtime_ms INTEGER,
36
+ stale INTEGER
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS symbols (
40
+ id TEXT NOT NULL,
41
+ file TEXT NOT NULL,
42
+ name TEXT NOT NULL,
43
+ kind TEXT NOT NULL,
44
+ start_line INTEGER NOT NULL,
45
+ end_line INTEGER NOT NULL,
46
+ start_col INTEGER,
47
+ end_col INTEGER,
48
+ start_byte INTEGER,
49
+ end_byte INTEGER,
50
+ signature TEXT,
51
+ docstring TEXT,
52
+ source TEXT,
53
+ parent TEXT,
54
+ is_async INTEGER,
55
+ is_exported INTEGER,
56
+ extras TEXT
57
+ );
58
+
59
+ CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(file);
60
+ CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);
61
+ CREATE INDEX IF NOT EXISTS idx_symbols_id ON symbols(id);
62
+ `;
63
+ /**
64
+ * v1 -> v2: rebuild `symbols` without the PRIMARY KEY, keeping every row already stored.
65
+ *
66
+ * Rebuilt in place rather than by re-importing: for most repos the JSON source is gone, so
67
+ * the db IS the index — dropping it to force a reindex would trade a store that is merely
68
+ * incomplete for no store at all. This recovers nothing on its own; rows lost under v1 come
69
+ * back when the repo is next indexed from source, which now keeps them.
70
+ */
71
+ export const MIGRATE_V1_TO_V2_SQL = `
72
+ ALTER TABLE symbols RENAME TO symbols_v1;
73
+ CREATE TABLE symbols (
74
+ id TEXT NOT NULL,
75
+ file TEXT NOT NULL,
76
+ name TEXT NOT NULL,
77
+ kind TEXT NOT NULL,
78
+ start_line INTEGER NOT NULL,
79
+ end_line INTEGER NOT NULL,
80
+ start_col INTEGER,
81
+ end_col INTEGER,
82
+ start_byte INTEGER,
83
+ end_byte INTEGER,
84
+ signature TEXT,
85
+ docstring TEXT,
86
+ source TEXT,
87
+ parent TEXT,
88
+ is_async INTEGER,
89
+ is_exported INTEGER,
90
+ extras TEXT
91
+ );
92
+ INSERT INTO symbols SELECT * FROM symbols_v1;
93
+ DROP TABLE symbols_v1;
94
+ CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(file);
95
+ CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);
96
+ CREATE INDEX IF NOT EXISTS idx_symbols_id ON symbols(id);
97
+ `;
98
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/storage/sqlite/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCzB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BnC,CAAC"}
@@ -1,89 +1,49 @@
1
- import type { DatabaseSync as DatabaseSyncType } from "node:sqlite";
2
- import type { CodeIndex, CodeSymbol, FileEntry } from "../types.js";
3
- export declare function loadSqliteCtor(): Promise<typeof DatabaseSyncType | null>;
4
- export declare function isSqliteAvailable(): Promise<boolean>;
5
- /** Tests need to prove the JSON fallback still works on a runtime that has sqlite. */
6
- export declare function setSqliteCtorForTesting(ctor: typeof DatabaseSyncType | null | undefined): void;
7
1
  /**
8
- * A storage fault, as distinct from "this repo has no index".
2
+ * SQLite backend for the per-repo index. See docs/adr/ADR-003-index-storage-format.md.
9
3
  *
10
- * Both used to arrive at callers as `null`, so a locked or corrupt database was indistinguishable
11
- * from an unindexed repo: tools reported "not indexed" (prompting a pointless full reindex over a
12
- * database that was merely busy) or returned empty results that read as an authoritative "no
13
- * matches". Empty-because-broken is the worst answer an index can give, because nothing about it
14
- * looks wrong.
15
- */
16
- export declare class IndexStorageError extends Error {
17
- readonly code: string;
18
- readonly path: string;
19
- constructor(message: string, code: string, path: string, options?: {
20
- cause?: unknown;
21
- });
22
- }
23
- /**
24
- * Structural check, not `instanceof`.
4
+ * The point of this module is NOT that SQL is nicer than JSON. It is that the JSON blob
5
+ * forced every write to cost the size of the whole repo: `saveIncremental` re-parsed and
6
+ * re-serialised 262 MB to record one edited file, and the PostToolUse hook — a fresh process
7
+ * per edit, so it can never batch — paid that on every single Write/Edit an agent made.
8
+ * Here a one-file re-index touches one row.
25
9
  *
26
- * A duplicated module instance (bundler, worker/thread boundary, a test importing through a
27
- * different specifier) makes `instanceof` false for an object that is in every observable way
28
- * the right error — and the failure mode is silent: the fault falls into the "unexpected error"
29
- * branch and gets reported as an unindexed repo, which is the exact bug this file exists to
30
- * prevent.
31
- */
32
- export declare function isIndexStorageError(err: unknown): err is IndexStorageError;
33
- /** The operational code for `err`, or null when it is not an operational failure. */
34
- export declare function classifyStorageError(err: unknown): string | null;
35
- export declare const SCHEMA_VERSION = 1;
36
- /**
37
- * Open (and cache) a connection, creating the schema on first use.
10
+ * Fidelity over elegance: hot fields get real columns (so a full load builds objects without
11
+ * parsing anything), and the rarely-populated tail (`tokens`, `decorators`, `extends`,
12
+ * `implements`, `meta`) is kept as one JSON `extras` column. That keeps the round-trip
13
+ * lossless for language-specific fields nobody here should have to know about, while the
14
+ * common symbol costs zero JSON.parse calls.
38
15
  *
39
- * WAL is the reason this migration solves a problem a sharded JSON layout would not: the MCP
40
- * server and the `codesift postindex-file` hook are separate processes writing the same
41
- * index, and WAL gives them concurrent readers with a single writer instead of a corruption
42
- * window. `busy_timeout` makes a writer wait its turn rather than throwing SQLITE_BUSY when
43
- * an agent edits files faster than the previous write settles.
44
- */
45
- export declare function openIndexDb(dbPath: string): Promise<DatabaseSyncType>;
46
- /** Close one cached connection (tests, and the shutdown path). */
47
- export declare function closeIndexDb(dbPath: string): void;
48
- export declare function closeAllIndexDbs(): void;
49
- /** Replace the entire index. Used by full (re)indexing and by JSON->SQLite migration. */
50
- export declare function saveIndexSqlite(dbPath: string, index: CodeIndex): Promise<void>;
51
- /**
52
- * Import a legacy JSON index, but only if this db is still empty — decided and written
53
- * inside ONE `BEGIN IMMEDIATE` transaction.
16
+ * ---------------------------------------------------------------------------
54
17
  *
55
- * The check-then-act cannot be done in JS: `codesift postindex-file` is a fresh process per
56
- * edit, so two of them (or one plus the server) can both observe an empty db, both read the
57
- * same legacy JSON, and the slower writer then overwrites an incremental update the faster
58
- * one already committed. An in-process guard cannot see the other process at all.
18
+ * This file is the FACADE. The implementation lives in `./sqlite/`:
59
19
  *
60
- * `BEGIN IMMEDIATE` takes the write lock before the emptiness check, so the second writer
61
- * either waits and then sees the committed import (returns false), or fails on busy_timeout —
62
- * never silently clobbers. Returns true when this call performed the import.
63
- */
64
- export declare function importLegacyIndexIfEmpty(dbPath: string, index: CodeIndex): Promise<boolean>;
65
- /** Materialise the whole index. Returns null when the db has never been written to. */
66
- export declare function loadIndexSqlite(dbPath: string): Promise<CodeIndex | null>;
67
- /**
68
- * One file's `mtime_ms`, without materialising the index.
20
+ * runtime.ts is node:sqlite present, and the memoised constructor
21
+ * errors.ts operational fault vs "nothing indexed here"
22
+ * schema.ts table definitions and the v1 -> v2 migration, as SQL text
23
+ * rows.ts row <-> domain mapping, and the byte accounting for it
24
+ * connection.ts open/close/cache, schema creation, migration, meta k/v
25
+ * meta.ts the optional meta fields, and the summary shape
26
+ * index-io.ts whole-index read and write — the paths that touch every row
27
+ * accessors.ts narrow reads that never materialise the index
69
28
  *
70
- * `file-indexer.ts` used to parse the whole blob for exactly this value and then
71
- * `saveIncremental` parsed it a second time — two full parses of 262 MB to decide whether a
72
- * 40-line file had changed.
73
- */
74
- export declare function getFileMtimeSqlite(dbPath: string, filePath: string): Promise<number | undefined>;
75
- /** One file's `files[]` entry, without materialising the index. */
76
- export declare function getFileEntrySqlite(dbPath: string, filePath: string): Promise<FileEntry | undefined>;
77
- /** Replace one file's symbols (and optionally its files[] entry) in a single transaction. */
78
- export declare function saveIncrementalSqlite(dbPath: string, updatedFile: string, newSymbols: CodeSymbol[], fileEntry?: FileEntry): Promise<void>;
79
- /** Drop a deleted file's symbols and its files[] entry. */
80
- export declare function removeFileFromIndexSqlite(dbPath: string, deletedFile: string): Promise<void>;
81
- /** All symbols for one file — lets per-file tools skip the whole-index load. */
82
- export declare function getSymbolsForFileSqlite(dbPath: string, filePath: string): Promise<CodeSymbol[]>;
83
- /**
84
- * Cross-process change counter. SQLite bumps `data_version` when *another* connection
85
- * commits, which is the invalidation signal a plain JSON file never had — and the reason an
86
- * in-memory index cache becomes safe here despite the hook writing from its own process.
29
+ * The path stays because 12 modules import it; keeping it as a re-export means the split is
30
+ * provably behaviour-preserving rather than an API change dressed as a refactor.
31
+ *
32
+ * Two invariants this arrangement rests on, both invisible to a type-check:
33
+ *
34
+ * - The memoised `node:sqlite` constructor lives ONLY in `runtime.ts`, and the open-connection
35
+ * cache ONLY in `connection.ts`. ESM gives one instance per module, so re-exporting is safe
36
+ * and re-DECLARING is not: a second copy of either forks the state, and the result is a
37
+ * `closeIndexDb` that closes a handle somebody else is still handing out.
38
+ * `tests/storage/sqlite-module-state.test.ts` fails on exactly that fork.
39
+ * - The re-exports below are an explicit list, not `export *`. Adding an export to a submodule
40
+ * should be a decision about this facade, not a side effect of writing a helper.
87
41
  */
88
- export declare function getDataVersion(dbPath: string): Promise<number>;
42
+ export { isSqliteAvailable, loadSqliteCtor, setSqliteCtorForTesting } from "./sqlite/runtime.js";
43
+ export { IndexStorageError, classifyStorageError, isIndexStorageError } from "./sqlite/errors.js";
44
+ export { SCHEMA_VERSION } from "./sqlite/schema.js";
45
+ export { closeAllIndexDbs, closeIndexDb, openIndexDb } from "./sqlite/connection.js";
46
+ export type { IndexSummary } from "./sqlite/meta.js";
47
+ export { importLegacyIndexIfEmpty, loadIndexSqlite, saveIndexSqlite, wasLossilyMigrated, } from "./sqlite/index-io.js";
48
+ export { getDataVersion, getFileEntrySqlite, getFileMtimeSqlite, getSymbolsForFileSqlite, loadIndexSummarySqlite, removeFileFromIndexSqlite, saveIncrementalSqlite, } from "./sqlite/accessors.js";
89
49
  //# sourceMappingURL=sqlite-index-store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite-index-store.d.ts","sourceRoot":"","sources":["../../src/storage/sqlite-index-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAa,MAAM,aAAa,CAAC;AA0B/E,wBAAsB,cAAc,IAAI,OAAO,CAAC,OAAO,gBAAgB,GAAG,IAAI,CAAC,CAS9E;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE1D;AAED,sFAAsF;AACtF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAE9F;AAMD;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAGxC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,E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