@monoes/monomindcli 2.15.5 → 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 (226) hide show
  1. package/dist/src/commands/cleanup-plan.d.ts +57 -0
  2. package/dist/src/commands/cleanup-plan.d.ts.map +1 -0
  3. package/dist/src/commands/cleanup-plan.js +379 -0
  4. package/dist/src/commands/cleanup-plan.js.map +1 -0
  5. package/dist/src/commands/cleanup.d.ts.map +1 -1
  6. package/dist/src/commands/cleanup.js +87 -160
  7. package/dist/src/commands/cleanup.js.map +1 -1
  8. package/dist/src/commands/search-universal.d.ts +8 -0
  9. package/dist/src/commands/search-universal.d.ts.map +1 -1
  10. package/dist/src/commands/search-universal.js +14 -0
  11. package/dist/src/commands/search-universal.js.map +1 -1
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +11 -2
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/orgrt/completion-gate.d.ts +40 -0
  16. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  17. package/dist/src/orgrt/completion-gate.js +90 -9
  18. package/dist/src/orgrt/completion-gate.js.map +1 -1
  19. package/dist/src/orgrt/daemon.d.ts +4 -0
  20. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  21. package/dist/src/orgrt/daemon.js +15 -2
  22. package/dist/src/orgrt/daemon.js.map +1 -1
  23. package/dist/src/orgrt/decisions.d.ts +24 -1
  24. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  25. package/dist/src/orgrt/decisions.js +171 -11
  26. package/dist/src/orgrt/decisions.js.map +1 -1
  27. package/dist/src/orgrt/idle-deadline.d.ts +10 -0
  28. package/dist/src/orgrt/idle-deadline.d.ts.map +1 -1
  29. package/dist/src/orgrt/idle-deadline.js +8 -0
  30. package/dist/src/orgrt/idle-deadline.js.map +1 -1
  31. package/dist/src/orgrt/mailbox.d.ts +7 -0
  32. package/dist/src/orgrt/mailbox.d.ts.map +1 -1
  33. package/dist/src/orgrt/mailbox.js +14 -0
  34. package/dist/src/orgrt/mailbox.js.map +1 -1
  35. package/dist/src/orgrt/review-packet.d.ts +1 -1
  36. package/dist/src/orgrt/review-packet.d.ts.map +1 -1
  37. package/dist/src/orgrt/review-packet.js +2 -1
  38. package/dist/src/orgrt/review-packet.js.map +1 -1
  39. package/dist/src/orgrt/role-sandbox.d.ts +1 -0
  40. package/dist/src/orgrt/role-sandbox.d.ts.map +1 -1
  41. package/dist/src/orgrt/role-sandbox.js +6 -1
  42. package/dist/src/orgrt/role-sandbox.js.map +1 -1
  43. package/dist/src/orgrt/session.d.ts +3 -0
  44. package/dist/src/orgrt/session.d.ts.map +1 -1
  45. package/dist/src/orgrt/session.js +8 -1
  46. package/dist/src/orgrt/session.js.map +1 -1
  47. package/dist/src/orgrt/task-dag.d.ts +3 -0
  48. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  49. package/dist/src/orgrt/task-dag.js +7 -0
  50. package/dist/src/orgrt/task-dag.js.map +1 -1
  51. package/dist/src/orgrt/types.d.ts +3 -0
  52. package/dist/src/orgrt/types.d.ts.map +1 -1
  53. package/dist/src/orgrt/types.js +6 -2
  54. package/dist/src/orgrt/types.js.map +1 -1
  55. package/dist/src/update/checker.d.ts +3 -1
  56. package/dist/src/update/checker.d.ts.map +1 -1
  57. package/dist/src/update/checker.js +7 -3
  58. package/dist/src/update/checker.js.map +1 -1
  59. package/dist/src/update/index.d.ts +16 -0
  60. package/dist/src/update/index.d.ts.map +1 -1
  61. package/dist/src/update/index.js +37 -1
  62. package/dist/src/update/index.js.map +1 -1
  63. package/dist/src/update/refresh-worker.d.ts +9 -0
  64. package/dist/src/update/refresh-worker.d.ts.map +1 -0
  65. package/dist/src/update/refresh-worker.js +17 -0
  66. package/dist/src/update/refresh-worker.js.map +1 -0
  67. package/dist/src/utils/resource-governor.d.ts +44 -2
  68. package/dist/src/utils/resource-governor.d.ts.map +1 -1
  69. package/dist/src/utils/resource-governor.js +157 -40
  70. package/dist/src/utils/resource-governor.js.map +1 -1
  71. package/dist/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +4 -4
  73. package/.claude/skills/monodesign/SKILL.md +0 -257
  74. package/.claude/skills/monodesign/adapt.md +0 -53
  75. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  76. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  77. package/.claude/skills/monodesign/animate.md +0 -65
  78. package/.claude/skills/monodesign/audit.md +0 -89
  79. package/.claude/skills/monodesign/bolder.md +0 -50
  80. package/.claude/skills/monodesign/clarify.md +0 -64
  81. package/.claude/skills/monodesign/colorize.md +0 -68
  82. package/.claude/skills/monodesign/craft.md +0 -51
  83. package/.claude/skills/monodesign/critique.md +0 -66
  84. package/.claude/skills/monodesign/delight.md +0 -47
  85. package/.claude/skills/monodesign/distill.md +0 -56
  86. package/.claude/skills/monodesign/document.md +0 -83
  87. package/.claude/skills/monodesign/extract.md +0 -74
  88. package/.claude/skills/monodesign/harden.md +0 -65
  89. package/.claude/skills/monodesign/init.md +0 -30
  90. package/.claude/skills/monodesign/layout.md +0 -36
  91. package/.claude/skills/monodesign/live.md +0 -34
  92. package/.claude/skills/monodesign/onboard.md +0 -50
  93. package/.claude/skills/monodesign/optimize.md +0 -64
  94. package/.claude/skills/monodesign/overdrive.md +0 -56
  95. package/.claude/skills/monodesign/polish.md +0 -68
  96. package/.claude/skills/monodesign/quieter.md +0 -57
  97. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  98. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  99. package/.claude/skills/monodesign/reference/android.md +0 -40
  100. package/.claude/skills/monodesign/reference/animate.md +0 -203
  101. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  102. package/.claude/skills/monodesign/reference/audit.md +0 -135
  103. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  104. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  105. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  106. package/.claude/skills/monodesign/reference/brand.md +0 -108
  107. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  108. package/.claude/skills/monodesign/reference/codex.md +0 -105
  109. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  110. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  111. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  112. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  113. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  114. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  115. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  116. package/.claude/skills/monodesign/reference/craft.md +0 -123
  117. package/.claude/skills/monodesign/reference/critique.md +0 -780
  118. package/.claude/skills/monodesign/reference/delight.md +0 -302
  119. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  120. package/.claude/skills/monodesign/reference/distill.md +0 -111
  121. package/.claude/skills/monodesign/reference/document.md +0 -429
  122. package/.claude/skills/monodesign/reference/extract.md +0 -69
  123. package/.claude/skills/monodesign/reference/harden.md +0 -347
  124. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  125. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  126. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  127. package/.claude/skills/monodesign/reference/init.md +0 -221
  128. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  129. package/.claude/skills/monodesign/reference/ios.md +0 -45
  130. package/.claude/skills/monodesign/reference/layout.md +0 -185
  131. package/.claude/skills/monodesign/reference/live.md +0 -710
  132. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  133. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  134. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  135. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  136. package/.claude/skills/monodesign/reference/personas.md +0 -179
  137. package/.claude/skills/monodesign/reference/polish.md +0 -241
  138. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  139. package/.claude/skills/monodesign/reference/product.md +0 -60
  140. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  141. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  142. package/.claude/skills/monodesign/reference/shape.md +0 -165
  143. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  144. package/.claude/skills/monodesign/reference/teach.md +0 -10
  145. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  146. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  147. package/.claude/skills/monodesign/reference/typography.md +0 -159
  148. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  149. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  150. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  151. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  152. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  153. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  154. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  155. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  156. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  157. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  158. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  159. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  160. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  161. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  162. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  163. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -349
  164. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  165. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  166. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  167. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  168. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  169. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  170. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  171. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  172. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  173. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  174. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  175. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  176. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  177. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  178. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  179. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  180. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  181. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  182. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  183. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  184. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  185. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  186. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  187. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  188. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  189. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  190. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  191. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  192. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  193. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  194. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  195. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  196. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  197. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  198. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  199. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  200. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  201. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  202. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  203. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  204. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  205. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  206. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  207. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  208. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  209. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  210. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  211. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  212. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  213. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  214. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  215. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  216. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  217. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  218. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  219. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  220. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  221. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  222. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  223. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  224. package/.claude/skills/monodesign/shape.md +0 -71
  225. package/.claude/skills/monodesign/teach.md +0 -18
  226. package/.claude/skills/monodesign/typeset.md +0 -59
