Monorepo for the nibling.run platform
core packages kernel sketches RESOLVER-R2-BRIEF.md
5.0 kB 77 lines
Markdown
at main

Resolver R2: specs, semver, registry metadata with prefer-offline #

The design is design-a, with grafts from design-b, as recorded in the session scratchpad (SYNTHESIS.md, design-a/). R1 landed the Tree (src/kernel/npm/tree.ts) and the oracle (scripts/npm-oracle.mjs, tests/fixtures/registry/<case>/). R2 builds the pieces the placement port (R3) calls. No placement yet: rt.install() behavior is unchanged.

Modules #

  • package.json: add semver 7.7.4 (the version npm 11.7.0 bundles) to dependencies. Import subpaths only (semver/functions/satisfies, semver/classes/range, ...), so esbuild bundles just those. Report the kernel bundle size before and after.
  • src/kernel/npm/spec.ts: the npm-package-arg subset as design-a's spec.ts sketches it. It covers version, range, tag and npm: alias (non-nesting), plus an unsupported variant for git, file, directory, url and workspace specs that names the spec in its error. Add depValid(node, spec) as arborist's dep-valid has it, for registry specs. Parse once into a discriminated union and trust it inside.
  • src/kernel/npm/registry.ts: today it holds registryTarball for bundleMissing. It becomes the resolver's whole view of the network:
    • manifest(spec) → Manifest. Fetch the abbreviated packument (Accept: application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*) and pick a version with a port of npm-pick-manifest 11 (dist-tag latest preference, then highest satisfying, non-deprecated first, engines against the runtime's Node version). Read npm 11.7.0's bundled npm-pick-manifest under ~/.volta/tools/image/npm/11.7.0/node_modules/ and port it, citing the file.
    • lockMeta(name, version): the per-version document (GET /<name>/<version>), cached without expiry, for the lockfile fields the abbreviated packument lacks (license, and whatever else the lockfile copies; check arborist's shrinkwrap.js for the list).
    • Prefer-offline. A stored packument is used whatever its age. The network is asked only on a miss, or when picking from the stored copy finds no version for the spec; that refetch uses cache: "no-cache". Dedupe in-flight fetches per name.
    • Counts for the report: metadata { cached, fetched }.
    • registryTarball keeps working, through the same packument path.
  • src/kernel/npm/store.ts: a second cache niw-npm-meta-v1 for metadata, keyed by URL plus Accept. Keep the store a mechanical adapter; the policy lives in registry.ts.
  • src/shared/platform.ts: NODE_VERSION, taken from src/runtime/process.ts, which then imports it.

Tests #

The repo's only runner is Playwright, and its spec files run in Node and can import src/ TypeScript directly. Use that for pure logic. Use the browser only where the browser matters (Cache Storage, kernel worker fetches).

  1. tests/npm-spec.spec.ts (Node side): parse cases, each with a literal expected union value, including aliases, tags, latest, prerelease ranges, scoped names and each unsupported kind.
  2. tests/pick-manifest.spec.ts (Node side): for each package in the conflict, hono and express recordings (loadRecording from scripts/npm-oracle.mjs), and each edge spec npm saw in the recorded package-lock.json, pickManifest returns the version npm locked. That is the oracle. Add hand cases for deprecated-skipping, the engines preference and a tag that is not latest.
  3. tests/registry.spec.ts (browser): with page.route serving recordings (Playwright intercepts kernel-worker fetches; that was checked), prefer-offline works:
    • a second manifest() for a satisfiable spec makes zero requests even when the stored packument is old;
    • an unsatisfiable-from-cache spec refetches once;
    • in-flight dedupe;
    • counts. Exercise it through a small test-only path. Do not add test hooks to the public host API: if you need a kernel entry point, put it behind the existing message protocol and say why.

Rules #

  • Bound every command with the process-group killer /private/tmp/claude-501/-Users-nmoo-Developer-natemoo-re-node-in-wasm/ae560627-5f68-439d-bf61-330961fd4901/scratchpad/bound SECONDS cmd.... perl alarm does NOT work here: node and npm are volta shims that survive SIGALRM, and three agents stalled that way. Write long output to a file and read the tail, rather than piping into tail.
  • Never background a command and then wait on it.
  • Playwright: -c playwright.worktree.config.ts (port 8947, uncommitted), one spec file per command, bound 240 and --global-timeout 220000. Rerun a live-registry "Failed to fetch" once with --last-failed before counting it.
  • Two or three verified commits. Imperative subjects in the repo's style. No Co-Authored-By trailer, no AI attribution: check git log -1 --format=%B after each commit and amend if one slipped in. Commit this brief with the last commit.