@inkeep/open-knowledge 0.52.4 → 0.52.6

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 (140) hide show
  1. package/dist/{acp-harness-probe-XTgNAWCH.mjs → acp-harness-probe-BFnNFv5O.mjs} +2 -2
  2. package/dist/assets/skills/project/references/linking.md +1 -1
  3. package/dist/cli.mjs +53 -53
  4. package/dist/constants-rtay2E1D.mjs +2 -0
  5. package/dist/git-handle-B7hMkLUm.mjs +1 -0
  6. package/dist/{git-handle--xISIJuo.mjs → git-handle-CSHsjfXr.mjs} +2 -2
  7. package/dist/index.mjs +1 -1
  8. package/dist/{init-BLgGQUiA.mjs → init-Bq2YfcXG.mjs} +4 -4
  9. package/dist/init-C1d1w8CD.mjs +1 -0
  10. package/dist/{launch-json-removal-BY0JfYzW.mjs → launch-json-removal-BghB5Blq.mjs} +2 -2
  11. package/dist/{loader-DFPCRuiv.mjs → loader-CbsfDiyI.mjs} +2 -2
  12. package/dist/loader-DSBs4gIk.mjs +1 -0
  13. package/dist/md-manager-qfeJIs4M.mjs +2 -0
  14. package/dist/{open-browser-CV5L0bD3.mjs → open-browser-jHUUD-04.mjs} +2 -2
  15. package/dist/parse-worker.mjs +1 -1
  16. package/dist/{preview-BuOydejY.mjs → preview-CTscDXn-.mjs} +2 -2
  17. package/dist/preview-D-07D_3m.mjs +1 -0
  18. package/dist/public/assets/{ActivityModeContent-82sBOezj.js → ActivityModeContent-Cv6gFAbZ.js} +1 -1
  19. package/dist/public/assets/{AgentDiffPane-CoeEE99v.js → AgentDiffPane-f4yfPjxM.js} +1 -1
  20. package/dist/public/assets/{AgentThreadClientBinder-DoXKRY3h.js → AgentThreadClientBinder-DyAvjXhp.js} +1 -1
  21. package/dist/public/assets/{ChangedOutsideBadge-D047_w8_.js → ChangedOutsideBadge-COpqJhAk.js} +1 -1
  22. package/dist/public/assets/CodeMirrorPropInput-ka8bDCWm.js +3 -0
  23. package/dist/public/assets/DocumentContext-B-mZSesL.js +38 -0
  24. package/dist/public/assets/{EditorModeToggle-BFLOwOkQ.js → EditorModeToggle-BY-XALtS.js} +1 -1
  25. package/dist/public/assets/{EnableSyncConfirmDialog-DrKJd8P_.js → EnableSyncConfirmDialog-CSvUaM7P.js} +1 -1
  26. package/dist/public/assets/FeedbackForm-DK_xfELf.js +1 -0
  27. package/dist/public/assets/{GraphPanel-CIsyWZZL.js → GraphPanel-Dvip3eEu.js} +1 -1
  28. package/dist/public/assets/{ImportSkillDialog-R8BKwyCS.js → ImportSkillDialog-B9unn5le.js} +1 -1
  29. package/dist/public/assets/{LintConfigEditor-CMXHDFZF.js → LintConfigEditor-CLpn2oN6.js} +1 -1
  30. package/dist/public/assets/ManagedArtifactProperties-B8s7Wxbj.js +1 -0
  31. package/dist/public/assets/ManagedArtifactProperties-DFHHvfBe.js +2 -0
  32. package/dist/public/assets/{McpConsentDialogBody-D6qWh37S.js → McpConsentDialogBody-DaFmSU31.js} +1 -1
  33. package/dist/public/assets/{MermaidDocEditor-DbdolXNy.js → MermaidDocEditor-CzG26H5S.js} +1 -1
  34. package/dist/public/assets/{ReportBugDialogBody-0zuUulQL.js → ReportBugDialogBody-BntcEaST.js} +1 -1
  35. package/dist/public/assets/{SchemaConfigEditor-rEKhSqJM.js → SchemaConfigEditor-Wx7TSdJM.js} +1 -1
  36. package/dist/public/assets/{SessionsHost-CGV_FZVZ.js → SessionsHost-DllDKIBM.js} +2 -2
  37. package/dist/public/assets/{SettingsDialogBody-DPjbScQ8.js → SettingsDialogBody-CXfeaj3f.js} +4 -4
  38. package/dist/public/assets/{ShareBranchSwitchDialog-BHZw8v-i.js → ShareBranchSwitchDialog-CNXPuzjW.js} +1 -1
  39. package/dist/public/assets/{ShareReceiveDialog-CA7GkSOU.js → ShareReceiveDialog-Bl1LD9uu.js} +1 -1
  40. package/dist/public/assets/{ShareReceiveMissDialog-BVb9iCe7.js → ShareReceiveMissDialog-D7PGcXQY.js} +1 -1
  41. package/dist/public/assets/{SkillEditBanner-Dc5M38zl.js → SkillEditBanner-c3RwP7xL.js} +1 -1
  42. package/dist/public/assets/{SkillOriginInline-B-wdZ-wi.js → SkillOriginInline-CWYW0Xok.js} +1 -1
  43. package/dist/public/assets/{SkillToolbarControls-B1VGCLbB.js → SkillToolbarControls-Dd4cQ4wS.js} +1 -1
  44. package/dist/public/assets/{SlidesToolbarControls-DpEF1_8n.js → SlidesToolbarControls-BAXFLZhs.js} +1 -1
  45. package/dist/public/assets/{SourceEditor-BXsOQKW8.js → SourceEditor-CZ3ahEem.js} +1 -1
  46. package/dist/public/assets/{TerminalPanel-D4k0ePYg.js → TerminalPanel-CL4WwuVQ.js} +3 -3
  47. package/dist/public/assets/{TerminalWindowApp-C1Ej4Kb1.js → TerminalWindowApp-ClQ-8h9C.js} +1 -1
  48. package/dist/public/assets/{TextDocEditor-DxhziylX.js → TextDocEditor-BNjKnYbD.js} +1 -1
  49. package/dist/public/assets/{ThreadView-DlpPbPgC.js → ThreadView-BNp1VbUY.js} +1 -1
  50. package/dist/public/assets/{TimelineDiffPane-35Fhuse-.js → TimelineDiffPane-DpnqycEF.js} +1 -1
  51. package/dist/public/assets/{agent-diff-store-BTtYfAZI.js → agent-diff-store-B3_hRSqk.js} +1 -1
  52. package/dist/public/assets/{auth-state-cache-j2uCE1rv.js → auth-state-cache-_N6OPo00.js} +4 -4
  53. package/dist/public/assets/client-version-COJAptxG.js +1 -0
  54. package/dist/public/assets/comment-chips-KfRlmuVu.js +5 -0
  55. package/dist/public/assets/{config-provider-DAD08DXO.js → config-provider-B-vej2jO.js} +2 -2
  56. package/dist/public/assets/{dist-CKFXiBrL.js → dist-DY61IBRu.js} +184 -184
  57. package/dist/public/assets/{doc-paths-aGtYCY4p.js → doc-paths-DopA_npJ.js} +1 -1
  58. package/dist/public/assets/{documents-events-BNjnUfCu.js → documents-events-SnOdQ93W.js} +1 -1
  59. package/dist/public/assets/{file-tree-adapter-BnKrzDCF.js → file-tree-adapter-DTzkonM5.js} +1 -1
  60. package/dist/public/assets/{file-tree-utils-CPfKs0_W.js → file-tree-utils-kvqZaRYy.js} +1 -1
  61. package/dist/public/assets/{folder-config-api-C00aXHgv.js → folder-config-api-Cbk0t_jz.js} +1 -1
  62. package/dist/public/assets/follow-file-BLE7V7Ud.js +4 -0
  63. package/dist/public/assets/i18n-Bpkw9fUi.js +1 -0
  64. package/dist/public/assets/{index-DkaSwI0X.js → index-TxVJhf6q.js} +12 -12
  65. package/dist/public/assets/{lint-config-client-CwpzRrsJ.js → lint-config-client-DVIeXUAy.js} +1 -1
  66. package/dist/public/assets/{markdownlint-rule-browser-DDivenan.js → markdownlint-rule-browser-B1NddhCN.js} +1 -1
  67. package/dist/public/assets/navigation-targets-TK0iEW9x.js +1 -0
  68. package/dist/public/assets/{open-managed-artifact-tab-Dxiu79gQ.js → open-managed-artifact-tab-BxvPyCwa.js} +1 -1
  69. package/dist/public/assets/{pending-receive-nav-store-DTGiCG3P.js → pending-receive-nav-store-EL2zkvzy.js} +1 -1
  70. package/dist/public/assets/prop-types-C7OsjwRF.js +1 -0
  71. package/dist/public/assets/{receive-store-C7RBAUmu.js → receive-store-d3EP_3Yi.js} +1 -1
  72. package/dist/public/assets/{selection-context-D_1ahjGj.js → selection-context-eyohwepk.js} +1 -1
  73. package/dist/public/assets/{skill-actions-BKW-L6YY.js → skill-actions-DfTwp3wO.js} +2 -2
  74. package/dist/public/assets/{skill-scope-D3fqbCKZ.js → skill-scope-CVkmq5Fg.js} +1 -1
  75. package/dist/public/assets/{skills-api-BAB9Nk_K.js → skills-api-B7YnVwGg.js} +1 -1
  76. package/dist/public/assets/{src-Dfy4grTv.js → src-4zYDPBbo.js} +1 -1
  77. package/dist/public/assets/{tag-pill-input-vgqgNkXB.js → tag-pill-input-Qig1Zllm.js} +1 -1
  78. package/dist/public/assets/{target-navigation-intent-DEiFgbdU.js → target-navigation-intent-DEWn_60C.js} +1 -1
  79. package/dist/public/assets/{terminal-cli-display-Du0YYwUl.js → terminal-cli-display-hn510icV.js} +1 -1
  80. package/dist/public/assets/{terminal-launch-events-C5JkD3Qb.js → terminal-launch-events-DTRPoOsC.js} +1 -1
  81. package/dist/public/assets/{terminal-telemetry-Cj_uo6eX.js → terminal-telemetry-CS2iZ-Ui.js} +1 -1
  82. package/dist/public/assets/{typing-burst-detector-vxYjrFWQ.js → typing-burst-detector-CuRfFjXi.js} +3 -3
  83. package/dist/public/assets/{uninstall-C6wmbgyN.js → uninstall-JvJC1VNe.js} +1 -1
  84. package/dist/public/assets/{use-activity-panel-DtCqiYlm.js → use-activity-panel-CfPHTbyU.js} +1 -1
  85. package/dist/public/assets/{use-apply-config-color-theme-DkVlJHc4.js → use-apply-config-color-theme--OSymvV9.js} +1 -1
  86. package/dist/public/assets/{use-collab-url-CpJYowg_.js → use-collab-url-F81QZJY2.js} +1 -1
  87. package/dist/public/assets/{use-live-xterm-theme-DfHZqsch.js → use-live-xterm-theme-C4F8fmV3.js} +1 -1
  88. package/dist/public/assets/{use-open-skill-DdTYxJp4.js → use-open-skill-sNcmJFye.js} +1 -1
  89. package/dist/public/assets/{use-popular-skills-C9TB91tU.js → use-popular-skills-CupHQJgQ.js} +1 -1
  90. package/dist/public/assets/{use-settings-route-D_8EQ_KO.js → use-settings-route-CAFphc2F.js} +1 -1
  91. package/dist/public/assets/{use-skill-origin-BjB7AiHp.js → use-skill-origin-BTS1j6rR.js} +1 -1
  92. package/dist/public/assets/{use-skills-DMV2hvXx.js → use-skills-CSj51ESd.js} +1 -1
  93. package/dist/public/assets/{use-terminal-enabled-D2pvXg6e.js → use-terminal-enabled-s9R0wszj.js} +1 -1
  94. package/dist/public/assets/use-timeline-entry-diff-DJpgJW42.js +6 -0
  95. package/dist/public/assets/{use-workspace-e-krFmvC.js → use-workspace-Pyq7RSuh.js} +1 -1
  96. package/dist/public/index.html +44 -44
  97. package/dist/public/uninstall.html +3 -3
  98. package/dist/{repair-launch-json-BgwsX3Jx.mjs → repair-launch-json-C9xXMVmu.mjs} +2 -2
  99. package/dist/{repair-mcp-configs-CcLsbctb.mjs → repair-mcp-configs-BQ61B77g.mjs} +2 -2
  100. package/dist/{repair-skills-pGap1_gF.mjs → repair-skills-Cdqec7U0.mjs} +2 -2
  101. package/dist/repair-skills-DCg6eBNi.mjs +1 -0
  102. package/dist/{server-lock-CyyeFKIF.mjs → server-lock-CU3-_gnL.mjs} +2 -2
  103. package/dist/server-lock-D833sKBI.mjs +1 -0
  104. package/dist/{skill-teardown-DxeHIPsr.mjs → skill-teardown-CuyNWxzR.mjs} +2 -2
  105. package/dist/{src-DtvO7rZS.mjs → src-BXftUDmM.mjs} +3 -3
  106. package/dist/src-Cxffy8op.mjs +2038 -0
  107. package/dist/{src-Qlsty_8B.mjs → src-D7BnleBG.mjs} +1 -1
  108. package/dist/{src-B8SfUeFe.mjs → src-DE02-xKN.mjs} +122 -122
  109. package/dist/src-DXtT-THQ.mjs +1 -0
  110. package/dist/start-BpRb1mY0.mjs +1 -0
  111. package/dist/start-BwcjNfvA.mjs +12 -0
  112. package/dist/{ui-BQkXNsD0.mjs → ui-ColO8lUq.mjs} +3 -3
  113. package/dist/ui-F9aOCyp-.mjs +1 -0
  114. package/dist/{write-project-skill-DHATTSra.mjs → write-project-skill-U5FHNOHQ.mjs} +3 -3
  115. package/package.json +5 -5
  116. package/dist/constants-DjzJQLPT.mjs +0 -2
  117. package/dist/git-handle-Dt3gdxML.mjs +0 -1
  118. package/dist/init-DRq2NWqE.mjs +0 -1
  119. package/dist/loader-NVyWW4oJ.mjs +0 -1
  120. package/dist/md-manager-RNjkssEV.mjs +0 -2
  121. package/dist/preview-T7rJOVHM.mjs +0 -1
  122. package/dist/public/assets/CodeMirrorPropInput-AfI-A739.js +0 -3
  123. package/dist/public/assets/DocumentContext-RfseIiCK.js +0 -38
  124. package/dist/public/assets/FeedbackForm-CpyB0Ay7.js +0 -1
  125. package/dist/public/assets/ManagedArtifactProperties-BfpBSbt8.js +0 -2
  126. package/dist/public/assets/ManagedArtifactProperties-CaU-7RSA.js +0 -1
  127. package/dist/public/assets/client-version-UVydSM1_.js +0 -1
  128. package/dist/public/assets/comment-chips-CspvZbMA.js +0 -5
  129. package/dist/public/assets/follow-file-ClUkwvTW.js +0 -4
  130. package/dist/public/assets/i18n-DnAdj3V4.js +0 -1
  131. package/dist/public/assets/navigation-targets-BN-b0SwY.js +0 -1
  132. package/dist/public/assets/prop-types-RgJQCViX.js +0 -1
  133. package/dist/public/assets/use-timeline-entry-diff-Do0ZBwge.js +0 -6
  134. package/dist/repair-skills-uGkRmBYx.mjs +0 -1
  135. package/dist/server-lock-DwSyFoTt.mjs +0 -1
  136. package/dist/src-BAzYWv6h.mjs +0 -1
  137. package/dist/src-DZEg-Zy7.mjs +0 -2038
  138. package/dist/start-CTUHFYX2.mjs +0 -1
  139. package/dist/start-HJ61fNSx.mjs +0 -12
  140. package/dist/ui-BkhU6wt_.mjs +0 -1
