omo-ai 5.1.68 → 5.1.70

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 (410) hide show
  1. package/bin/darwin/omo-keychain +0 -0
  2. package/bin/lib/agent-dir.js +8 -1
  3. package/bin/lib/auth-store.js +11 -1
  4. package/bin/lib/bun-bin-shim.js +12 -2
  5. package/bin/lib/category-coverage.js +56 -18
  6. package/bin/lib/child-process.js +2 -1
  7. package/bin/lib/compile-safe-engine.js +14 -2
  8. package/bin/lib/computer-use-doctor.js +1 -0
  9. package/bin/lib/daemon-adopt.js +41 -10
  10. package/bin/lib/daemon-config.js +9 -3
  11. package/bin/lib/daemon-operations.js +11 -3
  12. package/bin/lib/daemon-rollback.js +28 -23
  13. package/bin/lib/daemon-status.js +9 -3
  14. package/bin/lib/daemon.js +18 -3
  15. package/bin/lib/doctor-memory-runtime.js +46 -12
  16. package/bin/lib/doctor-migration.js +65 -38
  17. package/bin/lib/doctor-pi-config.js +8 -3
  18. package/bin/lib/doctor-reflection-lock.js +35 -12
  19. package/bin/lib/doctor.js +63 -23
  20. package/bin/lib/engine-boot.js +3 -1
  21. package/bin/lib/engine-commands.js +11 -1
  22. package/bin/lib/engine-environment.js +8 -1
  23. package/bin/lib/engine-models.js +2 -1
  24. package/bin/lib/engine-prepare.js +18 -3
  25. package/bin/lib/host-status.js +5 -1
  26. package/bin/lib/jsonc-edit.js +10 -6
  27. package/bin/lib/keychain-helper-doctor.js +13 -3
  28. package/bin/lib/launch-spec-mode.js +6 -2
  29. package/bin/lib/launcher.js +31 -19
  30. package/bin/lib/model-chains.js +12 -5
  31. package/bin/lib/npm-dist-tags.js +2 -1
  32. package/bin/lib/package-paths.js +18 -10
  33. package/bin/lib/private-fd-table.js +19 -10
  34. package/bin/lib/provider-map.json +1 -1
  35. package/bin/lib/rpc-stream-errors.js +6 -2
  36. package/bin/lib/same-version.js +6 -1
  37. package/bin/lib/self-update.js +41 -10
  38. package/bin/lib/service-auth.generated.js +44 -23
  39. package/bin/lib/setup-assets-import.js +25 -5
  40. package/bin/lib/setup-commandcode.js +5 -2
  41. package/bin/lib/setup-credentials.js +12 -2
  42. package/bin/lib/setup-detect-refresh.js +9 -6
  43. package/bin/lib/setup-detect.js +4 -5
  44. package/bin/lib/setup-guidance.js +1 -1
  45. package/bin/lib/setup-import.js +35 -7
  46. package/bin/lib/setup-model-choices-import.js +61 -10
  47. package/bin/lib/setup-models.js +9 -5
  48. package/bin/lib/setup-opencode-assets.js +26 -9
  49. package/bin/lib/setup-opencode-models.d.ts +4 -1
  50. package/bin/lib/setup-opencode-models.js +76 -30
  51. package/bin/lib/setup-opencode-providers.js +58 -17
  52. package/bin/lib/setup-providers-import.js +38 -6
  53. package/bin/lib/setup-report.js +9 -7
  54. package/bin/lib/setup-stream-items.js +29 -5
  55. package/bin/lib/setup-stream.d.ts +13 -3
  56. package/bin/lib/setup-stream.js +92 -15
  57. package/bin/lib/setup-summary.js +61 -18
  58. package/bin/lib/sqlite-rows.js +3 -1
  59. package/bin/lib/thread-output.js +14 -4
  60. package/bin/lib/thread.js +224 -38
  61. package/bin/lib/update-args.js +5 -1
  62. package/bin/lib/update-lock.js +13 -2
  63. package/bin/omo.js +1 -1
  64. package/package.json +2 -2
  65. package/plugin/CHANGELOG.md +146 -0
  66. package/plugin/extensions/assets.generated.json +4 -4
  67. package/plugin/extensions/gateway-store-worker.mjs +2 -2
  68. package/plugin/extensions/memory-run-supervisor.mjs +1 -1
  69. package/plugin/extensions/omo-claim-receipt.js +1 -1
  70. package/plugin/extensions/omo-computer-run-worker.mjs +2 -0
  71. package/plugin/extensions/omo-computer-use.js +2 -2
  72. package/plugin/extensions/omo-desktop-toolkit.js +1 -1
  73. package/plugin/extensions/omo-device-account.js +4 -4
  74. package/plugin/extensions/omo-device-service.js +5 -5
  75. package/plugin/extensions/omo-feedback.js +2 -2
  76. package/plugin/extensions/omo-init-deep-advisor.js +1 -1
  77. package/plugin/extensions/omo-member.js +2 -2
  78. package/plugin/extensions/omo-memory-commands.js +2 -2
  79. package/plugin/extensions/omo-memory-doctor.js +3 -3
  80. package/plugin/extensions/omo-memory-memfs.js +1 -1
  81. package/plugin/extensions/omo-memory-palace.js +1 -1
  82. package/plugin/extensions/omo-memory-sync.js +2 -2
  83. package/plugin/extensions/omo-onboarding-scan.js +2 -2
  84. package/plugin/extensions/omo-recall-store.js +1 -1
  85. package/plugin/extensions/omo-session-history.js +1 -1
  86. package/plugin/extensions/omo-side-panel.js +3 -3
  87. package/plugin/extensions/omo-task.js +2 -2
  88. package/plugin/extensions/omo-telemetry-otlp.js +1 -1
  89. package/plugin/extensions/omo-telemetry-posthog.js +1 -1
  90. package/plugin/extensions/omo-telemetry-recovery.js +1 -1
  91. package/plugin/extensions/omo-thread-client.js +5 -5
  92. package/plugin/extensions/omo.js +3 -3
  93. package/plugin/extensions/quickjs.wasm +0 -0
  94. package/plugin/package.json +1 -1
  95. package/plugin/runtime/agent-toolkit-sdk/sdk.js +2 -2
  96. package/plugin/runtime/ast-grep-mcp/cli.js +26 -5
  97. package/plugin/runtime/ast-grep-mcp/manifest.json +2 -2
  98. package/plugin/runtime/bunshin-ts/sdk.js +4 -4
  99. package/plugin/runtime/category-coverage/assets.generated.json +4 -4
  100. package/plugin/runtime/category-coverage/index.js +7 -7
  101. package/plugin/runtime/lsp-daemon/dist/.omo-runtime-manifest.json +4 -4
  102. package/plugin/runtime/lsp-daemon/dist/cli.js +8 -2
  103. package/plugin/runtime/lsp-daemon/dist/client.js +8 -2
  104. package/plugin/runtime/lsp-daemon/dist/index.js +8 -2
  105. package/plugin/runtime/rollback-migrate.js +2 -2
  106. package/plugin/runtime/task-config/index.js +3 -3
  107. package/plugin/runtime/thread-sdk/sdk.js +5 -5
  108. package/plugin/scripts/install.mjs +22 -15
  109. package/plugin/skills/ast-grep/references/recipes.md +1 -1
  110. package/plugin/skills/ast-grep/tests/smoke.ps1 +1 -1
  111. package/plugin/skills/ast-grep/tests/smoke.sh +1 -1
  112. package/plugin/skills/browser/runtime/omowright/index.js +16 -16
  113. package/plugin/skills/browser/runtime/omowright/manifest.json +5 -5
  114. package/plugin/skills/browser/runtime/omowright/page-bundle.js +14 -4
  115. package/plugin/skills/browser/scripts/browser-doctor-report.mjs +36 -9
  116. package/plugin/skills/browser/scripts/browser-doctor.mjs +24 -7
  117. package/plugin/skills/browser/scripts/browser-engine-guard.mjs +2 -1
  118. package/plugin/skills/browser/scripts/browser-install.mjs +40 -8
  119. package/plugin/skills/debugging/references/scripts/dap.mjs +280 -170
  120. package/plugin/skills/debugging/references/scripts/fixture-adapter.mjs +104 -42
  121. package/plugin/skills/frontend/scripts/detect/cli.ts +67 -50
  122. package/plugin/skills/frontend/scripts/detect/config.ts +41 -38
  123. package/plugin/skills/frontend/scripts/detect/core/color.ts +109 -94
  124. package/plugin/skills/frontend/scripts/detect/core/page.ts +43 -42
  125. package/plugin/skills/frontend/scripts/detect/core/shadow.ts +38 -29
  126. package/plugin/skills/frontend/scripts/detect/core/source.ts +25 -20
  127. package/plugin/skills/frontend/scripts/detect/detect.ts +63 -45
  128. package/plugin/skills/frontend/scripts/detect/lint.ts +78 -69
  129. package/plugin/skills/frontend/scripts/detect/render/probe-placement.ts +36 -32
  130. package/plugin/skills/frontend/scripts/detect/render/renderer.ts +14 -13
  131. package/plugin/skills/frontend/scripts/detect/render/webview.ts +53 -50
  132. package/plugin/skills/frontend/scripts/detect/report.ts +20 -18
  133. package/plugin/skills/frontend/scripts/detect/rule.ts +21 -21
  134. package/plugin/skills/frontend/scripts/detect/rules/color/ai-color-palette.ts +144 -63
  135. package/plugin/skills/frontend/scripts/detect/rules/color/cream-palette.ts +41 -27
  136. package/plugin/skills/frontend/scripts/detect/rules/color/dark-glow.ts +59 -34
  137. package/plugin/skills/frontend/scripts/detect/rules/color/design-system-color.ts +37 -28
  138. package/plugin/skills/frontend/scripts/detect/rules/color/gradient-text.ts +68 -45
  139. package/plugin/skills/frontend/scripts/detect/rules/color/gray-on-color.ts +34 -25
  140. package/plugin/skills/frontend/scripts/detect/rules/color/index.ts +9 -2
  141. package/plugin/skills/frontend/scripts/detect/rules/color/low-contrast.ts +106 -43
  142. package/plugin/skills/frontend/scripts/detect/rules/color/radial-halo.ts +48 -23
  143. package/plugin/skills/frontend/scripts/detect/rules/color/radial-spotlight-glow.ts +49 -26
  144. package/plugin/skills/frontend/scripts/detect/rules/color/support/animation-opacity.ts +90 -66
  145. package/plugin/skills/frontend/scripts/detect/rules/color/support/color-path.ts +43 -6
  146. package/plugin/skills/frontend/scripts/detect/rules/color/support/contrast-pairs.ts +75 -38
  147. package/plugin/skills/frontend/scripts/detect/rules/color/support/contrast-role.ts +142 -59
  148. package/plugin/skills/frontend/scripts/detect/rules/color/support/glow-forms.ts +93 -44
  149. package/plugin/skills/frontend/scripts/detect/rules/color/support/gradient-samples.ts +115 -114
  150. package/plugin/skills/frontend/scripts/detect/rules/color/support/gradients.ts +77 -66
  151. package/plugin/skills/frontend/scripts/detect/rules/color/support/mockup-roots.ts +178 -48
  152. package/plugin/skills/frontend/scripts/detect/rules/color/support/page-ignore.ts +6 -2
  153. package/plugin/skills/frontend/scripts/detect/rules/color/support/painted-text.ts +171 -108
  154. package/plugin/skills/frontend/scripts/detect/rules/color/support/palette-roles.ts +60 -39
  155. package/plugin/skills/frontend/scripts/detect/rules/color/support/placeholder-contrast.ts +36 -16
  156. package/plugin/skills/frontend/scripts/detect/rules/color/support/stock-accent.ts +48 -18
  157. package/plugin/skills/frontend/scripts/detect/rules/color/support/text-colors.ts +88 -62
  158. package/plugin/skills/frontend/scripts/detect/rules/copy/aphoristic-cadence.ts +25 -15
  159. package/plugin/skills/frontend/scripts/detect/rules/copy/broken-image.ts +20 -12
  160. package/plugin/skills/frontend/scripts/detect/rules/copy/em-dash-overuse.ts +63 -39
  161. package/plugin/skills/frontend/scripts/detect/rules/copy/index.ts +9 -2
  162. package/plugin/skills/frontend/scripts/detect/rules/copy/marketing-buzzword.ts +53 -25
  163. package/plugin/skills/frontend/scripts/detect/rules/copy/numbered-section-labels.ts +49 -28
  164. package/plugin/skills/frontend/scripts/detect/rules/copy/repeated-container-text.ts +80 -47
  165. package/plugin/skills/frontend/scripts/detect/rules/copy/script-error.ts +42 -34
  166. package/plugin/skills/frontend/scripts/detect/rules/copy/skipped-heading.ts +199 -75
  167. package/plugin/skills/frontend/scripts/detect/rules/copy/support/numbered-label.ts +122 -71
  168. package/plugin/skills/frontend/scripts/detect/rules/copy/support/page-text.ts +32 -24
  169. package/plugin/skills/frontend/scripts/detect/rules/copy/theater-slop-phrase.ts +42 -13
  170. package/plugin/skills/frontend/scripts/detect/rules/decoration/blinking-cursor.ts +49 -41
  171. package/plugin/skills/frontend/scripts/detect/rules/decoration/border-accent-on-rounded.ts +10 -10
  172. package/plugin/skills/frontend/scripts/detect/rules/decoration/bounce-easing.ts +87 -68
  173. package/plugin/skills/frontend/scripts/detect/rules/decoration/buried-raster.ts +83 -64
  174. package/plugin/skills/frontend/scripts/detect/rules/decoration/codex-grid-background.ts +29 -29
  175. package/plugin/skills/frontend/scripts/detect/rules/decoration/design-system-radius.ts +33 -26
  176. package/plugin/skills/frontend/scripts/detect/rules/decoration/gpt-thin-border-wide-shadow.ts +61 -58
  177. package/plugin/skills/frontend/scripts/detect/rules/decoration/hard-offset-shadow.ts +25 -23
  178. package/plugin/skills/frontend/scripts/detect/rules/decoration/hero-eyebrow-chip.ts +16 -14
  179. package/plugin/skills/frontend/scripts/detect/rules/decoration/icon-tile-stack.ts +85 -84
  180. package/plugin/skills/frontend/scripts/detect/rules/decoration/index.ts +17 -17
  181. package/plugin/skills/frontend/scripts/detect/rules/decoration/kicker-above-heading.ts +79 -64
  182. package/plugin/skills/frontend/scripts/detect/rules/decoration/marquee.ts +57 -40
  183. package/plugin/skills/frontend/scripts/detect/rules/decoration/organic-clip-path.ts +34 -34
  184. package/plugin/skills/frontend/scripts/detect/rules/decoration/pulsing-dot.ts +92 -58
  185. package/plugin/skills/frontend/scripts/detect/rules/decoration/repeating-stripes-gradient.ts +19 -19
  186. package/plugin/skills/frontend/scripts/detect/rules/decoration/shape-assembled-illustration.ts +59 -53
  187. package/plugin/skills/frontend/scripts/detect/rules/decoration/side-tab.ts +15 -12
  188. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/appearance.ts +89 -85
  189. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/assert-cases.ts +17 -15
  190. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/borders.ts +178 -136
  191. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/clip-geometry.ts +155 -145
  192. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/css-candidates.ts +60 -54
  193. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/curve-samples.ts +51 -48
  194. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/gradient-pattern.ts +43 -34
  195. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/keyframes.ts +118 -113
  196. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/labels.ts +74 -67
  197. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/raster-state.ts +80 -42
  198. package/plugin/skills/frontend/scripts/detect/rules/index.ts +6 -6
  199. package/plugin/skills/frontend/scripts/detect/rules/layout/body-text-viewport-edge.ts +116 -55
  200. package/plugin/skills/frontend/scripts/detect/rules/layout/clipped-overflow-container.ts +22 -9
  201. package/plugin/skills/frontend/scripts/detect/rules/layout/content-hidden-at-rest.ts +113 -52
  202. package/plugin/skills/frontend/scripts/detect/rules/layout/cramped-padding.ts +167 -90
  203. package/plugin/skills/frontend/scripts/detect/rules/layout/edge-flush-cards.ts +82 -41
  204. package/plugin/skills/frontend/scripts/detect/rules/layout/first-viewport-column-overflow.ts +74 -37
  205. package/plugin/skills/frontend/scripts/detect/rules/layout/heading-rhythm.ts +49 -24
  206. package/plugin/skills/frontend/scripts/detect/rules/layout/index.ts +14 -3
  207. package/plugin/skills/frontend/scripts/detect/rules/layout/monotonous-spacing.ts +47 -28
  208. package/plugin/skills/frontend/scripts/detect/rules/layout/nested-cards.ts +66 -31
  209. package/plugin/skills/frontend/scripts/detect/rules/layout/straggler.ts +46 -22
  210. package/plugin/skills/frontend/scripts/detect/rules/layout/support/cards.ts +157 -82
  211. package/plugin/skills/frontend/scripts/detect/rules/layout/support/clipping.ts +98 -50
  212. package/plugin/skills/frontend/scripts/detect/rules/layout/support/declared-mockups.ts +100 -36
  213. package/plugin/skills/frontend/scripts/detect/rules/layout/support/geometry.ts +66 -43
  214. package/plugin/skills/frontend/scripts/detect/rules/layout/support/hidden-interface.ts +56 -24
  215. package/plugin/skills/frontend/scripts/detect/rules/layout/support/layout-cases.ts +23 -8
  216. package/plugin/skills/frontend/scripts/detect/rules/layout/support/line-breaks.ts +28 -16
  217. package/plugin/skills/frontend/scripts/detect/rules/layout/support/motion.ts +88 -56
  218. package/plugin/skills/frontend/scripts/detect/rules/layout/support/padding.ts +106 -68
  219. package/plugin/skills/frontend/scripts/detect/rules/layout/support/rhythm.ts +204 -128
  220. package/plugin/skills/frontend/scripts/detect/rules/layout/text-occlusion.ts +125 -70
  221. package/plugin/skills/frontend/scripts/detect/rules/layout/text-overflow.ts +111 -59
  222. package/plugin/skills/frontend/scripts/detect/rules/layout/unbalanced-heading.ts +27 -16
  223. package/plugin/skills/frontend/scripts/detect/rules/layout/viewport-reflow.ts +38 -23
  224. package/plugin/skills/frontend/scripts/detect/rules/source/ai-color-palette.ts +17 -6
  225. package/plugin/skills/frontend/scripts/detect/rules/source/aphoristic-cadence.ts +19 -9
  226. package/plugin/skills/frontend/scripts/detect/rules/source/border-accent-on-rounded.ts +31 -13
  227. package/plugin/skills/frontend/scripts/detect/rules/source/bounce-easing.ts +41 -16
  228. package/plugin/skills/frontend/scripts/detect/rules/source/broken-image.ts +19 -9
  229. package/plugin/skills/frontend/scripts/detect/rules/source/codex-grid-background.ts +36 -12
  230. package/plugin/skills/frontend/scripts/detect/rules/source/dark-glow.ts +28 -14
  231. package/plugin/skills/frontend/scripts/detect/rules/source/em-dash-overuse.ts +17 -9
  232. package/plugin/skills/frontend/scripts/detect/rules/source/gradient-text.ts +14 -6
  233. package/plugin/skills/frontend/scripts/detect/rules/source/gray-on-color.ts +18 -7
  234. package/plugin/skills/frontend/scripts/detect/rules/source/index.ts +18 -1
  235. package/plugin/skills/frontend/scripts/detect/rules/source/marketing-buzzword.ts +49 -11
  236. package/plugin/skills/frontend/scripts/detect/rules/source/marquee.ts +16 -6
  237. package/plugin/skills/frontend/scripts/detect/rules/source/monotonous-spacing.ts +35 -17
  238. package/plugin/skills/frontend/scripts/detect/rules/source/overused-font.ts +51 -10
  239. package/plugin/skills/frontend/scripts/detect/rules/source/radial-halo.ts +16 -8
  240. package/plugin/skills/frontend/scripts/detect/rules/source/side-tab.ts +88 -47
  241. package/plugin/skills/frontend/scripts/detect/rules/source/support/accent-scans.ts +103 -62
  242. package/plugin/skills/frontend/scripts/detect/rules/source/support/check-source.ts +6 -2
  243. package/plugin/skills/frontend/scripts/detect/rules/source/support/corners.ts +148 -80
  244. package/plugin/skills/frontend/scripts/detect/rules/source/support/css-effects.ts +86 -66
  245. package/plugin/skills/frontend/scripts/detect/rules/source/support/css-scopes.ts +148 -113
  246. package/plugin/skills/frontend/scripts/detect/rules/source/support/image-tags.ts +113 -105
  247. package/plugin/skills/frontend/scripts/detect/rules/source/support/js-punctuation.ts +47 -30
  248. package/plugin/skills/frontend/scripts/detect/rules/source/support/markup-scope.ts +45 -34
  249. package/plugin/skills/frontend/scripts/detect/rules/source/support/source-color.ts +64 -29
  250. package/plugin/skills/frontend/scripts/detect/rules/source/support/source-shadow.ts +17 -10
  251. package/plugin/skills/frontend/scripts/detect/rules/source/support/source-text.ts +128 -86
  252. package/plugin/skills/frontend/scripts/detect/rules/typography/all-caps-body.ts +23 -9
  253. package/plugin/skills/frontend/scripts/detect/rules/typography/design-system-font-size.ts +27 -17
  254. package/plugin/skills/frontend/scripts/detect/rules/typography/design-system-font.ts +27 -17
  255. package/plugin/skills/frontend/scripts/detect/rules/typography/extreme-negative-tracking.ts +26 -12
  256. package/plugin/skills/frontend/scripts/detect/rules/typography/flat-type-hierarchy.ts +41 -19
  257. package/plugin/skills/frontend/scripts/detect/rules/typography/index.ts +14 -3
  258. package/plugin/skills/frontend/scripts/detect/rules/typography/italic-serif-display.ts +67 -16
  259. package/plugin/skills/frontend/scripts/detect/rules/typography/justified-text.ts +47 -25
  260. package/plugin/skills/frontend/scripts/detect/rules/typography/line-length.ts +37 -21
  261. package/plugin/skills/frontend/scripts/detect/rules/typography/oversized-h1.ts +35 -14
  262. package/plugin/skills/frontend/scripts/detect/rules/typography/overused-font.ts +83 -38
  263. package/plugin/skills/frontend/scripts/detect/rules/typography/support/drawn-enlargement.ts +68 -40
  264. package/plugin/skills/frontend/scripts/detect/rules/typography/support/fading-text.ts +59 -39
  265. package/plugin/skills/frontend/scripts/detect/rules/typography/support/flex-runs.ts +13 -8
  266. package/plugin/skills/frontend/scripts/detect/rules/typography/support/font-family.ts +68 -17
  267. package/plugin/skills/frontend/scripts/detect/rules/typography/support/painted-text.ts +173 -67
  268. package/plugin/skills/frontend/scripts/detect/rules/typography/support/svg-size.ts +56 -49
  269. package/plugin/skills/frontend/scripts/detect/rules/typography/support/text-context.ts +155 -78
  270. package/plugin/skills/frontend/scripts/detect/rules/typography/support/text-lines.ts +38 -28
  271. package/plugin/skills/frontend/scripts/detect/rules/typography/support/type-hierarchy.ts +43 -38
  272. package/plugin/skills/frontend/scripts/detect/rules/typography/tight-leading.ts +67 -39
  273. package/plugin/skills/frontend/scripts/detect/rules/typography/tiny-text.ts +34 -15
  274. package/plugin/skills/frontend/scripts/detect/rules/typography/undersized-ui-text.ts +52 -22
  275. package/plugin/skills/frontend/scripts/detect/rules/typography/wide-tracking.ts +37 -19
  276. package/plugin/skills/frontend/scripts/detect/snapshot/collect.ts +154 -145
  277. package/plugin/skills/frontend/scripts/detect/snapshot/style-props.ts +121 -21
  278. package/plugin/skills/frontend/scripts/detect/testing/build-snapshot.ts +140 -65
  279. package/plugin/skills/frontend/scripts/detect/types.ts +81 -76
  280. package/plugin/skills/frontend/scripts/perfection/accent-stripes/color.ts +205 -85
  281. package/plugin/skills/frontend/scripts/perfection/accent-stripes/css-parse.ts +97 -80
  282. package/plugin/skills/frontend/scripts/perfection/accent-stripes/declarations.ts +129 -101
  283. package/plugin/skills/frontend/scripts/perfection/accent-stripes/findings.ts +23 -23
  284. package/plugin/skills/frontend/scripts/perfection/accent-stripes/gradient.ts +43 -42
  285. package/plugin/skills/frontend/scripts/perfection/accent-stripes/lint.ts +75 -60
  286. package/plugin/skills/frontend/scripts/perfection/accent-stripes/markup.ts +131 -106
  287. package/plugin/skills/frontend/scripts/perfection/accent-stripes/selector.ts +28 -25
  288. package/plugin/skills/frontend/scripts/perfection/accent-stripes/tailwind.ts +93 -78
  289. package/plugin/skills/frontend/scripts/perfection/check-accent-stripes.ts +22 -22
  290. package/plugin/skills/frontend/scripts/perfection/check-draft-guard.ts +24 -24
  291. package/plugin/skills/frontend/scripts/perfection/collect-files.ts +49 -36
  292. package/plugin/skills/frontend/scripts/perfection/draft-guard/findings.ts +10 -9
  293. package/plugin/skills/frontend/scripts/perfection/draft-guard/lint.ts +27 -24
  294. package/plugin/skills/frontend/scripts/perfection/draft-guard/rules.ts +46 -42
  295. package/plugin/skills/frontend/scripts/perfection/draft-guard/text-nodes.ts +98 -75
  296. package/plugin/skills/lsp-setup/scripts/detect-lsp.ts +162 -152
  297. package/plugin/skills/lsp-setup/scripts/lsp-server-table.ts +164 -164
  298. package/plugin/skills/lsp-setup/scripts/verify-lsp.ts +94 -91
  299. package/plugin/skills/programming/SKILL.md +2 -2
  300. package/plugin/skills/programming/scripts/go/new-project.ts +68 -68
  301. package/plugin/skills/programming/scripts/python/new-project.ts +64 -64
  302. package/plugin/skills/programming/scripts/python/new-script.ts +39 -39
  303. package/plugin/skills/programming/scripts/rust/new-project.ts +60 -57
  304. package/plugin/skills/programming/scripts/shared/run-tool.ts +7 -7
  305. package/plugin/skills/programming/scripts/typescript/check-no-excuse-rules.ts +96 -36
  306. package/plugin/skills/programming/scripts/typescript/check-test-junk-rules.ts +38 -17
  307. package/plugin/skills/programming/scripts/typescript/check-test-junk.ts +13 -2
  308. package/plugin/skills/programming/scripts/typescript/mutation-proof.ts +16 -4
  309. package/plugin/skills/programming/scripts/typescript/new-project.ts +21 -21
  310. package/plugin/skills/ultimate-browsing/engine/templates/playwright_mobile_chrome.js +65 -62
  311. package/plugin/skills/ultimate-browsing/engine/templates/playwright_real_chrome.js +73 -70
  312. package/plugin/skills/ulw-plan/scripts/plan-templates.mjs +30 -30
  313. package/plugin/skills/ulw-plan/scripts/scaffold-plan.mjs +131 -123
  314. package/plugin/skills/ulw-research/scripts/claim-kinds.mjs +178 -67
  315. package/plugin/skills/ulw-research/scripts/claims-index.mjs +117 -93
  316. package/plugin/skills/ulw-research/scripts/cli-support.mjs +73 -73
  317. package/plugin/skills/ulw-research/scripts/contracts.mjs +604 -174
  318. package/plugin/skills/ulw-research/scripts/conversion-probe.mjs +161 -113
  319. package/plugin/skills/ulw-research/scripts/css-hiding.mjs +126 -92
  320. package/plugin/skills/ulw-research/scripts/css-lite.mjs +143 -137
  321. package/plugin/skills/ulw-research/scripts/design-spec.mjs +123 -107
  322. package/plugin/skills/ulw-research/scripts/entities.mjs +66 -30
  323. package/plugin/skills/ulw-research/scripts/entry-guard.mjs +8 -8
  324. package/plugin/skills/ulw-research/scripts/fact-commands-fill.mjs +104 -51
  325. package/plugin/skills/ulw-research/scripts/fact-commands-meaning.mjs +207 -105
  326. package/plugin/skills/ulw-research/scripts/fact-commands-polish.mjs +143 -76
  327. package/plugin/skills/ulw-research/scripts/fact-commands-verify.mjs +164 -120
  328. package/plugin/skills/ulw-research/scripts/fact-commands.mjs +264 -151
  329. package/plugin/skills/ulw-research/scripts/fact-derive.mjs +92 -48
  330. package/plugin/skills/ulw-research/scripts/fact-expr.mjs +90 -78
  331. package/plugin/skills/ulw-research/scripts/fact-fill.mjs +215 -127
  332. package/plugin/skills/ulw-research/scripts/fact-ledger-kinds.mjs +305 -131
  333. package/plugin/skills/ulw-research/scripts/fact-ledger-schema.mjs +264 -158
  334. package/plugin/skills/ulw-research/scripts/fact-ledger.mjs +93 -57
  335. package/plugin/skills/ulw-research/scripts/fact-locate.mjs +204 -147
  336. package/plugin/skills/ulw-research/scripts/fact-pairs.mjs +126 -108
  337. package/plugin/skills/ulw-research/scripts/fact-recompute.mjs +89 -66
  338. package/plugin/skills/ulw-research/scripts/fidelity-binding.mjs +101 -70
  339. package/plugin/skills/ulw-research/scripts/fidelity-brief.mjs +95 -89
  340. package/plugin/skills/ulw-research/scripts/fidelity-claims.mjs +76 -48
  341. package/plugin/skills/ulw-research/scripts/fidelity-csv.mjs +27 -27
  342. package/plugin/skills/ulw-research/scripts/fidelity-lexicon.mjs +101 -78
  343. package/plugin/skills/ulw-research/scripts/fidelity-originals.mjs +124 -77
  344. package/plugin/skills/ulw-research/scripts/fidelity-policy.mjs +132 -83
  345. package/plugin/skills/ulw-research/scripts/fidelity-records.mjs +179 -117
  346. package/plugin/skills/ulw-research/scripts/fidelity-snapshot-readability.mjs +38 -33
  347. package/plugin/skills/ulw-research/scripts/fidelity-sources.mjs +92 -54
  348. package/plugin/skills/ulw-research/scripts/fidelity-state.mjs +27 -27
  349. package/plugin/skills/ulw-research/scripts/fidelity-trace.mjs +81 -48
  350. package/plugin/skills/ulw-research/scripts/fidelity-value-unit.mjs +207 -104
  351. package/plugin/skills/ulw-research/scripts/fidelity-values.mjs +255 -154
  352. package/plugin/skills/ulw-research/scripts/format-extract-css.mjs +74 -74
  353. package/plugin/skills/ulw-research/scripts/format-extract.mjs +161 -134
  354. package/plugin/skills/ulw-research/scripts/gates-fidelity.mjs +118 -59
  355. package/plugin/skills/ulw-research/scripts/gates-figures.mjs +192 -141
  356. package/plugin/skills/ulw-research/scripts/gates-layout.mjs +119 -85
  357. package/plugin/skills/ulw-research/scripts/gates-static.mjs +109 -102
  358. package/plugin/skills/ulw-research/scripts/gates-structure.mjs +105 -86
  359. package/plugin/skills/ulw-research/scripts/gates-text.mjs +169 -113
  360. package/plugin/skills/ulw-research/scripts/html-foreign-object.mjs +39 -34
  361. package/plugin/skills/ulw-research/scripts/html-lite.mjs +230 -176
  362. package/plugin/skills/ulw-research/scripts/html-markup.mjs +150 -128
  363. package/plugin/skills/ulw-research/scripts/html-text-map.mjs +125 -96
  364. package/plugin/skills/ulw-research/scripts/layout-probe.mjs +10 -8
  365. package/plugin/skills/ulw-research/scripts/lexicon.mjs +36 -19
  366. package/plugin/skills/ulw-research/scripts/markdown-closers.mjs +85 -85
  367. package/plugin/skills/ulw-research/scripts/md-lite.mjs +133 -125
  368. package/plugin/skills/ulw-research/scripts/meaning-check.mjs +154 -123
  369. package/plugin/skills/ulw-research/scripts/number-grammar.mjs +10 -8
  370. package/plugin/skills/ulw-research/scripts/numerals.mjs +181 -137
  371. package/plugin/skills/ulw-research/scripts/outcome-start.mjs +50 -36
  372. package/plugin/skills/ulw-research/scripts/outcome.mjs +194 -153
  373. package/plugin/skills/ulw-research/scripts/particles-ko.mjs +72 -70
  374. package/plugin/skills/ulw-research/scripts/placeholder.mjs +130 -112
  375. package/plugin/skills/ulw-research/scripts/polish-apply.mjs +67 -51
  376. package/plugin/skills/ulw-research/scripts/polish-diff.mjs +10 -5
  377. package/plugin/skills/ulw-research/scripts/polish-project.mjs +67 -57
  378. package/plugin/skills/ulw-research/scripts/polish-rules.mjs +120 -100
  379. package/plugin/skills/ulw-research/scripts/rational.mjs +74 -73
  380. package/plugin/skills/ulw-research/scripts/raw-decode.mjs +74 -74
  381. package/plugin/skills/ulw-research/scripts/raw-locator.mjs +32 -24
  382. package/plugin/skills/ulw-research/scripts/repair-tracker.mjs +98 -93
  383. package/plugin/skills/ulw-research/scripts/report-tools-commands.mjs +265 -176
  384. package/plugin/skills/ulw-research/scripts/report-tools.mjs +65 -62
  385. package/plugin/skills/ulw-research/scripts/sentence-split.mjs +63 -43
  386. package/plugin/skills/ulw-research/scripts/source-commands.mjs +199 -125
  387. package/plugin/skills/ulw-research/scripts/source-refresh.mjs +91 -54
  388. package/plugin/skills/ulw-research/scripts/source-snapshot.mjs +143 -102
  389. package/plugin/skills/ulw-research/scripts/source-view.mjs +82 -46
  390. package/plugin/skills/ulw-research/scripts/sources-citation.mjs +135 -96
  391. package/plugin/skills/ulw-research/scripts/text-normalize.mjs +63 -48
  392. package/plugin/skills/ulw-research/scripts/text-similarity.mjs +15 -15
  393. package/plugin/skills/ulw-research/scripts/unit-algebra.mjs +98 -66
  394. package/plugin/skills/ulw-research/scripts/unit-errors.mjs +14 -14
  395. package/plugin/skills/ulw-research/scripts/unit-metadata.mjs +30 -14
  396. package/plugin/skills/ulw-research/scripts/unit-pairs.mjs +57 -45
  397. package/plugin/skills/ulw-research/scripts/unit-precision.mjs +39 -25
  398. package/plugin/skills/ulw-research/scripts/unit-rules-shapes.mjs +79 -44
  399. package/plugin/skills/ulw-research/scripts/unit-rules.mjs +262 -135
  400. package/plugin/skills/ulw-research/scripts/units.mjs +96 -65
  401. package/plugin/skills/visual-qa/scripts/ansi.ts +3 -6
  402. package/plugin/skills/visual-qa/scripts/cli.ts +52 -52
  403. package/plugin/skills/visual-qa/scripts/east-asian-width.ts +53 -53
  404. package/plugin/skills/visual-qa/scripts/image-diff.ts +86 -86
  405. package/plugin/skills/visual-qa/scripts/png-crc.ts +16 -16
  406. package/plugin/skills/visual-qa/scripts/png-decode.ts +167 -167
  407. package/plugin/skills/visual-qa/scripts/png-synth.ts +36 -40
  408. package/plugin/skills/visual-qa/scripts/tui-grid.ts +63 -63
  409. package/plugin/skills/visual-qa/scripts/types.ts +37 -37
  410. package/plugin/skills/visual-qa/scripts/visual-qa.mjs +268 -289
