@spuentesp/lain-mcp 0.7.4 → 0.8.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.
package/README.md CHANGED
@@ -18,12 +18,27 @@ npx @spuentesp/lain-mcp mcp
18
18
  - A native binary downloaded from the matching GitHub release.
19
19
  - A cache entry separated by LAIN version and platform target.
20
20
  - SHA-256 verification against the release's `SHA256SUMS` file.
21
+ - A `lain --version` check that must match the npm package version.
22
+
23
+ The launcher downloads into a temporary directory and only moves verified
24
+ files into the versioned cache. It checks cached binaries again before running
25
+ them. A verified cache entry works offline.
26
+
27
+ ## Published targets
28
+
29
+ | Host | Target | Current status |
30
+ |---|---|---|
31
+ | x86-64 Linux | `x86_64-unknown-linux-gnu` | Supported |
32
+ | Apple silicon | `aarch64-apple-darwin` | Supported |
33
+ | x86-64 Windows | `x86_64-pc-windows-msvc` | The repository contains the `DirectML.dll` packaging repair; `v0.7.4` predates it |
34
+
35
+ The release workflow doesn't currently publish x86-64 macOS or ARM64 Linux
36
+ archives. On those hosts, build Lain from source.
21
37
 
22
38
  ## Configuration
23
39
 
24
40
  Set `LAIN_VERSION` to run a different published version. Set
25
41
  `LAIN_CACHE_DIR` to override the operating system's user cache directory.
26
- An already verified cache entry works offline.
27
42
 
28
43
  ## Usage
29
44
 
package/bin/lain.js CHANGED
@@ -10,8 +10,23 @@ ensureBinary().then((binary) => {
10
10
  process.exitCode = 1;
11
11
  });
12
12
  child.on('exit', (code, signal) => {
13
- if (signal) process.kill(process.pid, signal);
14
- else process.exitCode = code == null ? 1 : code;
13
+ if (signal) {
14
+ process.kill(process.pid, signal);
15
+ return;
16
+ }
17
+ const exitCode = code == null ? 1 : code;
18
+ if (exitCode < 0 || exitCode > 255) {
19
+ // Windows NTSTATUS values arrive as large integers (a missing
20
+ // runtime DLL gives 0xC0000135). Assigning one to
21
+ // process.exitCode throws a RangeError during Node's exit path,
22
+ // which kills the process silently with code 1 — report the real
23
+ // status and clamp instead.
24
+ const status = (exitCode >>> 0).toString(16);
25
+ process.stderr.write(`Lain exited with Windows status 0x${status}; 0xc0000135 means a runtime DLL (DirectML.dll) is missing next to lain.exe\n`);
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ process.exitCode = exitCode;
15
30
  });
16
31
  }).catch((error) => {
17
32
  process.stderr.write(`Failed to prepare Lain: ${error.message}\n`);
package/bin/lain.test.js CHANGED
@@ -9,4 +9,6 @@ assert(source.includes("require('../scripts/runtime')"));
9
9
  assert(source.includes('process.argv.slice(2)'));
10
10
  assert(source.includes("stdio: 'inherit'"));
11
11
  assert(!source.includes("'.lain'"), 'launcher must not hard-code the legacy shared cache');
12
+ assert(source.includes('Windows status'), 'launcher must surface Windows NTSTATUS exits instead of dying silently');
13
+ assert(source.includes('exitCode > 255') || source.includes('exitCode < 0 || exitCode > 255'), 'launcher must clamp out-of-range exit codes');
12
14
  process.stdout.write('launcher delegates cache selection and forwards arguments\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spuentesp/lain-mcp",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "mcpName": "io.github.spuentesp/lain",
5
5
  "description": "High-performance knowledge graph MCP server for AI coding agents with semantic search.",
6
6
  "keywords": [
@@ -50,6 +50,41 @@ test('checksum mismatch fails closed', () => {
50
50
  } finally { fs.rmSync(directory, { recursive: true, force: true }); }
51
51
  });
52
52
 
53
+ test('Windows runtime DLLs are installed beside the executable', () => {
54
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'lain-windows-dlls-'));
55
+ const source = path.join(directory, 'source');
56
+ const destination = path.join(directory, 'cache');
57
+ fs.mkdirSync(source);
58
+ fs.mkdirSync(destination);
59
+ fs.writeFileSync(path.join(source, 'DirectML.dll'), 'authenticated archive bytes');
60
+ fs.writeFileSync(path.join(source, 'not-a-runtime.txt'), 'leave me behind');
61
+ try {
62
+ const installed = runtime.installWindowsRuntimeDlls(source, destination, 'win32');
63
+ assert.deepStrictEqual(installed, ['DirectML.dll']);
64
+ assert(fs.existsSync(path.join(destination, 'DirectML.dll')));
65
+ assert(fs.existsSync(path.join(source, 'not-a-runtime.txt')));
66
+ runtime.verifyWindowsRuntimeDlls(destination, 'win32');
67
+ } finally { fs.rmSync(directory, { recursive: true, force: true }); }
68
+ });
69
+
70
+ test('Windows install fails clearly when DirectML.dll is absent', () => {
71
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'lain-windows-dlls-missing-'));
72
+ const source = path.join(directory, 'source');
73
+ const destination = path.join(directory, 'cache');
74
+ fs.mkdirSync(source);
75
+ fs.mkdirSync(destination);
76
+ try {
77
+ assert.throws(
78
+ () => runtime.installWindowsRuntimeDlls(source, destination, 'win32'),
79
+ /missing DirectML\.dll/
80
+ );
81
+ assert.throws(
82
+ () => runtime.verifyWindowsRuntimeDlls(destination, 'win32'),
83
+ /missing DirectML\.dll/
84
+ );
85
+ } finally { fs.rmSync(directory, { recursive: true, force: true }); }
86
+ });
87
+
53
88
  if (process.platform !== 'win32') {
54
89
  test('verified install is atomic and a second invocation is offline', async () => {
55
90
  const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'lain-install-'));
@@ -89,6 +124,51 @@ if (process.platform !== 'win32') {
89
124
  assert.throws(() => runtime.verifyBinary(executable, '1.2.3'), /expected/);
90
125
  } finally { fs.rmSync(directory, { recursive: true, force: true }); }
91
126
  });
