omo-ai 5.1.69 → 5.1.71

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 (408) 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/daemon-adopt.js +41 -10
  9. package/bin/lib/daemon-config.js +9 -3
  10. package/bin/lib/daemon-operations.js +11 -3
  11. package/bin/lib/daemon-rollback.js +28 -23
  12. package/bin/lib/daemon-status.js +9 -3
  13. package/bin/lib/daemon.js +18 -3
  14. package/bin/lib/doctor-memory-runtime.js +46 -12
  15. package/bin/lib/doctor-migration.js +65 -38
  16. package/bin/lib/doctor-pi-config.js +8 -3
  17. package/bin/lib/doctor-reflection-lock.js +35 -12
  18. package/bin/lib/doctor.js +64 -49
  19. package/bin/lib/engine-boot.js +3 -1
  20. package/bin/lib/engine-commands.js +11 -1
  21. package/bin/lib/engine-environment.js +8 -1
  22. package/bin/lib/engine-models.js +2 -1
  23. package/bin/lib/engine-prepare.js +18 -3
  24. package/bin/lib/host-status.js +5 -1
  25. package/bin/lib/jsonc-edit.js +10 -6
  26. package/bin/lib/keychain-helper-doctor.js +13 -3
  27. package/bin/lib/launch-spec-mode.js +6 -2
  28. package/bin/lib/launcher.js +31 -19
  29. package/bin/lib/model-chains.js +12 -5
  30. package/bin/lib/npm-dist-tags.js +2 -1
  31. package/bin/lib/package-paths.js +18 -10
  32. package/bin/lib/private-fd-table.js +19 -10
  33. package/bin/lib/process-list.js +26 -0
  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 +57 -43
  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 +148 -0
  66. package/plugin/README.md +9 -1
  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 +1 -1
  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 +2 -2
  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 +3 -3
  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 +2 -2
  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/package.json +1 -1
  94. package/plugin/runtime/agent-toolkit-sdk/sdk.js +2 -2
  95. package/plugin/runtime/ast-grep-mcp/cli.js +26 -5
  96. package/plugin/runtime/ast-grep-mcp/manifest.json +2 -2
  97. package/plugin/runtime/bunshin-ts/sdk.js +4 -4
  98. package/plugin/runtime/category-coverage/index.js +6 -6
  99. package/plugin/runtime/lsp-daemon/dist/.omo-runtime-manifest.json +4 -4
  100. package/plugin/runtime/lsp-daemon/dist/cli.js +8 -2
  101. package/plugin/runtime/lsp-daemon/dist/client.js +8 -2
  102. package/plugin/runtime/lsp-daemon/dist/index.js +8 -2
  103. package/plugin/runtime/rollback-migrate.js +2 -2
  104. package/plugin/runtime/task-config/index.js +3 -3
  105. package/plugin/runtime/thread-sdk/sdk.js +5 -5
  106. package/plugin/scripts/install.mjs +20 -15
  107. package/plugin/skills/ast-grep/references/recipes.md +1 -1
  108. package/plugin/skills/ast-grep/tests/smoke.ps1 +1 -1
  109. package/plugin/skills/ast-grep/tests/smoke.sh +1 -1
  110. package/plugin/skills/browser/runtime/omowright/index.js +16 -16
  111. package/plugin/skills/browser/runtime/omowright/manifest.json +5 -5
  112. package/plugin/skills/browser/runtime/omowright/page-bundle.js +14 -4
  113. package/plugin/skills/browser/scripts/browser-doctor-report.mjs +36 -9
  114. package/plugin/skills/browser/scripts/browser-doctor.mjs +24 -7
  115. package/plugin/skills/browser/scripts/browser-engine-guard.mjs +2 -1
  116. package/plugin/skills/browser/scripts/browser-install.mjs +40 -8
  117. package/plugin/skills/debugging/references/scripts/dap.mjs +280 -170
  118. package/plugin/skills/debugging/references/scripts/fixture-adapter.mjs +104 -42
  119. package/plugin/skills/frontend/scripts/detect/cli.ts +67 -50
  120. package/plugin/skills/frontend/scripts/detect/config.ts +41 -38
  121. package/plugin/skills/frontend/scripts/detect/core/color.ts +109 -94
  122. package/plugin/skills/frontend/scripts/detect/core/page.ts +43 -42
  123. package/plugin/skills/frontend/scripts/detect/core/shadow.ts +38 -29
  124. package/plugin/skills/frontend/scripts/detect/core/source.ts +25 -20
  125. package/plugin/skills/frontend/scripts/detect/detect.ts +63 -45
  126. package/plugin/skills/frontend/scripts/detect/lint.ts +78 -69
  127. package/plugin/skills/frontend/scripts/detect/render/probe-placement.ts +36 -32
  128. package/plugin/skills/frontend/scripts/detect/render/renderer.ts +14 -13
  129. package/plugin/skills/frontend/scripts/detect/render/webview.ts +53 -50
  130. package/plugin/skills/frontend/scripts/detect/report.ts +20 -18
  131. package/plugin/skills/frontend/scripts/detect/rule.ts +21 -21
  132. package/plugin/skills/frontend/scripts/detect/rules/color/ai-color-palette.ts +144 -63
  133. package/plugin/skills/frontend/scripts/detect/rules/color/cream-palette.ts +41 -27
  134. package/plugin/skills/frontend/scripts/detect/rules/color/dark-glow.ts +59 -34
  135. package/plugin/skills/frontend/scripts/detect/rules/color/design-system-color.ts +37 -28
  136. package/plugin/skills/frontend/scripts/detect/rules/color/gradient-text.ts +68 -45
  137. package/plugin/skills/frontend/scripts/detect/rules/color/gray-on-color.ts +34 -25
  138. package/plugin/skills/frontend/scripts/detect/rules/color/index.ts +9 -2
  139. package/plugin/skills/frontend/scripts/detect/rules/color/low-contrast.ts +106 -43
  140. package/plugin/skills/frontend/scripts/detect/rules/color/radial-halo.ts +48 -23
  141. package/plugin/skills/frontend/scripts/detect/rules/color/radial-spotlight-glow.ts +49 -26
  142. package/plugin/skills/frontend/scripts/detect/rules/color/support/animation-opacity.ts +90 -66
  143. package/plugin/skills/frontend/scripts/detect/rules/color/support/color-path.ts +43 -6
  144. package/plugin/skills/frontend/scripts/detect/rules/color/support/contrast-pairs.ts +75 -38
  145. package/plugin/skills/frontend/scripts/detect/rules/color/support/contrast-role.ts +142 -59
  146. package/plugin/skills/frontend/scripts/detect/rules/color/support/glow-forms.ts +93 -44
  147. package/plugin/skills/frontend/scripts/detect/rules/color/support/gradient-samples.ts +115 -114
  148. package/plugin/skills/frontend/scripts/detect/rules/color/support/gradients.ts +77 -66
  149. package/plugin/skills/frontend/scripts/detect/rules/color/support/mockup-roots.ts +178 -48
  150. package/plugin/skills/frontend/scripts/detect/rules/color/support/page-ignore.ts +6 -2
  151. package/plugin/skills/frontend/scripts/detect/rules/color/support/painted-text.ts +171 -108
  152. package/plugin/skills/frontend/scripts/detect/rules/color/support/palette-roles.ts +60 -39
  153. package/plugin/skills/frontend/scripts/detect/rules/color/support/placeholder-contrast.ts +36 -16
  154. package/plugin/skills/frontend/scripts/detect/rules/color/support/stock-accent.ts +48 -18
  155. package/plugin/skills/frontend/scripts/detect/rules/color/support/text-colors.ts +88 -62
  156. package/plugin/skills/frontend/scripts/detect/rules/copy/aphoristic-cadence.ts +25 -15
  157. package/plugin/skills/frontend/scripts/detect/rules/copy/broken-image.ts +20 -12
  158. package/plugin/skills/frontend/scripts/detect/rules/copy/em-dash-overuse.ts +63 -39
  159. package/plugin/skills/frontend/scripts/detect/rules/copy/index.ts +9 -2
  160. package/plugin/skills/frontend/scripts/detect/rules/copy/marketing-buzzword.ts +53 -25
  161. package/plugin/skills/frontend/scripts/detect/rules/copy/numbered-section-labels.ts +49 -28
  162. package/plugin/skills/frontend/scripts/detect/rules/copy/repeated-container-text.ts +80 -47
  163. package/plugin/skills/frontend/scripts/detect/rules/copy/script-error.ts +42 -34
  164. package/plugin/skills/frontend/scripts/detect/rules/copy/skipped-heading.ts +199 -75
  165. package/plugin/skills/frontend/scripts/detect/rules/copy/support/numbered-label.ts +122 -71
  166. package/plugin/skills/frontend/scripts/detect/rules/copy/support/page-text.ts +32 -24
  167. package/plugin/skills/frontend/scripts/detect/rules/copy/theater-slop-phrase.ts +42 -13
  168. package/plugin/skills/frontend/scripts/detect/rules/decoration/blinking-cursor.ts +49 -41
  169. package/plugin/skills/frontend/scripts/detect/rules/decoration/border-accent-on-rounded.ts +10 -10
  170. package/plugin/skills/frontend/scripts/detect/rules/decoration/bounce-easing.ts +87 -68
  171. package/plugin/skills/frontend/scripts/detect/rules/decoration/buried-raster.ts +83 -64
  172. package/plugin/skills/frontend/scripts/detect/rules/decoration/codex-grid-background.ts +29 -29
  173. package/plugin/skills/frontend/scripts/detect/rules/decoration/design-system-radius.ts +33 -26
  174. package/plugin/skills/frontend/scripts/detect/rules/decoration/gpt-thin-border-wide-shadow.ts +61 -58
  175. package/plugin/skills/frontend/scripts/detect/rules/decoration/hard-offset-shadow.ts +25 -23
  176. package/plugin/skills/frontend/scripts/detect/rules/decoration/hero-eyebrow-chip.ts +16 -14
  177. package/plugin/skills/frontend/scripts/detect/rules/decoration/icon-tile-stack.ts +85 -84
  178. package/plugin/skills/frontend/scripts/detect/rules/decoration/index.ts +17 -17
  179. package/plugin/skills/frontend/scripts/detect/rules/decoration/kicker-above-heading.ts +79 -64
  180. package/plugin/skills/frontend/scripts/detect/rules/decoration/marquee.ts +57 -40
  181. package/plugin/skills/frontend/scripts/detect/rules/decoration/organic-clip-path.ts +34 -34
  182. package/plugin/skills/frontend/scripts/detect/rules/decoration/pulsing-dot.ts +92 -58
  183. package/plugin/skills/frontend/scripts/detect/rules/decoration/repeating-stripes-gradient.ts +19 -19
  184. package/plugin/skills/frontend/scripts/detect/rules/decoration/shape-assembled-illustration.ts +59 -53
  185. package/plugin/skills/frontend/scripts/detect/rules/decoration/side-tab.ts +15 -12
  186. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/appearance.ts +89 -85
  187. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/assert-cases.ts +17 -15
  188. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/borders.ts +178 -136
  189. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/clip-geometry.ts +155 -145
  190. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/css-candidates.ts +60 -54
  191. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/curve-samples.ts +51 -48
  192. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/gradient-pattern.ts +43 -34
  193. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/keyframes.ts +118 -113
  194. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/labels.ts +74 -67
  195. package/plugin/skills/frontend/scripts/detect/rules/decoration/support/raster-state.ts +80 -42
  196. package/plugin/skills/frontend/scripts/detect/rules/index.ts +6 -6
  197. package/plugin/skills/frontend/scripts/detect/rules/layout/body-text-viewport-edge.ts +116 -55
  198. package/plugin/skills/frontend/scripts/detect/rules/layout/clipped-overflow-container.ts +22 -9
  199. package/plugin/skills/frontend/scripts/detect/rules/layout/content-hidden-at-rest.ts +113 -52
  200. package/plugin/skills/frontend/scripts/detect/rules/layout/cramped-padding.ts +167 -90
  201. package/plugin/skills/frontend/scripts/detect/rules/layout/edge-flush-cards.ts +82 -41
  202. package/plugin/skills/frontend/scripts/detect/rules/layout/first-viewport-column-overflow.ts +74 -37
  203. package/plugin/skills/frontend/scripts/detect/rules/layout/heading-rhythm.ts +49 -24
  204. package/plugin/skills/frontend/scripts/detect/rules/layout/index.ts +14 -3
  205. package/plugin/skills/frontend/scripts/detect/rules/layout/monotonous-spacing.ts +47 -28
  206. package/plugin/skills/frontend/scripts/detect/rules/layout/nested-cards.ts +66 -31
  207. package/plugin/skills/frontend/scripts/detect/rules/layout/straggler.ts +46 -22
  208. package/plugin/skills/frontend/scripts/detect/rules/layout/support/cards.ts +157 -82
  209. package/plugin/skills/frontend/scripts/detect/rules/layout/support/clipping.ts +98 -50
  210. package/plugin/skills/frontend/scripts/detect/rules/layout/support/declared-mockups.ts +100 -36
  211. package/plugin/skills/frontend/scripts/detect/rules/layout/support/geometry.ts +66 -43
  212. package/plugin/skills/frontend/scripts/detect/rules/layout/support/hidden-interface.ts +56 -24
  213. package/plugin/skills/frontend/scripts/detect/rules/layout/support/layout-cases.ts +23 -8
  214. package/plugin/skills/frontend/scripts/detect/rules/layout/support/line-breaks.ts +28 -16
  215. package/plugin/skills/frontend/scripts/detect/rules/layout/support/motion.ts +88 -56
  216. package/plugin/skills/frontend/scripts/detect/rules/layout/support/padding.ts +106 -68
  217. package/plugin/skills/frontend/scripts/detect/rules/layout/support/rhythm.ts +204 -128
  218. package/plugin/skills/frontend/scripts/detect/rules/layout/text-occlusion.ts +125 -70
  219. package/plugin/skills/frontend/scripts/detect/rules/layout/text-overflow.ts +111 -59
  220. package/plugin/skills/frontend/scripts/detect/rules/layout/unbalanced-heading.ts +27 -16
  221. package/plugin/skills/frontend/scripts/detect/rules/layout/viewport-reflow.ts +38 -23
  222. package/plugin/skills/frontend/scripts/detect/rules/source/ai-color-palette.ts +17 -6
  223. package/plugin/skills/frontend/scripts/detect/rules/source/aphoristic-cadence.ts +19 -9
  224. package/plugin/skills/frontend/scripts/detect/rules/source/border-accent-on-rounded.ts +31 -13
  225. package/plugin/skills/frontend/scripts/detect/rules/source/bounce-easing.ts +41 -16
  226. package/plugin/skills/frontend/scripts/detect/rules/source/broken-image.ts +19 -9
  227. package/plugin/skills/frontend/scripts/detect/rules/source/codex-grid-background.ts +36 -12
  228. package/plugin/skills/frontend/scripts/detect/rules/source/dark-glow.ts +28 -14
  229. package/plugin/skills/frontend/scripts/detect/rules/source/em-dash-overuse.ts +17 -9
  230. package/plugin/skills/frontend/scripts/detect/rules/source/gradient-text.ts +14 -6
  231. package/plugin/skills/frontend/scripts/detect/rules/source/gray-on-color.ts +18 -7
  232. package/plugin/skills/frontend/scripts/detect/rules/source/index.ts +18 -1
  233. package/plugin/skills/frontend/scripts/detect/rules/source/marketing-buzzword.ts +49 -11
  234. package/plugin/skills/frontend/scripts/detect/rules/source/marquee.ts +16 -6
  235. package/plugin/skills/frontend/scripts/detect/rules/source/monotonous-spacing.ts +35 -17
  236. package/plugin/skills/frontend/scripts/detect/rules/source/overused-font.ts +51 -10
  237. package/plugin/skills/frontend/scripts/detect/rules/source/radial-halo.ts +16 -8
  238. package/plugin/skills/frontend/scripts/detect/rules/source/side-tab.ts +88 -47
  239. package/plugin/skills/frontend/scripts/detect/rules/source/support/accent-scans.ts +103 -62
  240. package/plugin/skills/frontend/scripts/detect/rules/source/support/check-source.ts +6 -2
  241. package/plugin/skills/frontend/scripts/detect/rules/source/support/corners.ts +148 -80
  242. package/plugin/skills/frontend/scripts/detect/rules/source/support/css-effects.ts +86 -66
  243. package/plugin/skills/frontend/scripts/detect/rules/source/support/css-scopes.ts +148 -113
  244. package/plugin/skills/frontend/scripts/detect/rules/source/support/image-tags.ts +113 -105
  245. package/plugin/skills/frontend/scripts/detect/rules/source/support/js-punctuation.ts +47 -30
  246. package/plugin/skills/frontend/scripts/detect/rules/source/support/markup-scope.ts +45 -34
  247. package/plugin/skills/frontend/scripts/detect/rules/source/support/source-color.ts +64 -29
  248. package/plugin/skills/frontend/scripts/detect/rules/source/support/source-shadow.ts +17 -10
  249. package/plugin/skills/frontend/scripts/detect/rules/source/support/source-text.ts +128 -86
  250. package/plugin/skills/frontend/scripts/detect/rules/typography/all-caps-body.ts +23 -9
  251. package/plugin/skills/frontend/scripts/detect/rules/typography/design-system-font-size.ts +27 -17
  252. package/plugin/skills/frontend/scripts/detect/rules/typography/design-system-font.ts +27 -17
  253. package/plugin/skills/frontend/scripts/detect/rules/typography/extreme-negative-tracking.ts +26 -12
  254. package/plugin/skills/frontend/scripts/detect/rules/typography/flat-type-hierarchy.ts +41 -19
  255. package/plugin/skills/frontend/scripts/detect/rules/typography/index.ts +14 -3
  256. package/plugin/skills/frontend/scripts/detect/rules/typography/italic-serif-display.ts +67 -16
  257. package/plugin/skills/frontend/scripts/detect/rules/typography/justified-text.ts +47 -25
  258. package/plugin/skills/frontend/scripts/detect/rules/typography/line-length.ts +37 -21
  259. package/plugin/skills/frontend/scripts/detect/rules/typography/oversized-h1.ts +35 -14
  260. package/plugin/skills/frontend/scripts/detect/rules/typography/overused-font.ts +83 -38
  261. package/plugin/skills/frontend/scripts/detect/rules/typography/support/drawn-enlargement.ts +68 -40
  262. package/plugin/skills/frontend/scripts/detect/rules/typography/support/fading-text.ts +59 -39
  263. package/plugin/skills/frontend/scripts/detect/rules/typography/support/flex-runs.ts +13 -8
  264. package/plugin/skills/frontend/scripts/detect/rules/typography/support/font-family.ts +68 -17
  265. package/plugin/skills/frontend/scripts/detect/rules/typography/support/painted-text.ts +173 -67
  266. package/plugin/skills/frontend/scripts/detect/rules/typography/support/svg-size.ts +56 -49
  267. package/plugin/skills/frontend/scripts/detect/rules/typography/support/text-context.ts +155 -78
  268. package/plugin/skills/frontend/scripts/detect/rules/typography/support/text-lines.ts +38 -28
  269. package/plugin/skills/frontend/scripts/detect/rules/typography/support/type-hierarchy.ts +43 -38
  270. package/plugin/skills/frontend/scripts/detect/rules/typography/tight-leading.ts +67 -39
  271. package/plugin/skills/frontend/scripts/detect/rules/typography/tiny-text.ts +34 -15
  272. package/plugin/skills/frontend/scripts/detect/rules/typography/undersized-ui-text.ts +52 -22
  273. package/plugin/skills/frontend/scripts/detect/rules/typography/wide-tracking.ts +37 -19
  274. package/plugin/skills/frontend/scripts/detect/snapshot/collect.ts +154 -145
  275. package/plugin/skills/frontend/scripts/detect/snapshot/style-props.ts +121 -21
  276. package/plugin/skills/frontend/scripts/detect/testing/build-snapshot.ts +140 -65
  277. package/plugin/skills/frontend/scripts/detect/types.ts +81 -76
  278. package/plugin/skills/frontend/scripts/perfection/accent-stripes/color.ts +205 -85
  279. package/plugin/skills/frontend/scripts/perfection/accent-stripes/css-parse.ts +97 -80
  280. package/plugin/skills/frontend/scripts/perfection/accent-stripes/declarations.ts +129 -101
  281. package/plugin/skills/frontend/scripts/perfection/accent-stripes/findings.ts +23 -23
  282. package/plugin/skills/frontend/scripts/perfection/accent-stripes/gradient.ts +43 -42
  283. package/plugin/skills/frontend/scripts/perfection/accent-stripes/lint.ts +75 -60
  284. package/plugin/skills/frontend/scripts/perfection/accent-stripes/markup.ts +131 -106
  285. package/plugin/skills/frontend/scripts/perfection/accent-stripes/selector.ts +28 -25
  286. package/plugin/skills/frontend/scripts/perfection/accent-stripes/tailwind.ts +93 -78
  287. package/plugin/skills/frontend/scripts/perfection/check-accent-stripes.ts +22 -22
  288. package/plugin/skills/frontend/scripts/perfection/check-draft-guard.ts +24 -24
  289. package/plugin/skills/frontend/scripts/perfection/collect-files.ts +49 -36
  290. package/plugin/skills/frontend/scripts/perfection/draft-guard/findings.ts +10 -9
  291. package/plugin/skills/frontend/scripts/perfection/draft-guard/lint.ts +27 -24
  292. package/plugin/skills/frontend/scripts/perfection/draft-guard/rules.ts +46 -42
  293. package/plugin/skills/frontend/scripts/perfection/draft-guard/text-nodes.ts +98 -75
  294. package/plugin/skills/lsp-setup/scripts/detect-lsp.ts +162 -152
  295. package/plugin/skills/lsp-setup/scripts/lsp-server-table.ts +164 -164
  296. package/plugin/skills/lsp-setup/scripts/verify-lsp.ts +94 -91
  297. package/plugin/skills/programming/SKILL.md +2 -2
  298. package/plugin/skills/programming/scripts/go/new-project.ts +68 -68
  299. package/plugin/skills/programming/scripts/python/new-project.ts +64 -64
  300. package/plugin/skills/programming/scripts/python/new-script.ts +39 -39
  301. package/plugin/skills/programming/scripts/rust/new-project.ts +60 -57
  302. package/plugin/skills/programming/scripts/shared/run-tool.ts +7 -7
  303. package/plugin/skills/programming/scripts/typescript/check-no-excuse-rules.ts +96 -36
  304. package/plugin/skills/programming/scripts/typescript/check-test-junk-rules.ts +38 -17
  305. package/plugin/skills/programming/scripts/typescript/check-test-junk.ts +13 -2
  306. package/plugin/skills/programming/scripts/typescript/mutation-proof.ts +16 -4
  307. package/plugin/skills/programming/scripts/typescript/new-project.ts +21 -21
  308. package/plugin/skills/ultimate-browsing/engine/templates/playwright_mobile_chrome.js +65 -62
  309. package/plugin/skills/ultimate-browsing/engine/templates/playwright_real_chrome.js +73 -70
  310. package/plugin/skills/ulw-plan/scripts/plan-templates.mjs +30 -30
  311. package/plugin/skills/ulw-plan/scripts/scaffold-plan.mjs +131 -123
  312. package/plugin/skills/ulw-research/scripts/claim-kinds.mjs +178 -67
  313. package/plugin/skills/ulw-research/scripts/claims-index.mjs +117 -93
  314. package/plugin/skills/ulw-research/scripts/cli-support.mjs +73 -73
  315. package/plugin/skills/ulw-research/scripts/contracts.mjs +604 -174
  316. package/plugin/skills/ulw-research/scripts/conversion-probe.mjs +161 -113
  317. package/plugin/skills/ulw-research/scripts/css-hiding.mjs +126 -92
  318. package/plugin/skills/ulw-research/scripts/css-lite.mjs +143 -137
  319. package/plugin/skills/ulw-research/scripts/design-spec.mjs +123 -107
  320. package/plugin/skills/ulw-research/scripts/entities.mjs +66 -30
  321. package/plugin/skills/ulw-research/scripts/entry-guard.mjs +8 -8
  322. package/plugin/skills/ulw-research/scripts/fact-commands-fill.mjs +104 -51
  323. package/plugin/skills/ulw-research/scripts/fact-commands-meaning.mjs +207 -105
  324. package/plugin/skills/ulw-research/scripts/fact-commands-polish.mjs +143 -76
  325. package/plugin/skills/ulw-research/scripts/fact-commands-verify.mjs +164 -120
  326. package/plugin/skills/ulw-research/scripts/fact-commands.mjs +264 -151
  327. package/plugin/skills/ulw-research/scripts/fact-derive.mjs +92 -48
  328. package/plugin/skills/ulw-research/scripts/fact-expr.mjs +90 -78
  329. package/plugin/skills/ulw-research/scripts/fact-fill.mjs +215 -127
  330. package/plugin/skills/ulw-research/scripts/fact-ledger-kinds.mjs +305 -131
  331. package/plugin/skills/ulw-research/scripts/fact-ledger-schema.mjs +264 -158
  332. package/plugin/skills/ulw-research/scripts/fact-ledger.mjs +93 -57
  333. package/plugin/skills/ulw-research/scripts/fact-locate.mjs +204 -147
  334. package/plugin/skills/ulw-research/scripts/fact-pairs.mjs +126 -108
  335. package/plugin/skills/ulw-research/scripts/fact-recompute.mjs +89 -66
  336. package/plugin/skills/ulw-research/scripts/fidelity-binding.mjs +101 -70
  337. package/plugin/skills/ulw-research/scripts/fidelity-brief.mjs +95 -89
  338. package/plugin/skills/ulw-research/scripts/fidelity-claims.mjs +76 -48
  339. package/plugin/skills/ulw-research/scripts/fidelity-csv.mjs +27 -27
  340. package/plugin/skills/ulw-research/scripts/fidelity-lexicon.mjs +101 -78
  341. package/plugin/skills/ulw-research/scripts/fidelity-originals.mjs +124 -77
  342. package/plugin/skills/ulw-research/scripts/fidelity-policy.mjs +132 -83
  343. package/plugin/skills/ulw-research/scripts/fidelity-records.mjs +179 -117
  344. package/plugin/skills/ulw-research/scripts/fidelity-snapshot-readability.mjs +38 -33
  345. package/plugin/skills/ulw-research/scripts/fidelity-sources.mjs +92 -54
  346. package/plugin/skills/ulw-research/scripts/fidelity-state.mjs +27 -27
  347. package/plugin/skills/ulw-research/scripts/fidelity-trace.mjs +81 -48
  348. package/plugin/skills/ulw-research/scripts/fidelity-value-unit.mjs +207 -104
  349. package/plugin/skills/ulw-research/scripts/fidelity-values.mjs +255 -154
  350. package/plugin/skills/ulw-research/scripts/format-extract-css.mjs +74 -74
  351. package/plugin/skills/ulw-research/scripts/format-extract.mjs +161 -134
  352. package/plugin/skills/ulw-research/scripts/gates-fidelity.mjs +118 -59
  353. package/plugin/skills/ulw-research/scripts/gates-figures.mjs +192 -141
  354. package/plugin/skills/ulw-research/scripts/gates-layout.mjs +119 -85
  355. package/plugin/skills/ulw-research/scripts/gates-static.mjs +109 -102
  356. package/plugin/skills/ulw-research/scripts/gates-structure.mjs +105 -86
  357. package/plugin/skills/ulw-research/scripts/gates-text.mjs +169 -113
  358. package/plugin/skills/ulw-research/scripts/html-foreign-object.mjs +39 -34
  359. package/plugin/skills/ulw-research/scripts/html-lite.mjs +230 -176
  360. package/plugin/skills/ulw-research/scripts/html-markup.mjs +150 -128
  361. package/plugin/skills/ulw-research/scripts/html-text-map.mjs +125 -96
  362. package/plugin/skills/ulw-research/scripts/layout-probe.mjs +10 -8
  363. package/plugin/skills/ulw-research/scripts/lexicon.mjs +36 -19
  364. package/plugin/skills/ulw-research/scripts/markdown-closers.mjs +85 -85
  365. package/plugin/skills/ulw-research/scripts/md-lite.mjs +133 -125
  366. package/plugin/skills/ulw-research/scripts/meaning-check.mjs +154 -123
  367. package/plugin/skills/ulw-research/scripts/number-grammar.mjs +10 -8
  368. package/plugin/skills/ulw-research/scripts/numerals.mjs +181 -137
  369. package/plugin/skills/ulw-research/scripts/outcome-start.mjs +50 -36
  370. package/plugin/skills/ulw-research/scripts/outcome.mjs +194 -153
  371. package/plugin/skills/ulw-research/scripts/particles-ko.mjs +72 -70
  372. package/plugin/skills/ulw-research/scripts/placeholder.mjs +130 -112
  373. package/plugin/skills/ulw-research/scripts/polish-apply.mjs +67 -51
  374. package/plugin/skills/ulw-research/scripts/polish-diff.mjs +10 -5
  375. package/plugin/skills/ulw-research/scripts/polish-project.mjs +67 -57
  376. package/plugin/skills/ulw-research/scripts/polish-rules.mjs +120 -100
  377. package/plugin/skills/ulw-research/scripts/rational.mjs +74 -73
  378. package/plugin/skills/ulw-research/scripts/raw-decode.mjs +74 -74
  379. package/plugin/skills/ulw-research/scripts/raw-locator.mjs +32 -24
  380. package/plugin/skills/ulw-research/scripts/repair-tracker.mjs +98 -93
  381. package/plugin/skills/ulw-research/scripts/report-tools-commands.mjs +265 -176
  382. package/plugin/skills/ulw-research/scripts/report-tools.mjs +65 -62
  383. package/plugin/skills/ulw-research/scripts/sentence-split.mjs +63 -43
  384. package/plugin/skills/ulw-research/scripts/source-commands.mjs +199 -125
  385. package/plugin/skills/ulw-research/scripts/source-refresh.mjs +91 -54
  386. package/plugin/skills/ulw-research/scripts/source-snapshot.mjs +143 -102
  387. package/plugin/skills/ulw-research/scripts/source-view.mjs +82 -46
  388. package/plugin/skills/ulw-research/scripts/sources-citation.mjs +135 -96
  389. package/plugin/skills/ulw-research/scripts/text-normalize.mjs +63 -48
  390. package/plugin/skills/ulw-research/scripts/text-similarity.mjs +15 -15
  391. package/plugin/skills/ulw-research/scripts/unit-algebra.mjs +98 -66
  392. package/plugin/skills/ulw-research/scripts/unit-errors.mjs +14 -14
  393. package/plugin/skills/ulw-research/scripts/unit-metadata.mjs +30 -14
  394. package/plugin/skills/ulw-research/scripts/unit-pairs.mjs +57 -45
  395. package/plugin/skills/ulw-research/scripts/unit-precision.mjs +39 -25
  396. package/plugin/skills/ulw-research/scripts/unit-rules-shapes.mjs +79 -44
  397. package/plugin/skills/ulw-research/scripts/unit-rules.mjs +262 -135
  398. package/plugin/skills/ulw-research/scripts/units.mjs +96 -65
  399. package/plugin/skills/visual-qa/scripts/ansi.ts +3 -6
  400. package/plugin/skills/visual-qa/scripts/cli.ts +52 -52
  401. package/plugin/skills/visual-qa/scripts/east-asian-width.ts +53 -53
  402. package/plugin/skills/visual-qa/scripts/image-diff.ts +86 -86
  403. package/plugin/skills/visual-qa/scripts/png-crc.ts +16 -16
  404. package/plugin/skills/visual-qa/scripts/png-decode.ts +167 -167
  405. package/plugin/skills/visual-qa/scripts/png-synth.ts +36 -40
  406. package/plugin/skills/visual-qa/scripts/tui-grid.ts +63 -63
  407. package/plugin/skills/visual-qa/scripts/types.ts +37 -37
  408. package/plugin/skills/visual-qa/scripts/visual-qa.mjs +268 -289
