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