Add aisw save command#6
Conversation
When claude login is run outside of aisw — for example after an interrupted aisw add — the live credentials in ~/.claude belong to no aisw-managed profile. aisw save captures those credentials and stores them as a named profile without re-running the login flow. The command reuses the same snapshot, identity deduplication, and credential storage logic as add, and follows the same run/run_in split for testability. Only claude is supported for now, matching the constraint that other tools do not have the same live-file capture path.
aisw save was Claude-only. Codex and Gemini expose the same manual-login scenario (codex login, gemini login run outside aisw), so the same save pattern applies: read live credentials from each tool's config directory and store them as a new aisw-managed profile without launching any login flow. Codex reads ~/.codex/auth.json and writes config.toml to force file-backed auth, matching the import path in aisw init. Gemini reads OAuth files from ~/.gemini/ or a .env API key, also matching init. Both branches deduplicate against existing profiles using the same identity helpers as add and init. Adds 6 new tests (create + config-registration + no-credentials error for each tool). All 369 tests pass.
Remove the "claude only" note and table, document the live credential source for each of the three tools, and add codex/gemini examples.
Previously save only applied credentials to the live config when --set-active was passed. This meant aisw status still showed the old profile as active after saving, which was confusing. Now save always applies the saved credentials to the live tool config and marks the profile as active, so status is immediately consistent. --set-active is replaced by --yes (used for overwrite confirmation).
|
Thanks for pushing this. I think the direction is right, and I want to confirm the problem statement as I understand it: this is primarily a recovery/adoption flow for cases where Given that goal, I think this fits better as Adding a new top-level command here has a few downsides: it increases CLI surface area and docs/completion overhead, creates semantic overlap with So overall: directionally right problem to solve, and I’d recommend we solve it via I would really love to merge this before the new version release this week, if you can reshape the PR in this direction. (or clean new PR) |
|
Closing in favor of #7, which reshapes this as |
Problem
aisw addruns a full interactive login flow. When it fails or is interrupted, the nativeclaude login(orcodex login,gemini login) is always available as a fallback — but there was no way to hand those credentials over to aisw afterward.Beyond
aisw init(which imports live credentials during first-run onboarding), there was no way to capture live credentials that are already working and store them as a named aisw profile at any point after setup.Solution
aisw save <tool> <profile_name>captures whatever credentials the tool currently has live and stores them as a new aisw-managed profile — no login flow launched.After saving, the profile is immediately activated and applied to the live tool config, so
aisw statusis consistent right away. If the profile name already exists, aisw prompts for confirmation before overwriting (or accepts--yesto skip the prompt).Scope
Supports all three tools, reading from each tool's live config location:
claude~/.claude/.credentials.jsonor system keyring (macOS)codex~/.codex/auth.jsongemini~/.gemini/.env(API key) or OAuth files in~/.gemini/aisw saveis essentiallyaisw initbut targeted — it runs the same import logic already present ininit(live_credentials_snapshot_for_import,copy_live_oauth_files_into_profile, etc.) and the same deduplication identity helpers used byaisw add, but lets you choose exactly which tool and profile name to save to without going through the full interactive onboarding flow.Changes
src/commands/save.rs— new command, ~370 lines including 10 testssrc/cli.rs—SaveArgsstruct andSavevariant inCommandsrc/commands/mod.rs— dispatch wired updocs/commands.md—aisw savesectioncompletions/— regenerated frombuild.rsAll 369 existing tests pass. New tests cover profile creation, config registration, active profile state, overwrite with
--yes, and the no-credentials error path for each tool.