Skip to content

experiment(cli): evaluate clap dynamic completion - #163

Open
NickNYU wants to merge 2 commits into
kvcache-ai:mainfrom
NickNYU:experiment/completion-clap-dynamic
Open

experiment(cli): evaluate clap dynamic completion#163
NickNYU wants to merge 2 commits into
kvcache-ai:mainfrom
NickNYU:experiment/completion-clap-dynamic

Conversation

@NickNYU

@NickNYU NickNYU commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This is one of two parallel experiments for #37. It evaluates clap_complete unstable-dynamic for dynamic sandbox-ID completion while preserving the existing static aenv completion bash|zsh|fish command.

What it adds

  • CompleteEnv shell adapter for Bash, Zsh, and Fish.
  • Dynamic candidates backed by the existing sandbox list API.
  • State-aware candidates for running, paused, and active sandbox IDs.
  • Short completion-specific network timeouts and silent failure behavior.
  • Focused tests and a design note.

Trade-off

This keeps the shell protocol small and shell-portable, but depends on clap_complete unstable-dynamic and its generated shell adapter contract. The companion PR proposes an AgentENV-owned aenv __complete protocol instead. These are alternatives; please review and choose one direction rather than merging both.

Verification

  • cargo fmt --all
  • cargo check -p aenv --bin aenv
  • cargo test -p aenv --bin aenv (56 passed; one pre-existing macOS /var symlink test failure in download tests)

nzhu added 2 commits August 8, 2026 11:45
Captures the sandbox-ID-only design, its short-timeout failure behavior, shell-adapter boundary, and verification plan before implementation begins.

Constraint: PR kvcache-ai#89 provides static completion but no stable dynamic hook\nRejected: Use clap_complete unstable-dynamic API | maintainer identified the surface as unstable\nConfidence: high\nScope-risk: narrow\nDirective: Keep dynamic lookup silent and separate from normal CLI timeouts\nTested: Design self-review and git diff --check\nNot-tested: CLI behavior; implementation has not started
Evaluate clap_complete's unstable dynamic completion engine for sandbox-ID lookup while preserving the existing generated completion command.

Constraint: The experiment must reuse the existing sandbox API and keep completion failures silent.

Rejected: Shell-specific API calls in generated scripts | duplicates authentication and response parsing across shells

Confidence: medium

Scope-risk: moderate

Directive: Keep the unstable protocol isolated until maintainers choose the long-term completion architecture

Tested: cargo check -p aenv --bin aenv; cargo fmt --all; generated COMPLETE=bash script; focused aenv tests (56 passed)

Not-tested: One existing download test fails on macOS because /var is a symlink
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

candidates.sort_by(|left, right| left.sandbox_id.cmp(&right.sandbox_id));
candidates
.into_iter()
.map(|sandbox| CompletionCandidate::new(sandbox.sandbox_id.clone()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[performance · low]
sandboxes is owned and is not used afterward, but filter_sandboxes converts it into references, forcing every completed sandbox ID to be cloned. Filter and sort the owned ListedSandbox values instead, then move each sandbox_id into CompletionCandidate; the test-only filtering helper can likewise return an iterator or be adapted to owned values.

Suggestion:

Suggested change
.map(|sandbox| CompletionCandidate::new(sandbox.sandbox_id.clone()))
.map(|sandbox| CompletionCandidate::new(sandbox.sandbox_id))

@LSX-s-Software LSX-s-Software left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing. I think this approach is more elegant and maintainable. However, there are some issues that should be fixed. In addition, please fix the clippy error and remove the docs generated by superpowers.

Comment on lines +55 to +57
pub fn active_sandbox_candidates() -> Vec<CompletionCandidate> {
sandbox_candidates(|state| matches!(state, Some("running") | Some("paused")))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a sandbox can only be in one of two states—running or paused—this filter seems a bit redundant.

Comment on lines +13 to +14
const DYNAMIC_CONNECT_TIMEOUT: Duration = Duration::from_millis(250);
const DYNAMIC_REQUEST_TIMEOUT: Duration = Duration::from_millis(500);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the timeout is a bit too short for remote users. Perhaps 500ms for connect and 1s for request is more appropriate.

#[arg(long = "sandbox-id")]
#[arg(
long = "sandbox-id",
add = crate::commands::completion::add_active_sandbox_candidates()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this completion candidate since the lifetime of the sandbox and its snapshots are independent.

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.

2 participants