Files
Agent-System/internal/intent/run_matcher.go
T
WeiCHENandCursor 9cb129d3e8 feat(intent): Phase 4 run control, subtypes, and limited IntentPlan
Add RUN_STATUS_QUERY/RUN_RESUME/RUN_RESTART with matcher and coordinator
handlers; write QUERY_PROGRESS/SUPPLEMENT_INFO subtypes to V2 frame; support
safe query+query multi-intent plans via IntentPlan dual-write.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 02:50:21 +00:00

80 lines
2.6 KiB
Go

package intent
import "strings"
func isRunControlInput(input string) bool {
runMarkers := []string{
"继续", "续跑", "接着跑", "继续上次", "继续任务", "恢复运行", "恢复任务",
"重来", "重新运行", "重启", "从头开始", "重新跑",
"运行状态", "任务状态", "执行状态", "跑到哪", "失败了吗", "完成了吗", "任务进度",
"上次任务", "这次运行", "工作区",
}
for _, m := range runMarkers {
if strings.Contains(input, m) {
return true
}
}
return false
}
func matchRunControl(input string, snap *ContextSnapshot) *CandidateIntent {
if !isRunControlInput(input) {
return nil
}
// 避免与挂起预期裸肯定词冲突(「继续」单独出现且 pending 存在时由 expectation 处理)
if strings.TrimSpace(input) == "继续" || strings.TrimSpace(input) == "接着" {
return nil
}
slots := map[string]string{}
if snap != nil && snap.SnapshotID != "" {
_ = snap.SnapshotID
}
restartMarkers := []string{"重来", "重新运行", "重启", "从头开始", "重新跑", "重新执行"}
for _, m := range restartMarkers {
if strings.Contains(input, m) {
slots[SlotRunAction] = "restart"
return &CandidateIntent{
Intent: IntentRunRestart,
Confidence: 0.91,
FilledSlots: slots,
Reasoning: "用户请求重新启动长任务运行(将创建新工作区,保留原意图)",
}
}
}
resumeMarkers := []string{"继续", "续跑", "接着跑", "继续上次", "继续任务", "恢复运行", "恢复任务"}
for _, m := range resumeMarkers {
if strings.Contains(input, m) {
slots[SlotRunAction] = "resume"
cand := &CandidateIntent{
Intent: IntentRunResume,
Confidence: 0.90,
FilledSlots: slots,
Reasoning: "用户请求续跑/恢复已有长任务工作区",
}
if snap == nil || (len(slots[SlotWorkDir]) == 0) {
cand.ClarificationQuestion = "请说明要续跑的具体任务或失败阶段;若您指的是最近一次失败运行,请确认后我将基于该工作区继续。"
}
return cand
}
}
if detectDialogueAct(input) == DialogueActAsk ||
strings.Contains(input, "状态") || strings.Contains(input, "失败了吗") ||
strings.Contains(input, "完成了吗") || strings.Contains(input, "跑到哪") {
slots[SlotRunAction] = "status"
return &CandidateIntent{
Intent: IntentRunStatusQuery,
Confidence: 0.89,
FilledSlots: map[string]string{
SlotRunAction: "status",
SlotQueryTopic: "run_status",
},
Reasoning: "用户查询长任务/工作流运行状态(只读)",
}
}
return nil
}