@inkeep/open-knowledge 0.25.0-beta.22 → 0.25.0-beta.24
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.
- package/dist/assets/skills/discovery/SKILL.md +1 -1
- package/dist/assets/skills/project/SKILL.md +1 -1
- package/dist/cli.mjs +66 -66
- package/dist/constants-DVW-9MaB.mjs +2 -0
- package/dist/{dist-TG9U-N9P.mjs → dist-AG4Gq9ev.mjs} +7 -7
- package/dist/dist-BWUwqOdN.mjs +1 -0
- package/dist/{gh-detect-agW-_3XF.mjs → gh-detect-DD9zzsz3.mjs} +2 -2
- package/dist/index.d.mts +28 -1
- package/dist/index.mjs +1 -1
- package/dist/init-BLlGTkgO.mjs +1 -0
- package/dist/init-D3sweWsY.mjs +321 -0
- package/dist/{loader-OqBg2MkQ.mjs → loader-C32u3Dvc.mjs} +3 -3
- package/dist/loader-bq73r__P.mjs +1 -0
- package/dist/preview-Bi4xON6m.mjs +1 -0
- package/dist/{preview-DgLBzg0c.mjs → preview-DnAEOXGa.mjs} +2 -2
- package/dist/public/assets/{ActivityModeContent-Bq2-szSy.js → ActivityModeContent-BiGyPtzs.js} +1 -1
- package/dist/public/assets/{DocumentContext-Cp5LrwUt.js → DocumentContext-DzW0Hd8f.js} +1 -1
- package/dist/public/assets/{EnableSyncConfirmDialog-D6td4gmM.js → EnableSyncConfirmDialog-DjDTAYSx.js} +1 -1
- package/dist/public/assets/{GraphPanel-CzvW16mF.js → GraphPanel-BRea0zG5.js} +1 -1
- package/dist/public/assets/{ManagedArtifactProperties-7tx2h5fh.js → ManagedArtifactProperties-Bvb-RQEJ.js} +1 -1
- package/dist/public/assets/McpConsentDialogBody-C5k8PPDu.js +1 -0
- package/dist/public/assets/{PropertyPanel-BYMeaHwv.js → PropertyPanel-BL6tDKwT.js} +1 -1
- package/dist/public/assets/{SettingsDialogBody-C4TH7Apf.js → SettingsDialogBody-CqgTnPy8.js} +1 -1
- package/dist/public/assets/{ShareBranchSwitchDialog-CAYidTth.js → ShareBranchSwitchDialog-1U2vVhQb.js} +1 -1
- package/dist/public/assets/{ShareReceiveDialog-B_g3WoKU.js → ShareReceiveDialog-Dxk-LrDr.js} +1 -1
- package/dist/public/assets/{ShareReceiveMissDialog-Bi8yB_Er.js → ShareReceiveMissDialog-Dr6VnJNL.js} +1 -1
- package/dist/public/assets/{SkillEditorActions-zGJNqarO.js → SkillEditorActions-BE4zpvxO.js} +1 -1
- package/dist/public/assets/{SourceEditor-z66BI1TW.js → SourceEditor-B76IS9B5.js} +1 -1
- package/dist/public/assets/{TerminalPanel-vd5LQunA.js → TerminalPanel-CuIUVEfX.js} +1 -1
- package/dist/public/assets/{auth-state-cache-CBnUAJVI.js → auth-state-cache-Dl3ZiBZL.js} +1 -1
- package/dist/public/assets/{config-provider-VM6ptPr5.js → config-provider-NM1p9Zm_.js} +1 -1
- package/dist/public/assets/{dist-BGXCkPeI.js → dist-BkxMNfFN.js} +1 -1
- package/dist/public/assets/{doc-hash-CyR3apuv.js → doc-hash-DYyNsXAD.js} +1 -1
- package/dist/public/assets/{documents-events-Bsq-Lwvc.js → documents-events-DFqHwl8q.js} +1 -1
- package/dist/public/assets/{file-tree-adapter-CI7t-Quy.js → file-tree-adapter-BarjCzXT.js} +1 -1
- package/dist/public/assets/{index-BuvV9Y-n.js → index-0Zv6gs2U.js} +7 -7
- package/dist/public/assets/{keyboard-shortcuts-BeQiNPv5.js → keyboard-shortcuts-DyCddAiu.js} +1 -1
- package/dist/public/assets/{open-managed-artifact-tab-C0CwefFo.js → open-managed-artifact-tab-D3bPW_N7.js} +1 -1
- package/dist/public/assets/{pending-receive-nav-store-BPFyzD9L.js → pending-receive-nav-store-CLwh-9nE.js} +1 -1
- package/dist/public/assets/{prop-types-DgIMu1uN.js → prop-types-BEZe0Mr0.js} +1 -1
- package/dist/public/assets/{receive-store-EKQrlEsf.js → receive-store-BZp1qikL.js} +1 -1
- package/dist/public/assets/{selection-context-B7L1o08O.js → selection-context-DDtYeIS_.js} +1 -1
- package/dist/public/assets/{skill-actions-BWXoXFJf.js → skill-actions-UwN9vpAE.js} +1 -1
- package/dist/public/assets/{skills-api-C8U58cr0.js → skills-api-CJJjd5CV.js} +1 -1
- package/dist/public/assets/{target-navigation-intent-D0W-SiFr.js → target-navigation-intent-B_RqIRfv.js} +1 -1
- package/dist/public/assets/{typing-burst-detector-g8ADg4Q2.js → typing-burst-detector-8OH-dz6h.js} +1 -1
- package/dist/public/index.html +20 -20
- package/dist/{repair-launch-json-e3Xal7gR.mjs → repair-launch-json-rZGx8Hlk.mjs} +2 -2
- package/dist/{repair-mcp-configs-uJr9vJYZ.mjs → repair-mcp-configs-Idc5CsVt.mjs} +2 -2
- package/dist/repair-skills-BJsTibpj.mjs +3 -0
- package/dist/repair-skills-DClA9KZj.mjs +1 -0
- package/dist/server-lock-LsXsWtim-BrcDoV-6.mjs +1 -0
- package/dist/{server-lock-ltHt39S2-FrJuEUby.mjs → server-lock-ltHt39S2-p0c2u2YF.mjs} +5 -5
- package/dist/{src-BlGVwaKa.mjs → src-ZKUfOXO5.mjs} +3 -3
- package/dist/start-CWAkTUKC.mjs +1 -0
- package/dist/{start-BL2OEs-Z.mjs → start-DaZwGnwh.mjs} +2 -2
- package/dist/write-project-skill-DK3lBBLD.mjs +36 -0
- package/package.json +1 -1
- package/dist/constants-BUU-f5cR.mjs +0 -2
- package/dist/dist-CDX3FPEf.mjs +0 -1
- package/dist/init-DXxXuTdF.mjs +0 -1
- package/dist/init-OSum2tdu.mjs +0 -321
- package/dist/loader-CTgKrU6h.mjs +0 -1
- package/dist/preview-DvHkfk9B.mjs +0 -1
- package/dist/public/assets/McpConsentDialogBody-BNMbefiw.js +0 -1
- package/dist/repair-skills-BEfm4X9B.mjs +0 -3
- package/dist/repair-skills-Bz8yC6_P.mjs +0 -1
- package/dist/server-lock-LsXsWtim-BLIrqdzC.mjs +0 -1
- package/dist/start-B8B-OPqe.mjs +0 -1
- package/dist/write-project-skill-qMcfR4xG.mjs +0 -36
package/dist/public/assets/{typing-burst-detector-g8ADg4Q2.js → typing-burst-detector-8OH-dz6h.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{n as t,r as n,t as r}from"./compiler-runtime-CVnuRdak.js";import{J as i,Y as a,ft as o,n as s,ot as c,q as l}from"./DocumentContext-Cp5LrwUt.js";import{n as u,r as d}from"./dist-CQw2y-s3.js";import{a as f,c as ee,i as te,n as ne,o as re,r as ie,s as ae,t as oe,u as se}from"./panel-BH2RZRZQ.js";import{Wn as ce,et as p,rt as m,xr as h}from"./dist-BGXCkPeI.js";import{i as le}from"./button-cneJOVxD.js";import{i as ue}from"./prop-types-DgIMu1uN.js";import{l as g}from"./documents-events-Bsq-Lwvc.js";import{i as _}from"./startup-marks-ChdnUQ0e.js";import{$ as v,At as y,Bt as b,Dt as x,E as S,Et as C,Ft as w,Ht as T,J as E,Mt as D,N as O,Ot as k,Pt as A,Q as j,Rt as de,Ut as fe,X as M,_ as N,_t as P,ct as F,dt as I,et as L,f as R,gt as pe,ht as me,l as he,lt as ge,mt as _e,nt as ve,ot as ye,rt as be,st as xe,tt as Se,ut as Ce,wt as z,y as we,yt as B,zt as Te}from"./dist-Ba_10F8i.js";import{i as Ee,n as De,o as Oe,r as ke}from"./dist-Bu8Xe-63.js";var Ae=e(t(),1),je=r(),Me=new Map;function Ne(e,t){Me.set(e,t)}function Pe(e){let t=Me.get(e)??null;return Me.delete(e),t}function Fe(e){Me.delete(e)}function Ie(e,t){let n=(0,je.c)(4),r=t===void 0?!1:t,[i,a]=(0,Ae.useState)(void 0),o=(0,Ae.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,Ae.useEffect)(s,c),i}var V=n(),Le=300;async function Re(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`),n;try{n=await t.json()}catch(e){throw new o(g._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=m.safeParse(n);throw e.success?Error(e.data.title):new o(g._({id:`zlErBl`}),{status:t.status})}let r=p.safeParse(n);if(!r.success)throw new o(g._({id:`XW18jo`}),{status:t.status});return r.data.headings??[]}var ze=32,Be=12,Ve=6,He=`open-knowledge:outline-nav`;function Ue(e){let t=(0,je.c)(2),n;return t[0]===e?n=t[1]:(n=(0,V.jsx)(_,{name:`outline-panel`,children:(0,V.jsx)(We,{...e})}),t[0]=e,t[1]=n),n}function We(e){let t=(0,je.c)(50),{docName:n,isSourceMode:r,className:i}=e,a=i===void 0?``:i,{_:o}=d(),{pages:c,loading:l}=ue(),p=se(),{activeProvider:m,activeDocName:h}=s(),g,_;t[0]===n?(g=t[1],_=t[2]):(g=[`page-headings`,n],_=()=>Re(n),t[0]=n,t[1]=g,t[2]=_);let v;t[3]!==n||t[4]!==l||t[5]!==c?(v=!l&&(c.has(n)||ce(n)),t[3]=n,t[4]=l,t[5]=c,t[6]=v):v=t[6];let y;t[7]!==g||t[8]!==_||t[9]!==v?(y={queryKey:g,queryFn:_,enabled:v,staleTime:1/0},t[7]=g,t[8]=_,t[9]=v,t[10]=y):y=t[10];let{data:b,isLoading:x,error:S}=ee(y),C;t[11]===b?C=t[12]:(C=b===void 0?[]:b,t[11]=b,t[12]=C);let w=C,T,E;t[13]!==h||t[14]!==m||t[15]!==n||t[16]!==p?(T=()=>{if(!m||h!==n)return;let e=m.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,p.invalidateQueries({queryKey:[`page-headings`,n]})},Le)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},E=[m,h,n,p],t[13]=h,t[14]=m,t[15]=n,t[16]=p,t[17]=T,t[18]=E):(T=t[17],E=t[18]),(0,Ae.useEffect)(T,E);let D;t[19]===w?D=t[20]:(D=w.map(Ge),t[19]=w,t[20]=D);let O=Ie(D,r),k;t[21]!==O||t[22]!==w?(k=O?w.findIndex(e=>e.slug===O):-1,t[21]=O,t[22]=w,t[23]=k):k=t[23];let A=k,j;t[24]!==n||t[25]!==r?(j=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&Ne(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(He,{detail:i}))},t[24]=n,t[25]=r,t[26]=j):j=t[26];let de=j,fe=((A>=0?w[A].level:1)-1)*Be+(Be-Ve)/2,M=A*ze+(ze-Ve)/2,N;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,V.jsx)(ae,{children:(0,V.jsx)(u,{id:`dD7NPy`})}),t[27]=N):N=t[27];let P;t[28]!==w.length||t[29]!==x?(P=!x&&(0,V.jsx)(ie,{children:w.length}),t[28]=w.length,t[29]=x,t[30]=P):P=t[30];let F;t[31]===P?F=t[32]:(F=(0,V.jsxs)(re,{children:[N,P]}),t[31]=P,t[32]=F);let I;t[33]!==o||t[34]!==A||t[35]!==O||t[36]!==S||t[37]!==de||t[38]!==w||t[39]!==x||t[40]!==fe||t[41]!==M?(I=S?(0,V.jsx)(f,{className:`px-2`,children:S instanceof Error?S.message:o({id:`GuqOb1`})}):w.length===0&&!x?(0,V.jsx)(te,{className:`px-2`,children:(0,V.jsx)(u,{id:`0BB9ID`})}):(0,V.jsxs)(`nav`,{"aria-label":o({id:`BymzO4`}),className:`relative`,children:[A>=0&&(0,V.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 rounded-full bg-primary motion-safe:[transition:transform_0.25s_var(--ease-out-strong)]`,style:{width:Ve,height:Ve,transform:`translate(${fe}px, ${M}px)`}}),w.map((e,t)=>{let n=e.slug===O;return(0,V.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>de(t,e.slug),className:le(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*Be+20}px`},title:e.text,children:e.text},t)})]}),t[33]=o,t[34]=A,t[35]=O,t[36]=S,t[37]=de,t[38]=w,t[39]=x,t[40]=fe,t[41]=M,t[42]=I):I=t[42];let L;t[43]!==x||t[44]!==I?(L=(0,V.jsx)(ne,{className:`px-3 py-2`,"aria-busy":x,children:I}),t[43]=x,t[44]=I,t[45]=L):L=t[45];let R;return t[46]!==a||t[47]!==F||t[48]!==L?(R=(0,V.jsxs)(oe,{className:a,children:[F,L]}),t[46]=a,t[47]=F,t[48]=L,t[49]=R):R=t[49],R}function Ge(e){return e.slug}var Ke=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,H=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(Ke(e)):Ke,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return de(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=fe(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=Te(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(H.prototype[Symbol.iterator]=function(){return this});var qe={from:-1,to:-1,match:/.*/.exec(``)},Je=`gm`+(/x/.unicode==null?``:`u`),Ye=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=qe,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Qe(e,t,n,r,i);this.re=new RegExp(t,Je+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=et(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=et(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},Xe=new WeakMap,Ze=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=Xe.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return Xe.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),Xe.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},Qe=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=qe,this.matchPos=et(e,r),this.re=new RegExp(t,Je+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=Ze.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=et(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Ze.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(Ye.prototype[Symbol.iterator]=Qe.prototype[Symbol.iterator]=function(){return this});function $e(e){try{return new RegExp(e,Je),!0}catch{return!1}}function et(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var tt=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=pe(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),ee=C.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,M.scrollIntoView(ee.from,{y:`center`})],selection:ee})}),!0},nt={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},rt=k.define({combine(e){return b(e,nt,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function it(e){let t=[ut,lt];return e&&t.push(rt.of(e)),t}var at=E.mark({class:`cm-selectionMatch`}),ot=E.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function st(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=z.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=z.Word)}function ct(e,t,n,r){return e(t.sliceDoc(n,n+1))==z.Word&&e(t.sliceDoc(r-1,r))==z.Word}var lt=j.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(rt),{state:n}=e,r=n.selection;if(r.ranges.length>1)return E.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return E.none;let e=n.wordAt(i.head);if(!e)return E.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return E.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(st(o,n,i.from,i.to)&&ct(o,n,i.from,i.to)))return E.none}else if(a=n.sliceDoc(i.from,i.to),!a)return E.none}let s=[];for(let r of e.visibleRanges){let e=new H(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||st(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(ot.range(r,a)):(r>=i.to||a<=i.from)&&s.push(at.range(r,a)),s.length>t.maxMatches))return E.none}}return E.set(s)}},{decorations:e=>e.decorations}),ut=M.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),dt=({state:e,dispatch:t})=>{let{selection:n}=e,r=C.create(n.ranges.map(t=>e.wordAt(t.head)||C.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function ft(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new H(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new H(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var pt=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return dt({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=ft(e,r);return i?(t(e.update({selection:e.selection.addRange(C.range(i.from,i.to),!1),effects:M.scrollIntoView(i.to)})),!0):!1},U=k.define({combine(e){return b(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Ut(e),scrollToMatch:e=>M.scrollIntoView(e)})}});function mt(e){return e?[U.of(e),Jt]:Jt}var ht=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||$e(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
|
|
1
|
+
import{o as e}from"./chunk-CFjPhJqf.js";import{n as t,r as n,t as r}from"./compiler-runtime-CVnuRdak.js";import{J as i,Y as a,ft as o,n as s,ot as c,q as l}from"./DocumentContext-DzW0Hd8f.js";import{n as u,r as d}from"./dist-CQw2y-s3.js";import{a as f,c as ee,i as te,n as ne,o as re,r as ie,s as ae,t as oe,u as se}from"./panel-BH2RZRZQ.js";import{Wn as ce,et as p,rt as m,xr as h}from"./dist-BkxMNfFN.js";import{i as le}from"./button-cneJOVxD.js";import{i as ue}from"./prop-types-BEZe0Mr0.js";import{l as g}from"./documents-events-DFqHwl8q.js";import{i as _}from"./startup-marks-ChdnUQ0e.js";import{$ as v,At as y,Bt as b,Dt as x,E as S,Et as C,Ft as w,Ht as T,J as E,Mt as D,N as O,Ot as k,Pt as A,Q as j,Rt as de,Ut as fe,X as M,_ as N,_t as P,ct as F,dt as I,et as L,f as R,gt as pe,ht as me,l as he,lt as ge,mt as _e,nt as ve,ot as ye,rt as be,st as xe,tt as Se,ut as Ce,wt as z,y as we,yt as B,zt as Te}from"./dist-Ba_10F8i.js";import{i as Ee,n as De,o as Oe,r as ke}from"./dist-Bu8Xe-63.js";var Ae=e(t(),1),je=r(),Me=new Map;function Ne(e,t){Me.set(e,t)}function Pe(e){let t=Me.get(e)??null;return Me.delete(e),t}function Fe(e){Me.delete(e)}function Ie(e,t){let n=(0,je.c)(4),r=t===void 0?!1:t,[i,a]=(0,Ae.useState)(void 0),o=(0,Ae.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,Ae.useEffect)(s,c),i}var V=n(),Le=300;async function Re(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`),n;try{n=await t.json()}catch(e){throw new o(g._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=m.safeParse(n);throw e.success?Error(e.data.title):new o(g._({id:`zlErBl`}),{status:t.status})}let r=p.safeParse(n);if(!r.success)throw new o(g._({id:`XW18jo`}),{status:t.status});return r.data.headings??[]}var ze=32,Be=12,Ve=6,He=`open-knowledge:outline-nav`;function Ue(e){let t=(0,je.c)(2),n;return t[0]===e?n=t[1]:(n=(0,V.jsx)(_,{name:`outline-panel`,children:(0,V.jsx)(We,{...e})}),t[0]=e,t[1]=n),n}function We(e){let t=(0,je.c)(50),{docName:n,isSourceMode:r,className:i}=e,a=i===void 0?``:i,{_:o}=d(),{pages:c,loading:l}=ue(),p=se(),{activeProvider:m,activeDocName:h}=s(),g,_;t[0]===n?(g=t[1],_=t[2]):(g=[`page-headings`,n],_=()=>Re(n),t[0]=n,t[1]=g,t[2]=_);let v;t[3]!==n||t[4]!==l||t[5]!==c?(v=!l&&(c.has(n)||ce(n)),t[3]=n,t[4]=l,t[5]=c,t[6]=v):v=t[6];let y;t[7]!==g||t[8]!==_||t[9]!==v?(y={queryKey:g,queryFn:_,enabled:v,staleTime:1/0},t[7]=g,t[8]=_,t[9]=v,t[10]=y):y=t[10];let{data:b,isLoading:x,error:S}=ee(y),C;t[11]===b?C=t[12]:(C=b===void 0?[]:b,t[11]=b,t[12]=C);let w=C,T,E;t[13]!==h||t[14]!==m||t[15]!==n||t[16]!==p?(T=()=>{if(!m||h!==n)return;let e=m.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,p.invalidateQueries({queryKey:[`page-headings`,n]})},Le)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},E=[m,h,n,p],t[13]=h,t[14]=m,t[15]=n,t[16]=p,t[17]=T,t[18]=E):(T=t[17],E=t[18]),(0,Ae.useEffect)(T,E);let D;t[19]===w?D=t[20]:(D=w.map(Ge),t[19]=w,t[20]=D);let O=Ie(D,r),k;t[21]!==O||t[22]!==w?(k=O?w.findIndex(e=>e.slug===O):-1,t[21]=O,t[22]=w,t[23]=k):k=t[23];let A=k,j;t[24]!==n||t[25]!==r?(j=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&Ne(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(He,{detail:i}))},t[24]=n,t[25]=r,t[26]=j):j=t[26];let de=j,fe=((A>=0?w[A].level:1)-1)*Be+(Be-Ve)/2,M=A*ze+(ze-Ve)/2,N;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,V.jsx)(ae,{children:(0,V.jsx)(u,{id:`dD7NPy`})}),t[27]=N):N=t[27];let P;t[28]!==w.length||t[29]!==x?(P=!x&&(0,V.jsx)(ie,{children:w.length}),t[28]=w.length,t[29]=x,t[30]=P):P=t[30];let F;t[31]===P?F=t[32]:(F=(0,V.jsxs)(re,{children:[N,P]}),t[31]=P,t[32]=F);let I;t[33]!==o||t[34]!==A||t[35]!==O||t[36]!==S||t[37]!==de||t[38]!==w||t[39]!==x||t[40]!==fe||t[41]!==M?(I=S?(0,V.jsx)(f,{className:`px-2`,children:S instanceof Error?S.message:o({id:`GuqOb1`})}):w.length===0&&!x?(0,V.jsx)(te,{className:`px-2`,children:(0,V.jsx)(u,{id:`0BB9ID`})}):(0,V.jsxs)(`nav`,{"aria-label":o({id:`BymzO4`}),className:`relative`,children:[A>=0&&(0,V.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 rounded-full bg-primary motion-safe:[transition:transform_0.25s_var(--ease-out-strong)]`,style:{width:Ve,height:Ve,transform:`translate(${fe}px, ${M}px)`}}),w.map((e,t)=>{let n=e.slug===O;return(0,V.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>de(t,e.slug),className:le(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*Be+20}px`},title:e.text,children:e.text},t)})]}),t[33]=o,t[34]=A,t[35]=O,t[36]=S,t[37]=de,t[38]=w,t[39]=x,t[40]=fe,t[41]=M,t[42]=I):I=t[42];let L;t[43]!==x||t[44]!==I?(L=(0,V.jsx)(ne,{className:`px-3 py-2`,"aria-busy":x,children:I}),t[43]=x,t[44]=I,t[45]=L):L=t[45];let R;return t[46]!==a||t[47]!==F||t[48]!==L?(R=(0,V.jsxs)(oe,{className:a,children:[F,L]}),t[46]=a,t[47]=F,t[48]=L,t[49]=R):R=t[49],R}function Ge(e){return e.slug}var Ke=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,H=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(Ke(e)):Ke,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return de(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=fe(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=Te(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(H.prototype[Symbol.iterator]=function(){return this});var qe={from:-1,to:-1,match:/.*/.exec(``)},Je=`gm`+(/x/.unicode==null?``:`u`),Ye=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=qe,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Qe(e,t,n,r,i);this.re=new RegExp(t,Je+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=et(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=et(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},Xe=new WeakMap,Ze=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=Xe.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return Xe.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),Xe.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},Qe=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=qe,this.matchPos=et(e,r),this.re=new RegExp(t,Je+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=Ze.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=et(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Ze.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(Ye.prototype[Symbol.iterator]=Qe.prototype[Symbol.iterator]=function(){return this});function $e(e){try{return new RegExp(e,Je),!0}catch{return!1}}function et(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var tt=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=pe(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),ee=C.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,M.scrollIntoView(ee.from,{y:`center`})],selection:ee})}),!0},nt={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},rt=k.define({combine(e){return b(e,nt,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function it(e){let t=[ut,lt];return e&&t.push(rt.of(e)),t}var at=E.mark({class:`cm-selectionMatch`}),ot=E.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function st(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=z.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=z.Word)}function ct(e,t,n,r){return e(t.sliceDoc(n,n+1))==z.Word&&e(t.sliceDoc(r-1,r))==z.Word}var lt=j.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(rt),{state:n}=e,r=n.selection;if(r.ranges.length>1)return E.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return E.none;let e=n.wordAt(i.head);if(!e)return E.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return E.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(st(o,n,i.from,i.to)&&ct(o,n,i.from,i.to)))return E.none}else if(a=n.sliceDoc(i.from,i.to),!a)return E.none}let s=[];for(let r of e.visibleRanges){let e=new H(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||st(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(ot.range(r,a)):(r>=i.to||a<=i.from)&&s.push(at.range(r,a)),s.length>t.maxMatches))return E.none}}return E.set(s)}},{decorations:e=>e.decorations}),ut=M.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),dt=({state:e,dispatch:t})=>{let{selection:n}=e,r=C.create(n.ranges.map(t=>e.wordAt(t.head)||C.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function ft(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new H(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new H(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var pt=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return dt({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=ft(e,r);return i?(t(e.update({selection:e.selection.addRange(C.range(i.from,i.to),!1),effects:M.scrollIntoView(i.to)})),!0):!1},U=k.define({combine(e){return b(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Ut(e),scrollToMatch:e=>M.scrollIntoView(e)})}});function mt(e){return e?[U.of(e),Jt]:Jt}var ht=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||$e(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
|
|
2
2
|
`:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new wt(this):new yt(this)}getCursor(e,t=0,n){let r=e.doc?e:x.create({doc:e});return n??=r.doc.length,this.regexp?G(this,r,t,n):W(this,r,t,n)}},gt=class{constructor(e){this.spec=e}};function _t(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function W(e,t,n,r){let i;return e.wholeWord&&(i=vt(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=_t(e.test,t,i)),new H(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function vt(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(xt(i,n-a))!=z.Word||t(St(i,n-a))!=z.Word)&&(t(St(i,r-a))!=z.Word||t(xt(i,r-a))!=z.Word))}var yt=class extends gt{constructor(e){super(e)}nextMatch(e,t,n){let r=W(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=W(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=W(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=W(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=W(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function bt(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function G(e,t,n,r){let i;return e.wholeWord&&(i=Ct(t.charCategorizer(t.selection.main.head))),e.test&&(i=bt(e.test,t,i)),new Ye(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function xt(e,t){return e.slice(T(e,t,!1),t)}function St(e,t){return e.slice(t,T(e,t))}function Ct(e){return(t,n,r)=>!r[0].length||(e(xt(r.input,r.index))!=z.Word||e(St(r.input,r.index))!=z.Word)&&(e(St(r.input,r.index+r[0].length))!=z.Word||e(xt(r.input,r.index+r[0].length))!=z.Word)}var wt=class extends gt{nextMatch(e,t,n){let r=G(this.spec,e,n,e.doc.length).next();return r.done&&(r=G(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=G(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=G(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=G(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},K=A.define(),Tt=A.define(),q=w.define({create(e){return new Et(Lt(e).create(),null)},update(e,t){for(let n of t.effects)n.is(K)?e=new Et(n.value.create(),e.panel):n.is(Tt)&&(e=new Et(e.query,n.value?It:null));return e},provide:e=>P.from(e,e=>e.panel)}),Et=class{constructor(e,t){this.query=e,this.panel=t}},Dt=E.mark({class:`cm-searchMatch`}),Ot=E.mark({class:`cm-searchMatch cm-searchMatch-selected`}),kt=j.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(q))}update(e){let t=e.state.field(q);(t!=e.startState.field(q)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return E.none;let{view:n}=this,r=new D;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?Ot:Dt)})}return r.finish()}},{decorations:e=>e.decorations});function J(e){return t=>{let n=t.state.field(q,!1);return n&&n.query.spec.valid?e(t,n):Bt(t)}}var At=J((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=C.single(r.from,r.to),a=e.state.facet(U);return e.dispatch({selection:i,effects:[Kt(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),zt(e),!0}),jt=J((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=C.single(i.from,i.to),o=e.state.facet(U);return e.dispatch({selection:a,effects:[Kt(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),zt(e),!0}),Mt=J((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:C.create(n.map(e=>C.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),Nt=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new H(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(C.range(t.value.from,t.value.to))}return t(e.update({selection:C.create(a,o),userEvent:`select.search.matches`})),!0},Pt=J((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(M.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`)));let d=e.state.changes(s);return o&&(c=C.single(o.from,o.to).map(d),u.push(Kt(e,o)),u.push(n.facet(U).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),Ft=J((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(e=>{let{from:n,to:r}=e;return{from:n,to:r,insert:t.getReplacement(e)}});if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:M.announce.of(r),userEvent:`input.replace.all`}),!0});function It(e){return e.state.facet(U).createPanel(e)}function Lt(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(U);return new ht({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function Rt(e){let t=be(e,It);return t&&t.dom.querySelector(`[main-field]`)}function zt(e){let t=Rt(e);t&&t==e.root.activeElement&&t.select()}var Bt=e=>{let t=e.state.field(q,!1);if(t&&t.panel){let n=Rt(e);if(n&&n!=e.root.activeElement){let r=Lt(e.state,t.query.spec);r.valid&&e.dispatch({effects:K.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[Tt.of(!0),t?K.of(Lt(e.state,t.query.spec)):A.appendConfig.of(Jt)]});return!0},Vt=e=>{let t=e.state.field(q,!1);if(!t||!t.panel)return!1;let n=be(e,It);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Tt.of(!1)}),!0},Ht=[{key:`Mod-f`,run:Bt,scope:`editor search-panel`},{key:`F3`,run:At,shift:jt,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:At,shift:jt,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:Vt,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:Nt},{key:`Mod-Alt-g`,run:tt},{key:`Mod-d`,run:pt,preventDefault:!0}],Ut=class{constructor(e){this.view=e;let t=this.query=e.state.field(q).query.spec;this.commit=this.commit.bind(this),this.searchField=B(`input`,{value:t.search,placeholder:Y(e,`Find`),"aria-label":Y(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=B(`input`,{value:t.replace,placeholder:Y(e,`Replace`),"aria-label":Y(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=B(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=B(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=B(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return B(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=B(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>At(e),[Y(e,`next`)]),n(`prev`,()=>jt(e),[Y(e,`previous`)]),n(`select`,()=>Mt(e),[Y(e,`all`)]),B(`label`,null,[this.caseField,Y(e,`match case`)]),B(`label`,null,[this.reField,Y(e,`regexp`)]),B(`label`,null,[this.wordField,Y(e,`by word`)]),...e.state.readOnly?[]:[B(`br`),this.replaceField,n(`replace`,()=>Pt(e),[Y(e,`replace`)]),n(`replaceAll`,()=>Ft(e),[Y(e,`replace all`)])],B(`button`,{name:`close`,onclick:()=>Vt(e),"aria-label":Y(e,`close`),type:`button`},[`×`])])}commit(){let e=new ht({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:K.of(e)}))}keydown(e){me(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?jt:At)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Pt(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(K)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(U).top}};function Y(e,t){return e.state.phrase(t)}var Wt=30,Gt=/[\s\.,:;?!]/;function Kt(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-Wt),o=Math.min(i,n+Wt),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<Wt;e++)if(!Gt.test(s[e+1])&&Gt.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-Wt;e--)if(!Gt.test(s[e-1])&&Gt.test(s[e])){s=s.slice(0,e);break}}return M.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var qt=M.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),Jt=[q,y.low(kt),qt],Yt=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},X=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet($).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new D,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let f=vn(s);if(i)o.add(n,n,E.widget({widget:new dn(f),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,E.mark({class:`cm-lintRange cm-lintRange-`+f+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let f=o.finish();return new e(f,n,Z(f))}};function Z(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new Yt(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new Yt(r.from,n,r.diagnostic)}),r}function Xt(e,t){let n=t.pos,r=t.end||n,i=e.state.facet($).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(Qt))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Zt(e,t){return e.field(Q,!1)?t:t.concat(A.appendConfig.of(yn))}var Qt=A.define(),$t=A.define(),en=A.define(),Q=w.define({create(){return new X(E.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=Z(n,e.selected.diagnostic,i)||Z(n,null,i)}!n.size&&i&&t.state.facet($).autoPanel&&(i=null),e=new X(n,i,r)}for(let n of t.effects)if(n.is(Qt)){let r=t.state.facet($).autoPanel?n.value.length?pn.open:null:e.panel;e=X.init(n.value,r,t.state)}else n.is($t)?e=new X(e.diagnostics,n.value?pn.open:null,e.selected):n.is(en)&&(e=new X(e.diagnostics,e.panel,n.value));return e},provide:e=>[P.from(e,e=>e.panel),M.decorations.from(e,e=>e.diagnostics)]}),tn=E.mark({class:`cm-lintRange cm-lintRange-active`});function nn(e,t,n){let{diagnostics:r}=e.state.field(Q),i,a=-1,o=-1;r.between(t-+(n<0),t+ +(n>0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet($).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:rn(e,i)}}}:null}function rn(e,t){return B(`ul`,{class:`cm-tooltip-lint`},t.map(t=>un(e,t,!1)))}var an=e=>{let t=e.state.field(Q,!1);(!t||!t.panel)&&e.dispatch({effects:Zt(e.state,[$t.of(!0)])});let n=be(e,pn.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},on=e=>{let t=e.state.field(Q,!1);return!t||!t.panel?!1:(e.dispatch({effects:$t.of(!1)}),!0)},sn=[{key:`Mod-Shift-m`,run:an,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(Q,!1);if(!t)return!1;let n=e.state.selection.main,r=Z(t.diagnostics,null,n.to+1);return!r&&(r=Z(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],$=k.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...b(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:cn,tooltipFilter:cn,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function cn(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function ln(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function un(e,t,n){let r=n?ln(t.actions):[];return B(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},B(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=Z(e.state.field(Q).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),B(`u`,s.slice(c,c+1)),s.slice(c+1)];return B(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&B(`div`,{class:`cm-diagnosticSource`},t.source))}var dn=class extends v{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return B(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},fn=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=un(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},pn=class e{constructor(e){this.view=e,this.items=[],this.list=B(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)on(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=ln(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=Z(this.view.state.field(Q).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=B(`div`,{class:`cm-panel-lint`},this.list,B(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>on(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(Q).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Q),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new fn(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new fn(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=Z(this.view.state.field(Q).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:en.of(t)})}static open(t){return new e(t)}};function mn(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function hn(e){return mn(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var gn=M.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:hn(`#d11`)},".cm-lintRange-warning":{backgroundImage:hn(`orange`)},".cm-lintRange-info":{backgroundImage:hn(`#999`)},".cm-lintRange-hint":{backgroundImage:hn(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function _n(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function vn(e){let t=`hint`,n=1;for(let r of e){let e=_n(r.severity);e>n&&(n=e,t=r.severity)}return t}var yn=[Q,M.decorations.compute([Q],e=>{let{selected:t,panel:n}=e.field(Q);return!t||!n||t.from==t.to?E.none:E.set([tn.range(t.from,t.to)])}),ge(nn,{hideOn:Xt}),gn],bn=[I(),xe(),F(),i(),N(),Se(),ve(),x.allowMultipleSelections.of(!0),S(),O(R,{fallback:!0}),he(),ke(),De(),_e(),L(),ye(),it(),Ce.of([...Ee,...l,...Ht,...a,...we,...Oe,...sn])];F(),i(),Se(),O(R,{fallback:!0}),Ce.of([...l,...a]);var xn={words:0,chars:0,tokens:0},Sn=/[ -〿-ゟ゠-ヿ㐀-䶿一-鿿豈---ក-]/,Cn=/[\p{L}\p{N}]/u,wn=new Set([`text`,`inlineCode`,`code`,`tag`]),Tn=new Set([`html`,`definition`,`footnoteDefinition`,`yaml`,`toml`,`image`,`imageReference`,`mdxFlowExpression`,`mdxTextExpression`,`mdxjsEsm`,`rawMdxFallback`,`rawMdxFallbackMdast`]),En=new Set([`paragraph`,`heading`,`blockquote`,`list`,`listItem`,`thematicBreak`,`table`,`tableRow`,`tableCell`,`mdxJsxFlowElement`,`commentBlock`]);function Dn(e,t){if(!e)return;let n=e.type;if(!Tn.has(n)){if(wn.has(n)){e.value&&(t.push(e.value),n===`code`&&t.push(`
|
|
3
3
|
`));return}if(n===`wikiLink`||n===`wikiLinkEmbed`){let n=e.data?.alias??e.value??``;n&&t.push(n);return}if(Array.isArray(e.children)){for(let n of e.children)Dn(n,t);if(En.has(n)&&t.length>0){let e=t[t.length-1];e&&!e.endsWith(`
|
|
4
4
|
`)&&t.push(`
|
package/dist/public/index.html
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
-->
|
|
49
49
|
<script>(() => { let t = 'system'; try { const r = localStorage.getItem('ok-theme-v1'); if (r === 'light' || r === 'dark' || r === 'system') t = r; } catch {} let dark = t === 'dark'; if (t === 'system') { try { dark = window.matchMedia('(prefers-color-scheme: dark)').matches; } catch {} } if (dark) document.documentElement.classList.add('dark'); if (window.okDesktop) document.documentElement.classList.add('electron-mode'); })();</script>
|
|
50
50
|
<style>html { background-color: #fafafa } html.dark { background-color: #171717 }</style>
|
|
51
|
-
<script type="module" crossorigin src="./assets/index-
|
|
51
|
+
<script type="module" crossorigin src="./assets/index-0Zv6gs2U.js"></script>
|
|
52
52
|
<link rel="modulepreload" crossorigin href="./assets/chunk-CFjPhJqf.js">
|
|
53
53
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-2ej06EnG.js">
|
|
54
54
|
<link rel="modulepreload" crossorigin href="./assets/w3c-keyname-CHcJEDvG.js">
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
<link rel="modulepreload" crossorigin href="./assets/dist-DFcaTwzj.js">
|
|
70
70
|
<link rel="modulepreload" crossorigin href="./assets/dist-BHLnUfd3.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="./assets/trace-api-D6fqC5Nw.js">
|
|
72
|
-
<link rel="modulepreload" crossorigin href="./assets/dist-
|
|
72
|
+
<link rel="modulepreload" crossorigin href="./assets/dist-BkxMNfFN.js">
|
|
73
73
|
<link rel="modulepreload" crossorigin href="./assets/config-context-CVpOcWSZ.js">
|
|
74
74
|
<link rel="modulepreload" crossorigin href="./assets/dist-BVOt51sU.js">
|
|
75
|
-
<link rel="modulepreload" crossorigin href="./assets/config-provider-
|
|
76
|
-
<link rel="modulepreload" crossorigin href="./assets/documents-events-
|
|
75
|
+
<link rel="modulepreload" crossorigin href="./assets/config-provider-NM1p9Zm_.js">
|
|
76
|
+
<link rel="modulepreload" crossorigin href="./assets/documents-events-DFqHwl8q.js">
|
|
77
77
|
<link rel="modulepreload" crossorigin href="./assets/dist-CQw2y-s3.js">
|
|
78
78
|
<link rel="modulepreload" crossorigin href="./assets/propagation-api-BHhJitgG.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="./assets/collapsible-NtcTfAgP.js">
|
|
@@ -84,44 +84,44 @@
|
|
|
84
84
|
<link rel="modulepreload" crossorigin href="./assets/check-Dqb-7gfx.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="./assets/chevron-down-D3nis7uo.js">
|
|
86
86
|
<link rel="modulepreload" crossorigin href="./assets/chevron-right-BfmqRYl8.js">
|
|
87
|
-
<link rel="modulepreload" crossorigin href="./assets/doc-hash-
|
|
87
|
+
<link rel="modulepreload" crossorigin href="./assets/doc-hash-DYyNsXAD.js">
|
|
88
88
|
<link rel="modulepreload" crossorigin href="./assets/startup-marks-ChdnUQ0e.js">
|
|
89
|
-
<link rel="modulepreload" crossorigin href="./assets/prop-types-
|
|
89
|
+
<link rel="modulepreload" crossorigin href="./assets/prop-types-BEZe0Mr0.js">
|
|
90
90
|
<link rel="modulepreload" crossorigin href="./assets/skill-scope-Bt2TwqtA.js">
|
|
91
91
|
<link rel="modulepreload" crossorigin href="./assets/git-branch-DtntyZcb.js">
|
|
92
92
|
<link rel="modulepreload" crossorigin href="./assets/loader-circle-CiIO3Fk-.js">
|
|
93
93
|
<link rel="modulepreload" crossorigin href="./assets/file-tree-rename-validation-BnIyXPzi.js">
|
|
94
94
|
<link rel="modulepreload" crossorigin href="./assets/input-DaVPmsWF.js">
|
|
95
|
-
<link rel="modulepreload" crossorigin href="./assets/DocumentContext-
|
|
95
|
+
<link rel="modulepreload" crossorigin href="./assets/DocumentContext-DzW0Hd8f.js">
|
|
96
96
|
<link rel="modulepreload" crossorigin href="./assets/panel-BH2RZRZQ.js">
|
|
97
|
-
<link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-
|
|
98
|
-
<link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-
|
|
97
|
+
<link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-8OH-dz6h.js">
|
|
98
|
+
<link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-D3bPW_N7.js">
|
|
99
99
|
<link rel="modulepreload" crossorigin href="./assets/checkbox-CF2d2zZW.js">
|
|
100
100
|
<link rel="modulepreload" crossorigin href="./assets/dist-D6OstNsL.js">
|
|
101
|
-
<link rel="modulepreload" crossorigin href="./assets/skills-api-
|
|
101
|
+
<link rel="modulepreload" crossorigin href="./assets/skills-api-CJJjd5CV.js">
|
|
102
102
|
<link rel="modulepreload" crossorigin href="./assets/label-C2i80316.js">
|
|
103
103
|
<link rel="modulepreload" crossorigin href="./assets/radio-group-Cn-Ci2Ym.js">
|
|
104
104
|
<link rel="modulepreload" crossorigin href="./assets/toggle-group-DFnOh2oq.js">
|
|
105
|
-
<link rel="modulepreload" crossorigin href="./assets/EnableSyncConfirmDialog-
|
|
105
|
+
<link rel="modulepreload" crossorigin href="./assets/EnableSyncConfirmDialog-DjDTAYSx.js">
|
|
106
106
|
<link rel="modulepreload" crossorigin href="./assets/refresh-cw-EVALIeLp.js">
|
|
107
107
|
<link rel="modulepreload" crossorigin href="./assets/cursor-CGeB2PU5.js">
|
|
108
|
-
<link rel="modulepreload" crossorigin href="./assets/skill-actions-
|
|
108
|
+
<link rel="modulepreload" crossorigin href="./assets/skill-actions-UwN9vpAE.js">
|
|
109
109
|
<link rel="modulepreload" crossorigin href="./assets/textarea-CHe7do1z.js">
|
|
110
110
|
<link rel="modulepreload" crossorigin href="./assets/external-link-D6GHfiOR.js">
|
|
111
|
-
<link rel="modulepreload" crossorigin href="./assets/keyboard-shortcuts-
|
|
112
|
-
<link rel="modulepreload" crossorigin href="./assets/auth-state-cache-
|
|
111
|
+
<link rel="modulepreload" crossorigin href="./assets/keyboard-shortcuts-DyCddAiu.js">
|
|
112
|
+
<link rel="modulepreload" crossorigin href="./assets/auth-state-cache-Dl3ZiBZL.js">
|
|
113
113
|
<link rel="modulepreload" crossorigin href="./assets/format-Cnb8lT3A.js">
|
|
114
|
-
<link rel="modulepreload" crossorigin href="./assets/selection-context-
|
|
115
|
-
<link rel="modulepreload" crossorigin href="./assets/PropertyPanel-
|
|
114
|
+
<link rel="modulepreload" crossorigin href="./assets/selection-context-DDtYeIS_.js">
|
|
115
|
+
<link rel="modulepreload" crossorigin href="./assets/PropertyPanel-BL6tDKwT.js">
|
|
116
116
|
<link rel="modulepreload" crossorigin href="./assets/miss-dialog-store-Ay7SdCdU.js">
|
|
117
|
-
<link rel="modulepreload" crossorigin href="./assets/pending-receive-nav-store-
|
|
117
|
+
<link rel="modulepreload" crossorigin href="./assets/pending-receive-nav-store-CLwh-9nE.js">
|
|
118
118
|
<link rel="modulepreload" crossorigin href="./assets/chevron-left-C6Q_NKVx.js">
|
|
119
119
|
<link rel="modulepreload" crossorigin href="./assets/agent-presence-0f5jUZHx.js">
|
|
120
120
|
<link rel="modulepreload" crossorigin href="./assets/project-paths-CXBtKZyA.js">
|
|
121
|
-
<link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-
|
|
122
|
-
<link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-
|
|
121
|
+
<link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-BarjCzXT.js">
|
|
122
|
+
<link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-B_RqIRfv.js">
|
|
123
123
|
<link rel="modulepreload" crossorigin href="./assets/mcp-consent-store-B6IQVdzB.js">
|
|
124
|
-
<link rel="modulepreload" crossorigin href="./assets/receive-store-
|
|
124
|
+
<link rel="modulepreload" crossorigin href="./assets/receive-store-BZp1qikL.js">
|
|
125
125
|
<link rel="stylesheet" crossorigin href="./assets/DocumentContext-B0sQn39F.css">
|
|
126
126
|
<link rel="stylesheet" crossorigin href="./assets/index-DJtUU5yP.css">
|
|
127
127
|
</head>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e,
|
|
2
|
-
//# sourceMappingURL=repair-launch-json-
|
|
1
|
+
import{r as e,y as t}from"./init-D3sweWsY.mjs";import{t as n}from"./is-object-Cg453afR.mjs";import{join as r}from"node:path";import{existsSync as i,readFileSync as a}from"node:fs";const o=[[`@inkeep/open-knowledge`,`ui`],[`-y`,`@inkeep/open-knowledge`,`ui`],e];function s(e){if(e.runtimeExecutable===`/bin/sh`&&Array.isArray(e.runtimeArgs)){let t=e.runtimeArgs[2];if(typeof t==`string`){if(t.includes(`# ok-ui-v1`))return`canonical`;if(/# ok-ui-v\d+/.test(t))return`legacy-bare`}return`preserved`}if(e.runtimeExecutable===`npx`&&Array.isArray(e.runtimeArgs)){for(let t of o)if(c(e.runtimeArgs,t))return`legacy-bare`}return`preserved`}function c(e,t){if(e.length!==t.length)return!1;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function l(e){let o=e.logger??u,c=r(e.projectDir,`.claude`,`launch.json`);if(e.reclaimDisableEnv===`1`)return o({event:`launch-json-repair-skipped`,reason:`reclaim-disabled`}),{outcome:{configPath:c,outcome:`skipped-reclaim-disabled`},repairedCount:0};if(!i(c))return{outcome:{configPath:c,outcome:`no-file`},repairedCount:0};let l;try{let e=a(c,`utf-8`).trim();l=e?JSON.parse(e):{}}catch(e){let t=e instanceof Error?e.message:String(e);return o({event:`launch-json-repair-read-failed`,configPath:c,error:t}),{outcome:{configPath:c,outcome:`read-failed`,error:t},repairedCount:0}}if(!n(l)){let e=`launch.json root is not an object`;return o({event:`launch-json-repair-read-failed`,configPath:c,error:e}),{outcome:{configPath:c,outcome:`read-failed`,error:e},repairedCount:0}}let d=l.configurations;if(!Array.isArray(d))return{outcome:{configPath:c,outcome:`no-entry`},repairedCount:0};let f=d.find(e=>n(e)&&e.name===`open-knowledge-ui`);if(!f)return{outcome:{configPath:c,outcome:`no-entry`},repairedCount:0};let p=s(f);if(p===`canonical`)return{outcome:{configPath:c,outcome:`canonical`},repairedCount:0};if(p===`preserved`)return{outcome:{configPath:c,outcome:`preserved`},repairedCount:0};let m=t(e.projectDir,{mode:`published`});if(m.action===`failed`){let e=m.error??`unknown write failure`;return o({event:`launch-json-repair-write-failed`,configPath:c,error:e}),{outcome:{configPath:c,outcome:`write-failed`,error:e},repairedCount:0}}return o({event:`launch-json-repair-applied`,configPath:c}),{outcome:{configPath:c,outcome:`repaired`},repairedCount:1}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{l as repairLaunchJson};
|
|
2
|
+
//# sourceMappingURL=repair-launch-json-rZGx8Hlk.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=repair-mcp-configs-
|
|
1
|
+
import{p as e,x as t}from"./init-D3sweWsY.mjs";import{a as n,f as r,l as i}from"./write-project-skill-DK3lBBLD.mjs";import{t as a}from"./mcp-migrate-event-D0NrGjvc.mjs";import{homedir as o}from"node:os";function s(e){let t=e.logger??u,r=e.home??o(),a=[];if(e.reclaimDisableEnv===`1`)return t({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of n){let n=i[o],s=c(()=>n.configPath(``,r));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:n,home:r,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),n.projectConfigPath){let r=n.projectConfigPath,i=c(()=>r(e.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:n,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(n){let i={scope:n.scope,editorId:n.editorId,configPath:n.configPath},o=e(n.target,n.cwd,n.home,n.configPathOverride);if(o===null)return{...i,outcome:`no-entry`};if(r(o))return{...i,outcome:`canonical`};n.logger(a({scope:n.scope,surface:`cli-repair`,editorId:n.editorId,configPath:n.configPath,priorEntry:o}));let s=t(n.target,n.cwd,{mode:`published`,skipAvailabilityCheck:!0},n.home,n.configPathOverride);if(s.action===`failed`){let e=s.error??`unknown write failure`;return n.logger({event:`mcp-config-repair-write-failed`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,error:e}),{...i,outcome:`write-failed`,error:e}}return s.action===`declined`?(n.logger({event:`mcp-config-repair-declined`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,reason:s.declineReason}),{...i,outcome:`declined`}):{...i,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
|
|
2
|
+
//# sourceMappingURL=repair-mcp-configs-Idc5CsVt.mjs.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{oa as e}from"./server-lock-ltHt39S2-p0c2u2YF.mjs";import{Jr as t,Lr as n,Wr as r,d as i,ei as a,na as o,oa as s,ut as c,zr as l}from"./dist-AG4Gq9ev.mjs";import{t as u}from"./esm-CsQUg9js.mjs";import{l as d,r as f,t as p,u as m}from"./write-project-skill-DK3lBBLD.mjs";import{dirname as h,join as g,resolve as _}from"node:path";import{homedir as v}from"node:os";import{existsSync as y,mkdirSync as b,readFileSync as x,readdirSync as S,rmSync as C,statSync as w,writeFileSync as T}from"node:fs";const E={existsSync:e=>y(e),isDirectory:e=>{try{return w(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>S(e),readFileSync:e=>x(e),writeFileSync:(e,t)=>{T(e,t)},mkdirSync:(e,t)=>{b(e,t)},rmSync:(e,t)=>{C(e,t)}},D={resolveProjectBundledSkillDir:()=>a(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>a(e,{checkDesktop:!1}),readBundledVersion:()=>l(),readRecordedVersion:e=>r(e,`cli-hosts`),writeRecordedVersion:(e,t)=>s(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>t(e),readBundleDecision:(e,t)=>n(e,t),writeBundleDecision:(e,t,n)=>o(e,t,n),removeBundleFromDisk:(e,t)=>f(e,t)};function O(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function k(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(h(t),{recursive:!0}),A(e,t,n)}function A(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=g(e,r),a=g(t,r);n.isDirectory(i)?A(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function j(e,t,n,r,i,a){let o=[],s=g(e,`.agents`,`skills`,t),c=r.existsSync(s),l=!1;try{k(n,s,r),l=!0,o.push({kind:`central`,path:s,outcome:c?`overwritten`:`written`}),i({event:`user-skill-reclaim-central-written`,scope:`user`,path:s,preexisting:c,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`central`,path:s,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-central-failed`,scope:`user`,path:s,error:t})}for(let c of m){let l=g(e,c.hostDir),u=g(l,`skills`,t);if(u===s){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-collapsed-with-central`});continue}if(!r.existsSync(l)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-host-absent`});continue}let d=r.existsSync(u);try{k(n,u,r),o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:d?`overwritten`:`written`}),i({event:`user-skill-reclaim-host-written`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,preexisting:d,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-host-failed`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,error:t})}}return{entries:o,centralWritten:l}}function M(e,t){if(!e)return!1;try{if(!t.existsSync(e))return!1;let n=t.readFileSync(e).toString(`utf8`);return n.includes(`# ok-mcp-v1`)||n.includes(`# ok-mcp-win-v1`)}catch{return!1}}function N(e,t,n,r){let i;try{i=t.resolveProjectBundledSkillDir()}catch(e){return r({event:`project-skill-reclaim-bundle-missing`,scope:`project`,error:e instanceof Error?e.message:String(e)}),{outcome:`skipped`,reason:`bundle-missing`}}let a=[];for(let t of m){let o=g(e,t.hostDir,`skills`,`open-knowledge`),s=g(o,`SKILL.md`),c=n.existsSync(s),l=d[t.editorId]?.projectConfigPath?.(e),u=!c&&M(l,n);if(!c&&!u){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`no-token`}),r({event:`project-skill-reclaim-no-token`,scope:`project`,editorId:t.editorId,path:o});continue}try{p(o,e),k(i,o,n);let s=c?`reclaimed`:`created`;a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:s}),r({event:c?`project-skill-reclaim-reclaimed`:`project-skill-reclaim-created`,scope:`project`,editorId:t.editorId,path:o})}catch(e){let n=e instanceof Error?e.message:String(e);a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`failed`,error:n}),r({event:`project-skill-reclaim-failed`,scope:`project`,editorId:t.editorId,path:o,error:n})}}return{outcome:`done`,entries:a}}async function P(t,n,r,a){let o=e=>{n.recordEvent(e).catch(()=>{})},s=()=>new Date().toISOString(),l;try{l=await n.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return a({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),o({ts:s(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let u;try{u=await n.readRecordedVersion(t)}catch(e){a({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),u=null}let d=[],f=null;for(let e of c)try{d.push({id:e,sourceDir:n.resolveUserBundledSkillDir(e)})}catch(e){f=e instanceof Error?e.message:String(e)}if(d.length===0)return a({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:f??`no user-global bundles`}),o({ts:s(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${f}`}),{outcome:`skipped`,reason:`bundle-missing`};let p=[];for(let o of d){let s=i[o.id],c=r.existsSync(g(t,`.agents`,`skills`,s)),l=await n.readBundleDecision(t,s).catch(()=>null);if(!e(l,{installedOnDisk:c})){if(c)try{n.removeBundleFromDisk(t,o.id),a({event:`user-skill-reclaim-bundle-declined-removed`,scope:`user`,bundle:o.id})}catch(e){a({event:`user-skill-reclaim-bundle-remove-failed`,scope:`user`,bundle:o.id,error:e instanceof Error?e.message:String(e)})}continue}if(l===null&&c)try{await n.writeBundleDecision(t,s,!0)}catch(e){a({event:`user-skill-reclaim-grandfather-write-failed`,scope:`user`,bundle:o.id,error:e instanceof Error?e.message:String(e)})}p.push(o)}if(p.length===0)return{outcome:`skipped`,reason:`all-bundles-declined`};let m=p.every(e=>r.existsSync(g(t,`.agents`,`skills`,i[e.id])));if(u!==null&&u===l&&m)return a({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:l}),{outcome:`skipped`,reason:`version-current`};let h=[],_=d.length===c.length,v=!0;for(let{id:e,sourceDir:n}of p){let o=j(t,i[e],n,r,a,l);h.push(...o.entries),o.centralWritten||(v=!1)}let y=h.some(e=>e.kind===`central`&&(e.outcome===`written`||e.outcome===`overwritten`));if(_&&v&&y){let e=null;try{await n.writeRecordedVersion(t,l),a({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:l})}catch(t){e=t instanceof Error?t.message:String(t),a({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:l,error:e})}for(let{id:t}of p)o({ts:s(),surface:`cli-start`,target:`cli-hosts`,bundle:t,outcome:e===null?`installed`:`failed`,version:l,...e===null?{}:{reason:`state-write-failed:${e}`}})}else{let e=h.some(e=>e.kind===`host`&&e.outcome===`failed`);o({ts:s(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:l,reason:e?`all-writes-failed`:`no-hosts-installed`})}return{outcome:`done`,version:l,entries:h}}async function F(e){let t=e.logger??O,n=e.fs??E,r=e.home??v(),i={...D,...e.deps};return e.reclaimDisableEnv===`1`?(t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`}):{status:`done`,project:N(e.projectDir,i,n,t),user:await P(r,i,n,t)}}function I(e){return e.status===`skipped`?e.reason===`reclaim-disabled`?0:1:e.project.outcome===`skipped`||e.user.outcome===`skipped`&&e.user.reason!==`version-current`&&e.user.reason!==`all-bundles-declined`||e.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function L(e){if(e.status===`skipped`)return`Skipped: ${e.reason}`;let t=[`Skill reclaim complete.`];if(e.project.outcome===`done`){let n=e.project.entries.filter(e=>e.outcome===`reclaimed`).length,r=e.project.entries.filter(e=>e.outcome===`created`).length,i=e.project.entries.filter(e=>e.outcome===`no-token`).length,a=e.project.entries.filter(e=>e.outcome===`failed`).length;t.push(` Project: ${n} reclaimed, ${r} created, ${i} no-token, ${a} failed.`)}else t.push(` Project: skipped (${e.project.reason}).`);if(e.user.outcome===`done`){let n=e.user.entries.filter(e=>e.outcome===`written`||e.outcome===`overwritten`).length,r=e.user.entries.filter(e=>e.outcome===`skipped-host-absent`||e.outcome===`skipped-collapsed-with-central`).length,i=e.user.entries.filter(e=>e.outcome===`failed`).length;t.push(` User (${e.user.version}): ${n} written, ${r} skipped, ${i} failed.`)}else t.push(` User: skipped (${e.user.reason}).`);return t.join(`
|
|
2
|
+
`)}function R(){return new u(`repair-skills`).description("Refresh bundled SKILL.md files for installed AI editors (project-local + user-global). Runs automatically during `ok start`; this command forces an explicit sweep.").action(async()=>{let e=await F({projectDir:_(process.cwd()),reclaimDisableEnv:process.env.OK_RECLAIM_DISABLE??null});process.stdout.write(`${L(e)}\n`),process.exitCode=I(e)})}export{R as n,F as t};
|
|
3
|
+
//# sourceMappingURL=repair-skills-BJsTibpj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./repair-skills-BJsTibpj.mjs";export{e as repairSkills};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as e}from"./server-lock-ltHt39S2-p0c2u2YF.mjs";export{e as updateServerLockPort};
|
|
@@ -446,8 +446,8 @@ $2`).split(`
|
|
|
446
446
|
`),T=e=>{for(let t=0;t<e.length-1;t++){let n=(e[t]??``).trim(),r=(e[t+1]??``).trim(),i=n!==``&&r===``&&I4.test(n),a=n===``&&r!==``&&I4.test(r);if(i||a)return!0}return!1};(T(C)||T(w))&&n.push(`jsx-container-boundary-blank`);let E=e=>e.replace(/^[ \t]+/,``).replace(k4,`1$1`),ee=Math.min(C.length,w.length);for(let e=0;e<ee;e++){let t=C[e]??``,r=w[e]??``;if(t!==r&&E(t)===E(r)&&/^[ \t]*\d+[.)]\s/.test(t)){n.push(`ordered-list-marker-number`);break}}return(/[ \t]\n/.test(_)||/[ \t]\n/.test(v))&&n.push(`trailing-whitespace`),(/[ \t]$/.test(_)||/[ \t]$/.test(v))&&(n.includes(`trailing-whitespace`)||n.push(`trailing-whitespace`)),(/\n{3,}/.test(_)||/\n{3,}/.test(v))&&n.push(`blank-line-collapse`),_.endsWith(`
|
|
447
447
|
`)!==v.endsWith(`
|
|
448
448
|
`)&&n.push(`trailing-newline`),n}const U4=`parse-equivalence`;function W4(e){return e.replace(/^\n+/,``).replace(/\n+$/,``)}function G4(e){return e.replace(/[ \t]+$/gm,``)}const K4=/^([ \t]*)\d+([.)])(?=[ \t])/;function q4(e){return e.split(`
|
|
449
|
-
`).map(e=>e.replace(K4,(e,t,n)=>`${t}1${n}`)).join(``).replace(/\s+/g,``)}const J4=new Set;function Y4(e,t){let n=0;for(let r=0;r<t.length&&n<e.length;r++)e[n]===t[r]&&n++;return n===e.length}function X4(e,t,n){let r=aK(e),i=aK(t);if(r.frontmatter!==i.frontmatter)return!1;if(r.body===i.body)return!0;let a;try{a=n(r.body)}catch(e){let t=e instanceof Error?e.message:String(e);return J4.size<8&&!J4.has(t)&&(J4.add(t),console.warn(`[parse-equivalence] canonicalizeBody threw; treating as not equivalent:`,t)),!1}return W4(G4(a))===W4(G4(i.body))?Y4(q4(r.body),q4(a)):!1}const Z4={setTimeout:(e,t)=>globalThis.setTimeout(e,t),clearTimeout:e=>globalThis.clearTimeout(e),now:()=>Date.now()},Q4={"emphasis-around-code":`pm-model-caused`,bom:`parser-caused`,crlf:`parser-caused`,"commonmark-escape":`parser-caused`,"leading-newline":`parser-caused`,"paragraph-continuation-indent":`parser-caused`,"doc-start-thematic":`parser-caused`,"block-separator-collapse":`serializer-caused`,"table-align-row-spacing":`serializer-caused`,"row-no-trailing-pipe":`serializer-caused`,"ordered-list-marker-number":`serializer-caused`,"list-indent-canonical":`serializer-caused`,"jsx-container-boundary-blank":`serializer-caused`,"trailing-whitespace":`serializer-caused`,"blank-line-collapse":`serializer-caused`,"trailing-newline":`serializer-caused`,"parse-equivalence":`parser-caused`};function $4(e){return Q4[e]}function e3(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e.charCodeAt(r)!==t.charCodeAt(r))return r;return e.length===t.length?-1:n}let t3=null;function n3(e){t3=e}function r3(e,t,n,r){if(!t3||e.length===0)return;let i=e3(t,n),a=new Date().toISOString();for(let t of e)t3({timestamp:a,className:t,documentName:r,codeUnitPosition:i,severity:$4(t)})}const i3=1e4,a3=`last-spawn-error.log`,o3=/^[a-zA-Z0-9][\w/-]*$/;function s3(e){return e.startsWith(`#`)?e.slice(1):e}function c3(e){return typeof e==`string`?[e]:Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function l3(e){if(!e||e.trim()===``)return[];let{map:t}=X2(e);if(!t)return[];let n=c3(t.tags),r=[];for(let e of n){let t=s3(e);o3.test(t)&&r.push(t)}return r}const u3=[`.ok`,`local`,`installed-skills.json`],d3=P(yG),f3=Ys({hosts:M(k()),scope:d3,scripts:j(),installedAt:Uo()}),p3=Ys({schema:F(1),skills:rc(k(),f3).default({})});function m3(){return{schema:1,skills:{}}}function h3(e){let t;try{t=JSON.parse(e)}catch{return null}let n=p3.safeParse(t);return n.success?n.data:null}const g3={id:`string`,kind:`enum`,path:`string`,title:`string`,name:`string`,pathSegments:`string`,content:`string`,modifiedTs:`number`},_3=new WeakMap;function v3(e){return e===void 0||!Number.isFinite(e)?20:Math.max(1,Math.min(100,Math.trunc(e)))}function y3(e){return e.trim().toLowerCase()}const b3=/\.(?:md|mdx)$/;function x3(e,t){if(t!==`page`)return e;let n=e.replace(b3,``);return n.length>0?n:e}function S3(e){let t=e.split(`/`).filter(Boolean);return t[t.length-1]??e}function C3(e){let t=S3(e.path),n=e.title?.trim()||t,r=e.modifiedTs??0,i=e.path.split(`/`).filter(Boolean),a=new Set(i),o=[...new Set((e.aliases??[]).flatMap(e=>e.split(`/`).filter(Boolean)).filter(e=>!a.has(e)))];return{id:`${e.kind}:${e.path}`,kind:e.kind,path:e.path,title:n,name:t,pathSegments:[...i,...o].join(` `),content:e.content??``,modifiedTs:Number.isFinite(r)?r:0}}function w3(e){let t=gW({schema:g3});return e.length>0&&DW(t,e),t}function T3(e){let t={documents:e};return _3.set(t,w3(e)),t}function E3(e){let t=_3.get(e);if(t)return t;let n=w3(e.documents);return _3.set(e,n),n}function D3(e){return e===`autocomplete`?[`page`]:e===`full_text`?[`page`,`content`,`file`]:[`page`,`folder`,`file`]}function O3(e,t){return t.has(e.kind)?!0:e.kind===`page`&&t.has(`content`)}function k3(e,t){let n=y3(t);if(!n)return 0;let r=x3(n,e.kind),i=y3(e.title),a=y3(e.name),o=y3(e.path),s=o.split(`/`);return i===r||a===r?700:o===r?650:i.startsWith(r)||a.startsWith(r)?600:s.some(e=>e.startsWith(r))?550:i.includes(r)||a.includes(r)?500:o.includes(r)?450:-1}function A3(e,t){let n=k3(e,t);return n<=0?n:dq(e.path)?n*.5:n}function j3(e){return e===`file`?-60:0}function M3(e,t,n,r,i){let a=i>0?t/i:0,o=n/50,s=r===`file`?-.001:0,c=1*a+1*o+s;return e*1e3+c}function N3(e,t,n,r){return e+t*20+n+j3(r)}function P3(e,t,n,r,i,a){return e===`relevance`?N3(t,n,r,i):M3(t,n,r,i,a)}function F3(e,t){return t||(e===`full_text`?`relevance`:`navigation`)}function I3(e,t){let n=0;for(let r of e){let e=t.get(r.id)??0;e>n&&(n=e)}return n}function L3(e){let t=e.map(e=>e.modifiedTs).filter(e=>Number.isFinite(e)&&e>0);if(t.length===0)return new Map;let n=1/0,r=-1/0;for(let e of t)e<n&&(n=e),e>r&&(r=e);let i=Math.max(1,r-n);return new Map(e.map(e=>[e.id,e.modifiedTs>0?(e.modifiedTs-n)/i*50:0]))}function R3(e){return e===`full_text`?[`title`,`name`,`path`,`pathSegments`,`content`]:[`title`,`name`,`path`,`pathSegments`]}function z3(e){return e===`full_text`?{title:8,name:7,path:5,pathSegments:4,content:1}:e===`autocomplete`?{title:10,name:9,path:5,pathSegments:4}:{title:8,name:7,path:5,pathSegments:4}}function B3(e,t){return y3(t).length<4?0:e===`full_text`?1:0}function V3(e){let{lexical:t,fullText:n}=e.signals;return t>=500?`lexical`:t===450&&n<=0?`pathOnly`:`body`}function H3(e){let t=[],n=[],r=[];for(let i of e){let e=V3(i);e===`lexical`?t.length<100&&t.push(i):e===`body`?n.length<6&&n.push(i):r.length<4&&r.push(i)}return[...t,...n,...r]}function U3(e,t,n){if(t===`relevance`)return e.slice(0,n);let r=H3(e),i=[],a=0,o=0;for(let e of r){if(e.document.kind===`folder`){if(a>=3)continue;a+=1}else if(e.document.kind===`file`){if(o>=3)continue;o+=1}if(i.push(e),i.length>=n)break}return i}function W3(e,t,n={}){let r=n.intent??`omnibar`,i=F3(r,n.ranking),a=v3(n.limit),o=new Set(n.scopes??D3(r)),s=e.documents.filter(e=>O3(e,o)),c=y3(t);if(!c)return s.slice().sort((e,t)=>e.path.localeCompare(t.path)).slice(0,a).map(e=>({document:e,score:0,signals:{lexical:0,fullText:0,recency:0}}));let l=rG(E3(e),{term:c,properties:R3(r),boost:z3(r),tolerance:B3(r,c),limit:Math.max(a*4,40)}),u=new Map(l.hits.filter(e=>O3(e.document,o)).map(e=>[e.document.id,e.score])),d=L3(s),f=new Map;for(let e of s)A3(e,c)>=0&&f.set(e.id,e);for(let e of l.hits)O3(e.document,o)&&f.set(e.document.id,e.document);if(!n.semantic){let e=I3(f.values(),u);return U3([...f.values()].map(t=>{let n=Math.max(0,A3(t,c)),r=u.get(t.id)??0,a=d.get(t.id)??0;return{document:t,score:P3(i,n,r,a,t.kind,e),signals:{lexical:n,fullText:r,recency:a}}}).sort((e,t)=>e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score),i,a)}return U3(K3({scopedDocuments:s,candidates:f,fullTextScores:u,recency:d,normalizedQuery:c,ranking:i,semantic:n.semantic}),i,a)}function G3(e){let t=new Map;return e.forEach((e,n)=>{t.set(e,n+1)}),t}function K3(e){let{scopedDocuments:t,candidates:n,fullTextScores:r,recency:i,normalizedQuery:a,ranking:o,semantic:s}=e,c=s.rrfK??60,l=s.candidateLimit??64,u=s.similarityFloor??0,d=s.scores,f=new Map(t.map(e=>[e.id,e])),p=[...d.entries()].filter(([e,t])=>t>=u&&f.has(e)).sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,l);for(let[e]of p)if(!n.has(e)){let t=f.get(e);t&&n.set(e,t)}let m=I3(n.values(),r),h=[...n.values()].map(e=>{let t=Math.max(0,A3(e,a)),n=r.get(e.id)??0,s=i.get(e.id)??0,c=d.get(e.id),l=c!==void 0&&c>=u;return{document:e,score:t>0?P3(o,t,n,s,e.kind,m):N3(t,n,s,e.kind),signals:l?{lexical:t,fullText:n,recency:s,vector:c}:{lexical:t,fullText:n,recency:s},lexical:t,fullText:n,recency:s,cosine:c}}),g=G3(h.filter(e=>e.fullText>0).sort((e,t)=>t.fullText-e.fullText||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),_=G3(h.filter(e=>e.cosine!==void 0&&e.cosine>=u).sort((e,t)=>t.cosine-e.cosine||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),v=e=>{let t=0,n=g.get(e);n!==void 0&&(t+=1/(c+n));let r=_.get(e);return r!==void 0&&(t+=1/(c+r)),t};return h.sort((e,t)=>{let n=e.lexical>0?1:0,r=t.lexical>0?1:0;if(n!==r)return r-n;if(n===1)return e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score;let i=v(e.document.id),a=v(t.document.id);return i===a?e.recency===t.recency?e.document.path.localeCompare(t.document.path):t.recency-e.recency:a-i}).map(({document:e,score:t,signals:n})=>({document:e,score:t,signals:n}))}function q3(e){let t=new TextEncoder().encode(e),n=new Uint8Array(1+t.length);return n[0]=1,n.set(t,1),J3(n)}function J3(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}const Y3=Symbol.for(`@inkeep/open-knowledge/skill-state-field-registry`),X3=globalThis;X3[Y3]===void 0&&(X3[Y3]=Ii());const Z3=X3[Y3],Q3=[`.ok`,`skill-state.yml`],$3=[`claude-cowork`,`cli-hosts`],e6=[`server-build-and-open`,`electron-build-and-open`,`cli-npx-skills-add`,`desktop-direct`,`cli-start`],t6=/^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/,n6=Ys({version:k().regex(t6,`version must match /^\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?$/`).register(Z3,{description:`Recorded skill version for this target.`}),recordedAt:Uo().register(Z3,{description:`ISO 8601 timestamp of the most recent successful write. Updated on every write, including reinstalls of the same version.`}),surface:P(e6).register(Z3,{description:`Install-source surface that recorded this entry.`}).optional()}),r6=Ys({schema:F(1).register(Z3,{description:`Schema major version. Bumped only on breaking shape changes.`}),targets:Ys({"claude-cowork":n6.optional(),"cli-hosts":n6.optional()}).register(Z3,{description:`Per-target install-state entries. Absent target = no recorded install.`}).default({})});function i6(){return{schema:1,targets:{}}}const a6=`template`;function o6(e){if(e.trim()===``)return{};let t;try{t=(0,Nc.parse)(e)}catch{return{}}return typeof t!=`object`||!t||Array.isArray(t)?{}:t}function s6(e,t){return e.trim()===``?t:`---\n${e}\n---\n${t}`}function c6(e){let{frontmatter:t,body:n}=aK(e);return t===``?{docFrontmatterText:``,markdown:e}:{docFrontmatterText:sK(t),markdown:n}}function l6(e){let t=e.split(`
|
|
450
|
-
`);if(!(t[0]??``).startsWith(`template:`))return null;let n=[t[0]??``],r=1;for(;r<t.length;){let e=t[r]??``;if(/^[ \t]/.test(e)){n.push(e),r++;continue}if(e.trim()===``){let i=r+1;for(;i<t.length&&(t[i]??``).trim()===``;)i++;if(i<t.length&&/^[ \t]/.test(t[i]??``)){n.push(e),r++;continue}}break}let i=
|
|
451
|
-
`))[
|
|
452
|
-
`).replace(/\n+$/,``)}}function u6(e){let t=e.charCodeAt(0)===65279?e.slice(1):e,{frontmatter:n,body:r}=aK(t);if(n===``)return{identity:{},starterContent:t};let i=sK(n),a=l6(i);if(a)return{identity:a.identity,starterContent:s6(a.docFrontmatterText,r)};let{frontmatter:o}=aK(r);if(o!==``)return{identity:o6(i),starterContent:r};let s=o6(i);return typeof s.title==`string`?{identity:s,starterContent:r}:{identity:{},starterContent:s6(i,r)}}function d6(e,t){let{docFrontmatterText:n,markdown:r}=c6(t),i={};for(let[t,n]of Object.entries(e))n!==void 0&&(i[t]=n);let a=(0,Nc.stringify)({[a6]:i});return`---\n${n.trim()===``?a:`${a}${n}\n`}---\n${r}`}function f6(e){return u6(e).starterContent}function p6(){let e=!1,t=``,n=0;return r=>{let i=m6(r);return e?(i&&i.char===t&&i.len>=n&&!i.hasInfo&&(e=!1,t=``,n=0),!0):i?(e=!0,t=i.char,n=i.len,!0):!1}}function m6(e){let t=(e.endsWith(`\r`)?e.slice(0,-1):e).match(/^ {0,3}([`~])(\1{2,})(.*)$/);return t?{char:t[1],len:1+t[2].length,hasInfo:t[3].trim()!==``}:null}const h6=[`#D97757`,`#1B1912`,`#F9F3E9`,`#7A9DFF`,`#8534F3`,`#9663F0`,`#727CF3`],g6={claude:`#D97757`,cursor:`#1B1912`,windsurf:`#0B100F`,openai:`#7A9DFF`,github:`#8534F3`,cline:`#9663F0`,bot:`#727CF3`};function _6(e,t=h6){let n=0;for(let t of e)n=(n<<5)-n+t.charCodeAt(0)|0;return t[Math.abs(n)%t.length]}const v6={"claude-code":`claude`,"claude-ai":`claude`,cursor:`cursor`,"cursor-vscode":`cursor`,cascade:`windsurf`,codex:`openai`,"codex-mcp-client":`openai`,copilot:`github`,cline:`cline`};function y6(e){return e?v6[e]||(e.startsWith(`local-agent-mode-`)?`claude`:`bot`):`bot`}const b6={claude:`Claude`,cursor:`Cursor`,windsurf:`Windsurf`,openai:`Codex`,github:`Copilot`,cline:`Cline`};function x6(e){let t=e?.trim();return t?b6[y6(t)]??t:`Agent`}function S6(e,t){let n=e.trim();if(!n||/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=r>=0?n.slice(0,r):n,a=r>=0?n.slice(r+1):null,o=(i.split(`?`)[0]??``).trim();if(!o)return null;let s=(o.split(`/`).pop()??``).match(/\.([a-z0-9]+)$/i);if(s){let e=(s[1]??``).toLowerCase();if(e!==`md`&&e!==`mdx`)return null}let c=o.toLowerCase(),l=c.endsWith(`.mdx`)?o.slice(0,-4):c.endsWith(`.md`)?o.slice(0,-3):o,u=l.startsWith(`/`),d=u?l.slice(1):l,f=u?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of d.split(`/`))if(e===`..`){if(f.length===0)return null;f.pop()}else e!==`.`&&e!==``&&f.push(e);return f.length===0?null:{docName:f.join(`/`),anchor:a||null}}const C6=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function w6(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function T6(e){let t=e.trim();return C6.test(t)||t.startsWith(`//`)}function E6(e,t){let n=e.trim();if(!n)return null;if(n.startsWith(`#`)){let e=n.slice(1).trim();return e?{kind:`anchor`,anchor:e}:null}if(T6(n))return{kind:`external`,url:n};let r=S6(n,t);if(r)return{kind:`doc`,docName:r.docName,anchor:r.anchor};let i=w6(n);return i&&i!==`md`&&i!==`mdx`?{kind:`asset`,url:n,ext:i}:null}function D6(e,t){let n=e.trim();if(!n)return null;if(T6(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=w6(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function O6(e,t){let n=e.trim();if(!n||C6.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=((r>=0?n.slice(0,r):n).split(`?`)[0]??``).trim();if(!i)return null;let a=i.startsWith(`/`),o=a?i.slice(1):i,s=a?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of o.split(`/`))if(e===`..`){if(s.length===0)return null;s.pop()}else e!==`.`&&e!==``&&s.push(e);return s.length===0?null:s.join(`/`)}function k6(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),t.startsWith(`/`)&&(t=t.slice(1)),t}function A6(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function j6(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function M6(e){return e.split(`/`).filter(e=>e!==``)}function N6(e,t){let n=j6(t);return e===``||n===e?!0:n.startsWith(`${e}/`)}function P6(e,t){let n=j6(t);if(e===n)return 0;let r=e===``?n:n.slice(e.length+1);return r===``?0:M6(r).length}function F6(e,t){let n=M6(e),r=M6(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return n.length-i+(r.length-i)}function I6(){let e=new Map;function t(t){let n=k6(t);if(n===``)return;let r=A6(n);if(r===``)return;let i=r.toLowerCase(),a=e.get(i);if(!a){e.set(i,[n]);return}a.includes(n)||a.push(n)}function n(t){let n=k6(t),r=A6(n).toLowerCase(),i=e.get(r);if(!i)return;let a=i.indexOf(n);a!==-1&&(i.splice(a,1),i.length===0&&e.delete(r))}function r(e,r){n(e),t(r)}function i(t,n){let r=t.toLowerCase(),i=e.get(r);if(!i||i.length===0)return null;if(i.length===1)return i[0];let a=j6(k6(n)),o=[],s=[];for(let e of i)N6(a,e)?o.push(e):s.push(e);return o.length>0?(e=>{let t=e[0],n=P6(a,t);for(let r=1;r<e.length;r++){let i=e[r],o=P6(a,i);(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(o):(e=>{let t=e[0],n=F6(a,j6(t));for(let r=1;r<e.length;r++){let i=e[r],o=F6(a,j6(i));(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(s)}function a(){let t=new Map;for(let[n,r]of e)t.set(n,[...r]);return t}function o(){e.clear()}return{add:t,remove:n,rename:r,resolveEmbed:i,clear:o,snapshot:a,size:()=>e.size}}function L6(e){if(!e)return[];let t=e.split(`/`),n=[],r=``;for(let e of t)r=r?`${r}/${e}`:e,n.push(r);return n}function R6(e,t){if(e.size===0)return new Set;if(t===``)return new Set(e);let n=new Set,r=`${t}/`;for(let i of e)(i===t||i.startsWith(r))&&n.add(i);return n}function z6(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function B6(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function V6(){try{let e=l(c(d(import.meta.url)),`..`,`package.json`),t=JSON.parse(v(e,`utf-8`));if(typeof t.version==`string`&&t.version.length>0)return t.version}catch{}return`0.0.0-unknown`}const H6=V6(),U6=1;var W6=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function G6(e,t){return l(e,`${t}.lock`)}const K6=new Map;function q6(e){K6.set(e,(K6.get(e)??0)+1)}function J6(e){let t=K6.get(e);return t===void 0||t<=1?(K6.delete(e),!0):(K6.set(e,t-1),!1)}function Y6(e,t){try{let n=JSON.parse(v(e,`utf-8`));return n&&typeof n==`object`&&B6(n.pid)?n:(console.warn(`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return console.warn(`${t} Corrupt lock file at ${e} — replacing`),null}}function X6(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;g(n,{recursive:!0});let a=G6(n,t),o={pid:process.pid,hostname:p(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??H6},s=JSON.stringify(o,null,2);for(let e=0;e<3;e++){if(!h(a))try{let e=_(a,`wx`,384);try{x(e,s)}finally{m(e)}return q6(a),Z6({lockName:t,lockDir:n,lockPath:a})}catch(e){if(e.code!==`EEXIST`)throw e}let e=Y6(a,i);if(e){let r=e.hostname===p();if(r&&e.pid===process.pid)return b(a,s,{encoding:`utf-8`,mode:384}),q6(a),Z6({lockName:t,lockDir:n,lockPath:a});if(r&&z6(e.pid))throw new W6(e,a,t);console.warn(`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{y(a)}catch{}}throw Error(`${i} Failed to acquire ${a} after 3 attempts (concurrent acquire contention).`)}function Z6(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>t8({lockName:t,lockDir:n}),updatePort:e=>Q6({lockName:t,lockDir:n,port:e})}}function Q6(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,a=G6(n,t);if(!h(a)){console.warn(`${i} Lock file missing at ${a} during port update — skipping`);return}let o;try{let e=JSON.parse(v(a,`utf-8`));if(!e||typeof e!=`object`||!B6(e.pid)){console.warn(`${i} Corrupt lock at ${a} during port update — skipping`);return}o=e}catch{console.warn(`${i} Unreadable lock at ${a} during port update — skipping`);return}if(o.pid===process.pid&&!(typeof o.hostname==`string`&&o.hostname!==p())){o.port=r;try{b(a,JSON.stringify(o,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${i} Failed to update port in ${a}: ${e instanceof Error?e.message:String(e)}`)}}}function $6(e){let{lockName:t,lockDir:n}=e,r=G6(n,t);if(!h(r))return null;let i;try{let e=JSON.parse(v(r,`utf-8`));if(!e||typeof e!=`object`||!B6(e.pid))return null;i=e}catch{return null}if(i.hostname!==p())return null;if(!z6(i.pid)){try{y(r)}catch{}return null}return i}function e8(e){let{lockName:t,lockDir:n}=e,r=G6(n,t);if(!h(r))return{status:`absent`};let i;try{i=JSON.parse(v(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!B6(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o={pid:a.pid,hostname:a.hostname,port:a.port,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(o.hostname!==p())return{status:`stale`,lock:o};if(!z6(o.pid)){try{y(r)}catch{}return{status:`stale`,lock:o}}return o.protocolVersion===void 0||o.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:o}}function t8(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=G6(n,t);if(J6(i)&&h(i))try{let e=JSON.parse(v(i,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||typeof e.hostname==`string`&&e.hostname!==p())return;y(i)}catch(e){console.warn(`${r} Failed to release ${i}: ${e instanceof Error?e.message:String(e)}`)}}var n8=class extends W6{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function r8(e,t){try{return X6({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof W6&&e.lockName===`server`?new n8(e.existing,e.lockPath):e}}function i8(e,t){Q6({lockName:`server`,lockDir:e,port:t})}function a8(e){return $6({lockName:`server`,lockDir:e})}function o8(e){t8({lockName:`server`,lockDir:e})}export{mG as $,Tl as $a,h$ as $i,u2 as $n,K2 as $r,vG as $t,Xq as A,bl as Aa,nq as Ai,uG as An,un as Ao,m0 as Ar,U$ as At,L2 as B,qc as Ba,Aq as Bi,Jq as Bn,H0 as Br,p3 as Bt,B$ as C,tp as Ca,L6 as Ci,J0 as Cn,Vo as Co,rJ as Cr,a1 as Ct,z$ as D,Cl as Da,o$ as Di,k0 as Dn,ai as Do,_0 as Dr,R0 as Dt,T$ as E,nu as Ea,IQ as Ei,t6 as En,Ga as Eo,g0 as Er,L0 as Et,x4 as F,Jc as Fa,dq as Fi,x0 as Fn,Tt as Fo,N0 as Fr,m1 as Ft,M2 as G,Kl as Ga,OG as Gi,Dq as Gn,P1 as Gr,w1 as Gt,F2 as H,Dl as Ha,v4 as Hi,bq as Hn,V0 as Hr,n1 as Ht,I$ as I,ll as Ia,zq as Ii,S0 as In,O as Io,W0 as Ir,u3 as It,dG as J,Xl as Ja,EG as Ji,Kq as Jn,o0 as Jr,C1 as Jt,j2 as K,Ul as Ka,h3 as Ki,kq as Kn,M1 as Kr,T1 as Kt,I2 as L,iu as La,bG as Li,T0 as Ln,D as Lo,B0 as Lr,E0 as Lt,X$ as M,_l as Ma,f6 as Mi,s1 as Mn,mn as Mo,a6 as Mr,VG as Mt,Vq as N,gl as Na,Mq as Ni,S2 as Nn,on as No,Z0 as Nr,l1 as Nt,w$ as O,Yc as Oa,e$ as Oi,a3 as On,vr as Oo,v0 as Or,$$ as Ot,f4 as P,Wc as Pa,C$ as Pi,E2 as Pn,Lt as Po,F0 as Pr,u1 as Pt,fG as Q,Ml as Qa,YG as Qi,l2 as Qn,d1 as Qr,_G as Qt,B2 as R,ru as Ra,KG as Ri,b0 as Rn,pt as Ro,G0 as Rr,O0 as Rt,E$ as S,db as Sa,q3 as Si,xG as Sn,Uo as So,V1 as Sr,zG as St,V$ as T,Gc as Ta,u4 as Ti,$3 as Tn,Wa as To,y0 as Tr,I0 as Tt,A2 as U,Pl as Ua,V4 as Ui,Tq as Un,F1 as Ur,E1 as Ut,R2 as V,Kc as Va,NG as Vi,_q as Vn,U0 as Vr,FG as Vt,N2 as W,tu as Wa,X2 as Wi,wq as Wn,N1 as Wr,x1 as Wt,gG as X,xl as Xa,u6 as Xi,f2 as Xn,tJ as Xr,v1 as Xt,cG as Y,ul as Ya,M0 as Yi,a2 as Yn,UG as Yr,S1 as Yt,hG as Z,Fl as Za,oK as Zi,d2 as Zn,eJ as Zr,b1 as Zt,g6 as _,d4 as _a,t4 as _i,t0 as _n,rc as _o,h2 as _r,q$ as _t,X6 as a,O6 as aa,D6 as ai,I1 as an,Hs as ao,s2 as ar,q1 as at,A1 as b,lq as ba,m3 as bi,s0 as bn,Ws as bo,i2 as br,RG as bt,B6 as c,W3 as ca,d6 as ci,U4 as cn,kc as co,b2 as cr,K1 as ct,e8 as d,oq as da,p6 as di,BG as dn,F as do,r6 as dr,i3 as dt,g4 as ea,G2 as ei,yG as en,El as eo,$0 as er,pG as et,a8 as f,cq as fa,uZ as fi,sG as fn,Ys as fo,A0 as fr,IG as ft,i8 as g,R6 as ga,H4 as gi,$q as gn,Mc as go,j0 as gr,J$ as gt,Q6 as h,aK as ha,Z4 as hi,Yq as hn,lc as ho,y2 as hr,i0 as ht,n8 as i,g$ as ia,E6 as ii,L1 as in,Bs as io,o2 as ir,G$ as it,Z$ as j,vl as ja,y6 as ji,o1 as jn,fn as jo,h0 as jr,b$ as jt,R$ as k,yl as ka,nY as ki,PG as kn,cn as ko,p0 as kr,H$ as kt,G6 as l,Z2 as la,X0 as li,JG as ln,$s as lo,x2 as lr,WG as lt,o8 as m,m4 as ma,C3 as mi,Z1 as mn,N as mo,v2 as mr,r0 as mt,H6 as n,i4 as na,Qq as ni,LQ as nn,cc as no,O2 as nr,Wq as nt,r8 as o,S6 as oa,lG as oi,GG as on,M as oo,t2 as or,J1 as ot,t8 as p,kG as pa,T3 as pi,$1 as pn,A as po,_2 as pr,g1 as pt,k2 as q,Sl as qa,jG as qi,Gq as qn,a0 as qr,nJ as qt,U6 as r,h4 as ra,Rq as ri,z1 as rn,P as ro,m2 as rr,W$ as rt,z6 as s,wG as sa,_6 as si,p1 as sn,j as so,n2 as sr,G1 as st,W6 as t,SG as ta,l4 as ti,qG as tn,Fs as to,p2 as tr,Hq as tt,$6 as u,n3 as ua,I6 as ui,XG as un,tc as uo,q0 as ur,ZG as ut,LG as v,QQ as va,x6 as vi,n0 as vn,k as vo,g2 as vr,Y1 as vt,D$ as w,I as wa,l3 as wi,Q3 as wn,fa as wo,_1 as wr,W1 as wt,j1 as x,e4 as xa,i6 as xi,c0 as xn,ys as xo,e2 as xr,HG as xt,P$ as y,sK as ya,r3 as yi,f1 as yn,Zs as yo,r2 as yr,X1 as yt,z2 as z,Ql as za,X4 as zi,T2 as zn,ft as zo,K0 as zr,B1 as zt};
|
|
453
|
-
//# sourceMappingURL=server-lock-ltHt39S2-
|
|
449
|
+
`).map(e=>e.replace(K4,(e,t,n)=>`${t}1${n}`)).join(``).replace(/\s+/g,``)}const J4=new Set;function Y4(e,t){let n=0;for(let r=0;r<t.length&&n<e.length;r++)e[n]===t[r]&&n++;return n===e.length}function X4(e,t,n){let r=aK(e),i=aK(t);if(r.frontmatter!==i.frontmatter)return!1;if(r.body===i.body)return!0;let a;try{a=n(r.body)}catch(e){let t=e instanceof Error?e.message:String(e);return J4.size<8&&!J4.has(t)&&(J4.add(t),console.warn(`[parse-equivalence] canonicalizeBody threw; treating as not equivalent:`,t)),!1}return W4(G4(a))===W4(G4(i.body))?Y4(q4(r.body),q4(a)):!1}const Z4={setTimeout:(e,t)=>globalThis.setTimeout(e,t),clearTimeout:e=>globalThis.clearTimeout(e),now:()=>Date.now()},Q4={"emphasis-around-code":`pm-model-caused`,bom:`parser-caused`,crlf:`parser-caused`,"commonmark-escape":`parser-caused`,"leading-newline":`parser-caused`,"paragraph-continuation-indent":`parser-caused`,"doc-start-thematic":`parser-caused`,"block-separator-collapse":`serializer-caused`,"table-align-row-spacing":`serializer-caused`,"row-no-trailing-pipe":`serializer-caused`,"ordered-list-marker-number":`serializer-caused`,"list-indent-canonical":`serializer-caused`,"jsx-container-boundary-blank":`serializer-caused`,"trailing-whitespace":`serializer-caused`,"blank-line-collapse":`serializer-caused`,"trailing-newline":`serializer-caused`,"parse-equivalence":`parser-caused`};function $4(e){return Q4[e]}function e3(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e.charCodeAt(r)!==t.charCodeAt(r))return r;return e.length===t.length?-1:n}let t3=null;function n3(e){t3=e}function r3(e,t,n,r){if(!t3||e.length===0)return;let i=e3(t,n),a=new Date().toISOString();for(let t of e)t3({timestamp:a,className:t,documentName:r,codeUnitPosition:i,severity:$4(t)})}const i3=1e4,a3=`last-spawn-error.log`,o3=/^[a-zA-Z0-9][\w/-]*$/;function s3(e){return e.startsWith(`#`)?e.slice(1):e}function c3(e){return typeof e==`string`?[e]:Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function l3(e){if(!e||e.trim()===``)return[];let{map:t}=X2(e);if(!t)return[];let n=c3(t.tags),r=[];for(let e of n){let t=s3(e);o3.test(t)&&r.push(t)}return r}const u3=[`.ok`,`local`,`installed-skills.json`],d3=P(yG),f3=Ys({hosts:M(k()),scope:d3,scripts:j(),installedAt:Uo()}),p3=Ys({schema:F(1),skills:rc(k(),f3).default({})});function m3(){return{schema:1,skills:{}}}function h3(e){let t;try{t=JSON.parse(e)}catch{return null}let n=p3.safeParse(t);return n.success?n.data:null}const g3={id:`string`,kind:`enum`,path:`string`,title:`string`,name:`string`,pathSegments:`string`,content:`string`,modifiedTs:`number`},_3=new WeakMap;function v3(e){return e===void 0||!Number.isFinite(e)?20:Math.max(1,Math.min(100,Math.trunc(e)))}function y3(e){return e.trim().toLowerCase()}const b3=/\.(?:md|mdx)$/;function x3(e,t){if(t!==`page`)return e;let n=e.replace(b3,``);return n.length>0?n:e}function S3(e){let t=e.split(`/`).filter(Boolean);return t[t.length-1]??e}function C3(e){let t=S3(e.path),n=e.title?.trim()||t,r=e.modifiedTs??0,i=e.path.split(`/`).filter(Boolean),a=new Set(i),o=[...new Set((e.aliases??[]).flatMap(e=>e.split(`/`).filter(Boolean)).filter(e=>!a.has(e)))];return{id:`${e.kind}:${e.path}`,kind:e.kind,path:e.path,title:n,name:t,pathSegments:[...i,...o].join(` `),content:e.content??``,modifiedTs:Number.isFinite(r)?r:0}}function w3(e){let t=gW({schema:g3});return e.length>0&&DW(t,e),t}function T3(e){let t={documents:e};return _3.set(t,w3(e)),t}function E3(e){let t=_3.get(e);if(t)return t;let n=w3(e.documents);return _3.set(e,n),n}function D3(e){return e===`autocomplete`?[`page`]:e===`full_text`?[`page`,`content`,`file`]:[`page`,`folder`,`file`]}function O3(e,t){return t.has(e.kind)?!0:e.kind===`page`&&t.has(`content`)}function k3(e,t){let n=y3(t);if(!n)return 0;let r=x3(n,e.kind),i=y3(e.title),a=y3(e.name),o=y3(e.path),s=o.split(`/`);return i===r||a===r?700:o===r?650:i.startsWith(r)||a.startsWith(r)?600:s.some(e=>e.startsWith(r))?550:i.includes(r)||a.includes(r)?500:o.includes(r)?450:-1}function A3(e,t){let n=k3(e,t);return n<=0?n:dq(e.path)?n*.5:n}function j3(e){return e===`file`?-60:0}function M3(e,t,n,r,i){let a=i>0?t/i:0,o=n/50,s=r===`file`?-.001:0,c=1*a+1*o+s;return e*1e3+c}function N3(e,t,n,r){return e+t*20+n+j3(r)}function P3(e,t,n,r,i,a){return e===`relevance`?N3(t,n,r,i):M3(t,n,r,i,a)}function F3(e,t){return t||(e===`full_text`?`relevance`:`navigation`)}function I3(e,t){let n=0;for(let r of e){let e=t.get(r.id)??0;e>n&&(n=e)}return n}function L3(e){let t=e.map(e=>e.modifiedTs).filter(e=>Number.isFinite(e)&&e>0);if(t.length===0)return new Map;let n=1/0,r=-1/0;for(let e of t)e<n&&(n=e),e>r&&(r=e);let i=Math.max(1,r-n);return new Map(e.map(e=>[e.id,e.modifiedTs>0?(e.modifiedTs-n)/i*50:0]))}function R3(e){return e===`full_text`?[`title`,`name`,`path`,`pathSegments`,`content`]:[`title`,`name`,`path`,`pathSegments`]}function z3(e){return e===`full_text`?{title:8,name:7,path:5,pathSegments:4,content:1}:e===`autocomplete`?{title:10,name:9,path:5,pathSegments:4}:{title:8,name:7,path:5,pathSegments:4}}function B3(e,t){return y3(t).length<4?0:e===`full_text`?1:0}function V3(e){let{lexical:t,fullText:n}=e.signals;return t>=500?`lexical`:t===450&&n<=0?`pathOnly`:`body`}function H3(e){let t=[],n=[],r=[];for(let i of e){let e=V3(i);e===`lexical`?t.length<100&&t.push(i):e===`body`?n.length<6&&n.push(i):r.length<4&&r.push(i)}return[...t,...n,...r]}function U3(e,t,n){if(t===`relevance`)return e.slice(0,n);let r=H3(e),i=[],a=0,o=0;for(let e of r){if(e.document.kind===`folder`){if(a>=3)continue;a+=1}else if(e.document.kind===`file`){if(o>=3)continue;o+=1}if(i.push(e),i.length>=n)break}return i}function W3(e,t,n={}){let r=n.intent??`omnibar`,i=F3(r,n.ranking),a=v3(n.limit),o=new Set(n.scopes??D3(r)),s=e.documents.filter(e=>O3(e,o)),c=y3(t);if(!c)return s.slice().sort((e,t)=>e.path.localeCompare(t.path)).slice(0,a).map(e=>({document:e,score:0,signals:{lexical:0,fullText:0,recency:0}}));let l=rG(E3(e),{term:c,properties:R3(r),boost:z3(r),tolerance:B3(r,c),limit:Math.max(a*4,40)}),u=new Map(l.hits.filter(e=>O3(e.document,o)).map(e=>[e.document.id,e.score])),d=L3(s),f=new Map;for(let e of s)A3(e,c)>=0&&f.set(e.id,e);for(let e of l.hits)O3(e.document,o)&&f.set(e.document.id,e.document);if(!n.semantic){let e=I3(f.values(),u);return U3([...f.values()].map(t=>{let n=Math.max(0,A3(t,c)),r=u.get(t.id)??0,a=d.get(t.id)??0;return{document:t,score:P3(i,n,r,a,t.kind,e),signals:{lexical:n,fullText:r,recency:a}}}).sort((e,t)=>e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score),i,a)}return U3(K3({scopedDocuments:s,candidates:f,fullTextScores:u,recency:d,normalizedQuery:c,ranking:i,semantic:n.semantic}),i,a)}function G3(e){let t=new Map;return e.forEach((e,n)=>{t.set(e,n+1)}),t}function K3(e){let{scopedDocuments:t,candidates:n,fullTextScores:r,recency:i,normalizedQuery:a,ranking:o,semantic:s}=e,c=s.rrfK??60,l=s.candidateLimit??64,u=s.similarityFloor??0,d=s.scores,f=new Map(t.map(e=>[e.id,e])),p=[...d.entries()].filter(([e,t])=>t>=u&&f.has(e)).sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,l);for(let[e]of p)if(!n.has(e)){let t=f.get(e);t&&n.set(e,t)}let m=I3(n.values(),r),h=[...n.values()].map(e=>{let t=Math.max(0,A3(e,a)),n=r.get(e.id)??0,s=i.get(e.id)??0,c=d.get(e.id),l=c!==void 0&&c>=u;return{document:e,score:t>0?P3(o,t,n,s,e.kind,m):N3(t,n,s,e.kind),signals:l?{lexical:t,fullText:n,recency:s,vector:c}:{lexical:t,fullText:n,recency:s},lexical:t,fullText:n,recency:s,cosine:c}}),g=G3(h.filter(e=>e.fullText>0).sort((e,t)=>t.fullText-e.fullText||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),_=G3(h.filter(e=>e.cosine!==void 0&&e.cosine>=u).sort((e,t)=>t.cosine-e.cosine||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),v=e=>{let t=0,n=g.get(e);n!==void 0&&(t+=1/(c+n));let r=_.get(e);return r!==void 0&&(t+=1/(c+r)),t};return h.sort((e,t)=>{let n=e.lexical>0?1:0,r=t.lexical>0?1:0;if(n!==r)return r-n;if(n===1)return e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score;let i=v(e.document.id),a=v(t.document.id);return i===a?e.recency===t.recency?e.document.path.localeCompare(t.document.path):t.recency-e.recency:a-i}).map(({document:e,score:t,signals:n})=>({document:e,score:t,signals:n}))}function q3(e){let t=new TextEncoder().encode(e),n=new Uint8Array(1+t.length);return n[0]=1,n.set(t,1),J3(n)}function J3(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}const Y3=Symbol.for(`@inkeep/open-knowledge/skill-state-field-registry`),X3=globalThis;X3[Y3]===void 0&&(X3[Y3]=Ii());const Z3=X3[Y3],Q3=[`.ok`,`skill-state.yml`],$3=[`claude-cowork`,`cli-hosts`],e6=[`server-build-and-open`,`electron-build-and-open`,`cli-npx-skills-add`,`desktop-direct`,`cli-start`],t6=/^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/,n6=Ys({version:k().regex(t6,`version must match /^\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?$/`).register(Z3,{description:`Recorded skill version for this target.`}),recordedAt:Uo().register(Z3,{description:`ISO 8601 timestamp of the most recent successful write. Updated on every write, including reinstalls of the same version.`}),surface:P(e6).register(Z3,{description:`Install-source surface that recorded this entry.`}).optional()}),r6=Ys({enabled:j().register(Z3,{description:`Whether this user-global skill bundle is opted in.`}),decidedAt:Uo().register(Z3,{description:`ISO 8601 timestamp of the opt-in / opt-out decision.`})}),i6=Ys({schema:F(1).register(Z3,{description:`Schema major version. Bumped only on breaking shape changes.`}),targets:Ys({"claude-cowork":n6.optional(),"cli-hosts":n6.optional()}).register(Z3,{description:`Per-target install-state entries. Absent target = no recorded install.`}).default({}),bundles:rc(k(),r6).register(Z3,{description:`Per-bundle opt-in decisions keyed by install name. Absent key = no recorded decision.`}).optional()});function a6(e,t){return e??t.installedOnDisk}function o6(){return{schema:1,targets:{}}}const s6=`template`;function c6(e){if(e.trim()===``)return{};let t;try{t=(0,Nc.parse)(e)}catch{return{}}return typeof t!=`object`||!t||Array.isArray(t)?{}:t}function l6(e,t){return e.trim()===``?t:`---\n${e}\n---\n${t}`}function u6(e){let{frontmatter:t,body:n}=aK(e);return t===``?{docFrontmatterText:``,markdown:e}:{docFrontmatterText:sK(t),markdown:n}}function d6(e){let t=e.split(`
|
|
450
|
+
`);if(!(t[0]??``).startsWith(`template:`))return null;let n=[t[0]??``],r=1;for(;r<t.length;){let e=t[r]??``;if(/^[ \t]/.test(e)){n.push(e),r++;continue}if(e.trim()===``){let i=r+1;for(;i<t.length&&(t[i]??``).trim()===``;)i++;if(i<t.length&&/^[ \t]/.test(t[i]??``)){n.push(e),r++;continue}}break}let i=c6(n.join(`
|
|
451
|
+
`))[s6];return{identity:typeof i==`object`&&i&&!Array.isArray(i)?i:{},docFrontmatterText:t.slice(r).join(`
|
|
452
|
+
`).replace(/\n+$/,``)}}function f6(e){let t=e.charCodeAt(0)===65279?e.slice(1):e,{frontmatter:n,body:r}=aK(t);if(n===``)return{identity:{},starterContent:t};let i=sK(n),a=d6(i);if(a)return{identity:a.identity,starterContent:l6(a.docFrontmatterText,r)};let{frontmatter:o}=aK(r);if(o!==``)return{identity:c6(i),starterContent:r};let s=c6(i);return typeof s.title==`string`?{identity:s,starterContent:r}:{identity:{},starterContent:l6(i,r)}}function p6(e,t){let{docFrontmatterText:n,markdown:r}=u6(t),i={};for(let[t,n]of Object.entries(e))n!==void 0&&(i[t]=n);let a=(0,Nc.stringify)({[s6]:i});return`---\n${n.trim()===``?a:`${a}${n}\n`}---\n${r}`}function m6(e){return f6(e).starterContent}function h6(){let e=!1,t=``,n=0;return r=>{let i=g6(r);return e?(i&&i.char===t&&i.len>=n&&!i.hasInfo&&(e=!1,t=``,n=0),!0):i?(e=!0,t=i.char,n=i.len,!0):!1}}function g6(e){let t=(e.endsWith(`\r`)?e.slice(0,-1):e).match(/^ {0,3}([`~])(\1{2,})(.*)$/);return t?{char:t[1],len:1+t[2].length,hasInfo:t[3].trim()!==``}:null}const _6=[`#D97757`,`#1B1912`,`#F9F3E9`,`#7A9DFF`,`#8534F3`,`#9663F0`,`#727CF3`],v6={claude:`#D97757`,cursor:`#1B1912`,windsurf:`#0B100F`,openai:`#7A9DFF`,github:`#8534F3`,cline:`#9663F0`,bot:`#727CF3`};function y6(e,t=_6){let n=0;for(let t of e)n=(n<<5)-n+t.charCodeAt(0)|0;return t[Math.abs(n)%t.length]}const b6={"claude-code":`claude`,"claude-ai":`claude`,cursor:`cursor`,"cursor-vscode":`cursor`,cascade:`windsurf`,codex:`openai`,"codex-mcp-client":`openai`,copilot:`github`,cline:`cline`};function x6(e){return e?b6[e]||(e.startsWith(`local-agent-mode-`)?`claude`:`bot`):`bot`}const S6={claude:`Claude`,cursor:`Cursor`,windsurf:`Windsurf`,openai:`Codex`,github:`Copilot`,cline:`Cline`};function C6(e){let t=e?.trim();return t?S6[x6(t)]??t:`Agent`}function w6(e,t){let n=e.trim();if(!n||/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=r>=0?n.slice(0,r):n,a=r>=0?n.slice(r+1):null,o=(i.split(`?`)[0]??``).trim();if(!o)return null;let s=(o.split(`/`).pop()??``).match(/\.([a-z0-9]+)$/i);if(s){let e=(s[1]??``).toLowerCase();if(e!==`md`&&e!==`mdx`)return null}let c=o.toLowerCase(),l=c.endsWith(`.mdx`)?o.slice(0,-4):c.endsWith(`.md`)?o.slice(0,-3):o,u=l.startsWith(`/`),d=u?l.slice(1):l,f=u?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of d.split(`/`))if(e===`..`){if(f.length===0)return null;f.pop()}else e!==`.`&&e!==``&&f.push(e);return f.length===0?null:{docName:f.join(`/`),anchor:a||null}}const T6=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function E6(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function D6(e){let t=e.trim();return T6.test(t)||t.startsWith(`//`)}function O6(e,t){let n=e.trim();if(!n)return null;if(n.startsWith(`#`)){let e=n.slice(1).trim();return e?{kind:`anchor`,anchor:e}:null}if(D6(n))return{kind:`external`,url:n};let r=w6(n,t);if(r)return{kind:`doc`,docName:r.docName,anchor:r.anchor};let i=E6(n);return i&&i!==`md`&&i!==`mdx`?{kind:`asset`,url:n,ext:i}:null}function k6(e,t){let n=e.trim();if(!n)return null;if(D6(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=E6(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function A6(e,t){let n=e.trim();if(!n||T6.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=((r>=0?n.slice(0,r):n).split(`?`)[0]??``).trim();if(!i)return null;let a=i.startsWith(`/`),o=a?i.slice(1):i,s=a?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of o.split(`/`))if(e===`..`){if(s.length===0)return null;s.pop()}else e!==`.`&&e!==``&&s.push(e);return s.length===0?null:s.join(`/`)}function j6(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),t.startsWith(`/`)&&(t=t.slice(1)),t}function M6(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function N6(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function P6(e){return e.split(`/`).filter(e=>e!==``)}function F6(e,t){let n=N6(t);return e===``||n===e?!0:n.startsWith(`${e}/`)}function I6(e,t){let n=N6(t);if(e===n)return 0;let r=e===``?n:n.slice(e.length+1);return r===``?0:P6(r).length}function L6(e,t){let n=P6(e),r=P6(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return n.length-i+(r.length-i)}function R6(){let e=new Map;function t(t){let n=j6(t);if(n===``)return;let r=M6(n);if(r===``)return;let i=r.toLowerCase(),a=e.get(i);if(!a){e.set(i,[n]);return}a.includes(n)||a.push(n)}function n(t){let n=j6(t),r=M6(n).toLowerCase(),i=e.get(r);if(!i)return;let a=i.indexOf(n);a!==-1&&(i.splice(a,1),i.length===0&&e.delete(r))}function r(e,r){n(e),t(r)}function i(t,n){let r=t.toLowerCase(),i=e.get(r);if(!i||i.length===0)return null;if(i.length===1)return i[0];let a=N6(j6(n)),o=[],s=[];for(let e of i)F6(a,e)?o.push(e):s.push(e);return o.length>0?(e=>{let t=e[0],n=I6(a,t);for(let r=1;r<e.length;r++){let i=e[r],o=I6(a,i);(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(o):(e=>{let t=e[0],n=L6(a,N6(t));for(let r=1;r<e.length;r++){let i=e[r],o=L6(a,N6(i));(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(s)}function a(){let t=new Map;for(let[n,r]of e)t.set(n,[...r]);return t}function o(){e.clear()}return{add:t,remove:n,rename:r,resolveEmbed:i,clear:o,snapshot:a,size:()=>e.size}}function z6(e){if(!e)return[];let t=e.split(`/`),n=[],r=``;for(let e of t)r=r?`${r}/${e}`:e,n.push(r);return n}function B6(e,t){if(e.size===0)return new Set;if(t===``)return new Set(e);let n=new Set,r=`${t}/`;for(let i of e)(i===t||i.startsWith(r))&&n.add(i);return n}function V6(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function H6(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function U6(){try{let e=l(c(d(import.meta.url)),`..`,`package.json`),t=JSON.parse(v(e,`utf-8`));if(typeof t.version==`string`&&t.version.length>0)return t.version}catch{}return`0.0.0-unknown`}const W6=U6(),G6=1;var K6=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function q6(e,t){return l(e,`${t}.lock`)}const J6=new Map;function Y6(e){J6.set(e,(J6.get(e)??0)+1)}function X6(e){let t=J6.get(e);return t===void 0||t<=1?(J6.delete(e),!0):(J6.set(e,t-1),!1)}function Z6(e,t){try{let n=JSON.parse(v(e,`utf-8`));return n&&typeof n==`object`&&H6(n.pid)?n:(console.warn(`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return console.warn(`${t} Corrupt lock file at ${e} — replacing`),null}}function Q6(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;g(n,{recursive:!0});let a=q6(n,t),o={pid:process.pid,hostname:p(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??W6},s=JSON.stringify(o,null,2);for(let e=0;e<3;e++){if(!h(a))try{let e=_(a,`wx`,384);try{x(e,s)}finally{m(e)}return Y6(a),$6({lockName:t,lockDir:n,lockPath:a})}catch(e){if(e.code!==`EEXIST`)throw e}let e=Z6(a,i);if(e){let r=e.hostname===p();if(r&&e.pid===process.pid)return b(a,s,{encoding:`utf-8`,mode:384}),Y6(a),$6({lockName:t,lockDir:n,lockPath:a});if(r&&V6(e.pid))throw new K6(e,a,t);console.warn(`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{y(a)}catch{}}throw Error(`${i} Failed to acquire ${a} after 3 attempts (concurrent acquire contention).`)}function $6(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>r8({lockName:t,lockDir:n}),updatePort:e=>e8({lockName:t,lockDir:n,port:e})}}function e8(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,a=q6(n,t);if(!h(a)){console.warn(`${i} Lock file missing at ${a} during port update — skipping`);return}let o;try{let e=JSON.parse(v(a,`utf-8`));if(!e||typeof e!=`object`||!H6(e.pid)){console.warn(`${i} Corrupt lock at ${a} during port update — skipping`);return}o=e}catch{console.warn(`${i} Unreadable lock at ${a} during port update — skipping`);return}if(o.pid===process.pid&&!(typeof o.hostname==`string`&&o.hostname!==p())){o.port=r;try{b(a,JSON.stringify(o,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${i} Failed to update port in ${a}: ${e instanceof Error?e.message:String(e)}`)}}}function t8(e){let{lockName:t,lockDir:n}=e,r=q6(n,t);if(!h(r))return null;let i;try{let e=JSON.parse(v(r,`utf-8`));if(!e||typeof e!=`object`||!H6(e.pid))return null;i=e}catch{return null}if(i.hostname!==p())return null;if(!V6(i.pid)){try{y(r)}catch{}return null}return i}function n8(e){let{lockName:t,lockDir:n}=e,r=q6(n,t);if(!h(r))return{status:`absent`};let i;try{i=JSON.parse(v(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!H6(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o={pid:a.pid,hostname:a.hostname,port:a.port,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(o.hostname!==p())return{status:`stale`,lock:o};if(!V6(o.pid)){try{y(r)}catch{}return{status:`stale`,lock:o}}return o.protocolVersion===void 0||o.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:o}}function r8(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=q6(n,t);if(X6(i)&&h(i))try{let e=JSON.parse(v(i,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||typeof e.hostname==`string`&&e.hostname!==p())return;y(i)}catch(e){console.warn(`${r} Failed to release ${i}: ${e instanceof Error?e.message:String(e)}`)}}var i8=class extends K6{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function a8(e,t){try{return Q6({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof K6&&e.lockName===`server`?new i8(e.existing,e.lockPath):e}}function o8(e,t){e8({lockName:`server`,lockDir:e,port:t})}function s8(e){return t8({lockName:`server`,lockDir:e})}function c8(e){r8({lockName:`server`,lockDir:e})}export{mG as $,Ml as $a,h$ as $i,u2 as $n,K2 as $r,vG as $t,Xq as A,yl as Aa,nq as Ai,uG as An,cn as Ao,m0 as Ar,U$ as At,L2 as B,Ql as Ba,Aq as Bi,Jq as Bn,ft as Bo,H0 as Br,p3 as Bt,B$ as C,db as Ca,z6 as Ci,J0 as Cn,Uo as Co,rJ as Cr,a1 as Ct,z$ as D,nu as Da,o$ as Di,k0 as Dn,Ga as Do,_0 as Dr,R0 as Dt,T$ as E,Gc as Ea,IQ as Ei,t6 as En,Wa as Eo,g0 as Er,L0 as Et,x4 as F,Wc as Fa,dq as Fi,x0 as Fn,Lt as Fo,N0 as Fr,m1 as Ft,M2 as G,tu as Ga,OG as Gi,Dq as Gn,P1 as Gr,w1 as Gt,F2 as H,Kc as Ha,v4 as Hi,bq as Hn,V0 as Hr,n1 as Ht,I$ as I,Jc as Ia,zq as Ii,S0 as In,Tt as Io,W0 as Ir,u3 as It,dG as J,Sl as Ja,EG as Ji,Kq as Jn,o0 as Jr,C1 as Jt,j2 as K,Kl as Ka,h3 as Ki,kq as Kn,M1 as Kr,T1 as Kt,I2 as L,ll as La,bG as Li,T0 as Ln,O as Lo,B0 as Lr,E0 as Lt,X$ as M,vl as Ma,m6 as Mi,s1 as Mn,fn as Mo,s6 as Mr,VG as Mt,Vq as N,_l as Na,Mq as Ni,S2 as Nn,mn as No,Z0 as Nr,l1 as Nt,w$ as O,Cl as Oa,e$ as Oi,a3 as On,ai as Oo,v0 as Or,$$ as Ot,f4 as P,gl as Pa,C$ as Pi,E2 as Pn,on as Po,F0 as Pr,u1 as Pt,fG as Q,Fl as Qa,YG as Qi,l2 as Qn,d1 as Qr,_G as Qt,B2 as R,iu as Ra,KG as Ri,b0 as Rn,D as Ro,G0 as Rr,O0 as Rt,E$ as S,e4 as Sa,q3 as Si,xG as Sn,ys as So,V1 as Sr,zG as St,V$ as T,I as Ta,u4 as Ti,$3 as Tn,fa as To,y0 as Tr,I0 as Tt,A2 as U,Dl as Ua,V4 as Ui,Tq as Un,F1 as Ur,E1 as Ut,R2 as V,qc as Va,NG as Vi,_q as Vn,U0 as Vr,FG as Vt,N2 as W,Pl as Wa,X2 as Wi,wq as Wn,N1 as Wr,x1 as Wt,gG as X,ul as Xa,f6 as Xi,f2 as Xn,tJ as Xr,v1 as Xt,cG as Y,Xl as Ya,M0 as Yi,a2 as Yn,UG as Yr,S1 as Yt,hG as Z,xl as Za,oK as Zi,d2 as Zn,eJ as Zr,b1 as Zt,v6 as _,B6 as _a,t4 as _i,t0 as _n,Mc as _o,h2 as _r,q$ as _t,Q6 as a,A6 as aa,k6 as ai,I1 as an,Bs as ao,s2 as ar,q1 as at,A1 as b,sK as ba,m3 as bi,s0 as bn,Zs as bo,i2 as br,RG as bt,H6 as c,wG as ca,p6 as ci,U4 as cn,j as co,b2 as cr,K1 as ct,n8 as d,n3 as da,h6 as di,BG as dn,tc as do,i6 as dr,i3 as dt,g4 as ea,G2 as ei,yG as en,Tl as eo,$0 as er,pG as et,s8 as f,oq as fa,uZ as fi,sG as fn,F as fo,A0 as fr,IG as ft,o8 as g,aK as ga,H4 as gi,$q as gn,lc as go,j0 as gr,J$ as gt,e8 as h,m4 as ha,Z4 as hi,Yq as hn,N as ho,y2 as hr,i0 as ht,i8 as i,g$ as ia,O6 as ii,L1 as in,P as io,o2 as ir,G$ as it,Z$ as j,bl as ja,x6 as ji,o1 as jn,un as jo,h0 as jr,b$ as jt,R$ as k,Yc as ka,nY as ki,PG as kn,vr as ko,p0 as kr,H$ as kt,q6 as l,W3 as la,X0 as li,JG as ln,kc as lo,x2 as lr,WG as lt,c8 as m,kG as ma,C3 as mi,Z1 as mn,A as mo,v2 as mr,r0 as mt,W6 as n,i4 as na,Qq as ni,LQ as nn,Fs as no,O2 as nr,Wq as nt,a8 as o,a6 as oa,lG as oi,GG as on,Hs as oo,t2 as or,J1 as ot,r8 as p,cq as pa,T3 as pi,$1 as pn,Ys as po,_2 as pr,g1 as pt,k2 as q,Ul as qa,jG as qi,Gq as qn,a0 as qr,nJ as qt,G6 as r,h4 as ra,Rq as ri,z1 as rn,cc as ro,m2 as rr,W$ as rt,V6 as s,w6 as sa,y6 as si,p1 as sn,M as so,n2 as sr,G1 as st,K6 as t,SG as ta,l4 as ti,qG as tn,El as to,p2 as tr,Hq as tt,t8 as u,Z2 as ua,R6 as ui,XG as un,$s as uo,q0 as ur,ZG as ut,LG as v,d4 as va,C6 as vi,n0 as vn,rc as vo,g2 as vr,Y1 as vt,D$ as w,tp as wa,l3 as wi,Q3 as wn,Vo as wo,_1 as wr,W1 as wt,j1 as x,lq as xa,o6 as xi,c0 as xn,Ws as xo,e2 as xr,HG as xt,P$ as y,QQ as ya,r3 as yi,f1 as yn,k as yo,r2 as yr,X1 as yt,z2 as z,ru as za,X4 as zi,T2 as zn,pt as zo,K0 as zr,B1 as zt};
|
|
453
|
+
//# sourceMappingURL=server-lock-ltHt39S2-p0c2u2YF.mjs.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{s as e}from"./chunk-C94x7I9S.mjs";import{c as t,l as n,s as r}from"./server-lock-ltHt39S2-
|
|
2
|
-
`)}async function J(e={}){let t=e.discover??
|
|
3
|
-
//# sourceMappingURL=src-
|
|
1
|
+
import{s as e}from"./chunk-C94x7I9S.mjs";import{c as t,l as n,s as r}from"./server-lock-ltHt39S2-p0c2u2YF.mjs";import{Mr as i,Nr as a,Tn as o,ii as s,pn as c,xn as l}from"./dist-AG4Gq9ev.mjs";import{t as u}from"./esm-CsQUg9js.mjs";import"./gh-detect-DD9zzsz3.mjs";import{x as d,y as f}from"./init-D3sweWsY.mjs";import{l as ee,n as p}from"./write-project-skill-DK3lBBLD.mjs";import"./loader-C32u3Dvc.mjs";import{c as m}from"./colors-8SzMRIVy.mjs";import"./preview-DnAEOXGa.mjs";import{dirname as te,isAbsolute as h,join as g,relative as _,resolve as v}from"node:path";import{hostname as y}from"node:os";import{existsSync as b,lstatSync as ne,readFileSync as x,readlinkSync as re,statSync as ie}from"node:fs";import{readFile as S,realpath as C}from"node:fs/promises";function w(e,i,a={}){let o=n(e,i);if(!b(o))return{status:`missing`,lockPath:o};let s;try{s=JSON.parse(x(o,`utf-8`))}catch{return{status:`corrupt`,lockPath:o}}if(!s||typeof s!=`object`||!t(s.pid))return{status:`corrupt`,lockPath:o};let c=s;if(!(a.isAlive??r)(c.pid))return{status:`dead-pid`,lockPath:o,lock:c};let l=a.host??y();return c.hostname===l?{status:`alive`,lockPath:o,lock:c}:{status:`foreign-host`,lockPath:o,lock:c}}function T(e){return e.replace(/:\d+$/,``)}function E(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function D(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`).filter(e=>e.length>0);if(n.length<5||n[2]!==`blob`)return null;let r,i,a,o;try{r=decodeURIComponent(n[0]),i=decodeURIComponent(n[1]),a=decodeURIComponent(n[3]),o=n.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!r||!i||!a||o.length===0||o.some(e=>e.length===0)?null:{owner:r,repo:i,branch:a,path:o.join(`/`)}}function O(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`);if(n.length<5||n[0]!==``||n[3]!==`tree`)return null;let r=n.slice(5);r.length===1&&r[0]===``&&r.pop();let i,a,o,s;try{i=decodeURIComponent(n[1]),a=decodeURIComponent(n[2]),o=decodeURIComponent(n[4]),s=r.map(e=>decodeURIComponent(e))}catch{return null}return!i||!a||!o||s.some(e=>e.length===0)?null:{owner:i,repo:a,branch:o,path:s.join(`/`)}}function ae(e){let t=D(e);if(t)return{kind:`doc`,...t};let n=O(e);return n?{kind:`folder`,...n}:null}const oe=`# >>> open-knowledge cli >>>`,se=`# <<< open-knowledge cli <<<`,k=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function A(e){return g(e,`Library`,`Application Support`,`OpenKnowledge`,`path-install.json`)}const j={existsSync:e=>b(e),readFileSync:(e,t)=>x(e,t),lstatSync:e=>ne(e),readlinkSync:e=>re(e)};function M(e,t=j){let n=A(e);if(!t.existsSync(n))return null;try{let e=JSON.parse(t.readFileSync(n,`utf8`));return e?.version===1?e:null}catch{return null}}function N(e){let t=e.replace(k,``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function P(e,t,n=j){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}const F=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`deinit`]);function I(e,t,n=o){if(e!==void 0&&!F.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let L=null;function R(e){L=e}function z(){return L??process.cwd()}var B=e(m(),1);function V(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function H(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function U(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,s=null;if(n.status!==`missing`&&n.status!==`corrupt`){let e=n.lock;s={port:e.port,status:n.status,pid:e.pid,startedAt:e.startedAt,usage:a}}return{directory:o.worktreeRoot,server:{port:o.port,status:t.status,pid:o.pid,startedAt:o.startedAt,usage:i},ui:s,hostname:o.hostname,lockPath:t.lockPath,binary:r==null?null:l(r),command:r,isDesktop:V(r)}}function W(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function G(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&W(e)?`ui-orphan`:`stale`}const K=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function ce(e){switch(e){case`running`:return B.default.green(e);case`desktop`:return B.default.blue(e);case`foreign`:return B.default.cyan(e);case`ui-orphan`:return B.default.magenta(e);case`stale`:return B.default.yellow(e)}}function q(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function le(e){return`${q(e.server.usage)} | ${q(e.ui?.usage??null)}`}function ue(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function de(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>{let t=G(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,ue(e),le(e),t,String(n),H(e.server.startedAt),e.binary??`—`]}),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=ce(G(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=B.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
2
|
+
`)}async function J(e={}){let t=e.discover??c,n=e.inspect??w,r=e.log??(e=>console.log(e)),o=e.resolveCommand??i,s=e.resolveUsage??a,l=await t(),u=[];for(let e of l){let t=n(e,`server`),r=n(e,`ui`),i=U(e,t,r,t.status===`missing`||t.status===`corrupt`?null:o(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:s(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:s(r.lock.pid));i!=null&&u.push(i)}if(e.json){let e=u.map(e=>({...e,displayStatus:G(e)}));r(JSON.stringify(e,null,2));return}r(de(e.all?u:u.filter(e=>K.has(G(e)))))}function fe(){return new u(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await J({all:t.all===!0||e===`all`,json:t.json===!0})})}function pe(e,t,n={}){let i=n.isAlive??r,a=[];for(let[n,r]of[[`server`,e],[`ui`,t]])(r.status===`alive`||r.status===`foreign-host`&&i(r.lock.pid))&&a.push({name:n,pid:r.lock.pid,port:r.lock.port});return{targets:a}}function Y(e){let t=e.inspect??(t=>w(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=pe(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function X(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function me(e,t=r){let n=await c(),i=null;for(let r of n){let n=w(r,`server`),a=w(r,`ui`);if(X(n,t)&&n.lock.port===e||X(a,t)&&a.lock.port===e)return r;i===null&&(X(n,t)&&n.lock.pid===e||X(a,t)&&a.lock.pid===e)&&(i=r)}return i}function Z(e){let t=Y({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function he(e){return new u(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=Y({lockDir:s(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await J({});return}if(n===`all`){let e=await c();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e){let e=w(n,`server`),i=w(n,`ui`);!X(e,r)&&!X(i,r)||(Z(n),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(n)){let e=Number.parseInt(n,10),t=await me(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}Z(t);return}Z(s(v(z(),n)))})}function ge(e){return{event:`mcp-config-decline`,scope:e.scope,surface:e.surface,editorId:e.editorId,reason:e.reason}}async function _e(e,t){let n,r;try{n=await C(v(e)),r=await C(v(te(e)))}catch{return{kind:`not-git`}}if(!$(n,r))return{kind:`symlink-escape`};let i=g(n,`.git`),a;try{a=ie(i)}catch{return{kind:`not-git`}}let o;if(a.isDirectory()){let e;try{e=await C(i)}catch{return{kind:`not-git`}}if(!$(e,n))return{kind:`symlink-escape`};o=e}else if(a.isFile()){let e;try{e=await S(i,`utf-8`)}catch{return{kind:`not-git`}}let t=/^gitdir:\s*(.+)$/m.exec(e.trim());if(!t)return{kind:`not-git`};let r=t[1].trim(),a=h(r)?r:v(n,r);try{o=await C(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let s=g(await Q(o),`config`),c;try{c=await S(s,`utf-8`)}catch{return{kind:`not-git`}}let l=ye(c);if(l===null)return{kind:`no-origin`};let u=E(l);if(u===null||u.hostname!==`github.com`)return{kind:`non-github`};let d=u.owner.toLowerCase()===t.owner.toLowerCase(),f=u.name.toLowerCase()===t.repo.toLowerCase();return!d||!f?{kind:`wrong-repo`,actualOwner:u.owner,actualRepo:u.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${u.owner}/${u.name}.git`}}async function Q(e){let t;try{t=(await S(g(e,`commondir`),`utf-8`)).trim()}catch{return e}if(t.length===0)return e;let n=h(t)?t:v(e,t);try{return await C(n)}catch{return n}}function $(e,t){if(e===t)return!0;let n=_(t,e);return n.length>0&&!n.startsWith(`..`)&&!h(n)}function ve(e){let t=e.indexOf(`#`),n=e.indexOf(`;`),r=-1;return t>=0&&n>=0?r=Math.min(t,n):t>=0?r=t:n>=0&&(r=n),(r===-1?e:e.slice(0,r)).trim()}function ye(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=ve(n);if(e.length===0)continue;if(e.startsWith(`[`)){t=/^\[\s*remote\s+["']origin["']\s*\]$/.test(e);continue}if(!t)continue;let r=/^url\s*=\s*(.+)$/.exec(e);if(r)return be(r[1])}return null}function be(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}const xe=[{id:`mcp-config`,write(e,t,n){let r=e.projectConfigPath?.(t);if(!r)return{integration:`mcp-config`,editorId:e.id,action:`skipped-unsupported`};try{let i=d(e,t,n,void 0,r);return i.action===`written`||i.action===`overwritten`?{integration:`mcp-config`,editorId:e.id,action:i.action,path:i.configPath}:i.action===`failed`?{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:i.error??`unknown failure`}:i.action===`declined`?{integration:`mcp-config`,editorId:e.id,action:`declined`,path:i.configPath,...i.declineReason===void 0?{}:{reason:i.declineReason}}:{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:`unexpected project-scope action: ${i.action}`}}catch(t){return{integration:`mcp-config`,editorId:e.id,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}},{id:`project-skill`,write(e,t,n){try{let n=p(e,t);return{integration:`project-skill`,editorId:e.id,action:n.action,...n.path?{path:n.path}:{},...n.error?{error:n.error}:{}}}catch(t){return{integration:`project-skill`,editorId:e.id,action:`failed`,error:t instanceof Error?t.message:String(t)}}}}];function Se(e,t,n={},r=xe){let i=[];for(let a of t){let t=ee[a];for(let a of r)i.push(a.write(t,e,n))}return i}function Ce(e,t,n={}){return{integrations:Se(e,t,n),claudeLaunchJson:t.includes(`claude`)?f(e,n):void 0}}export{ae as _,he as a,w as b,I as c,se as d,P as f,D as g,N as h,Y as i,oe as l,M as m,_e as n,fe as o,A as p,ge as r,R as s,Ce as t,k as u,O as v,E as y};
|
|
3
|
+
//# sourceMappingURL=src-ZKUfOXO5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,f as t,r as n}from"./start-DaZwGnwh.mjs";export{n as bootStartServer,t as resolveHost,e as startCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{On as e,dt as t}from"./server-lock-ltHt39S2-FrJuEUby.mjs";import{cr as n,jr as r,xr as i}from"./dist-TG9U-N9P.mjs";import{n as a,t as o}from"./esm-CsQUg9js.mjs";import{i as s,t as c}from"./gh-detect-agW-_3XF.mjs";import{n as l}from"./constants-BUU-f5cR.mjs";import{spawn as u}from"node:child_process";import{basename as d,dirname as f,join as p}from"node:path";import{homedir as m}from"node:os";import{closeSync as h,existsSync as g,mkdirSync as _,openSync as v,statSync as y}from"node:fs";import{rm as b}from"node:fs/promises";import{setTimeout as x}from"node:timers/promises";const S=`OpenKnowledge.app`,C=`/Applications/${S}`;function w(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return y(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function T(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(E(e,C))return C;let t=p(e.homeDir??m(),`Applications`,S);return E(e,t)?t:null}function E(e,t){try{let n=p(t,`Contents`,`MacOS`,`OpenKnowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function D(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=T(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.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function O(e){(e.log??(e=>console.error(e)))("Launching OpenKnowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function k(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${C}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. 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 desktop bundle at ${C} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${C} but launch dispatch did not fire (caller bug).`}}function A(e){return p(f(e),`..`,`Frameworks`,`OpenKnowledge Server.app`,`Contents`,`MacOS`,`OpenKnowledge Helper`)}const j=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function M(e){if(e.platform!==`darwin`||!j.test(e.execPath))return null;let t=A(e.execPath);return e.exists(t)?t:null}function N(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??g,a=r[1];return a?{command:M({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function P(e,t){return e.host??t.HOST??`127.0.0.1`}function F(e){let t=d(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var I=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}};function L(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function R(t){g(t.lockDir)||_(t.lockDir,{recursive:!0});let n=v(p(t.lockDir,e),`w`),r=t.spawn??u,{PORT:i,...a}=process.env,o=N();try{let e=r(o.command,[...o.prefixArgs,...t.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,n],cwd:t.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return e.unref(),e}finally{try{h(n)}catch{}}}function z(e,t,n){return e??(n===void 0?t:void 0)}function B(e,t){return e!==void 0&&t!==null&&t.port>0}function V(e,t,n){return e??(t!=null&&!n?1:0)}async function H(e){let t=e.spawn??u,n=N(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},c=()=>s(`SIGINT`),l=()=>s(`SIGTERM`);process.once(`SIGINT`,c),process.once(`SIGTERM`,l),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=V(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,c),process.removeListener(`SIGTERM`,l)}async function U(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const W=t;function G(e,t,n=e=>b(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{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`)}}}}function K(e){let t=e.sigtermGraceMs??W,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>x(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function q(e){let{config:t,cwd:a,host:o}=e,l=e.skipAutoInit??!1,u=e.skipUiAutoSpawn??!1,d=e.idleThresholdMs??18e5,{existsSync:f,mkdirSync:p}=await import(`node:fs`),{basename:m,dirname:h}=await import(`node:path`),{bootServer:g,getLogger:_,isProcessAlive:v,readUiLock:y,resolveContentDir:b}=await import(`./dist-CDX3FPEf.mjs`),S=e.log??_(`start`),C=e.singleFile!==void 0,w=e.projectDir??a,T=C?r(e.singleFile).canonicalFilePath:void 0,E=T?h(T):void 0,D=T?m(T):void 0;if(!C){if(!l&&!n(a))throw new I(a);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&S.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-uJr9vJYZ.mjs`)).repairMcpConfigs)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-e3Xal7gR.mjs`)).repairLaunchJson)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-Bz8yC6_P.mjs`)).repairSkills)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let O=E??b(t,a);!C&&!f(O)&&(p(O,{recursive:!0}),S.info({contentDir:O},`Created content directory`));let k=null,A=async({lockDir:t})=>{if(k=L({uiLock:y(t),isAlive:v}),k.action===`spawn`&&!u)try{let n=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];R({lockDir:t,cwd:a,spawn:e.spawn,args:n}),S.info({reason:k.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else k.action===`skip`&&S.info({port:k.port,pid:k.pid},`UI already running at port ${k.port}`)},j=e.reactShellDistDir===void 0,M=s(),N=i(),P=await g({config:t,contentDir:O,projectDir:C?w:a,contentRoot:C?void 0:t.content.dir,port:e.port,host:o,quiet:!1,detectGh:c,tokenStore:M,embeddingsKeyStore:N,...C?{ephemeral:!0,singleDocRelPath:D,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:j,idleShutdownMs:d,skipAutoInit:!0,...j?{spawnUiSiblingFn:A}:{},idleShutdownHandler:e=>{let t=K({readUiLock:()=>y(P.lockDir),isAlive:v,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:S});return C?G(t,w):t},log:S,...e.serveContentAssets?{serveContentAssets:!0}:{},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});k||={action:`skip`,reason:`alive`,pid:0,port:0};let F=k,z=null;if(F.action===`skip`)z=F.port>0?F.port:null;else if(!u){let t=e.uiBindTimeoutMs??3e3;z=await U({readUiLock:()=>y(P.lockDir),now:Date.now,sleep:e=>x(e),timeoutMs:t,pollIntervalMs:50}),z===null&&S.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:P.httpServer,destroy:P.destroy,lockDir:P.lockDir,contentDir:O,port:P.port,ready:P.ready,degraded:P.degraded,uiSpawnDecision:k,resolvedUiPort:z}}function J(e){if(e===`browser`||e===`app`)return e;throw new a(`--mode must be 'browser' or 'app'`)}function ee(e){let t=Number.parseInt(e,10);if(Number.isNaN(t)||t<1||t>65535)throw new a(`--ui-port must be a port number between 1 and 65535`);return t}function Y(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function X(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 Z(e,t){let n=Y(process.env);n!==null&&(process.env.OK_CONSOLE_LEVEL=n);let{renderBanner:r}=await import(`./banner-BxCFCyu8.mjs`),{accent:i,dim:a,error:o,warning:s}=await import(`./colors-CmkIIbww.mjs`),c=process.cwd(),u=e;process.title=F(c);let d=P(t,process.env),f=t.port===void 0?void 0:Number(t.port),p=process.env.PORT?Number(process.env.PORT):void 0,m=t.uiPort===void 0?void 0:Number(t.uiPort),h=z(f,p,m);if(m!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-CDX3FPEf.mjs`);if(B(m,e(t(c)))){await H({cwd:c,uiPort:m});return}}let g;try{g=await q({config:u,cwd:c,host:d,port:h,...m===void 0?{}:{uiPort:m},...t.serveContentAssets?{serveContentAssets:!0}:{},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{},...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof I&&(console.error(o(e.message)),process.exit(1));let t=await import(`./dist-CDX3FPEf.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(o(e.message)),process.exit(1)),m!==void 0&&Q(e,t)){await H({cwd:c,uiPort:m});return}let n=$(e,c,t);n!==null&&(console.error(o(n)),process.exit(1)),console.error(`${o(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let _=!1,v=async e=>{if(_)return;_=!0;let[t,...n]=X(e);console.log(i(`\n${t}`));for(let e of n)console.log(a(` ${e}`));try{await g.destroy()}catch(e){console.error(`${o(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{v(`SIGINT`)}),process.once(`SIGTERM`,()=>{v(`SIGTERM`)});let y=`http://${d}:${g.port}`,b=d===`0.0.0.0`||d===`::`?`http://0.0.0.0:${g.port}`:void 0,x=g.resolvedUiPort,S=x!==null&&x>0?`http://${d}:${x}`:y;console.log(r({name:`open-knowledge`,version:l,localUrl:S,apiUrl:S===y?void 0:y,networkUrl:b,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let C={"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`};g.ready.then(async()=>{if(g.degraded.length>0){console.log();for(let e of g.degraded){let t=C[e]??`${e} (check server logs for details)`;console.warn(` ${s(`⚠`)} ${s(e)}: ${a(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-DHTbHSqx.mjs`);e(S)}}).catch(e=>{console.error(` ${o(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function Q(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function $(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=p(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`OpenKnowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.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`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function te(e){return new o(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,ee).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,J).option(`--serve-content-assets`,`Serve content assets from this server`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
|
|
1
|
+
import{On as e,dt as t}from"./server-lock-ltHt39S2-p0c2u2YF.mjs";import{cr as n,jr as r,xr as i}from"./dist-AG4Gq9ev.mjs";import{n as a,t as o}from"./esm-CsQUg9js.mjs";import{i as s,t as c}from"./gh-detect-DD9zzsz3.mjs";import{n as l}from"./constants-DVW-9MaB.mjs";import{spawn as u}from"node:child_process";import{basename as d,dirname as f,join as p}from"node:path";import{homedir as m}from"node:os";import{closeSync as h,existsSync as g,mkdirSync as _,openSync as v,statSync as y}from"node:fs";import{rm as b}from"node:fs/promises";import{setTimeout as x}from"node:timers/promises";const S=`OpenKnowledge.app`,C=`/Applications/${S}`;function w(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return y(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function T(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(E(e,C))return C;let t=p(e.homeDir??m(),`Applications`,S);return E(e,t)?t:null}function E(e,t){try{let n=p(t,`Contents`,`MacOS`,`OpenKnowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function D(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=T(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.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function O(e){(e.log??(e=>console.error(e)))("Launching OpenKnowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function k(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${C}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. 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 desktop bundle at ${C} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${C} but launch dispatch did not fire (caller bug).`}}function A(e){return p(f(e),`..`,`Frameworks`,`OpenKnowledge Server.app`,`Contents`,`MacOS`,`OpenKnowledge Helper`)}const j=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function M(e){if(e.platform!==`darwin`||!j.test(e.execPath))return null;let t=A(e.execPath);return e.exists(t)?t:null}function N(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??g,a=r[1];return a?{command:M({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function P(e,t){return e.host??t.HOST??`127.0.0.1`}function F(e){let t=d(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var I=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}};function L(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function R(t){g(t.lockDir)||_(t.lockDir,{recursive:!0});let n=v(p(t.lockDir,e),`w`),r=t.spawn??u,{PORT:i,...a}=process.env,o=N();try{let e=r(o.command,[...o.prefixArgs,...t.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,n],cwd:t.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return e.unref(),e}finally{try{h(n)}catch{}}}function z(e,t,n){return e??(n===void 0?t:void 0)}function B(e,t){return e!==void 0&&t!==null&&t.port>0}function V(e,t,n){return e??(t!=null&&!n?1:0)}async function H(e){let t=e.spawn??u,n=N(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},c=()=>s(`SIGINT`),l=()=>s(`SIGTERM`);process.once(`SIGINT`,c),process.once(`SIGTERM`,l),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=V(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,c),process.removeListener(`SIGTERM`,l)}async function U(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const W=t;function G(e,t,n=e=>b(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{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`)}}}}function K(e){let t=e.sigtermGraceMs??W,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>x(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function q(e){let{config:t,cwd:a,host:o}=e,l=e.skipAutoInit??!1,u=e.skipUiAutoSpawn??!1,d=e.idleThresholdMs??18e5,{existsSync:f,mkdirSync:p}=await import(`node:fs`),{basename:m,dirname:h}=await import(`node:path`),{bootServer:g,getLogger:_,isProcessAlive:v,readUiLock:y,resolveContentDir:b}=await import(`./dist-BWUwqOdN.mjs`),S=e.log??_(`start`),C=e.singleFile!==void 0,w=e.projectDir??a,T=C?r(e.singleFile).canonicalFilePath:void 0,E=T?h(T):void 0,D=T?m(T):void 0;if(!C){if(!l&&!n(a))throw new I(a);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&S.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-Idc5CsVt.mjs`)).repairMcpConfigs)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-rZGx8Hlk.mjs`)).repairLaunchJson)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-DClA9KZj.mjs`)).repairSkills)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let O=E??b(t,a);!C&&!f(O)&&(p(O,{recursive:!0}),S.info({contentDir:O},`Created content directory`));let k=null,A=async({lockDir:t})=>{if(k=L({uiLock:y(t),isAlive:v}),k.action===`spawn`&&!u)try{let n=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];R({lockDir:t,cwd:a,spawn:e.spawn,args:n}),S.info({reason:k.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else k.action===`skip`&&S.info({port:k.port,pid:k.pid},`UI already running at port ${k.port}`)},j=e.reactShellDistDir===void 0,M=s(),N=i(),P=await g({config:t,contentDir:O,projectDir:C?w:a,contentRoot:C?void 0:t.content.dir,port:e.port,host:o,quiet:!1,detectGh:c,tokenStore:M,embeddingsKeyStore:N,...C?{ephemeral:!0,singleDocRelPath:D,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:j,idleShutdownMs:d,skipAutoInit:!0,...j?{spawnUiSiblingFn:A}:{},idleShutdownHandler:e=>{let t=K({readUiLock:()=>y(P.lockDir),isAlive:v,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:S});return C?G(t,w):t},log:S,...e.serveContentAssets?{serveContentAssets:!0}:{},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});k||={action:`skip`,reason:`alive`,pid:0,port:0};let F=k,z=null;if(F.action===`skip`)z=F.port>0?F.port:null;else if(!u){let t=e.uiBindTimeoutMs??3e3;z=await U({readUiLock:()=>y(P.lockDir),now:Date.now,sleep:e=>x(e),timeoutMs:t,pollIntervalMs:50}),z===null&&S.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:P.httpServer,destroy:P.destroy,lockDir:P.lockDir,contentDir:O,port:P.port,ready:P.ready,degraded:P.degraded,uiSpawnDecision:k,resolvedUiPort:z}}function J(e){if(e===`browser`||e===`app`)return e;throw new a(`--mode must be 'browser' or 'app'`)}function ee(e){let t=Number.parseInt(e,10);if(Number.isNaN(t)||t<1||t>65535)throw new a(`--ui-port must be a port number between 1 and 65535`);return t}function Y(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function X(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 Z(e,t){let n=Y(process.env);n!==null&&(process.env.OK_CONSOLE_LEVEL=n);let{renderBanner:r}=await import(`./banner-BxCFCyu8.mjs`),{accent:i,dim:a,error:o,warning:s}=await import(`./colors-CmkIIbww.mjs`),c=process.cwd(),u=e;process.title=F(c);let d=P(t,process.env),f=t.port===void 0?void 0:Number(t.port),p=process.env.PORT?Number(process.env.PORT):void 0,m=t.uiPort===void 0?void 0:Number(t.uiPort),h=z(f,p,m);if(m!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-BWUwqOdN.mjs`);if(B(m,e(t(c)))){await H({cwd:c,uiPort:m});return}}let g;try{g=await q({config:u,cwd:c,host:d,port:h,...m===void 0?{}:{uiPort:m},...t.serveContentAssets?{serveContentAssets:!0}:{},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{},...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof I&&(console.error(o(e.message)),process.exit(1));let t=await import(`./dist-BWUwqOdN.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(o(e.message)),process.exit(1)),m!==void 0&&Q(e,t)){await H({cwd:c,uiPort:m});return}let n=$(e,c,t);n!==null&&(console.error(o(n)),process.exit(1)),console.error(`${o(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let _=!1,v=async e=>{if(_)return;_=!0;let[t,...n]=X(e);console.log(i(`\n${t}`));for(let e of n)console.log(a(` ${e}`));try{await g.destroy()}catch(e){console.error(`${o(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{v(`SIGINT`)}),process.once(`SIGTERM`,()=>{v(`SIGTERM`)});let y=`http://${d}:${g.port}`,b=d===`0.0.0.0`||d===`::`?`http://0.0.0.0:${g.port}`:void 0,x=g.resolvedUiPort,S=x!==null&&x>0?`http://${d}:${x}`:y;console.log(r({name:`open-knowledge`,version:l,localUrl:S,apiUrl:S===y?void 0:y,networkUrl:b,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let C={"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`};g.ready.then(async()=>{if(g.degraded.length>0){console.log();for(let e of g.degraded){let t=C[e]??`${e} (check server logs for details)`;console.warn(` ${s(`⚠`)} ${s(e)}: ${a(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-DHTbHSqx.mjs`);e(S)}}).catch(e=>{console.error(` ${o(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function Q(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function $(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=p(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`OpenKnowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.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`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function te(e){return new o(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,ee).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,J).option(`--serve-content-assets`,`Serve content assets from this server`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
|
|
2
2
|
`),process.exit(2));let e=[];if(t.port!==void 0&&e.push(`--port`),t.uiPort!==void 0&&e.push(`--ui-port`),t.host!==void 0&&e.push(`--host`),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(w());if(n.available){O({spawn:u});return}console.error(k(n.reason)),process.exit(1)}await Z(n,t)})}export{O as C,D as S,te as _,V as a,N as b,F as c,z as d,P as f,R as g,B as h,K as i,X as l,Z as m,U as n,H as o,Y as p,q as r,L as s,I as t,Q as u,$ as v,w as x,G as y};
|
|
3
|
-
//# sourceMappingURL=start-
|
|
3
|
+
//# sourceMappingURL=start-DaZwGnwh.mjs.map
|