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
70 changes: 70 additions & 0 deletions .agents/skills/upgrade-packages/REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Reference — evidence artifact schema

The skill runs `bun run upgrade-packages:evidence` (default `--out scripts/upgrade-packages/artifact.json`). Phase 1 of [`SKILL.md`](./SKILL.md) owns network, cache TTLs, and the never-touch-registry rule.

Each outdated package gets **one** delta: the published tarball span `current → latest`. There is no per-tag GitHub release walk.

Cutter caps (`tarball-delta.ts`): `PATCH_PATH_CAP` 40 paths on the second `bun pm diff`, `FILE_LIST_CAP` 80 files in the artifact, `HINT_CAP` 8 hints per bucket, `PATCH_MAX_CHARS` 8000, `RELEASE_NOTES_MAX_CHARS` 1200. A missing `*.d.ts` patch means it lost the cap, not that the API is unchanged. `source: "none"` sets `tarball: null`.

## Artifact shape

```jsonc
{
"generatedAt": "ISO timestamp",
"inventory": {
"direct": [{ "name", "version", "range": "exact|caret|tilde", "dev" }],
"transitiveDuplicates": [{ "pkg", "versions": [...] }] // direct-dep conflicts + semver-major splits only
},
"outdated": [{
"pkg", "current", "latest",
"bumpClass": "patch|minor|major|prerelease|no-op",
"coupledWith": [], // naive; agent confirms peer/dep coupling from deltas
"dev"
}],
"audit": {
"bunAudit": <raw bun audit --json payload>,
"ghsa": [{ "pkg", "advisories": [{
"id", "cveId", "severity",
"vulnerableRange", "fixedIn",
"installedInRange": bool, // script-computed vs installed version
"verdict": "priority-bump|needs-higher-target|cleared-at-current|unpatched|check-failed",
"url", // github.com/advisories/<id>; empty + id:"error" on check-failed
"error" // optional — message on check-failed (gh/parse/cache failure)
}] }]
},
"deltas": {
"<pkg>": [{
"version", "date", // target; date from changelog hunk if present
"breaking": [...], "deprecations": [...], "features": [...],
"security": [...], "peerEngine": [...], // notes + changelog/package.json hints
"releaseNotes": "changelog added-lines, truncated",
"changelogUrl": "npmjs.com/package/<pkg>/v/<target>",
"tarball": {
"from", "to",
"notes": [...], // bun summary: engines, deps, install scripts, dangerous imports
"totals": { "files", "added", "deleted", "linesAdded", "linesRemoved", "formattingOnly" },
"files": [{ "path", "status", "linesAdded", "linesRemoved", "formattingOnly", "patch" }]
// patch only for paths that won PATCH_PATH_CAP (named keep + symbol-boosted .d.ts + extras)
},
"source": "bun-pm-diff|none",
"error": null | "reason"
}]
},
"usage": {
"<pkg>": {
"importedSymbols": [...], "typeOnlySymbols": [...], // parsed imports (codemap) — type-only included
"sites": ["file:line", ...], // import locations
"callSites": ["file:line", ...], // reference locations (codemap only — blast radius)
"source": "codemap|grep" // grep = fallback when codemap unavailable
}
}
}
```

## How to read it

- **Verdict a package**: read `outdated[].bumpClass` + `audit.ghsa[].verdict` + `tarball.notes` + `deltas[<pkg>][].breaking`/`security` + `usage[<pkg>].importedSymbols`. Cite `tarball.notes`, a kept `patch`, `changelogUrl`, or advisory `url`.
- **`features`/`breaking` arrays are hints** — when a hint is empty but the delta is minor/major, read `releaseNotes` and kept patches before concluding "no changes".
- **`error` on a delta** means `bun pm diff` failed for that span. `changelogUrl` is still the npm version page. Re-run evidence before marking **blocked**.
- **`cleared-at-current`** = the GHSA advisory's fix already ships at the installed version — no bump needed, record the URL as evidence.
- **Citations are artifact fields** — `tarball.notes`, kept `tarball.files[].patch`, `changelogUrl`, `url`. Do not invent GitHub compare URLs.
79 changes: 79 additions & 0 deletions .agents/skills/upgrade-packages/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: upgrade-packages
description: >-
Delta-driven dependency upgrades — a script gathers the evidence, you read the artifact and judge. Use when the user asks to upgrade, bump, or CVE-audit dependencies.
---

# Upgrade packages

A script gathers every tarball delta (`bun pm diff`), GHSA advisory, and codebase-usage site into one JSON artifact; you read it and judge. **Never touch the registry, GitHub, or GHSA directly** — every citation comes from the artifact (`tarball.notes`, kept `tarball.files[].patch`, `changelogUrl`, advisory `url`), so no model priors sneak in. Sources of truth: the artifact, then the codebase. Cite where you read every claim.

This repo uses **bun** with **exact** pins in `package.json` — `bun update` alone bumps nothing. Lift an exact pin with `bun update <pkg>@<target>` (or `bun update <pkg> --latest` per package) / a `package.json` edit. Never `bun update --latest` across the board. The `check-updates` script is inventory-only.