@@ -1,260 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Context-signals gatherer for the bare Monodesign invocation
4
- * (no-argument) path. Collects cheap, deterministic signals about the current
5
- * project and emits them as JSON.
6
- *
7
- * It does NOT score or rank. The agent reasons over the raw signals using its
8
- * knowledge of the command catalog (see SKILL.md routing rule 1). Deliberately
9
- * light: no LLM calls, no detector run (`monomind design detect` is heavier and
10
- * opt-in), no file writes. Every probe is best-effort and never throws; the
11
- * output is always valid JSON.
12
- *
13
- * Signals:
14
- * - setup: PRODUCT.md / DESIGN.md presence, register, whether code exists
15
- * - critique: the latest cached critique score (.monodesign/critique)
16
- * - git: branch + files changed vs the default branch (a scope hint)
17
- * - devServer: whether a local dev server answers on a common port (gates live)
18
- */
19
- import fs from 'node:fs';
20
- import net from 'node:net';
21
- import path from 'node:path';
22
- import { fileURLToPath } from 'node:url';
23
- import { execFileSync } from 'node:child_process';
24
- import { loadContext, extractRegister, extractPlatform } from './context.mjs';
25
- import { getCritiqueDir } from './lib/monodesign-paths.mjs';
26
- import { readTrend, extractIssueLines, trendDirection } from './critique-storage.mjs';
27
-
28
- /** Is there code here at all, or just context files / an empty repo? */
29
- function hasCode(cwd) {
30
- if (fs.existsSync(path.join(cwd, 'package.json'))) return true;
31
- for (const d of ['src', 'app', 'pages', 'site', 'public', 'components', 'lib']) {
32
- if (fs.existsSync(path.join(cwd, d))) return true;
33
- }
34
- return false;
35
- }
36
-
37
- /**
38
- * The most recent critique snapshot across all targets. Filenames are
39
- * timestamp-prefixed (`<iso>__<slug>.md`), so a lexical sort is chronological.
40
- * Parses the small frontmatter for score + P0/P1 counts, plus two "design
41
- * health" extras: the score trend for the same slug (last 3 runs, with a
42
- * direction) and the open [P0] issue titles from the snapshot body — enough
43
- * for a session to start design-health-aware without an LLM pass.
44
- */
45
- function latestCritique(cwd) {
46
- try {
47
- const dir = getCritiqueDir(cwd);
48
- if (!fs.existsSync(dir)) return null;
49
- const files = fs.readdirSync(dir).filter((f) => f.endsWith('.md')).sort();
50
- if (!files.length) return null;
51
- const newest = files[files.length - 1];
52
- const text = fs.readFileSync(path.join(dir, newest), 'utf-8');
53
- const front = text.split('---')[1] || '';
54
- const get = (k) => {
55
- const m = front.match(new RegExp(`^${k}:\\s*(.+)$`, 'm'));
56
- return m ? m[1].trim() : null;
57
- };
58
- const num = (v) => {
59
- const n = Number(v);
60
- return Number.isFinite(n) ? n : null;
61
- };
62
- const slug = get('slug');
63
- // Trend across the last 3 runs for the same slug. Frontmatter written by
64
- // critique-storage carries `total_score`; older/hand-written snapshots may
65
- // carry `score` — accept either. Best-effort: never let this probe throw.
66
- let trend = null;
67
- try {
68
- if (slug) {
69
- const rows = readTrend(slug, { limit: 3, cwd });
70
- const scores = rows
71
- .map((r) => num(r.total_score ?? r.score))
72
- .filter((n) => n !== null);
73
- if (scores.length) trend = { scores, direction: trendDirection(scores) };
74
- }
75
- } catch { /* trend stays null */ }
76
- let openP0 = [];
77
- try {
78
- openP0 = extractIssueLines(text).p0;
79
- } catch { /* openP0 stays empty */ }
80
- // Frontmatter key fallbacks: context fixtures use score/p0/p1, the
81
- // critique flow's MONODESIGN_CRITIQUE_META uses total_score/p0_count/
82
- // p1_count. `get` returns null for missing keys; keep null (not 0).
83
- const numKey = (...keys) => {
84
- for (const k of keys) {
85
- const v = get(k);
86
- if (v !== null) return num(v);
87
- }
88
- return null;
89
- };
90
- return {
91
- slug,
92
- score: numKey('score', 'total_score'),
93
- p0: numKey('p0', 'p0_count'),
94
- p1: numKey('p1', 'p1_count'),
95
- timestamp: get('timestamp'),
96
- file: path.relative(cwd, path.join(dir, newest)).split(path.sep).join('/'),
97
- trend,
98
- openP0,
99
- };
100
- } catch {
101
- return null;
102
- }
103
- }
104
-
105
- /** Branch + a scope hint: files changed vs the default branch, else working tree. */
106
- function gitSignals(cwd) {
107
- const run = (args, { trim = true } = {}) => {
108
- try {
109
- const out = execFileSync('git', args, {
110
- cwd,
111
- encoding: 'utf-8',
112
- stdio: ['ignore', 'pipe', 'ignore'],
113
- });
114
- return trim ? out.trim() : out;
115
- } catch {
116
- return null;
117
- }
118
- };
119
- if (run(['rev-parse', '--is-inside-work-tree']) !== 'true') {
120
- return { isRepo: false, branch: null, base: null, changedFiles: [], changedCount: 0 };
121
- }
122
- const branch = run(['rev-parse', '--abbrev-ref', 'HEAD']);
123
- let base = null;
124
- for (const b of ['main', 'master']) {
125
- if (run(['rev-parse', '--verify', '--quiet', b]) !== null) {
126
- base = b;
127
- break;
128
- }
129
- }
130
- const diffBase = base && branch && branch !== base ? base : null;
131
- const fromDiff = diffBase ? run(['diff', '--name-only', `${diffBase}...HEAD`]) : null;
132
- // porcelain lines are `XY PATH`: a 2-char status + a space, then the path.
133
- // Don't trim the combined output — an unstaged-modified line starts with a
134
- // leading space (` M path`), and a global trim would eat the first line's
135
- // status column and shift the slice. Renames render as `old -> new`.
136
- const fromStatus = run(['-c', 'core.quotepath=false', 'status', '--porcelain'], { trim: false });
137
- let changed = [];
138
- if (fromDiff) {
139
- changed = fromDiff.split('\n').filter(Boolean);
140
- } else if (fromStatus) {
141
- changed = fromStatus.split(/\r?\n/).filter(Boolean).map((l) => {
142
- const p = l.slice(3);
143
- const arrow = p.indexOf(' -> ');
144
- return arrow === -1 ? p : p.slice(arrow + 4);
145
- });
146
- }
147
- return {
148
- isRepo: true,
149
- branch,
150
- base: diffBase,
151
- changedFiles: changed.slice(0, 50),
152
- changedCount: changed.length,
153
- };
154
- }
155
-
156
- const COMMON_DEV_PORTS = [4321, 3000, 5173, 5174, 8080, 8000, 4200];
157
-
158
- function probePort(port, timeout = 250) {
159
- return new Promise((resolve) => {
160
- const sock = new net.Socket();
161
- let settled = false;
162
- const finish = (ok) => {
163
- if (settled) return;
164
- settled = true;
165
- try { sock.destroy(); } catch { /* ignore */ }
166
- resolve(ok);
167
- };
168
- sock.setTimeout(timeout);
169
- sock.once('connect', () => finish(true));
170
- sock.once('timeout', () => finish(false));
171
- sock.once('error', () => finish(false));
172
- sock.connect(port, '127.0.0.1');
173
- });
174
- }
175
-
176
- async function devServerSignals() {
177
- const open = [];
178
- await Promise.all(
179
- COMMON_DEV_PORTS.map(async (p) => {
180
- if (await probePort(p)) open.push(p);
181
- }),
182
- );
183
- open.sort((a, b) => a - b);
184
- return { running: open.length > 0, ports: open };
185
- }
186
-
187
- // Extensions the detector scans (mirrors the engine's walkDir set + HTML).
188
- const SCANNABLE_EXT = new Set([
189
- '.html', '.htm', '.css', '.scss',
190
- '.jsx', '.tsx', '.js', '.ts', '.vue', '.svelte', '.astro',
191
- ]);
192
- // Where UI source typically lives. The detector walks these and skips
193
- // node_modules / dist / build / .next / .nuxt automatically.
194
- const SOURCE_DIRS = ['src', 'app', 'components', 'pages', 'public'];
195
-
196
- /**
197
- * Local paths the agent should point the bundled detector at — never a URL.
198
- * A URL means a costly Puppeteer browser render, and a probed dev-server port
199
- * may not even belong to this project. An HTML *file* or a source tree is
200
- * scanned by the cheap, jsdom-free static engine. This script does NOT run the
201
- * detector; it just surfaces the target(s) so the agent can run
202
- * `node <scripts>/detect.mjs --json <targets>` and fold the hits in.
203
- */
204
- function scanTargets(cwd, git) {
205
- // 1. Dirty tree wins: scan exactly the markup/style files in flight. It's
206
- // what the user is working on, it's a small set, and it's local.
207
- if (git.isRepo && git.changedFiles.length) {
208
- const changed = git.changedFiles
209
- .filter((f) => SCANNABLE_EXT.has(path.extname(f).toLowerCase()))
210
- .filter((f) => fs.existsSync(path.join(cwd, f)));
211
- if (changed.length) return { targets: changed.slice(0, 50), via: 'git-changes' };
212
- }
213
- // 2. Otherwise scan the local source dirs that exist.
214
- const dirs = SOURCE_DIRS.filter((d) => fs.existsSync(path.join(cwd, d)));
215
- if (dirs.length) return { targets: dirs, via: 'source-dir' };
216
- // 3. A root HTML entry, or the project root as a last resort when there's
217
- // code but no conventional source dir (walkDir still skips heavy dirs).
218
- if (fs.existsSync(path.join(cwd, 'index.html'))) return { targets: ['index.html'], via: 'html' };
219
- if (hasCode(cwd)) return { targets: ['.'], via: 'root' };
220
- return { targets: [], via: null };
221
- }
222
-
223
- export async function gatherSignals(cwd = process.cwd()) {
224
- const ctx = loadContext(cwd);
225
- const git = gitSignals(cwd);
226
- return {
227
- setup: {
228
- hasProduct: ctx.hasProduct,
229
- productPath: ctx.productPath,
230
- hasDesign: ctx.hasDesign,
231
- designPath: ctx.designPath,
232
- hasCode: hasCode(cwd),
233
- register: extractRegister(ctx.product),
234
- platform: extractPlatform(ctx.product),
235
- },
236
- critique: { latest: latestCritique(cwd) },
237
- git,
238
- devServer: await devServerSignals(),
239
- scan: scanTargets(cwd, git),
240
- };
241
- }
242
-
243
- async function cli() {
244
- const signals = await gatherSignals(process.cwd());
245
- process.stdout.write(`${JSON.stringify(signals, null, 2)}\n`);
246
- }
247
-
248
- function invokedAsScript() {
249
- const arg = process.argv[1];
250
- if (!arg) return false;
251
- try {
252
- return fs.realpathSync(arg) === fs.realpathSync(fileURLToPath(import.meta.url));
253
- } catch {
254
- return false;
255
- }
256
- }
257
-
258
- if (invokedAsScript()) {
259
- cli();
260
- }