triflux 9.7.13 → 9.8.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.ko.md +2 -0
- package/README.md +2 -0
- package/bin/triflux.mjs +297 -47
- package/hooks/hook-registry.json +4 -4
- package/hub/fullcycle.mjs +96 -0
- package/hub/paths.mjs +30 -28
- package/hub/pipeline/index.mjs +318 -318
- package/hub/schema.sql +146 -146
- package/hub/team/cli/commands/kill.mjs +37 -37
- package/hub/team/cli/commands/stop.mjs +31 -31
- package/hub/team/cli/commands/task.mjs +30 -30
- package/hub/team/cli/services/hub-client.mjs +208 -208
- package/hub/team/cli/services/native-control.mjs +118 -118
- package/hub/team/cli/services/runtime-mode.mjs +62 -62
- package/hub/team/cli/services/state-store.mjs +48 -48
- package/hub/team/dashboard.mjs +274 -274
- package/hub/team/native.mjs +649 -649
- package/hub/team/psmux.mjs +68 -13
- package/hub/tools.mjs +554 -554
- package/hub/workers/claude-worker.mjs +423 -423
- package/hub/workers/codex-mcp.mjs +410 -410
- package/hub/workers/gemini-worker.mjs +429 -429
- package/hub/workers/interface.mjs +40 -40
- package/package.json +1 -1
- package/scripts/__tests__/remote-spawn-transfer.test.mjs +1 -1
- package/scripts/cache-warmup.mjs +1 -0
- package/scripts/claude-logged.ps1 +54 -0
- package/scripts/demo-tui.mjs +59 -0
- package/scripts/headless-guard.mjs +4 -7
- package/scripts/hub-ensure.mjs +120 -120
- package/scripts/lib/psmux-info.mjs +119 -0
- package/scripts/lib/remote-spawn-transfer.mjs +1 -1
- package/scripts/setup.mjs +150 -6
- package/scripts/tfx-route-post.mjs +90 -13
- package/scripts/token-snapshot.mjs +575 -575
- package/skills/.omc/state/agent-replay-8f0e10a9-9693-4410-96f5-a6b07e8ed995.jsonl +1 -0
- package/skills/.omc/state/idle-notif-cooldown.json +3 -0
- package/skills/.omc/state/last-tool-error.json +7 -0
- package/skills/.omc/state/subagent-tracking.json +7 -0
- package/skills/tfx-codex-swarm/SKILL.md +40 -5
- package/skills/tfx-codex-swarm/mcp-daemon/register-autostart.ps1 +32 -0
- package/skills/tfx-doctor/SKILL.md +3 -0
- package/skills/tfx-fullcycle/SKILL.md +79 -4
- package/skills/tfx-hub/SKILL.md +3 -1
- package/skills/tfx-psmux-rules/SKILL.md +53 -31
- package/skills/tfx-remote-spawn/references/hosts.json +16 -16
- package/skills/tfx-setup/SKILL.md +9 -0
- package/tui/doctor.mjs +1 -0
package/hub/team/dashboard.mjs
CHANGED
|
@@ -1,274 +1,274 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// hub/team/dashboard.mjs — 실시간 팀 상태 표시 (v2.2)
|
|
3
|
-
// tmux 의존 제거 — Hub task-list + native-supervisor 기반
|
|
4
|
-
//
|
|
5
|
-
// 실행:
|
|
6
|
-
// node hub/team/dashboard.mjs --session <세션이름> [--interval 2]
|
|
7
|
-
// node hub/team/dashboard.mjs --team <팀이름> [--interval 2]
|
|
8
|
-
import { get } from "node:http";
|
|
9
|
-
import { AMBER, GREEN, RED, GRAY, DIM, BOLD, RESET } from "./shared.mjs";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* HTTP GET JSON
|
|
13
|
-
* @param {string} url
|
|
14
|
-
* @returns {Promise<object|null>}
|
|
15
|
-
*/
|
|
16
|
-
function fetchJson(url) {
|
|
17
|
-
return new Promise((resolve) => {
|
|
18
|
-
const req = get(url, { timeout: 2000 }, (res) => {
|
|
19
|
-
let data = "";
|
|
20
|
-
res.on("data", (chunk) => (data += chunk));
|
|
21
|
-
res.on("end", () => {
|
|
22
|
-
try { resolve(JSON.parse(data)); } catch { resolve(null); }
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
req.on("error", () => resolve(null));
|
|
26
|
-
req.on("timeout", () => { req.destroy(); resolve(null); });
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* HTTP POST JSON (Hub bridge 용)
|
|
32
|
-
* @param {string} url
|
|
33
|
-
* @param {object} body
|
|
34
|
-
* @returns {Promise<object|null>}
|
|
35
|
-
*/
|
|
36
|
-
async function fetchPost(url, body = {}) {
|
|
37
|
-
try {
|
|
38
|
-
const res = await fetch(url, {
|
|
39
|
-
method: "POST",
|
|
40
|
-
headers: { "Content-Type": "application/json" },
|
|
41
|
-
body: JSON.stringify(body),
|
|
42
|
-
signal: AbortSignal.timeout(2000),
|
|
43
|
-
});
|
|
44
|
-
return await res.json();
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 진행률 바 생성
|
|
52
|
-
* @param {number} pct — 0~100
|
|
53
|
-
* @param {number} width — 바 너비 (기본 8)
|
|
54
|
-
* @returns {string}
|
|
55
|
-
*/
|
|
56
|
-
function progressBar(pct, width = 8) {
|
|
57
|
-
const filled = Math.round((pct / 100) * width);
|
|
58
|
-
const empty = width - filled;
|
|
59
|
-
return `${GREEN}${"█".repeat(filled)}${GRAY}${"░".repeat(empty)}${RESET}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 업타임 포맷
|
|
64
|
-
* @param {number} ms
|
|
65
|
-
* @returns {string}
|
|
66
|
-
*/
|
|
67
|
-
function formatUptime(ms) {
|
|
68
|
-
if (ms < 60000) return `${Math.round(ms / 1000)}초`;
|
|
69
|
-
if (ms < 3600000) return `${Math.round(ms / 60000)}분`;
|
|
70
|
-
return `${Math.round(ms / 3600000)}시간`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* task 상태 아이콘
|
|
75
|
-
* @param {string} status
|
|
76
|
-
* @returns {string}
|
|
77
|
-
*/
|
|
78
|
-
function statusIcon(status) {
|
|
79
|
-
switch (status) {
|
|
80
|
-
case "completed": return `${GREEN}✓${RESET}`;
|
|
81
|
-
case "in_progress": return `${AMBER}●${RESET}`;
|
|
82
|
-
case "failed": return `${RED}✗${RESET}`;
|
|
83
|
-
default: return `${GRAY}○${RESET}`;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 멤버 목록 구성: Hub tasks + supervisor + teamState 통합
|
|
89
|
-
* @param {Array} hubTasks — Hub bridge task-list 결과
|
|
90
|
-
* @param {Array} supervisorMembers — native-supervisor 멤버 상태
|
|
91
|
-
* @param {object} teamState — team-state.json 내용
|
|
92
|
-
* @returns {Array<{name: string, cli: string, status: string, subject: string, preview: string}>}
|
|
93
|
-
*/
|
|
94
|
-
function buildMemberList(hubTasks, supervisorMembers, teamState) {
|
|
95
|
-
const members = [];
|
|
96
|
-
const supervisorByName = new Map(supervisorMembers.map((m) => [m.name, m]));
|
|
97
|
-
|
|
98
|
-
// Hub tasks가 있으면 주 데이터 소스
|
|
99
|
-
if (hubTasks.length > 0) {
|
|
100
|
-
for (const task of hubTasks) {
|
|
101
|
-
const owner = task.owner || task.subject || "";
|
|
102
|
-
const sup = supervisorByName.get(owner);
|
|
103
|
-
members.push({
|
|
104
|
-
name: owner,
|
|
105
|
-
cli: task.metadata?.cli || sup?.cli || "",
|
|
106
|
-
status: task.status || "pending",
|
|
107
|
-
subject: task.subject || "",
|
|
108
|
-
preview: sup?.lastPreview || task.description?.slice(0, 80) || "",
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return members;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Supervisor 데이터 폴백
|
|
115
|
-
if (supervisorMembers.length > 0) {
|
|
116
|
-
for (const m of supervisorMembers) {
|
|
117
|
-
if (m.role === "lead") continue;
|
|
118
|
-
members.push({
|
|
119
|
-
name: m.name,
|
|
120
|
-
cli: m.cli || "",
|
|
121
|
-
status: m.status === "running" ? "in_progress" : m.status === "exited" ? "completed" : m.status,
|
|
122
|
-
subject: "",
|
|
123
|
-
preview: m.lastPreview || "",
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return members;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// teamState 폴백 (하위 호환)
|
|
130
|
-
const panes = teamState?.panes || {};
|
|
131
|
-
for (const [, paneInfo] of Object.entries(panes).filter(([, v]) => v.role !== "dashboard" && v.role !== "lead")) {
|
|
132
|
-
members.push({
|
|
133
|
-
name: paneInfo.agentId || paneInfo.name || "?",
|
|
134
|
-
cli: paneInfo.cli || "",
|
|
135
|
-
status: "unknown",
|
|
136
|
-
subject: paneInfo.subtask || "",
|
|
137
|
-
preview: "",
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return members;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 대시보드 렌더링 (v2.2: Hub/supervisor 기반)
|
|
145
|
-
* @param {string} sessionName — 세션 또는 팀 이름
|
|
146
|
-
* @param {object} opts
|
|
147
|
-
* @param {string} opts.hubUrl — Hub URL (기본 http://127.0.0.1:27888)
|
|
148
|
-
* @param {string} [opts.teamName] — Hub task-list 조회용 팀 이름
|
|
149
|
-
* @param {string} [opts.supervisorUrl] — native-supervisor 제어 URL
|
|
150
|
-
* @param {object} [opts.teamState] — team-state.json 내용 (하위 호환)
|
|
151
|
-
*/
|
|
152
|
-
export async function renderDashboard(sessionName, opts = {}) {
|
|
153
|
-
const {
|
|
154
|
-
hubUrl = "http://127.0.0.1:27888",
|
|
155
|
-
teamName,
|
|
156
|
-
supervisorUrl,
|
|
157
|
-
teamState = {},
|
|
158
|
-
} = opts;
|
|
159
|
-
const W = 50;
|
|
160
|
-
const border = "─".repeat(W);
|
|
161
|
-
|
|
162
|
-
// 데이터 수집 (병렬)
|
|
163
|
-
const [hubStatus, taskListRes, supervisorRes] = await Promise.all([
|
|
164
|
-
fetchJson(`${hubUrl}/status`),
|
|
165
|
-
teamName ? fetchPost(`${hubUrl}/bridge/team/task-list`, { team_name: teamName }) : null,
|
|
166
|
-
supervisorUrl ? fetchJson(`${supervisorUrl}/status`) : null,
|
|
167
|
-
]);
|
|
168
|
-
|
|
169
|
-
const hubOnline = !!hubStatus;
|
|
170
|
-
const hubState = hubOnline ? `${GREEN}● online${RESET}` : `${RED}● offline${RESET}`;
|
|
171
|
-
const uptime = hubStatus?.hub?.uptime ? formatUptime(hubStatus.hub.uptime) : "-";
|
|
172
|
-
const queueSize = hubStatus?.hub?.queue_depth ?? 0;
|
|
173
|
-
|
|
174
|
-
// Hub task 데이터
|
|
175
|
-
const hubTasks = taskListRes?.ok ? (taskListRes.data?.tasks || []) : [];
|
|
176
|
-
const completedCount = hubTasks.filter((t) => t.status === "completed").length;
|
|
177
|
-
const totalCount = hubTasks.length;
|
|
178
|
-
|
|
179
|
-
// Supervisor 멤버 데이터
|
|
180
|
-
const supervisorMembers = supervisorRes?.ok ? (supervisorRes.data?.members || []) : [];
|
|
181
|
-
|
|
182
|
-
// 헤더
|
|
183
|
-
const progress = totalCount > 0 ? ` ${completedCount}/${totalCount}` : "";
|
|
184
|
-
console.log(`${AMBER}┌─ ${sessionName}${progress} ${GRAY}${"─".repeat(Math.max(0, W - sessionName.length - progress.length - 3))}${AMBER}┐${RESET}`);
|
|
185
|
-
console.log(`${AMBER}│${RESET} Hub: ${hubState} Uptime: ${DIM}${uptime}${RESET} Queue: ${DIM}${queueSize}${RESET}`);
|
|
186
|
-
console.log(`${AMBER}│${RESET}`);
|
|
187
|
-
|
|
188
|
-
// 멤버/워커 렌더링
|
|
189
|
-
const members = buildMemberList(hubTasks, supervisorMembers, teamState);
|
|
190
|
-
|
|
191
|
-
if (members.length === 0) {
|
|
192
|
-
console.log(`${AMBER}│${RESET} ${DIM}에이전트 정보 없음${RESET}`);
|
|
193
|
-
} else {
|
|
194
|
-
for (const m of members) {
|
|
195
|
-
const icon = statusIcon(m.status);
|
|
196
|
-
const label = `[${m.name}]`;
|
|
197
|
-
const cliTag = m.cli ? m.cli.charAt(0).toUpperCase() + m.cli.slice(1) : "";
|
|
198
|
-
|
|
199
|
-
// 진행률 추정
|
|
200
|
-
const pct = m.status === "completed" ? 100
|
|
201
|
-
: m.status === "in_progress" ? 50
|
|
202
|
-
: m.status === "failed" ? 100
|
|
203
|
-
: 0;
|
|
204
|
-
|
|
205
|
-
console.log(`${AMBER}│${RESET} ${BOLD}${label}${RESET} ${cliTag} ${icon} ${m.status || "pending"} ${progressBar(pct)}`);
|
|
206
|
-
|
|
207
|
-
// 미리보기: supervisor lastPreview > task subject
|
|
208
|
-
const preview = m.preview || m.subject || "";
|
|
209
|
-
if (preview) {
|
|
210
|
-
const truncated = preview.length > W - 8 ? preview.slice(0, W - 11) + "..." : preview;
|
|
211
|
-
console.log(`${AMBER}│${RESET} ${DIM}> ${truncated}${RESET}`);
|
|
212
|
-
}
|
|
213
|
-
console.log(`${AMBER}│${RESET}`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 푸터
|
|
218
|
-
console.log(`${AMBER}└${GRAY}${border}${AMBER}┘${RESET}`);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/** team-state.json 로드 (세션별 파일 우선, fallback: team-state.json) */
|
|
222
|
-
async function loadTeamState() {
|
|
223
|
-
try {
|
|
224
|
-
const { existsSync, readFileSync } = await import("node:fs");
|
|
225
|
-
const { join } = await import("node:path");
|
|
226
|
-
const { homedir } = await import("node:os");
|
|
227
|
-
const hubDir = join(homedir(), ".claude", "cache", "tfx-hub");
|
|
228
|
-
const sessionId = process.env.CLAUDE_SESSION_ID;
|
|
229
|
-
if (sessionId) {
|
|
230
|
-
const sessionPath = join(hubDir, `team-state-${sessionId}.json`);
|
|
231
|
-
if (existsSync(sessionPath)) return JSON.parse(readFileSync(sessionPath, "utf8"));
|
|
232
|
-
}
|
|
233
|
-
const legacyPath = join(hubDir, "team-state.json");
|
|
234
|
-
if (existsSync(legacyPath)) return JSON.parse(readFileSync(legacyPath, "utf8"));
|
|
235
|
-
return {};
|
|
236
|
-
} catch {
|
|
237
|
-
return {};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// ── CLI 실행 ──
|
|
242
|
-
if (process.argv[1]?.includes("dashboard.mjs")) {
|
|
243
|
-
const sessionIdx = process.argv.indexOf("--session");
|
|
244
|
-
const teamIdx = process.argv.indexOf("--team");
|
|
245
|
-
const sessionName = sessionIdx !== -1 ? process.argv[sessionIdx + 1] : null;
|
|
246
|
-
const teamName = teamIdx !== -1 ? process.argv[teamIdx + 1] : null;
|
|
247
|
-
const intervalSec = parseInt(process.argv[process.argv.indexOf("--interval") + 1] || "2", 10);
|
|
248
|
-
|
|
249
|
-
const displayName = sessionName || teamName;
|
|
250
|
-
if (!displayName) {
|
|
251
|
-
console.error("사용법: node dashboard.mjs --session <세션이름> [--team <팀이름>] [--interval 2]");
|
|
252
|
-
process.exit(1);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Ctrl+C로 종료
|
|
256
|
-
process.on("SIGINT", () => process.exit(0));
|
|
257
|
-
|
|
258
|
-
// 갱신 루프
|
|
259
|
-
while (true) {
|
|
260
|
-
const teamState = await loadTeamState();
|
|
261
|
-
const effectiveTeamName = teamName || null;
|
|
262
|
-
const supervisorUrl = teamState?.native?.controlUrl || null;
|
|
263
|
-
|
|
264
|
-
// 화면 클리어 (ANSI)
|
|
265
|
-
process.stdout.write("\x1b[2J\x1b[H");
|
|
266
|
-
await renderDashboard(displayName, {
|
|
267
|
-
teamName: effectiveTeamName,
|
|
268
|
-
supervisorUrl,
|
|
269
|
-
teamState,
|
|
270
|
-
});
|
|
271
|
-
console.log(`${DIM} ${intervalSec}초 간격 갱신 | Ctrl+C로 종료${RESET}`);
|
|
272
|
-
await new Promise((r) => setTimeout(r, intervalSec * 1000));
|
|
273
|
-
}
|
|
274
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// hub/team/dashboard.mjs — 실시간 팀 상태 표시 (v2.2)
|
|
3
|
+
// tmux 의존 제거 — Hub task-list + native-supervisor 기반
|
|
4
|
+
//
|
|
5
|
+
// 실행:
|
|
6
|
+
// node hub/team/dashboard.mjs --session <세션이름> [--interval 2]
|
|
7
|
+
// node hub/team/dashboard.mjs --team <팀이름> [--interval 2]
|
|
8
|
+
import { get } from "node:http";
|
|
9
|
+
import { AMBER, GREEN, RED, GRAY, DIM, BOLD, RESET } from "./shared.mjs";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* HTTP GET JSON
|
|
13
|
+
* @param {string} url
|
|
14
|
+
* @returns {Promise<object|null>}
|
|
15
|
+
*/
|
|
16
|
+
function fetchJson(url) {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const req = get(url, { timeout: 2000 }, (res) => {
|
|
19
|
+
let data = "";
|
|
20
|
+
res.on("data", (chunk) => (data += chunk));
|
|
21
|
+
res.on("end", () => {
|
|
22
|
+
try { resolve(JSON.parse(data)); } catch { resolve(null); }
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
req.on("error", () => resolve(null));
|
|
26
|
+
req.on("timeout", () => { req.destroy(); resolve(null); });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* HTTP POST JSON (Hub bridge 용)
|
|
32
|
+
* @param {string} url
|
|
33
|
+
* @param {object} body
|
|
34
|
+
* @returns {Promise<object|null>}
|
|
35
|
+
*/
|
|
36
|
+
async function fetchPost(url, body = {}) {
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(url, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "Content-Type": "application/json" },
|
|
41
|
+
body: JSON.stringify(body),
|
|
42
|
+
signal: AbortSignal.timeout(2000),
|
|
43
|
+
});
|
|
44
|
+
return await res.json();
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 진행률 바 생성
|
|
52
|
+
* @param {number} pct — 0~100
|
|
53
|
+
* @param {number} width — 바 너비 (기본 8)
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
function progressBar(pct, width = 8) {
|
|
57
|
+
const filled = Math.round((pct / 100) * width);
|
|
58
|
+
const empty = width - filled;
|
|
59
|
+
return `${GREEN}${"█".repeat(filled)}${GRAY}${"░".repeat(empty)}${RESET}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 업타임 포맷
|
|
64
|
+
* @param {number} ms
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
function formatUptime(ms) {
|
|
68
|
+
if (ms < 60000) return `${Math.round(ms / 1000)}초`;
|
|
69
|
+
if (ms < 3600000) return `${Math.round(ms / 60000)}분`;
|
|
70
|
+
return `${Math.round(ms / 3600000)}시간`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* task 상태 아이콘
|
|
75
|
+
* @param {string} status
|
|
76
|
+
* @returns {string}
|
|
77
|
+
*/
|
|
78
|
+
function statusIcon(status) {
|
|
79
|
+
switch (status) {
|
|
80
|
+
case "completed": return `${GREEN}✓${RESET}`;
|
|
81
|
+
case "in_progress": return `${AMBER}●${RESET}`;
|
|
82
|
+
case "failed": return `${RED}✗${RESET}`;
|
|
83
|
+
default: return `${GRAY}○${RESET}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 멤버 목록 구성: Hub tasks + supervisor + teamState 통합
|
|
89
|
+
* @param {Array} hubTasks — Hub bridge task-list 결과
|
|
90
|
+
* @param {Array} supervisorMembers — native-supervisor 멤버 상태
|
|
91
|
+
* @param {object} teamState — team-state.json 내용
|
|
92
|
+
* @returns {Array<{name: string, cli: string, status: string, subject: string, preview: string}>}
|
|
93
|
+
*/
|
|
94
|
+
function buildMemberList(hubTasks, supervisorMembers, teamState) {
|
|
95
|
+
const members = [];
|
|
96
|
+
const supervisorByName = new Map(supervisorMembers.map((m) => [m.name, m]));
|
|
97
|
+
|
|
98
|
+
// Hub tasks가 있으면 주 데이터 소스
|
|
99
|
+
if (hubTasks.length > 0) {
|
|
100
|
+
for (const task of hubTasks) {
|
|
101
|
+
const owner = task.owner || task.subject || "";
|
|
102
|
+
const sup = supervisorByName.get(owner);
|
|
103
|
+
members.push({
|
|
104
|
+
name: owner,
|
|
105
|
+
cli: task.metadata?.cli || sup?.cli || "",
|
|
106
|
+
status: task.status || "pending",
|
|
107
|
+
subject: task.subject || "",
|
|
108
|
+
preview: sup?.lastPreview || task.description?.slice(0, 80) || "",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return members;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Supervisor 데이터 폴백
|
|
115
|
+
if (supervisorMembers.length > 0) {
|
|
116
|
+
for (const m of supervisorMembers) {
|
|
117
|
+
if (m.role === "lead") continue;
|
|
118
|
+
members.push({
|
|
119
|
+
name: m.name,
|
|
120
|
+
cli: m.cli || "",
|
|
121
|
+
status: m.status === "running" ? "in_progress" : m.status === "exited" ? "completed" : m.status,
|
|
122
|
+
subject: "",
|
|
123
|
+
preview: m.lastPreview || "",
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return members;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// teamState 폴백 (하위 호환)
|
|
130
|
+
const panes = teamState?.panes || {};
|
|
131
|
+
for (const [, paneInfo] of Object.entries(panes).filter(([, v]) => v.role !== "dashboard" && v.role !== "lead")) {
|
|
132
|
+
members.push({
|
|
133
|
+
name: paneInfo.agentId || paneInfo.name || "?",
|
|
134
|
+
cli: paneInfo.cli || "",
|
|
135
|
+
status: "unknown",
|
|
136
|
+
subject: paneInfo.subtask || "",
|
|
137
|
+
preview: "",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return members;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 대시보드 렌더링 (v2.2: Hub/supervisor 기반)
|
|
145
|
+
* @param {string} sessionName — 세션 또는 팀 이름
|
|
146
|
+
* @param {object} opts
|
|
147
|
+
* @param {string} opts.hubUrl — Hub URL (기본 http://127.0.0.1:27888)
|
|
148
|
+
* @param {string} [opts.teamName] — Hub task-list 조회용 팀 이름
|
|
149
|
+
* @param {string} [opts.supervisorUrl] — native-supervisor 제어 URL
|
|
150
|
+
* @param {object} [opts.teamState] — team-state.json 내용 (하위 호환)
|
|
151
|
+
*/
|
|
152
|
+
export async function renderDashboard(sessionName, opts = {}) {
|
|
153
|
+
const {
|
|
154
|
+
hubUrl = "http://127.0.0.1:27888",
|
|
155
|
+
teamName,
|
|
156
|
+
supervisorUrl,
|
|
157
|
+
teamState = {},
|
|
158
|
+
} = opts;
|
|
159
|
+
const W = 50;
|
|
160
|
+
const border = "─".repeat(W);
|
|
161
|
+
|
|
162
|
+
// 데이터 수집 (병렬)
|
|
163
|
+
const [hubStatus, taskListRes, supervisorRes] = await Promise.all([
|
|
164
|
+
fetchJson(`${hubUrl}/status`),
|
|
165
|
+
teamName ? fetchPost(`${hubUrl}/bridge/team/task-list`, { team_name: teamName }) : null,
|
|
166
|
+
supervisorUrl ? fetchJson(`${supervisorUrl}/status`) : null,
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
const hubOnline = !!hubStatus;
|
|
170
|
+
const hubState = hubOnline ? `${GREEN}● online${RESET}` : `${RED}● offline${RESET}`;
|
|
171
|
+
const uptime = hubStatus?.hub?.uptime ? formatUptime(hubStatus.hub.uptime) : "-";
|
|
172
|
+
const queueSize = hubStatus?.hub?.queue_depth ?? 0;
|
|
173
|
+
|
|
174
|
+
// Hub task 데이터
|
|
175
|
+
const hubTasks = taskListRes?.ok ? (taskListRes.data?.tasks || []) : [];
|
|
176
|
+
const completedCount = hubTasks.filter((t) => t.status === "completed").length;
|
|
177
|
+
const totalCount = hubTasks.length;
|
|
178
|
+
|
|
179
|
+
// Supervisor 멤버 데이터
|
|
180
|
+
const supervisorMembers = supervisorRes?.ok ? (supervisorRes.data?.members || []) : [];
|
|
181
|
+
|
|
182
|
+
// 헤더
|
|
183
|
+
const progress = totalCount > 0 ? ` ${completedCount}/${totalCount}` : "";
|
|
184
|
+
console.log(`${AMBER}┌─ ${sessionName}${progress} ${GRAY}${"─".repeat(Math.max(0, W - sessionName.length - progress.length - 3))}${AMBER}┐${RESET}`);
|
|
185
|
+
console.log(`${AMBER}│${RESET} Hub: ${hubState} Uptime: ${DIM}${uptime}${RESET} Queue: ${DIM}${queueSize}${RESET}`);
|
|
186
|
+
console.log(`${AMBER}│${RESET}`);
|
|
187
|
+
|
|
188
|
+
// 멤버/워커 렌더링
|
|
189
|
+
const members = buildMemberList(hubTasks, supervisorMembers, teamState);
|
|
190
|
+
|
|
191
|
+
if (members.length === 0) {
|
|
192
|
+
console.log(`${AMBER}│${RESET} ${DIM}에이전트 정보 없음${RESET}`);
|
|
193
|
+
} else {
|
|
194
|
+
for (const m of members) {
|
|
195
|
+
const icon = statusIcon(m.status);
|
|
196
|
+
const label = `[${m.name}]`;
|
|
197
|
+
const cliTag = m.cli ? m.cli.charAt(0).toUpperCase() + m.cli.slice(1) : "";
|
|
198
|
+
|
|
199
|
+
// 진행률 추정
|
|
200
|
+
const pct = m.status === "completed" ? 100
|
|
201
|
+
: m.status === "in_progress" ? 50
|
|
202
|
+
: m.status === "failed" ? 100
|
|
203
|
+
: 0;
|
|
204
|
+
|
|
205
|
+
console.log(`${AMBER}│${RESET} ${BOLD}${label}${RESET} ${cliTag} ${icon} ${m.status || "pending"} ${progressBar(pct)}`);
|
|
206
|
+
|
|
207
|
+
// 미리보기: supervisor lastPreview > task subject
|
|
208
|
+
const preview = m.preview || m.subject || "";
|
|
209
|
+
if (preview) {
|
|
210
|
+
const truncated = preview.length > W - 8 ? preview.slice(0, W - 11) + "..." : preview;
|
|
211
|
+
console.log(`${AMBER}│${RESET} ${DIM}> ${truncated}${RESET}`);
|
|
212
|
+
}
|
|
213
|
+
console.log(`${AMBER}│${RESET}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 푸터
|
|
218
|
+
console.log(`${AMBER}└${GRAY}${border}${AMBER}┘${RESET}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** team-state.json 로드 (세션별 파일 우선, fallback: team-state.json) */
|
|
222
|
+
async function loadTeamState() {
|
|
223
|
+
try {
|
|
224
|
+
const { existsSync, readFileSync } = await import("node:fs");
|
|
225
|
+
const { join } = await import("node:path");
|
|
226
|
+
const { homedir } = await import("node:os");
|
|
227
|
+
const hubDir = join(homedir(), ".claude", "cache", "tfx-hub");
|
|
228
|
+
const sessionId = process.env.CLAUDE_SESSION_ID;
|
|
229
|
+
if (sessionId) {
|
|
230
|
+
const sessionPath = join(hubDir, `team-state-${sessionId}.json`);
|
|
231
|
+
if (existsSync(sessionPath)) return JSON.parse(readFileSync(sessionPath, "utf8"));
|
|
232
|
+
}
|
|
233
|
+
const legacyPath = join(hubDir, "team-state.json");
|
|
234
|
+
if (existsSync(legacyPath)) return JSON.parse(readFileSync(legacyPath, "utf8"));
|
|
235
|
+
return {};
|
|
236
|
+
} catch {
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ── CLI 실행 ──
|
|
242
|
+
if (process.argv[1]?.includes("dashboard.mjs")) {
|
|
243
|
+
const sessionIdx = process.argv.indexOf("--session");
|
|
244
|
+
const teamIdx = process.argv.indexOf("--team");
|
|
245
|
+
const sessionName = sessionIdx !== -1 ? process.argv[sessionIdx + 1] : null;
|
|
246
|
+
const teamName = teamIdx !== -1 ? process.argv[teamIdx + 1] : null;
|
|
247
|
+
const intervalSec = parseInt(process.argv[process.argv.indexOf("--interval") + 1] || "2", 10);
|
|
248
|
+
|
|
249
|
+
const displayName = sessionName || teamName;
|
|
250
|
+
if (!displayName) {
|
|
251
|
+
console.error("사용법: node dashboard.mjs --session <세션이름> [--team <팀이름>] [--interval 2]");
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Ctrl+C로 종료
|
|
256
|
+
process.on("SIGINT", () => process.exit(0));
|
|
257
|
+
|
|
258
|
+
// 갱신 루프
|
|
259
|
+
while (true) {
|
|
260
|
+
const teamState = await loadTeamState();
|
|
261
|
+
const effectiveTeamName = teamName || null;
|
|
262
|
+
const supervisorUrl = teamState?.native?.controlUrl || null;
|
|
263
|
+
|
|
264
|
+
// 화면 클리어 (ANSI)
|
|
265
|
+
process.stdout.write("\x1b[2J\x1b[H");
|
|
266
|
+
await renderDashboard(displayName, {
|
|
267
|
+
teamName: effectiveTeamName,
|
|
268
|
+
supervisorUrl,
|
|
269
|
+
teamState,
|
|
270
|
+
});
|
|
271
|
+
console.log(`${DIM} ${intervalSec}초 간격 갱신 | Ctrl+C로 종료${RESET}`);
|
|
272
|
+
await new Promise((r) => setTimeout(r, intervalSec * 1000));
|
|
273
|
+
}
|
|
274
|
+
}
|