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

development.md

362 lines18.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 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 # `gh` is still used for merging
32bun install -g @gitcafe/cli@latest # `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>`, and GitHub Actions logs with `cafe ci logs <run>` (run ids
43 from `cafe ci list --pr <n>`). `cafe ci rerun <run>` reruns one. These need `cafe` 0.11 or newer.
44- Write closing references as `Fixes pingdotgg/t3code#<n>`. GitCafe turns a bare `#<n>` in text it
45 syncs to GitHub into a git.cafe link, and GitHub does not close issues from those.
46- Merge with `gh pr merge <n> --match-head-commit <sha>`, because `cafe pr merge` cannot pin the
47 commit you reviewed.
48- `cafe` commands differ from `gh`: `cafe issue comments <n>` not `--comments`, `cafe pr status`
49 not `pr checks`.
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​
60To stop a worktree's dev stack when its thread settles, import the **Dev** action from
61`t3.json` in Settings > Projects > Actions and start it through the action menu or its
62keybinding. Its `stopOnSettle` option lets T3 stop the terminal and its child processes.
63Running `vp run dev` through an agent's own shell tool does not attach it to this lifecycle.
64​
65### State and ports
66​
67Linked worktrees default to their own `.t3/userdata`, even when `T3CODE_HOME` is set.
68The main checkout defaults to `~/.t3/dev`. An explicit `--home-dir` wins in both cases.
69The first start in a worktree seeds its empty database from a read-only copy of
70`~/.t3/userdata/statev2.sqlite` if the source is at most 500 MiB. Larger sources warn
71and dev starts with an empty database. `--no-seed` or `T3CODE_DEV_SEED=0` skips seeding.
72To copy a larger source, run `vp run migrate-dev-db` with dev stopped. It may use
73substantial disk space before pruning.
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### Replay provider
82​
83`vp run dev` registers `Replay (dev)`, a local ACP agent at
84[dev-replay-agent.ts](../../apps/server/scripts/dev-replay-agent.ts). It plays recorded
85ACP transcripts with simulated streaming, so the real adapter, orchestration, and UI run
86without a paid model. Each scenario is a model, and each prompt plays the next recorded turn.
87Bundled servers, including desktop dev, skip it because they have no agent script.
88Dev servers add it back on start, so turn it off in Settings instead of removing it.
89To add a scenario, point a `SCENARIOS` entry at a generic ACP replay fixture
90(`registry_transcript.ndjson`) or a file in [dev-replay](../../apps/server/scripts/dev-replay).
91The agent replays session updates, permission requests, and questions. It drops session setup
92and vendor frames, so Grok and fx recordings lose their vendor-only behavior.
93​
94### Profiling dev startup
95​
96Run `vp run profile:startup` to capture the first 20 seconds of inherited Node processes under
97`.t3/startup-profiles/<timestamp>`. Workers that execute the preload get separate profiles.
98It starts the normal dev runner and accepts its flags.
99Stop it with Ctrl+C after the capture. Set `T3CODE_STARTUP_PROFILE_DIR` to choose another output
100directory. Profiling adds overhead, so compare readiness with an ordinary `vp run dev` run.
101​
102Open a `.cpuprofile` in Chrome DevTools' Performance panel for sampled function stacks and source
103lines. Each `.modules.json` is a Chrome trace containing timed module resolution, loading,
104synchronous subprocess calls, and startup measures. Per-file records include importer URLs,
105source loading, preparation, recursive dependency linking, and top-level evaluation. Preparation
106uses synchronous loader boundaries; linking includes dependencies, and CommonJS evaluation can
107include nested `require` calls. Some ESM/CommonJS interop reports a combined stage. `.process.json` records the process, Node version, and capture window.
108The server's nested Effect and SQL spans remain in `.t3/userdata/logs/server.trace.ndjson`.
109​
110The preload temporarily adds module-body timing markers and uses one automatic debugger pause
111to instrument the live Node loader. The launcher adds `--no-node-snapshot` to inherited
112`NODE_OPTIONS` because Node 26's snapshotted loader cannot accept that breakpoint. Include the
113same flag when using the preload directly. This disables Node's built-in startup snapshot,
114can change compilation-cache hits, and adds overhead.
115Treat per-file captures as diagnostic runs; use uninstrumented runs for baseline startup latency.
116The first entry module can compile before loader instrumentation is installed.
117​
118A fresh process still uses filesystem, Node compilation, provider, and Vite dependency caches.
119Measure a missing Vite dependency cache separately from a restart with an existing database.
120Neither the Vite ready message nor the HTTP listener proves that a browser has rendered the app.
121​
122### Sharing and remote debugging
123​
124`vp run dev --share` publishes the web port over the machine's tailnet and prints a pairing URL
125for that origin. Give the tester the complete URL, including its token. The dev runner removes
126its mapping on exit.
127​
128Leave `VITE_HTTP_URL` and `VITE_WS_URL` unset. Vite proxies the backend through the browser's
129origin so the same build works over localhost and remote connections.
130​
131Shared runs enable bundled dev to avoid a network round trip for each import level.
132`T3CODE_BUNDLED_DEV=0` opts out when debugging bundler differences. Two reload traps matter
133when changing this setup:
134​
135- The web entry must dynamically import the app so React refresh initializes before application
136 chunks. Static imports can work on first load and fail after a route split.
137- Bundled dev rebuilds Tailwind through watched files. Its ordinary Vite hot-update hook expects
138 a server/module graph that Rolldown does not provide.
139- The app and its routes are lazy chunks, built on first request. A plugin pre-bundles the
140 startup chain when the server starts. Renaming or moving a startup route or the app entry
141 silently drops it from that list.
142​
143The workarounds live in the [web entry](../../apps/web/src/bootstrap.ts),
144[Tailwind plugin](../../apps/web/vite/tailwind.ts), and
145[startup warmup](../../apps/web/vite/warmBundledDev.ts).
146​
147`vp run dev --share --built` skips the Vite dev server. It runs `vp build --watch` for the web
148app, and the backend serves `apps/web/dist` on the same tailnet URL and pairing flow. Use it when
149someone tests over a slow link or only needs to use the app: loads are production size, and the
150first load does not wait for dev bundling. There is no HMR. After an edit, wait for the
151`built in` line (about 6 s), then reload. Until the first build exists, the URL shows a page that
152reloads by itself. The license manifest is not generated in this mode. `--built` requires
153`--share` and the `dev` mode.
154​
155#### Reusable dev credential
156​
157Use this only on a hostname where you trust every service. Browsers send cookies to all ports
158on that hostname. Any service you visit there can receive the reusable admin credential,
159including services unrelated to T3 Code. If you run untrusted services on that hostname, keep
160normal per-environment pairing instead.
161​
162To use one browser profile across web dev worktrees on the same hostname, generate one fixed
163value once:
164​
165```sh
166openssl rand -hex 32
167```
168​
169Put that value in the main checkout's gitignored `.env`:
170​
171```dotenv
172T3CODE_DEV_AUTH_TOKEN=<the value generated above>
173```
174​
175The `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
176environment values override `.env`, so no per-worktree export is needed after setup.
177​
178For a manual worktree or launcher without that link, export the same fixed value instead:
179​
180```sh
181export T3CODE_DEV_AUTH_TOKEN="<the value generated above>"
182```
183​
184Do not generate a new value at startup. Start or restart `vp run dev --share` after configuration,
185then open its printed startup pairing URL once per browser profile on that hostname. Later web dev
186servers on the same hostname accept the shared cookie across ports. The cookie expires after 30
187days. Reload an old tab if its URL now serves a replacement environment.
188​
189The token and startup pairing URLs are reusable administrative secrets. Never put them in a
190commit, pull request, or public output. Every server still seeds its own auth database record at
191startup and keeps its own SQLite data, signing key, and revocation state. Desktop and non-dev
192servers ignore the value. See [environment authentication](../internals/environment-auth.md#reusable-dev-credential)
193for the security model.
194​
195## Checks
196​
197`vp run check:changed` runs CI's fast checks for your branch's changes: format and lint of the
198changed files, `knip:check` when code or a manifest changes, the generated GraphQL checks, typecheck
199of the affected packages and their dependents, and the test files beside the changed files. It also
200runs the checks that read other files: the agent context budget when the server is affected, and
201React Compiler coverage for only the changed web and mobile files. It maps
202files to packages with [ci-changes.cjs](../../.github/scripts/ci-changes.cjs), as CI does. It
203compares against the closest merge base with any remote's `main`, so a fork whose `main` lags
204upstream still compares against upstream, or with a ref you pass. CI still runs the full
205test suites and the jobs the summary lists, so a local pass does not promise a green CI run.
206​
207The steps run side by side, as many at once as the machine allows: one per two cores and per 6 GiB
208of available memory. On a large machine a run takes about as long as its slowest step, usually
209knip's exports pass at about 10 s. Pass `--concurrency <n>` or set `CHECK_CHANGED_CONCURRENCY` to
210change the limit (`1` runs the steps one by one). A step that runs past `--timeout <seconds>` or
211`CHECK_CHANGED_TIMEOUT` (default 900) is killed with every process it started and reported as
212`TIMEOUT`, not as a failing check. When the files are exactly those of the last passing run, it prints that
213run's summary instead of running again. Any change to a file, the install, or a generated file runs
214the checks again.
215​
216While you iterate, run single checks:
217​
218```sh
219vp test run <files>
220vp lint <files>
221vp run --filter <package> typecheck
222```
223​
224In `apps/web`, a test that renders React or touches the DOM is named `*.browser.test.{ts,tsx}`
225and runs in headless Chromium with the React Compiler on, like the app. There is no jsdom; other
226`*.test.ts` files run in Node.
227​
228TypeScript workspaces typecheck with `effect-tsgo tsrs --noEmit` from `@effect/tsgo`: the
229[tsrs](https://github.com/oxc-project/tsrs) checker with Effect diagnostics, quick fixes, and
230refactors built in. Only `apps/marketing` installs `typescript`, for Astro. VS Code's TypeScript 7
231extension starts the same checker through `.vscode/tsdk/tsgo` (`js/ts.tsdk.path`), a POSIX
232script, so on Windows open the workspace through WSL.
233​
234Use `vp run lint:mobile` for native mobile changes. CI owns the full suite; see
235[ci.yml](../../.github/workflows/ci.yml) for its current jobs.
236The [manual Windows lane](../../.github/workflows/windows-tests.yml) is available for focused
237Windows investigation while that suite is not a required gate.
238​
239### Unused code
240​
241`vp run knip:check` checks unused files and dependencies across the repo and, at the same time,
242unused runtime exports in `apps/server`, `apps/desktop`, `apps/web`, and every internal package under
243`packages/`. CI enforces both checks.
244Exported types and Effect schemas are allowed without consumers. The schema preprocessor
245recognizes schema types, including aliases and schema classes; functions that create or decode
246schemas remain checked. Canonical Effect service construction APIs stay exported with an explicit
247`@public` annotation, which Knip recognizes. Completely unused files remain checked too.
248Named exports in web UI component modules are kept as complete component sets. Knip ignores
249unused exports in `apps/web/src/components/ui/*.tsx`, while still reporting an entire unused file.
250Use `vp run knip --workspace apps/web` to audit one workspace, including exports,
251or `vp run knip:production --workspace apps/web` to find code kept alive only by tests.
252The full export audit still has findings and is not a repo-wide CI gate. Extend the
253export check's workspace selectors as more workspaces become clean. Review callers before
254deleting code; production mode can also report development scripts and test fixtures.
255Runtime-discovered entrypoints and dependency exceptions belong in [knip.jsonc](../../knip.jsonc).
256​
257## Desktop artifacts
258​
259Local artifact builds are unsigned by default and write to `release/`:
260​
261```sh
262vp run dist:desktop:dmg
263vp run dist:desktop:linux
264vp run dist:desktop:win
265```
266​
267`dist:desktop:linux` targets x64. For a native Linux ARM64 build, run:
268​
269```sh
270vp run dist:desktop:artifact --platform linux --target AppImage --arch arm64
271```
272​
273DMGs default to the host architecture. Use `--arch` to choose another target and `--keep-stage`
274to retain packaging files for inspection. Run `vp run dist:desktop:artifact --help` for other
275options.
276​
277### Prepared server bytecode
278​
279Native macOS and Windows desktop artifact builds, and native Linux x64 and ARM64 builds, generate server
280bytecode with the packaged Electron executable, after ASAR creation and before signing. Generation imports the CLI and server
281module declarations without launching server services; worker-only modules compile normally.
282AppImage backends use temporary links for each mount and remove them on normal exit. Later launches
283reclaim abandoned cache directories whose links point to gone mounts; AppImage main-process caching
284stays disabled. macOS x64 builds on ARM64 hosts run the packaged x64 Electron
285under Rosetta to generate the cache. Other cross-platform and cross-architecture builds skip
286generation explicitly. CLI, SEA and WSL runtimes keep their existing behavior.
287​
288Electron's Node 24 cache has no read-only option and includes the producer UID in its directory
289name. The backend links individual prepared files into its writable cache with keys for the
290installed module paths. Node replaces files atomically, so regeneration cannot write through those
291links into signed resources. Windows uses hard links and falls back to normal caching when volumes
292differ or resource permissions prevent linking. Protected installations therefore may not reuse
293prepared bytecode. No cache bytes are copied during startup.
294​
295The key calculation follows Node's internal portable ESM format. Generation checks that the
296packaged engine produced the expected CLI and server entries and fails the build if that format changes.
297The manifest also checks Electron, Node, OS, architecture and V8's flags-sensitive version tag.
298Missing or rejected entries compile from the shipped JavaScript. Prepared backends skip the
299explicit startup flush; Node can persist missing entries on normal exit. The writable fallback
300keeps the explicit flush needed when Windows force-kills the backend.
301​
302### Linux AppImage prerequisites
303​
304Build on Linux because the browser-secret helper links against the host's libsecret. Install
305C/C++ build tools, libsecret development headers, pkg-config, and ImageMagick.
306Bytecode preparation also runs packaged Electron and requires GTK, NSS, ALSA, and GBM runtime libraries.
307Install Rust 1.95 or newer through [rustup](https://rust-lang.org/install), using the stable
308toolchain as release CI does.
309​
310Ubuntu 24.04 and Debian 13:
311​
312```sh
313sudo apt-get update
314sudo apt-get install build-essential libsecret-1-dev pkg-config imagemagick libgtk-3-0t64 libnss3 libasound2t64 libgbm1
315```
316​
317On Ubuntu 22.04 and Debian 12, use `libgtk-3-0` and `libasound2` instead of the `t64` packages.
318​
319Fedora:
320​
321```sh
322sudo dnf install gcc gcc-c++ make libsecret-devel pkgconf-pkg-config ImageMagick gtk3 nss alsa-lib mesa-libgbm
323```
324​
325Arch Linux:
326​
327```sh
328sudo pacman -S base-devel libsecret pkgconf imagemagick gtk3 nss alsa-lib mesa
329```
330​
331The C toolchain, pkg-config, and libsecret headers are also needed for Linux desktop development.
332​
333### macOS DMG prerequisites
334​
335Install the Xcode Command Line Tools with `xcode-select --install` and install Rust.
336For a cross-architecture or universal build, add the requested Rust targets:
337​
338```sh
339rustup target add aarch64-apple-darwin x86_64-apple-darwin
340```
341​
342### Windows installer prerequisites
343​
344Install Rust, Python 3, and Visual Studio Build Tools with **Desktop development with C++**.
345Include the Windows SDK and the MSVC build tools and Spectre-mitigated libraries for the target
346architecture. Add its Rust target:
347​
348```powershell
349rustup target add x86_64-pc-windows-msvc
350# For an ARM64 installer:
351rustup target add aarch64-pc-windows-msvc
352```
353​
354NSIS is downloaded by electron-builder. WSL support additionally needs the Linux CLI archive
355passed as `--wsl-runtime`; see the
356[release runbook](./release.md#windows-payload-topology-and-update-validation).
357​
358### Signing and passkeys
359​
360Add `--signed` after configuring the platform credentials in the
361[release runbook](./release.md). macOS passkeys need a signed, provisioned app; follow the
362[Connect setup](./connect-setup.md#desktop-passkeys) for local signing and renderer HMR.