@cairn-tool/cairn 2.0.0

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 (526) hide show
  1. package/.markdownlintrc +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1431 -0
  4. package/dist/agent/audit/baseline.d.ts +69 -0
  5. package/dist/agent/audit/baseline.js +128 -0
  6. package/dist/agent/audit/baseline.js.map +1 -0
  7. package/dist/agent/audit/index.d.ts +126 -0
  8. package/dist/agent/audit/index.js +625 -0
  9. package/dist/agent/audit/index.js.map +1 -0
  10. package/dist/agent/import/detect.d.ts +49 -0
  11. package/dist/agent/import/detect.js +159 -0
  12. package/dist/agent/import/detect.js.map +1 -0
  13. package/dist/agent/import/normalize.d.ts +72 -0
  14. package/dist/agent/import/normalize.js +475 -0
  15. package/dist/agent/import/normalize.js.map +1 -0
  16. package/dist/agent/install/index.d.ts +211 -0
  17. package/dist/agent/install/index.js +907 -0
  18. package/dist/agent/install/index.js.map +1 -0
  19. package/dist/agent/manifest.d.ts +75 -0
  20. package/dist/agent/manifest.js +210 -0
  21. package/dist/agent/manifest.js.map +1 -0
  22. package/dist/agent/marketplace/index.d.ts +69 -0
  23. package/dist/agent/marketplace/index.js +212 -0
  24. package/dist/agent/marketplace/index.js.map +1 -0
  25. package/dist/agent/marketplace/spec.d.ts +48 -0
  26. package/dist/agent/marketplace/spec.js +237 -0
  27. package/dist/agent/marketplace/spec.js.map +1 -0
  28. package/dist/agent/output.d.ts +36 -0
  29. package/dist/agent/output.js +56 -0
  30. package/dist/agent/output.js.map +1 -0
  31. package/dist/agent/overlays.d.ts +38 -0
  32. package/dist/agent/overlays.js +223 -0
  33. package/dist/agent/overlays.js.map +1 -0
  34. package/dist/agent/package/index.d.ts +105 -0
  35. package/dist/agent/package/index.js +339 -0
  36. package/dist/agent/package/index.js.map +1 -0
  37. package/dist/agent/package/tar.d.ts +36 -0
  38. package/dist/agent/package/tar.js +137 -0
  39. package/dist/agent/package/tar.js.map +1 -0
  40. package/dist/agent/parser.d.ts +13 -0
  41. package/dist/agent/parser.js +559 -0
  42. package/dist/agent/parser.js.map +1 -0
  43. package/dist/agent/render.d.ts +16 -0
  44. package/dist/agent/render.js +721 -0
  45. package/dist/agent/render.js.map +1 -0
  46. package/dist/agent/sarif.d.ts +18 -0
  47. package/dist/agent/sarif.js +56 -0
  48. package/dist/agent/sarif.js.map +1 -0
  49. package/dist/agent/scaffold.d.ts +86 -0
  50. package/dist/agent/scaffold.js +250 -0
  51. package/dist/agent/scaffold.js.map +1 -0
  52. package/dist/agent/targets/antigravity.d.ts +17 -0
  53. package/dist/agent/targets/antigravity.js +218 -0
  54. package/dist/agent/targets/antigravity.js.map +1 -0
  55. package/dist/agent/targets/claude-code.d.ts +2 -0
  56. package/dist/agent/targets/claude-code.js +220 -0
  57. package/dist/agent/targets/claude-code.js.map +1 -0
  58. package/dist/agent/targets/codex.d.ts +2 -0
  59. package/dist/agent/targets/codex.js +212 -0
  60. package/dist/agent/targets/codex.js.map +1 -0
  61. package/dist/agent/targets/cursor.d.ts +2 -0
  62. package/dist/agent/targets/cursor.js +210 -0
  63. package/dist/agent/targets/cursor.js.map +1 -0
  64. package/dist/agent/targets/index.d.ts +31 -0
  65. package/dist/agent/targets/index.js +64 -0
  66. package/dist/agent/targets/index.js.map +1 -0
  67. package/dist/agent/targets/opencode.d.ts +15 -0
  68. package/dist/agent/targets/opencode.js +215 -0
  69. package/dist/agent/targets/opencode.js.map +1 -0
  70. package/dist/agent/targets/schema.d.ts +315 -0
  71. package/dist/agent/targets/schema.js +179 -0
  72. package/dist/agent/targets/schema.js.map +1 -0
  73. package/dist/agent/test/assert.d.ts +46 -0
  74. package/dist/agent/test/assert.js +288 -0
  75. package/dist/agent/test/assert.js.map +1 -0
  76. package/dist/agent/test/index.d.ts +73 -0
  77. package/dist/agent/test/index.js +181 -0
  78. package/dist/agent/test/index.js.map +1 -0
  79. package/dist/agent/test/schema.d.ts +81 -0
  80. package/dist/agent/test/schema.js +235 -0
  81. package/dist/agent/test/schema.js.map +1 -0
  82. package/dist/agent/types.d.ts +204 -0
  83. package/dist/agent/types.js +11 -0
  84. package/dist/agent/types.js.map +1 -0
  85. package/dist/agent/upgrade.d.ts +29 -0
  86. package/dist/agent/upgrade.js +72 -0
  87. package/dist/agent/upgrade.js.map +1 -0
  88. package/dist/agent/writer.d.ts +30 -0
  89. package/dist/agent/writer.js +73 -0
  90. package/dist/agent/writer.js.map +1 -0
  91. package/dist/archive/db.d.ts +20 -0
  92. package/dist/archive/db.js +98 -0
  93. package/dist/archive/db.js.map +1 -0
  94. package/dist/archive/progress.d.ts +62 -0
  95. package/dist/archive/progress.js +151 -0
  96. package/dist/archive/progress.js.map +1 -0
  97. package/dist/archive/query.d.ts +86 -0
  98. package/dist/archive/query.js +241 -0
  99. package/dist/archive/query.js.map +1 -0
  100. package/dist/archive/run.d.ts +91 -0
  101. package/dist/archive/run.js +331 -0
  102. package/dist/archive/run.js.map +1 -0
  103. package/dist/archive/segments.d.ts +89 -0
  104. package/dist/archive/segments.js +144 -0
  105. package/dist/archive/segments.js.map +1 -0
  106. package/dist/archive/sets.d.ts +58 -0
  107. package/dist/archive/sets.js +344 -0
  108. package/dist/archive/sets.js.map +1 -0
  109. package/dist/archive/tar-read.d.ts +35 -0
  110. package/dist/archive/tar-read.js +90 -0
  111. package/dist/archive/tar-read.js.map +1 -0
  112. package/dist/audit-baseline.d.ts +66 -0
  113. package/dist/audit-baseline.js +124 -0
  114. package/dist/audit-baseline.js.map +1 -0
  115. package/dist/automation.d.ts +16 -0
  116. package/dist/automation.js +38 -0
  117. package/dist/automation.js.map +1 -0
  118. package/dist/backlinks.d.ts +15 -0
  119. package/dist/backlinks.js +30 -0
  120. package/dist/backlinks.js.map +1 -0
  121. package/dist/checkers/katex.d.ts +3 -0
  122. package/dist/checkers/katex.js +71 -0
  123. package/dist/checkers/katex.js.map +1 -0
  124. package/dist/checkers/markdown-lint.d.ts +28 -0
  125. package/dist/checkers/markdown-lint.js +53 -0
  126. package/dist/checkers/markdown-lint.js.map +1 -0
  127. package/dist/checkers/mermaid.d.ts +6 -0
  128. package/dist/checkers/mermaid.js +53 -0
  129. package/dist/checkers/mermaid.js.map +1 -0
  130. package/dist/checkers/references.d.ts +3 -0
  131. package/dist/checkers/references.js +55 -0
  132. package/dist/checkers/references.js.map +1 -0
  133. package/dist/cli.d.ts +2 -0
  134. package/dist/cli.js +1117 -0
  135. package/dist/cli.js.map +1 -0
  136. package/dist/command-result.d.ts +6 -0
  137. package/dist/command-result.js +13 -0
  138. package/dist/command-result.js.map +1 -0
  139. package/dist/commands/agent-audit.d.ts +21 -0
  140. package/dist/commands/agent-audit.js +119 -0
  141. package/dist/commands/agent-audit.js.map +1 -0
  142. package/dist/commands/agent-doctor.d.ts +25 -0
  143. package/dist/commands/agent-doctor.js +217 -0
  144. package/dist/commands/agent-doctor.js.map +1 -0
  145. package/dist/commands/agent-import.d.ts +21 -0
  146. package/dist/commands/agent-import.js +212 -0
  147. package/dist/commands/agent-import.js.map +1 -0
  148. package/dist/commands/agent-install.d.ts +18 -0
  149. package/dist/commands/agent-install.js +59 -0
  150. package/dist/commands/agent-install.js.map +1 -0
  151. package/dist/commands/agent-installed.d.ts +6 -0
  152. package/dist/commands/agent-installed.js +17 -0
  153. package/dist/commands/agent-installed.js.map +1 -0
  154. package/dist/commands/agent-marketplace.d.ts +11 -0
  155. package/dist/commands/agent-marketplace.js +178 -0
  156. package/dist/commands/agent-marketplace.js.map +1 -0
  157. package/dist/commands/agent-package.d.ts +16 -0
  158. package/dist/commands/agent-package.js +159 -0
  159. package/dist/commands/agent-package.js.map +1 -0
  160. package/dist/commands/agent-scaffold.d.ts +17 -0
  161. package/dist/commands/agent-scaffold.js +181 -0
  162. package/dist/commands/agent-scaffold.js.map +1 -0
  163. package/dist/commands/agent-specs.d.ts +7 -0
  164. package/dist/commands/agent-specs.js +20 -0
  165. package/dist/commands/agent-specs.js.map +1 -0
  166. package/dist/commands/agent-test.d.ts +21 -0
  167. package/dist/commands/agent-test.js +50 -0
  168. package/dist/commands/agent-test.js.map +1 -0
  169. package/dist/commands/agent-uninstall.d.ts +6 -0
  170. package/dist/commands/agent-uninstall.js +45 -0
  171. package/dist/commands/agent-uninstall.js.map +1 -0
  172. package/dist/commands/agent-upgrade.d.ts +5 -0
  173. package/dist/commands/agent-upgrade.js +105 -0
  174. package/dist/commands/agent-upgrade.js.map +1 -0
  175. package/dist/commands/agent.d.ts +27 -0
  176. package/dist/commands/agent.js +549 -0
  177. package/dist/commands/agent.js.map +1 -0
  178. package/dist/commands/archive.d.ts +47 -0
  179. package/dist/commands/archive.js +311 -0
  180. package/dist/commands/archive.js.map +1 -0
  181. package/dist/commands/audit.d.ts +25 -0
  182. package/dist/commands/audit.js +325 -0
  183. package/dist/commands/audit.js.map +1 -0
  184. package/dist/commands/check-snippets.d.ts +58 -0
  185. package/dist/commands/check-snippets.js +247 -0
  186. package/dist/commands/check-snippets.js.map +1 -0
  187. package/dist/commands/check-urls.d.ts +52 -0
  188. package/dist/commands/check-urls.js +205 -0
  189. package/dist/commands/check-urls.js.map +1 -0
  190. package/dist/commands/code-blocks.d.ts +8 -0
  191. package/dist/commands/code-blocks.js +66 -0
  192. package/dist/commands/code-blocks.js.map +1 -0
  193. package/dist/commands/completion.d.ts +15 -0
  194. package/dist/commands/completion.js +20 -0
  195. package/dist/commands/completion.js.map +1 -0
  196. package/dist/commands/context.d.ts +16 -0
  197. package/dist/commands/context.js +131 -0
  198. package/dist/commands/context.js.map +1 -0
  199. package/dist/commands/describe.d.ts +12 -0
  200. package/dist/commands/describe.js +62 -0
  201. package/dist/commands/describe.js.map +1 -0
  202. package/dist/commands/diff.d.ts +11 -0
  203. package/dist/commands/diff.js +185 -0
  204. package/dist/commands/diff.js.map +1 -0
  205. package/dist/commands/fix.d.ts +59 -0
  206. package/dist/commands/fix.js +173 -0
  207. package/dist/commands/fix.js.map +1 -0
  208. package/dist/commands/frontmatter.d.ts +7 -0
  209. package/dist/commands/frontmatter.js +84 -0
  210. package/dist/commands/frontmatter.js.map +1 -0
  211. package/dist/commands/graph.d.ts +12 -0
  212. package/dist/commands/graph.js +122 -0
  213. package/dist/commands/graph.js.map +1 -0
  214. package/dist/commands/headers.d.ts +7 -0
  215. package/dist/commands/headers.js +48 -0
  216. package/dist/commands/headers.js.map +1 -0
  217. package/dist/commands/index.d.ts +8 -0
  218. package/dist/commands/index.js +32 -0
  219. package/dist/commands/index.js.map +1 -0
  220. package/dist/commands/links.d.ts +9 -0
  221. package/dist/commands/links.js +123 -0
  222. package/dist/commands/links.js.map +1 -0
  223. package/dist/commands/lint-dir.d.ts +15 -0
  224. package/dist/commands/lint-dir.js +156 -0
  225. package/dist/commands/lint-dir.js.map +1 -0
  226. package/dist/commands/lint.d.ts +14 -0
  227. package/dist/commands/lint.js +45 -0
  228. package/dist/commands/lint.js.map +1 -0
  229. package/dist/commands/orphans.d.ts +10 -0
  230. package/dist/commands/orphans.js +74 -0
  231. package/dist/commands/orphans.js.map +1 -0
  232. package/dist/commands/outline.d.ts +7 -0
  233. package/dist/commands/outline.js +54 -0
  234. package/dist/commands/outline.js.map +1 -0
  235. package/dist/commands/query.d.ts +18 -0
  236. package/dist/commands/query.js +341 -0
  237. package/dist/commands/query.js.map +1 -0
  238. package/dist/commands/refs-to.d.ts +8 -0
  239. package/dist/commands/refs-to.js +65 -0
  240. package/dist/commands/refs-to.js.map +1 -0
  241. package/dist/commands/refs.d.ts +10 -0
  242. package/dist/commands/refs.js +103 -0
  243. package/dist/commands/refs.js.map +1 -0
  244. package/dist/commands/rename-file.d.ts +16 -0
  245. package/dist/commands/rename-file.js +215 -0
  246. package/dist/commands/rename-file.js.map +1 -0
  247. package/dist/commands/rename-heading.d.ts +10 -0
  248. package/dist/commands/rename-heading.js +182 -0
  249. package/dist/commands/rename-heading.js.map +1 -0
  250. package/dist/commands/schema.d.ts +10 -0
  251. package/dist/commands/schema.js +34 -0
  252. package/dist/commands/schema.js.map +1 -0
  253. package/dist/commands/scripts.d.ts +59 -0
  254. package/dist/commands/scripts.js +222 -0
  255. package/dist/commands/scripts.js.map +1 -0
  256. package/dist/commands/section.d.ts +9 -0
  257. package/dist/commands/section.js +49 -0
  258. package/dist/commands/section.js.map +1 -0
  259. package/dist/commands/serve.d.ts +6 -0
  260. package/dist/commands/serve.js +48 -0
  261. package/dist/commands/serve.js.map +1 -0
  262. package/dist/commands/stats.d.ts +6 -0
  263. package/dist/commands/stats.js +109 -0
  264. package/dist/commands/stats.js.map +1 -0
  265. package/dist/commands/structure.d.ts +6 -0
  266. package/dist/commands/structure.js +130 -0
  267. package/dist/commands/structure.js.map +1 -0
  268. package/dist/commands/tables.d.ts +8 -0
  269. package/dist/commands/tables.js +77 -0
  270. package/dist/commands/tables.js.map +1 -0
  271. package/dist/commands/tasks.d.ts +8 -0
  272. package/dist/commands/tasks.js +59 -0
  273. package/dist/commands/tasks.js.map +1 -0
  274. package/dist/commands/toc.d.ts +18 -0
  275. package/dist/commands/toc.js +105 -0
  276. package/dist/commands/toc.js.map +1 -0
  277. package/dist/commands/update-check.d.ts +36 -0
  278. package/dist/commands/update-check.js +119 -0
  279. package/dist/commands/update-check.js.map +1 -0
  280. package/dist/commands/usage.d.ts +56 -0
  281. package/dist/commands/usage.js +883 -0
  282. package/dist/commands/usage.js.map +1 -0
  283. package/dist/commands/validate-frontmatter.d.ts +13 -0
  284. package/dist/commands/validate-frontmatter.js +34 -0
  285. package/dist/commands/validate-frontmatter.js.map +1 -0
  286. package/dist/completion/model.d.ts +49 -0
  287. package/dist/completion/model.js +194 -0
  288. package/dist/completion/model.js.map +1 -0
  289. package/dist/completion/shells.d.ts +2 -0
  290. package/dist/completion/shells.js +280 -0
  291. package/dist/completion/shells.js.map +1 -0
  292. package/dist/config-schema.d.ts +15 -0
  293. package/dist/config-schema.js +44 -0
  294. package/dist/config-schema.js.map +1 -0
  295. package/dist/config.d.ts +102 -0
  296. package/dist/config.js +614 -0
  297. package/dist/config.js.map +1 -0
  298. package/dist/context.d.ts +106 -0
  299. package/dist/context.js +202 -0
  300. package/dist/context.js.map +1 -0
  301. package/dist/contract/describe.d.ts +84 -0
  302. package/dist/contract/describe.js +104 -0
  303. package/dist/contract/describe.js.map +1 -0
  304. package/dist/contract/registry.d.ts +2 -0
  305. package/dist/contract/registry.js +622 -0
  306. package/dist/contract/registry.js.map +1 -0
  307. package/dist/contract/schemas/agent.d.ts +2 -0
  308. package/dist/contract/schemas/agent.js +572 -0
  309. package/dist/contract/schemas/agent.js.map +1 -0
  310. package/dist/contract/schemas/archive.d.ts +3 -0
  311. package/dist/contract/schemas/archive.js +227 -0
  312. package/dist/contract/schemas/archive.js.map +1 -0
  313. package/dist/contract/schemas/index.d.ts +11 -0
  314. package/dist/contract/schemas/index.js +49 -0
  315. package/dist/contract/schemas/index.js.map +1 -0
  316. package/dist/contract/schemas/markdown.d.ts +15 -0
  317. package/dist/contract/schemas/markdown.js +1035 -0
  318. package/dist/contract/schemas/markdown.js.map +1 -0
  319. package/dist/contract/schemas/meta.d.ts +5 -0
  320. package/dist/contract/schemas/meta.js +233 -0
  321. package/dist/contract/schemas/meta.js.map +1 -0
  322. package/dist/contract/schemas/scripts.d.ts +4 -0
  323. package/dist/contract/schemas/scripts.js +183 -0
  324. package/dist/contract/schemas/scripts.js.map +1 -0
  325. package/dist/contract/schemas/shared.d.ts +11 -0
  326. package/dist/contract/schemas/shared.js +26 -0
  327. package/dist/contract/schemas/shared.js.map +1 -0
  328. package/dist/contract/schemas/usage.d.ts +6 -0
  329. package/dist/contract/schemas/usage.js +489 -0
  330. package/dist/contract/schemas/usage.js.map +1 -0
  331. package/dist/contract/types.d.ts +63 -0
  332. package/dist/contract/types.js +2 -0
  333. package/dist/contract/types.js.map +1 -0
  334. package/dist/contract/version.d.ts +20 -0
  335. package/dist/contract/version.js +21 -0
  336. package/dist/contract/version.js.map +1 -0
  337. package/dist/diff.d.ts +156 -0
  338. package/dist/diff.js +500 -0
  339. package/dist/diff.js.map +1 -0
  340. package/dist/edit-plan.d.ts +133 -0
  341. package/dist/edit-plan.js +245 -0
  342. package/dist/edit-plan.js.map +1 -0
  343. package/dist/fix/markdownlint-fixer.d.ts +34 -0
  344. package/dist/fix/markdownlint-fixer.js +125 -0
  345. package/dist/fix/markdownlint-fixer.js.map +1 -0
  346. package/dist/fix/registry.d.ts +48 -0
  347. package/dist/fix/registry.js +28 -0
  348. package/dist/fix/registry.js.map +1 -0
  349. package/dist/fix/relative-links-fixer.d.ts +21 -0
  350. package/dist/fix/relative-links-fixer.js +96 -0
  351. package/dist/fix/relative-links-fixer.js.map +1 -0
  352. package/dist/fix/snippets-fixer.d.ts +2 -0
  353. package/dist/fix/snippets-fixer.js +64 -0
  354. package/dist/fix/snippets-fixer.js.map +1 -0
  355. package/dist/fix/toc-fixer.d.ts +2 -0
  356. package/dist/fix/toc-fixer.js +94 -0
  357. package/dist/fix/toc-fixer.js.map +1 -0
  358. package/dist/formats.d.ts +22 -0
  359. package/dist/formats.js +34 -0
  360. package/dist/formats.js.map +1 -0
  361. package/dist/formatters.d.ts +11 -0
  362. package/dist/formatters.js +48 -0
  363. package/dist/formatters.js.map +1 -0
  364. package/dist/frontmatter-validation.d.ts +11 -0
  365. package/dist/frontmatter-validation.js +188 -0
  366. package/dist/frontmatter-validation.js.map +1 -0
  367. package/dist/git.d.ts +40 -0
  368. package/dist/git.js +124 -0
  369. package/dist/git.js.map +1 -0
  370. package/dist/graph.d.ts +50 -0
  371. package/dist/graph.js +200 -0
  372. package/dist/graph.js.map +1 -0
  373. package/dist/input-selection.d.ts +9 -0
  374. package/dist/input-selection.js +122 -0
  375. package/dist/input-selection.js.map +1 -0
  376. package/dist/input.d.ts +2 -0
  377. package/dist/input.js +32 -0
  378. package/dist/input.js.map +1 -0
  379. package/dist/link-target.d.ts +39 -0
  380. package/dist/link-target.js +68 -0
  381. package/dist/link-target.js.map +1 -0
  382. package/dist/lint.d.ts +13 -0
  383. package/dist/lint.js +27 -0
  384. package/dist/lint.js.map +1 -0
  385. package/dist/markdown-ast.d.ts +73 -0
  386. package/dist/markdown-ast.js +187 -0
  387. package/dist/markdown-ast.js.map +1 -0
  388. package/dist/object-path.d.ts +14 -0
  389. package/dist/object-path.js +14 -0
  390. package/dist/object-path.js.map +1 -0
  391. package/dist/option-utils.d.ts +13 -0
  392. package/dist/option-utils.js +25 -0
  393. package/dist/option-utils.js.map +1 -0
  394. package/dist/outline.d.ts +16 -0
  395. package/dist/outline.js +32 -0
  396. package/dist/outline.js.map +1 -0
  397. package/dist/query/entities.d.ts +60 -0
  398. package/dist/query/entities.js +219 -0
  399. package/dist/query/entities.js.map +1 -0
  400. package/dist/query/execute.d.ts +22 -0
  401. package/dist/query/execute.js +0 -0
  402. package/dist/query/execute.js.map +1 -0
  403. package/dist/query/plan.d.ts +76 -0
  404. package/dist/query/plan.js +183 -0
  405. package/dist/query/plan.js.map +1 -0
  406. package/dist/query/render.d.ts +3 -0
  407. package/dist/query/render.js +39 -0
  408. package/dist/query/render.js.map +1 -0
  409. package/dist/refs.d.ts +19 -0
  410. package/dist/refs.js +10 -0
  411. package/dist/refs.js.map +1 -0
  412. package/dist/result.d.ts +49 -0
  413. package/dist/result.js +47 -0
  414. package/dist/result.js.map +1 -0
  415. package/dist/runtime.d.ts +35 -0
  416. package/dist/runtime.js +77 -0
  417. package/dist/runtime.js.map +1 -0
  418. package/dist/sarif.d.ts +36 -0
  419. package/dist/sarif.js +30 -0
  420. package/dist/sarif.js.map +1 -0
  421. package/dist/scripts/execute.d.ts +65 -0
  422. package/dist/scripts/execute.js +235 -0
  423. package/dist/scripts/execute.js.map +1 -0
  424. package/dist/scripts/registry.d.ts +55 -0
  425. package/dist/scripts/registry.js +103 -0
  426. package/dist/scripts/registry.js.map +1 -0
  427. package/dist/scripts/resolve.d.ts +90 -0
  428. package/dist/scripts/resolve.js +288 -0
  429. package/dist/scripts/resolve.js.map +1 -0
  430. package/dist/sections.d.ts +53 -0
  431. package/dist/sections.js +100 -0
  432. package/dist/sections.js.map +1 -0
  433. package/dist/serve/errors.d.ts +25 -0
  434. package/dist/serve/errors.js +45 -0
  435. package/dist/serve/errors.js.map +1 -0
  436. package/dist/serve/paths.d.ts +32 -0
  437. package/dist/serve/paths.js +71 -0
  438. package/dist/serve/paths.js.map +1 -0
  439. package/dist/serve/server.d.ts +31 -0
  440. package/dist/serve/server.js +123 -0
  441. package/dist/serve/server.js.map +1 -0
  442. package/dist/serve/tools.d.ts +19 -0
  443. package/dist/serve/tools.js +597 -0
  444. package/dist/serve/tools.js.map +1 -0
  445. package/dist/snippets.d.ts +184 -0
  446. package/dist/snippets.js +454 -0
  447. package/dist/snippets.js.map +1 -0
  448. package/dist/sqlite-store.d.ts +62 -0
  449. package/dist/sqlite-store.js +104 -0
  450. package/dist/sqlite-store.js.map +1 -0
  451. package/dist/sqlite.d.ts +59 -0
  452. package/dist/sqlite.js +51 -0
  453. package/dist/sqlite.js.map +1 -0
  454. package/dist/toc.d.ts +58 -0
  455. package/dist/toc.js +83 -0
  456. package/dist/toc.js.map +1 -0
  457. package/dist/types.d.ts +7 -0
  458. package/dist/types.js +2 -0
  459. package/dist/types.js.map +1 -0
  460. package/dist/update-notifier.d.ts +95 -0
  461. package/dist/update-notifier.js +301 -0
  462. package/dist/update-notifier.js.map +1 -0
  463. package/dist/url-cache.d.ts +14 -0
  464. package/dist/url-cache.js +70 -0
  465. package/dist/url-cache.js.map +1 -0
  466. package/dist/usage/aggregate.d.ts +107 -0
  467. package/dist/usage/aggregate.js +435 -0
  468. package/dist/usage/aggregate.js.map +1 -0
  469. package/dist/usage/db/index.d.ts +49 -0
  470. package/dist/usage/db/index.js +118 -0
  471. package/dist/usage/db/index.js.map +1 -0
  472. package/dist/usage/db/migrations.d.ts +29 -0
  473. package/dist/usage/db/migrations.js +38 -0
  474. package/dist/usage/db/migrations.js.map +1 -0
  475. package/dist/usage/db/open.d.ts +33 -0
  476. package/dist/usage/db/open.js +37 -0
  477. package/dist/usage/db/open.js.map +1 -0
  478. package/dist/usage/db/schema.d.ts +18 -0
  479. package/dist/usage/db/schema.js +147 -0
  480. package/dist/usage/db/schema.js.map +1 -0
  481. package/dist/usage/db/store.d.ts +74 -0
  482. package/dist/usage/db/store.js +280 -0
  483. package/dist/usage/db/store.js.map +1 -0
  484. package/dist/usage/events.d.ts +202 -0
  485. package/dist/usage/events.js +243 -0
  486. package/dist/usage/events.js.map +1 -0
  487. package/dist/usage/filter.d.ts +43 -0
  488. package/dist/usage/filter.js +97 -0
  489. package/dist/usage/filter.js.map +1 -0
  490. package/dist/usage/providers/antigravity.d.ts +2 -0
  491. package/dist/usage/providers/antigravity.js +431 -0
  492. package/dist/usage/providers/antigravity.js.map +1 -0
  493. package/dist/usage/providers/claude-code.d.ts +2 -0
  494. package/dist/usage/providers/claude-code.js +400 -0
  495. package/dist/usage/providers/claude-code.js.map +1 -0
  496. package/dist/usage/providers/codex.d.ts +2 -0
  497. package/dist/usage/providers/codex.js +387 -0
  498. package/dist/usage/providers/codex.js.map +1 -0
  499. package/dist/usage/providers/gemini-cli.d.ts +2 -0
  500. package/dist/usage/providers/gemini-cli.js +466 -0
  501. package/dist/usage/providers/gemini-cli.js.map +1 -0
  502. package/dist/usage/providers/index.d.ts +23 -0
  503. package/dist/usage/providers/index.js +46 -0
  504. package/dist/usage/providers/index.js.map +1 -0
  505. package/dist/usage/providers/opencode.d.ts +2 -0
  506. package/dist/usage/providers/opencode.js +422 -0
  507. package/dist/usage/providers/opencode.js.map +1 -0
  508. package/dist/usage/providers/protobuf.d.ts +35 -0
  509. package/dist/usage/providers/protobuf.js +125 -0
  510. package/dist/usage/providers/protobuf.js.map +1 -0
  511. package/dist/usage/providers/types.d.ts +74 -0
  512. package/dist/usage/providers/types.js +2 -0
  513. package/dist/usage/providers/types.js.map +1 -0
  514. package/dist/usage/scan.d.ts +54 -0
  515. package/dist/usage/scan.js +216 -0
  516. package/dist/usage/scan.js.map +1 -0
  517. package/dist/version.d.ts +2 -0
  518. package/dist/version.js +8 -0
  519. package/dist/version.js.map +1 -0
  520. package/dist/workspace-index.d.ts +39 -0
  521. package/dist/workspace-index.js +265 -0
  522. package/dist/workspace-index.js.map +1 -0
  523. package/dist/workspace.d.ts +89 -0
  524. package/dist/workspace.js +219 -0
  525. package/dist/workspace.js.map +1 -0
  526. package/package.json +92 -0
