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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# The server does not read this file itself. The systemd unit in deploy/ loads
# ~/bushido/.env through EnvironmentFile= if it exists, and docker-compose.yml
# takes an environment: block. Under plain `npm start`, export them in your shell.
# takes an environment: block. Under plain `pnpm start`, export them in your shell.
#
# Build-time settings for the frontend live in app/.env (see app/.env.example).

Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ jobs:
working-directory: app
steps:
- uses: actions/checkout@v4
# pnpm at the version package.json's packageManager names.
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: app/package-lock.json
- run: npm ci
cache: pnpm
cache-dependency-path: app/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
# Every app and server suite, each run even when one fails, with a summary at
# the end (scripts/test.mjs). The root package has no dependencies of its own.
- name: tests
working-directory: .
run: npm test
run: pnpm test
# ESLint: undefined names, the rules of hooks, and every suppression says why.
- run: npm run lint
- run: npm run build
- run: pnpm run lint
- run: pnpm run build

# The iPhone app: strict TypeScript over mobile/src, including the lib copies.
# mobile/ stays on npm: under pnpm its bundle came out different.
mobile:
runs-on: ${{ github.event.repository.private && 'box' || 'ubuntu-latest' }}
defaults:
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ jobs:
exit 1
fi

# pnpm at the version package.json names, from the Corepack that ships with node,
# so the runner's PATH needs only node on it.
- name: pnpm on the PATH
run: |
set -euo pipefail
bin="$RUNNER_TEMP/corepack-bin"
mkdir -p "$bin"
corepack enable --install-directory "$bin" pnpm
echo "$bin" >> "$GITHUB_PATH"

- name: Pull
id: pull
run: |
Expand All @@ -71,20 +81,21 @@ jobs:
fi
echo "go=true" >> "$GITHUB_OUTPUT"
changed=$(git diff --name-only "$before" "$after")
printf '%s\n' "$changed" | grep -qE '(^|/)package(-lock)?\.json$' && echo "deps=true" >> "$GITHUB_OUTPUT" || true
printf '%s\n' "$changed" | grep -qE '(^|/)(package(-lock)?\.json|pnpm-(lock|workspace)\.yaml)$' && echo "deps=true" >> "$GITHUB_OUTPUT" || true
# What the iPhone app is built from: its own folder, the web lib it copies, the server modules it imports.
printf '%s\n' "$changed" | grep -qE '^(mobile/|app/src/lib/|server/(whoop|strava)\.js$)' && echo "mobile=true" >> "$GITHUB_OUTPUT" || true
echo "Deploying $(git log --oneline -1) (was ${before:0:7})"
git log --oneline "$before..$after"

# The root's postinstall installs app/ (pnpm --dir app install --frozen-lockfile).
- name: Install dependencies
if: steps.pull.outputs.deps == 'true'
run: |
npm ci --no-audit --no-fund
pnpm install --frozen-lockfile

- name: Build
if: steps.pull.outputs.go == 'true'
run: npm run build
run: pnpm run build

- name: Restart
if: steps.pull.outputs.go == 'true'
Expand Down Expand Up @@ -115,9 +126,10 @@ jobs:
echo "::warning::Rolling back to ${{ steps.pull.outputs.before }}"
git reset --hard --quiet "${{ steps.pull.outputs.before }}"
if [ "${{ steps.pull.outputs.deps }}" = true ]; then
npm ci --no-audit --no-fund
# The commit rolled back to may predate pnpm (it has a package-lock.json).
if [ -f app/pnpm-lock.yaml ]; then pnpm install --frozen-lockfile; else npm ci --no-audit --no-fund; fi
fi
npm run build
npm run build # the root's build script, whichever manager that commit used
if [ "$(uname)" = Darwin ]; then
launchctl kickstart -k "gui/$(id -u)/$DEPLOY_SERVICE"
else
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Build output — regenerate with `cd app && npm run build`
# Build output — regenerate with `cd app && pnpm run build`
dist/
node_modules/
app/node_modules/
app/smoke/.smoke.mjs
app/.mdtest.mjs
Expand Down
39 changes: 22 additions & 17 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ reasons behind the design, and the things that have been removed on purpose.
## 0. If you read nothing else

