@inkeep/open-knowledge 0.68.21 → 0.68.22-beta.1

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 (112) hide show
  1. package/dist/{acp-harness-probe-Bn_BG7qV.mjs → acp-harness-probe-BOnBiK3L.mjs} +2 -2
  2. package/dist/cli.mjs +6 -6
  3. package/dist/constants-RvcXFy51.mjs +2 -0
  4. package/dist/index.mjs +218 -219
  5. package/dist/init-BgkYRzIB.mjs +1 -0
  6. package/dist/{init-C7iy54Rg.mjs → init-CXsmclrh.mjs} +3 -3
  7. package/dist/{launch-json-removal-C8XHXxac.mjs → launch-json-removal-Cm9svU9h.mjs} +2 -2
  8. package/dist/{loader-D0Cdv7AJ.mjs → loader-D5LxbCgB.mjs} +2 -2
  9. package/dist/loader-IfXMTN-k.mjs +1 -0
  10. package/dist/{open-browser-rCRwMz67.mjs → open-browser-7DkBQF9D.mjs} +2 -2
  11. package/dist/{preview-CVW-X45n.mjs → preview-B4XjR2Hv.mjs} +2 -2
  12. package/dist/preview-XSwku_wv.mjs +1 -0
  13. package/dist/public/assets/{ActivityModeContent-BGB9Lh00.js → ActivityModeContent-DrxGfMvz.js} +1 -1
  14. package/dist/public/assets/{AddPropertiesButton-CoGMp7mh.js → AddPropertiesButton-BJo_rppq.js} +1 -1
  15. package/dist/public/assets/{AgentDiffPane-mzkepVxC.js → AgentDiffPane-DsCk_N38.js} +1 -1
  16. package/dist/public/assets/{CodeMirrorPropInput-CWmumA35.js → CodeMirrorPropInput-CGOtxTRF.js} +1 -1
  17. package/dist/public/assets/{DocumentContext-DNP4uH62.js → DocumentContext-D05VcwL0.js} +1 -1
  18. package/dist/public/assets/{EditorModeToggle-BKJ5L0Yp.js → EditorModeToggle-QltvWtP-.js} +1 -1
  19. package/dist/public/assets/{EnableSyncConfirmDialog-Sn31-4fB.js → EnableSyncConfirmDialog-CMKantv5.js} +1 -1
  20. package/dist/public/assets/ExcalidrawDocEditor-C48E2J8X.js +1 -0
  21. package/dist/public/assets/FeedbackForm-CtwwmLh-.js +1 -0
  22. package/dist/public/assets/{ImportSkillDialog-DoUc1y6P.js → ImportSkillDialog-DXRVURiF.js} +1 -1
  23. package/dist/public/assets/{LintConfigEditor-SL1Qcszn.js → LintConfigEditor-CB0o3K-6.js} +1 -1
  24. package/dist/public/assets/ManagedArtifactProperties-CmlPj4Nz.js +1 -0
  25. package/dist/public/assets/{ManagedArtifactProperties-DL0g2imz.js → ManagedArtifactProperties-PfnMwxJm.js} +1 -1
  26. package/dist/public/assets/{MermaidDocEditor-DqBooTtY.js → MermaidDocEditor-J4ci7jAA.js} +1 -1
  27. package/dist/public/assets/{PropertyDisplayRow-u9XeJ-tz.js → PropertyDisplayRow-ONE-tzKI.js} +1 -1
  28. package/dist/public/assets/{ReportBugDialogBody-CT2Z753g.js → ReportBugDialogBody-CG8yDGbK.js} +1 -1
  29. package/dist/public/assets/{ReportBugMenuTrigger-Bgd4nbhS.js → ReportBugMenuTrigger-AGOrr1fp.js} +2 -2
  30. package/dist/public/assets/{SchemaConfigEditor-DM_-9AFT.js → SchemaConfigEditor-B0JgoJX1.js} +1 -1
  31. package/dist/public/assets/{SessionsHost-Yq1YfriR.js → SessionsHost-CkWnHm7-.js} +2 -2
  32. package/dist/public/assets/{SettingsDialogBody-BhA5Dvam.js → SettingsDialogBody-BsN9Kdfy.js} +1 -1
  33. package/dist/public/assets/{ShareReceiveMissDialog-DaqYsj_1.js → ShareReceiveMissDialog-DdLLhrno.js} +1 -1
  34. package/dist/public/assets/{SkillInstallMenu-BdNkzJ8H.js → SkillInstallMenu-Bbcf0WK7.js} +1 -1
  35. package/dist/public/assets/{SkillToolbarControls-e3TjlKXK.js → SkillToolbarControls-D_3eESsK.js} +1 -1
  36. package/dist/public/assets/{SourceEditor-DIih2RvT.js → SourceEditor-CNdEIp7F.js} +1 -1
  37. package/dist/public/assets/{TerminalWindowApp-DSyBcaqb.js → TerminalWindowApp-Cgj_x6tD.js} +1 -1
  38. package/dist/public/assets/{TextDocEditor-CPYlrI0k.js → TextDocEditor-CmulZC7e.js} +1 -1
  39. package/dist/public/assets/{ThreadView-BdY7Edkk.js → ThreadView-Cw7ub95K.js} +1 -1
  40. package/dist/public/assets/{TimelineDiffPane-hkuv6fM-.js → TimelineDiffPane-6vZyy4l3.js} +1 -1
  41. package/dist/public/assets/{agent-diff-store-C4qabVH4.js → agent-diff-store-wSkpgVlI.js} +1 -1
  42. package/dist/public/assets/{auth-state-cache-qocgBT-m.js → auth-state-cache-BkAb7BNf.js} +1 -1
  43. package/dist/public/assets/{client-version-thG88OYC.js → client-version-CyfblLiq.js} +1 -1
  44. package/dist/public/assets/{comment-chips-DjpgeIDZ.js → comment-chips-CAw_--st.js} +1 -1
  45. package/dist/public/assets/{config-provider-BxaA6qPR.js → config-provider-C4M_g0W4.js} +3 -3
  46. package/dist/public/assets/{doc-undo-manager-D39Jo6-z.js → doc-undo-manager-Ca9imJ6U.js} +1 -1
  47. package/dist/public/assets/i18n-BO9Xvo8q.js +1 -0
  48. package/dist/public/assets/{index-CKczg_ye.js → index-CTmmlQJN.js} +7 -7
  49. package/dist/public/assets/messages-B6Ac_knU.js +1 -0
  50. package/dist/public/assets/messages-BvfFbtmp.js +1 -0
  51. package/dist/public/assets/messages-ByqVbDZe.js +1 -0
  52. package/dist/public/assets/messages-CF4EMa7T.js +1 -0
  53. package/dist/public/assets/messages-CgBcbaHh.js +1 -0
  54. package/dist/public/assets/messages-CnVn5BDO.js +1 -0
  55. package/dist/public/assets/messages-CqyX3cbt.js +1 -0
  56. package/dist/public/assets/messages-CxKqlUtN.js +1 -0
  57. package/dist/public/assets/messages-D9dpfRAa.js +1 -0
  58. package/dist/public/assets/messages-DzfDu_9j.js +1 -0
  59. package/dist/public/assets/messages-K88Wi74D.js +1 -0
  60. package/dist/public/assets/messages-oiz3Xu6U.js +1 -0
  61. package/dist/public/assets/{pending-receive-nav-store-ClwjChpv.js → pending-receive-nav-store-BlPeJUhN.js} +1 -1
  62. package/dist/public/assets/{progress-Dy5i2DS-.js → progress-Dc-mYmpO.js} +1 -1
  63. package/dist/public/assets/{selection-context-MOqygxHb.js → selection-context-DPh4FTXp.js} +1 -1
  64. package/dist/public/assets/{src-CrjSKebx.js → src-DsA5nyew.js} +1 -1
  65. package/dist/public/assets/{telemetry-impl-DACYt1sl.js → telemetry-impl-D3BsIwDN.js} +1 -1
  66. package/dist/public/assets/{telemetry-startup-Dji40PV0.js → telemetry-startup-BLz9UO1p.js} +1 -1
  67. package/dist/public/assets/{typing-burst-detector-fyX2Di9k.js → typing-burst-detector-BGsY9LD0.js} +1 -1
  68. package/dist/public/assets/{uninstall-Q6KZCGd1.js → uninstall-ClePMC9B.js} +1 -1
  69. package/dist/public/assets/{use-activity-panel-D8b9ADRU.js → use-activity-panel-DRcDcqVD.js} +1 -1
  70. package/dist/public/assets/{use-open-skill-CfYMUr4M.js → use-open-skill-xa-WPLIN.js} +1 -1
  71. package/dist/public/assets/{use-terminal-enabled-BTbWe1Ec.js → use-terminal-enabled-B-jpEe-2.js} +1 -1
  72. package/dist/public/assets/{use-timeline-entry-diff-BLPTkHjP.js → use-timeline-entry-diff-CJDIRaWs.js} +1 -1
  73. package/dist/public/index.html +22 -22
  74. package/dist/public/uninstall.html +3 -3
  75. package/dist/{repair-launch-json-BDSOwo0q.mjs → repair-launch-json-DvZjMvmt.mjs} +2 -2
  76. package/dist/{repair-mcp-configs-tskp-dfX.mjs → repair-mcp-configs-DBd25taF.mjs} +2 -2
  77. package/dist/repair-skills-Cd0ulalA.mjs +1 -0
  78. package/dist/{repair-skills-CeMC3U8t.mjs → repair-skills-DV5Ex1fA.mjs} +2 -2
  79. package/dist/{resolve-project-root-_5tOVKSQ.mjs → resolve-project-root-Cc2d51uk.mjs} +2 -2
  80. package/dist/{skill-teardown-CTF1f6zQ.mjs → skill-teardown-CnsEXQ4M.mjs} +2 -2
  81. package/dist/{src-DUEV0OgR.mjs → src-BRvdXeYI.mjs} +1 -1
  82. package/dist/src-DS7mzkTK.mjs +1 -0
  83. package/dist/src-HCPUteLH.mjs +20 -0
  84. package/dist/src-IiV9Xv8E.mjs +2045 -0
  85. package/dist/{start-B3CIc82Y.mjs → start-BxGCev89.mjs} +3 -3
  86. package/dist/start-DuVy80M2.mjs +1 -0
  87. package/package.json +4 -4
  88. package/dist/constants-BN5-aOru.mjs +0 -2
  89. package/dist/init-rC5_Zp--.mjs +0 -1
  90. package/dist/loader-Bg7VGW0V.mjs +0 -1
  91. package/dist/preview-ciQ61PTF.mjs +0 -1
  92. package/dist/public/assets/ExcalidrawDocEditor-CKRQ4y3k.js +0 -1
  93. package/dist/public/assets/FeedbackForm-CoGAuRS2.js +0 -1
  94. package/dist/public/assets/ManagedArtifactProperties-CbxVak5w.js +0 -1
  95. package/dist/public/assets/i18n-CkFIIxkx.js +0 -1
  96. package/dist/public/assets/messages-1No0CauP.js +0 -1
  97. package/dist/public/assets/messages-BIqXzC4l.js +0 -1
  98. package/dist/public/assets/messages-B_4omNLT.js +0 -1
  99. package/dist/public/assets/messages-Be-FYfQ4.js +0 -1
  100. package/dist/public/assets/messages-CNHhZ4a3.js +0 -1
  101. package/dist/public/assets/messages-CQAvxRgS.js +0 -1
  102. package/dist/public/assets/messages-CVeyKz0B.js +0 -1
  103. package/dist/public/assets/messages-CtF6T86x.js +0 -1
  104. package/dist/public/assets/messages-M0QpAdXx.js +0 -1
  105. package/dist/public/assets/messages-hpjSQYVz.js +0 -1
  106. package/dist/public/assets/messages-prOy2Yu2.js +0 -1
  107. package/dist/public/assets/messages-wwh_OEGG.js +0 -1
  108. package/dist/repair-skills-Bo_BJNkk.mjs +0 -1
  109. package/dist/src-B0ljVoS2.mjs +0 -1
  110. package/dist/src-BR3UyegR.mjs +0 -21
  111. package/dist/src-BccaNJoN.mjs +0 -2045
  112. package/dist/start-mE3EYxo8.mjs +0 -1
