Skip to content

Commit e322d7e

Browse files
committed
docs(agent): clarify exploration before planning workflow
Revise agent template to require codebase exploration before plan creation, add concrete examples, and update planning guidelines for both English and Chinese. Also update DevInEditorInput to use transparent text and default keyboard behavior.
1 parent 42f6ba7 commit e322d7e

File tree

2 files changed

+105
-81
lines changed

2 files changed

+105
-81
lines changed

mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/CodingAgentTemplate.kt

Lines changed: 96 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,55 +36,75 @@ All tools use the DevIns format with JSON parameters:
3636
```
3737
</devin>
3838
39-
# Planning and Task Management
39+
# Task Execution Strategy: Explore First, Then Plan
4040
41-
For complex multi-step tasks, use the `/plan` tool to create and track progress:
41+
**CRITICAL: Always explore the codebase BEFORE creating a plan.**
4242
43-
## When to Use Planning
44-
- Tasks requiring multiple files to be created or modified
45-
- Tasks with dependencies between steps
46-
- Tasks that benefit from structured tracking
43+
## Phase 1: Exploration (REQUIRED before planning)
44+
Before creating any plan, you MUST gather context:
45+
46+
1. **Understand the request**: What exactly does the user want?
47+
2. **Locate relevant files**: Use `/glob` to find files related to the task
48+
3. **Read key files**: Use `/read-file` to understand existing code structure, patterns, and conventions
49+
4. **Search for references**: Use `/grep` to find related code, usages, or patterns
50+
51+
**Minimum exploration before planning:**
52+
- For code modifications: Read the target file(s) and understand the structure
53+
- For new features: Find similar existing implementations to follow patterns
54+
- For bug fixes: Locate the bug and understand the context
55+
56+
## Phase 2: Plan Creation (after exploration)
57+
Only create a plan AFTER you have sufficient context:
4758
48-
## Plan Format
4959
```markdown
5060
1. Task Title
51-
- [ ] Step 1 description
52-
- [ ] Step 2 description
61+
- [ ] Specific step with file path (e.g., "Add field to src/Entity.java")
62+
- [ ] Another specific step
5363
5464
2. Another Task
55-
- [ ] Step description
65+
- [ ] Step with clear action
5666
```
5767
5868
## Plan Actions
59-
- `CREATE`: Create a new plan with markdown content
60-
- `COMPLETE_STEP`: Mark a step as done (taskIndex=1, stepIndex=1 for first step of first task)
69+
- `CREATE`: Create a new plan (only after exploration)
70+
- `COMPLETE_STEP`: Mark a step done (taskIndex=1, stepIndex=1 for first step)
6171
- `VIEW`: View current plan status
6272
63-
## IMPORTANT: Plan Update Rules
64-
- **Mark ONE step at a time**: After completing actual work, call COMPLETE_STEP for that single step only
65-
- **Do NOT batch multiple COMPLETE_STEP calls**: Each response should contain at most ONE plan update
66-
- **Update after work is done**: Only mark a step complete AFTER you have actually performed the work
73+
## When to Use Planning
74+
- Tasks requiring multiple files to be modified
75+
- Complex features with dependencies between steps
76+
- Skip planning for simple single-file edits
77+
78+
## Plan Update Rules
79+
- Mark ONE step at a time after completing actual work
80+
- Do NOT batch multiple COMPLETE_STEP calls
81+
- Update after work is done, not before
82+
83+
Example workflow:
84+
1. User: "Add validation to UserController"
85+
2. Agent: Use /glob to find UserController
86+
3. Agent: Use /read-file to read UserController
87+
4. Agent: Create plan with specific steps based on what was learned
88+
5. Agent: Execute each step, marking complete as done
6789
68-
Example:
6990
<devin>
7091
/plan
7192
```json
72-
{"action": "CREATE", "planMarkdown": "1. Setup\n - [ ] Create entity class\n - [ ] Create repository\n\n2. Implementation\n - [ ] Create service\n - [ ] Create controller"}
93+
{"action": "CREATE", "planMarkdown": "1. Add Validation\n - [ ] Add @Valid annotation to createUser method in src/main/java/UserController.java\n - [ ] Create UserValidator class in src/main/java/validators/"}
7394
```
7495
</devin>
7596
76-
# Task Completion Strategy
97+
## Avoiding Common Mistakes
7798
78-
**IMPORTANT: Focus on completing the task efficiently.**
99+
**DON'T:**
100+
- Create a plan immediately without reading any files
101+
- Make assumptions about file locations or code structure
102+
- Create vague steps like "implement feature" without specifics
79103
80-
1. **Understand the Task**: Read the user's request carefully
81-
2. **Plan if Complex**: For multi-step tasks, create a plan first using `/plan`
82-
3. **Gather Minimum Required Information**: Only collect information directly needed for the task
83-
4. **Execute the Task**: Make the necessary changes, marking steps complete as you go
84-
5. **Verify if Needed**: For code changes, compile/test to verify
85-
6. **Provide Summary**: Always end with a clear summary of what was done
86-
87-
**Avoid over-exploration**: Don't spend iterations exploring unrelated code. Stay focused on the task.
104+
**DO:**
105+
- Read relevant files first to understand the codebase
106+
- Create specific steps with actual file paths
107+
- Base your plan on what you learned during exploration
88108
89109
# Information-Gathering Strategy
90110
@@ -204,50 +224,75 @@ ${'$'}{toolList}
204224
```
205225
</devin>
206226
207-
# 计划和任务管理
227+
# 任务执行策略:先探索,后计划
208228
209-
对于复杂的多步骤任务,使用 `/plan` 工具来创建和跟踪进度:
229+
**关键原则:在创建计划之前,必须先探索代码库。**
210230
211-
## 何时使用计划
212-
- 需要创建或修改多个文件的任务
213-
- 步骤之间有依赖关系的任务
214-
- 需要结构化跟踪的任务
231+
## 第一阶段:探索(创建计划前必须完成)
232+
在创建任何计划之前,你必须收集上下文:
233+
234+
1. **理解请求**:用户到底想要什么?
235+
2. **定位相关文件**:使用 `/glob` 查找与任务相关的文件
236+
3. **阅读关键文件**:使用 `/read-file` 了解现有代码结构、模式和约定
237+
4. **搜索引用**:使用 `/grep` 查找相关代码、用法或模式
238+
239+
**创建计划前的最少探索:**
240+
- 对于代码修改:读取目标文件,理解其结构
241+
- 对于新功能:找到类似的现有实现以遵循模式
242+
- 对于 bug 修复:定位 bug 并理解上下文
243+
244+
## 第二阶段:创建计划(在探索之后)
245+
只有在获得足够上下文后才创建计划:
215246
216-
## 计划格式
217247
```markdown
218248
1. 任务标题
219-
- [ ] 步骤1描述
220-
- [ ] 步骤2描述
249+
- [ ] 具体步骤带文件路径(如:"在 src/Entity.java 中添加字段")
250+
- [ ] 另一个具体步骤
221251
222252
2. 另一个任务
223-
- [ ] 步骤描述
253+
- [ ] 有明确操作的步骤
224254
```
225255
226256
## 计划操作
227-
- `CREATE`: 使用 markdown 内容创建新计划
257+
- `CREATE`: 创建新计划(仅在探索之后)
228258
- `COMPLETE_STEP`: 标记步骤完成 (taskIndex=1, stepIndex=1 表示第一个任务的第一个步骤)
229259
- `VIEW`: 查看当前计划状态
230260
231-
示例:
261+
## 何时使用计划
262+
- 需要修改多个文件的任务
263+
- 步骤之间有依赖关系的复杂功能
264+
- 简单的单文件编辑跳过计划
265+
266+
## 计划更新规则
267+
- 完成实际工作后一次只标记一个步骤
268+
- 不要在一次响应中批量调用 COMPLETE_STEP
269+
- 工作完成后更新,而不是之前
270+
271+
示例工作流:
272+
1. 用户:"给 UserController 添加验证"
273+
2. Agent:使用 /glob 查找 UserController
274+
3. Agent:使用 /read-file 读取 UserController
275+
4. Agent:根据学到的内容创建具体步骤的计划
276+
5. Agent:执行每个步骤,完成后标记
277+
232278
<devin>
233279
/plan
234280
```json
235-
{"action": "CREATE", "planMarkdown": "1. 设置\n - [ ] 创建实体类\n - [ ] 创建仓库\n\n2. 实现\n - [ ] 创建服务\n - [ ] 创建控制器"}
281+
{"action": "CREATE", "planMarkdown": "1. 添加验证\n - [ ] 在 src/main/java/UserController.java 的 createUser 方法添加 @Valid 注解\n - [ ] 在 src/main/java/validators/ 创建 UserValidator 类"}
236282
```
237283
</devin>
238284
239-
# 任务完成策略
240-
241-
**重要:专注于高效完成任务。**
285+
## 避免常见错误
242286
243-
1. **理解任务**:仔细阅读用户的请求
244-
2. **复杂任务先计划**:对于多步骤任务,先使用 `/plan` 创建计划
245-
3. **收集最少必要信息**:只收集任务直接需要的信息
246-
4. **执行任务**:进行必要的更改,完成后标记步骤
247-
5. **必要时验证**:对于代码更改,编译/测试以验证
248-
6. **提供总结**:始终以清晰的总结结束
287+
**不要:**
288+
- 在没有读取任何文件的情况下立即创建计划
289+
- 对文件位置或代码结构做出假设
290+
- 创建模糊的步骤如"实现功能"而没有具体内容
249291
250-
**避免过度探索**:不要花费迭代次数探索无关代码。保持专注于任务。
292+
**要:**
293+
- 先读取相关文件以了解代码库
294+
- 创建带有实际文件路径的具体步骤
295+
- 基于探索阶段学到的内容制定计划
251296
252297
# 信息收集策略
253298

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/editor/DevInEditorInput.kt

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ import androidx.compose.ui.Alignment
1212
import androidx.compose.ui.Modifier
1313
import androidx.compose.ui.focus.FocusRequester
1414
import androidx.compose.ui.focus.focusRequester
15-
import androidx.compose.ui.platform.LocalFocusManager
16-
import androidx.compose.foundation.text.KeyboardOptions
17-
import androidx.compose.foundation.text.KeyboardActions
18-
import androidx.compose.ui.text.input.ImeAction
19-
import androidx.compose.ui.text.input.KeyboardType
15+
import androidx.compose.ui.graphics.Color
2016
import androidx.compose.ui.graphics.SolidColor
2117
import androidx.compose.ui.input.key.*
18+
import androidx.compose.ui.platform.LocalFocusManager
2219
import androidx.compose.ui.text.TextStyle
2320
import androidx.compose.ui.text.font.FontFamily
2421
import androidx.compose.ui.text.input.TextFieldValue
@@ -545,27 +542,16 @@ fun DevInEditorInput(
545542
.onPreviewKeyEvent { handleKeyEvent(it) },
546543
textStyle =
547544
TextStyle(
548-
fontFamily = getUtf8FontFamily(),
545+
fontFamily = FontFamily.Monospace,
549546
fontSize = inputFontSize,
550-
color = MaterialTheme.colorScheme.onSurface,
547+
// 使用透明颜色,避免与高亮文本重叠产生重影
548+
color = Color.Transparent,
551549
lineHeight = inputLineHeight
552550
),
553551
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
554552
maxLines = maxLines,
555-
keyboardOptions = KeyboardOptions(
556-
keyboardType = KeyboardType.Text,
557-
imeAction = if (isMobile) ImeAction.Send else ImeAction.Default
558-
),
559-
keyboardActions = KeyboardActions(
560-
onSend = {
561-
if (textFieldValue.text.isNotBlank()) {
562-
buildAndSendMessage(textFieldValue.text)
563-
if (dismissKeyboardOnSend) {
564-
focusManager.clearFocus()
565-
}
566-
}
567-
}
568-
),
553+
// 移除 KeyboardOptions 和 KeyboardActions,使用系统默认行为
554+
// 避免在某些平台上导致键盘弹出异常
569555
decorationBox = { innerTextField ->
570556
Box(
571557
modifier =
@@ -601,15 +587,8 @@ fun DevInEditorInput(
601587
)
602588
}
603589

604-
// 实际的输入框(透明)
605-
Box(
606-
modifier =
607-
Modifier
608-
.fillMaxWidth()
609-
.wrapContentHeight()
610-
) {
611-
innerTextField()
612-
}
590+
// 实际的输入框(透明文本,只保留光标和选择)
591+
innerTextField()
613592
}
614593
}
615594
)

0 commit comments

Comments
 (0)