@monoes/monomindcli 2.16.4 → 2.16.5

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 (412) hide show
  1. package/.claude/agents/github/repo-architect.md +1 -1
  2. package/.claude/agents/specialists/integration-architect.md +9 -13
  3. package/.claude/commands/agents/agent-capabilities.md +1 -0
  4. package/.claude/commands/agents/agent-coordination.md +1 -0
  5. package/.claude/commands/agents/agent-spawning.md +1 -0
  6. package/.claude/commands/agents/agent-types.md +1 -0
  7. package/.claude/commands/analysis/bottleneck-detect.md +1 -0
  8. package/.claude/commands/analysis/performance-bottlenecks.md +1 -0
  9. package/.claude/commands/analysis/performance-report.md +1 -0
  10. package/.claude/commands/analysis/token-usage.md +1 -0
  11. package/.claude/commands/automation/README.md +1 -1
  12. package/.claude/commands/automation/auto-agent.md +1 -0
  13. package/.claude/commands/automation/self-healing.md +1 -0
  14. package/.claude/commands/automation/session-memory.md +1 -0
  15. package/.claude/commands/automation/smart-agents.md +1 -0
  16. package/.claude/commands/automation/smart-spawn.md +1 -0
  17. package/.claude/commands/automation/workflow-select.md +22 -27
  18. package/.claude/commands/coordination/README.md +2 -2
  19. package/.claude/commands/coordination/agent-spawn.md +1 -0
  20. package/.claude/commands/coordination/monoswarm-init.md +9 -8
  21. package/.claude/commands/coordination/task-orchestrate.md +6 -5
  22. package/.claude/commands/github/README.md +1 -1
  23. package/.claude/commands/github/github-modes.md +1 -0
  24. package/.claude/commands/github/issue-tracker.md +1 -0
  25. package/.claude/commands/github/pr-manager.md +1 -0
  26. package/.claude/commands/github/release-manager.md +1 -2
  27. package/.claude/commands/github/repo-architect.md +1 -0
  28. package/.claude/commands/github/sync-coordinator.md +1 -0
  29. package/.claude/commands/hooks/overview.md +1 -0
  30. package/.claude/commands/hooks/post-edit.md +1 -0
  31. package/.claude/commands/hooks/post-task.md +1 -0
  32. package/.claude/commands/hooks/pre-edit.md +1 -0
  33. package/.claude/commands/hooks/pre-task.md +1 -0
  34. package/.claude/commands/hooks/session-end.md +1 -0
  35. package/.claude/commands/hooks/setup.md +1 -0
  36. package/.claude/commands/mastermind/adr.md +3 -1
  37. package/.claude/commands/mastermind/brain.md +3 -1
  38. package/.claude/commands/mastermind/budget.md +3 -1
  39. package/.claude/commands/mastermind/code-review.md +3 -1
  40. package/.claude/commands/mastermind/content.md +3 -1
  41. package/.claude/commands/mastermind/createorg.md +3 -1
  42. package/.claude/commands/mastermind/createtask.md +6 -4
  43. package/.claude/commands/mastermind/debug.md +3 -1
  44. package/.claude/commands/mastermind/design.md +3 -1
  45. package/.claude/commands/mastermind/do.md +5 -3
  46. package/.claude/commands/mastermind/execute.md +3 -1
  47. package/.claude/commands/mastermind/finance.md +3 -1
  48. package/.claude/commands/mastermind/graph-status.md +3 -1
  49. package/.claude/commands/mastermind/help.md +12 -9
  50. package/.claude/commands/mastermind/idea.md +3 -1
  51. package/.claude/commands/mastermind/ideate.md +4 -2
  52. package/.claude/commands/mastermind/improve.md +4 -2
  53. package/.claude/commands/mastermind/loops.md +3 -1
  54. package/.claude/commands/mastermind/marketing.md +3 -1
  55. package/.claude/commands/mastermind/master.md +3 -1
  56. package/.claude/commands/mastermind/memory.md +8 -36
  57. package/.claude/commands/mastermind/monoswarm.md +3 -2
  58. package/.claude/commands/mastermind/okf-export.md +3 -1
  59. package/.claude/commands/mastermind/okf-import.md +3 -1
  60. package/.claude/commands/mastermind/ops.md +3 -1
  61. package/.claude/commands/mastermind/orgs.md +3 -1
  62. package/.claude/commands/mastermind/orgstatus.md +3 -1
  63. package/.claude/commands/mastermind/plan.md +3 -1
  64. package/.claude/commands/mastermind/receive-review.md +3 -1
  65. package/.claude/commands/mastermind/release.md +3 -1
  66. package/.claude/commands/mastermind/repeat.md +3 -1
  67. package/.claude/commands/mastermind/research.md +3 -1
  68. package/.claude/commands/mastermind/review.md +3 -1
  69. package/.claude/commands/mastermind/runorg.md +3 -1
  70. package/.claude/commands/mastermind/sales.md +3 -1
  71. package/.claude/commands/mastermind/skill-builder.md +3 -1
  72. package/.claude/commands/mastermind/specialagents.md +3 -1
  73. package/.claude/commands/mastermind/stoporg.md +3 -1
  74. package/.claude/commands/mastermind/techport.md +3 -1
  75. package/.claude/commands/mastermind/topology.md +4 -3
  76. package/.claude/commands/mastermind/understand.md +3 -1
  77. package/.claude/commands/mastermind/worktree.md +3 -1
  78. package/.claude/commands/memory/memory-search.md +1 -0
  79. package/.claude/commands/monitoring/README.md +1 -1
  80. package/.claude/commands/monitoring/agent-metrics.md +1 -0
  81. package/.claude/commands/monitoring/agents.md +1 -0
  82. package/.claude/commands/monitoring/status.md +1 -0
  83. package/.claude/commands/monoswarm/README.md +3 -3
  84. package/.claude/commands/monoswarm/analysis.md +2 -2
  85. package/.claude/commands/monoswarm/consensus.md +1 -0
  86. package/.claude/commands/monoswarm/development.md +3 -3
  87. package/.claude/commands/monoswarm/examples.md +4 -4
  88. package/.claude/commands/monoswarm/init.md +2 -1
  89. package/.claude/commands/monoswarm/maintenance.md +2 -2
  90. package/.claude/commands/monoswarm/memory.md +1 -0
  91. package/.claude/commands/monoswarm/monoswarm.md +5 -5
  92. package/.claude/commands/monoswarm/optimization.md +2 -2
  93. package/.claude/commands/monoswarm/research.md +2 -2
  94. package/.claude/commands/monoswarm/spawn.md +1 -0
  95. package/.claude/commands/monoswarm/status.md +2 -1
  96. package/.claude/commands/monoswarm/stop.md +2 -1
  97. package/.claude/commands/monoswarm/testing.md +2 -2
  98. package/.claude/commands/pair/README.md +8 -9
  99. package/.claude/commands/pair/examples.md +3 -4
  100. package/.claude/commands/pair/session.md +1 -1
  101. package/.claude/commands/workflows/README.md +45 -40
  102. package/.claude/commands/workflows/development.md +42 -55
  103. package/.claude/commands/workflows/research.md +41 -57
  104. package/.claude/commands/workflows/workflow-create.md +43 -45
  105. package/.claude/commands/workflows/workflow-execute.md +58 -68
  106. package/.claude/commands/workflows/workflow-export.md +37 -63
  107. package/.claude/helpers/build-skill-registry.cjs +10 -6
  108. package/.claude/helpers/handlers/pick-core.cjs +35 -24
  109. package/.claude/helpers/handlers/route-handler.cjs +11 -3
  110. package/.claude/helpers/hook-handler.cjs +4 -2
  111. package/.claude/helpers/jev-catalog.cjs +7 -3
  112. package/.claude/helpers/jev-picker.cjs +49 -7
  113. package/.claude/helpers/pick-rank.cjs +95 -3
  114. package/.claude/helpers/pick-stats.cjs +86 -2
  115. package/.claude/skills/agentic-jujutsu/SKILL.md +2 -3
  116. package/.claude/skills/github-toolkit/SKILL.md +1 -1
  117. package/.claude/skills/hooks-automation/SKILL.md +243 -938
  118. package/.claude/skills/mastermind-agent-detail/SKILL.md +1 -1
  119. package/.claude/skills/mastermind-agent-select/SKILL.md +16 -1
  120. package/.claude/skills/mastermind-inbox/SKILL.md +1 -1
  121. package/.claude/skills/mastermind-plugins/SKILL.md +1 -1
  122. package/.claude/skills/mastermind-release/SKILL.md +9 -1
  123. package/.claude/skills/mastermind-research/SKILL.md +9 -1
  124. package/.claude/skills/mastermind-review/SKILL.md +9 -1
  125. package/.claude/skills/mastermind-routine-detail/SKILL.md +1 -1
  126. package/.claude/skills/monodesign/SKILL.md +257 -0
  127. package/.claude/skills/monodesign/adapt.md +53 -0
  128. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +100 -0
  129. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +103 -0
  130. package/.claude/skills/monodesign/animate.md +65 -0
  131. package/.claude/skills/monodesign/audit.md +89 -0
  132. package/.claude/skills/monodesign/bolder.md +50 -0
  133. package/.claude/skills/monodesign/clarify.md +64 -0
  134. package/.claude/skills/monodesign/colorize.md +68 -0
  135. package/.claude/skills/monodesign/craft.md +51 -0
  136. package/.claude/skills/monodesign/critique.md +66 -0
  137. package/.claude/skills/monodesign/delight.md +47 -0
  138. package/.claude/skills/monodesign/distill.md +56 -0
  139. package/.claude/skills/monodesign/document.md +83 -0
  140. package/.claude/skills/monodesign/extract.md +74 -0
  141. package/.claude/skills/monodesign/harden.md +65 -0
  142. package/.claude/skills/monodesign/init.md +30 -0
  143. package/.claude/skills/monodesign/layout.md +36 -0
  144. package/.claude/skills/monodesign/live.md +34 -0
  145. package/.claude/skills/monodesign/onboard.md +50 -0
  146. package/.claude/skills/monodesign/optimize.md +64 -0
  147. package/.claude/skills/monodesign/overdrive.md +56 -0
  148. package/.claude/skills/monodesign/polish.md +68 -0
  149. package/.claude/skills/monodesign/quieter.md +57 -0
  150. package/.claude/skills/monodesign/reference/adapt.md +312 -0
  151. package/.claude/skills/monodesign/reference/adapt.native.md +58 -0
  152. package/.claude/skills/monodesign/reference/android.md +40 -0
  153. package/.claude/skills/monodesign/reference/animate.md +203 -0
  154. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +410 -0
  155. package/.claude/skills/monodesign/reference/audit.md +135 -0
  156. package/.claude/skills/monodesign/reference/audit.native.md +139 -0
  157. package/.claude/skills/monodesign/reference/bolder.md +120 -0
  158. package/.claude/skills/monodesign/reference/brand-workflow.md +180 -0
  159. package/.claude/skills/monodesign/reference/brand.md +108 -0
  160. package/.claude/skills/monodesign/reference/clarify.md +288 -0
  161. package/.claude/skills/monodesign/reference/codex.md +105 -0
  162. package/.claude/skills/monodesign/reference/cognitive-load.md +106 -0
  163. package/.claude/skills/monodesign/reference/color-and-contrast.md +105 -0
  164. package/.claude/skills/monodesign/reference/colorize.md +257 -0
  165. package/.claude/skills/monodesign/reference/component-specs.md +260 -0
  166. package/.claude/skills/monodesign/reference/component-states.md +274 -0
  167. package/.claude/skills/monodesign/reference/component-system.md +358 -0
  168. package/.claude/skills/monodesign/reference/copy-formulas.md +160 -0
  169. package/.claude/skills/monodesign/reference/craft.md +123 -0
  170. package/.claude/skills/monodesign/reference/critique.md +780 -0
  171. package/.claude/skills/monodesign/reference/delight.md +302 -0
  172. package/.claude/skills/monodesign/reference/design-principles.md +246 -0
  173. package/.claude/skills/monodesign/reference/distill.md +111 -0
  174. package/.claude/skills/monodesign/reference/document.md +429 -0
  175. package/.claude/skills/monodesign/reference/extract.md +69 -0
  176. package/.claude/skills/monodesign/reference/harden.md +347 -0
  177. package/.claude/skills/monodesign/reference/heuristics-scoring.md +234 -0
  178. package/.claude/skills/monodesign/reference/hooks.md +92 -0
  179. package/.claude/skills/monodesign/reference/image-prompts.md +130 -0
  180. package/.claude/skills/monodesign/reference/init.md +221 -0
  181. package/.claude/skills/monodesign/reference/interaction-design.md +189 -0
  182. package/.claude/skills/monodesign/reference/ios.md +45 -0
  183. package/.claude/skills/monodesign/reference/layout.md +185 -0
  184. package/.claude/skills/monodesign/reference/live.md +710 -0
  185. package/.claude/skills/monodesign/reference/motion-design.md +109 -0
  186. package/.claude/skills/monodesign/reference/onboard.md +234 -0
  187. package/.claude/skills/monodesign/reference/optimize.md +258 -0
  188. package/.claude/skills/monodesign/reference/overdrive.md +130 -0
  189. package/.claude/skills/monodesign/reference/personas.md +179 -0
  190. package/.claude/skills/monodesign/reference/polish.md +241 -0
  191. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +108 -0
  192. package/.claude/skills/monodesign/reference/product.md +60 -0
  193. package/.claude/skills/monodesign/reference/quieter.md +99 -0
  194. package/.claude/skills/monodesign/reference/responsive-design.md +114 -0
  195. package/.claude/skills/monodesign/reference/shape.md +165 -0
  196. package/.claude/skills/monodesign/reference/spatial-design.md +100 -0
  197. package/.claude/skills/monodesign/reference/teach.md +10 -0
  198. package/.claude/skills/monodesign/reference/token-architecture.md +222 -0
  199. package/.claude/skills/monodesign/reference/typeset.md +301 -0
  200. package/.claude/skills/monodesign/reference/typography.md +159 -0
  201. package/.claude/skills/monodesign/reference/ux-research.md +143 -0
  202. package/.claude/skills/monodesign/reference/ux-rules.md +211 -0
  203. package/.claude/skills/monodesign/reference/ux-writing.md +107 -0
  204. package/.claude/skills/monodesign/scripts/command-metadata.json +94 -0
  205. package/.claude/skills/monodesign/scripts/context-signals.mjs +260 -0
  206. package/.claude/skills/monodesign/scripts/context.mjs +1065 -0
  207. package/.claude/skills/monodesign/scripts/critique-storage.mjs +416 -0
  208. package/.claude/skills/monodesign/scripts/detect-csp.mjs +193 -0
  209. package/.claude/skills/monodesign/scripts/detect.mjs +33 -0
  210. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +1960 -0
  211. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +321 -0
  212. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +814 -0
  213. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +5628 -0
  214. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +50 -0
  215. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +259 -0
  216. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +339 -0
  217. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +636 -0
  218. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +1016 -0
  219. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +253 -0
  220. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +198 -0
  221. package/.claude/skills/monodesign/scripts/detector/findings.mjs +12 -0
  222. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +181 -0
  223. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +373 -0
  224. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +426 -0
  225. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +198 -0
  226. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +166 -0
  227. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +563 -0
  228. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +3024 -0
  229. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +124 -0
  230. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +101 -0
  231. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +30 -0
  232. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +148 -0
  233. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +7 -0
  234. package/.claude/skills/monodesign/scripts/hook-admin.mjs +694 -0
  235. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +516 -0
  236. package/.claude/skills/monodesign/scripts/hook-lib.mjs +1785 -0
  237. package/.claude/skills/monodesign/scripts/hook.mjs +61 -0
  238. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +809 -0
  239. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +69 -0
  240. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +640 -0
  241. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +129 -0
  242. package/.claude/skills/monodesign/scripts/lib/provider.mjs +4 -0
  243. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +42 -0
  244. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +50 -0
  245. package/.claude/skills/monodesign/scripts/live/completion.mjs +19 -0
  246. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +137 -0
  247. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +458 -0
  248. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +939 -0
  249. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +357 -0
  250. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +152 -0
  251. package/.claude/skills/monodesign/scripts/live/session-store.mjs +293 -0
  252. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +826 -0
  253. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +279 -0
  254. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +180 -0
  255. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +36 -0
  256. package/.claude/skills/monodesign/scripts/live-accept.mjs +812 -0
  257. package/.claude/skills/monodesign/scripts/live-browser-dom.js +147 -0
  258. package/.claude/skills/monodesign/scripts/live-browser-session.js +124 -0
  259. package/.claude/skills/monodesign/scripts/live-browser.js +11213 -0
  260. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +1241 -0
  261. package/.claude/skills/monodesign/scripts/live-complete.mjs +75 -0
  262. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +683 -0
  263. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +51 -0
  264. package/.claude/skills/monodesign/scripts/live-inject.mjs +596 -0
  265. package/.claude/skills/monodesign/scripts/live-insert.mjs +272 -0
  266. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +363 -0
  267. package/.claude/skills/monodesign/scripts/live-poll.mjs +384 -0
  268. package/.claude/skills/monodesign/scripts/live-resume.mjs +94 -0
  269. package/.claude/skills/monodesign/scripts/live-server.mjs +1210 -0
  270. package/.claude/skills/monodesign/scripts/live-status.mjs +61 -0
  271. package/.claude/skills/monodesign/scripts/live-target.mjs +30 -0
  272. package/.claude/skills/monodesign/scripts/live-wrap.mjs +884 -0
  273. package/.claude/skills/monodesign/scripts/live.mjs +297 -0
  274. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +14 -0
  275. package/.claude/skills/monodesign/scripts/palette.mjs +635 -0
  276. package/.claude/skills/monodesign/scripts/pin.mjs +221 -0
  277. package/.claude/skills/monodesign/shape.md +71 -0
  278. package/.claude/skills/monodesign/teach.md +18 -0
  279. package/.claude/skills/monodesign/typeset.md +59 -0
  280. package/.claude/skills/monolean-audit/SKILL.md +4 -6
  281. package/.claude/skills/monolean-help/SKILL.md +0 -1
  282. package/.claude/skills/monoswarm/SKILL.md +17 -17
  283. package/.claude/skills/pair-programming/SKILL.md +127 -1100
  284. package/README.md +1 -1
  285. package/dist/src/agents/registry-builder.d.ts +1 -1
  286. package/dist/src/commands/doctor-pick-checks.d.ts +20 -3
  287. package/dist/src/commands/doctor-pick-checks.d.ts.map +1 -1
  288. package/dist/src/commands/doctor-pick-checks.js +132 -7
  289. package/dist/src/commands/doctor-pick-checks.js.map +1 -1
  290. package/dist/src/commands/doctor-project-checks.d.ts +2 -2
  291. package/dist/src/commands/doctor-project-checks.d.ts.map +1 -1
  292. package/dist/src/commands/doctor-project-checks.js +14 -12
  293. package/dist/src/commands/doctor-project-checks.js.map +1 -1
  294. package/dist/src/commands/doctor.d.ts.map +1 -1
  295. package/dist/src/commands/doctor.js +6 -4
  296. package/dist/src/commands/doctor.js.map +1 -1
  297. package/dist/src/commands/init-upgrade.d.ts.map +1 -1
  298. package/dist/src/commands/init-upgrade.js +6 -0
  299. package/dist/src/commands/init-upgrade.js.map +1 -1
  300. package/dist/src/commands/init.d.ts.map +1 -1
  301. package/dist/src/commands/init.js +11 -0
  302. package/dist/src/commands/init.js.map +1 -1
  303. package/dist/src/commands/pick.d.ts.map +1 -1
  304. package/dist/src/commands/pick.js +4 -3
  305. package/dist/src/commands/pick.js.map +1 -1
  306. package/dist/src/decision/jev.d.ts +16 -0
  307. package/dist/src/decision/jev.d.ts.map +1 -1
  308. package/dist/src/decision/jev.js +12 -0
  309. package/dist/src/decision/jev.js.map +1 -1
  310. package/dist/src/decision/pick-eval.d.ts +23 -0
  311. package/dist/src/decision/pick-eval.d.ts.map +1 -1
  312. package/dist/src/decision/pick-eval.js +24 -1
  313. package/dist/src/decision/pick-eval.js.map +1 -1
  314. package/dist/src/decision/picks.d.ts +5 -0
  315. package/dist/src/decision/picks.d.ts.map +1 -1
  316. package/dist/src/decision/picks.js +33 -11
  317. package/dist/src/decision/picks.js.map +1 -1
  318. package/dist/src/init/claudemd-generator.d.ts.map +1 -1
  319. package/dist/src/init/claudemd-generator.js +1 -0
  320. package/dist/src/init/claudemd-generator.js.map +1 -1
  321. package/dist/src/init/copy-assets.d.ts.map +1 -1
  322. package/dist/src/init/copy-assets.js +17 -9
  323. package/dist/src/init/copy-assets.js.map +1 -1
  324. package/dist/src/init/executor.d.ts.map +1 -1
  325. package/dist/src/init/executor.js +26 -4
  326. package/dist/src/init/executor.js.map +1 -1
  327. package/dist/src/init/file-guard.d.ts +93 -0
  328. package/dist/src/init/file-guard.d.ts.map +1 -0
  329. package/dist/src/init/file-guard.js +239 -0
  330. package/dist/src/init/file-guard.js.map +1 -0
  331. package/dist/src/init/helpers-generator.d.ts +7 -0
  332. package/dist/src/init/helpers-generator.d.ts.map +1 -1
  333. package/dist/src/init/helpers-generator.js +9 -0
  334. package/dist/src/init/helpers-generator.js.map +1 -1
  335. package/dist/src/init/init-memory.d.ts +10 -0
  336. package/dist/src/init/init-memory.d.ts.map +1 -1
  337. package/dist/src/init/init-memory.js +44 -1
  338. package/dist/src/init/init-memory.js.map +1 -1
  339. package/dist/src/init/managed-block.d.ts +3 -1
  340. package/dist/src/init/managed-block.d.ts.map +1 -1
  341. package/dist/src/init/managed-block.js +9 -2
  342. package/dist/src/init/managed-block.js.map +1 -1
  343. package/dist/src/init/mcp-generator.d.ts +9 -0
  344. package/dist/src/init/mcp-generator.d.ts.map +1 -1
  345. package/dist/src/init/mcp-generator.js +28 -0
  346. package/dist/src/init/mcp-generator.js.map +1 -1
  347. package/dist/src/init/runtime-config-merge.d.ts +21 -0
  348. package/dist/src/init/runtime-config-merge.d.ts.map +1 -0
  349. package/dist/src/init/runtime-config-merge.js +88 -0
  350. package/dist/src/init/runtime-config-merge.js.map +1 -0
  351. package/dist/src/init/settings-generator.js +1 -1
  352. package/dist/src/init/settings-generator.js.map +1 -1
  353. package/dist/src/init/shared-instructions-generator.d.ts +3 -1
  354. package/dist/src/init/shared-instructions-generator.d.ts.map +1 -1
  355. package/dist/src/init/shared-instructions-generator.js +14 -39
  356. package/dist/src/init/shared-instructions-generator.js.map +1 -1
  357. package/dist/src/init/shared.d.ts +10 -0
  358. package/dist/src/init/shared.d.ts.map +1 -1
  359. package/dist/src/init/shared.js +32 -1
  360. package/dist/src/init/shared.js.map +1 -1
  361. package/dist/src/init/types.d.ts +9 -0
  362. package/dist/src/init/types.d.ts.map +1 -1
  363. package/dist/src/init/types.js.map +1 -1
  364. package/dist/src/init/upgrade.d.ts +4 -0
  365. package/dist/src/init/upgrade.d.ts.map +1 -1
  366. package/dist/src/init/upgrade.js +39 -42
  367. package/dist/src/init/upgrade.js.map +1 -1
  368. package/dist/src/init/write-antigravity.d.ts.map +1 -1
  369. package/dist/src/init/write-antigravity.js +9 -3
  370. package/dist/src/init/write-antigravity.js.map +1 -1
  371. package/dist/src/init/write-claude.d.ts.map +1 -1
  372. package/dist/src/init/write-claude.js +40 -19
  373. package/dist/src/init/write-claude.js.map +1 -1
  374. package/dist/src/init/write-kimicode.d.ts +27 -0
  375. package/dist/src/init/write-kimicode.d.ts.map +1 -1
  376. package/dist/src/init/write-kimicode.js +119 -92
  377. package/dist/src/init/write-kimicode.js.map +1 -1
  378. package/dist/src/init/write-opencode.d.ts.map +1 -1
  379. package/dist/src/init/write-opencode.js +45 -6
  380. package/dist/src/init/write-opencode.js.map +1 -1
  381. package/dist/src/init/write-runtime-config.d.ts.map +1 -1
  382. package/dist/src/init/write-runtime-config.js +108 -81
  383. package/dist/src/init/write-runtime-config.js.map +1 -1
  384. package/dist/src/knowledge/eval/golden-set.js +0 -15
  385. package/dist/src/knowledge/eval/golden-set.js.map +1 -1
  386. package/dist/src/mcp-tools/org-skill-tools.d.ts.map +1 -1
  387. package/dist/src/mcp-tools/org-skill-tools.js +6 -2
  388. package/dist/src/mcp-tools/org-skill-tools.js.map +1 -1
  389. package/dist/src/mcp-tools/pick-tools.d.ts.map +1 -1
  390. package/dist/src/mcp-tools/pick-tools.js +13 -4
  391. package/dist/src/mcp-tools/pick-tools.js.map +1 -1
  392. package/dist/src/platform-adapters/merge.d.ts +4 -3
  393. package/dist/src/platform-adapters/merge.d.ts.map +1 -1
  394. package/dist/src/platform-adapters/merge.js +18 -8
  395. package/dist/src/platform-adapters/merge.js.map +1 -1
  396. package/dist/src/platform-adapters/mutation.d.ts +6 -1
  397. package/dist/src/platform-adapters/mutation.d.ts.map +1 -1
  398. package/dist/src/platform-adapters/mutation.js +9 -3
  399. package/dist/src/platform-adapters/mutation.js.map +1 -1
  400. package/dist/src/platform-adapters/operations.d.ts.map +1 -1
  401. package/dist/src/platform-adapters/operations.js +14 -6
  402. package/dist/src/platform-adapters/operations.js.map +1 -1
  403. package/dist/src/platform-adapters/types.d.ts +5 -0
  404. package/dist/src/platform-adapters/types.d.ts.map +1 -1
  405. package/dist/src/routing/agent-pick.d.ts +9 -7
  406. package/dist/src/routing/agent-pick.d.ts.map +1 -1
  407. package/dist/src/routing/agent-pick.js +17 -17
  408. package/dist/src/routing/agent-pick.js.map +1 -1
  409. package/dist/tsconfig.tsbuildinfo +1 -1
  410. package/package.json +6 -6
  411. package/.claude/skills/github-issue-triage/SKILL.md +0 -354
  412. package/.claude/skills/github-repo-recap/SKILL.md +0 -207
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Anti-Pattern Detector for Monodesign
5
+ * Copyright (c) 2026 Paul Bakaus
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ *
8
+ * Public API facade. Runtime engines live under cli/engine/engines/.
9
+ */
10
+
11
+ import { detectCli } from './cli/main.mjs';
12
+
13
+ export { ANTIPATTERNS, RULE_ENGINE_SUPPORT, getAntipattern, getRulesForCategory, getRuleEngineSupport } from './registry/antipatterns.mjs';
14
+ export { SAFE_TAGS, BORDER_SAFE_TAGS, OVERUSED_FONTS, GENERIC_FONTS, KNOWN_SERIF_FONTS } from './shared/constants.mjs';
15
+ export { isNeutralColor, parseRgb, relativeLuminance, contrastRatio, parseGradientColors, hasChroma, getHue, colorToHex } from './shared/color.mjs';
16
+ export { isFullPage } from './shared/page.mjs';
17
+ export {
18
+ checkElementBorders,
19
+ checkElementMotion,
20
+ checkElementGlow,
21
+ checkPageTypography,
22
+ checkPageLayout,
23
+ checkHtmlPatterns,
24
+ } from './rules/checks.mjs';
25
+ export { createDetectorProfile, summarizeDetectorProfile } from './profile/profiler.mjs';
26
+ export {
27
+ parseFrontmatter as parseDesignFrontmatter,
28
+ normalizeDesignSystem,
29
+ loadDesignSystemForCwd,
30
+ checkSourceDesignSystem,
31
+ collectStaticDesignSystemFindings,
32
+ } from './design-system.mjs';
33
+ export { detectHtml } from './engines/static-html/detect-html.mjs';
34
+ export { detectUrl, createBrowserDetector } from './engines/browser/detect-url.mjs';
35
+ export { detectText, extractStyleBlocks, extractCSSinJS } from './engines/regex/detect-text.mjs';
36
+ export {
37
+ walkDir,
38
+ SCANNABLE_EXTENSIONS,
39
+ SKIP_DIRS,
40
+ buildImportGraph,
41
+ resolveImport,
42
+ detectFrameworkConfig,
43
+ isPortListening,
44
+ FRAMEWORK_CONFIGS,
45
+ } from './node/file-system.mjs';
46
+ export { formatFindings, detectCli } from './cli/main.mjs';
47
+
48
+ const isMainModule = process.argv[1]?.endsWith('detect-antipatterns.mjs') ||
49
+ process.argv[1]?.endsWith('detect-antipatterns.mjs/');
50
+ if (isMainModule) detectCli();
@@ -0,0 +1,259 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import { finding } from '../../findings.mjs';
6
+ import { filterByProviders } from '../../registry/antipatterns.mjs';
7
+ import { profileFindingsAsync, profileStep, profileStepAsync } from '../../profile/profiler.mjs';
8
+ import { captureVisualContrastCandidate } from '../visual/screenshot-contrast.mjs';
9
+ import { launchDetectionBrowser, normalizeBrowserHandle } from './drivers.mjs';
10
+
11
+ function serializeDesignSystemForBrowser(designSystem) {
12
+ if (!designSystem?.present) return null;
13
+ return {
14
+ present: true,
15
+ hasFonts: designSystem.hasFonts === true,
16
+ allowedFonts: Array.from(designSystem.allowedFonts || []),
17
+ hasColors: designSystem.hasColors === true,
18
+ allowedColors: Array.from(designSystem.allowedColorKeys?.values?.() || [])
19
+ .map(entry => entry?.color)
20
+ .filter(color => color && Number.isFinite(color.r) && Number.isFinite(color.g) && Number.isFinite(color.b))
21
+ .map(color => ({ r: color.r, g: color.g, b: color.b })),
22
+ hasRadii: designSystem.hasRadii === true,
23
+ allowedRadii: (designSystem.allowedRadii || [])
24
+ .map(entry => Number(entry?.px))
25
+ .filter(px => Number.isFinite(px)),
26
+ hasPillRadius: designSystem.hasPillRadius === true,
27
+ };
28
+ }
29
+
30
+ async function runVisualContrastFallback(page, serializedGroups, options, profile, target) {
31
+ if (options?.visualContrast === false) return [];
32
+ const maxCandidates = Number.isFinite(options?.visualContrastMaxCandidates)
33
+ ? options.visualContrastMaxCandidates
34
+ : 12;
35
+ const scrollOffscreen = options?.visualContrastScrollOffscreen !== false;
36
+ const existingLowContrastSelectors = new Set(
37
+ serializedGroups
38
+ .filter(group => group.findings?.some(f => f.type === 'low-contrast'))
39
+ .map(group => group.selector)
40
+ .filter(Boolean)
41
+ );
42
+
43
+ let browserAnalyses = [];
44
+ const findings = [];
45
+ if (options?.visualContrastBrowser !== false) {
46
+ const browserFindings = await profileFindingsAsync(profile, {
47
+ engine: 'browser',
48
+ phase: 'visual-contrast',
49
+ ruleId: 'browser-fallback',
50
+ target,
51
+ }, async () => {
52
+ browserAnalyses = await page.evaluate(async ({ maxCandidates, scrollOffscreen }) => {
53
+ if (typeof window.monodesignAnalyzeVisualContrast !== 'function') return [];
54
+ return window.monodesignAnalyzeVisualContrast({ maxCandidates, scrollOffscreen });
55
+ }, { maxCandidates, scrollOffscreen });
56
+ return browserAnalyses
57
+ .filter(result => result.finding && !existingLowContrastSelectors.has(result.selector))
58
+ .map(result => result.finding);
59
+ });
60
+ findings.push(...browserFindings);
61
+ }
62
+
63
+ let candidates = browserAnalyses.length > 0 ? browserAnalyses : [];
64
+ if (candidates.length === 0) {
65
+ candidates = await profileStepAsync(profile, {
66
+ engine: 'browser',
67
+ phase: 'visual-contrast',
68
+ ruleId: 'collect-candidates',
69
+ target,
70
+ }, () => page.evaluate(({ maxCandidates }) => {
71
+ if (typeof window.monodesignCollectVisualContrastCandidates !== 'function') return [];
72
+ return window.monodesignCollectVisualContrastCandidates({ maxCandidates });
73
+ }, { maxCandidates }));
74
+ }
75
+
76
+ const viewport = options?.viewport || { width: 1280, height: 800 };
77
+ const browserResolvedSelectors = new Set(
78
+ browserAnalyses
79
+ .filter(result => result.status === 'fail' || result.status === 'pass')
80
+ .map(result => result.selector)
81
+ .filter(Boolean)
82
+ );
83
+ const filtered = candidates.filter(candidate =>
84
+ !existingLowContrastSelectors.has(candidate.selector) &&
85
+ !browserResolvedSelectors.has(candidate.selector)
86
+ );
87
+ if (options?.visualContrastPixel === false) return findings;
88
+ for (const candidate of filtered) {
89
+ const result = await profileFindingsAsync(profile, {
90
+ engine: 'browser',
91
+ phase: 'visual-contrast',
92
+ ruleId: 'pixel-diff',
93
+ target,
94
+ }, async () => {
95
+ const finding = await captureVisualContrastCandidate(page, candidate, viewport);
96
+ return finding ? [finding] : [];
97
+ });
98
+ findings.push(...result);
99
+ }
100
+ return findings;
101
+ }
102
+
103
+ // ---------------------------------------------------------------------------
104
+ // Browser detection (for URLs) — driver-based: monobrowse (native CDP,
105
+ // preferred) with puppeteer as fallback. See ./drivers.mjs for the seam.
106
+ // ---------------------------------------------------------------------------
107
+
108
+ async function detectUrl(url, options = {}) {
109
+ const profile = options?.profile;
110
+ const waitUntil = options?.waitUntil || 'networkidle0';
111
+ const settleMs = Number.isFinite(options?.settleMs) ? options.settleMs : 0;
112
+ const viewport = options?.viewport || { width: 1280, height: 800 };
113
+ // options.browser accepts either a driver handle (from createBrowserDetector)
114
+ // or a raw puppeteer Browser (legacy callers).
115
+ const externalBrowser = options?.browser ? normalizeBrowserHandle(options.browser) : null;
116
+
117
+ // Read the browser detection script — reuse it instead of reimplementing
118
+ const browserScriptPath = path.resolve(
119
+ path.dirname(fileURLToPath(import.meta.url)),
120
+ '..',
121
+ '..',
122
+ 'detect-antipatterns-browser.js'
123
+ );
124
+ let browserScript;
125
+ try {
126
+ browserScript = profileStep(profile, {
127
+ engine: 'browser',
128
+ phase: 'setup',
129
+ ruleId: 'read-browser-script',
130
+ target: url,
131
+ }, () => fs.readFileSync(browserScriptPath, 'utf-8'));
132
+ } catch {
133
+ throw new Error(`Browser script not found at ${browserScriptPath}`);
134
+ }
135
+
136
+ const browser = externalBrowser || await profileStepAsync(profile, {
137
+ engine: 'browser',
138
+ phase: 'load',
139
+ ruleId: 'launch-browser',
140
+ target: url,
141
+ }, () => launchDetectionBrowser({ launchArgs: options?.launchArgs, headless: true }));
142
+ const page = await profileStepAsync(profile, {
143
+ engine: 'browser',
144
+ phase: 'load',
145
+ ruleId: 'new-page',
146
+ target: url,
147
+ }, () => browser.newPage());
148
+ let results = [];
149
+ try {
150
+ await profileStepAsync(profile, {
151
+ engine: 'browser',
152
+ phase: 'load',
153
+ ruleId: 'set-viewport',
154
+ target: url,
155
+ }, () => page.setViewport(viewport));
156
+ await profileStepAsync(profile, {
157
+ engine: 'browser',
158
+ phase: 'load',
159
+ ruleId: `goto:${waitUntil}`,
160
+ target: url,
161
+ }, () => page.goto(url, { waitUntil, timeout: 30000 }));
162
+ if (settleMs > 0) {
163
+ await profileStepAsync(profile, {
164
+ engine: 'browser',
165
+ phase: 'load',
166
+ ruleId: 'settle',
167
+ target: url,
168
+ }, () => new Promise(resolve => setTimeout(resolve, settleMs)));
169
+ }
170
+
171
+ // Inject the browser detection script and collect results
172
+ const browserDesignSystem = serializeDesignSystemForBrowser(options?.designSystem);
173
+ await profileStepAsync(profile, {
174
+ engine: 'browser',
175
+ phase: 'scan',
176
+ ruleId: 'configure-pure-detect',
177
+ target: url,
178
+ }, () => page.evaluate((designSystem) => {
179
+ window.__MONODESIGN_CONFIG__ = {
180
+ ...(window.__MONODESIGN_CONFIG__ || {}),
181
+ autoScan: false,
182
+ ...(designSystem ? { designSystem } : {}),
183
+ };
184
+ }, browserDesignSystem));
185
+ await profileStepAsync(profile, {
186
+ engine: 'browser',
187
+ phase: 'scan',
188
+ ruleId: 'inject-browser-script',
189
+ target: url,
190
+ }, () => page.evaluate(browserScript));
191
+ let serializedGroups = [];
192
+ results = await profileFindingsAsync(profile, {
193
+ engine: 'browser',
194
+ phase: 'scan',
195
+ ruleId: 'browser-scan',
196
+ target: url,
197
+ }, async () => {
198
+ serializedGroups = await page.evaluate(() => {
199
+ if (!window.monodesignDetect) return [];
200
+ return window.monodesignDetect({ decorate: false, serialize: true });
201
+ });
202
+ return serializedGroups.flatMap(({ findings }) =>
203
+ findings.map(f => ({ id: f.type, snippet: f.detail, ignoreValue: f.ignoreValue || '' }))
204
+ );
205
+ });
206
+ const visualFindings = await runVisualContrastFallback(page, serializedGroups, options, profile, url);
207
+ results.push(...visualFindings);
208
+ } finally {
209
+ await profileStepAsync(profile, {
210
+ engine: 'browser',
211
+ phase: 'load',
212
+ ruleId: 'close-page',
213
+ target: url,
214
+ }, () => page.close().catch(() => {}));
215
+ if (!externalBrowser) {
216
+ await profileStepAsync(profile, {
217
+ engine: 'browser',
218
+ phase: 'load',
219
+ ruleId: 'close-browser',
220
+ target: url,
221
+ }, () => browser.close());
222
+ }
223
+ }
224
+ return filterByProviders(results.map(f => {
225
+ const item = finding(f.id, url, f.snippet);
226
+ if (f.ignoreValue) item.ignoreValue = f.ignoreValue;
227
+ return item;
228
+ }), options.providers);
229
+ }
230
+
231
+ async function createBrowserDetector(options = {}) {
232
+ // Pooled reuse for multiple URLs. `browser` is a driver handle (monobrowse
233
+ // or puppeteer); pass a raw puppeteer Browser via options.browser to reuse
234
+ // an externally managed instance.
235
+ const browser = options.browser
236
+ ? normalizeBrowserHandle(options.browser)
237
+ : await launchDetectionBrowser({ launchArgs: options.launchArgs, headless: options.headless ?? true });
238
+ const ownsBrowser = !options.browser;
239
+ const defaults = {
240
+ waitUntil: options.waitUntil || 'load',
241
+ settleMs: Number.isFinite(options.settleMs) ? options.settleMs : 100,
242
+ viewport: options.viewport || { width: 1280, height: 800 },
243
+ };
244
+ return {
245
+ browser,
246
+ async detectUrl(url, scanOptions = {}) {
247
+ return detectUrl(url, {
248
+ ...defaults,
249
+ ...scanOptions,
250
+ browser,
251
+ });
252
+ },
253
+ async close() {
254
+ if (ownsBrowser) await browser.close().catch(() => {});
255
+ },
256
+ };
257
+ }
258
+
259
+ export { runVisualContrastFallback, detectUrl, createBrowserDetector };
@@ -0,0 +1,339 @@
1
+ //
2
+ // Browser driver seam for URL detection.
3
+ //
4
+ // The detection engine (detect-url.mjs) and the visual-contrast fallback
5
+ // (engines/visual/screenshot-contrast.mjs) only need a tiny, puppeteer-shaped
6
+ // page surface:
7
+ //
8
+ // browser: { driverName, newPage(): Promise<page>, close(): Promise<void> }
9
+ // page: {
10
+ // setViewport({ width, height })
11
+ // goto(url, { waitUntil, timeout })
12
+ // evaluate(fnOrExpressionString, ...serializableArgs) -> serializable value
13
+ // screenshot({ encoding: 'base64', clip?, captureBeyondViewport? }) -> base64 string
14
+ // close()
15
+ // }
16
+ //
17
+ // Two drivers implement it:
18
+ // - monobrowse (preferred): @monoes/monobrowse, the monorepo's native CDP
19
+ // client. Drives a locally installed Chrome/Edge/Chromium — no bundled
20
+ // Chromium download needed. Supports the full surface including clip
21
+ // screenshots (Page.captureScreenshot) and evaluate roundtrips
22
+ // (Runtime.evaluate), so the visual-contrast pixel fallback runs under it.
23
+ // - puppeteer (fallback): the original optionalDependency path, kept for
24
+ // environments that have puppeteer + its downloaded Chrome but no system
25
+ // browser. A raw puppeteer Page already satisfies the page surface, so the
26
+ // puppeteer driver returns real puppeteer pages untouched.
27
+ //
28
+ // Selection: MONODESIGN_BROWSER_DRIVER=monobrowse|puppeteer forces one;
29
+ // otherwise monobrowse is tried first and puppeteer is the fallback.
30
+
31
+ import { createServer } from 'node:net';
32
+ import { mkdtempSync, rmSync } from 'node:fs';
33
+ import { tmpdir } from 'node:os';
34
+ import { join } from 'node:path';
35
+
36
+ const DRIVER_ENV = 'MONODESIGN_BROWSER_DRIVER';
37
+ // Windows CI teardown is the slow case: Chrome acknowledges Browser.close long
38
+ // before the process exits and hands the socket back, and closeBrowser()'s
39
+ // force-kill safety net is itself a deferred 1s timer. 5s is comfortable
40
+ // locally but cuts into a loaded runner's teardown, so give CI more runway —
41
+ // same reasoning as launchTimeoutMs below.
42
+ const CDP_PORT_RELEASE_TIMEOUT_MS = process.env.CI ? 15_000 : 5_000;
43
+ const CDP_PORT_RELEASE_POLL_MS = 25;
44
+ const PROFILE_CLEANUP_RETRY_MS = 2_000;
45
+
46
+ function serializeEvalArg(arg) {
47
+ const json = JSON.stringify(arg);
48
+ return json === undefined ? 'undefined' : json;
49
+ }
50
+
51
+ function mapWaitUntil(waitUntil) {
52
+ if (waitUntil === 'domcontentloaded') return 'domcontentloaded';
53
+ if (waitUntil === 'networkidle0' || waitUntil === 'networkidle2' || waitUntil === 'networkidle') return 'networkidle';
54
+ return 'load';
55
+ }
56
+
57
+ // This timer is deliberately NOT unref'd. Both call sites race it against CDP
58
+ // I/O that can die silently: goto() awaits a promise settled only by a
59
+ // Page.loadEventFired/domContentEventFired event, and close() races
60
+ // Browser.close — the very command that tears the websocket down. An unref'd
61
+ // timer never fires once nothing else pins the event loop, and a launched
62
+ // Chrome is detached and unref'd, so that websocket is the only ref'd handle
63
+ // here — exactly the one that goes away. Node would then consider the loop
64
+ // drained and exit 0 with the race still pending, instead of surfacing the
65
+ // timeout. The .finally() below clears it either way, so keeping it ref'd
66
+ // only ever costs a caller `ms`, never a hang. (Same rule as monobrowse's
67
+ // waitForProcessExit, #314.)
68
+ function withTimeout(promise, ms, label) {
69
+ let handle;
70
+ const timeout = new Promise((_, reject) => {
71
+ handle = setTimeout(() => reject(new Error(`Timeout waiting for ${label} after ${ms}ms`)), ms);
72
+ });
73
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(handle));
74
+ }
75
+
76
+ // "Released" has to mean BINDABLE, not merely unreachable. A connect probe
77
+ // stops succeeding as soon as Chrome's listener socket closes, which happens
78
+ // early in its shutdown — while the process is still alive holding both the
79
+ // port and the --user-data-dir singleton lock for this port. On Windows that
80
+ // gap is wide and the socket stays unbindable across it (node does not set
81
+ // SO_REUSEADDR there), so close() reported success and the next launch on the
82
+ // same forced port sat until its timeout: "Chrome failed to start on port N
83
+ // within 30000ms". Binding is the question the next launch actually asks, so
84
+ // ask it directly. A listener that never accepted a connection leaves no
85
+ // TIME_WAIT behind, so probing this way does not itself hold the port.
86
+ function isPortBindable(port) {
87
+ return new Promise((resolve) => {
88
+ const server = createServer();
89
+ server.once('error', () => resolve(false));
90
+ server.listen(port, '127.0.0.1', () => server.close(() => resolve(true)));
91
+ });
92
+ }
93
+
94
+ function removeProfileDir(dir) {
95
+ try {
96
+ rmSync(dir, { recursive: true, force: true });
97
+ } catch {
98
+ /* reclaimed by the OS's temp cleanup instead */
99
+ }
100
+ }
101
+
102
+ async function waitForCdpPortRelease(port) {
103
+ const deadline = Date.now() + CDP_PORT_RELEASE_TIMEOUT_MS;
104
+ while (Date.now() < deadline) {
105
+ if (await isPortBindable(port)) return;
106
+ await new Promise(resolve => setTimeout(resolve, CDP_PORT_RELEASE_POLL_MS));
107
+ }
108
+ throw new Error(`Chrome did not release CDP port ${port} within ${CDP_PORT_RELEASE_TIMEOUT_MS}ms`);
109
+ }
110
+
111
+ // ---------------------------------------------------------------------------
112
+ // monobrowse driver
113
+ // ---------------------------------------------------------------------------
114
+
115
+ function createMonobrowsePage(mb, client, sessionId, targetId, port) {
116
+ return {
117
+ async setViewport({ width, height }) {
118
+ await mb.setViewport(client, sessionId, width, height);
119
+ },
120
+ async goto(url, { waitUntil = 'load', timeout = 30000 } = {}) {
121
+ const condition = mapWaitUntil(waitUntil);
122
+ if (condition === 'networkidle') {
123
+ const nav = await client.send('Page.navigate', { url }, sessionId);
124
+ if (nav?.errorText) throw new Error(`Navigation to ${url} failed: ${nav.errorText}`);
125
+ await mb.waitForLoad(client, sessionId, 'networkidle', timeout);
126
+ return;
127
+ }
128
+ // Register the lifecycle listener BEFORE navigating so a fast page load
129
+ // cannot slip past it (waitForLoad's readyState pre-check would otherwise
130
+ // race against the previous document's readyState).
131
+ const event = condition === 'load' ? 'Page.loadEventFired' : 'Page.domContentEventFired';
132
+ const [eventPromise, cancel] = client.onceWithOff(event, sessionId);
133
+ try {
134
+ const nav = await client.send('Page.navigate', { url }, sessionId);
135
+ if (nav?.errorText) throw new Error(`Navigation to ${url} failed: ${nav.errorText}`);
136
+ await withTimeout(eventPromise, timeout, condition);
137
+ } finally {
138
+ cancel();
139
+ }
140
+ },
141
+ async evaluate(fnOrExpression, ...args) {
142
+ const expression = typeof fnOrExpression === 'function'
143
+ ? `(${String(fnOrExpression)})(${args.map(serializeEvalArg).join(', ')})`
144
+ : String(fnOrExpression);
145
+ const result = await client.send('Runtime.evaluate', {
146
+ expression,
147
+ returnByValue: true,
148
+ awaitPromise: true,
149
+ }, sessionId);
150
+ if (result?.exceptionDetails) {
151
+ const details = result.exceptionDetails;
152
+ throw new Error(details.exception?.description || details.exception?.value || details.text || 'Evaluation failed');
153
+ }
154
+ return result?.result?.value;
155
+ },
156
+ // Always returns a base64 string (the only mode the engine uses).
157
+ async screenshot({ clip } = {}) {
158
+ const params = { format: 'png' };
159
+ if (clip) {
160
+ params.clip = { x: clip.x, y: clip.y, width: clip.width, height: clip.height, scale: 1 };
161
+ params.captureBeyondViewport = true;
162
+ }
163
+ const result = await client.send('Page.captureScreenshot', params, sessionId);
164
+ return result?.data;
165
+ },
166
+ async close() {
167
+ // HTTP endpoint works regardless of which domains the ws connection has.
168
+ try {
169
+ await fetch(`http://127.0.0.1:${port}/json/close/${encodeURIComponent(targetId)}`);
170
+ } catch {
171
+ // Tab may already be gone; browser close cleans up anything left.
172
+ }
173
+ client.close();
174
+ },
175
+ };
176
+ }
177
+
178
+ async function launchMonobrowseBrowser(options = {}) {
179
+ const mb = await import('@monoes/monobrowse');
180
+ const headless = options.headless ?? true;
181
+ const launchArgs = options.launchArgs || (process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : []);
182
+
183
+ // We must never attach to a browser we did not launch: browser.close()
184
+ // issues Browser.close. Picking a "free" port ourselves cannot guarantee
185
+ // that — the port is only probed, and a concurrent launch (node --test runs
186
+ // files in parallel) can pick the same one before either Chrome binds it.
187
+ // The losing Chrome then listens on [::1] instead and its launcher attaches
188
+ // to the winner's browser, which dies under it ("CDP connection closed")
189
+ // when the winner closes. Port 0 has Chrome take a kernel-assigned port and
190
+ // report it in its own profile dir, so the endpoint is always ours.
191
+ const forcedPort = Number(process.env.MONODESIGN_MONOBROWSE_PORT);
192
+ const port = Number.isInteger(forcedPort) && forcedPort > 0 ? forcedPort : 0;
193
+
194
+ // CI runners (observed on the Windows GH Actions runner) are slower to get
195
+ // Chrome's CDP port open than the 10s default — a batch of sequential
196
+ // headless launches in the same job intermittently misses that window and
197
+ // fails with "Chrome failed to start... within 10000ms" even though the
198
+ // browser starts fine, just later. Give CI more runway; local dev keeps
199
+ // the tighter default so a genuinely broken launch still fails fast.
200
+ const launchTimeoutMs = options.launchTimeoutMs ?? (process.env.CI ? 30000 : undefined);
201
+ // Throwaway profile per launch. monobrowse defaults --user-data-dir to
202
+ // tmpdir()/monomind-browser-<port>, which is right for `monomind browse`
203
+ // (a later process reattaches to the same session by port) but wrong here:
204
+ // detection launches are stateless, and keying the profile on the port
205
+ // means two launches on the SAME port share one profile. Chrome enforces
206
+ // single-instance-per-profile, so the second launch rendezvouses with the
207
+ // first instead of starting its own — it hands over its command line and
208
+ // exits without ever opening a debugging port, which surfaces as "Chrome
209
+ // failed to start on port N" after the full launch timeout. Windows is
210
+ // where this bites: its singleton lock survives the previous Chrome being
211
+ // force-killed, and outlives the port being released. A unique dir removes
212
+ // the sharing entirely rather than racing the lock's cleanup.
213
+ const userDataDir = mkdtempSync(join(tmpdir(), 'monodesign-cdp-'));
214
+ const launchedPort = await mb.launchBrowser({ port, headless, args: launchArgs, launchTimeoutMs, userDataDir });
215
+ // Control connection (to the initial about:blank tab) — used for lifecycle
216
+ // commands; detection pages get their own dedicated connections.
217
+ const control = await mb.connectToTarget(launchedPort);
218
+
219
+ async function openPage() {
220
+ const target = await mb.fetchNewTarget(launchedPort, 'about:blank');
221
+ const wsUrl = target.webSocketDebuggerUrl || `ws://127.0.0.1:${launchedPort}/devtools/page/${target.id}`;
222
+ const client = new mb.CdpClient();
223
+ await client.connect(wsUrl);
224
+ const { sessionId } = await client.send('Target.attachToTarget', { targetId: target.id, flatten: true });
225
+ await Promise.all([
226
+ client.send('Page.enable', {}, sessionId),
227
+ client.send('Runtime.enable', {}, sessionId),
228
+ client.send('Network.enable', {}, sessionId),
229
+ ]);
230
+ return createMonobrowsePage(mb, client, sessionId, target.id, launchedPort);
231
+ }
232
+
233
+ return {
234
+ driverName: 'monobrowse',
235
+ newPage: openPage,
236
+ async close() {
237
+ try {
238
+ if (typeof mb.closeBrowser === 'function') {
239
+ // Newer monobrowse: graceful Browser.close with PID-kill fallback.
240
+ await mb.closeBrowser(control.client, launchedPort);
241
+ } else {
242
+ // Published 1.0.3 has no closeBrowser export — send the CDP
243
+ // Browser.close command directly (best effort, short timeout).
244
+ await withTimeout(control.client.send('Browser.close', {}), 3000, 'Browser.close').catch(() => {});
245
+ }
246
+ // Browser.close is acknowledged before Chrome has actually exited. A
247
+ // following detection run on a forced port can otherwise attach to the
248
+ // shutting-down process and fail creating its first target. Do not
249
+ // expose close() as complete until that CDP listener is gone.
250
+ await waitForCdpPortRelease(launchedPort);
251
+ } finally {
252
+ control.client.close();
253
+ // Best effort, twice: Chrome is still flushing profile data when the
254
+ // port comes back, so an immediate delete gets a few files recreated
255
+ // under it. The unref'd retry lands after that (same pattern as
256
+ // monobrowse's own post-close force-kill net) and never holds the
257
+ // process open. Whatever still survives is a few KB under tmpdir that
258
+ // nothing reuses, so neither attempt may fail close().
259
+ removeProfileDir(userDataDir);
260
+ setTimeout(() => removeProfileDir(userDataDir), PROFILE_CLEANUP_RETRY_MS).unref?.();
261
+ }
262
+ },
263
+ };
264
+ }
265
+
266
+ // ---------------------------------------------------------------------------
267
+ // puppeteer driver (original behavior, kept as fallback)
268
+ // ---------------------------------------------------------------------------
269
+
270
+ function wrapPuppeteerBrowser(browser) {
271
+ return {
272
+ driverName: 'puppeteer',
273
+ raw: browser,
274
+ newPage: () => browser.newPage(),
275
+ close: () => browser.close(),
276
+ };
277
+ }
278
+
279
+ async function launchPuppeteerBrowser(options = {}) {
280
+ let puppeteer;
281
+ try {
282
+ puppeteer = await import('puppeteer');
283
+ } catch {
284
+ throw new Error('puppeteer is required for URL scanning. Install: npm install puppeteer');
285
+ }
286
+ // CI runners (GitHub Actions Ubuntu) block unprivileged user namespaces, so
287
+ // Chrome can't initialize its sandbox there. Disable the sandbox only when
288
+ // running in CI; local users keep the default hardened launch.
289
+ const launchArgs = options.launchArgs || (process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : []);
290
+ const browser = await puppeteer.default.launch({
291
+ headless: options.headless ?? true,
292
+ args: launchArgs,
293
+ });
294
+ return wrapPuppeteerBrowser(browser);
295
+ }
296
+
297
+ // ---------------------------------------------------------------------------
298
+ // Selection
299
+ // ---------------------------------------------------------------------------
300
+
301
+ /** Accepts either a driver browser handle or a raw puppeteer Browser. */
302
+ function normalizeBrowserHandle(browser) {
303
+ if (!browser) return null;
304
+ if (browser.driverName && typeof browser.newPage === 'function') return browser;
305
+ if (typeof browser.newPage === 'function') return wrapPuppeteerBrowser(browser);
306
+ throw new Error('Unsupported browser handle passed to detectUrl (expected a driver handle or puppeteer Browser)');
307
+ }
308
+
309
+ async function launchDetectionBrowser(options = {}) {
310
+ const forced = (process.env[DRIVER_ENV] || '').trim().toLowerCase();
311
+ if (forced && forced !== 'monobrowse' && forced !== 'puppeteer') {
312
+ throw new Error(`Invalid ${DRIVER_ENV}=${forced} (expected "monobrowse" or "puppeteer")`);
313
+ }
314
+ const order = forced ? [forced] : ['monobrowse', 'puppeteer'];
315
+ const errors = [];
316
+ for (const name of order) {
317
+ try {
318
+ return name === 'monobrowse'
319
+ ? await launchMonobrowseBrowser(options)
320
+ : await launchPuppeteerBrowser(options);
321
+ } catch (error) {
322
+ errors.push(`${name}: ${error?.message || error}`);
323
+ }
324
+ }
325
+ throw new Error(
326
+ 'A browser is required for URL scanning and no driver could start one ' +
327
+ `(${errors.join(' | ')}). ` +
328
+ 'Install Google Chrome/Chromium/Edge for the native @monoes/monobrowse driver, ' +
329
+ 'or puppeteer is required for URL scanning. Install: npm install puppeteer'
330
+ );
331
+ }
332
+
333
+ export {
334
+ launchDetectionBrowser,
335
+ launchMonobrowseBrowser,
336
+ launchPuppeteerBrowser,
337
+ normalizeBrowserHandle,
338
+ wrapPuppeteerBrowser,
339
+ };