返回 DeepSeek-Reasonix
main.go
1 package main
2
3 import (
4 "encoding/json"
5 "fmt"
6 "os"
7 "path/filepath"
8 "time"
9
10 "reasonix/internal/config"
11 fileencoding "reasonix/internal/fileutil/encoding"
12 )
13
14 type Task struct {
15 ID string `json:"id"`
16 Title string `json:"title"`
17 Prompt string `json:"prompt"`
18 Interval string `json:"interval"`
19 Enabled bool `json:"enabled"`
20 TopicID string `json:"topicId,omitempty"`
21 LastRunAt int64 `json:"lastRunAt,omitempty"`
22 CreatedAt int64 `json:"createdAt,omitempty"`
23 ApprovalMode string `json:"approvalMode"`
24 TimeWindowStart string `json:"timeWindowStart,omitempty"`
25 TimeWindowEnd string `json:"timeWindowEnd,omitempty"`
26 }
27
28 func main() {
29 base := config.MemoryUserDir()
30 if base == "" {
31 base = "."
32 }
33 path := filepath.Join(base, "heartbeat-tasks.json")
34
35 // Read existing
36 b, _ := fileencoding.ReadFileUTF8(path)
37 var data struct {
38 Tasks []Task `json:"tasks"`
39 }
40 if len(b) > 0 {
41 _ = json.Unmarshal(b, &data)
42 }
43 if data.Tasks == nil {
44 data.Tasks = []Task{}
45 }
46
47 now := time.Now().UnixMilli()
48 data.Tasks = append(data.Tasks, Task{
49 ID: "greeting_hello_001",
50 Title: "打个招呼",
51 Prompt: "你好!请用一段友好的话介绍一下你自己,然后用中文打个招呼。",
52 Interval: "2m",
53 Enabled: true,
54 CreatedAt: now,
55 }, Task{
56 ID: "daily_check_002",
57 Title: "每日检查",
58 Prompt: "检查当前项目的最新改动和状态,总结需要关注的事项。",
59 Interval: "1h",
60 Enabled: true,
61 CreatedAt: now,
62 })
63
64 out, _ := json.MarshalIndent(data, "", " ")
65 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
66 fmt.Println("Mkdir error:", err)
67 os.Exit(1)
68 }
69 if err := os.WriteFile(path, out, 0644); err != nil {
70 fmt.Println("Write error:", err)
71 os.Exit(1)
72 }
73 fmt.Println("Done! Added 2 tasks.")
74 fmt.Println("File:", path)
75 }
76
76 lines GO