Skip to content

Migrate HTTPS certificates to ~/.studio/certificates - #2871

Merged
fredrikekelund merged 44 commits into
trunkfrom
stu-1350-decoupled-config-dev-v4
Mar 23, 2026
Merged

Migrate HTTPS certificates to ~/.studio/certificates#2871
fredrikekelund merged 44 commits into
trunkfrom
stu-1350-decoupled-config-dev-v4

Conversation

@fredrikekelund

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Not at all.

Proposed Changes

Testing Instructions

  1. Have at least one site with HTTPS configured (do this before checking out this branch)
  2. Check out this branch
  3. npm start
  4. ls ~/.studio/certificates
  5. Ensure that the new certificates directory exists
  6. Ensure that the HTTPS site you had since before still works

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
bcotrim and others added 30 commits March 11, 2026 16:29
* STU-1350: Read site data from CLI instead of appdata

Studio now reads site data via `site list --format json` at startup
and maintains state through CLI events subscriber. Removes direct
appdata reads for site details, simplifies SiteServer create/start
flows, and removes waitForSiteEvent synchronization.

* Fix lint: indentation in index.test.ts

* Fix typecheck: narrow SiteDetails union before accessing url

* Remove dead url branch in SiteServer.create — events subscriber handles it

* Address PR review feedback: shared schemas, keyValuePair output, simplify start/delete
* STU-1350: Read site data from CLI instead of appdata

Studio now reads site data via `site list --format json` at startup
and maintains state through CLI events subscriber. Removes direct
appdata reads for site details, simplifies SiteServer create/start
flows, and removes waitForSiteEvent synchronization.

* Fix lint: indentation in index.test.ts

* STU-1350: Move CLI site data to dedicated cli.json config file

Split site data from appdata-v1.json into a new CLI-owned config at ~/.studio/cli.json.
Studio now reads sites exclusively via `studio site list` and _events. The CLI is the
source of truth for site configuration. Auth tokens, snapshots, locale remain in appdata.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* Fix delete test after trunk merge: use saveCliConfig instead of saveAppdata

* Extend require-lock-before-save eslint rule to support cli-config lock/save pairs

* Use shared lockfile constants and extract DEFAULT_CLI_CONFIG

* Fix typecheck: narrow SiteDetails union before accessing url

* Remove dead url branch in SiteServer.create — events subscriber handles it

* Fix lint: remove extra blank line in cli-config.ts

* triggert ci

* Update e2e tests to read site data from cli.json

* Address PR review feedback for cli-config

- Use structuredClone for DEFAULT_CLI_CONFIG deep copy
- Rename daemon-paths.ts to paths.ts, extract STUDIO_CLI_HOME
- Split config schema for version mismatch detection
- Improve readCliConfig error handling with version check
- Rename removeSite to removeSiteFromConfig
- Revert UPDATED event handler to warn for unknown sites

* Fix AI files to import site functions from cli-config instead of appdata

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
* Apply decoupled config strategy to preview sites (STU-1350)

- CLI stores/reads preview site data from cli.json instead of appdata
- Studio reads preview sites via CLI commands (preview list --format json)
- Added preview set command for updating snapshot settings (--name)
- Added --name option to preview create command
- Moved refreshSnapshots to store initialization with test guard
- Fixed snapshot-slice test mock setup to avoid module-load timing issues

* Emit snapshot events to Studio via _events for realtime updates

* Move snapshot name generation from cli-config to preview create command

* Split cli-config.ts into folder structure (core, sites, snapshots)

* Rename site-events to cli-events and enrich snapshot events with inline data (STU-1350)

* Fix snapshot update infinite loop and preview set error handling

* Unify CLI event emitter, share event schemas in cli-events, and clean up daemon-client (STU-1350)

* trigger ci

* Fix import order lint errors in core.ts and site-server.ts

* Address PR review: add stdout json output, addSnapshot action, reusable usage count helper, fix listener state bug

