Open History to see the last commit
1# Scripts
2
3> For maintainers. Using T3 Code? See [docs/user](../user/).
4
5## First checkout
6
7T3 Code uses [Vite+](https://viteplus.dev/guide/). Install the global `vp` command, install
8dependencies, then start the dev stack:
9
10```bash
11curl -fsSL https://vite.plus | bash # Windows: irm https://vite.plus/ps1 | iex
12vp i
13vp run dev
14```
15
16Node 24 is required. Bun is not: the server picks Bun adapters when it detects Bun and falls back to
17Node otherwise, and nothing in contributor setup needs it.
18
19`vp run dev` prints a one-time pairing URL. Open it so the first browser navigation is
20authenticated.
21
22## Dev
23
24- `vp run dev`: Starts contracts, server, and web in watch mode.
25- `vp run dev --share`: Also publishes the web port over HTTPS on this machine's tailnet. The
26 startup pairing URL is built against the shared origin, and the mapping is removed on exit.
27 Shared runs default to Vite's bundled dev mode (`T3CODE_BUNDLED_DEV=1`): a remote browser pays a
28 network round trip per import level in unbundled dev, which turns a cold module graph into
29 minutes of waterfall. Set `T3CODE_BUNDLED_DEV=0` to opt a shared run back out.
30 The web entry loads the app with a dynamic import so React refresh starts before shared UI
31 chunks run. Keep app imports out of that entry. A static import can work on the first load
32 and then fail on reload after Vite splits code for lazy routes.
33 Bundled dev uses Tailwind's watched files to rebuild CSS. Its Vite-only hot-update hook is
34 disabled in this mode because Rolldown does not supply the Vite server or module graph.
35- `vp run dev --browser`: Auto-opens a browser. Off by default. The dev runner writes
36 `T3CODE_NO_BROWSER` itself from this flag, so setting `T3CODE_NO_BROWSER=0` in your environment has
37 no effect; use `--browser`.
38- `vp run dev:server`: Starts just the server. It runs on Node (`node --watch src/bin.ts`), so
39 without Bun present it selects `NodePtyAdapter` and `NodeHttpServer`.
40- `vp run dev:web`: Starts just the Vite dev server for the web app.
41- `vp run dev:desktop`: Starts the Electron shell against the dev server.
42- `vp run dev:marketing`: Starts the Astro marketing site.
43- Pass dev-runner flags directly after the root task name, for example:
44 `vp run dev --home-dir /tmp/t3code-dev`
45
46### Dev state directories
47
48- Dev commands run from a linked **git worktree** default to that worktree's gitignored `.t3`, even
49 when `T3CODE_HOME` is set, storing state in `<worktree>/.t3/userdata`. Pass `--home-dir <path>` to
50 choose another isolated directory explicitly. Submodules are not worktrees and keep the normal
51 precedence.
52- From the **main checkout**, dev commands implicitly use `~/.t3/dev`, keeping development state
53 separate from `~/.t3/userdata`. An explicit `--home-dir <path>` stores state under
54 `<path>/userdata`; the base directory remains available for caches, worktrees, and other shared
55 data.
56
57## Build, check, test
58
59- `vp run build`: Fans out over `apps/*`, `packages/*`, `oxlint-plugin-t3code`, and `scripts`.
60 Workspaces that define a build task run one: desktop, marketing, server (which depends on web), and
61 web. Shared packages are consumed and bundled transitively rather than built separately.
62- `vp run build:desktop`: Builds the desktop pipeline (desktop plus server).
63- `vp run start`: Runs the production server (serves the built web app as static files).
64- `vp check`: Vite+ format, lint, and type checks. This repo sets `typeCheck: false` in its lint
65 options, so workspace type checking runs separately.
66- `vp run typecheck`: Strict TypeScript checks for all packages.
67- `vp run test`: Runs workspace tests.
68- `vp run lint:mobile`: Mobile native static analysis (`scripts/mobile-native-static-check.ts`).
69- `node apps/server/scripts/t3-sqlite-state.ts <query|exec> --base-dir <path> ...`: Inspects or seeds
70 an isolated T3 SQLite database; writes create a private backup first.
71
72## Desktop artifacts
73
74- `vp run dist:desktop:artifact --platform <mac|linux|win> --target <target> --arch <arch>`: Builds a desktop artifact for a specific platform/target/arch.
75- `vp run dist:desktop:dmg`: Builds a shareable macOS `.dmg` into `./release`. Architecture defaults
76 to the host, so this produces an arm64 DMG on Apple Silicon. Use `dist:desktop:dmg:arm64` or
77 `dist:desktop:dmg:x64`, or pass `--arch <arm64|x64|universal>`, to force one.
78- `vp run dist:desktop:linux`: Builds a Linux AppImage into `./release`.
79- `vp run dist:desktop:win`: Builds a Windows NSIS installer into `./release`. `:arm64` and `:x64`
80 variants exist.
81
82### Linux AppImage prerequisites
83
84Linux AppImage packaging compiles the Rust resource monitor and the libsecret browser import
85helper. Install a Rust toolchain, the standard C/C++ build tools, libsecret development headers,
86pkg-config, and ImageMagick before running `vp run dist:desktop:linux`.
87
88Ubuntu and Debian:
89
90```bash
91sudo apt-get update
92sudo apt-get install cargo rustc build-essential libsecret-1-dev pkg-config imagemagick
93```
94
95Fedora:
96
97```bash
98sudo dnf install rust cargo gcc gcc-c++ make libsecret-devel pkgconf-pkg-config ImageMagick
99```
100
101Arch Linux:
102
103```bash
104sudo pacman -S rust base-devel libsecret pkgconf imagemagick
105```
106
107Linux desktop development also needs the C compiler, pkg-config, and libsecret headers. Its build
108and launch commands compile `native/browser-secret/main.c` into the gitignored native build
109directory. Releases place the executable in `resources/browser-secret`, outside `app.asar`.
110The helper performs a read-only Chromium schema lookup through libsecret and writes the exact
111secret bytes to its stdout pipe. Exit codes are 2 for a missing key, 3 for denied/locked access,
112and 4 for other keyring failures; the desktop importer preserves these distinctions.
113
114The artifact script checks these capabilities before starting the web and desktop builds. If
115anything is unavailable, it reports every failed check together and prints the Ubuntu/Debian
116installation command. The check compiles and links tiny temporary programs, so it also catches
117installed runtime X11 libraries that are missing their development headers or linker symlinks.
118
119### macOS DMG prerequisites
120
121Install the Xcode Command Line Tools and Rust before building a DMG:
122
123```bash
124xcode-select --install
125```
126
127Install Rust from [rustup.rs](https://rustup.rs). The artifact script checks Cargo, Clang, Make,
128`sips`, and `iconutil`. Universal builds additionally require `lipo`. It also verifies that Rust
129has every requested target; add missing targets with:
130
131```bash
132rustup target add aarch64-apple-darwin x86_64-apple-darwin
133```
134
135Unsigned local builds need no Apple credentials. Builds using `--signed` additionally require the
136certificate, provisioning profile, team ID, and notarization configuration described below.
137
138### Windows installer prerequisites
139
140Install Rust from [rustup.rs](https://rustup.rs), Python 3, and Visual Studio Build Tools. In the
141Visual Studio Installer, select **Desktop development with C++** and include:
142
143- MSVC x64/x86 build tools
144- A Windows 10 or Windows 11 SDK
145- MSVC Spectre-mitigated libraries
146
147ARM64 installers require the corresponding MSVC ARM64 build tools and Spectre-mitigated libraries
148instead of the x64/x86 components.
149
150Add the Rust target matching the installer architecture:
151
152```powershell
153rustup target add x86_64-pc-windows-msvc
154# For an arm64 installer:
155rustup target add aarch64-pc-windows-msvc
156```
157
158Windows supplies `tar.exe`; it is checked when `--wsl-prebuild` makes the artifact include the WSL
159runtime. NSIS is downloaded by electron-builder and does not need a separate installation.
160When `T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR=true` points the build at an existing resource monitor,
161the artifact script skips the Rust and Visual Studio checks because it does not compile the monitor.
162Unsigned local builds need no Azure credentials. Builds using `--signed` additionally require the
163Azure Trusted Signing configuration described below.
164
165### Desktop `.dmg` packaging notes
166
167- Default build is unsigned/not notarized for local sharing.
168- The DMG build uses `assets/prod/black-macos-1024.png` as the production app icon source.
169- The DMG chrome follows the release channel: neutral for Latest and the Nightly sky artwork for
170 Nightly. Blueprint artwork remains exclusive to Dev builds. Packaging rasterizes the selected
171 SVG into standard and Retina PNGs inside the disposable staging directory.
172- The Finder window is 540×412 while its background is 540×380; the extra 32px accounts for the
173 title bar included in Finder's window bounds.
174- Desktop production windows load the bundled UI from the `t3code://app/` root URL (not a
175 `127.0.0.1` document URL, and not an explicit `index.html` path).
176- Desktop packaging includes `apps/server/dist` (the `t3` backend) and starts it on loopback with an
177 auth token for WebSocket/API traffic.
178- Your tester can still open it on macOS by right-clicking the app and choosing **Open** on first
179 launch.
180- To keep staging files for debugging package contents, run: `vp run dist:desktop:dmg --keep-stage`
181- To allow code-signing/notarization when configured in CI/secrets, add: `--signed`.
182- Signed macOS builds also require `T3CODE_APPLE_TEAM_ID` and
183 `T3CODE_MACOS_PROVISIONING_PROFILE`. The passkey RP domain is derived from
184 `T3CODE_CLERK_PUBLISHABLE_KEY` unless `T3CODE_CLERK_PASSKEY_RP_DOMAINS` overrides it.
185- Windows `--signed` uses Azure Trusted Signing and expects:
186 `AZURE_TRUSTED_SIGNING_ENDPOINT`, `AZURE_TRUSTED_SIGNING_ACCOUNT_NAME`,
187 `AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME`, and `AZURE_TRUSTED_SIGNING_PUBLISHER_NAME`.
188- Azure authentication env vars are also required (for example service principal with secret):
189 `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`.
190
191## Browser development
192
193`dev` and `dev:web` leave `VITE_HTTP_URL` and `VITE_WS_URL` unset so the browser resolves the backend
194from `window.location.origin`. Vite proxies `/api`, `/ws`, `/oauth`, and `/.well-known` to the
195server, allowing the same bundle to work from localhost or a tailnet hostname.
196
197## Running multiple dev instances
198
199Worktrees derive a preferred port offset from their path.
200
201- Default ports: server `13773`, web `5733`
202- Shifted ports: `base + offset`
203- Example: `T3CODE_DEV_INSTANCE=branch-a vp run dev:desktop`
204
205Offset resolution, in order:
206
2071. `T3CODE_PORT_OFFSET`, which must be a non-negative integer. Negative values are rejected.
2082. `T3CODE_DEV_INSTANCE`. An all-digit value is used directly as the offset; any other non-empty
209 value is hashed into one.
2103. The worktree path hash.
211
212Collision scanning depends on the mode. `dev:web` scans only the web port and shifts only the web
213offset. `dev:server` scans only the server port. `dev` and `dev:desktop` scan both and shift them
214together as one shared offset. Explicit server or dev-URL overrides remove the corresponding port
215from the availability check. Treat the `[dev-runner]` output as authoritative.