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
18 changes: 16 additions & 2 deletions .ai/contexts/build-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ pushes to `main` and `release/*` run Node 22/Linux+Windows. Matrix keys remain `
`os`, with no job-name override, retaining contexts such as
`test (22, ubuntu-latest)`. No step depends on a Node 20 or Windows/Node 20
cell. Linux real-bwrap enforcement stays on every Linux test cell; patch
coverage stays on PR Node 22/Linux only. Lint, docs-refs and e2e still run for every PR
coverage stays on PR Node 22/Linux only. Lint, deadcode, docs-refs and e2e still run for every PR
and push to these branches; changelog and docs stay PR-only. Test jobs have 25 minutes; lint,
changelog, docs, docs-refs and e2e have 10 each. `docs-refs` runs
deadcode, changelog, docs, docs-refs and e2e have 10 each. `docs-refs` runs
`node scripts/check-doc-refs.js` on Node 20 with no install step (the script has
no dependency) and is blocking; its rules are in
[changelog.md](../../docs/changelog.md#doc-references).
Expand All @@ -349,6 +349,20 @@ The rule is in [changelog.md](../../docs/changelog.md#documentation-in-the-same-
Review still assesses the prose. Adding the label or editing the reason needs
a rerun. Required-check settings and label creation remain separate actions.

The `deadcode` job reports and never blocks (#1356, first step). It runs one
cell, Node 22 on `ubuntu-latest`, installs locked dependencies with
`npm ci --ignore-scripts` (knip needs no native rebuild and no Electron
download), then runs the locked knip with `npx --no-install`, so the version
is the one pinned in `package.json`. The markdown report goes to the log and to
the job summary through `tee`. The step sets `shell: bash` for pipefail, so
knip's non-zero exit still marks the step, and `continue-on-error: true`, so
the job and the workflow stay green whatever knip finds. Nothing `needs` it and
it is not a required check. Making it blocking is a later step of #1356, once
the report is clean. `test/deadcode-report.test.js` checks the pin, the job's
shape and that no gate task or job depends on it. What knip analyses and its
known false positives are in
[development.md](../../docs/development.md#dead-code-report).

Linux runs the full Node suite with coverage. Every non-Linux runner runs
`node scripts/run-tests.js --platform-only` without c8; its matrix and job
name stay unchanged, including `test (22, windows-2022)`. The coverage step
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ jobs:
- name: Run ESLint
run: npm run lint

deadcode:
# see docs/development.md ("Dead-code report")
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

- name: Install dependencies without lifecycle scripts
run: npm ci --ignore-scripts

- name: Report unused files, exports and dependencies
continue-on-error: true
shell: bash
run: npx --no-install knip --no-progress --reporter markdown | tee -a "$GITHUB_STEP_SUMMARY"

changelog:
# see docs/changelog.md ("The CI check")
if: github.event_name == 'pull_request'
Expand Down
5 changes: 5 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ tasks:
- node scripts/check-doc-refs.js
- node scripts/check-docs.js --validate

deadcode:
desc: "Report unused files, exports and dependencies with knip (report only; see docs/development.md)"
cmds:
- npx --no-install knip {{.CLI_ARGS}}

ci:
desc: CI gate — runs test then lint, verbose, exits on first failure
cmds:
Expand Down
48 changes: 47 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
covers:
- "Taskfile.yaml"
- "knip.json"
- "package.json"
- "public/codemirror-setup.js"
- "public/mermaid-setup.js"
Expand Down Expand Up @@ -50,6 +51,7 @@ run `npm run bundle:mermaid` again.
| `task check` | Full `test` and `lint` gate before opening a PR, then the doc reference check (`scripts/check-doc-refs.js`, see [Doc references](changelog.md#doc-references)) |
| `task ci` | `npm test`, then `npx eslint .`, in sequence |
| `task coverage` | the suite under c8; text and lcov in `./coverage` |
| `task deadcode` | knip's report of unused files, exports and dependencies — see [Dead-code report](#dead-code-report) |
| `task install:lint` | installs `eslint` and `jsdom` if missing |
| `task build` | `npm run build:linux` — see [Building](#building) |
| `task test-pr PR=<n>` | a PR's code, isolated — see [Testing a PR live](testing-a-pr.md) |
Expand Down Expand Up @@ -115,7 +117,51 @@ modifies must be 80 % covered (`diff-cover`), `main.js`, `preload.js`, the MCP
bridge, `claude-auth.js`, `public/app.js`, `public/terminal-manager.js`, the
CodeMirror and Mermaid files, workers, scripts, tests and `e2e/` excepted. The
same workflow runs the [changelog check](changelog.md#the-ci-check) on pull
requests and the [end-to-end journeys](e2e.md).
requests and the [end-to-end journeys](e2e.md). Its `deadcode` job prints the
[dead-code report](#dead-code-report); knip's findings and errors never fail it,
though a failed install does.

### Dead-code report

`task deadcode` runs [knip](https://knip.dev), pinned to an exact version in
`devDependencies`, with `npx --no-install`: it uses the locked copy in
`node_modules` and never downloads another. Run `task install` first after
pulling the change that adds it. Arguments after `--` go to knip, for example
`task deadcode -- --production`. knip exits non-zero when it reports anything;
the report is information, not a gate, and no other task depends on it.

`knip.json` declares what is analysed:

- **Production entries**, marked `!`: `main.js` (the package `main`, found by
knip itself), `preload.js` and every `workers/*.js`. Workers are started with
`new Worker(path.join(__dirname, 'workers', …))`, a path knip cannot follow,
so they are listed by pattern.
- **Other entries**: every `scripts/*.js` and `scripts/*.cjs` (each one is run
by `package.json`, `Taskfile.yaml`, a workflow, a test or by hand from a doc,
or is required by one that is),
`test/**/*.test.js` and `e2e/**/*.spec.js`.
- **Project**: the root modules, `src/**`, `harnesses/**`, `workers/**` and
`scripts/**`. `public/**` is ignored: renderer files share globals through
`<script>` tags, which knip cannot see.

Tests are entries, so the default report counts an export used only by a test
as used: a module kept for its unit test is not dead code. `-- --production`
drops the tests and the development dependencies and shows what only tests
keep alive; it also lists `@xterm/xterm`, `marked` and `morphdom` (loaded by
`public/index.html`, which is not analysed) and the `electron` binary (a
development dependency by design).

`ignoreDependencies` holds packages only the renderer loads (the xterm addons,
`dompurify` from `public/index.html`, `codemirror` bundled from
`public/codemirror-setup.js`) and three packages tests reach on purpose without
listing them: `css-tree` through jsdom's own resolution path, and
`app-builder-lib` and `builder-util` for electron-builder's macro helpers in
`test/build-workflow.test.js`.

Known false positive: knip does not follow CommonJS namespace access. An export
read as `const ns = require('./x'); ns.name()`, destructured later from `ns`, or
re-exported with `module.exports = { ...ns }` is reported unused. Check every
reported export for that pattern before removing it.

## Running from source next to an installed copy

Expand Down
32 changes: 32 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://unpkg.com/knip@6/schema.json",
"entry": [
"preload.js!",
"workers/*.js!",
"scripts/*.{js,cjs}",
"test/**/*.test.js",
"e2e/**/*.spec.js"
],
"project": [
"*.js!",
"src/**/*.js!",
"harnesses/**/*.js!",
"workers/**/*.js!",
"scripts/**/*.{js,cjs}"
],
"ignore": [
"public/**"
],
"ignoreDependencies": [
"@xterm/addon-fit",
"@xterm/addon-search",
"@xterm/addon-unicode-graphemes",
"@xterm/addon-web-links",
"@xterm/addon-webgl",
"codemirror",
"dompurify",
"css-tree",
"app-builder-lib",
"builder-util"
]
}
Loading
Loading