Skip to content

Conversation

@sigmachirality
Copy link
Member

Refactors commands using Ink to explicitly call exit and waitUntilExit if they need to render multiple times.

@semanticdiff-com
Copy link

semanticdiff-com bot commented Dec 9, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  src/lib/clusters/clusters.tsx  76% smaller
  src/lib/orders/index.tsx  68% smaller
  src/lib/buy/index.tsx  56% smaller
  src/lib/scale/list.tsx  40% smaller
  src/lib/sell/index.tsx  27% smaller
  src/lib/scale/update.tsx  1% smaller
  src/index.ts  0% smaller

@sigmachirality sigmachirality self-assigned this Dec 9, 2025
@sigmachirality sigmachirality requested review from Flaque and joshi4 and removed request for Flaque December 9, 2025 21:39
@sigmachirality sigmachirality merged commit c68b86b into main Dec 9, 2025
1 check passed
@sigmachirality sigmachirality deleted the dt/refactor-to-use-parseasync branch December 9, 2025 21:40
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 9, 2025

Greptile Overview

Greptile Summary

This PR refactors the CLI to use parseAsync() instead of parse() and explicitly await waitUntilExit() from Ink render calls to control program flow.

Key changes:

  • Converted all command action handlers to async functions
  • Changed program.parse() to await program.parseAsync() in main entry point
  • Captured { waitUntilExit } from all render() calls and awaited them
  • Added exit to React dependency arrays where it's used in useEffect hooks
  • Standardized exit timing to use setTimeout(exit, 0) pattern

Benefits:

  • Explicit control over when the CLI process exits
  • Ensures Ink components complete their render cycles before program termination
  • Prevents race conditions where CLI might exit before async operations complete
  • More predictable program flow for commands that need to render multiple times

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward performance/reliability improvements following Ink's recommended patterns. All modifications are consistent, properly awaited, and don't alter business logic. The refactoring prevents race conditions and improves program flow control.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/index.ts 5/5 Changed parse to parseAsync in both tracking-enabled and tracking-disabled branches for explicit async control
src/lib/buy/index.tsx 5/5 Made action async, captured waitUntilExit from render calls, added exit to dependency arrays, and refactored exit timing to use setTimeout(exit, 0)
src/lib/clusters/clusters.tsx 5/5 Captured waitUntilExit from render call and awaited it; simplified setTimeout call
src/lib/orders/index.tsx 5/5 Captured waitUntilExit from render call and awaited it in non-JSON branch
src/lib/scale/list.tsx 5/5 Made action async, imported setTimeout, added exit hook and dependency, captured waitUntilExit and awaited it
src/lib/scale/update.tsx 5/5 Made action async, imported setTimeout, added useEffect to exit when results ready, captured waitUntilExit and awaited it
src/lib/sell/index.tsx 5/5 Imported setTimeout, captured waitUntilExit and awaited it, added exit call when order is fetched in polling loop

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as Commander.js
    participant Action as Command Action
    participant Ink as Ink Render
    participant Component as React Component
    
    Note over User,Component: Before (using parse + immediate exit)
    User->>CLI: Execute command
    CLI->>CLI: parse(process.argv)
    CLI->>Action: Execute action handler
    Action->>Ink: render(<Component />)
    Note over Ink: Component mounts
    Component->>Component: useEffect runs
    Component->>Component: setTimeout(exit, 0)
    Note over Action,Component: Action returns immediately<br/>CLI exits before render completes
    
    Note over User,Component: After (using parseAsync + waitUntilExit)
    User->>CLI: Execute command
    CLI->>CLI: await parseAsync(process.argv)
    CLI->>Action: await action handler
    Action->>Ink: render(<Component />)
    Ink-->>Action: { waitUntilExit }
    Note over Ink: Component mounts
    Component->>Component: useEffect runs
    Component->>Component: Fetch data/process
    Component->>Component: setTimeout(exit, 0)
    Action->>Ink: await waitUntilExit()
    Note over Ink: Waits for exit() call
    Ink-->>Action: Promise resolves
    Action-->>CLI: Returns
    CLI->>User: Clean exit
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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