Skip to content

feat(dev): pnpm dev hands the developer's Clerk keys to the server - #126

Merged
allisonmahmood merged 2 commits into
mainfrom
t3code/add-clerk-authentication
Sep 2, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
t3code/add-clerk-authentication

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

The auth build needs the Clerk development keys inside the server that pnpm dev runs, but the runner's server env is closed on purpose, so there was nowhere outside the repo to put them.

The supervisor now reads CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY from $XDG_CONFIG_HOME/patchy-cloud/dev.env (one file per developer, shared by every worktree) through Effect's dotenv ConfigProvider, forwards only those two names to the server, and names the loaded keys in dev.log. clerk env pull --app … --file writes that file. Documented in docs/DEVELOPMENT.md and the patchy-dev-loop skill, with one test on the reader.

Resolves the Clerk application task on the auth map (#118).

Made by Claude Fable 5.1 in Claude Code.

The dev runner's server env is closed on purpose, so there was nowhere
outside the repo to put the Clerk development keys that pnpm dev would
read. The supervisor now loads ~/.config/patchy-cloud/dev.env (one file
per developer, every worktree, XDG honoured) under the plan's own values
and names the loaded keys in dev.log. clerk env pull --file writes it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines labels Sep 2, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Fable review

Reviewed against origin/main (merge-base is the main tip, so this is rebased) with #118's resolution as the spec. Lint, @patchy/dev typecheck and the new test pass locally; CI is green apart from cli-smoke, still pending at review time.

Intent matches the resolution: one file per developer at $XDG_CONFIG_HOME/patchy-cloud/dev.env, loaded under the plan's values, keys named in dev.log, docs and skill updated. The real file on disk is two unquoted KEY=value lines, which parseEnv handles. The supervisor is spawned with extendEnv: true, so HOME and XDG_CONFIG_HOME do reach it. The server does not read CLERK_* yet; that is #119's job, as the issue says.

Blocking

The patchy-dev-loop skill's refresh command fails as written (.agents/skills/patchy-dev-loop/SKILL.md:24):

clerk env pull --file ~/.config/patchy-cloud/dev.env

#118 decided the worktree is deliberately not clerk linked and that "every command takes --app". Run from an unlinked directory, clerk env pull --file ... answers {"error":{"code":"not_linked", ...}} and writes nothing (verified with clerk 3.3.0). This skill is the surface an agent runs verbatim when it sees developer env: none in the log, so the one command it gives must work. docs/DEVELOPMENT.md:82 has --app <app id>, but nothing in the repo says what the id is, so the placeholder sends the developer back to the issue comment.

Fix: put --app app_3ImZuFeZJb8038U0oFds84rupA2 in both places (the app id is an identifier like the frontend API host, not a secret; the keys stay in the file). This is the "Hit every surface — the dev loop" entry from AGENTS.md: the runner change landed, the skill mirror is wrong.

Non-blocking

  • Effect 4 ships ConfigProvider.fromDotEnvContents (dotenv's own algorithm: export prefix, escapes, multiline). It only yields a ConfigProvider, and turning that back into a spreadable record means load([]) for the key set then one load per key, so the hand parser is not worse today. If dev.env ever needs more than what clerk env pull writes, switch to Effect's parser rather than growing parseEnv.
  • developerEnv.test.ts:29 is named "is empty when the developer has written no file" but asserts the written case too; rename or split so a failure reads right.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review

Request changes — two merge blockers.

Intent

  • .agents/skills/patchy-dev-loop/SKILL.md:24 does not give agents a working key-refresh command. Issue Create the Clerk application and hand its development keys to the dev loop #118 records that this deliberately unlinked worktree requires --app on every Clerk command, but the skill omits it. Both the skill and docs/DEVELOPMENT.md:82 also write to ~/.config/... even though the implementation reads $XDG_CONFIG_HOME/...; with a non-default XDG config home, the documented command writes a file the runner will never load. Use the actual non-secret app id from Create the Clerk application and hand its development keys to the dev loop #118 and the same resolved config path in both instructions, e.g. clerk env pull --app app_3ImZuFeZJb8038U0oFds84rupA2 --file "${XDG_CONFIG_HOME:-$HOME/.config}/patchy-cloud/dev.env".

Method / YAGNI

  • scripts/dev/src/developerEnv.ts:27-39 and scripts/dev/src/supervisor.ts:164-180 turn the two Clerk keys requested by Create the Clerk application and hand its development keys to the dev loop #118 into a generic dotenv subsystem that forwards every file entry into the server. That weakens the runner's deliberately closed environment, makes “anything the server needs” a new configuration contract, and adds a partial hand-written dotenv parser for an unasked future. Keep this change to CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY; use Node 22's built-in util.parseEnv to read them, and remove the generic parser/contract.

…ovider

Review on the PR: the runner's server env is closed on purpose, so the
file should not become a generic passthrough, and the hand-written
dotenv parser duplicated ConfigProvider.fromDotEnvContents. The
supervisor now asks the file for CLERK_PUBLISHABLE_KEY and
CLERK_SECRET_KEY only. The docs' refresh command gained the app id
(the worktree is deliberately not clerk-linked) and the XDG path the
runner actually reads.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed

Commit d4b39e2 answers both reviews.

Fixed

  • Refresh command in the skill and docs (Fable, Sol): both now carry --app app_3ImZuFeZJb8038U0oFds84rupA2, since the worktree is deliberately not clerk linked and the CLI answers not_linked without it. The app id is an identifier, not a secret; the keys stay in the file.
  • Documented path versus the path the runner reads (Sol): the command writes to "${XDG_CONFIG_HOME:-$HOME/.config}/patchy-cloud/dev.env", the same resolution the supervisor uses, and both docs say the ~/.config form is the default rather than the rule.
  • Generic dotenv passthrough (Sol): gone. The supervisor asks the file for CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY by name and forwards only those, so the closed env stays closed; the docs no longer describe an "anything the server needs" contract. Verified live: the server process's environment holds exactly the plan's variables plus those two.
  • Hand-written parser (Sol, Fable's note): replaced by ConfigProvider.fromDotEnvContents from Effect 4, loaded per key, so the parser is Effect's, not ours. Its test is one case that asserts exactly what its name says, which also covers Fable's naming note.

Kept as is

  • util.parseEnv from Node (Sol suggested it): not used, because Effect ships the same dotenv algorithm as a ConfigProvider and the repo's guardrails prefer the Effect equivalent when one exists. Same outcome, no Node-API exemption needed.

Lint, typecheck and the runner's tests pass; CI is running on the new commit.

@allisonmahmood
allisonmahmood merged commit 26c7adc into main Sep 2, 2026
6 checks passed
@allisonmahmood
allisonmahmood deleted the t3code/add-clerk-authentication branch September 2, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant