Skip to content

Commit f1addf4

Browse files
anandgupta42claude
andcommitted
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>
1 parent 4f6c176 commit f1addf4

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

packages/opencode/src/altimate/enhance-prompt.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,52 @@
22
import { Provider } from "@/provider/provider"
33
import { LLM } from "@/session/llm"
44
import { Agent } from "@/agent/agent"
5+
import { Config } from "@/config/config"
56
import { Log } from "@/util/log"
67
import { MessageV2 } from "@/session/message-v2"
78

89
const log = Log.create({ service: "enhance-prompt" })
910

10-
const ENHANCE_SYSTEM_PROMPT = `You are a prompt enhancement specialist for a data engineering coding agent.
11+
// Research-backed enhancement prompt based on:
12+
// - AutoPrompter (arxiv 2504.20196): 5 missing info categories that cause 27% lower edit correctness
13+
// - Meta-prompting best practices: clear role, structural scaffolding, few-shot examples
14+
// - KiloCode's enhance-prompt implementation: lightweight model, preserve intent, no wrapping
15+
const ENHANCE_SYSTEM_PROMPT = `You are a prompt rewriter for a data engineering coding agent. The agent can read/write files, run SQL, manage dbt models, inspect schemas, and execute shell commands.
1116
12-
Your job is to take a user's rough prompt and rewrite it into a clearer, more specific version that will produce better results from the coding agent.
17+
Your task: rewrite the user's rough prompt into a clearer version that will produce better results. Reply with ONLY the enhanced prompt — no explanations, no wrapping in quotes or code fences.
1318
14-
Rules:
15-
- Reply with ONLY the enhanced prompt text — no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes
16-
- Preserve the user's intent exactly — do not add requirements they didn't ask for
17-
- Make implicit requirements explicit (e.g. if they say "fix the bug", specify what kind of verification to do)
18-
- Add structure when the prompt is vague (e.g. "look at X first, then modify Y")
19-
- Keep the enhanced prompt concise — longer is not better
20-
- If the original prompt is already clear and specific, return it unchanged
21-
- Do not wrap your response in markdown code fences or quotes`
19+
## What to improve
20+
21+
Research shows developer prompts commonly lack these five categories of information. Add them when missing:
22+
23+
1. **Specifics** — Add concrete details the agent needs: table names, column names, file paths, SQL dialects, error messages. If the user references "the model" or "the table", keep the reference but clarify what the agent should look for.
24+
2. **Action plan** — When the prompt is vague ("fix this"), add explicit steps: investigate first, then modify, then verify. Structure as a logical sequence.
25+
3. **Scope** — Clarify what files, models, or queries are in scope. If ambiguous, instruct the agent to identify the scope first.
26+
4. **Verification** — Add a verification step when the user implies correctness matters (fixes, migrations, refactors). E.g. "run the query to confirm results" or "run dbt test after changes".
27+
5. **Intent clarification** — When the request could be interpreted multiple ways, pick the most likely interpretation and make it explicit.
28+
29+
## Rules
30+
31+
- Preserve the user's intent exactly — never add requirements they didn't ask for
32+
- Keep it concise — a good enhancement adds 1-3 sentences, not paragraphs
33+
- If the prompt is already clear and specific, return it unchanged
34+
- Write in the same tone/style as the user (casual stays casual, technical stays technical)
35+
- Never add generic filler like "please ensure best practices" or "follow coding standards"
36+
- Do not mention yourself or the enhancement process
37+
38+
## Examples
39+
40+
User: "fix the failing test"
41+
Enhanced: "Investigate the failing test — run the test suite first to identify which test is failing and why, then examine the relevant source code, apply a fix, and re-run the test to confirm it passes."
42+
43+
User: "add a created_at column to the users model"
44+
Enhanced: "Add a created_at timestamp column to the users dbt model. Update the SQL definition and the schema.yml entry. Use the appropriate timestamp type for the target warehouse."
45+
46+
User: "why is this query slow"
47+
Enhanced: "Analyze why the query is slow. Run EXPLAIN/query profile to identify bottlenecks (full table scans, missing indexes, expensive joins). Suggest specific optimizations based on the findings."
48+
49+
User: "migrate this from snowflake to bigquery"
50+
Enhanced: "Migrate the SQL from Snowflake dialect to BigQuery dialect. Convert Snowflake-specific functions (e.g. DATEADD, IFF, QUALIFY) to BigQuery equivalents. Preserve the query logic and verify the translated query is syntactically valid."`
2251

2352
export function clean(text: string) {
2453
return text
@@ -28,6 +57,15 @@ export function clean(text: string) {
2857
.trim()
2958
}
3059

60+
/**
61+
* Check if auto-enhance is enabled in config.
62+
* Defaults to false — user must explicitly opt in.
63+
*/
64+
export async function isAutoEnhanceEnabled(): Promise<boolean> {
65+
const cfg = await Config.get()
66+
return cfg.experimental?.auto_enhance_prompt === true
67+
}
68+
3169
export async function enhancePrompt(text: string): Promise<string> {
3270
if (!text.trim()) return text
3371

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { useKV } from "../../context/kv"
3535
import { useTextareaKeybindings } from "../textarea-keybindings"
3636
import { DialogSkill } from "../dialog-skill"
3737
// altimate_change start - import prompt enhancement
38-
import { enhancePrompt } from "@/altimate/enhance-prompt"
38+
import { enhancePrompt, isAutoEnhanceEnabled } from "@/altimate/enhance-prompt"
3939
// altimate_change end
4040

4141
export type PromptProps = {
@@ -630,6 +630,20 @@ export function Prompt(props: PromptProps) {
630630
// Filter out text parts (pasted content) since they're now expanded inline
631631
const nonTextParts = store.prompt.parts.filter((part) => part.type !== "text")
632632

633+
// altimate_change start - auto-enhance prompt before sending (if enabled)
634+
// Only enhance normal prompts, not shell commands or slash commands
635+
if (store.mode === "normal" && !inputText.startsWith("/")) {
636+
try {
637+
const autoEnhance = await isAutoEnhanceEnabled()
638+
if (autoEnhance) {
639+
inputText = await enhancePrompt(inputText)
640+
}
641+
} catch {
642+
// Enhancement failure should never block prompt submission
643+
}
644+
}
645+
// altimate_change end
646+
633647
// Capture mode before it gets reset
634648
const currentMode = store.mode
635649
const variant = local.model.variant.current()

packages/opencode/src/config/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,14 @@ export namespace Config {
12291229
.positive()
12301230
.optional()
12311231
.describe("Timeout in milliseconds for model context protocol (MCP) requests"),
1232+
// altimate_change start - auto-enhance prompt config
1233+
auto_enhance_prompt: z
1234+
.boolean()
1235+
.optional()
1236+
.describe(
1237+
"Automatically enhance prompts with AI before sending (default: false). Uses a small model to rewrite rough prompts into clearer versions.",
1238+
),
1239+
// altimate_change end
12321240
})
12331241
.optional(),
12341242
})

0 commit comments

Comments
 (0)