@@ -1 +0,0 @@
1
- import{t as e}from"./repair-skills-CeMC3U8t.mjs";export{e as repairSkills};
@@ -1 +0,0 @@
1
- import"./src-B2bAQ64a.mjs";import"./resolve-project-root-_5tOVKSQ.mjs";import"./src-BR3UyegR.mjs";import"./acp-harness-probe-Bn_BG7qV.mjs";import"./init-C7iy54Rg.mjs";import{n as e}from"./loader-D0Cdv7AJ.mjs";import"./skill-teardown-CTF1f6zQ.mjs";import"./preview-CVW-X45n.mjs";import"./mcp-migrate-event-9DFnNzHa.mjs";export{e as loadConfig};
@@ -1,21 +0,0 @@
1
- import{o as e}from"./chunk-DTipWd-i.mjs";import{Ha as t,Ia as n,La as r,ac as i,oc as a}from"./src-B2bAQ64a.mjs";import{$ as o,Ct as s,Q as c,c as l,s as u}from"./sleep-zea4v2sB.mjs";import{Bi as d,ct as ee,ei as f,h as p,lt as m,st as h,ut as g,xr as _}from"./src-BccaNJoN.mjs";import{A as v,I as y,L as b,O as x}from"./fs-traced-DgX7lP1u.mjs";import{C as S,S as C,_ as w,d as T,f as E,r as D}from"./server-lock-DKS1ePB3.mjs";import{t as O}from"./yazl-DejPO9b3.mjs";import{_ as k,h as te,m as A,v as j,x as M}from"./resolve-project-root-_5tOVKSQ.mjs";import{c as N}from"./colors-DSyAT9Cz.mjs";import{a as ne,i as re}from"./acp-harness-probe-Bn_BG7qV.mjs";import{D as ie,E as P,S as ae,T as F,_ as oe,b as se,o as ce}from"./init-C7iy54Rg.mjs";import{n as le}from"./constants-BN5-aOru.mjs";import{t as ue}from"./is-object-Bw0-z8qH.mjs";import"./loader-D0Cdv7AJ.mjs";import"./skill-teardown-CTF1f6zQ.mjs";import"./preview-CVW-X45n.mjs";import{execSync as de,spawnSync as fe}from"node:child_process";import{basename as I,dirname as L,join as R,relative as pe,resolve as z,sep as me}from"node:path";import{cpSync as he,createWriteStream as ge,existsSync as B,lstatSync as _e,mkdirSync as V,mkdtempSync as ve,readFileSync as H,readdirSync as U,readlinkSync as ye,rmSync as be,statSync as xe,writeFileSync as W}from"node:fs";import{arch as Se,freemem as Ce,homedir as G,hostname as we,platform as Te,release as Ee,tmpdir as De,totalmem as Oe,type as ke,uptime as Ae}from"node:os";import"node:fs/promises";import{createHash as je}from"node:crypto";var Me=s();let Ne;function Pe(){return Ne}function Fe(e,t){if(t!==void 0&&t.length>0)return t;try{return f(e)?.rootPath}catch{return}}function Ie(e){let t=Fe(e.cwd,e.configuredProjectName),n=p({name:`cli`,project:t});return Ne=n,n.info({command:e.command,cwd:e.cwd,project:t},`cli command started`),n}const Le=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function Re(e,t,n=f){if(e!==void 0&&!Le.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let ze=null;function Be(e){ze=e}function Ve(){return ze??process.cwd()}const He=`Open Knowledge`;function Ue(e={}){let t=e.platformName??process.platform,n=e.productName??`OpenKnowledge`;return k(t).join(j({...e,platformName:t}),n)}function We(e={}){let t=e.platformName??process.platform,n=e.home??G(),r=e.env??process.env,i=k(t),a;return a=t===`win32`?r.LOCALAPPDATA||i.join(n,`AppData`,`Local`):t===`darwin`?i.join(n,`Library`,`Caches`):r.XDG_CACHE_HOME||i.join(n,`.cache`),i.join(a,`@inkeepopen-knowledge-desktop-updater`)}function Ge(e){if(typeof e!=`object`||!e)return null;let t=e.recentProjects;if(!Array.isArray(t))return null;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let t=e;typeof t.path==`string`&&typeof t.name==`string`&&n.push({path:t.path,name:t.name})}return n}function Ke(e){let t=R(e,`state.json`);if(!B(t))return[];let n;try{n=JSON.parse(H(t,`utf-8`))}catch{return[]}return Ge(n)??[]}function qe(e){let t=R(e,`state.json`);if(!B(t))return!1;try{return Ge(JSON.parse(H(t,`utf-8`)))!==null}catch{return!1}}function Je(e,t){if(e.outcome===`not-present`)return`not-present (no DiagnosticReports directory)`;if(e.outcome===`unreadable-directory`)return`unreadable (${e.directoryErrorCode??`unknown`} reading DiagnosticReports)`;let n=[`${e.windowDays}d`,`${e.foreignIgnored} other-process report(s) ignored`,`${e.unparseable} unparseable`];e.droppedOverCap>0&&n.push(`${e.droppedOverCap} older dropped over cap`);let r=e.files.length-t;return r>0&&n.push(`${r} vanished before staging`),e.outcome===`none-in-window`?`none found in window (${n.join(`; `)})`:`${t} collected (${n.join(`; `)})`}function Ye(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const Xe=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Ze(e){return e.replace(Xe,`$1"[REDACTED-DEVICE-ID]"`)}function Qe(e){return Ze(Ye(e))}const $e=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function et(e){if(typeof e!=`string`)return null;let t=$e.exec(e.trim());if(t===null)return null;let[,n,r,i=``,a,o]=t,s=Date.parse(`${n}T${r}${i}${a}:${o}`);return Number.isNaN(s)?null:s}function tt(e){try{let t=H(e,`utf-8`),n=t.indexOf(`
2
- `),r=n===-1?t:t.slice(0,n),i=JSON.parse(r);if(typeof i!=`object`||!i)return{kind:`unreadable`};let{name:a,app_name:o,timestamp:s}=i,c=typeof a==`string`?a:typeof o==`string`?o:null;return c===null?{kind:`unreadable`}:{kind:`named`,name:c,timestampMs:et(s)}}catch{return{kind:`unreadable`}}}function nt(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function rt(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=U(e,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`?{...n,outcome:`not-present`}:{...n,outcome:`unreadable-directory`,directoryErrorCode:t??`unknown`}}let i=t.getTime()-6048e5,a=[],o=0,s=0;for(let t of r){if(!t.isFile()||!t.name.endsWith(`.ips`))continue;let n=R(e,t.name),r;try{r=xe(n).mtimeMs}catch{continue}if(r<i)continue;let c=tt(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!nt(c.name)){o+=1;continue}a.push({path:n,atMs:l})}a.sort((e,t)=>t.atMs-e.atMs);let c=a.slice(0,25),l={foreignIgnored:o,unparseable:s,droppedOverCap:a.length-c.length,windowDays:7};return c.length===0?{...l,files:[],outcome:`none-in-window`}:{...l,files:c.map(e=>e.path),outcome:`collected`}}function K(){return R(G(),`.ok`,`bug-reports`)}function it(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=K(),r=`${t}-bugreport`,i=R(n,`${r}.zip`);for(let e=2;B(i);e+=1)i=R(n,`${r}-${e}.zip`);return i}function at(e,t){let n=R(e,`.ok`,`config.yml`);if(B(n))try{let e=H(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 B(R(e,`.ok`))?je(`sha256`).update(z(e)).digest(`hex`).slice(0,12):null}function ot(){let e={timestamp:new Date().toISOString(),platform:Te(),osType:ke(),osRelease:Ee(),hostname:`[redacted]`,uptime:Ae(),freeMem:Ce(),totalMem:Oe(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=de(`sw_vers -productVersion 2>/dev/null`,d({encoding:`utf8`})).trim()}catch{}try{let t=R(__dirname,`..`,`..`,`package.json`);B(t)&&(e.okVersion=JSON.parse(H(t,`utf8`)).version)}catch{}return e}const st=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function ct(e){let t=I(e);return st.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function lt(e,t){return pt(e,t).files}const ut=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function dt(e,t=ne){let n=R(e,`${t}.ShipIt`);if(!B(n))return[];let r;try{r=U(n)}catch{return[]}return ut.flatMap(e=>r.map(t=>{if(t===e)return{entry:t,suffix:-1};if(!t.startsWith(`${e}.`))return null;let n=t.slice(e.length+1);return/^\d+$/.test(n)?{entry:t,suffix:Number(n)}:null}).filter(e=>e!==null).sort((e,t)=>e.suffix-t.suffix).slice(0,4).map(e=>R(n,e.entry)))}function ft(e){if(!B(e))return[];try{let t=new Map;for(let n of U(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-i.length):n.slice(0,-5),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return[...t.values()].slice(-25).flat().map(t=>R(e,t))}catch{return[]}}function pt(e,t){if(!B(t))return{files:[],excludedByProjectSlug:0};let n=U(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>R(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(ct),i=[],a=r.filter(t=>{try{return H(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=>!ct(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function mt(e){let t=R(e,`.ok`,`local`);return B(t)?{files:[`server.lock`,`last-spawn-error.log`,u].map(e=>R(t,e)).filter(e=>B(e))}:{files:[]}}function ht(e){let t=R(e,`.ok`,`local`,`logs`);return B(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>R(t,e)).filter(e=>B(e))}:{files:[]}}function gt(e){let t=0,n=new Map,r=e.replace(/("(?:docName|doc\.name|documentName)"\s*:\s*")((?:[^"\\]|\\.)*)"/g,(e,r,i)=>{t+=1;let a=n.get(i);return a===void 0&&(a=`doc#${je(`sha256`).update(i).digest(`hex`).slice(0,12)}`,n.set(i,a)),`${r}${a}"`});for(let[e,i]of[...n].sort(([e],[t])=>t.length-e.length)){if(e.length===0||!r.includes(e))continue;let n=r.split(e);t+=n.length-1,r=n.join(i)}return{text:r,count:t}}function _t(e){let t=e.revealDocNames?e.content:gt(e.content).text;if(e.redact){let{redacted:n,patterns:i,lineCount:a}=r(t);e.zipfile.addBuffer(Buffer.from(n,`utf8`),e.name),e.bundleFiles.push(e.name),i.length>0&&e.redactions.push({file:e.name,lineCount:a,patterns:i})}else e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name)}function q(e){for(let t of e.files)try{let n=H(t,`utf8`);_t({zipfile:e.zipfile,name:`${e.prefix}/${I(t)}`,content:t.endsWith(`.ips`)?Qe(n):n,redact:e.redact,revealDocNames:e.revealDocNames,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n},`bug-report: skipped unreadable file`)}}async function vt(t){let{redact:r,outputPath:i,logger:o}=t,s=t.revealDocNames??!1,c=t.userLogsDir??R(G(),`.ok`,`logs`),l=t.projectDir?at(t.projectDir,o):null;V(L(i),{recursive:!0}),o?.info({projectSlug:l},`gathering diagnostic data`);let u=ot();u.desktop=t.desktop??null,u.language=t.language??null;let{files:d,excludedByProjectSlug:ee}=pt(l,c),{files:f}=t.projectDir?mt(t.projectDir):{files:[]},{files:p}=t.projectDir?ht(t.projectDir):{files:[]},m=t.shipItLogFiles??[],h=t.diagnosticReports?.files??[];o?.info({logFileCount:d.length,logFilesExcludedByProjectSlug:ee,lockFileCount:f.length,localSinkFileCount:p.length,shipItLogFileCount:m.length,diagnosticReportCount:h.length},`files collected`);let g=[],_=[],{ZipFile:v}=await import(`./yazl-BwMlCqRQ.mjs`).then(t=>e(t.default,1)),y=new v;q({zipfile:y,files:[...d,...m],prefix:`logs`,redact:r,revealDocNames:s,bundleFiles:_,redactions:g,logger:o}),q({zipfile:y,files:f,prefix:`lockdir`,redact:r,revealDocNames:s,bundleFiles:_,redactions:g,logger:o}),q({zipfile:y,files:p,prefix:`local-logs`,redact:r,revealDocNames:s,bundleFiles:_,redactions:g,logger:o}),q({zipfile:y,files:t.bugReportLedgerFiles??[],prefix:a,redact:r,revealDocNames:s,bundleFiles:_,redactions:g,logger:o}),q({zipfile:y,files:h,prefix:`diagnostic-reports`,redact:r,revealDocNames:s,bundleFiles:_,redactions:g,logger:o});for(let e of t.extraFiles??[])try{let t=H(e.sourcePath),n=`extra/${e.zipName??I(e.sourcePath)}`;y.addBuffer(t,n),_.push(n)}catch(t){o?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&_t({zipfile:y,name:`note.txt`,content:t.note,redact:r,revealDocNames:s,bundleFiles:_,redactions:g});let b=new Set(h.map(e=>`diagnostic-reports/${I(e)}`)),x=_.filter(e=>b.has(e)),S=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Je(t.diagnosticReports,x.length);y.addBuffer(Buffer.from(`${S}\n`,`utf8`),`state/diagnostic-reports-status.txt`),_.push(`state/diagnostic-reports-status.txt`);let C=JSON.stringify(u,null,2);y.addBuffer(Buffer.from(C,`utf8`),`sysinfo.json`),_.push(`sysinfo.json`);let w={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:l,files:_,redactions:g,sysinfo:u};y.addBuffer(Buffer.from(JSON.stringify(w,null,2),`utf8`),`MANIFEST.json`);let T=g.reduce((e,t)=>e+t.lineCount,0),E=new Set(m.map(e=>`logs/${I(e)}`)),D=_.filter(e=>E.has(e)),O=new Set((t.bugReportLedgerFiles??[]).map(e=>`${a}/${I(e)}`)),k=_.filter(e=>O.has(e)),te=l?_.filter(e=>e.startsWith(`logs/`)&&!ct(e)&&!E.has(e)):[],A=x.length>0?[`Crash reports under diagnostic-reports/ are rewritten on the way in,`,`independently of this setting: escaped path separators are normalised`,`so the scrub above can read them, and the identifiers that link this`,`machine's bundles to each other are replaced. Nothing else is changed;`,`they are not byte-identical to the files macOS wrote.`]:[],j=A.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...A]:[`Redaction was disabled for this bundle; file contents are unmodified.`],M=[`# Bug Report Bundle`,``,`Generated: ${w.generatedAt}`,`Project: ${l??`(unscoped)`}`,`Discipline version: ${w.disciplineVersion}`,``,`## Contents`,``,..._.map(e=>`- ${e}`),``,`## Privacy`,``,...te.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:`,...te.map(e=>`- ${e}`),``]:[],...D.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:`,...D.map(e=>`- ${e}`),``]:[],...x.length>0?[`Crash reports: written by macOS itself rather than by OpenKnowledge,`,`and machine-wide rather than scoped to any one project. They record`,`why the operating system ended a process of this app — the signal or`,`exception, the code-signing verdict, and whatever text the process`,`left behind as it died. They also carry machine details the OS puts`,`in every report: the account uid, the Mac model, and the name of the`,`process that launched this app, which on a managed machine can be`,`internal tooling. The identifiers that would link this machine's`,`bundles to each other are replaced before bundling. Only this`,`app's own reports are collected, never another application's, though`,`a report of ours still names the processes it ran alongside:`,...x.map(e=>`- ${e}`),``]:[],...k.length>0?[`Send history: a small record for each bug report previously generated`,`on this machine — when it was generated, whether sending it`,`succeeded, and why it failed if it did. This is what makes a failed`,`send diagnosable at all. It is machine-wide rather than scoped to`,`this project, so it names the other projects reports were filed`,`from. It carries no document content:`,...k.map(e=>`- ${e}`),``]:[],...r?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${n.join(`, `)}`,T>0?`${T} line(s) were scrubbed across ${g.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...A,``,`This bundle is safe to attach to a GitHub issue.`]:j].join(`
3
- `);y.addBuffer(Buffer.from(M,`utf8`),`README.md`),y.end();let N=ge(i);return y.outputStream.pipe(N),await new Promise((e,t)=>{N.on(`close`,e),N.on(`error`,t)}),o?.info({bundlePath:i,fileCount:_.length,redactionCount:T},`bundle written`),{zipPath:i,summary:{projectSlug:l,files:_,redactions:g,redactedLineCount:T,generatedAt:w.generatedAt}}}var yt=e(O(),1),J=e(N(),1);function bt(e){return b({absPath:v(`user`,e,e),sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function xt({home:e=G(),env:n=process.env}={}){let r=bt(e),{override:i,preferenceList:a}=x(n),{locale:s,source:l}=t({override:i,storedPreference:r,supportedLocales:o,preferenceList:a,autoDetectableLocales:c});return{preference:r,locale:s,source:l,systemLanguages:a}}function St(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function Ct(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e,t){if(typeof e==`string`)return St(e,t.contentDir);if(Array.isArray(e))return e.map(e=>Y(e,t));if(!Ct(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=Y(i,t);return n}function wt(e,t){let n=H(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
4
- `),i=n.split(`
5
- `),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=Y(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}W(e,r?`${a.join(`
6
- `)}\n`:a.join(`
7
- `))}function Tt(e,t){let n=H(e,`utf-8`);if(n.trim().length!==0)try{let r=Y(JSON.parse(n),t),i=n.endsWith(`
8
- `)?`
9
- `:``;W(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=St(n,t.contentDir);r!==n&&W(e,r)}}function Et(e,t){let n=H(e,`utf-8`),r=St(n,t.contentDir);r!==n&&W(e,r)}function Dt(e){try{return U(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>R(e,t.name))}catch{return[]}}const Ot=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function kt(e){return/\.log\.\d+$/.test(e)}function At(e){return e.endsWith(`.jsonl`)||e.endsWith(`.log`)||kt(e)}const jt=[`telemetry`,`logs`,`process`,`diagnostic-reports`];function Mt(e){let t={contentDir:e.contentDir};for(let n of jt)for(let r of Dt(R(e.stagingDir,n)))At(r)?wt(r,t):r.endsWith(`.json`)?Tt(r,t):Et(r,t);for(let n of Dt(R(e.stagingDir,`state`))){let e=I(n);n.endsWith(`.jsonl`)?wt(n,t):Ot.has(e)?Tt(n,t):Et(n,t)}}const Nt=[`.ok`,`local`,`telemetry`],Pt=[`.ok`,`local`,`logs`],Ft=[`.ok`,`local`,`loss-capture`],It=`spans-current.jsonl`,Lt=`spans-prev.jsonl`,Rt=`server-current.jsonl`,zt=`server-prev.jsonl`,Bt=`loss-current.jsonl`,Vt=`loss-prev.jsonl`;function Ht(e){return R(e,...Nt,It)}function Ut(e){return R(e,...Nt,Lt)}function Wt(e){return R(e,...Pt,Rt)}function Gt(e){return R(e,...Pt,zt)}function Kt(e){return R(e,...Ft,Bt)}function qt(e){return R(e,...Ft,Vt)}const Jt=1e3;async function Yt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(Jt)});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(Jt)});return t.ok?await t.text():null}catch{return null}}async function Zt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout(Jt)});return t.ok?await t.text():null}catch{return null}}function Qt(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(`
10
- `)}\n`:null}catch{return null}}function $t(e){let t=R(e,`.git`,`ok`);if(!B(t))return null;let n=fe(`git`,[`-C`,t,`log`,`--oneline`,`-50`],d({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function en(e){let t=R(e,`.git`,`ok`);if(!B(t))return null;let n=fe(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],d({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function tn(){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 nn(){return{nodeVersion:process.version,platform:Te(),arch:Se()}}function rn(){return process.env.OTEL_SDK_DISABLED===`false`}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function an(e){if(!B(e))return{};let t;try{t=(0,Me.parse)(H(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(!X(t))return{};let n=t.telemetry;if(!X(n))return{};let r=n.localSink;return X(r)?r:{}}function on(e){return typeof e==`boolean`?e:void 0}function sn(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function Z(e){if(X(e))return sn(e.maxBytes)}function cn(e){let t=an(v(`project`,e)),n=an(v(`project-local`,e));return{enabled:on(n.enabled)??on(t.enabled)??!0,spansMaxBytes:Z(n.spans)??Z(t.spans)??52428800,logsMaxBytes:Z(n.logs)??Z(t.logs)??26214400}}function ln(e){return je(`sha256`).update(e).digest(`hex`)}function un(e){let t=H(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}const dn=[`"doc.name"`,`"docName"`];function fn(e){let t=H(e,`utf-8`),n=0;for(let e of dn){let r=t.indexOf(e);for(;r!==-1;)n++,r=t.indexOf(e,r+e.length)}return n}function Q(e,t){if(!B(e))return!1;try{return V(L(t),{recursive:!0}),e.endsWith(`.ips`)?W(t,Qe(H(e,`utf-8`))):he(e,t),!0}catch{return!1}}function pn(e){let t=[],n=e=>{let r=U(e,{withFileTypes:!0});for(let i of r){let r=R(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const mn=new Set([`.jsonl`]);function hn(e){let t=e.lastIndexOf(`.`);return t===-1?!1:mn.has(e.slice(t))}const gn=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`,`.yaml`,`.yml`,`.ips`]);function _n(e){if(kt(e))return!0;let t=e.lastIndexOf(`.`);return t===-1?!1:gn.has(e.slice(t))}function vn(e){let t=[];for(let n of pn(e)){let i=yn(e,n);if(!_n(i))continue;let{redacted:a,patterns:o,lineCount:s}=r(H(n,`utf-8`));o.length!==0&&(W(n,a),t.push({file:i,lineCount:s,patterns:o}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function yn(e,t){return pe(e,t).split(me).join(`/`)}async function bn(e){let t=z(e.contentDir),n=z(e.projectDir??e.contentDir),r=e.deps??{},i=r.fetchAgentPresence??Yt,o=r.fetchAgentEffects??Xt,s=r.fetchWatcherRecent??Zt,c=r.readShadowHead??$t,d=r.readCheckpointRefs??en,ee=r.now??(()=>new Date),f=r.okVersion??(()=>le),p=r.readDesktopEnv??tn,m=r.readLanguage??xt,h=r.readRuntime??nn,g=r.isOtlpPushEnabled??rn,_=ve(R(De(),`ok-bundle-`));try{V(R(_,`telemetry`),{recursive:!0}),V(R(_,`logs`),{recursive:!0}),V(R(_,`state`),{recursive:!0}),Q(Ht(n),R(_,`telemetry`,It)),Q(Ut(n),R(_,`telemetry`,Lt)),Q(Wt(n),R(_,`logs`,Rt)),Q(Gt(n),R(_,`logs`,zt));for(let t of e.userLogFiles??[])Q(t,R(_,`logs`,I(t)));for(let t of e.userStateFiles??[])Q(t,R(_,a,I(t)));let v=0;for(let t of e.diagnosticReports?.files??[])Q(t,R(_,`diagnostic-reports`,I(t)))&&(v+=1);let y=R(n,`.ok`,`local`),b=R(y,`server.lock`),x=`not-running`,S=`no server.lock`,C=null;if(B(b)){Q(b,R(_,`state`,`server.lock`));try{let e=H(b,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?C=t.port:S=`lock present but no port`}catch{S=`lock present but unparseable`}}if(C!==null){let e=await i(C);e===null?S=`agent-presence endpoint at :${C} unreachable`:(W(R(_,`state`,`agent-presence.json`),e),x=`running`,S=``);let t=await o(C);t!==null&&W(R(_,`state`,`agent-effects.json`),t);let n=await s(C);if(n!==null){let e=Qt(n);e!==null&&W(R(_,`state`,`watcher-recent.jsonl`),e)}}let w=c(t);w!==null&&W(R(_,`state`,`shadow-head.txt`),w);let T=d(t);T!==null&&W(R(_,`state`,`checkpoint-refs.txt`),T),Q(Kt(n),R(_,`state`,Bt)),Q(qt(n),R(_,`state`,Vt)),Q(R(y,`last-spawn-error.log`),R(_,`state`,`last-spawn-error.log`)),Q(R(y,l),R(_,`state`,l)),Q(R(y,u),R(_,`state`,u));let E=h(),D=p(),O=m(),k={ok:{version:f(),nodeVersion:E.nodeVersion,platform:E.platform,arch:E.arch},host:{desktop:D,language:O}};W(R(_,`state`,`runtime.json`),`${JSON.stringify(k,null,2)}\n`);let te=x===`running`?`running
11
- `:`not-running (${S})\n`;W(R(_,`state`,`server-status.txt`),te);let A=e.diagnosticReports===void 0?`not-collected (no collection attempted)`:Je(e.diagnosticReports,v);if(W(R(_,`state`,`diagnostic-reports-status.txt`),`${A}\n`),e.processDir&&B(e.processDir)){let t=R(_,`process`);V(t,{recursive:!0}),he(e.processDir,t,{recursive:!0})}let j=e.redact===!0;j&&Mt({stagingDir:_,contentDir:t}),e.note&&W(R(_,`note.txt`),e.note);let M=null;e.scrubSecrets===!0&&(M=vn(_));for(let t of e.extraFiles??[])Q(t.sourcePath,R(_,`extra`,t.zipName??I(t.sourcePath)))||r.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let N=cn(n),ne=pn(_),re=[],ie=0,P=0;for(let e of ne){let t=yn(_,e),n=xe(e).size,r=hn(t)?un(e):0;re.push({path:t,bytes:n,lines:r}),ie+=n,(t.startsWith(`telemetry/`)||t.startsWith(`logs/`))&&(P+=fn(e))}let ae={applied:j};M!==null&&(ae.secretScrub=M);let F={schemaVersion:2,createdAt:ee().toISOString(),ok:{version:f(),nodeVersion:E.nodeVersion,platform:E.platform,arch:E.arch},host:{desktop:D,language:O},contentDir:{pathSha256:ln(t),absolutePath:j?`<CONTENT_DIR>`:t},telemetry:{localSink:N,otlpPushEnabled:g()},redaction:ae,serverStatus:x,files:re};W(R(_,`manifest.json`),`${JSON.stringify(F,null,2)}\n`);let oe=ne.some(e=>{try{return H(e,`utf-8`).includes(t)}catch{return!1}}),se={stagedDiagnosticReports:v,totalBytes:ie,fileCount:re.length,docNameCount:P,contentDirVisible:oe,redacted:j},ce=!1;return{stagingDir:_,manifest:F,summary:se,cleanup:()=>{ce||(ce=!0,be(_,{recursive:!0,force:!0}))}}}catch(e){throw be(_,{recursive:!0,force:!0}),e}}async function xn(e){let{collected:t,outputPath:n}=e,r=L(n);if(!B(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new yt.ZipFile,a=pn(t.stagingDir);for(let e of a){let n=yn(t.stagingDir,e);i.addFile(e,n)}i.end();let o=ge(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 Sn(e,t){let n=R(e,`.ok`,`config.yml`);if(B(n))try{let t=(0,Me.parse)(H(n,`utf-8`)),r=ue(t)?t.content:void 0,i=ue(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return z(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 z(e)}async function Cn(e,t,n,r,i){let a=at(t,e.logger),o=await bn({contentDir:Sn(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,userLogFiles:[...lt(a,e.userLogsDir??R(G(),`.ok`,`logs`)),...dt(e.cachesDir??R(G(),`Library`,`Caches`))],userStateFiles:ft(e.bugReportsDir??K()),diagnosticReports:i,deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{V(L(e.outputPath),{recursive:!0}),await xn({collected:o,outputPath:e.outputPath});let t=o.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:a,files:o.manifest.files.map(e=>e.path),redactions:t?.redactions??[],redactedLineCount:t?.redactedLineCount??0,generatedAt:o.manifest.createdAt}}}finally{o.cleanup()}}async function wn(e){let{projectDir:t}=e,n=e.readDesktopEnv??tn,r=e.readLanguage??xt,i=()=>rt(e.diagnosticReportsDir??R(G(),`Library`,`Logs`,`DiagnosticReports`),new Date);if(e.level===`full`&&t!==void 0)return Cn(e,t,n,r,i());let{zipPath:a,summary:o}=await vt({projectDir:t,redact:e.redact,revealDocNames:e.level===`full`,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:dt(e.cachesDir??R(G(),`Library`,`Caches`)),bugReportLedgerFiles:ft(e.bugReportsDir??K()),diagnosticReports:e.level===`full`?i():void 0,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n(),language:r()});return{zipPath:a,summary:{level:e.level,systemWide:t===void 0,projectSlug:o.projectSlug,files:o.files,redactions:o.redactions,redactedLineCount:o.redactedLineCount,generatedAt:o.generatedAt}}}function $(e,t,n={}){let r=E(e,t);if(!B(r))return{status:`missing`,lockPath:r};let i;try{i=JSON.parse(H(r,`utf-8`))}catch{return{status:`corrupt`,lockPath:r}}if(!i||typeof i!=`object`||!S(i.pid))return{status:`corrupt`,lockPath:r};let a=i;if(!(n.isAlive??C)(a.pid))return{status:`dead-pid`,lockPath:r,lock:a};if(typeof a.machineId==`string`)return a.machineId===(n.machineId??w())?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a};let o=n.host??we();return a.hostname===o?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a}}function Tn(e){return e.replace(/:\d+$/,``)}function En(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:Tn(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:Tn(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:Tn(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 Dn=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function On(e){return R(e,`Library`,`Application Support`,`OpenKnowledge`,`path-install.json`)}const kn={existsSync:e=>B(e),readFileSync:(e,t)=>H(e,t),lstatSync:e=>_e(e),readlinkSync:e=>ye(e)};function An(e,t=kn){let n=On(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 jn(e){let t=e.replace(Dn,``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function Mn(e,t,n=kn){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}function Nn(e){return A(e)||te(e)||ae(e)}const Pn=10*1024*1024;function Fn(e,t,n,r){let i=ce(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);if(e.format===`file`){be(a,{force:!0});let e=re(t,n);return{kind:`removed`,trust:e.action,...e.error===void 0?{}:{trustError:e.error}}}return e.format===`toml`?Rn(a,o):e.format===`yaml`?Ln(a,e.topLevelKey,o):In(a,e.topLevelKey,e.serverMapSubKey,o)}function In(e,t,n,r){let i;try{i=H(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(i,`utf-8`)>Pn)return{kind:`declined`,reason:`oversize`};let{text:a,changed:o}=ie(i,oe(t,n,r));return o?(y(e,a,{mode:F(e)}),{kind:`removed`}):{kind:`not-present`}}function Ln(e,t,n){let r;try{r=H(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(r,`utf-8`)>Pn)return{kind:`declined`,reason:`oversize`};let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=(0,Me.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=P(a);a.trim()===``||a.endsWith(`
12
- `)?c.endsWith(`
13
- `)||(c=`${c}\n`):c=c.replace(/\n+$/,``),l&&(c=c.replace(/\r\n/g,`
14
- `).replace(/\n/g,`\r
15
- `));let u=`${i?``:``}${c}`;return u!==r&&y(e,u,{mode:F(e)}),{kind:`removed`}}function Rn(e,t){let n=se();if(n.backend===`fallback`)return{kind:`declined`,reason:`no-native-writer`};let r;try{r=H(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=P(a),s=a.trim()===``||a.endsWith(`
16
- `),c;try{c=n.removeEntry(a,t)}catch{return{kind:`declined`,reason:`unparseable`}}if(!c.existed)return{kind:`not-present`};let l=c.text;s?l.endsWith(`
17
- `)||(l=`${l}\n`):l=l.replace(/\n+$/,``),o&&(l=l.replace(/\r\n/g,`
18
- `).replace(/\n/g,`\r
19
- `));let u=`${i?``:``}${l}`;return u!==r&&y(e,u,{mode:F(e)}),{kind:`removed`}}function zn(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Bn(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 Vn(e,t,n,r){if(t.status===`missing`||t.status===`corrupt`)return null;let i=t.lock,a=t.status===`alive`&&D(i)?{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r}:null;return{directory:i.worktreeRoot,server:{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r},ui:a,hostname:i.hostname,lockPath:t.lockPath,binary:n==null?null:ee(n),command:n,isDesktop:zn(n)}}function Hn(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:`stale`}const Un=new Set([`running`,`desktop`,`foreign`]);function Wn(e){switch(e){case`running`:return J.default.green(e);case`desktop`:return J.default.blue(e);case`foreign`:return J.default.cyan(e);case`stale`:return J.default.yellow(e)}}function Gn(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Kn(e){return`${Gn(e.server.usage)} | ${Gn(e.ui?.usage??null)}`}function qn(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null?`—`:String(e.ui.port)}`}function Jn(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>[e.directory,qn(e),Kn(e),Hn(e),String(e.server.pid),Bn(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=Wn(Hn(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=J.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
20
- `)}async function Yn(e={}){let t=e.discover??h,n=e.inspect??(e=>$(e,`server`)),r=e.log??(e=>console.log(e)),i=e.resolveCommand??m,a=e.resolveUsage??g,o=await t(),s=[];for(let e of o){let t=n(e),r=Vn(e,t,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid));r!=null&&s.push(r)}if(e.json){let e=s.map(e=>({...e,displayStatus:Hn(e)}));r(JSON.stringify(e,null,2));return}r(Jn(e.all?s:s.filter(e=>Un.has(Hn(e)))))}function Xn(){return new M(`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})})}async function Zn(e,t=Pe()){let n=$(e,`server`);if(n.status!==`alive`&&n.status!==`foreign-host`)return null;let r=T(n.lock);if(r===null)return null;try{let n=await fetch(`${r}/api/server-info`,{signal:AbortSignal.timeout(1500)});if(!n.ok)return t?.warn({lockDir:e,baseUrl:r,outcome:`http-error`,status:n.status},`stop client-probe failed`),null;let i=(await n.json())?.collabClients;return typeof i==`number`&&Number.isFinite(i)?i:(t?.warn({lockDir:e,baseUrl:r,outcome:`no-client-count`,received:typeof i},`stop client-probe failed`),null)}catch(n){return t?.warn({lockDir:e,baseUrl:r,outcome:`unreachable`,err:n},`stop client-probe failed`),null}}function Qn(e,t={}){return{targets:er(e,t.isAlive??C)?[{name:`server`,pid:e.lock.pid,port:e.lock.port}]:[]}}async function $n(e){let t=e.inspect??(()=>$(e.lockDir,`server`)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=e.probeClients??Zn,o=e.logger??Pe(),s=Qn(t(),{isAlive:e.isAlive});if(s.targets.length===0)return r(`No running open-knowledge processes.`),o?.info({lockDir:e.lockDir,targets:0},`stop found nothing to signal`),{stopped:[],failed:[],hadTargets:!1};if(e.force!==!0){let t=await a(e.lockDir,o);if(t!==null&&t>0)return i(`Not stopping: ${t} collaboration client${t===1?``:`s`} (editor window${t===1?``:`s`} or agents) still connected to the server at ${e.lockDir}. Close them, or re-run with --force to terminate anyway.`),o?.warn({lockDir:e.lockDir,clients:t,pids:s.targets.map(e=>e.pid)},`stop declined: live collaboration clients`),{stopped:[],failed:[],hadTargets:!0,declined:{clients:t}}}let c=[],l=[];for(let e of s.targets)try{n(e.pid,`SIGTERM`),c.push(e)}catch(t){l.push({target:e,error:t instanceof Error?t.message:String(t)})}return c.length>0&&r(`Stopped: ${c.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),o?.info({lockDir:e.lockDir,signalled:c.map(e=>({name:e.name,pid:e.pid,port:e.port})),failed:l.map(({target:e,error:t})=>({pid:e.pid,error:t})),forced:e.force===!0},`stop signalled processes`),l.length>0&&i(`Failed to stop: ${l.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:c,failed:l,hadTargets:!0}}function er(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function tr(e,t=C){let n=await h(),r=null;for(let i of n){let n=$(i,`server`);if(er(n,t)){if(n.lock.port===e)return i;r===null&&n.lock.pid===e&&(r=i)}}return r}async function nr(e,t){let n=await $n({lockDir:e,force:t});return(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1),n}function rr(e,t,n={}){return t===0?`Nothing was running for ${e}, and no other open-knowledge servers are running.`:`Nothing was running for ${e}. ${t} other open-knowledge server${t===1?` is`:`s are`} running${n.listingFollows===!0?``:" — run `ok ps` to list them"}.`}async function ir(e){let t=await h(),n=0;for(let r of t)r!==e&&er($(r,`server`),C)&&n++;return n}function ar(e){return new M(`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"`).option(`--force`,`Stop even when editor windows or agents are still connected to the server`).action(async(t,n)=>{let r=n.force===!0,i=t.length===0?void 0:t.join(` `);if(i===void 0){e();let t=_(process.cwd()),n=await $n({lockDir:t,force:r,log:()=>{}});if(n.hadTargets){if(n.stopped.length>0){let e=n.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1)}else{let e=await ir(t);console.log(rr(process.cwd(),e,{listingFollows:e>0})),e>0&&await Yn({})}return}if(i===`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)er($(n,`server`),C)&&(await nr(n,r),t++);t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(i)){let e=Number.parseInt(i,10),t=await tr(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}await nr(t,r);return}let a=z(Ve(),i),o=_(a),s=[],c=await $n({lockDir:o,force:r,log:e=>s.push(e)});if((c.failed.length>0||c.declined!==void 0)&&(process.exitCode=1),c.hadTargets)for(let e of s)console.log(e);else console.log(rr(a,await ir(o)))})}export{Ke as C,Re as D,Be as E,Pe as O,Ue as S,Ve as T,K as _,Fn as a,He as b,On as c,En as d,$ as f,it as g,xn as h,Xn as i,Ie as k,An as l,bn as m,$n as n,Dn as o,wn as p,ar as r,Mn as s,Zn as t,jn as u,rt as v,qe as w,We as x,Je as y};
21
- //# sourceMappingURL=src-BR3UyegR.mjs.map