@triflux/remote 10.51.0 → 10.52.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/cto/brief.mjs +0 -8
- package/cto/collect.mjs +1 -127
- package/cto/current.schema.json +2 -19
- package/cto/hygiene.mjs +2 -61
- package/cto/lake-root.mjs +0 -56
- package/cto/status.mjs +5 -139
- package/hub/index.mjs +0 -9
- package/hub/team/agents-row-attach.py +120 -0
- package/hub/team/agents-row.mjs +200 -0
- package/hub/team/claude-daemon-control.mjs +1 -2
- package/hub/team/claude-session-projection.mjs +5 -73
- package/hub/team/cli/commands/debug.mjs +1 -2
- package/hub/team/cli/commands/start/index.mjs +2 -1
- package/hub/team/cli/commands/start/start-mux.mjs +2 -4
- package/hub/team/cli/services/state-store.mjs +5 -20
- package/hub/team/headless.mjs +96 -543
- package/hub/team/psmux.mjs +3 -33
- package/hub/team/session-context.mjs +1 -1
- package/hub/team/tui-viewer.mjs +9 -56
- package/hub/team/tui.mjs +0 -37
- package/hub/team/uds-orchestrator.mjs +2 -580
- package/hub/workers/factory.mjs +6 -51
- package/hub/workers/interface.mjs +1 -7
- package/hub/workers/lib/jsonrpc-core.mjs +11 -0
- package/hub/workers/lib/jsonrpc-ws-uds.mjs +5 -6
- package/package.json +3 -8
- package/scripts/lib/agent-route-policy.mjs +0 -67
- package/scripts/lib/cli-claude.mjs +0 -12
- package/scripts/lib/env-probe.mjs +0 -70
- package/scripts/lib/legacy-mcp-cleanup.mjs +283 -0
- package/scripts/lib/mcp-guard-engine.mjs +40 -98
- package/hub/hub-lifecycle.mjs +0 -248
- package/hub/pipe.mjs +0 -825
- package/hub/promote-penalties.mjs +0 -138
- package/hub/public/dashboard.html +0 -416
- package/hub/schema.sql +0 -209
- package/hub/server.mjs +0 -3048
- package/hub/store-adapter.mjs +0 -182
- package/hub/store.mjs +0 -1736
- package/hub/team/cli/services/hub-client.mjs +0 -178
- package/hub/team/conductor-registry.mjs +0 -121
- package/hub/team/cto-auto-collect.mjs +0 -115
- package/hub/team/lead-control.mjs +0 -191
- package/hub/team/session-sync.mjs +0 -316
- package/hub/team/swarm-intent.mjs +0 -18
- package/hub/team/synapse-cli.mjs +0 -458
- package/hub/team/synapse-http.mjs +0 -311
- package/hub/team/synapse-registry.mjs +0 -618
- package/hub/team/tui-synapse.mjs +0 -223
- package/hub/team/worker-sandbox.mjs +0 -125
- package/hub/tools.mjs +0 -900
- package/hub/workers/codex-app-server-worker.mjs +0 -1067
- package/hub/workers/delegator-mcp.mjs +0 -1098
- package/hub/workers/lib/jsonrpc-stdio.mjs +0 -204
- package/scripts/lib/claudemd-scanner.mjs +0 -26
- package/scripts/lib/context.mjs +0 -51
- package/scripts/lib/handoff.mjs +0 -187
- package/scripts/lib/logger.mjs +0 -122
- package/scripts/lib/stealth-fetch.mjs +0 -176
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { readState } from "@triflux/core/hub/state.mjs";
|
|
2
|
-
|
|
3
|
-
const DEFAULT_TIMEOUT_MS = 2500;
|
|
4
|
-
const DEFAULT_HEADLESS_POLL_MS = 1000;
|
|
5
|
-
|
|
6
|
-
function resolveFetch(fetchImpl) {
|
|
7
|
-
if (typeof fetchImpl === "function") return fetchImpl;
|
|
8
|
-
if (typeof globalThis.fetch === "function")
|
|
9
|
-
return globalThis.fetch.bind(globalThis);
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function normalizeHubBaseUrl(hubUrl) {
|
|
14
|
-
return String(hubUrl || "")
|
|
15
|
-
.replace(/\/+$/, "")
|
|
16
|
-
.replace(/\/mcp$/, "");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function safeAbortSignal(timeoutMs) {
|
|
20
|
-
if (typeof AbortSignal?.timeout !== "function") return undefined;
|
|
21
|
-
return AbortSignal.timeout(timeoutMs);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isPidAlive(pid) {
|
|
25
|
-
const resolvedPid = Number(pid);
|
|
26
|
-
if (!Number.isFinite(resolvedPid) || resolvedPid <= 0) return false;
|
|
27
|
-
try {
|
|
28
|
-
process.kill(resolvedPid, 0);
|
|
29
|
-
return true;
|
|
30
|
-
} catch {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function resolveHeadlessHubUrl(hubUrl) {
|
|
36
|
-
const normalized = normalizeHubBaseUrl(hubUrl);
|
|
37
|
-
if (normalized) return normalized;
|
|
38
|
-
|
|
39
|
-
const stateUrl = normalizeHubBaseUrl(readState()?.url);
|
|
40
|
-
if (stateUrl) return stateUrl;
|
|
41
|
-
|
|
42
|
-
const envHubUrl = normalizeHubBaseUrl(process.env.TFX_HUB_URL);
|
|
43
|
-
if (envHubUrl) return envHubUrl;
|
|
44
|
-
|
|
45
|
-
const envPort = Number(process.env.TFX_HUB_PORT || "27888");
|
|
46
|
-
const port = Number.isFinite(envPort) && envPort > 0 ? envPort : 27888;
|
|
47
|
-
return `http://127.0.0.1:${port}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function hasLiveHubState() {
|
|
51
|
-
const state = readState();
|
|
52
|
-
return !!normalizeHubBaseUrl(state?.url) && isPidAlive(state?.pid);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function toHeadlessSessionAgentId(sessionName) {
|
|
56
|
-
const normalizedSessionName = String(sessionName || "").trim();
|
|
57
|
-
return normalizedSessionName ? `session:${normalizedSessionName}` : "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function dispatchHeadlessCommand(command, callbacks) {
|
|
61
|
-
const callbackMap = {
|
|
62
|
-
pause: callbacks.onPause,
|
|
63
|
-
resume: callbacks.onResume,
|
|
64
|
-
abort: callbacks.onAbort,
|
|
65
|
-
reassign: callbacks.onReassign,
|
|
66
|
-
};
|
|
67
|
-
const handler = callbackMap[command?.command];
|
|
68
|
-
if (typeof handler === "function") {
|
|
69
|
-
await handler(command);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function safeJson(res) {
|
|
74
|
-
try {
|
|
75
|
-
return await res.json();
|
|
76
|
-
} catch {
|
|
77
|
-
return {};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function normalizeLeadCommandMessage(message) {
|
|
82
|
-
const payload =
|
|
83
|
-
message?.payload && typeof message.payload === "object"
|
|
84
|
-
? message.payload
|
|
85
|
-
: {};
|
|
86
|
-
const command = String(payload.command || "")
|
|
87
|
-
.trim()
|
|
88
|
-
.toLowerCase();
|
|
89
|
-
if (!command) return null;
|
|
90
|
-
return {
|
|
91
|
-
messageId: message.id || null,
|
|
92
|
-
topic: message.topic || "lead.control",
|
|
93
|
-
fromAgent: message.from_agent || payload.issued_by || "lead",
|
|
94
|
-
command,
|
|
95
|
-
reason: payload.reason || "",
|
|
96
|
-
payload,
|
|
97
|
-
traceId: message.trace_id || null,
|
|
98
|
-
correlationId: message.correlation_id || null,
|
|
99
|
-
createdAtMs: message.created_at_ms || null,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function subscribeToLeadCommands({
|
|
104
|
-
hubUrl,
|
|
105
|
-
agentId,
|
|
106
|
-
maxMessages = 10,
|
|
107
|
-
autoAck = true,
|
|
108
|
-
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
109
|
-
topics = ["lead.control"],
|
|
110
|
-
onCommand = null,
|
|
111
|
-
fetchImpl,
|
|
112
|
-
} = {}) {
|
|
113
|
-
const requestFetch = resolveFetch(fetchImpl);
|
|
114
|
-
if (!requestFetch) {
|
|
115
|
-
return { ok: false, error: "FETCH_UNAVAILABLE", commands: [] };
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const hubBase = normalizeHubBaseUrl(hubUrl);
|
|
119
|
-
if (!hubBase) {
|
|
120
|
-
return { ok: false, error: "HUB_URL_REQUIRED", commands: [] };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const normalizedAgentId = String(agentId || "").trim();
|
|
124
|
-
if (!normalizedAgentId) {
|
|
125
|
-
return { ok: false, error: "AGENT_ID_REQUIRED", commands: [] };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const res = await requestFetch(`${hubBase}/bridge/context`, {
|
|
130
|
-
method: "POST",
|
|
131
|
-
headers: { "Content-Type": "application/json" },
|
|
132
|
-
body: JSON.stringify({
|
|
133
|
-
agent_id: normalizedAgentId,
|
|
134
|
-
topics: Array.isArray(topics) ? topics : ["lead.control"],
|
|
135
|
-
max_messages: maxMessages,
|
|
136
|
-
auto_ack: autoAck,
|
|
137
|
-
}),
|
|
138
|
-
signal: safeAbortSignal(timeoutMs),
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const body = await safeJson(res);
|
|
142
|
-
const messages = Array.isArray(body?.data?.messages)
|
|
143
|
-
? body.data.messages
|
|
144
|
-
: [];
|
|
145
|
-
const commands = messages
|
|
146
|
-
.filter((message) => message?.topic === "lead.control")
|
|
147
|
-
.map(normalizeLeadCommandMessage)
|
|
148
|
-
.filter(Boolean);
|
|
149
|
-
|
|
150
|
-
if (typeof onCommand === "function") {
|
|
151
|
-
for (const command of commands) {
|
|
152
|
-
await onCommand(command);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
ok: res.ok && body?.ok !== false,
|
|
158
|
-
status: res.status,
|
|
159
|
-
commands,
|
|
160
|
-
messageCount: messages.length,
|
|
161
|
-
body,
|
|
162
|
-
};
|
|
163
|
-
} catch (error) {
|
|
164
|
-
return {
|
|
165
|
-
ok: false,
|
|
166
|
-
error: "LEAD_COMMAND_SUBSCRIBE_FAILED",
|
|
167
|
-
message: error?.message || "lead command subscribe failed",
|
|
168
|
-
commands: [],
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function createHeadlessControlSubscriber(
|
|
174
|
-
sessionName,
|
|
175
|
-
{
|
|
176
|
-
onPause,
|
|
177
|
-
onResume,
|
|
178
|
-
onAbort,
|
|
179
|
-
onReassign,
|
|
180
|
-
hubUrl,
|
|
181
|
-
pollIntervalMs = DEFAULT_HEADLESS_POLL_MS,
|
|
182
|
-
maxMessages = 10,
|
|
183
|
-
autoAck = true,
|
|
184
|
-
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
185
|
-
fetchImpl,
|
|
186
|
-
} = {},
|
|
187
|
-
) {
|
|
188
|
-
const sessionAgentId = toHeadlessSessionAgentId(sessionName);
|
|
189
|
-
if (!sessionAgentId) {
|
|
190
|
-
return { stop() {} };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const explicitHubUrl =
|
|
194
|
-
normalizeHubBaseUrl(hubUrl) || normalizeHubBaseUrl(process.env.TFX_HUB_URL);
|
|
195
|
-
if (!explicitHubUrl && !hasLiveHubState()) {
|
|
196
|
-
return { stop() {} };
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const resolvedHubUrl = explicitHubUrl || resolveHeadlessHubUrl(hubUrl);
|
|
200
|
-
const callbacks = { onPause, onResume, onAbort, onReassign };
|
|
201
|
-
const intervalMs = Math.max(
|
|
202
|
-
50,
|
|
203
|
-
Number(pollIntervalMs) || DEFAULT_HEADLESS_POLL_MS,
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
let stopped = false;
|
|
207
|
-
let timer = null;
|
|
208
|
-
let pending = false;
|
|
209
|
-
|
|
210
|
-
const stop = () => {
|
|
211
|
-
stopped = true;
|
|
212
|
-
if (timer) clearTimeout(timer);
|
|
213
|
-
timer = null;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const scheduleNext = () => {
|
|
217
|
-
if (stopped) return;
|
|
218
|
-
timer = setTimeout(tick, intervalMs);
|
|
219
|
-
if (typeof timer?.unref === "function") timer.unref();
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const tick = async () => {
|
|
223
|
-
if (stopped || pending) {
|
|
224
|
-
scheduleNext();
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
pending = true;
|
|
229
|
-
try {
|
|
230
|
-
const result = await subscribeToLeadCommands({
|
|
231
|
-
hubUrl: resolvedHubUrl,
|
|
232
|
-
agentId: sessionAgentId,
|
|
233
|
-
maxMessages,
|
|
234
|
-
autoAck,
|
|
235
|
-
timeoutMs,
|
|
236
|
-
fetchImpl,
|
|
237
|
-
onCommand: async (command) => {
|
|
238
|
-
await dispatchHeadlessCommand(command, callbacks);
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
if (!result?.ok && result?.error === "LEAD_COMMAND_SUBSCRIBE_FAILED") {
|
|
243
|
-
stop();
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
} finally {
|
|
247
|
-
pending = false;
|
|
248
|
-
scheduleNext();
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
void tick();
|
|
253
|
-
|
|
254
|
-
return { stop };
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export async function getTeamStatus({
|
|
258
|
-
hubUrl,
|
|
259
|
-
scope = "hub",
|
|
260
|
-
agentId,
|
|
261
|
-
includeMetrics = true,
|
|
262
|
-
method = "GET",
|
|
263
|
-
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
264
|
-
fetchImpl,
|
|
265
|
-
} = {}) {
|
|
266
|
-
const requestFetch = resolveFetch(fetchImpl);
|
|
267
|
-
if (!requestFetch) {
|
|
268
|
-
return { ok: false, error: "FETCH_UNAVAILABLE" };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const hubBase = normalizeHubBaseUrl(hubUrl);
|
|
272
|
-
if (!hubBase) {
|
|
273
|
-
return { ok: false, error: "HUB_URL_REQUIRED" };
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const normalizedMethod =
|
|
277
|
-
String(method || "GET").toUpperCase() === "POST" ? "POST" : "GET";
|
|
278
|
-
const statusScope = String(scope || "hub").trim() || "hub";
|
|
279
|
-
|
|
280
|
-
let endpoint = `${hubBase}/bridge/status`;
|
|
281
|
-
const options = {
|
|
282
|
-
method: normalizedMethod,
|
|
283
|
-
headers: { "Content-Type": "application/json" },
|
|
284
|
-
signal: safeAbortSignal(timeoutMs),
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
if (normalizedMethod === "GET") {
|
|
288
|
-
const params = new URLSearchParams({ scope: statusScope });
|
|
289
|
-
if (agentId) params.set("agent_id", String(agentId));
|
|
290
|
-
if (!includeMetrics) params.set("include_metrics", "0");
|
|
291
|
-
endpoint = `${endpoint}?${params.toString()}`;
|
|
292
|
-
} else {
|
|
293
|
-
options.body = JSON.stringify({
|
|
294
|
-
scope: statusScope,
|
|
295
|
-
agent_id: agentId || undefined,
|
|
296
|
-
include_metrics: includeMetrics,
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
try {
|
|
301
|
-
const res = await requestFetch(endpoint, options);
|
|
302
|
-
const body = await safeJson(res);
|
|
303
|
-
return {
|
|
304
|
-
ok: res.ok && body?.ok !== false,
|
|
305
|
-
status: res.status,
|
|
306
|
-
body,
|
|
307
|
-
data: body?.data || null,
|
|
308
|
-
};
|
|
309
|
-
} catch (error) {
|
|
310
|
-
return {
|
|
311
|
-
ok: false,
|
|
312
|
-
error: "TEAM_STATUS_FETCH_FAILED",
|
|
313
|
-
message: error?.message || "team status fetch failed",
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const INTENT_TRAILER_REGEX = /^X-Intent:\s*(.+)$/m;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Parse an X-Intent trailer from a commit message.
|
|
5
|
-
* @param {string} commitMessage
|
|
6
|
-
* @returns {object | null}
|
|
7
|
-
*/
|
|
8
|
-
export function parseIntentTrailer(commitMessage) {
|
|
9
|
-
const message = String(commitMessage ?? "");
|
|
10
|
-
const match = message.match(INTENT_TRAILER_REGEX);
|
|
11
|
-
if (!match) return null;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
return JSON.parse(match[1]);
|
|
15
|
-
} catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}
|