@isaacriehm/cairn-core 0.1.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 (616) hide show
  1. package/LICENSE +21 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/claude/error.d.ts +33 -0
  4. package/dist/claude/error.js +58 -0
  5. package/dist/claude/error.js.map +1 -0
  6. package/dist/claude/index.d.ts +3 -0
  7. package/dist/claude/index.js +3 -0
  8. package/dist/claude/index.js.map +1 -0
  9. package/dist/claude/runner.d.ts +11 -0
  10. package/dist/claude/runner.js +132 -0
  11. package/dist/claude/runner.js.map +1 -0
  12. package/dist/claude/types.d.ts +52 -0
  13. package/dist/claude/types.js +14 -0
  14. package/dist/claude/types.js.map +1 -0
  15. package/dist/context/checkpoint.d.ts +10 -0
  16. package/dist/context/checkpoint.js +29 -0
  17. package/dist/context/checkpoint.js.map +1 -0
  18. package/dist/context/handoff-builder.d.ts +11 -0
  19. package/dist/context/handoff-builder.js +268 -0
  20. package/dist/context/handoff-builder.js.map +1 -0
  21. package/dist/context/index.d.ts +11 -0
  22. package/dist/context/index.js +11 -0
  23. package/dist/context/index.js.map +1 -0
  24. package/dist/context/spec-delta.d.ts +47 -0
  25. package/dist/context/spec-delta.js +237 -0
  26. package/dist/context/spec-delta.js.map +1 -0
  27. package/dist/decision-capture/capture.d.ts +57 -0
  28. package/dist/decision-capture/capture.js +186 -0
  29. package/dist/decision-capture/capture.js.map +1 -0
  30. package/dist/decision-capture/extractor.d.ts +20 -0
  31. package/dist/decision-capture/extractor.js +103 -0
  32. package/dist/decision-capture/extractor.js.map +1 -0
  33. package/dist/decision-capture/id.d.ts +21 -0
  34. package/dist/decision-capture/id.js +60 -0
  35. package/dist/decision-capture/id.js.map +1 -0
  36. package/dist/decision-capture/index.d.ts +25 -0
  37. package/dist/decision-capture/index.js +21 -0
  38. package/dist/decision-capture/index.js.map +1 -0
  39. package/dist/decision-capture/prompt.d.ts +15 -0
  40. package/dist/decision-capture/prompt.js +68 -0
  41. package/dist/decision-capture/prompt.js.map +1 -0
  42. package/dist/decision-capture/refinement-prompt.d.ts +25 -0
  43. package/dist/decision-capture/refinement-prompt.js +146 -0
  44. package/dist/decision-capture/refinement-prompt.js.map +1 -0
  45. package/dist/decision-capture/refinement-schema.d.ts +52 -0
  46. package/dist/decision-capture/refinement-schema.js +61 -0
  47. package/dist/decision-capture/refinement-schema.js.map +1 -0
  48. package/dist/decision-capture/refinement.d.ts +60 -0
  49. package/dist/decision-capture/refinement.js +439 -0
  50. package/dist/decision-capture/refinement.js.map +1 -0
  51. package/dist/decision-capture/schema.d.ts +70 -0
  52. package/dist/decision-capture/schema.js +71 -0
  53. package/dist/decision-capture/schema.js.map +1 -0
  54. package/dist/decision-capture/types.d.ts +201 -0
  55. package/dist/decision-capture/types.js +20 -0
  56. package/dist/decision-capture/types.js.map +1 -0
  57. package/dist/decision-capture/writer.d.ts +90 -0
  58. package/dist/decision-capture/writer.js +267 -0
  59. package/dist/decision-capture/writer.js.map +1 -0
  60. package/dist/doctor/index.d.ts +48 -0
  61. package/dist/doctor/index.js +460 -0
  62. package/dist/doctor/index.js.map +1 -0
  63. package/dist/events/index.d.ts +15 -0
  64. package/dist/events/index.js +14 -0
  65. package/dist/events/index.js.map +1 -0
  66. package/dist/events/paths.d.ts +2 -0
  67. package/dist/events/paths.js +6 -0
  68. package/dist/events/paths.js.map +1 -0
  69. package/dist/events/reader.d.ts +40 -0
  70. package/dist/events/reader.js +139 -0
  71. package/dist/events/reader.js.map +1 -0
  72. package/dist/events/writer.d.ts +61 -0
  73. package/dist/events/writer.js +68 -0
  74. package/dist/events/writer.js.map +1 -0
  75. package/dist/frontend-types.d.ts +243 -0
  76. package/dist/frontend-types.js +15 -0
  77. package/dist/frontend-types.js.map +1 -0
  78. package/dist/gc/apply.d.ts +26 -0
  79. package/dist/gc/apply.js +48 -0
  80. package/dist/gc/apply.js.map +1 -0
  81. package/dist/gc/canary.d.ts +42 -0
  82. package/dist/gc/canary.js +134 -0
  83. package/dist/gc/canary.js.map +1 -0
  84. package/dist/gc/citation-integrity.d.ts +24 -0
  85. package/dist/gc/citation-integrity.js +151 -0
  86. package/dist/gc/citation-integrity.js.map +1 -0
  87. package/dist/gc/classify.d.ts +25 -0
  88. package/dist/gc/classify.js +89 -0
  89. package/dist/gc/classify.js.map +1 -0
  90. package/dist/gc/completion-integrity.d.ts +22 -0
  91. package/dist/gc/completion-integrity.js +165 -0
  92. package/dist/gc/completion-integrity.js.map +1 -0
  93. package/dist/gc/doc-gardening.d.ts +29 -0
  94. package/dist/gc/doc-gardening.js +146 -0
  95. package/dist/gc/doc-gardening.js.map +1 -0
  96. package/dist/gc/frontmatter.d.ts +35 -0
  97. package/dist/gc/frontmatter.js +105 -0
  98. package/dist/gc/frontmatter.js.map +1 -0
  99. package/dist/gc/generator-drift.d.ts +28 -0
  100. package/dist/gc/generator-drift.js +53 -0
  101. package/dist/gc/generator-drift.js.map +1 -0
  102. package/dist/gc/index.d.ts +42 -0
  103. package/dist/gc/index.js +30 -0
  104. package/dist/gc/index.js.map +1 -0
  105. package/dist/gc/quality-update.d.ts +23 -0
  106. package/dist/gc/quality-update.js +69 -0
  107. package/dist/gc/quality-update.js.map +1 -0
  108. package/dist/gc/scope-coverage.d.ts +20 -0
  109. package/dist/gc/scope-coverage.js +70 -0
  110. package/dist/gc/scope-coverage.js.map +1 -0
  111. package/dist/gc/stub-hits.d.ts +31 -0
  112. package/dist/gc/stub-hits.js +78 -0
  113. package/dist/gc/stub-hits.js.map +1 -0
  114. package/dist/gc/sweep.d.ts +56 -0
  115. package/dist/gc/sweep.js +205 -0
  116. package/dist/gc/sweep.js.map +1 -0
  117. package/dist/gc/types.d.ts +129 -0
  118. package/dist/gc/types.js +26 -0
  119. package/dist/gc/types.js.map +1 -0
  120. package/dist/gc/walk-source.d.ts +14 -0
  121. package/dist/gc/walk-source.js +59 -0
  122. package/dist/gc/walk-source.js.map +1 -0
  123. package/dist/ground/drift.d.ts +8 -0
  124. package/dist/ground/drift.js +23 -0
  125. package/dist/ground/drift.js.map +1 -0
  126. package/dist/ground/frontmatter.d.ts +20 -0
  127. package/dist/ground/frontmatter.js +49 -0
  128. package/dist/ground/frontmatter.js.map +1 -0
  129. package/dist/ground/glob.d.ts +10 -0
  130. package/dist/ground/glob.js +46 -0
  131. package/dist/ground/glob.js.map +1 -0
  132. package/dist/ground/index.d.ts +16 -0
  133. package/dist/ground/index.js +11 -0
  134. package/dist/ground/index.js.map +1 -0
  135. package/dist/ground/ledgers.d.ts +18 -0
  136. package/dist/ground/ledgers.js +103 -0
  137. package/dist/ground/ledgers.js.map +1 -0
  138. package/dist/ground/manifest.d.ts +10 -0
  139. package/dist/ground/manifest.js +88 -0
  140. package/dist/ground/manifest.js.map +1 -0
  141. package/dist/ground/paths.d.ts +20 -0
  142. package/dist/ground/paths.js +61 -0
  143. package/dist/ground/paths.js.map +1 -0
  144. package/dist/ground/quality-grades.d.ts +11 -0
  145. package/dist/ground/quality-grades.js +98 -0
  146. package/dist/ground/quality-grades.js.map +1 -0
  147. package/dist/ground/schemas.d.ts +306 -0
  148. package/dist/ground/schemas.js +188 -0
  149. package/dist/ground/schemas.js.map +1 -0
  150. package/dist/ground/scope-index.d.ts +48 -0
  151. package/dist/ground/scope-index.js +120 -0
  152. package/dist/ground/scope-index.js.map +1 -0
  153. package/dist/ground/walk.d.ts +7 -0
  154. package/dist/ground/walk.js +53 -0
  155. package/dist/ground/walk.js.map +1 -0
  156. package/dist/hooks/bypass-detection.d.ts +28 -0
  157. package/dist/hooks/bypass-detection.js +106 -0
  158. package/dist/hooks/bypass-detection.js.map +1 -0
  159. package/dist/hooks/index.d.ts +12 -0
  160. package/dist/hooks/index.js +13 -0
  161. package/dist/hooks/index.js.map +1 -0
  162. package/dist/hooks/post-tool-use/allowlist-reader.d.ts +14 -0
  163. package/dist/hooks/post-tool-use/allowlist-reader.js +69 -0
  164. package/dist/hooks/post-tool-use/allowlist-reader.js.map +1 -0
  165. package/dist/hooks/post-tool-use/citation-scanner.d.ts +23 -0
  166. package/dist/hooks/post-tool-use/citation-scanner.js +59 -0
  167. package/dist/hooks/post-tool-use/citation-scanner.js.map +1 -0
  168. package/dist/hooks/post-tool-use/copy-scanner.d.ts +25 -0
  169. package/dist/hooks/post-tool-use/copy-scanner.js +192 -0
  170. package/dist/hooks/post-tool-use/copy-scanner.js.map +1 -0
  171. package/dist/hooks/post-tool-use/index.d.ts +19 -0
  172. package/dist/hooks/post-tool-use/index.js +15 -0
  173. package/dist/hooks/post-tool-use/index.js.map +1 -0
  174. package/dist/hooks/post-tool-use/ledger-cache.d.ts +32 -0
  175. package/dist/hooks/post-tool-use/ledger-cache.js +236 -0
  176. package/dist/hooks/post-tool-use/ledger-cache.js.map +1 -0
  177. package/dist/hooks/post-tool-use/legend-builder.d.ts +15 -0
  178. package/dist/hooks/post-tool-use/legend-builder.js +84 -0
  179. package/dist/hooks/post-tool-use/legend-builder.js.map +1 -0
  180. package/dist/hooks/post-tool-use/read-enricher.d.ts +13 -0
  181. package/dist/hooks/post-tool-use/read-enricher.js +157 -0
  182. package/dist/hooks/post-tool-use/read-enricher.js.map +1 -0
  183. package/dist/hooks/post-tool-use/write-guardian.d.ts +17 -0
  184. package/dist/hooks/post-tool-use/write-guardian.js +176 -0
  185. package/dist/hooks/post-tool-use/write-guardian.js.map +1 -0
  186. package/dist/hooks/read-enrich.d.ts +6 -0
  187. package/dist/hooks/read-enrich.js +11 -0
  188. package/dist/hooks/read-enrich.js.map +1 -0
  189. package/dist/hooks/runners/index.d.ts +12 -0
  190. package/dist/hooks/runners/index.js +11 -0
  191. package/dist/hooks/runners/index.js.map +1 -0
  192. package/dist/hooks/runners/payload.d.ts +32 -0
  193. package/dist/hooks/runners/payload.js +70 -0
  194. package/dist/hooks/runners/payload.js.map +1 -0
  195. package/dist/hooks/runners/session-end.d.ts +7 -0
  196. package/dist/hooks/runners/session-end.js +42 -0
  197. package/dist/hooks/runners/session-end.js.map +1 -0
  198. package/dist/hooks/runners/session-start.d.ts +10 -0
  199. package/dist/hooks/runners/session-start.js +167 -0
  200. package/dist/hooks/runners/session-start.js.map +1 -0
  201. package/dist/hooks/runners/stop.d.ts +18 -0
  202. package/dist/hooks/runners/stop.js +165 -0
  203. package/dist/hooks/runners/stop.js.map +1 -0
  204. package/dist/hooks/session-end.d.ts +5 -0
  205. package/dist/hooks/session-end.js +10 -0
  206. package/dist/hooks/session-end.js.map +1 -0
  207. package/dist/hooks/session-start.d.ts +7 -0
  208. package/dist/hooks/session-start.js +12 -0
  209. package/dist/hooks/session-start.js.map +1 -0
  210. package/dist/hooks/stop.d.ts +5 -0
  211. package/dist/hooks/stop.js +10 -0
  212. package/dist/hooks/stop.js.map +1 -0
  213. package/dist/hooks/write-guard.d.ts +6 -0
  214. package/dist/hooks/write-guard.js +11 -0
  215. package/dist/hooks/write-guard.js.map +1 -0
  216. package/dist/inbox.d.ts +17 -0
  217. package/dist/inbox.js +30 -0
  218. package/dist/inbox.js.map +1 -0
  219. package/dist/index.d.ts +33 -0
  220. package/dist/index.js +32 -0
  221. package/dist/index.js.map +1 -0
  222. package/dist/init/baseline-audit.d.ts +71 -0
  223. package/dist/init/baseline-audit.js +377 -0
  224. package/dist/init/baseline-audit.js.map +1 -0
  225. package/dist/init/brand-setup.d.ts +44 -0
  226. package/dist/init/brand-setup.js +201 -0
  227. package/dist/init/brand-setup.js.map +1 -0
  228. package/dist/init/daemon-autostart.d.ts +16 -0
  229. package/dist/init/daemon-autostart.js +95 -0
  230. package/dist/init/daemon-autostart.js.map +1 -0
  231. package/dist/init/detect.d.ts +25 -0
  232. package/dist/init/detect.js +319 -0
  233. package/dist/init/detect.js.map +1 -0
  234. package/dist/init/index.d.ts +32 -0
  235. package/dist/init/index.js +18 -0
  236. package/dist/init/index.js.map +1 -0
  237. package/dist/init/ingest-docs.d.ts +74 -0
  238. package/dist/init/ingest-docs.js +499 -0
  239. package/dist/init/ingest-docs.js.map +1 -0
  240. package/dist/init/init.d.ts +165 -0
  241. package/dist/init/init.js +1166 -0
  242. package/dist/init/init.js.map +1 -0
  243. package/dist/init/mapper-legacy.d.ts +148 -0
  244. package/dist/init/mapper-legacy.js +238 -0
  245. package/dist/init/mapper-legacy.js.map +1 -0
  246. package/dist/init/mapper-merge.d.ts +38 -0
  247. package/dist/init/mapper-merge.js +238 -0
  248. package/dist/init/mapper-merge.js.map +1 -0
  249. package/dist/init/mapper-parallel.d.ts +48 -0
  250. package/dist/init/mapper-parallel.js +409 -0
  251. package/dist/init/mapper-parallel.js.map +1 -0
  252. package/dist/init/mapper-prompts.d.ts +135 -0
  253. package/dist/init/mapper-prompts.js +189 -0
  254. package/dist/init/mapper-prompts.js.map +1 -0
  255. package/dist/init/mapper.d.ts +211 -0
  256. package/dist/init/mapper.js +151 -0
  257. package/dist/init/mapper.js.map +1 -0
  258. package/dist/init/module-slicer.d.ts +39 -0
  259. package/dist/init/module-slicer.js +809 -0
  260. package/dist/init/module-slicer.js.map +1 -0
  261. package/dist/init/multi-dev/index.d.ts +2 -0
  262. package/dist/init/multi-dev/index.js +2 -0
  263. package/dist/init/multi-dev/index.js.map +1 -0
  264. package/dist/init/multi-dev/install.d.ts +40 -0
  265. package/dist/init/multi-dev/install.js +139 -0
  266. package/dist/init/multi-dev/install.js.map +1 -0
  267. package/dist/init/preflight-guards.d.ts +42 -0
  268. package/dist/init/preflight-guards.js +108 -0
  269. package/dist/init/preflight-guards.js.map +1 -0
  270. package/dist/init/prompts.d.ts +61 -0
  271. package/dist/init/prompts.js +66 -0
  272. package/dist/init/prompts.js.map +1 -0
  273. package/dist/init/rules-merge/discover.d.ts +21 -0
  274. package/dist/init/rules-merge/discover.js +78 -0
  275. package/dist/init/rules-merge/discover.js.map +1 -0
  276. package/dist/init/rules-merge/index.d.ts +10 -0
  277. package/dist/init/rules-merge/index.js +6 -0
  278. package/dist/init/rules-merge/index.js.map +1 -0
  279. package/dist/init/rules-merge/ingest.d.ts +56 -0
  280. package/dist/init/rules-merge/ingest.js +336 -0
  281. package/dist/init/rules-merge/ingest.js.map +1 -0
  282. package/dist/init/rules-merge/keep-markers.d.ts +39 -0
  283. package/dist/init/rules-merge/keep-markers.js +97 -0
  284. package/dist/init/rules-merge/keep-markers.js.map +1 -0
  285. package/dist/init/rules-merge/parse-sections.d.ts +24 -0
  286. package/dist/init/rules-merge/parse-sections.js +71 -0
  287. package/dist/init/rules-merge/parse-sections.js.map +1 -0
  288. package/dist/init/rules-merge/regenerate.d.ts +33 -0
  289. package/dist/init/rules-merge/regenerate.js +163 -0
  290. package/dist/init/rules-merge/regenerate.js.map +1 -0
  291. package/dist/init/secrets.d.ts +18 -0
  292. package/dist/init/secrets.js +76 -0
  293. package/dist/init/secrets.js.map +1 -0
  294. package/dist/init/seed.d.ts +21 -0
  295. package/dist/init/seed.js +96 -0
  296. package/dist/init/seed.js.map +1 -0
  297. package/dist/init/setup-runners.d.ts +15 -0
  298. package/dist/init/setup-runners.js +143 -0
  299. package/dist/init/setup-runners.js.map +1 -0
  300. package/dist/init/source-comments/classify.d.ts +98 -0
  301. package/dist/init/source-comments/classify.js +244 -0
  302. package/dist/init/source-comments/classify.js.map +1 -0
  303. package/dist/init/source-comments/index.d.ts +8 -0
  304. package/dist/init/source-comments/index.js +5 -0
  305. package/dist/init/source-comments/index.js.map +1 -0
  306. package/dist/init/source-comments/ingest.d.ts +51 -0
  307. package/dist/init/source-comments/ingest.js +236 -0
  308. package/dist/init/source-comments/ingest.js.map +1 -0
  309. package/dist/init/source-comments/strip-replace.d.ts +106 -0
  310. package/dist/init/source-comments/strip-replace.js +284 -0
  311. package/dist/init/source-comments/strip-replace.js.map +1 -0
  312. package/dist/init/source-comments/walker.d.ts +65 -0
  313. package/dist/init/source-comments/walker.js +777 -0
  314. package/dist/init/source-comments/walker.js.map +1 -0
  315. package/dist/init/submodules.d.ts +48 -0
  316. package/dist/init/submodules.js +149 -0
  317. package/dist/init/submodules.js.map +1 -0
  318. package/dist/init/types.d.ts +55 -0
  319. package/dist/init/types.js +10 -0
  320. package/dist/init/types.js.map +1 -0
  321. package/dist/init/visual.d.ts +69 -0
  322. package/dist/init/visual.js +265 -0
  323. package/dist/init/visual.js.map +1 -0
  324. package/dist/init/walker.d.ts +82 -0
  325. package/dist/init/walker.js +585 -0
  326. package/dist/init/walker.js.map +1 -0
  327. package/dist/init/workflow-block.d.ts +34 -0
  328. package/dist/init/workflow-block.js +110 -0
  329. package/dist/init/workflow-block.js.map +1 -0
  330. package/dist/join/index.d.ts +67 -0
  331. package/dist/join/index.js +256 -0
  332. package/dist/join/index.js.map +1 -0
  333. package/dist/lock.d.ts +39 -0
  334. package/dist/lock.js +129 -0
  335. package/dist/lock.js.map +1 -0
  336. package/dist/logger.d.ts +13 -0
  337. package/dist/logger.js +78 -0
  338. package/dist/logger.js.map +1 -0
  339. package/dist/mcp/bootstrap-guard.d.ts +29 -0
  340. package/dist/mcp/bootstrap-guard.js +47 -0
  341. package/dist/mcp/bootstrap-guard.js.map +1 -0
  342. package/dist/mcp/context.d.ts +23 -0
  343. package/dist/mcp/context.js +9 -0
  344. package/dist/mcp/context.js.map +1 -0
  345. package/dist/mcp/errors.d.ts +17 -0
  346. package/dist/mcp/errors.js +23 -0
  347. package/dist/mcp/errors.js.map +1 -0
  348. package/dist/mcp/history/index.d.ts +6 -0
  349. package/dist/mcp/history/index.js +5 -0
  350. package/dist/mcp/history/index.js.map +1 -0
  351. package/dist/mcp/history/prompt.d.ts +32 -0
  352. package/dist/mcp/history/prompt.js +99 -0
  353. package/dist/mcp/history/prompt.js.map +1 -0
  354. package/dist/mcp/history/schema.d.ts +58 -0
  355. package/dist/mcp/history/schema.js +41 -0
  356. package/dist/mcp/history/schema.js.map +1 -0
  357. package/dist/mcp/history/summarizer.d.ts +81 -0
  358. package/dist/mcp/history/summarizer.js +196 -0
  359. package/dist/mcp/history/summarizer.js.map +1 -0
  360. package/dist/mcp/history/walker.d.ts +57 -0
  361. package/dist/mcp/history/walker.js +156 -0
  362. package/dist/mcp/history/walker.js.map +1 -0
  363. package/dist/mcp/index.d.ts +13 -0
  364. package/dist/mcp/index.js +9 -0
  365. package/dist/mcp/index.js.map +1 -0
  366. package/dist/mcp/path-allowlist.d.ts +29 -0
  367. package/dist/mcp/path-allowlist.js +71 -0
  368. package/dist/mcp/path-allowlist.js.map +1 -0
  369. package/dist/mcp/result.d.ts +8 -0
  370. package/dist/mcp/result.js +18 -0
  371. package/dist/mcp/result.js.map +1 -0
  372. package/dist/mcp/schemas.d.ts +192 -0
  373. package/dist/mcp/schemas.js +174 -0
  374. package/dist/mcp/schemas.js.map +1 -0
  375. package/dist/mcp/serve.d.ts +15 -0
  376. package/dist/mcp/serve.js +71 -0
  377. package/dist/mcp/serve.js.map +1 -0
  378. package/dist/mcp/server.d.ts +11 -0
  379. package/dist/mcp/server.js +58 -0
  380. package/dist/mcp/server.js.map +1 -0
  381. package/dist/mcp/telemetry.d.ts +15 -0
  382. package/dist/mcp/telemetry.js +13 -0
  383. package/dist/mcp/telemetry.js.map +1 -0
  384. package/dist/mcp/tools/append-run-note.d.ts +18 -0
  385. package/dist/mcp/tools/append-run-note.js +47 -0
  386. package/dist/mcp/tools/append-run-note.js.map +1 -0
  387. package/dist/mcp/tools/append.d.ts +8 -0
  388. package/dist/mcp/tools/append.js +37 -0
  389. package/dist/mcp/tools/append.js.map +1 -0
  390. package/dist/mcp/tools/archive.d.ts +8 -0
  391. package/dist/mcp/tools/archive.js +72 -0
  392. package/dist/mcp/tools/archive.js.map +1 -0
  393. package/dist/mcp/tools/ask-operator.d.ts +34 -0
  394. package/dist/mcp/tools/ask-operator.js +97 -0
  395. package/dist/mcp/tools/ask-operator.js.map +1 -0
  396. package/dist/mcp/tools/canonical-for-topic.d.ts +6 -0
  397. package/dist/mcp/tools/canonical-for-topic.js +40 -0
  398. package/dist/mcp/tools/canonical-for-topic.js.map +1 -0
  399. package/dist/mcp/tools/decision-get.d.ts +6 -0
  400. package/dist/mcp/tools/decision-get.js +49 -0
  401. package/dist/mcp/tools/decision-get.js.map +1 -0
  402. package/dist/mcp/tools/decisions-for-symbol.d.ts +7 -0
  403. package/dist/mcp/tools/decisions-for-symbol.js +42 -0
  404. package/dist/mcp/tools/decisions-for-symbol.js.map +1 -0
  405. package/dist/mcp/tools/decisions-in-scope.d.ts +7 -0
  406. package/dist/mcp/tools/decisions-in-scope.js +47 -0
  407. package/dist/mcp/tools/decisions-in-scope.js.map +1 -0
  408. package/dist/mcp/tools/drop-task.d.ts +12 -0
  409. package/dist/mcp/tools/drop-task.js +68 -0
  410. package/dist/mcp/tools/drop-task.js.map +1 -0
  411. package/dist/mcp/tools/get-full.d.ts +7 -0
  412. package/dist/mcp/tools/get-full.js +46 -0
  413. package/dist/mcp/tools/get-full.js.map +1 -0
  414. package/dist/mcp/tools/ground-get.d.ts +7 -0
  415. package/dist/mcp/tools/ground-get.js +77 -0
  416. package/dist/mcp/tools/ground-get.js.map +1 -0
  417. package/dist/mcp/tools/index.d.ts +3 -0
  418. package/dist/mcp/tools/index.js +40 -0
  419. package/dist/mcp/tools/index.js.map +1 -0
  420. package/dist/mcp/tools/invariant-get.d.ts +6 -0
  421. package/dist/mcp/tools/invariant-get.js +49 -0
  422. package/dist/mcp/tools/invariant-get.js.map +1 -0
  423. package/dist/mcp/tools/invariants-in-scope.d.ts +7 -0
  424. package/dist/mcp/tools/invariants-in-scope.js +62 -0
  425. package/dist/mcp/tools/invariants-in-scope.js.map +1 -0
  426. package/dist/mcp/tools/query-history.d.ts +20 -0
  427. package/dist/mcp/tools/query-history.js +51 -0
  428. package/dist/mcp/tools/query-history.js.map +1 -0
  429. package/dist/mcp/tools/record-decision.d.ts +14 -0
  430. package/dist/mcp/tools/record-decision.js +98 -0
  431. package/dist/mcp/tools/record-decision.js.map +1 -0
  432. package/dist/mcp/tools/record-run-event.d.ts +10 -0
  433. package/dist/mcp/tools/record-run-event.js +32 -0
  434. package/dist/mcp/tools/record-run-event.js.map +1 -0
  435. package/dist/mcp/tools/resolve-attention.d.ts +31 -0
  436. package/dist/mcp/tools/resolve-attention.js +191 -0
  437. package/dist/mcp/tools/resolve-attention.js.map +1 -0
  438. package/dist/mcp/tools/search.d.ts +9 -0
  439. package/dist/mcp/tools/search.js +164 -0
  440. package/dist/mcp/tools/search.js.map +1 -0
  441. package/dist/mcp/tools/supersedes-chain.d.ts +6 -0
  442. package/dist/mcp/tools/supersedes-chain.js +66 -0
  443. package/dist/mcp/tools/supersedes-chain.js.map +1 -0
  444. package/dist/mcp/tools/timeline.d.ts +9 -0
  445. package/dist/mcp/tools/timeline.js +65 -0
  446. package/dist/mcp/tools/timeline.js.map +1 -0
  447. package/dist/mcp/tools/types.d.ts +9 -0
  448. package/dist/mcp/tools/types.js +2 -0
  449. package/dist/mcp/tools/types.js.map +1 -0
  450. package/dist/mirror/clone.d.ts +6 -0
  451. package/dist/mirror/clone.js +48 -0
  452. package/dist/mirror/clone.js.map +1 -0
  453. package/dist/mirror/dirty-overlap.d.ts +13 -0
  454. package/dist/mirror/dirty-overlap.js +42 -0
  455. package/dist/mirror/dirty-overlap.js.map +1 -0
  456. package/dist/mirror/index.d.ts +7 -0
  457. package/dist/mirror/index.js +7 -0
  458. package/dist/mirror/index.js.map +1 -0
  459. package/dist/mirror/paths.d.ts +18 -0
  460. package/dist/mirror/paths.js +45 -0
  461. package/dist/mirror/paths.js.map +1 -0
  462. package/dist/mirror/push.d.ts +9 -0
  463. package/dist/mirror/push.js +27 -0
  464. package/dist/mirror/push.js.map +1 -0
  465. package/dist/mirror/state.d.ts +4 -0
  466. package/dist/mirror/state.js +36 -0
  467. package/dist/mirror/state.js.map +1 -0
  468. package/dist/mirror/sync.d.ts +9 -0
  469. package/dist/mirror/sync.js +33 -0
  470. package/dist/mirror/sync.js.map +1 -0
  471. package/dist/mirror/types.d.ts +77 -0
  472. package/dist/mirror/types.js +2 -0
  473. package/dist/mirror/types.js.map +1 -0
  474. package/dist/paths/index.d.ts +23 -0
  475. package/dist/paths/index.js +50 -0
  476. package/dist/paths/index.js.map +1 -0
  477. package/dist/profiles/index.d.ts +3 -0
  478. package/dist/profiles/index.js +3 -0
  479. package/dist/profiles/index.js.map +1 -0
  480. package/dist/profiles/registry.d.ts +5 -0
  481. package/dist/profiles/registry.js +31 -0
  482. package/dist/profiles/registry.js.map +1 -0
  483. package/dist/profiles/types.d.ts +48 -0
  484. package/dist/profiles/types.js +11 -0
  485. package/dist/profiles/types.js.map +1 -0
  486. package/dist/profiles/unknown.d.ts +9 -0
  487. package/dist/profiles/unknown.js +17 -0
  488. package/dist/profiles/unknown.js.map +1 -0
  489. package/dist/prompt.d.ts +19 -0
  490. package/dist/prompt.js +50 -0
  491. package/dist/prompt.js.map +1 -0
  492. package/dist/sensors/attestation.d.ts +44 -0
  493. package/dist/sensors/attestation.js +262 -0
  494. package/dist/sensors/attestation.js.map +1 -0
  495. package/dist/sensors/catalog.d.ts +41 -0
  496. package/dist/sensors/catalog.js +123 -0
  497. package/dist/sensors/catalog.js.map +1 -0
  498. package/dist/sensors/decisions.d.ts +30 -0
  499. package/dist/sensors/decisions.js +393 -0
  500. package/dist/sensors/decisions.js.map +1 -0
  501. package/dist/sensors/diff.d.ts +27 -0
  502. package/dist/sensors/diff.js +148 -0
  503. package/dist/sensors/diff.js.map +1 -0
  504. package/dist/sensors/index.d.ts +13 -0
  505. package/dist/sensors/index.js +9 -0
  506. package/dist/sensors/index.js.map +1 -0
  507. package/dist/sensors/remediation.d.ts +20 -0
  508. package/dist/sensors/remediation.js +65 -0
  509. package/dist/sensors/remediation.js.map +1 -0
  510. package/dist/sensors/runner.d.ts +44 -0
  511. package/dist/sensors/runner.js +95 -0
  512. package/dist/sensors/runner.js.map +1 -0
  513. package/dist/sensors/structural.d.ts +30 -0
  514. package/dist/sensors/structural.js +204 -0
  515. package/dist/sensors/structural.js.map +1 -0
  516. package/dist/sensors/stub-catalog.d.ts +39 -0
  517. package/dist/sensors/stub-catalog.js +115 -0
  518. package/dist/sensors/stub-catalog.js.map +1 -0
  519. package/dist/sensors/types.d.ts +135 -0
  520. package/dist/sensors/types.js +14 -0
  521. package/dist/sensors/types.js.map +1 -0
  522. package/dist/session/events-marker.d.ts +39 -0
  523. package/dist/session/events-marker.js +74 -0
  524. package/dist/session/events-marker.js.map +1 -0
  525. package/dist/session/id.d.ts +83 -0
  526. package/dist/session/id.js +166 -0
  527. package/dist/session/id.js.map +1 -0
  528. package/dist/session/index.d.ts +14 -0
  529. package/dist/session/index.js +13 -0
  530. package/dist/session/index.js.map +1 -0
  531. package/dist/session-start/build.d.ts +53 -0
  532. package/dist/session-start/build.js +645 -0
  533. package/dist/session-start/build.js.map +1 -0
  534. package/dist/session-start/index.d.ts +18 -0
  535. package/dist/session-start/index.js +18 -0
  536. package/dist/session-start/index.js.map +1 -0
  537. package/dist/session-start/templates.d.ts +6 -0
  538. package/dist/session-start/templates.js +38 -0
  539. package/dist/session-start/templates.js.map +1 -0
  540. package/dist/status-line/format.d.ts +14 -0
  541. package/dist/status-line/format.js +40 -0
  542. package/dist/status-line/format.js.map +1 -0
  543. package/dist/status-line/index.d.ts +29 -0
  544. package/dist/status-line/index.js +14 -0
  545. package/dist/status-line/index.js.map +1 -0
  546. package/dist/status-line/reader.d.ts +13 -0
  547. package/dist/status-line/reader.js +76 -0
  548. package/dist/status-line/reader.js.map +1 -0
  549. package/dist/status-line/writer.d.ts +33 -0
  550. package/dist/status-line/writer.js +72 -0
  551. package/dist/status-line/writer.js.map +1 -0
  552. package/dist/tier0/classify.d.ts +10 -0
  553. package/dist/tier0/classify.js +110 -0
  554. package/dist/tier0/classify.js.map +1 -0
  555. package/dist/tier0/index.d.ts +2 -0
  556. package/dist/tier0/index.js +2 -0
  557. package/dist/tier0/index.js.map +1 -0
  558. package/dist/tier0/ollama.d.ts +22 -0
  559. package/dist/tier0/ollama.js +63 -0
  560. package/dist/tier0/ollama.js.map +1 -0
  561. package/dist/tier0/types.d.ts +24 -0
  562. package/dist/tier0/types.js +9 -0
  563. package/dist/tier0/types.js.map +1 -0
  564. package/dist/tightener/index.d.ts +4 -0
  565. package/dist/tightener/index.js +4 -0
  566. package/dist/tightener/index.js.map +1 -0
  567. package/dist/tightener/prompt.d.ts +3 -0
  568. package/dist/tightener/prompt.js +67 -0
  569. package/dist/tightener/prompt.js.map +1 -0
  570. package/dist/tightener/schema.d.ts +68 -0
  571. package/dist/tightener/schema.js +44 -0
  572. package/dist/tightener/schema.js.map +1 -0
  573. package/dist/tightener/tighten.d.ts +2 -0
  574. package/dist/tightener/tighten.js +66 -0
  575. package/dist/tightener/tighten.js.map +1 -0
  576. package/dist/tightener/types.d.ts +74 -0
  577. package/dist/tightener/types.js +6 -0
  578. package/dist/tightener/types.js.map +1 -0
  579. package/dist/voice/index.d.ts +4 -0
  580. package/dist/voice/index.js +4 -0
  581. package/dist/voice/index.js.map +1 -0
  582. package/dist/voice/model.d.ts +23 -0
  583. package/dist/voice/model.js +46 -0
  584. package/dist/voice/model.js.map +1 -0
  585. package/dist/voice/pipe.d.ts +9 -0
  586. package/dist/voice/pipe.js +47 -0
  587. package/dist/voice/pipe.js.map +1 -0
  588. package/dist/voice/transcribe.d.ts +3 -0
  589. package/dist/voice/transcribe.js +43 -0
  590. package/dist/voice/transcribe.js.map +1 -0
  591. package/dist/voice/types.d.ts +26 -0
  592. package/dist/voice/types.js +9 -0
  593. package/dist/voice/types.js.map +1 -0
  594. package/package.json +54 -0
  595. package/templates/.archive/README.md +67 -0
  596. package/templates/.cairn/JOIN.md +87 -0
  597. package/templates/.cairn/config/sensors.yaml +185 -0
  598. package/templates/.cairn/config/stub-patterns.yaml +231 -0
  599. package/templates/.cairn/config/trust-policy.yaml +95 -0
  600. package/templates/.cairn/config/workflow.md +230 -0
  601. package/templates/.cairn/git-hooks/commit-msg +17 -0
  602. package/templates/.cairn/git-hooks/post-commit +28 -0
  603. package/templates/.cairn/git-hooks/pre-commit +24 -0
  604. package/templates/.cairn/ground/brand/overview.md +24 -0
  605. package/templates/.cairn/ground/brand/voice.md +20 -0
  606. package/templates/.cairn/ground/canonical-map/topics.yaml +54 -0
  607. package/templates/.cairn/ground/capabilities/mcp-tools.yaml +4 -0
  608. package/templates/.cairn/ground/capabilities/skills.yaml +3 -0
  609. package/templates/.cairn/ground/capabilities/snippets.yaml +3 -0
  610. package/templates/.cairn/ground/manifest.yaml +16 -0
  611. package/templates/.cairn/ground/product/personas.yaml +4 -0
  612. package/templates/.cairn/ground/product/positioning.md +21 -0
  613. package/templates/.claude/settings.json +57 -0
  614. package/templates/.github/workflows/cairn-check.yml +31 -0
  615. package/templates/.mcp.json +8 -0
  616. package/templates/README.md +24 -0
