Escaping at a prompt should go up one level instead of exiting CLI #4

Closed
opened 2026-02-11 15:33:58 +00:00 by chris-kreidl · 2 comments
chris-kreidl commented 2026-02-11 15:33:58 +00:00 (Migrated from github.com)
No description provided.
chris-kreidl commented 2026-02-11 15:35:56 +00:00 (Migrated from github.com)

@coderabbitai plan

@coderabbitai plan
coderabbitai[bot] commented 2026-02-11 15:46:01 +00:00 (Migrated from github.com)

Coding Plan

Summary

  • Wrap the main execution in index.ts with a navigation loop that continuously presents mode selection until the user explicitly cancels at that level
  • Change internal cancellation handling to return control to the loop rather than exit the program
  • Preserve the existing exit behavior for authentication failures and non-interactive execution
  • Successful completion will also return to mode selection, enabling multi-operation sessions
Design Choices
Design Choice 1: Should successful completion of a mode also return to menu?

Options Considered:

  1. Return to menu after both cancel and successful completion (consistent experience, allows multiple operations per session)
  2. Return to menu only on cancel; exit on successful completion (matches current success path)

Chosen Option: 1

Rationale: Provides a more consistent user experience where the CLI acts as an interactive session rather than a one-shot tool, and aligns with the spirit of improved navigation.

💡 User Tips

Regenerate the plan with different choices with @coderabbitai <feedback>.

Implementation Steps

Phase 1: Establish Main Navigation Loop

This phase restructures the main execution flow to support returning to mode selection after any mode completes or is cancelled.

Task 1: Wrap Mode Execution in Navigation Loop

Restructure the main command handler to continuously loop through mode selection and execution until the user explicitly cancels at the mode selection prompt.

  • Modify src/index.ts to wrap the mode execution logic (lines ~140-356) in a while (true) loop
  • Move resolveSettingsWithPrompts() call inside the loop so mode selection is re-presented after each mode completes
  • When resolveSettingsWithPrompts() returns null (user cancelled at mode selection), break the loop and exit cleanly
  • When a mode execution completes (success or internal cancel), continue the loop to return to mode selection
Task 2: Adjust Settings Flow Integration

Ensure the settings flow integrates cleanly with the new navigation loop.

  • Review src/ui/settingsFlow.ts to confirm its existing settings loop continues to work correctly within the outer navigation loop
  • The existing while (mode === "settings") loop should function as before, with the outer loop handling production modes
🤖 Prompt for AI agents
**Goal:** Restructure the main execution flow in `src/index.ts` to support a
continuous navigation loop that returns to mode selection after operations
complete or are cancelled.

**Changes to `src/index.ts`:**
- Wrap the mode execution logic (lines ~140-356) in a `while (true)` loop
- Move the `resolveSettingsWithPrompts()` call inside the loop so mode selection
is re-presented after each iteration
- When `resolveSettingsWithPrompts()` returns `null` (indicating user cancelled
at mode selection), break the loop and exit cleanly
- When a mode execution completes (either successfully or due to internal
cancellation), continue the loop to return to mode selection

**Settings Flow Integration:**
- Review `src/ui/settingsFlow.ts` to ensure its existing `while (mode ===
"settings")` loop functions correctly within the new outer navigation loop
- The settings flow should continue to work as before, with the outer loop
handling production modes (purchase orders and manufacturing orders)

Phase 2: Update Cancellation Handling in Mode Flows

This phase changes how cancellation is handled within each mode so that it returns control to the navigation loop rather than exiting the program.

Task 1: Update Purchase Orders Flow Cancellation

Modify the PO creation flow to gracefully return on cancellation instead of exiting.

  • In src/index.ts, update the PO flow section (lines ~157-272) to handle cancellation by returning/continuing instead of exiting
  • Remove or relocate outro("Cancelled.") calls within the PO flow since the navigation loop will handle the return to menu
  • Ensure promptForSupplier() returning null triggers a return to the navigation loop, not program exit
  • Update the PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit
Task 2: Update Manufacturing Orders Flow Cancellation

Modify the MO creation flows (sales_orders and general modes) to return on cancellation.

  • In src/index.ts, update the MO flow section (lines ~276-356) to handle cancellation by returning/continuing
  • Ensure promptForSalesOrders() returning empty/null triggers return to navigation loop
  • Ensure promptForShortageVariants() cancellation returns to navigation loop
  • Update promptForMoCreation() behavior so its early returns propagate back to the navigation loop
Task 3: Clean Up Redundant Exit Messages

Remove cancellation messages that would now be redundant or confusing given the new navigation behavior.

  • Review src/ui/prompts.ts for outro("Cancelled.") calls that occur at non-root levels
  • Either remove these calls or replace with a brief indication of returning to menu (e.g., log.info("Returning to menu..."))
  • Keep the outro("Cancelled.") message only for the mode selection cancellation in selectMode() (line 163)
  • Consider changing outro("Aborted.") messages (lines 637, 223) to indicate return to menu rather than program exit