@@ -28,8 +28,13 @@ const isFactElement = (name, attrs) => FACT_TAGS.has(name) && (attrs["data-fact"
28
28
 
29
29
  /** Each fact span of the markup as {id, start, end, html}, in order; an unclosed one runs to the end. */
30
30
  export function factSpans(markup) {
31
- const src = String(markup)
32
- return elementSpans(src, isFactElement).map(({ start, end, tag }) => ({ id: tag.attrs["data-fact"], start, end, html: src.slice(start, end) }))
31
+ const src = String(markup)
32
+ return elementSpans(src, isFactElement).map(({ start, end, tag }) => ({
33
+ id: tag.attrs["data-fact"],
34
+ start,
35
+ end,
36
+ html: src.slice(start, end),
37
+ }))
33
38
  }
34
39
 
35
40
  /**
@@ -38,57 +43,62 @@ export function factSpans(markup) {
38
43
  * with the markup rules; no second tag-stripping regex.
39
44
  */
40
45
  export function textOf(html) {
41
- return decodeEntities(markupParts(html).text.join(" ")).replace(/\s+/g, " ")
46
+ return decodeEntities(markupParts(html).text.join(" ")).replace(/\s+/g, " ")
42
47
  }
43
48
 
44
49
  /** The protected projection of (already visible) markup; see the header. */
45
50
  export function project(markup) {
46
- const facts = []
47
- let visible = ""
48
- let masked = ""
49
- let at = 0
50
- for (const span of factSpans(markup)) {
51
- const outside = textOf(markup.slice(at, span.start))
52
- facts.push({ id: span.id, html: span.html.replace(/\s+/g, " ") })
53
- visible += `${outside}${textOf(span.html)}`
54
- masked += `${outside} ${SLOT} `
55
- at = span.end
56
- }
57
- const rest = textOf(markup.slice(at))
58
- const links = tagAttributes(markup).flatMap(({ attrs }) =>
59
- POLISH_LINK_ATTRIBUTES.filter((name) => Object.hasOwn(attrs, name)).map((name) => `${name}=${attrs[name]}`),
60
- )
61
- return { facts, visible: (visible + rest).replace(/\s+/g, " ").trim(), masked: (masked + rest).replace(/\s+/g, " ").trim(), links }
51
+ const facts = []
52
+ let visible = ""
53
+ let masked = ""
54
+ let at = 0
55
+ for (const span of factSpans(markup)) {
56
+ const outside = textOf(markup.slice(at, span.start))
57
+ facts.push({ id: span.id, html: span.html.replace(/\s+/g, " ") })
58
+ visible += `${outside}${textOf(span.html)}`
59
+ masked += `${outside} ${SLOT} `
60
+ at = span.end
61
+ }
62
+ const rest = textOf(markup.slice(at))
63
+ const links = tagAttributes(markup).flatMap(({ attrs }) =>
64
+ POLISH_LINK_ATTRIBUTES.filter((name) => Object.hasOwn(attrs, name)).map((name) => `${name}=${attrs[name]}`),
65
+ )
66
+ return {
67
+ facts,
68
+ visible: (visible + rest).replace(/\s+/g, " ").trim(),
69
+ masked: (masked + rest).replace(/\s+/g, " ").trim(),
70
+ links,
71
+ }
62
72
  }
63
73
 
64
74
  const unitKey = (raw) => (raw === null ? "" : (normalizeUnit(raw) ?? raw.toLowerCase()))
65
75
 
66
76
  /** Ordered numeral keys: a parsed quantity as "value unit" (once), any other digit run as written. */
67
77
  export function numeralKeys(text) {
68
- const quantities = []
69
- for (let found = parseNumeral(text); found !== null; found = parseNumeral(text, found.span[1])) quantities.push(found)
70
- const keys = []
71
- let k = 0
72
- for (const match of text.matchAll(POLISH_DIGITS)) {
73
- while (k < quantities.length && quantities[k].span[1] <= match.index) k++
74
- const quantity = quantities[k]
75
- if (!quantity || quantity.span[0] > match.index) keys.push(match[0])
76
- else if (!quantity.counted) {
77
- quantity.counted = true
78
- keys.push(`${quantity.value}${quantity.range ? `~${quantity.valueEnd}` : ""} ${unitKey(quantity.unitRaw)}`.trim())
79
- }
80
- }
81
- return keys
78
+ const quantities = []
79
+ for (let found = parseNumeral(text); found !== null; found = parseNumeral(text, found.span[1])) quantities.push(found)
80
+ const keys = []
81
+ let k = 0
82
+ for (const match of text.matchAll(POLISH_DIGITS)) {
83
+ while (k < quantities.length && quantities[k].span[1] <= match.index) k++
84
+ const quantity = quantities[k]
85
+ if (!quantity || quantity.span[0] > match.index) keys.push(match[0])
86
+ else if (!quantity.counted) {
87
+ quantity.counted = true
88
+ keys.push(`${quantity.value}${quantity.range ? `~${quantity.valueEnd}` : ""} ${unitKey(quantity.unitRaw)}`.trim())
89
+ }
90
+ }
91
+ return keys
82
92
  }
83
93
 
84
94
  /** term -> occurrence count of each listed term in the text (guard mode of the lexical engine). */
85
95
  export function termCounts(text, terms = guardedTerms()) {
86
- const counts = new Map()
87
- for (const term of terms) {
88
- const n = [...text.matchAll(lexicalPattern(term, "guard"))].length
89
- if (n > 0) counts.set(term, n)
90
- }
91
- return counts
96
+ const counts = new Map()
97
+ for (const term of terms) {
98
+ const n = [...text.matchAll(lexicalPattern(term, "guard"))].length
99
+ if (n > 0) counts.set(term, n)
100
+ }
101
+ return counts
92
102
  }
93
103
 
94
104
  const add = (into, term, n) => into.set(term, (into.get(term) ?? 0) + n)
@@ -100,26 +110,26 @@ const add = (into, term, n) => into.set(term, (into.get(term) ?? 0) + n)
100
110
  * qualifier forms name. A ledger term the sentence never held is never required.
101
111
  */
102
112
  export function requiredTerms(projection, rows) {
103
- const required = new Map()
104
- let cursor = 0
105
- for (const { text } of splitSentences(projection.masked)) {
106
- const slots = text.split(SLOT).length - 1
107
- const facts = projection.facts.slice(cursor, cursor + slots)
108
- cursor += slots
109
- const present = termCounts(text)
110
- const sourced = new Set()
111
- for (const { id } of facts) {
112
- const row = rows.get(id)
113
- for (const term of termCounts(row?.quote ?? "", HEDGES).keys()) sourced.add(term)
114
- for (const form of QUALIFIER_FORMS[row?.qualifier] ?? []) sourced.add(form)
115
- }
116
- for (const [term, n] of present) if (slots === 0 || sourced.has(term)) add(required, term, n)
117
- }
118
- return required
113
+ const required = new Map()
114
+ let cursor = 0
115
+ for (const { text } of splitSentences(projection.masked)) {
116
+ const slots = text.split(SLOT).length - 1
117
+ const facts = projection.facts.slice(cursor, cursor + slots)
118
+ cursor += slots
119
+ const present = termCounts(text)
120
+ const sourced = new Set()
121
+ for (const { id } of facts) {
122
+ const row = rows.get(id)
123
+ for (const term of termCounts(row?.quote ?? "", HEDGES).keys()) sourced.add(term)
124
+ for (const form of QUALIFIER_FORMS[row?.qualifier] ?? []) sourced.add(form)
125
+ }
126
+ for (const [term, n] of present) if (slots === 0 || sourced.has(term)) add(required, term, n)
127
+ }
128
+ return required
119
129
  }
120
130
 
121
131
  /** Required terms the text no longer holds as many times, as "term" names. */
122
132
  export function missingTerms(required, text) {
123
- const have = termCounts(text, [...required.keys()])
124
- return [...required].filter(([term, n]) => (have.get(term) ?? 0) < n).map(([term]) => term)
133
+ const have = termCounts(text, [...required.keys()])
134
+ return [...required].filter(([term, n]) => (have.get(term) ?? 0) < n).map(([term]) => term)
125
135
  }
@@ -28,7 +28,13 @@ import { splitSentences } from "./sentence-split.mjs"
28
28
  import { normalizeText } from "./text-normalize.mjs"
29
29
 
30
30
  /** The codes polishDefects can emit, in report order. */
31
- export const POLISH_CODES = Object.freeze(["polish_diff_fail", "polish_hedging_decreased", "polish_text_churn", "polish_link_changed", "polish_name_changed"])
31
+ export const POLISH_CODES = Object.freeze([
32
+ "polish_diff_fail",
33
+ "polish_hedging_decreased",
34
+ "polish_text_churn",
35
+ "polish_link_changed",
36
+ "polish_name_changed",
37
+ ])
32
38
  export const TICKER = /(?<![\p{L}\p{N}])(?:[A-Z]{1,5}(?:\.[A-Z]{1,2})?|\d{6})(?![\p{L}\p{N}])/gu
33
39
  /** The capitalized-token heuristic for proper nouns in ledger quotes. */
34
40
  export const POLISH_NAME = /\p{Lu}[\p{L}\p{N}&'-]+/gu
@@ -42,86 +48,94 @@ const same = (a, b) => a.length === b.length && a.every((item, k) => item === b[
42
48
 
43
49
  /** null when unchanged; a reorder counts only when ordered. */
44
50
  function listChange(label, before, after, ordered) {
45
- if (same(before, after)) return null
46
- const remaining = sorted(before)
47
- const added = []
48
- for (const item of after) {
49
- const at = remaining.indexOf(item)
50
- if (at === -1) added.push(item)
51
- else remaining.splice(at, 1)
52
- }
53
- if (remaining.length > 0 || added.length > 0) return `${label} changed: removed [${remaining.join(", ")}], added [${added.join(", ")}]`
54
- return ordered ? `${label} reordered: [${before.join(", ")}] became [${after.join(", ")}]` : null
51
+ if (same(before, after)) return null
52
+ const remaining = sorted(before)
53
+ const added = []
54
+ for (const item of after) {
55
+ const at = remaining.indexOf(item)
56
+ if (at === -1) added.push(item)
57
+ else remaining.splice(at, 1)
58
+ }
59
+ if (remaining.length > 0 || added.length > 0)
60
+ return `${label} changed: removed [${remaining.join(", ")}], added [${added.join(", ")}]`
61
+ return ordered ? `${label} reordered: [${before.join(", ")}] became [${after.join(", ")}]` : null
55
62
  }
56
63
 
57
- const tableRows = (html) => html.split(/<table\b/i).slice(1).map((part) => (part.split(/<\/table\s*>/i)[0].match(/<tr\b/gi) ?? []).length)
64
+ const tableRows = (html) =>
65
+ html
66
+ .split(/<table\b/i)
67
+ .slice(1)
68
+ .map((part) => (part.split(/<\/table\s*>/i)[0].match(/<tr\b/gi) ?? []).length)
58
69
 
59
70
  function levenshtein(a, b) {
60
- if (a === b) return 0
61
- if (a.length * b.length > DISTANCE_CELLS) return Math.max(a.length, b.length)
62
- let previous = Array.from({ length: b.length + 1 }, (_, k) => k)
63
- for (let i = 1; i <= a.length; i++) {
64
- const current = [i]
65
- for (let j = 1; j <= b.length; j++) {
66
- current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1))
67
- }
68
- previous = current
69
- }
70
- return previous[b.length]
71
+ if (a === b) return 0
72
+ if (a.length * b.length > DISTANCE_CELLS) return Math.max(a.length, b.length)
73
+ let previous = Array.from({ length: b.length + 1 }, (_, k) => k)
74
+ for (let i = 1; i <= a.length; i++) {
75
+ const current = [i]
76
+ for (let j = 1; j <= b.length; j++) {
77
+ current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1))
78
+ }
79
+ previous = current
80
+ }
81
+ return previous[b.length]
71
82
  }
72
83
 
73
84
  /** Changed share of normalized prose: edit distance over unmatched sentence runs / longer length. */
74
85
  export function churnRatio(beforeText, afterText) {
75
- const [a, b] = [normalizeText(beforeText), normalizeText(afterText)]
76
- const longest = Math.max(a.length, b.length)
77
- if (longest === 0) return 0
78
- const [sa, sb] = [splitSentences(a).map((s) => s.text), splitSentences(b).map((s) => s.text)]
79
- const lcs = Array.from({ length: sa.length + 1 }, () => new Array(sb.length + 1).fill(0))
80
- for (let i = sa.length - 1; i >= 0; i--) {
81
- for (let j = sb.length - 1; j >= 0; j--) lcs[i][j] = sa[i] === sb[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1])
82
- }
83
- let distance = 0
84
- let gap = [[], []]
85
- const flush = () => {
86
- distance += levenshtein(gap[0].join(" "), gap[1].join(" "))
87
- gap = [[], []]
88
- }
89
- let [i, j] = [0, 0]
90
- while (i < sa.length || j < sb.length) {
91
- if (i < sa.length && j < sb.length && sa[i] === sb[j]) {
92
- flush()
93
- i++
94
- j++
95
- } else if (j >= sb.length || (i < sa.length && lcs[i + 1][j] >= lcs[i][j + 1])) gap[0].push(sa[i++])
96
- else gap[1].push(sb[j++])
97
- }
98
- flush()
99
- return distance / longest
86
+ const [a, b] = [normalizeText(beforeText), normalizeText(afterText)]
87
+ const longest = Math.max(a.length, b.length)
88
+ if (longest === 0) return 0
89
+ const [sa, sb] = [splitSentences(a).map((s) => s.text), splitSentences(b).map((s) => s.text)]
90
+ const lcs = Array.from({ length: sa.length + 1 }, () => new Array(sb.length + 1).fill(0))
91
+ for (let i = sa.length - 1; i >= 0; i--) {
92
+ for (let j = sb.length - 1; j >= 0; j--)
93
+ lcs[i][j] = sa[i] === sb[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1])
94
+ }
95
+ let distance = 0
96
+ let gap = [[], []]
97
+ const flush = () => {
98
+ distance += levenshtein(gap[0].join(" "), gap[1].join(" "))
99
+ gap = [[], []]
100
+ }
101
+ let [i, j] = [0, 0]
102
+ while (i < sa.length || j < sb.length) {
103
+ if (i < sa.length && j < sb.length && sa[i] === sb[j]) {
104
+ flush()
105
+ i++
106
+ j++
107
+ } else if (j >= sb.length || (i < sa.length && lcs[i + 1][j] >= lcs[i][j + 1])) gap[0].push(sa[i++])
108
+ else gap[1].push(sb[j++])
109
+ }
110
+ flush()
111
+ return distance / longest
100
112
  }