## Phase 1 — Gather evidence

Run `bun run upgrade-packages:evidence` (defaults to `--out scripts/upgrade-packages/artifact.json`; pass `--out <path>` to override). **Requires network access** — the script calls `bun pm diff` (registry tarballs) and `gh api` (GHSA advisories only). A sandbox that blocks `api.github.com` fails GHSA (`check-failed`); deltas still land. Cache: `scripts/upgrade-packages/.cache/` (GHSA 1h, tarball diffs 7d). Read the artifact. Schema + how-to-read: [`REFERENCE.md`](./REFERENCE.md).

**Done when:** the artifact exists and you've read `inventory`, `outdated`, `audit`, `deltas`, and `usage`.

## Phase 2 — Triage (judge the artifact)

For each `outdated` package, produce a cited verdict + band:

- **band** = `bumpClass` (patch/minor/major/prerelease). **Coupled deps:** if a patch bump's peer/dep requires a minor+ bump of another direct dep (check `deltas[<pkg>][].peerEngine` + the other package's `bumpClass`), move the coupled set up a band.
- **priority-bump** if `audit.ghsa` verdict is `priority-bump` — goes first within its band.
- **check-failed** if `audit.ghsa` verdict is `check-failed` (gh/parse/cache failure, `id:"error"`) — inconclusive, not a vuln; re-run evidence before treating as blocked.
- **blocked** if any `deltas[<pkg>][].error` leaves the span uncovered (retry evidence; `changelogUrl` is the npm version page) OR a `breaking`/`security`/`peerEngine` delta is a break-risk you can't resolve (see Phase 3).
- **deferred-major** for a major with an unresolved break — unless it clears a high/critical advisory, in which case surface the tradeoff to the user.

Cite `tarball.notes` / kept patches / `changelogUrl` / advisory `url` for every verdict.

**Done when:** every outdated package has a cited verdict, a band, and a coupled-set tag; every `priority-bump` is flagged for Phase 3.

## Phase 3 — Fact-check break-risk against the codebase

For every **break-risk delta** (`breaking`, `deprecations`, `peerEngine`, or a behavior-changing fix in `security`/`features` — e.g. callback debounce, CVE patch altering semantics), read `tarball.notes` plus kept patches (`package.json`, `*.d.ts`, changelog, top-churn extras) and cross-check `usage[<pkg>]`. Use `callSites` (codemap) for **blast radius** — where the symbol is actually called, not just imported; `importedSymbols` + `typeOnlySymbols` for what's in scope; `sites` for import locations. Classify: **no usage** / **code-aligned** / **breaks** (needs a code change first). Cite `callSites`/`sites` (file:line). A `breaks` with no code change → the bump is **blocked** or **deferred**.

**Done when:** every break-risk delta has a citation-backed `no usage | aligned | breaks` verdict; every `breaks` has a proposed code change.

## Phase 4 — Apply, gated by risk

Bands: patch → minor → major, verify after each per [`verify-after-each-step`](../../rules/verify-after-each-step.md). Within each band, **priority-bump** packages first; **coupled sets** move up together; **prereleases** go in the patch band (moving-target, same-major-line gate).

1. **Patch** — bump together (`bun update <pkg>@<target>` per package); run the CI mirror (below).
2. **Minor** — bump together; same checks.
3. **Major** — one at a time; land its `breaks` code change _first_, bump, then checks. Defer unresolved majors (cited reason) unless they clear a high/critical advisory.

A bumped adapter peer (react / vue / svelte / solid / lit / alpine / angular / preact) can change DOM-suite behavior — re-run `bun run test:dom`. Re-run `bun run check:deps` after workspace bumps (sherif). Re-run `bun audit` after each band — a **new** advisory → revert that bump and re-research. Commit per band **only when the user asked to commit**.

**Done when:** CI mirror (`bun run check` + `bun run build`) green for patch + minor; every major green-and-committed/staged or deferred with a cited reason; no `breaks` unaddressed; final `bun audit` clean or every remaining advisory documented.

## Phase 5 — Verify (local CI mirror)

`package.json` `check` and `.github/workflows/ci.yml` are the SSOT. Do not restate their job lists here.

- `bun run check`
- `bun run build` — **do not skip** — dep upgrades break the bundler/codegen far more often than types
- `bun audit` — CI's audit job blocks on **high/critical**; treat a red high/critical audit as **blocking-with-triage**, lower severities as documented

## Phase 6 — Report

