diff --git a/README.md b/README.md index 889acc8..9de45d0 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ clawgo gateway status # 前台运行 clawgo gateway run + +# 自治开关(运行态) +clawgo gateway autonomy status +clawgo gateway autonomy on +clawgo gateway autonomy off ``` ## 📌 命令总览 diff --git a/README_EN.md b/README_EN.md index b5b7e9e..b7bacbe 100644 --- a/README_EN.md +++ b/README_EN.md @@ -57,6 +57,11 @@ clawgo gateway status # foreground run clawgo gateway run + +# runtime autonomy switches +clawgo gateway autonomy status +clawgo gateway autonomy on +clawgo gateway autonomy off ``` ## 📌 Command Reference diff --git a/pkg/autonomy/engine.go b/pkg/autonomy/engine.go index 4b0bc47..e99c844 100644 --- a/pkg/autonomy/engine.go +++ b/pkg/autonomy/engine.go @@ -41,6 +41,7 @@ type taskState struct { DueAt string Status string // idle|running|waiting|blocked|completed BlockReason string + WaitingSince time.Time LastRunAt time.Time LastAutonomyAt time.Time RetryAfter time.Time @@ -126,6 +127,7 @@ func (e *Engine) tick() { if st.Status == "running" { st.Status = "waiting" st.BlockReason = "manual_pause" + st.WaitingSince = now e.writeReflectLog("waiting", st, "paused by manual switch") e.writeTriggerAudit("waiting", st, "manual_pause") } @@ -139,6 +141,7 @@ func (e *Engine) tick() { if st.Status == "running" { st.Status = "waiting" st.BlockReason = "active_user" + st.WaitingSince = now e.writeReflectLog("waiting", st, "paused due to active user conversation") e.writeTriggerAudit("waiting", st, "active_user") } @@ -223,9 +226,14 @@ func (e *Engine) tick() { continue } if st.Status == "waiting" { + // Debounce waiting/resume flapping + if !st.WaitingSince.IsZero() && now.Sub(st.WaitingSince) < 5*time.Second { + continue + } reason := st.BlockReason st.Status = "idle" st.BlockReason = "" + st.WaitingSince = time.Time{} e.writeReflectLog("resume", st, "autonomy resumed from waiting") e.writeTriggerAudit("resume", st, reason) } @@ -257,6 +265,7 @@ func (e *Engine) tick() { e.dispatchTask(st) st.Status = "running" st.BlockReason = "" + st.WaitingSince = time.Time{} st.LastRunAt = now st.LastAutonomyAt = now e.writeReflectLog("dispatch", st, "task dispatched to agent loop")