@inkeep/open-knowledge 0.88.10-beta.0 → 0.88.11-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 (110) hide show
  1. package/dist/{cli-UjiLdpRk.mjs → cli-CKiNxYDi.mjs} +57 -57
  2. package/dist/cli.mjs +1 -1
  3. package/dist/config-schema.json +25 -0
  4. package/dist/config.user.schema.json +25 -0
  5. package/dist/constants-COUZx5WC.mjs +1 -0
  6. package/dist/dist-BSNy29T3.mjs +2326 -0
  7. package/dist/dist-Bfg_JABr.mjs +1 -0
  8. package/dist/index.d.mts +3 -0
  9. package/dist/index.mjs +343 -245
  10. package/dist/init-D4jlORuT.mjs +1 -0
  11. package/dist/{init-BJM0tqDo.mjs → init-DZf66ZMB.mjs} +8 -8
  12. package/dist/{launch-json-removal-DzsPe2PB.mjs → launch-json-removal-Bnn4Q8Q5.mjs} +1 -1
  13. package/dist/{loader-DIQF01bS.mjs → loader-CQWLo5wb.mjs} +1 -1
  14. package/dist/loader-CYqRMGXq.mjs +1 -0
  15. package/dist/{lzma-B6QS2aZK.mjs → lzma-Ciwelb1t.mjs} +2 -2
  16. package/dist/{md-manager-BGnqyqi1-B5Gyjk_N.mjs → md-manager-BGnqyqi1-DCCfgLfC.mjs} +142 -143
  17. package/dist/{open-browser-kL892VYi.mjs → open-browser-Bb2-wy79.mjs} +1 -1
  18. package/dist/parse-worker.mjs +1 -1
  19. package/dist/preview-CMjmNRLt.mjs +1 -0
  20. package/dist/{preview-DHNV39t9.mjs → preview-UtmI_Kbo.mjs} +1 -1
  21. package/dist/public/assets/{AccountSection-CxiGTQvT.js → AccountSection-92kzeYSz.js} +1 -1
  22. package/dist/public/assets/{ActivityModeContent-CsJLWo7P.js → ActivityModeContent-c0yIlei6.js} +1 -1
  23. package/dist/public/assets/{AddPropertiesButton-DDSKy0hZ.js → AddPropertiesButton-CD7DFmk4.js} +1 -1
  24. package/dist/public/assets/{AgentDiffPane-BTwm5dPg.js → AgentDiffPane-Qdw4whsW.js} +1 -1
  25. package/dist/public/assets/{AttachmentsSection-D--8u15R.js → AttachmentsSection-DkrZOM4_.js} +1 -1
  26. package/dist/public/assets/{CodeMirrorPropInput-Ba_sHgAe.js → CodeMirrorPropInput-BGz-GQYy.js} +1 -1
  27. package/dist/public/assets/{ContentRulesSection-CPWHfaPG.js → ContentRulesSection-Cp7WxUGq.js} +1 -1
  28. package/dist/public/assets/{DocumentContext-1lgfWMNj.js → DocumentContext-Oflbu4n0.js} +1 -1
  29. package/dist/public/assets/{EditorModeToggle-Bo9FdfPJ.js → EditorModeToggle-DbRqwAo8.js} +1 -1
  30. package/dist/public/assets/{ExcalidrawDocEditor-DT3l4Tga.js → ExcalidrawDocEditor-BB3VQ-A5.js} +1 -1
  31. package/dist/public/assets/FeedbackForm-BE3p6ea8.js +1 -0
  32. package/dist/public/assets/{ImportSkillDialog-DTrqagnm.js → ImportSkillDialog-CgLt_Ckj.js} +1 -1
  33. package/dist/public/assets/{LinkPreviewsSection-BWQDpXpm.js → LinkPreviewsSection-Ba0s74kx.js} +1 -1
  34. package/dist/public/assets/{LintConfigEditor-BF-mVtyQ.js → LintConfigEditor-BtsBpxqx.js} +1 -1
  35. package/dist/public/assets/{LintingSection-Cfhf0DPw.js → LintingSection-BWGxasTk.js} +1 -1
  36. package/dist/public/assets/ManagedArtifactProperties-DEfWLrVU.js +1 -0
  37. package/dist/public/assets/{ManagedArtifactProperties-D54iCwKr.js → ManagedArtifactProperties-FdKNrPr-.js} +1 -1
  38. package/dist/public/assets/{MermaidDocEditor-jLrjFhuK.js → MermaidDocEditor-D_MVfawW.js} +1 -1
  39. package/dist/public/assets/{NetworkAccessSection-B3PxlFUV.js → NetworkAccessSection-x1p6MRDS.js} +1 -1
  40. package/dist/public/assets/{PropertyDisplayRow-p7m1gH00.js → PropertyDisplayRow-hkfIbJsU.js} +1 -1
  41. package/dist/public/assets/{PublishToGitHubDialog-BldOZlur.js → PublishToGitHubDialog-CWp9_6sQ.js} +1 -1
  42. package/dist/public/assets/{SchemaConfigEditor-CQPB_KVk.js → SchemaConfigEditor-DES1MqTn.js} +1 -1
  43. package/dist/public/assets/{SearchSection-FjgJ4pYB.js → SearchSection-DaAoqTaY.js} +1 -1
  44. package/dist/public/assets/{SessionsHost-C0CPsloP.js → SessionsHost-BWqLoT8o.js} +2 -2
  45. package/dist/public/assets/{SettingsDialogBody-DA80GTbj.js → SettingsDialogBody-_2UYxQzL.js} +2 -2
  46. package/dist/public/assets/{ShareReceiveMissDialog-CwR5P3yc.js → ShareReceiveMissDialog-DsAhOXOf.js} +1 -1
  47. package/dist/public/assets/{SkillToolbarControls-C-BIZRfC.js → SkillToolbarControls-CxIhFxut.js} +1 -1
  48. package/dist/public/assets/{SourceEditor-C9fqzm-Y.js → SourceEditor-CmyXOjyo.js} +1 -1
  49. package/dist/public/assets/{SpellingSettings-BnekUXi0.js → SpellingSettings-aGM4YFpK.js} +1 -1
  50. package/dist/public/assets/{SyncSection-Bt4ojTQx.js → SyncSection-DKwcggD4.js} +1 -1
  51. package/dist/public/assets/{SyncStatusBadge-DaTGToC4.js → SyncStatusBadge-C3yXqn1g.js} +1 -1
  52. package/dist/public/assets/{TerminalSection-CYA0yx66.js → TerminalSection-Df2_OUq4.js} +1 -1
  53. package/dist/public/assets/{TerminalWindowApp-BH1UHA-h.js → TerminalWindowApp-BsaMrWLk.js} +1 -1
  54. package/dist/public/assets/{TextDocEditor-BjrgE8Or.js → TextDocEditor-lseiNuoW.js} +1 -1
  55. package/dist/public/assets/{ThemePluginSection-htJshVsF.js → ThemePluginSection-DdSQUUtI.js} +1 -1
  56. package/dist/public/assets/{ThreadView-Cc9oztDV.js → ThreadView-OZ2uZOIE.js} +1 -1
  57. package/dist/public/assets/{TimelineDiffPane-Q8VQLhyd.js → TimelineDiffPane-WxFbMDQS.js} +1 -1
  58. package/dist/public/assets/{client-version-BhRx5eCh.js → client-version-CY6vMdzi.js} +1 -1
  59. package/dist/public/assets/{comment-chips-CLGtIfZO.js → comment-chips-CGZDgzW5.js} +1 -1
  60. package/dist/public/assets/config-provider-pJEK9WCI.js +4 -0
  61. package/dist/public/assets/config-schema-DM88r6Wp.js +1 -0
  62. package/dist/public/assets/{doc-undo-manager-C-fYUKyc.js → doc-undo-manager-BJwKYuHY.js} +1 -1
  63. package/dist/public/assets/{field-controls-uK27_e3u.js → field-controls-C_sis3h8.js} +1 -1
  64. package/dist/public/assets/field-controls-Cl0fMM5C.js +1 -0
  65. package/dist/public/assets/{index-CYBoRjkk.js → index-CUM2b-vl.js} +107 -107
  66. package/dist/public/assets/{lint-config-client-D7WzQSDg.js → lint-config-client-CZ22hfd5.js} +1 -1
  67. package/dist/public/assets/{lint-plugins-Cn2uC583.js → lint-plugins-C3d0yJ4F.js} +1 -1
  68. package/dist/public/assets/{markdown-lint-DwFRnZJ_.js → markdown-lint-D13AGXjm.js} +2 -2
  69. package/dist/public/assets/{markdownlint-rule-browser-DBy2EH_P.js → markdownlint-rule-browser-mf_8la30.js} +1 -1
  70. package/dist/public/assets/{pending-receive-nav-store-fES-up-c.js → pending-receive-nav-store-CqX4bHwr.js} +1 -1
  71. package/dist/public/assets/{preferred-session-events-l03sDUdz.js → preferred-session-events-BYPsTTfd.js} +1 -1
  72. package/dist/public/assets/{progress-BPvowhCv.js → progress-ChjxM4dF.js} +1 -1
  73. package/dist/public/assets/saved-themes-client-B4QZmuf_.js +1 -0
  74. package/dist/public/assets/{schema-section-Cp00yQR2.js → schema-section-BaOibm8x.js} +1 -1
  75. package/dist/public/assets/{selection-context-BkLEsaBu.js → selection-context-Cub1fE1T.js} +1 -1
  76. package/dist/public/assets/{src-BeGsSfov.js → src-DewQmhy5.js} +1 -1
  77. package/dist/public/assets/{telemetry-impl-B1MY97_o.js → telemetry-impl-CaqdOBmg.js} +1 -1
  78. package/dist/public/assets/{telemetry-startup-Ch1mOkK0.js → telemetry-startup-DNHafhpO.js} +1 -1
  79. package/dist/public/assets/{typing-burst-detector-xkhkpi6D.js → typing-burst-detector-C0UhTw8o.js} +1 -1
  80. package/dist/public/assets/{use-activity-panel-B7tFs2_j.js → use-activity-panel-BHSrXZXF.js} +1 -1
  81. package/dist/public/assets/{use-open-skill-7Fj64f1d.js → use-open-skill-DrtR4XOY.js} +1 -1
  82. package/dist/public/assets/{use-terminal-enabled-Dsp6_rSS.js → use-terminal-enabled-CSFlSWPT.js} +1 -1
  83. package/dist/public/assets/{use-timeline-entry-diff-DZpZNVqQ.js → use-timeline-entry-diff-VsPbMLbd.js} +1 -1
  84. package/dist/public/index.html +22 -22
  85. package/dist/{registry-probes-ki_xxXZ3.mjs → registry-probes-DIqlo9h8.mjs} +2 -2
  86. package/dist/{removal-file-path-DwHGP18a.mjs → removal-file-path-wBKXFJo1.mjs} +1 -1
  87. package/dist/{repair-launch-json-tEr9u8zZ.mjs → repair-launch-json-24ZgLMF1.mjs} +1 -1
  88. package/dist/{repair-mcp-configs-DmDI3tPM.mjs → repair-mcp-configs-euqladvH.mjs} +1 -1
  89. package/dist/schemas/v0/config.user.schema.json +25 -0
  90. package/dist/src-DEXULBC-.mjs +1 -0
  91. package/dist/src-DKsIGYJ_.mjs +16 -0
  92. package/dist/{start-nOmb3qwo.mjs → start-9N2SMPQM.mjs} +3 -3
  93. package/dist/start-CJj6tAZ-.mjs +1 -0
  94. package/dist/{tar-MZQD7NO4-ljX84Spn.mjs → tar-MZQD7NO4-D-JBnhvQ.mjs} +2 -2
  95. package/package.json +4 -4
  96. package/dist/constants-BJdBF6qC.mjs +0 -1
  97. package/dist/dist-By4Q8HCV.mjs +0 -2227
  98. package/dist/dist-Ttulen40.mjs +0 -1
  99. package/dist/init-NviVfKX0.mjs +0 -1
  100. package/dist/loader-BF6xIB9H.mjs +0 -1
  101. package/dist/preview-BJIs-Agv.mjs +0 -1
  102. package/dist/public/assets/FeedbackForm-DmOvYi4E.js +0 -1
  103. package/dist/public/assets/ManagedArtifactProperties-D27yWRpD.js +0 -1
  104. package/dist/public/assets/config-provider-4A-Qi_lD.js +0 -4
  105. package/dist/public/assets/config-schema-BFeDYLCd.js +0 -1
  106. package/dist/public/assets/field-controls-lq4qcuvr.js +0 -1
  107. package/dist/public/assets/saved-themes-client-DX5dCXi5.js +0 -1
  108. package/dist/src-CIcIgMv1.mjs +0 -16
  109. package/dist/src-aQblTkIp.mjs +0 -1
  110. package/dist/start-DQR1IbHI.mjs +0 -1
@@ -86,7 +86,7 @@
86
86
  -->
87
87
  <script>(() => { try { const raw = localStorage.getItem('ok-language-v1'); if (!raw) return; const o = JSON.parse(raw); if (typeof o?.locale !== 'string' || !/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{2,8})*$/.test(o.locale)) return; document.documentElement.lang = o.locale; document.documentElement.dir = o.dir === 'rtl' ? 'rtl' : 'ltr'; } catch {} })();</script>
