@sledorze/cairn 0.1.0 → 0.3.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 (117) hide show
  1. package/README.md +69 -18
  2. package/dist/cli.js +69378 -70958
  3. package/dist/cli.js.map +1 -1
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +10 -10
  6. package/dist/config.js.map +1 -1
  7. package/dist/core/Config.d.ts +22 -22
  8. package/dist/core/Config.d.ts.map +1 -1
  9. package/dist/core/Config.js +33 -33
  10. package/dist/core/Config.js.map +1 -1
  11. package/dist/core/glob.bench.js +1 -1
  12. package/dist/core/glob.d.ts.map +1 -1
  13. package/dist/core/hashing.d.ts +3 -0
  14. package/dist/core/hashing.d.ts.map +1 -0
  15. package/dist/core/hashing.js +16 -0
  16. package/dist/core/hashing.js.map +1 -0
  17. package/dist/core/links/Anchors.d.ts +30 -0
  18. package/dist/core/links/Anchors.d.ts.map +1 -0
  19. package/dist/core/links/Anchors.js +119 -0
  20. package/dist/core/links/Anchors.js.map +1 -0
  21. package/dist/core/links/MarkdownLinks.bench.d.ts.map +1 -0
  22. package/dist/core/{MarkdownLinks.bench.js → links/MarkdownLinks.bench.js} +1 -1
  23. package/dist/core/links/MarkdownLinks.bench.js.map +1 -0
  24. package/dist/core/links/MarkdownLinks.d.ts +121 -0
  25. package/dist/core/links/MarkdownLinks.d.ts.map +1 -0
  26. package/dist/core/links/MarkdownLinks.js +228 -0
  27. package/dist/core/links/MarkdownLinks.js.map +1 -0
  28. package/dist/core/links/RefStore.d.ts +32 -0
  29. package/dist/core/links/RefStore.d.ts.map +1 -0
  30. package/dist/core/links/RefStore.js +60 -0
  31. package/dist/core/links/RefStore.js.map +1 -0
  32. package/dist/core/links/markdownFences.d.ts +10 -0
  33. package/dist/core/links/markdownFences.d.ts.map +1 -0
  34. package/dist/core/links/markdownFences.js +51 -0
  35. package/dist/core/links/markdownFences.js.map +1 -0
  36. package/dist/core/paths.d.ts +8 -0
  37. package/dist/core/paths.d.ts.map +1 -1
  38. package/dist/core/paths.js +13 -0
  39. package/dist/core/paths.js.map +1 -1
  40. package/dist/core/sidecar.d.ts +45 -0
  41. package/dist/core/sidecar.d.ts.map +1 -0
  42. package/dist/core/sidecar.js +83 -0
  43. package/dist/core/sidecar.js.map +1 -0
  44. package/dist/core/{DocSummaries.d.ts → summaries/DocSummaries.d.ts} +13 -3
  45. package/dist/core/summaries/DocSummaries.d.ts.map +1 -0
  46. package/dist/core/{DocSummaries.js → summaries/DocSummaries.js} +31 -11
  47. package/dist/core/summaries/DocSummaries.js.map +1 -0
  48. package/dist/core/summaries/StampStore.d.ts +19 -0
  49. package/dist/core/summaries/StampStore.d.ts.map +1 -0
  50. package/dist/core/summaries/StampStore.js +34 -0
  51. package/dist/core/summaries/StampStore.js.map +1 -0
  52. package/dist/core/summaries/SummaryTree.bench.d.ts.map +1 -0
  53. package/dist/core/{SummaryTree.bench.js → summaries/SummaryTree.bench.js} +24 -14
  54. package/dist/core/summaries/SummaryTree.bench.js.map +1 -0
  55. package/dist/core/{SummaryTree.d.ts → summaries/SummaryTree.d.ts} +10 -1
  56. package/dist/core/summaries/SummaryTree.d.ts.map +1 -0
  57. package/dist/core/{SummaryTree.js → summaries/SummaryTree.js} +35 -9
  58. package/dist/core/summaries/SummaryTree.js.map +1 -0
  59. package/dist/index.d.ts +5 -5
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +10 -10
  62. package/dist/index.js.map +1 -1
  63. package/dist/init/content.d.ts +2 -2
  64. package/dist/init/content.d.ts.map +1 -1
  65. package/dist/init/content.js +45 -15
  66. package/dist/init/content.js.map +1 -1
  67. package/dist/init/generate.d.ts +1 -1
  68. package/dist/init/generate.d.ts.map +1 -1
  69. package/dist/init/generate.js +1 -1
  70. package/dist/io/DocsFs.d.ts +2 -3
  71. package/dist/io/DocsFs.d.ts.map +1 -1
  72. package/dist/io/DocsFs.js +15 -5
  73. package/dist/io/DocsFs.js.map +1 -1
  74. package/dist/program/JsonReport.d.ts +2 -2
  75. package/dist/program/JsonReport.d.ts.map +1 -1
  76. package/dist/program/JsonReport.js +2 -2
  77. package/dist/program/JsonReport.js.map +1 -1
  78. package/dist/program/{CheckLinks.d.ts → links/CheckLinks.d.ts} +9 -4
  79. package/dist/program/links/CheckLinks.d.ts.map +1 -0
  80. package/dist/program/links/CheckLinks.js +243 -0
  81. package/dist/program/links/CheckLinks.js.map +1 -0
  82. package/dist/program/links/CheckRefs.d.ts +47 -0
  83. package/dist/program/links/CheckRefs.d.ts.map +1 -0
  84. package/dist/program/links/CheckRefs.js +151 -0
  85. package/dist/program/links/CheckRefs.js.map +1 -0
  86. package/dist/program/locale.d.ts.map +1 -1
  87. package/dist/program/summaries/CheckSummaries.bench.d.ts +2 -0
  88. package/dist/program/summaries/CheckSummaries.bench.d.ts.map +1 -0
  89. package/dist/program/summaries/CheckSummaries.bench.js +94 -0
  90. package/dist/program/summaries/CheckSummaries.bench.js.map +1 -0
  91. package/dist/program/summaries/CheckSummaries.d.ts +58 -0
  92. package/dist/program/summaries/CheckSummaries.d.ts.map +1 -0
  93. package/dist/program/summaries/CheckSummaries.js +302 -0
  94. package/dist/program/summaries/CheckSummaries.js.map +1 -0
  95. package/package.json +7 -8
  96. package/schema/cairn.schema.json +35 -38
  97. package/dist/core/DocSummaries.d.ts.map +0 -1
  98. package/dist/core/DocSummaries.js.map +0 -1
  99. package/dist/core/MarkdownLinks.bench.d.ts.map +0 -1
  100. package/dist/core/MarkdownLinks.bench.js.map +0 -1
  101. package/dist/core/MarkdownLinks.d.ts +0 -51
  102. package/dist/core/MarkdownLinks.d.ts.map +0 -1
  103. package/dist/core/MarkdownLinks.js +0 -115
  104. package/dist/core/MarkdownLinks.js.map +0 -1
  105. package/dist/core/SummaryTree.bench.d.ts.map +0 -1
  106. package/dist/core/SummaryTree.bench.js.map +0 -1
  107. package/dist/core/SummaryTree.d.ts.map +0 -1
  108. package/dist/core/SummaryTree.js.map +0 -1
  109. package/dist/program/CheckLinks.d.ts.map +0 -1
  110. package/dist/program/CheckLinks.js +0 -122
  111. package/dist/program/CheckLinks.js.map +0 -1
  112. package/dist/program/CheckSummaries.d.ts +0 -38
  113. package/dist/program/CheckSummaries.d.ts.map +0 -1
  114. package/dist/program/CheckSummaries.js +0 -198
  115. package/dist/program/CheckSummaries.js.map +0 -1
  116. /package/dist/core/{MarkdownLinks.bench.d.ts → links/MarkdownLinks.bench.d.ts} +0 -0
  117. /package/dist/core/{SummaryTree.bench.d.ts → summaries/SummaryTree.bench.d.ts} +0 -0
