@colbymchenry/codegraph 1.1.5 → 1.1.6

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.
@@ -119,4 +119,24 @@ export declare const DATABASE_FILENAME = "codegraph.db";
119
119
  * Get the default database path for a project
120
120
  */
121
121
  export declare function getDatabasePath(projectRoot: string): string;
122
+ /**
123
+ * Delete a database file and its WAL sidecars (`-wal`/`-shm`).
124
+ *
125
+ * This is how a FULL re-index discards an existing database — rather than
126
+ * opening the old graph and DELETE-ing every row. On a large or pre-fix
127
+ * poisoned index (e.g. an old graph that scanned an ignored gitlink corpus into
128
+ * ~1.6M nodes with a multi-GB WAL, #1065) the per-row `nodes_fts` delete-trigger
129
+ * churn blocks the main thread long enough to trip the #850 liveness watchdog
130
+ * before indexing even starts, so the rebuild could never recover the bad state
131
+ * (#1067). Unlinking is O(1) regardless of DB size and also reclaims the disk
132
+ * the bloated WAL would otherwise keep.
133
+ *
134
+ * POSIX removes the directory entry even while another process (a daemon/MCP
135
+ * server) still holds the file open; that holder heals via `reopenIfReplaced`
136
+ * (#925). On Windows a live holder can make the unlink fail with EBUSY/EPERM —
137
+ * that is thrown for the caller to surface ("stop the other process and retry").
138
+ * The `-wal`/`-shm` sidecars are best-effort: SQLite recreates them on the next
139
+ * open, so a leftover sidecar is harmless.
140
+ */
141
+ export declare function removeDatabaseFiles(dbPath: string): void;
122
142
  //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -110,6 +110,23 @@ export declare class CodeGraph {
110
110
  * @returns A CodeGraph instance
111
111
  */
112
112
  static open(projectRoot: string, options?: OpenOptions): Promise<CodeGraph>;
113
+ /**
114
+ * Rebuild the project's database from scratch and return a fresh, empty
115
+ * instance — the "same result as a fresh init" semantics that `codegraph
116
+ * index` documents.
117
+ *
118
+ * Unlike `open()` followed by `clear()`, this DISCARDS the existing
119
+ * `.codegraph/codegraph.db` (and its `-wal`/`-shm` sidecars) before
120
+ * re-initializing, instead of opening the old database and DELETE-ing every
121
+ * row. On a large or pre-fix poisoned index — e.g. an old graph that scanned
122
+ * an ignored gitlink corpus (#1065) into ~1.6M nodes with a multi-GB WAL —
123
+ * the per-row `nodes_fts` delete-trigger churn blocks the main thread long
124
+ * enough to trip the #850 liveness watchdog before indexing even starts, so a
125
+ * full re-index could never recover the bad state (#1067). Discarding the
126
+ * files is O(1) regardless of size, reclaims the disk, and sidesteps opening
127
+ * (and running migrations against) the poisoned database entirely.
128
+ */
129
+ static recreate(projectRoot: string): Promise<CodeGraph>;
113
130
  /**
114
131
  * Open synchronously (without sync)
115
132
  */
package/npm-shim.js CHANGED
@@ -105,7 +105,7 @@ async function selfHealBundle() {
105
105
  // Already downloaded by a previous run? Use it even when downloads are
106
106
  // disabled — CODEGRAPH_NO_DOWNLOAD blocks fetching, not a cached bundle.
107
107
  var cached = launcherIn(dest);
108
- if (cached) return cached;
108
+ if (cached) { pruneOldBundles(bundlesDir, dest); return cached; }
109
109
 
110
110
  if (process.env.CODEGRAPH_NO_DOWNLOAD) {
111
111
  fail('the network fallback is disabled (CODEGRAPH_NO_DOWNLOAD is set).');
@@ -149,6 +149,7 @@ async function selfHealBundle() {
149
149
 
150
150
  var ready = launcherIn(dest);
151
151
  if (!ready) fail('downloaded bundle is missing its launcher under ' + dest + '.');
152
+ pruneOldBundles(bundlesDir, dest);
152
153
  process.stderr.write('codegraph: bundle ready.\n');
153
154
  return ready;
154
155
  }
@@ -230,6 +231,27 @@ function rmrf(p) {
230
231
  try { fs.rmSync(p, { recursive: true, force: true }); } catch (e) { /* best effort */ }
231
232
  }
232
233
 
234
+ // Drop sibling bundles for OTHER versions of this same platform target, keeping
235
+ // only keepDir. The self-heal cache otherwise accumulates a full ~50 MB bundle
236
+ // per version forever (issue #1074). Best-effort: a locked/busy dir (a
237
+ // concurrent run still mapping an older node.exe on Windows) just stays — rmrf
238
+ // already swallows its own errors, and the readdir is guarded — so cleanup can
239
+ // never break a working command. Only this target's "<target>-<version>" dirs
240
+ // are touched; other platforms' bundles and the ".dl-*" staging dirs are left
241
+ // alone.
242
+ function pruneOldBundles(bundlesDir, keepDir) {
243
+ var keep = path.basename(keepDir);
244
+ try {
245
+ var names = fs.readdirSync(bundlesDir);
246
+ for (var i = 0; i < names.length; i++) {
247
+ var name = names[i];
248
+ if (name === keep) continue;
249
+ if (name.indexOf(target + '-') !== 0) continue;
250
+ rmrf(path.join(bundlesDir, name));
251
+ }
252
+ } catch (e) { /* best effort — never break a working run over cleanup */ }
253
+ }
254
+
233
255
  function fail(reason) {
234
256
  process.stderr.write(
235
257
  'codegraph: no prebuilt bundle for ' + target + '.\n' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colbymchenry/codegraph",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Local-first code intelligence for AI agents (MCP). Self-contained — bundles its own runtime.",
5
5
  "bin": {
6
6
  "codegraph": "npm-shim.js"
@@ -15,12 +15,12 @@
15
15
  "./package.json": "./package.json"
16
16
  },
17
17
  "optionalDependencies": {
18
- "@colbymchenry/codegraph-darwin-arm64": "1.1.5",
19
- "@colbymchenry/codegraph-darwin-x64": "1.1.5",
20
- "@colbymchenry/codegraph-linux-arm64": "1.1.5",
21
- "@colbymchenry/codegraph-linux-x64": "1.1.5",
22
- "@colbymchenry/codegraph-win32-arm64": "1.1.5",
23
- "@colbymchenry/codegraph-win32-x64": "1.1.5"
18
+ "@colbymchenry/codegraph-darwin-arm64": "1.1.6",
19
+ "@colbymchenry/codegraph-darwin-x64": "1.1.6",
20
+ "@colbymchenry/codegraph-linux-arm64": "1.1.6",
21
+ "@colbymchenry/codegraph-linux-x64": "1.1.6",
22
+ "@colbymchenry/codegraph-win32-arm64": "1.1.6",
23
+ "@colbymchenry/codegraph-win32-x64": "1.1.6"
24
24
  },
25
25
  "files": [
26
26
  "npm-shim.js",