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
revert WIP markdown output improvements that were mistakenly committed alongside docs
Dane Schneiderf8302e2dc072
diff --git a/app/cli/changes_tui/actions.go b/app/cli/changes_tui/actions.goindex f587b94f..1c66d1f0 100644--- a/app/cli/changes_tui/actions.go+++ b/app/cli/changes_tui/actions.go@@ -5,7 +5,6 @@ import ("log""plandex/api""plandex/lib"- "strings""github.com/atotto/clipboard""github.com/muesli/reflow/wrap"@@ -193,8 +192,6 @@ func (m *changesUIModel) updateMainView(scrollReplacement bool) {updatedFile = m.currentPlan.CurrentPlanFiles.Files[m.selectionInfo.currentPath]}- updatedFile = strings.ReplaceAll(updatedFile, "\\`\\`\\`", "```")-wrapped := wrap.String(updatedFile, m.fileViewport.Width-2)m.fileViewport.SetContent(wrapped)} else {diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.goindex 8f164bf7..3750751d 100644--- a/app/server/model/plan/build_exec.go+++ b/app/server/model/plan/build_exec.go@@ -9,7 +9,6 @@ import ("plandex-server/model/prompts""plandex-server/syntax""plandex-server/types"- "strings""github.com/davecgh/go-spew/spew""github.com/plandex/plandex/shared"@@ -243,16 +242,13 @@ func (fileState *activeBuildStreamFileState) buildFile() {}// new file- content := activeBuild.FileContent- content = strings.ReplaceAll(content, "\\`\\`\\`", "```")-planRes := &db.PlanFileResult{OrgId: currentOrgId,PlanId: planId,PlanBuildId: build.Id,ConvoMessageId: build.ConvoMessageId,Path: filePath,- Content: content,+ Content: activeBuild.FileContent,WillCheckSyntax: validationRes.HasParser && !validationRes.TimedOut,SyntaxValid: validationRes.Valid,SyntaxErrors: validationRes.Errors,diff --git a/app/server/model/plan/build_result.go b/app/server/model/plan/build_result.goindex aa8c0777..65e6d4a7 100644--- a/app/server/model/plan/build_result.go+++ b/app/server/model/plan/build_result.go@@ -76,8 +76,6 @@ func GetPlanResult(ctx context.Context, params PlanResultParams) (*db.PlanFileRenew := streamedChange.New- new = strings.ReplaceAll(new, "\\`\\`\\`", "```")-if streamedChange.Old.EntireFile {replacements = append(replacements, &shared.Replacement{EntireFile: true,diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex eea63880..8a99cbce 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -278,7 +278,7 @@ func execTellPlan(// if the user is continuing the plan, we need to check whether the previous message was a user message or assistant messagelastMessage := state.messages[len(state.messages)-1]- log.Println("User is continuing plan.") // Last message:\n\n", lastMessage.Content)+ log.Println("User is continuing plan. Last message:\n\n", lastMessage.Content)if lastMessage.Role == openai.ChatMessageRoleUser {// if last message was a user message, we want to remove it from the messages array and then use that last message as the prompt so we can continue from where the user left offdiff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex 633e874b..4f3c0e1d 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -46,13 +46,10 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionStreturn}- var lastParserRes *types.ReplyParserRes- var maybeRedundantMissingFileContent string- var chunksReceived int-replyFiles := []string{}+ chunksReceived := 0+ maybeRedundantBacktickContent := ""- var tempBuffer string// Create a timer that will trigger if no chunk is received within the specified durationtimer := time.NewTimer(model.OPENAI_STREAM_CHUNK_TIMEOUT)defer timer.Stop()@@ -336,139 +333,46 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionStreturn}+ chunksReceived++delta := choice.Deltacontent := delta.Content- chunksReceived++-- // log.Println("tell stream CHUNK: ", strconv.Quote(content))-if missingFileResponse != "" {- if maybeRedundantMissingFileContent != "" {+ if maybeRedundantBacktickContent != "" {if strings.Contains(content, "\n") {- maybeRedundantMissingFileContent = ""+ maybeRedundantBacktickContent = ""} else {- maybeRedundantMissingFileContent += content+ maybeRedundantBacktickContent += content}continue- } else if chunksReceived < 3 && strings.Contains(maybeRedundantMissingFileContent+content, "```") {- // received triple backticks in first 6 chunks after missing file response+ } else if chunksReceived < 3 && strings.Contains(content, "```") {+ // received closing triple backticks in first 3 chunks after missing file response// means this is a redundant start of a new file block, so just ignore it- maybeRedundantMissingFileContent += content- continue- }- }-- tempBuffer += content- filteredBuffer := tempBuffer-- // log.Println("tell stream BUFFER: ", strconv.Quote(filteredBuffer))-- if lastParserRes != nil && lastParserRes.MaybeFilePath != "" {- if strings.HasSuffix(filteredBuffer, "\n") {- // keep buffering so we don't end on a newline- continue- }-- if strings.Contains(filteredBuffer, "<block>") {- // this is an block tag denoting a code block, so we need to remove it- filteredBuffer = strings.Replace(filteredBuffer, "<block>", "", -1)- // remove 1 newline- filteredBuffer = strings.Replace(filteredBuffer, "\n", "", 1)- } else if isSuffixPrefix(filteredBuffer, "<block>") {- // keep buffering since this might be a partial block tag- continue- }- }-- if lastParserRes != nil {- // log.Println("tell stream currentFilePath: ", lastParserRes.CurrentFilePath)- }-- if lastParserRes != nil && lastParserRes.CurrentFilePath != "" {- if strings.Contains(filteredBuffer, "```") {- if strings.HasSuffix(filteredBuffer, "```") {- // if the buffer ends with triple backticks, keep buffering- // log.Println("tell Stream - buffer ends with triple backticks, keep buffering")- continue- } else {- if strings.Contains(filteredBuffer, "</block>") {- if strings.HasSuffix(filteredBuffer, "</block>") {- // if the buffer ends with an block tag, wait for the newline- // log.Println("tell Stream - buffer ends with block tag, keep buffering")- continue- }-- // log.Println("tell Stream - buffer contains block tag, filtering buffer")- // those were the closing backticks-- // remove the closing block tag- filteredBuffer = strings.Replace(filteredBuffer, "</block>", "", -1)-- // remove 1 newline from the end of the buffer- filteredBuffer = shared.ReplaceReverse(filteredBuffer, "\n", "", 1)-- // count the number of triple backticks in the buffer- backtickCount := strings.Count(filteredBuffer, "```")-- // if more than one, we need to escape all except the last one- if backtickCount > 1 {- filteredBuffer = strings.Replace(filteredBuffer, "```", "\\`\\`\\`", backtickCount-1)- }-- } else if isSuffixPrefix(filteredBuffer, "</block>") {- // keep buffering since this might be a partial closing block tag- // log.Println("tell Stream - buffer ends with partial closing block tag, keep buffering")- continue- } else if strings.HasSuffix(filteredBuffer, "\n") {- // keep buffering so we don't end on a newline- // log.Println("tell Stream - buffer ends with newline, keep buffering")- continue- } else if strings.HasSuffix(filteredBuffer, "`") {- // keep buffering since this might be a partial triple backtick and we don't want to break them up- // log.Println("tell Stream - buffer ends with partial triple backtick, keep buffering")- continue- } else {- // log.Println("tell Stream - buffer does not contain block tag, escaping backticks")- // no closing block tag- // so we need to escape any and all backticks- filteredBuffer = strings.Replace(filteredBuffer, "```", "\\`\\`\\`", -1)- }- }- } else if strings.HasSuffix(filteredBuffer, "`") {- // keep buffering since this might be a partial triple backtick- // log.Println("tell Stream - buffer ends with partial triple backtick, keep buffering")+ maybeRedundantBacktickContent += contentcontinue}}- // log.Println("tell Stream - filteredBuffer: ", strconv.Quote(filteredBuffer))- // log.Println()-UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {- ap.CurrentReplyContent += filteredBuffer+ ap.CurrentReplyContent += contentap.NumTokens++})- replyParser.AddChunk(filteredBuffer, true)+ // log.Printf("Sending stream msg: %s", content)+ active.Stream(shared.StreamMessage{+ Type: shared.StreamMessageReply,+ ReplyChunk: content,+ })++ replyParser.AddChunk(content, true)parserRes := replyParser.Read()- lastParserRes = &parserResfiles := parserRes.FilesfileContents := parserRes.FileContentsstate.replyNumTokens = parserRes.TotalTokenscurrentFile := parserRes.CurrentFilePathfileDescriptions := parserRes.FileDescriptions- // log.Printf("Sending stream msg: %s", filteredBuffer)- active.Stream(shared.StreamMessage{- Type: shared.StreamMessageReply,- ReplyChunk: filteredBuffer,- })-- // clear temp buffer- tempBuffer = ""-// log.Printf("currentFile: %s\n", currentFile)// log.Println("files:")// spew.Dump(files)@@ -756,15 +660,3 @@ func (state *activeTellStreamState) onError(streamErr error, storeDesc bool, conMsg: "Stream error: " + streamErr.Error(),}}--func isSuffixPrefix(a, b string) bool {- // Iterate through the lengths of possible prefixes of b- for i := 1; i <= len(b); i++ {- prefix := b[:i]- // Check if the end of a matches this prefix of b- if len(prefix) <= len(a) && a[len(a)-len(prefix):] == prefix {- return true- }- }- return false-}diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.goindex a88216ad..6a30f769 100644--- a/app/server/model/prompts/create.go+++ b/app/server/model/prompts/create.go@@ -27,16 +27,13 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context- src/main.rs:- lib/term.go:- main.py:- After the file path, there MUST ALWAYS WITHOUT FAIL be a line with nothing but '<block>' on it. Then the opening triple backticks for the code block should come immediately after the '<block>'. After the closing triple backticks of the code block, there MUST ALWAYS WITHOUT FAIL be a line with nothing but '</block>' on it. Do not include any other lines between the file path and the code block.- ***File paths MUST ALWAYS come *IMMEDIATELY before* the '<block> and the opening triple backticks of a code block. They should *not* be included in the code block itself. There MUST NEVER be *any other lines* between the file path, the '<block>' line, and the opening triple backticks. Any explanations should come either *before the file path or *after* the code block is closed by closing triple backticks and the closing '</block>' line.*+ ***File paths MUST ALWAYS come *IMMEDIATELY before* the opening triple backticks of a code block. They should *not* be included in the code block itself. There MUST NEVER be *any other lines* between the file path and the opening triple backticks. Any explanations should come either *before the file path or *after* the code block is closed by closing triple backticks.****You *must not* include **any other text** in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. Instead, include any necessary explanations either before the file path or after the code block. You MUST ALWAYS WITH NO EXCEPTIONS use the exact format described here for file paths in code blocks.***Do NOT include the file path again within the triple backticks, inside the code block itself. The file path must be included *only* in the file block label *preceding* the opening triple backticks.***- **EVERY CODE BLOCK** absolutely must begin with a file path label in the format described above, then a '<block>' on its own line, then the opening triple backticks for the code block. Immediately after the closing triple backticks of the code block, THERE ABSOLUTELY MUST ALWAYS be a line with nothing but '</block>' on it. You MUST NOT omit the '<block>' and '</block>' lines. ALWAYS include them, or else the code blocks won't be parsed correctly.**Labelled code block examples:- src/game.h:- <block>` + "```c" + `#ifndef GAME_LOGIC_H@@ -46,41 +43,6 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context#endif` + "```" + `- </block>-- - src/main.rs:- <block>- ` + "```rust" + `- fn main() {- println!("Hello, world!");- }- ` + "```" + `- </block>-- - src/component.ts:- <block>- ` + "```typescript" + `- export class Component {- constructor() {- console.log('Component created');- }- }- ` + "```" + `- </block>-- - docs/guide.md:- <block>- ` + "```markdown" + `- # Install-- To install the package, run the following command:-- ` + "\\`\\`\\`bash" + `- npm install my-package- ` + "\\`\\`\\`" + `- ` + "```" + `- </block>-b. If not:- Explicitly say "Let's break up this task."- Divide the task into smaller subtasks and list them in a numbered list. Subtasks MUST ALWAYS be numbered. Stop there.@@ -105,11 +67,11 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextFile block labels MUST ONLY include a *single* file path. You must NEVER include multiple files in a single file block. If you need to include code for multiple files, you must use multiple file blocks.- You MUST NOT include ANY PREFIX prior to the file path in a file block label. Include ONLY the EXACT file path like '- src/main.rs:' with no other text. You MUST NOT include the file path again in the code block itself. The file path must be included *only* in the file block label. There must be a SINGLE label for each file block, and the label must be placed immediately before the opening '<block>' and triple backticks of the code block. There must be NO other lines between the file path, the '<block>' line, and the opening triple backticks.+ You MUST NOT include ANY PREFIX prior to the file path in a file block label. Include ONLY the EXACT file path like '- src/main.rs:' with no other text. You MUST NOT include the file path again in the code block itself. The file path must be included *only* in the file block label. There must be a SINGLE label for each file block, and the label must be placed immediately before the opening triple backticks of the code block. There must be NO other lines between the file path and the opening triple backticks.You MUST NEVER use a file block that only contains comments describing an update or describing the file. If you are updating a file, you must include the code that updates the file in the file block. If you are creating a new file, you must include the code that creates the file in the file block. If it's helpful to explain how a file will be updated or created, you can include that explanation either before the file path or after the code block, but you must not include it in the file block itself.- You MUST NOT use the labelled file block format followed by '<block>' and triple backticks for **any purpose** other than creating or updating a file in the plan. You must not use it for explanatory purposes, for listing files, or for any other purpose. If you need to label a section or a list of files, use a markdown section header instead like this: '## Files to update'.+ You MUST NOT use the labelled file block format followed by triple backticks for **any purpose** other than creating or updating a file in the plan. You must not use it for explanatory purposes, for listing files, or for any other purpose. If you need to label a section or a list of files, use a markdown section header instead like this: '## Files to update'.If code is being removed from a file, the removal must be shown in a labelled file block according to your instructions. Use a comment within the file block to denote the removal like '// Plandex: removed the fooBar function' or '// Plandex: removed the loop'. Do NOT use any other formatting apart from a labelled file block to denote the removal.@@ -118,41 +80,6 @@ const SysCreate = Identity + ` A plan is a set of files with an attached contextFor code in markdown blocks, always include the language name after the opening triple backticks.If there are triple backticks within any file in context, they will be escaped with backslashes like this '` + "\\`\\`\\`" + `'. If you are outputting triple backticks in a code block, you MUST escape them in exactly the same way.-- If code or text within a code block includes triple backticks--in a markdown file, for example--you MUST ENSURE that all sections denoted by triple backticks are CLOSED before you close the code block with the final set of triple backticks and the closing '</block>' line.-- Instead of:-- - docs/guide.md:- <block>- ` + "```markdown" + `- # Install the package-- To install the package, run the following command:-- ` + "\\`\\`\\`bash" + `- npm install my-package- ` + "```" + `- </block>-- (Note the unclosed triple backticks in the code block)-- The correct output is:-- - docs/guide.md:- <block>- ` + "```markdown" + `- # Install the package-- To install the package, run the following command:-- ` + "\\`\\`\\`bash" + `- npm install my-package- ` + "\\`\\`\\`" + `- ` + "```" + `- </block>-- (Note the *closed* triple backticks in the code block)Don't include unnecessary comments in code. Lean towards no comments as much as you can. If you must include a comment to make the code understandable, be sure it is concise. Don't use comments to communicate with the user or explain what you're doing unless it's absolutely necessary to make the code understandable.@@ -305,7 +232,7 @@ If you're making a plan, remember to label code blocks with the file path *exactYou MUST NOT include any other text in a code block label apart from the initial '- ' and the EXACT file path ONLY. DO NOT UNDER ANY CIRCUMSTANCES use a label like 'File path: src/main.rs' or 'src/main.rs: (Create this file)' or 'File to Create: src/main.rs' or 'File to Update: src/main.rs'. Instead use EXACTLY 'src/main.rs:'. DO NOT include any explanatory text in the code block label like 'src/main.rs: (Add a new function)'. It is EXTREMELY IMPORTANT that the code block label includes *only* the initial '- ', the file path, and NO OTHER TEXT whatsoever. If additional text apart from the initial '- ' and the exact file path is included in the code block label, the plan will not be parsed properly and you will have failed at the task of generating a usable plan.-Always use a code block label, an opening '<block>' line, and opening triple backticks to start a code block. NEVER omit the opening '<block>' line. **Always** use closing triple backticks and a closing '</block>' line to end a code block. NEVER omit the closing '</block>' line. Do not include any other text in a code block apart from the code itself. Do not include any explanatory text or bullet points in code blocks. Only include code. Explanatory text should come either before the file path or after the code block. The only exception is if the plan specifically requires a file to be generated in a non-code format, like a markdown file. In that case, you can include the non-code content in the file block. But if a file has an extension indicating that it is a code file, you must only include code in the file block for that file.+Always use triple backticks to start and end code blocks.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.