package/README.md CHANGED
@@ -16,15 +16,18 @@ compares modification times. But **git does not preserve mtimes**: after a clone
16
16
  checkout, every file looks freshly written, so a time-based check silently passes on
17
17
  summaries that are actually stale. The bug you meant to catch ships anyway.
18
18
 
19
- `cairn` checks **content**, not clocks. Each summary embeds the SHA-256 of the
20
- source it summarizes as its first line:
19
+ `cairn` checks **content**, not clocks. The SHA-256 of the source each summary
20
+ summarizes is recorded in a hidden sidecar under `.cairn/`, mirroring your docs tree —
21
+ never inside the summary itself, so the tracking system leaves zero bytes in the docs
22
+ you write:
21
23
 
22
- ```markdown
23
- <!-- source-sha256: 3f9a…(64 hex) -->
24
+ ```
25
+ .cairn/docs/guide.summary.md.json → {"sha256": "3f9a…(64 hex)", "version": 1}
24
26
  ```
25
27
 
26
- The checker recomputes the source hash and compares. Mismatch means stale, missing means
27
- missing — and it behaves identically on your laptop and in CI, before and after a clone.
28
+ The checker recomputes the source hash and compares it to the sidecar. Mismatch means
29
+ stale, missing means missing — and it behaves identically on your laptop and in CI,
30
+ before and after a clone. Commit `.cairn/` alongside your docs; it isn't gitignored.
28
31
 
29
32
  ## Install
30
33
 
@@ -42,24 +45,72 @@ The round-trip when you touch a doc:
42
45
 
43
46
  1. **Edit** `docs/guide.md`.
44
47
  2. `npx cairn check` **flags it stale** — the source hash no longer matches the
45
- stamp in `guide.summary.md`.
48
+ sidecar recorded for `guide.summary.md`.
46
49
  3. **Write** the updated `guide.summary.md` (and update any parent `_SUMMARY.md`).
47
- 4. **Stamp**: `npx cairn check --summaries-only --stamp` rewrites the
48
- `source-sha256` lines bottom-up.
50
+ 4. **Stamp**: `npx cairn check --summaries-only --stamp` rewrites the `.cairn/`
51
+ sidecar hashes bottom-up — your summary's content is never touched.
49
52
  5. **Check** again — `npx cairn check` exits 0. Green.
50
53
 
51
- You author the prose; the tool verifies and stamps. It never invents content.
54
+ You author the prose; the tool verifies and stamps. It never invents content, and it
55
+ never writes into content either.
52
56
 
53
57
  ### Commands
54
58
 
55
- | Command | What it does |
56
- | ----------------------------------------- | -------------------------------------------------------- |
57
- | `cairn check` | Check summaries + links; exit 1 on any problem |
58
- | `cairn check --summaries-only` | Check only summary freshness |
59
- | `cairn check --links-only` | Check only Markdown links |
60
- | `cairn check --links-only --fix` | Auto-repair unambiguous dead links |
61
- | `cairn check --summaries-only --stamp` | Rewrite `source-sha256` of existing summaries, bottom-up |
62
- | `cairn init --agent claude\|copilot\|all` | Scaffold agent guidance files |
59
+ | Command | What it does |
60
+ | ----------------------------------------- | ------------------------------------------------------------------------- |
61
+ | `cairn check` | Check summaries + links; exit 1 on any problem |
62
+ | `cairn check --summaries-only` | Check only summary freshness |
63
+ | `cairn check --links-only` | Check only Markdown links |
64
+ | `cairn check --links-only --fix` | Auto-repair unambiguous dead links |
65
+ | `cairn check --summaries-only --stamp` | Rewrite the `.cairn/` sidecar hash of existing summaries, bottom-up |
66
+ | `cairn check --prune` | Delete orphan summaries and orphan `.cairn/` sidecars |
67
+ | `cairn check --migrate-stamps` | Optional: same self-healing `--stamp` already does, as its own named step |
68
+ | `cairn check --refs --stamp` | Opt-in: record each real reference target's content hash |
69
+ | `cairn check --refs` | Opt-in: report references whose target content has drifted since |
70
+ | `cairn init --agent claude\|copilot\|all` | Scaffold agent guidance files |
71
+
72
+ ### Link checking
73
+
74
+ A dead link is only the most obvious way a reference rots. `cairn check` (or
75
+ `--links-only`) verifies, for every relative Markdown link:
76
+
77
+ - **The path resolves** — including targets _outside_ your configured `roots`, as long as
78
+ they stay inside the repository checkout (e.g. a doc in `docs/` linking to `../src/foo.ts`).
79
+ Nothing outside the checkout root is ever touched, even to check existence — this bound is
80
+ deliberate: CI runs over untrusted PR content, and an unbounded filesystem check would be
81
+ an existence oracle.
82
+ - **The `#heading` fragment exists** — same-page (`[intro](#getting-started)`) and
83
+ cross-file (`[intro](./guide.md#getting-started)`), slugged the same way GitHub does.
84
+ - **A `#L10`/`#L10-L20` line-fragment is in range**, for links to source files outside `roots`.
85
+
86
+ A broken heading or out-of-range line reports with the reason (`path` / `anchor` / `line`)
87
+ and, where possible, what's actually there (the target's real headings, or its real line
88
+ count) — so fixing it doesn't require opening the target file first.
89
+
90
+ `cairn check --refs` is a separate, **opt-in** signal, off by default and not part of the
91
+ `path`/`anchor`/`line` checks above: it tracks the _content_ of what a link points to, not
92
+ just whether the link resolves. `--refs --stamp` records a hash of every reference target;
93
+ a later `--refs` run reports any that changed since — "this doc's claim about that file may
94
+ be stale," distinct from a broken link (the link still resolves; what it once meant may not
95
+ still hold). Still v1/experimental (whole-file hashing only — a one-line unrelated change to
96
+ a large target file is reported the same as a change to the exact part being referenced).
97
+
98
+ ### Upgrading from an older cairn
99
+
100
+ **If you're upgrading past `0.3.0`**: link checking got stricter. Anchors and links outside
101
+ `roots` were previously accepted unconditionally, whether or not they actually resolved —
102
+ `cairn` simply never looked. If `cairn check` newly fails after upgrading, the links it's
103
+ flagging were already broken; nothing about your docs changed, only the tool's ability to
104
+ notice did. Fix the flagged link/anchor, or, if a genuine false positive (e.g. a symbol-level
105
+ anchor like `x.ts#someExport` — deliberately never checked, see the source's own scenario
106
+ notes), please open an issue.
107
+
108
+ Nothing to look up for the summary/stamp side. If a summary still carries the old in-content
109
+ `<!-- source-sha256: ... -->` comment, the ordinary `--stamp` command strips it and
110
+ writes the `.cairn/` sidecar in the same run — automatically, every time. There is no
111
+ separate migration step to discover: whatever `stampCommand` your repo already runs
112
+ already handles it. `--migrate-stamps` exists only as an optional, explicitly-named
113
+ alias for the same behavior, for anyone who wants the cleanup reported as its own step.
63
114
 
64
115
  ## The two summary kinds
65
116