@inkeep/open-knowledge 0.69.0 → 0.69.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 (79) hide show
  1. package/dist/{acp-harness-probe-DDZx560B.mjs → acp-harness-probe-DBSW3LbG.mjs} +1 -1
  2. package/dist/cli.mjs +6 -6
  3. package/dist/constants-CDluLUFq.mjs +1 -0
  4. package/dist/{dist-Db-P3aGR.mjs → dist-D-X0Yg3B.mjs} +1 -1
  5. package/dist/{dist-DYRgOemK.mjs → dist-rXSsjKu4.mjs} +247 -247
  6. package/dist/index.mjs +1 -1
  7. package/dist/{init-ClVQKpTb.mjs → init-BBRSc_7a.mjs} +2 -2
  8. package/dist/init-IvScMWag.mjs +1 -0
  9. package/dist/{launch-json-removal-RVGoeN0A.mjs → launch-json-removal-DRfScIlI.mjs} +1 -1
  10. package/dist/{loader-B2BRl64M.mjs → loader-CcLX9hvf.mjs} +1 -1
  11. package/dist/loader-nfkvLo1X.mjs +1 -0
  12. package/dist/{open-browser-D7BRsUDm.mjs → open-browser-DTJSqTQH.mjs} +1 -1
  13. package/dist/preview-Cpbfv4-W.mjs +1 -0
  14. package/dist/{preview-DG6Du8Cq.mjs → preview-DOqLANTC.mjs} +1 -1
  15. package/dist/public/assets/{ActivityModeContent-BtUHOKhl.js → ActivityModeContent-D-gOyyIg.js} +1 -1
  16. package/dist/public/assets/{AddPropertiesButton-B1Sqlbky.js → AddPropertiesButton-DMepIRAv.js} +1 -1
  17. package/dist/public/assets/{AgentDiffPane-CjKxTFkX.js → AgentDiffPane-ZCO1qj1L.js} +1 -1
  18. package/dist/public/assets/{CodeMirrorPropInput-VVIzUqY-.js → CodeMirrorPropInput-DY70O775.js} +1 -1
  19. package/dist/public/assets/{DocumentContext-Bctph-Hl.js → DocumentContext-vBNJ-Cdr.js} +1 -1
  20. package/dist/public/assets/{EditorModeToggle-BoKBeRU9.js → EditorModeToggle-Bm-mLnCb.js} +1 -1
  21. package/dist/public/assets/{EnableSyncConfirmDialog-DmTuiGjB.js → EnableSyncConfirmDialog-BFcf4emo.js} +1 -1
  22. package/dist/public/assets/{ExcalidrawDocEditor-CqGr_rRC.js → ExcalidrawDocEditor-ByygowKy.js} +1 -1
  23. package/dist/public/assets/FeedbackForm-BEeIBVH4.js +1 -0
  24. package/dist/public/assets/{ImportSkillDialog-MGafxiRq.js → ImportSkillDialog-D8Y7cySO.js} +1 -1
  25. package/dist/public/assets/{LintConfigEditor-CsX2pq5S.js → LintConfigEditor-qw85cybs.js} +1 -1
  26. package/dist/public/assets/{ManagedArtifactProperties-BITPt-_L.js → ManagedArtifactProperties-BZNiVx42.js} +1 -1
  27. package/dist/public/assets/ManagedArtifactProperties-Cw5KWGzG.js +1 -0
  28. package/dist/public/assets/{MermaidDocEditor-8qhvNL-M.js → MermaidDocEditor-cvNMIn9f.js} +1 -1
  29. package/dist/public/assets/{PropertyDisplayRow-BYroqm7y.js → PropertyDisplayRow-CjzV4-Vt.js} +1 -1
  30. package/dist/public/assets/{SchemaConfigEditor-BsYLyhDs.js → SchemaConfigEditor-njM43CFG.js} +1 -1
  31. package/dist/public/assets/{SessionsHost-DM_V9GQB.js → SessionsHost-C1RzXIMS.js} +2 -2
  32. package/dist/public/assets/{SettingsDialogBody-CVNVDP3j.js → SettingsDialogBody-DTvvW_Zx.js} +1 -1
  33. package/dist/public/assets/{ShareReceiveMissDialog-CfAZyYpR.js → ShareReceiveMissDialog-C9ecBdyq.js} +1 -1
  34. package/dist/public/assets/{SkillInstallMenu-Bz6sIbLL.js → SkillInstallMenu-Cdo0N4rZ.js} +1 -1
  35. package/dist/public/assets/{SkillToolbarControls-Bi2IGVAN.js → SkillToolbarControls-CFhVVqUX.js} +1 -1
  36. package/dist/public/assets/{SourceEditor-DRWiP5Vf.js → SourceEditor-BKtF1CXz.js} +1 -1
  37. package/dist/public/assets/{TerminalWindowApp-BrJa7rfF.js → TerminalWindowApp-HnSyl8Yq.js} +1 -1
  38. package/dist/public/assets/{TextDocEditor-vicT5VSm.js → TextDocEditor-C1pZKMJy.js} +1 -1
  39. package/dist/public/assets/{ThreadView-ZAY_akk1.js → ThreadView-BM18mhAx.js} +1 -1
  40. package/dist/public/assets/{TimelineDiffPane-BNlcbJhw.js → TimelineDiffPane-BygEanlK.js} +1 -1
  41. package/dist/public/assets/{agent-diff-store-axExpP_d.js → agent-diff-store-CPizJ_eo.js} +1 -1
  42. package/dist/public/assets/{auth-state-cache-BFfz7JAK.js → auth-state-cache-BYTdrNrU.js} +1 -1
  43. package/dist/public/assets/{client-version-CjkZeZzF.js → client-version-SQ-LgVkc.js} +1 -1
  44. package/dist/public/assets/{comment-chips-B_igKUhF.js → comment-chips-Cbbf5tPC.js} +1 -1
  45. package/dist/public/assets/{config-provider-lMh3qB5Y.js → config-provider-2yYopfHI.js} +1 -1
  46. package/dist/public/assets/{doc-undo-manager-BLq8Dma7.js → doc-undo-manager-CgPwSDHm.js} +1 -1
  47. package/dist/public/assets/{index-B0HI1pzX.js → index--d9VPJh4.js} +7 -7
  48. package/dist/public/assets/{pending-receive-nav-store-UWSL7sU6.js → pending-receive-nav-store-DcN0rbT1.js} +1 -1
  49. package/dist/public/assets/{progress-DKJUdHw-.js → progress-pgO8UB4m.js} +1 -1
  50. package/dist/public/assets/{selection-context-D1tykBf6.js → selection-context-Bc6kodP9.js} +1 -1
  51. package/dist/public/assets/{src-Bd9_jj6p.js → src-tCMUadGy.js} +1 -1
  52. package/dist/public/assets/{telemetry-impl-DkxI3ruc.js → telemetry-impl-D8b0Lz4E.js} +1 -1
  53. package/dist/public/assets/{telemetry-startup-CSADiB4T.js → telemetry-startup-tdRVaPoP.js} +1 -1
  54. package/dist/public/assets/{typing-burst-detector-CDgmvf7o.js → typing-burst-detector-BWyPshFG.js} +1 -1
  55. package/dist/public/assets/{use-activity-panel-DSOGit1h.js → use-activity-panel-CRfGEqEf.js} +1 -1
  56. package/dist/public/assets/{use-open-skill-B0i7BySv.js → use-open-skill-DVsmIGYC.js} +1 -1
  57. package/dist/public/assets/{use-terminal-enabled-BL44WFHb.js → use-terminal-enabled-3oU29-6-.js} +1 -1
  58. package/dist/public/assets/{use-timeline-entry-diff-jtkhdBDb.js → use-timeline-entry-diff-CweASqOk.js} +1 -1
  59. package/dist/public/index.html +19 -19
  60. package/dist/{repair-launch-json-D3WpmymA.mjs → repair-launch-json-DWOikU7H.mjs} +1 -1
  61. package/dist/{repair-mcp-configs-Ul1vx1q9.mjs → repair-mcp-configs-Bunrwblo.mjs} +1 -1
  62. package/dist/repair-skills-5EO0Uwch.mjs +1 -0
  63. package/dist/{repair-skills-Cphq1SzP.mjs → repair-skills-hGJGjJEr.mjs} +1 -1
  64. package/dist/{resolve-project-root-Oh5l_16q.mjs → resolve-project-root-Dyi1SFSV.mjs} +1 -1
  65. package/dist/{skill-teardown-CJwWL618.mjs → skill-teardown-BIi-5NQJ.mjs} +1 -1
  66. package/dist/{src-P5JlIxeB.mjs → src-9XuK4ws5.mjs} +1 -1
  67. package/dist/src-B3yrrrM3.mjs +1 -0
  68. package/dist/{start-D3QRXVYB.mjs → start-Clkz9_Ou.mjs} +3 -3
  69. package/dist/start-DeFgW48G.mjs +1 -0
  70. package/package.json +4 -4
  71. package/dist/constants-CsSKBE7w.mjs +0 -1
  72. package/dist/init-1pbX3Cyj.mjs +0 -1
  73. package/dist/loader-Cgs4nR1G.mjs +0 -1
  74. package/dist/preview-CWGsVtt6.mjs +0 -1
  75. package/dist/public/assets/FeedbackForm-Bjn9zy_O.js +0 -1
  76. package/dist/public/assets/ManagedArtifactProperties-BdG10JoH.js +0 -1
  77. package/dist/repair-skills-BdPGQfHw.mjs +0 -1
  78. package/dist/src-IXvYkB5s.mjs +0 -1
  79. package/dist/start-BH6_3L8R.mjs +0 -1
