mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-06 22:57:30 +08:00
optimize status/config flow for sessions.json and template visibility
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"clawgo/pkg/config"
|
||||||
"clawgo/pkg/providers"
|
"clawgo/pkg/providers"
|
||||||
)
|
)
|
||||||
func statusCmd() {
|
func statusCmd() {
|
||||||
@@ -73,6 +73,7 @@ func statusCmd() {
|
|||||||
cfg.Agents.Defaults.Heartbeat.EverySec,
|
cfg.Agents.Defaults.Heartbeat.EverySec,
|
||||||
cfg.Agents.Defaults.Heartbeat.AckMaxChars,
|
cfg.Agents.Defaults.Heartbeat.AckMaxChars,
|
||||||
)
|
)
|
||||||
|
printTemplateStatus(cfg)
|
||||||
fmt.Printf("Cron Runtime: workers=%d sleep=%d-%ds\n",
|
fmt.Printf("Cron Runtime: workers=%d sleep=%d-%ds\n",
|
||||||
cfg.Cron.MaxWorkers,
|
cfg.Cron.MaxWorkers,
|
||||||
cfg.Cron.MinSleepSec,
|
cfg.Cron.MinSleepSec,
|
||||||
@@ -130,28 +131,43 @@ func statusCmd() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printTemplateStatus(cfg *config.Config) {
|
||||||
|
if cfg == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defaults := config.DefaultConfig().Agents.Defaults.Texts
|
||||||
|
cur := cfg.Agents.Defaults.Texts
|
||||||
|
fmt.Println("Dialog Templates:")
|
||||||
|
printTemplateField("system_rewrite_template", cur.SystemRewriteTemplate, defaults.SystemRewriteTemplate)
|
||||||
|
printTemplateField("lang_usage", cur.LangUsage, defaults.LangUsage)
|
||||||
|
printTemplateField("lang_invalid", cur.LangInvalid, defaults.LangInvalid)
|
||||||
|
printTemplateField("runtime_compaction_note", cur.RuntimeCompactionNote, defaults.RuntimeCompactionNote)
|
||||||
|
printTemplateField("startup_compaction_note", cur.StartupCompactionNote, defaults.StartupCompactionNote)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printTemplateField(name, current, def string) {
|
||||||
|
state := "custom"
|
||||||
|
if strings.TrimSpace(current) == strings.TrimSpace(def) {
|
||||||
|
state = "default"
|
||||||
|
}
|
||||||
|
fmt.Printf(" %s: %s\n", name, state)
|
||||||
|
}
|
||||||
|
|
||||||
func collectSessionKindCounts(sessionsDir string) (map[string]int, error) {
|
func collectSessionKindCounts(sessionsDir string) (map[string]int, error) {
|
||||||
entries, err := os.ReadDir(sessionsDir)
|
indexPath := filepath.Join(sessionsDir, "sessions.json")
|
||||||
|
data, err := os.ReadFile(indexPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var index map[string]struct {
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(data, &index); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
counts := map[string]int{}
|
counts := map[string]int{}
|
||||||
for _, e := range entries {
|
for _, row := range index {
|
||||||
if e.IsDir() || !strings.HasSuffix(e.Name(), ".meta") {
|
kind := strings.TrimSpace(strings.ToLower(row.Kind))
|
||||||
continue
|
|
||||||
}
|
|
||||||
metaPath := filepath.Join(sessionsDir, e.Name())
|
|
||||||
data, err := os.ReadFile(metaPath)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var meta struct {
|
|
||||||
Kind string `json:"kind"`
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &meta); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
kind := strings.TrimSpace(strings.ToLower(meta.Kind))
|
|
||||||
if kind == "" {
|
if kind == "" {
|
||||||
kind = "other"
|
kind = "other"
|
||||||
}
|
}
|
||||||
@@ -226,39 +242,28 @@ func collectTriggerErrorCounts(path string) (map[string]int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func collectRecentSubagentSessions(sessionsDir string, limit int) ([]string, error) {
|
func collectRecentSubagentSessions(sessionsDir string, limit int) ([]string, error) {
|
||||||
entries, err := os.ReadDir(sessionsDir)
|
indexPath := filepath.Join(sessionsDir, "sessions.json")
|
||||||
|
data, err := os.ReadFile(indexPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var index map[string]struct {
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
UpdatedAt int64 `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(data, &index); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
type item struct {
|
type item struct {
|
||||||
key string
|
key string
|
||||||
updated int64
|
updated int64
|
||||||
}
|
}
|
||||||
items := make([]item, 0)
|
items := make([]item, 0)
|
||||||
for _, e := range entries {
|
for key, row := range index {
|
||||||
if e.IsDir() || !strings.HasSuffix(e.Name(), ".meta") {
|
if strings.ToLower(strings.TrimSpace(row.Kind)) != "subagent" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
metaPath := filepath.Join(sessionsDir, e.Name())
|
items = append(items, item{key: key, updated: row.UpdatedAt})
|
||||||
data, err := os.ReadFile(metaPath)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var meta struct {
|
|
||||||
Kind string `json:"kind"`
|
|
||||||
Updated string `json:"updated"`
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &meta); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.ToLower(strings.TrimSpace(meta.Kind)) != "subagent" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t, err := time.Parse(time.RFC3339Nano, meta.Updated)
|
|
||||||
if err != nil {
|
|
||||||
t, _ = time.Parse(time.RFC3339, meta.Updated)
|
|
||||||
}
|
|
||||||
items = append(items, item{key: strings.TrimSuffix(e.Name(), ".meta"), updated: t.UnixMilli()})
|
|
||||||
}
|
}
|
||||||
sort.Slice(items, func(i, j int) bool { return items[i].updated > items[j].updated })
|
sort.Slice(items, func(i, j int) bool { return items[i].updated > items[j].updated })
|
||||||
if limit > 0 && len(items) > limit {
|
if limit > 0 && len(items) > limit {
|
||||||
|
|||||||
Reference in New Issue
Block a user