From bc354b355a206ca24133d0dc2b6cdc74295ef8d3 Mon Sep 17 00:00:00 2001 From: DBT Date: Mon, 23 Feb 2026 16:49:22 +0000 Subject: [PATCH] optimize config validation and document new text template settings --- README.md | 11 ++++++++++- README_EN.md | 11 ++++++++++- pkg/config/validate.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8428ba2..889acc8 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,16 @@ clawgo channel test --channel telegram --to -m "ping" "texts": { "no_response_fallback": "I've completed processing but have no response to give.", "think_only_fallback": "Thinking process completed.", - "memory_recall_keywords": ["remember", "记得", "上次", "之前", "偏好", "preference", "todo", "待办", "决定", "decision"] + "memory_recall_keywords": ["remember", "记得", "上次", "之前", "偏好", "preference", "todo", "待办", "决定", "decision"], + "lang_usage": "Usage: /lang ", + "lang_invalid": "Invalid language code.", + "lang_updated_template": "Language preference updated to %s", + "subagents_none": "No subagents.", + "sessions_none": "No sessions.", + "unsupported_action": "unsupported action", + "system_rewrite_template": "Rewrite the following internal system update in concise user-facing language:\n\n%s", + "runtime_compaction_note": "[runtime-compaction] removed %d old messages, kept %d recent messages", + "startup_compaction_note": "[startup-compaction] removed %d old messages, kept %d recent messages" }, "context_compaction": { "enabled": true, diff --git a/README_EN.md b/README_EN.md index d413f9e..b5b7e9e 100644 --- a/README_EN.md +++ b/README_EN.md @@ -156,7 +156,16 @@ Heartbeat + context compaction config example: "texts": { "no_response_fallback": "I've completed processing but have no response to give.", "think_only_fallback": "Thinking process completed.", - "memory_recall_keywords": ["remember", "记得", "上次", "之前", "偏好", "preference", "todo", "待办", "决定", "decision"] + "memory_recall_keywords": ["remember", "记得", "上次", "之前", "偏好", "preference", "todo", "待办", "决定", "decision"], + "lang_usage": "Usage: /lang ", + "lang_invalid": "Invalid language code.", + "lang_updated_template": "Language preference updated to %s", + "subagents_none": "No subagents.", + "sessions_none": "No sessions.", + "unsupported_action": "unsupported action", + "system_rewrite_template": "Rewrite the following internal system update in concise user-facing language:\n\n%s", + "runtime_compaction_note": "[runtime-compaction] removed %d old messages, kept %d recent messages", + "startup_compaction_note": "[startup-compaction] removed %d old messages, kept %d recent messages" }, "context_compaction": { "enabled": true, diff --git a/pkg/config/validate.go b/pkg/config/validate.go index 2dd9499..2590863 100644 --- a/pkg/config/validate.go +++ b/pkg/config/validate.go @@ -73,6 +73,39 @@ func Validate(cfg *Config) []error { if strings.TrimSpace(rc.SystemSummary.OutcomesTitle) == "" { errs = append(errs, fmt.Errorf("agents.defaults.runtime_control.system_summary.outcomes_title must be non-empty")) } + hb := cfg.Agents.Defaults.Heartbeat + if hb.Enabled { + if hb.EverySec <= 0 { + errs = append(errs, fmt.Errorf("agents.defaults.heartbeat.every_sec must be > 0 when enabled=true")) + } + if hb.AckMaxChars <= 0 { + errs = append(errs, fmt.Errorf("agents.defaults.heartbeat.ack_max_chars must be > 0 when enabled=true")) + } + } + texts := cfg.Agents.Defaults.Texts + if strings.TrimSpace(texts.NoResponseFallback) == "" { + errs = append(errs, fmt.Errorf("agents.defaults.texts.no_response_fallback must be non-empty")) + } + if strings.TrimSpace(texts.ThinkOnlyFallback) == "" { + errs = append(errs, fmt.Errorf("agents.defaults.texts.think_only_fallback must be non-empty")) + } + if len(texts.MemoryRecallKeywords) == 0 { + errs = append(errs, fmt.Errorf("agents.defaults.texts.memory_recall_keywords must contain at least one keyword")) + } + if strings.TrimSpace(texts.LangUpdatedTemplate) != "" && !strings.Contains(texts.LangUpdatedTemplate, "%s") { + errs = append(errs, fmt.Errorf("agents.defaults.texts.lang_updated_template must contain %%s placeholder")) + } + if strings.TrimSpace(texts.RuntimeCompactionNote) != "" { + if strings.Count(texts.RuntimeCompactionNote, "%d") < 2 { + errs = append(errs, fmt.Errorf("agents.defaults.texts.runtime_compaction_note must contain two %%d placeholders")) + } + } + if strings.TrimSpace(texts.StartupCompactionNote) != "" { + if strings.Count(texts.StartupCompactionNote, "%d") < 2 { + errs = append(errs, fmt.Errorf("agents.defaults.texts.startup_compaction_note must contain two %%d placeholders")) + } + } + if cfg.Agents.Defaults.ContextCompaction.Enabled { cc := cfg.Agents.Defaults.ContextCompaction if cc.Mode != "" {