feat: add interactive mode to strategy-builder CLI#2546
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
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.
How to use the Graphite Merge QueueAdd 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. |
5b81496 to
09b6e85
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
09b6e85 to
9a36b8f
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
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, ®istry, &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
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
crates/cli/Cargo.tomlcrates/cli/src/commands/strategy_builder/interactive.rscrates/cli/src/commands/strategy_builder/mod.rscrates/cli/src/commands/strategy_builder/select.rs
72e5a29 to
ea4b4dd
Compare
3188bcf to
70bd12e
Compare
Merge activity
|
## 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 -->
ea4b4dd to
70fbd42
Compare
## 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 -->
70bd12e to
064b102
Compare
## 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 -->
70fbd42 to
a1e2ce7
Compare
## 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 -->
064b102 to
42d4024
Compare
## 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 -->
## 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. [](https://app.coderabbit.ai/change-stack/rainlanguage/raindex/pull/2544) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
a1e2ce7 to
50d4083
Compare
42d4024 to
b71ab0d
Compare

Motivation
Constructing a non-interactive
raindex strategy-builderinvocation 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.rainYAML to assemble those flags is a poor UX.Solution
Add
-i/--interactivetostrategy-builder. It drives a TUI wizard in the terminal's alternate-screen buffer that mirrors the webapp flow:Built on
crosstermrather thandialoguerbecause 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
Summary by CodeRabbit