From 28c201921fa52e470dd2e85f67bef97b5548a430 Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Thu, 19 Nov 2026 10:22:51 +0530 Subject: [PATCH 1/2] fix(prompt): the agent keeps the user's changes and asks when intent is unclear When a test or build fails because of a change the user made, the agent now fixes the test or callers, or asks, instead of reverting the change. Adds the rule to the anthropic and builder prompts. Co-Authored-By: Claude Sonnet 5.5 --- .../src/altimate/prompts/builder/core.txt | 1 + .../opencode/src/session/prompt/anthropic.txt | 1 + .../opencode/test/altimate/prompt-identity.ts | 6 +++--- .../altimate/prompt-keep-user-changes.test.ts | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 packages/opencode/test/altimate/prompt-keep-user-changes.test.ts diff --git a/packages/opencode/src/altimate/prompts/builder/core.txt b/packages/opencode/src/altimate/prompts/builder/core.txt index cd5d0e5afc..05575f2068 100644 --- a/packages/opencode/src/altimate/prompts/builder/core.txt +++ b/packages/opencode/src/altimate/prompts/builder/core.txt @@ -5,3 +5,4 @@ You are altimate-code in builder mode — a data engineering agent specializing 1. **Understand before writing** — Read existing code, schemas, and actual data before writing any SQL. Never write blind. 2. **Follow conventions** — Match the project's naming patterns, layer structure, and style. Read 2-3 similar files first. 3. **Validate the output** — A task isn't done until the output data looks right. Check row counts, sample values, and column names. +4. **Keep the user's changes** — If a test or build fails because of a change the user made, fix the test or the callers, or ask; never revert the user's change. If it is unclear whether a change was intentional, ask before undoing it. diff --git a/packages/opencode/src/session/prompt/anthropic.txt b/packages/opencode/src/session/prompt/anthropic.txt index 25b1f711ee..2bf7e49b44 100644 --- a/packages/opencode/src/session/prompt/anthropic.txt +++ b/packages/opencode/src/session/prompt/anthropic.txt @@ -73,6 +73,7 @@ I've found some existing telemetry code. Let me mark the first todo as in_progre The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended: - - Use the TodoWrite tool to plan the task if required +- Keep the user's existing changes. If a test or build fails because of a change the user made, fix the test or the callers, or ask the user; never revert the user's change. If it is unclear whether a change was intentional, ask before undoing it. - Tool results and user messages may include tags. tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear. diff --git a/packages/opencode/test/altimate/prompt-identity.ts b/packages/opencode/test/altimate/prompt-identity.ts index 0e56825a98..d73ba58cbb 100644 --- a/packages/opencode/test/altimate/prompt-identity.ts +++ b/packages/opencode/test/altimate/prompt-identity.ts @@ -5,10 +5,10 @@ // EXPECTED_SHA256 / EXPECTED_BYTES describe the pre-split monolithic // `src/altimate/prompts/builder.txt` as of the commit that removed it // (7bbf8a6d23f5aa880be3e8436d3e74764e5928a4). A deliberate prompt edit must -// update this pin — and that PR then needs its own quality evidence, because +// update this pin (last: the keep-the-user's-changes principle in core.txt) — and that PR then needs its own quality evidence, because // byte identity no longer covers it. -export const EXPECTED_SHA256 = "17663410dd9accc527b4cbd84558fc577ccc36d33d0428c5c5205d5df25400d7" -export const EXPECTED_BYTES = 14773 +export const EXPECTED_SHA256 = "73cab02ab2b647be40e4458d609e47a578ccd1fc980785b77b500dd04c8c7c2a" +export const EXPECTED_BYTES = 15011 export function sha256(text: string): string { return new Bun.CryptoHasher("sha256").update(text).digest("hex") diff --git a/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts b/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts new file mode 100644 index 0000000000..3df45e3508 --- /dev/null +++ b/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, test } from "bun:test" +import fs from "fs" +import path from "path" +import { PromptProfiles } from "../../src/altimate/prompts/profiles" + +const anthropic = fs.readFileSync(path.join(import.meta.dir, "../../src/session/prompt/anthropic.txt"), "utf8") + +describe("prompts keep the user's changes", () => { + for (const [name, text] of [ + ["builder", PromptProfiles.PROMPT_BUILDER], + ["anthropic", anthropic], + ] as const) { + test(`${name} prompt forbids reverting user changes and says to ask when unclear`, () => { + expect(text).toContain("never revert the user's change") + expect(text).toContain("fix the test or the callers, or ask") + expect(text).toContain("ask before undoing it") + }) + } +}) From fb4c0898a10e409e1c5d8a8e6a1b9e0cc82e1b7b Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Thu, 19 Nov 2026 10:30:00 +0530 Subject: [PATCH 2/2] fix(prompt): allow explicit reverts, forbid weakening tests, cover qwen/trinity/beast prompts Co-Authored-By: Claude Sonnet 5.5 --- .../opencode/src/altimate/prompts/builder/core.txt | 2 +- packages/opencode/src/session/prompt/anthropic.txt | 2 +- packages/opencode/src/session/prompt/beast.txt | 1 + packages/opencode/src/session/prompt/qwen.txt | 1 + packages/opencode/src/session/prompt/trinity.txt | 1 + packages/opencode/test/altimate/prompt-identity.ts | 6 +++--- .../test/altimate/prompt-keep-user-changes.test.ts | 12 ++++++++---- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/opencode/src/altimate/prompts/builder/core.txt b/packages/opencode/src/altimate/prompts/builder/core.txt index 05575f2068..32d0a1750b 100644 --- a/packages/opencode/src/altimate/prompts/builder/core.txt +++ b/packages/opencode/src/altimate/prompts/builder/core.txt @@ -5,4 +5,4 @@ You are altimate-code in builder mode — a data engineering agent specializing 1. **Understand before writing** — Read existing code, schemas, and actual data before writing any SQL. Never write blind. 2. **Follow conventions** — Match the project's naming patterns, layer structure, and style. Read 2-3 similar files first. 3. **Validate the output** — A task isn't done until the output data looks right. Check row counts, sample values, and column names. -4. **Keep the user's changes** — If a test or build fails because of a change the user made, fix the test or the callers, or ask; never revert the user's change. If it is unclear whether a change was intentional, ask before undoing it. +4. **Keep the user's changes** — Never revert a user change unless the user explicitly asks you to. If a test or build fails because of a change the user made, update the test or the callers to match it (never delete or weaken assertions just to make it pass), or ask the user. If it is unclear whether a change was intentional, ask before undoing it. diff --git a/packages/opencode/src/session/prompt/anthropic.txt b/packages/opencode/src/session/prompt/anthropic.txt index 2bf7e49b44..3ab9f3d35a 100644 --- a/packages/opencode/src/session/prompt/anthropic.txt +++ b/packages/opencode/src/session/prompt/anthropic.txt @@ -73,7 +73,7 @@ I've found some existing telemetry code. Let me mark the first todo as in_progre The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended: - - Use the TodoWrite tool to plan the task if required -- Keep the user's existing changes. If a test or build fails because of a change the user made, fix the test or the callers, or ask the user; never revert the user's change. If it is unclear whether a change was intentional, ask before undoing it. +- Keep the user's existing changes. Never revert a user change unless the user explicitly asks you to. If a test or build fails because of a change the user made, update the test or the callers to match it (never delete or weaken assertions just to make it pass), or ask the user. If it is unclear whether a change was intentional, ask before undoing it. - Tool results and user messages may include tags. tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear. diff --git a/packages/opencode/src/session/prompt/beast.txt b/packages/opencode/src/session/prompt/beast.txt index 889106b8bb..d965b77e7a 100644 --- a/packages/opencode/src/session/prompt/beast.txt +++ b/packages/opencode/src/session/prompt/beast.txt @@ -83,6 +83,7 @@ Carefully read the issue and think hard about a plan to solve it before coding. - Always read 2000 lines of code at a time to ensure you have enough context. - If a patch is not applied correctly, attempt to reapply it. - Make small, testable, incremental changes that logically follow from your investigation and plan. +- Keep the user's existing changes. Never revert a user change unless the user explicitly asks you to. If a test or build fails because of a change the user made, update the test or the callers to match it (never delete or weaken assertions just to make it pass), or ask the user. If it is unclear whether a change was intentional, ask before undoing it. - Whenever you detect that a project requires an environment variable (such as an API key or secret), always check if a .env file exists in the project root. If it does not exist, automatically create a .env file with a placeholder for the required variable(s) and inform the user. Do this proactively, without waiting for the user to request it. ## 7. Debugging diff --git a/packages/opencode/src/session/prompt/qwen.txt b/packages/opencode/src/session/prompt/qwen.txt index 545cba902c..65ba2d6981 100644 --- a/packages/opencode/src/session/prompt/qwen.txt +++ b/packages/opencode/src/session/prompt/qwen.txt @@ -86,6 +86,7 @@ The user will primarily request you perform software engineering tasks. This inc - Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach. - VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (e.g. npm run lint, npm run typecheck, ruff, etc.) with Bash if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to AGENTS.md so that you will know to run it next time. NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive. +- Keep the user's existing changes. Never revert a user change unless the user explicitly asks you to. If a test or build fails because of a change the user made, update the test or the callers to match it (never delete or weaken assertions just to make it pass), or ask the user. If it is unclear whether a change was intentional, ask before undoing it. - Tool results and user messages may include tags. tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result. diff --git a/packages/opencode/src/session/prompt/trinity.txt b/packages/opencode/src/session/prompt/trinity.txt index eded88a7c4..f5a6ab93b8 100644 --- a/packages/opencode/src/session/prompt/trinity.txt +++ b/packages/opencode/src/session/prompt/trinity.txt @@ -76,6 +76,7 @@ The user will primarily request you perform software engineering tasks. This inc - Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach. - VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (e.g. npm run lint, npm run typecheck, ruff, etc.) with Bash if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to AGENTS.md so that you will know to run it next time. NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive. +- Keep the user's existing changes. Never revert a user change unless the user explicitly asks you to. If a test or build fails because of a change the user made, update the test or the callers to match it (never delete or weaken assertions just to make it pass), or ask the user. If it is unclear whether a change was intentional, ask before undoing it. - Tool results and user messages may include tags. tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result. diff --git a/packages/opencode/test/altimate/prompt-identity.ts b/packages/opencode/test/altimate/prompt-identity.ts index d73ba58cbb..83f31369e7 100644 --- a/packages/opencode/test/altimate/prompt-identity.ts +++ b/packages/opencode/test/altimate/prompt-identity.ts @@ -5,10 +5,10 @@ // EXPECTED_SHA256 / EXPECTED_BYTES describe the pre-split monolithic // `src/altimate/prompts/builder.txt` as of the commit that removed it // (7bbf8a6d23f5aa880be3e8436d3e74764e5928a4). A deliberate prompt edit must -// update this pin (last: the keep-the-user's-changes principle in core.txt) — and that PR then needs its own quality evidence, because +// update this pin — and that PR then needs its own quality evidence, because // byte identity no longer covers it. -export const EXPECTED_SHA256 = "73cab02ab2b647be40e4458d609e47a578ccd1fc980785b77b500dd04c8c7c2a" -export const EXPECTED_BYTES = 15011 +export const EXPECTED_SHA256 = "37bd335a70f9ba4f4fb0495ad59fb0752e501cce98eb19ceedb07ac03e698cf3" +export const EXPECTED_BYTES = 15127 export function sha256(text: string): string { return new Bun.CryptoHasher("sha256").update(text).digest("hex") diff --git a/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts b/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts index 3df45e3508..ee66df6f87 100644 --- a/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts +++ b/packages/opencode/test/altimate/prompt-keep-user-changes.test.ts @@ -3,16 +3,20 @@ import fs from "fs" import path from "path" import { PromptProfiles } from "../../src/altimate/prompts/profiles" -const anthropic = fs.readFileSync(path.join(import.meta.dir, "../../src/session/prompt/anthropic.txt"), "utf8") +const promptFile = (name: string) => + fs.readFileSync(path.join(import.meta.dir, "../../src/session/prompt", `${name}.txt`), "utf8") describe("prompts keep the user's changes", () => { for (const [name, text] of [ ["builder", PromptProfiles.PROMPT_BUILDER], - ["anthropic", anthropic], + ["anthropic", promptFile("anthropic")], + ["qwen", promptFile("qwen")], + ["trinity", promptFile("trinity")], + ["beast", promptFile("beast")], ] as const) { test(`${name} prompt forbids reverting user changes and says to ask when unclear`, () => { - expect(text).toContain("never revert the user's change") - expect(text).toContain("fix the test or the callers, or ask") + expect(text).toContain("unless the user explicitly asks you to") + expect(text).toContain("never delete or weaken assertions") expect(text).toContain("ask before undoing it") }) }