@@ -7,29 +7,53 @@ import { existsSync } from "node:fs"
7
7
  import { join } from "node:path"
8
8
 
9
9
  import { CliError, readJsonFile, writeJsonAtomic } from "./cli-support.mjs"
10
- import { DECIMAL, exactComesFromValue, exactFromDecimal, idPrefix, isString, readFlaws, readRow } from "./fact-ledger-kinds.mjs"
11
- import { LEDGER_SCHEMA_VERSION, ROW_DEFAULTS, ROW_FIELDS, transitionError, validateLedger } from "./fact-ledger-schema.mjs"
10
+ import {
11
+ DECIMAL,
12
+ exactComesFromValue,
13
+ exactFromDecimal,
14
+ idPrefix,
15
+ isString,
16
+ readFlaws,
17
+ readRow,
18
+ } from "./fact-ledger-kinds.mjs"
19
+ import {
20
+ LEDGER_SCHEMA_VERSION,
21
+ ROW_DEFAULTS,
22
+ ROW_FIELDS,
23
+ transitionError,
24
+ validateLedger,
25
+ } from "./fact-ledger-schema.mjs"
12
26
  import { normalizeInput } from "./unit-algebra.mjs"
13
27
 
14
28
  export { exactFromDecimal } from "./fact-ledger-kinds.mjs"
