Skip to content

Add dynamic shell completion to the aenv CLI #37

Description

@LSX-s-Software

Summary

Add first-class shell completion support to the native aenv CLI for Bash, Zsh, and Fish.

In addition to completing commands and flags, the CLI should dynamically complete AgentENV resources such as sandbox IDs and template/snapshot names.

Motivation

The CLI contains nested commands, aliases, and resource identifiers that are difficult to enter manually:

aenv snapshot create <sandbox-id>
aenv template watch <template>
aenv resume <sandbox-id>

Sandbox IDs are UUIDs, while templates and snapshots may be referenced by either names or IDs. As the number of resources grows, users currently need to run a list command, copy a value, and paste it into the next command.

Shell completion would make interactive CLI use faster and reduce invalid commands caused by stale or mistyped identifiers.

Proposed interface

Add a command that emits completion registration code:

aenv completion bash
aenv completion zsh
aenv completion fish

The generated registration should call back into the current aenv binary when completion is requested, allowing it to provide both static and dynamic candidates.

Static completion should cover:

  • top-level and nested subcommands;
  • command aliases such as ls, rm, cn, and snap;
  • flags and option values;
  • enum values such as --output table|json;
  • local paths such as the Dockerfile argument to aenv build.

Dynamic resource completion

Sandboxes

Commands accepting a sandbox ID should query the sandbox list and filter candidates by the states accepted by the command:

  • pause, exec, timeout, and snapshot create: running sandboxes;
  • resume: paused sandboxes;
  • connect, delete, and snapshot list --sandbox-id: running and paused sandboxes.

The inserted value should be the sandbox ID. When supported by the shell, the candidate description should include the sandbox's template and state.

Templates and snapshots

Commands accepting a template or snapshot should complete human-readable names or aliases first, with IDs available as fallback candidates:

  • aenv start <target>;
  • aenv template watch <template>;
  • aenv template delete <template>.

aenv start --cold should not query template or snapshot candidates because its target is an OCI image reference.

Candidate descriptions should distinguish templates from snapshots and include the underlying ID and build status where available.

Failure and performance behavior

Dynamic completion is an interactive, best-effort feature and must not make the shell feel blocked.

  • Use short connection and request timeouts.
  • Limit and deduplicate returned candidates.
  • Filter candidates by the prefix already entered.
  • If credentials are missing, the server is unavailable, or a request times out, silently return no dynamic candidates.
  • Static command and flag completion must continue to work when dynamic lookup fails.
  • Completion must not print diagnostic errors into the user's command line.

Installation

The existing installation paths should install lightweight completion loaders for Bash, Zsh, and Fish:

  • make install-aenv;
  • scripts/install-cli.sh;
  • the full AgentENV installer.

The loaders should generate registration code from the installed aenv binary when a shell starts, so CLI upgrades do not leave incompatible cached completion scripts behind.

Installers should use standard completion directories and must not modify .bashrc, .zshrc, or Fish configuration files automatically. If additional shell configuration is required, the installer should print an actionable message.

make uninstall-aenv should remove the installed completion loaders.

Documentation

Document automatic installation and manual activation:

source <(aenv completion bash)
source <(aenv completion zsh)
aenv completion fish | source

Acceptance criteria

  • Bash, Zsh, and Fish complete all current aenv commands, aliases, flags, and enum values.
  • Sandbox arguments are dynamically completed and filtered according to command-compatible states.
  • Template and snapshot names are completed for commands that accept them.
  • aenv start --cold does not return template or snapshot candidates.
  • Completion remains responsive and silent when authentication or the AgentENV server is unavailable.
  • Source builds and release installers install completion loaders without editing users' shell configuration.
  • CLI and installer tests cover script generation, candidate filtering, failure fallback, installation, upgrades, and removal.

Non-goals

  • PowerShell and Elvish support in the initial version.
  • Server-side API changes specifically for completion.
  • Persistent cross-process completion caches.
  • Automatically editing users' shell startup files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions