Skip to content

Conversation

pokgak
Copy link
Contributor

@pokgak pokgak commented Aug 21, 2025

Summary

Major CLI usability improvements with consistent --yes flags, --output=json support, human-friendly age display, and structured utilities for better maintainability.

✨ New Features

1. Skip Confirmation Prompts (--yes/-y)

Bypass interactive confirmations for automation and scripting.

Commands Updated:

  • prime sandbox create --yes
  • prime sandbox delete --yes
  • prime pod create --yes
  • prime pod terminate --yes

2. JSON Output Support (--output=json)

Machine-readable output for automation with consistent field exposure.

Commands Updated:

  • prime sandbox list --output=json
  • prime sandbox get <id> --output=json
  • prime pods list --output=json
  • prime pods status <id> --output=json
  • prime env list --output=json
  • prime availability list --output=json

3. Human-Friendly Age Display

Tables show intuitive age format, JSON preserves precise timestamps.

Commands Updated:

  • prime sandbox list - Age column (29m, 2h, 3d format)
  • prime pods list - Age column (29m, 2h, 3d format)

4. Consistent List Sorting

All lists sorted chronologically with oldest items first.

Commands Updated:

  • prime sandbox list - Sorted by creation time
  • prime pods list - Sorted by creation time

5. Structured Utilities Package

Extracted shared code into organized utility modules for better maintainability.

📋 Examples

Skip Confirmations (Great for Scripts)

# Create resources without prompts
prime sandbox create ubuntu:20.04 --name my-sandbox --yes
prime pod create --id 1234 --yes

# Delete resources without prompts  
prime sandbox delete sandbox-123 --yes
prime pod terminate pod-456 --yes

JSON Output for Automation

# Get structured data for scripts
prime sandbox list --output=json | jq '.sandboxes[].id'
prime pods list --output=json | jq '.pods[] | select(.status == "ACTIVE")'
prime availability list --output=json | jq '.gpu_resources[] | select(.price_value < 1.0)'

# Pipe to other tools
prime env list --output=json | jq '.environments[] | .environment'

Improved List Display

prime sandbox list
# Output:
# ID        NAME           IMAGE         STATUS   RESOURCES      AGE
# sb-old    old-sandbox    ubuntu:20.04  RUNNING  2CPU/4GB/1GPU  3d    ← Oldest
# sb-new    new-sandbox    python:3.9    RUNNING  1CPU/2GB       29m   ← Newest

prime pods list  
# Output:
# ID        NAME     GPU        STATUS   AGE
# pod-old   test-1   A100 x1    ACTIVE   2h     ← Oldest
# pod-new   test-2   V100 x2    ACTIVE   15m    ← Newest

Detailed Status Information

# Table format (human-readable)
prime pods status pod-123
prime sandbox get sandbox-456

# JSON format (automation-friendly)
prime pods status pod-123 --output=json
prime sandbox get sandbox-456 --output=json

🔧 Technical Details

Smart Output Format Selection:

  • Table format: Human-friendly age (29m, 2h, 3d) for quick scanning
  • JSON format: ISO timestamps (2024-01-15 14:30:00 UTC) for precision
  • Validation: Clear error messages for invalid formats

Shared Utilities Architecture:

  • utils/time_utils.py - Age formatting, timestamp handling, sorting
  • utils/display.py - Table building, status colors, JSON output
  • utils/formatters.py - Resource formatting, price display, env var obfuscation
  • utils/prompt.py - Confirmation prompts with --yes support