127
+
128
+ test('verified install unpacks sidecar binary if present', async () => {
129
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'lain-install-sidecar-'));
130
+ const source = path.join(directory, 'source');
131
+ const cache = path.join(directory, 'cache');
132
+ fs.mkdirSync(source);
133
+ const executable = path.join(source, 'lain');
134
+ fs.writeFileSync(executable, '#!/bin/sh\nprintf "lain 1.2.3\\n"\n');
135
+ fs.chmodSync(executable, 0o755);
136
+ const sidecar = path.join(source, 'lain-git-sidecar');
137
+ fs.writeFileSync(sidecar, '#!/bin/sh\nprintf "lain-git-sidecar 1.2.3\\n"\n');
138
+ fs.chmodSync(sidecar, 0o755);
139
+ const asset = runtime.assetName('1.2.3', 'x86_64-unknown-linux-gnu');
140
+ const archive = path.join(source, asset);
141
+ execFileSync('tar', ['czf', archive, '-C', source, 'lain', 'lain-git-sidecar']);
142
+ const digest = crypto.createHash('sha256').update(fs.readFileSync(archive)).digest('hex');
143
+ fs.writeFileSync(path.join(source, 'SHA256SUMS'), `${digest} ${asset}\n`);
144
+ let downloads = 0;
145
+ const download = async (url, destination) => {
146
+ downloads += 1;
147
+ fs.copyFileSync(path.join(source, path.basename(url)), destination);
148
+ };
149
+ const options = { version: '1.2.3', platform: 'linux', arch: 'x64', env: { LAIN_CACHE_DIR: cache }, download };
150
+ try {
151
+ const installed = await runtime.ensureBinary(options);
152
+ assert.strictEqual(downloads, 2);
153
+ assert.strictEqual(fs.statSync(installed).mode & 0o777, 0o755);
154
+ const installedSidecar = path.join(path.dirname(installed), 'lain-git-sidecar');
155
+ assert(fs.existsSync(installedSidecar), 'sidecar binary should exist alongside main binary');
156
+ assert.strictEqual(fs.statSync(installedSidecar).mode & 0o777, 0o755);
157
+ assert(!fs.readdirSync(path.dirname(installed)).some((name) => name.startsWith('.install-')));
158
+ await runtime.ensureBinary({ ...options, download: async () => { throw new Error('network used'); } });
159
+ assert.strictEqual(downloads, 2);
160
+ } finally { fs.rmSync(directory, { recursive: true, force: true }); }
161
+ });
162
+
163
+ test('downloaded sidecar binary version must match the selected release', () => {
164
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'lain-sidecar-version-'));
165
+ try {
166
+ const executable = path.join(directory, 'lain-git-sidecar');
167
+ fs.writeFileSync(executable, '#!/bin/sh\nprintf "lain-git-sidecar 9.9.9\\n"\n');
168
+ fs.chmodSync(executable, 0o755);
169
+ assert.throws(() => runtime.verifySidecarBinary(executable, '1.2.3'), /expected/);
170
+ } finally { fs.rmSync(directory, { recursive: true, force: true }); }
171
+ });
92
172
  }
93
173
 
