Skip to content

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

apply fixes

Dane Schneider255229e29afc
diff --git a/app/cli/cmd/cd.go b/app/cli/cmd/cd.go
index 859a53b8..c0f00919 100644
--- a/app/cli/cmd/cd.go
+++ b/app/cli/cmd/cd.go
@@ -9,6 +9,7 @@ import (
"strconv"
"time"
+ "github.com/fatih/color"
"github.com/plandex/plandex/shared"
"github.com/spf13/cobra"
)
@@ -76,5 +77,5 @@ func cd(cmd *cobra.Command, args []string) {
// give the SetProjectPlan request some time to be sent before exiting
time.Sleep(50 * time.Millisecond)
- fmt.Fprintln(os.Stderr, "✅ Changed current plan to "+name)
+ fmt.Fprintln(os.Stderr, "✅ Changed current plan to "+color.New(color.FgGreen, color.Bold).Sprint(plan.Name))
}
diff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.go
index ec4e413e..2f41cde2 100644
--- a/app/cli/lib/apply.go
+++ b/app/cli/lib/apply.go
@@ -20,7 +20,7 @@ func ApplyPlanWithOutput(planId string, autoConfirm bool) error {
currentPlanState, apiErr := api.Client.GetCurrentPlanState(planId)
if apiErr != nil {
- return fmt.Errorf("error getting current plan state: %w", apiErr.Msg)
+ return fmt.Errorf("error getting current plan state: %s", apiErr.Msg)
}
currentPlanFiles := currentPlanState.CurrentPlanFiles
@@ -308,7 +308,7 @@ func ApplyPlanWithOutput(planId string, autoConfirm bool) error {
if apiErr != nil {
aborted = true
- return fmt.Errorf("failed to set pending results applied: %w", apiErr.Msg)
+ return fmt.Errorf("failed to set pending results applied: %s", apiErr.Msg)
}
if isRepo {
diff --git a/app/cli/stream_tui/view.go b/app/cli/stream_tui/view.go
index 1975e3b5..a0062a6e 100644
--- a/app/cli/stream_tui/view.go
+++ b/app/cli/stream_tui/view.go
@@ -64,12 +64,12 @@ func (m streamUIModel) renderBuild() string {
for _, filePath := range filePaths {
tokens := m.tokensByPath[filePath]
finished := m.finishedByPath[filePath]
- block := fmt.Sprintf(" 📄 %s", filePath)
- if tokens > 0 {
- block += fmt.Sprintf(" | %d 🪙", tokens)
- }
+ block := fmt.Sprintf("📄 %s", filePath)
+
if finished {
- block += " | ✅"
+ block += " ✅"
+ } else if tokens > 0 {
+ block += fmt.Sprintf(" %d 🪙", tokens)
}
blockWidth := lipgloss.Width(block)
@@ -94,7 +94,7 @@ func (m streamUIModel) renderBuild() string {
resRows[0] = head
for i, row := range rows {
- resRows[i+1] = strings.Join(row, "")
+ resRows[i+1] = strings.Join(row, " | ")
}
return style.Render(strings.Join(resRows, "\n"))
diff --git a/app/server/db/fs.go b/app/server/db/fs.go
index 08de7650..a4761f83 100644
--- a/app/server/db/fs.go
+++ b/app/server/db/fs.go
@@ -14,7 +14,11 @@ func init() {
panic(fmt.Errorf("error getting user home dir: %v", err))
}
- BaseDir = filepath.Join(home, "plandex-server")
+ if os.Getenv("GOENV") == "development" {
+ BaseDir = filepath.Join(home, "plandex-server")
+ } else {
+ BaseDir = "/plandex-server"
+ }
}
func InitPlan(orgId, planId string) error {
diff --git a/app/server/db/result_helpers.go b/app/server/db/result_helpers.go
index fe564c2e..99b67f91 100644
--- a/app/server/db/result_helpers.go
+++ b/app/server/db/result_helpers.go
@@ -327,7 +327,7 @@ func ApplyPlan(orgId, planId string) error {
}()
go func() {
- res, err := GetPlanContexts(orgId, planId, false)
+ res, err := GetPlanContexts(orgId, planId, true)
if err != nil {
errCh <- fmt.Errorf("error getting plan contexts: %v", err)
return
diff --git a/app/server/model/plan/tell.go b/app/server/model/plan/tell.go
index 2e114c87..3eeae0f5 100644
--- a/app/server/model/plan/tell.go
+++ b/app/server/model/plan/tell.go
@@ -427,6 +427,7 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReq
}
assistantMsg := db.ConvoMessage{
+ Id: replyId,
OrgId: currentOrgId,
PlanId: planId,
UserId: currentUserId,
diff --git a/app/shared/go.mod b/app/shared/go.mod
index 55317c46..d5657f4f 100644
--- a/app/shared/go.mod
+++ b/app/shared/go.mod
@@ -3,9 +3,8 @@ module shared
go 1.21.3
require (
- github.com/looplab/fsm v1.0.1
+ github.com/davecgh/go-spew v1.1.1
github.com/pkoukk/tiktoken-go v0.1.6
- github.com/sashabaranov/go-openai v1.15.1
)
require github.com/mattn/go-runewidth v0.0.9 // indirect
diff --git a/app/shared/go.sum b/app/shared/go.sum
index 9f354986..eb4abc85 100644
--- a/app/shared/go.sum
+++ b/app/shared/go.sum
@@ -4,8 +4,6 @@ github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/looplab/fsm v1.0.1 h1:OEW0ORrIx095N/6lgoGkFkotqH6s7vaFPsgjLAaF5QU=
-github.com/looplab/fsm v1.0.1/go.mod h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
@@ -14,8 +12,6 @@ github.com/pkoukk/tiktoken-go v0.1.6 h1:JF0TlJzhTbrI30wCvFuiw6FzP2+/bR+FIxUdgEAc
github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/sashabaranov/go-openai v1.15.1 h1:BAV5LCVEzvZ3rN/Lh5NRVs2z6AahPt/jn5s2/cEEG0M=
-github.com/sashabaranov/go-openai v1.15.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/app/shared/plan_result.go b/app/shared/plan_result.go
index fced5d31..11f4ab6f 100644
--- a/app/shared/plan_result.go
+++ b/app/shared/plan_result.go
@@ -92,26 +92,20 @@ func ApplyReplacements(content string, replacements []*Replacement, setFailed bo
sub := updated[lastInsertedIdx:]
originalIdx := strings.Index(sub, replacement.Old)
+ // log.Println("Replacement: " + replacement.Old + " -> " + replacement.New)
+ // log.Println("Pre: " + pre)
+ // log.Println("Sub: " + sub)
+ // log.Println("Idx: " + fmt.Sprintf("%d", idx))
+ // log.Println("Updated: " + updated)
+
if originalIdx == -1 {
allSucceeded = false
if setFailed {
replacement.Failed = true
}
-
- // jsonBytes, _ := json.Marshal(replacement)
- // log.Println(string(jsonBytes))
-
- // log.Println("Replacement: " + replacement.Old + " -> " + replacement.New)
-
} else {
replaced := strings.Replace(sub, replacement.Old, replacement.New, 1)
- // log.Println("Replacement: " + replacement.Old + " -> " + replacement.New)
- // log.Println("Pre: " + pre)
- // log.Println("Sub: " + sub)
- // log.Println("Idx: " + fmt.Sprintf("%d", idx))
- // log.Println("Updated: " + updated)
-
updated = pre + replaced
lastInsertedIdx = lastInsertedIdx + originalIdx + len(replacement.New)
}
@@ -134,14 +128,13 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(
shas := make(map[string]string)
for _, contextPart := range contexts {
+
if contextPart.FilePath == "" {
continue
}
_, hasPath := planRes.FileResultsByPath[contextPart.FilePath]
- // log.Printf("hasPath: %v\n", hasPath)
-
if hasPath {
files[contextPart.FilePath] = contextPart.Body
shas[contextPart.FilePath] = contextPart.Sha
@@ -151,11 +144,9 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(
for path, planResults := range planRes.FileResultsByPath {
updated := files[path]
- // log.Printf("path: %s\n", path)
- // log.Printf("updated: %s\n", updated)
-
PlanResLoop:
for _, planRes := range planResults {
+
if !planRes.IsPending() {
continue
}
@@ -176,10 +167,6 @@ func (planState *CurrentPlanState) GetFilesBeforeReplacement(
return nil, fmt.Errorf("result sha doesn't match context sha: %s", path)
}
- if len(planRes.Replacements) == 0 {
- continue
- }
-
replacements := []*Replacement{}
for _, replacement := range planRes.Replacements {
if replacement.Id == replacementId {
@@ -250,7 +237,7 @@ func (state *CurrentPlanState) PendingChangesSummary() string {
descMsgs = append(descMsgs, fmt.Sprintf("📝 %s", desc.CommitMsg))
if len(pendingNewFiles) > 0 {
- newMsg := " 📄 New files:\n\n"
+ newMsg := " 📄 New files:\n"
for _, path := range pendingNewFiles {
newMsg += fmt.Sprintf(" • %s\n", path)
}
@@ -258,7 +245,7 @@ func (state *CurrentPlanState) PendingChangesSummary() string {
}
if len(pendingReplacementPaths) > 0 {
- updatesMsg := " ✏️ Edits:\n\n"
+ updatesMsg := " ✏️ Edits:\n"
for _, path := range pendingReplacementPaths {
updatesMsg += fmt.Sprintf(" • %s\n", path)
@@ -272,7 +259,7 @@ func (state *CurrentPlanState) PendingChangesSummary() string {
descMsgs = append(descMsgs, updatesMsg)
}
- msgs = append(msgs, strings.Join(descMsgs, "\n\n"))
+ msgs = append(msgs, strings.Join(descMsgs, "\n"))
}
- return strings.Join(msgs, "\n\n")
+ return strings.Join(msgs, "\n")
}
diff --git a/infra/lib/main.ts b/infra/lib/main.ts
deleted file mode 100644
index 58f6793a..00000000
--- a/infra/lib/main.ts
+++ /dev/null
@@ -1,181 +0,0 @@
-import * as cdk from '@aws-cdk/core';
-import * as ec2 from '@aws-cdk/aws-ec2';
-import * as rds from '@aws-cdk/aws-rds';
-import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
-import * as ecs from '@aws-cdk/aws-ecs';
-import * as ecr from '@aws-cdk/aws-ecr';
-import * as efs from '@aws-cdk/aws-efs';
-import * as iam from '@aws-cdk/aws-iam';
-import * as ses from '@aws-cdk/aws-ses';
-
-export class MyStack extends cdk.Stack {
- constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
- super(scope, id, props);
-
- // Create a VPC with two public and two private subnets
- const vpc = new ec2.Vpc(this, 'MyVpc', {
- maxAzs: 2,
- subnetConfiguration: [
- {
- cidrMask: 24,
- name: 'PublicSubnet',
- subnetType: ec2.SubnetType.PUBLIC,
- },
- {
- cidrMask: 24,
- name: 'PrivateSubnet',
- subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
- },
- ],
- });
-
- // Create a Secrets Manager secret to store the RDS database credentials
- const dbCredentialsSecret = new secretsmanager.Secret(this, 'DBCredentialsSecret', {
- generateSecretString: {
- secretStringTemplate: JSON.stringify({ username: 'dbadmin' }),
- generateStringKey: 'password',
- excludeCharacters: '"@/\\',
- },
- });
-
- // Create an RDS Aurora PostgreSQL database
- const dbInstance = new rds.DatabaseInstance(this, 'MyRdsInstance', {
- engine: rds.DatabaseInstanceEngine.postgres({
- version: rds.PostgresEngineVersion.VER_12_4,
- }),
- instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
- vpc,
- vpcSubnets: {
- subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
- },
- credentials: rds.Credentials.fromSecret(dbCredentialsSecret), // Use credentials from Secrets Manager
- multiAz: false,
- allocatedStorage: 20,
- maxAllocatedStorage: 100,
- });
-
- // Create an ECR repository
- const ecrRepository = new ecr.Repository(this, 'MyEcrRepository');
-
- // Create an ECS cluster
- const ecsCluster = new ecs.Cluster(this, 'MyEcsCluster', {
- vpc,
- });
-
- // Create an EFS file system
- const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
- vpc,
- lifecyclePolicy: efs.LifecyclePolicy.AFTER_14_DAYS, // Automatically delete files not accessed for 14 days
- performanceMode: efs.PerformanceMode.GENERAL_PURPOSE,
- throughputMode: efs.ThroughputMode.BURSTING,
- });
-
- // Create a Fargate task definition with EFS volume
- const taskDefinition = new ecs.FargateTaskDefinition(this, 'MyTaskDefinition', {
- memoryLimitMiB: 512,
- cpu: 256,
- });
-
- // Add a container to the task definition
- const container = taskDefinition.addContainer('MyContainer', {
- image: ecs.ContainerImage.fromEcrRepository(ecrRepository),
- logging: new ecs.AwsLogDriver({ streamPrefix: 'MyContainer' }),
- });
-
- // Mount the EFS file system to the container
- const volumeName = 'MyEfsVolume';
- taskDefinition.addVolume({
- name: volumeName,
- efsVolumeConfiguration: {
- fileSystemId: fileSystem.fileSystemId,
- },
- });
- container.addMountPoints({
- sourceVolume: volumeName,
- containerPath: '/mnt/efs',
- readOnly: false,
- });
-
- // Create a Fargate service with a security group that allows outbound internet access and access to the RDS database
- const fargateServiceSecurityGroup = new ec2.SecurityGroup(this, 'FargateServiceSG', {
- vpc,
- allowAllOutbound: true, // Allows the containers to access the internet
- });
-
- // Define the ingress rule for the security group to allow the Fargate service to communicate with the RDS instance
- fargateServiceSecurityGroup.addIngressRule(
- ec2.Peer.anyIpv4(),
- ec2.Port.tcp(dbInstance.dbInstanceEndpointPort),
- 'Allow Fargate service to access RDS instance'
- );
-
- const fargateService = new ecs.FargateService(this, 'MyFargateService', {
- cluster: ecsCluster,
- taskDefinition,
- desiredCount: 1,
- securityGroups: [fargateServiceSecurityGroup],
- });
-
- // Create an IAM role for the Fargate task to interact with SES
- const taskRole = new iam.Role(this, 'FargateTaskRole', {
- assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
- managedPolicies: [
- iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSESFullAccess'),
- ],
- });
-
- // Attach the IAM role to the task definition
- taskDefinition.taskRole = taskRole;
-
- // Create an SES email sending resource
- // Note: SES setup can vary based on the region and verification status. Here, we're creating a simple rule set.
- const emailSendingResource = new ses.CfnReceiptRuleSet(this, 'MyEmailSendingResource', {
- ruleSetName: 'MyRuleSet',
- });
-
- // The SES rule set and other configurations would be set up here.
- // ...
-
- // Grant the Fargate task permission to send emails via SES
- // This is achieved by the managed policy attached to the task role.
-
- // Create an IAM role for the Fargate task to interact with SES
- const taskRole = new iam.Role(this, 'FargateTaskRole', {
- assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
- managedPolicies: [
- iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSESFullAccess'),
- ],
- });
-
- // Attach the IAM role to the task definition
- taskDefinition.taskRole = taskRole;
-
- // Create an SES email sending resource
- // Note: SES setup can vary based on the region and verification status. Here, we're creating a simple rule set.
- const emailSendingResource = new ses.CfnReceiptRuleSet(this, 'MyEmailSendingResource', {
- ruleSetName: 'MyRuleSet',
- });
-
- // The SES rule set and other configurations would be set up here.
- // ...
-
- // Grant the Fargate task permission to send emails via SES
- // This is achieved by the managed policy attached to the task role.
- engine: rds.DatabaseInstanceEngine.postgres({
- version: rds.PostgresEngineVersion.VER_12_4,
- }),
- instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
- vpc,
- vpcSubnets: {
- subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
- },
- credentials: rds.Credentials.fromSecret(dbCredentialsSecret), // Use credentials from Secrets Manager
- multiAz: false,
- allocatedStorage: 20,
- maxAllocatedStorage: 100,
- });
- }
-}
-
-const app = new cdk.App();
-new MyStack(app, 'MyStack');
diff --git a/infra/package.json b/infra/package.json
index 44dc1772..2dded510 100644
--- a/infra/package.json
+++ b/infra/package.json
@@ -3,18 +3,20 @@
"version": "1.0.0",
"private": true,
"dependencies": {
- "@aws-cdk/aws-ec2": "^1.85.0",
- "@aws-cdk/aws-rds": "^1.85.0",
- "@aws-cdk/aws-ecs": "^1.85.0",
- "@aws-cdk/aws-ecr": "^1.85.0",
- "@aws-cdk/aws-efs": "^1.85.0",
- "@aws-cdk/aws-secretsmanager": "^1.85.0",
- "@aws-cdk/aws-ses": "^1.85.0",
- "@aws-cdk/core": "^1.85.0"
+ "@aws-cdk/aws-ec2": "^1.203.0",
+ "@aws-cdk/aws-ecr": "^1.203.0",
+ "@aws-cdk/aws-ecs": "^1.203.0",
+ "@aws-cdk/aws-efs": "^1.203.0",
+ "@aws-cdk/aws-rds": "^1.203.0",
+ "@aws-cdk/aws-secretsmanager": "^1.203.0",
+ "@aws-cdk/aws-ses": "^1.203.0",
+ "@aws-cdk/core": "^1.203.0",
+ "uuid": "^9.0.1"
},
"devDependencies": {
- "aws-cdk": "^1.85.0",
- "typescript": "^4.1.0"
+ "@types/uuid": "^9.0.7",
+ "aws-cdk": "^2.122.0",
+ "typescript": "^5.3.3"
},
"scripts": {
"build": "tsc",