101
113
 
102
114
  function linkChange(from, to, before, after, ordered) {
103
- const change = listChange("href and data-claim values", from.links, to.links, ordered)
104
- if (change) return change
105
- const ids = (html) => new Set(tagAttributes(html).flatMap(({ attrs }) => (Object.hasOwn(attrs, "id") ? [attrs.id] : [])))
106
- const [idsBefore, idsAfter] = [ids(before), ids(after)]
107
- const targets = to.links.filter((link) => link.startsWith("href=#")).map((link) => link.slice(5))
108
- const broken = targets.filter((href) => idsBefore.has(href.slice(1)) && !idsAfter.has(href.slice(1)))
109
- return broken.length > 0 ? `internal link targets stopped resolving: [${[...new Set(broken)].join(", ")}]` : null
115
+ const change = listChange("href and data-claim values", from.links, to.links, ordered)
116
+ if (change) return change
117
+ const ids = (html) =>
118
+ new Set(tagAttributes(html).flatMap(({ attrs }) => (Object.hasOwn(attrs, "id") ? [attrs.id] : [])))
119
+ const [idsBefore, idsAfter] = [ids(before), ids(after)]
120
+ const targets = to.links.filter((link) => link.startsWith("href=#")).map((link) => link.slice(5))
121
+ const broken = targets.filter((href) => idsBefore.has(href.slice(1)) && !idsAfter.has(href.slice(1)))
122
+ return broken.length > 0 ? `internal link targets stopped resolving: [${[...new Set(broken)].join(", ")}]` : null
110
123
  }
