Skip to content

Commit e722e4a

Browse files
committed
refactor(plan): rename PlanList to AgentPlan and update related references #331
- Renamed `PlanList` to `AgentPlan` and updated all references. - Changed `planLists` to `agentPlans` and `planTasks` to `tasks` for consistency. - Updated related classes, methods, and tests to reflect the new naming.
1 parent 45bf139 commit e722e4a

File tree

9 files changed

+98
-97
lines changed

9 files changed

+98
-97
lines changed

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

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

33
import cc.unitmesh.devti.agent.tool.AgentTool
44
import cc.unitmesh.devti.llms.custom.Message
5+
import cc.unitmesh.devti.observer.plan.AgentPlan
56
import com.intellij.openapi.vcs.changes.Change
67
import java.util.UUID
78

@@ -24,6 +25,6 @@ data class AgentState(
2425
*/
2526
var environment: Map<String, String> = emptyMap(),
2627

27-
var planLists: MutableList<PlanList> = mutableListOf()
28+
var plan: MutableList<AgentPlan> = mutableListOf()
2829
)
2930

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cc.unitmesh.devti.observer.agent
33
import cc.unitmesh.devti.agent.tool.AgentTool
44
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
55
import cc.unitmesh.devti.llms.custom.Message
6+
import cc.unitmesh.devti.observer.plan.AgentPlan
7+
import cc.unitmesh.devti.observer.plan.PlanUpdateListener
68
import com.intellij.openapi.application.ApplicationManager
79
import com.intellij.openapi.components.Service
810
import com.intellij.openapi.diagnostic.logger
@@ -53,14 +55,14 @@ class AgentStateService {
5355
return state.messages
5456
}
5557

