add autonomy control-file switching and block-reason status analytics

This commit is contained in:
DBT
2026-02-24 03:29:38 +00:00
parent c4b17f648e
commit a0585508ee
3 changed files with 99 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"bufio"
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
@@ -44,9 +45,15 @@ func gatewayCmd() {
os.Exit(1)
}
return
case "autonomy":
if err := gatewayAutonomyControlCmd(args[1:]); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
return
default:
fmt.Printf("Unknown gateway command: %s\n", args[0])
fmt.Println("Usage: clawgo gateway [run|start|stop|restart|status]")
fmt.Println("Usage: clawgo gateway [run|start|stop|restart|status|autonomy on|off|status]")
return
}
@@ -301,6 +308,58 @@ func gatewayCmd() {
}
}
func gatewayAutonomyControlCmd(args []string) error {
if len(args) < 1 {
return fmt.Errorf("usage: clawgo gateway autonomy [on|off|status]")
}
cfg, err := loadConfig()
if err != nil {
return err
}
memDir := filepath.Join(cfg.WorkspacePath(), "memory")
if err := os.MkdirAll(memDir, 0755); err != nil {
return err
}
pausePath := filepath.Join(memDir, "autonomy.pause")
ctrlPath := filepath.Join(memDir, "autonomy.control.json")
switch strings.ToLower(strings.TrimSpace(args[0])) {
case "on":
_ = os.Remove(pausePath)
if err := os.WriteFile(ctrlPath, []byte("{\n \"enabled\": true\n}\n"), 0644); err != nil {
return err
}
fmt.Println("✓ Autonomy enabled")
return nil
case "off":
if err := os.WriteFile(ctrlPath, []byte("{\n \"enabled\": false\n}\n"), 0644); err != nil {
return err
}
if err := os.WriteFile(pausePath, []byte(time.Now().UTC().Format(time.RFC3339)+"\n"), 0644); err != nil {
return err
}
fmt.Println("✓ Autonomy disabled (paused)")
return nil
case "status":
enabled := true
if data, err := os.ReadFile(ctrlPath); err == nil {
var c struct{ Enabled bool `json:"enabled"` }
if json.Unmarshal(data, &c) == nil {
enabled = c.Enabled
}
}
if _, err := os.Stat(pausePath); err == nil {
enabled = false
}
fmt.Printf("Autonomy status: %v\n", enabled)
fmt.Printf("Control file: %s\n", ctrlPath)
fmt.Printf("Pause file: %s\n", pausePath)
return nil
default:
return fmt.Errorf("usage: clawgo gateway autonomy [on|off|status]")
}
}
func summarizeAutonomyChanges(oldCfg, newCfg *config.Config) []string {
if oldCfg == nil || newCfg == nil {
return nil

View File

@@ -138,6 +138,7 @@ func statusCmd() {
if nextRetry != "" {
fmt.Printf("Autonomy Next Retry: %s\n", nextRetry)
}
fmt.Printf("Autonomy Control: %s\n", autonomyControlState(workspace))
}
}
}
@@ -164,6 +165,25 @@ func printTemplateField(name, current, def string) {
fmt.Printf(" %s: %s\n", name, state)
}
func autonomyControlState(workspace string) string {
memDir := filepath.Join(workspace, "memory")
pausePath := filepath.Join(memDir, "autonomy.pause")
if _, err := os.Stat(pausePath); err == nil {
return "paused (autonomy.pause)"
}
ctrlPath := filepath.Join(memDir, "autonomy.control.json")
if data, err := os.ReadFile(ctrlPath); err == nil {
var c struct{ Enabled bool `json:"enabled"` }
if json.Unmarshal(data, &c) == nil {
if c.Enabled {
return "enabled"
}
return "disabled (control file)"
}
}
return "default"
}
func collectSessionKindCounts(sessionsDir string) (map[string]int, error) {
indexPath := filepath.Join(sessionsDir, "sessions.json")
data, err := os.ReadFile(indexPath)