@inkeep/open-knowledge 0.41.0-beta.2 → 0.41.0
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/{acp-harness-probe-3CFDDPVl.mjs → acp-harness-probe-DecRl8LO.mjs} +3 -3
- package/dist/assets/skills/discovery/SKILL.md +1 -1
- package/dist/assets/skills/project/SKILL.md +1 -1
- package/dist/cli.mjs +48 -48
- package/dist/constants-Cqeohkbe.mjs +2 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/init-BeJfZs6k.mjs +1 -0
- package/dist/init-DDBwCP2s.mjs +643 -0
- package/dist/{launch-json-removal-CptGKLK_.mjs → launch-json-removal-BYSfutY8.mjs} +2 -2
- package/dist/{loader-4upXoAKc.mjs → loader-BbIO0d5P.mjs} +2 -2
- package/dist/loader-sHkW9VkF.mjs +1 -0
- package/dist/{open-browser-BLiH8Wh1.mjs → open-browser-BvP05JKj.mjs} +2 -2
- package/dist/{preview-DxtFkMmQ.mjs → preview-B7LrVAQ_.mjs} +2 -2
- package/dist/preview-CJGkRFCh.mjs +1 -0
- package/dist/{repair-launch-json-D3XbPlDO.mjs → repair-launch-json-C3CNbBhP.mjs} +2 -2
- package/dist/repair-mcp-configs-De_QzF4I.mjs +2 -0
- package/dist/repair-skills-DnayrFzZ.mjs +1 -0
- package/dist/repair-skills-xgU4BBSK.mjs +4 -0
- package/dist/src-BRhvjLkk.mjs +22 -0
- package/dist/src-Cf8OhPA7.mjs +1 -0
- package/dist/{src-B1AY2I2p.mjs → src-DAzaO37g.mjs} +313 -313
- package/dist/{start-y5LmZhJG.mjs → start-Brjd-nh_.mjs} +2 -2
- package/dist/start-DPkQR_Bf.mjs +1 -0
- package/dist/{write-project-skill-CLv32EpR.mjs → write-project-skill-4OvW1cn1.mjs} +7 -7
- package/package.json +4 -5
- package/dist/constants-CZ8NFmlZ.mjs +0 -2
- package/dist/init-2yIvpr4B.mjs +0 -643
- package/dist/init-CtYgAsHx.mjs +0 -1
- package/dist/loader-CbsXNIN0.mjs +0 -1
- package/dist/preview-DkPNmdc1.mjs +0 -1
- package/dist/repair-mcp-configs-DY2IxCII.mjs +0 -2
- package/dist/repair-skills-BMHM_-y2.mjs +0 -3
- package/dist/repair-skills-Bnuf7XDW.mjs +0 -1
- package/dist/src-B4xOeCWv.mjs +0 -1
- package/dist/src-CnyjX5Lj.mjs +0 -22
- package/dist/start-zeyY0ALU.mjs +0 -1
- package/scripts/postinstall.mjs +0 -52
package/dist/init-2yIvpr4B.mjs
DELETED
|
@@ -1,643 +0,0 @@
|
|
|
1
|
-
import{i as e,o as t,t as n}from"./chunk-DTipWd-i.mjs";import{O as r,Pa as i,Za as a,j as o}from"./src-3SN72BHH.mjs";import{Jr as s,Kr as c,Nr as l,Pr as u,Xr as d,_a as f,_r as p,ar as m,c as h,dn as g,fn as _,gn as v,ir as y,l as b,li as x,mn as S,qr as C,u as ee,wr as te}from"./src-B1AY2I2p.mjs";import{K as ne}from"./sleep-B2L0pvp4.mjs";import{M as w,P as T}from"./fs-traced-Cc6WsRtP.mjs";import{C as re,a as ie,b as ae,d as E,f as oe,i as se,l as D,m as ce,p as le,s as ue,t as de,x as fe}from"./write-project-skill-CLv32EpR.mjs";import{i as O,n as pe,o as k,r as me,s as A,t as j}from"./colors-BsmVIwfM.mjs";import{t as he}from"./constants-CZ8NFmlZ.mjs";import{t as M}from"./is-object-ByG7RnjH.mjs";import{t as ge}from"./preview-DxtFkMmQ.mjs";import{createRequire as _e}from"node:module";import{execFileSync as ve}from"node:child_process";import N,{dirname as P,isAbsolute as ye,join as F,relative as I,resolve as be,sep as xe}from"node:path";import{existsSync as L,lstatSync as Se,mkdirSync as Ce,readFileSync as R,readlinkSync as we,realpathSync as Te,statSync as Ee,writeFileSync as De}from"node:fs";import{homedir as Oe}from"node:os";import z from"node:process";import{fileURLToPath as ke}from"node:url";import*as Ae from"node:readline";import{inspect as je,stripVTControlCharacters as Me,styleText as B}from"node:util";import{AsyncLocalStorage as Ne,AsyncResource as Pe}from"node:async_hooks";const Fe=new Set([`emacs`,`vim`]);function Ie(e){return Fe.has(e)}function Le(){let e=process.env.INQUIRER_KEYBINDINGS;return e?Array.from(new Set(e.toLowerCase().split(/[\s,]+/).filter(Ie))):[]}const V=(e,t=[])=>e.name===`up`||t.includes(`vim`)&&e.name===`k`||t.includes(`emacs`)&&e.ctrl&&e.name===`p`,Re=(e,t=[])=>e.name===`down`||t.includes(`vim`)&&e.name===`j`||t.includes(`emacs`)&&e.ctrl&&e.name===`n`,ze=e=>e.name===`space`,Be=e=>e.name===`backspace`,Ve=e=>`1234567890`.includes(e.name),He=e=>e.name===`enter`||e.name===`return`;var Ue=class extends Error{name=`AbortPromptError`;message=`Prompt was aborted`;constructor(e){super(),this.cause=e?.cause}},We=class extends Error{name=`CancelPromptError`;message=`Prompt was canceled`},Ge=class extends Error{name=`ExitPromptError`},Ke=class extends Error{name=`HookError`},qe=class extends Error{name=`ValidationError`};const Je=new Ne;function Ye(e){return{rl:e,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function Xe(e,t){let n=Ye(e);return Je.run(n,()=>{function e(e){n.handleChange=()=>{n.index=0,e()},n.handleChange()}return t(e)})}function H(){let e=Je.getStore();if(!e)throw new Ke(`[Inquirer] Hook functions can only be called from within a prompt`);return e}function Ze(){return H().rl}function Qe(e){return Pe.bind((...t)=>{let n=H(),r=!1,i=n.handleChange;n.handleChange=()=>{r=!0};let a=e(...t);return r&&i(),n.handleChange=i,a})}function $e(e){let t=H(),{index:n}=t,r=e({get(){return t.hooks[n]},set(e){t.hooks[n]=e},initialized:n in t.hooks});return t.index++,r}function et(){H().handleChange()}const tt={queue(e){let t=H(),{index:n}=t;t.hooksEffect.push(()=>{t.hooksCleanup[n]?.();let r=e(Ze());if(r!=null&&typeof r!=`function`)throw new qe(`useEffect return value must be a cleanup function or nothing.`);t.hooksCleanup[n]=r})},run(){let e=H();Qe(()=>{e.hooksEffect.forEach(e=>{e()}),e.hooksEffect.length=0})()},clearAll(){let e=H();e.hooksCleanup.forEach(e=>{e?.()}),e.hooksEffect.length=0,e.hooksCleanup.length=0}};function nt(e){return typeof e==`function`}function U(e){return $e(t=>{let n=Pe.bind(function(e){t.get()!==e&&(t.set(e),et())});if(t.initialized)return[t.get(),n];let r=nt(e)?e():e;return t.set(r),[r,n]})}function rt(e,t){$e(n=>{let r=n.get();(!Array.isArray(r)||t.some((e,t)=>!Object.is(e,r[t])))&&tt.queue(e),n.set(t)})}function it(){return z.platform.startsWith(`win`)?!!z.env.CI||!!z.env.WT_SESSION||!!z.env.TERMINUS_SUBLIME||z.env.ConEmuTask===`{cmd::Cmder}`||z.env.TERM_PROGRAM===`Terminus-Sublime`||z.env.TERM_PROGRAM===`vscode`||z.env.TERM===`xterm-256color`||z.env.TERM===`alacritty`||z.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:z.env.TERM!==`linux`}const at={circleQuestionMark:`(?)`,questionMarkPrefix:`(?)`,square:`█`,squareDarkShade:`▓`,squareMediumShade:`▒`,squareLightShade:`░`,squareTop:`▀`,squareBottom:`▄`,squareLeft:`▌`,squareRight:`▐`,squareCenter:`■`,bullet:`●`,dot:`․`,ellipsis:`…`,pointerSmall:`›`,triangleUp:`▲`,triangleUpSmall:`▴`,triangleDown:`▼`,triangleDownSmall:`▾`,triangleLeftSmall:`◂`,triangleRightSmall:`▸`,home:`⌂`,heart:`♥`,musicNote:`♪`,musicNoteBeamed:`♫`,arrowUp:`↑`,arrowDown:`↓`,arrowLeft:`←`,arrowRight:`→`,arrowLeftRight:`↔`,arrowUpDown:`↕`,almostEqual:`≈`,notEqual:`≠`,lessOrEqual:`≤`,greaterOrEqual:`≥`,identical:`≡`,infinity:`∞`,subscriptZero:`₀`,subscriptOne:`₁`,subscriptTwo:`₂`,subscriptThree:`₃`,subscriptFour:`₄`,subscriptFive:`₅`,subscriptSix:`₆`,subscriptSeven:`₇`,subscriptEight:`₈`,subscriptNine:`₉`,oneHalf:`½`,oneThird:`⅓`,oneQuarter:`¼`,oneFifth:`⅕`,oneSixth:`⅙`,oneEighth:`⅛`,twoThirds:`⅔`,twoFifths:`⅖`,threeQuarters:`¾`,threeFifths:`⅗`,threeEighths:`⅜`,fourFifths:`⅘`,fiveSixths:`⅚`,fiveEighths:`⅝`,sevenEighths:`⅞`,line:`─`,lineBold:`━`,lineDouble:`═`,lineDashed0:`┄`,lineDashed1:`┅`,lineDashed2:`┈`,lineDashed3:`┉`,lineDashed4:`╌`,lineDashed5:`╍`,lineDashed6:`╴`,lineDashed7:`╶`,lineDashed8:`╸`,lineDashed9:`╺`,lineDashed10:`╼`,lineDashed11:`╾`,lineDashed12:`−`,lineDashed13:`–`,lineDashed14:`‐`,lineDashed15:`⁃`,lineVertical:`│`,lineVerticalBold:`┃`,lineVerticalDouble:`║`,lineVerticalDashed0:`┆`,lineVerticalDashed1:`┇`,lineVerticalDashed2:`┊`,lineVerticalDashed3:`┋`,lineVerticalDashed4:`╎`,lineVerticalDashed5:`╏`,lineVerticalDashed6:`╵`,lineVerticalDashed7:`╷`,lineVerticalDashed8:`╹`,lineVerticalDashed9:`╻`,lineVerticalDashed10:`╽`,lineVerticalDashed11:`╿`,lineDownLeft:`┐`,lineDownLeftArc:`╮`,lineDownBoldLeftBold:`┓`,lineDownBoldLeft:`┒`,lineDownLeftBold:`┑`,lineDownDoubleLeftDouble:`╗`,lineDownDoubleLeft:`╖`,lineDownLeftDouble:`╕`,lineDownRight:`┌`,lineDownRightArc:`╭`,lineDownBoldRightBold:`┏`,lineDownBoldRight:`┎`,lineDownRightBold:`┍`,lineDownDoubleRightDouble:`╔`,lineDownDoubleRight:`╓`,lineDownRightDouble:`╒`,lineUpLeft:`┘`,lineUpLeftArc:`╯`,lineUpBoldLeftBold:`┛`,lineUpBoldLeft:`┚`,lineUpLeftBold:`┙`,lineUpDoubleLeftDouble:`╝`,lineUpDoubleLeft:`╜`,lineUpLeftDouble:`╛`,lineUpRight:`└`,lineUpRightArc:`╰`,lineUpBoldRightBold:`┗`,lineUpBoldRight:`┖`,lineUpRightBold:`┕`,lineUpDoubleRightDouble:`╚`,lineUpDoubleRight:`╙`,lineUpRightDouble:`╘`,lineUpDownLeft:`┤`,lineUpBoldDownBoldLeftBold:`┫`,lineUpBoldDownBoldLeft:`┨`,lineUpDownLeftBold:`┥`,lineUpBoldDownLeftBold:`┩`,lineUpDownBoldLeftBold:`┪`,lineUpDownBoldLeft:`┧`,lineUpBoldDownLeft:`┦`,lineUpDoubleDownDoubleLeftDouble:`╣`,lineUpDoubleDownDoubleLeft:`╢`,lineUpDownLeftDouble:`╡`,lineUpDownRight:`├`,lineUpBoldDownBoldRightBold:`┣`,lineUpBoldDownBoldRight:`┠`,lineUpDownRightBold:`┝`,lineUpBoldDownRightBold:`┡`,lineUpDownBoldRightBold:`┢`,lineUpDownBoldRight:`┟`,lineUpBoldDownRight:`┞`,lineUpDoubleDownDoubleRightDouble:`╠`,lineUpDoubleDownDoubleRight:`╟`,lineUpDownRightDouble:`╞`,lineDownLeftRight:`┬`,lineDownBoldLeftBoldRightBold:`┳`,lineDownLeftBoldRightBold:`┯`,lineDownBoldLeftRight:`┰`,lineDownBoldLeftBoldRight:`┱`,lineDownBoldLeftRightBold:`┲`,lineDownLeftRightBold:`┮`,lineDownLeftBoldRight:`┭`,lineDownDoubleLeftDoubleRightDouble:`╦`,lineDownDoubleLeftRight:`╥`,lineDownLeftDoubleRightDouble:`╤`,lineUpLeftRight:`┴`,lineUpBoldLeftBoldRightBold:`┻`,lineUpLeftBoldRightBold:`┷`,lineUpBoldLeftRight:`┸`,lineUpBoldLeftBoldRight:`┹`,lineUpBoldLeftRightBold:`┺`,lineUpLeftRightBold:`┶`,lineUpLeftBoldRight:`┵`,lineUpDoubleLeftDoubleRightDouble:`╩`,lineUpDoubleLeftRight:`╨`,lineUpLeftDoubleRightDouble:`╧`,lineUpDownLeftRight:`┼`,lineUpBoldDownBoldLeftBoldRightBold:`╋`,lineUpDownBoldLeftBoldRightBold:`╈`,lineUpBoldDownLeftBoldRightBold:`╇`,lineUpBoldDownBoldLeftRightBold:`╊`,lineUpBoldDownBoldLeftBoldRight:`╉`,lineUpBoldDownLeftRight:`╀`,lineUpDownBoldLeftRight:`╁`,lineUpDownLeftBoldRight:`┽`,lineUpDownLeftRightBold:`┾`,lineUpBoldDownBoldLeftRight:`╂`,lineUpDownLeftBoldRightBold:`┿`,lineUpBoldDownLeftBoldRight:`╃`,lineUpBoldDownLeftRightBold:`╄`,lineUpDownBoldLeftBoldRight:`╅`,lineUpDownBoldLeftRightBold:`╆`,lineUpDoubleDownDoubleLeftDoubleRightDouble:`╬`,lineUpDoubleDownDoubleLeftRight:`╫`,lineUpDownLeftDoubleRightDouble:`╪`,lineCross:`╳`,lineBackslash:`╲`,lineSlash:`╱`},ot={tick:`✔`,info:`ℹ`,warning:`⚠`,cross:`✘`,squareSmall:`◻`,squareSmallFilled:`◼`,circle:`◯`,circleFilled:`◉`,circleDotted:`◌`,circleDouble:`◎`,circleCircle:`ⓞ`,circleCross:`ⓧ`,circlePipe:`Ⓘ`,radioOn:`◉`,radioOff:`◯`,checkboxOn:`☒`,checkboxOff:`☐`,checkboxCircleOn:`ⓧ`,checkboxCircleOff:`Ⓘ`,pointer:`❯`,triangleUpOutline:`△`,triangleLeft:`◀`,triangleRight:`▶`,lozenge:`◆`,lozengeOutline:`◇`,hamburger:`☰`,smiley:`㋡`,mustache:`෴`,star:`★`,play:`▶`,nodejs:`⬢`,oneSeventh:`⅐`,oneNinth:`⅑`,oneTenth:`⅒`},st={tick:`√`,info:`i`,warning:`‼`,cross:`×`,squareSmall:`□`,squareSmallFilled:`■`,circle:`( )`,circleFilled:`(*)`,circleDotted:`( )`,circleDouble:`( )`,circleCircle:`(○)`,circleCross:`(×)`,circlePipe:`(│)`,radioOn:`(*)`,radioOff:`( )`,checkboxOn:`[×]`,checkboxOff:`[ ]`,checkboxCircleOn:`(×)`,checkboxCircleOff:`( )`,pointer:`>`,triangleUpOutline:`∆`,triangleLeft:`◄`,triangleRight:`►`,lozenge:`♦`,lozengeOutline:`◊`,hamburger:`≡`,smiley:`☺`,mustache:`┌─┐`,star:`✶`,play:`►`,nodejs:`♦`,oneSeventh:`1/7`,oneNinth:`1/9`,oneTenth:`1/10`},ct={...at,...ot},lt={...at,...st},W=it()?ct:lt;Object.entries(ot);const ut={prefix:{idle:B(`blue`,`?`),done:B(`green`,W.tick)},spinner:{interval:80,frames:[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`].map(e=>B(`yellow`,e))},keybindings:[],style:{answer:e=>B(`cyan`,e),message:e=>B(`bold`,e),error:e=>B(`red`,`> ${e}`),defaultAnswer:e=>B(`dim`,`(${e})`),help:e=>B(`dim`,e),highlight:e=>B(`cyan`,e),key:e=>B(`cyan`,B(`bold`,`<${e}>`))}};function dt(){return{...ut,keybindings:Le()}}function ft(e){if(typeof e!=`object`||!e)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function pt(...e){let t={};for(let n of e)for(let[e,r]of Object.entries(n)){let n=t[e];t[e]=ft(n)&&ft(r)?pt(n,r):r}return t}function mt(...e){return pt(dt(),...e.filter(e=>e!=null))}function ht({status:e=`idle`,theme:t}){let[n,r]=U(!1),[i,a]=U(0),{prefix:o,spinner:s}=mt(t);return rt(()=>{if(e===`loading`){let e,t=-1,n=setTimeout(()=>{r(!0),e=setInterval(()=>{t+=1,a(t%s.frames.length)},s.interval)},300);return()=>{clearTimeout(n),clearInterval(e)}}else r(!1)},[e]),n?s.frames[i]:typeof o==`string`?o:o[e===`loading`?`idle`:e]??o.idle}function gt(e,t){return $e(n=>{let r=n.get();if(!r||r.dependencies.length!==t.length||r.dependencies.some((e,n)=>e!==t[n])){let r=e();return n.set({value:r,dependencies:t}),r}return r.value})}function _t(e){return U({current:e})[0]}function vt(e){let t=_t(e);t.current=e,rt(e=>{let n=!1,r=Qe((r,i)=>{n||t.current(i,e)});return e.input.on(`keypress`,r),()=>{n=!0,e.input.removeListener(`keypress`,r)}},[])}var yt=t(n(((t,n)=>{n.exports=i;function r(t){let n={defaultWidth:0,output:process.stdout,tty:e(`tty`)};return t?(Object.keys(n).forEach(function(e){t[e]||(t[e]=n[e])}),t):n}function i(e){let t=r(e);if(t.output.getWindowSize)return t.output.getWindowSize()[0]||t.defaultWidth;if(t.tty.getWindowSize)return t.tty.getWindowSize()[1]||t.defaultWidth;if(t.output.columns)return t.output.columns;if(process.env.CLI_WIDTH){let e=parseInt(process.env.CLI_WIDTH,10);if(!isNaN(e)&&e!==0)return e}return t.defaultWidth}}))(),1);const bt=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),xt=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,St=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,Ct=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,wt=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Tt=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Et=/\t{1,1000}/y,Dt=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy,Ot=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,kt=/\p{M}+/gu,At={limit:1/0,ellipsis:``},jt=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?jt(i,At,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[Ot,l],[Ct,0],[wt,o],[Et,s],[Dt,c],[Tt,u]],f=0,p=0,m=e.length,h=0,g=!1,_=m,v=Math.max(0,r-a),y=0,b=0,x=0,S=0;outer:for(;;){if(b>y||p>=m&&p>f){let t=e.slice(y,b)||e.slice(f,p);h=0;for(let e of t.replaceAll(kt,``)){let t=e.codePointAt(0)||0;if(S=xt(t)?2:St(t)?u:l,x+S>v&&(_=Math.min(_,Math.max(y,f)+h)),x+S>r){g=!0;break outer}h+=e.length,x+=S}y=b=0}if(p>=m)break outer;for(let t=0,n=d.length;t<n;t++){let[n,i]=d[t];if(n.lastIndex=p,n.test(e)){if(h=n===Tt?bt(e.slice(p,n.lastIndex)):n===Dt?1:n.lastIndex-p,S=h*i,x+S>v&&(_=Math.min(_,p+Math.floor((v-x)/i))),x+S>r){g=!0;break outer}x+=S,y=f,b=p,p=f=n.lastIndex;continue outer}}p+=1}return{width:g?v:x,index:g?_:m,truncated:g,ellipsed:g&&r>=a}},Mt={limit:1/0,ellipsis:``,ellipsisWidth:0},G=(e,t={})=>jt(e,Mt,t).width,Nt=`]8;;`,Pt=RegExp(`(?:\\[(?<code>\\d+)m|\\${Nt}(?<uri>.*))`,`y`),Ft=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},It=e=>`[${e}m`,Lt=e=>`${Nt}${e}`,Rt=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:G(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=G(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===``)&&(i=!0,a=t.startsWith(Nt,u+1)),i?a?o===`\x07`&&(i=!1,a=!1):o===`m`&&(i=!1):(s+=d,s===n&&!l.done&&(e.push(``),s=0)),c=l,l=r.next(),u+=o.length}o=e.at(-1),!s&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},zt=e=>{let t=e.split(` `),n=t.length;for(;n&&!G(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},Bt=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=e.split(` `),s=[``],c=0;for(let e=0;e<o.length;e++){let r=o[e];if(n.trim!==!1){let e=s.at(-1)??``,t=e.trimStart();e.length!==t.length&&(s[s.length-1]=t,c=G(t))}e!==0&&(c>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),c=0),(c||n.trim===!1)&&(s[s.length-1]+=` `,c++));let i=G(r);if(n.hard&&i>t){let e=t-c,n=1+Math.floor((i-e-1)/t);Math.floor((i-1)/t)<n&&s.push(``),Rt(s,r,t),c=G(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){Rt(s,r,t),c=G(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){Rt(s,r,t),c=G(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>zt(e)));let l=s.join(`
|
|
2
|
-
`),u=!1;for(let e=0;e<l.length;e++){let t=l[e];if(r+=t,u)u=!1;else if(u=t>=`\ud800`&&t<=`\udbff`,u)continue;if(t===`\x1B`||t===``){Pt.lastIndex=e+1;let t=Pt.exec(l)?.groups;if(t?.code!==void 0){let e=Number.parseFloat(t.code);i=e===39?void 0:e}else t?.uri!==void 0&&(a=t.uri.length===0?void 0:t.uri)}if(l[e+1]===`
|
|
3
|
-
`){a&&(r+=Lt(``));let e=i?Ft(i):void 0;i&&e&&(r+=It(e))}else t===`
|
|
4
|
-
`&&(i&&Ft(i)&&(r+=It(i)),a&&(r+=Lt(a)))}return r},Vt=/\r?\n/;function Ht(e,t,n){return String(e).normalize().split(Vt).map(e=>Bt(e,t,n)).join(`
|
|
5
|
-
`)}function Ut(e,t){return e.split(`
|
|
6
|
-
`).flatMap(e=>Ht(e,t,{trim:!1,wordWrap:!1}).split(`
|
|
7
|
-
`).map(e=>e.trimEnd())).join(`
|
|
8
|
-
`)}function Wt(){return(0,yt.default)({defaultWidth:80,output:Ze().output})}function Gt({active:e,renderedItems:t,pageSize:n,loop:r}){let i=_t({lastPointer:e,lastActive:void 0}),{lastPointer:a,lastActive:o}=i.current,s=Math.floor(n/2),c=t.reduce((e,t)=>e+t.length,0),l=t.slice(0,e).reduce((e,t)=>e+t.length,0),u=l;if(c>n)if(r)u=a,o!=null&&o<e&&e-o<n&&(u=Math.min(s,Math.abs(e-o)===1?Math.min(a+(t[o]?.length??0),Math.max(l,a)):a+e-o));else{let r=t.slice(e).reduce((e,t)=>e+t.length,0);u=r<n-s?n-r:Math.min(l,s)}return i.current.lastPointer=u,i.current.lastActive=e,u}function Kt({items:e,active:t,renderItem:n,pageSize:r,loop:i=!0}){let a=Wt(),o=t=>(t%e.length+e.length)%e.length,s=e.map((e,r)=>e==null?[]:Ut(n({item:e,index:r,isActive:r===t}),a).split(`
|
|
9
|
-
`)),c=s.reduce((e,t)=>e+t.length,0),l=e=>s[e]??[],u=Gt({active:t,renderedItems:s,pageSize:r,loop:i}),d=l(t).slice(0,r),f=u+d.length<=r?u:r-d.length,p=Array.from({length:r});p.splice(f,d.length,...d);let m=new Set([t]),h=f+d.length,g=o(t+1);for(;h<r&&!m.has(g)&&(i&&c>r?g!==t:g>t);){let e=l(g).slice(0,r-h);p.splice(h,e.length,...e),m.add(g),h+=e.length,g=o(g+1)}for(h=f-1,g=o(t-1);h>=0&&!m.has(g)&&(i&&c>r?g!==t:g<t);){let e=l(g),t=e.slice(Math.max(0,e.length-h-1));p.splice(h-t.length+1,t.length,...t),m.add(g),h-=t.length,g=o(g-1)}return p.filter(e=>typeof e==`string`).join(`
|
|
10
|
-
`)}var qt=t(n(((t,n)=>{let r=e(`stream`);n.exports=class extends r{#e=null;constructor(e={}){super(e),this.writable=this.readable=!0,this.muted=!1,this.on(`pipe`,this._onpipe),this.replace=e.replace,this._prompt=e.prompt||null,this._hadControl=!1}#t(e,t){return this._dest?this._dest[e]:this._src?this._src[e]:t}#n(e,...t){typeof this._dest?.[e]==`function`&&this._dest[e](...t),typeof this._src?.[e]==`function`&&this._src[e](...t)}get isTTY(){return this.#e===null?this.#t(`isTTY`,!1):this.#e}set isTTY(e){this.#e=e}get rows(){return this.#t(`rows`)}get columns(){return this.#t(`columns`)}mute(){this.muted=!0}unmute(){this.muted=!1}_onpipe(e){this._src=e}pipe(e,t){return this._dest=e,super.pipe(e,t)}pause(){if(this._src)return this._src.pause()}resume(){if(this._src)return this._src.resume()}write(e){if(this.muted){if(!this.replace)return!0;if(e.match(/^\u001b/))return e.indexOf(this._prompt)===0&&(e=e.slice(this._prompt.length),e=e.replace(/./g,this.replace),e=this._prompt+e),this._hadControl=!0,this.emit(`data`,e);this._prompt&&this._hadControl&&e.indexOf(this._prompt)===0&&(this._hadControl=!1,this.emit(`data`,this._prompt),e=e.slice(this._prompt.length)),e=e.toString().replace(/./g,this.replace)}this.emit(`data`,e)}end(e){this.muted&&(e=e&&this.replace?e.toString().replace(/./g,this.replace):null),e&&this.emit(`data`,e),this.emit(`end`)}destroy(...e){return this.#n(`destroy`,...e)}destroySoon(...e){return this.#n(`destroySoon`,...e)}close(...e){return this.#n(`close`,...e)}}}))(),1);const K=[];K.push(`SIGHUP`,`SIGINT`,`SIGTERM`),process.platform!==`win32`&&K.push(`SIGALRM`,`SIGABRT`,`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),process.platform===`linux`&&K.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`);const Jt=e=>!!e&&typeof e==`object`&&typeof e.removeListener==`function`&&typeof e.emit==`function`&&typeof e.reallyExit==`function`&&typeof e.listeners==`function`&&typeof e.kill==`function`&&typeof e.pid==`number`&&typeof e.on==`function`,Yt=Symbol.for(`signal-exit emitter`),Xt=globalThis,Zt=Object.defineProperty.bind(Object);var Qt=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(Xt[Yt])return Xt[Yt];Zt(Xt,Yt,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,t){this.listeners[e].push(t)}removeListener(e,t){let n=this.listeners[e],r=n.indexOf(t);r!==-1&&(r===0&&n.length===1?n.length=0:n.splice(r,1))}emit(e,t,n){if(this.emitted[e])return!1;this.emitted[e]=!0;let r=!1;for(let i of this.listeners[e])r=i(t,n)===!0||r;return e===`exit`&&(r=this.emit(`afterExit`,t,n)||r),r}},$t=class{};const en=e=>({onExit(t,n){return e.onExit(t,n)},load(){return e.load()},unload(){return e.unload()}});var tn=class extends $t{onExit(){return()=>{}}load(){}unload(){}},nn=class extends $t{#e=rn.platform===`win32`?`SIGINT`:`SIGHUP`;#t=new Qt;#n;#r;#i;#a={};#o=!1;constructor(e){super(),this.#n=e,this.#a={};for(let t of K)this.#a[t]=()=>{let n=this.#n.listeners(t),{count:r}=this.#t,i=e;if(typeof i.__signal_exit_emitter__==`object`&&typeof i.__signal_exit_emitter__.count==`number`&&(r+=i.__signal_exit_emitter__.count),n.length===r){this.unload();let n=this.#t.emit(`exit`,null,t),r=t===`SIGHUP`?this.#e:t;n||e.kill(e.pid,r)}};this.#i=e.reallyExit,this.#r=e.emit}onExit(e,t){if(!Jt(this.#n))return()=>{};this.#o===!1&&this.load();let n=t?.alwaysLast?`afterExit`:`exit`;return this.#t.on(n,e),()=>{this.#t.removeListener(n,e),this.#t.listeners.exit.length===0&&this.#t.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#o){this.#o=!0,this.#t.count+=1;for(let e of K)try{let t=this.#a[e];t&&this.#n.on(e,t)}catch{}this.#n.emit=(e,...t)=>this.#c(e,...t),this.#n.reallyExit=e=>this.#s(e)}}unload(){this.#o&&(this.#o=!1,K.forEach(e=>{let t=this.#a[e];if(!t)throw Error(`Listener not defined for signal: `+e);try{this.#n.removeListener(e,t)}catch{}}),this.#n.emit=this.#r,this.#n.reallyExit=this.#i,--this.#t.count)}#s(e){return Jt(this.#n)?(this.#n.exitCode=e||0,this.#t.emit(`exit`,this.#n.exitCode,null),this.#i.call(this.#n,this.#n.exitCode)):0}#c(e,...t){let n=this.#r;if(e===`exit`&&Jt(this.#n)){typeof t[0]==`number`&&(this.#n.exitCode=t[0]);let r=n.call(this.#n,e,...t);return this.#t.emit(`exit`,this.#n.exitCode,null),r}else return n.call(this.#n,e,...t)}};const rn=globalThis.process,{onExit:an,load:on,unload:sn}=en(Jt(rn)?new nn(rn):new tn),cn=`\x1B[?25l`,ln=(e=1)=>e>0?`[${e}A`:``,un=(e=1)=>e>0?`[${e}B`:``,dn=(e,t)=>typeof t==`number`&&!Number.isNaN(t)?`[${t+1};${e+1}H`:`[${e+1}G`,fn=`\x1B[2K`,pn=e=>e>0?(fn+ln(1)).repeat(e-1)+fn+`\x1B[G`:``,mn=e=>e.split(`
|
|
11
|
-
`).length,hn=e=>e.split(`
|
|
12
|
-
`).pop()??``;var gn=class{height=0;extraLinesUnderPrompt=0;cursorPos;rl;constructor(e){this.rl=e,this.cursorPos=e.getCursorPos()}write(e){this.rl.output.unmute(),this.rl.output.write(e),this.rl.output.mute()}render(e,t=``){let n=Me(hn(e)),r=n;this.rl.line.length>0&&(r=r.slice(0,-this.rl.line.length)),this.rl.setPrompt(r),this.cursorPos=this.rl.getCursorPos();let i=Wt();e=Ut(e,i),t=Ut(t,i),n.length%i===0&&(e+=`
|
|
13
|
-
`);let a=e+(t?`
|
|
14
|
-
`+t:``),o=Math.floor(n.length/i)-this.cursorPos.rows+(t?mn(t):0);o>0&&(a+=ln(o)),a+=dn(this.cursorPos.cols),this.write(un(this.extraLinesUnderPrompt)+pn(this.height)+a),this.extraLinesUnderPrompt=o,this.height=mn(a)}checkCursorPos(){let e=this.rl.getCursorPos();e.cols!==this.cursorPos.cols&&(this.write(dn(e.cols)),this.cursorPos=e)}done({clearContent:e}){this.rl.setPrompt(``);let t=un(this.extraLinesUnderPrompt);t+=e?pn(this.height):`
|
|
15
|
-
`,t+=`\x1B[G`,t+=`\x1B[?25h`,this.write(t),this.rl.close()}},_n=class extends Promise{static withResolver(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}};const vn=globalThis.setImmediate;function yn(){let e=Error.prepareStackTrace,t=[];try{Error.prepareStackTrace=(e,n)=>{let r=n.slice(1);return t=r,r},Error().stack}catch{return t}return Error.prepareStackTrace=e,t}function bn(e){let t=yn();return(n,r={})=>{let{input:i=process.stdin,signal:a}=r,o=new Set,s=new qt.default;s.pipe(r.output??process.stdout);let c=Ae.createInterface({terminal:!0,input:i,output:s});s.mute();let l=new gn(c),{promise:u,resolve:d,reject:f}=_n.withResolver(),p=()=>f(new We);if(a){let e=()=>f(new Ue({cause:a.reason}));if(a.aborted)return e(),Object.assign(u,{cancel:p});a.addEventListener(`abort`,e),o.add(()=>a.removeEventListener(`abort`,e))}o.add(an((e,t)=>{f(new Ge(`User force closed the prompt with ${e} ${t}`))}));let m=()=>f(new Ge(`User force closed the prompt with SIGINT`));return c.on(`SIGINT`,m),o.add(()=>c.removeListener(`SIGINT`,m)),Xe(c,a=>{let m=Pe.bind(()=>tt.clearAll());c.on(`close`,m),o.add(()=>c.removeListener(`close`,m));let h=()=>{let r=()=>l.checkCursorPos();c.input.on(`keypress`,r),o.add(()=>c.input.removeListener(`keypress`,r));let i=null;a(()=>{let r=!1;try{let a=e(n,e=>{r?d(e):i={value:e}});if(a===void 0){let e=t[1]?.getFileName();throw e&&!e.startsWith(`file://`)&&(e=N.resolve(e)),Error(`Prompt functions must return a string.\n at ${e}`)}let[o,s]=typeof a==`string`?[a]:a;l.render(o,s),tt.run()}catch(e){f(e)}if(r=!0,i!==null){let{value:e}=i;i=null,d(e)}})};return`readableFlowing`in i?vn(h):h(),Object.assign(u.then(e=>(tt.clearAll(),e),e=>{throw tt.clearAll(),e}).finally(()=>{o.forEach(e=>e()),l.done({clearContent:!!r.clearPromptOnDone}),s.end()}).then(()=>u),{cancel:p})})}}var q=class{separator=B(`dim`,Array.from({length:15}).join(W.line));type=`separator`;constructor(e){e&&(this.separator=e)}static isSeparator(e){return!!(e&&typeof e==`object`&&`type`in e&&e.type===`separator`)}},xn=ne();const Sn=`.ok/`,J=`**/.ok/*`,Cn=`!**/${a}/`;function wn(e){let t=[`.ok/`,`.okignore`];for(let n of ue){let r=D[n];r.projectConfigPath&&t.push(In(r.projectConfigPath(e),e))}t.push(`.claude/launch.json`);let n=F(e,...r);if(L(n))try{let e=o(R(n,`utf-8`));if(e){for(let[n,r]of Object.entries(e.skills))if(n!==`open-knowledge`)for(let e of r.hosts){let r=i[e];r&&t.push(`${r}/${n}/`)}}}catch{}return Array.from(new Set(t))}function Tn(e,t){let n=jn(e,t).tracked;if(n.length>0)return{kind:`refused-tracked`,tracked:n,remediation:Mn(n)};let r=Y(e);if(r.kind!==`ok`)return r.result;let i=L(r.path)?R(r.path,`utf-8`):``,a=Fn(i),o=[],s=[];for(let e of t)Pn(a,e)?s.push(e):o.push(e);if(o.length===0)return{kind:`updated`,appended:o,alreadyPresent:s,removed:[]};let c=i.length===0||i.endsWith(`
|
|
16
|
-
`)?``:`
|
|
17
|
-
`,l=`${o.join(`
|
|
18
|
-
`)}\n`;try{De(r.path,`${i}${c}${l}`,`utf-8`)}catch{return{kind:`no-exclude`,reason:`inaccessible`}}return{kind:`updated`,appended:o,alreadyPresent:s,removed:[]}}function En(e,t){let n=Y(e);if(n.kind!==`ok`)return n.result;if(!L(n.path))return{kind:`updated`,appended:[],alreadyPresent:[],removed:[]};let r=t.map(e=>Nn(e)),i=new Set;for(let e of r)for(let t of e)i.add(t);i.add(J),i.add(Cn);let a;try{a=R(n.path,`utf-8`)}catch{return{kind:`no-exclude`,reason:`inaccessible`}}let o=a.split(`
|
|
19
|
-
`),s=new Set,c=[];for(let e of o){let t=e.trim();if(i.has(t)){s.add(t);continue}c.push(e)}let l=t.filter(e=>{for(let t of Nn(e))if(s.has(t))return!0;return!1});if(s.size===0)return{kind:`updated`,appended:[],alreadyPresent:[],removed:[]};let u=c.join(`
|
|
20
|
-
`);if(u!==a)try{De(n.path,u,`utf-8`)}catch{return{kind:`no-exclude`,reason:`inaccessible`}}return{kind:`updated`,appended:[],alreadyPresent:[],removed:l}}function Dn(e){let t=Y(e);if(t.kind!==`ok`)return t.result.reason===`no-git`||t.result.reason===`malformed-pointer`||t.result.reason===`inaccessible`?`no-git`:`shared`;if(!L(t.path))return`shared`;let n;try{n=R(t.path,`utf-8`)}catch{return`shared`}let r=Fn(n),i=wn(e);for(let e of i)if(Pn(r,e))return`local-only`;return r.has(J)?`local-only`:`shared`}function On(e){let t=Y(e);if(t.kind!==`ok`||!L(t.path))return[];let n;try{n=R(t.path,`utf-8`)}catch{return[]}let r=Fn(n);return wn(e).filter(e=>Pn(r,e))}function kn(e){let t=Y(e);if(t.kind!==`ok`||!L(t.path))return!1;let n;try{n=R(t.path,`utf-8`)}catch{return!1}let r=Fn(n);return r.has(J)&&r.has(Cn)}function An(e,t){let n=Y(e);if(n.kind!==`ok`)return n.result;let r=``;if(L(n.path))try{r=R(n.path,`utf-8`)}catch{return{kind:`no-exclude`,reason:`inaccessible`}}let i=new Set([...Nn(Sn),J,Cn]),a=r.split(`
|
|
21
|
-
`).filter(e=>!i.has(e.trim())),o=t?[J,Cn]:[Sn],s=a.join(`
|
|
22
|
-
`),c=`${s}${s.length===0||s.endsWith(`
|
|
23
|
-
`)?``:`
|
|
24
|
-
`}${o.join(`
|
|
25
|
-
`)}\n`;try{De(n.path,c,`utf-8`)}catch{return{kind:`no-exclude`,reason:`inaccessible`}}return{kind:`updated`,appended:o,alreadyPresent:[],removed:[]}}function jn(e,t){let n=[];for(let r of t)if(L(be(e,r)))try{ve(`git`,[`ls-files`,`--error-unmatch`,`--`,r],x({cwd:e,stdio:[`ignore`,`ignore`,`ignore`]})),n.push(r)}catch{}return{tracked:n}}function Mn(e){let t=[];t.push(`Cannot switch OpenKnowledge to local-only — these OK files are tracked upstream:`),t.push(``);for(let n of e)t.push(` ${n}`);t.push(``),t.push(`.git/info/exclude only hides files that git isn't already tracking. To proceed, untrack them first:`),t.push(``);for(let n of e){let e=n.replace(/\/$/,``),r=n.endsWith(`/`)?`-r `:``;t.push(` git rm --cached ${r}${e}`)}return t.push(``),t.push("Then re-run the command. Note: `git rm --cached` removes the files from the index — your teammates will see a deletion on their next pull. If you don't want that, leave sharing mode set to 'shared'."),t.join(`
|
|
26
|
-
`)}function Y(e){let t=f(e);switch(t.kind){case`repository`:{let e=t.repository.readCommonDir();if(e.kind===`unreadable`)return{kind:`no-exclude`,result:{kind:`no-exclude`,reason:`inaccessible`}};let n=F(e.path,`info`);return L(n)?{kind:`ok`,path:F(n,`exclude`)}:{kind:`no-exclude`,result:{kind:`no-exclude`,reason:`no-info-dir`}}}case`absent`:return{kind:`no-exclude`,result:{kind:`no-exclude`,reason:`no-git`}};case`malformed-pointer`:return{kind:`no-exclude`,result:{kind:`no-exclude`,reason:`malformed-pointer`}};case`inaccessible`:return{kind:`no-exclude`,result:{kind:`no-exclude`,reason:`inaccessible`}}}}function Nn(e){let t=e.replace(/\/$/,``);return new Set([e,t,`/${e}`,`/${t}`])}function Pn(e,t){for(let n of Nn(t))if(e.has(n))return!0;return!1}function Fn(e){let t=new Set;for(let n of e.split(`
|
|
27
|
-
`)){let e=n.trim();e.length!==0&&t.add(e)}return t}function In(e,t){return Ln(I(t,e))}function Ln(e){return xe===`/`?e:e.split(xe).join(`/`)}function Rn(e){for(let t of e.split(`
|
|
28
|
-
`)){let e=t.trimStart();if(!(e.length===0||e.length===t.length))return t.charCodeAt(0)===9?{insertSpaces:!1,tabSize:1}:{insertSpaces:!0,tabSize:t.length-e.length}}return{insertSpaces:!0,tabSize:2}}function zn(e){let t=(e.match(/\r\n/g)??[]).length;return t===0?!1:t>=(e.match(/\n/g)??[]).length-t}function Bn(e){try{return Ee(e).mode&511}catch{return}}function Vn(e,t){let n=e.charCodeAt(0)===65279,r=n?e.slice(1):e,i=r.includes(`\r
|
|
29
|
-
`)?`\r
|
|
30
|
-
`:`
|
|
31
|
-
`,a=s(r,t,void 0,{formattingOptions:{...Rn(r),eol:i}});if(a.length===0)return{text:e,changed:!1};let o=`${n?``:``}${c(r,a)}`;return{text:o,changed:o!==e}}const Hn={icon:{checked:B(`green`,W.circleFilled),unchecked:W.circle,cursor:W.pointer,disabledChecked:B(`green`,W.circleDouble),disabledUnchecked:`-`},style:{disabled:e=>B(`dim`,e),renderSelectedChoices:e=>e.map(e=>e.short).join(`, `),description:e=>B(`cyan`,e),keysHelpTip:e=>e.map(([e,t])=>`${B(`bold`,e)} ${B(`dim`,t)}`).join(B(`dim`,` • `))},i18n:{disabledError:`This option is disabled and cannot be toggled.`}};function Un(e){return!q.isSeparator(e)&&!e.disabled}function Wn(e){return!q.isSeparator(e)}function Gn(e){return!q.isSeparator(e)&&e.checked}function Kn(e){return Un(e)?{...e,checked:!e.checked}:e}function qn(e){return function(t){return Un(t)?{...t,checked:e}:t}}function Jn(e){return e.map(e=>{if(q.isSeparator(e))return e;if(typeof e!=`object`||!e||!(`value`in e)){let t=String(e);return{value:e,name:t,short:t,checkedName:t,disabled:!1,checked:!1}}let t=e.name??String(e.value),n={value:e.value,name:t,short:e.short??t,checkedName:e.checkedName??t,disabled:e.disabled??!1,checked:e.checked??!1};return e.description&&(n.description=e.description),n})}var Yn=bn((e,t)=>{let{pageSize:n=7,loop:r=!0,required:i,validate:a=()=>!0}=e,o={all:`a`,invert:`i`,...e.shortcuts},s=mt(Hn,e.theme),{keybindings:c}=s,[l,u]=U(`idle`),d=ht({status:l,theme:s}),[f,p]=U(Jn(e.choices)),m=gt(()=>{let e=f.findIndex(Wn),t=f.findLastIndex(Wn);if(e===-1)throw new qe(`[checkbox prompt] No selectable choices. All choices are disabled.`);return{first:e,last:t}},[f]),[h,g]=U(m.first),[_,v]=U();vt(async e=>{if(He(e)){let e=f.filter(Gn),n=await a([...e]);i&&!e.length?v(`At least one choice must be selected`):n===!0?(u(`done`),t(e.map(e=>e.value))):v(n||`You must select a valid value`)}else if(V(e,c)||Re(e,c)){if(_&&v(void 0),r||V(e,c)&&h!==m.first||Re(e,c)&&h!==m.last){let t=V(e,c)?-1:1,n=h;do n=(n+t+f.length)%f.length;while(!Wn(f[n]));g(n)}}else if(ze(e)){let e=f[h];e&&!q.isSeparator(e)&&(e.disabled?v(s.i18n.disabledError):(v(void 0),p(f.map((e,t)=>t===h?Kn(e):e))))}else if(e.name===o.all){let e=f.some(e=>Un(e)&&!e.checked);p(f.map(qn(e)))}else if(e.name===o.invert)p(f.map(Kn));else if(Ve(e)){let t=Number(e.name)-1,n=-1,r=f.findIndex(e=>q.isSeparator(e)?!1:(n++,n===t)),i=f[r];i&&Un(i)&&(g(r),p(f.map((e,t)=>t===r?Kn(e):e)))}});let y=s.style.message(e.message,l),b,x=Kt({items:f,active:h,renderItem({item:e,isActive:t}){if(q.isSeparator(e))return` ${e.separator}`;let n=t?s.icon.cursor:` `;if(e.disabled){let t=typeof e.disabled==`string`?e.disabled:`(disabled)`,r=e.checked?s.icon.disabledChecked:s.icon.disabledUnchecked;return s.style.disabled(`${n}${r} ${e.name} ${t}`)}t&&(b=e.description);let r=e.checked?s.icon.checked:s.icon.unchecked,i=e.checked?e.checkedName:e.name;return(t?s.style.highlight:e=>e)(`${n}${r} ${i}`)},pageSize:n,loop:r});if(l===`done`){let e=f.filter(Gn);return[d,y,s.style.answer(s.style.renderSelectedChoices(e,f))].filter(Boolean).join(` `)}let S=[[`↑↓`,`navigate`],[`space`,`select`]];o.all&&S.push([o.all,`all`]),o.invert&&S.push([o.invert,`invert`]),S.push([`⏎`,`submit`]);let C=s.style.keysHelpTip(S);return`${[[d,y].filter(Boolean).join(` `),x,` `,b?s.style.description(b):``,_?s.style.error(_):``,C].filter(Boolean).join(`
|
|
32
|
-
`).trimEnd()}${cn}`});const Xn={icon:{cursor:W.pointer},style:{disabled:e=>B(`dim`,e),description:e=>B(`cyan`,e),keysHelpTip:e=>e.map(([e,t])=>`${B(`bold`,e)} ${B(`dim`,t)}`).join(B(`dim`,` • `))},i18n:{disabledError:`This option is disabled and cannot be selected.`},indexMode:`hidden`};function Zn(e){return!q.isSeparator(e)&&!e.disabled}function Qn(e){return!q.isSeparator(e)}function $n(e){return e.map(e=>{if(q.isSeparator(e))return e;if(typeof e!=`object`||!e||!(`value`in e)){let t=String(e);return{value:e,name:t,short:t,disabled:!1}}let t=e.name??String(e.value),n={value:e.value,name:t,short:e.short??t,disabled:e.disabled??!1};return e.description&&(n.description=e.description),n})}var er=bn((e,t)=>{let{loop:n=!0,pageSize:r=7}=e,i=mt(Xn,e.theme),{keybindings:a}=i,[o,s]=U(`idle`),c=ht({status:o,theme:i}),l=_t(),u=!a.includes(`vim`),d=gt(()=>$n(e.choices),[e.choices]),f=gt(()=>{let e=d.findIndex(Qn),t=d.findLastIndex(Qn);if(e===-1)throw new qe(`[select prompt] No selectable choices. All choices are disabled.`);return{first:e,last:t}},[d]),p=gt(()=>`default`in e?d.findIndex(t=>Zn(t)&&t.value===e.default):-1,[e.default,d]),[m,h]=U(p===-1?f.first:p),g=d[m];if(g==null||q.isSeparator(g))throw Error(`Active index does not point to a choice`);let[_,v]=U();vt((e,r)=>{if(clearTimeout(l.current),_&&v(void 0),He(e))g.disabled?v(i.i18n.disabledError):(s(`done`),t(g.value));else if(V(e,a)||Re(e,a)){if(r.clearLine(0),n||V(e,a)&&m!==f.first||Re(e,a)&&m!==f.last){let t=V(e,a)?-1:1,n=m;do n=(n+t+d.length)%d.length;while(!Qn(d[n]));h(n)}}else if(Ve(e)&&!Number.isNaN(Number(r.line))){let e=Number(r.line)-1,t=-1,n=d.findIndex(n=>q.isSeparator(n)?!1:(t++,t===e)),i=d[n];i!=null&&Zn(i)&&h(n),l.current=setTimeout(()=>{r.clearLine(0)},700)}else if(Be(e))r.clearLine(0);else if(u){let e=r.line.toLowerCase(),t=d.findIndex(t=>q.isSeparator(t)||!Zn(t)?!1:t.name.toLowerCase().startsWith(e));t!==-1&&h(t),l.current=setTimeout(()=>{r.clearLine(0)},700)}}),rt(()=>()=>{clearTimeout(l.current)},[]);let y=i.style.message(e.message,o),b=i.style.keysHelpTip([[`↑↓`,`navigate`],[`⏎`,`select`]]),x=0,S=Kt({items:d,active:m,renderItem({item:e,isActive:t,index:n}){if(q.isSeparator(e))return x++,` ${e.separator}`;let r=t?i.icon.cursor:` `,a=i.indexMode===`number`?`${n+1-x}. `:``;if(e.disabled){let n=typeof e.disabled==`string`?e.disabled:`(disabled)`,r=t?i.icon.cursor:`-`;return i.style.disabled(`${r} ${a}${e.name} ${n}`)}return(t?i.style.highlight:e=>e)(`${r} ${a}${e.name}`)},pageSize:r,loop:n});if(o===`done`)return[c,y,i.style.answer(g.short)].filter(Boolean).join(` `);let{description:C}=g;return`${[[c,y].filter(Boolean).join(` `),S,` `,C?i.style.description(C):``,_?i.style.error(_):``,b].filter(Boolean).join(`
|
|
33
|
-
`).trimEnd()}${cn}`});
|
|
34
|
-
/*!
|
|
35
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
36
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
37
|
-
*
|
|
38
|
-
* Redistribution and use in source and binary forms, with or without
|
|
39
|
-
* modification, are permitted provided that the following conditions are met:
|
|
40
|
-
*
|
|
41
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
42
|
-
* list of conditions and the following disclaimer.
|
|
43
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
44
|
-
* this list of conditions and the following disclaimer in the
|
|
45
|
-
* documentation and/or other materials provided with the distribution.
|
|
46
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
47
|
-
* may be used to endorse or promote products derived from this software without
|
|
48
|
-
* specific prior written permission.
|
|
49
|
-
*
|
|
50
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
51
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
52
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
53
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
54
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
55
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
56
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
57
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
58
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
59
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
60
|
-
*/
|
|
61
|
-
let tr=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;var nr=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e){let t=!0,n=!0,r=`Z`;if(typeof e==`string`){let i=e.match(tr);i?(i[1]||(t=!1,e=`0000-01-01T${e}`),n=!!i[2],n&&e[10]===` `&&(e=e.replace(` `,`T`)),i[2]&&+i[2]>23?e=``:(r=i[3]||null,e=e.toUpperCase(),!r&&n&&(e+=`Z`))):e=``}super(e),isNaN(this.getTime())||(this.#e=t,this.#t=n,this.#n=r)}isDateTime(){return this.#e&&this.#t}isLocal(){return!this.#e||!this.#t||!this.#n}isDate(){return this.#e&&!this.#t}isTime(){return this.#t&&!this.#e}isValid(){return this.#e||this.#t}toISOString(){let e=super.toISOString();if(this.isDate())return e.slice(0,10);if(this.isTime())return e.slice(11,23);if(this.#n===null)return e.slice(0,-1);if(this.#n===`Z`)return e;let t=this.#n.slice(1,3)*60+ +this.#n.slice(4,6);return t=this.#n[0]===`-`?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#n}static wrapAsOffsetDateTime(t,n=`Z`){let r=new e(t);return r.#n=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#n=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#t=!1,n.#n=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#e=!1,n.#n=null,n}};
|
|
62
|
-
/*!
|
|
63
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
64
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
65
|
-
*
|
|
66
|
-
* Redistribution and use in source and binary forms, with or without
|
|
67
|
-
* modification, are permitted provided that the following conditions are met:
|
|
68
|
-
*
|
|
69
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
70
|
-
* list of conditions and the following disclaimer.
|
|
71
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
72
|
-
* this list of conditions and the following disclaimer in the
|
|
73
|
-
* documentation and/or other materials provided with the distribution.
|
|
74
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
75
|
-
* may be used to endorse or promote products derived from this software without
|
|
76
|
-
* specific prior written permission.
|
|
77
|
-
*
|
|
78
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
79
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
80
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
81
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
82
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
83
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
84
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
85
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
86
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
87
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
88
|
-
*/
|
|
89
|
-
function rr(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop().length+1]}function ir(e,t,n){let r=e.split(/\r\n|\n|\r/g),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
|
|
90
|
-
`,e===t&&(i+=` `.repeat(a+n+2),i+=`^
|
|
91
|
-
`))}return i}var X=class extends Error{line;column;codeblock;constructor(e,t){let[n,r]=rr(t.toml,t.ptr),i=ir(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}};
|
|
92
|
-
/*!
|
|
93
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
94
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
95
|
-
*
|
|
96
|
-
* Redistribution and use in source and binary forms, with or without
|
|
97
|
-
* modification, are permitted provided that the following conditions are met:
|
|
98
|
-
*
|
|
99
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
100
|
-
* list of conditions and the following disclaimer.
|
|
101
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
102
|
-
* this list of conditions and the following disclaimer in the
|
|
103
|
-
* documentation and/or other materials provided with the distribution.
|
|
104
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
105
|
-
* may be used to endorse or promote products derived from this software without
|
|
106
|
-
* specific prior written permission.
|
|
107
|
-
*
|
|
108
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
109
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
110
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
111
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
112
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
113
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
114
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
115
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
116
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
117
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
118
|
-
*/
|
|
119
|
-
let ar=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,or=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,sr=/^[+-]?0[0-9_]/;function cr(e,t){let n=e[t++],r=n,i=n===`'`,a=n===e[t]&&n===e[t+1];a&&(e[t+=2]===`
|
|
120
|
-
`?t++:e[t]===`\r`&&e[t+1]===`
|
|
121
|
-
`&&(t+=2));let o=``,s=t,c=0;for(let l=t;l<e.length;l++)if(n=e[l],a&&(n===`
|
|
122
|
-
`||n===`\r`&&e[l+1]===`
|
|
123
|
-
`))c&&=3;else if(n<` `&&n!==` `||n===``)throw new X(`control characters are not allowed in strings`,{toml:e,ptr:l});else if((!c||c===3)&&n===r&&(!a||e[l+1]===r&&e[l+2]===r))return a&&(e[l+3]===r&&l++,e[l+3]===r&&l++),[c?o:o+e.slice(s,l),l+(a?3:1)];else if(!c)!i&&n===`\\`&&(o+=e.slice(s,s=l),c=1);else if(c===1)if(n===`x`||n===`u`||n===`U`){let t=0,r=n===`x`?2:n===`u`?4:8;for(let n=0;n<r;n++,l++){let n=e.charCodeAt(l+1),r=n>=48&&n<=57?n-48:n>=65&&n<=70?n-65+10:n>=97&&n<=102?n-97+10:-1;if(r<0)throw new X(`invalid non-hex character in unicode escape`,{toml:e,ptr:l+1});t=t<<4|r}if(t<0||t>1114111||t>=55296&&t<=57343)throw new X(`invalid unicode escape`,{toml:e,ptr:l});o+=String.fromCodePoint(t),s=l+1,c=0}else if(n===` `||n===` `)c=2;else{if(n===`b`)o+=`\b`;else if(n===`t`)o+=` `;else if(n===`n`)o+=`
|
|
124
|
-
`;else if(n===`f`)o+=`\f`;else if(n===`r`)o+=`\r`;else if(n===`e`)o+=`\x1B`;else if(n===`"`)o+=`"`;else if(n===`\\`)o+=`\\`;else throw new X(`unrecognized escape sequence`,{toml:e,ptr:l});s=l+1,c=0}else if(n!==` `&&n!==` `){if(c===2)throw new X(`invalid escape: only line-ending whitespace may be escaped`,{toml:e,ptr:s});c=+(!i&&n===`\\`),s=l}throw new X(`unfinished string`,{toml:e,ptr:t})}function lr(e,t,n,r){if(e===`true`)return!0;if(e===`false`)return!1;if(e===`-inf`)return-1/0;if(e===`inf`||e===`+inf`)return 1/0;if(e===`nan`||e===`+nan`||e===`-nan`)return NaN;if(e===`-0`)return r?0n:0;let i=ar.test(e);if(i||or.test(e)){if(sr.test(e))throw new X(`leading zeroes are not allowed`,{toml:t,ptr:n});e=e.replace(/_/g,``);let a=+e;if(isNaN(a))throw new X(`invalid number`,{toml:t,ptr:n});if(i){if((i=!Number.isSafeInteger(a))&&!r)throw new X(`integer value cannot be represented losslessly`,{toml:t,ptr:n});(i||r===!0)&&(a=BigInt(e))}return a}let a=new nr(e);if(!a.isValid())throw new X(`invalid value`,{toml:t,ptr:n});return a}
|
|
125
|
-
/*!
|
|
126
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
127
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
128
|
-
*
|
|
129
|
-
* Redistribution and use in source and binary forms, with or without
|
|
130
|
-
* modification, are permitted provided that the following conditions are met:
|
|
131
|
-
*
|
|
132
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
133
|
-
* list of conditions and the following disclaimer.
|
|
134
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
135
|
-
* this list of conditions and the following disclaimer in the
|
|
136
|
-
* documentation and/or other materials provided with the distribution.
|
|
137
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
138
|
-
* may be used to endorse or promote products derived from this software without
|
|
139
|
-
* specific prior written permission.
|
|
140
|
-
*
|
|
141
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
142
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
143
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
144
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
145
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
146
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
147
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
148
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
149
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
150
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
151
|
-
*/
|
|
152
|
-
function ur(e,t=0,n=e.length){let r=e.indexOf(`
|
|
153
|
-
`,t);return e[r-1]===`\r`&&r--,r<=n?r:-1}function dr(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r===`
|
|
154
|
-
`)return n;if(r===`\r`&&e[n+1]===`
|
|
155
|
-
`)return n+1;if(r<` `&&r!==` `||r===``)throw new X(`control characters are not allowed in comments`,{toml:e,ptr:t})}return e.length}function Z(e,t,n,r){let i;for(;;){for(;(i=e[t])===` `||i===` `||!n&&(i===`
|
|
156
|
-
`||i===`\r`&&e[t+1]===`
|
|
157
|
-
`);)t++;if(r||i!==`#`)break;t=dr(e,t)}return t}function fr(e,t,n,r,i=!1){if(!r)return t=ur(e,t),t<0?e.length:t;for(let a=t;a<e.length;a++){let t=e[a];if(t===`#`)a=ur(e,a);else if(t===n)return a+1;else if(t===r||i&&(t===`
|
|
158
|
-
`||t===`\r`&&e[a+1]===`
|
|
159
|
-
`))return a}throw new X(`cannot find end of structure`,{toml:e,ptr:t})}
|
|
160
|
-
/*!
|
|
161
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
162
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
163
|
-
*
|
|
164
|
-
* Redistribution and use in source and binary forms, with or without
|
|
165
|
-
* modification, are permitted provided that the following conditions are met:
|
|
166
|
-
*
|
|
167
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
168
|
-
* list of conditions and the following disclaimer.
|
|
169
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
170
|
-
* this list of conditions and the following disclaimer in the
|
|
171
|
-
* documentation and/or other materials provided with the distribution.
|
|
172
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
173
|
-
* may be used to endorse or promote products derived from this software without
|
|
174
|
-
* specific prior written permission.
|
|
175
|
-
*
|
|
176
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
177
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
178
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
179
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
180
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
181
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
182
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
183
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
184
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
185
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
186
|
-
*/
|
|
187
|
-
function pr(e,t,n){let r=e.slice(t,n),i=r.indexOf(`#`);return i>-1&&(dr(e,i),r=r.slice(0,i)),[r.trimEnd(),i]}function mr(e,t,n,r,i){if(r===0)throw new X(`document contains excessively nested structures. aborting.`,{toml:e,ptr:t});let a=e[t];if(a===`[`||a===`{`){let[o,s]=a===`[`?vr(e,t,r,i):_r(e,t,r,i);if(n){if(s=Z(e,s),e[s]===`,`)s++;else if(e[s]!==n)throw new X(`expected comma or end of structure`,{toml:e,ptr:s})}return[o,s]}if(a===`"`||a===`'`){let[r,i]=cr(e,t);if(n){if(i=Z(e,i),e[i]&&e[i]!==`,`&&e[i]!==n&&e[i]!==`
|
|
188
|
-
`&&e[i]!==`\r`)throw new X(`unexpected character encountered`,{toml:e,ptr:i});e[i]===`,`&&i++}return[r,i]}let o=fr(e,t,`,`,n),s=pr(e,t,o-+(e[o-1]===`,`));if(!s[0])throw new X(`incomplete key-value declaration: no value specified`,{toml:e,ptr:t});return n&&s[1]>-1&&(o=Z(e,t+s[1]),e[o]===`,`&&o++),[lr(s[0],e,t,i),o]}
|
|
189
|
-
/*!
|
|
190
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
191
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
192
|
-
*
|
|
193
|
-
* Redistribution and use in source and binary forms, with or without
|
|
194
|
-
* modification, are permitted provided that the following conditions are met:
|
|
195
|
-
*
|
|
196
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
197
|
-
* list of conditions and the following disclaimer.
|
|
198
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
199
|
-
* this list of conditions and the following disclaimer in the
|
|
200
|
-
* documentation and/or other materials provided with the distribution.
|
|
201
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
202
|
-
* may be used to endorse or promote products derived from this software without
|
|
203
|
-
* specific prior written permission.
|
|
204
|
-
*
|
|
205
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
206
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
207
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
208
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
209
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
210
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
211
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
212
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
213
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
214
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
215
|
-
*/
|
|
216
|
-
let hr=/^[a-zA-Z0-9-_]+[ \t]*$/;function gr(e,t,n=`=`){let r=t-1,i=[],a=e.indexOf(n,t);if(a<0)throw new X(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});do{let o=e[t=++r];if(o!==` `&&o!==` `)if(o===`"`||o===`'`){if(o===e[t+1]&&o===e[t+2])throw new X(`multiline strings are not allowed in keys`,{toml:e,ptr:t});let[s,c]=cr(e,t);r=e.indexOf(`.`,c);let l=e.slice(c,r<0||r>a?a:r),u=ur(l);if(u>-1)throw new X(`newlines are not allowed in keys`,{toml:e,ptr:t+r+u});if(l.trimStart())throw new X(`found extra tokens after the string part`,{toml:e,ptr:c});if(a<c&&(a=e.indexOf(n,c),a<0))throw new X(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});i.push(s)}else{r=e.indexOf(`.`,t);let n=e.slice(t,r<0||r>a?a:r);if(!hr.test(n))throw new X(`only letter, numbers, dashes and underscores are allowed in keys`,{toml:e,ptr:t});i.push(n.trimEnd())}}while(r+1&&r<a);return[i,Z(e,a+1,!0,!0)]}function _r(e,t,n,r){let i={},a=new Set,o;for(t++;(o=e[t++])!==`}`&&o;)if(o===`,`)throw new X(`expected value, found comma`,{toml:e,ptr:t-1});else if(o===`#`)t=dr(e,t);else if(o!==` `&&o!==` `&&o!==`
|
|
217
|
-
`&&o!==`\r`){let o,s=i,c=!1,[l,u]=gr(e,t-1);for(let n=0;n<l.length;n++){if(n&&(s=c?s[o]:s[o]={}),o=l[n],(c=Object.hasOwn(s,o))&&(typeof s[o]!=`object`||a.has(s[o])))throw new X(`trying to redefine an already defined value`,{toml:e,ptr:t});!c&&o===`__proto__`&&Object.defineProperty(s,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new X(`trying to redefine an already defined value`,{toml:e,ptr:t});let[d,f]=mr(e,u,`}`,n-1,r);a.add(d),s[o]=d,t=f}if(!o)throw new X(`unfinished table encountered`,{toml:e,ptr:t});return[i,t]}function vr(e,t,n,r){let i=[],a;for(t++;(a=e[t++])!==`]`&&a;)if(a===`,`)throw new X(`expected value, found comma`,{toml:e,ptr:t-1});else if(a===`#`)t=dr(e,t);else if(a!==` `&&a!==` `&&a!==`
|
|
218
|
-
`&&a!==`\r`){let a=mr(e,t-1,`]`,n-1,r);i.push(a[0]),t=a[1]}if(!a)throw new X(`unfinished array encountered`,{toml:e,ptr:t});return[i,t]}
|
|
219
|
-
/*!
|
|
220
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
221
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
222
|
-
*
|
|
223
|
-
* Redistribution and use in source and binary forms, with or without
|
|
224
|
-
* modification, are permitted provided that the following conditions are met:
|
|
225
|
-
*
|
|
226
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
227
|
-
* list of conditions and the following disclaimer.
|
|
228
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
229
|
-
* this list of conditions and the following disclaimer in the
|
|
230
|
-
* documentation and/or other materials provided with the distribution.
|
|
231
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
232
|
-
* may be used to endorse or promote products derived from this software without
|
|
233
|
-
* specific prior written permission.
|
|
234
|
-
*
|
|
235
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
236
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
237
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
238
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
239
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
240
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
241
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
242
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
243
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
244
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
245
|
-
*/
|
|
246
|
-
function yr(e,t,n,r){let i=t,a=n,o,s=!1,c;for(let t=0;t<e.length;t++){if(t){if(i=s?i[o]:i[o]={},a=(c=a[o]).c,r===0&&(c.t===1||c.t===2))return null;if(c.t===2){let e=i.length-1;i=i[e],a=a[e].c}}if(o=e[t],(s=Object.hasOwn(i,o))&&a[o]?.t===0&&a[o]?.d)return null;s||(o===`__proto__`&&(Object.defineProperty(i,o,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(a,o,{enumerable:!0,configurable:!0,writable:!0})),a[o]={t:t<e.length-1&&r===2?3:r,d:!1,i:0,c:{}})}if(c=a[o],c.t!==r&&!(r===1&&c.t===3)||(r===2&&(c.d||(c.d=!0,i[o]=[]),i[o].push(i={}),c.c[c.i++]=c={t:1,d:!1,i:0,c:{}}),c.d))return null;if(c.d=!0,r===1)i=s?i[o]:i[o]={};else if(r===0&&s)return null;return[o,i,c.c]}function br(e,{maxDepth:t=1e3,integersAsBigInt:n}={}){let r={},i={},a=r,o=i;for(let s=Z(e,0);s<e.length;){if(e[s]===`[`){let t=e[++s]===`[`,n=gr(e,s+=+t,`]`);if(t){if(e[n[1]-1]!==`]`)throw new X(`expected end of table declaration`,{toml:e,ptr:n[1]-1});n[1]++}let c=yr(n[0],r,i,t?2:1);if(!c)throw new X(`trying to redefine an already defined table or value`,{toml:e,ptr:s});o=c[2],a=c[1],s=n[1]}else{let r=gr(e,s),i=yr(r[0],a,o,0);if(!i)throw new X(`trying to redefine an already defined table or value`,{toml:e,ptr:s});let c=mr(e,r[1],void 0,t,n);i[1][i[0]]=c[0],s=c[1]}if(s=Z(e,s,!0),e[s]&&e[s]!==`
|
|
247
|
-
`&&e[s]!==`\r`)throw new X(`each key-value declaration must be followed by an end-of-line`,{toml:e,ptr:s});s=Z(e,s)}return r}
|
|
248
|
-
/*!
|
|
249
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
250
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
251
|
-
*
|
|
252
|
-
* Redistribution and use in source and binary forms, with or without
|
|
253
|
-
* modification, are permitted provided that the following conditions are met:
|
|
254
|
-
*
|
|
255
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
256
|
-
* list of conditions and the following disclaimer.
|
|
257
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
258
|
-
* this list of conditions and the following disclaimer in the
|
|
259
|
-
* documentation and/or other materials provided with the distribution.
|
|
260
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
261
|
-
* may be used to endorse or promote products derived from this software without
|
|
262
|
-
* specific prior written permission.
|
|
263
|
-
*
|
|
264
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
265
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
266
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
267
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
268
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
269
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
270
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
271
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
272
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
273
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
274
|
-
*/
|
|
275
|
-
let xr=/^[a-z0-9-_]+$/i;function Sr(e){let t=typeof e;if(t===`object`){if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`}return t}function Cr(e){for(let t=0;t<e.length;t++)if(Sr(e[t])!==`object`)return!1;return e.length!=0}function wr(e){return JSON.stringify(e).replace(/\x7f/g,`\\u007f`)}function Tr(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);if(t===`number`)return isNaN(e)?`nan`:e===1/0?`inf`:e===-1/0?`-inf`:Number.isInteger(e)&&(r||!Number.isSafeInteger(e))?e.toFixed(1):e.toString();if(t===`bigint`||t===`boolean`)return e.toString();if(t===`string`)return wr(e);if(t===`date`){if(isNaN(e.getTime()))throw TypeError(`cannot serialize invalid date`);return e.toISOString()}if(t===`object`)return Er(e,n,r);if(t===`array`)return Dr(e,n,r)}function Er(e,t,n){let r=Object.keys(e);if(r.length===0)return`{}`;let i=`{ `;for(let a=0;a<r.length;a++){let o=r[a];a&&(i+=`, `),i+=xr.test(o)?o:wr(o),i+=` = `,i+=Tr(e[o],Sr(e[o]),t-1,n)}return i+` }`}function Dr(e,t,n){if(e.length===0)return`[]`;let r=`[ `;for(let i=0;i<e.length;i++){if(i&&(r+=`, `),e[i]===null||e[i]===void 0)throw TypeError(`arrays cannot contain null or undefined values`);r+=Tr(e[i],Sr(e[i]),t-1,n)}return r+` ]`}function Or(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let i=``;for(let a=0;a<e.length;a++)i+=`${i&&`
|
|
276
|
-
`}[[${t}]]\n`,i+=kr(0,e[a],t,n,r);return i}function kr(e,t,n,r,i){if(r===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let a=``,o=``,s=Object.keys(t);for(let e=0;e<s.length;e++){let c=s[e];if(t[c]!==null&&t[c]!==void 0){let e=Sr(t[c]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let s=xr.test(c)?c:wr(c);if(e===`array`&&Cr(t[c]))o+=(o&&`
|
|
277
|
-
`)+Or(t[c],n?`${n}.${s}`:s,r-1,i);else if(e===`object`){let e=n?`${n}.${s}`:s;o+=(o&&`
|
|
278
|
-
`)+kr(e,t[c],e,r-1,i)}else a+=s,a+=` = `,a+=Tr(t[c],e,r,i),a+=`
|
|
279
|
-
`}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function Ar(e,{maxDepth:t=1e3,numbersAsFloat:n=!1}={}){if(Sr(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let r=kr(0,e,``,t,n);return r[r.length-1]===`
|
|
280
|
-
`?r:r+`
|
|
281
|
-
`}const jr=`${E}-dev`;function Mr(e){return e.startsWith(E)}function Nr(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.command!==`ok-pi-managed-extension`||!Array.isArray(t.args))return!1;let n=t.args[0];return typeof n==`string`&&Mr(n)}function Pr(e){return{command:le,args:[e]}}function Fr(e={}){let t=e.mode===`dev`?jr:oe,n={unix:ce({...e,platformName:`darwin`}),win32:ce({...e,platformName:`win32`})};return`${t}
|
|
282
|
-
/**
|
|
283
|
-
* Open Knowledge bridge for Pi — MANAGED FILE, written by \`ok init\`.
|
|
284
|
-
* Hand edits are overwritten whenever OK re-syncs this project; remove it
|
|
285
|
-
* with \`ok deinit\` (or delete the file) to disconnect Pi from OK.
|
|
286
|
-
*
|
|
287
|
-
* On session start it spawns Open Knowledge's MCP stdio server via OK's
|
|
288
|
-
* resilient launcher (bundle, then npx, then version-manager probes), performs
|
|
289
|
-
* the MCP handshake, and registers each MCP tool as a Pi tool under an
|
|
290
|
-
* \`ok_\` prefix (Pi has no MCP namespacing; the prefix keeps OK's \`edit\` /
|
|
291
|
-
* \`write\` from shadowing Pi's built-in tools).
|
|
292
|
-
*/
|
|
293
|
-
import { spawn } from "node:child_process";
|
|
294
|
-
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
295
|
-
|
|
296
|
-
const LAUNCHERS = ${JSON.stringify(n,null,2)} as const;
|
|
297
|
-
|
|
298
|
-
const TOOL_PREFIX = "ok_";
|
|
299
|
-
// First contact may cold-install the CLI through npx — allow a generous window.
|
|
300
|
-
const INIT_TIMEOUT_MS = 120000;
|
|
301
|
-
const STDERR_TAIL_LIMIT = 2000;
|
|
302
|
-
|
|
303
|
-
interface McpContentItem {
|
|
304
|
-
type: string;
|
|
305
|
-
text?: string;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
interface McpToolInfo {
|
|
309
|
-
name: string;
|
|
310
|
-
description?: string;
|
|
311
|
-
inputSchema?: Record<string, unknown>;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
interface PendingRequest {
|
|
315
|
-
resolve: (value: Record<string, unknown>) => void;
|
|
316
|
-
reject: (err: Error) => void;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
class OkMcpClient {
|
|
320
|
-
private child: ChildProcessWithoutNullStreams;
|
|
321
|
-
private pending = new Map<number, PendingRequest>();
|
|
322
|
-
private nextId = 1;
|
|
323
|
-
private buffer = "";
|
|
324
|
-
private stderrTail = "";
|
|
325
|
-
alive = true;
|
|
326
|
-
|
|
327
|
-
constructor(cwd: string, onExit: () => void) {
|
|
328
|
-
const launcher = process.platform === "win32" ? LAUNCHERS.win32 : LAUNCHERS.unix;
|
|
329
|
-
const env: Record<string, string | undefined> = { ...process.env };
|
|
330
|
-
const launcherEnv = (launcher as { env?: Record<string, string> }).env;
|
|
331
|
-
if (launcherEnv) Object.assign(env, launcherEnv);
|
|
332
|
-
this.child = spawn(launcher.command, [...launcher.args], {
|
|
333
|
-
cwd,
|
|
334
|
-
env,
|
|
335
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
336
|
-
// Inline (not the withHiddenWindowsConsole helper): this spawn lives in the
|
|
337
|
-
// GENERATED Pi extension source, which must stay dependency-free (Pi loads
|
|
338
|
-
// it with jiti; no npm packages resolve). Hide the console on Windows anyway.
|
|
339
|
-
windowsHide: true,
|
|
340
|
-
});
|
|
341
|
-
this.child.stdout.setEncoding("utf8");
|
|
342
|
-
this.child.stdout.on("data", (chunk: string) => this.onStdout(chunk));
|
|
343
|
-
this.child.stderr.setEncoding("utf8");
|
|
344
|
-
this.child.stderr.on("data", (chunk: string) => {
|
|
345
|
-
this.stderrTail = (this.stderrTail + chunk).slice(-STDERR_TAIL_LIMIT);
|
|
346
|
-
});
|
|
347
|
-
// A write buffered before the pipe breaks surfaces as an 'error' on stdin
|
|
348
|
-
// (not on the child); unhandled it would crash Pi's extension host.
|
|
349
|
-
// Swallow it — the exit handler owns teardown.
|
|
350
|
-
this.child.stdin.on("error", () => {});
|
|
351
|
-
const fail = () => {
|
|
352
|
-
if (!this.alive) return;
|
|
353
|
-
this.alive = false;
|
|
354
|
-
const err = new Error(
|
|
355
|
-
"Open Knowledge MCP server exited" +
|
|
356
|
-
(this.stderrTail ? ": " + this.stderrTail.trim() : ""),
|
|
357
|
-
);
|
|
358
|
-
for (const p of this.pending.values()) p.reject(err);
|
|
359
|
-
this.pending.clear();
|
|
360
|
-
onExit();
|
|
361
|
-
};
|
|
362
|
-
this.child.on("exit", fail);
|
|
363
|
-
this.child.on("error", fail);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private onStdout(chunk: string): void {
|
|
367
|
-
this.buffer += chunk;
|
|
368
|
-
let newline = this.buffer.indexOf("\\n");
|
|
369
|
-
while (newline !== -1) {
|
|
370
|
-
const line = this.buffer.slice(0, newline).trim();
|
|
371
|
-
this.buffer = this.buffer.slice(newline + 1);
|
|
372
|
-
if (line.startsWith("{")) {
|
|
373
|
-
try {
|
|
374
|
-
this.onMessage(JSON.parse(line) as Record<string, unknown>);
|
|
375
|
-
} catch {
|
|
376
|
-
// Non-JSON noise on stdout is ignored; framing recovers on the next line.
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
newline = this.buffer.indexOf("\\n");
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
private onMessage(msg: Record<string, unknown>): void {
|
|
384
|
-
const id = msg.id;
|
|
385
|
-
if (typeof msg.method === "string") {
|
|
386
|
-
// Server-initiated request (e.g. roots/list). This bridge declares no
|
|
387
|
-
// client capabilities, so decline rather than leave the server hanging.
|
|
388
|
-
if (id !== undefined && id !== null) {
|
|
389
|
-
this.send({
|
|
390
|
-
jsonrpc: "2.0",
|
|
391
|
-
id,
|
|
392
|
-
error: { code: -32601, message: "Method not supported by the OK Pi bridge" },
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
if (typeof id !== "number") return;
|
|
398
|
-
const pending = this.pending.get(id);
|
|
399
|
-
if (!pending) return;
|
|
400
|
-
this.pending.delete(id);
|
|
401
|
-
const error = msg.error as { message?: string } | undefined;
|
|
402
|
-
if (error) {
|
|
403
|
-
pending.reject(new Error(error.message || "Open Knowledge MCP error"));
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
pending.resolve((msg.result ?? {}) as Record<string, unknown>);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
private send(msg: Record<string, unknown>): void {
|
|
410
|
-
// Buffered stdout can still dispatch onMessage replies after close() ends
|
|
411
|
-
// stdin; writing then would raise ERR_STREAM_WRITE_AFTER_END unhandled.
|
|
412
|
-
if (!this.alive) return;
|
|
413
|
-
this.child.stdin.write(JSON.stringify(msg) + "\\n");
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
request(
|
|
417
|
-
method: string,
|
|
418
|
-
params: Record<string, unknown>,
|
|
419
|
-
opts: { timeoutMs?: number; signal?: AbortSignal } = {},
|
|
420
|
-
): Promise<Record<string, unknown>> {
|
|
421
|
-
if (!this.alive) return Promise.reject(new Error("Open Knowledge MCP server is not running"));
|
|
422
|
-
const id = this.nextId++;
|
|
423
|
-
return new Promise<Record<string, unknown>>((resolve, reject) => {
|
|
424
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
425
|
-
let onAbort: (() => void) | undefined;
|
|
426
|
-
const cleanup = () => {
|
|
427
|
-
if (timer !== undefined) clearTimeout(timer);
|
|
428
|
-
if (onAbort && opts.signal) opts.signal.removeEventListener("abort", onAbort);
|
|
429
|
-
this.pending.delete(id);
|
|
430
|
-
};
|
|
431
|
-
const done: PendingRequest = {
|
|
432
|
-
resolve: (value) => {
|
|
433
|
-
cleanup();
|
|
434
|
-
resolve(value);
|
|
435
|
-
},
|
|
436
|
-
reject: (err) => {
|
|
437
|
-
cleanup();
|
|
438
|
-
reject(err);
|
|
439
|
-
},
|
|
440
|
-
};
|
|
441
|
-
this.pending.set(id, done);
|
|
442
|
-
if (opts.timeoutMs) {
|
|
443
|
-
timer = setTimeout(() => {
|
|
444
|
-
done.reject(new Error(method + " timed out after " + opts.timeoutMs + "ms"));
|
|
445
|
-
}, opts.timeoutMs);
|
|
446
|
-
}
|
|
447
|
-
if (opts.signal) {
|
|
448
|
-
onAbort = () => {
|
|
449
|
-
this.notify("notifications/cancelled", { requestId: id, reason: "aborted" });
|
|
450
|
-
done.reject(new Error("Cancelled"));
|
|
451
|
-
};
|
|
452
|
-
if (opts.signal.aborted) {
|
|
453
|
-
onAbort();
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
opts.signal.addEventListener("abort", onAbort, { once: true });
|
|
457
|
-
}
|
|
458
|
-
this.send({ jsonrpc: "2.0", id, method, params });
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
notify(method: string, params: Record<string, unknown>): void {
|
|
463
|
-
if (!this.alive) return;
|
|
464
|
-
this.send({ jsonrpc: "2.0", method, params });
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
close(): void {
|
|
468
|
-
this.alive = false;
|
|
469
|
-
for (const p of this.pending.values()) {
|
|
470
|
-
p.reject(new Error("Open Knowledge MCP client closed"));
|
|
471
|
-
}
|
|
472
|
-
this.pending.clear();
|
|
473
|
-
// ok mcp exits on stdin EOF; the delayed kill is a backstop.
|
|
474
|
-
try {
|
|
475
|
-
this.child.stdin.end();
|
|
476
|
-
} catch {
|
|
477
|
-
// Already gone.
|
|
478
|
-
}
|
|
479
|
-
const child = this.child;
|
|
480
|
-
setTimeout(() => {
|
|
481
|
-
try {
|
|
482
|
-
child.kill();
|
|
483
|
-
} catch {
|
|
484
|
-
// Already gone.
|
|
485
|
-
}
|
|
486
|
-
}, 2000).unref();
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/** JSON Schema pass-through: Pi validates plain JSON Schema parameters. */
|
|
491
|
-
function toParameters(inputSchema: Record<string, unknown> | undefined): Record<string, unknown> {
|
|
492
|
-
if (!inputSchema || typeof inputSchema !== "object") {
|
|
493
|
-
return { type: "object", properties: {} };
|
|
494
|
-
}
|
|
495
|
-
const schema = { ...inputSchema };
|
|
496
|
-
delete schema.$schema;
|
|
497
|
-
return schema;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
function contentText(content: unknown): string {
|
|
501
|
-
if (!Array.isArray(content)) return "";
|
|
502
|
-
return (content as McpContentItem[])
|
|
503
|
-
.filter((item) => item && item.type === "text" && typeof item.text === "string")
|
|
504
|
-
.map((item) => item.text as string)
|
|
505
|
-
.join("\\n");
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
export default function okBridge(pi: {
|
|
509
|
-
on(event: string, handler: (event: unknown, ctx: unknown) => unknown): void;
|
|
510
|
-
registerTool(definition: Record<string, unknown>): void;
|
|
511
|
-
}) {
|
|
512
|
-
let client: OkMcpClient | null = null;
|
|
513
|
-
let starting: Promise<OkMcpClient> | null = null;
|
|
514
|
-
let sessionCwd = process.cwd();
|
|
515
|
-
const registeredTools = new Set<string>();
|
|
516
|
-
|
|
517
|
-
async function ensureClient(): Promise<OkMcpClient> {
|
|
518
|
-
if (client && client.alive) return client;
|
|
519
|
-
if (starting) return starting;
|
|
520
|
-
starting = (async () => {
|
|
521
|
-
const next = new OkMcpClient(sessionCwd, () => {
|
|
522
|
-
if (client === next) client = null;
|
|
523
|
-
});
|
|
524
|
-
try {
|
|
525
|
-
await next.request(
|
|
526
|
-
"initialize",
|
|
527
|
-
{
|
|
528
|
-
protocolVersion: "2025-06-18",
|
|
529
|
-
capabilities: {},
|
|
530
|
-
clientInfo: { name: "pi", version: "1.0.0" },
|
|
531
|
-
},
|
|
532
|
-
{ timeoutMs: INIT_TIMEOUT_MS },
|
|
533
|
-
);
|
|
534
|
-
} catch (err) {
|
|
535
|
-
// A timed-out initialize rejects the request while the child may
|
|
536
|
-
// still be running; tear it down so retries don't stack orphans.
|
|
537
|
-
next.close();
|
|
538
|
-
throw err;
|
|
539
|
-
}
|
|
540
|
-
next.notify("notifications/initialized", {});
|
|
541
|
-
client = next;
|
|
542
|
-
return next;
|
|
543
|
-
})();
|
|
544
|
-
try {
|
|
545
|
-
return await starting;
|
|
546
|
-
} finally {
|
|
547
|
-
starting = null;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
async function registerOkTools(): Promise<number> {
|
|
552
|
-
const mcp = await ensureClient();
|
|
553
|
-
const listed = await mcp.request("tools/list", {}, { timeoutMs: INIT_TIMEOUT_MS });
|
|
554
|
-
const tools = Array.isArray(listed.tools) ? (listed.tools as McpToolInfo[]) : [];
|
|
555
|
-
for (const tool of tools) {
|
|
556
|
-
const name = TOOL_PREFIX + tool.name;
|
|
557
|
-
if (registeredTools.has(name)) continue;
|
|
558
|
-
registeredTools.add(name);
|
|
559
|
-
pi.registerTool({
|
|
560
|
-
name,
|
|
561
|
-
label: "OK " + tool.name,
|
|
562
|
-
description: tool.description || "Open Knowledge " + tool.name + " tool.",
|
|
563
|
-
parameters: toParameters(tool.inputSchema),
|
|
564
|
-
execute: async (
|
|
565
|
-
_toolCallId: string,
|
|
566
|
-
params: Record<string, unknown>,
|
|
567
|
-
signal: AbortSignal | undefined,
|
|
568
|
-
) => {
|
|
569
|
-
const live = await ensureClient();
|
|
570
|
-
const result = await live.request(
|
|
571
|
-
"tools/call",
|
|
572
|
-
{ name: tool.name, arguments: params ?? {} },
|
|
573
|
-
{ signal },
|
|
574
|
-
);
|
|
575
|
-
const text = contentText(result.content);
|
|
576
|
-
if (result.isError) {
|
|
577
|
-
throw new Error(text || "Open Knowledge tool " + tool.name + " failed");
|
|
578
|
-
}
|
|
579
|
-
return {
|
|
580
|
-
content: [{ type: "text", text }],
|
|
581
|
-
details: result.structuredContent,
|
|
582
|
-
};
|
|
583
|
-
},
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
return tools.length;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
590
|
-
const cwd = (ctx as { cwd?: string } | undefined)?.cwd;
|
|
591
|
-
if (typeof cwd === "string" && cwd.length > 0) sessionCwd = cwd;
|
|
592
|
-
try {
|
|
593
|
-
await registerOkTools();
|
|
594
|
-
} catch (err) {
|
|
595
|
-
const ui = (ctx as { ui?: { notify?: (m: string, level: string) => void } } | undefined)?.ui;
|
|
596
|
-
try {
|
|
597
|
-
ui?.notify?.(
|
|
598
|
-
"Open Knowledge tools unavailable: " + (err instanceof Error ? err.message : String(err)),
|
|
599
|
-
"warning",
|
|
600
|
-
);
|
|
601
|
-
} catch {
|
|
602
|
-
// Non-interactive mode; the failure will resurface on first tool use.
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
pi.on("session_shutdown", async () => {
|
|
608
|
-
const pending = starting;
|
|
609
|
-
starting = null;
|
|
610
|
-
const current = client;
|
|
611
|
-
client = null;
|
|
612
|
-
current?.close();
|
|
613
|
-
// An in-flight ensureClient would otherwise assign a live client after
|
|
614
|
-
// shutdown; await it and tear that one down too.
|
|
615
|
-
if (pending) {
|
|
616
|
-
try {
|
|
617
|
-
(await pending).close();
|
|
618
|
-
} catch {
|
|
619
|
-
// Initialization failed — its catch path already closed the client.
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
`}function Ir(e,t){let n=I(t,e);return n.length>0&&!n.startsWith(`..`)&&!ye(n)}const Lr=e=>{try{let t=ve(`git`,[`rev-parse`,`--show-toplevel`],x({cwd:e,encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]})).trim();return t.length>0?t:null}catch{return null}};function Rr(e,t={}){let n=t.homeDir??Oe(),r=t.gitTopLevel??Lr,i=be(e),a;try{a=Te(i)}catch{a=i}let o=a,s=0;for(;s<30&&!(o===n||o===`/`||o===``);){if(v(o))return{projectRoot:o,defaultContentDir:`.`,ancestorPromoted:o!==a,gitRootPromoted:!1};let e=P(o);if(e===o)break;o=e,s+=1}let c=r(a);return c!==null&&Ir(c,n)?c===a?{projectRoot:i,defaultContentDir:`.`,ancestorPromoted:!1,gitRootPromoted:!1}:{projectRoot:c,defaultContentDir:`.`,ancestorPromoted:!1,gitRootPromoted:!0}:{projectRoot:i,defaultContentDir:`.`,ancestorPromoted:!1,gitRootPromoted:!1}}function zr(e){let t=e&&typeof e==`object`&&`code`in e?e.code:void 0;return t===`MODULE_NOT_FOUND`||t===`ERR_MODULE_NOT_FOUND`}function Q(e,t){if(!process.env.OK_DEBUG_NATIVE)return;let n=t instanceof Error?t.message:String(t);process.stderr.write(`[ok] native-config ${e}: ${n}\n`)}const Br=[`native`,`index.js`];function Vr(e={}){let t=e.moduleUrl??import.meta.url,n=e.requireModule??_e(t);try{return n(F(P(ke(t)),...Br))}catch(e){zr(e)||Q(`bundled loader failed to load`,e)}try{return n(`@inkeep/open-knowledge-native-config`)}catch(e){return zr(e)||Q(`workspace addon failed to load`,e),null}}function Hr(){let e=Vr();return e&&typeof e.resolveSymlinkWritePath==`function`?e:null}function Ur(e){let t=e,n=new Set;for(;;){let r;try{r=Se(t).isSymbolicLink()}catch(n){return n.code===`ENOENT`?{readPath:t,writePath:t}:{readPath:null,writePath:e}}if(!r)return{readPath:t,writePath:t};if(n.has(t))return{readPath:null,writePath:e};n.add(t);let i;try{i=we(t)}catch(t){return Q(`readlinkSync threw during symlink walk`,t),{readPath:null,writePath:e}}t=ye(i)?i:F(P(t),i)}}let Wr;function Gr(){return Wr===void 0&&(Wr=Hr()),Wr}function Kr(e,t=Gr){let n=t();if(n)try{let t=n.resolveSymlinkWritePath(e);return{readPath:t.readPath??null,writePath:t.writePath}}catch(e){Q(`resolveSymlinkWritePath threw`,e)}return Ur(e)}function qr(){let e=Vr();return e&&typeof e.parseTomlToJson==`function`?e:null}function Jr(e){try{let t=e.parseTomlToJson(`probe = 1`);return typeof t==`string`&&t.includes(`probe`)}catch(e){return Q(`addon loaded but probe failed`,e),!1}}function Yr(e){if(!M(e))throw Error(`TOML root is not a table`);return e}function Xr(e){return{backend:`native`,parseToObject(t){return Yr(JSON.parse(e.parseTomlToJson(t)))},upsertEntry(t,n,r){let i=e.upsertMcpServer(t,n,JSON.stringify(r));return{text:i.text,existed:i.existed}},removeEntry(t,n){let r=e.removeMcpServer(t,n);return{text:r.text,existed:r.existed}}}}function Zr(){return{backend:`fallback`,parseToObject(e){return Yr(br(e))}}}function Qr(e=qr){let t=e();return t&&Jr(t)?Xr(t):Zr()}let $r=null;function ei(){return $r===null&&($r=Qr()),$r}const ti={allowTrailingComma:!0,disallowComments:!1};function ni(e,t){return e.error===1&&e.offset===0&&t.charCodeAt(0)===65279}function ri(e){let t=[],n=d(e,t,ti);return t.some(t=>!ni(t,e))||!n||n.type!==`object`?null:n}function ii(e,t){let n=0;for(let r of e.children??[]){let e=r.children?.[0];e!==void 0&&C(e)===t&&(n+=1)}return n}function ai(e,t){T(e,`${JSON.stringify(t,null,2)}\n`)}function oi(e,t){let n=Ar(t);T(e,n.endsWith(`
|
|
625
|
-
`)?n:`${n}\n`)}function si(e,t){let n=(0,xn.stringify)(t);T(e,n.endsWith(`
|
|
626
|
-
`)?n:`${n}\n`)}const ci=10*1024*1024;function li(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((e,n)=>li(e,t[n]));if(M(e)&&M(t)){let n=Object.keys(e);return n.length===Object.keys(t).length?n.every(n=>Object.hasOwn(t,n)&&li(e[n],t[n])):!1}return!1}function ui(e){for(let t of e.split(`
|
|
627
|
-
`)){let e=t.trimStart();if(!(e.length===0||e.length===t.length))return t.charCodeAt(0)===9?{insertSpaces:!1,tabSize:1}:{insertSpaces:!0,tabSize:t.length-e.length}}return{insertSpaces:!0,tabSize:2}}function di(e,t,n){return t===void 0?[e,n]:[e,t,n]}function fi(e,t,n,r){let i={[n]:r};return{[e]:t===void 0?i:{[t]:i}}}function pi(e,t,n){let r=e[t];return n===void 0?r:M(r)?r[n]:void 0}function mi(e,t,n,r,i){if(!L(e))return ai(e,fi(t,i,n,r)),{kind:`written`};let a;try{a=R(e,`utf-8`)}catch(e){return Q(`json config read failed`,e),{kind:`declined`,reason:`unparseable`}}if(a.trim()===``)return ai(e,fi(t,i,n,r)),{kind:`written`};if(Buffer.byteLength(a,`utf-8`)>ci)return{kind:`declined`,reason:`oversize`};let o=ri(a);if(!o)return{kind:`declined`,reason:`unparseable`};if(ii(o,t)>1)return{kind:`declined`,reason:`duplicate-container`};let l=pi(C(o),t,i),u=M(l)?l[n]:void 0,d=u!==void 0;if(d&&li(u,r))return{kind:`overwritten`};let f=a.charCodeAt(0)===65279,p=f?a.slice(1):a,m=p.includes(`\r
|
|
628
|
-
`)?`\r
|
|
629
|
-
`:`
|
|
630
|
-
`,h=s(p,di(t,i,n),r,{formattingOptions:{...ui(p),eol:m}}),g=`${f?``:``}${c(p,h)}`;return g!==a&&T(e,g,{mode:Bn(e)}),{kind:d?`overwritten`:`written`}}function hi(e,t,n,r,i){let a=``;if(L(t))try{a=R(t,`utf-8`)}catch(e){return Q(`toml config read failed`,e),{kind:`declined`,reason:`unparseable`}}let o=a.trim()===``;if(e.backend===`fallback`)return o?(oi(t,{[n]:{[r]:i}}),{kind:`written`}):{kind:`declined`,reason:`no-native-writer`};let s=a.charCodeAt(0)===65279,c=s?a.slice(1):a,l=zn(c),u=o||c.endsWith(`
|
|
631
|
-
`),d;try{d=e.upsertEntry(c,r,i)}catch(e){return Q(`upsertEntry failed`,e),{kind:`declined`,reason:`unparseable`}}let f=d.text;u?f.endsWith(`
|
|
632
|
-
`)||(f=`${f}\n`):f=f.replace(/\n+$/,``),l&&(f=f.replace(/\r\n/g,`
|
|
633
|
-
`).replace(/\n/g,`\r
|
|
634
|
-
`));let p=`${s?``:``}${f}`;return p!==a&&T(t,p,{mode:Bn(t)}),{kind:d.existed?`overwritten`:`written`}}function gi(e,t,n,r){let i=``;if(L(e))try{i=R(e,`utf-8`)}catch(e){return Q(`yaml config read failed`,e),{kind:`declined`,reason:`unparseable`}}if(i.trim()===``)return si(e,{[t]:{[n]:r}}),{kind:`written`};if(Buffer.byteLength(i,`utf-8`)>ci)return{kind:`declined`,reason:`oversize`};let a=i.charCodeAt(0)===65279,o=a?i.slice(1):i,s=(0,xn.parseDocument)(o);if(s.errors.length>0)return{kind:`declined`,reason:`unparseable`};let c=[t,n],l=s.hasIn(c);s.hasIn([t])&&!(0,xn.isCollection)(s.getIn([t],!0))&&s.deleteIn([t]),s.setIn(c,s.createNode(r));let u=s.toString(),d=zn(o);o.endsWith(`
|
|
635
|
-
`)?u.endsWith(`
|
|
636
|
-
`)||(u=`${u}\n`):u=u.replace(/\n+$/,``),d&&(u=u.replace(/\r\n/g,`
|
|
637
|
-
`).replace(/\n/g,`\r
|
|
638
|
-
`));let f=`${a?``:``}${u}`;return f!==i&&T(e,f,{mode:Bn(e)}),{kind:l?`overwritten`:`written`}}const _i=e=>e!==`project`,vi=e=>e!==`user`;async function yi(){let e=await Yn({message:`Where should the MCP server be configured?
|
|
639
|
-
`,required:!1,theme:{icon:{checked:`[x]`,unchecked:`[ ]`}},choices:[{name:`User-level (~/.claude.json, ~/.cursor/mcp.json, …)`,value:`user`,checked:!0},{name:`Project-level (.mcp.json, .cursor/mcp.json, …)`,value:`project`,checked:!0}]});return e.includes(`user`)&&e.includes(`project`)?`both`:e.includes(`user`)?`user`:e.includes(`project`)?`project`:null}async function bi(e){return e.mcp===!1?null:e.scope?e.scope:e.isTTY??process.stdout.isTTY?(e.promptFn??yi)():`both`}async function xi(e){return er({message:`How do you want to handle OpenKnowledge config files (.ok/, .mcp.json, project skills)?`,default:e,choices:[{name:`Share with my team (commit alongside content)`,value:`shared`,description:`OK config gets committed alongside your project content.`},{name:`Local only (keep out of git via .git/info/exclude)`,value:`local-only`,description:"OK config stays on this machine only; teammates do not see it. Safe escape hatch via `ok config-sharing share`."}]})}async function Si(e){if(e.sharing!==void 0)return e.sharing;let t=Dn(e.projectRoot)===`local-only`?`local-only`:`shared`;return e.isTTY??process.stdout.isTTY?(e.promptFn??xi)(t):t}var $=class extends Error{constructor(e){super(e),this.name=`ContentDirError`}};function Ci(e){if(e===void 0||e===!0)return new Set(u);if(e===!1)return new Set;let t=e.split(`,`).map(e=>e.trim()).filter(Boolean);return new Set(u.filter(e=>t.includes(e)))}function wi(e,t,n){let r=be(n,e),i;try{i=Ee(r)}catch(e){let t=e.code;throw t===`ENOENT`?new $(`--content-dir path does not exist: ${r}`):new $(`--content-dir path is not accessible (${t??`unknown error`}): ${r}`)}if(!i.isDirectory())throw new $(`--content-dir must be a directory: ${r}`);let a=I(Ti(t),Ti(r));if(a.startsWith(`..`)||ye(a))throw new $(`--content-dir must be inside the project root (${t}); got ${r}`);return a===``?`.`:a}function Ti(e){try{return Te(e)}catch{return e}}const Ei=`open-knowledge-ui`;function Di(e,t,n){try{return L(e.detectPath?.(t,n)??P(e.configPath(t,n)))}catch{return!1}}function Oi(e,t,n,r,i){let a=e.serverName(t),o;try{o=i??e.configPath(t,r)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:``,serverName:a,error:t instanceof Error?t.message:String(t)}}let s=!n.skipAvailabilityCheck||e.offerOnlyWhenDetected===!0;if(!i&&s&&!Di(e,t,r))return{editorId:e.id,label:e.label,action:`skipped-missing`,configPath:o,serverName:a};if(i!==void 0)try{de(o,t)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t),configScope:`project`}}if(e.format===`file`)return Ai(e,o,a,n,{isProjectScope:i!==void 0});let c;try{c=e.buildEntry(t,n)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t),...i===void 0?{}:{configScope:`project`}}}try{Ce(P(o),{recursive:!0})}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t),...i===void 0?{}:{configScope:`project`}}}let l={action:`written`},u;try{w(`${o}.lock`,()=>{let t=Kr(o).writePath;if(Ce(P(t),{recursive:!0}),e.format===`toml`){let n=hi(ei(),t,e.topLevelKey,a,c);l.action=n.kind,n.kind===`declined`&&(l.declineReason=n.reason);return}if(e.format===`yaml`){let n=gi(t,e.topLevelKey,a,c);l.action=n.kind,n.kind===`declined`&&(l.declineReason=n.reason);return}let n=mi(t,e.topLevelKey,a,c,e.serverMapSubKey);l.action=n.kind,n.kind===`declined`&&(l.declineReason=n.reason)},{onWarn:(e,t)=>process.stderr.write(`[ok] ${e} ${JSON.stringify(t)}\n`)})}catch(e){u=e instanceof Error?e:Error(String(e))}return u?{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:u.message,...i===void 0?{}:{configScope:`project`}}:l.action===`declined`?{editorId:e.id,label:e.label,action:`declined`,configPath:o,serverName:a,declineReason:l.declineReason,...i===void 0?{}:{configScope:`project`}}:{editorId:e.id,label:e.label,action:l.action,configPath:o,serverName:a,...i===void 0?{}:{configScope:`project`}}}const ki={pi:Fr};function Ai(e,t,n,r,i){let a=i.isProjectScope?{configScope:`project`}:{},o=r=>({editorId:e.id,label:e.label,action:`failed`,configPath:t,serverName:n,error:r instanceof Error?r.message:String(r),...a}),s=ki[e.id];if(!s)return o(Error(`No managed-file builder registered for editor "${e.id}" (format: 'file' targets need a MANAGED_FILE_BUILDERS entry).`));let c;try{c=s(r)}catch(e){return o(e)}try{Ce(P(t),{recursive:!0})}catch(e){return o(e)}let l={action:`written`};try{w(`${t}.lock`,()=>{let e=null;try{e=R(t,`utf-8`)}catch{e=null}if(e===c){l.action=`overwritten`;return}T(t,c,e===null?void 0:{mode:Bn(t)}),l.action=e===null?`written`:`overwritten`},{onWarn:(e,t)=>process.stderr.write(`[ok] ${e} ${JSON.stringify(t)}\n`)})}catch(e){return o(e)}return{editorId:e.id,label:e.label,action:l.action,configPath:t,serverName:n,...a}}function ji(e,t){let n=e.projectConfigPath?.(t);if(!(!n||!L(n)))return{editorId:e.id,label:e.label,path:n}}async function Mi(e){let t=ae(e.editors).filter(e=>e.scope===`global`),n={mode:`published`,skipAvailabilityCheck:!0};return t.map(t=>Oi(t,``,n,e.home))}function Ni(e,t,n,r){let i=Fi(e,t,n,r);return i.kind===`present`?i.entry:null}function Pi(e,t,n,r){let i=pi(e,t,r);if(!M(i))return{kind:`no-entry`};let a=i[n];return M(a)?{kind:`present`,entry:a}:{kind:`no-entry`}}function Fi(e,t,n,r){let i;try{i=r??e.configPath(t,n)}catch{return{kind:`absent`}}if(!L(i))return{kind:`absent`};try{if(Ee(i).size>ci)return{kind:`decline`,reason:`oversize`}}catch{return{kind:`decline`,reason:`unparseable`}}let a;try{a=R(i,`utf-8`)}catch{return{kind:`decline`,reason:`unparseable`}}if(a.trim()===``)return{kind:`absent`};if(e.format===`file`)return{kind:`present`,entry:Pr(a)};let o=e.serverName(t);if(e.format===`toml`){let t;try{t=ei().parseToObject(a)}catch{return{kind:`decline`,reason:`unparseable`}}return Pi(t,e.topLevelKey,o,e.serverMapSubKey)}if(e.format===`yaml`){let t=(0,xn.parseDocument)(a.charCodeAt(0)===65279?a.slice(1):a);return t.errors.length>0?{kind:`decline`,reason:`unparseable`}:Pi(t.toJS()??{},e.topLevelKey,o,e.serverMapSubKey)}let s=ri(a);return s?ii(s,e.topLevelKey)>1?{kind:`decline`,reason:`duplicate-container`}:Pi(C(s),e.topLevelKey,o,e.serverMapSubKey):{kind:`decline`,reason:`unparseable`}}async function Ii(e={}){let t=be(e.cwd??process.cwd()),n=Rr(t,{homeDir:e.home}),r=n.projectRoot,i=!L(F(r,`.ok`)),a=n.gitRootPromoted?I(r,t):void 0,o=e.contentDir===void 0?n.defaultContentDir:wi(e.contentDir,r,t);n.ancestorPromoted?console.log(`[ok] Opened existing project at ${r}`):n.gitRootPromoted&&i&&o===`.`&&process.stderr.write(`${A(`[ok] Content scope promoted to the git repo root: ${r}`)}\n Ran in ${a}/, but .ok/ lives at the git root (one .ok/ per git repo),\n so the whole repo is now the content scope. To narrow it, re-run with\n \`ok init --content-dir .\`, or set content.dir: ${a} in .ok/config.yml.\n`);let s={mode:e.devMcp?`dev`:`published`},c=await ee(r),d;try{d=_(r,{contentDir:o})}catch(t){let i=D.claude.configPath(r,e.home);return{projectRoot:r,contentCreated:[],contentUpdated:[],contentSkipped:[],editors:[],projectSkills:[],legacyProjectConfigs:[],didGitInit:c.didInit,rootGitignoreCreated:!1,gitRootPromoted:n.gitRootPromoted,promotedFromDir:a,contentDirRequested:e.contentDir,contentScaffoldFailed:!0,mcpAction:`failed`,mcpPath:i,mcpError:`Content scaffolding failed: ${t instanceof Error?t.message:String(t)}`,sharing:{kind:`no-exclude`,reason:`no-git`,localOnlyRequested:!1}}}let f=d.created.includes(he),m=!1;if(c.didInit)try{m=S(r)===`created`}catch(e){console.warn(`[ok] Skipping .gitignore seed at ${r}: ${e instanceof Error?e.message:String(e)}`)}try{g(r)}catch(e){console.warn(`[ok] Skipping project-skill .gitignore entry at ${r}: ${e instanceof Error?e.message:String(e)}`)}let v=await h(r);v.kind===`untracked`&&console.warn(`[ok] Untracked the OpenKnowledge project skill (${v.dirs.join(`, `)}) — it is now local-only. Teammates will see this as a deletion on their next pull.`);let y=await bi({scope:e.scope,mcp:e.mcp,isTTY:e.isTTY,promptFn:e.promptFn}),b=e.editors??Hi(r,e.home),x=e.editors??ue.filter(e=>D[e].projectConfigPath!==void 0||D[e].projectSkillPath!==void 0),C=ae(b),ne=ae(x),w=e.mcp===!1||y===null,T=Array.from(new Map([...C,...w?[]:ne].map(e=>[e.id,e])).values()),re=C.filter(t=>Di(t,r,e.home)),E=[],oe=[],ce=new Set;for(let t of T){if(w){let n=``;try{n=t.configPath(r,e.home)}catch{}E.push({editorId:t.id,label:t.label,action:`skipped-flag`,configPath:n,serverName:t.serverName(r)});continue}if(_i(y)&&C.includes(t)&&t.scope===`global`&&E.push(Oi(t,r,s,e.home)),vi(y)&&ne.includes(t)&&t.projectConfigPath){let n=t.projectConfigPath(r),i=Oi(t,r,s,e.home,n);E.push(i),(i.action===`written`||i.action===`overwritten`)&&ce.add(n)}}let le=new Set;for(let t of ne){let n=t.projectSkillPath?.(r);!n||le.has(n)||(le.add(n),oe.push(se(t,r,{home:e.home})))}let de=!w&&y!==null&&vi(y)?ne.filter(e=>!e.projectConfigPath&&!e.projectSkillPath).map(e=>e.label):void 0,fe=w?[]:re.map(e=>ji(e,r)).filter(e=>e!==void 0).filter(e=>!ce.has(e.path)),O=e.installUserSkill??p,pe=e.home??Oe(),k=Ci(e.skills),me=!1,j=!1,M=!1,ge=!1;for(let t of u){let n=k.has(t);if(await te(pe,l[t],n).catch(()=>{}),n){me=!0;let n=await O({home:e.home,bundleId:t,force:!0});n===`installed`?j=!0:n===`failed`?M=!0:ge=!0}else try{ie(pe,t)}catch{}}let _e=M?`failed`:j?`installed`:me&&ge?`skip-current`:`declined`,ve=w?`skipped-flag`:`skipped-missing`,N=E.find(e=>e.editorId===`claude`)??E[0]??{action:ve,configPath:D.claude.configPath(r,e.home)},P=await Li({projectRoot:r,desiredMode:await Si({sharing:e.sharing,projectRoot:r,isTTY:e.isTTY,promptFn:e.sharingPromptFn}),explicitFlag:e.sharing});return{projectRoot:r,contentCreated:d.created,contentUpdated:d.updated,contentSkipped:d.skipped,editors:E,projectSkills:oe,legacyProjectConfigs:fe,skillInstall:_e,didGitInit:c.didInit,rootGitignoreCreated:m,gitRootPromoted:n.gitRootPromoted,promotedFromDir:a,contentDir:f?o:void 0,contentDirRequested:e.contentDir,contentScaffoldFailed:!1,mcpAction:N.action,mcpPath:N.configPath,mcpError:`error`in N?N.error:void 0,projectScopeUnsupportedLabels:de,sharing:P}}async function Li(e){let{projectRoot:t,desiredMode:n,explicitFlag:r}=e,i=Dn(t);if(i===`no-git`)return{kind:`no-exclude`,reason:`no-git`,localOnlyRequested:r===`local-only`};let a=wn(t);if(n===`local-only`){let e=Tn(t,a);if(e.kind===`refused-tracked`){let t=e;return{kind:`refused-tracked`,tracked:t.tracked,remediation:t.remediation}}return e.kind===`no-exclude`?{kind:`no-exclude`,reason:e.reason,localOnlyRequested:r===`local-only`}:Ri(t,e,`add`)}if(i===`shared`)return{kind:`applied`,mode:`shared`,action:`noop`,appended:[],alreadyPresent:[],removed:[]};let o=En(t,a);return o.kind===`no-exclude`?{kind:`no-exclude`,reason:o.reason,localOnlyRequested:!1}:Ri(t,o,`remove`)}function Ri(e,t,n){let r=Dn(e);return n===`add`?{kind:`applied`,mode:r,action:t.appended.length>0?`added`:`noop`,appended:t.appended,alreadyPresent:t.alreadyPresent,removed:[]}:{kind:`applied`,mode:r,action:`removed`,appended:[],alreadyPresent:[],removed:t.removed}}function zi(e){switch(e){case`oversize`:return`config too large to edit safely`;case`duplicate-container`:return`duplicate server block`;case`no-native-writer`:return`no format-preserving writer available`;default:return`config not readable`}}function Bi(e,t){let n=[],r=e.editors.some(e=>e.action===`written`||e.action===`overwritten`),i=e.editors.some(e=>e.action===`failed`)||e.projectSkills.some(e=>e.action===`failed`),a=e.editors.length>0&&e.editors.every(e=>e.action===`skipped-flag`),o=e.editors.length>0&&e.editors.every(e=>e.action===`skipped-missing`);e.didGitInit&&n.push(`Initialized git repo at ${t}/.git/ (default branch: main)`),e.rootGitignoreCreated&&n.push(`Seeded .gitignore at ${t}/.gitignore (.DS_Store)`);let s=F(t,`.ok`);if(e.contentCreated.length>0||e.contentUpdated.length>0?(n.push(j(`Content scaffolded at ${s}/`)),e.contentCreated.length>0&&n.push(` Created: ${e.contentCreated.join(`, `)}`),e.contentUpdated.length>0&&n.push(` Updated: ${e.contentUpdated.join(`, `)}`)):n.push(j(`Content already present at ${s}/`)),e.contentSkipped.length>0&&n.push(` Skipped (already exist): ${e.contentSkipped.join(`, `)}`),n.push(``),e.mcpError&&e.editors.length===0)n.push(`Warning: ${e.mcpError}`);else if(e.editors.length===0)if(n.push(j(`MCP server configuration:`)),e.mcpAction===`skipped-flag`)n.push(` MCP config not written — use without --no-mcp to configure editors`);else if(e.projectScopeUnsupportedLabels&&e.projectScopeUnsupportedLabels.length>0){let t=e.projectScopeUnsupportedLabels.join(`, `),r=e.projectScopeUnsupportedLabels.length===1?`does`:`do`;n.push(` ${t} ${r} not support project-level config; skipped`)}else n.push(` No supported editor config directories detected; skipped MCP registration`);else if(a)n.push(`MCP config not written — use without --no-mcp to configure editors`);else if(o)n.push(j(`MCP server configuration:`)),n.push(` No supported editor config directories detected; skipped MCP registration`);else{n.push(j(`MCP server configuration:`));for(let r of e.editors){let e=r.configPath.startsWith(t)?I(t,r.configPath):r.configPath.replace(/^\/Users\/[^/]+/,`~`),i=r.serverName===`open-knowledge`?``:` (${r.serverName})`,a=r.configScope===`project`?` (project)`:``,o=`${r.label}${a}`,s=` `.repeat(Math.max(1,20-o.length)),c=r.editorId===`claude-desktop`&&(r.action===`written`||r.action===`overwritten`)?` — quit and relaunch Claude Desktop to activate`:``;switch(r.action){case`written`:n.push(` ${o}${s}${e} ${k(`registered`)}${i}${c}`);break;case`overwritten`:n.push(` ${o}${s}${e} ${k(`updated`)}${i}${c}`);break;case`skipped-missing`:n.push(` ${o}${s}${e} config root missing; skipped`);break;case`failed`:n.push(` ${o}${s}${e} ${me(`FAILED`)}: ${r.error}`);break;case`declined`:n.push(` ${o}${s}${e} left unchanged (${zi(r.declineReason)})`);break;case`skipped-flag`:break;default:r.action}}if(e.projectScopeUnsupportedLabels&&e.projectScopeUnsupportedLabels.length>0){let t=e.projectScopeUnsupportedLabels.join(`, `),r=e.projectScopeUnsupportedLabels.length===1?`does`:`do`;n.push(` ${t} ${r} not support project-level config; skipped`)}}if(e.projectSkills.length>0){n.push(``),n.push(j(`Project-local skills:`));for(let r of e.projectSkills){let e=`${r.label} (project)`,i=` `.repeat(Math.max(1,20-e.length)),a=r.path?I(t,r.path):``;switch(r.action){case`written`:n.push(` ${e}${i}${a} ${k(`installed`)}`);break;case`overwritten`:n.push(` ${e}${i}${a} ${k(`updated`)}`);break;case`skipped-unsupported`:n.push(` ${e}${i}no known project skill surface; skipped`);break;case`skipped-prerequisite`:n.push(` ${e}${i}OpenKnowledge MCP is not configured; skipped`);break;case`failed`:n.push(` ${e}${i}${a} ${me(`FAILED`)}: ${r.error}`);break}}}if(i&&(n.push(``),n.push(`For failed editors, add the MCP server entry or project skill manually. See:`),n.push(` https://github.com/inkeep/open-knowledge#mcp-setup`)),e.legacyProjectConfigs.length>0){n.push(``),n.push(`Project MCP configs found:`);for(let r of e.legacyProjectConfigs)n.push(` ${r.label} ${I(t,r.path)}`);n.push(` These project-local files may override the global config. Remove them if you want fully user-scoped MCP setup in this project.`)}if(e.skillInstall)switch(n.push(``),n.push(j(`User-global skill:`)),e.skillInstall){case`installed`:n.push(` open-knowledge ${k(`installed to detected agent hosts`)} via \`npx skills\``);break;case`skip-current`:n.push(` open-knowledge ${k(`already installed at current version`)}`);break;case`declined`:n.push(` open-knowledge ${pe(`skipped (opted out via --no-skills)`)}`);break;case`failed`:n.push(` ${A(`open-knowledge install failed — MCP still configured; run manually:`)}`),n.push(` ${A(` npx skills@~1.5.0 add <bundled-path> --agent '*' -g -y --copy`)}`);break}if(e.contentDirRequested!==void 0&&e.contentDir===void 0&&!e.contentScaffoldFailed?(n.push(``),n.push(A(`⚠ --content-dir ${e.contentDirRequested} ignored — .ok/config.yml already exists`)),n.push(` Edit .ok/config.yml → content.dir directly to change the content scope.`)):e.contentDir!==void 0&&e.contentDir!==`.`?(n.push(``),n.push(`Content scope set to ${e.contentDir}/ (content.dir in .ok/config.yml).`)):e.gitRootPromoted&&e.contentDir===`.`&&e.contentDirRequested===void 0&&(n.push(``),n.push(A(`⚠ Content scope promoted to the git repo root`)),n.push(` .ok/ was initialized at ${t} because it contains a .git folder (one .ok/ per git repo),`),n.push(` not the sub-folder you ran \`ok init\` in${e.promotedFromDir?` (${e.promotedFromDir})`:``}. The whole repo is now the content scope.`),e.promotedFromDir&&(n.push(" To scope to just that sub-folder, re-run `ok init --content-dir .` from there, or set"),n.push(` content.dir: ${e.promotedFromDir} in .ok/config.yml.`))),e.preview?(n.push(``),n.push(ge(e.preview,t))):e.previewWarning&&(n.push(``),n.push(`Content preview unavailable: ${e.previewWarning}`)),n.push(``),n.push(...Gi(e.sharing,t)),r){let t=new Set,r=e.editors.filter(e=>e.action===`written`||e.action===`overwritten`).filter(e=>!t.has(e.editorId)&&t.add(e.editorId)).map(e=>e.label);n.push(``),n.push(`${k(`✓`)} ${j(`Next steps:`)}`),n.push(` 1. Open your editor (${O(r.join(` / `))})`),n.push(` 2. Approve the MCP server when prompted`),n.push(` 3. (Optional) scaffold the starter knowledge-base structure:`),n.push(` - ${O(`ok seed`)} — empty repo, Karpathy 3-layer`),n.push(` - ${O(`mcp__open-knowledge__discover`)} — existing repo, extract conventions`),n.push(` 4. Use the MCP workflow tools as you build the wiki:`),n.push(` - ${O(`mcp__open-knowledge__ingest`)} — capture an external source`),n.push(` - ${O(`mcp__open-knowledge__research`)} — gather sources and write findings`),n.push(` - ${O(`mcp__open-knowledge__consolidate`)} — promote research to canonical articles`)}return n.join(`
|
|
640
|
-
`)}function Vi(e,t){return{projectRoot:e.projectRoot,gitRootPromoted:e.gitRootPromoted,promotedFromDir:e.promotedFromDir??null,contentDir:t.contentDir,contentDirRequested:e.contentDirRequested??null,contentDirApplied:e.contentDir!==void 0,contentFileCount:t.contentFileCount,previewError:e.previewWarning??null,didGitInit:e.didGitInit,mcpAction:e.mcpAction,editors:e.editors.map(e=>({editorId:e.editorId,label:e.label,action:e.action,configPath:e.configPath,scope:e.configScope===`project`?`project`:`user`}))}}function Hi(e,t){let n=[];for(let r of ue)Di(D[r],e,t)&&n.push(r);return n}function Ui(){let e={log:console.log,info:console.info,debug:console.debug},t=(...e)=>{process.stderr.write(`${e.map(e=>typeof e==`string`?e:je(e)).join(` `)}\n`)};return console.log=t,console.info=t,console.debug=t,()=>{console.log=e.log,console.info=e.info,console.debug=e.debug}}function Wi(){return new fe(`init`).description(`Scaffold .ok/ in the current directory and register the MCP server for your editor(s)`).option(`--mcp`,`Register the MCP server for selected editors (default: true)`,!0).option(`--no-mcp`,`Scaffold the .ok/ directory but do not touch MCP config`).option(`--dev-mcp`,`Register a local dev MCP entry using node + packages/cli/dist/cli.mjs with debug logging`).option(`--content-dir <dir>`,`Limit content to <dir> instead of the whole project. <dir> is interpreted relative to your current directory (e.g. "." = the folder you run the command in), then saved to .ok/config.yml as content.dir.`).option(`--json`,`Emit a structured JSON summary to stdout (diagnostics stay on stderr)`).option(`--skills <ids>`,`Install only the named user-global skill bundles (comma list: discovery,write-skill)`).option(`--no-skills`,`Do not install any user-global skill bundles`).addOption(new re(`--scope <scope>`,`Write MCP config at user level, project level, or both`).choices([`user`,`project`,`both`])).addOption(new re(`--shared`,`Commit OK config alongside content (the default for fresh repos)`).conflicts(`localOnly`)).addOption(new re(`--local-only`,`Keep OK config out of git via .git/info/exclude (per-clone, not committed)`).conflicts(`shared`)).action(async e=>{let t=process.cwd(),n=e.shared?`shared`:e.localOnly?`local-only`:void 0,r=e.json?Ui():null;try{let r;try{r=await Ii({cwd:t,mcp:e.mcp,devMcp:e.devMcp,scope:e.scope,sharing:n,contentDir:e.contentDir,skills:e.skills})}catch(e){if(e instanceof $){process.stderr.write(`${e.message}\n`),process.exitCode=64;return}if(e instanceof y||e instanceof m){process.stderr.write(`${e.message}\n`),process.exitCode=78;return}if(e instanceof b){process.stderr.write(`open-knowledge could not initialize a git repo for this project. Re-run, or run 'git init' yourself in the project folder.
|
|
641
|
-
`),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}let i=r.contentDir??`.`,a=null,{loadConfig:o}=await import(`./loader-CbsXNIN0.mjs`),{resolveContentDir:s}=await import(`./src-B4xOeCWv.mjs`),c;try{c=o(r.projectRoot).config,i=c.content.dir}catch(e){r.previewWarning=e instanceof Error?e.message:String(e)}if(c)try{let{previewContent:e}=await import(`./preview-DkPNmdc1.mjs`),t=s(c,r.projectRoot);r.preview=e({projectDir:r.projectRoot,contentDir:t}),a=r.preview.totalCount}catch(e){r.previewWarning=e instanceof Error?e.message:String(e)}e.json?process.stdout.write(`${JSON.stringify(Vi(r,{contentDir:i,contentFileCount:a}),null,2)}\n`):process.stdout.write(`${Bi(r,r.projectRoot)}\n`),(r.editors.some(e=>e.action===`failed`)||r.mcpAction===`failed`)&&(process.exitCode=1)}finally{r?.()}})}function Gi(e,t){let n=[];switch(e.kind){case`applied`:return n.push(j(`Sharing mode:`)),e.mode===`local-only`?e.action===`added`?n.push(` ${k(`local-only`)} — appended ${e.appended.length} path(s) to ${j(`${t}/.git/info/exclude`)} (per-clone, not committed).`):e.action===`noop`&&e.alreadyPresent.length>0?n.push(` ${k(`local-only`)} — already excluded; nothing to do.`):n.push(` ${k(`local-only`)}`):e.action===`removed`?n.push(` ${k(`shared`)} — removed OK paths from ${j(`${t}/.git/info/exclude`)}; commit the files to share with teammates.`):n.push(` ${k(`shared`)} — OK config will be committed alongside content.`),n;case`refused-tracked`:n.push(A(`Sharing mode: switch to local-only deferred`));for(let t of e.remediation.split(`
|
|
642
|
-
`))n.push(t.length>0?` ${t}`:``);return n.push(` Re-run ${O(`ok config-sharing unshare`)} after resolving to complete the switch.`),n;case`no-exclude`:if(e.localOnlyRequested)n.push(A(`Sharing mode: --local-only requested but no git repo found — option ignored`)),n.push(` Run ${O(`git init`)} (or open this folder via OK Desktop, which can scaffold a repo) and then ${O(`ok config-sharing unshare`)}.`);else if(e.reason===`no-git`)return[];else n.push(A(`Sharing mode unavailable: ${e.reason}.`));return n}}export{On as A,ht as B,er as C,Vn as D,zn as E,En as F,U as H,An as I,bn as L,jn as M,Dn as N,Tn as O,kn as P,cn as R,Nr as S,Bn as T,He as U,mt as V,di as _,Vi as a,ei as b,Bi as c,Ni as d,Ci as f,Ii as g,Si as h,Li as i,wn as j,Mn as k,Gi as l,wi as m,Ei as n,Fi as o,bi as p,ki as r,Hi as s,$ as t,Wi as u,Oi as v,Yn as w,Rr as x,Mi as y,vt as z};
|
|
643
|
-
//# sourceMappingURL=init-2yIvpr4B.mjs.map
|