@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,777 @@
1
+ /**
2
+ * Phase 7b — deterministic source-comment walker.
3
+ *
4
+ * Walks every source file in the repo (via `git ls-files` when available, else
5
+ * a manual recursive walk respecting a hardcoded ignore list) and extracts
6
+ * essay-style comment blocks per language. Detection is deterministic — no
7
+ * LLM. The output feeds the Haiku batch classifier (`classify.ts`).
8
+ *
9
+ * "Essay-style" heuristic per spec §15:
10
+ * - block comment > 3 lines, OR
11
+ * - block comment > 200 chars, OR
12
+ * - JSDoc with > 30 words of prose (after stripping @tags + symbols).
13
+ *
14
+ * License headers are detected separately and exported with `kind: "license"`
15
+ * — the classifier passes them through; the strip-replace stage leaves them
16
+ * in source untouched.
17
+ */
18
+ import { execFileSync } from "node:child_process";
19
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
20
+ import { extname, join, relative } from "node:path";
21
+ const SOURCE_EXTENSIONS = new Set([
22
+ ".ts",
23
+ ".tsx",
24
+ ".js",
25
+ ".jsx",
26
+ ".mjs",
27
+ ".cjs",
28
+ ".py",
29
+ ".rs",
30
+ ".go",
31
+ ".java",
32
+ ".kt",
33
+ ".kts",
34
+ ".swift",
35
+ ".scala",
36
+ ".c",
37
+ ".cc",
38
+ ".cpp",
39
+ ".cxx",
40
+ ".h",
41
+ ".hpp",
42
+ ".cs",
43
+ ".rb",
44
+ ".sh",
45
+ ".bash",
46
+ ".zsh",
47
+ ".php",
48
+ ".lua",
49
+ ".dart",
50
+ ]);
51
+ const SKIP_DIRS = new Set([
52
+ ".git",
53
+ "node_modules",
54
+ "dist",
55
+ "build",
56
+ "target",
57
+ "out",
58
+ "__pycache__",
59
+ "vendor",
60
+ ".venv",
61
+ ".direnv",
62
+ ".cache",
63
+ "coverage",
64
+ ".next",
65
+ ".turbo",
66
+ ".nuxt",
67
+ ".svelte-kit",
68
+ ".astro",
69
+ ".parcel-cache",
70
+ ".vercel",
71
+ ".netlify",
72
+ ".pytest_cache",
73
+ ".mypy_cache",
74
+ ".ruff_cache",
75
+ ".tox",
76
+ ".gradle",
77
+ ".idea",
78
+ ".vscode",
79
+ ".cairn",
80
+ ".archive",
81
+ ]);
82
+ /** Lower bound: only consider blocks above one of these. */
83
+ const MIN_LINES = 4;
84
+ const MIN_CHARS = 200;
85
+ const MIN_JSDOC_WORDS = 30;
86
+ /* -------------------------------------------------------------------------- */
87
+ /* Public API */
88
+ /* -------------------------------------------------------------------------- */
89
+ export function walkSourceComments(opts) {
90
+ const repoRoot = opts.repoRoot;
91
+ const files = opts.onlyFiles ?? listSourceFiles(repoRoot, opts.fileCap);
92
+ const blocks = [];
93
+ const fileCountByLang = {};
94
+ let bytesScanned = 0;
95
+ for (const rel of files) {
96
+ const lang = detectLang(rel);
97
+ if (lang === "unknown")
98
+ continue;
99
+ fileCountByLang[lang] = (fileCountByLang[lang] ?? 0) + 1;
100
+ const abs = join(repoRoot, rel);
101
+ let body;
102
+ try {
103
+ body = readFileSync(abs, "utf8");
104
+ }
105
+ catch {
106
+ continue;
107
+ }
108
+ bytesScanned += body.length;
109
+ const fileBlocks = extractFileBlocks(rel, lang, body);
110
+ for (const b of fileBlocks)
111
+ blocks.push(b);
112
+ }
113
+ return { files, blocks, fileCountByLang, bytesScanned };
114
+ }
115
+ /* -------------------------------------------------------------------------- */
116
+ /* File discovery */
117
+ /* -------------------------------------------------------------------------- */
118
+ function listSourceFiles(repoRoot, fileCap) {
119
+ const fromGit = listFromGit(repoRoot);
120
+ const list = fromGit ?? listFromFs(repoRoot);
121
+ const filtered = list.filter((p) => SOURCE_EXTENSIONS.has(extname(p).toLowerCase()));
122
+ if (fileCap !== undefined && filtered.length > fileCap) {
123
+ return filtered.slice(0, fileCap);
124
+ }
125
+ return filtered;
126
+ }
127
+ function listFromGit(repoRoot) {
128
+ try {
129
+ const out = execFileSync("git", ["ls-files", "--cached", "--others", "--exclude-standard", "-z"], {
130
+ cwd: repoRoot,
131
+ encoding: "utf8",
132
+ maxBuffer: 64 * 1024 * 1024,
133
+ stdio: ["ignore", "pipe", "ignore"],
134
+ });
135
+ const parts = out.split("\0").filter((s) => s.length > 0);
136
+ return parts.filter((p) => !pathInSkipDir(p));
137
+ }
138
+ catch {
139
+ return null;
140
+ }
141
+ }
142
+ function listFromFs(repoRoot) {
143
+ const out = [];
144
+ walkFs(repoRoot, repoRoot, out);
145
+ return out;
146
+ }
147
+ function walkFs(repoRoot, dir, out) {
148
+ let entries;
149
+ try {
150
+ entries = readdirSync(dir, { withFileTypes: true, encoding: "utf8" });
151
+ }
152
+ catch {
153
+ return;
154
+ }
155
+ for (const e of entries) {
156
+ if (e.name.startsWith(".") && SKIP_DIRS.has(e.name))
157
+ continue;
158
+ if (SKIP_DIRS.has(e.name))
159
+ continue;
160
+ const abs = join(dir, e.name);
161
+ if (e.isDirectory()) {
162
+ walkFs(repoRoot, abs, out);
163
+ continue;
164
+ }
165
+ if (!e.isFile())
166
+ continue;
167
+ out.push(toPosix(relative(repoRoot, abs)));
168
+ }
169
+ }
170
+ function pathInSkipDir(rel) {
171
+ const segs = rel.split(/[\\/]/);
172
+ for (const s of segs)
173
+ if (SKIP_DIRS.has(s))
174
+ return true;
175
+ return false;
176
+ }
177
+ function toPosix(p) {
178
+ return p.replace(/\\/g, "/");
179
+ }
180
+ /* -------------------------------------------------------------------------- */
181
+ /* Lang detection */
182
+ /* -------------------------------------------------------------------------- */
183
+ export function detectLang(file) {
184
+ const ext = extname(file).toLowerCase();
185
+ switch (ext) {
186
+ case ".ts":
187
+ case ".tsx":
188
+ case ".js":
189
+ case ".jsx":
190
+ case ".mjs":
191
+ case ".cjs":
192
+ return "js";
193
+ case ".py":
194
+ return "py";
195
+ case ".rs":
196
+ return "rs";
197
+ case ".go":
198
+ return "go";
199
+ case ".java":
200
+ return "java";
201
+ case ".kt":
202
+ case ".kts":
203
+ return "kt";
204
+ case ".swift":
205
+ return "swift";
206
+ case ".scala":
207
+ return "scala";
208
+ case ".c":
209
+ case ".cc":
210
+ case ".cpp":
211
+ case ".cxx":
212
+ case ".h":
213
+ case ".hpp":
214
+ return "c";
215
+ case ".cs":
216
+ return "cs";
217
+ case ".rb":
218
+ return "rb";
219
+ case ".sh":
220
+ case ".bash":
221
+ case ".zsh":
222
+ return "sh";
223
+ case ".php":
224
+ return "php";
225
+ case ".lua":
226
+ return "lua";
227
+ case ".dart":
228
+ return "dart";
229
+ default:
230
+ return "unknown";
231
+ }
232
+ }
233
+ /* -------------------------------------------------------------------------- */
234
+ /* Per-file extraction */
235
+ /* -------------------------------------------------------------------------- */
236
+ function extractFileBlocks(file, lang, body) {
237
+ switch (lang) {
238
+ case "js":
239
+ case "java":
240
+ case "c":
241
+ case "cs":
242
+ case "kt":
243
+ case "swift":
244
+ case "scala":
245
+ case "php":
246
+ case "dart":
247
+ return extractCStyle(file, lang, body);
248
+ case "rs":
249
+ return extractRust(file, body);
250
+ case "go":
251
+ return extractGo(file, body);
252
+ case "py":
253
+ return extractPython(file, body);
254
+ case "rb":
255
+ return extractRuby(file, body);
256
+ case "sh":
257
+ case "lua":
258
+ return extractHashCluster(file, lang, body);
259
+ default:
260
+ return [];
261
+ }
262
+ }
263
+ /* C-style: /* … *\/, /** … *\/ (JSDoc), and clusters of // (3+ lines). */
264
+ function extractCStyle(file, lang, body) {
265
+ const blocks = [];
266
+ const lineStarts = computeLineStarts(body);
267
+ const len = body.length;
268
+ let i = 0;
269
+ while (i < len) {
270
+ if (body[i] === "/" && body[i + 1] === "*") {
271
+ const isJsDoc = body[i + 2] === "*" && body[i + 3] !== "/";
272
+ const end = body.indexOf("*/", i + 2);
273
+ if (end === -1)
274
+ break;
275
+ const startOffset = i;
276
+ const endOffset = end + 2;
277
+ const raw = body.slice(startOffset, endOffset);
278
+ const startLine = offsetToLine(lineStarts, startOffset);
279
+ const endLine = offsetToLine(lineStarts, endOffset - 1);
280
+ const block = makeBlock({
281
+ file,
282
+ lang,
283
+ kind: isJsDoc ? "jsdoc" : "block",
284
+ raw,
285
+ startLine,
286
+ endLine,
287
+ startOffset,
288
+ endOffset,
289
+ prose: stripCStyleProse(raw, isJsDoc),
290
+ });
291
+ const license = isLicense(block);
292
+ if (license)
293
+ block.kind = "license";
294
+ if (passesHeuristic(block))
295
+ blocks.push(block);
296
+ i = endOffset;
297
+ continue;
298
+ }
299
+ if (body[i] === "/" && body[i + 1] === "/" && !inString(body, i)) {
300
+ const cluster = readLineCluster(body, lineStarts, i, "//");
301
+ if (cluster !== null) {
302
+ const block = makeBlock({
303
+ file,
304
+ lang,
305
+ kind: "line-cluster",
306
+ raw: cluster.raw,
307
+ startLine: cluster.startLine,
308
+ endLine: cluster.endLine,
309
+ startOffset: cluster.startOffset,
310
+ endOffset: cluster.endOffset,
311
+ prose: stripLineClusterProse(cluster.raw, "//"),
312
+ });
313
+ if (isLicense(block))
314
+ block.kind = "license";
315
+ if (passesHeuristic(block))
316
+ blocks.push(block);
317
+ i = cluster.endOffset;
318
+ continue;
319
+ }
320
+ }
321
+ if (body[i] === '"' || body[i] === "'" || body[i] === "`") {
322
+ i = skipString(body, i);
323
+ continue;
324
+ }
325
+ i += 1;
326
+ }
327
+ return blocks;
328
+ }
329
+ function extractGo(file, body) {
330
+ return extractCStyle(file, "go", body);
331
+ }
332
+ function extractRust(file, body) {
333
+ // Rust: ///, //!, /** */, /*! */ are doc-style. Treat /// + //! clusters as JSDoc-equiv.
334
+ const blocks = [];
335
+ const lineStarts = computeLineStarts(body);
336
+ const len = body.length;
337
+ let i = 0;
338
+ while (i < len) {
339
+ if (body[i] === "/" && body[i + 1] === "*") {
340
+ const end = body.indexOf("*/", i + 2);
341
+ if (end === -1)
342
+ break;
343
+ const startOffset = i;
344
+ const endOffset = end + 2;
345
+ const raw = body.slice(startOffset, endOffset);
346
+ const startLine = offsetToLine(lineStarts, startOffset);
347
+ const endLine = offsetToLine(lineStarts, endOffset - 1);
348
+ const isDoc = body[i + 2] === "*" || body[i + 2] === "!";
349
+ const block = makeBlock({
350
+ file,
351
+ lang: "rs",
352
+ kind: isDoc ? "jsdoc" : "block",
353
+ raw,
354
+ startLine,
355
+ endLine,
356
+ startOffset,
357
+ endOffset,
358
+ prose: stripCStyleProse(raw, isDoc),
359
+ });
360
+ if (isLicense(block))
361
+ block.kind = "license";
362
+ if (passesHeuristic(block))
363
+ blocks.push(block);
364
+ i = endOffset;
365
+ continue;
366
+ }
367
+ if (body[i] === "/" && body[i + 1] === "/" && !inString(body, i)) {
368
+ // Detect /// or //! prefix for doc-cluster
369
+ const isDoc = body[i + 2] === "/" || body[i + 2] === "!";
370
+ const marker = isDoc ? (body[i + 2] === "/" ? "///" : "//!") : "//";
371
+ const cluster = readLineCluster(body, lineStarts, i, marker);
372
+ if (cluster !== null) {
373
+ const block = makeBlock({
374
+ file,
375
+ lang: "rs",
376
+ kind: isDoc ? "jsdoc" : "line-cluster",
377
+ raw: cluster.raw,
378
+ startLine: cluster.startLine,
379
+ endLine: cluster.endLine,
380
+ startOffset: cluster.startOffset,
381
+ endOffset: cluster.endOffset,
382
+ prose: stripLineClusterProse(cluster.raw, marker),
383
+ });
384
+ if (isLicense(block))
385
+ block.kind = "license";
386
+ if (passesHeuristic(block))
387
+ blocks.push(block);
388
+ i = cluster.endOffset;
389
+ continue;
390
+ }
391
+ }
392
+ if (body[i] === '"') {
393
+ i = skipString(body, i);
394
+ continue;
395
+ }
396
+ i += 1;
397
+ }
398
+ return blocks;
399
+ }
400
+ function extractPython(file, body) {
401
+ const blocks = [];
402
+ const lineStarts = computeLineStarts(body);
403
+ const len = body.length;
404
+ let i = 0;
405
+ while (i < len) {
406
+ // Triple-quoted strings used as docstrings. We treat any """…""" or '''…'''
407
+ // anywhere as a candidate. Real Python docstrings only count when at module
408
+ // start or right after `def`/`class`, but for adoption purposes we capture
409
+ // every triple-string to maximize prose surface; the classifier filters.
410
+ if ((body[i] === '"' && body[i + 1] === '"' && body[i + 2] === '"') ||
411
+ (body[i] === "'" && body[i + 1] === "'" && body[i + 2] === "'")) {
412
+ const quote = body.slice(i, i + 3);
413
+ const end = body.indexOf(quote, i + 3);
414
+ if (end === -1)
415
+ break;
416
+ const startOffset = i;
417
+ const endOffset = end + 3;
418
+ const raw = body.slice(startOffset, endOffset);
419
+ const startLine = offsetToLine(lineStarts, startOffset);
420
+ const endLine = offsetToLine(lineStarts, endOffset - 1);
421
+ const block = makeBlock({
422
+ file,
423
+ lang: "py",
424
+ kind: "block",
425
+ raw,
426
+ startLine,
427
+ endLine,
428
+ startOffset,
429
+ endOffset,
430
+ prose: stripPyDocstringProse(raw),
431
+ });
432
+ if (isLicense(block))
433
+ block.kind = "license";
434
+ if (passesHeuristic(block))
435
+ blocks.push(block);
436
+ i = endOffset;
437
+ continue;
438
+ }
439
+ if (body[i] === "#") {
440
+ const cluster = readLineCluster(body, lineStarts, i, "#");
441
+ if (cluster !== null) {
442
+ const block = makeBlock({
443
+ file,
444
+ lang: "py",
445
+ kind: "line-cluster",
446
+ raw: cluster.raw,
447
+ startLine: cluster.startLine,
448
+ endLine: cluster.endLine,
449
+ startOffset: cluster.startOffset,
450
+ endOffset: cluster.endOffset,
451
+ prose: stripLineClusterProse(cluster.raw, "#"),
452
+ });
453
+ if (isLicense(block))
454
+ block.kind = "license";
455
+ if (passesHeuristic(block))
456
+ blocks.push(block);
457
+ i = cluster.endOffset;
458
+ continue;
459
+ }
460
+ }
461
+ i += 1;
462
+ }
463
+ return blocks;
464
+ }
465
+ function extractRuby(file, body) {
466
+ const blocks = [];
467
+ const lineStarts = computeLineStarts(body);
468
+ const len = body.length;
469
+ let i = 0;
470
+ while (i < len) {
471
+ // =begin … =end heredoc-style block at line start
472
+ if (atLineStart(body, i) && body.startsWith("=begin", i)) {
473
+ const end = body.indexOf("\n=end", i);
474
+ if (end === -1)
475
+ break;
476
+ const closeNl = body.indexOf("\n", end + 5);
477
+ const endOffset = closeNl === -1 ? body.length : closeNl;
478
+ const startOffset = i;
479
+ const raw = body.slice(startOffset, endOffset);
480
+ const startLine = offsetToLine(lineStarts, startOffset);
481
+ const endLine = offsetToLine(lineStarts, endOffset - 1);
482
+ const block = makeBlock({
483
+ file,
484
+ lang: "rb",
485
+ kind: "block",
486
+ raw,
487
+ startLine,
488
+ endLine,
489
+ startOffset,
490
+ endOffset,
491
+ prose: raw.replace(/^=begin.*$|^=end.*$/gm, "").trim(),
492
+ });
493
+ if (isLicense(block))
494
+ block.kind = "license";
495
+ if (passesHeuristic(block))
496
+ blocks.push(block);
497
+ i = endOffset;
498
+ continue;
499
+ }
500
+ if (body[i] === "#") {
501
+ const cluster = readLineCluster(body, lineStarts, i, "#");
502
+ if (cluster !== null) {
503
+ const block = makeBlock({
504
+ file,
505
+ lang: "rb",
506
+ kind: "line-cluster",
507
+ raw: cluster.raw,
508
+ startLine: cluster.startLine,
509
+ endLine: cluster.endLine,
510
+ startOffset: cluster.startOffset,
511
+ endOffset: cluster.endOffset,
512
+ prose: stripLineClusterProse(cluster.raw, "#"),
513
+ });
514
+ if (isLicense(block))
515
+ block.kind = "license";
516
+ if (passesHeuristic(block))
517
+ blocks.push(block);
518
+ i = cluster.endOffset;
519
+ continue;
520
+ }
521
+ }
522
+ i += 1;
523
+ }
524
+ return blocks;
525
+ }
526
+ function extractHashCluster(file, lang, body) {
527
+ const blocks = [];
528
+ const lineStarts = computeLineStarts(body);
529
+ const len = body.length;
530
+ let i = 0;
531
+ while (i < len) {
532
+ if (body[i] === "#" && (i === 0 || body[i - 1] === "\n")) {
533
+ // shebang line — skip if first line and starts with #!
534
+ if (i === 0 && body[i + 1] === "!") {
535
+ const nl = body.indexOf("\n", i);
536
+ if (nl === -1)
537
+ break;
538
+ i = nl + 1;
539
+ continue;
540
+ }
541
+ const cluster = readLineCluster(body, lineStarts, i, "#");
542
+ if (cluster !== null) {
543
+ const block = makeBlock({
544
+ file,
545
+ lang,
546
+ kind: "line-cluster",
547
+ raw: cluster.raw,
548
+ startLine: cluster.startLine,
549
+ endLine: cluster.endLine,
550
+ startOffset: cluster.startOffset,
551
+ endOffset: cluster.endOffset,
552
+ prose: stripLineClusterProse(cluster.raw, "#"),
553
+ });
554
+ if (isLicense(block))
555
+ block.kind = "license";
556
+ if (passesHeuristic(block))
557
+ blocks.push(block);
558
+ i = cluster.endOffset;
559
+ continue;
560
+ }
561
+ }
562
+ i += 1;
563
+ }
564
+ return blocks;
565
+ }
566
+ function makeBlock(a) {
567
+ const lineCount = a.endLine - a.startLine + 1;
568
+ const charCount = a.raw.length;
569
+ const wordCount = countWords(a.prose);
570
+ return {
571
+ id: `${a.file}:${a.startLine}-${a.endLine}`,
572
+ file: a.file,
573
+ lang: a.lang,
574
+ kind: a.kind,
575
+ startLine: a.startLine,
576
+ endLine: a.endLine,
577
+ raw: a.raw,
578
+ prose: a.prose,
579
+ lineCount,
580
+ charCount,
581
+ wordCount,
582
+ startOffset: a.startOffset,
583
+ endOffset: a.endOffset,
584
+ };
585
+ }
586
+ function passesHeuristic(b) {
587
+ if (b.kind === "license")
588
+ return true; // capture, just don't strip
589
+ if (b.kind === "jsdoc") {
590
+ if (b.wordCount > MIN_JSDOC_WORDS)
591
+ return true;
592
+ return b.lineCount >= MIN_LINES || b.charCount > MIN_CHARS;
593
+ }
594
+ return b.lineCount >= MIN_LINES || b.charCount > MIN_CHARS;
595
+ }
596
+ function isLicense(b) {
597
+ // Only check the first 1000 chars for typical license markers.
598
+ const head = b.raw.slice(0, 1000);
599
+ return (/\bcopyright\b/i.test(head) ||
600
+ /\bSPDX-License-Identifier\b/.test(head) ||
601
+ /\bAll rights reserved\b/i.test(head) ||
602
+ /\bLicensed under\b/i.test(head));
603
+ }
604
+ function stripCStyleProse(raw, isJsDoc) {
605
+ // Strip /* */ and leading * per line; if JSDoc, drop @tag blocks.
606
+ let s = raw.replace(/^\/\*+!?/, "").replace(/\*+\/$/, "");
607
+ s = s
608
+ .split("\n")
609
+ .map((line) => line.replace(/^\s*\*+\s?/, ""))
610
+ .join("\n");
611
+ if (isJsDoc) {
612
+ // drop @tag lines (e.g. @param, @returns, @throws, @example)
613
+ s = s
614
+ .split("\n")
615
+ .filter((line) => !/^\s*@\w+/.test(line))
616
+ .join("\n");
617
+ }
618
+ return s.trim();
619
+ }
620
+ function stripLineClusterProse(raw, marker) {
621
+ // marker: //, ///, //!, #
622
+ const escaped = marker.replace(/[/]/g, "\\/");
623
+ const re = new RegExp(`^\\s*${escaped}\\s?`, "gm");
624
+ return raw.replace(re, "").trim();
625
+ }
626
+ function stripPyDocstringProse(raw) {
627
+ // strip leading + trailing triple quotes
628
+ let s = raw;
629
+ const q = s.slice(0, 3);
630
+ if (q === '"""' || q === "'''")
631
+ s = s.slice(3);
632
+ if (s.endsWith('"""') || s.endsWith("'''"))
633
+ s = s.slice(0, -3);
634
+ return s.trim();
635
+ }
636
+ function countWords(prose) {
637
+ const stripped = prose.replace(/[^\p{L}\p{N}\s]/gu, " ");
638
+ const tokens = stripped.split(/\s+/).filter((t) => t.length > 0);
639
+ return tokens.length;
640
+ }
641
+ function computeLineStarts(body) {
642
+ const starts = [0];
643
+ for (let i = 0; i < body.length; i++) {
644
+ if (body[i] === "\n")
645
+ starts.push(i + 1);
646
+ }
647
+ return starts;
648
+ }
649
+ function offsetToLine(starts, offset) {
650
+ // binary search
651
+ let lo = 0;
652
+ let hi = starts.length - 1;
653
+ while (lo < hi) {
654
+ const mid = (lo + hi + 1) >>> 1;
655
+ const v = starts[mid];
656
+ if (v !== undefined && v <= offset)
657
+ lo = mid;
658
+ else
659
+ hi = mid - 1;
660
+ }
661
+ return lo + 1;
662
+ }
663
+ function atLineStart(body, i) {
664
+ return i === 0 || body[i - 1] === "\n";
665
+ }
666
+ /**
667
+ * Read a contiguous cluster of single-line comments starting at `i` (which
668
+ * must point to the marker). Returns null if the cluster is < MIN_LINES and
669
+ * the total chars is ≤ MIN_CHARS — the caller's heuristic also re-checks, but
670
+ * this fast-rejects short clusters cheaply.
671
+ */
672
+ function readLineCluster(body, lineStarts, i, marker) {
673
+ // Verify we're at a line start.
674
+ if (!atLineStart(body, i)) {
675
+ // Allow leading whitespace before marker (indented comments).
676
+ let j = i;
677
+ while (j > 0 && (body[j - 1] === " " || body[j - 1] === "\t"))
678
+ j -= 1;
679
+ if (j === 0 || body[j - 1] === "\n") {
680
+ i = j;
681
+ }
682
+ else {
683
+ return null;
684
+ }
685
+ }
686
+ const startLine = offsetToLine(lineStarts, i);
687
+ const startOffset = i;
688
+ let cursor = i;
689
+ let lineCount = 0;
690
+ while (cursor < body.length) {
691
+ // Skip leading whitespace
692
+ let lineStart = cursor;
693
+ while (lineStart < body.length &&
694
+ (body[lineStart] === " " || body[lineStart] === "\t")) {
695
+ lineStart += 1;
696
+ }
697
+ if (!body.startsWith(marker, lineStart))
698
+ break;
699
+ // Reject /// when we're scanning //, and vice-versa: marker must match exactly
700
+ // and not be a prefix of a longer one (handled by callers picking the right marker).
701
+ const nextChar = body[lineStart + marker.length];
702
+ if (marker === "//" && (nextChar === "/" || nextChar === "!"))
703
+ break;
704
+ const nl = body.indexOf("\n", lineStart);
705
+ cursor = nl === -1 ? body.length : nl + 1;
706
+ lineCount += 1;
707
+ if (cursor >= body.length)
708
+ break;
709
+ }
710
+ if (lineCount < 2)
711
+ return null; // cluster is at least 2 lines
712
+ const endOffset = cursor === 0 ? 0 : (body[cursor - 1] === "\n" ? cursor - 1 : cursor);
713
+ const raw = body.slice(startOffset, endOffset);
714
+ const endLine = offsetToLine(lineStarts, endOffset === startOffset ? startOffset : endOffset - 1);
715
+ return { raw, startLine, endLine, startOffset, endOffset };
716
+ }
717
+ /**
718
+ * Crude string-context check — true when offset i is inside a "..." or '...'
719
+ * literal on the current line. Good enough for the C-style scanner; misses
720
+ * multi-line backtick template strings, which are rare for real "//" tokens.
721
+ */
722
+ function inString(body, i) {
723
+ // walk back to start of line
724
+ let j = i;
725
+ while (j > 0 && body[j - 1] !== "\n")
726
+ j -= 1;
727
+ let s = false;
728
+ let q = null;
729
+ while (j < i) {
730
+ const ch = body[j];
731
+ if (q !== null) {
732
+ if (ch === "\\") {
733
+ j += 2;
734
+ continue;
735
+ }
736
+ if (ch === q) {
737
+ q = null;
738
+ s = false;
739
+ }
740
+ }
741
+ else if (ch === '"' || ch === "'" || ch === "`") {
742
+ q = ch;
743
+ s = true;
744
+ }
745
+ j += 1;
746
+ }
747
+ return s;
748
+ }
749
+ function skipString(body, i) {
750
+ const q = body[i];
751
+ if (q === undefined)
752
+ return i + 1;
753
+ let j = i + 1;
754
+ while (j < body.length) {
755
+ if (body[j] === "\\") {
756
+ j += 2;
757
+ continue;
758
+ }
759
+ if (body[j] === q)
760
+ return j + 1;
761
+ j += 1;
762
+ }
763
+ return body.length;
764
+ }
765
+ /* -------------------------------------------------------------------------- */
766
+ /* Re-exports for convenience */
767
+ /* -------------------------------------------------------------------------- */
768
+ export const HEURISTIC = {
769
+ MIN_LINES,
770
+ MIN_CHARS,
771
+ MIN_JSDOC_WORDS,
772
+ };
773
+ export function _existsForTest(p) {
774
+ return existsSync(p);
775
+ }
776
+ void statSync; // keep imports stable across edits
777
+ //# sourceMappingURL=walker.js.map