111
124
 
112
125
  /** Capitalized tokens of the ledger quotes, minus each sentence's first word. */
113
126
  function ledgerNames(rows) {
114
- const names = new Set()
115
- for (const row of rows) {
116
- for (const { text } of splitSentences(row.quote ?? "")) {
117
- const first = text.match(/^\P{L}*\p{L}+/u)?.[0].length ?? 0
118
- for (const match of text.matchAll(POLISH_NAME)) if (match.index >= first) names.add(match[0])
119
- }
120
- }
121
- return names
127
+ const names = new Set()
128
+ for (const row of rows) {
129
+ for (const { text } of splitSentences(row.quote ?? "")) {
130
+ const first = text.match(/^\P{L}*\p{L}+/u)?.[0].length ?? 0
131
+ for (const match of text.matchAll(POLISH_NAME)) if (match.index >= first) names.add(match[0])
132
+ }
133
+ }
134
+ return names
122
135
  }
123
136
 
124
- const hasWord = (text, word) => new RegExp(`(?<![\\p{L}\\p{N}])${word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\p{L}\\p{N}])`, "u").test(text)
137
+ const hasWord = (text, word) =>
138
+ new RegExp(`(?<![\\p{L}\\p{N}])${word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\p{L}\\p{N}])`, "u").test(text)
125
139
 
