@bastani/atomic 0.9.20-alpha.4 → 0.9.20-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/package.json +1 -1
  4. package/dist/builtin/intercom/skills/intercom/SKILL.md +32 -1
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/CHANGELOG.md +12 -0
  7. package/dist/builtin/subagents/README.md +2 -0
  8. package/dist/builtin/subagents/agents/code-simplifier.md +1 -1
  9. package/dist/builtin/subagents/agents/codebase-analyzer.md +1 -1
  10. package/dist/builtin/subagents/agents/codebase-online-researcher.md +3 -3
  11. package/dist/builtin/subagents/agents/debugger.md +7 -5
  12. package/dist/builtin/subagents/agents/worker.md +4 -2
  13. package/dist/builtin/subagents/package.json +1 -1
  14. package/dist/builtin/subagents/skills/agent-browser/SKILL.md +56 -0
  15. package/dist/builtin/subagents/skills/subagent/SKILL.md +32 -8
  16. package/dist/builtin/subagents/src/extension/index.bundle.mjs +7 -4
  17. package/dist/builtin/web-access/package.json +1 -1
  18. package/dist/builtin/workflows/CHANGELOG.md +30 -0
  19. package/dist/builtin/workflows/README.md +4 -2
  20. package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
  21. package/dist/builtin/workflows/builtin/{chunk-n8g2da69.js → chunk-00ywx588.js} +1 -1
  22. package/dist/builtin/workflows/builtin/{chunk-d1xqh1rd.js → chunk-55p5dxjk.js} +1 -1
  23. package/dist/builtin/workflows/builtin/{chunk-1dydq7w3.js → chunk-7f381xnq.js} +62 -24
  24. package/dist/builtin/workflows/builtin/{chunk-k18g9me8.js → chunk-7h7s5xdj.js} +1 -1
  25. package/dist/builtin/workflows/builtin/{chunk-n4yxrsm9.js → chunk-e83tc6nr.js} +1 -1
  26. package/dist/builtin/workflows/builtin/{chunk-sn5mchnx.js → chunk-evfb0312.js} +1 -1
  27. package/dist/builtin/workflows/builtin/{chunk-scgprmdj.js → chunk-ne6vh5ct.js} +1 -1
  28. package/dist/builtin/workflows/builtin/{chunk-119kxb28.js → chunk-pfm1kgqz.js} +62 -43
  29. package/dist/builtin/workflows/builtin/{chunk-hnbbb5r0.js → chunk-tdqvdrg1.js} +4 -4
  30. package/dist/builtin/workflows/builtin/{chunk-kf5xpbkz.js → chunk-tvcydq13.js} +1 -1
  31. package/dist/builtin/workflows/builtin/{chunk-9y0f90rd.js → chunk-x2nftpgj.js} +1 -1
  32. package/dist/builtin/workflows/builtin/{chunk-vt9zgr9d.js → chunk-zj5162bh.js} +4 -4
  33. package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
  34. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
  35. package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
  36. package/dist/builtin/workflows/builtin/goal.js +4 -4
  37. package/dist/builtin/workflows/builtin/index.d.ts +1 -1
  38. package/dist/builtin/workflows/builtin/index.js +12 -12
  39. package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
  40. package/dist/builtin/workflows/builtin/open-claude-design.d.ts +1 -1
  41. package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
  42. package/dist/builtin/workflows/builtin/ralph.js +4 -4
  43. package/dist/builtin/workflows/builtin/steering-context.js +1 -1
  44. package/dist/builtin/workflows/builtin/tournament.js +3 -3
  45. package/dist/builtin/workflows/package.json +1 -1
  46. package/dist/builtin/workflows/skills/impeccable/SKILL.md +18 -11
  47. package/dist/builtin/workflows/skills/impeccable/reference/adapt.md +1 -1
  48. package/dist/builtin/workflows/skills/impeccable/reference/adapt.native.md +1 -1
  49. package/dist/builtin/workflows/skills/impeccable/reference/animate.md +1 -1
  50. package/dist/builtin/workflows/skills/impeccable/reference/audit.md +5 -5
  51. package/dist/builtin/workflows/skills/impeccable/reference/audit.native.md +6 -6
  52. package/dist/builtin/workflows/skills/impeccable/reference/bolder.md +2 -2
  53. package/dist/builtin/workflows/skills/impeccable/reference/clarify.md +1 -1
  54. package/dist/builtin/workflows/skills/impeccable/reference/colorize.md +1 -1
  55. package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +0 -6
  56. package/dist/builtin/workflows/skills/impeccable/reference/critique.md +19 -41
  57. package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +11 -65
  58. package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +3 -3
  59. package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +4 -4
  60. package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +1 -1
  61. package/dist/builtin/workflows/skills/impeccable/reference/delight.md +1 -1
  62. package/dist/builtin/workflows/skills/impeccable/reference/distill.md +2 -2
  63. package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +4 -4
  64. package/dist/builtin/workflows/skills/impeccable/reference/document.md +4 -4
  65. package/dist/builtin/workflows/skills/impeccable/reference/extract.md +1 -1
  66. package/dist/builtin/workflows/skills/impeccable/reference/harden.md +1 -1
  67. package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +21 -21
  68. package/dist/builtin/workflows/skills/impeccable/reference/init.md +8 -8
  69. package/dist/builtin/workflows/skills/impeccable/reference/layout.md +2 -2
  70. package/dist/builtin/workflows/skills/impeccable/reference/live-setup.md +10 -8
  71. package/dist/builtin/workflows/skills/impeccable/reference/live.md +39 -38
  72. package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +48 -21
  73. package/dist/builtin/workflows/skills/impeccable/reference/onboard.md +1 -1
  74. package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +1 -1
  75. package/dist/builtin/workflows/skills/impeccable/reference/overdrive.md +1 -1
  76. package/dist/builtin/workflows/skills/impeccable/reference/polish.md +11 -3
  77. package/dist/builtin/workflows/skills/impeccable/reference/quieter.md +2 -2
  78. package/dist/builtin/workflows/skills/impeccable/reference/routing.md +13 -7
  79. package/dist/builtin/workflows/skills/impeccable/reference/typeset.md +2 -2
  80. package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +13 -19
  81. package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -0
  82. package/dist/builtin/workflows/skills/impeccable/scripts/data/font-index-failures.json +121 -0
  83. package/dist/builtin/workflows/skills/impeccable/scripts/data/font-index.json +1 -0
  84. package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +212 -0
  85. package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +218 -0
  86. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-dom.js +21 -0
  87. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +242 -0
  88. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +25 -4
  89. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +666 -197
  90. package/dist/builtin/workflows/skills/research-codebase/SKILL.md +1 -1
  91. package/dist/builtin/workflows/src/extension/index.bundle.mjs +156 -84
  92. package/dist/builtin/workflows/src/index.js +62 -24
  93. package/dist/core/execution-model-router.d.ts +2 -0
  94. package/dist/core/execution-model-router.d.ts.map +1 -1
  95. package/dist/core/execution-model-router.js +30 -4
  96. package/dist/core/execution-model-router.js.map +1 -1
  97. package/dist/core/model-routing-task.d.ts +1 -1
  98. package/dist/core/model-routing-task.d.ts.map +1 -1
  99. package/dist/core/model-routing-task.js +4 -3
  100. package/dist/core/model-routing-task.js.map +1 -1
  101. package/dist/core/system-prompt.d.ts.map +1 -1
  102. package/dist/core/system-prompt.js +2 -1
  103. package/dist/core/system-prompt.js.map +1 -1
  104. package/dist/index.d.ts +1 -1
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.js +1 -1
  107. package/dist/index.js.map +1 -1
  108. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  109. package/dist/modes/interactive/components/chat-message-renderer.js +4 -0
  110. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  111. package/docs/computer-use.md +22 -21
  112. package/docs/getting-started/first-session.md +2 -2
  113. package/docs/getting-started/installation.md +6 -2
  114. package/docs/intercom.md +6 -1
  115. package/docs/models/model-selection.md +11 -7
  116. package/docs/quickstart.md +1 -1
  117. package/docs/skills.md +1 -1
  118. package/docs/subagents/reference.md +2 -2
  119. package/docs/subagents.md +7 -1
  120. package/docs/usage.md +2 -0
  121. package/docs/windows.md +1 -1
  122. package/docs/workflows/api-reference.md +3 -4
  123. package/docs/workflows/builtins.md +2 -2
  124. package/docs/workflows/operations.md +1 -1
  125. package/docs/workflows/reliable-design.md +12 -1
  126. package/docs/workflows/verification.md +8 -8
  127. package/npm-shrinkwrap.json +32 -32
  128. package/package.json +3 -3
  129. package/dist/builtin/subagents/skills/playwright-cli/SKILL.md +0 -420
  130. package/dist/builtin/subagents/skills/playwright-cli/references/element-attributes.md +0 -23
  131. package/dist/builtin/subagents/skills/playwright-cli/references/playwright-tests.md +0 -39
  132. package/dist/builtin/subagents/skills/playwright-cli/references/request-mocking.md +0 -87
  133. package/dist/builtin/subagents/skills/playwright-cli/references/running-code.md +0 -241
  134. package/dist/builtin/subagents/skills/playwright-cli/references/session-management.md +0 -225
  135. package/dist/builtin/subagents/skills/playwright-cli/references/storage-state.md +0 -275
  136. package/dist/builtin/subagents/skills/playwright-cli/references/test-generation.md +0 -433
  137. package/dist/builtin/subagents/skills/playwright-cli/references/tracing.md +0 -139
  138. package/dist/builtin/subagents/skills/playwright-cli/references/video-recording.md +0 -143
  139. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_asset_producer.toml +0 -94
  140. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_documenter.toml +0 -27
  141. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_finish_reviewer.toml +0 -41
  142. package/dist/builtin/workflows/skills/impeccable/agents/impeccable_manual_edit_applier.toml +0 -95
  143. package/dist/builtin/workflows/skills/impeccable/agents/openai.yaml +0 -4
  144. package/dist/builtin/workflows/skills/impeccable/scripts/concept-seed.mjs +0 -695
  145. package/dist/builtin/workflows/skills/impeccable/scripts/context-signals.mjs +0 -325
  146. package/dist/builtin/workflows/skills/impeccable/scripts/context.mjs +0 -1503
  147. package/dist/builtin/workflows/skills/impeccable/scripts/critique-storage.mjs +0 -222
  148. package/dist/builtin/workflows/skills/impeccable/scripts/detect-csp.mjs +0 -198
  149. package/dist/builtin/workflows/skills/impeccable/scripts/detect.mjs +0 -21
  150. package/dist/builtin/workflows/skills/impeccable/scripts/detector/browser/injected/index.mjs +0 -2073
  151. package/dist/builtin/workflows/skills/impeccable/scripts/detector/cli/main.mjs +0 -432
  152. package/dist/builtin/workflows/skills/impeccable/scripts/detector/design-system.mjs +0 -1121
  153. package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +0 -8746
  154. package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns.mjs +0 -51
  155. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +0 -376
  156. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +0 -1168
  157. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +0 -1192
  158. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +0 -290
  159. package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -189
  160. package/dist/builtin/workflows/skills/impeccable/scripts/detector/findings.mjs +0 -18
  161. package/dist/builtin/workflows/skills/impeccable/scripts/detector/node/file-system.mjs +0 -213
  162. package/dist/builtin/workflows/skills/impeccable/scripts/detector/profile/profiler.mjs +0 -166
  163. package/dist/builtin/workflows/skills/impeccable/scripts/detector/registry/antipatterns.mjs +0 -617
  164. package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +0 -5534
  165. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/color.mjs +0 -588
  166. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/constants.mjs +0 -112
  167. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/fonts.mjs +0 -30
  168. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/inline-ignores.mjs +0 -148
  169. package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/page.mjs +0 -35
  170. package/dist/builtin/workflows/skills/impeccable/scripts/doctor.mjs +0 -338
  171. package/dist/builtin/workflows/skills/impeccable/scripts/embed-prompt.mjs +0 -270
  172. package/dist/builtin/workflows/skills/impeccable/scripts/generate-image.mjs +0 -277
  173. package/dist/builtin/workflows/skills/impeccable/scripts/hook-admin.mjs +0 -783
  174. package/dist/builtin/workflows/skills/impeccable/scripts/hook-lib.mjs +0 -2305
  175. package/dist/builtin/workflows/skills/impeccable/scripts/hook.mjs +0 -78
  176. package/dist/builtin/workflows/skills/impeccable/scripts/lib/artifact-schema.mjs +0 -93
  177. package/dist/builtin/workflows/skills/impeccable/scripts/lib/composition-catalog.mjs +0 -200
  178. package/dist/builtin/workflows/skills/impeccable/scripts/lib/concept-catalog.mjs +0 -395
  179. package/dist/builtin/workflows/skills/impeccable/scripts/lib/design-parser.mjs +0 -925
  180. package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-config.mjs +0 -640
  181. package/dist/builtin/workflows/skills/impeccable/scripts/lib/impeccable-paths.mjs +0 -137
  182. package/dist/builtin/workflows/skills/impeccable/scripts/lib/is-generated.mjs +0 -72
  183. package/dist/builtin/workflows/skills/impeccable/scripts/lib/open-system-browser.mjs +0 -57
  184. package/dist/builtin/workflows/skills/impeccable/scripts/lib/provider.mjs +0 -5
  185. package/dist/builtin/workflows/skills/impeccable/scripts/lib/roll-selection.mjs +0 -369
  186. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-deep.mjs +0 -483
  187. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness-notice.mjs +0 -169
  188. package/dist/builtin/workflows/skills/impeccable/scripts/lib/staleness.mjs +0 -528
  189. package/dist/builtin/workflows/skills/impeccable/scripts/lib/surface-briefs.mjs +0 -151
  190. package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-args.mjs +0 -42
  191. package/dist/builtin/workflows/skills/impeccable/scripts/lib/target-slug.mjs +0 -33
  192. package/dist/builtin/workflows/skills/impeccable/scripts/lib/template-extensions.mjs +0 -146
  193. package/dist/builtin/workflows/skills/impeccable/scripts/live/accept-css.mjs +0 -617
  194. package/dist/builtin/workflows/skills/impeccable/scripts/live/accept-verify.mjs +0 -71
  195. package/dist/builtin/workflows/skills/impeccable/scripts/live/browser-script-parts.mjs +0 -77
  196. package/dist/builtin/workflows/skills/impeccable/scripts/live/completion.mjs +0 -28
  197. package/dist/builtin/workflows/skills/impeccable/scripts/live/event-validation.mjs +0 -199
  198. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/astro.mjs +0 -47
  199. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/detect-utils.mjs +0 -157
  200. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/index.mjs +0 -143
  201. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/journal.mjs +0 -205
  202. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/nextjs.mjs +0 -49
  203. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/nuxt.mjs +0 -170
  204. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/script-src.mjs +0 -26
  205. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/static-html.mjs +0 -26
  206. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/sveltekit.mjs +0 -71
  207. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/tag-strategy.mjs +0 -247
  208. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/tanstack-start.mjs +0 -70
  209. package/dist/builtin/workflows/skills/impeccable/scripts/live/frameworks/vite-generic.mjs +0 -42
  210. package/dist/builtin/workflows/skills/impeccable/scripts/live/generation-preflight.mjs +0 -149
  211. package/dist/builtin/workflows/skills/impeccable/scripts/live/insert-ui.mjs +0 -458
  212. package/dist/builtin/workflows/skills/impeccable/scripts/live/instructions.mjs +0 -169
  213. package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-apply.mjs +0 -939
  214. package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edit-routes.mjs +0 -357
  215. package/dist/builtin/workflows/skills/impeccable/scripts/live/manual-edits-buffer.mjs +0 -152
  216. package/dist/builtin/workflows/skills/impeccable/scripts/live/poll-lanes.mjs +0 -14
  217. package/dist/builtin/workflows/skills/impeccable/scripts/live/roots.mjs +0 -670
  218. package/dist/builtin/workflows/skills/impeccable/scripts/live/session-store.mjs +0 -563
  219. package/dist/builtin/workflows/skills/impeccable/scripts/live/source-lock.mjs +0 -105
  220. package/dist/builtin/workflows/skills/impeccable/scripts/live/source-search.mjs +0 -105
  221. package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-ast.mjs +0 -969
  222. package/dist/builtin/workflows/skills/impeccable/scripts/live/svelte-component.mjs +0 -1401
  223. package/dist/builtin/workflows/skills/impeccable/scripts/live/sveltekit-adapter.mjs +0 -314
  224. package/dist/builtin/workflows/skills/impeccable/scripts/live/tanstack-adapter.mjs +0 -280
  225. package/dist/builtin/workflows/skills/impeccable/scripts/live/ui-surfaces.mjs +0 -75
  226. package/dist/builtin/workflows/skills/impeccable/scripts/live/vocabulary.mjs +0 -171
  227. package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +0 -961
  228. package/dist/builtin/workflows/skills/impeccable/scripts/live-commit-manual-edits.mjs +0 -1244
  229. package/dist/builtin/workflows/skills/impeccable/scripts/live-complete.mjs +0 -107
  230. package/dist/builtin/workflows/skills/impeccable/scripts/live-copy-edit-agent.mjs +0 -800
  231. package/dist/builtin/workflows/skills/impeccable/scripts/live-discard-manual-edits.mjs +0 -51
  232. package/dist/builtin/workflows/skills/impeccable/scripts/live-inject.mjs +0 -515
  233. package/dist/builtin/workflows/skills/impeccable/scripts/live-insert.mjs +0 -292
  234. package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +0 -371
  235. package/dist/builtin/workflows/skills/impeccable/scripts/live-poll.mjs +0 -427
  236. package/dist/builtin/workflows/skills/impeccable/scripts/live-resume.mjs +0 -123
  237. package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +0 -1675
  238. package/dist/builtin/workflows/skills/impeccable/scripts/live-status.mjs +0 -71
  239. package/dist/builtin/workflows/skills/impeccable/scripts/live-target.mjs +0 -30
  240. package/dist/builtin/workflows/skills/impeccable/scripts/live-wrap.mjs +0 -927
  241. package/dist/builtin/workflows/skills/impeccable/scripts/live.mjs +0 -365
  242. package/dist/builtin/workflows/skills/impeccable/scripts/palette.mjs +0 -628
  243. package/dist/builtin/workflows/skills/impeccable/scripts/pin.mjs +0 -224
  244. package/dist/builtin/workflows/skills/impeccable/scripts/serve-question.mjs +0 -1540
  245. package/dist/builtin/workflows/skills/impeccable/scripts/surface-brief.mjs +0 -74
