@triflux/remote 10.50.2 → 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.
Files changed (134) hide show
  1. package/cto/brief.mjs +0 -20
  2. package/cto/collect.mjs +1 -200
  3. package/cto/current.schema.json +2 -23
  4. package/cto/hygiene.mjs +2 -61
  5. package/cto/lake-root.mjs +0 -56
  6. package/cto/status.mjs +5 -187
  7. package/hub/index.mjs +0 -17
  8. package/hub/team/agent-map.json +0 -1
  9. package/hub/team/agents-row-attach.py +120 -0
  10. package/hub/team/agents-row.mjs +200 -0
  11. package/hub/team/ansi.mjs +1 -35
  12. package/hub/team/backend.mjs +9 -145
  13. package/hub/team/claude-daemon-control.mjs +1 -2
  14. package/hub/team/claude-session-projection.mjs +5 -73
  15. package/hub/team/cli/commands/attach.mjs +1 -17
  16. package/hub/team/cli/commands/control.mjs +12 -38
  17. package/hub/team/cli/commands/debug.mjs +2 -39
  18. package/hub/team/cli/commands/focus.mjs +5 -31
  19. package/hub/team/cli/commands/interrupt.mjs +6 -25
  20. package/hub/team/cli/commands/kill.mjs +1 -30
  21. package/hub/team/cli/commands/list.mjs +0 -16
  22. package/hub/team/cli/commands/send.mjs +6 -26
  23. package/hub/team/cli/commands/start/index.mjs +42 -133
  24. package/hub/team/cli/commands/start/parse-args.mjs +15 -40
  25. package/hub/team/cli/commands/start/start-headless.mjs +138 -105
  26. package/hub/team/cli/commands/start/start-mux.mjs +2 -7
  27. package/hub/team/cli/commands/status.mjs +2 -57
  28. package/hub/team/cli/commands/stop.mjs +14 -19
  29. package/hub/team/cli/help.mjs +4 -5
  30. package/hub/team/cli/manifest.mjs +5 -1
  31. package/hub/team/cli/render.mjs +0 -12
  32. package/hub/team/cli/services/runtime-mode.mjs +27 -98
  33. package/hub/team/cli/services/state-store.mjs +5 -20
  34. package/hub/team/handoff.mjs +3 -34
  35. package/hub/team/headless.mjs +108 -1296
  36. package/hub/team/orchestrator.mjs +4 -30
  37. package/hub/team/pane.mjs +6 -28
  38. package/hub/team/psmux.mjs +3 -34
  39. package/hub/team/remote-session.mjs +1 -2
  40. package/hub/team/session-context.mjs +1 -1
  41. package/hub/team/session.mjs +7 -91
  42. package/hub/team/tui-core.mjs +1 -1
  43. package/hub/team/tui-viewer.mjs +11 -58
  44. package/hub/team/tui.mjs +8 -306
  45. package/hub/team/uds-orchestrator.mjs +2 -580
  46. package/hub/team/wt-manager.mjs +2 -2
  47. package/hub/workers/factory.mjs +6 -84
  48. package/hub/workers/interface.mjs +1 -7
  49. package/hub/workers/lib/jsonrpc-core.mjs +11 -0
  50. package/hub/workers/lib/jsonrpc-ws-uds.mjs +5 -8
  51. package/package.json +3 -8
  52. package/scripts/lib/agent-route-policy.mjs +143 -62
  53. package/scripts/lib/cli-claude.mjs +0 -14
  54. package/scripts/lib/env-probe.mjs +2 -131
  55. package/scripts/lib/gemini-profiles.mjs +2 -69
  56. package/scripts/lib/legacy-mcp-cleanup.mjs +283 -0
  57. package/scripts/lib/machine-profile.mjs +3 -17
  58. package/scripts/lib/mcp-filter.mjs +109 -53
  59. package/scripts/lib/mcp-guard-engine.mjs +40 -98
  60. package/scripts/lib/mcp-health.mjs +2 -2
  61. package/scripts/lib/mcp-server-catalog.mjs +2 -2
  62. package/scripts/lib/psmux-info.mjs +11 -59
  63. package/scripts/lib/skill-template.mjs +0 -245
  64. package/hub/hub-lifecycle.mjs +0 -248
  65. package/hub/pipe.mjs +0 -825
  66. package/hub/promote-penalties.mjs +0 -138
  67. package/hub/public/dashboard.html +0 -416
  68. package/hub/schema.sql +0 -209
  69. package/hub/server.mjs +0 -3048
  70. package/hub/store-adapter.mjs +0 -182
  71. package/hub/store.mjs +0 -1736
  72. package/hub/team/build-worker-prompt.mjs +0 -92
  73. package/hub/team/check-mcp-hub.mjs +0 -49
  74. package/hub/team/claude-native-bridge.mjs +0 -987
  75. package/hub/team/cli/commands/start/start-in-process.mjs +0 -50
  76. package/hub/team/cli/commands/start/start-wt.mjs +0 -86
  77. package/hub/team/cli/services/hub-client.mjs +0 -264
  78. package/hub/team/cli/services/native-control.mjs +0 -145
  79. package/hub/team/codex-review.mjs +0 -520
  80. package/hub/team/conductor-mesh-bridge.mjs +0 -122
  81. package/hub/team/conductor-registry.mjs +0 -121
  82. package/hub/team/conductor.mjs +0 -1529
  83. package/hub/team/consensus-meta.mjs +0 -176
  84. package/hub/team/cto-auto-collect.mjs +0 -115
  85. package/hub/team/cto-pull.mjs +0 -31
  86. package/hub/team/daemon-pty-tmux-bridge.mjs +0 -146
  87. package/hub/team/dashboard.mjs +0 -322
  88. package/hub/team/event-log.mjs +0 -84
  89. package/hub/team/execution-mode.mjs +0 -324
  90. package/hub/team/extract-completion-payload.mjs +0 -110
  91. package/hub/team/headless-bridge-session.mjs +0 -17
  92. package/hub/team/health-probe.mjs +0 -435
  93. package/hub/team/interactive-native-launcher.mjs +0 -119
  94. package/hub/team/interactive-native-worker.mjs +0 -80
  95. package/hub/team/interactive-tui-transport.mjs +0 -479
  96. package/hub/team/launcher-template.mjs +0 -144
  97. package/hub/team/lead-control.mjs +0 -191
  98. package/hub/team/mcp-selector.mjs +0 -145
  99. package/hub/team/native-supervisor.mjs +0 -460
  100. package/hub/team/native.mjs +0 -727
  101. package/hub/team/recovery-store.mjs +0 -149
  102. package/hub/team/remote-probe.mjs +0 -292
  103. package/hub/team/remote-watcher.mjs +0 -506
  104. package/hub/team/runtime-strategy.mjs +0 -200
  105. package/hub/team/schemas/worker-completion.json +0 -39
  106. package/hub/team/sentinel-capture.mjs +0 -127
  107. package/hub/team/session-sync.mjs +0 -316
  108. package/hub/team/swarm-cli.mjs +0 -390
  109. package/hub/team/swarm-hypervisor.mjs +0 -2206
  110. package/hub/team/swarm-intent.mjs +0 -216
  111. package/hub/team/swarm-locks.mjs +0 -335
  112. package/hub/team/swarm-planner.mjs +0 -371
  113. package/hub/team/swarm-preflight.mjs +0 -366
  114. package/hub/team/swarm-reconciler.mjs +0 -242
  115. package/hub/team/synapse-cli.mjs +0 -458
  116. package/hub/team/synapse-http.mjs +0 -311
  117. package/hub/team/synapse-registry.mjs +0 -618
  118. package/hub/team/tui-remote-adapter.mjs +0 -377
  119. package/hub/team/tui-synapse.mjs +0 -223
  120. package/hub/team/worker-completion-validator.mjs +0 -79
  121. package/hub/team/worker-sandbox.mjs +0 -125
  122. package/hub/team/worktree-lifecycle.mjs +0 -639
  123. package/hub/team/wt-templates.json +0 -43
  124. package/hub/tools.mjs +0 -900
  125. package/hub/workers/antigravity-route-worker.mjs +0 -179
  126. package/hub/workers/codex-app-server-worker.mjs +0 -1067
  127. package/hub/workers/delegator-mcp.mjs +0 -1098
  128. package/hub/workers/lib/jsonrpc-stdio.mjs +0 -204
  129. package/scripts/lib/claudemd-scanner.mjs +0 -223
  130. package/scripts/lib/context.mjs +0 -67
  131. package/scripts/lib/dynamic-route-cli.mjs +0 -107
  132. package/scripts/lib/handoff.mjs +0 -187
  133. package/scripts/lib/logger.mjs +0 -122
  134. 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
- }