@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,311 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
-
import { homedir, hostname } from "node:os";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
6
|
-
import { normalizeRoleKey } from "@triflux/core/hub/role-contract.mjs";
|
|
7
|
-
|
|
8
|
-
const HUB_DEFAULT_PORT = 27888;
|
|
9
|
-
// Same token file as hub/bridge.mjs (HUB_TOKEN_FILE). Kept inline rather than
|
|
10
|
-
// imported so this helper stays dependency-free and byte-identical across the
|
|
11
|
-
// packages/core mirror (which cannot carry relative cross-package imports).
|
|
12
|
-
const HUB_TOKEN_FILE = join(homedir(), ".claude", ".tfx-hub-token");
|
|
13
|
-
|
|
14
|
-
// In-flight fire-and-forget POSTs. A short-lived caller (the SessionStart hook,
|
|
15
|
-
// which process.exit(0)s immediately after firing register) must be able to
|
|
16
|
-
// flush these before the process dies: Node's process.exit() abandons pending
|
|
17
|
-
// socket I/O, so an un-awaited loopback POST is created but never written.
|
|
18
|
-
// Callers on an exit budget drain this set via drainPendingSynapse() first.
|
|
19
|
-
const inFlightSynapse = new Set();
|
|
20
|
-
|
|
21
|
-
function normalizeToken(raw) {
|
|
22
|
-
if (raw == null) return null;
|
|
23
|
-
const token = String(raw).trim();
|
|
24
|
-
return token || null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function opaqueId(prefix, value) {
|
|
28
|
-
return `${prefix}_${createHash("sha256")
|
|
29
|
-
.update(String(value || ""))
|
|
30
|
-
.digest("base64url")
|
|
31
|
-
.slice(0, 22)}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function normalizedProjectId(value) {
|
|
35
|
-
try {
|
|
36
|
-
return normalizeRoleKey({ project_id: value, role_kind: "cto" }).project_id;
|
|
37
|
-
} catch {
|
|
38
|
-
return "";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function resolveProjectId(cwd, meta, opts = {}) {
|
|
43
|
-
const explicit = meta?.project_id || process.env.TFX_PROJECT_ID;
|
|
44
|
-
if (explicit) return normalizedProjectId(explicit);
|
|
45
|
-
if (typeof opts.resolveProjectId === "function") {
|
|
46
|
-
return normalizedProjectId(opts.resolveProjectId(cwd));
|
|
47
|
-
}
|
|
48
|
-
let current = cwd;
|
|
49
|
-
while (current) {
|
|
50
|
-
const manifest = join(current, ".triflux", "project.json");
|
|
51
|
-
if (existsSync(manifest)) {
|
|
52
|
-
try {
|
|
53
|
-
const parsed = JSON.parse(readFileSync(manifest, "utf8"));
|
|
54
|
-
if (parsed?.schema_version !== "tfx.project.v1") return "";
|
|
55
|
-
return normalizedProjectId(parsed.project_id);
|
|
56
|
-
} catch {
|
|
57
|
-
return "";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const parent = dirname(current);
|
|
61
|
-
if (parent === current) break;
|
|
62
|
-
current = parent;
|
|
63
|
-
}
|
|
64
|
-
return "";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function inferSessionCli(meta, opts = {}) {
|
|
68
|
-
const explicit = String(meta?.cli || meta?.actor_cli || "")
|
|
69
|
-
.trim()
|
|
70
|
-
.toLowerCase();
|
|
71
|
-
if (explicit === "codex" || explicit === "claude") return explicit;
|
|
72
|
-
const entrypoint = String(opts.entrypoint ?? process.argv[1] ?? "");
|
|
73
|
-
if (entrypoint.includes("codex-session-hook")) return "codex";
|
|
74
|
-
if (entrypoint.includes("agy-session-hook")) return "other";
|
|
75
|
-
return "claude";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function resolveTmuxSession(meta, opts = {}) {
|
|
79
|
-
const explicit =
|
|
80
|
-
meta?.tmux_session || meta?.session_name || process.env.TFX_TMUX_SESSION;
|
|
81
|
-
if (explicit) return String(explicit).trim();
|
|
82
|
-
if (!process.env.TMUX) return "";
|
|
83
|
-
try {
|
|
84
|
-
const run =
|
|
85
|
-
opts.tmuxSessionName ||
|
|
86
|
-
(() =>
|
|
87
|
-
execFileSync("tmux", ["display-message", "-p", "#{session_name}"], {
|
|
88
|
-
encoding: "utf8",
|
|
89
|
-
timeout: 200,
|
|
90
|
-
windowsHide: true,
|
|
91
|
-
}));
|
|
92
|
-
return String(run() || "").trim();
|
|
93
|
-
} catch {
|
|
94
|
-
return "";
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function buildSynapseRegistrationMeta(meta, opts = {}) {
|
|
99
|
-
if (!meta || meta.sessionKind !== "interactive") return meta;
|
|
100
|
-
const sessionId = String(meta.sessionId || "").trim();
|
|
101
|
-
if (!sessionId) return meta;
|
|
102
|
-
const cwd = typeof meta.cwd === "string" ? meta.cwd : process.cwd();
|
|
103
|
-
const cli = inferSessionCli(meta, opts);
|
|
104
|
-
const hostId = String(
|
|
105
|
-
meta.host_id ||
|
|
106
|
-
process.env.TFX_HOST_ID ||
|
|
107
|
-
opaqueId("hst", opts.hostname?.() || hostname()),
|
|
108
|
-
).trim();
|
|
109
|
-
const expiresAtMs = Number(opts.nowMs?.() ?? Date.now()) + 299000;
|
|
110
|
-
const transportLocators = [];
|
|
111
|
-
if (cli === "claude") {
|
|
112
|
-
transportLocators.push({
|
|
113
|
-
schema_version: "tfx.transport-locator.v1",
|
|
114
|
-
transport_id: opaqueId("trn", `claude-uds:${hostId}:${sessionId}`),
|
|
115
|
-
kind: "claude-uds",
|
|
116
|
-
host_id: hostId,
|
|
117
|
-
capabilities: ["probe", "wake", "activate", "interrupt"],
|
|
118
|
-
priority: 100,
|
|
119
|
-
expires_at_ms: expiresAtMs,
|
|
120
|
-
locator: {
|
|
121
|
-
session_id: sessionId,
|
|
122
|
-
bridge_id: String(
|
|
123
|
-
meta.bridge_id || process.env.TFX_BRIDGE_ID || "local-hub",
|
|
124
|
-
),
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
const tmuxSession = resolveTmuxSession(meta, opts);
|
|
129
|
-
if (tmuxSession) {
|
|
130
|
-
const muxServerSource =
|
|
131
|
-
meta.mux_server_id ||
|
|
132
|
-
process.env.TFX_MUX_SERVER_ID ||
|
|
133
|
-
String(process.env.TMUX || "default").split(",", 1)[0];
|
|
134
|
-
transportLocators.push({
|
|
135
|
-
schema_version: "tfx.transport-locator.v1",
|
|
136
|
-
transport_id: opaqueId("trn", `tmux:${hostId}:${tmuxSession}`),
|
|
137
|
-
kind: "tmux",
|
|
138
|
-
host_id: hostId,
|
|
139
|
-
capabilities: ["probe", "wake", "activate", "interrupt"],
|
|
140
|
-
priority: cli === "codex" ? 100 : 50,
|
|
141
|
-
expires_at_ms: expiresAtMs,
|
|
142
|
-
locator: {
|
|
143
|
-
session_name: tmuxSession,
|
|
144
|
-
mux_server_id: opaqueId("mux", muxServerSource),
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
const directAgentId = `session:${sessionId}`;
|
|
149
|
-
return {
|
|
150
|
-
...meta,
|
|
151
|
-
agent_id:
|
|
152
|
-
meta.agent_id ||
|
|
153
|
-
(directAgentId.length <= 64 && /^[a-zA-Z0-9._:-]+$/u.test(directAgentId)
|
|
154
|
-
? directAgentId
|
|
155
|
-
: opaqueId("session", sessionId)),
|
|
156
|
-
cli,
|
|
157
|
-
project_id: resolveProjectId(cwd, meta, opts) || undefined,
|
|
158
|
-
session_id: meta.session_id || sessionId,
|
|
159
|
-
host_id: hostId,
|
|
160
|
-
transport_locators_json:
|
|
161
|
-
meta.transport_locators_json ?? JSON.stringify(transportLocators),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Mirrors hub/bridge.mjs:readHubToken — env override first, then the token file.
|
|
166
|
-
// Missing token → null (backward-compatible with token-less hubs).
|
|
167
|
-
function readHubToken() {
|
|
168
|
-
const envToken = normalizeToken(process.env.TFX_HUB_TOKEN);
|
|
169
|
-
if (envToken) return envToken;
|
|
170
|
-
try {
|
|
171
|
-
return normalizeToken(readFileSync(HUB_TOKEN_FILE, "utf8"));
|
|
172
|
-
} catch {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Wrap IPv6 hosts in [...] so they form a valid URL authority (cf. bridge.mjs).
|
|
178
|
-
function formatHostForUrl(host) {
|
|
179
|
-
return String(host).includes(":") ? `[${host}]` : host;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Resolve the hub base URL from env (TFX_HUB_URL / TFX_HUB_PORT) before falling
|
|
183
|
-
// back to the loopback default, so a cascaded / non-default hub port is hit
|
|
184
|
-
// instead of silently posting to 127.0.0.1:27888 and missing the live hub.
|
|
185
|
-
function resolveSynapseBaseUrl() {
|
|
186
|
-
const envUrl = normalizeToken(process.env.TFX_HUB_URL);
|
|
187
|
-
if (envUrl) return envUrl.replace(/\/mcp$/, "");
|
|
188
|
-
|
|
189
|
-
const envPort = Number.parseInt(String(process.env.TFX_HUB_PORT ?? ""), 10);
|
|
190
|
-
if (Number.isFinite(envPort) && envPort > 0) {
|
|
191
|
-
return `http://${formatHostForUrl("127.0.0.1")}:${envPort}`;
|
|
192
|
-
}
|
|
193
|
-
return `http://${formatHostForUrl("127.0.0.1")}:${HUB_DEFAULT_PORT}`;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function resolveSynapseFetch(fetchImpl) {
|
|
197
|
-
if (fetchImpl === null) return null;
|
|
198
|
-
if (typeof fetchImpl === "function") return fetchImpl;
|
|
199
|
-
if (typeof globalThis.fetch === "function") {
|
|
200
|
-
return globalThis.fetch.bind(globalThis);
|
|
201
|
-
}
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function buildSynapseTaskSummary(prompt, maxLength = 100) {
|
|
206
|
-
if (maxLength <= 0) return "";
|
|
207
|
-
return String(prompt ?? "").slice(0, maxLength);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export function fireAndForgetSynapse(path, payload, opts = {}) {
|
|
211
|
-
const fetchImpl = resolveSynapseFetch(opts.fetchImpl);
|
|
212
|
-
if (!fetchImpl) return false;
|
|
213
|
-
|
|
214
|
-
try {
|
|
215
|
-
const baseUrl = opts.baseUrl || resolveSynapseBaseUrl();
|
|
216
|
-
const url = new URL(path, baseUrl).toString();
|
|
217
|
-
const headers = { "content-type": "application/json" };
|
|
218
|
-
// token: false explicitly skips auth; otherwise reuse the hub token so a
|
|
219
|
-
// token-required hub does not 401 (the failure would be swallowed silently).
|
|
220
|
-
if (opts.token !== false) {
|
|
221
|
-
const token =
|
|
222
|
-
typeof opts.token === "string" && opts.token.trim()
|
|
223
|
-
? opts.token.trim()
|
|
224
|
-
: readHubToken();
|
|
225
|
-
if (token) headers.Authorization = `Bearer ${token}`;
|
|
226
|
-
}
|
|
227
|
-
const init = {
|
|
228
|
-
method: "POST",
|
|
229
|
-
headers,
|
|
230
|
-
body: JSON.stringify(payload),
|
|
231
|
-
};
|
|
232
|
-
// Optional bounded timeout so callers on a teardown budget (e.g. SessionEnd)
|
|
233
|
-
// cannot hang the host process if the hub stalls. The timer is unref'd so it
|
|
234
|
-
// never keeps the event loop (and thus the hook process) alive on its own.
|
|
235
|
-
let timer = null;
|
|
236
|
-
const timeoutMs = Number(opts.timeoutMs);
|
|
237
|
-
if (
|
|
238
|
-
Number.isFinite(timeoutMs) &&
|
|
239
|
-
timeoutMs > 0 &&
|
|
240
|
-
typeof AbortController === "function"
|
|
241
|
-
) {
|
|
242
|
-
const controller = new AbortController();
|
|
243
|
-
init.signal = controller.signal;
|
|
244
|
-
timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
245
|
-
if (typeof timer.unref === "function") timer.unref();
|
|
246
|
-
}
|
|
247
|
-
const tracked = Promise.resolve(fetchImpl(url, init))
|
|
248
|
-
.catch(() => {})
|
|
249
|
-
.finally(() => {
|
|
250
|
-
if (timer) clearTimeout(timer);
|
|
251
|
-
inFlightSynapse.delete(tracked);
|
|
252
|
-
});
|
|
253
|
-
inFlightSynapse.add(tracked);
|
|
254
|
-
return true;
|
|
255
|
-
} catch {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Await any in-flight fire-and-forget Synapse POSTs, bounded by timeoutMs so a
|
|
261
|
-
// stalled hub can never hang the caller. The SessionStart hook calls this right
|
|
262
|
-
// before process.exit(0) so the register POST actually flushes to the socket.
|
|
263
|
-
export function drainPendingSynapse(timeoutMs = 1000) {
|
|
264
|
-
if (inFlightSynapse.size === 0) return Promise.resolve();
|
|
265
|
-
const settled = Promise.allSettled([...inFlightSynapse]);
|
|
266
|
-
const ms = Number(timeoutMs);
|
|
267
|
-
if (!Number.isFinite(ms) || ms <= 0) return settled;
|
|
268
|
-
let timeout = null;
|
|
269
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
270
|
-
// Keep this timer ref'ed: drainPendingSynapse() is awaited specifically
|
|
271
|
-
// to hold the process open until either in-flight POSTs settle or the
|
|
272
|
-
// bounded drain budget expires. An unref'ed timer can let Node's test
|
|
273
|
-
// runner/process exit before the Promise resolves when no other handles
|
|
274
|
-
// remain.
|
|
275
|
-
timeout = setTimeout(resolve, ms);
|
|
276
|
-
});
|
|
277
|
-
return Promise.race([settled, timeoutPromise]).finally(() => {
|
|
278
|
-
if (timeout) clearTimeout(timeout);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export function registerSynapseSession(meta, opts = {}) {
|
|
283
|
-
return fireAndForgetSynapse(
|
|
284
|
-
"/synapse/register",
|
|
285
|
-
buildSynapseRegistrationMeta(meta, opts),
|
|
286
|
-
opts,
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export function heartbeatSynapseSession(
|
|
291
|
-
sessionId,
|
|
292
|
-
partialMeta = {},
|
|
293
|
-
opts = {},
|
|
294
|
-
) {
|
|
295
|
-
// The live route reads `{ sessionId, partial }` (hub/server.mjs
|
|
296
|
-
// /synapse/heartbeat → synapseRegistry.heartbeat(sessionId, partial)), so the
|
|
297
|
-
// helper must nest the meta under `partial` rather than spreading it top-level.
|
|
298
|
-
return fireAndForgetSynapse(
|
|
299
|
-
"/synapse/heartbeat",
|
|
300
|
-
{
|
|
301
|
-
sessionId,
|
|
302
|
-
partial:
|
|
303
|
-
partialMeta && typeof partialMeta === "object" ? partialMeta : {},
|
|
304
|
-
},
|
|
305
|
-
opts,
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export function unregisterSynapseSession(sessionId, opts = {}) {
|
|
310
|
-
return fireAndForgetSynapse("/synapse/unregister", { sessionId }, opts);
|
|
311
|
-
}
|