15
- export { FACT_KINDS, FACT_STATUSES, LEDGER_SCHEMA_VERSION, OPERATIONS, QUALIFIERS, ROW_FIELDS, TRANSITIONS, transitionError, validateLedger } from "./fact-ledger-schema.mjs"
29
+ export {
30
+ FACT_KINDS,
31
+ FACT_STATUSES,
32
+ LEDGER_SCHEMA_VERSION,
33
+ OPERATIONS,
34
+ QUALIFIERS,
35
+ ROW_FIELDS,
36
+ TRANSITIONS,
37
+ transitionError,
38
+ validateLedger,
39
+ } from "./fact-ledger-schema.mjs"
16
40
 
17
41
  export const LEDGER_FILENAME = "fact-ledger.json"
18
42
 
19
43
  export function emptyLedger() {
20
- return { schemaVersion: LEDGER_SCHEMA_VERSION, rows: [], events: [] }
44
+ return { schemaVersion: LEDGER_SCHEMA_VERSION, rows: [], events: [] }
21
45
  }
22
46
 
23
47
  function assertValid(ledger) {
24
- const errors = validateLedger(ledger)
25
- if (errors.length > 0) throw new CliError(`invalid fact ledger: ${errors.join("; ")}`)
48
+ const errors = validateLedger(ledger)
49
+ if (errors.length > 0) throw new CliError(`invalid fact ledger: ${errors.join("; ")}`)
26
50
  }
