Repository navigation
cloudpin switch: plan, confirm once, run, re-check (#14) - #102
Merged
Merged
Conversation
Owner-approved decisions of 2026-10-18: agents are asked through the hook, missing logins are skipped while the rest run, --json, AWS_PROFILE through a wrapper side file, choose-or-skip for ambiguous matches, Supabase and Wrangler stay manual, kube namespace preference. CLI facts checked against each CLI's docs, help and source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lists the profiles in the AWS config file and the account each names, from sso_account_id or the account field of role_arn only. Every other value is dropped while reading; the credentials file is never read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runCheck can fill a map with guard's trace per provider, so cloudpin switch plans from the same resolution check used. The kubeconfig loader, server normalising and the Vercel team listing are exported for reuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For each pinned provider not on its pin, plan the commands to run (az account set, gh auth switch, vercel teams switch, gcloud config set, kubectl use-context and set-context), a choice between several targets, or a manual line naming the exact command or variable: logins, env-var overrides, supabase link and the Wrangler config. AWS reads profiles from the config file offline. Names with characters outside the allowed set are quoted in a manual line and never run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shows the plan for every pinned provider, picks between several candidates by number in a terminal, asks once, runs each command without a shell (a failing command does not stop the others; a kube namespace step is skipped when its use-context failed), writes AWS_PROFILE to CLOUDPIN_ENV_FILE for the shell function, then re-checks. Exits 0 only when every pinned, installed CLI matches. --json prints the plan, the commands run with their exit codes, and the check report after, and never prompts; without --yes it runs nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like cloudpin use <env>: agents that can ask (Claude Code, Copilot, Cursor, Antigravity's force_ask) ask the user, naming the pins it would switch to, read from the pin file without running a CLI; Codex and Gemini CLI deny and tell the agent to ask the human to run it. --yes does not change the decision; cloudpin switch --help is not asked about. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a mismatch the fix reads "<provider's switch hint> (or run cloudpin switch)", in the block message and in check. Not for Supabase and Wrangler, where switch only says what to do by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For cloudpin switch only, the function passes a temporary side file in
CLOUDPIN_ENV_FILE, then applies just AWS_PROFILE=<name> lines whose name
is [A-Za-z0-9._-]{1,64} and unsets AWS_DEFAULT_PROFILE. No eval or
Invoke-Expression; the file is deleted and cloudpin's exit code kept.
Every other subcommand passes straight through. The guarded functions
now look for the cloudpin executable with type -P (bash) or whence -p
(zsh), which a cloudpin function can't satisfy after an uninstall.
CLOUDPIN_ENV_FILE joins the variables an agent's line can't set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README and SECURITY.md no longer say cloudpin never switches accounts: it switches only when you run cloudpin switch and confirm, and an agent's attempt asks you first. Both note the AWS config read (profile names, sso_account_id and role_arn only; never the credentials file). README gains the command, the shell function and the exit code; DESIGN gains the edge case and a Decisions row; CHANGELOG lists it under Unreleased; AGENTS lists the new files; the plugin skill may suggest it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
botocore keeps the second word of any "profile..." header that splits into two words, without checking the first (configloader.py _parse_section); do the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After unwrapping `cloudpin exec`, an inner `cloudpin switch` or `cloudpin use` went to guard, which ignores cloudpin, so the agent got no objection. The hook now keeps unwrapping while the command is cloudpin and applies the same confirmation at each level. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hook built the cloudpin switch summary with the agent environment, which drops user-only variables, while the real run honours them: with CLOUDPIN_ENV=production on the line it named the staging pins. The summary now uses the environment the command will have, and the command shown to the human includes the line's user-only assignments. Guard's treatment of them for agents is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With AWS_PROFILE and AWS_DEFAULT_PROFILE unset the AWS CLI uses [default], but the plan treated no profile as in use, so a logged-out [default] naming the pinned account planned AWS_PROFILE=default, which changes nothing. It now gets the log-in line, as any other active profile does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README, SECURITY.md and DESIGN.md said cloudpin switches only when you run cloudpin switch and confirm, but --yes skips the prompt. They now say it shows the plan and asks first unless you pass --yes, and that an agent's attempt asks the human through its hook. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Real end-to-end run on the maintainer's Vercel login (owner's explicit yes), built from bed5e28:
|
Brings main (1.2.0, 1.2.1, and everything since) into the switch branch. Every conflicted file takes main's side: AGENTS.md, CHANGELOG.md, README.md, SECURITY.md, src/guard.ts, src/hooks/agents.ts, src/providers/kubernetes.ts, src/shellwords.ts. The switch behaviour those files carried is ported back on top in the commits that follow, so this merge alone does not pass tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge took main's src/providers/kubernetes.ts; switch-plan.ts reads the kubeconfig through these three names, so they are exported again. Loaded stays private: its one consumer only destructures the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
USER_ONLY_VARS moved to src/user-env.ts on main, so the switch side file's variable goes there. A command line can't set it for an agent's guard check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Except for Supabase and Wrangler, where switch only says what to do by hand. The hunk is on main's guard: the fix comes after the #165 unread-field check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The file is at the 5,000-token cap and the next commit adds to it. Only the type moves; shellwords.ts re-exports it, so no caller changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st one (#14) `cloudpin exec -- bash -c '...'` and `cloudpin exec -- npx ...` reached guard as an unguarded `bash` or `npx`, so the call inside was never checked. The switch PR's loop in the hook only saw a directly nested `cloudpin`. Since exec starts its command without a shell, findInvocations now reads those words as a call of their own, so the hook and explain see the wrapped CLI whatever is around it. This also closes the same gap on main for a wrapped az or gh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ads (#14) The port of the switch PR's hook hunks, onto main's newer parsing: an agent's `cloudpin switch` asks the human (deny where the hook can't ask), `--yes` or not. The question names the pins, read with the line's own variables, with names folded on Windows (#136) and flags masked (#134). Beyond the straight port: - A cloudpin call whose first word is only known when the line runs may be `switch`, so it asks too, rather than passing as "not cloudpin use". - `npm exec cloudpin -- switch` runs `cloudpin switch` (npm drops the `--`), so a leading `--` is skipped. - Help is only the first word after `switch`, in the command and the hook alike (#146); anywhere else it is an unknown argument and nothing runs. - The exec loop is gone: findInvocations already reads what exec starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/switch-plan.ts was over the 5,000-token cap and has more to take. It keeps the plan's shape and planProvider; the planners that ask a CLI move to src/switch-planners.ts, and the two that read a config file (kubectl, AWS) to src/switch-plan-files.ts. No behaviour changes; its test file is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…runs nothing (#14) The plan read GH_TOKEN, CLOUDSDK_CORE_PROJECT, AWS_CONFIG_FILE and the rest in one spelling. On Windows a name has no case and guard already folds it (#119, #136), so a lowercase gh_token was seen by gh but missed by the plan, which then ran a switch gh refuses. The environment is folded once, on the way in, and everything after it (the check, the planners, the commands, the re-check, the side file) sees those names. The plan is now its own function, planSwitch, so it can be called without running anything: the later MCP tool (#112 part 2) needs exactly that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The masking itself landed in the previous commit by accident (a scripted split stopped before removing that hunk); this is its test. A CLI's stderr is the one thing switch prints in words it didn't write, so its first line goes through maskArgv like every other message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- gcloud: with impersonation on (#165) the identity is the service account, so `config set account` would change nothing; the line says what to clear instead. - Vercel: a scope in the local config beats the active team (#127), so a team switch would change nothing; the line says so instead of running one. - helm: HELM_KUBEAPISERVER and HELM_NAMESPACE decide its target too (#133), beside the HELM_KUBECONTEXT the design named, and use-context doesn't change them. Tests also pin what stayed true: Wrangler's manual line still beats CLOUDFLARE_ACCOUNT_ID and CF_ACCOUNT_ID (#103, #119), it gives an auth profile's login, the block message doesn't send anyone to switch for it, and --only accepts every current provider. No planner reads a flag, so targetFlags is untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…MAP (#14) README and SECURITY keep main's wording plus the corrections that cloudpin no longer "never switches accounts" and now reads the AWS config file's profile names, sso_account_id and role_arn. The CHANGELOG entry moves under Unreleased. ROADMAP marks the 1.3.0 line done. AGENTS.md lists the new source files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They reported "no command here that cloudpin guards" for cloudpin switch and cloudpin use <env>, which the hook asks about. The MCP skill tells an agent to run a command only on "allow", so the answer has to match the hook's. It uses the hook's own function, so they can't drift. In a terminal the command asks by itself, so nothing changes there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cursor runs the hook only on lines its matcher finds, and the matcher was lowercase, so CLOUDPIN.CMD switch (or AZ.CMD on a guarded command) never reached the hook on Windows, where the shell runs it all the same. Reinstalling the hook already moves an older matcher to the current one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14
cloudpin switch [--yes] [--json] [--only <clouds>]: shows a plan for each pinned CLI that is not on its pinned account, asks once, runs the switch commands (argv, no shell), then re-checks. Design and sources:docs/superpowers/specs/2026-10-18-switch-design.md(owner decisions of 2026-10-18).What it does
account set --subscription <GUID>, ghauth switch --hostname --user, vercelteams switch <slug>(team ID mapped to slug), gcloudconfig set ... --quiet(with--configuration), kubectlconfig use-context(+ namespace viaset-context --currentwhen no context matches both).sso_account_id,role_arnonly; the credentials file is never read). The newcloudpinshell function appliesAWS_PROFILEfrom a side file (CLOUDPIN_ENV_FILE, strict charset, no eval).GH_TOKEN,CLOUDSDK_CORE_PROJECT,HELM_KUBECONTEXT, ...), Supabase and Wrangler are manual lines; the rest still run.cloudpin exec -- cloudpin switch;--yesnever changes that. MCP stays read-only.Evidence
switch --jsonwithout--yes, so nothing ran), in a temp folder pinned bycloudpin init: right pins allok(exit 0); fake IDs allmanualwith the login hint (exit 1); a real but inactive Vercel team and Azure subscription each planned arunline (vercel teams switch <slug>,az account set --subscription <GUID>); active accounts unchanged afterwards. gcloud is unit-tested only (no test install on the dev machine).🤖 Generated with Claude Code
Ported onto main (2026-11-04)
The branch was too stale to merge (8 conflicted files), so main was merged taking main's side and the PR's intent was ported as new commits. Beyond a straight port:
cloudpin execis unwrapped in the parser, so what it starts is read as a call. This also fixes a gap on main: an agent'scloudpin exec -- bash -c 'gh ...'andcloudpin exec -- npx gh ...were allowed on the wrong account.cloudpin $x), since it may beswitchoruse. Side effect: an agent'seval "$(cloudpin shell-init bash)"asks too.npm exec cloudpin -- switchis read ascloudpin switch.--helpcounts only as the first word afterswitch, in the CLI and the hook alike.planSwitchplans without running anything, ready for MCP: cloudpin_switch_plan and cloudpin_doctor tools (read-only) #112 part 2. No MCP tool here.vercel.jsonscope,HELM_KUBEAPISERVERandHELM_NAMESPACE.explainand MCPcloudpin_checkreportaskfor an agent'scloudpin switchorcloudpin use <env>.CLOUDPIN.CMDandAZ.CMDreach the hook. Existing installs get it when the hook is reinstalled.Evidence for the port
npm run typecheckexit 0;npx vitest run: 85 files, 2629 passed, 19 skipped (before the last docs commit).--yes, masking, and the unknown subcommand.switch --json, no--yes, GitHub and Azure): right pinsok, exit 0; made-up pinsmanual, exit 1; nothing ran and the active accounts were unchanged.Not tested
No real switch has been run on the port (a real but inactive account's
runline is from the earlier evidence above). gcloud is unit-tested only. Left as they are: Cursor's matcher is a text prefilter, so a name not literally on the line ("cloud"pin,-EncodedCommand) never reaches the hook there, as for every guarded CLI on main;node path/to/dist/cli.js switchisn't detected, likecloudpin use.