@monoes/monomindcli 2.16.1 → 2.16.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 (214) hide show
  1. package/.claude/helpers/handlers/edit-handler.cjs +14 -12
  2. package/.claude/helpers/handlers/route-handler.cjs +6 -0
  3. package/.claude/helpers/monograph-freshen.cjs +31 -113
  4. package/.claude/helpers/utils/monograph-resolve.cjs +497 -0
  5. package/.claude/helpers/utils/monograph.cjs +8 -51
  6. package/README.md +1 -1
  7. package/dist/src/commands/doctor-hook-monograph-checks.d.ts +8 -0
  8. package/dist/src/commands/doctor-hook-monograph-checks.d.ts.map +1 -0
  9. package/dist/src/commands/doctor-hook-monograph-checks.js +79 -0
  10. package/dist/src/commands/doctor-hook-monograph-checks.js.map +1 -0
  11. package/dist/src/commands/doctor.d.ts.map +1 -1
  12. package/dist/src/commands/doctor.js +4 -1
  13. package/dist/src/commands/doctor.js.map +1 -1
  14. package/dist/src/commands/monograph.d.ts.map +1 -1
  15. package/dist/src/commands/monograph.js +16 -1
  16. package/dist/src/commands/monograph.js.map +1 -1
  17. package/dist/src/orgrt/bash-timeout.d.ts +14 -0
  18. package/dist/src/orgrt/bash-timeout.d.ts.map +1 -0
  19. package/dist/src/orgrt/bash-timeout.js +18 -0
  20. package/dist/src/orgrt/bash-timeout.js.map +1 -0
  21. package/dist/src/orgrt/block-recheck.d.ts +30 -0
  22. package/dist/src/orgrt/block-recheck.d.ts.map +1 -0
  23. package/dist/src/orgrt/block-recheck.js +81 -0
  24. package/dist/src/orgrt/block-recheck.js.map +1 -0
  25. package/dist/src/orgrt/completion-gate.d.ts +4 -0
  26. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  27. package/dist/src/orgrt/completion-gate.js +22 -2
  28. package/dist/src/orgrt/completion-gate.js.map +1 -1
  29. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  30. package/dist/src/orgrt/daemon.js +6 -4
  31. package/dist/src/orgrt/daemon.js.map +1 -1
  32. package/dist/src/orgrt/decisions.d.ts +1 -1
  33. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  34. package/dist/src/orgrt/decisions.js +14 -6
  35. package/dist/src/orgrt/decisions.js.map +1 -1
  36. package/dist/src/orgrt/mailbox.d.ts +14 -0
  37. package/dist/src/orgrt/mailbox.d.ts.map +1 -1
  38. package/dist/src/orgrt/mailbox.js +31 -1
  39. package/dist/src/orgrt/mailbox.js.map +1 -1
  40. package/dist/src/orgrt/sandbox-fault.d.ts +16 -6
  41. package/dist/src/orgrt/sandbox-fault.d.ts.map +1 -1
  42. package/dist/src/orgrt/sandbox-fault.js +78 -33
  43. package/dist/src/orgrt/sandbox-fault.js.map +1 -1
  44. package/dist/src/orgrt/session.d.ts +4 -3
  45. package/dist/src/orgrt/session.d.ts.map +1 -1
  46. package/dist/src/orgrt/session.js +24 -13
  47. package/dist/src/orgrt/session.js.map +1 -1
  48. package/dist/src/orgrt/task-dag.d.ts +8 -2
  49. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  50. package/dist/src/orgrt/task-dag.js +10 -4
  51. package/dist/src/orgrt/task-dag.js.map +1 -1
  52. package/dist/src/orgrt/types.d.ts +11 -0
  53. package/dist/src/orgrt/types.d.ts.map +1 -1
  54. package/dist/src/orgrt/types.js +18 -0
  55. package/dist/src/orgrt/types.js.map +1 -1
  56. package/dist/src/utils/resource-governor.d.ts.map +1 -1
  57. package/dist/src/utils/resource-governor.js +35 -2
  58. package/dist/src/utils/resource-governor.js.map +1 -1
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +6 -6
  61. package/.claude/skills/monodesign/SKILL.md +0 -257
  62. package/.claude/skills/monodesign/adapt.md +0 -53
  63. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  64. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  65. package/.claude/skills/monodesign/animate.md +0 -65
  66. package/.claude/skills/monodesign/audit.md +0 -89
  67. package/.claude/skills/monodesign/bolder.md +0 -50
  68. package/.claude/skills/monodesign/clarify.md +0 -64
  69. package/.claude/skills/monodesign/colorize.md +0 -68
  70. package/.claude/skills/monodesign/craft.md +0 -51
  71. package/.claude/skills/monodesign/critique.md +0 -66
  72. package/.claude/skills/monodesign/delight.md +0 -47
  73. package/.claude/skills/monodesign/distill.md +0 -56
  74. package/.claude/skills/monodesign/document.md +0 -83
  75. package/.claude/skills/monodesign/extract.md +0 -74
  76. package/.claude/skills/monodesign/harden.md +0 -65
  77. package/.claude/skills/monodesign/init.md +0 -30
  78. package/.claude/skills/monodesign/layout.md +0 -36
  79. package/.claude/skills/monodesign/live.md +0 -34
  80. package/.claude/skills/monodesign/onboard.md +0 -50
  81. package/.claude/skills/monodesign/optimize.md +0 -64
  82. package/.claude/skills/monodesign/overdrive.md +0 -56
  83. package/.claude/skills/monodesign/polish.md +0 -68
  84. package/.claude/skills/monodesign/quieter.md +0 -57
  85. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  86. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  87. package/.claude/skills/monodesign/reference/android.md +0 -40
  88. package/.claude/skills/monodesign/reference/animate.md +0 -203
  89. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  90. package/.claude/skills/monodesign/reference/audit.md +0 -135
  91. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  92. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  93. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  94. package/.claude/skills/monodesign/reference/brand.md +0 -108
  95. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  96. package/.claude/skills/monodesign/reference/codex.md +0 -105
  97. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  98. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  99. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  100. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  101. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  102. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  103. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  104. package/.claude/skills/monodesign/reference/craft.md +0 -123
  105. package/.claude/skills/monodesign/reference/critique.md +0 -780
  106. package/.claude/skills/monodesign/reference/delight.md +0 -302
  107. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  108. package/.claude/skills/monodesign/reference/distill.md +0 -111
  109. package/.claude/skills/monodesign/reference/document.md +0 -429
  110. package/.claude/skills/monodesign/reference/extract.md +0 -69
  111. package/.claude/skills/monodesign/reference/harden.md +0 -347
  112. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  113. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  114. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  115. package/.claude/skills/monodesign/reference/init.md +0 -221
  116. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  117. package/.claude/skills/monodesign/reference/ios.md +0 -45
  118. package/.claude/skills/monodesign/reference/layout.md +0 -185
  119. package/.claude/skills/monodesign/reference/live.md +0 -710
  120. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  121. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  122. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  123. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  124. package/.claude/skills/monodesign/reference/personas.md +0 -179
  125. package/.claude/skills/monodesign/reference/polish.md +0 -241
  126. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  127. package/.claude/skills/monodesign/reference/product.md +0 -60
  128. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  129. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  130. package/.claude/skills/monodesign/reference/shape.md +0 -165
  131. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  132. package/.claude/skills/monodesign/reference/teach.md +0 -10
  133. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  134. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  135. package/.claude/skills/monodesign/reference/typography.md +0 -159
  136. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  137. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  138. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  139. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  140. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  141. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  142. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  143. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  144. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  145. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  146. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  147. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  148. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  149. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  150. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  151. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -339
  152. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  153. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  154. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  155. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  156. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  157. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  158. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  159. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  160. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  161. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  162. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  163. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  164. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  165. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  166. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  167. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  168. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  169. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  170. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  171. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  172. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  173. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  174. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  175. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  176. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  177. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  178. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  179. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  180. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  181. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  182. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  183. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  184. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  185. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  186. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  187. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  188. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  189. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  190. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  191. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  192. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  193. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  194. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  195. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  196. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  197. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  198. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  199. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  200. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  201. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  202. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  203. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  204. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  205. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  206. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  207. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  208. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  209. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  210. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  211. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  212. package/.claude/skills/monodesign/shape.md +0 -71
  213. package/.claude/skills/monodesign/teach.md +0 -18
  214. package/.claude/skills/monodesign/typeset.md +0 -59
