Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
improve: update prompts and explanation formats
Dane Schneider98a734cf36d8
diff --git a/app/server/model/prompts/apply_exec.go b/app/server/model/prompts/apply_exec.goindex a1f84e97..c31c41cd 100644--- a/app/server/model/prompts/apply_exec.go+++ b/app/server/model/prompts/apply_exec.go@@ -340,8 +340,7 @@ open http://localhost:$PORT</PlandexBlock>Note the usage of & to run the server in the background. This is CRITICAL to ensure the script does not block and allows the browser to launch.--` + ApplyScriptResetUpdateImplementationPrompt+` + ExitCodePrompt + ApplyScriptResetUpdateImplementationPromptconst ApplyScriptResetUpdateSharedPrompt = `## Script State and Reset Behavior@@ -768,7 +767,9 @@ Always:- Group related commands- Check tool prerequisites- Use clear error messages-` + ApplyScriptResetUpdateImplementationSummary + ApplyScriptExecutionSummary++---+` + ExitCodePrompt + ApplyScriptResetUpdateImplementationSummary + ApplyScriptExecutionSummaryconst ApplyScriptResetUpdateSharedSummary = `Core Reset/Update Concepts:@@ -929,3 +930,7 @@ DO NOT update the _apply.sh script unless it is necessary to fix the problem. If**Follow all other instructions you've been given for the _apply.sh script.**`++const ExitCodePrompt = `+Apart from _apply.sh, since execution is enabled, when writing *new* code, ensure that code which exits due to errors or otherwise exits unexpectedly does so with a non-zero exit code, unless the user has requested otherwise or there is a very good reason to do otherwise. Do NOT change *existing* code in the user's project to fit this requirement unless the user has specifically requested it, but *do* ensure that unless there's a very good reason to do otherwise, *new* code you add will exit with a non-zero exit code if it exits due to errors.+`diff --git a/app/server/model/prompts/build_validation_replacements.go b/app/server/model/prompts/build_validation_replacements.goindex d5097c0e..74b2ad8f 100644--- a/app/server/model/prompts/build_validation_replacements.go+++ b/app/server/model/prompts/build_validation_replacements.go@@ -76,10 +76,10 @@ Your first task is to examine whether the changes were applied as described in t- Syntax (unless syntax errors have been previously specified and you are determining the cause of the syntax errors)Your evaluation should ONLY assess:-a. Whether the changes were applied at the correct location as specified-b. Whether the changes included all the specified additions/modifications-c. Whether any unintended changes were made to surrounding code-d. Whether any specified code was accidentally removed or duplicated+a. Whether the changes were applied at the correct location, *exactly* as specified in the proposed changes explanation, and at the correct level of nesting/indentation+b. Whether the changes included *all* the specified additions/modifications+c. Whether *any* unintended changes were made to surrounding code+d. Whether *any* specified code was accidentally removed or duplicatede. Any syntax errors that have been previously specified--@@ -89,6 +89,7 @@ Line numbers prefixed with 'pdx-' are included in the original file. Line number--First, briefly reason through and assess whether the changes were applied *correctly*.+You MUST include reasoning–do not skip this step.If the changes were applied *correctly*, you MUST output a <PlandexCorrect/> tag, followed by a <PlandexFinish/> tag, then end your response, like this:@@ -97,7 +98,9 @@ If the changes were applied *correctly*, you MUST output a <PlandexCorrect/> tag---If the changes were applied *incorrectly*, first assess what went wrong, and briefly strategize on how these issues can be avoided when you generate replacements. Next, you MUST output a <PlandexIncorrect/> tag, and then proceed to output the <PlandexComments/> tag and the <PlandexReplacements/> tag with at least one <Replacement> element (see below for details). Example:+If the changes were applied *incorrectly*, first assess what went wrong in your reasoning, and briefly strategize on how these issues can be avoided when you generate replacements. You MUST include reasoning–do not skip this step.++Next, you MUST output a <PlandexIncorrect/> tag, and then proceed to output the <PlandexComments/> tag and the <PlandexReplacements/> tag with at least one <Replacement> element (see below for details). Example:<PlandexIncorrect/><PlandexComments>@@ -201,6 +204,7 @@ IMPORTANT RULES:2. If your evaluation finds NO issues, you MUST use <PlandexCorrect/> then a <PlandexFinish/> element. Do NOT output comments or replacements if the changes were applied correctly.3. In replacements, every line in the <Old> element MUST exactly match a line in the original file and MUST begin with the line number with a 'pdx-' prefix (NOT with a 'pdx-new-' prefix).4. In replacements, lines in the <New> element MUST NOT begin with a line number or prefix.+5. Always include reasoning in a '## Evaluate Diff' section prior to outputting the <PlandexCorrect/> or <PlandexIncorrect/> tags.`return sdiff --git a/app/server/model/prompts/explanation_format.go b/app/server/model/prompts/explanation_format.goindex 96b482f8..bf987890 100644--- a/app/server/model/prompts/explanation_format.go+++ b/app/server/model/prompts/explanation_format.go@@ -11,7 +11,7 @@ Prior to any code block that is *updating* an existing file in context, you MUST**Updating ` + "`[file path]`" + `**Type: [type]Summary: [brief description, symbols/sections being changed]-Remove: [lines to remove]+Replace: [lines to replace/remove]Context: [describe surrounding code that helps locate the change unambiguously]Preserve: [symbols/structures/sections to preserve when overwriting entire file]---@@ -23,13 +23,13 @@ OR if multiple changes are being made to the same file in a single subtask and aChange 1.Type: [type]Summary: [brief description, symbols/sections being changed]-Remove: [lines to remove]+Replace: [lines to replace/remove]Context: [describe surrounding code that helps locate the change unambiguously]Change 2.Type: [type]Summary: [brief description, symbols/sections being changed]-Remove: [lines to remove]+Replace: [lines to replace/remove]Context: [describe surrounding code that helps locate the change unambiguously]... and so on for each change@@ -112,14 +112,22 @@ CRITICAL: The Context field MUST include symbols/structures that are NOT being mINCORRECT - symbols in Context are part of the change:Summary: Replace implementations of ` + "`foo`, `bar`, and `baz`" + `- Remove: lines 105-200+ Replace: lines 105-200Context: Located between ` + "`foo`" + ` and ` + "`baz`" + ` # Wrong - these are being changed!CORRECT - symbols in Context are outside the change:Summary: Replace implementations of ` + "`foo`, `bar`, and `baz`" + `- Remove: lines 105-200+ Replace: lines 105-200Context: Located between ` + "`setup`" + ` and ` + "`cleanup`" + ` functions # Correct - these aren't being changed+Again, the point of the Context field is to identify *anchors* that exist completely *outside* of the bounds of the change in the original file. The Context field is NOT used to identify code that is being *modified* or *replaced* as part of the change, but rather the code immediately *surrounding* the change.++The symbols/structure you mention in the Context field MUST ALSO be *immediately adjacent* to the change in the original file. Do NOT use symbols or structures that are further away from the change and have other code between them and the change.++ALWAYS surround the symbols/structures you mention in the Context field with backticks. Do NOT leave them out.++Furthermore, every symbol/structure you mention in the Context field ABSOLUTELY MUST be included in the code block that updates the file. Do NOT UNDER ANY CIRCUMSTANCES omit any of these symbols/structures from the code block. Use reference comments to avoid repeating code that is not changing.+Keep the explanation as succinct as possible while still following all of the above rules.You ABSOLUTELY MUST use this template EXACTLY as described above. DO NOT CHANGE THE FORMATTING OR WORDING IN ANY WAY! DO NOT OMIT ANY FIELDS FROM THE EXPLANATION AS DESCRIBED ABOVE.@@ -134,7 +142,7 @@ Context: Located between ` + "`NewClient`" + ` constructor and ` + "`getUser`" +**Updating ` + "`server/types/api.go`" + `**Type: replaceSummary: Replace implementation of ` + "`extractName`" + ` function with new version using ` + "`xml.Decoder`" + `-Remove: lines 8-15+Replace: lines 8-15Context: Located between ` + "`validateName`" + ` and ` + "`formatName`" + ` functions**Updating ` + "`cli/cmd/update.go`" + `**@@ -155,7 +163,7 @@ Context: Will be placed after the ` + "`validateUser`" + ` function**Updating ` + "`server/handlers/auth.go`" + `**Type: removeSummary: Remove unused ` + "`validateLegacyTokens`" + ` function and its helper ` + "`checkTokenFormat`" + `-Remove: lines 25-85+Replace: lines 25-85Context: Located between ` + "`parseAuthHeader`" + ` and ` + "`validateJWT`" + ` functions*@@ -168,20 +176,20 @@ When writing the explanation for multiple changes that will be included in a sinChange 1.Type: removeSummary: Remove unused ` + "`validateLegacyTokens`" + ` function and its helper ` + "`checkTokenFormat`" + `- Remove: lines 25-85+ Replace: lines 25-85Context: Located between ` + "`parseAuthHeader`" + ` and ` + "`validateJWT`" + ` functionsChange 2.Type: appendSummary: Append just-removed ` + "`checkTokenFormat`" + ` function to the end of the file- Remove: lines 8-15+ Replace: lines 8-15Context: The last code structure is ` + "`finalizeAuth`" + ` functionWhen outputting a compound explanation in the above format, it is CRITICAL that you still only output a SINGLE code block. Do NOT output multiple code blocks.*-ALL code structures that are mentioned in the Context field MUST be included as *anchors* in the code block that updates the file. If you are inserting new code between [structure 1] and [structure 2], then you MUST include both [structure 1] and [structure 2] as anchors in the code block that updates the file. Include *anchors* from the Context field so that the change is clearly positioned in the file between sections of code that are *not* being modified.+Again, ALL code structures/symbols that are mentioned in the Context field MUST be included as *anchors* in the code block that updates the file. If you are inserting new code between [structure 1] and [structure 2], then you MUST include both [structure 1] and [structure 2] as anchors in the code block that updates the file. Include *anchors* from the Context field so that the change is clearly positioned in the file between sections of code that are *not* being modified.At the same time, you MUST NOT reproduce large sections of code from the original file that are not changing. You MUST use reference comments "// ... existing code ..." to avoid reproducing large sections of code from the original file that are not changing.@@ -194,10 +202,10 @@ If your change description is:**Updating ` + "`server/api/users.go`" + `**Type: replaceSummary: Replace implementation of ` + "`validateUser`" + ` function to add role and permission validation-Remove: lines 10-20+Replace: lines 10-20Context: Located between ` + "`parseUser`" + ` and ` + "`updateUser`" + ` functions-Then your code block should look like:+Then your code block MUST look like:---// ... existing code ...@@ -251,6 +259,53 @@ Notice how:*+❌ INCORRECT - Context symbols missing from code block:+**Updating ` + "`sound.py`" + `**+Type: add+Summary: Add ` + "`debug_status`" + ` method to ` + "`Engine`" + ` class+Context: Located in the ` + "`Engine`" + ` class, right after the ` + "`__init__`" + ` method and right before the ` + "`cleanup`" + ` method++- sound.py:+<PlandexBlock lang="python" path="sound.py">+# ... existing code ...++def debug_status(self):+ """Print debug information about the sound engine state."""+ print("Sound engine debug info")++# ... existing code ...+</PlandexBlock>++✅ CORRECT - Context symbols included in code block:+**Updating ` + "`sound.py`" + `**+Type: add+Summary: Add ` + "`debug_status`" + ` method to ` + "`Engine`" + ` class+Context: Located in the ` + "`Engine`" + ` class, after the ` + "`cleanup`" + ` method++- sound.py:+<PlandexBlock lang="python" path="sound.py">+# ... existing code ...++class Engine:+ def __init__(self):+ # ... existing code ...++ def debug_status(self):+ """Print debug information about the sound engine state."""+ print("Sound engine debug info")++ def cleanup(self):+ # ... existing code ...++# ... existing code ...+</PlandexBlock>++*++As you can see, in the correct example, every symbol/structure mentioned in the Context field is included in the code block, unambiguously locating the change.++*+If a file is being *updated* and the above explanation does *not* indicate that the file is being *overwritten* or that the change is being prepended to the *start* of the file, then the code block ABSOLUTELY ALWAYS MUST begin with an "... existing code ..." comment to account for all the code before the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.If a file is being *updated* and the above explanation does *not* indicate that the file is being *overwritten* or that the change is being appended to the *end* of the file, then the code block ABSOLUTELY ALWAYS MUST end with an "... existing code ..." comment to account for all the code after the change. It is EXTREMELY IMPORTANT that you include this comment when it is needed—it must not be omitted.diff --git a/app/server/model/prompts/planning.go b/app/server/model/prompts/planning.goindex 54fbf516..77d55892 100644--- a/app/server/model/prompts/planning.go+++ b/app/server/model/prompts/planning.go@@ -5,16 +5,9 @@ type CreatePromptParams struct {ExecMode boolIsUserDebug boolIsApplyDebug bool+ IsGitRepo bool}-var SysPlanningBasic = GetPlanningPrompt(CreatePromptParams{- AutoContext: false,-})--var SysPlanningAutoContext = GetPlanningPrompt(CreatePromptParams{- AutoContext: true,-})-func GetPlanningPrompt(params CreatePromptParams) string {prompt := Identity + ` A plan is a set of files with an attached context.@@ -135,6 +128,42 @@ func GetPlanningPrompt(params CreatePromptParams) string {If the user's task is small and does not have any component subtasks, just restate the user's task in a '### Task' section as the only subtask and end the response immediately.`+ if params.IsGitRepo {+ prompt += `+ This project is a git repository. When creating a new project from scratch, include a .gitignore file in the root of the project.++ Do NOT do this in existing projects unless the user has asked you to or there is a strong reason to do so that is directly related to the user's task.++ If .gitignore already exists in the project, consider whether there are any new files that should be added to it. If so, add a task to the plan to update the .gitignore file accordingly.++ Apart from sensitive files, ensure build directories, cache directories, and other temporary/ephemeral files and directories are included in the .gitignore file.+ `++ if params.ExecMode {+ prompt += `+ If you are writing any commands to the _apply.sh file, consider whether they produce output that should be added to the .gitignore file. If so, add an additional task to the plan to update the .gitignore file accordingly.+ `+ }+ } else {+ prompt += `+ This project is a NOT a git repository. When creating a new project from scratch, include a .plandexignore file in the root of the project.++ .plandexignore is a file that tells Plandex which files and directories to ignore when loading context. Use it to prevent Plandex from loading unnecessary, irrelevant, or sensitive files and directories.++ Do NOT do this in existing projects unless the user has asked you to or there is a strong reason to do so that is directly related to the user's task.++ If .plandexignore already exists in the project, consider whether there are any new files that should be added to it. If so, add a task to the plan to update the .plandexignore file accordingly.++ Apart from sensitive files, ensure build directories, cache directories, and other temporary/ephemeral files and directories are included in the .plandexignore file.+ `++ if params.ExecMode {+ prompt += `+ If you are writing any commands to the _apply.sh file, consider whether they produce output that should be added to the .plandexignore file. If so, add an additional task to the plan to update the .plandexignore file accordingly.+ `+ }+ }+if params.AutoContext {prompt += `Since you are in auto-context mode and you have loaded the context you need, use it to make a much more detailed plan than the plan you made in your previous response before loading context. Be thorough in your planning.@@ -296,121 +325,3 @@ Example:Do NOT use any other format for the '### Remove Tasks' section. Do NOT use a numbered list. Identify tasks *only* by exact name matching.`--func GetFollowUpPlanClassifierPrompt(params CreatePromptParams) string {- s := `-[MANDATORY FOLLOW-UP FLOW]--FOR EVERY USER PROMPT:-You MUST FIRST respond naturally (but without jumping to code or planning). Then do classification.--CLASSIFICATION PROCESS:--1. Primary Classification:- A. Update/revision to tasks in current plan- B. Conversation prompt (question/comment)--2. For Type A, Sub-classify as:- A1. Small/minor update- A2. Significant update- A3. New distinct task--DETAILED CLASSIFICATION CRITERIA:--A1 (Small Update):-- Minor changes to existing functionality-- Changes contained within files already in context-- Simple additions or modifications-- Refinements to existing subtasks-CRITICAL: Even for A1, you MUST still create/update task list--A2 (Significant Update):-- Major changes to existing functionality-- Changes spanning multiple components-- New features that build on current work-- Substantial restructuring of existing subtasks--A3 (New Task):-- Addresses a different concern/feature-- Has little overlap with current work-- Would make more sense as separate plan-- Requires fresh context evaluation--REQUIRED ACTIONS BY CLASSIFICATION:--For Type B (Conversation):-- After responding conversationally, assess context needs-- If you have sufficient context: naturally indicate you can proceed- Example: "Based on the code I see, I can explain this in detail..."-- If you need more context: "I need more context to respond." followed by <PlandexFinish/>-- Never create tasks or implement code for Type B--For A1 (Small Update):-- After responding conversationally:- - MUST create/update ### Tasks list- - MUST assess context requirements- - If sufficient context: naturally state "This is a small update to the plan"- - If insufficient context: state "I need more context to continue." and output <PlandexFinish/>--For A2 (Significant Update):-- After responding conversationally:- - MUST output exactly: "This is a significant update to the plan. I'll clear all context without pending changes, then decide what context I need to move forward. <PlandexFinish/>"--For A3 (New Task):-- After responding conversationally:- - MUST output exactly: "This is a new task that is distinct from the plan. I'll clear all context without pending changes, then decide what context I need to move forward. <PlandexFinish/>"--CONTEXT ASSESSMENT CRITERIA:--For Chat Responses (B):-- Sufficient if: you have enough information to provide accurate, informed answers about the specific code or concepts--For Small Updates (A1):-- Sufficient if you have:- * All files that will be modified- * Any dependent files needed to understand the changes- * Any similar implementations that would be helpful as reference--RESPONSE FLOW AND STYLE:--1. Natural Response Integration:- - Always respond naturally to what the user has said first- - Then weave classification and context statements naturally into response- - Avoid mechanical or checklist-style responses- - Do not quote the exact phrases - incorporate their meaning naturally--Example of Good Flow:-"Those OpenGL errors look like compilation issues with modern OpenGL functions. This is a straightforward update to fix the build process, and I have all the context I need to resolve these errors."--Example of Poor Flow:-"Let me classify this prompt:-This is a small update to the plan.-I have the context I need to continue."--HANDLING MULTI-PART PROMPTS:--If the prompt contains both questions and updates:-1. First respond conversationally to all parts-2. Then assess any updates/changes per classification rules above-3. Only after proper conversation, incorporate classification statements/tags--CRITICAL REMINDERS:-- ALWAYS respond conversationally first-- NEVER proceed to implementation before completing planning phase-`-- if params.ExecMode {- s += `- Since execution mode is enabled, ALWAYS include a '### Commands' section in your response prior to the '### Tasks' section.`- }-- s += `-- ALWAYS create/update ### Tasks list for any type-A classification-- If the '### Commands' section indicates that commands should be added or updated in _apply.sh, you MUST also create a subtask referencing _apply.sh in the '### Tasks' section.-- ALWAYS output <PlandexFinish/> immediately after the task list-- ALWAYS end response immediately after <PlandexFinish/>-- NO EXCEPTIONS - Never continue past <PlandexFinish/> for any reason-- NEVER mix planning and implementation phases-`-- return s-}diff --git a/app/server/model/prompts/user_prompt.go b/app/server/model/prompts/user_prompt.goindex 6d3f816c..c4ba1583 100644--- a/app/server/model/prompts/user_prompt.go+++ b/app/server/model/prompts/user_prompt.go@@ -79,6 +79,8 @@ Output a <PlandexFinish/> tag after the '### Tasks' section. NEVER output a '###IMPORTANT: During this planning phase, you must NOT implement any code or create any code blocks. Your ONLY JOB is to break down the work into subtasks. Code implementation will happen in a separate phase after planning is complete. The planning phase is ONLY for breaking the work into subtasks.Do not attempt to write any code or show any implementation details at this stage.++The MOST IMPORTANT THING to remember is that you are in the PLANNING phase. Even though you see examples of implementation in your conversation history, you MUST NOT do any implementation at this stage. Your ONLY JOB is to make a plan and output a list of tasks, even if there is only *one* task in your list. That is your ONLY JOB at this stage. It may seem more natural to just respond to the user with code for small tasks, but it is ABSOLUTELY CRITICAL that you devote sufficient attention that you never make this mistake. It is critical that you have a 100% success rate at giving correct output according to the stage.`if params.IsUserDebug {@@ -141,6 +143,18 @@ When *updating an existing file*, you MUST follow the instructions you've been g- If you are replacing or removing code, you MUST include an exhaustive list of all symbols/sections that are being removed—ALL removed code must be accounted for. That MUST be followed by a line number range of lines in the original file that are being replaced. Use the exact format: '(original file lines [startLineNumber]-[endLineNumber])' — e.g. '(original file lines 10-20)' or for a single line, '(original file line [lineNumber])' — e.g. '(original file line 10)'+ - CRITICAL: When writing the Context field in an Action Explanation:+ - The symbols/structures mentioned MUST be code that is NOT being changed+ - These symbols serve as ANCHORS to precisely locate where the change should be applied+ - Every symbol/structure mentioned in the Context MUST appear in the code block+ - These anchors MUST be immediately adjacent to where the change occurs+ - Do NOT use distant symbols with other code between them and the change+ - All symbols must be surrounded with backticks+ - The code block MUST include these anchors to unambiguously locate the change+ - If you mention "Located between ` + "`functionA`" + "` and `" + "`functionB`" + `, both functions MUST appear in your code block++ FAILURE TO INCLUDE THE CONTEXT SYMBOLS IN THE CODE BLOCK MAKES CHANGES IMPOSSIBLE TO APPLY CORRECTLY AND IS A CRITICAL ERROR.+When *creating a new file*, follow the instructions in the "### Action Explanation Format" section for creating a new file.- The Type field MUST be exactly 'new file'.@@ -154,6 +168,7 @@ When *creating a new file*, follow the instructions in the "### Action Explanati- Do NOT use reference comments ('// ... existing code ...'). Those are only used for updating existing files and *never* when creating new files.- Include the *entire file* in the code block.+If multiple changes are being made to the same file in a single subtask, you MUST ALWAYS combine them into a SINGLE code block. Do NOT use multiple code blocks for multiple changes to the same file. Instead:- Include all changes in a single code block that follows the file's structure@@ -191,6 +206,28 @@ If you break up a task into subtasks, only include subtasks that can be implemen` + FileOpsImplementationPromptSummary+ file := ".gitignore"+ if !params.IsGitRepo {+ file = ".plandexignore"+ }++ s += fmt.Sprintf(`+- Create or update the %s file if necessary.+- If you write commands to _apply.sh, consider if output should be added to %s.+`, file, file)++ s += `+Remember, the MOST critical factor in creating code blocks correctly is to locate them unambiguously in the file using the definitions that are immediately before and immediately after the the section of code that is being changed or extended. Pay special attention to the 'Context' field in the Action Explanation. ALWAYS include at least a few additional lines of code before and after the section that is changing. And even if you need to include many lines to reach the *definitions* that are immediately before and after the section that is changing, do so.++Definitions in the original file that are outside of the section that is changing are like "hooks" that determine where in the resulting file the new code you write will be placed.++This is why it's critical for you to ALWAYS include enough immediately surrounding code to unambiguously locate ALL the new code you write. All the blocks of new code you write must hook in correctly using the hooks you supply from the original file when you include additional lines of code from the original file before and after the section that is changing.++It's not easy to be 100% consistent in writing code blocks that follow these rules, but you are capable of doing it with sufficient attention.++This disambiguation technique is the *most important* part of correctly implementing a plan.+`+return s}