feat(intents): 删除 work 改为「停止+记录原因」,不再销毁数据
删除不再删意图与其产出,而是:停到 stopped、要求填写删除原因、把原因作为 事实挂到该意图上、并写进意图 payload,规划者收到 cancelled 触发(意图内容+原因)。 - db: StopIntentWithReason —— 标 stopped + 建原因事实 + 连边 + 合并 payload (cancelled_by_user/cancel_reason),单事务;旧 CancelIntent 保留不再被调用 - agent/server: renderTriggers 加 cancelled 分支;Task.NotifyCancelled; controlIntent/applyIntentControl 接收并要求 reason - web: 删除弹窗改为必填原因的 Textarea;列表用红色垃圾桶+删除线+「已删除」徽标 区分;选中会话顶部横幅展示删除原因;controlIntent 传 reason Claude-Session: https://claude.ai/code/session_019QXSCDmzimwnjntBNCgUD7
This commit is contained in:
1 parent
3297ca1821
commit
025e1ce445
7 files changed
+182
-39
No files matched your search
@@ -1488,6 +1488,18 @@ func (t *Task) NotifyGoal(texts []string) {
|
||||
t.Notify()
|
||||
}
|
||||
|
||||
// NotifyCancelled records that the human deleted intentID (reason = 删除原因), then
|
||||
// wakes the planner so the next round spells out which intent was removed and why.
|
||||
// The intent is stopped (not deleted); the reason is attached to it as a fact.
|
||||
func (t *Task) NotifyCancelled(intentID int64, reason string) {
|
||||
if intentID > 0 {
|
||||
t.trigMu.Lock()
|
||||
t.pendingTriggers = append(t.pendingTriggers, agent.TriggerEvent{Kind: "cancelled", IntentID: intentID, Detail: reason})
|
||||
t.trigMu.Unlock()
|
||||
}
|
||||
t.Notify()
|
||||
}
|
||||
|
||||
// drainTriggers returns and clears the trigger events accumulated since the last round.
|
||||
func (t *Task) drainTriggers() []agent.TriggerEvent {
|
||||
t.trigMu.Lock()
|
||||
|
||||
+2
-1
@@ -1055,6 +1055,7 @@ func (s *Server) controlIntent(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
var req struct {
|
||||
Action string `json:"action"`
|
||||
Reason string `json:"reason"` // cancel(删除)时必填:删除原因,挂为事实并告知 planner
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeErr(w, 400, "bad json: "+err.Error())
|
||||
@@ -1065,7 +1066,7 @@ func (s *Server) controlIntent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := s.applyIntentControl(r.Context(), t, iid, req.Action)
|
||||
result, err := s.applyIntentControl(r.Context(), t, iid, req.Action, req.Reason)
|
||||
if err != nil {
|
||||
writeErr(w, 409, err.Error())
|
||||
return
|
||||
|
||||
+11
-6
@@ -115,7 +115,7 @@ func (s *Server) applyTaskControlWithCause(t *Task, action string, pauseCause er
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *Server) applyIntentControl(ctx context.Context, t *Task, iid int64, action string) (intentControlResult, error) {
|
||||
func (s *Server) applyIntentControl(ctx context.Context, t *Task, iid int64, action, reason string) (intentControlResult, error) {
|
||||
out := intentControlResult{ID: iid}
|
||||
node, err := t.Store.GetNode(iid)
|
||||
if err != nil {
|
||||
@@ -153,20 +153,25 @@ func (s *Server) applyIntentControl(ctx context.Context, t *Task, iid int64, act
|
||||
t.Notify()
|
||||
out.State = "open"
|
||||
case "cancel":
|
||||
// 「删除」新语义:不销毁意图与产出,而是把意图停到 stopped、把用户填写的删除原因
|
||||
// 作为一条事实挂到该意图上,并用 cancelled 触发告知 planner(意图内容 + 删除原因)。
|
||||
if node.State != "running" && node.State != "paused" {
|
||||
return out, fmt.Errorf("仅运行中或已暂停的意图可以取消")
|
||||
return out, fmt.Errorf("仅运行中或已暂停的意图可以删除")
|
||||
}
|
||||
reason = strings.TrimSpace(reason)
|
||||
if reason == "" {
|
||||
return out, fmt.Errorf("请填写删除原因")
|
||||
}
|
||||
if node.State == "running" {
|
||||
if err := s.engine.ControlWork(ctx, iid, "cancel"); err != nil {
|
||||
return out, err
|
||||
}
|
||||
}
|
||||
deleted, err := t.Store.CancelIntent(iid)
|
||||
if err != nil {
|
||||
if _, err := t.Store.StopIntentWithReason(iid, reason, "user"); err != nil {
|
||||
return out, err
|
||||
}
|
||||
t.Notify()
|
||||
out.State, out.Deleted = "cancelled", &deleted
|
||||
t.NotifyCancelled(iid, reason)
|
||||
out.State = "stopped"
|
||||
default:
|
||||
return out, fmt.Errorf("action must be pause|resume|cancel")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user