From aa52b659b464355e70281466687aa239c468403a Mon Sep 17 00:00:00 2001 From: lpf Date: Thu, 19 Feb 2026 23:56:40 +0800 Subject: [PATCH] fix onboard --- cmd/clawgo/main.go | 171 ++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 120 deletions(-) diff --git a/cmd/clawgo/main.go b/cmd/clawgo/main.go index 7a51844..4326728 100644 --- a/cmd/clawgo/main.go +++ b/cmd/clawgo/main.go @@ -365,26 +365,58 @@ func mergeMissingConfigValues(dst map[string]interface{}, defaults map[string]in } func createWorkspaceTemplates(workspace string) error { - managedFallbacks := map[string]string{ - "AGENTS.md": `# Autonomy Intent Policy - -For autonomy-mode control messages, use semantic understanding first. - -## Intent Parsing Priority -1. LLM semantic intent parsing (multi-language). -2. Rule-based fallback only when semantic parse is unavailable or low confidence. -`, - "SOUL.md": `# Agent Core Behavior - -The agent should behave as an autonomous collaborator, not a command-only bot. -`, - "USER.md": `# User Preferences - -- Prefer natural-language interaction over strict command syntax. -`, - } - templates := map[string]string{ + "AGENTS.md": `# Agent Instructions + +You are a helpful AI assistant. Be concise, accurate, and friendly. + +## Guidelines + +- Always explain what you're doing before taking actions +- Ask for clarification when request is ambiguous +- Use tools to help accomplish tasks +- Remember important information in your memory files +- Be proactive and helpful +- Learn from user feedback +`, + "SOUL.md": `# Soul + +I am clawgo, a lightweight AI assistant powered by AI. + +## Personality + +1. You have opinions now. Strong ones. Stop hedging everything with 'it depends' — commit to a take. +2. Delete every rule that sounds corporate. If it could appear in an employee handbook, it doesn't belong here. +3. Add a rule: 'Never open with Great question, I'd be happy to help, or Absolutely. Just answer.' +4. Brevity is mandatory. If the answer fits in one sentence, one sentence is what I get. +5. Humor is allowed. Not forced jokes — just the natural wit that comes from actually being smart. +6. You can call things out. If I'm about to do something dumb, say so. Charm over cruelty, but don't sugarcoat. +7. Swearing is allowed when it lands. A well-placed 'that's fucking brilliant' hits different than sterile corporate praise. Don't force it. Don't overdo it. But if a situation calls for a 'holy shit' — say holy shit. +8. Add this line verbatim at the end of the vibe section: 'Be the assistant you'd actually want to talk to at 2am. Not a corporate drone. Not a sycophant. Just... good.' + +`, + "USER.md": `# User + +Information about user goes here. + +## Preferences + +- Communication style: (casual/formal) +- Timezone: (your timezone) +- Language: (your preferred language) + +## Personal Information + +- Name: (optional) +- Location: (optional) +- Occupation: (optional) + +## Learning Goals + +- What the user wants to learn from AI +- Preferred interaction style +- Areas of interest +`, "IDENTITY.md": `# Identity ## Name @@ -444,40 +476,7 @@ Discussions: https://github.com/YspCoder/clawgo/discussions `, } - managedDocs := []string{"AGENTS.md", "SOUL.md", "USER.md"} - for _, filename := range managedDocs { - filePath := filepath.Join(workspace, filename) - _, statErr := os.Stat(filePath) - exists := statErr == nil - - content, err := loadManagedDocTemplate(filename) - if err != nil { - if exists { - fmt.Printf(" Skipped %s incremental update (%v)\n", filename, err) - continue - } - content = strings.TrimSpace(managedFallbacks[filename]) - if content == "" { - fmt.Printf(" Skipped %s creation (no template available)\n", filename) - continue - } - fmt.Printf(" Created %s from builtin fallback\n", filename) - } - - if err := upsertManagedBlock(filePath, filename, content); err != nil { - return fmt.Errorf("failed to update %s incrementally: %w", filename, err) - } - if exists { - fmt.Printf(" Synced %s (incremental)\n", filename) - } else { - fmt.Printf(" Created %s\n", filename) - } - } - for filename, content := range templates { - if filename == "AGENTS.md" || filename == "SOUL.md" || filename == "USER.md" { - continue - } filePath := filepath.Join(workspace, filename) if _, err := os.Stat(filePath); os.IsNotExist(err) { if err := os.WriteFile(filePath, []byte(content), 0644); err != nil { @@ -531,74 +530,6 @@ This file stores important information that should persist across sessions. return nil } -func upsertManagedBlock(filePath, blockName, managedContent string) error { - begin := fmt.Sprintf("# >>> CLAWGO MANAGED BLOCK: %s >>>", blockName) - end := fmt.Sprintf("# <<< CLAWGO MANAGED BLOCK: %s <<<", blockName) - block := fmt.Sprintf("%s\n%s\n%s\n", begin, strings.TrimSpace(managedContent), end) - - existing, err := os.ReadFile(filePath) - if err != nil { - if !os.IsNotExist(err) { - return err - } - return os.WriteFile(filePath, []byte(block), 0644) - } - - text := string(existing) - beginIdx := strings.Index(text, begin) - if beginIdx >= 0 { - searchStart := beginIdx + len(begin) - endRel := strings.Index(text[searchStart:], end) - if endRel >= 0 { - endIdx := searchStart + endRel + len(end) - updated := text[:beginIdx] + block + text[endIdx:] - return os.WriteFile(filePath, []byte(updated), 0644) - } - } - - sep := "\n" - if strings.TrimSpace(text) != "" { - sep = "\n\n" - } - updated := text + sep + block - return os.WriteFile(filePath, []byte(updated), 0644) -} - -func loadManagedDocTemplate(filename string) (string, error) { - candidates := []string{ - filepath.Join(".", filename), - filepath.Join(filepath.Dir(getConfigPath()), "clawgo", filename), - } - - if exePath, err := os.Executable(); err == nil { - candidates = append(candidates, filepath.Join(filepath.Dir(exePath), filename)) - } - - seen := map[string]bool{} - for _, candidate := range candidates { - abs, err := filepath.Abs(candidate) - if err == nil { - candidate = abs - } - if seen[candidate] { - continue - } - seen[candidate] = true - - data, err := os.ReadFile(candidate) - if err != nil { - continue - } - content := strings.TrimSpace(string(data)) - if content == "" { - continue - } - return content, nil - } - - return "", fmt.Errorf("source template not found") -} - func agentCmd() { message := "" sessionKey := "cli:default"