@remnic/core 9.25.7 → 9.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/dist/access-admin-ops-surface.d.ts +5 -5
  2. package/dist/access-admin-ops-surface.js +41 -41
  3. package/dist/access-audit.js +2 -2
  4. package/dist/access-authorization-probe.d.ts +5 -5
  5. package/dist/access-authorization-probe.js +42 -42
  6. package/dist/access-boundary.d.ts +5 -5
  7. package/dist/access-boundary.js +41 -41
  8. package/dist/access-cli.js +98 -97
  9. package/dist/access-cli.js.map +1 -1
  10. package/dist/access-http-lcm-compaction.d.ts +130 -0
  11. package/dist/access-http-lcm-compaction.js +10 -0
  12. package/dist/access-http.d.ts +5 -5
  13. package/dist/access-http.js +53 -52
  14. package/dist/access-identity-continuity-surface.d.ts +4 -4
  15. package/dist/access-identity-continuity-surface.js +41 -41
  16. package/dist/access-lcm-surface.d.ts +5 -5
  17. package/dist/access-lcm-surface.js +41 -41
  18. package/dist/access-mcp.d.ts +5 -5
  19. package/dist/access-mcp.js +47 -47
  20. package/dist/access-namespace-preflight.js +41 -41
  21. package/dist/access-observe-write-surface.d.ts +5 -5
  22. package/dist/access-observe-write-surface.js +41 -41
  23. package/dist/access-operations-batch.js +43 -43
  24. package/dist/access-operations.d.ts +8 -8
  25. package/dist/access-operations.js +45 -45
  26. package/dist/access-recall-concurrency.d.ts +5 -5
  27. package/dist/access-recall-concurrency.js +41 -41
  28. package/dist/access-recall-response.d.ts +5 -5
  29. package/dist/access-recall-response.js +41 -41
  30. package/dist/access-recall-surface.d.ts +5 -5
  31. package/dist/access-recall-surface.js +41 -41
  32. package/dist/access-schema.d.ts +92 -77
  33. package/dist/access-schema.js +8 -8
  34. package/dist/{access-service-CIdWkP6J.d.ts → access-service-B4-Fu9x2.d.ts} +4 -4
  35. package/dist/access-service.d.ts +5 -5
  36. package/dist/access-service.js +41 -41
  37. package/dist/access-surface-catalog.d.ts +5 -5
  38. package/dist/access-wearables-meetings-surface.d.ts +2 -2
  39. package/dist/adapters/index.js +7 -7
  40. package/dist/adapters/registry.js +3 -3
  41. package/dist/{auto-sync-5OE5QOZB.js → auto-sync-UPTUVE4X.js} +3 -3
  42. package/dist/bootstrap.d.ts +4 -4
  43. package/dist/briefing.d.ts +1 -1
  44. package/dist/briefing.js +5 -5
  45. package/dist/buffer.d.ts +1 -1
  46. package/dist/{capsule-crypto-7FJQINUR.js → capsule-crypto-YO5QJ6L3.js} +2 -2
  47. package/dist/capsule-crypto-YO5QJ6L3.js.map +1 -0
  48. package/dist/causal-behavior.js +2 -2
  49. package/dist/causal-chain.js +2 -2
  50. package/dist/causal-consolidation.js +11 -11
  51. package/dist/causal-retrieval.js +2 -2
  52. package/dist/causal-trajectory.js +1 -1
  53. package/dist/{chunk-JBPKEARU.js → chunk-2QSZNTDO.js} +7 -7
  54. package/dist/{chunk-UMFLAACL.js → chunk-2RAC4JIG.js} +9 -9
  55. package/dist/{chunk-OIE242WM.js → chunk-4MJZTF42.js} +3 -3
  56. package/dist/chunk-4Z4XNEWZ.js +86 -0
  57. package/dist/chunk-4Z4XNEWZ.js.map +1 -0
  58. package/dist/{chunk-IR4LGIH6.js → chunk-5BRT4Z2I.js} +2 -2
  59. package/dist/{chunk-2PHX3I5C.js → chunk-6NNNURLK.js} +8 -8
  60. package/dist/{chunk-BLAKS3CP.js → chunk-77CNV7DY.js} +4 -4
  61. package/dist/{chunk-TVVEYCNW.js → chunk-7K5Q6COX.js} +4 -4
  62. package/dist/{chunk-227UFSEQ.js → chunk-7RZJWZ46.js} +5 -5
  63. package/dist/{chunk-7CPOZH6Y.js → chunk-AJ7QCSIS.js} +2 -2
  64. package/dist/{chunk-TPYZ727G.js → chunk-BHLN7L7M.js} +6 -6
  65. package/dist/{chunk-WIGBTWXA.js → chunk-BNGPHGVZ.js} +2 -2
  66. package/dist/{chunk-2NLLXCJG.js → chunk-BXLOS5AJ.js} +2 -2
  67. package/dist/{chunk-PS5OG75R.js → chunk-CI26JDZA.js} +2 -2
  68. package/dist/{chunk-K4DP5KZA.js → chunk-CIQXI47W.js} +684 -22
  69. package/dist/chunk-CIQXI47W.js.map +1 -0
  70. package/dist/{chunk-X7Y7WX73.js → chunk-DQEMWVMT.js} +1 -1
  71. package/dist/{chunk-W33DEUKR.js → chunk-EOLC6EXV.js} +2 -2
  72. package/dist/{chunk-UOURUMBN.js → chunk-EUSLKI4X.js} +2 -2
  73. package/dist/{chunk-ZPUFQGUF.js → chunk-EYJSW2RV.js} +5 -5
  74. package/dist/{chunk-3CHQZVAL.js → chunk-FRVTCCGD.js} +5 -5
  75. package/dist/{chunk-AQ2ZQYDI.js → chunk-HEXSNYJD.js} +6 -6
  76. package/dist/{chunk-E5A6C4A5.js → chunk-HORJVJ6K.js} +48 -48
  77. package/dist/{chunk-3UOSVTFR.js → chunk-JCVQV6QX.js} +11 -11
  78. package/dist/{chunk-37VPMR4E.js → chunk-JDOJZTFF.js} +6 -6
  79. package/dist/{chunk-P25IPRXP.js → chunk-KGTD2KZJ.js} +28 -8
  80. package/dist/chunk-KGTD2KZJ.js.map +1 -0
  81. package/dist/{chunk-WSEA52RI.js → chunk-MEBQFQ26.js} +2 -2
  82. package/dist/{chunk-G6MGAE36.js → chunk-MG6MNSP4.js} +5 -5
  83. package/dist/{chunk-BL4JHZSO.js → chunk-NUWMZIYZ.js} +40 -40
  84. package/dist/{chunk-ES36HTSC.js → chunk-PTN6UAUA.js} +4 -4
  85. package/dist/{chunk-KZVPTJNZ.js → chunk-RGJBM7Z3.js} +75 -75
  86. package/dist/{chunk-7IGWPXVC.js → chunk-RNY3BO35.js} +2 -2
  87. package/dist/{chunk-JA4HEXV7.js → chunk-RPA2RX5P.js} +2 -2
  88. package/dist/{chunk-32XTXKIA.js → chunk-RSYJV25N.js} +22 -14
  89. package/dist/chunk-RSYJV25N.js.map +1 -0
  90. package/dist/{chunk-S2BBISHU.js → chunk-RYHWZ52A.js} +4 -4
  91. package/dist/{chunk-ZN4UZWMT.js → chunk-SK3EYPKC.js} +2 -2
  92. package/dist/{chunk-BUK2FXOL.js → chunk-TKBDJTXG.js} +4 -4
  93. package/dist/{chunk-D7MAWMMK.js → chunk-U3TH5Q2Q.js} +2 -2
  94. package/dist/{chunk-SSYBI43M.js → chunk-UT3OQPFA.js} +6 -6
  95. package/dist/{chunk-4B77XSG5.js → chunk-UV72DEZD.js} +5 -5
  96. package/dist/{chunk-KQAFEZQX.js → chunk-VDX2J7OX.js} +2 -2
  97. package/dist/{chunk-NRV4Y3PM.js → chunk-W4FBGYGK.js} +1 -1
  98. package/dist/{chunk-5J7HJ7RT.js → chunk-WEAO45M4.js} +2 -2
  99. package/dist/{chunk-MU7ZHSZE.js → chunk-WZFAPHIK.js} +2 -2
  100. package/dist/{chunk-NY6W6CJW.js → chunk-XKO7BM2C.js} +2 -2
  101. package/dist/{chunk-7KXQ44PA.js → chunk-XQ4EH6DI.js} +5 -5
  102. package/dist/{chunk-EZ25VE3G.js → chunk-YNDLCWXS.js} +4 -4
  103. package/dist/{chunk-VPSAVXHM.js → chunk-YSGBD3QN.js} +7 -7
  104. package/dist/{cli-Da5kesWC.d.ts → cli-Bz7X7dGx.d.ts} +3 -3
  105. package/dist/cli.d.ts +6 -6
  106. package/dist/cli.js +75 -74
  107. package/dist/compounding/engine.d.ts +1 -1
  108. package/dist/compounding/engine.js +5 -5
  109. package/dist/connectors/codex-materialize-runner.js +5 -5
  110. package/dist/connectors/index.js +5 -5
  111. package/dist/consolidation-provenance-check.d.ts +1 -1
  112. package/dist/consolidation-undo.d.ts +1 -1
  113. package/dist/contradiction/index.d.ts +1 -1
  114. package/dist/conversation-index/backend.js +2 -2
  115. package/dist/corpus-watermark.js +16 -16
  116. package/dist/dashboard-runtime.js +2 -2
  117. package/dist/entity-retrieval.d.ts +1 -1
  118. package/dist/entity-retrieval.js +5 -5
  119. package/dist/explicit-capture.d.ts +4 -4
  120. package/dist/extraction.js +3 -3
  121. package/dist/{first-start-migration-BKNGOFED.js → first-start-migration-LEXL3XYL.js} +4 -4
  122. package/dist/index.d.ts +398 -398
  123. package/dist/index.js +177 -176
  124. package/dist/lcm/engine.js +3 -3
  125. package/dist/lcm/index.js +9 -9
  126. package/dist/maintenance/memory-governance.js +6 -6
  127. package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +1 -1
  128. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +5 -5
  129. package/dist/maintenance/rebuild-memory-projection.d.ts +1 -1
  130. package/dist/maintenance/rebuild-memory-projection.js +7 -7
  131. package/dist/{maintenance-DD22oIx9.d.ts → maintenance-DgnD2z8S.d.ts} +1 -1
  132. package/dist/mcp-memory-inspector-app.d.ts +5 -5
  133. package/dist/memory-worth-outcomes.d.ts +1 -1
  134. package/dist/namespaces/migrate.d.ts +1 -1
  135. package/dist/namespaces/migrate.js +15 -15
  136. package/dist/namespaces/search.js +9 -9
  137. package/dist/namespaces/storage.d.ts +1 -1
  138. package/dist/namespaces/storage.js +5 -5
  139. package/dist/operator-doctor-corpus.js +17 -17
  140. package/dist/operator-toolkit.d.ts +1 -1
  141. package/dist/operator-toolkit.js +28 -28
  142. package/dist/orchestration/compression-guideline-coordinator.d.ts +1 -1
  143. package/dist/orchestration/maintenance.d.ts +2 -2
  144. package/dist/orchestration/maintenance.js +11 -11
  145. package/dist/{orchestrator-CFJ_TG6D.d.ts → orchestrator-rIHmHpv1.d.ts} +3 -3
  146. package/dist/orchestrator.d.ts +4 -4
  147. package/dist/orchestrator.js +98 -97
  148. package/dist/resume-bundles.js +1 -1
  149. package/dist/schemas.d.ts +76 -76
  150. package/dist/search/factory.js +8 -8
  151. package/dist/search/index.js +13 -13
  152. package/dist/search/lancedb-backend.js +2 -2
  153. package/dist/search/meilisearch-backend.js +2 -2
  154. package/dist/search/orama-backend.js +2 -2
  155. package/dist/semantic-consolidation.js +7 -7
  156. package/dist/semantic-rule-promotion.js +5 -5
  157. package/dist/semantic-rule-verifier.js +6 -6
  158. package/dist/{service-Z8uzoAST.d.ts → service-cTvil7D_.d.ts} +1 -1
  159. package/dist/session-namespace-bindings.d.ts +27 -0
  160. package/dist/session-namespace-bindings.js +243 -0
  161. package/dist/session-namespace-bindings.js.map +1 -0
  162. package/dist/shared-context/manager.d.ts +8 -8
  163. package/dist/{storage-BZVMn8yJ.d.ts → storage-C9ibpTme.d.ts} +0 -3
  164. package/dist/storage.d.ts +1 -1
  165. package/dist/storage.js +4 -4
  166. package/dist/temporal-supersession.d.ts +1 -1
  167. package/dist/testing/lifecycle-matrix.d.ts +100 -0
  168. package/dist/testing/lifecycle-matrix.js +149 -0
  169. package/dist/testing/lifecycle-matrix.js.map +1 -0
  170. package/dist/tier-migration.d.ts +1 -1
  171. package/dist/transfer/backup.js +4 -4
  172. package/dist/transfer/capsule-export.js +4 -4
  173. package/dist/transfer/capsule-import.js +3 -3
  174. package/dist/transfer/types.d.ts +66 -66
  175. package/dist/verified-recall.js +6 -6
  176. package/package.json +22 -2
  177. package/src/access-http-lcm-compaction.ts +116 -0
  178. package/src/access-http.test.ts +218 -0
  179. package/src/access-http.ts +8 -8
  180. package/src/access-schema-pi.test.ts +9 -0
  181. package/src/access-schema.ts +29 -4
  182. package/src/access-surface-catalog.test.ts +1 -0
  183. package/src/session-namespace-bindings.test.ts +358 -0
  184. package/src/session-namespace-bindings.ts +301 -0
  185. package/src/storage/profile-header.ts +897 -0
  186. package/src/storage-profile-timestamp.test.ts +3290 -0
  187. package/src/storage.ts +5 -8
  188. package/src/testing/lifecycle-matrix.ts +17 -7
  189. package/src/testing/subjects/profile-header-write.test.ts +71 -0
  190. package/dist/chunk-32XTXKIA.js.map +0 -1
  191. package/dist/chunk-K4DP5KZA.js.map +0 -1
  192. package/dist/chunk-P25IPRXP.js.map +0 -1
  193. /package/dist/{capsule-crypto-7FJQINUR.js.map → access-http-lcm-compaction.js.map} +0 -0
  194. /package/dist/{auto-sync-5OE5QOZB.js.map → auto-sync-UPTUVE4X.js.map} +0 -0
  195. /package/dist/{chunk-JBPKEARU.js.map → chunk-2QSZNTDO.js.map} +0 -0
  196. /package/dist/{chunk-UMFLAACL.js.map → chunk-2RAC4JIG.js.map} +0 -0
  197. /package/dist/{chunk-OIE242WM.js.map → chunk-4MJZTF42.js.map} +0 -0
  198. /package/dist/{chunk-IR4LGIH6.js.map → chunk-5BRT4Z2I.js.map} +0 -0
  199. /package/dist/{chunk-2PHX3I5C.js.map → chunk-6NNNURLK.js.map} +0 -0
  200. /package/dist/{chunk-BLAKS3CP.js.map → chunk-77CNV7DY.js.map} +0 -0
  201. /package/dist/{chunk-TVVEYCNW.js.map → chunk-7K5Q6COX.js.map} +0 -0
  202. /package/dist/{chunk-227UFSEQ.js.map → chunk-7RZJWZ46.js.map} +0 -0
  203. /package/dist/{chunk-7CPOZH6Y.js.map → chunk-AJ7QCSIS.js.map} +0 -0
  204. /package/dist/{chunk-TPYZ727G.js.map → chunk-BHLN7L7M.js.map} +0 -0
  205. /package/dist/{chunk-WIGBTWXA.js.map → chunk-BNGPHGVZ.js.map} +0 -0
  206. /package/dist/{chunk-2NLLXCJG.js.map → chunk-BXLOS5AJ.js.map} +0 -0
  207. /package/dist/{chunk-PS5OG75R.js.map → chunk-CI26JDZA.js.map} +0 -0
  208. /package/dist/{chunk-X7Y7WX73.js.map → chunk-DQEMWVMT.js.map} +0 -0
  209. /package/dist/{chunk-W33DEUKR.js.map → chunk-EOLC6EXV.js.map} +0 -0
  210. /package/dist/{chunk-UOURUMBN.js.map → chunk-EUSLKI4X.js.map} +0 -0
  211. /package/dist/{chunk-ZPUFQGUF.js.map → chunk-EYJSW2RV.js.map} +0 -0
  212. /package/dist/{chunk-3CHQZVAL.js.map → chunk-FRVTCCGD.js.map} +0 -0
  213. /package/dist/{chunk-AQ2ZQYDI.js.map → chunk-HEXSNYJD.js.map} +0 -0
  214. /package/dist/{chunk-E5A6C4A5.js.map → chunk-HORJVJ6K.js.map} +0 -0
  215. /package/dist/{chunk-3UOSVTFR.js.map → chunk-JCVQV6QX.js.map} +0 -0
  216. /package/dist/{chunk-37VPMR4E.js.map → chunk-JDOJZTFF.js.map} +0 -0
  217. /package/dist/{chunk-WSEA52RI.js.map → chunk-MEBQFQ26.js.map} +0 -0
  218. /package/dist/{chunk-G6MGAE36.js.map → chunk-MG6MNSP4.js.map} +0 -0
  219. /package/dist/{chunk-BL4JHZSO.js.map → chunk-NUWMZIYZ.js.map} +0 -0
  220. /package/dist/{chunk-ES36HTSC.js.map → chunk-PTN6UAUA.js.map} +0 -0
  221. /package/dist/{chunk-KZVPTJNZ.js.map → chunk-RGJBM7Z3.js.map} +0 -0
  222. /package/dist/{chunk-7IGWPXVC.js.map → chunk-RNY3BO35.js.map} +0 -0
  223. /package/dist/{chunk-JA4HEXV7.js.map → chunk-RPA2RX5P.js.map} +0 -0
  224. /package/dist/{chunk-S2BBISHU.js.map → chunk-RYHWZ52A.js.map} +0 -0
  225. /package/dist/{chunk-ZN4UZWMT.js.map → chunk-SK3EYPKC.js.map} +0 -0
  226. /package/dist/{chunk-BUK2FXOL.js.map → chunk-TKBDJTXG.js.map} +0 -0
  227. /package/dist/{chunk-D7MAWMMK.js.map → chunk-U3TH5Q2Q.js.map} +0 -0
  228. /package/dist/{chunk-SSYBI43M.js.map → chunk-UT3OQPFA.js.map} +0 -0
  229. /package/dist/{chunk-4B77XSG5.js.map → chunk-UV72DEZD.js.map} +0 -0
  230. /package/dist/{chunk-KQAFEZQX.js.map → chunk-VDX2J7OX.js.map} +0 -0
  231. /package/dist/{chunk-NRV4Y3PM.js.map → chunk-W4FBGYGK.js.map} +0 -0
  232. /package/dist/{chunk-5J7HJ7RT.js.map → chunk-WEAO45M4.js.map} +0 -0
  233. /package/dist/{chunk-MU7ZHSZE.js.map → chunk-WZFAPHIK.js.map} +0 -0
  234. /package/dist/{chunk-NY6W6CJW.js.map → chunk-XKO7BM2C.js.map} +0 -0
  235. /package/dist/{chunk-7KXQ44PA.js.map → chunk-XQ4EH6DI.js.map} +0 -0
  236. /package/dist/{chunk-EZ25VE3G.js.map → chunk-YNDLCWXS.js.map} +0 -0
  237. /package/dist/{chunk-VPSAVXHM.js.map → chunk-YSGBD3QN.js.map} +0 -0
  238. /package/dist/{first-start-migration-BKNGOFED.js.map → first-start-migration-LEXL3XYL.js.map} +0 -0