🤖 Prompt for AI agents
**Goal:** Update cancellation handling across mode flows to return control to
the navigation loop instead of exiting the program.

**Purchase Orders Flow (`src/index.ts` lines ~157-272):**
- Change cancellation handling to return/continue instead of exiting
- Remove or relocate `outro("Cancelled.")` calls within the PO flow
- Ensure `promptForSupplier()` returning `null` triggers a return to the
navigation loop
- Update PO prefix input cancellation (line 214) and final confirmation
cancellation (line 223) to return instead of exit

**Manufacturing Orders Flow (`src/index.ts` lines ~276-356):**
- Update the MO flow section to handle cancellation by returning/continuing
- Ensure `promptForSalesOrders()` returning empty/null triggers return to
navigation loop
- Ensure `promptForShortageVariants()` cancellation returns to navigation loop
- Update `promptForMoCreation()` behavior so its early returns propagate back to
the navigation loop

**Exit Messages Cleanup (`src/ui/prompts.ts`):**
- Review all `outro("Cancelled.")` calls at non-root levels
- Remove these calls or replace with `log.info("Returning to menu...")` to
indicate navigation behavior
- Keep `outro("Cancelled.")` only for mode selection cancellation in
`selectMode()` (line 163)
- Change `outro("Aborted.")` messages (lines 637, 223) to indicate return to
menu rather than program exit

Phase 3: Preserve Critical Exit Points and Handle Edge Cases

This phase ensures that certain critical paths still exit appropriately and handles edge cases in the navigation flow.

Task 1: Preserve API Key Authentication Exit Behavior

Maintain the current exit behavior for API key resolution since this occurs before any navigation context exists.

  • Keep the process.exit(1) call in resolveApiKey() (line 132 in prompts.ts) unchanged
  • Keep the early return behavior when API key resolution fails in src/index.ts (line 120)
  • This authentication step must succeed before any navigation loop can begin
Task 2: Verify Pagination Behavior

Ensure the existing pagination logic in pagedMultiSelect() works correctly within the new navigation structure.

  • Review pagedMultiSelect() in src/ui/prompts.ts (lines 25-87)
  • The existing behavior where cancelling page continuation breaks the loop and returns accumulated selections should continue to work
  • Cancelling the page selection itself (line 59) already returns null, which will now propagate up to return to mode selection
Task 3: Update Completion Messaging

Add appropriate messaging when returning to mode selection after a completed or cancelled operation.

  • After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...")
  • This prevents jarring immediate return to menu after a successful operation
  • Consider using @clack/prompts log utilities for consistent styling
Task 4: Handle Non-Interactive Mode

Ensure non-interactive mode (when CLI args specify mode directly) still behaves correctly.

  • When mode is provided via CLI arguments, the navigation loop should execute that mode once and exit (current behavior)
  • Add a check to skip the navigation loop when running in non-interactive/scripted mode
  • This preserves the ability to use the CLI in automated pipelines
🤖 Prompt for AI agents
**Goal:** Preserve critical exit points and handle edge cases to ensure the
navigation loop doesn't break existing functionality.

**API Key Authentication (`src/ui/prompts.ts` line 132, `src/index.ts` line
120):**
- Keep the `process.exit(1)` call in `resolveApiKey()` unchanged
- Keep the early return behavior when API key resolution fails in `src/index.ts`
- Authentication must succeed before the navigation loop begins

**Pagination Behavior (`src/ui/prompts.ts` lines 25-87):**
- Review `pagedMultiSelect()` to verify it works correctly within the new
navigation structure
- Ensure cancelling page continuation breaks the loop and returns accumulated
selections as before
- Cancelling page selection itself (line 59) returns null, which should now
propagate up to return to mode selection

**Completion Messaging:**
- After successful MO/PO creation, add a brief pause or message before returning
to mode selection (e.g., "Press enter to continue...")
- Use `@clack/prompts` log utilities for consistent styling
- Prevents jarring immediate return to menu after successful operations

**Non-Interactive Mode:**
- Add a check to detect when mode is provided via CLI arguments
- Skip the navigation loop in non-interactive/scripted mode—execute the mode
once and exit
- Preserves the ability to use the CLI in automated pipelines
Research

The katana-mo-cli is a Manufacturing Order/Purchase Order creation tool built with gunshi for CLI argument parsing and @clack/prompts for interactive prompts. The current navigation is linear and forward-only: mode selection → data fetching → mode-specific prompts → exit. Cancellation (via isCancel()) is handled at 21 locations across prompts.ts and index.ts, with most returning null which propagates up and causes program exit. There is no navigation stack or state machine—the settings menu is the only flow that loops back to mode selection via a while loop in settingsFlow.ts. Data fetching happens after mode selection and is not cached.


🚀 Next Steps

🤖 All AI agent prompts combined
Task: 1

**Goal:** Restructure the main execution flow in `src/index.ts` to support a
continuous navigation loop that returns to mode selection after operations
complete or are cancelled.

