@monoes/monomindcli 2.15.6 → 2.15.7

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 (180) hide show
  1. package/dist/src/orgrt/completion-gate.d.ts +15 -0
  2. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  3. package/dist/src/orgrt/completion-gate.js +59 -3
  4. package/dist/src/orgrt/completion-gate.js.map +1 -1
  5. package/dist/src/orgrt/daemon.d.ts +4 -0
  6. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  7. package/dist/src/orgrt/daemon.js +1 -0
  8. package/dist/src/orgrt/daemon.js.map +1 -1
  9. package/dist/src/orgrt/decisions.d.ts +17 -0
  10. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  11. package/dist/src/orgrt/decisions.js +104 -4
  12. package/dist/src/orgrt/decisions.js.map +1 -1
  13. package/dist/src/orgrt/review-packet.d.ts +1 -1
  14. package/dist/src/orgrt/review-packet.d.ts.map +1 -1
  15. package/dist/src/orgrt/review-packet.js +2 -2
  16. package/dist/src/orgrt/review-packet.js.map +1 -1
  17. package/dist/src/orgrt/session.d.ts +3 -0
  18. package/dist/src/orgrt/session.d.ts.map +1 -1
  19. package/dist/src/orgrt/session.js +6 -1
  20. package/dist/src/orgrt/session.js.map +1 -1
  21. package/dist/src/orgrt/task-dag.d.ts +3 -0
  22. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  23. package/dist/src/orgrt/task-dag.js +6 -0
  24. package/dist/src/orgrt/task-dag.js.map +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +4 -4
  27. package/.claude/skills/monodesign/SKILL.md +0 -257
  28. package/.claude/skills/monodesign/adapt.md +0 -53
  29. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  30. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  31. package/.claude/skills/monodesign/animate.md +0 -65
  32. package/.claude/skills/monodesign/audit.md +0 -89
  33. package/.claude/skills/monodesign/bolder.md +0 -50
  34. package/.claude/skills/monodesign/clarify.md +0 -64
  35. package/.claude/skills/monodesign/colorize.md +0 -68
  36. package/.claude/skills/monodesign/craft.md +0 -51
  37. package/.claude/skills/monodesign/critique.md +0 -66
  38. package/.claude/skills/monodesign/delight.md +0 -47
  39. package/.claude/skills/monodesign/distill.md +0 -56
  40. package/.claude/skills/monodesign/document.md +0 -83
  41. package/.claude/skills/monodesign/extract.md +0 -74
  42. package/.claude/skills/monodesign/harden.md +0 -65
  43. package/.claude/skills/monodesign/init.md +0 -30
  44. package/.claude/skills/monodesign/layout.md +0 -36
  45. package/.claude/skills/monodesign/live.md +0 -34
  46. package/.claude/skills/monodesign/onboard.md +0 -50
  47. package/.claude/skills/monodesign/optimize.md +0 -64
  48. package/.claude/skills/monodesign/overdrive.md +0 -56
  49. package/.claude/skills/monodesign/polish.md +0 -68
  50. package/.claude/skills/monodesign/quieter.md +0 -57
  51. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  52. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  53. package/.claude/skills/monodesign/reference/android.md +0 -40
  54. package/.claude/skills/monodesign/reference/animate.md +0 -203
  55. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  56. package/.claude/skills/monodesign/reference/audit.md +0 -135
  57. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  58. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  59. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  60. package/.claude/skills/monodesign/reference/brand.md +0 -108
  61. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  62. package/.claude/skills/monodesign/reference/codex.md +0 -105
  63. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  64. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  65. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  66. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  67. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  68. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  69. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  70. package/.claude/skills/monodesign/reference/craft.md +0 -123
  71. package/.claude/skills/monodesign/reference/critique.md +0 -780
  72. package/.claude/skills/monodesign/reference/delight.md +0 -302
  73. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  74. package/.claude/skills/monodesign/reference/distill.md +0 -111
  75. package/.claude/skills/monodesign/reference/document.md +0 -429
  76. package/.claude/skills/monodesign/reference/extract.md +0 -69
  77. package/.claude/skills/monodesign/reference/harden.md +0 -347
  78. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  79. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  80. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  81. package/.claude/skills/monodesign/reference/init.md +0 -221
  82. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  83. package/.claude/skills/monodesign/reference/ios.md +0 -45
  84. package/.claude/skills/monodesign/reference/layout.md +0 -185
  85. package/.claude/skills/monodesign/reference/live.md +0 -710
  86. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  87. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  88. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  89. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  90. package/.claude/skills/monodesign/reference/personas.md +0 -179
  91. package/.claude/skills/monodesign/reference/polish.md +0 -241
  92. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  93. package/.claude/skills/monodesign/reference/product.md +0 -60
  94. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  95. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  96. package/.claude/skills/monodesign/reference/shape.md +0 -165
  97. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  98. package/.claude/skills/monodesign/reference/teach.md +0 -10
  99. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  100. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  101. package/.claude/skills/monodesign/reference/typography.md +0 -159
  102. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  103. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  104. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  105. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  106. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  107. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  108. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  109. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  110. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  111. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  112. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  113. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  114. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  115. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  116. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  117. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -339
  118. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  119. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  120. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  121. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  122. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  123. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  124. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  125. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  126. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  127. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  128. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  129. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  130. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  131. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  132. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  133. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  134. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  135. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  136. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  137. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  138. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  139. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  140. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  141. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  142. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  143. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  144. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  145. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  146. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  147. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  148. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  149. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  150. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  151. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  152. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  153. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  154. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  155. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  156. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  157. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  158. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  159. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  160. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  161. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  162. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  163. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  164. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  165. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  166. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  167. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  168. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  169. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  170. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  171. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  172. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  173. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  174. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  175. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  176. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  177. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  178. package/.claude/skills/monodesign/shape.md +0 -71
  179. package/.claude/skills/monodesign/teach.md +0 -18
  180. 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
- }