glasspane-harness 0.12.5 → 0.14.1

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
@@ -79,7 +79,7 @@ Install the engine first — the harness is a client, not a substitute:
79
79
  ```bash
80
80
  # Engine (macOS 14+). When the permission panel opens, grant Accessibility,
81
81
  # Input Monitoring and Screen Recording to `GlassPane Daemon`.
82
- curl -fsSL https://raw.githubusercontent.com/jingzhao-l/GlassPane/main/install.sh -o /tmp/gp-install.sh && sh /tmp/gp-install.sh
82
+ GP="$(mktemp "${TMPDIR:-/tmp/}gp-install.XXXXXXXX")" && curl -fsSL https://raw.githubusercontent.com/jingzhao-l/GlassPane/main/install.sh -o "$GP" && sh "$GP" && rm -f "$GP"
83
83
  ```
84
84
 
85
85
  Its README is the place for install channels, permissions, the evidence-pack format and the
@@ -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.12.5/scripts/install.sh | bash
160
+ curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.1/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
@@ -71,7 +71,7 @@ macOS 上的运行时验证引擎:一个 Swift 后台服务,测量应用的
71
71
  ```bash
72
72
  # 引擎(macOS 14+)。权限面板弹出时,为 `GlassPane Daemon` 勾选辅助功能、
73
73
  # 输入监控与屏幕录制。
74
- curl -fsSL https://raw.githubusercontent.com/jingzhao-l/GlassPane/main/install.sh -o /tmp/gp-install.sh && sh /tmp/gp-install.sh
74
+ GP="$(mktemp "${TMPDIR:-/tmp/}gp-install.XXXXXXXX")" && curl -fsSL https://raw.githubusercontent.com/jingzhao-l/GlassPane/main/install.sh -o "$GP" && sh "$GP" && rm -f "$GP"
75
75
  ```
76
76
 
77
77
  安装渠道、权限、证据包格式与更新线都在它的 README:[jingzhao-l/GlassPane](https://github.com/jingzhao-l/GlassPane)。
@@ -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.12.5/scripts/install.sh | bash
138
+ curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.1/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.12.5",
28
+ "version": "0.14.1",
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.12.5",
48
- "glasspane-harness-darwin-x64": "0.12.5"
47
+ "glasspane-harness-darwin-arm64": "0.14.1",
48
+ "glasspane-harness-darwin-x64": "0.14.1"
49
49
  }
50
50
  }
package/postinstall.mjs CHANGED
@@ -4,11 +4,9 @@ import childProcess from "child_process"
4
4
  import fs from "fs"
5
5
  import os from "os"
6
6
  import path from "path"
7
- import { createRequire } from "module"
8
7
  import { fileURLToPath } from "url"
9
8
 
10
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
11
- const require = createRequire(import.meta.url)
12
10
  const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
13
11
 
