glasspane-harness 0.13.0 → 0.14.2

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.13.0/scripts/install.sh | bash
160
+ curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.2/scripts/install.sh | bash
161
161
  ```
162
162
 
163
163
  Two commands are installed: **`glasspane-harness`** and the short alias **`gp-harness`**. npm and
@@ -275,9 +275,12 @@ What stays where it belongs: the engine decides what the application did; neithe
275
275
  an interface on its own. The gate reports and withholds — it does not run the recipe, because
276
276
  neither product ships a recipe executor. The formats above come from one published contract
277
277
  layer, [`iterate-kernel`](https://www.npmjs.com/package/iterate-kernel), and the boundary is
278
- stated honestly: whether the two implementations still agree on a case the corpus never wrote
279
- down is answered by `scripts/diff_kernel_implementations.py`, an operator command rather than a
280
- CI step. The exchange from the loop's side is documented in the iterate-harness README
278
+ stated honestly: `bun script/kernel-conformance.mjs --impl <canonical checkout>` runs both
279
+ implementations over the *pinned* corpus and requires byte-identical answers, and nothing in this
280
+ repository — no CI step, no operator command — compares the two on a case the corpus never wrote down.
281
+ The sentence that used to live here named `scripts/diff_kernel_implementations.py`, a file that exists
282
+ in neither this fork nor the canonical kernel checkout, which made it a pointer to nowhere rather than a
283
+ boundary. The exchange from the loop's side is documented in the iterate-harness README
281
284
  ([Two-way integration with GlassPane](https://github.com/jingzhao-l/iterate-harness#-two-way-integration-with-glasspane)),
282
285
  and from the engine's side in [GlassPane's two-way integration section](https://github.com/jingzhao-l/GlassPane#two-way-integration-with-the-review-loop).
283
286
  Implementation detail: [`docs/kernel-integration.md`](docs/kernel-integration.md) and
@@ -285,6 +288,8 @@ Implementation detail: [`docs/kernel-integration.md`](docs/kernel-integration.md
285
288
 
286
289
  ## Documentation
287
290
 
291
+ - [`docs/index.md`](docs/index.md) — the page map and the four laws; every other page in this
292
+ directory is linked from it
288
293
  - [`docs/install.md`](docs/install.md) — install paths, permissions, verification
289
294
  - [`docs/models-and-keys.md`](docs/models-and-keys.md) — the model catalog and how to supply
290
295
  your own API keys
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.13.0/scripts/install.sh | bash
138
+ curl -fsSL https://raw.githubusercontent.com/jingzhao-l/glasspane-harness/v0.14.2/scripts/install.sh | bash
139
139
  ```
140
140
 
141
141
  会装出两个命令:**`glasspane-harness`** 与短别名 **`gp-harness`**。npm 与 bun 从 wrapper 的
@@ -230,8 +230,10 @@ GlassPane Harness 是第二对产品里的一半。引擎回答"这次操作到
230
230
  各归各位:应用做了什么由引擎判定,两个 harness 都不自行给界面下结论。闸只报与拦,不执行配方——
231
231
  两个产品都没有配方执行器。上面这些格式来自同一份发布出去的契约层
232
232
  [`iterate-kernel`](https://www.npmjs.com/package/iterate-kernel),边界也说清楚:
233
- "两份实现对语料没写过的案子还一致吗"由 `scripts/diff_kernel_implementations.py` 回答——它是给操作者
234
- 跑的命令,不在 CI 步骤里。回路那一侧的说明见 iterate-harness README 的
233
+ `bun script/kernel-conformance.mjs --impl <canonical checkout>` 会让两份实现对同一份**钉住的**语料
234
+ 给出逐字节相同的答案;语料没写过的案子,这个仓里没有任何东西(CI 步骤或操作者命令)去比对两份实现。
235
+ 原先这里写的是 `scripts/diff_kernel_implementations.py`——那个文件在本 fork 与 canonical 内核检出里
236
+ 都不存在,所以它不是一条边界,是一个指向别处的指针。回路那一侧的说明见 iterate-harness README 的
235
237
  [与 GlassPane 的双向集成](https://github.com/jingzhao-l/iterate-harness/blob/main/README.zh-CN.md#-与-glasspane-的双向集成),
236
238
  引擎那一侧见 [GlassPane 的双向集成小节](https://github.com/jingzhao-l/GlassPane#two-way-integration-with-the-review-loop)。
237
239
  实现细节:[`docs/kernel-integration.md`](docs/kernel-integration.md) 与
@@ -239,6 +241,7 @@ GlassPane Harness 是第二对产品里的一半。引擎回答"这次操作到
239
241
 
240
242
  ## 文档
241
243
 
244
+ - [`docs/index.md`](docs/index.md) — 页面索引与四条铁律;这个目录里每一页都由它连出去
242
245
  - [`docs/install.md`](docs/install.md) — 安装通道、权限、自检
243
246
  - [`docs/models-and-keys.md`](docs/models-and-keys.md) — 模型目录,以及怎么把你自己的 API key
244
247
  交进去
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "scripts": {
26
26
  "postinstall": "node ./postinstall.mjs"
27
27
  },
28
- "version": "0.13.0",
28
+ "version": "0.14.2",
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.13.0",
48
- "glasspane-harness-darwin-x64": "0.13.0"
47
+ "glasspane-harness-darwin-arm64": "0.14.2",
48
+ "glasspane-harness-darwin-x64": "0.14.2"
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 {