@inkeep/open-knowledge 0.25.0-beta.6 → 0.25.0-beta.8
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 +6 -6
- package/dist/constants-6L3bwbSM.mjs +2 -0
- package/dist/{dist-CMJUtzX1.mjs → dist-7R982DBB.mjs} +1 -1
- package/dist/{dist-CWHBXHzy.mjs → dist-B1-OZ0zK.mjs} +4 -4
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/init-CGNl62xW.mjs +1 -0
- package/dist/{init-DvnBfvsT.mjs → init-D998mblu.mjs} +5 -5
- package/dist/loader-BfDp4sqJ.mjs +1 -0
- package/dist/{loader-DTIVnIQS.mjs → loader-CoLeuXs-.mjs} +2 -2
- package/dist/preview-CnOFDDeV.mjs +1 -0
- package/dist/{preview-CnShDa2p.mjs → preview-DWBYV32d.mjs} +2 -2
- package/dist/public/assets/{ActivityModeContent-CNxdYTCc.js → ActivityModeContent-QvRIx_do.js} +1 -1
- package/dist/public/assets/{DocumentContext-bNGvFuJS.js → DocumentContext-zL3ZbwDo.js} +1 -1
- package/dist/public/assets/{GraphPanel-D5yxV_ez.js → GraphPanel-DiyMfzQg.js} +1 -1
- package/dist/public/assets/{ManagedArtifactProperties-CRYWYGK4.js → ManagedArtifactProperties-OxkUY14x.js} +1 -1
- package/dist/public/assets/{PropertyPanel-DgbQo3wG.js → PropertyPanel-D9A27c2E.js} +1 -1
- package/dist/public/assets/{SettingsDialogBody-CU-nEwde.js → SettingsDialogBody-cotnwVMw.js} +1 -1
- package/dist/public/assets/{SkillEditorActions-Bfh-iuK_.js → SkillEditorActions-BsGotb40.js} +1 -1
- package/dist/public/assets/{SourceEditor-CAUoNOTU.js → SourceEditor-BZ3cbLjs.js} +1 -1
- package/dist/public/assets/{TerminalPanel-Ds-ev2-D.js → TerminalPanel-XlICQw5o.js} +1 -1
- package/dist/public/assets/{config-validation-events-DiOTHiAz.js → config-validation-events-yB2QWKKJ.js} +1 -1
- package/dist/public/assets/{dist-GmorMgHF.js → dist-BRGUidv4.js} +8 -6
- package/dist/public/assets/{documents-events-CSQluyCM.js → documents-events-DA8Q5ICz.js} +1 -1
- package/dist/public/assets/{file-tree-adapter-TDYabCI-.js → file-tree-adapter-CP3Xa3us.js} +1 -1
- package/dist/public/assets/{index-BCPjnywU.js → index-CoukPsjj.js} +5 -5
- package/dist/public/assets/{keyboard-shortcuts-CZysvuV8.js → keyboard-shortcuts-DOkzBlgc.js} +1 -1
- package/dist/public/assets/{navigation-targets-CXdtVjj4.js → navigation-targets-DNRja8Z0.js} +1 -1
- package/dist/public/assets/{open-managed-artifact-tab-CvsZjaW-.js → open-managed-artifact-tab-DBkxdYp_.js} +1 -1
- package/dist/public/assets/{prop-types-C_2IQGCC.js → prop-types-C-aZftyS.js} +1 -1
- package/dist/public/assets/{selection-context-B6kAEK37.js → selection-context-vh0MmCBb.js} +1 -1
- package/dist/public/assets/{skill-actions-CPoGr_7b.js → skill-actions-Sc4IN52j.js} +1 -1
- package/dist/public/assets/{skills-api-mcV6MiPo.js → skills-api-ts3L80AV.js} +1 -1
- package/dist/public/assets/{target-navigation-intent-C4nLupIH.js → target-navigation-intent-CIKQ1Hj-.js} +1 -1
- package/dist/public/assets/{typing-burst-detector-DEl5qeGr.js → typing-burst-detector-BT98lJOb.js} +1 -1
- package/dist/public/index.html +16 -16
- package/dist/{repair-launch-json-DpU0i0eM.mjs → repair-launch-json-DiMbidtg.mjs} +2 -2
- package/dist/repair-mcp-configs-dTwbVEwq.mjs +2 -0
- package/dist/repair-skills-BvhYVWdw.mjs +3 -0
- package/dist/repair-skills-qkZ_LTHD.mjs +1 -0
- package/dist/{src-BQi1rIBd.mjs → src-CeXDKSSn.mjs} +2 -2
- package/dist/{start-RS2gu3vK.mjs → start-BqOu87VR.mjs} +2 -2
- package/dist/start-ByfafCut.mjs +1 -0
- package/dist/write-project-skill-CAgr6zKv.mjs +36 -0
- package/package.json +1 -1
- package/dist/constants-D3-jp47D.mjs +0 -2
- package/dist/init-BPc0rfg_.mjs +0 -1
- package/dist/loader-Scpsv3B1.mjs +0 -1
- package/dist/preview-OyZSYy4k.mjs +0 -1
- package/dist/repair-mcp-configs-DioIDpS1.mjs +0 -2
- package/dist/repair-skills-BFe09bLm.mjs +0 -1
- package/dist/repair-skills-xrYOvyVd.mjs +0 -3
- package/dist/start-B2g--lvD.mjs +0 -1
- package/dist/write-project-skill-CRxX-42S.mjs +0 -12
package/dist/public/assets/{typing-burst-detector-DEl5qeGr.js → typing-burst-detector-BT98lJOb.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,X as a,Y as o,n as s,pt as c,st as l}from"./DocumentContext-bNGvFuJS.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-BbrtnF__.js";import{Wn as ce,et as p,rt as m,xr as h}from"./dist-GmorMgHF.js";import{l as le}from"./button-DGf25ccp.js";import{i as ue}from"./prop-types-C_2IQGCC.js";import{u as g}from"./documents-events-CSQluyCM.js";import{i as _}from"./startup-marks-CWTDb1CP.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-DWaLpHcz.js";import{i as Ee,n as De,o as Oe,r as ke}from"./dist-Bqo1ZTng.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 c(g._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=m.safeParse(n);throw e.success?Error(e.data.title):new c(g._({id:`zlErBl`}),{status:t.status})}let r=p.safeParse(n);if(!r.success)throw new c(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,X as a,Y as o,n as s,pt as c,st as l}from"./DocumentContext-zL3ZbwDo.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-BbrtnF__.js";import{Wn as ce,et as p,rt as m,xr as h}from"./dist-BRGUidv4.js";import{l as le}from"./button-DGf25ccp.js";import{i as ue}from"./prop-types-C-aZftyS.js";import{u as g}from"./documents-events-DA8Q5ICz.js";import{i as _}from"./startup-marks-CWTDb1CP.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-DWaLpHcz.js";import{i as Ee,n as De,o as Oe,r as ke}from"./dist-Bqo1ZTng.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 c(g._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=m.safeParse(n);throw e.success?Error(e.data.title):new c(g._({id:`zlErBl`}),{status:t.status})}let r=p.safeParse(n);if(!r.success)throw new c(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(),o(),N(),Se(),ve(),x.allowMultipleSelections.of(!0),S(),O(R,{fallback:!0}),he(),ke(),De(),_e(),L(),ye(),it(),Ce.of([...Ee,...i,...Ht,...a,...we,...Oe,...sn])];F(),o(),Se(),O(R,{fallback:!0}),Ce.of([...i,...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-CoukPsjj.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-beU76Hfb.js">
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
<link rel="modulepreload" crossorigin href="./assets/dist-BXd_K33i.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="./assets/dist-ICp_3rWY.js">
|
|
70
70
|
<link rel="modulepreload" crossorigin href="./assets/trace-api-MhJXZpsM.js">
|
|
71
|
-
<link rel="modulepreload" crossorigin href="./assets/dist-
|
|
72
|
-
<link rel="modulepreload" crossorigin href="./assets/documents-events-
|
|
71
|
+
<link rel="modulepreload" crossorigin href="./assets/dist-BRGUidv4.js">
|
|
72
|
+
<link rel="modulepreload" crossorigin href="./assets/documents-events-DA8Q5ICz.js">
|
|
73
73
|
<link rel="modulepreload" crossorigin href="./assets/dist-CQw2y-s3.js">
|
|
74
74
|
<link rel="modulepreload" crossorigin href="./assets/propagation-api-CR2CQW4x.js">
|
|
75
75
|
<link rel="modulepreload" crossorigin href="./assets/collapsible-CjgfK1G5.js">
|
|
@@ -79,36 +79,36 @@
|
|
|
79
79
|
<link rel="modulepreload" crossorigin href="./assets/dist-ug68MPTZ.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="./assets/chevron-down-CzFz_0zd.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="./assets/chevron-right-jyIhGBkw.js">
|
|
82
|
-
<link rel="modulepreload" crossorigin href="./assets/navigation-targets-
|
|
82
|
+
<link rel="modulepreload" crossorigin href="./assets/navigation-targets-DNRja8Z0.js">
|
|
83
83
|
<link rel="modulepreload" crossorigin href="./assets/startup-marks-CWTDb1CP.js">
|
|
84
|
-
<link rel="modulepreload" crossorigin href="./assets/prop-types-
|
|
84
|
+
<link rel="modulepreload" crossorigin href="./assets/prop-types-C-aZftyS.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="./assets/config-context-DhhN0rlf.js">
|
|
86
86
|
<link rel="modulepreload" crossorigin href="./assets/file-tree-rename-validation-BqGkSO9-.js">
|
|
87
87
|
<link rel="modulepreload" crossorigin href="./assets/input-DkQ8Zmzd.js">
|
|
88
|
-
<link rel="modulepreload" crossorigin href="./assets/DocumentContext-
|
|
88
|
+
<link rel="modulepreload" crossorigin href="./assets/DocumentContext-zL3ZbwDo.js">
|
|
89
89
|
<link rel="modulepreload" crossorigin href="./assets/panel-BbrtnF__.js">
|
|
90
|
-
<link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-
|
|
91
|
-
<link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-
|
|
90
|
+
<link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-BT98lJOb.js">
|
|
91
|
+
<link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-DBkxdYp_.js">
|
|
92
92
|
<link rel="modulepreload" crossorigin href="./assets/checkbox-EGJP9xna.js">
|
|
93
93
|
<link rel="modulepreload" crossorigin href="./assets/dist-AQSp7Qij.js">
|
|
94
|
-
<link rel="modulepreload" crossorigin href="./assets/skills-api-
|
|
94
|
+
<link rel="modulepreload" crossorigin href="./assets/skills-api-ts3L80AV.js">
|
|
95
95
|
<link rel="modulepreload" crossorigin href="./assets/label-DyT4OD9H.js">
|
|
96
96
|
<link rel="modulepreload" crossorigin href="./assets/radio-group-CFPLlVag.js">
|
|
97
97
|
<link rel="modulepreload" crossorigin href="./assets/toggle-group-Bc5FaFo3.js">
|
|
98
98
|
<link rel="modulepreload" crossorigin href="./assets/cursor-CpjEfgnv.js">
|
|
99
|
-
<link rel="modulepreload" crossorigin href="./assets/skill-actions-
|
|
99
|
+
<link rel="modulepreload" crossorigin href="./assets/skill-actions-Sc4IN52j.js">
|
|
100
100
|
<link rel="modulepreload" crossorigin href="./assets/textarea-BQFFQ9_l.js">
|
|
101
101
|
<link rel="modulepreload" crossorigin href="./assets/external-link-Bc6KvE1i.js">
|
|
102
|
-
<link rel="modulepreload" crossorigin href="./assets/keyboard-shortcuts-
|
|
103
|
-
<link rel="modulepreload" crossorigin href="./assets/config-validation-events-
|
|
102
|
+
<link rel="modulepreload" crossorigin href="./assets/keyboard-shortcuts-DOkzBlgc.js">
|
|
103
|
+
<link rel="modulepreload" crossorigin href="./assets/config-validation-events-yB2QWKKJ.js">
|
|
104
104
|
<link rel="modulepreload" crossorigin href="./assets/format-Fsxus_sZ.js">
|
|
105
|
-
<link rel="modulepreload" crossorigin href="./assets/selection-context-
|
|
106
|
-
<link rel="modulepreload" crossorigin href="./assets/PropertyPanel-
|
|
105
|
+
<link rel="modulepreload" crossorigin href="./assets/selection-context-vh0MmCBb.js">
|
|
106
|
+
<link rel="modulepreload" crossorigin href="./assets/PropertyPanel-D9A27c2E.js">
|
|
107
107
|
<link rel="modulepreload" crossorigin href="./assets/chevron-left-Bb3WBx0B.js">
|
|
108
108
|
<link rel="modulepreload" crossorigin href="./assets/agent-presence-BRmBPq78.js">
|
|
109
109
|
<link rel="modulepreload" crossorigin href="./assets/project-paths-CcPGtodV.js">
|
|
110
|
-
<link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-
|
|
111
|
-
<link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-
|
|
110
|
+
<link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-CP3Xa3us.js">
|
|
111
|
+
<link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-CIKQ1Hj-.js">
|
|
112
112
|
<link rel="modulepreload" crossorigin href="./assets/mcp-consent-store-Q_heVQ86.js">
|
|
113
113
|
<link rel="stylesheet" crossorigin href="./assets/DocumentContext-B0sQn39F.css">
|
|
114
114
|
<link rel="stylesheet" crossorigin href="./assets/index-CG7gf_6X.css">
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e,v as t}from"./init-
|
|
2
|
-
//# sourceMappingURL=repair-launch-json-
|
|
1
|
+
import{r as e,v as t}from"./init-D998mblu.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-DiMbidtg.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{p as e,y as t}from"./init-D998mblu.mjs";import{r as n,s as r,u as i}from"./write-project-skill-CAgr6zKv.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,i=e.home??o(),a=[];if(e.reclaimDisableEnv===`1`)return t({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of n){let n=r[o],s=c(()=>n.configPath(``,i));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:n,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),n.projectConfigPath){let r=n.projectConfigPath,i=c(()=>r(e.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:n,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(n){let r={scope:n.scope,editorId:n.editorId,configPath:n.configPath},o=e(n.target,n.cwd,n.home,n.configPathOverride);if(o===null)return{...r,outcome:`no-entry`};if(i(o))return{...r,outcome:`canonical`};n.logger(a({scope:n.scope,surface:`cli-repair`,editorId:n.editorId,configPath:n.configPath,priorEntry:o}));let s=t(n.target,n.cwd,{mode:`published`,skipAvailabilityCheck:!0},n.home,n.configPathOverride);if(s.action===`failed`){let e=s.error??`unknown write failure`;return n.logger({event:`mcp-config-repair-write-failed`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,error:e}),{...r,outcome:`write-failed`,error:e}}return s.action===`declined`?(n.logger({event:`mcp-config-repair-declined`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,reason:s.declineReason}),{...r,outcome:`declined`}):{...r,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
|
|
2
|
+
//# sourceMappingURL=repair-mcp-configs-dTwbVEwq.mjs.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{t as e}from"./esm-BLMtE3s6.mjs";import{$r as t,Rr as n,Ur as r,d as i,ia as a,qr as o,ut as s}from"./dist-B1-OZ0zK.mjs";import{c,s as l,t as u}from"./write-project-skill-CAgr6zKv.mjs";import{dirname as d,join as f,resolve as p}from"node:path";import{existsSync as m,mkdirSync as h,readFileSync as g,readdirSync as _,rmSync as v,statSync as y,writeFileSync as b}from"node:fs";import{homedir as x}from"node:os";const S={existsSync:e=>m(e),isDirectory:e=>{try{return y(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>_(e),readFileSync:e=>g(e),writeFileSync:(e,t)=>{b(e,t)},mkdirSync:(e,t)=>{h(e,t)},rmSync:(e,t)=>{v(e,t)}},C={resolveProjectBundledSkillDir:()=>t(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>t(e,{checkDesktop:!1}),readBundledVersion:()=>n(),readRecordedVersion:e=>r(e,`cli-hosts`),writeRecordedVersion:(e,t)=>a(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>o(e)};function w(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function T(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(d(t),{recursive:!0}),E(e,t,n)}function E(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=f(e,r),a=f(t,r);n.isDirectory(i)?E(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function D(e,t,n,r,i,a){let o=[],s=f(e,`.agents`,`skills`,t),l=r.existsSync(s),u=!1;try{T(n,s,r),u=!0,o.push({kind:`central`,path:s,outcome:l?`overwritten`:`written`}),i({event:`user-skill-reclaim-central-written`,scope:`user`,path:s,preexisting:l,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 l of c){let c=f(e,l.hostDir),u=f(c,`skills`,t);if(u===s){o.push({kind:`host`,editorId:l.editorId,hostDir:l.hostDir,path:u,outcome:`skipped-collapsed-with-central`});continue}if(!r.existsSync(c)){o.push({kind:`host`,editorId:l.editorId,hostDir:l.hostDir,path:u,outcome:`skipped-host-absent`});continue}let d=r.existsSync(u);try{T(n,u,r),o.push({kind:`host`,editorId:l.editorId,hostDir:l.hostDir,path:u,outcome:d?`overwritten`:`written`}),i({event:`user-skill-reclaim-host-written`,scope:`user`,editorId:l.editorId,hostDir:l.hostDir,path:u,preexisting:d,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`host`,editorId:l.editorId,hostDir:l.hostDir,path:u,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-host-failed`,scope:`user`,editorId:l.editorId,hostDir:l.hostDir,path:u,error:t})}}return{entries:o,centralWritten:u}}function O(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 k(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 c){let o=f(e,t.hostDir,`skills`,`open-knowledge`),s=f(o,`SKILL.md`),c=n.existsSync(s),d=l[t.editorId]?.projectConfigPath?.(e),p=!c&&O(d,n);if(!c&&!p){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{u(o,e),T(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 A(e,t,n,r){let a=e=>{t.recordEvent(e).catch(()=>{})},o=()=>new Date().toISOString(),c;try{c=await t.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return r({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let l;try{l=await t.readRecordedVersion(e)}catch(e){r({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),l=null}if(l!==null&&l===c)return r({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:c}),{outcome:`skipped`,reason:`version-current`};let u=[],d=null;for(let e of s)try{u.push({id:e,sourceDir:t.resolveUserBundledSkillDir(e)})}catch(e){d=e instanceof Error?e.message:String(e)}if(u.length===0)return r({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:d??`no user-global bundles`}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${d}`}),{outcome:`skipped`,reason:`bundle-missing`};let f=[],p=u.length===s.length;for(let{id:t,sourceDir:a}of u){let o=D(e,i[t],a,n,r,c);f.push(...o.entries),o.centralWritten||(p=!1)}let m=f.some(e=>e.kind===`central`&&(e.outcome===`written`||e.outcome===`overwritten`));if(p&&m){let n=null;try{await t.writeRecordedVersion(e,c),r({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:c})}catch(e){n=e instanceof Error?e.message:String(e),r({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:c,error:n})}for(let{id:e}of u)a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:e,outcome:n===null?`installed`:`failed`,version:c,...n===null?{}:{reason:`state-write-failed:${n}`}})}else{let e=f.some(e=>e.kind===`host`&&e.outcome===`failed`);a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:c,reason:e?`all-writes-failed`:`no-hosts-installed`})}return{outcome:`done`,version:c,entries:f}}async function j(e){let t=e.logger??w,n=e.fs??S,r=e.home??x(),i={...C,...e.deps};return e.reclaimDisableEnv===`1`?(t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`}):{status:`done`,project:k(e.projectDir,i,n,t),user:await A(r,i,n,t)}}function M(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.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function N(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 P(){return new e(`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 j({projectDir:p(process.cwd()),reclaimDisableEnv:process.env.OK_RECLAIM_DISABLE??null});process.stdout.write(`${N(e)}\n`),process.exitCode=M(e)})}export{P as n,j as t};
|
|
3
|
+
//# sourceMappingURL=repair-skills-BvhYVWdw.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./repair-skills-BvhYVWdw.mjs";export{e as repairSkills};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{s as e}from"./chunk-C94x7I9S.mjs";import{t}from"./esm-BLMtE3s6.mjs";import{c as n,l as r,s as i}from"./server-lock-CN2YHwpP-Cwa4llpq.mjs";import"./gh-detect-BIaONQmT.mjs";import{Mr as a,Nr as o,Tn as s,pn as c,ri as l,xn as u}from"./dist-
|
|
1
|
+
import{s as e}from"./chunk-C94x7I9S.mjs";import{t}from"./esm-BLMtE3s6.mjs";import{c as n,l as r,s as i}from"./server-lock-CN2YHwpP-Cwa4llpq.mjs";import"./gh-detect-BIaONQmT.mjs";import{Mr as a,Nr as o,Tn as s,pn as c,ri as l,xn as u}from"./dist-B1-OZ0zK.mjs";import{v as d,y as f}from"./init-D998mblu.mjs";import{n as p,s as ee}from"./write-project-skill-CAgr6zKv.mjs";import"./loader-CoLeuXs-.mjs";import{c as m}from"./colors-8SzMRIVy.mjs";import"./preview-DWBYV32d.mjs";import{dirname as h,isAbsolute as g,join as _,relative as v,resolve as y}from"node:path";import{existsSync as te,readFileSync as ne,statSync as b}from"node:fs";import{hostname as x}from"node:os";import{readFile as S,realpath as C}from"node:fs/promises";function w(e,t,a={}){let o=r(e,t);if(!te(o))return{status:`missing`,lockPath:o};let s;try{s=JSON.parse(ne(o,`utf-8`))}catch{return{status:`corrupt`,lockPath:o}}if(!s||typeof s!=`object`||!n(s.pid))return{status:`corrupt`,lockPath:o};let c=s;if(!(a.isAlive??i)(c.pid))return{status:`dead-pid`,lockPath:o,lock:c};let l=a.host??x();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 re(e){let t=D(e);if(t)return{kind:`doc`,...t};let n=O(e);return n?{kind:`folder`,...n}:null}var k=e(m(),1);function A(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function j(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 M(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:u(r),command:r,isDesktop:A(r)}}function N(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function P(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&N(e)?`ui-orphan`:`stale`}const F=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function I(e){switch(e){case`running`:return k.default.green(e);case`desktop`:return k.default.blue(e);case`foreign`:return k.default.cyan(e);case`ui-orphan`:return k.default.magenta(e);case`stale`:return k.default.yellow(e)}}function L(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function R(e){return`${L(e.server.usage)} | ${L(e.ui?.usage??null)}`}function z(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function B(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=P(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,z(e),R(e),t,String(n),j(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=I(P(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=k.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
2
2
|
`)}async function V(e={}){let t=e.discover??c,n=e.inspect??w,r=e.log??(e=>console.log(e)),i=e.resolveCommand??a,s=e.resolveUsage??o,l=await t(),u=[];for(let e of l){let t=n(e,`server`),r=n(e,`ui`),a=M(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(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));a!=null&&u.push(a)}if(e.json){let e=u.map(e=>({...e,displayStatus:P(e)}));r(JSON.stringify(e,null,2));return}r(B(e.all?u:u.filter(e=>F.has(P(e)))))}function H(){return new t(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await V({all:t.all===!0||e===`all`,json:t.json===!0})})}const U=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`]);function W(e,t,n=s){if(e!==void 0&&!U.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let G=null;function K(e){G=e}function q(){return G??process.cwd()}function J(e,t,n={}){let r=n.isAlive??i,a=[];for(let[n,i]of[[`server`,e],[`ui`,t]])(i.status===`alive`||i.status===`foreign-host`&&r(i.lock.pid))&&a.push({name:n,pid:i.lock.pid,port:i.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=J(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 ie(e,t=i){let n=await c(),r=null;for(let i of n){let n=w(i,`server`),a=w(i,`ui`);if(X(n,t)&&n.lock.port===e||X(a,t)&&a.lock.port===e)return i;r===null&&(X(n,t)&&n.lock.pid===e||X(a,t)&&a.lock.pid===e)&&(r=i)}return r}function Z(e){let t=Y({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function ae(e){return new t(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=Y({lockDir:l(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 V({});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`),r=w(n,`ui`);!X(e,i)&&!X(r,i)||(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 ie(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}Z(t);return}Z(l(y(q(),n)))})}function oe(e){return{event:`mcp-config-decline`,scope:e.scope,surface:e.surface,editorId:e.editorId,reason:e.reason}}async function se(e,t){let n,r;try{n=await C(y(e)),r=await C(y(h(e)))}catch{return{kind:`not-git`}}if(!Q(n,r))return{kind:`symlink-escape`};let i=_(n,`.git`),a;try{a=b(i)}catch{return{kind:`not-git`}}let o;if(a.isDirectory()){let e;try{e=await C(i)}catch{return{kind:`not-git`}}if(!Q(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=g(r)?r:y(n,r);try{o=await C(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let s=_(await ce(o),`config`),c;try{c=await S(s,`utf-8`)}catch{return{kind:`not-git`}}let l=$(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 ce(e){let t;try{t=(await S(_(e,`commondir`),`utf-8`)).trim()}catch{return e}if(t.length===0)return e;let n=g(t)?t:y(e,t);try{return await C(n)}catch{return n}}function Q(e,t){if(e===t)return!0;let n=v(t,e);return n.length>0&&!n.startsWith(`..`)&&!g(n)}function le(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 $(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=le(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 ue(r[1])}return null}function ue(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}const de=[{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=f(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 fe(e,t,n={},r=de){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 pe(e,t,n={}){return{integrations:fe(e,t,n),claudeLaunchJson:t.includes(`claude`)?d(e,n):void 0}}export{ae as a,H as c,O as d,E as f,Y as i,D as l,se as n,K as o,w as p,oe as r,W as s,pe as t,re as u};
|
|
3
|
-
//# sourceMappingURL=src-
|
|
3
|
+
//# sourceMappingURL=src-CeXDKSSn.mjs.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,t}from"./esm-BLMtE3s6.mjs";import{Dn as n,dt as r}from"./server-lock-CN2YHwpP-Cwa4llpq.mjs";import{i,t as a}from"./gh-detect-BIaONQmT.mjs";import{cr as o,jr as s,xr as c}from"./dist-CWHBXHzy.mjs";import{n as l}from"./constants-D3-jp47D.mjs";import{spawn as u}from"node:child_process";import{basename as d,dirname as f,join as p}from"node:path";import{closeSync as m,existsSync as h,mkdirSync as g,openSync as _,statSync as v}from"node:fs";import{homedir as y}from"node:os";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 v(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??y(),`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??h,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(e){h(e.lockDir)||g(e.lockDir,{recursive:!0});let t=_(p(e.lockDir,n),`w`),r=e.spawn??u,{PORT:i,...a}=process.env,o=N();try{let n=r(o.command,[...o.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return n.unref(),n}finally{try{m(t)}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=r;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:n,host:r}=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-CMJUtzX1.mjs`),S=e.log??_(`start`),C=e.singleFile!==void 0,w=e.projectDir??n,T=C?s(e.singleFile).canonicalFilePath:void 0,E=T?h(T):void 0,D=T?m(T):void 0;if(!C){if(!l&&!o(n))throw new I(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&S.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-DioIDpS1.mjs`)).repairMcpConfigs)({projectDir:n,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-DpU0i0eM.mjs`)).repairLaunchJson)({projectDir:n,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-BFe09bLm.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let O=E??b(t,n);!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 r=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];R({lockDir:t,cwd:n,spawn:e.spawn,args:r}),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=i(),N=c(),P=await g({config:t,contentDir:O,projectDir:C?w:n,contentRoot:C?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:a,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(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}function ee(t){let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1||n>65535)throw new e(`--ui-port must be a port number between 1 and 65535`);return n}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-CMJUtzX1.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-CMJUtzX1.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 t(`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{n as e,t}from"./esm-BLMtE3s6.mjs";import{Dn as n,dt as r}from"./server-lock-CN2YHwpP-Cwa4llpq.mjs";import{i,t as a}from"./gh-detect-BIaONQmT.mjs";import{cr as o,jr as s,xr as c}from"./dist-B1-OZ0zK.mjs";import{n as l}from"./constants-6L3bwbSM.mjs";import{spawn as u}from"node:child_process";import{basename as d,dirname as f,join as p}from"node:path";import{closeSync as m,existsSync as h,mkdirSync as g,openSync as _,statSync as v}from"node:fs";import{homedir as y}from"node:os";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 v(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??y(),`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??h,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(e){h(e.lockDir)||g(e.lockDir,{recursive:!0});let t=_(p(e.lockDir,n),`w`),r=e.spawn??u,{PORT:i,...a}=process.env,o=N();try{let n=r(o.command,[...o.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return n.unref(),n}finally{try{m(t)}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=r;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:n,host:r}=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-7R982DBB.mjs`),S=e.log??_(`start`),C=e.singleFile!==void 0,w=e.projectDir??n,T=C?s(e.singleFile).canonicalFilePath:void 0,E=T?h(T):void 0,D=T?m(T):void 0;if(!C){if(!l&&!o(n))throw new I(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&S.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-dTwbVEwq.mjs`)).repairMcpConfigs)({projectDir:n,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-DiMbidtg.mjs`)).repairLaunchJson)({projectDir:n,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-qkZ_LTHD.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){S.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let O=E??b(t,n);!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 r=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];R({lockDir:t,cwd:n,spawn:e.spawn,args:r}),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=i(),N=c(),P=await g({config:t,contentDir:O,projectDir:C?w:n,contentRoot:C?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:a,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(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}function ee(t){let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1||n>65535)throw new e(`--ui-port must be a port number between 1 and 65535`);return n}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-7R982DBB.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-7R982DBB.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 t(`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-BqOu87VR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,f as t,r as n}from"./start-BqOu87VR.mjs";export{n as bootStartServer,t as resolveHost,e as startCommand};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import{Mt as e,bt as t,tn as n,v as r}from"./server-lock-CN2YHwpP-Cwa4llpq.mjs";import{$r as i}from"./dist-B1-OZ0zK.mjs";import{basename as a,dirname as o,isAbsolute as s,join as c,posix as l,relative as u,resolve as d,sep as f,win32 as p}from"node:path";import{cpSync as m,existsSync as h,lstatSync as g,mkdirSync as _,realpathSync as v,rmSync as y}from"node:fs";import{homedir as b}from"node:os";const x=r,S=t,C=e,w=`node`,T={MCP_DEBUG:`1`,OK_LOG_FILE:`/tmp/ok-mcp.log`},E=`# ok-mcp-v1`,D=`# ok-mcp-v1
|
|
2
|
+
USER_BUNDLE="$HOME/Applications/OpenKnowledge.app/Contents/Resources/cli/bin/ok.sh"
|
|
3
|
+
[ -f "$USER_BUNDLE" ] && [ -x "$USER_BUNDLE" ] && exec "$USER_BUNDLE" mcp
|
|
4
|
+
BUNDLE="/Applications/OpenKnowledge.app/Contents/Resources/cli/bin/ok.sh"
|
|
5
|
+
[ -f "$BUNDLE" ] && [ -x "$BUNDLE" ] && exec "$BUNDLE" mcp
|
|
6
|
+
command -v npx >/dev/null 2>&1 && exec npx -y @inkeep/open-knowledge@latest mcp
|
|
7
|
+
for d in "$HOME/.nvm/versions/node"/*/bin "$HOME/.fnm/node-versions"/*/installation/bin "$HOME/.asdf/installs/nodejs"/*/bin /opt/homebrew/bin /usr/local/bin "$HOME/.local/bin" "$HOME/.volta/bin"; do
|
|
8
|
+
[ -f "$d/npx" ] && [ -x "$d/npx" ] && exec "$d/npx" -y @inkeep/open-knowledge@latest mcp
|
|
9
|
+
done
|
|
10
|
+
echo "OpenKnowledge: install OK Desktop or Node.js 24+, then restart your editor" >&2
|
|
11
|
+
exit 127`,O=`# ok-mcp-win-v1`,k=`# ok-mcp-win-v1
|
|
12
|
+
if ($env:PATHEXT -notmatch 'CMD') { $env:PATHEXT = '.COM;.EXE;.BAT;.CMD;' + $env:PATHEXT }
|
|
13
|
+
if ($env:APPDATA) {
|
|
14
|
+
$shim = Join-Path $env:APPDATA 'npm\\ok.cmd'
|
|
15
|
+
if (Test-Path -LiteralPath $shim -PathType Leaf) { & $shim mcp; exit $LASTEXITCODE }
|
|
16
|
+
}
|
|
17
|
+
$ok = Get-Command ok.cmd -CommandType Application -ErrorAction SilentlyContinue
|
|
18
|
+
if ($ok) { & $ok.Source mcp; exit $LASTEXITCODE }
|
|
19
|
+
$npx = Get-Command npx.cmd -CommandType Application -ErrorAction SilentlyContinue
|
|
20
|
+
if ($npx) { & $npx.Source -y '@inkeep/open-knowledge@latest' mcp; exit $LASTEXITCODE }
|
|
21
|
+
$dirs = @()
|
|
22
|
+
if ($env:ProgramFiles) { $dirs += Join-Path $env:ProgramFiles 'nodejs' }
|
|
23
|
+
if ($env:NVM_SYMLINK) { $dirs += $env:NVM_SYMLINK }
|
|
24
|
+
if ($env:LOCALAPPDATA) {
|
|
25
|
+
$dirs += Join-Path $env:LOCALAPPDATA 'fnm\\aliases\\default'
|
|
26
|
+
$dirs += Join-Path $env:LOCALAPPDATA 'Volta\\bin'
|
|
27
|
+
$dirs += Join-Path $env:LOCALAPPDATA 'pnpm'
|
|
28
|
+
}
|
|
29
|
+
if ($env:USERPROFILE) { $dirs += Join-Path $env:USERPROFILE 'scoop\\shims' }
|
|
30
|
+
foreach ($d in $dirs) {
|
|
31
|
+
$probe = Join-Path $d 'npx.cmd'
|
|
32
|
+
if (Test-Path -LiteralPath $probe -PathType Leaf) { & $probe -y '@inkeep/open-knowledge@latest' mcp; exit $LASTEXITCODE }
|
|
33
|
+
}
|
|
34
|
+
[Console]::Error.WriteLine('OpenKnowledge: install Node.js 24+ (npm i -g @inkeep/open-knowledge), then restart your editor')
|
|
35
|
+
exit 127`;function A(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.command===`/bin/sh`){if(!Array.isArray(t.args)||t.args[0]!==`-l`||t.args[1]!==`-c`)return!1;let e=t.args[2];return typeof e==`string`&&e.includes(`# ok-mcp-v1`)}if(t.command===`powershell`){if(!Array.isArray(t.args)||t.args[0]!==`-NoProfile`||t.args[1]!==`-NonInteractive`||t.args[2]!==`-Command`)return!1;let e=t.args[3];return typeof e==`string`&&e.includes(`# ok-mcp-win-v1`)}if(t.type===`local`&&Array.isArray(t.command)){if(t.command[0]===`/bin/sh`){if(t.command[1]!==`-l`||t.command[2]!==`-c`)return!1;let e=t.command[3];return typeof e==`string`&&e.includes(`# ok-mcp-v1`)}if(t.command[0]===`powershell`){if(t.command[1]!==`-NoProfile`||t.command[2]!==`-NonInteractive`||t.command[3]!==`-Command`)return!1;let e=t.command[4];return typeof e==`string`&&e.includes(`# ok-mcp-win-v1`)}return!1}return!1}function j(e=process.argv[1]){if(!e)throw Error(`Cannot infer the local CLI entry for --dev-mcp because process.argv[1] is empty.`);let t=d(e);if(a(t)===`cli.mjs`&&a(o(t))===`dist`)return t;let n=t.split(f),r=n.lastIndexOf(`packages`);if(r===-1||n[r+1]!==`cli`)throw Error(`Cannot infer the repo root for --dev-mcp from ${t}. Run the local CLI from this repo so the built dist path can be derived.`);let i=n.slice(0,r);return c(i.length===0?f:i.join(f),`packages`,`cli`,`dist`,`cli.mjs`)}function M(e={}){return e.mode===`dev`?{command:w,args:[j(),`mcp`],env:{...T}}:(e.platformName??process.platform)===`win32`?{command:`powershell`,args:[`-NoProfile`,`-NonInteractive`,`-Command`,k]}:{command:`/bin/sh`,args:[`-l`,`-c`,D]}}function N(e={}){return e.mode===`dev`?{type:`local`,enabled:!0,command:[w,j(),`mcp`],environment:{...T}}:(e.platformName??process.platform)===`win32`?{type:`local`,enabled:!0,command:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,k]}:{type:`local`,enabled:!0,command:[`/bin/sh`,`-l`,`-c`,D]}}function P(e){if(typeof e!=`object`||!e)return!1;let t=e;return F(t,M({mode:`published`,platformName:`darwin`}))||F(t,M({mode:`published`,platformName:`win32`}))}function F(e,t){if(Object.keys(e).length!==Object.keys(t).length||e.command!==t.command)return!1;let n=t.args;return!Array.isArray(n)||!Array.isArray(e.args)||e.args.length!==n.length?!1:e.args.every((e,t)=>e===n[t])}function I(e){return e===`win32`?p:l}function L(e={}){let t=e.platformName??process.platform,n=e.home??b();return I(t).join(n,`.claude.json`)}function R(e={}){let t=e.platformName??process.platform,n=e.home??b(),r=e.env??process.env;if(t===`darwin`)return l.join(n,`Library`,`Application Support`,`Claude`,`claude_desktop_config.json`);if(t===`win32`){let e=r.APPDATA??p.join(n,`AppData`,`Roaming`);return p.join(e,`Claude`,`claude_desktop_config.json`)}throw Error(`Claude Desktop is not available on ${t}. Supported: macOS, Windows.`)}function z(e={}){let t=e.platformName??process.platform,n=e.home??b();return I(t).join(n,`.cursor`,`mcp.json`)}function B(e={}){let t=e.platformName??process.platform,n=e.home??b();return(e.env??process.env).CODEX_HOME??I(t).join(n,`.codex`)}function V(e={}){return I(e.platformName??process.platform).join(B(e),`config.toml`)}function H(e={}){let t=e.platformName??process.platform,n=e.home??b(),r=e.env??process.env,i=I(t);if(t===`win32`){let e=r.APPDATA??i.join(n,`AppData`,`Roaming`);return i.join(e,`opencode`)}let a=r.XDG_CONFIG_HOME??i.join(n,`.config`);return i.join(a,`opencode`)}function U(e={}){return I(e.platformName??process.platform).join(H(e),`opencode.json`)}function W(e={}){let t=e.platformName??process.platform,n=e.home??b();return I(t).join(n,`.openclaw`,`openclaw.json`)}const G={claude:{id:`claude`,label:S.claude,configPath:(e,t)=>L({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>M(t),scope:`global`,detectPath:(e,t)=>c(t??b(),`.claude`),projectConfigPath:e=>c(e,`.mcp.json`),projectSkillPath:e=>c(e,`.claude`,`skills`,`open-knowledge`,`SKILL.md`)},"claude-desktop":{id:`claude-desktop`,label:S[`claude-desktop`],configPath:(e,t)=>R({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>M(t),scope:`global`,detectPath:(e,t)=>o(R({home:t}))},cursor:{id:`cursor`,label:S.cursor,configPath:(e,t)=>z({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>M(t),scope:`global`,detectPath:(e,t)=>o(z({home:t})),projectConfigPath:e=>c(e,`.cursor`,`mcp.json`),projectSkillPath:e=>c(e,`.cursor`,`skills`,`open-knowledge`,`SKILL.md`)},codex:{id:`codex`,label:S.codex,configPath:(e,t)=>V({home:t}),format:`toml`,topLevelKey:`mcp_servers`,serverName:()=>n,buildEntry:(e,t)=>M(t),scope:`global`,detectPath:(e,t)=>o(V({home:t})),projectConfigPath:e=>c(e,`.codex`,`config.toml`),projectSkillPath:e=>c(e,`.codex`,`skills`,`open-knowledge`,`SKILL.md`)},opencode:{id:`opencode`,label:S.opencode,configPath:(e,t)=>U({home:t}),format:`json`,topLevelKey:`mcp`,serverName:()=>n,buildEntry:(e,t)=>N(t),scope:`global`,detectPath:(e,t)=>o(U({home:t})),projectConfigPath:e=>c(e,`opencode.json`),projectSkillPath:e=>c(e,`.opencode`,`skills`,`open-knowledge`,`SKILL.md`)},openclaw:{id:`openclaw`,label:S.openclaw,configPath:(e,t)=>W({home:t}),format:`json`,topLevelKey:`mcp`,serverMapSubKey:`servers`,serverName:()=>n,buildEntry:(e,t)=>M(t),scope:`global`,detectPath:(e,t)=>c(t??b(),`.openclaw`),offerOnlyWhenDetected:!0}};function K(e){let t=e.filter(e=>!Object.hasOwn(G,e));if(t.length>0)throw Error(`Unknown editor(s): ${t.join(`, `)}. Valid options: ${x.join(`, `)}`);return e.map(e=>G[e])}function q(e,t){let n;try{n=v(t)}catch{n=d(t)}let r;try{r=g(e)}catch(e){if(e.code!==`ENOENT`)throw e}if(r?.isSymbolicLink())throw Error(`Refusing to write through a symbolic link at ${e}. Remove the symlink and re-run project setup.`);let i=o(e);for(;i.length>1&&i!==f;){let t;try{t=v(i)}catch(e){if(e.code===`ENOENT`){i=o(i);continue}throw e}let r=u(n,t);if(r===``||!r.startsWith(`..`)&&!s(r))return;throw Error(`Refusing to write at ${e}: ancestor ${i} resolves to ${t}, which is outside the project directory ${n}. A symbolic link in the path likely escapes the project. Remove the symlink and re-run project setup.`)}}function J(e,t){let n=e.projectSkillPath?.(t);if(!n)return{editorId:e.id,label:e.label,action:`skipped-unsupported`,path:``};try{let r=i(`project`,{checkDesktop:!0}),a=o(n);q(a,t);let s=h(n)?`overwritten`:`written`;return y(a,{recursive:!0,force:!0}),_(o(a),{recursive:!0}),m(r,a,{recursive:!0}),{editorId:e.id,label:e.label,action:s,path:n}}catch(t){return{editorId:e.id,label:e.label,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}export{O as a,C as c,P as d,j as f,E as i,M as l,J as n,S as o,K as p,x as r,G as s,q as t,A as u};
|
|
36
|
+
//# sourceMappingURL=write-project-skill-CAgr6zKv.mjs.map
|
package/package.json
CHANGED
package/dist/init-BPc0rfg_.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e}from"./init-DvnBfvsT.mjs";export{e as runInit};
|
package/dist/loader-Scpsv3B1.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./loader-DTIVnIQS.mjs";export{e as loadConfig};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./preview-CnShDa2p.mjs";export{t as formatPreviewBlock,e as previewContent};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{p as e,y as t}from"./init-DvnBfvsT.mjs";import{l as n,o as r,r as i}from"./write-project-skill-CRxX-42S.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,n=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 i){let i=r[o],s=c(()=>i.configPath(``,n));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:i,home:n,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),i.projectConfigPath){let n=i.projectConfigPath,r=c(()=>n(e.projectDir));r!==null&&a.push(l({scope:`project`,editorId:o,target:i,home:void 0,cwd:e.projectDir,configPath:r,configPathOverride:r,logger:t}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(r){let i={scope:r.scope,editorId:r.editorId,configPath:r.configPath},o=e(r.target,r.cwd,r.home,r.configPathOverride);if(o===null)return{...i,outcome:`no-entry`};if(n(o))return{...i,outcome:`canonical`};r.logger(a({scope:r.scope,surface:`cli-repair`,editorId:r.editorId,configPath:r.configPath,priorEntry:o}));let s=t(r.target,r.cwd,{mode:`published`,skipAvailabilityCheck:!0},r.home,r.configPathOverride);if(s.action===`failed`){let e=s.error??`unknown write failure`;return r.logger({event:`mcp-config-repair-write-failed`,scope:r.scope,editorId:r.editorId,configPath:r.configPath,error:e}),{...i,outcome:`write-failed`,error:e}}return s.action===`declined`?(r.logger({event:`mcp-config-repair-declined`,scope:r.scope,editorId:r.editorId,configPath:r.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-DioIDpS1.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./repair-skills-xrYOvyVd.mjs";export{e as repairSkills};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./esm-BLMtE3s6.mjs";import{$r as t,Rr as n,Ur as r,d as i,ia as a,qr as o,ut as s}from"./dist-CWHBXHzy.mjs";import{i as c,o as l,s as u,t as d}from"./write-project-skill-CRxX-42S.mjs";import{dirname as f,join as p,resolve as m}from"node:path";import{existsSync as h,mkdirSync as g,readFileSync as _,readdirSync as v,rmSync as y,statSync as b,writeFileSync as x}from"node:fs";import{homedir as S}from"node:os";const C={existsSync:e=>h(e),isDirectory:e=>{try{return b(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>v(e),readFileSync:e=>_(e),writeFileSync:(e,t)=>{x(e,t)},mkdirSync:(e,t)=>{g(e,t)},rmSync:(e,t)=>{y(e,t)}},w={resolveProjectBundledSkillDir:()=>t(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>t(e,{checkDesktop:!1}),readBundledVersion:()=>n(),readRecordedVersion:e=>r(e,`cli-hosts`),writeRecordedVersion:(e,t)=>a(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>o(e)};function T(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function E(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(f(t),{recursive:!0}),D(e,t,n)}function D(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=p(e,r),a=p(t,r);n.isDirectory(i)?D(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function O(e,t,n,r,i,a){let o=[],s=p(e,`.agents`,`skills`,t),c=r.existsSync(s),l=!1;try{E(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 u){let l=p(e,c.hostDir),u=p(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{E(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 k(e,t){if(!e)return!1;try{return t.existsSync(e)?t.readFileSync(e).toString(`utf8`).includes(c):!1}catch{return!1}}function A(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 u){let o=p(e,t.hostDir,`skills`,`open-knowledge`),s=p(o,`SKILL.md`),c=n.existsSync(s),u=l[t.editorId]?.projectConfigPath?.(e),f=!c&&k(u,n);if(!c&&!f){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{d(o,e),E(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 j(e,t,n,r){let a=e=>{t.recordEvent(e).catch(()=>{})},o=()=>new Date().toISOString(),c;try{c=await t.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return r({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let l;try{l=await t.readRecordedVersion(e)}catch(e){r({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),l=null}if(l!==null&&l===c)return r({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:c}),{outcome:`skipped`,reason:`version-current`};let u=[],d=null;for(let e of s)try{u.push({id:e,sourceDir:t.resolveUserBundledSkillDir(e)})}catch(e){d=e instanceof Error?e.message:String(e)}if(u.length===0)return r({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:d??`no user-global bundles`}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${d}`}),{outcome:`skipped`,reason:`bundle-missing`};let f=[],p=u.length===s.length;for(let{id:t,sourceDir:a}of u){let o=O(e,i[t],a,n,r,c);f.push(...o.entries),o.centralWritten||(p=!1)}let m=f.some(e=>e.kind===`central`&&(e.outcome===`written`||e.outcome===`overwritten`));if(p&&m){let n=null;try{await t.writeRecordedVersion(e,c),r({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:c})}catch(e){n=e instanceof Error?e.message:String(e),r({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:c,error:n})}for(let{id:e}of u)a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:e,outcome:n===null?`installed`:`failed`,version:c,...n===null?{}:{reason:`state-write-failed:${n}`}})}else{let e=f.some(e=>e.kind===`host`&&e.outcome===`failed`);a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:c,reason:e?`all-writes-failed`:`no-hosts-installed`})}return{outcome:`done`,version:c,entries:f}}async function M(e){let t=e.logger??T,n=e.fs??C,r=e.home??S(),i={...w,...e.deps};return e.reclaimDisableEnv===`1`?(t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`}):{status:`done`,project:A(e.projectDir,i,n,t),user:await j(r,i,n,t)}}function N(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.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function P(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 F(){return new e(`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 M({projectDir:m(process.cwd()),reclaimDisableEnv:process.env.OK_RECLAIM_DISABLE??null});process.stdout.write(`${P(e)}\n`),process.exitCode=N(e)})}export{F as n,M as t};
|
|
3
|
-
//# sourceMappingURL=repair-skills-xrYOvyVd.mjs.map
|
package/dist/start-B2g--lvD.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,f as t,r as n}from"./start-RS2gu3vK.mjs";export{n as bootStartServer,t as resolveHost,e as startCommand};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{Mt as e,bt as t,tn as n,v as r}from"./server-lock-CN2YHwpP-Cwa4llpq.mjs";import{$r as i}from"./dist-CWHBXHzy.mjs";import{basename as a,dirname as o,isAbsolute as s,join as c,posix as l,relative as u,resolve as d,sep as f,win32 as p}from"node:path";import{cpSync as m,existsSync as h,lstatSync as g,mkdirSync as _,realpathSync as v,rmSync as y}from"node:fs";import{homedir as b}from"node:os";const x=r,S=t,C=e,w=`node`,T={MCP_DEBUG:`1`,OK_LOG_FILE:`/tmp/ok-mcp.log`},E=`# ok-mcp-v1`,D=`# ok-mcp-v1
|
|
2
|
-
USER_BUNDLE="$HOME/Applications/OpenKnowledge.app/Contents/Resources/cli/bin/ok.sh"
|
|
3
|
-
[ -f "$USER_BUNDLE" ] && [ -x "$USER_BUNDLE" ] && exec "$USER_BUNDLE" mcp
|
|
4
|
-
BUNDLE="/Applications/OpenKnowledge.app/Contents/Resources/cli/bin/ok.sh"
|
|
5
|
-
[ -f "$BUNDLE" ] && [ -x "$BUNDLE" ] && exec "$BUNDLE" mcp
|
|
6
|
-
command -v npx >/dev/null 2>&1 && exec npx -y @inkeep/open-knowledge@latest mcp
|
|
7
|
-
for d in "$HOME/.nvm/versions/node"/*/bin "$HOME/.fnm/node-versions"/*/installation/bin "$HOME/.asdf/installs/nodejs"/*/bin /opt/homebrew/bin /usr/local/bin "$HOME/.local/bin" "$HOME/.volta/bin"; do
|
|
8
|
-
[ -f "$d/npx" ] && [ -x "$d/npx" ] && exec "$d/npx" -y @inkeep/open-knowledge@latest mcp
|
|
9
|
-
done
|
|
10
|
-
echo "OpenKnowledge: install OK Desktop or Node.js 24+, then restart your editor" >&2
|
|
11
|
-
exit 127`;function O(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.command===`/bin/sh`){if(!Array.isArray(t.args)||t.args[0]!==`-l`||t.args[1]!==`-c`)return!1;let e=t.args[2];return typeof e==`string`&&e.includes(`# ok-mcp-v1`)}if(t.type===`local`&&Array.isArray(t.command)){if(t.command[0]!==`/bin/sh`||t.command[1]!==`-l`||t.command[2]!==`-c`)return!1;let e=t.command[3];return typeof e==`string`&&e.includes(`# ok-mcp-v1`)}return!1}function k(e=process.argv[1]){if(!e)throw Error(`Cannot infer the local CLI entry for --dev-mcp because process.argv[1] is empty.`);let t=d(e);if(a(t)===`cli.mjs`&&a(o(t))===`dist`)return t;let n=t.split(f),r=n.lastIndexOf(`packages`);if(r===-1||n[r+1]!==`cli`)throw Error(`Cannot infer the repo root for --dev-mcp from ${t}. Run the local CLI from this repo so the built dist path can be derived.`);let i=n.slice(0,r);return c(i.length===0?f:i.join(f),`packages`,`cli`,`dist`,`cli.mjs`)}function A(e={}){return e.mode===`dev`?{command:w,args:[k(),`mcp`],env:{...T}}:{command:`/bin/sh`,args:[`-l`,`-c`,D]}}function j(e={}){return e.mode===`dev`?{type:`local`,enabled:!0,command:[w,k(),`mcp`],environment:{...T}}:{type:`local`,enabled:!0,command:[`/bin/sh`,`-l`,`-c`,D]}}function M(e){if(typeof e!=`object`||!e)return!1;let t=e;if(Object.keys(t).length!==2)return!1;let n=A({mode:`published`}),r=n.args;return t.command!==n.command||!Array.isArray(r)||!Array.isArray(t.args)||t.args.length!==r.length?!1:t.args.every((e,t)=>e===r[t])}function N(e){return e===`win32`?p:l}function P(e={}){let t=e.platformName??process.platform,n=e.home??b();return N(t).join(n,`.claude.json`)}function F(e={}){let t=e.platformName??process.platform,n=e.home??b(),r=e.env??process.env;if(t===`darwin`)return l.join(n,`Library`,`Application Support`,`Claude`,`claude_desktop_config.json`);if(t===`win32`){let e=r.APPDATA??p.join(n,`AppData`,`Roaming`);return p.join(e,`Claude`,`claude_desktop_config.json`)}throw Error(`Claude Desktop is not available on ${t}. Supported: macOS, Windows.`)}function I(e={}){let t=e.platformName??process.platform,n=e.home??b();return N(t).join(n,`.cursor`,`mcp.json`)}function L(e={}){let t=e.platformName??process.platform,n=e.home??b();return(e.env??process.env).CODEX_HOME??N(t).join(n,`.codex`)}function R(e={}){return N(e.platformName??process.platform).join(L(e),`config.toml`)}function z(e={}){let t=e.platformName??process.platform,n=e.home??b(),r=e.env??process.env,i=N(t);if(t===`win32`){let e=r.APPDATA??i.join(n,`AppData`,`Roaming`);return i.join(e,`opencode`)}let a=r.XDG_CONFIG_HOME??i.join(n,`.config`);return i.join(a,`opencode`)}function B(e={}){return N(e.platformName??process.platform).join(z(e),`opencode.json`)}function V(e={}){let t=e.platformName??process.platform,n=e.home??b();return N(t).join(n,`.openclaw`,`openclaw.json`)}const H={claude:{id:`claude`,label:S.claude,configPath:(e,t)=>P({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>A(t),scope:`global`,detectPath:(e,t)=>c(t??b(),`.claude`),projectConfigPath:e=>c(e,`.mcp.json`),projectSkillPath:e=>c(e,`.claude`,`skills`,`open-knowledge`,`SKILL.md`)},"claude-desktop":{id:`claude-desktop`,label:S[`claude-desktop`],configPath:(e,t)=>F({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>A(t),scope:`global`,detectPath:(e,t)=>o(F({home:t}))},cursor:{id:`cursor`,label:S.cursor,configPath:(e,t)=>I({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>A(t),scope:`global`,detectPath:(e,t)=>o(I({home:t})),projectConfigPath:e=>c(e,`.cursor`,`mcp.json`),projectSkillPath:e=>c(e,`.cursor`,`skills`,`open-knowledge`,`SKILL.md`)},codex:{id:`codex`,label:S.codex,configPath:(e,t)=>R({home:t}),format:`toml`,topLevelKey:`mcp_servers`,serverName:()=>n,buildEntry:(e,t)=>A(t),scope:`global`,detectPath:(e,t)=>o(R({home:t})),projectConfigPath:e=>c(e,`.codex`,`config.toml`),projectSkillPath:e=>c(e,`.codex`,`skills`,`open-knowledge`,`SKILL.md`)},opencode:{id:`opencode`,label:S.opencode,configPath:(e,t)=>B({home:t}),format:`json`,topLevelKey:`mcp`,serverName:()=>n,buildEntry:(e,t)=>j(t),scope:`global`,detectPath:(e,t)=>o(B({home:t})),projectConfigPath:e=>c(e,`opencode.json`),projectSkillPath:e=>c(e,`.opencode`,`skills`,`open-knowledge`,`SKILL.md`)},openclaw:{id:`openclaw`,label:S.openclaw,configPath:(e,t)=>V({home:t}),format:`json`,topLevelKey:`mcp`,serverMapSubKey:`servers`,serverName:()=>n,buildEntry:(e,t)=>A(t),scope:`global`,detectPath:(e,t)=>c(t??b(),`.openclaw`),offerOnlyWhenDetected:!0}};function U(e){let t=e.filter(e=>!Object.hasOwn(H,e));if(t.length>0)throw Error(`Unknown editor(s): ${t.join(`, `)}. Valid options: ${x.join(`, `)}`);return e.map(e=>H[e])}function W(e,t){let n;try{n=v(t)}catch{n=d(t)}let r;try{r=g(e)}catch(e){if(e.code!==`ENOENT`)throw e}if(r?.isSymbolicLink())throw Error(`Refusing to write through a symbolic link at ${e}. Remove the symlink and re-run project setup.`);let i=o(e);for(;i.length>1&&i!==f;){let t;try{t=v(i)}catch(e){if(e.code===`ENOENT`){i=o(i);continue}throw e}let r=u(n,t);if(r===``||!r.startsWith(`..`)&&!s(r))return;throw Error(`Refusing to write at ${e}: ancestor ${i} resolves to ${t}, which is outside the project directory ${n}. A symbolic link in the path likely escapes the project. Remove the symlink and re-run project setup.`)}}function G(e,t){let n=e.projectSkillPath?.(t);if(!n)return{editorId:e.id,label:e.label,action:`skipped-unsupported`,path:``};try{let r=i(`project`,{checkDesktop:!0}),a=o(n);W(a,t);let s=h(n)?`overwritten`:`written`;return y(a,{recursive:!0,force:!0}),_(o(a),{recursive:!0}),m(r,a,{recursive:!0}),{editorId:e.id,label:e.label,action:s,path:n}}catch(t){return{editorId:e.id,label:e.label,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}export{S as a,A as c,k as d,U as f,E as i,O as l,G as n,H as o,x as r,C as s,W as t,M as u};
|
|
12
|
-
//# sourceMappingURL=write-project-skill-CRxX-42S.mjs.map
|