14
12
  const platformMap = {
@@ -175,11 +173,145 @@ function machineLabel() {
175
173
  return parts.join(" ")
176
174
  }
177
175
 
176
+ /**
177
+ * Which copies this run may load, and what has to be true of them before one is executed.
178
+ *
179
+ * This used to be `require.resolve(`${name}/package.json`)`. That walks every `node_modules`
180
+ * ABOVE this wrapper — out of the project, through the home directory, to `/` — and consults
181
+ * `NODE_PATH`, so a package planted in an ancestor directory, or in any directory an environment
182
+ * variable names, satisfied it. The only thing then said about those bytes was `--version` string
183
+ * equality, which a 3-line shell script answers. This is the channel that copies a binary next to
184
+ * the user's PATH, chmods it 0755 and runs it.
185
+ *
186
+ * Three separate statements are required now, none of them self-reported by the candidate:
187
+ * 1. it sits inside THIS install's tree. The boundary is the outermost `node_modules` path
188
+ * component of the wrapper's own realpath, which is the project's (or the global prefix's)
189
+ * store and nothing above it — so every layout a manager really produces is inside it (npm
190
+ * hoisting to the project's `node_modules`, npm nesting under the wrapper, pnpm's `.pnpm`
191
+ * symlink farm, bun's isolated links), while an ancestor `node_modules` and a `NODE_PATH`
192
+ * detour are outside it by construction. This is derived from the path, not from a walk:
193
+ * `/Users/me/node_modules` is not a component of `/Users/me/app/node_modules/glasspane-harness`.
194
+ * 2. its `package.json` names this package at the exact version this wrapper seals in its own
195
+ * `optionalDependencies` — a claim about the package, made by the manifest that npm resolved
196
+ * for this install, not about what the binary chooses to print.
197
+ * 3. when the tree keeps an install record — `node_modules/.package-lock.json`, which npm writes
198
+ * for project installs (measured absent for `npm install -g`, pnpm and bun) — that record must
199
+ * name this directory, this version, an `sha512-` integrity and the `${name}-${version}.tgz`
200
+ * tarball it was unpacked from. A directory that exists but is not in the record was not
201
+ * placed by this install, which is precisely the pre-positioned-package case.
202
+ * A copy that fails any of these is not installed; the caller then does its own registry-pinned
203
+ * fetch, which is the branch that can still prove what it received.
204
+ */
205
+ /**
206
+ * The two directories a manager may have placed this wrapper's platform package in, and the tree
207
+ * that bounds them. `nestedTree` is the wrapper's own `node_modules` (npm nests a copy there when
208
+ * the hoisted one cannot be used, and every test fixture and pack directory is this shape);
209
+ * `boundary` is the outermost `node_modules` component of the wrapper's own path — the project's
210
+ * or the global prefix's store — which is where a hoisted npm copy, pnpm's `.pnpm` farm and bun's
211
+ * isolated links all live. A wrapper that is not itself inside a `node_modules` has no boundary,
212
+ * and then only its nested tree can be loaded from.
213
+ */
214
+ function installTrees() {
215
+ const own = fs.realpathSync(__dirname)
216
+ const nestedTree = path.join(own, "node_modules")
217
+ const segments = own.split(path.sep)
218
+ let boundary = null
219
+ for (let index = 1; index < segments.length; index++) {
220
+ if (segments[index] === "node_modules") boundary = segments.slice(0, index + 1).join(path.sep)
221
+ }
222
+ return { nestedTree, boundary }
223
+ }
224
+
225
+ function candidateDirs(name) {
226
+ const own = fs.realpathSync(__dirname)
227
+ const dirs = [path.join(own, "node_modules", name)]
228
+ const parent = path.dirname(own)
229
+ if (path.basename(parent) === "node_modules") dirs.push(path.join(parent, name))
230
+ return dirs
231
+ }
232
+
233
+ function readJson(file) {
234
+ return JSON.parse(fs.readFileSync(file, "utf8"))
235
+ }
236
+
237
+ /** npm's own record of this tree, for this exact directory. Absent record: null, absent entry: a refusal. */
238
+ function installRecord(pkgDir, name, version) {
239
+ const { nestedTree, boundary } = installTrees()
240
+ const root = boundary ?? nestedTree
241
+ const file = path.join(root, ".package-lock.json")
242
+ if (!fs.existsSync(file)) return { state: "no-record", detail: `${file} does not exist (npm -g, pnpm and bun write no install record)` }
243
+ let record
244
+ try {
245
+ record = readJson(file)
246
+ } catch (error) {
247
+ return { state: "refuse", detail: `${file} could not be read: ${error instanceof Error ? error.message : String(error)}` }
248
+ }
249
+ const key = `node_modules/${path.relative(root, pkgDir).split(path.sep).join("/")}`
250
+ const entry = record?.packages?.[key]
251
+ if (!entry) return { state: "refuse", detail: `${key} is not recorded in ${file}, so this install did not place it` }
252
+ if (entry.version !== version) {
253
+ return { state: "refuse", detail: `${file} records ${key} at ${entry.version}, this wrapper seals ${version}` }
254
+ }
255
+ if (!/^sha512-/.test(String(entry.integrity ?? ""))) {
256
+ return { state: "refuse", detail: `${file} records no sha512 integrity for ${key}` }
257
+ }
258
+ // npm's own layout for a registry tarball: `<registry>/<name>/-/<basename>-<version>.tgz`, where
259
+ // the basename drops the `@scope/` prefix. Shape read off a real `npm install` record on this
260
+ // machine (`node_modules/@parcel/watcher-darwin-arm64` → resolved
261
+ // `https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.5.1.tgz`).
262
+ const url = String(entry.resolved ?? "")
263
+ if (!url.includes(`/${name}/-/`) || !url.endsWith(`-${version}.tgz`)) {
264
+ return { state: "refuse", detail: `${file} records ${key} as arriving from ${JSON.stringify(url)}, not the ${name}@${version} tarball` }
265
+ }
266
+ return { state: "recorded", detail: `${key} is recorded here as ${name}@${version} from ${entry.resolved}` }
267
+ }
268
+
178
269
  function resolveBinary(name) {
179
- const packageJsonPath = require.resolve(`${name}/package.json`)
180
- const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
181
- if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
182
- return binaryPath
270
+ const declaredVersion = packageJson.optionalDependencies?.[name]
271
+ if (!declaredVersion) throw new Error(`${name} is not one of this wrapper's optionalDependencies — there is no version to check it against`)
272
+ const { nestedTree, boundary } = installTrees()
273
+ const seen = []
274
+ for (const dir of candidateDirs(name)) {
275
+ if (!fs.existsSync(dir)) continue
276
+ let real
277
+ try {
278
+ real = fs.realpathSync(dir)
279
+ } catch (error) {
280
+ seen.push(`${dir}: unreadable (${error instanceof Error ? error.message : String(error)})`)
281
+ continue
282
+ }
283
+ const inside = (tree) => tree !== null && (real === tree || real.startsWith(tree + path.sep))
284
+ if (!inside(boundary) && !inside(nestedTree)) {
285
+ seen.push(`${real} is not inside this install (${boundary ?? nestedTree})`)
286
+ continue
287
+ }
288
+ let manifest
289
+ try {
290
+ manifest = readJson(path.join(dir, "package.json"))
291
+ } catch (error) {
292
+ seen.push(`${real}: no readable package.json (${error instanceof Error ? error.message : String(error)})`)
293
+ continue
294
+ }
295
+ if (manifest.name !== name) {
296
+ seen.push(`${real}: its package.json names ${JSON.stringify(manifest.name)}, not ${name}`)
297
+ continue
298
+ }
299
+ if (manifest.version !== declaredVersion) {
300
+ seen.push(`${real} is ${manifest.name}@${manifest.version}, this wrapper seals ${declaredVersion}`)
301
+ continue
302
+ }
303
+ const record = installRecord(real, name, declaredVersion)
304
+ if (record.state === "refuse") {
305
+ seen.push(record.detail)
306
+ continue
307
+ }
308
+ const binaryPath = path.join(dir, "bin", sourceBinary)
309
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
310
+ return binaryPath
311
+ }
312
+ throw new Error(
313
+ `no copy of ${name}@${declaredVersion} inside this install is loadable${seen.length === 0 ? "" : `:\n ${seen.join("\n ")}`}`,
314
+ )
183
315
  }
184
316
 
185
317
  function installPackage(name) {
@@ -211,6 +343,20 @@ function installPackage(name) {
211
343
  )
212
344
  if (result.status !== 0) return
213
345
  const packageDir = path.join(temp, "node_modules", name)
346
+ // The fetch asked for `${name}@${version}` by name; what npm unpacked is checked rather than
347
+ // trusted, because this is the branch that runs when nothing in the tree could be attributed
348
+ // to this install and it is the one branch whose bytes we have not seen before.
349
+ let fetched
350
+ try {
351
+ fetched = readJson(path.join(packageDir, "package.json"))
352
+ } catch (error) {
353
+ console.error(`the package this run fetched has no readable manifest: ${error instanceof Error ? error.message : String(error)}`)
354
+ return false
355
+ }
356
+ if (fetched.name !== name || fetched.version !== version) {
357
+ console.error(`the package this run fetched is ${fetched.name}@${fetched.version}, not ${name}@${version} — refusing it`)
358
+ return false
359
+ }
214
360
  copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
215
361
  return true
216
362
  } finally {