Repository navigation
tui: extract apply_prompt_mode helper for prompt selection - #202
Merged
Merged
Conversation
Replace the four duplicated prompt-mode blocks (/prompt, /review, chain transitions, dot commands) with a single apply_prompt_mode(name, context, permission) helper that selects the prompt, strips its %%mode= directive, and applies the directive to the permission checker. The helper returns a PromptModeOutcome so /prompt keeps its user-facing feedback, and apply_current_prompt_mode now shares the same directive-application logic. Implements item 3 of 'Control flow and duplication' from gi-dellav#186.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements item 3 of Control flow and duplication from #186: Extract a single
apply_prompt_mode(name, context, permission)helper to replace the duplicated prompt-mode blocks.Changes
apply_prompt_mode(name, context, permission)helper insrc/ui/mod.rs: selects the prompt by name, strips its%%mode=directive from the stored content, and applies the directive to the permission checker (last_user_moderestores the user-selected mode).PromptModeOutcomeenum (None/RestoredUserMode/Applied(mode)) so/promptkeeps its exact user-facing feedback without re-parsing the prompt./prompt <name>insrc/ui/slash/content.rs/reviewinsrc/ui/slash/review.rsrun_chain_transition) insrc/ui/app.rssrc/ui/app.rs(theapply_prompt_from_contentmethod is gone)apply_current_prompt_mode(worktree reload path) now shares the same innerapply_mode_directivelogic instead of its own copy.No behavior change intended: same stripping rules, same mode semantics, same
/promptmessages.Tests
src/tests/prompt_mode_tests.rs(6 tests): no-directive passthrough, directive strip + mode applied,last_user_moderestore (incl.user_modenot clobbered by prompt modes), unknown prompt no-op, unrecognized mode name, and no-permission-checker path.cargo fmt, fullcargo test(614 passed), andcargo install --path . --debugall green.Follow-up note (out of scope here)
src/main.rs:754-772tries to apply the%%mode=directive at startup by re-parsingcontext.current_prompt— but the directive was already stripped when the prompt was stored (src/main.rs:659-664), so the default prompt's mode is never actually applied at startup (e.g.default_prompt = "plan"does not enableplanwrite). This contradictsdocs/CONFIG.md'sdefault_promptdescription. I left it untouched to keep this PR a pure refactor; happy to send a follow-up PR fixing startup mode application using this helper.