monomind 2.5.1 → 2.5.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 (289) hide show
  1. package/package.json +2 -1
  2. package/packages/@monomind/cli/.claude/agents/design/design-monodesign.md +6 -6
  3. package/packages/@monomind/cli/.claude/commands/mastermind/_repeat.md +4 -4
  4. package/packages/@monomind/cli/.claude/commands/mastermind/approvev1.md +4 -4
  5. package/packages/@monomind/cli/.claude/commands/mastermind/architect.md +6 -6
  6. package/packages/@monomind/cli/.claude/commands/mastermind/autodev.md +5 -5
  7. package/packages/@monomind/cli/.claude/commands/mastermind/brain.md +2 -2
  8. package/packages/@monomind/cli/.claude/commands/mastermind/build.md +6 -6
  9. package/packages/@monomind/cli/.claude/commands/mastermind/code-review.md +2 -2
  10. package/packages/@monomind/cli/.claude/commands/mastermind/content.md +6 -6
  11. package/packages/@monomind/cli/.claude/commands/mastermind/createorg.md +4 -4
  12. package/packages/@monomind/cli/.claude/commands/mastermind/createtask.md +3 -3
  13. package/packages/@monomind/cli/.claude/commands/mastermind/debug.md +5 -5
  14. package/packages/@monomind/cli/.claude/commands/mastermind/design.md +5 -5
  15. package/packages/@monomind/cli/.claude/commands/mastermind/do.md +2 -2
  16. package/packages/@monomind/cli/.claude/commands/mastermind/execute.md +5 -5
  17. package/packages/@monomind/cli/.claude/commands/mastermind/finance.md +6 -6
  18. package/packages/@monomind/cli/.claude/commands/mastermind/finish.md +5 -5
  19. package/packages/@monomind/cli/.claude/commands/mastermind/idea.md +6 -6
  20. package/packages/@monomind/cli/.claude/commands/mastermind/ideate.md +5 -5
  21. package/packages/@monomind/cli/.claude/commands/mastermind/improve.md +6 -6
  22. package/packages/@monomind/cli/.claude/commands/mastermind/marketing.md +6 -6
  23. package/packages/@monomind/cli/.claude/commands/mastermind/master.md +54 -54
  24. package/packages/@monomind/cli/.claude/commands/mastermind/ops.md +6 -6
  25. package/packages/@monomind/cli/.claude/commands/mastermind/orgs.md +2 -2
  26. package/packages/@monomind/cli/.claude/commands/mastermind/orgstatus.md +2 -2
  27. package/packages/@monomind/cli/.claude/commands/mastermind/plan.md +5 -5
  28. package/packages/@monomind/cli/.claude/commands/mastermind/receive-review.md +5 -5
  29. package/packages/@monomind/cli/.claude/commands/mastermind/release.md +6 -6
  30. package/packages/@monomind/cli/.claude/commands/mastermind/research.md +6 -6
  31. package/packages/@monomind/cli/.claude/commands/mastermind/review.md +6 -6
  32. package/packages/@monomind/cli/.claude/commands/mastermind/runorg.md +4 -4
  33. package/packages/@monomind/cli/.claude/commands/mastermind/runorgv1.md +5 -5
  34. package/packages/@monomind/cli/.claude/commands/mastermind/sales.md +6 -6
  35. package/packages/@monomind/cli/.claude/commands/mastermind/skill-builder.md +5 -5
  36. package/packages/@monomind/cli/.claude/commands/mastermind/stoporg.md +3 -3
  37. package/packages/@monomind/cli/.claude/commands/mastermind/taskdev.md +5 -5
  38. package/packages/@monomind/cli/.claude/commands/mastermind/tdd.md +5 -5
  39. package/packages/@monomind/cli/.claude/commands/mastermind/techport.md +5 -5
  40. package/packages/@monomind/cli/.claude/commands/mastermind/verify.md +5 -5
  41. package/packages/@monomind/cli/.claude/commands/mastermind/worktree.md +5 -5
  42. package/packages/@monomind/cli/.claude/helpers/control-start.cjs +30 -0
  43. package/packages/@monomind/cli/.claude/helpers/utils/monograph.cjs +44 -12
  44. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/access.md → mastermind-access/SKILL.md} +2 -2
  45. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/activity.md → mastermind-activity/SKILL.md} +2 -2
  46. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/adapter-manager.md → mastermind-adapter-manager/SKILL.md} +2 -2
  47. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/adapters.md → mastermind-adapters/SKILL.md} +2 -2
  48. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/agent-detail.md → mastermind-agent-detail/SKILL.md} +2 -2
  49. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/agents.md → mastermind-agents/SKILL.md} +2 -2
  50. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/approval-detail.md → mastermind-approval-detail/SKILL.md} +2 -2
  51. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/approvev1.md → mastermind-approvev1/SKILL.md} +2 -2
  52. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/architect.md → mastermind-architect/SKILL.md} +7 -7
  53. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/autodev.md → mastermind-autodev/SKILL.md} +10 -10
  54. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/backup.md → mastermind-backup/SKILL.md} +2 -2
  55. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/bootstrap.md → mastermind-bootstrap/SKILL.md} +2 -2
  56. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/budgets.md → mastermind-budgets/SKILL.md} +2 -2
  57. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/build.md → mastermind-build/SKILL.md} +5 -5
  58. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/companies.md → mastermind-companies/SKILL.md} +2 -2
  59. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/content.md → mastermind-content/SKILL.md} +5 -5
  60. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/costs.md → mastermind-costs/SKILL.md} +2 -2
  61. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/createorg.md → mastermind-createorg/SKILL.md} +3 -3
  62. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/debug.md → mastermind-debug/SKILL.md} +4 -4
  63. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/_delegation.md → mastermind-delegation/SKILL.md} +1 -1
  64. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/design.md → mastermind-design/SKILL.md} +9 -9
  65. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/diagnose.md → mastermind-diagnose/SKILL.md} +2 -2
  66. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/env.md → mastermind-env/SKILL.md} +2 -2
  67. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/environments.md → mastermind-environments/SKILL.md} +2 -2
  68. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/execute.md → mastermind-execute/SKILL.md} +10 -10
  69. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/export.md → mastermind-export/SKILL.md} +2 -2
  70. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/finance.md → mastermind-finance/SKILL.md} +5 -5
  71. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/goal-detail.md → mastermind-goal-detail/SKILL.md} +2 -2
  72. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/goals.md → mastermind-goals/SKILL.md} +2 -2
  73. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/heartbeatv1.md → mastermind-heartbeatv1/SKILL.md} +2 -2
  74. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/idea.md → mastermind-idea/SKILL.md} +7 -7
  75. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/import.md → mastermind-import/SKILL.md} +2 -2
  76. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/inbox.md → mastermind-inbox/SKILL.md} +2 -2
  77. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/instance.md → mastermind-instance/SKILL.md} +2 -2
  78. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/instance-settings.md → mastermind-instance-settings/SKILL.md} +2 -2
  79. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/invite-landing.md → mastermind-invite-landing/SKILL.md} +2 -2
  80. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/invites.md → mastermind-invites/SKILL.md} +2 -2
  81. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/issue-detail.md → mastermind-issue-detail/SKILL.md} +2 -2
  82. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/issues.md → mastermind-issues/SKILL.md} +2 -2
  83. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/join-queue.md → mastermind-join-queue/SKILL.md} +2 -2
  84. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/liveness.md → mastermind-liveness/SKILL.md} +2 -2
  85. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/marketing.md → mastermind-marketing/SKILL.md} +8 -8
  86. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/memory.md → mastermind-memory/SKILL.md} +2 -2
  87. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/monitor.md → mastermind-monitor/SKILL.md} +2 -2
  88. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/my-issues.md → mastermind-my-issues/SKILL.md} +2 -2
  89. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/new-agent.md → mastermind-new-agent/SKILL.md} +2 -2
  90. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/ops.md → mastermind-ops/SKILL.md} +5 -5
  91. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/org-chart.md → mastermind-org-chart/SKILL.md} +2 -2
  92. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/org-settings.md → mastermind-org-settings/SKILL.md} +2 -2
  93. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/orgs.md → mastermind-orgs/SKILL.md} +1 -1
  94. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/orgstatus.md → mastermind-orgstatus/SKILL.md} +2 -2
  95. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/plan.md → mastermind-plan/SKILL.md} +7 -7
  96. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/plan-to-tasks.md → mastermind-plan-to-tasks/SKILL.md} +2 -2
  97. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/plugin-manager.md → mastermind-plugin-manager/SKILL.md} +2 -2
  98. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/plugin-settings.md → mastermind-plugin-settings/SKILL.md} +2 -2
  99. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/plugins.md → mastermind-plugins/SKILL.md} +2 -2
  100. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/profile.md → mastermind-profile/SKILL.md} +2 -2
  101. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/project-detail.md → mastermind-project-detail/SKILL.md} +2 -2
  102. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/project-workspace.md → mastermind-project-workspace/SKILL.md} +2 -2
  103. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/projects.md → mastermind-projects/SKILL.md} +2 -2
  104. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/_protocol.md → mastermind-protocol/SKILL.md} +3 -3
  105. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/release.md → mastermind-release/SKILL.md} +5 -5
  106. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/_repeat.md → mastermind-repeat/SKILL.md} +2 -2
  107. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/research.md → mastermind-research/SKILL.md} +5 -5
  108. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/review.md → mastermind-review/SKILL.md} +5 -5
  109. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/routine-detail.md → mastermind-routine-detail/SKILL.md} +2 -2
  110. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/routines.md → mastermind-routines/SKILL.md} +2 -2
  111. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/runorgv1.md → mastermind-runorgv1/SKILL.md} +2 -2
  112. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/sales.md → mastermind-sales/SKILL.md} +5 -5
  113. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/search.md → mastermind-search/SKILL.md} +2 -2
  114. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/secrets.md → mastermind-secrets/SKILL.md} +2 -2
  115. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/skill-builder.md → mastermind-skill-builder/SKILL.md} +16 -14
  116. package/packages/@monomind/cli/.claude/skills/mastermind-skills/{skills.md → SKILL.md} +2 -2
  117. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/stoporg.md → mastermind-stoporg/SKILL.md} +2 -2
  118. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/taskdev.md → mastermind-taskdev/SKILL.md} +6 -6
  119. package/packages/@monomind/cli/.claude/skills/{mastermind-skills → mastermind-taskdev}/implementer-prompt.md +1 -1
  120. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/tasks.md → mastermind-tasks/SKILL.md} +2 -2
  121. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/tdd.md → mastermind-tdd/SKILL.md} +4 -4
  122. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/techport.md → mastermind-techport/SKILL.md} +5 -5
  123. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/threads.md → mastermind-threads/SKILL.md} +2 -2
  124. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/tree-control.md → mastermind-tree-control/SKILL.md} +2 -2
  125. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/verify.md → mastermind-verify/SKILL.md} +1 -1
  126. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/wiki.md → mastermind-wiki/SKILL.md} +2 -2
  127. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/workspace-detail.md → mastermind-workspace-detail/SKILL.md} +2 -2
  128. package/packages/@monomind/cli/.claude/skills/{mastermind-skills/workspaces.md → mastermind-workspaces/SKILL.md} +2 -2
  129. package/packages/@monomind/cli/.claude/skills/monodesign/SKILL.md +114 -190
  130. package/packages/@monomind/cli/.claude/skills/monodesign/adapt.md +1 -1
  131. package/packages/@monomind/cli/.claude/skills/monodesign/agents/monodesign-asset-producer.md +4 -4
  132. package/packages/@monomind/cli/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +103 -0
  133. package/packages/@monomind/cli/.claude/skills/monodesign/audit.md +1 -1
  134. package/packages/@monomind/cli/.claude/skills/monodesign/craft.md +2 -2
  135. package/packages/@monomind/cli/.claude/skills/monodesign/critique.md +1 -1
  136. package/packages/@monomind/cli/.claude/skills/monodesign/init.md +30 -0
  137. package/packages/@monomind/cli/.claude/skills/monodesign/layout.md +36 -0
  138. package/packages/@monomind/cli/.claude/skills/monodesign/live.md +19 -44
  139. package/packages/@monomind/cli/.claude/skills/monodesign/reference/adapt.md +122 -0
  140. package/packages/@monomind/cli/.claude/skills/monodesign/reference/adapt.native.md +58 -0
  141. package/packages/@monomind/cli/.claude/skills/monodesign/reference/android.md +40 -0
  142. package/packages/@monomind/cli/.claude/skills/monodesign/reference/animate.md +39 -11
  143. package/packages/@monomind/cli/.claude/skills/monodesign/reference/antipatterns-catalog.md +22 -16
  144. package/packages/@monomind/cli/.claude/skills/monodesign/reference/audit.md +5 -3
  145. package/packages/@monomind/cli/.claude/skills/monodesign/reference/audit.native.md +139 -0
  146. package/packages/@monomind/cli/.claude/skills/monodesign/reference/bolder.md +71 -64
  147. package/packages/@monomind/cli/.claude/skills/monodesign/reference/brand.md +12 -18
  148. package/packages/@monomind/cli/.claude/skills/monodesign/reference/clarify.md +114 -0
  149. package/packages/@monomind/cli/.claude/skills/monodesign/reference/codex.md +4 -6
  150. package/packages/@monomind/cli/.claude/skills/monodesign/reference/colorize.md +108 -5
  151. package/packages/@monomind/cli/.claude/skills/monodesign/reference/craft.md +70 -143
  152. package/packages/@monomind/cli/.claude/skills/monodesign/reference/critique.md +635 -68
  153. package/packages/@monomind/cli/.claude/skills/monodesign/reference/delight.md +1 -1
  154. package/packages/@monomind/cli/.claude/skills/monodesign/reference/distill.md +1 -1
  155. package/packages/@monomind/cli/.claude/skills/monodesign/reference/document.md +24 -22
  156. package/packages/@monomind/cli/.claude/skills/monodesign/reference/extract.md +1 -1
  157. package/packages/@monomind/cli/.claude/skills/monodesign/reference/hooks.md +22 -29
  158. package/packages/@monomind/cli/.claude/skills/monodesign/reference/init.md +221 -0
  159. package/packages/@monomind/cli/.claude/skills/monodesign/reference/interaction-design.md +0 -6
  160. package/packages/@monomind/cli/.claude/skills/monodesign/reference/ios.md +45 -0
  161. package/packages/@monomind/cli/.claude/skills/monodesign/reference/layout.md +57 -13
  162. package/packages/@monomind/cli/.claude/skills/monodesign/reference/live.md +159 -63
  163. package/packages/@monomind/cli/.claude/skills/monodesign/reference/overdrive.md +1 -1
  164. package/packages/@monomind/cli/.claude/skills/monodesign/reference/personas.md +1 -1
  165. package/packages/@monomind/cli/.claude/skills/monodesign/reference/polish.md +16 -8
  166. package/packages/@monomind/cli/.claude/skills/monodesign/reference/pre-delivery-checklist.md +1 -1
  167. package/packages/@monomind/cli/.claude/skills/monodesign/reference/product.md +1 -3
  168. package/packages/@monomind/cli/.claude/skills/monodesign/reference/quieter.md +1 -1
  169. package/packages/@monomind/cli/.claude/skills/monodesign/reference/shape.md +27 -13
  170. package/packages/@monomind/cli/.claude/skills/monodesign/reference/teach.md +6 -152
  171. package/packages/@monomind/cli/.claude/skills/monodesign/reference/typeset.md +180 -3
  172. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/command-metadata.json +94 -0
  173. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/context-signals.mjs +227 -0
  174. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/context.mjs +1062 -0
  175. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/critique-storage.mjs +243 -0
  176. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detect-csp.mjs +199 -0
  177. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detect.mjs +34 -0
  178. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +1938 -0
  179. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/cli/main.mjs +322 -0
  180. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/design-system.mjs +815 -0
  181. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +5246 -0
  182. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +51 -0
  183. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +260 -0
  184. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +259 -0
  185. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +574 -0
  186. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +1016 -0
  187. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +235 -0
  188. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +199 -0
  189. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/findings.mjs +13 -0
  190. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +199 -0
  191. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +167 -0
  192. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +515 -0
  193. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +2704 -0
  194. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/color.mjs +125 -0
  195. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +102 -0
  196. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +31 -0
  197. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +149 -0
  198. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/detector/shared/page.mjs +8 -0
  199. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook-admin.mjs +662 -0
  200. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook-before-edit.mjs +517 -0
  201. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook-lib.mjs +1777 -0
  202. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/hook.mjs +62 -0
  203. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/design-parser.mjs +843 -0
  204. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/is-generated.mjs +70 -0
  205. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +641 -0
  206. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +130 -0
  207. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/provider.mjs +5 -0
  208. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/lib/target-args.mjs +43 -0
  209. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +51 -0
  210. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/completion.mjs +20 -0
  211. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/event-validation.mjs +138 -0
  212. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/insert-ui.mjs +459 -0
  213. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/manual-apply.mjs +940 -0
  214. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +358 -0
  215. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +153 -0
  216. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/session-store.mjs +290 -0
  217. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/svelte-component.mjs +827 -0
  218. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +275 -0
  219. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/ui-core.mjs +181 -0
  220. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live/vocabulary.mjs +37 -0
  221. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-accept.mjs +813 -0
  222. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-browser-dom.js +147 -0
  223. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-browser-session.js +124 -0
  224. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-browser.js +11241 -0
  225. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +1242 -0
  226. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-complete.mjs +76 -0
  227. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +684 -0
  228. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +52 -0
  229. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-inject.mjs +584 -0
  230. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-insert.mjs +273 -0
  231. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +364 -0
  232. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-poll.mjs +385 -0
  233. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-resume.mjs +95 -0
  234. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-server.mjs +1138 -0
  235. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-status.mjs +62 -0
  236. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-target.mjs +31 -0
  237. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live-wrap.mjs +895 -0
  238. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/live.mjs +298 -0
  239. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +15 -0
  240. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/palette.mjs +634 -0
  241. package/packages/@monomind/cli/.claude/skills/monodesign/scripts/pin.mjs +222 -0
  242. package/packages/@monomind/cli/.claude/skills/monodesign/teach.md +7 -58
  243. package/packages/@monomind/cli/dist/src/commands/design-detect.d.ts +7 -1
  244. package/packages/@monomind/cli/dist/src/commands/design-detect.js +70 -38
  245. package/packages/@monomind/cli/dist/src/commands/design-palette.d.ts +1 -1
  246. package/packages/@monomind/cli/dist/src/commands/design-palette.js +3 -3
  247. package/packages/@monomind/cli/dist/src/commands/doc.js +72 -15
  248. package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.d.ts +4 -0
  249. package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.js +23 -0
  250. package/packages/@monomind/cli/dist/src/commands/doctor.js +3 -3
  251. package/packages/@monomind/cli/dist/src/commands/org.js +109 -9
  252. package/packages/@monomind/cli/dist/src/init/executor.js +14 -3
  253. package/packages/@monomind/cli/dist/src/knowledge/document-pipeline.d.ts +2 -0
  254. package/packages/@monomind/cli/dist/src/knowledge/document-pipeline.js +1 -0
  255. package/packages/@monomind/cli/dist/src/mcp-tools/knowledge-tools.js +38 -7
  256. package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.d.ts +8 -3
  257. package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.js +193 -31
  258. package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +33 -0
  259. package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +166 -17
  260. package/packages/@monomind/cli/dist/src/memory/memory-kg.d.ts +185 -0
  261. package/packages/@monomind/cli/dist/src/memory/memory-kg.js +449 -0
  262. package/packages/@monomind/cli/dist/src/memory/query-router.d.ts +44 -0
  263. package/packages/@monomind/cli/dist/src/memory/query-router.js +113 -0
  264. package/packages/@monomind/cli/dist/src/orgrt/daemon.d.ts +18 -0
  265. package/packages/@monomind/cli/dist/src/orgrt/daemon.js +249 -12
  266. package/packages/@monomind/cli/dist/src/orgrt/migrate.js +7 -0
  267. package/packages/@monomind/cli/dist/src/orgrt/policy.js +7 -0
  268. package/packages/@monomind/cli/dist/src/orgrt/session.d.ts +24 -1
  269. package/packages/@monomind/cli/dist/src/orgrt/session.js +18 -3
  270. package/packages/@monomind/cli/dist/src/orgrt/templates.d.ts +1 -0
  271. package/packages/@monomind/cli/dist/src/orgrt/templates.js +9 -4
  272. package/packages/@monomind/cli/dist/src/orgrt/types.d.ts +15 -0
  273. package/packages/@monomind/cli/dist/src/orgrt/types.js +2 -0
  274. package/packages/@monomind/cli/dist/src/ui/dashboard.html +154 -6
  275. package/packages/@monomind/cli/dist/src/ui/orgs.html +24 -0
  276. package/packages/@monomind/cli/dist/src/ui/server.mjs +162 -12
  277. package/packages/@monomind/cli/package.json +5 -3
  278. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/_agent-select.md → mastermind-agent-select/SKILL.md} +0 -0
  279. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/finish.md → mastermind-finish/SKILL.md} +0 -0
  280. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/_intake.md → mastermind-intake/SKILL.md} +0 -0
  281. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills → mastermind-marketing}/references/copywriting-frameworks.md +0 -0
  282. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills → mastermind-marketing}/references/persuasion-psychology.md +0 -0
  283. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/monotask.md → mastermind-monotask/SKILL.md} +0 -0
  284. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/receive-review.md → mastermind-receive-review/SKILL.md} +0 -0
  285. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/runorg.md → mastermind-runorg/SKILL.md} +0 -0
  286. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills → mastermind-taskdev}/code-quality-reviewer-prompt.md +0 -0
  287. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills → mastermind-taskdev}/final-reviewer-prompt.md +0 -0
  288. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills → mastermind-taskdev}/spec-reviewer-prompt.md +0 -0
  289. /package/packages/@monomind/cli/.claude/skills/{mastermind-skills/worktree.md → mastermind-worktree/SKILL.md} +0 -0
