Skip to content

feat: add interactive mode to strategy-builder CLI#2546

Open
hardyjosh wants to merge 1 commit into
strategy-builder-clifrom
interactive-strategy-builder
Open

feat: add interactive mode to strategy-builder CLI#2546
hardyjosh wants to merge 1 commit into
strategy-builder-clifrom
interactive-strategy-builder

Conversation

@hardyjosh
Copy link
Copy Markdown
Contributor

@hardyjosh hardyjosh commented Apr 13, 2026

Motivation

Constructing a non-interactive raindex strategy-builder invocation requires knowing the strategy key, deployment key, which select-tokens apply, which fields the deployment asks for, and the presets for each field. That is the exact flow the webapp walks users through visually. Asking a human or agent to read the raw .rain YAML to assemble those flags is a poor UX.

Solution

Add -i / --interactive to strategy-builder. It drives a TUI wizard in the terminal's alternate-screen buffer that mirrors the webapp flow:

  1. Enter owner address
  2. Pick a strategy (scrollable list with name + description, arrow navigation, paging)
  3. Pick a deployment
  4. Select tokens for each slot (with balance lookup)
  5. Fill each field (preset picker with custom-value escape hatch)
  6. Optionally add deposits (with preset amounts)
  7. Generate calldata, print to stdout or save to a file

Built on crossterm rather than dialoguer because dialoguer's cursor-up redraw maths miscounts multi-line wrapped items and corrupts the terminal. The alt-screen avoids all of that — the wizard owns its own screen and leaves the main terminal untouched.

All prior selections are shown as context at the top of every screen so the user can see how choices accumulate.

Checks

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features
    • Added interactive mode to the strategy builder CLI command with a guided wizard for configuring strategies and deployments.
    • Users can now select from available strategies, configure deployment variants, choose token approvals, and input deposits through an interactive prompt.
    • Added support for exporting generated deployment calldata to stdout or a specified file.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: edbf6ec3-2bf7-4ba6-aaf5-28037db2c659

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request introduces an interactive CLI mode for the strategy builder that guides users through strategy deployment configuration. New dependencies are added for terminal UI and HTTP requests. The interactive flow fetches available strategies, collects user inputs for owner, strategy selection, and builder parameters, then generates and outputs deployment transaction calldata.

Changes

Cohort / File(s) Summary
Dependencies
crates/cli/Cargo.toml
Added CLI dependencies: console, crossterm, and dialoguer for terminal UI; added workspace reqwest for HTTP requests.
Terminal UI Components
crates/cli/src/commands/strategy_builder/select.rs
New module providing interactive terminal selection and text input primitives with word-wrapping, ANSI styling, and scrollable list rendering.
Interactive Mode Implementation
crates/cli/src/commands/strategy_builder/interactive.rs
New 580-line interactive wizard that orchestrates strategy fetching, user input collection, and deployment calldata generation with progress tracking and terminal state management.
Strategy Builder Module
crates/cli/src/commands/strategy_builder/mod.rs
Added --interactive flag and submodules; changed strategy, deployment, and owner from required to optional fields; updated execution flow to delegate to interactive mode when enabled.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as StrategyBuilder<br/>(mod.rs)
    participant Interactive as Interactive<br/>Wizard
    participant UI as Terminal UI<br/>(select.rs)
    participant Registry as Registry API
    participant Calldata as Calldata<br/>Generator

    User->>CLI: Run with --interactive flag
    CLI->>Interactive: run_interactive(registry_url)
    
    Interactive->>Registry: Fetch available strategies
    Registry-->>Interactive: Strategy list
    
    Interactive->>UI: Render strategy selection
    UI->>User: Display selectable list
    User->>UI: Select strategy + deployment variant
    UI-->>Interactive: Selected indices
    
    Interactive->>UI: Prompt owner address input
    User->>UI: Enter owner address
    UI-->>Interactive: Owner address
    
    Interactive->>UI: Prompt order tokens selection
    User->>UI: Select tokens (optional)
    UI-->>Interactive: Token choices
    
    Interactive->>UI: Prompt builder field inputs
    User->>UI: Fill required fields
    UI-->>Interactive: Field values
    
    Interactive->>UI: Prompt deposit amounts
    User->>UI: Enter deposits
    UI-->>Interactive: Deposit values
    
    Interactive->>Calldata: Generate deployment calldata<br/>(with approvals + deployment)
    Calldata-->>Interactive: Calldata lines
    
    Interactive->>UI: Prompt output mode (stdout/file)
    User->>UI: Choose output destination
    UI-->>Interactive: Output preference
    
    Interactive->>User: Write calldata to stdout or file
    User-->>Interactive: Output complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding an interactive mode to the strategy-builder CLI, which aligns with the core objective of the changeset.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch interactive-strategy-builder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor Author