**Changes to `src/index.ts`:**
- Wrap the mode execution logic (lines ~140-356) in a `while (true)` loop
- Move the `resolveSettingsWithPrompts()` call inside the loop so mode selection
is re-presented after each iteration
- When `resolveSettingsWithPrompts()` returns `null` (indicating user cancelled
at mode selection), break the loop and exit cleanly
- When a mode execution completes (either successfully or due to internal
cancellation), continue the loop to return to mode selection

**Settings Flow Integration:**
- Review `src/ui/settingsFlow.ts` to ensure its existing `while (mode ===
"settings")` loop functions correctly within the new outer navigation loop
- The settings flow should continue to work as before, with the outer loop
handling production modes (purchase orders and manufacturing orders)
===============================================================================

Task: 2

**Goal:** Update cancellation handling across mode flows to return control to
the navigation loop instead of exiting the program.

**Purchase Orders Flow (`src/index.ts` lines ~157-272):**
- Change cancellation handling to return/continue instead of exiting
- Remove or relocate `outro("Cancelled.")` calls within the PO flow
- Ensure `promptForSupplier()` returning `null` triggers a return to the
navigation loop
- Update PO prefix input cancellation (line 214) and final confirmation
cancellation (line 223) to return instead of exit

**Manufacturing Orders Flow (`src/index.ts` lines ~276-356):**
- Update the MO flow section to handle cancellation by returning/continuing
- Ensure `promptForSalesOrders()` returning empty/null triggers return to
navigation loop
- Ensure `promptForShortageVariants()` cancellation returns to navigation loop
- Update `promptForMoCreation()` behavior so its early returns propagate back to
the navigation loop

**Exit Messages Cleanup (`src/ui/prompts.ts`):**
- Review all `outro("Cancelled.")` calls at non-root levels
- Remove these calls or replace with `log.info("Returning to menu...")` to
indicate navigation behavior
- Keep `outro("Cancelled.")` only for mode selection cancellation in
`selectMode()` (line 163)
- Change `outro("Aborted.")` messages (lines 637, 223) to indicate return to
menu rather than program exit
===============================================================================

Task: 3

**Goal:** Preserve critical exit points and handle edge cases to ensure the
navigation loop doesn't break existing functionality.

**API Key Authentication (`src/ui/prompts.ts` line 132, `src/index.ts` line
120):**
- Keep the `process.exit(1)` call in `resolveApiKey()` unchanged
- Keep the early return behavior when API key resolution fails in `src/index.ts`
- Authentication must succeed before the navigation loop begins

**Pagination Behavior (`src/ui/prompts.ts` lines 25-87):**
- Review `pagedMultiSelect()` to verify it works correctly within the new
navigation structure
- Ensure cancelling page continuation breaks the loop and returns accumulated
selections as before
- Cancelling page selection itself (line 59) returns null, which should now
propagate up to return to mode selection

**Completion Messaging:**
- After successful MO/PO creation, add a brief pause or message before returning
to mode selection (e.g., "Press enter to continue...")
- Use `@clack/prompts` log utilities for consistent styling
- Prevents jarring immediate return to menu after successful operations

**Non-Interactive Mode:**
- Add a check to detect when mode is provided via CLI arguments
- Skip the navigation loop in non-interactive/scripted mode—execute the mode
once and exit
- Preserves the ability to use the CLI in automated pipelines
💡 Iterate on the plan with: @coderabbitai <feedback>
Example Feedback
- `@coderabbitai` You can skip phase 3. Add a simple unit test case for phase 2.
- `@coderabbitai` For design choice 1 go ahead with option 3 and replan.

💬 Have feedback or questions? Drop into our discord!

