返回 CodeWhale
README.md
根目录 / web / README.md
1 # codewhale-web
2
3 Documentation and community site for [Codewhale](https://github.com/codewhale-hq/CodeWhale) — lives at **codewhale.net**.
4
5 Next.js 16 (App Router) + Tailwind, deployed to Cloudflare Workers via [`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare). Scheduled upkeep runs as pull requests from `.github/workflows/web-maintainer.yml` (see `maintainer/README.md`).
6
7 ## Local dev
8
9 ```bash
10 cd web
11 npm install
12 cp .env.example .env.local # fill in the keys you have
13 npm run dev # http://localhost:3000
14 ```
15
16 Env (mirrors `.env.example`):
17
18 | Variable | What | Required? |
19 | --------------------------- | ---------------------------------------------------------------- | -------------------- |
20 | `DEEPSEEK_API_KEY` | DeepSeek platform key (`sk-...`) | only for the `/api/cron` tasks (summarization + community agent) |
21 | `GITHUB_TOKEN` | Fine-grained PAT, public-repo read scope | optional (raises rate limit 60 → 5000 req/h) |
22 | `GITHUB_REPO` | Defaults to `codewhale-hq/CodeWhale` | optional |
23 | `CRON_SECRET` | Shared secret for manual `/api/cron` invocation (32-512 characters, 8+ distinct; a shorter value repeated is refused)| optional (Cloudflare cron triggers don't need it) |
24 | `DEEPSEEK_MODEL` | Defaults to `deepseek-flash` | optional |
25 | `DEEPSEEK_BASE_URL` | Defaults to `https://api.deepseek.com` | optional |
26 | `MAINTAINER_TOKEN` | Admin panel auth (32-512 characters, 8+ distinct; a shorter value repeated is refused; changing it signs out sessions); enter it in the `/admin` login form | only for `/admin` |
27 | `MAINTAINER_GITHUB_PAT` | PAT with `issues:write`, for posting comments via `/admin` | only for `/admin` posting |
28 | `NEXT_PUBLIC_GITEE_ENABLED` | Set to `1` once the Gitee mirror exists; blank hides Gitee links | optional |
29
30 The site renders fine without any of them — the GitHub feed shows "feed not yet loaded".
31
32 ## Deploy to Cloudflare
33
34 The `.github/workflows/web.yml` workflow runs only for a maintainer-triggered
35 `workflow_dispatch`. Ordinary pushes and pull requests do not start it.
36 A dispatch on `main` runs the web checks and production build before deploying.
37 At the approved final publication step, record the exact 40-character
38 `origin/main` SHA and trigger that ref:
39
40 ```bash
41 git fetch origin main
42 git rev-parse origin/main
43 gh workflow run web.yml --repo codewhale-hq/CodeWhale --ref main
44 ```
45
46 Confirm that the dispatched run resolved to the recorded SHA before treating
47 its result as evidence for that candidate. The deploy job checks out the exact
48 dispatch SHA even if `main` advances while the run is queued.
49
50 The manual job records the pre-deploy source drift, builds the OpenNext bundle,
51 deploys only after the protected Cloudflare inputs pass, and then requires the
52 public `/api/facts` receipt to report the exact workflow SHA. A credential-free
53 local comparison is available without starting a deployment:
54
55 ```bash
56 npm run compare:deployed-facts -- --expected-revision <exact-40-character-sha>
57 ```
58
59 The Worker configuration now lives in `cloudflare.config.ts`; it retains the
60 existing namespace IDs, domains, cron schedules and SQLite Durable Object.
61 `npm ci` installs pinned `cf` and Cloudflare bundler versions. Use Node 22.18 or
62 newer. OpenNext currently consumes a generated legacy configuration in the
63 ignored `.cloudflare/` directory, derived from that same source with
64 Cloudflare's configuration SDK.
65
66 ```bash
67 npm run build:cloudflare # one OpenNext build, then native cf Build Output
68 npx cf deploy --prebuilt --dry-run # local validation; no upload
69 npm run preview # local Worker with populated local cache
70 ```
71
72 The pinned cf beta's Next.js detection currently invokes plain `next build`,
73 which does not produce the OpenNext Worker. `build:cloudflare` therefore runs
74 OpenNext first and invokes cf's installed bundler (`cf-wrangler.js`) to emit
75 Build Output. This is a build step; production deployment uses `cf deploy
76 --prebuilt`. Do not add a custom post-cache build to `wrangler.config.ts`:
77 rebuilding there changes the cache identity after OpenNext populates it.
78
79 After production approval, the manual workflow runs `npm run deploy`,
80 populates the remote OpenNext cache, and passes the exact prebuilt bundle to
81 cf. Existing secrets remain managed in Cloudflare; namespace provisioning,
82 secret changes and domain changes require separate approval. The predeploy
83 guard rejects unset namespace IDs to avoid accidentally replacing live data.
84 Use `npx cf cli search` to find the current resource-management commands.
85
86 ## What's where
87
88 Pages are bilingual by default: each `app/[locale]/` page renders both
89 English and Chinese from the same file, keyed by the `[locale]` segment
90 (see `lib/i18n/config.ts`). Copy changes must update both locales. Additional
91 routed **partial** locales (ja, vi, ko, ru, uk, es, pt-BR) are also wired:
92 their shared chrome (nav/footer/switcher) and home-page copy live in
93 `lib/i18n/dictionaries/<code>/` (checked by `npm run check:locales`), and
94 everything else falls back to the English copy. Routing, middleware
95 detection (`lib/i18n/detect.ts`), sitemap, and hreflang all derive from the
96 one registry.
97
98 ```
99 web/
100 ├── app/
101 │ ├── globals.css ocean portal, docs layout, type, and shared surfaces
102 │ ├── [locale]/ 10 routed locales; zh has native page bodies,
103 │ │ the rest fall back to the English body
104 │ │ ├── layout.tsx root + locale layout: html shell, fonts, nav, footer
105 │ │ ├── page.tsx home — hero, ticker, proof, decides, workflow,
106 │ │ │ start, boundaries, surfaces, install band, community
107 │ │ ├── install/page.tsx per-OS install with auto-detection
108 │ │ ├── docs/page.tsx modes / tools / approval / config / mcp / providers
109 │ │ ├── faq/page.tsx frequently asked questions
110 │ │ ├── feed/page.tsx live mirror of issues + PRs
111 │ │ ├── roadmap/page.tsx shipped / underway / considered / ruled out
112 │ │ ├── contribute/page.tsx how to contribute + house rules + dev loop
113 │ │ └── admin/ maintainer panel (page.tsx + admin-client.tsx)
114 │ └── api/
115 │ ├── cron/route.ts cron tasks: digest, facts-drift, linkcheck, …
116 │ ├── facts/route.ts public source/deployment receipt
117 │ ├── github/feed/route.ts cached JSON endpoint
118 │ └── admin/ login, logout, post (MAINTAINER_TOKEN-gated)
119 ├── data/
120 │ └── latest-published-release.json manually advanced only after publication
121 ├── components/
122 │ ├── native-terminal-gallery.tsx six captured native terminal views
123 │ ├── nav.tsx sticky header w/ date strip + CJK accents
124 │ ├── footer.tsx dense 5-column footer
125 │ ├── locale-switcher.tsx N-locale dropdown; partial packs grouped last
126 │ └── install-*.tsx install page blocks (binary, code block, tiles)
127 ├── lib/
128 │ ├── types.ts shared types
129 │ ├── i18n/ locale config, en/zh dictionaries
130 │ ├── github.ts REST client + relative-time formatter
131 │ ├── deepseek.ts v4-flash chat client
132 │ ├── facts.ts getFacts(): KV value, else build-time FACTS
133 │ ├── facts.generated.ts GENERATED — do not edit by hand
134 │ ├── changelog.generated.ts GENERATED at build/test time, untracked
135 │ ├── install-guide.generated.ts GENERATED at build/test time, untracked
136 │ ├── facts-drift.ts runtime re-derivation for the drift cron
137 │ ├── community-agent.ts digest cron task and draft store
138 │ └── kv.ts Cloudflare KV access via OpenNext bindings
139 ├── scripts/
140 │ ├── derive-facts.mjs prebuild: repo sources → lib/facts.generated.ts
141 │ ├── derive-changelog.mjs prebuild + vitest setup: CHANGELOG.md → lib/changelog.generated.ts
142 │ ├── derive-install.mjs prebuild + vitest setup: docs/INSTALL.md → lib/install-guide.generated.ts
143 │ ├── compare-deployed-facts.mjs credential-free exact-SHA receipt check
144 │ └── check-kv-id.mjs predeploy guard for KV namespace ids
145 ├── cloudflare.config.ts Worker config + existing bindings, exports and cron
146 ├── wrangler.config.ts cf bundler options (no separate Worker config)
147 ├── open-next.config.ts OpenNext adapter config
148 └── tailwind.config.ts design tokens
149 ```
150
151 ## Facts pipeline
152
153 Mechanical facts (version, provider list, sandbox backends, crate names,
154 default model, Node engines) are never hand-written into pages:
155
156 1. **Build time** — `web/scripts/derive-facts.mjs` runs as `prebuild` (and before
157 `npm run dev`), parses the parent repo (`Cargo.toml`,
158 `crates/config/assets/provider_descriptors.json`,
159 `crates/sandbox/src/lib.rs`, `npm/codewhale/package.json`) and writes
160 `lib/facts.generated.ts`. Never edit that file by hand.
161 2. **Published release** — `data/latest-published-release.json` records the
162 latest GitHub Release separately from the source candidate. Install commands
163 use this published tag; they never turn the workspace version into a release
164 before publication. The credential-free deployed-facts comparison checks the
165 record against the public receipt.
166 3. **Runtime** — the `/api/cron?task=facts-drift` cron (`lib/facts-drift.ts`)
167 resolves an exact `main` revision, derives every source fact from that SHA,
168 and writes changes to `CURATED_KV` under `facts:current`. Pages accept that
169 snapshot only when its source provenance is the same as or newer than the
170 deployed build. Legacy, malformed, or older KV data cannot replace newer
171 build facts; published-release metadata is resolved independently. Public
172 fact pages revalidate their cached HTML every five minutes.
173
174 `/api/facts` exposes only public provenance and counts: deployed/resolved source
175 revision, version, provider count, tool count, selection reason, and latest
176 published release. It contains no environment values, tokens, or KV contents.
177
178 Public provider facts derive the complete roster and optional presentation
179 labels from `crates/config/assets/provider_descriptors.json`, alongside the
180 catalog from the same selected source revision. Both local generation and the
181 remote drift check validate that descriptor document and refuse missing or
182 malformed data. Add metadata there; there is no separate website label map or
183 TUI enum roster to update.
184
185 ## Visual direction
186
187 The public site is a documentation portal with a restrained underwater atmosphere. Content and navigation come first; ocean depth, currents, and the whale mark provide identity without turning every section into a themed card.
188
189 - **Palette**: cool paper and mist for reading surfaces, deep navy for terminal and community sections, muted current blue for links, and small gold/coral signals where status needs contrast.
190 - **Type**: Space Grotesk for headings, IBM Plex Sans for body copy, and JetBrains Mono for commands and compact interface labels.
191 - **Structure**: compact documentation rows, quiet hairline dividers, generous but bounded reading widths, and responsive layouts that remove chrome before content.
192
193 If you want to retune the palette, edit `:root` in `app/globals.css` and the `colors` block in `tailwind.config.ts`.
194
194 lines MARKDOWN