oh-my-opencode 5.1.45 → 5.1.47

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 (370) hide show
  1. package/.agents/command/publish.md +12 -13
  2. package/.agents/skills/publish/SKILL.md +12 -13
  3. package/.opencode/command/publish.md +12 -13
  4. package/README.de.md +0 -5
  5. package/README.es.md +0 -5
  6. package/README.fr.md +0 -5
  7. package/README.it.md +0 -5
  8. package/README.ja.md +0 -5
  9. package/README.ko.md +0 -5
  10. package/README.md +4 -5
  11. package/README.pt-br.md +0 -5
  12. package/README.ru.md +0 -6
  13. package/README.zh-cn.md +0 -5
  14. package/dist/agents/atlas/agent.d.ts +3 -2
  15. package/dist/agents/sisyphus/index.d.ts +1 -0
  16. package/dist/agents/sisyphus/kimi-k3-1.d.ts +9 -0
  17. package/dist/agents/sisyphus-agent-factory.d.ts +1 -1
  18. package/dist/agents/sisyphus-junior/agent.d.ts +1 -1
  19. package/dist/agents/sisyphus-junior/index.d.ts +1 -0
  20. package/dist/agents/sisyphus-junior/kimi-k3-1.d.ts +6 -0
  21. package/dist/agents/types.d.ts +2 -2
  22. package/dist/cli/index.js +91 -163
  23. package/dist/cli/service-auth/keystore.d.ts +8 -3
  24. package/dist/cli-node/index.js +91 -163
  25. package/dist/config-migration/index.d.ts +2 -2
  26. package/dist/config-migration/migration-plans.d.ts +0 -10
  27. package/dist/index.js +1784 -1204
  28. package/dist/skills/ast-grep/AGENTS.md +1 -1
  29. package/dist/skills/browser/runtime/omowright/manifest.json +1 -1
  30. package/dist/skills/frontend/ATTRIBUTION.md +2 -2
  31. package/dist/skills/ultimate-browsing/engine/AGENTS.md +1 -1
  32. package/dist/skills/ulw-research/AGENTS.md +14 -2
  33. package/dist/skills/ulw-research/SKILL.md +37 -12
  34. package/dist/skills/ulw-research/references/deliverable-phase.md +81 -14
  35. package/dist/skills/ulw-research/references/fact-ledger-grammar.md +19 -1
  36. package/dist/skills/ulw-research/references/fact-ledger.md +95 -0
  37. package/dist/skills/ulw-research/references/fidelity-claim-kinds.md +19 -0
  38. package/dist/skills/ulw-research/references/report-gates.md +21 -4
  39. package/dist/skills/ulw-research/references/report-visualization.md +2 -0
  40. package/dist/skills/ulw-research/references/unit-rules.md +157 -0
  41. package/dist/skills/ulw-research/scripts/claim-kinds.mjs +116 -0
  42. package/dist/skills/ulw-research/scripts/claim-kinds.test.ts +193 -0
  43. package/dist/skills/ulw-research/scripts/cli-support.mjs +19 -5
  44. package/dist/skills/ulw-research/scripts/cli-support.test.ts +13 -2
  45. package/dist/skills/ulw-research/scripts/contracts.mjs +27 -6
  46. package/dist/skills/ulw-research/scripts/contracts.test.ts +3 -0
  47. package/dist/skills/ulw-research/scripts/copy-returns-polish.test.ts +209 -0
  48. package/dist/skills/ulw-research/scripts/copy-returns.test.ts +183 -0
  49. package/dist/skills/ulw-research/scripts/delivery-barrier.test.ts +245 -0
  50. package/dist/skills/ulw-research/scripts/fact-commands-meaning.mjs +176 -0
  51. package/dist/skills/ulw-research/scripts/fact-commands-polish.mjs +127 -0
  52. package/dist/skills/ulw-research/scripts/fact-commands-verify.mjs +183 -0
  53. package/dist/skills/ulw-research/scripts/fact-commands.mjs +241 -0
  54. package/dist/skills/ulw-research/scripts/fact-derive.mjs +66 -0
  55. package/dist/skills/ulw-research/scripts/fact-derive.test.ts +375 -0
  56. package/dist/skills/ulw-research/scripts/fact-expr.mjs +108 -0
  57. package/dist/skills/ulw-research/scripts/fact-fill.mjs +194 -0
  58. package/dist/skills/ulw-research/scripts/fact-fill.test.ts +221 -0
  59. package/dist/skills/ulw-research/scripts/fact-ledger-grammar.test.ts +9 -2
  60. package/dist/skills/ulw-research/scripts/fact-ledger-kinds.mjs +127 -13
  61. package/dist/skills/ulw-research/scripts/fact-ledger-kinds.test.ts +18 -3
  62. package/dist/skills/ulw-research/scripts/fact-ledger-legacy.test.ts +160 -0
  63. package/dist/skills/ulw-research/scripts/fact-ledger-schema.mjs +33 -16
  64. package/dist/skills/ulw-research/scripts/fact-ledger.mjs +29 -9
  65. package/dist/skills/ulw-research/scripts/fact-ledger.test.ts +2 -0
  66. package/dist/skills/ulw-research/scripts/fact-locate.mjs +231 -0
  67. package/dist/skills/ulw-research/scripts/fact-locate.test.ts +118 -0
  68. package/dist/skills/ulw-research/scripts/fact-pairs.mjs +185 -0
  69. package/dist/skills/ulw-research/scripts/fact-pairs.test.ts +151 -0
  70. package/dist/skills/ulw-research/scripts/fact-recompute.mjs +89 -0
  71. package/dist/skills/ulw-research/scripts/fact-unit-dimensions.test.ts +409 -0
  72. package/dist/skills/ulw-research/scripts/fact-unit-rules.test.ts +388 -0
  73. package/dist/skills/ulw-research/scripts/fidelity-binding.mjs +130 -0
  74. package/dist/skills/ulw-research/scripts/fidelity-binding.test.ts +81 -0
  75. package/dist/skills/ulw-research/scripts/fidelity-brief.mjs +5 -0
  76. package/dist/skills/ulw-research/scripts/fidelity-claims.mjs +89 -0
  77. package/dist/skills/ulw-research/scripts/fidelity-lexicon.mjs +145 -0
  78. package/dist/skills/ulw-research/scripts/fidelity-lexicon.test.ts +117 -0
  79. package/dist/skills/ulw-research/scripts/fidelity-records.mjs +163 -0
  80. package/dist/skills/ulw-research/scripts/fidelity-state.mjs +2 -1
  81. package/dist/skills/ulw-research/scripts/fidelity-trace.mjs +85 -0
  82. package/dist/skills/ulw-research/scripts/fidelity-trace.test.ts +58 -0
  83. package/dist/skills/ulw-research/scripts/fidelity-values.mjs +229 -0
  84. package/dist/skills/ulw-research/scripts/fidelity-values.test.ts +270 -0
  85. package/dist/skills/ulw-research/scripts/gates-fidelity.mjs +113 -0
  86. package/dist/skills/ulw-research/scripts/gates-fidelity.test.ts +73 -0
  87. package/dist/skills/ulw-research/scripts/gates-static.mjs +28 -8
  88. package/dist/skills/ulw-research/scripts/html-lite.mjs +2 -2
  89. package/dist/skills/ulw-research/scripts/html-markup.mjs +182 -0
  90. package/dist/skills/ulw-research/scripts/md-lite.mjs +193 -0
  91. package/dist/skills/ulw-research/scripts/md-lite.test.ts +271 -0
  92. package/dist/skills/ulw-research/scripts/meaning-check.mjs +196 -0
  93. package/dist/skills/ulw-research/scripts/meaning-check.test.ts +228 -0
  94. package/dist/skills/ulw-research/scripts/outcome.mjs +6 -5
  95. package/dist/skills/ulw-research/scripts/placeholder.mjs +184 -0
  96. package/dist/skills/ulw-research/scripts/placeholder.test.ts +77 -0
  97. package/dist/skills/ulw-research/scripts/polish-apply.mjs +115 -0
  98. package/dist/skills/ulw-research/scripts/polish-apply.test.ts +363 -0
  99. package/dist/skills/ulw-research/scripts/polish-diff.mjs +31 -0
  100. package/dist/skills/ulw-research/scripts/polish-diff.test.ts +168 -0
  101. package/dist/skills/ulw-research/scripts/polish-markup.test.ts +187 -0
  102. package/dist/skills/ulw-research/scripts/polish-project.mjs +125 -0
  103. package/dist/skills/ulw-research/scripts/polish-rules.mjs +170 -0
  104. package/dist/skills/ulw-research/scripts/references-fences.test.ts +25 -0
  105. package/dist/skills/ulw-research/scripts/report-tools-commands.mjs +19 -8
  106. package/dist/skills/ulw-research/scripts/report-tools.mjs +15 -0
  107. package/dist/skills/ulw-research/scripts/report-tools.test.ts +545 -2
  108. package/dist/skills/ulw-research/scripts/source-commands.mjs +140 -0
  109. package/dist/skills/ulw-research/scripts/source-snapshot.mjs +176 -0
  110. package/dist/skills/ulw-research/scripts/source-snapshot.test.ts +113 -0
  111. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/assets/share.csv +3 -0
  112. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/gen-legacy-dev.mjs +89 -0
  113. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-basic.json +223 -0
  114. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-legacy-dev.json +859 -0
  115. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-verify.json +420 -0
  116. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/polish-edits.json +12 -0
  117. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/report-bad.html +19 -0
  118. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/report-good.html +39 -0
  119. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/acronyms.json +3 -0
  120. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/meta.json +9 -0
  121. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/sentences.jsonl +7 -0
  122. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/text.txt +7 -0
  123. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4.html +19 -0
  124. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/acronyms.json +1 -0
  125. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/meta.json +9 -0
  126. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/sentences.jsonl +1 -0
  127. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/text.txt +1 -0
  128. package/dist/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S9.txt +1 -0
  129. package/dist/skills/ulw-research/scripts/unit-algebra.mjs +101 -0
  130. package/dist/skills/ulw-research/scripts/unit-errors.mjs +23 -0
  131. package/dist/skills/ulw-research/scripts/unit-metadata.mjs +31 -0
  132. package/dist/skills/ulw-research/scripts/unit-pairs.mjs +72 -0
  133. package/dist/skills/ulw-research/scripts/unit-precision.mjs +44 -0
  134. package/dist/skills/ulw-research/scripts/unit-rules-shapes.mjs +64 -0
  135. package/dist/skills/ulw-research/scripts/unit-rules.mjs +173 -0
  136. package/dist/skills/ulw-research/scripts/units.mjs +4 -4
  137. package/dist/testing/module-mock-lifecycle.d.ts +1 -1
  138. package/dist/tui.js +32 -34
  139. package/package.json +13 -13
  140. package/packages/lsp-core/src/mcp-protocol-pin.test.ts +29 -0
  141. package/packages/lsp-core/src/mcp.ts +5 -2
  142. package/packages/lsp-daemon/dist/cli.js +3 -3
  143. package/packages/lsp-daemon/dist/client.js +3 -3
  144. package/packages/lsp-daemon/dist/index.js +3 -3
  145. package/packages/lsp-tools-mcp/dist/cli.js +3 -3
  146. package/packages/lsp-tools-mcp/dist/mcp.js +3 -3
  147. package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
  148. package/packages/omo-codex/plugin/components/bootstrap/dist/cli.js +23 -14
  149. package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
  150. package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
  151. package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
  152. package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
  153. package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
  154. package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
  155. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
  156. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
  157. package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +2 -2
  158. package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
  159. package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
  160. package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
  161. package/packages/omo-codex/plugin/components/rules/package.json +1 -1
  162. package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
  163. package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
  164. package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
  165. package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
  166. package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
  167. package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
  168. package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +1 -1
  169. package/packages/omo-codex/plugin/components/ulw-execute-continuation/package.json +1 -1
  170. package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +5 -5
  171. package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
  172. package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
  173. package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
  174. package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
  175. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
  176. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
  177. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
  178. package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
  179. package/packages/omo-codex/plugin/hooks/post-tool-use-recording-spawn-admission.json +1 -1
  180. package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
  181. package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
  182. package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
  183. package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
  184. package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
  185. package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
  186. package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
  187. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-execute-continuation.json +1 -1
  188. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
  189. package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
  190. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
  191. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
  192. package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
  193. package/packages/omo-codex/plugin/package-lock.json +12 -12
  194. package/packages/omo-codex/plugin/package.json +1 -1
  195. package/packages/omo-codex/plugin/scripts/sync-skills.mjs +8 -3
  196. package/packages/omo-codex/plugin/shared/test/config-loader.test.ts +0 -2
  197. package/packages/omo-codex/plugin/skills/ast-grep/AGENTS.md +1 -1
  198. package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
  199. package/packages/omo-codex/plugin/skills/frontend/ATTRIBUTION.md +2 -2
  200. package/packages/omo-codex/plugin/skills/ultimate-browsing/engine/AGENTS.md +1 -1
  201. package/packages/omo-codex/plugin/skills/ulw-research/AGENTS.md +14 -2
  202. package/packages/omo-codex/plugin/skills/ulw-research/SKILL.md +36 -11
  203. package/packages/omo-codex/plugin/skills/ulw-research/references/deliverable-phase.md +81 -14
  204. package/packages/omo-codex/plugin/skills/ulw-research/references/fact-ledger-grammar.md +19 -1
  205. package/packages/omo-codex/plugin/skills/ulw-research/references/fact-ledger.md +95 -0
  206. package/packages/omo-codex/plugin/skills/ulw-research/references/fidelity-claim-kinds.md +19 -0
  207. package/packages/omo-codex/plugin/skills/ulw-research/references/report-gates.md +21 -4
  208. package/packages/omo-codex/plugin/skills/ulw-research/references/report-visualization.md +2 -0
  209. package/packages/omo-codex/plugin/skills/ulw-research/references/unit-rules.md +157 -0
  210. package/packages/omo-codex/plugin/skills/ulw-research/scripts/claim-kinds.mjs +116 -0
  211. package/packages/omo-codex/plugin/skills/ulw-research/scripts/cli-support.mjs +19 -5
  212. package/packages/omo-codex/plugin/skills/ulw-research/scripts/contracts.mjs +27 -6
  213. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands-meaning.mjs +176 -0
  214. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands-polish.mjs +127 -0
  215. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands-verify.mjs +183 -0
  216. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands.mjs +241 -0
  217. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-derive.mjs +66 -0
  218. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-expr.mjs +108 -0
  219. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-fill.mjs +194 -0
  220. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-ledger-kinds.mjs +127 -13
  221. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-ledger-schema.mjs +33 -16
  222. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-ledger.mjs +29 -9
  223. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-locate.mjs +231 -0
  224. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-pairs.mjs +185 -0
  225. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-recompute.mjs +89 -0
  226. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-binding.mjs +130 -0
  227. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-brief.mjs +5 -0
  228. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-claims.mjs +89 -0
  229. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-lexicon.mjs +145 -0
  230. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-records.mjs +163 -0
  231. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-state.mjs +2 -1
  232. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-trace.mjs +85 -0
  233. package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-values.mjs +229 -0
  234. package/packages/omo-codex/plugin/skills/ulw-research/scripts/gates-fidelity.mjs +113 -0
  235. package/packages/omo-codex/plugin/skills/ulw-research/scripts/gates-static.mjs +28 -8
  236. package/packages/omo-codex/plugin/skills/ulw-research/scripts/html-lite.mjs +2 -2
  237. package/packages/omo-codex/plugin/skills/ulw-research/scripts/html-markup.mjs +182 -0
  238. package/packages/omo-codex/plugin/skills/ulw-research/scripts/md-lite.mjs +193 -0
  239. package/packages/omo-codex/plugin/skills/ulw-research/scripts/meaning-check.mjs +196 -0
  240. package/packages/omo-codex/plugin/skills/ulw-research/scripts/outcome.mjs +6 -5
  241. package/packages/omo-codex/plugin/skills/ulw-research/scripts/placeholder.mjs +184 -0
  242. package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-apply.mjs +115 -0
  243. package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-diff.mjs +31 -0
  244. package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-project.mjs +125 -0
  245. package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-rules.mjs +170 -0
  246. package/packages/omo-codex/plugin/skills/ulw-research/scripts/report-tools-commands.mjs +19 -8
  247. package/packages/omo-codex/plugin/skills/ulw-research/scripts/report-tools.mjs +15 -0
  248. package/packages/omo-codex/plugin/skills/ulw-research/scripts/source-commands.mjs +140 -0
  249. package/packages/omo-codex/plugin/skills/ulw-research/scripts/source-snapshot.mjs +176 -0
  250. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-algebra.mjs +101 -0
  251. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-errors.mjs +23 -0
  252. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-metadata.mjs +31 -0
  253. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-pairs.mjs +72 -0
  254. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-precision.mjs +44 -0
  255. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-rules-shapes.mjs +64 -0
  256. package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-rules.mjs +173 -0
  257. package/packages/omo-codex/plugin/skills/ulw-research/scripts/units.mjs +4 -4
  258. package/packages/omo-codex/plugin/test/sync-skills-codex-compatibility.test.mjs +19 -0
  259. package/packages/omo-codex/plugin/test/sync-skills-test-support.mjs +7 -3
  260. package/packages/omo-codex/scripts/install-dist/install-local.mjs +28 -19
  261. package/packages/shared-skills/skills/ast-grep/AGENTS.md +1 -1
  262. package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +1 -1
  263. package/packages/shared-skills/skills/frontend/ATTRIBUTION.md +2 -2
  264. package/packages/shared-skills/skills/ultimate-browsing/engine/AGENTS.md +1 -1
  265. package/packages/shared-skills/skills/ulw-research/AGENTS.md +14 -2
  266. package/packages/shared-skills/skills/ulw-research/SKILL.md +37 -12
  267. package/packages/shared-skills/skills/ulw-research/references/deliverable-phase.md +81 -14
  268. package/packages/shared-skills/skills/ulw-research/references/fact-ledger-grammar.md +19 -1
  269. package/packages/shared-skills/skills/ulw-research/references/fact-ledger.md +95 -0
  270. package/packages/shared-skills/skills/ulw-research/references/fidelity-claim-kinds.md +19 -0
  271. package/packages/shared-skills/skills/ulw-research/references/report-gates.md +21 -4
  272. package/packages/shared-skills/skills/ulw-research/references/report-visualization.md +2 -0
  273. package/packages/shared-skills/skills/ulw-research/references/unit-rules.md +157 -0
  274. package/packages/shared-skills/skills/ulw-research/scripts/claim-kinds.mjs +116 -0
  275. package/packages/shared-skills/skills/ulw-research/scripts/claim-kinds.test.ts +193 -0
  276. package/packages/shared-skills/skills/ulw-research/scripts/cli-support.mjs +19 -5
  277. package/packages/shared-skills/skills/ulw-research/scripts/cli-support.test.ts +13 -2
  278. package/packages/shared-skills/skills/ulw-research/scripts/contracts.mjs +27 -6
  279. package/packages/shared-skills/skills/ulw-research/scripts/contracts.test.ts +3 -0
  280. package/packages/shared-skills/skills/ulw-research/scripts/copy-returns-polish.test.ts +209 -0
  281. package/packages/shared-skills/skills/ulw-research/scripts/copy-returns.test.ts +183 -0
  282. package/packages/shared-skills/skills/ulw-research/scripts/delivery-barrier.test.ts +245 -0
  283. package/packages/shared-skills/skills/ulw-research/scripts/fact-commands-meaning.mjs +176 -0
  284. package/packages/shared-skills/skills/ulw-research/scripts/fact-commands-polish.mjs +127 -0
  285. package/packages/shared-skills/skills/ulw-research/scripts/fact-commands-verify.mjs +183 -0
  286. package/packages/shared-skills/skills/ulw-research/scripts/fact-commands.mjs +241 -0
  287. package/packages/shared-skills/skills/ulw-research/scripts/fact-derive.mjs +66 -0
  288. package/packages/shared-skills/skills/ulw-research/scripts/fact-derive.test.ts +375 -0
  289. package/packages/shared-skills/skills/ulw-research/scripts/fact-expr.mjs +108 -0
  290. package/packages/shared-skills/skills/ulw-research/scripts/fact-fill.mjs +194 -0
  291. package/packages/shared-skills/skills/ulw-research/scripts/fact-fill.test.ts +221 -0
  292. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-grammar.test.ts +9 -2
  293. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-kinds.mjs +127 -13
  294. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-kinds.test.ts +18 -3
  295. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-legacy.test.ts +160 -0
  296. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-schema.mjs +33 -16
  297. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger.mjs +29 -9
  298. package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger.test.ts +2 -0
  299. package/packages/shared-skills/skills/ulw-research/scripts/fact-locate.mjs +231 -0
  300. package/packages/shared-skills/skills/ulw-research/scripts/fact-locate.test.ts +118 -0
  301. package/packages/shared-skills/skills/ulw-research/scripts/fact-pairs.mjs +185 -0
  302. package/packages/shared-skills/skills/ulw-research/scripts/fact-pairs.test.ts +151 -0
  303. package/packages/shared-skills/skills/ulw-research/scripts/fact-recompute.mjs +89 -0
  304. package/packages/shared-skills/skills/ulw-research/scripts/fact-unit-dimensions.test.ts +409 -0
  305. package/packages/shared-skills/skills/ulw-research/scripts/fact-unit-rules.test.ts +388 -0
  306. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-binding.mjs +130 -0
  307. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-binding.test.ts +81 -0
  308. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-brief.mjs +5 -0
  309. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-claims.mjs +89 -0
  310. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-lexicon.mjs +145 -0
  311. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-lexicon.test.ts +117 -0
  312. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-records.mjs +163 -0
  313. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-state.mjs +2 -1
  314. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-trace.mjs +85 -0
  315. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-trace.test.ts +58 -0
  316. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-values.mjs +229 -0
  317. package/packages/shared-skills/skills/ulw-research/scripts/fidelity-values.test.ts +270 -0
  318. package/packages/shared-skills/skills/ulw-research/scripts/gates-fidelity.mjs +113 -0
  319. package/packages/shared-skills/skills/ulw-research/scripts/gates-fidelity.test.ts +73 -0
  320. package/packages/shared-skills/skills/ulw-research/scripts/gates-static.mjs +28 -8
  321. package/packages/shared-skills/skills/ulw-research/scripts/html-lite.mjs +2 -2
  322. package/packages/shared-skills/skills/ulw-research/scripts/html-markup.mjs +182 -0
  323. package/packages/shared-skills/skills/ulw-research/scripts/md-lite.mjs +193 -0
  324. package/packages/shared-skills/skills/ulw-research/scripts/md-lite.test.ts +271 -0
  325. package/packages/shared-skills/skills/ulw-research/scripts/meaning-check.mjs +196 -0
  326. package/packages/shared-skills/skills/ulw-research/scripts/meaning-check.test.ts +228 -0
  327. package/packages/shared-skills/skills/ulw-research/scripts/outcome.mjs +6 -5
  328. package/packages/shared-skills/skills/ulw-research/scripts/placeholder.mjs +184 -0
  329. package/packages/shared-skills/skills/ulw-research/scripts/placeholder.test.ts +77 -0
  330. package/packages/shared-skills/skills/ulw-research/scripts/polish-apply.mjs +115 -0
  331. package/packages/shared-skills/skills/ulw-research/scripts/polish-apply.test.ts +363 -0
  332. package/packages/shared-skills/skills/ulw-research/scripts/polish-diff.mjs +31 -0
  333. package/packages/shared-skills/skills/ulw-research/scripts/polish-diff.test.ts +168 -0
  334. package/packages/shared-skills/skills/ulw-research/scripts/polish-markup.test.ts +187 -0
  335. package/packages/shared-skills/skills/ulw-research/scripts/polish-project.mjs +125 -0
  336. package/packages/shared-skills/skills/ulw-research/scripts/polish-rules.mjs +170 -0
  337. package/packages/shared-skills/skills/ulw-research/scripts/references-fences.test.ts +25 -0
  338. package/packages/shared-skills/skills/ulw-research/scripts/report-tools-commands.mjs +19 -8
  339. package/packages/shared-skills/skills/ulw-research/scripts/report-tools.mjs +15 -0
  340. package/packages/shared-skills/skills/ulw-research/scripts/report-tools.test.ts +545 -2
  341. package/packages/shared-skills/skills/ulw-research/scripts/source-commands.mjs +140 -0
  342. package/packages/shared-skills/skills/ulw-research/scripts/source-snapshot.mjs +176 -0
  343. package/packages/shared-skills/skills/ulw-research/scripts/source-snapshot.test.ts +113 -0
  344. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/assets/share.csv +3 -0
  345. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/gen-legacy-dev.mjs +89 -0
  346. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-basic.json +223 -0
  347. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-legacy-dev.json +859 -0
  348. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-verify.json +420 -0
  349. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/polish-edits.json +12 -0
  350. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/report-bad.html +19 -0
  351. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/report-good.html +39 -0
  352. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/acronyms.json +3 -0
  353. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/meta.json +9 -0
  354. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/sentences.jsonl +7 -0
  355. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/text.txt +7 -0
  356. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4.html +19 -0
  357. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/acronyms.json +1 -0
  358. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/meta.json +9 -0
  359. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/sentences.jsonl +1 -0
  360. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/text.txt +1 -0
  361. package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S9.txt +1 -0
  362. package/packages/shared-skills/skills/ulw-research/scripts/unit-algebra.mjs +101 -0
  363. package/packages/shared-skills/skills/ulw-research/scripts/unit-errors.mjs +23 -0
  364. package/packages/shared-skills/skills/ulw-research/scripts/unit-metadata.mjs +31 -0
  365. package/packages/shared-skills/skills/ulw-research/scripts/unit-pairs.mjs +72 -0
  366. package/packages/shared-skills/skills/ulw-research/scripts/unit-precision.mjs +44 -0
  367. package/packages/shared-skills/skills/ulw-research/scripts/unit-rules-shapes.mjs +64 -0
  368. package/packages/shared-skills/skills/ulw-research/scripts/unit-rules.mjs +173 -0
  369. package/packages/shared-skills/skills/ulw-research/scripts/units.mjs +4 -4
  370. package/dist/config-migration/dori-section-rename.d.ts +0 -3
