mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 09:28:14 +00:00
- IO abstraction layer with OutputChannel routing and capability validation - Three-layer memory (Context-Document-Graph) with TF-IDF relevance pruning - OneBot V11 QQ protocol plugin with Reverse WebSocket client - Plugin system with hot-reload (SKILL.md + native factories) - Knowledge system with TF-IDF vector indexing - Personality system (personal.md) - Text memory (JSONL with rotation) - Change tracker (overlayfs) with rollback - Lua adapter VM - Design document (DESIGN.md) Module: gitcode.com/JianFeeeee/HomeAgent
42 lines
798 B
Go
42 lines
798 B
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type Personality struct {
|
|
Content string
|
|
Path string
|
|
}
|
|
|
|
func LoadPersonality(path string) (*Personality, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return &Personality{}, nil
|
|
}
|
|
return nil, fmt.Errorf("read personal.md: %w", err)
|
|
}
|
|
return &Personality{
|
|
Content: string(data),
|
|
Path: path,
|
|
}, nil
|
|
}
|
|
|
|
func SavePersonality(path, content string) error {
|
|
dir := filepath.Dir(path)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return fmt.Errorf("create personality dir: %w", err)
|
|
}
|
|
return os.WriteFile(path, []byte(content), 0644)
|
|
}
|
|
|
|
func (p *Personality) InjectPrompt() string {
|
|
if p.Content == "" {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf("【人格设定】\n%s\n", p.Content)
|
|
}
|