Produce: **security** (advisories → verdict, with GHSA id + URL + fixed-in), **consolidated changeset** (rolled up from `deltas` — per package `current → target` from the single tarball span, bucketed breaking/deprecations/features/fixes/peer-engine, one line per hint or note), **adoption opportunities** (top ~5 `features` deltas the codebase isn't using — `usage` verdict + file:line + one-line why-adopt + follow-up; non-blocking), bumped packages (band → version → why-safe), deferred/blocked (cited reason + file:line), verification results. Every citation from the artifact. If the user asked to commit/PR, hand off to [`harden-pr`](../harden-pr/SKILL.md) full mode.

**Done when:** report accounts for every non-no-op package and advisory; every citation is real — no `possibly`, `likely`, or unstated assumptions.

## Anti-patterns

- ❌ Touching the registry/GitHub/GHSA directly — run the script, read the artifact.
- ❌ `bun update --latest` across the board — per-package `--latest`/`package.json` edit for exact pins.
- ❌ Treating `bun audit` as pass/fail — every advisory needs a cited verdict; a high/critical audit is blocking-with-triage.
- ❌ `bun audit fix`. It treats exact pins as `^version` and rewrites `package.json`.
- ❌ Isolated linker. Do not set `linker = "isolated"`. Existing lockfiles stay hoisted.
- ❌ bunfig `[test]` for isolate. `--isolate` is CLI-only. `--parallel` implies isolate.
- ❌ Skipping `bun run build` — bundler/codegen breakage beats type breakage for dep upgrades.

## Reference

- [`REFERENCE.md`](./REFERENCE.md) — evidence artifact schema + how to read it
- [`verify-after-each-step`](../../rules/verify-after-each-step.md) — per-band checks
- [`harden-pr`](../harden-pr/SKILL.md) — full mode before PR
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`@stainless-code/layers` is a small, freshly extracted library. Before large PRs, please open an issue so we can align on:

- **Public surface** — anything exported from a package entry point (`src/index.ts` / React's `src/index.tsx`, plus Svelte's `src/store.ts`) is the public API and must carry JSDoc that reads well in hovers and published typings. See [`docs/architecture.md`](../docs/architecture.md) for the core + adapter model.
- **Runtimes** — **Node** `^20.19.0 || >=22.12.0` and **Bun** `>=1.0.0` (`package.json` **engines**). The core is zero-dep by design; each adapter package declares its required peer (`react`, `preact`, `solid-js`, `@angular/core`, `vue`, `lit` + `@lit/context`, `svelte`).
- **Runtimes** — **Node** `^20.19.0 || >=22.12.0` and **Bun** `>=1.4.0` at the private monorepo root (`packageManager: bun@1.4.0`). Published adapter packages keep `engines.bun` `>=1.0.0`. The core is zero-dep by design; each adapter package declares its required peer (`react`, `preact`, `solid-js`, `@angular/core`, `vue`, `lit` + `@lit/context`, `svelte`).

## Dev workflow

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
bun-version: 1.4.0

- name: Install packages
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ jobs:
- name: Run unit tests with coverage gate
run: bun run test:coverage

# Workspace `test:coverage` is per-package `src/` only. Root
# `scripts/upgrade-packages` is on `bun run test`, not the coverage gate.
- name: Run upgrade-packages tests
run: bun test --isolate scripts/upgrade-packages

test-dom:
name: 🌐 Test (DOM)
needs: skip-ci
Expand Down
9 changes: 8 additions & 1 deletion .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"sortPackageJson": {
"sortScripts": true
},
"ignorePatterns": ["node_modules", "dist", "coverage", "bun.lock"],
"ignorePatterns": [
"node_modules",
"dist",
"coverage",
"bun.lock",
"scripts/upgrade-packages/.cache",
"scripts/upgrade-packages/artifact.json"
],
"printWidth": 80
}
6 changes: 3 additions & 3 deletions bun.lock

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"prepare": "husky || true",
"release": "bun scripts/release.ts",
"size": "size-limit",
"test": "bun run --filter '*' test",
"test": "bun run --filter '*' test && bun test --isolate scripts/upgrade-packages",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"test:coverage": "bun run --filter '*' test:coverage",
"test:dom": "bun run --filter '*' test:dom",
"test:types": "bun run --filter '*' typecheck",
Expand All @@ -68,7 +68,7 @@
"@size-limit/preset-small-lib": "13.0.3",
"@stainless-code/codemap": "0.11.4",
"@tanstack/intent": "0.3.6",
"@types/bun": "1.3.14",
"@types/bun": "1.4.0",
"@types/node": "26.1.2",
"husky": "9.1.7",
"knip": "6.32.0",
Expand All @@ -91,8 +91,8 @@
"yuku-parser": "0.6.5"
},
"engines": {
"bun": ">=1.0.0",
"bun": ">=1.4.0",
"node": "^20.19.0 || >=22.12.0"
},
"packageManager": "bun@1.3.14"
"packageManager": "bun@1.4.0"
}
2 changes: 1 addition & 1 deletion packages/alpine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "bun run --filter '@stainless-code/layers' --filter '@stainless-code/layers-devtools' --filter '@stainless-code/react-layers' build && tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"scripts": {
"build": "tsdown",
"check:pack": "attw --pack . --profile esm-only && publint --strict",
"test": "bun test ./src",
"test": "bun test --isolate ./src",
"test:coverage": "bun test ./src --coverage --coverage-threshold=0.75",
"test:dom": "vitest run",
"typecheck": "tsc --noEmit"
Expand Down
Loading
Loading