126
140
  /**
127
141
  * @param {string} beforeHtml
@@ -131,40 +145,46 @@ const hasWord = (text, word) => new RegExp(`(?<![\\p{L}\\p{N}])${word.replace(/[
131
145
  * @returns {{ code: string, message: string }[]} in POLISH_CODES order
132
146
  */
133
147
  export function polishDefects(beforeHtml, afterHtml, ledger, { ordered = false } = {}) {
134
- const ambiguous = [...new Set([...ambiguousMarkup(beforeHtml), ...ambiguousMarkup(afterHtml)])]
135
- if (ambiguous.length > 0) return [{ code: "polish_diff_fail", message: `ambiguous markup: ${ambiguous.join(", ")}` }]
136
- const [beforeParts, afterParts] = [markupParts(beforeHtml), markupParts(afterHtml)]
137
- const [before, after] = [beforeParts.source, afterParts.source]
138
- const [from, to] = [project(before), project(after)]
139
- const rows = ledger?.rows ?? []
140
- const defects = []
141
- const note = (code, message) => message && defects.push({ code, message })
142
- const factKey = (fact) => `${fact.id} ${fact.html}`
143
- const tickers = (text) => text.match(TICKER) ?? []
144
- const markupEqual = same(beforeParts.markup, afterParts.markup)
145
- note("polish_diff_fail", markupEqual ? null : "markup changed")
146
- note("polish_diff_fail", skeletonChange(beforeHtml, afterHtml))
147
- note("polish_diff_fail", listChange("fact spans", from.facts.map(factKey), to.facts.map(factKey), ordered))
148
- note("polish_diff_fail", listChange("numerals outside fact spans", numeralKeys(from.masked), numeralKeys(to.masked), ordered))
149
- note("polish_diff_fail", listChange("tickers", tickers(from.masked), tickers(to.masked), ordered))
150
- const [rowsBefore, rowsAfter] = [tableRows(before), tableRows(after)]
151
- if (!same(rowsBefore, rowsAfter)) note("polish_diff_fail", `table row counts changed: [${rowsBefore}] became [${rowsAfter}]`)
152
- const required = requiredTerms(from, new Map(rows.map((row) => [row.fact_id, row])))
153
- if (markupEqual) {
154
- for (const [index, raw] of beforeParts.text.entries()) {
155
- const [a, b] = [raw, afterParts.text[index]].map(textOf)
156
- note("polish_diff_fail", listChange("text-node numerals", numeralKeys(a), numeralKeys(b), ordered))
157
- note("polish_diff_fail", listChange("text-node tickers", tickers(a), tickers(b), ordered))
158
- const lost = missingTerms(termCounts(a, [...required.keys()]), b)
159
- if (lost.length) note("polish_hedging_decreased", `text-node hedges removed: ${lost.join(", ")}`)
160
- }
161
- }
162
- const missing = missingTerms(required, to.visible)
163
- if (missing.length > 0) note("polish_hedging_decreased", `hedges or qualifiers removed: ${missing.map((term) => `"${term}"`).join(", ")}`)
164
- const ratio = churnRatio(from.visible, to.visible)
165
- if (ratio > POLISH_CHURN_LIMIT) note("polish_text_churn", `${(ratio * 100).toFixed(1)} percent of the normalized prose changed`)
166
- note("polish_link_changed", linkChange(from, to, before, after, ordered))
167
- const lost = [...ledgerNames(rows)].filter((name) => hasWord(from.visible, name) && !hasWord(to.visible, name))
168
- if (lost.length > 0) note("polish_name_changed", `ledger-quote names missing after polish: ${lost.join(", ")}`)
169
- return defects.sort((a, b) => POLISH_CODES.indexOf(a.code) - POLISH_CODES.indexOf(b.code))
148
+ const ambiguous = [...new Set([...ambiguousMarkup(beforeHtml), ...ambiguousMarkup(afterHtml)])]
149
+ if (ambiguous.length > 0) return [{ code: "polish_diff_fail", message: `ambiguous markup: ${ambiguous.join(", ")}` }]
150
+ const [beforeParts, afterParts] = [markupParts(beforeHtml), markupParts(afterHtml)]
151
+ const [before, after] = [beforeParts.source, afterParts.source]
152
+ const [from, to] = [project(before), project(after)]
153
+ const rows = ledger?.rows ?? []
154
+ const defects = []
155
+ const note = (code, message) => message && defects.push({ code, message })
156
+ const factKey = (fact) => `${fact.id} ${fact.html}`
157
+ const tickers = (text) => text.match(TICKER) ?? []
158
+ const markupEqual = same(beforeParts.markup, afterParts.markup)
159
+ note("polish_diff_fail", markupEqual ? null : "markup changed")
160
+ note("polish_diff_fail", skeletonChange(beforeHtml, afterHtml))
161
+ note("polish_diff_fail", listChange("fact spans", from.facts.map(factKey), to.facts.map(factKey), ordered))
162
+ note(
163
+ "polish_diff_fail",
164
+ listChange("numerals outside fact spans", numeralKeys(from.masked), numeralKeys(to.masked), ordered),
165
+ )
166
+ note("polish_diff_fail", listChange("tickers", tickers(from.masked), tickers(to.masked), ordered))
167
+ const [rowsBefore, rowsAfter] = [tableRows(before), tableRows(after)]
168
+ if (!same(rowsBefore, rowsAfter))
169
+ note("polish_diff_fail", `table row counts changed: [${rowsBefore}] became [${rowsAfter}]`)
170
+ const required = requiredTerms(from, new Map(rows.map((row) => [row.fact_id, row])))
171
+ if (markupEqual) {
172
+ for (const [index, raw] of beforeParts.text.entries()) {
173
+ const [a, b] = [raw, afterParts.text[index]].map(textOf)
174
+ note("polish_diff_fail", listChange("text-node numerals", numeralKeys(a), numeralKeys(b), ordered))
175
+ note("polish_diff_fail", listChange("text-node tickers", tickers(a), tickers(b), ordered))
176
+ const lost = missingTerms(termCounts(a, [...required.keys()]), b)
177
+ if (lost.length) note("polish_hedging_decreased", `text-node hedges removed: ${lost.join(", ")}`)
178
+ }
179
+ }
180
+ const missing = missingTerms(required, to.visible)
181
+ if (missing.length > 0)
182
+ note("polish_hedging_decreased", `hedges or qualifiers removed: ${missing.map((term) => `"${term}"`).join(", ")}`)
183
+ const ratio = churnRatio(from.visible, to.visible)
184
+ if (ratio > POLISH_CHURN_LIMIT)
185
+ note("polish_text_churn", `${(ratio * 100).toFixed(1)} percent of the normalized prose changed`)
186
+ note("polish_link_changed", linkChange(from, to, before, after, ordered))
187
+ const lost = [...ledgerNames(rows)].filter((name) => hasWord(from.visible, name) && !hasWord(to.visible, name))
188
+ if (lost.length > 0) note("polish_name_changed", `ledger-quote names missing after polish: ${lost.join(", ")}`)
189
+ return defects.sort((a, b) => POLISH_CODES.indexOf(a.code) - POLISH_CODES.indexOf(b.code))
170
190
  }
