Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/runtime-matrix.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions .github/workflows/security-scan.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Your notes stay in this browser (IndexedDB + a small localStorage envelope). No
### Prerequisites

- **Node.js**: $\ge 22$ (pinned by `.nvmrc` and permitted by `package.json` `engines`)
- **pnpm**: `10.30.3` (pinned by `package.json` `packageManager`)
- **pnpm**: `12.17.0` (pinned by `package.json` `packageManager`)

### Installation & Development

Expand Down
4 changes: 2 additions & 2 deletions agents-docs/DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<https://vercel.com/docs/package-managers>, an override makes Vercel use the
*oldest* version of the named package manager in the build image — for pnpm
that is **v6**, which cannot read this repo's `lockfileVersion: '9.0'` or its
`pnpm.overrides`. With no override, Vercel infers pnpm from `pnpm-lock.yaml`
`pnpm-workspace.yaml` `overrides`. With no override, Vercel infers pnpm from `pnpm-lock.yaml`
and picks the right major.

The `packageManager: "pnpm@10.30.3"` field only takes effect when Corepack is
The `packageManager: "pnpm@12.17.0"` field only takes effect when Corepack is
enabled on the Vercel project (`ENABLE_EXPERIMENTAL_COREPACK=1`). Do not assume
it is active.

Expand Down
52 changes: 52 additions & 0 deletions agents-docs/RUNTIME_TOOLCHAIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Runtime & Toolchain

Authoritative decisions: `plans/219-runtime-toolchain-1165-1166-2026-11-19.md`
(#1165 Node matrix, #1166 pnpm 12). This page is the operator-facing summary.

## Node.js

| Runtime | Status | Where validated |
|---------|--------|-----------------|
| Node 22 LTS | **Primary runtime** — `engines.node` floor is `>=22.12.0` | Per-PR CI (`ci-and-labels.yml`), `setup-node` pinned to `'22'` |
| Node 24 LTS | Supported — inside `engines.node` `>=22.12.0 <27.0.0` | Scheduled weekly matrix (`.github/workflows/runtime-matrix.yml`) |
| Node 26 LTS | Supported — same range, same schedule | Same matrix |
| Node 27+ | **Not supported** (untested future line) — engine-strict refuses it | — |

- The matrix runs frozen install, lint, typecheck, unit tests, and the
production build on every listed runtime (weekly + on demand + on any
change to the workflow, lockfile, or root manifests).
- A red matrix run is a supported-runtime blocker: record the concrete
failure (and the upstream issue) in plan 219, narrow `engines.node`, and
note the exclusion — no runtime is advertised merely because install
worked.

## pnpm

- Pinned **`pnpm@12.17.0`** by `packageManager` (lockfile vendors the pinned
manager: integrity-checked `@pnpm/exe.*` artifacts in the lockfile's
manager document, so CI and local installs are reproducible even before
`pnpm/action-setup` runs).
- All pnpm settings live in `pnpm-workspace.yaml` (`engineStrict`,
`peerDependencyRules`, `overrides`, `allowBuilds`, `auditConfig`). There is
**no `.npmrc`** and no `pnpm` field in `package.json` — pnpm 12 ignores the
latter and the validator (`scripts/validate-package-manager.sh`) fails the
gate if settings drift back.
- Build scripts of pinned deps are **denied by default** (`allowBuilds:
pkg: false` — core-js, esbuild, onnxruntime-node, protobufjs,
unrs-resolver). To approve a new dep's postinstall, run
`pnpm approve-builds <pkg>` and review the resulting `allowBuilds` diff —
never run `--all`.
- Rollback pnpm: `git revert` the plan-219 commit, then
`pnpm install --frozen-lockfile` (details in plan 219).

## Upgrading the toolchain (next time)

1. `npm view pnpm versions` + release notes; test with
`npm_config_manage_package_manager_versions=false npx -y pnpm@<candidate>
install --frozen-lockfile` first — expect a settings migration, never
regenerate blindly.
2. `pnpm approve-builds` for new build-script deps (deny form to preserve the
default).
3. Full gate under the candidate (`pnpm --version` must print the candidate),
lockfile churn diff (target: zero dep-graph changes), docs + plan record,
then pin.
39 changes: 2 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.2.0",
"private": true,
"type": "module",
"packageManager": "pnpm@10.30.3",
"packageManager": "pnpm@12.17.0",
"engines": {
"node": ">=22.0.0 <25.0.0"
"node": ">=22.12.0 <27.0.0"
},
"scripts": {
"prepare": "./scripts/install-hooks.sh",
Expand Down Expand Up @@ -124,40 +124,5 @@
"typescript-eslint": "^8.67.0",
"vite": "^8.2.4",
"vitest": "4.1.11"
},
"pnpm": {
"peerDependencyRules": {
"allowedVersions": {
"eslint": "10"
}
},
"overrides": {
"postcss": "^8.5.23",
"source-map-js": "^1.2.2",
"brace-expansion@<1.1.18": "1.1.21",
"brace-expansion@>=5": "^5.0.12",
"picomatch": "^4.0.4",
"browserslist": "^4.28.7",
"js-yaml": "^4.3.2",
"adm-zip": "npm:adm-zip@0.6.1",
"dompurify": "^3.4.18",
"undici": "^7.29.1",
"nanoid@3": "3.3.18",
"postcss-selector-parser": "^7.1.6",
"smol-toml": "^1.9.1",
"katex": "^0.19.0"
},
"ignoredBuiltDependencies": [
"core-js",
"esbuild",
"onnxruntime-node",
"protobufjs",
"unrs-resolver"
],
"auditConfig": {
"ignoreCves": [
"CVE-2026-93687"
]
}
}
}
57 changes: 57 additions & 0 deletions plans/218-csp-reassessment-1167-2026-11-19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Plan 218 — CSP reassessment for #1167 (2026-11-19)