27
51
 
28
52
  /** The row's fields in ROW_FIELDS order, then any unknown field (which validation reports). */
29
53
  function ordered(row) {
30
- const out = Object.fromEntries(ROW_FIELDS.filter((key) => Object.hasOwn(row, key)).map((key) => [key, row[key]]))
31
- for (const key of Object.keys(row)) if (!ROW_FIELDS.includes(key)) out[key] = row[key]
32
- return out
54
+ const out = Object.fromEntries(ROW_FIELDS.filter((key) => Object.hasOwn(row, key)).map((key) => [key, row[key]]))
55
+ for (const key of Object.keys(row)) if (!ROW_FIELDS.includes(key)) out[key] = row[key]
56
+ return out
33
57
  }
34
58
 
35
59
  /**
@@ -37,33 +61,33 @@ function ordered(row) {
37
61
  * units and null later columns) before any strict rule runs; the file changes on the next write.
38
62
  */
39
63
  export function readLedger(dir) {
40
- const file = join(dir, LEDGER_FILENAME)
41
- if (!existsSync(file)) return emptyLedger()
42
- const ledger = readJsonFile(file)
43
- assertValid(ledger)
44
- ledger.rows = ledger.rows.map((row) => ordered(readRow(row)))
45
- assertValid(ledger)
46
- return ledger
64
+ const file = join(dir, LEDGER_FILENAME)
65
+ if (!existsSync(file)) return emptyLedger()
66
+ const ledger = readJsonFile(file)
67
+ assertValid(ledger)
68
+ ledger.rows = ledger.rows.map((row) => ordered(readRow(row)))
69
+ assertValid(ledger)
70
+ return ledger
47
71
  }
