From 643f4c7134cae239d282c226f7f0696e6846b7a9 Mon Sep 17 00:00:00 2001 From: takehiroman Date: Sat, 21 Mar 2026 12:27:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B5=90=E6=9E=9C=E5=B1=A5=E6=AD=B4?= =?UTF-8?q?=E3=81=AE=E5=8F=96=E5=BE=97=E3=81=A8=E6=9B=B4=E6=96=B0=E3=83=AD?= =?UTF-8?q?=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92=E6=94=B9=E5=96=84=E3=81=97?= =?UTF-8?q?=E3=80=81API=E3=81=A8=E3=81=AE=E6=95=B4=E5=90=88=E6=80=A7?= =?UTF-8?q?=E3=82=92=E5=BC=B7=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SKILL.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/SKILL.md b/SKILL.md index 6bebee8..f84ea0e 100644 --- a/SKILL.md +++ b/SKILL.md @@ -24,32 +24,36 @@ Use this skill for feature work, bug fixes, refactors, or reviews in this reposi - The frontend builds a typed client with `hc('/')` and calls: - `GET /api/weapons/random?count=` - `GET /api/results` + - `POST /api/results` - Local Vite dev proxies `/api` to `http://localhost:3000`. +- Result history is stored in Cloudflare KV under a single bounded key (`results`) rather than one key per record. ## Working rules for this repo - Treat `src/app.tsx` as the current source of truth for user-visible behavior. - Keep frontend and API changes aligned. If you change an API response shape, update the typed client usage in `src/app.tsx` in the same task. -- Be careful with the boundary between real data and placeholders: - - `useSWR('results', ...)` fetches live result data from KV. - - `cards` in `src/app.tsx` are currently hardcoded sample history entries. - - Do not assume the rendered history UI is already wired to backend data. +- History is live data now: + - `useSWR('results', ...)` reads current history from `GET /api/results`. + - After `POST /api/results`, the frontend updates the SWR cache directly instead of forcing a refetch. + - Keep the frontend cache update logic aligned with the backend retention limit. - `src/constants/weapon.ts` appears to be legacy or unused. Confirm usage before editing it. - `tsconfig.json` includes only `src`, even though the frontend imports types from `functions/`. If type changes behave strangely, inspect this include boundary first. - `package.json` is configured for `husky` and `lint-staged`. Avoid assuming hooks are consistently installed. +- Free-tier-conscious behavior matters here. Prefer bounded KV usage and avoid extra reads when the UI can update from the mutation response. ## Safe change workflow 1. Read `src/app.tsx` and the relevant route files before editing. 2. Prefer the existing API shape and component patterns unless the task clearly requires a change. 3. For backend changes, verify the corresponding Cloudflare binding exists in `wrangler.toml`. -4. For frontend changes, check whether data is live or placeholder before wiring UI logic. +4. For history changes, update both `functions/api/routes/result.ts` and the SWR mutation logic in `src/app.tsx`. 5. Run the narrowest useful verification available after edits. ## Verification - Install dependencies: `npm install` - Frontend dev server: `npm run dev` +- Production build: `npm run build` - Lint scripts: `npm run lint:script` - Lint styles: `npm run lint:style` @@ -57,6 +61,6 @@ If a task touches Cloudflare runtime behavior, note that local verification may ## Known pitfalls -- `functions/api/routes/weapon.ts` builds the SQL `LIMIT` clause from the query string directly. Be cautious when changing request handling there. -- `index.html` still has the default Vite title, so product polish tasks may need to update app metadata. +- `functions/api/routes/result.ts` keeps only the newest `MAX_HISTORY_ITEMS` entries. If you change that value, update the frontend cache trimming logic too. +- `src/app.tsx` disables several SWR revalidation paths and relies on mutation results for freshness. If you change that strategy, reevaluate KV read volume. - `wrangler.toml` contains concrete binding IDs. Do not rotate or replace them casually.