* Remove barrel file, replace z.nativeEnum with z.enum, update imports to direct paths

* Fix import order in cli-events.ts and remove unused test imports
* Wire auth and locale to shared.json, AI settings to cli.json

Move auth token reads/writes from appdata to shared-config for Desktop+CLI. Move locale reads/writes to shared-config (Desktop saves, CLI reads). Move aiProvider and anthropicApiKey from shared-config to cli-config (CLI-only). Remove auth and locale fields from appdata schema and types since they're now in separate files. Update all imports and tests accordingly.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* Move CLI telemetry stats from appdata to cli-config

* Fix import order lint errors

* Remove CLI appdata dependency and move infrastructure paths to ~/.studio

* Revert server-files and certificate paths to appdata directory

* Watch shared config for auth changes from CLI

* Align shared config watcher with user-data watcher pattern

* trigger ci

* Address PR review feedback: events-based auth, rename types, deduplicate schemas

* Fix prettier formatting in auth test

* Fix shared-config mock in tests to export authTokenSchema

* Use z.literal for config version validation, remove unused re-export, update test mocks

* Extract authTokenSchema to avoid Node.js imports in renderer bundle

* trigger ci

* Fix daemon test to use os.tmpdir() for Windows compatibility

* Make CLI event emission best-effort in auth commands

* Throw on shared config version mismatch instead of silently returning defaults

* Add line break before version mismatch error message

* Handle version mismatch errors through standard Logger flow in auth commands

* Show only display name in AI chat status bar

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
…nto stu-1350-decoupled-config-dev-v3

# Conflicts:
#	apps/cli/lib/appdata.ts
#	apps/cli/lib/tests/appdata.test.ts
@fredrikekelund
fredrikekelund requested review from a team and bcotrim March 23, 2026 10:19
@fredrikekelund fredrikekelund self-assigned this Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/storage/paths is already mocked globally in apps/studio/vitest.setup.ts

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM and nice cleanup on tests!

Something I would like to discuss before we land, would it make sense to run this from the CLI migrations instead?
Since it migration copies the cert from the Studio folder to the CLI folder, it seems to make sense to have it run from the CLI. What do you think?

@fredrikekelund

Copy link
Copy Markdown
Contributor Author

would it make sense to run this from the CLI migrations instead

Same as with the config file migration, the place where we need a guarantee that the code works with the current file structure is primarily the app, not the CLI.

I also think it's sensible for the old owner (the Studio app) to execute the move to the new owner (the CLI).

migration copies the cert from the Studio folder to the CLI folder

~/.studio/certificates is not 100% under CLI management, as I see it. Yes, we're moving towards an architecture where the CLI acts as a back-end API, and it will probably be the only component that touches that directory. Still, the first difference between the old location and this one is that it's "well-known" (fully deterministic).

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it in Studio then.
LGTM 👍

Base automatically changed from stu-1350-decoupled-config-dev-v3 to stu-1350-decoupled-config-dev March 23, 2026 15:14
Base automatically changed from stu-1350-decoupled-config-dev to trunk March 23, 2026 17:52
@fredrikekelund
fredrikekelund enabled auto-merge (squash) March 23, 2026 19:36
@wpmobilebot

wpmobilebot commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 462a336 vs trunk

app-size

Metric trunk 462a336 Diff Change
App Size (Mac) 1237.57 MB 1237.57 MB 0.00 MB ⚪ 0.0%

site-editor

Metric trunk 462a336 Diff Change
load 2032 ms 1874 ms 158 ms 🟢 -7.8%

site-startup

Metric trunk 462a336 Diff Change
siteCreation 7079 ms 7076 ms 3 ms ⚪ 0.0%
siteStartup 3935 ms 3937 ms +2 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@fredrikekelund
fredrikekelund merged commit 9290f01 into trunk Mar 23, 2026
8 of 10 checks passed
@fredrikekelund
fredrikekelund deleted the stu-1350-decoupled-config-dev-v4 branch March 23, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants