@monoes/monomindcli 2.16.3 → 2.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (488) hide show
  1. package/.claude/agents/github/repo-architect.md +1 -1
  2. package/.claude/agents/specialists/integration-architect.md +9 -13
  3. package/.claude/commands/agents/agent-capabilities.md +1 -0
  4. package/.claude/commands/agents/agent-coordination.md +1 -0
  5. package/.claude/commands/agents/agent-spawning.md +1 -0
  6. package/.claude/commands/agents/agent-types.md +1 -0
  7. package/.claude/commands/analysis/bottleneck-detect.md +1 -0
  8. package/.claude/commands/analysis/performance-bottlenecks.md +1 -0
  9. package/.claude/commands/analysis/performance-report.md +1 -0
  10. package/.claude/commands/analysis/token-usage.md +1 -0
  11. package/.claude/commands/automation/README.md +1 -1
  12. package/.claude/commands/automation/auto-agent.md +1 -0
  13. package/.claude/commands/automation/self-healing.md +1 -0
  14. package/.claude/commands/automation/session-memory.md +1 -0
  15. package/.claude/commands/automation/smart-agents.md +1 -0
  16. package/.claude/commands/automation/smart-spawn.md +1 -0
  17. package/.claude/commands/automation/workflow-select.md +22 -27
  18. package/.claude/commands/coordination/README.md +2 -2
  19. package/.claude/commands/coordination/agent-spawn.md +1 -0
  20. package/.claude/commands/coordination/monoswarm-init.md +9 -8
  21. package/.claude/commands/coordination/task-orchestrate.md +6 -5
  22. package/.claude/commands/github/README.md +1 -1
  23. package/.claude/commands/github/github-modes.md +1 -0
  24. package/.claude/commands/github/issue-tracker.md +1 -0
  25. package/.claude/commands/github/pr-manager.md +1 -0
  26. package/.claude/commands/github/release-manager.md +1 -2
  27. package/.claude/commands/github/repo-architect.md +1 -0
  28. package/.claude/commands/github/sync-coordinator.md +1 -0
  29. package/.claude/commands/hooks/overview.md +1 -0
  30. package/.claude/commands/hooks/post-edit.md +1 -0
  31. package/.claude/commands/hooks/post-task.md +1 -0
  32. package/.claude/commands/hooks/pre-edit.md +1 -0
  33. package/.claude/commands/hooks/pre-task.md +1 -0
  34. package/.claude/commands/hooks/session-end.md +1 -0
  35. package/.claude/commands/hooks/setup.md +1 -0
  36. package/.claude/commands/mastermind/adr.md +3 -1
  37. package/.claude/commands/mastermind/brain.md +3 -1
  38. package/.claude/commands/mastermind/budget.md +3 -1
  39. package/.claude/commands/mastermind/code-review.md +3 -1
  40. package/.claude/commands/mastermind/content.md +3 -1
  41. package/.claude/commands/mastermind/createorg.md +4 -2
  42. package/.claude/commands/mastermind/createtask.md +6 -4
  43. package/.claude/commands/mastermind/debug.md +3 -1
  44. package/.claude/commands/mastermind/design.md +3 -1
  45. package/.claude/commands/mastermind/do.md +5 -3
  46. package/.claude/commands/mastermind/execute.md +3 -1
  47. package/.claude/commands/mastermind/finance.md +3 -1
  48. package/.claude/commands/mastermind/graph-status.md +3 -1
  49. package/.claude/commands/mastermind/help.md +17 -20
  50. package/.claude/commands/mastermind/idea.md +3 -1
  51. package/.claude/commands/mastermind/ideate.md +4 -2
  52. package/.claude/commands/mastermind/improve.md +4 -2
  53. package/.claude/commands/mastermind/loops.md +3 -1
  54. package/.claude/commands/mastermind/marketing.md +3 -1
  55. package/.claude/commands/mastermind/master.md +4 -3
  56. package/.claude/commands/mastermind/memory.md +8 -36
  57. package/.claude/commands/mastermind/monoswarm.md +3 -2
  58. package/.claude/commands/mastermind/okf-export.md +3 -1
  59. package/.claude/commands/mastermind/okf-import.md +3 -1
  60. package/.claude/commands/mastermind/ops.md +3 -1
  61. package/.claude/commands/mastermind/orgs.md +3 -1
  62. package/.claude/commands/mastermind/orgstatus.md +3 -1
  63. package/.claude/commands/mastermind/plan.md +3 -1
  64. package/.claude/commands/mastermind/receive-review.md +3 -1
  65. package/.claude/commands/mastermind/release.md +3 -1
  66. package/.claude/commands/mastermind/repeat.md +3 -1
  67. package/.claude/commands/mastermind/research.md +3 -1
  68. package/.claude/commands/mastermind/review.md +3 -1
  69. package/.claude/commands/mastermind/runorg.md +4 -2
  70. package/.claude/commands/mastermind/sales.md +3 -1
  71. package/.claude/commands/mastermind/skill-builder.md +3 -1
  72. package/.claude/commands/mastermind/specialagents.md +3 -1
  73. package/.claude/commands/mastermind/stoporg.md +9 -11
  74. package/.claude/commands/mastermind/techport.md +3 -1
  75. package/.claude/commands/mastermind/topology.md +4 -3
  76. package/.claude/commands/mastermind/understand.md +3 -1
  77. package/.claude/commands/mastermind/worktree.md +3 -1
  78. package/.claude/commands/memory/memory-search.md +1 -0
  79. package/.claude/commands/monitoring/README.md +1 -1
  80. package/.claude/commands/monitoring/agent-metrics.md +1 -0
  81. package/.claude/commands/monitoring/agents.md +1 -0
  82. package/.claude/commands/monitoring/status.md +1 -0
  83. package/.claude/commands/monoswarm/README.md +3 -3
  84. package/.claude/commands/monoswarm/analysis.md +2 -2
  85. package/.claude/commands/monoswarm/consensus.md +1 -0
  86. package/.claude/commands/monoswarm/development.md +3 -3
  87. package/.claude/commands/monoswarm/examples.md +4 -4
  88. package/.claude/commands/monoswarm/init.md +2 -1
  89. package/.claude/commands/monoswarm/maintenance.md +2 -2
  90. package/.claude/commands/monoswarm/memory.md +1 -0
  91. package/.claude/commands/monoswarm/monoswarm.md +5 -5
  92. package/.claude/commands/monoswarm/optimization.md +2 -2
  93. package/.claude/commands/monoswarm/research.md +2 -2
  94. package/.claude/commands/monoswarm/spawn.md +1 -0
  95. package/.claude/commands/monoswarm/status.md +2 -1
  96. package/.claude/commands/monoswarm/stop.md +2 -1
  97. package/.claude/commands/monoswarm/testing.md +2 -2
  98. package/.claude/commands/pair/README.md +8 -9
  99. package/.claude/commands/pair/examples.md +3 -4
  100. package/.claude/commands/pair/session.md +1 -1
  101. package/.claude/commands/workflows/README.md +45 -40
  102. package/.claude/commands/workflows/development.md +42 -55
  103. package/.claude/commands/workflows/research.md +41 -57
  104. package/.claude/commands/workflows/workflow-create.md +43 -45
  105. package/.claude/commands/workflows/workflow-execute.md +58 -68
  106. package/.claude/commands/workflows/workflow-export.md +37 -63
  107. package/.claude/helpers/agent-registry.cjs +434 -0
  108. package/.claude/helpers/build-skill-registry.cjs +10 -6
  109. package/.claude/helpers/handlers/pick-core.cjs +55 -26
  110. package/.claude/helpers/handlers/route-handler.cjs +11 -3
  111. package/.claude/helpers/handlers/session-restore-handler.cjs +4 -1
  112. package/.claude/helpers/hook-handler.cjs +4 -2
  113. package/.claude/helpers/jev-catalog.cjs +14 -6
  114. package/.claude/helpers/jev-picker.cjs +52 -8
  115. package/.claude/helpers/pick-rank.cjs +184 -6
  116. package/.claude/helpers/pick-stats.cjs +86 -2
  117. package/.claude/skills/agentic-jujutsu/SKILL.md +2 -3
  118. package/.claude/skills/github-toolkit/SKILL.md +1 -1
  119. package/.claude/skills/hooks-automation/SKILL.md +243 -938
  120. package/.claude/skills/mastermind-agent-detail/SKILL.md +1 -1
  121. package/.claude/skills/mastermind-agent-select/SKILL.md +16 -1
  122. package/.claude/skills/mastermind-agents/SKILL.md +31 -38
  123. package/.claude/skills/mastermind-createorg/SKILL.md +3 -3
  124. package/.claude/skills/mastermind-env/SKILL.md +4 -18
  125. package/.claude/skills/mastermind-inbox/SKILL.md +31 -52
  126. package/.claude/skills/mastermind-instance/SKILL.md +7 -5
  127. package/.claude/skills/mastermind-new-agent/SKILL.md +3 -3
  128. package/.claude/skills/mastermind-org-settings/SKILL.md +3 -4
  129. package/.claude/skills/mastermind-orgs/SKILL.md +26 -32
  130. package/.claude/skills/mastermind-orgstatus/SKILL.md +49 -140
  131. package/.claude/skills/mastermind-plugins/SKILL.md +1 -1
  132. package/.claude/skills/mastermind-release/SKILL.md +9 -1
  133. package/.claude/skills/mastermind-research/SKILL.md +9 -1
  134. package/.claude/skills/mastermind-review/SKILL.md +9 -1
  135. package/.claude/skills/mastermind-routine-detail/SKILL.md +1 -1
  136. package/.claude/skills/mastermind-runorg/SKILL.md +13 -13
  137. package/.claude/skills/mastermind-stoporg/SKILL.md +7 -62
  138. package/.claude/skills/mastermind-tasks/SKILL.md +6 -8
  139. package/.claude/skills/monodesign/SKILL.md +257 -0
  140. package/.claude/skills/monodesign/adapt.md +53 -0
  141. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +100 -0
  142. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +103 -0
  143. package/.claude/skills/monodesign/animate.md +65 -0
  144. package/.claude/skills/monodesign/audit.md +89 -0
  145. package/.claude/skills/monodesign/bolder.md +50 -0
  146. package/.claude/skills/monodesign/clarify.md +64 -0
  147. package/.claude/skills/monodesign/colorize.md +68 -0
  148. package/.claude/skills/monodesign/craft.md +51 -0
  149. package/.claude/skills/monodesign/critique.md +66 -0
  150. package/.claude/skills/monodesign/delight.md +47 -0
  151. package/.claude/skills/monodesign/distill.md +56 -0
  152. package/.claude/skills/monodesign/document.md +83 -0
  153. package/.claude/skills/monodesign/extract.md +74 -0
  154. package/.claude/skills/monodesign/harden.md +65 -0
  155. package/.claude/skills/monodesign/init.md +30 -0
  156. package/.claude/skills/monodesign/layout.md +36 -0
  157. package/.claude/skills/monodesign/live.md +34 -0
  158. package/.claude/skills/monodesign/onboard.md +50 -0
  159. package/.claude/skills/monodesign/optimize.md +64 -0
  160. package/.claude/skills/monodesign/overdrive.md +56 -0
  161. package/.claude/skills/monodesign/polish.md +68 -0
  162. package/.claude/skills/monodesign/quieter.md +57 -0
  163. package/.claude/skills/monodesign/reference/adapt.md +312 -0
  164. package/.claude/skills/monodesign/reference/adapt.native.md +58 -0
  165. package/.claude/skills/monodesign/reference/android.md +40 -0
  166. package/.claude/skills/monodesign/reference/animate.md +203 -0
  167. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +410 -0
  168. package/.claude/skills/monodesign/reference/audit.md +135 -0
  169. package/.claude/skills/monodesign/reference/audit.native.md +139 -0
  170. package/.claude/skills/monodesign/reference/bolder.md +120 -0
  171. package/.claude/skills/monodesign/reference/brand-workflow.md +180 -0
  172. package/.claude/skills/monodesign/reference/brand.md +108 -0
  173. package/.claude/skills/monodesign/reference/clarify.md +288 -0
  174. package/.claude/skills/monodesign/reference/codex.md +105 -0
  175. package/.claude/skills/monodesign/reference/cognitive-load.md +106 -0
  176. package/.claude/skills/monodesign/reference/color-and-contrast.md +105 -0
  177. package/.claude/skills/monodesign/reference/colorize.md +257 -0
  178. package/.claude/skills/monodesign/reference/component-specs.md +260 -0
  179. package/.claude/skills/monodesign/reference/component-states.md +274 -0
  180. package/.claude/skills/monodesign/reference/component-system.md +358 -0
  181. package/.claude/skills/monodesign/reference/copy-formulas.md +160 -0
  182. package/.claude/skills/monodesign/reference/craft.md +123 -0
  183. package/.claude/skills/monodesign/reference/critique.md +780 -0
  184. package/.claude/skills/monodesign/reference/delight.md +302 -0
  185. package/.claude/skills/monodesign/reference/design-principles.md +246 -0
  186. package/.claude/skills/monodesign/reference/distill.md +111 -0
  187. package/.claude/skills/monodesign/reference/document.md +429 -0
  188. package/.claude/skills/monodesign/reference/extract.md +69 -0
  189. package/.claude/skills/monodesign/reference/harden.md +347 -0
  190. package/.claude/skills/monodesign/reference/heuristics-scoring.md +234 -0
  191. package/.claude/skills/monodesign/reference/hooks.md +92 -0
  192. package/.claude/skills/monodesign/reference/image-prompts.md +130 -0
  193. package/.claude/skills/monodesign/reference/init.md +221 -0
  194. package/.claude/skills/monodesign/reference/interaction-design.md +189 -0
  195. package/.claude/skills/monodesign/reference/ios.md +45 -0
  196. package/.claude/skills/monodesign/reference/layout.md +185 -0
  197. package/.claude/skills/monodesign/reference/live.md +710 -0
  198. package/.claude/skills/monodesign/reference/motion-design.md +109 -0
  199. package/.claude/skills/monodesign/reference/onboard.md +234 -0
  200. package/.claude/skills/monodesign/reference/optimize.md +258 -0
  201. package/.claude/skills/monodesign/reference/overdrive.md +130 -0
  202. package/.claude/skills/monodesign/reference/personas.md +179 -0
  203. package/.claude/skills/monodesign/reference/polish.md +241 -0
  204. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +108 -0
  205. package/.claude/skills/monodesign/reference/product.md +60 -0
  206. package/.claude/skills/monodesign/reference/quieter.md +99 -0
  207. package/.claude/skills/monodesign/reference/responsive-design.md +114 -0
  208. package/.claude/skills/monodesign/reference/shape.md +165 -0
  209. package/.claude/skills/monodesign/reference/spatial-design.md +100 -0
  210. package/.claude/skills/monodesign/reference/teach.md +10 -0
  211. package/.claude/skills/monodesign/reference/token-architecture.md +222 -0
  212. package/.claude/skills/monodesign/reference/typeset.md +301 -0
  213. package/.claude/skills/monodesign/reference/typography.md +159 -0
  214. package/.claude/skills/monodesign/reference/ux-research.md +143 -0
  215. package/.claude/skills/monodesign/reference/ux-rules.md +211 -0
  216. package/.claude/skills/monodesign/reference/ux-writing.md +107 -0
  217. package/.claude/skills/monodesign/scripts/command-metadata.json +94 -0
  218. package/.claude/skills/monodesign/scripts/context-signals.mjs +260 -0
  219. package/.claude/skills/monodesign/scripts/context.mjs +1065 -0
  220. package/.claude/skills/monodesign/scripts/critique-storage.mjs +416 -0
  221. package/.claude/skills/monodesign/scripts/detect-csp.mjs +193 -0
  222. package/.claude/skills/monodesign/scripts/detect.mjs +33 -0
  223. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +1960 -0
  224. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +321 -0
  225. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +814 -0
  226. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +5628 -0
  227. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +50 -0
  228. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +259 -0
  229. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +339 -0
  230. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +636 -0
  231. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +1016 -0
  232. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +253 -0
  233. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +198 -0
  234. package/.claude/skills/monodesign/scripts/detector/findings.mjs +12 -0
  235. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +181 -0
  236. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +373 -0
  237. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +426 -0
  238. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +198 -0
  239. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +166 -0
  240. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +563 -0
  241. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +3024 -0
  242. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +124 -0
  243. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +101 -0
  244. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +30 -0
  245. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +148 -0
  246. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +7 -0
  247. package/.claude/skills/monodesign/scripts/hook-admin.mjs +694 -0
  248. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +516 -0
  249. package/.claude/skills/monodesign/scripts/hook-lib.mjs +1785 -0
  250. package/.claude/skills/monodesign/scripts/hook.mjs +61 -0
  251. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +809 -0
  252. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +69 -0
  253. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +640 -0
  254. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +129 -0
  255. package/.claude/skills/monodesign/scripts/lib/provider.mjs +4 -0
  256. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +42 -0
  257. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +50 -0
  258. package/.claude/skills/monodesign/scripts/live/completion.mjs +19 -0
  259. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +137 -0
  260. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +458 -0
  261. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +939 -0
  262. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +357 -0
  263. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +152 -0
  264. package/.claude/skills/monodesign/scripts/live/session-store.mjs +293 -0
  265. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +826 -0
  266. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +279 -0
  267. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +180 -0
  268. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +36 -0
  269. package/.claude/skills/monodesign/scripts/live-accept.mjs +812 -0
  270. package/.claude/skills/monodesign/scripts/live-browser-dom.js +147 -0
  271. package/.claude/skills/monodesign/scripts/live-browser-session.js +124 -0
  272. package/.claude/skills/monodesign/scripts/live-browser.js +11213 -0
  273. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +1241 -0
  274. package/.claude/skills/monodesign/scripts/live-complete.mjs +75 -0
  275. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +683 -0
  276. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +51 -0
  277. package/.claude/skills/monodesign/scripts/live-inject.mjs +596 -0
  278. package/.claude/skills/monodesign/scripts/live-insert.mjs +272 -0
  279. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +363 -0
  280. package/.claude/skills/monodesign/scripts/live-poll.mjs +384 -0
  281. package/.claude/skills/monodesign/scripts/live-resume.mjs +94 -0
  282. package/.claude/skills/monodesign/scripts/live-server.mjs +1210 -0
  283. package/.claude/skills/monodesign/scripts/live-status.mjs +61 -0
  284. package/.claude/skills/monodesign/scripts/live-target.mjs +30 -0
  285. package/.claude/skills/monodesign/scripts/live-wrap.mjs +884 -0
  286. package/.claude/skills/monodesign/scripts/live.mjs +297 -0
  287. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +14 -0
  288. package/.claude/skills/monodesign/scripts/palette.mjs +635 -0
  289. package/.claude/skills/monodesign/scripts/pin.mjs +221 -0
  290. package/.claude/skills/monodesign/shape.md +71 -0
  291. package/.claude/skills/monodesign/teach.md +18 -0
  292. package/.claude/skills/monodesign/typeset.md +59 -0
  293. package/.claude/skills/monolean-audit/SKILL.md +4 -6
  294. package/.claude/skills/monolean-help/SKILL.md +0 -1
  295. package/.claude/skills/monoswarm/SKILL.md +17 -17
  296. package/.claude/skills/pair-programming/SKILL.md +127 -1100
  297. package/README.md +28 -43
  298. package/dist/src/agents/registry-builder.d.ts +58 -22
  299. package/dist/src/agents/registry-builder.d.ts.map +1 -1
  300. package/dist/src/agents/registry-builder.js +41 -341
  301. package/dist/src/agents/registry-builder.js.map +1 -1
  302. package/dist/src/agents/registry-freshness.d.ts +4 -4
  303. package/dist/src/agents/registry-freshness.d.ts.map +1 -1
  304. package/dist/src/agents/registry-freshness.js +11 -60
  305. package/dist/src/agents/registry-freshness.js.map +1 -1
  306. package/dist/src/commands/doc.d.ts.map +1 -1
  307. package/dist/src/commands/doc.js +6 -15
  308. package/dist/src/commands/doc.js.map +1 -1
  309. package/dist/src/commands/doctor-pick-checks.d.ts +20 -3
  310. package/dist/src/commands/doctor-pick-checks.d.ts.map +1 -1
  311. package/dist/src/commands/doctor-pick-checks.js +138 -45
  312. package/dist/src/commands/doctor-pick-checks.js.map +1 -1
  313. package/dist/src/commands/doctor-project-checks.d.ts +2 -2
  314. package/dist/src/commands/doctor-project-checks.d.ts.map +1 -1
  315. package/dist/src/commands/doctor-project-checks.js +21 -17
  316. package/dist/src/commands/doctor-project-checks.js.map +1 -1
  317. package/dist/src/commands/doctor.d.ts.map +1 -1
  318. package/dist/src/commands/doctor.js +6 -4
  319. package/dist/src/commands/doctor.js.map +1 -1
  320. package/dist/src/commands/hooks-routing-commands.d.ts.map +1 -1
  321. package/dist/src/commands/hooks-routing-commands.js +4 -3
  322. package/dist/src/commands/hooks-routing-commands.js.map +1 -1
  323. package/dist/src/commands/init-upgrade.d.ts.map +1 -1
  324. package/dist/src/commands/init-upgrade.js +10 -0
  325. package/dist/src/commands/init-upgrade.js.map +1 -1
  326. package/dist/src/commands/init-wizard.d.ts.map +1 -1
  327. package/dist/src/commands/init-wizard.js +7 -2
  328. package/dist/src/commands/init-wizard.js.map +1 -1
  329. package/dist/src/commands/init.d.ts.map +1 -1
  330. package/dist/src/commands/init.js +27 -27
  331. package/dist/src/commands/init.js.map +1 -1
  332. package/dist/src/commands/monograph.d.ts.map +1 -1
  333. package/dist/src/commands/monograph.js +16 -21
  334. package/dist/src/commands/monograph.js.map +1 -1
  335. package/dist/src/commands/org.js +1 -1
  336. package/dist/src/commands/org.js.map +1 -1
  337. package/dist/src/commands/pick.d.ts.map +1 -1
  338. package/dist/src/commands/pick.js +4 -3
  339. package/dist/src/commands/pick.js.map +1 -1
  340. package/dist/src/decision/jev.d.ts +20 -0
  341. package/dist/src/decision/jev.d.ts.map +1 -1
  342. package/dist/src/decision/jev.js +12 -0
  343. package/dist/src/decision/jev.js.map +1 -1
  344. package/dist/src/decision/pick-eval.d.ts +23 -0
  345. package/dist/src/decision/pick-eval.d.ts.map +1 -1
  346. package/dist/src/decision/pick-eval.js +24 -1
  347. package/dist/src/decision/pick-eval.js.map +1 -1
  348. package/dist/src/decision/pick-real.d.ts +93 -0
  349. package/dist/src/decision/pick-real.d.ts.map +1 -0
  350. package/dist/src/decision/pick-real.js +253 -0
  351. package/dist/src/decision/pick-real.js.map +1 -0
  352. package/dist/src/decision/picks.d.ts +6 -0
  353. package/dist/src/decision/picks.d.ts.map +1 -1
  354. package/dist/src/decision/picks.js +34 -11
  355. package/dist/src/decision/picks.js.map +1 -1
  356. package/dist/src/init/claudemd-generator.d.ts.map +1 -1
  357. package/dist/src/init/claudemd-generator.js +1 -0
  358. package/dist/src/init/claudemd-generator.js.map +1 -1
  359. package/dist/src/init/copy-assets.d.ts.map +1 -1
  360. package/dist/src/init/copy-assets.js +17 -9
  361. package/dist/src/init/copy-assets.js.map +1 -1
  362. package/dist/src/init/embeddings-step.d.ts +23 -0
  363. package/dist/src/init/embeddings-step.d.ts.map +1 -0
  364. package/dist/src/init/embeddings-step.js +53 -0
  365. package/dist/src/init/embeddings-step.js.map +1 -0
  366. package/dist/src/init/executor.d.ts.map +1 -1
  367. package/dist/src/init/executor.js +35 -5
  368. package/dist/src/init/executor.js.map +1 -1
  369. package/dist/src/init/file-guard.d.ts +93 -0
  370. package/dist/src/init/file-guard.d.ts.map +1 -0
  371. package/dist/src/init/file-guard.js +239 -0
  372. package/dist/src/init/file-guard.js.map +1 -0
  373. package/dist/src/init/helpers-generator.d.ts +7 -0
  374. package/dist/src/init/helpers-generator.d.ts.map +1 -1
  375. package/dist/src/init/helpers-generator.js +13 -0
  376. package/dist/src/init/helpers-generator.js.map +1 -1
  377. package/dist/src/init/init-memory.d.ts +10 -0
  378. package/dist/src/init/init-memory.d.ts.map +1 -1
  379. package/dist/src/init/init-memory.js +44 -1
  380. package/dist/src/init/init-memory.js.map +1 -1
  381. package/dist/src/init/managed-block.d.ts +3 -1
  382. package/dist/src/init/managed-block.d.ts.map +1 -1
  383. package/dist/src/init/managed-block.js +9 -2
  384. package/dist/src/init/managed-block.js.map +1 -1
  385. package/dist/src/init/mcp-generator.d.ts +9 -0
  386. package/dist/src/init/mcp-generator.d.ts.map +1 -1
  387. package/dist/src/init/mcp-generator.js +28 -0
  388. package/dist/src/init/mcp-generator.js.map +1 -1
  389. package/dist/src/init/project-indexes.d.ts +19 -0
  390. package/dist/src/init/project-indexes.d.ts.map +1 -0
  391. package/dist/src/init/project-indexes.js +44 -0
  392. package/dist/src/init/project-indexes.js.map +1 -0
  393. package/dist/src/init/runtime-config-merge.d.ts +21 -0
  394. package/dist/src/init/runtime-config-merge.d.ts.map +1 -0
  395. package/dist/src/init/runtime-config-merge.js +88 -0
  396. package/dist/src/init/runtime-config-merge.js.map +1 -0
  397. package/dist/src/init/settings-generator.js +1 -1
  398. package/dist/src/init/settings-generator.js.map +1 -1
  399. package/dist/src/init/shared-instructions-generator.d.ts +3 -1
  400. package/dist/src/init/shared-instructions-generator.d.ts.map +1 -1
  401. package/dist/src/init/shared-instructions-generator.js +14 -39
  402. package/dist/src/init/shared-instructions-generator.js.map +1 -1
  403. package/dist/src/init/shared.d.ts +17 -2
  404. package/dist/src/init/shared.d.ts.map +1 -1
  405. package/dist/src/init/shared.js +39 -7
  406. package/dist/src/init/shared.js.map +1 -1
  407. package/dist/src/init/types.d.ts +22 -2
  408. package/dist/src/init/types.d.ts.map +1 -1
  409. package/dist/src/init/types.js +11 -3
  410. package/dist/src/init/types.js.map +1 -1
  411. package/dist/src/init/upgrade.d.ts +7 -0
  412. package/dist/src/init/upgrade.d.ts.map +1 -1
  413. package/dist/src/init/upgrade.js +60 -48
  414. package/dist/src/init/upgrade.js.map +1 -1
  415. package/dist/src/init/write-antigravity.d.ts +1 -0
  416. package/dist/src/init/write-antigravity.d.ts.map +1 -1
  417. package/dist/src/init/write-antigravity.js +28 -4
  418. package/dist/src/init/write-antigravity.js.map +1 -1
  419. package/dist/src/init/write-claude.d.ts.map +1 -1
  420. package/dist/src/init/write-claude.js +47 -23
  421. package/dist/src/init/write-claude.js.map +1 -1
  422. package/dist/src/init/write-kimicode.d.ts +27 -0
  423. package/dist/src/init/write-kimicode.d.ts.map +1 -1
  424. package/dist/src/init/write-kimicode.js +119 -92
  425. package/dist/src/init/write-kimicode.js.map +1 -1
  426. package/dist/src/init/write-opencode.d.ts.map +1 -1
  427. package/dist/src/init/write-opencode.js +45 -6
  428. package/dist/src/init/write-opencode.js.map +1 -1
  429. package/dist/src/init/write-runtime-config.d.ts.map +1 -1
  430. package/dist/src/init/write-runtime-config.js +108 -81
  431. package/dist/src/init/write-runtime-config.js.map +1 -1
  432. package/dist/src/knowledge/eval/golden-set.js +0 -15
  433. package/dist/src/knowledge/eval/golden-set.js.map +1 -1
  434. package/dist/src/mcp-tools/embeddings-tools.d.ts.map +1 -1
  435. package/dist/src/mcp-tools/embeddings-tools.js +14 -5
  436. package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
  437. package/dist/src/mcp-tools/hooks-routing.d.ts.map +1 -1
  438. package/dist/src/mcp-tools/hooks-routing.js +4 -3
  439. package/dist/src/mcp-tools/hooks-routing.js.map +1 -1
  440. package/dist/src/mcp-tools/monograph/build-tools.d.ts.map +1 -1
  441. package/dist/src/mcp-tools/monograph/build-tools.js +16 -9
  442. package/dist/src/mcp-tools/monograph/build-tools.js.map +1 -1
  443. package/dist/src/mcp-tools/org-skill-tools.d.ts.map +1 -1
  444. package/dist/src/mcp-tools/org-skill-tools.js +6 -2
  445. package/dist/src/mcp-tools/org-skill-tools.js.map +1 -1
  446. package/dist/src/mcp-tools/pick-tools.d.ts.map +1 -1
  447. package/dist/src/mcp-tools/pick-tools.js +13 -4
  448. package/dist/src/mcp-tools/pick-tools.js.map +1 -1
  449. package/dist/src/memory/embedding-operations.d.ts +0 -4
  450. package/dist/src/memory/embedding-operations.d.ts.map +1 -1
  451. package/dist/src/memory/embedding-operations.js +11 -85
  452. package/dist/src/memory/embedding-operations.js.map +1 -1
  453. package/dist/src/memory/memory-bridge.d.ts +7 -0
  454. package/dist/src/memory/memory-bridge.d.ts.map +1 -1
  455. package/dist/src/memory/memory-bridge.js +15 -0
  456. package/dist/src/memory/memory-bridge.js.map +1 -1
  457. package/dist/src/orgrt/bash-timeout.d.ts +17 -0
  458. package/dist/src/orgrt/bash-timeout.d.ts.map +1 -1
  459. package/dist/src/orgrt/bash-timeout.js +15 -0
  460. package/dist/src/orgrt/bash-timeout.js.map +1 -1
  461. package/dist/src/orgrt/session.d.ts.map +1 -1
  462. package/dist/src/orgrt/session.js +5 -2
  463. package/dist/src/orgrt/session.js.map +1 -1
  464. package/dist/src/orgrt/task-match.d.ts +3 -1
  465. package/dist/src/orgrt/task-match.d.ts.map +1 -1
  466. package/dist/src/orgrt/task-match.js +12 -4
  467. package/dist/src/orgrt/task-match.js.map +1 -1
  468. package/dist/src/platform-adapters/merge.d.ts +4 -3
  469. package/dist/src/platform-adapters/merge.d.ts.map +1 -1
  470. package/dist/src/platform-adapters/merge.js +18 -8
  471. package/dist/src/platform-adapters/merge.js.map +1 -1
  472. package/dist/src/platform-adapters/mutation.d.ts +6 -1
  473. package/dist/src/platform-adapters/mutation.d.ts.map +1 -1
  474. package/dist/src/platform-adapters/mutation.js +9 -3
  475. package/dist/src/platform-adapters/mutation.js.map +1 -1
  476. package/dist/src/platform-adapters/operations.d.ts.map +1 -1
  477. package/dist/src/platform-adapters/operations.js +14 -6
  478. package/dist/src/platform-adapters/operations.js.map +1 -1
  479. package/dist/src/platform-adapters/types.d.ts +5 -0
  480. package/dist/src/platform-adapters/types.d.ts.map +1 -1
  481. package/dist/src/routing/agent-pick.d.ts +9 -7
  482. package/dist/src/routing/agent-pick.d.ts.map +1 -1
  483. package/dist/src/routing/agent-pick.js +17 -17
  484. package/dist/src/routing/agent-pick.js.map +1 -1
  485. package/dist/tsconfig.tsbuildinfo +1 -1
  486. package/package.json +6 -6
  487. package/.claude/skills/github-issue-triage/SKILL.md +0 -354
  488. package/.claude/skills/github-repo-recap/SKILL.md +0 -207
