autonomy M1: add idle-safe task policy whitelist and fix active-user detection path

This commit is contained in:
DBT
2026-02-28 05:32:00 +00:00
parent 09bc89bc1e
commit 17d8b7f605
3 changed files with 29 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ type Options struct {
QuietHours string
UserIdleResumeSec int
WaitingResumeDebounceSec int
AllowedTaskKeywords []string
ImportantKeywords []string
CompletionTemplate string
BlockedTemplate string
@@ -273,6 +274,9 @@ func (e *Engine) tick() {
if !st.LastRunAt.IsZero() && now.Sub(st.LastRunAt) < time.Duration(e.opts.MinRunIntervalSec)*time.Second {
continue
}
if !e.allowTaskByPolicy(st.Content) {
continue
}
if st.Status == "running" && now.Sub(st.LastRunAt) > time.Duration(e.opts.MaxPendingDurationSec)*time.Second {
st.ConsecutiveStall++
if st.ConsecutiveStall > e.opts.MaxConsecutiveStalls {
@@ -839,10 +843,14 @@ func (e *Engine) hasRecentUserActivity(now time.Time) bool {
if e.opts.UserIdleResumeSec <= 0 || strings.TrimSpace(e.opts.Workspace) == "" {
return false
}
sessionsPath := filepath.Join(filepath.Dir(e.opts.Workspace), "sessions", "sessions.json")
sessionsPath := filepath.Join(filepath.Dir(e.opts.Workspace), "agents", "main", "sessions", "sessions.json")
data, err := os.ReadFile(sessionsPath)
if err != nil {
return false
legacy := filepath.Join(filepath.Dir(e.opts.Workspace), "sessions", "sessions.json")
data, err = os.ReadFile(legacy)
if err != nil {
return false
}
}
var index map[string]struct {
Kind string `json:"kind"`
@@ -866,6 +874,22 @@ func (e *Engine) hasRecentUserActivity(now time.Time) bool {
return false
}
func (e *Engine) allowTaskByPolicy(content string) bool {
if len(e.opts.AllowedTaskKeywords) == 0 {
return true
}
v := strings.ToLower(content)
for _, kw := range e.opts.AllowedTaskKeywords {
if kw == "" {
continue
}
if strings.Contains(v, strings.ToLower(kw)) {
return true
}
}
return false
}
func latestUserMessageTime(path string) time.Time {
f, err := os.Open(path)
if err != nil {