@@ -0,0 +1,895 @@
1
+ // Pattern adapted from impeccable (Apache-2.0) — rebranded for monomind
2
+ /**
3
+ * CLI helper: find an element in source and wrap it in a variant container.
4
+ *
5
+ * Usage:
6
+ * node <scripts_path>/live-wrap.mjs --id SESSION_ID --count N --query "hero-combined-left" [--file path]
7
+ *
8
+ * Searches project files for the element matching the query (class name, ID, or
9
+ * text snippet), wraps it with the variant scaffolding, and prints the file path
10
+ * + line range where the agent should insert variant HTML.
11
+ *
12
+ * This replaces 3-4 agent tool calls (grep + read + edit) with a single CLI call.
13
+ */
14
+
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import { isGeneratedFile } from './lib/is-generated.mjs';
18
+ import { readBuffer as readManualEditsBuffer } from './live/manual-edits-buffer.mjs';
19
+ import {
20
+ buildSvelteComponentCssAuthoring,
21
+ scaffoldSvelteComponentSession,
22
+ shouldUseSvelteComponentInjection,
23
+ } from './live/svelte-component.mjs';
24
+
25
+ const EXTENSIONS = ['.html', '.jsx', '.tsx', '.vue', '.svelte', '.astro'];
26
+
27
+ export async function wrapCli() {
28
+ const args = process.argv.slice(2);
29
+
30
+ if (args.includes('--help') || args.includes('-h')) {
31
+ console.log(`Usage: monodesign wrap [options]
32
+
33
+ Find an element in source and wrap it in a variant container.
34
+
35
+ Required:
36
+ --id ID Session ID for the variant wrapper
37
+ --count N Number of expected variants (1-8)
38
+
39
+ Element identification (at least one required):
40
+ --element-id ID HTML id attribute of the element
41
+ --classes A,B,C Comma- or space-separated CSS class names
42
+ --tag TAG Tag name (div, section, etc.)
43
+ --query TEXT Fallback: raw text to search for
44
+
45
+ Optional:
46
+ --file PATH Source file to search in (skips auto-detection)
47
+ --text TEXT Picked element's textContent. Used to disambiguate when
48
+ classes/tag match multiple sibling elements (e.g. a list
49
+ of <Card>s with the same className). Pass the first ~80
50
+ chars of event.element.textContent.
51
+ --page-url URL Current page URL. Required when pending manual edits may
52
+ affect the picked source block. Pending edits are filtered
53
+ to this page so an edit on /a doesn't bleed into /b.
54
+ --help Show this help message
55
+
56
+ Output (JSON):
57
+ { file, startLine, endLine, insertLine, commentSyntax }
58
+
59
+ The agent should insert variant HTML at insertLine.`);
60
+ process.exit(0);
61
+ }
62
+
63
+ const id = argVal(args, '--id');
64
+ const count = parseInt(argVal(args, '--count') || '3');
65
+ const elementId = argVal(args, '--element-id');
66
+ const classes = argVal(args, '--classes');
67
+ const tag = argVal(args, '--tag');
68
+ const query = argVal(args, '--query');
69
+ const filePath = argVal(args, '--file');
70
+ const text = argVal(args, '--text');
71
+ const pageUrl = argVal(args, '--page-url');
72
+
73
+ if (!id) { console.error('Missing --id'); process.exit(1); }
74
+ if (!elementId && !classes && !query) {
75
+ console.error('Need at least one of: --element-id, --classes, --query');
76
+ process.exit(1);
77
+ }
78
+
79
+ // Build search queries in priority order (most specific first)
80
+ const queries = buildSearchQueries(elementId, classes, tag, query);
81
+
82
+ const genOpts = { cwd: process.cwd() };
83
+
84
+ // Find the source file. Generated files are excluded from auto-search so we
85
+ // don't silently write variants into a file the next build will wipe.
86
+ let targetFile = filePath;
87
+ let matchedQuery = null;
88
+ if (!targetFile) {
89
+ for (const q of queries) {
90
+ targetFile = findFileWithQuery(q, process.cwd(), genOpts);
91
+ if (targetFile) { matchedQuery = q; break; }
92
+ }
93
+ if (!targetFile) {
94
+ // Nothing in source. Did the element show up in a generated file? That
95
+ // tells the agent "fall back to the agent-driven flow" vs "element just
96
+ // doesn't exist in this project."
97
+ let generatedHit = null;
98
+ for (const q of queries) {
99
+ generatedHit = findFileWithQuery(q, process.cwd(), { ...genOpts, includeGenerated: true });
100
+ if (generatedHit) break;
101
+ }
102
+ if (generatedHit) {
103
+ console.error(JSON.stringify({
104
+ error: 'element_not_in_source',
105
+ fallback: 'agent-driven',
106
+ generatedMatch: path.relative(process.cwd(), generatedHit),
107
+ hint: 'Element found only in a generated file. See "Handle fallback" in live.md.',
108
+ }));
109
+ } else {
110
+ console.error(JSON.stringify({
111
+ error: 'element_not_found',
112
+ fallback: 'agent-driven',
113
+ hint: 'Element not found in any project file. It may be runtime-injected (JS component, etc.). See "Handle fallback" in live.md.',
114
+ }));
115
+ }
116
+ process.exit(1);
117
+ }
118
+ } else {
119
+ if (isGeneratedFile(targetFile, genOpts)) {
120
+ console.error(JSON.stringify({
121
+ error: 'file_is_generated',
122
+ fallback: 'agent-driven',
123
+ file: path.relative(process.cwd(), path.resolve(process.cwd(), targetFile)),
124
+ hint: 'Explicit --file points at a generated file. Writing here gets wiped by the next build. See "Handle fallback" in live.md.',
125
+ }));
126
+ process.exit(1);
127
+ }
128
+ matchedQuery = queries[0];
129
+ }
130
+
131
+ const content = fs.readFileSync(targetFile, 'utf-8');
132
+ const lines = content.split('\n');
133
+
134
+ // Find the element, trying each query in priority order. When `--text` is
135
+ // supplied, collect every candidate the queries surface and disambiguate
136
+ // by the picked element's textContent. Without `--text`, fall back to the
137
+ // legacy first-match behavior so unmodified callers keep working.
138
+ let match = null;
139
+ if (text) {
140
+ const candidates = [];
141
+ for (const q of queries) {
142
+ const all = findAllElements(lines, q, tag);
143
+ for (const c of all) {
144
+ if (!candidates.some((x) => x.startLine === c.startLine)) {
145
+ candidates.push(c);
146
+ }
147
+ }
148
+ // Once a more-specific query (ID, full className combo) yielded a unique
149
+ // result, stop — falling through to the loose tag+single-class query
150
+ // would readmit the siblings we just disambiguated past.
151
+ if (candidates.length === 1) break;
152
+ }
153
+ if (candidates.length === 0) {
154
+ console.error(JSON.stringify({ error: 'Found file but could not locate element in ' + targetFile + '. Searched for: ' + queries.join(', ') }));
155
+ process.exit(1);
156
+ }
157
+ if (candidates.length === 1) {
158
+ match = candidates[0];
159
+ } else {
160
+ const filtered = filterByText(candidates, lines, text);
161
+ if (filtered.length === 1) {
162
+ match = filtered[0];
163
+ } else if (filtered.length === 0) {
164
+ // Source uses dynamic content (`<h1>{title}</h1>` etc.) so the
165
+ // browser-side textContent doesn't appear literally in source. Fall
166
+ // back to first-match rather than refusing — this is the same
167
+ // behavior unmodified callers see, just preserved.
168
+ match = candidates[0];
169
+ } else {
170
+ // Multiple candidates ALSO match the text. Truly ambiguous — refuse
171
+ // rather than pick wrong, and hand the agent the candidate locations
172
+ // so it can disambiguate by reading the file.
173
+ console.error(JSON.stringify({
174
+ error: 'element_ambiguous',
175
+ fallback: 'agent-driven',
176
+ file: path.relative(process.cwd(), targetFile),
177
+ candidates: filtered.map((c) => ({
178
+ startLine: c.startLine + 1,
179
+ endLine: c.endLine + 1,
180
+ })),
181
+ hint: 'Multiple source elements match both classes/tag and textContent. Pass --element-id, a more specific --text, or write the wrapper manually. See "Handle fallback" in live.md.',
182
+ }));
183
+ process.exit(1);
184
+ }
185
+ }
186
+ } else {
187
+ for (const q of queries) {
188
+ match = findElement(lines, q, tag);
189
+ if (match) break;
190
+ }
191
+ if (!match) {
192
+ console.error(JSON.stringify({ error: 'Found file but could not locate element in ' + targetFile + '. Searched for: ' + queries.join(', ') }));
193
+ process.exit(1);
194
+ }
195
+ }
196
+
197
+ const { startLine, endLine } = match;
198
+ const commentSyntax = detectCommentSyntax(targetFile);
199
+ const styleMode = detectStyleMode(targetFile);
200
+ const isJsx = commentSyntax.open === '{/*';
201
+ const indent = lines[startLine].match(/^(\s*)/)[1];
202
+
203
+ // Extract the original element. Reindent under the wrapper while preserving
204
+ // the relative depth between lines — `l.trimStart()` would strip ALL leading
205
+ // whitespace and collapse e.g. `<aside>`/` <h1>`/`</aside>` (6/8/6 spaces)
206
+ // to a single uniform indent, so on accept/discard the round-trip restores
207
+ // the inner element at its parent's depth instead of nested inside it.
208
+ // Strip only the COMMON minimum leading whitespace across the picked lines;
209
+ // `deindentContent` on the accept side already mirrors this convention.
210
+ let originalLines = lines.slice(startLine, endLine + 1);
211
+
212
+ // Buffer-aware "original" content: if the user has pending manual edits for
213
+ // this page whose originalText appears in the picked source range, apply
214
+ // them so the wrap block's "original" variant reflects what the user was
215
+ // looking at (their edited DOM), not the raw source. Source itself stays
216
+ // untouched here — only the wrap block's embedded "original" copy is
217
+ // adjusted. The pending edits remain in the buffer until committed.
218
+ //
219
+ // Apply buffered edits only when the browser provided the current page URL.
220
+ // Without it, fail if pending edits plausibly touch this exact source range;
221
+ // otherwise skip buffer awareness so unrelated staged edits on another page
222
+ // do not block normal wrap work.
223
+ let pendingBuffer = { entries: [] };
224
+ try { pendingBuffer = readManualEditsBuffer(process.cwd()); } catch {}
225
+ const pendingEntriesForTarget = pageUrl
226
+ ? []
227
+ : pendingEntriesThatMayAffectWrap(pendingBuffer.entries, targetFile, originalLines, startLine, process.cwd());
228
+ if (pendingEntriesForTarget.length > 0) {
229
+ console.error(JSON.stringify({
230
+ error: 'missing_page_url_with_pending_edits',
231
+ pendingEntries: pendingEntriesForTarget.length,
232
+ hint: 'Pending manual edits may affect the selected source block. Pass --page-url=$event.pageUrl so the wrap block reflects the user\'s staged DOM.',
233
+ }));
234
+ process.exit(1);
235
+ }
236
+ if (pageUrl) {
237
+ const failedBufferedOps = [];
238
+ for (const entry of pendingBuffer.entries || []) {
239
+ if (entry.pageUrl !== pageUrl) continue;
240
+ for (const op of entry.ops || []) {
241
+ const mayAffectWrap = manualEditMayAffectWrap(op, targetFile, originalLines, startLine, process.cwd());
242
+ const result = applyBufferedManualEditToLines(originalLines, startLine, op);
243
+ if (result.changed) {
244
+ originalLines = result.lines;
245
+ continue;
246
+ }
247
+ if (!mayAffectWrap) continue;
248
+ failedBufferedOps.push({
249
+ entryId: entry.id,
250
+ ref: op?.ref || null,
251
+ originalText: op?.originalText || null,
252
+ reason: 'ambiguous_or_unmatched_pending_edit',
253
+ });
254
+ }
255
+ }
256
+ if (failedBufferedOps.length > 0) {
257
+ console.error(JSON.stringify({
258
+ error: 'manual_edit_buffer_apply_failed',
259
+ pendingOps: failedBufferedOps,
260
+ hint: 'A staged copy edit appears to affect the selected source block, but could not be applied unambiguously to the wrap original. Apply or discard copy edits first, or write the wrapper manually.',
261
+ }));
262
+ process.exit(1);
263
+ }
264
+ }
265
+
266
+ const originalBaseIndent = minLeadingSpaces(originalLines);
267
+ const reindentOriginal = (extra) => originalLines
268
+ .map((l) => (l.trim() === '' ? '' : indent + extra + l.slice(originalBaseIndent)))
269
+ .join('\n');
270
+ const originalIndented = reindentOriginal(' ');
271
+ const relTargetFile = path.relative(process.cwd(), targetFile).split(path.sep).join('/');
272
+ const useSvelteComponent = shouldUseSvelteComponentInjection(targetFile);
273
+
274
+ // Wrapper attributes differ by syntax. HTML allows plain string attrs;
275
+ // JSX requires object-literal style and parses string attrs as HTML (which
276
+ // either type-errors or renders a literal CSS string).
277
+ const styleContents = isJsx ? 'style={{ display: "contents" }}' : 'style="display: contents"';
278
+
279
+ // JSX/TSX guard: the picked element occupies a single JSX child slot
280
+ // (inside `return (...)`, an array `.map(...)`, an `asChild` branch, or
281
+ // any other expression position). Replacing it with `comment + <div> +
282
+ // comment` yields three adjacent siblings — invalid JSX. We can't use a
283
+ // Fragment `<></>` either: parents that clone children (Radix `asChild`,
284
+ // Headless UI, etc.) hit "Invalid prop supplied to React.Fragment" when
285
+ // they try to pass an `id` through.
286
+ //
287
+ // Solution: keep the wrapper `<div>` as the single JSX-slot child and
288
+ // tuck both marker comments INSIDE it. accept/discard then expands its
289
+ // replacement range to include the wrapper's `<div>` open / close lines
290
+ // so the entire scaffold gets removed cleanly.
291
+ const wrapperLines = isJsx ? [
292
+ indent + '<div data-monodesign-variants="' + id + '" data-monodesign-variant-count="' + count + '" ' + styleContents + '>',
293
+ indent + ' ' + commentSyntax.open + ' monodesign-variants-start ' + id + ' ' + commentSyntax.close,
294
+ indent + ' ' + commentSyntax.open + ' Original ' + commentSyntax.close,
295
+ indent + ' <div data-monodesign-variant="original">',
296
+ reindentOriginal(' '),
297
+ indent + ' </div>',
298
+ indent + ' ' + commentSyntax.open + ' Variants: insert below this line ' + commentSyntax.close,
299
+ indent + ' ' + commentSyntax.open + ' monodesign-variants-end ' + id + ' ' + commentSyntax.close,
300
+ indent + '</div>',
301
+ ] : [
302
+ indent + commentSyntax.open + ' monodesign-variants-start ' + id + ' ' + commentSyntax.close,
303
+ indent + '<div data-monodesign-variants="' + id + '" data-monodesign-variant-count="' + count + '" ' + styleContents + '>',
304
+ indent + ' ' + commentSyntax.open + ' Original ' + commentSyntax.close,
305
+ indent + ' <div data-monodesign-variant="original">',
306
+ originalIndented,
307
+ indent + ' </div>',
308
+ indent + ' ' + commentSyntax.open + ' Variants: insert below this line ' + commentSyntax.close,
309
+ indent + '</div>',
310
+ indent + commentSyntax.open + ' monodesign-variants-end ' + id + ' ' + commentSyntax.close,
311
+ ];
312
+
313
+ let outputFile = targetFile;
314
+ let outputLines;
315
+ let outputStartLine = startLine + 1;
316
+ let outputEndLine = startLine + wrapperLines.length + (originalLines.length - 1);
317
+ let insertLine;
318
+ let svelteSession = null;
319
+
320
+ if (useSvelteComponent) {
321
+ // Svelte/SvelteKit resets component-local state on markup HMR updates.
322
+ // Keep generation source-neutral: agents write real variant components
323
+ // under the generated componentDir, the browser mounts them into the live
324
+ // DOM, and live-accept.mjs inlines the accepted variant back into the route.
325
+ svelteSession = scaffoldSvelteComponentSession({
326
+ id,
327
+ count,
328
+ sourceFile: relTargetFile,
329
+ sourceStartLine: startLine + 1,
330
+ sourceEndLine: endLine + 1,
331
+ originalLines,
332
+ cwd: process.cwd(),
333
+ });
334
+ outputFile = path.resolve(process.cwd(), svelteSession.manifestFile);
335
+ outputStartLine = 1;
336
+ outputEndLine = 1;
337
+ insertLine = 1;
338
+ } else {
339
+ // Replace the original element with the wrapper
340
+ const newLines = [
341
+ ...lines.slice(0, startLine),
342
+ ...wrapperLines,
343
+ ...lines.slice(endLine + 1),
344
+ ];
345
+ fs.writeFileSync(targetFile, newLines.join('\n'), 'utf-8');
346
+
347
+ // Calculate insert line (the "insert below this line" comment).
348
+ // 0-indexed file position. Both HTML and JSX wrappers have 6 lines above
349
+ // the insert marker (HTML: start-comment + outer-div + Original-comment +
350
+ // original-div + content + close-original-div; JSX: outer-div +
351
+ // start-comment + Original-comment + original-div + content +
352
+ // close-original-div). Multi-line originals push the marker by their
353
+ // extra line count.
354
+ insertLine = startLine + 6 + (originalLines.length - 1) + 1;
355
+ }
356
+
357
+ const outputRelFile = path.relative(process.cwd(), outputFile).split(path.sep).join('/');
358
+
359
+ const svelteComponentAuthoring = useSvelteComponent ? buildSvelteComponentCssAuthoring(count) : null;
360
+
361
+ console.log(JSON.stringify({
362
+ file: outputRelFile,
363
+ sourceFile: useSvelteComponent ? relTargetFile : undefined,
364
+ previewMode: useSvelteComponent ? 'svelte-component' : undefined,
365
+ componentDir: svelteSession?.componentDir,
366
+ propContract: svelteSession?.propContract,
367
+ sourceStartLine: useSvelteComponent ? startLine + 1 : undefined,
368
+ sourceEndLine: useSvelteComponent ? endLine + 1 : undefined,
369
+ startLine: outputStartLine, // 1-indexed for the agent
370
+ // wrapperLines is an array but one element (the original-content slot)
371
+ // is a `\n`-joined multi-line string, so the actual file-row count is
372
+ // wrapperLines.length + (originalLines.length - 1). Without the offset,
373
+ // endLine pointed inside the wrapper for any picked element that
374
+ // spanned more than one source line.
375
+ endLine: outputEndLine, // 1-indexed
376
+ insertLine, // 1-indexed: where variants go
377
+ commentSyntax: commentSyntax,
378
+ styleMode: useSvelteComponent ? 'svelte-component' : styleMode.mode,
379
+ styleTag: useSvelteComponent ? null : styleMode.styleTag,
380
+ cssSelectorPrefixExamples: useSvelteComponent ? [] : buildCssSelectorPrefixExamples(styleMode.mode, count),
381
+ cssAuthoring: useSvelteComponent ? svelteComponentAuthoring : buildCssAuthoring(styleMode, count),
382
+ originalLineCount: originalLines.length,
383
+ }));
384
+ }
385
+
386
+ // ---------------------------------------------------------------------------
387
+ // Helpers
388
+ // ---------------------------------------------------------------------------
389
+
390
+ function argVal(args, flag) {
391
+ const prefix = flag + '=';
392
+ for (const arg of args) {
393
+ if (arg.startsWith(prefix)) return arg.slice(prefix.length);
394
+ }
395
+ const idx = args.indexOf(flag);
396
+ return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : null;
397
+ }
398
+
399
+ function pendingEntriesThatMayAffectWrap(entries, targetFile, originalLines, selectionStartLine, cwd) {
400
+ const targetAbs = path.resolve(cwd, targetFile);
401
+ return (entries || []).filter((entry) => {
402
+ return (entry.ops || []).some((op) => {
403
+ return manualEditMayAffectWrap(op, targetAbs, originalLines, selectionStartLine, cwd);
404
+ });
405
+ });
406
+ }
407
+
408
+ function manualEditMayAffectWrap(op, targetFile, originalLines, selectionStartLine, cwd) {
409
+ const targetAbs = path.resolve(cwd, targetFile);
410
+ if (manualEditHintFallsInsideSelection(op, targetAbs, originalLines, selectionStartLine, cwd)) return true;
411
+ if (manualEditLocatorMatchesSelection(op, originalLines)) return true;
412
+ if (typeof op?.originalText === 'string' && op.originalText.length > 0) {
413
+ return originalLines.join('\n').includes(op.originalText);
414
+ }
415
+ return false;
416
+ }
417
+
418
+ function manualEditHintFallsInsideSelection(op, targetAbs, originalLines, selectionStartLine, cwd) {
419
+ const hintFile = op?.sourceHint?.file;
420
+ const hintedLine = Number(op?.sourceHint?.line);
421
+ if (!hintFile || !Number.isFinite(hintedLine)) return false;
422
+ const hintAbs = path.isAbsolute(hintFile) ? hintFile : path.resolve(cwd, hintFile);
423
+ if (path.resolve(hintAbs) !== targetAbs) return false;
424
+ const hintedIndex = hintedLine - 1 - selectionStartLine;
425
+ return hintedIndex >= 0
426
+ && hintedIndex < originalLines.length
427
+ && typeof op?.originalText === 'string'
428
+ && originalLines[hintedIndex].includes(op.originalText);
429
+ }
430
+
431
+ function manualEditLocatorMatchesSelection(op, originalLines) {
432
+ if (!op || typeof op.originalText !== 'string' || op.originalText.length === 0) return false;
433
+ return originalLines.some((line) => (
434
+ line.includes(op.originalText) && lineMatchesManualEditLocator(line, op)
435
+ ));
436
+ }
437
+
438
+ function applyBufferedManualEditToLines(originalLines, selectionStartLine, op) {
439
+ if (
440
+ !op
441
+ || typeof op.originalText !== 'string'
442
+ || op.originalText.length === 0
443
+ || typeof op.newText !== 'string'
444
+ ) {
445
+ return { lines: originalLines, changed: false };
446
+ }
447
+
448
+ const replaceLine = (lineIndex) => ({
449
+ lines: originalLines.map((line, index) => (
450
+ index === lineIndex ? replaceOnce(line, op.originalText, op.newText) : line
451
+ )),
452
+ changed: true,
453
+ });
454
+
455
+ const hintedLine = Number(op.sourceHint?.line);
456
+ if (Number.isFinite(hintedLine)) {
457
+ const hintedIndex = hintedLine - 1 - selectionStartLine;
458
+ if (hintedIndex >= 0 && hintedIndex < originalLines.length && originalLines[hintedIndex].includes(op.originalText)) {
459
+ return replaceLine(hintedIndex);
460
+ }
461
+ }
462
+
463
+ const locatorMatches = [];
464
+ for (let index = 0; index < originalLines.length; index += 1) {
465
+ const line = originalLines[index];
466
+ if (!line.includes(op.originalText)) continue;
467
+ if (!lineMatchesManualEditLocator(line, op)) continue;
468
+ locatorMatches.push(index);
469
+ }
470
+ if (locatorMatches.length === 1) return replaceLine(locatorMatches[0]);
471
+
472
+ const originalBlock = originalLines.join('\n');
473
+ if (countOccurrences(originalBlock, op.originalText) === 1) {
474
+ return {
475
+ lines: replaceOnce(originalBlock, op.originalText, op.newText).split('\n'),
476
+ changed: true,
477
+ };
478
+ }
479
+
480
+ return { lines: originalLines, changed: false };
481
+ }
482
+
483
+ function lineMatchesManualEditLocator(line, op) {
484
+ if (op.tag) {
485
+ const tagRe = new RegExp('<\\s*' + escapeRegExp(op.tag) + '(?=[\\s>/]|$)', 'i');
486
+ if (!tagRe.test(line)) return false;
487
+ }
488
+
489
+ if (op.elementId) {
490
+ const id = escapeRegExp(op.elementId);
491
+ const idRe = new RegExp('\\bid\\s*=\\s*["\']' + id + '["\']');
492
+ if (!idRe.test(line)) return false;
493
+ }
494
+
495
+ const classes = Array.isArray(op.classes) ? op.classes.filter(Boolean) : [];
496
+ for (const className of classes) {
497
+ if (!line.includes(className)) return false;
498
+ }
499
+
500
+ return true;
501
+ }
502
+
503
+ function replaceOnce(value, needle, replacement) {
504
+ const index = value.indexOf(needle);
505
+ if (index === -1) return value;
506
+ return value.slice(0, index) + replacement + value.slice(index + needle.length);
507
+ }
508
+
509
+ function countOccurrences(value, needle) {
510
+ if (!needle) return 0;
511
+ let count = 0;
512
+ let index = 0;
513
+ while (true) {
514
+ index = value.indexOf(needle, index);
515
+ if (index === -1) return count;
516
+ count += 1;
517
+ index += needle.length;
518
+ }
519
+ }
520
+
521
+ function escapeRegExp(value) {
522
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
523
+ }
524
+
525
+ /**
526
+ * Build search query strings in priority order (most specific first).
527
+ * ID is most reliable, then specific class combos, then single classes, then raw query.
528
+ */
529
+ function buildSearchQueries(elementId, classes, tag, query) {
530
+ const queries = [];
531
+
532
+ // 1. ID is the most specific
533
+ if (elementId) {
534
+ queries.push('id="' + elementId + '"');
535
+ }
536
+
537
+ // 2. Full class attribute match (for elements with distinctive multi-class combos).
538
+ // Emit both class="..." (HTML) and className="..." (React/JSX) so whichever
539
+ // convention the file uses will match.
540
+ if (classes) {
541
+ const classList = splitClassList(classes);
542
+ if (classList.length > 1) {
543
+ const joined = classList.join(' ');
544
+ const sorted = [...classList].sort((a, b) => b.length - a.length);
545
+ queries.push('class="' + joined + '"');
546
+ queries.push('className="' + joined + '"');
547
+ for (const className of sorted) {
548
+ queries.push(className);
549
+ }
550
+ } else if (classList.length === 1) {
551
+ queries.push(classList[0]);
552
+ }
553
+ }
554
+
555
+ // 3. Tag + class combo (e.g., <section class="hero">).
556
+ // Same dual-emit for JSX compatibility.
557
+ if (tag && classes) {
558
+ const firstClass = splitClassList(classes)[0];
559
+ queries.push('<' + tag + ' class="' + firstClass);
560
+ queries.push('<' + tag + ' className="' + firstClass);
561
+ }
562
+
563
+ // 4. Raw fallback query
564
+ if (query) {
565
+ queries.push(query);
566
+ }
567
+
568
+ return queries;
569
+ }
570
+
571
+ function splitClassList(classes) {
572
+ return String(classes).split(/[,\s]+/).map(c => c.trim()).filter(Boolean);
573
+ }
574
+
575
+ function attrEscapeDouble(str) {
576
+ return String(str)
577
+ .replace(/&/g, '&amp;')
578
+ .replace(/"/g, '&quot;')
579
+ .replace(/</g, '&lt;')
580
+ .replace(/>/g, '&gt;');
581
+ }
582
+
583
+ function detectCommentSyntax(filePath) {
584
+ const ext = path.extname(filePath).toLowerCase();
585
+ if (ext === '.jsx' || ext === '.tsx') {
586
+ return { open: '{/*', close: '*/}' };
587
+ }
588
+ // HTML, Vue, Svelte, Astro all use HTML comments
589
+ return { open: '<!--', close: '-->' };
590
+ }
591
+
592
+ function detectStyleMode(filePath) {
593
+ const ext = path.extname(filePath).toLowerCase();
594
+ if (ext === '.astro') {
595
+ return {
596
+ mode: 'astro-global-prefixed',
597
+ styleTag: '<style is:inline data-monodesign-css="SESSION_ID">',
598
+ };
599
+ }
600
+ return {
601
+ mode: 'scoped',
602
+ styleTag: '<style data-monodesign-css="SESSION_ID">',
603
+ };
604
+ }
605
+
606
+ function buildCssSelectorPrefixExamples(styleMode, count) {
607
+ if (styleMode !== 'astro-global-prefixed') return [];
608
+ return Array.from({ length: count }, (_, i) => `[data-monodesign-variant="${i + 1}"]`);
609
+ }
610
+
611
+ function buildCssAuthoring(styleMode, count) {
612
+ const variantNumbers = Array.from({ length: count }, (_, i) => i + 1);
613
+ if (styleMode.mode === 'astro-global-prefixed') {
614
+ return {
615
+ mode: styleMode.mode,
616
+ styleTag: styleMode.styleTag,
617
+ strategy: 'global-prefixed',
618
+ rulePattern: '[data-monodesign-variant="N"] > .variant-class { ... }',
619
+ selectorExamples: variantNumbers.map((n) => `[data-monodesign-variant="${n}"] > .variant-class`),
620
+ requirements: [
621
+ 'Use the styleTag exactly; the is:inline attribute is required for this file.',
622
+ 'Put raw CSS directly between the styleTag opening and a plain </style> close.',
623
+ 'Prefix every preview selector with the matching [data-monodesign-variant="N"] selector.',
624
+ 'Keep selectors anchored to the generated variant wrapper; do not rely on component CSS scoping for preview rules.',
625
+ ],
626
+ forbidden: [
627
+ 'Do not use @scope for this styleMode.',
628
+ 'Do not wrap style content in a JSX/TSX template literal ({` ... `}); that syntax is for .tsx/.jsx only.',
629
+ 'Do not put { immediately after the style opening tag; Astro parses { as expression syntax.',
630
+ ],
631
+ };
632
+ }
633
+ return {
634
+ mode: styleMode.mode,
635
+ styleTag: styleMode.styleTag,
636
+ strategy: 'scope-rule',
637
+ rulePattern: '@scope ([data-monodesign-variant="N"]) { :scope > .variant-class { ... } }',
638
+ selectorExamples: variantNumbers.map((n) => `@scope ([data-monodesign-variant="${n}"]) { :scope > .variant-class { ... } }`),
639
+ requirements: [
640
+ 'Use @scope blocks keyed to each [data-monodesign-variant="N"] wrapper.',
641
+ 'Inside each @scope block, make :scope rules step into the replacement element with a descendant combinator.',
642
+ 'Use the styleTag exactly; do not add framework-specific style attributes unless this object says to.',
643
+ ],
644
+ forbidden: [
645
+ 'Do not use global [data-monodesign-variant="N"] selector prefixes for this styleMode.',
646
+ 'Do not add is:inline to the style tag for this styleMode.',
647
+ ],
648
+ };
649
+ }
650
+
651
+ /**
652
+ * Search project files for the query string (class name, ID, etc.)
653
+ * Returns the first matching file path, or null.
654
+ */
655
+ function findFileWithQuery(query, cwd, genOpts = {}) {
656
+ const searchDirs = ['src', 'app', 'pages', 'components', 'public', 'views', 'templates', '.'];
657
+ const seen = new Set();
658
+
659
+ for (const dir of searchDirs) {
660
+ const absDir = path.join(cwd, dir);
661
+ if (!fs.existsSync(absDir)) continue;
662
+ const result = searchDir(absDir, query, seen, 0, genOpts);
663
+ if (result) return result;
664
+ }
665
+ return null;
666
+ }
667
+
668
+ function searchDir(dir, query, seen, depth, genOpts) {
669
+ if (depth > 5) return null; // don't go too deep
670
+ const realDir = fs.realpathSync(dir);
671
+ if (seen.has(realDir)) return null;
672
+ seen.add(realDir);
673
+
674
+ let entries;
675
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
676
+ catch { return null; }
677
+
678
+ // Check files first
679
+ for (const entry of entries) {
680
+ if (!entry.isFile()) continue;
681
+ const ext = path.extname(entry.name).toLowerCase();
682
+ if (!EXTENSIONS.includes(ext)) continue;
683
+
684
+ const filePath = path.join(dir, entry.name);
685
+ if (!genOpts.includeGenerated && isGeneratedFile(filePath, genOpts)) continue;
686
+ try {
687
+ const content = fs.readFileSync(filePath, 'utf-8');
688
+ if (content.includes(query)) return filePath;
689
+ } catch { /* skip unreadable files */ }
690
+ }
691
+
692
+ // Then recurse into directories. Always skip node_modules and .git (never
693
+ // project content). dist/build/out are left to the isGeneratedFile guard so
694
+ // the includeGenerated second-pass can still find the element there and
695
+ // report `generatedMatch`.
696
+ for (const entry of entries) {
697
+ if (!entry.isDirectory()) continue;
698
+ if (entry.name === 'node_modules' || entry.name === '.git') continue;
699
+ const result = searchDir(path.join(dir, entry.name), query, seen, depth + 1, genOpts);
700
+ if (result) return result;
701
+ }
702
+
703
+ return null;
704
+ }
705
+
706
+ /**
707
+ * Regex that matches a tag opener on a line. Allows the tag name to be
708
+ * followed by whitespace, `>`, `/`, or end-of-line so that multi-line JSX
709
+ * openers (e.g. `<section\n className="..."\n>`) are recognised.
710
+ */
711
+ const OPENER_RE = /<([A-Za-z][A-Za-z0-9]*)(?=[\s/>]|$)/;
712
+
713
+ /**
714
+ * Find the element's start and end line in the file.
715
+ *
716
+ * `query` is a class name, attribute fragment (`class="..."`, `className="..."`,
717
+ * `id="..."`), or a raw text snippet. Because a query can appear on a
718
+ * continuation line of a multi-line tag (e.g. the `className="..."` row of a
719
+ * `<section\n className="..."\n>` JSX tag), we walk backward from the match
720
+ * line to find the actual tag opener. When `tag` is provided, opener candidates
721
+ * must match that tag name.
722
+ */
723
+ /**
724
+ * Return the smallest leading-whitespace count across a set of lines,
725
+ * ignoring blank lines (whose indent isn't load-bearing). Used to compute
726
+ * the common base indent of a multi-line picked element so reindenting
727
+ * under the wrapper preserves the relative depth between lines.
728
+ */
729
+ function minLeadingSpaces(lines) {
730
+ let min = Infinity;
731
+ for (const l of lines) {
732
+ if (l.trim() === '') continue;
733
+ const m = l.match(/^(\s*)/);
734
+ if (m && m[1].length < min) min = m[1].length;
735
+ }
736
+ return min === Infinity ? 0 : min;
737
+ }
738
+
739
+ function findElement(lines, query, tag = null) {
740
+ // Iterate all matches — the first substring hit isn't always the right one.
741
+ for (let i = 0; i < lines.length; i++) {
742
+ if (!lines[i].includes(query)) continue;
743
+
744
+ const stripped = lines[i].trim();
745
+ if (stripped.startsWith('<!--') || stripped.startsWith('{/*') || stripped.startsWith('//')) continue;
746
+ // Skip lines already inside a variant wrapper
747
+ if (lines[i].includes('data-monodesign-variant')) continue;
748
+
749
+ const openerLine = findOpenerLine(lines, i, tag);
750
+ if (openerLine === -1) continue;
751
+
752
+ const endLine = findClosingLine(lines, openerLine);
753
+ return { startLine: openerLine, endLine };
754
+ }
755
+
756
+ return null;
757
+ }
758
+
759
+ /**
760
+ * Like findElement, but returns every match. Used for ambiguity detection
761
+ * when the agent passes --text: when the same className appears on multiple
762
+ * sibling elements (a list of cards, repeated section variants, etc.),
763
+ * first-match silently lands on the wrong branch. Returning all matches lets
764
+ * the caller narrow by textContent or fail with a structured ambiguity error.
765
+ */
766
+ function findAllElements(lines, query, tag = null) {
767
+ const out = [];
768
+ const seen = new Set();
769
+ for (let i = 0; i < lines.length; i++) {
770
+ if (!lines[i].includes(query)) continue;
771
+ const stripped = lines[i].trim();
772
+ if (stripped.startsWith('<!--') || stripped.startsWith('{/*') || stripped.startsWith('//')) continue;
773
+ if (lines[i].includes('data-monodesign-variant')) continue;
774
+ const openerLine = findOpenerLine(lines, i, tag);
775
+ if (openerLine === -1) continue;
776
+ if (seen.has(openerLine)) continue; // multiple matches inside the same element
777
+ seen.add(openerLine);
778
+ const endLine = findClosingLine(lines, openerLine);
779
+ out.push({ startLine: openerLine, endLine });
780
+ }
781
+ return out;
782
+ }
783
+
784
+ /**
785
+ * Narrow a candidate set to those whose source body matches a meaningful
786
+ * prefix of the picked element's textContent. The compare strips tags and
787
+ * JSX expressions, then checks two whitespace normalizations side-by-side:
788
+ *
789
+ * - single-space ("hero two second card body")
790
+ * - no-whitespace ("herotwosecondcardbody")
791
+ *
792
+ * Both are needed because `el.textContent` concatenates sibling text without
793
+ * inserting whitespace (e.g. `<h1>Hero Two</h1><p>Second…</p>` reads as
794
+ * `"Hero TwoSecond…"`), while the source has whitespace between tags. If
795
+ * EITHER normalization matches, the candidate keeps. A snippet shorter than
796
+ * 8 chars after stripping is too weak to disambiguate — the caller falls
797
+ * back to first-match.
798
+ */
799
+ function filterByText(candidates, lines, text) {
800
+ const trimmed = text.replace(/\s+/g, ' ').trim().toLowerCase().slice(0, 80);
801
+ // Too short to disambiguate. Return [] so the caller's `filtered.length
802
+ // === 0` branch fires (fall back to first-match) — the previous
803
+ // `candidates.slice()` return forced `filtered.length > 1` and surfaced
804
+ // a spurious `element_ambiguous` error on every short-text picker event
805
+ // with multiple candidates.
806
+ if (trimmed.length < 8) return [];
807
+ const targetSpaced = trimmed;
808
+ const targetCompact = trimmed.replace(/\s+/g, '');
809
+
810
+ return candidates.filter((c) => {
811
+ const body = lines.slice(c.startLine, c.endLine + 1).join(' ');
812
+ const inner = body
813
+ .replace(/<[^>]*>/g, ' ') // strip HTML/JSX tags
814
+ .replace(/\{[^}]*\}/g, ' ') // strip JSX expressions
815
+ .toLowerCase();
816
+ const sourceSpaced = inner.replace(/\s+/g, ' ').trim();
817
+ const sourceCompact = inner.replace(/\s+/g, '');
818
+ return sourceSpaced.includes(targetSpaced) || sourceCompact.includes(targetCompact);
819
+ });
820
+ }
821
+
822
+ /**
823
+ * Resolve a match line to the real tag opener. If the match line itself opens
824
+ * a tag, return it. Otherwise walk up to 10 lines backward looking for the
825
+ * first tag opener. If `tag` is specified, the opener must match that tag
826
+ * name; an opener with a different tag name aborts the backward walk for this
827
+ * match (we don't jump across element boundaries).
828
+ *
829
+ * Returns the line index of the opener, or -1 if none can be resolved.
830
+ */
831
+ function findOpenerLine(lines, matchLine, tag) {
832
+ const self = lines[matchLine].match(OPENER_RE);
833
+ if (self) {
834
+ if (!tag || self[1] === tag) return matchLine;
835
+ return -1;
836
+ }
837
+ const MAX_BACKWALK = 10;
838
+ for (let i = matchLine - 1; i >= Math.max(0, matchLine - MAX_BACKWALK); i--) {
839
+ const opener = lines[i].match(OPENER_RE);
840
+ if (!opener) continue;
841
+ if (!tag || opener[1] === tag) return i;
842
+ // Different tag name than requested — abort; we're inside a non-target opener.
843
+ return -1;
844
+ }
845
+ return -1;
846
+ }
847
+
848
+ /**
849
+ * Starting from a line with an opening tag, find the line with the matching
850
+ * closing tag by counting tag nesting depth.
851
+ */
852
+ function findClosingLine(lines, start) {
853
+ const openMatch = lines[start].match(OPENER_RE);
854
+ if (!openMatch) return start; // caller passed a non-opener; nothing to span
855
+
856
+ const tagName = openMatch[1];
857
+ let depth = 0;
858
+ const openRe = new RegExp('<' + tagName + '(?=[\\s/>]|$)', 'g');
859
+ const selfCloseRe = new RegExp('<' + tagName + '[^>]*/>', 'g');
860
+ const closeRe = new RegExp('</' + tagName + '\\s*>', 'g');
861
+
862
+ for (let i = start; i < lines.length; i++) {
863
+ const line = lines[i];
864
+ const opens = (line.match(openRe) || []).length;
865
+ const selfCloses = (line.match(selfCloseRe) || []).length;
866
+ const closes = (line.match(closeRe) || []).length;
867
+
868
+ depth += opens - selfCloses - closes;
869
+
870
+ if (depth <= 0) return i;
871
+ }
872
+
873
+ // If we can't find the close, return a reasonable guess
874
+ return Math.min(start + 50, lines.length - 1);
875
+ }
876
+
877
+ // Auto-execute when run directly (node live-wrap.mjs ...)
878
+ const _running = process.argv[1];
879
+ if (_running?.endsWith('live-wrap.mjs') || _running?.endsWith('live-wrap.mjs/')) {
880
+ wrapCli();
881
+ }
882
+
883
+ // Test exports (used by tests/live-wrap.test.mjs)
884
+ export {
885
+ buildSearchQueries,
886
+ findElement,
887
+ findClosingLine,
888
+ detectCommentSyntax,
889
+ findAllElements,
890
+ filterByText,
891
+ findFileWithQuery,
892
+ detectStyleMode,
893
+ buildCssAuthoring,
894
+ buildCssSelectorPrefixExamples,
895
+ };