feat(cli): environment spike#381
Conversation
Redefine the dev root as the null-parent instance so a named `main` root and its forks classify correctly (ADR-0003/0010): - isPrimaryInstance tests parent_instance_id only; scope the guardless development finders in deploy/status, autolink, and link to the null-parent root so a fork is never mistaken for the root. - Collapse target resolution to one chain (ADR-0011): explicit --instance/--branch, else the worktree active pointer, else the development root. Remove the forced >1-instance disambiguation prompt from the users instance context. - clerk open joins the chain: it honors the pointer, accepts --instance and --branch, and labels via the resolved instance label instead of always opening the dev root. - Reject a branch name (including `main`) passed to the environment lens --instance with a `use --branch <name>` hint (ADR-0002); register --branch in shell completion so its value returns NO_FILE rather than filenames. - ActiveEntry gains an additive branch_name field, written on switch, so status can report the branch without a second fetch (ADR-0008). Update affected fixtures/tests to the new model (forks carry parent_instance_id; no forced picker).
- branch list becomes a pure branch view (ADR-0005): `main` (the null-parent
branch) is pinned at the top with its forks nested as a box-drawing tree, and
production is removed from both human and JSON output.
- Restructure branch list --json from {trunks, branches} to a single `branches`
list: `main` first (parent_instance_id null), forks carrying their parent, plus
active_instance_id/active_instance_missing. No default flag; `main` is the
null-parent branch.
- switch no-arg picker becomes the two-stage selector (ADR-0006): stage 1 picks
the environment (Development/Production), stage 2 picks the branch (`main` +
forks). Any single-option stage is skipped: no production skips stage 1, a lone
`main` skips stage 2, and production never reaches stage 2. Positional/flag args
bypass the stages.
Rework the shared branch-tree model (developmentBranches/buildBranchTable) to the
pinned-main-plus-forks shape shared by both surfaces, and update the branch list
and shared unit tests to the new model.
Change instanceLabel from `branch_name || environment_type` to the env-qualified glyph form `<environment> ⎇ <branch>` (else `<environment>`), living in lib/config so lib-layer resolvers share it (ADR-0007). A nameless dev root renders `development`, the named root `development ⎇ main`, a fork `development ⎇ feature`, production `production`. Fan out the glyph: - resolveAppContext instance labels feed the ` · on <label>` command suffixes, env pull echoes, switch outros, and BAPI error hints (all read ctx.instanceLabel). - switch writes the glyph label to the pointer; fork messages use the bare parent name (`Forking main → <name>`); branch delete's active-branch hint points at `clerk switch main`. - status: active label uses the glyph form, the annotation is slimmed to just `(default branch)` for main (forks/production get none), and status --json gains an additive branch_name. - apps list ENVIRONMENTS is deduped to unique environment_types (never branch names); the users picker (buildInstancePickerChoices) adopts the glyph label. - The two-stage switch branch picker keeps bare branch names (the environment is chosen in stage 1). Rewrite the branch and status README/help text off the old `trunk` terminology.
Add self-serve branching activation and gate the fork commands (ADR-0013/0015):
- `clerk enable branches` / `clerk disable branches` join the verb-first
enable/disable (toggles) family, calling the Platform
`PATCH /v1/platform/applications/{appId}/branch_settings` route with
`{enabled}`. Enabling names the dev root main (server-side); disabling is
refused server-side while forks exist. There is deliberately no
`clerk branch enable` subcommand.
- Passive gate: `clerk branch create` and `clerk switch --create` read the
serialized app-level `branches_available` / `branches_enabled` and refuse to
fork with a hint — `clerk enable branches` when available-but-not-enabled, a
not-available message otherwise — identically in interactive and
non-interactive shells. Switching to an existing instance is never gated.
- plapi: add the `branches_available` / `branches_enabled` fields to the
Application payload and the `updateBranchSettings` route helper.
branch create now forks from the named `main` and reports it with the bare parent
name. Update fixtures/mocks to carry the enablement state.
- Delete buildInstancePickerChoices and its test: the users interactive instance picker was removed with the forced-disambiguation prompt (ADR-0011), leaving this helper with no runtime caller. Dead-code removal, not a lost feature. - Surface the branch gate error codes distinctly: development_branches_not_available, development_branches_not_enabled, and cannot_disable_branches_with_live_forks carry their actionable detail (the enable hint, the live-fork count) in long_message rather than meta, so formatStructuredError now appends it beneath the headline for these codes.
`clerk branch create --name <n> --switch` (`-s`) forks the branch and then activates it for the current worktree in one step. It delegates to branchSwitch so the pointer update, .env sync, and output stay identical to `clerk switch <branch>`. In agent mode branchSwitch emits the lone "switched" JSON object and the human-facing "Forked" line is suppressed.
Refresh the branching-only changeset so the summary covers the cumulative branch featureset: create with --switch, list/delete/switch management, the enable/disable branch gate, and --branch targeting. Bump stays minor.
`clerk branch create` with no arguments now runs interactively in human mode: it prompts for the branch name via Clack and then offers to switch the worktree to the new branch. `--name` becomes optional, and the branching-enabled gate is checked before prompting so the user is never asked for a name we cannot use. Agent mode cannot be prompted, so it fails fast with a usage error directing the caller to pass --name. Refreshes the branching changeset to describe the interactive flow.
Add branchNameError/assertValidBranchName in the branch command's shared module, mirroring clerk_go's ValidateBranchName + IsReservedBranchName and the dashboard. `clerk branch create` validates --name up front (all modes) and enforces the same rules in its interactive prompt; `clerk switch --create` validates its name before the fork round-trip. Malformed or reserved names fail with a usage error listing the allowed characters. Refreshes the branching changeset.
🦋 Changeset detectedLatest commit: 7acacd0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Stack: branching-only
Part of a stacked-prs chain. Do not merge manually. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (94)
Disabled knowledge base sources:
📝 WalkthroughWalkthroughThis PR adds development-instance branching to the Clerk CLI. It introduces Estimated code review effort: 5 (Critical) | ~150 minutes Suggested reviewers: ✨ Finishing Touches⚔️ Resolve merge conflicts
Comment |
No description provided.