monomind 2.5.0 → 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 +169 -18
  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 +211 -13
  277. package/packages/@monomind/cli/package.json +6 -4
  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,1062 @@
1
+ // Pattern adapted from impeccable (Apache-2.0) — rebranded for monomind
2
+ /**
3
+ * Context loader: prints PRODUCT.md (and DESIGN.md if present) as one
4
+ * markdown block on stdout, or prints a `NO_PRODUCT_MD:` message when no
5
+ * PRODUCT.md is found anywhere. The skill keys off that message to branch:
6
+ * from-scratch build commands (init / teach / craft / shape) and clear
7
+ * build/shape intent divert into the init flow, while scoped commands proceed
8
+ * using the existing code as context.
9
+ *
10
+ * Path resolution (first match wins):
11
+ * 1. Active project root, if PRODUCT.md or DESIGN.md is there. An explicit
12
+ * --target selects the active project: the workspace child in a
13
+ * monorepo, or the nearest directory around the target carrying
14
+ * canonical context files in an ordinary repo (issue #376).
15
+ * 2. Active project .agents/context/ then docs/
16
+ * 3. Repo root context, using the same order, as a per-file fallback
17
+ * whenever the active project is nested below it
18
+ * 4. $MONODESIGN_CONTEXT_DIR (absolute or cwd-relative) — power-user
19
+ * escape hatch, only consulted when defaults are empty
20
+ * 5. Active project root as a "nothing found" default
21
+ *
22
+ * `resolveContextDir()` and `loadContext()` are also exported for the
23
+ * server-side scripts (live.mjs, live-server.mjs) that need the structured
24
+ * shape rather than the markdown block.
25
+ */
26
+ import fs from 'node:fs';
27
+ import os from 'node:os';
28
+ import path from 'node:path';
29
+ import { fileURLToPath } from 'node:url';
30
+ import { parseTargetOptions } from './lib/target-args.mjs';
31
+ import { MONODESIGN_COMMAND } from './lib/provider.mjs';
32
+
33
+ const PRODUCT_NAMES = ['PRODUCT.md', 'Product.md', 'product.md'];
34
+ const DESIGN_NAMES = ['DESIGN.md', 'Design.md', 'design.md'];
35
+ const FALLBACK_DIRS = ['.agents/context', 'docs'];
36
+ const MONOREPO_MARKER_FILES = ['pnpm-workspace.yaml', 'turbo.json', 'nx.json', 'lerna.json'];
37
+ const MONOREPO_FALLBACK_PROJECT_DIRS = ['apps', 'packages'];
38
+ const WORKSPACE_DISCOVERY_IGNORED_DIRS = new Set([
39
+ 'node_modules',
40
+ '.git',
41
+ 'dist',
42
+ 'build',
43
+ '.next',
44
+ '.nuxt',
45
+ '.svelte-kit',
46
+ '.turbo',
47
+ '.cache',
48
+ 'coverage',
49
+ ]);
50
+
51
+ // ─── Update check ──────────────────────────────────────────────────────────
52
+ // Piggyback a lightweight skill-version check on the once-per-session boot.
53
+ // When a newer skill ships, append an UPDATE_AVAILABLE directive so the agent
54
+ // can offer `monomind design update`. Everything here is best-effort and
55
+ // silent on failure: a network problem, sandbox, or missing cache must never
56
+ // block context output or print an error.
57
+
58
+ const UPDATE_HOST = (process.env.MONODESIGN_UPDATE_HOST || 'https://github.com/monoes/monomind').replace(/\/$/, '');
59
+ const UPDATE_CACHE_PATH =
60
+ process.env.MONODESIGN_UPDATE_CACHE || path.join(os.homedir(), '.monodesign', 'update-check.json');
61
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // throttle the network poll to once a day
62
+ const RENOTIFY_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000; // don't re-surface the same version for a week
63
+ const FETCH_TIMEOUT_MS = 1200;
64
+
65
+ export function resolveContextDir(cwd = process.cwd(), options = {}) {
66
+ return resolveContext(cwd, options).contextDir;
67
+ }
68
+
69
+ export function loadContext(cwd = process.cwd(), options = {}) {
70
+ const resolved = resolveContext(cwd, options);
71
+ const absCwd = path.resolve(cwd);
72
+ const productPath = resolved.productPath;
73
+ const designPath = resolved.designPath;
74
+ const product = productPath ? safeRead(productPath) : null;
75
+ const design = designPath ? safeRead(designPath) : null;
76
+ return {
77
+ hasProduct: !!product,
78
+ product,
79
+ productPath: productPath ? path.relative(absCwd, productPath) : null,
80
+ hasDesign: !!design,
81
+ design,
82
+ designPath: designPath ? path.relative(absCwd, designPath) : null,
83
+ contextDir: resolved.contextDir,
84
+ productContextDir: productPath ? path.dirname(productPath) : null,
85
+ designContextDir: designPath ? path.dirname(designPath) : null,
86
+ projectRoot: resolved.projectRoot,
87
+ repoRoot: resolved.repoRoot,
88
+ isMonorepo: resolved.isMonorepo,
89
+ };
90
+ }
91
+
92
+ function resolveContext(cwd = process.cwd(), options = {}) {
93
+ const absCwd = path.resolve(cwd);
94
+ const project = resolveProject(absCwd, options);
95
+ const projectContextDir = resolveLocalContextDir(project.projectRoot);
96
+ // Per-file inheritance from the repo root whenever the active project is
97
+ // nested below it: monorepo workspace children and explicit-target nested
98
+ // products in ordinary repos behave the same way.
99
+ const rootContextDir = project.repoRoot !== project.projectRoot
100
+ ? resolveLocalContextDir(project.repoRoot)
101
+ : null;
102
+
103
+ let productPath =
104
+ (projectContextDir ? firstExisting(projectContextDir, PRODUCT_NAMES) : null)
105
+ || (rootContextDir ? firstExisting(rootContextDir, PRODUCT_NAMES) : null);
106
+ let designPath =
107
+ (projectContextDir ? firstExisting(projectContextDir, DESIGN_NAMES) : null)
108
+ || (rootContextDir ? firstExisting(rootContextDir, DESIGN_NAMES) : null);
109
+
110
+ let envContextDir = null;
111
+ if (!productPath && !designPath) {
112
+ envContextDir = resolveEnvContextDir(absCwd);
113
+ if (envContextDir) {
114
+ productPath = firstExisting(envContextDir, PRODUCT_NAMES);
115
+ designPath = firstExisting(envContextDir, DESIGN_NAMES);
116
+ }
117
+ }
118
+
119
+ return {
120
+ contextDir: productPath
121
+ ? path.dirname(productPath)
122
+ : designPath
123
+ ? path.dirname(designPath)
124
+ : envContextDir || project.projectRoot,
125
+ productPath,
126
+ designPath,
127
+ projectRoot: project.projectRoot,
128
+ repoRoot: project.repoRoot,
129
+ isMonorepo: project.isMonorepo,
130
+ targetDir: project.targetDir,
131
+ };
132
+ }
133
+
134
+ export function resolveProjectRoot(cwd = process.cwd(), options = {}) {
135
+ return resolveProject(cwd, options).projectRoot;
136
+ }
137
+
138
+ export function resolveTargetSelection(cwd = process.cwd(), options = {}) {
139
+ if (hasTargetOption(options)) return null;
140
+ const project = resolveProject(cwd);
141
+ if (
142
+ !project.isMonorepo
143
+ || !project.projectRoot
144
+ || !project.repoRoot
145
+ || path.resolve(project.projectRoot) !== path.resolve(project.repoRoot)
146
+ ) {
147
+ return null;
148
+ }
149
+ const targetCandidates = discoverTargetCandidates(project.repoRoot);
150
+ // No discoverable child apps (e.g. `workspaces: ["."]`, a root-only workspace,
151
+ // or a marker file with no apps/packages children): there is nothing to choose,
152
+ // so treat the repo root as the active project rather than blocking on an empty
153
+ // selection prompt that the user cannot answer.
154
+ if (targetCandidates.length === 0) return null;
155
+ return {
156
+ targetPath: null,
157
+ projectRoot: project.projectRoot,
158
+ repoRoot: project.repoRoot,
159
+ targetCandidates,
160
+ };
161
+ }
162
+
163
+ function resolveProject(cwd = process.cwd(), options = {}) {
164
+ const absCwd = path.resolve(cwd);
165
+ const targetDir = resolveTargetDir(absCwd, options);
166
+ let repoRoot = findMonorepoRoot(targetDir);
167
+ if (!repoRoot && targetDir !== absCwd) {
168
+ const cwdRepoRoot = findMonorepoRoot(absCwd);
169
+ if (cwdRepoRoot && isPathInside(targetDir, cwdRepoRoot)) {
170
+ repoRoot = cwdRepoRoot;
171
+ }
172
+ }
173
+ if (!repoRoot) {
174
+ return {
175
+ targetDir,
176
+ projectRoot: nearestTargetContextRoot(absCwd, targetDir) || absCwd,
177
+ repoRoot: absCwd,
178
+ isMonorepo: false,
179
+ };
180
+ }
181
+ return {
182
+ targetDir,
183
+ projectRoot: resolveWorkspaceProjectRoot(repoRoot, targetDir) || repoRoot,
184
+ repoRoot,
185
+ isMonorepo: true,
186
+ };
187
+ }
188
+
189
+ function isPathInside(candidate, root) {
190
+ const rel = path.relative(root, candidate);
191
+ return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel);
192
+ }
193
+
194
+ function resolveLocalContextDir(root) {
195
+ if (firstExisting(root, [...PRODUCT_NAMES, ...DESIGN_NAMES])) {
196
+ return root;
197
+ }
198
+ for (const rel of FALLBACK_DIRS) {
199
+ const candidate = path.resolve(root, rel);
200
+ if (firstExisting(candidate, [...PRODUCT_NAMES, ...DESIGN_NAMES])) {
201
+ return candidate;
202
+ }
203
+ }
204
+ return null;
205
+ }
206
+
207
+ function resolveEnvContextDir(cwd) {
208
+ const envDir = process.env.MONODESIGN_CONTEXT_DIR;
209
+ if (!envDir || !envDir.trim()) return null;
210
+ const trimmed = envDir.trim();
211
+ return path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
212
+ }
213
+
214
+ function resolveTargetDir(cwd, options = {}) {
215
+ const targetPath = options && typeof options === 'object' ? options.targetPath : null;
216
+ if (!targetPath || !String(targetPath).trim()) return cwd;
217
+ const abs = path.isAbsolute(targetPath) ? targetPath : path.resolve(cwd, targetPath);
218
+ try {
219
+ const stat = fs.statSync(abs);
220
+ return stat.isDirectory() ? abs : path.dirname(abs);
221
+ } catch {
222
+ return path.extname(abs) ? path.dirname(abs) : abs;
223
+ }
224
+ }
225
+
226
+ function findMonorepoRoot(startDir) {
227
+ let dir = path.resolve(startDir);
228
+ const homeDir = path.resolve(os.homedir());
229
+ while (true) {
230
+ if (dir === homeDir) return null;
231
+ // isMonorepoRoot is checked before hasGitBoundary on purpose: a workspace
232
+ // root that also carries its own .git is still recognized. The trade-off is
233
+ // deliberate — a directory with a monorepo *marker* but no workspace patterns
234
+ // and no apps/packages children is not a monorepo root, so its .git stops
235
+ // traversal and a further-up root is not searched. The nested .git is treated
236
+ // as an independent project boundary, which is the intended isolation.
237
+ if (isMonorepoRoot(dir)) return dir;
238
+ if (hasGitBoundary(dir)) return null;
239
+ const parent = path.dirname(dir);
240
+ if (parent === dir) return null;
241
+ dir = parent;
242
+ }
243
+ }
244
+
245
+ function isMonorepoRoot(dir) {
246
+ if (readWorkspacePatterns(dir).some((pattern) => !normalizeWorkspacePattern(pattern).startsWith('!'))) return true;
247
+ if (!MONOREPO_MARKER_FILES.some((file) => fs.existsSync(path.join(dir, file)))) return false;
248
+ return hasFallbackWorkspaceChildren(dir);
249
+ }
250
+
251
+ function hasGitBoundary(dir) {
252
+ return fs.existsSync(path.join(dir, '.git'));
253
+ }
254
+
255
+ function hasFallbackWorkspaceChildren(dir) {
256
+ for (const name of MONOREPO_FALLBACK_PROJECT_DIRS) {
257
+ const base = path.join(dir, name);
258
+ let entries;
259
+ try {
260
+ entries = fs.readdirSync(base, { withFileTypes: true });
261
+ } catch {
262
+ continue;
263
+ }
264
+ if (entries.some((entry) => entry.isDirectory() && !isIgnoredWorkspaceDiscoveryDir(entry.name))) return true;
265
+ }
266
+ return false;
267
+ }
268
+
269
+ function discoverTargetCandidates(repoRoot) {
270
+ const roots = new Map();
271
+ const patterns = readWorkspacePatterns(repoRoot);
272
+ for (const pattern of patterns) {
273
+ for (const root of discoverRootsForPattern(repoRoot, pattern)) {
274
+ roots.set(path.relative(repoRoot, root).split(path.sep).join('/'), root);
275
+ }
276
+ }
277
+ if (MONOREPO_MARKER_FILES.some((file) => fs.existsSync(path.join(repoRoot, file)))) {
278
+ for (const name of MONOREPO_FALLBACK_PROJECT_DIRS) {
279
+ const base = path.join(repoRoot, name);
280
+ let entries;
281
+ try {
282
+ entries = fs.readdirSync(base, { withFileTypes: true });
283
+ } catch {
284
+ continue;
285
+ }
286
+ for (const entry of entries) {
287
+ if (!entry.isDirectory() || isIgnoredWorkspaceDiscoveryDir(entry.name)) continue;
288
+ const root = path.join(base, entry.name);
289
+ roots.set(path.relative(repoRoot, root).split(path.sep).join('/'), root);
290
+ }
291
+ }
292
+ }
293
+ return [...roots.entries()]
294
+ .filter(([rel]) => rel && !rel.startsWith('..'))
295
+ // Honor negated workspace patterns (e.g. "!packages/internal"). resolveWorkspaceProjectRoot
296
+ // sends an excluded package back to the repo root, so an excluded folder must not appear as a
297
+ // selectable target — choosing it would silently resolve to the root instead.
298
+ .filter(([rel]) => !isExcludedByWorkspacePattern(rel.split('/').filter(Boolean), patterns))
299
+ .sort(([a], [b]) => a.localeCompare(b))
300
+ .map(([rel, root]) => {
301
+ const targetExample = findTargetExample(repoRoot, root);
302
+ return {
303
+ name: path.basename(root),
304
+ path: rel,
305
+ targetExample,
306
+ ...resolveCandidateContextSummary(repoRoot, root, targetExample),
307
+ };
308
+ });
309
+ }
310
+
311
+ function resolveCandidateContextSummary(repoRoot, projectRoot, targetPath) {
312
+ const ctx = resolveContext(repoRoot, { targetPath });
313
+ return {
314
+ productStatus: contextSourceStatus(ctx.productPath, repoRoot, projectRoot),
315
+ productPath: contextSourcePath(ctx.productPath, repoRoot),
316
+ designStatus: contextSourceStatus(ctx.designPath, repoRoot, projectRoot),
317
+ designPath: contextSourcePath(ctx.designPath, repoRoot),
318
+ };
319
+ }
320
+
321
+ // Selection candidates surface one of four statuses: 'child' (a canonical
322
+ // PRODUCT.md/DESIGN.md directly in the app root), 'inherited' (resolved from the
323
+ // repo root in a monorepo), 'missing' (no file found), and 'fallback'. 'fallback'
324
+ // intentionally covers two non-canonical locations: a file inside the project
325
+ // root but in a subdirectory (FALLBACK_DIRS, e.g. `.agents/context/`), and a file
326
+ // outside both the project and repo roots (MONODESIGN_CONTEXT_DIR override).
327
+ function contextSourceStatus(filePath, repoRoot, projectRoot) {
328
+ if (!filePath) return 'missing';
329
+ const absPath = path.resolve(filePath);
330
+ const absProjectRoot = path.resolve(projectRoot);
331
+ const absRepoRoot = path.resolve(repoRoot);
332
+ if (isPathInsideOrEqual(absPath, absProjectRoot)) {
333
+ return path.dirname(absPath) === absProjectRoot ? 'child' : 'fallback';
334
+ }
335
+ if (absProjectRoot !== absRepoRoot && isPathInsideOrEqual(absPath, absRepoRoot)) {
336
+ return 'inherited';
337
+ }
338
+ return 'fallback';
339
+ }
340
+
341
+ function contextSourcePath(filePath, repoRoot) {
342
+ if (!filePath) return null;
343
+ const rel = path.relative(repoRoot, filePath);
344
+ if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) {
345
+ return rel.split(path.sep).join('/');
346
+ }
347
+ return filePath;
348
+ }
349
+
350
+ function discoverRootsForPattern(repoRoot, rawPattern) {
351
+ const pattern = normalizeWorkspacePattern(rawPattern);
352
+ if (!pattern || pattern.startsWith('!')) return [];
353
+ const segments = pattern.split('/').filter(Boolean);
354
+ if (!segments.length) return [];
355
+ const firstGlobIndex = segments.findIndex((segment) => segment.includes('*'));
356
+ const literalPrefix = firstGlobIndex === -1 ? segments : segments.slice(0, firstGlobIndex);
357
+ const base = path.join(repoRoot, ...literalPrefix);
358
+ if (!fs.existsSync(base)) return [];
359
+ if (segments.includes('**')) {
360
+ const packageRoots = [];
361
+ walkDirs(base, (dir) => {
362
+ if (dir !== base && isCandidateProjectRoot(dir)) packageRoots.push(dir);
363
+ });
364
+ if (packageRoots.length) return packageRoots;
365
+ return directChildDirs(base);
366
+ }
367
+ return expandSimplePattern(repoRoot, segments);
368
+ }
369
+
370
+ function expandSimplePattern(repoRoot, patternSegments, index = 0, current = repoRoot) {
371
+ if (index >= patternSegments.length) return fs.existsSync(current) ? [current] : [];
372
+ const segment = patternSegments[index];
373
+ if (!segment.includes('*')) {
374
+ return expandSimplePattern(repoRoot, patternSegments, index + 1, path.join(current, segment));
375
+ }
376
+ let entries;
377
+ try {
378
+ entries = fs.readdirSync(current, { withFileTypes: true });
379
+ } catch {
380
+ return [];
381
+ }
382
+ const roots = [];
383
+ for (const entry of entries) {
384
+ if (!entry.isDirectory() || isIgnoredWorkspaceDiscoveryDir(entry.name)) continue;
385
+ if (!segmentMatches(segment, entry.name)) continue;
386
+ roots.push(...expandSimplePattern(repoRoot, patternSegments, index + 1, path.join(current, entry.name)));
387
+ }
388
+ return roots;
389
+ }
390
+
391
+ function directChildDirs(dir) {
392
+ try {
393
+ return fs.readdirSync(dir, { withFileTypes: true })
394
+ .filter((entry) => entry.isDirectory() && !isIgnoredWorkspaceDiscoveryDir(entry.name))
395
+ .map((entry) => path.join(dir, entry.name));
396
+ } catch {
397
+ return [];
398
+ }
399
+ }
400
+
401
+ function walkDirs(root, visit) {
402
+ let entries;
403
+ try {
404
+ entries = fs.readdirSync(root, { withFileTypes: true });
405
+ } catch {
406
+ return;
407
+ }
408
+ for (const entry of entries) {
409
+ if (!entry.isDirectory() || isIgnoredWorkspaceDiscoveryDir(entry.name)) continue;
410
+ const dir = path.join(root, entry.name);
411
+ visit(dir);
412
+ walkDirs(dir, visit);
413
+ }
414
+ }
415
+
416
+ function isCandidateProjectRoot(dir) {
417
+ return !!(
418
+ fs.existsSync(path.join(dir, 'package.json'))
419
+ || firstExisting(dir, [...PRODUCT_NAMES, ...DESIGN_NAMES])
420
+ || fs.existsSync(path.join(dir, 'src'))
421
+ || fs.existsSync(path.join(dir, 'app'))
422
+ || fs.existsSync(path.join(dir, 'pages'))
423
+ || fs.existsSync(path.join(dir, 'public'))
424
+ );
425
+ }
426
+
427
+ function isIgnoredWorkspaceDiscoveryDir(name) {
428
+ return name.startsWith('.') || WORKSPACE_DISCOVERY_IGNORED_DIRS.has(name);
429
+ }
430
+
431
+ function findTargetExample(repoRoot, projectRoot) {
432
+ const examples = [
433
+ 'src/App.jsx',
434
+ 'src/App.tsx',
435
+ 'src/main.jsx',
436
+ 'src/main.tsx',
437
+ 'src/index.jsx',
438
+ 'src/index.ts',
439
+ 'app/page.tsx',
440
+ 'pages/index.tsx',
441
+ 'public/index.html',
442
+ ];
443
+ for (const rel of examples) {
444
+ const abs = path.join(projectRoot, rel);
445
+ if (fs.existsSync(abs)) return path.relative(repoRoot, abs).split(path.sep).join('/');
446
+ }
447
+ return path.relative(repoRoot, projectRoot).split(path.sep).join('/');
448
+ }
449
+
450
+ function resolveWorkspaceProjectRoot(repoRoot, targetDir) {
451
+ const rel = path.relative(repoRoot, targetDir);
452
+ if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return repoRoot;
453
+ const relSegments = rel.split(path.sep).filter(Boolean);
454
+ const patterns = readWorkspacePatterns(repoRoot);
455
+ const excluded = isExcludedByWorkspacePattern(relSegments, patterns);
456
+ if (!excluded) {
457
+ for (const pattern of patterns) {
458
+ const projectRoot = projectRootFromWorkspacePattern(repoRoot, relSegments, pattern);
459
+ if (projectRoot) return projectRoot;
460
+ }
461
+ }
462
+ if (excluded) return repoRoot;
463
+ if (
464
+ relSegments.length >= 2
465
+ && MONOREPO_FALLBACK_PROJECT_DIRS.includes(relSegments[0])
466
+ ) {
467
+ return path.join(repoRoot, relSegments[0], relSegments[1]);
468
+ }
469
+ const nearest = nearestProjectLikeRoot(repoRoot, targetDir);
470
+ if (nearest) return nearest;
471
+ return repoRoot;
472
+ }
473
+
474
+ function isExcludedByWorkspacePattern(relSegments, patterns) {
475
+ return patterns.some((rawPattern) => {
476
+ const pattern = normalizeWorkspacePattern(rawPattern);
477
+ if (!pattern.startsWith('!')) return false;
478
+ return workspacePatternMatchesRel(pattern.slice(1), relSegments);
479
+ });
480
+ }
481
+
482
+ // An explicit --target in an ordinary (non-monorepo) repository must still
483
+ // select a nested product's own context (issue #376). Walk from the target up
484
+ // to — but not including — the invocation root and return the nearest
485
+ // directory carrying context files, in the canonical spot or a fallback dir
486
+ // (resolveLocalContextDir covers both). Context files only, not package.json:
487
+ // without the monorepo root-context fallback, a package.json marker would
488
+ // strand targets inside plain subpackages away from the root PRODUCT.md. The
489
+ // cwd's own fallback context dirs (.agents/context, docs) hold the root
490
+ // project's context, not a nested product, so they never count.
491
+ // Returns null when nothing nested is found, keeping the cwd default.
492
+ function nearestTargetContextRoot(absCwd, targetDir) {
493
+ if (!isPathInside(targetDir, absCwd)) return null;
494
+ const rootFallbackDirs = FALLBACK_DIRS.map((rel) => path.resolve(absCwd, rel));
495
+ let dir = path.resolve(targetDir);
496
+ while (dir && dir !== absCwd) {
497
+ if (!rootFallbackDirs.includes(dir) && resolveLocalContextDir(dir)) {
498
+ return dir;
499
+ }
500
+ const parent = path.dirname(dir);
501
+ if (parent === dir) break;
502
+ dir = parent;
503
+ }
504
+ return null;
505
+ }
506
+
507
+ function nearestProjectLikeRoot(repoRoot, targetDir) {
508
+ let dir = path.resolve(targetDir);
509
+ const stop = path.resolve(repoRoot);
510
+ while (dir && dir !== stop) {
511
+ if (
512
+ firstExisting(dir, [...PRODUCT_NAMES, ...DESIGN_NAMES])
513
+ || fs.existsSync(path.join(dir, 'package.json'))
514
+ ) {
515
+ return dir;
516
+ }
517
+ const parent = path.dirname(dir);
518
+ if (parent === dir) break;
519
+ dir = parent;
520
+ }
521
+ return null;
522
+ }
523
+
524
+ function nearestPackageRootBetween(repoRoot, targetDir, stopDir) {
525
+ let dir = path.resolve(targetDir);
526
+ const stop = path.resolve(stopDir || repoRoot);
527
+ const root = path.resolve(repoRoot);
528
+ while (dir && dir !== stop && isPathInsideOrEqual(dir, root)) {
529
+ if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
530
+ const parent = path.dirname(dir);
531
+ if (parent === dir) break;
532
+ dir = parent;
533
+ }
534
+ return null;
535
+ }
536
+
537
+ function isPathInsideOrEqual(candidate, root) {
538
+ return path.resolve(candidate) === path.resolve(root) || isPathInside(candidate, root);
539
+ }
540
+
541
+ function workspacePatternMatchesRel(pattern, relSegments) {
542
+ const patternSegments = normalizeWorkspacePattern(pattern).split('/').filter(Boolean);
543
+ if (!patternSegments.length) return false;
544
+ if (patternSegments.includes('**')) {
545
+ const firstGlobIndex = patternSegments.findIndex((segment) => segment.includes('*'));
546
+ const literalPrefix = firstGlobIndex === -1
547
+ ? patternSegments
548
+ : patternSegments.slice(0, firstGlobIndex);
549
+ if (relSegments.length < literalPrefix.length + 1) return false;
550
+ for (let i = 0; i < literalPrefix.length; i++) {
551
+ if (!segmentMatches(literalPrefix[i], relSegments[i])) return false;
552
+ }
553
+ return true;
554
+ }
555
+ if (relSegments.length < patternSegments.length) return false;
556
+ for (let i = 0; i < patternSegments.length; i++) {
557
+ if (!segmentMatches(patternSegments[i], relSegments[i])) return false;
558
+ }
559
+ return true;
560
+ }
561
+
562
+ function readWorkspacePatterns(repoRoot) {
563
+ return [
564
+ ...readPackageWorkspaces(repoRoot),
565
+ ...readPnpmWorkspaces(repoRoot),
566
+ ...readLernaWorkspaces(repoRoot),
567
+ ].filter(Boolean);
568
+ }
569
+
570
+ function readPackageWorkspaces(repoRoot) {
571
+ const pkg = readJson(path.join(repoRoot, 'package.json'));
572
+ const workspaces = pkg?.workspaces;
573
+ if (Array.isArray(workspaces)) return workspaces;
574
+ if (Array.isArray(workspaces?.packages)) return workspaces.packages;
575
+ return [];
576
+ }
577
+
578
+ function readLernaWorkspaces(repoRoot) {
579
+ const lerna = readJson(path.join(repoRoot, 'lerna.json'));
580
+ return Array.isArray(lerna?.packages) ? lerna.packages : [];
581
+ }
582
+
583
+ function readPnpmWorkspaces(repoRoot) {
584
+ try {
585
+ const body = fs.readFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), 'utf-8');
586
+ const patterns = [];
587
+ let inPackages = false;
588
+ for (const line of body.split(/\r?\n/)) {
589
+ const trimmed = stripYamlInlineComment(line).trim();
590
+ if (!trimmed || trimmed.startsWith('#')) continue;
591
+ const flowMatch = trimmed.match(/^packages:\s*\[(.*)\]\s*$/);
592
+ if (flowMatch) {
593
+ patterns.push(...parseYamlFlowList(flowMatch[1]));
594
+ inPackages = false;
595
+ continue;
596
+ }
597
+ if (/^packages:\s*$/.test(trimmed)) {
598
+ inPackages = true;
599
+ continue;
600
+ }
601
+ if (inPackages && /^[A-Za-z0-9_-]+:\s*/.test(trimmed)) break;
602
+ if (inPackages) {
603
+ const match = trimmed.match(/^-\s*(.+)$/);
604
+ if (match) patterns.push(unquoteYamlValue(match[1]));
605
+ }
606
+ }
607
+ return patterns;
608
+ } catch {
609
+ return [];
610
+ }
611
+ }
612
+
613
+ function stripYamlInlineComment(line) {
614
+ let quote = null;
615
+ for (let i = 0; i < line.length; i++) {
616
+ const ch = line[i];
617
+ if ((ch === '"' || ch === "'") && line[i - 1] !== '\\') {
618
+ quote = quote === ch ? null : quote || ch;
619
+ continue;
620
+ }
621
+ if (ch === '#' && !quote) return line.slice(0, i);
622
+ }
623
+ return line;
624
+ }
625
+
626
+ function parseYamlFlowList(body) {
627
+ const items = [];
628
+ let quote = null;
629
+ let current = '';
630
+ for (let i = 0; i < body.length; i++) {
631
+ const ch = body[i];
632
+ if ((ch === '"' || ch === "'") && body[i - 1] !== '\\') {
633
+ quote = quote === ch ? null : quote || ch;
634
+ current += ch;
635
+ continue;
636
+ }
637
+ if (ch === ',' && !quote) {
638
+ const value = unquoteYamlValue(current);
639
+ if (value) items.push(value);
640
+ current = '';
641
+ continue;
642
+ }
643
+ current += ch;
644
+ }
645
+ const value = unquoteYamlValue(current);
646
+ if (value) items.push(value);
647
+ return items;
648
+ }
649
+
650
+ function unquoteYamlValue(value) {
651
+ return String(value || '')
652
+ .trim()
653
+ .replace(/^['"]|['"]$/g, '');
654
+ }
655
+
656
+ function readJson(filePath) {
657
+ try {
658
+ return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
659
+ } catch {
660
+ return null;
661
+ }
662
+ }
663
+
664
+ function projectRootFromWorkspacePattern(repoRoot, relSegments, rawPattern) {
665
+ const pattern = normalizeWorkspacePattern(rawPattern);
666
+ if (!pattern || pattern.startsWith('!')) return null;
667
+ const patternSegments = pattern.split('/').filter(Boolean);
668
+ if (!patternSegments.length) return null;
669
+ if (patternSegments.includes('**')) {
670
+ return projectRootFromDoubleStarPattern(repoRoot, relSegments, patternSegments);
671
+ }
672
+ if (relSegments.length < patternSegments.length) return null;
673
+ for (let i = 0; i < patternSegments.length; i++) {
674
+ if (!segmentMatches(patternSegments[i], relSegments[i])) return null;
675
+ }
676
+ return path.join(repoRoot, ...relSegments.slice(0, patternSegments.length));
677
+ }
678
+
679
+ function projectRootFromDoubleStarPattern(repoRoot, relSegments, patternSegments) {
680
+ const firstGlobIndex = patternSegments.findIndex((segment) => segment.includes('*'));
681
+ const literalPrefix = firstGlobIndex === -1
682
+ ? patternSegments
683
+ : patternSegments.slice(0, firstGlobIndex);
684
+ if (relSegments.length < literalPrefix.length + 1) return null;
685
+ for (let i = 0; i < literalPrefix.length; i++) {
686
+ if (!segmentMatches(literalPrefix[i], relSegments[i])) return null;
687
+ }
688
+ const prefixDir = path.join(repoRoot, ...literalPrefix);
689
+ const targetDir = path.join(repoRoot, ...relSegments);
690
+ const packageRoot = nearestPackageRootBetween(repoRoot, targetDir, prefixDir);
691
+ if (packageRoot) return packageRoot;
692
+ return path.join(repoRoot, ...relSegments.slice(0, literalPrefix.length + 1));
693
+ }
694
+
695
+ function normalizeWorkspacePattern(pattern) {
696
+ return String(pattern || '')
697
+ .trim()
698
+ .replace(/^['"]|['"]$/g, '')
699
+ .replace(/^\.\//, '')
700
+ .replace(/\/+$/, '');
701
+ }
702
+
703
+ function segmentMatches(patternSegment, relSegment) {
704
+ if (patternSegment === '*') return true;
705
+ if (!patternSegment.includes('*')) return patternSegment === relSegment;
706
+ const re = new RegExp(`^${escapeRegExp(patternSegment).replace(/\\\*/g, '[^/]*')}$`);
707
+ return re.test(relSegment);
708
+ }
709
+
710
+ function firstExisting(dir, names) {
711
+ for (const name of names) {
712
+ const abs = path.join(dir, name);
713
+ if (fs.existsSync(abs)) return abs;
714
+ }
715
+ return null;
716
+ }
717
+
718
+ function safeRead(p) {
719
+ try {
720
+ return fs.readFileSync(p, 'utf-8');
721
+ } catch {
722
+ return null;
723
+ }
724
+ }
725
+
726
+ function escapeRegExp(value) {
727
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
728
+ }
729
+
730
+ /**
731
+ * Read the first non-empty line under a bare `## <heading>` section of
732
+ * PRODUCT.md (e.g. `## Register`, `## Platform`). Returns null when the
733
+ * section is absent. The heading match is exact (`\s*$`) so near-miss
734
+ * headings like `## Register guidelines` don't shadow the real field.
735
+ */
736
+ export function extractSectionValue(product, heading) {
737
+ if (!product) return null;
738
+ const headingRe = new RegExp(`^##\\s+${escapeRegExp(heading)}\\s*$`, 'i');
739
+ const lines = product.split('\n');
740
+ for (let i = 0; i < lines.length; i++) {
741
+ if (headingRe.test(lines[i].trim())) {
742
+ for (let j = i + 1; j < lines.length; j++) {
743
+ const next = lines[j].trim();
744
+ // A new heading before any value means the section is empty.
745
+ if (/^#{1,6}\s/.test(next)) return null;
746
+ if (next) return next;
747
+ }
748
+ }
749
+ }
750
+ return null;
751
+ }
752
+
753
+ /**
754
+ * Pull the register (`brand` or `product`) out of PRODUCT.md by looking
755
+ * for a `## Register` section and reading the first non-empty line that
756
+ * follows it. Returns null when the file is legacy / register-less.
757
+ */
758
+ export function extractRegister(product) {
759
+ const word = (extractSectionValue(product, 'Register') || '').toLowerCase();
760
+ return word === 'brand' || word === 'product' ? word : null;
761
+ }
762
+
763
+ /**
764
+ * Pull the platform (`web`, `ios`, `android`, or `adaptive`) out of PRODUCT.md
765
+ * by looking for a `## Platform` section and reading the first non-empty line
766
+ * that follows it. `adaptive` is for cross-platform apps (Flutter, React
767
+ * Native) that ship both iOS and Android from one codebase; a line that names
768
+ * both targets (e.g. `ios, android`) is also read as `adaptive`. Returns null
769
+ * when the file is legacy / platform-less, which the skill treats as `web`
770
+ * (the default the general rules already assume).
771
+ */
772
+ export function extractPlatform(product) {
773
+ const value = (extractSectionValue(product, 'Platform') || '').toLowerCase();
774
+ if (!value) return null;
775
+ if (value === 'web' || value === 'ios' || value === 'android' || value === 'adaptive') return value;
776
+ // A short list naming both native targets (`ios, android`, `ios and
777
+ // android`) = adaptive. Only list separators and the two platform words may
778
+ // appear; anything else (prose, negations) is unrecognized and falls
779
+ // through to the CLI's WARNING path.
780
+ const tokens = value.split(/[\s,+&/]+/).filter(t => t && t !== 'and');
781
+ if (tokens.length >= 2 && tokens.every(t => t === 'ios' || t === 'android')
782
+ && tokens.includes('ios') && tokens.includes('android')) {
783
+ return 'adaptive';
784
+ }
785
+ return null;
786
+ }
787
+
788
+ /**
789
+ * Read the installed skill's own version from the sibling SKILL.md frontmatter
790
+ * (this file lives at `<skill>/scripts/context.mjs`). Returns null when the
791
+ * frontmatter is missing or unreadable.
792
+ */
793
+ function readLocalSkillVersion() {
794
+ try {
795
+ const here = path.dirname(fileURLToPath(import.meta.url));
796
+ const skillMd = path.join(here, '..', 'SKILL.md');
797
+ const content = fs.readFileSync(skillMd, 'utf-8');
798
+ const match = content.match(/^version:\s*(.+)$/m);
799
+ return match ? match[1].trim().replace(/^["']|["']$/g, '') : null;
800
+ } catch {
801
+ return null;
802
+ }
803
+ }
804
+
805
+ function readUpdateCache() {
806
+ try {
807
+ return JSON.parse(fs.readFileSync(UPDATE_CACHE_PATH, 'utf-8'));
808
+ } catch {
809
+ return {};
810
+ }
811
+ }
812
+
813
+ function writeUpdateCache(cache) {
814
+ try {
815
+ fs.mkdirSync(path.dirname(UPDATE_CACHE_PATH), { recursive: true });
816
+ fs.writeFileSync(UPDATE_CACHE_PATH, JSON.stringify(cache));
817
+ } catch {
818
+ // Best-effort: a read-only home dir just means we re-poll next session.
819
+ }
820
+ }
821
+
822
+ /** Compare dotted numeric versions. Returns >0 when a is newer than b. */
823
+ function compareSemver(a, b) {
824
+ const pa = String(a).split('.').map(n => parseInt(n, 10) || 0);
825
+ const pb = String(b).split('.').map(n => parseInt(n, 10) || 0);
826
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
827
+ const diff = (pa[i] || 0) - (pb[i] || 0);
828
+ if (diff !== 0) return diff;
829
+ }
830
+ return 0;
831
+ }
832
+
833
+ async function fetchLatestSkillVersion() {
834
+ try {
835
+ const res = await fetch(`${UPDATE_HOST}/api/version`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
836
+ if (!res.ok) return null;
837
+ const data = await res.json();
838
+ return typeof data?.skills === 'string' ? data.skills : null;
839
+ } catch {
840
+ return null; // offline, sandboxed, timed out, or bad JSON: all non-fatal
841
+ }
842
+ }
843
+
844
+ function buildUpdateDirective(localVersion, latestVersion) {
845
+ return (
846
+ `UPDATE_AVAILABLE: A newer Monodesign skill is available ` +
847
+ `(installed v${localVersion}, latest v${latestVersion}). ` +
848
+ `Before continuing, ask the user once: "A newer Monodesign (v${latestVersion}) is available. ` +
849
+ `Update now? It runs \`monomind design update\`." ` +
850
+ `If they agree, run \`monomind design update\` (the update applies to the next session, not this one). ` +
851
+ `Either way, continue the current task without waiting, and do not raise this again.`
852
+ );
853
+ }
854
+
855
+ /**
856
+ * Best-effort update directive for the boot output. Returns a string to append
857
+ * or null. Polls the version endpoint at most once per day (cached globally in
858
+ * the user's home dir) and re-surfaces a given version at most once per week so
859
+ * the agent never nags. Opt out entirely with MONODESIGN_NO_UPDATE_CHECK=1.
860
+ */
861
+ // Read the unified config's top-level `updateCheck` (local overrides shared).
862
+ // Inlined rather than importing hook-lib so the boot path stays lightweight.
863
+ function updateCheckDisabledByConfig(cwd = process.cwd()) {
864
+ let value;
865
+ for (const name of ['config.json', 'config.local.json']) {
866
+ try {
867
+ const raw = JSON.parse(fs.readFileSync(path.join(cwd, '.monodesign', name), 'utf-8'));
868
+ if (raw && typeof raw === 'object' && typeof raw.updateCheck === 'boolean') value = raw.updateCheck;
869
+ } catch { /* missing or malformed: ignore */ }
870
+ }
871
+ return value === false;
872
+ }
873
+
874
+ async function computeUpdateDirective(now = Date.now()) {
875
+ // Update checking is disabled in monomind: the skill ships with the monomind
876
+ // package and follows monomind's own update flow (`monomind update`), so
877
+ // there is no separate registry endpoint to poll. Kept as a stub so the boot
878
+ // path (and MONODESIGN_NO_UPDATE_CHECK-aware tests) stays unchanged.
879
+ return null;
880
+ // eslint-disable-next-line no-unreachable
881
+ try {
882
+ if (process.env.MONODESIGN_NO_UPDATE_CHECK) return null;
883
+ if (updateCheckDisabledByConfig()) return null;
884
+ const localVersion = readLocalSkillVersion();
885
+ if (!localVersion) return null;
886
+
887
+ const cache = readUpdateCache();
888
+
889
+ // Poll the network only when the throttle window has elapsed. Stamp
890
+ // lastCheck even on failure so an offline machine doesn't poll every boot.
891
+ if (!cache.lastCheck || now - cache.lastCheck > CHECK_INTERVAL_MS) {
892
+ const latest = await fetchLatestSkillVersion();
893
+ cache.lastCheck = now;
894
+ if (latest) cache.latestVersion = latest;
895
+ writeUpdateCache(cache);
896
+ }
897
+
898
+ const latest = cache.latestVersion;
899
+ if (!latest || compareSemver(latest, localVersion) <= 0) return null;
900
+
901
+ // Anti-nag: surface a given version at most once per RENOTIFY window.
902
+ if (cache.notifiedVersion === latest && cache.notifiedAt && now - cache.notifiedAt < RENOTIFY_INTERVAL_MS) {
903
+ return null;
904
+ }
905
+ cache.notifiedVersion = latest;
906
+ cache.notifiedAt = now;
907
+ writeUpdateCache(cache);
908
+
909
+ return buildUpdateDirective(localVersion, latest);
910
+ } catch {
911
+ return null;
912
+ }
913
+ }
914
+
915
+ async function cli() {
916
+ let cliOptions;
917
+ try {
918
+ cliOptions = parseCliOptions(process.argv.slice(2));
919
+ } catch (err) {
920
+ if (err?.name === 'TargetArgError') {
921
+ process.stderr.write(`${err.message}\n`);
922
+ process.exit(1);
923
+ }
924
+ throw err;
925
+ }
926
+ const targetProvided = hasTargetOption(cliOptions);
927
+ const targetExists = targetProvided ? pathExistsForTarget(process.cwd(), cliOptions.targetPath) : null;
928
+ const selection = resolveTargetSelection(process.cwd(), cliOptions);
929
+ if (selection) {
930
+ process.stdout.write(buildTargetSelectionDirective(selection) + '\n');
931
+ process.exit(0);
932
+ }
933
+ const ctx = loadContext(process.cwd(), cliOptions);
934
+ const updateDirective = await computeUpdateDirective();
935
+
936
+ if (!ctx.hasProduct) {
937
+ // Direct stdout message instead of relying on empty output as a signal
938
+ // — cheap models miss the empty case more often than the explicit one.
939
+ const parts = [
940
+ 'NO_PRODUCT_MD: This project has no PRODUCT.md yet. ' +
941
+ 'Follow SKILL.md Setup step 1: for `init`, `teach`, `craft`, `shape`, ' +
942
+ 'or wording that clearly maps to a from-scratch build/shape flow, load ' +
943
+ 'reference/init.md and write PRODUCT.md first; for any other (scoped) ' +
944
+ 'command against existing code, proceed using the code as context and ' +
945
+ `offer \`${MONODESIGN_COMMAND} init\` as a suggestion (do not block).`,
946
+ ];
947
+ parts.push(buildResolvedContextDirective(ctx, cliOptions, { targetExists }));
948
+ if (shouldWarnMissingTarget(ctx, targetProvided, targetExists)) {
949
+ parts.push(buildMissingTargetDirective());
950
+ }
951
+ if (updateDirective) parts.push(updateDirective);
952
+ process.stdout.write(parts.join('\n\n---\n\n') + '\n');
953
+ process.exit(0);
954
+ }
955
+ const parts = [`# PRODUCT.md\n\n${ctx.product.trim()}`];
956
+ if (ctx.hasDesign) {
957
+ parts.push(`# DESIGN.md\n\n${ctx.design.trim()}`);
958
+ }
959
+ parts.push(buildResolvedContextDirective(ctx, cliOptions, { targetExists }));
960
+ if (shouldWarnMissingTarget(ctx, targetProvided, targetExists)) {
961
+ parts.push(buildMissingTargetDirective());
962
+ }
963
+ const register = extractRegister(ctx.product);
964
+ const next = register
965
+ ? `NEXT STEP: This project's register is \`${register}\`. You MUST now read \`reference/${register}.md\` before producing any design output.`
966
+ : `NEXT STEP: You MUST now read the matching register reference (\`reference/brand.md\` or \`reference/product.md\`) before producing any design output. Pick based on PRODUCT.md above.`;
967
+ parts.push(next);
968
+ const platform = extractPlatform(ctx.product);
969
+ const nativeRefs =
970
+ platform === 'adaptive' ? ['ios', 'android'] : platform === 'ios' || platform === 'android' ? [platform] : [];
971
+ if (nativeRefs.length) {
972
+ const refList = nativeRefs.map(p => `\`reference/${p}.md\``).join(' and ');
973
+ const label = platform === 'adaptive' ? '`adaptive` (both iOS and Android)' : `\`${platform}\``;
974
+ parts.push(
975
+ `NEXT STEP: This project targets ${label}. Also read ${refList} for native conventions, in addition to the register reference.`,
976
+ );
977
+ } else if (!platform) {
978
+ // A `## Platform` section that names something we don't recognize (a
979
+ // toolchain like `flutter`, a typo) would otherwise silently fall back to
980
+ // web — the wrong default exactly when the user tried to say "native".
981
+ const rawPlatform = extractSectionValue(ctx.product, 'Platform');
982
+ if (rawPlatform) {
983
+ parts.push(
984
+ `WARNING: PRODUCT.md's \`## Platform\` value \`${rawPlatform}\` is not recognized; treating the project as \`web\`. Valid values are \`web\`, \`ios\`, \`android\`, or \`adaptive\` (cross-platform, ships both). If this project is native, fix the field (name the design language the app renders, not the toolchain) and surface it to the user.`,
985
+ );
986
+ }
987
+ }
988
+ if (updateDirective) parts.push(updateDirective);
989
+ process.stdout.write(parts.join('\n\n---\n\n') + '\n');
990
+ }
991
+
992
+ function parseCliOptions(args) {
993
+ return parseTargetOptions(args, { strict: true });
994
+ }
995
+
996
+ function hasTargetOption(options) {
997
+ return !!(options && typeof options.targetPath === 'string' && options.targetPath.trim());
998
+ }
999
+
1000
+ function pathExistsForTarget(cwd, targetPath) {
1001
+ const abs = path.isAbsolute(targetPath) ? targetPath : path.resolve(cwd, targetPath);
1002
+ return fs.existsSync(abs);
1003
+ }
1004
+
1005
+ function buildResolvedContextDirective(ctx, options, { targetExists = null } = {}) {
1006
+ const targetPath = hasTargetOption(options) ? options.targetPath : null;
1007
+ return `RESOLVED_CONTEXT:\n${JSON.stringify({
1008
+ targetPath,
1009
+ ...(targetPath ? { targetExists } : {}),
1010
+ projectRoot: ctx.projectRoot,
1011
+ repoRoot: ctx.repoRoot,
1012
+ productPath: ctx.productPath,
1013
+ designPath: ctx.designPath,
1014
+ }, null, 2)}`;
1015
+ }
1016
+
1017
+ function shouldWarnMissingTarget(ctx, targetProvided, targetExists = null) {
1018
+ if (ctx.isMonorepo && targetProvided && targetExists === false) return true;
1019
+ return !!(
1020
+ ctx.isMonorepo
1021
+ && (!targetProvided || targetExists === false)
1022
+ && ctx.projectRoot
1023
+ && ctx.repoRoot
1024
+ && path.resolve(ctx.projectRoot) === path.resolve(ctx.repoRoot)
1025
+ );
1026
+ }
1027
+
1028
+ function buildMissingTargetDirective() {
1029
+ const script = process.argv[1] || 'context.mjs';
1030
+ return (
1031
+ 'MONOREPO_TARGET_REQUIRED: This is a monorepo and context.mjs ran without --target. ' +
1032
+ 'If the user named a file, route, or child app, do not answer from this output. ' +
1033
+ `Rerun \`node ${script} --target <path>\` and answer from that run's RESOLVED_CONTEXT fields.`
1034
+ );
1035
+ }
1036
+
1037
+ function buildTargetSelectionDirective(selection) {
1038
+ return (
1039
+ `TARGET_SELECTION_REQUIRED:\n${JSON.stringify(selection, null, 2)}\n\n` +
1040
+ 'Show each app with its productStatus/productPath and designStatus/designPath so the user can see child overrides, inherited root files, fallback files, or missing files before choosing. ' +
1041
+ 'Ask the user which app Monodesign should use, then rerun Monodesign helper commands from that child app cwd using this same scripts directory. ' +
1042
+ 'Use `--target <path>` only as a fallback when changing cwd is not possible, or when the user explicitly named a file/path.'
1043
+ );
1044
+ }
1045
+
1046
+ // Run cli() only when this module is the entry point. Compare realpaths
1047
+ // rather than endsWith(): a loose suffix match also fires for unrelated
1048
+ // scripts like `load-context.mjs`, and realpath tolerates symlinked
1049
+ // invocation (the test harness symlinks the skill dir).
1050
+ function invokedAsScript() {
1051
+ const arg = process.argv[1];
1052
+ if (!arg) return false;
1053
+ try {
1054
+ return fs.realpathSync(arg) === fs.realpathSync(fileURLToPath(import.meta.url));
1055
+ } catch {
1056
+ return false;
1057
+ }
1058
+ }
1059
+
1060
+ if (invokedAsScript()) {
1061
+ cli();
1062
+ }