self-evolving-workflow 0.0.0-stage → 0.1.4

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 (375) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +195 -2
  3. package/dist/agent-memory-prompts.d.ts +13 -0
  4. package/dist/agent-memory-prompts.js +55 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +6 -0
  7. package/dist/closeout.d.ts +105 -0
  8. package/dist/closeout.js +473 -0
  9. package/dist/code.d.ts +39 -0
  10. package/dist/code.js +124 -0
  11. package/dist/codex-memory.d.ts +24 -0
  12. package/dist/codex-memory.js +217 -0
  13. package/dist/common.d.ts +16 -0
  14. package/dist/common.js +52 -0
  15. package/dist/context-envelope.d.ts +59 -0
  16. package/dist/context-envelope.js +23 -0
  17. package/dist/host-adapters.d.ts +34 -0
  18. package/dist/host-adapters.js +151 -0
  19. package/dist/http.d.ts +3 -0
  20. package/dist/http.js +90 -0
  21. package/dist/index.d.ts +16 -0
  22. package/dist/index.js +13 -0
  23. package/dist/knowledge-cli.d.ts +198 -0
  24. package/dist/knowledge-cli.js +761 -0
  25. package/dist/knowledge-reads.d.ts +72 -0
  26. package/dist/knowledge-reads.js +201 -0
  27. package/dist/memory-config.d.ts +44 -0
  28. package/dist/memory-config.js +204 -0
  29. package/dist/memory-evidence.d.ts +13 -0
  30. package/dist/memory-evidence.js +40 -0
  31. package/dist/memory-history.d.ts +46 -0
  32. package/dist/memory-history.js +432 -0
  33. package/dist/memory.d.ts +96 -0
  34. package/dist/memory.js +362 -0
  35. package/dist/retrospective.d.ts +57 -0
  36. package/dist/retrospective.js +240 -0
  37. package/dist/search.d.ts +36 -0
  38. package/dist/search.js +112 -0
  39. package/dist/skill-addition.d.ts +25 -0
  40. package/dist/skill-addition.js +89 -0
  41. package/dist/skill-design.d.ts +96 -0
  42. package/dist/skill-design.js +226 -0
  43. package/dist/skill-replay.d.ts +55 -0
  44. package/dist/skill-replay.js +448 -0
  45. package/dist/skill-route.d.ts +30 -0
  46. package/dist/skill-route.js +75 -0
  47. package/dist/transcript-evidence.d.ts +3 -0
  48. package/dist/transcript-evidence.js +58 -0
  49. package/dist/upstream/chunker.d.ts +24 -0
  50. package/dist/upstream/chunker.js +96 -0
  51. package/dist/upstream/file-protocol.d.ts +45 -0
  52. package/dist/upstream/file-protocol.js +117 -0
  53. package/dist/upstream/frontmatter.d.ts +47 -0
  54. package/dist/upstream/frontmatter.js +86 -0
  55. package/dist/upstream/graph-search.d.ts +33 -0
  56. package/dist/upstream/graph-search.js +67 -0
  57. package/dist/upstream/l1-extraction.d.ts +26 -0
  58. package/dist/upstream/l1-extraction.js +405 -0
  59. package/dist/upstream/llm.d.ts +8 -0
  60. package/dist/upstream/llm.js +1 -0
  61. package/dist/upstream/merge.d.ts +50 -0
  62. package/dist/upstream/merge.js +153 -0
  63. package/dist/upstream/prompts.d.ts +53 -0
  64. package/dist/upstream/prompts.js +181 -0
  65. package/dist/upstream/search-utils.d.ts +34 -0
  66. package/dist/upstream/search-utils.js +55 -0
  67. package/dist/upstream/slug.d.ts +26 -0
  68. package/dist/upstream/slug.js +103 -0
  69. package/dist/upstream/template.d.ts +29 -0
  70. package/dist/upstream/template.js +80 -0
  71. package/dist/upstream/tokenize.d.ts +4 -0
  72. package/dist/upstream/tokenize.js +29 -0
  73. package/dist/wiki-change.d.ts +76 -0
  74. package/dist/wiki-change.js +299 -0
  75. package/dist/wiki-entry.d.ts +26 -0
  76. package/dist/wiki-entry.js +93 -0
  77. package/dist/wiki-ingest.d.ts +12 -0
  78. package/dist/wiki-ingest.js +126 -0
  79. package/dist/wiki-migration.d.ts +16 -0
  80. package/dist/wiki-migration.js +268 -0
  81. package/dist/wiki-tokens.d.ts +1 -0
  82. package/dist/wiki-tokens.js +46 -0
  83. package/dist/wiki.d.ts +103 -0
  84. package/dist/wiki.js +330 -0
  85. package/dist/workflow-cli.d.ts +2 -0
  86. package/dist/workflow-cli.js +319 -0
  87. package/dist/workflow-install.d.ts +37 -0
  88. package/dist/workflow-install.js +148 -0
  89. package/dist/workflow-knowledge.d.ts +18 -0
  90. package/dist/workflow-knowledge.js +32 -0
  91. package/dist/workflow-mcp.d.ts +2 -0
  92. package/dist/workflow-mcp.js +137 -0
  93. package/dist/workflow-names.d.ts +4 -0
  94. package/dist/workflow-names.js +31 -0
  95. package/dist/workflow-runtime.d.ts +735 -0
  96. package/dist/workflow-runtime.js +747 -0
  97. package/dist/workflow-skills.d.ts +48 -0
  98. package/dist/workflow-skills.js +141 -0
  99. package/docs/images/impeccable-skill.png +0 -0
  100. package/docs/images/workflow-overview.png +0 -0
  101. package/docs/images/workflow-skills.png +0 -0
  102. package/package.json +77 -4
  103. package/skills/ew-impeccable/LICENSE +191 -0
  104. package/skills/ew-impeccable/NOTICE.md +19 -0
  105. package/skills/ew-impeccable/SKILL.md +91 -0
  106. package/skills/ew-impeccable/UPSTREAM.md +23 -0
  107. package/skills/ew-impeccable/reference/adapt.md +314 -0
  108. package/skills/ew-impeccable/reference/adapt.native.md +60 -0
  109. package/skills/ew-impeccable/reference/android.md +46 -0
  110. package/skills/ew-impeccable/reference/animate.md +91 -0
  111. package/skills/ew-impeccable/reference/audit.md +138 -0
  112. package/skills/ew-impeccable/reference/audit.native.md +141 -0
  113. package/skills/ew-impeccable/reference/bolder.md +35 -0
  114. package/skills/ew-impeccable/reference/clarify.md +96 -0
  115. package/skills/ew-impeccable/reference/colorize.md +88 -0
  116. package/skills/ew-impeccable/reference/craft-floor.md +44 -0
  117. package/skills/ew-impeccable/reference/craft.md +5 -0
  118. package/skills/ew-impeccable/reference/critique.md +808 -0
  119. package/skills/ew-impeccable/reference/degraded/asset-producer.md +36 -0
  120. package/skills/ew-impeccable/reference/degraded/documenter.md +23 -0
  121. package/skills/ew-impeccable/reference/degraded/finish-reviewer.md +72 -0
  122. package/skills/ew-impeccable/reference/degraded/manual-edit-applier.md +91 -0
  123. package/skills/ew-impeccable/reference/delight.md +72 -0
  124. package/skills/ew-impeccable/reference/distill.md +113 -0
  125. package/skills/ew-impeccable/reference/doctor.md +56 -0
  126. package/skills/ew-impeccable/reference/document.md +418 -0
  127. package/skills/ew-impeccable/reference/extract.md +68 -0
  128. package/skills/ew-impeccable/reference/harden.md +338 -0
  129. package/skills/ew-impeccable/reference/hooks.md +113 -0
  130. package/skills/ew-impeccable/reference/init.md +133 -0
  131. package/skills/ew-impeccable/reference/ios.md +51 -0
  132. package/skills/ew-impeccable/reference/layout.md +86 -0
  133. package/skills/ew-impeccable/reference/live-setup.md +102 -0
  134. package/skills/ew-impeccable/reference/live.md +326 -0
  135. package/skills/ew-impeccable/reference/new-work.md +209 -0
  136. package/skills/ew-impeccable/reference/onboard.md +236 -0
  137. package/skills/ew-impeccable/reference/operate.md +61 -0
  138. package/skills/ew-impeccable/reference/optimize.md +260 -0
  139. package/skills/ew-impeccable/reference/overdrive.md +127 -0
  140. package/skills/ew-impeccable/reference/polish.md +105 -0
  141. package/skills/ew-impeccable/reference/quieter.md +101 -0
  142. package/skills/ew-impeccable/reference/routing.md +20 -0
  143. package/skills/ew-impeccable/reference/shape.md +59 -0
  144. package/skills/ew-impeccable/reference/typeset.md +82 -0
  145. package/skills/ew-impeccable/reference/visualize.md +46 -0
  146. package/skills/ew-impeccable/scripts/build-phase.mjs +1022 -0
  147. package/skills/ew-impeccable/scripts/command-metadata.json +94 -0
  148. package/skills/ew-impeccable/scripts/comp-diff.mjs +391 -0
  149. package/skills/ew-impeccable/scripts/comp-spec.mjs +513 -0
  150. package/skills/ew-impeccable/scripts/concept-seed.mjs +814 -0
  151. package/skills/ew-impeccable/scripts/context-signals.mjs +325 -0
  152. package/skills/ew-impeccable/scripts/context.mjs +1521 -0
  153. package/skills/ew-impeccable/scripts/critique-storage.mjs +473 -0
  154. package/skills/ew-impeccable/scripts/data/font-index-failures.json +121 -0
  155. package/skills/ew-impeccable/scripts/data/font-index.json +1 -0
  156. package/skills/ew-impeccable/scripts/detect-csp.mjs +246 -0
  157. package/skills/ew-impeccable/scripts/detect.mjs +30 -0
  158. package/skills/ew-impeccable/scripts/detector/browser/injected/index.mjs +2580 -0
  159. package/skills/ew-impeccable/scripts/detector/cli/main.mjs +498 -0
  160. package/skills/ew-impeccable/scripts/detector/design-system.mjs +1311 -0
  161. package/skills/ew-impeccable/scripts/detector/detect-antipatterns-browser.js +9486 -0
  162. package/skills/ew-impeccable/scripts/detector/detect-antipatterns.mjs +51 -0
  163. package/skills/ew-impeccable/scripts/detector/engines/browser/detect-url.mjs +434 -0
  164. package/skills/ew-impeccable/scripts/detector/engines/regex/detect-text.mjs +1439 -0
  165. package/skills/ew-impeccable/scripts/detector/engines/static-html/css-cascade.mjs +1242 -0
  166. package/skills/ew-impeccable/scripts/detector/engines/static-html/detect-html.mjs +263 -0
  167. package/skills/ew-impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +189 -0
  168. package/skills/ew-impeccable/scripts/detector/findings.mjs +23 -0
  169. package/skills/ew-impeccable/scripts/detector/node/file-system.mjs +225 -0
  170. package/skills/ew-impeccable/scripts/detector/profile/profiler.mjs +166 -0
  171. package/skills/ew-impeccable/scripts/detector/registry/antipatterns.mjs +636 -0
  172. package/skills/ew-impeccable/scripts/detector/rules/checks.mjs +5750 -0
  173. package/skills/ew-impeccable/scripts/detector/shared/color.mjs +596 -0
  174. package/skills/ew-impeccable/scripts/detector/shared/constants.mjs +127 -0
  175. package/skills/ew-impeccable/scripts/detector/shared/fonts.mjs +30 -0
  176. package/skills/ew-impeccable/scripts/detector/shared/inline-ignores.mjs +148 -0
  177. package/skills/ew-impeccable/scripts/detector/shared/page.mjs +7 -0
  178. package/skills/ew-impeccable/scripts/detector/vendor/MDN-DATA-LICENSE +116 -0
  179. package/skills/ew-impeccable/scripts/detector/vendor/THIRD_PARTY_LICENSES.md +227 -0
  180. package/skills/ew-impeccable/scripts/detector/vendor/static-html-parser.build-entry.txt +11 -0
  181. package/skills/ew-impeccable/scripts/detector/vendor/static-html-parser.bundle.mjs +9121 -0
  182. package/skills/ew-impeccable/scripts/doctor.mjs +330 -0
  183. package/skills/ew-impeccable/scripts/embed-prompt.mjs +166 -0
  184. package/skills/ew-impeccable/scripts/font-match.mjs +457 -0
  185. package/skills/ew-impeccable/scripts/generate-image.mjs +447 -0
  186. package/skills/ew-impeccable/scripts/hook-admin.mjs +829 -0
  187. package/skills/ew-impeccable/scripts/hook-before-edit.mjs +538 -0
  188. package/skills/ew-impeccable/scripts/hook-lib.mjs +2493 -0
  189. package/skills/ew-impeccable/scripts/hook.mjs +79 -0
  190. package/skills/ew-impeccable/scripts/lib/artifact-schema.mjs +93 -0
  191. package/skills/ew-impeccable/scripts/lib/composition-catalog.mjs +200 -0
  192. package/skills/ew-impeccable/scripts/lib/concept-catalog.mjs +395 -0
  193. package/skills/ew-impeccable/scripts/lib/design-parser.mjs +880 -0
  194. package/skills/ew-impeccable/scripts/lib/font-fingerprint.mjs +564 -0
  195. package/skills/ew-impeccable/scripts/lib/font-index.mjs +130 -0
  196. package/skills/ew-impeccable/scripts/lib/hero-checks.mjs +246 -0
  197. package/skills/ew-impeccable/scripts/lib/image-metrics.mjs +306 -0
  198. package/skills/ew-impeccable/scripts/lib/impeccable-config.mjs +640 -0
  199. package/skills/ew-impeccable/scripts/lib/impeccable-paths.mjs +137 -0
  200. package/skills/ew-impeccable/scripts/lib/is-generated.mjs +72 -0
  201. package/skills/ew-impeccable/scripts/lib/live-path-globs.mjs +37 -0
  202. package/skills/ew-impeccable/scripts/lib/open-system-browser.mjs +26 -0
  203. package/skills/ew-impeccable/scripts/lib/png.mjs +281 -0
  204. package/skills/ew-impeccable/scripts/lib/provider.mjs +5 -0
  205. package/skills/ew-impeccable/scripts/lib/raster.mjs +194 -0
  206. package/skills/ew-impeccable/scripts/lib/roll-selection.mjs +369 -0
  207. package/skills/ew-impeccable/scripts/lib/staleness-deep.mjs +491 -0
  208. package/skills/ew-impeccable/scripts/lib/staleness-notice.mjs +169 -0
  209. package/skills/ew-impeccable/scripts/lib/staleness.mjs +532 -0
  210. package/skills/ew-impeccable/scripts/lib/surface-briefs.mjs +149 -0
  211. package/skills/ew-impeccable/scripts/lib/target-args.mjs +42 -0
  212. package/skills/ew-impeccable/scripts/lib/target-slug.mjs +33 -0
  213. package/skills/ew-impeccable/scripts/lib/template-extensions.mjs +146 -0
  214. package/skills/ew-impeccable/scripts/live/accept-css.mjs +617 -0
  215. package/skills/ew-impeccable/scripts/live/accept-verify.mjs +60 -0
  216. package/skills/ew-impeccable/scripts/live/browser-script-parts.mjs +84 -0
  217. package/skills/ew-impeccable/scripts/live/completion.mjs +28 -0
  218. package/skills/ew-impeccable/scripts/live/event-validation.mjs +199 -0
  219. package/skills/ew-impeccable/scripts/live/frameworks/astro.mjs +47 -0
  220. package/skills/ew-impeccable/scripts/live/frameworks/detect-utils.mjs +73 -0
  221. package/skills/ew-impeccable/scripts/live/frameworks/index.mjs +143 -0
  222. package/skills/ew-impeccable/scripts/live/frameworks/journal.mjs +197 -0
  223. package/skills/ew-impeccable/scripts/live/frameworks/nextjs.mjs +49 -0
  224. package/skills/ew-impeccable/scripts/live/frameworks/nuxt.mjs +161 -0
  225. package/skills/ew-impeccable/scripts/live/frameworks/script-src.mjs +17 -0
  226. package/skills/ew-impeccable/scripts/live/frameworks/static-html.mjs +26 -0
  227. package/skills/ew-impeccable/scripts/live/frameworks/sveltekit.mjs +71 -0
  228. package/skills/ew-impeccable/scripts/live/frameworks/tag-strategy.mjs +247 -0
  229. package/skills/ew-impeccable/scripts/live/frameworks/tanstack-start.mjs +70 -0
  230. package/skills/ew-impeccable/scripts/live/frameworks/vite-generic.mjs +42 -0
  231. package/skills/ew-impeccable/scripts/live/generation-preflight.mjs +149 -0
  232. package/skills/ew-impeccable/scripts/live/insert-ui.mjs +458 -0
  233. package/skills/ew-impeccable/scripts/live/instructions.mjs +142 -0
  234. package/skills/ew-impeccable/scripts/live/manual-apply.mjs +939 -0
  235. package/skills/ew-impeccable/scripts/live/manual-edit-routes.mjs +357 -0
  236. package/skills/ew-impeccable/scripts/live/manual-edits-buffer.mjs +152 -0
  237. package/skills/ew-impeccable/scripts/live/poll-lanes.mjs +14 -0
  238. package/skills/ew-impeccable/scripts/live/project-ignores.mjs +139 -0
  239. package/skills/ew-impeccable/scripts/live/roots.mjs +508 -0
  240. package/skills/ew-impeccable/scripts/live/session-store.mjs +563 -0
  241. package/skills/ew-impeccable/scripts/live/source-lock.mjs +105 -0
  242. package/skills/ew-impeccable/scripts/live/source-search.mjs +105 -0
  243. package/skills/ew-impeccable/scripts/live/svelte-ast.mjs +969 -0
  244. package/skills/ew-impeccable/scripts/live/svelte-component.mjs +1366 -0
  245. package/skills/ew-impeccable/scripts/live/sveltekit-adapter.mjs +304 -0
  246. package/skills/ew-impeccable/scripts/live/tanstack-adapter.mjs +259 -0
  247. package/skills/ew-impeccable/scripts/live/ui-surfaces.mjs +75 -0
  248. package/skills/ew-impeccable/scripts/live/vocabulary.mjs +171 -0
  249. package/skills/ew-impeccable/scripts/live-accept.mjs +938 -0
  250. package/skills/ew-impeccable/scripts/live-browser-dom.js +167 -0
  251. package/skills/ew-impeccable/scripts/live-browser-ignores.js +242 -0
  252. package/skills/ew-impeccable/scripts/live-browser-session.js +144 -0
  253. package/skills/ew-impeccable/scripts/live-browser.js +12851 -0
  254. package/skills/ew-impeccable/scripts/live-commit-manual-edits.mjs +1200 -0
  255. package/skills/ew-impeccable/scripts/live-complete.mjs +107 -0
  256. package/skills/ew-impeccable/scripts/live-copy-edit-agent.mjs +800 -0
  257. package/skills/ew-impeccable/scripts/live-discard-manual-edits.mjs +51 -0
  258. package/skills/ew-impeccable/scripts/live-inject.mjs +463 -0
  259. package/skills/ew-impeccable/scripts/live-insert.mjs +292 -0
  260. package/skills/ew-impeccable/scripts/live-manual-edit-evidence.mjs +368 -0
  261. package/skills/ew-impeccable/scripts/live-poll.mjs +430 -0
  262. package/skills/ew-impeccable/scripts/live-resume.mjs +123 -0
  263. package/skills/ew-impeccable/scripts/live-server.mjs +1698 -0
  264. package/skills/ew-impeccable/scripts/live-status.mjs +71 -0
  265. package/skills/ew-impeccable/scripts/live-target.mjs +30 -0
  266. package/skills/ew-impeccable/scripts/live-wrap.mjs +927 -0
  267. package/skills/ew-impeccable/scripts/live.mjs +334 -0
  268. package/skills/ew-impeccable/scripts/modern-screenshot.umd.js +14 -0
  269. package/skills/ew-impeccable/scripts/palette.mjs +628 -0
  270. package/skills/ew-impeccable/scripts/pin.mjs +352 -0
  271. package/skills/ew-impeccable/scripts/serve-question.mjs +1783 -0
  272. package/skills/ew-impeccable/scripts/surface-brief.mjs +74 -0
  273. package/skills/ew-knowledge/SKILL.md +35 -0
  274. package/skills/ew-knowledge/references/closeout-protocol.md +68 -0
  275. package/skills/ew-knowledge/references/knowledge-route.md +73 -0
  276. package/skills/ew-knowledge/references/wiki-maintenance.md +27 -0
  277. package/skills/ew-odyssey/SKILL.md +106 -0
  278. package/skills/ew-odyssey/references/audit-artifacts.md +7 -0
  279. package/skills/ew-odyssey/references/odyssey-base.md +104 -0
  280. package/skills/ew-odyssey/references/odyssey-debug.md +264 -0
  281. package/skills/ew-odyssey/references/odyssey-defensive.md +351 -0
  282. package/skills/ew-odyssey/references/odyssey-improve.md +230 -0
  283. package/skills/ew-odyssey/references/odyssey-planex.md +294 -0
  284. package/skills/ew-odyssey/references/odyssey-review.md +233 -0
  285. package/skills/ew-odyssey/references/odyssey-security.md +231 -0
  286. package/skills/ew-odyssey/references/odyssey-ui.md +232 -0
  287. package/skills/ew-odyssey/references/prepare/odyssey-debug.md +102 -0
  288. package/skills/ew-odyssey/references/prepare/odyssey-defensive.md +117 -0
  289. package/skills/ew-odyssey/references/prepare/odyssey-improve.md +95 -0
  290. package/skills/ew-odyssey/references/prepare/odyssey-planex.md +105 -0
  291. package/skills/ew-odyssey/references/prepare/odyssey-review.md +105 -0
  292. package/skills/ew-odyssey/references/prepare/odyssey-security.md +91 -0
  293. package/skills/ew-odyssey/references/prepare/odyssey-ui.md +88 -0
  294. package/skills/ew-odyssey/references/runtime-adapters.md +31 -0
  295. package/skills/ew-orchestrate/SKILL.md +89 -0
  296. package/skills/ew-orchestrate/references/auto-policy.md +66 -0
  297. package/skills/ew-orchestrate/references/boundary-grill.md +51 -0
  298. package/skills/ew-orchestrate/references/companion-route.md +40 -0
  299. package/skills/ew-orchestrate/references/ew-orchestrate.md +44 -0
  300. package/skills/ew-orchestrate/references/goal.md +51 -0
  301. package/skills/ew-orchestrate/references/orchestrator-run-loop.md +33 -0
  302. package/skills/ew-orchestrate/references/planning.md +54 -0
  303. package/skills/ew-orchestrate/steps/ew-analyze/SKILL.md +70 -0
  304. package/skills/ew-orchestrate/steps/ew-analyze/references/issue-gaps-analyze.md +24 -0
  305. package/skills/ew-orchestrate/steps/ew-analyze/references/prepare.md +8 -0
  306. package/skills/ew-orchestrate/steps/ew-analyze/references/workflow.md +138 -0
  307. package/skills/ew-orchestrate/steps/ew-auto-test/SKILL.md +80 -0
  308. package/skills/ew-orchestrate/steps/ew-auto-test/references/prepare.md +23 -0
  309. package/skills/ew-orchestrate/steps/ew-auto-test/references/workflow.md +31 -0
  310. package/skills/ew-orchestrate/steps/ew-blueprint/SKILL.md +122 -0
  311. package/skills/ew-orchestrate/steps/ew-blueprint/references/prepare.md +21 -0
  312. package/skills/ew-orchestrate/steps/ew-blueprint/references/workflow.md +28 -0
  313. package/skills/ew-orchestrate/steps/ew-brainstorm/SKILL.md +49 -0
  314. package/skills/ew-orchestrate/steps/ew-companion/SKILL.md +50 -0
  315. package/skills/ew-orchestrate/steps/ew-debug/SKILL.md +85 -0
  316. package/skills/ew-orchestrate/steps/ew-debug/references/prepare.md +27 -0
  317. package/skills/ew-orchestrate/steps/ew-debug/references/workflow.md +31 -0
  318. package/skills/ew-orchestrate/steps/ew-execute/SKILL.md +74 -0
  319. package/skills/ew-orchestrate/steps/ew-execute/references/prepare.md +27 -0
  320. package/skills/ew-orchestrate/steps/ew-execute/references/workflow.md +87 -0
  321. package/skills/ew-orchestrate/steps/ew-grill/SKILL.md +62 -0
  322. package/skills/ew-orchestrate/steps/ew-grill/references/prepare.md +26 -0
  323. package/skills/ew-orchestrate/steps/ew-grill/references/workflow.md +31 -0
  324. package/skills/ew-orchestrate/steps/ew-init/SKILL.md +56 -0
  325. package/skills/ew-orchestrate/steps/ew-init/references/prepare.md +25 -0
  326. package/skills/ew-orchestrate/steps/ew-init/references/workflow.md +28 -0
  327. package/skills/ew-orchestrate/steps/ew-plan/SKILL.md +131 -0
  328. package/skills/ew-orchestrate/steps/ew-plan/references/prepare.md +8 -0
  329. package/skills/ew-orchestrate/steps/ew-plan/references/tdd.md +53 -0
  330. package/skills/ew-orchestrate/steps/ew-plan/references/workflow.md +100 -0
  331. package/skills/ew-orchestrate/steps/ew-retrospective/SKILL.md +68 -0
  332. package/skills/ew-orchestrate/steps/ew-retrospective/references/prepare.md +18 -0
  333. package/skills/ew-orchestrate/steps/ew-retrospective/references/workflow.md +34 -0
  334. package/skills/ew-orchestrate/steps/ew-review/SKILL.md +45 -0
  335. package/skills/ew-orchestrate/steps/ew-review/references/prepare.md +17 -0
  336. package/skills/ew-orchestrate/steps/ew-review/references/workflow.md +116 -0
  337. package/skills/ew-orchestrate/steps/ew-roadmap/SKILL.md +62 -0
  338. package/skills/ew-orchestrate/steps/ew-roadmap/references/prepare.md +27 -0
  339. package/skills/ew-orchestrate/steps/ew-roadmap/references/workflow.md +28 -0
  340. package/skills/ew-orchestrate/steps/ew-test/SKILL.md +99 -0
  341. package/skills/ew-orchestrate/steps/ew-test/references/prepare.md +23 -0
  342. package/skills/ew-orchestrate/steps/ew-test/references/workflow.md +23 -0
  343. package/skills/ew-orchestrate/steps/ew-verify/SKILL.md +73 -0
  344. package/skills/ew-orchestrate/steps/ew-verify/references/prepare.md +21 -0
  345. package/skills/ew-orchestrate/steps/ew-verify/references/workflow.md +29 -0
  346. package/skills/ew-skill-design/SKILL.md +30 -0
  347. package/skills/ew-skill-design/references/package-contract.md +40 -0
  348. package/skills/ew-skill-design/references/validation.md +21 -0
  349. package/skills/team-swarm/SKILL.md +68 -0
  350. package/skills/team-swarm/references/mcp-coordination.md +14 -0
  351. package/skills/team-swarm/roles/analyst/role.md +181 -0
  352. package/skills/team-swarm/roles/ant/role.md +149 -0
  353. package/skills/team-swarm/roles/coordinator/commands/converge.md +112 -0
  354. package/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  355. package/skills/team-swarm/roles/coordinator/commands/iterate.md +171 -0
  356. package/skills/team-swarm/roles/coordinator/role.md +170 -0
  357. package/skills/team-swarm/roles/scorer/role.md +150 -0
  358. package/skills/team-swarm/scripts/aco.py +646 -0
  359. package/skills/team-swarm/scripts/pheromone.py +144 -0
  360. package/skills/team-swarm/scripts/scoring.py +111 -0
  361. package/skills/team-swarm/scripts/test_aco.py +606 -0
  362. package/skills/team-swarm/specs/ant-output-schema.md +127 -0
  363. package/skills/team-swarm/specs/convergence-criteria.md +108 -0
  364. package/skills/team-swarm/specs/pheromone-schema.md +125 -0
  365. package/skills/team-swarm/specs/swarm-config-template.json +71 -0
  366. package/skills/team-swarm/specs/swarm-protocol.md +119 -0
  367. package/skills/workflow-evolve/SKILL.md +64 -0
  368. package/skills/workflow-evolve/references/agy-gate.md +27 -0
  369. package/skills/workflow-evolve/references/auto-loop.md +23 -0
  370. package/skills/workflow-evolve/references/history-review.md +15 -0
  371. package/skills/workflow-evolve/scripts/codex-memory-replay.mjs +86 -0
  372. package/skills/workflow-evolve/scripts/codex-replay.mjs +1 -0
  373. package/skills/workflow-evolve/scripts/evolve-loop.mjs +260 -0
  374. package/skills/workflow-evolve/scripts/memory-codex-mcp.mjs +124 -0
  375. package/workflows/index.json +33 -0
