leerness 1.12.1 → 1.14.0
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.
- package/CHANGELOG.md +119 -0
- package/README.md +23 -5
- package/bin/leerness.js +86 -20
- package/lib/analyzers.js +90 -90
- package/lib/catalogs.js +11 -10
- package/lib/diagnostics.js +194 -193
- package/lib/pure-utils.js +7 -4
- package/lib/session-close.js +620 -616
- package/package.json +1 -1
package/lib/session-close.js
CHANGED
|
@@ -1,616 +1,620 @@
|
|
|
1
|
-
// lib/session-close.js — session close 핸들러 (UR-0025/UR-0125 큰 핸들러 모듈화 10번째, 1.9.425)
|
|
2
|
-
// bin/leerness.js 에서 sessionClose(599줄) 분리. DI: harness 고유 의존 다수 주입.
|
|
3
|
-
// io 프리미티브는 ./io, _sanitizeFences/_parseArchiveBlocks 는 ./pure-utils, cp/os/path/fs 빌트인.
|
|
4
|
-
// __filename→harnessPath(self-spawn). 동작/출력 무변경(9 카테고리 + 활성 룰 검증 + retro 등).
|
|
5
|
-
'use strict';
|
|
6
|
-
const cp = require('child_process');
|
|
7
|
-
const os = require('os');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const { log, ok, warn, fail, failJson, today, now, absRoot, exists, read, readBuf, mkdirp, writeUtf8, append, rel } = require('./io');
|
|
11
|
-
const { _sanitizeFences, _parseArchiveBlocks } = require('./pure-utils');
|
|
12
|
-
|
|
13
|
-
function sessionClose(root, opts = {}, deps = {}) {
|
|
14
|
-
const { VERSION, STATUSES, MARK, has, arg, harnessPath, readProgressRows, evidencePath, handoffPath, currentStatePath, taskLogPath, verifyRules, _autoRoadmap, _readUsageStats, readSessionCounter, writeSessionCounter, _retroAggregate, _retroOneLine, retroCmd, _loadDecisions, readRules, planPath, _loadLessons, _readFeatureGraph, _auditUserRequests, _detectDeliveredRequests, _computeRoundHistory, _computeMilestones, _computeRecentChanges, _collectPyFiles, _analyzePyFile, _collectRuntimeEnv, _scanShellScriptsEncoding, _listAPISkills, _matchAPISkills, _loadShellFailures, _shellEnvDrift, _runPreWakeAudit, _saveAndAppendPreWakeReport, _runIdempotencyAudit, _detectAbnormalShutdown, _updateUserRequest } = deps;
|
|
15
|
-
root = absRoot(root);
|
|
16
|
-
// 1.10.4 (13th 버그헌트 P2, UR-0167): 경로 없음/디렉토리 아님 → 구조화 에러 + exit 1. mkdir <path>/.harness ENOTDIR 크래시 & 실패를 성공(exit 0)으로 오판하던 문제 차단.
|
|
17
|
-
if (!exists(root) || !fs.statSync(root).isDirectory()) { failJson(!!opts.json || has('--json'), 'path_not_found', `경로 없음 또는 디렉토리 아님: ${root}`); return; }
|
|
18
|
-
// 1.9.103: --json 모드 — stdout 억제 후 구조화 출력
|
|
19
|
-
const jsonMode = !!opts.json || has('--json');
|
|
20
|
-
const _origWrite = process.stdout.write.bind(process.stdout);
|
|
21
|
-
if (jsonMode) process.stdout.write = () => true;
|
|
22
|
-
const jsonResult = { version: VERSION, root, closedAt: now() };
|
|
23
|
-
try {
|
|
24
|
-
const rows = readProgressRows(root);
|
|
25
|
-
const buckets = {};
|
|
26
|
-
for (const s of STATUSES) buckets[s] = [];
|
|
27
|
-
for (const r of rows) (buckets[r.status] || (buckets[r.status] = [])).push(r);
|
|
28
|
-
// 1.9.103: JSON 결과 누적
|
|
29
|
-
jsonResult.taskCounts = {};
|
|
30
|
-
for (const s of STATUSES) jsonResult.taskCounts[s] = (buckets[s] || []).length;
|
|
31
|
-
jsonResult.recommendedDirection = (buckets['in-progress'][0]?.request) || (buckets['planned'][0]?.request) || (buckets['requested'][0]?.request) || null;
|
|
32
|
-
jsonResult.nextExactStep = (buckets['in-progress'][0]?.nextAction) || (buckets['planned'][0]?.nextAction) || (buckets['requested'][0]?.nextAction) || null;
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
cs =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
} catch {}
|
|
353
|
-
// 1.9.
|
|
354
|
-
try {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
} else {
|
|
489
|
-
log(
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
log(
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
log(
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
const
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
const
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
1
|
+
// lib/session-close.js — session close 핸들러 (UR-0025/UR-0125 큰 핸들러 모듈화 10번째, 1.9.425)
|
|
2
|
+
// bin/leerness.js 에서 sessionClose(599줄) 분리. DI: harness 고유 의존 다수 주입.
|
|
3
|
+
// io 프리미티브는 ./io, _sanitizeFences/_parseArchiveBlocks 는 ./pure-utils, cp/os/path/fs 빌트인.
|
|
4
|
+
// __filename→harnessPath(self-spawn). 동작/출력 무변경(9 카테고리 + 활성 룰 검증 + retro 등).
|
|
5
|
+
'use strict';
|
|
6
|
+
const cp = require('child_process');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const { log, ok, warn, fail, failJson, today, now, absRoot, exists, read, readBuf, mkdirp, writeUtf8, append, rel } = require('./io');
|
|
11
|
+
const { _sanitizeFences, _parseArchiveBlocks } = require('./pure-utils');
|
|
12
|
+
|
|
13
|
+
function sessionClose(root, opts = {}, deps = {}) {
|
|
14
|
+
const { VERSION, STATUSES, MARK, has, arg, harnessPath, readProgressRows, evidencePath, handoffPath, currentStatePath, taskLogPath, verifyRules, _autoRoadmap, _readUsageStats, readSessionCounter, writeSessionCounter, _retroAggregate, _retroOneLine, retroCmd, _loadDecisions, readRules, planPath, _loadLessons, _readFeatureGraph, _auditUserRequests, _detectDeliveredRequests, _computeRoundHistory, _computeMilestones, _computeRecentChanges, _collectPyFiles, _analyzePyFile, _collectRuntimeEnv, _scanShellScriptsEncoding, _listAPISkills, _matchAPISkills, _loadShellFailures, _shellEnvDrift, _runPreWakeAudit, _saveAndAppendPreWakeReport, _runIdempotencyAudit, _detectAbnormalShutdown, _updateUserRequest } = deps;
|
|
15
|
+
root = absRoot(root);
|
|
16
|
+
// 1.10.4 (13th 버그헌트 P2, UR-0167): 경로 없음/디렉토리 아님 → 구조화 에러 + exit 1. mkdir <path>/.harness ENOTDIR 크래시 & 실패를 성공(exit 0)으로 오판하던 문제 차단.
|
|
17
|
+
if (!exists(root) || !fs.statSync(root).isDirectory()) { failJson(!!opts.json || has('--json'), 'path_not_found', `경로 없음 또는 디렉토리 아님: ${root}`); return; }
|
|
18
|
+
// 1.9.103: --json 모드 — stdout 억제 후 구조화 출력
|
|
19
|
+
const jsonMode = !!opts.json || has('--json');
|
|
20
|
+
const _origWrite = process.stdout.write.bind(process.stdout);
|
|
21
|
+
if (jsonMode) process.stdout.write = () => true;
|
|
22
|
+
const jsonResult = { version: VERSION, root, closedAt: now() };
|
|
23
|
+
try {
|
|
24
|
+
const rows = readProgressRows(root);
|
|
25
|
+
const buckets = {};
|
|
26
|
+
for (const s of STATUSES) buckets[s] = [];
|
|
27
|
+
for (const r of rows) (buckets[r.status] || (buckets[r.status] = [])).push(r);
|
|
28
|
+
// 1.9.103: JSON 결과 누적
|
|
29
|
+
jsonResult.taskCounts = {};
|
|
30
|
+
for (const s of STATUSES) jsonResult.taskCounts[s] = (buckets[s] || []).length;
|
|
31
|
+
jsonResult.recommendedDirection = (buckets['in-progress'][0]?.request) || (buckets['planned'][0]?.request) || (buckets['requested'][0]?.request) || null;
|
|
32
|
+
jsonResult.nextExactStep = (buckets['in-progress'][0]?.nextAction) || (buckets['planned'][0]?.nextAction) || (buckets['requested'][0]?.nextAction) || null;
|
|
33
|
+
// 1.12.3 (14th 버그헌트 P3, UR-0183): 마감 시 완료 정직성 advisory — done 인데 evidence 가 비었거나 placeholder 인 task 노출(차단 X, 정직성 환기). lazy detect 의 done_no_evidence 휴리스틱과 동일.
|
|
34
|
+
const _doneNoEvidence = (buckets['done'] || []).filter(r => !r.evidence || /^(\s*|user-request|-)$/.test(r.evidence) || /^plan:M-\d{4}\s*$/.test(r.evidence));
|
|
35
|
+
jsonResult.completionHonesty = { doneTotal: (buckets['done'] || []).length, doneWithoutEvidence: _doneNoEvidence.length, ids: _doneNoEvidence.slice(0, 5).map(r => r.id) };
|
|
36
|
+
if (_doneNoEvidence.length) log(` ⚠ 완료 정직성: done ${_doneNoEvidence.length}건 evidence 없음/placeholder (${_doneNoEvidence.slice(0, 3).map(r => r.id).join(', ')}) — verify-claim 권장 (advisory)`);
|
|
37
|
+
|
|
38
|
+
function rowsToList(arr) {
|
|
39
|
+
if (!arr || !arr.length) return '- 없음';
|
|
40
|
+
return arr.map(r => `- ${r.id} ${r.request} → next: ${r.nextAction}`).join('\n');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 1.9.287 (Codex 리뷰 수렴): evidence 임베딩 시 코드펜스(```) 가 session-handoff.md 마크다운을 깨뜨리는 품질 버그 수정.
|
|
44
|
+
const evidenceSummary = _sanitizeFences(exists(evidencePath(root)) ? (read(evidencePath(root)).split('\n').slice(-30).join('\n')) : '(no review-evidence.md)');
|
|
45
|
+
const block = [
|
|
46
|
+
`# Session Handoff`,
|
|
47
|
+
``,
|
|
48
|
+
`Last generated: ${now()}`,
|
|
49
|
+
``,
|
|
50
|
+
`## Completed`,
|
|
51
|
+
rowsToList(buckets['done']),
|
|
52
|
+
``,
|
|
53
|
+
`## In Progress`,
|
|
54
|
+
rowsToList(buckets['in-progress']),
|
|
55
|
+
``,
|
|
56
|
+
`## Incomplete / Waiting / On Hold / Blocked`,
|
|
57
|
+
rowsToList([...(buckets['incomplete']||[]), ...(buckets['waiting']||[]), ...(buckets['on-hold']||[]), ...(buckets['blocked']||[])]),
|
|
58
|
+
``,
|
|
59
|
+
`## Dropped`,
|
|
60
|
+
rowsToList(buckets['dropped']),
|
|
61
|
+
``,
|
|
62
|
+
`## Verification`,
|
|
63
|
+
'```',
|
|
64
|
+
evidenceSummary.trim() || '(empty)',
|
|
65
|
+
'```',
|
|
66
|
+
``,
|
|
67
|
+
`## Recommended Direction`,
|
|
68
|
+
`- ${(buckets['in-progress'][0]?.request) || (buckets['planned'][0]?.request) || (buckets['requested'][0]?.request) || '다음 우선순위를 사용자와 정합니다.'}`,
|
|
69
|
+
``,
|
|
70
|
+
`## Next Exact Step`,
|
|
71
|
+
`- ${(buckets['in-progress'][0]?.nextAction) || (buckets['planned'][0]?.nextAction) || (buckets['requested'][0]?.nextAction) || '없음'}`,
|
|
72
|
+
``
|
|
73
|
+
].join('\n');
|
|
74
|
+
const cur = exists(handoffPath(root)) ? read(handoffPath(root)) : '';
|
|
75
|
+
// 1.9.316 (drift 마커 버그): 프론트매터는 파일이 '---' 로 시작할 때만 추출.
|
|
76
|
+
// 이전: 본문의 '---'(수평선/구분자)을 프론트매터 종료로 오인 → 구 블록(구 'Last generated')을 보존 →
|
|
77
|
+
// session-handoff.md 에 'Last generated' 중복 누적 → drift 가 첫(=구) 매치를 읽어 'session close 누락' 영구 오발화.
|
|
78
|
+
let frontmatter = '';
|
|
79
|
+
if (/^---\r?\n/.test(cur)) {
|
|
80
|
+
const fmEnd = cur.indexOf('\n---\n', 4);
|
|
81
|
+
if (fmEnd > 0) frontmatter = cur.slice(0, fmEnd + 5) + MARK + '\n';
|
|
82
|
+
}
|
|
83
|
+
writeUtf8(handoffPath(root), frontmatter + block);
|
|
84
|
+
|
|
85
|
+
if (exists(currentStatePath(root))) {
|
|
86
|
+
let cs = read(currentStatePath(root));
|
|
87
|
+
cs = cs.replace(/Updated: \d{4}-\d{2}-\d{2}/, `Updated: ${today()}`);
|
|
88
|
+
cs = cs.replace(/## Now\n[\s\S]*?(?=\n## Next)/, `## Now\n- ${(buckets['in-progress'][0]?.request) || '대기 중'}\n`);
|
|
89
|
+
cs = cs.replace(/## Next\n[\s\S]*?(?=\n## Blockers)/, `## Next\n- ${(buckets['planned'][0]?.request) || (buckets['requested'][0]?.request) || '계획된 작업 없음'}\n`);
|
|
90
|
+
cs = cs.replace(/## Blockers\n[\s\S]*$/, `## Blockers\n${(buckets['blocked']||[]).map(b=>`- ${b.id} ${b.request}`).join('\n') || '-'}\n`);
|
|
91
|
+
writeUtf8(currentStatePath(root), cs);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
append(taskLogPath(root), `\n## ${today()} session-close\n- Generated session-handoff.md and refreshed current-state.md.\n`);
|
|
95
|
+
|
|
96
|
+
log('# Session Close');
|
|
97
|
+
log('## Task Lists');
|
|
98
|
+
for (const s of STATUSES) {
|
|
99
|
+
log(`\n### ${s}`);
|
|
100
|
+
log(rowsToList(buckets[s]));
|
|
101
|
+
}
|
|
102
|
+
// 1.9.8: 룰 검증 자동 수행 + 보고
|
|
103
|
+
const ruleResults = verifyRules(root);
|
|
104
|
+
jsonResult.rules = ruleResults.map(r => ({ id: r.id, trigger: r.trigger, verified: r.verified, note: r.note }));
|
|
105
|
+
log('\n## ⚡ User Rules verification');
|
|
106
|
+
if (!ruleResults.length) log('- 활성 룰 없음');
|
|
107
|
+
else {
|
|
108
|
+
log('| ID | Trigger | Rule | Verified | Note |');
|
|
109
|
+
log('|---|---|---|---|---|');
|
|
110
|
+
const ic = { pass: '✓ pass', pending: '⓿ pending', manual: 'ⓘ manual', baseline: '○ baseline' };
|
|
111
|
+
for (const r of ruleResults) log(`| ${r.id} | ${r.trigger} | ${r.rule.slice(0, 40)} | ${ic[r.verified] || '?'} | ${r.note} |`);
|
|
112
|
+
}
|
|
113
|
+
log('\n## Required final response sections');
|
|
114
|
+
log('- 완료 작업\n- 진행 중 작업\n- 미완료/예정/대기/보류/차단/드랍 작업\n- 검증 결과\n- 추천 방향\n- 다음 정확한 작업\n- ⚡ 활성 룰별 검증 결과');
|
|
115
|
+
ok(`session-handoff.md and current-state.md updated`);
|
|
116
|
+
// 1.9.12: session close 끝에 roadmap.html 자동 갱신
|
|
117
|
+
_autoRoadmap(root, 'session-close');
|
|
118
|
+
// 1.9.57: --suggest 옵션 — 마감 시 skill suggest + drift check + lessons 통합 보고
|
|
119
|
+
// 1.9.59: default 활성 — --no-suggest로 명시 비활성 가능
|
|
120
|
+
const suggestEnabled = (has('--suggest') || (!has('--no-suggest') && process.env.LEERNESS_NO_SUGGEST !== '1'));
|
|
121
|
+
if (suggestEnabled) {
|
|
122
|
+
const isTty = process.stdout && process.stdout.isTTY;
|
|
123
|
+
const cy = s => isTty ? `\x1b[36m${s}\x1b[0m` : s;
|
|
124
|
+
const dim = s => isTty ? `\x1b[2m${s}\x1b[0m` : s;
|
|
125
|
+
log('');
|
|
126
|
+
log(cy('## 💡 다음 라운드 추천 (1.9.57 --suggest)'));
|
|
127
|
+
// 1) skill suggest
|
|
128
|
+
try {
|
|
129
|
+
const r = cp.spawnSync(process.execPath, [harnessPath, 'skill', 'suggest', '--path', root, '--min', '3', '--json'],
|
|
130
|
+
{ encoding: 'utf8', timeout: 15000, env: { ...process.env, LEERNESS_INTERNAL: '1', LEERNESS_NO_PROMPT: '1', LEERNESS_NO_DRIFT_CHECK: '1' } });
|
|
131
|
+
const j = JSON.parse(r.stdout);
|
|
132
|
+
if (j.candidates && j.candidates.length) {
|
|
133
|
+
log(dim(' 📌 신규 skill 후보 (Hermes-style 자동 학습):'));
|
|
134
|
+
for (const c of j.candidates.slice(0, 3)) log(` • ${c.keyword} (${c.count}회 등장, 출처: ${c.source})`);
|
|
135
|
+
jsonResult.skillCandidates = j.candidates.slice(0, 5);
|
|
136
|
+
}
|
|
137
|
+
} catch {}
|
|
138
|
+
// 2) drift check
|
|
139
|
+
try {
|
|
140
|
+
const r = cp.spawnSync(process.execPath, [harnessPath, 'drift', 'check', root, '--json'],
|
|
141
|
+
{ encoding: 'utf8', timeout: 15000, env: { ...process.env, LEERNESS_INTERNAL: '1', LEERNESS_NO_PROMPT: '1', LEERNESS_NO_DRIFT_CHECK: '0' } });
|
|
142
|
+
const j = JSON.parse(r.stdout.trim());
|
|
143
|
+
if (j.level) {
|
|
144
|
+
log(dim(` 🩺 drift 상태: ${j.level} ${j.score}/200`));
|
|
145
|
+
if (j.fired && j.fired.length) log(dim(` 🔥 ${j.fired.length}건 임계 초과 — \`leerness drift check\` 상세`));
|
|
146
|
+
jsonResult.drift = { level: j.level, score: j.score, fired: (j.fired || []).map(f => ({ label: f.label, weight: f.weight })) };
|
|
147
|
+
}
|
|
148
|
+
} catch {}
|
|
149
|
+
// 3) usage stats top
|
|
150
|
+
try {
|
|
151
|
+
const stats = _readUsageStats(root);
|
|
152
|
+
const entries = Object.entries(stats.commands || {}).sort((a, b) => b[1] - a[1]).slice(0, 3);
|
|
153
|
+
if (entries.length) {
|
|
154
|
+
log(dim(` 📊 가장 많이 쓴 명령: ${entries.map(([c, n]) => `${c}(${n})`).join(', ')}`));
|
|
155
|
+
jsonResult.topCommands = entries.map(([command, count]) => ({ command, count }));
|
|
156
|
+
}
|
|
157
|
+
// 1.9.74: MCP tools/call 통계 + rare 도구 노출
|
|
158
|
+
if (stats.mcp && stats.mcp.tools) {
|
|
159
|
+
const mcpEntries = Object.entries(stats.mcp.tools).sort((a, b) => b[1] - a[1]);
|
|
160
|
+
if (mcpEntries.length) {
|
|
161
|
+
const mcpTotal = mcpEntries.reduce((s, [, n]) => s + n, 0);
|
|
162
|
+
log(dim(` 🔌 MCP 호출 (1.9.74): 총 ${mcpTotal}회, top: ${mcpEntries.slice(0, 3).map(([t, n]) => `${t}(${n})`).join(', ')}`));
|
|
163
|
+
const threshold = Math.max(1, Math.floor(mcpTotal * 0.05));
|
|
164
|
+
const rare = mcpEntries.filter(([, n]) => n <= threshold).map(([t]) => t);
|
|
165
|
+
if (rare.length && mcpTotal >= 5) log(dim(` 💡 드물게 호출된 MCP: ${rare.slice(0, 4).join(', ')}`));
|
|
166
|
+
jsonResult.mcpStats = { total: mcpTotal, top: mcpEntries.slice(0, 5).map(([tool, count]) => ({ tool, count })), rare: rare.slice(0, 10) };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} catch {}
|
|
170
|
+
// 1.9.74: skill match query top (skill-suggestions.md 누적)
|
|
171
|
+
try {
|
|
172
|
+
const histPath = path.join(root, '.harness', 'skill-suggestions.md');
|
|
173
|
+
if (exists(histPath)) {
|
|
174
|
+
const histTxt = read(histPath);
|
|
175
|
+
const queries = [];
|
|
176
|
+
for (const block of histTxt.split(/\n(?=## )/)) {
|
|
177
|
+
const h = block.match(/^## ([\d-]+ [\d:]+) — query "([^"]+)"/);
|
|
178
|
+
if (h) queries.push(h[2]);
|
|
179
|
+
}
|
|
180
|
+
if (queries.length) {
|
|
181
|
+
// 같은 query 개수 카운트
|
|
182
|
+
const counts = {};
|
|
183
|
+
for (const q of queries) counts[q] = (counts[q] || 0) + 1;
|
|
184
|
+
const topQueries = Object.entries(counts).sort((a, b) => b[1] - a[1]).slice(0, 3);
|
|
185
|
+
log(dim(` 📒 skill match query 누적 (1.9.74): 총 ${queries.length}회 / 종류 ${Object.keys(counts).length}개`));
|
|
186
|
+
for (const [q, n] of topQueries) log(dim(` • "${q.slice(0, 50)}"${n > 1 ? ` (${n}회)` : ''}`));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} catch {}
|
|
190
|
+
log('');
|
|
191
|
+
}
|
|
192
|
+
// 1.9.13: 세션 카운터 + 자동 한 줄 요약 + 5세션마다 깊은 회고
|
|
193
|
+
try {
|
|
194
|
+
const sc = readSessionCounter(root);
|
|
195
|
+
sc.count = (sc.count || 0) + 1;
|
|
196
|
+
sc.lastCloseAt = now();
|
|
197
|
+
writeSessionCounter(root, sc);
|
|
198
|
+
const agg = _retroAggregate(root);
|
|
199
|
+
log(`\n## 📈 진행 요약 (session #${sc.count})`);
|
|
200
|
+
log(` ${_retroOneLine(agg)}`);
|
|
201
|
+
// 1.9.132: archive 활동 1줄 요약 — 마감 시점에 DELETE 활동 가시화 (handoff 7번째 회수와 symmetric)
|
|
202
|
+
try {
|
|
203
|
+
const hdSC = path.join(root, '.harness');
|
|
204
|
+
const arc = { d: 0, l: 0, p: 0, total: 0 };
|
|
205
|
+
for (const [k, f] of [['d', 'decisions.archive.md'], ['l', 'lessons.archive.md'], ['p', 'plan.archive.md']]) {
|
|
206
|
+
const fp = path.join(hdSC, f);
|
|
207
|
+
if (exists(fp)) {
|
|
208
|
+
const entries = _parseArchiveBlocks(read(fp));
|
|
209
|
+
arc[k] = entries.length;
|
|
210
|
+
arc.total += entries.length;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (arc.total > 0) {
|
|
214
|
+
log(` 🗑 archive 누적: D${arc.d}/L${arc.l}/P${arc.p} (${arc.total}건) — 복원 후보: leerness memory archive list`);
|
|
215
|
+
}
|
|
216
|
+
} catch {}
|
|
217
|
+
if (sc.count % 5 === 0) {
|
|
218
|
+
log(`\n## 🔄 ${sc.count}세션 마일스톤 — 자동 회고 (5세션마다)`);
|
|
219
|
+
retroCmd(root);
|
|
220
|
+
sc.lastDeepRetroAt = now();
|
|
221
|
+
writeSessionCounter(root, sc);
|
|
222
|
+
} else {
|
|
223
|
+
const left = 5 - (sc.count % 5);
|
|
224
|
+
log(` 💡 ${left}세션 후 자동 깊은 회고 — \`leerness retro\`로 즉시 실행 가능`);
|
|
225
|
+
}
|
|
226
|
+
// 1.9.16: 워크스페이스 안내 (다른 leerness 프로젝트가 있으면)
|
|
227
|
+
try {
|
|
228
|
+
const wsCands = [path.resolve(root, '_apps'), path.resolve(root, '..', '_apps')];
|
|
229
|
+
let wsCount = 0;
|
|
230
|
+
for (const base of wsCands) {
|
|
231
|
+
if (!exists(base)) continue;
|
|
232
|
+
try { if (!fs.statSync(base).isDirectory()) continue; } catch { continue; }
|
|
233
|
+
for (const e of fs.readdirSync(base)) {
|
|
234
|
+
try {
|
|
235
|
+
const p = path.join(base, e);
|
|
236
|
+
if (fs.statSync(p).isDirectory() && exists(path.join(p, '.harness')) && p !== root) wsCount++;
|
|
237
|
+
} catch {}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (wsCount > 0) log(` 🌐 워크스페이스에 ${wsCount}개 다른 leerness 프로젝트 — \`leerness retro --all-apps\`로 통합 회고`);
|
|
241
|
+
jsonResult.workspacePeers = wsCount;
|
|
242
|
+
} catch {}
|
|
243
|
+
} catch (e) {
|
|
244
|
+
warn('retro 요약 실패: ' + (e && e.message ? e.message : e));
|
|
245
|
+
jsonResult.retroSummaryError = e && e.message ? e.message : String(e);
|
|
246
|
+
}
|
|
247
|
+
} finally {
|
|
248
|
+
// 1.9.103: stdout 복원
|
|
249
|
+
if (jsonMode) process.stdout.write = _origWrite;
|
|
250
|
+
}
|
|
251
|
+
// 1.9.103: JSON 모드 — 구조화 출력
|
|
252
|
+
if (jsonMode) {
|
|
253
|
+
try {
|
|
254
|
+
const sc = readSessionCounter(root);
|
|
255
|
+
jsonResult.sessionNumber = sc.count;
|
|
256
|
+
} catch {}
|
|
257
|
+
// 1.9.122: memorySurface 통합 (handoff --json 1.9.115 와 동일 패턴)
|
|
258
|
+
try {
|
|
259
|
+
const rows0 = readProgressRows(root);
|
|
260
|
+
const tasksByStatus0 = {};
|
|
261
|
+
for (const s of STATUSES) tasksByStatus0[s] = 0;
|
|
262
|
+
for (const r of rows0) tasksByStatus0[r.status] = (tasksByStatus0[r.status] || 0) + 1;
|
|
263
|
+
const tasksInProgress0 = tasksByStatus0['in-progress'] || 0;
|
|
264
|
+
const decisionsCount0 = _loadDecisions(root).length; // 1.9.339 (UR-0053): canonical 단일 진실소스
|
|
265
|
+
const rules0 = readRules(root);
|
|
266
|
+
const rulesActive0 = rules0.filter(r => r.status === 'active').length;
|
|
267
|
+
const planText0 = exists(planPath(root)) ? read(planPath(root)) : '';
|
|
268
|
+
const milestones0 = (planText0.match(/^### M-\d{4}\./gm) || []).length;
|
|
269
|
+
const lessonsCount0 = _loadLessons(root).length;
|
|
270
|
+
// 1.9.130: archive 카운트 통합
|
|
271
|
+
const archiveCountsS = { decisions: 0, lessons: 0, plan: 0, total: 0 };
|
|
272
|
+
try {
|
|
273
|
+
const hdS = path.join(root, '.harness');
|
|
274
|
+
for (const [key, file] of [['decisions', 'decisions.archive.md'], ['lessons', 'lessons.archive.md'], ['plan', 'plan.archive.md']]) {
|
|
275
|
+
const fpS = path.join(hdS, file);
|
|
276
|
+
if (exists(fpS)) {
|
|
277
|
+
const entries = _parseArchiveBlocks(read(fpS));
|
|
278
|
+
archiveCountsS[key] = entries.length;
|
|
279
|
+
archiveCountsS.total += entries.length;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
} catch {}
|
|
283
|
+
jsonResult.memorySurface = {
|
|
284
|
+
tasks: { inProgress: tasksInProgress0, total: rows0.length, byStatus: tasksByStatus0 },
|
|
285
|
+
decisions: { count: decisionsCount0 },
|
|
286
|
+
rules: { active: rulesActive0, total: rules0.length },
|
|
287
|
+
plan: { milestones: milestones0 },
|
|
288
|
+
lessons: { count: lessonsCount0 },
|
|
289
|
+
archive: archiveCountsS, // 1.9.130
|
|
290
|
+
summary: `T${tasksInProgress0}/D${decisionsCount0}/R${rulesActive0}/P${milestones0}/L${lessonsCount0}`,
|
|
291
|
+
};
|
|
292
|
+
// 1.9.142: featureCounts 통합 — session close JSON에 Feature Graph 통계
|
|
293
|
+
try {
|
|
294
|
+
const { nodes: fNodesC } = _readFeatureGraph(root);
|
|
295
|
+
const edgeCount = fNodesC.reduce((s, n) => s + (n.dependsOn?.length || 0) + (n.affects?.length || 0) + (n.coChangesWith?.length || 0), 0);
|
|
296
|
+
const linkedIds = new Set();
|
|
297
|
+
for (const n of fNodesC) {
|
|
298
|
+
for (const x of [...(n.dependsOn||[]), ...(n.affects||[]), ...(n.coChangesWith||[])]) { linkedIds.add(n.id); linkedIds.add(x); }
|
|
299
|
+
}
|
|
300
|
+
const isolated = fNodesC.length ? (fNodesC.length - linkedIds.size) : 0;
|
|
301
|
+
jsonResult.featureGraph = {
|
|
302
|
+
total: fNodesC.length,
|
|
303
|
+
edges: edgeCount,
|
|
304
|
+
isolated: Math.max(0, isolated),
|
|
305
|
+
summary: `F${fNodesC.length}/E${edgeCount}${isolated > 0 ? `/iso${isolated}` : ''}`
|
|
306
|
+
};
|
|
307
|
+
} catch {}
|
|
308
|
+
} catch {}
|
|
309
|
+
|
|
310
|
+
// 1.9.217: session close 자동 통합 — 1.9.207 + 1.9.209 + 1.9.212
|
|
311
|
+
// 마감 시 미답 요청 / pre-wake audit / 멱등성 검사 자동 실행 + JSON 통합
|
|
312
|
+
try {
|
|
313
|
+
// 1.9.207: 미답 사용자 요청 audit
|
|
314
|
+
const reqAudit = _auditUserRequests(root);
|
|
315
|
+
jsonResult.userRequestsAudit = {
|
|
316
|
+
total: reqAudit.total,
|
|
317
|
+
open: reqAudit.open,
|
|
318
|
+
missing: reqAudit.missing ? reqAudit.missing.length : 0,
|
|
319
|
+
tracked: reqAudit.tracked ? reqAudit.tracked.length : 0,
|
|
320
|
+
stale: reqAudit.stale ? reqAudit.stale.length : 0
|
|
321
|
+
};
|
|
322
|
+
// 1.9.223: delivered 패턴 자동 감지 통합
|
|
323
|
+
try {
|
|
324
|
+
const delivered = _detectDeliveredRequests(root);
|
|
325
|
+
jsonResult.deliveredRequests = {
|
|
326
|
+
candidates: delivered.candidates.length,
|
|
327
|
+
currentVersion: delivered.currentVersion,
|
|
328
|
+
autoCompleteAvailable: delivered.candidates.length > 0
|
|
329
|
+
};
|
|
330
|
+
} catch {}
|
|
331
|
+
// 1.9.227: roundHistory 통합 (session close JSON 6번째 통합 필드)
|
|
332
|
+
try {
|
|
333
|
+
const rh = _computeRoundHistory(root);
|
|
334
|
+
jsonResult.roundHistory = {
|
|
335
|
+
roundCount: rh.roundCount,
|
|
336
|
+
baselineVersion: rh.baselineVersion,
|
|
337
|
+
nextMilestone: rh.nextMilestone,
|
|
338
|
+
roundsToNextMilestone: rh.roundsToNextMilestone,
|
|
339
|
+
daysActive: rh.daysActive,
|
|
340
|
+
avgRoundsPerDay: rh.avgRoundsPerDay
|
|
341
|
+
};
|
|
342
|
+
} catch {}
|
|
343
|
+
// 1.9.230: milestones 통합 (session close JSON 7번째 통합 필드)
|
|
344
|
+
try {
|
|
345
|
+
const ms = _computeMilestones(root);
|
|
346
|
+
jsonResult.milestones = {
|
|
347
|
+
reachedCount: ms.reached.length,
|
|
348
|
+
reached: ms.reached.map(m => ({ milestone: m.milestone, version: m.version, reachedAt: m.reachedAt })),
|
|
349
|
+
next: ms.next,
|
|
350
|
+
avgRoundsPerDay: ms.avgRoundsPerDay
|
|
351
|
+
};
|
|
352
|
+
} catch {}
|
|
353
|
+
// 1.9.234: recentChanges 통합 (session close JSON 8번째 통합 필드) — 최근 5 라운드 변경
|
|
354
|
+
try {
|
|
355
|
+
jsonResult.recentChanges = _computeRecentChanges(root, 5);
|
|
356
|
+
} catch {}
|
|
357
|
+
// 1.9.240: pyFiles 통합 (session close JSON 9번째 통합 필드) — UR-0013 2단계
|
|
358
|
+
try {
|
|
359
|
+
const pyFiles = _collectPyFiles(root, 200);
|
|
360
|
+
const analyses = pyFiles.slice(0, 200).map(f => _analyzePyFile(f)).filter(Boolean);
|
|
361
|
+
jsonResult.pyFiles = {
|
|
362
|
+
total: pyFiles.length,
|
|
363
|
+
analyzed: analyses.length,
|
|
364
|
+
totalLOC: analyses.reduce((s, a) => s + a.loc, 0),
|
|
365
|
+
totalImports: analyses.reduce((s, a) => s + a.imports, 0),
|
|
366
|
+
totalFuncs: analyses.reduce((s, a) => s + a.funcs, 0),
|
|
367
|
+
totalClasses: analyses.reduce((s, a) => s + a.classes, 0)
|
|
368
|
+
};
|
|
369
|
+
} catch {}
|
|
370
|
+
// 1.9.242: envInfo 통합 (session close JSON 10번째 통합 필드) — UR-0014 2단계
|
|
371
|
+
try {
|
|
372
|
+
const runtimeEnv = _collectRuntimeEnv();
|
|
373
|
+
const encScan = _scanShellScriptsEncoding(root);
|
|
374
|
+
jsonResult.envInfo = {
|
|
375
|
+
os: runtimeEnv.os.platform,
|
|
376
|
+
isKoreanWindows: runtimeEnv.locale.isKoreanWindows || false,
|
|
377
|
+
codepage: runtimeEnv.locale.codepage || null,
|
|
378
|
+
nodeVersion: runtimeEnv.node.version,
|
|
379
|
+
shellScriptsScanned: encScan.scanned,
|
|
380
|
+
encodingRiskCount: encScan.atRisk.length,
|
|
381
|
+
encodingRiskFiles: encScan.atRisk.slice(0, 5).map(r => r.file),
|
|
382
|
+
// 1.9.249 (UR-0018): 터미널 출력 인코딩 안전 여부 + 자동 회복 결과
|
|
383
|
+
terminalEncodingOk: runtimeEnv.locale.codepage === 65001 || !runtimeEnv.locale.isKoreanWindows,
|
|
384
|
+
autoChcpApplied: process.env._LEERNESS_AUTOCHCP_APPLIED || null,
|
|
385
|
+
// 1.9.250 (UR-0018 2단계): POSIX (Linux/macOS/WSL) terminal encoding 점검
|
|
386
|
+
posixEncodingOk: runtimeEnv.locale.posixEncodingOk,
|
|
387
|
+
isWSL: runtimeEnv.locale.isWSL || false
|
|
388
|
+
};
|
|
389
|
+
} catch {}
|
|
390
|
+
// 1.9.245: apiSkills 통합 (session close JSON 11번째 통합 필드) — UR-0015
|
|
391
|
+
try {
|
|
392
|
+
const allSkills = _listAPISkills(root);
|
|
393
|
+
let currentTaskText = '';
|
|
394
|
+
try {
|
|
395
|
+
const rows = readProgressRows(root);
|
|
396
|
+
const ip = rows.find(r => r.status === 'in-progress');
|
|
397
|
+
if (ip) currentTaskText = (ip.title || '') + ' ' + (ip.notes || '');
|
|
398
|
+
} catch {}
|
|
399
|
+
const matched = currentTaskText ? _matchAPISkills(root, currentTaskText) : [];
|
|
400
|
+
jsonResult.apiSkills = {
|
|
401
|
+
total: allSkills.length,
|
|
402
|
+
matched: matched.length,
|
|
403
|
+
matchedIds: matched.slice(0, 5).map(s => s.id),
|
|
404
|
+
ids: allSkills.slice(0, 10).map(s => s.id)
|
|
405
|
+
};
|
|
406
|
+
} catch {}
|
|
407
|
+
// 1.9.264: shellGuard 통합 (session close JSON 12번째 통합 필드) — UR-0020 셸 실패 메모리 + 환경 변동
|
|
408
|
+
try {
|
|
409
|
+
const sf = _loadShellFailures(root);
|
|
410
|
+
const drift = _shellEnvDrift(root);
|
|
411
|
+
jsonResult.shellGuard = {
|
|
412
|
+
failureCount: sf.failures.length,
|
|
413
|
+
recent: sf.failures.slice(-3).map(f => ({ cmd: (f.cmd || '').slice(0, 50), exitCode: f.exitCode, shell: f.shell, rules: f.issues || [] })),
|
|
414
|
+
envDriftChanges: drift && drift.changes ? drift.changes.length : 0,
|
|
415
|
+
envDrift: drift ? drift.changes : null
|
|
416
|
+
};
|
|
417
|
+
} catch {}
|
|
418
|
+
} catch {}
|
|
419
|
+
try {
|
|
420
|
+
// 1.9.209: pre-wake-audit 자동 실행 + 저장 (sleep 전 자동 점검)
|
|
421
|
+
if (!opts.noPreWake && !has('--no-pre-wake')) {
|
|
422
|
+
const audit = _runPreWakeAudit(root);
|
|
423
|
+
_saveAndAppendPreWakeReport(root, audit);
|
|
424
|
+
jsonResult.preWakeAudit = {
|
|
425
|
+
auditedAt: audit.auditedAt,
|
|
426
|
+
critical: audit.summary.criticalCount,
|
|
427
|
+
warning: audit.summary.warningCount,
|
|
428
|
+
info: audit.summary.infoCount,
|
|
429
|
+
needsAttention: audit.summary.needsAttention
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
} catch {}
|
|
433
|
+
try {
|
|
434
|
+
// 1.9.212: 멱등성 검사 자동 실행 (rule/task/user-requests/wakeups 4영역)
|
|
435
|
+
const idemp = _runIdempotencyAudit(root);
|
|
436
|
+
jsonResult.idempotencyAudit = {
|
|
437
|
+
violations: idemp.summary.totalViolations,
|
|
438
|
+
high: idemp.summary.highSeverity,
|
|
439
|
+
medium: idemp.summary.mediumSeverity,
|
|
440
|
+
low: idemp.summary.lowSeverity,
|
|
441
|
+
verified: idemp.summary.verifiedAreas,
|
|
442
|
+
overall: idemp.summary.overall
|
|
443
|
+
};
|
|
444
|
+
} catch {}
|
|
445
|
+
try {
|
|
446
|
+
// 1.9.221: abnormalShutdown 자동 감지 (1.9.220 통합) — session close 시 다음 재개 가이드 회수
|
|
447
|
+
const ad = _detectAbnormalShutdown(root);
|
|
448
|
+
jsonResult.abnormalShutdown = {
|
|
449
|
+
detected: ad.abnormalShutdown,
|
|
450
|
+
severity: ad.severity,
|
|
451
|
+
signalCount: ad.signals.length,
|
|
452
|
+
signals: ad.signals.map(s => ({ kind: s.kind, severity: s.severity, detail: s.detail })),
|
|
453
|
+
resumeGuide: ad.resumeGuide
|
|
454
|
+
};
|
|
455
|
+
} catch {}
|
|
456
|
+
|
|
457
|
+
process.stdout.write(JSON.stringify(jsonResult, null, 2) + '\n');
|
|
458
|
+
} else {
|
|
459
|
+
// 1.9.217: human 출력 모드에서도 통합 보고 노출 (마감 직전)
|
|
460
|
+
try {
|
|
461
|
+
const isTty = process.stdout.isTTY;
|
|
462
|
+
const grn = s => isTty ? `\x1b[32m${s}\x1b[0m` : s;
|
|
463
|
+
const yel = s => isTty ? `\x1b[33m${s}\x1b[0m` : s;
|
|
464
|
+
const red = s => isTty ? `\x1b[31m${s}\x1b[0m` : s;
|
|
465
|
+
const dim = s => isTty ? `\x1b[2m${s}\x1b[0m` : s;
|
|
466
|
+
|
|
467
|
+
log('');
|
|
468
|
+
log(`## 🔚 session close 자동 통합 보고 (1.9.217)`);
|
|
469
|
+
// 1.9.207 + 1.9.223 (delivered 패턴 자동 권장) + 1.9.224 (--auto-apply-delivered 옵션)
|
|
470
|
+
try {
|
|
471
|
+
const reqAudit = _auditUserRequests(root);
|
|
472
|
+
const missCnt = reqAudit.missing ? reqAudit.missing.length : 0;
|
|
473
|
+
let delivered = { candidates: [] };
|
|
474
|
+
try { delivered = _detectDeliveredRequests(root); } catch {}
|
|
475
|
+
if (delivered.candidates && delivered.candidates.length > 0) {
|
|
476
|
+
if (has('--auto-apply-delivered')) {
|
|
477
|
+
// 1.9.224: 자동 정리 (마감 시 호출 — 안전: 패턴 매칭 + 버전 가드)
|
|
478
|
+
let ok = 0;
|
|
479
|
+
for (const c of delivered.candidates) {
|
|
480
|
+
const u = _updateUserRequest(root, c.id, { status: 'completed', autoCompletedAt: new Date().toISOString(), autoCompleteReason: 'session-close-auto-apply-1.9.224' });
|
|
481
|
+
if (u) ok++;
|
|
482
|
+
}
|
|
483
|
+
log(grn(` ✓ delivered 패턴 ${ok}건 자동 완료 (--auto-apply-delivered 1.9.224)`));
|
|
484
|
+
} else {
|
|
485
|
+
log(yel(` 📥 delivered 패턴 ${delivered.candidates.length}건 (1.9.223) — 자동 완료 가능`));
|
|
486
|
+
log(dim(` → leerness requests auto-complete --apply (수동) 또는 session close --auto-apply-delivered (1.9.224)`));
|
|
487
|
+
}
|
|
488
|
+
} else if (missCnt > 0) {
|
|
489
|
+
log(red(` ⚠ 미답 사용자 요청 ${missCnt}건 (task-log/plan/decisions 매칭 안 됨)`));
|
|
490
|
+
} else if (reqAudit.open > 0) {
|
|
491
|
+
log(grn(` ✓ 사용자 요청 ${reqAudit.open}건 모두 tracked`));
|
|
492
|
+
} else {
|
|
493
|
+
log(dim(` ℹ 사용자 요청 없음 (UR 백로그 비어있음)`));
|
|
494
|
+
}
|
|
495
|
+
} catch {}
|
|
496
|
+
// 1.9.209
|
|
497
|
+
try {
|
|
498
|
+
if (!opts.noPreWake && !has('--no-pre-wake')) {
|
|
499
|
+
const audit = _runPreWakeAudit(root);
|
|
500
|
+
_saveAndAppendPreWakeReport(root, audit);
|
|
501
|
+
const sum = audit.summary;
|
|
502
|
+
if (sum.criticalCount > 0) {
|
|
503
|
+
log(red(` 🚨 pre-wake-audit: critical ${sum.criticalCount} (다음 깨어남 시 점검 필요)`));
|
|
504
|
+
} else if (sum.warningCount > 0) {
|
|
505
|
+
log(yel(` ⚠ pre-wake-audit: warning ${sum.warningCount}`));
|
|
506
|
+
} else {
|
|
507
|
+
log(grn(` ✓ pre-wake-audit: clean (sleep 안전)`));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
} catch {}
|
|
511
|
+
// 1.9.212
|
|
512
|
+
try {
|
|
513
|
+
const idemp = _runIdempotencyAudit(root);
|
|
514
|
+
const v = idemp.summary.totalViolations;
|
|
515
|
+
if (v > 0) {
|
|
516
|
+
log(red(` ⚠ 멱등성 위반 ${v}건 (high: ${idemp.summary.highSeverity})`));
|
|
517
|
+
log(dim(` → leerness idempotency audit 으로 상세 확인`));
|
|
518
|
+
} else {
|
|
519
|
+
log(grn(` ✓ 멱등성 검사 통과 — verified ${idemp.summary.verifiedAreas} 영역`));
|
|
520
|
+
}
|
|
521
|
+
} catch {}
|
|
522
|
+
// 1.9.264: 셸 실패 메모리 + 환경 변동 요약 (UR-0020) — 마감 시 이번 세션 셸 실패를 회고에 노출
|
|
523
|
+
try {
|
|
524
|
+
const sf = _loadShellFailures(root);
|
|
525
|
+
const drift = _shellEnvDrift(root);
|
|
526
|
+
const driftN = drift && drift.changes ? drift.changes.length : 0;
|
|
527
|
+
if (sf.failures.length > 0 || driftN > 0) {
|
|
528
|
+
if (driftN > 0) log(yel(` ⚠ 환경 버전 변동 ${driftN}건 — 다음 세션 셸 실패 기록 재검토 권장`));
|
|
529
|
+
if (sf.failures.length > 0) {
|
|
530
|
+
log(yel(` 🐚 셸 실패 누적 ${sf.failures.length}건 — 다음 handoff 가 자동 노출`));
|
|
531
|
+
log(dim(` → 명령 실행 전 점검: leerness shell-guard "<command>"`));
|
|
532
|
+
}
|
|
533
|
+
} else {
|
|
534
|
+
log(grn(` ✓ 셸 실패 기록 없음 (터미널 호환성 양호)`));
|
|
535
|
+
}
|
|
536
|
+
} catch {}
|
|
537
|
+
// 1.9.237: session close --auto-cleanup-branches — 50+ release/* branches 시 자동 정리
|
|
538
|
+
// 1.9.224 패턴 (--auto-apply-delivered) 확장 — 마감 시 운영 누적 폐기물 자동 정리
|
|
539
|
+
// 안전: keep 10, merged 만, 현재 branch 보호
|
|
540
|
+
try {
|
|
541
|
+
const branchR = cp.spawnSync('git', ['branch', '--merged', 'main', '--list', 'release/*'], { cwd: root, encoding: 'utf8' });
|
|
542
|
+
if (branchR.status === 0) {
|
|
543
|
+
const merged = (branchR.stdout || '').split('\n')
|
|
544
|
+
.map(l => l.replace(/^\*?\s+/, '').trim())
|
|
545
|
+
.filter(l => l && /^release\/\d+\.\d+\.\d+$/.test(l));
|
|
546
|
+
if (merged.length > 50) {
|
|
547
|
+
if (has('--auto-cleanup-branches')) {
|
|
548
|
+
merged.sort((a, b) => {
|
|
549
|
+
const va = a.replace('release/', '').split('.').map(n => parseInt(n, 10) || 0);
|
|
550
|
+
const vb = b.replace('release/', '').split('.').map(n => parseInt(n, 10) || 0);
|
|
551
|
+
for (let i = 0; i < 3; i++) if (va[i] !== vb[i]) return vb[i] - va[i];
|
|
552
|
+
return 0;
|
|
553
|
+
});
|
|
554
|
+
const curR = cp.spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: root, encoding: 'utf8' });
|
|
555
|
+
const cur = (curR.stdout || '').trim();
|
|
556
|
+
const toDelete = merged.slice(10).filter(b => b !== cur);
|
|
557
|
+
let okCnt = 0;
|
|
558
|
+
for (const b of toDelete) {
|
|
559
|
+
const r = cp.spawnSync('git', ['branch', '-d', b], { cwd: root, encoding: 'utf8' });
|
|
560
|
+
if (r.status === 0) okCnt++;
|
|
561
|
+
}
|
|
562
|
+
log(grn(` ✓ release 정리 ${okCnt}/${toDelete.length}건 (--auto-cleanup-branches 1.9.237, keep 10)`));
|
|
563
|
+
} else {
|
|
564
|
+
log(yel(` 🗑 release/* merged ${merged.length}개 (50+) — cleanup 가능 (1.9.235)`));
|
|
565
|
+
log(dim(` → leerness release cleanup --apply --keep 10 (수동)`));
|
|
566
|
+
log(dim(` → 또는 session close --auto-cleanup-branches (1.9.237 자동)`));
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
} catch {}
|
|
571
|
+
// 1.9.243: session close --auto-fix-encoding — 셸 스크립트 인코딩 위험 자동 회복 (UR-0014 3단계)
|
|
572
|
+
// 1.9.224 (--auto-apply-delivered) / 1.9.237 (--auto-cleanup-branches) 패턴 확장
|
|
573
|
+
// 마감 시 한국어/일본어/중국어 PowerShell 인코딩 위험 자동 BOM 추가
|
|
574
|
+
try {
|
|
575
|
+
const encScan = _scanShellScriptsEncoding(root);
|
|
576
|
+
if (encScan.atRisk && encScan.atRisk.length > 0) {
|
|
577
|
+
if (has('--auto-fix-encoding')) {
|
|
578
|
+
let ok = 0;
|
|
579
|
+
for (const r of encScan.atRisk) {
|
|
580
|
+
try {
|
|
581
|
+
const fullPath = path.join(root, r.file);
|
|
582
|
+
const orig = fs.readFileSync(fullPath);
|
|
583
|
+
const bom = Buffer.from([0xEF, 0xBB, 0xBF]);
|
|
584
|
+
const fixed = Buffer.concat([bom, orig]);
|
|
585
|
+
fs.writeFileSync(fullPath, fixed);
|
|
586
|
+
ok++;
|
|
587
|
+
} catch {}
|
|
588
|
+
}
|
|
589
|
+
log(grn(` ✓ 인코딩 위험 ${ok}/${encScan.atRisk.length}건 UTF-8 BOM 자동 추가 (--auto-fix-encoding 1.9.243)`));
|
|
590
|
+
} else {
|
|
591
|
+
log(yel(` ⚠ 셸 스크립트 인코딩 위험 ${encScan.atRisk.length}건 (1.9.241) — 자동 회복 가능`));
|
|
592
|
+
log(dim(` → leerness env encoding --apply (수동) 또는 session close --auto-fix-encoding (1.9.243 자동)`));
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
} catch {}
|
|
596
|
+
// 1.9.232: 마감 시 pulse 한 줄 자동 노출 — 다음 라운드 진입 시 즉시 상태 인지
|
|
597
|
+
try {
|
|
598
|
+
const rh = _computeRoundHistory(root);
|
|
599
|
+
const ms = _computeMilestones(root);
|
|
600
|
+
const rows = readProgressRows(root);
|
|
601
|
+
const tIn = rows.filter(r => r.status === 'in-progress').length;
|
|
602
|
+
const dCnt = _loadDecisions(root).length; // 1.9.339 (UR-0053): canonical 단일 진실소스
|
|
603
|
+
const rActive = readRules(root).filter(r => r.status === 'active').length;
|
|
604
|
+
const planText = exists(planPath(root)) ? read(planPath(root)) : '';
|
|
605
|
+
const pCnt = (planText.match(/^### M-\d{4}\./gm) || []).length;
|
|
606
|
+
const lCnt = _loadLessons(root).length;
|
|
607
|
+
const mem = `T${tIn}/D${dCnt}/R${rActive}/P${pCnt}/L${lCnt}`;
|
|
608
|
+
let pulseLine = `📍 v${VERSION} · 🔄 R${rh.roundCount} · 🧠 ${mem}`;
|
|
609
|
+
if (ms.next) {
|
|
610
|
+
const eta = ms.next.etaDays != null ? ` (${ms.next.etaDays}d)` : '';
|
|
611
|
+
pulseLine += ` · 🎯 R${ms.next.milestone}${eta}`;
|
|
612
|
+
}
|
|
613
|
+
log('');
|
|
614
|
+
log(` ${pulseLine} ${dim('— leerness pulse (1.9.232)')}`);
|
|
615
|
+
} catch {}
|
|
616
|
+
} catch {}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
module.exports = { sessionClose };
|