context-mode 1.0.36 → 1.0.38

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/start.mjs CHANGED
@@ -1,10 +1,52 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync } from "node:child_process";
3
- import { existsSync, readFileSync, writeFileSync, readdirSync } from "node:fs";
3
+ import { existsSync, copyFileSync, readFileSync, writeFileSync, readdirSync } from "node:fs";
4
4
  import { dirname, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { homedir } from "node:os";
7
- import { ensureNativeCompat } from "./native-abi.mjs";
7
+ import { createRequire } from "node:module";
8
+
9
+ /**
10
+ * ABI-aware native binary caching for better-sqlite3 (#148).
11
+ * Users with mise/asdf may run concurrent sessions with different Node versions.
12
+ * Each ABI needs its own compiled binary — cache them side-by-side.
13
+ */
14
+ function ensureNativeCompat(pluginRoot) {
15
+ try {
16
+ const abi = process.versions.modules;
17
+ const nativeDir = resolve(pluginRoot, "node_modules", "better-sqlite3", "build", "Release");
18
+ const binaryPath = resolve(nativeDir, "better_sqlite3.node");
19
+ const abiCachePath = resolve(nativeDir, `better_sqlite3.abi${abi}.node`);
20
+
21
+ if (!existsSync(nativeDir)) return;
22
+
23
+ if (existsSync(abiCachePath)) {
24
+ copyFileSync(abiCachePath, binaryPath);
25
+ return;
26
+ }
27
+
28
+ if (!existsSync(binaryPath)) return;
29
+
30
+ try {
31
+ const req = createRequire(resolve(pluginRoot, "package.json"));
32
+ req("better-sqlite3");
33
+ copyFileSync(binaryPath, abiCachePath);
34
+ } catch (probeErr) {
35
+ if (probeErr?.message?.includes("NODE_MODULE_VERSION")) {
36
+ execSync("npm rebuild better-sqlite3", {
37
+ cwd: pluginRoot,
38
+ stdio: "pipe",
39
+ timeout: 60000,
40
+ });
41
+ if (existsSync(binaryPath)) {
42
+ copyFileSync(binaryPath, abiCachePath);
43
+ }
44
+ }
45
+ }
46
+ } catch {
47
+ /* best effort — server will report the error on first DB access */
48
+ }
49
+ }
8
50
 
9
51
  const __dirname = dirname(fileURLToPath(import.meta.url));
10
52
  const originalCwd = process.cwd();
package/native-abi.mjs DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * ABI-aware native binary caching for better-sqlite3.
3
- *
4
- * Users with mise/asdf may run concurrent Claude Code sessions with
5
- * different Node.js versions. Each ABI needs its own compiled binary.
6
- * This module caches per-ABI binaries side-by-side so switching between
7
- * Node versions is instant after the first encounter.
8
- *
9
- * @see https://github.com/mksglu/context-mode/issues/148
10
- */
11
-
12
- import { existsSync, copyFileSync } from "node:fs";
13
- import { resolve } from "node:path";
14
- import { execSync } from "node:child_process";
15
- import { createRequire } from "node:module";
16
-
17
- /**
18
- * Ensure better-sqlite3 native binary matches the current Node.js ABI.
19
- *
20
- * @param {string} pluginRoot — root directory containing node_modules/
21
- * @param {object} [opts] — options for testing
22
- * @param {boolean} [opts.skipProbe] — skip loading the binary to check ABI (for testing with fake binaries)
23
- * @param {function} [opts.rebuild] — custom rebuild function (for testing without running npm)
24
- */
25
- export function ensureNativeCompat(pluginRoot, opts = {}) {
26
- try {
27
- const abi = process.versions.modules;
28
- const nativeDir = resolve(pluginRoot, "node_modules", "better-sqlite3", "build", "Release");
29
- const binaryPath = resolve(nativeDir, "better_sqlite3.node");
30
- const abiCachePath = resolve(nativeDir, `better_sqlite3.abi${abi}.node`);
31
-
32
- if (!existsSync(nativeDir)) return;
33
-
34
- if (existsSync(abiCachePath)) {
35
- // Fast path: cached binary for this ABI — swap it in
36
- copyFileSync(abiCachePath, binaryPath);
37
- return;
38
- }
39
-
40
- if (!existsSync(binaryPath)) return;
41
-
42
- if (opts.skipProbe) {
43
- // Testing mode: assume binary is compatible, just cache it
44
- copyFileSync(binaryPath, abiCachePath);
45
- return;
46
- }
47
-
48
- // Probe: try loading current binary to check ABI compatibility
49
- try {
50
- const req = createRequire(resolve(pluginRoot, "package.json"));
51
- req("better-sqlite3");
52
- // Compatible — cache for future sessions
53
- copyFileSync(binaryPath, abiCachePath);
54
- } catch (probeErr) {
55
- if (probeErr?.message?.includes("NODE_MODULE_VERSION")) {
56
- // ABI mismatch — rebuild
57
- const rebuildFn = opts.rebuild ?? (() => {
58
- execSync("npm rebuild better-sqlite3", {
59
- cwd: pluginRoot,
60
- stdio: "pipe",
61
- timeout: 60000,
62
- });
63
- });
64
- rebuildFn();
65
- if (existsSync(binaryPath)) {
66
- copyFileSync(binaryPath, abiCachePath);
67
- }
68
- }
69
- }
70
- } catch {
71
- /* best effort — server will report the error on first DB access */
72
- }
73
- }