Periodic reassessment of the Content-Security-Policy required by #1167.
**Outcome: the least-privilege posture is confirmed; every exception is
measured and carries a revisit trigger; no policy change ships in plan 217.**

Baseline: `packages` of evidence from #1051 / plan 191 — implementation in
`src/lib/security/csp.ts` (+ `next.config.ts`) with the unit invariant pins
in `src/lib/security/csp.test.ts` and production-Chromium violation capture
in `e2e/csp-violations.spec.ts`.

## Directive inventory (each source → why it exists → evidence)

| Directive | Included sources | Required by | Evidence / revisit trigger |
|-----------|------------------|-------------|----------------------------|
| `default-src` | `'self'` | Everything else falls back to self; frame/object/base are separately tightened | Static site; no third-party frame/object/base use. Revisit on any new embedding feature. |
| `script-src` | `'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' blob:` | - `self`: app bundles. - `unsafe-eval`: `onnxruntime-web` compiles with `eval` — production Chromium drive recorded a real `script-src → eval` violation without it (plan 191). Removing it ships a permanent lexical fallback behind a working-looking toggle. - `wasm-unsafe-eval`: WebAssembly compile of the ONNX runtime (additive, never a substitute). - `blob:`: onnxruntime imports its WASM loader as a blob module — measured `script-src-elem → blob` + "no available backend found" without it. - `unsafe-inline`: Next.js does not emit nonce-bearing inline scripts in a static export; removing it breaks hydration (**#1051** tracks the nonce pipeline). | Re-run the production drive whenever: Next.js major upgrades; transformers.js/onnxruntime-web upgrades (watch for a no-eval build); any CSP violation appears in the e2e log. |
| `style-src` | `'self' 'unsafe-inline'` | Next.js inlines critical CSS `<style>` blocks in statically prerendered HTML; hashes would have to be computed at build and mirrored into the precache/SW contract (ADR 041) | Revisit trigger: if the build output switches to external-styles-only, drop `unsafe-inline` and pin hashes. |
| `worker-src` | `'self' blob:` | transformers.js spawns its embedding worker from a blob URL (same model runtime as above) | Same drive as `script-src`. |
| `img-src` | `IMG_SRC_SOURCES` explicit allowlist | App assets + model-card images pinned per host | Constants in `csp.ts`; new hosts must be added deliberately with a reason comment. |
| `font-src` | `'self' data:` | Geist/Newsreader are self-hosted; `data:` covers inlined font subsets | - |
| `connect-src` | `CONNECT_SRC_SOURCES` explicit allowlist (local AI endpoints, model hosts incl. the Xet bridge, signaling `wss://`) | Unit-pinned to contain no blanket `https:`/`wss:` (`csp.test.ts`); the Xet CAS bridge (`*.cdn.hf.co`) was measured 2026-11-08 after CI showed 16/16 lexical fallbacks | Dev-only origins stay out: loopback/Ollama sources are a **product** feature (local-first AI), not development leftovers. Re-examine on any new provider/integration. |
| `object-src`, `base-uri`, `form-action`, `frame-ancestors` | `'none'`/`'self'` variants | Hard lockdown of plugin/root/ancestor surfaces | No dynamic rendering; keep unchanged. |

## Nonce evaluation (the #1167 "evaluate" question, answered)

Next.js `headers()`/middleware nonces were evaluated and **not** adopted:

1. The app is a statically prerendered export with a service-worker precache
contract (ADR 041); per-request nonces change HTML per response, which
conflicts with precached offline pages (the offline shell must load
without a server to mint a nonce).
2. Vercel Hobby serves the single production deployment; middleware-injected
headers cannot reach SW-served responses offline, so the nonce pipeline
would need a hash-based build-time alternative for the offline shell —
tracked with the nonce work itself in **#1051**.

Hash/SRI authorization of inline scripts is feasible at build time in
principle but shares the same precache coupling; revisit when #1051 lands or
when the model runtime drops `eval` (then `unsafe-eval` goes with it — the
measured, not assumed, trigger).

## Verification obligations (kept green in CI)

- `pnpm run test:e2e` includes the production-drive specs asserting semantic
model load, initialization, inference, lexical fallback, and the CSP
violation log capture (`e2e/csp-violations.spec.ts`).
- `src/lib/security/csp.test.ts` pins the allowlist invariants.
- No duplicate headers: the single `cspHeader` constant in `next.config.ts`
is the only Content-Security-Policy source (verified by the settings-view
header audit in plan 191).

## Reassessment log

- 2026-11-19 (#1167): inventory re-verified against the current build; no
drift found; policy unchanged; next scheduled reassessment at the next
Next.js or onnxruntime-web/transformers.js major.
61 changes: 61 additions & 0 deletions plans/219-runtime-toolchain-1165-1166-2026-11-19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Plan 219 — Runtime toolchain decision (Node matrix + pnpm 12) — #1165, #1166

Date: 2026-11-19 · Batch: plans/217 PR3 · Branch: `feat/plans-217-3-runtime-security`

## Node.js runtime matrix (#1165)

**Decision: keep Node 22 as the primary CI runtime; validate Node 24 and 26 on
a scheduled matrix (`.github/workflows/runtime-matrix.yml`).** The issue
explicitly permits this when a full per-PR matrix is too expensive: the
primary runtime gates PRs, the scheduled weekly workflow (plus
`workflow_dispatch`, plus every change to the workflow definition,
lockfile, or root manifests) runs install/lint/typecheck/unit/build on
Node 22, 24, and 26 with `fail-fast: false`.

- `engines.node` widens from `>=22.0.0 <25.0.0` to **`>=22.12.0 <27.0.0`**:
- floor `(>=22.12.0)` — first 22.x line with the current toolchain floor;
- ceiling `(<27.0.0)` — includes the Node 24 and 26 LTS lines
(nodejs.org/previous-releases), excludes the unnamed Node 27 line so an
untested future major never matches.
- No runtime is advertised merely because installation succeeds: the shipped
matrix is the evidence record, and a matrix RED run must be turned into a
documented exclusion here (with the upstream issue) before shipping.
- `pnpm/action-setup` reads `packageManager`; cache keys use setup-node's
`cache: 'pnpm'` (keyed by `pnpm-lock.yaml`), so CI/local majors stay aligned.

## pnpm 10 → 12.17.0 (#1166)

**Decision: upgrade the pin from 10.30.3 to 12.17.0.** Evidence recorded on
2026-11-19 (pnpm.io 12.17.0 release notes: lockfile settings moved to
`pnpm-workspace.yaml`; the package.json `pnpm` field was removed in major 12).

| Check | Result |
|-------|--------|
| `pnpm install --frozen-lockfile` with the 10.30.3 lockfile under pnpm 12 | **Failed by design** — `ERR_PNPM_LOCKFILE_CONFIG_MISMATCH`: pnpm 12 no longer reads the `pnpm` field, so the `overrides` hash did not match. This is the settings migration, not dependency drift. |
| Settings migration | `peerDependencyRules`, `overrides`, `ignoredBuiltDependencies`→pnpm 12's `allowBuilds` (via `pnpm approve-builds '!pkg'` deny form), and `auditConfig.ignoreCves` moved to `pnpm-workspace.yaml`. `.npmrc` (`engine-strict`) replaced by `engineStrict: true` in the same file; the file itself deleted. |
| Post-migration `pnpm install --frozen-lockfile` under 12.17.0 | **Passes** (exit 0, "Lockfile is up to date"). |
| Lockfile dependency-graph churn | **Zero**: 1179 packages before, 1179 after; added 0, removed 0, changed 0 (verified by a name→version key diff of the lockfile's dependency document). The only lockfile change is the format restructure: settings/overrides moved out (now sourced from `pnpm-workspace.yaml`) and pnpm 12's **package-manager vendor document** (`packageManagerDependencies` + `@pnpm/exe.*` platform entries) — the pinned manager itself is now lockfile-reproducible. |
| Full quality gate under 12.17.0 | lint ✓, typecheck×3 ✓, unit suites ✓ (all projects), production build ✓ — all exit 0 with `pnpm --version` = 12.17.0. |
| New pnpm-12 facts banked | (1) `managePackageManagerVersions` defaults on: a newer `npx pnpm@X` self-downgrades to the pin unless run with `npm_config_manage_package_manager_versions=false`; (2) `ignoredBuiltDependencies` is replaced by `allowBuilds: {pkg: true/false}` — a bare `pnpm install` ERRORS (`ERR_PNPM_IGNORED_BUILDS`) until `pnpm approve-builds [<'pkg'> \| <!pkg>…]` runs; (3) the lockfile becomes a **two-document YAML**: document 1 = manager pin/vendor metadata, document 2 = the dependency lockfile. |

## Rollback path (#1166)

1. Revert the plan-219 commit (restores `packageManager: pnpm@10.30.3`,
the `engines` range, the `pnpm` field, `.npmrc`, and the single-document
lockfile: `git revert <commit> && pnpm install --frozen-lockfile`).
2. If only the lockfile needs regenerating (e.g. after an unrelated merge),
the pnpm 10 path still reads a pnpm-12 lockfile document **only when the
settings/overrides sections resolve** — safest is to regenerate with the
pinned major: `npx -y pnpm@10.30.3 install --lockfile-only` then run the
gate. Because the pnpm-12 vendor document is additive and the dependency
graph is identical, a 10-formatted lockfile remains a valid rollback
target.
3. CI rollback: the runtime-matrix workflow is additive; disabling it
(or its schedule) does not affect the required check set.

## Verification ordering

The lockfile in this branch is the pnpm-12 artifact. PR1/#1178 merged first;
PR2 (#1179) carries no dependency changes; this branch rebases on main after
each merge and regenerates the lockfile only via `pnpm install
--no-frozen-lockfile` with the pinned major.
Loading
Loading