Skip to content

Commit cba74ec

Browse files
committed
feat(prompt): add project README information to enhance prompt context #358
- Include README.md content from project root in prompt enhancement- Add conditional logic to display README information if available - Update PromptEnhancer and PromptEnhancerContext to support README data
1 parent 1c29646 commit cba74ec

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/indexer/usage/PromptEnhancer.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package cc.unitmesh.devti.indexer.usage
22

33
import cc.unitmesh.devti.indexer.DomainDictService
44
import cc.unitmesh.devti.llms.LlmFactory
5+
import cc.unitmesh.devti.sketch.ui.patch.readText
56
import cc.unitmesh.devti.template.GENIUS_CODE
67
import cc.unitmesh.devti.template.TemplateRender
78
import cc.unitmesh.devti.template.context.TemplateContext
89
import com.intellij.openapi.components.Service
910
import com.intellij.openapi.project.Project
11+
import com.intellij.openapi.project.guessProjectDir
1012

1113
@Service(Service.Level.PROJECT)
1214
class PromptEnhancer(val project: Project) {
@@ -15,7 +17,10 @@ class PromptEnhancer(val project: Project) {
1517

1618
suspend fun create(input: String): String {
1719
val dict = project.getService(DomainDictService::class.java).loadContent() ?: ""
18-
val context = PromptEnhancerContext(dict, input)
20+
val readme = project.guessProjectDir()?.findChild("README.md")?.let {
21+
runCatching { it.readText() }.getOrNull() ?: ""
22+
} ?: ""
23+
val context = PromptEnhancerContext(dict, input, readme)
1924
val prompt = templateRender.renderTemplate(template, context)
2025

2126
var result = StringBuilder()
@@ -29,7 +34,8 @@ class PromptEnhancer(val project: Project) {
2934

3035
data class PromptEnhancerContext(
3136
val dict: String,
32-
val userInput: String
37+
val userInput: String,
38+
val readme: String = "",
3339
) : TemplateContext {
3440

3541
}

core/src/main/resources/genius/en/code/enhance.vm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
$context.dict
77
```
88

9+
#if( $context.readme.length() > 0 )
10+
以下是项目的 README 信息
11+
==========
12+
$context.readme
13+
==========
14+
#end
15+
916
输出格式要求:
1017

1118
- 使用 markdown 代码块返回结果,方便我解析

core/src/main/resources/genius/zh/code/enhance.vm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
$context.dict
77
```
88

9+
#if( $context.readme.length() > 0 )
10+
以下是项目的 README 信息
11+
==========
12+
$context.readme
13+
==========
14+
#end
15+
916
输出格式要求:
1017

1118
- 使用 markdown 代码块返回结果,方便我解析

0 commit comments

Comments
 (0)