triflux 7.1.4 → 7.2.1
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/.claude-plugin/marketplace.json +31 -31
- package/.claude-plugin/plugin.json +22 -23
- package/bin/triflux.mjs +18 -5
- package/hooks/keyword-rules.json +393 -361
- package/hub/bridge.mjs +799 -786
- package/hub/delegator/contracts.mjs +37 -38
- package/hub/delegator/schema/delegator-tools.schema.json +250 -250
- package/hub/delegator/service.mjs +307 -302
- package/hub/intent.mjs +108 -11
- package/hub/lib/process-utils.mjs +20 -0
- package/hub/pipe.mjs +589 -589
- package/hub/pipeline/gates/confidence.mjs +1 -1
- package/hub/pipeline/gates/selfcheck.mjs +2 -4
- package/hub/pipeline/state.mjs +191 -187
- package/hub/pipeline/transitions.mjs +124 -120
- package/hub/public/dashboard.html +355 -349
- package/hub/quality/deslop.mjs +5 -3
- package/hub/reflexion.mjs +5 -1
- package/hub/research.mjs +6 -1
- package/hub/router.mjs +791 -782
- package/hub/server.mjs +893 -822
- package/hub/store.mjs +807 -778
- package/hub/team/agent-map.json +10 -0
- package/hub/team/ansi.mjs +3 -4
- package/hub/team/cli/commands/control.mjs +43 -43
- package/hub/team/cli/commands/interrupt.mjs +36 -36
- package/hub/team/cli/commands/kill.mjs +3 -3
- package/hub/team/cli/commands/send.mjs +37 -37
- package/hub/team/cli/commands/start/index.mjs +18 -8
- package/hub/team/cli/commands/start/parse-args.mjs +3 -1
- package/hub/team/cli/commands/start/start-headless.mjs +4 -1
- package/hub/team/cli/commands/status.mjs +87 -87
- package/hub/team/cli/commands/stop.mjs +1 -1
- package/hub/team/cli/commands/task.mjs +1 -1
- package/hub/team/cli/index.mjs +41 -39
- package/hub/team/cli/manifest.mjs +29 -28
- package/hub/team/cli/services/hub-client.mjs +37 -0
- package/hub/team/cli/services/state-store.mjs +26 -12
- package/hub/team/dashboard.mjs +11 -4
- package/hub/team/handoff.mjs +12 -0
- package/hub/team/headless.mjs +202 -200
- package/hub/team/native-supervisor.mjs +386 -346
- package/hub/team/nativeProxy.mjs +680 -692
- package/hub/team/staleState.mjs +361 -369
- package/hub/team/tui-viewer.mjs +27 -3
- package/hub/team/tui.mjs +1 -0
- package/hub/token-mode.mjs +114 -24
- package/hub/workers/delegator-mcp.mjs +1059 -1057
- package/hud/colors.mjs +88 -0
- package/hud/constants.mjs +78 -0
- package/hud/hud-qos-status.mjs +206 -1872
- package/hud/providers/claude.mjs +309 -0
- package/hud/providers/codex.mjs +151 -0
- package/hud/providers/gemini.mjs +320 -0
- package/hud/renderers.mjs +424 -0
- package/hud/terminal.mjs +140 -0
- package/hud/utils.mjs +271 -0
- package/package.json +1 -2
- package/scripts/__tests__/keyword-detector.test.mjs +234 -234
- package/scripts/headless-guard-fast.sh +21 -0
- package/scripts/headless-guard.mjs +26 -6
- package/scripts/lib/keyword-rules.mjs +166 -168
- package/scripts/setup.mjs +720 -690
- package/scripts/tfx-route-post.mjs +424 -424
- package/scripts/tfx-route.sh +1663 -1650
- package/scripts/tmp-cleanup.mjs +74 -0
- package/skills/tfx-auto/SKILL.md +279 -278
- package/skills/tfx-auto-codex/SKILL.md +98 -77
- package/skills/tfx-codex/SKILL.md +65 -65
- package/skills/tfx-gemini/SKILL.md +83 -82
- package/skills/tfx-hub/SKILL.md +205 -136
- package/skills/tfx-multi/SKILL.md +11 -5
- package/.mcp.json +0 -8
package/scripts/setup.mjs
CHANGED
|
@@ -1,690 +1,720 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// triflux 세션 시작 시 자동 설정 스크립트
|
|
3
|
-
// - tfx-route.sh를 ~/.claude/scripts/에 동기화
|
|
4
|
-
// - hud-qos-status.mjs를 ~/.claude/hud/에 동기화
|
|
5
|
-
// - skills/를 ~/.claude/skills/에 동기화
|
|
6
|
-
|
|
7
|
-
import { copyFileSync, mkdirSync, readFileSync, writeFileSync, readdirSync, existsSync, chmodSync, unlinkSync } from "fs";
|
|
8
|
-
import { join, dirname } from "path";
|
|
9
|
-
import { homedir } from "os";
|
|
10
|
-
import { spawn, execFileSync } from "child_process";
|
|
11
|
-
import { fileURLToPath } from "url";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
//
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (
|
|
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
|
-
const
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
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
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// triflux 세션 시작 시 자동 설정 스크립트
|
|
3
|
+
// - tfx-route.sh를 ~/.claude/scripts/에 동기화
|
|
4
|
+
// - hud-qos-status.mjs를 ~/.claude/hud/에 동기화
|
|
5
|
+
// - skills/를 ~/.claude/skills/에 동기화
|
|
6
|
+
|
|
7
|
+
import { copyFileSync, mkdirSync, readFileSync, writeFileSync, readdirSync, existsSync, chmodSync, unlinkSync } from "fs";
|
|
8
|
+
import { join, dirname } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
import { spawn, execFileSync } from "child_process";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
import { cleanupTmpFiles } from "./tmp-cleanup.mjs";
|
|
13
|
+
|
|
14
|
+
const PLUGIN_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
15
|
+
const CLAUDE_DIR = join(homedir(), ".claude");
|
|
16
|
+
const CODEX_DIR = join(homedir(), ".codex");
|
|
17
|
+
const CODEX_CONFIG_PATH = join(CODEX_DIR, "config.toml");
|
|
18
|
+
|
|
19
|
+
// ── 로컬 개발 모드 감지 ──
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* PLUGIN_ROOT에 .git 디렉토리가 존재하면 dev mode (git clone 직접 사용)로 판정.
|
|
23
|
+
* @param {string} [root] - 검사할 루트 경로 (기본: PLUGIN_ROOT)
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
function detectDevMode(root = PLUGIN_ROOT) {
|
|
27
|
+
return existsSync(join(root, ".git"));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const BREADCRUMB_PATH = join(CLAUDE_DIR, "scripts", ".tfx-pkg-root");
|
|
31
|
+
|
|
32
|
+
const REQUIRED_CODEX_PROFILES = [
|
|
33
|
+
{
|
|
34
|
+
name: "high",
|
|
35
|
+
lines: [
|
|
36
|
+
'model = "gpt-5.3-codex"',
|
|
37
|
+
'model_reasoning_effort = "high"',
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "xhigh",
|
|
42
|
+
lines: [
|
|
43
|
+
'model = "gpt-5.3-codex"',
|
|
44
|
+
'model_reasoning_effort = "xhigh"',
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "spark_fast",
|
|
49
|
+
lines: [
|
|
50
|
+
'model = "gpt-5.1-codex-mini"',
|
|
51
|
+
'model_reasoning_effort = "low"',
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
// ── 파일 동기화 ──
|
|
57
|
+
|
|
58
|
+
const SYNC_MAP = [
|
|
59
|
+
{
|
|
60
|
+
src: join(PLUGIN_ROOT, "scripts", "tfx-route.sh"),
|
|
61
|
+
dst: join(CLAUDE_DIR, "scripts", "tfx-route.sh"),
|
|
62
|
+
label: "tfx-route.sh",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
src: join(PLUGIN_ROOT, "scripts", "tfx-route-post.mjs"),
|
|
66
|
+
dst: join(CLAUDE_DIR, "scripts", "tfx-route-post.mjs"),
|
|
67
|
+
label: "tfx-route-post.mjs",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
src: join(PLUGIN_ROOT, "scripts", "tfx-route-worker.mjs"),
|
|
71
|
+
dst: join(CLAUDE_DIR, "scripts", "tfx-route-worker.mjs"),
|
|
72
|
+
label: "tfx-route-worker.mjs",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
src: join(PLUGIN_ROOT, "hub", "workers", "codex-mcp.mjs"),
|
|
76
|
+
dst: join(CLAUDE_DIR, "scripts", "hub", "workers", "codex-mcp.mjs"),
|
|
77
|
+
label: "hub/workers/codex-mcp.mjs",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
src: join(PLUGIN_ROOT, "hub", "workers", "delegator-mcp.mjs"),
|
|
81
|
+
dst: join(CLAUDE_DIR, "scripts", "hub", "workers", "delegator-mcp.mjs"),
|
|
82
|
+
label: "hub/workers/delegator-mcp.mjs",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
src: join(PLUGIN_ROOT, "hub", "workers", "interface.mjs"),
|
|
86
|
+
dst: join(CLAUDE_DIR, "scripts", "hub", "workers", "interface.mjs"),
|
|
87
|
+
label: "hub/workers/interface.mjs",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
src: join(PLUGIN_ROOT, "hub", "workers", "gemini-worker.mjs"),
|
|
91
|
+
dst: join(CLAUDE_DIR, "scripts", "hub", "workers", "gemini-worker.mjs"),
|
|
92
|
+
label: "hub/workers/gemini-worker.mjs",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
src: join(PLUGIN_ROOT, "hub", "workers", "claude-worker.mjs"),
|
|
96
|
+
dst: join(CLAUDE_DIR, "scripts", "hub", "workers", "claude-worker.mjs"),
|
|
97
|
+
label: "hub/workers/claude-worker.mjs",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
src: join(PLUGIN_ROOT, "hub", "workers", "factory.mjs"),
|
|
101
|
+
dst: join(CLAUDE_DIR, "scripts", "hub", "workers", "factory.mjs"),
|
|
102
|
+
label: "hub/workers/factory.mjs",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
src: join(PLUGIN_ROOT, "hud", "hud-qos-status.mjs"),
|
|
106
|
+
dst: join(CLAUDE_DIR, "hud", "hud-qos-status.mjs"),
|
|
107
|
+
label: "hud-qos-status.mjs",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
src: join(PLUGIN_ROOT, "hud", "colors.mjs"),
|
|
111
|
+
dst: join(CLAUDE_DIR, "hud", "colors.mjs"),
|
|
112
|
+
label: "hud/colors.mjs",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
src: join(PLUGIN_ROOT, "hud", "constants.mjs"),
|
|
116
|
+
dst: join(CLAUDE_DIR, "hud", "constants.mjs"),
|
|
117
|
+
label: "hud/constants.mjs",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
src: join(PLUGIN_ROOT, "hud", "terminal.mjs"),
|
|
121
|
+
dst: join(CLAUDE_DIR, "hud", "terminal.mjs"),
|
|
122
|
+
label: "hud/terminal.mjs",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
src: join(PLUGIN_ROOT, "hud", "utils.mjs"),
|
|
126
|
+
dst: join(CLAUDE_DIR, "hud", "utils.mjs"),
|
|
127
|
+
label: "hud/utils.mjs",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
src: join(PLUGIN_ROOT, "hud", "renderers.mjs"),
|
|
131
|
+
dst: join(CLAUDE_DIR, "hud", "renderers.mjs"),
|
|
132
|
+
label: "hud/renderers.mjs",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
src: join(PLUGIN_ROOT, "hud", "providers", "claude.mjs"),
|
|
136
|
+
dst: join(CLAUDE_DIR, "hud", "providers", "claude.mjs"),
|
|
137
|
+
label: "hud/providers/claude.mjs",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
src: join(PLUGIN_ROOT, "hud", "providers", "codex.mjs"),
|
|
141
|
+
dst: join(CLAUDE_DIR, "hud", "providers", "codex.mjs"),
|
|
142
|
+
label: "hud/providers/codex.mjs",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
src: join(PLUGIN_ROOT, "hud", "providers", "gemini.mjs"),
|
|
146
|
+
dst: join(CLAUDE_DIR, "hud", "providers", "gemini.mjs"),
|
|
147
|
+
label: "hud/providers/gemini.mjs",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
src: join(PLUGIN_ROOT, "scripts", "notion-read.mjs"),
|
|
151
|
+
dst: join(CLAUDE_DIR, "scripts", "notion-read.mjs"),
|
|
152
|
+
label: "notion-read.mjs",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
src: join(PLUGIN_ROOT, "scripts", "tfx-batch-stats.mjs"),
|
|
156
|
+
dst: join(CLAUDE_DIR, "scripts", "tfx-batch-stats.mjs"),
|
|
157
|
+
label: "tfx-batch-stats.mjs",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
src: join(PLUGIN_ROOT, "scripts", "lib", "mcp-filter.mjs"),
|
|
161
|
+
dst: join(CLAUDE_DIR, "scripts", "lib", "mcp-filter.mjs"),
|
|
162
|
+
label: "lib/mcp-filter.mjs",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
src: join(PLUGIN_ROOT, "scripts", "lib", "mcp-server-catalog.mjs"),
|
|
166
|
+
dst: join(CLAUDE_DIR, "scripts", "lib", "mcp-server-catalog.mjs"),
|
|
167
|
+
label: "lib/mcp-server-catalog.mjs",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
src: join(PLUGIN_ROOT, "scripts", "lib", "keyword-rules.mjs"),
|
|
171
|
+
dst: join(CLAUDE_DIR, "scripts", "lib", "keyword-rules.mjs"),
|
|
172
|
+
label: "lib/keyword-rules.mjs",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
src: join(PLUGIN_ROOT, "scripts", "headless-guard.mjs"),
|
|
176
|
+
dst: join(CLAUDE_DIR, "scripts", "headless-guard.mjs"),
|
|
177
|
+
label: "headless-guard.mjs",
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
src: join(PLUGIN_ROOT, "scripts", "headless-guard-fast.sh"),
|
|
181
|
+
dst: join(CLAUDE_DIR, "scripts", "headless-guard-fast.sh"),
|
|
182
|
+
label: "headless-guard-fast.sh",
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
function getVersion(filePath) {
|
|
187
|
+
try {
|
|
188
|
+
const content = readFileSync(filePath, "utf8");
|
|
189
|
+
const match = content.match(/VERSION\s*=\s*"([^"]+)"/);
|
|
190
|
+
return match ? match[1] : null;
|
|
191
|
+
} catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function shouldSyncTextFile(src, dst) {
|
|
197
|
+
if (!existsSync(dst)) return true;
|
|
198
|
+
try {
|
|
199
|
+
return readFileSync(src, "utf8") !== readFileSync(dst, "utf8");
|
|
200
|
+
} catch {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function escapeRegExp(value) {
|
|
206
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function hasProfileSection(tomlContent, profileName) {
|
|
210
|
+
const section = `^\\[profiles\\.${escapeRegExp(profileName)}\\]\\s*$`;
|
|
211
|
+
return new RegExp(section, "m").test(tomlContent);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function replaceProfileSection(tomlContent, profileName, lines) {
|
|
215
|
+
const header = `[profiles.${profileName}]`;
|
|
216
|
+
const sectionRe = new RegExp(
|
|
217
|
+
`^\\[profiles\\.${escapeRegExp(profileName)}\\]\\s*\\n?(?:(?!\\[)[^\\n]*\\n?)*`,
|
|
218
|
+
"m",
|
|
219
|
+
);
|
|
220
|
+
const replacement = `${header}\n${lines.join("\n")}\n`;
|
|
221
|
+
return tomlContent.replace(sectionRe, replacement);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function ensureCodexProfiles() {
|
|
225
|
+
try {
|
|
226
|
+
if (!existsSync(CODEX_DIR)) mkdirSync(CODEX_DIR, { recursive: true });
|
|
227
|
+
|
|
228
|
+
const original = existsSync(CODEX_CONFIG_PATH)
|
|
229
|
+
? readFileSync(CODEX_CONFIG_PATH, "utf8")
|
|
230
|
+
: "";
|
|
231
|
+
|
|
232
|
+
let updated = original;
|
|
233
|
+
let changed = 0;
|
|
234
|
+
|
|
235
|
+
for (const profile of REQUIRED_CODEX_PROFILES) {
|
|
236
|
+
const desired = `[profiles.${profile.name}]\n${profile.lines.join("\n")}\n`;
|
|
237
|
+
|
|
238
|
+
if (hasProfileSection(updated, profile.name)) {
|
|
239
|
+
// 기존 프로필이 있으면 강제 갱신
|
|
240
|
+
const before = updated;
|
|
241
|
+
updated = replaceProfileSection(updated, profile.name, profile.lines);
|
|
242
|
+
if (updated !== before) changed++;
|
|
243
|
+
} else {
|
|
244
|
+
// 없으면 추가
|
|
245
|
+
if (updated.length > 0 && !updated.endsWith("\n")) updated += "\n";
|
|
246
|
+
if (updated.trim().length > 0) updated += "\n";
|
|
247
|
+
updated += desired;
|
|
248
|
+
changed++;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (changed > 0) {
|
|
253
|
+
writeFileSync(CODEX_CONFIG_PATH, updated, "utf8");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return changed;
|
|
257
|
+
} catch {
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export { replaceProfileSection, hasProfileSection, detectDevMode, SYNC_MAP, BREADCRUMB_PATH, PLUGIN_ROOT, CLAUDE_DIR };
|
|
263
|
+
|
|
264
|
+
async function main() {
|
|
265
|
+
const isSync = process.argv.includes("--sync");
|
|
266
|
+
const isDev = detectDevMode();
|
|
267
|
+
|
|
268
|
+
if (isDev) {
|
|
269
|
+
console.log(" [dev] \uB85C\uCEEC \uAC1C\uBC1C \uBAA8\uB4DC \uAC10\uC9C0");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (isSync) {
|
|
273
|
+
console.log(" [sync] \uBA85\uC2DC\uC801 \uC7AC\uB3D9\uAE30\uD654 \uC2E4\uD589");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let synced = 0;
|
|
277
|
+
|
|
278
|
+
for (const { src, dst, label } of SYNC_MAP) {
|
|
279
|
+
if (!existsSync(src)) continue;
|
|
280
|
+
|
|
281
|
+
const dstDir = dirname(dst);
|
|
282
|
+
if (!existsSync(dstDir)) {
|
|
283
|
+
mkdirSync(dstDir, { recursive: true });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (!existsSync(dst)) {
|
|
287
|
+
copyFileSync(src, dst);
|
|
288
|
+
try { chmodSync(dst, 0o755); } catch {}
|
|
289
|
+
synced++;
|
|
290
|
+
} else {
|
|
291
|
+
if (shouldSyncTextFile(src, dst)) {
|
|
292
|
+
copyFileSync(src, dst);
|
|
293
|
+
try { chmodSync(dst, 0o755); } catch {}
|
|
294
|
+
synced++;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ── Worker 의존성 동기화 (MCP SDK + transitive deps) ──
|
|
300
|
+
|
|
301
|
+
const workerNodeModules = join(CLAUDE_DIR, "scripts", "node_modules");
|
|
302
|
+
const mcpSdkPath = join(workerNodeModules, "@modelcontextprotocol", "sdk");
|
|
303
|
+
const srcNodeModules = join(PLUGIN_ROOT, "node_modules");
|
|
304
|
+
|
|
305
|
+
// native 모듈은 제외 (플랫폼 의존적, worker에서 불필요)
|
|
306
|
+
const SKIP_PACKAGES = new Set(["better-sqlite3", "prebuild-install", "node-abi", "node-addon-api"]);
|
|
307
|
+
|
|
308
|
+
if (!existsSync(mcpSdkPath) && existsSync(srcNodeModules)) {
|
|
309
|
+
try {
|
|
310
|
+
const { cpSync } = await import("fs");
|
|
311
|
+
for (const entry of readdirSync(srcNodeModules)) {
|
|
312
|
+
if (SKIP_PACKAGES.has(entry)) continue;
|
|
313
|
+
|
|
314
|
+
const src = join(srcNodeModules, entry);
|
|
315
|
+
const dst = join(workerNodeModules, entry);
|
|
316
|
+
if (existsSync(dst)) continue;
|
|
317
|
+
|
|
318
|
+
mkdirSync(dirname(dst), { recursive: true });
|
|
319
|
+
cpSync(src, dst, { recursive: true });
|
|
320
|
+
}
|
|
321
|
+
synced++;
|
|
322
|
+
} catch {
|
|
323
|
+
// best effort: 의존성 복사 실패 시 exec fallback으로 동작
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ── 패키지 루트 breadcrumb 기록 ──
|
|
328
|
+
// tfx-route.sh가 hub/server.mjs, hub/bridge.mjs를 찾을 수 있도록
|
|
329
|
+
// 패키지 루트 경로를 ~/.claude/scripts/.tfx-pkg-root에 기록한다.
|
|
330
|
+
// dev mode에서는 항상 최신 경로를 기록 (--sync 시 강제 갱신).
|
|
331
|
+
{
|
|
332
|
+
const pkgRootForward = PLUGIN_ROOT.replace(/\\/g, "/");
|
|
333
|
+
const currentBreadcrumb = existsSync(BREADCRUMB_PATH)
|
|
334
|
+
? readFileSync(BREADCRUMB_PATH, "utf8").trim()
|
|
335
|
+
: "";
|
|
336
|
+
if (currentBreadcrumb !== pkgRootForward || isSync) {
|
|
337
|
+
const breadcrumbDir = dirname(BREADCRUMB_PATH);
|
|
338
|
+
if (!existsSync(breadcrumbDir)) mkdirSync(breadcrumbDir, { recursive: true });
|
|
339
|
+
writeFileSync(BREADCRUMB_PATH, pkgRootForward + "\n", "utf8");
|
|
340
|
+
synced++;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ── 에이전트 동기화 (.claude/agents/ → ~/.claude/agents/) ──
|
|
345
|
+
// slim-wrapper 등 커스텀 에이전트를 글로벌에 배포하여
|
|
346
|
+
// 다른 프로젝트에서도 subagent_type으로 참조 가능하게 한다.
|
|
347
|
+
|
|
348
|
+
const agentsSrc = join(PLUGIN_ROOT, ".claude", "agents");
|
|
349
|
+
const agentsDst = join(CLAUDE_DIR, "agents");
|
|
350
|
+
|
|
351
|
+
if (existsSync(agentsSrc)) {
|
|
352
|
+
if (!existsSync(agentsDst)) mkdirSync(agentsDst, { recursive: true });
|
|
353
|
+
|
|
354
|
+
for (const name of readdirSync(agentsSrc)) {
|
|
355
|
+
if (!name.endsWith(".md")) continue;
|
|
356
|
+
|
|
357
|
+
const src = join(agentsSrc, name);
|
|
358
|
+
const dst = join(agentsDst, name);
|
|
359
|
+
|
|
360
|
+
if (!existsSync(dst)) {
|
|
361
|
+
copyFileSync(src, dst);
|
|
362
|
+
synced++;
|
|
363
|
+
} else if (shouldSyncTextFile(src, dst)) {
|
|
364
|
+
copyFileSync(src, dst);
|
|
365
|
+
synced++;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// ── 스킬 동기화 ──
|
|
371
|
+
// SKILL.md + 하위 디렉토리(references/ 등)를 재귀적으로 동기화
|
|
372
|
+
|
|
373
|
+
const skillsSrc = join(PLUGIN_ROOT, "skills");
|
|
374
|
+
const skillsDst = join(CLAUDE_DIR, "skills");
|
|
375
|
+
|
|
376
|
+
function syncSkillDir(srcDir, dstDir) {
|
|
377
|
+
if (!existsSync(dstDir)) mkdirSync(dstDir, { recursive: true });
|
|
378
|
+
|
|
379
|
+
let count = 0;
|
|
380
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
381
|
+
const srcPath = join(srcDir, entry.name);
|
|
382
|
+
const dstPath = join(dstDir, entry.name);
|
|
383
|
+
|
|
384
|
+
if (entry.isDirectory()) {
|
|
385
|
+
count += syncSkillDir(srcPath, dstPath);
|
|
386
|
+
} else if (entry.name.endsWith(".md")) {
|
|
387
|
+
if (shouldSyncTextFile(srcPath, dstPath)) {
|
|
388
|
+
copyFileSync(srcPath, dstPath);
|
|
389
|
+
count++;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return count;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (existsSync(skillsSrc)) {
|
|
397
|
+
for (const name of readdirSync(skillsSrc)) {
|
|
398
|
+
const skillDir = join(skillsSrc, name);
|
|
399
|
+
const skillMd = join(skillDir, "SKILL.md");
|
|
400
|
+
if (!existsSync(skillMd)) continue;
|
|
401
|
+
|
|
402
|
+
synced += syncSkillDir(skillDir, join(skillsDst, name));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// ── settings.json 통합 R/W ──
|
|
407
|
+
// 3개 섹션(statusLine, agentTeams, hooks)을 1회 read → 일괄 수정 → 1회 write
|
|
408
|
+
|
|
409
|
+
const settingsPath = join(CLAUDE_DIR, "settings.json");
|
|
410
|
+
const hudPath = join(CLAUDE_DIR, "hud", "hud-qos-status.mjs");
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* statusLine 섹션 적용.
|
|
414
|
+
* @param {object} s - settings 객체 (직접 변경)
|
|
415
|
+
* @returns {boolean} 변경 여부
|
|
416
|
+
*/
|
|
417
|
+
function applyStatusLine(s) {
|
|
418
|
+
if (!existsSync(hudPath)) return false;
|
|
419
|
+
const currentCmd = s.statusLine?.command || "";
|
|
420
|
+
if (currentCmd.includes("hud-qos-status.mjs")) return false;
|
|
421
|
+
|
|
422
|
+
const nodePath = process.execPath.replace(/\\/g, "/");
|
|
423
|
+
const hudForward = hudPath.replace(/\\/g, "/");
|
|
424
|
+
const nodeRef = nodePath.includes(" ") ? `"${nodePath}"` : nodePath;
|
|
425
|
+
const hudRef = hudForward.includes(" ") ? `"${hudForward}"` : hudForward;
|
|
426
|
+
|
|
427
|
+
s.statusLine = { type: "command", command: `${nodeRef} ${hudRef}` };
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Agent Teams 환경변수 섹션 적용.
|
|
433
|
+
* @param {object} s - settings 객체 (직접 변경)
|
|
434
|
+
* @returns {boolean} 변경 여부
|
|
435
|
+
*/
|
|
436
|
+
function applyAgentTeams(s) {
|
|
437
|
+
if (!s.env) s.env = {};
|
|
438
|
+
let changed = false;
|
|
439
|
+
|
|
440
|
+
if (s.env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS !== "1") {
|
|
441
|
+
s.env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS = "1";
|
|
442
|
+
changed = true;
|
|
443
|
+
}
|
|
444
|
+
// teammateMode: auto (tmux 밖이면 in-process, 안이면 split-pane)
|
|
445
|
+
if (!s.teammateMode) {
|
|
446
|
+
s.teammateMode = "auto";
|
|
447
|
+
changed = true;
|
|
448
|
+
}
|
|
449
|
+
return changed;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* SessionStart + PreToolUse 훅 섹션 적용.
|
|
454
|
+
* @param {object} s - settings 객체 (직접 변경)
|
|
455
|
+
* @returns {boolean} 변경 여부
|
|
456
|
+
*/
|
|
457
|
+
function applyHooks(s) {
|
|
458
|
+
if (!s.hooks) s.hooks = {};
|
|
459
|
+
let changed = false;
|
|
460
|
+
|
|
461
|
+
// ── SessionStart 훅 ──
|
|
462
|
+
if (!Array.isArray(s.hooks.SessionStart)) s.hooks.SessionStart = [];
|
|
463
|
+
|
|
464
|
+
const hasTrifluxHooks = s.hooks.SessionStart.some((entry) =>
|
|
465
|
+
Array.isArray(entry.hooks) &&
|
|
466
|
+
entry.hooks.some((h) => typeof h.command === "string" && h.command.includes("triflux")),
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
if (!hasTrifluxHooks) {
|
|
470
|
+
const nodePath = process.execPath.replace(/\\/g, "/");
|
|
471
|
+
const nodeRef = nodePath.includes(" ") ? `"${nodePath}"` : nodePath;
|
|
472
|
+
const pluginRoot = PLUGIN_ROOT.replace(/\\/g, "/");
|
|
473
|
+
|
|
474
|
+
s.hooks.SessionStart.push({
|
|
475
|
+
matcher: "*",
|
|
476
|
+
hooks: [
|
|
477
|
+
{
|
|
478
|
+
type: "command",
|
|
479
|
+
command: `${nodeRef} "${pluginRoot}/scripts/setup.mjs"`,
|
|
480
|
+
timeout: 10,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
type: "command",
|
|
484
|
+
command: `${nodeRef} "${pluginRoot}/scripts/hub-ensure.mjs"`,
|
|
485
|
+
timeout: 8,
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
type: "command",
|
|
489
|
+
command: `${nodeRef} "${pluginRoot}/scripts/preflight-cache.mjs"`,
|
|
490
|
+
timeout: 5,
|
|
491
|
+
},
|
|
492
|
+
],
|
|
493
|
+
});
|
|
494
|
+
changed = true;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// ── PreToolUse 훅: headless-guard (auto-route) ──
|
|
498
|
+
if (!Array.isArray(s.hooks.PreToolUse)) s.hooks.PreToolUse = [];
|
|
499
|
+
|
|
500
|
+
const guardScriptPath = join(CLAUDE_DIR, "scripts", "headless-guard-fast.sh").replace(/\\/g, "/");
|
|
501
|
+
const hasGuardHook = s.hooks.PreToolUse.some((entry) =>
|
|
502
|
+
Array.isArray(entry.hooks) &&
|
|
503
|
+
entry.hooks.some((h) => typeof h.command === "string" && h.command.includes("headless-guard")),
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
if (!hasGuardHook && existsSync(guardScriptPath.replace(/\//g, "\\"))) {
|
|
507
|
+
s.hooks.PreToolUse.push({
|
|
508
|
+
matcher: "Bash|Agent",
|
|
509
|
+
hooks: [
|
|
510
|
+
{
|
|
511
|
+
type: "command",
|
|
512
|
+
command: `bash "${guardScriptPath}"`,
|
|
513
|
+
timeout: 3,
|
|
514
|
+
},
|
|
515
|
+
],
|
|
516
|
+
});
|
|
517
|
+
changed = true;
|
|
518
|
+
} else if (hasGuardHook) {
|
|
519
|
+
// 기존 훅 경로를 동기화된 경로로 업데이트
|
|
520
|
+
for (const entry of s.hooks.PreToolUse) {
|
|
521
|
+
if (!Array.isArray(entry.hooks)) continue;
|
|
522
|
+
for (const h of entry.hooks) {
|
|
523
|
+
if (typeof h.command === "string" && h.command.includes("headless-guard") && !h.command.includes(guardScriptPath)) {
|
|
524
|
+
h.command = `bash "${guardScriptPath}"`;
|
|
525
|
+
changed = true;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return changed;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// 1회 읽기
|
|
535
|
+
let settings = {};
|
|
536
|
+
if (existsSync(settingsPath)) {
|
|
537
|
+
try { settings = JSON.parse(readFileSync(settingsPath, "utf8")); } catch { /* 기존 설정 보존 */ }
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// 3개 섹션 일괄 수정 (각각 try-catch로 독립 실행)
|
|
541
|
+
let settingsChanged = false;
|
|
542
|
+
try { if (applyStatusLine(settings)) { settingsChanged = true; synced++; } } catch {}
|
|
543
|
+
try { if (applyAgentTeams(settings)) { settingsChanged = true; synced++; } } catch {}
|
|
544
|
+
try { if (applyHooks(settings)) { settingsChanged = true; synced++; } } catch {}
|
|
545
|
+
|
|
546
|
+
// 1회 쓰기
|
|
547
|
+
if (settingsChanged) {
|
|
548
|
+
try {
|
|
549
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf8");
|
|
550
|
+
} catch {
|
|
551
|
+
// settings.json 쓰기 실패 시 무시
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// ── Stale PID 파일 정리 (hub 좀비 방지) ──
|
|
556
|
+
|
|
557
|
+
const HUB_PID_FILE = join(CLAUDE_DIR, "cache", "tfx-hub", "hub.pid");
|
|
558
|
+
if (existsSync(HUB_PID_FILE)) {
|
|
559
|
+
try {
|
|
560
|
+
const pidInfo = JSON.parse(readFileSync(HUB_PID_FILE, "utf8"));
|
|
561
|
+
process.kill(pidInfo.pid, 0); // 프로세스 존재 확인 (신호 미전송)
|
|
562
|
+
} catch {
|
|
563
|
+
try { unlinkSync(HUB_PID_FILE); } catch {} // 죽은 프로세스면 PID 파일 삭제
|
|
564
|
+
synced++;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ── psmux 자동 설치 (Windows, headless 모드용) ──
|
|
569
|
+
|
|
570
|
+
if (process.platform === "win32") {
|
|
571
|
+
try {
|
|
572
|
+
execFileSync("where", ["psmux"], { stdio: "ignore" });
|
|
573
|
+
} catch {
|
|
574
|
+
// psmux 미설치 — winget으로 자동 설치 시도
|
|
575
|
+
console.log(" psmux 미설치 — winget으로 설치 중...");
|
|
576
|
+
try {
|
|
577
|
+
execFileSync("winget", ["install", "--id", "marlocarlo.psmux", "--accept-package-agreements", "--accept-source-agreements"], {
|
|
578
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
579
|
+
timeout: 60000,
|
|
580
|
+
});
|
|
581
|
+
console.log(" \x1b[32m✓\x1b[0m psmux 설치 완료");
|
|
582
|
+
synced++;
|
|
583
|
+
} catch {
|
|
584
|
+
console.log(" \x1b[33m⚠\x1b[0m psmux 자동 설치 실패 — 수동 설치: winget install psmux");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// ── HUD 에러 캐시 자동 클리어 (업데이트/재설치 시) ──
|
|
590
|
+
|
|
591
|
+
const cacheDir = join(CLAUDE_DIR, "cache");
|
|
592
|
+
const staleFiles = [
|
|
593
|
+
"claude-usage-cache.json",
|
|
594
|
+
".claude-refresh-lock",
|
|
595
|
+
"codex-rate-limits-cache.json",
|
|
596
|
+
];
|
|
597
|
+
|
|
598
|
+
for (const name of staleFiles) {
|
|
599
|
+
const fp = join(cacheDir, name);
|
|
600
|
+
if (!existsSync(fp)) continue;
|
|
601
|
+
try {
|
|
602
|
+
const content = readFileSync(fp, "utf8");
|
|
603
|
+
const parsed = JSON.parse(content);
|
|
604
|
+
// 에러 상태이거나 락 파일이면 삭제 → 새 세션에서 fresh start
|
|
605
|
+
if (parsed.error || name.startsWith(".")) {
|
|
606
|
+
unlinkSync(fp);
|
|
607
|
+
synced++;
|
|
608
|
+
}
|
|
609
|
+
} catch {
|
|
610
|
+
// 파싱 실패 파일도 삭제
|
|
611
|
+
try { unlinkSync(fp); } catch {}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// ── Windows bash PATH 자동 설정 ──
|
|
616
|
+
// Codex/Gemini가 cmd에는 있지만 bash에서 못 찾는 문제 해결
|
|
617
|
+
|
|
618
|
+
if (process.platform === "win32") {
|
|
619
|
+
const npmBin = join(process.env.APPDATA || "", "npm");
|
|
620
|
+
if (existsSync(npmBin)) {
|
|
621
|
+
const bashrcPath = join(homedir(), ".bashrc");
|
|
622
|
+
const pathExport = 'export PATH="$PATH:$APPDATA/npm"';
|
|
623
|
+
let needsUpdate = true;
|
|
624
|
+
|
|
625
|
+
if (existsSync(bashrcPath)) {
|
|
626
|
+
const content = readFileSync(bashrcPath, "utf8");
|
|
627
|
+
if (content.includes("APPDATA/npm") || content.includes("APPDATA\\npm")) {
|
|
628
|
+
needsUpdate = false;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (needsUpdate) {
|
|
633
|
+
const line = `\n# triflux: Codex/Gemini CLI를 bash에서 사용하기 위한 PATH 설정\n${pathExport}\n`;
|
|
634
|
+
try {
|
|
635
|
+
writeFileSync(bashrcPath, (existsSync(bashrcPath) ? readFileSync(bashrcPath, "utf8") : "") + line, "utf8");
|
|
636
|
+
synced++;
|
|
637
|
+
} catch {}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// ── Codex 프로필 자동 보정 ──
|
|
643
|
+
|
|
644
|
+
const codexProfilesAdded = ensureCodexProfiles();
|
|
645
|
+
if (codexProfilesAdded > 0) {
|
|
646
|
+
synced++;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// ── MCP 인벤토리 백그라운드 갱신 ──
|
|
650
|
+
|
|
651
|
+
const mcpCheck = join(PLUGIN_ROOT, "scripts", "mcp-check.mjs");
|
|
652
|
+
if (existsSync(mcpCheck)) {
|
|
653
|
+
const child = spawn(process.execPath, [mcpCheck], {
|
|
654
|
+
detached: true,
|
|
655
|
+
stdio: "ignore",
|
|
656
|
+
windowsHide: true,
|
|
657
|
+
});
|
|
658
|
+
child.unref(); // 부모 프로세스와 분리 — 비동기 실행
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// ── /tmp 임시 파일 자동 정리 (setup 지연 방지: fire-and-forget) ──
|
|
662
|
+
cleanupTmpFiles().catch(() => {});
|
|
663
|
+
|
|
664
|
+
// ── postinstall 배너 (npm install 시에만 출력) ──
|
|
665
|
+
|
|
666
|
+
if (process.env.npm_lifecycle_event === "postinstall") {
|
|
667
|
+
const G = "\x1b[32m";
|
|
668
|
+
const C = "\x1b[36m";
|
|
669
|
+
const Y = "\x1b[33m";
|
|
670
|
+
const D = "\x1b[2m";
|
|
671
|
+
const B = "\x1b[1m";
|
|
672
|
+
const R = "\x1b[0m";
|
|
673
|
+
|
|
674
|
+
const ver = (() => {
|
|
675
|
+
try {
|
|
676
|
+
return JSON.parse(readFileSync(join(PLUGIN_ROOT, "package.json"), "utf8")).version;
|
|
677
|
+
} catch { return "?"; }
|
|
678
|
+
})();
|
|
679
|
+
|
|
680
|
+
console.log(`
|
|
681
|
+
${B}╔═══════════════════════════════════════════════╗${R}
|
|
682
|
+
${B}║${R} ${C}triflux${R} ${D}v${ver}${R} ${B}— Setup Complete${R} ${B}║${R}
|
|
683
|
+
${B}╚═══════════════════════════════════════════════╝${R}
|
|
684
|
+
|
|
685
|
+
${G}✓${R} tfx-route.sh → ~/.claude/scripts/
|
|
686
|
+
${G}✓${R} hud-qos-status → ~/.claude/hud/
|
|
687
|
+
${G}✓${R} ${synced > 0 ? synced + " files synced" : "all files up to date"}
|
|
688
|
+
${G}✓${R} HUD statusLine → settings.json
|
|
689
|
+
|
|
690
|
+
${B}Commands:${R}
|
|
691
|
+
${C}triflux${R} setup 파일 동기화 + HUD 설정
|
|
692
|
+
${C}triflux${R} doctor CLI 진단 (Codex/Gemini 확인)
|
|
693
|
+
${C}triflux${R} list 설치된 스킬 목록
|
|
694
|
+
${C}triflux${R} update 최신 안정 버전으로 업데이트
|
|
695
|
+
${C}triflux${R} update --dev dev 채널로 업데이트 (${D}dev 별칭 지원${R})
|
|
696
|
+
|
|
697
|
+
${B}Shortcuts:${R}
|
|
698
|
+
${C}tfx${R} triflux 축약
|
|
699
|
+
${C}tfx-setup${R} triflux setup
|
|
700
|
+
${C}tfx-doctor${R} triflux doctor
|
|
701
|
+
|
|
702
|
+
${B}Skills (Claude Code):${R}
|
|
703
|
+
${C}/tfx-auto${R} "작업" 자동 분류 + 병렬 실행
|
|
704
|
+
${C}/tfx-auto-codex${R} "작업" Codex 리드 + Gemini 유지
|
|
705
|
+
${C}/tfx-codex${R} "작업" Codex 전용 모드
|
|
706
|
+
${C}/tfx-gemini${R} "작업" Gemini 전용 모드
|
|
707
|
+
${C}/tfx-setup${R} HUD 설정 + 진단
|
|
708
|
+
|
|
709
|
+
${Y}!${R} 세션 재시작 후 스킬이 활성화됩니다
|
|
710
|
+
${D}https://github.com/tellang/triflux${R}
|
|
711
|
+
`);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
process.exit(0);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
718
|
+
main();
|
|
719
|
+
}
|
|
720
|
+
|