@@ -9,99 +9,100 @@ const DECIMAL = /^([+-]?)(\d+)(?:\.(\d+))?$/
9
9
  const abs = (n) => (n < 0n ? -n : n)
10
10
 
11
11
  function gcd(a, b) {
12
- let x = abs(a)
13
- let y = abs(b)
14
- while (y !== 0n) [x, y] = [y, x % y]
15
- return x
12
+ let x = abs(a)
13
+ let y = abs(b)
14
+ while (y !== 0n) [x, y] = [y, x % y]
15
+ return x
16
16
  }
17
17
 
18
18
  function make(num, den) {
19
- if (den === 0n) throw new RangeError("rational: zero denominator")
20
- const sign = den < 0n ? -1n : 1n
21
- const g = gcd(num, den) || 1n
22
- return Object.freeze({ num: (sign * num) / g, den: (sign * den) / g })
19
+ if (den === 0n) throw new RangeError("rational: zero denominator")
20
+ const sign = den < 0n ? -1n : 1n
21
+ const g = gcd(num, den) || 1n
22
+ return Object.freeze({ num: (sign * num) / g, den: (sign * den) / g })
23
23
  }
24
24
 
25
25
  /** Accepts a rational, a bigint, a safe integer, or a decimal string. */
26
26
  function coerce(value) {
27
- if (typeof value === "bigint") return make(value, 1n)
28
- if (typeof value === "number") {
29
- if (!Number.isSafeInteger(value)) throw new TypeError(`rational: ${value} is not a safe integer; pass a decimal string`)
30
- return make(BigInt(value), 1n)
31
- }
32
- if (typeof value === "string") return fromDecimal(value)
33
- if (value && typeof value.num === "bigint" && typeof value.den === "bigint") return make(value.num, value.den)
34
- throw new TypeError("rational: expected a rational, bigint, integer, or decimal string")
27
+ if (typeof value === "bigint") return make(value, 1n)
28
+ if (typeof value === "number") {
29
+ if (!Number.isSafeInteger(value))
30
+ throw new TypeError(`rational: ${value} is not a safe integer; pass a decimal string`)
31
+ return make(BigInt(value), 1n)
32
+ }
33
+ if (typeof value === "string") return fromDecimal(value)
34
+ if (value && typeof value.num === "bigint" && typeof value.den === "bigint") return make(value.num, value.den)
35
+ throw new TypeError("rational: expected a rational, bigint, integer, or decimal string")
35
36
  }
