Skip to content

feat(use): CLI-agent presets in aic use + provider vocabulary completion - #140

Merged
CaicoLeung merged 6 commits into
mainfrom
feat/use-cli-agents
Aug 15, 2026
Merged

feat(use): CLI-agent presets in aic use + provider vocabulary completion#140
CaicoLeung merged 6 commits into
mainfrom
feat/use-cli-agents

Conversation

@CaicoLeung

Copy link
Copy Markdown
Owner

What

Two related changes to aic use:

  1. Fix: shell completion offered nothing for aic use <TAB>. The provider positional was a plain String with no possible values, so clap_complete emitted a _default action that completes nothing (bell on TAB). Now driven by use_values() — a PossibleValuesParser built from the registry (single source of truth): every provider canonical name + alias.
  2. Feat: aic use <preset> switches to a CLI agent. claude, codex, pi, opencode (case-insensitive) write the preset's command/args/timeout_secs/encoding and flip backend_kind = "cli". Preset names win over colliding provider aliases: aic use claude is the claude code CLI agent — aic use anthropic is the API provider.

How

  • src/core/cli/mod.rsuse_values(): CLI presets first, then provider names/aliases, order-preserving dedupe so a preset-shadowed alias (claude) appears exactly once. ignore_case = true kept.
  • src/core/config/mod.rsapply_use gained the preset arm (checked before the provider path, mirrors clap's ignore_case); presets are stateless so switching just overwrites the CLI fields — the API row stays dormant-but-intact for a switch back (ADR 0011). run_use prints Switched to CLI agent <command>. and skips the API-key note on that arm.
  • Tests: preset switch pins backend flip + full claude spec + dormant API row; case-insensitive match; completion test pins the full use vocabulary.
  • README.md / README.zh-CN.md mirrored.

Verification

  • cargo test: 405 unit + 2 e2e passing; cargo fmt --all -- --check and cargo clippy --all-targets -- -D warnings clean.
  • Runtime smoke (isolated HOME): aic use claudebackend_kind = "cli" + full claude preset written, openai row intact; aic use ANTHROPIC → restores banked anthropic profile, backend_kind = "api"; aic use nonsense → rejected with the full vocabulary.
  • Completion verified interactively in a real zsh: aic use <TAB> offers the whole vocabulary (zpty harness + fresh interactive shell against the real fpath).

Known limitation

fish completion still lacks positional-arg values — upstream clap_complete fish generator limitation, unchanged by this PR.

Expose the provider's registry aliases so callers can enumerate all names accepted by from_name
Derive clap possible values from Provider::all() so `aic use` accepts only known names/aliases (case-insensitively) and shell completions expose the same vocabulary as Provider::from_name.
…tion

Assert that the zsh completion script offers every canonical provider name and alias for the `aic use` command, guarding against the reported missing-completion regression.
Let `aic use claude|codex|pi|opencode` switch the active backend to that CLI agent, reusing its own auth instead of requiring a setup profile. Preset names win over provider aliases and match case-insensitively; the dormant API row stays intact for switching back (ADR 0011).
Clarify that aic use switches between saved providers and CLI agents (claude, codex, pi, opencode) in both READMEs
- `aic use <preset>` now works on a machine with no config at all, honouring
  the documented "no setup needed" promise; provider switches still require
  an existing config (banked profiles come from `aic setup`).
- One ASCII folding rule (clap `ignore_case`, preset arm, provider registry)
  now governs the whole `aic use` vocabulary, so the accepted set cannot
  drift between clap and `apply_use`.
- `use_vocabulary()` is the single source for both clap possible values and
  the zsh completion test, which now asserts exact equality instead of
  re-deriving the assembly.
- `use_messages` pure core (cf. `list_lines`/`run_list`) pins the switch
  output contracts: agent line on the CLI arm, key-note only on a keyless
  provider arm.
- Truth up the cli_agent module docs: preset names ARE reserved words in
  `aic use` that win over provider aliases; replace dead `unwrap_or(name)`
  fallbacks with structural `expect`s; preset test now pins the full spec
  (command/args/timeout_secs/encoding) instead of spot checks.
@CaicoLeung
CaicoLeung merged commit fad9777 into main Aug 15, 2026
9 checks passed
@CaicoLeung
CaicoLeung deleted the feat/use-cli-agents branch August 15, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant