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
#!/usr/bin/env python3
"""
创建/追加L2层 (journal/)
"""
 
import sys
import argparse
from datetime import datetime
from pathlib import Path
 
 
def main():
    parser = argparse.ArgumentParser(description="写入L2层记忆")
    parser.add_argument("--date", default=datetime.now().strftime("%Y-%m-%d"), help="日期 (YYYY-MM-DD)")
    parser.add_argument("--title", required=True, help="事件标题")
    parser.add_argument("--content", help="内容(或从stdin读取)")
    parser.add_argument("--file", help="从文件读取内容")
    args = parser.parse_args()
    
    workspace = Path.home() / ".openclaw" / "workspace"
    journal_dir = workspace / "memory" / "journal"
    journal_dir.mkdir(parents=True, exist_ok=True)
    
    journal_file = journal_dir / f"{args.date}.md"
    
    # 获取内容
    content = ""
    if args.file:
        with open(args.file, 'r', encoding='utf-8') as f:
            content = f.read()
    elif args.content:
        content = args.content
    elif not sys.stdin.isatty():
        content = sys.stdin.read()
    
    now = datetime.now().strftime("%H:%M")
    
    # 构建记录
    entry = f"\n## [{now}] {args.title}\n\n{content}\n"
    
    # 写入文件
    if journal_file.exists():
        with open(journal_file, 'a', encoding='utf-8') as f:
            f.write(entry)
        print(f"✅ 已追加到 {journal_file}")
    else:
        header = f"# {args.date}\n"
        with open(journal_file, 'w', encoding='utf-8') as f:
            f.write(header + entry)
        print(f"✅ 已创建 {journal_file}")
    
    return 0
 
 
if __name__ == "__main__":
    sys.exit(main())