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.
Files changed (426) hide show
  1. package/CLAUDE.md +171 -0
  2. package/README.md +32 -15
  3. package/bin/triflux.mjs +62 -5
  4. package/hooks/agent-route-guard.mjs +109 -0
  5. package/hooks/cross-review-tracker.mjs +122 -0
  6. package/hooks/error-context.mjs +148 -0
  7. package/hooks/hook-adaptive-collector.mjs +86 -0
  8. package/hooks/hook-manager.mjs +365 -0
  9. package/hooks/hook-orchestrator.mjs +312 -0
  10. package/hooks/hook-registry.json +246 -0
  11. package/hooks/hooks.json +89 -0
  12. package/hooks/keyword-rules.json +574 -0
  13. package/hooks/lib/resolve-root.mjs +59 -0
  14. package/hooks/mcp-config-watcher.mjs +80 -0
  15. package/hooks/pipeline-stop.mjs +76 -0
  16. package/hooks/safety-guard.mjs +169 -0
  17. package/hooks/subagent-verifier.mjs +80 -0
  18. package/hub/account-broker.mjs +251 -0
  19. package/hub/adaptive-diagnostic.mjs +323 -0
  20. package/hub/adaptive-inject.mjs +186 -0
  21. package/hub/adaptive-memory.mjs +163 -0
  22. package/hub/adaptive.mjs +143 -0
  23. package/hub/assign-callbacks.mjs +133 -0
  24. package/hub/bridge.mjs +799 -0
  25. package/hub/cli-adapter-base.mjs +280 -0
  26. package/hub/codex-adapter.mjs +199 -0
  27. package/hub/codex-compat.mjs +11 -0
  28. package/hub/codex-preflight.mjs +166 -0
  29. package/hub/delegator/contracts.mjs +37 -0
  30. package/hub/delegator/index.mjs +14 -0
  31. package/hub/delegator/schema/delegator-tools.schema.json +250 -0
  32. package/hub/delegator/service.mjs +307 -0
  33. package/hub/delegator/tool-definitions.mjs +35 -0
  34. package/hub/fullcycle.mjs +96 -0
  35. package/hub/gemini-adapter.mjs +180 -0
  36. package/hub/hitl.mjs +143 -0
  37. package/hub/intent.mjs +193 -0
  38. package/hub/lib/cache-guard.mjs +114 -0
  39. package/hub/lib/known-errors.json +72 -0
  40. package/hub/lib/memory-store.mjs +748 -0
  41. package/hub/lib/process-utils.mjs +361 -0
  42. package/hub/lib/ssh-command.mjs +211 -0
  43. package/hub/lib/ssh-retry.mjs +59 -0
  44. package/hub/lib/uuidv7.mjs +44 -0
  45. package/hub/memory-doctor.mjs +480 -0
  46. package/hub/middleware/request-logger.mjs +161 -0
  47. package/hub/paths.mjs +30 -0
  48. package/hub/pipe.mjs +664 -0
  49. package/hub/pipeline/gates/confidence.mjs +56 -0
  50. package/hub/pipeline/gates/consensus.mjs +94 -0
  51. package/hub/pipeline/gates/index.mjs +5 -0
  52. package/hub/pipeline/gates/selfcheck.mjs +82 -0
  53. package/hub/pipeline/index.mjs +318 -0
  54. package/hub/pipeline/state.mjs +191 -0
  55. package/hub/pipeline/transitions.mjs +124 -0
  56. package/hub/platform.mjs +225 -0
  57. package/hub/public/dashboard.html +355 -0
  58. package/hub/public/tray-icon.ico +0 -0
  59. package/hub/public/tray-icon.png +0 -0
  60. package/hub/quality/deslop.mjs +253 -0
  61. package/hub/reflexion.mjs +372 -0
  62. package/hub/research.mjs +146 -0
  63. package/hub/router.mjs +791 -0
  64. package/hub/routing/complexity.mjs +166 -0
  65. package/hub/routing/index.mjs +117 -0
  66. package/hub/routing/q-learning.mjs +336 -0
  67. package/hub/schema.sql +148 -0
  68. package/hub/server.mjs +1264 -0
  69. package/hub/session-fingerprint.mjs +352 -0
  70. package/hub/state.mjs +258 -0
  71. package/hub/store-adapter.mjs +118 -0
  72. package/hub/store.mjs +857 -0
  73. package/hub/team/agent-map.json +11 -0
  74. package/hub/team/ansi.mjs +379 -0
  75. package/hub/team/backend.mjs +90 -0
  76. package/hub/team/cli/commands/attach.mjs +37 -0
  77. package/hub/team/cli/commands/control.mjs +43 -0
  78. package/hub/team/cli/commands/debug.mjs +74 -0
  79. package/hub/team/cli/commands/focus.mjs +53 -0
  80. package/hub/team/cli/commands/interrupt.mjs +36 -0
  81. package/hub/team/cli/commands/kill.mjs +37 -0
  82. package/hub/team/cli/commands/list.mjs +24 -0
  83. package/hub/team/cli/commands/send.mjs +37 -0
  84. package/hub/team/cli/commands/start/index.mjs +106 -0
  85. package/hub/team/cli/commands/start/parse-args.mjs +130 -0
  86. package/hub/team/cli/commands/start/start-headless.mjs +109 -0
  87. package/hub/team/cli/commands/start/start-in-process.mjs +40 -0
  88. package/hub/team/cli/commands/start/start-mux.mjs +73 -0
  89. package/hub/team/cli/commands/start/start-wt.mjs +69 -0
  90. package/hub/team/cli/commands/status.mjs +87 -0
  91. package/hub/team/cli/commands/stop.mjs +31 -0
  92. package/hub/team/cli/commands/task.mjs +30 -0
  93. package/hub/team/cli/commands/tasks.mjs +13 -0
  94. package/hub/team/cli/help.mjs +42 -0
  95. package/hub/team/cli/index.mjs +41 -0
  96. package/hub/team/cli/manifest.mjs +29 -0
  97. package/hub/team/cli/render.mjs +30 -0
  98. package/hub/team/cli/services/attach-fallback.mjs +54 -0
  99. package/hub/team/cli/services/hub-client.mjs +227 -0
  100. package/hub/team/cli/services/member-selector.mjs +30 -0
  101. package/hub/team/cli/services/native-control.mjs +117 -0
  102. package/hub/team/cli/services/runtime-mode.mjs +62 -0
  103. package/hub/team/cli/services/state-store.mjs +48 -0
  104. package/hub/team/cli/services/task-model.mjs +30 -0
  105. package/hub/team/conductor-mesh-bridge.mjs +121 -0
  106. package/hub/team/conductor.mjs +671 -0
  107. package/hub/team/dashboard-anchor.mjs +14 -0
  108. package/hub/team/dashboard-layout.mjs +33 -0
  109. package/hub/team/dashboard-open.mjs +153 -0
  110. package/hub/team/dashboard.mjs +274 -0
  111. package/hub/team/event-log.mjs +76 -0
  112. package/hub/team/handoff.mjs +303 -0
  113. package/hub/team/headless.mjs +1156 -0
  114. package/hub/team/health-probe.mjs +272 -0
  115. package/hub/team/launcher-template.mjs +95 -0
  116. package/hub/team/lead-control.mjs +104 -0
  117. package/hub/team/native-supervisor.mjs +392 -0
  118. package/hub/team/native.mjs +649 -0
  119. package/hub/team/nativeProxy.mjs +688 -0
  120. package/hub/team/notify.mjs +293 -0
  121. package/hub/team/orchestrator.mjs +161 -0
  122. package/hub/team/pane.mjs +153 -0
  123. package/hub/team/process-cleanup.mjs +342 -0
  124. package/hub/team/psmux.mjs +1354 -0
  125. package/hub/team/remote-probe.mjs +276 -0
  126. package/hub/team/remote-session.mjs +299 -0
  127. package/hub/team/remote-watcher.mjs +478 -0
  128. package/hub/team/routing.mjs +223 -0
  129. package/hub/team/session-sync.mjs +169 -0
  130. package/hub/team/session.mjs +611 -0
  131. package/hub/team/shared.mjs +13 -0
  132. package/hub/team/staleState.mjs +361 -0
  133. package/hub/team/swarm-hypervisor.mjs +589 -0
  134. package/hub/team/swarm-locks.mjs +204 -0
  135. package/hub/team/swarm-planner.mjs +260 -0
  136. package/hub/team/swarm-reconciler.mjs +137 -0
  137. package/hub/team/tui-lite.mjs +380 -0
  138. package/hub/team/tui-remote-adapter.mjs +393 -0
  139. package/hub/team/tui-viewer.mjs +463 -0
  140. package/hub/team/tui.mjs +1449 -0
  141. package/hub/team/worktree-lifecycle.mjs +193 -0
  142. package/hub/team/wt-manager.mjs +407 -0
  143. package/hub/team/wt-templates.json +43 -0
  144. package/hub/team-bridge.mjs +27 -0
  145. package/hub/token-mode.mjs +224 -0
  146. package/hub/tools.mjs +636 -0
  147. package/hub/tray.mjs +376 -0
  148. package/hub/workers/claude-worker.mjs +475 -0
  149. package/hub/workers/codex-mcp.mjs +507 -0
  150. package/hub/workers/delegator-mcp.mjs +1076 -0
  151. package/hub/workers/factory.mjs +21 -0
  152. package/hub/workers/gemini-worker.mjs +374 -0
  153. package/hub/workers/interface.mjs +52 -0
  154. package/hub/workers/worker-utils.mjs +104 -0
  155. package/hud/colors.mjs +88 -0
  156. package/hud/constants.mjs +88 -0
  157. package/hud/context-monitor.mjs +403 -0
  158. package/hud/hud-qos-status.mjs +210 -0
  159. package/hud/providers/claude.mjs +314 -0
  160. package/hud/providers/codex.mjs +151 -0
  161. package/hud/providers/gemini.mjs +320 -0
  162. package/hud/renderers.mjs +442 -0
  163. package/hud/terminal.mjs +140 -0
  164. package/hud/utils.mjs +313 -0
  165. package/mesh/index.mjs +63 -0
  166. package/mesh/mesh-budget.mjs +128 -0
  167. package/mesh/mesh-heartbeat.mjs +100 -0
  168. package/mesh/mesh-protocol.mjs +96 -0
  169. package/mesh/mesh-queue.mjs +165 -0
  170. package/mesh/mesh-registry.mjs +78 -0
  171. package/mesh/mesh-router.mjs +76 -0
  172. package/package.json +8 -1
  173. package/references/hosts.json +33 -0
  174. package/scripts/__tests__/gen-skill-docs.test.mjs +87 -0
  175. package/scripts/__tests__/keyword-detector.test.mjs +234 -0
  176. package/scripts/__tests__/mcp-guard-engine.test.mjs +118 -0
  177. package/scripts/__tests__/remote-spawn-transfer.test.mjs +117 -0
  178. package/scripts/__tests__/remote-spawn.test.mjs +92 -0
  179. package/scripts/__tests__/skill-template.test.mjs +193 -0
  180. package/scripts/__tests__/smoke.test.mjs +34 -0
  181. package/scripts/cache-buildup.mjs +30 -0
  182. package/scripts/cache-doctor.mjs +149 -0
  183. package/scripts/cache-warmup.mjs +557 -0
  184. package/scripts/claudemd-sync.mjs +148 -0
  185. package/scripts/cli-route.sh +3 -0
  186. package/scripts/completions/tfx.bash +47 -0
  187. package/scripts/completions/tfx.fish +44 -0
  188. package/scripts/completions/tfx.zsh +83 -0
  189. package/scripts/cross-review-gate.mjs +126 -0
  190. package/scripts/cross-review-tracker.mjs +238 -0
  191. package/scripts/gen-skill-docs.mjs +111 -0
  192. package/scripts/headless-guard-fast.sh +21 -0
  193. package/scripts/headless-guard.mjs +360 -0
  194. package/scripts/hub-ensure.mjs +120 -0
  195. package/scripts/keyword-detector.mjs +272 -0
  196. package/scripts/keyword-rules-expander.mjs +521 -0
  197. package/scripts/lib/claudemd-scanner.mjs +218 -0
  198. package/scripts/lib/context.mjs +67 -0
  199. package/scripts/lib/cross-review-utils.mjs +51 -0
  200. package/scripts/lib/env-probe.mjs +241 -0
  201. package/scripts/lib/gemini-profiles.mjs +85 -0
  202. package/scripts/lib/handoff.mjs +171 -0
  203. package/scripts/lib/hook-utils.mjs +14 -0
  204. package/scripts/lib/keyword-rules.mjs +166 -0
  205. package/scripts/lib/logger.mjs +105 -0
  206. package/scripts/lib/mcp-filter.mjs +739 -0
  207. package/scripts/lib/mcp-guard-engine.mjs +954 -0
  208. package/scripts/lib/mcp-manifest.mjs +79 -0
  209. package/scripts/lib/mcp-server-catalog.mjs +118 -0
  210. package/scripts/lib/psmux-info.mjs +119 -0
  211. package/scripts/lib/remote-spawn-transfer.mjs +196 -0
  212. package/scripts/lib/skill-template.mjs +326 -0
  213. package/scripts/mcp-check.mjs +237 -0
  214. package/scripts/mcp-cleanup.ps1 +17 -0
  215. package/scripts/mcp-gateway-config.mjs +207 -0
  216. package/scripts/mcp-gateway-ensure.mjs +85 -0
  217. package/scripts/mcp-gateway-integration-test.mjs +228 -0
  218. package/scripts/mcp-gateway-start.mjs +226 -0
  219. package/scripts/mcp-gateway-start.ps1 +141 -0
  220. package/scripts/mcp-gateway-verify.mjs +77 -0
  221. package/scripts/mcp-safety-guard.mjs +44 -0
  222. package/scripts/notion-read.mjs +556 -0
  223. package/scripts/pack.mjs +295 -0
  224. package/scripts/preflight-cache.mjs +69 -0
  225. package/scripts/preinstall.mjs +96 -0
  226. package/scripts/remote-spawn.mjs +1376 -0
  227. package/scripts/run.cjs +79 -0
  228. package/scripts/session-spawn-helper.mjs +185 -0
  229. package/scripts/setup.mjs +1178 -0
  230. package/scripts/test-lock.mjs +71 -0
  231. package/scripts/test-tfx-route-no-claude-native.mjs +57 -0
  232. package/scripts/tfx-batch-stats.mjs +96 -0
  233. package/scripts/tfx-gate-activate.mjs +89 -0
  234. package/scripts/tfx-route-post.mjs +505 -0
  235. package/scripts/tfx-route-worker.mjs +223 -0
  236. package/scripts/tfx-route.sh +2014 -0
  237. package/scripts/tmp-cleanup.mjs +103 -0
  238. package/scripts/token-snapshot.mjs +575 -0
  239. package/skills/tfx-auto/SKILL.md.tmpl +2 -3
  240. package/skills/tfx-autoresearch/SKILL.md +6 -5
  241. package/skills/tfx-codex/SKILL.md.tmpl +2 -3
  242. package/skills/tfx-codex-swarm-workspace/iteration-1/benchmark.json +33 -0
  243. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/eval_metadata.json +42 -0
  244. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/grading.json +11 -0
  245. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/analysis.md +87 -0
  246. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/classification.md +35 -0
  247. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/commands.sh +275 -0
  248. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/outputs/routing.md +56 -0
  249. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/timing.json +5 -0
  250. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/grading.json +11 -0
  251. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/analysis.md +92 -0
  252. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/classification.md +71 -0
  253. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/commands.sh +264 -0
  254. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/outputs/routing.md +113 -0
  255. package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/timing.json +5 -0
  256. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/eval_metadata.json +32 -0
  257. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/grading.json +9 -0
  258. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/analysis.md +96 -0
  259. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/classification.md +38 -0
  260. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/commands.sh +151 -0
  261. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/outputs/routing.md +51 -0
  262. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/timing.json +5 -0
  263. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/grading.json +9 -0
  264. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/analysis.md +127 -0
  265. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/classification.md +57 -0
  266. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/commands.sh +129 -0
  267. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/outputs/routing.md +84 -0
  268. package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/timing.json +5 -0
  269. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/eval_metadata.json +27 -0
  270. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/grading.json +8 -0
  271. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/analysis.md +98 -0
  272. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/classification.md +65 -0
  273. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/commands.sh +123 -0
  274. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/outputs/routing.md +66 -0
  275. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/timing.json +5 -0
  276. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/grading.json +8 -0
  277. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/analysis.md +88 -0
  278. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/classification.md +40 -0
  279. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/commands.sh +130 -0
  280. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/outputs/routing.md +61 -0
  281. package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/timing.json +5 -0
  282. package/skills/tfx-deep-interview/SKILL.md +1 -2
  283. package/skills/tfx-plan/SKILL.md.tmpl +2 -3
  284. package/skills/tfx-psmux-rules/SKILL.md +11 -2
  285. package/skills/tfx-qa/SKILL.md.tmpl +2 -3
  286. package/skills/tfx-remote-spawn/SKILL.md +8 -11
  287. package/skills/tfx-research/SKILL.md.tmpl +2 -3
  288. package/skills/tfx-review/SKILL.md.tmpl +2 -3
  289. package/skills/tfx-workspace/async-tests/run-tests.sh +203 -0
  290. package/skills/tfx-workspace/evals/evals.json +79 -0
  291. package/skills/tfx-workspace/iteration-1/benchmark.json +162 -0
  292. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/eval_metadata.json +11 -0
  293. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/grading.json +9 -0
  294. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/outputs/analysis.md +154 -0
  295. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/timing.json +5 -0
  296. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/grading.json +9 -0
  297. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/outputs/analysis.md +126 -0
  298. package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/timing.json +5 -0
  299. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/eval_metadata.json +11 -0
  300. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/grading.json +9 -0
  301. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/outputs/analysis.md +119 -0
  302. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/timing.json +5 -0
  303. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/grading.json +9 -0
  304. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/outputs/analysis.md +115 -0
  305. package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/timing.json +5 -0
  306. package/skills/tfx-workspace/iteration-1/hub-start-sequence/eval_metadata.json +10 -0
  307. package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/grading.json +8 -0
  308. package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/outputs/analysis.md +86 -0
  309. package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/timing.json +5 -0
  310. package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/grading.json +8 -0
  311. package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/outputs/analysis.md +81 -0
  312. package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/timing.json +5 -0
  313. package/skills/tfx-workspace/iteration-1/multi-team-creation/eval_metadata.json +12 -0
  314. package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/grading.json +10 -0
  315. package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/outputs/analysis.md +316 -0
  316. package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/timing.json +5 -0
  317. package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/grading.json +10 -0
  318. package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/outputs/analysis.md +352 -0
  319. package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/timing.json +5 -0
  320. package/skills/tfx-workspace/iteration-1/review.html +1325 -0
  321. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/eval_metadata.json +12 -0
  322. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/grading.json +10 -0
  323. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/outputs/analysis.md +97 -0
  324. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/timing.json +5 -0
  325. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/grading.json +10 -0
  326. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/outputs/analysis.md +94 -0
  327. package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/timing.json +5 -0
  328. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/eval_metadata.json +12 -0
  329. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/grading.json +10 -0
  330. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/outputs/analysis.md +209 -0
  331. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/timing.json +5 -0
  332. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/grading.json +10 -0
  333. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/outputs/analysis.md +193 -0
  334. package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/timing.json +5 -0
  335. package/skills/tfx-workspace/iteration-2/benchmark.json +62 -0
  336. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/eval_metadata.json +13 -0
  337. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/grading.json +11 -0
  338. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/outputs/analysis.md +382 -0
  339. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/timing.json +5 -0
  340. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/grading.json +11 -0
  341. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/outputs/analysis.md +333 -0
  342. package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/timing.json +5 -0
  343. package/skills/tfx-workspace/iteration-2/review.html +1325 -0
  344. package/skills/tfx-workspace/skill-snapshot/tfx-auto/SKILL.md +217 -0
  345. package/skills/{tfx-auto-codex/SKILL.md.tmpl → tfx-workspace/skill-snapshot/tfx-auto-codex/SKILL.md} +3 -31
  346. package/skills/tfx-workspace/skill-snapshot/tfx-codex/SKILL.md +65 -0
  347. package/skills/tfx-workspace/skill-snapshot/tfx-doctor/SKILL.md +94 -0
  348. package/skills/{tfx-gemini/SKILL.md.tmpl → tfx-workspace/skill-snapshot/tfx-gemini/SKILL.md} +6 -14
  349. package/skills/tfx-workspace/skill-snapshot/tfx-hub/SKILL.md +133 -0
  350. package/skills/tfx-workspace/skill-snapshot/tfx-multi/SKILL.md +426 -0
  351. package/skills/tfx-workspace/skill-snapshot/tfx-setup/SKILL.md +101 -0
  352. package/skills/merge-worktree/SKILL.md.tmpl +0 -144
  353. package/skills/shared/arguments-processing.md +0 -2
  354. package/skills/shared/mandatory-rules.md +0 -6
  355. package/skills/shared/telemetry-segment.md +0 -6
  356. package/skills/star-prompt/SKILL.md.tmpl +0 -122
  357. package/skills/tfx-analysis/SKILL.md.tmpl +0 -106
  358. package/skills/tfx-analysis/skill.json +0 -11
  359. package/skills/tfx-auto/skill.json +0 -26
  360. package/skills/tfx-auto-codex/skill.json +0 -8
  361. package/skills/tfx-autopilot/SKILL.md.tmpl +0 -115
  362. package/skills/tfx-autopilot/skill.json +0 -10
  363. package/skills/tfx-autoresearch/SKILL.md.tmpl +0 -135
  364. package/skills/tfx-autoresearch/skill.json +0 -14
  365. package/skills/tfx-autoroute/SKILL.md.tmpl +0 -188
  366. package/skills/tfx-autoroute/skill.json +0 -12
  367. package/skills/tfx-codex/skill.json +0 -8
  368. package/skills/tfx-codex-swarm/SKILL.md.tmpl +0 -16
  369. package/skills/tfx-codex-swarm/skill.json +0 -5
  370. package/skills/tfx-consensus/SKILL.md.tmpl +0 -145
  371. package/skills/tfx-consensus/skill.json +0 -8
  372. package/skills/tfx-debate/SKILL.md.tmpl +0 -191
  373. package/skills/tfx-debate/skill.json +0 -12
  374. package/skills/tfx-deep-analysis/SKILL.md.tmpl +0 -227
  375. package/skills/tfx-deep-analysis/skill.json +0 -10
  376. package/skills/tfx-deep-interview/SKILL.md.tmpl +0 -203
  377. package/skills/tfx-deep-interview/skill.json +0 -12
  378. package/skills/tfx-deep-plan/SKILL.md.tmpl +0 -281
  379. package/skills/tfx-deep-plan/skill.json +0 -13
  380. package/skills/tfx-deep-qa/SKILL.md.tmpl +0 -164
  381. package/skills/tfx-deep-qa/skill.json +0 -11
  382. package/skills/tfx-deep-research/SKILL.md.tmpl +0 -216
  383. package/skills/tfx-deep-research/skill.json +0 -14
  384. package/skills/tfx-deep-review/SKILL.md.tmpl +0 -178
  385. package/skills/tfx-deep-review/skill.json +0 -12
  386. package/skills/tfx-doctor/SKILL.md.tmpl +0 -172
  387. package/skills/tfx-doctor/skill.json +0 -8
  388. package/skills/tfx-find/skill.json +0 -12
  389. package/skills/tfx-forge/SKILL.md.tmpl +0 -187
  390. package/skills/tfx-forge/skill.json +0 -12
  391. package/skills/tfx-fullcycle/SKILL.md.tmpl +0 -285
  392. package/skills/tfx-fullcycle/skill.json +0 -11
  393. package/skills/tfx-gemini/skill.json +0 -8
  394. package/skills/tfx-hooks/SKILL.md.tmpl +0 -216
  395. package/skills/tfx-hooks/skill.json +0 -8
  396. package/skills/tfx-hub/SKILL.md.tmpl +0 -212
  397. package/skills/tfx-hub/skill.json +0 -8
  398. package/skills/tfx-index/skill.json +0 -11
  399. package/skills/tfx-interview/SKILL.md.tmpl +0 -284
  400. package/skills/tfx-interview/skill.json +0 -12
  401. package/skills/tfx-multi/SKILL.md.tmpl +0 -183
  402. package/skills/tfx-multi/skill.json +0 -8
  403. package/skills/tfx-panel/SKILL.md.tmpl +0 -188
  404. package/skills/tfx-panel/skill.json +0 -12
  405. package/skills/tfx-persist/SKILL.md.tmpl +0 -269
  406. package/skills/tfx-persist/skill.json +0 -12
  407. package/skills/tfx-plan/skill.json +0 -11
  408. package/skills/tfx-profile/SKILL.md.tmpl +0 -239
  409. package/skills/tfx-profile/skill.json +0 -8
  410. package/skills/tfx-prune/SKILL.md.tmpl +0 -199
  411. package/skills/tfx-prune/skill.json +0 -12
  412. package/skills/tfx-psmux-rules/SKILL.md.tmpl +0 -317
  413. package/skills/tfx-psmux-rules/skill.json +0 -8
  414. package/skills/tfx-qa/skill.json +0 -11
  415. package/skills/tfx-ralph/SKILL.md.tmpl +0 -27
  416. package/skills/tfx-ralph/skill.json +0 -8
  417. package/skills/tfx-remote-setup/SKILL.md.tmpl +0 -576
  418. package/skills/tfx-remote-setup/skill.json +0 -8
  419. package/skills/tfx-remote-spawn/SKILL.md.tmpl +0 -263
  420. package/skills/tfx-remote-spawn/skill.json +0 -9
  421. package/skills/tfx-research/skill.json +0 -13
  422. package/skills/tfx-review/skill.json +0 -11
  423. package/skills/tfx-setup/SKILL.md.tmpl +0 -380
  424. package/skills/tfx-setup/skill.json +0 -8
  425. package/skills/tfx-swarm/SKILL.md.tmpl +0 -154
  426. package/skills/tfx-swarm/skill.json +0 -5
