@inkeep/open-knowledge 0.83.0 → 0.84.0-beta.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 (192) hide show
  1. package/dist/assets/skills/project/SKILL.md +1 -1
  2. package/dist/assets/skills/project/references/linking.md +1 -1
  3. package/dist/cli.mjs +60 -60
  4. package/dist/constants-CJTSHFDQ.mjs +1 -0
  5. package/dist/dist-BUsVlOD-.mjs +1 -0
  6. package/dist/dist-BmMYmJrU.mjs +2212 -0
  7. package/dist/index.d.mts +8 -0
  8. package/dist/index.mjs +228 -226
  9. package/dist/init-6eE8auCX.mjs +1 -0
  10. package/dist/{init-0oLlE1YP.mjs → init-D29QcTZq.mjs} +55 -55
  11. package/dist/{launch-json-removal-COnVteTA.mjs → launch-json-removal-5ndYNGXL.mjs} +1 -1
  12. package/dist/{loader-1manjX2x.mjs → loader-CUPoyzHp.mjs} +1 -1
  13. package/dist/loader-CisLPZPW.mjs +1 -0
  14. package/dist/{md-manager-BGnqyqi1-IqwoPmS1.mjs → md-manager-BGnqyqi1-BfETHApY.mjs} +158 -156
  15. package/dist/native/native-config.win32-arm64-msvc.node +0 -0
  16. package/dist/native/native-config.win32-x64-msvc.node +0 -0
  17. package/dist/{open-browser-jE55xNly.mjs → open-browser-BM0E2IrX.mjs} +1 -1
  18. package/dist/parse-worker.mjs +1 -1
  19. package/dist/{preview-C5jJBQtN.mjs → preview-BfxmnsOn.mjs} +1 -1
  20. package/dist/preview-DQ-4J61L.mjs +1 -0
  21. package/dist/public/assets/{AccountSection-DTTPxtuy.js → AccountSection-BsoknTRm.js} +1 -1
  22. package/dist/public/assets/{ActivityModeContent-CQzz888N.js → ActivityModeContent-DZbyWBlo.js} +1 -1
  23. package/dist/public/assets/AddPropertiesButton-DvtOOL5J.js +2 -0
  24. package/dist/public/assets/{AgentConnectionsSection-CmOmHMSc.js → AgentConnectionsSection-D_gmSJG4.js} +1 -1
  25. package/dist/public/assets/{AgentDiffPane-C5rwquce.js → AgentDiffPane-D9olUVts.js} +1 -1
  26. package/dist/public/assets/{AttachmentsSection-CwdNONkc.js → AttachmentsSection-DdqsNOtE.js} +1 -1
  27. package/dist/public/assets/{AuthModal-D1eciNeA.js → AuthModal-CkHLmy_N.js} +1 -1
  28. package/dist/public/assets/CodeMirrorPropInput-BTCkQ8gy.js +166 -0
  29. package/dist/public/assets/{ContentRulesSection-DuNQpths.js → ContentRulesSection-BPc0bEex.js} +1 -1
  30. package/dist/public/assets/{DiffViewBoundary-DnPwZD0g.js → DiffViewBoundary-BVzts2c4.js} +1 -1
  31. package/dist/public/assets/DocumentContext-Cgpe7PUq.js +108 -0
  32. package/dist/public/assets/{EditorModeToggle-W5mm426e.js → EditorModeToggle-8PbuUKPX.js} +1 -1
  33. package/dist/public/assets/{ExcalidrawDocEditor-CW1j5GUX.js → ExcalidrawDocEditor-DPjKh0Z6.js} +1 -1
  34. package/dist/public/assets/FeedbackForm-w2RNhl0R.js +1 -0
  35. package/dist/public/assets/{GraphPanel-CpJ-EZeA.js → GraphPanel-COpuyFxT.js} +1 -1
  36. package/dist/public/assets/{ImageAttachments-ChGavHQ_.js → ImageAttachments-By1ZcRNT.js} +1 -1
  37. package/dist/public/assets/{ImportSkillDialog-DkTuvulO.js → ImportSkillDialog-BRMCNFIO.js} +1 -1
  38. package/dist/public/assets/{LinkPreviewsSection-BxmWF9rJ.js → LinkPreviewsSection-DrVzxhzA.js} +1 -1
  39. package/dist/public/assets/{LintConfigEditor-zLsWA0AF.js → LintConfigEditor-CYgb3HLw.js} +1 -1
  40. package/dist/public/assets/LintingSection-DwEExyYA.js +1 -0
  41. package/dist/public/assets/ManagedArtifactProperties-Cejw-D7l.js +1 -0
  42. package/dist/public/assets/ManagedArtifactProperties-sO6f840l.js +1 -0
  43. package/dist/public/assets/{MermaidDocEditor-BwSa_Kj7.js → MermaidDocEditor-TV8MQtbb.js} +1 -1
  44. package/dist/public/assets/{NetworkAccessSection-DS-N7ydZ.js → NetworkAccessSection-G-tyEPOW.js} +1 -1
  45. package/dist/public/assets/{OkignoreSection-B6lKSJGD.js → OkignoreSection-DUIPj4Vl.js} +1 -1
  46. package/dist/public/assets/PageListContext-CYKNvec7.js +1 -0
  47. package/dist/public/assets/{ProjectTemplatesSection-BgjUl8Rv.js → ProjectTemplatesSection-Ctdx9_AL.js} +1 -1
  48. package/dist/public/assets/{PropertyDisplayRow-DmCbpgtw.js → PropertyDisplayRow-DULpBoN1.js} +1 -1
  49. package/dist/public/assets/{PublishToGitHubDialog-BjbUw2by.js → PublishToGitHubDialog-BcpO5RKl.js} +1 -1
  50. package/dist/public/assets/{RegisteredAgentIcon-DHzxArZN.js → RegisteredAgentIcon-Begcc-nC.js} +1 -1
  51. package/dist/public/assets/{ReportBugDialogBody-CW-yLP7E.js → ReportBugDialogBody-CPjEs_zr.js} +1 -1
  52. package/dist/public/assets/{ReportBugMenuTrigger-D2RpbMHk.js → ReportBugMenuTrigger-DwuaKFu1.js} +1 -1
  53. package/dist/public/assets/{SchemaConfigEditor-Ds-Wwcpz.js → SchemaConfigEditor-D79vqFmf.js} +1 -1
  54. package/dist/public/assets/{SearchSection-DWQPLLZH.js → SearchSection-Dx8-C7aO.js} +1 -1
  55. package/dist/public/assets/{SessionsHost-Dy_wH2Wz.js → SessionsHost-DhB6vMF-.js} +2 -2
  56. package/dist/public/assets/{SettingsDialogBody-CEe2nLHS.js → SettingsDialogBody-BmlfRDFb.js} +2 -2
  57. package/dist/public/assets/{ShareReceiveMissDialog-CSwgOlOM.js → ShareReceiveMissDialog-0PE01E7W.js} +1 -1
  58. package/dist/public/assets/{SkillCostValue-DC_VaXgy.js → SkillCostValue-Bajv3P86.js} +1 -1
  59. package/dist/public/assets/{SkillForkDialog-DeoTv3wY.js → SkillForkDialog-BKGY1iRx.js} +1 -1
  60. package/dist/public/assets/{SkillInstallMenu-1E0cH5_q.js → SkillInstallMenu-CuOKJ4_n.js} +1 -1
  61. package/dist/public/assets/{SkillOriginInline-CLKoMHNo.js → SkillOriginInline-BrUb4Fgy.js} +1 -1
  62. package/dist/public/assets/{SkillToolbarControls-DNsDkeEV.js → SkillToolbarControls-CT26YXuL.js} +1 -1
  63. package/dist/public/assets/{SkillsManagerSection-DKedsWHo.js → SkillsManagerSection-dqXRCM3C.js} +1 -1
  64. package/dist/public/assets/{SlidesToolbarControls-BSKDSVIG.js → SlidesToolbarControls-D-0pa5F-.js} +1 -1
  65. package/dist/public/assets/SourceEditor-DghQVHvX.js +1 -0
  66. package/dist/public/assets/{SpellingSettings-CSLMKByF.js → SpellingSettings-C3y5UjRC.js} +1 -1
  67. package/dist/public/assets/{SyncSection-B-0xnMkA.js → SyncSection-DmMPCcrO.js} +1 -1
  68. package/dist/public/assets/{SyncStatusBadge-CH-ZxZGx.js → SyncStatusBadge-7CGaFHUk.js} +1 -1
  69. package/dist/public/assets/{TemplateRow-B2jVmQlY.js → TemplateRow-C8tLmbrb.js} +1 -1
  70. package/dist/public/assets/{TerminalLaunchContext-BReEuF5W.js → TerminalLaunchContext-58PQDilg.js} +1 -1
  71. package/dist/public/assets/{TerminalPanel-DQg3L4EK.js → TerminalPanel-DOYDhObX.js} +1 -1
  72. package/dist/public/assets/{TerminalSection-CW6bVoDJ.js → TerminalSection-BBA8y3S1.js} +1 -1
  73. package/dist/public/assets/{TerminalWindowApp-Cgr90cUf.js → TerminalWindowApp-DFmcq1vG.js} +1 -1
  74. package/dist/public/assets/{TextDocEditor-YUi-Iplf.js → TextDocEditor-DxghXof_.js} +1 -1
  75. package/dist/public/assets/{ThemePluginSection-Q9Vltk4w.js → ThemePluginSection-rW_Rhi3t.js} +1 -1
  76. package/dist/public/assets/{ThreadView-5gjgK_DM.js → ThreadView-BcdaDwyX.js} +5 -5
  77. package/dist/public/assets/{TimelineDiffPane-KqkBWswY.js → TimelineDiffPane-DbgES6nK.js} +1 -1
  78. package/dist/public/assets/{agent-connections-D-XX-7tC.js → agent-connections-Bc1t_U_m.js} +1 -1
  79. package/dist/public/assets/{agent-registry-CC-eSzdu.js → agent-registry-3ko3YkCm.js} +1 -1
  80. package/dist/public/assets/{bridge-1xVdv27q.js → bridge-BqL-1MyE.js} +1 -1
  81. package/dist/public/assets/{card-CUu_Dbtf.js → card-CHd8wMSS.js} +1 -1
  82. package/dist/public/assets/{catalog-DQ0C9DYn.js → catalog-nXBoyoEn.js} +1 -1
  83. package/dist/public/assets/{client-version-Dhdam9yn.js → client-version-uAhaPZPt.js} +1 -1
  84. package/dist/public/assets/{comment-chips-CXPOi5DO.js → comment-chips-D7PAXgFJ.js} +2 -2
  85. package/dist/public/assets/{config-provider-CA1b0otM.js → config-provider-DBgrt1kx.js} +1 -1
  86. package/dist/public/assets/config-schema-xOnB5jc5.js +1 -0
  87. package/dist/public/assets/{css-color-to-hex-Ds26W_X-.js → css-color-to-hex-Dk3DSeEK.js} +1 -1
  88. package/dist/public/assets/{doc-undo-manager-KJDEezHH.js → doc-undo-manager-DGQuNlgn.js} +1 -1
  89. package/dist/public/assets/{field-controls-Bm8W4dMo.js → field-controls-BqsFU6aY.js} +1 -1
  90. package/dist/public/assets/field-controls-CnF_w0df.js +1 -0
  91. package/dist/public/assets/{file-tree-adapter-B1gVPdEq.js → file-tree-adapter-BeSKxnyg.js} +1 -1
  92. package/dist/public/assets/{frontmatter-tags-BIkfDL6K.js → frontmatter-tags-B7FS--Ga.js} +1 -1
  93. package/dist/public/assets/index-C_8iI96N.js +2205 -0
  94. package/dist/public/assets/{lint-config-client-Dk5JUh5o.js → lint-config-client-C0cPUFg9.js} +1 -1
  95. package/dist/public/assets/{lint-plugins-D0OR2gqs.js → lint-plugins-24yMjYos.js} +1 -1
  96. package/dist/public/assets/{markdown-lint-BuIftP9_.js → markdown-lint-DxrbxECW.js} +1 -1
  97. package/dist/public/assets/{markdownlint-rule-browser-C_XoUwYX.js → markdownlint-rule-browser-C-vo_WXw.js} +1 -1
  98. package/dist/public/assets/messages-9pu0eKMD.js +1 -0
  99. package/dist/public/assets/messages-BCv3uDH5.js +1 -0
  100. package/dist/public/assets/messages-BGib4TMp.js +1 -0
  101. package/dist/public/assets/messages-BOWt1g5R.js +1 -0
  102. package/dist/public/assets/messages-BtwWpZz0.js +1 -0
  103. package/dist/public/assets/messages-BtzlQnhk.js +1 -0
  104. package/dist/public/assets/messages-BxPgHAGT.js +1 -0
  105. package/dist/public/assets/messages-C_IQGWPh.js +1 -0
  106. package/dist/public/assets/messages-CgvGzWvU.js +1 -0
  107. package/dist/public/assets/messages-CmBBJ_lX.js +1 -0
  108. package/dist/public/assets/messages-D07eucGp.js +1 -0
  109. package/dist/public/assets/messages-DHQmHLsP.js +1 -0
  110. package/dist/public/assets/messages-R6IvK1vE.js +1 -0
  111. package/dist/public/assets/navigation-targets-DTSxcGor.js +1 -0
  112. package/dist/public/assets/{page-list-cache-s0lTSAFU.js → page-list-cache-BNFVKu-D.js} +1 -1
  113. package/dist/public/assets/{pending-receive-nav-store-Cl__M2P3.js → pending-receive-nav-store-ge0q0US7.js} +1 -1
  114. package/dist/public/assets/{preferred-session-events-78C4kXpL.js → preferred-session-events-DZS0rMoL.js} +1 -1
  115. package/dist/public/assets/{progress-CxYYQVJg.js → progress-BXjvg4DI.js} +5 -5
  116. package/dist/public/assets/{saved-themes-client-B-8W7FeI.js → saved-themes-client-CmQnQ6kY.js} +1 -1
  117. package/dist/public/assets/{schema-section-BsG4UYYw.js → schema-section-eljmMDBb.js} +1 -1
  118. package/dist/public/assets/{schemas-api-KjBzkxAy.js → schemas-api-BM3O7zA1.js} +1 -1
  119. package/dist/public/assets/{selection-context-zIbsZWBB.js → selection-context-C68gF2Oq.js} +1 -1
  120. package/dist/public/assets/{skills-api-DfXaxEkX.js → skills-api-Cwv39pKK.js} +1 -1
  121. package/dist/public/assets/{src-CmVf3jdp.js → src-COG_7U42.js} +1 -1
  122. package/dist/public/assets/storage-scope-67lIepq6.js +1 -0
  123. package/dist/public/assets/{tag-pill-input-D_82NbMi.js → tag-pill-input-DoehfrBo.js} +1 -1
  124. package/dist/public/assets/{target-navigation-intent-DAN5F8dH.js → target-navigation-intent-D7IZjXLN.js} +1 -1
  125. package/dist/public/assets/{telemetry-impl-BOm8dXoA.js → telemetry-impl-C15v97Eo.js} +1 -1
  126. package/dist/public/assets/{telemetry-startup-B9kArDNb.js → telemetry-startup-B-aSb531.js} +1 -1
  127. package/dist/public/assets/{terminal-launch-events-BBXwmVEO.js → terminal-launch-events-vPUm3fxK.js} +1 -1
  128. package/dist/public/assets/typing-burst-detector-BKuWOIaA.js +8 -0
  129. package/dist/public/assets/{uninstall-CJslSGim.js → uninstall-DiNfurw6.js} +1 -1
  130. package/dist/public/assets/{use-activity-panel-njYj0Tyg.js → use-activity-panel-BgzoGLEn.js} +1 -1
  131. package/dist/public/assets/{use-apply-config-color-theme-DyzsFMYv.js → use-apply-config-color-theme-DsCyuU3O.js} +1 -1
  132. package/dist/public/assets/{use-apply-config-language-CJ2P6ZVJ.js → use-apply-config-language-BvXQKexF.js} +2 -2
  133. package/dist/public/assets/{use-conflicts-B9eHyj9o.js → use-conflicts-CpABgIGI.js} +1 -1
  134. package/dist/public/assets/{use-installed-clis-4inF6O-n.js → use-installed-clis-CXwm5pk2.js} +2 -2
  135. package/dist/public/assets/{use-live-xterm-theme-D9OrOkx3.js → use-live-xterm-theme-CkVAs5Ql.js} +1 -1
  136. package/dist/public/assets/{use-open-skill-BJ1g1TS4.js → use-open-skill-CDNmRdpj.js} +1 -1
  137. package/dist/public/assets/{use-semantic-search-status-BGdqXgED.js → use-semantic-search-status-BYu4PoVz.js} +1 -1
  138. package/dist/public/assets/{use-skill-origin-BqSrJPU6.js → use-skill-origin-Be1NTkgW.js} +1 -1
  139. package/dist/public/assets/{use-skill-targets-oy2zvORL.js → use-skill-targets-Cf23drqO.js} +1 -1
  140. package/dist/public/assets/{use-skills-CV4zn3OT.js → use-skills-gbn1t63C.js} +1 -1
  141. package/dist/public/assets/{use-terminal-enabled-oZoJIl77.js → use-terminal-enabled-CYPFWXCG.js} +1 -1
  142. package/dist/public/assets/{use-timeline-entry-diff-CRdNlwgo.js → use-timeline-entry-diff-Cb24Bjqb.js} +2 -2
  143. package/dist/public/assets/{use-workspace-Co3BqTgM.js → use-workspace-BafUpQnS.js} +1 -1
  144. package/dist/public/index.html +56 -56
  145. package/dist/public/uninstall.html +3 -3
  146. package/dist/registry-probes-NShX9Gbx.mjs +17 -0
  147. package/dist/{removal-file-path-BgjM5SuP.mjs → removal-file-path-BdSClBgZ.mjs} +1 -1
  148. package/dist/{repair-launch-json-DX0T39ky.mjs → repair-launch-json-C-OCcoOV.mjs} +1 -1
  149. package/dist/{repair-mcp-configs-CSuOjpAP.mjs → repair-mcp-configs-Ck7wXNVg.mjs} +1 -1
  150. package/dist/src-BPKOub-z.mjs +11 -0
  151. package/dist/src-CZcP6UNX.mjs +1 -0
  152. package/dist/{start-DmACO7Nh.mjs → start-CPHxqFwe.mjs} +3 -3
  153. package/dist/start-s51e4yCV.mjs +1 -0
  154. package/package.json +5 -5
  155. package/dist/constants-BrjqlEsS.mjs +0 -1
  156. package/dist/dist-BrWQNlOF.mjs +0 -2198
  157. package/dist/dist-DuSuuwp2.mjs +0 -1
  158. package/dist/init-Caw9z0RZ.mjs +0 -1
  159. package/dist/loader-OSwfQPyG.mjs +0 -1
  160. package/dist/preview-P8UzNPlh.mjs +0 -1
  161. package/dist/public/assets/AddPropertiesButton-sAtpD3bF.js +0 -2
  162. package/dist/public/assets/CodeMirrorPropInput-DNYs7K0K.js +0 -164
  163. package/dist/public/assets/DocumentContext-CDwWviYm.js +0 -108
  164. package/dist/public/assets/FeedbackForm-DXTFUuAS.js +0 -1
  165. package/dist/public/assets/LintingSection-BZWdGarX.js +0 -1
  166. package/dist/public/assets/ManagedArtifactProperties-C5jRvpCl.js +0 -1
  167. package/dist/public/assets/ManagedArtifactProperties-ColnuPUV.js +0 -1
  168. package/dist/public/assets/PageListContext-OHnhzUbe.js +0 -1
  169. package/dist/public/assets/SourceEditor-BlbcJdBG.js +0 -1
  170. package/dist/public/assets/config-schema-CxzfSS_F.js +0 -1
  171. package/dist/public/assets/field-controls-mmRmxoOm.js +0 -1
  172. package/dist/public/assets/index-CggMAzzQ.js +0 -2205
  173. package/dist/public/assets/messages-BN4BZRJF.js +0 -1
  174. package/dist/public/assets/messages-BwUT5OR_.js +0 -1
  175. package/dist/public/assets/messages-BwfMRpDZ.js +0 -1
  176. package/dist/public/assets/messages-C-u__l_6.js +0 -1
  177. package/dist/public/assets/messages-CP3ZhE7d.js +0 -1
  178. package/dist/public/assets/messages-CWh_KhcE.js +0 -1
  179. package/dist/public/assets/messages-CqZP9U4h.js +0 -1
  180. package/dist/public/assets/messages-D8MF6gQm.js +0 -1
  181. package/dist/public/assets/messages-DXuxFgle.js +0 -1
  182. package/dist/public/assets/messages-Dh4iAG8x.js +0 -1
  183. package/dist/public/assets/messages-Dwjpql-D.js +0 -1
  184. package/dist/public/assets/messages-VQrT5xuZ.js +0 -1
  185. package/dist/public/assets/messages-cWliijXA.js +0 -1
  186. package/dist/public/assets/navigation-targets-BVafzc0v.js +0 -1
  187. package/dist/public/assets/storage-scope-BVU9p11A.js +0 -1
  188. package/dist/public/assets/typing-burst-detector-B5w8ea1t.js +0 -8
  189. package/dist/registry-probes-TTIv_jQo.mjs +0 -17
  190. package/dist/src-Ap_2wxuM.mjs +0 -11
  191. package/dist/src-DuIWze9R.mjs +0 -1
  192. package/dist/start-vg8tMVqI.mjs +0 -1