36
37
 
37
38
  /** "12.50" -> 25/2. Accepts an optional sign, digits, and an optional fraction; nothing else. */
38
39
  export function fromDecimal(str) {
39
- const match = DECIMAL.exec(String(str).trim())
40
- if (!match) throw new SyntaxError(`rational: "${str}" is not a plain decimal`)
41
- const [, sign, whole, frac = ""] = match
42
- const num = BigInt(whole + frac) * (sign === "-" ? -1n : 1n)
43
- return make(num, 10n ** BigInt(frac.length))
40
+ const match = DECIMAL.exec(String(str).trim())
41
+ if (!match) throw new SyntaxError(`rational: "${str}" is not a plain decimal`)
42
+ const [, sign, whole, frac = ""] = match
43
+ const num = BigInt(whole + frac) * (sign === "-" ? -1n : 1n)
44
+ return make(num, 10n ** BigInt(frac.length))
44
45
  }
45
46
 
46
47
  export function add(a, b) {
47
- const x = coerce(a)
48
- const y = coerce(b)
49
- return make(x.num * y.den + y.num * x.den, x.den * y.den)
48
+ const x = coerce(a)
49
+ const y = coerce(b)
50
+ return make(x.num * y.den + y.num * x.den, x.den * y.den)
50
51
  }