@@ -0,0 +1,218 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ export const TFX_START = "<!-- TFX:START -->";
7
+ export const TFX_END = "<!-- TFX:END -->";
8
+ export const OMC_END = "<!-- OMC:END -->";
9
+ const TFX_VERSION_RE = /<!-- TFX:VERSION:([\d.]+) -->/u;
10
+
11
+ const LEGACY_PATTERNS = [
12
+ /<user_cli_routing>/u,
13
+ /Codex Pro 무료 기간/u,
14
+ /codex exec --dangerously-bypass.*skip-git-repo-check/u,
15
+ /OMC 에이전트 → CLI 매핑/u,
16
+ /Spark 가드레일/u,
17
+ ];
18
+
19
+ const DEFAULT_TFX_TEMPLATE = [
20
+ "### triflux CLI routing (managed)",
21
+ "- 이 블록은 triflux setup에서 자동으로 관리됩니다.",
22
+ "- 직접 수정이 필요하면 블록 바깥에 사용자 섹션을 추가하세요.",
23
+ ].join("\n");
24
+
25
+ const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
26
+ const DEFAULT_TEMPLATE_PATH = join(SCRIPT_DIR, "..", "templates", "claudemd-tfx-section.md");
27
+
28
+ function resolveVersion(version) {
29
+ if (version) return version;
30
+ try {
31
+ const pkgPath = join(SCRIPT_DIR, "..", "..", "package.json");
32
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
33
+ return pkg.version || "0.0.0";
34
+ } catch {
35
+ return "0.0.0";
36
+ }
37
+ }
38
+
39
+ function resolveTemplate(template, templatePath = DEFAULT_TEMPLATE_PATH) {
40
+ if (typeof template === "string" && template.trim()) {
41
+ return template.trim();
42
+ }
43
+ if (existsSync(templatePath)) {
44
+ const raw = readFileSync(templatePath, "utf8").trim();
45
+ if (raw) return raw;
46
+ }
47
+ return DEFAULT_TFX_TEMPLATE;
48
+ }
49
+
50
+ function findManagedSection(rawText) {
51
+ const raw = String(rawText || "");
52
+ const startIdx = raw.indexOf(TFX_START);
53
+ const endMarkerIdx = raw.indexOf(TFX_END);
54
+ if (startIdx === -1 || endMarkerIdx === -1 || endMarkerIdx <= startIdx) {
55
+ return {
56
+ found: false,
57
+ content: null,
58
+ version: null,
59
+ startIdx: -1,
60
+ endIdx: -1,
61
+ };
62
+ }
63
+
64
+ const endIdx = endMarkerIdx + TFX_END.length;
65
+ const content = raw.slice(startIdx, endIdx);
66
+ const versionMatch = content.match(TFX_VERSION_RE);
67
+
68
+ return {
69
+ found: true,
70
+ content,
71
+ version: versionMatch ? versionMatch[1] : null,
72
+ startIdx,
73
+ endIdx,
74
+ };
75
+ }
76
+
77
+ function detectLegacyRange(rawText) {
78
+ const raw = String(rawText || "");
79
+ const matches = LEGACY_PATTERNS.some((pattern) => pattern.test(raw));
80
+ if (!matches) {
81
+ return { found: false, startIdx: -1, endIdx: -1 };
82
+ }
83
+
84
+ const startTag = raw.indexOf("<user_cli_routing>");
85
+ const endTag = raw.indexOf("</user_cli_routing>");
86
+ if (startTag === -1 || endTag === -1 || endTag <= startTag) {
87
+ return { found: true, startIdx: -1, endIdx: -1 };
88
+ }
89
+
90
+ let removeStart = startTag;
91
+ const userOverridesComment = "<!-- USER OVERRIDES";
92
+ const commentIdx = raw.lastIndexOf(userOverridesComment, startTag);
93
+ if (commentIdx !== -1 && startTag - commentIdx < 200) {
94
+ removeStart = commentIdx;
95
+ }
96
+
97
+ return {
98
+ found: true,
99
+ startIdx: removeStart,
100
+ endIdx: endTag + "</user_cli_routing>".length,
101
+ };
102
+ }
103
+
104
+ function normalizeSpacing(text) {
105
+ return String(text || "").replace(/\n{3,}/gu, "\n\n");
106
+ }
107
+
108
+ export function findAllClaudeMdPaths(options = {}) {
109
+ const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
110
+ const homeDir = options.homeDir ? resolve(options.homeDir) : homedir();
111
+ const includeGlobal = options.includeGlobal !== false;
112
+ const includeProject = options.includeProject !== false;
113
+
114
+ const candidates = [];
115
+ if (includeGlobal) candidates.push(join(homeDir, ".claude", "CLAUDE.md"));
116
+ if (includeProject) candidates.push(join(cwd, "CLAUDE.md"));
117
+
118
+ const seen = new Set();
119
+ const paths = [];
120
+ for (const candidate of candidates) {
121
+ const normalized = resolve(candidate);
122
+ if (seen.has(normalized)) continue;
123
+ seen.add(normalized);
124
+ if (existsSync(normalized)) {
125
+ paths.push(normalized);
126
+ }
127
+ }
128
+ return paths;
129
+ }
130
+
131
+ export function writeSection(filePath, options = {}) {
132
+ const absolutePath = resolve(filePath);
133
+ const version = resolveVersion(options.version);
134
+ const template = resolveTemplate(options.template, options.templatePath);
135
+ const block = [
136
+ TFX_START,
137
+ `<!-- TFX:VERSION:${version} -->`,
138
+ template,
139
+ TFX_END,
140
+ ].join("\n");
141
+
142
+ if (!existsSync(absolutePath)) {
143
+ writeFileSync(absolutePath, `${block}\n`, "utf8");
144
+ return { action: "created", version, path: absolutePath };
145
+ }
146
+
147
+ const raw = readFileSync(absolutePath, "utf8");
148
+ const existing = findManagedSection(raw);
149
+
150
+ if (existing.found) {
151
+ const nextContent = `${raw.slice(0, existing.startIdx)}${block}${raw.slice(existing.endIdx)}`;
152
+ writeFileSync(absolutePath, nextContent, "utf8");
153
+ return {
154
+ action: "updated",
155
+ oldVersion: existing.version,
156
+ version,
157
+ path: absolutePath,
158
+ };
159
+ }
160
+
161
+ const omcEndIdx = raw.indexOf(OMC_END);
162
+ if (omcEndIdx !== -1) {
163
+ const insertAt = omcEndIdx + OMC_END.length;
164
+ const before = raw.slice(0, insertAt);
165
+ const after = raw.slice(insertAt);
166
+ const nextContent = `${before}\n${block}${after}`;
167
+ writeFileSync(absolutePath, nextContent, "utf8");
168
+ return { action: "inserted_after_omc", version, path: absolutePath };
169
+ }
170
+
171
+ const separator = raw.endsWith("\n") ? "" : "\n";
172
+ writeFileSync(absolutePath, `${raw}${separator}${block}\n`, "utf8");
173
+ return { action: "appended", version, path: absolutePath };
174
+ }
175
+
176
+ export function migrateClaudeMd(filePath, options = {}) {
177
+ const absolutePath = resolve(filePath);
178
+ if (!existsSync(absolutePath)) {
179
+ return { action: "no_file", removed: [], path: absolutePath };
180
+ }
181
+
182
+ const raw = readFileSync(absolutePath, "utf8");
183
+ const existing = findManagedSection(raw);
184
+ const legacy = detectLegacyRange(raw);
185
+
186
+ if (existing.found && !legacy.found) {
187
+ return {
188
+ action: "already_managed",
189
+ removed: [],
190
+ version: existing.version,
191
+ path: absolutePath,
192
+ };
193
+ }
194
+
195
+ const removed = [];
196
+ let nextContent = raw;
197
+
198
+ if (legacy.found && legacy.startIdx !== -1 && legacy.endIdx !== -1) {
199
+ nextContent = `${nextContent.slice(0, legacy.startIdx)}${nextContent.slice(legacy.endIdx)}`;
200
+ removed.push("<user_cli_routing> block");
201
+ }
202
+
203
+ const existingAfterLegacy = findManagedSection(nextContent);
204
+ if (existingAfterLegacy.found) {
205
+ nextContent = `${nextContent.slice(0, existingAfterLegacy.startIdx)}${nextContent.slice(existingAfterLegacy.endIdx)}`;
206
+ removed.push("old TFX block");
207
+ }
208
+
209
+ writeFileSync(absolutePath, normalizeSpacing(nextContent), "utf8");
210
+ const writeResult = writeSection(absolutePath, options);
211
+
212
+ return {
213
+ action: "migrated",
214
+ removed,
215
+ version: writeResult.version,
216
+ path: absolutePath,
217
+ };
218
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 요청별 로그 컨텍스트 전파 (AsyncLocalStorage 기반).
3
+ *
4
+ * Hub HTTP 서버의 요청마다 correlationId를 자동 할당하여,
5
+ * 하나의 요청에서 발생한 모든 로그를 추적할 수 있다.
6
+ *
7
+ * 사용법:
8
+ * import { getLogger, getCorrelationId, withRequestContext } from './lib/context.mjs';
9
+ *
10
+ * // 미들웨어에서 컨텍스트 생성
11
+ * withRequestContext({ method: 'POST', path: '/bridge/result' }, () => {
12
+ * const log = getLogger();
13
+ * log.info({ agentId }, 'bridge.result_received');
14
+ * });
15
+ *
16
+ * // 내부 함수에서 자동 상관 ID
17
+ * function processResult() {
18
+ * const log = getLogger();
19
+ * log.info('result.processed'); // correlationId 자동 포함
20
+ * }
21
+ */
22
+ import { AsyncLocalStorage } from 'node:async_hooks';
23
+ import { randomUUID } from 'node:crypto';
24
+
25
+ import { logger } from './logger.mjs';
26
+
27
+ /** @type {AsyncLocalStorage<{logger: import('pino').Logger, correlationId: string}>} */
28
+ export const asyncLocalStorage = new AsyncLocalStorage();
29
+
30
+ /**
31
+ * 현재 요청 컨텍스트의 로거를 반환한다.
32
+ * 요청 컨텍스트 밖에서 호출하면 기본 로거를 반환한다.
33
+ *
34
+ * @returns {import('pino').Logger}
35
+ */
36
+ export function getLogger() {
37
+ return asyncLocalStorage.getStore()?.logger || logger;
38
+ }
39
+
40
+ /**
41
+ * 현재 요청의 상관 ID를 반환한다.
42
+ *
43
+ * @returns {string|undefined}
44
+ */
45
+ export function getCorrelationId() {
46
+ return asyncLocalStorage.getStore()?.correlationId;
47
+ }
48
+
49
+ /**
50
+ * 요청 컨텍스트를 생성하고 콜백을 실행한다.
51
+ *
52
+ * @param {object} context — 컨텍스트 필드 (method, path 등)
53
+ * @param {string} [context.correlationId] — 외부에서 전달된 상관 ID (없으면 자동 생성)
54
+ * @param {function} callback — 컨텍스트 내에서 실행할 함수
55
+ * @returns {*}
56
+ */
57
+ export function withRequestContext(context, callback) {
58
+ const correlationId = context.correlationId || randomUUID();
59
+ const { correlationId: _, ...rest } = context;
60
+
61
+ const store = {
62
+ correlationId,
63
+ logger: logger.child({ correlationId, ...rest }),
64
+ };
65
+
66
+ return asyncLocalStorage.run(store, callback);
67
+ }
@@ -0,0 +1,51 @@
1
+ import { join } from "node:path";
2
+
3
+ export const SESSION_TTL_SEC = 30 * 60;
4
+ export const STATE_REL_PATH = join(".omc", "state", "cross-review.json");
5
+
6
+ export function readStdin() {
7
+ return new Promise((resolve) => {
8
+ let raw = "";
9
+ process.stdin.setEncoding("utf8");
10
+ process.stdin.on("data", (chunk) => {
11
+ raw += chunk;
12
+ });
13
+ process.stdin.on("end", () => resolve(raw));
14
+ process.stdin.on("error", () => resolve(""));
15
+ });
16
+ }
17
+
18
+ export function parseJson(raw) {
19
+ try {
20
+ return JSON.parse(raw);
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+
26
+ export function nowSec() {
27
+ return Math.floor(Date.now() / 1000);
28
+ }
29
+
30
+ export function resolveBaseDir(payload) {
31
+ if (typeof payload?.cwd === "string" && payload.cwd.trim()) return payload.cwd;
32
+ if (typeof payload?.directory === "string" && payload.directory.trim()) return payload.directory;
33
+ return process.cwd();
34
+ }
35
+
36
+ export function shouldTrackPath(filePath) {
37
+ if (typeof filePath !== "string" || !filePath.trim()) return false;
38
+
39
+ const lower = filePath.toLowerCase();
40
+ if (lower.startsWith(".omc/") || lower.startsWith(".claude/")) return false;
41
+ if (lower === "package-lock.json" || lower.endsWith("/package-lock.json")) return false;
42
+ if (/\.(md|lock|yml|yaml)$/i.test(lower)) return false;
43
+ return true;
44
+ }
45
+
46
+ export function expectedReviewer(author) {
47
+ if (author === "claude") return "codex";
48
+ if (author === "codex") return "claude";
49
+ if (author === "gemini") return "claude";
50
+ return "";
51
+ }
@@ -0,0 +1,241 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join, dirname } from "node:path";
3
+ import { homedir } from "node:os";
4
+ import { execSync, spawn } from "node:child_process";
5
+ import { fileURLToPath } from "node:url";
6
+ import { createHash } from "node:crypto";
7
+ import { whichCommand, whichCommandAsync } from "../../hub/platform.mjs";
8
+
9
+ const DEFAULT_STATUS_URL = "http://127.0.0.1:27888/status";
10
+ const _sab = new Int32Array(new SharedArrayBuffer(4));
11
+ const CLI_PROBE_CACHE = new Map();
12
+ const CLI_PROBE_PROMISES = new Map();
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const DEFAULT_PKG_ROOT = join(dirname(__filename), "..", "..");
16
+
17
+ function sleepSync(ms) {
18
+ Atomics.wait(_sab, 0, 0, ms);
19
+ }
20
+
21
+ function fetchHubStatus({
22
+ execSyncFn = execSync,
23
+ statusUrl = DEFAULT_STATUS_URL,
24
+ timeout = 3000,
25
+ } = {}) {
26
+ const response = execSyncFn(`curl -sf ${statusUrl}`, {
27
+ timeout,
28
+ encoding: "utf8",
29
+ windowsHide: true,
30
+ });
31
+ const data = JSON.parse(response);
32
+ return {
33
+ ok: true,
34
+ state: data?.hub?.state || "unknown",
35
+ pid: data?.pid,
36
+ };
37
+ }
38
+
39
+ function normalizeCliName(name) {
40
+ return String(name ?? "").trim() || null;
41
+ }
42
+
43
+ function toCliResult(path) {
44
+ return path ? { ok: true, path } : { ok: false };
45
+ }
46
+
47
+ function cloneCliResult(result) {
48
+ return result?.ok ? { ...result } : { ok: false };
49
+ }
50
+
51
+ function readCachedCliResult(name) {
52
+ const cached = CLI_PROBE_CACHE.get(name);
53
+ return cached ? cloneCliResult(cached) : null;
54
+ }
55
+
56
+ function storeCliResult(name, result) {
57
+ const snapshot = cloneCliResult(result);
58
+ CLI_PROBE_CACHE.set(name, snapshot);
59
+ return cloneCliResult(snapshot);
60
+ }
61
+
62
+ function buildCliProbeOptions(options = {}) {
63
+ return {
64
+ timeout: options.timeout ?? 2000,
65
+ env: options.env,
66
+ cwd: options.cwd,
67
+ platform: options.platform,
68
+ };
69
+ }
70
+
71
+ function normalizeCliNames(names) {
72
+ return [...new Set((names || []).map(normalizeCliName).filter(Boolean))];
73
+ }
74
+
75
+ function mapCliResults(names, results) {
76
+ return names.reduce((acc, name, index) => ({
77
+ ...acc,
78
+ [name]: results[index],
79
+ }), {});
80
+ }
81
+
82
+ async function resolveCliProbe(name, options = {}) {
83
+ const path = await (options.whichCommandAsyncFn || whichCommandAsync)(name, {
84
+ ...buildCliProbeOptions(options),
85
+ execFileFn: options.execFileFn,
86
+ });
87
+ return toCliResult(path);
88
+ }
89
+
90
+ export async function checkCli(name, options = {}) {
91
+ const cliName = normalizeCliName(name);
92
+ if (!cliName) return { ok: false };
93
+
94
+ const cached = readCachedCliResult(cliName);
95
+ if (cached) return cached;
96
+
97
+ const pending = CLI_PROBE_PROMISES.get(cliName);
98
+ if (pending) return pending.then(cloneCliResult);
99
+
100
+ const nextProbe = resolveCliProbe(cliName, options)
101
+ .then((result) => storeCliResult(cliName, result))
102
+ .catch(() => storeCliResult(cliName, { ok: false }))
103
+ .finally(() => {
104
+ CLI_PROBE_PROMISES.delete(cliName);
105
+ });
106
+
107
+ CLI_PROBE_PROMISES.set(cliName, nextProbe);
108
+ return nextProbe.then(cloneCliResult);
109
+ }
110
+
111
+ export function checkCliSync(name, options = {}) {
112
+ const cliName = normalizeCliName(name);
113
+ if (!cliName) return { ok: false };
114
+
115
+ const cached = readCachedCliResult(cliName);
116
+ if (cached) return cached;
117
+
118
+ const path = (options.whichCommandFn || whichCommand)(cliName, buildCliProbeOptions(options));
119
+ return storeCliResult(cliName, toCliResult(path));
120
+ }
121
+
122
+ export async function probeClis(names, options = {}) {
123
+ const cliNames = normalizeCliNames(names);
124
+ const results = await Promise.all(cliNames.map((name) => checkCli(name, options)));
125
+ return mapCliResults(cliNames, results);
126
+ }
127
+
128
+ export function resetCliProbeCache() {
129
+ CLI_PROBE_CACHE.clear();
130
+ CLI_PROBE_PROMISES.clear();
131
+ }
132
+
133
+ export function detectCodexAuthState({
134
+ homeDir = homedir(),
135
+ existsSyncFn = existsSync,
136
+ readFileSyncFn = readFileSync,
137
+ } = {}) {
138
+ try {
139
+ const authPath = join(homeDir, ".codex", "auth.json");
140
+ if (!existsSyncFn(authPath)) return { plan: "unknown", source: "no_auth", fingerprint: "no_auth" };
141
+
142
+ const auth = JSON.parse(readFileSyncFn(authPath, "utf8"));
143
+ if (auth.auth_mode !== "chatgpt") {
144
+ const fingerprint = createHash("sha256")
145
+ .update(JSON.stringify({
146
+ auth_mode: auth.auth_mode || "api_key",
147
+ has_api_key: Boolean(auth.api_key || auth.apiKey),
148
+ }))
149
+ .digest("hex");
150
+ return { plan: "api", source: "api_key", fingerprint };
151
+ }
152
+
153
+ const token = auth.tokens?.id_token || auth.tokens?.access_token;
154
+ if (!token) {
155
+ return {
156
+ plan: "unknown",
157
+ source: "no_token",
158
+ fingerprint: createHash("sha256")
159
+ .update(JSON.stringify({ auth_mode: auth.auth_mode || "chatgpt", token: null }))
160
+ .digest("hex"),
161
+ };
162
+ }
163
+
164
+ const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64url").toString());
165
+ const plan = payload?.["https://api.openai.com/auth"]?.chatgpt_plan_type || "unknown";
166
+ const fingerprint = createHash("sha256")
167
+ .update(JSON.stringify({
168
+ auth_mode: auth.auth_mode || "chatgpt",
169
+ plan,
170
+ sub: payload?.sub || null,
171
+ exp: payload?.exp || null,
172
+ }))
173
+ .digest("hex");
174
+ return { plan, source: "jwt", fingerprint };
175
+ } catch {
176
+ return { plan: "unknown", source: "error", fingerprint: "error" };
177
+ }
178
+ }
179
+
180
+ export function detectCodexPlan(options = {}) {
181
+ const { plan, source } = detectCodexAuthState(options);
182
+ return { plan, source };
183
+ }
184
+
185
+ export function checkHub({
186
+ pkgRoot = DEFAULT_PKG_ROOT,
187
+ statusUrl = DEFAULT_STATUS_URL,
188
+ restart = true,
189
+ requestTimeoutMs = 3000,
190
+ pollAttempts = 8,
191
+ pollIntervalMs = 500,
192
+ execSyncFn = execSync,
193
+ spawnFn = spawn,
194
+ existsSyncFn = existsSync,
195
+ sleepSyncFn = sleepSync,
196
+ } = {}) {
197
+ try {
198
+ return fetchHubStatus({
199
+ execSyncFn,
200
+ statusUrl,
201
+ timeout: requestTimeoutMs,
202
+ });
203
+ } catch {}
204
+
205
+ if (!restart) return { ok: false, state: "unreachable", restart: "disabled" };
206
+
207
+ const serverPath = join(pkgRoot, "hub", "server.mjs");
208
+ if (!existsSyncFn(serverPath)) return { ok: false, state: "unreachable", restart: "no_server" };
209
+
210
+ try {
211
+ const child = spawnFn(process.execPath, [serverPath], {
212
+ detached: true,
213
+ stdio: "ignore",
214
+ windowsHide: true,
215
+ });
216
+ child.unref();
217
+ } catch {
218
+ return { ok: false, state: "unreachable", restart: "spawn_failed" };
219
+ }
220
+
221
+ for (let i = 0; i < pollAttempts; i++) {
222
+ sleepSyncFn(pollIntervalMs);
223
+ try {
224
+ const status = fetchHubStatus({
225
+ execSyncFn,
226
+ statusUrl,
227
+ timeout: Math.min(requestTimeoutMs, 1000),
228
+ });
229
+ if (status.state === "healthy") {
230
+ return { ...status, restarted: true };
231
+ }
232
+ } catch {}
233
+ }
234
+
235
+ return { ok: false, state: "unreachable", restart: "timeout" };
236
+ }
237
+
238
+ export {
239
+ DEFAULT_PKG_ROOT,
240
+ DEFAULT_STATUS_URL,
241
+ };
@@ -0,0 +1,85 @@
1
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ const DEFAULT_GEMINI_PROFILES = {
6
+ model: "gemini-3.1-pro-preview",
7
+ profiles: {
8
+ pro31: { model: "gemini-3.1-pro-preview", hint: "3.1 Pro — 플래그십 (1M ctx, 멀티모달)" },
9
+ flash3: { model: "gemini-3-flash-preview", hint: "3.0 Flash — 빠른 응답, 비용 효율" },
10
+ pro25: { model: "gemini-2.5-pro", hint: "2.5 Pro — 안정 (추론 강화)" },
11
+ flash25: { model: "gemini-2.5-flash", hint: "2.5 Flash — 경량 범용" },
12
+ lite25: { model: "gemini-2.5-flash-lite", hint: "2.5 Flash Lite — 최경량" },
13
+ },
14
+ };
15
+
16
+ const DEFAULT_PROFILE_COUNT = Object.keys(DEFAULT_GEMINI_PROFILES.profiles).length;
17
+
18
+ function ensureGeminiProfiles({
19
+ geminiDir = join(homedir(), ".gemini"),
20
+ profilesPath = join(geminiDir, "triflux-profiles.json"),
21
+ } = {}) {
22
+ try {
23
+ if (!existsSync(geminiDir)) mkdirSync(geminiDir, { recursive: true });
24
+
25
+ if (!existsSync(profilesPath)) {
26
+ writeFileSync(profilesPath, JSON.stringify(DEFAULT_GEMINI_PROFILES, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
27
+ return {
28
+ ok: true,
29
+ created: true,
30
+ added: DEFAULT_PROFILE_COUNT,
31
+ count: DEFAULT_PROFILE_COUNT,
32
+ message: null,
33
+ };
34
+ }
35
+
36
+ let cfg;
37
+ try {
38
+ cfg = JSON.parse(readFileSync(profilesPath, "utf8"));
39
+ } catch {
40
+ try { copyFileSync(profilesPath, profilesPath + `.bak.${Date.now()}`); } catch {}
41
+ writeFileSync(profilesPath, JSON.stringify(DEFAULT_GEMINI_PROFILES, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
42
+ return {
43
+ ok: true,
44
+ created: true,
45
+ added: DEFAULT_PROFILE_COUNT,
46
+ count: DEFAULT_PROFILE_COUNT,
47
+ message: null,
48
+ };
49
+ }
50
+
51
+ if (!cfg || typeof cfg !== "object" || Array.isArray(cfg)) cfg = {};
52
+ if (!cfg.profiles || typeof cfg.profiles !== "object" || Array.isArray(cfg.profiles)) cfg.profiles = {};
53
+
54
+ let added = 0;
55
+ for (const [name, value] of Object.entries(DEFAULT_GEMINI_PROFILES.profiles)) {
56
+ if (!cfg.profiles[name]) {
57
+ cfg.profiles[name] = value;
58
+ added++;
59
+ }
60
+ }
61
+ if (!cfg.model) cfg.model = DEFAULT_GEMINI_PROFILES.model;
62
+
63
+ if (added > 0) {
64
+ writeFileSync(profilesPath, JSON.stringify(cfg, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
65
+ }
66
+
67
+ return {
68
+ ok: true,
69
+ created: false,
70
+ added,
71
+ count: Object.keys(cfg.profiles).length,
72
+ message: null,
73
+ };
74
+ } catch (error) {
75
+ return {
76
+ ok: false,
77
+ created: false,
78
+ added: 0,
79
+ count: 0,
80
+ message: error.message,
81
+ };
82
+ }
83
+ }
84
+
85
+ export { DEFAULT_GEMINI_PROFILES, ensureGeminiProfiles };