@@ -1 +0,0 @@
1
- import{g as e,h as t,p as n,y as r}from"./constants-upload-CVKO8P4d.js";import{C as i,S as a,_ as o,b as s,d as c,g as l,h as u,m as d,v as f,w as p,x as m,y as h}from"./constants-cc1-Bt4QPTUe.js";import{t as g}from"./doc-extensions-CcO7K8uD-B004ggqh.js";import{r as _}from"./doc-paths-cEiFVCxr.js";import{o as v,r as ee}from"./file-tree-utils-DUpeRMj2.js";var y=524288;function b(e,t=y){return typeof e==`number`&&Number.isFinite(e)&&e>t}var te=10485760,x=/\p{M}+/gu,ne=/[^\p{L}\p{N}]+/gu,re=/^-+|-+$/g;function S(e){return e.trim().normalize(`NFKD`).replace(x,``).toLowerCase().replace(ne,`-`).replace(re,``)}function C(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}-${n}`}function w(e,t){let n=S(e);return n?C(n,t):``}function T(e,t){let n=S(e);return t?`#${n}-${S(t)}`:`#${n}`}function E(e){if(!e.includes(`%`))return e;let t;try{t=decodeURIComponent(e)}catch{return e}return t===`.`||t===`..`||t.includes(`/`)||t.includes(`\\`)||t.includes(`\0`)?e:t}function ie(e){return e===`.`||e===`..`?e:encodeURIComponent(e).replace(/[!'()*]/g,e=>`%${e.codePointAt(0)?.toString(16).toUpperCase()}`)}function ae(e){return e.split(`/`).map(ie).join(`/`)}function D(e){return e.split(`/`).map(E).join(`/`)}function O(e,t){let n=e.trim();if(!n||/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),a=r>=0?n.slice(0,r):n,o=r>=0?n.slice(r+1):null,s=(a.split(`?`)[0]??``).trim();if(!s)return null;let c=E(s.split(`/`).pop()??``).match(/\.([a-z0-9]+)$/i);if(c){let e=`.${(c[1]??``).toLowerCase()}`;if(!g.includes(e))return null}let l=s.startsWith(`/`),u=l?s.slice(1):s,d=l?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[],f=u.split(`/`),p=f.length-1;for(let e=0;e<f.length;e++){let t=E(f[e]??``);if(e===p&&(t=i(t)),t===`..`){if(d.length===0)return null;d.pop()}else t!==`.`&&t!==``&&d.push(t)}return d.length===0?null:{docName:d.join(`/`),anchor:o||null}}function oe(e){throw Error(`Unhandled ClassifiedLinkTarget variant: ${JSON.stringify(e)}`)}var k=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function A(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function j(e){return e.split(`/`).filter(Boolean)}function M(e){let t=e.trim();return k.test(t)||t.startsWith(`//`)}function se(e,t){let n=e.trim();if(!n)return null;if(n.startsWith(`#`)){let e=n.slice(1).trim();return e?{kind:`anchor`,anchor:e}:null}if(M(n))return{kind:`external`,url:n};let r=n.indexOf(`#`),i=D(r<0?n:n.slice(0,r)),a=h(i,t);if(a)return{kind:`doc`,docName:a,anchor:r<0?null:n.slice(r+1)};let o=s(i,t);if(o)return{kind:`doc`,docName:o,anchor:r<0?null:n.slice(r+1)};let c=O(n,t);if(c)return{kind:`doc`,docName:c.docName,anchor:c.anchor};let l=A(i);return l&&l!==`md`&&l!==`mdx`?{kind:`asset`,url:n,ext:l,literal:!1}:null}function ce(e,t){let n=e.trim();if(!n)return null;if(M(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=A(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r,literal:!0}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function le(e,t,n){let r=e.trim();if(!r||k.test(r)||r.startsWith(`//`)||r.startsWith(`#`))return null;let i=r.indexOf(`#`),a=((i>=0?r.slice(0,i):r).split(`?`)[0]??``).trim();if(!a)return null;let o=a.startsWith(`/`),s=o?a.slice(1):a,c=o?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of s.split(`/`))if(e===`..`){if(c.length===0)return null;c.pop()}else e!==`.`&&e!==``&&c.push(n.literal?e:E(e));return c.length===0?null:c.join(`/`)}function ue(e,t,n=null,r=`.md`){let i=j(e);i.pop();let a=j(t),o=0;for(;o<i.length&&o<a.length&&i[o]===a[o];)o+=1;let s=i.slice(o).map(()=>`..`),c=a.slice(o),l=[...s,...c].join(`/`);return l||=a.at(-1)??t,!l.startsWith(`./`)&&!l.startsWith(`../`)&&(l=`./${l}`),`${ae(l)}${r}${n?`#${n}`:``}`}function N(e){return`pagesBySlug`in e}function P(e){return N(e)?e.pages:e}function F(e,t){return N(e)?e.assetPaths??new Set:t??new Set}function I(e,t){return N(e)?e.filePaths??new Set:t??new Set}function L(e,t){return e<t?-1:+(e>t)}function R(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);e&&(i===void 0||L(r,i)<0)&&n.set(e,r)}return n}function z(e,t){let n=new Map,r=[...e].sort(L);for(let e of r){let r=e.lastIndexOf(`/`),i=t(r===-1?e:e.slice(r+1));i&&!n.has(i)&&n.set(i,e)}return n}function B(e,t){let n=S(e);if(!n)return;if(N(t))return t.pagesBySlug.get(n);let r;for(let e of t)S(e)===n&&(r===void 0||L(e,r)<0)&&(r=e);return r}function V(e,t){if(e.includes(`/`))return;let n=S(e);if(!n)return;if(N(t))return t.pagesByBasename?.get(n);let r;for(let e of t){let t=e.lastIndexOf(`/`);S(t===-1?e:e.slice(t+1))===n&&(r===void 0||L(e,r)<0)&&(r=e)}return r}function H(e){let t=e.trim();if(!t)return[];let n=S(t);return n.length>0&&n!==t?[n]:[]}function U(e,t){let n=e.trim();if(!n)return;if(P(t).has(n))return n;let r=n.replace(/\.(md|mdx)$/i,``);if(r!==n){let e=W(r,t);if(e!==void 0)return e}return W(n,t)}function W(e,t){let n=e.trim();if(!n)return;let r=P(t);if(r.has(n))return n;let i=B(n,t);if(i)return i;for(let e of H(n))if(r.has(e))return e;return de(n,r)||V(n,t)}function de(e,t){let n=`${e}/index`;if(t.has(n))return n;let r=e.lastIndexOf(`/`),i=r===-1?e:e.slice(r+1),a=i?`${e}/${i}`:null;if(a&&t.has(a))return a}function G(e){let t=((e.trim().split(`#`)[0]??``).trim().split(`?`)[0]??``).trim();return t.startsWith(`/`)?t.slice(1):t}function K(e,t,n){let r=G(e);if(!r)return null;let i=r.toLowerCase(),a=n?[t,n]:[t];for(let e of a){if(e.has(r))return r;for(let t of e)if(t.toLowerCase()===i)return t}if(r.includes(`/`))return null;let o=[];for(let e of a)for(let t of e){let e=t.lastIndexOf(`/`);(e===-1?t:t.slice(e+1)).toLowerCase()===i&&o.push(t)}return o.length===0?null:o.sort(L)[0]??null}function fe(...e){let t=new Set;for(let n of e)for(let e of n){let n=e.toLowerCase();t.add(`path:${n}`),t.add(`basename:${n.slice(n.lastIndexOf(`/`)+1)}`)}return t}function pe(e,t,n,r){let i=e.trim();if(!i)return!1;let a=G(i).toLowerCase(),o=N(t)?t.assetTargetKeys:void 0;if(o!==void 0){if(o.has(`path:${a}`)||!a.includes(`/`)&&o.has(`basename:${a}`))return!0}else if(K(i,F(t,n),I(t,r)))return!0;return U(i,t)!==void 0}function me(e,t,n){let r=ce(e,t);return r===null||r.kind!==`asset`||K(r.url,F(n),I(n))!==null||U(e,n)===void 0?r:{kind:`doc`,docName:e.trim(),anchor:t?.trim()||null}}function he(e){return e.scope===`project`?i(q(e)):a(e.scope,e.name,e.hostQualifier)}function q(e){return e.canonicalPath??e.path}function ge(e,t){return e.scope===`project`?`${q(e).replace(/\/SKILL\.mdx?$/i,``)}/${i(t)}`:m(e.scope,e.name,t,e.hostQualifier)}function J(e){let t=l(e);return t?.kind===`skill`?t.name:null}function Y(e){let t=e.trim();return{normalizedTarget:t.replace(/^\.\/+/,``).replace(/^\/+/,``).replace(/\/+$/g,``),expectsFolder:/\/+$/.test(t)}}function _e(e){return _(e).replace(/\/+$/g,``)}var X=/\.(md|mdx)$/i;function ve(e,t){let{normalizedTarget:n,expectsFolder:r}=Y(e);return r||!X.test(n)||t.has(n)?e:n.replace(X,``)}function Z(e){let t=new Set;for(let n of e)for(let e of ee(n))t.add(e);return t}function ye(e,t){return t?`${e}${t}`:(e.split(`/`).pop()??``).lastIndexOf(`.`)>0?e:`${e}.md`}function Q(t,n){if(!v(t)||o(t)||n.pages.has(t))return null;let r=ye(t,n.docExt);return{kind:`asset`,target:r,assetPath:r,mediaKind:e(r.slice(r.lastIndexOf(`.`)+1))}}function be(e,i){let a=e,s=ve(a,i.pages);if(c(s)){let e=u(s);if(e?.kind===`skill`&&e.scope===`project`){let t=f(e.name);return{kind:`doc`,target:t,docName:t}}let t=d(s);if(t){let e=p(t.folder,t.name);return{kind:`doc`,target:e,docName:e}}return{kind:`doc`,target:s,docName:s}}if(J(s))return{kind:`doc`,target:s,docName:s};let l=o(s);if(l){let e=p(l.folder,l.name);return{kind:`doc`,target:e,docName:e}}let{normalizedTarget:m,expectsFolder:h}=Y(a);if(!m)return{kind:`missing`,target:m};if(!h&&(t(m)||n(m)||r(m)))return{kind:`doc`,target:m,docName:m};let g=_e(a),_=h?void 0:U(m,{pages:i.pages,pagesBySlug:i.pagesBySlug??new Map,pagesByBasename:i.pagesByBasename}),v=h?[g]:[m,g];for(let e of v){let t=`${e}/index`;if(h?i.pages.has(t):_===t)return{kind:`folder-index`,target:e,folderPath:e,docName:t,noteKind:`canonical-index`};let n=e.split(`/`).pop(),r=n?`${e}/${n}`:null;if(r&&(h?i.pages.has(r):_===r))return{kind:`folder-index`,target:e,folderPath:e,docName:r,noteKind:`legacy-folder-note`}}if(_!==void 0)return{kind:`doc`,target:_,docName:_};if((i.folderPaths??Z(i.pages)).has(g))return{kind:`folder`,target:g,folderPath:g};if(!h){let e=Q(m,i);if(e)return e}return{kind:`missing`,target:g||m}}function xe(e){return e.kind===`folder-index`?{kind:`folder`,target:e.folderPath,folderPath:e.folderPath}:e}function $(e,t,n=y){return typeof t!=`number`||!b(t,n)?null:{kind:`large-file`,target:e,docName:e,size:t,limit:n}}function Se(e,t,n=y){return e.kind!==`doc`&&e.kind!==`folder-index`?e:$(e.docName,t.get(e.docName)?.size,n)??e}function Ce(e){switch(e.kind){case`doc`:case`folder-index`:case`large-file`:return e.docName;case`missing`:return e.target;case`asset`:case`skill-file`:case`skills`:case`skill-preview`:case`folder`:return null}}export{te as A,M as C,w as D,O as E,S as O,A as S,D as T,me as _,Q as a,ue as b,J as c,z as d,R as f,K as g,pe as h,$ as i,b as j,T as k,ge as l,H as m,Ce as n,be as o,fe as p,xe as r,Se as s,Z as t,he as u,U as v,le as w,se as x,oe as y};
@@ -1 +0,0 @@
1
- import{o as e}from"./bridge-1xVdv27q.js";function t(e,t){return t===null?e:`${e}:${n(t)}`}function n(t){return e(t)}export{t as n,n as t};
@@ -1,8 +0,0 @@
1
- import{o as e}from"./chunk-CYidjpOJ.js";import{t}from"./jsx-runtime-BUgB2tll.js";import{L as n,Nn as r,Rn as i,Rt as a,Xn as o,fr as s,i as c,kn as l,pn as u,si as d,ui as f,vr as p,zt as m}from"./DocumentContext-CDwWviYm.js";import{t as h}from"./react-f2sANaYj.js";import{n as g,r as _}from"./dist-Nvb76hAm.js";import{r as v,t as y}from"./useQuery-ZeEDLtxh.js";import{t as b}from"./compiler-runtime-BfE3aGVn.js";import{t as x}from"./utils-CPqDy6Hr.js";import{i as S,n as C,t as w}from"./tooltip-DBqLYfio.js";import{n as T,r as E,t as D}from"./collapsible-BKbszYZV.js";import{n as O,t as k}from"./toggle-group-B7p69Qfd.js";import{t as A}from"./button-DzgjsZzC.js";import{y as j}from"./constants-upload-CVKO8P4d.js";import{n as M}from"./dist-BGzUo_18.js";import{t as N}from"./dist-C_FzPxEX2.js";import{d as P}from"./constants-cc1-Bt4QPTUe.js";import{f as F,v as I}from"./documents-events-C04vpPEp.js";import{C as L,ht as ee,vt as R}from"./schemas-api-KjBzkxAy.js";import{n as z}from"./_envelope-Dwl6i2K9-DPqJ_Q4W.js";import{t as B}from"./note-window-mode-CI3Yju9B.js";import{t as V}from"./createLucideIcon-DdBzwsHe.js";import{t as H}from"./chevron-right-Bofu4lib.js";import{n as U,t as te}from"./lint-plugin-meta-CtDE2R0v.js";import{t as W}from"./circle-alert-eBm4JPxY.js";import{S as G,Un as K,Vn as q,ar as J,ct as ne,dt as Y,nn as X,sr as re,tt as ie,ur as ae}from"./CodeMirrorPropInput-DNYs7K0K.js";import{t as oe}from"./info-CyR0W2SK.js";import{t as se}from"./refresh-cw-CC7UZEnZ.js";import{t as ce}from"./sparkles-BS2TX_Um.js";import{t as le}from"./triangle-alert-BXrUEeRU.js";import{t as ue}from"./wrench-DqFwoSdV.js";import{t as de}from"./badge-DmdA1C7r.js";import{c as fe}from"./use-settings-route-DT86DJkF.js";import{l as pe,s as me}from"./doc-hash-BJkweiX9.js";import{t as he}from"./diagnostic-breadcrumb-Cr0C15nJ.js";import{n as ge,t as _e}from"./perf-DZJpLc5j.js";import{D as ve}from"./navigation-targets-BVafzc0v.js";import{C as ye,y as be}from"./config-provider-CA1b0otM.js";import{J as xe,K as Se,Mt as Ce,Nt as we,X as Te,wt as Ee}from"./dist-D2SphF3p.js";import{n as De,r as Oe}from"./PageListContext-OHnhzUbe.js";import{a as ke,c as Ae,i as je,n as Me,r as Ne,s as Pe,t as Fe}from"./panel-My61A8fk.js";import{d as Ie,h as Le,u as Re,y as ze}from"./markdown-lint-BuIftP9_.js";import{t as Be}from"./skeleton-BPb29aFG.js";import{a as Ve,c as He,d as Ue}from"./lint-config-client-Dk5JUh5o.js";var We=V(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),Ge=56,Ke=2,qe=150,Je=2e3;function Ye(e,t,n){return e.top+e.height/2-(n+t)/2}function Xe(e,t){let n=Math.max(0,t.scrollHeight-t.clientHeight);return Math.max(0,Math.min(e,n))}function Ze(e){let{docName:t,container:n,measureTarget:a,placement:o,intent:s,grade:c,landedMode:u,transition:d,onOutcome:f,onDiscardQueuedTarget:p,toolbarOffset:m=Ge,driftThresholdPx:h=Ke,quietMs:g=qe,abandonAfterMs:_=Je}=e,v=e.contentColumn??n.firstElementChild,y=l(t,`landing`),b=r(t,{yieldsToNavigation:s===`toggle`,supersede:()=>P(`superseded`)}),x=n.style.overflowAnchor;n.style.overflowAnchor=`none`,d&&ge(`ok/mode-switch/transition`,{from:d.from,to:d.to,grade:c});let S=!1,C=null,w,T,E=0,D,O=()=>{let e=a();return e===null?null:Xe(o===`center`?Ye(e,n.clientHeight,m):e.top-m,n)},k=()=>{let e=O();if(e===null)return{measurable:!1,moved:!1};C=e;let t=Math.abs(n.scrollTop-e)>h;return t&&(n.scrollTop=e),{measurable:!0,moved:t}},A=()=>n.scrollTop-(O()??C??n.scrollTop),j=()=>{w&&clearTimeout(w),T&&clearTimeout(T),E&&cancelAnimationFrame(E),D?.disconnect(),n.removeEventListener(`wheel`,I),n.removeEventListener(`touchstart`,I),n.removeEventListener(`contentvisibilityautostatechange`,L,!0),n.style.overflowAnchor=x,y.release(),b.release()},M=()=>{if(S)return;S=!0;let e;try{k(),e=A(),C!==null&&i({docName:t,container:n,targetScrollTop:n.scrollTop,mode:u})}finally{j()}ge(`ok/landing/land`,{grade:c,delta:e}),f?.({status:`landed`,delta:e})},N=()=>{if(S)return;S=!0;let e=C??n.scrollTop,t;try{t=A()}finally{j()}ge(`ok/landing/abandoned`,{grade:c,target:e,delta:t}),f?.({status:`abandoned`,delta:t})},P=e=>{S||(S=!0,j(),e===`mode-flip`&&p?.(),f?.({status:`cancelled`,reason:e}))},F=()=>{w&&clearTimeout(w),w=setTimeout(M,g)};function I(){P(`user-scroll`)}function L(){if(S)return;let{measurable:e,moved:t}=k();e&&(t||w===void 0)&&F()}try{k().measurable&&F(),n.addEventListener(`contentvisibilityautostatechange`,L,!0),n.addEventListener(`wheel`,I,{passive:!0}),n.addEventListener(`touchstart`,I,{passive:!0}),typeof ResizeObserver<`u`&&v&&(D=new ResizeObserver(L),D.observe(v)),E=requestAnimationFrame(L),T=setTimeout(N,_)}catch(e){throw S=!0,j(),e}return{cancel:P}}function Qe(e){switch(e){case`bulletList`:case`orderedList`:case`taskList`:case`list`:return`list`;case`codeBlock`:case`code`:return`code`;case`horizontalRule`:case`thematicBreak`:return`thematicBreak`;case`jsxComponent`:case`mdxJsxFlowElement`:case`mdxJsxTextElement`:return`jsx`;case`htmlBlock`:case`html`:return`html`;default:return e}}function $e(e){return typeof e!=`object`||!e?``:`value`in e&&typeof e.value==`string`?e.value:`children`in e&&Array.isArray(e.children)?e.children.map($e).join(``):``}function et(e,t){let{frontmatter:n,body:r}=R(e),i=n===``?0:n.split(`
2
- `).length-1;try{return{blocks:t.parseToEditorMdast(r).children.map(e=>({start:(e.position?.start.line??1/0)+i,end:(e.position?.end.line??-1/0)+i,kind:Qe(e.type),text:$e(e)})),fmLineCount:i}}catch{return performance.mark(`ok/block-spans/parse-failed`),{blocks:[],fmLineCount:i}}}function tt(e,t){let{blocks:n,fmLineCount:r}=et(e,t);return{spans:n.map(e=>({start:e.start,end:e.end})),fmLineCount:r}}function nt(e,t){if(e.length===0)return null;let n=0,r=e.length-1,i=e.length-1;for(;n<=r;){let a=n+r>>1,o=e[a];o!==void 0&&o.end>=t?(i=a,r=a-1):n=a+1}return i}function rt(e){let t=0;for(let n=e.childCount-1;n>=0;n--){let r=e.child(n);if(r.type.name!==`paragraph`||r.content.size!==0)break;t++}return t===e.childCount?0:e.childCount}function it(e,t,n){let r=e.childCount,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));if(a<=i)return null;let o=0;for(let t=0;t<i;t++)o+=e.child(t).nodeSize;let s=o;for(let t=i;t<a;t++)o+=e.child(t).nodeSize;let c=o,l=e.content.size,u=Math.max(0,Math.min(s,l)),d=Math.max(u,Math.min(c,l));return d<=u?null:{from:u,to:d}}function at(e){let t=[0];for(let n=0;n<e.length;n++)e[n]===`
3
- `&&t.push(n+1);return t}function ot(e,t,n){return t<=1?0:t-1>=e.length?n:e[t-1]??n}function st(e,t){let n=0,r=e.length-1,i=1;for(;n<=r;){let a=n+r>>1;(e[a]??0)<=t?(i=a+1,n=a+1):r=a-1}return i}function ct(e,t,n){return Math.max(t,Math.min(e,n))}function lt(e,t){let n=e=>e.replace(/\s+/g,` `).trim();return n(e)===n(t)}function ut(e,t){return t.inRange?t.tripwireOk?lt(e.content,t.text)?`exact`:e.kind===t.kind?`same-type-ordinal`:`ordinal`:`ordinal`:`clamped`}function dt(e){let t=null,n=null;function r(r){return n!==null&&t===r?n:(n={blocks:et(r,e).blocks,lineStarts:at(r)},t=r,n)}return{captureFromWysiwyg(e,t,n){if(e.childCount===0)return null;let r=ct(t,0,e.content.size),i=0,a=e.childCount-1,o=0;for(let t=0;t<e.childCount;t++){let n=e.child(t).nodeSize;if(r<i+n){a=t,o=i+1;break}i+=n,o=i+1}let s=e.child(a),c={blockIndex:a,kind:Qe(s.type.name),content:s.textContent};return n?.refine&&(c.selectionInBlock=Math.max(0,r-o)),c},captureFromSource(e,t,n){let{blocks:i,lineStarts:a}=r(e);if(i.length===0)return null;let o=ct(t,0,e.length),s=nt(i,st(a,o));if(s===null)return null;let c=i[s];if(!c)return null;let l={blockIndex:s,kind:c.kind,content:c.text};if(n?.refine){let t=ot(a,c.start,e.length);l.selectionInBlock=Math.max(0,o-t)}return l},resolveInSource(e,{source:t,doc:n}){let{blocks:i,lineStarts:a}=r(t);if(i.length===0)return null;let o=e.blockIndex>=0&&e.blockIndex<i.length,s=rt(n)===i.length,c=i[ct(e.blockIndex,0,i.length-1)],l=ot(a,c.start,t.length),u=Math.min(ot(a,c.end+1,t.length),t.length),d=ut(e,{inRange:o,tripwireOk:s,kind:c.kind,text:c.text}),f=l;return d===`exact`&&e.selectionInBlock!==void 0&&(f=ct(l+e.selectionInBlock,l,u)),{blockStart:l,blockEnd:u,point:f,confidence:d}},resolveInWysiwyg(e,{source:t,doc:n}){let i=rt(n);if(i===0)return null;let{blocks:a}=r(t),o=e.blockIndex>=0&&e.blockIndex<i,s=i===a.length,c=ct(e.blockIndex,0,i-1),l=it(n,c,c+1);if(l===null)return null;let u=n.child(c),d=ut(e,{inRange:o,tripwireOk:s,kind:Qe(u.type.name),text:u.textContent});return{blockStart:l.from,blockEnd:l.to,point:l.from,confidence:d}}}}var ft=Ce.define(),pt=Ce.define(),mt=Se.mark({class:a}),ht=we.define({create(){return Se.none},update(e,t){let n=e.map(t.changes);for(let e of t.effects)e.is(ft)?n=Se.set([mt.range(e.value.from,e.value.to)]):e.is(pt)&&(n=Se.none);return n},provide:e=>xe.decorations.from(e)}),gt=new WeakMap,_t=Te.define(e=>({destroy(){let t=gt.get(e);t!==void 0&&(clearTimeout(t),gt.delete(e))}}));function vt(e,t,n,r){let i=m(e.state.doc.length,t,n,r);if(!i)return;e.dispatch({effects:ft.of(i)});let a=gt.get(e);a!==void 0&&clearTimeout(a);let o=setTimeout(()=>{gt.delete(e),e.dispatch({effects:pt.of(null)})},ne);gt.set(e,o)}function yt(){return[ht,_t]}var bt=3e4;function xt(){let e=new Map,t=e=>e?Date.now()-e.rememberedAt>bt?null:e.navigation:null;return{remember(t,n){e.set(t,{navigation:n,rememberedAt:Date.now()})},peek(n){return t(e.get(n))},consume(n){let r=e.get(n);return e.delete(n),t(r)},clear(t){e.delete(t)},clearForTest(){e.clear()}}}var St=xt(),Ct=xt(),wt=St.remember,Tt=St.peek,Et=St.consume,Dt=St.clear;St.clearForTest;var Ot=Ct.remember,kt=Ct.peek,At=Ct.consume,jt=Ct.clear;Ct.clearForTest;function Mt(e,t,n){return{start:ye(e,t),end:ye(e,n)}}function Nt(e,t){let n=be(e.start,t),r=be(e.end,t);return n===null||r===null||r.index<=n.index?null:n.index}var Pt=`open-knowledge:view-in-source`,Ft=null;function It(){return Ft??=dt(ie()),Ft}function Lt(e,t,n,r,i=`toggle`){let a=r.captureFromWysiwyg(e,t,{refine:i===`jump`});if(!a)return null;let o=r.resolveInSource(a,{source:n.toString(),doc:e});return{kind:`selection-offset`,intent:i,anchor:a,pin:o?Mt(n,o.blockStart,o.blockEnd):void 0}}function Rt(e){let{editor:t,docName:n,ytext:r}=e,i=J(t);if(!i)return;let a=i.state.selection.from,o=Lt(i.state.doc,a,r,It(),`jump`);o&&wt(n,o),window.dispatchEvent(new CustomEvent(Pt,{detail:{docName:n}}))}function zt(e,t,n,r,i){let a=r.captureFromSource(e,t);if(!a)return null;let o=i?r.resolveInSource(a,{source:e,doc:i}):null;return{kind:`selection-offset`,anchor:a,pin:o?Mt(n,o.blockStart,o.blockEnd):void 0}}function Bt(e,t){let{source:n,pmDoc:r,ydoc:i,resolver:a}=t;if(e.pin){let t=Nt(e.pin,i);if(t===null){let t=a.resolveInWysiwyg(e.anchor,{source:n,doc:r});return t?{...t,point:t.blockStart,confidence:`clamped`}:null}let o=a.captureFromSource(n,t);if(o)return a.resolveInWysiwyg(o,{source:n,doc:r})}return a.resolveInWysiwyg(e.anchor,{source:n,doc:r})}function Vt(e,t){let{source:n,pmDoc:r,ydoc:i,resolver:a}=t;if(e.pin){let t=Nt(e.pin,i);if(t===null){let t=a.resolveInSource(e.anchor,{source:n,doc:r});return t?{...t,point:t.blockStart,confidence:`clamped`}:null}let o=a.captureFromSource(n,t);if(o)return a.resolveInSource(o,{source:n,doc:r})}return a.resolveInSource(e.anchor,{source:n,doc:r})}function Ht(e,t){try{return e.coordsAtPos(t)}catch{return null}}function Ut(e,t,n){let r=Math.max(0,Math.min(n,e.state.doc.length)),i=t.getBoundingClientRect().top,a=Ht(e,r);if(a)return{top:a.top-i+t.scrollTop,height:a.bottom-a.top};try{let n=e.lineBlockAt(r);return{top:e.documentTop-i+t.scrollTop+n.top,height:n.height}}catch{return null}}function Wt(e,t){if(e.isDestroyed)return null;try{let n=e.nodeDOM(t);if(n instanceof HTMLElement)return n;let{node:r}=e.domAtPos(t);return r instanceof HTMLElement?r:r.parentElement}catch{return null}}function Gt(e,t,n){if(e.isDestroyed)return null;let r=Wt(e,Math.max(0,Math.min(n,e.state.doc.content.size)));if(!r)return null;let i=r.getBoundingClientRect(),a=t.getBoundingClientRect().top;return{top:i.top-a+t.scrollTop,height:i.height}}function Kt(){return typeof document>`u`?null:u()}function qt(e,t){let n=t.getBoundingClientRect(),r=n.left+n.width/2,i=G();for(let t of[i+1,i+12,i+40]){let i=e.posAtCoords({left:r,top:n.top+t});if(i)return i.pos}return null}function Jt(e,t){let n=t.getBoundingClientRect(),r=n.left+n.width/2,i=G();for(let t of[i+1,i+12,i+40]){let i=e.posAtCoords({x:r,y:n.top+t});if(i!==null)return i}return null}function Yt(e){let{from:t,to:n,docName:r,ytext:i}=e;t===`wysiwyg`&&n===`source`?Xt(r,i):t===`source`&&n===`wysiwyg`&&Zt(r,i)}function Xt(e,t){let n=Tt(e);if(n&&n.kind!==`selection-offset`)return;let r=o(e);if(!r)return;let i=J(r);if(!i)return;let a=Kt();if(!a)return;let s=qt(i,a);if(s===null)return;let c=Lt(i.state.doc,s,t,It());c&&wt(e,c)}function Zt(e,t){let n=q(e);if(!n)return;let r=Kt();if(!r)return;let i=Jt(n,r);if(i===null)return;let a=o(e),s=a?J(a)?.state.doc:void 0,c=zt(t.toString(),i,t,It(),s);c&&Ot(e,c)}function Qt(e){let{view:t,docName:n,navigation:i,ydoc:a,transition:s}=e,c=o(n),l=c?J(c)?.state.doc:void 0;if(!l)return null;let u=Vt(i,{source:t.state.doc.toString(),pmDoc:l,ydoc:a,resolver:It()});if(!u)return null;let d=Kt();if(!d)return null;let f=u,p=i.intent===`jump`,m=p?f.point:f.blockStart;t.dispatch({effects:xe.scrollIntoView(m,{y:`start`})});let h=!1,g=null,_=r(n,{yieldsToNavigation:!p,supersede:()=>{h=!0,_.release()}}),v=e=>{if(!h){if(Ht(t,m)===null&&e<8){requestAnimationFrame(()=>v(e+1));return}try{p&&(t.dispatch({selection:Ee.cursor(m)}),t.focus())}finally{_.release()}g=Ze({docName:n,container:d,contentColumn:t.contentDOM,measureTarget:()=>Ut(t,d,m),placement:p?`center`:`top`,intent:p?`jump`:`toggle`,grade:f.confidence,landedMode:`source`,transition:s,toolbarOffset:G(),onOutcome:p?e=>{e.status===`landed`&&vt(t,f.blockStart,f.blockEnd,f.confidence)}:void 0,onDiscardQueuedTarget:()=>Dt(n)})}};return v(0),{cancel:e=>{h=!0,_.release(),g?.cancel(e)}}}function $t(e){let{editor:t,docName:n,navigation:r,ydoc:i,transition:a}=e,o=J(t);if(!o)return null;let s=Bt(r,{source:i.getText(`source`).toString(),pmDoc:o.state.doc,ydoc:i,resolver:It()});if(!s)return null;let c=Kt();if(!c)return null;let l=s;return Ze({docName:n,container:c,contentColumn:o.dom,measureTarget:()=>Gt(o,c,l.point),placement:`top`,intent:`toggle`,grade:l.confidence,landedMode:`wysiwyg`,transition:a,toolbarOffset:G(),onDiscardQueuedTarget:()=>jt(n)})}var en={words:0,chars:0,tokens:0},tn=/[ -〿぀-ゟ゠-ヿ㐀-䶿一-鿿豈-﫿＀-￯฀-๿ក-៿]/,nn=/[\p{L}\p{N}]/u,rn=new Set([`text`,`inlineCode`,`code`,`tag`]),an=new Set([`html`,`definition`,`footnoteDefinition`,`yaml`,`toml`,`image`,`imageReference`,`mdxFlowExpression`,`mdxTextExpression`,`mdxjsEsm`,`rawMdxFallback`,`rawMdxFallbackMdast`]),on=new Set([`paragraph`,`heading`,`blockquote`,`list`,`listItem`,`thematicBreak`,`table`,`tableRow`,`tableCell`,`mdxJsxFlowElement`,`commentBlock`]);function sn(e,t){if(!e)return;let n=e.type;if(!an.has(n)){if(rn.has(n)){e.value&&(t.push(e.value),n===`code`&&t.push(`
4
- `));return}if(n===`wikiLink`||n===`wikiLinkEmbed`){let n=e.data?.alias??e.value??``;n&&t.push(n);return}if(Array.isArray(e.children)){for(let n of e.children)sn(n,t);if(on.has(n)&&t.length>0){let e=t[t.length-1];e&&!e.endsWith(`
5
- `)&&t.push(`
6
- `)}}}}function cn(e){try{let t=ie().parseToMdast(e),n=[];return sn(t,n),n.join(``).trim()}catch(t){return console.warn(`[document-stats] mdast parse failed, falling back to raw text`,t),e.trim()}}function ln(e){if(!e)return 0;let t=0;for(let n of e.split(/\s+/))nn.test(n)&&t++;return t}function un(e){let t=globalThis.Intl.Segmenter;if(!t)return ln(e);let n=new t(void 0,{granularity:`word`}),r=0;for(let t of n.segment(e))t.isWordLike&&r++;return r}function dn(e){let t=tn.test(e)?1.5:4;return Math.ceil(e.length/t)}function fn(e){return e?{words:tn.test(e)?un(e):ln(e),chars:e.length,tokens:dn(e)}:{words:0,chars:0,tokens:0}}function pn(e){if(!e)return{words:0,chars:0,tokens:0};let{body:t}=R(e);return t.trim()?fn(cn(t)):{words:0,chars:0,tokens:0}}function mn(e){return fn(e)}function hn(e,{isMarkdown:t}){let n=e.trim();return n?fn(t?cn(e):n):en}function gn(e,t){return e!==null&&j(e)?`source`:t}var _n=new Map,vn=new Set,yn=(e,t)=>`${t}:${e}`;function bn(){for(let e of vn)e()}function xn(e,t,n){let r=yn(e,t);if(n===null){_n.delete(r)&&bn();return}let i=_n.get(r);i&&i.words===n.words&&i.chars===n.chars&&i.tokens===n.tokens||(_n.set(r,n),bn())}function Sn(e,t){return e===null?null:_n.get(yn(e,t))??null}function Cn(e){return vn.add(e),()=>{vn.delete(e)}}function wn(e){let{from:t,to:n,empty:r}=e.state.selection;if(r)return null;let i=e.state.doc.textBetween(t,n,`
7
- `,` `);return i.trim()?hn(i,{isMarkdown:!1}):null}function Tn(e){let t=[];for(let n of e.state.selection.ranges)n.empty||t.push(e.state.sliceDoc(n.from,n.to));if(t.length===0)return null;let n=t.join(`
8
- `);return n.trim()?hn(n,{isMarkdown:!0}):null}var Z=e(h(),1),Q=b(),$=t();function En(e){let t=(0,Q.c)(14),{scope:n,onScopeChange:r,projectLabel:i}=e,{_:a}=_(),o;t[0]===r?o=t[1]:(o=e=>{e&&r(e)},t[0]=r,t[1]=o);let s;t[2]===a?s=t[3]:(s=a({id:`aBgwis`}),t[2]=a,t[3]=s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(O,{value:`doc`,className:`flex-1`,"data-testid":`panel-scope-doc`,children:(0,$.jsx)(g,{id:`UpCz01`})}),t[4]=c):c=t[4];let l;t[5]===i?l=t[6]:(l=i??(0,$.jsx)(g,{id:`ZWyHmq`}),t[5]=i,t[6]=l);let u;t[7]===l?u=t[8]:(u=(0,$.jsx)(O,{value:`project`,className:`flex-1`,"data-testid":`panel-scope-project`,children:l}),t[7]=l,t[8]=u);let d;return t[9]!==n||t[10]!==o||t[11]!==s||t[12]!==u?(d=(0,$.jsx)(`div`,{className:`shrink-0 px-4 pb-2`,children:(0,$.jsxs)(k,{type:`single`,variant:`segmented`,size:`sm`,spacing:1,value:n,onValueChange:o,"aria-label":s,className:`w-full rounded-md bg-muted p-0.5 dark:bg-background`,children:[c,u]})}),t[9]=n,t[10]=o,t[11]=s,t[12]=u,t[13]=d):d=t[13],d}function Dn(e){let t=e.localTarget;if(e.source!==`links`||t===void 0)return e.message;let n=t.resolvedTarget??t.href;return t.reason===`unresolvable`?t.role===`image`?N._({id:`W5qdI_`,values:{shown:n}}):N._({id:`bpMVIA`,values:{shown:n}}):t.targetKind===`file`?t.role===`image`?N._({id:`iSWh95`,values:{shown:n}}):N._({id:`fOzzSV`,values:{shown:n}}):N._({id:`XBBZnv`,values:{shown:n}})}var On=`audit-superseded`;async function kn(e={kind:`project`},t){return jn(e,Ie,!1,t)}async function An(e={kind:`project`},t){return jn(e,Re,!0,t)}async function jn(e,t,n,r){try{let i=new URLSearchParams;e.kind===`path`?i.set(`path`,e.path):e.kind===`doc`&&i.set(`doc`,e.docName),n&&i.set(`counts`,`1`);let a=i.size===0?``:`?${i}`,o=await fetch(`/api/audit${a}`,r===void 0?void 0:{signal:r});if(!o.ok)return o.status===409?On:(console.warn(`[audit] request failed`,o.status,o.statusText),null);let s;try{s=await o.json()}catch{return r?.aborted===!0||console.warn(`[audit] response body is not valid JSON`),null}let c=t.safeParse(s);return c.success?c.data:(console.warn(`[audit] response failed schema validation`,c.error.issues),null)}catch(e){return r?.aborted===!0||console.warn(`[audit] fetch threw`,e),null}}function Mn(e,t){let n=!1,r=!1,i=!1,a=[],o,s=null,c=()=>({findings:a,...o===void 0?{}:{brokenLinkSuppression:o}}),l=()=>{if(r){i=!0;return}r=!0,s=new AbortController,t({status:`loading`,...c()}),kn({kind:`doc`,docName:e},s.signal).then(e=>{if(!(n||s?.signal.aborted===!0)){if(e===null){t({status:`failed`,...c()});return}if(e===`audit-superseded`){i=!0;return}i||(a=e.files.flatMap(e=>e.diagnostics).filter(e=>e.source===`links`),o=e.brokenLinkSuppression,t({status:`loaded`,...c()}))}}).finally(()=>{n||(r=!1,s=null,i&&(i=!1,l()))})};l();let u=I(e=>{(e.includes(`backlinks`)||F(e))&&l()}),d=He(l);return()=>{n=!0,s?.abort(),u(),d()}}function Nn(e){let t=(0,Q.c)(6),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={docName:null,state:{status:`idle`,findings:[]}},t[0]=n):n=t[0];let[r,i]=(0,Z.useState)(n),a,o;if(t[1]===e?(a=t[2],o=t[3]):(a=()=>{if(e===null){i({docName:null,state:{status:`idle`,findings:[]}});return}return i({docName:e,state:{status:`loading`,findings:[]}}),Mn(e,t=>i({docName:e,state:t}))},o=[e],t[1]=e,t[2]=a,t[3]=o),(0,Z.useEffect)(a,o),r.docName!==e){let n;return t[4]===e?n=t[5]:(n=e===null?{status:`idle`,findings:[]}:{status:`loading`,findings:[]},t[4]=e,t[5]=n),n}return r.state}function Pn(e){return Math.min(50,Math.max(1,Math.ceil(e/10)))}function Fn(e,t){return e===t||e%Pn(t)===0}var In=[250,500,1e3,2e3,4e3];function Ln(e){return e.status===503&&e.problemType===`urn:ok:error:too-many-agent-sessions`}async function Rn(e,t){let n=await t.fixItem(e);for(let r of In){if(n.ok||!Ln(n)||!t.shouldContinue()||(console.debug(`[sweep] capacity refusal, backing off %dms`,r),await t.sleep(r),!t.shouldContinue()))break;n=await t.fixItem(e)}return n}async function zn(e){let t=e.items.length,n=[];for(let[r,i]of e.items.entries()){if(r>0&&(await e.sleep(15),!e.shouldContinue()))return{failures:n,cancelled:!0};let a=await Rn(i,e);if(a.ok||n.push({item:i,detail:a.errorDetail}),!e.shouldContinue())return{failures:n,cancelled:!0};let o=r+1;Fn(o,t)&&e.onProgress(o,t)}return{failures:n,cancelled:!1}}function Bn(e){return new Promise(t=>setTimeout(t,e))}var Vn=null,Hn=!1,Un=new Set,Wn=new Set;function Gn(e){Vn=e;for(let e of Un)e()}function Kn(e){return Un.add(e),()=>{Un.delete(e)}}function qn(){return Vn}function Jn(){return(0,Z.useSyncExternalStore)(Kn,qn,qn)}function Yn(e){return Wn.add(e),()=>{Wn.delete(e)}}function Xn(){Hn=!0}function Zn(e,t,n){if(e.length>0&&(console.warn(`[lint] fix-all: ${e.length} of ${n} files failed`,e.map(e=>({file:e.item.file,detail:e.detail}))),!t)){let t=e[0];M.error(N._({id:`se-tU0`,values:{0:e.length,total:n}}),{description:t===void 0?void 0:`${t.item.file}${t.detail===null?``:` — ${t.detail}`}`})}if(t){M.info(N._({id:`H1TmTu`}));return}e.length===0&&M.success(N._({id:`SWX1O7`,values:{total:n}}))}async function Qn({items:e,fixItem:t,sleep:n=Bn}){if(Vn!==null||e.length===0)return;let r=e.length;Hn=!1,Gn({done:0,total:r});let i=[],a=!1,o=!1;try{let o=await zn({items:e,fixItem:t,sleep:n,onProgress:e=>Gn({done:e,total:r}),shouldContinue:()=>!Hn});i=o.failures,a=o.cancelled}catch(e){console.warn(`[lint] fix-all: sweep threw`,e),o=!0}finally{Gn(null)}try{o?M.error(N._({id:`vwV-kH`})):Zn(i,a,r)}finally{for(let e of Wn)e()}}var $n={errorCount:0,warningCount:0},er=new Map,tr=new Set,nr=new Map;function rr(){let e=new Map;for(let[t,n]of er){let r=n.lint.errorCount+n.links.errorCount,i=n.lint.warningCount+n.links.warningCount;r===0&&i===0||e.set(t,{errorCount:r,warningCount:i})}nr=e;for(let e of tr)e()}var ir=Le;function ar(e){return tr.add(e),()=>{tr.delete(e)}}function or(){return nr}function sr(e){er.clear();for(let t of e)er.set(me(t.file),ir(t.diagnostics));rr()}function cr(e){er.clear();for(let t of e)er.set(me(t.file),{lint:t.lint,links:t.links});rr()}function lr(e,t){er.set(e,ir(t)),rr()}function ur(e,t,n){let r=er.get(e)??{lint:$n,links:$n},i=r[t];i.errorCount===n.errorCount&&i.warningCount===n.warningCount||(er.set(e,{...r,[t]:n}),rr())}var dr=`open-knowledge:lint-nav`;function fr(e,t){return e.range.start.line-t.range.start.line||e.range.start.character-t.range.start.character}function pr(e,t){return{docName:e,line:t.range.start.line+1,column:t.range.start.character+1,source:t.source,...t.frontmatterScope===void 0?{}:{frontmatterScope:t.frontmatterScope}}}function mr(e){if(e.source!==`links`)return null;let t=e.localTarget;return t===void 0?`document`:t.role===`image`?`image`:t.targetKind===`file`?`file`:t.targetKind===`document`?`document`:`unresolvable`}var hr={document:s,file:p,image:re,unresolvable:s};function gr(e){return e.linkTarget!==void 0&&mr(e)===`document`}function _r(e){let t=(0,Q.c)(40),{diagnostic:n,instanceCount:r}=e,{_:i}=_(),a=n.severity===`error`?W:le,o=n.range.start.line+1,s;t[0]===n?s=t[1]:(s=mr(n),t[0]=n,t[1]=s);let c=s,l=c===null?null:hr[c],u=r!==void 0&&r>1,d=n.severity===`error`?`text-destructive`:`text-amber-500`,f;t[2]===d?f=t[3]:(f=x(`mt-0.5 size-3.5 shrink-0`,d),t[2]=d,t[3]=f);let p;t[4]!==a||t[5]!==f?(p=(0,$.jsx)(a,{"aria-hidden":`true`,className:f}),t[4]=a,t[5]=f,t[6]=p):p=t[6];let m;t[7]===n?m=t[8]:(m=Dn(n),t[7]=n,t[8]=m);let h;t[9]===m?h=t[10]:(h=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 text-foreground`,children:m}),t[9]=m,t[10]=h);let v;t[11]!==u||t[12]!==r?(v=u?(0,$.jsxs)(`span`,{className:`mt-0.5 flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(de,{variant:`gray`,"data-testid":`problems-instance-count`,className:`h-4 px-1 font-sans text-[10px] leading-none`,children:(0,$.jsx)(g,{id:`iZCZmF`,values:{instanceCount:r}})}),(0,$.jsx)(H,{"aria-hidden":`true`,className:`size-3 text-muted-foreground transition-transform group-data-[state=open]:rotate-90 motion-reduce:transition-none`})]}):null,t[11]=u,t[12]=r,t[13]=v):v=t[13];let y;t[14]!==p||t[15]!==h||t[16]!==v?(y=(0,$.jsxs)(`span`,{className:`flex items-start gap-1.5 text-sm`,children:[p,h,v]}),t[14]=p,t[15]=h,t[16]=v,t[17]=y):y=t[17];let b=c??void 0,S=l!==null&&`gap-0.5`,C;t[18]===S?C=t[19]:(C=x(`h-4 shrink-0 px-1 font-sans text-[10px] uppercase leading-none`,S),t[18]=S,t[19]=C);let w;t[20]===l?w=t[21]:(w=l===null?null:(0,$.jsx)(l,{"aria-hidden":`true`,className:`size-2.5`}),t[20]=l,t[21]=w);let T;t[22]!==n.source||t[23]!==C||t[24]!==w||t[25]!==b?(T=(0,$.jsxs)(de,{variant:`gray`,"data-testid":`problems-source-tag`,"data-target-kind":b,className:C,children:[w,n.source]}),t[22]=n.source,t[23]=C,t[24]=w,t[25]=b,t[26]=T):T=t[26];let E;t[27]!==i||t[28]!==n.code||t[29]!==o||t[30]!==u?(E=u?n.code:`${n.code} · ${i({id:`enPTnx`,values:{displayLine:o}})}`,t[27]=i,t[28]=n.code,t[29]=o,t[30]=u,t[31]=E):E=t[31];let D;t[32]===E?D=t[33]:(D=(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:E}),t[32]=E,t[33]=D);let O;t[34]!==T||t[35]!==D?(O=(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 ps-5 font-mono text-xs text-muted-foreground`,children:[T,D]}),t[34]=T,t[35]=D,t[36]=O):O=t[36];let k;return t[37]!==O||t[38]!==y?(k=(0,$.jsxs)($.Fragment,{children:[y,O]}),t[37]=O,t[38]=y,t[39]=k):k=t[39],k}function vr(e){let t=new Map;for(let n of e){let e=`${n.source}/${n.code}\u0000${n.linkTarget??``}\u0000${n.message}`,r=t.get(e);r===void 0?t.set(e,{key:e,instances:[n]}):r.instances.push(n)}return[...t.values()]}function yr(e){let t=(0,Q.c)(63),{group:n,onNavigate:r,navTitle:i,renderActions:a}=e,{_:o}=_(),s=n.instances[0],c,l,u,d,f,p,m,h;if(t[0]!==o||t[1]!==s||t[2]!==n.instances.length||t[3]!==i||t[4]!==r||t[5]!==a){h=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Dn(s);if(n.instances.length===1){let e;t[14]!==s||t[15]!==a?(e=a(s),t[14]=s,t[15]=a,t[16]=e):e=t[16];let n=e,o;t[17]!==s||t[18]!==r?(o=()=>r(s),t[17]=s,t[18]=r,t[19]=o):o=t[19];let c;t[20]!==s||t[21]!==i?(c=i(s),t[20]=s,t[21]=i,t[22]=c):c=t[22];let l;t[23]===s?l=t[24]:(l=(0,$.jsx)(_r,{diagnostic:s}),t[23]=s,t[24]=l);let u;t[25]!==l||t[26]!==o||t[27]!==c?(u=(0,$.jsx)(`button`,{type:`button`,onClick:o,className:`flex w-full cursor-pointer flex-col gap-0.5 rounded px-2 py-1.5 text-left`,title:c,children:l}),t[25]=l,t[26]=o,t[27]=c,t[28]=u):u=t[28];let d;t[29]===n?d=t[30]:(d=n===null?null:(0,$.jsx)(`div`,{className:`absolute bottom-1 right-1 flex items-center gap-1 rounded bg-muted opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100 motion-reduce:transition-none`,children:n}),t[29]=n,t[30]=d);let f;t[31]!==u||t[32]!==d?(f=(0,$.jsxs)(`li`,{className:`group relative rounded transition-colors hover:bg-muted`,children:[u,d]}),t[31]=u,t[32]=d,t[33]=f):f=t[33],h=f;break bb0}p=`rounded`,m=`problems-duplicate-group`,l=D,t[34]!==s||t[35]!==n.instances.length?(f=(0,$.jsx)(E,{className:`group flex w-full cursor-pointer flex-col gap-0.5 rounded px-2 py-1.5 text-left transition-colors hover:bg-muted`,children:(0,$.jsx)(_r,{diagnostic:s,instanceCount:n.instances.length})}),t[34]=s,t[35]=n.instances.length,t[36]=f):f=t[36],c=T,d=`overflow-hidden data-[state=open]:animate-[collapsible-down_150ms_ease-out] data-[state=closed]:animate-[collapsible-up_150ms_ease-in] motion-reduce:animate-none`,u=o({id:`_Bix3-`,values:{localizedFirstMessage:e}})}t[0]=o,t[1]=s,t[2]=n.instances.length,t[3]=i,t[4]=r,t[5]=a,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h}else c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13];if(h!==Symbol.for(`react.early_return_sentinel`))return h;let g;if(t[37]!==o||t[38]!==n.instances||t[39]!==i||t[40]!==r||t[41]!==a){let e;t[43]!==o||t[44]!==i||t[45]!==r||t[46]!==a?(e=e=>{let t=a(e),n=e.range.start.line+1,s=Dn(e);return(0,$.jsxs)(`li`,{className:`group relative rounded transition-colors hover:bg-muted`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:`flex w-full cursor-pointer rounded px-2 py-1 text-left font-mono text-xs text-muted-foreground`,title:i(e),"aria-label":o({id:`txUHO8`,values:{localizedMessage:s,displayLine:n}}),children:o({id:`enPTnx`,values:{displayLine:n}})}),t===null?null:(0,$.jsx)(`div`,{className:`absolute bottom-0.5 right-1 flex items-center gap-1 rounded bg-muted opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100 motion-reduce:transition-none`,children:t})]},br(e))},t[43]=o,t[44]=i,t[45]=r,t[46]=a,t[47]=e):e=t[47],g=n.instances.map(e),t[37]=o,t[38]=n.instances,t[39]=i,t[40]=r,t[41]=a,t[42]=g}else g=t[42];let v;t[48]!==u||t[49]!==g?(v=(0,$.jsx)(`ul`,{"aria-label":u,className:`flex flex-col gap-0.5 pb-1 ps-5`,"data-testid":`problems-duplicate-instances`,children:g}),t[48]=u,t[49]=g,t[50]=v):v=t[50];let y;t[51]!==c||t[52]!==d||t[53]!==v?(y=(0,$.jsx)(c,{className:d,children:v}),t[51]=c,t[52]=d,t[53]=v,t[54]=y):y=t[54];let b;t[55]!==l||t[56]!==f||t[57]!==y?(b=(0,$.jsxs)(l,{children:[f,y]}),t[55]=l,t[56]=f,t[57]=y,t[58]=b):b=t[58];let x;return t[59]!==b||t[60]!==p||t[61]!==m?(x=(0,$.jsx)(`li`,{className:p,"data-testid":m,children:b}),t[59]=b,t[60]=p,t[61]=m,t[62]=x):x=t[62],x}function br(e){return`${e.source}/${e.code}-${e.range.start.line}-${e.range.start.character}-${e.message}`}function xr(e){return e.reduce((e,t)=>e+ +((t.fixes?.length??0)>0),0)}function Sr(e){let t=(0,Q.c)(11),{target:n,creating:r,disabled:i,onCreate:a}=e,{_:o}=_(),s;t[0]!==o||t[1]!==n?(s=o({id:`oWsZk8`,values:{target:n}}),t[0]=o,t[1]=n,t[2]=s):s=t[2];let c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(ae,{"aria-hidden":`true`,className:`size-3`}),t[3]=c):c=t[3];let l;t[4]===r?l=t[5]:(l=r?(0,$.jsx)(g,{id:`E9bKSA`}):(0,$.jsx)(g,{id:`XRuL0i`}),t[4]=r,t[5]=l);let u;return t[6]!==i||t[7]!==a||t[8]!==s||t[9]!==l?(u=(0,$.jsxs)(A,{size:`sm`,variant:`ghost`,className:`h-6 shrink-0 px-2 text-xs`,disabled:i,onClick:a,"aria-label":s,"data-testid":`problems-create-page`,children:[c,l]}),t[6]=i,t[7]=a,t[8]=s,t[9]=l,t[10]=u):u=t[10],u}function Cr(e){let t=(0,Q.c)(8),{tip:n,testId:r,children:i}=e,a;t[0]===i?a=t[1]:(a=(0,$.jsx)(S,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex shrink-0`,children:i})}),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==n?(o=(0,$.jsx)(C,{"data-testid":r,children:n}),t[2]=r,t[3]=n,t[4]=o):o=t[4];let s;return t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(w,{children:[a,o]}),t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function wr(e){let t=(0,Q.c)(21),{count:n,problemCount:r,aiAvailable:i,disabled:a,onClick:o,children:s}=e,{_:c}=_(),l;t[0]!==i||t[1]!==n||t[2]!==r?(l=n>0?(0,$.jsx)(g,{id:`vjwsDi`,values:{count:n}}):r===0?(0,$.jsx)(g,{id:`gAhHu7`}):i?(0,$.jsx)(g,{id:`zA9zRL`}):(0,$.jsx)(g,{id:`X3MMeA`}),t[0]=i,t[1]=n,t[2]=r,t[3]=l):l=t[3];let u;t[4]!==c||t[5]!==s||t[6]!==n||t[7]!==r?(u=s===void 0?r===0?c({id:`4m-xuX`}):n===0?c({id:`SqIoy_`}):void 0:void 0,t[4]=c,t[5]=s,t[6]=n,t[7]=r,t[8]=u):u=t[8];let d;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(ue,{"aria-hidden":`true`,className:`size-3`}),t[9]=d):d=t[9];let f;t[10]!==s||t[11]!==n?(f=s??(0,$.jsx)(g,{id:`RZXTlY`,values:{count:n}}),t[10]=s,t[11]=n,t[12]=f):f=t[12];let p;t[13]!==a||t[14]!==o||t[15]!==u||t[16]!==f?(p=(0,$.jsxs)(A,{size:`sm`,variant:`ghost`,className:`h-6 shrink-0 px-2 text-xs`,disabled:a,onClick:o,"aria-label":u,"data-testid":`problems-auto-fix`,children:[d,f]}),t[13]=a,t[14]=o,t[15]=u,t[16]=f,t[17]=p):p=t[17];let m;return t[18]!==l||t[19]!==p?(m=(0,$.jsx)(Cr,{testId:`problems-auto-fix-tip`,tip:l,children:p}),t[18]=l,t[19]=p,t[20]=m):m=t[20],m}function Tr(e){let t=(0,Q.c)(12),{count:n,disabled:r,onClick:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(g,{id:`mgDKWS`,values:{count:n}}),t[0]=n,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(ce,{"aria-hidden":`true`,className:`size-3`}),t[2]=o):o=t[2];let s;t[3]===n?s=t[4]:(s=(0,$.jsx)(g,{id:`gyHDWC`,values:{count:n}}),t[3]=n,t[4]=s);let c;t[5]!==r||t[6]!==i||t[7]!==s?(c=(0,$.jsxs)(A,{size:`sm`,variant:`ghost`,className:`h-6 shrink-0 px-2 text-xs`,disabled:r,onClick:i,"data-testid":`problems-fix-with-ai`,children:[o,s]}),t[5]=r,t[6]=i,t[7]=s,t[8]=c):c=t[8];let l;return t[9]!==a||t[10]!==c?(l=(0,$.jsx)(Cr,{testId:`problems-fix-with-ai-tip`,tip:a,children:c}),t[9]=a,t[10]=c,t[11]=l):l=t[11],l}function Er(e){let t=(0,Q.c)(59),{docName:r,diagnostics:i,linkFindingsStatus:a,brokenLinkSuppression:o,onFix:s,onAutoFix:c,onAskAi:l,onFixWithAi:u}=e,p=a===void 0?`loaded`:a,{_:m}=_(),h=(0,Z.useRef)(null),v=(0,Z.useId)(),[y,b]=(0,Z.useState)(`doc`),x;t[0]===r?x=t[1]:(x=j(r),t[0]=r,t[1]=x);let T=!x,{data:E}=Ue(),D=E===null?null:E.effective.enabled?te.filter(e=>E.effective.plugins[e.id].enabled):[],O=D!==null&&D.length===0,k=o!==void 0,N=(y===`project`||T)&&D!==null&&D.length>0,P;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(P={status:`idle`},t[2]=P):P=t[2];let[L,ee]=(0,Z.useState)(P),R=Jn(),z=De(),[B,V]=(0,Z.useState)(null),H=(0,Z.useRef)(!0),U,W;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(U=()=>(H.current=!0,()=>{H.current=!1}),W=[],t[3]=U,t[4]=W):(U=t[3],W=t[4]),(0,Z.useEffect)(U,W);let G=(0,Z.useRef)(Pr),K=(0,Z.useRef)(Nr),q;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(q={status:`idle`},t[5]=q):q=t[5];let J=(0,Z.useRef)(q),ne;t[6]===L?ne=t[7]:(ne=()=>{L.status!==`loading`&&(J.current=L)},t[6]=L,t[7]=ne),(0,Z.useEffect)(ne);let Y=(0,Z.useRef)(0),X=[...i].sort(fr),re=xr(X),ie;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(ie=async function(){Y.current+=1;let e=Y.current,t=J.current;ee({status:`loading`});let n=await kn();if(n===`audit-superseded`){Y.current===e&&H.current&&ee(t.status===`idle`?{status:`failed`}:t);return}n!==null&&sr(n.files),H.current&&ee(n===null?{status:`failed`}:{status:`loaded`,result:n})},t[8]=ie):ie=t[8];let ae=ie,oe;t[9]!==m||t[10]!==L.status||t[11]!==B||t[12]!==z?(oe=async function(e){let t=e.linkTarget;if(!(t===void 0||B!==null||z===null)){V(t);try{await n({initialDir:``,suggestedName:t},{addPage:z.addPage})}catch(e){let t=e;M.error(t instanceof Error?t.message:m({id:`tfi40B`})),H.current&&V(null);return}M.success(m({id:`EWCJFu`,values:{target:t}})),H.current&&V(null),H.current&&L.status===`loaded`&&await ae()}},t[9]=m,t[10]=L.status,t[11]=B,t[12]=z,t[13]=oe):oe=t[13];let se=oe,le=L.status===`loaded`?L.result.files.filter(jr):[],de=function(){Qn({items:le,fixItem:Ar})},he;t[14]===L.status?he=t[15]:(he=function(e){b(e),e===`project`&&L.status===`idle`&&ae()},t[14]=L.status,t[15]=he);let ge=he,_e;t[16]===L.status?_e=t[17]:(_e=()=>{G.current=()=>{L.status===`idle`||L.status===`failed`||ae()}},t[16]=L.status,t[17]=_e),(0,Z.useEffect)(_e);let ve,ye;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>He(()=>G.current()),ye=[],t[18]=ve,t[19]=ye):(ve=t[18],ye=t[19]),(0,Z.useEffect)(ve,ye);let be,xe;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(be=()=>I(e=>{F(e)&&G.current()}),xe=[],t[20]=be,t[21]=xe):(be=t[20],xe=t[21]),(0,Z.useEffect)(be,xe);let Se;t[22]===ge?Se=t[23]:(Se=(e,t)=>{e===`problems`&&(d(`problems`),t.scope!==void 0&&ge(t.scope),t.focus===`panel`&&h.current?.focus({preventScroll:!0}))},t[22]=ge,t[23]=Se);let Ce=(0,Z.useEffectEvent)(Se),we;t[24]===Ce?we=t[25]:(we=()=>{let e=d(`problems`);return e!==null&&Ce(`problems`,e),f(Ce)},t[24]=Ce,t[25]=we);let Te;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(Te=[],t[26]=Te):Te=t[26],(0,Z.useEffect)(we,Te);let Ee;t[27]===L.status?Ee=t[28]:(Ee=()=>{K.current=()=>{L.status===`idle`||L.status===`failed`||ae().catch(e=>{console.warn(`[lint] post-sweep re-audit failed`,e),H.current&&ee({status:`failed`})})}},t[27]=L.status,t[28]=Ee),(0,Z.useEffect)(Ee);let Oe,Ie;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=()=>Yn(()=>K.current()),Ie=[],t[29]=Oe,t[30]=Ie):(Oe=t[29],Ie=t[30]),(0,Z.useEffect)(Oe,Ie);let Le;t[31]===r?Le=t[32]:(Le=function(e){let t=pr(r,e);wt(r,{kind:`lint`,detail:t}),window.dispatchEvent(new CustomEvent(dr,{detail:t}))},t[31]=r,t[32]=Le);let Re=Le,ze;t[33]!==r||t[34]!==Re?(ze=function(e,t){let n=me(e);if(n===r){Re(t);return}wt(n,{kind:`lint`,detail:pr(n,t)}),window.location.hash=pe(n)},t[33]=r,t[34]=Re,t[35]=ze):ze=t[35];let Be=ze,Ve;t[36]!==m||t[37]!==se||t[38]!==B||t[39]!==l||t[40]!==s||t[41]!==z?(Ve=function(e){let t=s!==void 0&&(e.fixes?.length??0)>0,n=gr(e)&&z!==null;if(!t&&!n&&l===void 0)return null;let r=`${e.source}/${e.code}`;return(0,$.jsxs)($.Fragment,{children:[n?(0,$.jsx)(Sr,{target:e.linkTarget??``,creating:B===e.linkTarget,disabled:B!==null,onCreate:()=>void se(e)}):null,t?(0,$.jsxs)(A,{size:`sm`,variant:`ghost`,className:`h-6 shrink-0 px-2 text-xs`,onClick:()=>s?.(e),"aria-label":m({id:`fZj9em`,values:{flatId:r}}),"data-testid":`problems-fix`,children:[(0,$.jsx)(ue,{"aria-hidden":`true`,className:`size-3`}),(0,$.jsx)(g,{id:`c4fVUV`})]}):null,l===void 0?null:(0,$.jsxs)(A,{size:`sm`,variant:`ghost`,className:`h-6 shrink-0 px-2 text-xs`,onClick:()=>l(e),"aria-label":m({id:`hh4mVC`,values:{flatId:r}}),"data-testid":`problems-ask-ai`,children:[(0,$.jsx)(ce,{"aria-hidden":`true`,className:`size-3`}),(0,$.jsx)(g,{id:`xWEvuo`})]})]})},t[36]=m,t[37]=se,t[38]=B,t[39]=l,t[40]=s,t[41]=z,t[42]=Ve):Ve=t[42];let We=Ve,Ge=Fe,Ke;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(Ke=(0,$.jsx)(g,{id:`OXdGnd`}),t[43]=Ke):Ke=t[43];let qe;t[44]===v?qe=t[45]:(qe=(0,$.jsx)(Ae,{id:v,children:Ke}),t[44]=v,t[45]=qe);let Je=y===`doc`&&X.length>0&&(0,$.jsx)(Ne,{children:X.length}),Ye=N&&(0,$.jsxs)(w,{children:[(0,$.jsx)(S,{className:`shrink-0 cursor-default rounded-md bg-muted-foreground/5 px-2 py-1 font-mono text-xs text-muted-foreground`,"data-testid":`problems-active-plugins`,children:(0,$.jsx)(g,{id:`yxF19Y`,values:{0:D.length}})}),(0,$.jsx)(C,{"data-testid":`problems-active-plugins-tooltip`,children:(0,$.jsx)(g,{id:`ws5o1F`,values:{0:D.map(kr).join(`, `)}})})]}),Xe;t[46]!==qe||t[47]!==Je||t[48]!==Ye?(Xe=(0,$.jsx)(Pe,{children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[qe,Je,Ye]})}),t[46]=qe,t[47]=Je,t[48]=Ye,t[49]=Xe):Xe=t[49];let Ze;t[50]!==ge||t[51]!==y?(Ze=(0,$.jsx)(En,{scope:y,onScopeChange:ge}),t[50]=ge,t[51]=y,t[52]=Ze):Ze=t[52];let Qe=y===`doc`?(0,$.jsxs)(Me,{className:`px-2 py-2`,children:[p===`idle`||p===`loading`?(0,$.jsx)(je,{className:`px-2 pb-2`,role:`status`,"aria-live":`polite`,"data-testid":`problems-links-loading`,children:(0,$.jsx)(g,{id:`W9NSe0`})}):p===`failed`?(0,$.jsx)(ke,{className:`px-2 pb-2`,role:`status`,"data-testid":`problems-links-failed`,children:X.length>0||k?(0,$.jsx)(g,{id:`IoHQYP`}):(0,$.jsx)(g,{id:`gpbKxw`})}):null,k&&(0,$.jsx)(zr,{suppression:o}),X.length===0?p===`loaded`?T?O?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(je,{className:`px-2`,"data-testid":`problems-no-plugins`,children:k?(0,$.jsx)(g,{id:`mI1KPS`}):(0,$.jsx)(g,{id:`Hngy37`})}),(0,$.jsx)(`div`,{className:`px-2 pt-2`,children:(0,$.jsx)(A,{variant:`outline`,size:`sm`,onClick:fe,"data-testid":`problems-enable-plugins`,children:(0,$.jsx)(g,{id:`rnX-1S`})})})]}):k?null:(0,$.jsx)(je,{className:`px-2`,children:(0,$.jsx)(g,{id:`ZI8uvA`})}):(0,$.jsx)(je,{className:`px-2`,"data-testid":`problems-markdown-not-applicable`,children:(0,$.jsx)(g,{id:`Kdvukk`})}):null:(0,$.jsxs)($.Fragment,{children:[c!==void 0||u!==void 0?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-1 px-2 pb-1`,children:[c!==void 0&&(0,$.jsx)(wr,{count:re,problemCount:X.length,aiAvailable:u!==void 0,disabled:re===0,onClick:c}),u!==void 0&&(0,$.jsx)(Tr,{count:X.length,disabled:!1,onClick:()=>u(`doc`)})]}):null,(0,$.jsx)(`ul`,{"aria-label":m({id:`OXdGnd`}),className:`flex flex-col gap-0.5`,children:vr(X).map(e=>(0,$.jsx)(yr,{group:e,onNavigate:Re,navTitle:e=>m({id:`vbMHjo`,values:{0:e.range.start.line+1}}),renderActions:We},e.key))})]})]}):(0,$.jsx)(Fr,{audit:L,onRefresh:()=>void ae(),onNavigate:Be,fixableCount:le.reduce(Or,0),problemCount:L.status===`loaded`?L.result.files.reduce(Dr,0):0,fixing:R,onAutoFix:de,onCancelFix:Xn,onFixWithAi:u===void 0||L.status!==`loaded`?void 0:()=>u(`project`),onCreateTarget:z===null?void 0:e=>void se(e),creatingTarget:B}),$e;return t[53]!==Ge||t[54]!==v||t[55]!==Xe||t[56]!==Ze||t[57]!==Qe?($e=(0,$.jsxs)(Ge,{ref:h,tabIndex:-1,"aria-labelledby":v,"data-testid":`problems-panel`,children:[Xe,Ze,Qe]}),t[53]=Ge,t[54]=v,t[55]=Xe,t[56]=Ze,t[57]=Qe,t[58]=$e):$e=t[58],$e}function Dr(e,t){return e+t.diagnostics.length}function Or(e,t){return e+xr(t.diagnostics)}function kr(e){return e.label}function Ar(e){return Ve(me(e.file))}function jr(e){return e.diagnostics.some(Mr)}function Mr(e){return(e.fixes?.length??0)>0}function Nr(){}function Pr(){}function Fr(e){let t=(0,Q.c)(81),{audit:n,onRefresh:r,onNavigate:i,fixableCount:a,problemCount:o,fixing:s,onAutoFix:c,onCancelFix:l,onFixWithAi:u,onCreateTarget:d,creatingTarget:f}=e,{_:p}=_(),m=n.status===`loading`||n.status===`idle`,h;t[0]!==n.result||t[1]!==n.status?(h=n.status===`loaded`?n.result.files:[],t[0]=n.result,t[1]=n.status,t[2]=h):h=t[2];let v=h,[y,b]=(0,Z.useState)(Rr),x;t[3]!==y||t[4]!==v?(x=v.length>0&&v.every(e=>y.has(e.file)),t[3]=y,t[4]=v,t[5]=x):x=t[5];let T=x,E;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(E=function(e,t){b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},t[6]=E):E=t[6];let D=E,O;t[7]!==T||t[8]!==v?(O=function(){b(T?new Set:new Set(v.map(Lr)))},t[7]=T,t[8]=v,t[9]=O):O=t[9];let k=O,j;t[10]!==n.result||t[11]!==n.status?(j=n.status===`loaded`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{id:`DsDwR-`,values:{0:n.result.errorCount}}),` · `,(0,$.jsx)(g,{id:`W1SI2K`,values:{0:n.result.warningCount}})]}),t[10]=n.result,t[11]=n.status,t[12]=j):j=t[12];let M;t[13]===j?M=t[14]:(M=(0,$.jsx)(`p`,{className:`min-w-0 truncate text-xs text-muted-foreground`,"data-testid":`problems-audit-summary`,children:j}),t[13]=j,t[14]=M);let N;t[15]!==p||t[16]!==T||t[17]!==v.length||t[18]!==k?(N=v.length>0?(0,$.jsxs)(w,{children:[(0,$.jsx)(S,{asChild:!0,children:(0,$.jsx)(A,{variant:`ghost`,size:`icon`,className:`size-6 shrink-0 text-muted-foreground`,"aria-label":p(T?{id:`I4LGsH`}:{id:`Ugvy4O`}),"data-testid":`problems-audit-expand-toggle`,onClick:k,children:T?(0,$.jsx)(We,{"aria-hidden":`true`,className:`size-3.5`}):(0,$.jsx)(U,{"aria-hidden":`true`,className:`size-3.5`})})}),(0,$.jsx)(C,{"data-testid":`problems-audit-expand-toggle-tooltip`,children:T?(0,$.jsx)(g,{id:`I4LGsH`}):(0,$.jsx)(g,{id:`Ugvy4O`})})]}):null,t[15]=p,t[16]=T,t[17]=v.length,t[18]=k,t[19]=N):N=t[19];let P;t[20]===p?P=t[21]:(P=p({id:`I7y_vn`}),t[20]=p,t[21]=P);let F=m||s!==null,I;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(se,{"aria-hidden":`true`,className:`size-3.5`}),t[22]=I):I=t[22];let L;t[23]!==r||t[24]!==P||t[25]!==F?(L=(0,$.jsx)(S,{asChild:!0,children:(0,$.jsx)(A,{variant:`ghost`,size:`icon`,className:`size-6 shrink-0 text-muted-foreground`,"aria-label":P,"data-testid":`problems-audit-refresh`,disabled:F,onClick:r,children:I})}),t[23]=r,t[24]=P,t[25]=F,t[26]=L):L=t[26];let ee;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(C,{"data-testid":`problems-audit-refresh-tooltip`,children:(0,$.jsx)(g,{id:`I7y_vn`})}),t[27]=ee):ee=t[27];let R;t[28]===L?R=t[29]:(R=(0,$.jsxs)(w,{children:[L,ee]}),t[28]=L,t[29]=R);let z;t[30]!==R||t[31]!==N?(z=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[N,R]}),t[30]=R,t[31]=N,t[32]=z):z=t[32];let B;t[33]!==z||t[34]!==M?(B=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[M,z]}),t[33]=z,t[34]=M,t[35]=B):B=t[35];let V;t[36]!==p||t[37]!==s?(V=s===null?null:(0,$.jsx)(`span`,{className:`sr-only`,role:`status`,children:p({id:`gZElfU`,values:{0:s.done,1:s.total}})}),t[36]=p,t[37]=s,t[38]=V):V=t[38];let H;t[39]!==p||t[40]!==s||t[41]!==l?(H=s===null?null:(0,$.jsxs)(w,{children:[(0,$.jsx)(S,{asChild:!0,children:(0,$.jsx)(A,{variant:`ghost`,size:`sm`,className:`h-6 shrink-0 px-2 text-muted-foreground`,"aria-label":p({id:`q2cLM6`}),"data-testid":`problems-cancel-fix`,onClick:l,children:(0,$.jsx)(g,{id:`ygCKqB`})})}),(0,$.jsx)(C,{"data-testid":`problems-cancel-fix-tooltip`,children:(0,$.jsx)(g,{id:`yvSAuM`})})]}),t[39]=p,t[40]=s,t[41]=l,t[42]=H):H=t[42];let te=u!==void 0,W=m||s!==null||a===0,G;t[43]===s?G=t[44]:(G=s===null?void 0:(0,$.jsx)(g,{id:`S9t1PI`,values:{0:s.done,1:s.total}}),t[43]=s,t[44]=G);let K;t[45]!==a||t[46]!==c||t[47]!==o||t[48]!==te||t[49]!==W||t[50]!==G?(K=(0,$.jsx)(wr,{count:a,problemCount:o,aiAvailable:te,disabled:W,onClick:c,children:G}),t[45]=a,t[46]=c,t[47]=o,t[48]=te,t[49]=W,t[50]=G,t[51]=K):K=t[51];let q;t[52]!==s||t[53]!==u||t[54]!==o?(q=u!==void 0&&o>0?(0,$.jsx)(Tr,{count:o,disabled:s!==null,onClick:u}):null,t[52]=s,t[53]=u,t[54]=o,t[55]=q):q=t[55];let J;t[56]!==V||t[57]!==H||t[58]!==K||t[59]!==q?(J=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[V,H,K,q]}),t[56]=V,t[57]=H,t[58]=K,t[59]=q,t[60]=J):J=t[60];let ne;t[61]!==B||t[62]!==J?(ne=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 px-2 pb-1`,children:[B,J]}),t[61]=B,t[62]=J,t[63]=ne):ne=t[63];let Y;t[64]!==p||t[65]!==m?(Y=m&&(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,role:`status`,"aria-busy":`true`,"aria-label":p({id:`dx-TwN`}),children:[1,2,3].map(Ir)}),t[64]=p,t[65]=m,t[66]=Y):Y=t[66];let X;t[67]===n.status?X=t[68]:(X=n.status===`failed`&&(0,$.jsx)(ke,{className:`px-2 text-xs`,children:(0,$.jsx)(g,{id:`IFezUv`})}),t[67]=n.status,t[68]=X);let re;t[69]!==n.result||t[70]!==n.status||t[71]!==f||t[72]!==y||t[73]!==d||t[74]!==i?(re=n.status===`loaded`&&(0,$.jsx)(Br,{result:n.result,onNavigate:i,onCreateTarget:d,creatingTarget:f,expandedFiles:y,onToggleFile:D}),t[69]=n.result,t[70]=n.status,t[71]=f,t[72]=y,t[73]=d,t[74]=i,t[75]=re):re=t[75];let ie;return t[76]!==ne||t[77]!==Y||t[78]!==X||t[79]!==re?(ie=(0,$.jsxs)(Me,{className:`px-2 py-2`,"data-testid":`problems-project-scope`,children:[ne,Y,X,re]}),t[76]=ne,t[77]=Y,t[78]=X,t[79]=re,t[80]=ie):ie=t[80],ie}function Ir(e){return(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2 py-1.5`,children:[(0,$.jsx)(Be,{className:`mt-0.5 size-3.5 shrink-0 rounded`}),(0,$.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,$.jsx)(Be,{className:`h-3 w-28`}),(0,$.jsx)(Be,{className:`h-3 w-40`})]})]},e)}function Lr(e){return e.file}function Rr(){return new Set}function zr(e){let t=(0,Q.c)(6),{suppression:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(oe,{"aria-hidden":`true`,className:`mt-0.5 size-3.5 shrink-0`}),t[0]=r):r=t[0];let i;t[1]===n.count?i=t[2]:(i=(0,$.jsx)(g,{id:`gi9c0-`,values:{0:n.count}}),t[1]=n.count,t[2]=i);let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(g,{id:`l91IVc`}),t[3]=a):a=t[3];let o;return t[4]===i?o=t[5]:(o=(0,$.jsxs)(`div`,{role:`note`,"aria-live":`polite`,"data-testid":`problems-broken-link-suppression`,className:`mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-border/70 bg-muted/40 px-2 py-1.5 text-xs text-muted-foreground`,children:[r,(0,$.jsxs)(`span`,{className:`min-w-0`,children:[i,` `,a]})]}),t[4]=i,t[5]=o),o}function Br(e){let t=(0,Q.c)(24),{result:n,onNavigate:r,onCreateTarget:i,creatingTarget:a,expandedFiles:o,onToggleFile:s}=e,{_:c}=_(),l,u,d,f;if(t[0]!==c||t[1]!==n.warnings){let e=n.warnings.filter(Ur);l=n.warnings.filter(ze),u=`flex flex-col gap-1`,d=e.length>0&&(0,$.jsx)(`ul`,{"aria-label":c({id:`Rsdhj9`}),className:`flex flex-col gap-0.5 pb-1`,children:e.map(Hr)}),f=l.map(Vr),t[0]=c,t[1]=n.warnings,t[2]=l,t[3]=u,t[4]=d,t[5]=f}else l=t[2],u=t[3],d=t[4],f=t[5];let p;t[6]===n.brokenLinkSuppression?p=t[7]:(p=n.brokenLinkSuppression!==void 0&&(0,$.jsx)(zr,{suppression:n.brokenLinkSuppression}),t[6]=n.brokenLinkSuppression,t[7]=p);let m;t[8]!==a||t[9]!==l||t[10]!==o||t[11]!==i||t[12]!==r||t[13]!==s||t[14]!==n.brokenLinkSuppression||t[15]!==n.fileCount||t[16]!==n.files?(m=n.files.length===0?n.brokenLinkSuppression===void 0&&l.length===0?(0,$.jsx)(je,{className:`px-2`,children:(0,$.jsx)(g,{id:`k_Dqw1`,values:{0:n.fileCount}})}):null:n.files.map(e=>(0,$.jsx)(Wr,{file:e,onNavigate:r,onCreateTarget:i,creatingTarget:a,open:o.has(e.file),onOpenChange:t=>s(e.file,t)},e.file)),t[8]=a,t[9]=l,t[10]=o,t[11]=i,t[12]=r,t[13]=s,t[14]=n.brokenLinkSuppression,t[15]=n.fileCount,t[16]=n.files,t[17]=m):m=t[17];let h;return t[18]!==u||t[19]!==d||t[20]!==f||t[21]!==p||t[22]!==m?(h=(0,$.jsxs)(`div`,{className:u,children:[d,f,p,m]}),t[18]=u,t[19]=d,t[20]=f,t[21]=p,t[22]=m,t[23]=h):h=t[23],h}function Vr(e){return(0,$.jsxs)(`div`,{role:`status`,className:`flex items-start gap-1.5 px-2 text-xs`,children:[(0,$.jsx)(oe,{"aria-hidden":`true`,className:`mt-0.5 size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 text-foreground`,children:e})]},e)}function Hr(e,t){return(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 px-2 text-xs`,children:[(0,$.jsx)(le,{"aria-hidden":`true`,className:`mt-0.5 size-3.5 shrink-0 text-amber-500`}),(0,$.jsx)(`span`,{className:`min-w-0 text-foreground`,children:e})]},`${t}-${e}`)}function Ur(e){return!ze(e)}function Wr(e){let t=(0,Q.c)(45),{file:n,onNavigate:r,onCreateTarget:i,creatingTarget:a,open:o,onOpenChange:s}=e,{_:c}=_(),l,u,d,f,p,m,h,g,v,y;if(t[0]!==c||t[1]!==a||t[2]!==n.diagnostics||t[3]!==n.file||t[4]!==i||t[5]!==r||t[6]!==s||t[7]!==o){let e=[...n.diagnostics].sort(fr);u=D,h=o,g=s,v=`problems-audit-group`;let _;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(H,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90 motion-reduce:transition-none`}),t[18]=_):_=t[18];let b;t[19]===n.file?b=t[20]:(b=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,title:n.file,children:n.file}),t[19]=n.file,t[20]=b),y=(0,$.jsxs)(E,{className:`group flex w-full cursor-pointer items-center gap-1.5 rounded px-2 py-1.5 text-left transition-colors hover:bg-muted`,children:[_,b,(0,$.jsx)(de,{variant:`gray`,"data-testid":`problems-audit-file-count`,className:`shrink-0`,children:e.length})]}),l=T,m=`overflow-hidden data-[state=open]:animate-[collapsible-down_150ms_ease-out] data-[state=closed]:animate-[collapsible-up_150ms_ease-in] motion-reduce:animate-none`,t[21]!==c||t[22]!==n.file?(d=c({id:`zAJzIg`,values:{0:n.file}}),t[21]=c,t[22]=n.file,t[23]=d):d=t[23],f=`flex flex-col gap-0.5 pb-1 ps-3`;let x;t[24]!==c||t[25]!==a||t[26]!==n.file||t[27]!==i||t[28]!==r?(x=e=>(0,$.jsx)(yr,{group:e,onNavigate:e=>r(n.file,e),navTitle:e=>c({id:`xKDsGS`,values:{0:e.range.start.line+1,1:n.file}}),renderActions:e=>!gr(e)||i===void 0?null:(0,$.jsx)(Sr,{target:e.linkTarget??``,creating:a===e.linkTarget,disabled:a!==null,onCreate:()=>i(e)})},e.key),t[24]=c,t[25]=a,t[26]=n.file,t[27]=i,t[28]=r,t[29]=x):x=t[29],p=vr(e).map(x),t[0]=c,t[1]=a,t[2]=n.diagnostics,t[3]=n.file,t[4]=i,t[5]=r,t[6]=s,t[7]=o,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=v,t[17]=y}else l=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],v=t[16],y=t[17];let b;t[30]!==d||t[31]!==f||t[32]!==p?(b=(0,$.jsx)(`ul`,{"aria-label":d,className:f,children:p}),t[30]=d,t[31]=f,t[32]=p,t[33]=b):b=t[33];let x;t[34]!==l||t[35]!==m||t[36]!==b?(x=(0,$.jsx)(l,{className:m,children:b}),t[34]=l,t[35]=m,t[36]=b,t[37]=x):x=t[37];let S;return t[38]!==u||t[39]!==x||t[40]!==h||t[41]!==g||t[42]!==v||t[43]!==y?(S=(0,$.jsxs)(u,{open:h,onOpenChange:g,"data-testid":v,children:[y,x]}),t[38]=u,t[39]=x,t[40]=h,t[41]=g,t[42]=v,t[43]=y,t[44]=S):S=t[44],S}function Gr(e,t){return e.has(t)||P(t)}var Kr=/^(#{1,6})\s+(.+)$/;function qr(e,t){let n=(e.endsWith(`\r`)?e.slice(0,-1):e).match(Kr);if(!n)return null;let r=n[2].trim(),i=ve(r,t);return i?{level:n[1].length,text:r,slug:i}:null}var Jr=null,Yr=[];function Xr(e){if(e===Jr)return Yr;let t=Zr(e);return Jr=e,Yr=t,t}function Zr(e){let t=[],n=new Map,r=X();for(let i=Qr(e);i<=e.lines;i++){let a=e.line(i);if(r(a.text))continue;let o=qr(a.text,n);o&&t.push({slug:o.slug,from:a.from})}return t}function Qr(e){if(!$r(e.line(1).text))return 1;for(let t=2;t<=e.lines;t++)if($r(e.line(t).text))return t+1;return 1}function $r(e){return ee.test(e.endsWith(`\r`)?e.slice(0,-1):e)}function ei(e){let t=document.getElementById(e);return t?t.getBoundingClientRect().top:null}function ti(e){let t=new Map;for(let n of Xr(e.state.doc))t.set(n.slug,n.from);let n=e.documentTop;return r=>{let i=t.get(r);return i===void 0?null:n+e.lineBlockAt(i).top}}function ni(e,t){let n=(0,Q.c)(9),r;n[0]===t?r=n[1]:(r=t===void 0?{}:t,n[0]=t,n[1]=r);let{isSourceMode:i,docName:a}=r,o=i===void 0?!1:i,[s,c]=(0,Z.useState)(void 0),l=(0,Z.useRef)(null),u;n[2]===a?u=n[3]:(u=()=>a?q(a):null,n[2]=a,n[3]=u);let d=(0,Z.useSyncExternalStore)(K,u,ri),f,p;return n[4]!==o||n[5]!==e||n[6]!==d?(f=()=>{if(e.length===0||o&&!d){c(void 0);return}let t=function(){let t=o&&d?ti(d):ei,n=window.innerHeight/2,r,i;for(let a of e){let e=t(a);e!==null&&(e<0?r=a:i===void 0&&e<n&&(i=a))}c(i??r??e[0])},n=function(){l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},p=[e,o,d],n[4]=o,n[5]=e,n[6]=d,n[7]=f,n[8]=p):(f=n[7],p=n[8]),(0,Z.useEffect)(f,p),s}function ri(){return null}var ii=300;async function ai(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`),n;try{n=await t.json()}catch(e){throw new Y(N._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=z.safeParse(n);throw e.success?Error(e.data.title):new Y(N._({id:`zlErBl`}),{status:t.status})}let r=L.safeParse(n);if(!r.success)throw new Y(N._({id:`XW18jo`}),{status:t.status});return r.data.headings??[]}var oi=32,si=12,ci=6,li=`open-knowledge:outline-nav`,ui=`ok-outline-nav`,di=`ok-outline-nav-dispatch`,fi=`ok-outline-nav-settled`;function pi(e){let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(_e,{name:`outline-panel`,children:(0,$.jsx)(mi,{...e})}),t[0]=e,t[1]=n),n}function mi(e){let t=(0,Q.c)(65),{docName:n,isSourceMode:r,className:i}=e,a=i===void 0?``:i,{_:o}=_(),{pages:s,loading:l,error:u}=Oe(),d=v(),{activeProvider:f,activeDocName:p}=c(),m;t[0]!==n||t[1]!==s?(m=Gr(s,n),t[0]=n,t[1]=s,t[2]=m):m=t[2];let h=m,b;t[3]!==n||t[4]!==d?(b=d.getQueryState([`page-headings`,n]),t[3]=n,t[4]=d,t[5]=b):b=t[5];let S=!l&&u===null&&!h&&b!==void 0,C,w;t[6]===n?(C=t[7],w=t[8]):(C=[`page-headings`,n],w=()=>ai(n),t[6]=n,t[7]=C,t[8]=w);let T=!l&&h,E;t[9]!==C||t[10]!==w||t[11]!==T?(E={queryKey:C,queryFn:w,enabled:T,staleTime:1/0},t[9]=C,t[10]=w,t[11]=T,t[12]=E):E=t[12];let{data:D,isLoading:O,error:k}=y(E),A;t[13]===D?A=t[14]:(A=D===void 0?[]:D,t[13]=D,t[14]=A);let j=A,M,N;t[15]!==n||t[16]!==S||t[17]!==d?(M=()=>{S&&d.resetQueries({queryKey:[`page-headings`,n]})},N=[S,n,d],t[15]=n,t[16]=S,t[17]=d,t[18]=M,t[19]=N):(M=t[18],N=t[19]),(0,Z.useEffect)(M,N);let P,F;t[20]!==p||t[21]!==f||t[22]!==n||t[23]!==d?(P=()=>{if(!f||p!==n)return;let e=f.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,d.invalidateQueries({queryKey:[`page-headings`,n]})},ii)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},F=[f,p,n,d],t[20]=p,t[21]=f,t[22]=n,t[23]=d,t[24]=P,t[25]=F):(P=t[24],F=t[25]),(0,Z.useEffect)(P,F);let I=l||O,L;t[26]===j?L=t[27]:(L=j.map(hi),t[26]=j,t[27]=L);let ee=L,R;t[28]!==n||t[29]!==r?(R={isSourceMode:r,docName:n},t[28]=n,t[29]=r,t[30]=R):R=t[30];let z=ni(ee,R),B,V,H,U,te,W,G;if(t[31]!==o||t[32]!==z||t[33]!==a||t[34]!==n||t[35]!==k||t[36]!==j||t[37]!==I||t[38]!==r||t[39]!==S){let e=z?j.findIndex(e=>e.slug===z):-1,i=function(t,i){let a={docName:n,index:t,slug:i,mode:r?`source`:`wysiwyg`};a.mode===`source`&&wt(n,{kind:`outline`,detail:a}),he(di,{docName:n,index:t,mode:a.mode,outlineCount:j.length,headingLevel:j[t]?.level,activeIndex:e}),window.dispatchEvent(new CustomEvent(li,{detail:a}))},s=((e>=0?j[e].level:1)-1)*si+(si-ci)/2,c=e*oi+(oi-ci)/2;V=Fe,W=a;let l;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Ae,{children:(0,$.jsx)(g,{id:`dD7NPy`})}),t[47]=l):l=t[47];let u;t[48]!==k||t[49]!==j.length||t[50]!==I||t[51]!==S?(u=!I&&!k&&!S&&(0,$.jsx)(Ne,{children:j.length}),t[48]=k,t[49]=j.length,t[50]=I,t[51]=S,t[52]=u):u=t[52],t[53]===u?G=t[54]:(G=(0,$.jsx)(Pe,{children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[l,u]})}),t[53]=u,t[54]=G),B=Me,H=`px-3 py-2`,U=I,te=S?(0,$.jsx)(je,{className:`px-2`,role:`status`,children:(0,$.jsx)(g,{id:`0x9smA`})}):k?(0,$.jsx)(ke,{className:`px-2`,children:k instanceof Error?k.message:o({id:`GuqOb1`})}):j.length===0&&!I?(0,$.jsx)(je,{className:`px-2`,children:(0,$.jsx)(g,{id:`0BB9ID`})}):(0,$.jsxs)(`nav`,{"aria-label":o({id:`BymzO4`}),className:`relative`,children:[e>=0&&(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 rounded-full bg-primary motion-safe:[transition:transform_0.25s_var(--ease-out-strong)]`,style:{width:ci,height:ci,transform:`translate(${s}px, ${c}px)`}}),j.map((e,t)=>{let n=e.slug===z;return(0,$.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>i(t,e.slug),className:x(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*si+20}px`},title:e.text,children:e.text},t)})]}),t[31]=o,t[32]=z,t[33]=a,t[34]=n,t[35]=k,t[36]=j,t[37]=I,t[38]=r,t[39]=S,t[40]=B,t[41]=V,t[42]=H,t[43]=U,t[44]=te,t[45]=W,t[46]=G}else B=t[40],V=t[41],H=t[42],U=t[43],te=t[44],W=t[45],G=t[46];let K;t[55]!==B||t[56]!==H||t[57]!==U||t[58]!==te?(K=(0,$.jsx)(B,{className:H,"aria-busy":U,children:te}),t[55]=B,t[56]=H,t[57]=U,t[58]=te,t[59]=K):K=t[59];let q;return t[60]!==V||t[61]!==W||t[62]!==G||t[63]!==K?(q=(0,$.jsxs)(V,{className:W,children:[G,K]}),t[60]=V,t[61]=W,t[62]=G,t[63]=K,t[64]=q):q=t[64],q}function hi(e){return e.slug}var gi=!1;function _i(){return gi||!B()?!1:(gi=!0,!0)}export{mn as A,kt as B,Sn as C,Cn as D,wn as E,Pt as F,rt as G,yt as H,Dt as I,tt as K,Et as L,Rt as M,Qt as N,en as O,$t as P,At as R,gn as S,Tn as T,nt as U,wt as V,it as W,An as _,pi as a,Dn as b,dr as c,lr as d,ur as f,kn as g,On as h,fi as i,Yt as j,pn as k,Er as l,ar as m,ui as n,Xr as o,cr as p,li as r,Gr as s,_i as t,or as u,Mn as v,xn as w,En as x,Nn as y,Tt as z};
@@ -1,17 +0,0 @@
1
- import{i as e,o as t,t as n}from"./rolldown-runtime-tZXQYakl.mjs";import{Bd as r,Ea as i,Rd as a,Ud as o,Vd as s,Yu as c,ef as l,kc as u,ku as d,of as f,rf as p,sf as m,wc as h}from"./md-manager-BGnqyqi1-IqwoPmS1.mjs";import{Jn as g,Pn as _,Xo as v,Yo as y,fa as ee,lr as b,m as x,ns as S,ts as te,wo as ne,zo as re}from"./dist-BrWQNlOF.mjs";import{$ as ie,A as C,J as ae,M as w,O as T,P as oe,R as se,T as ce,X as E,at as le,ct as ue,d as de,dt as fe,f as pe,it as me,j as he,k as ge,lt as _e,nt as ve,o as ye,rt as be,tt as xe,v as Se,w as Ce,x as we,y as Te}from"./init-0oLlE1YP.mjs";import{t as Ee}from"./is-object-BGze3w87.mjs";import{t as De}from"./removal-file-path-BgjM5SuP.mjs";import{spawn as Oe}from"node:child_process";import{basename as D,dirname as O,join as k,resolve as A,win32 as ke}from"node:path";import{accessSync as Ae,constants as j,existsSync as M,lstatSync as N,mkdirSync as je,readFileSync as P,readdirSync as F,realpathSync as I,rmSync as Me,rmdirSync as Ne,statSync as L,unlinkSync as Pe}from"node:fs";import{homedir as Fe}from"node:os";import{createHash as Ie}from"node:crypto";import{isDeepStrictEqual as Le}from"node:util";import{setTimeout as Re}from"node:timers/promises";var ze=d();let Be;function Ve(){return Be}function He(e,t){if(t!==void 0&&t.length>0)return t;try{return b(e)?.rootPath}catch{return}}function Ue(e){let t=He(e.cwd,e.configuredProjectName),n=_({name:`cli`,project:t});return Be=n,n.info({command:e.command,cwd:e.cwd,project:t},`cli command started`),n}function R(){return u(h)}function z(){return p().keyringService}function B(e){try{e()}catch{}}var We=class{backend=`keyring`;onKeychainRead;constructor(e){this.onKeychainRead=e}async get(e){let{Entry:t}=await import(`@napi-rs/keyring`),n;try{n=new t(z(),e).getPassword()}catch(t){return B(()=>this.onKeychainRead?.({kind:`read-error`,host:e,error:t instanceof Error?t.name:`unknown`})),null}if(n==null)return B(()=>this.onKeychainRead?.({kind:`absent`,host:e})),null;try{return JSON.parse(n)}catch{return B(()=>this.onKeychainRead?.({kind:`corrupt-entry`,host:e,error:`corrupt-entry`})),null}}async set(e,t,n,r){let{Entry:i}=await import(`@napi-rs/keyring`),a=new i(z(),e),o={login:t,token:n,...r};a.setPassword(JSON.stringify(o))}async clear(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{new t(z(),e).deletePassword()}catch{}}},V=class{backend=`file`;authFile;constructor(e){this.authFile=e??k(v(),`auth.yml`)}read(){if(!M(this.authFile))return{};try{let e=P(this.authFile,`utf-8`);return(0,ze.parse)(e)??{}}catch(e){let t=e instanceof Error?e.message:`unknown error`;return process.stderr.write(`[auth] Failed to parse ${this.authFile}: ${t}. Starting with empty credentials.\n`),{}}}write(e){let t=O(this.authFile);M(t)||je(t,{recursive:!0,mode:448}),y(this.authFile,(0,ze.stringify)(e),{mode:384})}async get(e){return this.read()[e]??null}async set(e,t,n,r){let i=this.read();i[e]={login:t,token:n,...r},this.write(i)}async clear(e){let t=this.read();delete t[e],this.write(t)}},Ge=class{backend=`keyring`;keychain;file;constructor(e,t){this.keychain=e,this.file=t}async get(e){let t=await this.keychain.get(e);if(t!=null)return t;let n=await this.file.get(e);if(n==null)return null;try{await this.keychain.set(e,n.login,n.token,{gitProtocol:n.gitProtocol,name:n.name,email:n.email}),await this.file.clear(e),process.stderr.write(`[auth] migrated ${e} credential from ${R()} to the OS keychain\n`)}catch{}return n}set(e,t,n,r){return this.keychain.set(e,t,n,r)}async clear(e){await this.keychain.clear(e),await this.file.get(e)!=null&&await this.file.clear(e)}};async function Ke(e,t){try{let{Entry:n}=await import(`@napi-rs/keyring`);return new n(z(),`__probe__`),process.stderr.write(`[auth] token storage: OS keychain
2
- `),B(()=>t?.onBackendSelected?.({backend:`keyring`})),new Ge(new We(t?.onKeychainRead),new V(e))}catch(n){let r=n instanceof Error?`${n.name}: ${n.message}`:String(n);return process.stderr.write(`[auth] token storage: file (${R()}) — OS keychain unavailable: ${r}\n`),B(()=>t?.onBackendSelected?.({backend:`file`,reason:r})),new V(e)}}function qe(e){let t=null;return function(){if(t)return t;let n=2e3;return t=(async()=>{let t=null,r=new Promise(r=>{t=setTimeout(()=>{process.stderr.write(`[auth] token storage: keyring init exceeded ${n}ms; falling back to file (${R()})\n`),r(new V(e))},n)});try{return await Promise.race([Ke(e),r])}catch{return new V(e)}finally{t!==null&&clearTimeout(t)}})(),t}}function Je(e){let t=qe(e);return{async get(e){let n=await(await t()).get(e);return n===null?null:{token:n.token,login:n.login}}}}function Ye(e){let t=qe(e);return{backend:`file`,async get(e){return(await t()).get(e)},async set(e,n,r,i){return(await t()).set(e,n,r,i)},async clear(e){return(await t()).clear(e)}}}async function Xe(e,t){let n=[],r=new V(t);await r.get(e)!=null&&(await r.clear(e),n.push(`file`));let i;try{let{Entry:t}=await import(`@napi-rs/keyring`);new t(z(),`__probe__`);let r,a=await new We(e=>{e.kind===`read-error`&&(r=e.error??`read-error`)}).get(e);if(r!==void 0)i=r;else if(a!=null)try{new t(z(),e).deletePassword(),n.push(`keychain`)}catch(e){i=e instanceof Error?e.name:`delete-error`}}catch{}return{touched:n,keychainError:i}}function Ze(e){let t={...e};return delete t.ELECTRON_RUN_AS_NODE,t}function Qe(e){let t=e?.code;return t===`ENOENT`||t===`EACCES`||t===`EPERM`?{ok:!1,reason:`not-installed`}:{ok:!1,reason:`spawn-error`}}function $e(e){return ne({detached:!0,stdio:`ignore`,shell:!1,env:Ze(e)})}function et(e,t,n={}){let r=(n.spawn??Oe)(e,[...t],$e(n.env??process.env));return r.unref(),r}function tt(e,t,n={}){let r=n.spawn??Oe,i=n.timeoutMs??2e3;return new Promise(a=>{let o=!1,s=e=>{o||(o=!0,a(e))},c=setTimeout(()=>s({ok:!1,reason:`timeout`}),i);try{let i=r(e,[...t],$e(n.env??process.env));i.once(`error`,e=>{clearTimeout(c),s(Qe(e))}),i.once(`spawn`,()=>{clearTimeout(c),s({ok:!0})});try{i.unref()}catch{}}catch(e){clearTimeout(c),s(Qe(e))}})}const nt=l.stable.appId,H=[l.stable,l.beta];function rt(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return L(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function it(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}let t=e.homeDir??Fe();for(let n of H)for(let r of[k(t,`Applications`),`/Applications`]){let t=k(r,`${n.productName}.app`);if(at(e,k(t,`Contents`,`MacOS`,n.productName)))return t}return null}function at(e,t){try{let n=e.statSync(t);return n?typeof n.isFile==`function`&&n.isFile():!1}catch{return!1}}function ot(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`&&H.find(t=>e.execPath.toLowerCase().endsWith(`\\${f(t).toLowerCase()}`)))return e.execPath;let t=e.env.LOCALAPPDATA;if(t)for(let n of H)for(let r of m(n)){let i=ke.join(t,`Programs`,r,f(n));if(at(e,i))return i}return null}function st(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`&&H.find(t=>e.execPath.endsWith(`/${t.linuxExecutableName}`)))return e.execPath;for(let t of H){let n=`/opt/${t.productName}/${t.linuxExecutableName}`;if(at(e,n))return n}return null}function ct(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`&&e.platform!==`win32`&&e.platform!==`linux`)return{available:!1,reason:`unsupported-platform`};let t;try{t=e.platform===`darwin`?it(e):e.platform===`win32`?ot(e):st(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:!(e.isTTY===!0||e.platform===`win32`&&e.isTTY===void 0&&!e.env.CI)||e.env.SSH_CONNECTION||e.env.SSH_TTY||e.platform===`linux`&&!e.env.DISPLAY&&!e.env.WAYLAND_DISPLAY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function lt(e,t){let n=e.log??(e=>console.error(e)),r=e.platform??process.platform;n("Launching OpenKnowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let i=t?.bundlePath;if(!i){n(`Desktop launch skipped: no resolved desktop executable (caller bug).`);return}if(r===`darwin`){et(`open`,[`-a`,i],{spawn:e.spawn});return}et(i,[],{spawn:e.spawn})}function ut(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found (checked the standard install locations for this OS). Install it from https://openknowledge.ai/download, or omit --mode for browser mode.`;case`darwin-only`:case`unsupported-platform`:return`Desktop app is not available on this platform. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect the desktop install (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available but launch dispatch did not fire (caller bug).`}}function U(e){return e.replace(/[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\u200b\ufeff]/gu,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function dt(e){return Ie(`sha256`).update(e).digest(`hex`)}function W(e){return k(v(A(e)),`pi-trust`)}function ft(e,t){return k(W(e),dt(A(t)))}function pt(e,t,n){return k(ft(e,t),`${dt(n)}.json`)}var G=class extends Error{constructor(e,t,n,r){super(`Pi trust receipt at ${U(e)} ${U(t)}; ${U(n)}`,{cause:r}),this.name=`PiTrustReceiptError`}};function K(e,t,n){let r=n.code,i=n instanceof Error?n.message:String(n),a;switch(r){case`EACCES`:case`EPERM`:a=`check receipt and parent-directory permissions, then retry`;break;case`ENOENT`:a=`the location no longer exists; restore access to its expected location, then retry`;break;default:a=`check the path and available storage, then retry`}return new G(e,`could not ${t}: ${i}`,a,n)}function q(e){let t;try{t=N(e)}catch(t){if(t.code===`ENOENT`)return!1;throw K(e,`be inspected`,t)}if(!t.isDirectory())throw new G(e,`is not a regular directory`,`restore the intended receipt directory without a symlink, then retry`);return!0}function mt(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}function ht(e,t){if(!Ee(e)||!mt(e,[`version`,`cwd`,`configuredTrustPath`,`canonicalTrustPath`,`state`,`previous`])||e.version!==1||typeof e.cwd!=`string`||e.cwd!==A(e.cwd)||typeof e.configuredTrustPath!=`string`||e.configuredTrustPath!==A(e.configuredTrustPath)||typeof e.canonicalTrustPath!=`string`||e.canonicalTrustPath!==A(e.canonicalTrustPath)||e.state!==`pending`&&e.state!==`committed`||!Ee(e.previous))throw new G(t,`has invalid contents`,`restore a valid ownership record from a backup without guessing its trust decision, then retry`);let n;if(e.previous.present===!1&&mt(e.previous,[`present`]))n={present:!1};else if(e.previous.present===!0&&mt(e.previous,[`present`,`value`]))n={present:!0,value:e.previous.value};else throw new G(t,`has an invalid previous decision`,`restore the recorded previous decision from a backup without guessing its value, then retry`);return{version:1,cwd:e.cwd,configuredTrustPath:e.configuredTrustPath,canonicalTrustPath:e.canonicalTrustPath,state:e.state,previous:n}}function gt(e,t,n){let r;try{r=N(n)}catch(e){throw K(n,`be inspected`,e)}if(!r.isFile())throw new G(n,`is not a regular file`,`restore the intended receipt as a regular file without a symlink, then retry`);let i;try{i=P(n,`utf8`)}catch(e){throw K(n,`be read`,e)}let a;try{a=JSON.parse(i)}catch(e){throw new G(n,`is not valid JSON`,`repair its JSON syntax without changing the recorded decision, then retry`,e)}let o=ht(a,n);if(o.cwd!==A(t)||n!==pt(e,t,o.canonicalTrustPath))throw new G(n,`does not match its project or trust-store location`,`restore the ownership record to its original project and trust-store location, then retry`);return{path:n,record:o}}function _t(e,t){let{record:n,path:r}=t;for(let t of[W(e),ft(e,n.cwd)])if(!q(t))throw new G(t,`no longer exists`,`restore access to the expected receipt directory, then retry`);let i=gt(e,n.cwd,r);if(!Le(i.record,n))throw new G(r,`changed while its trust decision was being updated`,`retry to read its current ownership record`);return i}function vt(e,t,n,r,i){let a={version:1,cwd:A(t),configuredTrustPath:A(n),canonicalTrustPath:A(r),state:`pending`,previous:i},o=pt(e,a.cwd,a.canonicalTrustPath),s=`${JSON.stringify(a,null,2)}\n`;if(!Le(ht(JSON.parse(s),o),a))throw new G(o,`cannot preserve the previous decision as JSON`,`provide the original decision as a JSON value before retrying`);q(W(e)),q(O(o));try{je(O(o),{recursive:!0,mode:448})}catch(e){throw K(O(o),`be created`,e)}let c;try{c=N(o,{throwIfNoEntry:!1})}catch(e){throw K(o,`be inspected`,e)}if(c)throw new G(o,`already exists`,`reconcile the existing ownership record before recording another grant`);try{y(o,s,{mode:384})}catch(e){throw K(o,`be written`,e)}return{path:o,record:a}}function yt(e,t){let n=_t(e,t);if(n.record.state!==`pending`)throw new G(n.path,`is already committed`,`use the current ownership record without committing it again`);let r={...n.record,state:`committed`};try{y(n.path,`${JSON.stringify(r,null,2)}\n`,{mode:384})}catch(e){throw K(n.path,`be committed`,e)}return{path:n.path,record:r}}function J(e,t){if(!q(W(e)))return[];let n=ft(e,t);if(!q(n))return[];let r;try{r=F(n).sort()}catch(e){throw K(n,`be listed`,e)}return r.filter(e=>/^[a-f0-9]{64}\.json$/.test(e)).map(r=>gt(e,t,k(n,r)))}function Y(e,t){let n=_t(e,t);try{Pe(n.path)}catch(e){throw K(n.path,`be removed after reconciling its grant`,e)}for(let t of[O(n.path),W(e)])try{Ne(t)}catch(e){let n=e.code;if(n!==`ENOTEMPTY`&&n!==`EEXIST`&&n!==`ENOENT`)throw K(t,`be removed after reconciling its grant`,e)}}var bt=n(((t,n)=>{var r=e(`constants`),i=process.cwd,a=null,o=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return a||=i.call(process),a};try{process.cwd()}catch{}if(typeof process.chdir==`function`){var s=process.chdir;process.chdir=function(e){a=null,s.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,s)}n.exports=c;function c(e){r.hasOwnProperty(`O_SYMLINK`)&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||n(e),e.chown=s(e.chown),e.fchown=s(e.fchown),e.lchown=s(e.lchown),e.chmod=i(e.chmod),e.fchmod=i(e.fchmod),e.lchmod=i(e.lchmod),e.chownSync=c(e.chownSync),e.fchownSync=c(e.fchownSync),e.lchownSync=c(e.lchownSync),e.chmodSync=a(e.chmodSync),e.fchmodSync=a(e.fchmodSync),e.lchmodSync=a(e.lchmodSync),e.stat=l(e.stat),e.fstat=l(e.fstat),e.lstat=l(e.lstat),e.statSync=u(e.statSync),e.fstatSync=u(e.fstatSync),e.lstatSync=u(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(e,t,n){n&&process.nextTick(n)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(e,t,n,r){r&&process.nextTick(r)},e.lchownSync=function(){}),o===`win32`&&(e.rename=typeof e.rename==`function`?(function(t){function n(n,r,i){var a=Date.now(),o=0;t(n,r,function s(c){if(c&&(c.code===`EACCES`||c.code===`EPERM`||c.code===`EBUSY`)&&Date.now()-a<6e4){setTimeout(function(){e.stat(r,function(e,a){e&&e.code===`ENOENT`?t(n,r,s):i(c)})},o),o<100&&(o+=10);return}i&&i(c)})}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n})(e.rename):e.rename),e.read=typeof e.read==`function`?(function(t){function n(n,r,i,a,o,s){var c;if(s&&typeof s==`function`){var l=0;c=function(u,d,f){if(u&&u.code===`EAGAIN`&&l<10)return l++,t.call(e,n,r,i,a,o,c);s.apply(this,arguments)}}return t.call(e,n,r,i,a,o,c)}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n})(e.read):e.read,e.readSync=typeof e.readSync==`function`?(function(t){return function(n,r,i,a,o){for(var s=0;;)try{return t.call(e,n,r,i,a,o)}catch(e){if(e.code===`EAGAIN`&&s<10){s++;continue}throw e}}})(e.readSync):e.readSync;function t(e){e.lchmod=function(t,n,i){e.open(t,r.O_WRONLY|r.O_SYMLINK,n,function(t,r){if(t){i&&i(t);return}e.fchmod(r,n,function(t){e.close(r,function(e){i&&i(t||e)})})})},e.lchmodSync=function(t,n){var i=e.openSync(t,r.O_WRONLY|r.O_SYMLINK,n),a=!0,o;try{o=e.fchmodSync(i,n),a=!1}finally{if(a)try{e.closeSync(i)}catch{}else e.closeSync(i)}return o}}function n(e){r.hasOwnProperty(`O_SYMLINK`)&&e.futimes?(e.lutimes=function(t,n,i,a){e.open(t,r.O_SYMLINK,function(t,r){if(t){a&&a(t);return}e.futimes(r,n,i,function(t){e.close(r,function(e){a&&a(t||e)})})})},e.lutimesSync=function(t,n,i){var a=e.openSync(t,r.O_SYMLINK),o,s=!0;try{o=e.futimesSync(a,n,i),s=!1}finally{if(s)try{e.closeSync(a)}catch{}else e.closeSync(a)}return o}):e.futimes&&(e.lutimes=function(e,t,n,r){r&&process.nextTick(r)},e.lutimesSync=function(){})}function i(t){return t&&function(n,r,i){return t.call(e,n,r,function(e){d(e)&&(e=null),i&&i.apply(this,arguments)})}}function a(t){return t&&function(n,r){try{return t.call(e,n,r)}catch(e){if(!d(e))throw e}}}function s(t){return t&&function(n,r,i,a){return t.call(e,n,r,i,function(e){d(e)&&(e=null),a&&a.apply(this,arguments)})}}function c(t){return t&&function(n,r,i){try{return t.call(e,n,r,i)}catch(e){if(!d(e))throw e}}}function l(t){return t&&function(n,r,i){typeof r==`function`&&(i=r,r=null);function a(e,t){t&&(t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296)),i&&i.apply(this,arguments)}return r?t.call(e,n,r,a):t.call(e,n,a)}}function u(t){return t&&function(n,r){var i=r?t.call(e,n,r):t.call(e,n);return i&&(i.uid<0&&(i.uid+=4294967296),i.gid<0&&(i.gid+=4294967296)),i}}function d(e){return!e||e.code===`ENOSYS`||(!process.getuid||process.getuid()!==0)&&(e.code===`EINVAL`||e.code===`EPERM`)}}})),xt=n(((t,n)=>{var r=e(`stream`).Stream;n.exports=i;function i(e){return{ReadStream:t,WriteStream:n};function t(n,i){if(!(this instanceof t))return new t(n,i);r.call(this);var a=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags=`r`,this.mode=438,this.bufferSize=65536,i||={};for(var o=Object.keys(i),s=0,c=o.length;s<c;s++){var l=o[s];this[l]=i[l]}if(this.encoding&&this.setEncoding(this.encoding),this.start!==void 0){if(typeof this.start!=`number`)throw TypeError(`start must be a Number`);if(this.end===void 0)this.end=1/0;else if(typeof this.end!=`number`)throw TypeError(`end must be a Number`);if(this.start>this.end)throw Error(`start must be <= end`);this.pos=this.start}if(this.fd!==null){process.nextTick(function(){a._read()});return}e.open(this.path,this.flags,this.mode,function(e,t){if(e){a.emit(`error`,e),a.readable=!1;return}a.fd=t,a.emit(`open`,t),a._read()})}function n(t,i){if(!(this instanceof n))return new n(t,i);r.call(this),this.path=t,this.fd=null,this.writable=!0,this.flags=`w`,this.encoding=`binary`,this.mode=438,this.bytesWritten=0,i||={};for(var a=Object.keys(i),o=0,s=a.length;o<s;o++){var c=a[o];this[c]=i[c]}if(this.start!==void 0){if(typeof this.start!=`number`)throw TypeError(`start must be a Number`);if(this.start<0)throw Error(`start must be >= zero`);this.pos=this.start}this.busy=!1,this._queue=[],this.fd===null&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}})),St=n(((e,t)=>{t.exports=r;var n=Object.getPrototypeOf||function(e){return e.__proto__};function r(e){if(typeof e!=`object`||!e)return e;if(e instanceof Object)var t={__proto__:n(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}),t}})),Ct=n(((t,n)=>{var r=e(`fs`),i=bt(),a=xt(),o=St(),s=e(`util`),c,l;typeof Symbol==`function`&&typeof Symbol.for==`function`?(c=Symbol.for(`graceful-fs.queue`),l=Symbol.for(`graceful-fs.previous`)):(c=`___graceful-fs.queue`,l=`___graceful-fs.previous`);function u(){}function d(e,t){Object.defineProperty(e,c,{get:function(){return t}})}var f=u;s.debuglog?f=s.debuglog(`gfs4`):/\bgfs4\b/i.test(process.env.NODE_DEBUG||``)&&(f=function(){var e=s.format.apply(s,arguments);e=`GFS4: `+e.split(/\n/).join(`
3
- GFS4: `),console.error(e)}),r[c]||(d(r,global[c]||[]),r.close=(function(e){function t(t,n){return e.call(r,t,function(e){e||g(),typeof n==`function`&&n.apply(this,arguments)})}return Object.defineProperty(t,l,{value:e}),t})(r.close),r.closeSync=(function(e){function t(t){e.apply(r,arguments),g()}return Object.defineProperty(t,l,{value:e}),t})(r.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||``)&&process.on(`exit`,function(){f(r[c]),e(`assert`).equal(r[c].length,0)})),global[c]||d(global,r[c]),n.exports=p(o(r)),process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!r.__patched&&(n.exports=p(r),r.__patched=!0);function p(e){i(e),e.gracefulify=p,e.createReadStream=ne,e.createWriteStream=re;var t=e.readFile;e.readFile=n;function n(e,n,r){return typeof n==`function`&&(r=n,n=null),i(e,n,r);function i(e,n,r,a){return t(e,n,function(t){t&&(t.code===`EMFILE`||t.code===`ENFILE`)?m([i,[e,n,r],t,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var r=e.writeFile;e.writeFile=o;function o(e,t,n,i){return typeof n==`function`&&(i=n,n=null),a(e,t,n,i);function a(e,t,n,i,o){return r(e,t,n,function(r){r&&(r.code===`EMFILE`||r.code===`ENFILE`)?m([a,[e,t,n,i],r,o||Date.now(),Date.now()]):typeof i==`function`&&i.apply(this,arguments)})}}var s=e.appendFile;s&&(e.appendFile=c);function c(e,t,n,r){return typeof n==`function`&&(r=n,n=null),i(e,t,n,r);function i(e,t,n,r,a){return s(e,t,n,function(o){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var l=e.copyFile;l&&(e.copyFile=u);function u(e,t,n,r){return typeof n==`function`&&(r=n,n=0),i(e,t,n,r);function i(e,t,n,r,a){return l(e,t,n,function(o){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var d=e.readdir;e.readdir=h;var f=/^v[0-5]\./;function h(e,t,n){typeof t==`function`&&(n=t,t=null);var r=f.test(process.version)?function(e,t,n,r){return d(e,i(e,t,n,r))}:function(e,t,n,r){return d(e,t,i(e,t,n,r))};return r(e,t,n);function i(e,t,n,i){return function(a,o){a&&(a.code===`EMFILE`||a.code===`ENFILE`)?m([r,[e,t,n],a,i||Date.now(),Date.now()]):(o&&o.sort&&o.sort(),typeof n==`function`&&n.call(this,a,o))}}}if(process.version.substr(0,4)===`v0.8`){var g=a(e);b=g.ReadStream,S=g.WriteStream}var _=e.ReadStream;_&&(b.prototype=Object.create(_.prototype),b.prototype.open=x);var v=e.WriteStream;v&&(S.prototype=Object.create(v.prototype),S.prototype.open=te),Object.defineProperty(e,"ReadStream",{get:function(){return b},set:function(e){b=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return S},set:function(e){S=e},enumerable:!0,configurable:!0});var y=b;Object.defineProperty(e,"FileReadStream",{get:function(){return y},set:function(e){y=e},enumerable:!0,configurable:!0});var ee=S;Object.defineProperty(e,"FileWriteStream",{get:function(){return ee},set:function(e){ee=e},enumerable:!0,configurable:!0});function b(e,t){return this instanceof b?(_.apply(this,arguments),this):b.apply(Object.create(b.prototype),arguments)}function x(){var e=this;C(e.path,e.flags,e.mode,function(t,n){t?(e.autoClose&&e.destroy(),e.emit(`error`,t)):(e.fd=n,e.emit(`open`,n),e.read())})}function S(e,t){return this instanceof S?(v.apply(this,arguments),this):S.apply(Object.create(S.prototype),arguments)}function te(){var e=this;C(e.path,e.flags,e.mode,function(t,n){t?(e.destroy(),e.emit(`error`,t)):(e.fd=n,e.emit(`open`,n))})}function ne(t,n){return new e.ReadStream(t,n)}function re(t,n){return new e.WriteStream(t,n)}var ie=e.open;e.open=C;function C(e,t,n,r){return typeof n==`function`&&(r=n,n=null),i(e,t,n,r);function i(e,t,n,r,a){return ie(e,t,n,function(o,s){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}return e}function m(e){f(`ENQUEUE`,e[0].name,e[1]),r[c].push(e),_()}var h;function g(){for(var e=Date.now(),t=0;t<r[c].length;++t)r[c][t].length>2&&(r[c][t][3]=e,r[c][t][4]=e);_()}function _(){if(clearTimeout(h),h=void 0,r[c].length!==0){var e=r[c].shift(),t=e[0],n=e[1],i=e[2],a=e[3],o=e[4];if(a===void 0)f(`RETRY`,t.name,n),t.apply(null,n);else if(Date.now()-a>=6e4){f(`TIMEOUT`,t.name,n);var s=n.pop();typeof s==`function`&&s.call(null,i)}else{var l=Date.now()-o,u=Math.max(o-a,1);l>=Math.min(u*1.2,100)?(f(`RETRY`,t.name,n),t.apply(null,n.concat([a]))):r[c].push(e)}h===void 0&&(h=setTimeout(_,0))}}})),wt=n(((e,t)=>{function n(e,t){typeof t==`boolean`&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}t.exports=n,n.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},n.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null},n.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(Error(`RetryOperation timeout occurred`)),!1;this._errors.push(e);var n=this._timeouts.shift();if(n===void 0){if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),n=this._timeouts.shift();else return!1}var r=this,i=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},n);return this._options.unref&&i.unref(),!0},n.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)},n.prototype.try=function(e){console.log(`Using RetryOperation.try() is deprecated`),this.attempt(e)},n.prototype.start=function(e){console.log(`Using RetryOperation.start() is deprecated`),this.attempt(e)},n.prototype.start=n.prototype.try,n.prototype.errors=function(){return this._errors},n.prototype.attempts=function(){return this._attempts},n.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var i=this._errors[r],a=i.message,o=(e[a]||0)+1;e[a]=o,o>=n&&(t=i,n=o)}return t}})),Tt=n((e=>{var t=wt();e.operation=function(n){return new t(e.timeouts(n),{forever:n&&n.forever,unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw Error(`minTimeout is greater than maxTimeout`);for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(e,t){return e-t}),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*t.minTimeout*t.factor**+e);return r=Math.min(r,t.maxTimeout),r},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var i in r=[],t)typeof t[i]==`function`&&r.push(i);for(var a=0;a<r.length;a++){var o=r[a],s=t[o];t[o]=function(r){var i=e.operation(n),a=Array.prototype.slice.call(arguments,1),o=a.pop();a.push(function(e){i.retry(e)||(e&&(arguments[0]=i.mainError()),o.apply(this,arguments))}),i.attempt(function(){r.apply(t,a)})}.bind(t,s),t[o].options=n}}})),Et=n(((e,t)=>{t.exports=Tt()})),Dt=n(((e,t)=>{t.exports=[`SIGABRT`,`SIGALRM`,`SIGHUP`,`SIGINT`,`SIGTERM`],process.platform!==`win32`&&t.exports.push(`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),process.platform===`linux`&&t.exports.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`,`SIGUNUSED`)})),Ot=n(((t,n)=>{var r=global.process;let i=function(e){return e&&typeof e==`object`&&typeof e.removeListener==`function`&&typeof e.emit==`function`&&typeof e.reallyExit==`function`&&typeof e.listeners==`function`&&typeof e.kill==`function`&&typeof e.pid==`number`&&typeof e.on==`function`};if(!i(r))n.exports=function(){return function(){}};else{var a=e(`assert`),o=Dt(),s=/^win/i.test(r.platform),c=e(`events`);typeof c!=`function`&&(c=c.EventEmitter);var l;r.__signal_exit_emitter__?l=r.__signal_exit_emitter__:(l=r.__signal_exit_emitter__=new c,l.count=0,l.emitted={}),l.infinite||(l.setMaxListeners(1/0),l.infinite=!0),n.exports=function(e,t){if(!i(global.process))return function(){};a.equal(typeof e,`function`,`a callback must be provided for exit handler`),p===!1&&m();var n=`exit`;return t&&t.alwaysLast&&(n=`afterexit`),l.on(n,e),function(){l.removeListener(n,e),l.listeners(`exit`).length===0&&l.listeners(`afterexit`).length===0&&u()}};var u=function(){!p||!i(global.process)||(p=!1,o.forEach(function(e){try{r.removeListener(e,f[e])}catch{}}),r.emit=_,r.reallyExit=h,--l.count)};n.exports.unload=u;var d=function(e,t,n){l.emitted[e]||(l.emitted[e]=!0,l.emit(e,t,n))},f={};o.forEach(function(e){f[e]=function(){i(global.process)&&r.listeners(e).length===l.count&&(u(),d(`exit`,null,e),d(`afterexit`,null,e),s&&e===`SIGHUP`&&(e=`SIGINT`),r.kill(r.pid,e))}}),n.exports.signals=function(){return o};var p=!1,m=function(){p||!i(global.process)||(p=!0,l.count+=1,o=o.filter(function(e){try{return r.on(e,f[e]),!0}catch{return!1}}),r.emit=v,r.reallyExit=g)};n.exports.load=m;var h=r.reallyExit,g=function(e){i(global.process)&&(r.exitCode=e||0,d(`exit`,r.exitCode,null),d(`afterexit`,r.exitCode,null),h.call(r,r.exitCode))},_=r.emit,v=function(e,t){if(e===`exit`&&i(global.process)){t!==void 0&&(r.exitCode=t);var n=_.apply(this,arguments);return d(`exit`,r.exitCode,null),d(`afterexit`,r.exitCode,null),n}return _.apply(this,arguments)}}})),kt=n(((e,t)=>{let n=Symbol();function r(e,t,r){let i=t[n];if(i)return t.stat(e,(e,t)=>{if(e)return r(e);r(null,t.mtime,i)});let a=new Date(Math.ceil(Date.now()/1e3)*1e3+5);t.utimes(e,a,a,i=>{if(i)return r(i);t.stat(e,(e,i)=>{if(e)return r(e);let a=i.mtime.getTime()%1e3==0?`s`:`ms`;Object.defineProperty(t,n,{value:a}),r(null,i.mtime,a)})})}function i(e){let t=Date.now();return e===`s`&&(t=Math.ceil(t/1e3)*1e3),new Date(t)}t.exports.probe=r,t.exports.getMtime=i})),At=n(((t,n)=>{let r=e(`path`),i=Ct(),a=Et(),o=Ot(),s=kt(),c={};function l(e,t){return t.lockfilePath||`${e}.lock`}function u(e,t,n){if(!t.realpath)return n(null,r.resolve(e));t.fs.realpath(e,n)}function d(e,t,n){let r=l(e,t);t.fs.mkdir(r,i=>{if(!i)return s.probe(r,t.fs,(e,i,a)=>{if(e)return t.fs.rmdir(r,()=>{}),n(e);n(null,i,a)});if(i.code!==`EEXIST`)return n(i);if(t.stale<=0)return n(Object.assign(Error(`Lock file is already being held`),{code:`ELOCKED`,file:e}));t.fs.stat(r,(r,i)=>{if(r)return r.code===`ENOENT`?d(e,{...t,stale:0},n):n(r);if(!f(i,t))return n(Object.assign(Error(`Lock file is already being held`),{code:`ELOCKED`,file:e}));p(e,t,r=>{if(r)return n(r);d(e,{...t,stale:0},n)})})})}function f(e,t){return e.mtime.getTime()<Date.now()-t.stale}function p(e,t,n){t.fs.rmdir(l(e,t),e=>{if(e&&e.code!==`ENOENT`)return n(e);n()})}function m(e,t){let n=c[e];n.updateTimeout||(n.updateDelay=n.updateDelay||t.update,n.updateTimeout=setTimeout(()=>{n.updateTimeout=null,t.fs.stat(n.lockfilePath,(r,i)=>{let a=n.lastUpdate+t.stale<Date.now();if(r)return r.code===`ENOENT`||a?h(e,n,Object.assign(r,{code:`ECOMPROMISED`})):(n.updateDelay=1e3,m(e,t));if(n.mtime.getTime()!==i.mtime.getTime())return h(e,n,Object.assign(Error(`Unable to update lock within the stale threshold`),{code:`ECOMPROMISED`}));let o=s.getMtime(n.mtimePrecision);t.fs.utimes(n.lockfilePath,o,o,r=>{let i=n.lastUpdate+t.stale<Date.now();if(!n.released){if(r)return r.code===`ENOENT`||i?h(e,n,Object.assign(r,{code:`ECOMPROMISED`})):(n.updateDelay=1e3,m(e,t));n.mtime=o,n.lastUpdate=Date.now(),n.updateDelay=null,m(e,t)}})})},n.updateDelay),n.updateTimeout.unref&&n.updateTimeout.unref())}function h(e,t,n){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),c[e]===t&&delete c[e],t.options.onCompromised(n)}function g(e,t,n){t={stale:1e4,update:null,realpath:!0,retries:0,fs:i,onCompromised:e=>{throw e},...t},t.retries=t.retries||0,t.retries=typeof t.retries==`number`?{retries:t.retries}:t.retries,t.stale=Math.max(t.stale||0,2e3),t.update=t.update==null?t.stale/2:t.update||0,t.update=Math.max(Math.min(t.update,t.stale/2),1e3),u(e,t,(e,r)=>{if(e)return n(e);let i=a.operation(t.retries);i.attempt(()=>{d(r,t,(e,a,o)=>{if(i.retry(e))return;if(e)return n(i.mainError());let s=c[r]={lockfilePath:l(r,t),mtime:a,mtimePrecision:o,options:t,lastUpdate:Date.now()};m(r,t),n(null,e=>{if(s.released)return e&&e(Object.assign(Error(`Lock is already released`),{code:`ERELEASED`}));_(r,{...t,realpath:!1},e)})})})})}function _(e,t,n){t={fs:i,realpath:!0,...t},u(e,t,(e,r)=>{if(e)return n(e);let i=c[r];if(!i)return n(Object.assign(Error(`Lock is not acquired/owned by you`),{code:`ENOTACQUIRED`}));i.updateTimeout&&clearTimeout(i.updateTimeout),i.released=!0,delete c[r],p(r,t,n)})}function v(e,t,n){t={stale:1e4,realpath:!0,fs:i,...t},t.stale=Math.max(t.stale||0,2e3),u(e,t,(e,r)=>{if(e)return n(e);t.fs.stat(l(r,t),(e,r)=>e?e.code===`ENOENT`?n(null,!1):n(e):n(null,!f(r,t)))})}function y(){return c}o(()=>{for(let e in c){let t=c[e].options;try{t.fs.rmdirSync(l(e,t))}catch{}}}),n.exports.lock=g,n.exports.unlock=_,n.exports.check=v,n.exports.getLocks=y})),jt=n(((e,t)=>{let n=Ct();function r(e){let t=[`mkdir`,`realpath`,`stat`,`rmdir`,`utimes`],n={...e};return t.forEach(t=>{n[t]=(...n)=>{let r=n.pop(),i;try{i=e[`${t}Sync`](...n)}catch(e){return r(e)}r(null,i)}}),n}function i(e){return(...t)=>new Promise((n,r)=>{t.push((e,t)=>{e?r(e):n(t)}),e(...t)})}function a(e){return(...t)=>{let n,r;if(t.push((e,t)=>{n=e,r=t}),e(...t),n)throw n;return r}}function o(e){if(e={...e},e.fs=r(e.fs||n),typeof e.retries==`number`&&e.retries>0||e.retries&&typeof e.retries.retries==`number`&&e.retries.retries>0)throw Object.assign(Error(`Cannot use retries with the sync api`),{code:`ESYNC`});return e}t.exports={toPromise:i,toSync:a,toSyncOptions:o}})),Mt=t(n(((e,t)=>{let n=At(),{toPromise:r,toSync:i,toSyncOptions:a}=jt();async function o(e,t){let i=await r(n.lock)(e,t);return r(i)}function s(e,t){let r=i(n.lock)(e,a(t));return i(r)}function c(e,t){return r(n.unlock)(e,t)}function l(e,t){return i(n.unlock)(e,a(t))}function u(e,t){return r(n.check)(e,t)}function d(e,t){return i(n.check)(e,a(t))}t.exports=o,t.exports.lock=o,t.exports.unlock=c,t.exports.lockSync=s,t.exports.unlockSync=l,t.exports.check=u,t.exports.checkSync=d}))(),1);const Nt=5e3;function Pt(e,t,n){if(!(e instanceof Error)||!(`code`in e)||e.code!==`ELOCKED`)throw e;let r=t-performance.now();if(r<=0)throw Object.assign(Error(`Could not acquire Pi trust lock at ${n}.lock within ${Nt}ms`,{cause:e}),{code:`ELOCKED`});return Math.min(25,r)}function Ft(e,t){Ve()?.warn(t,e)}function It(e,t){if(e.length===0)return;if(e.length===1)throw e[0];let[n,r]=e,i=n instanceof Error?n.message:String(n),a=r instanceof Error?r.message:String(r);throw AggregateError(e,`Pi trust update failed: ${i}\nReleasing Pi trust lock ${t}.lock also failed: ${a}`)}async function Lt(e,t,n){await te(`${t}.ok.lock`,async()=>{let t=performance.now()+Nt,r;for(;;)try{r=await Mt.default.lock(O(e),{realpath:!1,lockfilePath:`${e}.lock`});break}catch(n){await Re(Pt(n,t,e))}let i=[];try{n()}catch(e){i.push(e)}finally{try{await r()}catch(e){i.push(e)}}It(i,e)},{onWarn:Ft})}function Rt(e,t,n){S(`${t}.ok.lock`,()=>{let t=performance.now()+Nt,r=new Int32Array(new SharedArrayBuffer(4)),i;for(;;)try{i=Mt.default.lockSync(O(e),{realpath:!1,lockfilePath:`${e}.lock`});break}catch(n){Atomics.wait(r,0,0,Pt(n,t,e))}let a=[];try{n()}catch(e){a.push(e)}finally{try{i()}catch(e){a.push(e)}}It(a,e)},{onWarn:Ft})}const zt=[`settings.json`,`prompts`,`themes`,`SYSTEM.md`,`APPEND_SYSTEM.md`];var Bt=class extends Error{name=`PiResourceInspectionError`};function X(e){let t;try{t=N(e)}catch(e){if(e.code===`ENOENT`)return!1;throw e}let n;try{n=L(e)}catch(e){throw t.isSymbolicLink()&&e.code===`ENOENT`?new Bt(he(`missing-symlink-target`),{cause:e}):e}return Ae(e,j.R_OK|(n.isDirectory()?j.X_OK:0)),!0}function Vt(e){return e===`open-knowledge`||e.startsWith(`open-knowledge-`)}function Ht(e,t,n){let r=e;try{let i=I(e),a;r=t;try{a=I(t)}catch(e){if(e.code!==`ENOENT`)throw e;a=A(t)}let o=k(a,`.agents`,`skills`),s=[];for(let e of zt)r=k(i,`.pi`,e),X(r)&&s.push(r);if(r=k(i,`.pi`,`extensions`),X(r))for(let t of F(r).sort()){let i=k(r,t);A(n)!==k(A(e),`.pi`,`extensions`,t)&&s.push(i)}for(let e of[k(i,`.pi`,`skills`),k(i,`.agents`,`skills`)])if(e!==o&&(r=e,X(e)))for(let t of F(e).sort())Vt(t)||s.push(k(e,t));let c=O(i);for(;c!==i;){r=k(c,`.agents`,`skills`),r!==o&&X(r)&&s.push(r);let e=O(c);if(e===c)break;c=e}return s.length===0?{kind:`none`}:{kind:`shared`,paths:s.sort()}}catch(e){return{kind:`unreadable`,error:`Could not inspect Pi project resources at ${U(r)}: ${e instanceof Bt?e.message:he(w(e))}`}}}function Ut(e,t,n){let r=A(e),i=ue({home:t,env:n??(t===void 0?process.env:{})});return{cwd:r,bridgePath:E.pi.projectConfigPath(r),trustPath:k(i,`trust.json`)}}function Z(e){try{let t=I(e);return L(t).isDirectory()?(Ae(t,j.X_OK),{kind:`ready`,project:{path:e,canonical:t}}):{kind:`refused`,error:`Pi project path ${U(e)} is not a directory; restore the intended project directory, then retry`}}catch(t){return{kind:`refused`,error:`Pi project directory ${U(e)} could not be resolved or accessed: ${U(t instanceof Error?t.message:String(t))}; restore the directory or symlink and check its permissions, then retry`}}}function Wt(e){let t=Z(e.path);if(t.kind===`refused`)return t.error;if(t.project.canonical!==e.canonical)return`Pi project path ${U(e.path)} changed while waiting for its trust lock; restore the intended project location, then retry`}function Gt(e,t,n){let r=ye(E.pi,e,n,t);if(r.kind===`absent`)return{state:`absent`,text:null};if(r.kind!==`present`)return{state:`unreadable`,text:null};let i=r.entry,a=Array.isArray(i.args)&&typeof i.args[0]==`string`?i.args[0]:null;return be(i)?{state:`own-current`,text:a}:ce(i)?{state:`own-stale`,text:a}:{state:`foreign`,text:a}}function Kt(e,t){let n;try{n=P(e.path,`utf-8`)}catch(t){let n=t.code;return e.kind===`missing`&&n===`ENOENT`?{state:`untrusted`,entries:{},trailingNewline:!1}:{state:`unreadable`,reason:w(t)}}if(n.trim()===``)return{state:`untrusted`,entries:{},trailingNewline:!1};let r;try{r=JSON.parse(n)}catch{return{state:`unreadable`,reason:`invalid-json`}}return Ee(r)?{state:r[t]===!0?`trusted`:`untrusted`,entries:r,trailingNewline:n.endsWith(`
4
- `)}:{state:`unreadable`,reason:`invalid-json`}}function qt(e){switch(e){case`invalid-json`:return`the file is not a valid JSON object; repair its JSON, then retry`;case`path-changed`:return`the path changed while waiting for its lock; retry to check its current state`;case`unavailable-root`:return`the filesystem root is unavailable; reconnect the drive or network share, then retry`;default:return he(e)}}function Q(e,t){return{kind:`refused`,error:`trust store ${U(e)}: ${qt(t)}`}}function Jt(e){let t=De(e);try{switch(t.kind){case`declined`:return Q(e,t.reason);case`ready`:return{kind:`ready`,path:I(t.path)};case`not-present`:break;default:throw Error(`unhandled trust file resolution: ${t}`)}let n=O(e),r=[D(e)],i=N(n,{throwIfNoEntry:!1});for(;!i;){let t=O(n);if(t===n)return Q(e,`unavailable-root`);r.unshift(D(n)),n=t,i=N(n,{throwIfNoEntry:!1})}try{return{kind:`missing`,path:k(I(n),...r)}}catch(t){return Q(e,i.isSymbolicLink()&&t.code===`ENOENT`?`missing-symlink-target`:w(t))}}catch(t){return Q(e,w(t))}}function Yt(e,t){let n=Jt(e);return n.kind===`refused`?n:n.path!==t.path||t.kind===`ready`&&n.kind===`missing`?Q(e,`path-changed`):n}function Xt(e,t,n){let r=Ut(e,t,n),i=Z(r.cwd);if(i.kind===`refused`)return{...r,project:`unavailable`,error:i.error};let a=Gt(r.cwd,r.bridgePath,t).state,o=Jt(r.trustPath),s=o.kind===`refused`?`unreadable`:o.kind===`missing`?`untrusted`:Kt(o,i.project.canonical).state;return{...r,project:`ready`,canonicalCwd:i.project.canonical,bridge:a,trust:s,bridgeLoadable:(a===`own-current`||a===`own-stale`)&&s===`trusted`,otherExtensions:Zt(r.bridgePath).displayNames}}function Zt(e){let t=O(e),n=D(e);try{return{displayNames:F(t).filter(e=>e!==n&&e.endsWith(`.ts`)).sort().map(e=>U(JSON.stringify(e)))}}catch{return{displayNames:[]}}}async function Qt(e,t={mode:`published`},n,r,i){let a=Ut(e,n,r),o=Z(a.cwd);if(o.kind===`refused`)return{...a,ok:!1,bridge:`refused-project-path`,trust:`skipped`,error:o.error};if(i!==void 0&&o.project.canonical!==i)return{...a,ok:!1,bridge:`refused-project-path`,trust:`skipped`,error:`The approved Pi project directory ${U(i)} no longer matches the current directory ${U(o.project.canonical)}. Reopen the intended project and approve the Pi integration again; no bridge or trust settings were changed.`};let s=Gt(a.cwd,a.bridgePath,n);if(s.state===`foreign`)return{...a,ok:!1,bridge:`refused-foreign`,trust:`skipped`};if(s.state===`unreadable`)return{...a,ok:!1,bridge:`refused-unreadable`,trust:`skipped`};let c;if(s.state===`absent`)c=`written`;else{let e;try{e=Ce(t)}catch{e=void 0}c=e!==void 0&&s.text===e?`unchanged`:`refreshed`}if(c!==`unchanged`){let e=Te(E.pi,a.cwd,t,n,a.bridgePath);if(e.action!==`written`&&e.action!==`overwritten`)return{...a,ok:!1,bridge:`failed`,trust:`skipped`,error:e.error===void 0?`bridge write ${e.action}`:U(e.error)}}let l=await $t(a.trustPath,o.project,n??Fe());return{...a,ok:l.action===`already-trusted`||l.action===`added`,bridge:c,trust:l.action,...l.error===void 0?{}:{error:l.error}}}async function $t(e,t,n){let r=t.canonical,i=Jt(e);if(i.kind===`refused`)return{action:`refused-unreadable`,error:i.error};try{je(O(i.path),{recursive:!0})}catch(e){return{action:`failed`,error:U(e instanceof Error?e.message:String(e))}}let a={action:`added`};try{await Lt(e,i.path,()=>{let o=Wt(t);if(o){a.action=`refused-unreadable`,a.error=o;return}let s=Yt(e,i);if(s.kind===`refused`){a.action=`refused-unreadable`,a.error=s.error;return}let c=Kt(s,r);if(c.state===`trusted`){a.action=`already-trusted`;return}if(c.state===`unreadable`){a.action=`refused-unreadable`,a.error=Q(e,c.reason).error;return}let l=$(n,()=>{let t=J(n,r).find(e=>e.record.canonicalTrustPath===s.path);return t&&Y(n,t),vt(n,r,e,s.path,Object.hasOwn(c.entries,r)?{present:!0,value:c.entries[r]}:{present:!1})}),u={...c.entries,[r]:!0},d=JSON.stringify(u,null,2)+(c.trailingNewline?`
5
- `:``),f=T(s.path);y(s.path,d,f===void 0?void 0:{mode:f}),$(n,()=>yt(n,l)),a.action=`added`})}catch(e){return{action:`failed`,error:U(e instanceof Error?e.message:String(e))}}return a}function en(e){let t=[],n=e;try{for(;;){if(N(n,{throwIfNoEntry:!1})){if(t.length===0)return;let e=I(n);return L(e).isDirectory()?(Ae(e,j.X_OK),k(e,...t)):void 0}let e=O(n);if(e===n)return;t.unshift(D(n)),n=e}}catch{return}}function tn(e){let t={"not-present":0,removed:1,"kept-unowned":2,"kept-shared":3,"kept-unverified":4,"refused-unreadable":5,failed:6},n=e.reduce((e,n)=>t[n.action]>t[e.action]?n:e,{action:`not-present`}),r=e.flatMap(e=>e.error??[]),i=e.flatMap(e=>e.detail??[]);return r.length>0?{action:n.error===void 0?`failed`:n.action,error:[...r,...i].join(`
6
- `)}:n.detail===void 0?n:{...n,detail:i.join(`
7
- `)}}function nn(e,t,n,r={}){let i=Ut(e,t,n),a=t??Fe(),o=Z(i.cwd),s=o.kind===`refused`&&r.recordedOnly?en(i.cwd):void 0,c=o.kind===`ready`?o.project.canonical:s,l;try{l=$(a,()=>{let e=J(a,i.cwd);return c===void 0||c===i.cwd?e:[...J(a,c),...e]})}catch(e){return{action:`failed`,error:U(e instanceof Error?e.message:String(e))}}if(l.length===0&&r.recordedOnly)return o.kind===`ready`||s!==void 0?{action:`not-present`}:{action:`kept-unverified`,error:`${o.error}. OpenKnowledge could not verify whether this path refers to a project with recorded Pi trust; cleanup was left pending. Retry once the project path can be resolved to check again.`};if(o.kind===`refused`){if(l.length===0)return{action:`kept-unverified`,error:o.error};let e=l.map(({path:e,record:t})=>`key ${U(JSON.stringify(t.cwd))}; configured store ${U(JSON.stringify(t.configuredTrustPath))}; recorded destination ${U(JSON.stringify(t.canonicalTrustPath))}; ownership record ${U(JSON.stringify(e))} (${t.state})`);return{action:`kept-unverified`,error:[`${o.error}. OpenKnowledge kept these Pi trust ownership records; current trust decisions were not checked:`,...e,`To review manually, close Pi, verify the intended store against its recorded destination, and inspect only the exact key. A pending record does not prove setup completed or ownership of a current grant. If you choose to undo a current true decision, restore the recorded previous value, or remove that key only when no previous entry was recorded. Preserve other current decisions; parent-folder and global trust settings still apply.`].join(`
8
- `)}}let u=Ht(o.project.canonical,a,E.pi.projectConfigPath(o.project.canonical));if(u.kind===`unreadable`)return{action:`kept-unverified`,error:u.error};let d=u.kind===`shared`?u.paths:[],f=[],p=new Map,m=(e,t)=>{let n=p.get(e);if(!n){let t=Jt(e);if(t.kind===`refused`){f.push({action:`refused-unreadable`,error:t.error});return}n={trustPath:e,resolved:t,keys:new Map},p.set(e,n)}if(t){if(n.resolved.path!==t.record.canonicalTrustPath){f.push({action:`refused-unreadable`,error:`Pi trust store ${U(e)} no longer points to its recorded destination ${U(t.record.canonicalTrustPath)}; restore the intended file location or symlink, then retry`});return}n.keys.set(t.record.cwd,{cwd:t.record.cwd,mode:`recorded`,receipt:t})}};for(let e of l)m(e.record.configuredTrustPath,e);m(i.trustPath);for(let e of p.values()){for(let t of[o.project.canonical,i.cwd])e.keys.has(t)||e.keys.set(t,{cwd:t,mode:`inspect`,receipt:l.find(n=>n.record.cwd===t&&n.record.canonicalTrustPath===e.resolved.path)});f.push(rn(e,a,d,o.project))}return tn(f)}function $(e,t){try{return t()}catch(t){throw t instanceof G?t:Error(`Could not access OpenKnowledge's Pi trust ownership records at ${U(k(v(e),`pi-trust`))}: ${U(t instanceof Error?t.message:String(t))}. Check the records and their permissions, then retry.`,{cause:t})}}function rn(e,t,n,r){let{trustPath:i,resolved:a}=e,o=[...e.keys.values()];if(!o.some(e=>e.mode===`recorded`)&&a.kind===`missing`)return{action:`not-present`};if(a.kind===`missing`)try{N(O(a.path))}catch(e){return{action:`failed`,error:`The recorded Pi trust directory ${U(O(a.path))} is unavailable: ${U(e instanceof Error?e.message:String(e))}. Restore access to its parent directory or mounted drive, then retry; the ownership record was kept.`}}let s=[],c={result:{action:`not-present`}};try{Rt(i,a.path,()=>{let e=Wt(r);if(e){c.result={action:`kept-unverified`,error:e};return}let l=Yt(i,a);if(l.kind===`refused`){c.result={action:`refused-unreadable`,error:l.error};return}let u=Kt(l,r.canonical);if(u.state===`unreadable`){c.result={action:`refused-unreadable`,error:Q(i,u.reason).error};return}let d=o.map(e=>({cwd:e.cwd,mode:e.mode,expectedConfiguredPath:e.receipt?.record.configuredTrustPath,receipt:$(t,()=>J(t,e.cwd).find(e=>e.record.canonicalTrustPath===l.path))}));if(d.some(e=>e.receipt&&e.receipt.record.configuredTrustPath!==e.expectedConfiguredPath)){c.result={action:`failed`,error:`The Pi trust ownership record changed during cleanup; retry to read its current location.`};return}for(let e of d){try{an(e,t,i,l.path,u,n,r,c)}catch(t){let n=U(t instanceof Error?t.message:String(t)),r=t instanceof G?``:`; retry to check its current state.`;s.push({action:`failed`,error:`Pi trust entry ${U(JSON.stringify(e.cwd))} in ${U(i)} could not be reconciled: ${n}${r}`})}s.push(c.result),c.result={action:`not-present`}}})}catch(e){s.push({action:`failed`,error:U(e instanceof Error?e.message:String(e))})}return tn([...s,c.result])}function an(e,t,n,r,i,a,o,s){let{cwd:c,receipt:l}=e;if(i.entries[c]!==!0){l&&e.mode===`recorded`&&$(t,()=>Y(t,l)),s.result={action:`not-present`};return}let u=`To remove this grant manually, close Pi and remove only the ${U(JSON.stringify(c))} entry from ${U(n)}; parent-folder and global trust settings still apply.`;if(a.length>0&&c===o.canonical){let n=`kept Pi's folder trust because other resources still need it: ${a.slice(0,3).map(e=>U(JSON.stringify(e))).join(`, `)}${a.length>3?` (+${a.length-3} more)`:``}. ${u} Removing this grant may stop Pi from loading those resources, including any not listed here.`;s.result={action:`kept-shared`,detail:n},l&&e.mode===`recorded`&&$(t,()=>Y(t,l)),s.result={action:`kept-shared`,detail:`${n} ${l?e.mode===`recorded`?`OpenKnowledge has relinquished this grant and will not revoke it on later cleanup runs.`:`OpenKnowledge kept the existing ownership record; cleanup of its recorded location remains incomplete.`:`OpenKnowledge has no ownership record for this grant and will not revoke it on later cleanup runs.`}`};return}if(e.mode===`inspect`||!l||l.record.state===`pending`){let e=l?l.record.state===`pending`?`its ownership record is pending after an interrupted setup; completion cannot be verified. Re-running setup or cleanup does not reconcile this record while the folder remains trusted.`:`OpenKnowledge must reconcile its recorded location at ${U(l.record.configuredTrustPath)} before removing it.`:`no OpenKnowledge ownership record exists; this includes every grant made before ownership recording was introduced.`;s.result={action:`kept-unowned`,detail:`${c===o.canonical?`kept Pi's folder trust because ${e}`:`kept a Pi trust entry under a non-canonical project path because ${e} Pi uses the real project directory instead of this key.`} ${u}`};return}let d={...i.entries};l.record.previous.present?d[c]=l.record.previous.value:delete d[c];let f=JSON.stringify(d,null,2)+(i.trailingNewline?`
9
- `:``),p=T(r);y(r,f,p===void 0?void 0:{mode:p}),i.entries=d,$(t,()=>Y(t,l)),s.result={action:`removed`}}function on(e){return be(e)||me(e)||ce(e)}const sn=10485760;function cn(e,t,n,r=!1){let i=nn(e,t,n,{recordedOnly:r});switch(i.action){case`removed`:case`not-present`:return{trust:i.action};case`kept-shared`:case`kept-unowned`:return{trust:i.action,trustDetail:i.detail};case`failed`:case`refused-unreadable`:case`kept-unverified`:{let e=r?`Trust cleanup remains incomplete`:`The bridge file was left untouched`;throw Error(`Pi trust cleanup failed (${i.action}):\n${i.error}\n${e} so cleanup can be retried.`)}default:throw Error(`unhandled Pi trust cleanup result: ${i}`)}}function ln(e,t,n,r){if(e.id!==`pi`)return{kind:`not-present`};let i=cn(t,n,r,!0);return i.trust===`not-present`?{kind:`not-present`}:{kind:`removed`,...i}}function un(e,t,n,r,i){let a;try{a=r??e.configPath(t,n)}catch{return{kind:`not-present`}}let o=De(a);if(o.kind===`not-present`)return ln(e,t,n,i);if(o.kind===`declined`)return o;let s=ye(e,t,n,o.path);if(s.kind===`absent`||s.kind===`no-entry`)return ln(e,t,n,i);if(s.kind===`decline`)return{kind:`declined`,reason:s.reason};if(!on(s.entry))return{kind:`left-foreign`};let c=e.serverName(t);if(e.format===`file`){let e=cn(t,n,i);try{Me(a,{force:!0})}catch(t){throw e.trustDetail?Error(`${t instanceof Error?t.message:String(t)}\n${e.trustDetail}`,{cause:t}):t}return{kind:`removed`,...e}}return e.format===`toml`?pn(o.path,c):e.format===`yaml`?fn(o.path,e.topLevelKey,c):dn(o.path,e.topLevelKey,e.serverMapSubKey,c)}function dn(e,t,n,r){let i;try{i=P(e,`utf-8`)}catch(e){return{kind:`declined`,reason:w(e)}}if(Buffer.byteLength(i,`utf-8`)>sn)return{kind:`declined`,reason:`oversize`};let{text:a,changed:o}=C(i,Se(t,n,r));return o?(y(e,a,{mode:T(e)}),{kind:`removed`}):{kind:`not-present`}}function fn(e,t,n){let r;try{r=P(e,`utf-8`)}catch(e){return{kind:`declined`,reason:w(e)}}if(Buffer.byteLength(r,`utf-8`)>sn)return{kind:`declined`,reason:`oversize`};let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=(0,ze.parseDocument)(a);if(o.errors.length>0)return{kind:`declined`,reason:`unparseable`};let s=[t,n];if(!o.hasIn(s))return{kind:`not-present`};o.deleteIn(s);let c=o.toString(),l=ge(a);a.trim()===``||a.endsWith(`
10
- `)?c.endsWith(`
11
- `)||(c=`${c}\n`):c=c.replace(/\n+$/,``),l&&(c=c.replace(/\r\n/g,`
12
- `).replace(/\n/g,`\r
13
- `));let u=`${i?``:``}${c}`;return u!==r&&y(e,u,{mode:T(e)}),{kind:`removed`}}function pn(e,t){let n=fe();if(n.backend===`fallback`)return{kind:`declined`,reason:`no-native-writer`};let r;try{r=P(e,`utf-8`)}catch(e){return{kind:`declined`,reason:w(e)}}let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=ge(a),s=a.trim()===``||a.endsWith(`
14
- `),c;try{c=n.removeEntry(a,t)}catch{return{kind:`declined`,reason:`unparseable`}}if(!c.existed)return{kind:`not-present`};let l=c.text;s?l.endsWith(`
15
- `)||(l=`${l}\n`):l=l.replace(/\n+$/,``),o&&(l=l.replace(/\r\n/g,`
16
- `).replace(/\n/g,`\r
17
- `));let u=`${i?``:``}${l}`;return u!==r&&y(e,u,{mode:T(e)}),{kind:`removed`}}function mn(e,t){let n=s[e];return n===null?null:k(t,...n.split(`/`),x.discovery,`SKILL.md`)}function hn(e,t){let n=mn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};if(!g(t).some(t=>t.editorId===e))return{editorId:e,label:e,action:`skipped-unsupported`,path:n};try{let r=ee(`discovery`,{checkDesktop:!0});return oe(O(n),t),{editorId:e,label:e,action:se(r,n),path:n}}catch(t){return{editorId:e,label:e,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function gn(e){return M(k(e,...`.agents/skills`.split(`/`),x.discovery))?!0:a.some(t=>{let n=mn(t,e);return n!==null&&M(O(n))})}function _n(e,t){let n=mn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};let r=O(n);try{return M(n)?(oe(r,t),Me(r,{recursive:!0,force:!0}),{editorId:e,label:e,action:`removed`,path:n}):{editorId:e,label:e,action:`not-present`,path:n}}catch(t){return{editorId:e,label:e,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function vn(e){return e===`opencode`?le:ve}function yn(e,t,n){let r=E[e],i=vn(e),a=[],o=r.projectConfigPath?.(t);o!==void 0&&a.push({scope:`project`,configPath:o});try{a.push({scope:`user`,configPath:r.configPath(t,n)})}catch{}for(let o of a){let a=pe(r,t,n,o.configPath);if(a!==null&&i(a))return{editorId:e,scope:o.scope,configPath:o.configPath}}return null}function bn(e,t,n=[]){let r=M(k(e,x[t]))?`satisfied`:`absent`;return{...r===`satisfied`?{state:r,strictness:[`reclaim-permissive`]}:{state:r},...n.length===0?{}:{sharedWith:n}}}function xn(e,t){let n=ae.flatMap(t=>{let n=e[t];return n===null?[]:[{editor:t,root:n}]}),r=o.filter(e=>e.scope===t).map(e=>({editor:e.editorId,root:i}));return[...n,...r]}function Sn(e,t,n,r){let i=re(e,xn(t,r)),a=i.find(e=>e.host===n);if(a===void 0||a.state===`absent`)return[];let o=a.real;return i.filter(e=>e.host!==n&&e.state!==`absent`&&e.real===o).map(e=>e.host)}function Cn(e,t){let n=(t??Fe()).replace(/[\\/]+$/,``);if(!n.includes(`\\`))return e.startsWith(`${n}/`)?`~/${e.slice(n.length+1)}`:e;let r=e=>e.replace(/\\/g,`/`),i=r(n),a=r(e);return a.startsWith(`${i}/`)?`~/${a.slice(i.length+1)}`:e}function wn(e,t){let n=E[e];return we(n,``,t)&&!de(n,``,t)}function Tn(e,t,n,r,i){let a=E[e],o;if(i===void 0)try{o=a.configPath(n,r)}catch{return{state:`structural-na`}}else o=i;let s=i===void 0?Cn(o,r):void 0,c=ye(a,n,r,i);switch(c.kind){case`absent`:case`no-entry`:return i===void 0&&wn(e,r)?{state:`structural-na`}:{state:`absent`,path:s};case`decline`:return{state:`unprobed`};case`present`:{let{entry:r}=c,i=[];be(r)&&i.push(`reclaim-permissive`),me(r)&&i.push(`pre-approval-exact`),vn(e)(r)&&i.push(`injection-functional`);let o=ie(a,n);return i.length>0&&(o!==null&&xe(r,o)||t.includes(`pre-approval-exact`)&&i.includes(`reclaim-permissive`)&&!i.includes(`pre-approval-exact`))?{state:`drifted`,strictness:i,path:s}:i.length>0?{state:`satisfied`,strictness:i,path:s}:_e(a)?{state:`foreign-replaceable`,path:s}:{state:`foreign`,path:s}}}}function En(e){let{cwd:t,home:n}=e;return e=>{if(e.pathId===null)return null;let a=c(e.pathId);if(a===null)return null;if(a.kind===`central-skill-store`)return n===void 0?null:bn(k(n,i),`discovery`,Sn(n,s,e.agent,`global`));let o=a.editor;switch(a.kind){case`editor-user-skill-root`:{let e=s[o];return e===null||n===void 0?null:g(n).some(e=>e.editorId===o)?bn(k(n,e),`discovery`,Sn(n,s,o,`global`)):{state:`structural-na`}}case`editor-project-skill-root`:{let e=r[o];return e===null?null:bn(k(t,e),`project`,Sn(t,r,o,`project`))}case`editor-user-config`:return Tn(o,e.strictness,t,n);case`editor-project-config`:{let r=E[o].projectConfigPath?.(t);return r===void 0?null:Tn(o,e.strictness,t,n,r)}}}}export{Ue as S,Xe as _,hn as a,Ye as b,Xt as c,ct as d,lt as f,R as g,tt as h,gn as i,nt as l,et as m,yn as n,un as o,ut as p,_n as r,Qt as s,En as t,rt as u,Ke as v,Ve as x,Je as y};
@@ -1,11 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{Ac as t,B as n,H as r,Nc as i,Pc as a,V as o,Yd as s,aa as c,af as l,bl as u,cf as d,ku as f,l as p,oa as m,rf as h,u as ee,xl as g}from"./md-manager-BGnqyqi1-IqwoPmS1.mjs";import{$o as _,Dt as v,Mi as y,Ni as b,Qo as x,Sr as S,Xo as C,Yn as w,_i as T,ar as E,ba as D,es as O,gi as k,hi as A,li as j,lr as M,m as N,ri as P,wo as F,ys as I}from"./dist-BrWQNlOF.mjs";import{t as L}from"./yazl-BBz29IQN.mjs";import{Ct as te,ot as ne,st as re}from"./init-0oLlE1YP.mjs";import{l as ie,x as ae}from"./registry-probes-TTIv_jQo.mjs";import{c as oe}from"./colors-r_owlCuY.mjs";import{t as se}from"./is-object-BGze3w87.mjs";import{n as ce}from"./constants-BrjqlEsS.mjs";import"./loader-1manjX2x.mjs";import"./preview-C5jJBQtN.mjs";import{execSync as le,spawnSync as ue}from"node:child_process";import{basename as R,dirname as z,isAbsolute as de,join as B,relative as fe,resolve as V,sep as H}from"node:path";import{closeSync as pe,cpSync as me,createWriteStream as he,existsSync as U,lstatSync as ge,mkdirSync as W,mkdtempSync as _e,openSync as ve,readFileSync as G,readSync as ye,readdirSync as K,readlinkSync as be,rmSync as q,rmdirSync as xe,statSync as Se,writeFileSync as J}from"node:fs";import{arch as Ce,freemem as we,homedir as Y,hostname as Te,platform as Ee,release as De,tmpdir as Oe,totalmem as ke,type as Ae,uptime as je}from"node:os";import"node:fs/promises";import{createHash as Me}from"node:crypto";function Ne(e,t){let n=t.map(e=>[I(e),e]);for(let t of e){let e=I(t);if(e===null)continue;let r=n.find(([t])=>t===e);if(r!==void 0)return r[1]}}function Pe(e){let{override:t,storedPreference:n,preferenceList:r,supportedLocales:i}=e,a=e.autoDetectableLocales??i;if(t!==void 0){let e=Ne([t],i);if(e!==void 0)return{locale:e,source:`override`}}if(n!==void 0&&n!==`system`&&i.includes(n))return{locale:n,source:`explicit`};let o=Ne(r,a);return o===void 0?{locale:`en`,source:`fallback`}:{locale:o,source:`system`}}function Fe(e,t=Date.now()){let n=Date.parse(e);if(!Number.isFinite(n))return`unknown`;let r=Math.floor(Math.max(0,t-n)/1e3);if(r<60)return`${r}s ago`;let i=Math.floor(r/60);if(i<60)return`${i}m ago`;let a=Math.floor(i/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}const Ie=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`audit`,`deinit`,`auth`]);function Le(e,t,n=M){if(e!==void 0&&!Ie.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let Re=null;function ze(e){Re=e}function Be(){return Re??process.cwd()}const Ve=`Open Knowledge`;function He(e={}){let t=e.platformName??process.platform,n=e.productName??h().productName;return ne(t).join(re({...e,platformName:t}),n)}function Ue(e={}){let t=e.platformName??process.platform,n=e.home??Y(),r=e.env??process.env,i=ne(t),a;return a=t===`win32`?r.LOCALAPPDATA||i.join(n,`AppData`,`Local`):t===`darwin`?i.join(n,`Library`,`Caches`):r.XDG_CACHE_HOME||i.join(n,`.cache`),i.join(a,`${h().packageName.replaceAll(`/`,``)}-updater`)}function We(e){if(typeof e!=`object`||!e)return null;let t=e.recentProjects;if(!Array.isArray(t))return null;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let t=e;typeof t.path==`string`&&typeof t.name==`string`&&n.push({path:t.path,name:t.name})}return n}function Ge(e){let t=B(e,`state.json`);if(!U(t))return[];let n;try{n=JSON.parse(G(t,`utf-8`))}catch{return[]}return We(n)??[]}function Ke(e){let t=B(e,`state.json`);if(!U(t))return!1;try{return We(JSON.parse(G(t,`utf-8`)))!==null}catch{return!1}}const qe=8192;function Je(e,t){if(e.outcome===`not-present`)return`not-present (no DiagnosticReports directory)`;if(e.outcome===`unreadable-directory`)return`unreadable (${e.directoryErrorCode??`unknown`} reading DiagnosticReports)`;let n=[`${e.windowDays}d`,`${e.foreignIgnored} other-process report(s) ignored`,`${e.unparseable} unparseable`];e.droppedOverCap>0&&n.push(`${e.droppedOverCap} older dropped over cap`);let r=e.files.length-t;return r>0&&n.push(`${r} vanished before staging`),e.outcome===`none-in-window`?`none found in window (${n.join(`; `)})`:`${t} collected (${n.join(`; `)})`}function Ye(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const Xe=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Ze(e){return e.replace(Xe,`$1"[REDACTED-DEVICE-ID]"`)}function Qe(e){return Ze(Ye(e))}const $e=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function et(e){if(typeof e!=`string`)return null;let t=$e.exec(e.trim());if(t===null)return null;let[,n,r,i=``,a,o]=t,s=Date.parse(`${n}T${r}${i}${a}:${o}`);return Number.isNaN(s)?null:s}function tt(e){let t=ve(e,`r`);try{let e=Buffer.alloc(qe),n=0,r=!1;for(;n<qe;){let i=ye(t,e,n,qe-n,n);if(i===0){r=!0;break}let a=n;n+=i;let o=e.subarray(0,n).indexOf(10,a);if(o!==-1)return e.subarray(0,o).toString(`utf-8`)}return r?e.subarray(0,n).toString(`utf-8`):null}finally{pe(t)}}function nt(e){try{let t=tt(e);if(t===null)return{kind:`unreadable`};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{kind:`unreadable`};let{name:r,app_name:i,timestamp:a}=n,o=typeof r==`string`?r:typeof i==`string`?i:null;return o===null?{kind:`unreadable`}:{kind:`named`,name:o,timestampMs:et(a)}}catch{return{kind:`unreadable`}}}function rt(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function it(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=K(e,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`?{...n,outcome:`not-present`}:{...n,outcome:`unreadable-directory`,directoryErrorCode:t??`unknown`}}let i=t.getTime()-6048e5,a=[],o=0,s=0;for(let t of r){if(!t.isFile()||!t.name.endsWith(`.ips`))continue;let n=B(e,t.name),r;try{r=Se(n).mtimeMs}catch{continue}if(r<i)continue;let c=nt(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!rt(c.name)){o+=1;continue}a.push({path:n,atMs:l})}a.sort((e,t)=>t.atMs-e.atMs);let c=a.slice(0,25),l={foreignIgnored:o,unparseable:s,droppedOverCap:a.length-c.length,windowDays:7};return c.length===0?{...l,files:[],outcome:`none-in-window`}:{...l,files:c.map(e=>e.path),outcome:`collected`}}function at(){return B(C(),`bug-reports`)}function ot(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=at(),r=`${t}-bugreport`,i=B(n,`${r}.zip`);for(let e=2;U(i);e+=1)i=B(n,`${r}-${e}.zip`);return i}function st(e,t){let{scrubbed:n}=e;return n!==void 0&&n.patterns.length>0?{file:t,lineCount:n.lineCount,patterns:[...n.patterns]}:null}function ct(e,t){let n=B(e,`.ok`,`config.yml`);if(U(n))try{let e=G(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return U(B(e,`.ok`))?Me(`sha256`).update(V(e)).digest(`hex`).slice(0,12):null}function lt(){let e={timestamp:new Date().toISOString(),platform:Ee(),osType:Ae(),osRelease:De(),hostname:`[redacted]`,uptime:je(),freeMem:we(),totalMem:ke(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=le(`sw_vers -productVersion 2>/dev/null`,F({encoding:`utf8`})).trim()}catch{}try{let t=B(__dirname,`..`,`..`,`package.json`);U(t)&&(e.okVersion=JSON.parse(G(t,`utf8`)).version)}catch{}return e}const ut=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function dt(e){let t=R(e);return ut.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function ft(e,t){return gt(e,t).files}const pt=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function mt(e,t=ie){let n=B(e,`${t}.ShipIt`);if(!U(n))return[];let r;try{r=K(n)}catch{return[]}return pt.flatMap(e=>r.map(t=>{if(t===e)return{entry:t,suffix:-1};if(!t.startsWith(`${e}.`))return null;let n=t.slice(e.length+1);return/^\d+$/.test(n)?{entry:t,suffix:Number(n)}:null}).filter(e=>e!==null).sort((e,t)=>e.suffix-t.suffix).slice(0,4).map(e=>B(n,e.entry)))}function ht(e){if(!U(e))return[];try{let t=new Map;for(let n of K(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-p.length):n.slice(0,-5),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return[...t.values()].slice(-25).flat().map(t=>B(e,t))}catch{return[]}}function gt(e,t){if(!U(t))return{files:[],excludedByProjectSlug:0};let n=K(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>B(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(dt),i=[],a=r.filter(t=>{try{return G(t,`utf8`).includes(`"project":"${e}"`)}catch{return i.push(t),!1}});if(a.length===0)return{files:n,excludedByProjectSlug:0};let o=new Set([...a,...i]);return{files:n.filter(e=>!dt(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function _t(e){let n=B(e,`.ok`,`local`);return U(n)?{files:[`server.lock`,`last-spawn-error.log`,i,t].map(e=>B(n,e)).filter(e=>U(e))}:{files:[]}}function vt(e){let t=B(e,`.ok`,`local`,`logs`);return U(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>B(t,e)).filter(e=>U(e))}:{files:[]}}function yt(e){let t=0,n=new Map,r=e.replace(/("(?:docName|doc\.name|documentName)"\s*:\s*")((?:[^"\\]|\\.)*)"/g,(e,r,i)=>{t+=1;let a=n.get(i);return a===void 0&&(a=`doc#${Me(`sha256`).update(i).digest(`hex`).slice(0,12)}`,n.set(i,a)),`${r}${a}"`});for(let[e,i]of[...n].sort(([e],[t])=>t.length-e.length)){if(e.length===0||!r.includes(e))continue;let n=r.split(e);t+=n.length-1,r=n.join(i)}return{text:r,count:t}}function bt(e){let t=e.revealDocNames?e.content:yt(e.content).text;if(e.redact){let{redacted:n,patterns:r,lineCount:i}=m(t);e.zipfile.addBuffer(Buffer.from(n,`utf8`),e.name),e.bundleFiles.push(e.name),r.length>0&&e.redactions.push({file:e.name,lineCount:i,patterns:r})}else e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name)}function X(e){for(let t of e.files)try{let n=G(t,`utf8`);bt({zipfile:e.zipfile,name:`${e.prefix}/${R(t)}`,content:t.endsWith(`.ips`)?Qe(n):n,redact:e.redact,revealDocNames:e.revealDocNames,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n},`bug-report: skipped unreadable file`)}}async function xt(t){let{redact:n,outputPath:r,logger:i}=t,a=t.revealDocNames??!1,o=t.userLogsDir??B(C(),`logs`),s=t.projectDir?ct(t.projectDir,i):null;W(z(r),{recursive:!0}),i?.info({projectSlug:s},`gathering diagnostic data`);let l=lt();l.desktop=t.desktop??null,l.language=t.language??null;let{files:u,excludedByProjectSlug:d}=gt(s,o),{files:f}=t.projectDir?_t(t.projectDir):{files:[]},{files:p}=t.projectDir?vt(t.projectDir):{files:[]},m=t.shipItLogFiles??[],h=t.diagnosticReports?.files??[];i?.info({logFileCount:u.length,logFilesExcludedByProjectSlug:d,lockFileCount:f.length,localSinkFileCount:p.length,shipItLogFileCount:m.length,diagnosticReportCount:h.length},`files collected`);let g=[],_=[],{ZipFile:v}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),y=new v;X({zipfile:y,files:[...u,...m],prefix:`logs`,redact:n,revealDocNames:a,bundleFiles:_,redactions:g,logger:i}),X({zipfile:y,files:f,prefix:`lockdir`,redact:n,revealDocNames:a,bundleFiles:_,redactions:g,logger:i}),X({zipfile:y,files:p,prefix:`local-logs`,redact:n,revealDocNames:a,bundleFiles:_,redactions:g,logger:i}),X({zipfile:y,files:t.bugReportLedgerFiles??[],prefix:ee,redact:n,revealDocNames:a,bundleFiles:_,redactions:g,logger:i}),X({zipfile:y,files:h,prefix:`diagnostic-reports`,redact:n,revealDocNames:a,bundleFiles:_,redactions:g,logger:i});for(let e of t.extraFiles??[])try{let t=G(e.sourcePath),n=`extra/${e.zipName??R(e.sourcePath)}`;y.addBuffer(t,n),_.push(n);let r=st(e,n);r!==null&&g.push(r)}catch(t){i?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&bt({zipfile:y,name:`note.txt`,content:t.note,redact:n,revealDocNames:a,bundleFiles:_,redactions:g});let b=new Set(h.map(e=>`diagnostic-reports/${R(e)}`)),x=_.filter(e=>b.has(e)),S=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Je(t.diagnosticReports,x.length);y.addBuffer(Buffer.from(`${S}\n`,`utf8`),`state/diagnostic-reports-status.txt`),_.push(`state/diagnostic-reports-status.txt`);let w=JSON.stringify(l,null,2);y.addBuffer(Buffer.from(w,`utf8`),`sysinfo.json`),_.push(`sysinfo.json`);let T={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:s,files:_,redactions:g,sysinfo:l};y.addBuffer(Buffer.from(JSON.stringify(T,null,2),`utf8`),`MANIFEST.json`);let E=g.reduce((e,t)=>e+t.lineCount,0),D=new Set(m.map(e=>`logs/${R(e)}`)),O=_.filter(e=>D.has(e)),k=new Set((t.bugReportLedgerFiles??[]).map(e=>`${ee}/${R(e)}`)),A=_.filter(e=>k.has(e)),j=s?_.filter(e=>e.startsWith(`logs/`)&&!dt(e)&&!D.has(e)):[],M=x.length>0?[`Crash reports under diagnostic-reports/ are rewritten on the way in,`,`independently of this setting: escaped path separators are normalised`,`so the scrub above can read them, and the identifiers that link this`,`machine's bundles to each other are replaced. Nothing else is changed;`,`they are not byte-identical to the files macOS wrote.`]:[],N=M.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...M]:[`Redaction was disabled for this bundle; file contents are unmodified.`],P=[`# Bug Report Bundle`,``,`Generated: ${T.generatedAt}`,`Project: ${s??`(unscoped)`}`,`Discipline version: ${T.disciplineVersion}`,``,`## Contents`,``,..._.map(e=>`- ${e}`),``,`## Privacy`,``,...j.length>0?[`Scope: some collected logs are user-wide rather than project-scoped.`,`These are written once per machine per day and can contain activity`,`from other projects open on this machine, including captured console`,`output:`,...j.map(e=>`- ${e}`),``]:[],...O.length>0?[`Installer logs: written by the macOS update helper rather than by`,`OpenKnowledge itself, and machine-wide rather than scoped to any one`,`project. They record the install and update history of this app on`,`this machine. Only this app is collected, never other applications`,`that use the same update mechanism:`,...O.map(e=>`- ${e}`),``]:[],...x.length>0?[`Crash reports: written by macOS itself rather than by OpenKnowledge,`,`and machine-wide rather than scoped to any one project. They record`,`why the operating system ended a process of this app — the signal or`,`exception, the code-signing verdict, and whatever text the process`,`left behind as it died. They also carry machine details the OS puts`,`in every report: the account uid, the Mac model, and the name of the`,`process that launched this app, which on a managed machine can be`,`internal tooling. The identifiers that would link this machine's`,`bundles to each other are replaced before bundling. Only this`,`app's own reports are collected, never another application's, though`,`a report of ours still names the processes it ran alongside:`,...x.map(e=>`- ${e}`),``]:[],...A.length>0?[`Send history: a small record for each bug report previously generated`,`on this machine — when it was generated, whether sending it`,`succeeded, and why it failed if it did. This is what makes a failed`,`send diagnosable at all. It is machine-wide rather than scoped to`,`this project, so it names the other projects reports were filed`,`from. It carries no document content:`,...A.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${c.join(`, `)}`,E>0?`${E} line(s) were scrubbed across ${g.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...M,``,`This bundle is safe to attach to a GitHub issue.`]:N].join(`
2
- `);y.addBuffer(Buffer.from(P,`utf8`),`README.md`),y.end();let F=he(r);return y.outputStream.pipe(F),await new Promise((e,t)=>{F.on(`close`,e),F.on(`error`,t)}),i?.info({bundlePath:r,fileCount:_.length,redactionCount:E},`bundle written`),{zipPath:r,summary:{projectSlug:s,files:_,redactions:g,redactedLineCount:E,generatedAt:T.generatedAt}}}var St=f(),Ct=e(L(),1),Z=e(oe(),1);function wt(e){let t=O(`user`,e,e);return x({absPath:t,sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function Tt({home:e=Y(),env:t=process.env}={}){let n=wt(e),{override:r,preferenceList:i}=_(t),{locale:a,source:o}=Pe({override:r,storedPreference:n,supportedLocales:g,preferenceList:i,autoDetectableLocales:u});return{preference:n,locale:a,source:o,systemLanguages:i}}function Et(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function Dt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ot(e,t){if(typeof e==`string`)return Et(e,t.contentDir);if(Array.isArray(e))return e.map(e=>Ot(e,t));if(!Dt(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=Ot(i,t);return n}function kt(e,t){let n=G(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
3
- `),i=n.split(`
4
- `),a=[];for(let e=0;e<i.length;e++){let n=i[e]??``;if(e!==i.length-1||n!==``){if(n.length===0){a.push(``);continue}try{let e=Ot(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}let o=r?`${a.join(`
5
- `)}\n`:a.join(`
6
- `);J(e,o)}function At(e,t){let n=G(e,`utf-8`);if(n.trim().length!==0)try{let r=Ot(JSON.parse(n),t),i=n.endsWith(`
7
- `)?`
8
- `:``;J(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=Et(n,t.contentDir);r!==n&&J(e,r)}}function jt(e,t){let n=G(e,`utf-8`),r=Et(n,t.contentDir);r!==n&&J(e,r)}function Mt(e){try{return K(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>B(e,t.name))}catch{return[]}}const Nt=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function Pt(e){return/\.log\.\d+$/.test(e)}function Ft(e){return e.endsWith(`.jsonl`)||e.endsWith(`.log`)||Pt(e)}const It=[`telemetry`,`logs`,`process`,`diagnostic-reports`];function Lt(e){let t={contentDir:e.contentDir};for(let n of It)for(let r of Mt(B(e.stagingDir,n)))Ft(r)?kt(r,t):r.endsWith(`.json`)?At(r,t):jt(r,t);for(let n of Mt(B(e.stagingDir,`state`))){let e=R(n);n.endsWith(`.jsonl`)?kt(n,t):Nt.has(e)?At(n,t):jt(n,t)}}const Rt=[`.ok`,`local`,`telemetry`],zt=[`.ok`,`local`,`logs`],Bt=[`.ok`,`local`,`loss-capture`],Vt=`spans-current.jsonl`,Ht=`spans-prev.jsonl`,Ut=`server-current.jsonl`,Wt=`server-prev.jsonl`,Gt=`loss-current.jsonl`,Kt=`loss-prev.jsonl`;function qt(e){return B(e,...Rt,Vt)}function Jt(e){return B(e,...Rt,Ht)}function Yt(e){return B(e,...zt,Ut)}function Xt(e){return B(e,...zt,Wt)}function Zt(e){return B(e,...Bt,Gt)}function Qt(e){return B(e,...Bt,Kt)}const $t=1e3;async function en(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout($t)});return t.ok?await t.text():null}catch{return null}}async function tn(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-effects`,{signal:AbortSignal.timeout($t)});return t.ok?await t.text():null}catch{return null}}async function nn(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout($t)});return t.ok?await t.text():null}catch{return null}}function rn(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=t.decisions;return Array.isArray(n)?n.length===0?``:`${n.map(e=>JSON.stringify(e)).join(`
9
- `)}\n`:null}catch{return null}}function an(e){let t=B(e,`.git`,`ok`);if(!U(t))return null;let n=ue(`git`,[`-C`,t,`log`,`--oneline`,`-50`],F({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function on(e){let t=B(e,`.git`,`ok`);if(!U(t))return null;let n=ue(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],F({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function sn(){let e=process.env.OK_DESKTOP_VERSION,t=process.env.OK_DESKTOP_PACKAGED,n=process.env.OK_DESKTOP_CHANNEL;return e===void 0||t===void 0||n===void 0?null:{electronVersion:e,packaged:t===`1`||t.toLowerCase()===`true`,channel:n}}function cn(){return{nodeVersion:process.version,platform:Ee(),arch:Ce()}}function ln(){return process.env.OTEL_SDK_DISABLED===`false`}function un(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function dn(e){if(!U(e))return{};let t;try{t=(0,St.parse)(G(e,`utf-8`))}catch(t){return console.warn(`[ok diagnose bundle] failed to parse ${e} for manifest config; manifest will report schema defaults. Reason: ${t instanceof Error?t.message:String(t)}`),{}}if(!un(t))return{};let n=t.telemetry;if(!un(n))return{};let r=n.localSink;return un(r)?r:{}}function fn(e){return typeof e==`boolean`?e:void 0}function pn(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function mn(e){if(un(e))return pn(e.maxBytes)}function hn(e){let t=dn(O(`project`,e)),n=dn(O(`project-local`,e));return{enabled:fn(n.enabled)??fn(t.enabled)??!0,spansMaxBytes:mn(n.spans)??mn(t.spans)??52428800,logsMaxBytes:mn(n.logs)??mn(t.logs)??26214400}}function gn(e){return Me(`sha256`).update(e).digest(`hex`)}function _n(e){let t=G(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}const vn=[`"doc.name"`,`"docName"`];function yn(e){let t=G(e,`utf-8`),n=0;for(let e of vn){let r=t.indexOf(e);for(;r!==-1;)n++,r=t.indexOf(e,r+e.length)}return n}function Q(e,t){if(!U(e))return!1;try{return W(z(t),{recursive:!0}),e.endsWith(`.ips`)?J(t,Qe(G(e,`utf-8`))):me(e,t),!0}catch{return!1}}function bn(e){let t=[],n=e=>{let r=K(e,{withFileTypes:!0});for(let i of r){let r=B(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const xn=new Set([`.jsonl`]);function Sn(e){let t=e.lastIndexOf(`.`);return t!==-1&&xn.has(e.slice(t))}const Cn=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`,`.yaml`,`.yml`,`.ips`]);function wn(e){if(Pt(e))return!0;let t=e.lastIndexOf(`.`);return t!==-1&&Cn.has(e.slice(t))}function Tn(e){let t=[];for(let n of bn(e)){let r=En(e,n);if(!wn(r))continue;let{redacted:i,patterns:a,lineCount:o}=m(G(n,`utf-8`));a.length!==0&&(J(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function En(e,t){return fe(e,t).split(H).join(`/`)}async function Dn(e){let n=V(e.contentDir),r=V(e.projectDir??e.contentDir),o=e.deps??{},s=o.fetchAgentPresence??en,c=o.fetchAgentEffects??tn,l=o.fetchWatcherRecent??nn,u=o.readShadowHead??an,d=o.readCheckpointRefs??on,f=o.now??(()=>new Date),p=o.okVersion??(()=>ce),m=o.readDesktopEnv??sn,h=o.readLanguage??Tt,g=o.readRuntime??cn,_=o.isOtlpPushEnabled??ln,v=_e(B(Oe(),`ok-bundle-`));try{W(B(v,`telemetry`),{recursive:!0}),W(B(v,`logs`),{recursive:!0}),W(B(v,`state`),{recursive:!0}),Q(qt(r),B(v,`telemetry`,Vt)),Q(Jt(r),B(v,`telemetry`,Ht)),Q(Yt(r),B(v,`logs`,Ut)),Q(Xt(r),B(v,`logs`,Wt));for(let t of e.userLogFiles??[])Q(t,B(v,`logs`,R(t)));for(let t of e.userStateFiles??[])Q(t,B(v,ee,R(t)));let y=0;for(let t of e.diagnosticReports?.files??[])Q(t,B(v,`diagnostic-reports`,R(t)))&&(y+=1);let b=B(r,`.ok`,`local`),x=B(b,`server.lock`),S=`not-running`,C=`no server.lock`,w=null;if(U(x)){Q(x,B(v,`state`,`server.lock`));try{let e=G(x,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?w=t.port:C=`lock present but no port`}catch{C=`lock present but unparseable`}}if(w!==null){let e=await s(w);e===null?C=`agent-presence endpoint at :${w} unreachable`:(J(B(v,`state`,`agent-presence.json`),e),S=`running`,C=``);let t=await c(w);t!==null&&J(B(v,`state`,`agent-effects.json`),t);let n=await l(w);if(n!==null){let e=rn(n);e!==null&&J(B(v,`state`,`watcher-recent.jsonl`),e)}}let T=u(n);T!==null&&J(B(v,`state`,`shadow-head.txt`),T);let E=d(n);E!==null&&J(B(v,`state`,`checkpoint-refs.txt`),E),Q(Zt(r),B(v,`state`,Gt)),Q(Qt(r),B(v,`state`,Kt)),Q(B(b,`last-spawn-error.log`),B(v,`state`,`last-spawn-error.log`)),Q(B(b,a),B(v,`state`,a)),Q(B(b,i),B(v,`state`,i)),Q(B(b,t),B(v,`state`,t));let D=g(),O=m(),k=h(),A={ok:{version:p(),nodeVersion:D.nodeVersion,platform:D.platform,arch:D.arch},host:{desktop:O,language:k}};J(B(v,`state`,`runtime.json`),`${JSON.stringify(A,null,2)}\n`);let j=S===`running`?`running
10
- `:`not-running (${C})\n`;J(B(v,`state`,`server-status.txt`),j);let M=e.diagnosticReports===void 0?`not-collected (no collection attempted)`:Je(e.diagnosticReports,y);if(J(B(v,`state`,`diagnostic-reports-status.txt`),`${M}\n`),e.processDir&&U(e.processDir)){let t=B(v,`process`);W(t,{recursive:!0}),me(e.processDir,t,{recursive:!0})}let N=e.redact===!0;N&&Lt({stagingDir:v,contentDir:n}),e.note&&J(B(v,`note.txt`),e.note);let P=null;e.scrubSecrets===!0&&(P=Tn(v));for(let t of e.extraFiles??[]){let e=t.zipName??R(t.sourcePath);if(!Q(t.sourcePath,B(v,`extra`,e))){o.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);continue}let n=st(t,`extra/${e}`);n!==null&&(P??={redactions:[],redactedLineCount:0},P.redactions.push(n),P.redactedLineCount+=n.lineCount)}let F=hn(r),I=bn(v),L=[],te=0,ne=0;for(let e of I){let t=En(v,e),n=Se(e).size,r=Sn(t)?_n(e):0;L.push({path:t,bytes:n,lines:r}),te+=n,(t.startsWith(`telemetry/`)||t.startsWith(`logs/`))&&(ne+=yn(e))}let re={applied:N};P!==null&&(re.secretScrub=P);let ie={schemaVersion:2,createdAt:f().toISOString(),ok:{version:p(),nodeVersion:D.nodeVersion,platform:D.platform,arch:D.arch},host:{desktop:O,language:k},contentDir:{pathSha256:gn(n),absolutePath:N?`<CONTENT_DIR>`:n},telemetry:{localSink:F,otlpPushEnabled:_()},redaction:re,serverStatus:S,files:L};J(B(v,`manifest.json`),`${JSON.stringify(ie,null,2)}\n`);let ae=I.some(e=>{try{return G(e,`utf-8`).includes(n)}catch{return!1}}),oe={stagedDiagnosticReports:y,totalBytes:te,fileCount:L.length,docNameCount:ne,contentDirVisible:ae,redacted:N},se=!1;return{stagingDir:v,manifest:ie,summary:oe,cleanup:()=>{se||(se=!0,q(v,{recursive:!0,force:!0}))}}}catch(e){throw q(v,{recursive:!0,force:!0}),e}}async function On(e){let{collected:t,outputPath:n}=e,r=z(n);if(!U(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new Ct.ZipFile,a=bn(t.stagingDir);for(let e of a){let n=En(t.stagingDir,e);i.addFile(e,n)}i.end();let o=he(n);return i.outputStream.pipe(o),await new Promise((e,t)=>{o.on(`close`,e),o.on(`error`,t),i.outputStream.on(`error`,t)}),n}function kn(e,t){let n=B(e,`.ok`,`config.yml`);if(U(n))try{let t=(0,St.parse)(G(n,`utf-8`)),r=se(t)?t.content:void 0,i=se(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return V(e,i)}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml; falling back to project root as content dir`)}return V(e)}async function An(e,t,n,r,i){let a=ct(t,e.logger),o=await Dn({contentDir:kn(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,userLogFiles:[...ft(a,e.userLogsDir??B(C(),`logs`)),...mt(e.cachesDir??B(Y(),`Library`,`Caches`))],userStateFiles:ht(e.bugReportsDir??at()),diagnosticReports:i,deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{W(z(e.outputPath),{recursive:!0}),await On({collected:o,outputPath:e.outputPath});let t=o.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:a,files:o.manifest.files.map(e=>e.path),redactions:t?.redactions??[],redactedLineCount:t?.redactedLineCount??0,generatedAt:o.manifest.createdAt}}}finally{o.cleanup()}}async function jn(e){let{projectDir:t}=e,n=e.readDesktopEnv??sn,r=e.readLanguage??Tt,i=()=>it(e.diagnosticReportsDir??B(Y(),`Library`,`Logs`,`DiagnosticReports`),new Date);if(e.level===`full`&&t!==void 0)return An(e,t,n,r,i());let{zipPath:a,summary:o}=await xt({projectDir:t,redact:e.redact,revealDocNames:e.level===`full`,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:mt(e.cachesDir??B(Y(),`Library`,`Caches`)),bugReportLedgerFiles:ht(e.bugReportsDir??at()),diagnosticReports:e.level===`full`?i():void 0,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n(),language:r()});return{zipPath:a,summary:{level:e.level,systemWide:t===void 0,projectSlug:o.projectSlug,files:o.files,redactions:o.redactions,redactedLineCount:o.redactedLineCount,generatedAt:o.generatedAt}}}function $(e,t,n={}){let r=T(e,t),i;try{i=G(r,`utf-8`)}catch(e){return e&&typeof e==`object`&&`code`in e&&e.code===`ENOENT`?{status:`missing`,lockPath:r}:{status:`read-error`,lockPath:r,error:e instanceof Error?e.message:String(e)}}let a;try{a=JSON.parse(i)}catch{return{status:`corrupt`,lockPath:r}}let o=a&&typeof a==`object`?a:{},s=`machineId`in o&&typeof o.machineId==`string`?o.machineId!==(n.machineId??S()):`hostname`in o&&typeof o.hostname==`string`&&o.hostname!==(n.host??Te());if(!a||typeof a!=`object`||!j(a.pid))return{status:`corrupt`,lockPath:r,...s?{foreignHost:!0}:{}};let c=a.pid,l=`machineId`in o&&typeof o.machineId==`string`||`hostname`in o&&typeof o.hostname==`string`;return s?{status:`foreign-host`,lockPath:r,lock:a}:(n.isAlive??P)(c)?l?{status:`alive`,lockPath:r,lock:a}:{status:`unverified-owner`,lockPath:r,pid:c}:{status:`dead-pid`,lockPath:r,lock:a}}function Mn(e){return e.status===`unverified-owner`?`Cannot verify shutdown: the server lock at ${e.lockPath} does not record its owning machine, and its recorded process ${e.pid} is still running on this machine. Check whether process ${e.pid} is an OpenKnowledge server. If it is, stop it and retry. Do not remove the lock file while that process is running.`:`Cannot verify shutdown: the server lock at ${e.lockPath} belongs to another machine. Stop OpenKnowledge on the owning machine. Confirm that no OpenKnowledge server is using this directory on the owning machine or any other machine sharing it. Only then remove the stale lock file at ${e.lockPath} and retry cleanup.`}function Nn(e){return e.replace(/:\d+$/,``)}function Pn(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:Nn(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:Nn(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:Nn(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.\-~%]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}const Fn=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function In(e){return r(d(),e)}function Ln(){return o(d())}function Rn(){let e=d();if(e===`stable`)return Fn;let t=n(e);return RegExp(`^# >>> ${t} >>>\\n[\\s\\S]*?^# <<< ${t} <<<\\n?`,`m`)}const zn={existsSync:e=>U(e),readFileSync:(e,t)=>G(e,t),lstatSync:e=>ge(e),readlinkSync:e=>be(e)};function Bn(e,t=zn){let n=In(e);if(!t.existsSync(n))return null;try{let e=JSON.parse(t.readFileSync(n,`utf8`));return e?.version===1?e:null}catch{return null}}function Vn(e){let t=e.replace(Rn(),``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function Hn(e,t,n=zn){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}const Un=[{hostDir:`.adal`,pruneRoot:`.adal`},{hostDir:`.aider-desk`,pruneRoot:`.aider-desk`},{hostDir:`.astrbot/data`,pruneRoot:`.astrbot`},{hostDir:`.augment`,pruneRoot:`.augment`},{hostDir:`.autohand`,pruneRoot:`.autohand`},{hostDir:`.bob`,pruneRoot:`.bob`},{hostDir:`.codeartsdoer`,pruneRoot:`.codeartsdoer`},{hostDir:`.codebuddy`,pruneRoot:`.codebuddy`},{hostDir:`.codeium/windsurf`,pruneRoot:`.codeium`},{hostDir:`.codemaker`,pruneRoot:`.codemaker`},{hostDir:`.codestudio`,pruneRoot:`.codestudio`},{hostDir:`.commandcode`,pruneRoot:`.commandcode`},{hostDir:`.config/crush`,pruneRoot:`.config/crush`},{hostDir:`.config/devin`,pruneRoot:`.config/devin`},{hostDir:`.config/goose`,pruneRoot:`.config/goose`},{hostDir:`.config/kimchi/harness`,pruneRoot:`.config/kimchi`},{hostDir:`.continue`,pruneRoot:`.continue`},{hostDir:`.factory`,pruneRoot:`.factory`},{hostDir:`.forge`,pruneRoot:`.forge`},{hostDir:`.grok`,pruneRoot:`.grok`},{hostDir:`.iflow`,pruneRoot:`.iflow`},{hostDir:`.inferencesh`,pruneRoot:`.inferencesh`},{hostDir:`.jazz`,pruneRoot:`.jazz`},{hostDir:`.junie`,pruneRoot:`.junie`},{hostDir:`.kilocode`,pruneRoot:`.kilocode`},{hostDir:`.kiro`,pruneRoot:`.kiro`},{hostDir:`.kode`,pruneRoot:`.kode`},{hostDir:`.lingma`,pruneRoot:`.lingma`},{hostDir:`.mcpjam`,pruneRoot:`.mcpjam`},{hostDir:`.moxby`,pruneRoot:`.moxby`},{hostDir:`.mux`,pruneRoot:`.mux`},{hostDir:`.neovate`,pruneRoot:`.neovate`},{hostDir:`.ona`,pruneRoot:`.ona`},{hostDir:`.openhands`,pruneRoot:`.openhands`},{hostDir:`.pochi`,pruneRoot:`.pochi`},{hostDir:`.qoder`,pruneRoot:`.qoder`},{hostDir:`.qoder-cn`,pruneRoot:`.qoder-cn`},{hostDir:`.qwen`,pruneRoot:`.qwen`},{hostDir:`.reasonix`,pruneRoot:`.reasonix`},{hostDir:`.roo`,pruneRoot:`.roo`},{hostDir:`.rovodev`,pruneRoot:`.rovodev`},{hostDir:`.snowflake/cortex`,pruneRoot:`.snowflake`},{hostDir:`.tabnine/agent`,pruneRoot:`.tabnine`},{hostDir:`.terramind`,pruneRoot:`.terramind`},{hostDir:`.tinycloud`,pruneRoot:`.tinycloud`},{hostDir:`.trae`,pruneRoot:`.trae`},{hostDir:`.trae-cn`,pruneRoot:`.trae-cn`},{hostDir:`.vibe`,pruneRoot:`.vibe`},{hostDir:`.zcode`,pruneRoot:`.zcode`},{hostDir:`.zencoder`,pruneRoot:`.zencoder`}],Wn=[...v.map(e=>N[e]),`open-knowledge`];function Gn(e){if(!de(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=V(e);if(t===H||z(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function Kn(e,t){let n=fe(e,t);if(n.startsWith(`..`)||de(n))return!1;let r=e;for(let e of n.split(H)){r=B(r,e);try{if(!ge(r).isDirectory())return!1}catch{return!1}}return!0}function qn(e,t){try{return K(e).every(n=>t.has(B(e,n)))}catch{return!1}}function Jn(e){let t=Gn(e),n=[],r=[],i=new Set;for(let e of Un){let a=B(t,e.hostDir,`skills`);if(!Kn(t,a))continue;let o=Wn.map(e=>B(a,e)).filter(e=>U(e));n.push(...o);for(let e of o)i.add(e);let s=B(t,e.pruneRoot),c=a;for(;qn(c,i)&&(r.push(c),i.add(c),c!==s);){let e=z(c);if(e===c||e===t||!e.startsWith(t+H))break;c=e}}return{skillDirs:n,emptyDirs:r}}function Yn(e){try{if(!ge(e).isDirectory())return!1;let t=K(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function Xn(e){let t=new Set,n=new Set;for(let r of Un){let i=B(e,r.hostDir,`skills`);for(let e of Wn)t.add(B(i,e));let a=B(e,r.pruneRoot),o=i;for(;n.add(o),o!==a;){let t=z(o);if(t===o||t===e||!t.startsWith(e+H))break;o=t}}return{skillDirs:t,emptyDirs:n}}function Zn(e,t){let n=Gn(e),r=Xn(n),i=[...t.skillDirs.filter(e=>!r.skillDirs.has(e)),...t.emptyDirs.filter(e=>!r.emptyDirs.has(e))];if(i.length>0)throw Error(`refusing skill cleanup — ${i.length} path(s) outside the known legacy set: ${i.join(`, `)}`);let a=[];for(let e of t.skillDirs)if(Kn(n,e)&&Yn(e))try{q(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(Kn(n,e))try{xe(e),a.push(e)}catch{}return a}function Qn(e){let t=Gn(e),n=[];for(let e of v){let r=N[e];n.push({path:B(t,`.agents`,`skills`,r),bundleId:e,scope:`central`});for(let i of s)n.push({path:B(t,i.skillsRoot,r),bundleId:e,scope:`host`,hostDir:i.hostDir})}return n}function $n(e,t){let n=[];for(let r of Qn(e))if(r.bundleId===t)try{q(r.path,{recursive:!0,force:!0})}catch(e){n.push(e instanceof Error?e:Error(String(e)))}if(n.length>0)throw AggregateError(n,`Failed to remove ${n.length} path(s) for ${t}`)}function er(e){return e!=null&&e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function tr(e,t=Date.now()){if(e===null)return`—`;let n=Fe(e,t);return n===`unknown`?`—`:n}function nr(e){let t=z(e);return R(e)===`local`&&R(t)===`.ok`?z(t):R(e)===`.ok`?t:null}function rr(e,t,n,r){if(t.status===`missing`||t.status===`corrupt`||t.status===`read-error`)return null;if(t.status===`unverified-owner`)return{directory:nr(e),server:{port:null,status:t.status,pid:t.pid,startedAt:null,usage:null},ui:null,hostname:null,lockPath:t.lockPath,binary:null,command:null,isDesktop:!1};let i=t.lock,a=t.status===`alive`&&A(i)?{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r}:null;return{directory:i.worktreeRoot,server:{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r},ui:a,hostname:i.hostname,lockPath:t.lockPath,binary:n==null?null:E(n),command:n,isDesktop:er(n)}}function ir(e){let t=e.server.status;switch(t){case`unverified-owner`:return`unverified`;case`alive`:return e.isDesktop?`desktop`:`running`;case`foreign-host`:return e.isDesktop?`desktop`:`foreign`;case`dead-pid`:return`stale`;default:return t}}const ar=new Set([`running`,`desktop`,`foreign`,`unverified`]);function or(e){switch(e){case`running`:return Z.default.green(e);case`desktop`:return Z.default.blue(e);case`foreign`:return Z.default.cyan(e);case`unverified`:case`stale`:return Z.default.yellow(e)}}function sr(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function cr(e){return`${sr(e.server.usage)} | ${sr(e.ui?.usage??null)}`}function lr(e){return`${e.server.port===null?`—`:e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null?`—`:String(e.ui.port)}`}function ur(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>[e.directory??`—`,lr(e),cr(e),ir(e),String(e.server.pid),tr(e.server.startedAt),e.binary??`—`]),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=or(ir(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=Z.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
11
- `)}async function dr(e={}){let t=e.discover??w,n=e.inspect??(e=>$(e,`server`)),r=e.log??(e=>console.log(e)),i=e.resolveCommand??y,a=e.resolveUsage??b,o=await t(),s=[];for(let e of o){let t=n(e),r=rr(e,t,t.status===`missing`||t.status===`corrupt`||t.status===`read-error`||t.status===`unverified-owner`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`||t.status===`read-error`||t.status===`unverified-owner`?null:a(t.lock.pid));r!=null&&s.push(r)}if(e.json){let e=s.map(e=>({...e,displayStatus:ir(e)}));r(JSON.stringify(e,null,2));return}r(ur(e.all?s:s.filter(e=>ar.has(ir(e)))))}function fr(){return new te(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale entries (foreign and unverified entries already show)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await dr({all:t.all===!0||e===`all`,json:t.json===!0})})}async function pr(e,t=ae()){let n=$(e,`server`);if(n.status!==`alive`&&n.status!==`foreign-host`)return null;let r=k(n.lock);if(r===null)return null;try{let n=await fetch(`${r}/api/server-info`,{signal:AbortSignal.timeout(1500),redirect:`manual`});if(!n.ok)return t?.warn({lockDir:e,baseUrl:r,outcome:`http-error`,status:n.status},`stop client-probe failed`),null;let i=(await n.json())?.collabClients;return typeof i==`number`&&Number.isFinite(i)?i:(t?.warn({lockDir:e,baseUrl:r,outcome:`no-client-count`,received:typeof i},`stop client-probe failed`),null)}catch(n){return t?.warn({lockDir:e,baseUrl:r,outcome:`unreachable`,err:n},`stop client-probe failed`),null}}function mr(e,t={}){return{targets:_r(e,t.isAlive??P)?[{name:`server`,pid:e.lock.pid,port:e.lock.port}]:[]}}function hr(e){try{return d()}catch(t){e?.warn({err:t},`stop channel check skipped: ${t instanceof Error?t.message:String(t)}`);return}}async function gr(e){let t=e.inspect??(()=>$(e.lockDir,`server`)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=e.probeClients??pr,o=e.logger??ae(),s=t(),c=mr(s,{isAlive:e.isAlive});if(c.targets.length===0)return r(`No running open-knowledge processes.`),o?.info({lockDir:e.lockDir,targets:0},`stop found nothing to signal`),{stopped:[],failed:[],hadTargets:!1};let u=s.status===`alive`||s.status===`foreign-host`?s.lock.channel:void 0;if(e.force!==!0&&typeof u==`string`&&u.length>0){let t=e.selfChannel??hr(o);if(t!==void 0&&u!==t)return i(`Not stopping: the server at ${e.lockDir} belongs to ${l(u)}. Stop it from that app or its CLI, or re-run with --force to terminate anyway.`),o?.warn({lockDir:e.lockDir,holderChannel:u,selfChannel:t,pids:c.targets.map(e=>e.pid)},`stop declined: server belongs to another channel`),{stopped:[],failed:[],hadTargets:!0,declined:{otherChannel:u}}}if(e.force!==!0){let t=await a(e.lockDir,o);if(t!==null&&t>0)return i(`Not stopping: ${t} collaboration client${t===1?``:`s`} (editor window${t===1?``:`s`} or agents) still connected to the server at ${e.lockDir}. Close them, or re-run with --force to terminate anyway.`),o?.warn({lockDir:e.lockDir,clients:t,pids:c.targets.map(e=>e.pid)},`stop declined: live collaboration clients`),{stopped:[],failed:[],hadTargets:!0,declined:{clients:t}}}let d=[],f=[];for(let e of c.targets)try{n(e.pid,`SIGTERM`),d.push(e)}catch(t){f.push({target:e,error:t instanceof Error?t.message:String(t)})}return d.length>0&&r(`Stopped: ${d.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),o?.info({lockDir:e.lockDir,signalled:d.map(e=>({name:e.name,pid:e.pid,port:e.port})),failed:f.map(({target:e,error:t})=>({pid:e.pid,error:t})),forced:e.force===!0},`stop signalled processes`),f.length>0&&i(`Failed to stop: ${f.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:d,failed:f,hadTargets:!0}}function _r(e,t){return e.status===`alive`||e.status===`foreign-host`&&t(e.lock.pid)}async function vr(e,t=P){let n=await w(),r=null;for(let i of n){let n=$(i,`server`);if(_r(n,t)){if(n.lock.port===e)return i;r===null&&n.lock.pid===e&&(r=i)}}return r}async function yr(e,t){let n=await gr({lockDir:e,force:t});return(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1),n}function br(e,t,n={}){return t===0?`Nothing was running for ${e}, and no other open-knowledge servers are running.`:`Nothing was running for ${e}. ${t} other open-knowledge server${t===1?` is`:`s are`} running${n.listingFollows===!0?``:" — run `ok ps` to list them"}.`}async function xr(e){let t=await w(),n=0;for(let r of t)r!==e&&_r($(r,`server`),P)&&n++;return n}function Sr(e){return new te(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the enclosing project — run it from anywhere inside the project. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).option(`--force`,`Stop even when the server belongs to another OpenKnowledge app (Stable or Beta) or editor windows or agents are still connected to it`).action(async(t,n)=>{let r=n.force===!0,i=t.length===0?void 0:t.join(` `);if(i===void 0){e();let t=D(process.cwd()),n=await gr({lockDir:t,force:r,log:()=>{}});if(n.hadTargets){if(n.stopped.length>0){let e=n.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1)}else{let e=await xr(t);console.log(br(process.cwd(),e,{listingFollows:e>0})),e>0&&await dr({})}return}if(i===`all`){let e=await w();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e)_r($(n,`server`),P)&&(await yr(n,r),t++);t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(i)){let e=Number.parseInt(i,10),t=await vr(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}await yr(t,r);return}let a=V(Be(),i),o=D(a),s=[],c=await gr({lockDir:o,force:r,log:e=>s.push(e)});if((c.failed.length>0||c.declined!==void 0)&&(process.exitCode=1),c.hadTargets)for(let e of s)console.log(e);else console.log(br(a,await xr(o)))})}export{Be as A,it as C,He as D,Ue as E,Le as M,Ge as O,at as S,Ve as T,$ as _,Zn as a,On as b,Qn as c,In as d,Ln as f,Mn as g,Pn as h,fr as i,ze as j,Ke as k,Fn as l,Vn as m,gr as n,Jn as o,Bn as p,Sr as r,$n as s,pr as t,Hn as u,jn as v,Je as w,ot as x,Dn as y};
@@ -1 +0,0 @@
1
- import"./md-manager-BGnqyqi1-IqwoPmS1.mjs";import"./src-Ap_2wxuM.mjs";import"./init-0oLlE1YP.mjs";import"./registry-probes-TTIv_jQo.mjs";import"./start-DmACO7Nh.mjs";import{n as e}from"./loader-1manjX2x.mjs";import"./preview-C5jJBQtN.mjs";import"./repair-mcp-configs-CSuOjpAP.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{S as e,m as t,p as n,r}from"./start-DmACO7Nh.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};