@mseep/core 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/CHANGELOG.md +285 -0
  2. package/LICENSE +21 -0
  3. package/README.ja.md +14 -0
  4. package/README.ko.md +14 -0
  5. package/README.md +227 -0
  6. package/README.pt-BR.md +14 -0
  7. package/README.skills.md +50 -0
  8. package/README.uk.md +14 -0
  9. package/README.zh-CN.md +14 -0
  10. package/bin/booklib-mcp.js +458 -0
  11. package/bin/booklib.js +2394 -0
  12. package/bin/skills.cjs +1292 -0
  13. package/community/registry.json +1616 -0
  14. package/hooks/hooks.json +52 -0
  15. package/hooks/posttooluse-capture.mjs +67 -0
  16. package/hooks/posttooluse-contradict.mjs +76 -0
  17. package/hooks/posttooluse-imports.mjs +67 -0
  18. package/hooks/pretooluse-inject.mjs +82 -0
  19. package/hooks/suggest.js +153 -0
  20. package/lib/agent-detector.js +96 -0
  21. package/lib/config-loader.js +39 -0
  22. package/lib/conflict-resolver.js +148 -0
  23. package/lib/connectors/context7.js +167 -0
  24. package/lib/connectors/github.js +223 -0
  25. package/lib/connectors/local.js +120 -0
  26. package/lib/connectors/notion.js +436 -0
  27. package/lib/connectors/web.js +134 -0
  28. package/lib/context-builder.js +574 -0
  29. package/lib/discovery-engine.js +298 -0
  30. package/lib/doctor/hook-installer.js +83 -0
  31. package/lib/doctor/usage-tracker.js +87 -0
  32. package/lib/engine/auditor.js +103 -0
  33. package/lib/engine/auto-linker.js +177 -0
  34. package/lib/engine/bm25-index.js +178 -0
  35. package/lib/engine/capture.js +120 -0
  36. package/lib/engine/context-map.js +641 -0
  37. package/lib/engine/corrections.js +194 -0
  38. package/lib/engine/decision-checker.js +203 -0
  39. package/lib/engine/doctor.js +207 -0
  40. package/lib/engine/embedding-provider.js +72 -0
  41. package/lib/engine/gap-detector.js +138 -0
  42. package/lib/engine/gap-resolver.js +135 -0
  43. package/lib/engine/graph-injector.js +137 -0
  44. package/lib/engine/graph-search.js +183 -0
  45. package/lib/engine/graph.js +170 -0
  46. package/lib/engine/handoff.js +411 -0
  47. package/lib/engine/import-checker.js +249 -0
  48. package/lib/engine/import-parser.js +145 -0
  49. package/lib/engine/indexer.js +334 -0
  50. package/lib/engine/lookup-priority.js +15 -0
  51. package/lib/engine/parser.js +257 -0
  52. package/lib/engine/principle-extractor.js +116 -0
  53. package/lib/engine/project-analyzer.js +353 -0
  54. package/lib/engine/query-expander.js +42 -0
  55. package/lib/engine/reasoning-modes.js +353 -0
  56. package/lib/engine/registries.js +524 -0
  57. package/lib/engine/reranker.js +45 -0
  58. package/lib/engine/rrf.js +59 -0
  59. package/lib/engine/scanner.js +151 -0
  60. package/lib/engine/searcher.js +223 -0
  61. package/lib/engine/session-coordinator.js +291 -0
  62. package/lib/engine/session-manager.js +375 -0
  63. package/lib/engine/source-detector.js +240 -0
  64. package/lib/engine/source-manager.js +142 -0
  65. package/lib/engine/structured-response.js +47 -0
  66. package/lib/engine/synthesis-templates.js +364 -0
  67. package/lib/installer.js +70 -0
  68. package/lib/instinct-block.js +21 -0
  69. package/lib/mcp-config-writer.js +107 -0
  70. package/lib/paths.js +62 -0
  71. package/lib/project-initializer.js +856 -0
  72. package/lib/registry/skills.js +102 -0
  73. package/lib/registry-searcher.js +107 -0
  74. package/lib/rules/rules-manager.js +169 -0
  75. package/lib/skill-fetcher.js +333 -0
  76. package/lib/well-known-builder.js +74 -0
  77. package/lib/wizard/index.js +1389 -0
  78. package/lib/wizard/integration-detector.js +41 -0
  79. package/lib/wizard/project-detector.js +146 -0
  80. package/lib/wizard/prompt.js +221 -0
  81. package/lib/wizard/registry-embeddings.js +107 -0
  82. package/lib/wizard/skill-recommender.js +69 -0
  83. package/package.json +70 -0
  84. package/skills/animation-at-work/SKILL.md +270 -0
  85. package/skills/animation-at-work/assets/example_asset.txt +1 -0
  86. package/skills/animation-at-work/evals/evals.json +44 -0
  87. package/skills/animation-at-work/evals/results.json +13 -0
  88. package/skills/animation-at-work/examples/after.md +64 -0
  89. package/skills/animation-at-work/examples/before.md +35 -0
  90. package/skills/animation-at-work/references/api_reference.md +369 -0
  91. package/skills/animation-at-work/references/review-checklist.md +79 -0
  92. package/skills/animation-at-work/scripts/audit_animations.py +295 -0
  93. package/skills/animation-at-work/scripts/example.py +1 -0
  94. package/skills/booklib-mcp-guide/SKILL.md +129 -0
  95. package/skills/booklib-mcp-guide/evals/evals.json +37 -0
  96. package/skills/booklib-mcp-guide/examples/after.md +34 -0
  97. package/skills/booklib-mcp-guide/examples/before.md +27 -0
  98. package/skills/booklib-mcp-guide/references/tool-catalog.md +9 -0
  99. package/skills/clean-code-reviewer/SKILL.md +444 -0
  100. package/skills/clean-code-reviewer/audit.json +35 -0
  101. package/skills/clean-code-reviewer/evals/evals.json +185 -0
  102. package/skills/clean-code-reviewer/evals/results.json +13 -0
  103. package/skills/clean-code-reviewer/examples/after.md +48 -0
  104. package/skills/clean-code-reviewer/examples/before.md +33 -0
  105. package/skills/clean-code-reviewer/references/api_reference.md +158 -0
  106. package/skills/clean-code-reviewer/references/practices-catalog.md +282 -0
  107. package/skills/clean-code-reviewer/references/review-checklist.md +254 -0
  108. package/skills/clean-code-reviewer/scripts/pre-review.py +206 -0
  109. package/skills/data-intensive-patterns/SKILL.md +267 -0
  110. package/skills/data-intensive-patterns/assets/example_asset.txt +1 -0
  111. package/skills/data-intensive-patterns/evals/evals.json +54 -0
  112. package/skills/data-intensive-patterns/evals/results.json +13 -0
  113. package/skills/data-intensive-patterns/examples/after.md +61 -0
  114. package/skills/data-intensive-patterns/examples/before.md +38 -0
  115. package/skills/data-intensive-patterns/references/api_reference.md +34 -0
  116. package/skills/data-intensive-patterns/references/patterns-catalog.md +551 -0
  117. package/skills/data-intensive-patterns/references/review-checklist.md +193 -0
  118. package/skills/data-intensive-patterns/scripts/adr.py +213 -0
  119. package/skills/data-intensive-patterns/scripts/example.py +1 -0
  120. package/skills/data-pipelines/SKILL.md +259 -0
  121. package/skills/data-pipelines/assets/example_asset.txt +1 -0
  122. package/skills/data-pipelines/evals/evals.json +45 -0
  123. package/skills/data-pipelines/evals/results.json +13 -0
  124. package/skills/data-pipelines/examples/after.md +97 -0
  125. package/skills/data-pipelines/examples/before.md +37 -0
  126. package/skills/data-pipelines/references/api_reference.md +301 -0
  127. package/skills/data-pipelines/references/review-checklist.md +181 -0
  128. package/skills/data-pipelines/scripts/example.py +1 -0
  129. package/skills/data-pipelines/scripts/new_pipeline.py +444 -0
  130. package/skills/design-patterns/SKILL.md +271 -0
  131. package/skills/design-patterns/assets/example_asset.txt +1 -0
  132. package/skills/design-patterns/evals/evals.json +46 -0
  133. package/skills/design-patterns/evals/results.json +13 -0
  134. package/skills/design-patterns/examples/after.md +52 -0
  135. package/skills/design-patterns/examples/before.md +29 -0
  136. package/skills/design-patterns/references/api_reference.md +1 -0
  137. package/skills/design-patterns/references/patterns-catalog.md +726 -0
  138. package/skills/design-patterns/references/review-checklist.md +173 -0
  139. package/skills/design-patterns/scripts/example.py +1 -0
  140. package/skills/design-patterns/scripts/scaffold.py +807 -0
  141. package/skills/domain-driven-design/SKILL.md +142 -0
  142. package/skills/domain-driven-design/assets/example_asset.txt +1 -0
  143. package/skills/domain-driven-design/evals/evals.json +48 -0
  144. package/skills/domain-driven-design/evals/results.json +13 -0
  145. package/skills/domain-driven-design/examples/after.md +80 -0
  146. package/skills/domain-driven-design/examples/before.md +43 -0
  147. package/skills/domain-driven-design/references/api_reference.md +1 -0
  148. package/skills/domain-driven-design/references/patterns-catalog.md +545 -0
  149. package/skills/domain-driven-design/references/review-checklist.md +158 -0
  150. package/skills/domain-driven-design/scripts/example.py +1 -0
  151. package/skills/domain-driven-design/scripts/scaffold.py +421 -0
  152. package/skills/effective-java/SKILL.md +227 -0
  153. package/skills/effective-java/assets/example_asset.txt +1 -0
  154. package/skills/effective-java/evals/evals.json +46 -0
  155. package/skills/effective-java/evals/results.json +13 -0
  156. package/skills/effective-java/examples/after.md +83 -0
  157. package/skills/effective-java/examples/before.md +37 -0
  158. package/skills/effective-java/references/api_reference.md +1 -0
  159. package/skills/effective-java/references/items-catalog.md +955 -0
  160. package/skills/effective-java/references/review-checklist.md +216 -0
  161. package/skills/effective-java/scripts/checkstyle_setup.py +211 -0
  162. package/skills/effective-java/scripts/example.py +1 -0
  163. package/skills/effective-kotlin/SKILL.md +271 -0
  164. package/skills/effective-kotlin/assets/example_asset.txt +1 -0
  165. package/skills/effective-kotlin/audit.json +29 -0
  166. package/skills/effective-kotlin/evals/evals.json +45 -0
  167. package/skills/effective-kotlin/evals/results.json +13 -0
  168. package/skills/effective-kotlin/examples/after.md +36 -0
  169. package/skills/effective-kotlin/examples/before.md +38 -0
  170. package/skills/effective-kotlin/references/api_reference.md +1 -0
  171. package/skills/effective-kotlin/references/practices-catalog.md +1228 -0
  172. package/skills/effective-kotlin/references/review-checklist.md +126 -0
  173. package/skills/effective-kotlin/scripts/example.py +1 -0
  174. package/skills/effective-python/SKILL.md +441 -0
  175. package/skills/effective-python/evals/evals.json +44 -0
  176. package/skills/effective-python/evals/results.json +13 -0
  177. package/skills/effective-python/examples/after.md +56 -0
  178. package/skills/effective-python/examples/before.md +40 -0
  179. package/skills/effective-python/ref-01-pythonic-thinking.md +202 -0
  180. package/skills/effective-python/ref-02-lists-and-dicts.md +146 -0
  181. package/skills/effective-python/ref-03-functions.md +186 -0
  182. package/skills/effective-python/ref-04-comprehensions-generators.md +211 -0
  183. package/skills/effective-python/ref-05-classes-interfaces.md +188 -0
  184. package/skills/effective-python/ref-06-metaclasses-attributes.md +209 -0
  185. package/skills/effective-python/ref-07-concurrency.md +213 -0
  186. package/skills/effective-python/ref-08-robustness-performance.md +248 -0
  187. package/skills/effective-python/ref-09-testing-debugging.md +253 -0
  188. package/skills/effective-python/ref-10-collaboration.md +175 -0
  189. package/skills/effective-python/references/api_reference.md +218 -0
  190. package/skills/effective-python/references/practices-catalog.md +483 -0
  191. package/skills/effective-python/references/review-checklist.md +190 -0
  192. package/skills/effective-python/scripts/lint.py +173 -0
  193. package/skills/effective-typescript/SKILL.md +262 -0
  194. package/skills/effective-typescript/audit.json +29 -0
  195. package/skills/effective-typescript/evals/evals.json +37 -0
  196. package/skills/effective-typescript/evals/results.json +13 -0
  197. package/skills/effective-typescript/examples/after.md +70 -0
  198. package/skills/effective-typescript/examples/before.md +47 -0
  199. package/skills/effective-typescript/references/api_reference.md +118 -0
  200. package/skills/effective-typescript/references/practices-catalog.md +371 -0
  201. package/skills/effective-typescript/scripts/review.py +169 -0
  202. package/skills/kotlin-in-action/SKILL.md +261 -0
  203. package/skills/kotlin-in-action/assets/example_asset.txt +1 -0
  204. package/skills/kotlin-in-action/evals/evals.json +43 -0
  205. package/skills/kotlin-in-action/evals/results.json +13 -0
  206. package/skills/kotlin-in-action/examples/after.md +53 -0
  207. package/skills/kotlin-in-action/examples/before.md +39 -0
  208. package/skills/kotlin-in-action/references/api_reference.md +1 -0
  209. package/skills/kotlin-in-action/references/practices-catalog.md +436 -0
  210. package/skills/kotlin-in-action/references/review-checklist.md +204 -0
  211. package/skills/kotlin-in-action/scripts/example.py +1 -0
  212. package/skills/kotlin-in-action/scripts/setup_detekt.py +224 -0
  213. package/skills/lean-startup/SKILL.md +160 -0
  214. package/skills/lean-startup/assets/example_asset.txt +1 -0
  215. package/skills/lean-startup/evals/evals.json +43 -0
  216. package/skills/lean-startup/evals/results.json +13 -0
  217. package/skills/lean-startup/examples/after.md +80 -0
  218. package/skills/lean-startup/examples/before.md +34 -0
  219. package/skills/lean-startup/references/api_reference.md +319 -0
  220. package/skills/lean-startup/references/review-checklist.md +137 -0
  221. package/skills/lean-startup/scripts/example.py +1 -0
  222. package/skills/lean-startup/scripts/new_experiment.py +286 -0
  223. package/skills/microservices-patterns/SKILL.md +384 -0
  224. package/skills/microservices-patterns/evals/evals.json +45 -0
  225. package/skills/microservices-patterns/evals/results.json +13 -0
  226. package/skills/microservices-patterns/examples/after.md +69 -0
  227. package/skills/microservices-patterns/examples/before.md +40 -0
  228. package/skills/microservices-patterns/references/patterns-catalog.md +391 -0
  229. package/skills/microservices-patterns/references/review-checklist.md +169 -0
  230. package/skills/microservices-patterns/scripts/new_service.py +583 -0
  231. package/skills/programming-with-rust/SKILL.md +209 -0
  232. package/skills/programming-with-rust/evals/evals.json +37 -0
  233. package/skills/programming-with-rust/evals/results.json +13 -0
  234. package/skills/programming-with-rust/examples/after.md +107 -0
  235. package/skills/programming-with-rust/examples/before.md +59 -0
  236. package/skills/programming-with-rust/references/api_reference.md +152 -0
  237. package/skills/programming-with-rust/references/practices-catalog.md +335 -0
  238. package/skills/programming-with-rust/scripts/review.py +142 -0
  239. package/skills/refactoring-ui/SKILL.md +362 -0
  240. package/skills/refactoring-ui/assets/example_asset.txt +1 -0
  241. package/skills/refactoring-ui/evals/evals.json +45 -0
  242. package/skills/refactoring-ui/evals/results.json +13 -0
  243. package/skills/refactoring-ui/examples/after.md +85 -0
  244. package/skills/refactoring-ui/examples/before.md +58 -0
  245. package/skills/refactoring-ui/references/api_reference.md +355 -0
  246. package/skills/refactoring-ui/references/review-checklist.md +114 -0
  247. package/skills/refactoring-ui/scripts/audit_css.py +250 -0
  248. package/skills/refactoring-ui/scripts/example.py +1 -0
  249. package/skills/rust-in-action/SKILL.md +350 -0
  250. package/skills/rust-in-action/evals/evals.json +38 -0
  251. package/skills/rust-in-action/evals/results.json +13 -0
  252. package/skills/rust-in-action/examples/after.md +156 -0
  253. package/skills/rust-in-action/examples/before.md +56 -0
  254. package/skills/rust-in-action/references/practices-catalog.md +346 -0
  255. package/skills/rust-in-action/scripts/review.py +147 -0
  256. package/skills/skill-router/SKILL.md +186 -0
  257. package/skills/skill-router/evals/evals.json +38 -0
  258. package/skills/skill-router/evals/results.json +13 -0
  259. package/skills/skill-router/examples/after.md +63 -0
  260. package/skills/skill-router/examples/before.md +39 -0
  261. package/skills/skill-router/references/api_reference.md +24 -0
  262. package/skills/skill-router/references/routing-heuristics.md +89 -0
  263. package/skills/skill-router/references/skill-catalog.md +174 -0
  264. package/skills/skill-router/scripts/route.py +266 -0
  265. package/skills/spring-boot-in-action/SKILL.md +340 -0
  266. package/skills/spring-boot-in-action/evals/evals.json +39 -0
  267. package/skills/spring-boot-in-action/evals/results.json +13 -0
  268. package/skills/spring-boot-in-action/examples/after.md +185 -0
  269. package/skills/spring-boot-in-action/examples/before.md +84 -0
  270. package/skills/spring-boot-in-action/references/practices-catalog.md +403 -0
  271. package/skills/spring-boot-in-action/scripts/review.py +184 -0
  272. package/skills/storytelling-with-data/SKILL.md +241 -0
  273. package/skills/storytelling-with-data/assets/example_asset.txt +1 -0
  274. package/skills/storytelling-with-data/evals/evals.json +47 -0
  275. package/skills/storytelling-with-data/evals/results.json +13 -0
  276. package/skills/storytelling-with-data/examples/after.md +50 -0
  277. package/skills/storytelling-with-data/examples/before.md +33 -0
  278. package/skills/storytelling-with-data/references/api_reference.md +379 -0
  279. package/skills/storytelling-with-data/references/review-checklist.md +111 -0
  280. package/skills/storytelling-with-data/scripts/chart_review.py +301 -0
  281. package/skills/storytelling-with-data/scripts/example.py +1 -0
  282. package/skills/system-design-interview/SKILL.md +233 -0
  283. package/skills/system-design-interview/assets/example_asset.txt +1 -0
  284. package/skills/system-design-interview/evals/evals.json +46 -0
  285. package/skills/system-design-interview/evals/results.json +13 -0
  286. package/skills/system-design-interview/examples/after.md +94 -0
  287. package/skills/system-design-interview/examples/before.md +27 -0
  288. package/skills/system-design-interview/references/api_reference.md +582 -0
  289. package/skills/system-design-interview/references/review-checklist.md +201 -0
  290. package/skills/system-design-interview/scripts/example.py +1 -0
  291. package/skills/system-design-interview/scripts/new_design.py +421 -0
  292. package/skills/using-asyncio-python/SKILL.md +290 -0
  293. package/skills/using-asyncio-python/assets/example_asset.txt +1 -0
  294. package/skills/using-asyncio-python/evals/evals.json +43 -0
  295. package/skills/using-asyncio-python/evals/results.json +13 -0
  296. package/skills/using-asyncio-python/examples/after.md +68 -0
  297. package/skills/using-asyncio-python/examples/before.md +39 -0
  298. package/skills/using-asyncio-python/references/api_reference.md +267 -0
  299. package/skills/using-asyncio-python/references/review-checklist.md +149 -0
  300. package/skills/using-asyncio-python/scripts/check_blocking.py +270 -0
  301. package/skills/using-asyncio-python/scripts/example.py +1 -0
  302. package/skills/web-scraping-python/SKILL.md +280 -0
  303. package/skills/web-scraping-python/assets/example_asset.txt +1 -0
  304. package/skills/web-scraping-python/evals/evals.json +46 -0
  305. package/skills/web-scraping-python/evals/results.json +13 -0
  306. package/skills/web-scraping-python/examples/after.md +109 -0
  307. package/skills/web-scraping-python/examples/before.md +40 -0
  308. package/skills/web-scraping-python/references/api_reference.md +393 -0
  309. package/skills/web-scraping-python/references/review-checklist.md +163 -0
  310. package/skills/web-scraping-python/scripts/example.py +1 -0
  311. package/skills/web-scraping-python/scripts/new_scraper.py +231 -0
  312. package/skills/writing-plans/audit.json +34 -0