88
88
  <style>html { background-color: #fafafa } html.dark { background-color: #0b0b0b }</style>
89
- <script type="module" crossorigin src="./assets/index-CYBoRjkk.js"></script>
89
+ <script type="module" crossorigin src="./assets/index-CUM2b-vl.js"></script>
90
90
  <link rel="modulepreload" crossorigin href="./assets/chunk-CYidjpOJ.js">
91
91
  <link rel="modulepreload" crossorigin href="./assets/react-f2sANaYj.js">
92
92
  <link rel="modulepreload" crossorigin href="./assets/react-dom-DPxgxlDT.js">
@@ -127,14 +127,14 @@
127
127
  <link rel="modulepreload" crossorigin href="./assets/dist-BGzUo_18.js">
128
128
  <link rel="modulepreload" crossorigin href="./assets/messages-BY7FXc1p.js">
129
129
  <link rel="modulepreload" crossorigin href="./assets/use-apply-config-language-9fLQZCsK.js">
130
- <link rel="modulepreload" crossorigin href="./assets/client-version-BhRx5eCh.js">
130
+ <link rel="modulepreload" crossorigin href="./assets/client-version-CY6vMdzi.js">
131
131
  <link rel="modulepreload" crossorigin href="./assets/dist-Nvb76hAm.js">
132
132
  <link rel="modulepreload" crossorigin href="./assets/use-apply-config-theme-CYFG76sS.js">
133
133
  <link rel="modulepreload" crossorigin href="./assets/use-apply-config-color-theme-CTtLraO9.js">
134
134
  <link rel="modulepreload" crossorigin href="./assets/css-color-to-hex-pv-EKOQu.js">
135
135
  <link rel="modulepreload" crossorigin href="./assets/constants-upload-DZP-sCdl.js">
136
- <link rel="modulepreload" crossorigin href="./assets/saved-themes-client-DX5dCXi5.js">
137
- <link rel="modulepreload" crossorigin href="./assets/config-provider-4A-Qi_lD.js">
136
+ <link rel="modulepreload" crossorigin href="./assets/saved-themes-client-B4QZmuf_.js">
137
+ <link rel="modulepreload" crossorigin href="./assets/config-provider-pJEK9WCI.js">
138
138
  <link rel="modulepreload" crossorigin href="./assets/dist-Dc8tD1th.js">
139
139
  <link rel="modulepreload" crossorigin href="./assets/ccount-s_UaBrax.js">
140
140
  <link rel="modulepreload" crossorigin href="./assets/lib-CZXZ01YL.js">
@@ -157,7 +157,7 @@
157
157
  <link rel="modulepreload" crossorigin href="./assets/documents-fetch-ZX1mUge_.js">
158
158
  <link rel="modulepreload" crossorigin href="./assets/note-window-mode-CI3Yju9B.js">
159
159
  <link rel="modulepreload" crossorigin href="./assets/structural-freshness-C6rR7cV3-VXiZX15w.js">
160
- <link rel="modulepreload" crossorigin href="./assets/CodeMirrorPropInput-Ba_sHgAe.js">
160
+ <link rel="modulepreload" crossorigin href="./assets/CodeMirrorPropInput-BGz-GQYy.js">
161
161
  <link rel="modulepreload" crossorigin href="./assets/dist-CSCUSbQc.js">
162
162
  <link rel="modulepreload" crossorigin href="./assets/dist-DTFuvKje.js">
163
163
  <link rel="modulepreload" crossorigin href="./assets/dist-CRjqnzU7.js">
@@ -241,36 +241,36 @@
241
241
  <link rel="modulepreload" crossorigin href="./assets/storage-scope-sNHb4BCO.js">
242
242
  <link rel="modulepreload" crossorigin href="./assets/use-workspace-5RavNejH.js">
243
243
  <link rel="modulepreload" crossorigin href="./assets/utils-random-uuid-CE1X6bNM.js">
244
- <link rel="modulepreload" crossorigin href="./assets/DocumentContext-1lgfWMNj.js">
244
+ <link rel="modulepreload" crossorigin href="./assets/DocumentContext-Oflbu4n0.js">
245
245
  <link rel="modulepreload" crossorigin href="./assets/dist-BKgU0kag.js">
246
246
  <link rel="modulepreload" crossorigin href="./assets/dist-d2WYntJB.js">
247
247
  <link rel="modulepreload" crossorigin href="./assets/dist-C0nuYMFu.js">
248
248
  <link rel="modulepreload" crossorigin href="./assets/dropdown-menu-5XqyQTVx.js">
249
- <link rel="modulepreload" crossorigin href="./assets/comment-chips-CLGtIfZO.js">
249
+ <link rel="modulepreload" crossorigin href="./assets/comment-chips-CGZDgzW5.js">
250
250
  <link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-BD1Le0QE.js">
251
251
  <link rel="modulepreload" crossorigin href="./assets/tool-list-format-ahklHT7Z.js">
252
252
  <link rel="modulepreload" crossorigin href="./assets/acp-thread-protocol-EC8X7m2Z.js">
253
253
  <link rel="modulepreload" crossorigin href="./assets/image-attachment-Chp6ejuJ.js">
254
254
  <link rel="modulepreload" crossorigin href="./assets/workspace-paths-BjilyZF6.js">
255
255
  <link rel="modulepreload" crossorigin href="./assets/acp-tool-call-input-B6Z0o0iM.js">
256
- <link rel="modulepreload" crossorigin href="./assets/progress-BPvowhCv.js">
256
+ <link rel="modulepreload" crossorigin href="./assets/progress-ChjxM4dF.js">
257
257
  <link rel="modulepreload" crossorigin href="./assets/radio-group-G1GR05Rb.js">
258
258
  <link rel="modulepreload" crossorigin href="./assets/separator-D7s_9ZwH.js">
259
259
  <link rel="modulepreload" crossorigin href="./assets/toggle-group-B7p69Qfd.js">
260
260
  <link rel="modulepreload" crossorigin href="./assets/useQuery-ZeEDLtxh.js">
261
261
  <link rel="modulepreload" crossorigin href="./assets/markdownit-B0tzyo4f.js">
262
- <link rel="modulepreload" crossorigin href="./assets/markdown-lint-DwFRnZJ_.js">
262
+ <link rel="modulepreload" crossorigin href="./assets/markdown-lint-D13AGXjm.js">
263
263
  <link rel="modulepreload" crossorigin href="./assets/format-DUHlUJ5L.js">
264
264
  <link rel="modulepreload" crossorigin href="./assets/braces--g9Mwtim.js">
265
- <link rel="modulepreload" crossorigin href="./assets/PropertyDisplayRow-p7m1gH00.js">
265
+ <link rel="modulepreload" crossorigin href="./assets/PropertyDisplayRow-hkfIbJsU.js">
266
266
  <link rel="modulepreload" crossorigin href="./assets/grip-vertical-DNbkgWZL.js">
267
267
  <link rel="modulepreload" crossorigin href="./assets/SkillCostValue-BcfssFYU.js">
268
268
  <link rel="modulepreload" crossorigin href="./assets/textarea-DkcNoPBJ.js">
269
- <link rel="modulepreload" crossorigin href="./assets/selection-context-BkLEsaBu.js">
270
- <link rel="modulepreload" crossorigin href="./assets/lint-config-client-D7WzQSDg.js">
269
+ <link rel="modulepreload" crossorigin href="./assets/selection-context-Cub1fE1T.js">
270
+ <link rel="modulepreload" crossorigin href="./assets/lint-config-client-CZ22hfd5.js">
271
271
  <link rel="modulepreload" crossorigin href="./assets/use-skills-B6ndwLoW.js">
272
272
  <link rel="modulepreload" crossorigin href="./assets/folder-config-api-C6LhS3Cf.js">
273
- <link rel="modulepreload" crossorigin href="./assets/ManagedArtifactProperties-D54iCwKr.js">
273
+ <link rel="modulepreload" crossorigin href="./assets/ManagedArtifactProperties-FdKNrPr-.js">
274
274
  <link rel="modulepreload" crossorigin href="./assets/arrow-up-right-nJaICi16.js">
275
275
  <link rel="modulepreload" crossorigin href="./assets/git-merge-VDBzSZBV.js">
276
276
  <link rel="modulepreload" crossorigin href="./assets/refresh-cw-BVQchE6b.js">
@@ -281,7 +281,7 @@
281
281
  <link rel="modulepreload" crossorigin href="./assets/use-conflicts-DEteFrWs.js">
282
282
  <link rel="modulepreload" crossorigin href="./assets/use-git-sync-status-DB3RSBj5.js">
283
283
  <link rel="modulepreload" crossorigin href="./assets/use-settings-route-BGtkup9E.js">
284
- <link rel="modulepreload" crossorigin href="./assets/SyncStatusBadge-DaTGToC4.js">
284
+ <link rel="modulepreload" crossorigin href="./assets/SyncStatusBadge-C3yXqn1g.js">
285
285
  <link rel="modulepreload" crossorigin href="./assets/cursor-pH0WlPzE.js">
286
286
  <link rel="modulepreload" crossorigin href="./assets/agent-registry-Z4n6bROi.js">
287
287
  <link rel="modulepreload" crossorigin href="./assets/RegisteredAgentIcon-3YdE9YD2.js">
@@ -305,18 +305,18 @@
305
305
  <link rel="modulepreload" crossorigin href="./assets/agent-launcher-labels-CKD6Vuny.js">
306
306
  <link rel="modulepreload" crossorigin href="./assets/terminal-cli-display-CHuCou07.js">
307
307
  <link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-BcMHQbeA.js">
308
- <link rel="modulepreload" crossorigin href="./assets/use-open-skill-7Fj64f1d.js">
308
+ <link rel="modulepreload" crossorigin href="./assets/use-open-skill-DrtR4XOY.js">
309
309
  <link rel="modulepreload" crossorigin href="./assets/platform-labels-DDy1ouuX.js">
310
310
  <link rel="modulepreload" crossorigin href="./assets/clipboard-adapter-FO6gFDPG.js">
311
- <link rel="modulepreload" crossorigin href="./assets/AddPropertiesButton-DDSKy0hZ.js">
311
+ <link rel="modulepreload" crossorigin href="./assets/AddPropertiesButton-CD7DFmk4.js">
312
312
  <link rel="modulepreload" crossorigin href="./assets/case-sensitive-DIxypOE0.js">
313
313
  <link rel="modulepreload" crossorigin href="./assets/chevron-left-C5T97PNU.js">
314
314
  <link rel="modulepreload" crossorigin href="./assets/lint-plugin-meta-CtDE2R0v.js">
315
315
  <link rel="modulepreload" crossorigin href="./assets/wrench-DmtZXcHB.js">
316
316
  <link rel="modulepreload" crossorigin href="./assets/panel-eNhYruJz.js">
317
- <link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-xkhkpi6D.js">
317
+ <link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-C0UhTw8o.js">
318
318
  <link rel="modulepreload" crossorigin href="./assets/miss-dialog-store-CsiJb9Ou.js">
319
- <link rel="modulepreload" crossorigin href="./assets/pending-receive-nav-store-fES-up-c.js">
319
+ <link rel="modulepreload" crossorigin href="./assets/pending-receive-nav-store-CqX4bHwr.js">
320
320
  <link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-D_irC8wr.js">
321
321
  <link rel="modulepreload" crossorigin href="./assets/terminal-launch-events-aL5veMO9.js">
322
322
  <link rel="modulepreload" crossorigin href="./assets/contact-email-store-B_5aVbhf.js">
@@ -325,7 +325,7 @@
325
325
  <link rel="modulepreload" crossorigin href="./assets/package-PkCmIx3S.js">
326
326
  <link rel="modulepreload" crossorigin href="./assets/panel-right-open-D4M8nGPT.js">
327
327
  <link rel="modulepreload" crossorigin href="./assets/overlay-layers-CKMAjef3.js">
328
- <link rel="modulepreload" crossorigin href="./assets/preferred-session-events-l03sDUdz.js">
328
+ <link rel="modulepreload" crossorigin href="./assets/preferred-session-events-BYPsTTfd.js">
329
329
  <link rel="modulepreload" crossorigin href="./assets/panel-right-close-Bsh1pCmh.js">
330
330
  <link rel="modulepreload" crossorigin href="./assets/rotate-ccw-DeMl2ou7.js">
331
331
  <link rel="modulepreload" crossorigin href="./assets/square-pen-DU3t-IcD.js">
@@ -335,13 +335,13 @@
335
335
  <link rel="modulepreload" crossorigin href="./assets/dist-DMhg0Xyd.js">
336
336
  <link rel="modulepreload" crossorigin href="./assets/dist-ucvNbATJ.js">
337
337
  <link rel="modulepreload" crossorigin href="./assets/text-viewer-languages-CDBOzWaI.js">
338
- <link rel="modulepreload" crossorigin href="./assets/EditorModeToggle-Bo9FdfPJ.js">
338
+ <link rel="modulepreload" crossorigin href="./assets/EditorModeToggle-DbRqwAo8.js">
339
339
  <link rel="modulepreload" crossorigin href="./assets/ImageAttachments-BGB1Xeig.js">
340
340
  <link rel="modulepreload" crossorigin href="./assets/TemplateRow-CHung0e5.js">
341
341
  <link rel="modulepreload" crossorigin href="./assets/ConfigSharingInfoTooltip-CJywmyrk.js">
342
342
  <link rel="modulepreload" crossorigin href="./assets/RowDisclosure-BpaiWVwL.js">
343
343
  <link rel="modulepreload" crossorigin href="./assets/project-paths-Cq56bh9f.js">
344
- <link rel="modulepreload" crossorigin href="./assets/PublishToGitHubDialog-BldOZlur.js">
344
+ <link rel="modulepreload" crossorigin href="./assets/PublishToGitHubDialog-CWp9_6sQ.js">
345
345
  <link rel="modulepreload" crossorigin href="./assets/use-installed-clis-APSgNRF8.js">
346
346
  <link rel="modulepreload" crossorigin href="./assets/ReportBugMenuTrigger-YhgSFu20.js">
347
347
  <link rel="modulepreload" crossorigin href="./assets/SkillModeBanner-BLTTRSBJ.js">
@@ -359,7 +359,7 @@
359
359
  <link rel="modulepreload" crossorigin href="./assets/alert-BEwM2iOp.js">
360
360
  <link rel="modulepreload" crossorigin href="./assets/input-group-CBuVp6zh.js">
361
361
  <link rel="modulepreload" crossorigin href="./assets/use-skill-origin-CFF_c9ld.js">
362
- <link rel="modulepreload" crossorigin href="./assets/use-terminal-enabled-Dsp6_rSS.js">
362
+ <link rel="modulepreload" crossorigin href="./assets/use-terminal-enabled-CSFlSWPT.js">
363
363
  <link rel="modulepreload" crossorigin href="./assets/catalog-CLnUnyxw.js">
364
364
  <link rel="modulepreload" crossorigin href="./assets/agent-presence-DU3TT-KP.js">
365
365
  <link rel="modulepreload" crossorigin href="./assets/auth-prompt-store-Br5SQeuk.js">
@@ -1,4 +1,4 @@
1
- import{i as e,o as t,t as n}from"./rolldown-runtime-tZXQYakl.mjs";import{C as r,E as i,L as a,M as o,N as s,P as c,w as l,x as u}from"./constants-ok-dir-DZ25OS9-.mjs";import{Ya as d,af as f,bd as p,cf as m,of as h,rf as g}from"./md-manager-BGnqyqi1-B5Gyjk_N.mjs";import{Ms as _,Ns as v,Oa as y,Vo as ee,m as b,ns as te,tr as x}from"./dist-By4Q8HCV.mjs";import{s as S,y as ne}from"./fs-find-project-root-BYV07wjn.mjs";import{A as re,B as ie,E as C,F as ae,M as w,N as T,S as oe,T as se,Y as ce,Z as E,at as le,b as ue,et as de,f as fe,ft as pe,it as me,j as he,k as D,lt as ge,nt as _e,ot as ve,p as ye,rt as be,s as xe,ut as Se,y as Ce}from"./init-BJM0tqDo.mjs";import{o as we}from"./token-store-Bmb3_0hU.mjs";import{t as Te}from"./is-object-BGze3w87.mjs";import{t as Ee}from"./removal-file-path-DwHGP18a.mjs";import{basename as O,dirname as k,join as A,resolve as j,win32 as De}from"node:path";import{accessSync as Oe,constants as M,existsSync as N,lstatSync as P,mkdirSync as ke,readFileSync as F,readdirSync as I,realpathSync as L,rmSync as Ae,rmdirSync as je,statSync as R,unlinkSync as Me}from"node:fs";import{homedir as z}from"node:os";import{createHash as Ne}from"node:crypto";import{spawn as Pe}from"node:child_process";import{setTimeout as Fe}from"node:timers/promises";import{isDeepStrictEqual as Ie}from"node:util";function Le(e){let t={...e};return delete t.ELECTRON_RUN_AS_NODE,t}function Re(e){let t=e?.code;return t===`ENOENT`||t===`EACCES`||t===`EPERM`?{ok:!1,reason:`not-installed`}:{ok:!1,reason:`spawn-error`}}function ze(e){return ee({detached:!0,stdio:`ignore`,shell:!1,env:Le(e)})}function Be(e,t,n={}){let r=(n.spawn??Pe)(e,[...t],ze(n.env??process.env));return r.unref(),r}function Ve(e,t,n={}){let r=n.spawn??Pe,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],ze(n.env??process.env));i.once(`error`,e=>{clearTimeout(c),s(Re(e))}),i.once(`spawn`,()=>{clearTimeout(c),s({ok:!0})});try{i.unref()}catch{}}catch(e){clearTimeout(c),s(Re(e))}})}const He=r.stable.appId,B=i,Ue=[`stable`,`beta`];function We(e,t,n=e=>console.error(e)){try{return a(e,t)}catch(r){let i=a({...e,[l]:void 0},t);return n(`Treating this CLI as ${o(i)} for this command: ${r instanceof Error?r.message:String(r)}`),i}}function V(e){return Ue.includes(e)||!B.includes(e)?Ue:[e,...Ue]}function Ge(e){return e.bundlePath===void 0?null:{bundlePath:e.bundlePath,protocolScheme:r[e.product].protocolScheme}}function Ke(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return R(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function qe(e,t){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let n=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(n?.[1]){let e=n[1];return{path:e,product:B.find(t=>e.endsWith(`/${r[t].productName}.app`))??t}}}let n=e.homeDir??z();for(let i of V(t)){let{productName:t}=r[i];for(let r of[A(n,`Applications`),`/Applications`]){let n=A(r,`${t}.app`);if(Je(e,A(n,`Contents`,`MacOS`,t)))return{path:n,product:i}}}return null}function Je(e,t){try{let n=e.statSync(t);return n?typeof n.isFile==`function`&&n.isFile():!1}catch{return!1}}function Ye(e,t){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=B.find(t=>e.execPath.toLowerCase().endsWith(`\\${s(r[t]).toLowerCase()}`));if(t)return{path:e.execPath,product:t}}let n=e.env.LOCALAPPDATA;if(n)for(let i of V(t))for(let t of c(r[i])){let a=De.join(n,`Programs`,t,s(r[i]));if(Je(e,a))return{path:a,product:i}}return null}function Xe(e,t){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=B.find(t=>e.execPath.endsWith(`/${r[t].linuxExecutableName}`));if(t)return{path:e.execPath,product:t}}for(let n of V(t)){let{productName:t,linuxExecutableName:i}=r[n],a=`/opt/${t}/${i}`;if(Je(e,a))return{path:a,product:n}}return null}function Ze(e){let t=We(e.env,e.execPath,e.warn);if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`,cliProduct:t};if(e.platform!==`darwin`&&e.platform!==`win32`&&e.platform!==`linux`)return{available:!1,reason:`unsupported-platform`,cliProduct:t};let n;try{n=e.platform===`darwin`?qe(e,t):e.platform===`win32`?Ye(e,t):Xe(e,t)}catch{return{available:!1,reason:`stat-error`,cliProduct:t}}if(!n)return{available:!1,reason:`no-bundle`,cliProduct:t};let r={bundlePath:n.path,product:n.product,cliProduct:t};return e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,...r}:!(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`,...r}:{available:!0,reason:`available`,...r}}function Qe(e,t){let n=e.log??(e=>console.error(e)),i=e.platform??process.platform;if(t.bundlePath===void 0){n(`Desktop launch skipped: no resolved desktop executable (caller bug).`);return}let{productName:a}=r[t.product],[o]=r[t.cliProduct].cliCommandNames;n(`Launching ${a} desktop (use \`${o} start\` for the browser server, or \`OK_FORCE_BROWSER=1\` to always skip)`);let s=t.bundlePath;if(i===`darwin`){Be(`open`,[`-a`,s],{spawn:e.spawn});return}Be(s,[],{spawn:e.spawn})}function $e(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).`}}var et=u();function H(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 tt(e){return Ne(`sha256`).update(e).digest(`hex`)}function U(e){return A(ne(j(e)),`pi-trust`)}function nt(e,t){return A(U(e),tt(j(t)))}function rt(e,t,n){return A(nt(e,t),`${tt(n)}.json`)}var W=class extends Error{constructor(e,t,n,r){super(`Pi trust receipt at ${H(e)} ${H(t)}; ${H(n)}`,{cause:r}),this.name=`PiTrustReceiptError`}};function G(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 W(e,`could not ${t}: ${i}`,a,n)}function K(e){let t;try{t=P(e)}catch(t){if(t.code===`ENOENT`)return!1;throw G(e,`be inspected`,t)}if(!t.isDirectory())throw new W(e,`is not a regular directory`,`restore the intended receipt directory without a symlink, then retry`);return!0}function it(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}function at(e,t){if(!Te(e)||!it(e,[`version`,`cwd`,`configuredTrustPath`,`canonicalTrustPath`,`state`,`previous`])||e.version!==1||typeof e.cwd!=`string`||e.cwd!==j(e.cwd)||typeof e.configuredTrustPath!=`string`||e.configuredTrustPath!==j(e.configuredTrustPath)||typeof e.canonicalTrustPath!=`string`||e.canonicalTrustPath!==j(e.canonicalTrustPath)||e.state!==`pending`&&e.state!==`committed`||!Te(e.previous))throw new W(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&&it(e.previous,[`present`]))n={present:!1};else if(e.previous.present===!0&&it(e.previous,[`present`,`value`]))n={present:!0,value:e.previous.value};else throw new W(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 ot(e,t,n){let r;try{r=P(n)}catch(e){throw G(n,`be inspected`,e)}if(!r.isFile())throw new W(n,`is not a regular file`,`restore the intended receipt as a regular file without a symlink, then retry`);let i;try{i=F(n,`utf8`)}catch(e){throw G(n,`be read`,e)}let a;try{a=JSON.parse(i)}catch(e){throw new W(n,`is not valid JSON`,`repair its JSON syntax without changing the recorded decision, then retry`,e)}let o=at(a,n);if(o.cwd!==j(t)||n!==rt(e,t,o.canonicalTrustPath))throw new W(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 st(e,t){let{record:n,path:r}=t;for(let t of[U(e),nt(e,n.cwd)])if(!K(t))throw new W(t,`no longer exists`,`restore access to the expected receipt directory, then retry`);let i=ot(e,n.cwd,r);if(!Ie(i.record,n))throw new W(r,`changed while its trust decision was being updated`,`retry to read its current ownership record`);return i}function ct(e,t,n,r,i){let a={version:1,cwd:j(t),configuredTrustPath:j(n),canonicalTrustPath:j(r),state:`pending`,previous:i},o=rt(e,a.cwd,a.canonicalTrustPath),s=`${JSON.stringify(a,null,2)}\n`;if(!Ie(at(JSON.parse(s),o),a))throw new W(o,`cannot preserve the previous decision as JSON`,`provide the original decision as a JSON value before retrying`);K(U(e)),K(k(o));try{ke(k(o),{recursive:!0,mode:448})}catch(e){throw G(k(o),`be created`,e)}let c;try{c=P(o,{throwIfNoEntry:!1})}catch(e){throw G(o,`be inspected`,e)}if(c)throw new W(o,`already exists`,`reconcile the existing ownership record before recording another grant`);try{S(o,s,{mode:384})}catch(e){throw G(o,`be written`,e)}return{path:o,record:a}}function lt(e,t){let n=st(e,t);if(n.record.state!==`pending`)throw new W(n.path,`is already committed`,`use the current ownership record without committing it again`);let r={...n.record,state:`committed`};try{S(n.path,`${JSON.stringify(r,null,2)}\n`,{mode:384})}catch(e){throw G(n.path,`be committed`,e)}return{path:n.path,record:r}}function q(e,t){if(!K(U(e)))return[];let n=nt(e,t);if(!K(n))return[];let r;try{r=I(n).sort()}catch(e){throw G(n,`be listed`,e)}return r.filter(e=>/^[a-f0-9]{64}\.json$/.test(e)).map(r=>ot(e,t,A(n,r)))}function J(e,t){let n=st(e,t);try{Me(n.path)}catch(e){throw G(n.path,`be removed after reconciling its grant`,e)}for(let t of[k(n.path),U(e)])try{je(t)}catch(e){let n=e.code;if(n!==`ENOTEMPTY`&&n!==`EEXIST`&&n!==`ENOENT`)throw G(t,`be removed after reconciling its grant`,e)}}var ut=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`)}}})),dt=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())}}})),ft=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}})),pt=n(((t,n)=>{var r=e(`fs`),i=ut(),a=dt(),o=ft(),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(`
1
+ import{i as e,o as t,t as n}from"./rolldown-runtime-tZXQYakl.mjs";import{C as r,E as i,L as a,M as o,N as s,P as c,w as l,x as u}from"./constants-ok-dir-DZ25OS9-.mjs";import{$d as d,Qd as f,Xd as p,Ya as m,pd as h,tf as g}from"./md-manager-BGnqyqi1-DCCfgLfC.mjs";import{Ms as _,Ns as v,Oa as y,Vo as ee,m as b,ns as te,tr as x}from"./dist-BSNy29T3.mjs";import{s as S,y as ne}from"./fs-find-project-root-BYV07wjn.mjs";import{A as re,B as ie,E as C,F as ae,M as w,N as T,S as oe,T as se,Y as ce,Z as E,at as le,b as ue,et as de,f as fe,ft as pe,it as me,j as he,k as D,lt as ge,nt as _e,ot as ve,p as ye,rt as be,s as xe,ut as Se,y as Ce}from"./init-DZf66ZMB.mjs";import{o as we}from"./token-store-Bmb3_0hU.mjs";import{t as Te}from"./is-object-BGze3w87.mjs";import{t as Ee}from"./removal-file-path-wBKXFJo1.mjs";import{basename as O,dirname as k,join as A,resolve as j,win32 as De}from"node:path";import{accessSync as Oe,constants as M,existsSync as N,lstatSync as P,mkdirSync as ke,readFileSync as F,readdirSync as I,realpathSync as L,rmSync as Ae,rmdirSync as je,statSync as R,unlinkSync as Me}from"node:fs";import{homedir as z}from"node:os";import{createHash as Ne}from"node:crypto";import{spawn as Pe}from"node:child_process";import{setTimeout as Fe}from"node:timers/promises";import{isDeepStrictEqual as Ie}from"node:util";function Le(e){let t={...e};return delete t.ELECTRON_RUN_AS_NODE,t}function Re(e){let t=e?.code;return t===`ENOENT`||t===`EACCES`||t===`EPERM`?{ok:!1,reason:`not-installed`}:{ok:!1,reason:`spawn-error`}}function ze(e){return ee({detached:!0,stdio:`ignore`,shell:!1,env:Le(e)})}function Be(e,t,n={}){let r=(n.spawn??Pe)(e,[...t],ze(n.env??process.env));return r.unref(),r}function Ve(e,t,n={}){let r=n.spawn??Pe,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],ze(n.env??process.env));i.once(`error`,e=>{clearTimeout(c),s(Re(e))}),i.once(`spawn`,()=>{clearTimeout(c),s({ok:!0})});try{i.unref()}catch{}}catch(e){clearTimeout(c),s(Re(e))}})}const He=r.stable.appId,B=i,Ue=[`stable`,`beta`];function We(e,t,n=e=>console.error(e)){try{return a(e,t)}catch(r){let i=a({...e,[l]:void 0},t);return n(`Treating this CLI as ${o(i)} for this command: ${r instanceof Error?r.message:String(r)}`),i}}function V(e){return Ue.includes(e)||!B.includes(e)?Ue:[e,...Ue]}function Ge(e){return e.bundlePath===void 0?null:{bundlePath:e.bundlePath,protocolScheme:r[e.product].protocolScheme}}function Ke(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return R(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function qe(e,t){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let n=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(n?.[1]){let e=n[1];return{path:e,product:B.find(t=>e.endsWith(`/${r[t].productName}.app`))??t}}}let n=e.homeDir??z();for(let i of V(t)){let{productName:t}=r[i];for(let r of[A(n,`Applications`),`/Applications`]){let n=A(r,`${t}.app`);if(Je(e,A(n,`Contents`,`MacOS`,t)))return{path:n,product:i}}}return null}function Je(e,t){try{let n=e.statSync(t);return n?typeof n.isFile==`function`&&n.isFile():!1}catch{return!1}}function Ye(e,t){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=B.find(t=>e.execPath.toLowerCase().endsWith(`\\${s(r[t]).toLowerCase()}`));if(t)return{path:e.execPath,product:t}}let n=e.env.LOCALAPPDATA;if(n)for(let i of V(t))for(let t of c(r[i])){let a=De.join(n,`Programs`,t,s(r[i]));if(Je(e,a))return{path:a,product:i}}return null}function Xe(e,t){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=B.find(t=>e.execPath.endsWith(`/${r[t].linuxExecutableName}`));if(t)return{path:e.execPath,product:t}}for(let n of V(t)){let{productName:t,linuxExecutableName:i}=r[n],a=`/opt/${t}/${i}`;if(Je(e,a))return{path:a,product:n}}return null}function Ze(e){let t=We(e.env,e.execPath,e.warn);if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`,cliProduct:t};if(e.platform!==`darwin`&&e.platform!==`win32`&&e.platform!==`linux`)return{available:!1,reason:`unsupported-platform`,cliProduct:t};let n;try{n=e.platform===`darwin`?qe(e,t):e.platform===`win32`?Ye(e,t):Xe(e,t)}catch{return{available:!1,reason:`stat-error`,cliProduct:t}}if(!n)return{available:!1,reason:`no-bundle`,cliProduct:t};let r={bundlePath:n.path,product:n.product,cliProduct:t};return e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,...r}:!(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`,...r}:{available:!0,reason:`available`,...r}}function Qe(e,t){let n=e.log??(e=>console.error(e)),i=e.platform??process.platform;if(t.bundlePath===void 0){n(`Desktop launch skipped: no resolved desktop executable (caller bug).`);return}let{productName:a}=r[t.product],[o]=r[t.cliProduct].cliCommandNames;n(`Launching ${a} desktop (use \`${o} start\` for the browser server, or \`OK_FORCE_BROWSER=1\` to always skip)`);let s=t.bundlePath;if(i===`darwin`){Be(`open`,[`-a`,s],{spawn:e.spawn});return}Be(s,[],{spawn:e.spawn})}function $e(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).`}}var et=u();function H(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 tt(e){return Ne(`sha256`).update(e).digest(`hex`)}function U(e){return A(ne(j(e)),`pi-trust`)}function nt(e,t){return A(U(e),tt(j(t)))}function rt(e,t,n){return A(nt(e,t),`${tt(n)}.json`)}var W=class extends Error{constructor(e,t,n,r){super(`Pi trust receipt at ${H(e)} ${H(t)}; ${H(n)}`,{cause:r}),this.name=`PiTrustReceiptError`}};function G(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 W(e,`could not ${t}: ${i}`,a,n)}function K(e){let t;try{t=P(e)}catch(t){if(t.code===`ENOENT`)return!1;throw G(e,`be inspected`,t)}if(!t.isDirectory())throw new W(e,`is not a regular directory`,`restore the intended receipt directory without a symlink, then retry`);return!0}function it(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}function at(e,t){if(!Te(e)||!it(e,[`version`,`cwd`,`configuredTrustPath`,`canonicalTrustPath`,`state`,`previous`])||e.version!==1||typeof e.cwd!=`string`||e.cwd!==j(e.cwd)||typeof e.configuredTrustPath!=`string`||e.configuredTrustPath!==j(e.configuredTrustPath)||typeof e.canonicalTrustPath!=`string`||e.canonicalTrustPath!==j(e.canonicalTrustPath)||e.state!==`pending`&&e.state!==`committed`||!Te(e.previous))throw new W(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&&it(e.previous,[`present`]))n={present:!1};else if(e.previous.present===!0&&it(e.previous,[`present`,`value`]))n={present:!0,value:e.previous.value};else throw new W(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 ot(e,t,n){let r;try{r=P(n)}catch(e){throw G(n,`be inspected`,e)}if(!r.isFile())throw new W(n,`is not a regular file`,`restore the intended receipt as a regular file without a symlink, then retry`);let i;try{i=F(n,`utf8`)}catch(e){throw G(n,`be read`,e)}let a;try{a=JSON.parse(i)}catch(e){throw new W(n,`is not valid JSON`,`repair its JSON syntax without changing the recorded decision, then retry`,e)}let o=at(a,n);if(o.cwd!==j(t)||n!==rt(e,t,o.canonicalTrustPath))throw new W(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 st(e,t){let{record:n,path:r}=t;for(let t of[U(e),nt(e,n.cwd)])if(!K(t))throw new W(t,`no longer exists`,`restore access to the expected receipt directory, then retry`);let i=ot(e,n.cwd,r);if(!Ie(i.record,n))throw new W(r,`changed while its trust decision was being updated`,`retry to read its current ownership record`);return i}function ct(e,t,n,r,i){let a={version:1,cwd:j(t),configuredTrustPath:j(n),canonicalTrustPath:j(r),state:`pending`,previous:i},o=rt(e,a.cwd,a.canonicalTrustPath),s=`${JSON.stringify(a,null,2)}\n`;if(!Ie(at(JSON.parse(s),o),a))throw new W(o,`cannot preserve the previous decision as JSON`,`provide the original decision as a JSON value before retrying`);K(U(e)),K(k(o));try{ke(k(o),{recursive:!0,mode:448})}catch(e){throw G(k(o),`be created`,e)}let c;try{c=P(o,{throwIfNoEntry:!1})}catch(e){throw G(o,`be inspected`,e)}if(c)throw new W(o,`already exists`,`reconcile the existing ownership record before recording another grant`);try{S(o,s,{mode:384})}catch(e){throw G(o,`be written`,e)}return{path:o,record:a}}function lt(e,t){let n=st(e,t);if(n.record.state!==`pending`)throw new W(n.path,`is already committed`,`use the current ownership record without committing it again`);let r={...n.record,state:`committed`};try{S(n.path,`${JSON.stringify(r,null,2)}\n`,{mode:384})}catch(e){throw G(n.path,`be committed`,e)}return{path:n.path,record:r}}function q(e,t){if(!K(U(e)))return[];let n=nt(e,t);if(!K(n))return[];let r;try{r=I(n).sort()}catch(e){throw G(n,`be listed`,e)}return r.filter(e=>/^[a-f0-9]{64}\.json$/.test(e)).map(r=>ot(e,t,A(n,r)))}function J(e,t){let n=st(e,t);try{Me(n.path)}catch(e){throw G(n.path,`be removed after reconciling its grant`,e)}for(let t of[k(n.path),U(e)])try{je(t)}catch(e){let n=e.code;if(n!==`ENOTEMPTY`&&n!==`EEXIST`&&n!==`ENOENT`)throw G(t,`be removed after reconciling its grant`,e)}}var ut=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`)}}})),dt=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())}}})),ft=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}})),pt=n(((t,n)=>{var r=e(`fs`),i=ut(),a=dt(),o=ft(),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(`
2
2
  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,x=g.WriteStream}var _=e.ReadStream;_&&(b.prototype=Object.create(_.prototype),b.prototype.open=te);var v=e.WriteStream;v&&(x.prototype=Object.create(v.prototype),x.prototype.open=S),Object.defineProperty(e,"ReadStream",{get:function(){return b},set:function(e){b=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return x},set:function(e){x=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=x;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 te(){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 x(e,t){return this instanceof x?(v.apply(this,arguments),this):x.apply(Object.create(x.prototype),arguments)}function S(){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))}}})),mt=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}})),ht=n((e=>{var t=mt();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}}})),gt=n(((e,t)=>{t.exports=ht()})),_t=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`)})),vt=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=_t(),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)}}})),yt=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})),bt=n(((t,n)=>{let r=e(`path`),i=pt(),a=gt(),o=vt(),s=yt(),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})),xt=n(((e,t)=>{let n=pt();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}})),St=t(n(((e,t)=>{let n=bt(),{toPromise:r,toSync:i,toSyncOptions:a}=xt();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 Ct=5e3;function wt(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 ${Ct}ms`,{cause:e}),{code:`ELOCKED`});return Math.min(25,r)}function Tt(e,t){we()?.warn(t,e)}function Et(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 Dt(e,t,n){await _(`${t}.ok.lock`,async()=>{let t=performance.now()+Ct,r;for(;;)try{r=await St.default.lock(k(e),{realpath:!1,lockfilePath:`${e}.lock`});break}catch(n){await Fe(wt(n,t,e))}let i=[];try{n()}catch(e){i.push(e)}finally{try{await r()}catch(e){i.push(e)}}Et(i,e)},{onWarn:Tt})}function Ot(e,t,n){v(`${t}.ok.lock`,()=>{let t=performance.now()+Ct,r=new Int32Array(new SharedArrayBuffer(4)),i;for(;;)try{i=St.default.lockSync(k(e),{realpath:!1,lockfilePath:`${e}.lock`});break}catch(n){Atomics.wait(r,0,0,wt(n,t,e))}let a=[];try{n()}catch(e){a.push(e)}finally{try{i()}catch(e){a.push(e)}}Et(a,e)},{onWarn:Tt})}const kt=[`settings.json`,`prompts`,`themes`,`SYSTEM.md`,`APPEND_SYSTEM.md`];var At=class extends Error{name=`PiResourceInspectionError`};function Y(e){let t;try{t=P(e)}catch(e){if(e.code===`ENOENT`)return!1;throw e}let n;try{n=R(e)}catch(e){throw t.isSymbolicLink()&&e.code===`ENOENT`?new At(w(`missing-symlink-target`),{cause:e}):e}return Oe(e,M.R_OK|(n.isDirectory()?M.X_OK:0)),!0}function jt(e){return e===`open-knowledge`||e.startsWith(`open-knowledge-`)}function Mt(e,t,n){let r=e;try{let i=L(e),a;r=t;try{a=L(t)}catch(e){if(e.code!==`ENOENT`)throw e;a=j(t)}let o=A(a,`.agents`,`skills`),s=[];for(let e of kt)r=A(i,`.pi`,e),Y(r)&&s.push(r);if(r=A(i,`.pi`,`extensions`),Y(r))for(let t of I(r).sort()){let i=A(r,t);j(n)!==A(j(e),`.pi`,`extensions`,t)&&s.push(i)}for(let e of[A(i,`.pi`,`skills`),A(i,`.agents`,`skills`)])if(e!==o&&(r=e,Y(e)))for(let t of I(e).sort())jt(t)||s.push(A(e,t));let c=k(i);for(;c!==i;){r=A(c,`.agents`,`skills`),r!==o&&Y(r)&&s.push(r);let e=k(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 ${H(r)}: ${e instanceof At?e.message:w(T(e))}`}}}function Nt(e,t,n){let r=j(e),i=ge({home:t,env:n??(t===void 0?process.env:{})});return{cwd:r,bridgePath:E.pi.projectConfigPath(r),trustPath:A(i,`trust.json`)}}function X(e){try{let t=L(e);return R(t).isDirectory()?(Oe(t,M.X_OK),{kind:`ready`,project:{path:e,canonical:t}}):{kind:`refused`,error:`Pi project path ${H(e)} is not a directory; restore the intended project directory, then retry`}}catch(t){return{kind:`refused`,error:`Pi project directory ${H(e)} could not be resolved or accessed: ${H(t instanceof Error?t.message:String(t))}; restore the directory or symlink and check its permissions, then retry`}}}function Pt(e){let t=X(e.path);if(t.kind===`refused`)return t.error;if(t.project.canonical!==e.canonical)return`Pi project path ${H(e.path)} changed while waiting for its trust lock; restore the intended project location, then retry`}function Ft(e,t,n){let r=xe(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 me(i)?{state:`own-current`,text:a}:C(i)?{state:`own-stale`,text:a}:{state:`foreign`,text:a}}function It(e,t){let n;try{n=F(e.path,`utf-8`)}catch(t){let n=t.code;return e.kind===`missing`&&n===`ENOENT`?{state:`untrusted`,entries:{},trailingNewline:!1}:{state:`unreadable`,reason:T(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 Te(r)?{state:r[t]===!0?`trusted`:`untrusted`,entries:r,trailingNewline:n.endsWith(`
3
3
  `)}:{state:`unreadable`,reason:`invalid-json`}}function Lt(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 w(e)}}function Z(e,t){return{kind:`refused`,error:`trust store ${H(e)}: ${Lt(t)}`}}function Q(e){let t=Ee(e);try{switch(t.kind){case`declined`:return Z(e,t.reason);case`ready`:return{kind:`ready`,path:L(t.path)};case`not-present`:break;default:throw Error(`unhandled trust file resolution: ${t}`)}let n=k(e),r=[O(e)],i=P(n,{throwIfNoEntry:!1});for(;!i;){let t=k(n);if(t===n)return Z(e,`unavailable-root`);r.unshift(O(n)),n=t,i=P(n,{throwIfNoEntry:!1})}try{return{kind:`missing`,path:A(L(n),...r)}}catch(t){return Z(e,i.isSymbolicLink()&&t.code===`ENOENT`?`missing-symlink-target`:T(t))}}catch(t){return Z(e,T(t))}}function Rt(e,t){let n=Q(e);return n.kind===`refused`?n:n.path!==t.path||t.kind===`ready`&&n.kind===`missing`?Z(e,`path-changed`):n}function zt(e,t,n){let r=Nt(e,t,n),i=X(r.cwd);if(i.kind===`refused`)return{...r,project:`unavailable`,error:i.error};let a=Ft(r.cwd,r.bridgePath,t).state,o=Q(r.trustPath),s=o.kind===`refused`?`unreadable`:o.kind===`missing`?`untrusted`:It(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:Bt(r.bridgePath).displayNames}}function Bt(e){let t=k(e),n=O(e);try{return{displayNames:I(t).filter(e=>e!==n&&e.endsWith(`.ts`)).sort().map(e=>H(JSON.stringify(e)))}}catch{return{displayNames:[]}}}async function Vt(e,t={mode:`published`},n,r,i){let a=Nt(e,n,r),o=X(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 ${H(i)} no longer matches the current directory ${H(o.project.canonical)}. Reopen the intended project and approve the Pi integration again; no bridge or trust settings were changed.`};let s=Ft(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=se(t)}catch{e=void 0}c=e!==void 0&&s.text===e?`unchanged`:`refreshed`}if(c!==`unchanged`){let e=ue(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}`:H(e.error)}}let l=await Ht(a.trustPath,o.project,n??z());return{...a,ok:l.action===`already-trusted`||l.action===`added`,bridge:c,trust:l.action,...l.error===void 0?{}:{error:l.error}}}async function Ht(e,t,n){let r=t.canonical,i=Q(e);if(i.kind===`refused`)return{action:`refused-unreadable`,error:i.error};try{ke(k(i.path),{recursive:!0})}catch(e){return{action:`failed`,error:H(e instanceof Error?e.message:String(e))}}let a={action:`added`};try{await Dt(e,i.path,()=>{let o=Pt(t);if(o){a.action=`refused-unreadable`,a.error=o;return}let s=Rt(e,i);if(s.kind===`refused`){a.action=`refused-unreadable`,a.error=s.error;return}let c=It(s,r);if(c.state===`trusted`){a.action=`already-trusted`;return}if(c.state===`unreadable`){a.action=`refused-unreadable`,a.error=Z(e,c.reason).error;return}let l=$(n,()=>{let t=q(n,r).find(e=>e.record.canonicalTrustPath===s.path);return t&&J(n,t),ct(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?`
4
4
  `:``),f=D(s.path);S(s.path,d,f===void 0?void 0:{mode:f}),$(n,()=>lt(n,l)),a.action=`added`})}catch(e){return{action:`failed`,error:H(e instanceof Error?e.message:String(e))}}return a}function Ut(e){let t=[],n=e;try{for(;;){if(P(n,{throwIfNoEntry:!1})){if(t.length===0)return;let e=L(n);return R(e).isDirectory()?(Oe(e,M.X_OK),A(e,...t)):void 0}let e=k(n);if(e===n)return;t.unshift(O(n)),n=e}}catch{return}}function Wt(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(`
@@ -13,4 +13,4 @@ GFS4: `),console.error(e)}),r[c]||(d(r,global[c]||[]),r.close=(function(e){funct
13
13
  `),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(`
14
14
  `)||(l=`${l}\n`):l=l.replace(/\n+$/,``),o&&(l=l.replace(/\r\n/g,`
15
15
  `).replace(/\n/g,`\r
16
- `));let u=`${i?``:``}${l}`;return u!==r&&S(e,u,{mode:D(e)}),{kind:`removed`}}function nn(e,t){let n=h[e];return n===null?null:A(t,...n.split(`/`),b.discovery,`SKILL.md`)}function rn(e,t){let n=nn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};if(!x(t).some(t=>t.editorId===e))return{editorId:e,label:e,action:`skipped-unsupported`,path:n};try{let r=y(`discovery`,{checkDesktop:!0});return ae(k(n),t),{editorId:e,label:e,action:ie(r,n),path:n}}catch(t){return{editorId:e,label:e,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function an(e){return N(A(e,...`.agents/skills`.split(`/`),b.discovery))?!0:g.some(t=>{let n=nn(t,e);return n!==null&&N(k(n))})}function on(e,t){let n=nn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};let r=k(n);try{return N(n)?(ae(r,t),Ae(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 sn(e){return e===`opencode`?ve:be}function cn(e,t,n){let r=E[e],i=sn(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=ye(r,t,n,o.configPath);if(a!==null&&i(a))return{editorId:e,scope:o.scope,configPath:o.configPath}}return null}function ln(e,t,n=[]){let r=N(A(e,b[t]))?`satisfied`:`absent`;return{...r===`satisfied`?{state:r,strictness:[`reclaim-permissive`]}:{state:r},...n.length===0?{}:{sharedWith:n}}}function un(e,t){let n=ce.flatMap(t=>{let n=e[t];return n===null?[]:[{editor:t,root:n}]}),r=m.filter(e=>e.scope===t).map(e=>({editor:e.editorId,root:d}));return[...n,...r]}function dn(e,t,n,r){let i=te(e,un(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 fn(e,t){let n=(t??z()).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 pn(e,t){let n=E[e];return oe(n,``,t)&&!fe(n,``,t)}function mn(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?fn(o,r):void 0,c=xe(a,n,r,i);switch(c.kind){case`absent`:case`no-entry`:return i===void 0&&pn(e,r)?{state:`structural-na`}:{state:`absent`,path:s};case`decline`:return{state:`unprobed`};case`present`:{let{entry:r}=c,i=[];me(r)&&i.push(`reclaim-permissive`),le(r)&&i.push(`pre-approval-exact`),sn(e)(r)&&i.push(`injection-functional`);let o=de(a,n);return i.length>0&&(o!==null&&_e(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}:Se(a)?{state:`foreign-replaceable`,path:s}:{state:`foreign`,path:s}}}}function hn(e){let{cwd:t,home:n}=e;return e=>{if(e.pathId===null)return null;let r=p(e.pathId);if(r===null)return null;if(r.kind===`central-skill-store`)return n===void 0?null:ln(A(n,d),`discovery`,dn(n,h,e.agent,`global`));let i=r.editor;switch(r.kind){case`editor-user-skill-root`:{let e=h[i];return e===null||n===void 0?null:x(n).some(e=>e.editorId===i)?ln(A(n,e),`discovery`,dn(n,h,i,`global`)):{state:`structural-na`}}case`editor-project-skill-root`:{let e=f[i];return e===null?null:ln(A(t,e),`project`,dn(t,f,i,`project`))}case`editor-user-config`:return mn(i,e.strictness,t,n);case`editor-project-config`:{let r=E[i].projectConfigPath?.(t);return r===void 0?null:mn(i,e.strictness,t,n,r)}}}}export{We as _,rn as a,zt as c,Ke as d,Ge as f,$e as g,Qe as h,an as i,H as l,Ze as m,cn as n,Qt as o,V as p,on as r,Vt as s,hn as t,He as u,Be as v,Ve as y};
16
+ `));let u=`${i?``:``}${l}`;return u!==r&&S(e,u,{mode:D(e)}),{kind:`removed`}}function nn(e,t){let n=d[e];return n===null?null:A(t,...n.split(`/`),b.discovery,`SKILL.md`)}function rn(e,t){let n=nn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};if(!x(t).some(t=>t.editorId===e))return{editorId:e,label:e,action:`skipped-unsupported`,path:n};try{let r=y(`discovery`,{checkDesktop:!0});return ae(k(n),t),{editorId:e,label:e,action:ie(r,n),path:n}}catch(t){return{editorId:e,label:e,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function an(e){return N(A(e,...`.agents/skills`.split(`/`),b.discovery))?!0:p.some(t=>{let n=nn(t,e);return n!==null&&N(k(n))})}function on(e,t){let n=nn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};let r=k(n);try{return N(n)?(ae(r,t),Ae(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 sn(e){return e===`opencode`?ve:be}function cn(e,t,n){let r=E[e],i=sn(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=ye(r,t,n,o.configPath);if(a!==null&&i(a))return{editorId:e,scope:o.scope,configPath:o.configPath}}return null}function ln(e,t,n=[]){let r=N(A(e,b[t]))?`satisfied`:`absent`;return{...r===`satisfied`?{state:r,strictness:[`reclaim-permissive`]}:{state:r},...n.length===0?{}:{sharedWith:n}}}function un(e,t){let n=ce.flatMap(t=>{let n=e[t];return n===null?[]:[{editor:t,root:n}]}),r=g.filter(e=>e.scope===t).map(e=>({editor:e.editorId,root:m}));return[...n,...r]}function dn(e,t,n,r){let i=te(e,un(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 fn(e,t){let n=(t??z()).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 pn(e,t){let n=E[e];return oe(n,``,t)&&!fe(n,``,t)}function mn(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?fn(o,r):void 0,c=xe(a,n,r,i);switch(c.kind){case`absent`:case`no-entry`:return i===void 0&&pn(e,r)?{state:`structural-na`}:{state:`absent`,path:s};case`decline`:return{state:`unprobed`};case`present`:{let{entry:r}=c,i=[];me(r)&&i.push(`reclaim-permissive`),le(r)&&i.push(`pre-approval-exact`),sn(e)(r)&&i.push(`injection-functional`);let o=de(a,n);return i.length>0&&(o!==null&&_e(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}:Se(a)?{state:`foreign-replaceable`,path:s}:{state:`foreign`,path:s}}}}function hn(e){let{cwd:t,home:n}=e;return e=>{if(e.pathId===null)return null;let r=h(e.pathId);if(r===null)return null;if(r.kind===`central-skill-store`)return n===void 0?null:ln(A(n,m),`discovery`,dn(n,d,e.agent,`global`));let i=r.editor;switch(r.kind){case`editor-user-skill-root`:{let e=d[i];return e===null||n===void 0?null:x(n).some(e=>e.editorId===i)?ln(A(n,e),`discovery`,dn(n,d,i,`global`)):{state:`structural-na`}}case`editor-project-skill-root`:{let e=f[i];return e===null?null:ln(A(t,e),`project`,dn(t,f,i,`project`))}case`editor-user-config`:return mn(i,e.strictness,t,n);case`editor-project-config`:{let r=E[i].projectConfigPath?.(t);return r===void 0?null:mn(i,e.strictness,t,n,r)}}}}export{We as _,rn as a,zt as c,Ke as d,Ge as f,$e as g,Qe as h,an as i,H as l,Ze as m,cn as n,Qt as o,V as p,on as r,Vt as s,hn as t,He as u,Be as v,Ve as y};
@@ -1 +1 @@
1
- import{C as e,N as t}from"./init-BJM0tqDo.mjs";import{lstatSync as n,statSync as r}from"node:fs";function i(i){let a;try{a=n(i).isSymbolicLink()}catch(e){return e.code===`ENOENT`?{kind:`not-present`}:{kind:`declined`,reason:t(e)}}let o=e(i);if(o.readPath===null)return{kind:`declined`,reason:`unresolved-symlink`};try{if(!r(o.readPath).isFile())return{kind:`declined`,reason:`not-a-file`}}catch(e){return{kind:`declined`,reason:a&&e.code===`ENOENT`?`missing-symlink-target`:t(e)}}return{kind:`ready`,path:o.writePath,symlink:a}}export{i as t};
1
+ import{C as e,N as t}from"./init-DZf66ZMB.mjs";import{lstatSync as n,statSync as r}from"node:fs";function i(i){let a;try{a=n(i).isSymbolicLink()}catch(e){return e.code===`ENOENT`?{kind:`not-present`}:{kind:`declined`,reason:t(e)}}let o=e(i);if(o.readPath===null)return{kind:`declined`,reason:`unresolved-symlink`};try{if(!r(o.readPath).isFile())return{kind:`declined`,reason:`not-a-file`}}catch(e){return{kind:`declined`,reason:a&&e.code===`ENOENT`?`missing-symlink-target`:t(e)}}return{kind:`ready`,path:o.writePath,symlink:a}}export{i as t};
@@ -1 +1 @@
1
- import{t as e}from"./launch-json-removal-DzsPe2PB.mjs";import{join as t}from"node:path";function n(n){let i=n.logger??r,a=t(n.projectDir,`.claude`,`launch.json`);if(n.reclaimDisableEnv===`1`)return i({event:`launch-json-repair-skipped`,severity:`info`,reason:`reclaim-disabled`}),{outcome:{configPath:a,outcome:`skipped-reclaim-disabled`},repairedCount:0};let o;try{o=(n.removeOwnLaunchEntryFn??e)(n.projectDir)}catch(e){let t=e instanceof Error?e.message:String(e);return i({event:`launch-json-repair-write-failed`,severity:`warn`,configPath:a}),{outcome:{configPath:a,outcome:`write-failed`,error:t},repairedCount:0}}let s=o.kind===`removed`;return s&&i({event:`launch-json-repair-removed`,severity:`info`,configPath:a}),{outcome:{configPath:a,outcome:o.kind},repairedCount:+!!s}}function r(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{n as repairLaunchJson};
1
+ import{t as e}from"./launch-json-removal-Bnn4Q8Q5.mjs";import{join as t}from"node:path";function n(n){let i=n.logger??r,a=t(n.projectDir,`.claude`,`launch.json`);if(n.reclaimDisableEnv===`1`)return i({event:`launch-json-repair-skipped`,severity:`info`,reason:`reclaim-disabled`}),{outcome:{configPath:a,outcome:`skipped-reclaim-disabled`},repairedCount:0};let o;try{o=(n.removeOwnLaunchEntryFn??e)(n.projectDir)}catch(e){let t=e instanceof Error?e.message:String(e);return i({event:`launch-json-repair-write-failed`,severity:`warn`,configPath:a}),{outcome:{configPath:a,outcome:`write-failed`,error:t},repairedCount:0}}let s=o.kind===`removed`;return s&&i({event:`launch-json-repair-removed`,severity:`info`,configPath:a}),{outcome:{configPath:a,outcome:o.kind},repairedCount:+!!s}}function r(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{n as repairLaunchJson};
@@ -1 +1 @@
1
- import{E as e}from"./md-manager-BGnqyqi1-B5Gyjk_N.mjs";import{Y as t,Z as n,b as r,et as i,it as a,p as o,tt as s}from"./init-BJM0tqDo.mjs";import{homedir as c}from"node:os";function l(e){let{priorCommand:t,priorArgs:n}=u(e.priorEntry);return{event:`mcp-config-migrate`,scope:e.scope,surface:e.surface,editorId:e.editorId,configPath:e.configPath,priorCommand:t,priorArgs:n}}function u(e){return{priorCommand:typeof e.command==`string`?e.command.slice(0,200):null,priorArgs:Array.isArray(e.args)?e.args.slice(0,10).map(e=>typeof e==`string`?e.slice(0,200):e):null}}function d(e){let r=e.logger??h,i=e.home??c(),a=[];if(e.reclaimDisableEnv===`1`)return r({event:`mcp-config-repair-skipped`,severity:`info`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of t){let t=n[o],s=f(()=>t.configPath(``,i));if(s!==null&&a.push(p({scope:`user`,editorId:o,target:t,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:r})),t.projectConfigPath){let n=t.projectConfigPath,i=f(()=>n(e.projectDir));i!==null&&a.push(p({scope:`project`,editorId:o,target:t,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:r}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function f(e){try{return e()}catch{return null}}function p(t){let n={scope:t.scope,editorId:t.editorId,configPath:t.configPath},c=o(t.target,t.cwd,t.home,t.configPathOverride);if(c===null)return{...n,outcome:`no-entry`};if(t.target.format===`file`){if(a(c))return{...n,outcome:`canonical`}}else{let a=e(c);if(a.kind===`recognized`&&a.disposition===`keep`){let e=s(c,i(t.target,t.cwd));if(e.length===0)return{...n,outcome:`canonical`};let a=m(t,n,r(t.target,t.cwd,{mode:`published`,skipAvailabilityCheck:!0,pruneOnly:!0},t.home,t.configPathOverride));return(a.outcome===`repaired`||a.outcome===`canonical`)&&t.logger({event:a.outcome===`repaired`?`mcp-config-repair-pruned`:`mcp-config-repair-prune-unchanged`,severity:a.outcome===`repaired`?`info`:`warn`,scope:t.scope,editorId:t.editorId,configPath:t.configPath,keys:e}),a.outcome===`canonical`?{...n,outcome:`prune-unchanged`}:a}if(a.kind===`declined`&&t.scope===`project`)return t.logger({event:`mcp-config-repair-skipped-foreign`,severity:`info`,scope:t.scope,editorId:t.editorId,configPath:t.configPath,reason:a.reason}),{...n,outcome:`foreign`,reason:a.reason}}return t.logger({...l({scope:t.scope,surface:`cli-repair`,editorId:t.editorId,configPath:t.configPath,priorEntry:c}),severity:`info`}),m(t,n,r(t.target,t.cwd,{mode:`published`,skipAvailabilityCheck:!0},t.home,t.configPathOverride))}function m(e,t,n){if(n.action===`failed`){let r=n.error??`unknown write failure`;return e.logger({event:`mcp-config-repair-write-failed`,severity:`warn`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,error:r}),{...t,outcome:`write-failed`,error:r}}return n.action===`declined`?(e.logger({event:`mcp-config-repair-declined`,severity:`warn`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,reason:n.declineReason}),{...t,outcome:`declined`,reason:n.declineReason}):n.action===`skipped-flag`?{...t,outcome:`canonical`}:{...t,outcome:`repaired`}}function h(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{u as n,d as repairMcpConfigs,l as t};
1
+ import{E as e}from"./md-manager-BGnqyqi1-DCCfgLfC.mjs";import{Y as t,Z as n,b as r,et as i,it as a,p as o,tt as s}from"./init-DZf66ZMB.mjs";import{homedir as c}from"node:os";function l(e){let{priorCommand:t,priorArgs:n}=u(e.priorEntry);return{event:`mcp-config-migrate`,scope:e.scope,surface:e.surface,editorId:e.editorId,configPath:e.configPath,priorCommand:t,priorArgs:n}}function u(e){return{priorCommand:typeof e.command==`string`?e.command.slice(0,200):null,priorArgs:Array.isArray(e.args)?e.args.slice(0,10).map(e=>typeof e==`string`?e.slice(0,200):e):null}}function d(e){let r=e.logger??h,i=e.home??c(),a=[];if(e.reclaimDisableEnv===`1`)return r({event:`mcp-config-repair-skipped`,severity:`info`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of t){let t=n[o],s=f(()=>t.configPath(``,i));if(s!==null&&a.push(p({scope:`user`,editorId:o,target:t,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:r})),t.projectConfigPath){let n=t.projectConfigPath,i=f(()=>n(e.projectDir));i!==null&&a.push(p({scope:`project`,editorId:o,target:t,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:r}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function f(e){try{return e()}catch{return null}}function p(t){let n={scope:t.scope,editorId:t.editorId,configPath:t.configPath},c=o(t.target,t.cwd,t.home,t.configPathOverride);if(c===null)return{...n,outcome:`no-entry`};if(t.target.format===`file`){if(a(c))return{...n,outcome:`canonical`}}else{let a=e(c);if(a.kind===`recognized`&&a.disposition===`keep`){let e=s(c,i(t.target,t.cwd));if(e.length===0)return{...n,outcome:`canonical`};let a=m(t,n,r(t.target,t.cwd,{mode:`published`,skipAvailabilityCheck:!0,pruneOnly:!0},t.home,t.configPathOverride));return(a.outcome===`repaired`||a.outcome===`canonical`)&&t.logger({event:a.outcome===`repaired`?`mcp-config-repair-pruned`:`mcp-config-repair-prune-unchanged`,severity:a.outcome===`repaired`?`info`:`warn`,scope:t.scope,editorId:t.editorId,configPath:t.configPath,keys:e}),a.outcome===`canonical`?{...n,outcome:`prune-unchanged`}:a}if(a.kind===`declined`&&t.scope===`project`)return t.logger({event:`mcp-config-repair-skipped-foreign`,severity:`info`,scope:t.scope,editorId:t.editorId,configPath:t.configPath,reason:a.reason}),{...n,outcome:`foreign`,reason:a.reason}}return t.logger({...l({scope:t.scope,surface:`cli-repair`,editorId:t.editorId,configPath:t.configPath,priorEntry:c}),severity:`info`}),m(t,n,r(t.target,t.cwd,{mode:`published`,skipAvailabilityCheck:!0},t.home,t.configPathOverride))}function m(e,t,n){if(n.action===`failed`){let r=n.error??`unknown write failure`;return e.logger({event:`mcp-config-repair-write-failed`,severity:`warn`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,error:r}),{...t,outcome:`write-failed`,error:r}}return n.action===`declined`?(e.logger({event:`mcp-config-repair-declined`,severity:`warn`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,reason:n.declineReason}),{...t,outcome:`declined`,reason:n.declineReason}):n.action===`skipped-flag`?{...t,outcome:`canonical`}:{...t,outcome:`repaired`}}function h(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{u as n,d as repairMcpConfigs,l as t};
@@ -417,6 +417,31 @@
417
417
  },
418
418
  "additionalProperties": {}
419
419
  },
420
+ "skills": {
421
+ "default": {
422
+ "trustedPrivateOrigins": []
423
+ },
424
+ "type": "object",
425
+ "properties": {
426
+ "trustedPrivateOrigins": {
427
+ "default": [],
428
+ "type": "array",
429
+ "items": {
430
+ "default": null,
431
+ "type": [
432
+ "string",
433
+ "null"
434
+ ]
435
+ },
436
+ "scope": "user",
437
+ "agentSettable": false,
438
+ "reload": "live",
439
+ "defaultScope": "user",
440
+ "description": "Canonical HTTPS origins allowed to serve website skills from private network addresses. Empty by default: website skills require public addresses. Set only in user global.yml, never project configuration or acquisition requests. Use a lowercase hostname and omit credentials, default port 443, trailing slash, path, query, fragment and wildcards. Include nondefault ports when required. Invalid entries are ignored with located config diagnostics; valid siblings remain approved. TLS certificate and hostname checks still apply."
441
+ }
442
+ },
443
+ "additionalProperties": {}
444
+ },
420
445
  "git": {
421
446
  "default": {
422
447
  "hosts": {}
@@ -0,0 +1 @@
1
+ import"./md-manager-BGnqyqi1-DCCfgLfC.mjs";import"./src-DKsIGYJ_.mjs";import"./init-DZf66ZMB.mjs";import"./token-store-Bmb3_0hU.mjs";import"./start-9N2SMPQM.mjs";import"./registry-probes-DIqlo9h8.mjs";import{n as e}from"./loader-CQWLo5wb.mjs";import"./preview-UtmI_Kbo.mjs";import"./repair-mcp-configs-euqladvH.mjs";export{e as loadConfig};
@@ -0,0 +1,16 @@
1
+ import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{C as t,E as n,L as r,M as i,N as a,O as o,S as s,d as c,k as l,x as u}from"./constants-ok-dir-DZ25OS9-.mjs";import{Da as d,G as f,Oa as p,Rl as m,U as h,W as g,l as _,sf as v,u as ee,zl as y}from"./md-manager-BGnqyqi1-DCCfgLfC.mjs";import{$r as b,As as x,Bs as te,Cs as S,Es as C,Hi as w,Ia as T,Is as E,Ls as D,Nt as O,Os as ne,Qt as k,Rs as A,Si as re,Ss as ie,Vo as j,Vs as ae,Wi as M,_a as N,bi as oe,ci as P,fr as se,js as F,ks as ce,m as le,ma as ue,mi as de,nr as I,ta as fe,wi as pe,ws as me,xi as he,xo as ge,xs as _e,zs as ve}from"./dist-BSNy29T3.mjs";import{t as ye}from"./yazl-BBz29IQN.mjs";import{t as be,y as xe}from"./fs-find-project-root-BYV07wjn.mjs";import{ct as Se,gt as Ce,ht as we,mt as Te,pt as Ee,st as De,wt as Oe}from"./init-DZf66ZMB.mjs";import{o as ke}from"./token-store-Bmb3_0hU.mjs";import{c as Ae}from"./colors-r_owlCuY.mjs";import{t as je}from"./is-object-BGze3w87.mjs";import{l as Me,u as Ne}from"./registry-probes-DIqlo9h8.mjs";import{n as Pe}from"./constants-COUZx5WC.mjs";import"./loader-CQWLo5wb.mjs";import"./preview-UtmI_Kbo.mjs";import{basename as L,dirname as R,isAbsolute as Fe,join as z,relative as Ie,resolve as B,sep as V,win32 as Le}from"node:path";import{closeSync as Re,cpSync as ze,createWriteStream as Be,existsSync as H,lstatSync as Ve,mkdirSync as U,mkdtempSync as He,openSync as Ue,readFileSync as W,readSync as We,readdirSync as G,readlinkSync as Ge,realpathSync as Ke,rmSync as qe,rmdirSync as Je,statSync as Ye,writeFileSync as K}from"node:fs";import{arch as Xe,freemem as Ze,homedir as q,hostname as Qe,platform as $e,release as et,tmpdir as tt,totalmem as nt,type as rt,uptime as it}from"node:os";import{readFile as at,readdir as ot,stat as st}from"node:fs/promises";import{createHash as ct}from"node:crypto";import{execFile as lt,execSync as ut,spawnSync as dt}from"node:child_process";function ft(e,t){let n=t.map(e=>[E(e),e]);for(let t of e){let e=E(t);if(e===null)continue;let r=n.find(([t])=>t===e);if(r!==void 0)return r[1]}}function pt(e){let{override:t,storedPreference:n,preferenceList:r,supportedLocales:i}=e,a=e.autoDetectableLocales??i;if(t!==void 0){let e=ft([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=ft(r,a);return o===void 0?{locale:`en`,source:`fallback`}:{locale:o,source:`system`}}function mt(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 ht=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`audit`,`deinit`,`auth`]);function gt(e,t,n=be){if(e!==void 0&&!ht.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let _t=null;function vt(e){_t=e}function yt(){return _t??process.cwd()}const bt=`Open Knowledge`;function xt(e={}){let t=e.platformName??process.platform,n=e.productName??l().productName;return De(t).join(Se({...e,platformName:t}),n)}function St(e={}){let t=e.platformName??process.platform,n=e.home??q(),r=e.env??process.env,i=De(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,`${l().packageName.replaceAll(`/`,``)}-updater`)}function Ct(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 wt(e){let t=z(e,`state.json`);if(!H(t))return[];let n;try{n=JSON.parse(W(t,`utf-8`))}catch{return[]}return Ct(n)??[]}function Tt(e){let t=z(e,`state.json`);if(!H(t))return!1;try{return Ct(JSON.parse(W(t,`utf-8`)))!==null}catch{return!1}}const Et=8192;function Dt(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 Ot(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const kt=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function At(e){return e.replace(kt,`$1"[REDACTED-DEVICE-ID]"`)}function jt(e){return At(Ot(e))}const Mt=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function Nt(e){if(typeof e!=`string`)return null;let t=Mt.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 Pt(e){let t=Ue(e,`r`);try{let e=Buffer.alloc(Et),n=0,r=!1;for(;n<Et;){let i=We(t,e,n,Et-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{Re(t)}}function Ft(e){try{let t=Pt(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:Nt(a)}}catch{return{kind:`unreadable`}}}function It(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function Lt(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=G(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=z(e,t.name),r;try{r=Ye(n).mtimeMs}catch{continue}if(r<i)continue;let c=Ft(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!It(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`}}const Rt=`state/os-termination-evidence.json`,zt=6048e5,Bt=/openknowledge/i,Vt=n.map(e=>a(t[e]));function Ht(e={}){return(t,n)=>new Promise(r=>{try{lt(t,n,{encoding:`utf8`,timeout:e.timeoutMs??15e3,maxBuffer:e.maxBuffer??16777216,windowsHide:!0},(e,t,n)=>{r({...Ut(e),stdout:t,stderr:n})})}catch(e){let t=e.code;r({status:null,stdout:``,stderr:``,errorCode:typeof t==`string`?t:`spawn-failed`})}})}function Ut(e){return e===null?{status:0}:typeof e.code==`string`?{status:null,errorCode:e.code}:typeof e.code==`number`?{status:e.code}:e.killed===!0?{status:null,errorCode:`ETIMEDOUT`}:e.signal?{status:null,signal:e.signal}:{status:null}}function Wt(e){if(e.errorCode!==void 0)return e.errorCode;if(e.signal!==void 0)return`signal ${e.signal}`;let t=(e.stderr.trim().split(`
2
+ `)[0]??``).replace(/\S*\/journal\/\S*/g,`<journal path>`).replace(/\b[0-9a-f]{32}\b/gi,`<id>`);return`exit ${e.status}${t===``?``:`: ${t}`}`}function Gt(e,t,n){return{schemaVersion:1,platform:e,source:t,outcome:`none-in-window`,readFrom:n,windowDays:7,foreignIgnored:0,unparseable:0,droppedOverCap:0,events:[]}}function Kt(e,t){return{...e,outcome:`unavailable`,unavailableReason:t}}function qt(e){return{...e,outcome:e.events.length>0?`collected`:`none-in-window`}}function Jt(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Yt(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function Xt(e,t){let n=t.indexOf(`
3
+ `);if(n===-1)return null;let r,i;try{r=Yt(JSON.parse(t.slice(0,n))),i=Yt(JSON.parse(t.slice(n+1)))}catch{return null}if(r===null||i===null||!Array.isArray(i.processes))return null;let a=[];for(let e of i.processes){let t=Yt(e);t===null||typeof t.name!=`string`||!It(t.name)||a.push({name:t.name,pid:Jt(t.pid),killReason:typeof t.reason==`string`?t.reason:null,residentPages:Jt(t.rpages),lifetimeMaxPages:Jt(t.lifetimeMax)})}let o=Nt(r.timestamp);return{kind:`jetsam`,at:o===null?null:new Date(o).toISOString(),file:e,pageSize:Jt(Yt(i.memoryStatus)?.pageSize),largestProcessOwned:typeof i.largestProcess==`string`?It(i.largestProcess):null,ownedProcesses:a}}const Zt=/^JetsamEvent-.*\.ips$/;function Qt(e,t,n,r){let i=e.flatMap(({file:e,mtimeMs:n})=>n!==null&&n>=t?[{file:e,mtimeMs:n}]:[]);return i.sort((e,t)=>r===`newest-first`?t.mtimeMs-e.mtimeMs:e.mtimeMs-t.mtimeMs),{files:i.slice(0,n).map(({file:e})=>e),statFailed:e.filter(({mtimeMs:e})=>e===null).length,droppedOverCap:Math.max(0,i.length-n)}}async function $t(e,t){let n=Gt(`darwin`,`macos-jetsam`,[z(e,`JetsamEvent-*.ips`)]),r;try{r=await ot(e)}catch(e){return Kt(n,e.code??`unknown`)}let i=Qt(await Promise.all(r.filter(e=>Zt.test(e)).map(async t=>{try{return{file:t,mtimeMs:(await st(z(e,t))).mtimeMs}}catch{return{file:t,mtimeMs:null}}})),t.getTime()-zt,50,`newest-first`);n.unparseable+=i.statFailed,n.droppedOverCap=i.droppedOverCap;for(let t of i.files){let r=null;try{r=Xt(t,await at(z(e,t),`utf8`))}catch{}r===null?n.unparseable+=1:r.ownedProcesses.length===0?n.foreignIgnored+=1:n.events.push(r)}return qt(n)}const en=[`--no-pager`,`--output=short-iso-precise`,`--since=-7d`,`--grep=Out of memory|oom-kill|Killed process|Killed /|memory pressure`,`_TRANSPORT=kernel`,`+`,`_SYSTEMD_UNIT=systemd-oomd.service`],tn=[`--user`,`--no-pager`,`--output=short-iso-precise`,`--since=-7d`,`--grep=Fatal Wayland communication error|Wayland protocol error|X IO error|Missing X server`],nn=/^(\S+) \S+ ([^:\s[]+)(?:\[\d+\])?: (.*)$/,rn=/\[(\d+)(?::\d+)?:\d{4}\/\d{6}\.\d+:[A-Z0-9]+:[^\]]*\]\s*(.*)$/,an=/^desktop\.\d{4}-\d{2}-\d{2}\.log$/;async function on(e,t){let n=new Set,r;try{r=await ot(e)}catch{return{pids:n,unreadable:!0}}let i=!1;for(let a of r){if(!an.test(a))continue;let r=z(e,a);try{if(t.getTime()-(await st(r)).mtimeMs>zt)continue;for(let e of(await at(r,`utf8`)).split(`
4
+ `)){if(!e.includes(`"event":"desktop.boot"`))continue;let t=/"pid":(\d+)/.exec(e)?.[1];t!==void 0&&n.add(Number(t))}}catch{i=!0}}return{pids:n,unreadable:i}}function sn(e,t){if(e===`systemd-oomd`){let e=/^Killed (\S+)/.exec(t);if(e===null)return null;let n=e[1]?.split(`/`).pop()??``;return{origin:`systemd-oomd`,action:`oomd-kill`,pid:null,processName:null,unit:Bt.test(n)?n:null,trigger:/swap used/.test(t)?`swap`:/memory pressure/.test(t)?`memory-pressure`:null}}if(e!==`kernel`)return null;let n=/Killed process (\d+) \(([^)]+)\)/.exec(t);if(n!==null)return{origin:`kernel`,action:`oom-kill`,pid:Number(n[1]),processName:n[2]??null,unit:null,trigger:null};let r=/task=([^,]+),pid=(\d+)/.exec(t);if(r!==null)return{origin:`kernel`,action:`oom-kill`,pid:Number(r[2]),processName:r[1]??null,unit:null,trigger:null};let i=/^(\S+) invoked oom-killer/.exec(t);return i===null?null:{origin:`kernel`,action:`oom-invoked`,pid:null,processName:i[1]??null,unit:null,trigger:null}}function cn(e){let t=[],n=0,r=0;for(let i of e.split(`
5
+ `)){if(i.trim()===``||i.startsWith(`-- `))continue;let e=nn.exec(i);if(e===null){r+=1;continue}let[,a=``,o=``,s=``]=e;if(!Bt.test(s)){n+=1;continue}let c=sn(o,s);if(c===null){r+=1;continue}t.push({kind:`journal`,at:a,...c})}return{events:t,foreignIgnored:n,unparseable:r}}function ln(e){let t=[],n=0,r=0;for(let i of e.split(`
6
+ `)){if(i.trim()===``||i.startsWith(`-- `))continue;let e=nn.exec(i);if(e===null){r+=1;continue}let[,a=``,,o=``]=e,s=rn.exec(o);if(s===null){n+=1;continue}t.push({at:a,pid:Number(s[1]),detail:(s[2]??``).slice(0,200)})}return{lines:t,foreignIgnored:n,unparseable:r}}async function un(e,t,n){let r=ln(e);if(r.lines.length===0)return{...r,events:[],unattributed:null};let i=await on(t,n),a=[],o=0;for(let e of r.lines){if(!i.pids.has(e.pid)){o+=1;continue}a.push({kind:`journal`,at:e.at,origin:`chromium`,action:`display-connection-lost`,pid:e.pid,processName:null,unit:null,trigger:/Wayland/.test(e.detail)?`wayland`:`x11`,detail:e.detail})}let s=i.pids.size>0&&!i.unreadable;if(o>0&&!s){let e=i.unreadable?`desktop logs unreadable`:`no desktop.boot pid in desktop logs`;return{events:a,foreignIgnored:r.foreignIgnored,unparseable:r.unparseable,unattributed:`${o} Chromium display line(s) not attributed, ${e}`}}return{events:a,foreignIgnored:r.foreignIgnored+o,unparseable:r.unparseable,unattributed:null}}function dn(e){return e.status===0||e.status===1&&/^-- No entries --$/m.test(e.stdout)}async function fn(e,t,n){let r=Gt(`linux`,`linux-journal`,[`journalctl ${en.join(` `)}`,`journalctl ${tn.join(` `)}`]),[i,a]=await Promise.all([e(`journalctl`,[...en]),e(`journalctl`,[...tn])]),o=[];if(dn(i)){let e=cn(i.stdout);r.droppedOverCap+=Math.max(0,e.events.length-50),r.events.push(...e.events.slice(-50)),r.foreignIgnored+=e.foreignIgnored,r.unparseable+=e.unparseable,/not seeing messages from other users/i.test(`${i.stdout}\n${i.stderr}`)&&(r.restrictedToCurrentUser=!0)}else o.push(`system journal: ${Wt(i)}`);if(dn(a)){let e=await un(a.stdout,n,t);r.droppedOverCap+=Math.max(0,e.events.length-50),r.events.push(...e.events.slice(-50)),r.foreignIgnored+=e.foreignIgnored,r.unparseable+=e.unparseable,e.unattributed!==null&&o.push(`user journal: ${e.unattributed}`)}else o.push(`user journal: ${Wt(a)}`);return o.length===2?Kt(r,o.join(`; `)):o.length===1?{...r,outcome:`partial`,unavailableReason:o.join(`; `)}:qt(r)}const pn={41:`Microsoft-Windows-Kernel-Power`,1074:`User32`,2004:`Microsoft-Windows-Resource-Exhaustion-Detector`,6008:`EventLog`},mn={1e3:`Application Error`,1001:`Windows Error Reporting`,1002:`Application Hang`};function hn(e){return e===`System`?pn:mn}function gn(e){let t=`System[(${Object.keys(hn(e)).map(e=>`EventID=${e}`).join(` or `)}) and TimeCreated[timediff(@SystemTime) <= ${zt}]]`;return e===`System`?`*[${t}]`:`*[${t} and EventData[${Vt.map(e=>`Data='${e}'`).join(` or `)}]]`}function _n(e){return[`qe`,e,`/q:${gn(e)}`,`/f:xml`,`/rd:true`,`/c:200`]}function vn(e){return Le.join(e??`C:\\Windows`,`System32`,`wevtutil.exe`)}function yn(e){return e.replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&apos;/g,`'`).replace(/&amp;/g,`&`)}function bn(e){return/[\\/]/.test(e)||/^[a-z]:/i.test(e)}function xn(e,t){let n=RegExp(`<${t}(?:\\s[^>]*)?>([\\s\\S]*?)</${t}>`,`g`);return[...e.matchAll(n)].map(e=>yn(e[1]??``).trim())}function Sn(e,t){let n=hn(e),r=[],i=0,a=0;for(let o of t.match(/<Event[\s>][\s\S]*?<\/Event>/g)??[]){let t=/<Provider\s+Name=['"]([^'"]+)['"]/.exec(o)?.[1],s=Number(/<EventID[^>]*>(\d+)<\/EventID>/.exec(o)?.[1]),c=/<TimeCreated\s+SystemTime=['"]([^'"]+)['"]/.exec(o)?.[1];if(t===void 0||!Number.isInteger(s)||c===void 0){a+=1;continue}if(n[s]!==t){i+=1;continue}let l=xn(o,`Data`),u=xn(o,`Name`),d=[...l,...u].some(e=>Bt.test(e));if(e===`Application`&&!d){i+=1;continue}r.push({kind:`windows-event`,at:c,log:e,provider:t,eventId:s,mentionsOpenKnowledge:d,data:e===`Application`?l.filter(e=>e!==``&&!bn(e)):[]})}return{events:r,foreignIgnored:i,unparseable:a}}async function Cn(e,t){let n=vn(t),r=[`System`,`Application`],i=Gt(`win32`,`windows-event-log`,r.map(e=>`${n} ${_n(e).join(` `)}`)),a=await Promise.all(r.map(async t=>({log:t,result:await e(n,_n(t))}))),o=[];for(let{log:e,result:t}of a){if(t.status!==0){o.push(`${e}: ${Wt(t)}`);continue}let n=Sn(e,t.stdout);i.droppedOverCap+=Math.max(0,n.events.length-50),i.events.push(...n.events.slice(0,50)),i.foreignIgnored+=n.foreignIgnored,i.unparseable+=n.unparseable}return o.length===r.length?Kt(i,o.join(`; `)):o.length>0?{...i,outcome:`partial`,unavailableReason:o.join(`; `)}:qt(i)}async function wn(e={}){let t=e.platform??process.platform,n=e.runCommand??Ht(),r=(e.now??(()=>new Date))();switch(t){case`darwin`:return $t(e.macosReportsDir??`/Library/Logs/DiagnosticReports`,r);case`linux`:return fn(n,r,e.desktopLogsDir??z(xe(),`logs`));case`win32`:return Cn(n,e.systemRoot??process.env.SystemRoot);default:return{...Gt(t,null,[]),outcome:`unsupported`}}}const Tn={schemaVersion:1,outcome:`not-collected`};function En(e){return`${JSON.stringify(e??Tn,null,2)}\n`}const Dn={"macos-jetsam":`macOS low-memory reports`,"linux-journal":`system and user journals`,"windows-event-log":`Windows event logs`};function On(e){let t=[`${e.windowDays}d`,`${e.events.length} kept`,`${e.foreignIgnored} other-process record(s) ignored`,`${e.unparseable} unparseable`];e.droppedOverCap>0&&t.push(`${e.droppedOverCap} older dropped over cap`);let n=e.source?` from ${Dn[e.source]}`:``,r=e.unavailableReason?`, ${e.unavailableReason}`:``;return`${e.outcome}${n}${r} (${t.join(`; `)})`}function kn(){return z(xe(),`bug-reports`)}function An(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=kn(),r=`${t}-bugreport`,i=z(n,`${r}.zip`);for(let e=2;H(i);e+=1)i=z(n,`${r}-${e}.zip`);return i}function jn(e,t){let{scrubbed:n}=e;return n!==void 0&&n.patterns.length>0?{file:t,lineCount:n.lineCount,patterns:[...n.patterns]}:null}function Mn(e,t){let n=z(e,`.ok`,`config.yml`);if(H(n))try{let e=W(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 H(z(e,`.ok`))?ct(`sha256`).update(B(e)).digest(`hex`).slice(0,12):null}function Nn(){let e={timestamp:new Date().toISOString(),platform:$e(),osType:rt(),osRelease:et(),hostname:`[redacted]`,uptime:it(),freeMem:Ze(),totalMem:nt(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=ut(`sw_vers -productVersion 2>/dev/null`,j({encoding:`utf8`})).trim()}catch{}try{let t=z(__dirname,`..`,`..`,`package.json`);H(t)&&(e.okVersion=JSON.parse(W(t,`utf8`)).version)}catch{}return e}const Pn=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function Fn(e){let t=L(e);return Pn.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function In(e,t){return Vn(e,t).files}const Ln=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function Rn(e,t=Ne){let n=z(e,`${t}.ShipIt`);if(!H(n))return[];let r;try{r=G(n)}catch{return[]}return Ln.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).map(e=>{let t=z(n,e.entry);return{path:t,suffix:e.suffix,mtimeMs:zn(t)}}).sort((e,t)=>t.mtimeMs-e.mtimeMs||t.suffix-e.suffix).slice(0,4).map(e=>e.path))}function zn(e){try{return Ye(e).mtimeMs}catch{return 0}}function Bn(e){if(!H(e))return[];try{let t=new Map;for(let n of G(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-_.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=>z(e,t))}catch{return[]}}function Vn(e,t){if(!H(t))return{files:[],excludedByProjectSlug:0};let n=G(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>z(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(Fn),i=[],a=r.filter(t=>{try{return W(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=>!Fn(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function Hn(e){let t=z(e,`.ok`,`local`);return H(t)?{files:[`server.lock`,ve,D].map(e=>z(t,e)).filter(e=>H(e))}:{files:[]}}function Un(e,t,n){let r=C(e),i=[],a=[];for(let e of t){let t=z(r,e),o=z(n,e),s=H(t);s&&i.push(t),H(o)&&(s?a:i).push(o)}return{files:i,legacyFiles:a}}function Wn(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#${ct(`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 Gn(e){let t=e.revealDocNames?e.content:Wn(e.content).text;if(e.redact){let{redacted:n,patterns:r,lineCount:i}=p(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 J(e){for(let t of e.files)try{let n=W(t,`utf8`);Gn({zipfile:e.zipfile,name:`${e.prefix}/${L(t)}`,content:t.endsWith(`.ips`)?jt(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 Kn(t){let{redact:n,outputPath:r,logger:i}=t,a=t.revealDocNames??!1,o=t.userLogsDir??z(xe(),`logs`),s=t.projectDir?Mn(t.projectDir,i):null;U(R(r),{recursive:!0}),i?.info({projectSlug:s},`gathering diagnostic data`);let l=Nn();l.desktop=t.desktop??null,l.language=t.language??null;let{files:u,excludedByProjectSlug:f}=Vn(s,o),{files:p}=t.projectDir?Hn(t.projectDir):{files:[]},{files:m,legacyFiles:h}=t.projectDir?Un(t.projectDir,[A.logsCurrent,A.logsPrevious],z(t.projectDir,`.ok`,`local`,`logs`)):{files:[],legacyFiles:[]},{files:g,legacyFiles:_}=t.projectDir?Un(t.projectDir,[ae],z(t.projectDir,`.ok`,`local`)):{files:[],legacyFiles:[]},v=t.shipItLogFiles??[],y=t.diagnosticReports?.files??[];i?.info({logFileCount:u.length,logFilesExcludedByProjectSlug:f,lockFileCount:p.length+g.length+_.length,localSinkFileCount:m.length+h.length,shipItLogFileCount:v.length,diagnosticReportCount:y.length},`files collected`);let b=[],x=[],{ZipFile:te}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),S=new te;J({zipfile:S,files:[...u,...v],prefix:`logs`,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i}),J({zipfile:S,files:[...p,...g],prefix:`lockdir`,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i}),J({zipfile:S,files:m,prefix:`local-logs`,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i}),J({zipfile:S,files:h,prefix:`legacy/local-logs`,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i}),J({zipfile:S,files:_,prefix:`legacy/lockdir`,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i}),J({zipfile:S,files:t.bugReportLedgerFiles??[],prefix:ee,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i}),J({zipfile:S,files:y,prefix:`diagnostic-reports`,redact:n,revealDocNames:a,bundleFiles:x,redactions:b,logger:i});for(let e of t.extraFiles??[])try{let t=W(e.sourcePath),n=`extra/${e.zipName??L(e.sourcePath)}`;S.addBuffer(t,n),x.push(n);let r=jn(e,n);r!==null&&b.push(r)}catch(t){i?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&Gn({zipfile:S,name:`note.txt`,content:t.note,redact:n,revealDocNames:a,bundleFiles:x,redactions:b});let C=new Set(y.map(e=>`diagnostic-reports/${L(e)}`)),w=x.filter(e=>C.has(e)),T=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Dt(t.diagnosticReports,w.length);S.addBuffer(Buffer.from(`${T}\n`,`utf8`),`state/diagnostic-reports-status.txt`),x.push(`state/diagnostic-reports-status.txt`),Gn({zipfile:S,name:Rt,content:En(t.osTerminationEvidence),redact:n,revealDocNames:!0,bundleFiles:x,redactions:b});let E=JSON.stringify(l,null,2);S.addBuffer(Buffer.from(E,`utf8`),`sysinfo.json`),x.push(`sysinfo.json`);let D={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:s,files:x,redactions:b,sysinfo:l};S.addBuffer(Buffer.from(JSON.stringify(D,null,2),`utf8`),`MANIFEST.json`);let O=b.reduce((e,t)=>e+t.lineCount,0),ne=new Set(v.map(e=>`logs/${L(e)}`)),k=x.filter(e=>ne.has(e)),re=new Set((t.bugReportLedgerFiles??[]).map(e=>`${ee}/${L(e)}`)),ie=x.filter(e=>re.has(e)),j=s?x.filter(e=>e.startsWith(`logs/`)&&!Fn(e)&&!ne.has(e)):[],M=w.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.`],oe=[`# Bug Report Bundle`,``,`Generated: ${D.generatedAt}`,`Project: ${s??`(unscoped)`}`,...t.projectDir?[`Project diagnostic source: ${c(`logs`,`projects`)} (current product only).`]:[],`Discipline version: ${D.disciplineVersion}`,``,`## Contents`,``,...x.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}`),``]:[],...k.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:`,...k.map(e=>`- ${e}`),``]:[],...w.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:`,...w.map(e=>`- ${e}`),``]:[],...(t.osTerminationEvidence?.events.length??0)>0?[`Termination records: read from the operating system's own logs, covering`,`the last 7 days, to explain an exit the app could not record itself. On`,`macOS: the memory-pressure (jetsam) reports`,`that list processes of this app, with each one's memory use and whether`,`it was killed. On Linux: kernel and systemd-oomd out-of-memory kills of`,`this app, as structured fields with the machine name, cgroup paths and`,`user id left out, plus display-connection errors this app's desktop`,`process wrote to the user's own journal, with Chromium's message cut to`,`200 characters. On Windows: crash and hang records for this app with`,`file paths left out, plus the time of every shutdown, restart, power`,`loss and low-memory warning on the machine, whatever caused it:`,`- ${Rt}`,``]:[],...ie.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:`,...ie.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${d.join(`, `)}`,O>0?`${O} line(s) were scrubbed across ${b.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(`
7
+ `);S.addBuffer(Buffer.from(oe,`utf8`),`README.md`),S.end();let P=Be(r);return S.outputStream.pipe(P),await new Promise((e,t)=>{P.on(`close`,e),P.on(`error`,t)}),i?.info({bundlePath:r,fileCount:x.length,redactionCount:O},`bundle written`),{zipPath:r,summary:{projectSlug:s,files:x,redactions:b,redactedLineCount:O,generatedAt:D.generatedAt}}}var qn=u(),Jn=e(ye(),1),Y=e(Ae(),1);function Yn(e){let t=F(`user`,e,e);return x({absPath:t,sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function Xn({home:e=q(),env:t=process.env}={}){let n=Yn(e),{override:r,preferenceList:i}=ce(t),{locale:a,source:o}=pt({override:r,storedPreference:n,supportedLocales:y,preferenceList:i,autoDetectableLocales:m});return{preference:n,locale:a,source:o,systemLanguages:i}}function Zn(e){let t=new Set([e]);try{t.add(Ke.native(e))}catch{return[e].filter(e=>e.length>0)}return[...t].filter(e=>e.length>0).sort((e,t)=>t.length-e.length)}function Qn(e,t){let n=e;for(let e of t)n.includes(e)&&(n=n.split(e).join(`<CONTENT_DIR>`));return n}function $n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function er(e,t){if(typeof e==`string`)return Qn(e,t.contentDirSpellings);if(Array.isArray(e))return e.map(e=>er(e,t));if(!$n(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=er(i,t);return n}function tr(e,t){let n=W(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
8
+ `),i=n.split(`
9
+ `),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=er(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}let o=r?`${a.join(`
10
+ `)}\n`:a.join(`
11
+ `);K(e,o)}function nr(e,t){let n=W(e,`utf-8`);if(n.trim().length!==0)try{let r=er(JSON.parse(n),t),i=n.endsWith(`
12
+ `)?`
13
+ `:``;K(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=Qn(n,t.contentDirSpellings);r!==n&&K(e,r)}}function rr(e,t){let n=W(e,`utf-8`),r=Qn(n,t.contentDirSpellings);r!==n&&K(e,r)}function ir(e){try{return G(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>z(e,t.name))}catch{return[]}}const ar=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function or(e){return/\.log\.\d+$/.test(e)}function sr(e){return e.endsWith(`.jsonl`)||e.endsWith(`.log`)||or(e)}const cr=[`telemetry`,`logs`,`process`,`diagnostic-reports`];function lr(e){let t={contentDirSpellings:Zn(e.contentDir)};for(let n of cr)for(let r of ir(z(e.stagingDir,n)))sr(r)?tr(r,t):r.endsWith(`.json`)?nr(r,t):rr(r,t);for(let n of ir(z(e.stagingDir,`state`))){let e=L(n);n.endsWith(`.jsonl`)?tr(n,t):ar.has(e)?nr(n,t):rr(n,t)}}const ur=[`.ok`,`local`,`telemetry`],dr=[`.ok`,`local`,`logs`],fr=[`.ok`,`local`,`loss-capture`],pr=A.spansCurrent,mr=A.spansPrevious,hr=A.logsCurrent,gr=A.logsPrevious,_r=`loss-current.jsonl`,vr=`loss-prev.jsonl`;function yr(e){return z(e,...fr,_r)}function br(e){return z(e,...fr,vr)}const xr=1e3;async function Sr(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(xr)});return t.ok?await t.text():null}catch{return null}}async function Cr(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-effects`,{signal:AbortSignal.timeout(xr)});return t.ok?await t.text():null}catch{return null}}async function wr(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout(xr)});return t.ok?await t.text():null}catch{return null}}function Tr(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(`
14
+ `)}\n`:null}catch{return null}}function Er(e){let t=z(e,`.git`,`ok`);if(!H(t))return null;let n=dt(`git`,[`-C`,t,`log`,`--oneline`,`-50`],j({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Dr(e){let t=z(e,`.git`,`ok`);if(!H(t))return null;let n=dt(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],j({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Or(){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 kr(){return{nodeVersion:process.version,platform:$e(),arch:Xe()}}function Ar(){return process.env.OTEL_SDK_DISABLED===`false`}function jr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Mr(e){if(!H(e))return{};let t;try{t=(0,qn.parse)(W(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(!jr(t))return{};let n=t.telemetry;if(!jr(n))return{};let r=n.localSink;return jr(r)?r:{}}function Nr(e){return typeof e==`boolean`?e:void 0}function Pr(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function Fr(e){if(jr(e))return Pr(e.maxBytes)}function Ir(e){let t=Mr(F(`project`,e)),n=Mr(F(`project-local`,e));return{enabled:Nr(n.enabled)??Nr(t.enabled)??!0,spansMaxBytes:Fr(n.spans)??Fr(t.spans)??52428800,logsMaxBytes:Fr(n.logs)??Fr(t.logs)??26214400}}function Lr(e){return ct(`sha256`).update(e).digest(`hex`)}function Rr(e){let t=W(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}const zr=[`"doc.name"`,`"docName"`];function Br(e){let t=W(e,`utf-8`),n=0;for(let e of zr){let r=t.indexOf(e);for(;r!==-1;)n++,r=t.indexOf(e,r+e.length)}return n}function X(e,t){if(!H(e))return!1;try{return U(R(t),{recursive:!0}),e.endsWith(`.ips`)?K(t,jt(W(e,`utf-8`))):ze(e,t),!0}catch{return!1}}function Z(e,t,n,r){let i=H(e);X(e,z(n,r)),X(t,i?z(n,`legacy`,r):z(n,r))}function Vr(e){let t=[],n=e=>{let r=G(e,{withFileTypes:!0});for(let i of r){let r=z(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const Hr=new Set([`.jsonl`]);function Ur(e){let t=e.lastIndexOf(`.`);return t!==-1&&Hr.has(e.slice(t))}const Wr=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`,`.yaml`,`.yml`,`.ips`]);function Gr(e){if(or(e))return!0;let t=e.lastIndexOf(`.`);return t!==-1&&Wr.has(e.slice(t))}function Kr(e){let t=[];for(let n of Vr(e)){let r=qr(e,n);if(!Gr(r))continue;let{redacted:i,patterns:a,lineCount:o}=p(W(n,`utf-8`));a.length!==0&&(K(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function qr(e,t){return Ie(e,t).split(V).join(`/`)}async function Jr(e){let t=B(e.contentDir),n=B(e.projectDir??e.contentDir),r=e.deps??{},i=r.fetchAgentPresence??Sr,a=r.fetchAgentEffects??Cr,o=r.fetchWatcherRecent??wr,s=r.readShadowHead??Er,l=r.readCheckpointRefs??Dr,u=r.now??(()=>new Date),d=r.okVersion??(()=>Pe),f=r.readDesktopEnv??Or,p=r.readLanguage??Xn,m=r.readRuntime??kr,h=r.isOtlpPushEnabled??Ar,g=He(z(tt(),`ok-bundle-`));try{U(z(g,`telemetry`),{recursive:!0}),U(z(g,`logs`),{recursive:!0}),U(z(g,`state`),{recursive:!0}),Z(S(n),z(n,...ur,pr),g,z(`telemetry`,pr)),Z(me(n),z(n,...ur,mr),g,z(`telemetry`,mr)),Z(_e(n),z(n,...dr,hr),g,z(`logs`,hr)),Z(ie(n),z(n,...dr,gr),g,z(`logs`,gr));for(let t of e.userLogFiles??[])X(t,z(g,`logs`,L(t)));for(let t of e.userStateFiles??[])X(t,z(g,ee,L(t)));let _=0;for(let t of e.diagnosticReports?.files??[])X(t,z(g,`diagnostic-reports`,L(t)))&&(_+=1);let v=z(n,`.ok`,`local`),y=z(v,`server.lock`),b=`not-running`,x=`no server.lock`,C=null;if(H(y)){X(y,z(g,`state`,`server.lock`));try{let e=W(y,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?C=t.port:x=`lock present but no port`}catch{x=`lock present but unparseable`}}if(C!==null){let e=await i(C);e===null?x=`agent-presence endpoint at :${C} unreachable`:(K(z(g,`state`,`agent-presence.json`),e),b=`running`,x=``);let t=await a(C);t!==null&&K(z(g,`state`,`agent-effects.json`),t);let n=await o(C);if(n!==null){let e=Tr(n);e!==null&&K(z(g,`state`,`watcher-recent.jsonl`),e)}}let w=s(t);w!==null&&K(z(g,`state`,`shadow-head.txt`),w);let T=l(t);T!==null&&K(z(g,`state`,`checkpoint-refs.txt`),T),X(yr(n),z(g,`state`,_r)),X(br(n),z(g,`state`,vr)),Z(ne(n),z(v,ae),g,`state/last-spawn-error.log`),X(z(v,te),z(g,`state`,te)),X(z(v,ve),z(g,`state`,ve)),X(z(v,D),z(g,`state`,D));let E=m(),O=f(),k=p(),A={ok:{version:d(),nodeVersion:E.nodeVersion,platform:E.platform,arch:E.arch},host:{desktop:O,language:k}};K(z(g,`state`,`runtime.json`),`${JSON.stringify(A,null,2)}\n`);let re=b===`running`?`running
15
+ `:`not-running (${x})\n`;K(z(g,`state`,`server-status.txt`),re);let j=e.diagnosticReports===void 0?`not-collected (no collection attempted)`:Dt(e.diagnosticReports,_);if(K(z(g,`state`,`diagnostic-reports-status.txt`),`${j}\n`),K(z(g,Rt),En(e.osTerminationEvidence)),e.processDir&&H(e.processDir)){let t=z(g,`process`);U(t,{recursive:!0}),ze(e.processDir,t,{recursive:!0})}let M=e.redact===!0;M&&(lr({stagingDir:g,contentDir:t}),lr({stagingDir:z(g,`legacy`),contentDir:t})),e.note&&K(z(g,`note.txt`),e.note);let N=null;e.scrubSecrets===!0&&(N=Kr(g));for(let t of e.extraFiles??[]){let e=t.zipName??L(t.sourcePath);if(!X(t.sourcePath,z(g,`extra`,e))){r.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);continue}let n=jn(t,`extra/${e}`);n!==null&&(N??={redactions:[],redactedLineCount:0},N.redactions.push(n),N.redactedLineCount+=n.lineCount)}let oe=Ir(n),P=Vr(g),se=[],F=0,ce=0;for(let e of P){let t=qr(g,e),n=Ye(e).size,r=Ur(t)?Rr(e):0;se.push({path:t,bytes:n,lines:r}),F+=n;let i=t.startsWith(`legacy/`)?t.slice(7):t;(i.startsWith(`telemetry/`)||i.startsWith(`logs/`))&&(ce+=Br(e))}let le={applied:M};N!==null&&(le.secretScrub=N);let ue={schemaVersion:2,createdAt:u().toISOString(),ok:{version:d(),nodeVersion:E.nodeVersion,platform:E.platform,arch:E.arch},host:{desktop:O,language:k},contentDir:{pathSha256:Lr(t),absolutePath:M?`<CONTENT_DIR>`:t},telemetry:{localSink:{...oe,directory:c(`logs`,`projects`)},otlpPushEnabled:h()},redaction:le,serverStatus:b,files:se};K(z(g,`manifest.json`),`${JSON.stringify(ue,null,2)}\n`);let de=Zn(t),I=P.some(e=>{try{let t=W(e,`utf-8`);return de.some(e=>t.includes(e))}catch{return!1}}),fe={stagedDiagnosticReports:_,totalBytes:F,fileCount:se.length,docNameCount:ce,contentDirVisible:I,redacted:M},pe=!1;return{stagingDir:g,manifest:ue,summary:fe,cleanup:()=>{pe||(pe=!0,qe(g,{recursive:!0,force:!0}))}}}catch(e){throw qe(g,{recursive:!0,force:!0}),e}}async function Yr(e){let{collected:t,outputPath:n}=e,r=R(n);if(!H(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new Jn.ZipFile,a=Vr(t.stagingDir);for(let e of a){let n=qr(t.stagingDir,e);i.addFile(e,n)}i.end();let o=Be(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 Xr(e,t){let n=z(e,`.ok`,`config.yml`);if(H(n))try{let t=(0,qn.parse)(W(n,`utf-8`)),r=je(t)?t.content:void 0,i=je(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return B(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 B(e)}async function Zr(e,t,n,r,i,a){let o=Mn(t,e.logger),s=await Jr({contentDir:Xr(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,userLogFiles:[...In(o,e.userLogsDir??z(xe(),`logs`)),...Rn(e.cachesDir??z(q(),`Library`,`Caches`))],userStateFiles:Bn(e.bugReportsDir??kn()),diagnosticReports:i,osTerminationEvidence:a,deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{U(R(e.outputPath),{recursive:!0}),await Yr({collected:s,outputPath:e.outputPath});let t=s.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:o,files:s.manifest.files.map(e=>e.path),redactions:t?.redactions??[],redactedLineCount:t?.redactedLineCount??0,generatedAt:s.manifest.createdAt}}}finally{s.cleanup()}}async function Qr(e){let{projectDir:t}=e,n=e.readDesktopEnv??Or,r=e.readLanguage??Xn,i=()=>Lt(e.diagnosticReportsDir??z(q(),`Library`,`Logs`,`DiagnosticReports`),new Date);if(e.level===`full`&&t!==void 0)return Zr(e,t,n,r,i(),await wn(e.osTerminationEvidenceDeps));let{zipPath:a,summary:o}=await Kn({projectDir:t,redact:e.redact,revealDocNames:e.level===`full`,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:Rn(e.cachesDir??z(q(),`Library`,`Caches`)),bugReportLedgerFiles:Bn(e.bugReportsDir??kn()),diagnosticReports:e.level===`full`?i():void 0,osTerminationEvidence:e.level===`full`?await wn(e.osTerminationEvidenceDeps):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 Q(e,t,n={}){let r=re(e,t),i;try{i=W(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,text:i}}let o=a&&typeof a==`object`?a:{},s=ue(o),c=s&&!b(o,n);if(!a||typeof a!=`object`||!de(a.pid))return{status:`corrupt`,lockPath:r,text:i,...c?{foreignHost:!0}:{}};let l=ge(a),{pid:u}=l;if(c)return{status:`foreign-host`,lockPath:r,lock:l};let d=k(l,{isAlive:n.isAlive,readProcessStart:n.readProcessStart,readBootInstant:n.readBootInstant,sameMachine:s});switch(d.verdict){case`gone`:return{status:`dead-pid`,lockPath:r,lock:l,text:i};case`replaced`:return{status:`reused-pid`,lockPath:r,lock:l,text:i};case`unverified`:return d.cause===`unverified-owner`?{status:`unverified-owner`,lockPath:r,pid:u}:{status:`alive`,lockPath:r,lock:l};case`writer`:return{status:`alive`,lockPath:r,lock:l};default:return d}}function $r(e){return`does not record its owning machine, and its recorded process ${e} is still running on this machine`}function ei(e){return typeof e.machineId==`string`?`records a machine ID different from the one in ${pe()}`:`records only the host ${Me(e.hostname)}, not this machine's ${Qe()}`}function ti(e){return e===`win32`?`USERPROFILE`:`HOME`}function ni(e){return e.processStart===void 0?` This lock records no process start; a server started by this release records one, which lets \`${o()} stop\` confirm it from any home folder.`:``}function ri(e,t){let n=`\`${o()} stop\``;return`If the server was started on this machine from another account, run ${n} as that account. If it was started from this account with a different home folder, run ${n} with \`${ti(t)}\` set to that folder. Otherwise stop it from the machine that owns the lock.${ni(e)}`}function ii(e,t){let n=o();return`If the server was started on this machine from another account, run \`${n} stop\` as that account while it is running, or \`${n} clean\` once it has exited. If it was started from this account with a different home folder, run the same command with \`${ti(t)}\` set to that folder. Otherwise run the same command on the machine that owns the lock.${ni(e)}`}function ai(e){return`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} and retry cleanup.`}function oi(e,t=process.platform){let{lock:n,lockPath:r}=e;return`${typeof n.machineId==`string`?ii(n,t):`If ${Me(n.hostname)} is another machine, stop OpenKnowledge there; if it is an earlier name of this machine, stop OpenKnowledge here if it is still running.`} ${ai(r)}`}function si(e,t=process.platform){let{lockPath:n}=e;return e.status===`unverified-owner`?`Cannot verify shutdown: the server lock at ${n} ${$r(e.pid)}. 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.`:e.status===`corrupt`?`Cannot verify shutdown: the server lock at ${n} records a machine ID or host name that is not this machine's, so its server may run on another machine, or on this one from another account, with a different home folder, or under an earlier host name. Stop OpenKnowledge wherever it was started. ${ai(n)}`:`Cannot verify shutdown: the server lock at ${n} ${ei(e.lock)}. ${oi(e,t)}`}function ci(e){return e.replace(/:\d+$/,``)}function li(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:ci(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:ci(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:ci(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 ui=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function di(e,t=process.platform,n=process.env){return f(r(),e,t,n.XDG_CONFIG_HOME)}function fi(){return g(r())}function pi(){let e=r();if(e===`stable`)return ui;let t=h(e);return RegExp(`^# >>> ${t} >>>\\n[\\s\\S]*?^# <<< ${t} <<<\\n?`,`m`)}const mi={existsSync:e=>H(e),readFileSync:(e,t)=>W(e,t),lstatSync:e=>Ve(e),readlinkSync:e=>Ge(e)};function hi(e,t=mi,n=process.platform,i=process.env){let a=r(),o=di(e,n,i),s=f(a,e),c=t.existsSync(o)?o:a===`stable`&&n===`linux`&&t.existsSync(s)?s:null;if(c===null)return null;try{let e=JSON.parse(t.readFileSync(c,`utf8`));return e?.version===1?e:null}catch{return null}}function gi(e){let t=e.replace(pi(),``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function _i(e,t,n=mi){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}const vi=[{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`}],yi=[...O.map(e=>le[e]),`open-knowledge`];function bi(e){if(!Fe(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=B(e);if(t===V||R(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function xi(e,t){let n=Ie(e,t);if(n.startsWith(`..`)||Fe(n))return!1;let r=e;for(let e of n.split(V)){r=z(r,e);try{if(!Ve(r).isDirectory())return!1}catch{return!1}}return!0}function Si(e,t){try{return G(e).every(n=>t.has(z(e,n)))}catch{return!1}}function Ci(e){let t=bi(e),n=[],r=[],i=new Set;for(let e of vi){let a=z(t,e.hostDir,`skills`);if(!xi(t,a))continue;let o=yi.map(e=>z(a,e)).filter(e=>H(e));n.push(...o);for(let e of o)i.add(e);let s=z(t,e.pruneRoot),c=a;for(;Si(c,i)&&(r.push(c),i.add(c),c!==s);){let e=R(c);if(e===c||e===t||!e.startsWith(t+V))break;c=e}}return{skillDirs:n,emptyDirs:r}}function wi(e){try{if(!Ve(e).isDirectory())return!1;let t=G(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function Ti(e){let t=new Set,n=new Set;for(let r of vi){let i=z(e,r.hostDir,`skills`);for(let e of yi)t.add(z(i,e));let a=z(e,r.pruneRoot),o=i;for(;n.add(o),o!==a;){let t=R(o);if(t===o||t===e||!t.startsWith(e+V))break;o=t}}return{skillDirs:t,emptyDirs:n}}function Ei(e,t){let n=bi(e),r=Ti(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(xi(n,e)&&wi(e))try{qe(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(xi(n,e))try{Je(e),a.push(e)}catch{}return a}function Di(e){let t=bi(e),n=[];for(let e of O){let r=le[e];n.push({path:z(t,`.agents`,`skills`,r),bundleId:e,scope:`central`});for(let i of v)n.push({path:z(t,i.skillsRoot,r),bundleId:e,scope:`host`,hostDir:i.hostDir})}return n}function Oi(e,t){let n=[];for(let r of Di(e))if(r.bundleId===t)try{qe(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 ki(e){if(!e||typeof e!=`object`)return String(e);let t=typeof e.readProcessStart;return`${we(e)} readProcessStart=${t}`}function Ai(e,t={}){if(!Number.isSafeInteger(e)||e<=0||e>4294967295)return null;let n=t.arch??process.arch,r=(e,n,r)=>{Ee(n,r),t.onNativeFailure?.({kind:e,reason:Te(n,r)})};try{let i=!1,a=Ce(t.nativeResolver,(e,t)=>{i=!0,r(`unavailable`,e,t)});if(!a||typeof a!=`object`||!(`readProcessStart`in a)||typeof a.readProcessStart!=`function`){let e;return e=a==null?i?`no usable binding was returned`:`the addon was not found`:ki(a),r(`unavailable`,`the Windows native addon (native-config.win32-${n}-msvc.node) did not load or does not export readProcessStart`,e),null}let o=a.readProcessStart(e);return typeof o==`number`&&Number.isSafeInteger(o)&&o>=0?o:(r(`unavailable`,`readProcessStart returned an invalid value`,we(o)),null)}catch(e){return r(`query-failed`,`readProcessStart failed`,e),null}}function ji(e,t={}){return fe(e,{platform:t.platform,readNative:e=>Ai(e,{onNativeFailure:t.onNativeFailure})})}function Mi(e){let{platform:t,pid:n,nativeFailures:r,causeRecorded:i}=e,a=r.some(e=>{switch(e.kind){case`unavailable`:return!0;case`query-failed`:return!1;default:return e.kind}}),o=r.length===0?``:a?`Reinstall OpenKnowledge to restore the Windows component that verifies process identity. `:`The Windows component loaded but the operating system refused the query, so reinstalling will not help; retry from an account that can inspect that process. `;return(t===`linux`?`Linux reads the process start from /proc/${n}/stat and /proc/stat; restore read access to /proc and retry. `:t===`darwin`?`macOS reads the process start with ps, and that read failed, as it does inside some sandboxes; retry from a shell where ps can run. `:t===`win32`?o:``)+(r.length>0&&i?`The failure detail is recorded in the CLI log under ${c(`logs`)}. `:``)}function Ni(e){let t=new Set;return N(n=>{let r=[],i=Ai(n,{onNativeFailure:e=>{r.push(e)}});for(let i of new Set(r.map(e=>e.kind)))t.has(i)||(t.add(i),(e??ke())?.warn({event:`process-start-native-failure`,lockPid:n,kind:i,reasons:r.filter(e=>e.kind===i).map(e=>e.reason)},`the Windows process-start query failed, so lock holders cannot be verified; later failures of this kind are not recorded again`));return i})}function Pi(e){return e!=null&&e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Fi(e,t=Date.now()){if(e===null)return`—`;let n=mt(e,t);return n===`unknown`?`—`:n}function Ii(e){let t=R(e);return L(e)===`local`&&L(t)===`.ok`?R(t):L(e)===`.ok`?t:null}function Li(e,t,n,r){if(t.status===`missing`||t.status===`corrupt`||t.status===`read-error`)return null;if(t.status===`unverified-owner`)return{directory:Ii(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`&&oe(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:se(n),command:n,isDesktop:Pi(n)}}function Ri(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`:case`reused-pid`:return`stale`;default:return t}}const zi=new Set([`running`,`desktop`,`foreign`,`unverified`]);function Bi(e){switch(e){case`running`:return Y.default.green(e);case`desktop`:return Y.default.blue(e);case`foreign`:return Y.default.cyan(e);case`unverified`:case`stale`:return Y.default.yellow(e)}}function Vi(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Hi(e){return`${Vi(e.server.usage)} | ${Vi(e.ui?.usage??null)}`}function Ui(e){return`${e.server.port===null?`—`:e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null?`—`:String(e.ui.port)}`}function Wi(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??`—`,Ui(e),Hi(e),Ri(e),String(e.server.pid),Fi(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(),s=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=Bi(Ri(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),c=Y.default.dim(`To stop a server: ${o()} stop <port|pid|directory|all>`);return[a,...s,``,c].join(`
16
+ `)}async function Gi(e={}){let t=e.discover??I,n=e.inspect??(e=>Q(e,`server`)),r=e.log??(e=>console.log(e)),i=e.resolveCommand??w,a=e.resolveUsage??M,o=await t(),s=[];for(let e of o){let t=n(e),r=Li(e,t,t.status===`missing`||t.status===`corrupt`||t.status===`read-error`||t.status===`unverified-owner`||t.status===`reused-pid`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`||t.status===`read-error`||t.status===`unverified-owner`||t.status===`reused-pid`?null:a(t.lock.pid));r!=null&&s.push(r)}if(e.json){let e=s.map(e=>({...e,displayStatus:Ri(e)}));r(JSON.stringify(e,null,2));return}r(Wi(e.all?s:s.filter(e=>zi.has(Ri(e)))))}function Ki(){return new Oe(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale 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 Gi({all:t.all===!0||e===`all`,json:t.json===!0})})}async function qi(e,t=ke()){let n=Q(e,`server`);if(n.status!==`alive`&&n.status!==`foreign-host`)return null;let r=he(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 Ji(e,t={}){return ea(e,t.isAlive??P)?{targets:[{name:`server`,pid:e.lock.pid,port:e.lock.port}],lock:e.lock}:{targets:[]}}function Yi(e){try{return r()}catch(t){e?.warn({err:t},`stop channel check skipped: ${t instanceof Error?t.message:String(t)}`);return}}async function $(e){let t=e.inspect??(()=>Q(e.lockDir,`server`)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),a=e.error??(e=>console.error(e)),c=e.probeClients??qi,l=e.logger??ke(),u=e.platform??process.platform,d=t(),f=Ji(d,{isAlive:e.isAlive}),{lock:p}=f,m=[],h=[],g=(t,n)=>{l?.warn({lockDir:e.lockDir,lockPath:n.lockPath,lockPid:n.pid,platform:u,cause:n.cause,...`nativeFailures`in n&&n.nativeFailures.length>0?{nativeFailures:n.nativeFailures}:{}},`stop declined: lock holder identity unverified`),h.push({target:t,error:Qi(n,l!==void 0),unverified:n})},_=()=>{if(m.length>0){let e=m.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);r(`Stopped: ${e}`)}if(l?.info({lockDir:e.lockDir,signalled:m.map(e=>({name:e.name,pid:e.pid,port:e.port})),failed:h.map(({target:e,error:t})=>({pid:e.pid,error:t})),forced:e.force===!0},`stop signalled processes`),h.length>0){let e=h.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `);a(`Failed to stop: ${e}`)}return{stopped:m,failed:h,hadTargets:!0}};if(d.status===`unverified-owner`){let{pid:e,lockPath:t}=d;return g({name:`server`,pid:e},{cause:`unverified-owner`,pid:e,lockPath:t}),_()}if(p===void 0)return r(`No running open-knowledge processes.`),l?.info({lockDir:e.lockDir,targets:0},`stop found nothing to signal`),{stopped:[],failed:[],hadTargets:!1};let v=d.status===`alive`||d.status===`foreign-host`?d.lock.channel:void 0;if(e.force!==!0&&typeof v==`string`&&v.length>0){let t=e.selfChannel??Yi(l);if(t!==void 0&&v!==t)return a(`Not stopping: the server at ${e.lockDir} belongs to ${i(v)}. `+(v===`dev`?`Stop it from that dev build, or run \`${s} stop\` with OK_CHANNEL=dev set, or re-run with --force to terminate anyway.`:`Stop it from that app or its CLI, or re-run with --force to terminate anyway.`)),l?.warn({lockDir:e.lockDir,holderChannel:v,selfChannel:t,pids:f.targets.map(e=>e.pid)},`stop declined: server belongs to another channel`),{stopped:[],failed:[],hadTargets:!0,declined:{otherChannel:v}}}if(e.force!==!0){let t=await c(e.lockDir,l);if(t!==null&&t>0)return a(`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.`),l?.warn({lockDir:e.lockDir,clients:t,pids:f.targets.map(e=>e.pid)},`stop declined: live collaboration clients`),{stopped:[],failed:[],hadTargets:!0,declined:{clients:t}}}for(let t of f.targets){let i=[],s=(e.readProcessStart??ji)(t.pid,{platform:u,onNativeFailure:e=>{i.push(e)}}),c=k(p,{isAlive:e.isAlive??P,readProcessStart:()=>s,refuseHolderStartedAfterLock:e.refuseHolderStartedAfterLock,platform:u,readBootInstant:e.readBootInstant});switch(c.verdict){case`writer`:try{n(t.pid,`SIGTERM`),m.push(t)}catch(e){h.push({target:t,error:e instanceof Error?e.message:String(e)})}break;case`gone`:r(`${t.name} (pid=${t.pid}) had already exited`);break;case`replaced`:a(`Process ${t.pid} is no longer the server that wrote ${d.lockPath}; it was not signalled. Run \`${o()} clean\` to remove the stale lock.`);break;case`unverified`:g(t,Xi(c.cause,{pid:t.pid,lockPath:d.lockPath,lock:p,platform:u,nativeFailures:i}));break;default:return c}}return _()}function Xi(e,t){let{pid:n,lockPath:r}=t;switch(e){case`foreign-host`:return{cause:e,pid:n,lockPath:r,lock:t.lock,platform:t.platform};case`unverified-owner`:return{cause:e,pid:n,lockPath:r};default:return{cause:e,pid:n,lockPath:r,platform:t.platform,nativeFailures:t.nativeFailures}}}const Zi=`it was not signalled, and --force does not override this check.`;function Qi(e,t){let{pid:n,lockPath:r}=e;switch(e.cause){case`foreign-host`:{let{lock:t}=e;return typeof t.machineId==`string`?`The server lock at ${r} ${ei(t)}, so process ${n}, which is running on this machine, cannot be confirmed as the server that wrote it; ${Zi} ${ri(t,e.platform)}`:`The server lock at ${r} ${ei(t)}, and the start of process ${n}, which is running on this machine, does not confirm it as the server that wrote the lock; ${Zi} If ${Me(t.hostname)} is another machine, stop the server there. If it is an earlier name of this machine, confirm that process ${n} is an OpenKnowledge server before ending it yourself, and once no OpenKnowledge server is running for this project, remove ${r}.`}case`unverified-owner`:return`The server lock at ${r} ${$r(n)}, so it cannot be confirmed as the server that wrote the lock; ${Zi} Check whether process ${n} is an OpenKnowledge server, and if it is, stop it yourself. Do not remove the lock file while that process is running.`;default:{let n=$i(e,Zi,`Once you have confirmed no OpenKnowledge server is running for this project, remove ${r}.`,t);return e.cause===`writer-identity-unrecorded`?`${n} A server you start again with this release records its machine ID, so \`${o()} stop\` can confirm it.`:n}}}function $i(e,t,n,r){let{pid:i,lockPath:a,platform:o,nativeFailures:s}=e,c=`Before ending process ${i} yourself, confirm that it is an OpenKnowledge server.`;switch(e.cause){case`process-start-unreadable`:return`Could not read when process ${i} started, so it cannot be confirmed as the server that wrote ${a}; ${t} `+Mi({platform:o,pid:i,nativeFailures:s,causeRecorded:r})+`${c} ${n}`;case`process-start-incomparable`:return`The start of process ${i} cannot be compared with the start recorded in ${a}, so it cannot be confirmed as the server that wrote the lock; ${t} ${c} ${n}`;case`process-start-mismatch`:return`Process ${i} started before the start recorded in ${a}, so it cannot be confirmed as the server that wrote the lock; ${t} ${c} ${n}`;case`process-started-after-lock`:return`Process ${i} started after the server lock at ${a} was written, so it cannot be confirmed as the server that wrote the lock; ${t} ${c} ${n}`;case`recorded-start-in-future`:return`The server lock at ${a} records a start later than the current time on this machine, so process ${i} cannot be confirmed as the server that wrote it; ${t} ${c} ${n}`;case`writer-identity-unrecorded`:return`The server lock at ${a} records neither a machine ID nor a process start, as locks written by version 0.25.0 and earlier do, so process ${i} cannot be confirmed as the server that wrote it; ${t} ${c} ${n}`;default:return e.cause}}function ea(e,t){return e.status===`alive`||e.status===`foreign-host`&&t(e.lock.pid)}async function ta(e,t=P){let n=await I(),r=null;for(let i of n){let n=Q(i,`server`);if(ea(n,t)){if(n.lock.port===e)return i;r===null&&n.lock.pid===e&&(r=i)}}return r}function na(e){(e.failed.length>0||e.declined!==void 0)&&(process.exitCode=1)}async function ra(e,t){let n=await $({lockDir:e,force:t});return na(n),n}function ia(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 \`${o()} ps\` to list them`}.`}async function aa(e){let t=await I(),n=0;for(let r of t)r!==e&&ea(Q(r,`server`),P)&&n++;return n}function oa(e){return new Oe(`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, Beta or a dev build run from source) 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=T(process.cwd()),n=[],i=await $({lockDir:t,force:r,log:e=>n.push(e)});if(i.hadTargets){for(let e of n)console.log(e);na(i)}else{let e=await aa(t);console.log(ia(process.cwd(),e,{listingFollows:e>0})),e>0&&await Gi({})}return}if(i===`all`){let e=await I();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e)ea(Q(n,`server`),P)&&(await ra(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 ta(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}await ra(t,r);return}let a=B(yt(),i),o=T(a),s=[],c=await $({lockDir:o,force:r,log:e=>s.push(e)});if(na(c),c.hadTargets)for(let e of s)console.log(e);else console.log(ia(a,await aa(o)))})}export{Lt as A,Qr as C,kn as D,An as E,wt as F,Tt as I,yt as L,bt as M,St as N,wn as O,xt as P,vt as R,Q as S,Yr as T,gi as _,Ki as a,ei as b,Ei as c,Di as d,ui as f,hi as g,fi as h,oa as i,Dt as j,On as k,Ci as l,di as m,qi as n,ji as o,_i as p,$ as r,Ni as s,$i as t,Oi as u,li as v,Jr as w,si as x,oi as y,gt as z};