51
52
 
52
53
  export function sub(a, b) {
53
- const x = coerce(a)
54
- const y = coerce(b)
55
- return make(x.num * y.den - y.num * x.den, x.den * y.den)
54
+ const x = coerce(a)
55
+ const y = coerce(b)
56
+ return make(x.num * y.den - y.num * x.den, x.den * y.den)
56
57
  }
57
58
 
58
59
  export function mul(a, b) {
59
- const x = coerce(a)
60
- const y = coerce(b)
61
- return make(x.num * y.num, x.den * y.den)
60
+ const x = coerce(a)
61
+ const y = coerce(b)
62
+ return make(x.num * y.num, x.den * y.den)
62
63
  }
63
64
 
64
65
  export function div(a, b) {
65
- const x = coerce(a)
66
- const y = coerce(b)
67
- if (y.num === 0n) throw new RangeError("rational: division by zero")
68
- return make(x.num * y.den, x.den * y.num)
66
+ const x = coerce(a)
67
+ const y = coerce(b)
68
+ if (y.num === 0n) throw new RangeError("rational: division by zero")
69
+ return make(x.num * y.den, x.den * y.num)
69
70
  }
70
71
 
71
72
  export function eq(a, b) {
72
- const x = coerce(a)
73
- const y = coerce(b)
74
- return x.num === y.num && x.den === y.den
73
+ const x = coerce(a)
74
+ const y = coerce(b)
75
+ return x.num === y.num && x.den === y.den
75
76
  }
76
77
 
77
78
  /** Digits of a non-negative integer scaled by 10^-scale, as a decimal string. */
78
79
  function placeDecimal(digits, scale) {
79
- if (scale <= 0) return digits + "0".repeat(-scale)
80
- const padded = digits.padStart(scale + 1, "0")
81
- return `${padded.slice(0, padded.length - scale)}.${padded.slice(padded.length - scale)}`
80
+ if (scale <= 0) return digits + "0".repeat(-scale)
81
+ const padded = digits.padStart(scale + 1, "0")
82
+ return `${padded.slice(0, padded.length - scale)}.${padded.slice(padded.length - scale)}`
82
83
  }
83
84
 
84
85
  /** Exact decimal; throws RangeError when the expansion does not terminate. */
85
86
  function exactDecimal(r) {
86
- let den = r.den
87
- let twos = 0
88
- let fives = 0
89
- while (den % 2n === 0n) [den, twos] = [den / 2n, twos + 1]
90
- while (den % 5n === 0n) [den, fives] = [den / 5n, fives + 1]
91
- if (den !== 1n) throw new RangeError(`rational: ${r.num}/${r.den} has no finite decimal; pass sigFigs`)
92
- const scale = Math.max(twos, fives)
93
- const digits = (abs(r.num) * 10n ** BigInt(scale)) / r.den
94
- return (r.num < 0n ? "-" : "") + placeDecimal(digits.toString(), scale)
87
+ let den = r.den
88
+ let twos = 0
89
+ let fives = 0
90
+ while (den % 2n === 0n) [den, twos] = [den / 2n, twos + 1]
91
+ while (den % 5n === 0n) [den, fives] = [den / 5n, fives + 1]
92
+ if (den !== 1n) throw new RangeError(`rational: ${r.num}/${r.den} has no finite decimal; pass sigFigs`)
93
+ const scale = Math.max(twos, fives)
94
+ const digits = (abs(r.num) * 10n ** BigInt(scale)) / r.den
95
+ return (r.num < 0n ? "-" : "") + placeDecimal(digits.toString(), scale)
95
96
  }
96
97
 
97
98
  /** Number of decimal digits in the integer part of |num/den| (0 when below 1). */
98
99
  function integerDigits(num, den) {
99
- const whole = num / den
100
- if (whole > 0n) return whole.toString().length
101
- let exp = 0
102
- let scaled = num
103
- while (scaled < den) [scaled, exp] = [scaled * 10n, exp - 1]
104
- return exp + 1
100
+ const whole = num / den
101
+ if (whole > 0n) return whole.toString().length
102
+ let exp = 0
103
+ let scaled = num
104
+ while (scaled < den) [scaled, exp] = [scaled * 10n, exp - 1]
105
+ return exp + 1
105
106
  }
106
107
 
107
108
  /**
@@ -110,19 +111,19 @@ function integerDigits(num, den) {
110
111
  * with an exponent, so 319999 at 2 figures renders "320000".
111
112
  */
112
113
  export function toDecimal(value, sigFigs) {
113
- const r = coerce(value)
114
- if (sigFigs === undefined) return exactDecimal(r)
115
- if (!Number.isInteger(sigFigs) || sigFigs < 1) throw new RangeError("rational: sigFigs must be a positive integer")
116
- if (r.num === 0n) return sigFigs > 1 ? `0.${"0".repeat(sigFigs - 1)}` : "0"
117
- const num = abs(r.num)
118
- const scale = sigFigs - integerDigits(num, r.den)
119
- const numer = scale >= 0 ? num * 10n ** BigInt(scale) : num
120
- const denom = scale >= 0 ? r.den : r.den * 10n ** BigInt(-scale)
121
- let digits = numer / denom
122
- let places = scale
123
- if ((numer % denom) * 2n >= denom) digits += 1n
124
- if (digits.toString().length > sigFigs) [digits, places] = [digits / 10n, places - 1]
125
- return (r.num < 0n ? "-" : "") + placeDecimal(digits.toString(), places)
114
+ const r = coerce(value)
115
+ if (sigFigs === undefined) return exactDecimal(r)
116
+ if (!Number.isInteger(sigFigs) || sigFigs < 1) throw new RangeError("rational: sigFigs must be a positive integer")
117
+ if (r.num === 0n) return sigFigs > 1 ? `0.${"0".repeat(sigFigs - 1)}` : "0"
118
+ const num = abs(r.num)
119
+ const scale = sigFigs - integerDigits(num, r.den)
120
+ const numer = scale >= 0 ? num * 10n ** BigInt(scale) : num
121
+ const denom = scale >= 0 ? r.den : r.den * 10n ** BigInt(-scale)
122
+ let digits = numer / denom
123
+ let places = scale
124
+ if ((numer % denom) * 2n >= denom) digits += 1n
125
+ if (digits.toString().length > sigFigs) [digits, places] = [digits / 10n, places - 1]
126
+ return (r.num < 0n ? "-" : "") + placeDecimal(digits.toString(), places)
126
127
  }
127
128
 
128
129
  /**
@@ -131,9 +132,9 @@ export function toDecimal(value, sigFigs) {
131
132
  * after leading zeros counts ("320" -> 3, "100" -> 3, "20" -> 2).
132
133
  */
133
134
  export function sigFigsOf(decimalStr) {
134
- const match = DECIMAL.exec(String(decimalStr).trim())
135
- if (!match) throw new SyntaxError(`rational: "${decimalStr}" is not a plain decimal`)
136
- const [, , whole, frac] = match
137
- const digits = (whole + (frac ?? "")).replace(/^0+/, "")
138
- return Math.max(digits.length, 1)
135
+ const match = DECIMAL.exec(String(decimalStr).trim())
136
+ if (!match) throw new SyntaxError(`rational: "${decimalStr}" is not a plain decimal`)
137
+ const [, , whole, frac] = match
138
+ const digits = (whole + (frac ?? "")).replace(/^0+/, "")
139
+ return Math.max(digits.length, 1)
139
140
  }