Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

feat: enhance prompts for better model instructions

Dane Schneiderc7c13533809a
diff --git a/app/server/model/prompts/apply_exec.go b/app/server/model/prompts/apply_exec.go
index 2542c33d..a1f84e97 100644
--- a/app/server/model/prompts/apply_exec.go
+++ b/app/server/model/prompts/apply_exec.go
@@ -31,6 +31,10 @@ BE CAREFUL AND CONSERVATIVE when making changes to the user's machine:
- Only modify files/directories in the root directory of the plan unless specifically directed otherwise
- Unless some commands are risky/dangerous, include ALL commands in _apply.sh rather than telling users to run them later
+#### Avoid User Prompts
+
+Avoid user prompts. Make reasonable default choices rather than prompting the user for input. The _apply.sh script MUST be able to run successfully in a non-interactive context.
+
#### Command Preservation Rules
The _apply.sh script accumulates commands during the plan:
@@ -96,6 +100,26 @@ Running programs:
- For example: after 'make', include the command to run the program
- After 'npm install', include 'npm start' if appropriate
- Use judgment on the best way to run/execute the implemented plan
+- Running web servers and browsers:
+ * Launch the default browser with the appropriate localhost URL after starting the server
+ * When writing a web server that connects to a port, use a port environment variable or command line argument to specify the port number. If you include a fallback port, you can use a common port in the context of the project like 3000 or 8080. Include a port override in the _apply.sh script that uses an UNCOMMON port number that is unlikely to be in use.
+ * Try multiple ports so if a port is in use, the server won't fail to start
+ * When starting a web server that needs a browser launched:
+ * CRITICAL: ALWAYS run the server in the background using & or the script will block and never reach the browser launch
+ * Add a brief sleep to allow the server to start (use your judgment based on the server type and the complexity of the server startup process how long is reasonable)
+ * Use the appropriate browser launch command for the OS (provided in context—DO NOT include commands for other operating systems, just the one that is appropriate for the user's OS):
+ - macOS: open http://localhost:$PORT
+ - Linux: xdg-open http://localhost:$PORT
+ - Windows: start http://localhost:$PORT
+ Example:
+ # INCORRECT - will block and never launch browser:
+ npm start
+ open http://localhost:$PORT
+
+ # CORRECT - runs in background, waits, then launches browser:
+ npm start &
+ sleep 3
+ open http://localhost:$PORT # Using appropriate command based on OS in context
`
const ApplyScriptPlanningPrompt = ApplyScriptSharedPrompt + `
@@ -156,6 +180,9 @@ Think strategically about command execution:
- Group related commands together
- Plan for proper error handling and dependency checking
- Consider the user's environment and likely installed tools
+- For web applications and web servers:
+ * Use port environment variables or command line arguments to specify the port number. If you include a fallback port, you can use a common port in the context of the project like 3000 or 8080. Include a port override in the _apply.sh script that uses an UNCOMMON port number that is unlikely to be in use.
+ * Include default browser launch commands after server start
` + ApplyScriptResetUpdatePlanningPrompt
const ApplyScriptImplementationPrompt = ApplyScriptSharedPrompt + `
@@ -295,10 +322,25 @@ npm install --save-dev \
"typescript@^4.9.0" \
"prettier@^2.8.0"
-# Build and start
+# Find an available port
+export PORT=3400
+while ! nc -z localhost $PORT && [ $PORT -lt 3410 ]; do
+ export PORT=$((PORT + 1))
+done
+
+# Build and start in background
npm run build
-npm start
+npm start &
+
+# Wait briefly for server to be ready
+sleep 3
+
+# Launch browser
+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
const ApplyScriptResetUpdateSharedPrompt = `
@@ -354,6 +396,7 @@ When planning tasks (and subtasks) that involve command execution, you must cons
- **Startup/Execution**: Start or run the program once built (e.g., ` + "`./app`" + `, ` + "`npm start`" + `).
- **Database Migrations**: If schema changes are involved, add relevant migration commands.
- **Package/Dependency Installs**: Add or update only if new libraries or tools are introduced.
+- **Web Server**: Start the server again after source changes, dependency updates, etc.
### Example of Task Organization
@@ -405,6 +448,8 @@ Remember, after successful execution, _apply.sh ALWAYS resets to empty.
You MUST ALWAYS consider adding build/run commands again after ANY source changes.
If the _apply.sh script previously had a build/run command, and then it was reset to empty after being successfully executed, and then you make ANY subsequent code changes, you MUST add a new build/run command to the _apply.sh file.
+CRITICAL: If you have run the project previously with the _apply.sh script *and* the _apply.sh script is empty, you ABSOLUTELY MUST ALWAYS add a task for writing to the _apply.sh file. DO NOT OMIT THIS STEP.
+
INCORRECT FOLLOW UP:
### Tasks
1. Fix bug in source.c
@@ -639,6 +684,8 @@ Bad Practices to Avoid:
- Don't create subtasks just for single commands
- Don't duplicate package installations
- Don't run same program multiple times
+- Don't hide command output
+- Don't prompt the user for input
Remember:
- Include _apply.sh in 'Uses:' list when modifying it
@@ -712,6 +759,7 @@ DO NOT:
- Add unnecessary logging
- Use absolute paths
- Hide error conditions
+- Prompt the user for input
Always:
- Use relative paths
@@ -755,6 +803,8 @@ Task Organization:
- Consider dependencies between tasks
- Plan for command reuse after reset
- Account for the full change lifecycle
+
+CRITICAL: If you have run the project previously with the _apply.sh script *and* the _apply.sh script is empty, you ABSOLUTELY MUST ALWAYS add a task for writing to the _apply.sh file. DO NOT OMIT THIS STEP.
`
const ApplyScriptResetUpdateImplementationSummary = `
@@ -792,6 +842,12 @@ CRITICAL: The script must handle both program execution and security carefully:
- ALWAYS include commands to run the actual program after building/installing
- If there's a clear way to run the project, users should never need to run programs manually—always include commands to run the project in _apply.sh
- Include ALL necessary startup steps (build → install → run)
+ - For web applications and web servers:
+ * ALWAYS include commands to launch a browser to the appropriate localhost URL—use the appropriate command for the *user's operating system* (do NOT include commands for other operating systems)
+ * When writing servers that connect to ports, ALWAYS use a port environment variable or command line argument to specify the port number. If you include a fallback port, you can use a common port in the context of the project like 3000 or 8080.
+ * But when writing _apply.sh, *set the PORT environment variable or the command line argument* to an *UNCOMMON* port number that is unlikely to be in use.
+ * ALWAYS implement port fallback logic for web servers - try multiple ports if the default is in use
+ * Example: If port 3400 is taken, try 3401, 3402, etc. up to a reasonable maximum
2. Security Considerations
- BE EXTREMELY CAREFUL with system-modifying commands
@@ -835,7 +891,26 @@ When breaking up a task into subtasks, only include subtasks that you can do you
For tasks that you ARE able to complete because they only require creating or updating files, complete them thoroughly yourself and don't ask the user to do any part of them.
`
-const UserPlanningDebugPrompt = `You are debugging a failing shell command. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
+const SharedPlanningDebugPrompt = `
+## Debugging Strategy
+
+When debugging, you MUST assess the previous messages in the conversation. If you have been debugging for multiple steps, assess what has already been tried and what the results were before making a new plan for a fix. Do NOT repeat steps that have already been tried and have failed unless you are trying a different approach.
+
+Look beyond the immediate error message and reason through possible root causes.
+
+If you notice other connected or related issues, fix those as well. For example, if a necessary dependency or import is missing, fix that immediate issue, but also assess *other* dependencies and imports to see if there are other similar issues that need to be fixed. Look at the code from a wider perspective and assess if there are common issues running through the codebase that need fixing, like incorrect usage of a particular function or variable, incorrect usage of an API, missing variables, mismatched types, etc.
+
+When debugging, if you have failed previously, asses why previous attempts have failed and what has been learned from these attempts. Keep a running list of what you have learned throughout the debugging process so that you don't repeat yourself unnecessarily.
+
+Think in terms of making hypotheses and then testing them. Use the output to prove or disprove your hypotheses. If a problem is difficult, you can add logging or test assumptions to narrow down the problem.
+
+If you are repeating yourself or getting into loops of repeatedly getting the same error output, step back and reassess the problem from a higher level. Is there another way around this issue? Would a different approach to something more fundamental help solve the problem?
+
+---
+
+`
+
+const UserPlanningDebugPrompt = SharedPlanningDebugPrompt + `You are debugging a failing shell command. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
Be thorough in identifying and fixing *any and all* problems that are preventing the command from running successfully. If there are multiple problems, identify and fix all of them.
@@ -844,7 +919,7 @@ The command will be run again *automatically* on the user's machine once the cha
Command details:
`
-const ApplyPlanningDebugPrompt = `The _apply.sh script failed and you must debug. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
+const ApplyPlanningDebugPrompt = SharedPlanningDebugPrompt + `The _apply.sh script failed and you must debug. Focus only on fixing this issue so that the command runs successfully; don't make other changes.
Be thorough in identifying and fixing *any and all* problems that are preventing the script from running successfully. If there are multiple problems, identify and fix all of them.
diff --git a/app/server/model/prompts/build.go b/app/server/model/prompts/build.go
deleted file mode 100644
index 5a180418..00000000
--- a/app/server/model/prompts/build.go
+++ /dev/null
@@ -1,534 +0,0 @@
-package prompts
-
-import (
- "fmt"
- "plandex-server/syntax"
- "strings"
-
- shared "plandex-shared"
-)
-
-type ValidateEditsPromptParams struct {
- Path string
- Original string
- Desc string
- Proposed string
- Diff string
- Reasons []syntax.NeedsVerifyReason
- SyntaxErrors []string
-
- FullCorrection bool
-}
-
-func GetValidateEditsPrompt(params ValidateEditsPromptParams) string {
- path := params.Path
- original := params.Original
- desc := params.Desc
- proposed := params.Proposed
- diff := params.Diff
- reasons := params.Reasons
- fullCorrection := params.FullCorrection
- syntaxErrors := params.SyntaxErrors
-
- var s string
-
- // if fullCorrection {
- // s += fmt.Sprintf(`
- // [Explanation Rules]
-
- // %s
-
- // [End Explanation Rules]
- // `, ChangeExplanationPrompt)
- // }
-
- s += fmt.Sprintf("Path: %s\n\nOriginal file:\n%s\n\nProposed changes explanation:\n%s\n\nProposed changes:\n%s", path, original, desc, proposed)
- s += fmt.Sprintf("\n\nApplied changes:\n%s", diff)
- s += `You will examine the original file, proposed changes explanation, proposed changes, and applied changes diff.`
-
- var editsIncorrect bool
-
- for _, reason := range reasons {
- if reason == syntax.NeedsVerifyReasonAmbiguousLocation {
- editsIncorrect = true
- s += `The proposed changes were applied to an ambiguous location. This may mean that anchors were written incorrectly (with incorrect spacing or indentation, for example), or else that the ordering of anchors was incorrect. It may also mean that necessary surrounding context and anchors were not included.`
- } else if reason == syntax.NeedsVerifyReasonCodeRemoved {
- s += `The proposed changes removed or replaced code. Was this intentional? If this was the clear intention of the plan, then removing or replacing code can be correct. But it could also be a sign that the proposed changes were not correctly applied.`
- } else if reason == syntax.NeedsVerifyReasonCodeDuplicated {
- s += `The proposed may have duplicated code. Was this intentional? If this was the clear intention of the plan, or the duplication exists in the original file for a valid reason, then duplicating code can be correct. But it could also be a sign that the proposed changes were not correctly applied.`
- }
- }
-
- if len(syntaxErrors) > 0 {
- editsIncorrect = true
- s += `The proposed changes, when applied, resulted in a file with syntax errors, meaning the proposed changes were either written incorrectly or were not correctly applied. The resulting file has the following syntax errors:\n\n` + strings.Join(syntaxErrors, "\n") + `
-
- In your evaluation step, include an assessment of what caused the syntax errors.
- `
- }
-
- if fullCorrection {
- if !editsIncorrect {
- s += EditsValidateFullPrompt
- }
-
- // s += EditsExplanationPrompt
- s += ReferencesPrompt
- s += EditsFindReplacePrompt
- }
-
- if fullCorrection {
- s += getFullCorrectionExamples(!editsIncorrect)
- } else {
- s += EditsValidateOnlyPrompt
- s += ValidateOnlyExample
- }
-
- s += `You will examine ONLY whether the changes were correctly applied according to the proposed changes explanation. Do NOT evaluate code quality, best practices, or potential issues - focus solely on whether the applied changes match what was proposed.`
-
- return s
-}
-
-const EditsValidateBasePrompt = `
-Your task is to ONLY examine whether the changes were applied as described in the proposed changes explanation. Do NOT evaluate:
-- Code quality
-- Missing imports
-- Unused variables
-- Best practices
-- Potential bugs
-- Syntax (unless syntax errors have been previously specified)
-
-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
-e. Any syntax errors that have been previously specified
-`
-
-const EditsValidateCorrectPattern = `
-Pattern 1 - If changes were applied correctly:
-## Evaluate Diff
-[Your evaluation]
-<PlandexCorrect/>
-<PlandexFinish/>
-`
-
-const EditsValidateFullIncorrectPattern = `
-Pattern 2 - If changes were NOT applied correctly:
-## Evaluate Diff
-[Your evaluation]
-<PlandexIncorrect/>
-[Continue to next section for full correction]
-`
-
-const EditsValidateOnlyIncorrectPattern = `
-Pattern 2 - If changes were NOT applied correctly:
-## Evaluate Diff
-[Your evaluation]
-<PlandexIncorrect/>
-<PlandexFinish/>
-`
-
-const EditsValidateFullPrompt = EditsValidateBasePrompt + EditsValidateCorrectPattern + EditsValidateFullIncorrectPattern
-
-const EditsValidateOnlyPrompt = EditsValidateBasePrompt + EditsValidateCorrectPattern + EditsValidateOnlyIncorrectPattern
-
-// const EditsExplanationPrompt = `
-// - Next, in an '## Evaluate Explanation' section, examine the proposed changes explanation and determine whether it is correct. Did it follow all the rules in the [Explanation Rules] section?
-
-// a. If the changes are inserting, removing, or replacing code between two specific code structures, are these the correct code structures to use for the update? Are these structures *immediately* adjacent to each other or is there other code between them?
-
-// b. If the changes are inserting, removing, or replacing code between a specific code structure and the start or end of the file, are these the correct code structures or locations to use for the update? If the change is between the start of the file and a specific code structure, is there any other code between the start of the file and that code structure? (There must not be). If the change is between a specific code structure and the end of the file, is there any other code between that code structure and the end of the file? (There must not be).
-
-// - If the proposed changes explanation is *not* correct, you must rewrite the proposed changes explanation to correctly follow *all* the rules in the [Explanation Rules] section in a <PlandexProposedUpdatesExplanation> element. Include *only* the rewritten proposed changes explanation inside the <PlandexProposedUpdatesExplanation> element, and no other text. If the proposed changes explanation is already correct, skip this step.
-
-// - When rewriting the proposed changes explanation, DO NOT change the *type* of the change. You must ONLY update the portion of the explanation that explains the *location* of the change, not the *type* of the change. For example, if the proposed changes explanation is "I'll add 'someFunction' at the end of the file, immediately after 'existingFunction1'", you must rewrite it to correctly explain the *location* of the change, like "I'll add 'someFunction' at the end of the file, immediately after 'existingFunction2'". You MUST NOT change the type of the change, such as from 'add' to 'remove'.
-
-// - If the explanation does not match the changes that were made in the proposed updates (for example, the explanation says to add code, but the proposed updates removed code), this means that the proposed updates are *incorrect*—you MUST NOT alter the explanation to match the incorrect proposed updates (for example, you MUST NOT change the explanation to remove code instead of adding it just because the proposed updates incorrectly removed code). Instead, focus on ensuring that the explanation correctly shows the *location* of the change so that a *correct* find/replace operation can be generated.
-
-// - You MUST NOT make *functional* changes when rewriting the explanation. Your job is *NOT* to change functionality or add additional code in *any way*. It is *only* to ensure that the explanation follows all the rules correctly. Stick as close to the original explanation as possible when rewriting. Fix the problems, but keep everything else *exactly the same*.
-// `
-
-const EditsFindReplacePrompt = `
-- Next, convert the proposed updates into a find/replace operation. You MUST output EXACTLY ONE <PlandexReplacement> element. Multiple replacements are NOT allowed under any circumstances.
-
-- The SINGLE <PlandexReplacement> element MUST contain two child elements:
- - A <PlandexOld> element that contains the *EXACT* text from the *original file* that will be replaced.
- - A <PlandexNew> element that contains the *EXACT* text that will replace it.
-
-CRITICAL RULES FOR REPLACEMENTS:
-1. You MUST output EXACTLY ONE <PlandexReplacement> element
-2. If multiple changes are needed, you MUST combine them into a single replacement operation
-3. The <PlandexOld> element MUST match a UNIQUE block of text in the original file
-4. You MUST NEVER output multiple <PlandexReplacement> elements
-
-For multiple changes, include ALL changes in the SAME <PlandexReplacement> element:
-
-Example of CORRECT way to handle multiple changes:
-
-<PlandexReplacement>
- <PlandexOld>
- function existingFunction1() {
- someFunction();
- someOtherFunction();
- }
-
- function existingFunction2() {
- anotherFunction();
- }
- </PlandexOld>
- <PlandexNew>
- function existingFunction1() {
- someFunction(nil);
- someOtherFunction(nil);
- yetAnotherFunction(10);
- }
-
- function existingFunction2() {
- anotherFunction(true);
- newFunction();
- }
- </PlandexNew>
-</PlandexReplacement>
-
-Example of INCORRECT way (DO NOT DO THIS):
-
-❌ WRONG - Multiple replacement tags are NOT allowed:
-
-<PlandexReplacement>
- <PlandexOld>function1...</PlandexOld>
- <PlandexNew>function1...</PlandexNew>
-</PlandexReplacement>
-
-<PlandexReplacement>
- <PlandexOld>function2...</PlandexOld>
- <PlandexNew>function2...</PlandexNew>
-</PlandexReplacement>
-
-Additional Requirements:
-- The <PlandexOld> text MUST be *EXACTLY* the same as the text in the *original file* and MUST be *UNIQUE*
-- Make sure sufficient context is included to match uniquely and unambiguously
-- Newlines and special characters MUST also be *EXACTLY* matched
-- You MUST NOT include any placeholders or reference comments
-- Both <PlandexOld> and <PlandexNew> must consist of *entire* lines of code *only*
-- Do NOT find and replace partial lines of code
-- The smallest unit of code that can be replaced is an entire line
-`
-
-const ValidateOnlyExample = `
-Here are examples showing ALL possible valid response patterns:
-
-Example 1 - Changes Applied Correctly:
-
-## Evaluate Diff
-The new function 'someFunction' was correctly added to the end of the file, with proper indentation and spacing.
-
-<PlandexCorrect/>
-<PlandexFinish/>
-
-Example 2 - Simple Error Case:
-
-## Evaluate Diff
-The new function 'someFunction' was incorrectly added to the end of the file - it was inserted with wrong indentation.
-
-<PlandexIncorrect/>
-<PlandexFinish/>
-
-Example 3 - Duplicated Code Case:
-
-## Evaluate Diff
-The changes introduced duplicate code - the 'initializeConfig' function now appears twice in the file, when it should have been replaced.
-
-<PlandexIncorrect/>
-<PlandexFinish/>
-
-Example 4 - Wrong Location Case:
-
-## Evaluate Diff
-The new validation checks were added to the wrong function. They were inserted into 'validateInput' when they should have been added to 'validateOutput'.
-
-<PlandexIncorrect/>
-<PlandexFinish/>
-
-Example 5 - Missing Code Case:
-
-## Evaluate Diff
-The changes accidentally removed the error handling code that should have been preserved.
-
-<PlandexIncorrect/>
-<PlandexFinish/>
-
-IMPORTANT RULES:
-1. If your evaluation finds ANY issues, use Example 2-5 format and STOP.
-2. If your evaluation finds NO issues, you MUST use Example 1's format EXACTLY and STOP.
-3. You MUST never mix these formats or add additional sections when changes are correct.
-4. The response MUST start with '## Evaluate Diff' in all cases.
-5. Every response MUST end with either <PlandexCorrect/> followed by <PlandexFinish/>, or with <PlandexIncorrect/> followed by <PlandexFinish/>.
-`
-
-func getFullCorrectionExamples(evaluateDiff bool) string {
- s := ""
-
- if evaluateDiff {
- s += `
-- Example Response if changes were applied correctly ('## Evaluate Diff' section included):
-
---
-
-## Evaluate Diff
-
-The new function 'someFunction' was correctly added to the end of the file.
-
-<PlandexCorrect/>
-<PlandexFinish/>
-
---
-
-- Additional Examples of Correct Changes:
-
-Example 1 - Simple Addition:
-
-## Evaluate Diff
-The new error handling function was correctly added with proper error types and return values.
-
-<PlandexCorrect/>
-<PlandexFinish/>
-
-Example 2 - Multiple Changes:
-
-## Evaluate Diff
-All changes were applied correctly:
-1. New validation function was added with correct parameter types
-2. Error messages were updated with the requested format
-3. Return types were modified as specified
-
-<PlandexCorrect/>
-<PlandexFinish/>
-
-Example 3 - File Overwrite:
-
-## Evaluate Diff
-The file was correctly replaced with the new implementation, maintaining all required interfaces and types.
-
-<PlandexCorrect/>
-<PlandexFinish/>
-
---
-
-- Example Response if changes were *not* applied correctly, but explanation and proposed changes were correct:
-
---
-
-## Evaluate Diff
-
-The new function 'someFunction' was incorrectly added to the end of the file. It should have been added at the start of the 'existingFunction1' function.
-
-<PlandexIncorrect/>
-
-## Comments
-
-// ... existing code ...
-Evaluation: refers to the initialization code at the start of the 'existingFunction1' function
-Reference: true
-
-// loop 15 times
-Evaluation: explains the for loop below the comment
-Reference: false
-
-// ... existing function calls ...
-Evaluation: refers to the function calls at the start of the for loop
-Reference: true
-
-<PlandexReplacement>
- <PlandexOld>
- function existingFunction1() {
- prepare();
- init();
- fullInit();
- // loop 10 times
- for (let i = 0; i < 10; i++) {
- originalFunction();
- someOtherFunction();
- }
- }
- </PlandexOld>
- <PlandexNew>
- function existingFunction1() {
- prepare();
- init();
- fullInit();
- // loop 15 times
- for (let i = 0; i < 15; i++) {
- originalFunction();
- someOtherFunction();
- someFunction();
- andAnotherFunction();
- andOneMoreFunction();
- }
- }
- </PlandexNew>
-</PlandexReplacement>
-`
- }
-
- s += `
-- Example Response if explanation and proposed changes were *not* correct:
-
---
-`
-
- if evaluateDiff {
- s += `
-## Evaluate Diff
-
-The proposed changes incorrectly removed the 'existingFunction2' function.
-
-<PlandexIncorrect/>
-`
- }
-
- // s += `
- // ## Evaluate Explanation
-
- // The explanation incorrectly used 'existingFunction1' as an anchor when there is code between 'existingFunction1' and the end of the file. It should have used 'existingFunction2' instead.
-
- // <PlandexProposedUpdatesExplanation>
- // **Updating some/path/to/file.js:** I'll add 'someFunction' at the end of the file, immediately after 'existingFunction2'.
- // </PlandexProposedUpdatesExplanation>
- // `
-
- s += `
-<PlandexReplacement>
- <PlandexOld>
- function existingFunction1() {
- someOtherFunction();
- }
- </PlandexOld>
- <PlandexNew>
- function existingFunction1() {
- someFunction();
- someOtherFunction();
- }
- </PlandexNew>
-</PlandexReplacement>
-`
-
- if evaluateDiff {
- s += `
-FINAL REMINDER: The response pattern is strictly binary:
-1. If changes are correct: ONLY output '## Evaluate Diff' with "<PlandexCorrect/>" + <PlandexFinish/>
-2. If changes have ANY issues: Output '## Evaluate Diff' with "<PlandexIncorrect/>" and then continue to the next section ('## Evaluate Explanation').
-There are NO other valid response patterns.`
- }
-
- return s
-}
-
-func getPreBuildStatePrompt(filePath, preBuildState string) string {
- if preBuildState == "" {
- return ""
- }
-
- return fmt.Sprintf("**The current file is %s. Original state of the file:**\n```\n%s\n```", filePath, preBuildState) + "\n\n"
-}
-
-func GetWholeFilePrompt(filePath, preBuildState, changesFile, changesDesc string) string {
- preBuildStateWithLineNums := shared.AddLineNums(preBuildState)
- changesWithLineNums := shared.AddLineNumsWithPrefix(changesFile, "pdx-new-")
-
- s := WholeFileBeginning + ReferencesPrompt + WholeFileEnding + "\n\n" + getPreBuildStatePrompt(filePath, preBuildStateWithLineNums) + "\n\n"
-
- s += fmt.Sprintf("Proposed updates:\n%s\n```\n%s\n```", changesDesc, changesWithLineNums)
-
- return s
-}
-
-var ExampleReferences = `
-A reference comment is a comment that references code in the *original file* for the purpose of making it clear where a change should be applied. Examples of reference comments include:
-
- - // ... existing code...
- - # Existing code...
- - /* ... */
- - // Rest of the function...
- - <!-- rest of div tag -->
- - // ... rest of function ...
- - // rest of component...
- - # other methods...
- - // ... rest of init code...
- - // rest of the class...
- - // other properties
- - // other methods
- // ... existing properties ...
- // ... existing values ...
- // ... existing text ...
-
-Reference comments often won't exactly match one of the above examples, but they will always be referencing a block of code from the *original file* that is left out of the *proposed updates* for the sake of focusing on the specific change that is being made.
-
-Reference comments do NOT need to be valid comments for the given file type. For file types like JSON or plain text that do not use comments, reference comments in the form of '// ... existing properties ...' or '// ... existing values ...' or '// ... existing text ...' can still be present. These MUST be treated as valid reference comments regardless of the file type or the validity of the syntax.
-`
-
-const RefsBeginning = `
-You are an AI that analyzes an *original file* and *proposed updates* to that file and then identifies *all* *reference comments* present in the *proposed updates*.
-
-`
-
-const WholeFileBeginning = `
-After identifying all references, you will output the *entire file* with the *proposed updates* correctly applied. ALL references will be replaced by the appropriate code from the *original file*. You will correctly merge the code from the *original file* with the *proposed updates* and output the entire file.
-
-`
-
-var ReferencesPrompt = ExampleReferences + `
-
- *NOT EVERY COMMENT IS A REFERENCE.* If a comment refers to code that is present in the *proposed updates* then it is *not* a reference. Similarly, if a comment explains something about the change being made in the *proposed updates*, it is also *not* a reference.
-
- A reference comment MUST EXIST in the *proposed updates*. Do not include a reference comment unless it exists VERBATIM in the *proposed updates*.
-
- Output a section that lists *EVERY* comment in the *proposed updates*, including the line number of each comment prefixed by 'pdx-new-'. Below each comment, evaluate whether it is a reference comment. Focus on whether the comment is clearly referencing a block of code in the *original file*, whether it is explaining a change being made, or whether it is a comment that was carried over from the *original file* but does *not* reference any code that was left out of the *proposed updates*. After this evaluation, state whether each comment is a reference comment or not. Only list valid *comments* for the given programming language in the comments section. Do not include non-comment lines of code in the comments section.
-
- Example:
-
- ---
- Comments:
-
- // ... existing code to start transaction ...
- Evaluation: refers the code at the beginning of the 'update' function that starts the database transaction.
- Reference: true
-
- // verify user permission before performing update
- Evaluation: describes the change being made. Does not refer to any code in the *original file*.
- Reference: false
-
- // ... existing update code ...
- Evaluation: refers the code inside the 'update' function that updates the user.
- Reference: true
-
- --
-
- If there are no comments in the *proposed updates*, output just the string 'No comments' and continue.
-`
-
-const WholeFileEnding = `
- *
-
- Now output the entire file with the *proposed updates* correctly applied. ALL identified references MUST be replaced by the appropriate code from the *original file*. You MUST correctly merge the code from the *original file* with the *proposed updates* and output the *entire* resulting file. The resulting file MUST NOT include any reference comments.
-
- The resulting file MUST be syntactically and semantically correct. All code structures must be properly balanced.
-
- The full resulting file should be output within a <PlandexWholeFile> element, like this:
-
- <PlandexWholeFile>
- package main
-
- import "logger"
-
- function main() {
- logger.info("Hello, world!");
- exec()
- }
- </PlandexWholeFile>
-
- Do NOT include line numbers in the <PlandexWholeFile> element. Do NOT include reference comments in the <PlandexWholeFile> element. Output the ENTIRE file, no matter how long it is, with NO EXCEPTIONS. Include the resulting file *only* with no other text. Do NOT wrap the file output in triple backticks or any other formatting, except for the <PlandexWholeFile> element tags.
-
- Do NOT include any additional text after the <PlandexWholeFile> element. The output must end after </PlandexWholeFile>. DO NOT use the string <PlandexWholeFile> anywhere else in the output. ONLY use it to start the <PlandexWholeFile> element.
-`
diff --git a/app/server/model/prompts/build_helpers.go b/app/server/model/prompts/build_helpers.go
new file mode 100644
index 00000000..c99de8b6
--- /dev/null
+++ b/app/server/model/prompts/build_helpers.go
@@ -0,0 +1,53 @@
+package prompts
+
+const ExampleReferences = `
+A reference comment is a comment that references code in the *original file* for the purpose of making it clear where a change should be applied. Examples of reference comments include:
+
+ - // ... existing code...
+ - # Existing code...
+ - /* ... */
+ - // rest of the function...
+ - <!-- rest of div tag -->
+ - // ... rest of function ...
+ - // rest of component...
+ - # other methods...
+ - // ... rest of init code...
+ - // rest of the class...
+ - // other properties
+ - // other methods
+ - // ... existing properties ...
+ - // ... existing values ...
+ - // ... existing text ...
+
+Reference comments often won't exactly match one of the above examples, but they will always be referencing a block of code from the *original file* that is left out of the *proposed updates* for the sake of focusing on the specific change that is being made.
+
+Reference comments do NOT need to be valid comments for the given file type. For file types like JSON or plain text that do not use comments, reference comments in the form of '// ... existing properties ...' or '// ... existing values ...' or '// ... existing text ...' can still be present. These MUST be treated as valid reference comments regardless of the file type or the validity of the syntax.
+`
+
+const CommentClassifierPrompt = `
+You must analyze the *original file* and the *proposed updates* and output a <PlandexComments> element that lists *EVERY* comment in the *proposed updates*, including the line number of each comment prefixed by 'pdx-new-'. Below each comment, evaluate whether it is a reference comment.
+
+` + ExampleReferences + `
+
+ For each comment in the proposed changes, focus on whether the comment is clearly referencing a block of code in the *original file*, whether it is explaining a change being made, or whether it is a comment that was carried over from the *original file* but does *not* reference any code that was left out of the *proposed updates*. After this evaluation, state whether each comment is a reference comment or not. Only list valid *comments* for the given programming language in the comments section. Do not include non-comment lines of code in the comments section.
+
+ Example:
+
+<PlandexComments>
+pdx-new-1: // ... existing code to start transaction ...
+Evaluation: refers the code at the beginning of the 'update' function that starts the database transaction.
+Reference: true
+
+pdx-new-5: // verify user permission before performing update
+Evaluation: describes the change being made. Does not refer to any code in the *original file*.
+Reference: false
+
+pdx-new-10: // ... existing update code ...
+Evaluation: refers the code inside the 'update' function that updates the user.
+Reference: true
+</PlandexComments>
+
+If there are no comments in the *proposed updates*, output an empty <PlandexComments> element.
+
+ONLY include valid comments for the language in this list. Do NOT include any other lines of code in the comments section. You MUST include ALL comments from the *proposed updates*.
+`
diff --git a/app/server/model/prompts/build_validation_replacements.go b/app/server/model/prompts/build_validation_replacements.go
new file mode 100644
index 00000000..d5097c0e
--- /dev/null
+++ b/app/server/model/prompts/build_validation_replacements.go
@@ -0,0 +1,237 @@
+package prompts
+
+import (
+ "fmt"
+ "strings"
+
+ "plandex-server/syntax"
+ shared "plandex-shared"
+)
+
+type ValidationPromptParams struct {
+ Path string
+ Original string
+ Desc string
+ Proposed string
+ Diff string
+ Reasons []syntax.NeedsVerifyReason
+ SyntaxErrors []string
+}
+
+// GetValidationReplacementsXmlPrompt constructs the complete prompt string for XML responses.
+func GetValidationReplacementsXmlPrompt(params ValidationPromptParams) string {
+ reasons := params.Reasons
+ syntaxErrs := params.SyntaxErrors
+ path := params.Path
+ original := params.Original
+ desc := params.Desc
+ proposed := params.Proposed
+ diff := params.Diff
+
+ s := getBuildPromptHead(path, original, desc, proposed)
+
+ s += fmt.Sprintf(
+ `
+Diff of applied changes:
+>>>
+%s
+<<<
+
+`,
+ diff,
+ )
+
+ var parts []string
+
+ reasonMap := map[syntax.NeedsVerifyReason]string{
+ syntax.NeedsVerifyReasonAmbiguousLocation: "Changes were applied to an ambiguous location. This may indicate incorrect anchor spacing/indentation, wrong anchor ordering, or missing context.",
+ syntax.NeedsVerifyReasonCodeRemoved: "Code was removed or replaced. Verify if this was intentional according to the plan.",
+ syntax.NeedsVerifyReasonCodeDuplicated: "Code may have been duplicated. Verify if this was intentional according to the plan.",
+ }
+
+ for _, reason := range reasons {
+ if msg, ok := reasonMap[reason]; ok {
+ parts = append(parts, msg)
+ }
+ }
+
+ if len(syntaxErrs) > 0 {
+ parts = append(parts, fmt.Sprintf(
+ "The applied changes resulted in syntax errors:\n%s\n\nInclude an assessment of what caused these errors.",
+ strings.Join(syntaxErrs, "\n"),
+ ))
+ }
+
+ s += strings.Join(parts, "\n\n")
+
+ s += `
+## Validation
+
+Your first task is to examine whether the changes were applied as described in the proposed changes explanation. Do NOT evaluate:
+- Code quality
+- Missing imports
+- Unused variables
+- Best practices
+- Potential bugs
+- 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
+e. Any syntax errors that have been previously specified
+
+--
+
+Line numbers prefixed with 'pdx-' are included in the original file. Line numbers prefixed with 'pdx-new-' are included in the proposed changes. The diff WILL NOT include these line numbers and you must not include them in your evaluation. You must ignore them completely.
+
+--
+
+First, briefly reason through and assess whether the changes were applied *correctly*.
+
+If the changes were applied *correctly*, you MUST output a <PlandexCorrect/> tag, followed by a <PlandexFinish/> tag, then end your response, like this:
+
+<PlandexCorrect/>
+<PlandexFinish/>
+
+--
+
+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:
+
+<PlandexIncorrect/>
+<PlandexComments>
+...
+</PlandexComments>
+<PlandexReplacements>
+ <Replacement>
+ <Old>...</Old>
+ <New>...</New>
+ </Replacement>
+</PlandexReplacements>
+
+--
+
+## Comments
+
+Next, if the changes were applied *incorrectly*:
+
+` + CommentClassifierPrompt + `
+
+--
+
+## Replacements
+
+Next, if the changes were applied *incorrectly*, you must analyze the *original file* and the *proposed updates* and output a <PlandexReplacements> element that applies the changes described in the *proposed updates* to the *original file* in order to produce a final, valid resulting file with all changes correctly applied.
+
+CRITICALLY IMPORTANT: When applying changes with replacements, NO REFERENCE COMMENTS CAN BE PRESENT IN THE RESULTING FILE. All reference comments (as listed in the <PlandexComments> element above) ABSOLUTELY MUST be replaced with the code they refer to in the *original file*.
+
+Now output a <PlandexReplacements> element that contains all the replacements needed to correctly apply the changes described in the *proposed updates* to the *original file*. The <PlandexReplacements> element MUST contain at least one <Replacement> element.
+
+For each replacement, use a <Replacement> element with the following structure:
+
+<Replacement>
+ <Old>...</Old>
+ <New>...</New>
+</Replacement>
+
+The <Old> element must contain the *exact* original code that will be replaced. *Every* character in the <Old> element must be present in the original file. You MUST include line numbers prefixed with 'pdx-' in the <Old> element (NOT with 'pdx-new-'). Every line in the <Old> element must exactly match a line in the original file, including spacing, indentation, newlines, and the 'pdx-' line number. <Old> MUST NOT contain any partial lines, only complete lines.
+
+The <New> element must contain ALL the new code that will replace the code in <Old>. It must contain complete lines only (no partial lines). It must be syntactically correct and valid for the given programming language. It MUST NOT contain any line numbers. It MUST NOT contain any reference comments listed in the <PlandexComments> element. ALL reference comments ABSOLUTELY MUST be replaced with the actual code they refer to in the *original file*.
+
+Apply changes intelligently *in order* to avoid syntax errors, breaking code, or removing code from the original file that should not be removed. Consider the reason behind the update and make sure the result is consistent with the intention of the plan.
+
+Pay *EXTREMELY close attention* to opening and closing brackets, parentheses, and braces. Never leave them unbalanced when the changes are applied. Also pay *EXTREMELY close attention* to newlines and indentation. Make sure that the indentation of the new code is consistent with the indentation of the original code, and syntactically correct.
+
+Replacements must be ordered according to their position in the file. Each <Old> block must come after the previous block in the file. Replacements MUST NOT overlap. If a replacement is dependent on another replacement or intersects with it, group those replacements together into a single <PlandexReplacement> block.
+
+You ABSOLUTELY MUST NOT overwrite or delete code from the original file unless the plan *clearly intends* for the code to be overwritten or removed. Do NOT replace a full section of code with only new code unless that is the clear intention of the plan. Instead, merge the original code and the proposed updates together intelligently according to the intention of the plan.
+
+--
+
+Example responses:
+
+1. Changes Applied Correctly:
+
+## Evaluate Diff
+The new function 'someFunction' was correctly added to the end of the file, with proper indentation and spacing.
+
+<PlandexCorrect/>
+<PlandexFinish/>
+
+2. Changes Applied Incorrectly:
+
+## Evaluate Diff
+The new function 'someFunction' was incorrectly added to the end of the file - it was inserted with wrong indentation.
+
+<PlandexIncorrect/>
+
+<PlandexComments>
+pdx-new-42: // Update the user
+Evaluation: Describes the change being made. Not a reference.
+Reference: false
+
+pdx-new-44: // ... existing code ...
+Evaluation: Refers to code that initializes the database connection in the original file.
+Reference: true
+</PlandexComments>
+
+<PlandexReplacements>
+ <Replacement>
+ <Old>
+ pdx-42: func someFunction() {
+ pdx-43: connectToDatabase()
+ pdx-44: }
+ </Old>
+ <New>
+ func someFunction() {
+ err := connectToDatabase()
+ if err != nil {
+ log.Printf("error: %v", err)
+ return
+ }
+ processData()
+ }
+ </New>
+ </Replacement>
+</PlandexReplacements>
+
+IMPORTANT RULES:
+1. If your evaluation finds ANY issues, you MUST use <PlandexIncorrect/> followed by a <PlandexComments> element and a <PlandexReplacements> element with at least one <Replacement> element.
+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.
+`
+
+ return s
+}
+
+// getBuildPromptHead describes the original file and proposed changes
+func getBuildPromptHead(filePath, preBuildState, desc, proposed string) string {
+ preBuildStateWithLineNums := shared.AddLineNums(preBuildState)
+ proposedWithLineNums := shared.AddLineNumsWithPrefix(proposed, "pdx-new-")
+
+ return fmt.Sprintf(
+ `Path: %s
+
+Original file (with line nums):
+>>>
+%s
+<<<
+
+Proposed changes explanation (with line nums):
+>>>
+%s
+<<<
+
+Proposed changes:
+>>>
+%s
+<<<
+`,
+ filePath,
+ preBuildStateWithLineNums,
+ desc,
+ proposedWithLineNums,
+ )
+}
diff --git a/app/server/model/prompts/build_whole_file.go b/app/server/model/prompts/build_whole_file.go
new file mode 100644
index 00000000..a9c8d90e
--- /dev/null
+++ b/app/server/model/prompts/build_whole_file.go
@@ -0,0 +1,45 @@
+package prompts
+
+func GetWholeFilePrompt(filePath, preBuildState, changesFile, changesDesc, comments string) string {
+ s := getBuildPromptHead(filePath, preBuildState, changesDesc, changesFile)
+
+ s += "## Comments\n\n"
+
+ if comments != "" {
+ s += comments + "\n\n"
+ } else {
+ s += CommentClassifierPrompt + "\n\n"
+ }
+
+ s += WholeFilePrompt
+ return s
+}
+
+const WholeFilePrompt = `
+## Whole File
+
+Output the *entire merged file* with the *proposed updates* correctly applied. ALL reference comments will be replaced by the appropriate code from the *original file*. You will correctly merge the code from the *original file* with the *proposed updates* and output the entire file.
+
+ALL identified reference comments MUST be replaced by the appropriate code from the *original file*. You MUST correctly merge the code from the *original file* with the *proposed updates* and output the *entire* resulting file. The resulting file MUST NOT include any reference comments.
+
+The resulting file MUST be syntactically and semantically correct. All code structures must be properly balanced.
+
+The full resulting file should be output within a <PlandexWholeFile> element, like this:
+
+<PlandexWholeFile>
+ package main
+
+ import "logger"
+
+ function main() {
+ logger.info("Hello, world!");
+ exec()
+ }
+</PlandexWholeFile>
+
+Do NOT include line numbers in the <PlandexWholeFile> element. Do NOT include reference comments in the <PlandexWholeFile> element. Output the ENTIRE file, no matter how long it is, with NO EXCEPTIONS. Include the resulting file *only* with no other text. Do NOT wrap the file output in triple backticks or any other formatting, except for the <PlandexWholeFile> element tags.
+
+Do NOT include any additional text after the <PlandexWholeFile> element. The output must end after </PlandexWholeFile>. DO NOT use the string <PlandexWholeFile> anywhere else in the output. ONLY use it to start the <PlandexWholeFile> element.
+
+Do NOT UNDER ANY CIRCUMSTANCES *remove or change* any code that is not part of the changes in the *proposed updates*. ALL OTHER code from the *original file* must be reproduced *exactly* as it is in the *original file*. Do NOT remove comments, logging statements, commented out code, or anything else that is not part of the changes in the *proposed updates*. Your job is *only* to *apply* the changes in the *proposed updates* to the *original file*, not to make additional changes of *any kind*.
+`
diff --git a/app/server/model/prompts/context_load.go b/app/server/model/prompts/context_load.go
index 1e0e01af..c2f71f79 100644
--- a/app/server/model/prompts/context_load.go
+++ b/app/server/model/prompts/context_load.go
@@ -21,7 +21,7 @@ Phase 2 - Response (Next Phase):
IMPORTANT CONCEPTS:
- Relevant files are listed in a '### Files' section at the end of the response.
- Only these files will be included in the next phase.
-- Be liberal about marking context as relevant. Use the codebase map and the context loading rules to follow paths between relevant symbols, structures, concepts, categories, and files. It's *much* *much* *much* worse to leave out a relevant file than to include a non-relevant file. Go GET that relevant context, and get it ALL.
+- Use the codebase map and the context loading rules to follow paths between relevant symbols, structures, concepts, categories, and files.
YOUR TASK:
1. Assess Information
@@ -36,6 +36,7 @@ YOUR TASK:
- Talk about the user's project at a high level, how it's organized, and what areas are likely to be relevant to the user's task or message.
- Explain what parts of the codebase you'll need to examine. Start broadly and then narrow in on specific files and symbols.
- Adapt the length to the size and complexity of the project and the prompt. For simple tasks, a few sentences are sufficient. For complex tasks, a few paragraphs are appropriate. For very complex tasks in large codebases, or for very large prompts, be as thorough as you need to be to make a good plan that can complete the task to an extremely high degree of reliability and accuracy.
+ - You MUST only discuss files that are *in the project*. Do NOT mention files that are not part of the project. Do NOT FOR ANY REASON reference a file path unless it exists in the codebase map. Do NOT mention hypothetical files based on common project layouts. ONLY mention files that are *explicitly* listed in the codebase map.
3. Output Context Sections
If NO context needed:
@@ -51,6 +52,7 @@ YOUR TASK:
- Group by category from above
- Files must be in backticks
- List relevant symbols for each file
+ - ALL file paths in the '### Files' section ABSOLUTELY MUST be in the codebase map. Do NOT UNDER ANY CIRCUMSTANCES include files that are not in the codebase map. File paths in the codebase map are always preceeded by '###'. You must ONLY include these files. Do NOT include hypothetical files based on common project layouts. ONLY mention files that are *explicitly* listed in the codebase map.
c) Output <PlandexFinish/> immediately after
@@ -94,7 +96,7 @@ In response to the user's latest prompt, do the following IN ORDER:
s += `
3. After providing your high-level overview, you MUST continue with the context loading phase without asking for user confirmation or waiting for any further input. This is one continuous process in a single response.
- 4. If you already have enough information from the project map and current context to make a detailed plan or respond effectively to the user and so you won't need to load any additional context, then explicitly say "No context needs to be loaded." and continue on to the instructions below. NEVER say "No context needs to be loaded." *after* you've already output the '### Context Categories' and '### Files' sections.
+ 4. If you already have enough information from the project map to make a detailed plan or respond effectively to the user and so you won't need to load any additional context, then skip step 5 and output a <PlandexFinish/> immediately after steps 1 and 2 above.
5. Otherwise, you MUST output:
a) A section titled "### Context Categories" listing one or more categories of context that are relevant to the user's task or message. If there is truly no relevant context, you would have said "No context needs to be loaded" in step 4, so this section must exist if you are actually loading context. Do not list files here—just categories.
@@ -124,7 +126,7 @@ You have access to the directory layout of the project as well as a map of defin
Your job is to assess which context in the project might be relevant or helpful to the user's question or message.
Assess the following:
-- Are there specific files referenced that you need to examine?
+- Are there specific files listed in the codebase map that you need to examine?
- Would related files help you give a more accurate or complete answer?
- Do you need to understand implementations or dependencies?
@@ -156,7 +158,12 @@ func GetAutoContextShared(params CreatePromptParams, tellMode bool) string {
}
s += `
-- Using the project map in context, output a '### Files' list of potentially relevant *symbols* (like functions, methods, types, variables, etc.) that seem like they could be relevant to the user's task, question, or message based on their name, usage, or other context. Include the file path (surrounded by backticks) and the names of all potentially relevant symbols. File paths *absolutely must* be surrounded by backticks like this: ` + "`path/to/file.go`" + `. Any symbols that are referred to in the user's prompt must be included. You MUST organize the list by category using the categories from the '### Context Categories' section—ensure each category is represented in the list. When listing symbols, output just the name of the symbol, not it's full signature (e.g. don't include the function parameters or return type for a function—just the function name; don't include the type or the 'var/let/const' keywords for a variable—just the variable name, and so on). Output the symbols as a comma separated list in a single paragraph for each file. You MUST include relevant symbols (and associated file paths) for each category from the '### Context Categories' section. Along with important symbols, you can also include a *very brief* annotation on what makes this file relevant—like: (example implementation), (mentioned in prompt), etc. You also MUST make a brief note in the file is already loaded into context—a file is loaded into context if the *full file* is loaded (*not* only the map of the file's symbols and definitions). At the end of the list, output a <PlandexFinish/> tag.
+- Using the project map in context, output a '### Files' list of potentially relevant *symbols* (like functions, methods, types, variables, etc.) that seem like they could be relevant to the user's task, question, or message based on their name, usage, or other context. Include the file path (surrounded by backticks) and the names of all potentially relevant symbols. File paths *absolutely must* be surrounded by backticks like this: ` + "`path/to/file.go`" + `. Any symbols that are referred to in the user's prompt must be included. You MUST organize the list by category using the categories from the '### Context Categories' section—ensure each category is represented in the list. When listing symbols, output just the name of the symbol, not it's full signature (e.g. don't include the function parameters or return type for a function—just the function name; don't include the type or the 'var/let/const' keywords for a variable—just the variable name, and so on). Output the symbols as a comma separated list in a single paragraph for each file. You MUST include relevant symbols (and associated file paths) for each category from the '### Context Categories' section. Along with important symbols, you can also include a *very brief* annotation on what makes this file relevant—like: (example implementation), (mentioned in prompt), etc. At the end of the list, output a <PlandexFinish/> tag.
+
+- ALL file paths in the '### Files' section ABSOLUTELY MUST be in the codebase map. Do NOT UNDER ANY CIRCUMSTANCES include files that are not in the codebase map. File paths in the codebase map are always preceeded by '###'. You must ONLY include these files. Do NOT include hypothetical files based on common project layouts. ONLY mention files that are *explicitly* listed in the codebase map.
+
+[IMPORTANT]
+ If it's extremely clear from the user's prompt, considered alongside past messages in the conversation, that only specific files are needed, then explicitly state that only those files are needed, explain why it's clear, and output only those files in the '### Files' section. For example, if a user asks you to make a change to a specific file, and it's clear that no context beyond that file will be needed for the change, then state that only that file is needed based on the user's prompt, and then output *only* that file in the '### Files' section, then a <PlandexFinish/> tag. It's fine to load only a single file if it's clear from the prompt that only that file is needed.
- Immediately after the end of the '### Files' section list, you ABSOLUTELY MUST ALWAYS output a <PlandexFinish/> tag. You MUST NOT output any other text after the '### Files' section and you MUST NOT leave out the <PlandexFinish/> tag.
@@ -193,8 +200,6 @@ When assessing relevant context, you MUST follow these rules:
- Load ALL files containing utilities you might need
Example: If using string formatting utilities, load the utils file with those functions
-Remember: It's better to load more context than you need than to miss an important file. If you're not sure whether a file will be helpful, include it.
-
When considering relevant categories in the '### Context Categories' and relevant symbols in the '### Files' sections:
1. Look for naming patterns:
diff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.go
index b292af1c..01eb664a 100644
--- a/app/server/model/prompts/exec_status.go
+++ b/app/server/model/prompts/exec_status.go
@@ -1,9 +1,10 @@
-
package prompts
import (
"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/jsonschema"
+
+ shared "plandex-shared"
)
const SysExecStatusFinishedSubtaskXml = `You are tasked with evaluating a response generated by another AI (AI 1) that has been given a coding task to implement.
@@ -44,9 +45,23 @@ The 'subtaskFinished' key is a boolean that indicates whether the current task h
You must always call 'didFinishSubtask'. Don't call any other function.`
-func GetExecStatusFinishedSubtask(userPrompt, currentSubtask string, currentMessage string, previousMessages []string) string {
+type GetExecStatusFinishedSubtaskParams struct {
+ UserPrompt string
+ CurrentSubtask string
+ CurrentMessage string
+ PreviousMessages []string
+ PreferredModelOutputFormat shared.ModelOutputFormat
+}
+
+func GetExecStatusFinishedSubtask(params GetExecStatusFinishedSubtaskParams) string {
+ userPrompt := params.UserPrompt
+ currentSubtask := params.CurrentSubtask
+ currentMessage := params.CurrentMessage
+ previousMessages := params.PreviousMessages
+ preferredModelOutputFormat := params.PreferredModelOutputFormat
+
var s string
- if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ if preferredModelOutputFormat == shared.ModelOutputFormatXml {
s = SysExecStatusFinishedSubtaskXml
} else {
s = SysExecStatusFinishedSubtask
@@ -81,4 +96,3 @@ var DidFinishSubtaskFn = openai.FunctionDefinition{
Required: []string{"reasoning", "subtaskFinished"},
},
}
-
diff --git a/app/server/model/prompts/explanation_format.go b/app/server/model/prompts/explanation_format.go
index 1b059a01..96b482f8 100644
--- a/app/server/model/prompts/explanation_format.go
+++ b/app/server/model/prompts/explanation_format.go
@@ -11,10 +11,30 @@ 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]
Context: [describe surrounding code that helps locate the change unambiguously]
Preserve: [symbols/structures/sections to preserve when overwriting entire file]
---
+OR if multiple changes are being made to the same file in a single subtask and a single code block, list each change independently like this:
+
+---
+**Updating ` + "`[file path]`" + `**
+Change 1.
+Type: [type]
+Summary: [brief description, symbols/sections being changed]
+Remove: [lines to 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]
+Context: [describe surrounding code that helps locate the change unambiguously]
+
+... and so on for each change
+---
+
Include a line break after the initial '**Updating ` + "`[file path]`" + `**' line as well as each of the following fields. Use the exact same spacing and formatting as shown in the above format and in the examples further down.
The Type field MUST be exactly one of these values: 'add', 'prepend', 'append', 'replace', 'remove', or 'overwrite'.
@@ -38,43 +58,51 @@ The Type field MUST be exactly one of these values: 'add', 'prepend', 'append',
- remove
- For removing existing code within the file *only*
- Only use if existing code is being removed. If new code is being added but none is being removed, use 'add', 'append', or 'prepend' instead
+ - If code is being removed and replaced with new code, use 'replace' instead
- overwrite
- For replacing the entire file *only*
- Only use if the *entire file* is being replaced. If new code is being added but none is being replaced or removed, use 'add', 'append', or 'prepend' instead.
+
For each Type, follow these validation rules:
- For 'add':
- Summary MUST briefly describe the new code being added and where it will be inserted
- Context MUST describe the surrounding code structures that help locate where the new code will be inserted
- Preserve field must be omitted
+ - Remove field must be omitted
- For 'prepend':
- Summary MUST briefly describe the new code being added and where it will be inserted
- Context MUST describe the first code structure in the original file
- Preserve field must be omitted
+ - Remove field must be omitted
- For 'append':
- Summary MUST briefly describe the new code being appended to the end of the file
- Context MUST describe the last code structure in the original file
- Preserve field must be omitted
+ - Remove field must be omitted
- For 'replace':
- - Summary MUST briefly describe the change and list the specific symbols/sections being changed or replaced
- - Context MUST describe the surrounding code structures that help locate what is being replaced
+ - Summary MUST briefly describe the change
+ - Remove field MUST list lines in the original file that are being replaced. Use the exact format: 'lines [startLineNumber]-[endLineNumber]' — e.g. 'lines 10-20' or for a single line, 'line [lineNumber]' — e.g. 'line 10' — DO NOT use any other format, or describe the lines in any other way.
+ - Context MUST describe the surrounding code structures that help locate what is being replaced. Context MUST be *OUTSIDE* of the lines that are being replaced, as specified in C.
- Preserve field must be omitted
- For 'remove':
- - Summary MUST briefly describe the change and list the specific symbols/sections being changed or removed
- - Context MUST describe the surrounding code structures that help locate what is being removed
+ - Summary MUST briefly describe the change
+ - Remove field MUST list lines in the original file that are being removed. Use the exact format: 'lines [startLineNumber]-[endLineNumber]' — e.g. 'lines 10-20' or for a single line, 'line [lineNumber]' — e.g. 'line 10' — DO NOT use any other format, or describe the lines in any other way.
+ - Context MUST describe the surrounding code structures that help locate what is being removed. Context MUST be *OUTSIDE* of the lines that are being removed, as specified in C.
- Preserve field must be omitted
- For 'overwrite':
- Summary MUST briefly describe the change and list the specific symbols/sections being changed or replaced
- Context field must be omitted
- Preserve MUST *exhaustively* list all symbols/sections in the original file that should be included in the final result. Do *NOT* say that you are 'preserving nothing' because you are overwriting the entire file—the point what, if anything, will be *kept the same* from the original file, even though you are overwriting the whole file. Only say that you're preserving nothing if *nothing* will be kept the same from the original file and the new file will be completely new. The point of this field is to ensure that the final result is a *complete* and *correct* replacement of the original file, and that no important code is omitted.
+ - Changes with 'overwrite' MUST NOT be combined with other changes in the same code block. An 'overwrite' change MUST be the ONLY change for the code block.
-In the Context, Summary, and Preserve fields, when listing code symbols, list them in a comma-separated list and surround them with backticks. For example, ` + "`foo`,`someFunc`, `someVar`" + `
+In the Context, Summary, Remove, and Preserve fields, when listing code symbols, list them in a comma-separated list and surround them with backticks. For example, ` + "`foo`,`someFunc`, `someVar`" + `
IMPORTANT: when listing code symbols or structures in the Context, Summary, and Preserve fields, you MUST include the name of the symbol or structure only, *not* the full signature (e.g. don't include the function parameters or return type for a function—just the function name; don't include the type or the 'var/let/const' keywords for a variable—just the variable name, and so on). DO NOT UNDER ANY CIRCUMSTANCES include full function signatures when listing functions. Include *only* the function name.
@@ -84,10 +112,12 @@ CRITICAL: The Context field MUST include symbols/structures that are NOT being m
INCORRECT - symbols in Context are part of the change:
Summary: Replace implementations of ` + "`foo`, `bar`, and `baz`" + `
+ Remove: lines 105-200
Context: 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
Context: Located between ` + "`setup`" + ` and ` + "`cleanup`" + ` functions # Correct - these aren't being changed
Keep the explanation as succinct as possible while still following all of the above rules.
@@ -104,6 +134,7 @@ Context: Located between ` + "`NewClient`" + ` constructor and ` + "`getUser`" +
**Updating ` + "`server/types/api.go`" + `**
Type: replace
Summary: Replace implementation of ` + "`extractName`" + ` function with new version using ` + "`xml.Decoder`" + `
+Remove: lines 8-15
Context: Located between ` + "`validateName`" + ` and ` + "`formatName`" + ` functions
**Updating ` + "`cli/cmd/update.go`" + `**
@@ -124,10 +155,32 @@ Context: Will be placed after the ` + "`validateUser`" + ` function
**Updating ` + "`server/handlers/auth.go`" + `**
Type: remove
Summary: Remove unused ` + "`validateLegacyTokens`" + ` function and its helper ` + "`checkTokenFormat`" + `
+Remove: lines 25-85
Context: Located between ` + "`parseAuthHeader`" + ` and ` + "`validateJWT`" + ` functions
*
+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.
+
+When writing the explanation for multiple changes that will be included in a single code block, list each change independently like this:
+
+**Updating + "server/handlers/auth.go" + **
+Change 1.
+ Type: remove
+ Summary: Remove unused ` + "`validateLegacyTokens`" + ` function and its helper ` + "`checkTokenFormat`" + `
+ Remove: lines 25-85
+ Context: Located between ` + "`parseAuthHeader`" + ` and ` + "`validateJWT`" + ` functions
+
+Change 2.
+ Type: append
+ Summary: Append just-removed ` + "`checkTokenFormat`" + ` function to the end of the file
+ Remove: lines 8-15
+ Context: The last code structure is ` + "`finalizeAuth`" + ` function
+
+When 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.
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.
@@ -141,6 +194,7 @@ If your change description is:
**Updating ` + "`server/api/users.go`" + `**
Type: replace
Summary: Replace implementation of ` + "`validateUser`" + ` function to add role and permission validation
+Remove: lines 10-20
Context: Located between ` + "`parseUser`" + ` and ` + "`updateUser`" + ` functions
Then your code block should look like:
@@ -152,7 +206,6 @@ func (api *API) parseUser(input []byte) (*User, error) {
// ... existing code ...
}
-// Replacing existing validateUser implementation
func (api *API) validateUser(user *User) error {
// Validate basic fields
if user.ID == "" {
@@ -254,6 +307,48 @@ If the explanation includes a 'Preserve' field, be absolutely certain that the c
---
+Example of an explanation that includes multiple changes to the same file, with a *single* code block:
+
+**Updating + "server/handlers/auth.go" + **
+Change 1.
+ Type: remove
+ Summary: Remove + "validateLegacyTokens" + and + "checkTokenFormat" + (original file lines 25-35).
+ Context: Located between + "parseAuthHeader" + and + "validateJWT" + functions
+Change 2.
+ Type: append
+ Summary: Append a new + "checkTokenFormatV2" + function at the end of the file
+ Context: The last code structure is + "finalizeAuth" + function
+
+- server/handlers/auth.go:
+<PlandexBlock lang="go" path="server/handlers/auth.go">
+// ... existing code ...
+
+func parseAuthHeader() {
+ // ... existing code ...
+}
+
+// Plandex: removed code
+
+func validateJWT() {
+ // ... existing code ...
+}
+
+func finalizeAuth() {
+ // ... existing code ...
+}
+
+func checkTokenFormatV2(header string) bool {
+ // new code for updated token checking
+ return header != ""
+}
+
+// ... existing code ...
+</PlandexBlock>
+
+*
+
+Remember, when outputting a compound explanation in the above format, it is CRITICAL that you still only output a SINGLE code block.
+
#### 2. Creating a new file
Prior to any code block that is *creating a new file*, you MUST explain the change in the following format EXACTLY:
@@ -318,4 +413,7 @@ For new files:
- Do NOT use placeholder code or comments like '// implement authentication here' to indicate that the file is incomplete. Implement *all* functionality.
- Do NOT use reference comments like '// ... existing code ...'. Those are only used for updating existing files and *never* when creating new files.
- Include the *entire file* in the code block.
+
+
+
`
diff --git a/app/server/model/prompts/implement.go b/app/server/model/prompts/implement.go
index 8594e69c..e193a815 100644
--- a/app/server/model/prompts/implement.go
+++ b/app/server/model/prompts/implement.go
@@ -47,6 +47,7 @@ In a <PlandexBlock> tag attribute, the 'path' attribute MUST be the exact file p
- Do NOT include anything except the code itself within the <PlandexBlock> tags. No other labels, text, or formatting. Just the code.
- Do NOT omit the 'lang' or 'path' attributes from the <PlandexBlock> tag. EVERY <PlandexBlock> tag MUST ALWAYS have both 'lang' and 'path' attributes.
- Do NOT omit the *file path label* before the <PlandexBlock> tag. Every code block MUST ALWAYS be preceded by a file path label.
+- Do NOT UNDER ANY CIRCUMSTANCES include line numbers in the <PlandexBlock> tag. While line numbers are included in the original file in context (prefixed with 'pdx-', like 'pdx-10: ') to assist you with describing the location of changes in the 'Action Explanation', they ABSOLUTELY MUST NOT be included in the <PlandexBlock> tag.
Labelled code block example:
@@ -100,10 +101,126 @@ When updating an existing file in context, use the *reference comment* "// ... e
` + FileOpsImplementationPrompt + `
+## Multiple updates to the same file
+
+When a task involves multiple updates to the same file:
+- You MUST combine all changes into a SINGLE code block
+- Do NOT split changes across multiple code blocks
+- Use reference comments ("// ... existing code ...") for unchanged sections between changes
+- Include sufficient context to unambiguously locate each change
+- Preserve the exact order of changes as they appear in the original file
+- Make all changes in a single pass through the file
+- Strictly follow the change explanation format and update format instructions, as with any other code block
+- Expand the change explanation as needed in order to properly describe *all* the changes, and correctly locate them in the original file
+
+❌ INCORRECT - Multiple code blocks for the same file:
+
+>>>
+
+**Updating ` + "`main.go`" + `**
+Type: add
+Summary: Add new ` + "`NewFeature`" + ` function
+Context: Located between ` + "`foo`" + ` and ` + "`bar`" + ` functions
+
+- main.go:
+<PlandexBlock lang="go" path="main.go">
+// ... existing code ...
+
+func foo() {
+ // ... existing code ...
+}
+
+func NewFeature() {
+ doSomething()
+}
+
+func bar() {
+ // ... existing code ...
+}
+
+// ... existing code ...
+</PlandexBlock>
+
+**Updating ` + "`main.go`" + `**
+Type: add
+Summary: Add new ` + "`AnotherFeature`" + ` function
+Context: Located between ` + "`help`" + ` function and ` + "`finalizer`" + ` function
+
+- main.go:
+<PlandexBlock lang="go" path="main.go">
+// ... existing code ...
+
+func help() {
+ // ... existing code ...
+}
+
+func AnotherFeature() {
+ doSomethingElse()
+}
+
+func finalizer() {
+ // ... existing code ...
+}
+
+// ... existing code ...
+</PlandexBlock>
+
+<<<
+
+✅ CORRECT - Single code block with multiple changes:
+
+>>>
+
+**Updating ` + "`main.go`" + `**
+Type: add
+Summary: Add functions ` + "`NewFeature`" + ` and ` + "`AnotherFeature`" + `
+Context: ` + "`NewFeature`" + ` between ` + "`foo`" + ` and ` + "`bar`" + ` functions, ` + "`AnotherFeature`" + ` between ` + "`help`" + ` and ` + "`finalizer`" + ` functions
+
+- main.go:
+<PlandexBlock lang="go" path="main.go">
+// ... existing code ...
+
+func foo() {
+ // ... existing code ...
+}
+
+func NewFeature() {
+ doSomething()
+}
+
+func bar() {
+ // ... existing code ...
+}
+
+// ... existing code ...
+
+func help() {
+ // ... existing code ...
+}
+
+func AnotherFeature() {
+ doSomethingElse()
+}
+
+func finalizer() {
+ // ... existing code ...
+}
+
+// ... existing code ...
+</PlandexBlock>
+
+<<<
+
+## Placeholders
+
As much as possible, do not include placeholders in code blocks like "// implement functionality here". Unless you absolutely cannot implement the full code block, do not include a placeholder denoted with comments. Do your best to implement the functionality rather than inserting a placeholder. You **MUST NOT** include placeholders just to shorten the code block. If the task is too large to implement in a single code block, you should break the task down into smaller steps and **FULLY** implement each step.
+## Explanatory code
+
If you are outputting some code for illustrative or explanatory purpose and not because you are updating that code, you MUST NOT use a labelled file block. Instead output the label with NO PRECEDING DASH and NO COLON postfix. Use a conversational sentence like 'This code in src/main.rs.' to label the code. This is the only exception to the rule that all code blocks must be labelled with a file path. Labelled code blocks are ONLY for code that is being created or modified in the plan.
+## Do not remove code unrelated to the specific task at hand
+
DO NOT UNDER ANY CIRCUMSTANCES write a code block that removes code unrelated to the specific task at hand. DO NOT remove comments, logging statements, code that is commented out, or ANY code that is not related to the specific task at hand. Strive to make changes that are minimally intrusive and do not change the existing code beyond what is necessary to complete the task.
## Do the task yourself and don't give up
diff --git a/app/server/model/prompts/name.go b/app/server/model/prompts/name.go
index 8264c73c..e1a56817 100644
--- a/app/server/model/prompts/name.go
+++ b/app/server/model/prompts/name.go
@@ -1,4 +1,3 @@
-
package prompts
import (
@@ -26,8 +25,12 @@ var PlanNameFn = openai.FunctionDefinition{
},
}
-func GetPlanNamePrompt(text string) string {
- return SysPlanName + "\n\nContent:\n" + text
+type PlanNameRes struct {
+ PlanName string `json:"planName"`
+}
+
+func GetPlanNamePrompt(sysPrompt, text string) string {
+ return sysPrompt + "\n\nContent:\n" + text
}
type PipedDataNameRes struct {
@@ -54,7 +57,7 @@ var PipedDataNameFn = openai.FunctionDefinition{
},
}
-func GetPipedDataNamePrompt(text string) string {
+func GetPipedDataNamePrompt(sysPrompt, text string) string {
return SysPipedDataName + "\n\nContent:\n" + text
}
@@ -62,7 +65,6 @@ type NoteNameRes struct {
Name string `json:"name"`
}
-
const SysNoteNameXml = `You are an AI namer that creates a name for an arbitrary text note. You MUST output a valid XML response that includes a <name> tag. The <name> tag should contain a *short* lowercase name for the data. Use dashes as word separators. No spaces, numbers, or special characters. Shorten and abbreviate where possible. Do not use XML attributes - put all data as tag content.
Example response:
@@ -83,7 +85,6 @@ var NoteNameFn = openai.FunctionDefinition{
},
}
-func GetNoteNamePrompt(text string) string {
- return SysNoteName + "\n\nNote:\n" + text
+func GetNoteNamePrompt(sysPrompt, text string) string {
+ return sysPrompt + "\n\nNote:\n" + text
}
-
diff --git a/app/server/model/prompts/user_prompt.go b/app/server/model/prompts/user_prompt.go
index fab96cf4..6d3f816c 100644
--- a/app/server/model/prompts/user_prompt.go
+++ b/app/server/model/prompts/user_prompt.go
@@ -107,12 +107,14 @@ The <PlandexBlock> tag MUST ALWAYS include both a 'lang' attribute and a 'path'
When *updating an existing file*, you MUST follow the instructions you've been given on how to update code in code blocks:
- - Do NOT include large sections of the file that are not changing. Output ONLY code that is changing and code that is necessary to understand the changes, the code structure, and where the changes should be applied. Use references comments for sections of the file that are not changing.
+ - Do NOT include large sections of the file that are not changing. Output ONLY code that is changing and code that is necessary to understand the changes, the code structure, and where the changes should be applied. Use references comments for sections of the file that are not changing. ONLY use exactly '... existing code ...' (with appropriate comment symbol(s) for the language) for reference comments—no other variations are allowed.
- Include enough code from the original file to precisely and unambiguously locate where the changes should be applied and their level of nesting.
- Match the indentation of the original file exactly.
+ - Do NOT include line numbers in the <PlandexBlock> tag. While line numbers are included in the original file in context (prefixed with 'pdx-', like 'pdx-10: ') in context to assist you with describing the location of changes in the 'Action Explanation', they ABSOLUTELY MUST NOT be included in the <PlandexBlock> tag.
+
- Do NOT output multiple references with no changes in between them.
- Do NOT add superfluous newlines around reference comments.
@@ -137,6 +139,8 @@ When *updating an existing file*, you MUST follow the instructions you've been g
- Every code block that *updates* an existing file MUST ALWAYS be preceded by an explanation of the change that *exactly matches* one of the formats listed in the "### Action Explanation Format" section. Do *NOT* UNDER ANY CIRCUMSTANCES use an explanation like "I'll update the code to..." that does not match one of these formats.
+ - 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)'
+
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'.
@@ -147,9 +151,29 @@ When *creating a new file*, follow the instructions in the "### Action Explanati
- The <PlandexBlock> tag MUST NOT include any other text or formatting. It must only contain the code for the code block and NOTHING ELSE. Do NOT wrap the code block in triple backticks, CDATA tags, or any other text or formatting. Output ONLY the code and nothing else within the <PlandexBlock> tag.
- The code block MUST include the *entire file* to be created. Do not omit any code from the file.
- Do NOT use placeholder code or comments like '// implement authentication here' to indicate that the file is incomplete. Implement *all* functionality.
- - Do NOT use reference comments like '// ... existing code ...'. Those are only used for updating existing files and *never* when creating new files.
+ - 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
+ - Use "... existing code ..." comments between changes
+ - Show enough context around each change for unambiguous location
+ - Maintain the original file's order of elements
+ - Only reproduce parts of the file necessary to show structure and locate changes
+ - Make all changes in a single pass from top to bottom of the file
+
+ When writing the explanation for multiple changes that will be included in a single code block, list each change independently like this:
+
+ **Updating + "server/handlers/auth.go" + **
+ Change 1.
+ Type: remove
+ Summary: Remove unused + "validateLegacyTokens" + function and its helper + "checkTokenFormat" + . Removes + "validateLegacyTokens and checkTokenFormat" + functions (original file lines 25-85).
+ Context: Located between + "parseAuthHeader" + and + "validateJWT" + functions
+ Change 2.
+ Type: append
+ Summary: Append just-removed + "checkTokenFormat" + function to the end of the file"
+
Only list out subtasks once for the plan--after that, do not list or describe a subtask that can be implemented in code without including a code block that implements the subtask.
@@ -428,20 +452,15 @@ CRITICAL PLANNING RULES:
}
s += `
- - You MUST NOT start implementing code
+ - You MUST NOT UNDER ANY CIRCUMSTANCES start implementing code, even if you have already made a plan in a previous response and are ready to implement it—you still ABSOLUTELY MUST NOT implement code at this stage. You MUST make a plan first in the format described above.
- You MUST follow planning phase format exactly
2. Even for small changes:
- Create/update task list first
- - No implementation until planning is complete
+ - No implementation and NO CODE until planning is complete, and you have output a '### Tasks' section and a <PlandexFinish/>
- All changes must be in task list
-3. Task Planning Required:
- - When adding new functionality
- - When modifying existing code
- - When fixing bugs or issues
- - When continuing an existing plan
- NO EXCEPTIONS - always plan first
+3. The planning stage is *ALWAYS* required. You MUST NEVER skip ahead and start writing code in this response. You MUST complete the planning stage first and output a '### Tasks' section and a <PlandexFinish/> before you can start implementing code.
`
return s