@@ -0,0 +1,357 @@
1
+ import { validateEvent } from './event-validation.mjs';
2
+ import {
3
+ countByPage as countPendingByPage,
4
+ readBuffer as readManualEditsBuffer,
5
+ removeEntries as removeManualEditEntries,
6
+ stageEntry as stageManualEditEntry,
7
+ truncateBuffer as truncateManualEditsBuffer,
8
+ } from './manual-edits-buffer.mjs';
9
+ import {
10
+ summarizeManualApplyFailures,
11
+ summarizeManualDiagnostics,
12
+ summarizeManualLogFile,
13
+ } from './manual-apply.mjs';
14
+ import { buildManualEditEvidence } from '../live-manual-edit-evidence.mjs';
15
+ import { commitManualEdits } from '../live-commit-manual-edits.mjs';
16
+
17
+ export function createManualEditRoutes({
18
+ getToken,
19
+ manualApply,
20
+ recordManualEditActivity,
21
+ getManualEditStatus,
22
+ chatAgentLikelyActive,
23
+ cwd = () => process.cwd(),
24
+ env = () => process.env,
25
+ } = {}) {
26
+ const projectCwd = () => typeof cwd === 'function' ? cwd() : cwd || process.cwd();
27
+ const currentEnv = () => typeof env === 'function' ? env() : env || process.env;
28
+
29
+ return function handleManualEditRoute(req, res, url) {
30
+ const p = url.pathname;
31
+
32
+ // Save stages entries; Apply commits the staged page batch through the
33
+ // local AI copy-edit runner.
34
+ if (p === '/manual-edit-stash' && req.method === 'POST') {
35
+ let body = '';
36
+ req.on('data', (c) => { body += c; });
37
+ req.on('end', () => {
38
+ let msg;
39
+ try { msg = JSON.parse(body); } catch {
40
+ sendJson(res, 400, { error: 'Invalid JSON' });
41
+ return;
42
+ }
43
+ if (msg.token !== getToken()) {
44
+ sendJson(res, 401, { error: 'Unauthorized' });
45
+ return;
46
+ }
47
+ const error = validateEvent({ ...msg, type: 'manual_edits' });
48
+ if (error) {
49
+ sendJson(res, 400, { error });
50
+ return;
51
+ }
52
+ try {
53
+ stageManualEditEntry(projectCwd(), {
54
+ id: msg.id,
55
+ pageUrl: msg.pageUrl,
56
+ element: msg.element,
57
+ ops: msg.ops,
58
+ });
59
+ } catch (err) {
60
+ sendJson(res, 500, { error: 'stash_write_failed', message: err.message });
61
+ return;
62
+ }
63
+ const { totalCount, perPage } = countPendingByPage(projectCwd());
64
+ const pendingCount = perPage[msg.pageUrl] || 0;
65
+ recordManualEditActivity('manual_edit_stashed', {
66
+ id: msg.id,
67
+ pageUrl: msg.pageUrl,
68
+ opCount: msg.ops.length,
69
+ pendingCount,
70
+ totalCount,
71
+ hintedFileCount: new Set((msg.ops || []).map((op) => summarizeManualLogFile(op.sourceHint?.file, projectCwd())).filter(Boolean)).size,
72
+ });
73
+ sendJson(res, 200, { ok: true, pendingCount, totalCount, perPage });
74
+ });
75
+ return true;
76
+ }
77
+
78
+ if (p === '/manual-edit-stash' && req.method === 'GET') {
79
+ const token = url.searchParams.get('token');
80
+ if (token !== getToken()) { res.writeHead(401); res.end('Unauthorized'); return true; }
81
+ const pageUrl = url.searchParams.get('pageUrl') || '';
82
+ const { totalCount, perPage } = countPendingByPage(projectCwd());
83
+ const buffer = readManualEditsBuffer(projectCwd());
84
+ const entriesForPage = pageUrl ? buffer.entries.filter((e) => e.pageUrl === pageUrl) : buffer.entries;
85
+ sendJson(res, 200, {
86
+ count: pageUrl ? (perPage[pageUrl] || 0) : totalCount,
87
+ totalCount,
88
+ perPage,
89
+ entries: entriesForPage,
90
+ });
91
+ return true;
92
+ }
93
+
94
+ if (p === '/manual-edit-commit' && req.method === 'POST') {
95
+ const token = url.searchParams.get('token');
96
+ if (token !== getToken()) { res.writeHead(401); res.end('Unauthorized'); return true; }
97
+ const pageUrl = url.searchParams.get('pageUrl');
98
+ const asyncMode = /^(1|true|yes)$/i.test(url.searchParams.get('async') || '');
99
+ const repairOnly = /^(1|true|yes)$/i.test(url.searchParams.get('repair') || '');
100
+ const existingTransaction = manualApply.readTransaction();
101
+ if (repairOnly && !existingTransaction) {
102
+ sendJson(res, 409, { error: 'manual_edit_repair_transaction_missing' });
103
+ return true;
104
+ }
105
+ const recoveredTransaction = repairOnly ? null : manualApply.rollbackTransaction({
106
+ pageUrl,
107
+ reason: 'manual_edit_commit_recovered_abandoned_transaction',
108
+ });
109
+ const before = getManualEditStatus();
110
+ const pendingCount = pageUrl ? (before.perPage[pageUrl] || 0) : before.totalCount;
111
+ recordManualEditActivity('manual_edit_commit_started', {
112
+ pageUrl,
113
+ repairOnly,
114
+ pendingCount,
115
+ totalCount: before.totalCount,
116
+ recoveredTransaction: recoveredTransaction ? {
117
+ id: recoveredTransaction.id,
118
+ reason: recoveredTransaction.reason,
119
+ skipped: recoveredTransaction.skipped,
120
+ rolledBackFiles: recoveredTransaction.rolledBackFiles,
121
+ rollbackFailures: summarizeManualDiagnostics(recoveredTransaction.rollbackFailures, projectCwd()),
122
+ } : null,
123
+ ...summarizePendingManualEditBatch(projectCwd(), pageUrl),
124
+ });
125
+ if (asyncMode) {
126
+ sendJson(res, 202, {
127
+ status: 'started',
128
+ pendingCount,
129
+ totalCount: before.totalCount,
130
+ perPage: before.perPage,
131
+ });
132
+ }
133
+ (async () => {
134
+ let result;
135
+ let routedProvider = 'subprocess';
136
+ let transaction = null;
137
+ let commitBatch = null;
138
+ try {
139
+ if (pendingCount > 0) {
140
+ const transactionBatch = buildManualEditEvidence({ cwd: projectCwd(), pageUrl });
141
+ commitBatch = transactionBatch;
142
+ if (!repairOnly && manualApply.countOps(transactionBatch) > 0) {
143
+ transaction = manualApply.writeTransaction({
144
+ pageUrl,
145
+ batch: transactionBatch,
146
+ });
147
+ } else if (repairOnly && existingTransaction) {
148
+ transaction = existingTransaction;
149
+ }
150
+ }
151
+ const envValue = currentEnv();
152
+ const requestedMode = (envValue.MONODESIGN_LIVE_COPY_AGENT || 'auto').trim().toLowerCase();
153
+ const useChatRoute = requestedMode === 'chat'
154
+ || (requestedMode === 'auto' && chatAgentLikelyActive());
155
+ if (useChatRoute) {
156
+ routedProvider = 'chat';
157
+ const timeoutMs = Number(envValue.MONODESIGN_LIVE_COPY_AGENT_TIMEOUT_MS || 120000);
158
+ result = await commitManualEdits({
159
+ cwd: projectCwd(),
160
+ pageUrl,
161
+ provider: 'chat',
162
+ env: envValue,
163
+ timeoutMs,
164
+ chatAvailable: chatAgentLikelyActive,
165
+ applyBatchToSource: (batch, context) => manualApply.pushBatchInChunksAndWait(batch, pageUrl, context),
166
+ repairOnly,
167
+ transactionId: transaction?.id || existingTransaction?.id || null,
168
+ batch: commitBatch,
169
+ });
170
+ } else {
171
+ const timeoutMs = Number(envValue.MONODESIGN_LIVE_COPY_AGENT_TIMEOUT_MS || 120000);
172
+ const provider = ['codex', 'claude', 'mock'].includes(requestedMode) ? requestedMode : undefined;
173
+ result = await commitManualEdits({
174
+ cwd: projectCwd(),
175
+ pageUrl,
176
+ provider,
177
+ env: envValue,
178
+ timeoutMs,
179
+ chatAvailable: chatAgentLikelyActive,
180
+ repairOnly,
181
+ transactionId: transaction?.id || existingTransaction?.id || null,
182
+ batch: commitBatch,
183
+ });
184
+ }
185
+ } catch (err) {
186
+ if (transaction) {
187
+ manualApply.rollbackTransaction({
188
+ pageUrl,
189
+ reason: 'manual_edit_commit_exception',
190
+ });
191
+ }
192
+ const message = err.stderr?.toString?.() || err.message;
193
+ recordManualEditActivity('manual_edit_commit_failed', {
194
+ pageUrl,
195
+ provider: routedProvider,
196
+ error: 'manual_edit_commit_failed',
197
+ message,
198
+ transactionId: transaction?.id || null,
199
+ });
200
+ if (!asyncMode) {
201
+ sendJson(res, 500, {
202
+ error: 'manual_edit_commit_failed',
203
+ message,
204
+ });
205
+ }
206
+ return;
207
+ } finally {
208
+ if (transaction) {
209
+ const shouldKeepTransaction = result?.needsManualDecision === true;
210
+ if (!shouldKeepTransaction) manualApply.clearTransaction(transaction.id);
211
+ }
212
+ }
213
+ const { totalCount, perPage } = countPendingByPage(projectCwd());
214
+ if (result?.needsManualDecision) {
215
+ recordManualEditActivity('manual_edit_repair_needs_decision', {
216
+ pageUrl,
217
+ provider: routedProvider,
218
+ transactionId: transaction?.id || existingTransaction?.id || null,
219
+ repair: result.repair || null,
220
+ failed: summarizeManualApplyFailures(result.failed, projectCwd()),
221
+ files: Array.isArray(result.files) ? result.files.slice(0, 20).map((file) => summarizeManualLogFile(file, projectCwd())).filter(Boolean) : [],
222
+ remainingCount: pageUrl ? (perPage[pageUrl] || 0) : totalCount,
223
+ totalCount,
224
+ });
225
+ } else {
226
+ recordManualEditActivity('manual_edit_commit_done', {
227
+ pageUrl,
228
+ provider: routedProvider,
229
+ reason: result.reason || null,
230
+ repair: result.repair || null,
231
+ appliedCount: Array.isArray(result.applied) ? result.applied.length : 0,
232
+ failedCount: Array.isArray(result.failed) ? result.failed.length : 0,
233
+ failed: summarizeManualApplyFailures(result.failed, projectCwd()),
234
+ files: Array.isArray(result.files) ? result.files.slice(0, 20).map((file) => summarizeManualLogFile(file, projectCwd())).filter(Boolean) : [],
235
+ warnings: summarizeManualDiagnostics(result.warnings, projectCwd()),
236
+ rolledBackFiles: Array.isArray(result.rolledBackFiles) ? result.rolledBackFiles.slice(0, 20).map((file) => summarizeManualLogFile(file, projectCwd())).filter(Boolean) : [],
237
+ rollbackFailures: summarizeManualDiagnostics(result.rollbackFailures, projectCwd()),
238
+ unreportedFiles: Array.isArray(result.unreportedFiles) ? result.unreportedFiles.slice(0, 20).map((file) => summarizeManualLogFile(file, projectCwd())).filter(Boolean) : undefined,
239
+ noteCount: Array.isArray(result.notes) ? result.notes.length : 0,
240
+ cleared: result.cleared || 0,
241
+ remainingCount: pageUrl ? (perPage[pageUrl] || 0) : totalCount,
242
+ totalCount,
243
+ });
244
+ }
245
+ if (!asyncMode) {
246
+ sendJson(res, 200, { ...result, totalCount, perPage });
247
+ }
248
+ })();
249
+ return true;
250
+ }
251
+
252
+ if (p === '/manual-edit-repair-decision' && req.method === 'POST') {
253
+ let body = '';
254
+ req.on('data', (chunk) => { body += chunk; });
255
+ req.on('end', () => {
256
+ let payload = {};
257
+ try { payload = body ? JSON.parse(body) : {}; } catch {
258
+ sendJson(res, 400, { error: 'Invalid JSON' });
259
+ return;
260
+ }
261
+ const token = payload.token || url.searchParams.get('token');
262
+ if (token !== getToken()) { res.writeHead(401); res.end('Unauthorized'); return; }
263
+ const pageUrl = payload.pageUrl || url.searchParams.get('pageUrl') || null;
264
+ const action = String(payload.action || url.searchParams.get('action') || '').trim().toLowerCase();
265
+ if (action !== 'rollback') {
266
+ sendJson(res, 400, { error: 'unsupported_manual_edit_repair_decision', action });
267
+ return;
268
+ }
269
+ const rollback = manualApply.rollbackTransaction({
270
+ pageUrl,
271
+ reason: 'manual_edit_user_requested_rollback',
272
+ });
273
+ const { totalCount, perPage } = countPendingByPage(projectCwd());
274
+ const response = {
275
+ action,
276
+ pageUrl,
277
+ rollback,
278
+ remainingCount: pageUrl ? (perPage[pageUrl] || 0) : totalCount,
279
+ totalCount,
280
+ perPage,
281
+ };
282
+ recordManualEditActivity('manual_edit_repair_rollback_done', response);
283
+ sendJson(res, 200, response);
284
+ });
285
+ return true;
286
+ }
287
+
288
+ if (p === '/manual-edit-discard' && req.method === 'POST') {
289
+ const token = url.searchParams.get('token');
290
+ if (token !== getToken()) { res.writeHead(401); res.end('Unauthorized'); return true; }
291
+ const pageUrl = url.searchParams.get('pageUrl');
292
+ let discarded;
293
+ let discardedEntries = [];
294
+ let canceledApplyEvents = [];
295
+ let transactionRollback = null;
296
+ try {
297
+ const buffer = readManualEditsBuffer(projectCwd());
298
+ transactionRollback = manualApply.rollbackTransaction({
299
+ pageUrl,
300
+ reason: 'manual_edit_discarded',
301
+ });
302
+ if (pageUrl) {
303
+ discardedEntries = buffer.entries.filter((entry) => entry.pageUrl === pageUrl);
304
+ discarded = removeManualEditEntries(projectCwd(), (entry) => entry.pageUrl === pageUrl);
305
+ } else {
306
+ discardedEntries = buffer.entries;
307
+ discarded = truncateManualEditsBuffer(projectCwd());
308
+ }
309
+ canceledApplyEvents = manualApply.cancelPendingEvents(pageUrl);
310
+ } catch (err) {
311
+ sendJson(res, 500, { error: 'discard_failed', message: err.message });
312
+ return true;
313
+ }
314
+ const { totalCount, perPage } = countPendingByPage(projectCwd());
315
+ recordManualEditActivity('manual_edit_discarded', {
316
+ pageUrl,
317
+ discarded,
318
+ canceledApplyIds: canceledApplyEvents.map((event) => event.id),
319
+ transactionRollback: transactionRollback ? {
320
+ id: transactionRollback.id,
321
+ rolledBackFiles: transactionRollback.rolledBackFiles?.map((file) => summarizeManualLogFile(file, projectCwd())).filter(Boolean) || [],
322
+ rollbackFailures: summarizeManualDiagnostics(transactionRollback.rollbackFailures, projectCwd()),
323
+ skipped: transactionRollback.skipped,
324
+ } : undefined,
325
+ totalCount,
326
+ });
327
+ sendJson(res, 200, { discarded, entries: discardedEntries, canceledApplyEvents, totalCount, perPage });
328
+ return true;
329
+ }
330
+
331
+ if (p === '/manual-edit' && req.method === 'POST') {
332
+ sendJson(res, 410, { error: '/manual-edit is removed; use /manual-edit-stash and /manual-edit-commit for staged copy edits.' });
333
+ return true;
334
+ }
335
+
336
+ return false;
337
+ };
338
+ }
339
+
340
+ function sendJson(res, status, body) {
341
+ res.writeHead(status, { 'Content-Type': 'application/json' });
342
+ res.end(JSON.stringify(body));
343
+ }
344
+
345
+ function summarizePendingManualEditBatch(cwd, pageUrl = null) {
346
+ try {
347
+ const buffer = readManualEditsBuffer(cwd);
348
+ const entries = (buffer.entries || [])
349
+ .filter((entry) => !pageUrl || entry.pageUrl === pageUrl);
350
+ return {
351
+ pendingEntryCount: entries.length,
352
+ pendingOpCount: entries.reduce((sum, entry) => sum + (entry.ops?.length || 0), 0),
353
+ };
354
+ } catch (err) {
355
+ return { pendingSummaryError: err.message || String(err) };
356
+ }
357
+ }
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Shared helpers for the pending-manual-edits buffer on disk.
3
+ *
4
+ * Location: .monodesign/live/pending-manual-edits.json (project-local).
5
+ * Schema: { version: 1, entries: [{ id, pageUrl, element, ops, stagedAt }] }
6
+ *
7
+ * Each entry corresponds to one Save action from the browser. Ops merge by
8
+ * (pageUrl, ref): if the user re-edits the same element before committing, the
9
+ * existing entry's `newText` is replaced and `originalText` is kept (it holds
10
+ * the real source state).
11
+ */
12
+
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+ import { getLiveDir } from '../lib/monodesign-paths.mjs';
16
+
17
+ const BUFFER_VERSION = 1;
18
+ const BUFFER_FILENAME = 'pending-manual-edits.json';
19
+
20
+ export function getBufferPath(cwd = process.cwd()) {
21
+ return path.join(getLiveDir(cwd), BUFFER_FILENAME);
22
+ }
23
+
24
+ export function readBuffer(cwd = process.cwd()) {
25
+ return readBufferInternal(cwd, { strict: false });
26
+ }
27
+
28
+ export function readBufferStrict(cwd = process.cwd()) {
29
+ return readBufferInternal(cwd, { strict: true });
30
+ }
31
+
32
+ function readBufferInternal(cwd, { strict }) {
33
+ const filePath = getBufferPath(cwd);
34
+ try {
35
+ const raw = fs.readFileSync(filePath, 'utf-8');
36
+ const parsed = JSON.parse(raw);
37
+ if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.entries)) {
38
+ if (strict) throw new Error('manual_edit_buffer_invalid_schema');
39
+ return { version: BUFFER_VERSION, entries: [] };
40
+ }
41
+ return { version: BUFFER_VERSION, entries: parsed.entries };
42
+ } catch (err) {
43
+ if (strict && err?.code !== 'ENOENT') {
44
+ throw new Error(`manual_edit_buffer_unreadable: ${err.message || String(err)}`);
45
+ }
46
+ return { version: BUFFER_VERSION, entries: [] };
47
+ }
48
+ }
49
+
50
+ export function writeBuffer(cwd, buffer) {
51
+ const filePath = getBufferPath(cwd);
52
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
53
+ fs.writeFileSync(filePath, JSON.stringify({ version: BUFFER_VERSION, entries: buffer.entries }, null, 2));
54
+ }
55
+
56
+ /**
57
+ * Merge a new entry into the buffer. For each op in the new entry, if there's
58
+ * already a buffered op for the same (pageUrl, ref), update that op's newText
59
+ * and keep its original originalText (the true source state). Otherwise add
60
+ * the op (creating an entry if needed).
61
+ *
62
+ * Multiple ops in one Save are allowed; each is keyed by (pageUrl, ref).
63
+ */
64
+ export function stageEntry(cwd, newEntry) {
65
+ const buf = readBufferStrict(cwd);
66
+ const pageUrl = newEntry.pageUrl;
67
+ for (const newOp of newEntry.ops) {
68
+ let mergedIntoExisting = false;
69
+ for (const existing of buf.entries) {
70
+ if (existing.pageUrl !== pageUrl) continue;
71
+ const existingOpIdx = existing.ops.findIndex((op) => op.ref === newOp.ref);
72
+ if (existingOpIdx >= 0) {
73
+ // Keep the original source text but refresh the latest DOM/source evidence.
74
+ existing.ops[existingOpIdx] = {
75
+ ...newOp,
76
+ originalText: existing.ops[existingOpIdx].originalText,
77
+ newText: newOp.newText,
78
+ deleted: newOp.deleted || false,
79
+ };
80
+ if (newEntry.element) existing.element = newEntry.element;
81
+ existing.stagedAt = new Date().toISOString();
82
+ mergedIntoExisting = true;
83
+ break;
84
+ }
85
+ }
86
+ if (mergedIntoExisting) continue;
87
+ // No existing op for this (pageUrl, ref). Find or create an entry to hold it.
88
+ let entry = buf.entries.find((e) => e.pageUrl === pageUrl && e.id === newEntry.id);
89
+ if (!entry) {
90
+ entry = {
91
+ id: newEntry.id,
92
+ pageUrl,
93
+ element: newEntry.element,
94
+ ops: [],
95
+ stagedAt: new Date().toISOString(),
96
+ };
97
+ buf.entries.push(entry);
98
+ }
99
+ entry.ops.push(newOp);
100
+ entry.stagedAt = new Date().toISOString();
101
+ }
102
+ writeBuffer(cwd, buf);
103
+ return buf;
104
+ }
105
+
106
+ /**
107
+ * Remove entries matching a predicate. Returns count of removed *ops* (not
108
+ * entries) so callers report a unit consistent with truncateBuffer and the
109
+ * pill's per-page op count. Empty entries (no ops left) are also pruned.
110
+ */
111
+ export function removeEntries(cwd, predicate) {
112
+ const buf = readBuffer(cwd);
113
+ let removedOps = 0;
114
+ const kept = [];
115
+ for (const entry of buf.entries) {
116
+ if (predicate(entry)) {
117
+ removedOps += entry.ops?.length || 0;
118
+ } else if (entry.ops && entry.ops.length > 0) {
119
+ kept.push(entry);
120
+ }
121
+ }
122
+ buf.entries = kept;
123
+ writeBuffer(cwd, buf);
124
+ return removedOps;
125
+ }
126
+
127
+ /**
128
+ * Count by page for the counter UI. Returns { totalCount, perPage: {[pageUrl]: count} }.
129
+ */
130
+ export function countByPage(cwd = process.cwd()) {
131
+ const buf = readBuffer(cwd);
132
+ const perPage = {};
133
+ let totalCount = 0;
134
+ for (const entry of buf.entries) {
135
+ const n = entry.ops.length;
136
+ perPage[entry.pageUrl] = (perPage[entry.pageUrl] || 0) + n;
137
+ totalCount += n;
138
+ }
139
+ return { totalCount, perPage };
140
+ }
141
+
142
+ /**
143
+ * Truncate the buffer to empty (used by discard-all). Returns the count of
144
+ * removed ops.
145
+ */
146
+ export function truncateBuffer(cwd) {
147
+ const buf = readBuffer(cwd);
148
+ let removed = 0;
149
+ for (const entry of buf.entries) removed += entry.ops.length;
150
+ writeBuffer(cwd, { version: BUFFER_VERSION, entries: [] });
151
+ return removed;
152
+ }