Commit c189028
feat: add AI-powered prompt enhancement (#144)
* feat: add prompt enhancement feature
Add AI-powered prompt enhancement that rewrites rough user prompts into
clearer, more specific versions before sending to the main model.
- Add `enhancePrompt()` utility using a small/cheap model to polish prompts
- Register `prompt.enhance` TUI command with `<leader>i` keybind
- Show "enhance" hint in the bottom bar alongside agents/commands
- Add `prompt_enhance` keybind to config schema
- Add unit tests for the `clean()` text sanitization function
Inspired by KiloCode's prompt enhancement feature.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat: improve enhancement prompt with research-backed approach and add auto-enhance config
- Rewrite system prompt based on AutoPrompter research (5 missing info
categories: specifics, action plan, scope, verification, intent)
- Add few-shot examples for data engineering tasks (dbt, SQL, migrations)
- Add `experimental.auto_enhance_prompt` config flag (default: false)
- Auto-enhance normal prompts on submit when enabled (skips shell/slash)
- Export `isAutoEnhanceEnabled()` for config-driven behavior
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address code review findings for prompt enhancement
- Add 15s timeout via `AbortController` to prevent indefinite hangs
- Extract `ENHANCE_ID` constant and document synthetic `as any` casts
- Fix `clean()` regex to match full-string code fences only (avoids
stripping inner code blocks)
- Export `stripThinkTags()` as separate utility for testability
- Move auto-enhance before extmark expansion (prevents sending
expanded paste content to the small model)
- Add toast feedback and error logging for auto-enhance path
- Update `store.prompt.input` after enhancement so history is accurate
- Add outer try/catch with logging to `enhancePrompt()`
- Expand tests from 9 to 30: `stripThinkTags()`, `clean()` edge
cases, combined pipeline tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: handle unclosed `<think>` tags from truncated model output
When the small model hits its token limit mid-generation, `<think>` tags
may not have a closing `</think>`. The previous regex required a closing
tag, which would leak the entire reasoning block into the enhanced prompt.
Now `stripThinkTags()` matches both closed and unclosed think blocks.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address remaining review findings — history, debounce, tests
- Fix history storing original text instead of enhanced text by passing
`inputText` explicitly to `history.append()` instead of spreading
`store.prompt` which may contain stale state
- Add concurrency guard (`enhancingInProgress` flag) to prevent multiple
concurrent auto-enhance LLM calls from rapid submissions
- Consolidate magic string into `ENHANCE_NAME` constant used across
agent name, user agent, log service, and ID derivation
- Add justifying comment for `as any` cast on synthetic IDs explaining
why branded types are safely bypassed
- Add `isAutoEnhanceEnabled()` tests (5 cases): config absent, present
but missing flag, false, true, undefined
- Add `enhancePrompt()` tests (10 cases): empty input, whitespace,
successful enhancement, think tag stripping, code fence stripping,
stream.text failure, stream init failure, empty LLM response, think
tags with no content, combined pipeline
Test count: 32 -> 48
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address Sentry findings — stream consumption and race condition
- Explicitly consume `stream.fullStream` before awaiting `stream.text`
to prevent potential hangs from Vercel AI SDK stream not being drained
- Add race condition guard to manual enhance command: if user edits the
prompt while enhancement is in-flight, discard the stale result
- Add same guard to auto-enhance path in `submit()` for consistency
- Update LLM mock to include `fullStream` async iterable
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 0c92216 commit c189028
File tree
4 files changed
+564
-0
lines changed- packages/opencode
- src
- altimate
- cli/cmd/tui/component/prompt
- config
- test/altimate
4 files changed
+564
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
Lines changed: 83 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
194 | 198 | | |
195 | 199 | | |
196 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
197 | 248 | | |
198 | 249 | | |
199 | 250 | | |
| |||
564 | 615 | | |
565 | 616 | | |
566 | 617 | | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
567 | 644 | | |
568 | 645 | | |
569 | 646 | | |
| |||
653 | 730 | | |
654 | 731 | | |
655 | 732 | | |
| 733 | + | |
656 | 734 | | |
657 | 735 | | |
658 | 736 | | |
| |||
1155 | 1233 | | |
1156 | 1234 | | |
1157 | 1235 | | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
1158 | 1241 | | |
1159 | 1242 | | |
1160 | 1243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
866 | 866 | | |
867 | 867 | | |
868 | 868 | | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
869 | 872 | | |
870 | 873 | | |
871 | 874 | | |
| |||
1226 | 1229 | | |
1227 | 1230 | | |
1228 | 1231 | | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1229 | 1240 | | |
1230 | 1241 | | |
1231 | 1242 | | |
| |||
0 commit comments