56-
fun updatePlan(items: MutableList<PlanList>) {
57-
this.state.planLists = items
58+
fun updatePlan(items: MutableList<AgentPlan>) {
59+
this.state.plan = items
5860
ApplicationManager.getApplication().messageBus
5961
.syncPublisher(PlanUpdateListener.TOPIC)
6062
.onPlanUpdate(items)
6163
}
6264

63-
fun getPlan(): MutableList<PlanList> {
64-
return state.planLists
65+
fun getPlan(): MutableList<AgentPlan> {
66+
return state.plan
6567
}
6668
}

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/PlanList.kt renamed to core/src/main/kotlin/cc/unitmesh/devti/observer/plan/AgentPlan.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
package cc.unitmesh.devti.observer.agent
1+
package cc.unitmesh.devti.observer.plan
22

33
import kotlinx.serialization.Serializable
44

55
@Serializable
6-
data class PlanList(
6+
data class AgentPlan(
77
val title: String,
8-
val planTasks: List<PlanTask>,
8+
val tasks: List<PlanTask>,
99
var completed: Boolean = false,
1010
var status: TaskStatus = TaskStatus.TODO
1111
) {
1212
/**
1313
* Updates the completion status based on the tasks' statuses
1414
*/
1515
fun updateCompletionStatus() {
16-
if (planTasks.isEmpty()) return
16+
if (tasks.isEmpty()) return
1717

1818
// Check if all tasks are completed
19-
completed = planTasks.all { it.status == TaskStatus.COMPLETED }
19+
completed = tasks.all { it.status == TaskStatus.COMPLETED }
2020

2121
// Determine section status based on tasks
2222
status = when {
23-
planTasks.all { it.status == TaskStatus.COMPLETED } -> TaskStatus.COMPLETED
24-
planTasks.any { it.status == TaskStatus.FAILED } -> TaskStatus.FAILED
25-
planTasks.any { it.status == TaskStatus.IN_PROGRESS } -> TaskStatus.IN_PROGRESS
23+
tasks.all { it.status == TaskStatus.COMPLETED } -> TaskStatus.COMPLETED
24+
tasks.any { it.status == TaskStatus.FAILED } -> TaskStatus.FAILED
25+
tasks.any { it.status == TaskStatus.IN_PROGRESS } -> TaskStatus.IN_PROGRESS
2626
else -> TaskStatus.TODO
2727
}
2828
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cc.unitmesh.devti.observer.plan
22

33
import cc.unitmesh.devti.observer.agent.AgentStateService
4-
import cc.unitmesh.devti.observer.agent.PlanList
5-
import cc.unitmesh.devti.observer.agent.PlanUpdateListener
64
import cc.unitmesh.devti.sketch.ui.PlanSketch
75
import com.intellij.icons.AllIcons
86
import com.intellij.openapi.Disposable
@@ -23,7 +21,7 @@ class PlanBoard(private val project: Project) : Disposable {
2321
init {
2422
createPopup()
2523
connection.subscribe(PlanUpdateListener.TOPIC, object : PlanUpdateListener {
26-
override fun onPlanUpdate(items: MutableList<PlanList>) {
24+
override fun onPlanUpdate(items: MutableList<AgentPlan>) {
2725
planSketch.updatePlan(items)
2826
}
2927
})

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/PlanTask.kt renamed to core/src/main/kotlin/cc/unitmesh/devti/observer/plan/PlanTask.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package cc.unitmesh.devti.observer.agent
1+
package cc.unitmesh.devti.observer.plan
22

33
import kotlinx.serialization.Serializable
44

55
/**
66
* 计划任务,描述了一个具体任务的细节和状态
7-
* @property description 任务描述
7+
* @property step 任务描述
88
* @property completed 任务是否已完成
99
* @property status 任务状态(COMPLETED, FAILED, IN_PROGRESS, TODO)
1010
*/
1111
@Serializable
1212
class PlanTask(
13-
val description: String,
13+
val step: String,
1414
var completed: Boolean = false,
1515
var status: TaskStatus = TaskStatus.TODO
1616
) {
@@ -59,7 +59,7 @@ class PlanTask(
5959
TaskStatus.IN_PROGRESS -> "[*]"
6060
TaskStatus.TODO -> "[ ]"
6161
}
62-
return "$statusMarker $description"
62+
return "$statusMarker $step"
6363
}
6464

6565
/**

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/PlanUpdateListener.kt renamed to core/src/main/kotlin/cc/unitmesh/devti/observer/plan/PlanUpdateListener.kt

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

33
import com.intellij.util.messages.Topic
44
import java.util.*
55

66
@FunctionalInterface
77
interface PlanUpdateListener: EventListener {
8-
fun onPlanUpdate(items: MutableList<PlanList>)
8+
fun onPlanUpdate(items: MutableList<AgentPlan>)
99

1010
companion object {
1111
@Topic.AppLevel

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.gui.AutoDevToolWindowFactory
55
import cc.unitmesh.devti.gui.chat.message.ChatActionType
66
import cc.unitmesh.devti.observer.agent.AgentStateService
7-
import cc.unitmesh.devti.observer.agent.PlanList
8-
import cc.unitmesh.devti.observer.agent.PlanTask
9-
import cc.unitmesh.devti.observer.agent.TaskStatus
7+
import cc.unitmesh.devti.observer.plan.AgentPlan
8+
import cc.unitmesh.devti.observer.plan.PlanTask
9+
import cc.unitmesh.devti.observer.plan.TaskStatus
1010
import cc.unitmesh.devti.observer.plan.PlanBoard
1111
import cc.unitmesh.devti.sketch.ui.code.CodeHighlightSketch
1212
import cc.unitmesh.devti.sketch.ui.plan.MarkdownPlanParser
@@ -47,7 +47,7 @@ class ThoughtPlanSketchProvider : LanguageSketchProvider {
4747
class PlanSketch(
4848
private val project: Project,
4949
private var content: String,
50-
private val planLists: MutableList<PlanList>,
50+
private val agentPlans: MutableList<AgentPlan>,
5151
private val isInPopup: Boolean = false
5252
) : JBPanel<PlanSketch>(BorderLayout()), ExtensionLangSketch {
5353
private val panel = JBPanel<PlanSketch>(BorderLayout())
@@ -91,7 +91,7 @@ class PlanSketch(
9191
override fun displayTextInToolbar(): Boolean = true
9292

9393
override fun actionPerformed(e: AnActionEvent) {
94-
project.getService(AgentStateService::class.java).updatePlan(planLists)
94+
project.getService(AgentStateService::class.java).updatePlan(agentPlans)
9595
project.getService(PlanBoard::class.java).updateShow()
9696
}
9797
}
@@ -101,7 +101,7 @@ class PlanSketch(
101101

102102

103103
private fun createPlanUI() {
104-
planLists.forEachIndexed { index, planItem ->
104+
agentPlans.forEachIndexed { index, planItem ->
105105
val titlePanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT)).apply {
106106
border = JBUI.Borders.empty()
107107
}
@@ -128,7 +128,7 @@ class PlanSketch(
128128
titlePanel.add(sectionLabel)
129129
contentPanel.add(titlePanel)
130130

131-
planItem.planTasks.forEachIndexed { taskIndex, task ->
131+
planItem.tasks.forEachIndexed { taskIndex, task ->
132132
val taskPanel = JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT)).apply {
133133
border = JBUI.Borders.empty()
134134
}
@@ -152,7 +152,7 @@ class PlanSketch(
152152
}
153153

154154
// Update section status when task status changes
155-
val currentSection = planLists.find { it.planTasks.contains(task) }
155+
val currentSection = agentPlans.find { it.tasks.contains(task) }
156156
currentSection?.let { updateSectionCompletionStatus(it) }
157157

158158
updateTaskLabel(taskLabel, task)
@@ -175,7 +175,7 @@ class PlanSketch(
175175

176176
addActionListener {
177177
AutoDevToolWindowFactory.sendToSketchToolWindow(project, ChatActionType.SKETCH) { ui, _ ->
178-
ui.sendInput(AutoDevBundle.message("sketch.plan.finish.task") + task.description)
178+
ui.sendInput(AutoDevBundle.message("sketch.plan.finish.task") + task.step)
179179
}
180180
}
181181
}
@@ -197,7 +197,7 @@ class PlanSketch(
197197
updateTaskLabel(taskLabel, task)
198198

199199
// Update section status after changing task status
200-
val currentSection = planLists.find { it.planTasks.contains(task) }
200+
val currentSection = agentPlans.find { it.tasks.contains(task) }
201201
currentSection?.let { updateSectionCompletionStatus(it) }
202202

203203
contentPanel.revalidate()
@@ -208,7 +208,7 @@ class PlanSketch(
208208
task.updateStatus(TaskStatus.IN_PROGRESS)
209209
updateTaskLabel(taskLabel, task)
210210

211-
val currentSection = planLists.find { it.planTasks.contains(task) }
211+
val currentSection = agentPlans.find { it.tasks.contains(task) }
212212
currentSection?.let { updateSectionCompletionStatus(it) }
213213

214214
contentPanel.revalidate()
@@ -219,7 +219,7 @@ class PlanSketch(
219219
task.updateStatus(TaskStatus.FAILED)
220220
updateTaskLabel(taskLabel, task)
221221

222-
val currentSection = planLists.find { it.planTasks.contains(task) }
222+
val currentSection = agentPlans.find { it.tasks.contains(task) }
223223
currentSection?.let { updateSectionCompletionStatus(it) }
224224

225225
contentPanel.revalidate()
@@ -230,7 +230,7 @@ class PlanSketch(
230230
task.updateStatus(TaskStatus.TODO)
231231
updateTaskLabel(taskLabel, task)
232232

233-
val currentSection = planLists.find { it.planTasks.contains(task) }
233+
val currentSection = agentPlans.find { it.tasks.contains(task) }
234234
currentSection?.let { updateSectionCompletionStatus(it) }
235235

236236
contentPanel.revalidate()
@@ -247,7 +247,7 @@ class PlanSketch(
247247
contentPanel.add(taskPanel)
248248
}
249249

250-
if (index < planLists.size - 1) {
250+
if (index < agentPlans.size - 1) {
251251
contentPanel.add(Box.createVerticalStrut(8))
252252
}
253253
}
@@ -256,10 +256,10 @@ class PlanSketch(
256256
// Helper method to create a styled task label based on status
257257
private fun createStyledTaskLabel(task: PlanTask): JLabel {
258258
val labelText = when (task.status) {
259-
TaskStatus.COMPLETED -> "<html><strike>${task.description}</strike></html>"
260-
TaskStatus.FAILED -> "<html><span style='color:red'>${task.description}</span></html>"
261-
TaskStatus.IN_PROGRESS -> "<html><span style='color:blue;font-style:italic'>${task.description}</span></html>"
262-
TaskStatus.TODO -> task.description
259+
TaskStatus.COMPLETED -> "<html><strike>${task.step}</strike></html>"
260+
TaskStatus.FAILED -> "<html><span style='color:red'>${task.step}</span></html>"
261+
TaskStatus.IN_PROGRESS -> "<html><span style='color:blue;font-style:italic'>${task.step}</span></html>"
262+
TaskStatus.TODO -> task.step
263263
}
264264

265265
return JLabel(labelText).apply {
@@ -270,15 +270,15 @@ class PlanSketch(
270270
// Helper method to update the task label based on current status
271271
private fun updateTaskLabel(label: JLabel, task: PlanTask) {
272272
label.text = when (task.status) {
273-
TaskStatus.COMPLETED -> "<html><strike>${task.description}</strike></html>"
274-
TaskStatus.FAILED -> "<html><span style='color:red'>${task.description}</span></html>"
275-
TaskStatus.IN_PROGRESS -> "<html><span style='color:blue;font-style:italic'>${task.description}</span></html>"
276-
TaskStatus.TODO -> task.description
273+
TaskStatus.COMPLETED -> "<html><strike>${task.step}</strike></html>"
274+
TaskStatus.FAILED -> "<html><span style='color:red'>${task.step}</span></html>"
275+
TaskStatus.IN_PROGRESS -> "<html><span style='color:blue;font-style:italic'>${task.step}</span></html>"
276+
TaskStatus.TODO -> task.step
277277
}
278278
}
279279

280280
// Helper method to update section completion status based on tasks
281-
private fun updateSectionCompletionStatus(planItem: PlanList) {
281+
private fun updateSectionCompletionStatus(planItem: AgentPlan) {
282282
// Use the new method instead of reflection
283283
planItem.updateCompletionStatus()
284284

@@ -300,26 +300,26 @@ class PlanSketch(
300300
updatePlan(MarkdownPlanParser.parse(text))
301301
}
302302

303-
fun updatePlan(newPlanItems: List<PlanList>) {
303+
fun updatePlan(newPlanItems: List<AgentPlan>) {
304304
if (newPlanItems.isNotEmpty()) {
305305
// Save current states of all tasks
306306
val taskStateMap = mutableMapOf<String, Pair<Boolean, TaskStatus>>()
307307

308-
planLists.forEach { planItem ->
309-
planItem.planTasks.forEach { task ->
310-
taskStateMap[task.description] = Pair(task.completed, task.status)
308+
agentPlans.forEach { planItem ->
309+
planItem.tasks.forEach { task ->
310+
taskStateMap[task.step] = Pair(task.completed, task.status)
311311
}
312312
}
313313

314314
contentPanel.removeAll()
315-
planLists.clear()
315+
agentPlans.clear()
316316

317317
newPlanItems.forEach { newItem ->
318-
planLists.add(newItem)
318+
agentPlans.add(newItem)
319319

320-
newItem.planTasks.forEach { task ->
320+
newItem.tasks.forEach { task ->
321321
// Restore saved states if available
322-
taskStateMap[task.description]?.let { (completed, status) ->
322+
taskStateMap[task.step]?.let { (completed, status) ->
323323
task.completed = completed
324324
task.status = status
325325
}
@@ -338,7 +338,7 @@ class PlanSketch(
338338
override fun onDoneStream(allText: String) {
339339
if (!isInPopup) {
340340
updatePlan(this.content)
341-
project.getService(AgentStateService::class.java).updatePlan(planLists)
341+
project.getService(AgentStateService::class.java).updatePlan(agentPlans)
342342
}
343343
}
344344

0 commit comments

Comments
 (0)