@triflux/remote 10.1.0 → 10.26.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/hub/pipe.mjs +239 -121
- package/hub/public/dashboard.html +61 -0
- package/hub/server.mjs +2179 -709
- package/hub/store-adapter.mjs +59 -26
- package/hub/store.mjs +356 -153
- package/hub/team/agent-map.json +26 -7
- package/hub/team/ansi.mjs +245 -146
- package/hub/team/backend.mjs +78 -17
- package/hub/team/build-worker-prompt.mjs +73 -0
- package/hub/team/check-mcp-hub.mjs +49 -0
- package/hub/team/claude-daemon-control.mjs +1130 -0
- package/hub/team/claude-native-bridge.mjs +1011 -0
- package/hub/team/claude-session-projection.mjs +74 -0
- package/hub/team/cli/commands/attach.mjs +57 -37
- package/hub/team/cli/commands/control.mjs +29 -8
- package/hub/team/cli/commands/debug.mjs +95 -74
- package/hub/team/cli/commands/focus.mjs +80 -53
- package/hub/team/cli/commands/interrupt.mjs +18 -6
- package/hub/team/cli/commands/kill.mjs +16 -5
- package/hub/team/cli/commands/list.mjs +31 -24
- package/hub/team/cli/commands/send.mjs +19 -6
- package/hub/team/cli/commands/start/index.mjs +151 -33
- package/hub/team/cli/commands/start/parse-args.mjs +97 -13
- package/hub/team/cli/commands/start/start-headless.mjs +155 -37
- package/hub/team/cli/commands/start/start-in-process.mjs +50 -40
- package/hub/team/cli/commands/start/start-mux.mjs +122 -73
- package/hub/team/cli/commands/start/start-wt.mjs +86 -69
- package/hub/team/cli/commands/status.mjs +43 -14
- package/hub/team/cli/commands/stop.mjs +11 -4
- package/hub/team/cli/commands/task.mjs +8 -3
- package/hub/team/cli/commands/tasks.mjs +13 -13
- package/hub/team/cli/help.mjs +1 -1
- package/hub/team/cli/index.mjs +2 -2
- package/hub/team/cli/manifest.mjs +38 -8
- package/hub/team/cli/render.mjs +52 -30
- package/hub/team/cli/services/attach-fallback.mjs +74 -54
- package/hub/team/cli/services/hub-client.mjs +44 -16
- package/hub/team/cli/services/member-selector.mjs +37 -30
- package/hub/team/cli/services/native-control.mjs +144 -116
- package/hub/team/cli/services/runtime-mode.mjs +61 -4
- package/hub/team/cli/services/state-store.mjs +66 -9
- package/hub/team/cli/services/task-model.mjs +40 -30
- package/hub/team/codex-review.mjs +521 -0
- package/hub/team/conductor-mesh-bridge.mjs +25 -24
- package/hub/team/conductor-registry.mjs +121 -0
- package/hub/team/conductor.mjs +1379 -671
- package/hub/team/consensus-meta.mjs +176 -0
- package/hub/team/dashboard-anchor.mjs +4 -5
- package/hub/team/dashboard-layout.mjs +3 -1
- package/hub/team/dashboard-open.mjs +20 -118
- package/hub/team/dashboard.mjs +76 -28
- package/hub/team/event-log.mjs +18 -10
- package/hub/team/execution-mode.mjs +256 -0
- package/hub/team/extract-completion-payload.mjs +110 -0
- package/hub/team/git-preflight.mjs +286 -0
- package/hub/team/handoff.mjs +49 -18
- package/hub/team/headless-bridge-session.mjs +17 -0
- package/hub/team/headless.mjs +2213 -1156
- package/hub/team/health-probe.mjs +232 -69
- package/hub/team/interactive-native-launcher.mjs +106 -0
- package/hub/team/interactive-native-worker.mjs +80 -0
- package/hub/team/interactive-tui-transport.mjs +465 -0
- package/hub/team/launcher-template.mjs +49 -17
- package/hub/team/lead-control.mjs +91 -4
- package/hub/team/mcp-selector.mjs +145 -0
- package/hub/team/native-supervisor.mjs +90 -26
- package/hub/team/native.mjs +120 -42
- package/hub/team/nativeProxy.mjs +184 -113
- package/hub/team/notify.mjs +147 -78
- package/hub/team/orchestrator.mjs +173 -161
- package/hub/team/pane.mjs +43 -20
- package/hub/team/process-cleanup.mjs +69 -25
- package/hub/team/psmux.mjs +1022 -281
- package/hub/team/recovery-store.mjs +149 -0
- package/hub/team/remote-probe.mjs +68 -52
- package/hub/team/remote-session.mjs +131 -59
- package/hub/team/remote-watcher.mjs +61 -33
- package/hub/team/retry-state-machine.mjs +336 -0
- package/hub/team/routing.mjs +51 -25
- package/hub/team/runtime-strategy.mjs +200 -0
- package/hub/team/schemas/worker-completion.json +39 -0
- package/hub/team/sentinel-capture.mjs +127 -0
- package/hub/team/session-sync.mjs +153 -6
- package/hub/team/session.mjs +574 -611
- package/hub/team/shared.mjs +13 -13
- package/hub/team/staleState.mjs +72 -30
- package/hub/team/swarm-cli.mjs +390 -0
- package/hub/team/swarm-hypervisor.mjs +1544 -193
- package/hub/team/swarm-intent.mjs +216 -0
- package/hub/team/swarm-locks.mjs +140 -25
- package/hub/team/swarm-planner.mjs +121 -21
- package/hub/team/swarm-preflight.mjs +319 -0
- package/hub/team/swarm-reconciler.mjs +128 -23
- package/hub/team/synapse-cli.mjs +458 -0
- package/hub/team/synapse-http.mjs +60 -0
- package/hub/team/synapse-registry.mjs +329 -0
- package/hub/team/terminal-opener.mjs +216 -0
- package/hub/team/tui-core.mjs +292 -0
- package/hub/team/tui-lite.mjs +237 -148
- package/hub/team/tui-remote-adapter.mjs +18 -34
- package/hub/team/tui-synapse.mjs +223 -0
- package/hub/team/tui-viewer.mjs +108 -48
- package/hub/team/tui-widgets.mjs +262 -0
- package/hub/team/tui.mjs +931 -439
- package/hub/team/worker-completion-validator.mjs +84 -0
- package/hub/team/worker-sandbox.mjs +97 -0
- package/hub/team/worker-signal.mjs +263 -0
- package/hub/team/worker-signal.types.d.ts +52 -0
- package/hub/team/worktree-lifecycle.mjs +517 -63
- package/hub/team/wt-manager.mjs +297 -26
- package/hub/tools.mjs +477 -252
- package/hub/tray.mjs +411 -368
- package/hub/workers/antigravity-route-worker.mjs +169 -0
- package/hub/workers/claude-worker.mjs +162 -118
- package/hub/workers/codex-app-server-worker.mjs +1015 -0
- package/hub/workers/codex-mcp.mjs +724 -507
- package/hub/workers/delegator-mcp.mjs +570 -499
- package/hub/workers/factory.mjs +103 -21
- package/hub/workers/gemini-worker.mjs +126 -284
- package/hub/workers/interface.mjs +24 -2
- package/hub/workers/lib/jsonrpc-stdio.mjs +463 -0
- package/hub/workers/worker-utils.mjs +23 -17
- package/package.json +4 -3
- package/scripts/lib/agent-json.mjs +27 -0
- package/scripts/lib/async.mjs +174 -0
- package/scripts/lib/claudemd-scanner.mjs +223 -0
- package/scripts/lib/cli-agy.mjs +62 -0
- package/scripts/lib/cli-claude.mjs +78 -0
- package/scripts/lib/cli-codex.mjs +199 -0
- package/scripts/lib/cli-gemini.mjs +37 -0
- package/scripts/lib/codex-recovery.sh +50 -0
- package/scripts/lib/context.mjs +67 -0
- package/scripts/lib/cross-review-utils.mjs +59 -0
- package/scripts/lib/doctor-env-checks.mjs +121 -0
- package/scripts/lib/dynamic-route-cli.mjs +107 -0
- package/scripts/lib/env-probe.mjs +269 -0
- package/scripts/lib/env.mjs +14 -0
- package/scripts/lib/gemini-profiles.mjs +119 -0
- package/scripts/lib/handoff.mjs +187 -0
- package/scripts/lib/hook-utils.mjs +16 -0
- package/scripts/lib/hub.mjs +48 -0
- package/scripts/lib/keyword-rules.mjs +195 -0
- package/scripts/lib/logger.mjs +105 -0
- package/scripts/lib/mcp-filter.mjs +883 -0
- package/scripts/lib/mcp-gateway-health-check.mjs +159 -0
- package/scripts/lib/mcp-gateway-servers.mjs +70 -0
- package/scripts/lib/mcp-gateway-wrapper-check.mjs +35 -0
- package/scripts/lib/mcp-guard-engine.mjs +2120 -0
- package/scripts/lib/mcp-health.mjs +773 -0
- package/scripts/lib/mcp-manifest.mjs +89 -0
- package/scripts/lib/mcp-server-catalog.mjs +355 -0
- package/scripts/lib/pid.mjs +63 -0
- package/scripts/lib/process-utils.mjs +26 -0
- package/scripts/lib/psmux-info.mjs +224 -0
- package/scripts/lib/quota.mjs +47 -0
- package/scripts/lib/remote-spawn-transfer.mjs +226 -0
- package/scripts/lib/skill-state.mjs +220 -0
- package/scripts/lib/skill-template.mjs +375 -0
- package/scripts/lib/team.mjs +75 -0
- package/scripts/lib/timeout.mjs +66 -0
- package/scripts/lib/tmp.mjs +26 -0
- package/scripts/lib/toml.mjs +113 -0
package/hub/team/backend.mjs
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
// hub/team/backend.mjs — CLI 백엔드 추상화 레이어
|
|
2
|
-
// 각 CLI(codex/
|
|
2
|
+
// 각 CLI(codex/antigravity/claude)의 명령 빌드 로직을 클래스로 캡슐화한다.
|
|
3
3
|
// v7.2.2
|
|
4
|
+
import { writeFileSync } from "node:fs";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
|
|
6
7
|
import { buildExecArgs } from "@triflux/core/hub/codex-adapter.mjs";
|
|
8
|
+
import { IS_WINDOWS } from "@triflux/core/hub/platform.mjs";
|
|
9
|
+
|
|
10
|
+
export function buildGeminiCommand(prompt, resultFile, { isWindows } = {}) {
|
|
11
|
+
return buildAntigravityCommand(prompt, resultFile, { isWindows });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function buildAntigravityCommand(
|
|
15
|
+
prompt,
|
|
16
|
+
resultFile,
|
|
17
|
+
{ isWindows } = {},
|
|
18
|
+
) {
|
|
19
|
+
// Persist prompt to a sibling file so the shell never interpolates raw
|
|
20
|
+
// prompt content. Without this the Unix branch let `$()`, backticks, `\\`,
|
|
21
|
+
// and `"` reach the shell verbatim (P1: shell injection).
|
|
22
|
+
const promptFile = `${resultFile}.prompt`;
|
|
23
|
+
writeFileSync(promptFile, prompt);
|
|
24
|
+
if (isWindows) {
|
|
25
|
+
return `Get-Content -Raw '${promptFile}' | agy --print --dangerously-skip-permissions > '${resultFile}' 2>'${resultFile}.err'`;
|
|
26
|
+
}
|
|
27
|
+
return `agy --print --dangerously-skip-permissions < '${promptFile}' > '${resultFile}' 2>'${resultFile}.err'`;
|
|
28
|
+
}
|
|
7
29
|
|
|
8
30
|
const _require = createRequire(import.meta.url);
|
|
9
31
|
|
|
10
32
|
// ── 백엔드 클래스 ──────────────────────────────────────────────────────────
|
|
11
33
|
|
|
12
34
|
export class CodexBackend {
|
|
13
|
-
name() {
|
|
14
|
-
|
|
35
|
+
name() {
|
|
36
|
+
return "codex";
|
|
37
|
+
}
|
|
38
|
+
command() {
|
|
39
|
+
return "codex";
|
|
40
|
+
}
|
|
15
41
|
|
|
16
42
|
/**
|
|
17
43
|
* @param {string} prompt — 프롬프트 (프롬프트 파일 경로가 아닌 PowerShell 표현식)
|
|
@@ -23,44 +49,79 @@ export class CodexBackend {
|
|
|
23
49
|
return buildExecArgs({ prompt, resultFile, ...opts });
|
|
24
50
|
}
|
|
25
51
|
|
|
26
|
-
env() {
|
|
52
|
+
env() {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
27
55
|
}
|
|
28
56
|
|
|
29
57
|
export class GeminiBackend {
|
|
30
|
-
name() {
|
|
31
|
-
|
|
58
|
+
name() {
|
|
59
|
+
return "gemini";
|
|
60
|
+
}
|
|
61
|
+
command() {
|
|
62
|
+
return "agy";
|
|
63
|
+
}
|
|
32
64
|
|
|
33
65
|
buildArgs(prompt, resultFile, opts = {}) {
|
|
34
|
-
return
|
|
66
|
+
return buildGeminiCommand(prompt, resultFile, { isWindows: IS_WINDOWS });
|
|
35
67
|
}
|
|
36
68
|
|
|
37
|
-
env() {
|
|
69
|
+
env() {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
38
72
|
}
|
|
39
73
|
|
|
40
74
|
export class ClaudeBackend {
|
|
41
|
-
name() {
|
|
42
|
-
|
|
75
|
+
name() {
|
|
76
|
+
return "claude";
|
|
77
|
+
}
|
|
78
|
+
command() {
|
|
79
|
+
return "claude";
|
|
80
|
+
}
|
|
43
81
|
|
|
44
82
|
buildArgs(prompt, resultFile, opts = {}) {
|
|
45
83
|
return `claude --print ${prompt} --output-format text > '${resultFile}' 2>&1`;
|
|
46
84
|
}
|
|
47
85
|
|
|
48
|
-
env() {
|
|
86
|
+
env() {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class AntigravityBackend {
|
|
92
|
+
name() {
|
|
93
|
+
return "antigravity";
|
|
94
|
+
}
|
|
95
|
+
command() {
|
|
96
|
+
return "agy";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildArgs(prompt, resultFile, opts = {}) {
|
|
100
|
+
return buildAntigravityCommand(prompt, resultFile, {
|
|
101
|
+
isWindows: IS_WINDOWS,
|
|
102
|
+
...opts,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
env() {
|
|
107
|
+
return {};
|
|
108
|
+
}
|
|
49
109
|
}
|
|
50
110
|
|
|
51
111
|
// ── 레지스트리 ─────────────────────────────────────────────────────────────
|
|
52
112
|
|
|
53
|
-
/** @type {Map<string, CodexBackend|GeminiBackend|ClaudeBackend>} */
|
|
113
|
+
/** @type {Map<string, CodexBackend|GeminiBackend|ClaudeBackend|AntigravityBackend>} */
|
|
54
114
|
const backends = new Map([
|
|
55
|
-
["codex",
|
|
115
|
+
["codex", new CodexBackend()],
|
|
56
116
|
["gemini", new GeminiBackend()],
|
|
57
117
|
["claude", new ClaudeBackend()],
|
|
118
|
+
["antigravity", new AntigravityBackend()],
|
|
58
119
|
]);
|
|
59
120
|
|
|
60
121
|
/**
|
|
61
122
|
* 백엔드 이름으로 조회한다.
|
|
62
|
-
* @param {string} name — "codex" | "gemini" | "claude"
|
|
63
|
-
* @returns {CodexBackend|GeminiBackend|ClaudeBackend}
|
|
123
|
+
* @param {string} name — "codex" | "gemini" | "claude" | "antigravity"
|
|
124
|
+
* @returns {CodexBackend|GeminiBackend|ClaudeBackend|AntigravityBackend}
|
|
64
125
|
* @throws {Error} 등록되지 않은 이름
|
|
65
126
|
*/
|
|
66
127
|
export function getBackend(name) {
|
|
@@ -73,7 +134,7 @@ export function getBackend(name) {
|
|
|
73
134
|
* 에이전트명 또는 CLI명을 Backend로 해석한다.
|
|
74
135
|
* agent-map.json을 통해 에이전트명 → CLI명으로 변환 후 레지스트리에서 조회한다.
|
|
75
136
|
* @param {string} agentOrCli — "executor", "codex", "designer" 등
|
|
76
|
-
* @returns {CodexBackend|GeminiBackend|ClaudeBackend}
|
|
137
|
+
* @returns {CodexBackend|GeminiBackend|ClaudeBackend|AntigravityBackend}
|
|
77
138
|
*/
|
|
78
139
|
export function getBackendForAgent(agentOrCli) {
|
|
79
140
|
const agentMap = _require("./agent-map.json");
|
|
@@ -83,7 +144,7 @@ export function getBackendForAgent(agentOrCli) {
|
|
|
83
144
|
|
|
84
145
|
/**
|
|
85
146
|
* 등록된 모든 백엔드를 반환한다.
|
|
86
|
-
* @returns {Array<CodexBackend|GeminiBackend|ClaudeBackend>}
|
|
147
|
+
* @returns {Array<CodexBackend|GeminiBackend|ClaudeBackend|AntigravityBackend>}
|
|
87
148
|
*/
|
|
88
149
|
export function listBackends() {
|
|
89
150
|
return Array.from(backends.values());
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// hub/team/build-worker-prompt.mjs — append Completion Protocol to PRD prompt (#125)
|
|
2
|
+
//
|
|
3
|
+
// swarm-hypervisor injects a Completion Protocol appendix into every worker
|
|
4
|
+
// prompt so that workers emit a sentinel-framed JSON payload conductor.mjs can
|
|
5
|
+
// reliably capture (see sentinel-capture.mjs and extract-completion-payload.mjs).
|
|
6
|
+
//
|
|
7
|
+
// Pure module — no I/O — so the appendix and merge logic can be unit-tested
|
|
8
|
+
// without spawning conductors.
|
|
9
|
+
|
|
10
|
+
import { SENTINEL_BEGIN, SENTINEL_END } from "./sentinel-capture.mjs";
|
|
11
|
+
|
|
12
|
+
function normalizeLeaseFiles(leaseFiles) {
|
|
13
|
+
if (!Array.isArray(leaseFiles)) return [];
|
|
14
|
+
return leaseFiles
|
|
15
|
+
.map((file) => (typeof file === "string" ? file.trim() : ""))
|
|
16
|
+
.filter(Boolean);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function formatLeaseFiles(leaseFiles) {
|
|
20
|
+
const normalized = normalizeLeaseFiles(leaseFiles);
|
|
21
|
+
if (normalized.length === 0) return "- (none declared)";
|
|
22
|
+
return normalized.map((file) => `- ${file}`).join("\n");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function buildLeaseScopedAcceptanceAppendix({ leaseFiles = [] } = {}) {
|
|
26
|
+
return `
|
|
27
|
+
|
|
28
|
+
## Lease-scoped Acceptance / Lint Guard (자동 삽입됨)
|
|
29
|
+
- 이 shard 의 파일 lease:
|
|
30
|
+
${formatLeaseFiles(leaseFiles)}
|
|
31
|
+
- Acceptance, lint, and format checks are scoped to files changed by this shard; if that set is unclear, use only the lease list above.
|
|
32
|
+
- Do not run repo-wide format/lint fixers such as \`biome check --write .\`, \`biome --write .\`, \`npm run lint:fix\`, or broad \`npm run lint\` to absorb unrelated drift.
|
|
33
|
+
- For Biome, use \`npx biome check <changed-files-or-lease-files>\`; add \`--write\` only when every target is a changed/leased file you intend to commit.
|
|
34
|
+
- Pre-existing lint drift outside the lease is not this shard's acceptance responsibility; report it instead of editing it.
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const COMPLETION_PROTOCOL_APPENDIX = `
|
|
39
|
+
|
|
40
|
+
## Completion Protocol (자동 삽입됨)
|
|
41
|
+
<!-- swarm hypervisor 가 이 섹션을 worker prompt 에 자동 주입합니다.
|
|
42
|
+
PRD 작성자는 이 섹션을 수정하지 마세요.
|
|
43
|
+
상세: hub/team/build-worker-prompt.mjs / sentinel-capture.mjs (#125). -->
|
|
44
|
+
|
|
45
|
+
작업의 마지막 단계로, stdout 에 다음 형식의 완료 payload 를 정확히 한 번 출력하라:
|
|
46
|
+
|
|
47
|
+
${SENTINEL_BEGIN}
|
|
48
|
+
{"shard":"<shard name>","status":"ok","commits_made":[{"sha":"<40-char full sha>","message":"<commit msg>"}]}
|
|
49
|
+
${SENTINEL_END}
|
|
50
|
+
|
|
51
|
+
규약:
|
|
52
|
+
- 두 sentinel 마커는 각자 자기 줄에 단독으로 출력 (앞뒤 newline)
|
|
53
|
+
- 마커 사이 본문은 단일 JSON object (배열/primitive 금지)
|
|
54
|
+
- commits_made 가 비어 있어도 됨 (no-op shard)
|
|
55
|
+
- 마커 쌍은 stdout 에 정확히 한 번만 출력해야 함. 재emit 시 conductor 는 첫 BEGIN..END 한 쌍만 채택하며, 이후 stdout 은 무시한다.
|
|
56
|
+
- ${SENTINEL_BEGIN} 만 출력하고 ${SENTINEL_END} 누락 시 conductor 가 truncation 으로 명확히 reject
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Append the Completion Protocol section to a PRD prompt.
|
|
61
|
+
*
|
|
62
|
+
* @param {string|null|undefined} prdPrompt — original PRD body
|
|
63
|
+
* @param {{ leaseFiles?: string[] }} [opts] — shard file lease for scoped acceptance
|
|
64
|
+
* @returns {string} prompt with appendix
|
|
65
|
+
*/
|
|
66
|
+
export function buildWorkerPrompt(prdPrompt, opts = {}) {
|
|
67
|
+
const body = typeof prdPrompt === "string" ? prdPrompt : "";
|
|
68
|
+
return (
|
|
69
|
+
body +
|
|
70
|
+
buildLeaseScopedAcceptanceAppendix({ leaseFiles: opts.leaseFiles }) +
|
|
71
|
+
COMPLETION_PROTOCOL_APPENDIX
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// hub/team/check-mcp-hub.mjs — health-probe L2 용 hub /health ping 체커.
|
|
2
|
+
// health-probe.mjs 의 checkMcp 로 주입되어 `mcp_initializing` state 판정에 사용.
|
|
3
|
+
// hub /health 가 200 이면 OK (MCP transport 인프라 살아있음), 그 외는 fail.
|
|
4
|
+
|
|
5
|
+
const DEFAULT_HUB_URL = "http://127.0.0.1:27888";
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 3000;
|
|
7
|
+
|
|
8
|
+
function resolveHubHealthUrl(hubUrl) {
|
|
9
|
+
const base = hubUrl || process.env.TFX_HUB_URL || DEFAULT_HUB_URL;
|
|
10
|
+
// `/mcp` suffix 제거 (triflux convention — bridge.mjs:54, hub-client.mjs,
|
|
11
|
+
// lead-control.mjs, session-sync.mjs 전부 TFX_HUB_URL 을 MCP transport URL
|
|
12
|
+
// 로 쓰고 base URL 이 필요할 때 `/mcp$` 를 strip 한다). 제거하지 않으면
|
|
13
|
+
// `.../mcp/health` 가 되어 hub 가 404 로 응답 → L2 영구 fail → heartbeat
|
|
14
|
+
// 이 지속적으로 `mcp_initializing` 로 grace — #173 Codex P2 review.
|
|
15
|
+
return base.replace(/\/mcp\/?$/, "").replace(/\/+$/, "") + "/health";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hub /health 기반 L2 checker factory.
|
|
20
|
+
* @param {object} [opts]
|
|
21
|
+
* @param {string} [opts.hubUrl] — override. 미지정 시 TFX_HUB_URL env 또는 default.
|
|
22
|
+
* @param {number} [opts.timeoutMs=3000] — fetch timeout (ms).
|
|
23
|
+
* @param {typeof fetch} [opts.fetchFn] — fetch 오버라이드 (테스트용).
|
|
24
|
+
* @returns {() => Promise<boolean>} — true = hub healthy, false = degraded/down/timeout.
|
|
25
|
+
*/
|
|
26
|
+
export function createHubHealthChecker(opts = {}) {
|
|
27
|
+
const url = resolveHubHealthUrl(opts.hubUrl);
|
|
28
|
+
const timeoutMs = Number.isFinite(opts.timeoutMs)
|
|
29
|
+
? opts.timeoutMs
|
|
30
|
+
: DEFAULT_TIMEOUT_MS;
|
|
31
|
+
const fetchFn = opts.fetchFn || globalThis.fetch;
|
|
32
|
+
|
|
33
|
+
return async function checkMcpHubHealth() {
|
|
34
|
+
if (typeof fetchFn !== "function") return false;
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetchFn(url, {
|
|
39
|
+
method: "GET",
|
|
40
|
+
signal: controller.signal,
|
|
41
|
+
});
|
|
42
|
+
return res.ok === true;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
} finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|