94
174
  (async () => {
@@ -68,6 +68,42 @@ function verifyBinary(file, version) {
68
68
  if (reported !== `lain ${normalizeVersion(version)}`) throw new Error(`Downloaded binary reports ${JSON.stringify(reported)}, expected "lain ${normalizeVersion(version)}"`);
69
69
  }
70
70
 
71
+ function verifySidecarBinary(file, version) {
72
+ const result = spawnSync(file, ['--version'], { encoding: 'utf8', timeout: 10_000 });
73
+ if (result.error) throw new Error(`Cannot run downloaded sidecar: ${result.error.message}`);
74
+ if (result.status !== 0) throw new Error(`Downloaded sidecar exited ${result.status} during version check`);
75
+ const reported = String(result.stdout).trim();
76
+ if (reported !== `lain-git-sidecar ${normalizeVersion(version)}`) throw new Error(`Downloaded sidecar reports ${JSON.stringify(reported)}, expected "lain-git-sidecar ${normalizeVersion(version)}"`);
77
+ }
78
+
79
+ function installWindowsRuntimeDlls(source, destination, platform = process.platform) {
80
+ if (platform !== 'win32') return [];
81
+ const dlls = fs.readdirSync(source).filter((name) => name.toLowerCase().endsWith('.dll'));
82
+ if (!dlls.some((name) => name.toLowerCase() === 'directml.dll')) {
83
+ throw new Error('Windows release archive is missing DirectML.dll required by the Lain executable');
84
+ }
85
+ for (const name of dlls) {
86
+ const from = path.join(source, name);
87
+ const to = path.join(destination, name);
88
+ try {
89
+ fs.renameSync(from, to);
90
+ } catch (error) {
91
+ // Another concurrent npx invocation may have installed the same
92
+ // version first. The aggregate archive checksum authenticates the
93
+ // DLL bytes, and versioned cache directories keep releases apart.
94
+ if (!fs.existsSync(to)) throw error;
95
+ }
96
+ }
97
+ return dlls;
98
+ }
99
+
100
+ function verifyWindowsRuntimeDlls(directory, platform = process.platform) {
101
+ if (platform !== 'win32') return;
102
+ if (!fs.existsSync(path.join(directory, 'DirectML.dll'))) {
103
+ throw new Error('Cached Windows installation is missing DirectML.dll; remove this version from LAIN_CACHE_DIR and retry');
104
+ }
105
+ }
106
+
71
107
  function download(url, destination, redirects = 5) {
72
108
  return new Promise((resolve, reject) => {
73
109
  const request = https.get(url, { headers: { 'User-Agent': '@spuentesp/lain-mcp' } }, (response) => {
@@ -107,11 +143,17 @@ async function ensureBinary(options = {}) {
107
143
  const version = normalizeVersion(options.version || selectedVersion(env));
108
144
  const target = targetFor(platform, arch);
109
145
  const finalBinary = binaryPath(version, target, env, platform);
146
+ const directory = path.dirname(finalBinary);
147
+ const sidecarName = platform === 'win32' ? 'lain-git-sidecar.exe' : 'lain-git-sidecar';
148
+ const finalSidecar = path.join(directory, sidecarName);
110
149
  if (fs.existsSync(finalBinary)) {
150
+ verifyWindowsRuntimeDlls(directory, platform);
111
151
  verifyBinary(finalBinary, version);
152
+ if (fs.existsSync(finalSidecar)) {
153
+ verifySidecarBinary(finalSidecar, version);
154
+ }
112
155
  return finalBinary;
113
156
  }
114
- const directory = path.dirname(finalBinary);
115
157
  fs.mkdirSync(directory, { recursive: true });
116
158
  const temporary = path.join(directory, `.install-${process.pid}-${crypto.randomBytes(6).toString('hex')}`);
117
159
  fs.mkdirSync(temporary);
@@ -128,6 +170,18 @@ async function ensureBinary(options = {}) {
128
170
  if (!fs.existsSync(extracted)) throw new Error(`${asset} does not contain the Lain executable at its root`);
129
171
  if (platform !== 'win32') fs.chmodSync(extracted, 0o755);
130
172
  verifyBinary(extracted, version);
173
+ const extractedSidecar = path.join(temporary, sidecarName);
174
+ if (fs.existsSync(extractedSidecar)) {
175
+ if (platform !== 'win32') fs.chmodSync(extractedSidecar, 0o755);
176
+ verifySidecarBinary(extractedSidecar, version);
177
+ try {
178
+ fs.renameSync(extractedSidecar, finalSidecar);
179
+ } catch (error) {
180
+ if (!fs.existsSync(finalSidecar)) throw error;
181
+ verifySidecarBinary(finalSidecar, version);
182
+ }
183
+ }
184
+ installWindowsRuntimeDlls(temporary, directory, platform);
131
185
  try {
132
186
  fs.renameSync(extracted, finalBinary);
133
187
  } catch (error) {
@@ -140,4 +194,4 @@ async function ensureBinary(options = {}) {
140
194
  }
141
195
  }
142
196
 
143
- module.exports = { assetName, binaryPath, cacheRoot, ensureBinary, normalizeVersion, parseChecksum, releaseUrl, selectedVersion, sha256, targetFor, verifyArchive, verifyBinary };
197
+ module.exports = { assetName, binaryPath, cacheRoot, ensureBinary, installWindowsRuntimeDlls, normalizeVersion, parseChecksum, releaseUrl, selectedVersion, sha256, targetFor, verifyArchive, verifyBinary, verifySidecarBinary, verifyWindowsRuntimeDlls };