@@ -1,640 +0,0 @@
1
- /**
2
- * CLI-side reader/writer for the unified `.impeccable` config.
3
- *
4
- * The CLI (published to npm) and the skill scripts (bundled into the install)
5
- * live in separate trees and cannot share runtime code, so this duplicates a
6
- * small slice of skill/scripts/hook-lib.mjs — the config-path layout, detector
7
- * ignore semantics, and the `.git/info/exclude` handling. Keep the schema,
8
- * ignore filtering, and exclude marker in sync if either side changes.
9
- *
10
- * Schema (config.json shared / config.local.json gitignored, per-developer):
11
- * {
12
- * "detector": { "ignoreRules": [], "ignoreFiles": [], "ignoreValues": [], "designSystem": { "enabled": true } },
13
- * "hook": { "consent": "accepted" | "declined", ... },
14
- * "updateCheck": bool
15
- * }
16
- */
17
-
18
- import { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
19
- import { join, dirname, isAbsolute, relative, resolve, sep } from 'node:path';
20
-
21
- export function getConfigPath(root) {
22
- return join(root, '.impeccable', 'config.json');
23
- }
24
-
25
- export function getLocalConfigPath(root) {
26
- return join(root, '.impeccable', 'config.local.json');
27
- }
28
-
29
- function safeReadJson(filePath) {
30
- try {
31
- const raw = JSON.parse(readFileSync(filePath, 'utf-8'));
32
- return raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : null;
33
- } catch {
34
- return null;
35
- }
36
- }
37
-
38
- function hookSection(raw) {
39
- return raw && raw.hook && typeof raw.hook === 'object' && !Array.isArray(raw.hook) ? raw.hook : null;
40
- }
41
-
42
- function detectorSection(raw) {
43
- return raw && raw.detector && typeof raw.detector === 'object' && !Array.isArray(raw.detector) ? raw.detector : null;
44
- }
45
-
46
- const DETECTOR_CONFIG_KEYS = new Set(['ignoreRules', 'ignoreFiles', 'ignoreValues', 'designSystem', 'advisoryRules']);
47
-
48
- const DEFAULT_DETECTION_CONFIG = Object.freeze({
49
- ignoreRules: [],
50
- ignoreFiles: [],
51
- ignoreValues: [],
52
- designSystem: { enabled: true },
53
- });
54
-
55
- function cloneDetectionConfig() {
56
- return {
57
- ignoreRules: [],
58
- ignoreFiles: [],
59
- ignoreValues: [],
60
- designSystem: { ...DEFAULT_DETECTION_CONFIG.designSystem },
61
- };
62
- }
63
-
64
- function cloneRawDetectionConfig() {
65
- return {
66
- ignoreRules: [],
67
- ignoreFiles: [],
68
- ignoreValues: [],
69
- };
70
- }
71
-
72
- function applyDetectionConfigSource(config, raw) {
73
- if (!raw || typeof raw !== 'object') return config;
74
- // Advisory rules are opt-in for the design hook; the CLI carries the setting
75
- // so config round-trips (e.g. `impeccable hooks ignore-value`) preserve it.
76
- if (raw.advisoryRules === 'include' || raw.advisoryRules === 'exclude') {
77
- config.advisoryRules = raw.advisoryRules;
78
- }
79
- if (raw.designSystem && typeof raw.designSystem === 'object' && !Array.isArray(raw.designSystem)) {
80
- config.designSystem = {
81
- ...config.designSystem,
82
- enabled: raw.designSystem.enabled === false ? false : true,
83
- };
84
- }
85
- if (Array.isArray(raw.ignoreRules)) {
86
- config.ignoreRules = uniqueStrings([...config.ignoreRules, ...raw.ignoreRules]);
87
- }
88
- if (Array.isArray(raw.ignoreFiles)) {
89
- config.ignoreFiles = uniqueStrings([...config.ignoreFiles, ...raw.ignoreFiles]);
90
- }
91
- if (Array.isArray(raw.ignoreValues)) {
92
- config.ignoreValues = mergeIgnoreValues(config.ignoreValues, raw.ignoreValues);
93
- }
94
- return config;
95
- }
96
-
97
- function uniqueStrings(values) {
98
- return Array.from(new Set(values.map(String)));
99
- }
100
-
101
- /**
102
- * Detector filters shared by `npx impeccable detect` and the design hook.
103
- * `hook.enabled` remains hook lifecycle state; manual CLI scans still run when
104
- * the hook is disabled, but they honor the same ignore rules and design-system
105
- * toggle.
106
- */
107
- export function readDetectionConfig(root) {
108
- const config = cloneDetectionConfig();
109
- for (const filePath of [getConfigPath(root), getLocalConfigPath(root)]) {
110
- const raw = safeReadJson(filePath);
111
- // Back-compat: old builds stored detector filters under hook.*.
112
- applyDetectionConfigSource(config, hookSection(raw));
113
- applyDetectionConfigSource(config, detectorSection(raw));
114
- }
115
- return config;
116
- }
117
-
118
- export function readRawDetectionConfig(root, opts = {}) {
119
- const raw = safeReadJson(opts.local ? getLocalConfigPath(root) : getConfigPath(root));
120
- const config = cloneRawDetectionConfig();
121
- applyDetectionConfigSource(config, hookSection(raw));
122
- applyDetectionConfigSource(config, detectorSection(raw));
123
- return config;
124
- }
125
-
126
- export function writeDetectionConfig(root, detectorConfig, opts = {}) {
127
- const filePath = opts.local ? getLocalConfigPath(root) : getConfigPath(root);
128
- if (opts.local) ensureConfigGitExclude(root);
129
- const existing = safeReadJson(filePath) || {};
130
- const existingHook = hookSection(existing);
131
- const nextHook = stripDetectorKeys(existingHook);
132
- const nextDetector = {
133
- ...(detectorSection(existing) || {}),
134
- ...normalizeDetectionConfigForWrite(detectorConfig),
135
- };
136
- const next = {
137
- ...existing,
138
- detector: nextDetector,
139
- };
140
- if (nextHook && Object.keys(nextHook).length > 0) {
141
- next.hook = nextHook;
142
- } else {
143
- delete next.hook;
144
- }
145
- mkdirSync(dirname(filePath), { recursive: true });
146
- writeFileSync(filePath, `${JSON.stringify(next, null, 2)}\n`);
147
- return filePath;
148
- }
149
-
150
- function normalizeDetectionConfigForWrite(config) {
151
- const out = {};
152
- if (Array.isArray(config?.ignoreRules)) {
153
- out.ignoreRules = uniqueStrings(config.ignoreRules.map((rule) => normalizeIgnoreRule(rule)).filter(Boolean));
154
- }
155
- if (Array.isArray(config?.ignoreFiles)) {
156
- out.ignoreFiles = uniqueStrings(config.ignoreFiles.filter(v => typeof v === 'string' && v.trim()).map(v => v.trim()));
157
- }
158
- out.ignoreValues = normalizeIgnoreValueEntries(config?.ignoreValues || []);
159
- if (config?.advisoryRules === 'include' || config?.advisoryRules === 'exclude') {
160
- out.advisoryRules = config.advisoryRules;
161
- }
162
- if (config?.designSystem && typeof config.designSystem === 'object' && !Array.isArray(config.designSystem)) {
163
- out.designSystem = {
164
- enabled: config.designSystem.enabled === false ? false : true,
165
- };
166
- }
167
- return out;
168
- }
169
-
170
- function stripDetectorKeys(raw) {
171
- if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
172
- const out = {};
173
- for (const [key, value] of Object.entries(raw)) {
174
- if (!DETECTOR_CONFIG_KEYS.has(key)) out[key] = value;
175
- }
176
- return out;
177
- }
178
-
179
- export function normalizeIgnoreValue(value) {
180
- return String(value || '')
181
- .trim()
182
- .replace(/^["']|["']$/g, '')
183
- .replace(/\+/g, ' ')
184
- .replace(/\s+/g, ' ')
185
- .toLowerCase();
186
- }
187
-
188
- function normalizeIgnoreRule(rule) {
189
- return String(rule || '').trim().toLowerCase();
190
- }
191
-
192
- function colorIgnoreKey(value) {
193
- const color = parseIgnoreColor(value);
194
- if (!color) return '';
195
- return `${color.r},${color.g},${color.b},${Math.round(color.a * 255)}`;
196
- }
197
-
198
- function parseIgnoreColor(value) {
199
- const text = String(value || '').trim().toLowerCase();
200
- if (!text) return null;
201
-
202
- const hex = text.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);
203
- if (hex) return parseHexIgnoreColor(hex[1]);
204
-
205
- const rgb = text.match(/^rgba?\((.*)\)$/i);
206
- if (rgb) {
207
- const parts = splitColorArgs(rgb[1]);
208
- if (parts.length < 3 || parts.length > 4) return null;
209
- const r = parseColorChannel(parts[0], COLOR_CHANNEL_FORMATS.rgb);
210
- const g = parseColorChannel(parts[1], COLOR_CHANNEL_FORMATS.rgb);
211
- const b = parseColorChannel(parts[2], COLOR_CHANNEL_FORMATS.rgb);
212
- const a = parts[3] === undefined ? 1 : parseColorChannel(parts[3], COLOR_CHANNEL_FORMATS.alpha);
213
- if ([r, g, b, a].some((v) => v === null)) return null;
214
- return { r, g, b, a };
215
- }
216
-
217
- const hsl = text.match(/^hsla?\((.*)\)$/i);
218
- if (hsl) {
219
- const parts = splitColorArgs(hsl[1]);
220
- if (parts.length < 3 || parts.length > 4) return null;
221
- const h = parseColorChannel(parts[0], COLOR_CHANNEL_FORMATS.hue);
222
- const s = parseColorChannel(parts[1], COLOR_CHANNEL_FORMATS.percent);
223
- const l = parseColorChannel(parts[2], COLOR_CHANNEL_FORMATS.percent);
224
- const a = parts[3] === undefined ? 1 : parseColorChannel(parts[3], COLOR_CHANNEL_FORMATS.alpha);
225
- if ([h, s, l, a].some((v) => v === null)) return null;
226
- return hslToRgb(h, s, l, a);
227
- }
228
-
229
- return null;
230
- }
231
-
232
- function parseHexIgnoreColor(hex) {
233
- const expanded = hex.length <= 4
234
- ? [...hex].map((digit) => digit.repeat(2)).join('')
235
- : hex;
236
- const [r, g, b, alpha = 255] = expanded
237
- .match(/../g)
238
- .map((channel) => Number.parseInt(channel, 16));
239
- return { r, g, b, a: alpha / 255 };
240
- }
241
-
242
- function splitColorArgs(body) {
243
- const text = String(body || '').trim();
244
- if (!text) return [];
245
- if (text.includes(',')) {
246
- const parts = text.split(',').map((part) => part.trim()).filter(Boolean);
247
- const last = parts[parts.length - 1];
248
- if (last && last.includes('/')) {
249
- const split = last.split('/').map((part) => part.trim()).filter(Boolean);
250
- return [...parts.slice(0, -1), ...split];
251
- }
252
- return parts;
253
- }
254
- return text.replace(/\s*\/\s*/g, ' / ').split(/\s+/).filter((part) => part && part !== '/');
255
- }
256
-
257
- const CSS_NUMBER_RE = /^(-?\d*\.?\d+)(%|deg|rad|turn|grad)?$/;
258
- const identity = (value) => value;
259
- const COLOR_CHANNEL_FORMATS = {
260
- rgb: { units: { '': identity, '%': (value) => value * 2.55 }, min: 0, max: 255, round: true },
261
- alpha: { units: { '': identity, '%': (value) => value / 100 }, min: 0, max: 1 },
262
- hue: {
263
- units: {
264
- '': identity,
265
- deg: identity,
266
- rad: (value) => value * (180 / Math.PI),
267
- turn: (value) => value * 360,
268
- grad: (value) => value * 0.9,
269
- },
270
- },
271
- percent: { units: { '%': (value) => value / 100 }, min: 0, max: 1 },
272
- };
273
-
274
- function parseColorChannel(raw, { units, min = -Infinity, max = Infinity, round = false }) {
275
- const text = String(raw || '').trim();
276
- const match = text.match(CSS_NUMBER_RE);
277
- if (!match) return null;
278
- const convert = units[match[2] || ''];
279
- if (!convert) return null;
280
- const number = Number.parseFloat(match[1]);
281
- if (!Number.isFinite(number)) return null;
282
- const value = convert(number);
283
- if (value < min || value > max) return null;
284
- return round ? Math.round(value) : value;
285
- }
286
-
287
- function hslToRgb(hue, saturation, lightness, alpha) {
288
- const h = (((hue % 360) + 360) % 360) / 360;
289
- if (saturation === 0) {
290
- const gray = clampByte(Math.round(lightness * 255));
291
- return { r: gray, g: gray, b: gray, a: alpha };
292
- }
293
- const q = lightness < 0.5
294
- ? lightness * (1 + saturation)
295
- : lightness + saturation - lightness * saturation;
296
- const p = 2 * lightness - q;
297
- const toRgb = (t) => {
298
- let channel = t;
299
- if (channel < 0) channel += 1;
300
- if (channel > 1) channel -= 1;
301
- if (channel < 1 / 6) return p + (q - p) * 6 * channel;
302
- if (channel < 1 / 2) return q;
303
- if (channel < 2 / 3) return p + (q - p) * (2 / 3 - channel) * 6;
304
- return p;
305
- };
306
- return {
307
- r: clampByte(Math.round(toRgb(h + 1 / 3) * 255)),
308
- g: clampByte(Math.round(toRgb(h) * 255)),
309
- b: clampByte(Math.round(toRgb(h - 1 / 3) * 255)),
310
- a: alpha,
311
- };
312
- }
313
-
314
- function clampByte(value) {
315
- return Math.min(255, Math.max(0, value));
316
- }
317
-
318
- function ignoreValueMatches(rule, entryValue, findingValue) {
319
- if (entryValue === findingValue) return true;
320
- if (rule !== 'design-system-color') return false;
321
- const entryColor = colorIgnoreKey(entryValue);
322
- return Boolean(entryColor && entryColor === colorIgnoreKey(findingValue));
323
- }
324
-
325
- export function normalizeIgnoreValueEntries(entries) {
326
- if (!Array.isArray(entries)) return [];
327
- const out = [];
328
- for (const entry of entries) {
329
- if (!entry || typeof entry !== 'object') continue;
330
- const rule = normalizeIgnoreRule(entry.rule);
331
- const value = normalizeIgnoreValue(entry.value);
332
- if (!rule || !value) continue;
333
- const normalized = { rule, value };
334
- const files = uniqueStrings([
335
- ...(typeof entry.file === 'string' && entry.file.trim() ? [entry.file.trim()] : []),
336
- ...(Array.isArray(entry.files) ? entry.files.filter(v => typeof v === 'string' && v.trim()).map(v => v.trim()) : []),
337
- ]);
338
- if (files.length > 0) normalized.files = files;
339
- // Key order is rule, value, files, createdAt, reason and must stay that way:
340
- // normalizing runs on every write, so emitting a different order than the one
341
- // already on disk rewrites every untouched entry and churns the diff. Keep in
342
- // step with normalizeIgnoreValueEntries in skill/scripts/hook-lib.mjs.
343
- if (typeof entry.createdAt === 'string' && entry.createdAt.trim()) {
344
- normalized.createdAt = entry.createdAt.trim();
345
- }
346
- if (typeof entry.reason === 'string' && entry.reason.trim()) {
347
- normalized.reason = entry.reason.trim();
348
- }
349
- out.push(normalized);
350
- }
351
- return out;
352
- }
353
-
354
- function mergeIgnoreValues(existing, incoming) {
355
- const map = new Map();
356
- for (const entry of normalizeIgnoreValueEntries(existing)) {
357
- map.set(`${entry.rule}\0${entry.value}\0${ignoreValueFilesKey(entry.files)}`, entry);
358
- }
359
- for (const entry of normalizeIgnoreValueEntries(incoming)) {
360
- map.set(`${entry.rule}\0${entry.value}\0${ignoreValueFilesKey(entry.files)}`, entry);
361
- }
362
- return Array.from(map.values());
363
- }
364
-
365
- function ignoreValueFilesKey(files) {
366
- // Sort before joining: a scope is a set, so an entry already on disk in another
367
- // order must compare equal rather than dedup as two distinct entries.
368
- return Array.isArray(files) && files.length > 0 ? [...files].sort().join('\x1f') : '';
369
- }
370
-
371
- // Glob -> RegExp. Supports `**`, `*`, `?`, and `{a,b}` alternation.
372
- function globToRegex(glob) {
373
- let re = '^';
374
- let i = 0;
375
- while (i < glob.length) {
376
- const c = glob[i];
377
- if (c === '*') {
378
- if (glob[i + 1] === '*') {
379
- re += '.*';
380
- i += 2;
381
- if (glob[i] === '/') i += 1;
382
- } else {
383
- re += '[^/]*';
384
- i += 1;
385
- }
386
- } else if (c === '?') {
387
- re += '[^/]';
388
- i += 1;
389
- } else if (c === '{') {
390
- const end = glob.indexOf('}', i);
391
- if (end === -1) { re += '\\{'; i += 1; continue; }
392
- const parts = glob.slice(i + 1, end).split(',').map((p) => p.replace(/[.+^$()|[\]\\]/g, '\\$&'));
393
- re += `(?:${parts.join('|')})`;
394
- i = end + 1;
395
- } else if (/[.+^$()|[\]\\]/.test(c)) {
396
- re += `\\${c}`;
397
- i += 1;
398
- } else {
399
- re += c;
400
- i += 1;
401
- }
402
- }
403
- re += '$';
404
- return new RegExp(re);
405
- }
406
-
407
- export function matchesAnyGlob(filePath, globs) {
408
- if (!Array.isArray(globs) || globs.length === 0) return false;
409
- const normalized = String(filePath || '').split(sep).join('/');
410
- for (const glob of globs) {
411
- try {
412
- const re = globToRegex(String(glob));
413
- if (re.test(normalized)) return true;
414
- const base = normalized.split('/').pop();
415
- if (re.test(base)) return true;
416
- } catch {
417
- /* malformed glob, skip */
418
- }
419
- }
420
- return false;
421
- }
422
-
423
- export function shouldIgnoreDetectionFile(filePath, root, config) {
424
- const globs = config?.ignoreFiles || [];
425
- if (!Array.isArray(globs) || globs.length === 0) return false;
426
- const raw = String(filePath || '').trim();
427
- if (!raw) return false;
428
- if (matchesAnyGlob(raw, globs)) return true;
429
-
430
- try {
431
- const abs = isAbsolute(raw) ? raw : resolve(root, raw);
432
- if (matchesAnyGlob(abs, globs)) return true;
433
- const rel = relative(root, abs);
434
- if (rel && !rel.startsWith('..') && !isAbsolute(rel)) {
435
- return matchesAnyGlob(rel, globs);
436
- }
437
- } catch {
438
- /* ignore */
439
- }
440
- return false;
441
- }
442
-
443
- export function filterDetectionFindings(findings, config) {
444
- if (!Array.isArray(findings) || findings.length === 0) return [];
445
- const ignoreRules = new Set((config?.ignoreRules || []).map((rule) => normalizeIgnoreRule(rule)));
446
- const ignoreValues = normalizeIgnoreValueEntries(config?.ignoreValues || []);
447
- return findings.filter((finding) => {
448
- if (!finding || typeof finding !== 'object') return false;
449
- if (ignoreRules.has(normalizeIgnoreRule(finding.antipattern))) return false;
450
- if (isIgnoredFindingValue(finding, ignoreValues)) return false;
451
- return true;
452
- });
453
- }
454
-
455
- function isIgnoredFindingValue(finding, ignoreValues) {
456
- if (!Array.isArray(ignoreValues) || ignoreValues.length === 0) return false;
457
- const rule = normalizeIgnoreRule(finding.antipattern);
458
- if (!rule) return false;
459
- // File-scoped wildcards suppress rules with no extractable value, such as side-tab.
460
- const value = extractFindingIgnoreValue(finding);
461
- return ignoreValues.some((entry) => {
462
- if (entry.rule !== rule) return false;
463
- const wildcardValue = entry.value === '*';
464
- if (!wildcardValue && (!value || !ignoreValueMatches(rule, entry.value, value))) return false;
465
- if (!Array.isArray(entry.files) || entry.files.length === 0) return !wildcardValue;
466
- return findingMatchesScopedIgnoreFile(finding, entry.files);
467
- });
468
- }
469
-
470
- function findingMatchesScopedIgnoreFile(finding, globs) {
471
- const filePath = String(finding?.file || '').trim();
472
- if (!filePath) return false;
473
- if (matchesAnyGlob(filePath, globs)) return true;
474
-
475
- const normalized = filePath.split(sep).join('/');
476
- const parts = normalized.split('/').filter(Boolean);
477
- for (let i = 0; i < parts.length; i++) {
478
- const suffix = parts.slice(i).join('/');
479
- if (matchesAnyGlob(suffix, globs)) return true;
480
- }
481
- return false;
482
- }
483
-
484
- export function extractFindingIgnoreValue(finding) {
485
- if (!finding || typeof finding !== 'object') return '';
486
- const rule = normalizeIgnoreRule(finding.antipattern);
487
- const directValueRules = new Set([
488
- 'overused-font',
489
- 'bounce-easing',
490
- 'design-system-font',
491
- 'design-system-color',
492
- 'design-system-radius',
493
- 'design-system-font-size',
494
- ]);
495
- if (!directValueRules.has(rule)) return '';
496
- return normalizeIgnoreValue(extractFindingIgnoreValueRaw(finding, rule));
497
- }
498
-
499
- function extractFindingIgnoreValueRaw(finding, rule = normalizeIgnoreRule(finding?.antipattern)) {
500
- const direct = cleanIgnoreValueDisplay(finding.ignoreValue || finding.value || '');
501
- if (direct) return direct;
502
-
503
- const candidates = [finding.detail, finding.snippet].filter((v) => typeof v === 'string' && v);
504
- for (const text of candidates) {
505
- if (rule === 'bounce-easing') {
506
- const motion = extractMotionIgnoreValue(text);
507
- if (motion) return motion;
508
- continue;
509
- }
510
-
511
- const primary = text.match(/Primary font:\s*([^()\n;]+)/i);
512
- if (primary) return cleanIgnoreValueDisplay(primary[1]);
513
-
514
- const googleLabel = text.match(/Google Fonts:\s*([^()\n;]+)/i);
515
- if (googleLabel) return cleanIgnoreValueDisplay(googleLabel[1]);
516
-
517
- const family = text.match(/font-family\s*:\s*["']?([^'",;\n]+)/i);
518
- if (family) return cleanIgnoreValueDisplay(family[1]);
519
-
520
- const google = text.match(/[?&]family=([^&:;\n]+)/i);
521
- if (google) {
522
- try {
523
- return cleanIgnoreValueDisplay(decodeURIComponent(google[1]));
524
- } catch {
525
- return cleanIgnoreValueDisplay(google[1]);
526
- }
527
- }
528
- }
529
-
530
- return '';
531
- }
532
-
533
- function extractMotionIgnoreValue(text) {
534
- const tailwind = text.match(/\banimate-bounce\b/i);
535
- if (tailwind) return cleanIgnoreValueDisplay(tailwind[0]);
536
-
537
- const bezier = text.match(/cubic-bezier\([^)]+\)/i);
538
- if (bezier) return cleanIgnoreValueDisplay(bezier[0]);
539
-
540
- const animation = text.match(/animation(?:-name)?\s*:\s*([^;\n]+)/i);
541
- if (animation) {
542
- const token = animation[1]
543
- .split(/[,\s]+/)
544
- .find((part) => /bounce|elastic|wobble|jiggle|spring/i.test(part));
545
- if (token) return cleanIgnoreValueDisplay(token);
546
- }
547
-
548
- return '';
549
- }
550
-
551
- function cleanIgnoreValueDisplay(value) {
552
- return String(value || '')
553
- .trim()
554
- .replace(/^["']|["']$/g, '')
555
- .replace(/\+/g, ' ')
556
- .replace(/\s+/g, ' ');
557
- }
558
-
559
- /**
560
- * The recorded design-hook decision: 'accepted' | 'declined' | undefined.
561
- * config.local.json (per-developer) overrides config.json.
562
- */
563
- export function getHookConsent(root) {
564
- let consent;
565
- for (const filePath of [getConfigPath(root), getLocalConfigPath(root)]) {
566
- const hook = hookSection(safeReadJson(filePath));
567
- if (hook && (hook.consent === 'accepted' || hook.consent === 'declined')) consent = hook.consent;
568
- }
569
- return consent;
570
- }
571
-
572
- /**
573
- * Persist the per-developer decision to config.local.json, preserving any
574
- * sibling keys, and ensure the file is gitignored.
575
- */
576
- export function setHookConsent(root, value) {
577
- const filePath = getLocalConfigPath(root);
578
- const existing = safeReadJson(filePath) || {};
579
- const hook = hookSection(existing) || {};
580
- const next = { ...existing, hook: { ...hook, consent: value } };
581
- mkdirSync(dirname(filePath), { recursive: true });
582
- writeFileSync(filePath, `${JSON.stringify(next, null, 2)}\n`);
583
- ensureConfigGitExclude(root);
584
- return filePath;
585
- }
586
-
587
- const EXCLUDE_OPEN = '# impeccable-config-ignore-start';
588
- const EXCLUDE_CLOSE = '# impeccable-config-ignore-end';
589
- const EXCLUDE_PATTERNS = ['.impeccable/config.local.json'];
590
-
591
- /**
592
- * Add config.local.json to `.git/info/exclude` so a developer's decision is
593
- * never committed. Idempotent via marker comments. Best-effort; returns false
594
- * when there is no resolvable git dir.
595
- */
596
- export function ensureConfigGitExclude(root) {
597
- try {
598
- const gitDir = resolveGitDir(root);
599
- if (!gitDir) return false;
600
- const target = join(gitDir, 'info', 'exclude');
601
- const existing = existsSync(target) ? readFileSync(target, 'utf-8') : '';
602
- const block = [EXCLUDE_OPEN, ...EXCLUDE_PATTERNS, EXCLUDE_CLOSE].join('\n');
603
- const markerRe = new RegExp(`${escapeRegExp(EXCLUDE_OPEN)}[\\s\\S]*?${escapeRegExp(EXCLUDE_CLOSE)}`);
604
- let updated;
605
- if (markerRe.test(existing)) {
606
- updated = existing.replace(markerRe, block);
607
- } else {
608
- const prefix = existing.length === 0 ? '' : existing.endsWith('\n') ? existing : `${existing}\n`;
609
- updated = `${prefix}${block}\n`;
610
- }
611
- if (updated !== existing) {
612
- mkdirSync(dirname(target), { recursive: true });
613
- writeFileSync(target, updated);
614
- }
615
- return true;
616
- } catch {
617
- return false;
618
- }
619
- }
620
-
621
- function resolveGitDir(root) {
622
- const dotGit = join(root, '.git');
623
- if (!existsSync(dotGit)) return null;
624
- try {
625
- if (statSync(dotGit).isDirectory()) return dotGit;
626
- // A `.git` file (worktree/submodule) points elsewhere: "gitdir: <path>".
627
- const match = readFileSync(dotGit, 'utf-8').match(/gitdir:\s*(.+)/);
628
- if (match) {
629
- const resolved = match[1].trim();
630
- return isAbsolute(resolved) ? resolved : join(root, resolved);
631
- }
632
- } catch {
633
- /* fall through */
634
- }
635
- return null;
636
- }
637
-
638
- function escapeRegExp(value) {
639
- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
640
- }