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- `vp run dev --browser`: Auto-opens a browser. Off by default. The dev runner writes
28 `T3CODE_NO_BROWSER` itself from this flag, so setting `T3CODE_NO_BROWSER=0` in your environment has
29 no effect; use `--browser`.
30- `vp run dev:server`: Starts just the server. It runs on Node (`node --watch src/bin.ts`), so
31 without Bun present it selects `NodePtyAdapter` and `NodeHttpServer`.
32- `vp run dev:web`: Starts just the Vite dev server for the web app.
33- `vp run dev:desktop`: Starts the Electron shell against the dev server.
34- `vp run dev:marketing`: Starts the Astro marketing site.
35- Pass dev-runner flags directly after the root task name, for example:
36 `vp run dev --home-dir /tmp/t3code-dev`
37
38### Dev state directories
39
40- Dev commands run from a linked **git worktree** default to that worktree's gitignored `.t3`, even
41 when `T3CODE_HOME` is set, storing state in `<worktree>/.t3/userdata`. Pass `--home-dir <path>` to
42 choose another isolated directory explicitly. Submodules are not worktrees and keep the normal
43 precedence.
44- From the **main checkout**, dev commands implicitly use `~/.t3/dev`, keeping development state
45 separate from `~/.t3/userdata`. An explicit `--home-dir <path>` stores state under
46 `<path>/userdata`; the base directory remains available for caches, worktrees, and other shared
47 data.
48
49## Build, check, test
50
51- `vp run build`: Fans out over `apps/*`, `packages/*`, `oxlint-plugin-t3code`, and `scripts`.
52 Workspaces that define a build task run one: desktop, marketing, server (which depends on web), and
53 web. Shared packages are consumed and bundled transitively rather than built separately.
54- `vp run build:desktop`: Builds the desktop pipeline (desktop plus server).
55- `vp run start`: Runs the production server (serves the built web app as static files).
56- `vp check`: Vite+ format, lint, and type checks. This repo sets `typeCheck: false` in its lint
57 options, so workspace type checking runs separately.
58- `vp run typecheck`: Strict TypeScript checks for all packages.
59- `vp run test`: Runs workspace tests.
60- `vp run lint:mobile`: Mobile native static analysis (`scripts/mobile-native-static-check.ts`).
61- `node apps/server/scripts/t3-sqlite-state.ts <query|exec> --base-dir <path> ...`: Inspects or seeds
62 an isolated T3 SQLite database; writes create a private backup first.
63
64## Desktop artifacts
65
66- `vp run dist:desktop:artifact --platform <mac|linux|win> --target <target> --arch <arch>`: Builds a desktop artifact for a specific platform/target/arch.
67- `vp run dist:desktop:dmg`: Builds a shareable macOS `.dmg` into `./release`. Architecture defaults
68 to the host, so this produces an arm64 DMG on Apple Silicon. Use `dist:desktop:dmg:arm64` or
69 `dist:desktop:dmg:x64`, or pass `--arch <arm64|x64|universal>`, to force one.
70- `vp run dist:desktop:linux`: Builds a Linux AppImage and `.deb` into `./release`.
71- `vp run dist:desktop:win`: Builds a Windows NSIS installer into `./release`. `:arm64` and `:x64`
72 variants exist.
73
74### Desktop `.dmg` packaging notes
75
76- Default build is unsigned/not notarized for local sharing.
77- The DMG build uses `assets/prod/black-macos-1024.png` as the production app icon source.
78- Desktop production windows load the bundled UI from the `t3code://app/` root URL (not a
79 `127.0.0.1` document URL, and not an explicit `index.html` path).
80- Desktop packaging includes `apps/server/dist` (the `t3` backend) and starts it on loopback with an
81 auth token for WebSocket/API traffic.
82- Your tester can still open it on macOS by right-clicking the app and choosing **Open** on first
83 launch.
84- To keep staging files for debugging package contents, run: `vp run dist:desktop:dmg --keep-stage`
85- To allow code-signing/notarization when configured in CI/secrets, add: `--signed`.
86- Signed macOS builds also require `T3CODE_APPLE_TEAM_ID` and
87 `T3CODE_MACOS_PROVISIONING_PROFILE`. The passkey RP domain is derived from
88 `T3CODE_CLERK_PUBLISHABLE_KEY` unless `T3CODE_CLERK_PASSKEY_RP_DOMAINS` overrides it.
89- Windows `--signed` uses Azure Trusted Signing and expects:
90 `AZURE_TRUSTED_SIGNING_ENDPOINT`, `AZURE_TRUSTED_SIGNING_ACCOUNT_NAME`,
91 `AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME`, and `AZURE_TRUSTED_SIGNING_PUBLISHER_NAME`.
92- Azure authentication env vars are also required (for example service principal with secret):
93 `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`.
94
95## Browser development
96
97`dev` and `dev:web` leave `VITE_HTTP_URL` and `VITE_WS_URL` unset so the browser resolves the backend
98from `window.location.origin`. Vite proxies `/api`, `/ws`, `/oauth`, and `/.well-known` to the
99server, allowing the same bundle to work from localhost or a tailnet hostname.
100
101## Running multiple dev instances
102
103Worktrees derive a preferred port offset from their path.
104
105- Default ports: server `13773`, web `5733`
106- Shifted ports: `base + offset`
107- Example: `T3CODE_DEV_INSTANCE=branch-a vp run dev:desktop`
108
109Offset resolution, in order:
110
1111. `T3CODE_PORT_OFFSET`, which must be a non-negative integer. Negative values are rejected.
1122. `T3CODE_DEV_INSTANCE`. An all-digit value is used directly as the offset; any other non-empty
113 value is hashed into one.
1143. The worktree path hash.
115
116Collision scanning depends on the mode. `dev:web` scans only the web port and shifts only the web
117offset. `dev:server` scans only the server port. `dev` and `dev:desktop` scan both and shift them
118together as one shared offset. Explicit server or dev-URL overrides remove the corresponding port
119from the availability check. Treat the `[dev-runner]` output as authoritative.