Skip to content

feat(tui): add prompt enhancement via ctrl+x p#17502

Open
rjamestaylor wants to merge 1 commit intoanomalyco:devfrom
rjamestaylor:feat/enhance-prompt
Open

feat(tui): add prompt enhancement via ctrl+x p#17502
rjamestaylor wants to merge 1 commit intoanomalyco:devfrom
rjamestaylor:feat/enhance-prompt

Conversation

@rjamestaylor
Copy link

@rjamestaylor rjamestaylor commented Mar 14, 2026

Issue for this PR

Closes #10237

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a prompt_enhance command to the TUI. With text in the input field, pressing <leader>p (default: ctrl+x p) sends the draft to a lightweight model that rewrites it for clarity, then replaces the input with the result. Pressing esc immediately reverts to the original, or cancels an in-flight request.

Changes:

  • agent.ts — new enhance built-in agent and Agent.enhancePrompt(). Uses the provider's small model by default; falls back to the session model. Last 5 user turns are passed as context so references like "fix that bug" resolve correctly.
  • prompt/enhance.txt — system prompt for the enhancer.
  • config.tsprompt_enhance keybind (default <leader>p).
  • prompt/index.tsx — wires up the command, loading state, esc-to-revert, and footer hints.
  • Docs: tui.mdx, agents.mdx, keybinds.mdx updated.

The enhance agent is hidden, excluded from Agent.defaultAgent(), and has all tool access denied (text-in/text-out only). Model is configurable via agent.enhance.model in opencode.json.

How did you verify your code works?

  • bun test test/agent-enhance.test.ts — 9 tests pass covering agent definition, permission rules, config overrides, and keybind defaults.
  • bun typecheck — no errors.
  • Manual testing: triggered enhancement with Anthropic (Haiku auto-selected as small model) and with a local Qwen model via Ollama. Tested esc-to-revert, esc-to-cancel-in-flight, provider-not-found error path, and rate-limit error path.

Screenshots / recordings

Enhance Prompt Demo
https://github.com/user-attachments/assets/4c9955c5-2e8b-401c-b1e3-05973ac32b88

Input field with ctrl+x p hint in footer
1-oc-prompt-with-leader-p-hint

"Enhance prompt" entry in the command menu
1 1-command-screen-menu

Enhancement in progress (Claude Haiku 4.5)
2-oc-enhance-with-haiku

Enhancement in progress (qwen3.5:35b via Ollama)
2 1-oc-enhance-with-qwen35

Enhanced result with esc-to-revert hint
3-oc-enhanced-esc-to-revert

Error: provider model not found
4-oc-enhanced-error-provider-not-found

Error: rate limit / retry exhausted
4 1-oc-enhance-failed-message

Enhancement cancelled via esc
4 2-oc-enhance-process-interrupted

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Press <leader>p (default ctrl+x p) in the TUI to have a small model
rewrite and expand the current prompt before submitting. Enhanced text
replaces the input; press esc to immediately revert.

- Add built-in `enhance` agent (hidden, primary mode, deny-all tools,
  temperature 0.3) with a dedicated system prompt
- Add `Agent.enhancePrompt()` resolving model via getSmallModel() fallback
- Add `prompt_enhance` keybind (default <leader>p) to Config.Keybinds
- Wire prompt component: abort-safe async flow, preEnhance undo field,
  onModel callback for real-time "enhancing (model-name)" footer display
- Add 9 unit tests covering agent properties, permissions, model/
  temperature config overrides, and keybind defaults
- Document in tui.mdx, agents.mdx, and keybinds.mdx

Closes anomalyco#10237
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 14, 2026
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 14, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

[FEATURE]: Context-Aware Prompt Enhancement

1 participant