<!-- This is an auto-generated reply by CodeRabbit --> ## Coding Plan ### Summary - Wrap the main execution in `index.ts` with a navigation loop that continuously presents mode selection until the user explicitly cancels at that level - Change internal cancellation handling to return control to the loop rather than exit the program - Preserve the existing exit behavior for authentication failures and non-interactive execution - Successful completion will also return to mode selection, enabling multi-operation sessions <details> <summary><b>Design Choices</b></summary> <details> <summary><b>Design Choice 1: Should successful completion of a mode also return to menu?</b></summary> **Options Considered:** 1. Return to menu after both cancel and successful completion (consistent experience, allows multiple operations per session) 2. Return to menu only on cancel; exit on successful completion (matches current success path) **Chosen Option:** 1 **Rationale:** Provides a more consistent user experience where the CLI acts as an interactive session rather than a one-shot tool, and aligns with the spirit of improved navigation. </details> </details> <b>💡 User Tips</b> Regenerate the plan with different choices with `@coderabbitai <feedback>`. ## Implementation Steps ### Phase 1: Establish Main Navigation Loop This phase restructures the main execution flow to support returning to mode selection after any mode completes or is cancelled. <details> <summary><b>Task 1: Wrap Mode Execution in Navigation Loop</b></summary> Restructure the main command handler to continuously loop through mode selection and execution until the user explicitly cancels at the mode selection prompt. - Modify `src/index.ts` to wrap the mode execution logic (lines ~140-356) in a `while (true)` loop - Move `resolveSettingsWithPrompts()` call inside the loop so mode selection is re-presented after each mode completes - When `resolveSettingsWithPrompts()` returns `null` (user cancelled at mode selection), break the loop and exit cleanly - When a mode execution completes (success or internal cancel), continue the loop to return to mode selection </details> <details> <summary><b>Task 2: Adjust Settings Flow Integration</b></summary> Ensure the settings flow integrates cleanly with the new navigation loop. - Review `src/ui/settingsFlow.ts` to confirm its existing settings loop continues to work correctly within the outer navigation loop - The existing `while (mode === "settings")` loop should function as before, with the outer loop handling production modes </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` **Goal:** Restructure the main execution flow in `src/index.ts` to support a continuous navigation loop that returns to mode selection after operations complete or are cancelled. **Changes to `src/index.ts`:** - Wrap the mode execution logic (lines ~140-356) in a `while (true)` loop - Move the `resolveSettingsWithPrompts()` call inside the loop so mode selection is re-presented after each iteration - When `resolveSettingsWithPrompts()` returns `null` (indicating user cancelled at mode selection), break the loop and exit cleanly - When a mode execution completes (either successfully or due to internal cancellation), continue the loop to return to mode selection **Settings Flow Integration:** - Review `src/ui/settingsFlow.ts` to ensure its existing `while (mode === "settings")` loop functions correctly within the new outer navigation loop - The settings flow should continue to work as before, with the outer loop handling production modes (purchase orders and manufacturing orders) ``` </details> ### Phase 2: Update Cancellation Handling in Mode Flows This phase changes how cancellation is handled within each mode so that it returns control to the navigation loop rather than exiting the program. <details> <summary><b>Task 1: Update Purchase Orders Flow Cancellation</b></summary> Modify the PO creation flow to gracefully return on cancellation instead of exiting. - In `src/index.ts`, update the PO flow section (lines ~157-272) to handle cancellation by returning/continuing instead of exiting - Remove or relocate `outro("Cancelled.")` calls within the PO flow since the navigation loop will handle the return to menu - Ensure `promptForSupplier()` returning `null` triggers a return to the navigation loop, not program exit - Update the PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit </details> <details> <summary><b>Task 2: Update Manufacturing Orders Flow Cancellation</b></summary> Modify the MO creation flows (sales_orders and general modes) to return on cancellation. - In `src/index.ts`, update the MO flow section (lines ~276-356) to handle cancellation by returning/continuing - Ensure `promptForSalesOrders()` returning empty/null triggers return to navigation loop - Ensure `promptForShortageVariants()` cancellation returns to navigation loop - Update `promptForMoCreation()` behavior so its early returns propagate back to the navigation loop </details> <details> <summary><b>Task 3: Clean Up Redundant Exit Messages</b></summary> Remove cancellation messages that would now be redundant or confusing given the new navigation behavior. - Review `src/ui/prompts.ts` for `outro("Cancelled.")` calls that occur at non-root levels - Either remove these calls or replace with a brief indication of returning to menu (e.g., `log.info("Returning to menu...")`) - Keep the `outro("Cancelled.")` message only for the mode selection cancellation in `selectMode()` (line 163) - Consider changing `outro("Aborted.")` messages (lines 637, 223) to indicate return to menu rather than program exit </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` **Goal:** Update cancellation handling across mode flows to return control to the navigation loop instead of exiting the program. **Purchase Orders Flow (`src/index.ts` lines ~157-272):** - Change cancellation handling to return/continue instead of exiting - Remove or relocate `outro("Cancelled.")` calls within the PO flow - Ensure `promptForSupplier()` returning `null` triggers a return to the navigation loop - Update PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit **Manufacturing Orders Flow (`src/index.ts` lines ~276-356):** - Update the MO flow section to handle cancellation by returning/continuing - Ensure `promptForSalesOrders()` returning empty/null triggers return to navigation loop - Ensure `promptForShortageVariants()` cancellation returns to navigation loop - Update `promptForMoCreation()` behavior so its early returns propagate back to the navigation loop **Exit Messages Cleanup (`src/ui/prompts.ts`):** - Review all `outro("Cancelled.")` calls at non-root levels - Remove these calls or replace with `log.info("Returning to menu...")` to indicate navigation behavior - Keep `outro("Cancelled.")` only for mode selection cancellation in `selectMode()` (line 163) - Change `outro("Aborted.")` messages (lines 637, 223) to indicate return to menu rather than program exit ``` </details> ### Phase 3: Preserve Critical Exit Points and Handle Edge Cases This phase ensures that certain critical paths still exit appropriately and handles edge cases in the navigation flow. <details> <summary><b>Task 1: Preserve API Key Authentication Exit Behavior</b></summary> Maintain the current exit behavior for API key resolution since this occurs before any navigation context exists. - Keep the `process.exit(1)` call in `resolveApiKey()` (line 132 in prompts.ts) unchanged - Keep the early return behavior when API key resolution fails in `src/index.ts` (line 120) - This authentication step must succeed before any navigation loop can begin </details> <details> <summary><b>Task 2: Verify Pagination Behavior</b></summary> Ensure the existing pagination logic in `pagedMultiSelect()` works correctly within the new navigation structure. - Review `pagedMultiSelect()` in `src/ui/prompts.ts` (lines 25-87) - The existing behavior where cancelling page continuation breaks the loop and returns accumulated selections should continue to work - Cancelling the page selection itself (line 59) already returns null, which will now propagate up to return to mode selection </details> <details> <summary><b>Task 3: Update Completion Messaging</b></summary> Add appropriate messaging when returning to mode selection after a completed or cancelled operation. - After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...") - This prevents jarring immediate return to menu after a successful operation - Consider using `@clack/prompts` log utilities for consistent styling </details> <details> <summary><b>Task 4: Handle Non-Interactive Mode</b></summary> Ensure non-interactive mode (when CLI args specify mode directly) still behaves correctly. - When mode is provided via CLI arguments, the navigation loop should execute that mode once and exit (current behavior) - Add a check to skip the navigation loop when running in non-interactive/scripted mode - This preserves the ability to use the CLI in automated pipelines </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` **Goal:** Preserve critical exit points and handle edge cases to ensure the navigation loop doesn't break existing functionality. **API Key Authentication (`src/ui/prompts.ts` line 132, `src/index.ts` line 120):** - Keep the `process.exit(1)` call in `resolveApiKey()` unchanged - Keep the early return behavior when API key resolution fails in `src/index.ts` - Authentication must succeed before the navigation loop begins **Pagination Behavior (`src/ui/prompts.ts` lines 25-87):** - Review `pagedMultiSelect()` to verify it works correctly within the new navigation structure - Ensure cancelling page continuation breaks the loop and returns accumulated selections as before - Cancelling page selection itself (line 59) returns null, which should now propagate up to return to mode selection **Completion Messaging:** - After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...") - Use `@clack/prompts` log utilities for consistent styling - Prevents jarring immediate return to menu after successful operations **Non-Interactive Mode:** - Add a check to detect when mode is provided via CLI arguments - Skip the navigation loop in non-interactive/scripted mode—execute the mode once and exit - Preserves the ability to use the CLI in automated pipelines ``` </details> <details> <summary><b>Research</b></summary> The katana-mo-cli is a Manufacturing Order/Purchase Order creation tool built with `gunshi` for CLI argument parsing and `@clack/prompts` for interactive prompts. The current navigation is linear and forward-only: mode selection → data fetching → mode-specific prompts → exit. Cancellation (via `isCancel()`) is handled at 21 locations across `prompts.ts` and `index.ts`, with most returning `null` which propagates up and causes program exit. There is no navigation stack or state machine—the settings menu is the only flow that loops back to mode selection via a `while` loop in `settingsFlow.ts`. Data fetching happens after mode selection and is not cached. </details> --- ### 🚀 Next Steps <details> <summary><b>🤖 All AI agent prompts combined</b></summary> ``` Task: 1 **Goal:** Restructure the main execution flow in `src/index.ts` to support a continuous navigation loop that returns to mode selection after operations complete or are cancelled. **Changes to `src/index.ts`:** - Wrap the mode execution logic (lines ~140-356) in a `while (true)` loop - Move the `resolveSettingsWithPrompts()` call inside the loop so mode selection is re-presented after each iteration - When `resolveSettingsWithPrompts()` returns `null` (indicating user cancelled at mode selection), break the loop and exit cleanly - When a mode execution completes (either successfully or due to internal cancellation), continue the loop to return to mode selection **Settings Flow Integration:** - Review `src/ui/settingsFlow.ts` to ensure its existing `while (mode === "settings")` loop functions correctly within the new outer navigation loop - The settings flow should continue to work as before, with the outer loop handling production modes (purchase orders and manufacturing orders) =============================================================================== Task: 2 **Goal:** Update cancellation handling across mode flows to return control to the navigation loop instead of exiting the program. **Purchase Orders Flow (`src/index.ts` lines ~157-272):** - Change cancellation handling to return/continue instead of exiting - Remove or relocate `outro("Cancelled.")` calls within the PO flow - Ensure `promptForSupplier()` returning `null` triggers a return to the navigation loop - Update PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit **Manufacturing Orders Flow (`src/index.ts` lines ~276-356):** - Update the MO flow section to handle cancellation by returning/continuing - Ensure `promptForSalesOrders()` returning empty/null triggers return to navigation loop - Ensure `promptForShortageVariants()` cancellation returns to navigation loop - Update `promptForMoCreation()` behavior so its early returns propagate back to the navigation loop **Exit Messages Cleanup (`src/ui/prompts.ts`):** - Review all `outro("Cancelled.")` calls at non-root levels - Remove these calls or replace with `log.info("Returning to menu...")` to indicate navigation behavior - Keep `outro("Cancelled.")` only for mode selection cancellation in `selectMode()` (line 163) - Change `outro("Aborted.")` messages (lines 637, 223) to indicate return to menu rather than program exit =============================================================================== Task: 3 **Goal:** Preserve critical exit points and handle edge cases to ensure the navigation loop doesn't break existing functionality. **API Key Authentication (`src/ui/prompts.ts` line 132, `src/index.ts` line 120):** - Keep the `process.exit(1)` call in `resolveApiKey()` unchanged - Keep the early return behavior when API key resolution fails in `src/index.ts` - Authentication must succeed before the navigation loop begins **Pagination Behavior (`src/ui/prompts.ts` lines 25-87):** - Review `pagedMultiSelect()` to verify it works correctly within the new navigation structure - Ensure cancelling page continuation breaks the loop and returns accumulated selections as before - Cancelling page selection itself (line 59) returns null, which should now propagate up to return to mode selection **Completion Messaging:** - After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...") - Use `@clack/prompts` log utilities for consistent styling - Prevents jarring immediate return to menu after successful operations **Non-Interactive Mode:** - Add a check to detect when mode is provided via CLI arguments - Skip the navigation loop in non-interactive/scripted mode—execute the mode once and exit - Preserves the ability to use the CLI in automated pipelines ``` </details> <details> <summary><b>💡 Iterate on the plan with: <code>@coderabbitai &lt;feedback&gt;</code> </b></summary> ``` Example Feedback - `@coderabbitai` You can skip phase 3. Add a simple unit test case for phase 2. - `@coderabbitai` For design choice 1 go ahead with option 3 and replan. ``` </details> --- 💬 Have feedback or questions? Drop into our [discord](https://discord.gg/coderabbit)! <!-- <agentComponentType>plan-edits</agentComponentType> --> <!-- <rawResChunk><planningResult>## Coding Plan ### Summary - Wrap the main execution in `index.ts` with a navigation loop that continuously presents mode selection until the user explicitly cancels at that level - Change internal cancellation handling to return control to the loop rather than exit the program - Preserve the existing exit behavior for authentication failures and non-interactive execution - Successful completion will also return to mode selection, enabling multi-operation sessions <details> <summary><b>Design Choices</b></summary> <details> <summary><b>Design Choice 1: Should successful completion of a mode also return to menu?</b></summary> **Options Considered:** 1. Return to menu after both cancel and successful completion (consistent experience, allows multiple operations per session) 2. Return to menu only on cancel; exit on successful completion (matches current success path) **Chosen Option:** 1 **Rationale:** Provides a more consistent user experience where the CLI acts as an interactive session rather than a one-shot tool, and aligns with the spirit of improved navigation. </details> </details> <b>💡 User Tips</b> Regenerate the plan with different choices with `@coderabbitai <feedback>`. ## Implementation Steps ### Phase 1: Establish Main Navigation Loop This phase restructures the main execution flow to support returning to mode selection after any mode completes or is cancelled. <details> <summary><b>Task 1: Wrap Mode Execution in Navigation Loop</b></summary> Restructure the main command handler to continuously loop through mode selection and execution until the user explicitly cancels at the mode selection prompt. - Modify `src/index.ts` to wrap the mode execution logic (lines ~140-356) in a `while (true)` loop - Move `resolveSettingsWithPrompts()` call inside the loop so mode selection is re-presented after each mode completes - When `resolveSettingsWithPrompts()` returns `null` (user cancelled at mode selection), break the loop and exit cleanly - When a mode execution completes (success or internal cancel), continue the loop to return to mode selection </details> <details> <summary><b>Task 2: Adjust Settings Flow Integration</b></summary> Ensure the settings flow integrates cleanly with the new navigation loop. - Review `src/ui/settingsFlow.ts` to confirm its existing settings loop continues to work correctly within the outer navigation loop - The existing `while (mode === "settings")` loop should function as before, with the outer loop handling production modes </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` **Goal:** Restructure the main execution flow in `src/index.ts` to support a continuous navigation loop that returns to mode selection after operations complete or are cancelled. **Changes to `src/index.ts`:** - Wrap the mode execution logic (lines ~140-356) in a `while (true)` loop - Move the `resolveSettingsWithPrompts()` call inside the loop so mode selection is re-presented after each iteration - When `resolveSettingsWithPrompts()` returns `null` (indicating user cancelled at mode selection), break the loop and exit cleanly - When a mode execution completes (either successfully or due to internal cancellation), continue the loop to return to mode selection **Settings Flow Integration:** - Review `src/ui/settingsFlow.ts` to ensure its existing `while (mode === "settings")` loop functions correctly within the new outer navigation loop - The settings flow should continue to work as before, with the outer loop handling production modes (purchase orders and manufacturing orders) ``` </details> ### Phase 2: Update Cancellation Handling in Mode Flows This phase changes how cancellation is handled within each mode so that it returns control to the navigation loop rather than exiting the program. <details> <summary><b>Task 1: Update Purchase Orders Flow Cancellation</b></summary> Modify the PO creation flow to gracefully return on cancellation instead of exiting. - In `src/index.ts`, update the PO flow section (lines ~157-272) to handle cancellation by returning/continuing instead of exiting - Remove or relocate `outro("Cancelled.")` calls within the PO flow since the navigation loop will handle the return to menu - Ensure `promptForSupplier()` returning `null` triggers a return to the navigation loop, not program exit - Update the PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit </details> <details> <summary><b>Task 2: Update Manufacturing Orders Flow Cancellation</b></summary> Modify the MO creation flows (sales_orders and general modes) to return on cancellation. - In `src/index.ts`, update the MO flow section (lines ~276-356) to handle cancellation by returning/continuing - Ensure `promptForSalesOrders()` returning empty/null triggers return to navigation loop - Ensure `promptForShortageVariants()` cancellation returns to navigation loop - Update `promptForMoCreation()` behavior so its early returns propagate back to the navigation loop </details> <details> <summary><b>Task 3: Clean Up Redundant Exit Messages</b></summary> Remove cancellation messages that would now be redundant or confusing given the new navigation behavior. - Review `src/ui/prompts.ts` for `outro("Cancelled.")` calls that occur at non-root levels - Either remove these calls or replace with a brief indication of returning to menu (e.g., `log.info("Returning to menu...")`) - Keep the `outro("Cancelled.")` message only for the mode selection cancellation in `selectMode()` (line 163) - Consider changing `outro("Aborted.")` messages (lines 637, 223) to indicate return to menu rather than program exit </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` **Goal:** Update cancellation handling across mode flows to return control to the navigation loop instead of exiting the program. **Purchase Orders Flow (`src/index.ts` lines ~157-272):** - Change cancellation handling to return/continue instead of exiting - Remove or relocate `outro("Cancelled.")` calls within the PO flow - Ensure `promptForSupplier()` returning `null` triggers a return to the navigation loop - Update PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit **Manufacturing Orders Flow (`src/index.ts` lines ~276-356):** - Update the MO flow section to handle cancellation by returning/continuing - Ensure `promptForSalesOrders()` returning empty/null triggers return to navigation loop - Ensure `promptForShortageVariants()` cancellation returns to navigation loop - Update `promptForMoCreation()` behavior so its early returns propagate back to the navigation loop **Exit Messages Cleanup (`src/ui/prompts.ts`):** - Review all `outro("Cancelled.")` calls at non-root levels - Remove these calls or replace with `log.info("Returning to menu...")` to indicate navigation behavior - Keep `outro("Cancelled.")` only for mode selection cancellation in `selectMode()` (line 163) - Change `outro("Aborted.")` messages (lines 637, 223) to indicate return to menu rather than program exit ``` </details> ### Phase 3: Preserve Critical Exit Points and Handle Edge Cases This phase ensures that certain critical paths still exit appropriately and handles edge cases in the navigation flow. <details> <summary><b>Task 1: Preserve API Key Authentication Exit Behavior</b></summary> Maintain the current exit behavior for API key resolution since this occurs before any navigation context exists. - Keep the `process.exit(1)` call in `resolveApiKey()` (line 132 in prompts.ts) unchanged - Keep the early return behavior when API key resolution fails in `src/index.ts` (line 120) - This authentication step must succeed before any navigation loop can begin </details> <details> <summary><b>Task 2: Verify Pagination Behavior</b></summary> Ensure the existing pagination logic in `pagedMultiSelect()` works correctly within the new navigation structure. - Review `pagedMultiSelect()` in `src/ui/prompts.ts` (lines 25-87) - The existing behavior where cancelling page continuation breaks the loop and returns accumulated selections should continue to work - Cancelling the page selection itself (line 59) already returns null, which will now propagate up to return to mode selection </details> <details> <summary><b>Task 3: Update Completion Messaging</b></summary> Add appropriate messaging when returning to mode selection after a completed or cancelled operation. - After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...") - This prevents jarring immediate return to menu after a successful operation - Consider using `@clack/prompts` log utilities for consistent styling </details> <details> <summary><b>Task 4: Handle Non-Interactive Mode</b></summary> Ensure non-interactive mode (when CLI args specify mode directly) still behaves correctly. - When mode is provided via CLI arguments, the navigation loop should execute that mode once and exit (current behavior) - Add a check to skip the navigation loop when running in non-interactive/scripted mode - This preserves the ability to use the CLI in automated pipelines </details> <details> <summary><b>🤖 Prompt for AI agents</b></summary> ``` **Goal:** Preserve critical exit points and handle edge cases to ensure the navigation loop doesn't break existing functionality. **API Key Authentication (`src/ui/prompts.ts` line 132, `src/index.ts` line 120):** - Keep the `process.exit(1)` call in `resolveApiKey()` unchanged - Keep the early return behavior when API key resolution fails in `src/index.ts` - Authentication must succeed before the navigation loop begins **Pagination Behavior (`src/ui/prompts.ts` lines 25-87):** - Review `pagedMultiSelect()` to verify it works correctly within the new navigation structure - Ensure cancelling page continuation breaks the loop and returns accumulated selections as before - Cancelling page selection itself (line 59) returns null, which should now propagate up to return to mode selection **Completion Messaging:** - After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...") - Use `@clack/prompts` log utilities for consistent styling - Prevents jarring immediate return to menu after successful operations **Non-Interactive Mode:** - Add a check to detect when mode is provided via CLI arguments - Skip the navigation loop in non-interactive/scripted mode—execute the mode once and exit - Preserves the ability to use the CLI in automated pipelines ``` </details> <details> <summary><b>Research</b></summary> The katana-mo-cli is a Manufacturing Order/Purchase Order creation tool built with `gunshi` for CLI argument parsing and `@clack/prompts` for interactive prompts. The current navigation is linear and forward-only: mode selection → data fetching → mode-specific prompts → exit. Cancellation (via `isCancel()`) is handled at 21 locations across `prompts.ts` and `index.ts`, with most returning `null` which propagates up and causes program exit. There is no navigation stack or state machine—the settings menu is the only flow that loops back to mode selection via a `while` loop in `settingsFlow.ts`. Data fetching happens after mode selection and is not cached. </details> --- ### 🚀 Next Steps <details> <summary><b>🤖 All AI agent prompts combined</b></summary> ``` Task: 1 **Goal:** Restructure the main execution flow in `src/index.ts` to support a continuous navigation loop that returns to mode selection after operations complete or are cancelled. **Changes to `src/index.ts`:** - Wrap the mode execution logic (lines ~140-356) in a `while (true)` loop - Move the `resolveSettingsWithPrompts()` call inside the loop so mode selection is re-presented after each iteration - When `resolveSettingsWithPrompts()` returns `null` (indicating user cancelled at mode selection), break the loop and exit cleanly - When a mode execution completes (either successfully or due to internal cancellation), continue the loop to return to mode selection **Settings Flow Integration:** - Review `src/ui/settingsFlow.ts` to ensure its existing `while (mode === "settings")` loop functions correctly within the new outer navigation loop - The settings flow should continue to work as before, with the outer loop handling production modes (purchase orders and manufacturing orders) =============================================================================== Task: 2 **Goal:** Update cancellation handling across mode flows to return control to the navigation loop instead of exiting the program. **Purchase Orders Flow (`src/index.ts` lines ~157-272):** - Change cancellation handling to return/continue instead of exiting - Remove or relocate `outro("Cancelled.")` calls within the PO flow - Ensure `promptForSupplier()` returning `null` triggers a return to the navigation loop - Update PO prefix input cancellation (line 214) and final confirmation cancellation (line 223) to return instead of exit **Manufacturing Orders Flow (`src/index.ts` lines ~276-356):** - Update the MO flow section to handle cancellation by returning/continuing - Ensure `promptForSalesOrders()` returning empty/null triggers return to navigation loop - Ensure `promptForShortageVariants()` cancellation returns to navigation loop - Update `promptForMoCreation()` behavior so its early returns propagate back to the navigation loop **Exit Messages Cleanup (`src/ui/prompts.ts`):** - Review all `outro("Cancelled.")` calls at non-root levels - Remove these calls or replace with `log.info("Returning to menu...")` to indicate navigation behavior - Keep `outro("Cancelled.")` only for mode selection cancellation in `selectMode()` (line 163) - Change `outro("Aborted.")` messages (lines 637, 223) to indicate return to menu rather than program exit =============================================================================== Task: 3 **Goal:** Preserve critical exit points and handle edge cases to ensure the navigation loop doesn't break existing functionality. **API Key Authentication (`src/ui/prompts.ts` line 132, `src/index.ts` line 120):** - Keep the `process.exit(1)` call in `resolveApiKey()` unchanged - Keep the early return behavior when API key resolution fails in `src/index.ts` - Authentication must succeed before the navigation loop begins **Pagination Behavior (`src/ui/prompts.ts` lines 25-87):** - Review `pagedMultiSelect()` to verify it works correctly within the new navigation structure - Ensure cancelling page continuation breaks the loop and returns accumulated selections as before - Cancelling page selection itself (line 59) returns null, which should now propagate up to return to mode selection **Completion Messaging:** - After successful MO/PO creation, add a brief pause or message before returning to mode selection (e.g., "Press enter to continue...") - Use `@clack/prompts` log utilities for consistent styling - Prevents jarring immediate return to menu after successful operations **Non-Interactive Mode:** - Add a check to detect when mode is provided via CLI arguments - Skip the navigation loop in non-interactive/scripted mode—execute the mode once and exit - Preserves the ability to use the CLI in automated pipelines ``` </details> <details> <summary><b>💡 Iterate on the plan with: <code>@coderabbitai &lt;feedback&gt;</code> </b></summary> ``` Example Feedback - `@coderabbitai` You can skip phase 3. Add a simple unit test case for phase 2. - `@coderabbitai` For design choice 1 go ahead with option 3 and replan. ``` </details> --- 💬 Have feedback or questions? Drop into our [discord](https://discord.gg/coderabbit)!</planningResult></rawResChunk> -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/katana#4
No description provided.