@inkeep/open-knowledge 0.77.2-beta.7 → 0.77.2

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 (107) hide show
  1. package/dist/cli.mjs +69 -69
  2. package/dist/constants-BSyYdAQG.mjs +1 -0
  3. package/dist/dist-Bm7UNIQ7.mjs +1 -0
  4. package/dist/dist-C9m6GTCy.mjs +2103 -0
  5. package/dist/index.mjs +54 -54
  6. package/dist/{init-DaLmOoJr.mjs → init-Bmgfz2Uz.mjs} +53 -53
  7. package/dist/init-w94YG4lH.mjs +1 -0
  8. package/dist/{launch-json-removal-B5uyrxYw.mjs → launch-json-removal-DdSeGXO-.mjs} +1 -1
  9. package/dist/{loader-MbeLji7K.mjs → loader-DUfk5TBF.mjs} +1 -1
  10. package/dist/loader-ZDMLWaoJ.mjs +1 -0
  11. package/dist/{open-browser-wd9wHZQk.mjs → open-browser-OpHQJzqy.mjs} +1 -1
  12. package/dist/{preview-DLw39xAD.mjs → preview-Bavx4mIc.mjs} +1 -1
  13. package/dist/preview-DrGrRGwj.mjs +1 -0
  14. package/dist/public/assets/{ActivityModeContent-BI7UiveH.js → ActivityModeContent-Vl6pwifD.js} +1 -1
  15. package/dist/public/assets/{AddPropertiesButton-CofY4w8v.js → AddPropertiesButton-Dkcg9vdy.js} +1 -1
  16. package/dist/public/assets/{AgentDiffPane-BWxStMhc.js → AgentDiffPane-Dzxa315q.js} +1 -1
  17. package/dist/public/assets/{CodeMirrorPropInput-C4usP1JL.js → CodeMirrorPropInput-DVe4wD_N.js} +1 -1
  18. package/dist/public/assets/{DocumentContext-DUQYQdyb.js → DocumentContext-CNNn86SD.js} +20 -20
  19. package/dist/public/assets/{EditorModeToggle-psQ4IO7b.js → EditorModeToggle-B_ngg6b-.js} +1 -1
  20. package/dist/public/assets/{EnableSyncConfirmDialog-BY2SsAct.js → EnableSyncConfirmDialog-JheZk6DM.js} +1 -1
  21. package/dist/public/assets/{ExcalidrawDocEditor-wBso9bSL.js → ExcalidrawDocEditor-DbYGp5_p.js} +1 -1
  22. package/dist/public/assets/FeedbackForm-WmvAxHkb.js +1 -0
  23. package/dist/public/assets/{ImportSkillDialog-DSy0mmFL.js → ImportSkillDialog-D5szggRQ.js} +1 -1
  24. package/dist/public/assets/{LintConfigEditor-B1H2FJsK.js → LintConfigEditor-B0KT3R1_.js} +1 -1
  25. package/dist/public/assets/ManagedArtifactProperties-CQf6baFP.js +1 -0
  26. package/dist/public/assets/{ManagedArtifactProperties-CyRqUrc7.js → ManagedArtifactProperties-DlORA12f.js} +1 -1
  27. package/dist/public/assets/{MermaidDocEditor-B4wqh_V5.js → MermaidDocEditor-Cq1CyzOk.js} +1 -1
  28. package/dist/public/assets/{PropertyDisplayRow-DyfQG8O6.js → PropertyDisplayRow-BsydKIFK.js} +1 -1
  29. package/dist/public/assets/{SchemaConfigEditor-BgQPfEUL.js → SchemaConfigEditor-37WJ51GR.js} +1 -1
  30. package/dist/public/assets/{SessionsHost-CCKzOI4X.js → SessionsHost-CYVsjrQI.js} +2 -2
  31. package/dist/public/assets/{SettingsDialogBody-Cik4C72L.js → SettingsDialogBody-B5-Ld_e6.js} +1 -1
  32. package/dist/public/assets/{ShareReceiveMissDialog-j0uPkM4r.js → ShareReceiveMissDialog-K5C9JK_G.js} +1 -1
  33. package/dist/public/assets/{SkillToolbarControls-CqfpQq7w.js → SkillToolbarControls-DggrLEDq.js} +1 -1
  34. package/dist/public/assets/{SourceEditor-D1l70bqh.js → SourceEditor-Cw4wSDtc.js} +1 -1
  35. package/dist/public/assets/{TerminalWindowApp-ZAIzfdLY.js → TerminalWindowApp-DghgC-6z.js} +1 -1
  36. package/dist/public/assets/{TextDocEditor-DSuwoftR.js → TextDocEditor-DrBWJVuW.js} +1 -1
  37. package/dist/public/assets/ThreadView-BM6MuNzK.js +18 -0
  38. package/dist/public/assets/{TimelineDiffPane-Bzfz8XXw.js → TimelineDiffPane-jaBZlYWq.js} +1 -1
  39. package/dist/public/assets/{auth-state-cache-BbqYWXPa.js → auth-state-cache-vidMN3NZ.js} +1 -1
  40. package/dist/public/assets/{comment-chips-CJ_ESlB-.js → comment-chips-geicHQR3.js} +1 -1
  41. package/dist/public/assets/{config-provider-PtUeJBr3.js → config-provider-DFcchYF_.js} +2 -2
  42. package/dist/public/assets/{doc-undo-manager-BvNq2KNl.js → doc-undo-manager-DZnm55D1.js} +1 -1
  43. package/dist/public/assets/globals-7nCZAq2S.css +1 -0
  44. package/dist/public/assets/index-ChCXmSPV.js +2205 -0
  45. package/dist/public/assets/messages-BFg9-qlP.js +1 -0
  46. package/dist/public/assets/messages-BHdlsepL.js +1 -0
  47. package/dist/public/assets/messages-BjZgTBY9.js +1 -0
  48. package/dist/public/assets/messages-BkkpXTZM.js +1 -0
  49. package/dist/public/assets/messages-C2QtPbJj.js +1 -0
  50. package/dist/public/assets/messages-CIY7f-a1.js +1 -0
  51. package/dist/public/assets/messages-DEMxBGLW.js +1 -0
  52. package/dist/public/assets/messages-DTROvhTk.js +1 -0
  53. package/dist/public/assets/messages-D_UKhiH5.js +1 -0
  54. package/dist/public/assets/messages-D_m0QoQO.js +1 -0
  55. package/dist/public/assets/messages-Dp632KAD.js +1 -0
  56. package/dist/public/assets/messages-FtAFLlAq.js +1 -0
  57. package/dist/public/assets/{pending-receive-nav-store-BL3LmsL1.js → pending-receive-nav-store-BpynqTsI.js} +1 -1
  58. package/dist/public/assets/progress-B4-6I3_h.js +9 -0
  59. package/dist/public/assets/{selection-context-D3utDccb.js → selection-context-gelM_MCh.js} +1 -1
  60. package/dist/public/assets/{src-DI2FX2OJ.js → src-C8GI9PJ6.js} +1 -1
  61. package/dist/public/assets/{typing-burst-detector-DGZVOw2-.js → typing-burst-detector-CoszxP3G.js} +1 -1
  62. package/dist/public/assets/{uninstall-BmvLrb2W.js → uninstall-DYsPV9Se.js} +1 -1
  63. package/dist/public/assets/{use-activity-panel-JE7Xd2N0.js → use-activity-panel-B-sX0TT-.js} +1 -1
  64. package/dist/public/assets/{use-apply-config-language-BG3V72CW.js → use-apply-config-language--D5KrAwV.js} +2 -2
  65. package/dist/public/assets/{use-open-skill-vO0iRTN0.js → use-open-skill-CKVWwdSU.js} +1 -1
  66. package/dist/public/assets/{use-terminal-enabled-D85X8nic.js → use-terminal-enabled-DPUHlEKT.js} +1 -1
  67. package/dist/public/assets/{use-timeline-entry-diff-B9ZWCASK.js → use-timeline-entry-diff-BvjsGsbq.js} +1 -1
  68. package/dist/public/index.html +20 -20
  69. package/dist/public/uninstall.html +5 -5
  70. package/dist/registry-probes-CJobas59.mjs +17 -0
  71. package/dist/{removal-file-path-5pTgbCWb.mjs → removal-file-path-DXtjEEG7.mjs} +1 -1
  72. package/dist/{repair-launch-json-d9rLMBoV.mjs → repair-launch-json-i7YCQJvq.mjs} +1 -1
  73. package/dist/{repair-mcp-configs-Cp0nqANo.mjs → repair-mcp-configs-BINgn4D-.mjs} +1 -1
  74. package/dist/src-DLt2yNOp.mjs +1 -0
  75. package/dist/{src-CjybiOl3.mjs → src-D_hTVC1I.mjs} +5 -5
  76. package/dist/start-CKwG9D85.mjs +1 -0
  77. package/dist/start-D75O0tS9.mjs +5 -0
  78. package/package.json +4 -4
  79. package/dist/constants-CeRULqiD.mjs +0 -1
  80. package/dist/dist-B5vmOfkB.mjs +0 -2104
  81. package/dist/dist-D2OjImAs.mjs +0 -1
  82. package/dist/init-BcV5Hb2F.mjs +0 -1
  83. package/dist/loader-D_UPiWCM.mjs +0 -1
  84. package/dist/preview-DjdOxPOh.mjs +0 -1
  85. package/dist/public/assets/FeedbackForm-DDaR89Bh.js +0 -1
  86. package/dist/public/assets/ManagedArtifactProperties-B3bKejlG.js +0 -1
  87. package/dist/public/assets/ThreadView-SUSZCKAg.js +0 -19
  88. package/dist/public/assets/globals-DQTCRH6J.css +0 -1
  89. package/dist/public/assets/index-RYhjL_x5.js +0 -2205
  90. package/dist/public/assets/messages-2ku_y04q.js +0 -1
  91. package/dist/public/assets/messages-BIC-T4p1.js +0 -1
  92. package/dist/public/assets/messages-CFtpRqY7.js +0 -1
  93. package/dist/public/assets/messages-CWvvXCad.js +0 -1
  94. package/dist/public/assets/messages-CX_L3Z7h.js +0 -1
  95. package/dist/public/assets/messages-Cz3qUVx6.js +0 -1
  96. package/dist/public/assets/messages-DjwO0PQ1.js +0 -1
  97. package/dist/public/assets/messages-DlwadW8k.js +0 -1
  98. package/dist/public/assets/messages-Dnf3Bx2V.js +0 -1
  99. package/dist/public/assets/messages-DyCycqYY.js +0 -1
  100. package/dist/public/assets/messages-Jgk0JmYN.js +0 -1
  101. package/dist/public/assets/messages-f6M5jM7z.js +0 -1
  102. package/dist/public/assets/progress-BaBFNclu.js +0 -9
  103. package/dist/registry-probes-C6-MQkI8.mjs +0 -17
  104. package/dist/src-CjT0xVrn.mjs +0 -1
  105. package/dist/start-B9z-wbjR.mjs +0 -1
  106. package/dist/start-BJQG3Tj1.mjs +0 -5
  107. /package/dist/public/assets/{globals-D_vtSey-.js → globals-D1RUz7O8.js} +0 -0
