Skip to content

Commit f1e468f

Browse files
committed
feat(plan): add execute button for incomplete tasks and update plan handling #331
- Add an execute button for incomplete tasks in the ThoughtPlanSketchProvider to allow task execution. - Update plan handling logic to fetch plans from AgentStateService and refresh the PlanBoard UI. - Modify plan templates and documentation to improve clarity and structure. - Add new message bundle entries for task execution prompts.
1 parent c6c1210 commit f1e468f

File tree

9 files changed

+73
-24
lines changed

9 files changed

+73
-24
lines changed

core/src/main/kotlin/cc/unitmesh/devti/llms/custom/CustomLLMProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ class CustomLLMProvider(val project: Project, var llmConfig: LlmConfig = LlmConf
121121
*/
122122
private fun CustomLLMProvider.tryUpdateModelForPlan(systemPrompt: String): LlmConfig {
123123
val canBePlanLength = 3
124-
return if (messages.size == canBePlanLength && LlmConfig.hasPlanModel()) {
125-
if (messages.size == canBePlanLength) {
126-
messages[0] = Message("system", systemPrompt)
127-
}
124+
if (messages.size == canBePlanLength) {
125+
messages[0] = Message("system", systemPrompt)
126+
}
128127

128+
return if (messages.size == canBePlanLength && LlmConfig.hasPlanModel()) {
129129
backupLlmConfigForPlan = llmConfig
130130
LlmConfig.load(ModelType.Plan).first()
131131
} else {

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/AgentStateService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ class AgentStateService {
5959
.syncPublisher(PlanUpdateListener.TOPIC)
6060
.onPlanUpdate(items)
6161
}
62+
63+
fun getPlan(): MutableList<PlanList> {
64+
return state.planLists
65+
}
6266
}

core/src/main/kotlin/cc/unitmesh/devti/observer/plan/PlanBoard.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.observer.plan
22

3+
import cc.unitmesh.devti.observer.agent.AgentStateService
34
import cc.unitmesh.devti.observer.agent.PlanList
45
import cc.unitmesh.devti.observer.agent.PlanUpdateListener
56
import cc.unitmesh.devti.sketch.ui.PlanSketch
@@ -50,15 +51,18 @@ class PlanBoard(private val project: Project) : Disposable {
5051
return popup
5152
}
5253

53-
fun show(content: String, planLists: MutableList<PlanList>) {
54+
fun updateShow() {
55+
val planLists = project.getService(AgentStateService::class.java).getPlan()
5456
planSketch.updatePlan(planLists)
57+
5558
if (popup?.isVisible == true) return
5659

5760
try {
5861
if (popup?.isDisposed == true) {
5962
createPopup()
6063
}
6164

65+
popup?.content?.updateUI()
6266
popup?.showInFocusCenter()
6367
} catch (e: Exception) {
6468
logger<PlanBoard>().error("Failed to show popup", e)

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/ThoughtPlanSketchProvider.kt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package cc.unitmesh.devti.sketch.ui
22

3+
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.gui.AutoDevToolWindowFactory
5+
import cc.unitmesh.devti.gui.chat.message.ChatActionType
36
import cc.unitmesh.devti.observer.agent.AgentStateService
4-
import cc.unitmesh.devti.sketch.ui.code.CodeHighlightSketch
5-
import cc.unitmesh.devti.sketch.ui.plan.MarkdownPlanParser
67
import cc.unitmesh.devti.observer.agent.PlanList
78
import cc.unitmesh.devti.observer.plan.PlanBoard
9+
import cc.unitmesh.devti.sketch.ui.code.CodeHighlightSketch
10+
import cc.unitmesh.devti.sketch.ui.plan.MarkdownPlanParser
811
import com.intellij.icons.AllIcons
912
import com.intellij.lang.Language
1013
import com.intellij.openapi.actionSystem.ActionManager
@@ -20,12 +23,9 @@ import com.intellij.util.ui.JBEmptyBorder
2023
import com.intellij.util.ui.JBUI
2124
import com.intellij.util.ui.UIUtil
2225
import java.awt.BorderLayout
26+
import java.awt.Dimension
2327
import java.awt.FlowLayout
24-
import javax.swing.Box
25-
import javax.swing.BoxLayout
26-
import javax.swing.JComponent
27-
import javax.swing.JLabel
28-
import javax.swing.JPanel
28+
import javax.swing.*
2929

3030
class ThoughtPlanSketchProvider : LanguageSketchProvider {
3131
override fun isSupported(lang: String): Boolean = lang == "plan"
@@ -89,7 +89,8 @@ class PlanSketch(
8989
override fun displayTextInToolbar(): Boolean = true
9090

9191
override fun actionPerformed(e: AnActionEvent) {
92-
project.getService(PlanBoard::class.java).show(content, planLists)
92+
project.getService(AgentStateService::class.java).updatePlan(planLists)
93+
project.getService(PlanBoard::class.java).updateShow()
9394
}
9495
}
9596

@@ -126,6 +127,23 @@ class PlanSketch(
126127
}
127128

128129
taskPanel.add(checkbox)
130+
131+
if (!task.completed) {
132+
val executeButton = JButton(AllIcons.Actions.Execute).apply {
133+
border = BorderFactory.createEmptyBorder()
134+
preferredSize = Dimension(32, 32)
135+
toolTipText = "Execute"
136+
137+
addActionListener {
138+
AutoDevToolWindowFactory.sendToSketchToolWindow(project, ChatActionType.SKETCH) { ui, _ ->
139+
ui.sendInput(AutoDevBundle.message("sketch.plan.finish.task") + task.description)
140+
}
141+
}
142+
}
143+
144+
taskPanel.add(executeButton)
145+
}
146+
129147
contentPanel.add(taskPanel)
130148
}
131149

core/src/main/resources/genius/zh/code/plan.devin

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ Here is the rule you should follow:
4141
1. Thoroughly review `<user.question>`. Create/update an initial plan that includes all the necessary steps to
4242
resolve `<user.question>`, using the recommended steps provided below, and incorporating any requirements from
4343
the `<user.question>`. Place your plan inside code-fence block which language is `plan`.
44-
2. Review the project’s codebase, examining not only its structure but also the specific implementation details, to
44+
2. Plan should use a markdown ordered list to describe tasks and an unordered list to outline the steps for each task.
45+
3. Review the project’s codebase, examining not only its structure but also the specific implementation details, to
4546
identify all segments that may contribute to or help resolve the issue described in `<user.question>`.
46-
3. If `<user.question>` describes an error, create a script to reproduce it and run the script to confirm the error.
47-
4. Propose and explain the necessary code modifications to resolve `<user.question>`, ensuring that edge cases are
47+
4. If `<user.question>` describes an error, create a script to reproduce it and run the script to confirm the error.
48+
5. Propose and explain the necessary code modifications to resolve `<user.question>`, ensuring that edge cases are
4849
properly handled. Analyze these modifications before implementing them.
49-
5. use `<devin></devin>` command and code-fence block to Edit the source code in the repo to resolve `<user.question>`.
5050
6. You should alwasy think verify or auto-test your code to ensure it is correct and meets the requirements of `<user.question>`.
51-
7. Each plan should use a markdown ordered list to describe tasks and an unordered list to outline the steps for each task.
51+
52+
For example:
53+
54+
```plan
55+
1. xxx
56+
- [ ] xxx
57+
2. xxx
58+
```
5259

5360
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
5461
first. Be thorough in your thinking process, so it's okay if it is lengthy.

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ have created a routes.py and main.js file, and updated the main.html file.
7272
</devin>
7373
</you.answer.step2>
7474
// ... If you provide a plan to the user, you should update it using a Markdown to-do list as you receive more contextual information.
75+
// ```plan
76+
// 1. 创建 routes.py
77+
// - [x] 定义 "/upload" 和 "/query" 端点
78+
// - [x] 添加 "/" 作为 main.html 的端点。
79+
// 2. 创建 main.js。存储所有的交互式前端代码
80+
// - [ ] 创建并定义 UI 元素
81+
// 3. 更新 index.html
82+
// 4. 自动化测试与验证
83+
// - [ ] 使用 Flask 的测试框架编写自动化测试用例
84+
// 5. 运行应用程序,测试和验证
85+
// - [ ] 运行应用程序
86+
// ```
7587
<you.answer.stepN>
7688
// In this step 2, You should first explain to the user how to solve the problem, and then use the DevIn language
7789
// 并且不要在 explain 阶段编写代码,只在编码步骤生成代码
@@ -93,7 +105,7 @@ have created a routes.py and main.js file, and updated the main.html file.
93105
看看是否一切正常。
94106

95107
# 总结
96-
如是,我已经完成了您的需求,您可以继续测试和验证应用程序。如下是更新后的计划
108+
如是,我已经完成了您的需求,您可以继续测试和验证应用程序。如下是根据上下文信息,更新后的计划,添加了更多的步骤
97109

98110
```plan
99111
1. 创建 routes.py
@@ -227,11 +239,10 @@ It is EXTREMELY important that your generated code can be run immediately by the
227239
It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task.
228240
This approach allows you to:
229241

230-
1. Confirm the success of each step before proceeding.
231-
2. Address any issues or errors that arise immediately.
232-
3. Adapt your approach based on new information or unexpected results.
233-
4. Ensure that each action builds correctly on the previous ones.
234-
5. Update the plan in every conversation turn based on the user's responses.
242+
1. 以最开始的计划为基础,当发现问题时;调整计划时,需要更新到原来的计划,确保最后的计划是最新的。
243+
2. 在每一步操作之前,确保上一步操作的成功。
244+
3. 立即解决任何出现的问题或错误。
245+
4. 根据新信息或意外结果调整你的方法、步骤、计划,更新到原来的计划中。
235246

236247
By waiting for and carefully considering the user's response after each tool use, you can react
237248
accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,4 @@ autodev.run.action=Run this file
226226
#llm.error.url.scheme=请配置好您的模型,参考文档:https://ide.unitmesh.cc/quick-start
227227
llm.error.url.scheme=Please, Please, Please configure your model, refer to the document: https://ide.unitmesh.cc/quick-start
228228
counit.mcp.services.placeholder=MCP Servers
229+
sketch.plan.finish.task=Please help me finish task:

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,4 @@ sketch.compile.devins=收集上下文中(即转译 AutoDev DevIns 指令)
229229
autodev.run.action=Run this file
230230
llm.error.url.scheme=请请请先配置好您的模型,参考文档:https://ide.unitmesh.cc/quick-start
231231
counit.mcp.services.placeholder=MCP Servers
232+
sketch.plan.finish.task=Please help me finish task:

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteInsCommand.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
102102

103103
runInEdt {
104104
FileEditorManager.getInstance(myProject).openFile(newFile, true)
105+
}
106+
107+
ApplicationManager.getApplication().invokeLater {
105108
document.setText(content)
106109
}
107110

0 commit comments

Comments
 (0)