pokgak and others added 6 commits August 21, 2025 12:50
- Add --yes/-y option to sandbox create/delete and pods create/terminate
- Sort sandbox list by age (oldest first)
- Change Created column to Age with human-friendly format (29m, 2h, 3d)

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-d686962a-b0a1-47d0-a329-43b3555d7591
- Add --output/-o option with table (default) or json formats
- JSON output includes all sandbox data with proper API field names
- Maintains backward compatibility with default table output

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-d686962a-b0a1-47d0-a329-43b3555d7591
- JSON output now matches table format scope
- Excludes internal API fields like kubernetes_job_id, updated_at
- Environment variables are obfuscated in JSON same as table
- Maintains data privacy and consistency between formats
- Created _format_sandbox_for_list() and _format_sandbox_for_details() functions
- Both table and JSON outputs now use the same underlying data model
- Ensures consistent field exposure across output formats
- Eliminates code duplication and reduces risk of inconsistencies
- Add proper type hints for _format_sandbox_for_list and _format_sandbox_for_details
- Import Sandbox type and typing utilities
- Explicit type annotation for data dict to satisfy mypy
@pokgak pokgak changed the title Add --yes option and improve sandbox list display Add --yes option, --output=json, and improve sandbox list display Aug 21, 2025
@pokgak pokgak requested a review from JannikSt August 21, 2025 05:29
pokgak added 9 commits August 21, 2025 13:51
- Validate that --output only accepts 'table' or 'json'
- Show clear error message for invalid formats
- Exit with code 1 on invalid format
- Created utils.py with shared functions:
  - validate_output_format() for output validation
  - output_data_as_json() for consistent JSON output
  - confirm_or_skip() for confirmation prompts with --yes support
- Updated sandbox commands to use shared utilities
- Added --output=json support to pods list command
- Added --output=json support to env list command
- Updated all confirmation prompts to use shared utility
- Added JSON output validation for watch mode in pods list
- Added age formatting to pods list table output (29m, 2h, 3d format)
- Changed Created column to Age column in pods list table
- Keep timestamp in JSON output for automation needs
- Updated sandbox list to also use timestamp in JSON (consistent approach)
- Table format shows human-friendly age, JSON shows precise timestamps
- Added --output/-o option to 'prime pods status <id>' command
- Created _format_pod_for_status() helper function for data formatting
- JSON output includes all status data, port mappings, and attached resources
- Table output uses same data source for consistency
- Both formats show identical information with appropriate styling
- Added sorting by created_at timestamp in pods list command
- Oldest pods now appear at the top, newest at the bottom
- Consistent behavior with sandbox list sorting
- Applied to both table and JSON output formats
- Added --output/-o option to 'prime availability list' command
- Created _format_availability_for_display() helper function for data formatting
- JSON output includes all availability data, filters, and count information
- Table output uses same data source for consistency
- Both formats show identical information with appropriate styling
Based on Oracle analysis, created structured utils package:

- utils/time_utils.py: human_age(), iso_timestamp(), sort_by_created()
- utils/display.py: build_table(), status_color(), common color mappings
- utils/formatters.py: obfuscate_env_vars(), format_resources(), format_price()
- utils/prompt.py: confirm_or_skip()

Refactored sandbox.py to use new utilities:
- Removed duplicate _format_age() and _obfuscate_env_vars() functions
- Uses shared status color mappings and table building
- Maintains backward compatibility with existing utils.py imports

Benefits:
- Single source of truth for time/formatting logic
- Consistent styling across commands
- Easier testing and maintenance
- Foundation for future command refactoring
cursor[bot]

This comment was marked as outdated.

@pokgak pokgak changed the title Add --yes option, --output=json, and improve sandbox list display eng-1668: Add --yes option, --output=json, and improve sandbox list display Aug 21, 2025
pokgak and others added 2 commits August 21, 2025 22:43
- Export format_resources function in utils/__init__.py
- Fix undefined _obfuscate_env_vars reference in sandbox.py
- Remove old utils.py compatibility module
- All imports now use the unified utils/ package

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-d686962a-b0a1-47d0-a329-43b3555d7591
@pokgak pokgak changed the title eng-1668: Add --yes option, --output=json, and improve sandbox list display eng-1668: Add --yes option, --output=json, and improve table list display Aug 21, 2025
cursor[bot]

This comment was marked as outdated.

pokgak added 3 commits August 21, 2025 22:49
- Add type annotations to key_fn functions in time_utils.py
- Fix typer.confirm return type in prompt.py
- Resolve variable name conflict in availability.py
- Use proper Pod and PodStatus types instead of Any in pods.py
- Import Pod and PodStatus classes for type safety
- Fix function signature conflict in time_utils.py by using single key_fn with Union return type
- Add explicit Dict[str, Any] type annotation to status_data in pods.py to resolve assignment errors
- All real type errors now resolved (ignoring missing stub packages)
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