@@ -111,7 +111,10 @@ identical to production. It needs no secrets, 1Password, or GitHub OAuth App.
111111 Every dev server start then makes sure the one shared ` syntax-auth ` container is running,
112112 whether or not any other Syntax app is already running, without delaying the dev server. Any number of
113113 apps may start at once: container changes are serialized by a machine-wide lock that the OS
114- releases even if a process crashes. It opens Docker Desktop on macOS when needed, pulls newer
114+ releases even if a process crashes. It opens Docker Desktop (or OrbStack) on macOS when needed
115+ and a person is at the Mac's screen (see below for when it never does), under the same lock, so
116+ the app is opened only once at a time: a second app starting meanwhile waits for that start and,
117+ if it failed or stalled, prints the same message instead of opening it again. It pulls newer
115118 images and swaps them in from a detached process, keeps local users and sessions in a Docker
116119 volume, and skips Vitest. If Docker is missing or stopped, the image is not accessible, or
117120 another program holds the port, it prints one warning naming the exact problem and its fix, and
@@ -154,7 +157,97 @@ two addresses to use instead. A request from an origin it doesn't trust gets a 4
154157Syntax apps can also run locally on three HTTPS names, served by a local HTTPS proxy:
155158` https://syntax.test ` (the website), ` https://lab.syntax.test ` (Lab), and ` https://auth.syntax.test `
156159(local Syntax Auth). On those names, as in production, one cookie on the parent domain
157- (` .syntax.test ` ) signs a browser in to every app:
160+ (` .syntax.test ` ) signs a browser in to every app.
161+
162+ Give the plugin the app's name to set its name up whenever its dev server starts (never under
163+ Vitest or in a build). ` port ` is where the name forwards, by default the port Vite listens on; an
164+ app whose dev server sits behind another (Lab under ` alchemy dev ` ) passes that one. ` routes ` sends
165+ paths to other local servers:
166+
167+ ``` ts
168+ syntax_auth ({ name: ' lab' , port: 1337 , routes: [{ path: ' /parties/*' , port: 1999 }] });
169+ ```
170+
171+ On macOS, each start makes sure of these steps, in order, without delaying the dev server. A step
172+ that is already done is skipped, so after the first start nothing asks again:
173+
174+ 1 . ** Hosts file.** ` /etc/hosts ` gets any missing ` 127.0.0.1 ` and ` ::1 ` entries for the three names,
175+ in one block marked ` # >>> syntax.test ` … ` # <<< syntax.test ` . Changing it asks for your password
176+ (or Touch ID) in a macOS dialog. A fixed script, never a file anyone could edit, then checks the
177+ file is still the one setup planned from (if another program changed it while the dialog was
178+ open, it changes nothing and says so), saves it as ` /etc/hosts.syntax-test.bak ` , rewrites only
179+ that block through a copy moved into place, and clears the DNS cache; an interrupted edit leaves
180+ the old file or the new one. Every byte outside the block stays as it was, CRLF line endings and
181+ a missing final newline included, and a name another line points elsewhere is left alone and
182+ reported. A damaged block (a marker without its partner, two blocks, or an altered marker line)
183+ is refused with its fix. One setup runs at a time on the machine, and a dialog left open closes
184+ after 5 minutes.
185+ 2 . ** HTTPS proxy.** If Caddy's admin API answers on ` 127.0.0.1:2019 ` and is proven to be Caddy
186+ (it answers as Caddy's does, and the one program listening on ` 127.0.0.1:2019 ` , or on a wildcard
187+ address that covers it, is ` caddy ` ), setup adds its routes there, first in the port 443 server,
188+ and leaves every other route alone. If a route it didn't add matches a name at any depth (inside
189+ a subroute, in a host list, or by a wildcard such as ` *.syntax.test ` ), setup names that route and
190+ changes nothing. Otherwise it starts Syntax's
191+ own ` syntax-caddy ` container from the official Caddy image, pinned by digest, published on
192+ ` 127.0.0.1 ` only (ports 443, 80, and 2019), with its certificates in a Docker volume; a program
193+ already on one of those ports is named instead, and if setup can't read which programs listen,
194+ it stops rather than assume the ports are free. Each name gets a route with the ` @id `
195+ ` syntax-test-<name> ` (` syntax-test-auth ` forwards to port 37960 on every start), plus one
196+ ` tls internal ` certificate policy, ` syntax-test-tls ` . Only this computer and its tailnet
197+ (` 100.64.0.0/10 ` ) get through; any other client gets a 403. While dev runs, setup checks every
198+ 15 seconds and adds the routes back if Caddy lost them (a restart or ` caddy reload ` ).
199+ 3 . ** Certificate trust.** Setup reads the root certificate from that Caddy's own certificate
200+ authority, checks that it issued the certificate Caddy serves for the names, and trusts it in
201+ your login keychain with one macOS approval. A root that didn't issue it is refused, with the
202+ reason. If you decline, the certificate macOS added is removed again.
203+ 4 . ** Final check.** The names resolve to this computer, Caddy has the routes, macOS trusts the
204+ certificate, and ` https://<name> ` reaches this very dev server.
205+
206+ Then the dev server prints ` https://<name> is ready. ` , and page loads on ` localhost ` (or
207+ ` 127.0.0.1 ` ) go to the same path on the https name; scripts' requests are never redirected. If a
208+ step fails, the dev server prints the step, what failed, and its fix, keeps running on ` localhost ` ,
209+ and answers page loads there with a page naming the same, with a link to keep that browser on
210+ ` localhost ` for now. A retry (restart dev) is always safe, and a command that stalls is stopped
211+ with a message naming it.
212+
213+ Setup shows its password and approval dialogs only when a person is likely at the Mac's screen.
214+ It shows none, changes nothing, and prints each fix when dev (or ` syntax-auth-local setup ` )
215+ starts:
216+
217+ - from an AI coding agent's shell (` CLAUDECODE ` or ` PI_CODING_AGENT ` set), so an agent checking
218+ a page never makes a dialog appear in front of you;
219+ - over SSH (` SSH_CONNECTION ` or ` SSH_TTY ` set), in CI (` CI ` set), or under a test runner
220+ (` NODE_TEST_CONTEXT ` or ` VITEST ` set);
221+ - outside the Mac's desktop session (` launchctl managername ` isn't ` Aqua ` ).
222+
223+ Each of these variables counts when it is set at all, whatever its value: ` CI= ` , ` CI=0 ` , and
224+ ` CI=false ` all mean CI. Only an unset variable is absent.
225+
226+ Its first line says which one, for example "Started from an agent shell (PI_CODING_AGENT), so
227+ setup didn't show any dialogs and changed nothing." Each fix after it is a command to run in
228+ Terminal at the Mac's own screen, such as
229+ ` pnpm exec syntax-auth-local setup lab --port 1337 --route '/parties/*=1999' ` (the dev server
230+ prints it with its own port and routes); ` setup lab ` and ` setup website ` need ` --port ` . When you
231+ are watching the screen and want an agent's run to show the dialogs, start it with
232+ ` SYNTAX_DEV_SETUP_DIALOGS=allow ` , for example ` SYNTAX_DEV_SETUP_DIALOGS=allow pnpm dev ` . That
233+ switch never works over SSH, in CI, or under a test runner.
234+
235+ In those same cases nothing opens Docker Desktop or OrbStack either, since their first run and
236+ privileged helper can show dialogs of their own: not a dev server with a name, not one without,
237+ and not ` syntax-auth-local ` . If Docker isn't running, the app runs signed out with a message
238+ such as "Docker isn't running, and this dev server was started from an agent shell
239+ (PI_CODING_AGENT), so it didn't open Docker Desktop or OrbStack. Start Docker Desktop (or
240+ OrbStack), then restart dev." When Docker already runs, an agent's dev server still starts the
241+ local Syntax Auth container, which shows no dialog. ` SYNTAX_DEV_SETUP_DIALOGS=allow ` , at the
242+ Mac's screen, lets it open Docker too.
243+
244+ On Linux and Windows setup changes nothing and says that automatic setup is macOS-only for now.
245+ There, and over SSH, in CI, under a test runner, or outside the desktop session, a named dev
246+ server also leaves Docker and the local Syntax Auth container alone: if Syntax Auth isn't
247+ running, it says to start it with ` pnpm exec syntax-auth-local ` . The routes stay in Caddy when dev stops; Syntax Auth's ` README.md `
248+ shows how to undo every step.
249+
250+ On those names:
158251
159252- Send browsers to ` https://auth.syntax.test ` , for example
160253 ` https://auth.syntax.test/sign-in?return_to=<encoded app URL> ` . Local Syntax Auth accepts
0 commit comments