CS-10615: Reimplement boxel profile command#4354
Conversation
Port profile management from standalone boxel-cli into monorepo. Adds ProfileManager class for CRUD operations on ~/.boxel-cli/profiles.json with subcommands: list, add, switch, remove, migrate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d9086f986
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Review: CS-10615 — Reimplement boxel profile command
Overall: Solid foundation for profile management. This is the right first step toward CS-10642's full auth lifecycle.
Key concerns (8 inline comments):
-
Realm server URL inference from matrix URL —
getActiveCredentials()guessesrealmServerUrlfrommatrixUrlhostname patterns when env vars are used. This is fragile and inconsistent withmigrateFromEnv()which correctly requiresREALM_SERVER_URLexplicitly. Recommend removing the inference. -
Duplicate helper functions —
getEnvironmentLabelandgetEnvironmentShortLabelare identical implementations. -
Singleton
configDirconfusion —getProfileManager(configDir?)caches the first instance and silently ignoresconfigDiron subsequent calls. -
migrateFromEnvno-op on existing profiles — Silently returns without updating credentials if profile already exists. -
Terminal cleanup in
promptPassword— Raw mode may not be restored on unexpected errors. -
Duplicated ANSI constants — Same color codes defined in both
profile.tsandprofile-manager.ts. -
I would like to see a happy path test against a real realm server. consider leveraging testing infra from the packages/realm-server/tests so that we can spin up a real realm server that we can test against and assert that auth works against an actual realm server.
Phase 2 alignment (CS-10642): The Profile interface and async method signatures are well-positioned for extension with server tokens, per-realm JWTs, and auto-refresh. The getActiveCredentials() method is the natural evolution point for the programmatic BoxelAuth API. Inline comment on the interface details what fields will be needed.
There was a problem hiding this comment.
Pull request overview
Ports the boxel profile command into the monorepo’s @cardstack/boxel-cli, adding a local profile storage layer and CLI UX to manage Matrix/realm credentials across environments.
Changes:
- Added
ProfileManager+ helper utilities for reading/writing~/.boxel-cli/profiles.jsonwith restrictive permissions. - Implemented
boxel profilesubcommands (list/add/switch/remove/migrate) including interactive prompting. - Added unit tests for ProfileManager behavior and environment parsing helpers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/boxel-cli/src/lib/profile-manager.ts | Implements profile config persistence, credential selection, and migration from env vars. |
| packages/boxel-cli/src/commands/profile.ts | Adds CLI subcommand routing + interactive/non-interactive profile workflows. |
| packages/boxel-cli/src/index.ts | Wires the new profile command into the CLI entrypoint and loads dotenv. |
| packages/boxel-cli/tests/commands/profile.test.ts | Adds unit tests covering ProfileManager operations and helper functions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Extract shared ANSI color constants to src/lib/colors.ts - Remove duplicate getEnvironmentShortLabel (keep getEnvironmentLabel) - Remove fragile realmServerUrl inference from matrixUrl hostname pattern - Return distinct result from migrateFromEnv for new vs existing profiles - Update existing profile password on re-migration - Add REALM_SERVER_URL to migrate command precheck - Remove configDir param from singleton getProfileManager() - Fix promptPassword raw mode cleanup with try/finally pattern - Reject unknown domains in addProfile without explicit URLs - Validate JSON shape in loadConfig() - Skip Windows-incompatible file permission test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wrap setup code in try/catch so raw mode is restored if anything throws between setRawMode(true) and the data handler. Pair stdin.resume() with stdin.pause() on cleanup to restore original flow state. Use reject() instead of throw for proper promise error propagation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@FadhlanR you still did not address my point about having a test against a real realm server |
|
it sounds like @jurgenwerk is working on this. can you merge his branch into this once he gets to a good place and then include those tests? |
|
Yeah #4368 should have the test helpers for spinning up a realm server so that the CLI can test against it. The mentioned PR is not finished yet but you can check and see if you can make it work in this branch. That part should already be functional as I am seeing my tests pass in the CI |
|
Currently the I think we can merge this PR as-is so we can unblock other boxel CLI command PRs, including Matic's PR that introduces authentication against the realm server. We will change the auth behavior in CS-10642, the happy path test against a real realm server would fit naturally there, when the profile command evolves to manage tokens. What do you think @habdelra? |
|
that seems fair. we can tackle dealing with tokens in CS-10642 |
Summary
boxel profilecommand from standalone boxel-cli into monorepo atpackages/boxel-cliProfileManagerclass for CRUD operations on~/.boxel-cli/profiles.json(0600 perms)list,add(interactive wizard),switch(partial match),remove,migrate(from .env)Test plan
pnpm --filter @cardstack/boxel-cli test— 24 tests passpnpm --filter @cardstack/boxel-cli build— builds successfullypnpm --filter @cardstack/boxel-cli lint— no errors🤖 Generated with Claude Code