mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-21 01:13:31 +08:00
enhance autonomy operational telemetry and control status details
This commit is contained in:
@@ -323,16 +323,31 @@ func gatewayAutonomyControlCmd(args []string) error {
|
|||||||
pausePath := filepath.Join(memDir, "autonomy.pause")
|
pausePath := filepath.Join(memDir, "autonomy.pause")
|
||||||
ctrlPath := filepath.Join(memDir, "autonomy.control.json")
|
ctrlPath := filepath.Join(memDir, "autonomy.control.json")
|
||||||
|
|
||||||
|
type autonomyControl struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
UpdatedAt string `json:"updated_at"`
|
||||||
|
Source string `json:"source"`
|
||||||
|
}
|
||||||
|
|
||||||
|
writeControl := func(enabled bool) error {
|
||||||
|
c := autonomyControl{Enabled: enabled, UpdatedAt: time.Now().UTC().Format(time.RFC3339), Source: "manual_cli"}
|
||||||
|
data, err := json.MarshalIndent(c, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.WriteFile(ctrlPath, append(data, '\n'), 0644)
|
||||||
|
}
|
||||||
|
|
||||||
switch strings.ToLower(strings.TrimSpace(args[0])) {
|
switch strings.ToLower(strings.TrimSpace(args[0])) {
|
||||||
case "on":
|
case "on":
|
||||||
_ = os.Remove(pausePath)
|
_ = os.Remove(pausePath)
|
||||||
if err := os.WriteFile(ctrlPath, []byte("{\n \"enabled\": true\n}\n"), 0644); err != nil {
|
if err := writeControl(true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("✓ Autonomy enabled")
|
fmt.Println("✓ Autonomy enabled")
|
||||||
return nil
|
return nil
|
||||||
case "off":
|
case "off":
|
||||||
if err := os.WriteFile(ctrlPath, []byte("{\n \"enabled\": false\n}\n"), 0644); err != nil {
|
if err := writeControl(false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(pausePath, []byte(time.Now().UTC().Format(time.RFC3339)+"\n"), 0644); err != nil {
|
if err := os.WriteFile(pausePath, []byte(time.Now().UTC().Format(time.RFC3339)+"\n"), 0644); err != nil {
|
||||||
@@ -343,10 +358,14 @@ func gatewayAutonomyControlCmd(args []string) error {
|
|||||||
case "status":
|
case "status":
|
||||||
enabled := true
|
enabled := true
|
||||||
reason := "default"
|
reason := "default"
|
||||||
|
updatedAt := ""
|
||||||
|
source := ""
|
||||||
if data, err := os.ReadFile(ctrlPath); err == nil {
|
if data, err := os.ReadFile(ctrlPath); err == nil {
|
||||||
var c struct{ Enabled bool `json:"enabled"` }
|
var c autonomyControl
|
||||||
if json.Unmarshal(data, &c) == nil {
|
if json.Unmarshal(data, &c) == nil {
|
||||||
enabled = c.Enabled
|
enabled = c.Enabled
|
||||||
|
updatedAt = c.UpdatedAt
|
||||||
|
source = c.Source
|
||||||
if !c.Enabled {
|
if !c.Enabled {
|
||||||
reason = "control_file"
|
reason = "control_file"
|
||||||
}
|
}
|
||||||
@@ -357,6 +376,13 @@ func gatewayAutonomyControlCmd(args []string) error {
|
|||||||
reason = "pause_file"
|
reason = "pause_file"
|
||||||
}
|
}
|
||||||
fmt.Printf("Autonomy status: %v (%s)\n", enabled, reason)
|
fmt.Printf("Autonomy status: %v (%s)\n", enabled, reason)
|
||||||
|
if strings.TrimSpace(updatedAt) != "" {
|
||||||
|
fmt.Printf("Last switch: %s", updatedAt)
|
||||||
|
if strings.TrimSpace(source) != "" {
|
||||||
|
fmt.Printf(" via %s", source)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
fmt.Printf("Control file: %s\n", ctrlPath)
|
fmt.Printf("Control file: %s\n", ctrlPath)
|
||||||
fmt.Printf("Pause file: %s\n", pausePath)
|
fmt.Printf("Pause file: %s\n", pausePath)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -191,6 +191,13 @@ func summarizeAutonomyActions(statsJSON []byte) string {
|
|||||||
b := payload.Counts["autonomy:blocked"]
|
b := payload.Counts["autonomy:blocked"]
|
||||||
parts = append(parts, fmt.Sprintf("ratios(dispatch/waiting/blocked)=%.2f/%.2f/%.2f", float64(d)/float64(total), float64(w)/float64(total), float64(b)/float64(total)))
|
parts = append(parts, fmt.Sprintf("ratios(dispatch/waiting/blocked)=%.2f/%.2f/%.2f", float64(d)/float64(total), float64(w)/float64(total), float64(b)/float64(total)))
|
||||||
}
|
}
|
||||||
|
wa := payload.Counts["autonomy:waiting:active_user"]
|
||||||
|
wm := payload.Counts["autonomy:waiting:manual_pause"]
|
||||||
|
ra := payload.Counts["autonomy:resume:active_user"]
|
||||||
|
rm := payload.Counts["autonomy:resume:manual_pause"]
|
||||||
|
if wa+wm+ra+rm > 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("wait_resume(active_user=%d/%d manual_pause=%d/%d)", wa, ra, wm, rm))
|
||||||
|
}
|
||||||
return strings.Join(parts, " ")
|
return strings.Join(parts, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -464,6 +464,12 @@ func (e *Engine) writeTriggerAudit(action string, st *taskState, errText string)
|
|||||||
act := strings.ToLower(strings.TrimSpace(action))
|
act := strings.ToLower(strings.TrimSpace(action))
|
||||||
if act != "" {
|
if act != "" {
|
||||||
stats.Counts["autonomy:"+act]++
|
stats.Counts["autonomy:"+act]++
|
||||||
|
reason := strings.ToLower(strings.TrimSpace(errText))
|
||||||
|
if reason != "" {
|
||||||
|
reason = strings.ReplaceAll(reason, " ", "_")
|
||||||
|
reason = strings.ReplaceAll(reason, ":", "_")
|
||||||
|
stats.Counts["autonomy:"+act+":"+reason]++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stats.UpdatedAt = time.Now().UTC().Format(time.RFC3339)
|
stats.UpdatedAt = time.Now().UTC().Format(time.RFC3339)
|
||||||
if raw, mErr := json.MarshalIndent(stats, "", " "); mErr == nil {
|
if raw, mErr := json.MarshalIndent(stats, "", " "); mErr == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user