@@ -1,8 +1,3 @@
1
- import {
2
- TombstoneStore,
3
- buildRetiredFactTombstoneInputs,
4
- collectRetiredMemoriesForRebuild
5
- } from "./chunk-2QMKMVHH.js";
6
1
  import {
7
2
  WEARABLES_DIR_NAME,
8
3
  escapeSegmentText,
@@ -14,18 +9,23 @@ import {
14
9
  unescapeSegmentText,
15
10
  unescapeSpeakerLabel
16
11
  } from "./chunk-UHVXE24Y.js";
12
+ import {
13
+ TombstoneStore,
14
+ buildRetiredFactTombstoneInputs,
15
+ collectRetiredMemoriesForRebuild
16
+ } from "./chunk-2QMKMVHH.js";
17
17
  import {
18
18
  supersessionKeysForFact
19
19
  } from "./chunk-DNHVPZOD.js";
20
+ import {
21
+ assertMemoryFrontmatterId,
22
+ warnProjectionFallback
23
+ } from "./chunk-HKF5VASQ.js";
20
24
  import {
21
25
  DEFAULT_CITATION_FORMAT,
22
26
  hasCitation,
23
27
  stripCitationForTemplate
24
28
  } from "./chunk-J6A3CX5N.js";
25
- import {
26
- assertMemoryFrontmatterId,
27
- warnProjectionFallback
28
- } from "./chunk-HKF5VASQ.js";
29
29
  import {
30
30
  SPECULATIVE_TTL_DAYS,
31
31
  confidenceTier
@@ -94,10 +94,6 @@ import {
94
94
  parseFaithfulnessField,
95
95
  serializeFaithfulnessFields
96
96
  } from "./chunk-JYIJNNN3.js";
97
- import {
98
- computeContentHash,
99
- normalizeContent
100
- } from "./chunk-W5H6ZRPT.js";
101
97
  import {
102
98
  createVersion
103
99
  } from "./chunk-5VQJBH2G.js";
@@ -121,6 +117,10 @@ import {
121
117
  getInFlightRead,
122
118
  setInFlightRead
123
119
  } from "./chunk-PDJTHRAW.js";
120
+ import {
121
+ computeContentHash,
122
+ normalizeContent
123
+ } from "./chunk-W5H6ZRPT.js";
124
124
  import {
125
125
  isConsolidationOperator,
126
126
  isValidDerivedFromEntry
@@ -705,6 +705,673 @@ var MemoryReadStore = class {
705
705
  }
706
706
  };
707
707
 
708
+ // src/storage/profile-header.ts
709
+ var LAST_UPDATED_HEADER = /^\*Last updated:[^*]*\*$/;
710
+ var PROFILE_TITLE = /^ {0,3}#(?:[ \t]+|$)/;
711
+ var MARKDOWN_HEADING = /^ {0,3}#{1,6}(?:[ \t]+|$)/;
712
+ var MARKDOWN_LIST_ITEM = /^(?:[-+*]|\d{1,9}[.)])[ \t]+/;
713
+ var MARKDOWN_LIST_ITEM_CAN_INTERRUPT = /^(?:[-+*]|1[.)])[ \t]+/;
714
+ var MARKDOWN_THEMATIC_BREAK = /^(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/;
715
+ var MARKDOWN_SETEXT_UNDERLINE = /^(?:=+|-+)$/;
716
+ var MARKDOWN_BLOCK_QUOTE = /^>/;
717
+ var MARKDOWN_LINK_REFERENCE = /^\[(?:\\.|[^\\\[\]])+\]:\s*(?:<[^>\n]*>|([^\s]+))(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?$/;
718
+ var MARKDOWN_LINK_REFERENCE_LABEL = /^\[(?:\\.|[^\\\[\]])+\]:\s*$/;
719
+ var MARKDOWN_LINK_REFERENCE_CONTINUATION = /^ {1,3}(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\))$/;
720
+ var MARKDOWN_LINK_REFERENCE_DESTINATION_CONTINUATION = /^ {1,3}(?:<[^>\n]*>|(?!["'(])[^\s]+(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?)$/;
721
+ var UTF8_BOM = "\uFEFF";
722
+ function isLastUpdatedHeader(line) {
723
+ const withoutBom = line.startsWith(UTF8_BOM) ? line.slice(1) : line;
724
+ if (isIndentedCodeLine(withoutBom)) return false;
725
+ return LAST_UPDATED_HEADER.test(withoutBom.trim());
726
+ }
727
+ function isIndentedCodeLine(line) {
728
+ let indentation = 0;
729
+ while (line[indentation] === " ") indentation += 1;
730
+ return indentation >= 4 || line[indentation] === " ";
731
+ }
732
+ function getFenceMarker(line) {
733
+ let indentation = 0;
734
+ while (line[indentation] === " ") indentation += 1;
735
+ if (indentation > 3 || line[indentation] === " ") return null;
736
+ const trimmed = line.slice(indentation);
737
+ const character = trimmed[0];
738
+ if (character !== "`" && character !== "~") return null;
739
+ let length = 0;
740
+ while (trimmed[length] === character) length += 1;
741
+ if (length < 3) return null;
742
+ const trailing = trimmed.slice(length);
743
+ if (character === "`" && trailing.includes("`")) return null;
744
+ return { indentation, character, length, trailing };
745
+ }
746
+ function isClosingFence(fence, openFence) {
747
+ return fence.character === openFence.character && fence.length >= openFence.length && fence.trailing.trim() === "";
748
+ }
749
+ var RAW_HTML_BLOCK_TAGS = ["pre", "textarea", "script", "style"];
750
+ var HTML_BLOCK_TAGS = [
751
+ "address",
752
+ "article",
753
+ "aside",
754
+ "base",
755
+ "basefont",
756
+ "blockquote",
757
+ "body",
758
+ "caption",
759
+ "center",
760
+ "col",
761
+ "colgroup",
762
+ "dd",
763
+ "details",
764
+ "dialog",
765
+ "dir",
766
+ "div",
767
+ "dl",
768
+ "dt",
769
+ "fieldset",
770
+ "figcaption",
771
+ "figure",
772
+ "footer",
773
+ "form",
774
+ "frame",
775
+ "frameset",
776
+ "h1",
777
+ "h2",
778
+ "h3",
779
+ "h4",
780
+ "h5",
781
+ "h6",
782
+ "head",
783
+ "header",
784
+ "hgroup",
785
+ "hr",
786
+ "html",
787
+ "iframe",
788
+ "legend",
789
+ "li",
790
+ "link",
791
+ "main",
792
+ "menu",
793
+ "menuitem",
794
+ "nav",
795
+ "noframes",
796
+ "ol",
797
+ "optgroup",
798
+ "option",
799
+ "p",
800
+ "param",
801
+ "search",
802
+ "section",
803
+ "summary",
804
+ "table",
805
+ "tbody",
806
+ "td",
807
+ "tfoot",
808
+ "th",
809
+ "thead",
810
+ "title",
811
+ "tr",
812
+ "track",
813
+ "ul"
814
+ ];
815
+ function findHtmlBlockTag(line, tags) {
816
+ const isClosing = line.startsWith("</");
817
+ const nameStart = isClosing ? 2 : 1;
818
+ for (const tag of tags) {
819
+ const nextCharacter = line[nameStart + tag.length];
820
+ const isSelfClosingSlash = !isClosing && nextCharacter === "/" && line[nameStart + tag.length + 1] === ">";
821
+ if (line.startsWith(`${isClosing ? "</" : "<"}${tag}`) && (nextCharacter === void 0 || nextCharacter === ">" || isSelfClosingSlash || nextCharacter === " " || nextCharacter === " ")) {
822
+ return tag;
823
+ }
824
+ }
825
+ return null;
826
+ }
827
+ function isAsciiLetter(character) {
828
+ return character >= "a" && character <= "z" || character >= "A" && character <= "Z";
829
+ }
830
+ function isHtmlTagNameCharacter(character) {
831
+ return isAsciiLetter(character) || character >= "0" && character <= "9" || character === "-";
832
+ }
833
+ var HTML_ATTRIBUTES = /^(?:[A-Za-z_:][A-Za-z0-9_.:-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)(?:\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*$/;
834
+ function hasValidHtmlTagAttributes(attributeText, isClosing) {
835
+ const trimmed = attributeText.trim();
836
+ if (isClosing || trimmed === "") return trimmed === "";
837
+ const withoutSelfClosingSlash = trimmed.endsWith("/") ? trimmed.slice(0, -1).trimEnd() : trimmed;
838
+ return withoutSelfClosingSlash === "" || HTML_ATTRIBUTES.test(withoutSelfClosingSlash);
839
+ }
840
+ function findCompleteHtmlTag(line) {
841
+ let index = 1;
842
+ const isClosing = line[index] === "/";
843
+ if (isClosing) index += 1;
844
+ const nameStart = index;
845
+ if (!isAsciiLetter(line[index] ?? "")) return null;
846
+ while (isHtmlTagNameCharacter(line[index] ?? "")) index += 1;
847
+ const nextCharacter = line[index] ?? "";
848
+ if (nextCharacter !== ">" && nextCharacter !== "/" && nextCharacter !== " " && nextCharacter !== " ") {
849
+ return null;
850
+ }
851
+ const name = line.slice(nameStart, index).toLowerCase();
852
+ let quote = null;
853
+ for (; index < line.length; index += 1) {
854
+ const character = line[index];
855
+ if (quote) {
856
+ if (character === quote) quote = null;
857
+ continue;
858
+ }
859
+ if (character === '"' || character === "'") {
860
+ quote = character;
861
+ continue;
862
+ }
863
+ if (character === ">" && line.slice(index + 1).trim() === "") {
864
+ const tagBody = line.slice(nameStart, index).trimEnd();
865
+ if (!hasValidHtmlTagAttributes(tagBody.slice(name.length), isClosing)) return null;
866
+ return {
867
+ name,
868
+ isClosing,
869
+ isSelfClosing: !isClosing && tagBody.endsWith("/")
870
+ };
871
+ }
872
+ }
873
+ return null;
874
+ }
875
+ function findHtmlTagPrefix(line) {
876
+ let quote = null;
877
+ for (let index = 1; index < line.length; index += 1) {
878
+ const character = line[index];
879
+ if (quote) {
880
+ if (character === quote) quote = null;
881
+ continue;
882
+ }
883
+ if (character === '"' || character === "'") {
884
+ quote = character;
885
+ continue;
886
+ }
887
+ if (character !== ">") continue;
888
+ return findCompleteHtmlTag(line.slice(0, index + 1));
889
+ }
890
+ return null;
891
+ }
892
+ function findHtmlTags(line) {
893
+ const tags = [];
894
+ let index = 0;
895
+ while (index < line.length) {
896
+ if (line[index] !== "<") {
897
+ index += 1;
898
+ continue;
899
+ }
900
+ let cursor = index + 1;
901
+ const isClosing = line[cursor] === "/";
902
+ if (isClosing) cursor += 1;
903
+ const nameStart = cursor;
904
+ if (!isAsciiLetter(line[cursor] ?? "")) {
905
+ index += 1;
906
+ continue;
907
+ }
908
+ while (isHtmlTagNameCharacter(line[cursor] ?? "")) cursor += 1;
909
+ const name = line.slice(nameStart, cursor).toLowerCase();
910
+ let quote = null;
911
+ for (; cursor < line.length; cursor += 1) {
912
+ const character = line[cursor] ?? "";
913
+ if (quote) {
914
+ if (character === quote) quote = null;
915
+ continue;
916
+ }
917
+ if (character === '"' || character === "'") {
918
+ quote = character;
919
+ continue;
920
+ }
921
+ if (character !== ">") continue;
922
+ const tagBody = line.slice(nameStart, cursor).trimEnd();
923
+ tags.push({
924
+ name,
925
+ isClosing,
926
+ isSelfClosing: !isClosing && tagBody.endsWith("/")
927
+ });
928
+ index = cursor + 1;
929
+ break;
930
+ }
931
+ if (cursor >= line.length) break;
932
+ }
933
+ return tags;
934
+ }
935
+ function updateHtmlBlockDepth(htmlBlock, line, skipFirstOpening) {
936
+ if (!htmlBlock.tagName) return htmlBlock;
937
+ let depth = htmlBlock.depth;
938
+ let skippedFirstOpening = !skipFirstOpening;
939
+ for (const tag of findHtmlTags(line)) {
940
+ if (tag.name !== htmlBlock.tagName) continue;
941
+ if (tag.isClosing) {
942
+ depth -= 1;
943
+ } else if (!tag.isSelfClosing) {
944
+ if (!skippedFirstOpening) {
945
+ skippedFirstOpening = true;
946
+ continue;
947
+ }
948
+ depth += 1;
949
+ }
950
+ }
951
+ if (depth > 0) return { ...htmlBlock, depth };
952
+ return htmlBlock.endsAtBlankLine ? { ...htmlBlock, endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 } : null;
953
+ }
954
+ function hasSpacedSelfClosingSlash(line) {
955
+ return /\s\/\s*>/.test(line);
956
+ }
957
+ function findHtmlBlockStart(normalizedLine, trimmedLine, allowGenericHtmlBlock) {
958
+ const rawTag = findHtmlBlockTag(normalizedLine, RAW_HTML_BLOCK_TAGS);
959
+ if (rawTag) {
960
+ const completeTag = findCompleteHtmlTag(trimmedLine) ?? findHtmlTagPrefix(trimmedLine);
961
+ if (!completeTag && normalizedLine.startsWith("</")) return null;
962
+ if (completeTag?.isSelfClosing && !hasSpacedSelfClosingSlash(trimmedLine)) return null;
963
+ const endMarker = `</${rawTag}>`;
964
+ if (hasHtmlBlockEndMarker(normalizedLine, endMarker)) {
965
+ if (!completeTag || completeTag.isClosing) return null;
966
+ return { endMarker, endsAtBlankLine: false, tagName: null, depth: 0 };
967
+ }
968
+ return { endMarker, endsAtBlankLine: false, tagName: null, depth: 0 };
969
+ }
970
+ if (normalizedLine.startsWith("<!--")) {
971
+ return { endMarker: "-->", endsAtBlankLine: false, tagName: null, depth: 0 };
972
+ }
973
+ if (normalizedLine.startsWith("<?")) {
974
+ return { endMarker: "?>", endsAtBlankLine: false, tagName: null, depth: 0 };
975
+ }
976
+ if (trimmedLine.startsWith("<![CDATA[")) {
977
+ return { endMarker: "]]>", endsAtBlankLine: false, tagName: null, depth: 0 };
978
+ }
979
+ const declarationFirst = trimmedLine[2];
980
+ if (trimmedLine.startsWith("<!") && declarationFirst && declarationFirst >= "A" && declarationFirst <= "Z") {
981
+ return { endMarker: ">", endsAtBlankLine: false, tagName: null, depth: 0 };
982
+ }
983
+ const blockTag = findHtmlBlockTag(normalizedLine, HTML_BLOCK_TAGS);
984
+ if (blockTag) {
985
+ const completeTag = findCompleteHtmlTag(trimmedLine) ?? findHtmlTagPrefix(trimmedLine);
986
+ if (!completeTag) {
987
+ return { endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 };
988
+ }
989
+ if (completeTag.isSelfClosing) {
990
+ return { endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 };
991
+ }
992
+ return { endMarker: `</${blockTag}>`, endsAtBlankLine: true, tagName: blockTag, depth: 1 };
993
+ }
994
+ if (!allowGenericHtmlBlock) return null;
995
+ const genericTag = findCompleteHtmlTag(trimmedLine);
996
+ if (!genericTag) return null;
997
+ if (genericTag.isClosing || genericTag.isSelfClosing) {
998
+ return { endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 };
999
+ }
1000
+ return { endMarker: `</${genericTag.name}>`, endsAtBlankLine: true, tagName: genericTag.name, depth: 1 };
1001
+ }
1002
+ function parseProfileLines(content) {
1003
+ const segments = content.split(/(\r\n|\n|\r)/);
1004
+ const lines = [];
1005
+ for (let index = 0; index < segments.length; index += 2) {
1006
+ lines.push({
1007
+ content: segments[index] ?? "",
1008
+ ending: segments[index + 1] ?? ""
1009
+ });
1010
+ }
1011
+ return lines;
1012
+ }
1013
+ function renderProfileLines(lines) {
1014
+ let rendered = "";
1015
+ for (const line of lines) {
1016
+ rendered += line.content + line.ending;
1017
+ }
1018
+ return rendered;
1019
+ }
1020
+ function findFrontmatterEnd(lines) {
1021
+ const firstLine = lines[0]?.content.startsWith(UTF8_BOM) ? lines[0].content.slice(1) : lines[0]?.content;
1022
+ if (firstLine !== "---") return -1;
1023
+ for (let index = 1; index < lines.length; index += 1) {
1024
+ const line = lines[index]?.content.trimEnd();
1025
+ if (line === "---" || line === "...") return index;
1026
+ }
1027
+ return -1;
1028
+ }
1029
+ function hasHtmlBlockEndMarker(line, endMarker) {
1030
+ return line.includes(endMarker);
1031
+ }
1032
+ function shouldCloseHtmlBlock(line, endMarker) {
1033
+ const normalizedLine = line.trimStart().toLowerCase();
1034
+ return normalizedLine.includes(endMarker.toLowerCase());
1035
+ }
1036
+ function canStartGenericHtmlBlock(lines, index, previousHtmlTerminator) {
1037
+ const previousLine = lines[index - 1]?.content.trim() ?? "";
1038
+ if (previousLine === "") return true;
1039
+ return isMetadataBoundary(previousLine, previousHtmlTerminator) && !isLastUpdatedHeader(previousLine) && !MARKDOWN_LIST_ITEM.test(previousLine) && !MARKDOWN_BLOCK_QUOTE.test(previousLine);
1040
+ }
1041
+ function isHtmlBlockBoundary(lines, index, htmlTerminatorIndexes) {
1042
+ if (htmlTerminatorIndexes.has(index)) return true;
1043
+ const line = lines[index]?.content ?? "";
1044
+ const parserLine = index === 0 && line.startsWith(UTF8_BOM) ? line.slice(1) : line;
1045
+ if (isIndentedCodeLine(parserLine) || getFenceMarker(parserLine)) return false;
1046
+ const trimmedLine = parserLine.trimStart();
1047
+ return findHtmlBlockStart(
1048
+ trimmedLine.toLowerCase(),
1049
+ trimmedLine,
1050
+ canStartGenericHtmlBlock(lines, index, htmlTerminatorIndexes.has(index - 1))
1051
+ ) !== null;
1052
+ }
1053
+ function visitProfileMetadataLines(lines, visit, onHtmlBlockTerminator, onFenceBlockTerminator) {
1054
+ const frontmatterEnd = findFrontmatterEnd(lines);
1055
+ const htmlTerminatorIndexes = /* @__PURE__ */ new Set();
1056
+ const markHtmlTerminator = (index) => {
1057
+ htmlTerminatorIndexes.add(index);
1058
+ onHtmlBlockTerminator?.(index);
1059
+ };
1060
+ let openFence = null;
1061
+ let openHtmlBlock = null;
1062
+ for (let index = 0; index < lines.length; index += 1) {
1063
+ const line = lines[index]?.content ?? "";
1064
+ const parserLine = index === 0 && line.startsWith(UTF8_BOM) ? line.slice(1) : line;
1065
+ if (index <= frontmatterEnd) continue;
1066
+ const fence = getFenceMarker(parserLine);
1067
+ if (openFence) {
1068
+ const indentation = parserLine.length - parserLine.trimStart().length;
1069
+ const leavesListContainer = openFence.listIndentation !== null && parserLine.trim() !== "" && indentation < openFence.listIndentation;
1070
+ if (!leavesListContainer) {
1071
+ if (fence && isClosingFence(fence, openFence)) openFence = null;
1072
+ continue;
1073
+ }
1074
+ openFence = null;
1075
+ if (index > 0) onFenceBlockTerminator?.(index - 1);
1076
+ }
1077
+ const trimmedLine = parserLine.trimStart();
1078
+ const normalizedLine = trimmedLine.toLowerCase();
1079
+ if (openHtmlBlock) {
1080
+ const indentation = parserLine.length - parserLine.trimStart().length;
1081
+ const leavesListContainer = openHtmlBlock.listIndentation !== null && parserLine.trim() !== "" && indentation < openHtmlBlock.listIndentation;
1082
+ if (!leavesListContainer) {
1083
+ if (openHtmlBlock.endsAtBlankLine && normalizedLine === "") {
1084
+ openHtmlBlock = null;
1085
+ continue;
1086
+ }
1087
+ if (openHtmlBlock.tagName) {
1088
+ const nextHtmlBlock = updateHtmlBlockDepth(openHtmlBlock, normalizedLine, false);
1089
+ if (!nextHtmlBlock) markHtmlTerminator(index);
1090
+ openHtmlBlock = nextHtmlBlock;
1091
+ continue;
1092
+ }
1093
+ if (openHtmlBlock.endMarker && shouldCloseHtmlBlock(normalizedLine, openHtmlBlock.endMarker)) {
1094
+ openHtmlBlock = null;
1095
+ markHtmlTerminator(index);
1096
+ }
1097
+ continue;
1098
+ }
1099
+ openHtmlBlock = null;
1100
+ if (index > 0) markHtmlTerminator(index - 1);
1101
+ }
1102
+ if (isIndentedCodeLine(parserLine)) continue;
1103
+ if (fence) {
1104
+ openFence = {
1105
+ ...fence,
1106
+ listIndentation: isNestedListContent(lines, index, fence.indentation) ? fence.indentation : null
1107
+ };
1108
+ continue;
1109
+ }
1110
+ const htmlBlock = findHtmlBlockStart(
1111
+ normalizedLine,
1112
+ trimmedLine,
1113
+ canStartGenericHtmlBlock(lines, index, htmlTerminatorIndexes.has(index - 1))
1114
+ );
1115
+ if (htmlBlock) {
1116
+ markHtmlTerminator(index);
1117
+ const indentation = parserLine.length - parserLine.trimStart().length;
1118
+ const htmlBlockWithContainer = {
1119
+ ...htmlBlock,
1120
+ listIndentation: isNestedListContent(lines, index, indentation) ? indentation : null
1121
+ };
1122
+ if (htmlBlock.tagName) {
1123
+ openHtmlBlock = updateHtmlBlockDepth(htmlBlockWithContainer, normalizedLine, true);
1124
+ if (!openHtmlBlock) markHtmlTerminator(index);
1125
+ } else if (htmlBlock.endMarker && shouldCloseHtmlBlock(normalizedLine, htmlBlock.endMarker)) {
1126
+ openHtmlBlock = null;
1127
+ markHtmlTerminator(index);
1128
+ } else {
1129
+ openHtmlBlock = htmlBlockWithContainer;
1130
+ }
1131
+ continue;
1132
+ }
1133
+ visit(line, index);
1134
+ }
1135
+ }
1136
+ function isCompletedIndentedCodeBlock(lines, index) {
1137
+ if (!isIndentedCodeLine(lines[index - 1]?.content ?? "")) return false;
1138
+ let sawBlank = false;
1139
+ for (let previousIndex = index - 2; previousIndex >= 0; previousIndex -= 1) {
1140
+ const previousLine = lines[previousIndex]?.content ?? "";
1141
+ if (previousLine.trim() === "") {
1142
+ sawBlank = true;
1143
+ continue;
1144
+ }
1145
+ if (isIndentedCodeLine(previousLine)) continue;
1146
+ return sawBlank;
1147
+ }
1148
+ return true;
1149
+ }
1150
+ function isListContinuation(lines, index, indentation) {
1151
+ for (let previousIndex = index - 1; previousIndex >= 0; previousIndex -= 1) {
1152
+ const previousLine = lines[previousIndex]?.content ?? "";
1153
+ if (previousLine.trim() === "") return false;
1154
+ const previousIndentation = previousLine.length - previousLine.trimStart().length;
1155
+ if (previousIndentation > indentation) continue;
1156
+ const previousBoundaryLine = previousLine.trimStart();
1157
+ if (MARKDOWN_LIST_ITEM.test(previousBoundaryLine)) return true;
1158
+ if (MARKDOWN_HEADING.test(previousBoundaryLine) || MARKDOWN_THEMATIC_BREAK.test(previousBoundaryLine) || MARKDOWN_BLOCK_QUOTE.test(previousBoundaryLine) || getFenceMarker(previousLine) !== null) {
1159
+ return false;
1160
+ }
1161
+ }
1162
+ return false;
1163
+ }
1164
+ function isNestedListContent(lines, index, indentation) {
1165
+ for (let previousIndex = index - 1; previousIndex >= 0; previousIndex -= 1) {
1166
+ const previousLine = lines[previousIndex]?.content ?? "";
1167
+ if (previousLine.trim() === "") continue;
1168
+ const previousIndentation = previousLine.length - previousLine.trimStart().length;
1169
+ if (previousIndentation >= indentation) continue;
1170
+ if (MARKDOWN_LIST_ITEM.test(previousLine.trimStart()) || isListContinuation(lines, previousIndex, indentation)) {
1171
+ return true;
1172
+ }
1173
+ break;
1174
+ }
1175
+ return false;
1176
+ }
1177
+ function isValidBareLinkDestination(destination) {
1178
+ let parentheses = 0;
1179
+ for (let index = 0; index < destination.length; index += 1) {
1180
+ const character = destination[index];
1181
+ if (character === "\\") {
1182
+ if (index + 1 >= destination.length) return false;
1183
+ index += 1;
1184
+ continue;
1185
+ }
1186
+ if (character === "<" || character === ">") return false;
1187
+ if (character === "(") {
1188
+ parentheses += 1;
1189
+ } else if (character === ")") {
1190
+ if (parentheses === 0) return false;
1191
+ parentheses -= 1;
1192
+ }
1193
+ }
1194
+ return parentheses === 0;
1195
+ }
1196
+ function isMarkdownLinkReferenceDefinition(line) {
1197
+ const match = MARKDOWN_LINK_REFERENCE.exec(line);
1198
+ return match !== null && (match[1] === void 0 || isValidBareLinkDestination(match[1]));
1199
+ }
1200
+ function isMarkdownLinkReferenceDefinitionEnd(lines, index) {
1201
+ const line = lines[index]?.content ?? "";
1202
+ const boundaryLine = /^ {0,3}(?=\S)/.test(line) ? line.trimStart() : line;
1203
+ if (isMarkdownLinkReferenceDefinition(boundaryLine)) return true;
1204
+ if (MARKDOWN_LINK_REFERENCE_CONTINUATION.test(line)) {
1205
+ const previousLine2 = lines[index - 1]?.content ?? "";
1206
+ const previousBoundaryLine2 = /^ {0,3}(?=\S)/.test(previousLine2) ? previousLine2.trimStart() : previousLine2;
1207
+ if (isMarkdownLinkReferenceDefinition(previousBoundaryLine2)) return true;
1208
+ const destinationLine = lines[index - 1]?.content ?? "";
1209
+ if (!MARKDOWN_LINK_REFERENCE_DESTINATION_CONTINUATION.test(destinationLine)) return false;
1210
+ const labelLine = lines[index - 2]?.content ?? "";
1211
+ const labelBoundaryLine = /^ {0,3}(?=\S)/.test(labelLine) ? labelLine.trimStart() : labelLine;
1212
+ return MARKDOWN_LINK_REFERENCE_LABEL.test(labelBoundaryLine);
1213
+ }
1214
+ if (!MARKDOWN_LINK_REFERENCE_DESTINATION_CONTINUATION.test(line)) return false;
1215
+ const previousLine = lines[index - 1]?.content ?? "";
1216
+ const previousBoundaryLine = /^ {0,3}(?=\S)/.test(previousLine) ? previousLine.trimStart() : previousLine;
1217
+ return MARKDOWN_LINK_REFERENCE_LABEL.test(previousBoundaryLine);
1218
+ }
1219
+ function isProfileTitleLine(lines, index, line) {
1220
+ const titleLine = index === 0 && line.startsWith(UTF8_BOM) ? line.slice(1) : line;
1221
+ if (!PROFILE_TITLE.test(titleLine)) return false;
1222
+ const indentation = titleLine.length - titleLine.trimStart().length;
1223
+ if (indentation === 0 || index === 0) return true;
1224
+ const previousLine = lines[index - 1]?.content.trim() ?? "";
1225
+ return previousLine === "" ? !isNestedListContent(lines, index, indentation) : previousLine === "---" || previousLine === "...";
1226
+ }
1227
+ function findProfileTitleIndex(lines) {
1228
+ let titleIndex = -1;
1229
+ visitProfileMetadataLines(lines, (line, index) => {
1230
+ if (titleIndex >= 0) return;
1231
+ if (isProfileTitleLine(lines, index, line)) titleIndex = index;
1232
+ });
1233
+ return titleIndex;
1234
+ }
1235
+ function isSetextHeadingText(line) {
1236
+ const withoutBom = line.startsWith(UTF8_BOM) ? line.slice(1) : line;
1237
+ const boundaryLine = withoutBom.trim();
1238
+ return boundaryLine !== "" && !MARKDOWN_HEADING.test(boundaryLine) && !MARKDOWN_LIST_ITEM.test(boundaryLine) && !MARKDOWN_BLOCK_QUOTE.test(boundaryLine) && !MARKDOWN_THEMATIC_BREAK.test(boundaryLine) && !isMarkdownLinkReferenceDefinition(boundaryLine) && getFenceMarker(withoutBom) === null;
1239
+ }
1240
+ function isMetadataBoundary(line, htmlTerminator = false, allowSetext = true, allowParagraphListInterrupt = false, setextPreviousLine = "") {
1241
+ const listPattern = allowParagraphListInterrupt ? MARKDOWN_LIST_ITEM_CAN_INTERRUPT : MARKDOWN_LIST_ITEM;
1242
+ const boundaryLine = /^ {0,3}(?=\S)/.test(line) ? line.trimStart() : line;
1243
+ const isSetextUnderline = !allowSetext && MARKDOWN_SETEXT_UNDERLINE.test(boundaryLine) && isSetextHeadingText(setextPreviousLine);
1244
+ return line.trim() === "" || MARKDOWN_HEADING.test(boundaryLine) || listPattern.test(boundaryLine) || allowSetext && MARKDOWN_SETEXT_UNDERLINE.test(boundaryLine) || MARKDOWN_THEMATIC_BREAK.test(boundaryLine) && !isSetextUnderline || MARKDOWN_BLOCK_QUOTE.test(boundaryLine) || isMarkdownLinkReferenceDefinition(boundaryLine) || isLastUpdatedHeader(line) || getFenceMarker(line) !== null || htmlTerminator;
1245
+ }
1246
+ function isStandaloneMetadataLine(lines, index, frontmatterEnd, htmlTerminatorIndexes, fenceTerminatorIndexes, standaloneHeaderIndexes) {
1247
+ const currentLine = lines[index]?.content ?? "";
1248
+ const currentWithoutBom = currentLine.startsWith(UTF8_BOM) ? currentLine.slice(1) : currentLine;
1249
+ const indentation = currentWithoutBom.length - currentWithoutBom.trimStart().length;
1250
+ const previousLine = lines[index - 1]?.content.trimEnd() ?? "";
1251
+ const nextLine = lines[index + 1]?.content.trimEnd() ?? "";
1252
+ const previousWithoutBom = previousLine.startsWith(UTF8_BOM) ? previousLine.slice(1) : previousLine;
1253
+ const nextWithoutBom = nextLine.startsWith(UTF8_BOM) ? nextLine.slice(1) : nextLine;
1254
+ const previousLinkReferenceBoundary = isMarkdownLinkReferenceDefinitionEnd(lines, index - 1);
1255
+ const previousMetadataBoundary = isCompletedIndentedCodeBlock(lines, index) || previousLinkReferenceBoundary || fenceTerminatorIndexes.has(index - 1) || isMetadataBoundary(
1256
+ previousWithoutBom,
1257
+ htmlTerminatorIndexes.has(index - 1)
1258
+ ) && (!isLastUpdatedHeader(previousWithoutBom) || standaloneHeaderIndexes.has(index - 1));
1259
+ const nextHtmlBlockBoundary = isHtmlBlockBoundary(
1260
+ lines,
1261
+ index + 1,
1262
+ htmlTerminatorIndexes
1263
+ );
1264
+ const nextMetadataBoundary = nextHtmlBlockBoundary || isMetadataBoundary(
1265
+ nextWithoutBom,
1266
+ htmlTerminatorIndexes.has(index + 1),
1267
+ false,
1268
+ true,
1269
+ currentWithoutBom
1270
+ );
1271
+ const previousContainerMarker = !MARKDOWN_THEMATIC_BREAK.test(previousWithoutBom) && (MARKDOWN_LIST_ITEM.test(previousWithoutBom) || MARKDOWN_BLOCK_QUOTE.test(previousWithoutBom));
1272
+ const nestedListContent = indentation > 0 && isNestedListContent(lines, index, indentation);
1273
+ const startsBlock = (index === 0 || index === frontmatterEnd + 1 || previousMetadataBoundary) && !previousContainerMarker && !nestedListContent;
1274
+ const endsBlock = index === lines.length - 1 || nextMetadataBoundary;
1275
+ const compactHeaderAfterTitle = isProfileTitleLine(lines, index - 1, previousWithoutBom);
1276
+ const compactHeaderAfterHeader = isLastUpdatedHeader(previousWithoutBom) && standaloneHeaderIndexes.has(index - 1);
1277
+ return startsBlock && (endsBlock || compactHeaderAfterTitle || compactHeaderAfterHeader);
1278
+ }
1279
+ function findProfileHeaderIndexes(lines) {
1280
+ const indexes = [];
1281
+ const frontmatterEnd = findFrontmatterEnd(lines);
1282
+ const htmlTerminatorIndexes = /* @__PURE__ */ new Set();
1283
+ const fenceTerminatorIndexes = /* @__PURE__ */ new Set();
1284
+ const standaloneHeaderIndexes = /* @__PURE__ */ new Set();
1285
+ visitProfileMetadataLines(
1286
+ lines,
1287
+ (line, index) => {
1288
+ if (isLastUpdatedHeader(line) && isStandaloneMetadataLine(
1289
+ lines,
1290
+ index,
1291
+ frontmatterEnd,
1292
+ htmlTerminatorIndexes,
1293
+ fenceTerminatorIndexes,
1294
+ standaloneHeaderIndexes
1295
+ )) {
1296
+ indexes.push(index);
1297
+ standaloneHeaderIndexes.add(index);
1298
+ }
1299
+ },
1300
+ (index) => htmlTerminatorIndexes.add(index),
1301
+ (index) => fenceTerminatorIndexes.add(index)
1302
+ );
1303
+ return indexes;
1304
+ }
1305
+ function insertHeaderAfter(lines, index, header) {
1306
+ const insertAt = index + 1;
1307
+ const ending = lines[index]?.ending || lines[insertAt]?.ending || "\n";
1308
+ if (lines[insertAt]?.content.trim() === "") {
1309
+ lines.splice(
1310
+ insertAt + 1,
1311
+ 0,
1312
+ { content: header, ending },
1313
+ { content: "", ending }
1314
+ );
1315
+ } else {
1316
+ lines.splice(
1317
+ insertAt,
1318
+ 0,
1319
+ { content: "", ending },
1320
+ { content: header, ending },
1321
+ { content: "", ending }
1322
+ );
1323
+ }
1324
+ }
1325
+ function prependHeader(lines, header) {
1326
+ const frontmatterEnd = findFrontmatterEnd(lines);
1327
+ if (frontmatterEnd >= 0) {
1328
+ insertHeaderAfter(lines, frontmatterEnd, header);
1329
+ return renderProfileLines(lines);
1330
+ }
1331
+ const ending = lines[0]?.ending || "\n";
1332
+ if (lines[0]?.content.startsWith(UTF8_BOM)) {
1333
+ lines[0].content = lines[0].content.slice(1);
1334
+ lines.unshift(
1335
+ { content: `${UTF8_BOM}${header}`, ending },
1336
+ { content: "", ending }
1337
+ );
1338
+ return renderProfileLines(lines);
1339
+ }
1340
+ lines.unshift(
1341
+ { content: header, ending },
1342
+ { content: "", ending }
1343
+ );
1344
+ return renderProfileLines(lines);
1345
+ }
1346
+ function renderProfileWithLastUpdated(content, updatedAt) {
1347
+ const lines = parseProfileLines(content);
1348
+ const header = `*Last updated: ${updatedAt}*`;
1349
+ const titleIndex = findProfileTitleIndex(lines);
1350
+ const headerIndexes = findProfileHeaderIndexes(lines);
1351
+ if (headerIndexes.length > 0) {
1352
+ const firstHeaderIndex = headerIndexes[0];
1353
+ if (firstHeaderIndex === void 0) return renderProfileLines(lines);
1354
+ const canonicalIndex = titleIndex >= 0 ? headerIndexes.find((index) => index > titleIndex) ?? firstHeaderIndex : firstHeaderIndex;
1355
+ const preserveBomAtFileStart = headerIndexes.some(
1356
+ (index) => lines[index].content.startsWith(UTF8_BOM)
1357
+ );
1358
+ const bomPrefix = canonicalIndex === 0 && lines[canonicalIndex].content.startsWith(UTF8_BOM) ? UTF8_BOM : "";
1359
+ lines[canonicalIndex].content = `${bomPrefix}${header}`;
1360
+ for (let index = headerIndexes.length - 1; index >= 0; index -= 1) {
1361
+ const headerIndex = headerIndexes[index];
1362
+ if (headerIndex === void 0 || headerIndex === canonicalIndex) continue;
1363
+ lines.splice(headerIndex, 1);
1364
+ }
1365
+ if (preserveBomAtFileStart && !lines[0].content.startsWith(UTF8_BOM)) {
1366
+ lines[0].content = `${UTF8_BOM}${lines[0].content}`;
1367
+ }
1368
+ return renderProfileLines(lines);
1369
+ }
1370
+ if (titleIndex < 0) return prependHeader(lines, header);
1371
+ insertHeaderAfter(lines, titleIndex, header);
1372
+ return renderProfileLines(lines);
1373
+ }
1374
+
708
1375
  // src/orchestration/self-deps.ts
709
1376
  function selfDeps(self) {
710
1377
  const source = self;
@@ -6812,14 +7479,12 @@ ${sanitized.text}
6812
7479
  }
6813
7480
  }
6814
7481
  async writeProfile(content) {
7482
+ const stampedContent = renderProfileWithLastUpdated(content, (/* @__PURE__ */ new Date()).toISOString());
6815
7483
  await this.ensureDirectories();
6816
7484
  await this.snapshotBeforeWrite(this.profilePath, "consolidation");
6817
- await this.writeStorageSecureFile(this.profilePath, content);
7485
+ await this.writeStorageSecureFile(this.profilePath, stampedContent);
6818
7486
  log.debug("updated profile.md");
6819
7487
  }
6820
- /**
6821
- * Normalize a string for fuzzy profile dedup: lowercase, strip punctuation, collapse whitespace.
6822
- */
6823
7488
  static normalizeForDedup(s) {
6824
7489
  if (typeof s !== "string") return "";
6825
7490
  return s.toLowerCase().replace(/[^a-z0-9\s]/g, " ").replace(/\s+/g, " ").trim();
@@ -6855,15 +7520,12 @@ ${sanitized.text}
6855
7520
  const content = [
6856
7521
  "# Behavioral Profile",
6857
7522
  "",
6858
- `*Last updated: ${(/* @__PURE__ */ new Date()).toISOString()}*`,
6859
- "",
6860
7523
  ...newBullets.map((b) => `- ${b}`),
6861
7524
  ""
6862
7525
  ].join("\n");
6863
7526
  await this.writeProfile(content);
6864
7527
  } else {
6865
- const updatedTimestamp = existing.replace(/\*Last updated:.*\*/, `*Last updated: ${(/* @__PURE__ */ new Date()).toISOString()}*`);
6866
- const withBullets = updatedTimestamp.trimEnd() + "\n" + newBullets.map((b) => `- ${b}`).join("\n") + "\n";
7528
+ const withBullets = existing.trimEnd() + "\n" + newBullets.map((b) => `- ${b}`).join("\n") + "\n";
6867
7529
  await this.writeProfile(withBullets);
6868
7530
  }
6869
7531
  }
@@ -8982,4 +9644,4 @@ export {
8982
9644
  isValidBufferSurpriseEvent,
8983
9645
  StorageManager3 as StorageManager
8984
9646
  };
8985
- //# sourceMappingURL=chunk-K4DP5KZA.js.map
9647
+ //# sourceMappingURL=chunk-CIQXI47W.js.map