issues/completed/10-032-fix-shared-flag-prefix-collision-in-tui-sync.md
10-032: Fix Shared Flag Prefix Collision in TUI Command Sync
Current Behavior
When moving the cursor from the command preview to another menu item (e.g., "Run Selected Stages"), checkboxes with space-separated flag values (like --force-stage 9) get incorrectly deselected.
Reproduction steps:
- Open
./run.sh -I(interactive TUI mode) - Enable "9. Generate HTML" stage
- Enable "Force regenerate" checkbox for stage 9 (adds
--force-stage 9to command) - Navigate cursor to the command preview
- Navigate cursor away from command preview to "Run Selected Stages"
- Observe: Stage 9's force regenerate checkbox is now deselected
Root Cause
The build_flag_lookup() function in menu.lua stores both full flags and their prefixes:
lookup["--force-stage 9"]=force_generate_htmllookup["--force-stage"]=force_generate_html
However, ALL --force-stage N items share the same prefix --force-stage. Since items are processed in order, the prefix key gets overwritten by each subsequent item. The last item (--force-stage 10 → force_generate_index) "wins" the prefix.
When sync_checkboxes_from_command() parses the command text ./run.sh --force-stage 9:
- The command is tokenized as separate tokens:
--force-stage,9 - Token
--force-stageis looked up → findsforce_generate_index(wrong item!) found_flags["force_generate_index"]= true- Token
9is treated as unrecognized (not consumed as part of the flag) force_generate_htmlis never found, so it gets unchecked (line 1413)
Intended Behavior
When parsing a command that contains --force-stage 9, the correct checkbox (force_generate_html) should be marked as found, preserving its checked state.
Suggested Implementation Steps
- In
sync_checkboxes_from_command(), after finding a prefix match, check if combining with the next token creates a full flag match - If a full flag match exists and has a different item_id, use that instead
- Skip the value token since it's now part of the flag
Implementation (Completed)
Added check in sync_checkboxes_from_command() (lines 1308-1321):
-- Issue 10-008b: Check if combining with next token creates a full flag match
-- This handles flags like "--force-stage 9" where the prefix "--force-stage"
-- might match the wrong item due to multiple items sharing the same prefix.
-- We prioritize the full match (e.g., "--force-stage 9") over prefix match.
if flag_info and i < #tokens then
local next_token = tokens[i + 1]
local combined_flag = token.text .. " " .. next_token.text
local full_flag_info = flag_lookup[combined_flag]
if full_flag_info then
-- Full flag match found - use it instead of prefix match
flag_info = full_flag_info
i = i + 1 -- Skip the value token since it's part of the flag
end
end
Related Documents
menu.lua- TUI library with bidirectional command syncrun.sh- Uses TUI for interactive pipeline configuration- Issue 10-016 - Introduced per-stage force regeneration options
Status
IMPLEMENTED - Fix applied to /home/ritz/programming/ai-stuff/scripts/libs/menu.lua
Notes
- This fix affects all checkbox-type items with space-separated flag values
- Coloring of the value token (e.g.,
9) is not addressed - this is a cosmetic issue - The prefix lookup is still useful for flag-type items (which consume the next token as their value)