hardyjosh commented Apr 13, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label Raindex-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@hardyjosh
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hardyjosh hardyjosh force-pushed the interactive-strategy-builder branch from 09b6e85 to 9a36b8f Compare April 15, 2026 20:50
@hardyjosh
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/cli/src/commands/strategy_builder/interactive.rs`:
- Around line 165-185: Replace the catch-all `_ => Ok(calldata_lines)` in the
match on `output_choice` with an explicit `0 => Ok(calldata_lines)` arm to
self-document the intended case; also add a fallback arm (e.g., `_ =>
unreachable!("invalid output_choice")` or return a descriptive error) to catch
unexpected indices at runtime. Update the match that references `output_choice`,
`calldata_lines`, and `path` accordingly so the two intended branches are
explicit and any other values are handled explicitly.
- Around line 29-37: Wrap the terminal setup/teardown with a panic-safe guard so
raw mode and cursor/screen state are always restored if run_wizard panics: after
calling terminal::enable_raw_mode() and execute!(w,
terminal::EnterAlternateScreen, cursor::Hide), create a small RAII guard type
(or use std::panic::catch_unwind) whose Drop implementation calls execute!(w,
terminal::LeaveAlternateScreen, cursor::Show) and terminal::disable_raw_mode();
then call run_wizard(&mut w, &registry, &mut progress).await normally and let
the guard handle cleanup (or explicitly dismiss the guard) to ensure w, raw
mode, and cursor state are restored even on panic.

In `@crates/cli/src/commands/strategy_builder/select.rs`:
- Around line 284-292: The code risks underflow when computing positions like
cols as u16 - 3 and rows as u16 - 2; change these to use saturating subtraction
on the usize values before casting (e.g., let xpos = cols.saturating_sub(3) as
u16 and let ypos = rows.saturating_sub(2) as u16) and use xpos/ypos in the
execute! calls so cursor::MoveTo gets a safe u16; update both places where
cols/rows are adjusted and keep existing variables (scroll, total_header,
count_items_fitting, items) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 70e78f15-8e44-4f16-805a-db1cd610bebd

📥 Commits

Reviewing files that changed from the base of the PR and between 72e5a29 and 9a36b8f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/cli/Cargo.toml
  • crates/cli/src/commands/strategy_builder/interactive.rs
  • crates/cli/src/commands/strategy_builder/mod.rs
  • crates/cli/src/commands/strategy_builder/select.rs

Comment thread crates/cli/src/commands/strategy_builder/interactive.rs Outdated
Comment thread crates/cli/src/commands/strategy_builder/interactive.rs
Comment thread crates/cli/src/commands/strategy_builder/select.rs
Copy link
Copy Markdown
Contributor Author

hardyjosh commented May 11, 2026

Merge activity

graphite-app Bot pushed a commit that referenced this pull request May 11, 2026
## Motivation

The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata.

## Solution

Add a `strategy-builder` subcommand to the raindex CLI that generates deployment calldata from a remote registry strategy.

```
raindex strategy-builder \
  --registry <url> \
  --strategy <key> \
  --deployment <key> \
  --owner <0x-address> \
  [--select-token KEY=ADDRESS ...] \
  [--set-field BINDING=VALUE ...] \
  [--set-deposit TOKEN=AMOUNT ...]