@@ -1,9 +0,0 @@
1
- import{o as e}from"./chunk-CYidjpOJ.js";import{t}from"./jsx-runtime-BUgB2tll.js";import{I as n,L as r,N as i}from"./DocumentContext-DUQYQdyb.js";import{t as a}from"./react-f2sANaYj.js";import{r as o}from"./dist-Nvb76hAm.js";import{t as s}from"./compiler-runtime-BfE3aGVn.js";import{t as c}from"./utils-CPqDy6Hr.js";import{t as l}from"./button-HKX9wT1K.js";import{c as u,l as d}from"./dist-BcvirUWL.js";import{i as f,n as p,t as m}from"./tooltip-BnyyQDRs.js";import{Ca as h,La as g,Pa as _,Sa as v,Ta as y,ao as b,do as x,eo as S,io as ee,oo as C,uo as te,wa as w,yc as ne}from"./dist-DOFOMv5X.js";import{t as T}from"./dist-Cr4-nBVI.js";import{a as re}from"./local-menu-action-bus-DaoT7_kL.js";import{t as ie}from"./workspace-paths-Dczkx4vn.js";import{t as E}from"./createLucideIcon-B6ULg5PN.js";import{A as D,H as ae,Y as oe,f as O,g as se,h as ce,k as le,l as ue,m as k,p as de,q as fe,u as A}from"./CodeMirrorPropInput-C4usP1JL.js";import{t as j}from"./spinner-Bp2_BYkl.js";import{t as M}from"./x-DIayTyoR.js";import{r as N}from"./doc-paths-D8ecfw_S.js";import{h as pe}from"./file-tree-adapter-tR_J9F2L.js";import{C as me,S as P}from"./thread-client-g2-or03F.js";var F=e(a(),1),I=t(),L=`Progress`,R=100,[z,he]=u(L),[ge,_e]=z(L),B=F.forwardRef((e,t)=>{let{__scopeProgress:n,value:r=null,max:i,getValueLabel:a=ve,...o}=e;(i||i===0)&&!G(i)&&console.error(ye(`${i}`,`Progress`));let s=G(i)?i:R;r!==null&&!K(r,s)&&console.error(q(`${r}`,`Progress`));let c=K(r,s)?r:null,l=W(c)?a(c,s):void 0;return(0,I.jsx)(ge,{scope:n,value:c,max:s,children:(0,I.jsx)(d.div,{"aria-valuemax":s,"aria-valuemin":0,"aria-valuenow":W(c)?c:void 0,"aria-valuetext":l,role:`progressbar`,"data-state":U(c,s),"data-value":c??void 0,"data-max":s,...o,ref:t})})});B.displayName=L;var V=`ProgressIndicator`,H=F.forwardRef((e,t)=>{let{__scopeProgress:n,...r}=e,i=_e(V,n);return(0,I.jsx)(d.div,{"data-state":U(i.value,i.max),"data-value":i.value??void 0,"data-max":i.max,...r,ref:t})});H.displayName=V;function ve(e,t){return`${Math.round(e/t*100)}%`}function U(e,t){return e==null?`indeterminate`:e===t?`complete`:`loading`}function W(e){return typeof e==`number`}function G(e){return W(e)&&!isNaN(e)&&e>0}function K(e,t){return W(e)&&!isNaN(e)&&e<=t&&e>=0}function ye(e,t){return`Invalid prop \`max\` of value \`${e}\` supplied to \`${t}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${R}\`.`}function q(e,t){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${t}\`. The \`value\` prop must be:
2
- - a positive number
3
- - less than the value passed to \`max\` (or ${R} if no \`max\` prop is set)
4
- - \`null\` or \`undefined\` if the progress is indeterminate.
5
-
6
- Defaulting to \`null\`.`}var be=B,xe=H,J=E(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Y=s(),X=`ok-ask-ai-draft-v2`,Z={doc:null,dismissed:!1};function Q(){if(typeof window>`u`)return null;try{return window.localStorage}catch{return null}}var Se=null,Ce=new Set;function we(e){if(e===null)return!0;let t=e.content;return!Array.isArray(t)||t.length===0?!0:t.every(e=>{let t=e.content;return!Array.isArray(t)||t.length===0})}function Te(){let e=Q();if(!e)return Z;try{let t=e.getItem(X);if(!t)return Z;let n=JSON.parse(t);return typeof n!=`object`||!n||Array.isArray(n)?Z:{doc:n,dismissed:!1}}catch(e){return console.warn(`failed to parse stored draft — clearing`,e),Z}}function Ee(){return Se===null&&(Se=Te()),Se}function De(e){let t=Q();if(t)try{e&&!we(e)?t.setItem(X,JSON.stringify(e)):t.removeItem(X)}catch{}}function Oe(){for(let e of Ce)e()}function ke(){return Ee()}function Ae(e){let t=e&&!we(e)?e:null;Se={...Ee(),doc:t},De(t),Oe()}function je(){Ae(null)}var Me=v;function Ne(e){let t=le(e).kind;return t===`folder`||t===`asset`?t:`page`}function Pe(e){let t=(0,Y.c)(14),{items:n,query:r,selectedIndex:a,onSelect:s,loading:c,error:l,hasMore:u}=e,d=c===void 0?!1:c,f=l===void 0?!1:l,p=u===void 0?!1:u,{_:m}=o(),h=(0,F.useId)(),g=(0,F.useRef)(null),_,v;t[0]===a?(_=t[1],v=t[2]):(_=()=>{(g.current?.querySelectorAll(`[role="option"]`))?.item(a)?.scrollIntoView({block:`nearest`})},v=[a],t[0]=a,t[1]=_,t[2]=v),(0,F.useEffect)(_,v);let y=a>=0&&a<n.length?n[a]:null,b;return t[3]!==m||t[4]!==f||t[5]!==p||t[6]!==n||t[7]!==h||t[8]!==d||t[9]!==s||t[10]!==r||t[11]!==a||t[12]!==y?(b=(0,I.jsx)(`div`,{ref:g,className:`w-80 max-w-[min(28rem,90vw)] overflow-hidden rounded-lg border bg-popover p-1 text-popover-foreground shadow-md`,children:d?(0,I.jsx)(`p`,{className:`px-2 py-1.5 text-sm text-muted-foreground`,"aria-live":`polite`,children:m({id:`3m2GBo`})}):f?(0,I.jsx)(`p`,{className:`px-2 py-1.5 text-sm text-muted-foreground`,"aria-live":`assertive`,children:m({id:`weP6me`})}):n.length===0?(0,I.jsx)(`p`,{className:`px-2 py-1.5 text-sm text-muted-foreground`,"aria-live":`polite`,children:r.trim()===``?m({id:`0E9DR6`}):m({id:`yQyglE`})}):(0,I.jsxs)(`div`,{role:`listbox`,id:h,"aria-label":m({id:`05n5wS`}),tabIndex:-1,className:`max-h-64 overflow-y-auto overscroll-contain subtle-scrollbar`,children:[(0,I.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:y?y.title:``}),n.map((e,t)=>{let n=t===a,r=Ne(e.path),o=r===`folder`,c=o?`${e.path}/`:e.path;return(0,I.jsxs)(`button`,{id:`${h}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-active":n,"data-mention-kind":r,"data-testid":`composer-mention-option-${e.docName}`,className:`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left ${n?`bg-accent text-accent-foreground`:``}`,onMouseDown:t=>{t.preventDefault(),s(e)},children:[(0,I.jsx)(i,{path:e.path,className:`mt-0.5 size-4 shrink-0 text-muted-foreground`}),(0,I.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,I.jsxs)(`span`,{className:`flex items-baseline gap-1.5`,children:[(0,I.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.title}),o?(0,I.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:m({id:`kNqMMd`})}):null]}),(0,I.jsx)(`span`,{className:`line-clamp-2 break-all text-xs text-muted-foreground`,children:c})]})]},e.docName)}),p?(0,I.jsx)(`div`,{className:`px-2 py-1 text-xs text-muted-foreground`,"aria-hidden":!0,children:m({id:`F1T9y_`})}):null]})}),t[3]=m,t[4]=f,t[5]=p,t[6]=n,t[7]=h,t[8]=d,t[9]=s,t[10]=r,t[11]=a,t[12]=y,t[13]=b):b=t[13],b}function Fe(e){let t=(0,Y.c)(12),{items:n,query:r,selectedIndex:i,onSelect:a,commandsKnown:s}=e,{_:c}=o(),l=(0,F.useId)(),u=(0,F.useRef)(null),d,f;t[0]===i?(d=t[1],f=t[2]):(d=()=>{(u.current?.querySelectorAll(`[role="option"]`))?.item(i)?.scrollIntoView({block:`nearest`})},f=[i],t[0]=i,t[1]=d,t[2]=f),(0,F.useEffect)(d,f);let p=i>=0&&i<n.length?n[i]:null,m;return t[3]!==c||t[4]!==s||t[5]!==n||t[6]!==l||t[7]!==a||t[8]!==r||t[9]!==i||t[10]!==p?(m=(0,I.jsx)(`div`,{ref:u,"data-testid":`composer-slash-menu`,className:`w-[42rem] max-w-[min(42rem,90vw)] overflow-hidden rounded-lg border bg-popover p-1 text-popover-foreground shadow-md`,children:n.length===0?(0,I.jsx)(`p`,{className:`px-2 py-1.5 text-sm text-muted-foreground`,"aria-live":`polite`,children:s?r.trim()===``?c({id:`QohqVL`}):c({id:`odYWGJ`}):c({id:`9OPs7U`})}):(0,I.jsxs)(`div`,{role:`listbox`,id:l,"aria-label":c({id:`67Dpmh`}),tabIndex:-1,className:`max-h-64 overflow-y-auto overscroll-contain subtle-scrollbar`,children:[(0,I.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:p?`/${p.name}`:``}),n.map((e,t)=>{let n=t===i;return(0,I.jsxs)(`button`,{id:`${l}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-active":n,"data-testid":`composer-slash-option-${e.name}`,className:`flex w-full items-baseline gap-2 rounded-md px-2 py-1.5 text-left ${n?`bg-accent text-accent-foreground`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,I.jsxs)(`span`,{className:`shrink-0 font-mono text-sm font-medium`,children:[`/`,e.name]}),(0,I.jsx)(`span`,{className:`line-clamp-2 min-w-0 flex-1 text-xs text-muted-foreground`,children:e.description})]},e.name)})]})}),t[3]=c,t[4]=s,t[5]=n,t[6]=l,t[7]=a,t[8]=r,t[9]=i,t[10]=p,t[11]=m):m=t[11],m}var Ie=new x(`composerSlashSuggestion`),Le=g.create({name:`composerCommand`,group:`inline`,inline:!0,atom:!0,selectable:!1,addAttributes(){return{name:{default:``},description:{default:``},hint:{default:``}}},parseHTML(){return[{tag:`span[data-composer-command]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=String(e.attrs.name??``);return[`span`,S(t,{"data-composer-command":n,class:`composer-slash-token composer-slash-token-known`}),`/${n}`]},renderText({node:e}){return`/${e.attrs.name}`}}),Re=new x(`composerSlashToken`),ze=`composerSlashCommand`;function Be(e){return e.storage[ze]}function Ve(e){return Be(e)?.commands??null}function He(e,t){let n=Be(e);return n===void 0||n.commands===t?!1:(n.commands=t,!0)}function Ue(e,t){let n=t.trim().toLowerCase();if(n===``)return[...e];let r=[],i=[],a=[];for(let t of e){let e=t.name.toLowerCase();e.startsWith(n)?r.push(t):e.includes(n)?i.push(t):t.description.toLowerCase().includes(n)&&a.push(t)}return[...r,...i,...a]}function We(e){let t=/^\/(\S+)/.exec(e);return t===null?null:{name:t[1]??``,length:t[0].length}}function Ge(e,t){let n=We(e);if(n===null||t===null)return null;let r=t.find(e=>e.name===n.name);return r===void 0?{kind:`unknown`,name:n.name,agentHasCommands:t.length>0}:{kind:`known`,name:r.name,description:r.description}}function Ke(e){return qe(e.state.doc.firstChild)}function qe(e){let t=e?.firstChild??null;return t?.isText?t.text??``:``}function Je(e,t){let n=e.firstChild,r=n?.firstChild??null;if(r!==null&&r.type.name===`composerCommand`){if(!Ze(e))return C.empty;let t=String(r.attrs.hint??``),i=String(r.attrs.description??``),a=t===``?i===``?``:`— ${i}`:t;return a===``?C.empty:C.create(e,[Ye(1+(n?.content.size??0),a,String(r.attrs.name))])}if(t===null)return C.empty;let i=We(qe(e.firstChild));if(i===null)return C.empty;let a=t.find(e=>e.name===i.name),o=[b.inline(1,1+i.length,{class:a===void 0?`composer-slash-token composer-slash-token-unknown`:`composer-slash-token composer-slash-token-known`})];if(a!==void 0&&Xe(e,i.length)){let t=a.input?.hint!=null&&a.input.hint!==``?a.input.hint:`— ${a.description}`;(a.description!==``||a.input?.hint)&&o.push(Ye(1+(e.firstChild?.firstChild?.nodeSize??0),t,a.name))}return C.create(e,o)}function Ye(e,t,n){return b.widget(e,()=>{let e=document.createElement(`span`);return e.className=`composer-slash-ghost`,e.setAttribute(`aria-hidden`,`true`),e.textContent=t,e},{side:1,key:`slash-ghost:${n}`})}function Xe(e,t){if(e.childCount!==1)return!1;let n=e.firstChild;if(n===null||n.childCount!==1)return!1;let r=n.firstChild;if(r===null||!r.isText)return!1;let i=r.text??``;return i.length<=t+1&&(i.length===t||i.endsWith(` `))}function Ze(e){if(e.childCount!==1)return!1;let t=e.firstChild;if(t===null)return!1;if(t.childCount===1)return!0;if(t.childCount!==2)return!1;let n=t.child(1);return n.isText&&/^\s*$/.test(n.text??``)}var Qe=_.create({name:ze,addOptions(){return{commands:null}},addStorage(){return{commands:this.options.commands}},addProseMirrorPlugins(){let e=this.storage,t=()=>e.commands??null;return[new te({key:Re,state:{init:(e,n)=>Je(n.doc,t()),apply:e=>Je(e.doc,t())},props:{decorations(e){return this.getState(e)}}}),D({editor:this.editor,pluginKey:Ie,char:`/`,startOfLine:!0,allow:({range:e})=>e.from===1,items:({query:e})=>{let n=t();return n===null||n.length===0?[]:Ue(n,e)},command:({editor:e,range:t,props:n})=>{let r=e.state.doc.firstChild?.firstChild??null,i=r?.isText?We(r.text??``)?.length??0:0;try{e.chain().focus().deleteRange({from:t.from,to:Math.max(t.to,1+i)}).insertContent([{type:`composerCommand`,attrs:{name:n.name,description:n.description,hint:n.input?.hint??``}},{type:`text`,text:` `}]).run()}catch(e){console.error(`[composer-slash-command] insert failed`,{item:n,range:t},e)}},render:()=>{let e=null,n=null,r=0,i={popup:null,stopAutoUpdate:null},a=null,o=null,s=e=>{n?.command(e)},c=e=>{o=e.editor.view,ce(o,(e.items??[]).length)},l=e=>({items:e.items??[],query:e.query??``,selectedIndex:r,onSelect:s,commandsKnown:t()!==null}),u=()=>{!e||!n||e.updateProps(l(n))};return{onBeforeStart(t){n=t,r=0,c(t);let o=de(()=>n,`composer-slash`);i.popup=o.popup,a=o.doPosition,e=new fe(Fe,{props:l(t),editor:t.editor}),o.popup.appendChild(e.element),i.stopAutoUpdate=o.startAutoUpdate(),o.reveal()},onStart(e){n=e,r=0,c(e),u()},onUpdate(e){n=e,r=Math.min(r,Math.max(0,e.items.length-1)),c(e),u(),a?.()},onKeyDown({event:e}){if(!n)return!1;let t=n.items;if(e.key===`ArrowDown`)return t.length===0?!1:(r=(r+1)%t.length,u(),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(r=(r-1+t.length)%t.length,u(),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[r];return e?(n.command(e),!0):!1}return!1},onExit(){k(i),a=null,e?.destroy(),e=null,n=null,r=0,o!==null&&(O(o),o=null)}}}})]}}),$e=8,et=4,tt=`composerMention`,nt={currentDocName:null,recentPaths:[]};function rt(e){return e.storage[tt]}function it(e){return rt(e)?.recency??nt}function at(e,t){let n=rt(e);n!==void 0&&(n.recency=t)}function ot(e,t){let n=t.currentDocName===null?null:N(t.currentDocName),r=new Map;for(let[e,n]of t.recentPaths.entries())r.set(n,e+1);let i=[];for(let t of e){if(n!==null&&t.docName===n){i.push({page:t,order:0});continue}let e=r.get(ct(t));e!==void 0&&i.push({page:t,order:e})}i.sort((e,t)=>e.order-t.order);let a=i.slice(0,et).map(e=>e.page),o=new Set(a);return[...a,...A(e.filter(e=>!o.has(e)),``)]}var st=new x(`composerMentionSuggestion`);function ct(e){return e.kind===`asset`?e.docName.replace(/^\//,``):e.kind===`folder`?e.docName:ie(e.docName)}var lt=g.create({name:`doc`,topNode:!0,content:`paragraph+`}),ut=g.create({name:`paragraph`,group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML(){return[`p`,0]}}),dt=g.create({name:`text`,group:`inline`}),ft=g.create({name:`hardBreak`,group:`inline`,inline:!0,selectable:!1,parseHTML(){return[{tag:`br`}]},renderHTML(){return[`br`]},addKeyboardShortcuts(){return{"Shift-Enter":()=>this.editor.commands.insertContent({type:`hardBreak`})}}}),pt=_.create({name:`composerHistory`,addProseMirrorPlugins(){return[h(),ee({"Mod-z":y,"Mod-y":w,"Shift-Mod-z":w})]}}),mt=g.create({name:tt,group:`inline`,inline:!0,atom:!0,selectable:!0,addAttributes(){return{path:{default:``},label:{default:``},mentionKind:{default:`file`}}},parseHTML(){return[{tag:`span[data-composer-mention]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=String(e.attrs.label||e.attrs.path);return[`span`,S(t,{"data-composer-mention":String(e.attrs.path??``),class:`composer-mention-chip`}),`@${n}`]},renderText({node:e}){return`@${e.attrs.path}`},addNodeView(){return({node:e,editor:t,getPos:i})=>{let a=String(e.attrs.path??``),o=String(e.attrs.label||e.attrs.path),s=document.createElement(`span`);s.className=`composer-mention-chip group/mention`,s.setAttribute(`data-composer-mention`,a),s.title=o;let c=document.createElement(`button`);c.type=`button`,c.className=`composer-mention-icon`,c.setAttribute(`aria-label`,T._({id:`Xzy0s0`,values:{fullLabel:o}}));let l=document.createElement(`span`);l.className=`composer-mention-glyph composer-mention-glyph-icon`,l.setAttribute(`aria-hidden`,`true`),l.innerHTML=n(a),c.appendChild(l);let u=document.createElement(`span`);u.className=`composer-mention-glyph composer-mention-glyph-x`,u.setAttribute(`aria-hidden`,`true`),u.innerHTML=r(M),c.appendChild(u),c.addEventListener(`mousedown`,e=>e.preventDefault()),c.addEventListener(`click`,n=>{n.preventDefault();let r=typeof i==`function`?i():null;r!=null&&t.chain().focus().deleteRange({from:r,to:r+e.nodeSize}).run()}),s.appendChild(c);let d=document.createElement(`span`);return d.className=`composer-mention-label`,d.textContent=o,s.appendChild(d),{dom:s}}},addStorage(){return{recency:nt}},addProseMirrorPlugins(){return[_t(this.editor)]}});function ht(e){return[lt,ut,dt,ft,pt,mt,Le,...e?.slashCommands===void 0?[]:[Qe.configure({commands:e.slashCommands})],...e?.placeholder?[Me.configure({placeholder:e.placeholder,showOnlyWhenEditable:!1})]:[]]}function gt(e=()=>ue({includeFolders:!0})){let t=[],n=!1,r=null,i=!1;return{snapshot(){return{loaded:n,error:i}},async getItems(a,o=nt){if(!n){r||=e();try{t=await r,n=!0,i=!1}catch(e){console.error(`[composer-mention] failed to fetch pages`,e),t=[],i=!0}finally{r=null}}return(a===``?ot(t,o):A(t,a)).slice(0,$e).map(e=>({docName:e.docName,title:e.title,path:ct(e),kind:e.kind===`folder`?`folder`:`file`})).filter(e=>e.path!==``)},reset(){t=[],n=!1,r=null,i=!1}}}function _t(e){let t=gt();return D({editor:e,pluginKey:st,char:`@`,items:({query:n})=>t.getItems(n,it(e)),command:({editor:e,range:t,props:n})=>{try{e.chain().focus().deleteRange(t).insertContent([{type:`composerMention`,attrs:{path:n.path,label:n.title,mentionKind:n.kind}},{type:`text`,text:` `}]).run()}catch(e){console.error(`[composer-mention] insert failed`,{item:n,range:t},e)}},render:()=>{let e=null,n=null,r=0,i={popup:null,stopAutoUpdate:null},a=null,o=null,s=null,c=e=>{n?.command(e)},l=e=>{s=e.editor.view,ce(s,(e.items??[]).length)},u=e=>{let n=e.items??[],{loaded:i,error:a}=t.snapshot();return{items:n,query:e.query??``,selectedIndex:r,onSelect:c,loading:!i&&!a,error:a,hasMore:n.length>=$e}},d=()=>{!e||!n||e.updateProps(u(n))};return{onBeforeStart(t){n=t,r=0,l(t);let s=de(()=>n,`composer-mention`);i.popup=s.popup,a=s.doPosition,o=s.reveal,e=new fe(Pe,{props:u(t),editor:t.editor}),s.popup.appendChild(e.element),i.stopAutoUpdate=s.startAutoUpdate()},onStart(e){n=e,r=0,l(e),d(),o?.()},onUpdate(e){n=e,r=Math.min(r,Math.max(0,e.items.length-1)),l(e),d(),a?.()},onKeyDown({event:e}){if(!n)return!1;let t=n.items;if(e.key===`ArrowDown`)return t.length===0?!1:(r=(r+1)%t.length,d(),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(r=(r-1+t.length)%t.length,d(),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[r];return e?(n.command(e),!0):!1}return!1},onExit(){k(i),a=null,o=null,e?.destroy(),e=null,n=null,r=0,s!==null&&(O(s),s=null),t.reset()}}}})}function vt(e){let t=[],n=[],r=new Set,i=[];return e.state.doc.forEach(e=>{let a=``;e.forEach(e=>{if(e.type.name===`composerMention`){let i=String(e.attrs.path??``);if(i!==``&&(a+=`@${i}`,!r.has(i))){r.add(i),t.push(i);let a=String(e.attrs.label??``),o=e.attrs.mentionKind===`folder`?`folder`:`file`;n.push({kind:o,path:i,name:a===``?i:a})}}else e.type.name===`composerCommand`?a+=`/${String(e.attrs.name??``)}`:e.isText?a+=e.text??``:e.type.name===`hardBreak`&&(a+=`
7
- `)}),i.push(a)}),{instruction:i.join(`
8
- `).trim(),mentions:t,attachments:n}}function $(e){let{instruction:t,mentions:n}=vt(e);return t===``&&n.length===0}var yt=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),bt=700*1024,xt=bt,St=bt;function Ct(e){return e.kind!==`image`&&e.kind!==`blob`?0:e.sizeBytes??e.data.length}function wt(e){return e.reduce((e,t)=>e+Ct(t),0)}function Tt(){return Math.round(St/1024)}function Et(e){if(e.kind===`unsupported-type`){let t=e.mimeType;if(t.startsWith(`image/`))return T._({id:`FqMKq2`,values:{mimeType:t}});let n=t||`unknown`;return T._({id:`9gu0n7`,values:{fileType:n}})}if(e.kind===`outside-workspace`){let t=e.name;return T._({id:`K9ViCA`,values:{name:t}})}if(e.kind===`unknown-path`){let t=e.name;return T._({id:`q8tKSU`,values:{name:t}})}let t=Math.round(e.limitBytes/1024),n=Math.round(e.sizeBytes/1024);return T._({id:`Kb08WL`,values:{sizeKb:n,limitKb:t}})}async function Dt(e){let t=await new Promise((t,n)=>{let r=new FileReader;r.onerror=()=>n(r.error??Error(`FileReader failed`)),r.onload=()=>{let e=r.result;if(typeof e!=`string`){n(Error(`FileReader returned non-string result`));return}t(e)},r.readAsDataURL(e)}),n=t.indexOf(`,`);return{data:n>=0?t.slice(n+1):t,mimeType:e.type||`application/octet-stream`,name:e.name||`image`,sizeBytes:e.size}}async function Ot(e){let t=e.type||``;if(!yt.has(t))return{ok:!1,error:{kind:`unsupported-type`,mimeType:t}};if(e.size>716800)return{ok:!1,error:{kind:`too-large`,sizeBytes:e.size,limitBytes:xt}};let n=await Dt(e);return{ok:!0,part:{kind:`image`,data:n.data,mimeType:n.mimeType,name:n.name,sizeBytes:n.sizeBytes}}}function kt(e){return jt(e,e=>e.type.startsWith(`image/`))}function At(e){return jt(e,e=>e.size>0)}function jt(e,t){if(e===null)return[];let n=[],r=e=>{e!==null&&t(e)&&n.push(e)},i=!1,a=e.items;if(a)for(let e=0;e<a.length;e+=1){let t=a[e];if(t?.kind!==`file`)continue;let n=t.getAsFile();n!==null&&(i=!0,r(n))}if(!i){let t=e.files;if(t)for(let e=0;e<t.length;e+=1)r(t[e]??null)}return n}function Mt(e,t,n){let r=n===`\\`?e.toLowerCase():e,i=n===`\\`?t.toLowerCase():t,a=i.endsWith(n)?i:`${i}${n}`;if(r===i)return``;if(!r.startsWith(a))return null;let o=e.slice(a.length);return n===`\\`?o.replaceAll(`\\`,`/`):o}async function Nt(e,t={}){if((e.type||``).startsWith(`image/`))return Ot(e);let n=t.absPathOf,r=t.workspaceContentDir,i=t.pathSeparator??`/`,a=e.name||`attachment`;if(n===void 0||r===void 0||r===``)return{ok:!1,error:{kind:`unknown-path`,name:a}};let o=n(e);if(o===null||o===``)return{ok:!1,error:{kind:`unknown-path`,name:a}};let s=Mt(o,r,i);return s===null?{ok:!1,error:{kind:`outside-workspace`,name:a}}:{ok:!0,part:{kind:`file`,path:s,name:a}}}function Pt(e){let t=e?.content;return!Array.isArray(t)||t.length===0?!1:t.some(e=>Array.isArray(e.content)&&e.content.length>0)}function Ft(e){return e.split(`
9
- `).map(e=>({type:`paragraph`,content:e===``?[]:[{type:`text`,text:e}]}))}function It(e){let t=(0,Y.c)(75),{ref:n,ariaLabel:r,ariaDescribedBy:i,onEmptyChange:a,onContentChange:s,onMentionsChange:l,onSubmit:u,onEscape:d,className:f,placeholder:p,initialDoc:m,disabled:h,testId:g,slashCommands:_,mentionRecency:v,attachmentDrop:y}=e,b=h===void 0?!1:h,{_:x}=o(),[S,ee]=(0,F.useState)(null),[C,te]=(0,F.useState)(null),w=(0,F.useRef)(0),ne;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>{w.current+=1,te({text:e,id:w.current})},t[0]=ne):ne=t[0];let T=ne,re,ie;t[1]===C?(re=t[2],ie=t[3]):(re=()=>{if(C===null)return;let e=setTimeout(()=>te(null),4e3);return()=>clearTimeout(e)},ie=[C],t[1]=C,t[2]=re,t[3]=ie),(0,F.useEffect)(re,ie);let E=(0,F.useRef)(a),D=(0,F.useRef)(s),O=(0,F.useRef)(l),ce=(0,F.useRef)(u),le=(0,F.useRef)(d),ue;t[4]!==s||t[5]!==a||t[6]!==d||t[7]!==l||t[8]!==u?(ue=()=>{E.current=a,D.current=s,O.current=l,ce.current=u,le.current=d},t[4]=s,t[5]=a,t[6]=d,t[7]=l,t[8]=u,t[9]=ue):ue=t[9],(0,F.useEffect)(ue);let k;t[10]!==p||t[11]!==_?(k=ht({placeholder:p,slashCommands:_}),t[10]=p,t[11]=_,t[12]=k):k=t[12];let de=m??void 0,fe=!b,A;t[13]===i?A=t[14]:(A=i===void 0?{}:{"aria-describedby":i},t[13]=i,t[14]=A);let j;t[15]===g?j=t[16]:(j=g===void 0?{}:{"data-testid":g},t[15]=g,t[16]=j);let M;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(M=c(`composer-prosemirror py-1 outline-none`),t[17]=M):M=t[17];let N;t[18]!==r||t[19]!==j||t[20]!==A?(N={role:`textbox`,"aria-label":r,...A,"aria-multiline":`true`,...j,class:M},t[18]=r,t[19]=j,t[20]=A,t[21]=N):N=t[21];let me;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(me=(e,t)=>t.key===`Escape`?st.getState(e.state)?.active||Ie.getState(e.state)?.active?!1:le.current===void 0?(e.dom.blur(),!0):(le.current(),!0):t.key===`Enter`&&!t.shiftKey&&!t.isComposing&&!e.composing?(st.getState(e.state)?.active||Ie.getState(e.state)?.active)&&se(e)?!1:(ce.current(),!0):!1,t[22]=me):me=t[22];let P;t[23]===N?P=t[24]:(P={attributes:N,handleKeyDown:me},t[23]=N,t[24]=P);let L;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>{let{editor:t}=e;E.current($(t)),D.current?.(t.getJSON()),O.current?.(vt(t).mentions),ee(Ge(Ke(t),Ve(t)))},t[25]=L):L=t[25];let R;t[26]!==P||t[27]!==k||t[28]!==de||t[29]!==fe?(R={extensions:k,content:de,immediatelyRender:!0,editable:fe,editorProps:P,onUpdate:L},t[26]=P,t[27]=k,t[28]=de,t[29]=fe,t[30]=R):R=t[30];let z=oe(R),he,ge;t[31]!==i||t[32]!==r||t[33]!==z||t[34]!==p?(he=()=>{if(!z||z.isDestroyed)return;let e=z.extensionManager.extensions.find(zt);e&&(e.options.placeholder=p??``);let t=z.editorView;t&&(t.dom.setAttribute(`aria-label`,r??``),i===void 0?t.dom.removeAttribute(`aria-describedby`):t.dom.setAttribute(`aria-describedby`,i),t.dispatch(z.state.tr.setMeta(`addToHistory`,!1)))},ge=[z,p,r,i],t[31]=i,t[32]=r,t[33]=z,t[34]=p,t[35]=he,t[36]=ge):(he=t[35],ge=t[36]),(0,F.useEffect)(he,ge);let _e,B;t[37]!==b||t[38]!==z?(_e=()=>{if(!z||z.isDestroyed)return;let e=!b;z.isEditable!==e&&z.setEditable(e,!1);let t=z.editorView;t&&(b?t.dom.setAttribute(`aria-disabled`,`true`):t.dom.removeAttribute(`aria-disabled`))},B=[z,b],t[37]=b,t[38]=z,t[39]=_e,t[40]=B):(_e=t[39],B=t[40]),(0,F.useEffect)(_e,B);let V,H;t[41]!==z||t[42]!==_?(V=()=>{if(!(!z||z.isDestroyed)){if(He(z,_??null)){let e=z.editorView;e&&e.dispatch(z.state.tr.setMeta(`addToHistory`,!1))}ee(Ge(Ke(z),Ve(z)))}},H=[z,_],t[41]=z,t[42]=_,t[43]=V,t[44]=H):(V=t[43],H=t[44]),(0,F.useEffect)(V,H);let ve,U;t[45]!==z||t[46]!==v?(ve=()=>{!z||z.isDestroyed||at(z,v??nt)},U=[z,v],t[45]=z,t[46]=v,t[47]=ve,t[48]=U):(ve=t[47],U=t[48]),(0,F.useEffect)(ve,U);let W;t[49]!==z||t[50]!==m?(W=()=>{z&&($(z)&&Pt(m)&&(console.warn(`composer draft was incompatible with the current schema — clearing it`),je()),E.current($(z)),O.current?.(vt(z).mentions))},t[49]=z,t[50]=m,t[51]=W):W=t[51];let G;t[52]===z?G=t[53]:(G=[z],t[52]=z,t[53]=G),(0,F.useEffect)(W,G);let K,ye;t[54]===z?(K=t[55],ye=t[56]):(K=()=>({focus:()=>z?.commands.focus(),refuseDrop:e=>{w.current+=1,te({text:e,id:w.current})},focusEnd:()=>z?.commands.focus(`end`),blur:()=>z?.commands.blur(),clear:()=>z?.commands.clearContent(!0),setText:e=>{z&&(z.commands.setContent(Ft(e)),E.current($(z)),D.current?.(z.getJSON()),O.current?.(vt(z).mentions),ee(Ge(Ke(z),Ve(z))))},appendText:e=>{!z||e===``||($(z)?z.commands.setContent(Ft(e)):z.commands.insertContentAt(z.state.doc.content.size,[{type:`paragraph`,content:[]},...Ft(e)]),E.current($(z)),D.current?.(z.getJSON()),O.current?.(vt(z).mentions),ee(Ge(Ke(z),Ve(z))))},getContent:()=>z?vt(z):{instruction:``,mentions:[],attachments:[]},openMentionPicker:()=>{z&&z.chain().focus().insertContent(`@`).run()}}),ye=[z],t[54]=z,t[55]=K,t[56]=ye),(0,F.useImperativeHandle)(n,K,ye);let q=y,be;t[57]!==x||t[58]!==q?(be=q.kind===`host`?{}:{onDragEnter:Rt,onDragOver:Lt,onDrop:e=>{if(!pe(e))return;e.preventDefault(),e.stopPropagation();let t=At(e.dataTransfer);if(t.length===0){T(x({id:`rNi1kZ`}));return}if(q.kind===`accept`){q.onFiles(t);return}T(q.reason??x({id:`SgAFuo`}))}},t[57]=x,t[58]=q,t[59]=be):be=t[59];let xe=be,J;t[60]!==f||t[61]!==xe||t[62]!==z?(J=(0,I.jsx)(ae,{editor:z,className:f,...xe}),t[60]=f,t[61]=xe,t[62]=z,t[63]=J):J=t[63];let X;t[64]!==q.kind||t[65]!==C?(X=q.kind===`host`?null:(0,I.jsx)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`composer-drop-refusal`,children:C===null?null:(0,I.jsx)(`p`,{className:`px-2.5 py-1 text-muted-foreground text-xs`,children:C.text},C.id)}),t[64]=q.kind,t[65]=C,t[66]=X):X=t[66];let Z;t[67]!==x||t[68]!==_||t[69]!==S?(Z=_===void 0?null:(0,I.jsx)(`p`,{className:c(`truncate px-2.5 text-xs text-muted-foreground`,S?.kind===`unknown`&&`pb-1`),"aria-live":`polite`,"aria-atomic":`true`,"data-testid":`composer-slash-hint`,children:S?.kind===`unknown`?S.agentHasCommands?x({id:`mBK8zm`,values:{0:S.name}}):x({id:`Q9AxTM`}):null}),t[67]=x,t[68]=_,t[69]=S,t[70]=Z):Z=t[70];let Q;return t[71]!==J||t[72]!==X||t[73]!==Z?(Q=(0,I.jsxs)(I.Fragment,{children:[J,X,Z]}),t[71]=J,t[72]=X,t[73]=Z,t[74]=Q):Q=t[74],Q}function Lt(e){pe(e)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}function Rt(e){pe(e)&&e.preventDefault()}function zt(e){return e.name===`placeholder`}function Bt(e){let t=(0,Y.c)(21),{onFiles:n,referencesOnly:r,testId:i,size:a}=e,s=r===void 0?!1:r,c=a===void 0?`icon-sm`:a,{_:u}=o(),d;t[0]===n?d=t[1]:(d=()=>{let e=document.createElement(`input`);e.type=`file`,e.multiple=!0,e.addEventListener(`change`,()=>{let t=Array.from(e.files??[]);t.length>0&&n(t)}),e.click()},t[0]=n,t[1]=d);let h=d,g;t[2]===u?g=t[3]:(g=u({id:`tCyvAw`}),t[2]=u,t[3]=g);let _;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,I.jsx)(re,{className:`size-4`,"aria-hidden":`true`}),t[4]=_):_=t[4];let v;t[5]!==h||t[6]!==c||t[7]!==g||t[8]!==i?(v=(0,I.jsx)(f,{asChild:!0,children:(0,I.jsx)(l,{type:`button`,size:c,variant:`ghost`,className:`rounded-lg`,onClick:h,"aria-label":g,"data-testid":i,children:_})}),t[5]=h,t[6]=c,t[7]=g,t[8]=i,t[9]=v):v=t[9];let y;t[10]===u?y=t[11]:(y=u({id:`tCyvAw`}),t[10]=u,t[11]=y);let b;t[12]!==u||t[13]!==s?(b=s?u({id:`LZe2vX`}):null,t[12]=u,t[13]=s,t[14]=b):b=t[14];let x;t[15]!==y||t[16]!==b?(x=(0,I.jsxs)(p,{side:`top`,children:[y,b]}),t[15]=y,t[16]=b,t[17]=x):x=t[17];let S;return t[18]!==v||t[19]!==x?(S=(0,I.jsxs)(m,{children:[v,x]}),t[18]=v,t[19]=x,t[20]=S):S=t[20],S}var Vt=(0,F.createContext)(null);function Ht(e,t){let n=e.lastIndexOf(`.`);if(n>0&&n<e.length-1)return e.slice(n+1).toLowerCase();let r=t.lastIndexOf(`/`);return r>0&&r<t.length-1?t.slice(r+1).toLowerCase():`file`}function Ut(e){let t=(0,Y.c)(23),{testIdPrefix:n,images:r,uploads:i,onRemove:a}=e,{_:s}=o(),c=(0,F.use)(Vt),u=i.length>0,d=`${n}-pending-images`,f;if(t[0]!==s||t[1]!==r||t[2]!==a||t[3]!==c||t[4]!==n){let e;t[6]!==s||t[7]!==a||t[8]!==c||t[9]!==n?(e=(e,t)=>{let r=e.kind===`image`||e.kind===`blob`?`${t}:${e.name}:${e.data.slice(0,24)}`:`${t}:${e.name}:${e.path}`,i=e.kind===`image`?`data:${e.mimeType};base64,${e.data}`:null,o=e.kind===`file`||e.kind===`folder`?Ht(e.name,``):Ht(e.name,e.mimeType);return(0,I.jsxs)(`div`,{className:`group relative inline-flex size-14`,title:e.name,children:[i!==null&&c!==null?(0,I.jsx)(l,{type:`button`,variant:`ghost`,onClick:()=>c({src:i,name:e.name}),className:`size-full items-center justify-center overflow-hidden rounded-md border border-input bg-muted p-0 hover:bg-muted`,"aria-label":e.name,"data-testid":`${n}-pending-image-preview`,children:(0,I.jsx)(`img`,{src:i,alt:e.name,className:`h-full w-full object-cover`,draggable:!1})}):(0,I.jsx)(`div`,{className:`inline-flex size-full items-center justify-center overflow-hidden rounded-md border border-input bg-muted`,children:i===null?(0,I.jsx)(`span`,{className:`text-muted-foreground text-xs uppercase`,children:o}):(0,I.jsx)(`img`,{src:i,alt:e.name,className:`h-full w-full object-cover`,draggable:!1})}),(0,I.jsx)(l,{type:`button`,size:`icon`,variant:`secondary`,onClick:e=>{e.stopPropagation(),a(t)},"aria-label":s({id:`w61W3L`,values:{0:e.name}}),className:`absolute top-0.5 end-0.5 size-5 rounded-full border border-border bg-background/80 p-0 shadow-sm opacity-0 backdrop-blur-sm transition-opacity group-hover:opacity-100 focus-visible:opacity-100`,"data-testid":`${n}-pending-image-remove`,children:(0,I.jsx)(M,{className:`size-3`,"aria-hidden":`true`})})]},r)},t[6]=s,t[7]=a,t[8]=c,t[9]=n,t[10]=e):e=t[10],f=r.map(e),t[0]=s,t[1]=r,t[2]=a,t[3]=c,t[4]=n,t[5]=f}else f=t[5];let p;if(t[11]!==s||t[12]!==n||t[13]!==i){let e;t[15]!==s||t[16]!==n?(e=e=>{let t=e.name;return(0,I.jsx)(`div`,{role:`img`,"aria-label":s({id:`KDuPiY`,values:{fileName:t}}),className:`relative inline-flex size-14 items-center justify-center overflow-hidden rounded-md border border-input bg-muted`,title:e.name,"data-testid":`${n}-pending-upload`,children:(0,I.jsx)(j,{className:`size-4 text-muted-foreground`,"aria-hidden":`true`})},e.id)},t[15]=s,t[16]=n,t[17]=e):e=t[17],p=i.map(e),t[11]=s,t[12]=n,t[13]=i,t[14]=p}else p=t[14];let m;return t[18]!==u||t[19]!==d||t[20]!==f||t[21]!==p?(m=(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2 px-3 pt-2 pb-1`,"aria-busy":u,"data-testid":d,children:[f,p]}),t[18]=u,t[19]=d,t[20]=f,t[21]=p,t[22]=m):m=t[22],m}var Wt=`button, a[href], [role="menuitem"], [role="button"], input, textarea, select, [contenteditable="true"]`;function Gt(e,t){if(!(e.target instanceof HTMLElement)||!(e.currentTarget instanceof HTMLElement)||!e.currentTarget.contains(e.target)||e.target.closest(Wt))return;e.preventDefault();let n=t.current;n!==null&&(n.focusEnd===void 0?n.focus():n.focusEnd())}function Kt(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function qt(e){let t=(0,Y.c)(21),{path:n,onRemove:r}=e,{_:a}=o(),s,c;t[0]!==a||t[1]!==n?(s=Kt(n),c=a({id:`hnq8fP`,values:{label:s}}),t[0]=a,t[1]=n,t[2]=s,t[3]=c):(s=t[2],c=t[3]);let u=c,d=`composer-context-chip-file-${n}`,f;t[4]===r?f=t[5]:(f=e=>{(e.key===`Backspace`||e.key===`Delete`)&&(e.preventDefault(),r())},t[4]=r,t[5]=f);let p;t[6]===n?p=t[7]:(p=(0,I.jsx)(`span`,{className:`absolute top-1/2 left-1/2 inline-flex size-3 -translate-x-1/2 -translate-y-1/2 opacity-100 transition-opacity duration-150 ease-out group-hover/chip:opacity-0 group-focus-within/chip:opacity-0 motion-reduce:transition-none`,children:(0,I.jsx)(i,{path:n,className:`size-3`,showExtensionBadge:!1})}),t[6]=n,t[7]=p);let m;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,I.jsx)(M,{className:`absolute top-1/2 left-1/2 size-3 -translate-x-1/2 -translate-y-1/2 opacity-0 transition-opacity duration-150 ease-out group-hover/chip:opacity-100 group-focus-within/chip:opacity-100 motion-reduce:transition-none`,"aria-hidden":!0}),t[8]=m):m=t[8];let h;t[9]!==r||t[10]!==u||t[11]!==f||t[12]!==p?(h=(0,I.jsxs)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":u,onClick:r,onKeyDown:f,className:`group/remove relative size-3.5 shrink-0 rounded-sm text-muted-foreground/80 hover:text-foreground`,children:[p,m]}),t[9]=r,t[10]=u,t[11]=f,t[12]=p,t[13]=h):h=t[13];let g;t[14]===s?g=t[15]:(g=(0,I.jsx)(`span`,{className:`min-w-0 truncate`,children:s}),t[14]=s,t[15]=g);let _;return t[16]!==n||t[17]!==d||t[18]!==h||t[19]!==g?(_=(0,I.jsxs)(`span`,{"data-testid":d,title:n,className:`group/chip inline-flex max-w-[14rem] items-center gap-1 rounded-md border bg-muted/40 py-0.5 pr-1.5 pl-1 text-muted-foreground text-xs`,children:[h,g]}),t[16]=n,t[17]=d,t[18]=h,t[19]=g,t[20]=_):_=t[20],_}function Jt(e){let t=(0,Y.c)(13),{files:n,onRemoveFile:r,className:i,children:a}=e,o;t[0]===n?o=t[1]:(o=n===void 0?[]:n,t[0]=n,t[1]=o);let s=o;if(s.length===0&&F.Children.toArray(a).length===0)return null;let l;t[2]===i?l=t[3]:(l=c(`flex flex-wrap items-center gap-1`,i),t[2]=i,t[3]=l);let u;if(t[4]!==s||t[5]!==r){let e;t[7]===r?e=t[8]:(e=e=>(0,I.jsx)(qt,{path:e,onRemove:()=>r?.(e)},e),t[7]=r,t[8]=e),u=s.map(e),t[4]=s,t[5]=r,t[6]=u}else u=t[6];let d;return t[9]!==a||t[10]!==l||t[11]!==u?(d=(0,I.jsxs)(`div`,{className:l,"data-testid":`composer-context-chips`,children:[u,a]}),t[9]=a,t[10]=l,t[11]=u,t[12]=d):d=t[12],d}var Yt=5200;function Xt(e,t){let n=(0,Y.c)(9),[r,i]=(0,F.useState)(0),[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(e.length);s!==e.length&&(c(e.length),i(0),o(!0));let l,u;if(n[0]!==t||n[1]!==a?(l=()=>{if(!t)return;if(a){let e=setTimeout(()=>o(!1),Yt);return()=>clearTimeout(e)}let e=setTimeout(()=>{i(Zt),o(!0)},500);return()=>clearTimeout(e)},u=[a,t],n[0]=t,n[1]=a,n[2]=l,n[3]=u):(l=n[2],u=n[3]),(0,F.useEffect)(l,u),!t){let t=e[0]??``,r;return n[4]===t?r=n[5]:(r={text:t,visible:!0},n[4]=t,n[5]=r),r}let d=e[e.length>0?r%e.length:0]??``,f;return n[6]!==d||n[7]!==a?(f={text:d,visible:a},n[6]=d,n[7]=a,n[8]=f):f=n[8],f}function Zt(e){return e+1}function Qt(e){let t=(0,Y.c)(9),{phrases:n,rotating:r,className:i,testId:a}=e,{text:o,visible:s}=Xt(n,r);if(o===``)return null;let l=s?`opacity-100`:`opacity-0`,u;t[0]!==i||t[1]!==l?(u=c(`pointer-events-none absolute inset-0 text-base leading-[1.5] text-muted-foreground/60 transition-opacity duration-500 ease-in-out md:text-sm`,l,i),t[0]=i,t[1]=l,t[2]=u):u=t[2];let d;t[3]===o?d=t[4]:(d=(0,I.jsx)(`span`,{"data-rotating-placeholder":o,className:`block min-w-0 truncate before:content-[attr(data-rotating-placeholder)]`}),t[3]=o,t[4]=d);let f;return t[5]!==u||t[6]!==d||t[7]!==a?(f=(0,I.jsx)(`div`,{"aria-hidden":!0,"data-testid":a,className:u,children:d}),t[5]=u,t[6]=d,t[7]=a,t[8]=f):f=t[8],f}var $t=`ok-acp-follow-file-v1`;function en(){try{return localStorage.getItem($t)!==`0`}catch{return!0}}function tn(e){try{localStorage.setItem($t,e?`1`:`0`)}catch{}}function nn(e){return e===``||e.startsWith(`/`)||e.startsWith(`\\`)||e.split(`/`).some(e=>e===``||e.startsWith(`.`))?null:e}function rn(e,t){let n=t.pathSeparator,r=e=>n===`\\`?e.replaceAll(`\\`,`/`):e,i=r(t.contentDir).replace(/\/$/,``),a=r(e);if(!a.startsWith(`${i}/`))return null;let o=a.slice(i.length+1),s=/\.(md|mdx)$/.exec(o);return s===null?null:nn(o.slice(0,-s[0].length))}var an=new Set(ne);function on(e,t,n){let r=me(e);if(r===null)return null;let{tool:i,args:a}=r;if(i===`delete`||i===null&&/\bdelete\b/i.test(t))return null;let o=typeof a.document==`object`&&a.document!==null?a.document:null,s=null;if(Array.isArray(a.documents))for(let e=a.documents.length-1;e>=0;e--){let t=a.documents[e];if(typeof t==`object`&&t){s=t;break}}let c=(o===null?null:P(o,`path`))??(s===null?null:P(s,`path`))??P(a,`to`);if(c!==null)return nn(c.replace(/\.(md|mdx)$/,``));let l=P(a,`docName`);return l===null||!(i!==null&&an.has(i))&&!(n===`edit`||n===`move`)?null:nn(l.replace(/\.(md|mdx)$/,``))}function sn(e,t){if(e.toolKind===`delete`)return null;let n=on(e.rawInput,e.title,e.toolKind);if(n!==null)return n;if(t===null||e.toolKind!==`edit`&&e.toolKind!==`move`)return null;for(let n=e.locations.length-1;n>=0;n--){let r=e.locations[n];if(r===void 0)continue;let i=rn(r.path,t);if(i!==null)return i}return null}var cn={lastFollowed:null,yielded:!1,reArmed:!1};function ln(e,t,n){if(e===null||n.lastFollowed===e)return{navigateTo:null,state:n};if(n.lastFollowed!==null&&t!==null&&t!==n.lastFollowed&&t!==e&&!n.reArmed)return{navigateTo:null,state:{...n,yielded:!0}};if(n.yielded&&!n.reArmed)return{navigateTo:null,state:n};let r={lastFollowed:e,yielded:!1,reArmed:!1};return t===e?{navigateTo:null,state:r}:{navigateTo:e,state:r}}function un(e,t){let n=null;for(let r of e){if(r.kind!==`tool_call`)continue;let e=sn(r,t);e!==null&&(n=e)}return n}function dn(e){let t=(0,Y.c)(16),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:n,value:o,max:i,indeterminateFillPercent:r,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s=typeof i==`number`&&i>0?i:100,l=typeof o==`number`&&o>=0&&o<=s?o/s*100:r??0,u=Math.min(100,Math.max(0,l)),d;t[6]===n?d=t[7]:(d=c(`relative flex h-1 w-full items-center overflow-x-hidden rounded-full bg-muted`,n),t[6]=n,t[7]=d);let f=`translateX(-${100-u}%)`,p;t[8]===f?p=t[9]:(p=(0,I.jsx)(xe,{"data-slot":`progress-indicator`,className:`size-full flex-1 bg-primary transition-all motion-reduce:transition-none`,style:{transform:f}}),t[8]=f,t[9]=p);let m;return t[10]!==i||t[11]!==a||t[12]!==d||t[13]!==p||t[14]!==o?(m=(0,I.jsx)(be,{"data-slot":`progress`,value:o,max:i,className:d,...a,children:p}),t[10]=i,t[11]=a,t[12]=d,t[13]=p,t[14]=o,t[15]=m):m=t[15],m}export{wt as C,Ae as D,ke as E,J as O,Nt as S,je as T,Tt as _,un as a,Et as b,tn as c,Gt as d,Vt as f,St as g,It as h,rn as i,Qt as l,Bt as m,cn as n,en as o,Ut as p,ln as r,nn as s,dn as t,Jt as u,At as v,Me as w,Ct as x,kt as y};
@@ -1,17 +0,0 @@
1
- import{i as e,o as t,t as n}from"./rolldown-runtime-tZXQYakl.mjs";import{Ad as r,Hu as i,Id as a,Md as o,Nd as s,Nl as c,Pd as l,ju as u}from"./md-manager-BGnqyqi1-DKflYxqj.mjs";import{$n as d,Io as f,Lo as p,Rn as m,So as h,Zi as g,jo as _,m as v,so as y,wn as ee}from"./dist-B5vmOfkB.mjs";import{A as b,L as te,M as x,N as ne,O as S,Q as re,T as ie,Y as C,ct as ae,d as oe,et as se,f as ce,it as le,j as ue,k as de,nt as fe,o as pe,q as me,rt as he,st as ge,tt as _e,ut as ve,v as ye,w as be,x as xe,y as Se}from"./init-DaLmOoJr.mjs";import{t as Ce}from"./is-object-BGze3w87.mjs";import{t as we}from"./removal-file-path-5pTgbCWb.mjs";import{spawn as Te}from"node:child_process";import{basename as w,dirname as T,join as E,resolve as D,win32 as Ee}from"node:path";import{accessSync as De,constants as O,existsSync as k,lstatSync as A,mkdirSync as Oe,readFileSync as j,readdirSync as M,realpathSync as N,rmSync as ke,rmdirSync as Ae,statSync as P,unlinkSync as je,writeFileSync as Me}from"node:fs";import{homedir as F}from"node:os";import{createHash as Ne}from"node:crypto";import{isDeepStrictEqual as Pe}from"node:util";import{setTimeout as Fe}from"node:timers/promises";var I=u();let Ie;function Le(){return Ie}function Re(e,t){if(t!==void 0&&t.length>0)return t;try{return d(e)?.rootPath}catch{return}}function ze(e){let t=Re(e.cwd,e.configuredProjectName),n=ee({name:`cli`,project:t});return Ie=n,n.info({command:e.command,cwd:e.cwd,project:t},`cli command started`),n}const L=`open-knowledge`;function R(e){try{e()}catch{}}var Be=class{backend=`keyring`;onKeychainRead;constructor(e){this.onKeychainRead=e}async get(e){let{Entry:t}=await import(`@napi-rs/keyring`),n;try{n=new t(L,e).getPassword()}catch(t){return R(()=>this.onKeychainRead?.({kind:`read-error`,host:e,error:t instanceof Error?t.name:`unknown`})),null}if(n==null)return R(()=>this.onKeychainRead?.({kind:`absent`,host:e})),null;try{return JSON.parse(n)}catch{return R(()=>this.onKeychainRead?.({kind:`corrupt-entry`,host:e,error:`corrupt-entry`})),null}}async set(e,t,n,r){let{Entry:i}=await import(`@napi-rs/keyring`),a=new i(L,e),o={login:t,token:n,...r};a.setPassword(JSON.stringify(o))}async clear(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{new t(L,e).deletePassword()}catch{}}},z=class{backend=`file`;authFile;constructor(e){this.authFile=e??E(F(),`.ok`,`auth.yml`)}read(){if(!k(this.authFile))return{};try{let e=j(this.authFile,`utf-8`);return(0,I.parse)(e)??{}}catch(e){let t=e instanceof Error?e.message:`unknown error`;return process.stderr.write(`[auth] Failed to parse ${this.authFile}: ${t}. Starting with empty credentials.\n`),{}}}write(e){let t=T(this.authFile);k(t)||Oe(t,{recursive:!0,mode:448}),Me(this.authFile,(0,I.stringify)(e),{mode:384})}async get(e){return this.read()[e]??null}async set(e,t,n,r){let i=this.read();i[e]={login:t,token:n,...r},this.write(i)}async clear(e){let t=this.read();delete t[e],this.write(t)}},Ve=class{backend=`keyring`;keychain;file;constructor(e,t){this.keychain=e,this.file=t}async get(e){let t=await this.keychain.get(e);if(t!=null)return t;let n=await this.file.get(e);if(n==null)return null;try{await this.keychain.set(e,n.login,n.token,{gitProtocol:n.gitProtocol,name:n.name,email:n.email}),await this.file.clear(e),process.stderr.write(`[auth] migrated ${e} credential from ~/.ok/auth.yml to the OS keychain\n`)}catch{}return n}set(e,t,n,r){return this.keychain.set(e,t,n,r)}async clear(e){await this.keychain.clear(e),await this.file.get(e)!=null&&await this.file.clear(e)}};async function He(e,t){try{let{Entry:n}=await import(`@napi-rs/keyring`);return new n(L,`__probe__`),process.stderr.write(`[auth] token storage: OS keychain
2
- `),R(()=>t?.onBackendSelected?.({backend:`keyring`})),new Ve(new Be(t?.onKeychainRead),new z(e))}catch(n){let r=n instanceof Error?`${n.name}: ${n.message}`:String(n);return process.stderr.write(`[auth] token storage: file (~/.ok/auth.yml) — OS keychain unavailable: ${r}\n`),R(()=>t?.onBackendSelected?.({backend:`file`,reason:r})),new z(e)}}function Ue(e){let t=null;return function(){if(t)return t;let n=2e3;return t=(async()=>{let t=null,r=new Promise(r=>{t=setTimeout(()=>{process.stderr.write(`[auth] token storage: keyring init exceeded ${n}ms; falling back to file (~/.ok/auth.yml)\n`),r(new z(e))},n)});try{return await Promise.race([He(e),r])}catch{return new z(e)}finally{t!==null&&clearTimeout(t)}})(),t}}function We(e){let t=Ue(e);return{async get(e){let n=await(await t()).get(e);return n===null?null:{token:n.token,login:n.login}}}}function Ge(e){let t=Ue(e);return{backend:`file`,async get(e){return(await t()).get(e)},async set(e,n,r,i){return(await t()).set(e,n,r,i)},async clear(e){return(await t()).clear(e)}}}async function Ke(e,t){let n=[],r=new z(t);await r.get(e)!=null&&(await r.clear(e),n.push(`file`));let i;try{let{Entry:t}=await import(`@napi-rs/keyring`);new t(L,`__probe__`);let r,a=await new Be(e=>{e.kind===`read-error`&&(r=e.error??`read-error`)}).get(e);if(r!==void 0)i=r;else if(a!=null)try{new t(L,e).deletePassword(),n.push(`keychain`)}catch(e){i=e instanceof Error?e.name:`delete-error`}}catch{}return{touched:n,keychainError:i}}function qe(e){let t={...e};return delete t.ELECTRON_RUN_AS_NODE,t}function Je(e){let t=e?.code;return t===`ENOENT`||t===`EACCES`||t===`EPERM`?{ok:!1,reason:`not-installed`}:{ok:!1,reason:`spawn-error`}}function Ye(e){return y({detached:!0,stdio:`ignore`,shell:!1,env:qe(e)})}function B(e,t,n={}){let r=(n.spawn??Te)(e,[...t],Ye(n.env??process.env));return r.unref(),r}function Xe(e,t,n={}){let r=n.spawn??Te,i=n.timeoutMs??2e3;return new Promise(a=>{let o=!1,s=e=>{o||(o=!0,a(e))},c=setTimeout(()=>s({ok:!1,reason:`timeout`}),i);try{let i=r(e,[...t],Ye(n.env??process.env));i.once(`error`,e=>{clearTimeout(c),s(Je(e))}),i.once(`spawn`,()=>{clearTimeout(c),s({ok:!0})});try{i.unref()}catch{}}catch(e){clearTimeout(c),s(Je(e))}})}const Ze=`com.inkeep.open-knowledge`,Qe=`OpenKnowledge.app`,$e=`/Applications/${Qe}`;function et(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return P(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function tt(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(nt(e,$e))return $e;let t=e.homeDir??F(),n=E(t,`Applications`,Qe);return nt(e,n)?n:null}function nt(e,t){return rt(e,E(t,`Contents`,`MacOS`,`OpenKnowledge`))}function rt(e,t){try{let n=e.statSync(t);return n?typeof n.isFile==`function`&&n.isFile():!1}catch{return!1}}const it=[`@inkeepopen-knowledge-desktop`,`OpenKnowledge`];function at(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`&&/\\OpenKnowledge\.exe$/i.test(e.execPath))return e.execPath;let t=e.env.LOCALAPPDATA;if(t)for(let n of it){let r=Ee.join(t,`Programs`,n,`OpenKnowledge.exe`);if(rt(e,r))return r}return null}function ot(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`&&e.execPath.endsWith(`/openknowledge`))return e.execPath;let t=`/opt/OpenKnowledge/openknowledge`;return rt(e,t)?t:null}function st(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`&&e.platform!==`win32`&&e.platform!==`linux`)return{available:!1,reason:`unsupported-platform`};let t;try{t=e.platform===`darwin`?tt(e):e.platform===`win32`?at(e):ot(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:!(e.isTTY===!0||e.platform===`win32`&&e.isTTY===void 0&&!e.env.CI)||e.env.SSH_CONNECTION||e.env.SSH_TTY||e.platform===`linux`&&!e.env.DISPLAY&&!e.env.WAYLAND_DISPLAY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function ct(e,t){let n=e.log??(e=>console.error(e)),r=e.platform??process.platform;if(n("Launching OpenKnowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)"),r===`darwin`){B(`open`,[`-b`,Ze],{spawn:e.spawn});return}let i=t?.bundlePath;if(!i){n(`Desktop launch skipped: no resolved desktop executable (caller bug).`);return}B(i,[],{spawn:e.spawn})}function lt(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found (checked the standard install locations for this OS). Install it from https://openknowledge.ai/download, or omit --mode for browser mode.`;case`darwin-only`:case`unsupported-platform`:return`Desktop app is not available on this platform. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect the desktop install (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available but launch dispatch did not fire (caller bug).`}}function V(e){return e.replace(/[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\u200b\ufeff]/gu,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function ut(e){return Ne(`sha256`).update(e).digest(`hex`)}function H(e){return E(D(e),`.ok`,`pi-trust`)}function U(e,t){return E(H(e),ut(D(t)))}function dt(e,t,n){return E(U(e,t),`${ut(n)}.json`)}var W=class extends Error{constructor(e,t,n,r){super(`Pi trust receipt at ${V(e)} ${V(t)}; ${V(n)}`,{cause:r}),this.name=`PiTrustReceiptError`}};function G(e,t,n){let r=n.code,i=n instanceof Error?n.message:String(n),a;switch(r){case`EACCES`:case`EPERM`:a=`check receipt and parent-directory permissions, then retry`;break;case`ENOENT`:a=`the location no longer exists; restore access to its expected location, then retry`;break;default:a=`check the path and available storage, then retry`}return new W(e,`could not ${t}: ${i}`,a,n)}function K(e){let t;try{t=A(e)}catch(t){if(t.code===`ENOENT`)return!1;throw G(e,`be inspected`,t)}if(!t.isDirectory())throw new W(e,`is not a regular directory`,`restore the intended receipt directory without a symlink, then retry`);return!0}function ft(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}function pt(e,t){if(!Ce(e)||!ft(e,[`version`,`cwd`,`configuredTrustPath`,`canonicalTrustPath`,`state`,`previous`])||e.version!==1||typeof e.cwd!=`string`||e.cwd!==D(e.cwd)||typeof e.configuredTrustPath!=`string`||e.configuredTrustPath!==D(e.configuredTrustPath)||typeof e.canonicalTrustPath!=`string`||e.canonicalTrustPath!==D(e.canonicalTrustPath)||e.state!==`pending`&&e.state!==`committed`||!Ce(e.previous))throw new W(t,`has invalid contents`,`restore a valid ownership record from a backup without guessing its trust decision, then retry`);let n;if(e.previous.present===!1&&ft(e.previous,[`present`]))n={present:!1};else if(e.previous.present===!0&&ft(e.previous,[`present`,`value`]))n={present:!0,value:e.previous.value};else throw new W(t,`has an invalid previous decision`,`restore the recorded previous decision from a backup without guessing its value, then retry`);return{version:1,cwd:e.cwd,configuredTrustPath:e.configuredTrustPath,canonicalTrustPath:e.canonicalTrustPath,state:e.state,previous:n}}function mt(e,t,n){let r;try{r=A(n)}catch(e){throw G(n,`be inspected`,e)}if(!r.isFile())throw new W(n,`is not a regular file`,`restore the intended receipt as a regular file without a symlink, then retry`);let i;try{i=j(n,`utf8`)}catch(e){throw G(n,`be read`,e)}let a;try{a=JSON.parse(i)}catch(e){throw new W(n,`is not valid JSON`,`repair its JSON syntax without changing the recorded decision, then retry`,e)}let o=pt(a,n);if(o.cwd!==D(t)||n!==dt(e,t,o.canonicalTrustPath))throw new W(n,`does not match its project or trust-store location`,`restore the ownership record to its original project and trust-store location, then retry`);return{path:n,record:o}}function ht(e,t){let{record:n,path:r}=t;for(let t of[H(e),U(e,n.cwd)])if(!K(t))throw new W(t,`no longer exists`,`restore access to the expected receipt directory, then retry`);let i=mt(e,n.cwd,r);if(!Pe(i.record,n))throw new W(r,`changed while its trust decision was being updated`,`retry to read its current ownership record`);return i}function gt(e,t,n,r,i){let a={version:1,cwd:D(t),configuredTrustPath:D(n),canonicalTrustPath:D(r),state:`pending`,previous:i},o=dt(e,a.cwd,a.canonicalTrustPath),s=`${JSON.stringify(a,null,2)}\n`;if(!Pe(pt(JSON.parse(s),o),a))throw new W(o,`cannot preserve the previous decision as JSON`,`provide the original decision as a JSON value before retrying`);K(H(e)),K(T(o));try{Oe(T(o),{recursive:!0,mode:448})}catch(e){throw G(T(o),`be created`,e)}let c;try{c=A(o,{throwIfNoEntry:!1})}catch(e){throw G(o,`be inspected`,e)}if(c)throw new W(o,`already exists`,`reconcile the existing ownership record before recording another grant`);try{_(o,s,{mode:384})}catch(e){throw G(o,`be written`,e)}return{path:o,record:a}}function _t(e,t){let n=ht(e,t);if(n.record.state!==`pending`)throw new W(n.path,`is already committed`,`use the current ownership record without committing it again`);let r={...n.record,state:`committed`};try{_(n.path,`${JSON.stringify(r,null,2)}\n`,{mode:384})}catch(e){throw G(n.path,`be committed`,e)}return{path:n.path,record:r}}function q(e,t){if(!K(H(e)))return[];let n=U(e,t);if(!K(n))return[];let r;try{r=M(n).sort()}catch(e){throw G(n,`be listed`,e)}return r.filter(e=>/^[a-f0-9]{64}\.json$/.test(e)).map(r=>mt(e,t,E(n,r)))}function J(e,t){let n=ht(e,t);try{je(n.path)}catch(e){throw G(n.path,`be removed after reconciling its grant`,e)}for(let t of[T(n.path),H(e)])try{Ae(t)}catch(e){let n=e.code;if(n!==`ENOTEMPTY`&&n!==`EEXIST`&&n!==`ENOENT`)throw G(t,`be removed after reconciling its grant`,e)}}var vt=n(((t,n)=>{var r=e(`constants`),i=process.cwd,a=null,o=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return a||=i.call(process),a};try{process.cwd()}catch{}if(typeof process.chdir==`function`){var s=process.chdir;process.chdir=function(e){a=null,s.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,s)}n.exports=c;function c(e){r.hasOwnProperty(`O_SYMLINK`)&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||n(e),e.chown=s(e.chown),e.fchown=s(e.fchown),e.lchown=s(e.lchown),e.chmod=i(e.chmod),e.fchmod=i(e.fchmod),e.lchmod=i(e.lchmod),e.chownSync=c(e.chownSync),e.fchownSync=c(e.fchownSync),e.lchownSync=c(e.lchownSync),e.chmodSync=a(e.chmodSync),e.fchmodSync=a(e.fchmodSync),e.lchmodSync=a(e.lchmodSync),e.stat=l(e.stat),e.fstat=l(e.fstat),e.lstat=l(e.lstat),e.statSync=u(e.statSync),e.fstatSync=u(e.fstatSync),e.lstatSync=u(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(e,t,n){n&&process.nextTick(n)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(e,t,n,r){r&&process.nextTick(r)},e.lchownSync=function(){}),o===`win32`&&(e.rename=typeof e.rename==`function`?(function(t){function n(n,r,i){var a=Date.now(),o=0;t(n,r,function s(c){if(c&&(c.code===`EACCES`||c.code===`EPERM`||c.code===`EBUSY`)&&Date.now()-a<6e4){setTimeout(function(){e.stat(r,function(e,a){e&&e.code===`ENOENT`?t(n,r,s):i(c)})},o),o<100&&(o+=10);return}i&&i(c)})}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n})(e.rename):e.rename),e.read=typeof e.read==`function`?(function(t){function n(n,r,i,a,o,s){var c;if(s&&typeof s==`function`){var l=0;c=function(u,d,f){if(u&&u.code===`EAGAIN`&&l<10)return l++,t.call(e,n,r,i,a,o,c);s.apply(this,arguments)}}return t.call(e,n,r,i,a,o,c)}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n})(e.read):e.read,e.readSync=typeof e.readSync==`function`?(function(t){return function(n,r,i,a,o){for(var s=0;;)try{return t.call(e,n,r,i,a,o)}catch(e){if(e.code===`EAGAIN`&&s<10){s++;continue}throw e}}})(e.readSync):e.readSync;function t(e){e.lchmod=function(t,n,i){e.open(t,r.O_WRONLY|r.O_SYMLINK,n,function(t,r){if(t){i&&i(t);return}e.fchmod(r,n,function(t){e.close(r,function(e){i&&i(t||e)})})})},e.lchmodSync=function(t,n){var i=e.openSync(t,r.O_WRONLY|r.O_SYMLINK,n),a=!0,o;try{o=e.fchmodSync(i,n),a=!1}finally{if(a)try{e.closeSync(i)}catch{}else e.closeSync(i)}return o}}function n(e){r.hasOwnProperty(`O_SYMLINK`)&&e.futimes?(e.lutimes=function(t,n,i,a){e.open(t,r.O_SYMLINK,function(t,r){if(t){a&&a(t);return}e.futimes(r,n,i,function(t){e.close(r,function(e){a&&a(t||e)})})})},e.lutimesSync=function(t,n,i){var a=e.openSync(t,r.O_SYMLINK),o,s=!0;try{o=e.futimesSync(a,n,i),s=!1}finally{if(s)try{e.closeSync(a)}catch{}else e.closeSync(a)}return o}):e.futimes&&(e.lutimes=function(e,t,n,r){r&&process.nextTick(r)},e.lutimesSync=function(){})}function i(t){return t&&function(n,r,i){return t.call(e,n,r,function(e){d(e)&&(e=null),i&&i.apply(this,arguments)})}}function a(t){return t&&function(n,r){try{return t.call(e,n,r)}catch(e){if(!d(e))throw e}}}function s(t){return t&&function(n,r,i,a){return t.call(e,n,r,i,function(e){d(e)&&(e=null),a&&a.apply(this,arguments)})}}function c(t){return t&&function(n,r,i){try{return t.call(e,n,r,i)}catch(e){if(!d(e))throw e}}}function l(t){return t&&function(n,r,i){typeof r==`function`&&(i=r,r=null);function a(e,t){t&&(t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296)),i&&i.apply(this,arguments)}return r?t.call(e,n,r,a):t.call(e,n,a)}}function u(t){return t&&function(n,r){var i=r?t.call(e,n,r):t.call(e,n);return i&&(i.uid<0&&(i.uid+=4294967296),i.gid<0&&(i.gid+=4294967296)),i}}function d(e){return!e||e.code===`ENOSYS`||(!process.getuid||process.getuid()!==0)&&(e.code===`EINVAL`||e.code===`EPERM`)}}})),yt=n(((t,n)=>{var r=e(`stream`).Stream;n.exports=i;function i(e){return{ReadStream:t,WriteStream:n};function t(n,i){if(!(this instanceof t))return new t(n,i);r.call(this);var a=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags=`r`,this.mode=438,this.bufferSize=65536,i||={};for(var o=Object.keys(i),s=0,c=o.length;s<c;s++){var l=o[s];this[l]=i[l]}if(this.encoding&&this.setEncoding(this.encoding),this.start!==void 0){if(typeof this.start!=`number`)throw TypeError(`start must be a Number`);if(this.end===void 0)this.end=1/0;else if(typeof this.end!=`number`)throw TypeError(`end must be a Number`);if(this.start>this.end)throw Error(`start must be <= end`);this.pos=this.start}if(this.fd!==null){process.nextTick(function(){a._read()});return}e.open(this.path,this.flags,this.mode,function(e,t){if(e){a.emit(`error`,e),a.readable=!1;return}a.fd=t,a.emit(`open`,t),a._read()})}function n(t,i){if(!(this instanceof n))return new n(t,i);r.call(this),this.path=t,this.fd=null,this.writable=!0,this.flags=`w`,this.encoding=`binary`,this.mode=438,this.bytesWritten=0,i||={};for(var a=Object.keys(i),o=0,s=a.length;o<s;o++){var c=a[o];this[c]=i[c]}if(this.start!==void 0){if(typeof this.start!=`number`)throw TypeError(`start must be a Number`);if(this.start<0)throw Error(`start must be >= zero`);this.pos=this.start}this.busy=!1,this._queue=[],this.fd===null&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}})),bt=n(((e,t)=>{t.exports=r;var n=Object.getPrototypeOf||function(e){return e.__proto__};function r(e){if(typeof e!=`object`||!e)return e;if(e instanceof Object)var t={__proto__:n(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}),t}})),xt=n(((t,n)=>{var r=e(`fs`),i=vt(),a=yt(),o=bt(),s=e(`util`),c,l;typeof Symbol==`function`&&typeof Symbol.for==`function`?(c=Symbol.for(`graceful-fs.queue`),l=Symbol.for(`graceful-fs.previous`)):(c=`___graceful-fs.queue`,l=`___graceful-fs.previous`);function u(){}function d(e,t){Object.defineProperty(e,c,{get:function(){return t}})}var f=u;s.debuglog?f=s.debuglog(`gfs4`):/\bgfs4\b/i.test(process.env.NODE_DEBUG||``)&&(f=function(){var e=s.format.apply(s,arguments);e=`GFS4: `+e.split(/\n/).join(`
3
- GFS4: `),console.error(e)}),r[c]||(d(r,global[c]||[]),r.close=(function(e){function t(t,n){return e.call(r,t,function(e){e||g(),typeof n==`function`&&n.apply(this,arguments)})}return Object.defineProperty(t,l,{value:e}),t})(r.close),r.closeSync=(function(e){function t(t){e.apply(r,arguments),g()}return Object.defineProperty(t,l,{value:e}),t})(r.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||``)&&process.on(`exit`,function(){f(r[c]),e(`assert`).equal(r[c].length,0)})),global[c]||d(global,r[c]),n.exports=p(o(r)),process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!r.__patched&&(n.exports=p(r),r.__patched=!0);function p(e){i(e),e.gracefulify=p,e.createReadStream=S,e.createWriteStream=re;var t=e.readFile;e.readFile=n;function n(e,n,r){return typeof n==`function`&&(r=n,n=null),i(e,n,r);function i(e,n,r,a){return t(e,n,function(t){t&&(t.code===`EMFILE`||t.code===`ENFILE`)?m([i,[e,n,r],t,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var r=e.writeFile;e.writeFile=o;function o(e,t,n,i){return typeof n==`function`&&(i=n,n=null),a(e,t,n,i);function a(e,t,n,i,o){return r(e,t,n,function(r){r&&(r.code===`EMFILE`||r.code===`ENFILE`)?m([a,[e,t,n,i],r,o||Date.now(),Date.now()]):typeof i==`function`&&i.apply(this,arguments)})}}var s=e.appendFile;s&&(e.appendFile=c);function c(e,t,n,r){return typeof n==`function`&&(r=n,n=null),i(e,t,n,r);function i(e,t,n,r,a){return s(e,t,n,function(o){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var l=e.copyFile;l&&(e.copyFile=u);function u(e,t,n,r){return typeof n==`function`&&(r=n,n=0),i(e,t,n,r);function i(e,t,n,r,a){return l(e,t,n,function(o){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var d=e.readdir;e.readdir=h;var f=/^v[0-5]\./;function h(e,t,n){typeof t==`function`&&(n=t,t=null);var r=f.test(process.version)?function(e,t,n,r){return d(e,i(e,t,n,r))}:function(e,t,n,r){return d(e,t,i(e,t,n,r))};return r(e,t,n);function i(e,t,n,i){return function(a,o){a&&(a.code===`EMFILE`||a.code===`ENFILE`)?m([r,[e,t,n],a,i||Date.now(),Date.now()]):(o&&o.sort&&o.sort(),typeof n==`function`&&n.call(this,a,o))}}}if(process.version.substr(0,4)===`v0.8`){var g=a(e);b=g.ReadStream,x=g.WriteStream}var _=e.ReadStream;_&&(b.prototype=Object.create(_.prototype),b.prototype.open=te);var v=e.WriteStream;v&&(x.prototype=Object.create(v.prototype),x.prototype.open=ne),Object.defineProperty(e,"ReadStream",{get:function(){return b},set:function(e){b=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return x},set:function(e){x=e},enumerable:!0,configurable:!0});var y=b;Object.defineProperty(e,"FileReadStream",{get:function(){return y},set:function(e){y=e},enumerable:!0,configurable:!0});var ee=x;Object.defineProperty(e,"FileWriteStream",{get:function(){return ee},set:function(e){ee=e},enumerable:!0,configurable:!0});function b(e,t){return this instanceof b?(_.apply(this,arguments),this):b.apply(Object.create(b.prototype),arguments)}function te(){var e=this;C(e.path,e.flags,e.mode,function(t,n){t?(e.autoClose&&e.destroy(),e.emit(`error`,t)):(e.fd=n,e.emit(`open`,n),e.read())})}function x(e,t){return this instanceof x?(v.apply(this,arguments),this):x.apply(Object.create(x.prototype),arguments)}function ne(){var e=this;C(e.path,e.flags,e.mode,function(t,n){t?(e.destroy(),e.emit(`error`,t)):(e.fd=n,e.emit(`open`,n))})}function S(t,n){return new e.ReadStream(t,n)}function re(t,n){return new e.WriteStream(t,n)}var ie=e.open;e.open=C;function C(e,t,n,r){return typeof n==`function`&&(r=n,n=null),i(e,t,n,r);function i(e,t,n,r,a){return ie(e,t,n,function(o,s){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}return e}function m(e){f(`ENQUEUE`,e[0].name,e[1]),r[c].push(e),_()}var h;function g(){for(var e=Date.now(),t=0;t<r[c].length;++t)r[c][t].length>2&&(r[c][t][3]=e,r[c][t][4]=e);_()}function _(){if(clearTimeout(h),h=void 0,r[c].length!==0){var e=r[c].shift(),t=e[0],n=e[1],i=e[2],a=e[3],o=e[4];if(a===void 0)f(`RETRY`,t.name,n),t.apply(null,n);else if(Date.now()-a>=6e4){f(`TIMEOUT`,t.name,n);var s=n.pop();typeof s==`function`&&s.call(null,i)}else{var l=Date.now()-o,u=Math.max(o-a,1);l>=Math.min(u*1.2,100)?(f(`RETRY`,t.name,n),t.apply(null,n.concat([a]))):r[c].push(e)}h===void 0&&(h=setTimeout(_,0))}}})),St=n(((e,t)=>{function n(e,t){typeof t==`boolean`&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}t.exports=n,n.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},n.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null},n.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(Error(`RetryOperation timeout occurred`)),!1;this._errors.push(e);var n=this._timeouts.shift();if(n===void 0){if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),n=this._timeouts.shift();else return!1}var r=this,i=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},n);return this._options.unref&&i.unref(),!0},n.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)},n.prototype.try=function(e){console.log(`Using RetryOperation.try() is deprecated`),this.attempt(e)},n.prototype.start=function(e){console.log(`Using RetryOperation.start() is deprecated`),this.attempt(e)},n.prototype.start=n.prototype.try,n.prototype.errors=function(){return this._errors},n.prototype.attempts=function(){return this._attempts},n.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var i=this._errors[r],a=i.message,o=(e[a]||0)+1;e[a]=o,o>=n&&(t=i,n=o)}return t}})),Ct=n((e=>{var t=St();e.operation=function(n){return new t(e.timeouts(n),{forever:n&&n.forever,unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw Error(`minTimeout is greater than maxTimeout`);for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(e,t){return e-t}),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*t.minTimeout*t.factor**+e);return r=Math.min(r,t.maxTimeout),r},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var i in r=[],t)typeof t[i]==`function`&&r.push(i);for(var a=0;a<r.length;a++){var o=r[a],s=t[o];t[o]=function(r){var i=e.operation(n),a=Array.prototype.slice.call(arguments,1),o=a.pop();a.push(function(e){i.retry(e)||(e&&(arguments[0]=i.mainError()),o.apply(this,arguments))}),i.attempt(function(){r.apply(t,a)})}.bind(t,s),t[o].options=n}}})),wt=n(((e,t)=>{t.exports=Ct()})),Tt=n(((e,t)=>{t.exports=[`SIGABRT`,`SIGALRM`,`SIGHUP`,`SIGINT`,`SIGTERM`],process.platform!==`win32`&&t.exports.push(`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),process.platform===`linux`&&t.exports.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`,`SIGUNUSED`)})),Et=n(((t,n)=>{var r=global.process;let i=function(e){return e&&typeof e==`object`&&typeof e.removeListener==`function`&&typeof e.emit==`function`&&typeof e.reallyExit==`function`&&typeof e.listeners==`function`&&typeof e.kill==`function`&&typeof e.pid==`number`&&typeof e.on==`function`};if(!i(r))n.exports=function(){return function(){}};else{var a=e(`assert`),o=Tt(),s=/^win/i.test(r.platform),c=e(`events`);typeof c!=`function`&&(c=c.EventEmitter);var l;r.__signal_exit_emitter__?l=r.__signal_exit_emitter__:(l=r.__signal_exit_emitter__=new c,l.count=0,l.emitted={}),l.infinite||(l.setMaxListeners(1/0),l.infinite=!0),n.exports=function(e,t){if(!i(global.process))return function(){};a.equal(typeof e,`function`,`a callback must be provided for exit handler`),p===!1&&m();var n=`exit`;return t&&t.alwaysLast&&(n=`afterexit`),l.on(n,e),function(){l.removeListener(n,e),l.listeners(`exit`).length===0&&l.listeners(`afterexit`).length===0&&u()}};var u=function(){!p||!i(global.process)||(p=!1,o.forEach(function(e){try{r.removeListener(e,f[e])}catch{}}),r.emit=_,r.reallyExit=h,--l.count)};n.exports.unload=u;var d=function(e,t,n){l.emitted[e]||(l.emitted[e]=!0,l.emit(e,t,n))},f={};o.forEach(function(e){f[e]=function(){i(global.process)&&r.listeners(e).length===l.count&&(u(),d(`exit`,null,e),d(`afterexit`,null,e),s&&e===`SIGHUP`&&(e=`SIGINT`),r.kill(r.pid,e))}}),n.exports.signals=function(){return o};var p=!1,m=function(){p||!i(global.process)||(p=!0,l.count+=1,o=o.filter(function(e){try{return r.on(e,f[e]),!0}catch{return!1}}),r.emit=v,r.reallyExit=g)};n.exports.load=m;var h=r.reallyExit,g=function(e){i(global.process)&&(r.exitCode=e||0,d(`exit`,r.exitCode,null),d(`afterexit`,r.exitCode,null),h.call(r,r.exitCode))},_=r.emit,v=function(e,t){if(e===`exit`&&i(global.process)){t!==void 0&&(r.exitCode=t);var n=_.apply(this,arguments);return d(`exit`,r.exitCode,null),d(`afterexit`,r.exitCode,null),n}return _.apply(this,arguments)}}})),Dt=n(((e,t)=>{let n=Symbol();function r(e,t,r){let i=t[n];if(i)return t.stat(e,(e,t)=>{if(e)return r(e);r(null,t.mtime,i)});let a=new Date(Math.ceil(Date.now()/1e3)*1e3+5);t.utimes(e,a,a,i=>{if(i)return r(i);t.stat(e,(e,i)=>{if(e)return r(e);let a=i.mtime.getTime()%1e3==0?`s`:`ms`;Object.defineProperty(t,n,{value:a}),r(null,i.mtime,a)})})}function i(e){let t=Date.now();return e===`s`&&(t=Math.ceil(t/1e3)*1e3),new Date(t)}t.exports.probe=r,t.exports.getMtime=i})),Ot=n(((t,n)=>{let r=e(`path`),i=xt(),a=wt(),o=Et(),s=Dt(),c={};function l(e,t){return t.lockfilePath||`${e}.lock`}function u(e,t,n){if(!t.realpath)return n(null,r.resolve(e));t.fs.realpath(e,n)}function d(e,t,n){let r=l(e,t);t.fs.mkdir(r,i=>{if(!i)return s.probe(r,t.fs,(e,i,a)=>{if(e)return t.fs.rmdir(r,()=>{}),n(e);n(null,i,a)});if(i.code!==`EEXIST`)return n(i);if(t.stale<=0)return n(Object.assign(Error(`Lock file is already being held`),{code:`ELOCKED`,file:e}));t.fs.stat(r,(r,i)=>{if(r)return r.code===`ENOENT`?d(e,{...t,stale:0},n):n(r);if(!f(i,t))return n(Object.assign(Error(`Lock file is already being held`),{code:`ELOCKED`,file:e}));p(e,t,r=>{if(r)return n(r);d(e,{...t,stale:0},n)})})})}function f(e,t){return e.mtime.getTime()<Date.now()-t.stale}function p(e,t,n){t.fs.rmdir(l(e,t),e=>{if(e&&e.code!==`ENOENT`)return n(e);n()})}function m(e,t){let n=c[e];n.updateTimeout||(n.updateDelay=n.updateDelay||t.update,n.updateTimeout=setTimeout(()=>{n.updateTimeout=null,t.fs.stat(n.lockfilePath,(r,i)=>{let a=n.lastUpdate+t.stale<Date.now();if(r)return r.code===`ENOENT`||a?h(e,n,Object.assign(r,{code:`ECOMPROMISED`})):(n.updateDelay=1e3,m(e,t));if(n.mtime.getTime()!==i.mtime.getTime())return h(e,n,Object.assign(Error(`Unable to update lock within the stale threshold`),{code:`ECOMPROMISED`}));let o=s.getMtime(n.mtimePrecision);t.fs.utimes(n.lockfilePath,o,o,r=>{let i=n.lastUpdate+t.stale<Date.now();if(!n.released){if(r)return r.code===`ENOENT`||i?h(e,n,Object.assign(r,{code:`ECOMPROMISED`})):(n.updateDelay=1e3,m(e,t));n.mtime=o,n.lastUpdate=Date.now(),n.updateDelay=null,m(e,t)}})})},n.updateDelay),n.updateTimeout.unref&&n.updateTimeout.unref())}function h(e,t,n){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),c[e]===t&&delete c[e],t.options.onCompromised(n)}function g(e,t,n){t={stale:1e4,update:null,realpath:!0,retries:0,fs:i,onCompromised:e=>{throw e},...t},t.retries=t.retries||0,t.retries=typeof t.retries==`number`?{retries:t.retries}:t.retries,t.stale=Math.max(t.stale||0,2e3),t.update=t.update==null?t.stale/2:t.update||0,t.update=Math.max(Math.min(t.update,t.stale/2),1e3),u(e,t,(e,r)=>{if(e)return n(e);let i=a.operation(t.retries);i.attempt(()=>{d(r,t,(e,a,o)=>{if(i.retry(e))return;if(e)return n(i.mainError());let s=c[r]={lockfilePath:l(r,t),mtime:a,mtimePrecision:o,options:t,lastUpdate:Date.now()};m(r,t),n(null,e=>{if(s.released)return e&&e(Object.assign(Error(`Lock is already released`),{code:`ERELEASED`}));_(r,{...t,realpath:!1},e)})})})})}function _(e,t,n){t={fs:i,realpath:!0,...t},u(e,t,(e,r)=>{if(e)return n(e);let i=c[r];if(!i)return n(Object.assign(Error(`Lock is not acquired/owned by you`),{code:`ENOTACQUIRED`}));i.updateTimeout&&clearTimeout(i.updateTimeout),i.released=!0,delete c[r],p(r,t,n)})}function v(e,t,n){t={stale:1e4,realpath:!0,fs:i,...t},t.stale=Math.max(t.stale||0,2e3),u(e,t,(e,r)=>{if(e)return n(e);t.fs.stat(l(r,t),(e,r)=>e?e.code===`ENOENT`?n(null,!1):n(e):n(null,!f(r,t)))})}function y(){return c}o(()=>{for(let e in c){let t=c[e].options;try{t.fs.rmdirSync(l(e,t))}catch{}}}),n.exports.lock=g,n.exports.unlock=_,n.exports.check=v,n.exports.getLocks=y})),kt=n(((e,t)=>{let n=xt();function r(e){let t=[`mkdir`,`realpath`,`stat`,`rmdir`,`utimes`],n={...e};return t.forEach(t=>{n[t]=(...n)=>{let r=n.pop(),i;try{i=e[`${t}Sync`](...n)}catch(e){return r(e)}r(null,i)}}),n}function i(e){return(...t)=>new Promise((n,r)=>{t.push((e,t)=>{e?r(e):n(t)}),e(...t)})}function a(e){return(...t)=>{let n,r;if(t.push((e,t)=>{n=e,r=t}),e(...t),n)throw n;return r}}function o(e){if(e={...e},e.fs=r(e.fs||n),typeof e.retries==`number`&&e.retries>0||e.retries&&typeof e.retries.retries==`number`&&e.retries.retries>0)throw Object.assign(Error(`Cannot use retries with the sync api`),{code:`ESYNC`});return e}t.exports={toPromise:i,toSync:a,toSyncOptions:o}})),At=t(n(((e,t)=>{let n=Ot(),{toPromise:r,toSync:i,toSyncOptions:a}=kt();async function o(e,t){let i=await r(n.lock)(e,t);return r(i)}function s(e,t){let r=i(n.lock)(e,a(t));return i(r)}function c(e,t){return r(n.unlock)(e,t)}function l(e,t){return i(n.unlock)(e,a(t))}function u(e,t){return r(n.check)(e,t)}function d(e,t){return i(n.check)(e,a(t))}t.exports=o,t.exports.lock=o,t.exports.unlock=c,t.exports.lockSync=s,t.exports.unlockSync=l,t.exports.check=u,t.exports.checkSync=d}))(),1);const jt=5e3;function Mt(e,t,n){if(!(e instanceof Error)||!(`code`in e)||e.code!==`ELOCKED`)throw e;let r=t-performance.now();if(r<=0)throw Object.assign(Error(`Could not acquire Pi trust lock at ${n}.lock within ${jt}ms`,{cause:e}),{code:`ELOCKED`});return Math.min(25,r)}function Nt(e,t){Le()?.warn(t,e)}function Pt(e,t){if(e.length===0)return;if(e.length===1)throw e[0];let[n,r]=e,i=n instanceof Error?n.message:String(n),a=r instanceof Error?r.message:String(r);throw AggregateError(e,`Pi trust update failed: ${i}\nReleasing Pi trust lock ${t}.lock also failed: ${a}`)}async function Ft(e,t,n){await f(`${t}.ok.lock`,async()=>{let t=performance.now()+jt,r;for(;;)try{r=await At.default.lock(T(e),{realpath:!1,lockfilePath:`${e}.lock`});break}catch(n){await Fe(Mt(n,t,e))}let i=[];try{n()}catch(e){i.push(e)}finally{try{await r()}catch(e){i.push(e)}}Pt(i,e)},{onWarn:Nt})}function It(e,t,n){p(`${t}.ok.lock`,()=>{let t=performance.now()+jt,r=new Int32Array(new SharedArrayBuffer(4)),i;for(;;)try{i=At.default.lockSync(T(e),{realpath:!1,lockfilePath:`${e}.lock`});break}catch(n){Atomics.wait(r,0,0,Mt(n,t,e))}let a=[];try{n()}catch(e){a.push(e)}finally{try{i()}catch(e){a.push(e)}}Pt(a,e)},{onWarn:Nt})}const Lt=[`settings.json`,`prompts`,`themes`,`SYSTEM.md`,`APPEND_SYSTEM.md`];var Rt=class extends Error{name=`PiResourceInspectionError`};function Y(e){let t;try{t=A(e)}catch(e){if(e.code===`ENOENT`)return!1;throw e}let n;try{n=P(e)}catch(e){throw t.isSymbolicLink()&&e.code===`ENOENT`?new Rt(ue(`missing-symlink-target`),{cause:e}):e}return De(e,O.R_OK|(n.isDirectory()?O.X_OK:0)),!0}function zt(e){return e===`open-knowledge`||e.startsWith(`open-knowledge-`)}function Bt(e,t,n){let r=e;try{let i=N(e),a;r=t;try{a=N(t)}catch(e){if(e.code!==`ENOENT`)throw e;a=D(t)}let o=E(a,`.agents`,`skills`),s=[];for(let e of Lt)r=E(i,`.pi`,e),Y(r)&&s.push(r);if(r=E(i,`.pi`,`extensions`),Y(r))for(let t of M(r).sort()){let i=E(r,t);D(n)!==E(D(e),`.pi`,`extensions`,t)&&s.push(i)}for(let e of[E(i,`.pi`,`skills`),E(i,`.agents`,`skills`)])if(e!==o&&(r=e,Y(e)))for(let t of M(e).sort())zt(t)||s.push(E(e,t));let c=T(i);for(;c!==i;){r=E(c,`.agents`,`skills`),r!==o&&Y(r)&&s.push(r);let e=T(c);if(e===c)break;c=e}return s.length===0?{kind:`none`}:{kind:`shared`,paths:s.sort()}}catch(e){return{kind:`unreadable`,error:`Could not inspect Pi project resources at ${V(r)}: ${e instanceof Rt?e.message:ue(x(e))}`}}}function Vt(e,t,n){let r=D(e),i=ge({home:t,env:n??(t===void 0?process.env:{})});return{cwd:r,bridgePath:C.pi.projectConfigPath(r),trustPath:E(i,`trust.json`)}}function X(e){try{let t=N(e);return P(t).isDirectory()?(De(t,O.X_OK),{kind:`ready`,project:{path:e,canonical:t}}):{kind:`refused`,error:`Pi project path ${V(e)} is not a directory; restore the intended project directory, then retry`}}catch(t){return{kind:`refused`,error:`Pi project directory ${V(e)} could not be resolved or accessed: ${V(t instanceof Error?t.message:String(t))}; restore the directory or symlink and check its permissions, then retry`}}}function Ht(e){let t=X(e.path);if(t.kind===`refused`)return t.error;if(t.project.canonical!==e.canonical)return`Pi project path ${V(e.path)} changed while waiting for its trust lock; restore the intended project location, then retry`}function Ut(e,t,n){let r=pe(C.pi,e,n,t);if(r.kind===`absent`)return{state:`absent`,text:null};if(r.kind!==`present`)return{state:`unreadable`,text:null};let i=r.entry,a=Array.isArray(i.args)&&typeof i.args[0]==`string`?i.args[0]:null;return fe(i)?{state:`own-current`,text:a}:ie(i)?{state:`own-stale`,text:a}:{state:`foreign`,text:a}}function Wt(e,t){let n;try{n=j(e.path,`utf-8`)}catch(t){let n=t.code;return e.kind===`missing`&&n===`ENOENT`?{state:`untrusted`,entries:{},trailingNewline:!1}:{state:`unreadable`,reason:x(t)}}if(n.trim()===``)return{state:`untrusted`,entries:{},trailingNewline:!1};let r;try{r=JSON.parse(n)}catch{return{state:`unreadable`,reason:`invalid-json`}}return Ce(r)?{state:r[t]===!0?`trusted`:`untrusted`,entries:r,trailingNewline:n.endsWith(`
4
- `)}:{state:`unreadable`,reason:`invalid-json`}}function Gt(e){switch(e){case`invalid-json`:return`the file is not a valid JSON object; repair its JSON, then retry`;case`path-changed`:return`the path changed while waiting for its lock; retry to check its current state`;case`unavailable-root`:return`the filesystem root is unavailable; reconnect the drive or network share, then retry`;default:return ue(e)}}function Z(e,t){return{kind:`refused`,error:`trust store ${V(e)}: ${Gt(t)}`}}function Q(e){let t=we(e);try{switch(t.kind){case`declined`:return Z(e,t.reason);case`ready`:return{kind:`ready`,path:N(t.path)};case`not-present`:break;default:throw Error(`unhandled trust file resolution: ${t}`)}let n=T(e),r=[w(e)],i=A(n,{throwIfNoEntry:!1});for(;!i;){let t=T(n);if(t===n)return Z(e,`unavailable-root`);r.unshift(w(n)),n=t,i=A(n,{throwIfNoEntry:!1})}try{return{kind:`missing`,path:E(N(n),...r)}}catch(t){return Z(e,i.isSymbolicLink()&&t.code===`ENOENT`?`missing-symlink-target`:x(t))}}catch(t){return Z(e,x(t))}}function Kt(e,t){let n=Q(e);return n.kind===`refused`?n:n.path!==t.path||t.kind===`ready`&&n.kind===`missing`?Z(e,`path-changed`):n}function qt(e,t,n){let r=Vt(e,t,n),i=X(r.cwd);if(i.kind===`refused`)return{...r,project:`unavailable`,error:i.error};let a=Ut(r.cwd,r.bridgePath,t).state,o=Q(r.trustPath),s=o.kind===`refused`?`unreadable`:o.kind===`missing`?`untrusted`:Wt(o,i.project.canonical).state;return{...r,project:`ready`,canonicalCwd:i.project.canonical,bridge:a,trust:s,bridgeLoadable:(a===`own-current`||a===`own-stale`)&&s===`trusted`,otherExtensions:Jt(r.bridgePath).displayNames}}function Jt(e){let t=T(e),n=w(e);try{return{displayNames:M(t).filter(e=>e!==n&&e.endsWith(`.ts`)).sort().map(e=>V(JSON.stringify(e)))}}catch{return{displayNames:[]}}}async function Yt(e,t={mode:`published`},n,r,i){let a=Vt(e,n,r),o=X(a.cwd);if(o.kind===`refused`)return{...a,ok:!1,bridge:`refused-project-path`,trust:`skipped`,error:o.error};if(i!==void 0&&o.project.canonical!==i)return{...a,ok:!1,bridge:`refused-project-path`,trust:`skipped`,error:`The approved Pi project directory ${V(i)} no longer matches the current directory ${V(o.project.canonical)}. Reopen the intended project and approve the Pi integration again; no bridge or trust settings were changed.`};let s=Ut(a.cwd,a.bridgePath,n);if(s.state===`foreign`)return{...a,ok:!1,bridge:`refused-foreign`,trust:`skipped`};if(s.state===`unreadable`)return{...a,ok:!1,bridge:`refused-unreadable`,trust:`skipped`};let c;if(s.state===`absent`)c=`written`;else{let e;try{e=be(t)}catch{e=void 0}c=e!==void 0&&s.text===e?`unchanged`:`refreshed`}if(c!==`unchanged`){let e=Se(C.pi,a.cwd,t,n,a.bridgePath);if(e.action!==`written`&&e.action!==`overwritten`)return{...a,ok:!1,bridge:`failed`,trust:`skipped`,error:e.error===void 0?`bridge write ${e.action}`:V(e.error)}}let l=await Xt(a.trustPath,o.project,n??F());return{...a,ok:l.action===`already-trusted`||l.action===`added`,bridge:c,trust:l.action,...l.error===void 0?{}:{error:l.error}}}async function Xt(e,t,n){let r=t.canonical,i=Q(e);if(i.kind===`refused`)return{action:`refused-unreadable`,error:i.error};try{Oe(T(i.path),{recursive:!0})}catch(e){return{action:`failed`,error:V(e instanceof Error?e.message:String(e))}}let a={action:`added`};try{await Ft(e,i.path,()=>{let o=Ht(t);if(o){a.action=`refused-unreadable`,a.error=o;return}let s=Kt(e,i);if(s.kind===`refused`){a.action=`refused-unreadable`,a.error=s.error;return}let c=Wt(s,r);if(c.state===`trusted`){a.action=`already-trusted`;return}if(c.state===`unreadable`){a.action=`refused-unreadable`,a.error=Z(e,c.reason).error;return}let l=$(n,()=>{let t=q(n,r).find(e=>e.record.canonicalTrustPath===s.path);return t&&J(n,t),gt(n,r,e,s.path,Object.hasOwn(c.entries,r)?{present:!0,value:c.entries[r]}:{present:!1})}),u={...c.entries,[r]:!0},d=JSON.stringify(u,null,2)+(c.trailingNewline?`
5
- `:``),f=S(s.path);_(s.path,d,f===void 0?void 0:{mode:f}),$(n,()=>_t(n,l)),a.action=`added`})}catch(e){return{action:`failed`,error:V(e instanceof Error?e.message:String(e))}}return a}function Zt(e){let t=[],n=e;try{for(;;){if(A(n,{throwIfNoEntry:!1})){if(t.length===0)return;let e=N(n);return P(e).isDirectory()?(De(e,O.X_OK),E(e,...t)):void 0}let e=T(n);if(e===n)return;t.unshift(w(n)),n=e}}catch{return}}function Qt(e){let t={"not-present":0,removed:1,"kept-unowned":2,"kept-shared":3,"kept-unverified":4,"refused-unreadable":5,failed:6},n=e.reduce((e,n)=>t[n.action]>t[e.action]?n:e,{action:`not-present`}),r=e.flatMap(e=>e.error??[]),i=e.flatMap(e=>e.detail??[]);return r.length>0?{action:n.error===void 0?`failed`:n.action,error:[...r,...i].join(`
6
- `)}:n.detail===void 0?n:{...n,detail:i.join(`
7
- `)}}function $t(e,t,n,r={}){let i=Vt(e,t,n),a=t??F(),o=X(i.cwd),s=o.kind===`refused`&&r.recordedOnly?Zt(i.cwd):void 0,c=o.kind===`ready`?o.project.canonical:s,l;try{l=$(a,()=>{let e=q(a,i.cwd);return c===void 0||c===i.cwd?e:[...q(a,c),...e]})}catch(e){return{action:`failed`,error:V(e instanceof Error?e.message:String(e))}}if(l.length===0&&r.recordedOnly)return o.kind===`ready`||s!==void 0?{action:`not-present`}:{action:`kept-unverified`,error:`${o.error}. OpenKnowledge could not verify whether this path refers to a project with recorded Pi trust; cleanup was left pending. Retry once the project path can be resolved to check again.`};if(o.kind===`refused`){if(l.length===0)return{action:`kept-unverified`,error:o.error};let e=l.map(({path:e,record:t})=>`key ${V(JSON.stringify(t.cwd))}; configured store ${V(JSON.stringify(t.configuredTrustPath))}; recorded destination ${V(JSON.stringify(t.canonicalTrustPath))}; ownership record ${V(JSON.stringify(e))} (${t.state})`);return{action:`kept-unverified`,error:[`${o.error}. OpenKnowledge kept these Pi trust ownership records; current trust decisions were not checked:`,...e,`To review manually, close Pi, verify the intended store against its recorded destination, and inspect only the exact key. A pending record does not prove setup completed or ownership of a current grant. If you choose to undo a current true decision, restore the recorded previous value, or remove that key only when no previous entry was recorded. Preserve other current decisions; parent-folder and global trust settings still apply.`].join(`
8
- `)}}let u=Bt(o.project.canonical,a,C.pi.projectConfigPath(o.project.canonical));if(u.kind===`unreadable`)return{action:`kept-unverified`,error:u.error};let d=u.kind===`shared`?u.paths:[],f=[],p=new Map,m=(e,t)=>{let n=p.get(e);if(!n){let t=Q(e);if(t.kind===`refused`){f.push({action:`refused-unreadable`,error:t.error});return}n={trustPath:e,resolved:t,keys:new Map},p.set(e,n)}if(t){if(n.resolved.path!==t.record.canonicalTrustPath){f.push({action:`refused-unreadable`,error:`Pi trust store ${V(e)} no longer points to its recorded destination ${V(t.record.canonicalTrustPath)}; restore the intended file location or symlink, then retry`});return}n.keys.set(t.record.cwd,{cwd:t.record.cwd,mode:`recorded`,receipt:t})}};for(let e of l)m(e.record.configuredTrustPath,e);m(i.trustPath);for(let e of p.values()){for(let t of[o.project.canonical,i.cwd])e.keys.has(t)||e.keys.set(t,{cwd:t,mode:`inspect`,receipt:l.find(n=>n.record.cwd===t&&n.record.canonicalTrustPath===e.resolved.path)});f.push(en(e,a,d,o.project))}return Qt(f)}function $(e,t){try{return t()}catch(t){throw t instanceof W?t:Error(`Could not access OpenKnowledge's Pi trust ownership records at ${V(E(e,`.ok`,`pi-trust`))}: ${V(t instanceof Error?t.message:String(t))}. Check the records and their permissions, then retry.`,{cause:t})}}function en(e,t,n,r){let{trustPath:i,resolved:a}=e,o=[...e.keys.values()];if(!o.some(e=>e.mode===`recorded`)&&a.kind===`missing`)return{action:`not-present`};if(a.kind===`missing`)try{A(T(a.path))}catch(e){return{action:`failed`,error:`The recorded Pi trust directory ${V(T(a.path))} is unavailable: ${V(e instanceof Error?e.message:String(e))}. Restore access to its parent directory or mounted drive, then retry; the ownership record was kept.`}}let s=[],c={result:{action:`not-present`}};try{It(i,a.path,()=>{let e=Ht(r);if(e){c.result={action:`kept-unverified`,error:e};return}let l=Kt(i,a);if(l.kind===`refused`){c.result={action:`refused-unreadable`,error:l.error};return}let u=Wt(l,r.canonical);if(u.state===`unreadable`){c.result={action:`refused-unreadable`,error:Z(i,u.reason).error};return}let d=o.map(e=>({cwd:e.cwd,mode:e.mode,expectedConfiguredPath:e.receipt?.record.configuredTrustPath,receipt:$(t,()=>q(t,e.cwd).find(e=>e.record.canonicalTrustPath===l.path))}));if(d.some(e=>e.receipt&&e.receipt.record.configuredTrustPath!==e.expectedConfiguredPath)){c.result={action:`failed`,error:`The Pi trust ownership record changed during cleanup; retry to read its current location.`};return}for(let e of d){try{tn(e,t,i,l.path,u,n,r,c)}catch(t){let n=V(t instanceof Error?t.message:String(t)),r=t instanceof W?``:`; retry to check its current state.`;s.push({action:`failed`,error:`Pi trust entry ${V(JSON.stringify(e.cwd))} in ${V(i)} could not be reconciled: ${n}${r}`})}s.push(c.result),c.result={action:`not-present`}}})}catch(e){s.push({action:`failed`,error:V(e instanceof Error?e.message:String(e))})}return Qt([...s,c.result])}function tn(e,t,n,r,i,a,o,s){let{cwd:c,receipt:l}=e;if(i.entries[c]!==!0){l&&e.mode===`recorded`&&$(t,()=>J(t,l)),s.result={action:`not-present`};return}let u=`To remove this grant manually, close Pi and remove only the ${V(JSON.stringify(c))} entry from ${V(n)}; parent-folder and global trust settings still apply.`;if(a.length>0&&c===o.canonical){let n=`kept Pi's folder trust because other resources still need it: ${a.slice(0,3).map(e=>V(JSON.stringify(e))).join(`, `)}${a.length>3?` (+${a.length-3} more)`:``}. ${u} Removing this grant may stop Pi from loading those resources, including any not listed here.`;s.result={action:`kept-shared`,detail:n},l&&e.mode===`recorded`&&$(t,()=>J(t,l)),s.result={action:`kept-shared`,detail:`${n} ${l?e.mode===`recorded`?`OpenKnowledge has relinquished this grant and will not revoke it on later cleanup runs.`:`OpenKnowledge kept the existing ownership record; cleanup of its recorded location remains incomplete.`:`OpenKnowledge has no ownership record for this grant and will not revoke it on later cleanup runs.`}`};return}if(e.mode===`inspect`||!l||l.record.state===`pending`){let e=l?l.record.state===`pending`?`its ownership record is pending after an interrupted setup; completion cannot be verified. Re-running setup or cleanup does not reconcile this record while the folder remains trusted.`:`OpenKnowledge must reconcile its recorded location at ${V(l.record.configuredTrustPath)} before removing it.`:`no OpenKnowledge ownership record exists; this includes every grant made before ownership recording was introduced.`;s.result={action:`kept-unowned`,detail:`${c===o.canonical?`kept Pi's folder trust because ${e}`:`kept a Pi trust entry under a non-canonical project path because ${e} Pi uses the real project directory instead of this key.`} ${u}`};return}let d={...i.entries};l.record.previous.present?d[c]=l.record.previous.value:delete d[c];let f=JSON.stringify(d,null,2)+(i.trailingNewline?`
9
- `:``),p=S(r);_(r,f,p===void 0?void 0:{mode:p}),i.entries=d,$(t,()=>J(t,l)),s.result={action:`removed`}}function nn(e){return fe(e)||he(e)||ie(e)}const rn=10485760;function an(e,t,n,r=!1){let i=$t(e,t,n,{recordedOnly:r});switch(i.action){case`removed`:case`not-present`:return{trust:i.action};case`kept-shared`:case`kept-unowned`:return{trust:i.action,trustDetail:i.detail};case`failed`:case`refused-unreadable`:case`kept-unverified`:{let e=r?`Trust cleanup remains incomplete`:`The bridge file was left untouched`;throw Error(`Pi trust cleanup failed (${i.action}):\n${i.error}\n${e} so cleanup can be retried.`)}default:throw Error(`unhandled Pi trust cleanup result: ${i}`)}}function on(e,t,n,r){if(e.id!==`pi`)return{kind:`not-present`};let i=an(t,n,r,!0);return i.trust===`not-present`?{kind:`not-present`}:{kind:`removed`,...i}}function sn(e,t,n,r,i){let a;try{a=r??e.configPath(t,n)}catch{return{kind:`not-present`}}let o=we(a);if(o.kind===`not-present`)return on(e,t,n,i);if(o.kind===`declined`)return o;let s=pe(e,t,n,o.path);if(s.kind===`absent`||s.kind===`no-entry`)return on(e,t,n,i);if(s.kind===`decline`)return{kind:`declined`,reason:s.reason};if(!nn(s.entry))return{kind:`left-foreign`};let c=e.serverName(t);if(e.format===`file`){let e=an(t,n,i);try{ke(a,{force:!0})}catch(t){throw e.trustDetail?Error(`${t instanceof Error?t.message:String(t)}\n${e.trustDetail}`,{cause:t}):t}return{kind:`removed`,...e}}return e.format===`toml`?un(o.path,c):e.format===`yaml`?ln(o.path,e.topLevelKey,c):cn(o.path,e.topLevelKey,e.serverMapSubKey,c)}function cn(e,t,n,r){let i;try{i=j(e,`utf-8`)}catch(e){return{kind:`declined`,reason:x(e)}}if(Buffer.byteLength(i,`utf-8`)>rn)return{kind:`declined`,reason:`oversize`};let{text:a,changed:o}=b(i,ye(t,n,r));return o?(_(e,a,{mode:S(e)}),{kind:`removed`}):{kind:`not-present`}}function ln(e,t,n){let r;try{r=j(e,`utf-8`)}catch(e){return{kind:`declined`,reason:x(e)}}if(Buffer.byteLength(r,`utf-8`)>rn)return{kind:`declined`,reason:`oversize`};let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=(0,I.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=de(a);a.trim()===``||a.endsWith(`
10
- `)?c.endsWith(`
11
- `)||(c=`${c}\n`):c=c.replace(/\n+$/,``),l&&(c=c.replace(/\r\n/g,`
12
- `).replace(/\n/g,`\r
13
- `));let u=`${i?``:``}${c}`;return u!==r&&_(e,u,{mode:S(e)}),{kind:`removed`}}function un(e,t){let n=ve();if(n.backend===`fallback`)return{kind:`declined`,reason:`no-native-writer`};let r;try{r=j(e,`utf-8`)}catch(e){return{kind:`declined`,reason:x(e)}}let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=de(a),s=a.trim()===``||a.endsWith(`
14
- `),c;try{c=n.removeEntry(a,t)}catch{return{kind:`declined`,reason:`unparseable`}}if(!c.existed)return{kind:`not-present`};let l=c.text;s?l.endsWith(`
15
- `)||(l=`${l}\n`):l=l.replace(/\n+$/,``),o&&(l=l.replace(/\r\n/g,`
16
- `).replace(/\n/g,`\r
17
- `));let u=`${i?``:``}${l}`;return u!==r&&_(e,u,{mode:S(e)}),{kind:`removed`}}function dn(e,t){let n=l[e];return n===null?null:E(t,...n.split(`/`),v.discovery,`SKILL.md`)}function fn(e,t){let n=dn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};if(!m(t).some(t=>t.editorId===e))return{editorId:e,label:e,action:`skipped-unsupported`,path:n};try{let r=g(`discovery`,{checkDesktop:!0});return ne(T(n),t),{editorId:e,label:e,action:te(r,n),path:n}}catch(t){return{editorId:e,label:e,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function pn(e){return k(E(e,...`.agents/skills`.split(`/`),v.discovery))?!0:r.some(t=>{let n=dn(t,e);return n!==null&&k(T(n))})}function mn(e,t){let n=dn(e,t);if(n===null)return{editorId:e,label:e,action:`skipped-unsupported`,path:``};let r=T(n);try{return k(n)?(ne(r,t),ke(r,{recursive:!0,force:!0}),{editorId:e,label:e,action:`removed`,path:n}):{editorId:e,label:e,action:`not-present`,path:n}}catch(t){return{editorId:e,label:e,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function hn(e){return e===`opencode`?le:_e}function gn(e,t,n){let r=C[e],i=hn(e),a=[],o=r.projectConfigPath?.(t);o!==void 0&&a.push({scope:`project`,configPath:o});try{a.push({scope:`user`,configPath:r.configPath(t,n)})}catch{}for(let o of a){let a=ce(r,t,n,o.configPath);if(a!==null&&i(a))return{editorId:e,scope:o.scope,configPath:o.configPath}}return null}function _n(e,t,n=[]){let r=k(E(e,v[t]))?`satisfied`:`absent`;return{...r===`satisfied`?{state:r,strictness:[`reclaim-permissive`]}:{state:r},...n.length===0?{}:{sharedWith:n}}}function vn(e,t){let n=me.flatMap(t=>{let n=e[t];return n===null?[]:[{editor:t,root:n}]}),r=a.filter(e=>e.scope===t).map(e=>({editor:e.editorId,root:c}));return[...n,...r]}function yn(e,t,n,r){let i=h(e,vn(t,r)),a=i.find(e=>e.host===n);if(a===void 0||a.state===`absent`)return[];let o=a.real;return i.filter(e=>e.host!==n&&e.state!==`absent`&&e.real===o).map(e=>e.host)}function bn(e,t){let n=(t??F()).replace(/[\\/]+$/,``);if(!n.includes(`\\`))return e.startsWith(`${n}/`)?`~/${e.slice(n.length+1)}`:e;let r=e=>e.replace(/\\/g,`/`),i=r(n),a=r(e);return a.startsWith(`${i}/`)?`~/${a.slice(i.length+1)}`:e}function xn(e,t){let n=C[e];return xe(n,``,t)&&!oe(n,``,t)}function Sn(e,t,n,r,i){let a=C[e],o;if(i===void 0)try{o=a.configPath(n,r)}catch{return{state:`structural-na`}}else o=i;let s=i===void 0?bn(o,r):void 0,c=pe(a,n,r,i);switch(c.kind){case`absent`:case`no-entry`:return i===void 0&&xn(e,r)?{state:`structural-na`}:{state:`absent`,path:s};case`decline`:return{state:`unprobed`};case`present`:{let{entry:r}=c,i=[];fe(r)&&i.push(`reclaim-permissive`),he(r)&&i.push(`pre-approval-exact`),hn(e)(r)&&i.push(`injection-functional`);let o=re(a,n);return i.length>0&&(o!==null&&se(r,o)||t.includes(`pre-approval-exact`)&&i.includes(`reclaim-permissive`)&&!i.includes(`pre-approval-exact`))?{state:`drifted`,strictness:i,path:s}:i.length>0?{state:`satisfied`,strictness:i,path:s}:ae(a)?{state:`foreign-replaceable`,path:s}:{state:`foreign`,path:s}}}}function Cn(e){let{cwd:t,home:n}=e;return e=>{if(e.pathId===null)return null;let r=i(e.pathId);if(r===null)return null;if(r.kind===`central-skill-store`)return n===void 0?null:_n(E(n,c),`discovery`,yn(n,l,e.agent,`global`));let a=r.editor;switch(r.kind){case`editor-user-skill-root`:{let e=l[a];return e===null||n===void 0?null:m(n).some(e=>e.editorId===a)?_n(E(n,e),`discovery`,yn(n,l,a,`global`)):{state:`structural-na`}}case`editor-project-skill-root`:{let e=s[a];return e===null?null:_n(E(t,e),`project`,yn(t,s,a,`project`))}case`editor-user-config`:return Sn(a,e.strictness,t,n);case`editor-project-config`:{let r=o[a];return r===null?null:Sn(a,e.strictness,t,n,E(t,r))}}}}export{He as _,fn as a,Le as b,qt as c,st as d,ct as f,Ke as g,Xe as h,pn as i,Ze as l,B as m,gn as n,sn as o,lt as p,mn as r,Yt as s,Cn as t,et as u,We as v,ze as x,Ge as y};
@@ -1 +0,0 @@
1
- import"./md-manager-BGnqyqi1-DKflYxqj.mjs";import"./init-DaLmOoJr.mjs";import"./registry-probes-C6-MQkI8.mjs";import"./src-CjybiOl3.mjs";import"./start-BJQG3Tj1.mjs";import{n as e}from"./loader-MbeLji7K.mjs";import"./preview-DLw39xAD.mjs";import"./cli.mjs";import"./repair-mcp-configs-Cp0nqANo.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{S as e,m as t,p as n,r}from"./start-BJQG3Tj1.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};
@@ -1,5 +0,0 @@
1
- import{Fc as e,Fs as t,Hu as n,Md as r,No as i,Rs as a,_t as o,da as s}from"./md-manager-BGnqyqi1-DKflYxqj.mjs";import{Fo as c,Ko as l,No as u,ci as d,ii as f,k as p,qr as m,xi as h}from"./dist-B5vmOfkB.mjs";import{Ct as g,I as _,R as v,St as y,Y as b,b as x,lt as S,wt as C,y as w}from"./init-DaLmOoJr.mjs";import{a as T,c as E,d as D,f as O,i as ee,n as k,o as A,p as j,r as M,s as N,t as te,u as P,v as F}from"./registry-probes-C6-MQkI8.mjs";import{n as ne}from"./constants-CeRULqiD.mjs";import{execFileSync as I,spawn as L}from"node:child_process";import{basename as R,dirname as z,join as re,resolve as B}from"node:path";import{existsSync as V,realpathSync as ie}from"node:fs";import{homedir as ae,tmpdir as oe}from"node:os";import{rm as se}from"node:fs/promises";import{setTimeout as ce}from"node:timers/promises";const le=[`/opt/homebrew/bin/gh`,`/usr/local/bin/gh`,`/opt/local/bin/gh`,`/snap/bin/gh`,`/usr/bin/gh`],ue={encoding:`utf-8`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3,windowsHide:!0};function H(e,t={}){let{login:n}=t,r=t._exec??I,i=U(t._fileExists??V),a=e?[`--hostname`,e]:[];if(n){let e=W(r,i,[`auth`,`token`,...a,`--user`,n]);if(e)return{available:!0,token:e,resolvedLogin:n,fallback:!1}}let o=W(r,i,[`auth`,`token`,...a]);return o?n?{available:!0,token:o,fallback:!0}:{available:!0,token:o}:{available:!1}}function U(e){return[`gh`,...le.filter(e)]}function W(e,t,n){for(let r of t)try{let t=e(r,n,ue).toString().trim();if(t.length>0)return t}catch{}}function de(e,t={}){let n=t._exec??I,r=U(t._fileExists??V),i=[`auth`,`status`,...e?[`--hostname`,e]:[]],a=W(n,r,[...i,`--json`,`hosts`]);if(a!==void 0){let t=fe(a,e);if(t)return t}let o=W(n,r,i);if(o!==void 0){let e=_e(o);if(e.length>0)return e}}function G(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function fe(e,t){let n;try{n=JSON.parse(e)}catch{return}let r=G(G(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=G(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 pe=/Logged in to \S+ account (\S+) \(/,me=/(?:Failed to log in to|Timeout trying to log in to) \S+/,he=/^\s*-\s*Active account:\s*true\s*$/,ge=/\u001b\[[0-9;]*m/g;function _e(e){let t=[],n;for(let r of e.split(`
2
- `)){let e=r.replace(ge,``),i=pe.exec(e)?.[1];if(i){n={login:i,active:!1},t.push(n);continue}if(me.test(e)){n=void 0;continue}n&&he.test(e)&&(n.active=!0)}return t}const ve={mode:`published`,skipAvailabilityCheck:!0,replaceEntry:!0};function K(){return{action:`failed`,errorId:`write-failed`}}function q(){return{action:`skipped-missing`,errorId:`surface-missing`}}function J(e,t,n){l(`agent-integrations-apply`).warn({editor:e,path:t,reason:n},`skill write failed`)}function Y(){return{action:`skipped-unsupported`,errorId:`no-writer`}}function ye(e){switch(e){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`left-foreign`:return{action:`skipped-foreign`,errorId:`foreign-artifact`};case`declined`:return{action:`declined`,errorId:`write-declined`}}}function be(e,t,n,r,i){let a=b[e];try{let o=A(a,t,n,r,i);return o.kind===`removed`&&o.trustDetail&&l(`agent-integrations-apply`).warn({editor:e,path:r??a.configPath(t,n),trust:o.trust,trustDetail:o.trustDetail},`MCP config removal retained Pi folder trust`),ye(o.kind)}catch(i){return l(`agent-integrations-apply`).warn({editor:e,path:r??a.configPath(t,n),reason:i instanceof Error?i.message:String(i)},`MCP config removal failed`),K()}}async function xe(e,t,n){if(b[e].scope!==`global`)return q();if(n===`absent`)return be(e,``,t.home,void 0,t.env);let r=(await x({editors:[e],home:t.home,replaceEntry:!0})).find(t=>t.editorId===e);if(r===void 0)return K();switch(r.action){case`written`:case`overwritten`:return{action:r.action};case`declined`:return{action:`declined`,errorId:`write-declined`};case`skipped-missing`:return q();case`skipped-flag`:return Y();default:return K()}}function Se(e,t,n){let i=r[e];if(i===null)return q();let a=re(t.cwd,i);if(n===`absent`)return be(e,t.cwd,t.home,a,t.env);let o=w(b[e],t.cwd,ve,void 0,a);switch(o.action){case`written`:case`overwritten`:return{action:o.action};case`declined`:return{action:`declined`,errorId:`write-declined`};default:return K()}}function Ce(e,t,n){let r=t.home??ae();if(n===`absent`){let t=M(e,r);switch(t.action){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`skipped-unsupported`:return q();case`failed`:return J(e,t.path,t.error),K()}}let i=T(e,r);switch(i.action){case`written`:return{action:`written`};case`overwritten`:return{action:`overwritten`};case`skipped-unsupported`:return q();case`failed`:return J(e,i.path,i.error),K()}}function we(e,t,n){if(n===`absent`){let n=_(b[e],t.cwd);switch(n.action){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`skipped-unsupported`:return q();case`failed`:return J(e,n.path,n.error),K()}}let r=v(b[e],t.cwd);switch(r.action){case`written`:return{action:`written`};case`overwritten`:return{action:`overwritten`};case`skipped-unsupported`:return q();case`skipped-prerequisite`:return{action:`skipped-prerequisite`,errorId:`dependency-failed`};case`failed`:return J(e,r.path,r.error),K()}}function Te(e){return t=>{if(t.pathId===void 0)return Y();let r=n(t.pathId);if(r===null||r.kind===`central-skill-store`)return Y();switch(r.kind){case`editor-user-config`:return xe(r.editor,e,t.desired);case`editor-project-config`:return Se(r.editor,e,t.desired);case`editor-project-skill-root`:return we(r.editor,e,t.desired);case`editor-user-skill-root`:return Ce(r.editor,e,t.desired)}}}function Ee(e,t){return e.bind?.[0]??t.HOST??`127.0.0.1`}function De(e){if(e===`server`)return e;throw new g(`--only must be 'server'`)}function Oe(e=V){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[B(t,`public`),B(t,`../../app/dist`),B(t,`../../../app/dist`)].find(t=>e(t))}function ke(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 Ae(t){if(t===`off`)return`off`;if(!e.test(t))throw new g(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return t}function je(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function Me(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function Ne(e){return!e.openBrowser||e.ephemeral||e.only===`server`||!e.servesUi?!1:(e.explicitOn||je(e.host))&&e.isTTY}function Pe(e,t){let n;try{n=new URL(t)}catch{throw new g(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new g(`${e} must be an http(s) origin (got: ${t})`);return t}function Fe(e){return Pe(`--external-url`,e)}function Ie(e){let t=R(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 ${p}* 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??oe,r=t.realpathFn??ie,i=e=>{try{return r(e)}catch(t){return t.code===`ENOENT`?B(e):null}},a=B(e),o;try{o=r(a)}catch(e){if(e.code===`ENOENT`){let e=i(z(a));o=e===null?null:B(e,R(a))}else o=null}if(o===null)return!1;let s=i(n());return s!==null&&z(o)===s&&R(o).startsWith(`ok-ephemeral-`)}function Le(e,t,n=e=>se(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 ${p}* dirs under the OS temp dir are removed on ephemeral teardown\n`)}}}function $(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 Re(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:l,resolve:u}=await import(`node:path`),{bootServer:f,createEphemeralProjectDir:p,getLogger:g,resolveContentDir:_,resolveLockDir:v,seedEphemeralProjectDir:y,waitForServerLockDrain:b}=await import(`./dist-D2OjImAs.mjs`),x=e.log??g(`start`),C=e.singleFile!==void 0,w=C?h(e.singleFile).canonicalFilePath:void 0,T=w?l(w):void 0,D=w?c(w):void 0,O,A=!1;if(T!==void 0){if(e.projectDir!==void 0){if(O=e.projectDir,!Q(O))throw new Z(O);o(u(O,`.ok`,`config.yml`))||y(O,T)}else O=p(T),A=!0}let j=async()=>{if(!(!A||O===void 0)){if(!Q(O)){x.warn({ephemeralProjectDir:O},`[start] refusing to reap self-provisioned ephemeral dir: no longer resolves to an ok-ephemeral-* temp dir`);return}try{await se(O,{recursive:!0,force:!0})}catch(e){x.warn({err:e,ephemeralProjectDir:O},`[start] failed to reap self-provisioned ephemeral temp dir`)}}},M=O;if(!C){if(!i&&!m(n))throw new X(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{e.severity===`info`?x.debug({event:e},`[start] reclaim sweep event`):x.warn({event:e},`[start] reclaim sweep reported a problem`)};try{let i=(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-Cp0nqANo.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r}).outcomes.filter(e=>e.outcome!==`no-entry`&&e.outcome!==`canonical`&&e.outcome!==`repaired`&&e.outcome!==`foreign`);i.length>0&&x.warn({unhealed:i},`[start] reclaim sweep left entries it could not heal`)}catch(e){x.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-d9rLMBoV.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){x.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}}let P=T??_(t,n);!C&&!o(P)&&(s(P,{recursive:!0}),x.info({contentDir:P},`Created content directory`));let ne=F(),I=d(),L;try{{let e=v(O??n),t=Date.now(),r=await b(e);r!==`no-drain`&&x.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`)}L=await f({config:t,contentDir:P,projectDir:O??n,contentRoot:C?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:H,detectGhAccounts:de,tokenStore:ne,embeddingsKeyStore:I,mcpTomlEditor:S(),...C?{ephemeral:!0,singleDocRelPath:D,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>k(e,t),probePiAcpBridge:e=>E(e),ensurePiAcpBridge:(e,t)=>N(e,void 0,void 0,void 0,t),agentIntegrations:(()=>{let e={cwd:O??n,home:ae(),env:process.env};return{probe:te(e),execute:Te(e),userSkillPresentAnywhere:ee}})(),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return $(M===void 0?n:Le(n,M),{log:x,exit:e.idleExit})},log:x,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}})}catch(e){throw await j(),e}let R=L.destroy,z=A?async()=>{try{await R()}finally{await j()}}:R;return{httpServer:L.httpServer,destroy:z,lockDir:L.lockDir,contentDir:P,port:L.port,ready:L.ready,degraded:L.degraded}}function ze(e,t,n=()=>u({absPath:c(`user`,process.cwd()),sideline:!1,warn:()=>{}}).value){return t===void 0?e:n()}function Be(e){if(e===`browser`||e===`app`)return e;throw new g(`--mode must be 'browser' or 'app'`)}function Ve(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 Ue(e,n){let r=ze(e,n.singleFile),c=Ve(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=Ie(m);let h;try{h=t(process.env)}catch(e){throw e instanceof o&&(console.error(f(e.message)),process.exit(78)),e}for(let e of h.diagnostics)console.warn(p(`[config] ${e.message}`));let g=s(r,h.layer),_=h.overrides.some(e=>e.envVar===`OK_BIND`),v=n.bind!==void 0&&n.bind.length>0?n.bind:void 0,y=process.env.HOST,b=y!==void 0&&y.trim()!==``?y:void 0,x=a(g),S=v??(_||b===void 0?[...x.bind]:[b]);Me({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=n.externalUrl,E=a(s(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=n.port===void 0?void 0:Number(n.port),O=h.overrides.find(e=>e.envVar===`PORT`)?.value,ee=D??O??r.server?.port,k=ke({explicitDir:n.reactShellDistDir,only:n.only,findBundledDir:Oe}),A=k.dir;k.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 j;try{j=await Re({config:r,cwd:m,host:C,port:ee,bind:w,...n.serveContentAssets===void 0?{}:{serveContentAssets:n.serveContentAssets},...A?{reactShellDistDir:A}:{},idleThresholdMs:i(n.idleShutdown??E.idleShutdown),serverRuntime:E,...n.singleFile?{singleFile:n.singleFile}:{},...n.projectDir?{projectDir:n.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-D2OjImAs.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||e instanceof t.DocumentDurabilityStateError)&&(console.error(f(e.message)),process.exit(1)),Ke(e,t)){let e=t.resolveLockDir(m),n=null;try{n=await We({readServerLock:()=>t.readServerLock(e),now:Date.now,sleep:e=>ce(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]=Ge(n);console.log(u(e));for(let e of t)console.log(d(e));process.exit(0)}}let n=qe(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 M=!1,N=async e=>{if(M)return;M=!0;let[t,...n]=He(e);console.log(u(`\n${t}`));for(let e of n)console.log(d(` ${e}`));try{await j.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`,()=>{N(`SIGINT`)}),process.once(`SIGTERM`,()=>{N(`SIGTERM`)});let te=`http://${C.includes(`:`)&&!C.startsWith(`[`)?`[${C}]`:C}:${j.port}`,P=C===`0.0.0.0`||C===`::`?`http://0.0.0.0:${j.port}`:void 0,F=te;console.log(l({name:`open-knowledge`,version:ne,localUrl:F,networkUrl:P,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let I={"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`};j.ready.then(async()=>{if(j.degraded.length>0){console.log();for(let e of j.degraded){let t=I[e]??`${e} (check server logs for details)`;console.warn(` ${p(`⚠`)} ${p(e)}: ${d(t)}`)}console.log()}if(Ne({openBrowser:n.openBrowser!==!1&&E.openBrowser,explicitOn:n.openBrowser!==!1&&g.server?.openBrowser===!0,host:C,isTTY:process.stdout.isTTY===!0,ephemeral:n.singleFile!==void 0,only:n.only,servesUi:A!==void 0})){let{openBrowser:e}=await import(`./open-browser-wd9wHZQk.mjs`);e(F)}}).catch(e=>{console.error(` ${f(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}async function We(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:f(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 Ge(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 Ke(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function qe(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 Je(e){return new y(`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)`,De).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)`,Ae).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,Be).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 C(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).hideHelp()).addOption(new C(`--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).`,Fe).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
- `),process.exit(2)),t.projectDir!==void 0&&t.singleFile===void 0&&(process.stderr.write(`error: option '--project-dir' requires '--single-file'
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=D(P());if(n.available){O({spawn:L},n);return}console.error(j(n.reason)),process.exit(1)}await Ue(n,t)})}export{qe as C,de as D,H as E,Je as S,$ as T,Ve as _,Ge as a,Ne as b,Q as c,Ae as d,De as f,ze as g,We as h,Ie as i,Ke as l,Ee as m,X as n,He as o,Oe as p,Re as r,je as s,Z as t,Fe as u,ke as v,Le as w,Me as x,Ue as y};