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

development.md

202 lines8.0 KB

1# Development
2​
3## First checkout
4​
5Install `vp` using the [root README](../../README.md#install-vp). The checkout requires Node 24;
6Bun is optional. 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## Choosing a dev process
19​
20Use `vp run dev` for server and web, or `vp run dev:desktop` for the Electron client.
21`dev:server` and `dev:web` start those processes separately.
22See the [mobile README](../../apps/mobile/README.md) for native builds and Metro.
23​
24Flags go directly after the task name, for example `vp run dev --home-dir /tmp/t3code-dev`.
25Add `--browser` to open a browser automatically.
26​
27### State and ports
28​
29Linked worktrees default to their own `.t3/userdata`, even when `T3CODE_HOME` is set.
30The main checkout defaults to `~/.t3/dev/userdata`. An explicit `--home-dir` wins in both cases.
31Never run a development server against the live `~/.t3/userdata`.
32See [test data](../../AGENTS.md#test-data) for copying a consistent database snapshot.
33​
34Read ports from the `[dev-runner]` output. Worktrees derive stable preferences from their paths,
35but occupied ports can shift them. `T3CODE_PORT_OFFSET` or `T3CODE_DEV_INSTANCE` can select a
36different preference when needed.
37​
38### Sharing and remote debugging
39​
40`vp run dev --share` publishes the web port over the machine's tailnet and prints a pairing URL
41for that origin. Give the tester the complete URL, including its token. The dev runner removes
42its mapping on exit.
43​
44Leave `VITE_HTTP_URL` and `VITE_WS_URL` unset. Vite proxies the backend through the browser's
45origin so the same build works over localhost and remote connections.
46​
47Shared runs enable bundled dev to avoid a network round trip for each import level.
48`T3CODE_BUNDLED_DEV=0` opts out when debugging bundler differences. Two reload traps matter
49when changing this setup:
50​
51- The web entry must dynamically import the app so React refresh initializes before application
52 chunks. Static imports can work on first load and fail after a route split.
53- Bundled dev rebuilds Tailwind through watched files. Its ordinary Vite hot-update hook expects
54 a server/module graph that Rolldown does not provide.
55​
56The workarounds live in the [web entry](../../apps/web/src/bootstrap.ts) and
57[Tailwind plugin](../../apps/web/vite/tailwind.ts).
58​
59#### Reusable dev credential
60​
61Use this only on a hostname where you trust every service. Browsers send cookies to all ports
62on that hostname. Any service you visit there can receive the reusable admin credential,
63including services unrelated to T3 Code. If you run untrusted services on that hostname, keep
64normal per-environment pairing instead.
65​
66To use one browser profile across web dev worktrees on the same hostname, generate one fixed
67value once:
68​
69```sh
70openssl rand -hex 32
71```
72​
73Put that value in the main checkout's gitignored `.env`:
74​
75```dotenv
76T3CODE_DEV_AUTH_TOKEN=<the value generated above>
77```
78​
79The `t3.json` Setup Worktree commands on Unix and Windows link that file to each worktree's
80`.env`. The dev runner reads repository env files at startup. `.env.local` and inherited process
81environment values override `.env`, so no per-worktree export is needed after setup.
82​
83For a manual worktree or launcher without that link, export the same fixed value instead:
84​
85```sh
86export T3CODE_DEV_AUTH_TOKEN="<the value generated above>"
87```
88​
89Do not generate a new value at startup. Start or restart `vp run dev --share` after configuration,
90then open its printed startup pairing URL once per browser profile on that hostname. Later web dev
91servers on the same hostname accept the shared cookie across ports. The cookie expires after 30
92days. Reload an old tab if its URL now serves a replacement environment.
93​
94The token and startup pairing URLs are reusable administrative secrets. Never put them in a
95commit, pull request, or public output. Every server still seeds its own auth database record at
96startup and keeps its own SQLite data, signing key, and revocation state. Desktop and non-dev
97servers ignore the value. See [environment authentication](../internals/environment-auth.md#reusable-dev-credential)
98for the security model.
99​
100## Checks
101​
102Run checks for the files and packages you changed:
103​
104```sh
105vp test run <files>
106vp lint <files>
107vp run --filter <package> typecheck
108```
109​
110Use `vp run lint:mobile` for native mobile changes. CI owns the full suite; see
111[ci.yml](../../.github/workflows/ci.yml) for its current jobs.
112The [manual Windows lane](../../.github/workflows/windows-tests.yml) is available for focused
113Windows investigation while that suite is not a required gate.
114​
115### Unused code
116​
117`vp run knip:check` checks unused files and dependencies across the repo, then
118unused runtime exports in `apps/server`, `apps/desktop`, `apps/web`, and every internal package under
119`packages/`. CI enforces both checks.
120Exported types and Effect schemas are allowed without consumers. The schema preprocessor
121recognizes schema types, including aliases and schema classes; functions that create or decode
122schemas remain checked. Canonical Effect service construction APIs stay exported with an explicit
123`@public` annotation, which Knip recognizes. Completely unused files remain checked too.
124Named exports in web UI component modules are kept as complete component sets. Knip ignores
125unused exports in `apps/web/src/components/ui/*.tsx`, while still reporting an entire unused file.
126Use `vp run knip --workspace apps/web` to audit one workspace, including exports,
127or `vp run knip:production --workspace apps/web` to find code kept alive only by tests.
128The full export audit still has findings and is not a repo-wide CI gate. Extend the
129export check's workspace selectors as more workspaces become clean. Review callers before
130deleting code; production mode can also report development scripts and test fixtures.
131Runtime-discovered entrypoints and dependency exceptions belong in [knip.jsonc](../../knip.jsonc).
132​
133## Desktop artifacts
134​
135Local artifact builds are unsigned by default and write to `release/`:
136​
137```sh
138vp run dist:desktop:dmg
139vp run dist:desktop:linux
140vp run dist:desktop:win
141```
142​
143DMGs default to the host architecture. Use `--arch` to choose another target and `--keep-stage`
144to retain packaging files for inspection. Run `vp run dist:desktop:artifact --help` for other
145options.
146​
147### Linux AppImage prerequisites
148​
149Build on Linux because the browser-secret helper links against the host's libsecret. Install
150Rust, C/C++ build tools, libsecret development headers, pkg-config, and ImageMagick.
151​
152Ubuntu and Debian:
153​
154```sh
155sudo apt-get update
156sudo apt-get install cargo rustc build-essential libsecret-1-dev pkg-config imagemagick
157```
158​
159Fedora:
160​
161```sh
162sudo dnf install rust cargo gcc gcc-c++ make libsecret-devel pkgconf-pkg-config ImageMagick
163```
164​
165Arch Linux:
166​
167```sh
168sudo pacman -S rust base-devel libsecret pkgconf imagemagick
169```
170​
171The C toolchain, pkg-config, and libsecret headers are also needed for Linux desktop development.
172​
173### macOS DMG prerequisites
174​
175Install the Xcode Command Line Tools with `xcode-select --install` and install Rust.
176For a cross-architecture or universal build, add the requested Rust targets:
177​
178```sh
179rustup target add aarch64-apple-darwin x86_64-apple-darwin
180```
181​
182### Windows installer prerequisites
183​
184Install Rust, Python 3, and Visual Studio Build Tools with **Desktop development with C++**.
185Include the Windows SDK and the MSVC build tools and Spectre-mitigated libraries for the target
186architecture. Add its Rust target:
187​
188```powershell
189rustup target add x86_64-pc-windows-msvc
190# For an ARM64 installer:
191rustup target add aarch64-pc-windows-msvc
192```
193​
194NSIS is downloaded by electron-builder. WSL support additionally needs the Linux CLI archive
195passed as `--wsl-runtime`; see the
196[release runbook](./release.md#windows-payload-topology-and-update-validation).
197​
198### Signing and passkeys
199​
200Add `--signed` after configuring the platform credentials in the
201[release runbook](./release.md). macOS passkeys need a signed, provisioned app; follow the
202[Connect setup](./connect-setup.md#desktop-passkeys) for local signing and renderer HMR.