@nano-step/nano-brain 2026.8.2601 → 2026.11.2102

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.
@@ -14,6 +14,12 @@ const REPO = "nano-step/nano-brain";
14
14
  const PLATFORM_MAP = {
15
15
  darwin: "darwin",
16
16
  linux: "linux",
17
+ // Windows was partially implemented (binaryPath() + tryAutoLink() + run.js
18
+ // already handle win32 / .exe) but PLATFORM_MAP was never extended, so the
19
+ // postinstall threw "Unsupported platform: win32-x64" before any of that
20
+ // code could run. Map win32 → "windows" so the release asset is named
21
+ // nano-brain-windows-amd64(.exe) (#637).
22
+ win32: "windows",
17
23
  };
18
24
  const ARCH_MAP = {
19
25
  arm64: "arm64",
@@ -32,6 +38,14 @@ function getPlatformKey() {
32
38
  return `${platform}-${arch}`;
33
39
  }
34
40
 
41
+ // Windows binaries are .exe — both the Go build output and the GitHub release
42
+ // asset. Match the local binaryPath() convention so the downloaded file lands
43
+ // at binaryPath() after the safeUnlink+download (#637).
44
+ function platformExtension(platform) {
45
+ platform = platform || os.platform();
46
+ return platform === "win32" ? ".exe" : "";
47
+ }
48
+
35
49
  // Remove a partial download without throwing. A socket error can fire before
36
50
  // createWriteStream has opened the file, or after a redirect branch already
37
51
  // removed it — an unguarded fs.unlinkSync then throws ENOENT *inside* the
@@ -273,6 +287,19 @@ function binaryPath() {
273
287
  return path.join(__dirname, binName);
274
288
  }
275
289
 
290
+ function binaryMatchesVersion(output, expectedVersion) {
291
+ if (typeof output !== "string" || typeof expectedVersion !== "string") return false;
292
+ try {
293
+ const parsed = JSON.parse(output.trim());
294
+ if (parsed && typeof parsed.version === "string") {
295
+ return normalizeVersion(parsed.version) === normalizeVersion(expectedVersion);
296
+ }
297
+ } catch (_) {
298
+ // Fall back to raw check when output is not JSON
299
+ }
300
+ return output.includes(expectedVersion);
301
+ }
302
+
276
303
  // Download-and-verify the platform binary to binaryPath() and return that path.
277
304
  // THROWS on failure (never calls process.exit) so both the install-time caller
278
305
  // (main) and the run-time caller (run.js) can choose their own exit behavior.
@@ -291,7 +318,7 @@ async function ensureBinary() {
291
318
  if (fs.existsSync(binPath)) {
292
319
  try {
293
320
  const output = execFileSync(binPath, ["version", "--json"], { timeout: 5000 }).toString();
294
- if (output.includes(VERSION)) {
321
+ if (binaryMatchesVersion(output, VERSION)) {
295
322
  return binPath;
296
323
  }
297
324
  console.error("Existing nano-brain binary is a different version; re-downloading.");
@@ -306,7 +333,7 @@ async function ensureBinary() {
306
333
 
307
334
  console.error(`Downloading nano-brain v${VERSION} for ${platformKey}...`);
308
335
 
309
- const assetName = `nano-brain-${platformKey}`;
336
+ const assetName = `nano-brain-${platformKey}${platformExtension()}`;
310
337
  let lastErr;
311
338
 
312
339
  const attempt = async (tag, suffix) => {
@@ -370,4 +397,4 @@ if (require.main === module) {
370
397
  main();
371
398
  }
372
399
 
373
- module.exports = { parseSHA256Line, download, downloadWithHash, verifySHA256, tryAutoLink, safeUnlink, ensureBinary, binaryPath };
400
+ module.exports = { parseSHA256Line, download, downloadWithHash, verifySHA256, tryAutoLink, safeUnlink, ensureBinary, binaryPath, getPlatformKey, platformExtension, binaryMatchesVersion };
@@ -7,7 +7,7 @@ const path = require("node:path");
7
7
  const os = require("node:os");
8
8
  const crypto = require("node:crypto");
9
9
  const { spawnSync } = require("node:child_process");
10
- const { parseSHA256Line, tryAutoLink, safeUnlink, download, downloadWithHash, ensureBinary, binaryPath } = require("./postinstall");
10
+ const { parseSHA256Line, tryAutoLink, safeUnlink, download, downloadWithHash, ensureBinary, binaryPath, getPlatformKey, platformExtension, binaryMatchesVersion } = require("./postinstall");
11
11
  const VERSION = require("../package.json").version;
12
12
  const isWin = os.platform() === "win32";
13
13
 
@@ -31,6 +31,13 @@ test("ensureBinary: returns existing binary without downloading", { skip: isWin
31
31
  }
32
32
  });
33
33
 
34
+ test("binaryMatchesVersion: normalizes v-prefix and leading zeros (#644)", () => {
35
+ assert.strictEqual(binaryMatchesVersion('{"version":"v2026.9.0703"}\n', "2026.9.703"), true);
36
+ assert.strictEqual(binaryMatchesVersion('{"version":"v2026.11.2101"}\n', "2026.11.2101"), true);
37
+ assert.strictEqual(binaryMatchesVersion('{"version":"0.0.0-dev"}\n', "0.0.0-dev"), true);
38
+ assert.strictEqual(binaryMatchesVersion('{"version":"v2026.11.2101"}\n', "2026.11.210"), false);
39
+ });
40
+
34
41
  // #594 BLOCKER regression: an unsupported platform must REJECT (not process.exit),
35
42
  // so run.js can report it and exit 1. getPlatformKey throws; ensureBinary propagates.
36
43
  test("ensureBinary: rejects (does not exit) on unsupported platform", async () => {
@@ -43,6 +50,72 @@ test("ensureBinary: rejects (does not exit) on unsupported platform", async () =
43
50
  }
44
51
  });
45
52
 
53
+ // #637: Windows was partially implemented (binaryPath, tryAutoLink, run.js all
54
+ // special-case win32) but PLATFORM_MAP never included it — postinstall threw
55
+ // "Unsupported platform: win32-x64". These guard that gap from regressing.
56
+ test("getPlatformKey: returns windows-amd64 on win32+x64", () => {
57
+ const realPlatform = os.platform;
58
+ const realArch = os.arch;
59
+ os.platform = () => "win32";
60
+ os.arch = () => "x64";
61
+ try {
62
+ assert.strictEqual(getPlatformKey(), "windows-amd64");
63
+ } finally {
64
+ os.platform = realPlatform;
65
+ os.arch = realArch;
66
+ }
67
+ });
68
+
69
+ test("getPlatformKey: returns windows-arm64 on win32+arm64", () => {
70
+ const realPlatform = os.platform;
71
+ const realArch = os.arch;
72
+ os.platform = () => "win32";
73
+ os.arch = () => "arm64";
74
+ try {
75
+ assert.strictEqual(getPlatformKey(), "windows-arm64");
76
+ } finally {
77
+ os.platform = realPlatform;
78
+ os.arch = realArch;
79
+ }
80
+ });
81
+
82
+ test("platformExtension: returns .exe on win32, '' elsewhere", () => {
83
+ assert.strictEqual(platformExtension("win32"), ".exe");
84
+ assert.strictEqual(platformExtension("darwin"), "");
85
+ assert.strictEqual(platformExtension("linux"), "");
86
+ });
87
+
88
+ test("platformExtension: defaults to current os.platform() when called with no arg", () => {
89
+ const expected = os.platform() === "win32" ? ".exe" : "";
90
+ assert.strictEqual(platformExtension(), expected);
91
+ });
92
+
93
+ test("ensureBinary: accepts win32+x64 without 'Unsupported platform' (#637 regression)", async () => {
94
+ const realPlatform = os.platform;
95
+ const realArch = os.arch;
96
+ const realExists = fs.existsSync;
97
+ os.platform = () => "win32";
98
+ os.arch = () => "x64";
99
+ // No existing binary at binaryPath() — force ensureBinary into the download
100
+ // path so getPlatformKey() runs end-to-end. ECONNREFUSED is acceptable; the
101
+ // assertion is that the failure is NOT the "Unsupported platform" branch.
102
+ fs.existsSync = () => false;
103
+ try {
104
+ await assert.rejects(() => ensureBinary(), (err) => {
105
+ assert.ok(err instanceof Error);
106
+ assert.ok(
107
+ !/Unsupported platform/.test(err.message),
108
+ `should not throw Unsupported platform on win32+x64, got: ${err.message}`,
109
+ );
110
+ return true;
111
+ });
112
+ } finally {
113
+ os.platform = realPlatform;
114
+ os.arch = realArch;
115
+ fs.existsSync = realExists;
116
+ }
117
+ });
118
+
46
119
  // #594: run.js executes the binary NANO_BRAIN_BIN points to (override path),
47
120
  // end-to-end via a subprocess — proves the wrapper's exec path works.
48
121
  test("run.js: runs NANO_BRAIN_BIN target and exits 0", { skip: isWin }, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nano-step/nano-brain",
3
- "version": "2026.8.2601",
3
+ "version": "2026.11.2102",
4
4
  "description": "Persistent memory and code intelligence for AI coding agents",
5
5
  "bin": {
6
6
  "nano-brain": "npm/run.js"