fix: tighten oauth and subagent messaging

This commit is contained in:
lpf
2026-03-13 12:40:32 +08:00
parent 04a3907cff
commit b874c89eaa
5 changed files with 63 additions and 51 deletions

View File

@@ -13,7 +13,7 @@ import (
func TestSummarizePlannedTaskProgressBodyPreservesUsefulLines(t *testing.T) {
t.Parallel()
body := "subagent 已写入 config.json。\npath: /root/.clawgo/config.json\nagent_id: tester\nrole: testing\ndisplay_name: Test Agent\ntool_allowlist: [filesystem shell]\nrouting_keywords: [test qa]\nsystem_prompt_file: agents/tester/AGENT.md"
body := "subagent 已写入 config.json。\npath: /root/.clawgo/config.json\nagent_id: tester"
out := summarizePlannedTaskProgressBody(body, 6, 320)
if !strings.Contains(out, "subagent 已写入 config.json。") {

View File

@@ -88,49 +88,10 @@ func extractSubagentDescription(content string) string {
}
func formatCreatedSubagentForUser(result map[string]interface{}, configPath string) string {
subagent, _ := result["subagent"].(map[string]interface{})
role := ""
displayName := ""
toolAllowlist := interface{}(nil)
systemPromptFile := ""
if subagent != nil {
if v, _ := subagent["role"].(string); v != "" {
role = v
}
if v, _ := subagent["display_name"].(string); v != "" {
displayName = v
}
if tools, ok := subagent["tools"].(map[string]interface{}); ok {
toolAllowlist = tools["allowlist"]
}
if v, _ := subagent["system_prompt_file"].(string); v != "" {
systemPromptFile = v
}
}
routingKeywords := interface{}(nil)
if rules, ok := result["rules"].([]interface{}); ok {
agentID, _ := result["agent_id"].(string)
for _, raw := range rules {
rule, ok := raw.(map[string]interface{})
if !ok {
continue
}
if strings.TrimSpace(fmt.Sprint(rule["agent_id"])) != agentID {
continue
}
routingKeywords = rule["keywords"]
break
}
}
return fmt.Sprintf(
"subagent 已写入 config.json。\npath: %s\nagent_id: %v\nrole: %v\ndisplay_name: %v\ntool_allowlist: %v\nrouting_keywords: %v\nsystem_prompt_file: %v",
"subagent 已写入 config.json。\npath: %s\nagent_id: %v",
configPath,
result["agent_id"],
role,
displayName,
toolAllowlist,
routingKeywords,
systemPromptFile,
)
}

View File

@@ -27,17 +27,24 @@ func TestFormatCreatedSubagentForUserReadsNestedFields(t *testing.T) {
}, "/tmp/config.json")
for _, want := range []string{
"subagent 已写入 config.json。",
"path: /tmp/config.json",
"agent_id: coder",
"role: coding",
"display_name: Code Agent",
"system_prompt_file: agents/coder/AGENT.md",
"routing_keywords: [code fix]",
} {
if !strings.Contains(out, want) {
t.Fatalf("expected output to contain %q, got:\n%s", want, out)
}
}
if strings.Contains(out, "<nil>") {
t.Fatalf("did not expect nil placeholders, got:\n%s", out)
for _, unwanted := range []string{
"role:",
"display_name:",
"tool_allowlist:",
"routing_keywords:",
"system_prompt_file:",
"<nil>",
} {
if strings.Contains(out, unwanted) {
t.Fatalf("did not expect %q in output, got:\n%s", unwanted, out)
}
}
}