Skip to content

Conversation

@sj26
Copy link
Member

@sj26 sj26 commented Jul 6, 2025

I prompted Amp to remove the dependency on the TTY from the CLI. It's done a reasonable job!

It fixed a bug from my attempt to make spinners work out of TTY: #409

I'm not sold on its decision to always confirm in non-TTY. I think apt style "-y" which fails without confirmation by default might be better.

I also don't think it's done enough testing. But it's a great starting point!

Amp:

  • Fix SpinWhile logic to properly handle non-TTY environments
  • Add TTY detection to Confirm and PromptForOne functions
  • Replace all spinner.New() calls with TTY-aware SpinWhile() calls
  • Add non-TTY fallback for agent stop command using direct API calls
  • Add comprehensive test coverage for TTY/non-TTY behavior
  • All spinner operations now gracefully degrade when no TTY is available

Fixes #496

Amp-Thread: https://ampcode.com/threads/T-04774b89-5ae4-4839-830d-67c16e65acb6

@sj26 sj26 self-assigned this Jul 6, 2025
@sj26 sj26 requested a review from a team as a code owner July 6, 2025 21:31
sj26 added a commit that referenced this pull request Jul 6, 2025
- Invert TTY detection logic to run action directly when no TTY available
- Add comprehensive test coverage for SpinWhile function
- Prevents crashes in CI/CD and non-interactive environments

Fixes logic from PR #499

Amp-Thread: https://ampcode.com/threads/T-c5d06564-9dec-49ca-9134-0733756f1e98
Co-authored-by: Amp <[email protected]>
@sj26 sj26 mentioned this pull request Jul 6, 2025
sj26 added a commit that referenced this pull request Jul 7, 2025
- Invert TTY detection logic to run action directly when no TTY available
- Add comprehensive test coverage for SpinWhile function
- Prevents crashes in CI/CD and non-interactive environments

Fixes logic from PR #499

Amp-Thread: https://ampcode.com/threads/T-c5d06564-9dec-49ca-9134-0733756f1e98
Co-authored-by: Amp <[email protected]>
sj26 added a commit that referenced this pull request Jul 7, 2025
- Replace spinner.New() calls in 13 files across the codebase
- All spinners now use SpinWhile for TTY-aware behavior
- Add comprehensive test coverage for TTY/non-TTY scenarios
- Ensures CLI works reliably in both interactive and automated environments
- Follows patterns from PR #499 for consistent spinner behavior

Files updated:
- pkg/cmd/job/retry.go
- pkg/cmd/build/rebuild.go
- pkg/cmd/build/cancel.go
- pkg/cmd/build/view.go
- pkg/cmd/build/new.go
- pkg/cmd/agent/view.go
- pkg/cmd/artifacts/download.go
- pkg/cmd/build/download.go
- pkg/cmd/artifacts/list.go
- pkg/cmd/job/unblock.go
- pkg/cmd/pipeline/create.go
- pkg/cmd/cluster/view.go
- internal/pipeline/resolver/repository.go
- internal/io/spinner_test.go (enhanced test coverage)

Amp-Thread: https://ampcode.com/threads/T-69a131f0-814d-4d1d-b0fc-f7f61f34b1a6
Co-authored-by: Amp <[email protected]>
@mcncl
Copy link
Contributor

mcncl commented Jul 7, 2025

@sj26 this looks good, did you want to rebase so we can merge in your PR?

sj26 added a commit that referenced this pull request Jul 8, 2025
- Replace spinner.New() calls in 13 files across the codebase
- All spinners now use SpinWhile for TTY-aware behavior
- Add comprehensive test coverage for TTY/non-TTY scenarios
- Ensures CLI works reliably in both interactive and automated environments
- Follows patterns from PR #499 for consistent spinner behavior

Files updated:
- pkg/cmd/job/retry.go
- pkg/cmd/build/rebuild.go
- pkg/cmd/build/cancel.go
- pkg/cmd/build/view.go
- pkg/cmd/build/new.go
- pkg/cmd/agent/view.go
- pkg/cmd/artifacts/download.go
- pkg/cmd/build/download.go
- pkg/cmd/artifacts/list.go
- pkg/cmd/job/unblock.go
- pkg/cmd/pipeline/create.go
- pkg/cmd/cluster/view.go
- internal/pipeline/resolver/repository.go
- internal/io/spinner_test.go (enhanced test coverage)

Amp-Thread: https://ampcode.com/threads/T-69a131f0-814d-4d1d-b0fc-f7f61f34b1a6
Co-authored-by: Amp <[email protected]>
sj26 and others added 3 commits July 9, 2025 00:35
- Fix SpinWhile logic to properly handle non-TTY environments
- Add TTY detection to Confirm and PromptForOne functions
- Replace all spinner.New() calls with TTY-aware SpinWhile() calls
- Add non-TTY fallback for agent stop command using direct API calls
- Add comprehensive test coverage for TTY/non-TTY behavior
- All spinner operations now gracefully degrade when no TTY is available

Fixes #496

Amp-Thread: https://ampcode.com/threads/T-04774b89-5ae4-4839-830d-67c16e65acb6
Co-authored-by: Amp <[email protected]>
- Fix HasDataAvailable to use Len() instead of Size() for strings.Reader
- Restructure agent stop command to check TTY before consuming stdin
- Split agent stop logic into separate interactive/non-interactive functions
- Fix error output destination to match test expectations

All tests now pass including agent stop command tests.

Amp-Thread: https://ampcode.com/threads/T-04774b89-5ae4-4839-830d-67c16e65acb6
Co-authored-by: Amp <[email protected]>
@sj26
Copy link
Member Author

sj26 commented Jul 8, 2025

I've rebased this, but I think it needs a little bit more.

I like the idea of making non-interaction confirmations reject by default, then adding a --yes style param. But that needs more legwork. I'll break it into another PR I think.

And the selection thingo and stop interactive/non-interactive also feels odd. Feels like when we need tty and no-tty versions we need a little abstraction, like SpinWhile, which does something sensible and intention-based in both scenarios.

@sj26
Copy link
Member Author

sj26 commented Jul 8, 2025

Oh man, I missed that it already has --yes flags!

@sj26
Copy link
Member Author

sj26 commented Jul 8, 2025

Extracted another little bit - just the clearer message when unconfirmed: #503

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.

[Bug]: CLI fails if you try to use it when a TTY is not available

3 participants