@remnic/core 1.0.1 → 1.0.3

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 (347) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -0
  3. package/dist/access-cli.d.ts +13 -3
  4. package/dist/access-cli.js +90 -75
  5. package/dist/access-cli.js.map +1 -1
  6. package/dist/access-http.d.ts +10 -3
  7. package/dist/access-http.js +25 -18
  8. package/dist/access-mcp.d.ts +30 -3
  9. package/dist/access-mcp.js +16 -1
  10. package/dist/access-schema.d.ts +46 -46
  11. package/dist/access-schema.js +1 -1
  12. package/dist/access-service.d.ts +65 -4
  13. package/dist/access-service.js +21 -15
  14. package/dist/active-memory-bridge.d.ts +66 -0
  15. package/dist/active-memory-bridge.js +11 -0
  16. package/dist/active-recall.d.ts +96 -0
  17. package/dist/active-recall.js +308 -0
  18. package/dist/active-recall.js.map +1 -0
  19. package/dist/behavior-learner.js +1 -1
  20. package/dist/bootstrap.d.ts +6 -3
  21. package/dist/bootstrap.js +2 -2
  22. package/dist/boxes.js +2 -2
  23. package/dist/briefing.d.ts +169 -0
  24. package/dist/briefing.js +52 -0
  25. package/dist/briefing.js.map +1 -0
  26. package/dist/buffer.d.ts +19 -5
  27. package/dist/buffer.js +2 -2
  28. package/dist/calibration.js +6 -6
  29. package/dist/causal-behavior.js +5 -5
  30. package/dist/causal-chain.js +3 -3
  31. package/dist/causal-consolidation.d.ts +22 -2
  32. package/dist/causal-consolidation.js +36 -9
  33. package/dist/causal-consolidation.js.map +1 -1
  34. package/dist/causal-retrieval.js +6 -6
  35. package/dist/causal-trajectory-graph.js +1 -1
  36. package/dist/causal-trajectory.d.ts +14 -1
  37. package/dist/causal-trajectory.js +5 -1
  38. package/dist/{chunk-KWBU5S5U.js → chunk-2ODBA7MQ.js} +9 -3
  39. package/dist/chunk-2ODBA7MQ.js.map +1 -0
  40. package/dist/{chunk-6UJQNRIO.js → chunk-2VFW5K5U.js} +93 -36
  41. package/dist/chunk-2VFW5K5U.js.map +1 -0
  42. package/dist/chunk-3PG3H5TD.js +7 -0
  43. package/dist/chunk-3PG3H5TD.js.map +1 -0
  44. package/dist/{chunk-NTTLPF7F.js → chunk-3QFQGRHO.js} +5 -5
  45. package/dist/chunk-4DJQYKMN.js +187 -0
  46. package/dist/chunk-4DJQYKMN.js.map +1 -0
  47. package/dist/chunk-4KAN3GZ3.js +225 -0
  48. package/dist/chunk-4KAN3GZ3.js.map +1 -0
  49. package/dist/{chunk-ORZMT74A.js → chunk-4NRAJUDS.js} +11 -1
  50. package/dist/chunk-4NRAJUDS.js.map +1 -0
  51. package/dist/{chunk-B7LOFDVE.js → chunk-4WMCPJWX.js} +8 -3
  52. package/dist/chunk-4WMCPJWX.js.map +1 -0
  53. package/dist/{chunk-G3AG3KZN.js → chunk-5IZL4DCV.js} +2 -2
  54. package/dist/{chunk-BRK4ODMI.js → chunk-5NPGSAVB.js} +2 -2
  55. package/dist/chunk-6MKAMLQL.js +16 -0
  56. package/dist/chunk-6MKAMLQL.js.map +1 -0
  57. package/dist/{chunk-ESSMF2FR.js → chunk-6PFRXT4K.js} +15 -6
  58. package/dist/chunk-6PFRXT4K.js.map +1 -0
  59. package/dist/chunk-6ZH4TU6I.js +245 -0
  60. package/dist/chunk-6ZH4TU6I.js.map +1 -0
  61. package/dist/{chunk-V4YC4LUK.js → chunk-74JR4N5J.js} +175 -63
  62. package/dist/chunk-74JR4N5J.js.map +1 -0
  63. package/dist/{chunk-L5RPWGFK.js → chunk-7DHTMOND.js} +2 -2
  64. package/dist/{chunk-TVVVQQAK.js → chunk-7PA4OZEU.js} +53 -11
  65. package/dist/chunk-7PA4OZEU.js.map +1 -0
  66. package/dist/{chunk-Q6FETXJA.js → chunk-7SEAZFFB.js} +2 -2
  67. package/dist/chunk-ALXMCZEU.js +332 -0
  68. package/dist/chunk-ALXMCZEU.js.map +1 -0
  69. package/dist/{chunk-QANCTXQF.js → chunk-AYPYCLR7.js} +3 -3
  70. package/dist/{chunk-WWIQTB2Y.js → chunk-BKQJBXXX.js} +9 -2
  71. package/dist/chunk-BKQJBXXX.js.map +1 -0
  72. package/dist/{chunk-LP47L3ZX.js → chunk-BTY5RRRF.js} +7 -7
  73. package/dist/{chunk-SCHEKPYH.js → chunk-C2EFFULQ.js} +1 -1
  74. package/dist/{chunk-GJR6D6KC.js → chunk-D654IBA6.js} +2 -2
  75. package/dist/{chunk-UV2FO7J4.js → chunk-E6K4NIEU.js} +2 -2
  76. package/dist/{chunk-T4WRIV2C.js → chunk-EABGC2TL.js} +2 -2
  77. package/dist/chunk-ECKDIK5F.js +813 -0
  78. package/dist/chunk-ECKDIK5F.js.map +1 -0
  79. package/dist/chunk-EJI5XIBB.js +232 -0
  80. package/dist/chunk-EJI5XIBB.js.map +1 -0
  81. package/dist/{chunk-ONRU4L2N.js → chunk-FEMOX5AD.js} +2 -2
  82. package/dist/{chunk-IFFFR3MR.js → chunk-FSFEQI74.js} +3 -3
  83. package/dist/chunk-G4SK7DSQ.js +121 -0
  84. package/dist/chunk-G4SK7DSQ.js.map +1 -0
  85. package/dist/{chunk-UIYZ5T3I.js → chunk-GJQPH5G3.js} +8 -8
  86. package/dist/{chunk-2PO5ZRKV.js → chunk-GZCUW5IC.js} +16 -3
  87. package/dist/chunk-GZCUW5IC.js.map +1 -0
  88. package/dist/{chunk-IZME7KW2.js → chunk-HITJFT7E.js} +24 -10
  89. package/dist/{chunk-IZME7KW2.js.map → chunk-HITJFT7E.js.map} +1 -1
  90. package/dist/chunk-IQT3XTKW.js +121 -0
  91. package/dist/chunk-IQT3XTKW.js.map +1 -0
  92. package/dist/{chunk-BDFZXRSO.js → chunk-J4IYOZZ5.js} +15 -2
  93. package/dist/chunk-J4IYOZZ5.js.map +1 -0
  94. package/dist/{chunk-ZKYI7UVO.js → chunk-JR4ZC3G4.js} +2 -2
  95. package/dist/{chunk-UCYSTFZR.js → chunk-JRNQ3RNA.js} +2 -2
  96. package/dist/{chunk-UYSKNO6E.js → chunk-JROGC36Y.js} +15 -4
  97. package/dist/chunk-JROGC36Y.js.map +1 -0
  98. package/dist/{chunk-GPGBSNKM.js → chunk-K4FLSOR5.js} +2 -2
  99. package/dist/{chunk-M5ZBBBJI.js → chunk-KEG4GNGI.js} +2 -2
  100. package/dist/chunk-KVE7R4CG.js +320 -0
  101. package/dist/chunk-KVE7R4CG.js.map +1 -0
  102. package/dist/{chunk-L7WO3MZ4.js → chunk-KWP7T3DP.js} +2 -2
  103. package/dist/chunk-LAYN4LDC.js +267 -0
  104. package/dist/chunk-LAYN4LDC.js.map +1 -0
  105. package/dist/{chunk-PGK3VUHN.js → chunk-MTLYEMJB.js} +3 -2
  106. package/dist/chunk-MTLYEMJB.js.map +1 -0
  107. package/dist/{chunk-J47FNDR7.js → chunk-MYQWXITD.js} +7 -7
  108. package/dist/{chunk-YNI4S5WT.js → chunk-N53K2EXC.js} +2 -2
  109. package/dist/{chunk-763GUIOU.js → chunk-NBNN5GOB.js} +2 -2
  110. package/dist/{chunk-CXWFUJR2.js → chunk-NSB3WSYS.js} +125 -6
  111. package/dist/chunk-NSB3WSYS.js.map +1 -0
  112. package/dist/{chunk-KL4CP4SB.js → chunk-O5ETUNBT.js} +17 -5
  113. package/dist/chunk-O5ETUNBT.js.map +1 -0
  114. package/dist/{chunk-OOSWAUYB.js → chunk-ODWDQNRE.js} +2 -2
  115. package/dist/{chunk-ISY75RLM.js → chunk-OJFGVJS6.js} +288 -7
  116. package/dist/chunk-OJFGVJS6.js.map +1 -0
  117. package/dist/{chunk-HLBYLYRD.js → chunk-PAORGQRI.js} +70 -13
  118. package/dist/chunk-PAORGQRI.js.map +1 -0
  119. package/dist/{chunk-ZJLY4QSU.js → chunk-PMB3WGDL.js} +69 -6
  120. package/dist/chunk-PMB3WGDL.js.map +1 -0
  121. package/dist/{chunk-J3BT33K7.js → chunk-POBPGDWI.js} +5 -5
  122. package/dist/{chunk-QWUUMMIK.js → chunk-POMSFKTB.js} +1351 -76
  123. package/dist/chunk-POMSFKTB.js.map +1 -0
  124. package/dist/{chunk-OTAVQCSF.js → chunk-PYXS46O7.js} +2 -2
  125. package/dist/chunk-QDW3E4RD.js +108 -0
  126. package/dist/chunk-QDW3E4RD.js.map +1 -0
  127. package/dist/{chunk-YNCQ7E4M.js → chunk-QDYXG4CS.js} +4 -3
  128. package/dist/chunk-QDYXG4CS.js.map +1 -0
  129. package/dist/{chunk-XUHI52HK.js → chunk-QKAH5B6E.js} +4 -4
  130. package/dist/{chunk-HLXVTBF3.js → chunk-QNJMBKFK.js} +3 -2
  131. package/dist/chunk-QNJMBKFK.js.map +1 -0
  132. package/dist/chunk-RCICHSHL.js +789 -0
  133. package/dist/chunk-RCICHSHL.js.map +1 -0
  134. package/dist/{chunk-HG2NKWR2.js → chunk-S4LX5EBI.js} +2 -2
  135. package/dist/{chunk-4A24LIM2.js → chunk-S75M5ZRK.js} +2 -2
  136. package/dist/{chunk-QCCCQT3O.js → chunk-TBBDFYXW.js} +2 -2
  137. package/dist/chunk-TBBDFYXW.js.map +1 -0
  138. package/dist/{chunk-U4PV25RD.js → chunk-U2IQTSBY.js} +1 -1
  139. package/dist/chunk-U2IQTSBY.js.map +1 -0
  140. package/dist/chunk-U66YHYC7.js +31 -0
  141. package/dist/chunk-U66YHYC7.js.map +1 -0
  142. package/dist/{chunk-MWGVGUIS.js → chunk-UEYA6UC7.js} +36 -4
  143. package/dist/chunk-UEYA6UC7.js.map +1 -0
  144. package/dist/{chunk-MDDAA2AO.js → chunk-UPMD5XND.js} +2 -2
  145. package/dist/{chunk-M5KEYE5E.js → chunk-URB2WSKZ.js} +2 -2
  146. package/dist/chunk-UVJFDP7P.js +202 -0
  147. package/dist/chunk-UVJFDP7P.js.map +1 -0
  148. package/dist/{chunk-QY2BHY5O.js → chunk-V7XCAHIB.js} +265 -25
  149. package/dist/chunk-V7XCAHIB.js.map +1 -0
  150. package/dist/chunk-W6SL7OFG.js +180 -0
  151. package/dist/chunk-W6SL7OFG.js.map +1 -0
  152. package/dist/{chunk-QDOSNLB4.js → chunk-X4WESCKA.js} +17 -15
  153. package/dist/chunk-X4WESCKA.js.map +1 -0
  154. package/dist/{chunk-OTFNI3OO.js → chunk-XMGSSBFX.js} +1738 -383
  155. package/dist/chunk-XMGSSBFX.js.map +1 -0
  156. package/dist/chunk-YDBIWGNI.js +298 -0
  157. package/dist/chunk-YDBIWGNI.js.map +1 -0
  158. package/dist/chunk-YFYL2SIJ.js +7857 -0
  159. package/dist/chunk-YFYL2SIJ.js.map +1 -0
  160. package/dist/chunking.js +1 -1
  161. package/dist/citations.d.ts +67 -0
  162. package/dist/citations.js +13 -0
  163. package/dist/citations.js.map +1 -0
  164. package/dist/cli-DwIBnp2g.d.ts +1240 -0
  165. package/dist/cli.d.ts +31 -1147
  166. package/dist/cli.js +149 -7092
  167. package/dist/cli.js.map +1 -1
  168. package/dist/codex-materialize-CQlLTzke.d.ts +139 -0
  169. package/dist/codex-thread-key.d.ts +3 -0
  170. package/dist/codex-thread-key.js +7 -0
  171. package/dist/codex-thread-key.js.map +1 -0
  172. package/dist/config.js +3 -2
  173. package/dist/connectors/codex/instructions.md +160 -0
  174. package/dist/connectors/codex/resources/namespace-cheatsheet.md +48 -0
  175. package/dist/day-summary.d.ts +7 -2
  176. package/dist/day-summary.js +5 -2
  177. package/dist/embedding-fallback.d.ts +96 -2
  178. package/dist/embedding-fallback.js +6 -4
  179. package/dist/{engine-2A6J4XEX.js → engine-X7X3AAG3.js} +10 -7
  180. package/dist/engine-X7X3AAG3.js.map +1 -0
  181. package/dist/entity-retrieval.d.ts +3 -2
  182. package/dist/entity-retrieval.js +10 -7
  183. package/dist/entity-schema.d.ts +11 -0
  184. package/dist/entity-schema.js +19 -0
  185. package/dist/entity-schema.js.map +1 -0
  186. package/dist/explicit-capture.d.ts +6 -3
  187. package/dist/explicit-capture.js +2 -2
  188. package/dist/extraction-judge.d.ts +66 -0
  189. package/dist/extraction-judge.js +18 -0
  190. package/dist/extraction-judge.js.map +1 -0
  191. package/dist/extraction.d.ts +1 -0
  192. package/dist/extraction.js +12 -10
  193. package/dist/fallback-llm.js +4 -4
  194. package/dist/graph.js +1 -1
  195. package/dist/importance.d.ts +11 -1
  196. package/dist/importance.js +3 -1
  197. package/dist/index.d.ts +1140 -8
  198. package/dist/index.js +3350 -333
  199. package/dist/index.js.map +1 -1
  200. package/dist/intent.d.ts +2 -1
  201. package/dist/intent.js +3 -1
  202. package/dist/lifecycle.js +1 -1
  203. package/dist/local-llm.js +2 -2
  204. package/dist/logger.d.ts +1 -1
  205. package/dist/logger.js +1 -1
  206. package/dist/memory-cache.d.ts +2 -2
  207. package/dist/memory-cache.js +1 -1
  208. package/dist/{memory-projection-store-NxMkbocT.d.ts → memory-projection-store-DeSXPh1j.d.ts} +1 -1
  209. package/dist/memory-projection-store.d.ts +1 -1
  210. package/dist/model-registry.js +2 -2
  211. package/dist/models-json.js +2 -2
  212. package/dist/native-knowledge.js +2 -2
  213. package/dist/negative.js +2 -2
  214. package/dist/operator-toolkit.js +20 -16
  215. package/dist/{orchestrator-CIvLFHx3.d.ts → orchestrator-B9kwlCep.d.ts} +254 -9
  216. package/dist/orchestrator.d.ts +6 -3
  217. package/dist/orchestrator.js +70 -58
  218. package/dist/page-versioning.d.ts +77 -0
  219. package/dist/page-versioning.js +15 -0
  220. package/dist/page-versioning.js.map +1 -0
  221. package/dist/plugin-id.d.ts +37 -0
  222. package/dist/plugin-id.js +11 -0
  223. package/dist/plugin-id.js.map +1 -0
  224. package/dist/policy-runtime.js +2 -2
  225. package/dist/profiling.js +2 -2
  226. package/dist/qmd.d.ts +5 -2
  227. package/dist/qmd.js +3 -3
  228. package/dist/recall-audit.d.ts +20 -0
  229. package/dist/recall-audit.js +50 -0
  230. package/dist/recall-audit.js.map +1 -0
  231. package/dist/recall-mmr.d.ts +152 -0
  232. package/dist/recall-mmr.js +17 -0
  233. package/dist/recall-mmr.js.map +1 -0
  234. package/dist/recall-qos.js +2 -2
  235. package/dist/recall-state.js +2 -2
  236. package/dist/relevance.js +2 -2
  237. package/dist/resolve-provider-secret.js +2 -2
  238. package/dist/resume-bundles.js +5 -4
  239. package/dist/retrieval-agents.js +2 -2
  240. package/dist/retrieval.js +2 -2
  241. package/dist/schemas.d.ts +422 -64
  242. package/dist/schemas.js +3 -1
  243. package/dist/sdk-compat.d.ts +2 -0
  244. package/dist/sdk-compat.js +6 -3
  245. package/dist/sdk-compat.js.map +1 -1
  246. package/dist/semantic-chunking.d.ts +87 -0
  247. package/dist/semantic-chunking.js +20 -0
  248. package/dist/semantic-chunking.js.map +1 -0
  249. package/dist/semantic-consolidation-DrvSYRdB.d.ts +119 -0
  250. package/dist/semantic-consolidation.d.ts +4 -42
  251. package/dist/semantic-consolidation.js +23 -2
  252. package/dist/semantic-rule-promotion.js +9 -6
  253. package/dist/semantic-rule-verifier.js +10 -7
  254. package/dist/session-observer-state.js +2 -2
  255. package/dist/session-toggles.d.ts +22 -0
  256. package/dist/session-toggles.js +116 -0
  257. package/dist/session-toggles.js.map +1 -0
  258. package/dist/skills-registry.d.ts +47 -0
  259. package/dist/skills-registry.js +48 -0
  260. package/dist/skills-registry.js.map +1 -0
  261. package/dist/source-attribution.d.ts +169 -0
  262. package/dist/source-attribution.js +27 -0
  263. package/dist/source-attribution.js.map +1 -0
  264. package/dist/storage.d.ts +171 -10
  265. package/dist/storage.js +16 -5
  266. package/dist/summarizer.js +7 -7
  267. package/dist/temporal-supersession.d.ts +127 -0
  268. package/dist/temporal-supersession.js +20 -0
  269. package/dist/temporal-supersession.js.map +1 -0
  270. package/dist/threading.js +2 -2
  271. package/dist/tier-migration.d.ts +2 -1
  272. package/dist/tier-routing.js +2 -2
  273. package/dist/tokens.d.ts +21 -1
  274. package/dist/tokens.js +5 -1
  275. package/dist/transcript.js +2 -2
  276. package/dist/types.d.ts +497 -3
  277. package/dist/types.js +1 -1
  278. package/dist/utility-learner.js +2 -2
  279. package/dist/utility-runtime.js +3 -3
  280. package/dist/verified-recall.js +11 -8
  281. package/dist/whitespace.d.ts +4 -0
  282. package/dist/whitespace.js +9 -0
  283. package/dist/whitespace.js.map +1 -0
  284. package/package.json +14 -8
  285. package/dist/chunk-2CJCWDMR.js +0 -87
  286. package/dist/chunk-2CJCWDMR.js.map +0 -1
  287. package/dist/chunk-2PO5ZRKV.js.map +0 -1
  288. package/dist/chunk-6UJQNRIO.js.map +0 -1
  289. package/dist/chunk-B7LOFDVE.js.map +0 -1
  290. package/dist/chunk-BDFZXRSO.js.map +0 -1
  291. package/dist/chunk-CXWFUJR2.js.map +0 -1
  292. package/dist/chunk-DORBM6OB.js +0 -81
  293. package/dist/chunk-DORBM6OB.js.map +0 -1
  294. package/dist/chunk-ESSMF2FR.js.map +0 -1
  295. package/dist/chunk-HLBYLYRD.js.map +0 -1
  296. package/dist/chunk-HLXVTBF3.js.map +0 -1
  297. package/dist/chunk-ISY75RLM.js.map +0 -1
  298. package/dist/chunk-KL4CP4SB.js.map +0 -1
  299. package/dist/chunk-KWBU5S5U.js.map +0 -1
  300. package/dist/chunk-MWGVGUIS.js.map +0 -1
  301. package/dist/chunk-ORZMT74A.js.map +0 -1
  302. package/dist/chunk-OTFNI3OO.js.map +0 -1
  303. package/dist/chunk-PGK3VUHN.js.map +0 -1
  304. package/dist/chunk-QCCCQT3O.js.map +0 -1
  305. package/dist/chunk-QDOSNLB4.js.map +0 -1
  306. package/dist/chunk-QPKFPHOO.js +0 -178
  307. package/dist/chunk-QPKFPHOO.js.map +0 -1
  308. package/dist/chunk-QWUUMMIK.js.map +0 -1
  309. package/dist/chunk-QY2BHY5O.js.map +0 -1
  310. package/dist/chunk-TVVVQQAK.js.map +0 -1
  311. package/dist/chunk-U4PV25RD.js.map +0 -1
  312. package/dist/chunk-UYSKNO6E.js.map +0 -1
  313. package/dist/chunk-V4YC4LUK.js.map +0 -1
  314. package/dist/chunk-WWIQTB2Y.js.map +0 -1
  315. package/dist/chunk-YNCQ7E4M.js.map +0 -1
  316. package/dist/chunk-ZJLY4QSU.js.map +0 -1
  317. /package/dist/{engine-2A6J4XEX.js.map → active-memory-bridge.js.map} +0 -0
  318. /package/dist/{chunk-NTTLPF7F.js.map → chunk-3QFQGRHO.js.map} +0 -0
  319. /package/dist/{chunk-G3AG3KZN.js.map → chunk-5IZL4DCV.js.map} +0 -0
  320. /package/dist/{chunk-BRK4ODMI.js.map → chunk-5NPGSAVB.js.map} +0 -0
  321. /package/dist/{chunk-L5RPWGFK.js.map → chunk-7DHTMOND.js.map} +0 -0
  322. /package/dist/{chunk-Q6FETXJA.js.map → chunk-7SEAZFFB.js.map} +0 -0
  323. /package/dist/{chunk-QANCTXQF.js.map → chunk-AYPYCLR7.js.map} +0 -0
  324. /package/dist/{chunk-LP47L3ZX.js.map → chunk-BTY5RRRF.js.map} +0 -0
  325. /package/dist/{chunk-SCHEKPYH.js.map → chunk-C2EFFULQ.js.map} +0 -0
  326. /package/dist/{chunk-GJR6D6KC.js.map → chunk-D654IBA6.js.map} +0 -0
  327. /package/dist/{chunk-UV2FO7J4.js.map → chunk-E6K4NIEU.js.map} +0 -0
  328. /package/dist/{chunk-T4WRIV2C.js.map → chunk-EABGC2TL.js.map} +0 -0
  329. /package/dist/{chunk-ONRU4L2N.js.map → chunk-FEMOX5AD.js.map} +0 -0
  330. /package/dist/{chunk-IFFFR3MR.js.map → chunk-FSFEQI74.js.map} +0 -0
  331. /package/dist/{chunk-UIYZ5T3I.js.map → chunk-GJQPH5G3.js.map} +0 -0
  332. /package/dist/{chunk-ZKYI7UVO.js.map → chunk-JR4ZC3G4.js.map} +0 -0
  333. /package/dist/{chunk-UCYSTFZR.js.map → chunk-JRNQ3RNA.js.map} +0 -0
  334. /package/dist/{chunk-GPGBSNKM.js.map → chunk-K4FLSOR5.js.map} +0 -0
  335. /package/dist/{chunk-M5ZBBBJI.js.map → chunk-KEG4GNGI.js.map} +0 -0
  336. /package/dist/{chunk-L7WO3MZ4.js.map → chunk-KWP7T3DP.js.map} +0 -0
  337. /package/dist/{chunk-J47FNDR7.js.map → chunk-MYQWXITD.js.map} +0 -0
  338. /package/dist/{chunk-YNI4S5WT.js.map → chunk-N53K2EXC.js.map} +0 -0
  339. /package/dist/{chunk-763GUIOU.js.map → chunk-NBNN5GOB.js.map} +0 -0
  340. /package/dist/{chunk-OOSWAUYB.js.map → chunk-ODWDQNRE.js.map} +0 -0
  341. /package/dist/{chunk-J3BT33K7.js.map → chunk-POBPGDWI.js.map} +0 -0
  342. /package/dist/{chunk-OTAVQCSF.js.map → chunk-PYXS46O7.js.map} +0 -0
  343. /package/dist/{chunk-XUHI52HK.js.map → chunk-QKAH5B6E.js.map} +0 -0
  344. /package/dist/{chunk-HG2NKWR2.js.map → chunk-S4LX5EBI.js.map} +0 -0
  345. /package/dist/{chunk-4A24LIM2.js.map → chunk-S75M5ZRK.js.map} +0 -0
  346. /package/dist/{chunk-MDDAA2AO.js.map → chunk-UPMD5XND.js.map} +0 -0
  347. /package/dist/{chunk-M5KEYE5E.js.map → chunk-URB2WSKZ.js.map} +0 -0