48
72
 
49
73
  export function writeLedger(dir, ledger) {
50
- assertValid(ledger)
51
- const file = join(dir, LEDGER_FILENAME)
52
- writeJsonAtomic(file, ledger)
53
- return file
74
+ assertValid(ledger)
75
+ const file = join(dir, LEDGER_FILENAME)
76
+ writeJsonAtomic(file, ledger)
77
+ return file
54
78
  }
55
79
 
56
80
  const ID_NUMBER = Object.freeze({ F: /^F(\d+)$/, Q: /^Q(\d+)$/ })
57
81
 
58
82
  /** The next id with the kind's prefix from KIND_RULES (F<n> for value rows, Q<n> for quotes). */
59
83
  export function nextId(ledger, kind) {
60
- const prefix = idPrefix(kind)
61
- let max = 0n
62
- for (const row of ledger.rows) {
63
- const match = ID_NUMBER[prefix].exec(row.fact_id ?? "")
64
- if (match && BigInt(match[1]) > max) max = BigInt(match[1])
65
- }
66
- return `${prefix}${max + 1n}`
84
+ const prefix = idPrefix(kind)
85
+ let max = 0n
86
+ for (const row of ledger.rows) {
87
+ const match = ID_NUMBER[prefix].exec(row.fact_id ?? "")
88
+ if (match && BigInt(match[1]) > max) max = BigInt(match[1])
89
+ }
90
+ return `${prefix}${max + 1n}`
67
91
  }
68
92
 
69
93
  /**
@@ -73,51 +97,63 @@ export function nextId(ledger, kind) {
73
97
  * never one read back from the rounded value.
74
98
  */
75
99
  export function addRow(ledger, row) {
76
- const filled = { ...structuredClone(ROW_DEFAULTS), ...row, fact_id: row.fact_id ?? nextId(ledger, row.kind) }
77
- if (!["derived", "converted"].includes(filled.kind)) {
78
- const normalized = normalizeInput(filled.unit, filled.value)
79
- if (normalized.value !== filled.value && filled.exact !== null) throw new CliError("scaled input must omit exact; it is computed after normalization")
80
- Object.assign(filled, readRow({ ...filled, ...normalized }))
81
- }
82
- if (exactComesFromValue(filled.kind) && filled.exact === null && isString(filled.value) && DECIMAL.test(filled.value)) {
83
- filled.exact = exactFromDecimal(filled.value)
84
- }
85
- const added = ordered(filled)
86
- const flaws = readFlaws(added)
87
- if (flaws.length > 0) throw new CliError(`invalid fact ledger: ${flaws.map((flaw) => `${flaw.shape}: ${flaw.detail}`).join("; ")}`)
88
- assertValid({ ...ledger, rows: [...ledger.rows, added] })
89
- ledger.rows.push(added)
90
- return added
100
+ const filled = { ...structuredClone(ROW_DEFAULTS), ...row, fact_id: row.fact_id ?? nextId(ledger, row.kind) }
101
+ if (!["derived", "converted"].includes(filled.kind)) {
102
+ const normalized = normalizeInput(filled.unit, filled.value)
103
+ if (normalized.value !== filled.value && filled.exact !== null)
104
+ throw new CliError("scaled input must omit exact; it is computed after normalization")
105
+ Object.assign(filled, readRow({ ...filled, ...normalized }))
106
+ }
107
+ if (
108
+ exactComesFromValue(filled.kind) &&
109
+ filled.exact === null &&
110
+ isString(filled.value) &&
111
+ DECIMAL.test(filled.value)
112
+ ) {
113
+ filled.exact = exactFromDecimal(filled.value)
114
+ }
115
+ const added = ordered(filled)
116
+ const flaws = readFlaws(added)
117
+ if (flaws.length > 0)
118
+ throw new CliError(`invalid fact ledger: ${flaws.map((flaw) => `${flaw.shape}: ${flaw.detail}`).join("; ")}`)
119
+ assertValid({ ...ledger, rows: [...ledger.rows, added] })
120
+ ledger.rows.push(added)
121
+ return added
91
122
  }
92
123
 
93
124
  /** Build the event from the row's current status and append it only if transitionError allows it. */
94
125
  function changeStatus(ledger, id, to, replacement, reason) {
95
- const row = ledger.rows.find((candidate) => candidate.fact_id === id)
96
- const event = { fact_id: id, from: row?.status ?? null, to, replacement: replacement ?? null, reason }
97
- const problem = transitionError(new Map(ledger.rows.map((candidate) => [candidate.fact_id, candidate.status])), event)
98
- if (problem) throw new CliError(problem)
99
- ledger.events.push(event)
100
- row.status = to
101
- return row
126
+ const row = ledger.rows.find((candidate) => candidate.fact_id === id)
127
+ const event = { fact_id: id, from: row?.status ?? null, to, replacement: replacement ?? null, reason }
128
+ const problem = transitionError(new Map(ledger.rows.map((candidate) => [candidate.fact_id, candidate.status])), event)
129
+ if (problem) throw new CliError(problem)
130
+ ledger.events.push(event)
131
+ row.status = to
132
+ return row
102
133
  }
