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
remove exec.sh for now
Dane Schneider0f66e2266690
diff --git a/cli/lib/plan.go b/cli/lib/plan.goindex d57c7b5b..89c591aa 100644--- a/cli/lib/plan.go+++ b/cli/lib/plan.go@@ -73,21 +73,21 @@ func getCurrentPlanFiles() (shared.CurrentPlanFiles, error) {}}- var execContent string- var execExists bool- execPath := filepath.Join(CurrentPlanRootDir, "exec.sh")- _, err = os.Stat(execPath)- execExists = !os.IsNotExist(err)-- if execExists {- // exec.sh exists- // Read file content and set it to planFiles["exec"]- content, err := os.ReadFile(execPath)- if err != nil {- return shared.CurrentPlanFiles{}, err- }- execContent = string(content)- }-- return shared.CurrentPlanFiles{Files: planFiles.data, Exec: execContent}, nil+ // var execContent string+ // var execExists bool+ // execPath := filepath.Join(CurrentPlanRootDir, "exec.sh")+ // _, err = os.Stat(execPath)+ // execExists = !os.IsNotExist(err)++ // if execExists {+ // // exec.sh exists+ // // Read file content and set it to planFiles["exec"]+ // content, err := os.ReadFile(execPath)+ // if err != nil {+ // return shared.CurrentPlanFiles{}, err+ // }+ // execContent = string(content)+ // }++ return shared.CurrentPlanFiles{Files: planFiles.data /*Exec: execContent*/}, nil}diff --git a/cli/lib/proposal.go b/cli/lib/proposal.goindex 9667fb0b..c54abe51 100644--- a/cli/lib/proposal.go+++ b/cli/lib/proposal.go@@ -158,14 +158,14 @@ func Propose(prompt string) error {return}- if desc.MadePlan && (len(desc.Files) > 0 || desc.HasExec) {+ if desc.MadePlan && (len(desc.Files) > 0 /*|| desc.HasExec*/) {fmt.Println("Writing plan draft:")for _, filePath := range desc.Files {fmt.Printf("- %s\n", filePath)}- if desc.HasExec {- fmt.Printf("- %s\n", "exec.sh")- }+ // if desc.HasExec {+ // fmt.Printf("- %s\n", "exec.sh")+ // }}}@@ -182,11 +182,13 @@ func Propose(prompt string) error {return}- files := make([]string, len(desc.Files))- copy(files, desc.Files)- if desc.HasExec {- files = append(files, "exec.sh")- }+ // files := make([]string, len(desc.Files))+ // copy(files, desc.Files)+ // if desc.HasExec {+ // files = append(files, "exec.sh")+ // }++ files := desc.Files// Clear previous linesmoveUpLines(len(files))diff --git a/cli/lib/stream.go b/cli/lib/stream.goindex 542bb90b..ff2afba2 100644--- a/cli/lib/stream.go+++ b/cli/lib/stream.go@@ -18,11 +18,11 @@ func receiveFileChunk(content string, desc *shared.PlanDescription, jsonBuffers}var filePath string- if chunk.IsExec {- filePath = filepath.Join(PlanSubdir, "exec.sh")- } else {- filePath = filepath.Join(PlanFilesDir, chunk.FilePath)- }+ // if chunk.IsExec {+ // filePath = filepath.Join(PlanSubdir, "exec.sh")+ // } else {+ filePath = filepath.Join(PlanFilesDir, chunk.FilePath)+ // }buffer := jsonBuffers[chunk.FilePath]buffer += chunk.Contentdiff --git a/server/model/context.go b/server/model/context.goindex 1cfb2d06..5ef03d94 100644--- a/server/model/context.go+++ b/server/model/context.go@@ -30,9 +30,9 @@ func FormatCurrentPlan(plan shared.CurrentPlanFiles) string {planMessages = append(planMessages, fmt.Sprintf("\n\n-file: %s\n\n```%s```", path, content))}- if plan.Exec != "" {- planMessages = append(planMessages, fmt.Sprintf("\n\n-exec: %s", plan.Exec))- }+ // if plan.Exec != "" {+ // planMessages = append(planMessages, fmt.Sprintf("\n\n-exec: %s", plan.Exec))+ // }return strings.Join(planMessages, "\n")}diff --git a/server/model/proposal/confirm.go b/server/model/proposal/confirm.goindex a2cece41..73d9b9a3 100644--- a/server/model/proposal/confirm.go+++ b/server/model/proposal/confirm.go@@ -8,11 +8,8 @@ import ("os""plandex-server/model""plandex-server/types"- "strings"- "sync""time"- lorem "github.com/drhodes/golorem""github.com/plandex/plandex/shared""github.com/sashabaranov/go-openai""github.com/sashabaranov/go-openai/jsonschema"@@ -37,9 +34,9 @@ func confirmProposal(proposalId string, onStream types.OnStreamFunc) error {ctx, cancel := context.WithCancel(context.Background())plans.Set(proposalId, &types.Plan{- ProposalId: proposalId,- NumFiles: len(proposal.PlanDescription.Files),- HasExec: proposal.PlanDescription.HasExec,+ ProposalId: proposalId,+ NumFiles: len(proposal.PlanDescription.Files),+ // HasExec: proposal.PlanDescription.HasExec,Files: map[string]string{},FileErrs: map[string]error{},FilesFinished: map[string]bool{},@@ -196,7 +193,7 @@ func confirmProposal(proposalId string, onStream types.OnStreamFunc) error {chunk := &shared.PlanChunk{FilePath: filePath,Content: content,- IsExec: false,+ // IsExec: false,}// fmt.Printf("%s: %s", filePath, content)@@ -212,205 +209,146 @@ func confirmProposal(proposalId string, onStream types.OnStreamFunc) error {}(filePath)}- if !proposal.PlanDescription.HasExec {- fmt.Println("No exec.sh to parse")- return nil- }-- onExecErr := func(err error) {- plans.Update(proposalId, func(p *types.Plan) {- p.ExecErr = err- p.SetErr(err)- })-- onStream("", err)- }- go func() {- fmt.Println("Getting exec.sh from model: ")-- // Define the model request for exec.sh- modelReq := openai.ChatCompletionRequest{- Model: openai.GPT4,- Functions: []openai.FunctionDefinition{{- Name: "writeExec",- Parameters: &jsonschema.Definition{- Type: jsonschema.Object,- Properties: map[string]jsonschema.Definition{- "content": {- Type: jsonschema.String,- Description: "The shell script from the previous message, including any updates",- },- },- Required: []string{"content"},- },- }},- Messages: []openai.ChatCompletionMessage{- {- Role: openai.ChatMessageRoleSystem,- Content: "You are an AI parser that extracts shell commands from an AI-generated programming plan. Call the 'writeExec' function with any commands in '- exec' blocks in the previous response and combine them into a single shell script--pass only the raw text of the shell script to 'writeExec'. Only call the 'writeExec' function in your response. Don't call any other function.",- },- {- Role: openai.ChatMessageRoleAssistant,- Content: proposal.Content,- },- {- Role: openai.ChatMessageRoleUser,- Content: fmt.Sprintf(`- Based on your previous response, call the 'writeExec' function with a script that should be run after any relevant files are created and/or updated. If no commands should be executed, pass only 'no exec commands' to the 'writeExec' function. Otherwise, pass the full script as raw text to the function and output nothing else.- `),- },- },- }-- stream, err := model.Client.CreateChatCompletionStream(ctx, modelReq)- if err != nil {- fmt.Println("Error creating shell script stream: " + err.Error())- onExecErr(err)- return- }-- defer stream.Close()-- // Create a timer that will trigger if no chunk is received within the specified duration- timer := time.NewTimer(model.OPENAI_STREAM_CHUNK_TIMEOUT)- defer timer.Stop()-- for {- select {- case <-ctx.Done():- // The main context was canceled (not the timer)- return- case <-timer.C:- // Timer triggered because no new chunk was received in time- fmt.Println("\nStream timeout due to inactivity")- err = fmt.Errorf("stream timeout due to inactivity")- onExecErr(err)- return- default:- response, err := stream.Recv()-- if err == nil {- // Successfully received a chunk, reset the timer- if !timer.Stop() {- <-timer.C- }- timer.Reset(model.OPENAI_STREAM_CHUNK_TIMEOUT)- }-- if err != nil {- onExecErr(fmt.Errorf("Stream error for exec.sh: %v", err))- return- }-- if len(response.Choices) == 0 {- onExecErr(fmt.Errorf("Stream error for exec.sh: no choices"))- return- }-- choice := response.Choices[0]-- if choice.FinishReason != "" {- if choice.FinishReason == openai.FinishReasonFunctionCall {- finished := false- plans.Update(proposalId, func(plan *types.Plan) {- plan.ExecFinished = true-- if plan.DidFinish() {- plan.Finish()- finished = true- }- })-- if finished {- fmt.Println("Stream finished")- onStream(shared.STREAM_FINISHED, nil)- return- }-- } else {- onExecErr(fmt.Errorf("Stream finished without 'writeExec' function call. Reason: %s", choice.FinishReason))- return- }-- return- }-- var content string- delta := choice.Delta- if delta.FunctionCall != nil && delta.FunctionCall.Name == "writeExec" {- content = delta.FunctionCall.Arguments- }-- chunk := shared.PlanChunk{IsExec: true, Content: content}- chunkJson, err := json.Marshal(chunk)- if err != nil {- onExecErr(fmt.Errorf("error marshalling exec.sh chunk: %v", err))- return- }-- onStream(string(chunkJson), nil)- }- }- }()+ // if !proposal.PlanDescription.HasExec {+ // fmt.Println("No exec.sh to parse")+ // return nil+ // }++ // onExecErr := func(err error) {+ // plans.Update(proposalId, func(p *types.Plan) {+ // p.ExecErr = err+ // p.SetErr(err)+ // })++ // onStream("", err)+ // }+ // go func() {+ // fmt.Println("Getting exec.sh from model: ")++ // // Define the model request for exec.sh+ // modelReq := openai.ChatCompletionRequest{+ // Model: openai.GPT4,+ // Functions: []openai.FunctionDefinition{{+ // Name: "writeExec",+ // Parameters: &jsonschema.Definition{+ // Type: jsonschema.Object,+ // Properties: map[string]jsonschema.Definition{+ // "content": {+ // Type: jsonschema.String,+ // Description: "The shell script from the previous message, including any updates",+ // },+ // },+ // Required: []string{"content"},+ // },+ // }},+ // Messages: []openai.ChatCompletionMessage{+ // {+ // Role: openai.ChatMessageRoleSystem,+ // Content: "You are an AI parser that extracts shell commands from an AI-generated programming plan. Call the 'writeExec' function with any commands in '- exec' blocks in the previous response and combine them into a single shell script--pass only the raw text of the shell script to 'writeExec'. Only call the 'writeExec' function in your response. Don't call any other function.",+ // },+ // {+ // Role: openai.ChatMessageRoleAssistant,+ // Content: proposal.Content,+ // },+ // {+ // Role: openai.ChatMessageRoleUser,+ // Content: fmt.Sprintf(`+ // Based on your previous response, call the 'writeExec' function with a script that should be run after any relevant files are created and/or updated. If no commands should be executed, pass only 'no exec commands' to the 'writeExec' function. Otherwise, pass the full script as raw text to the function and output nothing else.+ // `),+ // },+ // },+ // }++ // stream, err := model.Client.CreateChatCompletionStream(ctx, modelReq)+ // if err != nil {+ // fmt.Println("Error creating shell script stream: " + err.Error())+ // onExecErr(err)+ // return+ // }++ // defer stream.Close()++ // // Create a timer that will trigger if no chunk is received within the specified duration+ // timer := time.NewTimer(model.OPENAI_STREAM_CHUNK_TIMEOUT)+ // defer timer.Stop()++ // for {+ // select {+ // case <-ctx.Done():+ // // The main context was canceled (not the timer)+ // return+ // case <-timer.C:+ // // Timer triggered because no new chunk was received in time+ // fmt.Println("\nStream timeout due to inactivity")+ // err = fmt.Errorf("stream timeout due to inactivity")+ // onExecErr(err)+ // return+ // default:+ // response, err := stream.Recv()++ // if err == nil {+ // // Successfully received a chunk, reset the timer+ // if !timer.Stop() {+ // <-timer.C+ // }+ // timer.Reset(model.OPENAI_STREAM_CHUNK_TIMEOUT)+ // }++ // if err != nil {+ // onExecErr(fmt.Errorf("Stream error for exec.sh: %v", err))+ // return+ // }++ // if len(response.Choices) == 0 {+ // onExecErr(fmt.Errorf("Stream error for exec.sh: no choices"))+ // return+ // }++ // choice := response.Choices[0]++ // if choice.FinishReason != "" {+ // if choice.FinishReason == openai.FinishReasonFunctionCall {+ // finished := false+ // plans.Update(proposalId, func(plan *types.Plan) {+ // plan.ExecFinished = true++ // if plan.DidFinish() {+ // plan.Finish()+ // finished = true+ // }+ // })++ // if finished {+ // fmt.Println("Stream finished")+ // onStream(shared.STREAM_FINISHED, nil)+ // return+ // }++ // } else {+ // onExecErr(fmt.Errorf("Stream finished without 'writeExec' function call. Reason: %s", choice.FinishReason))+ // return+ // }++ // return+ // }++ // var content string+ // delta := choice.Delta+ // if delta.FunctionCall != nil && delta.FunctionCall.Name == "writeExec" {+ // content = delta.FunctionCall.Arguments+ // }++ // chunk := shared.PlanChunk{IsExec: true, Content: content}+ // chunkJson, err := json.Marshal(chunk)+ // if err != nil {+ // onExecErr(fmt.Errorf("error marshalling exec.sh chunk: %v", err))+ // return+ // }++ // onStream(string(chunkJson), nil)+ // }+ // }+ // }()return nil}--func streamFilesLoremIpsum(onStream types.OnStreamFunc) {- writeChunk := func(filePath string, isExec bool, content string) {- chunk := shared.PlanChunk{FilePath: filePath, Content: content, IsExec: isExec}- chunkJson, _ := json.Marshal(chunk)- onStream(string(chunkJson), nil)- time.Sleep(50 * time.Millisecond) // Adding a small delay between files for effect- }-- // For each file in the proposal, stream some unstyled lorem ipsum content- var wg sync.WaitGroup- files := []string{"file1.txt", "file2.txt"}- for _, filePath := range files {- wg.Add(1)- go func(filePath string) {- defer wg.Done()- text := strings.Join([]string{lorem.Paragraph(2, 3), lorem.Paragraph(2, 3), lorem.Paragraph(2, 3)}, "\n\n")- streamedFile := shared.StreamedFile{Content: text}- fileContent, _ := json.Marshal(streamedFile)-- for _, line := range strings.Split(string(fileContent), "\n") {- for _, word := range strings.Split(line, " ") {- writeChunk(filePath, false, word+" ")- }- writeChunk(filePath, false, "\n")- }- }(filePath)- }-- // For the exec.sh script, generate a script that echoes some lorem ipsum content-- echoContent := `#!/bin/sh-echo "` + lorem.Sentence(5, 6) + `"` +- `- echo "` + lorem.Sentence(5, 6) + `"` +- `- echo "hi"`-- fmt.Println("exec.sh content: " + echoContent)-- streamedFile := shared.StreamedFile{Content: echoContent}- fileContent, _ := json.Marshal(streamedFile)-- wg.Add(1)-- go func() {- defer wg.Done()- for _, line := range strings.Split(string(fileContent), "\n") {- for _, word := range strings.Split(line, " ") {- writeChunk("", true, word+" ")- }- writeChunk("", true, "\n")- }- }()-- wg.Wait()-- onStream(shared.STREAM_FINISHED, nil)-}diff --git a/server/model/proposal/create.go b/server/model/proposal/create.goindex f33d1a62..d2e51a12 100644--- a/server/model/proposal/create.go+++ b/server/model/proposal/create.go@@ -2,26 +2,22 @@ package proposalimport ("context"- "encoding/json""fmt""os"- "strings""time""plandex-server/model""plandex-server/types"- lorem "github.com/drhodes/golorem""github.com/google/uuid""github.com/plandex/plandex/shared""github.com/sashabaranov/go-openai"- "github.com/sashabaranov/go-openai/jsonschema")const systemMessageHead = `You are Plandex, an AI programming and system administration assistant. You offer a structured, versioned, and iterative approach to AI-driven development.- You and the programmer collaborate to create a 'plan' for the task at hand. A plan is a set of files and an 'exec' script with an attached context.+ You and the programmer collaborate to create a 'plan' for the task at hand. A plan is a set of files with an attached context.Based on user-provided context, create a plan for the task using the following steps:@@ -31,18 +27,18 @@ const systemMessageHead = `- Ask the user for more information or context and stop there.2. Decide whether this task is small enough to be completed in a single response.- a. If so, write out the code and commands to complete the task.+ a. If so, write out the code to complete the task. Precede the code with the file path like this '- file_path:'.b. If not:- Explicitly say "I will break this large task into subtasks."- Divide the task into smaller subtasks and list them in a numbered list. Stop there.- When suggesting changes that would modify files from the context or create new files, always precede them with the file path like this '- file_path:'.+ Always precede code blocks them with the file path like this '- file_path:'.Code should always be inside a file block labelled with the path. You can have multiple blocks labelled with the same file path. Every file you reference should either exist in the context directly or be a new file that will be created in the same base directory as the context file paths.- Don't include unnecessary comments in code. Only add comments if they make the code significantly more readable. Make comments concise.+ For code in markdown blocks, always include the language name after the opening triple backticks.- When suggesting commands that should be run, always precede them with '- exec:'. For code or commands in markdown blocks, always include the language name after the opening triple backticks.+ Don't include unnecessary comments in code. Only add comments if they make the code significantly more readable. Make comments concise.At the end of a plan, you can suggest additional iterations to make the plan better. You can also ask the user to load more files or information into context if it would help you make a better plan.@@ -187,7 +183,7 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) erroronStream(planDescriptionJson, nil)- if planDescription.MadePlan && (len(planDescription.Files) > 0 || planDescription.HasExec) {+ if planDescription.MadePlan && (len(planDescription.Files) > 0 /*|| planDescription.HasExec*/) {onStream(shared.STREAM_BUILD_PHASE, nil)err = confirmProposal(proposalId, onStream)if err != nil {@@ -215,163 +211,3 @@ func CreateProposal(req shared.PromptRequest, onStream types.OnStreamFunc) errorreturn nil}--func genPlanDescriptionJson(proposalId string, ctx context.Context) (*shared.PlanDescription, string, error) {- proposal := proposals.Get(proposalId)-- planDescResp, err := model.Client.CreateChatCompletion(- ctx,- openai.ChatCompletionRequest{- Model: openai.GPT4,- Functions: []openai.FunctionDefinition{{- Name: "describePlan",- Parameters: &jsonschema.Definition{- Type: jsonschema.Object,- Properties: map[string]jsonschema.Definition{- "madePlan": {- Type: jsonschema.Boolean,- Description: "Whether a plan was made that includes code or commands. Should be false if 'subtasks' is true",- },- "subtasks": {- Type: jsonschema.Boolean,- Description: "Whether the task is too large to be completed in a single response and was broken up into subtasks. If 'madePlan' is true, this should be false",- },- "commitMsg": {- Type: jsonschema.String,- Description: "A good commit message for the changes proposed. If 'madePlan' is false, this should be an empty string",- },- "files": {- Type: jsonschema.Array,- Description: "An array of file paths to be created or updated in the plan. If 'madePlan' is false, this should be an empty array.",- Items: &jsonschema.Definition{- Type: jsonschema.String,- },- },- "hasExec": {- Type: jsonschema.Boolean,- Description: "Whether the plan includes any 'exec' blocks that include shell commands. If 'madePlan' is false, this should be false",- },- },- Required: []string{"madePlan", "subtasks", "commitMsg", "files", "hasExec"},- },- }},- Messages: []openai.ChatCompletionMessage{- {- Role: openai.ChatMessageRoleSystem,- Content: "You are an AI parser. You turn an AI's plan for a programming task into a structured description. You call the 'describePlan' function with arguments 'madePlan', 'subtasks', 'commitMsg', 'files', and 'hasExec'. Only call the 'describePlan' function in your response. Don't call any other function.",- },- {- Role: openai.ChatMessageRoleAssistant,- Content: proposal.Content,- },- },- },- )-- var planDescStrRes string- var planDesc shared.PlanDescription-- if err != nil {- fmt.Printf("Error during plan description model call: %v\n", err)- planDesc = shared.PlanDescription{}- bytes, err := json.Marshal(planDesc)- return &planDesc, string(bytes), err- }-- for _, choice := range planDescResp.Choices {- if choice.FinishReason == "function_call" &&- choice.Message.FunctionCall != nil &&- choice.Message.FunctionCall.Name == "describePlan" {- fnCall := choice.Message.FunctionCall- planDescStrRes = fnCall.Arguments- }- }-- if planDescStrRes == "" {- fmt.Println("no describePlan function call found in response")- planDesc = shared.PlanDescription{}- bytes, err := json.Marshal(planDesc)- return &planDesc, string(bytes), err- }-- planDescByteRes := []byte(planDescStrRes)-- err = json.Unmarshal(planDescByteRes, &planDesc)- if err != nil {- fmt.Printf("Error unmarshalling plan description response: %v\n", err)- return nil, "", err- }-- for i, filePath := range planDesc.Files {- filePath = strings.TrimSpace(filePath)- filePath = strings.TrimPrefix(filePath, "-")- filePath = strings.TrimSpace(filePath)- planDesc.Files[i] = filePath- fmt.Println("file path: " + filePath)- }-- bytes, err := json.Marshal(planDesc)- if err != nil {- fmt.Printf("Error marshalling plan description: %v\n", err)- return nil, "", err- }-- return &planDesc, string(bytes), nil-}--func applyLoremStyling(paragraphs []string) []string {- for p, paragraph := range paragraphs {- sentences := strings.Split(paragraph, ". ")- for _, sentence := range sentences {- words := strings.Split(sentence, " ")- for i, word := range words {- if (i+1)%5 == 0 { // Bold every 5th word- words[i] = "**" + word + "**"- }- if (i+1)%8 == 0 { // Italicize every 8th word- words[i] = "_" + word + "_"- }- if (i+1)%7 == 0 { // Color every 7th word- words[i] = `<span style="color:blue">` + word + `</span>`- }- }- }- paragraphs[p] = strings.Join(sentences, ". ")- }- return paragraphs-}--// Function to stream "lorem ipsum" text sentence by sentence with delay-func streamLoremIpsum(onStream types.OnStreamFunc) {- paragraphs := []string{lorem.Paragraph(2, 3), lorem.Paragraph(2, 3), lorem.Paragraph(2, 3)}- paragraphs = applyLoremStyling(paragraphs)-- for _, paragraph := range paragraphs {- for _, line := range strings.Split(paragraph, "\n") {- for _, word := range strings.Split(line, " ") {- onStream(word+" ", nil)- time.Sleep(50 * time.Millisecond)- }- onStream("\n", nil)- time.Sleep(50 * time.Millisecond)- }- onStream("\n\n", nil)- time.Sleep(50 * time.Millisecond)- }- onStream(shared.STREAM_DESCRIPTION_PHASE, nil)-- planDescription := &shared.PlanDescription{- MadePlan: true,- Files: []string{"file1.txt", "file2.txt"},- HasExec: true,- }- planDescriptionBytes, _ := json.Marshal(planDescription)- planDescriptionJson := string(planDescriptionBytes)- time.Sleep(2000 * time.Millisecond)-- onStream(planDescriptionJson, nil)-- onStream(shared.STREAM_BUILD_PHASE, nil)- confirmProposal("", onStream)--}diff --git a/server/model/proposal/describe.go b/server/model/proposal/describe.gonew file mode 100644index 00000000..8b4610ec--- /dev/null+++ b/server/model/proposal/describe.go@@ -0,0 +1,116 @@+package proposal++import (+ "context"+ "encoding/json"+ "fmt"+ "plandex-server/model"+ "strings"++ "github.com/plandex/plandex/shared"+ "github.com/sashabaranov/go-openai"+ "github.com/sashabaranov/go-openai/jsonschema"+)++func genPlanDescriptionJson(proposalId string, ctx context.Context) (*shared.PlanDescription, string, error) {+ proposal := proposals.Get(proposalId)++ planDescResp, err := model.Client.CreateChatCompletion(+ ctx,+ openai.ChatCompletionRequest{+ Model: openai.GPT4,+ Functions: []openai.FunctionDefinition{{+ Name: "describePlan",+ Parameters: &jsonschema.Definition{+ Type: jsonschema.Object,+ Properties: map[string]jsonschema.Definition{+ "madePlan": {+ Type: jsonschema.Boolean,+ Description: "Whether a plan was made that includes file paths and code. Should be false if 'subtasks' is true or 'files' is empty",+ },+ "subtasks": {+ Type: jsonschema.Boolean,+ Description: "Whether the task is too large to be completed in a single response and was broken up into subtasks. If 'madePlan' is true, this should be false",+ },+ "files": {+ Type: jsonschema.Array,+ Description: "An array of file paths that precede code blocks in the plan. If 'madePlan' is false or 'subtasks' is true, this should be an empty array.",+ Items: &jsonschema.Definition{+ Type: jsonschema.String,+ },+ },+ "commitMsg": {+ Type: jsonschema.String,+ Description: "A good commit message for the changes proposed. If 'madePlan' is false or 'subtasks' is true, this should be an empty string",+ },+ // "hasExec": {+ // Type: jsonschema.Boolean,+ // Description: "Whether the plan includes any 'exec' blocks that include shell commands. If 'madePlan' is false, this should be false",+ // },+ },+ Required: []string{"madePlan", "subtasks", "commitMsg", "files" /*"hasExec"*/},+ },+ }},+ Messages: []openai.ChatCompletionMessage{+ {+ Role: openai.ChatMessageRoleSystem,+ Content: "You are an AI parser. You turn an AI's plan for a programming task into a structured description. You call the 'describePlan' function with arguments 'madePlan', 'subtasks', 'commitMsg', 'files', and 'hasExec'. Only call the 'describePlan' function in your response. Don't call any other function.",+ },+ {+ Role: openai.ChatMessageRoleAssistant,+ Content: proposal.Content,+ },+ },+ },+ )++ var planDescStrRes string+ var planDesc shared.PlanDescription++ if err != nil {+ fmt.Printf("Error during plan description model call: %v\n", err)+ planDesc = shared.PlanDescription{}+ bytes, err := json.Marshal(planDesc)+ return &planDesc, string(bytes), err+ }++ for _, choice := range planDescResp.Choices {+ if choice.FinishReason == "function_call" &&+ choice.Message.FunctionCall != nil &&+ choice.Message.FunctionCall.Name == "describePlan" {+ fnCall := choice.Message.FunctionCall+ planDescStrRes = fnCall.Arguments+ }+ }++ if planDescStrRes == "" {+ fmt.Println("no describePlan function call found in response")+ planDesc = shared.PlanDescription{}+ bytes, err := json.Marshal(planDesc)+ return &planDesc, string(bytes), err+ }++ planDescByteRes := []byte(planDescStrRes)++ err = json.Unmarshal(planDescByteRes, &planDesc)+ if err != nil {+ fmt.Printf("Error unmarshalling plan description response: %v\n", err)+ return nil, "", err+ }++ for i, filePath := range planDesc.Files {+ filePath = strings.TrimSpace(filePath)+ filePath = strings.TrimPrefix(filePath, "-")+ filePath = strings.TrimSpace(filePath)+ planDesc.Files[i] = filePath+ fmt.Println("file path: " + filePath)+ }++ bytes, err := json.Marshal(planDesc)+ if err != nil {+ fmt.Printf("Error marshalling plan description: %v\n", err)+ return nil, "", err+ }++ return &planDesc, string(bytes), nil+}diff --git a/server/model/proposal/lorem_ipsum.go b/server/model/proposal/lorem_ipsum.gonew file mode 100644index 00000000..e6962820--- /dev/null+++ b/server/model/proposal/lorem_ipsum.go@@ -0,0 +1,128 @@+package proposal++import (+ "encoding/json"+ "plandex-server/types"+ "strings"+ "sync"+ "time"++ lorem "github.com/drhodes/golorem"+ "github.com/plandex/plandex/shared"+)++func applyLoremStyling(paragraphs []string) []string {+ for p, paragraph := range paragraphs {+ sentences := strings.Split(paragraph, ". ")+ for _, sentence := range sentences {+ words := strings.Split(sentence, " ")+ for i, word := range words {+ if (i+1)%5 == 0 { // Bold every 5th word+ words[i] = "**" + word + "**"+ }+ if (i+1)%8 == 0 { // Italicize every 8th word+ words[i] = "_" + word + "_"+ }+ if (i+1)%7 == 0 { // Color every 7th word+ words[i] = `<span style="color:blue">` + word + `</span>`+ }+ }+ }+ paragraphs[p] = strings.Join(sentences, ". ")+ }+ return paragraphs+}++// Function to stream "lorem ipsum" text sentence by sentence with delay+func streamLoremIpsum(onStream types.OnStreamFunc) {+ paragraphs := []string{lorem.Paragraph(2, 3), lorem.Paragraph(2, 3), lorem.Paragraph(2, 3)}+ paragraphs = applyLoremStyling(paragraphs)++ for _, paragraph := range paragraphs {+ for _, line := range strings.Split(paragraph, "\n") {+ for _, word := range strings.Split(line, " ") {+ onStream(word+" ", nil)+ time.Sleep(50 * time.Millisecond)+ }+ onStream("\n", nil)+ time.Sleep(50 * time.Millisecond)+ }+ onStream("\n\n", nil)+ time.Sleep(50 * time.Millisecond)+ }+ onStream(shared.STREAM_DESCRIPTION_PHASE, nil)++ planDescription := &shared.PlanDescription{+ MadePlan: true,+ Files: []string{"file1.txt", "file2.txt"},+ // HasExec: true,+ }+ planDescriptionBytes, _ := json.Marshal(planDescription)+ planDescriptionJson := string(planDescriptionBytes)+ time.Sleep(2000 * time.Millisecond)++ onStream(planDescriptionJson, nil)++ onStream(shared.STREAM_BUILD_PHASE, nil)+ confirmProposal("", onStream)++}++func streamFilesLoremIpsum(onStream types.OnStreamFunc) {+ writeChunk := func(filePath string, isExec bool, content string) {+ chunk := shared.PlanChunk{FilePath: filePath, Content: content /*IsExec: isExec*/}+ chunkJson, _ := json.Marshal(chunk)+ onStream(string(chunkJson), nil)+ time.Sleep(50 * time.Millisecond) // Adding a small delay between files for effect+ }++ // For each file in the proposal, stream some unstyled lorem ipsum content+ var wg sync.WaitGroup+ files := []string{"file1.txt", "file2.txt"}+ for _, filePath := range files {+ wg.Add(1)+ go func(filePath string) {+ defer wg.Done()+ text := strings.Join([]string{lorem.Paragraph(2, 3), lorem.Paragraph(2, 3), lorem.Paragraph(2, 3)}, "\n\n")+ streamedFile := shared.StreamedFile{Content: text}+ fileContent, _ := json.Marshal(streamedFile)++ for _, line := range strings.Split(string(fileContent), "\n") {+ for _, word := range strings.Split(line, " ") {+ writeChunk(filePath, false, word+" ")+ }+ writeChunk(filePath, false, "\n")+ }+ }(filePath)+ }++ // For the exec.sh script, generate a script that echoes some lorem ipsum content++ // echoContent := `#!/bin/sh+ // echo "` + lorem.Sentence(5, 6) + `"` ++ // `+ // echo "` + lorem.Sentence(5, 6) + `"` ++ // `+ // echo "hi"`++ // fmt.Println("exec.sh content: " + echoContent)++ // streamedFile := shared.StreamedFile{Content: echoContent}+ // fileContent, _ := json.Marshal(streamedFile)++ // wg.Add(1)++ // go func() {+ // defer wg.Done()+ // for _, line := range strings.Split(string(fileContent), "\n") {+ // for _, word := range strings.Split(line, " ") {+ // writeChunk("", true, word+" ")+ // }+ // writeChunk("", true, "\n")+ // }+ // }()++ wg.Wait()++ onStream(shared.STREAM_FINISHED, nil)+}diff --git a/server/types/plan.go b/server/types/plan.goindex b80961bd..f7bdbac6 100644--- a/server/types/plan.go+++ b/server/types/plan.go@@ -1,22 +1,22 @@package typestype Plan struct {- ProposalId string- NumFiles int- Files map[string]string- HasExec bool- Exec string- ExecErr error- ExecFinished bool+ ProposalId string+ NumFiles int+ Files map[string]string+ // HasExec bool+ // Exec string+ // ExecErr error+ // ExecFinished boolFilesFinished map[string]boolFileErrs map[string]errorProposalStage}func (s *Plan) DidFinish() bool {- if s.HasExec && !s.ExecFinished {- return false- }+ // if s.HasExec && !s.ExecFinished {+ // return false+ // }return len(s.FilesFinished) == int(s.NumFiles)}diff --git a/shared/types.go b/shared/types.goindex 5b1e50ae..b9406463 100644--- a/shared/types.go+++ b/shared/types.go@@ -6,7 +6,7 @@ import (type CurrentPlanFiles struct {Files map[string]string `json:"files"`- Exec string `json:"exec"`+ // Exec string `json:"exec"`}type PromptRequest struct {@@ -26,13 +26,6 @@ type SummarizeResponse struct {FileName string `json:"fileName"`}-type PromptResponse struct {- Summary string `json:"summary"`- CommitMsg string `json:"commitMsg"`- Files map[string]string `json:"files"`- Exec string `json:"exec"`-}-type ModelContextPart struct {Name string `json:"name"`Summary string `json:"summary"`@@ -61,7 +54,7 @@ type PlanChunk struct {Type string `json:"type"`FilePath string `json:"filePath"`Content string `json:"content"`- IsExec bool `json:"isExec"`+ // IsExec bool `json:"isExec"`}type PlanDescription struct {@@ -69,24 +62,5 @@ type PlanDescription struct {Subtasks bool `json:"subtasks"`CommitMsg string `json:"commitMsg"`Files []string `json:"files"`- HasExec bool `json:"hasExec"`+ // HasExec bool `json:"hasExec"`}--// type Plan struct {-// Id string-// Name string-// Summary string-// Creator string-// CreatedAt string-// UpdatedAt string--// ContextVersionNum uint32-// ContextSha string-// ContextUpdatedAt string-// ContextUpdatedBy string--// RevisionNum uint32-// RevisionSha string-// RevisedAt string-// RevisedBy string-// }