@@ -0,0 +1,1242 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ import { profileStep, recordProfileEvent } from '../../profile/profiler.mjs';
5
+ import { CSS_NAMED_COLORS, collectCssCustomProps, cssLengthToPx, parseAnyColor, resolveLengthPx, resolveVarRefs } from '../../rules/checks.mjs';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // jsdom CSS-variable border override map
9
+ // ---------------------------------------------------------------------------
10
+ //
11
+ // jsdom's CSSOM silently drops any border shorthand that contains a var()
12
+ // reference — the computed style for the element then shows empty width,
13
+ // empty style, and a default black color. That's enough to hide the most
14
+ // common real-world side-tab pattern in AI-generated pages:
15
+ //
16
+ // :root { --brand: #87a8ff; }
17
+ // .card { border-left: 5px solid var(--brand); border-radius: 4px; }
18
+ //
19
+ // Real browsers (and therefore the browser detector path) resolve var()
20
+ // natively, so this only affects the Node jsdom path.
21
+ //
22
+ // This pre-pass walks the stylesheets, finds any rule whose per-side or
23
+ // all-sides border property contains var(), resolves the var() against
24
+ // :root-level custom properties (read from the documentElement's computed
25
+ // style, which jsdom DOES handle correctly), and attaches the resolved
26
+ // width+color to every element that matches the rule's selector. The
27
+ // Node-side `checkElementBorders` adapter consumes that map as a fallback
28
+ // whenever jsdom's computed style came back empty.
29
+ //
30
+ // Limitations (intentional, to keep the pass simple):
31
+ // * Only :root-level custom properties are resolved. Scoped overrides on
32
+ // descendants are not tracked — uncommon in practice and would require
33
+ // a per-element cascade walk.
34
+ // * @media / @supports wrapped rules are ignored (jsdom often mishandles
35
+ // these anyway).
36
+ // * The fallback only fills sides that jsdom left empty, so any rule
37
+ // whose border parses normally still wins via the computed style.
38
+
39
+ const BORDER_SHORTHAND_RE = /^(\d+(?:\.\d+)?)px\s+(solid|dashed|dotted|double|groove|ridge|inset|outset)\s+(.+)$/i;
40
+
41
+ // isNeutralColor only understands rgba()/oklch()/lch()/lab()/hsl()/hwb().
42
+ // CSS variables typically hold hex or named colors, so normalize those to
43
+ // rgb() before handing the value off to the shared check. Anything we don't
44
+ // recognise is passed through unchanged — isNeutralColor then treats it as
45
+ // non-neutral, which is the safer default (matches the oklch-era bugfix).
46
+ const NAMED_COLORS = {
47
+ white: [255, 255, 255], black: [0, 0, 0], gray: [128, 128, 128],
48
+ grey: [128, 128, 128], silver: [192, 192, 192], red: [255, 0, 0],
49
+ green: [0, 128, 0], blue: [0, 0, 255], yellow: [255, 255, 0],
50
+ };
51
+
52
+ function normalizeColorForCheck(value) {
53
+ if (!value) return value;
54
+ const v = value.trim();
55
+ const hex6 = v.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
56
+ if (hex6) {
57
+ const [r, g, b] = [parseInt(hex6[1], 16), parseInt(hex6[2], 16), parseInt(hex6[3], 16)];
58
+ return `rgb(${r}, ${g}, ${b})`;
59
+ }
60
+ const hex3 = v.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);
61
+ if (hex3) {
62
+ const [r, g, b] = [
63
+ parseInt(hex3[1] + hex3[1], 16),
64
+ parseInt(hex3[2] + hex3[2], 16),
65
+ parseInt(hex3[3] + hex3[3], 16),
66
+ ];
67
+ return `rgb(${r}, ${g}, ${b})`;
68
+ }
69
+ const named = NAMED_COLORS[v.toLowerCase()];
70
+ if (named) return `rgb(${named[0]}, ${named[1]}, ${named[2]})`;
71
+ return v;
72
+ }
73
+
74
+ function buildBorderOverrideMap(document, window) {
75
+ const map = new Map();
76
+ const rootStyle = window.getComputedStyle(document.documentElement);
77
+
78
+ function resolveVar(value, depth = 0) {
79
+ if (!value || depth > 10 || !value.includes('var(')) return value;
80
+ return value.replace(
81
+ /var\(\s*(--[\w-]+)\s*(?:,\s*([^)]+))?\s*\)/g,
82
+ (_, name, fallback) => {
83
+ const v = rootStyle.getPropertyValue(name).trim();
84
+ if (v) return resolveVar(v, depth + 1);
85
+ if (fallback) return resolveVar(fallback.trim(), depth + 1);
86
+ return '';
87
+ }
88
+ );
89
+ }
90
+
91
+ function parseShorthand(text) {
92
+ const m = text.trim().match(BORDER_SHORTHAND_RE);
93
+ if (!m) return null;
94
+ return { width: parseFloat(m[1]), color: normalizeColorForCheck(m[3]) };
95
+ }
96
+
97
+ // Read from the per-property accessors on rule.style. jsdom preserves
98
+ // each border-* shorthand it parsed, even when the overall cssText has
99
+ // been truncated (e.g. a `border: 1px solid var(...)` followed by a
100
+ // `border-left: ...` loses the first declaration but keeps the second).
101
+ const SIDE_PROPS = [
102
+ ['borderLeft', 'Left'],
103
+ ['borderRight', 'Right'],
104
+ ['borderTop', 'Top'],
105
+ ['borderBottom', 'Bottom'],
106
+ ['borderInlineStart', 'Left'],
107
+ ['borderInlineEnd', 'Right'],
108
+ ];
109
+
110
+ for (const sheet of document.styleSheets) {
111
+ let rules;
112
+ try { rules = sheet.cssRules || []; } catch { continue; }
113
+ for (const rule of rules) {
114
+ // CSSStyleRule only; skip @media / @keyframes / @supports wrappers.
115
+ if (rule.type !== 1 || !rule.style || !rule.selectorText) continue;
116
+
117
+ const perSide = {};
118
+
119
+ for (const [prop, side] of SIDE_PROPS) {
120
+ const val = rule.style[prop];
121
+ if (!val || !val.includes('var(')) continue;
122
+ const parsed = parseShorthand(resolveVar(val));
123
+ if (parsed && parsed.color) perSide[side] = parsed;
124
+ }
125
+
126
+ // Uniform `border: <w> <style> var(...)` applies to every side the
127
+ // per-side map didn't already claim.
128
+ const borderAll = rule.style.border;
129
+ if (borderAll && borderAll.includes('var(')) {
130
+ const parsed = parseShorthand(resolveVar(borderAll));
131
+ if (parsed && parsed.color) {
132
+ for (const s of ['Top', 'Right', 'Bottom', 'Left']) {
133
+ if (!perSide[s]) perSide[s] = parsed;
134
+ }
135
+ }
136
+ }
137
+
138
+ // Longhand `border-*-color: var(...)` with width/style in separate
139
+ // declarations. Rare in AI-generated pages, but cheap to cover.
140
+ for (const [prop, side] of [
141
+ ['borderLeftColor', 'Left'],
142
+ ['borderRightColor', 'Right'],
143
+ ['borderTopColor', 'Top'],
144
+ ['borderBottomColor', 'Bottom'],
145
+ ]) {
146
+ const val = rule.style[prop];
147
+ if (!val || !val.includes('var(')) continue;
148
+ const resolved = resolveVar(val).trim();
149
+ if (!resolved) continue;
150
+ // Width may or may not come from this rule — that's fine; the
151
+ // adapter only substitutes the color when jsdom left it as a
152
+ // literal var() string.
153
+ if (!perSide[side]) perSide[side] = { width: 0, color: normalizeColorForCheck(resolved) };
154
+ }
155
+
156
+ if (Object.keys(perSide).length === 0) continue;
157
+
158
+ let matched;
159
+ try { matched = document.querySelectorAll(rule.selectorText); }
160
+ catch { continue; }
161
+
162
+ for (const el of matched) {
163
+ const existing = map.get(el);
164
+ if (existing) {
165
+ // Later rules overwrite earlier ones — approximates source-order
166
+ // cascade for equal-specificity rules and is good enough for the
167
+ // uncontested var()-dropped sides we're trying to recover.
168
+ Object.assign(existing, perSide);
169
+ } else {
170
+ map.set(el, { ...perSide });
171
+ }
172
+ }
173
+ }
174
+ }
175
+
176
+ return map;
177
+ }
178
+
179
+ // Strip `@layer NAME { … }` wrappers from a CSS / HTML source, leaving
180
+ // the inner rules as flat CSS. jsdom doesn't implement CSS @layer, so
181
+ // any rule inside a layer block becomes invisible to getComputedStyle.
182
+ // Tailwind v4 makes this ubiquitous: every utility class lives in
183
+ // `@layer utilities`, and Preflight lives in `@layer base`. Without
184
+ // unwrapping, every Tailwind-styled element returns empty computed
185
+ // styles. We walk the source character-by-character, balancing braces
186
+ // so we correctly handle nested style rules inside the layer block.
187
+ function unwrapCssAtLayer(source) {
188
+ if (!source || !source.includes('@layer')) return source;
189
+ // Find `@layer <name>? {` openers. The match starts at the @, and
190
+ // we then balance braces from the opening { onward.
191
+ const re = /@layer\b[^{;]*\{/g;
192
+ let out = '';
193
+ let lastIdx = 0;
194
+ let m;
195
+ while ((m = re.exec(source)) !== null) {
196
+ const openStart = m.index;
197
+ const openEnd = m.index + m[0].length; // position right after `{`
198
+ let depth = 1;
199
+ let i = openEnd;
200
+ while (i < source.length && depth > 0) {
201
+ const c = source.charCodeAt(i);
202
+ if (c === 0x7b /* { */) depth++;
203
+ else if (c === 0x7d /* } */) depth--;
204
+ i++;
205
+ }
206
+ if (depth !== 0) {
207
+ // Unbalanced — bail and return source unchanged.
208
+ return source;
209
+ }
210
+ // Emit everything before the @layer, then the inner contents
211
+ // (between the opening { and the matched closing }), then advance.
212
+ out += source.slice(lastIdx, openStart);
213
+ out += source.slice(openEnd, i - 1); // i-1 = position of the closing }
214
+ lastIdx = i;
215
+ re.lastIndex = i;
216
+ }
217
+ out += source.slice(lastIdx);
218
+ return out;
219
+ }
220
+
221
+ // ---------------------------------------------------------------------------
222
+ // Static HTML/CSS detection (default for local HTML files)
223
+ // ---------------------------------------------------------------------------
224
+
225
+ const STATIC_INHERITED_PROPS = new Set([
226
+ 'color', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'fontVariant',
227
+ 'lineHeight', 'letterSpacing', 'textTransform', 'textAlign', 'hyphens',
228
+ 'webkitHyphens',
229
+ // visibility inherits in real CSS, and the invisible-at-rest contrast skip
230
+ // relies on descendants of a hidden container computing as hidden. A child
231
+ // that declares `visibility: visible` still overrides the inherited value.
232
+ 'visibility',
233
+ ]);
234
+
235
+ const STATIC_DEFAULT_STYLE = {
236
+ color: 'rgb(0, 0, 0)',
237
+ backgroundColor: 'rgba(0, 0, 0, 0)',
238
+ backgroundImage: 'none',
239
+ borderTopWidth: '0px',
240
+ borderRightWidth: '0px',
241
+ borderBottomWidth: '0px',
242
+ borderLeftWidth: '0px',
243
+ borderTopColor: 'rgb(0, 0, 0)',
244
+ borderRightColor: 'rgb(0, 0, 0)',
245
+ borderBottomColor: 'rgb(0, 0, 0)',
246
+ borderLeftColor: 'rgb(0, 0, 0)',
247
+ borderRadius: '0px',
248
+ outlineWidth: '0px',
249
+ outlineColor: 'rgb(0, 0, 0)',
250
+ outlineStyle: 'none',
251
+ boxShadow: 'none',
252
+ // NOT in STATIC_INHERITED_PROPS even though text-shadow inherits in real
253
+ // CSS: the glow check only needs to fire once, on the element that
254
+ // declares the shadow, not on every descendant.
255
+ textShadow: 'none',
256
+ fontFamily: '',
257
+ fontSize: '16px',
258
+ fontStyle: 'normal',
259
+ fontVariant: 'normal',
260
+ fontWeight: '400',
261
+ lineHeight: 'normal',
262
+ letterSpacing: 'normal',
263
+ textTransform: 'none',
264
+ textAlign: 'start',
265
+ hyphens: 'manual',
266
+ webkitHyphens: 'manual',
267
+ transitionProperty: '',
268
+ transitionTimingFunction: '',
269
+ animationName: '',
270
+ animationTimingFunction: '',
271
+ webkitBackgroundClip: '',
272
+ backgroundClip: '',
273
+ width: '',
274
+ height: '',
275
+ paddingTop: '0px',
276
+ paddingRight: '0px',
277
+ paddingBottom: '0px',
278
+ paddingLeft: '0px',
279
+ marginTop: '0px',
280
+ marginRight: '0px',
281
+ marginBottom: '0px',
282
+ marginLeft: '0px',
283
+ position: 'static',
284
+ visibility: 'visible',
285
+ contentVisibility: 'visible',
286
+ opacity: '1',
287
+ top: 'auto',
288
+ right: 'auto',
289
+ bottom: 'auto',
290
+ left: 'auto',
291
+ inset: '',
292
+ display: '',
293
+ overflow: 'visible',
294
+ overflowX: 'visible',
295
+ overflowY: 'visible',
296
+ };
297
+
298
+ const STATIC_PROP_MAP = {
299
+ 'background-color': 'backgroundColor',
300
+ 'background-image': 'backgroundImage',
301
+ 'background-clip': 'backgroundClip',
302
+ '-webkit-background-clip': 'webkitBackgroundClip',
303
+ 'border-radius': 'borderRadius',
304
+ 'border-top-width': 'borderTopWidth',
305
+ 'border-right-width': 'borderRightWidth',
306
+ 'border-bottom-width': 'borderBottomWidth',
307
+ 'border-left-width': 'borderLeftWidth',
308
+ 'border-top-color': 'borderTopColor',
309
+ 'border-right-color': 'borderRightColor',
310
+ 'border-bottom-color': 'borderBottomColor',
311
+ 'border-left-color': 'borderLeftColor',
312
+ 'outline-width': 'outlineWidth',
313
+ 'outline-color': 'outlineColor',
314
+ 'outline-style': 'outlineStyle',
315
+ 'box-shadow': 'boxShadow',
316
+ 'text-shadow': 'textShadow',
317
+ 'font-family': 'fontFamily',
318
+ 'font-size': 'fontSize',
319
+ 'font-style': 'fontStyle',
320
+ 'font-weight': 'fontWeight',
321
+ 'line-height': 'lineHeight',
322
+ 'letter-spacing': 'letterSpacing',
323
+ 'text-transform': 'textTransform',
324
+ 'text-align': 'textAlign',
325
+ 'hyphens': 'hyphens',
326
+ '-webkit-hyphens': 'webkitHyphens',
327
+ 'transition-property': 'transitionProperty',
328
+ 'transition-timing-function': 'transitionTimingFunction',
329
+ 'animation-name': 'animationName',
330
+ 'animation-timing-function': 'animationTimingFunction',
331
+ 'width': 'width',
332
+ 'height': 'height',
333
+ 'padding-top': 'paddingTop',
334
+ 'padding-right': 'paddingRight',
335
+ 'padding-bottom': 'paddingBottom',
336
+ 'padding-left': 'paddingLeft',
337
+ 'margin-top': 'marginTop',
338
+ 'margin-right': 'marginRight',
339
+ 'margin-bottom': 'marginBottom',
340
+ 'margin-left': 'marginLeft',
341
+ 'position': 'position',
342
+ 'visibility': 'visibility',
343
+ 'opacity': 'opacity',
344
+ 'top': 'top',
345
+ 'right': 'right',
346
+ 'bottom': 'bottom',
347
+ 'left': 'left',
348
+ 'inset': 'inset',
349
+ 'display': 'display',
350
+ 'overflow': 'overflow',
351
+ 'overflow-x': 'overflowX',
352
+ 'overflow-y': 'overflowY',
353
+ };
354
+
355
+ // parseStaticColor tries parseAnyColor first, which already resolves every
356
+ // name in the shared CSS_NAMED_COLORS table. This fallback only carries the
357
+ // keywords parseAnyColor deliberately returns null for: the cascade needs
358
+ // `transparent` to read as an actual zero-alpha color.
359
+ const STATIC_NAMED_COLORS = {
360
+ transparent: { r: 0, g: 0, b: 0, a: 0 },
361
+ };
362
+
363
+ // Named-color alternation for plucking a color token out of shorthand values
364
+ // (issue #359: a hardcoded 9-name list here silently dropped `purple`,
365
+ // `crimson`, `teal`, ... from border shorthands, so the side defaulted to
366
+ // neutral black and side-tab never fired on .html files). Derived from the
367
+ // same table parseAnyColor resolves against, so extraction and parsing can't
368
+ // drift apart. Longest-first so names containing other names as substrings
369
+ // (rebeccapurple) are matched whole.
370
+ const NAMED_COLOR_TOKENS = [...Object.keys(CSS_NAMED_COLORS), ...Object.keys(STATIC_NAMED_COLORS)]
371
+ .sort((a, b) => b.length - a.length)
372
+ .join('|');
373
+ const STATIC_COLOR_TOKEN_RE = new RegExp(
374
+ `(?:rgba?\\([^)]+\\)|oklch\\([^)]+\\)|oklab\\([^)]+\\)|lch\\([^)]+\\)|lab\\([^)]+\\)|hsla?\\([^)]+\\)|hwb\\([^)]+\\)|#[0-9a-f]{3,8}\\b|\\b(?:${NAMED_COLOR_TOKENS})\\b)`,
375
+ 'i'
376
+ );
377
+
378
+ function splitCssList(value) {
379
+ const parts = [];
380
+ let depth = 0, quote = '', start = 0;
381
+ for (let i = 0; i < value.length; i++) {
382
+ const ch = value[i];
383
+ if (quote) {
384
+ if (ch === quote && value[i - 1] !== '\\') quote = '';
385
+ continue;
386
+ }
387
+ if (ch === '"' || ch === "'") { quote = ch; continue; }
388
+ if (ch === '(' || ch === '[') depth++;
389
+ else if (ch === ')' || ch === ']') depth = Math.max(0, depth - 1);
390
+ else if (ch === ',' && depth === 0) {
391
+ parts.push(value.slice(start, i).trim());
392
+ start = i + 1;
393
+ }
394
+ }
395
+ const tail = value.slice(start).trim();
396
+ if (tail) parts.push(tail);
397
+ return parts;
398
+ }
399
+
400
+ function splitCssTokens(value) {
401
+ const tokens = [];
402
+ let depth = 0, quote = '', current = '';
403
+ for (let i = 0; i < value.length; i++) {
404
+ const ch = value[i];
405
+ if (quote) {
406
+ current += ch;
407
+ if (ch === quote && value[i - 1] !== '\\') quote = '';
408
+ continue;
409
+ }
410
+ if (ch === '"' || ch === "'") { quote = ch; current += ch; continue; }
411
+ if (ch === '(') { depth++; current += ch; continue; }
412
+ if (ch === ')') { depth = Math.max(0, depth - 1); current += ch; continue; }
413
+ if (/\s/.test(ch) && depth === 0) {
414
+ if (current) { tokens.push(current); current = ''; }
415
+ continue;
416
+ }
417
+ current += ch;
418
+ }
419
+ if (current) tokens.push(current);
420
+ return tokens;
421
+ }
422
+
423
+ function cssPropToCamel(prop) {
424
+ if (!prop) return prop;
425
+ const mapped = STATIC_PROP_MAP[prop];
426
+ if (mapped) return mapped;
427
+ return prop.replace(/-([a-z])/g, (_m, ch) => ch.toUpperCase());
428
+ }
429
+
430
+ function staticColorToCss(c) {
431
+ if (!c) return '';
432
+ if (c.a != null && c.a < 1) return `rgba(${c.r}, ${c.g}, ${c.b}, ${Number(c.a.toFixed(3))})`;
433
+ return `rgb(${c.r}, ${c.g}, ${c.b})`;
434
+ }
435
+
436
+ function parseStaticColor(value) {
437
+ const parsed = parseAnyColor(value);
438
+ if (parsed) return parsed;
439
+ const named = STATIC_NAMED_COLORS[String(value || '').trim().toLowerCase()];
440
+ return named ? { ...named } : null;
441
+ }
442
+
443
+ function extractStaticColor(value) {
444
+ if (!value) return '';
445
+ const raw = String(value).trim();
446
+ if (/^var\(/i.test(raw)) return raw;
447
+ // color-mix(...) needs balanced-paren capture (its arguments regularly
448
+ // contain nested var()/oklch() calls AND the keyword `transparent`, which
449
+ // the flat regex below would otherwise pluck out of the middle of the
450
+ // expression and report as the whole color).
451
+ const mixStart = raw.search(/color-mix\(/i);
452
+ if (mixStart !== -1) {
453
+ let depth = 0;
454
+ for (let i = raw.indexOf('(', mixStart); i < raw.length; i++) {
455
+ if (raw[i] === '(') depth++;
456
+ else if (raw[i] === ')') {
457
+ depth--;
458
+ if (depth === 0) return raw.slice(mixStart, i + 1);
459
+ }
460
+ }
461
+ return '';
462
+ }
463
+ const colorLike = raw.match(STATIC_COLOR_TOKEN_RE);
464
+ if (!colorLike) return '';
465
+ return colorLike[0];
466
+ }
467
+
468
+ function normalizeStaticCssValue(prop, value, customProps, parentStyle, currentStyle = null) {
469
+ let resolved = resolveVarRefs(String(value || '').trim(), customProps);
470
+ if (resolved === 'inherit') return parentStyle?.[prop] || STATIC_DEFAULT_STYLE[prop] || '';
471
+ const isModernBorderColor = /^border[A-Z][a-z]+Color$/.test(prop) && /^(?:oklch|oklab|lch|lab|hsl|hwb)\(/i.test(resolved);
472
+ if (!isModernBorderColor && (/color$/i.test(prop) || prop === 'color' || prop === 'backgroundColor')) {
473
+ const parsed = parseStaticColor(resolved);
474
+ if (parsed) resolved = staticColorToCss(parsed);
475
+ }
476
+ if (prop === 'fontSize') {
477
+ const base = parseFloat(parentStyle?.fontSize) || 16;
478
+ const px = resolveLengthPx(resolved, base);
479
+ if (px != null) resolved = `${px}px`;
480
+ }
481
+ if (prop === 'letterSpacing') {
482
+ const base = parseFloat(currentStyle?.fontSize || parentStyle?.fontSize) || 16;
483
+ const px = resolveLengthPx(resolved, base);
484
+ if (px != null) resolved = `${px}px`;
485
+ }
486
+ if (prop === 'lineHeight' && resolved !== 'normal') {
487
+ const base = parseFloat(currentStyle?.fontSize || parentStyle?.fontSize) || 16;
488
+ const px = resolveLengthPx(resolved, base);
489
+ if (px != null) resolved = `${px}px`;
490
+ }
491
+ return resolved;
492
+ }
493
+
494
+ function expandStaticBoxValues(tokens) {
495
+ if (tokens.length === 0) return ['0px', '0px', '0px', '0px'];
496
+ if (tokens.length === 1) return [tokens[0], tokens[0], tokens[0], tokens[0]];
497
+ if (tokens.length === 2) return [tokens[0], tokens[1], tokens[0], tokens[1]];
498
+ if (tokens.length === 3) return [tokens[0], tokens[1], tokens[2], tokens[1]];
499
+ return [tokens[0], tokens[1], tokens[2], tokens[3]];
500
+ }
501
+
502
+ function parseStaticBorder(value) {
503
+ const tokens = splitCssTokens(value);
504
+ let width = '', color = '';
505
+ for (const token of tokens) {
506
+ if (!width && /^-?[\d.]+(?:px|rem|em|%)$/.test(token)) width = token;
507
+ if (!color) color = extractStaticColor(token);
508
+ }
509
+ return { width, color };
510
+ }
511
+
512
+ function parseStaticFont(value) {
513
+ const out = [];
514
+ const slashParts = value.match(/(?:^|\s)([\d.]+(?:px|rem|em|%))(?:\/([^\s]+))?/);
515
+ if (/\bitalic\b/i.test(value)) out.push(['fontStyle', 'italic']);
516
+ const weight = value.match(/\b([1-9]00|bold|normal|lighter|bolder)\b/i);
517
+ if (weight) out.push(['fontWeight', weight[1]]);
518
+ if (slashParts) {
519
+ out.push(['fontSize', slashParts[1]]);
520
+ if (slashParts[2]) out.push(['lineHeight', slashParts[2]]);
521
+ const familyStart = value.indexOf(slashParts[0]) + slashParts[0].length;
522
+ const family = value.slice(familyStart).trim();
523
+ if (family) out.push(['fontFamily', family]);
524
+ }
525
+ return out;
526
+ }
527
+
528
+ function parseStaticTransition(value) {
529
+ const props = [];
530
+ const timings = [];
531
+ for (const item of splitCssList(value)) {
532
+ const tokens = splitCssTokens(item);
533
+ const timing = tokens.find(token => /^(?:ease|linear|step-|cubic-bezier\()/i.test(token));
534
+ if (timing) timings.push(timing);
535
+ const prop = tokens.find(token => /^[a-z-]+$/i.test(token) && !/^(?:ease|linear|infinite|alternate|forwards|backwards|both|normal|none)$/.test(token) && !/s$/.test(token));
536
+ if (prop) props.push(prop);
537
+ }
538
+ return {
539
+ property: props.join(', '),
540
+ timing: timings.join(', '),
541
+ };
542
+ }
543
+
544
+ function parseStaticAnimation(value) {
545
+ const names = [];
546
+ const timings = [];
547
+ for (const item of splitCssList(value)) {
548
+ const tokens = splitCssTokens(item);
549
+ const timing = tokens.find(token => /^(?:ease|linear|step-|cubic-bezier\()/i.test(token));
550
+ if (timing) timings.push(timing);
551
+ const name = tokens.find(token =>
552
+ /^[a-z_-][\w-]*$/i.test(token) &&
553
+ !/^(?:ease|linear|infinite|alternate|forwards|backwards|both|normal|none|running|paused)$/.test(token)
554
+ );
555
+ if (name) names.push(name);
556
+ }
557
+ return {
558
+ name: names.join(', '),
559
+ timing: timings.join(', '),
560
+ };
561
+ }
562
+
563
+ function expandStaticDeclaration(prop, value) {
564
+ const p = prop.toLowerCase();
565
+ const v = String(value || '').trim();
566
+ if (!v) return [];
567
+ if (p.startsWith('--')) return [[p, v]];
568
+ if (p === 'background') {
569
+ const out = [];
570
+ const hasImage = /gradient|url\(/i.test(v);
571
+ if (hasImage) out.push(['backgroundImage', v]);
572
+ const beforeImage = hasImage ? v.split(/(?:repeating-)?(?:linear|radial|conic)-gradient\(|url\(/i)[0] : v;
573
+ const color = extractStaticColor(hasImage ? beforeImage : v);
574
+ if (color) out.push(['backgroundColor', color]);
575
+ // The `background` shorthand resets every longhand it does not set.
576
+ // Without this, `pre code { background: none }` leaves an earlier
577
+ // `background: var(--surface)` color standing and the contrast checks
578
+ // measure text against a surface the browser never paints. var() values
579
+ // stay untouched: they may resolve to a color later in the pipeline.
580
+ if (!color && !hasImage && !/var\(/i.test(v)) {
581
+ out.push(['backgroundColor', 'rgba(0, 0, 0, 0)']);
582
+ out.push(['backgroundImage', 'none']);
583
+ }
584
+ return out;
585
+ }
586
+ if (p === 'border') {
587
+ const parsed = parseStaticBorder(v);
588
+ const out = [];
589
+ for (const side of ['Top', 'Right', 'Bottom', 'Left']) {
590
+ if (parsed.width) out.push([`border${side}Width`, parsed.width]);
591
+ if (parsed.color) out.push([`border${side}Color`, parsed.color]);
592
+ }
593
+ return out;
594
+ }
595
+ if (p === 'outline') {
596
+ // `outline` shorthand: width | style | color, in any order. Reuse the
597
+ // border parser for width + color, then sniff a style keyword from the
598
+ // tokens (solid|dashed|...). `outline: 0` (single-token zero) zeros
599
+ // the width and effectively hides the outline.
600
+ const tokens = splitCssTokens(v);
601
+ const parsed = parseStaticBorder(v);
602
+ const styleToken = tokens.find(t =>
603
+ /^(none|hidden|solid|dashed|dotted|double|groove|ridge|inset|outset)$/i.test(t)
604
+ );
605
+ const out = [];
606
+ if (parsed.width) out.push(['outlineWidth', parsed.width]);
607
+ if (parsed.color) out.push(['outlineColor', parsed.color]);
608
+ if (styleToken) out.push(['outlineStyle', styleToken.toLowerCase()]);
609
+ // `outline: 0` with no other tokens: explicit zero width.
610
+ if (!parsed.width && /^0(?:px|rem|em|%)?$/.test(v.trim())) {
611
+ out.push(['outlineWidth', '0px']);
612
+ }
613
+ return out;
614
+ }
615
+ const sideMatch = p.match(/^border-(top|right|bottom|left)$/);
616
+ if (sideMatch) {
617
+ const parsed = parseStaticBorder(v);
618
+ const side = sideMatch[1][0].toUpperCase() + sideMatch[1].slice(1);
619
+ return [
620
+ ...(parsed.width ? [[`border${side}Width`, parsed.width]] : []),
621
+ ...(parsed.color ? [[`border${side}Color`, parsed.color]] : []),
622
+ ];
623
+ }
624
+ if (p === 'border-width') {
625
+ const vals = expandStaticBoxValues(splitCssTokens(v));
626
+ return [
627
+ ['borderTopWidth', vals[0]],
628
+ ['borderRightWidth', vals[1]],
629
+ ['borderBottomWidth', vals[2]],
630
+ ['borderLeftWidth', vals[3]],
631
+ ];
632
+ }
633
+ if (p === 'border-color') {
634
+ const vals = expandStaticBoxValues(splitCssTokens(v));
635
+ return [
636
+ ['borderTopColor', vals[0]],
637
+ ['borderRightColor', vals[1]],
638
+ ['borderBottomColor', vals[2]],
639
+ ['borderLeftColor', vals[3]],
640
+ ];
641
+ }
642
+ if (p === 'padding') {
643
+ const vals = expandStaticBoxValues(splitCssTokens(v));
644
+ return [
645
+ ['paddingTop', vals[0]],
646
+ ['paddingRight', vals[1]],
647
+ ['paddingBottom', vals[2]],
648
+ ['paddingLeft', vals[3]],
649
+ ];
650
+ }
651
+ if (p === 'margin') {
652
+ const vals = expandStaticBoxValues(splitCssTokens(v));
653
+ return [
654
+ ['marginTop', vals[0]],
655
+ ['marginRight', vals[1]],
656
+ ['marginBottom', vals[2]],
657
+ ['marginLeft', vals[3]],
658
+ ];
659
+ }
660
+ if (p === 'font') return parseStaticFont(v);
661
+ if (p === 'transition') {
662
+ const parsed = parseStaticTransition(v);
663
+ return [
664
+ ...(parsed.property ? [['transitionProperty', parsed.property]] : []),
665
+ ...(parsed.timing ? [['transitionTimingFunction', parsed.timing]] : []),
666
+ ];
667
+ }
668
+ if (p === 'animation') {
669
+ const parsed = parseStaticAnimation(v);
670
+ return [
671
+ ...(parsed.name ? [['animationName', parsed.name]] : []),
672
+ ...(parsed.timing ? [['animationTimingFunction', parsed.timing]] : []),
673
+ ];
674
+ }
675
+ const mapped = cssPropToCamel(p);
676
+ if (STATIC_DEFAULT_STYLE[mapped] != null || STATIC_INHERITED_PROPS.has(mapped)) {
677
+ return [[mapped, v]];
678
+ }
679
+ return [];
680
+ }
681
+
682
+ function compareStaticPriority(a, b) {
683
+ if (!a) return true;
684
+ if (!!b.important !== !!a.important) return !!b.important;
685
+ if (!!b.inline !== !!a.inline) return !!b.inline;
686
+ for (let i = 0; i < 3; i++) {
687
+ if ((b.specificity[i] || 0) !== (a.specificity[i] || 0)) {
688
+ return (b.specificity[i] || 0) > (a.specificity[i] || 0);
689
+ }
690
+ }
691
+ return b.order >= a.order;
692
+ }
693
+
694
+ function staticSpecificity(selector) {
695
+ const noWhere = selector.replace(/:where\([^)]*\)/g, '');
696
+ const ids = (noWhere.match(/#[\w-]+/g) || []).length;
697
+ const classes = (noWhere.match(/\.[\w-]+|\[[^\]]+\]|:(?!:)[\w-]+(?:\([^)]*\))?/g) || []).length;
698
+ const stripped = noWhere
699
+ .replace(/#[\w-]+/g, ' ')
700
+ .replace(/\.[\w-]+|\[[^\]]+\]|:{1,2}[\w-]+(?:\([^)]*\))?/g, ' ')
701
+ .replace(/[*>+~(),]/g, ' ');
702
+ const types = (stripped.match(/\b[a-zA-Z][\w-]*\b/g) || []).length;
703
+ return [ids, classes, types];
704
+ }
705
+
706
+ function applyStaticDeclaration(specified, node, prop, value, meta) {
707
+ let map = specified.get(node);
708
+ if (!map) { map = new Map(); specified.set(node, map); }
709
+ for (const [expandedProp, expandedValue] of expandStaticDeclaration(prop, value)) {
710
+ const existing = map.get(expandedProp);
711
+ const next = { ...meta, prop: expandedProp, value: expandedValue };
712
+ if (compareStaticPriority(existing, next)) map.set(expandedProp, next);
713
+ }
714
+ }
715
+
716
+ function parseStaticStyleAttribute(styleText, orderBase = 0) {
717
+ const decls = [];
718
+ for (const part of String(styleText || '').split(';')) {
719
+ const idx = part.indexOf(':');
720
+ if (idx <= 0) continue;
721
+ const prop = part.slice(0, idx).trim();
722
+ let value = part.slice(idx + 1).trim();
723
+ const important = /!important\s*$/i.test(value);
724
+ value = value.replace(/\s*!important\s*$/i, '').trim();
725
+ decls.push({ prop, value, important, order: orderBase + decls.length });
726
+ }
727
+ return decls;
728
+ }
729
+
730
+ function collectStaticCssRules(cssText, csstree) {
731
+ const rules = [];
732
+ let ast;
733
+ try {
734
+ ast = csstree.parse(cssText, { positions: false, parseValue: true, parseCustomProperty: false });
735
+ } catch {
736
+ return rules;
737
+ }
738
+ let order = 0;
739
+ const walkList = (list, atRuleStack = []) => {
740
+ list?.forEach?.(node => {
741
+ if (node.type === 'Rule' && node.block) {
742
+ if (atRuleStack.some(name => /keyframes$/i.test(name))) return;
743
+ const selectorText = csstree.generate(node.prelude).trim();
744
+ const declarations = [];
745
+ node.block.children?.forEach?.(child => {
746
+ if (child.type !== 'Declaration') return;
747
+ declarations.push({
748
+ prop: child.property,
749
+ value: csstree.generate(child.value).trim(),
750
+ important: !!child.important,
751
+ });
752
+ });
753
+ for (const selector of splitCssList(selectorText)) {
754
+ if (!selector) continue;
755
+ // :hover rules can't be matched statically as-is (no interaction
756
+ // state), but they carry real cascade weight while hovered. Tag
757
+ // them and record a state-stripped selector so the hover pass can
758
+ // find their targets; specificity stays computed from the ORIGINAL
759
+ // selector (per CSS, :hover counts as a class).
760
+ const isHover = /:hover\b/i.test(selector);
761
+ let matchSelector = null;
762
+ if (isHover) {
763
+ matchSelector = selector.replace(/:hover\b/gi, '').trim();
764
+ if (!matchSelector || /[>+~]\s*$/.test(matchSelector)) matchSelector = null;
765
+ else matchSelector = matchSelector.replace(/(^|[\s>+~])(?=$|[\s>+~])/g, '$1*');
766
+ }
767
+ rules.push({ selector, declarations, specificity: staticSpecificity(selector), order: order++, isHover, matchSelector });
768
+ }
769
+ return;
770
+ }
771
+ if (node.type === 'Atrule' && node.block) {
772
+ const name = String(node.name || '').toLowerCase();
773
+ if (name === 'media' || name === 'supports' || name === 'layer') {
774
+ walkList(node.block.children, [...atRuleStack, name]);
775
+ }
776
+ }
777
+ });
778
+ };
779
+ walkList(ast.children);
780
+ return rules;
781
+ }
782
+
783
+ class StaticElement {
784
+ constructor(node, doc) {
785
+ this.node = node;
786
+ this._doc = doc;
787
+ this.nodeType = 1;
788
+ this.tagName = String(node.name || '').toUpperCase();
789
+ this.nodeName = this.tagName;
790
+ }
791
+ get parentElement() {
792
+ let cur = this.node.parent;
793
+ while (cur && cur.type !== 'tag') cur = cur.parent;
794
+ return cur ? this._doc.wrap(cur) : null;
795
+ }
796
+ get previousElementSibling() {
797
+ let cur = this.node.prev;
798
+ while (cur && cur.type !== 'tag') cur = cur.prev;
799
+ return cur ? this._doc.wrap(cur) : null;
800
+ }
801
+ get children() {
802
+ return (this.node.children || []).filter(child => child.type === 'tag').map(child => this._doc.wrap(child));
803
+ }
804
+ get childNodes() {
805
+ return (this.node.children || []).map(child => {
806
+ if (child.type === 'text') return { nodeType: 3, textContent: child.data || '' };
807
+ if (child.type === 'tag') return this._doc.wrap(child);
808
+ return { nodeType: 8, textContent: child.data || '' };
809
+ });
810
+ }
811
+ get textContent() {
812
+ return this._doc.domutils.textContent(this.node);
813
+ }
814
+ get className() {
815
+ return this.getAttribute('class') || '';
816
+ }
817
+ get id() {
818
+ return this.getAttribute('id') || '';
819
+ }
820
+ getAttribute(name) {
821
+ return this.node.attribs?.[name] ?? null;
822
+ }
823
+ querySelector(selector) {
824
+ try {
825
+ const found = this._doc.selectOne(selector, this.node.children || []);
826
+ return found ? this._doc.wrap(found) : null;
827
+ } catch {
828
+ return null;
829
+ }
830
+ }
831
+ querySelectorAll(selector) {
832
+ try {
833
+ return this._doc.selectAll(selector, this.node.children || []).map(node => this._doc.wrap(node));
834
+ } catch {
835
+ return [];
836
+ }
837
+ }
838
+ closest(selector) {
839
+ const matcher = this._doc.matcherFor(selector);
840
+ let cur = this.node;
841
+ while (cur && cur.type === 'tag') {
842
+ try {
843
+ if (matcher(cur)) return this._doc.wrap(cur);
844
+ } catch {
845
+ return null;
846
+ }
847
+ cur = cur.parent;
848
+ while (cur && cur.type !== 'tag') cur = cur.parent;
849
+ }
850
+ return null;
851
+ }
852
+ contains(other) {
853
+ let cur = other?.node || null;
854
+ while (cur) {
855
+ if (cur === this.node) return true;
856
+ cur = cur.parent;
857
+ }
858
+ return false;
859
+ }
860
+ }
861
+
862
+ class StaticDocument {
863
+ constructor(root, modules) {
864
+ this.root = root;
865
+ this.selectAll = modules.selectAll;
866
+ this.selectOne = modules.selectOne;
867
+ this.compile = modules.compile;
868
+ this.domutils = modules.domutils;
869
+ this._wrappers = new WeakMap();
870
+ this._compiledSelectors = new Map();
871
+ this._styleMap = new WeakMap();
872
+ this._hoverStyleMap = new WeakMap();
873
+ this._accentDashPseudo = new WeakSet();
874
+ // Elements whose ::before/::after paints a full-cover opaque surface
875
+ // (position absolute/fixed + inset 0 + solid background). The pseudo is
876
+ // the element's visible background for contrast purposes even though it
877
+ // never joins the element cascade.
878
+ this._pseudoSurface = new WeakMap();
879
+ }
880
+ wrap(node) {
881
+ let wrapped = this._wrappers.get(node);
882
+ if (!wrapped) {
883
+ wrapped = new StaticElement(node, this);
884
+ this._wrappers.set(node, wrapped);
885
+ }
886
+ return wrapped;
887
+ }
888
+ matcherFor(selector) {
889
+ let matcher = this._compiledSelectors.get(selector);
890
+ if (!matcher) {
891
+ try {
892
+ matcher = this.compile(selector);
893
+ } catch (err) {
894
+ // Cache the failure as a rethrower so a bad selector still reaches
895
+ // closest()'s catch on every call, first and repeat alike.
896
+ matcher = () => { throw err; };
897
+ }
898
+ this._compiledSelectors.set(selector, matcher);
899
+ }
900
+ return matcher;
901
+ }
902
+ querySelectorAll(selector) {
903
+ try {
904
+ return this.selectAll(selector, this.root.children || []).map(node => this.wrap(node));
905
+ } catch {
906
+ return [];
907
+ }
908
+ }
909
+ querySelector(selector) {
910
+ try {
911
+ const found = this.selectOne(selector, this.root.children || []);
912
+ return found ? this.wrap(found) : null;
913
+ } catch {
914
+ return null;
915
+ }
916
+ }
917
+ get documentElement() {
918
+ return this.querySelector('html');
919
+ }
920
+ get body() {
921
+ return this.querySelector('body');
922
+ }
923
+ setStyle(node, style) {
924
+ this._styleMap.set(node, style);
925
+ }
926
+ getStyle(el) {
927
+ return this._styleMap.get(el.node) || makeStaticStyle();
928
+ }
929
+ setHoverStyle(node, style) {
930
+ this._hoverStyleMap.set(node, style);
931
+ }
932
+ getHoverStyle(el) {
933
+ return this._hoverStyleMap.get(el.node) || null;
934
+ }
935
+ setAccentDashPseudo(node) {
936
+ this._accentDashPseudo.add(node);
937
+ }
938
+ hasAccentDashPseudo(el) {
939
+ return this._accentDashPseudo.has(el.node);
940
+ }
941
+ setPseudoSurface(node, color) {
942
+ this._pseudoSurface.set(node, color);
943
+ }
944
+ getPseudoSurface(el) {
945
+ return this._pseudoSurface.get(el.node) || null;
946
+ }
947
+ }
948
+
949
+ function makeStaticStyle(values = {}) {
950
+ const style = { ...STATIC_DEFAULT_STYLE, ...values };
951
+ style.getPropertyValue = (prop) => {
952
+ const key = cssPropToCamel(prop);
953
+ return style[key] || style[prop] || '';
954
+ };
955
+ return style;
956
+ }
957
+
958
+ function buildStaticWindow(staticDoc) {
959
+ return {
960
+ document: staticDoc,
961
+ getComputedStyle: (el) => staticDoc.getStyle(el),
962
+ getHoverStyle: (el) => staticDoc.getHoverStyle(el),
963
+ hasAccentDashPseudo: (el) => staticDoc.hasAccentDashPseudo(el),
964
+ getPseudoSurface: (el) => staticDoc.getPseudoSurface(el),
965
+ };
966
+ }
967
+
968
+ function resolveLinkedCssPath(fileDir, href) {
969
+ const stripped = href.split(/[?#]/)[0];
970
+ const rootRelative = stripped.startsWith('/') && !stripped.startsWith('//');
971
+ if (!rootRelative) return path.resolve(fileDir, stripped);
972
+ // Drop "." and reject ".." so /../outside.css cannot walk out of dir.
973
+ const segments = stripped.replace(/^\/+/, '').split(/[/\\]/).filter(p => p && p !== '.');
974
+ if (segments.some(p => p === '..')) return path.join(fileDir, segments.filter(p => p !== '..').join(path.sep));
975
+ const rel = segments.join(path.sep);
976
+ let dir = fileDir;
977
+ for (;;) {
978
+ const parent = path.dirname(dir);
979
+ if (parent === dir) break; // never use the filesystem root as document root
980
+ try {
981
+ const candidate = path.join(dir, rel);
982
+ if (fs.statSync(candidate).isFile()) return candidate;
983
+ } catch { /* missing or unreadable candidate */ }
984
+ // Stop at the project root so a coincidental ~/static/app.css cannot win.
985
+ try {
986
+ if (fs.existsSync(path.join(dir, 'package.json')) || fs.existsSync(path.join(dir, '.git'))) break;
987
+ } catch { /* unreadable marker */ }
988
+ dir = parent;
989
+ }
990
+ return path.join(fileDir, rel);
991
+ }
992
+
993
+ function collectStaticCssText(root, fileDir, profile, filePath, modules) {
994
+ const styleTexts = [];
995
+ const warnedMissingStylesheets = new Set();
996
+ for (const styleEl of modules.selectAll('style', root.children || [])) {
997
+ styleTexts.push(modules.domutils.textContent(styleEl));
998
+ }
999
+ const links = modules.selectAll('link', root.children || []);
1000
+ for (const link of links) {
1001
+ const rel = link.attribs?.rel || '';
1002
+ const href = link.attribs?.href || '';
1003
+ if (!/\bstylesheet\b/i.test(rel) || !href || /^(https?:)?\/\//i.test(href)) continue;
1004
+ // Cache-busting (styles.css?v=3) and root-relative (/static/app.css) hrefs
1005
+ // must not resolve as OS-absolute paths; otherwise the whole stylesheet is
1006
+ // invisible to every element-level check.
1007
+ const cssPath = resolveLinkedCssPath(fileDir, href);
1008
+ try {
1009
+ const css = profileStep(profile, {
1010
+ engine: 'static-html',
1011
+ phase: 'preprocess',
1012
+ ruleId: 'inline-linked-stylesheet',
1013
+ target: filePath,
1014
+ detail: href,
1015
+ }, () => fs.readFileSync(cssPath, 'utf-8'));
1016
+ styleTexts.push(css);
1017
+ } catch {
1018
+ if (!warnedMissingStylesheets.has(cssPath)) {
1019
+ warnedMissingStylesheets.add(cssPath);
1020
+ process.stderr.write(
1021
+ `impeccable detect: could not read linked stylesheet ${href} (resolved to ${cssPath}); color and custom-property rules will be incomplete\n`
1022
+ );
1023
+ }
1024
+ }
1025
+ }
1026
+ return styleTexts.join('\n');
1027
+ }
1028
+
1029
+ function buildStaticStyleMap(root, staticDoc, cssText, modules, profile, filePath) {
1030
+ const specified = new Map();
1031
+ // Declarations from :hover rules, matched via their state-stripped
1032
+ // selectors. Merged per-property against the resting cascade in
1033
+ // computeNode — a hover declaration only takes effect if it would win
1034
+ // the cascade while the element is hovered (all resting rules still
1035
+ // apply in that state).
1036
+ const hoverSpecified = new Map();
1037
+ const rootCustomProps = collectCssCustomProps(cssText);
1038
+ const allNodes = modules.selectAll('*', root.children || []);
1039
+ const rules = profileStep(profile, {
1040
+ engine: 'static-html',
1041
+ phase: 'parse-css',
1042
+ ruleId: 'css-rules',
1043
+ target: filePath,
1044
+ }, () => collectStaticCssRules(cssText, modules.csstree));
1045
+
1046
+ profileStep(profile, {
1047
+ engine: 'static-html',
1048
+ phase: 'selector-match',
1049
+ ruleId: 'css-selectors',
1050
+ target: filePath,
1051
+ }, () => {
1052
+ for (const rule of rules) {
1053
+ // ::before/::after rules can't join the element cascade (pseudo
1054
+ // elements aren't DOM nodes), but one shape matters to the eyebrow
1055
+ // check: the short chromatic "kicker dash" (content box 8-80px wide,
1056
+ // 1-6px tall, accent-colored fill). Mark the base-selector matches
1057
+ // so checkElementHeroEyebrow can see the dash.
1058
+ if (!rule.isHover) {
1059
+ const pm = rule.selector.match(/^(.+?)\s*::?(?:before|after)$/i);
1060
+ if (pm) {
1061
+ const decls = new Map();
1062
+ for (const d of rule.declarations) decls.set(d.prop.toLowerCase(), d.value);
1063
+ const w = cssLengthToPx(resolveVarRefs(decls.get('width') || decls.get('inline-size') || '', rootCustomProps));
1064
+ const h = cssLengthToPx(resolveVarRefs(decls.get('height') || decls.get('block-size') || '', rootCustomProps));
1065
+ if (w != null && h != null && w >= 8 && w <= 80 && h >= 1 && h <= 6) {
1066
+ const bgRaw = String(resolveVarRefs(decls.get('background-color') || decls.get('background') || '', rootCustomProps));
1067
+ const token = bgRaw.match(/(?:rgba?|hsla?|oklch|oklab|lab|lch|hwb|color-mix)\([^)]*(?:\([^)]*\))?[^)]*\)|#[0-9a-f]{3,8}\b/i);
1068
+ const c = parseAnyColor(token ? token[0] : bgRaw);
1069
+ if (c && (c.a ?? 1) >= 0.1 && Math.max(c.r, c.g, c.b) - Math.min(c.r, c.g, c.b) >= 30) {
1070
+ try {
1071
+ for (const node of modules.selectAll(pm[1], root.children || [])) {
1072
+ staticDoc.setAccentDashPseudo(node);
1073
+ }
1074
+ } catch { /* unsupported base selector */ }
1075
+ }
1076
+ }
1077
+ // Full-cover surface pseudo: the CTA construction where the
1078
+ // element itself stays transparent and a ::before/::after with
1079
+ // position absolute/fixed + inset 0 (or all four sides 0, or
1080
+ // 100% width and height) plus an opaque background paints the
1081
+ // visible surface. Mark base-selector matches so the contrast
1082
+ // checks measure text against the surface the browser renders.
1083
+ const pseudoPos = String(decls.get('position') || '').toLowerCase();
1084
+ if (pseudoPos === 'absolute' || pseudoPos === 'fixed') {
1085
+ const zeroLen = v => v != null && /^0(?:px)?$/.test(String(v).trim());
1086
+ const insetRaw = String(decls.get('inset') || '').trim();
1087
+ const coversBox = (insetRaw !== '' && insetRaw.split(/\s+/).every(t => /^0(?:px)?$/.test(t)))
1088
+ || ['top', 'right', 'bottom', 'left'].every(side => zeroLen(decls.get(side)))
1089
+ || (String(decls.get('width') || '').trim() === '100%'
1090
+ && String(decls.get('height') || '').trim() === '100%');
1091
+ if (coversBox && decls.has('content')) {
1092
+ const surfRaw = String(resolveVarRefs(decls.get('background-color') || decls.get('background') || '', rootCustomProps));
1093
+ const surfToken = surfRaw.match(/(?:rgba?|hsla?|oklch|oklab|lab|lch|hwb|color-mix)\([^)]*(?:\([^)]*\))?[^)]*\)|#[0-9a-f]{3,8}\b/i);
1094
+ const surf = parseAnyColor(surfToken ? surfToken[0] : surfRaw);
1095
+ if (surf && (surf.a ?? 1) >= 0.9 && !/gradient/i.test(surfRaw)) {
1096
+ try {
1097
+ for (const node of modules.selectAll(pm[1], root.children || [])) {
1098
+ staticDoc.setPseudoSurface(node, surf);
1099
+ }
1100
+ } catch { /* unsupported base selector */ }
1101
+ }
1102
+ }
1103
+ }
1104
+ continue;
1105
+ }
1106
+ }
1107
+ const matchSelector = rule.isHover ? rule.matchSelector : rule.selector;
1108
+ if (!matchSelector) continue;
1109
+ let matched;
1110
+ try {
1111
+ matched = modules.selectAll(matchSelector, root.children || []);
1112
+ } catch {
1113
+ recordProfileEvent(profile, {
1114
+ engine: 'static-html',
1115
+ phase: 'selector-match',
1116
+ ruleId: 'unsupported-selector',
1117
+ target: filePath,
1118
+ ms: 0,
1119
+ findings: 0,
1120
+ detail: matchSelector,
1121
+ });
1122
+ continue;
1123
+ }
1124
+ for (const node of matched) {
1125
+ for (const decl of rule.declarations) {
1126
+ applyStaticDeclaration(rule.isHover ? hoverSpecified : specified, node, decl.prop, decl.value, {
1127
+ important: decl.important,
1128
+ specificity: rule.specificity,
1129
+ order: rule.order,
1130
+ inline: false,
1131
+ });
1132
+ }
1133
+ }
1134
+ }
1135
+
1136
+ let inlineOrder = rules.length + 1;
1137
+ for (const node of allNodes) {
1138
+ const styleText = node.attribs?.style;
1139
+ if (!styleText) continue;
1140
+ for (const decl of parseStaticStyleAttribute(styleText, inlineOrder)) {
1141
+ applyStaticDeclaration(specified, node, decl.prop, decl.value, {
1142
+ important: decl.important,
1143
+ specificity: [1, 0, 0],
1144
+ order: decl.order,
1145
+ inline: true,
1146
+ });
1147
+ }
1148
+ inlineOrder += 1000;
1149
+ }
1150
+ });
1151
+
1152
+ const computeNode = (node, parentStyle = null, parentCustom = new Map()) => {
1153
+ const specifiedMap = specified.get(node) || new Map();
1154
+ const customProps = new Map(parentCustom);
1155
+ for (const [prop, decl] of specifiedMap) {
1156
+ if (prop.startsWith('--')) customProps.set(prop, resolveVarRefs(decl.value, customProps));
1157
+ }
1158
+ const values = {};
1159
+ for (const prop of Object.keys(STATIC_DEFAULT_STYLE)) {
1160
+ if (STATIC_INHERITED_PROPS.has(prop) && parentStyle?.[prop] != null) values[prop] = parentStyle[prop];
1161
+ else values[prop] = STATIC_DEFAULT_STYLE[prop];
1162
+ }
1163
+ for (const [prop, decl] of specifiedMap) {
1164
+ if (prop.startsWith('--')) continue;
1165
+ values[prop] = normalizeStaticCssValue(prop, decl.value, customProps, parentStyle, values);
1166
+ }
1167
+ const style = makeStaticStyle(values);
1168
+ staticDoc.setStyle(node, style);
1169
+
1170
+ // Hover pass: limited to the two properties the hover-contrast check
1171
+ // consumes. A hover declaration wins only if it beats the resting
1172
+ // winner for that property under normal cascade rules (specificity /
1173
+ // order / importance) — exactly what a browser computes while the
1174
+ // element is hovered.
1175
+ const hoverMap = hoverSpecified.get(node);
1176
+ if (hoverMap) {
1177
+ let hoverValues = null;
1178
+ for (const prop of ['color', 'backgroundColor']) {
1179
+ const hoverDecl = hoverMap.get(prop);
1180
+ if (!hoverDecl) continue;
1181
+ const restingDecl = specifiedMap.get(prop);
1182
+ if (!compareStaticPriority(restingDecl, hoverDecl)) continue;
1183
+ const next = normalizeStaticCssValue(prop, hoverDecl.value, customProps, parentStyle, values);
1184
+ if (next === values[prop]) continue;
1185
+ if (!hoverValues) hoverValues = { ...values };
1186
+ hoverValues[prop] = next;
1187
+ }
1188
+ if (hoverValues) staticDoc.setHoverStyle(node, makeStaticStyle(hoverValues));
1189
+ }
1190
+
1191
+ for (const child of node.children || []) {
1192
+ if (child.type === 'tag') computeNode(child, style, customProps);
1193
+ }
1194
+ };
1195
+
1196
+ profileStep(profile, {
1197
+ engine: 'static-html',
1198
+ phase: 'cascade',
1199
+ ruleId: 'compute-styles',
1200
+ target: filePath,
1201
+ }, () => {
1202
+ for (const child of root.children || []) {
1203
+ if (child.type === 'tag') computeNode(child);
1204
+ }
1205
+ });
1206
+ }
1207
+
1208
+ export {
1209
+ BORDER_SHORTHAND_RE,
1210
+ NAMED_COLORS,
1211
+ normalizeColorForCheck,
1212
+ buildBorderOverrideMap,
1213
+ unwrapCssAtLayer,
1214
+ STATIC_INHERITED_PROPS,
1215
+ STATIC_DEFAULT_STYLE,
1216
+ STATIC_PROP_MAP,
1217
+ STATIC_NAMED_COLORS,
1218
+ splitCssList,
1219
+ splitCssTokens,
1220
+ cssPropToCamel,
1221
+ staticColorToCss,
1222
+ parseStaticColor,
1223
+ extractStaticColor,
1224
+ normalizeStaticCssValue,
1225
+ expandStaticBoxValues,
1226
+ parseStaticBorder,
1227
+ parseStaticFont,
1228
+ parseStaticTransition,
1229
+ parseStaticAnimation,
1230
+ expandStaticDeclaration,
1231
+ compareStaticPriority,
1232
+ staticSpecificity,
1233
+ applyStaticDeclaration,
1234
+ parseStaticStyleAttribute,
1235
+ collectStaticCssRules,
1236
+ StaticElement,
1237
+ StaticDocument,
1238
+ makeStaticStyle,
1239
+ buildStaticWindow,
1240
+ collectStaticCssText,
1241
+ buildStaticStyleMap,
1242
+ };