103
134
 
104
135
  export function retractRow(ledger, id, reason) {
105
- return changeStatus(ledger, id, "retracted", null, reason)
136
+ return changeStatus(ledger, id, "retracted", null, reason)
106
137
  }
107
138
 
108
139
  export function supersedeRow(ledger, id, replacementId, reason) {
109
- return changeStatus(ledger, id, "superseded", replacementId, reason)
140
+ return changeStatus(ledger, id, "superseded", replacementId, reason)
110
141
  }
111
142
 
112
143
  function cell(value) {
113
- return value === null || value === undefined ? "" : String(value).replace(/\|/g, "\\|").replace(/\n/g, " ")
144
+ return value === null || value === undefined ? "" : String(value).replace(/\|/g, "\\|").replace(/\n/g, " ")
114
145
  }
115
146
 
116
147
  /** The `--view` table: one line per row, retracted and superseded rows included. */
117
148
  export function renderLedgerMarkdown(ledger) {
118
- const lines = ["| fact_id | kind | label | value | unit | source | status | raw |", "|---|---|---|---|---|---|---|---|"]
119
- for (const row of ledger.rows) {
120
- lines.push(`| ${[row.fact_id, row.kind, row.label, row.value, row.unit, row.source_id, row.status, row.raw].map(cell).join(" | ")} |`)
121
- }
122
- return `${lines.join("\n")}\n`
149
+ const lines = [
150
+ "| fact_id | kind | label | value | unit | source | status | raw |",
151
+ "|---|---|---|---|---|---|---|---|",
152
+ ]
153
+ for (const row of ledger.rows) {
154
+ lines.push(
155
+ `| ${[row.fact_id, row.kind, row.label, row.value, row.unit, row.source_id, row.status, row.raw].map(cell).join(" | ")} |`,
156
+ )
157
+ }
158
+ return `${lines.join("\n")}\n`
123
159
  }