@@ -0,0 +1,10 @@
1
+ export { discoverRuleSources } from "./discover.js";
2
+ export type { RuleSourceFile } from "./discover.js";
3
+ export { KEEP_END_MARKER, KEEP_START_MARKER, extractKeepBlocks, reapplyKeepBlocks, renderKeepBlock, } from "./keep-markers.js";
4
+ export type { KeepBlock } from "./keep-markers.js";
5
+ export { parseRuleSections } from "./parse-sections.js";
6
+ export type { RuleSection } from "./parse-sections.js";
7
+ export { regenerateRulesFiles } from "./regenerate.js";
8
+ export type { RegenerateRulesArgs, RegenerateRulesResult, } from "./regenerate.js";
9
+ export { runRulesMerge } from "./ingest.js";
10
+ export type { RuleClassKind, RuleClassification, RunRulesMergeArgs, RunRulesMergeResult, } from "./ingest.js";
@@ -0,0 +1,6 @@
1
+ export { discoverRuleSources } from "./discover.js";
2
+ export { KEEP_END_MARKER, KEEP_START_MARKER, extractKeepBlocks, reapplyKeepBlocks, renderKeepBlock, } from "./keep-markers.js";
3
+ export { parseRuleSections } from "./parse-sections.js";
4
+ export { regenerateRulesFiles } from "./regenerate.js";
5
+ export { runRulesMerge } from "./ingest.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/init/rules-merge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAKvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Phase 7c orchestrator — discover + parse + Haiku classify + persist.
3
+ *
4
+ * Ingests CLAUDE.md, AGENTS.md, .claude/CLAUDE.md, and `.claude/rules/**.md`
5
+ * during init. Each H2/H3 section is classified by Haiku as:
6
+ *
7
+ * - "rule-net-new" — section states a rule cairn doesn't have yet (DEC draft to inbox)
8
+ * - "rule-conflict" — section conflicts with existing cairn state (soft-conflict to attention)
9
+ * - "informational" — TOC, history, walkthrough — no action
10
+ * - "operator-keep" — already inside keep-marker block (skipped pre-classification)
11
+ *
12
+ * Net-new rules become DEC drafts in `.cairn/ground/decisions/_inbox/`.
13
+ * Soft conflicts append to `.cairn/baseline/rule-conflicts-<ISO>.yaml`.
14
+ *
15
+ * Resilient: a single Haiku failure marks the section "informational" and
16
+ * continues. All output paths captured in the result so the skill can surface
17
+ * them.
18
+ */
19
+ import type { RuleSourceFile } from "./discover.js";
20
+ import type { RuleSection } from "./parse-sections.js";
21
+ export type RuleClassKind = "rule-net-new" | "rule-conflict" | "informational" | "operator-keep";
22
+ export interface RuleClassification {
23
+ source: string;
24
+ level: 2 | 3 | 0;
25
+ title: string;
26
+ startOffset: number;
27
+ kind: RuleClassKind;
28
+ proposedDecTitle: string;
29
+ proposedRationale: string;
30
+ conflictsWith: string;
31
+ failed: boolean;
32
+ errorMessage?: string;
33
+ }
34
+ export interface RunRulesMergeArgs {
35
+ repoRoot: string;
36
+ /** When set, every section is classified by this fn — bypasses Haiku. */
37
+ mockClassify?: (section: RuleSection, source: RuleSourceFile) => RuleClassification;
38
+ dryRun?: boolean;
39
+ nowIso?: string;
40
+ }
41
+ export interface RunRulesMergeResult {
42
+ sources: RuleSourceFile[];
43
+ sectionsTotal: number;
44
+ classifications: RuleClassification[];
45
+ decDraftsWritten: {
46
+ id: string;
47
+ path: string;
48
+ sourceFile: string;
49
+ }[];
50
+ conflictsRecorded: number;
51
+ conflictsPath: string | null;
52
+ auditPath: string;
53
+ auditRelPath: string;
54
+ kindCounts: Record<RuleClassKind, number>;
55
+ }
56
+ export declare function runRulesMerge(args: RunRulesMergeArgs): Promise<RunRulesMergeResult>;
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Phase 7c orchestrator — discover + parse + Haiku classify + persist.
3
+ *
4
+ * Ingests CLAUDE.md, AGENTS.md, .claude/CLAUDE.md, and `.claude/rules/**.md`
5
+ * during init. Each H2/H3 section is classified by Haiku as:
6
+ *
7
+ * - "rule-net-new" — section states a rule cairn doesn't have yet (DEC draft to inbox)
8
+ * - "rule-conflict" — section conflicts with existing cairn state (soft-conflict to attention)
9
+ * - "informational" — TOC, history, walkthrough — no action
10
+ * - "operator-keep" — already inside keep-marker block (skipped pre-classification)
11
+ *
12
+ * Net-new rules become DEC drafts in `.cairn/ground/decisions/_inbox/`.
13
+ * Soft conflicts append to `.cairn/baseline/rule-conflicts-<ISO>.yaml`.
14
+ *
15
+ * Resilient: a single Haiku failure marks the section "informational" and
16
+ * continues. All output paths captured in the result so the skill can surface
17
+ * them.
18
+ */
19
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
20
+ import { dirname, join } from "node:path";
21
+ import { stringify as stringifyYaml } from "yaml";
22
+ import { runClaude } from "../../claude/index.js";
23
+ import { allocateDecisionId, scanExistingDecisionIds, } from "../../decision-capture/id.js";
24
+ import { decisionsDir } from "../../ground/paths.js";
25
+ import { logger } from "../../logger.js";
26
+ import { discoverRuleSources } from "./discover.js";
27
+ import { parseRuleSections } from "./parse-sections.js";
28
+ const log = logger("init.rules-merge.ingest");
29
+ const PER_SECTION_TIMEOUT_MS = 60_000;
30
+ const SECTION_BODY_CAP = 4_000;
31
+ const CONCURRENCY = 4;
32
+ /* -------------------------------------------------------------------------- */
33
+ /* Schema + prompt */
34
+ /* -------------------------------------------------------------------------- */
35
+ const CLASSIFY_SCHEMA = {
36
+ type: "object",
37
+ additionalProperties: false,
38
+ required: ["kind"],
39
+ properties: {
40
+ kind: {
41
+ type: "string",
42
+ enum: ["rule-net-new", "rule-conflict", "informational", "operator-keep"],
43
+ },
44
+ proposed_dec_title: { type: "string" },
45
+ proposed_rationale: { type: "string" },
46
+ conflicts_with: { type: "string" },
47
+ },
48
+ };
49
+ const CLASSIFY_SYSTEM = `You classify markdown sections of project-rule files for Cairn adoption.
50
+
51
+ Each section comes from one of: CLAUDE.md, AGENTS.md, .claude/CLAUDE.md, or a .claude/rules/*.md file.
52
+
53
+ Return JSON matching the schema. \`kind\` must be exactly one of:
54
+ - "rule-net-new" the section states a binding rule cairn doesn't yet have
55
+ - "rule-conflict" the section contradicts an existing cairn rule (provide conflicts_with id when known)
56
+ - "informational" TOC, walkthrough, history, formatting notes — nothing to ingest
57
+ - "operator-keep" the section is wrapped in keep-markers (rare — caller usually filters first)
58
+
59
+ Optional fields:
60
+ - proposed_dec_title 5-10 word imperative title (only when kind = "rule-net-new")
61
+ - proposed_rationale 2-3 sentence summary (only when kind = "rule-net-new")
62
+ - conflicts_with DEC-NNNN or §V<N> id (only when kind = "rule-conflict")
63
+
64
+ Be conservative. When in doubt, "informational".`;
65
+ /* -------------------------------------------------------------------------- */
66
+ /* Public */
67
+ /* -------------------------------------------------------------------------- */
68
+ export async function runRulesMerge(args) {
69
+ const repoRoot = args.repoRoot;
70
+ const nowIso = args.nowIso ?? new Date().toISOString();
71
+ const tsSlug = nowIso.replace(/[:.]/g, "-").slice(0, 19);
72
+ const sources = discoverRuleSources(repoRoot);
73
+ const allClassifications = [];
74
+ const jobs = [];
75
+ for (const source of sources) {
76
+ let body;
77
+ try {
78
+ body = readFileSync(source.absPath, "utf8");
79
+ }
80
+ catch (err) {
81
+ log.warn({ source: source.path, err: err instanceof Error ? err.message : String(err) }, "rule source unreadable; skipping");
82
+ continue;
83
+ }
84
+ const sections = parseRuleSections(body);
85
+ for (const section of sections) {
86
+ if (section.level === 0)
87
+ continue; // skip preamble
88
+ if (section.protectedByKeepMarker) {
89
+ allClassifications.push({
90
+ source: source.path,
91
+ level: section.level,
92
+ title: section.title,
93
+ startOffset: section.startOffset,
94
+ kind: "operator-keep",
95
+ proposedDecTitle: "",
96
+ proposedRationale: "",
97
+ conflictsWith: "",
98
+ failed: false,
99
+ });
100
+ continue;
101
+ }
102
+ jobs.push({ source, section });
103
+ }
104
+ }
105
+ if (args.mockClassify !== undefined) {
106
+ for (const job of jobs) {
107
+ allClassifications.push(args.mockClassify(job.section, job.source));
108
+ }
109
+ }
110
+ else {
111
+ let cursor = 0;
112
+ const worker = async () => {
113
+ while (cursor < jobs.length) {
114
+ const idx = cursor++;
115
+ const job = jobs[idx];
116
+ if (job === undefined)
117
+ continue;
118
+ const cls = await classifySection(job.source, job.section);
119
+ allClassifications.push(cls);
120
+ }
121
+ };
122
+ const workers = Array.from({ length: Math.min(CONCURRENCY, jobs.length) }, () => worker());
123
+ await Promise.all(workers);
124
+ }
125
+ // Persist DEC drafts + conflicts.
126
+ const decDraftsWritten = [];
127
+ const conflictRows = [];
128
+ const existingIds = scanExistingDecisionIds(repoRoot);
129
+ for (const cls of allClassifications) {
130
+ if (cls.kind === "rule-net-new" && cls.proposedDecTitle.length > 0) {
131
+ const id = allocateDecisionId(repoRoot, existingIds);
132
+ existingIds.add(id);
133
+ if (args.dryRun !== true) {
134
+ const written = writeDecDraft({
135
+ repoRoot,
136
+ id,
137
+ classification: cls,
138
+ generatedAt: nowIso,
139
+ });
140
+ decDraftsWritten.push({ id, path: written.relPath, sourceFile: cls.source });
141
+ }
142
+ else {
143
+ decDraftsWritten.push({
144
+ id,
145
+ path: `.cairn/ground/decisions/_inbox/${id}.draft.md`,
146
+ sourceFile: cls.source,
147
+ });
148
+ }
149
+ }
150
+ if (cls.kind === "rule-conflict") {
151
+ conflictRows.push({
152
+ source_file: cls.source,
153
+ section_title: cls.title,
154
+ section_offset: cls.startOffset,
155
+ conflicts_with: cls.conflictsWith,
156
+ });
157
+ }
158
+ }
159
+ const auditRelPath = `.cairn/baseline/rules-merge-${tsSlug}.yaml`;
160
+ const auditPath = join(repoRoot, auditRelPath);
161
+ let conflictsPath = null;
162
+ const kindCounts = {
163
+ "rule-net-new": 0,
164
+ "rule-conflict": 0,
165
+ informational: 0,
166
+ "operator-keep": 0,
167
+ };
168
+ for (const c of allClassifications) {
169
+ kindCounts[c.kind] = (kindCounts[c.kind] ?? 0) + 1;
170
+ }
171
+ if (args.dryRun !== true) {
172
+ writeYaml(auditPath, {
173
+ run_at: nowIso,
174
+ sources: sources.map((s) => ({ path: s.path, kind: s.kind, size: s.size })),
175
+ sections_total: allClassifications.length,
176
+ kind_counts: kindCounts,
177
+ classifications: allClassifications.map((c) => ({
178
+ source: c.source,
179
+ title: c.title,
180
+ level: c.level,
181
+ kind: c.kind,
182
+ start_offset: c.startOffset,
183
+ proposed_dec_title: c.proposedDecTitle,
184
+ proposed_rationale: c.proposedRationale,
185
+ conflicts_with: c.conflictsWith,
186
+ failed: c.failed,
187
+ ...(c.errorMessage !== undefined ? { error: c.errorMessage } : {}),
188
+ })),
189
+ });
190
+ if (conflictRows.length > 0) {
191
+ const rel = `.cairn/baseline/rule-conflicts-${tsSlug}.yaml`;
192
+ conflictsPath = join(repoRoot, rel);
193
+ writeYaml(conflictsPath, {
194
+ run_at: nowIso,
195
+ conflicts: conflictRows,
196
+ });
197
+ }
198
+ }
199
+ log.info({
200
+ sources: sources.length,
201
+ sections: allClassifications.length,
202
+ kindCounts,
203
+ decDrafts: decDraftsWritten.length,
204
+ conflicts: conflictRows.length,
205
+ }, "rules merge complete");
206
+ return {
207
+ sources,
208
+ sectionsTotal: allClassifications.length,
209
+ classifications: allClassifications,
210
+ decDraftsWritten,
211
+ conflictsRecorded: conflictRows.length,
212
+ conflictsPath,
213
+ auditPath,
214
+ auditRelPath,
215
+ kindCounts,
216
+ };
217
+ }
218
+ /* -------------------------------------------------------------------------- */
219
+ /* Classify single section (Haiku) */
220
+ /* -------------------------------------------------------------------------- */
221
+ async function classifySection(source, section) {
222
+ const body = section.body.length > SECTION_BODY_CAP
223
+ ? `${section.body.slice(0, SECTION_BODY_CAP)}\n…[truncated]`
224
+ : section.body;
225
+ const prompt = [
226
+ `Source: ${source.path}`,
227
+ `Section title: ${section.title || "(preamble)"}`,
228
+ `Heading level: ${section.level}`,
229
+ "",
230
+ "Body:",
231
+ body,
232
+ ].join("\n");
233
+ try {
234
+ const result = await runClaude({
235
+ tier: "haiku",
236
+ system: CLASSIFY_SYSTEM,
237
+ prompt,
238
+ jsonSchema: CLASSIFY_SCHEMA,
239
+ timeoutMs: PER_SECTION_TIMEOUT_MS,
240
+ });
241
+ const parsed = result.parsed;
242
+ if (typeof parsed !== "object" || parsed === null) {
243
+ return informational({
244
+ source: source.path,
245
+ section,
246
+ failed: true,
247
+ errorMessage: "non-object response",
248
+ });
249
+ }
250
+ const r = parsed;
251
+ const kindRaw = r["kind"];
252
+ const kind = kindRaw === "rule-net-new" ||
253
+ kindRaw === "rule-conflict" ||
254
+ kindRaw === "operator-keep"
255
+ ? kindRaw
256
+ : "informational";
257
+ return {
258
+ source: source.path,
259
+ level: section.level,
260
+ title: section.title,
261
+ startOffset: section.startOffset,
262
+ kind,
263
+ proposedDecTitle: typeof r["proposed_dec_title"] === "string" ? r["proposed_dec_title"] : "",
264
+ proposedRationale: typeof r["proposed_rationale"] === "string" ? r["proposed_rationale"] : "",
265
+ conflictsWith: typeof r["conflicts_with"] === "string" ? r["conflicts_with"] : "",
266
+ failed: false,
267
+ };
268
+ }
269
+ catch (err) {
270
+ return informational({
271
+ source: source.path,
272
+ section,
273
+ failed: true,
274
+ errorMessage: err instanceof Error ? err.message : String(err),
275
+ });
276
+ }
277
+ }
278
+ function informational(args) {
279
+ return {
280
+ source: args.source,
281
+ level: args.section.level,
282
+ title: args.section.title,
283
+ startOffset: args.section.startOffset,
284
+ kind: "informational",
285
+ proposedDecTitle: "",
286
+ proposedRationale: "",
287
+ conflictsWith: "",
288
+ failed: args.failed,
289
+ ...(args.errorMessage !== undefined ? { errorMessage: args.errorMessage } : {}),
290
+ };
291
+ }
292
+ function writeDecDraft(args) {
293
+ const dir = decisionsDir(args.repoRoot);
294
+ const inboxDir = join(dir, "_inbox");
295
+ mkdirSync(inboxDir, { recursive: true });
296
+ const filename = `${args.id}.draft.md`;
297
+ const abs = join(inboxDir, filename);
298
+ const rel = `.cairn/ground/decisions/_inbox/${filename}`;
299
+ const fm = {
300
+ id: args.id,
301
+ title: args.classification.proposedDecTitle || `(untitled — from ${args.classification.source})`,
302
+ type: "adr",
303
+ status: "draft-from-rules-merge",
304
+ audience: "dual",
305
+ generated: args.generatedAt,
306
+ "verified-at": args.generatedAt,
307
+ decided_at: args.generatedAt,
308
+ decided_by: "cairn-init",
309
+ capture_source: "init-rules-merge",
310
+ capture_confidence: "medium",
311
+ sourceFile: args.classification.source,
312
+ sectionTitle: args.classification.title,
313
+ };
314
+ const lines = [];
315
+ lines.push("---");
316
+ lines.push(stringifyYaml(fm).trimEnd());
317
+ lines.push("---");
318
+ lines.push("");
319
+ lines.push(`# ${args.id} — ${fm["title"]}`);
320
+ lines.push("");
321
+ lines.push("## Source section");
322
+ lines.push("");
323
+ lines.push(`From \`${args.classification.source}\`, section "${args.classification.title}".`);
324
+ lines.push("");
325
+ lines.push("## Proposed rationale");
326
+ lines.push("");
327
+ lines.push(args.classification.proposedRationale);
328
+ lines.push("");
329
+ writeFileSync(abs, lines.join("\n"), "utf8");
330
+ return { absPath: abs, relPath: rel };
331
+ }
332
+ function writeYaml(path, payload) {
333
+ mkdirSync(dirname(path), { recursive: true });
334
+ writeFileSync(path, stringifyYaml(payload), "utf8");
335
+ }
336
+ //# sourceMappingURL=ingest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest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CAAC;IACf,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,CAAW,EAAE,CAAC,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAChC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,cAAc,CAAC,MAAM,gBAAgB,IAAI,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC,CAAC;IAC9F,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACpC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAClD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,OAAgB;IAC/C,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Phase 7c — operator keep-section preservation.
3
+ *
4
+ * After adoption, cairn regenerates CLAUDE.md / AGENTS.md from ground state
5
+ * on each sweep. Operator-written sections survive only when wrapped in a pair
6
+ * of HTML comment markers:
7
+ *
8
+ * <!-- cairn:keep-start -->
9
+ * ... operator content (preserved verbatim) ...
10
+ * <!-- cairn:keep-end -->
11
+ *
12
+ * These helpers parse + render those blocks.
13
+ */
14
+ export declare const KEEP_START_MARKER = "<!-- cairn:keep-start -->";
15
+ export declare const KEEP_END_MARKER = "<!-- cairn:keep-end -->";
16
+ export interface KeepBlock {
17
+ /** Optional operator label after the start marker (e.g. `:custom-flow`). */
18
+ label: string;
19
+ /** Body between the markers (markers excluded). */
20
+ body: string;
21
+ /** Byte offset in the source file where the block starts. */
22
+ startOffset: number;
23
+ /** Byte offset where the block (incl. closing marker) ends. */
24
+ endOffset: number;
25
+ }
26
+ export declare function extractKeepBlocks(source: string): KeepBlock[];
27
+ /**
28
+ * Wraps `body` with the keep markers. Adds an optional label.
29
+ */
30
+ export declare function renderKeepBlock(body: string, label?: string): string;
31
+ /**
32
+ * Replace any cairn-rendered region of `existing` with `regenerated`, while
33
+ * preserving every keep-block from `existing` at its original logical anchor:
34
+ * the regenerator inserts a placeholder marker `<!-- cairn:keep-anchor:N -->`
35
+ * for each keep block; this helper substitutes those anchors back to the real
36
+ * keep blocks. If a keep block has no matching anchor it is appended at the
37
+ * end of the file under a "## Operator-preserved sections" heading.
38
+ */
39
+ export declare function reapplyKeepBlocks(regenerated: string, keepBlocks: KeepBlock[]): string;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Phase 7c — operator keep-section preservation.
3
+ *
4
+ * After adoption, cairn regenerates CLAUDE.md / AGENTS.md from ground state
5
+ * on each sweep. Operator-written sections survive only when wrapped in a pair
6
+ * of HTML comment markers:
7
+ *
8
+ * <!-- cairn:keep-start -->
9
+ * ... operator content (preserved verbatim) ...
10
+ * <!-- cairn:keep-end -->
11
+ *
12
+ * These helpers parse + render those blocks.
13
+ */
14
+ export const KEEP_START_MARKER = "<!-- cairn:keep-start -->";
15
+ export const KEEP_END_MARKER = "<!-- cairn:keep-end -->";
16
+ const START_RE = /<!--\s*cairn:keep-start(?::([^\s]+))?\s*-->/g;
17
+ const END_TOKEN = "<!-- cairn:keep-end -->";
18
+ export function extractKeepBlocks(source) {
19
+ const blocks = [];
20
+ let match;
21
+ START_RE.lastIndex = 0;
22
+ while ((match = START_RE.exec(source)) !== null) {
23
+ const startOffset = match.index;
24
+ const afterStart = match.index + match[0].length;
25
+ // Find a matching end. We look for the literal token to keep parsing tight.
26
+ const endIdx = source.indexOf(END_TOKEN, afterStart);
27
+ if (endIdx === -1)
28
+ break;
29
+ const endOffset = endIdx + END_TOKEN.length;
30
+ let body = source.slice(afterStart, endIdx);
31
+ body = body.replace(/^\n/, "").replace(/\n$/, "");
32
+ blocks.push({
33
+ label: match[1] ?? "",
34
+ body,
35
+ startOffset,
36
+ endOffset,
37
+ });
38
+ START_RE.lastIndex = endOffset;
39
+ }
40
+ return blocks;
41
+ }
42
+ /**
43
+ * Wraps `body` with the keep markers. Adds an optional label.
44
+ */
45
+ export function renderKeepBlock(body, label) {
46
+ const labelPart = label && label.length > 0 ? `:${label}` : "";
47
+ return [
48
+ `<!-- cairn:keep-start${labelPart} -->`,
49
+ body,
50
+ KEEP_END_MARKER,
51
+ ].join("\n");
52
+ }
53
+ /**
54
+ * Replace any cairn-rendered region of `existing` with `regenerated`, while
55
+ * preserving every keep-block from `existing` at its original logical anchor:
56
+ * the regenerator inserts a placeholder marker `<!-- cairn:keep-anchor:N -->`
57
+ * for each keep block; this helper substitutes those anchors back to the real
58
+ * keep blocks. If a keep block has no matching anchor it is appended at the
59
+ * end of the file under a "## Operator-preserved sections" heading.
60
+ */
61
+ export function reapplyKeepBlocks(regenerated, keepBlocks) {
62
+ if (keepBlocks.length === 0)
63
+ return regenerated;
64
+ let out = regenerated;
65
+ const consumed = new Set();
66
+ for (let i = 0; i < keepBlocks.length; i++) {
67
+ const block = keepBlocks[i];
68
+ if (block === undefined)
69
+ continue;
70
+ const anchor = `<!-- cairn:keep-anchor:${i} -->`;
71
+ if (out.includes(anchor)) {
72
+ out = out.replace(anchor, renderKeepBlock(block.body, block.label));
73
+ consumed.add(i);
74
+ }
75
+ }
76
+ const orphans = keepBlocks
77
+ .map((b, idx) => ({ b, idx }))
78
+ .filter(({ idx, b }) => !consumed.has(idx) && b !== undefined);
79
+ if (orphans.length === 0)
80
+ return out;
81
+ const trailer = [
82
+ "",
83
+ "<!-- cairn:appendix-start -->",
84
+ "## Operator-preserved sections",
85
+ "",
86
+ ];
87
+ for (const o of orphans) {
88
+ if (o.b === undefined)
89
+ continue;
90
+ trailer.push(renderKeepBlock(o.b.body, o.b.label));
91
+ trailer.push("");
92
+ }
93
+ trailer.push("<!-- cairn:appendix-end -->");
94
+ trailer.push("");
95
+ return `${out.trimEnd()}\n${trailer.join("\n")}`;
96
+ }
97
+ //# sourceMappingURL=keep-markers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keep-markers.js","sourceRoot":"","sources":["../../../src/init/rules-merge/keep-markers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAC;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,yBAAyB,CAAC;AAazD,MAAM,QAAQ,GAAG,8CAA8C,CAAC;AAChE,MAAM,SAAS,GAAG,yBAAyB,CAAC;AAE5C,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,IAAI,KAA6B,CAAC;IAClC,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC;QAChC,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACjD,4EAA4E;QAC5E,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,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C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Markdown section splitter for rules-merge.
3
+ *
4
+ * Splits a markdown body into H2/H3-headed sections. Each section keeps the
5
+ * original heading line + body until the next heading at the same or lower
6
+ * level. Front-matter (everything before the first heading) is returned as a
7
+ * synthetic section with `level: 0` and `title: ""`.
8
+ *
9
+ * Operator-preserved blocks (between `<!-- cairn:keep-start -->` and
10
+ * `<!-- cairn:keep-end -->`) are tagged so the classifier can skip them.
11
+ */
12
+ export interface RuleSection {
13
+ /** 0 = preamble, 2 = H2, 3 = H3 (we ignore deeper levels — too granular). */
14
+ level: 0 | 2 | 3;
15
+ /** Heading text without leading hashes. Empty for the preamble. */
16
+ title: string;
17
+ /** Body markdown including the heading line itself. */
18
+ body: string;
19
+ /** Byte offset of section start in the original file. */
20
+ startOffset: number;
21
+ /** True when section overlaps a keep-block. */
22
+ protectedByKeepMarker: boolean;
23
+ }
24
+ export declare function parseRuleSections(source: string): RuleSection[];