@@ -0,0 +1,375 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import os from 'os';
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+
8
+ export class BookLibSessionManager {
9
+ constructor(projectRoot = process.cwd()) {
10
+ this.projectRoot = projectRoot;
11
+ this.sessionsDir = path.join(projectRoot, '.booklib/sessions');
12
+ this.globalSessionsDir = path.join(os.homedir(), '.booklib/sessions');
13
+ this.archiveDir = path.join(this.sessionsDir, '_archive');
14
+ this.templatesDir = path.join(this.sessionsDir, '_templates');
15
+ this.tagsFile = path.join(this.sessionsDir, '_tags.json');
16
+ this.versionsDir = path.join(this.sessionsDir, '_versions');
17
+ this.configFile = path.join(projectRoot, '.booklib/config.json');
18
+ this.hooksDir = path.join(projectRoot, '.git/hooks');
19
+ }
20
+
21
+ findSession(sessionName, options = {}) {
22
+ const { searchGlobal = false } = options;
23
+ const projectSession = path.join(this.sessionsDir, `${sessionName}.md`);
24
+ if (fs.existsSync(projectSession)) {
25
+ return { path: projectSession, scope: 'project' };
26
+ }
27
+ if (searchGlobal || this._getConfig().indexFallback === 'global') {
28
+ if (fs.existsSync(this.globalSessionsDir)) {
29
+ const globalSession = path.join(this.globalSessionsDir, `${sessionName}.md`);
30
+ if (fs.existsSync(globalSession)) {
31
+ return { path: globalSession, scope: 'global' };
32
+ }
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+
38
+ cleanupSessions(options = {}) {
39
+ const { beforeDays = 90, archive = true, dryRun = false } = options;
40
+ if (!fs.existsSync(this.sessionsDir)) return { archived: 0, deleted: 0 };
41
+
42
+ const cutoffTime = Date.now() - (beforeDays * 24 * 60 * 60 * 1000);
43
+ const files = fs.readdirSync(this.sessionsDir)
44
+ .filter(f => f.endsWith('.md') && !f.startsWith('_'));
45
+
46
+ let archived = 0, deleted = 0;
47
+ const result = [];
48
+
49
+ for (const file of files) {
50
+ const filePath = path.join(this.sessionsDir, file);
51
+ const stat = fs.statSync(filePath);
52
+
53
+ if (stat.mtime.getTime() < cutoffTime) {
54
+ const action = archive ? 'archive' : 'delete';
55
+ result.push({ file, action, mtime: stat.mtime });
56
+
57
+ if (!dryRun) {
58
+ if (archive) {
59
+ this._archiveFile(filePath);
60
+ archived++;
61
+ } else {
62
+ fs.unlinkSync(filePath);
63
+ deleted++;
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ return { archived, deleted, preview: result };
70
+ }
71
+
72
+ diffSessions(session1Name, session2Name) {
73
+ const s1 = this.findSession(session1Name);
74
+ const s2 = this.findSession(session2Name);
75
+
76
+ if (!s1 || !s2) {
77
+ return { error: 'Session not found' };
78
+ }
79
+
80
+ const data1 = this._parseSession(fs.readFileSync(s1.path, 'utf8'));
81
+ const data2 = this._parseSession(fs.readFileSync(s2.path, 'utf8'));
82
+
83
+ return {
84
+ session1: session1Name,
85
+ session2: session2Name,
86
+ goal: {
87
+ s1: data1.goal,
88
+ s2: data2.goal,
89
+ changed: data1.goal !== data2.goal
90
+ },
91
+ progress: {
92
+ s1: data1.progress,
93
+ s2: data2.progress,
94
+ changed: data1.progress !== data2.progress
95
+ },
96
+ tasks: {
97
+ s1: data1.pending_tasks,
98
+ s2: data2.pending_tasks,
99
+ conflicts: this._detectConflicts(data1.pending_tasks, data2.pending_tasks)
100
+ },
101
+ skills: {
102
+ s1: data1.skills,
103
+ s2: data2.skills,
104
+ added: data2.skills.filter(s => !data1.skills.includes(s)),
105
+ removed: data1.skills.filter(s => !data2.skills.includes(s))
106
+ }
107
+ };
108
+ }
109
+
110
+ createFromTemplate(templateName, sessionName, overrides = {}) {
111
+ const templatePath = path.join(this.templatesDir, `${templateName}.md`);
112
+
113
+ if (!fs.existsSync(templatePath)) {
114
+ return { error: `Template not found: ${templateName}` };
115
+ }
116
+
117
+ let content = fs.readFileSync(templatePath, 'utf8');
118
+ content = content.replace(/\{\{session_name\}\}/g, sessionName);
119
+ content = content.replace(/\{\{timestamp\}\}/g, new Date().toISOString());
120
+
121
+ if (overrides.goal) {
122
+ content = content.replace(/goal>.+?<\/goal/, `goal>${overrides.goal}</goal`);
123
+ }
124
+
125
+ const sessionPath = path.join(this.sessionsDir, `${sessionName}.md`);
126
+ fs.writeFileSync(sessionPath, content);
127
+
128
+ return { created: sessionPath, template: templateName };
129
+ }
130
+
131
+ searchSessions(query, options = {}) {
132
+ if (!fs.existsSync(this.sessionsDir)) return [];
133
+
134
+ const files = fs.readdirSync(this.sessionsDir)
135
+ .filter(f => f.endsWith('.md') && !f.startsWith('_'));
136
+
137
+ const results = [];
138
+ const lowerQuery = query.toLowerCase();
139
+
140
+ for (const file of files) {
141
+ const filePath = path.join(this.sessionsDir, file);
142
+ const content = fs.readFileSync(filePath, 'utf8');
143
+ const data = this._parseSession(content);
144
+
145
+ const matches =
146
+ data.goal.toLowerCase().includes(lowerQuery) ||
147
+ data.progress.toLowerCase().includes(lowerQuery) ||
148
+ (data.tags && data.tags.some(t => t.toLowerCase().includes(lowerQuery)));
149
+
150
+ if (matches) {
151
+ results.push({
152
+ name: file.replace('.md', ''),
153
+ goal: data.goal.substring(0, 50),
154
+ tags: data.tags || [],
155
+ timestamp: data.timestamp
156
+ });
157
+ }
158
+ }
159
+
160
+ return results.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));
161
+ }
162
+
163
+ tagSession(sessionName, tags, action = 'add') {
164
+ let allTags = this._loadTags();
165
+
166
+ if (!allTags[sessionName]) {
167
+ allTags[sessionName] = [];
168
+ }
169
+
170
+ if (action === 'add') {
171
+ allTags[sessionName] = [...new Set([...allTags[sessionName], ...tags])];
172
+ } else if (action === 'remove') {
173
+ allTags[sessionName] = allTags[sessionName].filter(t => !tags.includes(t));
174
+ }
175
+
176
+ this._saveTags(allTags);
177
+ return { session: sessionName, tags: allTags[sessionName] };
178
+ }
179
+
180
+ generateReport(options = {}) {
181
+ const { since = null, groupBy = null } = options;
182
+
183
+ if (!fs.existsSync(this.sessionsDir)) {
184
+ return { sessions: 0, report: {} };
185
+ }
186
+
187
+ const files = fs.readdirSync(this.sessionsDir)
188
+ .filter(f => f.endsWith('.md') && !f.startsWith('_'));
189
+
190
+ const sessions = [];
191
+ const sinceTime = since ? new Date(since).getTime() : 0;
192
+
193
+ for (const file of files) {
194
+ const filePath = path.join(this.sessionsDir, file);
195
+ const content = fs.readFileSync(filePath, 'utf8');
196
+ const data = this._parseSession(content);
197
+
198
+ if (new Date(data.timestamp).getTime() >= sinceTime) {
199
+ sessions.push(data);
200
+ }
201
+ }
202
+
203
+ const stats = {
204
+ total_sessions: sessions.length,
205
+ total_tasks: sessions.reduce((sum, s) => sum + (s.pending_tasks ? s.pending_tasks.split('\n').length : 0), 0),
206
+ total_skills: [...new Set(sessions.flatMap(s => s.skills || []))].length,
207
+ unique_skills: [...new Set(sessions.flatMap(s => s.skills || []))],
208
+ by_branch: this._groupBy(sessions, 'branch'),
209
+ recent_activity: sessions.slice(0, 5).map(s => ({
210
+ name: s.session_id,
211
+ timestamp: s.timestamp,
212
+ goal: s.goal
213
+ }))
214
+ };
215
+
216
+ return stats;
217
+ }
218
+
219
+ validateSession(sessionName) {
220
+ const session = this.findSession(sessionName);
221
+ if (!session) return { valid: false, errors: ['Session not found'] };
222
+
223
+ const content = fs.readFileSync(session.path, 'utf8');
224
+ const data = this._parseSession(content);
225
+ const errors = [];
226
+ const warnings = [];
227
+
228
+ if (!data.goal || data.goal.length < 10) {
229
+ errors.push('Goal too vague (< 10 characters)');
230
+ }
231
+
232
+ if (!data.progress || data.progress.length < 10) {
233
+ warnings.push('Progress not detailed enough');
234
+ }
235
+
236
+ if (!data.pending_tasks || data.pending_tasks.length === 0) {
237
+ warnings.push('No pending tasks defined');
238
+ }
239
+
240
+ if (!data.skills || data.skills.length === 0) {
241
+ warnings.push('No skills specified');
242
+ }
243
+
244
+ return {
245
+ valid: errors.length === 0,
246
+ errors,
247
+ warnings,
248
+ score: this._calculateSessionScore(data)
249
+ };
250
+ }
251
+
252
+ saveVersion(sessionName, reason = 'auto-save') {
253
+ const session = this.findSession(sessionName);
254
+ if (!session) return { error: 'Session not found' };
255
+
256
+ if (!fs.existsSync(this.versionsDir)) {
257
+ fs.mkdirSync(this.versionsDir, { recursive: true });
258
+ }
259
+
260
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
261
+ const versionDir = path.join(this.versionsDir, sessionName);
262
+ if (!fs.existsSync(versionDir)) {
263
+ fs.mkdirSync(versionDir, { recursive: true });
264
+ }
265
+
266
+ const versionPath = path.join(versionDir, `${timestamp}.md`);
267
+ const content = fs.readFileSync(session.path, 'utf8');
268
+ fs.writeFileSync(versionPath, content);
269
+
270
+ return { saved: versionPath, reason, timestamp };
271
+ }
272
+
273
+ getVersionHistory(sessionName) {
274
+ const versionDir = path.join(this.versionsDir, sessionName);
275
+ if (!fs.existsSync(versionDir)) return [];
276
+
277
+ return fs.readdirSync(versionDir)
278
+ .map(f => path.join(versionDir, f))
279
+ .sort((a, b) => fs.statSync(b).mtime - fs.statSync(a).mtime)
280
+ .map((p, i) => ({
281
+ version: i + 1,
282
+ timestamp: path.basename(p, '.md'),
283
+ path: p
284
+ }));
285
+ }
286
+
287
+ // PRIVATE METHODS
288
+
289
+ _parseSession(content) {
290
+ const extract = (tag) => {
291
+ const regex = new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`);
292
+ const match = content.match(regex);
293
+ return match ? match[1].trim() : '';
294
+ };
295
+
296
+ const skillRegex = /<skill id="([^"]+)"/g;
297
+ const skills = [];
298
+ let match;
299
+ while ((match = skillRegex.exec(content)) !== null) {
300
+ skills.push(match[1]);
301
+ }
302
+
303
+ return {
304
+ timestamp: extract('timestamp'),
305
+ session_id: extract('session_id'),
306
+ branch: extract('branch'),
307
+ goal: extract('goal'),
308
+ progress: extract('progress'),
309
+ pending_tasks: extract('pending_tasks'),
310
+ skills,
311
+ tags: this._extractTags(extract('session_id'))
312
+ };
313
+ }
314
+
315
+ _extractTags(sessionId) {
316
+ const tagsFile = this._loadTags();
317
+ return tagsFile[sessionId] || [];
318
+ }
319
+
320
+ _loadTags() {
321
+ if (fs.existsSync(this.tagsFile)) {
322
+ return JSON.parse(fs.readFileSync(this.tagsFile, 'utf8'));
323
+ }
324
+ return {};
325
+ }
326
+
327
+ _saveTags(tags) {
328
+ if (!fs.existsSync(this.sessionsDir)) {
329
+ fs.mkdirSync(this.sessionsDir, { recursive: true });
330
+ }
331
+ fs.writeFileSync(this.tagsFile, JSON.stringify(tags, null, 2));
332
+ }
333
+
334
+ _archiveFile(filePath) {
335
+ if (!fs.existsSync(this.archiveDir)) {
336
+ fs.mkdirSync(this.archiveDir, { recursive: true });
337
+ }
338
+ const fileName = path.basename(filePath);
339
+ const destPath = path.join(this.archiveDir, fileName);
340
+ fs.copyFileSync(filePath, destPath);
341
+ fs.unlinkSync(filePath);
342
+ }
343
+
344
+ _detectConflicts(tasks1, tasks2) {
345
+ if (!tasks1 || !tasks2) return [];
346
+ const t1Array = tasks1.split('\n');
347
+ const t2Array = tasks2.split('\n');
348
+ return t1Array.filter(t => t2Array.some(t2 => t.toLowerCase() === t2.toLowerCase()));
349
+ }
350
+
351
+ _calculateSessionScore(data) {
352
+ let score = 0;
353
+ if (data.goal && data.goal.length > 10) score += 25;
354
+ if (data.progress && data.progress.length > 20) score += 25;
355
+ if (data.pending_tasks && data.pending_tasks.length > 0) score += 25;
356
+ if (data.skills && data.skills.length > 0) score += 25;
357
+ return score;
358
+ }
359
+
360
+ _groupBy(items, key) {
361
+ return items.reduce((acc, item) => {
362
+ const groupKey = item[key] || 'unknown';
363
+ if (!acc[groupKey]) acc[groupKey] = [];
364
+ acc[groupKey].push(item);
365
+ return acc;
366
+ }, {});
367
+ }
368
+
369
+ _getConfig() {
370
+ if (fs.existsSync(this.configFile)) {
371
+ return JSON.parse(fs.readFileSync(this.configFile, 'utf8'));
372
+ }
373
+ return {};
374
+ }
375
+ }
@@ -0,0 +1,240 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const HEURISTICS = {
5
+ 'framework-docs': [
6
+ { pattern: /```[\s\S]*?```/g, weight: 2, name: 'code-blocks' },
7
+ { pattern: /\bimport\s+|require\s*\(/gi, weight: 3, name: 'imports' },
8
+ { pattern: /\b(npm|yarn|pnpm)\s+(install|add|run)/gi, weight: 2, name: 'package-mgr' },
9
+ { pattern: /\b(config|configuration|setup|getting.started)\b/gi, weight: 1, name: 'setup-words' },
10
+ ],
11
+ 'api-reference': [
12
+ { pattern: /\b(GET|POST|PUT|DELETE|PATCH)\s+\//gi, weight: 3, name: 'http-methods' },
13
+ { pattern: /\/api\//gi, weight: 2, name: 'api-paths' },
14
+ { pattern: /\b(endpoint|request|response|header|status.code)\b/gi, weight: 1, name: 'api-words' },
15
+ { pattern: /\b(200|201|400|401|403|404|500)\b/g, weight: 1, name: 'status-codes' },
16
+ ],
17
+ 'release-notes': [
18
+ { pattern: /^#{1,3}\s*v?\d+\.\d+/gm, weight: 4, name: 'version-headers' },
19
+ { pattern: /\b(breaking|deprecated|removed)\b/gi, weight: 3, name: 'breaking-words' },
20
+ { pattern: /\b(added|fixed|changed|updated)\b/gi, weight: 2, name: 'changelog-words' },
21
+ { pattern: /\bchangelog\b/gi, weight: 2, name: 'changelog-mention' },
22
+ ],
23
+ 'spec': [
24
+ { pattern: /\b(requirement|acceptance.criteria|user.story)\b/gi, weight: 4, name: 'spec-terms' },
25
+ { pattern: /\b(shall|must|should)\b/gi, weight: 2, name: 'rfc-modals' },
26
+ { pattern: /given.*when.*then/gi, weight: 4, name: 'gherkin' },
27
+ { pattern: /\b(feature|scenario|priority)\b/gi, weight: 1, name: 'spec-words' },
28
+ ],
29
+ 'team-decision': [
30
+ { pattern: /##\s*(Context|Decision|Consequences)/gi, weight: 5, name: 'adr-headers' },
31
+ { pattern: /\bStatus:\s*(Accepted|Proposed|Deprecated)/gi, weight: 4, name: 'adr-status' },
32
+ { pattern: /\b(ADR|architecture.decision)\b/gi, weight: 3, name: 'adr-mention' },
33
+ ],
34
+ 'tutorial': [
35
+ { pattern: /\bstep\s+\d+/gi, weight: 3, name: 'step-numbers' },
36
+ { pattern: /^#{1,3}\s*step\s+\d+/gim, weight: 4, name: 'step-headers' },
37
+ { pattern: /\b(first|next|then|finally|let's)\b/gi, weight: 1, name: 'sequence-words' },
38
+ ],
39
+ // Spec-driven development frameworks: SpecKit, GSD, Kiro, Superpowers
40
+ 'sdd-spec': [
41
+ { pattern: /\b(GOAL|DELIVERS|NOT.DOING|ASSUMPTIONS)\b/g, weight: 5, name: 'spec-card' },
42
+ { pattern: /\b(requirement|acceptance.criteria|user.story)\b/gi, weight: 3, name: 'req-terms' },
43
+ { pattern: /^#{1,3}\s*Task\s+\d+/gm, weight: 4, name: 'task-headers' },
44
+ { pattern: /- \[ \]/g, weight: 2, name: 'task-checkboxes' },
45
+ { pattern: /\b(implementation.plan|design.doc|architecture)\b/gi, weight: 2, name: 'plan-words' },
46
+ { pattern: /\b(spec|specification|roadmap|milestone)\b/gi, weight: 2, name: 'spec-words' },
47
+ { pattern: /\b(constitution|steering|constraints)\b/gi, weight: 3, name: 'speckit-terms' },
48
+ { pattern: /\b(STATE|REQUIREMENTS|ROADMAP|PROJECT)\.md\b/g, weight: 4, name: 'gsd-files' },
49
+ ],
50
+ // OpenAPI, AsyncAPI, GraphQL SDL, Protocol Buffers
51
+ 'api-spec': [
52
+ { pattern: /\bopenapi:\s*["']?3\./gi, weight: 6, name: 'openapi-version' },
53
+ { pattern: /\bswagger:\s*["']?2\./gi, weight: 6, name: 'swagger-version' },
54
+ { pattern: /\basyncapi:\s*["']?[23]\./gi, weight: 6, name: 'asyncapi-version' },
55
+ { pattern: /\bpaths:\s*$/gm, weight: 4, name: 'openapi-paths' },
56
+ { pattern: /\bschemas?:\s*$/gm, weight: 3, name: 'openapi-schemas' },
57
+ { pattern: /\b(operationId|requestBody|responses):/gi, weight: 3, name: 'openapi-keywords' },
58
+ { pattern: /^type\s+(Query|Mutation|Subscription)\s*\{/gm, weight: 6, name: 'graphql-types' },
59
+ { pattern: /^(input|enum|interface|union)\s+\w+/gm, weight: 3, name: 'graphql-defs' },
60
+ { pattern: /^service\s+\w+\s*\{/gm, weight: 5, name: 'grpc-service' },
61
+ { pattern: /^message\s+\w+\s*\{/gm, weight: 3, name: 'proto-message' },
62
+ ],
63
+ // Gherkin BDD specs (.feature files)
64
+ 'bdd-spec': [
65
+ { pattern: /^Feature:\s+/gm, weight: 6, name: 'feature-keyword' },
66
+ { pattern: /^\s*Scenario(?:\s+Outline)?:\s+/gm, weight: 5, name: 'scenario-keyword' },
67
+ { pattern: /^\s*Given\s+/gm, weight: 3, name: 'given-step' },
68
+ { pattern: /^\s*When\s+/gm, weight: 3, name: 'when-step' },
69
+ { pattern: /^\s*Then\s+/gm, weight: 3, name: 'then-step' },
70
+ { pattern: /^\s*And\s+/gm, weight: 1, name: 'and-step' },
71
+ { pattern: /^\s*Background:/gm, weight: 4, name: 'background' },
72
+ { pattern: /^\s*Examples:/gm, weight: 4, name: 'examples-table' },
73
+ ],
74
+ // Architecture: Structurizr DSL, C4 model
75
+ 'architecture': [
76
+ { pattern: /\bworkspace\s*\{/gi, weight: 6, name: 'structurizr-workspace' },
77
+ { pattern: /\b(softwareSystem|container|component|person)\s+/gi, weight: 5, name: 'c4-elements' },
78
+ { pattern: /\b(deploymentEnvironment|infrastructureNode)\b/gi, weight: 4, name: 'c4-deployment' },
79
+ { pattern: /\b(System.Context|Container|Component|Dynamic|Deployment)\s+(Diagram|View)/gi, weight: 5, name: 'c4-diagrams' },
80
+ { pattern: /\b(arc42|architecture.overview|building.block)/gi, weight: 3, name: 'arc42-terms' },
81
+ { pattern: /\b(quality.requirements|runtime.view|deployment.view)\b/gi, weight: 3, name: 'arc42-sections' },
82
+ ],
83
+ // Internal project documentation with code examples and spec terms
84
+ 'project-docs': [
85
+ { pattern: /```[\s\S]*?```/g, weight: 1, name: 'code-blocks' },
86
+ { pattern: /\bimport\s+|require\s*\(/gi, weight: 1, name: 'imports' },
87
+ { pattern: /\b(acceptance.criteria|user.stor(?:y|ies))\b/gi, weight: 4, name: 'project-spec-terms' },
88
+ { pattern: /##\s*(Context|Decision|Consequences)/gi, weight: 3, name: 'adr-headers' },
89
+ { pattern: /\b(implementation.plan|design.doc|technical.design)\b/gi, weight: 3, name: 'internal-plan-terms' },
90
+ { pattern: /\b(sprint|backlog|epic|milestone)\b/gi, weight: 2, name: 'agile-terms' },
91
+ { pattern: /\b(TODO|FIXME|HACK|NOTE):/g, weight: 2, name: 'dev-markers' },
92
+ { pattern: /\b(refactor|deprecate|migrate|upgrade)\b/gi, weight: 1, name: 'maintenance-words' },
93
+ ],
94
+ // Personal knowledge management: Obsidian, Logseq, Foam, Dendron
95
+ 'pkm': [
96
+ { pattern: /\[\[([^\]]+)\]\]/g, weight: 4, name: 'wikilinks' },
97
+ { pattern: /\(\(([a-f0-9-]+)\)\)/g, weight: 5, name: 'logseq-block-refs' },
98
+ { pattern: /^tags:\s*\[/gm, weight: 3, name: 'yaml-tags-array' },
99
+ { pattern: /^aliases:\s*\[/gm, weight: 4, name: 'obsidian-aliases' },
100
+ { pattern: /^cssclass:/gm, weight: 5, name: 'obsidian-cssclass' },
101
+ { pattern: /^publish:\s*(true|false)/gm, weight: 4, name: 'obsidian-publish' },
102
+ { pattern: /^date:\s*\d{4}-\d{2}-\d{2}/gm, weight: 2, name: 'dated-notes' },
103
+ { pattern: /#[a-zA-Z][\w/-]+/g, weight: 1, name: 'hashtags' },
104
+ { pattern: /^\s*- \[\[/gm, weight: 3, name: 'linked-list-items' },
105
+ { pattern: /\^[a-f0-9]{6}/g, weight: 4, name: 'obsidian-block-ids' },
106
+ ],
107
+ };
108
+
109
+ /** Penalty patterns that reduce scores for misclassified types. */
110
+ const NEGATIVE_SIGNALS = {
111
+ 'framework-docs': [
112
+ { pattern: /\b(acceptance.criteria|user.stor(?:y|ies))\b/gi, weight: -5, name: 'project-spec-terms' },
113
+ { pattern: /##\s*(Context|Decision|Consequences)/gi, weight: -4, name: 'adr-headers' },
114
+ { pattern: /\bStatus:\s*(Accepted|Proposed|Deprecated)/gi, weight: -4, name: 'adr-status' },
115
+ { pattern: /\b(sprint|backlog|epic|kanban)\b/gi, weight: -3, name: 'agile-terms' },
116
+ { pattern: /\b(implementation.plan|design.doc|technical.design)\b/gi, weight: -3, name: 'internal-plan-terms' },
117
+ ],
118
+ };
119
+
120
+ /**
121
+ * Detect the source type of a directory by analyzing file contents.
122
+ * Scores each file against keyword/pattern heuristics and picks the highest-scoring type.
123
+ * Falls back to 'wiki' when no type scores above the threshold.
124
+ *
125
+ * @param {string} dirPath - directory to analyze
126
+ * @param {object} [opts]
127
+ * @param {number} [opts.maxFiles=10] - max files to sample
128
+ * @param {number} [opts.minScore=5] - minimum score to beat 'wiki' default
129
+ * @returns {{ type: string, scores: Record<string, number>, confidence: string }}
130
+ */
131
+ export function detectSourceType(dirPath, opts = {}) {
132
+ const { maxFiles = 10, minScore = 5 } = opts;
133
+
134
+ if (maxFiles < 1) throw new Error('maxFiles must be >= 1');
135
+ if (minScore < 0) throw new Error('minScore must be >= 0');
136
+
137
+ let files;
138
+ try {
139
+ files = findContentFiles(dirPath).slice(0, maxFiles);
140
+ } catch {
141
+ return { type: 'wiki', scores: {}, confidence: 'none' };
142
+ }
143
+
144
+ if (files.length === 0) {
145
+ return { type: 'wiki', scores: {}, confidence: 'none' };
146
+ }
147
+
148
+ // Directory-level signals: config dirs that strongly indicate a tool
149
+ const dirBonus = detectDirSignals(dirPath);
150
+
151
+ const parts = [];
152
+ for (const f of files) {
153
+ const text = fs.readFileSync(f, 'utf8').trim();
154
+ if (text.length > 0) parts.push(text);
155
+ }
156
+ if (parts.length === 0) {
157
+ return { type: 'wiki', scores: {}, confidence: 'none' };
158
+ }
159
+ const content = parts.join('\n');
160
+
161
+ const scores = {};
162
+ for (const [type, rules] of Object.entries(HEURISTICS)) {
163
+ let score = 0;
164
+ for (const rule of rules) {
165
+ const matches = content.match(rule.pattern);
166
+ if (matches) score += matches.length * rule.weight;
167
+ }
168
+ // Apply negative signals (penalties for misclassification)
169
+ const penalties = NEGATIVE_SIGNALS[type];
170
+ if (penalties) {
171
+ for (const rule of penalties) {
172
+ const matches = content.match(rule.pattern);
173
+ if (matches) score += matches.length * rule.weight;
174
+ }
175
+ }
176
+ scores[type] = Math.max(0, score + (dirBonus[type] ?? 0));
177
+ }
178
+
179
+ const sorted = Object.entries(scores).sort((a, b) => b[1] - a[1]);
180
+ const [bestType, bestScore] = sorted[0];
181
+
182
+ if (bestScore < minScore) {
183
+ return { type: 'wiki', scores, confidence: 'low' };
184
+ }
185
+
186
+ const runnerUp = sorted[1]?.[1] ?? 0;
187
+ const confidence = bestScore >= runnerUp * 2 ? 'high' : 'medium';
188
+
189
+ return { type: bestType, scores, confidence };
190
+ }
191
+
192
+ /** Check for tool-specific config directories that strongly signal a source type. */
193
+ function detectDirSignals(dirPath) {
194
+ const bonus = {};
195
+ const DIR_SIGNALS = {
196
+ '.obsidian': { type: 'pkm', score: 100 },
197
+ '.logseq': { type: 'pkm', score: 100 },
198
+ '.foam': { type: 'pkm', score: 100 },
199
+ '.specify': { type: 'sdd-spec', score: 100 },
200
+ '.planning': { type: 'sdd-spec', score: 100 },
201
+ '.gsd': { type: 'sdd-spec', score: 100 },
202
+ '.kiro': { type: 'sdd-spec', score: 100 },
203
+ 'docs': { type: 'project-docs', score: 100 },
204
+ 'doc': { type: 'project-docs', score: 100 },
205
+ };
206
+
207
+ // Check the directory name itself (fixes BUG 9: self-check)
208
+ const selfSignal = DIR_SIGNALS[path.basename(dirPath)];
209
+ if (selfSignal) bonus[selfSignal.type] = (bonus[selfSignal.type] ?? 0) + selfSignal.score;
210
+
211
+ try {
212
+ const entries = fs.readdirSync(dirPath);
213
+ for (const name of entries) {
214
+ const signal = DIR_SIGNALS[name];
215
+ if (signal) bonus[signal.type] = (bonus[signal.type] ?? 0) + signal.score;
216
+ }
217
+ } catch { /* best effort */ }
218
+ return bonus;
219
+ }
220
+
221
+ /** Recursively find content files, skipping common noise directories.
222
+ * Includes markdown, YAML, JSON, GraphQL, Gherkin, and proto files
223
+ * so structured formats (OpenAPI, GraphQL SDL, .feature) are detected. */
224
+ function findContentFiles(dirPath) {
225
+ const results = [];
226
+ const walk = (dir) => {
227
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
228
+ const full = path.join(dir, entry.name);
229
+ if (entry.isDirectory()) {
230
+ if (!['node_modules', '.git', '.booklib'].includes(entry.name)) {
231
+ walk(full);
232
+ }
233
+ } else if (/\.(md|mdx|txt|rst|ya?ml|json|graphql|gql|feature|proto|dsl)$/i.test(entry.name)) {
234
+ results.push(full);
235
+ }
236
+ }
237
+ };
238
+ walk(dirPath);
239
+ return results;
240
+ }