@@ -0,0 +1,185 @@
1
+ // fact-pairs.mjs - (source, report sentence) pairs for the meaning verifier.
2
+ //
3
+ // extractPairs walks the prose sentences of a filled HTML report and emits, in document order:
4
+ // a quote pair per distinct ledger quote cited by a findings sentence (facts sharing one quote
5
+ // share one pair), a claim pair per sentence bound only by data-claim (the statement comes from
6
+ // the claim index), and a translation pair per data-translates span. force_strong routes a pair
7
+ // to the strong reader when the lexicon raised name_outside_quote or scope_widened_warn, when the
8
+ // hedge-position heuristic fired, or when the source hedges and the sentence's last six tokens do
9
+ // not. No model, no IO: the readers run as separate lanes. Plain Node ESM; no Hangul here.
10
+
11
+ import { isExemptKind, proseSentences } from "./fidelity-binding.mjs"
12
+ import { isKoreanTerm, lexicalPattern, lexiconChecks } from "./fidelity-lexicon.mjs"
13
+ import { sentenceKey } from "./fidelity-state.mjs"
14
+ import { buildContext } from "./gates-static.mjs"
15
+ import { parseHtml, proseText } from "./html-lite.mjs"
16
+ import { HEDGES } from "./lexicon.mjs"
17
+ import { normalizeText } from "./text-normalize.mjs"
18
+
19
+ /** Every pair kind the producers below emit; consumers count and schema pairs by this list. */
20
+ export const PAIR_KINDS = Object.freeze(["quote", "claim", "translation"])
21
+ const TAIL = 6
22
+
23
+ const lang = (text) => (isKoreanTerm(text) ? "ko" : "en")
24
+ /** Sentence text with its fact spans cut out, so a Korean value does not make an English sentence Korean. */
25
+ const outsideFacts = (sentence) => sentence.facts.reduceRight((text, fact) => text.slice(0, fact.start - sentence.start) + text.slice(fact.end - sentence.start), sentence.text)
26
+
27
+ /** Latin hedges match whole words ("exact"); Korean hedges match as substrings, one syllable as a token prefix ("stem"). */
28
+ const HEDGE_RES = HEDGES.map((term) => lexicalPattern(term, isKoreanTerm(term) ? "stem" : "exact"))
29
+
30
+ /** Hedge terms that are also month names; capitalized and followed by a date number, they are months. */
31
+ const MONTH_WORDS = new Set(["may"])
32
+
33
+ /** A capitalized Latin match after the first word is a name or a month ("in May"), not a hedge. */
34
+ const isHedgeAt = (text, match) => {
35
+ if (!/^\p{Lu}/u.test(match[0]) || isKoreanTerm(match[0])) return true
36
+ if (match.index !== 0) return false
37
+ // At the start of a text a capital is only sentence case, so the word still hedges - unless it is a
38
+ // month name followed by a date number ("May 2024 sales rose.").
39
+ return !(MONTH_WORDS.has(match[0].toLowerCase()) && /^\s+\p{Nd}/u.test(text.slice(match.index + match[0].length)))
40
+ }
41
+
42
+ export const hasHedge = (text) => {
43
+ const normal = normalizeText(text)
44
+ return HEDGE_RES.some((re) => [...normal.matchAll(re)].some((match) => isHedgeAt(normal, match)))
45
+ }
46
+
47
+ /** The source hedges and none of the sentence's last six tokens carries a hedge. */
48
+ function tailDropsHedge(source, sentence) {
49
+ if (!hasHedge(source)) return false
50
+ return !hasHedge(normalizeText(sentence).split(/\s+/u).filter(Boolean).slice(-TAIL).join(" "))
51
+ }
52
+
53
+ function slugOf(scope) {
54
+ const heading = scope.section?.heading
55
+ if (!heading) return ""
56
+ return (heading.attrs.id ?? proseText(heading))
57
+ .toLowerCase()
58
+ .replace(/[^\p{L}\p{N}]+/gu, "-")
59
+ .replace(/^-+|-+$/gu, "")
60
+ }
61
+
62
+ function claimMap(claims) {
63
+ const list = Array.isArray(claims) ? claims : (claims?.claims ?? [])
64
+ return new Map(list.map((claim) => [claim.claim_id, claim]))
65
+ }
66
+
67
+ const idsOf = (attr) => String(attr ?? "").split(/[\s,]+/u).filter(Boolean)
68
+
69
+ /** Claim ids that bind a sentence: on the block or an ancestor, or on an inner element whose text the sentence holds. */
70
+ function claimIdsFor(ctx, block, sentence) {
71
+ const { closest, descendants } = ctx.util
72
+ const up = block.owner.attrs["data-claim"] !== undefined ? block.owner : closest(block.owner, (node) => node.attrs?.["data-claim"] !== undefined)
73
+ const ids = up ? idsOf(up.attrs["data-claim"]) : []
74
+ const text = normalizeText(sentence.text)
75
+ for (const node of descendants(block.owner)) {
76
+ if (node.attrs?.["data-claim"] === undefined) continue
77
+ const inner = normalizeText(proseText(node))
78
+ if (inner !== "" && text.includes(inner)) ids.push(...idsOf(node.attrs["data-claim"]))
79
+ }
80
+ return [...new Set(ids)]
81
+ }
82
+
83
+ function exempt(ctx, node) {
84
+ return isExemptKind(node.attrs["data-kind"]) || Boolean(ctx.util.closest(node, (cur) => isExemptKind(cur.attrs?.["data-kind"])))
85
+ }
86
+
87
+ /** Lexicon routing for every fact span of one quote group in one sentence. */
88
+ function lexiconRouted(group, sentence) {
89
+ const probes = group.facts.map((fact, index) => ({
90
+ pair_id: String(index),
91
+ quote: group.quote,
92
+ sentence: sentence.text,
93
+ span: [fact.start - sentence.start, fact.end - sentence.start],
94
+ qualifier: group.row.kind === "quote" ? null : (group.rows.get(fact.id)?.qualifier ?? null),
95
+ }))
96
+ return lexiconChecks(probes).forceStrong.length > 0
97
+ }
98
+
99
+ function quotePairs(sentence, rows, slug, reportLang) {
100
+ const groups = new Map()
101
+ for (const fact of sentence.facts) {
102
+ const row = rows.get(fact.id)
103
+ if (!row?.quote) continue
104
+ const group = groups.get(row.quote) ?? { quote: row.quote, row, rows, facts: [], ids: [] }
105
+ group.facts.push(fact)
106
+ if (!group.ids.includes(fact.id)) group.ids.push(fact.id)
107
+ groups.set(row.quote, group)
108
+ }
109
+ const allIds = [...new Set(sentence.facts.map((fact) => fact.id))]
110
+ return [...groups.values()].map((group) => ({
111
+ kind: "quote",
112
+ sentence_key: sentenceKey(slug, allIds),
113
+ fact_ids: [...group.ids].sort(),
114
+ quote: group.quote,
115
+ sentence: sentence.text,
116
+ source_lang: lang(group.quote),
117
+ report_lang: reportLang ?? lang(outsideFacts(sentence)),
118
+ force_strong: lexiconRouted(group, sentence) || tailDropsHedge(group.quote, sentence.text),
119
+ }))
120
+ }
121
+
122
+ function claimPairs(ctx, block, sentence, byClaim, slug, reportLang) {
123
+ if (sentence.facts.length > 0 || exempt(ctx, block.owner)) return []
124
+ return claimIdsFor(ctx, block, sentence)
125
+ .map((id) => byClaim.get(id))
126
+ .filter(Boolean)
127
+ .map((claim) => ({
128
+ kind: "claim",
129
+ sentence_key: sentenceKey(slug, [claim.claim_id]),
130
+ claim_id: claim.claim_id,
131
+ statement: claim.statement,
132
+ sentence: sentence.text,
133
+ source_lang: lang(claim.statement),
134
+ report_lang: reportLang ?? lang(sentence.text),
135
+ force_strong: lexiconChecks([{ pair_id: "c", quote: claim.statement, sentence: sentence.text }]).forceStrong.length > 0 || tailDropsHedge(claim.statement, sentence.text),
136
+ }))
137
+ }
138
+
139
+ function translationPair(node, rows, slug, reportLang) {
140
+ const id = node.attrs["data-translates"]
141
+ const row = rows.get(id)
142
+ const text = proseText(node)
143
+ if (!row?.quote || text === "") return null
144
+ return {
145
+ kind: "translation",
146
+ sentence_key: sentenceKey(slug, [id]),
147
+ fact_ids: [id],
148
+ quote: row.quote,
149
+ sentence: text,
150
+ source_lang: lang(row.quote),
151
+ report_lang: reportLang ?? lang(text),
152
+ force_strong: tailDropsHedge(row.quote, text),
153
+ }
154
+ }
155
+
156
+ /**
157
+ * @param {string} html the filled report
158
+ * @param {{ rows: object[] }} ledger
159
+ * @param {{ claims: object[] } | object[] | null} claims indexClaims(...) output or its claims array
160
+ * @returns {object[]} pairs with pair_id P1, P2, ... in document order
161
+ */
162
+ export function extractPairs(html, ledger, claims) {
163
+ const ctx = buildContext(parseHtml(html), {})
164
+ const rows = new Map((ledger?.rows ?? []).map((row) => [row.fact_id, row]))
165
+ const byClaim = claimMap(claims)
166
+ const htmlLang = ctx.all.find((node) => node.tag === "html")?.attrs.lang
167
+ const reportLang = htmlLang ? htmlLang.toLowerCase().split("-")[0] : null
168
+ const out = []
169
+ const seenSpans = new Set()
170
+ for (const block of proseSentences(ctx)) {
171
+ const findings = Boolean(block.scope.section) && block.kind === null
172
+ if (!findings) continue
173
+ const slug = slugOf(block.scope)
174
+ for (const sentence of block.sentences) {
175
+ out.push(...quotePairs(sentence, rows, slug, reportLang), ...claimPairs(ctx, block, sentence, byClaim, slug, reportLang))
176
+ }
177
+ for (const node of ctx.util.descendants(block.owner)) {
178
+ if (node.attrs?.["data-translates"] === undefined || seenSpans.has(node)) continue
179
+ seenSpans.add(node)
180
+ const pair = translationPair(node, rows, slug, reportLang)
181
+ if (pair) out.push(pair)
182
+ }
183
+ }
184
+ return out.map((pair, index) => ({ pair_id: `P${index + 1}`, ...pair }))
185
+ }
@@ -0,0 +1,89 @@
1
+ // Iterative postorder verifier: one snapshot and one arithmetic evaluation per reachable node.
2
+ import { compute } from "./fact-derive.mjs"
3
+ import { parseExpr } from "./fact-expr.mjs"
4
+ import { isLegacyDerived, kindRuleErrors, readFlaws, readRow } from "./fact-ledger-kinds.mjs"
5
+ import { rowErrors } from "./fact-ledger-schema.mjs"
6
+ import { refuse } from "./unit-algebra.mjs"
7
+ import { refusal } from "./unit-errors.mjs"
8
+ import { object, sameDeclared } from "./unit-metadata.mjs"
9
+ import { expectedUnit, malformed, ruleOf, unitMismatch } from "./unit-rules.mjs"
10
+
11
+ const derived = (row) => row.kind === "derived" || row.kind === "converted"
12
+ const fail = (detail, shape, expected) => ({ ok: false, detail, shape, expected })
13
+ function refuseLegacy(row) {
14
+ if (isLegacyDerived(row)) refuse(`${row.fact_id} was written before precision, compatibility, and context existed; regenerate it with derive`, undefined, "legacy derived row", "a derived row regenerated by derive")
15
+ }
16
+
17
+ function verifyRow(row, rows) {
18
+ const rule = ruleOf(row.operation)
19
+ const ast = rule.expression ? parseExpr(row.formula) : null
20
+ const context = { ...row.context, rationale: row.rationale }
21
+ const unit = expectedUnit(row.operation, rows, { ast, context })
22
+ const expected = { unit, ...compute(row.operation, rows, unit, ast, context, row.formula), derived_from: rows.map((r) => r.fact_id) }
23
+ if (row.unit !== unit) return fail(`${row.fact_id}: ${unitMismatch(row.operation, rows, row.unit, unit)}`, "result_unit", expected)
24
+ for (const field of Object.keys(expected)) {
25
+ if (!sameDeclared(row[field], expected[field])) return fail(`${row.fact_id}: stored ${field} differs from the recomputed result`, `${field}_mismatch`, expected)
26
+ }
27
+ return { ok: true, expected }
28
+ }
29
+
30
+ export function verifyGraph(ledger, roots, requireActive = false, override = null) {
31
+ try {
32
+ if (!object(ledger) || !Array.isArray(ledger.rows)) refuse("ledger rows must be an array")
33
+ const byId = new Map()
34
+ for (const r of ledger.rows) {
35
+ if (!object(r) || typeof r.fact_id !== "string" || byId.has(r.fact_id)) refuse("ledger rows need distinct fact ids", undefined, "identity", "distinct fact ids")
36
+ byId.set(r.fact_id, r)
37
+ }
38
+ if (override) byId.set(override.fact_id, override)
39
+ const states = new Map()
40
+ const snapshots = new Map()
41
+ const results = new Map()
42
+ const stack = roots.map((id) => ({ id, finish: false }))
43
+ while (stack.length) {
44
+ const { id, finish } = stack.pop()
45
+ if (states.get(id) === "done") continue
46
+ if (!finish) {
47
+ if (states.get(id) === "open") refuse(`${id}: operands form a cycle`, undefined, "cycle", "an acyclic dependency graph")
48
+ const original = byId.get(id)
49
+ if (!original) refuse(`no ledger row ${id}`, undefined, "missing_operand", "an existing fact id")
50
+ const row = { ...readRow(original) }
51
+ snapshots.set(id, row)
52
+ if (requireActive && row.status !== "active") refuse(`${id} is ${row.status}`, undefined, "inactive_dependency", "active dependencies at every depth")
53
+ const [flaw] = readFlaws(row)
54
+ if (flaw) refuse(`${id}: ${flaw.detail}`, undefined, flaw.shape, flaw.expected)
55
+ if (derived(row)) {
56
+ refuseLegacy(row)
57
+ const shape = malformed(row)
58
+ if (shape) refuse(`${id}: ${shape}`, undefined, "malformed_row", "the operation's registry row shape")
59
+ }
60
+ const errors = derived(row) ? kindRuleErrors(row, id) : rowErrors(row)
61
+ if (errors.length) refuse(errors.join("; "), undefined, "row_schema", "a canonical row matching its kind and operation")
62
+ if (row.exact === null || row.value === null) refuse(`${id} has no exact value to derive from`)
63
+ states.set(id, "open")
64
+ stack.push({ id, finish: true })
65
+ if (derived(row)) for (const dependency of row.operands) stack.push({ id: dependency, finish: false })
66
+ } else {
67
+ const row = snapshots.get(id)
68
+ if (derived(row)) {
69
+ const result = verifyRow(row, row.operands.map((ref) => snapshots.get(ref)))
70
+ if (!result.ok) return result
71
+ const errors = rowErrors(row)
72
+ if (errors.length) refuse(errors.join("; "), undefined, "row_schema", "a complete canonical row")
73
+ results.set(id, result)
74
+ }
75
+ states.set(id, "done")
76
+ }
77
+ }
78
+ return results.get(roots[0]) ?? { ok: true }
79
+ } catch (error) { return { ok: false, ...refusal(error) } }
80
+ }
81
+
82
+ export function recompute(ledger, row) {
83
+ try {
84
+ refuseLegacy(row)
85
+ const shape = malformed(row)
86
+ if (shape) refuse(shape, undefined, "malformed_row", "a valid derived or converted row")
87
+ return verifyGraph(ledger, [row.fact_id], false, row)
88
+ } catch (error) { return { ok: false, ...refusal(error) } }
89
+ }
@@ -0,0 +1,130 @@
1
+ // fidelity-binding.mjs - sentence binding and claim-status checks of the fidelity gate.
2
+ //
3
+ // proseSentences walks every leaf prose element (p, li) outside figures, tables and page chrome,
4
+ // keeps the offsets of each data-fact element inside its text, and splits it into sentences, so
5
+ // every check sees which ledger rows a sentence cites. bindingChecks raises unbound_sentence (a
6
+ // findings sentence with no fact, placeholder, citation, or data-claim), claim_status_invalid (a
7
+ // data-claim id that is unknown, refuted or unresolved outside a Gaps or Contradictions section,
8
+ // or high-risk and missing from verified-claims), and conflicting_readings (two active rows with
9
+ // one value and unit but different periods or qualifiers cited in one sentence). Plain Node ESM.
10
+
11
+ import { proseText } from "./html-lite.mjs"
12
+ import { fromDecimal, eq } from "./rational.mjs"
13
+ import { splitSentences } from "./sentence-split.mjs"
14
+ import { normalizeUnit } from "./units.mjs"
15
+
16
+ const SKIP = new Set(["code", "pre", "kbd", "samp", "script", "style", "svg", "template", "noscript"])
17
+ const CONTAINERS = new Set(["figure", "table", "nav", "header", "footer"])
18
+ /** data-kind values whose sentences need no binding (opinion and recommendation blocks). */
19
+ export const EXEMPT_KINDS = Object.freeze(["opinion", "recommendation"])
20
+ export const isExemptKind = (kind) => EXEMPT_KINDS.includes(kind)
21
+ const DECIMAL = /^-?\d+(?:\.\d+)?$/
22
+ /** Gaps and Contradictions headings (English, and the Korean gap/limit/contradiction/conflict words). */
23
+ const GAPS_HEADING = /\b(?:gaps?|contradictions?|unresolved)\b|\uACF5\uBC31|\uD55C\uACC4|\uBAA8\uC21C|\uC0C1\uCDA9/i
24
+
25
+ /** Canonical unit token, or the raw unit without spaces, lowercased; "" for none. */
26
+ export function unitKey(unit) {
27
+ if (unit === null || unit === undefined) return ""
28
+ return normalizeUnit(String(unit)) ?? String(unit).replace(/\s+/g, "").toLowerCase()
29
+ }
30
+
31
+ /** Exact decimal equality; false when either side is not a plain decimal. */
32
+ export function sameValue(a, b) {
33
+ const [x, y] = [String(a ?? "").replace(/,/g, ""), String(b ?? "").replace(/,/g, "")]
34
+ return DECIMAL.test(x) && DECIMAL.test(y) && eq(fromDecimal(x), fromDecimal(y))
35
+ }
36
+
37
+ function serialize(node, out) {
38
+ for (const child of node.children) {
39
+ if (child.tag === "#text") out.text += child.text
40
+ else if (child.tag === "br") out.text += " "
41
+ else if (SKIP.has(child.tag)) continue
42
+ else if (child.attrs["data-fact"] !== undefined) {
43
+ const text = proseText(child)
44
+ out.facts.push({ id: child.attrs["data-fact"], start: out.text.length, end: out.text.length + text.length, text, node: child })
45
+ out.text += text
46
+ } else serialize(child, out)
47
+ }
48
+ return out
49
+ }
50
+
51
+ /**
52
+ * Leaf prose elements with their sentences and the facts each sentence cites.
53
+ * @returns {{ owner: object, scope: object, kind: string|null, sentences: { text: string, start: number, end: number, facts: object[] }[] }[]}
54
+ */
55
+ export function proseSentences(ctx) {
56
+ const { closest, descendants } = ctx.util
57
+ const blocks = []
58
+ for (const { node, scope } of ctx.elements) {
59
+ if (node.tag !== "p" && node.tag !== "li") continue
60
+ if (node.tag === "li" && descendants(node).some((child) => child.tag === "p" || child.tag === "li")) continue
61
+ if (closest(node, (cur) => CONTAINERS.has(cur.tag))) continue
62
+ const { text, facts } = serialize(node, { text: "", facts: [] })
63
+ const sentences = splitSentences(text).map((s) => ({ ...s, facts: facts.filter((f) => f.start < s.end && f.end > s.start) }))
64
+ blocks.push({ owner: node, scope, kind: ctx.kindOf(scope), sentences })
65
+ }
66
+ return blocks
67
+ }
68
+
69
+ function claimList(claims) {
70
+ const list = Array.isArray(claims) ? claims : (claims?.claims ?? [])
71
+ return new Map(list.map((claim) => [claim.claim_id, claim]))
72
+ }
73
+
74
+ const selfOrUp = (ctx, node, test) => test(node) || Boolean(ctx.util.closest(node, test))
75
+
76
+ function claimDefects(ctx, claims) {
77
+ const byId = claimList(claims)
78
+ const out = []
79
+ for (const { node, scope } of ctx.elements) {
80
+ const attr = node.attrs["data-claim"]
81
+ if (attr === undefined) continue
82
+ const heading = scope.section?.heading
83
+ const inGaps = Boolean(heading) && GAPS_HEADING.test(proseText(heading))
84
+ for (const id of attr.split(/[\s,]+/).filter(Boolean)) {
85
+ const claim = byId.get(id)
86
+ let why = null
87
+ if (!claim) why = `data-claim ${id} is not in the claim index`
88
+ else if (/refuted|unresolved/i.test(claim.status) && !inGaps) why = `claim ${id} is ${claim.status} but asserted outside Gaps or Contradictions`
89
+ else if (!inGaps && /high/i.test(claim.risk) && !claim.in_verified) why = `high-risk claim ${id} is not in verified-claims`
90
+ if (why) out.push(ctx.defect("claim_status_invalid", node, why))
91
+ }
92
+ }
93
+ return out
94
+ }
95
+
96
+ function conflict(rows, facts) {
97
+ const cited = [...new Set(facts.map((f) => f.id))].map((id) => rows.get(id)).filter((row) => row && row.status === "active" && row.kind !== "quote")
98
+ for (let i = 0; i < cited.length; i++) {
99
+ for (let k = i + 1; k < cited.length; k++) {
100
+ const [a, b] = [cited[i], cited[k]]
101
+ if (!sameValue(a.value, b.value) || unitKey(a.unit) !== unitKey(b.unit)) continue
102
+ if (a.valid_at !== b.valid_at || a.qualifier !== b.qualifier) return [a, b]
103
+ }
104
+ }
105
+ return null
106
+ }
107
+
108
+ /**
109
+ * @param {object} ctx buildContext(...) from gates-static.mjs
110
+ * @param {{ claims: object[] } | object[] | null} claims indexClaims(...) output or its claims array
111
+ * @param {{ rows: object[] } | null} ledger
112
+ */
113
+ export function bindingChecks(ctx, claims, ledger) {
114
+ const rows = new Map((ledger?.rows ?? []).map((row) => [row.fact_id, row]))
115
+ const out = []
116
+ for (const block of proseSentences(ctx)) {
117
+ const findings = Boolean(block.scope.section) && block.kind === null
118
+ const exempt = selfOrUp(ctx, block.owner, (cur) => isExemptKind(cur.attrs["data-kind"]) || cur.attrs["data-claim"] !== undefined)
119
+ for (const sentence of block.sentences) {
120
+ const bound = sentence.facts.length > 0 || ctx.util.citationMarker.test(sentence.text) || sentence.text.includes("{{")
121
+ if (findings && !exempt && !bound) out.push(ctx.defect("unbound_sentence", block.owner, `no fact, citation, or data-claim binds: "${sentence.text.slice(0, 80)}"`))
122
+ const pair = conflict(rows, sentence.facts)
123
+ if (pair) {
124
+ const [a, b] = pair
125
+ out.push(ctx.defect("conflicting_readings", block.owner, `${a.fact_id} (${a.valid_at ?? "no period"}) and ${b.fact_id} (${b.valid_at ?? "no period"}) share ${a.value} ${a.unit ?? ""} in one sentence`))
126
+ }
127
+ }
128
+ }
129
+ return [...out, ...claimDefects(ctx, claims)]
130
+ }
@@ -109,6 +109,11 @@ export function isLocked(parsed) {
109
109
  return FIDELITY_FIELDS.every((field) => Object.hasOwn(parsed.fields, field) && LOCKED_ANSWERED_BY.has(parsed.answered_by[field]))
110
110
  }
