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
@@ -18,14 +18,19 @@ import { PROSE_TAGS, proseText, selectorPath } from "./html-lite.mjs"
18
18
  const CITATION_MARKER = /\[S\d+\]|\[Source\s*\d+\]|\[\uCD9C\uCC98[^\]]*\]|\[\^\d+\]/i
19
19
  const ANCHOR_HREF = /^#(?:s|src|source|ref|fn)/i
20
20
  const ANCHOR_TEXT = /^\[(?:\uCD9C\uCC98|Source\s*\d+|S\d+)\]$/i
21
- /** Closing ("how this report was made") heading; Korean alternates cover the same register. */
22
- export const CLOSING_HEADING = /\b(?:method(?:ology)?|how)\b|\uB4B7\uBA74|\uBC29\uBC95|\uC5B4\uB5BB\uAC8C|\uB9CC\uB4E4\uC5B4/i
21
+ /**
22
+ * Closing ("how this report was made") heading; Korean alternates cover the same register. A
23
+ * heading that is exactly "Closing" (or the Korean word for it) also counts; a heading that only
24
+ * starts with it ("Closing the gap") does not.
25
+ */
26
+ export const CLOSING_HEADING = /\b(?:method(?:ology)?|how)\b|\uB4B7\uBA74|\uBC29\uBC95|\uC5B4\uB5BB\uAC8C|\uB9CC\uB4E4\uC5B4|^\s*(?:closing|\uB9C8\uBB34\uB9AC)\s*$/i
23
27
  export const SOURCES_HEADING = /references|sources|bibliography|\uCD9C\uCC98|\uCC38\uACE0\s*(?:\uBB38\uD5CC|\uC790\uB8CC)/i
24
- const OTHER_KINDS = [
28
+ /** Section kinds after sources and closing, in match order; HTML and Markdown share this table. */
29
+ export const OTHER_KINDS = Object.freeze([
25
30
  ["toc", /\b(?:contents|toc)\b|\uBAA9\uCC28/i],
26
31
  ["appendix", /appendix|\uBD80\uB85D/i],
27
32
  ["glossary", /glossary|\uC6A9\uC5B4/i],
28
- ]
33
+ ])
29
34
  const TEXT_SKIP = new Set(["code", "pre", "kbd", "samp", "script", "style", "svg", "template", "noscript"])
30
35
  const HEADING_TAG = /^h[1-6]$/
31
36
  /** The one sanctioned severity override: section-level lineage demotes unsourced_number. */
@@ -75,9 +80,25 @@ function findBody(doc) {
75
80
  return doc
76
81
  }
77
82
 
