Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

development.md

276 lines12.8 KB

1# Development
2​
3## First checkout
4​
5Install `vp` using the [root README](../../README.md#install-vp). It provides the Node version
6pinned in `package.json` (Node 26), so no separate Node install is needed. From the repository root:
7​
8```sh
9vp i
10vp run dev
11```
12​
13Open the pairing URL printed by the dev runner. The bare origin does not authenticate
14a new browser.
15​
16Prefer a container? See [Dev container](../internals/devcontainer.md) for VS Code and Codespaces setup.
17​
18## GitCafe mirror (optional)
19​
20GitHub is the source of truth. [git.cafe/pingdotgg/t3code](https://git.cafe/pingdotgg/t3code) is a
21two-way synced mirror with much higher API rate limits, which helps when many agents read PRs and
22issues at once. You never need it to contribute.
23​
24Comments, reviews, labels, and issue edits made on GitCafe sync back to GitHub. The exception is
25code: push branches and open PRs on GitHub, where CI runs. GitCafe mirrors a new PR within about a
26minute, and from then on you can work with it through either forge.
27​
28```sh
29git remote set-url origin https://git.cafe/pingdotgg/t3code.git
30git remote add github https://github.com/pingdotgg/t3code.git
31# The GitHub remote you push to: `github`, or your fork's remote.
32git config remote.pushDefault github
33gh repo set-default pingdotgg/t3code
34bun install -g @gitcafe/cli # `cafe` needs Bun 1.2 or newer
35cafe auth login && cafe auth http setup
36cafe skills install --global # optional: cafe-* skills for coding agents
37```
38​
39With `origin` on git.cafe:
40​
41- Use `cafe` for existing PRs, issues, comments, reviews, and labels, both reading and writing. Check status
42 comes from `cafe pr status <n> --json`.
43- Create PRs on GitHub: `git push` (to the `pushDefault` remote), then `gh pr create` or `gh stack`.
44 A PR opened with `cafe pr create` or `cafe stack submit` can get a different number on each forge,
45 a sync marker appended to its body, and rewritten references, and it cannot come from a fork.
46- Write or edit text with closing keywords using `gh`. Any text GitCafe writes to GitHub has its
47 `#<n>` references turned into GitCafe links, so a `Fixes #<n>` edited through `cafe` silently stops
48 closing the issue.
49- Merge with `gh pr merge <branch> --match-head-commit <sha>`. `cafe pr merge` only pins the head
50 GitCafe last saw, not the commit you reviewed.
51- Use `gh` where the mirror falls short: CI logs and reruns, a fork PR's head repository, and
52 anything `cafe` returns empty or 403/404 for.
53- PR and issue numbers can differ between the forges. Name PRs by branch
54 (`cafe pr list --head <branch>`, `gh pr view <branch>`), and write `Fixes #<GitHub number>`.
55- `cafe` flags differ from `gh`: `--repo` not `-R`, `cafe issue comments <n>` not `--comments`,
56 `cafe pr status` not `pr checks`. This repository's CI is GitHub Actions on GitHub, so `cafe ci`
57 has no runs for it; read logs with `gh run view`. `cafe api` paths omit `/api` (`cafe api /repos/...`).
58​
59## Choosing a dev process
60​
61Use `vp run dev` for server and web, or `vp run dev:desktop` for the Electron client.
62`dev:server` and `dev:web` start those processes separately.
63See the [mobile README](../../apps/mobile/README.md) for native builds and Metro.
64​
65Flags go directly after the task name, for example `vp run dev --home-dir /tmp/t3code-dev`.
66Add `--browser` to open a browser automatically.
67​
68### State and ports
69​
70Linked worktrees default to their own `.t3/userdata`, even when `T3CODE_HOME` is set.
71The main checkout defaults to `~/.t3/dev`. An explicit `--home-dir` wins in both cases.
72The first start in a worktree seeds its empty database from a read-only copy of
73`~/.t3/userdata`; `--no-seed` or `T3CODE_DEV_SEED=0` skips that.
74Never run a development server against the live `~/.t3/userdata`.
75See [test data](../../AGENTS.md#test-data) for copying a consistent database snapshot.
76​
77Read ports from the `[dev-runner]` output. Worktrees derive stable preferences from their paths,
78but occupied ports can shift them. `T3CODE_PORT_OFFSET` or `T3CODE_DEV_INSTANCE` can select a
79different preference when needed.
80​
81### Sharing and remote debugging
82​
83`vp run dev --share` publishes the web port over the machine's tailnet and prints a pairing URL
84for that origin. Give the tester the complete URL, including its token. The dev runner removes
85its mapping on exit.
86​
87Leave `VITE_HTTP_URL` and `VITE_WS_URL` unset. Vite proxies the backend through the browser's
88origin so the same build works over localhost and remote connections.
89​
90Shared runs enable bundled dev to avoid a network round trip for each import level.
91`T3CODE_BUNDLED_DEV=0` opts out when debugging bundler differences. Two reload traps matter
92when changing this setup:
93​
94- The web entry must dynamically import the app so React refresh initializes before application
95 chunks. Static imports can work on first load and fail after a route split.
96- Bundled dev rebuilds Tailwind through watched files. Its ordinary Vite hot-update hook expects
97 a server/module graph that Rolldown does not provide.
98- The app and its routes are lazy chunks, built on first request. A plugin pre-bundles the
99 startup chain when the server starts. Renaming or moving a startup route or the app entry
100 silently drops it from that list.
101​
102The workarounds live in the [web entry](../../apps/web/src/bootstrap.ts),
103[Tailwind plugin](../../apps/web/vite/tailwind.ts), and
104[startup warmup](../../apps/web/vite/warmBundledDev.ts).
105​
106`vp run dev --share --built` skips the Vite dev server. It runs `vp build --watch` for the web
107app, and the backend serves `apps/web/dist` on the same tailnet URL and pairing flow. Use it when
108someone tests over a slow link or only needs to use the app: loads are production size, and the
109first load does not wait for dev bundling. There is no HMR. After an edit, wait for the
110`built in` line (about 6 s), then reload. Until the first build exists, the URL shows a page that
111reloads by itself. The license manifest is not generated in this mode. `--built` requires
112`--share` and the `dev` mode.
113​
114#### Reusable dev credential
115​
116Use this only on a hostname where you trust every service. Browsers send cookies to all ports
117on that hostname. Any service you visit there can receive the reusable admin credential,
118including services unrelated to T3 Code. If you run untrusted services on that hostname, keep
119normal per-environment pairing instead.
120​
121To use one browser profile across web dev worktrees on the same hostname, generate one fixed
122value once:
123​
124```sh
125openssl rand -hex 32
126```
127​
128Put that value in the main checkout's gitignored `.env`:
129​
130```dotenv
131T3CODE_DEV_AUTH_TOKEN=<the value generated above>
132```
133​
134The `t3.json` Setup Worktree action links that file to each worktree's `.env`. The dev runner reads repository env files at startup. `.env.local` and inherited process
135environment values override `.env`, so no per-worktree export is needed after setup.
136​
137For a manual worktree or launcher without that link, export the same fixed value instead:
138​
139```sh
140export T3CODE_DEV_AUTH_TOKEN="<the value generated above>"
141```
142​
143Do not generate a new value at startup. Start or restart `vp run dev --share` after configuration,
144then open its printed startup pairing URL once per browser profile on that hostname. Later web dev
145servers on the same hostname accept the shared cookie across ports. The cookie expires after 30
146days. Reload an old tab if its URL now serves a replacement environment.
147​
148The token and startup pairing URLs are reusable administrative secrets. Never put them in a
149commit, pull request, or public output. Every server still seeds its own auth database record at
150startup and keeps its own SQLite data, signing key, and revocation state. Desktop and non-dev
151servers ignore the value. See [environment authentication](../internals/environment-auth.md#reusable-dev-credential)
152for the security model.
153​
154## Checks
155​
156`vp run check:changed` runs CI's fast checks for your branch's changes: format and lint of the
157changed files, `knip:check` when code or a manifest changes, the generated GraphQL checks, typecheck
158of the affected packages and their dependents, and the test files beside the changed files. It maps
159files to packages with [ci-changes.cjs](../../.github/scripts/ci-changes.cjs), as CI does. It
160compares against the merge base with `origin/main`, or with a ref you pass. CI still runs the full
161test suites and the jobs the summary lists, so a local pass does not promise a green CI run.
162​
163The steps run side by side, so a run takes about as long as its slowest step, usually knip's
164exports pass at about 10 s. When the files are exactly those of the last passing run, it prints that
165run's summary instead of running again. Any change to a file, the install, or a generated file runs
166the checks again.
167​
168While you iterate, run single checks:
169​
170```sh
171vp test run <files>
172vp lint <files>
173vp run --filter <package> typecheck
174```
175​
176In `apps/web`, a test that renders React or touches the DOM is named `*.browser.test.{ts,tsx}`
177and runs in headless Chromium with the React Compiler on, like the app. There is no jsdom; other
178`*.test.ts` files run in Node.
179​
180TypeScript workspaces typecheck with `tsc`. The `typescript` catalog entry is
181`@tsc-rs/typescript`, the tsc-rs drop-in, with Effect diagnostics, quick fixes, and
182refactors built in. VS Code uses it through `js/ts.tsdk.path` in `.vscode/settings.json`.
183​
184Use `vp run lint:mobile` for native mobile changes. CI owns the full suite; see
185[ci.yml](../../.github/workflows/ci.yml) for its current jobs.
186The [manual Windows lane](../../.github/workflows/windows-tests.yml) is available for focused
187Windows investigation while that suite is not a required gate.
188​
189### Unused code
190​
191`vp run knip:check` checks unused files and dependencies across the repo, then
192unused runtime exports in `apps/server`, `apps/desktop`, `apps/web`, and every internal package under
193`packages/`. CI enforces both checks.
194Exported types and Effect schemas are allowed without consumers. The schema preprocessor
195recognizes schema types, including aliases and schema classes; functions that create or decode
196schemas remain checked. Canonical Effect service construction APIs stay exported with an explicit
197`@public` annotation, which Knip recognizes. Completely unused files remain checked too.
198Named exports in web UI component modules are kept as complete component sets. Knip ignores
199unused exports in `apps/web/src/components/ui/*.tsx`, while still reporting an entire unused file.
200Use `vp run knip --workspace apps/web` to audit one workspace, including exports,
201or `vp run knip:production --workspace apps/web` to find code kept alive only by tests.
202The full export audit still has findings and is not a repo-wide CI gate. Extend the
203export check's workspace selectors as more workspaces become clean. Review callers before
204deleting code; production mode can also report development scripts and test fixtures.
205Runtime-discovered entrypoints and dependency exceptions belong in [knip.jsonc](../../knip.jsonc).
206​
207## Desktop artifacts
208​
209Local artifact builds are unsigned by default and write to `release/`:
210​
211```sh
212vp run dist:desktop:dmg
213vp run dist:desktop:linux
214vp run dist:desktop:win
215```
216​
217DMGs default to the host architecture. Use `--arch` to choose another target and `--keep-stage`
218to retain packaging files for inspection. Run `vp run dist:desktop:artifact --help` for other
219options.
220​
221### Linux AppImage prerequisites
222​
223Build on Linux because the browser-secret helper links against the host's libsecret. Install
224Rust, C/C++ build tools, libsecret development headers, pkg-config, and ImageMagick.
225​
226Ubuntu and Debian:
227​
228```sh
229sudo apt-get update
230sudo apt-get install cargo rustc build-essential libsecret-1-dev pkg-config imagemagick
231```
232​
233Fedora:
234​
235```sh
236sudo dnf install rust cargo gcc gcc-c++ make libsecret-devel pkgconf-pkg-config ImageMagick
237```
238​
239Arch Linux:
240​
241```sh
242sudo pacman -S rust base-devel libsecret pkgconf imagemagick
243```
244​
245The C toolchain, pkg-config, and libsecret headers are also needed for Linux desktop development.
246​
247### macOS DMG prerequisites
248​
249Install the Xcode Command Line Tools with `xcode-select --install` and install Rust.
250For a cross-architecture or universal build, add the requested Rust targets:
251​
252```sh
253rustup target add aarch64-apple-darwin x86_64-apple-darwin
254```
255​
256### Windows installer prerequisites
257​
258Install Rust, Python 3, and Visual Studio Build Tools with **Desktop development with C++**.
259Include the Windows SDK and the MSVC build tools and Spectre-mitigated libraries for the target
260architecture. Add its Rust target:
261​
262```powershell
263rustup target add x86_64-pc-windows-msvc
264# For an ARM64 installer:
265rustup target add aarch64-pc-windows-msvc
266```
267​
268NSIS is downloaded by electron-builder. WSL support additionally needs the Linux CLI archive
269passed as `--wsl-runtime`; see the
270[release runbook](./release.md#windows-payload-topology-and-update-validation).
271​
272### Signing and passkeys
273​
274Add `--signed` after configuring the platform credentials in the
275[release runbook](./release.md). macOS passkeys need a signed, provisioned app; follow the
276[Connect setup](./connect-setup.md#desktop-passkeys) for local signing and renderer HMR.