@@ -0,0 +1,813 @@
1
+ import {
2
+ StorageManager
3
+ } from "./chunk-POMSFKTB.js";
4
+ import {
5
+ log
6
+ } from "./chunk-2ODBA7MQ.js";
7
+
8
+ // src/briefing.ts
9
+ import { readFile } from "fs/promises";
10
+ import path from "path";
11
+ var BRIEFING_FORMAT_ALLOWED = ["markdown", "json"];
12
+ var BRIEFING_FOLLOWUP_DEFAULT_MODEL = "gpt-5.2";
13
+ function validateBriefingFormat(value) {
14
+ if (value === void 0) return null;
15
+ if (BRIEFING_FORMAT_ALLOWED.includes(value)) return null;
16
+ return `Invalid --format value: "${value}". Accepted: ${BRIEFING_FORMAT_ALLOWED.join(", ")}.`;
17
+ }
18
+ var DAY_MS = 24 * 60 * 60 * 1e3;
19
+ var MAX_WINDOW_MS = 100 * 365 * DAY_MS;
20
+ function parseBriefingWindow(token, now = /* @__PURE__ */ new Date()) {
21
+ const raw = typeof token === "string" ? token.trim().toLowerCase() : "";
22
+ if (raw.length === 0) return null;
23
+ if (raw === "yesterday") {
24
+ const startOfToday = startOfUtcDay(now);
25
+ const from2 = new Date(startOfToday.getTime() - DAY_MS);
26
+ return { from: from2, to: startOfToday, label: "yesterday" };
27
+ }
28
+ if (raw === "today") {
29
+ return { from: startOfUtcDay(now), to: now, label: "today" };
30
+ }
31
+ const match = raw.match(/^(\d+)\s*(h|d|w)$/);
32
+ if (!match) return null;
33
+ const value = parseInt(match[1], 10);
34
+ if (!Number.isFinite(value) || value <= 0) return null;
35
+ const unit = match[2];
36
+ let ms = 0;
37
+ if (unit === "h") ms = value * 60 * 60 * 1e3;
38
+ else if (unit === "d") ms = value * DAY_MS;
39
+ else if (unit === "w") ms = value * 7 * DAY_MS;
40
+ if (ms === 0) return null;
41
+ if (ms > MAX_WINDOW_MS || !Number.isFinite(ms)) return null;
42
+ const from = new Date(now.getTime() - ms);
43
+ if (!Number.isFinite(from.getTime())) return null;
44
+ return {
45
+ from,
46
+ to: now,
47
+ label: `last ${value}${unit}`
48
+ };
49
+ }
50
+ function startOfUtcDay(date) {
51
+ const d = new Date(date.getTime());
52
+ d.setUTCHours(0, 0, 0, 0);
53
+ return d;
54
+ }
55
+ function parseBriefingFocus(token) {
56
+ if (typeof token !== "string") return null;
57
+ const trimmed = token.trim();
58
+ if (trimmed.length === 0) return null;
59
+ const [maybeType, ...rest] = trimmed.split(":");
60
+ if (rest.length === 0) {
61
+ return { type: "topic", value: maybeType };
62
+ }
63
+ const rawType = maybeType.toLowerCase();
64
+ if (rawType === "person" || rawType === "project" || rawType === "topic") {
65
+ const value = rest.join(":").trim();
66
+ if (value.length === 0) return null;
67
+ return { type: rawType, value };
68
+ }
69
+ return { type: "topic", value: trimmed };
70
+ }
71
+ function focusToEntityRefSlug(focus) {
72
+ const sluggedValue = focus.value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
73
+ return `${focus.type}-${sluggedValue}`;
74
+ }
75
+ function focusMatchesMemory(memory, focus) {
76
+ const needle = focus.value.toLowerCase();
77
+ const entityRef = (memory.frontmatter.entityRef ?? "").toLowerCase();
78
+ const rawHaystack = [
79
+ memory.content,
80
+ entityRef,
81
+ ...memory.frontmatter.tags ?? []
82
+ ].join(" ").toLowerCase();
83
+ if (rawHaystack.includes(needle)) return true;
84
+ const slug = focusToEntityRefSlug(focus);
85
+ return entityRef.includes(slug);
86
+ }
87
+ function focusMatchesEntity(entity, focus) {
88
+ const needle = focus.value.toLowerCase();
89
+ if (focus.type === "person" && entity.type.toLowerCase() !== "person") return false;
90
+ if (focus.type === "project" && entity.type.toLowerCase() !== "project") return false;
91
+ const haystack = [
92
+ entity.name,
93
+ entity.synthesis || entity.summary || "",
94
+ ...entity.facts,
95
+ ...entity.aliases ?? [],
96
+ ...(entity.structuredSections ?? []).flatMap((section) => [section.title, ...section.facts])
97
+ ].join(" ").toLowerCase();
98
+ return haystack.includes(needle);
99
+ }
100
+ var FileCalendarSource = class {
101
+ constructor(filePath) {
102
+ this.filePath = filePath;
103
+ }
104
+ filePath;
105
+ async eventsForDate(dateIso) {
106
+ let raw;
107
+ try {
108
+ raw = await readFile(this.filePath, "utf-8");
109
+ } catch (err) {
110
+ log.warn(`briefing: calendar source unreadable at ${this.filePath}: ${err}`);
111
+ return [];
112
+ }
113
+ const events = this.filePath.toLowerCase().endsWith(".ics") ? parseIcsEvents(raw) : parseJsonEvents(raw);
114
+ return events.filter((event) => eventFallsOnDate(event, dateIso));
115
+ }
116
+ };
117
+ function parseJsonEvents(raw) {
118
+ try {
119
+ const parsed = JSON.parse(raw);
120
+ const arr = Array.isArray(parsed) ? parsed : parsed && typeof parsed === "object" && Array.isArray(parsed.events) ? parsed.events : [];
121
+ const events = [];
122
+ for (const entry of arr) {
123
+ if (!entry || typeof entry !== "object") continue;
124
+ const e = entry;
125
+ const id = typeof e.id === "string" ? e.id : typeof e.uid === "string" ? e.uid : cryptoRandomId();
126
+ const title = typeof e.title === "string" ? e.title : typeof e.summary === "string" ? e.summary : "";
127
+ const start = typeof e.start === "string" ? e.start : typeof e.dtstart === "string" ? e.dtstart : "";
128
+ if (!title || !start) continue;
129
+ events.push({
130
+ id,
131
+ title,
132
+ start,
133
+ end: typeof e.end === "string" ? e.end : typeof e.dtend === "string" ? e.dtend : void 0,
134
+ location: typeof e.location === "string" ? e.location : void 0,
135
+ notes: typeof e.notes === "string" ? e.notes : typeof e.description === "string" ? e.description : void 0
136
+ });
137
+ }
138
+ return events;
139
+ } catch (err) {
140
+ log.warn(`briefing: calendar JSON parse failed: ${err}`);
141
+ return [];
142
+ }
143
+ }
144
+ function parseIcsLine(line) {
145
+ const colonIdx = line.indexOf(":");
146
+ if (colonIdx <= 0) return null;
147
+ const head = line.slice(0, colonIdx);
148
+ const value = line.slice(colonIdx + 1).trim();
149
+ const headParts = head.split(";");
150
+ const property = headParts[0].toUpperCase();
151
+ if (!/^[A-Z0-9-]+$/.test(property)) return null;
152
+ const params = {};
153
+ for (let i = 1; i < headParts.length; i++) {
154
+ const segment = headParts[i];
155
+ const eqIdx = segment.indexOf("=");
156
+ if (eqIdx <= 0) continue;
157
+ const name = segment.slice(0, eqIdx).toUpperCase();
158
+ let val = segment.slice(eqIdx + 1);
159
+ if (val.startsWith('"') && val.endsWith('"') && val.length >= 2) {
160
+ val = val.slice(1, -1);
161
+ }
162
+ params[name] = val;
163
+ }
164
+ return { property, params, value };
165
+ }
166
+ function parseIcsEvents(raw) {
167
+ const events = [];
168
+ const normalized = raw.replace(/\r\n/g, "\n").replace(/\n[ \t]/g, "");
169
+ const blocks = normalized.split(/BEGIN:VEVENT/i).slice(1);
170
+ for (const block of blocks) {
171
+ const endIdx = block.search(/END:VEVENT/i);
172
+ const body = endIdx === -1 ? block : block.slice(0, endIdx);
173
+ const simpleFields = {};
174
+ const dateFields = {};
175
+ for (const line of body.split("\n")) {
176
+ const parsed = parseIcsLine(line);
177
+ if (!parsed) continue;
178
+ const { property, params, value } = parsed;
179
+ if (property === "DTSTART" || property === "DTEND") {
180
+ if (dateFields[property] === void 0) {
181
+ dateFields[property] = { raw: value, params };
182
+ }
183
+ } else if (simpleFields[property] === void 0) {
184
+ simpleFields[property] = value;
185
+ }
186
+ }
187
+ const title = simpleFields.SUMMARY;
188
+ const dtstart = dateFields.DTSTART;
189
+ if (!title || !dtstart) continue;
190
+ const dtend = dateFields.DTEND;
191
+ events.push({
192
+ id: simpleFields.UID ?? cryptoRandomId(),
193
+ title,
194
+ start: normalizeIcsDate(dtstart.raw, dtstart.params),
195
+ end: dtend ? normalizeIcsDate(dtend.raw, dtend.params) : void 0,
196
+ location: simpleFields.LOCATION,
197
+ notes: simpleFields.DESCRIPTION
198
+ });
199
+ }
200
+ return events;
201
+ }
202
+ function normalizeIcsDate(value, params = {}) {
203
+ if (/^\d{8}T\d{6}Z$/.test(value)) {
204
+ const y = value.slice(0, 4);
205
+ const m = value.slice(4, 6);
206
+ const d = value.slice(6, 8);
207
+ const hh = value.slice(9, 11);
208
+ const mm = value.slice(11, 13);
209
+ const ss = value.slice(13, 15);
210
+ return `${y}-${m}-${d}T${hh}:${mm}:${ss}Z`;
211
+ }
212
+ if (/^\d{8}T\d{6}$/.test(value)) {
213
+ const y = value.slice(0, 4);
214
+ const m = value.slice(4, 6);
215
+ const d = value.slice(6, 8);
216
+ const hh = value.slice(9, 11);
217
+ const mm = value.slice(11, 13);
218
+ const ss = value.slice(13, 15);
219
+ const local = `${y}-${m}-${d}T${hh}:${mm}:${ss}`;
220
+ const tzid = params.TZID;
221
+ if (tzid) {
222
+ const utcIso = icsWallclockToUtc(local, tzid);
223
+ if (utcIso) return utcIso;
224
+ log.warn(
225
+ `briefing: unsupported TZID "${tzid}" \u2014 treating as UTC for ${local}`
226
+ );
227
+ return `${local}Z`;
228
+ }
229
+ return local;
230
+ }
231
+ if (/^\d{8}$/.test(value)) {
232
+ return `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)}T00:00:00Z`;
233
+ }
234
+ return value;
235
+ }
236
+ function icsWallclockToUtc(local, tzid) {
237
+ const match = local.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/);
238
+ if (!match) return null;
239
+ const [, y, mo, d, hh, mm, ss] = match;
240
+ const naiveUtcMs = Date.UTC(
241
+ Number(y),
242
+ Number(mo) - 1,
243
+ Number(d),
244
+ Number(hh),
245
+ Number(mm),
246
+ Number(ss)
247
+ );
248
+ if (!Number.isFinite(naiveUtcMs)) return null;
249
+ let formatter;
250
+ try {
251
+ formatter = new Intl.DateTimeFormat("en-US", {
252
+ timeZone: tzid,
253
+ year: "numeric",
254
+ month: "2-digit",
255
+ day: "2-digit",
256
+ hour: "2-digit",
257
+ minute: "2-digit",
258
+ second: "2-digit",
259
+ hour12: false
260
+ });
261
+ } catch {
262
+ return null;
263
+ }
264
+ const zonedMs = zonedFormatToMs(formatter, new Date(naiveUtcMs));
265
+ if (zonedMs === null) return null;
266
+ const offsetMs = naiveUtcMs - zonedMs;
267
+ const realUtcMs = naiveUtcMs + offsetMs;
268
+ const zonedMs2 = zonedFormatToMs(formatter, new Date(realUtcMs));
269
+ if (zonedMs2 !== null) {
270
+ const offsetMs2 = realUtcMs - zonedMs2;
271
+ if (offsetMs2 !== offsetMs) {
272
+ return new Date(naiveUtcMs + offsetMs2).toISOString();
273
+ }
274
+ }
275
+ return new Date(realUtcMs).toISOString();
276
+ }
277
+ function zonedFormatToMs(formatter, date) {
278
+ const parts = formatter.formatToParts(date);
279
+ const get = (type) => parts.find((p) => p.type === type)?.value;
280
+ const y = get("year");
281
+ const mo = get("month");
282
+ const d = get("day");
283
+ const hh = get("hour");
284
+ const mm = get("minute");
285
+ const ss = get("second");
286
+ if (!y || !mo || !d || !hh || !mm || !ss) return null;
287
+ const normalizedHour = Number(hh) === 24 ? 0 : Number(hh);
288
+ const ms = Date.UTC(Number(y), Number(mo) - 1, Number(d), normalizedHour, Number(mm), Number(ss));
289
+ return Number.isFinite(ms) ? ms : null;
290
+ }
291
+ function isoHasTimezone(isoStr) {
292
+ return /(Z|[+-]\d{2}:?\d{2})$/.test(isoStr);
293
+ }
294
+ function isoToMs(isoStr) {
295
+ if (!isoStr) return null;
296
+ let src = isoStr;
297
+ if (!isoHasTimezone(src)) {
298
+ src = src + "Z";
299
+ }
300
+ const ms = new Date(src).getTime();
301
+ return Number.isFinite(ms) ? ms : null;
302
+ }
303
+ function eventFallsOnDate(event, dateIso) {
304
+ const target = dateIso.slice(0, 10);
305
+ const start = event.start;
306
+ const startIsFloating = !isoHasTimezone(start);
307
+ if (startIsFloating) {
308
+ const startShapeOk = typeof start === "string" && /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?)?$/.test(start);
309
+ if (!startShapeOk) {
310
+ log.debug(`briefing: skipping calendar event with invalid start value: ${JSON.stringify(start)}`);
311
+ return false;
312
+ }
313
+ const startDateStr = start.slice(0, 10);
314
+ const startDateProbe = /* @__PURE__ */ new Date(startDateStr + "T00:00:00Z");
315
+ if (Number.isNaN(startDateProbe.getTime()) || startDateProbe.toISOString().slice(0, 10) !== startDateStr) {
316
+ log.warn(
317
+ `briefing: skipping calendar event "${event.title}" with impossible start date ${JSON.stringify(startDateStr)}`
318
+ );
319
+ return false;
320
+ }
321
+ const startRawTime = start.indexOf("T") !== -1 ? start.slice(start.indexOf("T") + 1) : "";
322
+ if (startRawTime !== "") {
323
+ const startTimeParts = startRawTime.split(":").map(Number);
324
+ const shh = startTimeParts[0] ?? 0;
325
+ const smm = startTimeParts[1] ?? 0;
326
+ const sss = Math.floor(startTimeParts[2] ?? 0);
327
+ if (shh > 23 || smm > 59 || sss > 59) {
328
+ log.warn(
329
+ `briefing: skipping calendar event "${event.title}" with out-of-range start time ${JSON.stringify(startRawTime)}`
330
+ );
331
+ return false;
332
+ }
333
+ }
334
+ const startDate = startDateStr;
335
+ const end2 = event.end;
336
+ if (!end2) return startDate === target;
337
+ const endIsValid = typeof end2 === "string" && /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?)?$/.test(end2);
338
+ if (!endIsValid) {
339
+ log.warn(
340
+ `briefing: event "${event.title}" has malformed end timestamp ${JSON.stringify(end2)}; treating as single-day event at ${startDate}`
341
+ );
342
+ return startDate === target;
343
+ }
344
+ const endDate = end2.slice(0, 10);
345
+ const endDateProbe = /* @__PURE__ */ new Date(endDate + "T00:00:00Z");
346
+ if (Number.isNaN(endDateProbe.getTime()) || endDateProbe.toISOString().slice(0, 10) !== endDate) {
347
+ log.warn(
348
+ `briefing: event "${event.title}" has impossible end date ${JSON.stringify(endDate)}; treating as single-day event at ${startDate}`
349
+ );
350
+ return startDate === target;
351
+ }
352
+ const rawTime = end2.indexOf("T") !== -1 ? end2.slice(end2.indexOf("T") + 1) : "";
353
+ if (rawTime !== "") {
354
+ const timeParts = rawTime.split(":").map(Number);
355
+ const hh = timeParts[0] ?? 0;
356
+ const mm = timeParts[1] ?? 0;
357
+ const ss = Math.floor(timeParts[2] ?? 0);
358
+ const timeIsValid = hh <= 23 && mm <= 59 && ss <= 59;
359
+ if (!timeIsValid) {
360
+ log.warn(
361
+ `briefing: event "${event.title}" has out-of-range end time ${JSON.stringify(rawTime)}; treating as single-day event at ${startDate}`
362
+ );
363
+ return startDate === target;
364
+ }
365
+ }
366
+ const endTime = end2.slice(11);
367
+ const endIsDateOnly = endTime === "";
368
+ const endAtExactMidnight = endIsDateOnly || /^00(:00){1,2}(\.0+)?$/.test(endTime);
369
+ const endActiveOnEndDay = !endAtExactMidnight;
370
+ if (endActiveOnEndDay) {
371
+ return startDate <= target && target <= endDate;
372
+ }
373
+ return startDate <= target && target < endDate;
374
+ }
375
+ const startMs = isoToMs(start);
376
+ if (startMs === null) {
377
+ log.debug(`briefing: skipping calendar event with invalid start value: ${JSON.stringify(start)}`);
378
+ return false;
379
+ }
380
+ const dayStart = Date.UTC(
381
+ Number(target.slice(0, 4)),
382
+ Number(target.slice(5, 7)) - 1,
383
+ Number(target.slice(8, 10))
384
+ );
385
+ const dayEnd = dayStart + 864e5;
386
+ const end = event.end;
387
+ if (!end) {
388
+ return startMs >= dayStart && startMs < dayEnd;
389
+ }
390
+ const endMs = isoToMs(end);
391
+ if (endMs === null) {
392
+ return startMs >= dayStart && startMs < dayEnd;
393
+ }
394
+ return startMs < dayEnd && endMs > dayStart;
395
+ }
396
+ function cryptoRandomId() {
397
+ return `evt-${Math.random().toString(36).slice(2, 10)}`;
398
+ }
399
+ var MAX_ACTIVE_THREADS = 8;
400
+ var MAX_RECENT_ENTITIES = 8;
401
+ var MAX_OPEN_COMMITMENTS = 8;
402
+ async function buildBriefing(options) {
403
+ const now = options.now ?? /* @__PURE__ */ new Date();
404
+ const window = options.window ?? defaultWindow(now);
405
+ const maxFollowups = clampFollowups(options.maxFollowups);
406
+ const focus = options.focus ?? null;
407
+ const [allMemories, allEntities] = await Promise.all([
408
+ safeReadMemories(options.storage),
409
+ safeReadEntities(options.storage)
410
+ ]);
411
+ const memoriesInWindow = filterMemoriesByWindow(allMemories, window);
412
+ const focusedMemories = focus ? memoriesInWindow.filter((m) => focusMatchesMemory(m, focus)) : memoriesInWindow;
413
+ const activeThreads = buildActiveThreads(focusedMemories);
414
+ const recentEntities = buildRecentEntities(allEntities, window, focus);
415
+ const openCommitments = buildOpenCommitments(focusedMemories);
416
+ const calendarLoadResult = options.calendarSource ? await loadTodayCalendar(options.calendarSource, now) : void 0;
417
+ const calendarSourceErrors = calendarLoadResult?.error ? [calendarLoadResult.error] : [];
418
+ const sectionsBase = {
419
+ activeThreads,
420
+ recentEntities,
421
+ openCommitments,
422
+ suggestedFollowups: [],
423
+ todayCalendar: calendarLoadResult?.events
424
+ };
425
+ let followups = [];
426
+ let followupsUnavailableReason;
427
+ if (maxFollowups === 0 || options.allowLlm === false) {
428
+ followupsUnavailableReason = "LLM follow-ups disabled by configuration";
429
+ } else if (!options.openaiApiKey && !options.followupGenerator) {
430
+ followupsUnavailableReason = "OPENAI_API_KEY not configured";
431
+ } else {
432
+ try {
433
+ const generator = options.followupGenerator ?? buildOpenAiFollowupGenerator({
434
+ apiKey: options.openaiApiKey,
435
+ model: options.model ?? BRIEFING_FOLLOWUP_DEFAULT_MODEL,
436
+ baseURL: options.openaiBaseUrl
437
+ });
438
+ const generated = await generator({
439
+ sections: sectionsBase,
440
+ windowLabel: window.label,
441
+ maxFollowups
442
+ });
443
+ followups = generated.slice(0, maxFollowups);
444
+ } catch (err) {
445
+ const errMsg = stringifyError(err);
446
+ const modelName = options.model ?? BRIEFING_FOLLOWUP_DEFAULT_MODEL;
447
+ if (/model/i.test(errMsg) && (/not found/i.test(errMsg) || /does not exist/i.test(errMsg) || /invalid/i.test(errMsg))) {
448
+ followupsUnavailableReason = `configured follow-up model '${modelName}' is not available in the Responses API`;
449
+ } else {
450
+ followupsUnavailableReason = `LLM follow-ups failed: ${errMsg}`;
451
+ }
452
+ log.warn(`briefing: ${followupsUnavailableReason}`);
453
+ }
454
+ }
455
+ const sections = {
456
+ ...sectionsBase,
457
+ suggestedFollowups: followups
458
+ };
459
+ const windowIso = { from: window.from.toISOString(), to: window.to.toISOString() };
460
+ const markdown = renderBriefingMarkdown({
461
+ sections,
462
+ windowLabel: window.label,
463
+ focus,
464
+ followupsUnavailableReason,
465
+ generatedAt: now,
466
+ namespace: options.namespace
467
+ });
468
+ const json = {
469
+ generatedAt: now.toISOString(),
470
+ window: windowIso,
471
+ focus,
472
+ namespace: options.namespace ?? null,
473
+ sections,
474
+ followupsUnavailableReason: followupsUnavailableReason ?? null,
475
+ calendarSourceErrors: calendarSourceErrors.length > 0 ? calendarSourceErrors : null
476
+ };
477
+ const result = {
478
+ markdown,
479
+ json,
480
+ sections,
481
+ followupsUnavailableReason,
482
+ window: windowIso
483
+ };
484
+ if (calendarSourceErrors.length > 0) {
485
+ result.calendarSourceErrors = calendarSourceErrors;
486
+ }
487
+ return result;
488
+ }
489
+ function clampFollowups(value) {
490
+ if (typeof value !== "number" || !Number.isFinite(value)) return 5;
491
+ return Math.max(0, Math.min(10, Math.floor(value)));
492
+ }
493
+ function defaultWindow(now) {
494
+ const parsed = parseBriefingWindow("yesterday", now);
495
+ if (parsed) return parsed;
496
+ return { from: new Date(now.getTime() - DAY_MS), to: now, label: "yesterday" };
497
+ }
498
+ async function safeReadMemories(storage) {
499
+ try {
500
+ return await storage.readAllMemories();
501
+ } catch (err) {
502
+ log.warn(`briefing: readAllMemories failed: ${err}`);
503
+ return [];
504
+ }
505
+ }
506
+ async function safeReadEntities(storage) {
507
+ try {
508
+ return await storage.readAllEntityFiles();
509
+ } catch (err) {
510
+ log.warn(`briefing: readAllEntityFiles failed: ${err}`);
511
+ return [];
512
+ }
513
+ }
514
+ function memoryTimestamp(memory) {
515
+ const raw = memory.frontmatter.updated || memory.frontmatter.created;
516
+ if (!raw) return 0;
517
+ const t = Date.parse(raw);
518
+ return Number.isFinite(t) ? t : 0;
519
+ }
520
+ function filterMemoriesByWindow(memories, window) {
521
+ const fromMs = window.from.getTime();
522
+ const toMs = window.to.getTime();
523
+ return memories.filter((m) => {
524
+ const status = m.frontmatter.status;
525
+ if (status === "superseded" || status === "archived" || status === "rejected" || status === "quarantined") {
526
+ return false;
527
+ }
528
+ const ts = memoryTimestamp(m);
529
+ return ts >= fromMs && ts < toMs;
530
+ });
531
+ }
532
+ function buildActiveThreads(memories) {
533
+ const buckets = /* @__PURE__ */ new Map();
534
+ for (const memory of memories) {
535
+ const threadKey = extractThreadKey(memory);
536
+ const updatedAt = memory.frontmatter.updated || memory.frontmatter.created || "";
537
+ const existing = buckets.get(threadKey);
538
+ if (!existing || updatedAt > existing.updatedAt) {
539
+ buckets.set(threadKey, {
540
+ id: threadKey,
541
+ title: summarizeContentTitle(memory),
542
+ updatedAt,
543
+ // Always derive reason from the newest memory so the description
544
+ // reflects the most-recent activity type, not the first memory seen.
545
+ reason: describeReason(memory)
546
+ });
547
+ }
548
+ }
549
+ return Array.from(buckets.values()).sort((a, b) => {
550
+ if (a.updatedAt > b.updatedAt) return -1;
551
+ if (a.updatedAt < b.updatedAt) return 1;
552
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
553
+ }).slice(0, MAX_ACTIVE_THREADS);
554
+ }
555
+ function extractThreadKey(memory) {
556
+ const entityRef = memory.frontmatter.entityRef?.trim();
557
+ if (entityRef) return `entity:${entityRef}`;
558
+ const tags = memory.frontmatter.tags ?? [];
559
+ const topicTag = tags.find((t) => t.startsWith("topic:"));
560
+ if (topicTag) return topicTag;
561
+ if (tags.length > 0) return `tag:${tags[0]}`;
562
+ return `memory:${memory.frontmatter.id}`;
563
+ }
564
+ function summarizeContentTitle(memory) {
565
+ const firstLine = (memory.content || "").split("\n").find((line) => line.trim().length > 0) ?? "";
566
+ const trimmed = firstLine.trim();
567
+ if (trimmed.length === 0) return memory.frontmatter.id;
568
+ return trimmed.length > 120 ? `${trimmed.slice(0, 117)}...` : trimmed;
569
+ }
570
+ function describeReason(memory) {
571
+ const cat = memory.frontmatter.category;
572
+ if (cat === "commitment") return "open commitment";
573
+ if (cat === "decision") return "recent decision";
574
+ if (cat === "correction") return "recent correction";
575
+ return "recent activity";
576
+ }
577
+ function buildRecentEntities(entities, window, focus) {
578
+ const fromMs = window.from.getTime();
579
+ const scored = [];
580
+ const now = window.to;
581
+ for (const entity of entities) {
582
+ if (focus && !focusMatchesEntity(entity, focus)) continue;
583
+ const toMs = window.to.getTime();
584
+ const updatedMs = entity.updated ? Date.parse(entity.updated) : 0;
585
+ if (!Number.isFinite(updatedMs) || updatedMs < fromMs || updatedMs >= toMs) continue;
586
+ const score = StorageManager.scoreEntity(entity, now);
587
+ scored.push({
588
+ name: entity.name,
589
+ type: entity.type,
590
+ updatedAt: entity.updated,
591
+ score: Number(score.toFixed(4)),
592
+ summary: entity.synthesis || entity.summary
593
+ });
594
+ }
595
+ return scored.sort((a, b) => {
596
+ const scoreDiff = b.score - a.score;
597
+ if (scoreDiff !== 0) return scoreDiff;
598
+ if (a.updatedAt > b.updatedAt) return -1;
599
+ if (a.updatedAt < b.updatedAt) return 1;
600
+ return 0;
601
+ }).slice(0, MAX_RECENT_ENTITIES);
602
+ }
603
+ function buildOpenCommitments(memories) {
604
+ const commitments = [];
605
+ for (const memory of memories) {
606
+ const tags = memory.frontmatter.tags ?? [];
607
+ const isPending = tags.some((t) => t.toLowerCase() === "pending");
608
+ const isCommitment = memory.frontmatter.category === "commitment";
609
+ const isUnresolvedQuestion = /(?:\?$|\bfollow[- ]up\b|\btodo\b)/i.test(memory.content);
610
+ if (isPending || isCommitment || isUnresolvedQuestion) {
611
+ const kind = isCommitment ? "commitment" : isUnresolvedQuestion ? "question" : "pending_memory";
612
+ commitments.push({
613
+ id: memory.frontmatter.id,
614
+ kind,
615
+ text: summarizeContentTitle(memory),
616
+ source: memory.frontmatter.source,
617
+ createdAt: memory.frontmatter.created
618
+ });
619
+ }
620
+ }
621
+ return commitments.sort((a, b) => {
622
+ if (!a.createdAt && !b.createdAt) return 0;
623
+ if (!a.createdAt) return 1;
624
+ if (!b.createdAt) return -1;
625
+ if (a.createdAt > b.createdAt) return -1;
626
+ if (a.createdAt < b.createdAt) return 1;
627
+ return 0;
628
+ }).slice(0, MAX_OPEN_COMMITMENTS);
629
+ }
630
+ async function loadTodayCalendar(source, now) {
631
+ const sourceLabel = source.filePath ?? "calendar";
632
+ try {
633
+ const dateIso = now.toISOString().slice(0, 10);
634
+ const events = await source.eventsForDate(dateIso);
635
+ return { events, error: void 0 };
636
+ } catch (err) {
637
+ const message = err instanceof Error ? err.message : String(err);
638
+ log.warn(`briefing: calendar source error (${sourceLabel}): ${message}`);
639
+ return {
640
+ events: void 0,
641
+ error: { source: sourceLabel, error: message }
642
+ };
643
+ }
644
+ }
645
+ function buildOpenAiFollowupGenerator(cfg) {
646
+ return async ({ sections, windowLabel, maxFollowups }) => {
647
+ const { OpenAI } = await import("openai");
648
+ const clientOpts = { apiKey: cfg.apiKey };
649
+ if (cfg.baseURL) clientOpts.baseURL = cfg.baseURL;
650
+ const client = new OpenAI(clientOpts);
651
+ const prompt = buildFollowupPrompt(sections, windowLabel, maxFollowups);
652
+ const response = await client.responses.create({
653
+ model: cfg.model,
654
+ instructions: FOLLOWUP_INSTRUCTIONS,
655
+ input: prompt,
656
+ max_output_tokens: 512
657
+ });
658
+ const text = typeof response.output_text === "string" ? response.output_text : "";
659
+ return parseFollowupResponse(text, maxFollowups);
660
+ };
661
+ }
662
+ var FOLLOWUP_INSTRUCTIONS = `You suggest short follow-up prompts for a daily context briefing.
663
+ Return strict JSON of the form { "followups": [{ "text": "...", "rationale": "..." }] }.
664
+ Rules:
665
+ - Never invent facts absent from the input.
666
+ - Keep each "text" under 140 characters.
667
+ - Prefer concrete, action-oriented phrasing.
668
+ - Omit duplicates. Avoid filler.`;
669
+ function buildFollowupPrompt(sections, windowLabel, maxFollowups) {
670
+ const lines = [];
671
+ lines.push(`Window: ${windowLabel}`);
672
+ lines.push(`Desired follow-ups: ${maxFollowups}`);
673
+ lines.push("");
674
+ lines.push("Active threads:");
675
+ for (const t of sections.activeThreads) lines.push(`- ${t.title} (${t.reason})`);
676
+ lines.push("");
677
+ lines.push("Recent entities:");
678
+ for (const e of sections.recentEntities) lines.push(`- ${e.name} [${e.type}]`);
679
+ lines.push("");
680
+ lines.push("Open commitments:");
681
+ for (const c of sections.openCommitments) lines.push(`- [${c.kind}] ${c.text}`);
682
+ return lines.join("\n");
683
+ }
684
+ function parseFollowupResponse(raw, max) {
685
+ const parsed = JSON.parse(raw);
686
+ if (!parsed || typeof parsed !== "object") {
687
+ throw new Error(`LLM returned non-object JSON: ${typeof parsed}`);
688
+ }
689
+ const arr = parsed.followups;
690
+ if (!Array.isArray(arr)) {
691
+ throw new Error(`LLM response missing "followups" array`);
692
+ }
693
+ const out = [];
694
+ for (const entry of arr) {
695
+ if (!entry || typeof entry !== "object") continue;
696
+ const text = entry.text;
697
+ if (typeof text !== "string" || text.trim().length === 0) continue;
698
+ const rationale = entry.rationale;
699
+ out.push({
700
+ text: text.trim(),
701
+ rationale: typeof rationale === "string" ? rationale.trim() : void 0
702
+ });
703
+ if (out.length >= max) break;
704
+ }
705
+ return out;
706
+ }
707
+ function stringifyError(err) {
708
+ if (err instanceof Error) return err.message;
709
+ return String(err);
710
+ }
711
+ function renderBriefingMarkdown(ctx) {
712
+ const lines = [];
713
+ lines.push(`# Daily Context Briefing`);
714
+ lines.push("");
715
+ lines.push(`_Generated ${ctx.generatedAt.toISOString()} (window: ${ctx.windowLabel})_`);
716
+ if (ctx.focus) {
717
+ lines.push(`_Focus: ${ctx.focus.type}:${ctx.focus.value}_`);
718
+ }
719
+ if (ctx.namespace) {
720
+ lines.push(`_Namespace: ${ctx.namespace}_`);
721
+ }
722
+ lines.push("");
723
+ lines.push(`## Active threads`);
724
+ if (ctx.sections.activeThreads.length === 0) {
725
+ lines.push(`_No active threads in window._`);
726
+ } else {
727
+ for (const t of ctx.sections.activeThreads) {
728
+ lines.push(`- **${t.title}** \u2014 ${t.reason} (updated ${t.updatedAt})`);
729
+ }
730
+ }
731
+ lines.push("");
732
+ lines.push(`## Recent entities`);
733
+ if (ctx.sections.recentEntities.length === 0) {
734
+ lines.push(`_No entities updated in window._`);
735
+ } else {
736
+ for (const e of ctx.sections.recentEntities) {
737
+ const summary = e.summary ? ` \u2014 ${e.summary}` : "";
738
+ lines.push(`- **${e.name}** (${e.type}, score ${e.score})${summary}`);
739
+ }
740
+ }
741
+ lines.push("");
742
+ lines.push(`## Open commitments`);
743
+ if (ctx.sections.openCommitments.length === 0) {
744
+ lines.push(`_No open commitments detected._`);
745
+ } else {
746
+ for (const c of ctx.sections.openCommitments) {
747
+ lines.push(`- [${c.kind}] ${c.text}`);
748
+ }
749
+ }
750
+ lines.push("");
751
+ lines.push(`## Suggested follow-ups`);
752
+ if (ctx.followupsUnavailableReason) {
753
+ lines.push(`_Unavailable: ${ctx.followupsUnavailableReason}_`);
754
+ } else if (ctx.sections.suggestedFollowups.length === 0) {
755
+ lines.push(`_No follow-ups suggested._`);
756
+ } else {
757
+ for (const f of ctx.sections.suggestedFollowups) {
758
+ const rationale = f.rationale ? ` _(${f.rationale})_` : "";
759
+ lines.push(`- ${f.text}${rationale}`);
760
+ }
761
+ }
762
+ lines.push("");
763
+ if (ctx.sections.todayCalendar !== void 0) {
764
+ lines.push(`## Today's calendar`);
765
+ if (ctx.sections.todayCalendar.length === 0) {
766
+ lines.push(`_No events on the calendar today._`);
767
+ } else {
768
+ for (const ev of ctx.sections.todayCalendar) {
769
+ const end = ev.end ? ` \u2192 ${ev.end}` : "";
770
+ const loc = ev.location ? ` @ ${ev.location}` : "";
771
+ lines.push(`- **${ev.title}** (${ev.start}${end})${loc}`);
772
+ }
773
+ }
774
+ lines.push("");
775
+ }
776
+ return lines.join("\n").trimEnd() + "\n";
777
+ }
778
+ function resolveBriefingSaveDir(configOverride, env = process.env) {
779
+ if (typeof configOverride === "string" && configOverride.trim().length > 0) {
780
+ return path.resolve(configOverride.trim());
781
+ }
782
+ const remnicHome = env.REMNIC_HOME?.trim();
783
+ if (remnicHome && remnicHome.length > 0) {
784
+ return path.join(remnicHome, "briefings");
785
+ }
786
+ const home = env.HOME ?? env.USERPROFILE ?? ".";
787
+ return path.join(home, ".remnic", "briefings");
788
+ }
789
+ function briefingFilename(date, format = "markdown") {
790
+ const day = date.toISOString().slice(0, 10);
791
+ return format === "json" ? `${day}.json` : `${day}.md`;
792
+ }
793
+
794
+ export {
795
+ BRIEFING_FORMAT_ALLOWED,
796
+ BRIEFING_FOLLOWUP_DEFAULT_MODEL,
797
+ validateBriefingFormat,
798
+ parseBriefingWindow,
799
+ parseBriefingFocus,
800
+ focusMatchesMemory,
801
+ focusMatchesEntity,
802
+ FileCalendarSource,
803
+ parseIcsEvents,
804
+ eventFallsOnDate,
805
+ buildBriefing,
806
+ filterMemoriesByWindow,
807
+ buildActiveThreads,
808
+ buildRecentEntities,
809
+ renderBriefingMarkdown,
810
+ resolveBriefingSaveDir,
811
+ briefingFilename
812
+ };
813
+ //# sourceMappingURL=chunk-ECKDIK5F.js.map