@@ -30,116 +30,137 @@ const clean = (token) => token.replace(/^[^\p{L}\p{N}%]+|[^\p{L}\p{N}%]+$/gu, ""
30
30
  const sentenceAt = (sentences, offset) => sentences.find((row) => row.start <= offset && offset < row.end) ?? null
31
31
 
32
32
  function requireSource(sourceId) {
33
- if (!/^S[1-9]\d*$/.test(String(sourceId))) throw new TypeError(`sourceId must be S<n>, got ${sourceId}`)
33
+ if (!/^S[1-9]\d*$/.test(String(sourceId))) throw new TypeError(`sourceId must be S<n>, got ${sourceId}`)
34
34
  }
35
35
 
36
36
  /** Every normalized occurrence of `needle`, as raw [start, end) offsets. */
37
37
  function findAll(text, needle) {
38
- const hits = []
39
- for (let from = 0; from < text.length; ) {
40
- const hit = findNormalized(text.slice(from), needle)
41
- if (!hit) break
42
- hits.push({ start: from + hit.start, end: from + hit.end })
43
- from += hit.start + 1
44
- }
45
- return hits
38
+ const hits = []
39
+ for (let from = 0; from < text.length;) {
40
+ const hit = findNormalized(text.slice(from), needle)
41
+ if (!hit) break
42
+ hits.push({ start: from + hit.start, end: from + hit.end })
43
+ from += hit.start + 1
44
+ }
45
+ return hits
46
46
  }
47
47
 
48
48
  function locatorFor(text, sourceId, start, end, extra = {}) {
49
- const before = text.slice(0, start)
50
- const pageStart = before.lastIndexOf("\f") + 1
51
- const page = text.includes("\f") ? { page: before.split("\f").length } : {}
52
- return { artifact: `${sourceId}/text.txt`, ...page, line: before.slice(pageStart).split("\n").length, char_start: start, char_end: end, ...extra }
49
+ const before = text.slice(0, start)
50
+ const pageStart = before.lastIndexOf("\f") + 1
51
+ const page = text.includes("\f") ? { page: before.split("\f").length } : {}
52
+ return {
53
+ artifact: `${sourceId}/text.txt`,
54
+ ...page,
55
+ line: before.slice(pageStart).split("\n").length,
56
+ char_start: start,
57
+ char_end: end,
58
+ ...extra,
59
+ }
53
60
  }
54
61
 
55
62
  function candidate(text, sentences, start, end) {
56
- return { sentence_id: sentenceAt(sentences, start)?.sid ?? null, char_start: start, char_end: end, context: text.slice(Math.max(0, start - CONTEXT), end + CONTEXT) }
63
+ return {
64
+ sentence_id: sentenceAt(sentences, start)?.sid ?? null,
65
+ char_start: start,
66
+ char_end: end,
67
+ context: text.slice(Math.max(0, start - CONTEXT), end + CONTEXT),
68
+ }
57
69
  }
58
70
 
59
71
  /** A QUALIFIERS token ending within the 2 tokens before the value, or the 1 token right after it. */
60
72
  function qualifierAround(quote, [start, end]) {
61
- const before = quote.slice(0, start).split(/\s+/).filter(Boolean).map(clean)
62
- for (let skip = 0; skip < 2; skip++) {
63
- for (const words of PHRASES) {
64
- const stop = before.length - skip
65
- if (stop - words.length >= 0 && before.slice(stop - words.length, stop).join(" ") === words.join(" ")) return words.join(" ")
66
- }
67
- }
68
- const next = /^\s*(\S+)/.exec(quote.slice(end))
69
- return next && SINGLE_QUALIFIERS.has(clean(next[1])) ? clean(next[1]) : null
73
+ const before = quote.slice(0, start).split(/\s+/).filter(Boolean).map(clean)
74
+ for (let skip = 0; skip < 2; skip++) {
75
+ for (const words of PHRASES) {
76
+ const stop = before.length - skip
77
+ if (stop - words.length >= 0 && before.slice(stop - words.length, stop).join(" ") === words.join(" "))
78
+ return words.join(" ")
79
+ }
80
+ }
81
+ const next = /^\s*(\S+)/.exec(quote.slice(end))
82
+ return next && SINGLE_QUALIFIERS.has(clean(next[1])) ? clean(next[1]) : null
70
83
  }
71
84
 
72
85
  /** A located quantity: `holder` is the quote's { sid, start, end, text }, `numeral` is parsed from holder.text. */
73
86
  function quantityResult(text, sourceId, holder, numeral, extra = {}, unitFallback = null) {
74
- const unit = numeral.unitRaw ? (normalizeUnit(numeral.unitRaw) ?? numeral.unitRaw) : unitFallback
75
- return {
76
- value: numeral.value,
77
- unit,
78
- raw: numeral.raw,
79
- quote: holder.text,
80
- value_span: [numeral.span[0], numeral.span[1]],
81
- sentence_id: holder.sid,
82
- qualifier: qualifierAround(holder.text, numeral.span),
83
- locator: locatorFor(text, sourceId, holder.start, holder.end, extra),
84
- }
87
+ const unit = numeral.unitRaw ? (normalizeUnit(numeral.unitRaw) ?? numeral.unitRaw) : unitFallback
88
+ return {
89
+ value: numeral.value,
90
+ unit,
91
+ raw: numeral.raw,
92
+ quote: holder.text,
93
+ value_span: [numeral.span[0], numeral.span[1]],
94
+ sentence_id: holder.sid,
95
+ qualifier: qualifierAround(holder.text, numeral.span),
96
+ locator: locatorFor(text, sourceId, holder.start, holder.end, extra),
97
+ }
85
98
  }
86
99
 
87
100
  /** --find: one anchor occurrence, then the first numeral starting within 80 chars after it in the same sentence. */
88
101
  export function locateFind(text, { find, unitExpected, sourceId }) {
89
- requireSource(sourceId)
90
- const sentences = indexSentences(text, sourceId)
91
- const hits = findAll(text, find)
92
- if (hits.length === 0) return notLocated()
93
- if (hits.length > 1) return ambiguous(hits.map((hit) => candidate(text, sentences, hit.start, hit.end)))
94
- const [hit] = hits
95
- const sentence = sentenceAt(sentences, hit.start)
96
- if (!sentence || hit.end > sentence.end) return notLocated()
97
- const from = hit.end - sentence.start
98
- const numeral = parseNumeral(sentence.text, from)
99
- if (!numeral || numeral.span[0] - from > FIND_WINDOW) return notLocated([candidate(text, sentences, hit.start, hit.end)])
100
- const result = quantityResult(text, sourceId, sentence, numeral)
101
- if (unitExpected === undefined) return result
102
- const expected = normalizeUnit(unitExpected) ?? unitExpected
103
- return result.unit === expected ? result : { error: "unit_expected_mismatch", expected, found: result.unit, candidates: [result] }
102
+ requireSource(sourceId)
103
+ const sentences = indexSentences(text, sourceId)
104
+ const hits = findAll(text, find)
105
+ if (hits.length === 0) return notLocated()
106
+ if (hits.length > 1) return ambiguous(hits.map((hit) => candidate(text, sentences, hit.start, hit.end)))
107
+ const [hit] = hits
108
+ const sentence = sentenceAt(sentences, hit.start)
109
+ if (!sentence || hit.end > sentence.end) return notLocated()
110
+ const from = hit.end - sentence.start
111
+ const numeral = parseNumeral(sentence.text, from)
112
+ if (!numeral || numeral.span[0] - from > FIND_WINDOW)
113
+ return notLocated([candidate(text, sentences, hit.start, hit.end)])
114
+ const result = quantityResult(text, sourceId, sentence, numeral)
115
+ if (unitExpected === undefined) return result
116
+ const expected = normalizeUnit(unitExpected) ?? unitExpected
117
+ return result.unit === expected
118
+ ? result
119
+ : { error: "unit_expected_mismatch", expected, found: result.unit, candidates: [result] }
104
120
  }
105
121
 
106
122
  /** A row's cells by visual column (a colspan cell repeats). */
107
123
  export function cellsOf(row) {
108
- const cells = []
109
- for (const cell of row.children.filter((child) => child.tag === "td" || child.tag === "th")) {
110
- const span = Math.max(1, Number.parseInt(cell.attrs.colspan ?? "1", 10) || 1)
111
- for (let k = 0; k < span; k++) cells.push(cell)
112
- }
113
- return cells
124
+ const cells = []
125
+ for (const cell of row.children.filter((child) => child.tag === "td" || child.tag === "th")) {
126
+ const span = Math.max(1, Number.parseInt(cell.attrs.colspan ?? "1", 10) || 1)
127
+ for (let k = 0; k < span; k++) cells.push(cell)
128
+ }
129
+ return cells
114
130
  }
115
131
 
116
132
  export function rowsOf(table) {
117
- const rows = []
118
- const walk = (node) => {
119
- for (const child of node.children) {
120
- if (child.tag === "tr") rows.push(child)
121
- else if (child.tag !== "table" && child.tag !== "#text") walk(child)
122
- }
123
- }
124
- walk(table)
125
- return rows
133
+ const rows = []
134
+ const walk = (node) => {
135
+ for (const child of node.children) {
136
+ if (child.tag === "tr") rows.push(child)
137
+ else if (child.tag !== "table" && child.tag !== "#text") walk(child)
138
+ }
139
+ }
140
+ walk(table)
141
+ return rows
126
142
  }
127
143
 
128
144
  function tablesOf(root) {
129
- const tables = []
130
- const walk = (node) => {
131
- for (const child of node.children) {
132
- if (child.tag === "table") tables.push(child)
133
- if (child.tag !== "#text") walk(child)
134
- }
135
- }
136
- walk(root)
137
- return tables.map((table) => {
138
- const rows = rowsOf(table)
139
- const header = rows.find((row) => row.children.some((child) => child.tag === "th")) ?? rows[0]
140
- const caption = table.children.find((child) => child.tag === "caption")
141
- return { table, header, rows: rows.filter((row) => row !== header), caption: caption ? label(proseText(caption)) : null }
142
- })
145
+ const tables = []
146
+ const walk = (node) => {
147
+ for (const child of node.children) {
148
+ if (child.tag === "table") tables.push(child)
149
+ if (child.tag !== "#text") walk(child)
150
+ }
151
+ }
152
+ walk(root)
153
+ return tables.map((table) => {
154
+ const rows = rowsOf(table)
155
+ const header = rows.find((row) => row.children.some((child) => child.tag === "th")) ?? rows[0]
156
+ const caption = table.children.find((child) => child.tag === "caption")
157
+ return {
158
+ table,
159
+ header,
160
+ rows: rows.filter((row) => row !== header),
161
+ caption: caption ? label(proseText(caption)) : null,
162
+ }
163
+ })
143
164
  }
144
165
 
145
166
  const cellLabel = (cell) => label(proseText(cell))
@@ -150,88 +171,124 @@ const indexesOf = (labels, wanted) => labels.flatMap((value, index) => (value ==
150
171
  * never by index. `source` is page html or an extracted view ({ root, text, blocks }) of one.
151
172
  */
152
173
  export function locateTable(source, { table, row, col, sourceId }) {
153
- requireSource(sourceId)
154
- const { root, text, blocks } = typeof source === "string" ? snapshotBlocks(source) : source
155
- const key = label(table)
156
- const tables = tablesOf(root).filter((entry) => entry.table.attrs.id === table || entry.caption === key || (entry.header && cellsOf(entry.header).map(cellLabel).includes(key)))
157
- if (tables.length !== 1) return tables.length === 0 ? notLocated() : ambiguous(tables.map((entry) => ({ table: entry.table.attrs.id ?? entry.caption })))
158
- const [{ header, rows }] = tables
159
- const headerCells = header ? cellsOf(header) : []
160
- const columns = indexesOf(headerCells.map(cellLabel), label(col))
161
- const matches = rows.filter((candidateRow) => cellsOf(candidateRow).length > 0 && cellLabel(cellsOf(candidateRow)[0]) === label(row))
162
- if (columns.length > 1 || matches.length > 1) return ambiguous([...columns.map((index) => ({ col: index })), ...matches.map((match) => ({ row_line: match.line }))])
163
- const cell = columns.length === 1 && matches.length === 1 ? cellsOf(matches[0])[columns[0]] : null
164
- const block = cell ? blocks.find((entry) => entry.node === cell) : null
165
- if (!block) return notLocated()
166
- const holder = { sid: sentenceAt(indexSentences(text, sourceId), block.start)?.sid ?? null, start: block.start, end: block.end, text: text.slice(block.start, block.end) }
167
- const numeral = parseNumeral(holder.text)
168
- if (!numeral) return notLocated()
169
- const headerUnit = /\(([^()]+)\)\s*$/.exec(cellLabel(headerCells[columns[0]]))
170
- return quantityResult(text, sourceId, holder, numeral, { table, row_label: row, col_label: col }, headerUnit ? normalizeUnit(headerUnit[1]) : null)
174
+ requireSource(sourceId)
175
+ const { root, text, blocks } = typeof source === "string" ? snapshotBlocks(source) : source
176
+ const key = label(table)
177
+ const tables = tablesOf(root).filter(
178
+ (entry) =>
179
+ entry.table.attrs.id === table ||
180
+ entry.caption === key ||
181
+ (entry.header && cellsOf(entry.header).map(cellLabel).includes(key)),
182
+ )
183
+ if (tables.length !== 1)
184
+ return tables.length === 0
185
+ ? notLocated()
186
+ : ambiguous(tables.map((entry) => ({ table: entry.table.attrs.id ?? entry.caption })))
187
+ const [{ header, rows }] = tables
188
+ const headerCells = header ? cellsOf(header) : []
189
+ const columns = indexesOf(headerCells.map(cellLabel), label(col))
190
+ const matches = rows.filter(
191
+ (candidateRow) => cellsOf(candidateRow).length > 0 && cellLabel(cellsOf(candidateRow)[0]) === label(row),
192
+ )
193
+ if (columns.length > 1 || matches.length > 1)
194
+ return ambiguous([
195
+ ...columns.map((index) => ({ col: index })),
196
+ ...matches.map((match) => ({ row_line: match.line })),
197
+ ])
198
+ const cell = columns.length === 1 && matches.length === 1 ? cellsOf(matches[0])[columns[0]] : null
199
+ const block = cell ? blocks.find((entry) => entry.node === cell) : null
200
+ if (!block) return notLocated()
201
+ const holder = {
202
+ sid: sentenceAt(indexSentences(text, sourceId), block.start)?.sid ?? null,
203
+ start: block.start,
204
+ end: block.end,
205
+ text: text.slice(block.start, block.end),
206
+ }
207
+ const numeral = parseNumeral(holder.text)
208
+ if (!numeral) return notLocated()
209
+ const headerUnit = /\(([^()]+)\)\s*$/.exec(cellLabel(headerCells[columns[0]]))
210
+ return quantityResult(
211
+ text,
212
+ sourceId,
213
+ holder,
214
+ numeral,
215
+ { table, row_label: row, col_label: col },
216
+ headerUnit ? normalizeUnit(headerUnit[1]) : null,
217
+ )
171
218
  }
172
219
 
173
220
  /** --page/--line: exactly one quantity on that line of that page (pages split on a form feed). */
174
221
  export function locatePageLine(text, { page, line, sourceId }) {
175
- requireSource(sourceId)
176
- const pages = text.split("\f")
177
- if (!Number.isInteger(page) || page < 1 || page > pages.length) return notLocated()
178
- const lines = pages[page - 1].split("\n")
179
- if (!Number.isInteger(line) || line < 1 || line > lines.length) return notLocated()
180
- let start = pages.slice(0, page - 1).reduce((sum, body) => sum + body.length + 1, 0)
181
- for (const body of lines.slice(0, line - 1)) start += body.length + 1
182
- const holder = { start, end: start + lines[line - 1].length, text: lines[line - 1] }
183
- const numerals = []
184
- for (let numeral = parseNumeral(holder.text); numeral; numeral = parseNumeral(holder.text, numeral.span[1])) numerals.push(numeral)
185
- const sentences = indexSentences(text, sourceId)
186
- if (numerals.length !== 1) return numerals.length === 0 ? notLocated() : ambiguous(numerals.map((numeral) => candidate(text, sentences, start + numeral.span[0], start + numeral.span[1])))
187
- holder.sid = sentenceAt(sentences, start + numerals[0].span[0])?.sid ?? null
188
- return quantityResult(text, sourceId, holder, numerals[0])
222
+ requireSource(sourceId)
223
+ const pages = text.split("\f")
224
+ if (!Number.isInteger(page) || page < 1 || page > pages.length) return notLocated()
225
+ const lines = pages[page - 1].split("\n")
226
+ if (!Number.isInteger(line) || line < 1 || line > lines.length) return notLocated()
227
+ let start = pages.slice(0, page - 1).reduce((sum, body) => sum + body.length + 1, 0)
228
+ for (const body of lines.slice(0, line - 1)) start += body.length + 1
229
+ const holder = { start, end: start + lines[line - 1].length, text: lines[line - 1] }
230
+ const numerals = []
231
+ for (let numeral = parseNumeral(holder.text); numeral; numeral = parseNumeral(holder.text, numeral.span[1]))
232
+ numerals.push(numeral)
233
+ const sentences = indexSentences(text, sourceId)
234
+ if (numerals.length !== 1)
235
+ return numerals.length === 0
236
+ ? notLocated()
237
+ : ambiguous(
238
+ numerals.map((numeral) => candidate(text, sentences, start + numeral.span[0], start + numeral.span[1])),
239
+ )
240
+ holder.sid = sentenceAt(sentences, start + numerals[0].span[0])?.sid ?? null
241
+ return quantityResult(text, sourceId, holder, numerals[0])
189
242
  }
190
243
 
191
244
  /** Token-aligned windows of `sentence` whose similarity to `match` reaches the fuzzy floor; best first. */
192
245
  function fuzzyWindow(sentence, match) {
193
- const target = normalizeText(match).length
194
- const wanted = new Set(tokenize(match))
195
- const present = new Set(tokenize(sentence.text))
196
- if (wanted.size === 0 || [...wanted].filter((token) => present.has(token)).length / wanted.size < 0.5) return null
197
- const bounds = [...sentence.text.matchAll(/[\p{L}\p{N}]+/gu)].map((m) => [m.index, m.index + m[0].length])
198
- let best = null
199
- for (let i = 0; i < bounds.length; i++) {
200
- for (let j = i; j < bounds.length; j++) {
201
- const window = sentence.text.slice(bounds[i][0], bounds[j][1])
202
- if (window.length > target * 1.06 + 2) break
203
- if (window.length < target * 0.94 - 2) continue
204
- const score = similarity(window, match)
205
- if (score >= FUZZY_FLOOR && (!best || score > best.score)) best = { score, start: sentence.start + bounds[i][0], end: sentence.start + bounds[j][1] }
206
- }
207
- }
208
- return best
246
+ const target = normalizeText(match).length
247
+ const wanted = new Set(tokenize(match))
248
+ const present = new Set(tokenize(sentence.text))
249
+ if (wanted.size === 0 || [...wanted].filter((token) => present.has(token)).length / wanted.size < 0.5) return null
250
+ const bounds = [...sentence.text.matchAll(/[\p{L}\p{N}]+/gu)].map((m) => [m.index, m.index + m[0].length])
251
+ let best = null
252
+ for (let i = 0; i < bounds.length; i++) {
253
+ for (let j = i; j < bounds.length; j++) {
254
+ const window = sentence.text.slice(bounds[i][0], bounds[j][1])
255
+ if (window.length > target * 1.06 + 2) break
256
+ if (window.length < target * 0.94 - 2) continue
257
+ const score = similarity(window, match)
258
+ if (score >= FUZZY_FLOOR && (!best || score > best.score))
259
+ best = { score, start: sentence.start + bounds[i][0], end: sentence.start + bounds[j][1] }
260
+ }
261
+ }
262
+ return best
209
263
  }
210
264
 
211
265
  function quoteResult(text, sourceId, sentences, start, end, fuzzy) {
212
- const first = sentenceAt(sentences, start)
213
- const last = sentenceAt(sentences, end - 1) ?? first
214
- return {
215
- value: null,
216
- unit: null,
217
- raw: text.slice(start, end),
218
- quote: text.slice(first.start, last.end),
219
- value_span: null,
220
- sentence_id: first.sid,
221
- qualifier: null,
222
- fuzzy,
223
- locator: locatorFor(text, sourceId, first.start, last.end),
224
- }
266
+ const first = sentenceAt(sentences, start)
267
+ const last = sentenceAt(sentences, end - 1) ?? first
268
+ return {
269
+ value: null,
270
+ unit: null,
271
+ raw: text.slice(start, end),
272
+ quote: text.slice(first.start, last.end),
273
+ value_span: null,
274
+ sentence_id: first.sid,
275
+ qualifier: null,
276
+ fuzzy,
277
+ locator: locatorFor(text, sourceId, first.start, last.end),
278
+ }
225
279
  }
226
280
 
227
281
  /** --match: a normalized exact match (fuzzy false), else the one window with similarity >= 0.95 (fuzzy true). */
228
282
  export function locateMatch(text, { match, sourceId }) {
229
- requireSource(sourceId)
230
- const sentences = indexSentences(text, sourceId)
231
- const hits = findAll(text, match)
232
- if (hits.length > 1) return ambiguous(hits.map((hit) => candidate(text, sentences, hit.start, hit.end)))
233
- if (hits.length === 1) return quoteResult(text, sourceId, sentences, hits[0].start, hits[0].end, false)
234
- const windows = sentences.map((sentence) => fuzzyWindow(sentence, match)).filter(Boolean)
235
- if (windows.length > 1) return ambiguous(windows.map((window) => candidate(text, sentences, window.start, window.end)))
236
- return windows.length === 1 ? quoteResult(text, sourceId, sentences, windows[0].start, windows[0].end, true) : notLocated()
283
+ requireSource(sourceId)
284
+ const sentences = indexSentences(text, sourceId)
285
+ const hits = findAll(text, match)
286
+ if (hits.length > 1) return ambiguous(hits.map((hit) => candidate(text, sentences, hit.start, hit.end)))
287
+ if (hits.length === 1) return quoteResult(text, sourceId, sentences, hits[0].start, hits[0].end, false)
288
+ const windows = sentences.map((sentence) => fuzzyWindow(sentence, match)).filter(Boolean)
289
+ if (windows.length > 1)
290
+ return ambiguous(windows.map((window) => candidate(text, sentences, window.start, window.end)))
291
+ return windows.length === 1
292
+ ? quoteResult(text, sourceId, sentences, windows[0].start, windows[0].end, true)
293
+ : notLocated()
237
294
  }