triflux 10.0.0 → 10.0.2
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.md +171 -0
- package/README.md +32 -15
- package/bin/triflux.mjs +62 -5
- package/hooks/agent-route-guard.mjs +109 -0
- package/hooks/cross-review-tracker.mjs +122 -0
- package/hooks/error-context.mjs +148 -0
- package/hooks/hook-adaptive-collector.mjs +86 -0
- package/hooks/hook-manager.mjs +365 -0
- package/hooks/hook-orchestrator.mjs +312 -0
- package/hooks/hook-registry.json +246 -0
- package/hooks/hooks.json +89 -0
- package/hooks/keyword-rules.json +574 -0
- package/hooks/lib/resolve-root.mjs +59 -0
- package/hooks/mcp-config-watcher.mjs +80 -0
- package/hooks/pipeline-stop.mjs +76 -0
- package/hooks/safety-guard.mjs +169 -0
- package/hooks/subagent-verifier.mjs +80 -0
- package/hub/account-broker.mjs +251 -0
- package/hub/adaptive-diagnostic.mjs +323 -0
- package/hub/adaptive-inject.mjs +186 -0
- package/hub/adaptive-memory.mjs +163 -0
- package/hub/adaptive.mjs +143 -0
- package/hub/assign-callbacks.mjs +133 -0
- package/hub/bridge.mjs +799 -0
- package/hub/cli-adapter-base.mjs +280 -0
- package/hub/codex-adapter.mjs +199 -0
- package/hub/codex-compat.mjs +11 -0
- package/hub/codex-preflight.mjs +166 -0
- package/hub/delegator/contracts.mjs +37 -0
- package/hub/delegator/index.mjs +14 -0
- package/hub/delegator/schema/delegator-tools.schema.json +250 -0
- package/hub/delegator/service.mjs +307 -0
- package/hub/delegator/tool-definitions.mjs +35 -0
- package/hub/fullcycle.mjs +96 -0
- package/hub/gemini-adapter.mjs +180 -0
- package/hub/hitl.mjs +143 -0
- package/hub/intent.mjs +193 -0
- package/hub/lib/cache-guard.mjs +114 -0
- package/hub/lib/known-errors.json +72 -0
- package/hub/lib/memory-store.mjs +748 -0
- package/hub/lib/process-utils.mjs +361 -0
- package/hub/lib/ssh-command.mjs +211 -0
- package/hub/lib/ssh-retry.mjs +59 -0
- package/hub/lib/uuidv7.mjs +44 -0
- package/hub/memory-doctor.mjs +480 -0
- package/hub/middleware/request-logger.mjs +161 -0
- package/hub/paths.mjs +30 -0
- package/hub/pipe.mjs +664 -0
- package/hub/pipeline/gates/confidence.mjs +56 -0
- package/hub/pipeline/gates/consensus.mjs +94 -0
- package/hub/pipeline/gates/index.mjs +5 -0
- package/hub/pipeline/gates/selfcheck.mjs +82 -0
- package/hub/pipeline/index.mjs +318 -0
- package/hub/pipeline/state.mjs +191 -0
- package/hub/pipeline/transitions.mjs +124 -0
- package/hub/platform.mjs +225 -0
- package/hub/public/dashboard.html +355 -0
- package/hub/public/tray-icon.ico +0 -0
- package/hub/public/tray-icon.png +0 -0
- package/hub/quality/deslop.mjs +253 -0
- package/hub/reflexion.mjs +372 -0
- package/hub/research.mjs +146 -0
- package/hub/router.mjs +791 -0
- package/hub/routing/complexity.mjs +166 -0
- package/hub/routing/index.mjs +117 -0
- package/hub/routing/q-learning.mjs +336 -0
- package/hub/schema.sql +148 -0
- package/hub/server.mjs +1264 -0
- package/hub/session-fingerprint.mjs +352 -0
- package/hub/state.mjs +258 -0
- package/hub/store-adapter.mjs +118 -0
- package/hub/store.mjs +857 -0
- package/hub/team/agent-map.json +11 -0
- package/hub/team/ansi.mjs +379 -0
- package/hub/team/backend.mjs +90 -0
- package/hub/team/cli/commands/attach.mjs +37 -0
- package/hub/team/cli/commands/control.mjs +43 -0
- package/hub/team/cli/commands/debug.mjs +74 -0
- package/hub/team/cli/commands/focus.mjs +53 -0
- package/hub/team/cli/commands/interrupt.mjs +36 -0
- package/hub/team/cli/commands/kill.mjs +37 -0
- package/hub/team/cli/commands/list.mjs +24 -0
- package/hub/team/cli/commands/send.mjs +37 -0
- package/hub/team/cli/commands/start/index.mjs +106 -0
- package/hub/team/cli/commands/start/parse-args.mjs +130 -0
- package/hub/team/cli/commands/start/start-headless.mjs +109 -0
- package/hub/team/cli/commands/start/start-in-process.mjs +40 -0
- package/hub/team/cli/commands/start/start-mux.mjs +73 -0
- package/hub/team/cli/commands/start/start-wt.mjs +69 -0
- package/hub/team/cli/commands/status.mjs +87 -0
- package/hub/team/cli/commands/stop.mjs +31 -0
- package/hub/team/cli/commands/task.mjs +30 -0
- package/hub/team/cli/commands/tasks.mjs +13 -0
- package/hub/team/cli/help.mjs +42 -0
- package/hub/team/cli/index.mjs +41 -0
- package/hub/team/cli/manifest.mjs +29 -0
- package/hub/team/cli/render.mjs +30 -0
- package/hub/team/cli/services/attach-fallback.mjs +54 -0
- package/hub/team/cli/services/hub-client.mjs +227 -0
- package/hub/team/cli/services/member-selector.mjs +30 -0
- package/hub/team/cli/services/native-control.mjs +117 -0
- package/hub/team/cli/services/runtime-mode.mjs +62 -0
- package/hub/team/cli/services/state-store.mjs +48 -0
- package/hub/team/cli/services/task-model.mjs +30 -0
- package/hub/team/conductor-mesh-bridge.mjs +121 -0
- package/hub/team/conductor.mjs +671 -0
- package/hub/team/dashboard-anchor.mjs +14 -0
- package/hub/team/dashboard-layout.mjs +33 -0
- package/hub/team/dashboard-open.mjs +153 -0
- package/hub/team/dashboard.mjs +274 -0
- package/hub/team/event-log.mjs +76 -0
- package/hub/team/handoff.mjs +303 -0
- package/hub/team/headless.mjs +1156 -0
- package/hub/team/health-probe.mjs +272 -0
- package/hub/team/launcher-template.mjs +95 -0
- package/hub/team/lead-control.mjs +104 -0
- package/hub/team/native-supervisor.mjs +392 -0
- package/hub/team/native.mjs +649 -0
- package/hub/team/nativeProxy.mjs +688 -0
- package/hub/team/notify.mjs +293 -0
- package/hub/team/orchestrator.mjs +161 -0
- package/hub/team/pane.mjs +153 -0
- package/hub/team/process-cleanup.mjs +342 -0
- package/hub/team/psmux.mjs +1354 -0
- package/hub/team/remote-probe.mjs +276 -0
- package/hub/team/remote-session.mjs +299 -0
- package/hub/team/remote-watcher.mjs +478 -0
- package/hub/team/routing.mjs +223 -0
- package/hub/team/session-sync.mjs +169 -0
- package/hub/team/session.mjs +611 -0
- package/hub/team/shared.mjs +13 -0
- package/hub/team/staleState.mjs +361 -0
- package/hub/team/swarm-hypervisor.mjs +589 -0
- package/hub/team/swarm-locks.mjs +204 -0
- package/hub/team/swarm-planner.mjs +260 -0
- package/hub/team/swarm-reconciler.mjs +137 -0
- package/hub/team/tui-lite.mjs +380 -0
- package/hub/team/tui-remote-adapter.mjs +393 -0
- package/hub/team/tui-viewer.mjs +463 -0
- package/hub/team/tui.mjs +1449 -0
- package/hub/team/worktree-lifecycle.mjs +193 -0
- package/hub/team/wt-manager.mjs +407 -0
- package/hub/team/wt-templates.json +43 -0
- package/hub/team-bridge.mjs +27 -0
- package/hub/token-mode.mjs +224 -0
- package/hub/tools.mjs +636 -0
- package/hub/tray.mjs +376 -0
- package/hub/workers/claude-worker.mjs +475 -0
- package/hub/workers/codex-mcp.mjs +507 -0
- package/hub/workers/delegator-mcp.mjs +1076 -0
- package/hub/workers/factory.mjs +21 -0
- package/hub/workers/gemini-worker.mjs +374 -0
- package/hub/workers/interface.mjs +52 -0
- package/hub/workers/worker-utils.mjs +104 -0
- package/hud/colors.mjs +88 -0
- package/hud/constants.mjs +88 -0
- package/hud/context-monitor.mjs +403 -0
- package/hud/hud-qos-status.mjs +210 -0
- package/hud/providers/claude.mjs +314 -0
- package/hud/providers/codex.mjs +151 -0
- package/hud/providers/gemini.mjs +320 -0
- package/hud/renderers.mjs +442 -0
- package/hud/terminal.mjs +140 -0
- package/hud/utils.mjs +313 -0
- package/mesh/index.mjs +63 -0
- package/mesh/mesh-budget.mjs +128 -0
- package/mesh/mesh-heartbeat.mjs +100 -0
- package/mesh/mesh-protocol.mjs +96 -0
- package/mesh/mesh-queue.mjs +165 -0
- package/mesh/mesh-registry.mjs +78 -0
- package/mesh/mesh-router.mjs +76 -0
- package/package.json +8 -1
- package/references/hosts.json +33 -0
- package/scripts/__tests__/gen-skill-docs.test.mjs +87 -0
- package/scripts/__tests__/keyword-detector.test.mjs +234 -0
- package/scripts/__tests__/mcp-guard-engine.test.mjs +118 -0
- package/scripts/__tests__/remote-spawn-transfer.test.mjs +117 -0
- package/scripts/__tests__/remote-spawn.test.mjs +92 -0
- package/scripts/__tests__/skill-template.test.mjs +193 -0
- package/scripts/__tests__/smoke.test.mjs +34 -0
- package/scripts/cache-buildup.mjs +30 -0
- package/scripts/cache-doctor.mjs +149 -0
- package/scripts/cache-warmup.mjs +557 -0
- package/scripts/claudemd-sync.mjs +148 -0
- package/scripts/cli-route.sh +3 -0
- package/scripts/completions/tfx.bash +47 -0
- package/scripts/completions/tfx.fish +44 -0
- package/scripts/completions/tfx.zsh +83 -0
- package/scripts/cross-review-gate.mjs +126 -0
- package/scripts/cross-review-tracker.mjs +238 -0
- package/scripts/gen-skill-docs.mjs +111 -0
- package/scripts/headless-guard-fast.sh +21 -0
- package/scripts/headless-guard.mjs +360 -0
- package/scripts/hub-ensure.mjs +120 -0
- package/scripts/keyword-detector.mjs +272 -0
- package/scripts/keyword-rules-expander.mjs +521 -0
- package/scripts/lib/claudemd-scanner.mjs +218 -0
- package/scripts/lib/context.mjs +67 -0
- package/scripts/lib/cross-review-utils.mjs +51 -0
- package/scripts/lib/env-probe.mjs +241 -0
- package/scripts/lib/gemini-profiles.mjs +85 -0
- package/scripts/lib/handoff.mjs +171 -0
- package/scripts/lib/hook-utils.mjs +14 -0
- package/scripts/lib/keyword-rules.mjs +166 -0
- package/scripts/lib/logger.mjs +105 -0
- package/scripts/lib/mcp-filter.mjs +739 -0
- package/scripts/lib/mcp-guard-engine.mjs +954 -0
- package/scripts/lib/mcp-manifest.mjs +79 -0
- package/scripts/lib/mcp-server-catalog.mjs +118 -0
- package/scripts/lib/psmux-info.mjs +119 -0
- package/scripts/lib/remote-spawn-transfer.mjs +196 -0
- package/scripts/lib/skill-template.mjs +326 -0
- package/scripts/mcp-check.mjs +237 -0
- package/scripts/mcp-cleanup.ps1 +17 -0
- package/scripts/mcp-gateway-config.mjs +207 -0
- package/scripts/mcp-gateway-ensure.mjs +85 -0
- package/scripts/mcp-gateway-integration-test.mjs +228 -0
- package/scripts/mcp-gateway-start.mjs +226 -0
- package/scripts/mcp-gateway-start.ps1 +141 -0
- package/scripts/mcp-gateway-verify.mjs +77 -0
- package/scripts/mcp-safety-guard.mjs +44 -0
- package/scripts/notion-read.mjs +556 -0
- package/scripts/pack.mjs +295 -0
- package/scripts/preflight-cache.mjs +69 -0
- package/scripts/preinstall.mjs +96 -0
- package/scripts/remote-spawn.mjs +1376 -0
- package/scripts/run.cjs +79 -0
- package/scripts/session-spawn-helper.mjs +185 -0
- package/scripts/setup.mjs +1178 -0
- package/scripts/test-lock.mjs +71 -0
- package/scripts/test-tfx-route-no-claude-native.mjs +57 -0
- package/scripts/tfx-batch-stats.mjs +96 -0
- package/scripts/tfx-gate-activate.mjs +89 -0
- package/scripts/tfx-route-post.mjs +505 -0
- package/scripts/tfx-route-worker.mjs +223 -0
- package/scripts/tfx-route.sh +2014 -0
- package/scripts/tmp-cleanup.mjs +103 -0
- package/scripts/token-snapshot.mjs +575 -0
- package/skills/tfx-auto/SKILL.md.tmpl +2 -3
- package/skills/tfx-autoresearch/SKILL.md +6 -5
- package/skills/tfx-codex/SKILL.md.tmpl +2 -3
- package/skills/tfx-codex-swarm-workspace/iteration-1/benchmark.json +33 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/eval_metadata.json +42 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/grading.json +11 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/analysis.md +87 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/classification.md +35 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/commands.sh +275 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/routing.md +56 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/timing.json +5 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/grading.json +11 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/analysis.md +92 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/classification.md +71 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/commands.sh +264 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/routing.md +113 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/timing.json +5 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/eval_metadata.json +32 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/grading.json +9 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/analysis.md +96 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/classification.md +38 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/commands.sh +151 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/routing.md +51 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/timing.json +5 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/grading.json +9 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/analysis.md +127 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/classification.md +57 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/commands.sh +129 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/routing.md +84 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/timing.json +5 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/eval_metadata.json +27 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/grading.json +8 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/analysis.md +98 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/classification.md +65 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/commands.sh +123 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/routing.md +66 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/timing.json +5 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/grading.json +8 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/analysis.md +88 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/classification.md +40 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/commands.sh +130 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/routing.md +61 -0
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/timing.json +5 -0
- package/skills/tfx-deep-interview/SKILL.md +1 -2
- package/skills/tfx-plan/SKILL.md.tmpl +2 -3
- package/skills/tfx-psmux-rules/SKILL.md +11 -2
- package/skills/tfx-qa/SKILL.md.tmpl +2 -3
- package/skills/tfx-remote-spawn/SKILL.md +8 -11
- package/skills/tfx-research/SKILL.md.tmpl +2 -3
- package/skills/tfx-review/SKILL.md.tmpl +2 -3
- package/skills/tfx-workspace/async-tests/run-tests.sh +203 -0
- package/skills/tfx-workspace/evals/evals.json +79 -0
- package/skills/tfx-workspace/iteration-1/benchmark.json +162 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/eval_metadata.json +11 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/grading.json +9 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/outputs/analysis.md +154 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/grading.json +9 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/outputs/analysis.md +126 -0
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/eval_metadata.json +11 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/grading.json +9 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/outputs/analysis.md +119 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/grading.json +9 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/outputs/analysis.md +115 -0
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/eval_metadata.json +10 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/grading.json +8 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/outputs/analysis.md +86 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/grading.json +8 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/outputs/analysis.md +81 -0
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/eval_metadata.json +12 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/grading.json +10 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/outputs/analysis.md +316 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/grading.json +10 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/outputs/analysis.md +352 -0
- package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/review.html +1325 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/eval_metadata.json +12 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/grading.json +10 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/outputs/analysis.md +97 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/grading.json +10 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/outputs/analysis.md +94 -0
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/eval_metadata.json +12 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/grading.json +10 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/outputs/analysis.md +209 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/grading.json +10 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/outputs/analysis.md +193 -0
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-2/benchmark.json +62 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/eval_metadata.json +13 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/grading.json +11 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/outputs/analysis.md +382 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/grading.json +11 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/outputs/analysis.md +333 -0
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/timing.json +5 -0
- package/skills/tfx-workspace/iteration-2/review.html +1325 -0
- package/skills/tfx-workspace/skill-snapshot/tfx-auto/SKILL.md +217 -0
- package/skills/{tfx-auto-codex/SKILL.md.tmpl → tfx-workspace/skill-snapshot/tfx-auto-codex/SKILL.md} +3 -31
- package/skills/tfx-workspace/skill-snapshot/tfx-codex/SKILL.md +65 -0
- package/skills/tfx-workspace/skill-snapshot/tfx-doctor/SKILL.md +94 -0
- package/skills/{tfx-gemini/SKILL.md.tmpl → tfx-workspace/skill-snapshot/tfx-gemini/SKILL.md} +6 -14
- package/skills/tfx-workspace/skill-snapshot/tfx-hub/SKILL.md +133 -0
- package/skills/tfx-workspace/skill-snapshot/tfx-multi/SKILL.md +426 -0
- package/skills/tfx-workspace/skill-snapshot/tfx-setup/SKILL.md +101 -0
- package/skills/merge-worktree/SKILL.md.tmpl +0 -144
- package/skills/shared/arguments-processing.md +0 -2
- package/skills/shared/mandatory-rules.md +0 -6
- package/skills/shared/telemetry-segment.md +0 -6
- package/skills/star-prompt/SKILL.md.tmpl +0 -122
- package/skills/tfx-analysis/SKILL.md.tmpl +0 -106
- package/skills/tfx-analysis/skill.json +0 -11
- package/skills/tfx-auto/skill.json +0 -26
- package/skills/tfx-auto-codex/skill.json +0 -8
- package/skills/tfx-autopilot/SKILL.md.tmpl +0 -115
- package/skills/tfx-autopilot/skill.json +0 -10
- package/skills/tfx-autoresearch/SKILL.md.tmpl +0 -135
- package/skills/tfx-autoresearch/skill.json +0 -14
- package/skills/tfx-autoroute/SKILL.md.tmpl +0 -188
- package/skills/tfx-autoroute/skill.json +0 -12
- package/skills/tfx-codex/skill.json +0 -8
- package/skills/tfx-codex-swarm/SKILL.md.tmpl +0 -16
- package/skills/tfx-codex-swarm/skill.json +0 -5
- package/skills/tfx-consensus/SKILL.md.tmpl +0 -145
- package/skills/tfx-consensus/skill.json +0 -8
- package/skills/tfx-debate/SKILL.md.tmpl +0 -191
- package/skills/tfx-debate/skill.json +0 -12
- package/skills/tfx-deep-analysis/SKILL.md.tmpl +0 -227
- package/skills/tfx-deep-analysis/skill.json +0 -10
- package/skills/tfx-deep-interview/SKILL.md.tmpl +0 -203
- package/skills/tfx-deep-interview/skill.json +0 -12
- package/skills/tfx-deep-plan/SKILL.md.tmpl +0 -281
- package/skills/tfx-deep-plan/skill.json +0 -13
- package/skills/tfx-deep-qa/SKILL.md.tmpl +0 -164
- package/skills/tfx-deep-qa/skill.json +0 -11
- package/skills/tfx-deep-research/SKILL.md.tmpl +0 -216
- package/skills/tfx-deep-research/skill.json +0 -14
- package/skills/tfx-deep-review/SKILL.md.tmpl +0 -178
- package/skills/tfx-deep-review/skill.json +0 -12
- package/skills/tfx-doctor/SKILL.md.tmpl +0 -172
- package/skills/tfx-doctor/skill.json +0 -8
- package/skills/tfx-find/skill.json +0 -12
- package/skills/tfx-forge/SKILL.md.tmpl +0 -187
- package/skills/tfx-forge/skill.json +0 -12
- package/skills/tfx-fullcycle/SKILL.md.tmpl +0 -285
- package/skills/tfx-fullcycle/skill.json +0 -11
- package/skills/tfx-gemini/skill.json +0 -8
- package/skills/tfx-hooks/SKILL.md.tmpl +0 -216
- package/skills/tfx-hooks/skill.json +0 -8
- package/skills/tfx-hub/SKILL.md.tmpl +0 -212
- package/skills/tfx-hub/skill.json +0 -8
- package/skills/tfx-index/skill.json +0 -11
- package/skills/tfx-interview/SKILL.md.tmpl +0 -284
- package/skills/tfx-interview/skill.json +0 -12
- package/skills/tfx-multi/SKILL.md.tmpl +0 -183
- package/skills/tfx-multi/skill.json +0 -8
- package/skills/tfx-panel/SKILL.md.tmpl +0 -188
- package/skills/tfx-panel/skill.json +0 -12
- package/skills/tfx-persist/SKILL.md.tmpl +0 -269
- package/skills/tfx-persist/skill.json +0 -12
- package/skills/tfx-plan/skill.json +0 -11
- package/skills/tfx-profile/SKILL.md.tmpl +0 -239
- package/skills/tfx-profile/skill.json +0 -8
- package/skills/tfx-prune/SKILL.md.tmpl +0 -199
- package/skills/tfx-prune/skill.json +0 -12
- package/skills/tfx-psmux-rules/SKILL.md.tmpl +0 -317
- package/skills/tfx-psmux-rules/skill.json +0 -8
- package/skills/tfx-qa/skill.json +0 -11
- package/skills/tfx-ralph/SKILL.md.tmpl +0 -27
- package/skills/tfx-ralph/skill.json +0 -8
- package/skills/tfx-remote-setup/SKILL.md.tmpl +0 -576
- package/skills/tfx-remote-setup/skill.json +0 -8
- package/skills/tfx-remote-spawn/SKILL.md.tmpl +0 -263
- package/skills/tfx-remote-spawn/skill.json +0 -9
- package/skills/tfx-research/skill.json +0 -13
- package/skills/tfx-review/skill.json +0 -11
- package/skills/tfx-setup/SKILL.md.tmpl +0 -380
- package/skills/tfx-setup/skill.json +0 -8
- package/skills/tfx-swarm/SKILL.md.tmpl +0 -154
- package/skills/tfx-swarm/skill.json +0 -5
|
@@ -0,0 +1,954 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const PROJECT_ROOT = fileURLToPath(new URL("../../", import.meta.url));
|
|
7
|
+
const REGISTRY_PATH = join(PROJECT_ROOT, "config", "mcp-registry.json");
|
|
8
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
9
|
+
const DEFAULT_HUB_PATH = "/mcp";
|
|
10
|
+
const DEFAULT_REGISTRY = Object.freeze({
|
|
11
|
+
$schema: "mcp-registry-schema",
|
|
12
|
+
version: 1,
|
|
13
|
+
description: "MCP 서버 중앙 레지스트리 — 진실의 원천",
|
|
14
|
+
defaults: {
|
|
15
|
+
transport: "hub-url",
|
|
16
|
+
hub_base: "http://127.0.0.1:27888",
|
|
17
|
+
},
|
|
18
|
+
servers: {
|
|
19
|
+
"tfx-hub": {
|
|
20
|
+
transport: "hub-url",
|
|
21
|
+
url: "http://127.0.0.1:27888/mcp",
|
|
22
|
+
safe: true,
|
|
23
|
+
targets: ["claude", "gemini", "codex"],
|
|
24
|
+
description: "triflux Hub MCP 서버",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
policies: {
|
|
28
|
+
stdio_action: "replace-with-hub",
|
|
29
|
+
unknown_server_action: "warn",
|
|
30
|
+
watched_paths: [
|
|
31
|
+
"~/.gemini/settings.json",
|
|
32
|
+
"~/.codex/config.toml",
|
|
33
|
+
"~/.claude/settings.json",
|
|
34
|
+
"~/.claude/settings.local.json",
|
|
35
|
+
".mcp.json",
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function cloneDefaultRegistry() {
|
|
41
|
+
return JSON.parse(JSON.stringify(DEFAULT_REGISTRY));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function expandHome(filePath) {
|
|
45
|
+
if (typeof filePath !== "string") return "";
|
|
46
|
+
if (!filePath.startsWith("~/") && !filePath.startsWith("~\\")) return filePath;
|
|
47
|
+
return join(homedir(), filePath.slice(2));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function resolveFilePath(filePath) {
|
|
51
|
+
const expanded = expandHome(filePath);
|
|
52
|
+
return isAbsolute(expanded) ? resolve(expanded) : resolve(process.cwd(), expanded);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeForMatch(filePath) {
|
|
56
|
+
return resolveFilePath(filePath).replace(/\\/g, "/").toLowerCase();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function pathBasename(filePath) {
|
|
60
|
+
return basename(filePath.replace(/\\/g, "/")).toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readJsonFile(filePath) {
|
|
64
|
+
return JSON.parse(readFileSync(filePath, "utf8"));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function writeJsonFile(filePath, data) {
|
|
68
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
69
|
+
writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n", "utf8");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function ensureBackup(filePath) {
|
|
73
|
+
const backupPath = `${filePath}.bak`;
|
|
74
|
+
copyFileSync(filePath, backupPath);
|
|
75
|
+
return backupPath;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isJsonMcpConfig(filePath) {
|
|
79
|
+
const name = pathBasename(filePath);
|
|
80
|
+
return name === "settings.json" || name === "settings.local.json" || name === ".mcp.json";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function isCodexConfig(filePath) {
|
|
84
|
+
const normalized = normalizeForMatch(filePath);
|
|
85
|
+
return normalized.endsWith("/.codex/config.toml");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function detectClient(filePath) {
|
|
89
|
+
const normalized = normalizeForMatch(filePath);
|
|
90
|
+
if (normalized.endsWith("/.gemini/settings.json")) return "gemini";
|
|
91
|
+
if (normalized.endsWith("/.codex/config.toml")) return "codex";
|
|
92
|
+
if (
|
|
93
|
+
normalized.endsWith("/.claude/settings.json")
|
|
94
|
+
|| normalized.endsWith("/.claude/settings.local.json")
|
|
95
|
+
|| normalized.endsWith("/.mcp.json")
|
|
96
|
+
) {
|
|
97
|
+
return "claude";
|
|
98
|
+
}
|
|
99
|
+
return "unknown";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function detectLabel(filePath) {
|
|
103
|
+
const normalized = normalizeForMatch(filePath);
|
|
104
|
+
if (normalized.endsWith("/.gemini/settings.json")) return "Gemini";
|
|
105
|
+
if (normalized.endsWith("/.codex/config.toml")) return "Codex";
|
|
106
|
+
if (normalized.endsWith("/.claude/settings.json")) return "Claude User";
|
|
107
|
+
if (normalized.endsWith("/.claude/settings.local.json")) return "Claude Local";
|
|
108
|
+
if (normalized.endsWith("/.mcp.json")) return "Project MCP";
|
|
109
|
+
return basename(filePath);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isPrimaryConfigTarget(filePath) {
|
|
113
|
+
const normalized = normalizeForMatch(filePath);
|
|
114
|
+
return normalized.endsWith("/.gemini/settings.json")
|
|
115
|
+
|| normalized.endsWith("/.codex/config.toml")
|
|
116
|
+
|| normalized.endsWith("/.mcp.json");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function normalizeUrl(value) {
|
|
120
|
+
if (typeof value !== "string" || !value.trim()) return "";
|
|
121
|
+
try {
|
|
122
|
+
const url = new URL(value.trim());
|
|
123
|
+
if (url.pathname !== "/" && url.pathname.endsWith("/")) {
|
|
124
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
125
|
+
}
|
|
126
|
+
return url.toString();
|
|
127
|
+
} catch {
|
|
128
|
+
return value.trim();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function formatTomlString(value) {
|
|
133
|
+
return `"${String(value).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function parseTomlScalar(rawValue) {
|
|
137
|
+
const value = String(rawValue || "").trim();
|
|
138
|
+
if (!value) return "";
|
|
139
|
+
if (value === "true") return true;
|
|
140
|
+
if (value === "false") return false;
|
|
141
|
+
if (/^-?\d[\d_]*$/.test(value)) return Number(value.replace(/_/g, ""));
|
|
142
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
143
|
+
return value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
144
|
+
}
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function parseCodexMcpServers(raw) {
|
|
149
|
+
const lines = String(raw || "").split(/\r?\n/);
|
|
150
|
+
const servers = {};
|
|
151
|
+
let currentName = null;
|
|
152
|
+
|
|
153
|
+
for (const line of lines) {
|
|
154
|
+
const sectionMatch = line.match(/^\s*\[mcp_servers\.([^\]]+)\]\s*$/);
|
|
155
|
+
if (sectionMatch) {
|
|
156
|
+
currentName = sectionMatch[1];
|
|
157
|
+
servers[currentName] = {};
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (/^\s*\[/.test(line)) {
|
|
162
|
+
currentName = null;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!currentName) continue;
|
|
167
|
+
|
|
168
|
+
const kvMatch = line.match(/^\s*([A-Za-z0-9_]+)\s*=\s*(.+?)\s*$/);
|
|
169
|
+
if (!kvMatch) continue;
|
|
170
|
+
servers[currentName][kvMatch[1]] = parseTomlScalar(kvMatch[2]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return servers;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function removeTomlSection(raw, sectionName) {
|
|
177
|
+
const lines = String(raw || "").split(/\r?\n/);
|
|
178
|
+
const output = [];
|
|
179
|
+
const header = `[mcp_servers.${sectionName}]`;
|
|
180
|
+
let skipping = false;
|
|
181
|
+
|
|
182
|
+
for (const line of lines) {
|
|
183
|
+
if (line.trim() === header) {
|
|
184
|
+
skipping = true;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (skipping && /^\s*\[/.test(line)) {
|
|
189
|
+
skipping = false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!skipping) output.push(line);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const cleaned = output.join("\n").replace(/\n{3,}$/g, "\n\n").replace(/^\n+/, "");
|
|
196
|
+
return cleaned.length > 0 ? cleaned.replace(/\n{3,}/g, "\n\n") : "";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function upsertTomlUrlServer(raw, name, url) {
|
|
200
|
+
const section = [
|
|
201
|
+
`[mcp_servers.${name}]`,
|
|
202
|
+
`url = ${formatTomlString(url)}`,
|
|
203
|
+
];
|
|
204
|
+
const withoutExisting = removeTomlSection(raw, name).trimEnd();
|
|
205
|
+
return withoutExisting.length > 0
|
|
206
|
+
? `${withoutExisting}\n\n${section.join("\n")}\n`
|
|
207
|
+
: `${section.join("\n")}\n`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function getHubServerEntry(registry) {
|
|
211
|
+
const entries = Object.entries(registry?.servers || {});
|
|
212
|
+
if (entries.length === 0) {
|
|
213
|
+
return ["tfx-hub", { url: `${registry?.defaults?.hub_base || "http://127.0.0.1:27888"}${DEFAULT_HUB_PATH}` }];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return entries.find(([name]) => name === "tfx-hub")
|
|
217
|
+
|| entries.find(([, config]) => config?.transport === "hub-url")
|
|
218
|
+
|| entries[0];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function makeHubRuntimeConfig() {
|
|
222
|
+
return { url: resolveHubUrl() };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function serverTargets(serverConfig) {
|
|
226
|
+
if (Array.isArray(serverConfig?.targets) && serverConfig.targets.length > 0) {
|
|
227
|
+
return [...new Set(serverConfig.targets.map((value) => String(value).trim()).filter(Boolean))];
|
|
228
|
+
}
|
|
229
|
+
return ["claude", "gemini", "codex"];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function serverAppliesToClient(serverConfig, client) {
|
|
233
|
+
return serverTargets(serverConfig).includes(client);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function buildDesiredServerRecord(name, serverConfig, filePath) {
|
|
237
|
+
const url = serverConfig?.transport === "hub-url"
|
|
238
|
+
? resolveHubUrl()
|
|
239
|
+
: normalizeUrl(serverConfig?.url || "");
|
|
240
|
+
const basenameValue = pathBasename(filePath);
|
|
241
|
+
|
|
242
|
+
if (basenameValue === ".mcp.json") {
|
|
243
|
+
return { name, config: { type: "url", url } };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (isCodexConfig(filePath)) {
|
|
247
|
+
return { name, config: { url } };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return { name, config: { url } };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function scanJsonConfig(filePath) {
|
|
254
|
+
if (!existsSync(filePath)) {
|
|
255
|
+
return {
|
|
256
|
+
filePath,
|
|
257
|
+
client: detectClient(filePath),
|
|
258
|
+
label: detectLabel(filePath),
|
|
259
|
+
exists: false,
|
|
260
|
+
parseError: null,
|
|
261
|
+
servers: [],
|
|
262
|
+
stdioServers: [],
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
const parsed = readJsonFile(filePath);
|
|
268
|
+
const mcpServers = parsed?.mcpServers;
|
|
269
|
+
const servers = !mcpServers || typeof mcpServers !== "object"
|
|
270
|
+
? []
|
|
271
|
+
: Object.entries(mcpServers)
|
|
272
|
+
.filter(([name, config]) => typeof name === "string" && config && typeof config === "object")
|
|
273
|
+
.map(([name, config]) => ({
|
|
274
|
+
name: name.trim(),
|
|
275
|
+
url: typeof config.url === "string" ? normalizeUrl(config.url) : "",
|
|
276
|
+
command: typeof config.command === "string" ? config.command : "",
|
|
277
|
+
type: typeof config.type === "string" ? config.type : "",
|
|
278
|
+
transport: typeof config.url === "string" && config.url
|
|
279
|
+
? "url"
|
|
280
|
+
: typeof config.command === "string" && config.command
|
|
281
|
+
? "stdio"
|
|
282
|
+
: "unknown",
|
|
283
|
+
raw: config,
|
|
284
|
+
}));
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
filePath,
|
|
288
|
+
client: detectClient(filePath),
|
|
289
|
+
label: detectLabel(filePath),
|
|
290
|
+
exists: true,
|
|
291
|
+
parseError: null,
|
|
292
|
+
servers,
|
|
293
|
+
stdioServers: servers.filter((server) => server.transport === "stdio"),
|
|
294
|
+
};
|
|
295
|
+
} catch (error) {
|
|
296
|
+
return {
|
|
297
|
+
filePath,
|
|
298
|
+
client: detectClient(filePath),
|
|
299
|
+
label: detectLabel(filePath),
|
|
300
|
+
exists: true,
|
|
301
|
+
parseError: error,
|
|
302
|
+
servers: [],
|
|
303
|
+
stdioServers: [],
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function scanCodexConfig(filePath) {
|
|
309
|
+
if (!existsSync(filePath)) {
|
|
310
|
+
return {
|
|
311
|
+
filePath,
|
|
312
|
+
client: detectClient(filePath),
|
|
313
|
+
label: detectLabel(filePath),
|
|
314
|
+
exists: false,
|
|
315
|
+
parseError: null,
|
|
316
|
+
servers: [],
|
|
317
|
+
stdioServers: [],
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
const raw = readFileSync(filePath, "utf8");
|
|
323
|
+
const parsed = parseCodexMcpServers(raw);
|
|
324
|
+
const servers = Object.entries(parsed).map(([name, config]) => ({
|
|
325
|
+
name,
|
|
326
|
+
url: typeof config.url === "string" ? normalizeUrl(config.url) : "",
|
|
327
|
+
command: typeof config.command === "string" ? config.command : "",
|
|
328
|
+
transport: typeof config.url === "string" && config.url
|
|
329
|
+
? "url"
|
|
330
|
+
: typeof config.command === "string" && config.command
|
|
331
|
+
? "stdio"
|
|
332
|
+
: "unknown",
|
|
333
|
+
raw: config,
|
|
334
|
+
}));
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
filePath,
|
|
338
|
+
client: detectClient(filePath),
|
|
339
|
+
label: detectLabel(filePath),
|
|
340
|
+
exists: true,
|
|
341
|
+
parseError: null,
|
|
342
|
+
servers,
|
|
343
|
+
// Wave 1/2-B: Codex stdio servers are observed but not auto-remediated.
|
|
344
|
+
stdioServers: [],
|
|
345
|
+
};
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return {
|
|
348
|
+
filePath,
|
|
349
|
+
client: detectClient(filePath),
|
|
350
|
+
label: detectLabel(filePath),
|
|
351
|
+
exists: true,
|
|
352
|
+
parseError: error,
|
|
353
|
+
servers: [],
|
|
354
|
+
stdioServers: [],
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function updateJsonConfig(filePath, updates = [], removals = []) {
|
|
360
|
+
const resolvedPath = resolveFilePath(filePath);
|
|
361
|
+
let parsed = {};
|
|
362
|
+
|
|
363
|
+
if (existsSync(resolvedPath)) {
|
|
364
|
+
parsed = readJsonFile(resolvedPath);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
368
|
+
parsed = {};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (!parsed.mcpServers || typeof parsed.mcpServers !== "object" || Array.isArray(parsed.mcpServers)) {
|
|
372
|
+
parsed.mcpServers = {};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
let modified = false;
|
|
376
|
+
|
|
377
|
+
for (const name of removals) {
|
|
378
|
+
if (Object.hasOwn(parsed.mcpServers, name)) {
|
|
379
|
+
delete parsed.mcpServers[name];
|
|
380
|
+
modified = true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
for (const update of updates) {
|
|
385
|
+
const current = parsed.mcpServers[update.name];
|
|
386
|
+
const nextConfig = { ...(current && typeof current === "object" ? current : {}), ...update.config };
|
|
387
|
+
const changed = JSON.stringify(current || null) !== JSON.stringify(nextConfig);
|
|
388
|
+
if (changed) {
|
|
389
|
+
parsed.mcpServers[update.name] = nextConfig;
|
|
390
|
+
modified = true;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (!modified) {
|
|
395
|
+
return { modified: false, filePath: resolvedPath };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
writeJsonFile(resolvedPath, parsed);
|
|
399
|
+
return { modified: true, filePath: resolvedPath };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function updateCodexConfig(filePath, updates = [], removals = []) {
|
|
403
|
+
const resolvedPath = resolveFilePath(filePath);
|
|
404
|
+
let raw = existsSync(resolvedPath) ? readFileSync(resolvedPath, "utf8") : "";
|
|
405
|
+
|
|
406
|
+
for (const name of removals) {
|
|
407
|
+
raw = removeTomlSection(raw, name);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
for (const update of updates) {
|
|
411
|
+
raw = upsertTomlUrlServer(raw, update.name, update.config.url);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const finalRaw = raw.trim().length > 0 ? `${raw.trimEnd()}\n` : "";
|
|
415
|
+
const previousRaw = existsSync(resolvedPath) ? readFileSync(resolvedPath, "utf8") : "";
|
|
416
|
+
if (finalRaw === previousRaw) {
|
|
417
|
+
return { modified: false, filePath: resolvedPath };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
mkdirSync(dirname(resolvedPath), { recursive: true });
|
|
421
|
+
writeFileSync(resolvedPath, finalRaw, "utf8");
|
|
422
|
+
return { modified: true, filePath: resolvedPath };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function scanConfig(filePath) {
|
|
426
|
+
const resolvedPath = resolveFilePath(filePath);
|
|
427
|
+
if (isCodexConfig(resolvedPath)) return scanCodexConfig(resolvedPath);
|
|
428
|
+
if (isJsonMcpConfig(resolvedPath)) return scanJsonConfig(resolvedPath);
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
filePath: resolvedPath,
|
|
432
|
+
client: detectClient(resolvedPath),
|
|
433
|
+
label: detectLabel(resolvedPath),
|
|
434
|
+
exists: existsSync(resolvedPath),
|
|
435
|
+
parseError: null,
|
|
436
|
+
servers: [],
|
|
437
|
+
stdioServers: [],
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function getRegistryPath() {
|
|
442
|
+
return REGISTRY_PATH;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export function createDefaultRegistry() {
|
|
446
|
+
return cloneDefaultRegistry();
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export function validateRegistry(registry) {
|
|
450
|
+
const errors = [];
|
|
451
|
+
if (!registry || typeof registry !== "object" || Array.isArray(registry)) {
|
|
452
|
+
return ["registry must be an object"];
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (registry.version !== 1) {
|
|
456
|
+
errors.push("registry.version must be 1");
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (!registry.defaults || typeof registry.defaults !== "object") {
|
|
460
|
+
errors.push("registry.defaults must be an object");
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (!registry.servers || typeof registry.servers !== "object" || Array.isArray(registry.servers)) {
|
|
464
|
+
errors.push("registry.servers must be an object");
|
|
465
|
+
} else {
|
|
466
|
+
for (const [name, server] of Object.entries(registry.servers)) {
|
|
467
|
+
if (!name.trim()) {
|
|
468
|
+
errors.push("registry.servers contains an empty name");
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (!server || typeof server !== "object" || Array.isArray(server)) {
|
|
472
|
+
errors.push(`registry.servers.${name} must be an object`);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
if (typeof server.url !== "string" || !server.url.trim()) {
|
|
476
|
+
errors.push(`registry.servers.${name}.url must be a non-empty string`);
|
|
477
|
+
}
|
|
478
|
+
if (server.targets !== undefined && !Array.isArray(server.targets)) {
|
|
479
|
+
errors.push(`registry.servers.${name}.targets must be an array`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!registry.policies || typeof registry.policies !== "object" || Array.isArray(registry.policies)) {
|
|
485
|
+
errors.push("registry.policies must be an object");
|
|
486
|
+
} else {
|
|
487
|
+
if (!Array.isArray(registry.policies.watched_paths)) {
|
|
488
|
+
errors.push("registry.policies.watched_paths must be an array");
|
|
489
|
+
}
|
|
490
|
+
if (registry.policies.stdio_action && !["replace-with-hub", "warn"].includes(registry.policies.stdio_action)) {
|
|
491
|
+
errors.push("registry.policies.stdio_action must be replace-with-hub or warn");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return errors;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export function inspectRegistry() {
|
|
499
|
+
if (!existsSync(REGISTRY_PATH)) {
|
|
500
|
+
return {
|
|
501
|
+
path: REGISTRY_PATH,
|
|
502
|
+
exists: false,
|
|
503
|
+
valid: false,
|
|
504
|
+
errors: ["registry file missing"],
|
|
505
|
+
registry: null,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
try {
|
|
510
|
+
const registry = readJsonFile(REGISTRY_PATH);
|
|
511
|
+
const errors = validateRegistry(registry);
|
|
512
|
+
return {
|
|
513
|
+
path: REGISTRY_PATH,
|
|
514
|
+
exists: true,
|
|
515
|
+
valid: errors.length === 0,
|
|
516
|
+
errors,
|
|
517
|
+
registry: errors.length === 0 ? registry : null,
|
|
518
|
+
};
|
|
519
|
+
} catch (error) {
|
|
520
|
+
return {
|
|
521
|
+
path: REGISTRY_PATH,
|
|
522
|
+
exists: true,
|
|
523
|
+
valid: false,
|
|
524
|
+
errors: [error.message],
|
|
525
|
+
registry: null,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function loadRegistry() {
|
|
531
|
+
const state = inspectRegistry();
|
|
532
|
+
if (!state.exists) {
|
|
533
|
+
throw new Error(`MCP registry missing: ${state.path}`);
|
|
534
|
+
}
|
|
535
|
+
if (!state.valid) {
|
|
536
|
+
throw new Error(`MCP registry invalid: ${state.errors.join("; ")}`);
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
...state.registry,
|
|
540
|
+
defaults: { ...(state.registry?.defaults || {}) },
|
|
541
|
+
servers: { ...(state.registry?.servers || {}) },
|
|
542
|
+
policies: { ...(state.registry?.policies || {}) },
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export function loadRegistryOrDefault() {
|
|
547
|
+
const state = inspectRegistry();
|
|
548
|
+
if (!state.exists) return cloneDefaultRegistry();
|
|
549
|
+
if (!state.valid) return cloneDefaultRegistry();
|
|
550
|
+
return {
|
|
551
|
+
...state.registry,
|
|
552
|
+
defaults: { ...(state.registry?.defaults || {}) },
|
|
553
|
+
servers: { ...(state.registry?.servers || {}) },
|
|
554
|
+
policies: { ...(state.registry?.policies || {}) },
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export function saveRegistry(registry) {
|
|
559
|
+
const errors = validateRegistry(registry);
|
|
560
|
+
if (errors.length > 0) {
|
|
561
|
+
throw new Error(`MCP registry invalid: ${errors.join("; ")}`);
|
|
562
|
+
}
|
|
563
|
+
writeJsonFile(REGISTRY_PATH, registry);
|
|
564
|
+
return registry;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export function listManagedConfigTargets(registry = loadRegistryOrDefault()) {
|
|
568
|
+
return (registry?.policies?.watched_paths || []).map((watchedPath) => {
|
|
569
|
+
const filePath = resolveFilePath(watchedPath);
|
|
570
|
+
return {
|
|
571
|
+
watchedPath,
|
|
572
|
+
filePath,
|
|
573
|
+
client: detectClient(filePath),
|
|
574
|
+
label: detectLabel(filePath),
|
|
575
|
+
exists: existsSync(filePath),
|
|
576
|
+
};
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export function listPrimaryConfigTargets(registry = loadRegistryOrDefault()) {
|
|
581
|
+
return listManagedConfigTargets(registry).filter((target) => isPrimaryConfigTarget(target.filePath));
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export function scanManagedConfigs(registry = loadRegistryOrDefault()) {
|
|
585
|
+
return listManagedConfigTargets(registry).map((target) => ({
|
|
586
|
+
...target,
|
|
587
|
+
...scanConfig(target.filePath),
|
|
588
|
+
}));
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export function inspectRegistryStatus(registry = loadRegistryOrDefault()) {
|
|
592
|
+
const configs = scanManagedConfigs(registry);
|
|
593
|
+
const primaryTargets = new Set(listPrimaryConfigTargets(registry).map((target) => normalizeForMatch(target.filePath)));
|
|
594
|
+
const rows = [];
|
|
595
|
+
|
|
596
|
+
for (const config of configs) {
|
|
597
|
+
const isPrimary = primaryTargets.has(normalizeForMatch(config.filePath));
|
|
598
|
+
const managedServers = Object.entries(registry.servers || {})
|
|
599
|
+
.filter(([, serverConfig]) => isPrimary && serverAppliesToClient(serverConfig, config.client));
|
|
600
|
+
|
|
601
|
+
for (const [name, serverConfig] of managedServers) {
|
|
602
|
+
const expectedUrl = buildDesiredServerRecord(name, serverConfig, config.filePath).config.url;
|
|
603
|
+
const actual = config.servers.find((server) => server.name === name) || null;
|
|
604
|
+
let status = "missing";
|
|
605
|
+
|
|
606
|
+
if (!config.exists) {
|
|
607
|
+
status = "missing-file";
|
|
608
|
+
} else if (config.parseError) {
|
|
609
|
+
status = "invalid-config";
|
|
610
|
+
} else if (!actual) {
|
|
611
|
+
status = "missing";
|
|
612
|
+
} else if (!actual.url) {
|
|
613
|
+
status = actual.transport === "stdio" ? "stdio" : "invalid";
|
|
614
|
+
} else if (normalizeUrl(actual.url) === normalizeUrl(expectedUrl)) {
|
|
615
|
+
status = "present";
|
|
616
|
+
} else {
|
|
617
|
+
status = "mismatch";
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
rows.push({
|
|
621
|
+
type: "registry",
|
|
622
|
+
name,
|
|
623
|
+
client: config.client,
|
|
624
|
+
label: config.label,
|
|
625
|
+
filePath: config.filePath,
|
|
626
|
+
expectedUrl,
|
|
627
|
+
actualUrl: actual?.url || "",
|
|
628
|
+
status,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
for (const server of config.stdioServers) {
|
|
633
|
+
if (Object.hasOwn(registry.servers || {}, server.name)) continue;
|
|
634
|
+
rows.push({
|
|
635
|
+
type: "stdio",
|
|
636
|
+
name: server.name,
|
|
637
|
+
client: config.client,
|
|
638
|
+
label: config.label,
|
|
639
|
+
filePath: config.filePath,
|
|
640
|
+
expectedUrl: "",
|
|
641
|
+
actualUrl: "",
|
|
642
|
+
status: "warning",
|
|
643
|
+
command: server.command,
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return {
|
|
649
|
+
registry,
|
|
650
|
+
configs,
|
|
651
|
+
rows,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function scanForStdioServers(filePath) {
|
|
656
|
+
return scanConfig(filePath).stdioServers;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export function remediate(filePath, stdioServers, policy = {}) {
|
|
660
|
+
const resolvedPath = resolveFilePath(filePath);
|
|
661
|
+
const offenders = Array.isArray(stdioServers) ? stdioServers.filter((server) => server?.name) : [];
|
|
662
|
+
const action = policy?.stdio_action || "warn";
|
|
663
|
+
|
|
664
|
+
if (offenders.length === 0) {
|
|
665
|
+
return {
|
|
666
|
+
action: "noop",
|
|
667
|
+
modified: false,
|
|
668
|
+
backupPath: null,
|
|
669
|
+
removedServers: [],
|
|
670
|
+
warnings: [],
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (action === "warn") {
|
|
675
|
+
return {
|
|
676
|
+
action,
|
|
677
|
+
modified: false,
|
|
678
|
+
backupPath: null,
|
|
679
|
+
removedServers: [],
|
|
680
|
+
warnings: [
|
|
681
|
+
`[mcp-guard] stdio MCP 감지: ${offenders.map((server) => server.name).join(", ")}`,
|
|
682
|
+
],
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if (isCodexConfig(resolvedPath)) {
|
|
687
|
+
return {
|
|
688
|
+
action,
|
|
689
|
+
modified: false,
|
|
690
|
+
backupPath: null,
|
|
691
|
+
removedServers: [],
|
|
692
|
+
warnings: ["[mcp-guard] Codex TOML 자동 수정은 Wave 2-B 범위 밖입니다."],
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const snapshot = scanConfig(resolvedPath);
|
|
697
|
+
if (snapshot.parseError) {
|
|
698
|
+
return {
|
|
699
|
+
action,
|
|
700
|
+
modified: false,
|
|
701
|
+
backupPath: null,
|
|
702
|
+
removedServers: [],
|
|
703
|
+
warnings: [`[mcp-guard] 설정 파싱 실패: ${snapshot.parseError.message}`],
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let backupPath = null;
|
|
708
|
+
try {
|
|
709
|
+
if (existsSync(resolvedPath)) backupPath = ensureBackup(resolvedPath);
|
|
710
|
+
} catch (error) {
|
|
711
|
+
return {
|
|
712
|
+
action,
|
|
713
|
+
modified: false,
|
|
714
|
+
backupPath: null,
|
|
715
|
+
removedServers: [],
|
|
716
|
+
warnings: [`[mcp-guard] 백업 생성 실패: ${error.message}`],
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
const removals = offenders.map((server) => server.name);
|
|
721
|
+
const updates = [];
|
|
722
|
+
let replacement = null;
|
|
723
|
+
|
|
724
|
+
if (action === "replace-with-hub") {
|
|
725
|
+
const registry = loadRegistryOrDefault();
|
|
726
|
+
const [hubServerName, hubServerConfig] = getHubServerEntry(registry);
|
|
727
|
+
const desired = buildDesiredServerRecord(hubServerName, hubServerConfig, resolvedPath);
|
|
728
|
+
replacement = { name: desired.name, ...desired.config };
|
|
729
|
+
updates.push(desired);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
const result = updateJsonConfig(resolvedPath, updates, removals);
|
|
733
|
+
return {
|
|
734
|
+
action,
|
|
735
|
+
modified: result.modified,
|
|
736
|
+
backupPath,
|
|
737
|
+
removedServers: removals,
|
|
738
|
+
replacement,
|
|
739
|
+
warnings: [],
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
export function resolveHubUrl() {
|
|
744
|
+
const registryState = inspectRegistry();
|
|
745
|
+
const registry = registryState.valid ? registryState.registry : cloneDefaultRegistry();
|
|
746
|
+
const [, hubServer] = getHubServerEntry(registry);
|
|
747
|
+
const fallbackRaw = hubServer?.url || `${registry?.defaults?.hub_base || "http://127.0.0.1:27888"}${DEFAULT_HUB_PATH}`;
|
|
748
|
+
|
|
749
|
+
let fallback;
|
|
750
|
+
try {
|
|
751
|
+
fallback = new URL(fallbackRaw);
|
|
752
|
+
} catch {
|
|
753
|
+
fallback = new URL(`http://127.0.0.1:27888${DEFAULT_HUB_PATH}`);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
const envPortRaw = Number(process.env.TFX_HUB_PORT || "");
|
|
757
|
+
const envPort = Number.isFinite(envPortRaw) && envPortRaw > 0 ? envPortRaw : null;
|
|
758
|
+
const target = {
|
|
759
|
+
protocol: fallback.protocol || "http:",
|
|
760
|
+
host: fallback.hostname || "127.0.0.1",
|
|
761
|
+
port: envPort || Number(fallback.port || 27888),
|
|
762
|
+
pathname: fallback.pathname && fallback.pathname !== "/" ? fallback.pathname : DEFAULT_HUB_PATH,
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
const hubPidPath = join(homedir(), ".claude", "cache", "tfx-hub", "hub.pid");
|
|
766
|
+
if (existsSync(hubPidPath)) {
|
|
767
|
+
try {
|
|
768
|
+
const info = readJsonFile(hubPidPath);
|
|
769
|
+
if (!envPort) {
|
|
770
|
+
const pidPort = Number(info?.port);
|
|
771
|
+
if (Number.isFinite(pidPort) && pidPort > 0) target.port = pidPort;
|
|
772
|
+
}
|
|
773
|
+
if (typeof info?.host === "string") {
|
|
774
|
+
const host = info.host.trim();
|
|
775
|
+
if (LOOPBACK_HOSTS.has(host)) target.host = host;
|
|
776
|
+
}
|
|
777
|
+
} catch {
|
|
778
|
+
// pid 파일 파싱 실패 시 registry 기본값 사용
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const hostPart = target.host.includes(":") ? `[${target.host}]` : target.host;
|
|
783
|
+
return `${target.protocol}//${hostPart}:${target.port}${target.pathname}`;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
export function isWatchedPath(filePath) {
|
|
787
|
+
const registryState = inspectRegistry();
|
|
788
|
+
const registry = registryState.valid ? registryState.registry : cloneDefaultRegistry();
|
|
789
|
+
const candidate = normalizeForMatch(filePath);
|
|
790
|
+
|
|
791
|
+
return (registry?.policies?.watched_paths || []).some((watchedPath) => {
|
|
792
|
+
if (typeof watchedPath !== "string" || !watchedPath.trim()) return false;
|
|
793
|
+
|
|
794
|
+
const trimmed = watchedPath.trim();
|
|
795
|
+
const expanded = expandHome(trimmed);
|
|
796
|
+
|
|
797
|
+
if (trimmed !== expanded || isAbsolute(expanded)) {
|
|
798
|
+
return candidate === normalizeForMatch(expanded);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (!trimmed.includes("/") && !trimmed.includes("\\")) {
|
|
802
|
+
return pathBasename(candidate) === trimmed.toLowerCase();
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const suffix = trimmed.replace(/^[.][\\/]/, "").replace(/\\/g, "/").toLowerCase();
|
|
806
|
+
return candidate.endsWith(`/${suffix}`);
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
export function addRegistryServer(name, url, options = {}) {
|
|
811
|
+
const trimmedName = String(name || "").trim();
|
|
812
|
+
const normalizedUrl = normalizeUrl(url);
|
|
813
|
+
if (!trimmedName) throw new Error("server name is required");
|
|
814
|
+
if (!normalizedUrl) throw new Error("server url is required");
|
|
815
|
+
|
|
816
|
+
const registryState = inspectRegistry();
|
|
817
|
+
const registry = registryState.valid ? loadRegistry() : cloneDefaultRegistry();
|
|
818
|
+
const transport = options.transport || (trimmedName === "tfx-hub" ? "hub-url" : "url");
|
|
819
|
+
|
|
820
|
+
registry.servers[trimmedName] = {
|
|
821
|
+
transport,
|
|
822
|
+
url: normalizedUrl,
|
|
823
|
+
safe: options.safe ?? true,
|
|
824
|
+
targets: Array.isArray(options.targets) && options.targets.length > 0
|
|
825
|
+
? [...new Set(options.targets.map((value) => String(value).trim()).filter(Boolean))]
|
|
826
|
+
: ["claude", "gemini", "codex"],
|
|
827
|
+
description: options.description || `${trimmedName} MCP 서버`,
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
saveRegistry(registry);
|
|
831
|
+
return registry.servers[trimmedName];
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
export function removeRegistryServer(name) {
|
|
835
|
+
const trimmedName = String(name || "").trim();
|
|
836
|
+
if (!trimmedName) throw new Error("server name is required");
|
|
837
|
+
|
|
838
|
+
const state = inspectRegistry();
|
|
839
|
+
if (!state.exists || !state.valid) return null;
|
|
840
|
+
const registry = loadRegistry();
|
|
841
|
+
const existing = registry.servers[trimmedName] || null;
|
|
842
|
+
if (existing) {
|
|
843
|
+
delete registry.servers[trimmedName];
|
|
844
|
+
saveRegistry(registry);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
return existing;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
export function removeServerFromTargets(name, options = {}) {
|
|
851
|
+
const trimmedName = String(name || "").trim();
|
|
852
|
+
if (!trimmedName) throw new Error("server name is required");
|
|
853
|
+
|
|
854
|
+
const registry = options.registry || (inspectRegistry().valid ? loadRegistry() : cloneDefaultRegistry());
|
|
855
|
+
const targetsFilter = Array.isArray(options.targets) && options.targets.length > 0
|
|
856
|
+
? new Set(options.targets)
|
|
857
|
+
: null;
|
|
858
|
+
const actions = [];
|
|
859
|
+
|
|
860
|
+
for (const target of listManagedConfigTargets(registry)) {
|
|
861
|
+
if (targetsFilter && !targetsFilter.has(target.client)) continue;
|
|
862
|
+
|
|
863
|
+
const snapshot = scanConfig(target.filePath);
|
|
864
|
+
if (snapshot.parseError) {
|
|
865
|
+
actions.push({
|
|
866
|
+
type: "remove",
|
|
867
|
+
name: trimmedName,
|
|
868
|
+
filePath: target.filePath,
|
|
869
|
+
label: target.label,
|
|
870
|
+
status: "invalid-config",
|
|
871
|
+
message: snapshot.parseError.message,
|
|
872
|
+
});
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
let result;
|
|
877
|
+
if (isCodexConfig(target.filePath)) {
|
|
878
|
+
result = updateCodexConfig(target.filePath, [], [trimmedName]);
|
|
879
|
+
} else if (isJsonMcpConfig(target.filePath)) {
|
|
880
|
+
result = updateJsonConfig(target.filePath, [], [trimmedName]);
|
|
881
|
+
} else {
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
actions.push({
|
|
886
|
+
type: "remove",
|
|
887
|
+
name: trimmedName,
|
|
888
|
+
filePath: target.filePath,
|
|
889
|
+
label: target.label,
|
|
890
|
+
status: result.modified ? "removed" : "noop",
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
return { actions };
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
export function syncRegistryTargets(options = {}) {
|
|
898
|
+
const registry = options.registry || loadRegistryOrDefault();
|
|
899
|
+
const actions = [];
|
|
900
|
+
|
|
901
|
+
for (const target of listManagedConfigTargets(registry)) {
|
|
902
|
+
const snapshot = scanConfig(target.filePath);
|
|
903
|
+
if (snapshot.parseError) {
|
|
904
|
+
actions.push({
|
|
905
|
+
type: "sync",
|
|
906
|
+
filePath: target.filePath,
|
|
907
|
+
label: target.label,
|
|
908
|
+
status: "invalid-config",
|
|
909
|
+
message: snapshot.parseError.message,
|
|
910
|
+
});
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
if (snapshot.stdioServers.length > 0) {
|
|
915
|
+
const remediation = remediate(target.filePath, snapshot.stdioServers, registry.policies);
|
|
916
|
+
actions.push({
|
|
917
|
+
type: "remediate",
|
|
918
|
+
filePath: target.filePath,
|
|
919
|
+
label: target.label,
|
|
920
|
+
status: remediation.modified ? "updated" : "warning",
|
|
921
|
+
removedServers: remediation.removedServers,
|
|
922
|
+
replacement: remediation.replacement || null,
|
|
923
|
+
warnings: remediation.warnings || [],
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
for (const target of listPrimaryConfigTargets(registry)) {
|
|
929
|
+
const updates = Object.entries(registry.servers || {})
|
|
930
|
+
.filter(([, serverConfig]) => serverAppliesToClient(serverConfig, target.client))
|
|
931
|
+
.map(([name, serverConfig]) => buildDesiredServerRecord(name, serverConfig, target.filePath));
|
|
932
|
+
|
|
933
|
+
if (updates.length === 0) continue;
|
|
934
|
+
|
|
935
|
+
let result;
|
|
936
|
+
if (isCodexConfig(target.filePath)) {
|
|
937
|
+
result = updateCodexConfig(target.filePath, updates, []);
|
|
938
|
+
} else if (isJsonMcpConfig(target.filePath)) {
|
|
939
|
+
result = updateJsonConfig(target.filePath, updates, []);
|
|
940
|
+
} else {
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
actions.push({
|
|
945
|
+
type: "sync",
|
|
946
|
+
filePath: target.filePath,
|
|
947
|
+
label: target.label,
|
|
948
|
+
status: result.modified ? "updated" : "ok",
|
|
949
|
+
serverCount: updates.length,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
return { actions };
|
|
954
|
+
}
|