@andre.li/memoark 0.3.1

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 (441) hide show
  1. package/LICENSE +191 -0
  2. package/README.en.md +606 -0
  3. package/README.md +560 -0
  4. package/bin/memoark.mjs +36 -0
  5. package/dist/adapters/file.d.ts +19 -0
  6. package/dist/adapters/file.d.ts.map +1 -0
  7. package/dist/adapters/file.js +61 -0
  8. package/dist/adapters/file.js.map +1 -0
  9. package/dist/adapters/gbrain.d.ts +29 -0
  10. package/dist/adapters/gbrain.d.ts.map +1 -0
  11. package/dist/adapters/gbrain.js +622 -0
  12. package/dist/adapters/gbrain.js.map +1 -0
  13. package/dist/adapters/index.d.ts +6 -0
  14. package/dist/adapters/index.d.ts.map +1 -0
  15. package/dist/adapters/index.js +5 -0
  16. package/dist/adapters/index.js.map +1 -0
  17. package/dist/adapters/registry.d.ts +18 -0
  18. package/dist/adapters/registry.d.ts.map +1 -0
  19. package/dist/adapters/registry.js +18 -0
  20. package/dist/adapters/registry.js.map +1 -0
  21. package/dist/adapters/stdout.d.ts +12 -0
  22. package/dist/adapters/stdout.d.ts.map +1 -0
  23. package/dist/adapters/stdout.js +29 -0
  24. package/dist/adapters/stdout.js.map +1 -0
  25. package/dist/adapters/store.d.ts +47 -0
  26. package/dist/adapters/store.d.ts.map +1 -0
  27. package/dist/adapters/store.js +641 -0
  28. package/dist/adapters/store.js.map +1 -0
  29. package/dist/cli.d.ts +2 -0
  30. package/dist/cli.d.ts.map +1 -0
  31. package/dist/cli.js +694 -0
  32. package/dist/cli.js.map +1 -0
  33. package/dist/collectors/agent/claude-code.d.ts +12 -0
  34. package/dist/collectors/agent/claude-code.d.ts.map +1 -0
  35. package/dist/collectors/agent/claude-code.js +94 -0
  36. package/dist/collectors/agent/claude-code.js.map +1 -0
  37. package/dist/collectors/agent/codex.d.ts +16 -0
  38. package/dist/collectors/agent/codex.d.ts.map +1 -0
  39. package/dist/collectors/agent/codex.js +149 -0
  40. package/dist/collectors/agent/codex.js.map +1 -0
  41. package/dist/collectors/agent/collector.d.ts +20 -0
  42. package/dist/collectors/agent/collector.d.ts.map +1 -0
  43. package/dist/collectors/agent/collector.js +108 -0
  44. package/dist/collectors/agent/collector.js.map +1 -0
  45. package/dist/collectors/agent/hermes.d.ts +13 -0
  46. package/dist/collectors/agent/hermes.d.ts.map +1 -0
  47. package/dist/collectors/agent/hermes.js +90 -0
  48. package/dist/collectors/agent/hermes.js.map +1 -0
  49. package/dist/collectors/agent/index.d.ts +6 -0
  50. package/dist/collectors/agent/index.d.ts.map +1 -0
  51. package/dist/collectors/agent/index.js +5 -0
  52. package/dist/collectors/agent/index.js.map +1 -0
  53. package/dist/collectors/agent/types.d.ts +61 -0
  54. package/dist/collectors/agent/types.d.ts.map +1 -0
  55. package/dist/collectors/agent/types.js +6 -0
  56. package/dist/collectors/agent/types.js.map +1 -0
  57. package/dist/collectors/feishu/auth.d.ts +13 -0
  58. package/dist/collectors/feishu/auth.d.ts.map +1 -0
  59. package/dist/collectors/feishu/auth.js +72 -0
  60. package/dist/collectors/feishu/auth.js.map +1 -0
  61. package/dist/collectors/feishu/collector.d.ts +23 -0
  62. package/dist/collectors/feishu/collector.d.ts.map +1 -0
  63. package/dist/collectors/feishu/collector.js +113 -0
  64. package/dist/collectors/feishu/collector.js.map +1 -0
  65. package/dist/collectors/feishu/cursor-staging.d.ts +11 -0
  66. package/dist/collectors/feishu/cursor-staging.d.ts.map +1 -0
  67. package/dist/collectors/feishu/cursor-staging.js +37 -0
  68. package/dist/collectors/feishu/cursor-staging.js.map +1 -0
  69. package/dist/collectors/feishu/http-client.d.ts +26 -0
  70. package/dist/collectors/feishu/http-client.d.ts.map +1 -0
  71. package/dist/collectors/feishu/http-client.js +94 -0
  72. package/dist/collectors/feishu/http-client.js.map +1 -0
  73. package/dist/collectors/feishu/index.d.ts +3 -0
  74. package/dist/collectors/feishu/index.d.ts.map +1 -0
  75. package/dist/collectors/feishu/index.js +2 -0
  76. package/dist/collectors/feishu/index.js.map +1 -0
  77. package/dist/collectors/feishu/lark-cli-client.d.ts +16 -0
  78. package/dist/collectors/feishu/lark-cli-client.d.ts.map +1 -0
  79. package/dist/collectors/feishu/lark-cli-client.js +69 -0
  80. package/dist/collectors/feishu/lark-cli-client.js.map +1 -0
  81. package/dist/collectors/feishu/rate-limiter.d.ts +10 -0
  82. package/dist/collectors/feishu/rate-limiter.d.ts.map +1 -0
  83. package/dist/collectors/feishu/rate-limiter.js +33 -0
  84. package/dist/collectors/feishu/rate-limiter.js.map +1 -0
  85. package/dist/collectors/feishu/sources/base.d.ts +9 -0
  86. package/dist/collectors/feishu/sources/base.d.ts.map +1 -0
  87. package/dist/collectors/feishu/sources/base.js +2 -0
  88. package/dist/collectors/feishu/sources/base.js.map +1 -0
  89. package/dist/collectors/feishu/sources/calendar.d.ts +16 -0
  90. package/dist/collectors/feishu/sources/calendar.d.ts.map +1 -0
  91. package/dist/collectors/feishu/sources/calendar.js +93 -0
  92. package/dist/collectors/feishu/sources/calendar.js.map +1 -0
  93. package/dist/collectors/feishu/sources/dm.d.ts +28 -0
  94. package/dist/collectors/feishu/sources/dm.d.ts.map +1 -0
  95. package/dist/collectors/feishu/sources/dm.js +152 -0
  96. package/dist/collectors/feishu/sources/dm.js.map +1 -0
  97. package/dist/collectors/feishu/sources/docs.d.ts +23 -0
  98. package/dist/collectors/feishu/sources/docs.d.ts.map +1 -0
  99. package/dist/collectors/feishu/sources/docs.js +154 -0
  100. package/dist/collectors/feishu/sources/docs.js.map +1 -0
  101. package/dist/collectors/feishu/sources/mail.d.ts +27 -0
  102. package/dist/collectors/feishu/sources/mail.d.ts.map +1 -0
  103. package/dist/collectors/feishu/sources/mail.js +136 -0
  104. package/dist/collectors/feishu/sources/mail.js.map +1 -0
  105. package/dist/collectors/feishu/sources/message-search.d.ts +37 -0
  106. package/dist/collectors/feishu/sources/message-search.d.ts.map +1 -0
  107. package/dist/collectors/feishu/sources/message-search.js +140 -0
  108. package/dist/collectors/feishu/sources/message-search.js.map +1 -0
  109. package/dist/collectors/feishu/sources/messages.d.ts +26 -0
  110. package/dist/collectors/feishu/sources/messages.d.ts.map +1 -0
  111. package/dist/collectors/feishu/sources/messages.js +148 -0
  112. package/dist/collectors/feishu/sources/messages.js.map +1 -0
  113. package/dist/collectors/feishu/sources/tasks.d.ts +15 -0
  114. package/dist/collectors/feishu/sources/tasks.d.ts.map +1 -0
  115. package/dist/collectors/feishu/sources/tasks.js +74 -0
  116. package/dist/collectors/feishu/sources/tasks.js.map +1 -0
  117. package/dist/collectors/feishu/types.d.ts +224 -0
  118. package/dist/collectors/feishu/types.d.ts.map +1 -0
  119. package/dist/collectors/feishu/types.js +17 -0
  120. package/dist/collectors/feishu/types.js.map +1 -0
  121. package/dist/collectors/index.d.ts +10 -0
  122. package/dist/collectors/index.d.ts.map +1 -0
  123. package/dist/collectors/index.js +18 -0
  124. package/dist/collectors/index.js.map +1 -0
  125. package/dist/config-center/connection-checks.d.ts +28 -0
  126. package/dist/config-center/connection-checks.d.ts.map +1 -0
  127. package/dist/config-center/connection-checks.js +114 -0
  128. package/dist/config-center/connection-checks.js.map +1 -0
  129. package/dist/config-center/document.d.ts +21 -0
  130. package/dist/config-center/document.d.ts.map +1 -0
  131. package/dist/config-center/document.js +93 -0
  132. package/dist/config-center/document.js.map +1 -0
  133. package/dist/config-center/index.d.ts +9 -0
  134. package/dist/config-center/index.d.ts.map +1 -0
  135. package/dist/config-center/index.js +29 -0
  136. package/dist/config-center/index.js.map +1 -0
  137. package/dist/config-center/recommendations.d.ts +16 -0
  138. package/dist/config-center/recommendations.d.ts.map +1 -0
  139. package/dist/config-center/recommendations.js +50 -0
  140. package/dist/config-center/recommendations.js.map +1 -0
  141. package/dist/config-center/reducer.d.ts +57 -0
  142. package/dist/config-center/reducer.d.ts.map +1 -0
  143. package/dist/config-center/reducer.js +192 -0
  144. package/dist/config-center/reducer.js.map +1 -0
  145. package/dist/config-center/schema.d.ts +31 -0
  146. package/dist/config-center/schema.d.ts.map +1 -0
  147. package/dist/config-center/schema.js +365 -0
  148. package/dist/config-center/schema.js.map +1 -0
  149. package/dist/config-center/secrets.d.ts +4 -0
  150. package/dist/config-center/secrets.d.ts.map +1 -0
  151. package/dist/config-center/secrets.js +27 -0
  152. package/dist/config-center/secrets.js.map +1 -0
  153. package/dist/config-center/source-dirs.d.ts +16 -0
  154. package/dist/config-center/source-dirs.d.ts.map +1 -0
  155. package/dist/config-center/source-dirs.js +81 -0
  156. package/dist/config-center/source-dirs.js.map +1 -0
  157. package/dist/config-center/tui/app.d.ts +22 -0
  158. package/dist/config-center/tui/app.d.ts.map +1 -0
  159. package/dist/config-center/tui/app.js +142 -0
  160. package/dist/config-center/tui/app.js.map +1 -0
  161. package/dist/config-center/tui/render.d.ts +20 -0
  162. package/dist/config-center/tui/render.d.ts.map +1 -0
  163. package/dist/config-center/tui/render.js +166 -0
  164. package/dist/config-center/tui/render.js.map +1 -0
  165. package/dist/config-center/validation.d.ts +9 -0
  166. package/dist/config-center/validation.d.ts.map +1 -0
  167. package/dist/config-center/validation.js +59 -0
  168. package/dist/config-center/validation.js.map +1 -0
  169. package/dist/consolidator/consolidator.d.ts +31 -0
  170. package/dist/consolidator/consolidator.d.ts.map +1 -0
  171. package/dist/consolidator/consolidator.js +57 -0
  172. package/dist/consolidator/consolidator.js.map +1 -0
  173. package/dist/consolidator/dead-link.d.ts +7 -0
  174. package/dist/consolidator/dead-link.d.ts.map +1 -0
  175. package/dist/consolidator/dead-link.js +57 -0
  176. package/dist/consolidator/dead-link.js.map +1 -0
  177. package/dist/consolidator/hot-warm.d.ts +9 -0
  178. package/dist/consolidator/hot-warm.d.ts.map +1 -0
  179. package/dist/consolidator/hot-warm.js +88 -0
  180. package/dist/consolidator/hot-warm.js.map +1 -0
  181. package/dist/consolidator/infer-preferences.d.ts +14 -0
  182. package/dist/consolidator/infer-preferences.d.ts.map +1 -0
  183. package/dist/consolidator/infer-preferences.js +73 -0
  184. package/dist/consolidator/infer-preferences.js.map +1 -0
  185. package/dist/consolidator/rules.d.ts +5 -0
  186. package/dist/consolidator/rules.d.ts.map +1 -0
  187. package/dist/consolidator/rules.js +53 -0
  188. package/dist/consolidator/rules.js.map +1 -0
  189. package/dist/consolidator/warm-cold.d.ts +13 -0
  190. package/dist/consolidator/warm-cold.d.ts.map +1 -0
  191. package/dist/consolidator/warm-cold.js +91 -0
  192. package/dist/consolidator/warm-cold.js.map +1 -0
  193. package/dist/core/block-builder.d.ts +15 -0
  194. package/dist/core/block-builder.d.ts.map +1 -0
  195. package/dist/core/block-builder.js +185 -0
  196. package/dist/core/block-builder.js.map +1 -0
  197. package/dist/core/canonicalize.d.ts +3 -0
  198. package/dist/core/canonicalize.d.ts.map +1 -0
  199. package/dist/core/canonicalize.js +137 -0
  200. package/dist/core/canonicalize.js.map +1 -0
  201. package/dist/core/concurrency.d.ts +2 -0
  202. package/dist/core/concurrency.d.ts.map +1 -0
  203. package/dist/core/concurrency.js +14 -0
  204. package/dist/core/concurrency.js.map +1 -0
  205. package/dist/core/config.d.ts +184 -0
  206. package/dist/core/config.d.ts.map +1 -0
  207. package/dist/core/config.js +136 -0
  208. package/dist/core/config.js.map +1 -0
  209. package/dist/core/cursors.d.ts +36 -0
  210. package/dist/core/cursors.d.ts.map +1 -0
  211. package/dist/core/cursors.js +90 -0
  212. package/dist/core/cursors.js.map +1 -0
  213. package/dist/core/dedup.d.ts +45 -0
  214. package/dist/core/dedup.d.ts.map +1 -0
  215. package/dist/core/dedup.js +111 -0
  216. package/dist/core/dedup.js.map +1 -0
  217. package/dist/core/entity-extract.d.ts +3 -0
  218. package/dist/core/entity-extract.d.ts.map +1 -0
  219. package/dist/core/entity-extract.js +54 -0
  220. package/dist/core/entity-extract.js.map +1 -0
  221. package/dist/core/helpers.d.ts +3 -0
  222. package/dist/core/helpers.d.ts.map +1 -0
  223. package/dist/core/helpers.js +10 -0
  224. package/dist/core/helpers.js.map +1 -0
  225. package/dist/core/identity-resolver.d.ts +21 -0
  226. package/dist/core/identity-resolver.d.ts.map +1 -0
  227. package/dist/core/identity-resolver.js +62 -0
  228. package/dist/core/identity-resolver.js.map +1 -0
  229. package/dist/core/pipeline-factory.d.ts +13 -0
  230. package/dist/core/pipeline-factory.d.ts.map +1 -0
  231. package/dist/core/pipeline-factory.js +32 -0
  232. package/dist/core/pipeline-factory.js.map +1 -0
  233. package/dist/core/pipeline.d.ts +61 -0
  234. package/dist/core/pipeline.d.ts.map +1 -0
  235. package/dist/core/pipeline.js +261 -0
  236. package/dist/core/pipeline.js.map +1 -0
  237. package/dist/core/schemas.d.ts +2470 -0
  238. package/dist/core/schemas.d.ts.map +1 -0
  239. package/dist/core/schemas.js +229 -0
  240. package/dist/core/schemas.js.map +1 -0
  241. package/dist/core/signal-scoring.d.ts +3 -0
  242. package/dist/core/signal-scoring.d.ts.map +1 -0
  243. package/dist/core/signal-scoring.js +124 -0
  244. package/dist/core/signal-scoring.js.map +1 -0
  245. package/dist/core/state.d.ts +22 -0
  246. package/dist/core/state.d.ts.map +1 -0
  247. package/dist/core/state.js +32 -0
  248. package/dist/core/state.js.map +1 -0
  249. package/dist/core/types.d.ts +231 -0
  250. package/dist/core/types.d.ts.map +1 -0
  251. package/dist/core/types.js +6 -0
  252. package/dist/core/types.js.map +1 -0
  253. package/dist/daemon/alerts.d.ts +12 -0
  254. package/dist/daemon/alerts.d.ts.map +1 -0
  255. package/dist/daemon/alerts.js +34 -0
  256. package/dist/daemon/alerts.js.map +1 -0
  257. package/dist/daemon/index.d.ts +6 -0
  258. package/dist/daemon/index.d.ts.map +1 -0
  259. package/dist/daemon/index.js +6 -0
  260. package/dist/daemon/index.js.map +1 -0
  261. package/dist/daemon/logger.d.ts +8 -0
  262. package/dist/daemon/logger.d.ts.map +1 -0
  263. package/dist/daemon/logger.js +35 -0
  264. package/dist/daemon/logger.js.map +1 -0
  265. package/dist/daemon/run-history.d.ts +29 -0
  266. package/dist/daemon/run-history.d.ts.map +1 -0
  267. package/dist/daemon/run-history.js +54 -0
  268. package/dist/daemon/run-history.js.map +1 -0
  269. package/dist/daemon/scheduler.d.ts +37 -0
  270. package/dist/daemon/scheduler.d.ts.map +1 -0
  271. package/dist/daemon/scheduler.js +142 -0
  272. package/dist/daemon/scheduler.js.map +1 -0
  273. package/dist/daemon/source-schedule.d.ts +25 -0
  274. package/dist/daemon/source-schedule.d.ts.map +1 -0
  275. package/dist/daemon/source-schedule.js +87 -0
  276. package/dist/daemon/source-schedule.js.map +1 -0
  277. package/dist/embedded-assets.generated.d.ts +4 -0
  278. package/dist/embedded-assets.generated.d.ts.map +1 -0
  279. package/dist/embedded-assets.generated.js +12 -0
  280. package/dist/embedded-assets.generated.js.map +1 -0
  281. package/dist/extractors/noise-filter.d.ts +30 -0
  282. package/dist/extractors/noise-filter.d.ts.map +1 -0
  283. package/dist/extractors/noise-filter.js +185 -0
  284. package/dist/extractors/noise-filter.js.map +1 -0
  285. package/dist/extractors/providers/anthropic.d.ts +13 -0
  286. package/dist/extractors/providers/anthropic.d.ts.map +1 -0
  287. package/dist/extractors/providers/anthropic.js +67 -0
  288. package/dist/extractors/providers/anthropic.js.map +1 -0
  289. package/dist/extractors/providers/index.d.ts +12 -0
  290. package/dist/extractors/providers/index.d.ts.map +1 -0
  291. package/dist/extractors/providers/index.js +41 -0
  292. package/dist/extractors/providers/index.js.map +1 -0
  293. package/dist/extractors/providers/mock.d.ts +14 -0
  294. package/dist/extractors/providers/mock.d.ts.map +1 -0
  295. package/dist/extractors/providers/mock.js +37 -0
  296. package/dist/extractors/providers/mock.js.map +1 -0
  297. package/dist/extractors/providers/openai.d.ts +15 -0
  298. package/dist/extractors/providers/openai.d.ts.map +1 -0
  299. package/dist/extractors/providers/openai.js +109 -0
  300. package/dist/extractors/providers/openai.js.map +1 -0
  301. package/dist/extractors/providers/types.d.ts +27 -0
  302. package/dist/extractors/providers/types.d.ts.map +1 -0
  303. package/dist/extractors/providers/types.js +6 -0
  304. package/dist/extractors/providers/types.js.map +1 -0
  305. package/dist/extractors/signal-extractor.d.ts +29 -0
  306. package/dist/extractors/signal-extractor.d.ts.map +1 -0
  307. package/dist/extractors/signal-extractor.js +279 -0
  308. package/dist/extractors/signal-extractor.js.map +1 -0
  309. package/dist/formatters/index.d.ts +3 -0
  310. package/dist/formatters/index.d.ts.map +1 -0
  311. package/dist/formatters/index.js +3 -0
  312. package/dist/formatters/index.js.map +1 -0
  313. package/dist/formatters/json.d.ts +6 -0
  314. package/dist/formatters/json.d.ts.map +1 -0
  315. package/dist/formatters/json.js +16 -0
  316. package/dist/formatters/json.js.map +1 -0
  317. package/dist/formatters/markdown.d.ts +6 -0
  318. package/dist/formatters/markdown.d.ts.map +1 -0
  319. package/dist/formatters/markdown.js +198 -0
  320. package/dist/formatters/markdown.js.map +1 -0
  321. package/dist/processors/privacy.d.ts +98 -0
  322. package/dist/processors/privacy.d.ts.map +1 -0
  323. package/dist/processors/privacy.js +271 -0
  324. package/dist/processors/privacy.js.map +1 -0
  325. package/dist/server/api.d.ts +35 -0
  326. package/dist/server/api.d.ts.map +1 -0
  327. package/dist/server/api.js +453 -0
  328. package/dist/server/api.js.map +1 -0
  329. package/dist/server/backfill-job.d.ts +36 -0
  330. package/dist/server/backfill-job.d.ts.map +1 -0
  331. package/dist/server/backfill-job.js +88 -0
  332. package/dist/server/backfill-job.js.map +1 -0
  333. package/dist/server/backfill-routes.d.ts +7 -0
  334. package/dist/server/backfill-routes.d.ts.map +1 -0
  335. package/dist/server/backfill-routes.js +123 -0
  336. package/dist/server/backfill-routes.js.map +1 -0
  337. package/dist/server/config-routes.d.ts +8 -0
  338. package/dist/server/config-routes.d.ts.map +1 -0
  339. package/dist/server/config-routes.js +114 -0
  340. package/dist/server/config-routes.js.map +1 -0
  341. package/dist/server/context.d.ts +13 -0
  342. package/dist/server/context.d.ts.map +1 -0
  343. package/dist/server/context.js +47 -0
  344. package/dist/server/context.js.map +1 -0
  345. package/dist/server/entity.d.ts +25 -0
  346. package/dist/server/entity.d.ts.map +1 -0
  347. package/dist/server/entity.js +34 -0
  348. package/dist/server/entity.js.map +1 -0
  349. package/dist/server/event-bus.d.ts +35 -0
  350. package/dist/server/event-bus.d.ts.map +1 -0
  351. package/dist/server/event-bus.js +4 -0
  352. package/dist/server/event-bus.js.map +1 -0
  353. package/dist/server/mcp.d.ts +126 -0
  354. package/dist/server/mcp.d.ts.map +1 -0
  355. package/dist/server/mcp.js +103 -0
  356. package/dist/server/mcp.js.map +1 -0
  357. package/dist/server/setup-server.d.ts +7 -0
  358. package/dist/server/setup-server.d.ts.map +1 -0
  359. package/dist/server/setup-server.js +52 -0
  360. package/dist/server/setup-server.js.map +1 -0
  361. package/dist/setup/assess-hardware.d.ts +34 -0
  362. package/dist/setup/assess-hardware.d.ts.map +1 -0
  363. package/dist/setup/assess-hardware.js +179 -0
  364. package/dist/setup/assess-hardware.js.map +1 -0
  365. package/dist/setup/connection-tests.d.ts +17 -0
  366. package/dist/setup/connection-tests.d.ts.map +1 -0
  367. package/dist/setup/connection-tests.js +67 -0
  368. package/dist/setup/connection-tests.js.map +1 -0
  369. package/dist/setup/detect-api-keys.d.ts +13 -0
  370. package/dist/setup/detect-api-keys.d.ts.map +1 -0
  371. package/dist/setup/detect-api-keys.js +41 -0
  372. package/dist/setup/detect-api-keys.js.map +1 -0
  373. package/dist/setup/detect-runtime.d.ts +14 -0
  374. package/dist/setup/detect-runtime.d.ts.map +1 -0
  375. package/dist/setup/detect-runtime.js +43 -0
  376. package/dist/setup/detect-runtime.js.map +1 -0
  377. package/dist/setup/detect-sources.d.ts +14 -0
  378. package/dist/setup/detect-sources.d.ts.map +1 -0
  379. package/dist/setup/detect-sources.js +75 -0
  380. package/dist/setup/detect-sources.js.map +1 -0
  381. package/dist/setup/generate-config.d.ts +5 -0
  382. package/dist/setup/generate-config.d.ts.map +1 -0
  383. package/dist/setup/generate-config.js +103 -0
  384. package/dist/setup/generate-config.js.map +1 -0
  385. package/dist/setup/index.d.ts +9 -0
  386. package/dist/setup/index.d.ts.map +1 -0
  387. package/dist/setup/index.js +9 -0
  388. package/dist/setup/index.js.map +1 -0
  389. package/dist/setup/init-wizard.d.ts +19 -0
  390. package/dist/setup/init-wizard.d.ts.map +1 -0
  391. package/dist/setup/init-wizard.js +501 -0
  392. package/dist/setup/init-wizard.js.map +1 -0
  393. package/dist/setup/terminal.d.ts +28 -0
  394. package/dist/setup/terminal.d.ts.map +1 -0
  395. package/dist/setup/terminal.js +258 -0
  396. package/dist/setup/terminal.js.map +1 -0
  397. package/dist/setup/validate-config.d.ts +26 -0
  398. package/dist/setup/validate-config.d.ts.map +1 -0
  399. package/dist/setup/validate-config.js +27 -0
  400. package/dist/setup/validate-config.js.map +1 -0
  401. package/dist/store/chunks.d.ts +19 -0
  402. package/dist/store/chunks.d.ts.map +1 -0
  403. package/dist/store/chunks.js +70 -0
  404. package/dist/store/chunks.js.map +1 -0
  405. package/dist/store/database.d.ts +24 -0
  406. package/dist/store/database.d.ts.map +1 -0
  407. package/dist/store/database.js +62 -0
  408. package/dist/store/database.js.map +1 -0
  409. package/dist/store/embedding.d.ts +23 -0
  410. package/dist/store/embedding.d.ts.map +1 -0
  411. package/dist/store/embedding.js +62 -0
  412. package/dist/store/embedding.js.map +1 -0
  413. package/dist/store/graph.d.ts +53 -0
  414. package/dist/store/graph.d.ts.map +1 -0
  415. package/dist/store/graph.js +186 -0
  416. package/dist/store/graph.js.map +1 -0
  417. package/dist/store/migrations/index.d.ts +9 -0
  418. package/dist/store/migrations/index.d.ts.map +1 -0
  419. package/dist/store/migrations/index.js +68 -0
  420. package/dist/store/migrations/index.js.map +1 -0
  421. package/dist/store/pages.d.ts +39 -0
  422. package/dist/store/pages.d.ts.map +1 -0
  423. package/dist/store/pages.js +150 -0
  424. package/dist/store/pages.js.map +1 -0
  425. package/dist/store/search.d.ts +37 -0
  426. package/dist/store/search.d.ts.map +1 -0
  427. package/dist/store/search.js +200 -0
  428. package/dist/store/search.js.map +1 -0
  429. package/dist/store/tags.d.ts +10 -0
  430. package/dist/store/tags.d.ts.map +1 -0
  431. package/dist/store/tags.js +31 -0
  432. package/dist/store/tags.js.map +1 -0
  433. package/dist/store/timeline.d.ts +26 -0
  434. package/dist/store/timeline.d.ts.map +1 -0
  435. package/dist/store/timeline.js +43 -0
  436. package/dist/store/timeline.js.map +1 -0
  437. package/dist/sync/obsidian.d.ts +136 -0
  438. package/dist/sync/obsidian.d.ts.map +1 -0
  439. package/dist/sync/obsidian.js +539 -0
  440. package/dist/sync/obsidian.js.map +1 -0
  441. package/package.json +84 -0