1. **Build before you say it is done.** A change under `app/src` is not live until
`npm run build` has written `dist/`. Content files are read at runtime; app code is not.
2. **Run `npm test` at the repo root** after any change to the app, the server or a
`pnpm run build` has written `dist/`. Content files are read at runtime; app code is not.
2. **Run `pnpm test` at the repo root** after any change to the app, the server or a
content file. It runs every app suite, the SSR smoke render of every tab, and every
server suite (including `server/http.test.js`, which boots real servers).
3. **Stored data is never deleted or rewritten to suit the code.** Old entries of kinds
Expand Down Expand Up @@ -56,7 +56,7 @@ reasons behind the design, and the things that have been removed on purpose.
| `test/fixtures/plan.json` | A large synthetic climbing-and-triathlon programme used by the test suites (smoke render, every app suite, `starter.test.mjs`) and by `starter.build.mjs` / `muscles.build.mjs`. The canonical fixture, and the source both generated files are built from. |
| `data/` | Runtime state. Gitignored. Never commit, delete or rewrite it (§4). |
| `deploy/bushido.service` | The systemd user unit. |
| `scripts/start.js` | `npm start`: builds the app if there is no build, then runs the server. |
| `scripts/start.js` | `pnpm start`: builds the app if there is no build, then runs the server. |
| `Dockerfile`, `docker-compose.yml` | Container path; data in a volume at `/data`, no Claude CLI in the image. |
| `.github/workflows/ci.yml` | CI: app tests, server tests, build. A private repo runs it on a self-hosted runner labelled `box`; a public copy on GitHub's hosted runner. |

Expand All @@ -81,7 +81,7 @@ reasons behind the design, and the things that have been removed on purpose.

