Skip to content

Commit 584e2f5

Browse files
committed
feat(core): add support for user-defined coding rules #349
- Implement user-defined coding rules support in ProjectRule and SketchRunContext - Update template to include instructions for using user-defined rules - Modify rule content formatting for better integration with existing rules
1 parent 4a02594 commit 584e2f5

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchRunContext.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ data class SketchRunContext(
7373
val projectRule = ProjectRule(project)
7474
val rules = projectRule.getAllRules().map { it.nameWithoutExtension }
7575
val rule = if (rules.isNotEmpty()) {
76-
val allRules = "- User custom coding rules file:" + rules.joinToString(",") { it }
76+
val allRules = "- User custom coding rules file names:" + rules.joinToString(",") { it }
7777
val string = if (projectRule.hasRule("README")) {
78-
projectRule.getRuleContent("README")?.let {
79-
"<rule> $it </rule>"
80-
} ?: ""
78+
projectRule.getRuleContent("README") ?: ""
8179
} else ""
8280

8381
if (string.isNotEmpty()) {

core/src/main/kotlin/cc/unitmesh/devti/sketch/rule/ProjectRule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class ProjectRule(private val project: Project) {
2222
val file = project.lookupFile(fullname)
2323

2424
if (file != null) {
25-
return file.readText()
25+
val content = file.readText()
26+
return "<user-rule>\n$content\n</user-rule>"
2627
}
2728

2829
return file

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ It is EXTREMELY important that your generated code can be run immediately by the
224224
- If you've suggested a reasonable code_edit that wasn't followed by the apply model, you should try reapplying the edit.
225225
</making_code_changes>
226226

227+
<rule>
228+
用户可以通过 user-rule 来自定义编程规范,以生成更符合自己需要的代码。如果用户定制了规则,您需要在每次调用工具之前检查这些规则,并在代码中应用它们。
229+
</rule>
230+
227231
<plan>
228232
It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task.
229233
This approach allows you to:

docs/composer/proejct-rule.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ structure and configuration. The project rule is defined under `prompts/rules` d
1313
For example, the project rule file is defined as follows:
1414

1515
```bash
16-
promtps/rules/
16+
prompts/rules/
1717
├── service.md
1818
├── controller.md
19+
├── repository.md
1920
├── rpc.md
2021
└── README.md # will always load this file default !!
2122
```

0 commit comments

Comments
 (0)