Code Cleanup and Quality of Life

Checks to make sure repo is indexed before generating code.
Don't generate tests for changes to tests.
Remove unused code.
Fix bootstrapping issue with langchaingo tables.
This commit is contained in:
2025-04-20 08:31:26 -04:00
parent 4b8b8132fd
commit 25f8cae8cb
9 changed files with 282 additions and 256 deletions

View File

@@ -3,6 +3,7 @@ package autopatch
import (
"ai-code-assistant/pkg/config"
"ai-code-assistant/pkg/database"
"ai-code-assistant/pkg/indexer"
"ai-code-assistant/pkg/llm"
"bytes"
"context"
@@ -48,6 +49,13 @@ func (a *agent) run(ctx context.Context, cmd *cli.Command) error {
llmRef := llm.FromContext(ctx)
a.llm = llmRef
// Make sure we're indexed.
idx := indexer.New(ctx, cmd.String("repo"), config.FromContext(ctx).IndexChunkSize, false)
if err := idx.Index(ctx); err != nil {
return err
}
// Attempt to generate the commit.
err := a.generateGitCommit(ctx, cmd.String("repo"), cmd.String("task"))
if err != nil {
return err
@@ -57,20 +65,26 @@ func (a *agent) run(ctx context.Context, cmd *cli.Command) error {
}
func (a *agent) generateGitCommit(ctx context.Context, repoPath, prompt string) error {
var affectedFiles []string
fileName, newCode, err := a.generateCodePatch(ctx, repoPath, prompt)
if err != nil {
return err
}
testFile, err := a.generateUnitTest(ctx, prompt, fileName, newCode)
if err != nil {
return err
affectedFiles = append(affectedFiles, fileName)
// If we modified a test, we don't need to generate a test.
if !strings.HasSuffix(fileName, "_test.go") {
testFile, err := a.generateUnitTest(ctx, prompt, fileName, newCode)
if err != nil {
return err
}
affectedFiles = append(affectedFiles, testFile)
}
// fileName, testFile := "/home/mpowers/Projects/simple-go-server/main.go", "/home/mpowers/Projects/simple-go-server/main_test.go"
if err := a.commit(ctx, prompt, repoPath, fileName, testFile); err != nil {
if err := a.commit(ctx, prompt, repoPath, affectedFiles...); err != nil {
return err
}
@@ -126,7 +140,7 @@ func (a *agent) generateCodePatch(ctx context.Context, repoPath, prompt string)
db := database.FromContext(ctx)
cfg := config.FromContext(ctx)
repoID, err := db.RepoIDFromPath(ctx, repoPath)
repoID, _, err := db.UpsertRepo(ctx, repoPath)
if err != nil {
return "", "", err
}