@@ -0,0 +1,29 @@
1
+ import type { Adapter, AdapterPushResult, ExtractionResult } from "../core/types.js";
2
+ export interface GBrainAdapterConfig {
3
+ output_dir: string;
4
+ }
5
+ export declare class GBrainAdapter implements Adapter {
6
+ id: string;
7
+ name: string;
8
+ description: string;
9
+ private config;
10
+ constructor(config: GBrainAdapterConfig);
11
+ healthCheck(): Promise<{
12
+ ok: boolean;
13
+ message: string;
14
+ }>;
15
+ push(results: ExtractionResult[]): Promise<AdapterPushResult>;
16
+ private writeEntity;
17
+ private writeDecision;
18
+ private writeTask;
19
+ private writeDiscovery;
20
+ private writeKnowledge;
21
+ private appendTimelineEntry;
22
+ private appendLink;
23
+ private parsePage;
24
+ private serializePage;
25
+ private createEntityPage;
26
+ private kebabCase;
27
+ private contentHash;
28
+ }
29
+ //# sourceMappingURL=gbrain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gbrain.d.ts","sourceRoot":"","sources":["../../src/adapters/gbrain.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EAIjB,gBAAgB,EAKjB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAqBD,qBAAa,aAAc,YAAW,OAAO;IAC3C,EAAE,SAAY;IACd,IAAI,SAAoB;IACxB,WAAW,SAAoD;IAE/D,OAAO,CAAC,MAAM,CAAsB;gBAExB,MAAM,EAAE,mBAAmB;IAIjC,WAAW,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAQxD,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAoErD,WAAW;YAoDX,aAAa;YAoFb,SAAS;YAgET,cAAc;YA2Ed,cAAc;YA6Id,mBAAmB;YA0DnB,UAAU;IAkDxB,OAAO,CAAC,SAAS;IAmDjB,OAAO,CAAC,aAAa;IA4BrB,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,WAAW;CAGpB"}
@@ -0,0 +1,622 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
+ import { dirname, join } from "node:path";
5
+ import { stringify as yamlStringify } from "yaml";
6
+ export class GBrainAdapter {
7
+ id = "gbrain";
8
+ name = "GBrain Adapter";
9
+ description = "Writes extraction results to GBrain page files";
10
+ config;
11
+ constructor(config) {
12
+ this.config = config;
13
+ }
14
+ async healthCheck() {
15
+ if (!existsSync(this.config.output_dir)) {
16
+ return { ok: false, message: `Output directory does not exist: ${this.config.output_dir}` };
17
+ }
18
+ return { ok: true, message: "GBrain adapter is ready" };
19
+ }
20
+ async push(results) {
21
+ const pushResult = {
22
+ written: 0,
23
+ skipped: 0,
24
+ errors: [],
25
+ };
26
+ for (const result of results) {
27
+ // Process Entities
28
+ for (const entity of result.entities) {
29
+ const writeResult = await this.writeEntity(entity, result.source.raw_hash);
30
+ pushResult.written += writeResult.written;
31
+ pushResult.skipped += writeResult.skipped;
32
+ pushResult.errors.push(...writeResult.errors);
33
+ }
34
+ // Process Decisions
35
+ for (const decision of result.decisions) {
36
+ const writeResult = await this.writeDecision(decision, result.source.raw_hash);
37
+ pushResult.written += writeResult.written;
38
+ pushResult.skipped += writeResult.skipped;
39
+ pushResult.errors.push(...writeResult.errors);
40
+ }
41
+ // Process Tasks
42
+ for (const task of result.tasks) {
43
+ const writeResult = await this.writeTask(task, result.source.raw_hash);
44
+ pushResult.written += writeResult.written;
45
+ pushResult.skipped += writeResult.skipped;
46
+ pushResult.errors.push(...writeResult.errors);
47
+ }
48
+ // Process Discoveries
49
+ for (const discovery of result.discoveries) {
50
+ const writeResult = await this.writeDiscovery(discovery, result.source.raw_hash);
51
+ pushResult.written += writeResult.written;
52
+ pushResult.skipped += writeResult.skipped;
53
+ pushResult.errors.push(...writeResult.errors);
54
+ }
55
+ // Process Timeline Entries
56
+ for (const entry of result.timeline) {
57
+ const writeResult = await this.appendTimelineEntry(entry, result.source.raw_hash);
58
+ pushResult.written += writeResult.written;
59
+ pushResult.skipped += writeResult.skipped;
60
+ pushResult.errors.push(...writeResult.errors);
61
+ }
62
+ // Process Links
63
+ for (const link of result.links) {
64
+ const writeResult = await this.appendLink(link, result.source.raw_hash);
65
+ pushResult.written += writeResult.written;
66
+ pushResult.skipped += writeResult.skipped;
67
+ pushResult.errors.push(...writeResult.errors);
68
+ }
69
+ // Process Knowledge
70
+ for (const knowledge of result.knowledge) {
71
+ const writeResult = await this.writeKnowledge(knowledge);
72
+ pushResult.written += writeResult.written;
73
+ pushResult.skipped += writeResult.skipped;
74
+ pushResult.errors.push(...writeResult.errors);
75
+ }
76
+ }
77
+ return pushResult;
78
+ }
79
+ async writeEntity(entity, _sourceHash) {
80
+ const result = { written: 0, skipped: 0, errors: [] };
81
+ try {
82
+ const filepath = join(this.config.output_dir, `${entity.slug}.md`);
83
+ const dirPath = dirname(filepath);
84
+ // Ensure directory exists
85
+ if (!existsSync(dirPath)) {
86
+ await mkdir(dirPath, { recursive: true });
87
+ }
88
+ let content;
89
+ if (existsSync(filepath)) {
90
+ // Merge with existing page
91
+ const existingContent = await readFile(filepath, "utf-8");
92
+ const parsed = this.parsePage(existingContent);
93
+ // Update frontmatter
94
+ parsed.frontmatter.updated_at = new Date().toISOString();
95
+ parsed.frontmatter.confidence = entity.confidence;
96
+ // Update context section
97
+ parsed.sections.set("Context", [entity.context]);
98
+ content = this.serializePage(parsed);
99
+ result.written += 1;
100
+ }
101
+ else {
102
+ // Create new page
103
+ const frontmatter = {
104
+ title: entity.name,
105
+ type: entity.type,
106
+ slug: entity.slug,
107
+ created_at: new Date().toISOString(),
108
+ confidence: entity.confidence,
109
+ };
110
+ content = this.createEntityPage(frontmatter, entity.context);
111
+ result.written += 1;
112
+ }
113
+ await writeFile(filepath, content, "utf-8");
114
+ }
115
+ catch (error) {
116
+ result.errors.push({
117
+ signal: `entity:${entity.slug}`,
118
+ reason: error instanceof Error ? error.message : String(error),
119
+ });
120
+ }
121
+ return result;
122
+ }
123
+ async writeDecision(decision, sourceHash) {
124
+ const result = { written: 0, skipped: 0, errors: [] };
125
+ try {
126
+ const slug = this.kebabCase(decision.summary);
127
+ const filepath = join(this.config.output_dir, "decisions", `${slug}.md`);
128
+ const dirPath = dirname(filepath);
129
+ if (!existsSync(dirPath)) {
130
+ await mkdir(dirPath, { recursive: true });
131
+ }
132
+ // Check if same decision already exists with same hash
133
+ if (existsSync(filepath)) {
134
+ const existingContent = await readFile(filepath, "utf-8");
135
+ if (existingContent.includes(`source_hash: ${sourceHash}`)) {
136
+ result.skipped += 1;
137
+ return result;
138
+ }
139
+ }
140
+ const frontmatter = {
141
+ title: decision.summary,
142
+ type: "decision",
143
+ slug: `decisions/${slug}`,
144
+ date: decision.date,
145
+ entities: decision.entities,
146
+ created_at: new Date().toISOString(),
147
+ };
148
+ const parts = [];
149
+ // Frontmatter
150
+ parts.push("---");
151
+ parts.push(`title: ${frontmatter.title}`);
152
+ parts.push(`type: ${frontmatter.type}`);
153
+ parts.push(`slug: ${frontmatter.slug}`);
154
+ parts.push(`date: ${frontmatter.date}`);
155
+ if (decision.entities.length > 0) {
156
+ parts.push("entities:");
157
+ for (const entity of decision.entities) {
158
+ parts.push(` - ${entity}`);
159
+ }
160
+ }
161
+ parts.push(`confidence: ${decision.confidence}`);
162
+ parts.push(`source_hash: ${sourceHash}`);
163
+ parts.push(`created_at: ${frontmatter.created_at}`);
164
+ parts.push("---");
165
+ parts.push("");
166
+ // Summary
167
+ parts.push(`# ${decision.summary}`);
168
+ parts.push("");
169
+ // Reasoning
170
+ if (decision.reasoning) {
171
+ parts.push("## Reasoning");
172
+ parts.push("");
173
+ parts.push(decision.reasoning);
174
+ parts.push("");
175
+ }
176
+ // Alternatives
177
+ if (decision.alternatives && decision.alternatives.length > 0) {
178
+ parts.push("## Alternatives");
179
+ parts.push("");
180
+ for (const alt of decision.alternatives) {
181
+ parts.push(`- ${alt}`);
182
+ }
183
+ parts.push("");
184
+ }
185
+ await writeFile(filepath, parts.join("\n"), "utf-8");
186
+ result.written += 1;
187
+ }
188
+ catch (error) {
189
+ result.errors.push({
190
+ signal: `decision:${decision.summary}`,
191
+ reason: error instanceof Error ? error.message : String(error),
192
+ });
193
+ }
194
+ return result;
195
+ }
196
+ async writeTask(task, sourceHash) {
197
+ const result = { written: 0, skipped: 0, errors: [] };
198
+ try {
199
+ const slug = this.kebabCase(task.title);
200
+ const filepath = join(this.config.output_dir, "tasks", `${slug}.md`);
201
+ const dirPath = dirname(filepath);
202
+ if (!existsSync(dirPath)) {
203
+ await mkdir(dirPath, { recursive: true });
204
+ }
205
+ // Check for duplicate
206
+ if (existsSync(filepath)) {
207
+ const existingContent = await readFile(filepath, "utf-8");
208
+ if (existingContent.includes(`source_hash: ${sourceHash}`)) {
209
+ result.skipped += 1;
210
+ return result;
211
+ }
212
+ }
213
+ const frontmatter = {
214
+ title: task.title,
215
+ type: "task",
216
+ slug: `tasks/${slug}`,
217
+ status: task.status,
218
+ owner: task.owner,
219
+ project: task.project,
220
+ created_at: new Date().toISOString(),
221
+ };
222
+ const parts = [];
223
+ // Frontmatter
224
+ parts.push("---");
225
+ parts.push(`title: ${frontmatter.title}`);
226
+ parts.push(`type: ${frontmatter.type}`);
227
+ parts.push(`slug: ${frontmatter.slug}`);
228
+ parts.push(`status: ${frontmatter.status}`);
229
+ if (task.owner)
230
+ parts.push(`owner: ${task.owner}`);
231
+ if (task.project)
232
+ parts.push(`project: ${task.project}`);
233
+ if (task.due_date)
234
+ parts.push(`due_date: ${task.due_date}`);
235
+ parts.push(`confidence: ${task.confidence}`);
236
+ parts.push(`source_hash: ${sourceHash}`);
237
+ parts.push(`created_at: ${frontmatter.created_at}`);
238
+ parts.push("---");
239
+ parts.push("");
240
+ // Title
241
+ parts.push(`# ${task.title}`);
242
+ parts.push("");
243
+ await writeFile(filepath, parts.join("\n"), "utf-8");
244
+ result.written += 1;
245
+ }
246
+ catch (error) {
247
+ result.errors.push({
248
+ signal: `task:${task.title}`,
249
+ reason: error instanceof Error ? error.message : String(error),
250
+ });
251
+ }
252
+ return result;
253
+ }
254
+ async writeDiscovery(discovery, sourceHash) {
255
+ const result = { written: 0, skipped: 0, errors: [] };
256
+ try {
257
+ const slug = this.kebabCase(discovery.summary);
258
+ const filepath = join(this.config.output_dir, "discoveries", `${slug}.md`);
259
+ const dirPath = dirname(filepath);
260
+ if (!existsSync(dirPath)) {
261
+ await mkdir(dirPath, { recursive: true });
262
+ }
263
+ // Check for duplicate
264
+ if (existsSync(filepath)) {
265
+ const existingContent = await readFile(filepath, "utf-8");
266
+ if (existingContent.includes(`source_hash: ${sourceHash}`)) {
267
+ result.skipped += 1;
268
+ return result;
269
+ }
270
+ }
271
+ const frontmatter = {
272
+ title: discovery.summary,
273
+ type: `discovery-${discovery.type}`,
274
+ slug: `discoveries/${slug}`,
275
+ entities: discovery.entities,
276
+ created_at: new Date().toISOString(),
277
+ };
278
+ const parts = [];
279
+ // Frontmatter
280
+ parts.push("---");
281
+ parts.push(`title: ${frontmatter.title}`);
282
+ parts.push(`type: ${frontmatter.type}`);
283
+ parts.push(`slug: ${frontmatter.slug}`);
284
+ if (discovery.entities.length > 0) {
285
+ parts.push("entities:");
286
+ for (const entity of discovery.entities) {
287
+ parts.push(` - ${entity}`);
288
+ }
289
+ }
290
+ parts.push(`confidence: ${discovery.confidence}`);
291
+ parts.push(`source_hash: ${sourceHash}`);
292
+ parts.push(`created_at: ${frontmatter.created_at}`);
293
+ parts.push("---");
294
+ parts.push("");
295
+ // Summary
296
+ parts.push(`# ${discovery.summary}`);
297
+ parts.push("");
298
+ // Detail
299
+ if (discovery.detail) {
300
+ parts.push("## Detail");
301
+ parts.push("");
302
+ parts.push(discovery.detail);
303
+ parts.push("");
304
+ }
305
+ await writeFile(filepath, parts.join("\n"), "utf-8");
306
+ result.written += 1;
307
+ }
308
+ catch (error) {
309
+ result.errors.push({
310
+ signal: `discovery:${discovery.summary}`,
311
+ reason: error instanceof Error ? error.message : String(error),
312
+ });
313
+ }
314
+ return result;
315
+ }
316
+ async writeKnowledge(knowledge) {
317
+ const result = { written: 0, skipped: 0, errors: [] };
318
+ try {
319
+ // Skip speculative knowledge
320
+ if (knowledge.confidence === "speculative") {
321
+ console.warn(`Skipping speculative knowledge: ${knowledge.topic}/${knowledge.content.slice(0, 30)}`);
322
+ result.skipped += 1;
323
+ return result;
324
+ }
325
+ // Resolve source_hash (fallback to content hash if empty)
326
+ const sourceHash = knowledge.source.raw_hash || this.contentHash(knowledge.content);
327
+ // Build path: knowledge/{topic}/{content-hash-12}-{content-slug}.md
328
+ const contentHash12 = this.contentHash(knowledge.content).slice(0, 12);
329
+ const contentSlug = this.kebabCase(knowledge.content.slice(0, 50));
330
+ const filename = `${contentHash12}-${contentSlug}.md`;
331
+ const filepath = join(this.config.output_dir, "knowledge", knowledge.topic, filename);
332
+ const dirPath = dirname(filepath);
333
+ if (!existsSync(dirPath)) {
334
+ await mkdir(dirPath, { recursive: true });
335
+ }
336
+ if (existsSync(filepath)) {
337
+ const existingContent = await readFile(filepath, "utf-8");
338
+ // Case 2: Same source_hash → skip (exact duplicate)
339
+ if (existingContent.includes(`source_hash: ${sourceHash}`) ||
340
+ existingContent.includes(`source_hash: "${sourceHash}"`) ||
341
+ existingContent.includes(`source_hash: '${sourceHash}'`)) {
342
+ result.skipped += 1;
343
+ return result;
344
+ }
345
+ // Case 3: Different source_hash → append provenance
346
+ const provenanceEntry = [
347
+ "",
348
+ `> ${knowledge.source.quote}`,
349
+ "",
350
+ `**Platform:** ${knowledge.source.platform} | **Channel:** ${knowledge.source.channel} | **Time:** ${knowledge.source.timestamp}`,
351
+ "",
352
+ ].join("\n");
353
+ // Update updated_at in frontmatter
354
+ let updatedContent = existingContent.replace(/^(---\n[\s\S]*?)(---)/m, (_match, front, closing) => {
355
+ const now = new Date().toISOString();
356
+ if (front.includes("updated_at:")) {
357
+ return front.replace(/updated_at:.*/, `updated_at: "${now}"`) + closing;
358
+ }
359
+ return `${front}updated_at: "${now}"\n${closing}`;
360
+ });
361
+ // Insert before "## Related Entities" section
362
+ const relatedIdx = updatedContent.indexOf("## Related Entities");
363
+ if (relatedIdx !== -1) {
364
+ updatedContent =
365
+ updatedContent.slice(0, relatedIdx) +
366
+ provenanceEntry +
367
+ updatedContent.slice(relatedIdx);
368
+ }
369
+ else {
370
+ updatedContent = `${updatedContent}\n${provenanceEntry}`;
371
+ }
372
+ await writeFile(filepath, updatedContent, "utf-8");
373
+ result.written += 1;
374
+ return result;
375
+ }
376
+ // Case 1: New file — create with YAML serializer
377
+ const frontmatter = {
378
+ title: knowledge.content.slice(0, 80),
379
+ type: "knowledge",
380
+ slug: `knowledge/${knowledge.topic}/${contentHash12}-${contentSlug}`,
381
+ topic: knowledge.topic,
382
+ source_type: knowledge.source_type,
383
+ confidence: knowledge.confidence,
384
+ source_hash: sourceHash,
385
+ source_platform: knowledge.source.platform,
386
+ source_channel: knowledge.source.channel,
387
+ source_timestamp: knowledge.source.timestamp,
388
+ created_at: new Date().toISOString(),
389
+ };
390
+ if (knowledge.valid_at)
391
+ frontmatter.valid_at = knowledge.valid_at;
392
+ if (knowledge.invalid_at)
393
+ frontmatter.invalid_at = knowledge.invalid_at;
394
+ const parts = [];
395
+ // YAML serializer for safe frontmatter
396
+ parts.push("---");
397
+ parts.push(yamlStringify(frontmatter).trimEnd());
398
+ parts.push("---");
399
+ parts.push("");
400
+ // Content
401
+ parts.push(`# ${knowledge.content}`);
402
+ parts.push("");
403
+ // Provenance
404
+ parts.push("## Provenance");
405
+ parts.push("");
406
+ parts.push(`> ${knowledge.source.quote}`);
407
+ parts.push("");
408
+ parts.push(`**Platform:** ${knowledge.source.platform} | **Channel:** ${knowledge.source.channel} | **Time:** ${knowledge.source.timestamp}`);
409
+ parts.push("");
410
+ // Related Entities
411
+ parts.push("## Related Entities");
412
+ parts.push("");
413
+ if (knowledge.related_entities.length > 0) {
414
+ for (const entity of knowledge.related_entities) {
415
+ parts.push(`- ${entity}`);
416
+ }
417
+ }
418
+ else {
419
+ parts.push("- (none)");
420
+ }
421
+ parts.push("");
422
+ await writeFile(filepath, parts.join("\n"), "utf-8");
423
+ result.written += 1;
424
+ }
425
+ catch (error) {
426
+ result.errors.push({
427
+ signal: `knowledge:${knowledge.topic}/${knowledge.content.slice(0, 30)}`,
428
+ reason: error instanceof Error ? error.message : String(error),
429
+ });
430
+ }
431
+ return result;
432
+ }
433
+ async appendTimelineEntry(entry, sourceHash) {
434
+ const result = { written: 0, skipped: 0, errors: [] };
435
+ // Append timeline entry to all related entity pages
436
+ for (const entitySlug of entry.entities) {
437
+ try {
438
+ const filepath = join(this.config.output_dir, `${entitySlug}.md`);
439
+ if (!existsSync(filepath)) {
440
+ // Entity page doesn't exist yet, skip
441
+ continue;
442
+ }
443
+ const existingContent = await readFile(filepath, "utf-8");
444
+ // Check for duplicate
445
+ if (existingContent.includes(`source_hash: ${sourceHash}`) &&
446
+ existingContent.includes(entry.summary)) {
447
+ result.skipped += 1;
448
+ continue;
449
+ }
450
+ const parsed = this.parsePage(existingContent);
451
+ // Get or create Timeline section
452
+ const timelineLines = parsed.sections.get("Timeline") || [];
453
+ // Add new entry
454
+ timelineLines.push(`### ${entry.date}`);
455
+ timelineLines.push("");
456
+ timelineLines.push(entry.summary);
457
+ timelineLines.push("");
458
+ timelineLines.push(`**Confidence:** ${entry.confidence}`);
459
+ timelineLines.push(`**Source Hash:** ${sourceHash}`);
460
+ timelineLines.push("");
461
+ parsed.sections.set("Timeline", timelineLines);
462
+ const newContent = this.serializePage(parsed);
463
+ await writeFile(filepath, newContent, "utf-8");
464
+ result.written += 1;
465
+ }
466
+ catch (error) {
467
+ result.errors.push({
468
+ signal: `timeline:${entitySlug}`,
469
+ reason: error instanceof Error ? error.message : String(error),
470
+ });
471
+ }
472
+ }
473
+ return result;
474
+ }
475
+ async appendLink(link, sourceHash) {
476
+ const result = { written: 0, skipped: 0, errors: [] };
477
+ try {
478
+ const filepath = join(this.config.output_dir, `${link.from}.md`);
479
+ if (!existsSync(filepath)) {
480
+ // From entity page doesn't exist yet, skip
481
+ return result;
482
+ }
483
+ const existingContent = await readFile(filepath, "utf-8");
484
+ // Check for duplicate
485
+ if (existingContent.includes(`${link.type}: ${link.to}`) &&
486
+ existingContent.includes(`source_hash: ${sourceHash}`)) {
487
+ result.skipped += 1;
488
+ return result;
489
+ }
490
+ const parsed = this.parsePage(existingContent);
491
+ // Get or create Links section
492
+ const linksLines = parsed.sections.get("Links") || [];
493
+ // Add new link
494
+ linksLines.push(`- **${link.type}**: ${link.to}`);
495
+ linksLines.push(` - Context: ${link.context}`);
496
+ linksLines.push(` - Confidence: ${link.confidence}`);
497
+ linksLines.push(` - Source Hash: ${sourceHash}`);
498
+ linksLines.push("");
499
+ parsed.sections.set("Links", linksLines);
500
+ const newContent = this.serializePage(parsed);
501
+ await writeFile(filepath, newContent, "utf-8");
502
+ result.written += 1;
503
+ }
504
+ catch (error) {
505
+ result.errors.push({
506
+ signal: `link:${link.from}-${link.to}`,
507
+ reason: error instanceof Error ? error.message : String(error),
508
+ });
509
+ }
510
+ return result;
511
+ }
512
+ parsePage(content) {
513
+ const lines = content.split("\n");
514
+ const frontmatter = {};
515
+ const sections = new Map();
516
+ let inFrontmatter = false;
517
+ let currentSection = "";
518
+ let currentSectionLines = [];
519
+ for (const line of lines) {
520
+ if (line.trim() === "---") {
521
+ if (!inFrontmatter) {
522
+ inFrontmatter = true;
523
+ }
524
+ else {
525
+ inFrontmatter = false;
526
+ }
527
+ continue;
528
+ }
529
+ if (inFrontmatter) {
530
+ // Parse frontmatter
531
+ const match = line.match(/^(\w+):\s*(.+)$/);
532
+ if (match) {
533
+ const [, key, value] = match;
534
+ frontmatter[key] = value;
535
+ }
536
+ }
537
+ else if (line.startsWith("## ")) {
538
+ // Save previous section
539
+ if (currentSection) {
540
+ sections.set(currentSection, currentSectionLines);
541
+ }
542
+ // Start new section
543
+ currentSection = line.substring(3).trim();
544
+ currentSectionLines = [];
545
+ }
546
+ else if (currentSection) {
547
+ currentSectionLines.push(line);
548
+ }
549
+ }
550
+ // Save last section
551
+ if (currentSection) {
552
+ sections.set(currentSection, currentSectionLines);
553
+ }
554
+ return {
555
+ frontmatter: frontmatter,
556
+ sections,
557
+ };
558
+ }
559
+ serializePage(parsed) {
560
+ const parts = [];
561
+ // Frontmatter
562
+ parts.push("---");
563
+ for (const [key, value] of Object.entries(parsed.frontmatter)) {
564
+ if (Array.isArray(value)) {
565
+ parts.push(`${key}:`);
566
+ for (const item of value) {
567
+ parts.push(` - ${item}`);
568
+ }
569
+ }
570
+ else {
571
+ parts.push(`${key}: ${value}`);
572
+ }
573
+ }
574
+ parts.push("---");
575
+ parts.push("");
576
+ // Sections
577
+ for (const [sectionName, sectionLines] of parsed.sections.entries()) {
578
+ parts.push(`## ${sectionName}`);
579
+ parts.push("");
580
+ parts.push(...sectionLines);
581
+ }
582
+ return parts.join("\n");
583
+ }
584
+ createEntityPage(frontmatter, context) {
585
+ const parts = [];
586
+ // Frontmatter
587
+ parts.push("---");
588
+ parts.push(`title: ${frontmatter.title}`);
589
+ parts.push(`type: ${frontmatter.type}`);
590
+ parts.push(`slug: ${frontmatter.slug}`);
591
+ parts.push(`created_at: ${frontmatter.created_at}`);
592
+ parts.push(`confidence: ${frontmatter.confidence}`);
593
+ parts.push("---");
594
+ parts.push("");
595
+ // Context section
596
+ parts.push("## Context");
597
+ parts.push("");
598
+ parts.push(context);
599
+ parts.push("");
600
+ // Timeline section (empty)
601
+ parts.push("## Timeline");
602
+ parts.push("");
603
+ // Links section (empty)
604
+ parts.push("## Links");
605
+ parts.push("");
606
+ return parts.join("\n");
607
+ }
608
+ kebabCase(str) {
609
+ const ascii = str
610
+ .toLowerCase()
611
+ .replace(/[^a-z0-9]+/g, "-")
612
+ .replace(/^-+|-+$/g, "");
613
+ if (ascii.length >= 3)
614
+ return ascii;
615
+ const hash = createHash("sha256").update(str).digest("hex").slice(0, 12);
616
+ return ascii ? `${ascii}-${hash}` : hash;
617
+ }
618
+ contentHash(content) {
619
+ return createHash("sha256").update(content).digest("hex");
620
+ }
621
+ }
622
+ //# sourceMappingURL=gbrain.js.map