111
111
 
112
+ /** The brief's `meaning check` field turns the meaning verifier off only when it reads "off". */
113
+ export function meaningCheckEnabled(parsed) {
114
+ return !/^off\b/iu.test(parsed?.fields?.["meaning check"] ?? "")
115
+ }
116
+
112
117
  function incompleteDefect(briefPath, parsed) {
113
118
  const reasons = []
114
119
  if (!parsed.present) reasons.push("no ## Fidelity block")
@@ -0,0 +1,89 @@
1
+ // fidelity-claims.mjs - the claim-kind checks of the deterministic fidelity gate.
2
+ //
3
+ // A mark (the data-claim-kind attribute) binds per cited fact: a data-fact element takes the kind
4
+ // of its nearest mark (its own, else the closest marked ancestor), and only that kind is checked
5
+ // against its ledger row (claim-kinds.mjs CLAIM_KINDS); a row that fails is the kind's defect
6
+ // (unsupported_verification for `verified`). A fact under two marks of different kinds is a
7
+ // claim_kind_mismatch, and a mark that owns no fact of its own kind (every fact under it cites
8
+ // nothing or is shadowed by another kind) is its kind's defect: shadowing never satisfies a parent.
9
+ // An unmarked fact citing a row neither fact nor quote accepts (an assumed row) is a
10
+ // claim_kind_mismatch naming the mark it needs. A sentence that matches a kind's unmarked patterns warns (minor, verification_claim_unmarked)
11
+ // unless every fact it cites is marked that kind; a sentence citing no fact warns unless its block
12
+ // is marked. No model, no network.
13
+
14
+ import { CLAIM_ATTRIBUTE, CLAIM_KINDS, claimSatisfied, unmarkedKinds, unmarkedRequires } from "./claim-kinds.mjs"
15
+ import { proseSentences } from "./fidelity-binding.mjs"
16
+ import { clip } from "./fidelity-trace.mjs"
17
+ import { proseText } from "./html-lite.mjs"
18
+
19
+ const marked = (node) => node.attrs?.[CLAIM_ATTRIBUTE] !== undefined
20
+ const kindOf = (node) => node.attrs[CLAIM_ATTRIBUTE].trim()
21
+ const isFact = (node) => node.attrs["data-fact"] !== undefined
22
+
23
+ /** The marks over a node, nearest first: its own mark, then each marked ancestor. */
24
+ function marksOver(node) {
25
+ const marks = []
26
+ for (let cur = node; cur; cur = cur.parent) if (marked(cur)) marks.push(cur)
27
+ return marks
28
+ }
29
+
30
+ const nearestKind = (node) => {
31
+ const [mark] = marksOver(node)
32
+ return mark ? kindOf(mark) : null
33
+ }
34
+
35
+ /** Whether `mark` binds `fact`: every mark from the fact up to `mark` names the same kind. */
36
+ function binds(mark, fact) {
37
+ const marks = marksOver(fact)
38
+ const at = marks.indexOf(mark)
39
+ return at >= 0 && marks.slice(0, at + 1).every((cur) => kindOf(cur) === kindOf(mark))
40
+ }
41
+
42
+ /**
43
+ * @param {object} ctx buildContext(...) from gates-static.mjs
44
+ * @param {Map<string, object>} rows ledger rows by fact_id
45
+ * @param {(row: object) => string | undefined} provenanceOf meta.json kind of the snapshot holding the row's own locator artifact
46
+ * @param {(code: string, node: object, message: string) => void} flag
47
+ */
48
+ export function claimChecks(ctx, rows, provenanceOf, flag) {
49
+ for (const node of ctx.all.filter(marked)) {
50
+ const name = kindOf(node)
51
+ const entry = CLAIM_KINDS[name]
52
+ if (!entry) {
53
+ flag("claim_kind_mismatch", node, `${CLAIM_ATTRIBUTE}="${name}" is not a claim kind (${Object.keys(CLAIM_KINDS).join(", ")})`)
54
+ continue
55
+ }
56
+ const cited = [node, ...ctx.util.descendants(node)].filter(isFact)
57
+ if (cited.some((fact) => binds(node, fact))) continue
58
+ const why = cited.length === 0 ? "cites no fact" : "cites no fact of its own (a nested mark of another kind never satisfies it)"
59
+ flag(entry.defect, node, `"${clip(proseText(node))}" is marked ${name} but ${why}`)
60
+ }
61
+ for (const fact of ctx.all.filter(isFact)) {
62
+ const [nearest, ...outer] = marksOver(fact)
63
+ const id = fact.attrs["data-fact"]
64
+ if (!nearest) {
65
+ const need = unmarkedRequires(rows.get(id))
66
+ const mark = need && `{{${CLAIM_KINDS[need].prefix}:${id}}} (${CLAIM_ATTRIBUTE}="${need}")`
67
+ if (need) flag("claim_kind_mismatch", fact, `${id} is a ${rows.get(id).kind} row cited with no mark; an unmarked numeral reads as a fact, so mark it ${mark}`)
68
+ continue
69
+ }
70
+ const name = kindOf(nearest)
71
+ const conflict = outer.find((mark) => kindOf(mark) !== name)
72
+ if (conflict) flag("claim_kind_mismatch", fact, `${id} is marked ${name} inside a ${kindOf(conflict)} mark; a fact carries one claim kind`)
73
+ const entry = CLAIM_KINDS[name]
74
+ const row = rows.get(id)
75
+ if (!entry || !row || claimSatisfied(name, row, provenanceOf(row))) continue
76
+ const source = entry.sourceKinds ? ` and not one whose own locator artifact sits in a ${entry.sourceKinds.join(" or ")} snapshot` : ""
77
+ flag(entry.defect, fact, `${row.fact_id} is marked ${name}, but it is a ${row.kind} row${source}`)
78
+ }
79
+ for (const block of proseSentences(ctx)) {
80
+ if (block.kind === "sources" || block.kind === "toc") continue
81
+ for (const sentence of block.sentences) {
82
+ for (const name of unmarkedKinds(sentence.text)) {
83
+ const covered = sentence.facts.length > 0 ? sentence.facts.every((fact) => nearestKind(fact.node) === name) : nearestKind(block.owner) === name
84
+ if (covered) continue
85
+ flag(CLAIM_KINDS[name].unmarked.code, block.owner, `"${clip(sentence.text)}" reads as a ${name} claim but cites a fact with no ${CLAIM_ATTRIBUTE}="${name}" mark`)
86
+ }
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,145 @@
1
+ // fidelity-lexicon.mjs - closed-list lexical checks over (source quote, report sentence) pairs.
2
+ //
3
+ // lexiconChecks compares each pair with the lexicon.mjs lists: hedge_dropped, direction_flipped,
4
+ // causality_added, qualifier_dropped (six-token window around the fact span; a :q rendering puts
5
+ // the qualifier inside the span), scope_widened_warn, and the acronym-aware name_outside_quote.
6
+ // The hedge-position heuristic never yields a code; it only sets force_strong for the meaning
7
+ // verifier, as do name_outside_quote and scope_widened_warn. Latin terms match whole words (terms
8
+ // of four or more letters also match their inflections); Korean terms match as substrings, single
9
+ // syllables as tokens. No model, no IO. Plain Node ESM; Korean strings are \u escapes.
10
+
11
+ import { CAUSAL, CONCESSIVE, DIRECTION, HEDGES, NEGATION, QUALIFIERS, SCOPE_NARROW_TO_BROAD } from "./lexicon.mjs"
12
+ import { normalizeText } from "./text-normalize.mjs"
13
+ import { normalizeUnit } from "./units.mjs"
14
+
15
+ /** Ledger qualifier terms -> their surface forms in either language (closed mapping). */
16
+ export const QUALIFIER_FORMS = Object.freeze({
17
+ upper_inclusive: ["up to", "at most", "\uCD5C\uB300", "\uC774\uD558", "\uAE4C\uC9C0"],
18
+ lower_inclusive: ["at least", "\uCD5C\uC18C", "\uC774\uC0C1"],
19
+ approximate: ["about", "approximately", "\uC57D", "\uB0B4\uC678"],
20
+ near: ["nearly"],
21
+ lower_exclusive: ["over", "more than", "\uCD08\uACFC"],
22
+ upper_exclusive: ["under", "less than", "\uBBF8\uB9CC"],
23
+ })
24
+ /** Irregular and synonym direction forms the stem match cannot reach ("rose", "reduced"). */
25
+ const DIRECTION_FORMS = { up: ["rose", "risen", "rising", "grew", "grown", "gain"], down: ["reduc", "fell", "fallen", "falling", "drop", "lower"] }
26
+ const KOREAN = /[\uAC00-\uD7A3]/
27
+ /** True when the term holds a Hangul syllable (Korean terms match by the Korean rules below). */
28
+ export const isKoreanTerm = (term) => KOREAN.test(term)
29
+ /** The guarded hedge and qualifier vocabulary: the union of HEDGES, QUALIFIERS and every QUALIFIER_FORMS surface form. */
30
+ export const guardedTerms = () => [...new Set([...HEDGES, ...QUALIFIERS, ...Object.values(QUALIFIER_FORMS).flat()])]
31
+ const ACRONYM = /(?<![\p{L}\p{N}])[A-Z]{2,6}(?![\p{L}\p{N}])/gu
32
+ const WINDOW = 6
33
+ const cache = new Map()
34
+
35
+ const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
36
+
37
+ /**
38
+ * The lexical pattern engine. mode: "stem" (inflections, Korean one-syllable token prefix), "exact",
39
+ * "word", "suffix" (Korean attached to a value), "guard" (single Latin words of four or more letters
40
+ * take inflections, multiword terms never do; Korean terms match as plain substrings).
41
+ */
42
+ export function lexicalPattern(term, mode) {
43
+ const key = `${mode}\u0001${term}`
44
+ if (cache.has(key)) return cache.get(key)
45
+ let source
46
+ if (!KOREAN.test(term)) {
47
+ const stems = term.length >= 4 && (mode === "stem" || (mode === "guard" && !term.includes(" ")))
48
+ source = `(?<![\\p{L}\\p{N}])${escape(term).replace(/ /g, "\\s+")}${stems ? "\\p{L}*" : ""}(?![\\p{L}\\p{N}])`
49
+ } else if (mode === "guard") source = escape(term)
50
+ else if (mode === "suffix") source = `(?<=^|[\\s\\p{P}\\p{N}A-Za-z])${escape(term)}(?=$|[\\s\\p{P}])`
51
+ else if ([...term].length >= 2 || mode === "word") source = escape(term)
52
+ else source = `(?<=^|[\\s\\p{P}])${escape(term)}${mode === "stem" ? "" : "(?=$|[\\s\\p{P}])"}`
53
+ const re = new RegExp(source, "giu")
54
+ cache.set(key, re)
55
+ return re
56
+ }
57
+
58
+ function positions(text, terms, mode) {
59
+ const out = []
60
+ for (const term of terms) for (const match of text.matchAll(lexicalPattern(term, mode))) out.push({ term, at: match.index })
61
+ return out.sort((a, b) => a.at - b.at)
62
+ }
63
+
64
+ const has = (text, terms, mode) => positions(text, terms, mode).length > 0
65
+ const tokens = (text) => text.split(/\s+/).filter(Boolean)
66
+ const stripQualifiers = (text) => QUALIFIERS.reduce((rest, term) => rest.replace(lexicalPattern(term, "exact"), " "), text)
67
+
68
+ function directions(text) {
69
+ const rest = stripQualifiers(text)
70
+ return {
71
+ up: has(rest, DIRECTION.up, "stem") || has(rest, DIRECTION_FORMS.up, "stem"),
72
+ down: has(rest, DIRECTION.down, "stem") || has(rest, DIRECTION_FORMS.down, "stem"),
73
+ }
74
+ }
75
+
76
+ /** The fact span plus up to six tokens on each side, never crossing the sentence. */
77
+ function qualifierWindow(sentence, span) {
78
+ const [start, end] = span
79
+ return [...tokens(sentence.slice(0, start)).slice(-WINDOW), sentence.slice(start, end), ...tokens(sentence.slice(end)).slice(0, WINDOW)].join(" ")
80
+ }
81
+
82
+ function qualifierDropped(pair) {
83
+ if (!pair.qualifier || !Array.isArray(pair.span)) return false
84
+ const forms = QUALIFIER_FORMS[pair.qualifier] ?? [pair.qualifier]
85
+ const window = qualifierWindow(pair.sentence, pair.span)
86
+ return !forms.some((form) => has(window, [form], KOREAN.test(form) ? "suffix" : "exact"))
87
+ }
88
+
89
+ /** A hedge before the sentence's last concessive while the quote hedges its own final clause. */
90
+ function hedgeMoved(quote, sentence) {
91
+ const lastConcessive = (text) => positions(text, CONCESSIVE, "word").at(-1)?.at ?? -1
92
+ const sentenceHedge = positions(sentence, HEDGES, "stem")[0]?.at
93
+ const quoteHedge = positions(quote, HEDGES, "stem").at(-1)?.at
94
+ const sentenceConcessive = lastConcessive(sentence)
95
+ return sentenceHedge !== undefined && quoteHedge !== undefined && sentenceHedge < sentenceConcessive && quoteHedge > lastConcessive(quote)
96
+ }
97
+
98
+ function pairFindings(pair) {
99
+ const quote = normalizeText(pair.quote)
100
+ const sentence = normalizeText(pair.sentence)
101
+ const found = []
102
+ const add = (code, message) => found.push({ pair_id: pair.pair_id, code, message })
103
+ const dropped = qualifierDropped(pair)
104
+ if (dropped) add("qualifier_dropped", `the source bounds the value (${pair.qualifier}) and the sentence drops it`)
105
+ const sourceHedges = positions(quote, HEDGES, "stem")
106
+ const qualifierOnly = sourceHedges.every(({ term }) => QUALIFIERS.includes(term))
107
+ if (sourceHedges.length > 0 && !has(sentence, HEDGES, "stem") && !(dropped && qualifierOnly)) {
108
+ add("hedge_dropped", `the source hedges ("${sourceHedges[0].term}") and the sentence does not`)
109
+ }
110
+ const [from, to] = [directions(quote), directions(sentence)]
111
+ const negated = has(quote, NEGATION, "word") || has(sentence, NEGATION, "word")
112
+ if (!negated && ((from.up && !from.down && to.down && !to.up) || (from.down && !from.up && to.up && !to.down))) {
113
+ add("direction_flipped", `the source says ${from.up ? "up" : "down"} and the sentence says ${to.up ? "up" : "down"}`)
114
+ }
115
+ const causal = positions(sentence, CAUSAL, "word").find(({ term }) => !has(quote, [term], "word"))
116
+ if (causal) add("causality_added", `"${causal.term}" states a cause the source does not`)
117
+ const context = [quote, ...(pair.context ?? []).map(normalizeText)]
118
+ for (const [narrow, broad] of SCOPE_NARROW_TO_BROAD) {
119
+ if (has(quote, [narrow], "word") && has(sentence, [broad], "word") && !context.some((text) => has(text, [broad], "word"))) {
120
+ add("scope_widened_warn", `the source says "${narrow}" and the sentence says "${broad}"`)
121
+ }
122
+ }
123
+ const acronyms = pair.acronyms ?? {}
124
+ const quoteNames = new Set(quote.match(ACRONYM) ?? [])
125
+ const stray = (sentence.match(ACRONYM) ?? []).find((name) => !quoteNames.has(name) && !Object.hasOwn(acronyms, name) && !normalizeUnit(name))
126
+ if (stray) add("name_outside_quote", `"${stray}" is in neither the quote nor the source's acronym table`)
127
+ return found
128
+ }
129
+
130
+ /**
131
+ * @param {{ pair_id: string, quote: string, sentence: string, span?: [number, number] | null,
132
+ * qualifier?: string | null, acronyms?: Record<string, string>, context?: string[] }[]} pairs
133
+ * @returns {{ findings: { pair_id: string, code: string, message: string }[], forceStrong: string[] }}
134
+ */
135
+ export function lexiconChecks(pairs) {
136
+ const findings = []
137
+ const forceStrong = []
138
+ for (const pair of pairs) {
139
+ const found = pairFindings(pair)
140
+ findings.push(...found)
141
+ const routed = found.some(({ code }) => code === "name_outside_quote" || code === "scope_widened_warn")
142
+ if (routed || hedgeMoved(normalizeText(pair.quote), normalizeText(pair.sentence))) forceStrong.push(pair.pair_id)
143
+ }
144
+ return { findings, forceStrong }
145
+ }