```

Outputs one `<address>:<calldata>` line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction.

Implementation reuses `RaindexOrderBuilder` from the common crate (same object the webapp drives) and `DotrainRegistry` from the js_api crate, so the CLI and webapp use identical resolution semantics.

Follow-up PRs in this stack add `--interactive` (#2546), `--tokens` (#2549), the template-fallback operator (#2551), and `--describe` (#2548).

## Checks

- [x] made this PR as small as possible
- [x] unit-tested any new functionality
- [x] linked any relevant issues or PRs
- [ ] included screenshots (if this involves a front-end change)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added a new `strategy-builder` command that generates deployment calldata from registry strategies with configurable field bindings, token selections, and deposit amounts.

* **Improvements**
  * Token logo URIs are now optional, improving compatibility with token data sources.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app Bot force-pushed the strategy-builder-cli branch from ea4b4dd to 70fbd42 Compare May 11, 2026 10:04
graphite-app Bot pushed a commit that referenced this pull request May 11, 2026
## Motivation

Constructing a non-interactive `raindex strategy-builder` invocation requires knowing the strategy key, deployment key, which select-tokens apply, which fields the deployment asks for, and the presets for each field. That is the exact flow the webapp walks users through visually. Asking a human or agent to read the raw `.rain` YAML to assemble those flags is a poor UX.

## Solution

Add `-i` / `--interactive` to `strategy-builder`. It drives a TUI wizard in the terminal's alternate-screen buffer that mirrors the webapp flow:

1. Enter owner address
2. Pick a strategy (scrollable list with name + description, arrow navigation, paging)
3. Pick a deployment
4. Select tokens for each slot (with balance lookup)
5. Fill each field (preset picker with custom-value escape hatch)
6. Optionally add deposits (with preset amounts)
7. Generate calldata, print to stdout or save to a file

Built on `crossterm` rather than `dialoguer` because dialoguer's cursor-up redraw maths miscounts multi-line wrapped items and corrupts the terminal. The alt-screen avoids all of that — the wizard owns its own screen and leaves the main terminal untouched.

All prior selections are shown as context at the top of every screen so the user can see how choices accumulate.

## Checks

- [x] made this PR as small as possible
- [x] unit-tested any new functionality
- [x] linked any relevant issues or PRs
- [ ] included screenshots (if this involves a front-end change)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added interactive mode to the strategy builder CLI command with a guided wizard for configuring strategies and deployments.
  * Users can now select from available strategies, configure deployment variants, choose token approvals, and input deposits through an interactive prompt.
  * Added support for exporting generated deployment calldata to stdout or a specified file.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app Bot force-pushed the interactive-strategy-builder branch from 70bd12e to 064b102 Compare May 11, 2026 10:04
graphite-app Bot pushed a commit that referenced this pull request May 11, 2026
## Motivation

The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata.

## Solution

Add a `strategy-builder` subcommand to the raindex CLI that generates deployment calldata from a remote registry strategy.

```
raindex strategy-builder \
  --registry <url> \
  --strategy <key> \
  --deployment <key> \
  --owner <0x-address> \
  [--select-token KEY=ADDRESS ...] \
  [--set-field BINDING=VALUE ...] \
  [--set-deposit TOKEN=AMOUNT ...]
