glasspane-harness 0.14.9 → 0.14.12

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
@@ -157,7 +157,7 @@ npm install -g glasspane-harness
157
157
  bun add -g glasspane-harness
158
158
 
159
159
  # or one-click (npm first, GitHub release asset as fallback)
160
- curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.9/scripts/install.sh | bash
160
+ curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.12/scripts/install.sh | bash
161
161
  ```
162
162
 
163
163
  Two commands are installed: **`glasspane-harness`** and the short alias **`gp-harness`**. npm and
package/README.zh-CN.md CHANGED
@@ -135,7 +135,7 @@ Azure、OpenRouter 等等全在——几百个模型——每一个都用**你
135
135
  ```bash
136
136
  npm install -g glasspane-harness # 推荐
137
137
  bun add -g glasspane-harness
138
- curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.9/scripts/install.sh | bash
138
+ curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.12/scripts/install.sh | bash
139
139
  ```
140
140
 
141
141
  会装出两个命令:**`glasspane-harness`** 与短别名 **`gp-harness`**。npm 与 bun 从 wrapper 的
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "scripts": {
26
26
  "postinstall": "node ./postinstall.mjs"
27
27
  },
28
- "version": "0.14.9",
28
+ "version": "0.14.12",
29
29
  "license": "MIT",
30
30
  "os": [
31
31
  "darwin"
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "sideEffects": false,
46
46
  "optionalDependencies": {
47
- "glasspane-harness-darwin-arm64": "0.14.9",
48
- "glasspane-harness-darwin-x64": "0.14.9"
47
+ "glasspane-harness-darwin-arm64": "0.14.12",
48
+ "glasspane-harness-darwin-x64": "0.14.12"
49
49
  }
50
50
  }
package/postinstall.mjs CHANGED
@@ -5,6 +5,7 @@ import fs from "fs"
5
5
  import os from "os"
6
6
  import path from "path"
7
7
  import { fileURLToPath } from "url"
8
+ import { createHash } from "crypto"
8
9
 
9
10
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
11
  const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
@@ -320,25 +321,53 @@ function installPackage(name) {
320
321
 
321
322
  const temp = fs.mkdtempSync(path.join(os.tmpdir(), "glasspane-harness-install-"))
322
323
  try {
324
+ // The registry has to be named. npm resolves `npm_config_registry` (which npm exports
325
+ // into lifecycle scripts), `NPM_CONFIG_REGISTRY`, `~/.npmrc` and a project `.npmrc`, so
326
+ // without this the bytes fetched here — then chmod 0755 and executed — come from
327
+ // whatever mirror the ambient config names, and the package's integrity hash is
328
+ // self-attested by that same mirror. `script/verify-published.ts` passes `--registry`
329
+ // for exactly this reason; the install path is the one that runs on a user's machine.
330
+ //
331
+ // This branch then goes one step further than "name the registry": it downloads the
332
+ // tarball with `npm pack`, re-computes its sha512, and refuses it unless that hash equals
333
+ // the `dist.integrity` the registry itself advertises. npm's own integrity check happens
334
+ // against the registry's self-attested metadata during unpack — a mirror that serves a
335
+ // tampered tarball can attest it with matching metadata. Comparing the bytes WE downloaded
336
+ // against the registry's own claim closes that: `npm install <tarball>` below consumes
337
+ // exactly the bytes we verified, never a re-fetch.
338
+ const integrityProbe = childProcess.spawnSync(
339
+ "npm",
340
+ ["view", `${name}@${version}`, "dist.integrity", "--registry", REGISTRY],
341
+ { encoding: "utf8", windowsHide: true },
342
+ )
343
+ const declaredIntegrity = (integrityProbe.stdout ?? "").trim()
344
+ if (integrityProbe.status !== 0 || !/^sha512-[A-Za-z0-9+/]+=*$/.test(declaredIntegrity)) {
345
+ console.error(`the registry did not answer a sha512 integrity for ${name}@${version} (${integrityProbe.stderr?.trim() || `exit ${integrityProbe.status}`}) — refusing to install bytes this run cannot verify`)
346
+ return false
347
+ }
348
+ const pack = childProcess.spawnSync(
349
+ "npm",
350
+ ["pack", `${name}@${version}`, "--registry", REGISTRY, "--pack-destination", temp],
351
+ { encoding: "utf8", windowsHide: true },
352
+ )
353
+ if (pack.status !== 0) {
354
+ console.error(`npm pack failed for ${name}@${version}: ${pack.stderr?.trim() || `exit ${pack.status}`}`)
355
+ return false
356
+ }
357
+ const tarballName = (pack.stdout ?? "").trim().split("\n").pop()?.trim()
358
+ const tarballPath = tarballName ? path.join(temp, tarballName) : null
359
+ if (!tarballPath || !fs.existsSync(tarballPath)) {
360
+ console.error(`npm pack produced no readable tarball for ${name}@${version}`)
361
+ return false
362
+ }
363
+ const actual = createHash("sha512").update(fs.readFileSync(tarballPath)).digest("base64")
364
+ if (`sha512-${actual}` !== declaredIntegrity) {
365
+ console.error(`the tarball for ${name}@${version} does not match the registry's own integrity — downloaded bytes hash to sha512-${actual}, registry declares ${declaredIntegrity}. Refusing it.`)
366
+ return false
367
+ }
323
368
  const result = childProcess.spawnSync(
324
369
  "npm",
325
- [
326
- "install",
327
- "--ignore-scripts",
328
- "--no-save",
329
- "--loglevel=error",
330
- // The registry has to be named. npm resolves `npm_config_registry` (which npm exports
331
- // into lifecycle scripts), `NPM_CONFIG_REGISTRY`, `~/.npmrc` and a project `.npmrc`, so
332
- // without this the bytes fetched here — then chmod 0755 and executed — come from
333
- // whatever mirror the ambient config names, and the package's integrity hash is
334
- // self-attested by that same mirror. `script/verify-published.ts` passes `--registry`
335
- // for exactly this reason; the install path is the one that runs on a user's machine.
336
- "--registry",
337
- REGISTRY,
338
- "--prefix",
339
- temp,
340
- `${name}@${version}`,
341
- ],
370
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, tarballPath],
342
371
  { stdio: "inherit", windowsHide: true },
343
372
  )
344
373
  if (result.status !== 0) return