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
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
4
|
-
|
|
5
|
-
import { HUB_PID_DIR, PKG_ROOT } from "./state-store.mjs";
|
|
6
|
-
export { nativeGetStatus } from "./native-control.mjs";
|
|
7
|
-
|
|
8
|
-
const HUB_PID_FILE = join(HUB_PID_DIR, "hub.pid");
|
|
9
|
-
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
10
|
-
|
|
11
|
-
export function formatHostForUrl(host) {
|
|
12
|
-
return host.includes(":") ? `[${host}]` : host;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function buildHubBaseUrl(host, port) {
|
|
16
|
-
return `http://${formatHostForUrl(host)}:${port}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getDefaultHubPort() {
|
|
20
|
-
const envPortRaw = Number(process.env.TFX_HUB_PORT || "27888");
|
|
21
|
-
return Number.isFinite(envPortRaw) && envPortRaw > 0 ? envPortRaw : 27888;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getDefaultHubUrl() {
|
|
25
|
-
return `${buildHubBaseUrl("127.0.0.1", getDefaultHubPort())}/mcp`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function normalizeLoopbackHost(host) {
|
|
29
|
-
if (typeof host !== "string") return "127.0.0.1";
|
|
30
|
-
const candidate = host.trim();
|
|
31
|
-
return LOOPBACK_HOSTS.has(candidate) ? candidate : "127.0.0.1";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function probeHubStatus(host, port, timeoutMs = 1500) {
|
|
35
|
-
try {
|
|
36
|
-
const res = await fetch(`${buildHubBaseUrl(host, port)}/status`, {
|
|
37
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
38
|
-
});
|
|
39
|
-
if (!res.ok) return null;
|
|
40
|
-
const data = await res.json();
|
|
41
|
-
return data?.hub ? data : null;
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function getHubInfo() {
|
|
48
|
-
const probePort = getDefaultHubPort();
|
|
49
|
-
|
|
50
|
-
if (existsSync(HUB_PID_FILE)) {
|
|
51
|
-
try {
|
|
52
|
-
const raw = JSON.parse(readFileSync(HUB_PID_FILE, "utf8"));
|
|
53
|
-
const pid = Number(raw?.pid);
|
|
54
|
-
if (!Number.isFinite(pid) || pid <= 0) throw new Error("invalid pid");
|
|
55
|
-
process.kill(pid, 0);
|
|
56
|
-
const host = normalizeLoopbackHost(raw?.host);
|
|
57
|
-
const port = Number(raw?.port) || 27888;
|
|
58
|
-
const status = await probeHubStatus(host, port, 1200);
|
|
59
|
-
return {
|
|
60
|
-
...raw,
|
|
61
|
-
pid,
|
|
62
|
-
host,
|
|
63
|
-
port,
|
|
64
|
-
url: `${buildHubBaseUrl(host, port)}/mcp`,
|
|
65
|
-
...(status ? {} : { degraded: true }),
|
|
66
|
-
};
|
|
67
|
-
} catch {
|
|
68
|
-
try { unlinkSync(HUB_PID_FILE); } catch {}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
for (const portCandidate of Array.from(new Set([probePort, 27888]))) {
|
|
73
|
-
const data = await probeHubStatus("127.0.0.1", portCandidate, 1200);
|
|
74
|
-
if (!data) continue;
|
|
75
|
-
const port = Number(data.port) || portCandidate;
|
|
76
|
-
const pid = Number(data.pid);
|
|
77
|
-
const recovered = {
|
|
78
|
-
pid: Number.isFinite(pid) ? pid : null,
|
|
79
|
-
host: "127.0.0.1",
|
|
80
|
-
port,
|
|
81
|
-
url: `${buildHubBaseUrl("127.0.0.1", port)}/mcp`,
|
|
82
|
-
discovered: true,
|
|
83
|
-
};
|
|
84
|
-
if (Number.isFinite(recovered.pid) && recovered.pid > 0) {
|
|
85
|
-
try {
|
|
86
|
-
mkdirSync(HUB_PID_DIR, { recursive: true });
|
|
87
|
-
writeFileSync(HUB_PID_FILE, JSON.stringify({ ...recovered, started: Date.now() }));
|
|
88
|
-
} catch {}
|
|
89
|
-
}
|
|
90
|
-
return recovered;
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export async function startHubDaemon() {
|
|
96
|
-
const serverPath = join(PKG_ROOT, "hub", "server.mjs");
|
|
97
|
-
if (!existsSync(serverPath)) {
|
|
98
|
-
const error = new Error("hub/server.mjs 없음");
|
|
99
|
-
error.code = "HUB_SERVER_MISSING";
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const child = spawn(process.execPath, [serverPath], {
|
|
104
|
-
env: { ...process.env },
|
|
105
|
-
stdio: "ignore",
|
|
106
|
-
detached: true,
|
|
107
|
-
windowsHide: true,
|
|
108
|
-
});
|
|
109
|
-
child.unref();
|
|
110
|
-
|
|
111
|
-
const expectedPort = getDefaultHubPort();
|
|
112
|
-
const deadline = Date.now() + 3000;
|
|
113
|
-
while (Date.now() < deadline) {
|
|
114
|
-
const status = await probeHubStatus("127.0.0.1", expectedPort, 500);
|
|
115
|
-
if (status?.hub) {
|
|
116
|
-
return {
|
|
117
|
-
pid: Number(status.pid) || child.pid,
|
|
118
|
-
host: "127.0.0.1",
|
|
119
|
-
port: expectedPort,
|
|
120
|
-
url: `${buildHubBaseUrl("127.0.0.1", expectedPort)}/mcp`,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Hub가 살아있는지 확인하고, 죽어있으면 재시작을 시도한다.
|
|
131
|
-
* exponential backoff: 1초, 2초, 4초
|
|
132
|
-
* 모든 재시작 실패 시 에러를 throw한다 (silent fail 아님).
|
|
133
|
-
* @param {number} [maxRetries=3]
|
|
134
|
-
* @returns {Promise<object>} Hub 정보
|
|
135
|
-
* @throws {Error} 모든 재시작 시도 실패 시
|
|
136
|
-
*/
|
|
137
|
-
export async function ensureHubAlive(maxRetries = 3) {
|
|
138
|
-
const hub = await getHubInfo();
|
|
139
|
-
if (hub && !hub.degraded) return hub;
|
|
140
|
-
|
|
141
|
-
let lastError = null;
|
|
142
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
143
|
-
try {
|
|
144
|
-
const restarted = await startHubDaemon();
|
|
145
|
-
if (restarted) {
|
|
146
|
-
// 재시작 후 연결 복구 확인
|
|
147
|
-
const recovered = await getHubInfo();
|
|
148
|
-
if (recovered) return recovered;
|
|
149
|
-
}
|
|
150
|
-
} catch (err) {
|
|
151
|
-
lastError = err;
|
|
152
|
-
}
|
|
153
|
-
// 다음 재시도 전 대기: 1초, 2초, 4초 (마지막 시도 후에는 대기 없음)
|
|
154
|
-
if (i < maxRetries - 1) {
|
|
155
|
-
const backoffMs = Math.pow(2, i) * 1000; // i=0: 1초, i=1: 2초, i=2: 4초
|
|
156
|
-
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const error = new Error(`Hub 재시작 ${maxRetries}회 모두 실패${lastError ? `: ${lastError.message}` : ""}`);
|
|
161
|
-
error.code = "HUB_RESTART_FAILED";
|
|
162
|
-
error.cause = lastError;
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export async function fetchHubTaskList(state) {
|
|
167
|
-
const hubBase = (state?.hubUrl || getDefaultHubUrl()).replace(/\/mcp$/, "");
|
|
168
|
-
const teamName = state?.native?.teamName || state?.sessionName || null;
|
|
169
|
-
if (!teamName) return [];
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
const res = await fetch(`${hubBase}/bridge/team/task-list`, {
|
|
173
|
-
method: "POST",
|
|
174
|
-
headers: { "Content-Type": "application/json" },
|
|
175
|
-
body: JSON.stringify({ team_name: teamName }),
|
|
176
|
-
signal: AbortSignal.timeout(2000),
|
|
177
|
-
});
|
|
178
|
-
const data = await res.json();
|
|
179
|
-
return data?.ok ? (data.data?.tasks || []) : [];
|
|
180
|
-
} catch {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export async function publishLeadControl(state, targetMember, command, reason = "") {
|
|
186
|
-
const hubBase = (state?.hubUrl || getDefaultHubUrl()).replace(/\/mcp$/, "");
|
|
187
|
-
const leadAgent = (state?.members || []).find((member) => member.role === "lead")?.agentId || "lead";
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
const res = await fetch(`${hubBase}/bridge/control`, {
|
|
191
|
-
method: "POST",
|
|
192
|
-
headers: { "Content-Type": "application/json" },
|
|
193
|
-
body: JSON.stringify({
|
|
194
|
-
from_agent: leadAgent,
|
|
195
|
-
to_agent: targetMember.agentId,
|
|
196
|
-
command,
|
|
197
|
-
reason,
|
|
198
|
-
payload: {
|
|
199
|
-
issued_by: leadAgent,
|
|
200
|
-
issued_at: Date.now(),
|
|
201
|
-
},
|
|
202
|
-
}),
|
|
203
|
-
});
|
|
204
|
-
return !!res.ok;
|
|
205
|
-
} catch {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
import { HUB_PID_DIR, PKG_ROOT } from "./state-store.mjs";
|
|
6
|
+
export { nativeGetStatus } from "./native-control.mjs";
|
|
7
|
+
|
|
8
|
+
const HUB_PID_FILE = join(HUB_PID_DIR, "hub.pid");
|
|
9
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
10
|
+
|
|
11
|
+
export function formatHostForUrl(host) {
|
|
12
|
+
return host.includes(":") ? `[${host}]` : host;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function buildHubBaseUrl(host, port) {
|
|
16
|
+
return `http://${formatHostForUrl(host)}:${port}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getDefaultHubPort() {
|
|
20
|
+
const envPortRaw = Number(process.env.TFX_HUB_PORT || "27888");
|
|
21
|
+
return Number.isFinite(envPortRaw) && envPortRaw > 0 ? envPortRaw : 27888;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getDefaultHubUrl() {
|
|
25
|
+
return `${buildHubBaseUrl("127.0.0.1", getDefaultHubPort())}/mcp`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalizeLoopbackHost(host) {
|
|
29
|
+
if (typeof host !== "string") return "127.0.0.1";
|
|
30
|
+
const candidate = host.trim();
|
|
31
|
+
return LOOPBACK_HOSTS.has(candidate) ? candidate : "127.0.0.1";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function probeHubStatus(host, port, timeoutMs = 1500) {
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(`${buildHubBaseUrl(host, port)}/status`, {
|
|
37
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) return null;
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
return data?.hub ? data : null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function getHubInfo() {
|
|
48
|
+
const probePort = getDefaultHubPort();
|
|
49
|
+
|
|
50
|
+
if (existsSync(HUB_PID_FILE)) {
|
|
51
|
+
try {
|
|
52
|
+
const raw = JSON.parse(readFileSync(HUB_PID_FILE, "utf8"));
|
|
53
|
+
const pid = Number(raw?.pid);
|
|
54
|
+
if (!Number.isFinite(pid) || pid <= 0) throw new Error("invalid pid");
|
|
55
|
+
process.kill(pid, 0);
|
|
56
|
+
const host = normalizeLoopbackHost(raw?.host);
|
|
57
|
+
const port = Number(raw?.port) || 27888;
|
|
58
|
+
const status = await probeHubStatus(host, port, 1200);
|
|
59
|
+
return {
|
|
60
|
+
...raw,
|
|
61
|
+
pid,
|
|
62
|
+
host,
|
|
63
|
+
port,
|
|
64
|
+
url: `${buildHubBaseUrl(host, port)}/mcp`,
|
|
65
|
+
...(status ? {} : { degraded: true }),
|
|
66
|
+
};
|
|
67
|
+
} catch {
|
|
68
|
+
try { unlinkSync(HUB_PID_FILE); } catch {}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const portCandidate of Array.from(new Set([probePort, 27888]))) {
|
|
73
|
+
const data = await probeHubStatus("127.0.0.1", portCandidate, 1200);
|
|
74
|
+
if (!data) continue;
|
|
75
|
+
const port = Number(data.port) || portCandidate;
|
|
76
|
+
const pid = Number(data.pid);
|
|
77
|
+
const recovered = {
|
|
78
|
+
pid: Number.isFinite(pid) ? pid : null,
|
|
79
|
+
host: "127.0.0.1",
|
|
80
|
+
port,
|
|
81
|
+
url: `${buildHubBaseUrl("127.0.0.1", port)}/mcp`,
|
|
82
|
+
discovered: true,
|
|
83
|
+
};
|
|
84
|
+
if (Number.isFinite(recovered.pid) && recovered.pid > 0) {
|
|
85
|
+
try {
|
|
86
|
+
mkdirSync(HUB_PID_DIR, { recursive: true });
|
|
87
|
+
writeFileSync(HUB_PID_FILE, JSON.stringify({ ...recovered, started: Date.now() }));
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
return recovered;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function startHubDaemon() {
|
|
96
|
+
const serverPath = join(PKG_ROOT, "hub", "server.mjs");
|
|
97
|
+
if (!existsSync(serverPath)) {
|
|
98
|
+
const error = new Error("hub/server.mjs 없음");
|
|
99
|
+
error.code = "HUB_SERVER_MISSING";
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const child = spawn(process.execPath, [serverPath], {
|
|
104
|
+
env: { ...process.env },
|
|
105
|
+
stdio: "ignore",
|
|
106
|
+
detached: true,
|
|
107
|
+
windowsHide: true,
|
|
108
|
+
});
|
|
109
|
+
child.unref();
|
|
110
|
+
|
|
111
|
+
const expectedPort = getDefaultHubPort();
|
|
112
|
+
const deadline = Date.now() + 3000;
|
|
113
|
+
while (Date.now() < deadline) {
|
|
114
|
+
const status = await probeHubStatus("127.0.0.1", expectedPort, 500);
|
|
115
|
+
if (status?.hub) {
|
|
116
|
+
return {
|
|
117
|
+
pid: Number(status.pid) || child.pid,
|
|
118
|
+
host: "127.0.0.1",
|
|
119
|
+
port: expectedPort,
|
|
120
|
+
url: `${buildHubBaseUrl("127.0.0.1", expectedPort)}/mcp`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Hub가 살아있는지 확인하고, 죽어있으면 재시작을 시도한다.
|
|
131
|
+
* exponential backoff: 1초, 2초, 4초
|
|
132
|
+
* 모든 재시작 실패 시 에러를 throw한다 (silent fail 아님).
|
|
133
|
+
* @param {number} [maxRetries=3]
|
|
134
|
+
* @returns {Promise<object>} Hub 정보
|
|
135
|
+
* @throws {Error} 모든 재시작 시도 실패 시
|
|
136
|
+
*/
|
|
137
|
+
export async function ensureHubAlive(maxRetries = 3) {
|
|
138
|
+
const hub = await getHubInfo();
|
|
139
|
+
if (hub && !hub.degraded) return hub;
|
|
140
|
+
|
|
141
|
+
let lastError = null;
|
|
142
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
143
|
+
try {
|
|
144
|
+
const restarted = await startHubDaemon();
|
|
145
|
+
if (restarted) {
|
|
146
|
+
// 재시작 후 연결 복구 확인
|
|
147
|
+
const recovered = await getHubInfo();
|
|
148
|
+
if (recovered) return recovered;
|
|
149
|
+
}
|
|
150
|
+
} catch (err) {
|
|
151
|
+
lastError = err;
|
|
152
|
+
}
|
|
153
|
+
// 다음 재시도 전 대기: 1초, 2초, 4초 (마지막 시도 후에는 대기 없음)
|
|
154
|
+
if (i < maxRetries - 1) {
|
|
155
|
+
const backoffMs = Math.pow(2, i) * 1000; // i=0: 1초, i=1: 2초, i=2: 4초
|
|
156
|
+
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const error = new Error(`Hub 재시작 ${maxRetries}회 모두 실패${lastError ? `: ${lastError.message}` : ""}`);
|
|
161
|
+
error.code = "HUB_RESTART_FAILED";
|
|
162
|
+
error.cause = lastError;
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function fetchHubTaskList(state) {
|
|
167
|
+
const hubBase = (state?.hubUrl || getDefaultHubUrl()).replace(/\/mcp$/, "");
|
|
168
|
+
const teamName = state?.native?.teamName || state?.sessionName || null;
|
|
169
|
+
if (!teamName) return [];
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
const res = await fetch(`${hubBase}/bridge/team/task-list`, {
|
|
173
|
+
method: "POST",
|
|
174
|
+
headers: { "Content-Type": "application/json" },
|
|
175
|
+
body: JSON.stringify({ team_name: teamName }),
|
|
176
|
+
signal: AbortSignal.timeout(2000),
|
|
177
|
+
});
|
|
178
|
+
const data = await res.json();
|
|
179
|
+
return data?.ok ? (data.data?.tasks || []) : [];
|
|
180
|
+
} catch {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function publishLeadControl(state, targetMember, command, reason = "") {
|
|
186
|
+
const hubBase = (state?.hubUrl || getDefaultHubUrl()).replace(/\/mcp$/, "");
|
|
187
|
+
const leadAgent = (state?.members || []).find((member) => member.role === "lead")?.agentId || "lead";
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
const res = await fetch(`${hubBase}/bridge/control`, {
|
|
191
|
+
method: "POST",
|
|
192
|
+
headers: { "Content-Type": "application/json" },
|
|
193
|
+
body: JSON.stringify({
|
|
194
|
+
from_agent: leadAgent,
|
|
195
|
+
to_agent: targetMember.agentId,
|
|
196
|
+
command,
|
|
197
|
+
reason,
|
|
198
|
+
payload: {
|
|
199
|
+
issued_by: leadAgent,
|
|
200
|
+
issued_at: Date.now(),
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
return !!res.ok;
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
4
|
-
|
|
5
|
-
import { buildLeadPrompt, buildPrompt } from "../../orchestrator.mjs";
|
|
6
|
-
import { HUB_PID_DIR, PKG_ROOT } from "./state-store.mjs";
|
|
7
|
-
import { FEATURES } from "../../codex-compat.mjs";
|
|
8
|
-
|
|
9
|
-
export function buildNativeCliCommand(cli) {
|
|
10
|
-
switch (cli) {
|
|
11
|
-
case "codex":
|
|
12
|
-
return FEATURES.execSubcommand
|
|
13
|
-
? "codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check"
|
|
14
|
-
: "codex --dangerously-bypass-approvals-and-sandbox";
|
|
15
|
-
case "gemini":
|
|
16
|
-
return "gemini";
|
|
17
|
-
case "claude":
|
|
18
|
-
return "claude";
|
|
19
|
-
default:
|
|
20
|
-
return cli;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function startNativeSupervisor({ sessionId, task, lead, agents, subtasks, hubUrl }) {
|
|
25
|
-
const configPath = join(HUB_PID_DIR, `team-native-${sessionId}.config.json`);
|
|
26
|
-
const runtimePath = join(HUB_PID_DIR, `team-native-${sessionId}.runtime.json`);
|
|
27
|
-
const logsDir = join(HUB_PID_DIR, "team-logs", sessionId);
|
|
28
|
-
mkdirSync(logsDir, { recursive: true });
|
|
29
|
-
|
|
30
|
-
const leadMember = {
|
|
31
|
-
role: "lead",
|
|
32
|
-
name: "lead",
|
|
33
|
-
cli: lead,
|
|
34
|
-
agentId: `${lead}-lead`,
|
|
35
|
-
command: buildNativeCliCommand(lead),
|
|
36
|
-
};
|
|
37
|
-
const workers = agents.map((cli, index) => ({
|
|
38
|
-
role: "worker",
|
|
39
|
-
name: `${cli}-${index + 1}`,
|
|
40
|
-
cli,
|
|
41
|
-
agentId: `${cli}-w${index + 1}`,
|
|
42
|
-
command: buildNativeCliCommand(cli),
|
|
43
|
-
subtask: subtasks[index],
|
|
44
|
-
}));
|
|
45
|
-
const members = [
|
|
46
|
-
{
|
|
47
|
-
...leadMember,
|
|
48
|
-
prompt: buildLeadPrompt(task, {
|
|
49
|
-
agentId: leadMember.agentId,
|
|
50
|
-
hubUrl,
|
|
51
|
-
teammateMode: "in-process",
|
|
52
|
-
workers: workers.map((worker) => ({
|
|
53
|
-
agentId: worker.agentId,
|
|
54
|
-
cli: worker.cli,
|
|
55
|
-
subtask: worker.subtask,
|
|
56
|
-
})),
|
|
57
|
-
}),
|
|
58
|
-
},
|
|
59
|
-
...workers.map((worker) => ({
|
|
60
|
-
...worker,
|
|
61
|
-
prompt: buildPrompt(worker.subtask, { cli: worker.cli, agentId: worker.agentId, hubUrl }),
|
|
62
|
-
})),
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
writeFileSync(configPath, JSON.stringify({
|
|
66
|
-
sessionName: sessionId,
|
|
67
|
-
hubUrl,
|
|
68
|
-
startupDelayMs: 3000,
|
|
69
|
-
logsDir,
|
|
70
|
-
runtimeFile: runtimePath,
|
|
71
|
-
members,
|
|
72
|
-
}, null, 2) + "\n");
|
|
73
|
-
|
|
74
|
-
const child = spawn(process.execPath, [join(PKG_ROOT, "hub", "team", "native-supervisor.mjs"), "--config", configPath], {
|
|
75
|
-
detached: true,
|
|
76
|
-
stdio: "ignore",
|
|
77
|
-
env: { ...process.env },
|
|
78
|
-
windowsHide: true,
|
|
79
|
-
});
|
|
80
|
-
child.unref();
|
|
81
|
-
|
|
82
|
-
const deadline = Date.now() + 5000;
|
|
83
|
-
while (Date.now() < deadline) {
|
|
84
|
-
if (existsSync(runtimePath)) {
|
|
85
|
-
try {
|
|
86
|
-
const runtime = JSON.parse(readFileSync(runtimePath, "utf8"));
|
|
87
|
-
return { runtime, members };
|
|
88
|
-
} catch {}
|
|
89
|
-
}
|
|
90
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return { runtime: null, members };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export async function nativeRequest(state, path, body = {}) {
|
|
97
|
-
if (!state?.native?.controlUrl) return null;
|
|
98
|
-
try {
|
|
99
|
-
const res = await fetch(`${state.native.controlUrl}${path}`, {
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: { "Content-Type": "application/json" },
|
|
102
|
-
body: JSON.stringify(body),
|
|
103
|
-
});
|
|
104
|
-
return await res.json();
|
|
105
|
-
} catch {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function nativeGetStatus(state) {
|
|
111
|
-
if (!state?.native?.controlUrl) return null;
|
|
112
|
-
try {
|
|
113
|
-
const res = await fetch(`${state.native.controlUrl}/status`);
|
|
114
|
-
return await res.json();
|
|
115
|
-
} catch {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
import { buildLeadPrompt, buildPrompt } from "../../orchestrator.mjs";
|
|
6
|
+
import { HUB_PID_DIR, PKG_ROOT } from "./state-store.mjs";
|
|
7
|
+
import { FEATURES } from "../../codex-compat.mjs";
|
|
8
|
+
|
|
9
|
+
export function buildNativeCliCommand(cli) {
|
|
10
|
+
switch (cli) {
|
|
11
|
+
case "codex":
|
|
12
|
+
return FEATURES.execSubcommand
|
|
13
|
+
? "codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check"
|
|
14
|
+
: "codex --dangerously-bypass-approvals-and-sandbox";
|
|
15
|
+
case "gemini":
|
|
16
|
+
return "gemini";
|
|
17
|
+
case "claude":
|
|
18
|
+
return "claude";
|
|
19
|
+
default:
|
|
20
|
+
return cli;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function startNativeSupervisor({ sessionId, task, lead, agents, subtasks, hubUrl }) {
|
|
25
|
+
const configPath = join(HUB_PID_DIR, `team-native-${sessionId}.config.json`);
|
|
26
|
+
const runtimePath = join(HUB_PID_DIR, `team-native-${sessionId}.runtime.json`);
|
|
27
|
+
const logsDir = join(HUB_PID_DIR, "team-logs", sessionId);
|
|
28
|
+
mkdirSync(logsDir, { recursive: true });
|
|
29
|
+
|
|
30
|
+
const leadMember = {
|
|
31
|
+
role: "lead",
|
|
32
|
+
name: "lead",
|
|
33
|
+
cli: lead,
|
|
34
|
+
agentId: `${lead}-lead`,
|
|
35
|
+
command: buildNativeCliCommand(lead),
|
|
36
|
+
};
|
|
37
|
+
const workers = agents.map((cli, index) => ({
|
|
38
|
+
role: "worker",
|
|
39
|
+
name: `${cli}-${index + 1}`,
|
|
40
|
+
cli,
|
|
41
|
+
agentId: `${cli}-w${index + 1}`,
|
|
42
|
+
command: buildNativeCliCommand(cli),
|
|
43
|
+
subtask: subtasks[index],
|
|
44
|
+
}));
|
|
45
|
+
const members = [
|
|
46
|
+
{
|
|
47
|
+
...leadMember,
|
|
48
|
+
prompt: buildLeadPrompt(task, {
|
|
49
|
+
agentId: leadMember.agentId,
|
|
50
|
+
hubUrl,
|
|
51
|
+
teammateMode: "in-process",
|
|
52
|
+
workers: workers.map((worker) => ({
|
|
53
|
+
agentId: worker.agentId,
|
|
54
|
+
cli: worker.cli,
|
|
55
|
+
subtask: worker.subtask,
|
|
56
|
+
})),
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
...workers.map((worker) => ({
|
|
60
|
+
...worker,
|
|
61
|
+
prompt: buildPrompt(worker.subtask, { cli: worker.cli, agentId: worker.agentId, hubUrl }),
|
|
62
|
+
})),
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
writeFileSync(configPath, JSON.stringify({
|
|
66
|
+
sessionName: sessionId,
|
|
67
|
+
hubUrl,
|
|
68
|
+
startupDelayMs: 3000,
|
|
69
|
+
logsDir,
|
|
70
|
+
runtimeFile: runtimePath,
|
|
71
|
+
members,
|
|
72
|
+
}, null, 2) + "\n");
|
|
73
|
+
|
|
74
|
+
const child = spawn(process.execPath, [join(PKG_ROOT, "hub", "team", "native-supervisor.mjs"), "--config", configPath], {
|
|
75
|
+
detached: true,
|
|
76
|
+
stdio: "ignore",
|
|
77
|
+
env: { ...process.env },
|
|
78
|
+
windowsHide: true,
|
|
79
|
+
});
|
|
80
|
+
child.unref();
|
|
81
|
+
|
|
82
|
+
const deadline = Date.now() + 5000;
|
|
83
|
+
while (Date.now() < deadline) {
|
|
84
|
+
if (existsSync(runtimePath)) {
|
|
85
|
+
try {
|
|
86
|
+
const runtime = JSON.parse(readFileSync(runtimePath, "utf8"));
|
|
87
|
+
return { runtime, members };
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { runtime: null, members };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function nativeRequest(state, path, body = {}) {
|
|
97
|
+
if (!state?.native?.controlUrl) return null;
|
|
98
|
+
try {
|
|
99
|
+
const res = await fetch(`${state.native.controlUrl}${path}`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: { "Content-Type": "application/json" },
|
|
102
|
+
body: JSON.stringify(body),
|
|
103
|
+
});
|
|
104
|
+
return await res.json();
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function nativeGetStatus(state) {
|
|
111
|
+
if (!state?.native?.controlUrl) return null;
|
|
112
|
+
try {
|
|
113
|
+
const res = await fetch(`${state.native.controlUrl}/status`);
|
|
114
|
+
return await res.json();
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|