Skip to content

Commit 6b53958

Browse files
committed
Package moves
1 parent 578313d commit 6b53958

File tree

12 files changed

+140
-81
lines changed

12 files changed

+140
-81
lines changed

src/main/kotlin/com/embabel/coding/agent/AgentProjectCreator.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.embabel.agent.api.annotation.AgentCapabilities
2121
import com.embabel.agent.api.annotation.fromForm
2222
import com.embabel.agent.api.common.OperationContext
2323
import com.embabel.coding.domain.SoftwareProject
24+
import com.embabel.coding.domain.TaskFocus
2425
import org.slf4j.LoggerFactory
2526
import org.springframework.context.annotation.Profile
2627
import java.io.File
@@ -42,9 +43,9 @@ data class AgentRequirements(
4243
)
4344
@Profile("!test")
4445
class AgentProjectCreator(
45-
val root: File = File(System.getProperty("user.dir")).parentFile,
46-
// val workingDirName: String = "embabel-coder",
46+
private val coderProperties: CoderProperties,
4747
private val taskFocus: TaskFocus,
48+
properties: CoderProperties,
4849
) {
4950

5051
private val logger = LoggerFactory.getLogger(AgentProjectCreator::class.java)
@@ -60,18 +61,12 @@ class AgentProjectCreator(
6061
): SoftwareProject {
6162
logger.info("Creating Agent project named {}", requirements.projectName)
6263

63-
val workDir = root//File(root, workingDirName)
64-
65-
// TODO is this safe
66-
// val projectDir = File(root, requirements.projectName)
67-
// projectDir.mkdirs()
68-
64+
val workDir = coderProperties.root
6965
val newAgentProject = createProject(workDir, requirements)
7066
taskFocus.saveAndSwitch(newAgentProject)
7167
return newAgentProject
7268
}
7369

74-
7570
@Action(
7671
pre = [
7772
CoderConditions.BUILD_SUCCEEDED],

src/main/kotlin/com/embabel/coding/agent/Coder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.embabel.agent.api.common.create
2222
import com.embabel.agent.core.CoreToolGroups
2323
import com.embabel.agent.core.count
2424
import com.embabel.agent.domain.io.UserInput
25-
import com.embabel.coding.domain.SoftwareProject
25+
import com.embabel.coding.domain.*
2626
import com.embabel.coding.tools.BuildResult
2727
import com.embabel.common.util.time
2828
import org.slf4j.LoggerFactory

src/main/kotlin/com/embabel/coding/agent/CoderProperties.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,25 @@ import com.embabel.agent.config.models.AnthropicModels
1919
import com.embabel.common.ai.model.LlmOptions
2020
import com.embabel.common.ai.model.ModelSelectionCriteria
2121
import com.embabel.common.ai.prompt.PromptContributor
22-
import com.embabel.common.util.loggerFor
2322
import org.springframework.boot.context.properties.ConfigurationProperties
23+
import java.io.File
2424

2525
/**
2626
* Common configuration and utilities
27+
* @param primaryCodingModel The primary coding model to use for code modifications.
28+
* @param fixCodingModel The model to use for fixing broken builds.
29+
* @param projectRoot The root directory for the coding agent. Defaults to the parent
30+
* of the current working directory.
31+
* @param findNestedProjects Whether to search for nested projects in the project root.
32+
* For example, nested Maven projects. Slows down loading if set to true.
2733
*/
28-
@ConfigurationProperties(prefix = "embabel.coding")
34+
@ConfigurationProperties(prefix = "embabel.coder")
2935
data class CoderProperties(
30-
val primaryCodingModel: String = AnthropicModels.Companion.CLAUDE_37_SONNET,//OllamaModels.QWEN2_5_CODER,
36+
val primaryCodingModel: String = AnthropicModels.Companion.CLAUDE_37_SONNET,
3137
val fixCodingModel: String = AnthropicModels.Companion.CLAUDE_40_OPUS,
38+
val projectRoot: String? = null,
39+
val findNestedProjects: Boolean = false,
40+
val defaultProject: String? = null,
3241
private val codeModificationDirections: String = """
3342
Use the file tools to read code and directories.
3443
Use the web tools if you are asked to use a technology you don't know about.
@@ -37,14 +46,12 @@ data class CoderProperties(
3746
""".trimIndent()
3847
) {
3948

49+
val root: File = File(projectRoot ?: System.getProperty("user.dir")).parentFile
50+
4051
fun codeModificationDirections() = PromptContributor.fixed(
4152
codeModificationDirections,
4253
)
4354

44-
init {
45-
loggerFor<CoderProperties>().info("Coding properties: {}", this)
46-
}
47-
4855
/**
4956
* Primary coding Llm
5057
*/

src/main/kotlin/com/embabel/coding/agent/CodingCommands.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.embabel.coding.agent
1717

18+
import com.embabel.coding.domain.TaskFocus
1819
import org.springframework.shell.standard.ShellComponent
1920
import org.springframework.shell.standard.ShellMethod
2021
import org.springframework.shell.standard.ShellOption

src/main/kotlin/com/embabel/coding/agent/LogWriter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package com.embabel.coding.agent
1717

18+
import com.embabel.coding.domain.CodeModificationRequest
1819
import com.embabel.coding.domain.SoftwareProject
20+
import com.embabel.coding.domain.SuccessfulCodeModification
1921

2022
/**
2123
* Log the changes we've made to the codebase.

src/main/kotlin/com/embabel/coding/agent/TaskFocus.kt

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/main/kotlin/com/embabel/coding/agent/support/InProjectLogWriter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.embabel.coding.agent.support
22

3-
import com.embabel.coding.agent.CodeModificationRequest
43
import com.embabel.coding.agent.LogWriter
5-
import com.embabel.coding.agent.SuccessfulCodeModification
4+
import com.embabel.coding.domain.CodeModificationRequest
65
import com.embabel.coding.domain.SoftwareProject
6+
import com.embabel.coding.domain.SuccessfulCodeModification
77
import com.fasterxml.jackson.databind.ObjectMapper
88
import org.springframework.stereotype.Service
99

src/main/kotlin/com/embabel/coding/agent/domain.kt renamed to src/main/kotlin/com/embabel/coding/domain/CodeModification.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.embabel.coding.agent
1+
package com.embabel.coding.domain
22

33
import com.embabel.agent.domain.library.HasContent
44
import com.embabel.common.core.MobyNameGenerator
@@ -57,7 +57,7 @@ data class CodeModificationReport(
5757
val text: String,
5858
val filesChanged: List<String>
5959
) : HasContent {
60-
60+
6161
override val content: String
6262
get() = text
6363
}

src/main/kotlin/com/embabel/coding/domain/FromDiskSoftwareProjectRepository.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ package com.embabel.coding.domain
1717

1818
import com.embabel.agent.domain.InMemoryCrudRepository
1919
import com.embabel.agent.tools.file.FileTools
20+
import com.embabel.coding.agent.CoderProperties
2021
import org.slf4j.LoggerFactory
2122
import org.springframework.stereotype.Service
22-
import java.io.File
2323

2424
/**
25-
* Look under directory
25+
* Look for parallel directories
2626
*/
2727
@Service
2828
class FromDiskSoftwareProjectRepository(
29-
val root: File = File(System.getProperty("user.dir")).parentFile,
29+
private val properties: CoderProperties,
3030
) : SoftwareProjectRepository,
3131
InMemoryCrudRepository<SoftwareProject>(
3232
idGetter = { it.root },
@@ -37,14 +37,18 @@ class FromDiskSoftwareProjectRepository(
3737

3838
init {
3939
this.saveAll(findProjectsUnderRoot())
40+
logger.info("Loaded {} projects from disk", this.count())
41+
logger.info(
42+
"Projects:\n\t{}", this.findAll().sortedBy { it.root }.joinToString("\n\t") { it.root })
4043
}
4144

4245
private fun findProjectsUnderRoot(): List<SoftwareProject> {
43-
val rootFileTools = FileTools.readOnly(root.absolutePath)
46+
val rootFileTools = FileTools.readOnly(properties.root.absolutePath)
4447
logger.info("Looking under {} for projects", rootFileTools.root)
45-
val pomFiles = rootFileTools.findFiles("**/pom.xml")
46-
// TODO why is this needed?
47-
.filterNot { it.contains("..") }
48+
val pomFiles = rootFileTools.findFiles(
49+
glob = "**/pom.xml",
50+
findHighest = !properties.findNestedProjects
51+
)
4852
logger.info("Found {} Maven projects", pomFiles.size)
4953
return pomFiles
5054
.map { it.replace("pom.xml", "") }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.embabel.coding.domain
2+
3+
import com.embabel.agent.tools.file.FileReadTools
4+
import com.embabel.agent.tools.file.WellKnownFileContentTransformers
5+
import com.embabel.common.ai.prompt.PromptContributor
6+
import com.embabel.common.core.types.Described
7+
import com.embabel.common.core.types.Named
8+
import com.embabel.common.util.StringTransformer
9+
10+
/**
11+
* Reference
12+
* Must be added as tools and prompt contributor
13+
*/
14+
interface Reference : PromptContributor, Named, Described
15+
16+
/**
17+
* Reference to another project
18+
*/
19+
class ProjectReference(
20+
override val name: String,
21+
override val description: String,
22+
override val root: String,
23+
) : Reference, FileReadTools {
24+
25+
override val fileContentTransformers: List<StringTransformer>
26+
get() = listOf(WellKnownFileContentTransformers.removeApacheLicenseHeader)
27+
28+
override fun contribution(): String {
29+
return """
30+
|Software project: $name
31+
|Description: $description
32+
|Root: $root
33+
|Use file tools to read files in the project.
34+
"""".trimIndent()
35+
}
36+
}
37+
38+
/**
39+
* Directory structure but not a software project
40+
*/
41+
class FilesReference(
42+
override val name: String,
43+
override val description: String,
44+
override val root: String,
45+
) : Reference, FileReadTools {
46+
47+
override val fileContentTransformers: List<StringTransformer>
48+
get() = listOf(WellKnownFileContentTransformers.removeApacheLicenseHeader)
49+
50+
override fun contribution(): String {
51+
return """
52+
|Documentation: $name
53+
|Description: $description
54+
|Root: $root
55+
|Use file tools to read documents.
56+
"""".trimIndent()
57+
}
58+
}

0 commit comments

Comments
 (0)