@@ -1,2 +1,2 @@
1
- import{d as e,v as t}from"./init-BLgGQUiA.mjs";import{i as n,o as r,p as i}from"./write-project-skill-DHATTSra.mjs";import{t as a}from"./mcp-migrate-event-BsswfOLm.mjs";import{homedir as o}from"node:os";function s(e){let t=e.logger??u,i=e.home??o(),a=[];if(e.reclaimDisableEnv===`1`)return t({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of n){let n=r[o],s=c(()=>n.configPath(``,i));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:n,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),n.projectConfigPath){let r=n.projectConfigPath,i=c(()=>r(e.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:n,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(n){let r={scope:n.scope,editorId:n.editorId,configPath:n.configPath},o=e(n.target,n.cwd,n.home,n.configPathOverride);if(o===null)return{...r,outcome:`no-entry`};if(i(o))return{...r,outcome:`canonical`};n.logger(a({scope:n.scope,surface:`cli-repair`,editorId:n.editorId,configPath:n.configPath,priorEntry:o}));let s=t(n.target,n.cwd,{mode:`published`,skipAvailabilityCheck:!0},n.home,n.configPathOverride);if(s.action===`failed`){let e=s.error??`unknown write failure`;return n.logger({event:`mcp-config-repair-write-failed`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,error:e}),{...r,outcome:`write-failed`,error:e}}return s.action===`declined`?(n.logger({event:`mcp-config-repair-declined`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,reason:s.declineReason}),{...r,outcome:`declined`}):{...r,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
2
- //# sourceMappingURL=repair-mcp-configs-CcLsbctb.mjs.map
1
+ import{d as e,v as t}from"./init-Bq2YfcXG.mjs";import{i as n,o as r,p as i}from"./write-project-skill-U5FHNOHQ.mjs";import{t as a}from"./mcp-migrate-event-BsswfOLm.mjs";import{homedir as o}from"node:os";function s(e){let t=e.logger??u,i=e.home??o(),a=[];if(e.reclaimDisableEnv===`1`)return t({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of n){let n=r[o],s=c(()=>n.configPath(``,i));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:n,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),n.projectConfigPath){let r=n.projectConfigPath,i=c(()=>r(e.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:n,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(n){let r={scope:n.scope,editorId:n.editorId,configPath:n.configPath},o=e(n.target,n.cwd,n.home,n.configPathOverride);if(o===null)return{...r,outcome:`no-entry`};if(i(o))return{...r,outcome:`canonical`};n.logger(a({scope:n.scope,surface:`cli-repair`,editorId:n.editorId,configPath:n.configPath,priorEntry:o}));let s=t(n.target,n.cwd,{mode:`published`,skipAvailabilityCheck:!0},n.home,n.configPathOverride);if(s.action===`failed`){let e=s.error??`unknown write failure`;return n.logger({event:`mcp-config-repair-write-failed`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,error:e}),{...r,outcome:`write-failed`,error:e}}return s.action===`declined`?(n.logger({event:`mcp-config-repair-declined`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,reason:s.declineReason}),{...r,outcome:`declined`}):{...r,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
2
+ //# sourceMappingURL=repair-mcp-configs-BQ61B77g.mjs.map
@@ -1,4 +1,4 @@
1
- import{z as e}from"./src-B8SfUeFe.mjs";import{Cr as t,_r as n,cr as r,fr as i,lr as a,mr as o,pr as s,wr as c,yr as l}from"./src-DZEg-Zy7.mjs";import{t as u}from"./esm-DmX1RzAi.mjs";import{n as d,s as f,t as p}from"./colors-BsmVIwfM.mjs";import{o as m,s as h,t as g}from"./write-project-skill-DHATTSra.mjs";import{n as _,r as v,t as y}from"./skill-teardown-DxeHIPsr.mjs";import{dirname as b,join as x,relative as S,resolve as C}from"node:path";import{existsSync as w,mkdirSync as T,readFileSync as E,readdirSync as D,rmSync as O,statSync as k,writeFileSync as A}from"node:fs";import{homedir as j}from"node:os";import{createInterface as M}from"node:readline/promises";const N={existsSync:e=>w(e),isDirectory:e=>{try{return k(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>D(e),readFileSync:e=>E(e),writeFileSync:(e,t)=>{A(e,t)},mkdirSync:(e,t)=>{T(e,t)},rmSync:(e,t)=>{O(e,t)}},P={resolveProjectBundledSkillDir:()=>l(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>l(e,{checkDesktop:!1}),readBundledVersion:()=>a(),readRecordedVersion:e=>i(e,`cli-hosts`),writeRecordedVersion:(e,t)=>o(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>n(e),readBundleDecision:(e,t)=>r(e,t),writeBundleDecision:(e,t,n)=>s(e,t,n),removeBundleFromDisk:(e,t)=>v(e,t)};function F(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function I(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(b(t),{recursive:!0}),L(e,t,n)}function L(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=x(e,r),a=x(t,r);n.isDirectory(i)?L(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function R(e,t,n,r,i,a){let o=[],s=x(e,`.agents`,`skills`,t),c=!1;if(r.existsSync(s))o.push({kind:`central`,path:s,outcome:`skipped-present`});else try{I(n,s,r),c=!0,o.push({kind:`central`,path:s,outcome:`written`}),i({event:`user-skill-reclaim-central-written`,scope:`user`,path:s,preexisting:!1,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`central`,path:s,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-central-failed`,scope:`user`,path:s,error:t})}for(let c of h){let l=x(e,c.hostDir),u=x(l,`skills`,t);if(u===s){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-collapsed-with-central`});continue}if(!r.existsSync(l)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-host-absent`});continue}if(r.existsSync(u)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-present`});continue}try{I(n,u,r),o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`written`}),i({event:`user-skill-reclaim-host-written`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,preexisting:!1,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-host-failed`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,error:t})}}return{entries:o,centralWritten:c}}function z(e,t){if(!e)return!1;try{return t.existsSync(e)?t.readFileSync(e).toString(`utf8`).includes(`# ok-mcp-`):!1}catch{return!1}}function B(e,t,n,r){let i;try{i=t.resolveProjectBundledSkillDir()}catch(e){return r({event:`project-skill-reclaim-bundle-missing`,scope:`project`,error:e instanceof Error?e.message:String(e)}),{outcome:`skipped`,reason:`bundle-missing`}}let a=[];for(let t of h){let o=x(e,t.hostDir,`skills`,`open-knowledge`),s=x(o,`SKILL.md`);if(n.existsSync(s)){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`present`});continue}let c=m[t.editorId]?.projectConfigPath?.(e);if(!z(c,n)){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`no-token`}),r({event:`project-skill-reclaim-no-token`,scope:`project`,editorId:t.editorId,path:o});continue}try{g(o,e),I(i,o,n),a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`created`}),r({event:`project-skill-reclaim-created`,scope:`project`,editorId:t.editorId,path:o})}catch(e){let n=e instanceof Error?e.message:String(e);a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`failed`,error:n}),r({event:`project-skill-reclaim-failed`,scope:`project`,editorId:t.editorId,path:o,error:n})}}return{outcome:`done`,entries:a}}async function V(n,r,i,a){let o=e=>{r.recordEvent(e).catch(()=>{})},s=()=>new Date().toISOString(),l;try{l=await r.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return a({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),o({ts:s(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let u;try{u=await r.readRecordedVersion(n)}catch(e){a({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),u=null}let d=[],f=null;for(let e of c)try{d.push({id:e,sourceDir:r.resolveUserBundledSkillDir(e)})}catch(e){f=e instanceof Error?e.message:String(e)}if(d.length===0)return a({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:f??`no user-global bundles`}),o({ts:s(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${f}`}),{outcome:`skipped`,reason:`bundle-missing`};let p=[];for(let o of d){let s=t[o.id],c=i.existsSync(x(n,`.agents`,`skills`,s)),l=await r.readBundleDecision(n,s).catch(()=>null);if(!e(l,{installedOnDisk:c})){if(c)try{r.removeBundleFromDisk(n,o.id),a({event:`user-skill-reclaim-bundle-declined-removed`,scope:`user`,bundle:o.id})}catch(e){a({event:`user-skill-reclaim-bundle-remove-failed`,scope:`user`,bundle:o.id,error:e instanceof Error?e.message:String(e)})}continue}if(l===null&&c)try{await r.writeBundleDecision(n,s,!0)}catch(e){a({event:`user-skill-reclaim-grandfather-write-failed`,scope:`user`,bundle:o.id,error:e instanceof Error?e.message:String(e)})}p.push(o)}if(p.length===0)return{outcome:`skipped`,reason:`all-bundles-declined`};let m=p.every(e=>i.existsSync(x(n,`.agents`,`skills`,t[e.id])));if(u!==null&&u===l&&m)return a({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:l}),{outcome:`skipped`,reason:`version-current`};let h=[],g=d.length===c.length,_=[];for(let{id:e,sourceDir:r}of p){let o=R(n,t[e],r,i,a,l);h.push(...o.entries),_.push({id:e,centralWritten:o.centralWritten})}let v=h.some(e=>e.kind===`central`&&e.outcome===`failed`);if(g&&!v){let e=null;try{await r.writeRecordedVersion(n,l),a({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:l})}catch(t){e=t instanceof Error?t.message:String(t),a({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:l,error:e})}for(let{id:t,centralWritten:n}of _)o({ts:s(),surface:`cli-start`,target:`cli-hosts`,bundle:t,outcome:e===null?n?`installed`:`skip-current`:`failed`,version:l,...e===null?{}:{reason:`state-write-failed:${e}`}})}else{let e=h.some(e=>e.kind===`host`&&e.outcome===`failed`);o({ts:s(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:l,reason:g?e?`all-writes-failed`:`central-write-failed`:`bundle-unresolved`})}return{outcome:`done`,version:l,entries:h}}async function H(e){let t=e.logger??F,n=e.fs??N,r=e.home??j(),i={...P,...e.deps};if(e.reclaimDisableEnv===`1`)return t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`};let a=B(e.projectDir,i,n,t),o=await V(r,i,n,t),s=_(r),c=[],l=!1,u=!1;if(s.skillDirs.length>0||s.emptyDirs.length>0)if(e.confirmLegacyCleanup&&await e.confirmLegacyCleanup(s)){try{c=y(r,s)}catch(e){u=!0,t({event:`legacy-fanout-cleanup-refused`,scope:`user`,error:e instanceof Error?e.message:String(e)})}for(let e of c)t({event:`legacy-fanout-path-removed`,scope:`user`,path:e})}else l=!0,t({event:`legacy-fanout-cleanup-declined`,scope:`user`});return{status:`done`,project:a,user:o,legacySwept:c,legacyCleanupDeclined:l,legacyCleanupFailed:u}}function U(e){return e.status===`skipped`?e.reason===`reclaim-disabled`?0:1:e.project.outcome===`skipped`||e.user.outcome===`skipped`&&e.user.reason!==`version-current`&&e.user.reason!==`all-bundles-declined`||e.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function W(e){if(e.status===`skipped`)return`Skipped: ${e.reason}`;let t=[`Skill reclaim complete.`];if(e.project.outcome===`done`){let n=e.project.entries.filter(e=>e.outcome===`present`).length,r=e.project.entries.filter(e=>e.outcome===`created`).length,i=e.project.entries.filter(e=>e.outcome===`no-token`).length,a=e.project.entries.filter(e=>e.outcome===`failed`).length;t.push(` Project: ${n} present, ${r} created, ${i} no-token, ${a} failed.`)}else t.push(` Project: skipped (${e.project.reason}).`);if(e.user.outcome===`done`){let n=e.user.entries.filter(e=>e.outcome===`written`).length,r=e.user.entries.filter(e=>e.outcome===`skipped-present`).length,i=e.user.entries.filter(e=>e.outcome===`skipped-host-absent`||e.outcome===`skipped-collapsed-with-central`).length,a=e.user.entries.filter(e=>e.outcome===`failed`).length;t.push(` User (${e.user.version}): ${n} written, ${r} present, ${i} skipped, ${a} failed.`)}else t.push(` User: skipped (${e.user.reason}).`);return e.legacySwept.length>0?t.push(` Cleanup: removed ${e.legacySwept.length} path(s) from a pre-0.42 install.`):e.legacyCleanupFailed?t.push(` Cleanup: failed — see logs; pre-0.42 directories left in place.`):e.legacyCleanupDeclined&&t.push(` Cleanup: declined — pre-0.42 directories left in place.`),t.join(`
1
+ import{U as e}from"./src-DE02-xKN.mjs";import{Cr as t,_r as n,cr as r,fr as i,lr as a,mr as o,pr as s,wr as c,yr as l}from"./src-Cxffy8op.mjs";import{t as u}from"./esm-DmX1RzAi.mjs";import{n as d,s as f,t as p}from"./colors-BsmVIwfM.mjs";import{o as m,s as h,t as g}from"./write-project-skill-U5FHNOHQ.mjs";import{n as _,r as v,t as y}from"./skill-teardown-CuyNWxzR.mjs";import{dirname as b,join as x,relative as S,resolve as C}from"node:path";import{existsSync as w,mkdirSync as T,readFileSync as E,readdirSync as D,rmSync as O,statSync as k,writeFileSync as A}from"node:fs";import{homedir as j}from"node:os";import{createInterface as M}from"node:readline/promises";const N={existsSync:e=>w(e),isDirectory:e=>{try{return k(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>D(e),readFileSync:e=>E(e),writeFileSync:(e,t)=>{A(e,t)},mkdirSync:(e,t)=>{T(e,t)},rmSync:(e,t)=>{O(e,t)}},P={resolveProjectBundledSkillDir:()=>l(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>l(e,{checkDesktop:!1}),readBundledVersion:()=>a(),readRecordedVersion:e=>i(e,`cli-hosts`),writeRecordedVersion:(e,t)=>o(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>n(e),readBundleDecision:(e,t)=>r(e,t),writeBundleDecision:(e,t,n)=>s(e,t,n),removeBundleFromDisk:(e,t)=>v(e,t)};function F(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function I(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(b(t),{recursive:!0}),L(e,t,n)}function L(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=x(e,r),a=x(t,r);n.isDirectory(i)?L(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function R(e,t,n,r,i,a){let o=[],s=x(e,`.agents`,`skills`,t),c=!1;if(r.existsSync(s))o.push({kind:`central`,path:s,outcome:`skipped-present`});else try{I(n,s,r),c=!0,o.push({kind:`central`,path:s,outcome:`written`}),i({event:`user-skill-reclaim-central-written`,scope:`user`,path:s,preexisting:!1,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`central`,path:s,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-central-failed`,scope:`user`,path:s,error:t})}for(let c of h){let l=x(e,c.hostDir),u=x(l,`skills`,t);if(u===s){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-collapsed-with-central`});continue}if(!r.existsSync(l)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-host-absent`});continue}if(r.existsSync(u)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-present`});continue}try{I(n,u,r),o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`written`}),i({event:`user-skill-reclaim-host-written`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,preexisting:!1,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-host-failed`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,error:t})}}return{entries:o,centralWritten:c}}function z(e,t){if(!e)return!1;try{return t.existsSync(e)?t.readFileSync(e).toString(`utf8`).includes(`# ok-mcp-`):!1}catch{return!1}}function B(e,t,n,r){let i;try{i=t.resolveProjectBundledSkillDir()}catch(e){return r({event:`project-skill-reclaim-bundle-missing`,scope:`project`,error:e instanceof Error?e.message:String(e)}),{outcome:`skipped`,reason:`bundle-missing`}}let a=[];for(let t of h){let o=x(e,t.hostDir,`skills`,`open-knowledge`),s=x(o,`SKILL.md`);if(n.existsSync(s)){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`present`});continue}let c=m[t.editorId]?.projectConfigPath?.(e);if(!z(c,n)){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`no-token`}),r({event:`project-skill-reclaim-no-token`,scope:`project`,editorId:t.editorId,path:o});continue}try{g(o,e),I(i,o,n),a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`created`}),r({event:`project-skill-reclaim-created`,scope:`project`,editorId:t.editorId,path:o})}catch(e){let n=e instanceof Error?e.message:String(e);a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`failed`,error:n}),r({event:`project-skill-reclaim-failed`,scope:`project`,editorId:t.editorId,path:o,error:n})}}return{outcome:`done`,entries:a}}async function V(n,r,i,a){let o=e=>{r.recordEvent(e).catch(()=>{})},s=()=>new Date().toISOString(),l;try{l=await r.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return a({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),o({ts:s(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let u;try{u=await r.readRecordedVersion(n)}catch(e){a({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),u=null}let d=[],f=null;for(let e of c)try{d.push({id:e,sourceDir:r.resolveUserBundledSkillDir(e)})}catch(e){f=e instanceof Error?e.message:String(e)}if(d.length===0)return a({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:f??`no user-global bundles`}),o({ts:s(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${f}`}),{outcome:`skipped`,reason:`bundle-missing`};let p=[];for(let o of d){let s=t[o.id],c=i.existsSync(x(n,`.agents`,`skills`,s)),l=await r.readBundleDecision(n,s).catch(()=>null);if(!e(l,{installedOnDisk:c})){if(c)try{r.removeBundleFromDisk(n,o.id),a({event:`user-skill-reclaim-bundle-declined-removed`,scope:`user`,bundle:o.id})}catch(e){a({event:`user-skill-reclaim-bundle-remove-failed`,scope:`user`,bundle:o.id,error:e instanceof Error?e.message:String(e)})}continue}if(l===null&&c)try{await r.writeBundleDecision(n,s,!0)}catch(e){a({event:`user-skill-reclaim-grandfather-write-failed`,scope:`user`,bundle:o.id,error:e instanceof Error?e.message:String(e)})}p.push(o)}if(p.length===0)return{outcome:`skipped`,reason:`all-bundles-declined`};let m=p.every(e=>i.existsSync(x(n,`.agents`,`skills`,t[e.id])));if(u!==null&&u===l&&m)return a({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:l}),{outcome:`skipped`,reason:`version-current`};let h=[],g=d.length===c.length,_=[];for(let{id:e,sourceDir:r}of p){let o=R(n,t[e],r,i,a,l);h.push(...o.entries),_.push({id:e,centralWritten:o.centralWritten})}let v=h.some(e=>e.kind===`central`&&e.outcome===`failed`);if(g&&!v){let e=null;try{await r.writeRecordedVersion(n,l),a({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:l})}catch(t){e=t instanceof Error?t.message:String(t),a({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:l,error:e})}for(let{id:t,centralWritten:n}of _)o({ts:s(),surface:`cli-start`,target:`cli-hosts`,bundle:t,outcome:e===null?n?`installed`:`skip-current`:`failed`,version:l,...e===null?{}:{reason:`state-write-failed:${e}`}})}else{let e=h.some(e=>e.kind===`host`&&e.outcome===`failed`);o({ts:s(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:l,reason:g?e?`all-writes-failed`:`central-write-failed`:`bundle-unresolved`})}return{outcome:`done`,version:l,entries:h}}async function H(e){let t=e.logger??F,n=e.fs??N,r=e.home??j(),i={...P,...e.deps};if(e.reclaimDisableEnv===`1`)return t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`};let a=B(e.projectDir,i,n,t),o=await V(r,i,n,t),s=_(r),c=[],l=!1,u=!1;if(s.skillDirs.length>0||s.emptyDirs.length>0)if(e.confirmLegacyCleanup&&await e.confirmLegacyCleanup(s)){try{c=y(r,s)}catch(e){u=!0,t({event:`legacy-fanout-cleanup-refused`,scope:`user`,error:e instanceof Error?e.message:String(e)})}for(let e of c)t({event:`legacy-fanout-path-removed`,scope:`user`,path:e})}else l=!0,t({event:`legacy-fanout-cleanup-declined`,scope:`user`});return{status:`done`,project:a,user:o,legacySwept:c,legacyCleanupDeclined:l,legacyCleanupFailed:u}}function U(e){return e.status===`skipped`?e.reason===`reclaim-disabled`?0:1:e.project.outcome===`skipped`||e.user.outcome===`skipped`&&e.user.reason!==`version-current`&&e.user.reason!==`all-bundles-declined`||e.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function W(e){if(e.status===`skipped`)return`Skipped: ${e.reason}`;let t=[`Skill reclaim complete.`];if(e.project.outcome===`done`){let n=e.project.entries.filter(e=>e.outcome===`present`).length,r=e.project.entries.filter(e=>e.outcome===`created`).length,i=e.project.entries.filter(e=>e.outcome===`no-token`).length,a=e.project.entries.filter(e=>e.outcome===`failed`).length;t.push(` Project: ${n} present, ${r} created, ${i} no-token, ${a} failed.`)}else t.push(` Project: skipped (${e.project.reason}).`);if(e.user.outcome===`done`){let n=e.user.entries.filter(e=>e.outcome===`written`).length,r=e.user.entries.filter(e=>e.outcome===`skipped-present`).length,i=e.user.entries.filter(e=>e.outcome===`skipped-host-absent`||e.outcome===`skipped-collapsed-with-central`).length,a=e.user.entries.filter(e=>e.outcome===`failed`).length;t.push(` User (${e.user.version}): ${n} written, ${r} present, ${i} skipped, ${a} failed.`)}else t.push(` User: skipped (${e.user.reason}).`);return e.legacySwept.length>0?t.push(` Cleanup: removed ${e.legacySwept.length} path(s) from a pre-0.42 install.`):e.legacyCleanupFailed?t.push(` Cleanup: failed — see logs; pre-0.42 directories left in place.`):e.legacyCleanupDeclined&&t.push(` Cleanup: declined — pre-0.42 directories left in place.`),t.join(`
2
2
  `)}function G(){return new u(`repair-skills`).description("Refresh bundled SKILL.md files for installed AI editors (project-local + user-global). Runs automatically during `ok start`; this command forces an explicit sweep.").option(`-y, --yes`,`Skip the confirmation prompt for removing directories left by a pre-0.42 install.`).action(async e=>{let t=await H({projectDir:C(process.cwd()),reclaimDisableEnv:process.env.OK_RECLAIM_DISABLE??null,confirmLegacyCleanup:t=>K(t,{yes:e.yes===!0})});process.stdout.write(`${W(t)}\n`),process.exitCode=U(t)})}async function K(e,t){let n=j(),r=e=>`~/${S(n,e)}`,i=t.input??process.stdin,a=[``,p(`A previous version of OpenKnowledge installed its skill into agent tools you may never have used.`),d(`(Versions before 0.42 wrote to every host a third-party installer knew about — see issue #820.)`)];if(e.skillDirs.length>0&&a.push(``,`${p(`Remove OpenKnowledge skills:`)} ${e.skillDirs.length}`,...e.skillDirs.map(e=>` ${r(e)}`)),e.emptyDirs.length>0){let t=e.skillDirs.length>0?`Then remove these, which hold nothing else once the above are gone:`:`Remove these empty directories, left behind by that install:`;a.push(``,`${p(t)} ${e.emptyDirs.length}`,...e.emptyDirs.map(e=>` ${r(e)}`))}if(a.push(``,d(`Nothing outside these paths is touched. A directory that still holds anything is kept.`)),process.stdout.write(`${a.join(`
3
3
  `)}\n`),t.yes)return!0;if(!i.isTTY)return process.stdout.write(`${f("Not a terminal — skipping cleanup. Re-run with `ok repair-skills --yes` to remove these.")}\n`),!1;let o=M({input:i,output:process.stdout});try{let e=(await o.question(`\n${p(`Remove them?`)} ${d(`[y/N] `)}`)).trim().toLowerCase();return e===`y`||e===`yes`}finally{o.close()}}export{G as n,H as t};
4
- //# sourceMappingURL=repair-skills-pGap1_gF.mjs.map
4
+ //# sourceMappingURL=repair-skills-Cdqec7U0.mjs.map
@@ -0,0 +1 @@
1
+ import{t as e}from"./repair-skills-Cdqec7U0.mjs";export{e as repairSkills};
@@ -1,2 +1,2 @@
1
- import"./src-B8SfUeFe.mjs";import{r as e}from"./logger-CnfEoHs1.mjs";import{dirname as t,join as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{closeSync as a,existsSync as o,mkdirSync as s,openSync as c,readFileSync as l,unlinkSync as u,writeFileSync as d,writeSync as f}from"node:fs";import{homedir as p,hostname as m}from"node:os";import{randomUUID as h}from"node:crypto";function g(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function _(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function v(e){return new URL(e.url??``,`http://localhost`).searchParams}function y(e){let t=e?.code;return typeof t==`string`?t:void 0}const b=/^[A-Za-z0-9-]{8,64}$/;let x=null;function S(e){return n(e??p(),`.ok`,`machine-id`)}function C(n){if(n===void 0&&x!==null)return x;let r=S(n),i=null;try{let e=l(r,`utf-8`).trim();b.test(e)&&(i=e)}catch{}if(i===null){i=h();try{s(t(r),{recursive:!0}),d(r,`${i}\n`,{encoding:`utf-8`,mode:384})}catch(t){e(`machine-id`).warn({path:r,err:t},`Failed to persist ${r} — using an ephemeral per-process id; lock ownership checks will fail closed (collision) instead of recognizing this machine: ${t instanceof Error?t.message:String(t)}`)}}return n===void 0&&(x=i),i}function w(){try{let e=r(t(i(import.meta.url)),`..`,`package.json`),n=JSON.parse(l(e,`utf-8`));if(typeof n.version==`string`&&n.version.length>0)return n.version}catch{}return`0.0.0-unknown`}const T=w(),E=1,D=e(`process-lock`);var O=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running at ${e.url??`port ${e.port}`} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function k(e,t){return r(e,`${t}.lock`)}const A=new Map;function j(e){A.set(e,(A.get(e)??0)+1)}function M(e){let t=A.get(e);return t===void 0||t<=1?(A.delete(e),!0):(A.set(e,t-1),!1)}function N(e){return typeof e.machineId==`string`?e.machineId===C():e.hostname===m()}const P=new Set;let F=!1;function I(e){P.add(e),!F&&(F=!0,process.on(`exit`,()=>{for(let e of P)try{let t=JSON.parse(l(e,`utf-8`));if(t?.pid!==process.pid||typeof t.machineId==`string`&&t.machineId!==C()||t.machineId===void 0&&typeof t.hostname==`string`&&t.hostname!==m())continue;u(e)}catch{}}))}function L(e,t){try{let n=JSON.parse(l(e,`utf-8`));return n&&typeof n==`object`&&_(n.pid)?n:(D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null}}function R(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;s(n,{recursive:!0});let l=k(n,t),p={pid:process.pid,hostname:m(),port:r.port,...r.url!==void 0&&{url:r.url},startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,machineId:C(),...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??T},h=JSON.stringify(p,null,2);for(let e=0;e<3;e++){if(!o(l))try{let e=c(l,`wx`,384);try{f(e,h)}finally{a(e)}return j(l),I(l),z({lockName:t,lockDir:n,lockPath:l})}catch(e){if(y(e)!==`EEXIST`)throw e}let e=L(l,i);if(e){if(N(e)&&e.pid===process.pid)return d(l,h,{encoding:`utf-8`,mode:384}),j(l),I(l),z({lockName:t,lockDir:n,lockPath:l});if(g(e.pid))throw new O(e,l,t);D.warn({pid:e.pid,host:e.hostname},`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{u(l)}catch{}}throw Error(`${i} Failed to acquire ${l} after 3 attempts (concurrent acquire contention).`)}function z(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>q({lockName:t,lockDir:n}),updatePort:(e,r)=>H({lockName:t,lockDir:n,port:e,url:r})}}function B(e){let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`http:`&&t.protocol!==`https:`)return null;let n=t.hostname;return n===`localhost`||n===`[::1]`||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n)?t.origin:null}function V(e,t){if(typeof e.url==`string`&&e.url.length>0){let t=B(e.url);if(t!==null)return t}if(e.port>0){let n=t?.fallbackHost??`localhost`;return`http://${n===`0.0.0.0`||n===`::`?`localhost`:n.includes(`:`)&&!n.startsWith(`[`)?`[${n}]`:n}:${e.port}`}return null}function H(e){let{lockName:t,lockDir:n,port:r,url:i}=e,a=`[${t}-lock]`,s=k(n,t);if(!o(s)){D.warn({lockPath:s},`${a} Lock file missing at ${s} during port update — skipping`);return}let c;try{let e=JSON.parse(l(s,`utf-8`));if(!e||typeof e!=`object`||!_(e.pid)){D.warn({lockPath:s},`${a} Corrupt lock at ${s} during port update — skipping`);return}c=e}catch{D.warn({lockPath:s},`${a} Unreadable lock at ${s} during port update — skipping`);return}if(c.pid===process.pid&&N(c)){c.port=r,i===void 0?delete c.url:c.url=i;try{d(s,JSON.stringify(c,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:s,err:e},`${a} Failed to update port in ${s}: ${e instanceof Error?e.message:String(e)}`)}}}function U(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=k(n,t);if((A.get(i)??0)>1)return;let a;try{let e=JSON.parse(l(i,`utf-8`));if(!e||typeof e!=`object`||!_(e.pid)){D.warn({lockPath:i},`${r} Corrupt lock at ${i} during draining mark — skipping`);return}a=e}catch(e){y(e)!==`ENOENT`&&D.warn({lockPath:i,err:e},`${r} Unreadable lock at ${i} during draining mark — skipping: ${e instanceof Error?e.message:String(e)}`);return}if(a.pid===process.pid&&N(a)&&a.draining!==!0){a.draining=!0;try{d(i,JSON.stringify(a,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:i,err:e},`${r} Failed to mark ${i} draining: ${e instanceof Error?e.message:String(e)}`)}}}function W(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!o(r))return null;let i;try{let e=JSON.parse(l(r,`utf-8`));if(!e||typeof e!=`object`||!_(e.pid))return null;i=e}catch{return null}if(!N(i))return null;if(!g(i.pid)){try{u(r)}catch{}return null}return i}function G(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!o(r))return{status:`absent`};let i;try{i=JSON.parse(l(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!_(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let s={pid:a.pid,hostname:a.hostname,port:a.port,url:typeof a.url==`string`?a.url:void 0,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,machineId:typeof a.machineId==`string`?a.machineId:void 0,draining:a.draining===!0?!0:void 0,capabilities:Array.isArray(a.capabilities)&&a.capabilities.every(e=>typeof e==`string`)?a.capabilities:void 0,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(!N(s))return{status:`stale`,lock:s};if(!g(s.pid)){try{u(r)}catch{}return{status:`stale`,lock:s}}return s.protocolVersion===void 0||s.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:s}}async function K(e){let{lockName:t,lockDir:n}=e,r=e.timeoutMs??1e4,i=e.pollIntervalMs??100,a=e.readLock??(()=>W({lockName:t,lockDir:n})),o=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=a();if(s===null||s.draining!==!0)return`no-drain`;let c=Date.now()+r;for(;Date.now()<c;){await o(i);let e=a();if(e===null)return`released`;if(e.draining!==!0)return`no-drain`}return`timeout`}function q(e){let{lockName:t,lockDir:n,deferUnlinkToExit:r=!1}=e,i=`[${t}-lock]`,a=k(n,t);if(M(a)){if(r){U({lockName:t,lockDir:n});return}if(o(a))try{let e=JSON.parse(l(a,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||!N(e))return;u(a),P.delete(a)}catch(e){D.warn({lockPath:a,err:e},`${i} Failed to release ${a}: ${e instanceof Error?e.message:String(e)}`)}}}var J=class extends O{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function Y(e,t){try{return R({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof O&&e.lockName===`server`?new J(e.existing,e.lockPath):e}}function X(e,t,n){H({lockName:`server`,lockDir:e,port:t,url:n})}function Z(e){return W({lockName:`server`,lockDir:e})}function Q(e,t){q({lockName:`server`,lockDir:e,...t})}function $(e){U({lockName:`server`,lockDir:e})}function ee(e,t){return K({lockName:`server`,lockDir:e,...t})}export{_ as C,g as S,T as _,Q as a,y as b,O as c,k as d,U as f,H as g,q as h,Z as i,R as l,G as m,Y as n,X as o,W as p,$ as r,ee as s,J as t,V as u,E as v,v as x,C as y};
2
- //# sourceMappingURL=server-lock-CyyeFKIF.mjs.map
1
+ import"./src-DE02-xKN.mjs";import{r as e}from"./logger-CnfEoHs1.mjs";import{dirname as t,join as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{closeSync as a,existsSync as o,mkdirSync as s,openSync as c,readFileSync as l,unlinkSync as u,writeFileSync as d,writeSync as f}from"node:fs";import{homedir as p,hostname as m}from"node:os";import{randomUUID as h}from"node:crypto";function g(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function _(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function v(e){return new URL(e.url??``,`http://localhost`).searchParams}function y(e){let t=e?.code;return typeof t==`string`?t:void 0}const b=/^[A-Za-z0-9-]{8,64}$/;let x=null;function S(e){return n(e??p(),`.ok`,`machine-id`)}function C(n){if(n===void 0&&x!==null)return x;let r=S(n),i=null;try{let e=l(r,`utf-8`).trim();b.test(e)&&(i=e)}catch{}if(i===null){i=h();try{s(t(r),{recursive:!0}),d(r,`${i}\n`,{encoding:`utf-8`,mode:384})}catch(t){e(`machine-id`).warn({path:r,err:t},`Failed to persist ${r} — using an ephemeral per-process id; lock ownership checks will fail closed (collision) instead of recognizing this machine: ${t instanceof Error?t.message:String(t)}`)}}return n===void 0&&(x=i),i}function w(){try{let e=r(t(i(import.meta.url)),`..`,`package.json`),n=JSON.parse(l(e,`utf-8`));if(typeof n.version==`string`&&n.version.length>0)return n.version}catch{}return`0.0.0-unknown`}const T=w(),E=1,D=e(`process-lock`);var O=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running at ${e.url??`port ${e.port}`} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function k(e,t){return r(e,`${t}.lock`)}const A=new Map;function j(e){A.set(e,(A.get(e)??0)+1)}function M(e){let t=A.get(e);return t===void 0||t<=1?(A.delete(e),!0):(A.set(e,t-1),!1)}function N(e){return typeof e.machineId==`string`?e.machineId===C():e.hostname===m()}const P=new Set;let F=!1;function I(e){P.add(e),!F&&(F=!0,process.on(`exit`,()=>{for(let e of P)try{let t=JSON.parse(l(e,`utf-8`));if(t?.pid!==process.pid||typeof t.machineId==`string`&&t.machineId!==C()||t.machineId===void 0&&typeof t.hostname==`string`&&t.hostname!==m())continue;u(e)}catch{}}))}function L(e,t){try{let n=JSON.parse(l(e,`utf-8`));return n&&typeof n==`object`&&_(n.pid)?n:(D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null}}function R(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;s(n,{recursive:!0});let l=k(n,t),p={pid:process.pid,hostname:m(),port:r.port,...r.url!==void 0&&{url:r.url},startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,machineId:C(),...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??T},h=JSON.stringify(p,null,2);for(let e=0;e<3;e++){if(!o(l))try{let e=c(l,`wx`,384);try{f(e,h)}finally{a(e)}return j(l),I(l),z({lockName:t,lockDir:n,lockPath:l})}catch(e){if(y(e)!==`EEXIST`)throw e}let e=L(l,i);if(e){if(N(e)&&e.pid===process.pid)return d(l,h,{encoding:`utf-8`,mode:384}),j(l),I(l),z({lockName:t,lockDir:n,lockPath:l});if(g(e.pid))throw new O(e,l,t);D.warn({pid:e.pid,host:e.hostname},`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{u(l)}catch{}}throw Error(`${i} Failed to acquire ${l} after 3 attempts (concurrent acquire contention).`)}function z(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>q({lockName:t,lockDir:n}),updatePort:(e,r)=>H({lockName:t,lockDir:n,port:e,url:r})}}function B(e){let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`http:`&&t.protocol!==`https:`)return null;let n=t.hostname;return n===`localhost`||n===`[::1]`||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n)?t.origin:null}function V(e,t){if(typeof e.url==`string`&&e.url.length>0){let t=B(e.url);if(t!==null)return t}if(e.port>0){let n=t?.fallbackHost??`localhost`;return`http://${n===`0.0.0.0`||n===`::`?`localhost`:n.includes(`:`)&&!n.startsWith(`[`)?`[${n}]`:n}:${e.port}`}return null}function H(e){let{lockName:t,lockDir:n,port:r,url:i}=e,a=`[${t}-lock]`,s=k(n,t);if(!o(s)){D.warn({lockPath:s},`${a} Lock file missing at ${s} during port update — skipping`);return}let c;try{let e=JSON.parse(l(s,`utf-8`));if(!e||typeof e!=`object`||!_(e.pid)){D.warn({lockPath:s},`${a} Corrupt lock at ${s} during port update — skipping`);return}c=e}catch{D.warn({lockPath:s},`${a} Unreadable lock at ${s} during port update — skipping`);return}if(c.pid===process.pid&&N(c)){c.port=r,i===void 0?delete c.url:c.url=i;try{d(s,JSON.stringify(c,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:s,err:e},`${a} Failed to update port in ${s}: ${e instanceof Error?e.message:String(e)}`)}}}function U(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=k(n,t);if((A.get(i)??0)>1)return;let a;try{let e=JSON.parse(l(i,`utf-8`));if(!e||typeof e!=`object`||!_(e.pid)){D.warn({lockPath:i},`${r} Corrupt lock at ${i} during draining mark — skipping`);return}a=e}catch(e){y(e)!==`ENOENT`&&D.warn({lockPath:i,err:e},`${r} Unreadable lock at ${i} during draining mark — skipping: ${e instanceof Error?e.message:String(e)}`);return}if(a.pid===process.pid&&N(a)&&a.draining!==!0){a.draining=!0;try{d(i,JSON.stringify(a,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:i,err:e},`${r} Failed to mark ${i} draining: ${e instanceof Error?e.message:String(e)}`)}}}function W(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!o(r))return null;let i;try{let e=JSON.parse(l(r,`utf-8`));if(!e||typeof e!=`object`||!_(e.pid))return null;i=e}catch{return null}if(!N(i))return null;if(!g(i.pid)){try{u(r)}catch{}return null}return i}function G(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!o(r))return{status:`absent`};let i;try{i=JSON.parse(l(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!_(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let s={pid:a.pid,hostname:a.hostname,port:a.port,url:typeof a.url==`string`?a.url:void 0,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,machineId:typeof a.machineId==`string`?a.machineId:void 0,draining:a.draining===!0?!0:void 0,capabilities:Array.isArray(a.capabilities)&&a.capabilities.every(e=>typeof e==`string`)?a.capabilities:void 0,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(!N(s))return{status:`stale`,lock:s};if(!g(s.pid)){try{u(r)}catch{}return{status:`stale`,lock:s}}return s.protocolVersion===void 0||s.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:s}}async function K(e){let{lockName:t,lockDir:n}=e,r=e.timeoutMs??1e4,i=e.pollIntervalMs??100,a=e.readLock??(()=>W({lockName:t,lockDir:n})),o=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=a();if(s===null||s.draining!==!0)return`no-drain`;let c=Date.now()+r;for(;Date.now()<c;){await o(i);let e=a();if(e===null)return`released`;if(e.draining!==!0)return`no-drain`}return`timeout`}function q(e){let{lockName:t,lockDir:n,deferUnlinkToExit:r=!1}=e,i=`[${t}-lock]`,a=k(n,t);if(M(a)){if(r){U({lockName:t,lockDir:n});return}if(o(a))try{let e=JSON.parse(l(a,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||!N(e))return;u(a),P.delete(a)}catch(e){D.warn({lockPath:a,err:e},`${i} Failed to release ${a}: ${e instanceof Error?e.message:String(e)}`)}}}var J=class extends O{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function Y(e,t){try{return R({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof O&&e.lockName===`server`?new J(e.existing,e.lockPath):e}}function X(e,t,n){H({lockName:`server`,lockDir:e,port:t,url:n})}function Z(e){return W({lockName:`server`,lockDir:e})}function Q(e,t){q({lockName:`server`,lockDir:e,...t})}function $(e){U({lockName:`server`,lockDir:e})}function ee(e,t){return K({lockName:`server`,lockDir:e,...t})}export{_ as C,g as S,T as _,Q as a,y as b,O as c,k as d,U as f,H as g,q as h,Z as i,R as l,G as m,Y as n,X as o,W as p,$ as r,ee as s,J as t,V as u,E as v,v as x,C as y};
2
+ //# sourceMappingURL=server-lock-CU3-_gnL.mjs.map
@@ -0,0 +1 @@
1
+ import{a as e,o as t,r as n}from"./server-lock-CU3-_gnL.mjs";export{n as markServerLockDraining,e as releaseServerLock,t as updateServerLockPort};
@@ -1,2 +1,2 @@
1
- import{Cr as e,wr as t}from"./src-DZEg-Zy7.mjs";import{s as n}from"./write-project-skill-DHATTSra.mjs";import{dirname as r,isAbsolute as i,join as a,relative as o,resolve as s,sep as c}from"node:path";import{existsSync as l,lstatSync as u,readdirSync as d,rmSync as f,rmdirSync as p}from"node:fs";const m=[{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`}],h=[...t.map(t=>e[t]),`open-knowledge`];function g(e){if(!i(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=s(e);if(t===c||r(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function _(e,t){let n=o(e,t);if(n.startsWith(`..`)||i(n))return!1;let r=e;for(let e of n.split(c)){r=a(r,e);try{if(!u(r).isDirectory())return!1}catch{return!1}}return!0}function v(e,t){try{return d(e).every(n=>t.has(a(e,n)))}catch{return!1}}function y(e){let t=g(e),n=[],i=[],o=new Set;for(let e of m){let s=a(t,e.hostDir,`skills`);if(!_(t,s))continue;let u=h.map(e=>a(s,e)).filter(e=>l(e));n.push(...u);for(let e of u)o.add(e);let d=a(t,e.pruneRoot),f=s;for(;v(f,o)&&(i.push(f),o.add(f),f!==d);){let e=r(f);if(e===f||e===t||!e.startsWith(t+c))break;f=e}}return{skillDirs:n,emptyDirs:i}}function b(e){try{if(!u(e).isDirectory())return!1;let t=d(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function x(e){let t=new Set,n=new Set;for(let i of m){let o=a(e,i.hostDir,`skills`);for(let e of h)t.add(a(o,e));let s=a(e,i.pruneRoot),l=o;for(;n.add(l),l!==s;){let t=r(l);if(t===l||t===e||!t.startsWith(e+c))break;l=t}}return{skillDirs:t,emptyDirs:n}}function S(e,t){let n=g(e),r=x(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(_(n,e)&&b(e))try{f(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(_(n,e))try{p(e),a.push(e)}catch{}return a}function C(r){let i=g(r),o=[];for(let r of t){let t=e[r];o.push({path:a(i,`.agents`,`skills`,t),bundleId:r,scope:`central`});for(let e of n)o.push({path:a(i,e.hostDir,`skills`,t),bundleId:r,scope:`host`,hostDir:e.hostDir})}return o}function w(e,t){let n=[];for(let r of C(e))if(r.bundleId===t)try{f(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}`)}export{C as i,y as n,w as r,S as t};
2
- //# sourceMappingURL=skill-teardown-DxeHIPsr.mjs.map
1
+ import{Cr as e,wr as t}from"./src-Cxffy8op.mjs";import{s as n}from"./write-project-skill-U5FHNOHQ.mjs";import{dirname as r,isAbsolute as i,join as a,relative as o,resolve as s,sep as c}from"node:path";import{existsSync as l,lstatSync as u,readdirSync as d,rmSync as f,rmdirSync as p}from"node:fs";const m=[{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`}],h=[...t.map(t=>e[t]),`open-knowledge`];function g(e){if(!i(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=s(e);if(t===c||r(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function _(e,t){let n=o(e,t);if(n.startsWith(`..`)||i(n))return!1;let r=e;for(let e of n.split(c)){r=a(r,e);try{if(!u(r).isDirectory())return!1}catch{return!1}}return!0}function v(e,t){try{return d(e).every(n=>t.has(a(e,n)))}catch{return!1}}function y(e){let t=g(e),n=[],i=[],o=new Set;for(let e of m){let s=a(t,e.hostDir,`skills`);if(!_(t,s))continue;let u=h.map(e=>a(s,e)).filter(e=>l(e));n.push(...u);for(let e of u)o.add(e);let d=a(t,e.pruneRoot),f=s;for(;v(f,o)&&(i.push(f),o.add(f),f!==d);){let e=r(f);if(e===f||e===t||!e.startsWith(t+c))break;f=e}}return{skillDirs:n,emptyDirs:i}}function b(e){try{if(!u(e).isDirectory())return!1;let t=d(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function x(e){let t=new Set,n=new Set;for(let i of m){let o=a(e,i.hostDir,`skills`);for(let e of h)t.add(a(o,e));let s=a(e,i.pruneRoot),l=o;for(;n.add(l),l!==s;){let t=r(l);if(t===l||t===e||!t.startsWith(e+c))break;l=t}}return{skillDirs:t,emptyDirs:n}}function S(e,t){let n=g(e),r=x(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(_(n,e)&&b(e))try{f(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(_(n,e))try{p(e),a.push(e)}catch{}return a}function C(r){let i=g(r),o=[];for(let r of t){let t=e[r];o.push({path:a(i,`.agents`,`skills`,t),bundleId:r,scope:`central`});for(let e of n)o.push({path:a(i,e.hostDir,`skills`,t),bundleId:r,scope:`host`,hostDir:e.hostDir})}return o}function w(e,t){let n=[];for(let r of C(e))if(r.bundleId===t)try{f(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}`)}export{C as i,y as n,w as r,S as t};
2
+ //# sourceMappingURL=skill-teardown-CuyNWxzR.mjs.map
@@ -1,4 +1,4 @@
1
- import{o as e}from"./chunk-DTipWd-i.mjs";import{K as t,ft as n,q as r}from"./sleep-ChZE9826.mjs";import{Ks as i,Q as a,Xa as o,Z as s,qs as c}from"./src-B8SfUeFe.mjs";import{On as l,Zr as u,at as d,bi as f,it as p,ot as m,rt as h}from"./src-DZEg-Zy7.mjs";import{D as g,F as _,I as v,k as y}from"./fs-traced-RPXwxrA5.mjs";import{C as b,S as x,d as S,y as C}from"./server-lock-CyyeFKIF.mjs";import{t as w}from"./yazl-DZr4PyKA.mjs";import{t as T}from"./esm-DmX1RzAi.mjs";import{c as E}from"./colors-BsmVIwfM.mjs";import{n as D}from"./acp-harness-probe-XTgNAWCH.mjs";import{E as ee,T as O,_ as k,o as A,w as j,x as M,y as N}from"./init-BLgGQUiA.mjs";import{n as te}from"./constants-DjzJQLPT.mjs";import{t as P}from"./is-object-ByG7RnjH.mjs";import{m as ne,p as re}from"./write-project-skill-DHATTSra.mjs";import"./loader-DFPCRuiv.mjs";import"./skill-teardown-DxeHIPsr.mjs";import"./preview-BuOydejY.mjs";import{execSync as ie,spawnSync as ae}from"node:child_process";import{basename as F,dirname as I,join as L,relative as oe,resolve as R,sep as se}from"node:path";import{cpSync as ce,createWriteStream as le,existsSync as z,lstatSync as ue,mkdirSync as B,mkdtempSync as de,readFileSync as V,readdirSync as H,readlinkSync as fe,rmSync as U,statSync as pe,writeFileSync as W}from"node:fs";import{arch as me,freemem as he,homedir as G,hostname as ge,platform as _e,release as ve,tmpdir as ye,totalmem as be,type as xe,uptime as Se}from"node:os";import"node:fs/promises";import{createHash as Ce}from"node:crypto";var we=n();const Te=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function Ee(e,t,n=l){if(e!==void 0&&!Te.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let De=null;function Oe(e){De=e}function ke(){return De??process.cwd()}function Ae(){return L(G(),`.ok`,`bug-reports`)}function je(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=Ae(),r=`${t}-bugreport`,i=L(n,`${r}.zip`);for(let e=2;z(i);e+=1)i=L(n,`${r}-${e}.zip`);return i}function Me(e,t){let n=L(e,`.ok`,`config.yml`);if(z(n))try{let e=V(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 z(L(e,`.ok`))?Ce(`sha256`).update(R(e)).digest(`hex`).slice(0,12):null}function Ne(){let e={timestamp:new Date().toISOString(),platform:_e(),osType:xe(),osRelease:ve(),hostname:`[redacted]`,uptime:Se(),freeMem:he(),totalMem:be(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=ie(`sw_vers -productVersion 2>/dev/null`,u({encoding:`utf8`})).trim()}catch{}try{let t=L(__dirname,`..`,`..`,`package.json`);z(t)&&(e.okVersion=JSON.parse(V(t,`utf8`)).version)}catch{}return e}const Pe=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function Fe(e){let t=F(e);return Pe.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function Ie(e,t){return ze(e,t).files}const Le=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function Re(e,t=D){let n=L(e,`${t}.ShipIt`);return z(n)?Le.map(e=>L(n,e)).filter(e=>z(e)):[]}function ze(e,t){if(!z(t))return{files:[],excludedByProjectSlug:0};let n=H(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>L(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(Fe),i=[],a=r.filter(t=>{try{return V(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=>!Fe(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function Be(e){let t=L(e,`.ok`,`local`);return z(t)?{files:[`server.lock`,`last-spawn-error.log`,s].map(e=>L(t,e)).filter(e=>z(e))}:{files:[]}}function Ve(e){let t=L(e,`.ok`,`local`,`logs`);return z(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>L(t,e)).filter(e=>z(e))}:{files:[]}}function He(e){if(e.redact){let{redacted:t,patterns:n,lineCount:r}=c(e.content);e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name),n.length>0&&e.redactions.push({file:e.name,lineCount:r,patterns:n})}else e.zipfile.addBuffer(Buffer.from(e.content,`utf8`),e.name),e.bundleFiles.push(e.name)}function Ue(e){for(let t of e.files)try{He({zipfile:e.zipfile,name:`${e.prefix}/${F(t)}`,content:V(t,`utf8`),redact:e.redact,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 We(t){let{redact:n,outputPath:r,logger:a}=t,o=t.userLogsDir??L(G(),`.ok`,`logs`),s=t.projectDir?Me(t.projectDir,a):null;B(I(r),{recursive:!0}),a?.info({projectSlug:s},`gathering diagnostic data`);let c=Ne();c.desktop=t.desktop??null,c.language=t.language??null;let{files:l,excludedByProjectSlug:u}=ze(s,o),{files:d}=t.projectDir?Be(t.projectDir):{files:[]},{files:f}=t.projectDir?Ve(t.projectDir):{files:[]},p=t.shipItLogFiles??[];a?.info({logFileCount:l.length,logFilesExcludedByProjectSlug:u,lockFileCount:d.length,localSinkFileCount:f.length,shipItLogFileCount:p.length},`files collected`);let m=[],h=[],{ZipFile:g}=await import(`./yazl-jVENrf5i.mjs`).then(t=>e(t.default,1)),_=new g;Ue({zipfile:_,files:[...l,...p],prefix:`logs`,redact:n,bundleFiles:h,redactions:m,logger:a}),Ue({zipfile:_,files:d,prefix:`lockdir`,redact:n,bundleFiles:h,redactions:m,logger:a}),Ue({zipfile:_,files:f,prefix:`local-logs`,redact:n,bundleFiles:h,redactions:m,logger:a});for(let e of t.extraFiles??[])try{let t=V(e.sourcePath),n=`extra/${e.zipName??F(e.sourcePath)}`;_.addBuffer(t,n),h.push(n)}catch(t){a?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&He({zipfile:_,name:`note.txt`,content:t.note,redact:n,bundleFiles:h,redactions:m});let v=JSON.stringify(c,null,2);_.addBuffer(Buffer.from(v,`utf8`),`sysinfo.json`),h.push(`sysinfo.json`);let y={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:s,files:h,redactions:m,sysinfo:c};_.addBuffer(Buffer.from(JSON.stringify(y,null,2),`utf8`),`MANIFEST.json`);let b=m.reduce((e,t)=>e+t.lineCount,0),x=new Set(p.map(e=>`logs/${F(e)}`)),S=h.filter(e=>x.has(e)),C=s?h.filter(e=>e.startsWith(`logs/`)&&!Fe(e)&&!x.has(e)):[],w=[`# Bug Report Bundle`,``,`Generated: ${y.generatedAt}`,`Project: ${s??`(unscoped)`}`,`Discipline version: ${y.disciplineVersion}`,``,`## Contents`,``,...h.map(e=>`- ${e}`),``,`## Privacy`,``,...C.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:`,...C.map(e=>`- ${e}`),``]:[],...S.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:`,...S.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${i.join(`, `)}`,b>0?`${b} line(s) were scrubbed across ${m.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,``,`This bundle is safe to attach to a GitHub issue.`]:[`Redaction was disabled for this bundle; file contents are unmodified.`]].join(`
1
+ import{o as e}from"./chunk-DTipWd-i.mjs";import{K as t,ft as n,q as r}from"./sleep-ChZE9826.mjs";import{Xs as i,Zs as a,eo as o,nt as s,tt as c}from"./src-DE02-xKN.mjs";import{On as l,Zr as u,at as d,bi as f,it as p,ot as m,rt as h}from"./src-Cxffy8op.mjs";import{D as g,F as _,I as v,k as y}from"./fs-traced-RPXwxrA5.mjs";import{C as b,S as x,d as S,y as C}from"./server-lock-CU3-_gnL.mjs";import{t as w}from"./yazl-DZr4PyKA.mjs";import{t as T}from"./esm-DmX1RzAi.mjs";import{c as E}from"./colors-BsmVIwfM.mjs";import{n as D}from"./acp-harness-probe-BFnNFv5O.mjs";import{E as ee,T as O,_ as k,o as A,w as j,x as M,y as N}from"./init-Bq2YfcXG.mjs";import{n as te}from"./constants-rtay2E1D.mjs";import{t as P}from"./is-object-ByG7RnjH.mjs";import{m as ne,p as re}from"./write-project-skill-U5FHNOHQ.mjs";import"./loader-CbsfDiyI.mjs";import"./skill-teardown-CuyNWxzR.mjs";import"./preview-CTscDXn-.mjs";import{execSync as ie,spawnSync as ae}from"node:child_process";import{basename as F,dirname as I,join as L,relative as oe,resolve as R,sep as se}from"node:path";import{cpSync as ce,createWriteStream as le,existsSync as z,lstatSync as ue,mkdirSync as B,mkdtempSync as de,readFileSync as V,readdirSync as H,readlinkSync as fe,rmSync as U,statSync as pe,writeFileSync as W}from"node:fs";import{arch as me,freemem as he,homedir as G,hostname as ge,platform as _e,release as ve,tmpdir as ye,totalmem as be,type as xe,uptime as Se}from"node:os";import"node:fs/promises";import{createHash as Ce}from"node:crypto";var we=n();const Te=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function Ee(e,t,n=l){if(e!==void 0&&!Te.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let De=null;function Oe(e){De=e}function ke(){return De??process.cwd()}function Ae(){return L(G(),`.ok`,`bug-reports`)}function je(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=Ae(),r=`${t}-bugreport`,i=L(n,`${r}.zip`);for(let e=2;z(i);e+=1)i=L(n,`${r}-${e}.zip`);return i}function Me(e,t){let n=L(e,`.ok`,`config.yml`);if(z(n))try{let e=V(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 z(L(e,`.ok`))?Ce(`sha256`).update(R(e)).digest(`hex`).slice(0,12):null}function Ne(){let e={timestamp:new Date().toISOString(),platform:_e(),osType:xe(),osRelease:ve(),hostname:`[redacted]`,uptime:Se(),freeMem:he(),totalMem:be(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=ie(`sw_vers -productVersion 2>/dev/null`,u({encoding:`utf8`})).trim()}catch{}try{let t=L(__dirname,`..`,`..`,`package.json`);z(t)&&(e.okVersion=JSON.parse(V(t,`utf8`)).version)}catch{}return e}const Pe=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function Fe(e){let t=F(e);return Pe.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function Ie(e,t){return ze(e,t).files}const Le=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function Re(e,t=D){let n=L(e,`${t}.ShipIt`);return z(n)?Le.map(e=>L(n,e)).filter(e=>z(e)):[]}function ze(e,t){if(!z(t))return{files:[],excludedByProjectSlug:0};let n=H(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>L(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(Fe),i=[],a=r.filter(t=>{try{return V(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=>!Fe(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function Be(e){let t=L(e,`.ok`,`local`);return z(t)?{files:[`server.lock`,`last-spawn-error.log`,c].map(e=>L(t,e)).filter(e=>z(e))}:{files:[]}}function Ve(e){let t=L(e,`.ok`,`local`,`logs`);return z(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>L(t,e)).filter(e=>z(e))}:{files:[]}}function He(e){if(e.redact){let{redacted:t,patterns:n,lineCount:r}=a(e.content);e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name),n.length>0&&e.redactions.push({file:e.name,lineCount:r,patterns:n})}else e.zipfile.addBuffer(Buffer.from(e.content,`utf8`),e.name),e.bundleFiles.push(e.name)}function Ue(e){for(let t of e.files)try{He({zipfile:e.zipfile,name:`${e.prefix}/${F(t)}`,content:V(t,`utf8`),redact:e.redact,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 We(t){let{redact:n,outputPath:r,logger:a}=t,o=t.userLogsDir??L(G(),`.ok`,`logs`),s=t.projectDir?Me(t.projectDir,a):null;B(I(r),{recursive:!0}),a?.info({projectSlug:s},`gathering diagnostic data`);let c=Ne();c.desktop=t.desktop??null,c.language=t.language??null;let{files:l,excludedByProjectSlug:u}=ze(s,o),{files:d}=t.projectDir?Be(t.projectDir):{files:[]},{files:f}=t.projectDir?Ve(t.projectDir):{files:[]},p=t.shipItLogFiles??[];a?.info({logFileCount:l.length,logFilesExcludedByProjectSlug:u,lockFileCount:d.length,localSinkFileCount:f.length,shipItLogFileCount:p.length},`files collected`);let m=[],h=[],{ZipFile:g}=await import(`./yazl-jVENrf5i.mjs`).then(t=>e(t.default,1)),_=new g;Ue({zipfile:_,files:[...l,...p],prefix:`logs`,redact:n,bundleFiles:h,redactions:m,logger:a}),Ue({zipfile:_,files:d,prefix:`lockdir`,redact:n,bundleFiles:h,redactions:m,logger:a}),Ue({zipfile:_,files:f,prefix:`local-logs`,redact:n,bundleFiles:h,redactions:m,logger:a});for(let e of t.extraFiles??[])try{let t=V(e.sourcePath),n=`extra/${e.zipName??F(e.sourcePath)}`;_.addBuffer(t,n),h.push(n)}catch(t){a?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&He({zipfile:_,name:`note.txt`,content:t.note,redact:n,bundleFiles:h,redactions:m});let v=JSON.stringify(c,null,2);_.addBuffer(Buffer.from(v,`utf8`),`sysinfo.json`),h.push(`sysinfo.json`);let y={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:s,files:h,redactions:m,sysinfo:c};_.addBuffer(Buffer.from(JSON.stringify(y,null,2),`utf8`),`MANIFEST.json`);let b=m.reduce((e,t)=>e+t.lineCount,0),x=new Set(p.map(e=>`logs/${F(e)}`)),S=h.filter(e=>x.has(e)),C=s?h.filter(e=>e.startsWith(`logs/`)&&!Fe(e)&&!x.has(e)):[],w=[`# Bug Report Bundle`,``,`Generated: ${y.generatedAt}`,`Project: ${s??`(unscoped)`}`,`Discipline version: ${y.disciplineVersion}`,``,`## Contents`,``,...h.map(e=>`- ${e}`),``,`## Privacy`,``,...C.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:`,...C.map(e=>`- ${e}`),``]:[],...S.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:`,...S.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${i.join(`, `)}`,b>0?`${b} line(s) were scrubbed across ${m.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,``,`This bundle is safe to attach to a GitHub issue.`]:[`Redaction was disabled for this bundle; file contents are unmodified.`]].join(`
2
2
  `);_.addBuffer(Buffer.from(w,`utf8`),`README.md`),_.end();let T=le(r);return _.outputStream.pipe(T),await new Promise((e,t)=>{T.on(`close`,e),T.on(`error`,t)}),a?.info({bundlePath:r,fileCount:h.length,redactionCount:b},`bundle written`),{zipPath:r,summary:{projectSlug:s,files:h,redactions:m,redactedLineCount:b,generatedAt:y.generatedAt}}}var Ge=e(w(),1),K=e(E(),1);function Ke(e){return v({absPath:y(`user`,e,e),sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function qe({home:e=G(),env:n=process.env}={}){let i=Ke(e),{override:a,preferenceList:s}=g(n),{locale:c,source:l}=o({override:a,storedPreference:i,supportedLocales:r,preferenceList:s,autoDetectableLocales:t});return{preference:i,locale:c,source:l,systemLanguages:s}}function Je(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function Ye(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function q(e,t){if(typeof e==`string`)return Je(e,t.contentDir);if(Array.isArray(e))return e.map(e=>q(e,t));if(!Ye(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=q(i,t);return n}function Xe(e,t){let n=V(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
3
3
  `),i=n.split(`
4
4
  `),a=[];for(let e=0;e<i.length;e++){let n=i[e]??``;if(!(e===i.length-1&&n===``)){if(n.length===0){a.push(``);continue}try{let e=q(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}W(e,r?`${a.join(`
@@ -6,7 +6,7 @@ import{o as e}from"./chunk-DTipWd-i.mjs";import{K as t,ft as n,q as r}from"./sle
6
6
  `))}function Ze(e,t){let n=V(e,`utf-8`);if(n.trim().length!==0)try{let r=q(JSON.parse(n),t),i=n.endsWith(`
7
7
  `)?`
8
8
  `:``;W(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=Je(n,t.contentDir);r!==n&&W(e,r)}}function Qe(e,t){let n=V(e,`utf-8`),r=Je(n,t.contentDir);r!==n&&W(e,r)}function $e(e){try{return H(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>L(e,t.name))}catch{return[]}}const et=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function tt(e){return/\.log\.\d+$/.test(e)}function nt(e){return e.endsWith(`.jsonl`)||e.endsWith(`.log`)||tt(e)}function rt(e){let t={contentDir:e.contentDir};for(let n of[`telemetry`,`logs`,`process`])for(let r of $e(L(e.stagingDir,n)))nt(r)?Xe(r,t):r.endsWith(`.json`)?Ze(r,t):Qe(r,t);for(let n of $e(L(e.stagingDir,`state`))){let e=F(n);n.endsWith(`.jsonl`)?Xe(n,t):et.has(e)?Ze(n,t):Qe(n,t)}}const it=[`.ok`,`local`,`telemetry`],at=[`.ok`,`local`,`logs`],ot=[`.ok`,`local`,`loss-capture`],st=`spans-current.jsonl`,ct=`spans-prev.jsonl`,lt=`server-current.jsonl`,ut=`server-prev.jsonl`,dt=`loss-current.jsonl`,ft=`loss-prev.jsonl`;function pt(e){return L(e,...it,st)}function mt(e){return L(e,...it,ct)}function ht(e){return L(e,...at,lt)}function gt(e){return L(e,...at,ut)}function _t(e){return L(e,...ot,dt)}function vt(e){return L(e,...ot,ft)}const yt=1e3;async function bt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(yt)});return t.ok?await t.text():null}catch{return null}}async function xt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-effects`,{signal:AbortSignal.timeout(yt)});return t.ok?await t.text():null}catch{return null}}async function St(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout(yt)});return t.ok?await t.text():null}catch{return null}}function Ct(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=t.decisions;return Array.isArray(n)?n.length===0?``:`${n.map(e=>JSON.stringify(e)).join(`
9
- `)}\n`:null}catch{return null}}function wt(e){let t=L(e,`.git`,`ok`);if(!z(t))return null;let n=ae(`git`,[`-C`,t,`log`,`--oneline`,`-50`],u({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Tt(e){let t=L(e,`.git`,`ok`);if(!z(t))return null;let n=ae(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],u({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Et(){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 Dt(){return{nodeVersion:process.version,platform:_e(),arch:me()}}function Ot(){return process.env.OTEL_SDK_DISABLED===`false`}function J(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){if(!z(e))return{};let t;try{t=(0,we.parse)(V(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(!J(t))return{};let n=t.telemetry;if(!J(n))return{};let r=n.localSink;return J(r)?r:{}}function At(e){return typeof e==`boolean`?e:void 0}function jt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function Y(e){if(J(e))return jt(e.maxBytes)}function Mt(e){let t=kt(y(`project`,e)),n=kt(y(`project-local`,e));return{enabled:At(n.enabled)??At(t.enabled)??!0,spansMaxBytes:Y(n.spans)??Y(t.spans)??52428800,logsMaxBytes:Y(n.logs)??Y(t.logs)??26214400}}function Nt(e){return Ce(`sha256`).update(e).digest(`hex`)}function Pt(e){let t=V(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}function Ft(e){let t=V(e,`utf-8`),n=`"doc.name"`,r=0,i=t.indexOf(n);for(;i!==-1;)r++,i=t.indexOf(n,i+10);return r}function X(e,t){if(!z(e))return!1;try{return B(I(t),{recursive:!0}),ce(e,t),!0}catch{return!1}}function It(e){let t=[],n=e=>{let r=H(e,{withFileTypes:!0});for(let i of r){let r=L(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const Lt=new Set([`.jsonl`]);function Rt(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Lt.has(e.slice(t))}const zt=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`]);function Bt(e){if(tt(e))return!0;let t=e.lastIndexOf(`.`);return t===-1?!1:zt.has(e.slice(t))}function Vt(e){let t=[];for(let n of It(e)){let r=Ht(e,n);if(!Bt(r))continue;let{redacted:i,patterns:a,lineCount:o}=c(V(n,`utf-8`));a.length!==0&&(W(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function Ht(e,t){return oe(e,t).split(se).join(`/`)}async function Ut(e){let t=R(e.contentDir),n=R(e.projectDir??e.contentDir),r=e.deps??{},i=r.fetchAgentPresence??bt,o=r.fetchAgentEffects??xt,c=r.fetchWatcherRecent??St,l=r.readShadowHead??wt,u=r.readCheckpointRefs??Tt,d=r.now??(()=>new Date),f=r.okVersion??(()=>te),p=r.readDesktopEnv??Et,m=r.readLanguage??qe,h=r.readRuntime??Dt,g=r.isOtlpPushEnabled??Ot,_=de(L(ye(),`ok-bundle-`));try{B(L(_,`telemetry`),{recursive:!0}),B(L(_,`logs`),{recursive:!0}),B(L(_,`state`),{recursive:!0}),X(pt(n),L(_,`telemetry`,st)),X(mt(n),L(_,`telemetry`,ct)),X(ht(n),L(_,`logs`,lt)),X(gt(n),L(_,`logs`,ut));for(let t of e.userLogFiles??[])X(t,L(_,`logs`,F(t)));let v=L(n,`.ok`,`local`),y=L(v,`server.lock`),b=`not-running`,x=`no server.lock`,S=null;if(z(y)){X(y,L(_,`state`,`server.lock`));try{let e=V(y,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?S=t.port:x=`lock present but no port`}catch{x=`lock present but unparseable`}}if(S!==null){let e=await i(S);e===null?x=`agent-presence endpoint at :${S} unreachable`:(W(L(_,`state`,`agent-presence.json`),e),b=`running`,x=``);let t=await o(S);t!==null&&W(L(_,`state`,`agent-effects.json`),t);let n=await c(S);if(n!==null){let e=Ct(n);e!==null&&W(L(_,`state`,`watcher-recent.jsonl`),e)}}let C=l(t);C!==null&&W(L(_,`state`,`shadow-head.txt`),C);let w=u(t);w!==null&&W(L(_,`state`,`checkpoint-refs.txt`),w),X(_t(n),L(_,`state`,dt)),X(vt(n),L(_,`state`,ft)),X(L(v,`last-spawn-error.log`),L(_,`state`,`last-spawn-error.log`)),X(L(v,a),L(_,`state`,a)),X(L(v,s),L(_,`state`,s));let T=h(),E=p(),D=m(),ee={ok:{version:f(),nodeVersion:T.nodeVersion,platform:T.platform,arch:T.arch},host:{desktop:E,language:D}};W(L(_,`state`,`runtime.json`),`${JSON.stringify(ee,null,2)}\n`);let O=b===`running`?`running
9
+ `)}\n`:null}catch{return null}}function wt(e){let t=L(e,`.git`,`ok`);if(!z(t))return null;let n=ae(`git`,[`-C`,t,`log`,`--oneline`,`-50`],u({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Tt(e){let t=L(e,`.git`,`ok`);if(!z(t))return null;let n=ae(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],u({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Et(){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 Dt(){return{nodeVersion:process.version,platform:_e(),arch:me()}}function Ot(){return process.env.OTEL_SDK_DISABLED===`false`}function J(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){if(!z(e))return{};let t;try{t=(0,we.parse)(V(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(!J(t))return{};let n=t.telemetry;if(!J(n))return{};let r=n.localSink;return J(r)?r:{}}function At(e){return typeof e==`boolean`?e:void 0}function jt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function Y(e){if(J(e))return jt(e.maxBytes)}function Mt(e){let t=kt(y(`project`,e)),n=kt(y(`project-local`,e));return{enabled:At(n.enabled)??At(t.enabled)??!0,spansMaxBytes:Y(n.spans)??Y(t.spans)??52428800,logsMaxBytes:Y(n.logs)??Y(t.logs)??26214400}}function Nt(e){return Ce(`sha256`).update(e).digest(`hex`)}function Pt(e){let t=V(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}function Ft(e){let t=V(e,`utf-8`),n=`"doc.name"`,r=0,i=t.indexOf(n);for(;i!==-1;)r++,i=t.indexOf(n,i+10);return r}function X(e,t){if(!z(e))return!1;try{return B(I(t),{recursive:!0}),ce(e,t),!0}catch{return!1}}function It(e){let t=[],n=e=>{let r=H(e,{withFileTypes:!0});for(let i of r){let r=L(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const Lt=new Set([`.jsonl`]);function Rt(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Lt.has(e.slice(t))}const zt=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`]);function Bt(e){if(tt(e))return!0;let t=e.lastIndexOf(`.`);return t===-1?!1:zt.has(e.slice(t))}function Vt(e){let t=[];for(let n of It(e)){let r=Ht(e,n);if(!Bt(r))continue;let{redacted:i,patterns:o,lineCount:s}=a(V(n,`utf-8`));o.length!==0&&(W(n,i),t.push({file:r,lineCount:s,patterns:o}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function Ht(e,t){return oe(e,t).split(se).join(`/`)}async function Ut(e){let t=R(e.contentDir),n=R(e.projectDir??e.contentDir),r=e.deps??{},i=r.fetchAgentPresence??bt,a=r.fetchAgentEffects??xt,o=r.fetchWatcherRecent??St,l=r.readShadowHead??wt,u=r.readCheckpointRefs??Tt,d=r.now??(()=>new Date),f=r.okVersion??(()=>te),p=r.readDesktopEnv??Et,m=r.readLanguage??qe,h=r.readRuntime??Dt,g=r.isOtlpPushEnabled??Ot,_=de(L(ye(),`ok-bundle-`));try{B(L(_,`telemetry`),{recursive:!0}),B(L(_,`logs`),{recursive:!0}),B(L(_,`state`),{recursive:!0}),X(pt(n),L(_,`telemetry`,st)),X(mt(n),L(_,`telemetry`,ct)),X(ht(n),L(_,`logs`,lt)),X(gt(n),L(_,`logs`,ut));for(let t of e.userLogFiles??[])X(t,L(_,`logs`,F(t)));let v=L(n,`.ok`,`local`),y=L(v,`server.lock`),b=`not-running`,x=`no server.lock`,S=null;if(z(y)){X(y,L(_,`state`,`server.lock`));try{let e=V(y,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?S=t.port:x=`lock present but no port`}catch{x=`lock present but unparseable`}}if(S!==null){let e=await i(S);e===null?x=`agent-presence endpoint at :${S} unreachable`:(W(L(_,`state`,`agent-presence.json`),e),b=`running`,x=``);let t=await a(S);t!==null&&W(L(_,`state`,`agent-effects.json`),t);let n=await o(S);if(n!==null){let e=Ct(n);e!==null&&W(L(_,`state`,`watcher-recent.jsonl`),e)}}let C=l(t);C!==null&&W(L(_,`state`,`shadow-head.txt`),C);let w=u(t);w!==null&&W(L(_,`state`,`checkpoint-refs.txt`),w),X(_t(n),L(_,`state`,dt)),X(vt(n),L(_,`state`,ft)),X(L(v,`last-spawn-error.log`),L(_,`state`,`last-spawn-error.log`)),X(L(v,s),L(_,`state`,s)),X(L(v,c),L(_,`state`,c));let T=h(),E=p(),D=m(),ee={ok:{version:f(),nodeVersion:T.nodeVersion,platform:T.platform,arch:T.arch},host:{desktop:E,language:D}};W(L(_,`state`,`runtime.json`),`${JSON.stringify(ee,null,2)}\n`);let O=b===`running`?`running
10
10
  `:`not-running (${x})\n`;if(W(L(_,`state`,`server-status.txt`),O),e.processDir&&z(e.processDir)){let t=L(_,`process`);B(t,{recursive:!0}),ce(e.processDir,t,{recursive:!0})}let k=e.redact===!0;k&&rt({stagingDir:_,contentDir:t}),e.note&&W(L(_,`note.txt`),e.note);let A=null;e.scrubSecrets===!0&&(A=Vt(_));for(let t of e.extraFiles??[])X(t.sourcePath,L(_,`extra`,t.zipName??F(t.sourcePath)))||r.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let j=Mt(n),M=It(_),N=[],te=0,P=0;for(let e of M){let t=Ht(_,e),n=pe(e).size,r=Rt(t)?Pt(e):0;N.push({path:t,bytes:n,lines:r}),te+=n,t.startsWith(`telemetry/`)&&Rt(t)&&(P+=Ft(e))}let ne={applied:k};A!==null&&(ne.secretScrub=A);let re={schemaVersion:2,createdAt:d().toISOString(),ok:{version:f(),nodeVersion:T.nodeVersion,platform:T.platform,arch:T.arch},host:{desktop:E,language:D},contentDir:{pathSha256:Nt(t),absolutePath:k?`<CONTENT_DIR>`:t},telemetry:{localSink:j,otlpPushEnabled:g()},redaction:ne,serverStatus:b,files:N};W(L(_,`manifest.json`),`${JSON.stringify(re,null,2)}\n`);let ie=M.some(e=>{try{return V(e,`utf-8`).includes(t)}catch{return!1}}),ae={totalBytes:te,fileCount:N.length,docNameCount:P,contentDirVisible:ie,redacted:k},I=!1;return{stagingDir:_,manifest:re,summary:ae,cleanup:()=>{I||(I=!0,U(_,{recursive:!0,force:!0}))}}}catch(e){throw U(_,{recursive:!0,force:!0}),e}}async function Wt(e){let{collected:t,outputPath:n}=e,r=I(n);if(!z(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new Ge.ZipFile,a=It(t.stagingDir);for(let e of a){let n=Ht(t.stagingDir,e);i.addFile(e,n)}i.end();let o=le(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 Gt(e,t){let n=L(e,`.ok`,`config.yml`);if(z(n))try{let t=(0,we.parse)(V(n,`utf-8`)),r=P(t)?t.content:void 0,i=P(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return R(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 R(e)}async function Kt(e,t,n,r){let i=Me(t,e.logger),a=await Ut({contentDir:Gt(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,userLogFiles:[...Ie(i,e.userLogsDir??L(G(),`.ok`,`logs`)),...Re(e.cachesDir??L(G(),`Library`,`Caches`))],deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{B(I(e.outputPath),{recursive:!0}),await Wt({collected:a,outputPath:e.outputPath});let t=a.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:i,files:a.manifest.files.map(e=>e.path),redactions:t?.redactions??[],redactedLineCount:t?.redactedLineCount??0,generatedAt:a.manifest.createdAt}}}finally{a.cleanup()}}async function qt(e){let{projectDir:t}=e,n=e.readDesktopEnv??Et,r=e.readLanguage??qe;if(e.level===`full`&&t!==void 0)return Kt(e,t,n,r);let{zipPath:i,summary:a}=await We({projectDir:t,redact:e.redact,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:Re(e.cachesDir??L(G(),`Library`,`Caches`)),logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n(),language:r()});return{zipPath:i,summary:{level:e.level,systemWide:t===void 0,projectSlug:a.projectSlug,files:a.files,redactions:a.redactions,redactedLineCount:a.redactedLineCount,generatedAt:a.generatedAt}}}function Z(e,t,n={}){let r=S(e,t);if(!z(r))return{status:`missing`,lockPath:r};let i;try{i=JSON.parse(V(r,`utf-8`))}catch{return{status:`corrupt`,lockPath:r}}if(!i||typeof i!=`object`||!b(i.pid))return{status:`corrupt`,lockPath:r};let a=i;if(!(n.isAlive??x)(a.pid))return{status:`dead-pid`,lockPath:r,lock:a};if(typeof a.machineId==`string`)return a.machineId===(n.machineId??C())?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a};let o=n.host??ge();return a.hostname===o?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a}}function Jt(e){return e.replace(/:\d+$/,``)}function Yt(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:Jt(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:Jt(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:Jt(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 Xt=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function Zt(e){return L(e,`Library`,`Application Support`,`OpenKnowledge`,`path-install.json`)}const Qt={existsSync:e=>z(e),readFileSync:(e,t)=>V(e,t),lstatSync:e=>ue(e),readlinkSync:e=>fe(e)};function $t(e,t=Qt){let n=Zt(e);if(!t.existsSync(n))return null;try{let e=JSON.parse(t.readFileSync(n,`utf8`));return e?.version===1?e:null}catch{return null}}function en(e){let t=e.replace(Xt,``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function tn(e,t,n=Qt){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}function nn(e){return re(e)||ne(e)||M(e)}const rn=10*1024*1024;function an(e,t,n,r){let i=A(e,t,n,r);if(i.kind===`absent`||i.kind===`no-entry`)return{kind:`not-present`};if(i.kind===`decline`)return{kind:`declined`,reason:i.reason};if(!nn(i.entry))return{kind:`left-foreign`};let a;try{a=r??e.configPath(t,n)}catch{return{kind:`not-present`}}let o=e.serverName(t);return e.format===`file`?(U(a,{force:!0}),{kind:`removed`}):e.format===`toml`?cn(a,o):e.format===`yaml`?sn(a,e.topLevelKey,o):on(a,e.topLevelKey,e.serverMapSubKey,o)}function on(e,t,n,r){let i;try{i=V(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(i,`utf-8`)>rn)return{kind:`declined`,reason:`oversize`};let{text:a,changed:o}=ee(i,k(t,n,r));return o?(_(e,a,{mode:j(e)}),{kind:`removed`}):{kind:`not-present`}}function sn(e,t,n){let r;try{r=V(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(r,`utf-8`)>rn)return{kind:`declined`,reason:`oversize`};let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=(0,we.parseDocument)(a);if(o.errors.length>0)return{kind:`declined`,reason:`unparseable`};let s=[t,n];if(!o.hasIn(s))return{kind:`not-present`};o.deleteIn(s);let c=o.toString(),l=O(a);a.trim()===``||a.endsWith(`
11
11
  `)?c.endsWith(`
12
12
  `)||(c=`${c}\n`):c=c.replace(/\n+$/,``),l&&(c=c.replace(/\r\n/g,`
@@ -17,4 +17,4 @@ import{o as e}from"./chunk-DTipWd-i.mjs";import{K as t,ft as n,q as r}from"./sle
17
17
  `).replace(/\n/g,`\r
18
18
  `));let u=`${i?``:``}${l}`;return u!==r&&_(e,u,{mode:j(e)}),{kind:`removed`}}function ln(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function un(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function dn(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,s=null;if(n.status!==`missing`&&n.status!==`corrupt`){let e=n.lock;s={port:e.port,status:n.status,pid:e.pid,startedAt:e.startedAt,usage:a}}return{directory:o.worktreeRoot,server:{port:o.port,status:t.status,pid:o.pid,startedAt:o.startedAt,usage:i},ui:s,hostname:o.hostname,lockPath:t.lockPath,binary:r==null?null:p(r),command:r,isDesktop:ln(r)}}function fn(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function Q(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&fn(e)?`ui-orphan`:`stale`}const pn=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function mn(e){switch(e){case`running`:return K.default.green(e);case`desktop`:return K.default.blue(e);case`foreign`:return K.default.cyan(e);case`ui-orphan`:return K.default.magenta(e);case`stale`:return K.default.yellow(e)}}function hn(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function gn(e){return`${hn(e.server.usage)} | ${hn(e.ui?.usage??null)}`}function _n(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function vn(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=>{let t=Q(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,_n(e),gn(e),t,String(n),un(e.server.startedAt),e.binary??`—`]}),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=mn(Q(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=K.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
19
19
  `)}async function yn(e={}){let t=e.discover??h,n=e.inspect??Z,r=e.log??(e=>console.log(e)),i=e.resolveCommand??d,a=e.resolveUsage??m,o=await t(),s=[];for(let e of o){let t=n(e,`server`),r=n(e,`ui`),o=dn(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&s.push(o)}if(e.json){let e=s.map(e=>({...e,displayStatus:Q(e)}));r(JSON.stringify(e,null,2));return}r(vn(e.all?s:s.filter(e=>pn.has(Q(e)))))}function bn(){return new T(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await yn({all:t.all===!0||e===`all`,json:t.json===!0})})}function xn(e,t,n={}){let r=n.isAlive??x,i=[];for(let[n,a]of[[`server`,e],[`ui`,t]])(a.status===`alive`||a.status===`foreign-host`&&r(a.lock.pid))&&i.push({name:n,pid:a.lock.pid,port:a.lock.port});return{targets:i}}function Sn(e){let t=e.inspect??(t=>Z(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=xn(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function $(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function Cn(e,t=x){let n=await h(),r=null;for(let i of n){let n=Z(i,`server`),a=Z(i,`ui`);if($(n,t)&&n.lock.port===e||$(a,t)&&a.lock.port===e)return i;r===null&&($(n,t)&&n.lock.pid===e||$(a,t)&&a.lock.pid===e)&&(r=i)}return r}function wn(e){let t=Sn({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function Tn(e){return new T(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=Sn({lockDir:f(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await yn({});return}if(n===`all`){let e=await h();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e){let e=Z(n,`server`),r=Z(n,`ui`);!$(e,x)&&!$(r,x)||(wn(n),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(n)){let e=Number.parseInt(n,10),t=await Cn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}wn(t);return}wn(f(R(ke(),n)))})}export{ke as _,Xt as a,$t as c,Z as d,qt as f,Ae as g,je as h,an as i,en as l,Wt as m,Tn as n,tn as o,Ut as p,bn as r,Zt as s,Sn as t,Yt as u,Oe as v,Ee as y};
20
- //# sourceMappingURL=src-DtvO7rZS.mjs.map
20
+ //# sourceMappingURL=src-BXftUDmM.mjs.map