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