@@ -1,129 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { resolveProjectRoot } from '../context.mjs';
4
- export { MONODESIGN_COMMAND_PREFIX } from './provider.mjs';
5
-
6
- export const MONODESIGN_DIR = '.monodesign';
7
- export const LIVE_DIR = 'live';
8
- export const CRITIQUE_DIR = 'critique';
9
-
10
- export function getMonodesignDir(cwd = process.cwd(), options = {}) {
11
- return path.join(resolveProjectRoot(cwd, options), MONODESIGN_DIR);
12
- }
13
-
14
- export function getDesignSidecarPath(cwd = process.cwd(), options = {}) {
15
- return path.join(getMonodesignDir(cwd, options), 'design.json');
16
- }
17
-
18
- export function getDesignSidecarCandidates(cwd = process.cwd(), contextDir = cwd, options = {}) {
19
- const projectRoot = resolveProjectRoot(cwd, options);
20
- const candidates = [
21
- getDesignSidecarPath(cwd, options),
22
- path.join(projectRoot, 'DESIGN.json'),
23
- ];
24
- const contextLegacy = path.join(contextDir, 'DESIGN.json');
25
- if (!candidates.includes(contextLegacy)) candidates.push(contextLegacy);
26
- return candidates;
27
- }
28
-
29
- export function resolveDesignSidecarPath(cwd = process.cwd(), contextDir = cwd, options = {}) {
30
- return firstExisting(getDesignSidecarCandidates(cwd, contextDir, options));
31
- }
32
-
33
- export function getLiveDir(cwd = process.cwd(), options = {}) {
34
- return path.join(getMonodesignDir(cwd, options), LIVE_DIR);
35
- }
36
-
37
- export function getLiveConfigPath(cwd = process.cwd(), options = {}) {
38
- return path.join(getLiveDir(cwd, options), 'config.json');
39
- }
40
-
41
- export function getLegacyLiveConfigPath(scriptsDir) {
42
- return path.join(scriptsDir, 'config.json');
43
- }
44
-
45
- export function resolveLiveConfigPath({ cwd = process.cwd(), scriptsDir, env = process.env, targetPath } = {}) {
46
- if (env.MONODESIGN_LIVE_CONFIG?.trim()) {
47
- const configured = env.MONODESIGN_LIVE_CONFIG.trim();
48
- return path.isAbsolute(configured) ? configured : path.resolve(cwd, configured);
49
- }
50
- const primary = getLiveConfigPath(cwd, { targetPath });
51
- if (fs.existsSync(primary)) return primary;
52
- if (scriptsDir) {
53
- const legacy = getLegacyLiveConfigPath(scriptsDir);
54
- if (fs.existsSync(legacy)) return legacy;
55
- }
56
- return primary;
57
- }
58
-
59
- export function getLiveServerPath(cwd = process.cwd(), options = {}) {
60
- return path.join(getLiveDir(cwd, options), 'server.json');
61
- }
62
-
63
- export function getLegacyLiveServerPath(cwd = process.cwd(), options = {}) {
64
- return path.join(resolveProjectRoot(cwd, options), '.monodesign-live.json');
65
- }
66
-
67
- export function readLiveServerInfo(cwd = process.cwd(), options = {}) {
68
- for (const filePath of [getLiveServerPath(cwd, options), getLegacyLiveServerPath(cwd, options)]) {
69
- try {
70
- const info = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
71
- if (info && typeof info.pid === 'number' && !isLiveServerPidReachable(info.pid)) {
72
- try { fs.unlinkSync(filePath); } catch {}
73
- continue;
74
- }
75
- return { info, path: filePath };
76
- } catch {
77
- /* try next */
78
- }
79
- }
80
- return null;
81
- }
82
-
83
- export function isLiveServerPidReachable(pid) {
84
- try {
85
- process.kill(pid, 0);
86
- return true;
87
- } catch (err) {
88
- // ESRCH means "no such process". EPERM means the process exists but this
89
- // user cannot signal it, so the live server info is still valid.
90
- return err?.code !== 'ESRCH';
91
- }
92
- }
93
-
94
- export function writeLiveServerInfo(cwd = process.cwd(), info, options = {}) {
95
- const filePath = getLiveServerPath(cwd, options);
96
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
97
- fs.writeFileSync(filePath, JSON.stringify(info));
98
- return filePath;
99
- }
100
-
101
- export function removeLiveServerInfo(cwd = process.cwd(), options = {}) {
102
- for (const filePath of [getLiveServerPath(cwd, options), getLegacyLiveServerPath(cwd, options)]) {
103
- try { fs.unlinkSync(filePath); } catch {}
104
- }
105
- }
106
-
107
- export function getLiveSessionsDir(cwd = process.cwd(), options = {}) {
108
- return path.join(getLiveDir(cwd, options), 'sessions');
109
- }
110
-
111
- export function getLegacyLiveSessionsDir(cwd = process.cwd(), options = {}) {
112
- return path.join(resolveProjectRoot(cwd, options), '.monodesign-live', 'sessions');
113
- }
114
-
115
- export function getLiveAnnotationsDir(cwd = process.cwd(), options = {}) {
116
- return path.join(getLiveDir(cwd, options), 'annotations');
117
- }
118
-
119
- export function getCritiqueDir(cwd = process.cwd(), options = {}) {
120
- return path.join(getMonodesignDir(cwd, options), CRITIQUE_DIR);
121
- }
122
-
123
- export function getLegacyLiveAnnotationsDir(cwd = process.cwd(), options = {}) {
124
- return path.join(resolveProjectRoot(cwd, options), '.monodesign-live', 'annotations');
125
- }
126
-
127
- function firstExisting(paths) {
128
- return paths.find((filePath) => fs.existsSync(filePath)) || null;
129
- }
@@ -1,4 +0,0 @@
1
- // Source scripts default to slash commands. The provider build replaces only
2
- // this exact declaration, avoiding heuristic rewrites across executable code.
3
- export const MONODESIGN_COMMAND_PREFIX = '/'; // @monodesign-provider-command-prefix
4
- export const MONODESIGN_COMMAND = `${MONODESIGN_COMMAND_PREFIX}monodesign`;
@@ -1,42 +0,0 @@
1
- class TargetArgError extends Error {
2
- constructor(message, code) {
3
- super(message);
4
- this.name = 'TargetArgError';
5
- this.code = code;
6
- }
7
- }
8
-
9
- export function parseTargetPath(args = [], { strict = false } = {}) {
10
- let targetPath = null;
11
- for (let i = 0; i < args.length; i++) {
12
- const arg = String(args[i]);
13
- if (arg === '--target' || arg === '-t') {
14
- const next = args[i + 1];
15
- if (next && !String(next).startsWith('-')) {
16
- targetPath = String(next);
17
- i++;
18
- continue;
19
- }
20
- if (strict) {
21
- throw new TargetArgError('--target requires a path value.', 'TARGET_VALUE_MISSING');
22
- }
23
- continue;
24
- }
25
- if (arg.startsWith('--target=')) {
26
- const value = arg.slice('--target='.length);
27
- if (value) {
28
- targetPath = value;
29
- continue;
30
- }
31
- if (strict) {
32
- throw new TargetArgError('--target requires a path value.', 'TARGET_VALUE_MISSING');
33
- }
34
- }
35
- }
36
- return targetPath;
37
- }
38
-
39
- export function parseTargetOptions(args = [], options = {}) {
40
- const targetPath = parseTargetPath(args, options);
41
- return targetPath ? { targetPath } : {};
42
- }
@@ -1,50 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- export const LIVE_BROWSER_SCRIPT_PARTS = Object.freeze([
5
- Object.freeze({ name: 'session-state', file: 'live-browser-session.js' }),
6
- Object.freeze({ name: 'dom-helpers', file: 'live-browser-dom.js' }),
7
- Object.freeze({ name: 'browser-ui', file: 'live-browser.js' }),
8
- ]);
9
-
10
- export function resolveLiveBrowserScriptParts(scriptsDir, parts = LIVE_BROWSER_SCRIPT_PARTS) {
11
- if (!scriptsDir) throw new Error('scriptsDir is required');
12
- return parts.map((part, index) => ({
13
- ...part,
14
- index,
15
- path: path.join(scriptsDir, part.file),
16
- }));
17
- }
18
-
19
- export function assertLiveBrowserScriptParts(parts, exists = fs.existsSync) {
20
- for (const part of parts) {
21
- if (!exists(part.path)) {
22
- throw new Error(`Live browser script part missing: ${part.name} (${part.path})`);
23
- }
24
- }
25
- return parts;
26
- }
27
-
28
- export function readLiveBrowserScriptParts(parts, readFile = (filePath) => fs.readFileSync(filePath, 'utf-8')) {
29
- return parts.map((part) => ({
30
- ...part,
31
- source: readFile(part.path),
32
- }));
33
- }
34
-
35
- export function assembleLiveBrowserScript({ token, port, vocabulary, commandPrefix = '/', parts }) {
36
- const prelude =
37
- `window.__MONODESIGN_TOKEN__ = '${token}';\n` +
38
- `window.__MONODESIGN_PORT__ = ${port};\n` +
39
- `window.__MONODESIGN_COMMAND_PREFIX__ = ${JSON.stringify(commandPrefix)};\n` +
40
- // Canonical command vocabulary (values + labels + icons). live-browser.js
41
- // builds its action picker from this instead of an inline copy.
42
- `window.__MONODESIGN_VOCAB__ = ${JSON.stringify(vocabulary)};\n`;
43
-
44
- const body = parts.map((part) => {
45
- const file = part.file || path.basename(part.path || '');
46
- return `// --- monodesign live script part: ${part.name} (${file}) ---\n${part.source}`;
47
- }).join('\n');
48
-
49
- return prelude + body;
50
- }
@@ -1,19 +0,0 @@
1
- export function completionTypeForAcceptResult(eventType, acceptResult) {
2
- if (eventType === 'discard') return acceptResult?.handled === true ? 'discarded' : 'error';
3
- if (acceptResult?.handled === true && acceptResult?.carbonize === true) return 'agent_done';
4
- if (acceptResult?.handled === true) return 'complete';
5
- if (acceptResult?.mode === 'error') return 'error';
6
- if (eventType === 'accept' && acceptResult?.previewMode === 'svelte-component') return 'error';
7
- return 'agent_done';
8
- }
9
-
10
- export function completionAckForAcceptResult(eventId, completionType, acceptResult) {
11
- const ack = { ok: true, type: completionType };
12
- if (acceptResult?.handled === true && acceptResult?.carbonize === true) {
13
- ack.final = false;
14
- ack.requiresComplete = true;
15
- ack.nextCommand = `live-complete.mjs --id ${eventId}`;
16
- ack.message = 'Carbonize cleanup must be verified, then the session must be completed explicitly before polling again.';
17
- }
18
- return ack;
19
- }
@@ -1,137 +0,0 @@
1
- /**
2
- * Shared event validation for the live helper server.
3
- * Extracted for unit testing (insert mode rules).
4
- */
5
-
6
- import { canCreateInsert } from './insert-ui.mjs';
7
-
8
- // The accepted visual action values come from the canonical vocabulary so the
9
- // validator, the picker UI, and the marketing demo never drift. Imported (not
10
- // just re-exported) so it is also in scope for the validators below.
11
- import { VISUAL_ACTIONS } from './vocabulary.mjs';
12
- export { VISUAL_ACTIONS };
13
-
14
- const ID_PATTERN = /^[0-9a-f]{8}$/;
15
- const VARIANT_ID_PATTERN = /^[0-9]{1,3}$/;
16
- const INSERT_POSITIONS = new Set(['before', 'after']);
17
- const FORBIDDEN_MANUAL_EDIT_TEXT_CHARS = ['<', '{', '}', '`'];
18
-
19
- function isValidId(v) { return typeof v === 'string' && ID_PATTERN.test(v); }
20
- function isValidVariantId(v) { return typeof v === 'string' && VARIANT_ID_PATTERN.test(v); }
21
-
22
- function validateManualEditText(newText) {
23
- if (typeof newText !== 'string') return null;
24
- const hits = FORBIDDEN_MANUAL_EDIT_TEXT_CHARS.filter((char) => newText.includes(char));
25
- return hits.length > 0 ? hits : null;
26
- }
27
-
28
- function validateAnnotationFields(msg) {
29
- if (msg.screenshotPath !== undefined && typeof msg.screenshotPath !== 'string') {
30
- return 'generate: screenshotPath must be string';
31
- }
32
- if (msg.comments !== undefined && !Array.isArray(msg.comments)) {
33
- return 'generate: comments must be array';
34
- }
35
- if (msg.strokes !== undefined && !Array.isArray(msg.strokes)) {
36
- return 'generate: strokes must be array';
37
- }
38
- return null;
39
- }
40
-
41
- function validateInsertGenerate(msg) {
42
- if (!msg.insert || typeof msg.insert !== 'object') return 'generate: insert mode requires insert object';
43
- if (!INSERT_POSITIONS.has(msg.insert.position)) return 'generate: insert.position must be before or after';
44
- const anchor = msg.insert.anchor;
45
- if (!anchor || typeof anchor !== 'object') return 'generate: insert.anchor required';
46
- if (!anchor.tagName && !anchor.outerHTML && !(Array.isArray(anchor.classes) && anchor.classes.length)) {
47
- return 'generate: insert.anchor needs tagName, classes, or outerHTML';
48
- }
49
- if (!msg.placeholder || typeof msg.placeholder !== 'object') return 'generate: insert mode requires placeholder dimensions';
50
- if (!Number.isFinite(msg.placeholder.width) || !Number.isFinite(msg.placeholder.height)) {
51
- return 'generate: placeholder width and height must be numbers';
52
- }
53
- if (!canCreateInsert({
54
- prompt: msg.freeformPrompt,
55
- comments: msg.comments,
56
- strokes: msg.strokes,
57
- })) {
58
- return 'generate: insert requires freeformPrompt or annotations';
59
- }
60
- return validateAnnotationFields(msg);
61
- }
62
-
63
- function validateReplaceGenerate(msg) {
64
- if (!msg.action || !VISUAL_ACTIONS.includes(msg.action)) return 'generate: invalid action';
65
- if (!msg.element?.outerHTML) return 'generate: missing element context';
66
- return validateAnnotationFields(msg);
67
- }
68
-
69
- function validateManualEditEvent(msg, label) {
70
- if (!isValidId(msg.id)) return `${label}: missing or malformed id`;
71
- if (!msg.pageUrl || typeof msg.pageUrl !== 'string') return `${label}: missing pageUrl`;
72
- if (!msg.element || typeof msg.element !== 'object') return `${label}: missing element`;
73
- if (!Array.isArray(msg.ops) || msg.ops.length === 0) return `${label}: ops must be non-empty array`;
74
- if (msg.ops.length > 100) return `${label}: too many ops (max 100)`;
75
- for (const op of msg.ops) {
76
- if (typeof op.ref !== 'string') return `${label}: op.ref required`;
77
- if (typeof op.tag !== 'string') return `${label}: op.tag required`;
78
- if (typeof op.originalText !== 'string') return `${label}: op.originalText required`;
79
- if (op.deleted !== true && typeof op.newText !== 'string') {
80
- return `${label}: text op requires newText`;
81
- }
82
- if (typeof op.newText === 'string') {
83
- if (op.deleted !== true && op.newText.trim().length === 0) {
84
- return `${label}: newText cannot be empty`;
85
- }
86
- const forbidden = validateManualEditText(op.newText);
87
- if (forbidden) {
88
- return `${label}: newText cannot contain ${forbidden.join(' ')} (plain text only; ask the AI to insert markup)`;
89
- }
90
- }
91
- }
92
- return null;
93
- }
94
-
95
- export function validateEvent(msg) {
96
- if (!msg || typeof msg !== 'object' || !msg.type) return 'Missing or invalid message';
97
- switch (msg.type) {
98
- case 'generate':
99
- if (!isValidId(msg.id)) return 'generate: missing or malformed id';
100
- if (!Number.isInteger(msg.count) || msg.count < 1 || msg.count > 8) return 'generate: count must be 1-8';
101
- if (msg.mode === 'insert') return validateInsertGenerate(msg);
102
- return validateReplaceGenerate(msg);
103
- case 'accept':
104
- if (!isValidId(msg.id)) return 'accept: missing or malformed id';
105
- if (!isValidVariantId(msg.variantId)) return 'accept: missing or malformed variantId';
106
- if (msg.paramValues !== undefined) {
107
- if (typeof msg.paramValues !== 'object' || msg.paramValues === null || Array.isArray(msg.paramValues)) {
108
- return 'accept: paramValues must be an object';
109
- }
110
- }
111
- return null;
112
- case 'discard':
113
- return isValidId(msg.id) ? null : 'discard: missing or malformed id';
114
- case 'checkpoint':
115
- if (!isValidId(msg.id)) return 'checkpoint: missing or malformed id';
116
- if (!Number.isInteger(msg.revision) || msg.revision < 0) return 'checkpoint: revision must be a non-negative integer';
117
- if (msg.paramValues !== undefined && (typeof msg.paramValues !== 'object' || msg.paramValues === null || Array.isArray(msg.paramValues))) {
118
- return 'checkpoint: paramValues must be an object';
119
- }
120
- return null;
121
- case 'exit':
122
- return null;
123
- case 'prefetch':
124
- if (!msg.pageUrl || typeof msg.pageUrl !== 'string') return 'prefetch: missing pageUrl';
125
- return null;
126
- case 'manual_edits':
127
- return validateManualEditEvent(msg, 'manual_edits');
128
- case 'steer':
129
- if (!isValidId(msg.id)) return 'steer: missing or malformed id';
130
- if (typeof msg.message !== 'string' || !msg.message.trim()) return 'steer: message required';
131
- if (msg.message.length > 4000) return 'steer: message too long';
132
- if (msg.pageUrl !== undefined && typeof msg.pageUrl !== 'string') return 'steer: pageUrl must be string';
133
- return null;
134
- default:
135
- return `Unknown event type: ${msg.type}`;
136
- }
137
- }