@triflux/remote 10.1.0 → 10.25.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/hub/pipe.mjs +239 -121
- package/hub/public/dashboard.html +61 -0
- package/hub/server.mjs +2165 -708
- 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 +84 -17
- package/hub/team/build-worker-prompt.mjs +42 -0
- package/hub/team/check-mcp-hub.mjs +49 -0
- package/hub/team/claude-daemon-control.mjs +219 -0
- package/hub/team/claude-native-bridge.mjs +784 -0
- package/hub/team/claude-session-projection.mjs +65 -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 +154 -33
- package/hub/team/cli/commands/start/parse-args.mjs +89 -12
- package/hub/team/cli/commands/start/start-headless.mjs +125 -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/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 +55 -1
- 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 +241 -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 +2065 -1156
- package/hub/team/health-probe.mjs +232 -69
- package/hub/team/launcher-template.mjs +23 -13
- 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 +74 -35
- 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 -15
- package/hub/team/process-cleanup.mjs +69 -25
- package/hub/team/psmux.mjs +1020 -279
- 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 +267 -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 +605 -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 +1522 -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 +317 -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 +288 -0
- package/hub/team/tui-lite.mjs +234 -146
- package/hub/team/tui-remote-adapter.mjs +18 -34
- package/hub/team/tui-synapse.mjs +223 -0
- package/hub/team/tui-viewer.mjs +104 -44
- package/hub/team/tui-widgets.mjs +262 -0
- package/hub/team/tui.mjs +927 -437
- package/hub/team/worker-completion-validator.mjs +84 -0
- package/hub/team/worker-sandbox.mjs +93 -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 +474 -252
- package/hub/tray.mjs +411 -368
- 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 +662 -335
- package/hub/workers/factory.mjs +100 -21
- package/hub/workers/gemini-worker.mjs +179 -86
- package/hub/workers/interface.mjs +23 -2
- package/hub/workers/lib/jsonrpc-stdio.mjs +463 -0
- package/hub/workers/worker-utils.mjs +22 -16
- 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 +67 -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-servers.mjs +70 -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 +179 -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/conductor.mjs
CHANGED
|
@@ -1,671 +1,1379 @@
|
|
|
1
|
-
// hub/team/conductor.mjs — 세션 오케스트레이션 Conductor
|
|
2
|
-
// native-supervisor.mjs의 spawn/kill을 래핑하되, 상태 머신 + health probe +
|
|
3
|
-
// auto-restart + event log를 추가하여 "조용한 실패"를 구조적으로 불가능하게 만든다.
|
|
4
|
-
//
|
|
5
|
-
// 기존 native-supervisor와의 차이:
|
|
6
|
-
// 1. 상태 머신 (alive/dead → 7 states + 2 terminal)
|
|
7
|
-
// 2. Health probe 4단계 (+ INPUT_WAIT 감지)
|
|
8
|
-
// 3. Auto-restart (maxRestarts=3)
|
|
9
|
-
// 4. JSONL event log (블랙박스 리코더)
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { broker } from
|
|
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
|
-
|
|
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
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
session.
|
|
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
|
-
const
|
|
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
|
-
eventLog.append(
|
|
330
|
-
session: session.id,
|
|
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
|
-
|
|
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
|
-
if (
|
|
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
|
-
const launcher =
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
// hub/team/conductor.mjs — 세션 오케스트레이션 Conductor
|
|
2
|
+
// native-supervisor.mjs의 spawn/kill을 래핑하되, 상태 머신 + health probe +
|
|
3
|
+
// auto-restart + event log를 추가하여 "조용한 실패"를 구조적으로 불가능하게 만든다.
|
|
4
|
+
//
|
|
5
|
+
// 기존 native-supervisor와의 차이:
|
|
6
|
+
// 1. 상태 머신 (alive/dead → 7 states + 2 terminal)
|
|
7
|
+
// 2. Health probe 4단계 (+ INPUT_WAIT 감지)
|
|
8
|
+
// 3. Auto-restart (maxRestarts=3)
|
|
9
|
+
// 4. JSONL event log (블랙박스 리코더)
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { EventEmitter } from "node:events";
|
|
13
|
+
import {
|
|
14
|
+
copyFileSync,
|
|
15
|
+
createWriteStream,
|
|
16
|
+
mkdirSync,
|
|
17
|
+
readFileSync,
|
|
18
|
+
} from "node:fs";
|
|
19
|
+
import { homedir } from "node:os";
|
|
20
|
+
import { dirname, join } from "node:path";
|
|
21
|
+
import { createRegistry } from "@triflux/core/mesh/mesh-registry.mjs";
|
|
22
|
+
import { broker } from "@triflux/core/hub/account-broker.mjs";
|
|
23
|
+
import {
|
|
24
|
+
__internal__ as dynamicRoutingInternal,
|
|
25
|
+
evaluateDynamicRoute,
|
|
26
|
+
isDynamicRoutingEnabled,
|
|
27
|
+
} from "@triflux/core/hub/dynamic-routing-engine.mjs";
|
|
28
|
+
import {
|
|
29
|
+
findProcessTree,
|
|
30
|
+
killProcessTree,
|
|
31
|
+
killProcessTreeSnapshot,
|
|
32
|
+
} from "@triflux/core/hub/lib/process-utils.mjs";
|
|
33
|
+
import { execFile, spawn } from "@triflux/core/hub/lib/spawn-trace.mjs";
|
|
34
|
+
import { killProcess } from "@triflux/core/hub/platform.mjs";
|
|
35
|
+
import { tryGetCachedSnapshot } from "@triflux/core/hub/routing-snapshot.mjs";
|
|
36
|
+
import { createHubHealthChecker } from "./check-mcp-hub.mjs";
|
|
37
|
+
import { createConductorMeshBridge } from "./conductor-mesh-bridge.mjs";
|
|
38
|
+
import {
|
|
39
|
+
ensureConductorRegistry,
|
|
40
|
+
getConductorRegistry,
|
|
41
|
+
} from "./conductor-registry.mjs";
|
|
42
|
+
import { createEventLog } from "./event-log.mjs";
|
|
43
|
+
import { buildSpawnSpecForMode, MODES } from "./execution-mode.mjs";
|
|
44
|
+
import { extractCompletionPayload } from "./extract-completion-payload.mjs";
|
|
45
|
+
import { createHealthProbe } from "./health-probe.mjs";
|
|
46
|
+
import { buildLauncher } from "./launcher-template.mjs";
|
|
47
|
+
import { createSentinelCapture } from "./sentinel-capture.mjs";
|
|
48
|
+
import {
|
|
49
|
+
buildSynapseTaskSummary,
|
|
50
|
+
heartbeatSynapseSession,
|
|
51
|
+
registerSynapseSession,
|
|
52
|
+
unregisterSynapseSession,
|
|
53
|
+
} from "./synapse-http.mjs";
|
|
54
|
+
import { buildWorkerSandboxEnv } from "./worker-sandbox.mjs";
|
|
55
|
+
|
|
56
|
+
/** 세션 상태 */
|
|
57
|
+
export const STATES = Object.freeze({
|
|
58
|
+
INIT: "init",
|
|
59
|
+
STARTING: "starting",
|
|
60
|
+
HEALTHY: "healthy",
|
|
61
|
+
STALLED: "stalled",
|
|
62
|
+
INPUT_WAIT: "input_wait",
|
|
63
|
+
FAILED: "failed",
|
|
64
|
+
RESTARTING: "restarting",
|
|
65
|
+
DEAD: "dead",
|
|
66
|
+
COMPLETED: "completed",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/** 유효한 상태 전이 테이블 */
|
|
70
|
+
const TRANSITIONS = Object.freeze({
|
|
71
|
+
[STATES.INIT]: [STATES.STARTING],
|
|
72
|
+
[STATES.STARTING]: [STATES.HEALTHY, STATES.FAILED, STATES.COMPLETED],
|
|
73
|
+
[STATES.HEALTHY]: [
|
|
74
|
+
STATES.STALLED,
|
|
75
|
+
STATES.INPUT_WAIT,
|
|
76
|
+
STATES.FAILED,
|
|
77
|
+
STATES.COMPLETED,
|
|
78
|
+
],
|
|
79
|
+
[STATES.STALLED]: [STATES.HEALTHY, STATES.FAILED],
|
|
80
|
+
[STATES.INPUT_WAIT]: [STATES.HEALTHY, STATES.FAILED],
|
|
81
|
+
[STATES.FAILED]: [STATES.RESTARTING, STATES.DEAD],
|
|
82
|
+
[STATES.RESTARTING]: [STATES.STARTING],
|
|
83
|
+
[STATES.DEAD]: [],
|
|
84
|
+
[STATES.COMPLETED]: [],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const TERMINAL_STATES = new Set([STATES.DEAD, STATES.COMPLETED]);
|
|
88
|
+
const DEFAULT_MAX_RESTARTS = 3;
|
|
89
|
+
const DEFAULT_GRACE_MS = 10_000;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Auth 파일을 lease 소스에서 CLI 대상 경로로 복사.
|
|
93
|
+
* @param {object} lease — broker lease 객체 (mode, authFile 필수)
|
|
94
|
+
* @param {'codex'|'gemini'} agent
|
|
95
|
+
* @param {string} sessionId — 로깅용
|
|
96
|
+
* @param {object} eventLog — createEventLog 인스턴스
|
|
97
|
+
* @param {object} brokerInstance — AccountBroker 인스턴스
|
|
98
|
+
*/
|
|
99
|
+
function swapAuthFile(
|
|
100
|
+
lease,
|
|
101
|
+
agent,
|
|
102
|
+
sessionId,
|
|
103
|
+
eventLog,
|
|
104
|
+
brokerInstance,
|
|
105
|
+
targetEnv = {},
|
|
106
|
+
) {
|
|
107
|
+
if (lease?.mode !== "auth" || !lease.authFile) return true;
|
|
108
|
+
if (
|
|
109
|
+
agent === "codex" &&
|
|
110
|
+
lease.id &&
|
|
111
|
+
brokerInstance &&
|
|
112
|
+
typeof brokerInstance.syncAuthToSource === "function"
|
|
113
|
+
) {
|
|
114
|
+
const result = brokerInstance.syncAuthToSource(lease.id);
|
|
115
|
+
if (result?.copied || result?.reason === "up_to_date") {
|
|
116
|
+
eventLog.append("auth_copy", {
|
|
117
|
+
session: sessionId,
|
|
118
|
+
agent,
|
|
119
|
+
dest: result.sourcePath,
|
|
120
|
+
reason: result.reason,
|
|
121
|
+
});
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
eventLog.append("auth_copy_error", {
|
|
125
|
+
session: sessionId,
|
|
126
|
+
dest: result?.sourcePath || join(homedir(), ".codex", "auth.json"),
|
|
127
|
+
error: result?.reason || "sync_failed",
|
|
128
|
+
});
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const targetHome = targetEnv.HOME || homedir();
|
|
132
|
+
const codexHome = targetEnv.CODEX_HOME || join(targetHome, ".codex");
|
|
133
|
+
const dests =
|
|
134
|
+
agent === "codex"
|
|
135
|
+
? [join(codexHome, "auth.json")]
|
|
136
|
+
: [
|
|
137
|
+
join(targetHome, ".gemini", "oauth_creds.json"),
|
|
138
|
+
join(targetHome, ".gemini", "gemini-credentials.json"),
|
|
139
|
+
];
|
|
140
|
+
let allOk = true;
|
|
141
|
+
for (const dest of dests) {
|
|
142
|
+
try {
|
|
143
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
144
|
+
copyFileSync(lease.authFile, dest);
|
|
145
|
+
eventLog.append("auth_copy", { session: sessionId, agent, dest });
|
|
146
|
+
} catch (err) {
|
|
147
|
+
allOk = false;
|
|
148
|
+
eventLog.append("auth_copy_error", {
|
|
149
|
+
session: sessionId,
|
|
150
|
+
dest,
|
|
151
|
+
error: err.message,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return allOk;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Conductor 팩토리.
|
|
160
|
+
* @param {object} opts
|
|
161
|
+
* @param {string} opts.logsDir — 이벤트 로그 디렉토리
|
|
162
|
+
* @param {number} [opts.maxRestarts=3]
|
|
163
|
+
* @param {number} [opts.graceMs=10000] — shutdown grace period
|
|
164
|
+
* @param {object} [opts.probeOpts] — health-probe 옵션 오버라이드
|
|
165
|
+
* @param {object} [opts.broker] — AccountBroker 인스턴스 (tierFallback 구독용)
|
|
166
|
+
* @returns {Conductor}
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* Conductor 생성.
|
|
170
|
+
* @param {object} [opts]
|
|
171
|
+
* @param {object} [opts.deps] — 의존성 주입 (테스트용 mock 지원)
|
|
172
|
+
* @param {Function} [opts.deps.execFile] — execFile 오버라이드
|
|
173
|
+
* @param {Function} [opts.deps.spawn] — spawn 오버라이드 (로컬/원격 child process 모두)
|
|
174
|
+
*/
|
|
175
|
+
export function createConductor(opts = {}) {
|
|
176
|
+
const spawnFn = opts.deps?.spawn || spawn;
|
|
177
|
+
const processUtils = {
|
|
178
|
+
killProcessTree: opts.deps?.killProcessTree || killProcessTree,
|
|
179
|
+
killProcessTreeSnapshot:
|
|
180
|
+
opts.deps?.killProcessTreeSnapshot || killProcessTreeSnapshot,
|
|
181
|
+
findProcessTree: opts.deps?.findProcessTree || findProcessTree,
|
|
182
|
+
};
|
|
183
|
+
const {
|
|
184
|
+
logsDir,
|
|
185
|
+
maxRestarts = DEFAULT_MAX_RESTARTS,
|
|
186
|
+
graceMs = DEFAULT_GRACE_MS,
|
|
187
|
+
probeOpts = {},
|
|
188
|
+
broker: optsBroker,
|
|
189
|
+
} = opts;
|
|
190
|
+
|
|
191
|
+
if (!logsDir) throw new Error("logsDir is required");
|
|
192
|
+
mkdirSync(logsDir, { recursive: true });
|
|
193
|
+
|
|
194
|
+
const emitter = new EventEmitter();
|
|
195
|
+
const sessions = new Map();
|
|
196
|
+
let shuttingDown = false;
|
|
197
|
+
const publicApi = null;
|
|
198
|
+
const synapseOpts = {
|
|
199
|
+
baseUrl: opts.synapseBaseUrl,
|
|
200
|
+
fetchImpl: opts.synapseFetch,
|
|
201
|
+
};
|
|
202
|
+
const getActiveBroker = () => optsBroker ?? broker;
|
|
203
|
+
|
|
204
|
+
function buildSynapseMeta(session, state = session.state, reason = "") {
|
|
205
|
+
return {
|
|
206
|
+
sessionId: session.id,
|
|
207
|
+
host:
|
|
208
|
+
typeof session.config.host === "string" &&
|
|
209
|
+
session.config.host.length > 0
|
|
210
|
+
? session.config.host
|
|
211
|
+
: "local",
|
|
212
|
+
taskSummary: buildSynapseTaskSummary(session.config.prompt),
|
|
213
|
+
status: state,
|
|
214
|
+
reason,
|
|
215
|
+
isRemote: Boolean(session.config.remote),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 공유 event log (모든 세션 이벤트를 하나의 JSONL에)
|
|
220
|
+
const eventLog = createEventLog(join(logsDir, "conductor-events.jsonl"));
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 세션 상태 전이.
|
|
224
|
+
* @param {object} session
|
|
225
|
+
* @param {string} nextState
|
|
226
|
+
* @param {string} [reason]
|
|
227
|
+
*/
|
|
228
|
+
function transition(session, nextState, reason = "") {
|
|
229
|
+
const valid = TRANSITIONS[session.state] || [];
|
|
230
|
+
if (!valid.includes(nextState)) {
|
|
231
|
+
eventLog.append("invalid_transition", {
|
|
232
|
+
session: session.id,
|
|
233
|
+
from: session.state,
|
|
234
|
+
to: nextState,
|
|
235
|
+
reason,
|
|
236
|
+
});
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const prev = session.state;
|
|
241
|
+
session.state = nextState;
|
|
242
|
+
|
|
243
|
+
eventLog.append("stateChange", {
|
|
244
|
+
session: session.id,
|
|
245
|
+
from: prev,
|
|
246
|
+
to: nextState,
|
|
247
|
+
reason,
|
|
248
|
+
restarts: session.restarts,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
emitter.emit("stateChange", {
|
|
252
|
+
sessionId: session.id,
|
|
253
|
+
from: prev,
|
|
254
|
+
to: nextState,
|
|
255
|
+
reason,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
if (nextState === STATES.HEALTHY) {
|
|
259
|
+
registerSynapseSession(
|
|
260
|
+
buildSynapseMeta(session, nextState, reason),
|
|
261
|
+
synapseOpts,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
heartbeatSynapseSession(
|
|
265
|
+
session.id,
|
|
266
|
+
buildSynapseMeta(session, nextState, reason),
|
|
267
|
+
synapseOpts,
|
|
268
|
+
);
|
|
269
|
+
if (nextState === STATES.COMPLETED || nextState === STATES.DEAD) {
|
|
270
|
+
unregisterSynapseSession(session.id, synapseOpts);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Terminal state cleanup
|
|
274
|
+
if (TERMINAL_STATES.has(nextState)) {
|
|
275
|
+
session.probe?.stop();
|
|
276
|
+
getConductorRegistry()?.unregister?.(session.id, publicApi);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 프로세스를 강제 종료.
|
|
284
|
+
* Windows: taskkill /T /F /PID (프로세스 트리). POSIX: SIGKILL.
|
|
285
|
+
*/
|
|
286
|
+
function forceKill(pid) {
|
|
287
|
+
if (!pid || pid <= 0) return;
|
|
288
|
+
killProcess(pid, {
|
|
289
|
+
signal: "SIGKILL",
|
|
290
|
+
tree: true,
|
|
291
|
+
force: true,
|
|
292
|
+
timeout: 5000,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 원격 세션의 psmux 세션을 SSH 경유로 kill.
|
|
298
|
+
* fire-and-forget: 실패해도 에러 전파 안 함.
|
|
299
|
+
*/
|
|
300
|
+
function killRemoteSession(session) {
|
|
301
|
+
const host = session.config.host;
|
|
302
|
+
if (!host) return;
|
|
303
|
+
let sshUser = session.config.sshUser;
|
|
304
|
+
let sshIp = host;
|
|
305
|
+
// hosts.json에서 ssh_user/IP 해결
|
|
306
|
+
try {
|
|
307
|
+
const hostsPath = join(
|
|
308
|
+
opts.repoRoot || process.cwd(),
|
|
309
|
+
"references",
|
|
310
|
+
"hosts.json",
|
|
311
|
+
);
|
|
312
|
+
const hosts = JSON.parse(readFileSync(hostsPath, "utf8"));
|
|
313
|
+
const hostCfg = hosts.hosts?.[host];
|
|
314
|
+
if (hostCfg) {
|
|
315
|
+
sshUser = sshUser || hostCfg.ssh_user;
|
|
316
|
+
sshIp = hostCfg.tailscale?.ip || host;
|
|
317
|
+
}
|
|
318
|
+
} catch {
|
|
319
|
+
/* hosts.json 없으면 fallback */
|
|
320
|
+
}
|
|
321
|
+
if (!sshUser) return;
|
|
322
|
+
const execFn = opts.deps?.execFile || execFile;
|
|
323
|
+
execFn(
|
|
324
|
+
"ssh",
|
|
325
|
+
[`${sshUser}@${sshIp}`, "psmux", "kill-session", "-t", session.id],
|
|
326
|
+
{ timeout: 10_000, reason: "conductor:killRemoteSession" },
|
|
327
|
+
() => {},
|
|
328
|
+
);
|
|
329
|
+
eventLog.append("remote_kill", {
|
|
330
|
+
session: session.id,
|
|
331
|
+
host,
|
|
332
|
+
sshUser,
|
|
333
|
+
sshIp,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* 단일 세션의 child process를 정리.
|
|
339
|
+
* 원격 세션은 SSH 경유 psmux kill-session으로 정리.
|
|
340
|
+
*/
|
|
341
|
+
async function cleanupChild(session) {
|
|
342
|
+
session.probe?.stop();
|
|
343
|
+
|
|
344
|
+
// 원격 세션 — SSH 경유 psmux kill-session
|
|
345
|
+
if (session.config.remote) {
|
|
346
|
+
killRemoteSession(session);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const child = session.child;
|
|
351
|
+
if (!child) return;
|
|
352
|
+
|
|
353
|
+
const pid = child.pid;
|
|
354
|
+
if (!pid) return;
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
if (session.descendantSnapshot?.length > 0) {
|
|
358
|
+
processUtils.killProcessTreeSnapshot(session.descendantSnapshot);
|
|
359
|
+
}
|
|
360
|
+
} catch {
|
|
361
|
+
/* best-effort cleanup */
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (!session.alive) return;
|
|
365
|
+
|
|
366
|
+
// SIGTERM 먼저
|
|
367
|
+
try {
|
|
368
|
+
child.kill("SIGTERM");
|
|
369
|
+
} catch {
|
|
370
|
+
/* already dead */
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Grace period 대기
|
|
374
|
+
const exited = await new Promise((resolve) => {
|
|
375
|
+
const timer = setTimeout(() => {
|
|
376
|
+
resolve(false);
|
|
377
|
+
}, graceMs);
|
|
378
|
+
child.once("exit", () => {
|
|
379
|
+
clearTimeout(timer);
|
|
380
|
+
resolve(true);
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
if (!exited) {
|
|
385
|
+
try {
|
|
386
|
+
processUtils.killProcessTree(pid);
|
|
387
|
+
} catch {
|
|
388
|
+
forceKill(pid);
|
|
389
|
+
}
|
|
390
|
+
session.alive = false;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Health probe 콜백 — probe 결과에 따라 상태 전이 판단.
|
|
396
|
+
*/
|
|
397
|
+
function handleProbeResult(session, result) {
|
|
398
|
+
if (TERMINAL_STATES.has(session.state)) return;
|
|
399
|
+
if (session.state === STATES.INIT || session.state === STATES.RESTARTING)
|
|
400
|
+
return;
|
|
401
|
+
|
|
402
|
+
eventLog.append("health", {
|
|
403
|
+
session: session.id,
|
|
404
|
+
...result,
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// L0 실패 — 로컬: exit handler에서 처리. 원격: probe가 유일한 감지 수단.
|
|
408
|
+
if (result.l0 === "fail") {
|
|
409
|
+
if (session.config.remote) {
|
|
410
|
+
handleFailure(session, "remote_L0_fail");
|
|
411
|
+
}
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// L3 completed (원격 완료 토큰 감지)
|
|
416
|
+
if (result.l3 === "completed" && session.config.remote) {
|
|
417
|
+
transition(session, STATES.COMPLETED, "remote_completion_token");
|
|
418
|
+
emitter.emit("completed", { sessionId: session.id });
|
|
419
|
+
if (typeof session.config.onCompleted === "function") {
|
|
420
|
+
session.config.onCompleted({ sessionId: session.id });
|
|
421
|
+
}
|
|
422
|
+
maybeAutoShutdown();
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// L1 INPUT_WAIT 감지
|
|
427
|
+
if (result.l1 === "input_wait" && session.state === STATES.HEALTHY) {
|
|
428
|
+
transition(
|
|
429
|
+
session,
|
|
430
|
+
STATES.INPUT_WAIT,
|
|
431
|
+
`input_wait:${result.inputWaitPattern}`,
|
|
432
|
+
);
|
|
433
|
+
emitter.emit("inputWait", {
|
|
434
|
+
sessionId: session.id,
|
|
435
|
+
pattern: result.inputWaitPattern,
|
|
436
|
+
});
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// INPUT_WAIT → output 재개 시 HEALTHY 복귀
|
|
441
|
+
if (session.state === STATES.INPUT_WAIT && result.l1 === "ok") {
|
|
442
|
+
transition(session, STATES.HEALTHY, "output_resumed");
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// L1 stall
|
|
447
|
+
if (result.l1 === "stall" && session.state === STATES.HEALTHY) {
|
|
448
|
+
transition(session, STATES.STALLED, "L1_stall");
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// STALLED → output 재개 시 HEALTHY 복귀
|
|
453
|
+
if (session.state === STATES.STALLED && result.l1 === "ok") {
|
|
454
|
+
transition(session, STATES.HEALTHY, "output_resumed");
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// L3 timeout (아직 STARTING 상태)
|
|
459
|
+
if (result.l3 === "timeout" && session.state === STATES.STARTING) {
|
|
460
|
+
handleFailure(session, "L3_timeout");
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// STARTING → L0 ok + L3 ok → HEALTHY
|
|
465
|
+
if (
|
|
466
|
+
session.state === STATES.STARTING &&
|
|
467
|
+
result.l0 === "ok" &&
|
|
468
|
+
result.l3 === "ok"
|
|
469
|
+
) {
|
|
470
|
+
transition(session, STATES.HEALTHY, "probe_healthy");
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// STARTING → L0 ok (L3 아직 미판정) → STARTING 유지 (대기)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* 실패 처리 — restart 또는 DEAD.
|
|
479
|
+
*/
|
|
480
|
+
async function handleFailure(session, reason) {
|
|
481
|
+
if (TERMINAL_STATES.has(session.state)) return;
|
|
482
|
+
|
|
483
|
+
transition(session, STATES.FAILED, reason);
|
|
484
|
+
|
|
485
|
+
if (session.restarts < maxRestarts) {
|
|
486
|
+
transition(
|
|
487
|
+
session,
|
|
488
|
+
STATES.RESTARTING,
|
|
489
|
+
`restart_${session.restarts + 1}/${maxRestarts}`,
|
|
490
|
+
);
|
|
491
|
+
session.restarts += 1;
|
|
492
|
+
const backoffMs = Math.min(1000 * 2 ** (session.restarts - 1), 30_000);
|
|
493
|
+
session._respawnTimer = setTimeout(() => {
|
|
494
|
+
session._respawnTimer = null;
|
|
495
|
+
if (session.config.remote) {
|
|
496
|
+
startRemoteSession(session);
|
|
497
|
+
} else {
|
|
498
|
+
void respawnSession(session);
|
|
499
|
+
}
|
|
500
|
+
}, backoffMs);
|
|
501
|
+
} else {
|
|
502
|
+
await cleanupChild(session);
|
|
503
|
+
transition(session, STATES.DEAD, `maxRestarts(${maxRestarts})_exceeded`);
|
|
504
|
+
emitter.emit("dead", { sessionId: session.id, reason });
|
|
505
|
+
|
|
506
|
+
// broker release on final death
|
|
507
|
+
const activeBroker = getActiveBroker();
|
|
508
|
+
if (activeBroker && session.config.accountId) {
|
|
509
|
+
activeBroker.release(session.config.accountId, {
|
|
510
|
+
ok: false,
|
|
511
|
+
failureMode: session.lastFailureMode,
|
|
512
|
+
});
|
|
513
|
+
if (session.lastFailureMode === "rate_limited") {
|
|
514
|
+
activeBroker.markRateLimited(session.config.accountId, 5 * 60 * 1000);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* 세션의 child process를 (재)시작.
|
|
522
|
+
*/
|
|
523
|
+
async function respawnSession(session) {
|
|
524
|
+
// 기존 child 정리
|
|
525
|
+
await cleanupChild(session);
|
|
526
|
+
|
|
527
|
+
transition(
|
|
528
|
+
session,
|
|
529
|
+
STATES.STARTING,
|
|
530
|
+
session.restarts > 0 ? "respawn" : "initial",
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
const launcher = session.launcher;
|
|
534
|
+
const outPath = join(logsDir, `${session.id}.out.log`);
|
|
535
|
+
const errPath = join(logsDir, `${session.id}.err.log`);
|
|
536
|
+
mkdirSync(logsDir, { recursive: true });
|
|
537
|
+
|
|
538
|
+
const outWs = createWriteStream(outPath, { flags: "a" });
|
|
539
|
+
const errWs = createWriteStream(errPath, { flags: "a" });
|
|
540
|
+
|
|
541
|
+
let outputBytes = 0;
|
|
542
|
+
let recentOutput = "";
|
|
543
|
+
// #115 F7 wiring: stdout-only tail for completion payload extraction.
|
|
544
|
+
let stdoutTail = "";
|
|
545
|
+
// #125: sentinel-framed capture (preferred over the 16 KiB tail; survives
|
|
546
|
+
// payloads larger than the sliding window).
|
|
547
|
+
const sentinelCapture = createSentinelCapture();
|
|
548
|
+
|
|
549
|
+
const spawnCwd = session.config.workdir || launcher.cwd || undefined;
|
|
550
|
+
const spawnSpec = buildSpawnSpecForMode(MODES.HEADLESS, {
|
|
551
|
+
cli: session.config.agent,
|
|
552
|
+
prompt: session.config.prompt,
|
|
553
|
+
profile: session.config.profile,
|
|
554
|
+
model: session.config.model,
|
|
555
|
+
mcpServers: session.config.mcpServers,
|
|
556
|
+
resolveCommand: opts.deps?.resolveCliExecutable,
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
// #90 branch guard: shard spawn cwd가 main 브랜치면 즉시 abort.
|
|
560
|
+
// swarm shard는 반드시 shard 전용 worktree 브랜치에서 실행되어야 한다.
|
|
561
|
+
// cwd fallback으로 main working tree에 떨어진 경우 차단.
|
|
562
|
+
if (session.config.branchGuard && spawnCwd) {
|
|
563
|
+
try {
|
|
564
|
+
const r = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
565
|
+
cwd: spawnCwd,
|
|
566
|
+
encoding: "utf8",
|
|
567
|
+
windowsHide: true,
|
|
568
|
+
timeout: 5_000,
|
|
569
|
+
});
|
|
570
|
+
const curBranch = String(r.stdout || "").trim();
|
|
571
|
+
if (curBranch === "main" || curBranch === "master") {
|
|
572
|
+
eventLog.append("branch_guard_refused", {
|
|
573
|
+
session: session.id,
|
|
574
|
+
cwd: spawnCwd,
|
|
575
|
+
branch: curBranch,
|
|
576
|
+
});
|
|
577
|
+
handleFailure(session, `branch_guard:${curBranch}_refused`);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
} catch (err) {
|
|
581
|
+
eventLog.append("branch_guard_probe_failed", {
|
|
582
|
+
session: session.id,
|
|
583
|
+
cwd: spawnCwd,
|
|
584
|
+
error: err.message,
|
|
585
|
+
});
|
|
586
|
+
// 프로브 실패는 비차단 — git 미설치/non-repo 환경 대응
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const spawnEnv = {
|
|
591
|
+
...process.env,
|
|
592
|
+
...launcher.env,
|
|
593
|
+
...(session.config.env || {}),
|
|
594
|
+
...(session.config.branchGuard ? { TRIFLUX_GIT_BRANCH_GUARD: "1" } : {}),
|
|
595
|
+
};
|
|
596
|
+
if (session.config.workerSandbox?.root) {
|
|
597
|
+
eventLog.append("worker_sandbox_env", {
|
|
598
|
+
session: session.id,
|
|
599
|
+
root: session.config.workerSandbox.root,
|
|
600
|
+
codeHomePreserved: Boolean(spawnEnv.CODEX_HOME),
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
let child;
|
|
605
|
+
try {
|
|
606
|
+
child = spawnFn(spawnSpec.command, spawnSpec.args, {
|
|
607
|
+
shell: false,
|
|
608
|
+
cwd: spawnCwd,
|
|
609
|
+
env: spawnEnv,
|
|
610
|
+
reason: `conductor:respawnSession:${session.id}`,
|
|
611
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
612
|
+
windowsHide: true,
|
|
613
|
+
});
|
|
614
|
+
} catch (err) {
|
|
615
|
+
eventLog.append("spawn_error", {
|
|
616
|
+
session: session.id,
|
|
617
|
+
error: err.message,
|
|
618
|
+
cwd: spawnCwd || null,
|
|
619
|
+
command: spawnSpec.command,
|
|
620
|
+
});
|
|
621
|
+
handleFailure(session, `spawn_error:${err.message}`);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
session.child = child;
|
|
626
|
+
session.outPath = outPath;
|
|
627
|
+
session.errPath = errPath;
|
|
628
|
+
session.descendantSnapshot = [];
|
|
629
|
+
|
|
630
|
+
// #116-C: spawnSpec.stdinPrompt 가 true 면 codex 의 oh-my-codex hook
|
|
631
|
+
// (macOS) 가 매우 긴 argv-inline prompt 에서 SessionStart Failed → exit 1
|
|
632
|
+
// 회귀를 유발하므로 prompt 를 stdin write 로 분리해서 전달한다.
|
|
633
|
+
// stdinPrompt 없으면 기존 흐름 — codex "Reading additional input..." 대기
|
|
634
|
+
// 방지를 위해 stdin 즉시 닫기.
|
|
635
|
+
if (child.stdin) {
|
|
636
|
+
if (spawnSpec.stdinPrompt && typeof spawnSpec.prompt === "string") {
|
|
637
|
+
try {
|
|
638
|
+
child.stdin.write(spawnSpec.prompt);
|
|
639
|
+
} catch (err) {
|
|
640
|
+
eventLog.append("spawn_stdin_write_error", {
|
|
641
|
+
session: session.id,
|
|
642
|
+
error: err.message,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
child.stdin.end();
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
eventLog.append("spawn", {
|
|
650
|
+
session: session.id,
|
|
651
|
+
agent: session.config.agent,
|
|
652
|
+
pid: child.pid,
|
|
653
|
+
command: spawnSpec.command,
|
|
654
|
+
args: spawnSpec.args,
|
|
655
|
+
legacyCommand: launcher.command,
|
|
656
|
+
restart: session.restarts,
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
if (session._descendantSnapshotTimer) {
|
|
660
|
+
clearTimeout(session._descendantSnapshotTimer);
|
|
661
|
+
}
|
|
662
|
+
session._descendantSnapshotTimer = setTimeout(() => {
|
|
663
|
+
session._descendantSnapshotTimer = null;
|
|
664
|
+
if (session.child !== child) return;
|
|
665
|
+
try {
|
|
666
|
+
session.descendantSnapshot = processUtils.findProcessTree(child.pid);
|
|
667
|
+
} catch {
|
|
668
|
+
/* best-effort snapshot */
|
|
669
|
+
}
|
|
670
|
+
}, 200);
|
|
671
|
+
|
|
672
|
+
// stdout+stderr 통합 추적 (F3 해결: stderr만 출력되는 경우도 advancing 판정)
|
|
673
|
+
const trackOutput = (buf) => {
|
|
674
|
+
outputBytes += buf.length;
|
|
675
|
+
const txt = String(buf);
|
|
676
|
+
// 최근 2KB만 유지 (INPUT_WAIT 패턴 감지용)
|
|
677
|
+
recentOutput += txt;
|
|
678
|
+
if (recentOutput.length > 2048) {
|
|
679
|
+
recentOutput = recentOutput.slice(-2048);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
child.stdout?.on("data", (buf) => {
|
|
684
|
+
outWs.write(buf);
|
|
685
|
+
trackOutput(buf);
|
|
686
|
+
const text = buf.toString("utf8");
|
|
687
|
+
stdoutTail = (stdoutTail + text).slice(-16384);
|
|
688
|
+
sentinelCapture.push(text);
|
|
689
|
+
});
|
|
690
|
+
child.stderr?.on("data", (buf) => {
|
|
691
|
+
errWs.write(buf);
|
|
692
|
+
trackOutput(buf);
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
child.on("exit", (code, signal) => {
|
|
696
|
+
session.alive = false;
|
|
697
|
+
if (session._descendantSnapshotTimer) {
|
|
698
|
+
clearTimeout(session._descendantSnapshotTimer);
|
|
699
|
+
session._descendantSnapshotTimer = null;
|
|
700
|
+
}
|
|
701
|
+
try {
|
|
702
|
+
outWs.end();
|
|
703
|
+
} catch {
|
|
704
|
+
/* ignore */
|
|
705
|
+
}
|
|
706
|
+
try {
|
|
707
|
+
errWs.end();
|
|
708
|
+
} catch {
|
|
709
|
+
/* ignore */
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
eventLog.append("exit", {
|
|
713
|
+
session: session.id,
|
|
714
|
+
code,
|
|
715
|
+
signal,
|
|
716
|
+
restart: session.restarts,
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
if (TERMINAL_STATES.has(session.state)) return;
|
|
720
|
+
if (shuttingDown) return;
|
|
721
|
+
|
|
722
|
+
if (code === 0 && !signal) {
|
|
723
|
+
transition(session, STATES.COMPLETED, "exit_0");
|
|
724
|
+
// #125 Codex R1 MEDIUM: if sentinel capture overflowed past maxBytes
|
|
725
|
+
// and lost its BEGIN marker, do NOT fall back to stdoutTail/brace-scan
|
|
726
|
+
// — the worker tried sentinel protocol and the payload was clearly
|
|
727
|
+
// unbounded. Surface as "no payload" rather than silent partial.
|
|
728
|
+
let extracted;
|
|
729
|
+
if (sentinelCapture.isOverflow()) {
|
|
730
|
+
extracted = null;
|
|
731
|
+
} else {
|
|
732
|
+
const sentinelSnapshot = sentinelCapture.snapshot();
|
|
733
|
+
extracted = extractCompletionPayload(sentinelSnapshot || stdoutTail);
|
|
734
|
+
}
|
|
735
|
+
const completionPayload = extracted ? extracted.payload : undefined;
|
|
736
|
+
emitter.emit("completed", { sessionId: session.id, completionPayload });
|
|
737
|
+
if (typeof session.config.onCompleted === "function") {
|
|
738
|
+
session.config.onCompleted({
|
|
739
|
+
sessionId: session.id,
|
|
740
|
+
completionPayload,
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const activeBroker = getActiveBroker();
|
|
744
|
+
if (activeBroker && session.config.accountId) {
|
|
745
|
+
activeBroker.release(session.config.accountId, { ok: true });
|
|
746
|
+
}
|
|
747
|
+
} else {
|
|
748
|
+
// detect rate_limited from recent output before handleFailure
|
|
749
|
+
if (
|
|
750
|
+
/(rate.?limit|quota|throttl|too.many.requests|429|usage.limit)/iu.test(
|
|
751
|
+
recentOutput,
|
|
752
|
+
)
|
|
753
|
+
) {
|
|
754
|
+
session.lastFailureMode = "rate_limited";
|
|
755
|
+
}
|
|
756
|
+
handleFailure(session, `exit_code:${code},signal:${signal}`);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
maybeAutoShutdown();
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
child.on("error", (err) => {
|
|
763
|
+
session.alive = false;
|
|
764
|
+
if (session._descendantSnapshotTimer) {
|
|
765
|
+
clearTimeout(session._descendantSnapshotTimer);
|
|
766
|
+
session._descendantSnapshotTimer = null;
|
|
767
|
+
}
|
|
768
|
+
eventLog.append("child_error", {
|
|
769
|
+
session: session.id,
|
|
770
|
+
error: err.message,
|
|
771
|
+
});
|
|
772
|
+
if (!shuttingDown && !TERMINAL_STATES.has(session.state)) {
|
|
773
|
+
handleFailure(session, `child_error:${err.message}`);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
session.alive = true;
|
|
778
|
+
|
|
779
|
+
// Health probe 설정
|
|
780
|
+
session.probe?.stop();
|
|
781
|
+
const probe = createHealthProbe(
|
|
782
|
+
{
|
|
783
|
+
get pid() {
|
|
784
|
+
return child.pid;
|
|
785
|
+
},
|
|
786
|
+
get alive() {
|
|
787
|
+
return session.alive;
|
|
788
|
+
},
|
|
789
|
+
getOutputBytes: () => outputBytes,
|
|
790
|
+
getRecentOutput: () => recentOutput,
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
...probeOpts,
|
|
794
|
+
// #165: default off → on. atomic write (#162) 로 race 제거됨.
|
|
795
|
+
// opt-out: TFX_PROBE_WRITE_STATE=0 명시.
|
|
796
|
+
writeStateFile:
|
|
797
|
+
probeOpts.writeStateFile ?? process.env.TFX_PROBE_WRITE_STATE !== "0",
|
|
798
|
+
// #168 P3: L2 (hub /health) checker wiring. probeOpts 가 명시 주입하면
|
|
799
|
+
// 그걸 우선. 아니면 TFX_PROBE_L2=0 로 opt-out. 나머지 경우 hub URL 기반
|
|
800
|
+
// default checker 주입 → deriveState 가 `mcp_initializing` 라벨을 생산 →
|
|
801
|
+
// heartbeat (read_probe_state) 가 probe-grace 분기로 감.
|
|
802
|
+
enableL2: probeOpts.enableL2 ?? process.env.TFX_PROBE_L2 !== "0",
|
|
803
|
+
checkMcp:
|
|
804
|
+
probeOpts.checkMcp ||
|
|
805
|
+
(process.env.TFX_PROBE_L2 === "0"
|
|
806
|
+
? undefined
|
|
807
|
+
: createHubHealthChecker({ hubUrl: process.env.TFX_HUB_URL })),
|
|
808
|
+
onProbe: (result) => handleProbeResult(session, result),
|
|
809
|
+
},
|
|
810
|
+
);
|
|
811
|
+
session.probe = probe;
|
|
812
|
+
probe.start();
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* 원격 세션 시작 — SSH child process로 직접 실행.
|
|
817
|
+
* psmux 불필요. 원격 호스트에서 claude -p 를 SSH 경유로 실행하고
|
|
818
|
+
* 로컬 child process로 관리한다.
|
|
819
|
+
*/
|
|
820
|
+
function startRemoteSession(session) {
|
|
821
|
+
transition(session, STATES.STARTING, "remote_initial");
|
|
822
|
+
|
|
823
|
+
const { host, prompt, agent, workdir: remoteWorkdir } = session.config;
|
|
824
|
+
|
|
825
|
+
// SSH args를 배열로 구성하여 셸 이스케이프 문제 회피
|
|
826
|
+
const cdPrefix = remoteWorkdir ? `cd ${remoteWorkdir} && ` : "";
|
|
827
|
+
|
|
828
|
+
let remoteBin;
|
|
829
|
+
if (agent === "claude") {
|
|
830
|
+
remoteBin = "claude --output-format text";
|
|
831
|
+
} else if (agent === "gemini") {
|
|
832
|
+
remoteBin = "gemini -y";
|
|
833
|
+
} else {
|
|
834
|
+
remoteBin =
|
|
835
|
+
"codex exec -s danger-full-access --dangerously-bypass-approvals-and-sandbox";
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// prompt는 stdin으로 전달 — 셸 이스케이프 문제 완전 회피
|
|
839
|
+
const sshArgs = [
|
|
840
|
+
"-o",
|
|
841
|
+
"ConnectTimeout=30",
|
|
842
|
+
"-o",
|
|
843
|
+
"BatchMode=yes",
|
|
844
|
+
host,
|
|
845
|
+
`${cdPrefix}${remoteBin}`,
|
|
846
|
+
];
|
|
847
|
+
|
|
848
|
+
const sshCmd = `ssh ${sshArgs.join(" ")}`;
|
|
849
|
+
|
|
850
|
+
eventLog.append("remote_start", {
|
|
851
|
+
session: session.id,
|
|
852
|
+
host,
|
|
853
|
+
command: sshCmd,
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
const outPath = join(logsDir, `${session.id}.out.log`);
|
|
857
|
+
const errPath = join(logsDir, `${session.id}.err.log`);
|
|
858
|
+
const outWs = createWriteStream(outPath, { flags: "a" });
|
|
859
|
+
const errWs = createWriteStream(errPath, { flags: "a" });
|
|
860
|
+
|
|
861
|
+
let child;
|
|
862
|
+
try {
|
|
863
|
+
child = spawnFn("ssh", sshArgs, {
|
|
864
|
+
env: process.env,
|
|
865
|
+
reason: `conductor:remoteSession:${session.id}`,
|
|
866
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
867
|
+
windowsHide: true,
|
|
868
|
+
});
|
|
869
|
+
} catch (err) {
|
|
870
|
+
eventLog.append("spawn_error", {
|
|
871
|
+
session: session.id,
|
|
872
|
+
error: err.message,
|
|
873
|
+
});
|
|
874
|
+
handleFailure(session, `spawn_error:${err.message}`);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
session.child = child;
|
|
879
|
+
session.outPath = outPath;
|
|
880
|
+
session.errPath = errPath;
|
|
881
|
+
session.alive = true;
|
|
882
|
+
|
|
883
|
+
// stdin으로 프롬프트 전달 — 셸 이스케이프 완전 우회
|
|
884
|
+
if (child.stdin) {
|
|
885
|
+
child.stdin.write(prompt);
|
|
886
|
+
child.stdin.end();
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
eventLog.append("spawn", {
|
|
890
|
+
session: session.id,
|
|
891
|
+
agent,
|
|
892
|
+
pid: child.pid,
|
|
893
|
+
command: sshCmd,
|
|
894
|
+
remote: true,
|
|
895
|
+
host,
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
// stdout/stderr 추적 (recentOutput으로 rate_limit 패턴 감지 가능)
|
|
899
|
+
let outputBytes = 0;
|
|
900
|
+
let recentOutput = "";
|
|
901
|
+
// #115 F7 wiring: stdout-only tail for completion payload extraction.
|
|
902
|
+
let stdoutTail = "";
|
|
903
|
+
// #125: sentinel-framed capture (preferred over the 16 KiB tail).
|
|
904
|
+
const sentinelCapture = createSentinelCapture();
|
|
905
|
+
const trackOutput = (buf) => {
|
|
906
|
+
outputBytes += buf.length;
|
|
907
|
+
const text = buf.toString("utf8");
|
|
908
|
+
recentOutput = (recentOutput + text).slice(-2000);
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
child.stdout?.on("data", (buf) => {
|
|
912
|
+
trackOutput(buf);
|
|
913
|
+
outWs.write(buf);
|
|
914
|
+
const text = buf.toString("utf8");
|
|
915
|
+
stdoutTail = (stdoutTail + text).slice(-16384);
|
|
916
|
+
sentinelCapture.push(text);
|
|
917
|
+
});
|
|
918
|
+
child.stderr?.on("data", (buf) => {
|
|
919
|
+
trackOutput(buf);
|
|
920
|
+
errWs.write(buf);
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
// 상태를 healthy로 전이
|
|
924
|
+
transition(session, STATES.HEALTHY, "remote_ssh_spawned");
|
|
925
|
+
|
|
926
|
+
// Health probe — 주기적으로 출력 변화 체크 (F3 stall 감지)
|
|
927
|
+
let lastBytes = 0;
|
|
928
|
+
let stallChecks = 0;
|
|
929
|
+
const stallThreshold = probeOpts.stallChecks || 8; // 8 * intervalMs = stall
|
|
930
|
+
const healthInterval = setInterval(() => {
|
|
931
|
+
if (TERMINAL_STATES.has(session.state)) {
|
|
932
|
+
clearInterval(healthInterval);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (outputBytes > lastBytes) {
|
|
936
|
+
lastBytes = outputBytes;
|
|
937
|
+
stallChecks = 0;
|
|
938
|
+
if (session.state !== STATES.HEALTHY) {
|
|
939
|
+
transition(session, STATES.HEALTHY, "output_advancing");
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
stallChecks++;
|
|
943
|
+
if (stallChecks >= stallThreshold && session.state === STATES.HEALTHY) {
|
|
944
|
+
transition(session, STATES.STALLED, "remote_no_output");
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}, probeOpts.intervalMs || 5000);
|
|
948
|
+
|
|
949
|
+
// exit 핸들러
|
|
950
|
+
child.once("exit", (code) => {
|
|
951
|
+
clearInterval(healthInterval);
|
|
952
|
+
outWs.end();
|
|
953
|
+
errWs.end();
|
|
954
|
+
session.alive = false;
|
|
955
|
+
|
|
956
|
+
eventLog.append("remote_exit", {
|
|
957
|
+
session: session.id,
|
|
958
|
+
code,
|
|
959
|
+
outputBytes,
|
|
960
|
+
host,
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
if (shuttingDown || TERMINAL_STATES.has(session.state)) return;
|
|
964
|
+
|
|
965
|
+
// 원격 세션은 broker lease를 사용하지 않으므로 release 불필요
|
|
966
|
+
// (spawnSession에서 config.remote === true일 때 lease 건너뜀)
|
|
967
|
+
if (code === 0) {
|
|
968
|
+
transition(session, STATES.COMPLETED, `exit_${code}`);
|
|
969
|
+
// #125 Codex R1 MEDIUM: same overflow guard as the local exit path.
|
|
970
|
+
let extracted;
|
|
971
|
+
if (sentinelCapture.isOverflow()) {
|
|
972
|
+
extracted = null;
|
|
973
|
+
} else {
|
|
974
|
+
const sentinelSnapshot = sentinelCapture.snapshot();
|
|
975
|
+
extracted = extractCompletionPayload(sentinelSnapshot || stdoutTail);
|
|
976
|
+
}
|
|
977
|
+
const completionPayload = extracted ? extracted.payload : undefined;
|
|
978
|
+
emitter.emit("completed", { sessionId: session.id, completionPayload });
|
|
979
|
+
if (typeof session.config.onCompleted === "function") {
|
|
980
|
+
session.config.onCompleted({
|
|
981
|
+
sessionId: session.id,
|
|
982
|
+
completionPayload,
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
maybeAutoShutdown();
|
|
986
|
+
} else {
|
|
987
|
+
handleFailure(session, `remote_exit_${code}`);
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
child.once("error", (err) => {
|
|
992
|
+
clearInterval(healthInterval);
|
|
993
|
+
outWs.end();
|
|
994
|
+
errWs.end();
|
|
995
|
+
eventLog.append("spawn_error", {
|
|
996
|
+
session: session.id,
|
|
997
|
+
error: err.message,
|
|
998
|
+
});
|
|
999
|
+
if (!shuttingDown && !TERMINAL_STATES.has(session.state)) {
|
|
1000
|
+
handleFailure(session, `spawn_error:${err.message}`);
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* 모든 세션이 terminal이면 auto-shutdown.
|
|
1007
|
+
*/
|
|
1008
|
+
function maybeAutoShutdown() {
|
|
1009
|
+
if (shuttingDown) return;
|
|
1010
|
+
const allTerminal = [...sessions.values()].every((s) =>
|
|
1011
|
+
TERMINAL_STATES.has(s.state),
|
|
1012
|
+
);
|
|
1013
|
+
if (allTerminal && sessions.size > 0) {
|
|
1014
|
+
emitter.emit("allCompleted");
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// ── Public API ──────────────────────────────────────────────
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* 새 세션 spawn.
|
|
1022
|
+
* @param {object} config
|
|
1023
|
+
* @param {string} config.id — 세션 ID (unique)
|
|
1024
|
+
* @param {'codex'|'gemini'|'claude'} config.agent
|
|
1025
|
+
* @param {string} config.prompt
|
|
1026
|
+
* @param {string} [config.profile]
|
|
1027
|
+
* @param {string} [config.workdir]
|
|
1028
|
+
* @param {string} [config.model]
|
|
1029
|
+
* @param {boolean} [config.remote=false] — 원격 세션 여부
|
|
1030
|
+
* @param {string} [config.host] — SSH 호스트 (remote=true 필수)
|
|
1031
|
+
* @param {string} [config.paneTarget] — psmux pane target (remote용)
|
|
1032
|
+
* @param {string} [config.sessionName] — psmux 세션 이름 (remote용)
|
|
1033
|
+
* @param {function} [config.onCompleted] — 세션 완료 시 콜백 ({sessionId}) => void
|
|
1034
|
+
* @returns {string} session ID
|
|
1035
|
+
*/
|
|
1036
|
+
function spawnSession(config) {
|
|
1037
|
+
if (shuttingDown) throw new Error("Conductor is shutting down");
|
|
1038
|
+
if (!config.id) throw new Error("session id is required");
|
|
1039
|
+
if (sessions.has(config.id))
|
|
1040
|
+
throw new Error(`Session "${config.id}" already exists`);
|
|
1041
|
+
if (config.remote && !config.host)
|
|
1042
|
+
throw new Error("host is required for remote sessions");
|
|
1043
|
+
|
|
1044
|
+
// Phase 1 dynamic routing wire-up (opt-in env TRIFLUX_DYNAMIC_ROUTING).
|
|
1045
|
+
// sync 로만 평가해서 broker.lease atomic 인변량 (commit 761fb7a8 — leased
|
|
1046
|
+
// account = executing account) 을 깨지 않는다. snapshot 은 D-2 cache 의
|
|
1047
|
+
// sync getter 만 사용 — cache miss 면 evaluateDynamicRoute 가 fail-closed
|
|
1048
|
+
// 로 codex-default 를 반환한다.
|
|
1049
|
+
if (
|
|
1050
|
+
isDynamicRoutingEnabled(process.env) &&
|
|
1051
|
+
!config.remote &&
|
|
1052
|
+
config.agent
|
|
1053
|
+
) {
|
|
1054
|
+
try {
|
|
1055
|
+
const policy = dynamicRoutingInternal.loadPolicy();
|
|
1056
|
+
const snapshot = tryGetCachedSnapshot();
|
|
1057
|
+
const decision = evaluateDynamicRoute(
|
|
1058
|
+
{
|
|
1059
|
+
task_id: config.id,
|
|
1060
|
+
team_size: 1,
|
|
1061
|
+
agent_hint: config.agent,
|
|
1062
|
+
},
|
|
1063
|
+
snapshot || {},
|
|
1064
|
+
policy,
|
|
1065
|
+
{ now: Date.now() },
|
|
1066
|
+
);
|
|
1067
|
+
const shard = decision?.shards?.[0];
|
|
1068
|
+
if (shard?.cli && shard.cli !== config.agent) {
|
|
1069
|
+
eventLog.append("dynamic_route_override", {
|
|
1070
|
+
session: config.id,
|
|
1071
|
+
original: config.agent,
|
|
1072
|
+
override: shard.cli,
|
|
1073
|
+
scenario: decision.scenario ?? "unknown",
|
|
1074
|
+
decisionId: decision.decisionId ?? null,
|
|
1075
|
+
snapshotAgeMs: decision.snapshotAgeMs ?? null,
|
|
1076
|
+
});
|
|
1077
|
+
config = { ...config, agent: shard.cli };
|
|
1078
|
+
}
|
|
1079
|
+
} catch (err) {
|
|
1080
|
+
eventLog.append("dynamic_route_error", {
|
|
1081
|
+
session: config.id,
|
|
1082
|
+
error: err?.message || String(err),
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// broker lease (graceful — broker null if accounts.json absent)
|
|
1088
|
+
let lease = null;
|
|
1089
|
+
const activeBroker = getActiveBroker();
|
|
1090
|
+
if (activeBroker && config.agent && !config.remote) {
|
|
1091
|
+
lease = activeBroker.lease({ provider: config.agent });
|
|
1092
|
+
if (lease === null) {
|
|
1093
|
+
const eta = activeBroker.nextAvailableEta(config.agent);
|
|
1094
|
+
eventLog.append("broker_no_lease", {
|
|
1095
|
+
session: config.id,
|
|
1096
|
+
agent: config.agent,
|
|
1097
|
+
eta: eta ? new Date(eta).toISOString() : "unknown",
|
|
1098
|
+
});
|
|
1099
|
+
// 계정이 모두 cooldown이어도 세션 생성 자체는 유지한다.
|
|
1100
|
+
// 로컬 테스트/단일 계정 없는 환경에서도 상태 머신이 일관되게 동작해야 한다.
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// apply lease profile/env/auth to config (immutable — new object)
|
|
1105
|
+
const leaseEnv =
|
|
1106
|
+
lease?.authFile && config.agent === "codex"
|
|
1107
|
+
? { ...(lease.env || {}), CODEX_HOME: dirname(lease.authFile) }
|
|
1108
|
+
: lease?.env || {};
|
|
1109
|
+
|
|
1110
|
+
let resolvedConfig = lease
|
|
1111
|
+
? {
|
|
1112
|
+
...config,
|
|
1113
|
+
profile: lease.profile ?? config.profile,
|
|
1114
|
+
env: { ...(config.env || {}), ...leaseEnv },
|
|
1115
|
+
accountId: lease.id,
|
|
1116
|
+
}
|
|
1117
|
+
: {
|
|
1118
|
+
...config,
|
|
1119
|
+
env: { ...(config.env || {}) },
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
if (!resolvedConfig.remote) {
|
|
1123
|
+
const sandbox = buildWorkerSandboxEnv({
|
|
1124
|
+
cwd: resolvedConfig.workdir || process.cwd(),
|
|
1125
|
+
sessionId: resolvedConfig.id,
|
|
1126
|
+
env: { ...process.env, ...(resolvedConfig.env || {}) },
|
|
1127
|
+
});
|
|
1128
|
+
resolvedConfig = {
|
|
1129
|
+
...resolvedConfig,
|
|
1130
|
+
env: { ...(resolvedConfig.env || {}), ...sandbox.env },
|
|
1131
|
+
workerSandbox: sandbox.disabled
|
|
1132
|
+
? { disabled: true }
|
|
1133
|
+
: { root: sandbox.root, home: sandbox.home },
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// auth file copy — broker resolved absolute path, conductor does the actual copy
|
|
1138
|
+
swapAuthFile(
|
|
1139
|
+
lease,
|
|
1140
|
+
config.agent,
|
|
1141
|
+
config.id,
|
|
1142
|
+
eventLog,
|
|
1143
|
+
activeBroker,
|
|
1144
|
+
resolvedConfig.env,
|
|
1145
|
+
);
|
|
1146
|
+
|
|
1147
|
+
// 원격 세션은 launcher 불필요 (이미 원격에서 실행 중)
|
|
1148
|
+
const launcher = resolvedConfig.remote
|
|
1149
|
+
? null
|
|
1150
|
+
: buildLauncher({
|
|
1151
|
+
agent: resolvedConfig.agent,
|
|
1152
|
+
profile: resolvedConfig.profile,
|
|
1153
|
+
prompt: resolvedConfig.prompt,
|
|
1154
|
+
workdir: resolvedConfig.workdir,
|
|
1155
|
+
model: resolvedConfig.model,
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
const session = {
|
|
1159
|
+
id: resolvedConfig.id,
|
|
1160
|
+
config: resolvedConfig,
|
|
1161
|
+
launcher,
|
|
1162
|
+
state: STATES.INIT,
|
|
1163
|
+
child: null,
|
|
1164
|
+
probe: null,
|
|
1165
|
+
alive: false,
|
|
1166
|
+
restarts: 0,
|
|
1167
|
+
outPath: null,
|
|
1168
|
+
errPath: null,
|
|
1169
|
+
createdAt: Date.now(),
|
|
1170
|
+
descendantSnapshot: [],
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
sessions.set(resolvedConfig.id, session);
|
|
1174
|
+
getConductorRegistry()?.register?.(resolvedConfig.id, publicApi);
|
|
1175
|
+
|
|
1176
|
+
if (resolvedConfig.remote) {
|
|
1177
|
+
startRemoteSession(session);
|
|
1178
|
+
} else {
|
|
1179
|
+
void respawnSession(session);
|
|
1180
|
+
}
|
|
1181
|
+
return resolvedConfig.id;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* 세션 kill.
|
|
1186
|
+
* @param {string} id
|
|
1187
|
+
* @param {string} [reason]
|
|
1188
|
+
*/
|
|
1189
|
+
async function killSession(id, reason = "user_kill") {
|
|
1190
|
+
const session = sessions.get(id);
|
|
1191
|
+
if (!session) return;
|
|
1192
|
+
if (TERMINAL_STATES.has(session.state)) return;
|
|
1193
|
+
|
|
1194
|
+
if (session._respawnTimer) {
|
|
1195
|
+
clearTimeout(session._respawnTimer);
|
|
1196
|
+
session._respawnTimer = null;
|
|
1197
|
+
}
|
|
1198
|
+
eventLog.append("kill", { session: id, reason });
|
|
1199
|
+
await cleanupChild(session);
|
|
1200
|
+
transition(session, STATES.FAILED, reason);
|
|
1201
|
+
transition(session, STATES.DEAD, reason);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* 세션에 stdin 입력 전송 (INPUT_WAIT 해소용).
|
|
1206
|
+
* @param {string} id
|
|
1207
|
+
* @param {string} text
|
|
1208
|
+
*/
|
|
1209
|
+
function sendInput(id, text) {
|
|
1210
|
+
const session = sessions.get(id);
|
|
1211
|
+
if (!session) return false;
|
|
1212
|
+
|
|
1213
|
+
// 원격 세션 — stdin 미지원 (psmux send-keys는 별도 경로)
|
|
1214
|
+
if (session.config.remote) {
|
|
1215
|
+
eventLog.append("stdin_remote_unsupported", { session: id });
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
if (!session.child) return false;
|
|
1220
|
+
if (!session.child.stdin?.writable) return false;
|
|
1221
|
+
try {
|
|
1222
|
+
session.child.stdin.write(`${text}\n`);
|
|
1223
|
+
eventLog.append("stdin", { session: id, text: text.slice(0, 100) });
|
|
1224
|
+
return true;
|
|
1225
|
+
} catch {
|
|
1226
|
+
return false;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* 전체 세션 스냅샷.
|
|
1232
|
+
* @returns {object[]}
|
|
1233
|
+
*/
|
|
1234
|
+
function getSnapshot() {
|
|
1235
|
+
return [...sessions.values()].map((s) => ({
|
|
1236
|
+
id: s.id,
|
|
1237
|
+
agent: s.config.agent,
|
|
1238
|
+
state: s.state,
|
|
1239
|
+
pid: s.child?.pid || null,
|
|
1240
|
+
remote: s.config.remote || false,
|
|
1241
|
+
host: s.config.host || null,
|
|
1242
|
+
restarts: s.restarts,
|
|
1243
|
+
health: s.probe?.getStatus() || null,
|
|
1244
|
+
outPath: s.outPath,
|
|
1245
|
+
errPath: s.errPath,
|
|
1246
|
+
createdAt: s.createdAt,
|
|
1247
|
+
}));
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Graceful shutdown — 전체 세션 종료.
|
|
1252
|
+
*/
|
|
1253
|
+
async function shutdown(reason = "shutdown") {
|
|
1254
|
+
if (shuttingDown) return;
|
|
1255
|
+
shuttingDown = true;
|
|
1256
|
+
|
|
1257
|
+
eventLog.append("shutdown", { reason, sessions: sessions.size });
|
|
1258
|
+
|
|
1259
|
+
const cleanedSessionIds = new Set();
|
|
1260
|
+
const cleanups = [...sessions.values()]
|
|
1261
|
+
.filter((s) => {
|
|
1262
|
+
if (cleanedSessionIds.has(s.id)) return false;
|
|
1263
|
+
cleanedSessionIds.add(s.id);
|
|
1264
|
+
return true;
|
|
1265
|
+
})
|
|
1266
|
+
.map(async (s) => {
|
|
1267
|
+
if (s._respawnTimer) {
|
|
1268
|
+
clearTimeout(s._respawnTimer);
|
|
1269
|
+
s._respawnTimer = null;
|
|
1270
|
+
}
|
|
1271
|
+
if (s._descendantSnapshotTimer) {
|
|
1272
|
+
clearTimeout(s._descendantSnapshotTimer);
|
|
1273
|
+
s._descendantSnapshotTimer = null;
|
|
1274
|
+
}
|
|
1275
|
+
s.probe?.stop();
|
|
1276
|
+
await cleanupChild(s);
|
|
1277
|
+
if (!TERMINAL_STATES.has(s.state)) {
|
|
1278
|
+
transition(s, STATES.FAILED, reason);
|
|
1279
|
+
transition(s, STATES.DEAD, reason);
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
|
|
1283
|
+
await Promise.allSettled(cleanups);
|
|
1284
|
+
process.removeListener("SIGINT", onSignal);
|
|
1285
|
+
process.removeListener("SIGTERM", onSignal);
|
|
1286
|
+
if (brokerInstance && onTierFallback) {
|
|
1287
|
+
brokerInstance.removeListener("tierFallback", onTierFallback);
|
|
1288
|
+
}
|
|
1289
|
+
if (conductor._meshBridge) conductor._meshBridge.detach();
|
|
1290
|
+
await eventLog.flush();
|
|
1291
|
+
await eventLog.close();
|
|
1292
|
+
emitter.emit("shutdown");
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// ── broker tierFallback 구독 ──────────────────────────────────
|
|
1296
|
+
// 토큰 만료 등으로 상위 tier 계정이 불가능해지면, 활성 세션의 auth를 새 lease로 교체.
|
|
1297
|
+
const brokerInstance = optsBroker ?? null;
|
|
1298
|
+
const onTierFallback = brokerInstance
|
|
1299
|
+
? ({ provider }) => {
|
|
1300
|
+
for (const session of sessions.values()) {
|
|
1301
|
+
if (TERMINAL_STATES.has(session.state)) continue;
|
|
1302
|
+
if (session.config.agent !== provider) continue;
|
|
1303
|
+
if (session.config.remote) continue;
|
|
1304
|
+
|
|
1305
|
+
const newLease = brokerInstance.lease({ provider });
|
|
1306
|
+
if (!newLease) continue;
|
|
1307
|
+
if (newLease.authFile && provider === "codex") {
|
|
1308
|
+
session.config.env = {
|
|
1309
|
+
...(session.config.env || {}),
|
|
1310
|
+
CODEX_HOME: dirname(newLease.authFile),
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
swapAuthFile(
|
|
1315
|
+
newLease,
|
|
1316
|
+
provider,
|
|
1317
|
+
session.id,
|
|
1318
|
+
eventLog,
|
|
1319
|
+
brokerInstance,
|
|
1320
|
+
session.config.env,
|
|
1321
|
+
);
|
|
1322
|
+
eventLog.append("tier_fallback_swap", {
|
|
1323
|
+
session: session.id,
|
|
1324
|
+
agent: provider,
|
|
1325
|
+
newAccount: newLease.id,
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
: null;
|
|
1330
|
+
|
|
1331
|
+
if (brokerInstance && onTierFallback) {
|
|
1332
|
+
brokerInstance.on("tierFallback", onTierFallback);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// Shutdown traps
|
|
1336
|
+
const onSignal = () => {
|
|
1337
|
+
void shutdown("signal");
|
|
1338
|
+
};
|
|
1339
|
+
process.on("SIGINT", onSignal);
|
|
1340
|
+
process.on("SIGTERM", onSignal);
|
|
1341
|
+
|
|
1342
|
+
const conductor = {
|
|
1343
|
+
spawnSession,
|
|
1344
|
+
killSession,
|
|
1345
|
+
sendInput,
|
|
1346
|
+
getSnapshot,
|
|
1347
|
+
getMeshRegistry() {
|
|
1348
|
+
return this._meshRegistry || null;
|
|
1349
|
+
},
|
|
1350
|
+
shutdown,
|
|
1351
|
+
on: emitter.on.bind(emitter),
|
|
1352
|
+
off: emitter.off.bind(emitter),
|
|
1353
|
+
get sessionCount() {
|
|
1354
|
+
return sessions.size;
|
|
1355
|
+
},
|
|
1356
|
+
get isShuttingDown() {
|
|
1357
|
+
return shuttingDown;
|
|
1358
|
+
},
|
|
1359
|
+
get eventLogPath() {
|
|
1360
|
+
return eventLog.filePath;
|
|
1361
|
+
},
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
if (opts.enableMesh !== false) {
|
|
1365
|
+
try {
|
|
1366
|
+
const registry = opts.meshRegistry || createRegistry();
|
|
1367
|
+
const bridge = createConductorMeshBridge(conductor, registry);
|
|
1368
|
+
bridge.attach();
|
|
1369
|
+
conductor._meshBridge = bridge;
|
|
1370
|
+
conductor._meshRegistry = registry;
|
|
1371
|
+
} catch {
|
|
1372
|
+
// mesh 실패해도 conductor 정상 동작
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
const frozenApi = Object.freeze(conductor);
|
|
1377
|
+
ensureConductorRegistry();
|
|
1378
|
+
return frozenApi;
|
|
1379
|
+
}
|