@@ -1 +1 @@
1
- import{Sl as e}from"./md-manager-BGnqyqi1-eohu_6wW.mjs";import{Tt as t,m as n}from"./dist-DYRgOemK.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(e=>n[e]),`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=n[r];o.push({path:a(i,`.agents`,`skills`,t),bundleId:r,scope:`central`});for(let n of e)o.push({path:a(i,n.skillsRoot,t),bundleId:r,scope:`host`,hostDir:n.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};
1
+ import{Sl as e}from"./md-manager-BGnqyqi1-eohu_6wW.mjs";import{Tt as t,m as n}from"./dist-rXSsjKu4.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(e=>n[e]),`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=n[r];o.push({path:a(i,`.agents`,`skills`,t),bundleId:r,scope:`central`});for(let n of e)o.push({path:a(i,n.skillsRoot,t),bundleId:r,scope:`host`,hostDir:n.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};
@@ -1,4 +1,4 @@
1
- import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{$l as t,$s as n,Dn as r,En as i,Fn as a,Ps as o,Qs as s,Yo as c,ro as l,ss as u,tc as d}from"./md-manager-BGnqyqi1-eohu_6wW.mjs";import{$a as f,$r as p,Cn as m,Co as h,In as g,To as _,Vr as v,Xi as y,Zn as b,_i as x,ei as S,gi as C,qn as w,qr as T,ti as E,ur as D,wo as O,xo as k}from"./dist-DYRgOemK.mjs";import{t as A}from"./yazl-BBz29IQN.mjs";import{_ as j,h as M,m as N,v as P,x as F}from"./resolve-project-root-Oh5l_16q.mjs";import{c as ee}from"./colors-r_owlCuY.mjs";import{a as I,i as te}from"./acp-harness-probe-DDZx560B.mjs";import{D as ne,E as L,S as re,T as ie,_ as ae,b as oe,o as se}from"./init-ClVQKpTb.mjs";import{n as ce}from"./constants-CsSKBE7w.mjs";import{t as le}from"./is-object-BGze3w87.mjs";import"./loader-B2BRl64M.mjs";import"./skill-teardown-CJwWL618.mjs";import"./preview-DG6Du8Cq.mjs";import{execSync as ue,spawnSync as de}from"node:child_process";import{basename as R,dirname as z,join as B,relative as fe,resolve as V,sep as pe}from"node:path";import{closeSync as me,cpSync as he,createWriteStream as ge,existsSync as H,mkdirSync as U,mkdtempSync as _e,openSync as ve,readFileSync as W,readSync as ye,readdirSync as G,rmSync as be,statSync as xe,writeFileSync as K}from"node:fs";import{arch as Se,freemem as Ce,homedir as q,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=t();let Ne;function Pe(){return Ne}function Fe(e,t){if(t!==void 0&&t.length>0)return t;try{return b(e)?.rootPath}catch{return}}function Ie(e){let t=Fe(e.cwd,e.configuredProjectName),n=m({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=b){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 j(t).join(P({...e,platformName:t}),n)}function We(e={}){let t=e.platformName??process.platform,n=e.home??q(),r=e.env??process.env,i=j(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=B(e,`state.json`);if(!H(t))return[];let n;try{n=JSON.parse(W(t,`utf-8`))}catch{return[]}return Ge(n)??[]}function qe(e){let t=B(e,`state.json`);if(!H(t))return!1;try{return Ge(JSON.parse(W(t,`utf-8`)))!==null}catch{return!1}}const Je=8192;function Ye(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 Xe(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const Ze=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Qe(e){return e.replace(Ze,`$1"[REDACTED-DEVICE-ID]"`)}function $e(e){return Qe(Xe(e))}const et=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function tt(e){if(typeof e!=`string`)return null;let t=et.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 nt(e){let t=ve(e,`r`);try{let e=Buffer.alloc(Je),n=0,r=!1;for(;n<Je;){let i=ye(t,e,n,Je-n,n);if(i===0){r=!0;break}let a=n;n+=i;let o=e.subarray(0,n).indexOf(10,a);if(o!==-1)return e.subarray(0,o).toString(`utf-8`)}return r?e.subarray(0,n).toString(`utf-8`):null}finally{me(t)}}function rt(e){try{let t=nt(e);if(t===null)return{kind:`unreadable`};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{kind:`unreadable`};let{name:r,app_name:i,timestamp:a}=n,o=typeof r==`string`?r:typeof i==`string`?i:null;return o===null?{kind:`unreadable`}:{kind:`named`,name:o,timestampMs:tt(a)}}catch{return{kind:`unreadable`}}}function it(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function at(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=G(e,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`?{...n,outcome:`not-present`}:{...n,outcome:`unreadable-directory`,directoryErrorCode:t??`unknown`}}let i=t.getTime()-6048e5,a=[],o=0,s=0;for(let t of r){if(!t.isFile()||!t.name.endsWith(`.ips`))continue;let n=B(e,t.name),r;try{r=xe(n).mtimeMs}catch{continue}if(r<i)continue;let c=rt(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!it(c.name)){o+=1;continue}a.push({path:n,atMs:l})}a.sort((e,t)=>t.atMs-e.atMs);let c=a.slice(0,25),l={foreignIgnored:o,unparseable:s,droppedOverCap:a.length-c.length,windowDays:7};return c.length===0?{...l,files:[],outcome:`none-in-window`}:{...l,files:c.map(e=>e.path),outcome:`collected`}}function ot(){return B(q(),`.ok`,`bug-reports`)}function st(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=ot(),r=`${t}-bugreport`,i=B(n,`${r}.zip`);for(let e=2;H(i);e+=1)i=B(n,`${r}-${e}.zip`);return i}function ct(e,t){let n=B(e,`.ok`,`config.yml`);if(H(n))try{let e=W(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return H(B(e,`.ok`))?je(`sha256`).update(V(e)).digest(`hex`).slice(0,12):null}function lt(){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=ue(`sw_vers -productVersion 2>/dev/null`,f({encoding:`utf8`})).trim()}catch{}try{let t=B(__dirname,`..`,`..`,`package.json`);H(t)&&(e.okVersion=JSON.parse(W(t,`utf8`)).version)}catch{}return e}const ut=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function dt(e){let t=R(e);return ut.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function ft(e,t){return gt(e,t).files}const pt=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function mt(e,t=I){let n=B(e,`${t}.ShipIt`);if(!H(n))return[];let r;try{r=G(n)}catch{return[]}return pt.flatMap(e=>r.map(t=>{if(t===e)return{entry:t,suffix:-1};if(!t.startsWith(`${e}.`))return null;let n=t.slice(e.length+1);return/^\d+$/.test(n)?{entry:t,suffix:Number(n)}:null}).filter(e=>e!==null).sort((e,t)=>e.suffix-t.suffix).slice(0,4).map(e=>B(n,e.entry)))}function ht(e){if(!H(e))return[];try{let t=new Map;for(let n of G(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-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=>B(e,t))}catch{return[]}}function gt(e,t){if(!H(t))return{files:[],excludedByProjectSlug:0};let n=G(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>B(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(dt),i=[],a=r.filter(t=>{try{return W(t,`utf8`).includes(`"project":"${e}"`)}catch{return i.push(t),!1}});if(a.length===0)return{files:n,excludedByProjectSlug:0};let o=new Set([...a,...i]);return{files:n.filter(e=>!dt(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function _t(e){let t=B(e,`.ok`,`local`);return H(t)?{files:[`server.lock`,`last-spawn-error.log`,s].map(e=>B(t,e)).filter(e=>H(e))}:{files:[]}}function vt(e){let t=B(e,`.ok`,`local`,`logs`);return H(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>B(t,e)).filter(e=>H(e))}:{files:[]}}function yt(e){let t=0,n=new Map,r=e.replace(/("(?:docName|doc\.name|documentName)"\s*:\s*")((?:[^"\\]|\\.)*)"/g,(e,r,i)=>{t+=1;let a=n.get(i);return a===void 0&&(a=`doc#${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 bt(e){let t=e.revealDocNames?e.content:yt(e.content).text;if(e.redact){let{redacted:n,patterns:r,lineCount:i}=c(t);e.zipfile.addBuffer(Buffer.from(n,`utf8`),e.name),e.bundleFiles.push(e.name),r.length>0&&e.redactions.push({file:e.name,lineCount:i,patterns:r})}else e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name)}function J(e){for(let t of e.files)try{let n=W(t,`utf8`);bt({zipfile:e.zipfile,name:`${e.prefix}/${R(t)}`,content:t.endsWith(`.ips`)?$e(n):n,redact:e.redact,revealDocNames:e.revealDocNames,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n},`bug-report: skipped unreadable file`)}}async function xt(t){let{redact:n,outputPath:i,logger:o}=t,s=t.revealDocNames??!1,c=t.userLogsDir??B(q(),`.ok`,`logs`),l=t.projectDir?ct(t.projectDir,o):null;U(z(i),{recursive:!0}),o?.info({projectSlug:l},`gathering diagnostic data`);let u=lt();u.desktop=t.desktop??null,u.language=t.language??null;let{files:d,excludedByProjectSlug:f}=gt(l,c),{files:p}=t.projectDir?_t(t.projectDir):{files:[]},{files:m}=t.projectDir?vt(t.projectDir):{files:[]},h=t.shipItLogFiles??[],g=t.diagnosticReports?.files??[];o?.info({logFileCount:d.length,logFilesExcludedByProjectSlug:f,lockFileCount:p.length,localSinkFileCount:m.length,shipItLogFileCount:h.length,diagnosticReportCount:g.length},`files collected`);let _=[],v=[],{ZipFile:y}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),b=new y;J({zipfile:b,files:[...d,...h],prefix:`logs`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:p,prefix:`lockdir`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:m,prefix:`local-logs`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:t.bugReportLedgerFiles??[],prefix:r,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:g,prefix:`diagnostic-reports`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o});for(let e of t.extraFiles??[])try{let t=W(e.sourcePath),n=`extra/${e.zipName??R(e.sourcePath)}`;b.addBuffer(t,n),v.push(n)}catch(t){o?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&bt({zipfile:b,name:`note.txt`,content:t.note,redact:n,revealDocNames:s,bundleFiles:v,redactions:_});let x=new Set(g.map(e=>`diagnostic-reports/${R(e)}`)),S=v.filter(e=>x.has(e)),C=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Ye(t.diagnosticReports,S.length);b.addBuffer(Buffer.from(`${C}\n`,`utf8`),`state/diagnostic-reports-status.txt`),v.push(`state/diagnostic-reports-status.txt`);let w=JSON.stringify(u,null,2);b.addBuffer(Buffer.from(w,`utf8`),`sysinfo.json`),v.push(`sysinfo.json`);let T={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:l,files:v,redactions:_,sysinfo:u};b.addBuffer(Buffer.from(JSON.stringify(T,null,2),`utf8`),`MANIFEST.json`);let E=_.reduce((e,t)=>e+t.lineCount,0),D=new Set(h.map(e=>`logs/${R(e)}`)),O=v.filter(e=>D.has(e)),k=new Set((t.bugReportLedgerFiles??[]).map(e=>`${r}/${R(e)}`)),A=v.filter(e=>k.has(e)),j=l?v.filter(e=>e.startsWith(`logs/`)&&!dt(e)&&!D.has(e)):[],M=S.length>0?[`Crash reports under diagnostic-reports/ are rewritten on the way in,`,`independently of this setting: escaped path separators are normalised`,`so the scrub above can read them, and the identifiers that link this`,`machine's bundles to each other are replaced. Nothing else is changed;`,`they are not byte-identical to the files macOS wrote.`]:[],N=M.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...M]:[`Redaction was disabled for this bundle; file contents are unmodified.`],P=[`# Bug Report Bundle`,``,`Generated: ${T.generatedAt}`,`Project: ${l??`(unscoped)`}`,`Discipline version: ${T.disciplineVersion}`,``,`## Contents`,``,...v.map(e=>`- ${e}`),``,`## Privacy`,``,...j.length>0?[`Scope: some collected logs are user-wide rather than project-scoped.`,`These are written once per machine per day and can contain activity`,`from other projects open on this machine, including captured console`,`output:`,...j.map(e=>`- ${e}`),``]:[],...O.length>0?[`Installer logs: written by the macOS update helper rather than by`,`OpenKnowledge itself, and machine-wide rather than scoped to any one`,`project. They record the install and update history of this app on`,`this machine. Only this app is collected, never other applications`,`that use the same update mechanism:`,...O.map(e=>`- ${e}`),``]:[],...S.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:`,...S.map(e=>`- ${e}`),``]:[],...A.length>0?[`Send history: a small record for each bug report previously generated`,`on this machine — when it was generated, whether sending it`,`succeeded, and why it failed if it did. This is what makes a failed`,`send diagnosable at all. It is machine-wide rather than scoped to`,`this project, so it names the other projects reports were filed`,`from. It carries no document content:`,...A.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${a.join(`, `)}`,E>0?`${E} line(s) were scrubbed across ${_.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...M,``,`This bundle is safe to attach to a GitHub issue.`]:N].join(`
1
+ import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{$l as t,$s as n,Dn as r,En as i,Fn as a,Ps as o,Qs as s,Yo as c,ro as l,ss as u,tc as d}from"./md-manager-BGnqyqi1-eohu_6wW.mjs";import{$a as f,$r as p,Cn as m,Co as h,In as g,To as _,Vr as v,Xi as y,Zn as b,_i as x,ei as S,gi as C,qn as w,qr as T,ti as E,ur as D,wo as O,xo as k}from"./dist-rXSsjKu4.mjs";import{t as A}from"./yazl-BBz29IQN.mjs";import{_ as j,h as M,m as N,v as P,x as F}from"./resolve-project-root-Dyi1SFSV.mjs";import{c as ee}from"./colors-r_owlCuY.mjs";import{a as I,i as te}from"./acp-harness-probe-DBSW3LbG.mjs";import{D as ne,E as L,S as re,T as ie,_ as ae,b as oe,o as se}from"./init-BBRSc_7a.mjs";import{n as ce}from"./constants-CDluLUFq.mjs";import{t as le}from"./is-object-BGze3w87.mjs";import"./loader-CcLX9hvf.mjs";import"./skill-teardown-BIi-5NQJ.mjs";import"./preview-DOqLANTC.mjs";import{execSync as ue,spawnSync as de}from"node:child_process";import{basename as R,dirname as z,join as B,relative as fe,resolve as V,sep as pe}from"node:path";import{closeSync as me,cpSync as he,createWriteStream as ge,existsSync as H,mkdirSync as U,mkdtempSync as _e,openSync as ve,readFileSync as W,readSync as ye,readdirSync as G,rmSync as be,statSync as xe,writeFileSync as K}from"node:fs";import{arch as Se,freemem as Ce,homedir as q,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=t();let Ne;function Pe(){return Ne}function Fe(e,t){if(t!==void 0&&t.length>0)return t;try{return b(e)?.rootPath}catch{return}}function Ie(e){let t=Fe(e.cwd,e.configuredProjectName),n=m({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=b){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 j(t).join(P({...e,platformName:t}),n)}function We(e={}){let t=e.platformName??process.platform,n=e.home??q(),r=e.env??process.env,i=j(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=B(e,`state.json`);if(!H(t))return[];let n;try{n=JSON.parse(W(t,`utf-8`))}catch{return[]}return Ge(n)??[]}function qe(e){let t=B(e,`state.json`);if(!H(t))return!1;try{return Ge(JSON.parse(W(t,`utf-8`)))!==null}catch{return!1}}const Je=8192;function Ye(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 Xe(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const Ze=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Qe(e){return e.replace(Ze,`$1"[REDACTED-DEVICE-ID]"`)}function $e(e){return Qe(Xe(e))}const et=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function tt(e){if(typeof e!=`string`)return null;let t=et.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 nt(e){let t=ve(e,`r`);try{let e=Buffer.alloc(Je),n=0,r=!1;for(;n<Je;){let i=ye(t,e,n,Je-n,n);if(i===0){r=!0;break}let a=n;n+=i;let o=e.subarray(0,n).indexOf(10,a);if(o!==-1)return e.subarray(0,o).toString(`utf-8`)}return r?e.subarray(0,n).toString(`utf-8`):null}finally{me(t)}}function rt(e){try{let t=nt(e);if(t===null)return{kind:`unreadable`};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{kind:`unreadable`};let{name:r,app_name:i,timestamp:a}=n,o=typeof r==`string`?r:typeof i==`string`?i:null;return o===null?{kind:`unreadable`}:{kind:`named`,name:o,timestampMs:tt(a)}}catch{return{kind:`unreadable`}}}function it(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function at(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=G(e,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`?{...n,outcome:`not-present`}:{...n,outcome:`unreadable-directory`,directoryErrorCode:t??`unknown`}}let i=t.getTime()-6048e5,a=[],o=0,s=0;for(let t of r){if(!t.isFile()||!t.name.endsWith(`.ips`))continue;let n=B(e,t.name),r;try{r=xe(n).mtimeMs}catch{continue}if(r<i)continue;let c=rt(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!it(c.name)){o+=1;continue}a.push({path:n,atMs:l})}a.sort((e,t)=>t.atMs-e.atMs);let c=a.slice(0,25),l={foreignIgnored:o,unparseable:s,droppedOverCap:a.length-c.length,windowDays:7};return c.length===0?{...l,files:[],outcome:`none-in-window`}:{...l,files:c.map(e=>e.path),outcome:`collected`}}function ot(){return B(q(),`.ok`,`bug-reports`)}function st(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=ot(),r=`${t}-bugreport`,i=B(n,`${r}.zip`);for(let e=2;H(i);e+=1)i=B(n,`${r}-${e}.zip`);return i}function ct(e,t){let n=B(e,`.ok`,`config.yml`);if(H(n))try{let e=W(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return H(B(e,`.ok`))?je(`sha256`).update(V(e)).digest(`hex`).slice(0,12):null}function lt(){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=ue(`sw_vers -productVersion 2>/dev/null`,f({encoding:`utf8`})).trim()}catch{}try{let t=B(__dirname,`..`,`..`,`package.json`);H(t)&&(e.okVersion=JSON.parse(W(t,`utf8`)).version)}catch{}return e}const ut=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function dt(e){let t=R(e);return ut.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function ft(e,t){return gt(e,t).files}const pt=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function mt(e,t=I){let n=B(e,`${t}.ShipIt`);if(!H(n))return[];let r;try{r=G(n)}catch{return[]}return pt.flatMap(e=>r.map(t=>{if(t===e)return{entry:t,suffix:-1};if(!t.startsWith(`${e}.`))return null;let n=t.slice(e.length+1);return/^\d+$/.test(n)?{entry:t,suffix:Number(n)}:null}).filter(e=>e!==null).sort((e,t)=>e.suffix-t.suffix).slice(0,4).map(e=>B(n,e.entry)))}function ht(e){if(!H(e))return[];try{let t=new Map;for(let n of G(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-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=>B(e,t))}catch{return[]}}function gt(e,t){if(!H(t))return{files:[],excludedByProjectSlug:0};let n=G(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>B(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(dt),i=[],a=r.filter(t=>{try{return W(t,`utf8`).includes(`"project":"${e}"`)}catch{return i.push(t),!1}});if(a.length===0)return{files:n,excludedByProjectSlug:0};let o=new Set([...a,...i]);return{files:n.filter(e=>!dt(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function _t(e){let t=B(e,`.ok`,`local`);return H(t)?{files:[`server.lock`,`last-spawn-error.log`,s].map(e=>B(t,e)).filter(e=>H(e))}:{files:[]}}function vt(e){let t=B(e,`.ok`,`local`,`logs`);return H(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>B(t,e)).filter(e=>H(e))}:{files:[]}}function yt(e){let t=0,n=new Map,r=e.replace(/("(?:docName|doc\.name|documentName)"\s*:\s*")((?:[^"\\]|\\.)*)"/g,(e,r,i)=>{t+=1;let a=n.get(i);return a===void 0&&(a=`doc#${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 bt(e){let t=e.revealDocNames?e.content:yt(e.content).text;if(e.redact){let{redacted:n,patterns:r,lineCount:i}=c(t);e.zipfile.addBuffer(Buffer.from(n,`utf8`),e.name),e.bundleFiles.push(e.name),r.length>0&&e.redactions.push({file:e.name,lineCount:i,patterns:r})}else e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name)}function J(e){for(let t of e.files)try{let n=W(t,`utf8`);bt({zipfile:e.zipfile,name:`${e.prefix}/${R(t)}`,content:t.endsWith(`.ips`)?$e(n):n,redact:e.redact,revealDocNames:e.revealDocNames,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n},`bug-report: skipped unreadable file`)}}async function xt(t){let{redact:n,outputPath:i,logger:o}=t,s=t.revealDocNames??!1,c=t.userLogsDir??B(q(),`.ok`,`logs`),l=t.projectDir?ct(t.projectDir,o):null;U(z(i),{recursive:!0}),o?.info({projectSlug:l},`gathering diagnostic data`);let u=lt();u.desktop=t.desktop??null,u.language=t.language??null;let{files:d,excludedByProjectSlug:f}=gt(l,c),{files:p}=t.projectDir?_t(t.projectDir):{files:[]},{files:m}=t.projectDir?vt(t.projectDir):{files:[]},h=t.shipItLogFiles??[],g=t.diagnosticReports?.files??[];o?.info({logFileCount:d.length,logFilesExcludedByProjectSlug:f,lockFileCount:p.length,localSinkFileCount:m.length,shipItLogFileCount:h.length,diagnosticReportCount:g.length},`files collected`);let _=[],v=[],{ZipFile:y}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),b=new y;J({zipfile:b,files:[...d,...h],prefix:`logs`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:p,prefix:`lockdir`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:m,prefix:`local-logs`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:t.bugReportLedgerFiles??[],prefix:r,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o}),J({zipfile:b,files:g,prefix:`diagnostic-reports`,redact:n,revealDocNames:s,bundleFiles:v,redactions:_,logger:o});for(let e of t.extraFiles??[])try{let t=W(e.sourcePath),n=`extra/${e.zipName??R(e.sourcePath)}`;b.addBuffer(t,n),v.push(n)}catch(t){o?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&bt({zipfile:b,name:`note.txt`,content:t.note,redact:n,revealDocNames:s,bundleFiles:v,redactions:_});let x=new Set(g.map(e=>`diagnostic-reports/${R(e)}`)),S=v.filter(e=>x.has(e)),C=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Ye(t.diagnosticReports,S.length);b.addBuffer(Buffer.from(`${C}\n`,`utf8`),`state/diagnostic-reports-status.txt`),v.push(`state/diagnostic-reports-status.txt`);let w=JSON.stringify(u,null,2);b.addBuffer(Buffer.from(w,`utf8`),`sysinfo.json`),v.push(`sysinfo.json`);let T={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:l,files:v,redactions:_,sysinfo:u};b.addBuffer(Buffer.from(JSON.stringify(T,null,2),`utf8`),`MANIFEST.json`);let E=_.reduce((e,t)=>e+t.lineCount,0),D=new Set(h.map(e=>`logs/${R(e)}`)),O=v.filter(e=>D.has(e)),k=new Set((t.bugReportLedgerFiles??[]).map(e=>`${r}/${R(e)}`)),A=v.filter(e=>k.has(e)),j=l?v.filter(e=>e.startsWith(`logs/`)&&!dt(e)&&!D.has(e)):[],M=S.length>0?[`Crash reports under diagnostic-reports/ are rewritten on the way in,`,`independently of this setting: escaped path separators are normalised`,`so the scrub above can read them, and the identifiers that link this`,`machine's bundles to each other are replaced. Nothing else is changed;`,`they are not byte-identical to the files macOS wrote.`]:[],N=M.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...M]:[`Redaction was disabled for this bundle; file contents are unmodified.`],P=[`# Bug Report Bundle`,``,`Generated: ${T.generatedAt}`,`Project: ${l??`(unscoped)`}`,`Discipline version: ${T.disciplineVersion}`,``,`## Contents`,``,...v.map(e=>`- ${e}`),``,`## Privacy`,``,...j.length>0?[`Scope: some collected logs are user-wide rather than project-scoped.`,`These are written once per machine per day and can contain activity`,`from other projects open on this machine, including captured console`,`output:`,...j.map(e=>`- ${e}`),``]:[],...O.length>0?[`Installer logs: written by the macOS update helper rather than by`,`OpenKnowledge itself, and machine-wide rather than scoped to any one`,`project. They record the install and update history of this app on`,`this machine. Only this app is collected, never other applications`,`that use the same update mechanism:`,...O.map(e=>`- ${e}`),``]:[],...S.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:`,...S.map(e=>`- ${e}`),``]:[],...A.length>0?[`Send history: a small record for each bug report previously generated`,`on this machine — when it was generated, whether sending it`,`succeeded, and why it failed if it did. This is what makes a failed`,`send diagnosable at all. It is machine-wide rather than scoped to`,`this project, so it names the other projects reports were filed`,`from. It carries no document content:`,...A.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${a.join(`, `)}`,E>0?`${E} line(s) were scrubbed across ${_.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...M,``,`This bundle is safe to attach to a GitHub issue.`]:N].join(`
2
2
  `);b.addBuffer(Buffer.from(P,`utf8`),`README.md`),b.end();let F=ge(i);return b.outputStream.pipe(F),await new Promise((e,t)=>{F.on(`close`,e),F.on(`error`,t)}),o?.info({bundlePath:i,fileCount:v.length,redactionCount:E},`bundle written`),{zipPath:i,summary:{projectSlug:l,files:v,redactions:_,redactedLineCount:E,generatedAt:T.generatedAt}}}var St=e(A(),1),Y=e(ee(),1);function Ct(e){let t=_(`user`,e,e);return h({absPath:t,sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function wt({home:e=q(),env:t=process.env}={}){let n=Ct(e),{override:r,preferenceList:i}=O(t),{locale:a,source:s}=u({override:r,storedPreference:n,supportedLocales:d,preferenceList:i,autoDetectableLocales:o});return{preference:n,locale:a,source:s,systemLanguages:i}}function Tt(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function Et(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dt(e,t){if(typeof e==`string`)return Tt(e,t.contentDir);if(Array.isArray(e))return e.map(e=>Dt(e,t));if(!Et(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=Dt(i,t);return n}function Ot(e,t){let n=W(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=Dt(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}let o=r?`${a.join(`
@@ -0,0 +1 @@
1
+ import"./md-manager-BGnqyqi1-eohu_6wW.mjs";import"./resolve-project-root-Dyi1SFSV.mjs";import"./src-9XuK4ws5.mjs";import"./acp-harness-probe-DBSW3LbG.mjs";import"./init-BBRSc_7a.mjs";import"./start-Clkz9_Ou.mjs";import{n as e}from"./loader-CcLX9hvf.mjs";import"./skill-teardown-BIi-5NQJ.mjs";import"./preview-DOqLANTC.mjs";import"./cli.mjs";import"./repair-mcp-configs-Bunrwblo.mjs";export{e as loadConfig};
@@ -1,5 +1,5 @@
1
- import{Ks as e,Xi as t,cs as n,fo as r,is as i,ut as a}from"./md-manager-BGnqyqi1-eohu_6wW.mjs";import{$r as o,Co as s,E as c,Hr as l,To as u,hi as d,ri as f}from"./dist-DYRgOemK.mjs";import{C as p,S as m,x as h}from"./resolve-project-root-Oh5l_16q.mjs";import{c as g,l as _,m as v,n as y,o as b,r as x,s as S,t as C}from"./acp-harness-probe-DDZx560B.mjs";import{y as w}from"./init-ClVQKpTb.mjs";import{n as ee}from"./constants-CsSKBE7w.mjs";import{execFileSync as T,spawn as E}from"node:child_process";import{basename as D,dirname as O,resolve as k}from"node:path";import{existsSync as A,realpathSync as j}from"node:fs";import{tmpdir as M}from"node:os";import{rm as N}from"node:fs/promises";import{setTimeout as P}from"node:timers/promises";const F=[`/opt/homebrew/bin/gh`,`/usr/local/bin/gh`,`/opt/local/bin/gh`,`/snap/bin/gh`,`/usr/bin/gh`],I={encoding:`utf-8`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3,windowsHide:!0};function L(e,t={}){let{login:n}=t,r=t._exec??T,i=R(t._fileExists??A),a=e?[`--hostname`,e]:[];if(n){let e=z(r,i,[`auth`,`token`,...a,`--user`,n]);if(e)return{available:!0,token:e,resolvedLogin:n,fallback:!1}}let o=z(r,i,[`auth`,`token`,...a]);return o?n?{available:!0,token:o,fallback:!0}:{available:!0,token:o}:{available:!1}}function R(e){return[`gh`,...F.filter(e)]}function z(e,t,n){for(let r of t)try{let t=e(r,n,I).toString().trim();if(t.length>0)return t}catch{}}function te(e,t={}){let n=t._exec??T,r=R(t._fileExists??A),i=[`auth`,`status`,...e?[`--hostname`,e]:[]],a=z(n,r,[...i,`--json`,`hosts`]);if(a!==void 0){let t=ne(a,e);if(t)return t}let o=z(n,r,i);if(o!==void 0){let e=se(o);if(e.length>0)return e}}function B(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function ne(e,t){let n;try{n=JSON.parse(e)}catch{return}let r=B(B(n)?.hosts);if(!r||t!==void 0&&r[t]===void 0)return;let i=t===void 0?Object.values(r):[r[t]],a=[];for(let e of i){if(!Array.isArray(e))return;for(let t of e){let e=B(t);if(!e)continue;let n=e.login;typeof n==`string`&&n.length!==0&&a.push({login:n,active:e.active===!0})}}return a}const re=/Logged in to \S+ account (\S+) \(/,ie=/(?:Failed to log in to|Timeout trying to log in to) \S+/,ae=/^\s*-\s*Active account:\s*true\s*$/,oe=/\u001b\[[0-9;]*m/g;function se(e){let t=[],n;for(let r of e.split(`
2
- `)){let e=r.replace(oe,``),i=re.exec(e)?.[1];if(i){n={login:i,active:!1},t.push(n);continue}if(ie.test(e)){n=void 0;continue}n&&ae.test(e)&&(n.active=!0)}return t}function ce(e,t){return e.bind?.[0]??t.HOST??`127.0.0.1`}function V(e){if(e===`server`)return e;throw new m(`--only must be 'server'`)}function H(e=A){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[k(t,`public`),k(t,`../../app/dist`),k(t,`../../../app/dist`)].find(t=>e(t))}function U(e){if(e.explicitDir!==void 0)return{dir:e.explicitDir,missingBundle:!1};if(e.only===`server`)return{dir:void 0,missingBundle:!1};let t=e.findBundledDir();return{dir:t,missingBundle:t===void 0}}function W(t){if(t===`off`)return`off`;if(!e.test(t))throw new m(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return t}function G(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function K(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function q(e){return!e.openBrowser||e.ephemeral||e.only===`server`||!e.servesUi?!1:(e.explicitOn||G(e.host))&&e.isTTY}function le(e,t){let n;try{n=new URL(t)}catch{throw new m(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new m(`${e} must be an http(s) origin (got: ${t})`);return t}function J(e){return le(`--external-url`,e)}function Y(e){let t=D(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var X=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}},Z=class extends Error{projectDir;constructor(e){super(`--project-dir must be a throwaway ${c}* directory under the OS temp dir. Refusing to write ephemeral session state into ${e}. Omit --project-dir to let ok start create (and clean up) its own.`),this.name=`EphemeralProjectDirNotThrowawayError`,this.projectDir=e}};function Q(e,t={}){let n=t.tmpdirFn??M,r=t.realpathFn??j,i=e=>{try{return r(e)}catch(t){return t.code===`ENOENT`?k(e):null}},a=k(e),o;try{o=r(a)}catch(e){if(e.code===`ENOENT`){let e=i(O(a));o=e===null?null:k(e,D(a))}else o=null}if(o===null)return!1;let s=i(n());return s!==null&&O(o)===s&&D(o).startsWith(`ok-ephemeral-`)}function ue(e,t,n=e=>N(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{if(Q(t))try{await n(t)}catch(e){process.stderr.write(`[start] ephemeral temp dir reap failed for ${t}: ${e instanceof Error?e.message:String(e)}\n`)}else process.stderr.write(`[start] leaving ${t} in place: only ${c}* dirs under the OS temp dir are removed on ephemeral teardown\n`)}}}function de(e,t={}){let n=t.exit??(e=>process.exit(e)),r=t.getActiveHandles??(()=>{let e=process._getActiveHandles;return e?e.call(process):null});return async()=>{let i=!1;try{await e()}catch(e){i=!0,t.log?.error({err:e},`idle-shutdown: destroy failed — exiting anyway`)}finally{let e=null;try{let t=r();if(t!==null){e={};for(let n of t){let t=n?.constructor?.name??`unknown`;e[t]=(e[t]??0)+1}}}catch{e=null}t.log?.info({event:`idle-shutdown-exit`,exitCode:+!!i,openHandles:e??{},handlesAvailable:e!==null},`idle-shutdown: teardown finished — exiting process`),n(+!!i)}}}async function $(e){let{config:t,cwd:n,host:r}=e,i=e.skipAutoInit??!1,a=e.idleThresholdMs===void 0?18e5:e.idleThresholdMs,{existsSync:o,mkdirSync:s}=await import(`node:fs`),{basename:c,dirname:u,resolve:p}=await import(`node:path`),{bootServer:m,createEphemeralProjectDir:h,getLogger:g,resolveContentDir:_,resolveLockDir:b,seedEphemeralProjectDir:S,waitForServerLockDrain:ee}=await import(`./dist-Db-P3aGR.mjs`),T=e.log??g(`start`),E=e.singleFile!==void 0,D=E?d(e.singleFile).canonicalFilePath:void 0,O=D?u(D):void 0,k=D?c(D):void 0,A,j=!1;if(O!==void 0){if(e.projectDir!==void 0){if(A=e.projectDir,!Q(A))throw new Z(A);o(p(A,`.ok`,`config.yml`))||S(A,O)}else A=h(O),j=!0}let M=async()=>{if(!(!j||A===void 0)){if(!Q(A)){T.warn({ephemeralProjectDir:A},`[start] refusing to reap self-provisioned ephemeral dir: no longer resolves to an ok-ephemeral-* temp dir`);return}try{await N(A,{recursive:!0,force:!0})}catch(e){T.warn({err:e,ephemeralProjectDir:A},`[start] failed to reap self-provisioned ephemeral temp dir`)}}},P=A;if(!E){if(!i&&!l(n))throw new X(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&T.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-Ul1vx1q9.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){T.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-D3WpmymA.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){T.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-BdPGQfHw.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){T.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let F=O??_(t,n);!E&&!o(F)&&(s(F,{recursive:!0}),T.info({contentDir:F},`Created content directory`));let I=v(),R=f(),z;try{{let e=b(A??n),t=Date.now(),r=await ee(e);r!==`no-drain`&&T.info({event:`start-waited-for-draining-predecessor`,outcome:r,waitedMs:Date.now()-t,drainLockDir:e},r===`released`?`[start] predecessor server finished draining — proceeding`:`[start] predecessor server still draining after wait — proceeding to collide`)}z=await m({config:t,contentDir:F,projectDir:A??n,contentRoot:E?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:L,detectGhAccounts:te,tokenStore:I,embeddingsKeyStore:R,mcpTomlEditor:w(),...E?{ephemeral:!0,singleDocRelPath:k,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>C(e,t),probePiAcpBridge:e=>x(e),ensurePiAcpBridge:e=>y(e),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return de(P===void 0?n:ue(n,P),{log:T,exit:e.idleExit})},log:T,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}})}catch(e){throw await M(),e}let B=z.destroy,ne=j?async()=>{try{await B()}finally{await M()}}:B;return{httpServer:z.httpServer,destroy:ne,lockDir:z.lockDir,contentDir:F,port:z.port,ready:z.ready,degraded:z.degraded}}function fe(e,t,n=()=>s({absPath:u(`user`,process.cwd()),sideline:!1,warn:()=>{}}).value){return t===void 0?e:n()}function pe(e){if(e===`browser`||e===`app`)return e;throw new m(`--mode must be 'browser' or 'app'`)}function me(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function he(e){let t=[`Stopping OpenKnowledge…`,`Saving pending changes and releasing the server lock — this can take a few seconds.`];return e===`SIGINT`&&t.push(`Press Ctrl+C again to force quit.`),t}async function ge(e,o){let s=fe(e,o.singleFile),c=me(process.env);c!==null&&(process.env.OK_CONSOLE_LEVEL=c);let{renderBanner:l}=await import(`./banner-kywHhVaC.mjs`),{accent:u,dim:d,error:f,warning:p}=await import(`./colors-SgU3JHQu.mjs`),m=process.cwd();process.title=Y(m);let h;try{h=i(process.env)}catch(e){throw e instanceof a&&(console.error(f(e.message)),process.exit(78)),e}for(let e of h.diagnostics)console.warn(p(`[config] ${e.message}`));let g=t(s,h.layer),_=h.overrides.some(e=>e.envVar===`OK_BIND`),v=o.bind!==void 0&&o.bind.length>0?o.bind:void 0,y=process.env.HOST,b=y!==void 0&&y.trim()!==``?y:void 0,x=n(g),S=v??(_||b===void 0?[...x.bind]:[b]);K({flagBindSet:v!==void 0,okBindSet:_,hostEnvSet:b!==void 0,fileBindCount:x.bind.length})&&console.warn(p(`[config] HOST=${b} overrides server.bind — dropping the file-configured addresses (${x.bind.join(`, `)}). Use OK_BIND with a space-separated list to keep multiple binds.`));let C=S[0]??`127.0.0.1`,w=S,T=o.externalUrl,E=n(t(g,{server:{bind:w,...T===void 0?{}:{externalUrl:T}}}));if(E.allowExternal&&(!E.loopbackOnly||E.externalUrl)){let e=E.externalUrl??E.bind.join(`, `);console.warn(p([``,`⚠ EXTERNAL ACCESS ENABLED (server.allowExternal) — no server-side authentication.`,` This server is reachable beyond this machine (${e}). Anyone who can`,` reach it has FULL control of this knowledge base — sync, publishing, GitHub`,` credentials, and local operations (clone, sign-in, repo spawn).`,` Restrict who can reach it at the edge: a Tailscale ACL, a reverse proxy with`,` auth (Cloudflare Access, oauth2-proxy), or a firewall.`,``].join(`
3
- `)))}let D=o.port===void 0?void 0:Number(o.port),O=h.overrides.find(e=>e.envVar===`PORT`)?.value,k=D??O??s.server?.port,A=U({explicitDir:o.reactShellDistDir,only:o.only,findBundledDir:H}),j=A.dir;A.missingBundle&&console.warn(`bundled web UI not found — serving /api and /mcp only. Reinstall @inkeep/open-knowledge, or build packages/app in a source checkout.`);let M;try{M=await $({config:s,cwd:m,host:C,port:k,bind:w,...o.serveContentAssets===void 0?{}:{serveContentAssets:o.serveContentAssets},...j?{reactShellDistDir:j}:{},idleThresholdMs:r(o.idleShutdown??E.idleShutdown),serverRuntime:E,...o.singleFile?{singleFile:o.singleFile}:{},...o.projectDir?{projectDir:o.projectDir}:{}})}catch(e){e instanceof X&&(console.error(f(e.message)),process.exit(1)),e instanceof Z&&(console.error(f(e.message)),process.exit(1));let t=await import(`./dist-Db-P3aGR.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),e instanceof t.ExposureConsentError&&(console.error(f(e.message)),process.exit(78)),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(f(e.message)),process.exit(1)),e instanceof t.MissingOkConfigError&&(console.error(f(e.message)),process.exit(1)),ye(e,t)){let e=t.resolveLockDir(m),n=null;try{n=await _e({readServerLock:()=>t.readServerLock(e),now:Date.now,sleep:e=>P(e),timeoutMs:3e3,pollIntervalMs:50})}catch(e){process.stderr.write(`[start] spawn-or-reuse: lock poll failed (${e instanceof Error?e.message:String(e)}) — falling back to the collision message\n`)}if(n!==null){let[e,...t]=ve(n);console.log(u(e));for(let e of t)console.log(d(e));process.exit(0)}}let n=be(e,m,t);n!==null&&(console.error(f(n)),process.exit(1)),console.error(`${f(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let N=!1,F=async e=>{if(N)return;N=!0;let[t,...n]=he(e);console.log(u(`\n${t}`));for(let e of n)console.log(d(` ${e}`));try{await M.destroy(`external-signal`)}catch(e){console.error(`${f(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{F(`SIGINT`)}),process.once(`SIGTERM`,()=>{F(`SIGTERM`)});let I=`http://${C.includes(`:`)&&!C.startsWith(`[`)?`[${C}]`:C}:${M.port}`,L=C===`0.0.0.0`||C===`::`?`http://0.0.0.0:${M.port}`:void 0,R=I;console.log(l({name:`open-knowledge`,version:ee,localUrl:R,networkUrl:L,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let z={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};M.ready.then(async()=>{if(M.degraded.length>0){console.log();for(let e of M.degraded){let t=z[e]??`${e} (check server logs for details)`;console.warn(` ${p(`⚠`)} ${p(e)}: ${d(t)}`)}console.log()}if(q({openBrowser:o.openBrowser!==!1&&E.openBrowser,explicitOn:o.openBrowser!==!1&&g.server?.openBrowser===!0,host:C,isTTY:process.stdout.isTTY===!0,ephemeral:o.singleFile!==void 0,only:o.only,servesUi:j!==void 0})){let{openBrowser:e}=await import(`./open-browser-D7BRsUDm.mjs`);e(R)}}).catch(e=>{console.error(` ${f(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}async function _e(e){let t=e.now()+e.timeoutMs,n=e.readServerLock();for(;n!==null&&n.draining!==!0&&n.port<=0&&e.now()<t;)await e.sleep(e.pollIntervalMs),n=e.readServerLock();return n===null||n.draining===!0||n.port<=0?null:o(n)&&n.url!==void 0?{url:n.url,kind:n.kind,pid:n.pid,servesUi:!0}:{url:n.url??`http://127.0.0.1:${n.port}`,kind:n.kind,pid:n.pid,servesUi:!1}}function ve(e){return[`${e.kind===`mcp-spawned`?`An MCP-spawned OpenKnowledge server is already running on this project`:`OpenKnowledge is already running on this project`} (pid ${e.pid}).`,` ${e.url}`,"Leaving it running — run `ok stop` first if you want a fresh server."]}function ye(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function be(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=n.readServerLock(n.resolveLockDir(t));return e&&e.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function xe(e){return new h(`start`).description(`Start the OpenKnowledge server (UI + API + MCP + collab on one port)`).option(`-p, --port <port>`,`Server port`,void 0).option(`--bind <address>`,`Bind address (repeatable; default 127.0.0.1 — loopback only)`,(e,t)=>[...t??[],e]).option(`--no-open-browser`,`Do not open the browser after start (interactive loopback starts open it by default)`).option(`--only <module>`,`Serve one module: 'server' (API + MCP only, no shell or browser)`,V).option(`--idle-shutdown <duration>`,`Shut the server down after this long with no connected clients ('off', or a duration like 90s, 30m, 2h; default 30m)`,W).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,pe).option(`--serve-content-assets`,`Serve content assets from this server (now the default; kept for compatibility)`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path>`).addOption(new p(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).hideHelp()).addOption(new p(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).hideHelp()).option(`--external-url <url>`,`Canonical external origin clients dial (sets server.externalUrl for this run) — its host joins the Host/Origin allowlists (CORS + external-Host admission). External exposure additionally requires consent (OK_ALLOW_EXTERNAL=1 or server.allowExternal).`,J).action(async t=>{let n=e();if(t.only===`server`&&t.reactShellDistDir!==void 0&&(process.stderr.write(`error: option '--only server' cannot be combined with '--react-shell-dist-dir'
1
+ import{Ks as e,Xi as t,cs as n,fo as r,is as i,ut as a}from"./md-manager-BGnqyqi1-eohu_6wW.mjs";import{$r as o,Co as s,E as c,Hr as l,To as u,hi as d,ri as f}from"./dist-rXSsjKu4.mjs";import{C as p,S as m,x as h}from"./resolve-project-root-Dyi1SFSV.mjs";import{c as g,l as _,m as v,n as y,o as b,r as x,s as S,t as C}from"./acp-harness-probe-DBSW3LbG.mjs";import{y as w}from"./init-BBRSc_7a.mjs";import{n as ee}from"./constants-CDluLUFq.mjs";import{execFileSync as T,spawn as E}from"node:child_process";import{basename as D,dirname as O,resolve as k}from"node:path";import{existsSync as A,realpathSync as j}from"node:fs";import{tmpdir as M}from"node:os";import{rm as N}from"node:fs/promises";import{setTimeout as P}from"node:timers/promises";const F=[`/opt/homebrew/bin/gh`,`/usr/local/bin/gh`,`/opt/local/bin/gh`,`/snap/bin/gh`,`/usr/bin/gh`],I={encoding:`utf-8`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3,windowsHide:!0};function L(e,t={}){let{login:n}=t,r=t._exec??T,i=R(t._fileExists??A),a=e?[`--hostname`,e]:[];if(n){let e=z(r,i,[`auth`,`token`,...a,`--user`,n]);if(e)return{available:!0,token:e,resolvedLogin:n,fallback:!1}}let o=z(r,i,[`auth`,`token`,...a]);return o?n?{available:!0,token:o,fallback:!0}:{available:!0,token:o}:{available:!1}}function R(e){return[`gh`,...F.filter(e)]}function z(e,t,n){for(let r of t)try{let t=e(r,n,I).toString().trim();if(t.length>0)return t}catch{}}function te(e,t={}){let n=t._exec??T,r=R(t._fileExists??A),i=[`auth`,`status`,...e?[`--hostname`,e]:[]],a=z(n,r,[...i,`--json`,`hosts`]);if(a!==void 0){let t=ne(a,e);if(t)return t}let o=z(n,r,i);if(o!==void 0){let e=se(o);if(e.length>0)return e}}function B(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function ne(e,t){let n;try{n=JSON.parse(e)}catch{return}let r=B(B(n)?.hosts);if(!r||t!==void 0&&r[t]===void 0)return;let i=t===void 0?Object.values(r):[r[t]],a=[];for(let e of i){if(!Array.isArray(e))return;for(let t of e){let e=B(t);if(!e)continue;let n=e.login;typeof n==`string`&&n.length!==0&&a.push({login:n,active:e.active===!0})}}return a}const re=/Logged in to \S+ account (\S+) \(/,ie=/(?:Failed to log in to|Timeout trying to log in to) \S+/,ae=/^\s*-\s*Active account:\s*true\s*$/,oe=/\u001b\[[0-9;]*m/g;function se(e){let t=[],n;for(let r of e.split(`
2
+ `)){let e=r.replace(oe,``),i=re.exec(e)?.[1];if(i){n={login:i,active:!1},t.push(n);continue}if(ie.test(e)){n=void 0;continue}n&&ae.test(e)&&(n.active=!0)}return t}function ce(e,t){return e.bind?.[0]??t.HOST??`127.0.0.1`}function V(e){if(e===`server`)return e;throw new m(`--only must be 'server'`)}function H(e=A){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[k(t,`public`),k(t,`../../app/dist`),k(t,`../../../app/dist`)].find(t=>e(t))}function U(e){if(e.explicitDir!==void 0)return{dir:e.explicitDir,missingBundle:!1};if(e.only===`server`)return{dir:void 0,missingBundle:!1};let t=e.findBundledDir();return{dir:t,missingBundle:t===void 0}}function W(t){if(t===`off`)return`off`;if(!e.test(t))throw new m(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return t}function G(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function K(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function q(e){return!e.openBrowser||e.ephemeral||e.only===`server`||!e.servesUi?!1:(e.explicitOn||G(e.host))&&e.isTTY}function le(e,t){let n;try{n=new URL(t)}catch{throw new m(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new m(`${e} must be an http(s) origin (got: ${t})`);return t}function J(e){return le(`--external-url`,e)}function Y(e){let t=D(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var X=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}},Z=class extends Error{projectDir;constructor(e){super(`--project-dir must be a throwaway ${c}* directory under the OS temp dir. Refusing to write ephemeral session state into ${e}. Omit --project-dir to let ok start create (and clean up) its own.`),this.name=`EphemeralProjectDirNotThrowawayError`,this.projectDir=e}};function Q(e,t={}){let n=t.tmpdirFn??M,r=t.realpathFn??j,i=e=>{try{return r(e)}catch(t){return t.code===`ENOENT`?k(e):null}},a=k(e),o;try{o=r(a)}catch(e){if(e.code===`ENOENT`){let e=i(O(a));o=e===null?null:k(e,D(a))}else o=null}if(o===null)return!1;let s=i(n());return s!==null&&O(o)===s&&D(o).startsWith(`ok-ephemeral-`)}function ue(e,t,n=e=>N(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{if(Q(t))try{await n(t)}catch(e){process.stderr.write(`[start] ephemeral temp dir reap failed for ${t}: ${e instanceof Error?e.message:String(e)}\n`)}else process.stderr.write(`[start] leaving ${t} in place: only ${c}* dirs under the OS temp dir are removed on ephemeral teardown\n`)}}}function de(e,t={}){let n=t.exit??(e=>process.exit(e)),r=t.getActiveHandles??(()=>{let e=process._getActiveHandles;return e?e.call(process):null});return async()=>{let i=!1;try{await e()}catch(e){i=!0,t.log?.error({err:e},`idle-shutdown: destroy failed — exiting anyway`)}finally{let e=null;try{let t=r();if(t!==null){e={};for(let n of t){let t=n?.constructor?.name??`unknown`;e[t]=(e[t]??0)+1}}}catch{e=null}t.log?.info({event:`idle-shutdown-exit`,exitCode:+!!i,openHandles:e??{},handlesAvailable:e!==null},`idle-shutdown: teardown finished — exiting process`),n(+!!i)}}}async function $(e){let{config:t,cwd:n,host:r}=e,i=e.skipAutoInit??!1,a=e.idleThresholdMs===void 0?18e5:e.idleThresholdMs,{existsSync:o,mkdirSync:s}=await import(`node:fs`),{basename:c,dirname:u,resolve:p}=await import(`node:path`),{bootServer:m,createEphemeralProjectDir:h,getLogger:g,resolveContentDir:_,resolveLockDir:b,seedEphemeralProjectDir:S,waitForServerLockDrain:ee}=await import(`./dist-D-X0Yg3B.mjs`),T=e.log??g(`start`),E=e.singleFile!==void 0,D=E?d(e.singleFile).canonicalFilePath:void 0,O=D?u(D):void 0,k=D?c(D):void 0,A,j=!1;if(O!==void 0){if(e.projectDir!==void 0){if(A=e.projectDir,!Q(A))throw new Z(A);o(p(A,`.ok`,`config.yml`))||S(A,O)}else A=h(O),j=!0}let M=async()=>{if(!(!j||A===void 0)){if(!Q(A)){T.warn({ephemeralProjectDir:A},`[start] refusing to reap self-provisioned ephemeral dir: no longer resolves to an ok-ephemeral-* temp dir`);return}try{await N(A,{recursive:!0,force:!0})}catch(e){T.warn({err:e,ephemeralProjectDir:A},`[start] failed to reap self-provisioned ephemeral temp dir`)}}},P=A;if(!E){if(!i&&!l(n))throw new X(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&T.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-Bunrwblo.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){T.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-DWOikU7H.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){T.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-5EO0Uwch.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){T.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let F=O??_(t,n);!E&&!o(F)&&(s(F,{recursive:!0}),T.info({contentDir:F},`Created content directory`));let I=v(),R=f(),z;try{{let e=b(A??n),t=Date.now(),r=await ee(e);r!==`no-drain`&&T.info({event:`start-waited-for-draining-predecessor`,outcome:r,waitedMs:Date.now()-t,drainLockDir:e},r===`released`?`[start] predecessor server finished draining — proceeding`:`[start] predecessor server still draining after wait — proceeding to collide`)}z=await m({config:t,contentDir:F,projectDir:A??n,contentRoot:E?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:L,detectGhAccounts:te,tokenStore:I,embeddingsKeyStore:R,mcpTomlEditor:w(),...E?{ephemeral:!0,singleDocRelPath:k,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>C(e,t),probePiAcpBridge:e=>x(e),ensurePiAcpBridge:e=>y(e),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return de(P===void 0?n:ue(n,P),{log:T,exit:e.idleExit})},log:T,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}})}catch(e){throw await M(),e}let B=z.destroy,ne=j?async()=>{try{await B()}finally{await M()}}:B;return{httpServer:z.httpServer,destroy:ne,lockDir:z.lockDir,contentDir:F,port:z.port,ready:z.ready,degraded:z.degraded}}function fe(e,t,n=()=>s({absPath:u(`user`,process.cwd()),sideline:!1,warn:()=>{}}).value){return t===void 0?e:n()}function pe(e){if(e===`browser`||e===`app`)return e;throw new m(`--mode must be 'browser' or 'app'`)}function me(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function he(e){let t=[`Stopping OpenKnowledge…`,`Saving pending changes and releasing the server lock — this can take a few seconds.`];return e===`SIGINT`&&t.push(`Press Ctrl+C again to force quit.`),t}async function ge(e,o){let s=fe(e,o.singleFile),c=me(process.env);c!==null&&(process.env.OK_CONSOLE_LEVEL=c);let{renderBanner:l}=await import(`./banner-kywHhVaC.mjs`),{accent:u,dim:d,error:f,warning:p}=await import(`./colors-SgU3JHQu.mjs`),m=process.cwd();process.title=Y(m);let h;try{h=i(process.env)}catch(e){throw e instanceof a&&(console.error(f(e.message)),process.exit(78)),e}for(let e of h.diagnostics)console.warn(p(`[config] ${e.message}`));let g=t(s,h.layer),_=h.overrides.some(e=>e.envVar===`OK_BIND`),v=o.bind!==void 0&&o.bind.length>0?o.bind:void 0,y=process.env.HOST,b=y!==void 0&&y.trim()!==``?y:void 0,x=n(g),S=v??(_||b===void 0?[...x.bind]:[b]);K({flagBindSet:v!==void 0,okBindSet:_,hostEnvSet:b!==void 0,fileBindCount:x.bind.length})&&console.warn(p(`[config] HOST=${b} overrides server.bind — dropping the file-configured addresses (${x.bind.join(`, `)}). Use OK_BIND with a space-separated list to keep multiple binds.`));let C=S[0]??`127.0.0.1`,w=S,T=o.externalUrl,E=n(t(g,{server:{bind:w,...T===void 0?{}:{externalUrl:T}}}));if(E.allowExternal&&(!E.loopbackOnly||E.externalUrl)){let e=E.externalUrl??E.bind.join(`, `);console.warn(p([``,`⚠ EXTERNAL ACCESS ENABLED (server.allowExternal) — no server-side authentication.`,` This server is reachable beyond this machine (${e}). Anyone who can`,` reach it has FULL control of this knowledge base — sync, publishing, GitHub`,` credentials, and local operations (clone, sign-in, repo spawn).`,` Restrict who can reach it at the edge: a Tailscale ACL, a reverse proxy with`,` auth (Cloudflare Access, oauth2-proxy), or a firewall.`,``].join(`
3
+ `)))}let D=o.port===void 0?void 0:Number(o.port),O=h.overrides.find(e=>e.envVar===`PORT`)?.value,k=D??O??s.server?.port,A=U({explicitDir:o.reactShellDistDir,only:o.only,findBundledDir:H}),j=A.dir;A.missingBundle&&console.warn(`bundled web UI not found — serving /api and /mcp only. Reinstall @inkeep/open-knowledge, or build packages/app in a source checkout.`);let M;try{M=await $({config:s,cwd:m,host:C,port:k,bind:w,...o.serveContentAssets===void 0?{}:{serveContentAssets:o.serveContentAssets},...j?{reactShellDistDir:j}:{},idleThresholdMs:r(o.idleShutdown??E.idleShutdown),serverRuntime:E,...o.singleFile?{singleFile:o.singleFile}:{},...o.projectDir?{projectDir:o.projectDir}:{}})}catch(e){e instanceof X&&(console.error(f(e.message)),process.exit(1)),e instanceof Z&&(console.error(f(e.message)),process.exit(1));let t=await import(`./dist-D-X0Yg3B.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),e instanceof t.ExposureConsentError&&(console.error(f(e.message)),process.exit(78)),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(f(e.message)),process.exit(1)),e instanceof t.MissingOkConfigError&&(console.error(f(e.message)),process.exit(1)),ye(e,t)){let e=t.resolveLockDir(m),n=null;try{n=await _e({readServerLock:()=>t.readServerLock(e),now:Date.now,sleep:e=>P(e),timeoutMs:3e3,pollIntervalMs:50})}catch(e){process.stderr.write(`[start] spawn-or-reuse: lock poll failed (${e instanceof Error?e.message:String(e)}) — falling back to the collision message\n`)}if(n!==null){let[e,...t]=ve(n);console.log(u(e));for(let e of t)console.log(d(e));process.exit(0)}}let n=be(e,m,t);n!==null&&(console.error(f(n)),process.exit(1)),console.error(`${f(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let N=!1,F=async e=>{if(N)return;N=!0;let[t,...n]=he(e);console.log(u(`\n${t}`));for(let e of n)console.log(d(` ${e}`));try{await M.destroy(`external-signal`)}catch(e){console.error(`${f(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{F(`SIGINT`)}),process.once(`SIGTERM`,()=>{F(`SIGTERM`)});let I=`http://${C.includes(`:`)&&!C.startsWith(`[`)?`[${C}]`:C}:${M.port}`,L=C===`0.0.0.0`||C===`::`?`http://0.0.0.0:${M.port}`:void 0,R=I;console.log(l({name:`open-knowledge`,version:ee,localUrl:R,networkUrl:L,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let z={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};M.ready.then(async()=>{if(M.degraded.length>0){console.log();for(let e of M.degraded){let t=z[e]??`${e} (check server logs for details)`;console.warn(` ${p(`⚠`)} ${p(e)}: ${d(t)}`)}console.log()}if(q({openBrowser:o.openBrowser!==!1&&E.openBrowser,explicitOn:o.openBrowser!==!1&&g.server?.openBrowser===!0,host:C,isTTY:process.stdout.isTTY===!0,ephemeral:o.singleFile!==void 0,only:o.only,servesUi:j!==void 0})){let{openBrowser:e}=await import(`./open-browser-DTJSqTQH.mjs`);e(R)}}).catch(e=>{console.error(` ${f(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}async function _e(e){let t=e.now()+e.timeoutMs,n=e.readServerLock();for(;n!==null&&n.draining!==!0&&n.port<=0&&e.now()<t;)await e.sleep(e.pollIntervalMs),n=e.readServerLock();return n===null||n.draining===!0||n.port<=0?null:o(n)&&n.url!==void 0?{url:n.url,kind:n.kind,pid:n.pid,servesUi:!0}:{url:n.url??`http://127.0.0.1:${n.port}`,kind:n.kind,pid:n.pid,servesUi:!1}}function ve(e){return[`${e.kind===`mcp-spawned`?`An MCP-spawned OpenKnowledge server is already running on this project`:`OpenKnowledge is already running on this project`} (pid ${e.pid}).`,` ${e.url}`,"Leaving it running — run `ok stop` first if you want a fresh server."]}function ye(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function be(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=n.readServerLock(n.resolveLockDir(t));return e&&e.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function xe(e){return new h(`start`).description(`Start the OpenKnowledge server (UI + API + MCP + collab on one port)`).option(`-p, --port <port>`,`Server port`,void 0).option(`--bind <address>`,`Bind address (repeatable; default 127.0.0.1 — loopback only)`,(e,t)=>[...t??[],e]).option(`--no-open-browser`,`Do not open the browser after start (interactive loopback starts open it by default)`).option(`--only <module>`,`Serve one module: 'server' (API + MCP only, no shell or browser)`,V).option(`--idle-shutdown <duration>`,`Shut the server down after this long with no connected clients ('off', or a duration like 90s, 30m, 2h; default 30m)`,W).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,pe).option(`--serve-content-assets`,`Serve content assets from this server (now the default; kept for compatibility)`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path>`).addOption(new p(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).hideHelp()).addOption(new p(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).hideHelp()).option(`--external-url <url>`,`Canonical external origin clients dial (sets server.externalUrl for this run) — its host joins the Host/Origin allowlists (CORS + external-Host admission). External exposure additionally requires consent (OK_ALLOW_EXTERNAL=1 or server.allowExternal).`,J).action(async t=>{let n=e();if(t.only===`server`&&t.reactShellDistDir!==void 0&&(process.stderr.write(`error: option '--only server' cannot be combined with '--react-shell-dist-dir'
4
4
  `),process.exit(2)),t.projectDir!==void 0&&t.singleFile===void 0&&(process.stderr.write(`error: option '--project-dir' requires '--single-file'
5
5
  `),process.exit(2)),t.mode===`app`){let e=[];if(t.port!==void 0&&e.push(`--port`),t.bind!==void 0&&e.push(`--bind`),t.only!==void 0&&e.push(`--only`),t.idleShutdown!==void 0&&e.push(`--idle-shutdown`),t.openBrowser===!1&&e.push(`--no-open-browser`),t.externalUrl!==void 0&&e.push(`--external-url`),e.length>0){let t=process.env.OK_LOG_LEVEL??`info`;(t===`debug`||t===`trace`)&&console.error(`--mode=app: ignoring ${e.join(`, `)}`)}let n=S(b());if(n.available){g({spawn:E},n);return}console.error(_(n.reason)),process.exit(1)}await ge(n,t)})}export{be as C,te as D,L as E,xe as S,de as T,me as _,ve as a,q as b,Q as c,W as d,V as f,fe as g,_e as h,Y as i,ye as l,ce as m,X as n,he as o,H as p,$ as r,G as s,Z as t,J as u,U as v,ue as w,K as x,ge as y};
@@ -0,0 +1 @@
1
+ import{S as e,m as t,p as n,r}from"./start-Clkz9_Ou.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/open-knowledge",
3
- "version": "0.69.0",
3
+ "version": "0.69.1",
4
4
  "description": "Local-first, agent-friendly Markdown knowledge base with a cross-platform CLI and web editor",
5
5
  "keywords": [
6
6
  "knowledge-base",
@@ -70,10 +70,10 @@
70
70
  "ajv-formats": "^3.0.1",
71
71
  "tsdown": "^0.22.14",
72
72
  "typescript": "~7.0.2",
73
- "@inkeep/open-knowledge-core": "0.69.0",
73
+ "@inkeep/open-knowledge-app": "0.69.1",
74
74
  "@inkeep/open-knowledge-native-config": "0.0.0",
75
- "@inkeep/open-knowledge-app": "0.69.0",
76
- "@inkeep/open-knowledge-server": "0.69.0"
75
+ "@inkeep/open-knowledge-core": "0.69.1",
76
+ "@inkeep/open-knowledge-server": "0.69.1"
77
77
  },
78
78
  "scripts": {
79
79
  "build:cli": "rm -rf dist && tsdown",
@@ -1 +0,0 @@
1
- import"./md-manager-BGnqyqi1-eohu_6wW.mjs";var e=`0.69.0`;const t=`config.yml`,n=e;export{n,t};
@@ -1 +0,0 @@
1
- import"./dist-DYRgOemK.mjs";import{g as e}from"./init-ClVQKpTb.mjs";export{e as runInit};
@@ -1 +0,0 @@
1
- import{n as e}from"./loader-B2BRl64M.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{n as e,t}from"./preview-DG6Du8Cq.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1 +0,0 @@
1
- import{t as e}from"./index-B0HI1pzX.js";export{e as FeedbackForm};
@@ -1 +0,0 @@
1
- import{t as e}from"./ManagedArtifactProperties-BITPt-_L.js";export{e as ManagedArtifactProperties};
@@ -1 +0,0 @@
1
- import{t as e}from"./repair-skills-Cphq1SzP.mjs";export{e as repairSkills};
@@ -1 +0,0 @@
1
- import"./md-manager-BGnqyqi1-eohu_6wW.mjs";import"./resolve-project-root-Oh5l_16q.mjs";import"./src-P5JlIxeB.mjs";import"./acp-harness-probe-DDZx560B.mjs";import"./init-ClVQKpTb.mjs";import"./start-D3QRXVYB.mjs";import{n as e}from"./loader-B2BRl64M.mjs";import"./skill-teardown-CJwWL618.mjs";import"./preview-DG6Du8Cq.mjs";import"./cli.mjs";import"./repair-mcp-configs-Ul1vx1q9.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{S as e,m as t,p as n,r}from"./start-D3QRXVYB.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};