package/dist/diff.d.ts ADDED
@@ -0,0 +1,156 @@
1
+ import { type MdHeading } from "./markdown-ast.js";
2
+ import type { MarkdownDocument } from "./workspace.js";
3
+ export type DiffKind = "added" | "removed" | "changed" | "moved" | "renamed";
4
+ export type FrontmatterStatus = "missing" | "malformed" | "non-mapping" | "valid";
5
+ export interface HeadingChange {
6
+ kind: DiffKind;
7
+ oldText?: string;
8
+ oldSlug?: string;
9
+ oldLine?: number;
10
+ oldDepth?: number;
11
+ newText?: string;
12
+ newSlug?: string;
13
+ newLine?: number;
14
+ newDepth?: number;
15
+ /** The section body changed, independent of the heading itself. */
16
+ bodyChanged?: boolean;
17
+ /** Set only on a rename: matched by position, not by identity. */
18
+ heuristic?: boolean;
19
+ matchedBy?: "slug" | "text" | "position";
20
+ }
21
+ export interface FrontmatterChange {
22
+ kind: DiffKind;
23
+ /** Dotted path, or null for a whole-block status transition. */
24
+ key: string | null;
25
+ oldValue?: unknown;
26
+ newValue?: unknown;
27
+ oldStatus?: FrontmatterStatus;
28
+ newStatus?: FrontmatterStatus;
29
+ }
30
+ export interface LinkChange {
31
+ kind: DiffKind;
32
+ oldTarget?: string;
33
+ newTarget?: string;
34
+ /** Null for external and anchor-only references. */
35
+ oldResolved?: string | null;
36
+ newResolved?: string | null;
37
+ oldLine?: number;
38
+ newLine?: number;
39
+ linkText?: string;
40
+ /** Only the `#fragment` differs — the anchor-rot case. */
41
+ fragmentChanged?: boolean;
42
+ }
43
+ export interface TaskChange {
44
+ kind: DiffKind;
45
+ text: string;
46
+ oldLine?: number;
47
+ newLine?: number;
48
+ oldChecked?: boolean;
49
+ newChecked?: boolean;
50
+ }
51
+ export interface CodeBlockChange {
52
+ kind: DiffKind;
53
+ oldLang?: string | null;
54
+ newLang?: string | null;
55
+ oldLine?: number;
56
+ newLine?: number;
57
+ langChanged?: boolean;
58
+ contentChanged?: boolean;
59
+ /** The block is a Mermaid diagram on either side. */
60
+ mermaid?: boolean;
61
+ }
62
+ export interface TableChange {
63
+ kind: DiffKind;
64
+ oldLine?: number;
65
+ newLine?: number;
66
+ oldColumns?: number;
67
+ newColumns?: number;
68
+ oldRows?: number;
69
+ newRows?: number;
70
+ headersChanged?: boolean;
71
+ }
72
+ export type FileStatus = "added" | "removed" | "modified" | "renamed" | "unchanged";
73
+ export interface FileDiff {
74
+ file: string;
75
+ /** Path at the base revision, when it differed. */
76
+ oldPath?: string;
77
+ status: FileStatus;
78
+ /** Git similarity index for a rename, 0-100. */
79
+ similarity?: number;
80
+ headings: HeadingChange[];
81
+ frontmatter: FrontmatterChange[];
82
+ links: LinkChange[];
83
+ tasks: TaskChange[];
84
+ codeBlocks: CodeBlockChange[];
85
+ tables: TableChange[];
86
+ totals: {
87
+ headings: number;
88
+ frontmatter: number;
89
+ links: number;
90
+ tasks: number;
91
+ codeBlocks: number;
92
+ tables: number;
93
+ changes: number;
94
+ };
95
+ }
96
+ export interface DiffReport {
97
+ mode: "files" | "revision";
98
+ /** Revision mode: the revision as the user wrote it. */
99
+ base?: string;
100
+ /** Revision mode: the resolved commit, so a report says what it compared. */
101
+ baseCommit?: string;
102
+ /** Files mode. */
103
+ from?: string;
104
+ to?: string;
105
+ files: FileDiff[];
106
+ totals: {
107
+ files: number;
108
+ filesChanged: number;
109
+ headings: number;
110
+ frontmatter: number;
111
+ links: number;
112
+ tasks: number;
113
+ codeBlocks: number;
114
+ tables: number;
115
+ /** Heading pairs the positional heuristic called renames. */
116
+ heuristicRenames: number;
117
+ /** Code-block changes whose language is Mermaid. */
118
+ diagrams: number;
119
+ };
120
+ }
121
+ interface HeadingPair {
122
+ before: number;
123
+ after: number;
124
+ matchedBy: "slug" | "text" | "position";
125
+ }
126
+ /**
127
+ * Pairs headings across two revisions, conservatively.
128
+ *
129
+ * Three passes, most certain first: exact slug, then exact normalized text
130
+ * (which recovers a heading whose slug only shifted because a duplicate sibling
131
+ * appeared or vanished), then a positional guess. The positional pass requires
132
+ * the same depth, the same parent path, and the same position among siblings,
133
+ * and is the only one that ever produces a "renamed" verdict.
134
+ *
135
+ * String similarity is deliberately not used. It is the classic source of
136
+ * confident nonsense, and a wrong rename is worse than an honest add plus
137
+ * remove.
138
+ */
139
+ export declare function matchHeadings(before: readonly MdHeading[], after: readonly MdHeading[]): {
140
+ pairs: HeadingPair[];
141
+ removed: number[];
142
+ added: number[];
143
+ };
144
+ export interface DiffOptions {
145
+ /** Workspace root, for resolving link targets. */
146
+ root: string;
147
+ /** Path to show for the document. */
148
+ file: string;
149
+ oldPath?: string;
150
+ similarity?: number;
151
+ }
152
+ /** Compares two revisions of one document. `null` means absent on that side. */
153
+ export declare function diffDocuments(before: MarkdownDocument | null, after: MarkdownDocument | null, options: DiffOptions): FileDiff;
154
+ /** Rolls per-file diffs into a report. */
155
+ export declare function summarize(files: FileDiff[], head: Pick<DiffReport, "mode" | "base" | "baseCommit" | "from" | "to">): DiffReport;
156
+ export {};
package/dist/diff.js ADDED
@@ -0,0 +1,500 @@
1
+ import { extractCodeBlocks, extractTables, extractTasks, } from "./markdown-ast.js";
2
+ import { documentSections, frontmatterEndLine } from "./sections.js";
3
+ import { resolveLocalPath, splitLocalTarget } from "./link-target.js";
4
+ /** Headings outside the frontmatter block, in document order. */
5
+ function realHeadings(document) {
6
+ const end = frontmatterEndLine(document.content);
7
+ return document.headings.filter((heading) => heading.line > end);
8
+ }
9
+ /** The nearest enclosing headings, shallowest first, as a text path. */
10
+ function parentPath(headings, index) {
11
+ const path = [];
12
+ let depth = headings[index].depth;
13
+ for (let previous = index - 1; previous >= 0 && depth > 1; previous--) {
14
+ if (headings[previous].depth < depth) {
15
+ path.unshift(headings[previous].text);
16
+ depth = headings[previous].depth;
17
+ }
18
+ }
19
+ return path;
20
+ }
21
+ /** Position among siblings: headings at the same depth under the same parent. */
22
+ function siblingOrdinal(headings, index) {
23
+ let ordinal = 0;
24
+ for (let previous = index - 1; previous >= 0; previous--) {
25
+ if (headings[previous].depth < headings[index].depth)
26
+ break;
27
+ if (headings[previous].depth === headings[index].depth)
28
+ ordinal++;
29
+ }
30
+ return ordinal;
31
+ }
32
+ function normalize(value) {
33
+ return value.trim().toLowerCase().replace(/\s+/g, " ");
34
+ }
35
+ /** Body of the section a heading owns, with the heading line removed. */
36
+ function sectionBodies(document) {
37
+ const bodies = new Map();
38
+ for (const section of documentSections(document)) {
39
+ if (!section.heading)
40
+ continue;
41
+ const body = section.content.split("\n").slice(1).join("\n");
42
+ bodies.set(section.heading.line, body.replace(/\r\n/g, "\n"));
43
+ }
44
+ return bodies;
45
+ }
46
+ /**
47
+ * Pairs headings across two revisions, conservatively.
48
+ *
49
+ * Three passes, most certain first: exact slug, then exact normalized text
50
+ * (which recovers a heading whose slug only shifted because a duplicate sibling
51
+ * appeared or vanished), then a positional guess. The positional pass requires
52
+ * the same depth, the same parent path, and the same position among siblings,
53
+ * and is the only one that ever produces a "renamed" verdict.
54
+ *
55
+ * String similarity is deliberately not used. It is the classic source of
56
+ * confident nonsense, and a wrong rename is worse than an honest add plus
57
+ * remove.
58
+ */
59
+ export function matchHeadings(before, after) {
60
+ const pairs = [];
61
+ const usedBefore = new Set();
62
+ const usedAfter = new Set();
63
+ const pass = (key, matchedBy) => {
64
+ const index = new Map();
65
+ for (let position = 0; position < after.length; position++) {
66
+ if (usedAfter.has(position))
67
+ continue;
68
+ const value = key(after, position);
69
+ if (value === undefined)
70
+ continue;
71
+ index.set(value, [...(index.get(value) ?? []), position]);
72
+ }
73
+ for (let position = 0; position < before.length; position++) {
74
+ if (usedBefore.has(position))
75
+ continue;
76
+ const value = key(before, position);
77
+ if (value === undefined)
78
+ continue;
79
+ const candidates = index.get(value);
80
+ const match = candidates?.find((candidate) => !usedAfter.has(candidate));
81
+ if (match === undefined)
82
+ continue;
83
+ usedBefore.add(position);
84
+ usedAfter.add(match);
85
+ pairs.push({ before: position, after: match, matchedBy });
86
+ }
87
+ };
88
+ pass((headings, index) => headings[index].slug, "slug");
89
+ pass((headings, index) => normalize(headings[index].text), "text");
90
+ // Segments are joined with a separator that cannot appear in heading text,
91
+ // so a parent path of ["a", "b"] never collides with one of ["ab"].
92
+ pass((headings, index) => `${headings[index].depth}\0${parentPath(headings, index).map(normalize).join("\0")}\0${siblingOrdinal(headings, index)}`, "position");
93
+ return {
94
+ pairs: pairs.sort((a, b) => a.after - b.after || a.before - b.before),
95
+ removed: before.map((_, index) => index).filter((index) => !usedBefore.has(index)),
96
+ added: after.map((_, index) => index).filter((index) => !usedAfter.has(index)),
97
+ };
98
+ }
99
+ function headingChanges(before, after) {
100
+ const oldHeadings = before ? realHeadings(before) : [];
101
+ const newHeadings = after ? realHeadings(after) : [];
102
+ const oldBodies = before ? sectionBodies(before) : new Map();
103
+ const newBodies = after ? sectionBodies(after) : new Map();
104
+ const { pairs, removed, added } = matchHeadings(oldHeadings, newHeadings);
105
+ const changes = [];
106
+ for (const pair of pairs) {
107
+ const from = oldHeadings[pair.before];
108
+ const to = newHeadings[pair.after];
109
+ const bodyChanged = oldBodies.get(from.line) !== newBodies.get(to.line);
110
+ const renamed = normalize(from.text) !== normalize(to.text);
111
+ // Ordinal, not line: inserting a paragraph must not report every following
112
+ // heading as moved.
113
+ const moved = pair.before !== pair.after || from.depth !== to.depth;
114
+ if (!renamed && !moved && !bodyChanged)
115
+ continue;
116
+ const kind = renamed ? "renamed" : moved ? "moved" : "changed";
117
+ changes.push({
118
+ kind,
119
+ oldText: from.text,
120
+ oldSlug: from.slug,
121
+ oldLine: from.line,
122
+ oldDepth: from.depth,
123
+ newText: to.text,
124
+ newSlug: to.slug,
125
+ newLine: to.line,
126
+ newDepth: to.depth,
127
+ ...(bodyChanged ? { bodyChanged: true } : {}),
128
+ ...(kind === "renamed" ? { heuristic: pair.matchedBy === "position" } : {}),
129
+ matchedBy: pair.matchedBy,
130
+ });
131
+ }
132
+ for (const index of removed) {
133
+ const heading = oldHeadings[index];
134
+ changes.push({
135
+ kind: "removed",
136
+ oldText: heading.text,
137
+ oldSlug: heading.slug,
138
+ oldLine: heading.line,
139
+ oldDepth: heading.depth,
140
+ });
141
+ }
142
+ for (const index of added) {
143
+ const heading = newHeadings[index];
144
+ changes.push({
145
+ kind: "added",
146
+ newText: heading.text,
147
+ newSlug: heading.slug,
148
+ newLine: heading.line,
149
+ newDepth: heading.depth,
150
+ });
151
+ }
152
+ return changes;
153
+ }
154
+ /** Flattens a mapping to dotted paths, treating arrays as leaves. */
155
+ function flatten(value, prefix = "", into = new Map()) {
156
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
157
+ if (prefix)
158
+ into.set(prefix, value);
159
+ return into;
160
+ }
161
+ for (const [key, nested] of Object.entries(value)) {
162
+ flatten(nested, prefix ? `${prefix}.${key}` : key, into);
163
+ }
164
+ return into;
165
+ }
166
+ function sameValue(left, right) {
167
+ return JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
168
+ }
169
+ function frontmatterChanges(before, after) {
170
+ const oldStatus = before?.status;
171
+ const newStatus = after?.status;
172
+ if (before && after && oldStatus !== newStatus) {
173
+ return [{ kind: "changed", key: null, oldStatus, newStatus }];
174
+ }
175
+ if (before?.status !== "valid" || after?.status !== "valid")
176
+ return [];
177
+ const oldFlat = flatten(before.data);
178
+ const newFlat = flatten(after.data);
179
+ const changes = [];
180
+ for (const [key, oldValue] of oldFlat) {
181
+ if (!newFlat.has(key)) {
182
+ changes.push({ kind: "removed", key, oldValue });
183
+ }
184
+ else if (!sameValue(oldValue, newFlat.get(key))) {
185
+ changes.push({ kind: "changed", key, oldValue, newValue: newFlat.get(key) });
186
+ }
187
+ }
188
+ for (const [key, newValue] of newFlat) {
189
+ if (!oldFlat.has(key))
190
+ changes.push({ kind: "added", key, newValue });
191
+ }
192
+ // Byte comparison, never localeCompare: that is ICU-build and locale
193
+ // dependent, so a differently configured runner would reorder the payload.
194
+ return changes.sort((a, b) => {
195
+ const left = a.key ?? "";
196
+ const right = b.key ?? "";
197
+ return left < right ? -1 : left > right ? 1 : 0;
198
+ });
199
+ }
200
+ function resolveLinks(document, root) {
201
+ return document.references.map((reference) => {
202
+ if (reference.isExternal || reference.isAnchorOnly) {
203
+ return { reference, resolved: null, path: reference.target };
204
+ }
205
+ const parsed = splitLocalTarget(reference.target);
206
+ return {
207
+ reference,
208
+ resolved: resolveLocalPath(document.path, parsed.path, root),
209
+ ...(parsed.fragment === undefined ? {} : { fragment: parsed.fragment }),
210
+ path: parsed.path,
211
+ };
212
+ });
213
+ }
214
+ /**
215
+ * Pairs items across revisions by a sequence of keys, each tried in turn, in
216
+ * order of appearance.
217
+ *
218
+ * There is deliberately no unconditional positional fallback. Pairing whatever
219
+ * is left over by position invents a "changed" record out of an unrelated
220
+ * removal and addition. Where a looser match is genuinely wanted — a code block
221
+ * whose body was edited — it is expressed as a further key with its own guard,
222
+ * so every pairing rule is visible here rather than implied.
223
+ */
224
+ function pairByKeys(before, after, keys) {
225
+ const usedBefore = new Set();
226
+ const usedAfter = new Set();
227
+ const pairs = [];
228
+ for (const key of keys) {
229
+ for (let index = 0; index < before.length; index++) {
230
+ if (usedBefore.has(index))
231
+ continue;
232
+ const value = key(before[index]);
233
+ const match = after.findIndex((candidate, position) => !usedAfter.has(position) && key(candidate) === value);
234
+ if (match === -1)
235
+ continue;
236
+ usedBefore.add(index);
237
+ usedAfter.add(match);
238
+ pairs.push([index, match]);
239
+ }
240
+ }
241
+ return {
242
+ pairs: pairs.sort((a, b) => a[1] - b[1]),
243
+ removed: before.map((_, index) => index).filter((index) => !usedBefore.has(index)),
244
+ added: after.map((_, index) => index).filter((index) => !usedAfter.has(index)),
245
+ };
246
+ }
247
+ function linkChanges(before, after, root) {
248
+ const oldLinks = before ? resolveLinks(before, root) : [];
249
+ const newLinks = after ? resolveLinks(after, root) : [];
250
+ // Link text is the stable identity when a target is repointed, which is the
251
+ // change worth reporting. Links matching on neither text nor target stay a
252
+ // removal plus an addition rather than being guessed into a "changed".
253
+ const { pairs, removed, added } = pairByKeys(oldLinks, newLinks, [
254
+ (link) => `${link.reference.linkText}\0${link.reference.target}`,
255
+ (link) => link.reference.linkText,
256
+ (link) => link.reference.target,
257
+ ]);
258
+ const changes = [];
259
+ for (const [oldIndex, newIndex] of pairs) {
260
+ const from = oldLinks[oldIndex];
261
+ const to = newLinks[newIndex];
262
+ if (from.reference.target === to.reference.target)
263
+ continue;
264
+ changes.push({
265
+ kind: "changed",
266
+ oldTarget: from.reference.target,
267
+ newTarget: to.reference.target,
268
+ oldResolved: from.resolved,
269
+ newResolved: to.resolved,
270
+ oldLine: from.reference.line,
271
+ newLine: to.reference.line,
272
+ linkText: to.reference.linkText,
273
+ ...(from.path === to.path && from.fragment !== to.fragment ? { fragmentChanged: true } : {}),
274
+ });
275
+ }
276
+ for (const index of removed) {
277
+ changes.push({
278
+ kind: "removed",
279
+ oldTarget: oldLinks[index].reference.target,
280
+ oldResolved: oldLinks[index].resolved,
281
+ oldLine: oldLinks[index].reference.line,
282
+ linkText: oldLinks[index].reference.linkText,
283
+ });
284
+ }
285
+ for (const index of added) {
286
+ changes.push({
287
+ kind: "added",
288
+ newTarget: newLinks[index].reference.target,
289
+ newResolved: newLinks[index].resolved,
290
+ newLine: newLinks[index].reference.line,
291
+ linkText: newLinks[index].reference.linkText,
292
+ });
293
+ }
294
+ return changes;
295
+ }
296
+ function taskChanges(before, after) {
297
+ const oldTasks = before ? extractTasks(before.tree) : [];
298
+ const newTasks = after ? extractTasks(after.tree) : [];
299
+ const { pairs, removed, added } = pairByKeys(oldTasks, newTasks, [
300
+ (task) => normalize(task.text),
301
+ ]);
302
+ const changes = [];
303
+ for (const [oldIndex, newIndex] of pairs) {
304
+ const from = oldTasks[oldIndex];
305
+ const to = newTasks[newIndex];
306
+ if (from.checked === to.checked)
307
+ continue;
308
+ changes.push({
309
+ kind: "changed",
310
+ text: to.text,
311
+ oldLine: from.line,
312
+ newLine: to.line,
313
+ oldChecked: from.checked,
314
+ newChecked: to.checked,
315
+ });
316
+ }
317
+ for (const index of removed) {
318
+ changes.push({
319
+ kind: "removed",
320
+ text: oldTasks[index].text,
321
+ oldLine: oldTasks[index].line,
322
+ oldChecked: oldTasks[index].checked,
323
+ });
324
+ }
325
+ for (const index of added) {
326
+ changes.push({
327
+ kind: "added",
328
+ text: newTasks[index].text,
329
+ newLine: newTasks[index].line,
330
+ newChecked: newTasks[index].checked,
331
+ });
332
+ }
333
+ return changes;
334
+ }
335
+ function codeBlockChanges(before, after) {
336
+ const oldBlocks = before ? extractCodeBlocks(before.tree) : [];
337
+ const newBlocks = after ? extractCodeBlocks(after.tree) : [];
338
+ const { pairs, removed, added } = pairByKeys(oldBlocks, newBlocks, [
339
+ (block) => `${block.lang ?? ""}\0${block.value}`,
340
+ (block) => block.value,
341
+ // Same language, body edited. Without this a rewritten block reads as a
342
+ // removal plus an addition and the `contentChanged` signal is lost; the
343
+ // language guard stops it pairing two unrelated fences.
344
+ (block) => `lang\0${block.lang ?? ""}`,
345
+ ]);
346
+ const mermaid = (...langs) => langs.some((lang) => lang?.toLowerCase() === "mermaid");
347
+ const changes = [];
348
+ for (const [oldIndex, newIndex] of pairs) {
349
+ const from = oldBlocks[oldIndex];
350
+ const to = newBlocks[newIndex];
351
+ const langChanged = from.lang !== to.lang;
352
+ const contentChanged = from.value !== to.value;
353
+ if (!langChanged && !contentChanged)
354
+ continue;
355
+ changes.push({
356
+ kind: "changed",
357
+ oldLang: from.lang,
358
+ newLang: to.lang,
359
+ oldLine: from.line,
360
+ newLine: to.line,
361
+ ...(langChanged ? { langChanged: true } : {}),
362
+ ...(contentChanged ? { contentChanged: true } : {}),
363
+ ...(mermaid(from.lang, to.lang) ? { mermaid: true } : {}),
364
+ });
365
+ }
366
+ for (const index of removed) {
367
+ changes.push({
368
+ kind: "removed",
369
+ oldLang: oldBlocks[index].lang,
370
+ oldLine: oldBlocks[index].line,
371
+ ...(mermaid(oldBlocks[index].lang) ? { mermaid: true } : {}),
372
+ });
373
+ }
374
+ for (const index of added) {
375
+ changes.push({
376
+ kind: "added",
377
+ newLang: newBlocks[index].lang,
378
+ newLine: newBlocks[index].line,
379
+ ...(mermaid(newBlocks[index].lang) ? { mermaid: true } : {}),
380
+ });
381
+ }
382
+ return changes;
383
+ }
384
+ function tableChanges(before, after) {
385
+ const oldTables = before ? extractTables(before.tree) : [];
386
+ const newTables = after ? extractTables(after.tree) : [];
387
+ const { pairs, removed, added } = pairByKeys(oldTables, newTables, [
388
+ (table) => table.headers.join("\0"),
389
+ // Same shape, headers edited. The column count guards against pairing two
390
+ // structurally unrelated tables.
391
+ (table) => `columns\0${table.columns}`,
392
+ ]);
393
+ const changes = [];
394
+ for (const [oldIndex, newIndex] of pairs) {
395
+ const from = oldTables[oldIndex];
396
+ const to = newTables[newIndex];
397
+ const headersChanged = from.headers.join("\0") !== to.headers.join("\0");
398
+ if (from.columns === to.columns && from.rows === to.rows && !headersChanged)
399
+ continue;
400
+ changes.push({
401
+ kind: "changed",
402
+ oldLine: from.line,
403
+ newLine: to.line,
404
+ oldColumns: from.columns,
405
+ newColumns: to.columns,
406
+ oldRows: from.rows,
407
+ newRows: to.rows,
408
+ ...(headersChanged ? { headersChanged: true } : {}),
409
+ });
410
+ }
411
+ for (const index of removed) {
412
+ changes.push({
413
+ kind: "removed",
414
+ oldLine: oldTables[index].line,
415
+ oldColumns: oldTables[index].columns,
416
+ oldRows: oldTables[index].rows,
417
+ });
418
+ }
419
+ for (const index of added) {
420
+ changes.push({
421
+ kind: "added",
422
+ newLine: newTables[index].line,
423
+ newColumns: newTables[index].columns,
424
+ newRows: newTables[index].rows,
425
+ });
426
+ }
427
+ return changes;
428
+ }
429
+ const KIND_ORDER = {
430
+ added: 0,
431
+ changed: 1,
432
+ moved: 2,
433
+ removed: 3,
434
+ renamed: 4,
435
+ };
436
+ function sortChanges(changes) {
437
+ return changes.sort((a, b) => (a.newLine ?? a.oldLine ?? 0) - (b.newLine ?? b.oldLine ?? 0) ||
438
+ KIND_ORDER[a.kind] - KIND_ORDER[b.kind]);
439
+ }
440
+ /** Compares two revisions of one document. `null` means absent on that side. */
441
+ export function diffDocuments(before, after, options) {
442
+ const headings = sortChanges(headingChanges(before, after));
443
+ const frontmatter = frontmatterChanges(before?.frontmatter, after?.frontmatter);
444
+ const links = sortChanges(linkChanges(before, after, options.root));
445
+ const tasks = sortChanges(taskChanges(before, after));
446
+ const codeBlocks = sortChanges(codeBlockChanges(before, after));
447
+ const tables = sortChanges(tableChanges(before, after));
448
+ const counts = {
449
+ headings: headings.length,
450
+ frontmatter: frontmatter.length,
451
+ links: links.length,
452
+ tasks: tasks.length,
453
+ codeBlocks: codeBlocks.length,
454
+ tables: tables.length,
455
+ };
456
+ const changes = Object.values(counts).reduce((total, count) => total + count, 0);
457
+ let status = "unchanged";
458
+ if (!before)
459
+ status = "added";
460
+ else if (!after)
461
+ status = "removed";
462
+ else if (options.oldPath && options.oldPath !== options.file)
463
+ status = "renamed";
464
+ else if (changes > 0)
465
+ status = "modified";
466
+ return {
467
+ file: options.file,
468
+ ...(options.oldPath && options.oldPath !== options.file ? { oldPath: options.oldPath } : {}),
469
+ status,
470
+ ...(options.similarity === undefined ? {} : { similarity: options.similarity }),
471
+ headings,
472
+ frontmatter,
473
+ links,
474
+ tasks,
475
+ codeBlocks,
476
+ tables,
477
+ totals: { ...counts, changes },
478
+ };
479
+ }
480
+ /** Rolls per-file diffs into a report. */
481
+ export function summarize(files, head) {
482
+ const sum = (pick) => files.reduce((total, file) => total + pick(file), 0);
483
+ return {
484
+ ...head,
485
+ files,
486
+ totals: {
487
+ files: files.length,
488
+ filesChanged: files.filter((file) => file.status !== "unchanged").length,
489
+ headings: sum((file) => file.totals.headings),
490
+ frontmatter: sum((file) => file.totals.frontmatter),
491
+ links: sum((file) => file.totals.links),
492
+ tasks: sum((file) => file.totals.tasks),
493
+ codeBlocks: sum((file) => file.totals.codeBlocks),
494
+ tables: sum((file) => file.totals.tables),
495
+ heuristicRenames: sum((file) => file.headings.filter((change) => change.heuristic === true).length),
496
+ diagrams: sum((file) => file.codeBlocks.filter((change) => change.mermaid === true).length),
497
+ },
498
+ };
499
+ }
500
+ //# sourceMappingURL=diff.js.map