Skip to content

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

lots of fixes, work on build improvements (still issues here), work on versioning/releases

Dane Schneider30053666655b
diff --git a/PRIVACY.md b/PRIVACY.md
index 04d73f66..e69ce014 100644
--- a/PRIVACY.md
+++ b/PRIVACY.md
@@ -4,7 +4,7 @@
Data you send to Plandex Cloud is retained in order to debug and improve Plandex. In the future, this data may also be used to train and fine-tune models to improve performance.
-That said, if you delete a plan or delete your Plandex Cloud account, all associated data will be removed from the database. It will still be included in database backups for up to 7 days, then it will no longer exist anywhere on Plandex Cloud.
+That said, if you delete a plan or delete your Plandex Cloud account, all associated data will be removed. It will still be included in backups for up to 7 days, then it will no longer exist anywhere on Plandex Cloud.
Data sent to Plandex Cloud may be shared with the following third parties:
diff --git a/README.md b/README.md
index bd1f4122..8450033a 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,28 @@
## ๐ŸŒŸ Build large features and entire projects with AI.
-๐Ÿ”ฎ Plandex is an open source, terminal-based AI programming engine with long-running agents, automatic file updates, versioning, branches, and diff review.
+๐Ÿ”ฎ Plandex is an open source, terminal-based AI programming engine with long-running agents, context management, versioning, branches, diff review, a protected sandbox for changes, and automatic file updates.
-๐Ÿ”„ It enables a tight feedback loop between programmer and AI.
+๐Ÿฅ‡ It's the best tool available for driving robust, end-to-end software development with AI.
๐Ÿ’ช It helps you churn through your backlog, work with unfamiliar technologies, get unstuck, and spend less time on tedious tasks.
๐Ÿง  Plandex relies on the OpenAI API and requires an `OPENAI_API_KEY` environment variable. Support for open source models, Google Gemini, and Anthropic Claude is coming soon.
-โœ… Plandex supports Mac, Linux, and Windows (Windows supported via [Git bash](https://gitforwindows.org) or [WSL](https://learn.microsoft.com/en-us/windows/wsl/about)). It runs from a single binary with no dependencies.
+โœ… Plandex supports Mac, Linux, FreeBSD, and Windows. It runs from a single binary with no dependencies.
## Install ๐Ÿ“ฅ
-Run the quick install script:
+### Quick install
```bash
curl -sL https://plandex.ai/install.sh | bash
```
-Or grab the appropriate binary for your platform from the latest [release](https://github.com/plandex-ai/plandex/releases) and put it somewhere in your `PATH`.
+### Manual install
-Or build from source with Go:
+Grab the appropriate binary for your platform from the latest [release](https://github.com/plandex-ai/plandex/releases) and put it somewhere in your `PATH`.
+
+### Build from source
```bash
git clone plandex-ai/plandex.git
@@ -29,18 +31,23 @@ go build -o plandex
cp plandex /usr/local/bin # adapt as needed for your system
```
+### Windows
+
+Windows is supported via [Git bash](https://gitforwindows.org) or [WSL](https://learn.microsoft.com/en-us/windows/wsl/about).
+
## Why Plandex? ๐Ÿค”
- ๐Ÿ—๏ธ Go beyond autocomplete to build complex functionality with AI.
- ๐Ÿšซ Stop the mouse-centered, copy-pasting madness of coding with ChatGPT.
+- ๐Ÿ”„ Tighten the feedback loop between programmer and AI.
- ๐Ÿ“‘ Manage context efficiently in the terminal.
- โšก๏ธ Ensure AI models always have the latest versions of files in context.
-- ๐Ÿช™ Retain tight control over what's in context and how many tokens you're using.
+- ๐Ÿช™ Retain granular control over what's in context and how many tokens you're using.
- ๐Ÿšง Experiment, revise, and review in a protected sandbox before applying changes.
- โช Rewind and retry as needed with baked-in version control.
- ๐ŸŒฑ Explore multiple approaches with branches.
- ๐ŸŽ๏ธ Run tasks in the background or work on multiple tasks in parallel.
-- ๐ŸŽ›๏ธ Try different models and model settings and compare results.
+- ๐ŸŽ›๏ธ Try different models and model settings, then compare results.
## Get started ๐Ÿš€
@@ -88,7 +95,7 @@ Plandex Cloud accounts are free for now. In the future, there will be a monthly
[Read about self-hosting Plandex here.](./HOSTING.md)
-## Plandex security ๐Ÿ”
+## Security ๐Ÿ”
Plandex Cloud follows best practices for network and data security. And whether cloud or self-hosted, Plandex protects model provider API keys (like your OpenAI API key). [Read more here.](./SECURITY.md)
diff --git a/SECURITY.md b/SECURITY.md
index d6cf6671..0978d9e9 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -1,6 +1,6 @@
# Plandex security ๐Ÿ”
-Plandex Cloud follows best practices for network and data security. As I'm also the founder of a devops-security company ([EnvKey](https://envkey.com)), this is an area I have experience in and take extremely seriously. Data is encrypted in transit and at rest. The database runs within a private, hardened network.
+Plandex Cloud follows best practices for network and data security. As I (Plandex's creator ๐Ÿ‘‹) am also the founder of a devops-security company ([EnvKey](https://envkey.com)), this is an area I have experience in and take extremely seriously. Data is encrypted in transit and at rest. The database runs within a private, hardened network.
## Ignores sensitive files
@@ -10,12 +10,12 @@ Plandex respects `.gitignore` and won't load any files that you're ignoring. You
Plandex is a bring-your-own-API-key tool. On the Plandex server, whether that's Plandex Cloud or a self-hosted server, API keys are only stored ephemerally in RAM while they are in active use. They are never written to disk, logged, or stored in a database. As soon as a plan stream ends, the API key is removed from memory and no longer exists anywhere on our servers.
-It's up to you to manage your API keys securely. Try to avoid storing them in multiple places, exposing them to third party services, or sending them around in plain text. If you'd like some help, please do check out the aforementioned [EnvKey](https://envkey.com). It's open source, end-to-end encrypted, easy to use, and free for up to 3 users. To set your `OPENAI_API_KEY` with EnvKey, you'd add it to an app in the EnvKey UI or CLI, then run `eval $(envkey-source)` in your terminal.
+It's also up to you to manage your API keys securely. Try to avoid storing them in multiple places, exposing them to third party services, or sending them around in plain text. If you'd like some help, please do check out the aforementioned [EnvKey](https://envkey.com) for secrets management. It's open source, end-to-end encrypted, easy to use, and free for up to 3 users. To set your `OPENAI_API_KEY` with EnvKey, you'd add it to an app in the EnvKey UI or CLI, then run `eval $(envkey-source)` in your terminal.
## Third party services
- Plandex Cloud relies on AWS for all database and hosting services.
-- [EnvKey](https://envkey.com) for configuration and secrets management.
+- [EnvKey](https://envkey.com) for configuration and secrets management (only used in development so far).
- Github for code storage.
- OpenAI (called on your behalf) for AI models (other models providers will be added in the future).
- See the [privacy overview](./PRIVACY.md) for more details on third parties and data retention.
diff --git a/USAGE.md b/USAGE.md
index d8c040a4..e58d2e0b 100644
--- a/USAGE.md
+++ b/USAGE.md
@@ -16,6 +16,8 @@ When you create a plan, Plandex will automatically name your plan after you give
plandex new -n foo-adapters-component
```
+If you don't give your plan a name up front, it will be named 'draft' until you give it a task. To keep things tidy, you can only have one active plan named 'draft'. If you create a new draft plan, any existing draft plan will be removed.
+
### Loading context
After creating a plan, load any relevant files, directories, directory layouts, urls, or other data into the plan context.
@@ -76,19 +78,19 @@ plandex rewind a7c8d66 # rewind to a specific state
If you want to try a different approach but also keep the current one around, you can use branches. Create a new branch before rewinding.
```bash
-plandex checkout new-approach
+plandex checkout new-approach # create a new branch and switch to it
plandex rewind 2
plandex tell 'write the tests before the components.'
plandex branches # see all branches
-plandex delete-branch new-approach # delete a branch (sends you back to the main branch if you delete the current branch)
+plandex delete-branch new-approach # delete a branch
```
### Continue
If a plan has stopped and you just want to continue where you left off, you can use the `continue` command.
-```
-plandex continue
+```bash
+plandex continue # continue the current plan
```
### Background tasks
@@ -102,9 +104,9 @@ plandex tell --bg 'now add another similar component for widget adapters'
To see plans that are currently running (or recently finished) and their current status, use the `ps` command. You can connect to a running plan's stream to check on it. Or you can stop it.
```bash
-plandex ps
-plandex connect
-plandex stop
+plandex ps # show active and recently finished plans
+plandex connect # select an active plan to connect to
+plandex stop # select an active plan to stop
```
### Context management
@@ -112,7 +114,7 @@ plandex stop
You can see the plan's current context with the `ls` command. You can remove context with the `rm` command or clear it all with the `clear` command.
```bash
-plandex ls
+plandex ls # list all context in current plan
plandex rm component.ts # remove by name
plandex rm 2 # remove by number in the `plandex ls` list
plandex rm lib/**/*.js # remove by glob pattern
@@ -122,7 +124,7 @@ plandex clear # remove all context
If files in context are modified outside of Plandex, you will be prompted to update them the next time you interact with the AI. You can also update them manually with the `update` command.
```bash
-plandex update
+plandex update # update files in context
```
### Plans
@@ -130,11 +132,11 @@ plandex update
When you have multiple plans, you can list them with the `plans` command, switch between them with the `cd` command, see the current plan with the `current` command, and delete plans with the `delete-plan` command. Archiving of plans will be added in the future for plans that you want to keep around but aren't currently working on.
```
-plandex plans
+plandex plans # list all plans
plandex cd # select from a list of plans
plandex cd some-other-plan # cd to a plan by name
plandex cd 2 # cd to a plan by number in the `plandex plans` list
-plandex current
+plandex current # show the current plan
plandex delete-plan # select from a list of plans to delete
plandex delete-plan some-plan # delete a plan by name
plandex delete-plan 4 # delete a plan by number in the `plandex plans` list
@@ -145,7 +147,7 @@ plandex delete-plan 4 # delete a plan by number in the `plandex plans` list
You can see the full conversation history with the `convo` command.
```bash
-plandex convo
+plandex convo # show the full conversation history
```
### Conversation summaries
@@ -157,7 +159,7 @@ Every time the AI model replies, Plandex will summarize the conversation so far
You can see the current AI models and model settings with the `models` command and change them with the `set-model` command.
```bash
-plandex models
+plandex models # show the current AI models and model settings
plandex set-model # select from a list of models and settings
plandex set-model planner gpt-4 # set the main planner model to gpt-4
plandex set-model builder temperature 0.1 # set the builder model's temperature to 0.1
@@ -169,7 +171,7 @@ Model changes are versioned and can be rewound or applied to a branch just like
### .plandex and teams
-When you run `plandex new` for the first time in any directory, Plandex will create a `.plandex` directory there for light project-level config. While the `.plandex` directory can be safely added to version control, if multiple developers are using Plandex with the same project, then for now you should add `.plandex/` to .gitignore (or the ignore file for whatever VCS you use). When orgs and teams are fully implemented (they're currently a WIP), it can be re-added to version control so that all team members can work from the same org and project.
+When you run `plandex new` for the first time in any directory, Plandex will create a `.plandex` directory there for light project-level config. While the `.plandex` directory can be safely added to version control, **if multiple developers are using Plandex with the same project, then for now you should add `.plandex/` to .gitignore (or the ignore file for whatever VCS you use).** When orgs and teams are fully implemented (currently a WIP), it can be re-added to version control so that all team members can work from the same org and project.
### Directories
@@ -179,20 +181,21 @@ When you run `plandex plans`, in addition to showing you plans in the current di
```bash
cd your-project
-plandex new -n root-project-plan # cwd is your-project, current plan is root-project-plan
-plandex load file.go # loads your-project/file.go
-cd some-subdirectory
-plandex new -n subdir-plan1
-plandex load subfile.go # loads your-project/some-subdirectory/subfile.go
-plandex new -n subdir-plan2 # some-subdirectory current plan is now subdir-plan2
+plandex new -n root-project-plan # cwd is 'your-project'
+plandex current # 'your-project' current plan is root-project-plan
+plandex load file.go # loads 'your-project/file.go'
+cd some-subdirectory # cwd is now 'some-subdirectory'
+plandex new -n subdir-plan1 # current plan is subdir-plan1
+plandex load subfile.go # loads 'some-subdirectory/subfile.go'
+plandex new -n subdir-plan2 # current plan is now subdir-plan2
plandex plans # shows subdir-plan1 and subdir-plan2 in current directory + root-project-plan in parent directory
-cd ../ # cwd is now your-project, current plan is root-project-plan
-plandex plans # shows root-project-plan in current directory + subdir-plan1 and subdir-plan2 in child directory some-subdirectory
-cd some-subdirectory # cwd is now some-subdirectory, current plan is subdir-plan2
-plandex cd subdir-plan1 # cwd is still some-subdirectory, current plan is now subdir-plan1
+cd ../ # cwd is now 'your-project', current plan is root-project-plan
+plandex plans # shows root-project-plan in current directory + subdir-plan1 and subdir-plan2 in child directory 'some-subdirectory'
+cd some-subdirectory # cwd is now 'some-subdirectory', current plan is subdir-plan2
+plandex cd subdir-plan1 # cwd is still 'some-subdirectory', current plan is now subdir-plan1
```
-One last tidbit on this topic: you can also load context from parent or sibling directories if needed by using `..` in your load paths.
+One more thing to note on directories: you can load context from parent or sibling directories if needed by using `..` in your load paths.
```bash
cd your-project
diff --git a/app/cli/changes_tui/main_viewport.go b/app/cli/changes_tui/main_viewport.go
index 2bf29637..ec5ba798 100644
--- a/app/cli/changes_tui/main_viewport.go
+++ b/app/cli/changes_tui/main_viewport.go
@@ -101,7 +101,7 @@ func (m changesUIModel) renderMainViewHeader() string {
header = fmt.Sprintf(" %s New file: %s", icon, m.selectionInfo.currentPath)
} else {
- header = " ๐Ÿ‘‰ " + m.selectionInfo.currentRep.Summary
+ header = " ๐Ÿ‘‰ " + m.selectionInfo.currentRep.StreamedChange.ShortSummary
}
return style.Render(header)
diff --git a/app/cli/cmd/version.go b/app/cli/cmd/version.go
index ccdbc9f7..f53d3326 100644
--- a/app/cli/cmd/version.go
+++ b/app/cli/cmd/version.go
@@ -1,41 +1,19 @@
package cmd
import (
- "bufio"
"fmt"
- "os"
- "strings"
- "github.com/spf13/cobra"
-
-// Version will be set at build time using -ldflags
-var Version = "development"
-func readVersionFromFile() string {
- file, err := os.Open("version.txt") // Adjust the path as necessary
- if err != nil {
- fmt.Println("Unable to read version from file, defaulting to:", Version)
- return Version
- }
- defer file.Close()
-
- scanner := bufio.NewScanner(file)
- if scanner.Scan() {
- return strings.TrimSpace(scanner.Text())
- }
+ "plandex/version"
- return Version
-}
+ "github.com/spf13/cobra"
+)
-// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Plandex",
Long: `All software has versions. This is Plandex's`,
Run: func(cmd *cobra.Command, args []string) {
- if Version == "development" {
- Version = readVersionFromFile()
- }
- fmt.Println("Plandex CLI Version:", Version)
+ fmt.Println(version.Version)
},
}
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go
index e5ccb9ef..5cd30382 100644
--- a/app/cli/lib/context_load.go
+++ b/app/cli/lib/context_load.go
@@ -236,7 +236,6 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
term.StopSpinner()
fmt.Println("๐Ÿคทโ€โ™‚๏ธ No context loaded")
if len(ignoredPaths) > 0 {
- fmt.Println()
printIgnoredMsg()
}
os.Exit(0)
@@ -274,6 +273,6 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
}
func printIgnoredMsg() {
- fmt.Println("โ„น๏ธ " + color.New(color.FgWhite).Sprint("Due to .gitignore or .plandexignore, some paths weren't loaded.\nUse --force / -f to load ignored paths."))
fmt.Println()
+ fmt.Println("โ„น๏ธ " + color.New(color.FgWhite).Sprint("Due to .gitignore or .plandexignore, some paths weren't loaded.\nUse --force / -f to load ignored paths."))
}
diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.go
index aff6bf4c..d2d4d254 100644
--- a/app/cli/plan_exec/tell.go
+++ b/app/cli/plan_exec/tell.go
@@ -115,11 +115,9 @@ func TellPlan(
fmt.Println()
if tellStop {
- term.PrintCmds("", "continue", "convo", "changes", "log", "rewind")
- } else if tellNoBuild {
- term.PrintCmds("", "convo", "log", "rewind")
+ term.PrintCmds("", "continue", "changes", "apply", "log", "rewind")
} else {
- term.PrintCmds("", "changes", "log", "rewind")
+ term.PrintCmds("", "changes", "apply", "log", "rewind")
}
os.Exit(0)
}()
diff --git a/app/cli/stream/stream.go b/app/cli/stream/stream.go
index 8077cffa..e65ff693 100644
--- a/app/cli/stream/stream.go
+++ b/app/cli/stream/stream.go
@@ -5,6 +5,7 @@ import (
streamtui "plandex/stream_tui"
"plandex/types"
+ "github.com/davecgh/go-spew/spew"
"github.com/plandex/plandex/shared"
)
@@ -15,12 +16,12 @@ var OnStreamPlan types.OnStreamPlan = func(params types.OnStreamPlanParams) {
}
if params.Msg.Type == shared.StreamMessageStart {
- // log.Println("Stream started")
+ log.Println("Stream started")
return
}
- // log.Println("Stream message:")
- // log.Println(spew.Sdump(*params.Msg))
+ log.Println("Stream message:")
+ log.Println(spew.Sdump(*params.Msg))
streamtui.Send(*params.Msg)
}
diff --git a/app/cli/stream_tui/run.go b/app/cli/stream_tui/run.go
index a8e097c4..c832213a 100644
--- a/app/cli/stream_tui/run.go
+++ b/app/cli/stream_tui/run.go
@@ -17,8 +17,19 @@ var mu sync.Mutex
var wg sync.WaitGroup
var prestartReply string
+var prestartErr *shared.ApiError
+var prestartAbort bool
func StartStreamUI(prompt string, buildOnly bool) error {
+ if prestartErr != nil {
+ term.OutputErrorAndExit("Server error: " + prestartErr.Msg)
+ }
+
+ if prestartAbort {
+ fmt.Println("๐Ÿ›‘ Stopped early")
+ os.Exit(0)
+ }
+
initial := initialModel(prestartReply, prompt, buildOnly)
mu.Lock()
@@ -33,7 +44,14 @@ func StartStreamUI(prompt string, buildOnly bool) error {
return fmt.Errorf("error running stream UI: %v", err)
}
- mod := m.(*streamUIModel)
+ var mod *streamUIModel
+ c, ok := m.(*streamUIModel)
+ if ok {
+ mod = c
+ } else {
+ c := m.(streamUIModel)
+ mod = &c
+ }
fmt.Println()
@@ -52,7 +70,7 @@ func StartStreamUI(prompt string, buildOnly bool) error {
if mod.apiErr != nil {
fmt.Println()
- term.OutputErrorAndExit(mod.apiErr.Msg)
+ term.OutputErrorAndExit("Server error: " + mod.apiErr.Msg)
}
if mod.stopped {
@@ -87,11 +105,19 @@ func Quit() {
func Send(msg shared.StreamMessage) {
if ui == nil {
- // log.Println("stream ui is nil")
- prestartReply += msg.ReplyChunk
+ log.Println("stream ui is nil")
+
+ if msg.Type == shared.StreamMessageError {
+ prestartErr = msg.Error
+ } else if msg.Type == shared.StreamMessageAborted {
+
+ } else if msg.Type == shared.StreamMessageReply {
+ prestartReply += msg.ReplyChunk
+ }
return
}
mu.Lock()
defer mu.Unlock()
+ log.Printf("sending stream message to UI: %s\n", msg.Type)
ui.Send(msg)
}
diff --git a/app/cli/version.txt b/app/cli/version.txt
new file mode 100644
index 00000000..ac39a106
--- /dev/null
+++ b/app/cli/version.txt
@@ -0,0 +1 @@
+0.9.0
diff --git a/app/cli/version/version.go b/app/cli/version/version.go
new file mode 100644
index 00000000..f49f5590
--- /dev/null
+++ b/app/cli/version/version.go
@@ -0,0 +1,33 @@
+package version
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "strings"
+)
+
+// Version will be set at build time using -ldflags
+var Version = "source"
+var BuiltFromSource = false
+
+func init() {
+ if Version == "source" {
+ BuiltFromSource = true
+ readVersionFromFile()
+ }
+}
+
+func readVersionFromFile() {
+ file, err := os.Open("../version.txt")
+ if err != nil {
+ fmt.Println("Unable to read version from file, defaulting to:", Version)
+ return
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ if scanner.Scan() {
+ Version = strings.TrimSpace(scanner.Text())
+ }
+}
diff --git a/app/server/handlers/stream_helper.go b/app/server/handlers/stream_helper.go
index 16399f9a..3ab03e8c 100644
--- a/app/server/handlers/stream_helper.go
+++ b/app/server/handlers/stream_helper.go
@@ -34,7 +34,7 @@ func startResponseStream(w http.ResponseWriter, auth *types.ServerAuth, planId,
}
log.Println("Response stream manager: sending initial message")
- err = sendStreamMessage(w, active, string(bytes))
+ err = sendStreamMessage(w, string(bytes))
if err != nil {
log.Println("Response stream manager: error sending initial message:", err)
return
@@ -69,7 +69,7 @@ func startResponseStream(w http.ResponseWriter, auth *types.ServerAuth, planId,
return
case msg := <-ch:
// log.Println("Response stream manager: sending message:", msg)
- err = sendStreamMessage(w, active, msg)
+ err = sendStreamMessage(w, msg)
if err != nil {
return
}
@@ -78,7 +78,7 @@ func startResponseStream(w http.ResponseWriter, auth *types.ServerAuth, planId,
}
-func sendStreamMessage(w http.ResponseWriter, active *types.ActivePlan, msg string) error {
+func sendStreamMessage(w http.ResponseWriter, msg string) error {
bytes := []byte(msg + shared.STREAM_MESSAGE_SEPARATOR)
// log.Printf("Response stream manager: writing message to client: %s\n", msg)
@@ -143,7 +143,7 @@ func initConnectActive(auth *types.ServerAuth, planId, branch string, w http.Res
}
log.Println("Response stream manager: sending connect message")
- err = sendStreamMessage(w, active, string(bytes))
+ err = sendStreamMessage(w, string(bytes))
if err != nil {
return fmt.Errorf("error sending connect message: %v", err)
@@ -179,7 +179,7 @@ func initConnectActive(auth *types.ServerAuth, planId, branch string, w http.Res
return fmt.Errorf("error marshalling message: %v", err)
}
- err = sendStreamMessage(w, active, string(bytes))
+ err = sendStreamMessage(w, string(bytes))
if err != nil {
return fmt.Errorf("error sending message: %v", err)
diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.go
index 17d2e0d2..4fd0f173 100644
--- a/app/server/model/plan/build_exec.go
+++ b/app/server/model/plan/build_exec.go
@@ -74,16 +74,17 @@ func (state *activeBuildStreamState) queueBuilds(activeBuilds []*types.ActiveBui
planId := state.plan.Id
branch := state.branch
- activePlan := GetActivePlan(planId, branch)
-
queueBuild := func(activeBuild *types.ActiveBuild) {
filePath := activeBuild.Path
// log.Printf("Queue:")
// spew.Dump(activePlan.BuildQueuesByPath[filePath])
+ var activePlan *types.ActivePlan
+
UpdateActivePlan(planId, branch, func(active *types.ActivePlan) {
active.BuildQueuesByPath[filePath] = append(active.BuildQueuesByPath[filePath], activeBuilds...)
+ activePlan = active
})
log.Printf("Queued %d build(s) for file %s\n", len(activeBuilds), filePath)
@@ -92,6 +93,11 @@ func (state *activeBuildStreamState) queueBuilds(activeBuilds []*types.ActiveBui
return
} else {
log.Printf("Not building file %s, will execute now\n", filePath)
+
+ UpdateActivePlan(planId, branch, func(active *types.ActivePlan) {
+ active.IsBuildingByPath[filePath] = true
+ })
+
go state.execPlanBuild(activeBuild)
}
}
@@ -115,6 +121,12 @@ func (buildState *activeBuildStreamState) execPlanBuild(activeBuild *types.Activ
activePlan := GetActivePlan(planId, branch)
filePath := activeBuild.Path
+ if !activePlan.IsBuildingByPath[filePath] {
+ UpdateActivePlan(activePlan.Id, activePlan.Branch, func(ap *types.ActivePlan) {
+ ap.IsBuildingByPath[filePath] = true
+ })
+ }
+
// stream initial status to client
buildInfo := &shared.BuildInfo{
Path: filePath,
@@ -169,6 +181,9 @@ func (fileState *activeBuildStreamFileState) buildFile() {
if fileInCurrentPlan {
log.Printf("File %s found in current plan.\n", filePath)
currentState = currentPlanFile
+
+ log.Println("\n\nCurrent state:\n", currentState, "\n\n")
+
} else if contextPart != nil {
log.Printf("File %s found in model context. Using context state.\n", filePath)
currentState = contextPart.Body
@@ -176,6 +191,8 @@ func (fileState *activeBuildStreamFileState) buildFile() {
if currentState == "" {
log.Println("Context state is empty. That's bad.")
}
+
+ log.Println("\n\nCurrent state:\n", currentState, "\n\n")
}
fileState.currentState = currentState
diff --git a/app/server/model/plan/build_load.go b/app/server/model/plan/build_load.go
index a312c979..12265025 100644
--- a/app/server/model/plan/build_load.go
+++ b/app/server/model/plan/build_load.go
@@ -130,12 +130,6 @@ func (state *activeBuildStreamFileState) loadBuildFile(activeBuild *types.Active
convoMessageId := activeBuild.ReplyId
- if !activePlan.IsBuildingByPath[filePath] {
- UpdateActivePlan(activePlan.Id, activePlan.Branch, func(ap *types.ActivePlan) {
- ap.IsBuildingByPath[filePath] = true
- })
- }
-
build := &db.PlanBuild{
OrgId: currentOrgId,
PlanId: planId,
diff --git a/app/server/model/plan/build_result.go b/app/server/model/plan/build_result.go
index 5cb647d5..984622b9 100644
--- a/app/server/model/plan/build_result.go
+++ b/app/server/model/plan/build_result.go
@@ -2,7 +2,6 @@ package plan
import (
"plandex-server/db"
- "plandex-server/types"
"sort"
"strings"
@@ -11,14 +10,14 @@ import (
)
type planResultParams struct {
- orgId string
- planId string
- planBuildId string
- convoMessageId string
- filePath string
- currentState string
- fileContent string
- streamedReplacements []*types.StreamedReplacement
+ orgId string
+ planId string
+ planBuildId string
+ convoMessageId string
+ filePath string
+ currentState string
+ fileContent string
+ streamedChanges []*shared.StreamedChange
}
func getPlanResult(params planResultParams) (*db.PlanFileResult, bool) {
@@ -27,7 +26,7 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, bool) {
planBuildId := params.planBuildId
filePath := params.filePath
currentState := params.currentState
- streamedReplacements := params.streamedReplacements
+ streamedChanges := params.streamedChanges
updated := params.currentState
fileContent := params.fileContent
@@ -35,26 +34,38 @@ func getPlanResult(params planResultParams) (*db.PlanFileResult, bool) {
fileContentLines := strings.Split(fileContent, "\n")
var replacements []*shared.Replacement
- for _, streamedReplacement := range streamedReplacements {
+ for _, streamedChange := range streamedChanges {
var old string
var new string
- if streamedReplacement.Old.StartLine == streamedReplacement.Old.EndLine {
- old = currentStateLines[streamedReplacement.Old.StartLine-1]
+ if streamedChange.New.StartLine == streamedChange.New.EndLine {
+ new = fileContentLines[streamedChange.New.StartLine-1]
} else {
- old = strings.Join(currentStateLines[streamedReplacement.Old.StartLine-1:streamedReplacement.Old.EndLine], "\n")
+ new = strings.Join(fileContentLines[streamedChange.New.StartLine-1:streamedChange.New.EndLine], "\n")
}
- if streamedReplacement.New.StartLine == streamedReplacement.New.EndLine {
- new = fileContentLines[streamedReplacement.New.StartLine-1]
- } else {
- new = strings.Join(fileContentLines[streamedReplacement.New.StartLine-1:streamedReplacement.New.EndLine], "\n")
+ switch streamedChange.ChangeType {
+
+ case shared.StreamedChangeTypeReplace:
+ if streamedChange.Old.StartLine == streamedChange.Old.EndLine {
+ old = currentStateLines[streamedChange.Old.StartLine-1]
+ } else {
+ old = strings.Join(currentStateLines[streamedChange.Old.StartLine-1:streamedChange.Old.EndLine], "\n")
+ }
+
+ case shared.StreamedChangeTypeAppend:
+ old = currentStateLines[streamedChange.Old.EndLine-1]
+ new = old + "\n" + new
+
+ case shared.StreamedChangeTypePrepend:
+ old = currentStateLines[streamedChange.Old.StartLine-1]
+ new = new + "\n" + old
}
replacement := &shared.Replacement{
- Old: old,
- New: new,
- Summary: streamedReplacement.ShortSummary,
+ Old: old,
+ New: new,
+ StreamedChange: streamedChange,
}
replacements = append(replacements, replacement)
diff --git a/app/server/model/plan/build_stream.go b/app/server/model/plan/build_stream.go
index 172dbfae..fdcbfc9a 100644
--- a/app/server/model/plan/build_stream.go
+++ b/app/server/model/plan/build_stream.go
@@ -111,22 +111,22 @@ func (fileState *activeBuildStreamFileState) listenStream(stream *openai.ChatCom
fileState.buffer += content
}
- var streamed types.StreamedReplacements
+ var streamed types.StreamedChanges
err = json.Unmarshal([]byte(fileState.buffer), &streamed)
if err == nil {
log.Printf("File %s: Parsed streamed replacements\n", filePath)
- spew.Dump(streamed)
+ // spew.Dump(streamed)
planFileResult, allSucceeded := getPlanResult(
planResultParams{
- orgId: currentOrgId,
- planId: planId,
- planBuildId: build.Id,
- convoMessageId: build.ConvoMessageId,
- filePath: filePath,
- currentState: currentState,
- fileContent: activeBuild.FileContent,
- streamedReplacements: streamed.Replacements,
+ orgId: currentOrgId,
+ planId: planId,
+ planBuildId: build.Id,
+ convoMessageId: build.ConvoMessageId,
+ filePath: filePath,
+ currentState: currentState,
+ fileContent: activeBuild.FileContent,
+ streamedChanges: streamed.Changes,
},
)
diff --git a/app/server/model/plan/state.go b/app/server/model/plan/state.go
index adff1995..c11fcb8a 100644
--- a/app/server/model/plan/state.go
+++ b/app/server/model/plan/state.go
@@ -5,6 +5,7 @@ import (
"plandex-server/db"
"plandex-server/types"
"strings"
+ "time"
"github.com/plandex/plandex/shared"
)
@@ -57,6 +58,16 @@ func CreateActivePlan(planId, branch, prompt string, buildOnly bool) *types.Acti
log.Printf("Error setting plan %s status to error: %v\n", planId, err)
}
+ log.Println("Sending error message to client")
+ activePlan.Stream(shared.StreamMessage{
+ Type: shared.StreamMessageError,
+ Error: apiErr,
+ })
+
+ log.Println("Stopping any active summary stream")
+ activePlan.SummaryCancelFn()
+
+ time.Sleep(50 * time.Millisecond)
}
activePlan.CancelFn()
diff --git a/app/server/model/plan/stop.go b/app/server/model/plan/stop.go
index a63fb511..4f511bc1 100644
--- a/app/server/model/plan/stop.go
+++ b/app/server/model/plan/stop.go
@@ -14,6 +14,7 @@ func Stop(planId, branch, currentUserId, currentOrgId string) error {
return fmt.Errorf("no active plan with id %s", planId)
}
+ active.SummaryCancelFn()
active.CancelFn()
if !active.BuildOnly && !active.RepliesFinished {
diff --git a/app/server/model/plan/tell_load.go b/app/server/model/plan/tell_load.go
index 06ec7653..5682ca41 100644
--- a/app/server/model/plan/tell_load.go
+++ b/app/server/model/plan/tell_load.go
@@ -194,6 +194,9 @@ func (state *activeTellStreamState) loadTellPlan() error {
convoMessageIds = append(convoMessageIds, convoMessage.Id)
}
+ log.Println("getting plan summaries")
+ log.Println("convoMessageIds:", convoMessageIds)
+
res, err := db.GetPlanSummaries(planId, convoMessageIds)
if err != nil {
log.Printf("Error getting plan summaries: %v\n", err)
@@ -202,6 +205,8 @@ func (state *activeTellStreamState) loadTellPlan() error {
}
summaries = res
+ log.Printf("got %d plan summaries", len(summaries))
+
innerErrCh <- nil
}()
diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.go
index cbf52251..8b61b503 100644
--- a/app/server/model/plan/tell_stream.go
+++ b/app/server/model/plan/tell_stream.go
@@ -136,7 +136,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
summaries: summaries,
promptMessage: promptMessage,
currentOrgId: currentOrgId,
- }, active.Ctx)
+ }, active.SummaryCtx)
}
log.Println("Locking repo to store assistant reply and description")
diff --git a/app/server/model/plan/tell_summary.go b/app/server/model/plan/tell_summary.go
index f8e0b1ff..7e0a76f0 100644
--- a/app/server/model/plan/tell_summary.go
+++ b/app/server/model/plan/tell_summary.go
@@ -48,6 +48,8 @@ func (state *activeTellStreamState) summarizeMessagesIfNeeded() bool {
// log.Printf("(tokensBeforeConvo+conversationTokens) > state.settings.GetPlannerEffectiveMaxTokens(): %v\n", (tokensBeforeConvo+conversationTokens) > state.settings.GetPlannerEffectiveMaxTokens())
// log.Printf("conversationTokens > state.settings.GetPlannerMaxConvoTokens(): %v\n", conversationTokens > state.settings.GetPlannerMaxConvoTokens())
+ log.Printf("Num summaries: %d\n", len(summaries))
+
// token limit exceeded after adding conversation
// get summary for as much as the conversation as necessary to stay under the token limit
for _, s := range summaries {
@@ -216,6 +218,8 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, params
})
}
+ log.Printf("Calling model for plan summary. Summarizing %d messages\n", len(summaryMessages))
+
summary, err := model.PlanSummary(client, config, model.PlanSummaryParams{
Conversation: summaryMessages,
LatestConvoMessageId: latestMessageId,
diff --git a/app/server/model/prompts/build.go b/app/server/model/prompts/build.go
index a1886313..a468e416 100644
--- a/app/server/model/prompts/build.go
+++ b/app/server/model/prompts/build.go
@@ -9,14 +9,14 @@ import (
)
func GetBuildSysPrompt(filePath, currentState, desc, changes string) string {
- return listReplacementsPrompt + "\n\n" + getBuildCurrentStatePrompt(filePath, currentState) + "\n\n" + getBuildPrompt(desc, changes)
+ return listChangesPrompt + "\n\n" + getBuildCurrentStatePrompt(filePath, currentState) + "\n\n" + getBuildPrompt(desc, changes)
}
func getBuildPrompt(desc, changes string) string {
s := ""
if desc != "" {
- s += "Description of the proposed changes from AI-generated plan:\n```\n" + desc + "\n```\n\n"
+ s += "Description of the proposed updates from AI-generated plan:\n```\n" + desc + "\n```\n\n"
}
withLineNums := ""
@@ -24,9 +24,9 @@ func getBuildPrompt(desc, changes string) string {
withLineNums += fmt.Sprintf("%d: %s\n", i+1, line)
}
- s += "Proposed changes:\n```\n" + withLineNums + "\n```"
+ s += "Proposed updates:\n```\n" + withLineNums + "\n```"
- s += "\n\n" + "Now call the 'listReplacements' function with a valid JSON array of replacements according to your instructions. You must always call 'listReplacements' with one or more valid replacements. Don't call any other function."
+ s += "\n\n" + "Now call the 'listChanges' function with a valid JSON array of changes according to your instructions. You must always call 'listChanges' with one or more valid changes. Don't call any other function."
return s
}
@@ -44,11 +44,19 @@ func getBuildCurrentStatePrompt(filePath, currentState string) string {
return fmt.Sprintf("**The current file is %s. Original state of the file:**\n```\n%s\n```", filePath, withLineNums) + "\n\n"
}
-var listReplacementsPrompt = `
- You are an AI that analyzes a code file and an AI-generated plan to update the code file and produces a list of replacements.
+var listChangesPrompt = `
+ You are an AI that analyzes a code file and an AI-generated plan to update the code file and produces a list of changes.
+ There are four types of changes:
+
+ 1 - Replace: replace a section of code in the original file with a section of code from the proposed updates.
+
+ 2 - Append: add a section of code from the proposed update immediately after a section of code in the original file.
+
+ 3 - Prepend: add a section of code from the proposed updates immediately before a section of code in the original file.
+
[YOUR INSTRUCTIONS]
- Call the 'listReplacements' function with a valid JSON array of replacements. Each replacement is an object with properties: 'shortSummary', 'changeSections', 'old', and 'new'.
+ Call the 'listChanges' function with a valid JSON array of changes. Each replacement is an object with properties: 'shortSummary', 'changeSections', 'changeType', 'old', and 'new'.
The 'shortSummary' property is a brief summary of the change.
@@ -56,36 +64,98 @@ var listReplacementsPrompt = `
- 'Update loop that aggregates the results to iterate 10 times instead of 5 and log the value of someVar.'
- 'Change the value of someVar to 10.'
- 'Update the Org model to include StripeCustomerId and StripeSubscriptionId fields.'
+ - 'Add function ExecQuery to execute a query.'
+
+ The 'changeSections' property is a description of:
+ - The type of change (replace, append, prepend).
+ - If the type of change is 'replace', what section of code from the original file will be replaced.
+ - If the type of change is 'append', what section of code from the original file will have new code appended immediately after it.
+ - If the type of change is 'prepend', what section of code from the original file will have new code prepended immediately before it.
+ - What section of code from the proposed updates will be added.
+
+ Refer to sections of code using line numbers, how the section begins, and how the section ends.
+
+ If the change type is 'replace', it must be extremely clear which line(s) of code from the original file will be replaced with which line(s) of code from the proposed updates.
- The 'changeSections' property is a description of what section of the original file will be replaced, and what section of code from the proposed changes will replace it. Refer to sections of code using line numbers, how the section begins, and how the section ends. It must be extremely clear which line(s) of code from the original file will be replaced with which line(s) of code from the proposed changes.
+ If the change type is 'append' or 'prepend', it must be extremely clear which line(s) of code from the original file will have which line(s) of code from the proposed updates appended or prepended to them.
- 'changeSections' example:
+ 'changeSections' examples:
---
+ Type: replace
+
The section to be replaced begins on line 10 of the original file with 'for i := 0; i < 10; i++ {...' and ends on line 15 of the original file with '}'
- The new code begins on line 17 of the proposed changes with 'for i := 0; i < 10; i++ {...' and ends on line 25 of the proposed changes with '}'
+ The new code begins on line 17 of the proposed updates with 'for i := 0; i < 10; i++ {...' and ends on line 25 of the proposed updates with '}'
---
- If only a single line needs to be replaced, you can reference a single line from the original file and the proposed changes rather than a range of lines like this:
---
+ Type: append
+
+ The section that should have code appended to it begins on line 10 of the original file with 'func GetResults() {...' and ends on line 15 of the original file with '}'
+
+ The new code begins on line 10 of the proposed updates with 'func ExecQuery() {...' and ends on line 15 of the proposed updates with '}'
+ ---
+
+ ---
+ Type: prepend
+
+ The section that should have code prepended to it begins on line 10 of the original file with 'func GetResults() {...' and ends on line 15 of the original file with '}'
+
+ The new code begins on line 10 of the proposed updates with 'func ExecQuery() {...' and ends on line 15 of the proposed updates with '}'
+ ---
+
+ If the change type is 'replace' and only a single line needs to be replaced, you can reference a single line from the original file and the proposed updates rather than a range of lines like this:
+ ---
+ Type: replace
+
The section to be replaced is on line 10 of the original file with 'someVar = 5'
- The new code is on line 12 of the proposed changes with 'someVar = 10'
+ The new code is on line 12 of the proposed updates with 'someVar = 10'
---
+ To append to the end of the file, you can reference a single line, the last line of the original file, for the new code to be appended to like this:
+ ---
+ Type: append
+
+ Line 15 of the original file with '}'
+
+ The new code begins on line 10 of the proposed updates with 'func ExecQuery() {...' and ends on line 15 of the proposed updates with '}'
+ --
+
+ To prepend to the beginning of the file, you can reference a single line, the first line of the original file, for the new code to be prepended to like this:
+
+ ---
+ Type: prepend
+
+ Line 1 of the original file with 'package main'
+
+ The new code begins on line 10 of the proposed updates with 'func ExecQuery() {...' and ends on line 15 of the proposed updates with '}'
+ ---
+
+ The 'changeType' property is an integer that represents the type of change. The value of 'changeType' corresponds to the type of change as follows:
+ - 1: replace
+ - 2: append
+ - 3: prepend
+ You must include the 'changeType' property in each change object and it must be one of the above values (1, 2, or 3).
+
The 'old' property is an object with two properties: 'startLine' and 'endLine'.
- 'startLine' is the line number where the section to be replaced begins in the original file. 'endLine' is the line number where the section to be replaced ends in the original file. For a single line replacement, 'startLine' and 'endLine' will be the same.
+ If the changeType is 'replace': 'startLine' is the line number where the section to be replaced begins in the original file. 'endLine' is the line number where the section to be replaced ends in the original file. For a single line replacement, 'startLine' and 'endLine' will be the same.
+
+ If the changeType is 'append', 'startLine' and 'endLine' are both the same: the line number where the section to have code appended to it ends in the original file.
+
+ If the changeType is 'prepend', 'startLine' and 'endLine' are both the same: the line number where the section to have code prepended to it begins in the original file.
The 'new' property is also an object with two properties: 'startLine' and 'endLine'.
- 'startLine' is the line number where the new section begins in the code block included with the proposed changes. 'endLine' is the line number where the new section ends in the code block included with the proposed changes. For a single line replacement, 'startLine' and 'endLine' will be the same.
+ 'startLine' is the line number where the new section begins in the code block included with the proposed updates. 'endLine' is the line number where the new section ends in the code block included with the proposed updates. For a single line replacement, 'startLine' and 'endLine' will be the same.
Example function call with all keys:
---
- listReplacements([{
+ listChanges([{
shortSummary: "Insert function ExecQuery after GetResults function.",
- changeSections: "The section to be replaced is on line 5 of the original file with '\\n'\n\nThe new code starts on line 3 of the proposed changes with 'func ExecQuery()...' and ends on line 10 of the proposed changes with '}'",
+ changeSections: "Type: replace\nThe section to be replaced is on line 5 of the original file with '\\n'\n\nThe new code starts on line 3 of the proposed updates with 'func ExecQuery()...' and ends on line 10 of the proposed updates with '}'",
+ changeType: 1,
old: {
startLine: 5,
endLine: 5,
@@ -96,14 +166,21 @@ var listReplacementsPrompt = `
}
}])
---
+
+ Very important notes:
+
+ - 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.
+
+ - If the code block with the proposed updates includes references to the original code file, like this comment "// rest of the function here..." or "# rest of the code here" or "/* rest of the functionality goes here */", **do not include these references** when constructing the changes. In these cases, only replace the code that is actually changing and leave out the references to the original code file. The code should be ready for use and should not contain any artifacts of the planning process.
+
[END YOUR INSTRUCTIONS]
`
var ListReplacementsFn = openai.FunctionDefinition{
- Name: "listReplacements",
+ Name: "listChanges",
Parameters: &jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
- "replacements": {
+ "changes": {
Type: jsonschema.Array,
Items: &jsonschema.Definition{
Type: jsonschema.Object,
@@ -114,6 +191,9 @@ var ListReplacementsFn = openai.FunctionDefinition{
"changeSections": {
Type: jsonschema.String,
},
+ "changeType": {
+ Type: jsonschema.Integer,
+ },
"old": {
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
@@ -139,10 +219,10 @@ var ListReplacementsFn = openai.FunctionDefinition{
Required: []string{"startLine", "endLine"},
},
},
- Required: []string{"shortSummary", "changeSections", "old", "new"},
+ Required: []string{"shortSummary", "changeSections", "changeType", "old", "new"},
},
},
},
- Required: []string{"replacements"},
+ Required: []string{"changes"},
},
}
diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.go
index 82cd5abe..8b33017a 100644
--- a/app/server/model/prompts/create.go
+++ b/app/server/model/prompts/create.go
@@ -8,7 +8,7 @@ import (
const SysCreate = Identity + ` A plan is a set of files with an attached context.` +
- "Your instructions:\n\n```\n" +
+ "# Your instructions:\n\n```\n" +
`First, decide if the user has a task for you.
@@ -34,31 +34,49 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
- Explicitly say "Let's break up this task."
- Divide the task into smaller subtasks and list them in a numbered list. Stop there.
+ ## Code blocks and files
+
Always precede code blocks in a plan with the file path as described above in 2a. Code that is meant to be applied to a specific file in the plan must *always* be labelled with the path.
If code is being included for explanatory purposes and is not meant to be applied to a specific file, you MUST NOT label the code block in the format described in 2a. Instead, output the code without a label.
- Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. Don't ask the user to create new files or directories--you must do that yourself.
+ Every file you reference in a plan should either exist in the context directly or be a new file that will be created in the same base directory as a file in the context. For example, if there is a file in context at path 'lib/term.go', you can create a new file at path 'lib/utils_test.go' but *not* at path 'src/lib/term.go'. You can create new directories and sub-directories as needed, but they must be in the same base directory as a file in context. Don't ask the user to create new files or directories--you must do that yourself.
**You must not include anything except code in labelled file blocks for code files.** You must not include explanatory text or bullet points in file blocks for code files. Only 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.
For code in markdown blocks, always include the language name after the opening triple backticks.
- 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.
+ 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.
An exception to the above instructions on comments are if a file block is empty because you removed everything in it. In that case, leave a brief one-line comment starting with 'Plandex: removed' that says what was removed so that the file block isn't empty.
In code blocks, include the *minimum amount of code* necessary to describe the suggested changes. Include only lines that are changing and and lines that make it clear where the change should be applied. You can use comments like "// rest of the function..." or "// rest of the file..." to help make it clear where changes should be applied. You *must not* include large sections of the original file unless it helps make the suggested changes clear.
- Don't try to do too much in a single response. The code you include in file blocks will be parsed into replacements by an AI, and then applied to the file. If you include too much code, it may not be parsed correctly or the changes may be difficult to apply.
+ 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.
+
+ As much as possible, the code you suggest should be robust, complete, and ready for production.
+
+ ## Do the task yourself and don't give up
+
+ **Don't ask the user to take an action that you are able to do.** You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. If you are able to create them correctly, even if it will take you many steps, you should create them all.
+
+ **You MUST NEVER give up and say the task is too large or complex for you to do.** Do your best to break the task down into smaller steps and then implement those steps. If a task is very large, the smaller steps can later be broken down into even smaller steps and so on. You can use as many responses as needed to complete a large task. Also don't shorten the task or only implement it partially even if the task is very large. Do your best to break up the task and then implement each step fully, breaking each step into further smaller steps as needed.
+
+ ## Use open source libraries
+
+ When making a plan and describing each task or subtask, **always consider using open source libraries.** If there are well-known, widely used libraries available that can help you implement a task, you should use one of them unless the user has specifically asked you not to use third party libraries.
- If a plan requires a number of small changes, then multiple changes can be included single response, but they should be broken up into separate file blocks.
+ Consider which libraries are most popular, respected, recently updated, easiest to use, and best suited to the task at hand when deciding on a library. Also prefer libraries that have a permissive license.
- For changes that are larger or more complex, only include one change per response.
+ Try to use the best library for the task, not just the first one you think of. If you are deciding between multiple libraries, you can write a couple lines about each potential library and its pros and cons before deciding which one to use.
+
+ Don't ask the user which library to use--make the decision yourself. Don't recommend a library that is very old or unmaintained. Don't recommend a library that isn't widely used or respected. Don't recommend a library with a non-permissive license. Don't recommend a library that is difficult to use, has a steep learning curve, or is hard to understand unless it is the only library that can do the job. Strive for simplicity and ease of use when choosing a libraries.
- As much as possible, do not include placeholders in code blocks. 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.
+ If the user asks you to use a specific library, then use that library.
- **Don't ask the user to take an action that you are able to do.** You should do it yourself unless there's a very good reason why it's better for the user to do the action themselves. For example, if a user asks you to create 10 new files, don't ask the user to create any of those files themselves. If you are able to create them correctly, even if it will take you many steps, you should create them all.
+ If a task or subtask is small and the implementation is trivial, don't use a library. Just implement the task or subtask directly. Use libraries when they can significantly simplify the task or subtask.
+
+ ## Ending a response
At the end of each response, you can suggest additional iterations to make the plan better. You can also ask the user to load more files into context or give you more information if it would help you make a better plan.
@@ -74,6 +92,8 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
- Don't consider the user verifying or testing the code as a next step. If all that's left is for the user to verify or test the code, consider the plan complete.
+ ## Rules for responses
+
You *must never respond with just a single paragraph.* Every response should include at least a few paragraphs that try to move a plan forward. You *especially must never* reply with just a single paragraph that begins with "Next," or "The plan cannot be continued.". You must also **never reply with just a single paragraph that contains only "All tasks have been completed."**.
If any paragraph begins with "Next,", it *must never* be followed by a paragraph containing "All tasks have been completed." or "The plan cannot be continued." *Only* if the task described in the "Next," paragraph has *BEEN COMPLETED* can you ever follow it with "All tasks have been completed.".
@@ -84,6 +104,8 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
Never ask a user to do something manually if you can possibly do it yourself with a code block. Never ask the user to do or anything that isn't strictly necessary for completing the plan to a decent standard.
+ ## Continuing the plan
+
If the last paragraph (p) of your previous response in the conversation began with "Next," and you are continuing the plan:
- Continue from where your previous response left off.
- **Do not repeat any part of your previous response**
@@ -92,16 +114,20 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
- Always continue with the task described in paragraph p unless the user has given you new instructions or context that make it clear that you should do something else.
- **Never begin your response with "The plan cannot be continued." or "All tasks have been completed."**
+ ## Consider the latest context
+
Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context. For example, if you are working on a plan that has been broken up into subtasks, and you've reached the point of implementing a particular subtask, first consider whether the subtask is still necessary looking at the files in context. If it has already been implemented or is no longer necessary, say so, revise the plan as needed, and move on. Otherwise, implement the subtask.
+ ## Responding to questions
+
If a plan is in progress and the user asks you a question, don't respond by continuing with the plan unless that is the clear intention of the question. Instead, respond in chat form and answer the question, then stop there.
` +
"\n```\n\n" +
- "User-provided context:"
+ "# User-provided context:"
var CreateSysMsgNumTokens, _ = shared.GetNumTokens(SysCreate)
-const promptWrapperFormatStr = "The user's latest prompt:\n```\n%s\n```\n\n Please respond according to the 'Your instructions' section above. If you're making a plan, remember to precede code blocks with the file path *exactly* as described in 2a, and do not use any other formatting for file paths. **Do not include explanations or any other text apart from the file path in code block labels.** 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. Do not ask the user to do anything that you can do yourself with a code block. If you're making a plan, also remember to end every response with either " + `"All tasks have been completed.", "Next, " (plus a brief descripton of the next step), or "The plan cannot be continued." according to your instructions for ending a response.`
+const promptWrapperFormatStr = "# The user's latest prompt:\n```\n%s\n```\n\n Please respond according to the 'Your instructions' section above. If you're making a plan, remember to precede code blocks with the file path *exactly* as described in 2a, and do not use any other formatting for file paths. **Do not include explanations or any other text apart from the file path in code block labels.** 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. Do not ask the user to do anything that you can do yourself with a code block. Do not say a task is too large or complex for you to complete--do your best to break down the task and complete it even if it's very large or complex. Do not implement a task partially and then give up even if it's very large or complex--do your best to implement each task and subtask **fully**. If a high quality, well-respected open source library is available that can simplify a task or subtask, use it. If you're making a plan, also remember to end every response with either " + `"All tasks have been completed.", "Next, " (plus a brief descripton of the next step), or "The plan cannot be continued." according to your instructions for ending a response.`
func GetWrappedPrompt(prompt string) string {
return fmt.Sprintf(promptWrapperFormatStr, prompt)
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index 27dc7239..f88de3a9 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -44,6 +44,8 @@ type ActivePlan struct {
CancelFn context.CancelFunc
ModelStreamCtx context.Context
CancelModelStreamFn context.CancelFunc
+ SummaryCtx context.Context
+ SummaryCancelFn context.CancelFunc
Contexts []*db.Context
ContextsByPath map[string]*db.Context
Files []string
@@ -71,6 +73,9 @@ func NewActivePlan(planId, branch, prompt string, buildOnly bool) *ActivePlan {
// child context for model stream so we can cancel it separately if needed
modelStreamCtx, cancelModelStream := context.WithCancel(ctx)
+ // we don't want to cancel summaries unless the whole plan is stopped or there's an error -- if the active plan finishes, we want summaries to continue -- so they get their own context
+ summaryCtx, cancelSummary := context.WithCancel(context.Background())
+
active := ActivePlan{
Id: planId,
BuildOnly: buildOnly,
@@ -80,6 +85,8 @@ func NewActivePlan(planId, branch, prompt string, buildOnly bool) *ActivePlan {
CancelFn: cancel,
ModelStreamCtx: modelStreamCtx,
CancelModelStreamFn: cancelModelStream,
+ SummaryCtx: summaryCtx,
+ SummaryCancelFn: cancelSummary,
BuildQueuesByPath: map[string][]*ActiveBuild{},
Contexts: []*db.Context{},
ContextsByPath: map[string]*db.Context{},
diff --git a/app/server/types/model.go b/app/server/types/model.go
index 0b2f5bf7..4b0b6435 100644
--- a/app/server/types/model.go
+++ b/app/server/types/model.go
@@ -1,21 +1,13 @@
package types
+import (
+ "github.com/plandex/plandex/shared"
+)
+
type StreamedFile struct {
Content string `json:"content"`
}
-type Section struct {
- StartLine int `json:"startLine"`
- EndLine int `json:"endLine"`
-}
-
-type StreamedReplacement struct {
- ShortSummary string `json:"shortSummary"`
- ChangeSections string `json:"changeSections"`
- Old Section `json:"old"`
- New Section `json:"new"`
-}
-
-type StreamedReplacements struct {
- Replacements []*StreamedReplacement `json:"replacements"`
+type StreamedChanges struct {
+ Changes []*shared.StreamedChange `json:"changes"`
}
diff --git a/app/shared/data_models.go b/app/shared/data_models.go
index a6168546..29dcba99 100644
--- a/app/shared/data_models.go
+++ b/app/shared/data_models.go
@@ -137,12 +137,12 @@ type PlanBuild struct {
}
type Replacement struct {
- Id string `json:"id"`
- Old string `json:"old"`
- New string `json:"new"`
- Summary string `json:"summary"`
- Failed bool `json:"failed"`
- RejectedAt *time.Time `json:"rejectedAt,omitempty"`
+ Id string `json:"id"`
+ Old string `json:"old"`
+ New string `json:"new"`
+ Failed bool `json:"failed"`
+ RejectedAt *time.Time `json:"rejectedAt,omitempty"`
+ StreamedChange *StreamedChange `json:"streamedChange"`
}
type PlanFileResult struct {
diff --git a/app/shared/plan_result_replacements.go b/app/shared/plan_result_replacements.go
index 4970d6c6..711f93ea 100644
--- a/app/shared/plan_result_replacements.go
+++ b/app/shared/plan_result_replacements.go
@@ -5,6 +5,8 @@ import (
"log"
"strings"
"time"
+
+ "github.com/davecgh/go-spew/spew"
)
func ApplyReplacements(content string, replacements []*Replacement, setFailed bool) (string, bool) {
@@ -26,10 +28,11 @@ func ApplyReplacements(content string, replacements []*Replacement, setFailed bo
replacement.Failed = true
}
- log.Println("Replacement failed: " + replacement.Old + " -> " + replacement.New)
- log.Println("Pre: " + pre)
- log.Println("Sub: " + sub)
- log.Println("Updated: " + updated)
+ log.Println("Replacement failed: ")
+ log.Println(spew.Sdump(replacement))
+
+ log.Println("Sub: ")
+ log.Println(spew.Sdump(sub))
} else {
replaced := strings.Replace(sub, replacement.Old, replacement.New, 1)
@@ -91,7 +94,7 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(
updated, allSucceeded = ApplyReplacements(updated, replacements, false)
if !allSucceeded {
- return nil, fmt.Errorf("plan replacement failed: %s", path)
+ return nil, fmt.Errorf("plan replacement failed - %s", path)
}
updatedAtByPath[path] = planRes.CreatedAt
diff --git a/app/shared/streamed_change.go b/app/shared/streamed_change.go
new file mode 100644
index 00000000..4353664d
--- /dev/null
+++ b/app/shared/streamed_change.go
@@ -0,0 +1,22 @@
+package shared
+
+type StreamedChangeSection struct {
+ StartLine int `json:"startLine"`
+ EndLine int `json:"endLine"`
+}
+
+type StreamedChangeType int
+
+const (
+ StreamedChangeTypeReplace StreamedChangeType = 1
+ StreamedChangeTypeAppend StreamedChangeType = 2
+ StreamedChangeTypePrepend StreamedChangeType = 3
+)
+
+type StreamedChange struct {
+ ShortSummary string `json:"shortSummary"`
+ ChangeSections string `json:"changeSections"`
+ ChangeType StreamedChangeType `json:"changeType"`
+ Old StreamedChangeSection `json:"old"`
+ New StreamedChangeSection `json:"new"`
+}