```

Outputs one `<address>:<calldata>` line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction.

Implementation reuses `RaindexOrderBuilder` from the common crate (same object the webapp drives) and `DotrainRegistry` from the js_api crate, so the CLI and webapp use identical resolution semantics.

Follow-up PRs in this stack add `--interactive` (#2546), `--tokens` (#2549), the template-fallback operator (#2551), and `--describe` (#2548).

## Checks

- [x] made this PR as small as possible
- [x] unit-tested any new functionality
- [x] linked any relevant issues or PRs
- [ ] included screenshots (if this involves a front-end change)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added a new `strategy-builder` command that generates deployment calldata from registry strategies with configurable field bindings, token selections, and deposit amounts.

* **Improvements**
  * Token logo URIs are now optional, improving compatibility with token data sources.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app Bot force-pushed the strategy-builder-cli branch from 70fbd42 to a1e2ce7 Compare May 11, 2026 12:27
graphite-app Bot pushed a commit that referenced this pull request May 11, 2026
## Motivation

Constructing a non-interactive `raindex strategy-builder` invocation requires knowing the strategy key, deployment key, which select-tokens apply, which fields the deployment asks for, and the presets for each field. That is the exact flow the webapp walks users through visually. Asking a human or agent to read the raw `.rain` YAML to assemble those flags is a poor UX.

## Solution

Add `-i` / `--interactive` to `strategy-builder`. It drives a TUI wizard in the terminal's alternate-screen buffer that mirrors the webapp flow:

1. Enter owner address
2. Pick a strategy (scrollable list with name + description, arrow navigation, paging)
3. Pick a deployment
4. Select tokens for each slot (with balance lookup)
5. Fill each field (preset picker with custom-value escape hatch)
6. Optionally add deposits (with preset amounts)
7. Generate calldata, print to stdout or save to a file

Built on `crossterm` rather than `dialoguer` because dialoguer's cursor-up redraw maths miscounts multi-line wrapped items and corrupts the terminal. The alt-screen avoids all of that — the wizard owns its own screen and leaves the main terminal untouched.

All prior selections are shown as context at the top of every screen so the user can see how choices accumulate.

## Checks

- [x] made this PR as small as possible
- [x] unit-tested any new functionality
- [x] linked any relevant issues or PRs
- [ ] included screenshots (if this involves a front-end change)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added interactive mode to the strategy builder CLI command with a guided wizard for configuring strategies and deployments.
  * Users can now select from available strategies, configure deployment variants, choose token approvals, and input deposits through an interactive prompt.
  * Added support for exporting generated deployment calldata to stdout or a specified file.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app Bot force-pushed the interactive-strategy-builder branch from 064b102 to 42d4024 Compare May 11, 2026 12:28
## Motivation

Constructing a non-interactive `raindex strategy-builder` invocation requires knowing the strategy key, deployment key, which select-tokens apply, which fields the deployment asks for, and the presets for each field. That is the exact flow the webapp walks users through visually. Asking a human or agent to read the raw `.rain` YAML to assemble those flags is a poor UX.

## Solution

Add `-i` / `--interactive` to `strategy-builder`. It drives a TUI wizard in the terminal's alternate-screen buffer that mirrors the webapp flow:

1. Enter owner address
2. Pick a strategy (scrollable list with name + description, arrow navigation, paging)
3. Pick a deployment
4. Select tokens for each slot (with balance lookup)
5. Fill each field (preset picker with custom-value escape hatch)
6. Optionally add deposits (with preset amounts)
7. Generate calldata, print to stdout or save to a file

Built on `crossterm` rather than `dialoguer` because dialoguer's cursor-up redraw maths miscounts multi-line wrapped items and corrupts the terminal. The alt-screen avoids all of that — the wizard owns its own screen and leaves the main terminal untouched.

All prior selections are shown as context at the top of every screen so the user can see how choices accumulate.

## Checks

- [x] made this PR as small as possible
- [x] unit-tested any new functionality
- [x] linked any relevant issues or PRs
- [ ] included screenshots (if this involves a front-end change)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added interactive mode to the strategy builder CLI command with a guided wizard for configuring strategies and deployments.
  * Users can now select from available strategies, configure deployment variants, choose token approvals, and input deposits through an interactive prompt.
  * Added support for exporting generated deployment calldata to stdout or a specified file.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
graphite-app Bot pushed a commit that referenced this pull request May 11, 2026
## Motivation

The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata.

## Solution

Add a `strategy-builder` subcommand to the raindex CLI that generates deployment calldata from a remote registry strategy.

```
raindex strategy-builder \
  --registry <url> \
  --strategy <key> \
  --deployment <key> \
  --owner <0x-address> \
  [--select-token KEY=ADDRESS ...] \
  [--set-field BINDING=VALUE ...] \
  [--set-deposit TOKEN=AMOUNT ...]
```

Outputs one `<address>:<calldata>` line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction.

Implementation reuses `RaindexOrderBuilder` from the common crate (same object the webapp drives) and `DotrainRegistry` from the js_api crate, so the CLI and webapp use identical resolution semantics.

Follow-up PRs in this stack add `--interactive` (#2546), `--tokens` (#2549), the template-fallback operator (#2551), and `--describe` (#2548).

## Checks

- [x] made this PR as small as possible
- [x] unit-tested any new functionality
- [x] linked any relevant issues or PRs
- [ ] included screenshots (if this involves a front-end change)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Added `strategy-builder` command to the CLI for generating deployment calldata from registry-based strategies. The command accepts required parameters for registry URL, strategy identifier, deployment address, and owner. Users can further customize strategy deployments with repeatable options to set field bindings, select tokens, and configure deposit amounts, enabling streamlined deployment workflows.

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/rainlanguage/raindex/pull/2544)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app Bot force-pushed the strategy-builder-cli branch from a1e2ce7 to 50d4083 Compare May 11, 2026 12:31
@graphite-app graphite-app Bot force-pushed the interactive-strategy-builder branch from 42d4024 to b71ab0d Compare May 11, 2026 12:32
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