Skip to content

tui: extract apply_prompt_mode helper for prompt selection - #202

Merged
gi-dellav merged 1 commit into
gi-dellav:mainfrom
wowi42:refactor/apply-prompt-mode
Jul 21, 2026
Merged

gi-dellav merged 1 commit into
gi-dellav:mainfrom
wowi42:refactor/apply-prompt-mode

Conversation

@wowi42

@wowi42 wowi42 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

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

  • New apply_prompt_mode(name, context, permission) helper in src/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_mode restores the user-selected mode).
  • The helper returns a new PromptModeOutcome enum (None / RestoredUserMode / Applied(mode)) so /prompt keeps its exact user-facing feedback without re-parsing the prompt.
  • Replaced the four duplicated blocks:
    • /prompt <name> in src/ui/slash/content.rs
    • /review in src/ui/slash/review.rs
    • chain transitions (run_chain_transition) in src/ui/app.rs
    • dot commands in src/ui/app.rs (the apply_prompt_from_content method is gone)
  • apply_current_prompt_mode (worktree reload path) now shares the same inner apply_mode_directive logic instead of its own copy.

No behavior change intended: same stripping rules, same mode semantics, same /prompt messages.

Tests

  • New src/tests/prompt_mode_tests.rs (6 tests): no-directive passthrough, directive strip + mode applied, last_user_mode restore (incl. user_mode not clobbered by prompt modes), unknown prompt no-op, unrecognized mode name, and no-permission-checker path.
  • cargo fmt, full cargo test (614 passed), and cargo install --path . --debug all green.

Follow-up note (out of scope here)

src/main.rs:754-772 tries to apply the %%mode= directive at startup by re-parsing context.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 enable planwrite). This contradicts docs/CONFIG.md's default_prompt description. 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.

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.
@gi-dellav
gi-dellav merged commit d3abfde into gi-dellav:main Jul 21, 2026
12 checks passed
@wowi42
wowi42 deleted the refactor/apply-prompt-mode branch July 21, 2026 17:12
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