| Thing | Path | Notes |
|---|---|---|
| Render smoke suite | `app/smoke/` | `npm run smoke` in `app/`. Mounts every tab and session viewer against real content: one file of cases per area (`today.jsx`, `sheet.jsx`, `editor.jsx`, `planner.jsx`, `runner.jsx`, `workout.jsx`, `timer.jsx`, `log.jsx`, `progress.jsx`, `profile.jsx`, `people.jsx`, `misc.jsx`, `system.jsx`: the visual system), shared `fixtures.jsx`, one runner `index.jsx`. |
| Render smoke suite | `app/smoke/` | `pnpm run smoke` in `app/`. Mounts every tab and session viewer against real content: one file of cases per area (`today.jsx`, `sheet.jsx`, `editor.jsx`, `planner.jsx`, `runner.jsx`, `workout.jsx`, `timer.jsx`, `log.jsx`, `progress.jsx`, `profile.jsx`, `people.jsx`, `misc.jsx`, `system.jsx`: the visual system), shared `fixtures.jsx`, one runner `index.jsx`. |
| Store, merge, `isDone`, `markDone`, `doneWhenPlaced`, `isTraining`, entry ids | `app/src/lib/store.js` | The server's word-for-word copy of `isDone` is in `server/notify-facts.js` (§4). |
| Session lookup | `app/src/lib/menu.js` | `optFor(menu, optId)`; renamed cards declare old ids as `aka`. |
| Categories | `app/src/lib/category.js` | `categoryOf`, `disciplineOf`: what an entry files under, for the Log filter and Progress. |
Expand Down Expand Up @@ -119,7 +119,7 @@ reasons behind the design, and the things that have been removed on purpose.
| Number inputs | `app/src/numinput.jsx`, `app/src/lib/numtext.js` | Text inputs that own their text (§6.4). |
| Body diagram | `app/src/lib/bodymap.jsx`, `app/muscles.build.mjs` | `react-body-highlighter` + `free-exercise-db`; nothing hand-drawn. |
| How-to figures | `app/src/howto.jsx`, `app/src/lib/figuredata.js`, `app/src/lib/figures.jsx` | The drawings are data in `figuredata.js` (one skeleton, `body()`; copied byte for byte to mobile), and `figures.jsx` / `figures.tsx` only render them. Tested by `app/figures.test.jsx` (#109). |
| Palette | `app/src/styles.css` `:root`, `app/validate_palette.js` | `npm run palette`; a real gate (§6.10). The rest of the token contract is pinned by `app/smoke/system.jsx` (§10.13). |
| Palette | `app/src/styles.css` `:root`, `app/validate_palette.js` | `pnpm run palette`; a real gate (§6.10). The rest of the token contract is pinned by `app/smoke/system.jsx` (§10.13). |
| Styles | `app/src/styles.css` (tokens, base components, shell), `app/src/css/<area>.css` (each screen area's rules, one owner each), `app/src/timer.css` | A new rule goes in its area's file (`sheet.css`, `today.css`, `planner.css`, `editor.css`, `runner.css`, `workout.css`, …); `main.jsx` imports them in cascade order. See `docs/DESIGN.md`, "Visual system". |
| Notifications client | `app/src/lib/push.js`, `app/src/notifications.jsx` | |
| Device screen probe | `app/src/screeninfo.jsx` | Measures the iOS safe-area bug on the device (§10.5). |
Expand All @@ -132,23 +132,28 @@ reasons behind the design, and the things that have been removed on purpose.
## 2. Running, building, testing

```bash
npm install && npm start # builds on first run, serves on :8099
npm run dev # Vite on :5173, proxies /api and sign-in to :8099 (run npm start alongside)
npm run build # app/ → dist/
npm test # app suites + palette + SSR smoke + server suites
pnpm install && pnpm start # builds on first run, serves on :8099
pnpm run dev # Vite on :5173, proxies /api and sign-in to :8099 (run pnpm start alongside)
pnpm run build # app/ → dist/
pnpm test # app suites + palette + SSR smoke + server suites
node app/starter.build.mjs # regenerate content/starter.json and examples/plan.json
```

- **pnpm, not npm: never run `npm install` or `npm ci` at the root or in `app/`.** npm ignores
`pnpm-lock.yaml` and writes its own tree. `mobile/` is the exception: it stays on npm
(`npm ci` there): under pnpm its installed tree differed (e.g. metro 0.84.6 for
0.84.5 at the top level), and EAS's cloud build would switch to pnpm, which only a real
build could check.
- **A change under `app/src` is invisible until built.** The server serves `dist/` from
disk, so no restart is needed after a build, but without one the running app is the old
bundle while every test passes. To confirm a deploy picked it up, check that the
`assets/…` hash in the served `index.html` changed.
- **Content files need no rebuild** — they are fetched at runtime — but run `npm test`
- **Content files need no rebuild** — they are fetched at runtime — but run `pnpm test`
after editing one anyway: the suites walk every session set by set and catch a bad
property access in hand-written JSON here rather than on a phone mid-session.
- `npm test` at the root runs `scripts/test.mjs`: every app suite, then every
- `pnpm test` at the root runs `scripts/test.mjs`: every app suite, then every
`server/*.test.js`, each one even when an earlier one failed, then a PASS/FAIL line per
suite and a non-zero exit if any failed (`npm --prefix app test` and `npm run test:server`
suite and a non-zero exit if any failed (`pnpm --dir app test` and `pnpm run test:server`
run each half). The app half is its `test:*` scripts in the runner's order: the handoff
test, the palette check, the per-area suites (`test:fingers`, `test:streak`, `test:gear`,
`test:progress`, `test:workout`, `test:tests` (test-result sessions), `test:lifts`,
Expand Down Expand Up @@ -1050,9 +1055,9 @@ no rebuild. An older plan file may also carry `recommender`, `checkin`, `journal

### 6.10 Palette

**Never change a viz colour without `npm run palette`.** It checks contrast against the
**Never change a viz colour without `pnpm run palette`.** It checks contrast against the
panel, all-pairs separation under the three dichromacies, and a monotonic load ramp, and it
is part of `npm test`. It has already caught a shipped palette failing.
is part of `pnpm test`. It has already caught a shipped palette failing.

---

Expand Down Expand Up @@ -1612,8 +1617,8 @@ The regrade's code findings, behaviour unchanged except where a test names a bug
- **Files say what is in them**: `tabs.jsx` is Today, `daylist.jsx` its rows,
`dayswitcher.jsx` the switcher; `App.jsx` renders, `appdata.jsx` decides, `shell.jsx`
is the frame's pieces. The phone's `tabs.tsx` split the same way (`daylist.tsx`).
- **ESLint** (`npm run lint`): undefined names, hooks, and a reason after `--` on every
suppression. **`npm run check`** is tests, lint, build and the mobile typecheck.
- **ESLint** (`pnpm run lint`): undefined names, hooks, and a reason after `--` on every
suppression. **`pnpm run check`** is tests, lint, build and the mobile typecheck.
- **Lazy parts** (`lazy.jsx`): Plan a workout (`planner.jsx`), the interval timer's screen
(`timer.jsx`; its host, `timerhost.jsx`, is static) and WHOOP on Today (`whoopday.jsx`).
**Nothing a sheet or a workout in progress draws is lazy**: `PlanTalk` is `plantalk.jsx`,
Expand All @@ -1627,7 +1632,7 @@ The regrade's code findings, behaviour unchanged except where a test names a bug

## 11. Before you finish

- `npm run check` at the repo root passes: every suite, `npm run lint` (ESLint over
- `pnpm run check` at the repo root passes: every suite, `pnpm run lint` (ESLint over
`app/src`: undefined names, the rules of hooks, and a reason after `--` on every
suppression), the build and the mobile typecheck.
- If you touched shared content in `test/fixtures/plan.json`, you ran
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# settings and the owner account live in /data; mount a volume there.
FROM node:22-alpine AS build
WORKDIR /src
COPY app/package.json app/package-lock.json app/
RUN npm --prefix app ci --no-audit --no-fund
RUN corepack enable pnpm
COPY app/package.json app/pnpm-lock.yaml app/pnpm-workspace.yaml app/
# Corepack takes pnpm's version from the package.json in the working directory.
RUN cd app && pnpm install --frozen-lockfile
COPY . .
RUN npm --prefix app run build
RUN cd app && pnpm run build

FROM node:22-alpine
WORKDIR /app
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ server/server.js ── Node 22, no npm dependencies ────────

## Quick start

Requirements: **Node.js 22 or newer** and npm. Optional: the
Requirements: **Node.js 22 or newer** and pnpm (`corepack enable pnpm` gives you the version
`package.json` names). Optional: the
[Claude Code CLI](https://docs.claude.com/en/docs/claude-code/overview) for the AI
features.

```bash
git clone https://github.com/ehonis/bushido.git
cd bushido
npm install # installs the app's dependencies
npm start # builds the app on first run, then serves it on port 8099
pnpm install # installs the app's dependencies
pnpm start # builds the app on first run, then serves it on port 8099
```

1. The server prints a one-time setup link:
Expand Down Expand Up @@ -168,12 +169,15 @@ and WHOOP back from Bushido; it is not in this repository.
## Development

```bash
npm start # the server on :8099 (run it alongside the dev server)
npm run dev # Vite on :5173 with hot reload; proxies /api and sign-in to :8099
npm test # app suites, the render smoke test, then the server suites
pnpm start # the server on :8099 (run it alongside the dev server)
pnpm run dev # Vite on :5173 with hot reload; proxies /api and sign-in to :8099
pnpm test # app suites, the render smoke test, then the server suites
```

Editing the content file needs no rebuild. Run `npm test` after editing it anyway,
The root and `app/` use pnpm, not npm: never run `npm install` or `npm ci` there (npm ignores
`pnpm-lock.yaml`). The iPhone app in `mobile/` is the exception and stays on npm.

Editing the content file needs no rebuild. Run `pnpm test` after editing it anyway,
because the suites check every session against the code.

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion app/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frontend build-time settings. Copy to app/.env; Vite reads it on `npm run build`.
# Frontend build-time settings. Copy to app/.env; Vite reads it on `pnpm run build`.
# All optional. Nothing here has a default.

# The hostname this install is published at. Retired hostnames below move here.
Expand Down
Loading
Loading