@triflux/remote 10.1.0 → 10.26.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/hub/pipe.mjs +239 -121
- package/hub/public/dashboard.html +61 -0
- package/hub/server.mjs +2179 -709
- package/hub/store-adapter.mjs +59 -26
- package/hub/store.mjs +356 -153
- package/hub/team/agent-map.json +26 -7
- package/hub/team/ansi.mjs +245 -146
- package/hub/team/backend.mjs +78 -17
- package/hub/team/build-worker-prompt.mjs +73 -0
- package/hub/team/check-mcp-hub.mjs +49 -0
- package/hub/team/claude-daemon-control.mjs +1130 -0
- package/hub/team/claude-native-bridge.mjs +1011 -0
- package/hub/team/claude-session-projection.mjs +74 -0
- package/hub/team/cli/commands/attach.mjs +57 -37
- package/hub/team/cli/commands/control.mjs +29 -8
- package/hub/team/cli/commands/debug.mjs +95 -74
- package/hub/team/cli/commands/focus.mjs +80 -53
- package/hub/team/cli/commands/interrupt.mjs +18 -6
- package/hub/team/cli/commands/kill.mjs +16 -5
- package/hub/team/cli/commands/list.mjs +31 -24
- package/hub/team/cli/commands/send.mjs +19 -6
- package/hub/team/cli/commands/start/index.mjs +151 -33
- package/hub/team/cli/commands/start/parse-args.mjs +97 -13
- package/hub/team/cli/commands/start/start-headless.mjs +155 -37
- package/hub/team/cli/commands/start/start-in-process.mjs +50 -40
- package/hub/team/cli/commands/start/start-mux.mjs +122 -73
- package/hub/team/cli/commands/start/start-wt.mjs +86 -69
- package/hub/team/cli/commands/status.mjs +43 -14
- package/hub/team/cli/commands/stop.mjs +11 -4
- package/hub/team/cli/commands/task.mjs +8 -3
- package/hub/team/cli/commands/tasks.mjs +13 -13
- package/hub/team/cli/help.mjs +1 -1
- package/hub/team/cli/index.mjs +2 -2
- package/hub/team/cli/manifest.mjs +38 -8
- package/hub/team/cli/render.mjs +52 -30
- package/hub/team/cli/services/attach-fallback.mjs +74 -54
- package/hub/team/cli/services/hub-client.mjs +44 -16
- package/hub/team/cli/services/member-selector.mjs +37 -30
- package/hub/team/cli/services/native-control.mjs +144 -116
- package/hub/team/cli/services/runtime-mode.mjs +61 -4
- package/hub/team/cli/services/state-store.mjs +66 -9
- package/hub/team/cli/services/task-model.mjs +40 -30
- package/hub/team/codex-review.mjs +521 -0
- package/hub/team/conductor-mesh-bridge.mjs +25 -24
- package/hub/team/conductor-registry.mjs +121 -0
- package/hub/team/conductor.mjs +1379 -671
- package/hub/team/consensus-meta.mjs +176 -0
- package/hub/team/dashboard-anchor.mjs +4 -5
- package/hub/team/dashboard-layout.mjs +3 -1
- package/hub/team/dashboard-open.mjs +20 -118
- package/hub/team/dashboard.mjs +76 -28
- package/hub/team/event-log.mjs +18 -10
- package/hub/team/execution-mode.mjs +256 -0
- package/hub/team/extract-completion-payload.mjs +110 -0
- package/hub/team/git-preflight.mjs +286 -0
- package/hub/team/handoff.mjs +49 -18
- package/hub/team/headless-bridge-session.mjs +17 -0
- package/hub/team/headless.mjs +2213 -1156
- package/hub/team/health-probe.mjs +232 -69
- package/hub/team/interactive-native-launcher.mjs +106 -0
- package/hub/team/interactive-native-worker.mjs +80 -0
- package/hub/team/interactive-tui-transport.mjs +465 -0
- package/hub/team/launcher-template.mjs +49 -17
- package/hub/team/lead-control.mjs +91 -4
- package/hub/team/mcp-selector.mjs +145 -0
- package/hub/team/native-supervisor.mjs +90 -26
- package/hub/team/native.mjs +120 -42
- package/hub/team/nativeProxy.mjs +184 -113
- package/hub/team/notify.mjs +147 -78
- package/hub/team/orchestrator.mjs +173 -161
- package/hub/team/pane.mjs +43 -20
- package/hub/team/process-cleanup.mjs +69 -25
- package/hub/team/psmux.mjs +1022 -281
- package/hub/team/recovery-store.mjs +149 -0
- package/hub/team/remote-probe.mjs +68 -52
- package/hub/team/remote-session.mjs +131 -59
- package/hub/team/remote-watcher.mjs +61 -33
- package/hub/team/retry-state-machine.mjs +336 -0
- package/hub/team/routing.mjs +51 -25
- package/hub/team/runtime-strategy.mjs +200 -0
- package/hub/team/schemas/worker-completion.json +39 -0
- package/hub/team/sentinel-capture.mjs +127 -0
- package/hub/team/session-sync.mjs +153 -6
- package/hub/team/session.mjs +574 -611
- package/hub/team/shared.mjs +13 -13
- package/hub/team/staleState.mjs +72 -30
- package/hub/team/swarm-cli.mjs +390 -0
- package/hub/team/swarm-hypervisor.mjs +1544 -193
- package/hub/team/swarm-intent.mjs +216 -0
- package/hub/team/swarm-locks.mjs +140 -25
- package/hub/team/swarm-planner.mjs +121 -21
- package/hub/team/swarm-preflight.mjs +319 -0
- package/hub/team/swarm-reconciler.mjs +128 -23
- package/hub/team/synapse-cli.mjs +458 -0
- package/hub/team/synapse-http.mjs +60 -0
- package/hub/team/synapse-registry.mjs +329 -0
- package/hub/team/terminal-opener.mjs +216 -0
- package/hub/team/tui-core.mjs +292 -0
- package/hub/team/tui-lite.mjs +237 -148
- package/hub/team/tui-remote-adapter.mjs +18 -34
- package/hub/team/tui-synapse.mjs +223 -0
- package/hub/team/tui-viewer.mjs +108 -48
- package/hub/team/tui-widgets.mjs +262 -0
- package/hub/team/tui.mjs +931 -439
- package/hub/team/worker-completion-validator.mjs +84 -0
- package/hub/team/worker-sandbox.mjs +97 -0
- package/hub/team/worker-signal.mjs +263 -0
- package/hub/team/worker-signal.types.d.ts +52 -0
- package/hub/team/worktree-lifecycle.mjs +517 -63
- package/hub/team/wt-manager.mjs +297 -26
- package/hub/tools.mjs +477 -252
- package/hub/tray.mjs +411 -368
- package/hub/workers/antigravity-route-worker.mjs +169 -0
- package/hub/workers/claude-worker.mjs +162 -118
- package/hub/workers/codex-app-server-worker.mjs +1015 -0
- package/hub/workers/codex-mcp.mjs +724 -507
- package/hub/workers/delegator-mcp.mjs +570 -499
- package/hub/workers/factory.mjs +103 -21
- package/hub/workers/gemini-worker.mjs +126 -284
- package/hub/workers/interface.mjs +24 -2
- package/hub/workers/lib/jsonrpc-stdio.mjs +463 -0
- package/hub/workers/worker-utils.mjs +23 -17
- package/package.json +4 -3
- package/scripts/lib/agent-json.mjs +27 -0
- package/scripts/lib/async.mjs +174 -0
- package/scripts/lib/claudemd-scanner.mjs +223 -0
- package/scripts/lib/cli-agy.mjs +62 -0
- package/scripts/lib/cli-claude.mjs +78 -0
- package/scripts/lib/cli-codex.mjs +199 -0
- package/scripts/lib/cli-gemini.mjs +37 -0
- package/scripts/lib/codex-recovery.sh +50 -0
- package/scripts/lib/context.mjs +67 -0
- package/scripts/lib/cross-review-utils.mjs +59 -0
- package/scripts/lib/doctor-env-checks.mjs +121 -0
- package/scripts/lib/dynamic-route-cli.mjs +107 -0
- package/scripts/lib/env-probe.mjs +269 -0
- package/scripts/lib/env.mjs +14 -0
- package/scripts/lib/gemini-profiles.mjs +119 -0
- package/scripts/lib/handoff.mjs +187 -0
- package/scripts/lib/hook-utils.mjs +16 -0
- package/scripts/lib/hub.mjs +48 -0
- package/scripts/lib/keyword-rules.mjs +195 -0
- package/scripts/lib/logger.mjs +105 -0
- package/scripts/lib/mcp-filter.mjs +883 -0
- package/scripts/lib/mcp-gateway-health-check.mjs +159 -0
- package/scripts/lib/mcp-gateway-servers.mjs +70 -0
- package/scripts/lib/mcp-gateway-wrapper-check.mjs +35 -0
- package/scripts/lib/mcp-guard-engine.mjs +2120 -0
- package/scripts/lib/mcp-health.mjs +773 -0
- package/scripts/lib/mcp-manifest.mjs +89 -0
- package/scripts/lib/mcp-server-catalog.mjs +355 -0
- package/scripts/lib/pid.mjs +63 -0
- package/scripts/lib/process-utils.mjs +26 -0
- package/scripts/lib/psmux-info.mjs +224 -0
- package/scripts/lib/quota.mjs +47 -0
- package/scripts/lib/remote-spawn-transfer.mjs +226 -0
- package/scripts/lib/skill-state.mjs +220 -0
- package/scripts/lib/skill-template.mjs +375 -0
- package/scripts/lib/team.mjs +75 -0
- package/scripts/lib/timeout.mjs +66 -0
- package/scripts/lib/tmp.mjs +26 -0
- package/scripts/lib/toml.mjs +113 -0
package/hub/team/session.mjs
CHANGED
|
@@ -1,611 +1,574 @@
|
|
|
1
|
-
// hub/team/session.mjs — tmux/psmux/wt 세션 생명주기 관리
|
|
2
|
-
// 의존성: child_process (Node.js 내장)만 사용
|
|
3
|
-
import { execSync, spawnSync } from "node:child_process";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function
|
|
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
|
-
return
|
|
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
|
-
if (
|
|
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
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
303
|
-
const
|
|
304
|
-
const
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
tmux(
|
|
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
|
-
|
|
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
|
-
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
stdio: "
|
|
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
|
-
if (detectMultiplexer() === "psmux") {
|
|
576
|
-
return getPsmuxSessionAttachedCount(sessionName);
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
try {
|
|
580
|
-
const output = tmux('list-sessions -F "#{session_name} #{session_attached}"');
|
|
581
|
-
const line = output
|
|
582
|
-
.split("\n")
|
|
583
|
-
.find((l) => l.startsWith(`${sessionName} `));
|
|
584
|
-
if (!line) return null;
|
|
585
|
-
const n = parseInt(line.split(" ")[1], 10);
|
|
586
|
-
return Number.isFinite(n) ? n : null;
|
|
587
|
-
} catch {
|
|
588
|
-
return null;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* pane 마지막 N줄 캡처
|
|
594
|
-
* @param {string} target — 예: tfx-multi-abc:0.1
|
|
595
|
-
* @param {number} lines — 캡처할 줄 수 (기본 5)
|
|
596
|
-
* @returns {string}
|
|
597
|
-
*/
|
|
598
|
-
export function capturePaneOutput(target, lines = 5) {
|
|
599
|
-
if (detectMultiplexer() === "psmux") {
|
|
600
|
-
return capturePsmuxPane(target, lines);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
try {
|
|
604
|
-
// -l 플래그는 일부 tmux 빌드(MSYS2)에서 미지원 → 전체 캡처 후 JS에서 절삭
|
|
605
|
-
const full = tmux(`capture-pane -t ${target} -p`);
|
|
606
|
-
const nonEmpty = full.split("\n").filter((l) => l.trim() !== "");
|
|
607
|
-
return nonEmpty.slice(-lines).join("\n");
|
|
608
|
-
} catch {
|
|
609
|
-
return "";
|
|
610
|
-
}
|
|
611
|
-
}
|
|
1
|
+
// hub/team/session.mjs — tmux/psmux/wt 세션 생명주기 관리
|
|
2
|
+
// 의존성: child_process (Node.js 내장)만 사용
|
|
3
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
4
|
+
import { resolveGitBashExecutable } from "@triflux/core/hub/lib/bash-path.mjs";
|
|
5
|
+
import { getEnvironment } from "@triflux/core/hub/lib/env-detect.mjs";
|
|
6
|
+
import {
|
|
7
|
+
attachPsmuxSession,
|
|
8
|
+
capturePsmuxPane,
|
|
9
|
+
configurePsmuxKeybindings,
|
|
10
|
+
createPsmuxSession,
|
|
11
|
+
getMultiplexerType,
|
|
12
|
+
getPsmuxSessionAttachedCount,
|
|
13
|
+
hasMultiplexer,
|
|
14
|
+
killPsmuxSession,
|
|
15
|
+
listPsmuxSessions,
|
|
16
|
+
psmuxExec,
|
|
17
|
+
psmuxSessionExists,
|
|
18
|
+
} from "./psmux.mjs";
|
|
19
|
+
import { createWtManager } from "./wt-manager.mjs";
|
|
20
|
+
|
|
21
|
+
/** Windows Terminal 실행 파일 존재 여부 */
|
|
22
|
+
export function hasWindowsTerminal() {
|
|
23
|
+
return !!getEnvironment().terminal.hasWt;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 현재 프로세스가 Windows Terminal 내에서 실행 중인지 여부 */
|
|
27
|
+
export function hasWindowsTerminalSession() {
|
|
28
|
+
return process.platform === "win32" && !!process.env.WT_SESSION;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** tmux 실행 가능 여부 확인 */
|
|
32
|
+
function hasTmux() {
|
|
33
|
+
try {
|
|
34
|
+
execSync("tmux -V", { stdio: "ignore", timeout: 3000, windowsHide: true });
|
|
35
|
+
return true;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Git Bash 내 tmux 사용 가능 여부 (Windows 전용) */
|
|
42
|
+
function hasGitBashTmux() {
|
|
43
|
+
const bash = resolveGitBashExecutable();
|
|
44
|
+
if (!bash) return false;
|
|
45
|
+
try {
|
|
46
|
+
const r = spawnSync(bash, ["-lc", "tmux -V"], {
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
timeout: 5000,
|
|
49
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
50
|
+
windowsHide: true,
|
|
51
|
+
});
|
|
52
|
+
return (r.status ?? 1) === 0;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getCommandVersion(command) {
|
|
59
|
+
const r = spawnSync(command, ["-V"], {
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
timeout: 3000,
|
|
62
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
63
|
+
windowsHide: true,
|
|
64
|
+
});
|
|
65
|
+
if ((r.status ?? 1) !== 0) return null;
|
|
66
|
+
return `${r.stdout || ""}${r.stderr || ""}`.trim();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isPsmuxVersion(command) {
|
|
70
|
+
try {
|
|
71
|
+
return /\bpsmux\b/i.test(getCommandVersion(command) || "");
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isPsmuxCommandName(command) {
|
|
78
|
+
const name = String(command || "")
|
|
79
|
+
.replace(/\\/g, "/")
|
|
80
|
+
.split("/")
|
|
81
|
+
.pop()
|
|
82
|
+
.toLowerCase();
|
|
83
|
+
return name === "psmux" || name === "psmux.exe" || name === "psmux.cmd";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function hasLiteralPsmuxBinary(command = process.env.PSMUX_BIN || "psmux") {
|
|
87
|
+
return isPsmuxVersion(command);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 터미널 멀티플렉서 감지 (결과 캐싱 — 프로세스 수명 동안 불변)
|
|
92
|
+
* @returns {'tmux'|'git-bash-tmux'|'psmux'|null}
|
|
93
|
+
*/
|
|
94
|
+
let _cachedMux;
|
|
95
|
+
export function detectMultiplexer() {
|
|
96
|
+
if (_cachedMux !== undefined) return _cachedMux;
|
|
97
|
+
|
|
98
|
+
if (process.platform !== "win32") {
|
|
99
|
+
const primaryMux = getMultiplexerType();
|
|
100
|
+
if (primaryMux === "tmux" && hasMultiplexer()) {
|
|
101
|
+
_cachedMux = "tmux";
|
|
102
|
+
return _cachedMux;
|
|
103
|
+
}
|
|
104
|
+
if (hasTmux()) {
|
|
105
|
+
_cachedMux = "tmux";
|
|
106
|
+
return _cachedMux;
|
|
107
|
+
}
|
|
108
|
+
if (hasLiteralPsmuxBinary()) {
|
|
109
|
+
_cachedMux = "psmux";
|
|
110
|
+
return _cachedMux;
|
|
111
|
+
}
|
|
112
|
+
_cachedMux = null;
|
|
113
|
+
return _cachedMux;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (hasMultiplexer() && isPsmuxCommandName(getMultiplexerType())) {
|
|
117
|
+
_cachedMux = "psmux";
|
|
118
|
+
return _cachedMux;
|
|
119
|
+
}
|
|
120
|
+
if (hasTmux()) {
|
|
121
|
+
_cachedMux = "tmux";
|
|
122
|
+
return _cachedMux;
|
|
123
|
+
}
|
|
124
|
+
if (hasGitBashTmux()) {
|
|
125
|
+
_cachedMux = "git-bash-tmux";
|
|
126
|
+
return _cachedMux;
|
|
127
|
+
}
|
|
128
|
+
_cachedMux = null;
|
|
129
|
+
return _cachedMux;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* tmux/psmux 커맨드 실행
|
|
134
|
+
* @param {string} args — tmux 서브커맨드 + 인자
|
|
135
|
+
* @param {object} opts — execSync 옵션
|
|
136
|
+
* @returns {string} stdout
|
|
137
|
+
*/
|
|
138
|
+
function tmux(args, opts = {}) {
|
|
139
|
+
const mux = detectMultiplexer();
|
|
140
|
+
if (!mux) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"tmux/psmux 미발견.\n\n" +
|
|
143
|
+
"tfx multi은 tmux 계열 멀티플렉서가 필요합니다:\n" +
|
|
144
|
+
" Windows: psmux 설치\n" +
|
|
145
|
+
" macOS: brew install tmux\n" +
|
|
146
|
+
" Linux: apt install tmux",
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
if (mux === "psmux") {
|
|
150
|
+
return psmuxExec(args, opts);
|
|
151
|
+
}
|
|
152
|
+
if (mux === "git-bash-tmux") {
|
|
153
|
+
const bash = findGitBashExe();
|
|
154
|
+
if (!bash) throw new Error("git-bash-tmux 감지 실패");
|
|
155
|
+
const r = spawnSync(bash, ["-lc", `tmux ${args}`], {
|
|
156
|
+
encoding: "utf8",
|
|
157
|
+
timeout: 10000,
|
|
158
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
159
|
+
windowsHide: true,
|
|
160
|
+
...opts,
|
|
161
|
+
});
|
|
162
|
+
if ((r.status ?? 1) !== 0) {
|
|
163
|
+
const e = new Error(r.stderr || "tmux command failed");
|
|
164
|
+
e.status = r.status;
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
return (r.stdout || "").trim();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const result = execSync(`tmux ${args}`, {
|
|
171
|
+
encoding: "utf8",
|
|
172
|
+
timeout: 10000,
|
|
173
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
174
|
+
windowsHide: true,
|
|
175
|
+
...opts,
|
|
176
|
+
});
|
|
177
|
+
return result != null ? result.trim() : "";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* tmux 명령 직접 실행 (고수준 모듈에서 재사용)
|
|
182
|
+
* @param {string} args
|
|
183
|
+
* @param {object} opts
|
|
184
|
+
* @returns {string}
|
|
185
|
+
*/
|
|
186
|
+
export function tmuxExec(args, opts = {}) {
|
|
187
|
+
return tmux(args, opts);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 현재 멀티플렉서 환경에 맞는 attach 실행 스펙 반환
|
|
192
|
+
* @param {string} sessionName
|
|
193
|
+
* @returns {{ command: string, args: string[] }}
|
|
194
|
+
*/
|
|
195
|
+
export function resolveAttachCommand(sessionName, opts = {}) {
|
|
196
|
+
const mux = opts.mux || detectMultiplexer();
|
|
197
|
+
if (!mux) {
|
|
198
|
+
throw new Error("tmux/psmux 미발견");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (mux === "psmux") {
|
|
202
|
+
return {
|
|
203
|
+
command: process.env.PSMUX_BIN || "psmux",
|
|
204
|
+
args: ["attach-session", "-t", sessionName],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (mux === "git-bash-tmux") {
|
|
209
|
+
const bash = opts.bashCommand || resolveGitBashExecutable();
|
|
210
|
+
if (!bash) throw new Error("git-bash-tmux 감지 실패");
|
|
211
|
+
return {
|
|
212
|
+
command: bash,
|
|
213
|
+
args: ["-lc", `tmux attach-session -t ${sessionName}`],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
command: "tmux",
|
|
219
|
+
args: ["attach-session", "-t", sessionName],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Windows Terminal pane 포커스 이동
|
|
225
|
+
* @param {number} paneIndex - createWtSession()에서 생성한 pane 인덱스(0 기반)
|
|
226
|
+
* @param {object} opts
|
|
227
|
+
* @param {'1xN'|'Nx1'} opts.layout
|
|
228
|
+
* @returns {boolean}
|
|
229
|
+
*/
|
|
230
|
+
export function focusWtPane(paneIndex, opts = {}) {
|
|
231
|
+
// wt() 제거로 인해 일시 비활성화 (탭 기반 전환 필요)
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Windows Terminal에서 생성한 팀 pane 정리
|
|
237
|
+
* @param {object} opts
|
|
238
|
+
* @param {'1xN'|'Nx1'} opts.layout
|
|
239
|
+
* @param {number} opts.paneCount
|
|
240
|
+
* @returns {number} 닫힌 pane 수 (best-effort)
|
|
241
|
+
*/
|
|
242
|
+
export function closeWtSession(opts = {}) {
|
|
243
|
+
// wt() 제거로 인해 일시 비활성화 (탭 기반 전환 필요)
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Windows Terminal 독립 모드 세션 생성 (비동기)
|
|
249
|
+
* @param {string} sessionName
|
|
250
|
+
* @param {object} opts
|
|
251
|
+
* @param {'1xN'|'Nx1'} opts.layout
|
|
252
|
+
* @param {Array<{title:string,command:string,cwd?:string}>} opts.paneCommands
|
|
253
|
+
* @returns {Promise<{ sessionName: string, panes: string[], titles: string[], layout: '1xN'|'Nx1', paneCount: number, anchorPane: string }>}
|
|
254
|
+
*/
|
|
255
|
+
export async function createWtSession(sessionName, opts = {}) {
|
|
256
|
+
const { layout = "1xN", paneCommands = [] } = opts;
|
|
257
|
+
|
|
258
|
+
if (!hasWindowsTerminalSession()) {
|
|
259
|
+
throw new Error("WT_SESSION 미감지");
|
|
260
|
+
}
|
|
261
|
+
if (!getEnvironment().terminal.hasWt) {
|
|
262
|
+
throw new Error("wt.exe 미발견");
|
|
263
|
+
}
|
|
264
|
+
if (!Array.isArray(paneCommands) || paneCommands.length === 0) {
|
|
265
|
+
throw new Error("paneCommands가 비어 있음");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const wtManager = createWtManager();
|
|
269
|
+
const panes = [];
|
|
270
|
+
const titles = [];
|
|
271
|
+
|
|
272
|
+
for (let i = 0; i < paneCommands.length; i++) {
|
|
273
|
+
const pane = paneCommands[i] || {};
|
|
274
|
+
const title = pane.title || `${sessionName}-${i + 1}`;
|
|
275
|
+
const command = String(pane.command || "").trim();
|
|
276
|
+
const cwd = pane.cwd || process.cwd();
|
|
277
|
+
if (!command) continue;
|
|
278
|
+
|
|
279
|
+
await wtManager.createTab({ title, command, cwd });
|
|
280
|
+
panes.push(`wt:${i}`);
|
|
281
|
+
titles.push(title);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
sessionName,
|
|
286
|
+
panes,
|
|
287
|
+
titles,
|
|
288
|
+
layout: layout === "Nx1" ? "Nx1" : "1xN",
|
|
289
|
+
paneCount: panes.length,
|
|
290
|
+
anchorPane: "wt:anchor",
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* tmux 세션 생성 + 레이아웃 분할
|
|
296
|
+
* @param {string} sessionName — 세션 이름
|
|
297
|
+
* @param {object} opts
|
|
298
|
+
* @param {'2x2'|'1xN'|'Nx1'} opts.layout — 레이아웃 (기본 2x2)
|
|
299
|
+
* @param {number} opts.paneCount — pane 수 (기본 4)
|
|
300
|
+
* @returns {{ sessionName: string, panes: string[] }}
|
|
301
|
+
*/
|
|
302
|
+
export function createSession(sessionName, opts = {}) {
|
|
303
|
+
const { layout = "2x2", paneCount = 4 } = opts;
|
|
304
|
+
const mux = detectMultiplexer();
|
|
305
|
+
|
|
306
|
+
// 기존 세션 정리
|
|
307
|
+
if (sessionExists(sessionName)) {
|
|
308
|
+
killSession(sessionName);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (mux === "psmux") {
|
|
312
|
+
return createPsmuxSession(sessionName, { layout, paneCount });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 새 세션 생성 (detached)
|
|
316
|
+
tmux(`new-session -d -s ${sessionName} -x 220 -y 55`);
|
|
317
|
+
|
|
318
|
+
const panes = [`${sessionName}:0.0`];
|
|
319
|
+
|
|
320
|
+
if (layout === "2x2" && paneCount >= 3) {
|
|
321
|
+
// 3-pane 기본: lead 왼쪽, workers 오른쪽 상/하
|
|
322
|
+
// 4-pane: 좌/우 각각 상/하(균등 2x2)
|
|
323
|
+
tmux(`split-window -h -t ${sessionName}:0.0`);
|
|
324
|
+
tmux(`split-window -v -t ${sessionName}:0.1`);
|
|
325
|
+
if (paneCount >= 4) {
|
|
326
|
+
tmux(`split-window -v -t ${sessionName}:0.0`);
|
|
327
|
+
}
|
|
328
|
+
// pane ID 재수집
|
|
329
|
+
panes.length = 0;
|
|
330
|
+
for (let i = 0; i < Math.min(paneCount, 4); i++) {
|
|
331
|
+
panes.push(`${sessionName}:0.${i}`);
|
|
332
|
+
}
|
|
333
|
+
} else if (layout === "1xN") {
|
|
334
|
+
// 세로 분할(좌/우 컬럼 확장)
|
|
335
|
+
for (let i = 1; i < paneCount; i++) {
|
|
336
|
+
tmux(`split-window -h -t ${sessionName}:0`);
|
|
337
|
+
}
|
|
338
|
+
tmux(`select-layout -t ${sessionName}:0 even-horizontal`);
|
|
339
|
+
panes.length = 0;
|
|
340
|
+
for (let i = 0; i < paneCount; i++) {
|
|
341
|
+
panes.push(`${sessionName}:0.${i}`);
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
// Nx1 가로 분할(상/하 스택)
|
|
345
|
+
for (let i = 1; i < paneCount; i++) {
|
|
346
|
+
tmux(`split-window -v -t ${sessionName}:0`);
|
|
347
|
+
}
|
|
348
|
+
tmux(`select-layout -t ${sessionName}:0 even-vertical`);
|
|
349
|
+
panes.length = 0;
|
|
350
|
+
for (let i = 0; i < paneCount; i++) {
|
|
351
|
+
panes.push(`${sessionName}:0.${i}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return { sessionName, panes };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* pane 포커스 이동
|
|
360
|
+
* @param {string} target
|
|
361
|
+
* @param {object} opts
|
|
362
|
+
* @param {boolean} opts.zoom
|
|
363
|
+
*/
|
|
364
|
+
export function focusPane(target, opts = {}) {
|
|
365
|
+
const { zoom = false } = opts;
|
|
366
|
+
tmux(`select-pane -t ${target}`);
|
|
367
|
+
if (zoom) {
|
|
368
|
+
try {
|
|
369
|
+
tmux(`resize-pane -t ${target} -Z`);
|
|
370
|
+
} catch {}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* 팀메이트 조작 키 바인딩 설정
|
|
376
|
+
* - Shift+Down: 다음 팀메이트
|
|
377
|
+
* - Shift+Up: 이전 팀메이트
|
|
378
|
+
* - Shift+Left / Shift+Tab: 이전 팀메이트 대체 키
|
|
379
|
+
* - Shift+Right: 다음 팀메이트 대체 키
|
|
380
|
+
* - Escape: 현재 팀메이트 인터럽트(C-c)
|
|
381
|
+
* - Ctrl+T: 태스크 목록 표시
|
|
382
|
+
* @param {string} sessionName
|
|
383
|
+
* @param {object} opts
|
|
384
|
+
* @param {boolean} opts.inProcess
|
|
385
|
+
* @param {string} opts.taskListCommand
|
|
386
|
+
*/
|
|
387
|
+
export function configureTeammateKeybindings(sessionName, opts = {}) {
|
|
388
|
+
if (detectMultiplexer() === "psmux") {
|
|
389
|
+
configurePsmuxKeybindings(sessionName, opts);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const { inProcess = false, taskListCommand = "" } = opts;
|
|
394
|
+
const cond = `#{==:#{session_name},${sessionName}}`;
|
|
395
|
+
|
|
396
|
+
// Shift+Up이 터미널/호스트 조합에 따라 전달되지 않는 경우가 있어
|
|
397
|
+
// 좌/우/Shift+Tab 대체 키를 함께 바인딩한다.
|
|
398
|
+
const bindNext = inProcess
|
|
399
|
+
? `'select-pane -t :.+ \\; resize-pane -Z'`
|
|
400
|
+
: `'select-pane -t :.+'`;
|
|
401
|
+
const bindPrev = inProcess
|
|
402
|
+
? `'select-pane -t :.- \\; resize-pane -Z'`
|
|
403
|
+
: `'select-pane -t :.-'`;
|
|
404
|
+
|
|
405
|
+
if (inProcess) {
|
|
406
|
+
// 단일 뷰(zoom) 상태에서 팀메이트 순환
|
|
407
|
+
tmux(
|
|
408
|
+
`bind-key -T root -n S-Down if-shell -F '${cond}' ${bindNext} 'send-keys S-Down'`,
|
|
409
|
+
);
|
|
410
|
+
tmux(
|
|
411
|
+
`bind-key -T root -n S-Up if-shell -F '${cond}' ${bindPrev} 'send-keys S-Up'`,
|
|
412
|
+
);
|
|
413
|
+
} else {
|
|
414
|
+
// 분할 뷰에서 팀메이트 순환
|
|
415
|
+
tmux(
|
|
416
|
+
`bind-key -T root -n S-Down if-shell -F '${cond}' ${bindNext} 'send-keys S-Down'`,
|
|
417
|
+
);
|
|
418
|
+
tmux(
|
|
419
|
+
`bind-key -T root -n S-Up if-shell -F '${cond}' ${bindPrev} 'send-keys S-Up'`,
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// 대체 키: 일부 환경에서 S-Up이 누락될 때 사용
|
|
424
|
+
tmux(
|
|
425
|
+
`bind-key -T root -n S-Right if-shell -F '${cond}' ${bindNext} 'send-keys S-Right'`,
|
|
426
|
+
);
|
|
427
|
+
tmux(
|
|
428
|
+
`bind-key -T root -n S-Left if-shell -F '${cond}' ${bindPrev} 'send-keys S-Left'`,
|
|
429
|
+
);
|
|
430
|
+
tmux(
|
|
431
|
+
`bind-key -T root -n BTab if-shell -F '${cond}' ${bindPrev} 'send-keys BTab'`,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
// 현재 활성 pane 인터럽트
|
|
435
|
+
tmux(
|
|
436
|
+
`bind-key -T root -n Escape if-shell -F '${cond}' 'send-keys C-c' 'send-keys Escape'`,
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
// 태스크 목록 토글 (tmux 3.2+ popup 우선, 실패 시 안내 메시지)
|
|
440
|
+
if (taskListCommand) {
|
|
441
|
+
const escaped = taskListCommand.replace(/'/g, "'\\''");
|
|
442
|
+
try {
|
|
443
|
+
tmux(
|
|
444
|
+
`bind-key -T root -n C-t if-shell -F '${cond}' "display-popup -E '${escaped}'" "send-keys C-t"`,
|
|
445
|
+
);
|
|
446
|
+
} catch {
|
|
447
|
+
tmux(
|
|
448
|
+
`bind-key -T root -n C-t if-shell -F '${cond}' 'display-message "tfx multi tasks 명령으로 태스크 확인"' 'send-keys C-t'`,
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* tmux 세션 연결 (포그라운드 전환)
|
|
456
|
+
* @param {string} sessionName
|
|
457
|
+
*/
|
|
458
|
+
export function attachSession(sessionName) {
|
|
459
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY) {
|
|
460
|
+
throw new Error("현재 터미널은 tmux attach를 지원하지 않음 (non-TTY)");
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (detectMultiplexer() === "psmux") {
|
|
464
|
+
attachPsmuxSession(sessionName);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const { command, args } = resolveAttachCommand(sessionName);
|
|
469
|
+
const r = spawnSync(command, args, {
|
|
470
|
+
stdio: "inherit",
|
|
471
|
+
timeout: 0, // 타임아웃 없음 (사용자가 detach할 때까지)
|
|
472
|
+
});
|
|
473
|
+
if ((r.status ?? 1) !== 0) {
|
|
474
|
+
throw new Error(`tmux attach 실패 (exit=${r.status})`);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* tmux 세션 존재 확인
|
|
480
|
+
* @param {string} sessionName
|
|
481
|
+
* @returns {boolean}
|
|
482
|
+
*/
|
|
483
|
+
export function sessionExists(sessionName) {
|
|
484
|
+
if (detectMultiplexer() === "psmux") {
|
|
485
|
+
return psmuxSessionExists(sessionName);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
try {
|
|
489
|
+
tmux(`has-session -t ${sessionName}`, { stdio: "ignore" });
|
|
490
|
+
return true;
|
|
491
|
+
} catch {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* tmux 세션 종료
|
|
498
|
+
* @param {string} sessionName
|
|
499
|
+
*/
|
|
500
|
+
export function killSession(sessionName) {
|
|
501
|
+
if (detectMultiplexer() === "psmux") {
|
|
502
|
+
killPsmuxSession(sessionName);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
try {
|
|
507
|
+
tmux(`kill-session -t ${sessionName}`, { stdio: "ignore" });
|
|
508
|
+
} catch {
|
|
509
|
+
// 이미 종료된 세션 — 무시
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* tfx-multi- 접두사 세션 목록
|
|
515
|
+
* @returns {string[]}
|
|
516
|
+
*/
|
|
517
|
+
export function listSessions() {
|
|
518
|
+
if (detectMultiplexer() === "psmux") {
|
|
519
|
+
return listPsmuxSessions();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
try {
|
|
523
|
+
const output = tmux('list-sessions -F "#{session_name}"');
|
|
524
|
+
return output.split("\n").filter((s) => s.startsWith("tfx-multi-"));
|
|
525
|
+
} catch {
|
|
526
|
+
return [];
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* 세션 attach client 수 조회
|
|
532
|
+
* @param {string} sessionName
|
|
533
|
+
* @returns {number|null}
|
|
534
|
+
*/
|
|
535
|
+
export function getSessionAttachedCount(sessionName) {
|
|
536
|
+
if (detectMultiplexer() === "psmux") {
|
|
537
|
+
return getPsmuxSessionAttachedCount(sessionName);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
try {
|
|
541
|
+
const output = tmux(
|
|
542
|
+
'list-sessions -F "#{session_name} #{session_attached}"',
|
|
543
|
+
);
|
|
544
|
+
const line = output
|
|
545
|
+
.split("\n")
|
|
546
|
+
.find((l) => l.startsWith(`${sessionName} `));
|
|
547
|
+
if (!line) return null;
|
|
548
|
+
const n = parseInt(line.split(" ")[1], 10);
|
|
549
|
+
return Number.isFinite(n) ? n : null;
|
|
550
|
+
} catch {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* pane 마지막 N줄 캡처
|
|
557
|
+
* @param {string} target — 예: tfx-multi-abc:0.1
|
|
558
|
+
* @param {number} lines — 캡처할 줄 수 (기본 5)
|
|
559
|
+
* @returns {string}
|
|
560
|
+
*/
|
|
561
|
+
export function capturePaneOutput(target, lines = 5) {
|
|
562
|
+
if (detectMultiplexer() === "psmux") {
|
|
563
|
+
return capturePsmuxPane(target, lines);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
try {
|
|
567
|
+
// -l 플래그는 일부 tmux 빌드(MSYS2)에서 미지원 → 전체 캡처 후 JS에서 절삭
|
|
568
|
+
const full = tmux(`capture-pane -t ${target} -p`);
|
|
569
|
+
const nonEmpty = full.split("\n").filter((l) => l.trim() !== "");
|
|
570
|
+
return nonEmpty.slice(-lines).join("\n");
|
|
571
|
+
} catch {
|
|
572
|
+
return "";
|
|
573
|
+
}
|
|
574
|
+
}
|