78
- function sectionKind(text, closingTest) {
83
+ /**
84
+ * Closing-heading test for both editions: CLOSING_HEADING plus the spec's optional pattern.
85
+ * @param {RegExp|string|null} [pattern]
86
+ * @returns {(text: string) => boolean}
87
+ */
88
+ export function closingTest(pattern) {
89
+ const extra = pattern ? toRegExp(pattern) : null
90
+ return (text) => CLOSING_HEADING.test(text) || Boolean(extra?.test(text))
91
+ }
92
+
93
+ /**
94
+ * Section kind of an h2 heading text: sources, closing, toc, appendix, glossary, or null.
95
+ * @param {string} text
96
+ * @param {(text: string) => boolean} isClosing
97
+ * @returns {string|null}
98
+ */
99
+ export function sectionKind(text, isClosing) {
79
100
  if (SOURCES_HEADING.test(text)) return "sources"
80
- if (closingTest(text)) return "closing"
101
+ if (isClosing(text)) return "closing"
81
102
  return OTHER_KINDS.find(([, re]) => re.test(text))?.[0] ?? null
82
103
  }
83
104
 
@@ -111,7 +132,6 @@ function walkBody(ctx, node, state) {
111
132
  export function buildContext(doc, options) {
112
133
  const lineageMode = options.lineageMode ?? "inline"
113
134
  if (!LINEAGE_MODES.includes(lineageMode)) throw new TypeError(`lineageMode must be one of ${LINEAGE_MODES.join(", ")}`)
114
- const closingPattern = options.closingPattern ? toRegExp(options.closingPattern) : null
115
135
  const all = descendants(doc)
116
136
  const styleBlocks = all.filter((node) => node.tag === "style").map((node) => ({ node, css: node.raw ?? "" }))
117
137
  const styleAttrs = all.filter((node) => node.attrs.style).map((node) => ({ node, css: node.attrs.style }))
@@ -130,7 +150,7 @@ export function buildContext(doc, options) {
130
150
  requireSections: (options.requireSections ?? []).map(toRegExp),
131
151
  baseDir: options.baseDir ?? null,
132
152
  fs: options.fs ?? nodeFs,
133
- isClosing: (text) => CLOSING_HEADING.test(text) || Boolean(closingPattern?.test(text)),
153
+ isClosing: closingTest(options.closingPattern),
134
154
  util: { classTokens, closest, descendants, hasCitation, citationMarker: CITATION_MARKER },
135
155
  kindOf: (scope) => (scope.closingH3 ? "closing" : (scope.section?.kind ?? null)),
136
156
  defect(code, node, message) {
@@ -54,8 +54,8 @@ function skipSpaces(source, at) {
54
54
  return at
55
55
  }
56
56
 
57
- /** Read `<name attrs...>` starting just after `<`. */
58
- function readTag(source, start) {
57
+ /** Read `<name attrs...>` starting just after `<`; the one attribute parser (any quoting). */
58
+ export function readTag(source, start) {
59
59
  const end = source.length
60
60
  let at = start
61
61
  while (at < end && !isSpace(source[at]) && source[at] !== ">" && source[at] !== "/") at++
@@ -0,0 +1,182 @@
1
+ // Byte-preserving HTML boundaries for polish. No CSS or visibility inference.
2
+ import { readTag } from "./html-lite.mjs"
3
+
4
+ const RAW = new Set(["script", "style"])
5
+ const FROZEN = new Set([...RAW, "template"])
6
+ const VOID = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"])
7
+ const isLetter = (ch) => /[a-z]/i.test(ch ?? "")
8
+
9
+ function scan(src, at, visit) {
10
+ while (at < src.length) {
11
+ const start = src.indexOf("<", at)
12
+ if (start === -1) return
13
+ const next = src[start + 1]
14
+ let kind
15
+ let end
16
+ let tag = null
17
+ if (src.startsWith("<!--", start)) {
18
+ // From start + 2 so the abrupt closes <!--> and <!---> end where the HTML tokenizer ends them.
19
+ kind = "skip"
20
+ const stop = src.indexOf("-->", start + 2)
21
+ end = stop === -1 ? src.length : stop + 3
22
+ } else if (next === "!" || next === "?" || (next === "/" && !isLetter(src[start + 2]))) {
23
+ // Declarations, <?...> and </ + non-letter (</> included) are bogus comments up to the next ">".
24
+ kind = "skip"
25
+ const stop = src.indexOf(">", start + 2)
26
+ end = stop === -1 ? src.length : stop + 1
27
+ } else if (isLetter(next) || (next === "/" && isLetter(src[start + 2]))) {
28
+ kind = next === "/" ? "close" : "open"
29
+ tag = readTag(src, start + (kind === "close" ? 2 : 1))
30
+ end = tag.end
31
+ } else {
32
+ at = start + 1
33
+ continue
34
+ }
35
+ const resume = visit(kind, start, end, tag)
36
+ if (resume === Infinity) return
37
+ at = resume ?? (kind === "open" && RAW.has(tag.name) ? closeOf(src, end, tag.name) : end)
38
+ }
39
+ }
40
+
41
+ // Script data with its escaped and double-escaped states: a </script> inside <!--<script>...-->
42
+ // does not end the script. Returns the end of the closing tag, or the end of input.
43
+ const SCRIPT_MARKS = { data: /<!--|<\/script(?=[\s/>])/gi, escaped: /-->|<\/?script(?=[\s/>])/gi, double: /-->|<\/script(?=[\s/>])/gi }
44
+ function scriptEnd(src, from) {
45
+ let state = "data"
46
+ let at = from
47
+ for (;;) {
48
+ const marks = SCRIPT_MARKS[state]
49
+ marks.lastIndex = at
50
+ const match = marks.exec(src)
51
+ if (!match) return src.length
52
+ const token = match[0].toLowerCase()
53
+ if (token === "-->") [state, at] = ["data", match.index + 3]
54
+ else if (token === "<!--") [state, at] = ["escaped", match.index + 2]
55
+ else if (token === "<script") [state, at] = ["double", match.index + 7]
56
+ else if (state === "double") [state, at] = ["escaped", match.index + 8]
57
+ else return readTag(src, match.index + 2).end
58
+ }
59
+ }
60
+
61
+ function closeOf(src, from, name) {
62
+ if (name === "script") return scriptEnd(src, from)
63
+ if (RAW.has(name)) {
64
+ const close = new RegExp(`</${name}(?=[\\s/>])[^>]*>`, "gi")
65
+ close.lastIndex = from
66
+ const match = close.exec(src)
67
+ return match ? match.index + match[0].length : src.length
68
+ }
69
+ let depth = 0
70
+ let stop = src.length
71
+ scan(src, from, (kind, _start, end, tag) => {
72
+ if (tag?.name !== name) return undefined
73
+ if (kind === "open") depth++
74
+ else if (depth === 0) {
75
+ stop = end
76
+ return Infinity
77
+ } else depth--
78
+ return undefined
79
+ })
80
+ return stop
81
+ }
82
+
83
+ const endOf = (src, end, tag) => VOID.has(tag.name) ? end : closeOf(src, end, tag.name)
84
+
85
+ /** Raw markup sequence, corresponding text slots, and markup with frozen elements omitted. */
86
+ export function markupParts(html) {
87
+ const src = String(html)
88
+ const markup = []
89
+ const text = []
90
+ let source = ""
91
+ let kept = 0
92
+ scan(src, 0, (kind, start, end, tag) => {
93
+ const frozen = kind === "open" && FROZEN.has(tag.name)
94
+ const stop = frozen ? endOf(src, end, tag) : end
95
+ text.push(src.slice(kept, start))
96
+ markup.push(src.slice(start, stop))
97
+ source += src.slice(kept, start) + (frozen || kind === "skip" ? " " : src.slice(start, stop))
98
+ kept = stop
99
+ return stop
100
+ })
101
+ text.push(src.slice(kept))
102
+ source += src.slice(kept)
103
+ return { markup, text, source }
104
+ }
105
+
106
+ /** Whole elements accepted by the caller; nested matches stay within the outer match. */
107
+ export function elementSpans(html, accept) {
108
+ const src = String(html)
109
+ const spans = []
110
+ scan(src, 0, (kind, start, end, tag) => {
111
+ if (kind !== "open" || !accept(tag.name, tag.attrs)) return undefined
112
+ const stop = endOf(src, end, tag)
113
+ spans.push({ start, end: stop, tag })
114
+ return stop
115
+ })
116
+ return spans
117
+ }
118
+
119
+ export function tagAttributes(html) {
120
+ const tags = []
121
+ scan(String(html), 0, (kind, _start, _end, tag) => {
122
+ if (kind === "open") tags.push({ name: tag.name, attrs: tag.attrs })
123
+ return undefined
124
+ })
125
+ return tags
126
+ }
127
+
128
+ /**
129
+ * Constructs this tokenizer does not model exactly; renderer output never contains them, so polish
130
+ * refuses a document holding any of them instead of trusting the markup comparison.
131
+ */
132
+ export function ambiguousMarkup(html) {
133
+ const src = String(html)
134
+ const found = new Set()
135
+ if (/<\/(?![a-z])/i.test(src)) found.add("</ before a non-letter")
136
+ if (/<!\[CDATA\[/i.test(src)) found.add("<![CDATA[")
137
+ if (src.includes("<?")) found.add("<?")
138
+ if (src.includes("--!>")) found.add("--!>")
139
+ scan(src, 0, (kind, start, end, tag) => {
140
+ if (kind !== "skip" && src.slice(start + 1, end).includes("<")) found.add("< inside a tag or attribute value")
141
+ if (kind === "open" && RAW.has(tag.name) && src.slice(end, closeOf(src, end, tag.name)).includes("<!--")) found.add(`<!-- inside ${tag.name}`)
142
+ return undefined
143
+ })
144
+ return [...found]
145
+ }
146
+
147
+ /** One character reference token of a text node: & up to the first ; or non-name character. */
148
+ export const CHARACTER_REFERENCE = /&[^;\s<&]*;?/g
149
+
150
+ /**
151
+ * The skeleton of a document: every markup token (tags, comments, bogus comments and the frozen
152
+ * content of script/style/template) and every character reference of a text node, in document
153
+ * order, each with its byte offset. Polish may change text node characters only, and an edit can
154
+ * carry neither <, > nor & and may not touch a character reference, so an edited span holds no
155
+ * skeleton token: a polished document keeps this sequence byte-identical.
156
+ */
157
+ export function skeletonTokens(html) {
158
+ const { markup, text } = markupParts(html)
159
+ const tokens = []
160
+ let at = 0
161
+ text.forEach((slot, index) => {
162
+ for (const match of slot.matchAll(CHARACTER_REFERENCE)) tokens.push({ kind: "reference", value: match[0], offset: at + match.index })
163
+ at += slot.length
164
+ if (index < markup.length) {
165
+ tokens.push({ kind: "markup", value: markup[index], offset: at })
166
+ at += markup[index].length
167
+ }
168
+ })
169
+ return tokens
170
+ }
171
+
172
+ const describeToken = (token) => (token ? `${token.kind} ${JSON.stringify(token.value)} at offset ${token.offset}` : "end of document")
173
+
174
+ /** The first skeleton token two documents disagree on, as a message, or null when they agree. */
175
+ export function skeletonChange(beforeHtml, afterHtml) {
176
+ const [before, after] = [skeletonTokens(beforeHtml), skeletonTokens(afterHtml)]
177
+ for (let index = 0; index < Math.max(before.length, after.length); index++) {
178
+ if (before[index]?.value === after[index]?.value) continue
179
+ return `skeleton changed at token ${index}: ${describeToken(before[index])} became ${describeToken(after[index])}`
180
+ }
181
+ return null
182
+ }
@@ -0,0 +1,193 @@
1
+ // md-lite.mjs - a light Markdown block model for md/post deliverables.
2
+ //
3
+ // parseMarkdown(text) returns { blocks } in document order, each block one of heading,
4
+ // paragraph, list_item, table_row, code, blockquote, with start/end offsets into the raw text
5
+ // so text.slice(start, end) === block.text (table cells carry their own offsets). Headings carry
6
+ // level 1-6. Code blocks are fenced (``` or ~~~); an unterminated fence runs to the end of the
7
+ // text and is reported in problems as unterminated_fence, which a caller must refuse rather than
8
+ // skip. Callers skip kind 'code' when they look for numbers. sectionKindsMd(blocks) classifies
9
+ // sections with the gates-static classifier itself (sectionKind, closingTest). It never renders
10
+ // HTML. Plain Node ESM, sibling imports only.
11
+
12
+ import { closingTest, sectionKind } from "./gates-static.mjs"
13
+
14
+ export { closingTest, sectionKind }
15
+
16
+ /** A fence opener: a backtick fence's info string holds no backtick (else it is an inline span). */
17
+ const FENCE = /^ {0,3}(?:(`{3,})[^`]*|(~{3,}).*)$/
18
+ const HEADING = /^ {0,3}(#{1,6})(?=[ \t]|$)/
19
+ const BLOCKQUOTE = /^ {0,3}> ?/
20
+ /** A bullet or an ordered marker (digits, then . or ), then a space); group 1 is the number. */
21
+ const LIST_ITEM = /^[ \t]*(?:[-*+]|(\d{1,9})[.)])[ \t]+/
22
+ const TABLE_SEPARATOR = /^[ \t]*\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/
23
+ const CLOSING_HASHES = /[ \t]+#+[ \t]*$|^#+[ \t]*$/
24
+ const THEMATIC_BREAK = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/
25
+
26
+ /** The Markdown block grammar, one named pattern per syntax. */
27
+ export const MD_BLOCK_PATTERNS = Object.freeze({ FENCE, HEADING, BLOCKQUOTE, LIST_ITEM, TABLE_SEPARATOR, CLOSING_HASHES, THEMATIC_BREAK })
28
+
29
+ /** Split into lines with offsets; end excludes the newline and a trailing carriage return. */
30
+ function linesOf(text) {
31
+ const lines = []
32
+ let start = 0
33
+ while (start <= text.length) {
34
+ const newline = text.indexOf("\n", start)
35
+ const next = newline === -1 ? text.length + 1 : newline + 1
36
+ let end = newline === -1 ? text.length : newline
37
+ if (end > start && text[end - 1] === "\r") end--
38
+ lines.push({ start, end, next, raw: text.slice(start, end) })
39
+ start = next
40
+ }
41
+ return lines
42
+ }
43
+
44
+ /** Narrow [start, end) to its non-whitespace core. */
45
+ function trimRange(text, start, end) {
46
+ let from = start
47
+ let to = end
48
+ while (from < to && /\s/.test(text[from])) from++
49
+ while (to > from && /\s/.test(text[to - 1])) to--
50
+ return { start: from, end: to }
51
+ }
52
+
53
+ function block(text, kind, range, extra = {}) {
54
+ return { kind, ...extra, text: text.slice(range.start, range.end), start: range.start, end: range.end }
55
+ }
56
+
57
+ function isSeparator(line) {
58
+ return line !== undefined && line.raw.includes("-") && TABLE_SEPARATOR.test(line.raw)
59
+ }
60
+
61
+ /** Cells split on unescaped pipes, outer pipes dropped, each cell trimmed with offsets. */
62
+ function tableCells(text, range) {
63
+ const bounds = []
64
+ for (let k = range.start; k < range.end; k++) {
65
+ let slashes = 0
66
+ while (k - slashes - 1 >= range.start && text[k - slashes - 1] === "\\") slashes++
67
+ if (text[k] === "|" && slashes % 2 === 0) bounds.push(k)
68
+ }
69
+ const edges = [range.start - 1, ...bounds, range.end]
70
+ if (bounds[0] === range.start) edges.shift()
71
+ if (bounds.at(-1) === range.end - 1 && bounds.length > 0) edges.pop()
72
+ const cells = []
73
+ for (let k = 0; k + 1 < edges.length; k++) {
74
+ const cell = trimRange(text, edges[k] + 1, edges[k + 1])
75
+ cells.push({ text: text.slice(cell.start, cell.end), start: cell.start, end: cell.end })
76
+ }
77
+ return cells
78
+ }
79
+
80
+ function headingBlock(text, line, marker) {
81
+ const after = line.start + line.raw.indexOf(marker) + marker.length
82
+ const range = trimRange(text, after, line.end)
83
+ const closing = text.slice(range.start, range.end).match(CLOSING_HASHES)
84
+ if (closing) range.end = trimRange(text, range.start, range.start + (closing.index ?? 0)).end
85
+ return block(text, "heading", range, { level: marker.length })
86
+ }
87
+
88
+ /**
89
+ * Parse Markdown into a flat block list.
90
+ * @param {string} text
91
+ * @returns {{ blocks: { kind: string, level?: number, text: string, start: number, end: number,
92
+ * cells?: { text: string, start: number, end: number }[] }[],
93
+ * problems: { code: "unterminated_fence", line: number, start: number }[] }}
94
+ */
95
+ export function parseMarkdown(text) {
96
+ const source = String(text ?? "")
97
+ const lines = linesOf(source)
98
+ const blocks = []
99
+ const problems = []
100
+ let paragraph = null
101
+ let inTable = false
102
+ const flush = () => {
103
+ if (paragraph) blocks.push(block(source, "paragraph", paragraph))
104
+ paragraph = null
105
+ }
106
+ for (let i = 0; i < lines.length; i++) {
107
+ const line = lines[i]
108
+ const fence = line.raw.match(FENCE)
109
+ if (fence) {
110
+ flush()
111
+ inTable = false
112
+ const open = fence[1] ?? fence[2]
113
+ const codeStart = Math.min(line.next, source.length)
114
+ let close = lines.length
115
+ for (let k = i + 1; k < lines.length; k++) {
116
+ const candidate = lines[k].raw.trim()
117
+ if (candidate.startsWith(open[0].repeat(open.length)) && /^(`+|~+)$/.test(candidate)) {
118
+ close = k
119
+ break
120
+ }
121
+ }
122
+ let codeEnd = source.length
123
+ if (close === lines.length) problems.push({ code: "unterminated_fence", line: i + 1, start: line.start })
124
+ else {
125
+ codeEnd = Math.max(codeStart, lines[close].start - 1)
126
+ if (codeEnd > codeStart && source[codeEnd - 1] === "\r") codeEnd--
127
+ }
128
+ blocks.push(block(source, "code", { start: codeStart, end: codeEnd }))
129
+ i = close
130
+ continue
131
+ }
132
+ if (line.raw.trim() === "") {
133
+ flush()
134
+ inTable = false
135
+ continue
136
+ }
137
+ const range = trimRange(source, line.start, line.end)
138
+ if (!inTable && line.raw.includes("|") && isSeparator(lines[i + 1])) inTable = true
139
+ if (inTable && line.raw.includes("|")) {
140
+ flush()
141
+ if (!isSeparator(line)) blocks.push(block(source, "table_row", range, { cells: tableCells(source, range) }))
142
+ continue
143
+ }
144
+ inTable = false
145
+ const heading = line.raw.match(HEADING)
146
+ if (heading) {
147
+ flush()
148
+ blocks.push(headingBlock(source, line, heading[1]))
149
+ continue
150
+ }
151
+ if (THEMATIC_BREAK.test(line.raw)) {
152
+ flush()
153
+ continue
154
+ }
155
+ const marker = line.raw.match(BLOCKQUOTE) ?? line.raw.match(LIST_ITEM)
156
+ // Only an ordered marker numbered 1 may interrupt a paragraph (CommonMark); else it is text.
157
+ const continues = paragraph !== null && marker?.[1] !== undefined && Number(marker[1]) !== 1
158
+ if (marker && !continues) {
159
+ flush()
160
+ const kind = BLOCKQUOTE.test(line.raw) ? "blockquote" : "list_item"
161
+ const content = trimRange(source, line.start + marker[0].length, line.end)
162
+ if (content.end > content.start) blocks.push(block(source, kind, content))
163
+ continue
164
+ }
165
+ if (paragraph) paragraph.end = range.end
166
+ else paragraph = { start: range.start, end: range.end }
167
+ }
168
+ flush()
169
+ return { blocks, problems }
170
+ }
171
+
172
+ /**
173
+ * Section kind of every block, parallel to blocks: an h2 opens a section whose kind comes from
174
+ * its heading text (sources, closing, toc, appendix, glossary, or null for findings); an h3 that
175
+ * reads as a closing heading marks its blocks closing until the next h2 or h3, as in gates-static.
176
+ * @param {{ kind: string, level?: number, text: string }[]} blocks
177
+ * @param {{ closingPattern?: RegExp|string }} [options] extra closing heading pattern (the spec's)
178
+ * @returns {(string|null)[]}
179
+ */
180
+ export function sectionKindsMd(blocks, options = {}) {
181
+ const isClosing = closingTest(options.closingPattern)
182
+ let section = null
183
+ let closingH3 = false
184
+ return blocks.map((entry) => {
185
+ if (entry.kind === "heading" && entry.level === 2) {
186
+ section = sectionKind(entry.text, isClosing)
187
+ closingH3 = false
188
+ } else if (entry.kind === "heading" && entry.level === 3) {
189
+ closingH3 = isClosing(entry.text)
190
+ }
191
+ return closingH3 ? "closing" : section
192
+ })
193
+ }
@@ -0,0 +1,196 @@
1
+ // meaning-check.mjs - ingest the meaning readers' verdicts over fact-pairs output.
2
+ //
3
+ // ingestVerdicts reads verdict files written by separate reader lanes (cheap and strong tiers),
4
+ // keeps a drift verdict only when its pair exists, its tier and drift_kind are in the closed sets,
5
+ // and both its fragment (from the sentence) and source_fragment (from the quote or statement) are
6
+ // non-empty substrings after whitespace normalization; every other verdict is dropped and logged.
7
+ // Both tiers naming the same drift_kind (not "other") on a pair is meaning_drift_confirmed (major,
8
+ // never integrity); one tier is meaning_drift_warn (minor). Each flagged pair yields one
9
+ // calibration line; a dispute is recorded there and never removes the defect. Coverage is
10
+ // fail-closed: every pair no reader judged, and every force_strong pair no strong reader judged,
11
+ // is listed in `unverified`, so a gate can tell a clean check apart from a pair nobody read.
12
+ // No model, no fetch.
13
+
14
+ import { appendFileSync, readFileSync } from "node:fs"
15
+
16
+ import { DEFECT_CODES } from "./contracts.mjs"
17
+
18
+ export const DRIFT_KINDS = Object.freeze([
19
+ "subject_changed", "scope_widened", "hedge_dropped", "certainty_added", "causality_added",
20
+ "direction_flipped", "population_changed", "evidence_grade_raised", "other",
21
+ ])
22
+ export const MODEL_TIERS = Object.freeze(["cheap", "strong"])
23
+ export const VERDICTS = Object.freeze(["drift", "ok"])
24
+ export const isDriftKind = (kind) => DRIFT_KINDS.includes(kind)
25
+ /** The machine-read verdict contract a reader lane receives with pairs.json; built from the registries above. */
26
+ export const VERDICT_SCHEMA = Object.freeze({
27
+ model_tier: MODEL_TIERS,
28
+ verdict: VERDICTS,
29
+ drift_kind: DRIFT_KINDS,
30
+ required: Object.freeze(["pair_id", "verdict"]),
31
+ drift_required: Object.freeze(["drift_kind", "fragment", "source_fragment"]),
32
+ })
33
+
34
+ /** NFC, every whitespace run collapsed to one space, trimmed. */
35
+ const squash = (text) => String(text ?? "").normalize("NFC").replace(/\s+/gu, " ").trim()
36
+
37
+ /** Read a verdict file, mapping an unreadable path or invalid JSON to a short typed error. */
38
+ function parseFile(path) {
39
+ let text
40
+ try {
41
+ text = readFileSync(path, "utf8")
42
+ } catch {
43
+ throw new TypeError(`${path}: cannot read the verdict file`)
44
+ }
45
+ try {
46
+ return JSON.parse(text)
47
+ } catch {
48
+ throw new TypeError(`${path}: the verdict file is not valid JSON`)
49
+ }
50
+ }
51
+
52
+ function verdictsOf(input) {
53
+ const label = typeof input === "string" ? input : "<inline>"
54
+ const parsed = typeof input === "string" ? parseFile(input) : input
55
+ const list = Array.isArray(parsed) ? parsed : parsed?.verdicts
56
+ if (!Array.isArray(list)) throw new TypeError(`${label}: a verdict file is an array of verdicts or { verdicts: [...] }`)
57
+ const tier = Array.isArray(parsed) ? undefined : parsed.model_tier
58
+ return list.map((verdict) => ({ verdict: tier === undefined || verdict?.model_tier !== undefined ? verdict : { ...verdict, model_tier: tier }, file: label }))
59
+ }
60
+
61
+ /** The reason a verdict is dropped, or null when it is accepted. */
62
+ function dropReason(verdict, pair) {
63
+ if (verdict === null || typeof verdict !== "object") return "malformed_verdict"
64
+ if (!pair) return "unknown_pair"
65
+ if (!VERDICTS.includes(verdict.verdict)) return "invalid_verdict"
66
+ if (!MODEL_TIERS.includes(verdict.model_tier)) return "invalid_model_tier"
67
+ if (verdict.verdict === "ok") return null
68
+ if (!isDriftKind(verdict.drift_kind)) return "unknown_drift_kind"
69
+ const [fragment, sourceFragment] = [squash(verdict.fragment), squash(verdict.source_fragment)]
70
+ if (fragment === "" || sourceFragment === "") return "empty_fragment"
71
+ if (!squash(pair.sentence).includes(fragment)) return "fragment_not_found"
72
+ const source = pair.kind === "claim" ? pair.statement : pair.quote
73
+ if (!squash(source).includes(sourceFragment)) return "source_fragment_not_found"
74
+ return null
75
+ }
76
+
77
+ function defect(code, pair, driftKind, tiers, verdicts) {
78
+ const entry = DEFECT_CODES[code]
79
+ // The fragment must come from the verdict whose drift_kind is being reported, not from whichever
80
+ // verdict happened to arrive first on the pair.
81
+ const first = verdicts.find((verdict) => verdict.drift_kind === driftKind) ?? verdicts[0]
82
+ return {
83
+ code,
84
+ severity: entry.severity,
85
+ integrity: entry.integrity,
86
+ pair_id: pair.pair_id,
87
+ sentence_key: pair.sentence_key ?? null,
88
+ drift_kind: driftKind,
89
+ tiers,
90
+ fragment: first.fragment,
91
+ source_fragment: first.source_fragment,
92
+ selector: null,
93
+ line: null,
94
+ message: `${pair.pair_id}: ${tiers.join(" and ")} reader${tiers.length > 1 ? "s" : ""} found ${driftKind} at "${squash(first.fragment)}"`,
95
+ hint: entry.hint,
96
+ }
97
+ }
98
+
99
+ /** One meaning_unverified defect per coverage gap, so blocksDelivery sees an unread pair through the registry. */
100
+ export function unverifiedDefects(unverified) {
101
+ const entry = DEFECT_CODES.meaning_unverified
102
+ return unverified.map((gap) => ({
103
+ code: "meaning_unverified",
104
+ severity: entry.severity,
105
+ integrity: entry.integrity,
106
+ pair_id: gap.pair_id,
107
+ reason: gap.reason,
108
+ selector: null,
109
+ line: null,
110
+ message: `${gap.pair_id}: ${gap.reason === "no_strong_verdict" ? "no strong reader judged this force_strong pair" : "no reader judged this pair"}`,
111
+ hint: entry.hint,
112
+ }))
113
+ }
114
+
115
+ /** Pairs with no accepted verdict, and force_strong pairs with no accepted strong verdict, in pair order. */
116
+ function coverageGaps(list, accepted) {
117
+ const tiersByPair = new Map()
118
+ for (const verdict of accepted) {
119
+ tiersByPair.set(verdict.pair_id, (tiersByPair.get(verdict.pair_id) ?? new Set()).add(verdict.model_tier))
120
+ }
121
+ const gaps = []
122
+ for (const pair of list) {
123
+ const tiers = tiersByPair.get(pair.pair_id)
124
+ if (tiers === undefined || tiers.size === 0) gaps.push({ pair_id: pair.pair_id, reason: "no_verdict" })
125
+ else if (pair.force_strong === true && !tiers.has("strong")) gaps.push({ pair_id: pair.pair_id, reason: "no_strong_verdict" })
126
+ }
127
+ return gaps
128
+ }
129
+
130
+ /** Group accepted drift verdicts per pair, then per tier. */
131
+ function flaggedPairs(accepted) {
132
+ const byPair = new Map()
133
+ for (const verdict of accepted) {
134
+ if (verdict.verdict !== "drift") continue
135
+ const tiers = byPair.get(verdict.pair_id) ?? new Map()
136
+ tiers.set(verdict.model_tier, [...(tiers.get(verdict.model_tier) ?? []), verdict])
137
+ byPair.set(verdict.pair_id, tiers)
138
+ }
139
+ return byPair
140
+ }
141
+
142
+ /** The drift_kind both tiers named (never "other"), or null. */
143
+ function agreedKind(tiers) {
144
+ const [cheap, strong] = MODEL_TIERS.map((tier) => tiers.get(tier) ?? [])
145
+ return cheap.map((verdict) => verdict.drift_kind).find((kind) => kind !== "other" && strong.some((verdict) => verdict.drift_kind === kind)) ?? null
146
+ }
147
+
148
+ /**
149
+ * @param {object[] | { pairs: object[] }} pairs extractPairs(...) output
150
+ * @param {(string | object[] | { verdicts: object[], model_tier?: string })[]} verdictFiles paths, or parsed verdict lists
151
+ * @param {{ dispute?: { pair_id: string, reason: string }, calibrationPath?: string }} [options]
152
+ * calibrationPath: append each calibration line to this JSONL file (fidelity-calibration.jsonl)
153
+ * @returns {{ defects: object[], dropped: object[], unverified: { pair_id: string, reason: string }[], calibrationLines: string[] }}
154
+ * unverified lists, in pair order, every pair no reader judged (`no_verdict`) and every
155
+ * force_strong pair no strong reader judged (`no_strong_verdict`); a verdict that was dropped
156
+ * does not count as read. A consumer MUST treat a non-empty list as blocking: the pairs were
157
+ * never checked, so an empty `defects` list does not mean the report is clean.
158
+ * @throws {TypeError} when pairs is neither an array nor `{ pairs: [...] }` (fail closed: a missing
159
+ * pairs input never reads as a fully verified report)
160
+ */
161
+ export function ingestVerdicts(pairs, verdictFiles, options = {}) {
162
+ const list = Array.isArray(pairs) ? pairs : pairs?.pairs
163
+ if (!Array.isArray(list)) throw new TypeError("pairs: expected an array of pairs or { pairs: [...] }")
164
+ const byId = new Map(list.map((pair) => [pair.pair_id, pair]))
165
+ const accepted = []
166
+ const dropped = []
167
+ for (const input of verdictFiles) {
168
+ for (const { verdict, file } of verdictsOf(input)) {
169
+ const reason = dropReason(verdict, byId.get(verdict?.pair_id))
170
+ if (reason === null) accepted.push(verdict)
171
+ else dropped.push({ file, pair_id: verdict?.pair_id ?? null, model_tier: verdict?.model_tier ?? null, reason })
172
+ }
173
+ }
174
+ const dispute = options.dispute ?? null
175
+ const defects = []
176
+ const calibrationLines = []
177
+ const flagged = flaggedPairs(accepted)
178
+ for (const pair of list) {
179
+ const tiers = flagged.get(pair.pair_id)
180
+ if (!tiers) continue
181
+ const tierNames = MODEL_TIERS.filter((tier) => tiers.has(tier))
182
+ const agreed = agreedKind(tiers)
183
+ const verdicts = MODEL_TIERS.flatMap((tier) => tiers.get(tier) ?? [])
184
+ const kind = agreed ?? verdicts[0].drift_kind
185
+ const confirmed = agreed !== null
186
+ defects.push(defect(confirmed ? "meaning_drift_confirmed" : "meaning_drift_warn", pair, kind, tierNames, verdicts))
187
+ const disputed = dispute !== null && dispute.pair_id === pair.pair_id
188
+ calibrationLines.push(JSON.stringify({ kind: pair.kind, pair_id: pair.pair_id, tiers: tierNames, drift_kind: kind, confirmed, disputed, reason: disputed ? String(dispute.reason ?? "") : null }))
189
+ }
190
+ const unverified = coverageGaps(list, accepted)
191
+ if (dispute !== null && !flagged.has(dispute.pair_id)) {
192
+ dropped.push({ file: "<dispute>", pair_id: dispute.pair_id, model_tier: null, reason: "dispute_not_flagged" })
193
+ }
194
+ if (options.calibrationPath && calibrationLines.length > 0) appendFileSync(options.calibrationPath, `${calibrationLines.join("\n")}\n`)
195
+ return { defects, dropped, unverified, calibrationLines }
196
+ }