TevinClaw
18 hours ago 949bac4c4c9fda71ab129b7fc1067cde28de1463
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
"""
快速写入L0层 (MEMORY.md)
"""
 
import sys
import argparse
from datetime import datetime
from pathlib import Path
 
 
def main():
    parser = argparse.ArgumentParser(description="写入L0层记忆")
    parser.add_argument("content", help="记录内容")
    parser.add_argument("--link", help="关联的L2文件路径")
    parser.add_argument("--type", default="活动", help="记录类型")
    args = parser.parse_args()
    
    workspace = Path.home() / ".openclaw" / "workspace"
    memory_file = workspace / "MEMORY.md"
    
    # 确保文件存在
    if not memory_file.exists():
        print(f"❌ {memory_file} 不存在")
        return 1
    
    today = datetime.now().strftime("%Y-%m-%d")
    
    # 构建记录行
    line = f"- **[{args.type}]** {args.content}"
    if args.link:
        line += f" → 详见 [{args.link}](./{args.link})"
    
    # 读取现有内容
    with open(memory_file, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 在"最近活动"部分添加
    if "### 最近活动" in content:
        parts = content.split("### 最近活动")
        if len(parts) == 2:
            # 在第一行后插入
            lines = parts[1].split('\n')
            insert_idx = 0
            for i, l in enumerate(lines):
                if l.strip() and not l.startswith('#'):
                    insert_idx = i
                    break
            lines.insert(insert_idx, f"- {today}: {args.content}")
            new_content = parts[0] + "### 最近活动" + '\n'.join(lines)
            
            with open(memory_file, 'w', encoding='utf-8') as f:
                f.write(new_content)
            
            print(f"✅ 已写入L0: {args.content}")
            return 0
    
    print("⚠️  未找到'最近活动'区块,请手动添加")
    return 1
 
 
if __name__ == "__main__":
    sys.exit(main())