sumulige-claude 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,359 +1 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"id": "session-24007-21777",
|
|
4
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
5
|
-
"startedAt": 1768379744003,
|
|
6
|
-
"lastHeartbeat": 1768379744003,
|
|
7
|
-
"heartbeatCount": 1,
|
|
8
|
-
"status": "active"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"id": "session-24243-21777",
|
|
12
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
13
|
-
"startedAt": 1768380026778,
|
|
14
|
-
"lastHeartbeat": 1768380026778,
|
|
15
|
-
"heartbeatCount": 1,
|
|
16
|
-
"status": "active"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"id": "session-24261-21777",
|
|
20
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
21
|
-
"startedAt": 1768380041012,
|
|
22
|
-
"lastHeartbeat": 1768380041012,
|
|
23
|
-
"heartbeatCount": 1,
|
|
24
|
-
"status": "active"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"id": "session-24296-21777",
|
|
28
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
29
|
-
"startedAt": 1768380114984,
|
|
30
|
-
"lastHeartbeat": 1768380114984,
|
|
31
|
-
"heartbeatCount": 1,
|
|
32
|
-
"status": "active"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"id": "session-25203-21777",
|
|
36
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
37
|
-
"startedAt": 1768381841359,
|
|
38
|
-
"lastHeartbeat": 1768381841359,
|
|
39
|
-
"heartbeatCount": 1,
|
|
40
|
-
"status": "active"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"id": "session-25223-21777",
|
|
44
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
45
|
-
"startedAt": 1768381898336,
|
|
46
|
-
"lastHeartbeat": 1768381898336,
|
|
47
|
-
"heartbeatCount": 1,
|
|
48
|
-
"status": "active"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"id": "session-25240-21777",
|
|
52
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
53
|
-
"startedAt": 1768381909390,
|
|
54
|
-
"lastHeartbeat": 1768381909390,
|
|
55
|
-
"heartbeatCount": 1,
|
|
56
|
-
"status": "active"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"id": "session-25263-21777",
|
|
60
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
61
|
-
"startedAt": 1768381940430,
|
|
62
|
-
"lastHeartbeat": 1768381940430,
|
|
63
|
-
"heartbeatCount": 1,
|
|
64
|
-
"status": "active"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"id": "session-25284-21777",
|
|
68
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
69
|
-
"startedAt": 1768381952270,
|
|
70
|
-
"lastHeartbeat": 1768381952270,
|
|
71
|
-
"heartbeatCount": 1,
|
|
72
|
-
"status": "active"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"id": "session-25364-21777",
|
|
76
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
77
|
-
"startedAt": 1768381961451,
|
|
78
|
-
"lastHeartbeat": 1768381961451,
|
|
79
|
-
"heartbeatCount": 1,
|
|
80
|
-
"status": "active"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"id": "session-25391-21777",
|
|
84
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
85
|
-
"startedAt": 1768381967921,
|
|
86
|
-
"lastHeartbeat": 1768381967921,
|
|
87
|
-
"heartbeatCount": 1,
|
|
88
|
-
"status": "active"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"id": "session-25407-21777",
|
|
92
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
93
|
-
"startedAt": 1768381976308,
|
|
94
|
-
"lastHeartbeat": 1768381976308,
|
|
95
|
-
"heartbeatCount": 1,
|
|
96
|
-
"status": "active"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"id": "session-25421-21777",
|
|
100
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
101
|
-
"startedAt": 1768381986295,
|
|
102
|
-
"lastHeartbeat": 1768381986295,
|
|
103
|
-
"heartbeatCount": 1,
|
|
104
|
-
"status": "active"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"id": "session-25434-21777",
|
|
108
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
109
|
-
"startedAt": 1768381991401,
|
|
110
|
-
"lastHeartbeat": 1768381991401,
|
|
111
|
-
"heartbeatCount": 1,
|
|
112
|
-
"status": "active"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
"id": "session-25514-21777",
|
|
116
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
117
|
-
"startedAt": 1768382141338,
|
|
118
|
-
"lastHeartbeat": 1768382141338,
|
|
119
|
-
"heartbeatCount": 1,
|
|
120
|
-
"status": "active"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"id": "session-25564-21777",
|
|
124
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
125
|
-
"startedAt": 1768382147029,
|
|
126
|
-
"lastHeartbeat": 1768382147029,
|
|
127
|
-
"heartbeatCount": 1,
|
|
128
|
-
"status": "active"
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
"id": "session-25590-21777",
|
|
132
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
133
|
-
"startedAt": 1768382194722,
|
|
134
|
-
"lastHeartbeat": 1768382194722,
|
|
135
|
-
"heartbeatCount": 1,
|
|
136
|
-
"status": "active"
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
"id": "session-25605-21777",
|
|
140
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
141
|
-
"startedAt": 1768382200403,
|
|
142
|
-
"lastHeartbeat": 1768382200403,
|
|
143
|
-
"heartbeatCount": 1,
|
|
144
|
-
"status": "active"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"id": "session-25632-21777",
|
|
148
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
149
|
-
"startedAt": 1768382206644,
|
|
150
|
-
"lastHeartbeat": 1768382206644,
|
|
151
|
-
"heartbeatCount": 1,
|
|
152
|
-
"status": "active"
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
"id": "session-25652-21777",
|
|
156
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
157
|
-
"startedAt": 1768382206806,
|
|
158
|
-
"lastHeartbeat": 1768382206806,
|
|
159
|
-
"heartbeatCount": 1,
|
|
160
|
-
"status": "active"
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"id": "session-25796-21777",
|
|
164
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
165
|
-
"startedAt": 1768382343851,
|
|
166
|
-
"lastHeartbeat": 1768382343851,
|
|
167
|
-
"heartbeatCount": 1,
|
|
168
|
-
"status": "active"
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
"id": "session-25814-21777",
|
|
172
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
173
|
-
"startedAt": 1768382362496,
|
|
174
|
-
"lastHeartbeat": 1768382362496,
|
|
175
|
-
"heartbeatCount": 1,
|
|
176
|
-
"status": "active"
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
"id": "session-25996-21777",
|
|
180
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
181
|
-
"startedAt": 1768382669972,
|
|
182
|
-
"lastHeartbeat": 1768382669972,
|
|
183
|
-
"heartbeatCount": 1,
|
|
184
|
-
"status": "active"
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
"id": "session-26003-21777",
|
|
188
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
189
|
-
"startedAt": 1768382669992,
|
|
190
|
-
"lastHeartbeat": 1768382669992,
|
|
191
|
-
"heartbeatCount": 1,
|
|
192
|
-
"status": "active"
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"id": "session-26010-21777",
|
|
196
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
197
|
-
"startedAt": 1768382669998,
|
|
198
|
-
"lastHeartbeat": 1768382669998,
|
|
199
|
-
"heartbeatCount": 1,
|
|
200
|
-
"status": "active"
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
"id": "session-26110-21777",
|
|
204
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
205
|
-
"startedAt": 1768382728623,
|
|
206
|
-
"lastHeartbeat": 1768382728623,
|
|
207
|
-
"heartbeatCount": 1,
|
|
208
|
-
"status": "active"
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
"id": "session-26126-21777",
|
|
212
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
213
|
-
"startedAt": 1768382733375,
|
|
214
|
-
"lastHeartbeat": 1768382733375,
|
|
215
|
-
"heartbeatCount": 1,
|
|
216
|
-
"status": "active"
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
"id": "session-26140-21777",
|
|
220
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
221
|
-
"startedAt": 1768382749918,
|
|
222
|
-
"lastHeartbeat": 1768382749918,
|
|
223
|
-
"heartbeatCount": 1,
|
|
224
|
-
"status": "active"
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
"id": "session-26155-21777",
|
|
228
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
229
|
-
"startedAt": 1768382752479,
|
|
230
|
-
"lastHeartbeat": 1768382752479,
|
|
231
|
-
"heartbeatCount": 1,
|
|
232
|
-
"status": "active"
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
"id": "session-26181-21777",
|
|
236
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
237
|
-
"startedAt": 1768382792393,
|
|
238
|
-
"lastHeartbeat": 1768382792393,
|
|
239
|
-
"heartbeatCount": 1,
|
|
240
|
-
"status": "active"
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
"id": "session-26206-21777",
|
|
244
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
245
|
-
"startedAt": 1768382840410,
|
|
246
|
-
"lastHeartbeat": 1768382840410,
|
|
247
|
-
"heartbeatCount": 1,
|
|
248
|
-
"status": "active"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
"id": "session-26220-21777",
|
|
252
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
253
|
-
"startedAt": 1768382843372,
|
|
254
|
-
"lastHeartbeat": 1768382843372,
|
|
255
|
-
"heartbeatCount": 1,
|
|
256
|
-
"status": "active"
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
"id": "session-26313-21777",
|
|
260
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
261
|
-
"startedAt": 1768382884460,
|
|
262
|
-
"lastHeartbeat": 1768382884460,
|
|
263
|
-
"heartbeatCount": 1,
|
|
264
|
-
"status": "active"
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
"id": "session-26327-21777",
|
|
268
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
269
|
-
"startedAt": 1768382893665,
|
|
270
|
-
"lastHeartbeat": 1768382893665,
|
|
271
|
-
"heartbeatCount": 1,
|
|
272
|
-
"status": "active"
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
"id": "session-26340-21777",
|
|
276
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
277
|
-
"startedAt": 1768382896611,
|
|
278
|
-
"lastHeartbeat": 1768382896611,
|
|
279
|
-
"heartbeatCount": 1,
|
|
280
|
-
"status": "active"
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
"id": "session-26349-21777",
|
|
284
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
285
|
-
"startedAt": 1768382899845,
|
|
286
|
-
"lastHeartbeat": 1768382899845,
|
|
287
|
-
"heartbeatCount": 1,
|
|
288
|
-
"status": "active"
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
"id": "session-26373-21777",
|
|
292
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
293
|
-
"startedAt": 1768382925824,
|
|
294
|
-
"lastHeartbeat": 1768382925824,
|
|
295
|
-
"heartbeatCount": 1,
|
|
296
|
-
"status": "active"
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
"id": "session-26390-21777",
|
|
300
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
301
|
-
"startedAt": 1768382946454,
|
|
302
|
-
"lastHeartbeat": 1768382946454,
|
|
303
|
-
"heartbeatCount": 1,
|
|
304
|
-
"status": "active"
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
"id": "session-26417-21777",
|
|
308
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
309
|
-
"startedAt": 1768382960687,
|
|
310
|
-
"lastHeartbeat": 1768382960687,
|
|
311
|
-
"heartbeatCount": 1,
|
|
312
|
-
"status": "active"
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
"id": "session-26737-21777",
|
|
316
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
317
|
-
"startedAt": 1768383271371,
|
|
318
|
-
"lastHeartbeat": 1768383271371,
|
|
319
|
-
"heartbeatCount": 1,
|
|
320
|
-
"status": "active",
|
|
321
|
-
"number": 1
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
"id": "session-26751-21777",
|
|
325
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
326
|
-
"startedAt": 1768383271413,
|
|
327
|
-
"lastHeartbeat": 1768383271413,
|
|
328
|
-
"heartbeatCount": 1,
|
|
329
|
-
"status": "active",
|
|
330
|
-
"number": 2
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
"id": "session-26758-21777",
|
|
334
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
335
|
-
"startedAt": 1768383271424,
|
|
336
|
-
"lastHeartbeat": 1768383271424,
|
|
337
|
-
"heartbeatCount": 1,
|
|
338
|
-
"status": "active",
|
|
339
|
-
"number": 3
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
"id": "session-26744-21777",
|
|
343
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
344
|
-
"startedAt": 1768383271437,
|
|
345
|
-
"lastHeartbeat": 1768383271437,
|
|
346
|
-
"heartbeatCount": 1,
|
|
347
|
-
"status": "active",
|
|
348
|
-
"number": 4
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
"id": "session-26781-21777",
|
|
352
|
-
"identifier": "sumulige@M3 (darwin)",
|
|
353
|
-
"startedAt": 1768383304643,
|
|
354
|
-
"lastHeartbeat": 1768383304643,
|
|
355
|
-
"heartbeatCount": 1,
|
|
356
|
-
"status": "active",
|
|
357
|
-
"number": 5
|
|
358
|
-
}
|
|
359
|
-
]
|
|
1
|
+
[]
|
|
@@ -47,7 +47,23 @@
|
|
|
47
47
|
"Bash(gh repo view:*)",
|
|
48
48
|
"Bash(npm config get:*)",
|
|
49
49
|
"Bash(npm version:*)",
|
|
50
|
-
"Bash(git restore:*)"
|
|
50
|
+
"Bash(git restore:*)",
|
|
51
|
+
"Bash(smc sync:*)",
|
|
52
|
+
"Bash(smc:*)",
|
|
53
|
+
"Bash(docker-compose up:*)",
|
|
54
|
+
"Bash(curl:*)",
|
|
55
|
+
"Bash(lsof:*)",
|
|
56
|
+
"Bash(ls:*)",
|
|
57
|
+
"Bash(docker exec:*)",
|
|
58
|
+
"Bash(docker ps:*)",
|
|
59
|
+
"Bash(docker logs:*)",
|
|
60
|
+
"Bash(docker restart:*)",
|
|
61
|
+
"WebSearch",
|
|
62
|
+
"Bash(npm run build:*)",
|
|
63
|
+
"Bash(npx tsc:*)",
|
|
64
|
+
"Bash(npm ls:*)",
|
|
65
|
+
"Bash(npm run dev)",
|
|
66
|
+
"Bash(kill:*)"
|
|
51
67
|
]
|
|
52
68
|
},
|
|
53
69
|
"hooks": {
|
package/package.json
CHANGED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Conversation Logger - 增强版对话记录器
|
|
4
|
+
*
|
|
5
|
+
* 自动记录每次对话到 DAILY_CONVERSATION.md
|
|
6
|
+
* 按日期分组,无需手动触发
|
|
7
|
+
*
|
|
8
|
+
* 功能:
|
|
9
|
+
* - 捕获用户输入和 AI 输出
|
|
10
|
+
* - 记录工具使用
|
|
11
|
+
* - 按日期自动分组
|
|
12
|
+
* - 实时追加到日志
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const PROJECT_DIR = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
19
|
+
const CONVERSATION_LOG = path.join(PROJECT_DIR, '.claude', 'DAILY_CONVERSATION.md');
|
|
20
|
+
const THINKING_DIR = path.join(PROJECT_DIR, '.claude', 'thinking-routes');
|
|
21
|
+
const FLOW_FILE = path.join(THINKING_DIR, '.conversation-flow.json');
|
|
22
|
+
|
|
23
|
+
// 确保目录存在
|
|
24
|
+
try { fs.mkdirSync(THINKING_DIR, { recursive: true }); } catch (e) {}
|
|
25
|
+
|
|
26
|
+
// 获取当前日期字符串 (YYYY-MM-DD)
|
|
27
|
+
function getDateStr() {
|
|
28
|
+
const now = new Date();
|
|
29
|
+
const year = now.getFullYear();
|
|
30
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
31
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
32
|
+
return `${year}-${month}-${day}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 获取当前时间字符串 (HH:MM)
|
|
36
|
+
function getTimeStr() {
|
|
37
|
+
const now = new Date();
|
|
38
|
+
const hours = String(now.getHours()).padStart(2, '0');
|
|
39
|
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
40
|
+
return `${hours}:${minutes}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 转义 Markdown 特殊字符
|
|
44
|
+
function escapeMarkdown(text) {
|
|
45
|
+
if (!text) return '';
|
|
46
|
+
return text
|
|
47
|
+
.replace(/\|/g, '\\|')
|
|
48
|
+
.replace(/\n/g, ' ')
|
|
49
|
+
.slice(0, 500); // 限制长度
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 初始化日志文件
|
|
53
|
+
function initLogFile() {
|
|
54
|
+
if (!fs.existsSync(CONVERSATION_LOG)) {
|
|
55
|
+
const header = `# 每日对话记录
|
|
56
|
+
|
|
57
|
+
> 此文件由 conversation-logger.cjs 自动生成
|
|
58
|
+
> 记录与 AI 的每次对话
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
`;
|
|
62
|
+
fs.writeFileSync(CONVERSATION_LOG, header, 'utf-8');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 追加对话到日志
|
|
67
|
+
function appendConversation(role, content, toolInfo = '') {
|
|
68
|
+
initLogFile();
|
|
69
|
+
|
|
70
|
+
const dateStr = getDateStr();
|
|
71
|
+
const timeStr = getTimeStr();
|
|
72
|
+
const roleLabel = role === 'user' ? '👤 用户' : role === 'assistant' ? '🤖 AI' : '🔧 工具';
|
|
73
|
+
const safeContent = escapeMarkdown(content);
|
|
74
|
+
|
|
75
|
+
const entry = `### ${timeStr} - ${roleLabel}
|
|
76
|
+
${safeContent}${toolInfo ? `\n> ${toolInfo}` : ''}
|
|
77
|
+
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
// 读取现有内容
|
|
81
|
+
let logContent = fs.readFileSync(CONVERSATION_LOG, 'utf-8');
|
|
82
|
+
|
|
83
|
+
// 检查今天是否已有日期头
|
|
84
|
+
const todayHeader = `## ${dateStr}`;
|
|
85
|
+
const todayIndex = logContent.indexOf(todayHeader);
|
|
86
|
+
|
|
87
|
+
if (todayIndex === -1) {
|
|
88
|
+
// 今天还没有记录,添加新的日期头
|
|
89
|
+
const todaySection = `
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## ${dateStr}
|
|
93
|
+
|
|
94
|
+
${entry}
|
|
95
|
+
`;
|
|
96
|
+
logContent += todaySection;
|
|
97
|
+
} else {
|
|
98
|
+
// 找到今天的记录位置,在末尾追加
|
|
99
|
+
// 使用正则确保只匹配 ## 开头的日期行,而不是 ### 开头的条目
|
|
100
|
+
const afterToday = logContent.slice(todayIndex + todayHeader.length);
|
|
101
|
+
const dateMatch = afterToday.match(/^## \d{4}-\d{2}-\d{2}/m);
|
|
102
|
+
const nextDateIndex = dateMatch ? todayIndex + todayHeader.length + dateMatch.index : -1;
|
|
103
|
+
|
|
104
|
+
if (nextDateIndex === -1) {
|
|
105
|
+
// 今天是最后一天,直接追加到文件末尾
|
|
106
|
+
logContent += entry;
|
|
107
|
+
} else {
|
|
108
|
+
// 在下一天之前插入
|
|
109
|
+
logContent = logContent.slice(0, nextDateIndex) + entry + logContent.slice(nextDateIndex);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 写回文件
|
|
114
|
+
fs.writeFileSync(CONVERSATION_LOG, logContent, 'utf-8');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 从思维轨迹读取并记录完整对话
|
|
118
|
+
function syncFromFlowFile() {
|
|
119
|
+
if (!fs.existsSync(FLOW_FILE)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const flow = JSON.parse(fs.readFileSync(FLOW_FILE, 'utf-8'));
|
|
125
|
+
const turns = flow.turns || [];
|
|
126
|
+
|
|
127
|
+
if (turns.length === 0) return;
|
|
128
|
+
|
|
129
|
+
// 读取现有日志,记录已处理的 turn
|
|
130
|
+
const logContent = fs.existsSync(CONVERSATION_LOG)
|
|
131
|
+
? fs.readFileSync(CONVERSATION_LOG, 'utf-8')
|
|
132
|
+
: '';
|
|
133
|
+
initLogFile();
|
|
134
|
+
|
|
135
|
+
// 简单的追踪:只记录最新的几次交互
|
|
136
|
+
const recentTurns = turns.slice(-5);
|
|
137
|
+
|
|
138
|
+
recentTurns.forEach(turn => {
|
|
139
|
+
const time = turn.time ? new Date(turn.time).toISOString() : '';
|
|
140
|
+
const toolName = turn.toolName || '';
|
|
141
|
+
const type = turn.type || '';
|
|
142
|
+
|
|
143
|
+
// 根据 turn 类型记录
|
|
144
|
+
if (type === 'potential-action' && toolName) {
|
|
145
|
+
appendConversation('tool', `[${toolName}]`, turn.description || '');
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
} catch (e) {
|
|
149
|
+
// 静默处理错误
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 主函数
|
|
154
|
+
function main() {
|
|
155
|
+
try {
|
|
156
|
+
const eventType = process.env.CLAUDE_EVENT_TYPE || '';
|
|
157
|
+
const toolName = process.env.CLAUDE_TOOL_NAME || '';
|
|
158
|
+
const toolInput = process.env.CLAUDE_TOOL_INPUT || '';
|
|
159
|
+
const textOutput = process.env.CLAUDE_TEXT_OUTPUT || '';
|
|
160
|
+
|
|
161
|
+
// 根据事件类型记录
|
|
162
|
+
switch (eventType) {
|
|
163
|
+
case 'UserPromptSubmit':
|
|
164
|
+
// 用户提交输入
|
|
165
|
+
if (toolInput) {
|
|
166
|
+
appendConversation('user', toolInput);
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
|
|
170
|
+
case 'TextOutput':
|
|
171
|
+
// AI 输出文本
|
|
172
|
+
if (textOutput) {
|
|
173
|
+
appendConversation('assistant', textOutput);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case 'PostToolUse':
|
|
178
|
+
// 工具使用后
|
|
179
|
+
if (toolName) {
|
|
180
|
+
appendConversation('tool', toolInput, `使用工具: ${toolName}`);
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
|
|
184
|
+
case 'AgentStop':
|
|
185
|
+
// 会话结束,同步思维轨迹
|
|
186
|
+
syncFromFlowFile();
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
} catch (e) {
|
|
191
|
+
// 静默处理错误,不干扰正常对话
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
process.exit(0);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 如果直接运行,执行同步
|
|
198
|
+
if (require.main === module) {
|
|
199
|
+
if (process.argv.includes('--sync')) {
|
|
200
|
+
syncFromFlowFile();
|
|
201
|
+
console.log('✅ 已同步对话记录');
|
|
202
|
+
} else if (process.argv.includes('--view')) {
|
|
203
|
+
// 查看今日对话
|
|
204
|
+
if (fs.existsSync(CONVERSATION_LOG)) {
|
|
205
|
+
const content = fs.readFileSync(CONVERSATION_LOG, 'utf-8');
|
|
206
|
+
const today = getDateStr();
|
|
207
|
+
const start = content.indexOf(`## ${today}`);
|
|
208
|
+
if (start !== -1) {
|
|
209
|
+
const end = content.indexOf('## ', start + 10);
|
|
210
|
+
console.log(content.slice(start, end === -1 ? undefined : end));
|
|
211
|
+
} else {
|
|
212
|
+
console.log('📭 今天暂无对话记录');
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
console.log('📭 暂无对话记录');
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
main();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
module.exports = { main, syncFromFlowFile, appendConversation };
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"type": "command",
|
|
39
39
|
"command": "node \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/todo-manager.cjs",
|
|
40
40
|
"timeout": 1000
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"type": "command",
|
|
44
|
+
"command": "node \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/conversation-logger.cjs",
|
|
45
|
+
"timeout": 1000
|
|
41
46
|
}
|
|
42
47
|
]
|
|
43
48
|
}
|