@inkeep/open-knowledge 0.10.0-beta.8 → 0.10.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/skills/discovery/SKILL.md +1 -1
- package/dist/assets/skills/project/SKILL.md +3 -1
- package/dist/cli.mjs +5 -5
- package/dist/config-schema.json +0 -21
- package/dist/config.project.schema.json +0 -21
- package/dist/constants-Chrt6UKP.mjs +2 -0
- package/dist/{dist-CuFjIU6M.mjs → dist-CcfJnewj.mjs} +1 -1
- package/dist/{dist-peyy_Xqa.mjs → dist-DLLsPJ9U.mjs} +5 -5
- package/dist/{gh-detect-BUPEzJp9.mjs → gh-detect-BGpLt_9t.mjs} +2 -2
- package/dist/index.mjs +1 -1
- package/dist/init-BpglUwje.mjs +1 -0
- package/dist/{init-DFIeFfDO.mjs → init-DNFUwGbt.mjs} +4 -4
- package/dist/loader-BJsgp07g.mjs +1 -0
- package/dist/{loader-BRV6jbT-.mjs → loader-B_0kC5qP.mjs} +2 -2
- package/dist/preview-B2cD9lkg.mjs +1 -0
- package/dist/{preview-Cj1NaXIB.mjs → preview-BP4tJ2Iu.mjs} +2 -2
- package/dist/public/assets/{ActivityModeContent-D2i8Zn71.js → ActivityModeContent-BwQQ3J_E.js} +1 -1
- package/dist/public/assets/{DocumentContext-B8GbZdoY.js → DocumentContext-DSlG6YaD.js} +17 -17
- package/dist/public/assets/{GraphPanel-DnTtjLxL.js → GraphPanel-BRUm_fhE.js} +1 -1
- package/dist/public/assets/SettingsDialogBody-CKwZY_LV.js +7 -0
- package/dist/public/assets/SourceEditor-Dl9IMPTy.js +2 -0
- package/dist/public/assets/{config-validation-events-D_EFbncj.js → config-validation-events-DrkYIj0b.js} +5 -5
- package/dist/public/assets/{index-srOfVrqh.js → index-BsXXFIC5.js} +8 -8
- package/dist/public/assets/{keyboard-shortcuts-DmIuP6Z1.js → keyboard-shortcuts-7YXzJfGc.js} +1 -1
- package/dist/public/assets/{prop-types-9e5DMg2o.js → prop-types-DMEbXAvm.js} +2 -2
- package/dist/public/assets/{target-navigation-intent-BAEzEWPW.js → target-navigation-intent-CLpNsaEw.js} +1 -1
- package/dist/public/assets/{typing-burst-detector-C8iPoowF.js → typing-burst-detector-C8K6iZNM.js} +2 -2
- package/dist/public/index.html +7 -7
- package/dist/{repair-launch-json-rjX_x5sN.mjs → repair-launch-json-C3tWHctI.mjs} +2 -2
- package/dist/{repair-mcp-configs-CeShfDta.mjs → repair-mcp-configs-DP6bcoNL.mjs} +2 -2
- package/dist/repair-skills-B3uiMrne.mjs +1 -0
- package/dist/{repair-skills-CDKiT_Bf.mjs → repair-skills-aYu-R20l.mjs} +2 -2
- package/dist/schemas/v0/config.project.schema.json +0 -21
- package/dist/{server-lock-BpjJj3OD-yLJv0roS.mjs → server-lock-BpjJj3OD-DEuL_F6k.mjs} +3 -3
- package/dist/server-lock-CyhBidkz-BpB26sqh.mjs +1 -0
- package/dist/{src-D084_rtj.mjs → src-Ad1isO-9.mjs} +2 -2
- package/dist/{start-CUB_B0aW.mjs → start-BF1QWSQY.mjs} +2 -2
- package/dist/start-O4HqnFeH.mjs +1 -0
- package/dist/{write-project-skill-BNGFBLtA.mjs → write-project-skill-BrFmZCMd.mjs} +2 -2
- package/package.json +1 -1
- package/dist/constants-BXvmkg7Y.mjs +0 -2
- package/dist/init-CKGWEe26.mjs +0 -1
- package/dist/loader-CTYLzMxp.mjs +0 -1
- package/dist/preview-BItkz8RQ.mjs +0 -1
- package/dist/public/assets/SettingsDialogBody-pdbayjAd.js +0 -7
- package/dist/public/assets/SourceEditor-7WDSLWRs.js +0 -2
- package/dist/repair-skills-DnsSeH8x.mjs +0 -1
- package/dist/server-lock-CyhBidkz-B4QDNiiR.mjs +0 -1
- package/dist/start-JN3FGdMq.mjs +0 -1
|
@@ -151,7 +151,7 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
151
151
|
|
|
152
152
|
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=jt,s=!gt.jitless,c=s&&Mt.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?ii([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function si(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!qt(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Xt(e,r,_t())))}),t)}const ci=D(`$ZodUnion`,(e,t)=>{vr.init(e,t),Tt(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),Tt(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),Tt(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Tt(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>St(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>si(t,i,e,a)):si(s,i,e,a)}}),li=D(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,ci.init(e,t);let n=e._zod.parse;Tt(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=bt(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!jt(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),i)}}),ui=D(`$ZodIntersection`,(e,t)=>{vr.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>fi(e,t,n)):fi(e,i,a)}});function di(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Nt(e)&&Nt(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=di(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=di(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function fi(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),qt(e))return e;let o=di(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const pi=D(`$ZodRecord`,(e,t)=>{vr.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Nt(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){s.add(typeof e==`number`?e.toString():e);let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...Jt(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...Jt(e,o.issues)),n.value[e]=o.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Jn.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Xt(e,r,_t())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Jt(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Jt(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),mi=D(`$ZodEnum`,(e,t)=>{vr.init(e,t);let n=vt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Ft.has(typeof e)).map(e=>typeof e==`string`?It(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),hi=D(`$ZodLiteral`,(e,t)=>{if(vr.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?It(e):e?It(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),gi=D(`$ZodTransform`,(e,t)=>{vr.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new ht(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new mt;return n.value=i,n}});function _i(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const vi=D(`$ZodOptional`,(e,t)=>{vr.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,Tt(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Tt(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${St(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>_i(t,e.value)):_i(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),yi=D(`$ZodExactOptional`,(e,t)=>{vi.init(e,t),Tt(e._zod,`values`,()=>t.innerType._zod.values),Tt(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),bi=D(`$ZodNullable`,(e,t)=>{vr.init(e,t),Tt(e._zod,`optin`,()=>t.innerType._zod.optin),Tt(e._zod,`optout`,()=>t.innerType._zod.optout),Tt(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${St(e.source)}|null)$`):void 0}),Tt(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),xi=D(`$ZodDefault`,(e,t)=>{vr.init(e,t),e._zod.optin=`optional`,Tt(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Si(e,t)):Si(r,t)}});function Si(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Ci=D(`$ZodPrefault`,(e,t)=>{vr.init(e,t),e._zod.optin=`optional`,Tt(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),wi=D(`$ZodNonOptional`,(e,t)=>{vr.init(e,t),Tt(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Ti(t,e)):Ti(i,e)}});function Ti(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Ei=D(`$ZodCatch`,(e,t)=>{vr.init(e,t),Tt(e._zod,`optin`,()=>t.innerType._zod.optin),Tt(e._zod,`optout`,()=>t.innerType._zod.optout),Tt(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Xt(e,n,_t()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Xt(e,n,_t()))},input:e.value}),e.issues=[]),e)}}),Di=D(`$ZodPipe`,(e,t)=>{vr.init(e,t),Tt(e._zod,`values`,()=>t.in._zod.values),Tt(e._zod,`optin`,()=>t.in._zod.optin),Tt(e._zod,`optout`,()=>t.out._zod.optout),Tt(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Oi(e,t.in,n)):Oi(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Oi(e,t.out,n)):Oi(r,t.out,n)}});function Oi(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const ki=D(`$ZodReadonly`,(e,t)=>{vr.init(e,t),Tt(e._zod,`propValues`,()=>t.innerType._zod.propValues),Tt(e._zod,`values`,()=>t.innerType._zod.values),Tt(e._zod,`optin`,()=>t.innerType?._zod?.optin),Tt(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ai):Ai(r)}});function Ai(e){return e.value=Object.freeze(e.value),e}const ji=D(`$ZodCustom`,(e,t)=>{$n.init(e,t),vr.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Mi(t,n,r,e));Mi(i,n,r,e)}});function Mi(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Qt(e))}}var Ni,Pi=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Fi(){return new Pi}(Ni=globalThis).__zod_globalRegistry??(Ni.__zod_globalRegistry=Fi());const Ii=globalThis.__zod_globalRegistry;function Li(e,t){return new e({type:`string`,...O(t)})}function Ri(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...O(t)})}function zi(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...O(t)})}function Bi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...O(t)})}function Vi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...O(t)})}function Hi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...O(t)})}function Ui(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...O(t)})}function Wi(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...O(t)})}function Gi(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...O(t)})}function Ki(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...O(t)})}function qi(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...O(t)})}function Ji(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...O(t)})}function Yi(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...O(t)})}function Xi(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...O(t)})}function Zi(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...O(t)})}function Qi(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...O(t)})}function $i(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...O(t)})}function ea(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...O(t)})}function ta(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...O(t)})}function na(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...O(t)})}function ra(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...O(t)})}function ia(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...O(t)})}function aa(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...O(t)})}function oa(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...O(t)})}function sa(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...O(t)})}function ca(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...O(t)})}function la(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...O(t)})}function ua(e,t){return new e({type:`number`,checks:[],...O(t)})}function da(e,t){return new e({type:`number`,coerce:!0,checks:[],...O(t)})}function fa(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...O(t)})}function pa(e,t){return new e({type:`boolean`,...O(t)})}function ma(e,t){return new e({type:`null`,...O(t)})}function ha(e){return new e({type:`any`})}function ga(e){return new e({type:`unknown`})}function _a(e,t){return new e({type:`never`,...O(t)})}function va(e,t){return new tr({check:`less_than`,...O(t),value:e,inclusive:!1})}function ya(e,t){return new tr({check:`less_than`,...O(t),value:e,inclusive:!0})}function ba(e,t){return new nr({check:`greater_than`,...O(t),value:e,inclusive:!1})}function xa(e,t){return new nr({check:`greater_than`,...O(t),value:e,inclusive:!0})}function Sa(e,t){return new rr({check:`multiple_of`,...O(t),value:e})}function Ca(e,t){return new ar({check:`max_length`,...O(t),maximum:e})}function wa(e,t){return new or({check:`min_length`,...O(t),minimum:e})}function Ta(e,t){return new sr({check:`length_equals`,...O(t),length:e})}function Ea(e,t){return new lr({check:`string_format`,format:`regex`,...O(t),pattern:e})}function Da(e){return new ur({check:`string_format`,format:`lowercase`,...O(e)})}function Oa(e){return new dr({check:`string_format`,format:`uppercase`,...O(e)})}function ka(e,t){return new fr({check:`string_format`,format:`includes`,...O(t),includes:e})}function Aa(e,t){return new pr({check:`string_format`,format:`starts_with`,...O(t),prefix:e})}function ja(e,t){return new mr({check:`string_format`,format:`ends_with`,...O(t),suffix:e})}function Ma(e){return new hr({check:`overwrite`,tx:e})}function Na(e){return Ma(t=>t.normalize(e))}function Pa(){return Ma(e=>e.trim())}function Fa(){return Ma(e=>e.toLowerCase())}function Ia(){return Ma(e=>e.toUpperCase())}function La(){return Ma(e=>kt(e))}function Ra(e,t,n){return new e({type:`array`,element:t,...O(n)})}function za(e,t,n){let r=O(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}function Ba(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...O(n)})}function Va(e){let t=Ha(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(Qt(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(Qt(r))}},e(n.value,n)));return t}function Ha(e,t){let n=new $n({check:`custom`,...O(t)});return n._zod.check=e,n}function Ua(e){let t=new $n({check:`describe`});return t._zod.onattach=[t=>{let n=Ii.get(t)??{};Ii.add(t,{...n,description:e})}],t._zod.check=()=>{},t}function Wa(e){let t=new $n({check:`meta`});return t._zod.onattach=[t=>{let n=Ii.get(t)??{};Ii.add(t,{...n,...e})}],t._zod.check=()=>{},t}function Ga(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??Ii,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function Ka(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,Ka(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&Ya(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function qa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
153
153
|
|
|
154
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Ja(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:Za(t,`input`,e.processors),output:Za(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Ya(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Ya(r.element,n);if(r.type===`set`)return Ya(r.valueType,n);if(r.type===`lazy`)return Ya(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return Ya(r.innerType,n);if(r.type===`intersection`)return Ya(r.left,n)||Ya(r.right,n);if(r.type===`record`||r.type===`map`)return Ya(r.keyType,n)||Ya(r.valueType,n);if(r.type===`pipe`)return Ya(r.in,n)||Ya(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Ya(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Ya(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Ya(e,n))return!0;return!!(r.rest&&Ya(r.rest,n))}return!1}const Xa=(e,t={})=>n=>{let r=Ga({...n,processors:t});return Ka(e,r),qa(r,e),Ja(r,e)},Za=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Ga({...i??{},target:a,io:t,processors:n});return Ka(e,o),qa(o,e),Ja(o,e)},Qa={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},$a=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Qa[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},eo=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},to=(e,t,n,r)=>{n.type=`boolean`},no=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`BigInt cannot be represented in JSON Schema`)},ro=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Symbols cannot be represented in JSON Schema`)},io=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},ao=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Undefined cannot be represented in JSON Schema`)},oo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Void cannot be represented in JSON Schema`)},so=(e,t,n,r)=>{n.not={}},co=(e,t,n,r)=>{},lo=(e,t,n,r)=>{},uo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Date cannot be represented in JSON Schema`)},fo=(e,t,n,r)=>{let i=e._zod.def,a=vt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},po=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},mo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`NaN cannot be represented in JSON Schema`)},ho=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},go=(e,t,n,r)=>{let i=n,a={type:`string`,format:`binary`,contentEncoding:`binary`},{minimum:o,maximum:s,mime:c}=e._zod.bag;o!==void 0&&(a.minLength=o),s!==void 0&&(a.maxLength=s),c?c.length===1?(a.contentMediaType=c[0],Object.assign(i,a)):(Object.assign(i,a),i.anyOf=c.map(e=>({contentMediaType:e}))):Object.assign(i,a)},_o=(e,t,n,r)=>{n.type=`boolean`},vo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},yo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Function types cannot be represented in JSON Schema`)},bo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},xo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Map cannot be represented in JSON Schema`)},So=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Set cannot be represented in JSON Schema`)},Co=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Ka(a.element,t,{...r,path:[...r.path,`items`]})},wo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=Ka(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Ka(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},To=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Ka(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Eo=(e,t,n,r)=>{let i=e._zod.def,a=Ka(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Ka(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Do=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>Ka(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?Ka(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null;t.target===`draft-2020-12`?(i.prefixItems=c,l&&(i.items=l)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),i.minItems=c.length,l||(i.maxItems=c.length)):(i.items=c,l&&(i.additionalItems=l));let{minimum:u,maximum:d}=e._zod.bag;typeof u==`number`&&(i.minItems=u),typeof d==`number`&&(i.maxItems=d)},Oo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Ka(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=Ka(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=Ka(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},ko=(e,t,n,r)=>{let i=e._zod.def,a=Ka(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Ao=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},jo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Mo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},No=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Po=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;Ka(a,t,r);let o=t.seen.get(e);o.ref=a},Fo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Io=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Lo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ro={string:$a,number:eo,boolean:to,bigint:no,symbol:ro,null:io,undefined:ao,void:oo,never:so,any:co,unknown:lo,date:uo,enum:fo,literal:po,nan:mo,template_literal:ho,file:go,success:_o,custom:vo,function:yo,transform:bo,map:xo,set:So,array:Co,object:wo,union:To,intersection:Eo,tuple:Do,record:Oo,nullable:ko,nonoptional:Ao,default:jo,prefault:Mo,catch:No,pipe:Po,readonly:Fo,promise:Io,optional:Lo,lazy:(e,t,n,r)=>{let i=e._zod.innerType;Ka(i,t,r);let a=t.seen.get(e);a.ref=i}};function zo(e,t){if(`_idmap`in e){let n=e,r=Ga({...t,processors:Ro}),i={};for(let e of n._idmap.entries()){let[t,n]=e;Ka(n,r)}let a={};r.external={registry:n,uri:t?.uri,defs:i};for(let e of n._idmap.entries()){let[t,n]=e;qa(r,n),a[t]=Ja(r,n)}return Object.keys(i).length>0&&(a.__shared={[r.target===`draft-2020-12`?`$defs`:`definitions`]:i}),{schemas:a}}let n=Ga({...t,processors:Ro});return Ka(e,n),qa(n,e),Ja(n,e)}const Bo=D(`ZodISODateTime`,(e,t)=>{Mr.init(e,t),fs.init(e,t)});function Vo(e){return oa(Bo,e)}const Ho=D(`ZodISODate`,(e,t)=>{Nr.init(e,t),fs.init(e,t)});function Uo(e){return sa(Ho,e)}const Wo=D(`ZodISOTime`,(e,t)=>{Pr.init(e,t),fs.init(e,t)});function Go(e){return ca(Wo,e)}const Ko=D(`ZodISODuration`,(e,t)=>{Fr.init(e,t),fs.init(e,t)});function qo(e){return la(Ko,e)}const Jo=(e,t)=>{en.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>rn(e,t)},flatten:{value:t=>nn(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,yt,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,yt,2)}},isEmpty:{get(){return e.issues.length===0}}})};D(`ZodError`,Jo);const Yo=D(`ZodError`,Jo,{Parent:Error}),Xo=sn(Yo),Zo=ln(Yo),Qo=dn(Yo),$o=pn(Yo),es=hn(Yo),ts=gn(Yo),ns=_n(Yo),rs=vn(Yo),is=yn(Yo),as=bn(Yo),ss=xn(Yo),cs=Sn(Yo),ls=D(`ZodType`,(e,t)=>(vr.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Za(e,`input`),output:Za(e,`output`)}}),e.toJSONSchema=Xa(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(Dt(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Lt(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Xo(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Qo(e,t,n),e.parseAsync=async(t,n)=>Zo(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>$o(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>es(e,t,n),e.decode=(t,n)=>ts(e,t,n),e.encodeAsync=async(t,n)=>ns(e,t,n),e.decodeAsync=async(t,n)=>rs(e,t,n),e.safeEncode=(t,n)=>is(e,t,n),e.safeDecode=(t,n)=>as(e,t,n),e.safeEncodeAsync=async(t,n)=>ss(e,t,n),e.safeDecodeAsync=async(t,n)=>cs(e,t,n),e.refine=(t,n)=>e.check(Dc(t,n)),e.superRefine=t=>e.check(Oc(t)),e.overwrite=t=>e.check(Ma(t)),e.optional=()=>cc(e),e.exactOptional=()=>uc(e),e.nullable=()=>fc(e),e.nullish=()=>cc(fc(e)),e.nonoptional=t=>vc(e,t),e.array=()=>j(e),e.or=t=>Xs([e,t]),e.and=t=>ec(e,t),e.transform=t=>Sc(e,oc(t)),e.default=t=>mc(e,t),e.prefault=t=>gc(e,t),e.catch=t=>bc(e,t),e.pipe=t=>Sc(e,t),e.readonly=()=>wc(e),e.describe=t=>{let n=e.clone();return Ii.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return Ii.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return Ii.get(e);let n=e.clone();return Ii.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),us=D(`_ZodString`,(e,t)=>{yr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$a(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Ea(...t)),e.includes=(...t)=>e.check(ka(...t)),e.startsWith=(...t)=>e.check(Aa(...t)),e.endsWith=(...t)=>e.check(ja(...t)),e.min=(...t)=>e.check(wa(...t)),e.max=(...t)=>e.check(Ca(...t)),e.length=(...t)=>e.check(Ta(...t)),e.nonempty=(...t)=>e.check(wa(1,...t)),e.lowercase=t=>e.check(Da(t)),e.uppercase=t=>e.check(Oa(t)),e.trim=()=>e.check(Pa()),e.normalize=(...t)=>e.check(Na(...t)),e.toLowerCase=()=>e.check(Fa()),e.toUpperCase=()=>e.check(Ia()),e.slugify=()=>e.check(La())}),ds=D(`ZodString`,(e,t)=>{yr.init(e,t),us.init(e,t),e.email=t=>e.check(Ri(ps,t)),e.url=t=>e.check(Wi(gs,t)),e.jwt=t=>e.check(aa(Ms,t)),e.emoji=t=>e.check(Gi(vs,t)),e.guid=t=>e.check(zi(ms,t)),e.uuid=t=>e.check(Bi(hs,t)),e.uuidv4=t=>e.check(Vi(hs,t)),e.uuidv6=t=>e.check(Hi(hs,t)),e.uuidv7=t=>e.check(Ui(hs,t)),e.nanoid=t=>e.check(Ki(ys,t)),e.guid=t=>e.check(zi(ms,t)),e.cuid=t=>e.check(qi(bs,t)),e.cuid2=t=>e.check(Ji(xs,t)),e.ulid=t=>e.check(Yi(Ss,t)),e.base64=t=>e.check(na(ks,t)),e.base64url=t=>e.check(ra(As,t)),e.xid=t=>e.check(Xi(Cs,t)),e.ksuid=t=>e.check(Zi(ws,t)),e.ipv4=t=>e.check(Qi(Ts,t)),e.ipv6=t=>e.check($i(Es,t)),e.cidrv4=t=>e.check(ea(Ds,t)),e.cidrv6=t=>e.check(ta(Os,t)),e.e164=t=>e.check(ia(js,t)),e.datetime=t=>e.check(Vo(t)),e.date=t=>e.check(Uo(t)),e.time=t=>e.check(Go(t)),e.duration=t=>e.check(qo(t))});function k(e){return Li(ds,e)}const fs=D(`ZodStringFormat`,(e,t)=>{br.init(e,t),us.init(e,t)}),ps=D(`ZodEmail`,(e,t)=>{Cr.init(e,t),fs.init(e,t)}),ms=D(`ZodGUID`,(e,t)=>{xr.init(e,t),fs.init(e,t)}),hs=D(`ZodUUID`,(e,t)=>{Sr.init(e,t),fs.init(e,t)}),gs=D(`ZodURL`,(e,t)=>{wr.init(e,t),fs.init(e,t)});function _s(e){return Wi(gs,e)}const vs=D(`ZodEmoji`,(e,t)=>{Tr.init(e,t),fs.init(e,t)}),ys=D(`ZodNanoID`,(e,t)=>{Er.init(e,t),fs.init(e,t)}),bs=D(`ZodCUID`,(e,t)=>{Dr.init(e,t),fs.init(e,t)}),xs=D(`ZodCUID2`,(e,t)=>{Or.init(e,t),fs.init(e,t)}),Ss=D(`ZodULID`,(e,t)=>{kr.init(e,t),fs.init(e,t)}),Cs=D(`ZodXID`,(e,t)=>{Ar.init(e,t),fs.init(e,t)}),ws=D(`ZodKSUID`,(e,t)=>{jr.init(e,t),fs.init(e,t)}),Ts=D(`ZodIPv4`,(e,t)=>{Ir.init(e,t),fs.init(e,t)}),Es=D(`ZodIPv6`,(e,t)=>{Lr.init(e,t),fs.init(e,t)}),Ds=D(`ZodCIDRv4`,(e,t)=>{Rr.init(e,t),fs.init(e,t)}),Os=D(`ZodCIDRv6`,(e,t)=>{zr.init(e,t),fs.init(e,t)}),ks=D(`ZodBase64`,(e,t)=>{Vr.init(e,t),fs.init(e,t)}),As=D(`ZodBase64URL`,(e,t)=>{Ur.init(e,t),fs.init(e,t)}),js=D(`ZodE164`,(e,t)=>{Wr.init(e,t),fs.init(e,t)}),Ms=D(`ZodJWT`,(e,t)=>{Kr.init(e,t),fs.init(e,t)}),Ns=D(`ZodNumber`,(e,t)=>{qr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>eo(e,t,n,r),e.gt=(t,n)=>e.check(ba(t,n)),e.gte=(t,n)=>e.check(xa(t,n)),e.min=(t,n)=>e.check(xa(t,n)),e.lt=(t,n)=>e.check(va(t,n)),e.lte=(t,n)=>e.check(ya(t,n)),e.max=(t,n)=>e.check(ya(t,n)),e.int=t=>e.check(Fs(t)),e.safe=t=>e.check(Fs(t)),e.positive=t=>e.check(ba(0,t)),e.nonnegative=t=>e.check(xa(0,t)),e.negative=t=>e.check(va(0,t)),e.nonpositive=t=>e.check(ya(0,t)),e.multipleOf=(t,n)=>e.check(Sa(t,n)),e.step=(t,n)=>e.check(Sa(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function A(e){return ua(Ns,e)}const Ps=D(`ZodNumberFormat`,(e,t)=>{Jr.init(e,t),Ns.init(e,t)});function Fs(e){return fa(Ps,e)}const Is=D(`ZodBoolean`,(e,t)=>{Yr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>to(e,t,n,r)});function Ls(e){return pa(Is,e)}const Rs=D(`ZodNull`,(e,t)=>{Xr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>io(e,t,n,r)});function zs(e){return ma(Rs,e)}const Bs=D(`ZodAny`,(e,t)=>{Zr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Vs(){return ha(Bs)}const Hs=D(`ZodUnknown`,(e,t)=>{Qr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Us(){return ga(Hs)}const Ws=D(`ZodNever`,(e,t)=>{$r.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>so(e,t,n,r)});function Gs(e){return _a(Ws,e)}const Ks=D(`ZodArray`,(e,t)=>{ti.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Co(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(wa(t,n)),e.nonempty=t=>e.check(wa(1,t)),e.max=(t,n)=>e.check(Ca(t,n)),e.length=(t,n)=>e.check(Ta(t,n)),e.unwrap=()=>e.element});function j(e,t){return Ra(Ks,e,t)}const qs=D(`ZodObject`,(e,t)=>{oi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wo(e,t,n,r),Tt(e,`shape`,()=>t.shape),e.keyof=()=>N(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Us()}),e.loose=()=>e.clone({...e._zod.def,catchall:Us()}),e.strict=()=>e.clone({...e._zod.def,catchall:Gs()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Ht(e,t),e.safeExtend=t=>Ut(e,t),e.merge=t=>Wt(e,t),e.pick=t=>Bt(e,t),e.omit=t=>Vt(e,t),e.partial=(...t)=>Gt(sc,e,t[0]),e.required=(...t)=>Kt(_c,e,t[0])});function M(e,t){return new qs({type:`object`,shape:e??{},...O(t)})}function Js(e,t){return new qs({type:`object`,shape:e,catchall:Us(),...O(t)})}const Ys=D(`ZodUnion`,(e,t)=>{ci.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>To(e,t,n,r),e.options=t.options});function Xs(e,t){return new Ys({type:`union`,options:e,...O(t)})}const Zs=D(`ZodDiscriminatedUnion`,(e,t)=>{Ys.init(e,t),li.init(e,t)});function Qs(e,t,n){return new Zs({type:`union`,options:t,discriminator:e,...O(n)})}const $s=D(`ZodIntersection`,(e,t)=>{ui.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eo(e,t,n,r)});function ec(e,t){return new $s({type:`intersection`,left:e,right:t})}const tc=D(`ZodRecord`,(e,t)=>{pi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function nc(e,t,n){return new tc({type:`record`,keyType:e,valueType:t,...O(n)})}const rc=D(`ZodEnum`,(e,t)=>{mi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fo(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new rc({...t,checks:[],...O(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new rc({...t,checks:[],...O(r),entries:i})}});function N(e,t){return new rc({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...O(t)})}const ic=D(`ZodLiteral`,(e,t)=>{hi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>po(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function P(e,t){return new ic({type:`literal`,values:Array.isArray(e)?e:[e],...O(t)})}const ac=D(`ZodTransform`,(e,t)=>{gi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new ht(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Qt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Qt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function oc(e){return new ac({type:`transform`,transform:e})}const sc=D(`ZodOptional`,(e,t)=>{vi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function cc(e){return new sc({type:`optional`,innerType:e})}const lc=D(`ZodExactOptional`,(e,t)=>{yi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function uc(e){return new lc({type:`optional`,innerType:e})}const dc=D(`ZodNullable`,(e,t)=>{bi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function fc(e){return new dc({type:`nullable`,innerType:e})}const pc=D(`ZodDefault`,(e,t)=>{xi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function mc(e,t){return new pc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Pt(t)}})}const hc=D(`ZodPrefault`,(e,t)=>{Ci.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function gc(e,t){return new hc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Pt(t)}})}const _c=D(`ZodNonOptional`,(e,t)=>{wi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function vc(e,t){return new _c({type:`nonoptional`,innerType:e,...O(t)})}const yc=D(`ZodCatch`,(e,t)=>{Ei.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function bc(e,t){return new yc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const xc=D(`ZodPipe`,(e,t)=>{Di.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r),e.in=t.in,e.out=t.out});function Sc(e,t){return new xc({type:`pipe`,in:e,out:t})}const Cc=D(`ZodReadonly`,(e,t)=>{ki.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function wc(e){return new Cc({type:`readonly`,innerType:e})}const Tc=D(`ZodCustom`,(e,t)=>{ji.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vo(e,t,n,r)});function Ec(e,t){return za(Tc,e??(()=>!0),t)}function Dc(e,t={}){return Ba(Tc,e,t)}function Oc(e){return Va(e)}function kc(e,t){return Sc(oc(e),t)}var Ac=ft();a();const jc=Symbol.for(`@inkeep/open-knowledge/field-registry`),Mc=globalThis;Mc[jc]===void 0&&(Mc[jc]=Fi());const Nc=Mc[jc];function Pc(e){let t=e;for(let e=0;e<16;e++){if(t==null)return;let e=Fc(t)?Nc.get(t):void 0;if(e!==void 0)return e;let n=t._zod?.def?.innerType;if(n===void 0)return;t=n}}function Fc(e){return typeof e==`object`&&!!e&&`_zod`in e&&`parse`in e}const Ic=Object.freeze([`authorization`,`auth.token`,`auth.bearer`,`cookie`,`set-cookie`,`x-api-key`,`password`,`secret`]),Lc=52428800,Rc=26214400,zc=Js({content:Js({dir:k().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Folder Open Knowledge reads and writes documents under, relative to the project root (the folder that contains .ok/). Defaults to the project root. Exclude paths with .okignore.`}).default(`.`)}).default({dir:`.`}),preview:Js({scriptSrc:N([`cdn-allowlist`,`inline-only`]).register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Security policy for scripts in code-block preview embeds. 'cdn-allowlist' allows <script src> from a fixed set of trusted CDNs; 'inline-only' is the strict policy for cloud / multi-tenant deployments. Shared across collaborators.`}).default(`cdn-allowlist`)}).default({scriptSrc:`cdn-allowlist`}),appearance:Js({theme:N([`light`,`dark`,`system`]).register(Nc,{scope:`user`,agentSettable:!1,defaultScope:`user`,description:`Editor color theme: 'light', 'dark', or 'system' (follow the OS). A personal preference (user scope) — not shared with the project.`}).optional(),preview:Js({autoOpen:Ls().register(Nc,{scope:`user`,agentSettable:!1,defaultScope:`user`,description:`When on, the agent opens or refreshes the live preview after each edit. Turn off if you manage your own preview window. A personal preference (user scope).`}).default(!0)}).default({autoOpen:!0}),sidebar:Js({showHiddenFiles:Ls().register(Nc,{scope:`project-local`,agentSettable:!1,defaultScope:`project-local`,description:`Show dot-prefixed entries (e.g. .ok/, .okignore) in the file tree. Per-machine (project-local) — not shared with collaborators.`}).default(!1),showAllFiles:Ls().register(Nc,{scope:`project-local`,agentSettable:!1,defaultScope:`project-local`,description:`Show every file, including those excluded by .gitignore / .okignore. Per-machine (project-local) — not shared.`}).default(!1)}).optional()}).default({preview:{autoOpen:!0}}),editor:Js({wordWrap:Ls().register(Nc,{scope:`user`,agentSettable:!1,defaultScope:`user`,description:`Soft-wrap long lines in the source (CodeMirror) editor. A personal preference (user scope).`}).default(!0)}).default({wordWrap:!0}),autoSync:Js({enabled:Ls().register(Nc,{scope:`project-local`,agentSettable:!1,defaultScope:`project-local`,description:`Whether this machine auto-pulls and auto-pushes git commits for this project. null = not chosen yet (onboarding asks). Per-machine (project-local) — not shared.`}).nullable().default(null)}).default({enabled:null}),telemetry:Js({localSink:Js({enabled:Ls().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:"Write local diagnostic spans + logs under .ok/local/ for `ok diagnose bundle`. Local-only — never leaves the machine until you run bundle. Set false for sensitive workspaces. Shared across collaborators."}).default(!0),spans:Js({maxBytes:A().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Maximum size, in bytes, of the local diagnostic spans file before it rotates (default ~50 MB).`}).default(Lc)}).default({maxBytes:Lc}),logs:Js({maxBytes:A().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Maximum size, in bytes, of the local diagnostic logs file before it rotates (default ~25 MB).`}).default(Rc)}).default({maxBytes:Rc}),attributeDenylist:j(k()).register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Telemetry attribute keys whose values are redacted before any local span/log is written (credential / secret guard). Extends the built-in denylist.`}).default([...Ic])}).default({enabled:!0,spans:{maxBytes:Lc},logs:{maxBytes:Rc},attributeDenylist:[...Ic]})}).default({localSink:{enabled:!0,spans:{maxBytes:Lc},logs:{maxBytes:Rc},attributeDenylist:[...Ic]}})}),Bc=`open-knowledge-config`;async function Vc(e,t,n){let r=o.getTracer(Bc),a=t?{attributes:t}:{};return r.startActiveSpan(e,a,async e=>{try{return await n(e)}catch(t){throw e.recordException(t),e.setStatus({code:i.ERROR,message:t instanceof Error?t.message:String(t)}),t}finally{e.end()}})}function Hc(e,t,n){let r=o.getTracer(Bc),a=t?{attributes:t}:{};return r.startActiveSpan(e,a,e=>{try{return n(e)}catch(t){throw e.recordException(t),e.setStatus({code:i.ERROR,message:t instanceof Error?t.message:String(t)}),t}finally{e.end()}})}function Uc(e,t){let n=o.getActiveSpan();n&&n.addEvent(e,t)}function Wc(e){let t=e;for(let e=0;e<16;e++){if(t==null||t?._zod?.def?.shape!==void 0)return t;let e=t?._zod?.def?.innerType;if(e===void 0)return t;t=e}return t}function Gc(e,t){let n=e;for(let e of t){n=Wc(n);let t=n?._zod?.def?.shape;if(!t||(n=t[String(e)],n===void 0))return}return n}function Kc(e,t){let n=Gc(e,t);if(n!==void 0)return Pc(n)}function qc(e,t){return e===`either`?!0:e===t}function Jc(e,t){let n=null;function r(e,i){if(n!==null||e===void 0)return;if(typeof e==`object`&&e&&!Array.isArray(e)){for(let[t,a]of Object.entries(e))if(r(a,[...i,t]),n!==null)return;return}let a=Kc(zc,i);a?.scope!==void 0&&(qc(a.scope,t)||(n={code:`SCOPE_VIOLATION`,path:i,expectedScope:a.scope,actualScope:t}))}for(let[t,i]of Object.entries(e))if(r(i,[t]),n!==null)break;return n}function Yc(e,t){for(let n=1;n<t.length;n++){let r=t.slice(0,n);e.hasIn(r)&&((0,Ac.isCollection)(e.getIn(r,!0))||e.deleteIn(r))}}function Xc(e,t){let n=[];function r(t,i){if(t!==void 0){if(t===null){e.deleteIn(i),n.push(i.join(`.`));return}if(Array.isArray(t)){Yc(e,i),e.setIn(i,t),n.push(i.join(`.`));return}if(typeof t==`object`){for(let[e,n]of Object.entries(t))r(n,[...i,e]);return}Yc(e,i),e.setIn(i,t),n.push(i.join(`.`))}}for(let[e,n]of Object.entries(t))r(n,[e]);return n}function Zc(e){return{path:e.path.map(e=>typeof e==`symbol`?String(e):e),message:e.message,issueCode:e.code}}const Qc=M({file:k(),line:A().int().min(1),column:A().int().min(1),snippet:k().optional()}),$c=M({path:j(Xs([k(),A()])),message:k(),issueCode:k(),params:nc(k(),Us()).optional(),source:Qc.optional()}),el=N([`user`,`project`,`project-local`,`either`]),tl=N([`user`,`project`,`project-local`]),nl=Qs(`code`,[M({code:P(`YAML_PARSE`),detail:k()}),M({code:P(`SCHEMA_INVALID`),issues:j($c)}),M({code:P(`SCOPE_VIOLATION`),path:j(k()),expectedScope:el,actualScope:tl}),M({code:P(`NOT_AGENT_SETTABLE`),path:j(k())}),M({code:P(`MIXED_SCOPE`),paths:j(M({path:j(k()),scope:tl}))}),M({code:P(`REMOVED_KEY`),path:j(k()),redirect:k(),source:Qc.optional()}),M({code:P(`WRITE_ERROR`),detail:k()}),M({code:P(`OKIGNORE_INVALID`),detail:k(),lineNumber:A().int().min(1).optional()}),M({code:P(`UNKNOWN`),message:k().optional()})]),rl=new Set(nl.options.map(e=>e.shape.code.value)),il=Xs([nl,Js({code:k(),message:k().optional()})]);function al(e){return rl.has(e.code)}function ol(e){switch(e){case`user`:return`~/.ok/global.yml`;case`project`:return`.ok/config.yml`;case`project-local`:return`.ok/local/config.yml`;case`either`:return`.ok/config.yml or ~/.ok/global.yml`}}function sl(e){switch(e){case`user`:return`personal to you, across all projects`;case`project`:return`shared with your team via git`;case`project-local`:return`this machine only, not shared`;case`either`:return`user or project`}}function cl(e){if(!al(e))return e.message??`Unknown error (${e.code}).`;switch(e.code){case`YAML_PARSE`:return`Failed to parse YAML: ${e.detail}`;case`SCHEMA_INVALID`:{if(e.issues.length===0)return`Invalid configuration.`;let t=new Map;for(let n of e.issues){let e=n.source?.file??`<no source>`,r=t.get(e)??[];r.push(n),t.set(e,r)}let n=[];for(let[e,r]of t){e===`<no source>`?n.push(`Invalid configuration:`):n.push(`Invalid configuration at ${e}:`);for(let t of r){let r=t.path.length===0?`<root>`:t.path.join(`.`);if(t.source){if(n.push(` ${e}:${t.source.line}:${t.source.column}`),n.push(` ${r}: ${t.message}`),t.source.snippet&&t.source.snippet.length>0)for(let e of t.source.snippet.split(`
|
|
154
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Ja(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:Za(t,`input`,e.processors),output:Za(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Ya(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Ya(r.element,n);if(r.type===`set`)return Ya(r.valueType,n);if(r.type===`lazy`)return Ya(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return Ya(r.innerType,n);if(r.type===`intersection`)return Ya(r.left,n)||Ya(r.right,n);if(r.type===`record`||r.type===`map`)return Ya(r.keyType,n)||Ya(r.valueType,n);if(r.type===`pipe`)return Ya(r.in,n)||Ya(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Ya(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Ya(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Ya(e,n))return!0;return!!(r.rest&&Ya(r.rest,n))}return!1}const Xa=(e,t={})=>n=>{let r=Ga({...n,processors:t});return Ka(e,r),qa(r,e),Ja(r,e)},Za=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Ga({...i??{},target:a,io:t,processors:n});return Ka(e,o),qa(o,e),Ja(o,e)},Qa={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},$a=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Qa[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},eo=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},to=(e,t,n,r)=>{n.type=`boolean`},no=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`BigInt cannot be represented in JSON Schema`)},ro=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Symbols cannot be represented in JSON Schema`)},io=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},ao=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Undefined cannot be represented in JSON Schema`)},oo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Void cannot be represented in JSON Schema`)},so=(e,t,n,r)=>{n.not={}},co=(e,t,n,r)=>{},lo=(e,t,n,r)=>{},uo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Date cannot be represented in JSON Schema`)},fo=(e,t,n,r)=>{let i=e._zod.def,a=vt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},po=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},mo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`NaN cannot be represented in JSON Schema`)},ho=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},go=(e,t,n,r)=>{let i=n,a={type:`string`,format:`binary`,contentEncoding:`binary`},{minimum:o,maximum:s,mime:c}=e._zod.bag;o!==void 0&&(a.minLength=o),s!==void 0&&(a.maxLength=s),c?c.length===1?(a.contentMediaType=c[0],Object.assign(i,a)):(Object.assign(i,a),i.anyOf=c.map(e=>({contentMediaType:e}))):Object.assign(i,a)},_o=(e,t,n,r)=>{n.type=`boolean`},vo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},yo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Function types cannot be represented in JSON Schema`)},bo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},xo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Map cannot be represented in JSON Schema`)},So=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Set cannot be represented in JSON Schema`)},Co=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Ka(a.element,t,{...r,path:[...r.path,`items`]})},wo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=Ka(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Ka(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},To=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Ka(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Eo=(e,t,n,r)=>{let i=e._zod.def,a=Ka(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Ka(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Do=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>Ka(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?Ka(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null;t.target===`draft-2020-12`?(i.prefixItems=c,l&&(i.items=l)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),i.minItems=c.length,l||(i.maxItems=c.length)):(i.items=c,l&&(i.additionalItems=l));let{minimum:u,maximum:d}=e._zod.bag;typeof u==`number`&&(i.minItems=u),typeof d==`number`&&(i.maxItems=d)},Oo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Ka(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=Ka(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=Ka(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},ko=(e,t,n,r)=>{let i=e._zod.def,a=Ka(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Ao=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},jo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Mo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},No=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Po=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;Ka(a,t,r);let o=t.seen.get(e);o.ref=a},Fo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Io=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Lo=(e,t,n,r)=>{let i=e._zod.def;Ka(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ro={string:$a,number:eo,boolean:to,bigint:no,symbol:ro,null:io,undefined:ao,void:oo,never:so,any:co,unknown:lo,date:uo,enum:fo,literal:po,nan:mo,template_literal:ho,file:go,success:_o,custom:vo,function:yo,transform:bo,map:xo,set:So,array:Co,object:wo,union:To,intersection:Eo,tuple:Do,record:Oo,nullable:ko,nonoptional:Ao,default:jo,prefault:Mo,catch:No,pipe:Po,readonly:Fo,promise:Io,optional:Lo,lazy:(e,t,n,r)=>{let i=e._zod.innerType;Ka(i,t,r);let a=t.seen.get(e);a.ref=i}};function zo(e,t){if(`_idmap`in e){let n=e,r=Ga({...t,processors:Ro}),i={};for(let e of n._idmap.entries()){let[t,n]=e;Ka(n,r)}let a={};r.external={registry:n,uri:t?.uri,defs:i};for(let e of n._idmap.entries()){let[t,n]=e;qa(r,n),a[t]=Ja(r,n)}return Object.keys(i).length>0&&(a.__shared={[r.target===`draft-2020-12`?`$defs`:`definitions`]:i}),{schemas:a}}let n=Ga({...t,processors:Ro});return Ka(e,n),qa(n,e),Ja(n,e)}const Bo=D(`ZodISODateTime`,(e,t)=>{Mr.init(e,t),fs.init(e,t)});function Vo(e){return oa(Bo,e)}const Ho=D(`ZodISODate`,(e,t)=>{Nr.init(e,t),fs.init(e,t)});function Uo(e){return sa(Ho,e)}const Wo=D(`ZodISOTime`,(e,t)=>{Pr.init(e,t),fs.init(e,t)});function Go(e){return ca(Wo,e)}const Ko=D(`ZodISODuration`,(e,t)=>{Fr.init(e,t),fs.init(e,t)});function qo(e){return la(Ko,e)}const Jo=(e,t)=>{en.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>rn(e,t)},flatten:{value:t=>nn(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,yt,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,yt,2)}},isEmpty:{get(){return e.issues.length===0}}})};D(`ZodError`,Jo);const Yo=D(`ZodError`,Jo,{Parent:Error}),Xo=sn(Yo),Zo=ln(Yo),Qo=dn(Yo),$o=pn(Yo),es=hn(Yo),ts=gn(Yo),ns=_n(Yo),rs=vn(Yo),is=yn(Yo),as=bn(Yo),ss=xn(Yo),cs=Sn(Yo),ls=D(`ZodType`,(e,t)=>(vr.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Za(e,`input`),output:Za(e,`output`)}}),e.toJSONSchema=Xa(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(Dt(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Lt(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Xo(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Qo(e,t,n),e.parseAsync=async(t,n)=>Zo(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>$o(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>es(e,t,n),e.decode=(t,n)=>ts(e,t,n),e.encodeAsync=async(t,n)=>ns(e,t,n),e.decodeAsync=async(t,n)=>rs(e,t,n),e.safeEncode=(t,n)=>is(e,t,n),e.safeDecode=(t,n)=>as(e,t,n),e.safeEncodeAsync=async(t,n)=>ss(e,t,n),e.safeDecodeAsync=async(t,n)=>cs(e,t,n),e.refine=(t,n)=>e.check(Dc(t,n)),e.superRefine=t=>e.check(Oc(t)),e.overwrite=t=>e.check(Ma(t)),e.optional=()=>cc(e),e.exactOptional=()=>uc(e),e.nullable=()=>fc(e),e.nullish=()=>cc(fc(e)),e.nonoptional=t=>vc(e,t),e.array=()=>j(e),e.or=t=>Xs([e,t]),e.and=t=>ec(e,t),e.transform=t=>Sc(e,oc(t)),e.default=t=>mc(e,t),e.prefault=t=>gc(e,t),e.catch=t=>bc(e,t),e.pipe=t=>Sc(e,t),e.readonly=()=>wc(e),e.describe=t=>{let n=e.clone();return Ii.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return Ii.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return Ii.get(e);let n=e.clone();return Ii.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),us=D(`_ZodString`,(e,t)=>{yr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$a(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Ea(...t)),e.includes=(...t)=>e.check(ka(...t)),e.startsWith=(...t)=>e.check(Aa(...t)),e.endsWith=(...t)=>e.check(ja(...t)),e.min=(...t)=>e.check(wa(...t)),e.max=(...t)=>e.check(Ca(...t)),e.length=(...t)=>e.check(Ta(...t)),e.nonempty=(...t)=>e.check(wa(1,...t)),e.lowercase=t=>e.check(Da(t)),e.uppercase=t=>e.check(Oa(t)),e.trim=()=>e.check(Pa()),e.normalize=(...t)=>e.check(Na(...t)),e.toLowerCase=()=>e.check(Fa()),e.toUpperCase=()=>e.check(Ia()),e.slugify=()=>e.check(La())}),ds=D(`ZodString`,(e,t)=>{yr.init(e,t),us.init(e,t),e.email=t=>e.check(Ri(ps,t)),e.url=t=>e.check(Wi(gs,t)),e.jwt=t=>e.check(aa(Ms,t)),e.emoji=t=>e.check(Gi(vs,t)),e.guid=t=>e.check(zi(ms,t)),e.uuid=t=>e.check(Bi(hs,t)),e.uuidv4=t=>e.check(Vi(hs,t)),e.uuidv6=t=>e.check(Hi(hs,t)),e.uuidv7=t=>e.check(Ui(hs,t)),e.nanoid=t=>e.check(Ki(ys,t)),e.guid=t=>e.check(zi(ms,t)),e.cuid=t=>e.check(qi(bs,t)),e.cuid2=t=>e.check(Ji(xs,t)),e.ulid=t=>e.check(Yi(Ss,t)),e.base64=t=>e.check(na(ks,t)),e.base64url=t=>e.check(ra(As,t)),e.xid=t=>e.check(Xi(Cs,t)),e.ksuid=t=>e.check(Zi(ws,t)),e.ipv4=t=>e.check(Qi(Ts,t)),e.ipv6=t=>e.check($i(Es,t)),e.cidrv4=t=>e.check(ea(Ds,t)),e.cidrv6=t=>e.check(ta(Os,t)),e.e164=t=>e.check(ia(js,t)),e.datetime=t=>e.check(Vo(t)),e.date=t=>e.check(Uo(t)),e.time=t=>e.check(Go(t)),e.duration=t=>e.check(qo(t))});function k(e){return Li(ds,e)}const fs=D(`ZodStringFormat`,(e,t)=>{br.init(e,t),us.init(e,t)}),ps=D(`ZodEmail`,(e,t)=>{Cr.init(e,t),fs.init(e,t)}),ms=D(`ZodGUID`,(e,t)=>{xr.init(e,t),fs.init(e,t)}),hs=D(`ZodUUID`,(e,t)=>{Sr.init(e,t),fs.init(e,t)}),gs=D(`ZodURL`,(e,t)=>{wr.init(e,t),fs.init(e,t)});function _s(e){return Wi(gs,e)}const vs=D(`ZodEmoji`,(e,t)=>{Tr.init(e,t),fs.init(e,t)}),ys=D(`ZodNanoID`,(e,t)=>{Er.init(e,t),fs.init(e,t)}),bs=D(`ZodCUID`,(e,t)=>{Dr.init(e,t),fs.init(e,t)}),xs=D(`ZodCUID2`,(e,t)=>{Or.init(e,t),fs.init(e,t)}),Ss=D(`ZodULID`,(e,t)=>{kr.init(e,t),fs.init(e,t)}),Cs=D(`ZodXID`,(e,t)=>{Ar.init(e,t),fs.init(e,t)}),ws=D(`ZodKSUID`,(e,t)=>{jr.init(e,t),fs.init(e,t)}),Ts=D(`ZodIPv4`,(e,t)=>{Ir.init(e,t),fs.init(e,t)}),Es=D(`ZodIPv6`,(e,t)=>{Lr.init(e,t),fs.init(e,t)}),Ds=D(`ZodCIDRv4`,(e,t)=>{Rr.init(e,t),fs.init(e,t)}),Os=D(`ZodCIDRv6`,(e,t)=>{zr.init(e,t),fs.init(e,t)}),ks=D(`ZodBase64`,(e,t)=>{Vr.init(e,t),fs.init(e,t)}),As=D(`ZodBase64URL`,(e,t)=>{Ur.init(e,t),fs.init(e,t)}),js=D(`ZodE164`,(e,t)=>{Wr.init(e,t),fs.init(e,t)}),Ms=D(`ZodJWT`,(e,t)=>{Kr.init(e,t),fs.init(e,t)}),Ns=D(`ZodNumber`,(e,t)=>{qr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>eo(e,t,n,r),e.gt=(t,n)=>e.check(ba(t,n)),e.gte=(t,n)=>e.check(xa(t,n)),e.min=(t,n)=>e.check(xa(t,n)),e.lt=(t,n)=>e.check(va(t,n)),e.lte=(t,n)=>e.check(ya(t,n)),e.max=(t,n)=>e.check(ya(t,n)),e.int=t=>e.check(Fs(t)),e.safe=t=>e.check(Fs(t)),e.positive=t=>e.check(ba(0,t)),e.nonnegative=t=>e.check(xa(0,t)),e.negative=t=>e.check(va(0,t)),e.nonpositive=t=>e.check(ya(0,t)),e.multipleOf=(t,n)=>e.check(Sa(t,n)),e.step=(t,n)=>e.check(Sa(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function A(e){return ua(Ns,e)}const Ps=D(`ZodNumberFormat`,(e,t)=>{Jr.init(e,t),Ns.init(e,t)});function Fs(e){return fa(Ps,e)}const Is=D(`ZodBoolean`,(e,t)=>{Yr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>to(e,t,n,r)});function Ls(e){return pa(Is,e)}const Rs=D(`ZodNull`,(e,t)=>{Xr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>io(e,t,n,r)});function zs(e){return ma(Rs,e)}const Bs=D(`ZodAny`,(e,t)=>{Zr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Vs(){return ha(Bs)}const Hs=D(`ZodUnknown`,(e,t)=>{Qr.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Us(){return ga(Hs)}const Ws=D(`ZodNever`,(e,t)=>{$r.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>so(e,t,n,r)});function Gs(e){return _a(Ws,e)}const Ks=D(`ZodArray`,(e,t)=>{ti.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Co(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(wa(t,n)),e.nonempty=t=>e.check(wa(1,t)),e.max=(t,n)=>e.check(Ca(t,n)),e.length=(t,n)=>e.check(Ta(t,n)),e.unwrap=()=>e.element});function j(e,t){return Ra(Ks,e,t)}const qs=D(`ZodObject`,(e,t)=>{oi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wo(e,t,n,r),Tt(e,`shape`,()=>t.shape),e.keyof=()=>N(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Us()}),e.loose=()=>e.clone({...e._zod.def,catchall:Us()}),e.strict=()=>e.clone({...e._zod.def,catchall:Gs()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Ht(e,t),e.safeExtend=t=>Ut(e,t),e.merge=t=>Wt(e,t),e.pick=t=>Bt(e,t),e.omit=t=>Vt(e,t),e.partial=(...t)=>Gt(sc,e,t[0]),e.required=(...t)=>Kt(_c,e,t[0])});function M(e,t){return new qs({type:`object`,shape:e??{},...O(t)})}function Js(e,t){return new qs({type:`object`,shape:e,catchall:Us(),...O(t)})}const Ys=D(`ZodUnion`,(e,t)=>{ci.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>To(e,t,n,r),e.options=t.options});function Xs(e,t){return new Ys({type:`union`,options:e,...O(t)})}const Zs=D(`ZodDiscriminatedUnion`,(e,t)=>{Ys.init(e,t),li.init(e,t)});function Qs(e,t,n){return new Zs({type:`union`,options:t,discriminator:e,...O(n)})}const $s=D(`ZodIntersection`,(e,t)=>{ui.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eo(e,t,n,r)});function ec(e,t){return new $s({type:`intersection`,left:e,right:t})}const tc=D(`ZodRecord`,(e,t)=>{pi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function nc(e,t,n){return new tc({type:`record`,keyType:e,valueType:t,...O(n)})}const rc=D(`ZodEnum`,(e,t)=>{mi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fo(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new rc({...t,checks:[],...O(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new rc({...t,checks:[],...O(r),entries:i})}});function N(e,t){return new rc({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...O(t)})}const ic=D(`ZodLiteral`,(e,t)=>{hi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>po(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function P(e,t){return new ic({type:`literal`,values:Array.isArray(e)?e:[e],...O(t)})}const ac=D(`ZodTransform`,(e,t)=>{gi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new ht(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Qt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Qt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function oc(e){return new ac({type:`transform`,transform:e})}const sc=D(`ZodOptional`,(e,t)=>{vi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function cc(e){return new sc({type:`optional`,innerType:e})}const lc=D(`ZodExactOptional`,(e,t)=>{yi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function uc(e){return new lc({type:`optional`,innerType:e})}const dc=D(`ZodNullable`,(e,t)=>{bi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function fc(e){return new dc({type:`nullable`,innerType:e})}const pc=D(`ZodDefault`,(e,t)=>{xi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function mc(e,t){return new pc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Pt(t)}})}const hc=D(`ZodPrefault`,(e,t)=>{Ci.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function gc(e,t){return new hc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Pt(t)}})}const _c=D(`ZodNonOptional`,(e,t)=>{wi.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function vc(e,t){return new _c({type:`nonoptional`,innerType:e,...O(t)})}const yc=D(`ZodCatch`,(e,t)=>{Ei.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function bc(e,t){return new yc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const xc=D(`ZodPipe`,(e,t)=>{Di.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r),e.in=t.in,e.out=t.out});function Sc(e,t){return new xc({type:`pipe`,in:e,out:t})}const Cc=D(`ZodReadonly`,(e,t)=>{ki.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function wc(e){return new Cc({type:`readonly`,innerType:e})}const Tc=D(`ZodCustom`,(e,t)=>{ji.init(e,t),ls.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vo(e,t,n,r)});function Ec(e,t){return za(Tc,e??(()=>!0),t)}function Dc(e,t={}){return Ba(Tc,e,t)}function Oc(e){return Va(e)}function kc(e,t){return Sc(oc(e),t)}var Ac=ft();a();const jc=Symbol.for(`@inkeep/open-knowledge/field-registry`),Mc=globalThis;Mc[jc]===void 0&&(Mc[jc]=Fi());const Nc=Mc[jc];function Pc(e){let t=e;for(let e=0;e<16;e++){if(t==null)return;let e=Fc(t)?Nc.get(t):void 0;if(e!==void 0)return e;let n=t._zod?.def?.innerType;if(n===void 0)return;t=n}}function Fc(e){return typeof e==`object`&&!!e&&`_zod`in e&&`parse`in e}const Ic=Object.freeze([`authorization`,`auth.token`,`auth.bearer`,`cookie`,`set-cookie`,`x-api-key`,`password`,`secret`]),Lc=52428800,Rc=26214400,zc=Js({content:Js({dir:k().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Folder Open Knowledge reads and writes documents under, relative to the project root (the folder that contains .ok/). Defaults to the project root. Exclude paths with .okignore.`}).default(`.`)}).default({dir:`.`}),appearance:Js({theme:N([`light`,`dark`,`system`]).register(Nc,{scope:`user`,agentSettable:!1,defaultScope:`user`,description:`Editor color theme: 'light', 'dark', or 'system' (follow the OS). A personal preference (user scope) — not shared with the project.`}).optional(),preview:Js({autoOpen:Ls().register(Nc,{scope:`user`,agentSettable:!1,defaultScope:`user`,description:`When on, the agent opens or refreshes the live preview after each edit. Turn off if you manage your own preview window. A personal preference (user scope).`}).default(!0)}).default({autoOpen:!0}),sidebar:Js({showHiddenFiles:Ls().register(Nc,{scope:`project-local`,agentSettable:!1,defaultScope:`project-local`,description:`Show dot-prefixed entries (e.g. .ok/, .okignore) in the file tree. Per-machine (project-local) — not shared with collaborators.`}).default(!1),showAllFiles:Ls().register(Nc,{scope:`project-local`,agentSettable:!1,defaultScope:`project-local`,description:`Show every file, including those excluded by .gitignore / .okignore. Per-machine (project-local) — not shared.`}).default(!1)}).optional()}).default({preview:{autoOpen:!0}}),editor:Js({wordWrap:Ls().register(Nc,{scope:`user`,agentSettable:!1,defaultScope:`user`,description:`Soft-wrap long lines in the source (CodeMirror) editor. A personal preference (user scope).`}).default(!0)}).default({wordWrap:!0}),autoSync:Js({enabled:Ls().register(Nc,{scope:`project-local`,agentSettable:!1,defaultScope:`project-local`,description:`Whether this machine auto-pulls and auto-pushes git commits for this project. null = not chosen yet (onboarding asks). Per-machine (project-local) — not shared.`}).nullable().default(null)}).default({enabled:null}),telemetry:Js({localSink:Js({enabled:Ls().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:"Write local diagnostic spans + logs under .ok/local/ for `ok diagnose bundle`. Local-only — never leaves the machine until you run bundle. Set false for sensitive workspaces. Shared across collaborators."}).default(!0),spans:Js({maxBytes:A().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Maximum size, in bytes, of the local diagnostic spans file before it rotates (default ~50 MB).`}).default(Lc)}).default({maxBytes:Lc}),logs:Js({maxBytes:A().register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Maximum size, in bytes, of the local diagnostic logs file before it rotates (default ~25 MB).`}).default(Rc)}).default({maxBytes:Rc}),attributeDenylist:j(k()).register(Nc,{scope:`project`,agentSettable:!1,defaultScope:`project`,description:`Telemetry attribute keys whose values are redacted before any local span/log is written (credential / secret guard). Extends the built-in denylist.`}).default([...Ic])}).default({enabled:!0,spans:{maxBytes:Lc},logs:{maxBytes:Rc},attributeDenylist:[...Ic]})}).default({localSink:{enabled:!0,spans:{maxBytes:Lc},logs:{maxBytes:Rc},attributeDenylist:[...Ic]}})}),Bc=`open-knowledge-config`;async function Vc(e,t,n){let r=o.getTracer(Bc),a=t?{attributes:t}:{};return r.startActiveSpan(e,a,async e=>{try{return await n(e)}catch(t){throw e.recordException(t),e.setStatus({code:i.ERROR,message:t instanceof Error?t.message:String(t)}),t}finally{e.end()}})}function Hc(e,t,n){let r=o.getTracer(Bc),a=t?{attributes:t}:{};return r.startActiveSpan(e,a,e=>{try{return n(e)}catch(t){throw e.recordException(t),e.setStatus({code:i.ERROR,message:t instanceof Error?t.message:String(t)}),t}finally{e.end()}})}function Uc(e,t){let n=o.getActiveSpan();n&&n.addEvent(e,t)}function Wc(e){let t=e;for(let e=0;e<16;e++){if(t==null||t?._zod?.def?.shape!==void 0)return t;let e=t?._zod?.def?.innerType;if(e===void 0)return t;t=e}return t}function Gc(e,t){let n=e;for(let e of t){n=Wc(n);let t=n?._zod?.def?.shape;if(!t||(n=t[String(e)],n===void 0))return}return n}function Kc(e,t){let n=Gc(e,t);if(n!==void 0)return Pc(n)}function qc(e,t){return e===`either`?!0:e===t}function Jc(e,t){let n=null;function r(e,i){if(n!==null||e===void 0)return;if(typeof e==`object`&&e&&!Array.isArray(e)){for(let[t,a]of Object.entries(e))if(r(a,[...i,t]),n!==null)return;return}let a=Kc(zc,i);a?.scope!==void 0&&(qc(a.scope,t)||(n={code:`SCOPE_VIOLATION`,path:i,expectedScope:a.scope,actualScope:t}))}for(let[t,i]of Object.entries(e))if(r(i,[t]),n!==null)break;return n}function Yc(e,t){for(let n=1;n<t.length;n++){let r=t.slice(0,n);e.hasIn(r)&&((0,Ac.isCollection)(e.getIn(r,!0))||e.deleteIn(r))}}function Xc(e,t){let n=[];function r(t,i){if(t!==void 0){if(t===null){e.deleteIn(i),n.push(i.join(`.`));return}if(Array.isArray(t)){Yc(e,i),e.setIn(i,t),n.push(i.join(`.`));return}if(typeof t==`object`){for(let[e,n]of Object.entries(t))r(n,[...i,e]);return}Yc(e,i),e.setIn(i,t),n.push(i.join(`.`))}}for(let[e,n]of Object.entries(t))r(n,[e]);return n}function Zc(e){return{path:e.path.map(e=>typeof e==`symbol`?String(e):e),message:e.message,issueCode:e.code}}const Qc=M({file:k(),line:A().int().min(1),column:A().int().min(1),snippet:k().optional()}),$c=M({path:j(Xs([k(),A()])),message:k(),issueCode:k(),params:nc(k(),Us()).optional(),source:Qc.optional()}),el=N([`user`,`project`,`project-local`,`either`]),tl=N([`user`,`project`,`project-local`]),nl=Qs(`code`,[M({code:P(`YAML_PARSE`),detail:k()}),M({code:P(`SCHEMA_INVALID`),issues:j($c)}),M({code:P(`SCOPE_VIOLATION`),path:j(k()),expectedScope:el,actualScope:tl}),M({code:P(`NOT_AGENT_SETTABLE`),path:j(k())}),M({code:P(`MIXED_SCOPE`),paths:j(M({path:j(k()),scope:tl}))}),M({code:P(`REMOVED_KEY`),path:j(k()),redirect:k(),source:Qc.optional()}),M({code:P(`WRITE_ERROR`),detail:k()}),M({code:P(`OKIGNORE_INVALID`),detail:k(),lineNumber:A().int().min(1).optional()}),M({code:P(`UNKNOWN`),message:k().optional()})]),rl=new Set(nl.options.map(e=>e.shape.code.value)),il=Xs([nl,Js({code:k(),message:k().optional()})]);function al(e){return rl.has(e.code)}function ol(e){switch(e){case`user`:return`~/.ok/global.yml`;case`project`:return`.ok/config.yml`;case`project-local`:return`.ok/local/config.yml`;case`either`:return`.ok/config.yml or ~/.ok/global.yml`}}function sl(e){switch(e){case`user`:return`personal to you, across all projects`;case`project`:return`shared with your team via git`;case`project-local`:return`this machine only, not shared`;case`either`:return`user or project`}}function cl(e){if(!al(e))return e.message??`Unknown error (${e.code}).`;switch(e.code){case`YAML_PARSE`:return`Failed to parse YAML: ${e.detail}`;case`SCHEMA_INVALID`:{if(e.issues.length===0)return`Invalid configuration.`;let t=new Map;for(let n of e.issues){let e=n.source?.file??`<no source>`,r=t.get(e)??[];r.push(n),t.set(e,r)}let n=[];for(let[e,r]of t){e===`<no source>`?n.push(`Invalid configuration:`):n.push(`Invalid configuration at ${e}:`);for(let t of r){let r=t.path.length===0?`<root>`:t.path.join(`.`);if(t.source){if(n.push(` ${e}:${t.source.line}:${t.source.column}`),n.push(` ${r}: ${t.message}`),t.source.snippet&&t.source.snippet.length>0)for(let e of t.source.snippet.split(`
|
|
155
155
|
`))n.push(` ${e}`)}else n.push(` ${r}: ${t.message}`)}}return n.join(`
|
|
156
156
|
`)}case`SCOPE_VIOLATION`:return[`Setting ${e.path.join(`.`)} belongs in your ${e.expectedScope} config`,`(${ol(e.expectedScope)} — ${sl(e.expectedScope)}),`,`but it was set in the ${e.actualScope} config (${ol(e.actualScope)}).`,`Move it to ${ol(e.expectedScope)}.`].join(` `);case`NOT_AGENT_SETTABLE`:return[`Setting ${e.path.join(`.`)} is human-only and can't be changed by an agent.`,`Change it in the Settings pane, or edit the config.yml by hand.`].join(` `);case`MIXED_SCOPE`:return[`This change touches settings that live in different config files. Apply them one file at a time:`,e.paths.map(({path:e,scope:t})=>` ${e.join(`.`)} → ${ol(t)} (${t})`).join(`
|
|
157
157
|
`)].join(`
|
|
@@ -159,7 +159,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
159
159
|
`))n.push(` ${t}`);return n.join(`
|
|
160
160
|
`)}case`WRITE_ERROR`:return`Failed to write config file: ${e.detail}`;case`OKIGNORE_INVALID`:return e.lineNumber===void 0?`.okignore: ${e.detail}`:`.okignore line ${e.lineNumber}: ${e.detail}`;case`UNKNOWN`:return e.message??`Unknown error.`}}function ll(e,t){if(t.length===0)return e.contents??null;let n=e.getIn(t,!0);if((0,Ac.isNode)(n))return n;for(let n=t.length-1;n>=0;n--){let r=e.getIn(t.slice(0,n),!0);if((0,Ac.isNode)(r))return r}return e.contents??null}function ul(e,t){let n=1,r=1,i=Math.min(t,e.length);for(let t=0;t<i;t++)e.charCodeAt(t)===10?(n++,r=1):r++;return{line:n,column:r}}function dl(e,t,n,r,i){let a=e.split(`
|
|
161
161
|
`),o=r-1;if(o<0||o>=a.length)return``;let s=a[o]??``,c=t-(i-1)+s.length,l=Math.max(1,Math.min(n,c)-t),u=[],d=String(o+2).length;for(let e=Math.max(0,o-1);e<=Math.min(a.length-1,o+1);e++){let t=e===o,n=t?`>`:` `,r=String(e+1).padStart(d,` `);if(u.push(`${n} ${r} | ${a[e]??``}`),t){let e=` `.repeat(2+d+3+i-1);u.push(`${e}${`^`.repeat(l)}`)}}return u.join(`
|
|
162
|
-
`)}function fl(e){let t=ll(e.doc,e.path);if(!t)return;let n=t.range;if(!n)return;let[r,,i=r]=n,{line:a,column:o}=ul(e.source,r),s=(0,Ac.isCollection)(t)?dl(e.source,r,r+1,a,o):dl(e.source,r,i,a,o);return{file:e.file,line:a,column:o,snippet:s.length>0?s:void 0}}const pl="Run `ok config migrate` to strip the obsolete key from config.yml automatically, or remove it by hand.",ml=[{path:[`content`,`include`],redirect:[`content.include has been removed.`,`For subdirectory scoping, set content.dir in .ok/config.yml instead.`,`For pattern-based filtering, use .okignore (gitignore syntax — exclude-only; do not copy include patterns directly).`,pl].join(` `)},{path:[`content`,`exclude`],redirect:[`Move these patterns to .okignore at the project root (gitignore syntax, 1:1 migration).`,pl].join(` `)},{path:[`folders`],redirect:[`folders is no longer a top-level config field.`,"A folder's own frontmatter (open-shape, like a doc's) lives in nested `<folder>/.ok/frontmatter.yml`; new-doc starting properties come from templates in `<folder>/.ok/templates/`.","Edit via the folder overview in the editor sidebar, or `edit({ folder: { path, frontmatter } })` via the MCP.",pl].join(` `)},{path:[`appearance`,`editorModeDefault`],redirect:[`appearance.editorModeDefault was removed and is never read — new docs always open in WYSIWYG; toggle mode via the editor mode button.`,pl].join(` `)},{path:[`upload`,`maxBytes`],redirect:[`streaming uploads have no user-facing cap; the value is hardcoded in @inkeep/open-knowledge-core.`,pl].join(` `)},{path:[`github`,`oauthAppClientId`],redirect:[`Use the OPEN_KNOWLEDGE_GITHUB_CLIENT_ID environment variable instead.`,pl].join(` `)},{path:[`server`,`host`],redirect:[`Use the --host CLI flag or the HOST environment variable instead.`,pl].join(` `)},{path:[`server`,`openOnAgentEdit`],redirect:[`This behavior was removed; the value is hardcoded.`,pl].join(` `)},{path:[`mcp`,`autoStart`],redirect:[`To disable MCP auto-start, set OK_MCP_AUTOSTART=0.`,pl].join(` `)},{path:[`mcp`,`tools`,`read_document`,`historyDepth`],redirect:[`This value is hardcoded in @inkeep/open-knowledge-core.`,pl].join(` `)},{path:[`mcp`,`tools`,`grep`,`maxResults`],redirect:[`This value is hardcoded in @inkeep/open-knowledge-core.`,pl].join(` `)},{path:[`mcp`,`tools`,`search`,`maxResults`],redirect:[`The search result cap is hardcoded in @inkeep/open-knowledge-core; this config key was removed.`,pl].join(` `)},{path:[`preview`,`baseUrl`],redirect:["preview URLs now resolve only to the running UI process — start one with `ok ui`.",pl].join(` `)}];function hl(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gl(e,t){let n=e;for(let e=0;e<t.length-1;e++){if(!hl(n))return!1;n=n[t[e]]}return hl(n)?t[t.length-1]in n:!1}function _l(e){let{value:t,file:n,source:r,doc:i}=e;if(!hl(t))return[];let a=[];for(let e of ml){if(!gl(t,e.path))continue;let o;i!=null&&r!=null&&n!=null&&(o=fl({file:n,source:r,doc:i,path:e.path})),a.push({code:`REMOVED_KEY`,path:e.path,redirect:e.redirect,...o===void 0?{}:{source:o}})}return a}const vl=`v0`,yl=`.ok/config.yml`,bl=`local`;function xl(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?Cl(e.position):`start`in e||`end`in e?Cl(e):`line`in e||`column`in e?Sl(e):``}function Sl(e){return wl(e&&e.line)+`:`+wl(e&&e.column)}function Cl(e){return Sl(e&&e.start)+`-`+Sl(e&&e.end)}function wl(e){return e&&typeof e==`number`?e:1}var Tl=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=xl(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};Tl.prototype.file=``,Tl.prototype.name=``,Tl.prototype.reason=``,Tl.prototype.message=``,Tl.prototype.stack=``,Tl.prototype.column=void 0,Tl.prototype.line=void 0,Tl.prototype.ancestors=void 0,Tl.prototype.cause=void 0,Tl.prototype.fatal=void 0,Tl.prototype.place=void 0,Tl.prototype.ruleId=void 0,Tl.prototype.source=void 0;var El=r(((e,t)=>{var n=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},r=-1,i=1,a=0;n.Diff=function(e,t){return[e,t]},n.prototype.diff_main=function(e,t,r,i){i===void 0&&(i=this.Diff_Timeout<=0?Number.MAX_VALUE:new Date().getTime()+this.Diff_Timeout*1e3);var o=i;if(e==null||t==null)throw Error(`Null input. (diff_main)`);if(e==t)return e?[new n.Diff(a,e)]:[];r===void 0&&(r=!0);var s=r,c=this.diff_commonPrefix(e,t),l=e.substring(0,c);e=e.substring(c),t=t.substring(c),c=this.diff_commonSuffix(e,t);var u=e.substring(e.length-c);e=e.substring(0,e.length-c),t=t.substring(0,t.length-c);var d=this.diff_compute_(e,t,s,o);return l&&d.unshift(new n.Diff(a,l)),u&&d.push(new n.Diff(a,u)),this.diff_cleanupMerge(d),d},n.prototype.diff_compute_=function(e,t,o,s){var c;if(!e)return[new n.Diff(i,t)];if(!t)return[new n.Diff(r,e)];var l=e.length>t.length?e:t,u=e.length>t.length?t:e,d=l.indexOf(u);if(d!=-1)return c=[new n.Diff(i,l.substring(0,d)),new n.Diff(a,u),new n.Diff(i,l.substring(d+u.length))],e.length>t.length&&(c[0][0]=c[2][0]=r),c;if(u.length==1)return[new n.Diff(r,e),new n.Diff(i,t)];var f=this.diff_halfMatch_(e,t);if(f){var p=f[0],m=f[1],h=f[2],g=f[3],_=f[4],v=this.diff_main(p,h,o,s),y=this.diff_main(m,g,o,s);return v.concat([new n.Diff(a,_)],y)}return o&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,s):this.diff_bisect_(e,t,s)},n.prototype.diff_lineMode_=function(e,t,o){var s=this.diff_linesToChars_(e,t);e=s.chars1,t=s.chars2;var c=s.lineArray,l=this.diff_main(e,t,!1,o);this.diff_charsToLines_(l,c),this.diff_cleanupSemantic(l),l.push(new n.Diff(a,``));for(var u=0,d=0,f=0,p=``,m=``;u<l.length;){switch(l[u][0]){case i:f++,m+=l[u][1];break;case r:d++,p+=l[u][1];break;case a:if(d>=1&&f>=1){l.splice(u-d-f,d+f),u=u-d-f;for(var h=this.diff_main(p,m,!1,o),g=h.length-1;g>=0;g--)l.splice(u,0,h[g]);u+=h.length}f=0,d=0,p=``,m=``;break}u++}return l.pop(),l},n.prototype.diff_bisect_=function(e,t,a){for(var o=e.length,s=t.length,c=Math.ceil((o+s)/2),l=c,u=2*c,d=Array(u),f=Array(u),p=0;p<u;p++)d[p]=-1,f[p]=-1;d[l+1]=0,f[l+1]=0;for(var m=o-s,h=m%2!=0,g=0,_=0,v=0,y=0,b=0;b<c&&!(new Date().getTime()>a);b++){for(var x=-b+g;x<=b-_;x+=2){for(var S=l+x,C=x==-b||x!=b&&d[S-1]<d[S+1]?d[S+1]:d[S-1]+1,w=C-x;C<o&&w<s&&e.charAt(C)==t.charAt(w);)C++,w++;if(d[S]=C,C>o)_+=2;else if(w>s)g+=2;else if(h){var T=l+m-x;if(T>=0&&T<u&&f[T]!=-1){var E=o-f[T];if(C>=E)return this.diff_bisectSplit_(e,t,C,w,a)}}}for(var ee=-b+v;ee<=b-y;ee+=2){for(var T=l+ee,E=ee==-b||ee!=b&&f[T-1]<f[T+1]?f[T+1]:f[T-1]+1,te=E-ee;E<o&&te<s&&e.charAt(o-E-1)==t.charAt(s-te-1);)E++,te++;if(f[T]=E,E>o)y+=2;else if(te>s)v+=2;else if(!h){var S=l+m-ee;if(S>=0&&S<u&&d[S]!=-1){var C=d[S],w=l+C-S;if(E=o-E,C>=E)return this.diff_bisectSplit_(e,t,C,w,a)}}}}return[new n.Diff(r,e),new n.Diff(i,t)]},n.prototype.diff_bisectSplit_=function(e,t,n,r,i){var a=e.substring(0,n),o=t.substring(0,r),s=e.substring(n),c=t.substring(r),l=this.diff_main(a,o,!1,i),u=this.diff_main(s,c,!1,i);return l.concat(u)},n.prototype.diff_linesToChars_=function(e,t){var n=[],r={};n[0]=``;function i(e){for(var t=``,i=0,o=-1,s=n.length;o<e.length-1;){o=e.indexOf(`
|
|
162
|
+
`)}function fl(e){let t=ll(e.doc,e.path);if(!t)return;let n=t.range;if(!n)return;let[r,,i=r]=n,{line:a,column:o}=ul(e.source,r),s=(0,Ac.isCollection)(t)?dl(e.source,r,r+1,a,o):dl(e.source,r,i,a,o);return{file:e.file,line:a,column:o,snippet:s.length>0?s:void 0}}const pl="Run `ok config migrate` to strip the obsolete key from config.yml automatically, or remove it by hand.",ml=[{path:[`content`,`include`],redirect:[`content.include has been removed.`,`For subdirectory scoping, set content.dir in .ok/config.yml instead.`,`For pattern-based filtering, use .okignore (gitignore syntax — exclude-only; do not copy include patterns directly).`,pl].join(` `)},{path:[`content`,`exclude`],redirect:[`Move these patterns to .okignore at the project root (gitignore syntax, 1:1 migration).`,pl].join(` `)},{path:[`folders`],redirect:[`folders is no longer a top-level config field.`,"A folder's own frontmatter (open-shape, like a doc's) lives in nested `<folder>/.ok/frontmatter.yml`; new-doc starting properties come from templates in `<folder>/.ok/templates/`.","Edit via the folder overview in the editor sidebar, or `edit({ folder: { path, frontmatter } })` via the MCP.",pl].join(` `)},{path:[`appearance`,`editorModeDefault`],redirect:[`appearance.editorModeDefault was removed and is never read — new docs always open in WYSIWYG; toggle mode via the editor mode button.`,pl].join(` `)},{path:[`upload`,`maxBytes`],redirect:[`streaming uploads have no user-facing cap; the value is hardcoded in @inkeep/open-knowledge-core.`,pl].join(` `)},{path:[`github`,`oauthAppClientId`],redirect:[`Use the OPEN_KNOWLEDGE_GITHUB_CLIENT_ID environment variable instead.`,pl].join(` `)},{path:[`server`,`host`],redirect:[`Use the --host CLI flag or the HOST environment variable instead.`,pl].join(` `)},{path:[`server`,`openOnAgentEdit`],redirect:[`This behavior was removed; the value is hardcoded.`,pl].join(` `)},{path:[`mcp`,`autoStart`],redirect:[`To disable MCP auto-start, set OK_MCP_AUTOSTART=0.`,pl].join(` `)},{path:[`mcp`,`tools`,`read_document`,`historyDepth`],redirect:[`This value is hardcoded in @inkeep/open-knowledge-core.`,pl].join(` `)},{path:[`mcp`,`tools`,`grep`,`maxResults`],redirect:[`This value is hardcoded in @inkeep/open-knowledge-core.`,pl].join(` `)},{path:[`mcp`,`tools`,`search`,`maxResults`],redirect:[`The search result cap is hardcoded in @inkeep/open-knowledge-core; this config key was removed.`,pl].join(` `)},{path:[`preview`,`baseUrl`],redirect:["preview URLs now resolve only to the running UI process — start one with `ok ui`.",pl].join(` `)},{path:[`preview`,`scriptSrc`],redirect:[`preview.scriptSrc has been removed.`,`The code-block preview iframe now runs a fixed open network policy (it is no longer configurable).`,pl].join(` `)}];function hl(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gl(e,t){let n=e;for(let e=0;e<t.length-1;e++){if(!hl(n))return!1;n=n[t[e]]}return hl(n)?t[t.length-1]in n:!1}function _l(e){let{value:t,file:n,source:r,doc:i}=e;if(!hl(t))return[];let a=[];for(let e of ml){if(!gl(t,e.path))continue;let o;i!=null&&r!=null&&n!=null&&(o=fl({file:n,source:r,doc:i,path:e.path})),a.push({code:`REMOVED_KEY`,path:e.path,redirect:e.redirect,...o===void 0?{}:{source:o}})}return a}const vl=`v0`,yl=`.ok/config.yml`,bl=`local`;function xl(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?Cl(e.position):`start`in e||`end`in e?Cl(e):`line`in e||`column`in e?Sl(e):``}function Sl(e){return wl(e&&e.line)+`:`+wl(e&&e.column)}function Cl(e){return Sl(e&&e.start)+`-`+Sl(e&&e.end)}function wl(e){return e&&typeof e==`number`?e:1}var Tl=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=xl(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};Tl.prototype.file=``,Tl.prototype.name=``,Tl.prototype.reason=``,Tl.prototype.message=``,Tl.prototype.stack=``,Tl.prototype.column=void 0,Tl.prototype.line=void 0,Tl.prototype.ancestors=void 0,Tl.prototype.cause=void 0,Tl.prototype.fatal=void 0,Tl.prototype.place=void 0,Tl.prototype.ruleId=void 0,Tl.prototype.source=void 0;var El=r(((e,t)=>{var n=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},r=-1,i=1,a=0;n.Diff=function(e,t){return[e,t]},n.prototype.diff_main=function(e,t,r,i){i===void 0&&(i=this.Diff_Timeout<=0?Number.MAX_VALUE:new Date().getTime()+this.Diff_Timeout*1e3);var o=i;if(e==null||t==null)throw Error(`Null input. (diff_main)`);if(e==t)return e?[new n.Diff(a,e)]:[];r===void 0&&(r=!0);var s=r,c=this.diff_commonPrefix(e,t),l=e.substring(0,c);e=e.substring(c),t=t.substring(c),c=this.diff_commonSuffix(e,t);var u=e.substring(e.length-c);e=e.substring(0,e.length-c),t=t.substring(0,t.length-c);var d=this.diff_compute_(e,t,s,o);return l&&d.unshift(new n.Diff(a,l)),u&&d.push(new n.Diff(a,u)),this.diff_cleanupMerge(d),d},n.prototype.diff_compute_=function(e,t,o,s){var c;if(!e)return[new n.Diff(i,t)];if(!t)return[new n.Diff(r,e)];var l=e.length>t.length?e:t,u=e.length>t.length?t:e,d=l.indexOf(u);if(d!=-1)return c=[new n.Diff(i,l.substring(0,d)),new n.Diff(a,u),new n.Diff(i,l.substring(d+u.length))],e.length>t.length&&(c[0][0]=c[2][0]=r),c;if(u.length==1)return[new n.Diff(r,e),new n.Diff(i,t)];var f=this.diff_halfMatch_(e,t);if(f){var p=f[0],m=f[1],h=f[2],g=f[3],_=f[4],v=this.diff_main(p,h,o,s),y=this.diff_main(m,g,o,s);return v.concat([new n.Diff(a,_)],y)}return o&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,s):this.diff_bisect_(e,t,s)},n.prototype.diff_lineMode_=function(e,t,o){var s=this.diff_linesToChars_(e,t);e=s.chars1,t=s.chars2;var c=s.lineArray,l=this.diff_main(e,t,!1,o);this.diff_charsToLines_(l,c),this.diff_cleanupSemantic(l),l.push(new n.Diff(a,``));for(var u=0,d=0,f=0,p=``,m=``;u<l.length;){switch(l[u][0]){case i:f++,m+=l[u][1];break;case r:d++,p+=l[u][1];break;case a:if(d>=1&&f>=1){l.splice(u-d-f,d+f),u=u-d-f;for(var h=this.diff_main(p,m,!1,o),g=h.length-1;g>=0;g--)l.splice(u,0,h[g]);u+=h.length}f=0,d=0,p=``,m=``;break}u++}return l.pop(),l},n.prototype.diff_bisect_=function(e,t,a){for(var o=e.length,s=t.length,c=Math.ceil((o+s)/2),l=c,u=2*c,d=Array(u),f=Array(u),p=0;p<u;p++)d[p]=-1,f[p]=-1;d[l+1]=0,f[l+1]=0;for(var m=o-s,h=m%2!=0,g=0,_=0,v=0,y=0,b=0;b<c&&!(new Date().getTime()>a);b++){for(var x=-b+g;x<=b-_;x+=2){for(var S=l+x,C=x==-b||x!=b&&d[S-1]<d[S+1]?d[S+1]:d[S-1]+1,w=C-x;C<o&&w<s&&e.charAt(C)==t.charAt(w);)C++,w++;if(d[S]=C,C>o)_+=2;else if(w>s)g+=2;else if(h){var T=l+m-x;if(T>=0&&T<u&&f[T]!=-1){var E=o-f[T];if(C>=E)return this.diff_bisectSplit_(e,t,C,w,a)}}}for(var ee=-b+v;ee<=b-y;ee+=2){for(var T=l+ee,E=ee==-b||ee!=b&&f[T-1]<f[T+1]?f[T+1]:f[T-1]+1,te=E-ee;E<o&&te<s&&e.charAt(o-E-1)==t.charAt(s-te-1);)E++,te++;if(f[T]=E,E>o)y+=2;else if(te>s)v+=2;else if(!h){var S=l+m-ee;if(S>=0&&S<u&&d[S]!=-1){var C=d[S],w=l+C-S;if(E=o-E,C>=E)return this.diff_bisectSplit_(e,t,C,w,a)}}}}return[new n.Diff(r,e),new n.Diff(i,t)]},n.prototype.diff_bisectSplit_=function(e,t,n,r,i){var a=e.substring(0,n),o=t.substring(0,r),s=e.substring(n),c=t.substring(r),l=this.diff_main(a,o,!1,i),u=this.diff_main(s,c,!1,i);return l.concat(u)},n.prototype.diff_linesToChars_=function(e,t){var n=[],r={};n[0]=``;function i(e){for(var t=``,i=0,o=-1,s=n.length;o<e.length-1;){o=e.indexOf(`
|
|
163
163
|
`,i),o==-1&&(o=e.length-1);var c=e.substring(i,o+1);(r.hasOwnProperty?r.hasOwnProperty(c):r[c]!==void 0)?t+=String.fromCharCode(r[c]):(s==a&&(c=e.substring(i),o=e.length),t+=String.fromCharCode(s),r[c]=s,n[s++]=c),i=o+1}return t}var a=4e4,o=i(e);return a=65535,{chars1:o,chars2:i(t),lineArray:n}},n.prototype.diff_charsToLines_=function(e,t){for(var n=0;n<e.length;n++){for(var r=e[n][1],i=[],a=0;a<r.length;a++)i[a]=t[r.charCodeAt(a)];e[n][1]=i.join(``)}},n.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var n=0,r=Math.min(e.length,t.length),i=r,a=0;n<i;)e.substring(a,i)==t.substring(a,i)?(n=i,a=n):r=i,i=Math.floor((r-n)/2+n);return i},n.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var n=0,r=Math.min(e.length,t.length),i=r,a=0;n<i;)e.substring(e.length-i,e.length-a)==t.substring(t.length-i,t.length-a)?(n=i,a=n):r=i,i=Math.floor((r-n)/2+n);return i},n.prototype.diff_commonOverlap_=function(e,t){var n=e.length,r=t.length;if(n==0||r==0)return 0;n>r?e=e.substring(n-r):n<r&&(t=t.substring(0,n));var i=Math.min(n,r);if(e==t)return i;for(var a=0,o=1;;){var s=e.substring(i-o),c=t.indexOf(s);if(c==-1)return a;o+=c,(c==0||e.substring(i-o)==t.substring(0,o))&&(a=o,o++)}},n.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var n=e.length>t.length?e:t,r=e.length>t.length?t:e;if(n.length<4||r.length*2<n.length)return null;var i=this;function a(e,t,n){for(var r=e.substring(n,n+Math.floor(e.length/4)),a=-1,o=``,s,c,l,u;(a=t.indexOf(r,a+1))!=-1;){var d=i.diff_commonPrefix(e.substring(n),t.substring(a)),f=i.diff_commonSuffix(e.substring(0,n),t.substring(0,a));o.length<f+d&&(o=t.substring(a-f,a)+t.substring(a,a+d),s=e.substring(0,n-f),c=e.substring(n+d),l=t.substring(0,a-f),u=t.substring(a+d))}return o.length*2>=e.length?[s,c,l,u,o]:null}var o=a(n,r,Math.ceil(n.length/4)),s=a(n,r,Math.ceil(n.length/2)),c;if(!o&&!s)return null;c=s?o&&o[4].length>s[4].length?o:s:o;var l,u,d,f;e.length>t.length?(l=c[0],u=c[1],d=c[2],f=c[3]):(d=c[0],f=c[1],l=c[2],u=c[3]);var p=c[4];return[l,u,d,f,p]},n.prototype.diff_cleanupSemantic=function(e){for(var t=!1,o=[],s=0,c=null,l=0,u=0,d=0,f=0,p=0;l<e.length;)e[l][0]==a?(o[s++]=l,u=f,d=p,f=0,p=0,c=e[l][1]):(e[l][0]==i?f+=e[l][1].length:p+=e[l][1].length,c&&c.length<=Math.max(u,d)&&c.length<=Math.max(f,p)&&(e.splice(o[s-1],0,new n.Diff(r,c)),e[o[s-1]+1][0]=i,s--,s--,l=s>0?o[s-1]:-1,u=0,d=0,f=0,p=0,c=null,t=!0)),l++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),l=1;l<e.length;){if(e[l-1][0]==r&&e[l][0]==i){var m=e[l-1][1],h=e[l][1],g=this.diff_commonOverlap_(m,h),_=this.diff_commonOverlap_(h,m);g>=_?(g>=m.length/2||g>=h.length/2)&&(e.splice(l,0,new n.Diff(a,h.substring(0,g))),e[l-1][1]=m.substring(0,m.length-g),e[l+1][1]=h.substring(g),l++):(_>=m.length/2||_>=h.length/2)&&(e.splice(l,0,new n.Diff(a,m.substring(0,_))),e[l-1][0]=i,e[l-1][1]=h.substring(0,h.length-_),e[l+1][0]=r,e[l+1][1]=m.substring(_),l++),l++}l++}},n.prototype.diff_cleanupSemanticLossless=function(e){function t(e,t){if(!e||!t)return 6;var r=e.charAt(e.length-1),i=t.charAt(0),a=r.match(n.nonAlphaNumericRegex_),o=i.match(n.nonAlphaNumericRegex_),s=a&&r.match(n.whitespaceRegex_),c=o&&i.match(n.whitespaceRegex_),l=s&&r.match(n.linebreakRegex_),u=c&&i.match(n.linebreakRegex_),d=l&&e.match(n.blanklineEndRegex_),f=u&&t.match(n.blanklineStartRegex_);return d||f?5:l||u?4:a&&!s&&c?3:s||c?2:a||o?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==a&&e[r+1][0]==a){var i=e[r-1][1],o=e[r][1],s=e[r+1][1],c=this.diff_commonSuffix(i,o);if(c){var l=o.substring(o.length-c);i=i.substring(0,i.length-c),o=l+o.substring(0,o.length-c),s=l+s}for(var u=i,d=o,f=s,p=t(i,o)+t(o,s);o.charAt(0)===s.charAt(0);){i+=o.charAt(0),o=o.substring(1)+s.charAt(0),s=s.substring(1);var m=t(i,o)+t(o,s);m>=p&&(p=m,u=i,d=o,f=s)}e[r-1][1]!=u&&(u?e[r-1][1]=u:(e.splice(r-1,1),r--),e[r][1]=d,f?e[r+1][1]=f:(e.splice(r+1,1),r--))}r++}},n.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,n.whitespaceRegex_=/\s/,n.linebreakRegex_=/[\r\n]/,n.blanklineEndRegex_=/\n\r?\n$/,n.blanklineStartRegex_=/^\r?\n\r?\n/,n.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,o=[],s=0,c=null,l=0,u=!1,d=!1,f=!1,p=!1;l<e.length;)e[l][0]==a?(e[l][1].length<this.Diff_EditCost&&(f||p)?(o[s++]=l,u=f,d=p,c=e[l][1]):(s=0,c=null),f=p=!1):(e[l][0]==r?p=!0:f=!0,c&&(u&&d&&f&&p||c.length<this.Diff_EditCost/2&&u+d+f+p==3)&&(e.splice(o[s-1],0,new n.Diff(r,c)),e[o[s-1]+1][0]=i,s--,c=null,u&&d?(f=p=!0,s=0):(s--,l=s>0?o[s-1]:-1,f=p=!1),t=!0)),l++;t&&this.diff_cleanupMerge(e)},n.prototype.diff_cleanupMerge=function(e){e.push(new n.Diff(a,``));for(var t=0,o=0,s=0,c=``,l=``,u;t<e.length;)switch(e[t][0]){case i:s++,l+=e[t][1],t++;break;case r:o++,c+=e[t][1],t++;break;case a:o+s>1?(o!==0&&s!==0&&(u=this.diff_commonPrefix(l,c),u!==0&&(t-o-s>0&&e[t-o-s-1][0]==a?e[t-o-s-1][1]+=l.substring(0,u):(e.splice(0,0,new n.Diff(a,l.substring(0,u))),t++),l=l.substring(u),c=c.substring(u)),u=this.diff_commonSuffix(l,c),u!==0&&(e[t][1]=l.substring(l.length-u)+e[t][1],l=l.substring(0,l.length-u),c=c.substring(0,c.length-u))),t-=o+s,e.splice(t,o+s),c.length&&(e.splice(t,0,new n.Diff(r,c)),t++),l.length&&(e.splice(t,0,new n.Diff(i,l)),t++),t++):t!==0&&e[t-1][0]==a?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,s=0,o=0,c=``,l=``;break}e[e.length-1][1]===``&&e.pop();var d=!1;for(t=1;t<e.length-1;)e[t-1][0]==a&&e[t+1][0]==a&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),d=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),d=!0)),t++;d&&this.diff_cleanupMerge(e)},n.prototype.diff_xIndex=function(e,t){var n=0,a=0,o=0,s=0,c;for(c=0;c<e.length&&(e[c][0]!==i&&(n+=e[c][1].length),e[c][0]!==r&&(a+=e[c][1].length),!(n>t));c++)o=n,s=a;return e.length!=c&&e[c][0]===r?s:s+(t-o)},n.prototype.diff_prettyHtml=function(e){for(var t=[],n=/&/g,o=/</g,s=/>/g,c=/\n/g,l=0;l<e.length;l++){var u=e[l][0],d=e[l][1].replace(n,`&`).replace(o,`<`).replace(s,`>`).replace(c,`¶<br>`);switch(u){case i:t[l]=`<ins style="background:#e6ffe6;">`+d+`</ins>`;break;case r:t[l]=`<del style="background:#ffe6e6;">`+d+`</del>`;break;case a:t[l]=`<span>`+d+`</span>`;break}}return t.join(``)},n.prototype.diff_text1=function(e){for(var t=[],n=0;n<e.length;n++)e[n][0]!==i&&(t[n]=e[n][1]);return t.join(``)},n.prototype.diff_text2=function(e){for(var t=[],n=0;n<e.length;n++)e[n][0]!==r&&(t[n]=e[n][1]);return t.join(``)},n.prototype.diff_levenshtein=function(e){for(var t=0,n=0,o=0,s=0;s<e.length;s++){var c=e[s][0],l=e[s][1];switch(c){case i:n+=l.length;break;case r:o+=l.length;break;case a:t+=Math.max(n,o),n=0,o=0;break}}return t+=Math.max(n,o),t},n.prototype.diff_toDelta=function(e){for(var t=[],n=0;n<e.length;n++)switch(e[n][0]){case i:t[n]=`+`+encodeURI(e[n][1]);break;case r:t[n]=`-`+e[n][1].length;break;case a:t[n]=`=`+e[n][1].length;break}return t.join(` `).replace(/%20/g,` `)},n.prototype.diff_fromDelta=function(e,t){for(var o=[],s=0,c=0,l=t.split(/\t/g),u=0;u<l.length;u++){var d=l[u].substring(1);switch(l[u].charAt(0)){case`+`:try{o[s++]=new n.Diff(i,decodeURI(d))}catch{throw Error(`Illegal escape in diff_fromDelta: `+d)}break;case`-`:case`=`:var f=parseInt(d,10);if(isNaN(f)||f<0)throw Error(`Invalid number in diff_fromDelta: `+d);var p=e.substring(c,c+=f);l[u].charAt(0)==`=`?o[s++]=new n.Diff(a,p):o[s++]=new n.Diff(r,p);break;default:if(l[u])throw Error(`Invalid diff operation in diff_fromDelta: `+l[u])}}if(c!=e.length)throw Error(`Delta length (`+c+`) does not equal source text length (`+e.length+`).`);return o},n.prototype.match_main=function(e,t,n){if(e==null||t==null||n==null)throw Error(`Null input. (match_main)`);return n=Math.max(0,Math.min(n,e.length)),e==t?0:e.length?e.substring(n,n+t.length)==t?n:this.match_bitap_(e,t,n):-1},n.prototype.match_bitap_=function(e,t,n){if(t.length>this.Match_MaxBits)throw Error(`Pattern too long for this browser.`);var r=this.match_alphabet_(t),i=this;function a(e,r){var a=e/t.length,o=Math.abs(n-r);return i.Match_Distance?a+o/i.Match_Distance:o?1:a}var o=this.Match_Threshold,s=e.indexOf(t,n);s!=-1&&(o=Math.min(a(0,s),o),s=e.lastIndexOf(t,n+t.length),s!=-1&&(o=Math.min(a(0,s),o)));var c=1<<t.length-1;s=-1;for(var l,u,d=t.length+e.length,f,p=0;p<t.length;p++){for(l=0,u=d;l<u;)a(p,n+u)<=o?l=u:d=u,u=Math.floor((d-l)/2+l);d=u;var m=Math.max(1,n-u+1),h=Math.min(n+u,e.length)+t.length,g=Array(h+2);g[h+1]=(1<<p)-1;for(var _=h;_>=m;_--){var v=r[e.charAt(_-1)];if(p===0?g[_]=(g[_+1]<<1|1)&v:g[_]=(g[_+1]<<1|1)&v|(f[_+1]|f[_])<<1|1|f[_+1],g[_]&c){var y=a(p,_-1);if(y<=o)if(o=y,s=_-1,s>n)m=Math.max(1,2*n-s);else break}}if(a(p+1,n)>o)break;f=g}return s},n.prototype.match_alphabet_=function(e){for(var t={},n=0;n<e.length;n++)t[e.charAt(n)]=0;for(var n=0;n<e.length;n++)t[e.charAt(n)]|=1<<e.length-n-1;return t},n.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error(`patch not initialized`);for(var r=t.substring(e.start2,e.start2+e.length1),i=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)i+=this.Patch_Margin,r=t.substring(e.start2-i,e.start2+e.length1+i);i+=this.Patch_Margin;var o=t.substring(e.start2-i,e.start2);o&&e.diffs.unshift(new n.Diff(a,o));var s=t.substring(e.start2+e.length1,e.start2+e.length1+i);s&&e.diffs.push(new n.Diff(a,s)),e.start1-=o.length,e.start2-=o.length,e.length1+=o.length+s.length,e.length2+=o.length+s.length}},n.prototype.patch_make=function(e,t,o){var s,c;if(typeof e==`string`&&typeof t==`string`&&o===void 0)s=e,c=this.diff_main(s,t,!0),c.length>2&&(this.diff_cleanupSemantic(c),this.diff_cleanupEfficiency(c));else if(e&&typeof e==`object`&&t===void 0&&o===void 0)c=e,s=this.diff_text1(c);else if(typeof e==`string`&&t&&typeof t==`object`&&o===void 0)s=e,c=t;else if(typeof e==`string`&&typeof t==`string`&&o&&typeof o==`object`)s=e,c=o;else throw Error(`Unknown call format to patch_make.`);if(c.length===0)return[];for(var l=[],u=new n.patch_obj,d=0,f=0,p=0,m=s,h=s,g=0;g<c.length;g++){var _=c[g][0],v=c[g][1];switch(!d&&_!==a&&(u.start1=f,u.start2=p),_){case i:u.diffs[d++]=c[g],u.length2+=v.length,h=h.substring(0,p)+v+h.substring(p);break;case r:u.length1+=v.length,u.diffs[d++]=c[g],h=h.substring(0,p)+h.substring(p+v.length);break;case a:v.length<=2*this.Patch_Margin&&d&&c.length!=g+1?(u.diffs[d++]=c[g],u.length1+=v.length,u.length2+=v.length):v.length>=2*this.Patch_Margin&&d&&(this.patch_addContext_(u,m),l.push(u),u=new n.patch_obj,d=0,m=h,f=p);break}_!==i&&(f+=v.length),_!==r&&(p+=v.length)}return d&&(this.patch_addContext_(u,m),l.push(u)),l},n.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var i=e[r],a=new n.patch_obj;a.diffs=[];for(var o=0;o<i.diffs.length;o++)a.diffs[o]=new n.Diff(i.diffs[o][0],i.diffs[o][1]);a.start1=i.start1,a.start2=i.start2,a.length1=i.length1,a.length2=i.length2,t[r]=a}return t},n.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var n=this.patch_addPadding(e);t=n+t+n,this.patch_splitMax(e);for(var o=0,s=[],c=0;c<e.length;c++){var l=e[c].start2+o,u=this.diff_text1(e[c].diffs),d,f=-1;if(u.length>this.Match_MaxBits?(d=this.match_main(t,u.substring(0,this.Match_MaxBits),l),d!=-1&&(f=this.match_main(t,u.substring(u.length-this.Match_MaxBits),l+u.length-this.Match_MaxBits),(f==-1||d>=f)&&(d=-1))):d=this.match_main(t,u,l),d==-1)s[c]=!1,o-=e[c].length2-e[c].length1;else{s[c]=!0,o=d-l;var p=f==-1?t.substring(d,d+u.length):t.substring(d,f+this.Match_MaxBits);if(u==p)t=t.substring(0,d)+this.diff_text2(e[c].diffs)+t.substring(d+u.length);else{var m=this.diff_main(u,p,!1);if(u.length>this.Match_MaxBits&&this.diff_levenshtein(m)/u.length>this.Patch_DeleteThreshold)s[c]=!1;else{this.diff_cleanupSemanticLossless(m);for(var h=0,g,_=0;_<e[c].diffs.length;_++){var v=e[c].diffs[_];v[0]!==a&&(g=this.diff_xIndex(m,h)),v[0]===i?t=t.substring(0,d+g)+v[1]+t.substring(d+g):v[0]===r&&(t=t.substring(0,d+g)+t.substring(d+this.diff_xIndex(m,h+v[1].length))),v[0]!==r&&(h+=v[1].length)}}}}}return t=t.substring(n.length,t.length-n.length),[t,s]},n.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r=``,i=1;i<=t;i++)r+=String.fromCharCode(i);for(var i=0;i<e.length;i++)e[i].start1+=t,e[i].start2+=t;var o=e[0],s=o.diffs;if(s.length==0||s[0][0]!=a)s.unshift(new n.Diff(a,r)),o.start1-=t,o.start2-=t,o.length1+=t,o.length2+=t;else if(t>s[0][1].length){var c=t-s[0][1].length;s[0][1]=r.substring(s[0][1].length)+s[0][1],o.start1-=c,o.start2-=c,o.length1+=c,o.length2+=c}if(o=e[e.length-1],s=o.diffs,s.length==0||s[s.length-1][0]!=a)s.push(new n.Diff(a,r)),o.length1+=t,o.length2+=t;else if(t>s[s.length-1][1].length){var c=t-s[s.length-1][1].length;s[s.length-1][1]+=r.substring(0,c),o.length1+=c,o.length2+=c}return r},n.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,o=0;o<e.length;o++)if(!(e[o].length1<=t)){var s=e[o];e.splice(o--,1);for(var c=s.start1,l=s.start2,u=``;s.diffs.length!==0;){var d=new n.patch_obj,f=!0;for(d.start1=c-u.length,d.start2=l-u.length,u!==``&&(d.length1=d.length2=u.length,d.diffs.push(new n.Diff(a,u)));s.diffs.length!==0&&d.length1<t-this.Patch_Margin;){var p=s.diffs[0][0],m=s.diffs[0][1];p===i?(d.length2+=m.length,l+=m.length,d.diffs.push(s.diffs.shift()),f=!1):p===r&&d.diffs.length==1&&d.diffs[0][0]==a&&m.length>2*t?(d.length1+=m.length,c+=m.length,f=!1,d.diffs.push(new n.Diff(p,m)),s.diffs.shift()):(m=m.substring(0,t-d.length1-this.Patch_Margin),d.length1+=m.length,c+=m.length,p===a?(d.length2+=m.length,l+=m.length):f=!1,d.diffs.push(new n.Diff(p,m)),m==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(m.length))}u=this.diff_text2(d.diffs),u=u.substring(u.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==``&&(d.length1+=h.length,d.length2+=h.length,d.diffs.length!==0&&d.diffs[d.diffs.length-1][0]===a?d.diffs[d.diffs.length-1][1]+=h:d.diffs.push(new n.Diff(a,h))),f||e.splice(++o,0,d)}}},n.prototype.patch_toText=function(e){for(var t=[],n=0;n<e.length;n++)t[n]=e[n];return t.join(``)},n.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var o=e.split(`
|
|
164
164
|
`),s=0,c=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;s<o.length;){var l=o[s].match(c);if(!l)throw Error(`Invalid patch string: `+o[s]);var u=new n.patch_obj;for(t.push(u),u.start1=parseInt(l[1],10),l[2]===``?(u.start1--,u.length1=1):l[2]==`0`?u.length1=0:(u.start1--,u.length1=parseInt(l[2],10)),u.start2=parseInt(l[3],10),l[4]===``?(u.start2--,u.length2=1):l[4]==`0`?u.length2=0:(u.start2--,u.length2=parseInt(l[4],10)),s++;s<o.length;){var d=o[s].charAt(0);try{var f=decodeURI(o[s].substring(1))}catch{throw Error(`Illegal escape in patch_fromText: `+f)}if(d==`-`)u.diffs.push(new n.Diff(r,f));else if(d==`+`)u.diffs.push(new n.Diff(i,f));else if(d==` `)u.diffs.push(new n.Diff(a,f));else if(d==`@`)break;else if(d!==``)throw Error(`Invalid patch mode "`+d+`" in: `+f);s++}}return t},n.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0},n.patch_obj.prototype.toString=function(){for(var e=this.length1===0?this.start1+`,0`:this.length1==1?this.start1+1:this.start1+1+`,`+this.length1,t=this.length2===0?this.start2+`,0`:this.length2==1?this.start2+1:this.start2+1+`,`+this.length2,n=[`@@ -`+e+` +`+t+` @@
|
|
165
165
|
`],o,s=0;s<this.diffs.length;s++){switch(this.diffs[s][0]){case i:o=`+`;break;case r:o=`-`;break;case a:o=` `;break}n[s+1]=o+encodeURI(this.diffs[s][1])+`
|
|
@@ -425,4 +425,4 @@ $2`).split(`
|
|
|
425
425
|
`)},mdxJsxFlowElement(e,t,n,r){let i=e,a=i.data?.sourceRaw;if(typeof a==`string`)return a;let o=i.data?.htmlBoundary;if(o&&typeof o.opener==`string`&&typeof o.closer==`string`){let e=n.containerFlow({type:`root`,children:i.children??[]},r);return`${o.opener}\n\n${e}\n\n${o.closer}`}let s=i.name??``,c=jZ(i.attributes??[]);if(!i.children||i.children.length===0)return s?c?`<${s} ${c} />`:`<${s} />`:``;let l=c?`<${s} ${c}>`:`<${s}>`,u=`</${s}>`;return`${l}\n\n${n.containerFlow({type:`root`,children:i.children},r)}\n\n${u}`},mark(e,t,n,r){let i=n.createTracker(r),a=n.enter(`mark`),o=i.move(`==`);return o+=n.containerPhrasing(e,{before:o,after:`==`,...i.current()}),o+=i.move(`==`),a(),o},comment(e,t,n,r){let i=e.data?.sourceForm,a=i===`html`?`<!-- `:`%%`,o=i===`html`?` -->`:`%%`,s=n.createTracker(r),c=n.enter(`comment`),l=s.move(a);return l+=n.containerPhrasing(e,{before:l,after:o,...s.current()}),l+=s.move(o),c(),l},commentBlock(e,t,n,r){let i=n.createTracker(r),a=n.enter(`commentBlock`),o=e.children??[],s=e.data?.sourceForm,c=e.data?.sourceLayout,l=o.length===1&&o[0]?.type===`paragraph`;if(s===`html`&&l){let e=o[0],t=n.containerPhrasing(e,{before:`<!-- `,after:` -->`,...i.current()});return a(),`<!-- ${t} -->`}if(c===`inline`&&l){let e=o[0],t=n.containerPhrasing(e,{before:`%% `,after:` %%`,...i.current()});return a(),`%% ${t} %%`}let u=n.containerFlow(e,i.current());return a(),`%%\n\n${u}\n\n%%`},mdxJsxTextElement(e){let t=e.data?.sourceRaw;if(typeof t==`string`)return t;let n=e.name??``,r=jZ(e.attributes??[]);return r?`<${n} ${r} />`:`<${n}/>`},rawMdxFallback(e){return e.value??``},blockquote(e,t,n,r){let i=n.enter(`blockquote`),a=n.createTracker(r);a.move(`> `),a.shift(2);let o=n.containerFlow(e,a.current());i();let s=e.data?.sourceMarkerSpacings,c=0;return n.indentLines(o,(e,t,n)=>n?`>`:s?.[c++]===`none`?`>${e}`:`> ${e}`)}};function jZ(e){let t=[];for(let n of e){if(n.type===`mdxJsxExpressionAttribute`){t.push(`{${n.value}}`);continue}let e=n.name;if(n.value===null||n.value===void 0){t.push(e);continue}if(typeof n.value==`string`){if(n.value.includes(`"`)){let r=n.value.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`);t.push(`${e}={"${r}"}`)}else t.push(`${e}="${n.value}"`);continue}t.push(`${e}={${n.value.value}}`)}return t.join(` `)}function MZ(e,t,n=` `){return t===`single`?`${n}'${e.replace(/'/g,`\\'`)}'`:t===`paren`?`${n}(${e.replace(/[()]/g,`\\$&`)})`:`${n}"${e.replace(/"/g,`\\"`)}"`}function NZ(e){if(!e)return``;let t=0,n=!0;for(let r of e)r===`(`?t++:r===`)`&&(t--,t<0&&(n=!1));return t!==0&&(n=!1),n?e:e.replace(/[\\()]/g,`\\$&`)}function PZ(e){return e.replace(/(?<!\\)&(?=(#[0-9]+|#[xX][0-9A-Fa-f]+|[A-Za-z][A-Za-z0-9]*);)/g,(e,t)=>FZ(t)?e:`\\${e}`)}function FZ(e){if(e.charCodeAt(0)!==35)return!1;let t=e[1]===`x`||e[1]===`X`?Number.parseInt(e.slice(2),16):Number.parseInt(e.slice(1),10);return t===9||t===10||t===11||t===12||t===13||t===32}function IZ(e,t,n){let r=e.unsafe;e.unsafe=r.filter(e=>!(e.character===`&`&&e.after===`[#A-Za-z]`||e.character===`<`||e.character===`[`||e.character===`(`||e.character==="`"));let i;try{i=e.safe(t,n)}finally{e.unsafe=r}return PZ(i)}function LZ(e){if(!Number.isFinite(e)||e<0)return``;if(e<1024)return`${e} B`;let t=[`KiB`,`MiB`,`GiB`,`TiB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n.toFixed(1).replace(/\.0$/,``)} ${t[r]}`}var RZ=class{schema;handlers;pmNodeHandlers;pmMarkHandlers;parseProcessor;serializeProcessor;parseCtx={current:{}};constructor(e){this.schema=My(e.extensions),this.handlers=JZ(this.schema,this.parseCtx);let{nodeHandlers:t,markHandlers:n}=YZ(this.schema);this.pmNodeHandlers=t,this.pmMarkHandlers=n,this.parseProcessor=xZ({schema:this.schema,handlers:this.handlers,pmNodeHandlers:this.pmNodeHandlers,pmMarkHandlers:this.pmMarkHandlers}),this.serializeProcessor=SZ({schema:this.schema,handlers:this.handlers,pmNodeHandlers:this.pmNodeHandlers,pmMarkHandlers:this.pmMarkHandlers,toMarkdownHandlers:AZ})}parse(e,t){if(!e.trim())return{type:`doc`,content:[{type:`paragraph`,content:[]}]};this.parseCtx.current=t??{};try{return CZ(e,this.parseProcessor).toJSON()}finally{this.parseCtx.current={}}}parseToMdast(e){return e.trim()?wZ(e,this.parseProcessor):{type:`root`,children:[]}}parseWithFallback(e,t){return e.trim()?JJ(e,{parse:e=>this.parse(e,t)}):{type:`doc`,content:[{type:`paragraph`,content:[]}]}}serialize(e){let t;try{t=this.schema.nodeFromJSON(e)}catch(t){let n=`MarkdownManager.serialize() failed: schema rejected JSONContent (type=${e.type}, childCount=${e.content?.length??0})`;throw Error(n,{cause:t})}return TZ(t,this.serializeProcessor,{schema:this.schema,pmNodeHandlers:this.pmNodeHandlers,pmMarkHandlers:this.pmMarkHandlers})}};const zZ=LJ();function BZ(e,t){let n=new Map;for(let e of t)n.set(e.name,e);let r={};for(let t of e){if(t.type===`mdxJsxExpressionAttribute`)continue;let e=t.name,i=n.get(e);if(t.value===null||t.value===void 0){r[e]=!0;continue}if(typeof t.value==`string`){if(i?.type===`number`){let n=Number(t.value);r[e]=Number.isNaN(n)?t.value:n}else i?.type===`boolean`?r[e]=t.value===`true`:r[e]=t.value;continue}let a=t.value.value;try{r[e]=JSON.parse(a)}catch{r[e]=a}}return r}function VZ(e){let t=!1;return e.descendants(e=>t||e.type.name===`jsxInline`?!1:e.type.name===`jsxComponent`&&e.attrs.sourceDirty?(t=!0,!1):!0),t}function HZ(e){return e.attrs.sourceDirty||VZ(e)}function UZ(e){if(e.type!==`paragraph`)return!1;let t=e.children??[];return t.length===0?!0:t.every(e=>e.type===`text`&&e.value===``)}function WZ(e,t){if(!t)return e;let n={};return t.sourceFenceChar&&(n.sourceFenceChar=t.sourceFenceChar),typeof t.sourceFenceLength==`number`&&(n.sourceFenceLength=t.sourceFenceLength),Object.keys(n).length===0?e:{...e,data:n}}function GZ(e,t){if(e.length===0)return WZ({type:`inlineCode`,value:``},t);if(e.every(e=>e.type===`text`))return WZ({type:`inlineCode`,value:e.map(e=>e.value).join(``)},t);if(e.length===1&&`children`in e[0]){let n=e[0];return{...n,children:[GZ(n.children,t)]}}return WZ({type:`inlineCode`,value:KZ(e)},t)}function KZ(e){let t=``;for(let n of e)n.type===`text`?t+=n.value:`children`in n&&Array.isArray(n.children)?t+=KZ(n.children):`value`in n&&typeof n.value==`string`&&(t+=n.value);return t}const qZ=BG;function JZ(e,t){let n=e.nodes,r=e.marks,i={};n.paragraph&&(i.paragraph=(e,t,r)=>{let i=r.all(e).flat(),a=i.some(e=>e?.isBlock&&!e?.isInline),o=i.some(e=>e?.isInline||e?.isText||e?.isTextblock);if(a&&!o)return i.length===1?i[0]:i;if(a&&o){let e=i.filter(e=>!e?.isBlock||e?.isInline),t=i.filter(e=>e?.isBlock&&!e?.isInline),r=[],a=n.paragraph.createAndFill(null,e.length>0?e:null);return a&&r.push(a),r.push(...t),r.length===1?r[0]:r}return n.paragraph.createAndFill(null,i.length>0?i:null)}),n.blockquote&&(i.blockquote=UL(n.blockquote,e=>({sourceMarkerSpacings:e.data?.sourceMarkerSpacings??null}))),n.tableCell&&(i.tableCell=(e=>(t,r,i)=>{let a=i.all(t).flat();if(a.length>0&&n.paragraph){let t=n.paragraph.create(null,a);return e.createAndFill(null,[t])}return e.createAndFill(null,null)})(n.tableCell)),n.tableRow&&(i.tableRow=UL(n.tableRow)),n.table&&n.tableRow&&n.tableCell&&(i.table=(e,t,r)=>{let i=e.align??[],a=e.children??[],o=[];for(let e=0;e<a.length;e++){let t=a[e];if(t.type!==`tableRow`)continue;let s=t.children??[],c=[];for(let t=0;t<s.length;t++){let a=s[t];if(a.type!==`tableCell`)continue;let o=r.all(a).flat(),l=o.length>0&&n.paragraph?[n.paragraph.create(null,o)]:null,u=i[t]??null,d=e===0&&n.tableHeader?n.tableHeader:n.tableCell,f=a.data?.sourcePadding??null,p=d.createAndFill({align:u,sourcePadding:f},l);p&&c.push(p)}let l=n.tableRow.createAndFill(null,c.length>0?c:null);l&&o.push(l)}let s=e.data?.sourceDashCounts??null;return n.table.createAndFill({sourceDashCounts:s},o.length>0?o:null)}),n.image&&(i.image=e=>{let r=e.url??``,i=kZ(r,t.current.sourcePath);return n.image.createAndFill({src:i,alt:e.alt??null,title:e.title??null,sourceUrl:i===r?null:r})},n.imageReference?i.imageReference=e=>n.imageReference.createAndFill({alt:e.alt??``,label:e.label??e.identifier??``,identifier:e.identifier??``,referenceType:e.referenceType??`shortcut`}):i.imageReference=e=>n.image.createAndFill({src:``,alt:e.alt??null,title:null})),r.escapeMark&&(i.text=t=>{let n=t.value??``,i=typeof t.data?.sourceRaw==`string`?t.data.sourceRaw:null;if(!n&&!i)return null;if(i){let t=n.replaceAll(`\xA0`,` `);return r.sourceLiteral?e.text(t,[r.sourceLiteral.create({sourceRaw:i})]):e.text(t)}let a=t.data?.escapedChars,o=t.data?.entityRefSpans;if(!a?.length&&!o?.length)return e.text(n.replaceAll(`\xA0`,` `));let s=[...(a??[]).map(e=>({kind:`escape`,offset:e.offset,length:1})),...(o??[]).map(e=>({kind:`entity`,offset:e.offset,length:e.length,raw:e.raw}))];s.sort((e,t)=>e.offset-t.offset);let c=[],l=0;for(let t of s){if(t.offset>l){let r=n.slice(l,t.offset).replaceAll(`\xA0`,` `);r&&c.push(e.text(r))}if(t.offset<n.length){let i=n.slice(t.offset,t.offset+t.length).replaceAll(`\xA0`,` `);i&&(t.kind===`escape`?c.push(e.text(i,[r.escapeMark.create()])):r.sourceLiteral?c.push(e.text(i,[r.sourceLiteral.create({sourceRaw:t.raw})])):c.push(e.text(i))),l=t.offset+t.length}}if(l<n.length){let t=n.slice(l).replaceAll(`\xA0`,` `);t&&c.push(e.text(t))}return c.length===1?c[0]:c}),r.code&&(i.inlineCode=t=>e.text(t.value,[r.code.create({sourceFenceChar:t.data?.sourceFenceChar??"`",sourceFenceLength:typeof t.data?.sourceFenceLength==`number`?t.data.sourceFenceLength:1})]));let a=r.strike??r.delete;if(a&&(i.delete=WL(a)),r.highlight&&(i.mark=WL(r.highlight)),r.comment&&(i.comment=WL(r.comment,e=>({sourceForm:e.data?.sourceForm??`percent`}))),n.commentBlock&&(i.commentBlock=UL(n.commentBlock,e=>({sourceForm:e.data?.sourceForm??`percent`,sourceLayout:e.data?.sourceLayout??`block`}))),r.emphasis&&(i.emphasis=WL(r.emphasis,e=>({sourceDelimiter:e.data?.sourceDelimiter??`*`}))),r.strong&&(i.strong=WL(r.strong,e=>({sourceDelimiter:e.data?.sourceDelimiter??`**`}))),n.heading&&(i.heading=UL(n.heading,e=>({level:e.depth,headingStyle:e.data?.sourceStyle??`atx`,sourceTrailingHashes:e.data?.sourceTrailingHashes??null,sourceUnderlineLength:e.data?.sourceUnderlineLength??null,sourceContiguousNext:e.data?.sourceContiguousNext??!1}))),n.codeBlock&&(i.code=t=>{let r=t.value?[e.text(t.value)]:[];return n.codeBlock.createAndFill({language:t.lang??null,meta:t.meta??null,fenceDelimiter:t.data?.sourceFenceChar??"`",fenceLength:t.data?.sourceFenceLength??3,sourceStyle:t.data?.sourceStyle??`fenced`},r)}),n.thematicBreak&&(i.thematicBreak=e=>n.thematicBreak.createAndFill({sourceRaw:e.data?.sourceRaw??`---`})),n.hardBreak&&(i.break=e=>n.hardBreak.createAndFill({hardBreakStyle:e.data?.sourceStyle??`spaces`})),n.list&&(i.list=UL(n.list,e=>({ordered:!!e.ordered,start:e.start??1,spread:!!e.spread,bulletMarker:e.data?.bulletMarker??null,listMarkerDelimiter:e.data?.listMarkerDelimiter??null}))),n.listItem&&(i.listItem=UL(n.listItem,e=>({checked:e.checked??null,spread:!!e.spread}))),r.link){let t=r.sourceLiteral;i.link=(n,i,a)=>{if((n.children??[]).length===0){let r=typeof n.data?.sourceRaw==`string`?n.data.sourceRaw:`[](${n.url??``})`;return r?t?e.text(r,[t.create({sourceRaw:r})]):e.text(r):null}let o=a.all(n).flat(),s=r.link.create({href:n.url??``,title:n.title??null,linkStyle:n.data?.sourceStyle??`inline`,refLabel:null,sourceUrlForm:n.data?.sourceUrlForm??null,sourceTitleMarker:n.data?.sourceTitleMarker??null});return o.map(e=>e.mark(s.addToSet(e.marks)))},i.linkReference=(n,i,a)=>{if((n.children??[]).length===0){let r=typeof n.data?.sourceRaw==`string`?n.data.sourceRaw:`[${n.label??``}][${n.identifier??``}]`;return r?t?e.text(r,[t.create({sourceRaw:r})]):e.text(r):null}let o=a.all(n).flat(),s=r.link.create({href:``,title:null,linkStyle:n.referenceType??`shortcut`,refLabel:n.label??n.identifier??null});return o.map(e=>e.mark(s.addToSet(e.marks)))}}n.htmlBlock&&(i.html=e=>n.htmlBlock.createAndFill({content:e.value??``}));let o=n.linkDefinition??n.linkRefDef;if(o){let e=!!o.spec.attrs?.url,t=!!o.spec.attrs?.href,n=!!o.spec.attrs?.identifier,r=!!o.spec.attrs?.sourceLayout,a=!!o.spec.attrs?.sourceTitleMarker;i.definition=i=>{let s={title:i.title??null};return n&&(s.identifier=i.identifier??``),s.label=i.label??i.identifier??``,e?s.url=i.url??``:t&&(s.href=i.url??``),r&&(s.sourceLayout=i.data?.sourceLayout??null),a&&(s.sourceTitleMarker=i.data?.sourceTitleMarker??null),o.createAndFill(s)}}if(n.jsxComponent){let r=e=>{if(e&&typeof e==`object`&&`sourceRaw`in e){let t=e.sourceRaw;if(typeof t==`string`)return t}};i.mdxJsxFlowElement=(e,i,a)=>{let o=e.name??``,s=zZ.getOrWildcard(o),c=BZ(e.attributes,s.props);if(o===`CommonMarkImage`&&typeof c.src==`string`){let e=c.src,n=kZ(e,t.current.sourcePath);n!==e&&(c.src=n,c.sourceUrl=e)}let l=a.all(e).flat();return n.jsxComponent.createAndFill({componentName:o,kind:`element`,attributes:e.attributes,sourceRaw:r(e.data)??``,sourceDirty:!1,props:c},l.length?l:void 0)};let a=(e,t)=>{let n=e.attributes?.find(e=>e.type===`mdxJsxAttribute`&&e.name===t);return n&&typeof n.value==`string`?n.value:null};i.mdxJsxTextElement=t=>{if(t.name===`InlineMath`&&n.mathInline){let e=a(t,`formula`)??``,r=a(t,`id`);return n.mathInline.create({formula:e,id:r??null})}if(t.name===`Tag`&&n.tag){let e=a(t,`value`)??``;return n.tag.create({value:e})}if(n.jsxInline){let i=r(t.data)??``;return n.jsxInline.createAndFill({},i?[e.text(i)]:null)}return n.jsxComponent.createAndFill({sourceRaw:r(t.data)??``})},i.mdxFlowExpression=e=>{let t=r(e.data)??`{${e.value??``}}`;return n.jsxComponent.createAndFill({kind:`expression`,sourceRaw:t,sourceDirty:!1})},i.mdxTextExpression=t=>{let n=r(t.data)??`{${t.value??``}}`;return e.text(n)}}return n.wikiLink&&(i.wikiLink=e=>n.wikiLink.createAndFill({target:e.data?.target??``,alias:e.data?.alias??null,anchor:e.data?.anchor??null})),n.tag&&(i.tag=e=>n.tag.createAndFill({value:e.value})),n.wikiLinkEmbed&&(i.wikiLinkEmbed=(i,a)=>{let o=i.data?.target??``,s=i.data?.alias??null,c=i.data?.anchor??null,l=iq(o),{resolveEmbed:u,sourcePath:d}=t.current,f=u&&d?u(o,d)??null:null,p=f?`/${f}`:o,m=a?.type===`paragraph`&&Array.isArray(a.children)&&a.children.length===1;if(m&&qZ.has(l)&&n.jsxComponent&&zZ.has(`WikiEmbedImage`))return n.jsxComponent.createAndFill({componentName:`WikiEmbedImage`,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!1,props:{src:p,alt:s??o,target:o,anchor:c,alias:s}});if(m&&VG.has(l)&&n.jsxComponent&&zZ.has(`WikiEmbedVideo`))return n.jsxComponent.createAndFill({componentName:`WikiEmbedVideo`,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!1,props:{src:p,title:s??o,target:o,anchor:c,alias:s}});if(m&&UG.has(l)&&n.jsxComponent&&zZ.has(`WikiEmbedAudio`))return n.jsxComponent.createAndFill({componentName:`WikiEmbedAudio`,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!1,props:{src:p,title:s??o,target:o,anchor:c,alias:s}});if(m&&WG.has(l)&&n.jsxComponent&&zZ.has(`WikiEmbedFile`)){let{resolveSize:e}=t.current,r=e&&d?e(o,d)??null:null,i=r===null?null:LZ(r);return n.jsxComponent.createAndFill({componentName:`WikiEmbedFile`,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!1,props:{src:p,target:o,anchor:c,alias:s,size:i}})}let h=s||(c?`${o}#${c}`:o);if(YG.has(l)&&r.link){let t=r.link.create({href:p,title:null,linkStyle:`inline`,refLabel:null,sourceForm:`wikiembed`,target:o,anchor:c,alias:s});return e.text(h,[t])}if(r.link){let t=r.link.create({href:o,title:null,linkStyle:`inline`,refLabel:null});return e.text(h,[t])}throw Error("[wikiLinkEmbed handler] schema lacks `link` mark — cannot dispatch without violating the STOP rule against emitting PM wikiLinkEmbed server-side")}),n.mathInline&&(i.inlineMath=e=>n.mathInline.create({formula:e.value??``})),i.math||=t=>{let r=t.value==null?`«unknown:${t.type}»`:t.value;return n.rawMdxFallback?(console.warn(JSON.stringify({event:`unknown-mdast-type`,type:t.type,reason:`Unhandled block mdast: ${t.type}`})),n.rawMdxFallback.createAndFill({reason:`Unhandled block mdast: ${t.type}`},r?[e.text(r)]:null)):null},i.inlineMath||=t=>(console.warn(JSON.stringify({event:`unknown-mdast-type`,type:t.type,reason:`Unhandled inline mdast: ${t.type}`})),t.value==null?e.text(`«unknown:${t.type}»`):e.text(t.value)),n.footnoteReference?i.footnoteReference=e=>n.footnoteReference.create({identifier:e.identifier,label:e.label??e.identifier}):i.footnoteReference||=t=>(console.warn(JSON.stringify({event:`unknown-mdast-type`,type:`footnoteReference`,reason:`FootnoteReference extension missing — recovering [^id] source`})),e.text(`[^${t.label??t.identifier}]`)),n.footnoteDefinition?i.footnoteDefinition=UL(n.footnoteDefinition,e=>{let t=e;return{identifier:t.identifier,label:t.label??t.identifier}}):i.footnoteDefinition||=t=>{console.warn(JSON.stringify({event:`unknown-mdast-type`,type:`footnoteDefinition`,reason:`FootnoteDefinition extension missing — recovering [^id]: marker`}));let r=`[^${t.label??t.identifier}]: `;return n.paragraph?n.paragraph.create(null,e.text(r)):null},i.rawMdxFallbackMdast=t=>{if(!n.rawMdxFallback)return null;let r=t.position?{start:t.position.start?.offset??0,end:t.position.end?.offset??0}:{start:0,end:0};return console.warn(JSON.stringify({event:`unknown-mdast-type`,type:t.originalType,reason:`Unhandled mdast: ${t.originalType}`})),n.rawMdxFallback.createAndFill({reason:`Unhandled mdast: ${t.originalType}`,originalSpan:r},t.value?[e.text(t.value)]:null)},i}function YZ(e){let t={},n={},r=e.nodes,i=e.marks;r.paragraph&&(t.paragraph=YL(`paragraph`)),r.blockquote&&(t.blockquote=YL(`blockquote`,e=>{let t=e.attrs.sourceMarkerSpacings,n={};return Array.isArray(t)&&t.length>0&&(n.sourceMarkerSpacings=t),Object.keys(n).length>0?{data:n}:{}})),r.heading&&(t.heading=YL(`heading`,e=>({depth:e.attrs.level,data:{sourceStyle:e.attrs.headingStyle,sourceTrailingHashes:e.attrs.sourceTrailingHashes??void 0,sourceUnderlineLength:e.attrs.sourceUnderlineLength??void 0,sourceContiguousNext:e.attrs.sourceContiguousNext===!0?!0:void 0}}))),r.codeBlock&&(t.codeBlock=e=>{let t=e.attrs.sourceStyle===`indented`?`indented`:`fenced`;return{type:`code`,lang:t===`indented`?null:e.attrs.language??null,meta:t===`indented`?null:e.attrs.meta??null,value:e.textContent??``,data:{sourceFenceChar:e.attrs.fenceDelimiter,sourceFenceLength:e.attrs.fenceLength,sourceStyle:t}}}),r.thematicBreak&&(t.thematicBreak=e=>({type:`thematicBreak`,data:{sourceRaw:e.attrs.sourceRaw}})),r.hardBreak&&(t.hardBreak=e=>({type:`break`,data:{sourceStyle:e.attrs.hardBreakStyle}})),r.list&&(t.list=YL(`list`,e=>({ordered:e.attrs.ordered??!1,start:e.attrs.ordered?e.attrs.start??1:null,spread:e.attrs.spread??!1,data:{bulletMarker:e.attrs.bulletMarker,listMarkerDelimiter:e.attrs.listMarkerDelimiter}}))),r.listItem&&(t.listItem=(e,t,n)=>{let r=n.all(e),i=r.length>1&&UZ(r[0])?r.slice(1):r;return{type:`listItem`,checked:e.attrs.checked??null,spread:e.attrs.spread??!1,children:i}}),r.table&&(t.table=(e,t,n)=>{let r=n.all(e),i=[],a=e.firstChild;a&&a.forEach(e=>{let t=e.attrs.align;i.push(t===`left`||t===`right`||t===`center`?t:null)});let o=r.filter(e=>e.type===`tableRow`),s=e.attrs.sourceDashCounts,c=Array.isArray(s)&&s.length>0?{sourceDashCounts:s}:void 0,l={type:`table`,align:i,children:o};return c&&(l.data=c),l}),r.tableRow&&(t.tableRow=YL(`tableRow`));let a=e=>{let t=e.attrs.sourcePadding,n={};return typeof t==`object`&&t&&typeof t.left==`number`&&typeof t.right==`number`&&(n.sourcePadding=t),Object.keys(n).length>0?{data:n}:{}};if(r.tableCell&&(t.tableCell=YL(`tableCell`,a)),r.tableHeader&&(t.tableHeader=YL(`tableCell`,a)),r.image&&(t.image=e=>({type:`image`,url:e.attrs.sourceUrl??e.attrs.src,alt:e.attrs.alt,title:e.attrs.title})),r.imageReference&&(t.imageReference=e=>{let t=e.attrs.label??``,n=e.attrs.identifier??t;return{type:`imageReference`,alt:e.attrs.alt??``,identifier:n,label:t||n,referenceType:e.attrs.referenceType??`shortcut`}}),r.htmlBlock&&(t.htmlBlock=e=>({type:`html`,value:e.attrs.content})),r.linkDefinition??r.linkRefDef){let e=r.linkDefinition?`linkDefinition`:`linkRefDef`;t[e]=e=>{let t={},n=e.attrs.sourceLayout;(n===`multiline`||n===`inline`)&&(t.sourceLayout=n);let r=e.attrs.sourceTitleMarker;(r===`single`||r===`double`||r===`paren`)&&(t.sourceTitleMarker=r);let i={type:`definition`,identifier:e.attrs.identifier??e.attrs.label??``,label:e.attrs.label??e.attrs.identifier??``,url:e.attrs.url??e.attrs.href??``,title:e.attrs.title};return Object.keys(t).length>0&&(i.data=t),i}}if(r.jsxComponent&&(t.jsxComponent=(e,t,n)=>{if(e.attrs.kind===`expression`)return{type:`html`,value:e.attrs.sourceRaw??``};let r=e.attrs.componentName||null,i=Array.isArray(e.attrs.attributes)?e.attrs.attributes:[];return!HZ(e)&&e.attrs.sourceRaw?{type:`mdxJsxFlowElement`,name:r,attributes:i,children:[],data:{sourceRaw:String(e.attrs.sourceRaw)}}:zZ.getOrWildcard(r??`*`).serialize(e,{all:e=>n.all(e),registry:zZ,serializeChildren:()=>{throw Error(`SerializeContext.serializeChildren is not available in the PM→mdast handler. Compat descriptors that need markdown-byte body rendering must emit a marker mdast node and let the to-markdown handler render the body via state.containerFlow.`)}})}),r.rawMdxFallback&&(t.rawMdxFallback=e=>{let t=e.textContent??``,n=typeof e.attrs.reason==`string`?e.attrs.reason:``,r=e.attrs.originalSpan;return{type:`rawMdxFallback`,value:t,data:{reason:n,originalSpan:r&&typeof r==`object`&&`start`in r&&`end`in r?{start:Number(r.start)||0,end:Number(r.end)||0}:{start:0,end:0}}}}),r.jsxInline&&(t.jsxInline=e=>{let t=e.attrs.sourceRaw||e.textContent||``;return{type:`mdxJsxTextElement`,name:null,attributes:[],children:[],data:{sourceRaw:String(t)}}}),r.mathInline&&(t.mathInline=e=>{let t=e.attrs.formula??``,n=e.attrs.id;return typeof n==`string`&&n.length>0?{type:`mdxJsxTextElement`,name:`InlineMath`,attributes:[{type:`mdxJsxAttribute`,name:`formula`,value:t},{type:`mdxJsxAttribute`,name:`id`,value:n}],children:[]}:{type:`inlineMath`,value:t}}),r.wikiLink&&(t.wikiLink=e=>{let t=e.attrs.target??``,n=e.attrs.anchor??null,r=e.attrs.alias??null,i=r||(n?`${t}#${n}`:t);return{type:`wikiLink`,value:i,data:{target:t,anchor:n,alias:r},children:[{type:`text`,value:i}]}}),r.tag&&(t.tag=e=>({type:`tag`,value:String(e.attrs.value??``)})),r.wikiLinkEmbed&&(t.wikiLinkEmbed=e=>{let t=e.attrs.target??``,n=e.attrs.anchor??null,r=e.attrs.alias??null,i=r||(n?`${t}#${n}`:t);return{type:`wikiLinkEmbed`,value:i,data:{target:t,anchor:n,alias:r},children:[{type:`text`,value:i}]}}),i.emphasis&&(n.emphasis=XL(`emphasis`,e=>({data:{sourceDelimiter:e.attrs.sourceDelimiter}}))),i.strong&&(n.strong=XL(`strong`,e=>({data:{sourceDelimiter:e.attrs.sourceDelimiter}}))),i.code&&(n.code=(e,t,n)=>{let r=e.attrs.sourceFenceChar,i=e.attrs.sourceFenceLength;return GZ(n,{sourceFenceChar:r,sourceFenceLength:i})}),i.strike??i.delete){let e=i.strike?`strike`:`delete`;n[e]=XL(`delete`)}return i.highlight&&(n.highlight=XL(`mark`)),i.comment&&(n.comment=XL(`comment`,e=>({data:{sourceForm:e.attrs.sourceForm===`html`?`html`:`percent`}}))),r.commentBlock&&(t.commentBlock=YL(`commentBlock`,e=>({data:{sourceForm:e.attrs.sourceForm===`html`?`html`:`percent`,sourceLayout:e.attrs.sourceLayout===`inline`?`inline`:`block`}}))),r.footnoteReference&&(t.footnoteReference=e=>{let t=String(e.attrs.identifier??``);return{type:`footnoteReference`,identifier:t,label:e.attrs.label?String(e.attrs.label):t}}),r.footnoteDefinition&&(t.footnoteDefinition=YL(`footnoteDefinition`,e=>({identifier:String(e.attrs.identifier??``),label:e.attrs.label?String(e.attrs.label):String(e.attrs.identifier??``)}))),i.link&&(n.link=(e,t,n)=>{if(e.attrs.sourceForm===`wikiembed`){let t=typeof e.attrs.target==`string`&&e.attrs.target.length>0?e.attrs.target:e.attrs.href??``,n=typeof e.attrs.anchor==`string`&&e.attrs.anchor.length>0?e.attrs.anchor:null,r=typeof e.attrs.alias==`string`&&e.attrs.alias.length>0?e.attrs.alias:null,i=r||(n?`${t}#${n}`:t);return{type:`wikiLinkEmbed`,value:i,data:{target:t,anchor:n,alias:r},children:[{type:`text`,value:i}]}}let r=e.attrs.linkStyle;if(r===`autolink`)return{type:`link`,url:e.attrs.href??``,title:null,children:n,data:{sourceStyle:`autolink`}};if(r===`gfm-autolink`)return{type:`link`,url:e.attrs.href??``,title:null,children:n,data:{sourceStyle:`gfm-autolink`}};if(r===`inline`||!r){let t={};e.attrs.sourceUrlForm===`angle-bracketed`&&(t.sourceUrlForm=`angle-bracketed`);let r=e.attrs.sourceTitleMarker;return(r===`single`||r===`double`||r===`paren`)&&(t.sourceTitleMarker=r),{type:`link`,url:e.attrs.href??``,title:e.attrs.title??null,children:n,...Object.keys(t).length>0?{data:t}:{}}}return{type:`linkReference`,identifier:(e.attrs.refLabel??``).toLowerCase(),label:e.attrs.refLabel,referenceType:r,children:n}}),i.escapeMark&&(n.escapeMark=(e,t,n)=>{for(let e of n)if(e.type===`text`&&e.value){let t=e;t.data=t.data??{},t.data.escapedChars=t.data.escapedChars??[];for(let e=0;e<t.value.length;e++)t.data.escapedChars.push({offset:e,char:t.value[e]})}return n.length===1?n[0]:n}),i.sourceLiteral&&(n.sourceLiteral=(e,t,n)=>{let r=typeof e.attrs.sourceRaw==`string`?e.attrs.sourceRaw:``;if(n.length===1&&n[0]?.type===`text`){let e=n[0],t=r||e.value;return KK(t,e.value)&&(e.data=e.data??{},e.data.sourceRaw=t),e}return{type:`text`,value:n.filter(e=>e.type===`text`).map(e=>e.value??``).join(``)||r}}),{nodeHandlers:t,markHandlers:n}}const XZ=/\p{M}+/gu,ZZ=/[^\p{L}\p{N}]+/gu,QZ=/^-+|-+$/g;function $Z(e){return e.trim().normalize(`NFKD`).replace(XZ,``).toLowerCase().replace(ZZ,`-`).replace(QZ,``)}function eQ(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}-${n}`}function tQ(e,t){let n=$Z(e);return n?eQ(n,t):``}const nQ=zB(),rQ=rB(),iQ=iB();function aQ(){return FJ.filter(e=>e.surface===`canonical`&&e.name!==`*`)}function oQ(){return aQ().filter(e=>sQ(e)!==`fence`)}function sQ(e){return e.name===`MermaidFence`?`fence`:e.hasChildren?`jsx-block`:`jsx-void`}function cQ(e){return{id:e.name,displayName:e.displayName??e.name,description:e.description??``,kind:sQ(e)}}function lQ(e){if(e.hidden!==!0&&e.type!==`reactnode`){if(`defaultValue`in e&&e.defaultValue!==void 0)return e.defaultValue;if(e.type===`enum`)return e.enumValues[0];if(e.type===`string`)return``;if(e.type===`number`)return 0;if(e.type===`boolean`)return!1}}function uQ(e,t){return!(e.omitOnDefault===!0&&`defaultValue`in e&&Object.is(e.defaultValue,t)||e.type===`string`&&e.required===!1&&e.defaultValue===void 0&&t===``)}function dQ(e){let t=[];for(let n of e.props){let e=lQ(n);e!==void 0&&uQ(n,e)&&t.push(Jq(n.name,e))}return t}function fQ(e){return dz(e.exampleBody&&e.exampleBody.trim().length>0?e.exampleBody:`Body content here.`,{extensions:[nQ],mdastExtensions:[rQ]}).children}function pQ(e){let t=sQ(e),n;if(t===`fence`)n={type:`code`,lang:`mermaid`,meta:null,value:e.exampleBody&&e.exampleBody.trim().length>0?e.exampleBody:`graph LR
|
|
426
426
|
A --> B`};else{let r=dQ(e),i=t===`jsx-block`?fQ(e):[];n={type:`mdxJsxFlowElement`,name:e.name,attributes:r,children:i}}return aP({type:`root`,children:[n]},{extensions:[iQ]}).trimEnd()}function mQ(e){let t=[];for(let n of e.props){if(n.hidden===!0)continue;let e={name:n.name,type:n.type,required:n.required};n.description!==void 0&&(e.description=n.description),n.advanced===!0&&(e.advanced=!0),n.omitOnDefault===!0&&(e.omitOnDefault=!0),n.type===`enum`&&(e.values=n.enumValues,n.defaultValue!==void 0&&(e.defaultValue=n.defaultValue)),n.type===`string`&&(n.defaultValue!==void 0&&(e.defaultValue=n.defaultValue),n.language!==void 0&&(e.language=n.language),n.accept!==void 0&&(e.accept=n.accept)),n.type===`boolean`&&n.defaultValue!==void 0&&(e.defaultValue=n.defaultValue),n.type===`number`&&n.defaultValue!==void 0&&(e.defaultValue=n.defaultValue),t.push(e)}return t}function hQ(e){return{...cQ(e),example:pQ(e),params:mQ(e)}}function gQ(){return[``,"**Custom canonical components.** OK `.md` / `.mdx` supports the JSX components below — use whichever is semantically useful in any part of the doc. For full source syntax + parameter schemas, call `palette({ components: [ids] })` with the ids you want to use. Fenced code blocks render naturally and don't need a fetch — including ` ```mermaid ` for diagrams and ` ```html preview ` for interactive HTML/JS/CSS pages (the fence info-string `preview` token renders the block as a live iframe; works for `html` / `htm` / `xml`; optional `h=` / `w=` tokens set size, e.g. ` ```html preview h=400px `). Use ` ```html preview ` whenever you want anything interactive or JS-powered (charts, demos, calculators, animations) — just author the standalone HTML page in the fence. Call `palette` for the markdown-native component forms (write `> [!NOTE]`, not `<Callout>`), copy-ready themed `html preview` starters, and the theme tokens (`var(--chart-1)`, `var(--foreground)`, …) an embed should reference so it tracks the reader's light/dark theme. Arbitrary `<TagName>` JSX falls through as raw MDX when no canonical fits.",``,...oQ().map(cQ).map(e=>`- \`${e.id}\` (${e.kind}) — ${e.description}`)].join(`
|
|
427
427
|
`)}const _Q=M({docName:pq,summary:hq,content:k().optional(),...mq}).loose(),vQ=M({docName:pq,summary:hq,markdown:k(),position:N([`append`,`prepend`,`replace`]).optional(),extension:N([`.md`,`.mdx`]).optional(),...mq}).loose(),yQ=M({docName:pq,summary:hq,find:k().min(1),replace:k(),offset:A().int().nonnegative().optional(),...mq}).loose(),bQ=M({docName:pq,connectionId:k().min(1),scope:N([`last`,`session`,`file`]).optional(),...mq}).loose(),xQ=M({value:k(),truncatedFrom:A().int().nonnegative().optional(),hint:k().optional()}).loose(),SQ=Qs(`kind`,[M({kind:P(`inline`),content:k()}),M({kind:P(`truncated`),byteLength:A().int().nonnegative(),hint:k()})]),CQ=M({kind:P(`content-divergence`),intendedBytes:A().int().nonnegative(),actualBytes:A().int().nonnegative(),byteDelta:A().int(),divergenceType:k().optional(),currentState:SQ.optional(),hint:k().optional()}).loose(),wQ=M({type:P(`orphan`),parentCandidates:j(k()),message:k()}).loose(),TQ=Qs(`kind`,[CQ,M({kind:P(`disk-edit-reconciled`),intendedBytes:A().int().nonnegative(),actualBytes:A().int().nonnegative(),byteDelta:A().int(),hint:k().optional()}).loose()]),EQ=M({timestamp:k().min(1),summary:xQ.optional(),warning:TQ.optional()}).loose(),DQ=M({timestamp:k().min(1),subscriberCount:A().int().nonnegative(),systemSubscriberCount:A().int().nonnegative(),hints:j(wQ).optional(),summary:xQ.optional(),warning:TQ.optional()}).loose(),OQ=M({timestamp:k().min(1),subscriberCount:A().int().nonnegative(),systemSubscriberCount:A().int().nonnegative(),summary:xQ.optional(),warning:TQ.optional()}).loose(),kQ=M({docName:k().min(1),scope:N([`last`,`session`]),undone:Ls()}).loose(),AQ=M({docName:pq,patch:nc(k(),Xs([kW,zs()])),types:nc(k(),N(OW)).optional(),summary:hq,...mq}).loose(),jQ=M({timestamp:k().min(1),subscriberCount:A().int().nonnegative(),systemSubscriberCount:A().int().nonnegative(),appliedKeys:j(k()),summary:xQ.optional(),warning:TQ.optional()}).loose(),MQ=M({entries:j(M({level:N([`info`,`warn`,`error`]),message:k().max(8192),event:k().optional(),fields:nc(k(),Us()).optional(),ts:A().optional(),sourceId:k().optional(),lineNumber:A().optional()}).loose()).max(100)}).loose(),NQ=M({accepted:A().int().min(0)}).loose(),PQ=M({status:k().min(1),reason:k()}).loose(),FQ=M({docName:k().min(1),content:k(),lifecycle:PQ.nullable()}).loose(),IQ=M({documents:j(M({kind:N([`document`,`asset`,`folder`]).default(`document`),docName:k().min(1).optional(),docExt:k().min(1).default(`.md`),size:A().int().nonnegative(),modified:k().min(1),isSymlink:Ls().default(!1),canonicalDocName:k().nullable().default(null),targetPath:k().nullable().default(null),path:k().min(1).optional(),assetExt:k().min(1).optional(),mediaKind:N([`image`,`video`,`audio`,`pdf`,`text`]).nullable().optional(),referencedBy:j(k().min(1)).optional(),hasChildren:Ls().optional()}).loose().refine(e=>e.kind===`document`?e.docName!==void 0&&e.path===void 0&&e.assetExt===void 0&&e.mediaKind===void 0&&e.referencedBy===void 0&&e.hasChildren===void 0:e.kind===`folder`?e.docName===void 0&&e.path!==void 0&&e.assetExt===void 0&&e.mediaKind===void 0&&e.referencedBy===void 0:e.path!==void 0&&e.assetExt!==void 0&&e.referencedBy!==void 0&&e.hasChildren===void 0,{message:`document/asset/folder kind must match its required fields (document → docName; asset → path+assetExt+referencedBy; folder → path only, no docName)`})),truncated:Ls().optional()}).loose(),LQ=M({source:k().min(1),anchor:k().nullable(),title:k(),snippet:k().nullable()}).loose(),RQ=M({docName:k().min(1),backlinks:j(LQ)}).loose(),zQ=M({counts:nc(k().min(1),A().int().nonnegative())}).loose(),BQ=Qs(`kind`,[M({kind:P(`doc`),docName:k().min(1),anchor:k().nullable(),title:k(),snippet:k().nullable()}).loose(),M({kind:P(`external`),url:k().min(1),title:k(),snippet:k().nullable()}).loose()]),VQ=M({docName:k().min(1),forwardLinks:j(BQ)}).loose(),HQ=Qs(`kind`,[M({id:k().min(1),kind:P(`doc`),docName:k().min(1),anchor:k().nullable(),label:k(),cluster:k().nullable(),category:k().nullable(),tags:j(k()).nullable()}).loose(),M({id:k().min(1),kind:P(`external`),url:k().min(1),label:k()}).loose()]),UQ=M({source:k().min(1),target:k().min(1)}).loose(),WQ=M({nodes:j(HQ),links:j(UQ)}).loose(),GQ=M({ts:A().int().min(0),url:k(),method:k(),ua:k().optional(),origin:k().optional(),referer:k().optional(),host:k().optional(),remote:k().optional(),secChUa:k().optional(),secChUaMobile:k().optional(),secChUaPlatform:k().optional(),secFetchSite:k().optional(),secFetchDest:k().optional(),secFetchMode:k().optional(),secFetchUser:k().optional()}).loose(),KQ=M({app:Xs([P(`cursor`),P(`codex`),P(`claude`),zs()]),signals_fired:j(k())}).loose(),qQ=M({entries:j(GQ),count:A().int().min(0),detection:KQ}).loose(),JQ=M({writers:j(M({id:k().min(1),name:k().optional(),email:k().optional()}).loose()).optional(),summary:hq,...mq}).loose(),YQ=M({checkpointRef:k().min(1)}).loose(),XQ=M({v:A().int().optional(),id:k().min(1),name:k().min(1),colorSeed:k().optional(),docs:j(k()),summaries:j(k()).optional()}).loose(),ZQ=M({entries:j(M({sha:k().min(1),timestamp:k().min(1),author:k(),authorEmail:k(),type:N([`checkpoint`,`wip`,`upstream`,`park`]),message:k(),contributors:j(XQ),checkpoint:Us().nullable()}).loose()),total:A().int().nonnegative().optional(),truncated:Ls().optional()}).loose(),QQ=M({sha:k().regex(/^[0-9a-f]{40}$/i),content:k(),timestamp:k(),author:k()}).loose(),$Q=M({lines:j(M({type:N([`added`,`removed`,`unchanged`]),text:k()}).loose()),additions:A().int().nonnegative(),deletions:A().int().nonnegative()}).loose(),e$=M({contentDir:k().min(1),pathSeparator:N([`/`,`\\`]),symlinkResolved:Ls()}).loose(),t$=j(Qs(`source`,[M({docName:k().min(1),timestamp:k().min(1),size:A().int().nonnegative(),source:P(`flat`)}).loose(),M({docName:k().min(1),timestamp:k().min(1),source:P(`timeline`),sha:k().min(1)}).loose()])).meta({description:"Flat array of rescue buffer entries; discriminated via `source`."}),n$=M({orphans:j(M({docName:k().min(1),title:k()}).loose())}).loose(),r$=M({hubs:j(M({docName:k().min(1),title:k(),count:A().int().nonnegative()}).loose())}).loose(),i$=M({source:k().min(1),title:k(),snippet:k().nullable()}).loose(),a$=M({deadLinks:j(M({target:k().min(1),sources:j(i$)}).loose())}).loose(),o$=M({target:M({docName:k().min(1),title:k(),aliases:j(k())}).loose(),mentions:j(M({source:k().min(1),excerpt:k(),offset:A().int().nonnegative()}).loose()),truncated:Ls()}).loose(),s$=M({dir:k().min(1),port:A().int().min(1).max(65535).optional()}).loose(),c$=M({port:A().int().positive()}).loose(),l$=M({projectPath:k().min(1)}).loose(),u$=N([`not-a-git-worktree`,`init-failed`]),d$=Qs(`ok`,[M({ok:P(!0),projectPath:k().min(1)}).loose(),M({ok:P(!1),reason:u$,message:k().min(1)}).loose()]),f$=M({host:k().min(1).optional()}).loose(),p$=M({pat:k().min(1),host:k().min(1).optional()}).loose(),m$=M({name:k().refine(e=>e.trim().length>0,{message:`name must be non-empty`}),email:k().refine(e=>e.trim().length>0,{message:`email must be non-empty`})}).loose(),h$=M({identity:M({name:k().min(1),email:k().min(1)}).loose().nullable()}).loose(),g$=M({authenticated:Ls()}).loose(),_$=M({type:P(`complete`).optional(),login:k().min(1).optional()}).loose(),v$=M({}).loose(),y$=M({stackIndex:A().int().min(0),ts:A().int().min(0),additions:A().int().min(0),deletions:A().int().min(0)}).loose(),b$=M({docName:k().min(1),additionsTotal:A().int().min(0),deletionsTotal:A().int().min(0),lastTs:A().int().min(0),bursts:j(y$)}).loose(),x$=M({displayName:k().min(1),color:k().min(1),icon:k().optional(),connectionId:k().min(1)}).loose(),S$=M({sessionAlive:Ls(),agent:x$.nullable(),files:j(b$)}).loose(),C$=M({diff:k(),generatedAt:A().int().min(0)}).loose(),w$=M({}).loose(),T$=M({}).loose(),E$=M({}).loose(),D$=M({}).loose(),O$=M({}).loose(),k$=M({displayName:k().min(1),icon:k(),color:k().min(1),currentDoc:k().nullable(),mode:N([`idle`,`writing`]),ts:A().int().min(0)}).loose(),A$=M({presence:nc(k().min(1),k$)}).loose(),j$=nc(k().min(1),Ls()).meta({description:`Flat boolean record keyed by agent-scheme name (claude / codex / cursor). True = installed.`});M({path:k().min(1,`path must be non-empty`)}).loose();const M$=M({}).loose(),N$=M({fromDocName:k().min(1),toDocName:k().min(1)}).loose(),P$=M({fromPath:k().min(1),toPath:k().min(1)}).loose(),F$=M({}).loose(),I$=M({path:k().min(1),...mq,summary:hq}).loose(),L$=M({docName:k().min(1)}).loose(),R$=M({path:k().min(1),...mq,summary:hq}).loose(),z$=M({path:k().min(1)}).loose(),B$=M({kind:N([`file`,`folder`]),path:k().min(1),...mq,summary:hq}).loose(),V$=M({kind:N([`file`,`folder`]),path:k().min(1),duplicatedDocNames:j(k().min(1))}).loose(),H$=M({pages:j(M({docName:k().min(1),title:k(),docExt:k().min(1),size:A().int().nonnegative(),modified:k().min(1),icon:k().min(1).max(2048).optional()}).loose())}).loose(),U$=M({level:A().int().min(1).max(6),text:k(),slug:k()}).loose(),W$=M({docName:k().min(1),headings:j(U$)}).loose(),G$=M({docName:k().min(1),rewrites:A().int().nonnegative()}).loose(),K$=M({kind:N([`file`,`folder`,`asset`]),fromPath:k().min(1),toPath:k().min(1),...mq,summary:hq}).loose(),q$=M({renamed:j(N$),renamedAssets:j(P$),rewrittenDocs:j(G$).optional(),summary:xQ.optional()}).loose(),J$=M({kind:N([`file`,`folder`,`asset`]),path:k().min(1),...mq}).loose(),Y$=M({deletedDocNames:j(k().min(1))}).loose(),X$=M({kind:N([`file`,`folder`,`asset`]),path:k().min(1),...mq,summary:hq}).loose(),Z$=M({deletedDocNames:j(k().min(1))}).loose(),Q$=M({docName:k().min(1),commitSha:k().regex(/^[0-9a-f]{40}$/i,{message:`commitSha must be a 40-char git SHA`}),summary:hq,...mq}).loose(),$$=M({restoredFrom:k().min(1),timestamp:k().min(1),summary:xQ.optional(),warning:CQ.optional()}).loose(),e1=N([`dormant`,`idle`,`fetching`,`pulling`,`pushing`,`conflict`,`offline`,`auth-error`,`disabled`]),t1=M({label:k().min(1),webUrl:_s().nullable()}).loose(),n1=Qs(`checkStatus`,[M({checkStatus:P(`allowed`)}).loose(),M({checkStatus:P(`denied`),deniedReason:N([`no-collaborator`,`private-no-access`,`repo-not-found`])}).loose(),M({checkStatus:P(`unknown`),unknownError:N([`network`,`timeout`,`rate-limit`,`token-invalid`,`malformed-response`]).optional()}).loose()]),r1=N([`auth-403`,`auth-401`,`auth-scope-mismatch`,`semantic-protected-branch`]),i1=M({state:e1,lastSyncUtc:k().nullable(),lastFetchUtc:k().nullable(),lastPushedSha:k().nullable(),ahead:A().int().min(0),behind:A().int().min(0),consecutiveFailures:A().int().min(0),conflictCount:A().int().min(0),hasRemote:Ls(),syncEnabled:Ls(),identityUnresolved:Ls(),remote:t1.nullable().optional(),pushError:k().optional(),pushErrorCode:r1.optional(),pullError:k().optional(),pullErrorCode:r1.optional(),pausedReason:k().optional(),pushPermission:n1.optional()}).loose(),a1=M({op:N([`sync`,`push`,`pull`]).optional()}).loose(),o1=M({op:N([`sync`,`push`,`pull`])}).loose(),s1=M({conflicts:j(M({file:k().min(1),detectedAt:k().min(1),oursSha:k().optional(),theirsSha:k().optional(),baseSha:k().optional()}).loose())}).loose(),c1=M({file:k().min(1),strategy:N([`mine`,`theirs`,`content`,`delete`]),content:k().optional()}).loose().refine(e=>e.strategy!==`content`||e.content!==void 0&&e.content!==``,{message:`content must be a non-empty string when strategy is 'content'`,path:[`content`]}),l1=M({}).loose(),u1=M({file:k().min(1),base:k(),ours:k(),theirs:k(),kind:N([`both-modified`,`delete-modify`,`modify-delete`]),lifecycleStatus:k().nullable()}).loose(),d1=M({}).loose(),f1=M({plan:Ec(e=>e!==void 0,{message:`plan is required`})}).loose(),p1=M({plan:Ec(e=>e!==void 0,{message:`plan is required`})}).loose(),m1=M({result:Ec(e=>e!==void 0,{message:`result is required`})}).loose(),h1=M({path:k().min(1),summary:k().min(1)}).loose(),g1=M({files:A().int().nonnegative(),folders:A().int().nonnegative()}).loose(),_1=M({packs:j(M({id:k().min(1),name:k().min(1),description:k().min(1),defaultSubfolder:k().optional(),folders:j(h1),entryCounts:g1}).loose())}).loose(),v1=M({noOpen:Ls().optional(),out:k().min(1).optional()}).loose(),y1=M({reason:N([`unsupported-platform`,`spawn-error`]),message:k()}).loose(),b1=Qs(`status`,[M({status:P(`installed`),outputPath:k(),size:A().int().nonnegative(),sha256:k(),skillVersion:k()}).loose(),M({status:P(`built`),outputPath:k(),size:A().int().nonnegative(),sha256:k(),skillVersion:k(),handoffError:y1.optional()}).loose(),M({status:P(`failed`),buildError:k()}).loose(),M({status:P(`skip-current`),skillVersion:k(),recordedAt:k().optional()}).loose()]),x1=M({tags:j(M({name:k().min(1),count:A().int().nonnegative(),isLeaf:Ls()}).loose())}).loose(),S1=M({docName:k().min(1),title:k(),matchingTags:j(k().min(1)),snippet:k().nullable()}).loose(),C1=M({name:k().min(1),docs:j(S1)}).loose(),w1=M({folder:Us(),frontmatter_local:nc(k(),Us()).nullable()}).loose(),T1=M({path:k(),frontmatter:nc(k(),Us()).optional()}).loose(),E1=M({applied:Us()}).loose(),D1=nc(k(),Us()).meta({description:`Free-form frontmatter map embedded in template payloads.`}),O1=M({template:M({name:k().min(1),folder:k(),scope:N([`local`,`inherited`]),path:k().min(1),frontmatter:D1,body:k()}).strict()}).strict(),k1=M({templates:j(M({name:k().min(1),title:k().optional(),description:k().optional(),path:k().min(1),source_folder:k()}).strict()),truncated:Ls()}).strict(),A1=M({folder:k(),name:k(),body:k().optional(),frontmatter:D1.optional(),...mq,summary:hq}).strict(),j1=M({path:k().min(1),created:Ls(),warnings:j(k())}).strict(),M1=M({existed:Ls(),path:k().min(1)}).strict(),N1=M({fromFolder:k(),fromName:k(),toFolder:k(),toName:k(),body:k().optional(),frontmatter:D1.optional(),...mq,summary:hq}).strict(),P1=M({from:k().min(1),to:k().min(1),committed:Ls()}).strict(),F1=M({query:k().optional(),intent:N([`autocomplete`,`full_text`,`omnibar`]).optional(),scopes:j(N([`page`,`folder`,`content`])).optional(),scope:k().optional(),limit:A().int().nonnegative().optional()}).loose(),I1=M({kind:N([`page`,`folder`,`content`]),path:k().min(1),title:k(),score:A(),signals:nc(k(),Us()),snippet:k().optional()}).loose(),L1=M({query:k(),intent:N([`autocomplete`,`full_text`,`omnibar`]),results:j(I1),elapsedMs:A().nonnegative()}).loose(),R1=M({version:k().min(1),recordedAt:k().min(1)}).loose(),z1=M({currentVersion:k().min(1),targets:nc(k(),R1.nullable())}).loose(),B1=`server-info`,V1=`branch-switched`,H1=`disk-ack`,U1=`config-validation-rejected`,W1=`config-ignore-nested-error`,G1=N([`files`,`backlinks`,`graph`,`sync-status`,`session-activity`,`tags`]),K1=M({v:P(1),ch:P(B1),seq:A(),serverInstanceId:k().min(1),currentBranch:k().min(1).optional()}).loose(),q1=M({v:P(1),ch:P(V1),seq:A(),branch:k().min(1)}).loose(),J1=M({v:P(1),ch:G1,seq:A()}).loose(),Y1=M({v:P(1),ch:P(H1),seq:A(),docName:k().min(1),sv:k().min(1)}).loose(),X1=M({v:P(1),ch:P(U1),seq:A(),docName:k().min(1),error:il}).loose(),Z1=M({v:P(1),ch:P(W1),seq:A(),path:k().min(1),error:k().min(1)}).loose(),Q1={id:`string`,kind:`enum`,path:`string`,title:`string`,name:`string`,pathSegments:`string`,content:`string`,modifiedTs:`number`},$1=new WeakMap;function e0(e){return e===void 0||!Number.isFinite(e)?20:Math.max(1,Math.min(100,Math.trunc(e)))}function t0(e){return e.trim().toLowerCase()}function n0(e){let t=e.split(`/`).filter(Boolean);return t[t.length-1]??e}function r0(e){return e.split(`/`).filter(Boolean).join(` `)}function i0(e){let t=n0(e.path),n=e.title?.trim()||t,r=e.modifiedTs??0;return{id:`${e.kind}:${e.path}`,kind:e.kind,path:e.path,title:n,name:t,pathSegments:r0(e.path),content:e.content??``,modifiedTs:Number.isFinite(r)?r:0}}function a0(e){let t=kU({schema:Q1});return e.length>0&&BU(t,e),t}function o0(e){let t={documents:e};return $1.set(t,a0(e)),t}function s0(e){let t=$1.get(e);if(t)return t;let n=a0(e.documents);return $1.set(e,n),n}function c0(e){return e===`autocomplete`?[`page`]:e===`full_text`?[`page`,`content`]:[`page`,`folder`]}function l0(e,t){return t.has(e.kind)?!0:e.kind===`page`&&t.has(`content`)}function u0(e,t){let n=t0(t);if(!n)return 0;let r=t0(e.title),i=t0(e.name),a=t0(e.path),o=a.split(`/`);return r===n||i===n?700:a===n?650:r.startsWith(n)||i.startsWith(n)?600:o.some(e=>e.startsWith(n))?550:r.includes(n)||i.includes(n)?500:a.includes(n)?450:-1}function d0(e){let t=e.map(e=>e.modifiedTs).filter(e=>Number.isFinite(e)&&e>0);if(t.length===0)return new Map;let n=1/0,r=-1/0;for(let e of t)e<n&&(n=e),e>r&&(r=e);let i=Math.max(1,r-n);return new Map(e.map(e=>[e.id,e.modifiedTs>0?(e.modifiedTs-n)/i*50:0]))}function f0(e){return e===`full_text`?[`title`,`name`,`path`,`pathSegments`,`content`]:[`title`,`name`,`path`,`pathSegments`]}function p0(e){return e===`full_text`?{title:8,name:7,path:5,pathSegments:4,content:1}:e===`autocomplete`?{title:10,name:9,path:5,pathSegments:4}:{title:8,name:7,path:5,pathSegments:4}}function m0(e,t){return t0(t).length<4?0:e===`full_text`?1:0}function h0(e,t,n={}){let r=n.intent??`omnibar`,i=e0(n.limit),a=new Set(n.scopes??c0(r)),o=e.documents.filter(e=>l0(e,a)),s=t0(t);if(!s)return o.slice().sort((e,t)=>e.path.localeCompare(t.path)).slice(0,i).map(e=>({document:e,score:0,signals:{lexical:0,fullText:0,recency:0}}));let c=gW(s0(e),{term:s,properties:f0(r),boost:p0(r),tolerance:m0(r,s),limit:Math.max(i*4,40)}),l=new Map(c.hits.filter(e=>l0(e.document,a)).map(e=>[e.document.id,e.score])),u=d0(o),d=new Map;for(let e of o)u0(e,s)>=0&&d.set(e.id,e);for(let e of c.hits)l0(e.document,a)&&d.set(e.document.id,e.document);return[...d.values()].map(e=>{let t=Math.max(0,u0(e,s)),n=l.get(e.id)??0,r=u.get(e.id)??0;return{document:e,score:t+n*20+r,signals:{lexical:t,fullText:n,recency:r}}}).sort((e,t)=>e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score).slice(0,i)}function g0(e){let t=new TextEncoder().encode(e),n=new Uint8Array(1+t.length);return n[0]=1,n.set(t,1),_0(n)}function _0(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}const v0=Symbol.for(`@inkeep/open-knowledge/skill-state-field-registry`),y0=globalThis;y0[v0]===void 0&&(y0[v0]=Fi());const b0=y0[v0],x0=[`.ok`,`skill-state.yml`],S0=[`claude-cowork`,`cli-hosts`],C0=[`server-build-and-open`,`electron-build-and-open`,`cli-npx-skills-add`,`desktop-direct`,`cli-start`],w0=/^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/,T0=Js({version:k().regex(w0,`version must match /^\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?$/`).register(b0,{description:`Recorded skill version for this target.`}),recordedAt:Vo().register(b0,{description:`ISO 8601 timestamp of the most recent successful write. Updated on every write, including reinstalls of the same version.`}),surface:N(C0).register(b0,{description:`Install-source surface that recorded this entry.`}).optional()}),E0=Js({schema:P(1).register(b0,{description:`Schema major version. Bumped only on breaking shape changes.`}),targets:Js({"claude-cowork":T0.optional(),"cli-hosts":T0.optional()}).register(b0,{description:`Per-target install-state entries. Absent target = no recorded install.`}).default({})});function D0(){return{schema:1,targets:{}}}function O0(){let e=!1,t=``,n=0;return r=>{let i=k0(r);return e?(i&&i.char===t&&i.len>=n&&!i.hasInfo&&(e=!1,t=``,n=0),!0):i?(e=!0,t=i.char,n=i.len,!0):!1}}function k0(e){let t=(e.endsWith(`\r`)?e.slice(0,-1):e).match(/^ {0,3}([`~])(\1{2,})(.*)$/);return t?{char:t[1],len:1+t[2].length,hasInfo:t[3].trim()!==``}:null}const A0=[`#D97757`,`#1B1912`,`#F9F3E9`,`#7A9DFF`,`#8534F3`,`#9663F0`,`#727CF3`],j0={claude:`#D97757`,cursor:`#1B1912`,windsurf:`#0B100F`,openai:`#7A9DFF`,github:`#8534F3`,cline:`#9663F0`,bot:`#727CF3`};function M0(e,t=A0){let n=0;for(let t of e)n=(n<<5)-n+t.charCodeAt(0)|0;return t[Math.abs(n)%t.length]}const N0={"claude-code":`claude`,"claude-ai":`claude`,cursor:`cursor`,"cursor-vscode":`cursor`,cascade:`windsurf`,codex:`openai`,"codex-mcp-client":`openai`,copilot:`github`,cline:`cline`};function P0(e){return e?N0[e]||(e.startsWith(`local-agent-mode-`)?`claude`:`bot`):`bot`}const F0={claude:`Claude`,cursor:`Cursor`,windsurf:`Windsurf`,openai:`Codex`,github:`Copilot`,cline:`Cline`};function I0(e){let t=e?.trim();return t?F0[P0(t)]??t:`Agent`}function L0(e,t){let n=e.trim();if(!n||/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=r>=0?n.slice(0,r):n,a=r>=0?n.slice(r+1):null,o=(i.split(`?`)[0]??``).trim();if(!o)return null;let s=(o.split(`/`).pop()??``).match(/\.([a-z0-9]+)$/i);if(s){let e=(s[1]??``).toLowerCase();if(e!==`md`&&e!==`mdx`)return null}let c=o.toLowerCase(),l=c.endsWith(`.mdx`)?o.slice(0,-4):c.endsWith(`.md`)?o.slice(0,-3):o,u=l.startsWith(`/`),d=u?l.slice(1):l,f=u?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of d.split(`/`))if(e===`..`){if(f.length===0)return null;f.pop()}else e!==`.`&&e!==``&&f.push(e);return f.length===0?null:{docName:f.join(`/`),anchor:a||null}}const R0=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function z0(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function B0(e){let t=e.trim();return R0.test(t)||t.startsWith(`//`)}function V0(e,t){let n=e.trim();if(!n)return null;if(n.startsWith(`#`)){let e=n.slice(1).trim();return e?{kind:`anchor`,anchor:e}:null}if(B0(n))return{kind:`external`,url:n};let r=L0(n,t);if(r)return{kind:`doc`,docName:r.docName,anchor:r.anchor};let i=z0(n);return i&&i!==`md`&&i!==`mdx`?{kind:`asset`,url:n,ext:i}:null}function H0(e,t){let n=e.trim();if(!n)return null;if(B0(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=z0(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function U0(e,t){let n=e.trim();if(!n||R0.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=((r>=0?n.slice(0,r):n).split(`?`)[0]??``).trim();if(!i)return null;let a=i.startsWith(`/`),o=a?i.slice(1):i,s=a?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of o.split(`/`))if(e===`..`){if(s.length===0)return null;s.pop()}else e!==`.`&&e!==``&&s.push(e);return s.length===0?null:s.join(`/`)}function W0(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),t.startsWith(`/`)&&(t=t.slice(1)),t}function G0(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function K0(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function q0(e){return e.split(`/`).filter(e=>e!==``)}function J0(e,t){let n=K0(t);return e===``||n===e?!0:n.startsWith(`${e}/`)}function Y0(e,t){let n=K0(t);if(e===n)return 0;let r=e===``?n:n.slice(e.length+1);return r===``?0:q0(r).length}function X0(e,t){let n=q0(e),r=q0(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return n.length-i+(r.length-i)}function Z0(){let e=new Map;function t(t){let n=W0(t);if(n===``)return;let r=G0(n);if(r===``)return;let i=r.toLowerCase(),a=e.get(i);if(!a){e.set(i,[n]);return}a.includes(n)||a.push(n)}function n(t){let n=W0(t),r=G0(n).toLowerCase(),i=e.get(r);if(!i)return;let a=i.indexOf(n);a!==-1&&(i.splice(a,1),i.length===0&&e.delete(r))}function r(e,r){n(e),t(r)}function i(t,n){let r=t.toLowerCase(),i=e.get(r);if(!i||i.length===0)return null;if(i.length===1)return i[0];let a=K0(W0(n)),o=[],s=[];for(let e of i)J0(a,e)?o.push(e):s.push(e);return o.length>0?(e=>{let t=e[0],n=Y0(a,t);for(let r=1;r<e.length;r++){let i=e[r],o=Y0(a,i);(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(o):(e=>{let t=e[0],n=X0(a,K0(t));for(let r=1;r<e.length;r++){let i=e[r],o=X0(a,K0(i));(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(s)}function a(){let t=new Map;for(let[n,r]of e)t.set(n,[...r]);return t}function o(){e.clear()}return{add:t,remove:n,rename:r,resolveEmbed:i,clear:o,snapshot:a,size:()=>e.size}}function Q0(e){if(!e)return[];let t=e.split(`/`),n=[],r=``;for(let e of t)r=r?`${r}/${e}`:e,n.push(r);return n}function $0(e,t){if(e.size===0)return new Set;if(t===``)return new Set(e);let n=new Set,r=`${t}/`;for(let i of e)(i===t||i.startsWith(r))&&n.add(i);return n}function e2(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function t2(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function n2(){try{let e=_(g(b(import.meta.url)),`..`,`package.json`),t=JSON.parse(d(e,`utf-8`));if(typeof t.version==`string`&&t.version.length>0)return t.version}catch{}return`0.0.0-unknown`}const r2=n2(),i2=1;var a2=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`Open Knowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function o2(e,t){return _(e,`${t}.lock`)}const s2=new Map;function c2(e){s2.set(e,(s2.get(e)??0)+1)}function l2(e){let t=s2.get(e);return t===void 0||t<=1?(s2.delete(e),!0):(s2.set(e,t-1),!1)}function u2(e,t){try{let n=JSON.parse(d(e,`utf-8`));return n&&typeof n==`object`&&t2(n.pid)?n:(console.warn(`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return console.warn(`${t} Corrupt lock file at ${e} — replacing`),null}}function d2(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;l(n,{recursive:!0});let a=o2(n,t),o={pid:process.pid,hostname:y(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??r2},d=JSON.stringify(o,null,2);for(let e=0;e<3;e++){if(!c(a))try{let e=u(a,`wx`,384);try{m(e,d)}finally{s(e)}return c2(a),f2({lockName:t,lockDir:n,lockPath:a})}catch(e){if(e.code!==`EEXIST`)throw e}let e=u2(a,i);if(e){let r=e.hostname===y();if(r&&e.pid===process.pid)return p(a,d,{encoding:`utf-8`,mode:384}),c2(a),f2({lockName:t,lockDir:n,lockPath:a});if(r&&e2(e.pid))throw new a2(e,a,t);console.warn(`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{f(a)}catch{}}throw Error(`${i} Failed to acquire ${a} after 3 attempts (concurrent acquire contention).`)}function f2(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>g2({lockName:t,lockDir:n}),updatePort:e=>p2({lockName:t,lockDir:n,port:e})}}function p2(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,a=o2(n,t);if(!c(a)){console.warn(`${i} Lock file missing at ${a} during port update — skipping`);return}let o;try{let e=JSON.parse(d(a,`utf-8`));if(!e||typeof e!=`object`||!t2(e.pid)){console.warn(`${i} Corrupt lock at ${a} during port update — skipping`);return}o=e}catch{console.warn(`${i} Unreadable lock at ${a} during port update — skipping`);return}if(o.pid===process.pid&&!(typeof o.hostname==`string`&&o.hostname!==y())){o.port=r;try{p(a,JSON.stringify(o,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${i} Failed to update port in ${a}: ${e instanceof Error?e.message:String(e)}`)}}}function m2(e){let{lockName:t,lockDir:n}=e,r=o2(n,t);if(!c(r))return null;let i;try{let e=JSON.parse(d(r,`utf-8`));if(!e||typeof e!=`object`||!t2(e.pid))return null;i=e}catch{return null}if(i.hostname!==y())return null;if(!e2(i.pid)){try{f(r)}catch{}return null}return i}function h2(e){let{lockName:t,lockDir:n}=e,r=o2(n,t);if(!c(r))return{status:`absent`};let i;try{i=JSON.parse(d(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!t2(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o={pid:a.pid,hostname:a.hostname,port:a.port,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(o.hostname!==y())return{status:`stale`,lock:o};if(!e2(o.pid)){try{f(r)}catch{}return{status:`stale`,lock:o}}return o.protocolVersion===void 0||o.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:o}}function g2(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=o2(n,t);if(l2(i)&&c(i))try{let e=JSON.parse(d(i,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||typeof e.hostname==`string`&&e.hostname!==y())return;f(i)}catch(e){console.warn(`${r} Failed to release ${i}: ${e instanceof Error?e.message:String(e)}`)}}var _2=class extends a2{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function v2(e,t){try{return d2({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof a2&&e.lockName===`server`?new _2(e.existing,e.lockPath):e}}function y2(e,t){p2({lockName:`server`,lockDir:e,port:t})}function b2(e){return m2({lockName:`server`,lockDir:e})}function x2(e){g2({lockName:`server`,lockDir:e})}export{yG as $,_s as $i,O1 as $n,hQ as $r,RZ as $t,zq as A,Jc as Ai,Lq as An,zW as Ar,jQ as At,Y1 as B,Ec as Bi,Kq as Bn,HJ as Br,WQ as Bt,OQ as C,Uc as Ci,YQ as Cn,Z0 as Cr,qQ as Ct,DQ as D,al as Di,m1 as Dn,i0 as Dr,E1 as Dt,vQ as E,cl as Ei,p1 as En,o0 as Er,T1 as Et,tG as F,N as Fi,Eq as Fn,uq as Fr,qG as Ft,H1 as G,A as Gi,c1 as Gn,kG as Gr,_$ as Gt,V1 as H,ec as Hi,d1 as Hn,P0 as Hr,f$ as Ht,q1 as I,zs as Ii,Oq as In,JW as Ir,v1 as It,mG as J,kc as Ji,a1 as Jn,QW as Jr,Gq as Jt,B1 as K,M as Ki,l1 as Kn,kq as Kr,m$ as Kt,Z1 as L,Vs as Li,z1 as Ln,LZ as Lr,b1 as Lt,RQ as M,Hc as Mi,yq as Mn,D0 as Mr,ZQ as Mt,Nq as N,Ns as Ni,wq as Nn,g0 as Nr,QQ as Nt,_Q as O,fl as Oi,_1 as On,fG as Or,VQ as Ot,XW as P,sc as Pi,Cq as Pn,Q0 as Pr,r$ as Pt,bG as Q,Us as Qi,M1 as Qn,NG as Qr,c$ as Qt,X1 as R,j as Ri,E0 as Rn,oQ as Rr,j$ as Rt,yQ as S,ml as Si,JQ as Sn,M0 as Sr,GG as St,kQ as T,_l as Ti,L1 as Tn,RX as Tr,w1 as Tt,W1 as U,P as Ui,u1 as Un,jq as Ur,h$ as Ut,K1 as V,Qs as Vi,o$ as Vn,nq as Vr,v$ as Vt,U1 as W,Js as Wi,s1 as Wn,jW as Wr,p$ as Wt,xG as X,k as Xi,C1 as Xn,LW as Xr,d$ as Xt,SG as Y,nc as Yi,o1 as Yn,uG as Yr,l$ as Yt,vG as Z,Xs as Zi,x1 as Zn,PW as Zr,s$ as Zt,j0 as _,ft as _a,Rc as _i,x0 as _n,qW as _r,IQ as _t,d2 as a,ai as aa,oq as ai,MG as an,T$ as ar,z$ as at,S$ as b,bl as bi,jG as bn,H0 as br,V$ as bt,t2 as c,un as ca,YW as ci,W$ as cn,X$ as cr,JG as ct,h2 as d,on as da,dq as di,Hq as dn,Wq as dr,AG as dt,Vo as ea,HW as ei,A$ as en,N1 as er,Pq as et,b2 as f,Lt as fa,My as fi,K$ as fn,Uq as fr,CG as ft,y2 as g,pt as ga,zc as gi,$$ as gn,wW as gr,$Q as gt,p2 as h,D as ha,vl as hi,Q$ as hn,TW as hr,Y$ as ht,_2 as i,Wa as ia,h0 as ii,n$ as in,k1 as ir,R$ as it,zQ as j,Vc as ji,_q as jn,I0 as jr,kW as jt,EQ as k,Zc as ki,f1 as kn,dG as kr,AQ as kt,o2 as l,fn as la,$Z as li,H$ as ln,Z$ as lr,DG as lt,x2 as m,O as ma,F as mi,t$ as mn,TQ as mr,J$ as mt,r2 as n,da as na,U0 as ni,D$ as nn,A1 as nr,MQ as nt,v2 as o,vr as oa,NW as oi,PG as on,E$ as or,I$ as ot,g2 as p,Tt as pa,Sf as pi,q$ as pn,e$ as pr,a$ as pt,_G as q,cc as qi,i1 as qn,lK as qr,g$ as qt,i2 as r,Ua as ra,L0 as ri,OG as rn,j1 as rr,NQ as rt,e2 as s,cn as sa,$0 as si,pG as sn,w$ as sr,L$ as st,a2 as t,zo as ta,gQ as ti,O$ as tn,P1 as tr,Iq as tt,m2 as u,mn as ua,FW as ui,Rq as un,EG as ur,FG as ut,wG as v,Lc as vi,S0 as vn,Vq as vr,FQ as vt,bQ as w,Xc as wi,F1 as wn,O0 as wr,F$ as wt,C$ as x,yl as xi,gG as xn,hG as xr,TG as xt,KG as y,Ic as yi,w0 as yn,V0 as yr,B$ as yt,J1 as z,Ls as zi,M$ as zn,tQ as zr,cK as zt};
|
|
428
|
-
//# sourceMappingURL=server-lock-BpjJj3OD-
|
|
428
|
+
//# sourceMappingURL=server-lock-BpjJj3OD-DEuL_F6k.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as e}from"./server-lock-BpjJj3OD-DEuL_F6k.mjs";export{e as updateServerLockPort};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{c as n,l as r,s as i}from"./server-lock-BpjJj3OD-
|
|
1
|
+
import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{c as n,l as r,s as i}from"./server-lock-BpjJj3OD-DEuL_F6k.mjs";import"./gh-detect-BGpLt_9t.mjs";import{g as a,h as o,k as s}from"./init-DNFUwGbt.mjs";import{Dr as c}from"./dist-DLLsPJ9U.mjs";import"./loader-B_0kC5qP.mjs";import{c as l}from"./colors-BtKMHmBX.mjs";import"./preview-BP4tJ2Iu.mjs";import{n as u}from"./write-project-skill-BrFmZCMd.mjs";import{spawnSync as d}from"node:child_process";import{existsSync as f,lstatSync as p,readFileSync as m,readdirSync as h,statSync as ee}from"node:fs";import{basename as te,dirname as g,isAbsolute as _,join as v,relative as y,resolve as b}from"node:path";import{hostname as ne}from"node:os";import{readFile as x,realpath as S}from"node:fs/promises";function C(e,t,a={}){let o=r(e,t);if(!f(o))return{status:`missing`,lockPath:o};let s;try{s=JSON.parse(m(o,`utf-8`))}catch{return{status:`corrupt`,lockPath:o}}if(!s||typeof s!=`object`||!n(s.pid))return{status:`corrupt`,lockPath:o};let c=s;if(!(a.isAlive??i)(c.pid))return{status:`dead-pid`,lockPath:o,lock:c};let l=a.host??ne();return c.hostname===l?{status:`alive`,lockPath:o,lock:c}:{status:`foreign-host`,lockPath:o,lock:c}}function w(e){return e.replace(/:\d+$/,``)}function T(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:w(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:w(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:w(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function E(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`).filter(e=>e.length>0);if(n.length<5||n[2]!==`blob`)return null;let r,i,a,o;try{r=decodeURIComponent(n[0]),i=decodeURIComponent(n[1]),a=decodeURIComponent(n[3]),o=n.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!r||!i||!a||o.length===0||o.some(e=>e.length===0)?null:{owner:r,repo:i,branch:a,path:o.join(`/`)}}function D(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`);if(n.length<5||n[0]!==``||n[3]!==`tree`)return null;let r=n.slice(5);r.length===1&&r[0]===``&&r.pop();let i,a,o,s;try{i=decodeURIComponent(n[1]),a=decodeURIComponent(n[2]),o=decodeURIComponent(n[4]),s=r.map(e=>decodeURIComponent(e))}catch{return null}return!i||!a||!o||s.some(e=>e.length===0)?null:{owner:i,repo:a,branch:o,path:s.join(`/`)}}function O(e){let t=E(e);if(t)return{kind:`doc`,...t};let n=D(e);return n?{kind:`folder`,...n}:null}const k=2e3,A=2e3,re=[/cli\.mjs/,/(^|[\s/])(open-knowledge|ok)\s+(start|mcp|ui)(\s|$)/,/Open Knowledge(?:\.app| Helper)/,/(^|[\s/])bun([\s/]).*?(run dev|packages\/app|vite|hocuspocus)/,/(^|[\s/])node([\s/]).*?(packages\/(cli|app)|vite|hocuspocus)/,/(^|\s)--ok-lock-dir-b64=/,/(^|\s)--ok-project-path=/];function j(e){return re.some(t=>t.test(e))}function ie(e){let t=e.trim().split(/\s+/).find(e=>e.startsWith(`--ok-lock-dir-b64=`));if(t==null)return null;let n=t.slice(18);if(!n)return null;try{let e=Buffer.from(n,`base64url`).toString(`utf8`);return _(e)?e:null}catch{return null}}function ae(e){let t=e.indexOf(`--ok-project-path=`);if(t===-1)return null;let n=t+18,r=e.slice(n),i=r.search(/\s--/),a=(i===-1?r:r.slice(0,i)).trim();return a&&_(a)?a:null}function oe(e){let t=[];for(let n of e.split(`
|
|
2
2
|
`)){let e=n.trim();if(!e)continue;let r=e.indexOf(` `);if(r===-1)continue;let i=e.slice(0,r),a=e.slice(r+1),o=Number.parseInt(i,10);!Number.isNaN(o)&&j(a)&&t.push({pid:o,command:a})}return t}function se(e){let t=[],n=e.split(`
|
|
3
3
|
`);for(let e=1;e<n.length;e++){let r=n[e]?.trim();if(!r)continue;let i=r.indexOf(` `);if(i===-1)continue;let a=r.slice(0,i),o=r.slice(i+1).trim(),s=Number.parseInt(a,10);!Number.isNaN(s)&&j(o)&&t.push({pid:s,command:o})}return t}async function ce(){let e=d(`pgrep`,[`-a`,`-f`,`cli\\.mjs|open-knowledge|Open Knowledge(\\.app| Helper)|--ok-lock-dir-b64=|--ok-project-path=|(^|[ /])ok[ ]+(start|mcp|ui)([ ]|$)|packages/(cli|app)|hocuspocus|vite`],{encoding:`utf-8`,timeout:k});if(!(e.error!=null&&e.error.code===`ENOENT`)){let t=e.stdout??``,n=oe(t);if(n.length>0||t.trim()===``)return n}let t=d(`ps`,[`-axo`,`pid,command`],{encoding:`utf-8`,timeout:k});return t.error!=null||!t.stdout?[]:se(t.stdout)}function M(e){let t=e.trim().split(/\s+/).filter(Boolean);for(let e of t){if(e.startsWith(`@`))continue;let t=te(e);if(t===`open-knowledge`||t===`ok`||e.endsWith(`/packages/cli/src/cli.ts`)||e.endsWith(`/packages/cli/dist/cli.mjs`)||t===`cli.mjs`||t===`cli.ts`)return e}return null}function N(e){let t=d(`ps`,[`-p`,String(e),`-o`,`command=`],{encoding:`utf-8`,timeout:k});return t.error!=null||!t.stdout?null:t.stdout.trim()||null}function P(e){let t=d(`ps`,[`-p`,String(e),`-o`,`%cpu=,%mem=`],{encoding:`utf-8`,timeout:k});if(t.error!=null||!t.stdout)return null;let[n,r]=t.stdout.trim().split(/\s+/),i=Number.parseFloat(n??``),a=Number.parseFloat(r??``);return Number.isNaN(i)||Number.isNaN(a)?null:{cpuPercent:i,memPercent:a}}async function F(e){let t=d(`lsof`,[`-p`,String(e),`-a`,`-d`,`cwd`,`-Fn`],{encoding:`utf-8`,timeout:k});if(t.error!=null)return null;let n=t.stdout??``;for(let e of n.split(`
|
|
4
4
|
`))if(e.startsWith(`n`)&&e.length>1)return e.slice(1);return null}function I(e){let t=[],n=e.split(`
|
|
5
5
|
`);for(let e=1;e<n.length;e++){let r=n[e]?.trim();if(!r)continue;let i=r.split(/\s+/);if(i.length<2)continue;let a=Number.parseInt(i[1]??``,10);Number.isNaN(a)||t.push(a)}return[...new Set(t)]}function L(e){return f(v(e,`server.lock`))||f(v(e,`ui.lock`))}function R(e,t){for(let n of[v(t,`.ok`,`local`),v(t,`.ok`)])f(n)&&L(n)&&e.add(n)}function z(e,t){let n=0,r=(t,i)=>{if(n>=A||(n++,R(e,t),i>=3))return;let a;try{a=h(t)}catch{return}for(let e of a){if(n>=A)return;if(e===`node_modules`||e===`.git`||e===`Library`||e.startsWith(`.`)&&e!==`.ok`)continue;let a=v(t,e),o=!1;try{o=p(a).isDirectory()}catch{continue}o&&r(a,i+1)}};r(t,0)}async function B(){let e=new Set,t=await ce(),n=t.map(e=>F(e.pid)),r=await Promise.all(n);for(let n of t){let t=ie(n.command);t!=null&&f(t)&&e.add(t);let r=ae(n.command);r!=null&&R(e,r)}for(let t of r)t!=null&&R(e,t);let i=d(`lsof`,[`-iTCP`,`-sTCP:LISTEN`,`-nP`],{encoding:`utf-8`,timeout:k});if(i.error==null&&i.stdout){let n=I(i.stdout),r=new Set(t.map(e=>e.pid)),a=n.filter(e=>!r.has(e)).map(e=>F(e)),o=await Promise.all(a);for(let t of o)t!=null&&R(e,t)}(e.size===0||r.some(e=>e===`/`))&&z(e,process.cwd());let a=new Map;for(let t of e)try{let e=await S(t);a.set(e,e)}catch{a.set(t,t)}return[...a.values()]}var V=e(l(),1);function H(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function U(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function W(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,s=null;if(n.status!==`missing`&&n.status!==`corrupt`){let e=n.lock;s={port:e.port,status:n.status,pid:e.pid,startedAt:e.startedAt,usage:a}}return{directory:o.worktreeRoot,server:{port:o.port,status:t.status,pid:o.pid,startedAt:o.startedAt,usage:i},ui:s,hostname:o.hostname,lockPath:t.lockPath,binary:r==null?null:M(r),command:r,isDesktop:H(r)}}function G(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function K(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&G(e)?`ui-orphan`:`stale`}const le=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function ue(e){switch(e){case`running`:return V.default.green(e);case`desktop`:return V.default.blue(e);case`foreign`:return V.default.cyan(e);case`ui-orphan`:return V.default.magenta(e);case`stale`:return V.default.yellow(e)}}function q(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function de(e){return`${q(e.server.usage)} | ${q(e.ui?.usage??null)}`}function fe(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function pe(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>{let t=K(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,fe(e),de(e),t,String(n),U(e.server.startedAt),e.binary??`—`]}),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=ue(K(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=V.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
6
6
|
`)}async function J(e={}){let t=e.discover??B,n=e.inspect??C,r=e.log??(e=>console.log(e)),i=e.resolveCommand??N,a=e.resolveUsage??P,o=await t(),s=[];for(let e of o){let t=n(e,`server`),r=n(e,`ui`),o=W(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&s.push(o)}if(e.json){let e=s.map(e=>({...e,displayStatus:K(e)}));r(JSON.stringify(e,null,2));return}r(pe(e.all?s:s.filter(e=>le.has(K(e)))))}function me(){return new t(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await J({all:t.all===!0||e===`all`,json:t.json===!0})})}function he(e,t,n={}){let r=n.isAlive??i,a=[];for(let[n,i]of[[`server`,e],[`ui`,t]])(i.status===`alive`||i.status===`foreign-host`&&r(i.lock.pid))&&a.push({name:n,pid:i.lock.pid,port:i.lock.port});return{targets:a}}function Y(e){let t=e.inspect??(t=>C(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=he(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function X(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function Z(e,t=i){let n=await B(),r=null;for(let i of n){let n=C(i,`server`),a=C(i,`ui`);if(X(n,t)&&n.lock.port===e||X(a,t)&&a.lock.port===e)return i;r===null&&(X(n,t)&&n.lock.pid===e||X(a,t)&&a.lock.pid===e)&&(r=i)}return r}function Q(e){let t=Y({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function ge(e){return new t(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=Y({lockDir:c(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await J({});return}if(n===`all`){let e=await B();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e){let e=C(n,`server`),r=C(n,`ui`);!X(e,i)&&!X(r,i)||(Q(n),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(n)){let e=Number.parseInt(n,10),t=await Z(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}Q(t);return}Q(c(n))})}async function _e(e,t){let n,r;try{n=await S(b(e)),r=await S(b(g(e)))}catch{return{kind:`not-git`}}if(!$(n,r))return{kind:`symlink-escape`};let i=v(n,`.git`),a;try{a=ee(i)}catch{return{kind:`not-git`}}let o;if(a.isDirectory()){let e;try{e=await S(i)}catch{return{kind:`not-git`}}if(!$(e,n))return{kind:`symlink-escape`};o=e}else if(a.isFile()){let e;try{e=await x(i,`utf-8`)}catch{return{kind:`not-git`}}let t=/^gitdir:\s*(.+)$/m.exec(e.trim());if(!t)return{kind:`not-git`};let r=t[1].trim(),a=_(r)?r:b(n,r);try{o=await S(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let s=v(await ve(o),`config`),c;try{c=await x(s,`utf-8`)}catch{return{kind:`not-git`}}let l=be(c);if(l===null)return{kind:`no-origin`};let u=T(l);if(u===null||u.hostname!==`github.com`)return{kind:`non-github`};let d=u.owner.toLowerCase()===t.owner.toLowerCase(),f=u.name.toLowerCase()===t.repo.toLowerCase();return!d||!f?{kind:`wrong-repo`,actualOwner:u.owner,actualRepo:u.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${u.owner}/${u.name}.git`}}async function ve(e){let t;try{t=(await x(v(e,`commondir`),`utf-8`)).trim()}catch{return e}if(t.length===0)return e;let n=_(t)?t:b(e,t);try{return await S(n)}catch{return n}}function $(e,t){if(e===t)return!0;let n=y(t,e);return n.length>0&&!n.startsWith(`..`)&&!_(n)}function ye(e){let t=e.indexOf(`#`),n=e.indexOf(`;`),r=-1;return t>=0&&n>=0?r=Math.min(t,n):t>=0?r=t:n>=0&&(r=n),(r===-1?e:e.slice(0,r)).trim()}function be(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=ye(n);if(e.length===0)continue;if(e.startsWith(`[`)){t=/^\[\s*remote\s+["']origin["']\s*\]$/.test(e);continue}if(!t)continue;let r=/^url\s*=\s*(.+)$/.exec(e);if(r)return xe(r[1])}return null}function xe(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}const Se=[{id:`mcp-config`,write(e,t,n){let r=e.projectConfigPath?.(t);if(!r)return{integration:`mcp-config`,editorId:e.id,action:`skipped-unsupported`};try{let i=a(e,t,n,void 0,r);return i.action===`written`||i.action===`overwritten`?{integration:`mcp-config`,editorId:e.id,action:i.action,path:i.configPath}:i.action===`failed`?{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:i.error??`unknown failure`}:{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:`unexpected project-scope action: ${i.action}`}}catch(t){return{integration:`mcp-config`,editorId:e.id,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}},{id:`project-skill`,write(e,t,n){try{let n=u(e,t);return{integration:`project-skill`,editorId:e.id,action:n.action,...n.path?{path:n.path}:{},...n.error?{error:n.error}:{}}}catch(t){return{integration:`project-skill`,editorId:e.id,action:`failed`,error:t instanceof Error?t.message:String(t)}}}}];function Ce(e,t,n={},r=Se){let i=[];for(let a of t){let t=s[a];for(let a of r)i.push(a.write(t,e,n))}return i}function we(e,t,n={}){return{integrations:Ce(e,t,n),claudeLaunchJson:t.includes(`claude`)?o(e,n):void 0}}export{me as a,P as c,D as d,T as f,ge as i,E as l,_e as n,B as o,C as p,Y as r,N as s,we as t,O as u};
|
|
7
|
-
//# sourceMappingURL=src-
|
|
7
|
+
//# sourceMappingURL=src-Ad1isO-9.mjs.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,t}from"./esm-CEs3LWY3.mjs";import{bn as n,dt as r}from"./server-lock-BpjJj3OD-yLJv0roS.mjs";import{i,t as a}from"./gh-detect-BUPEzJp9.mjs";import{Bn as o,ar as s}from"./dist-peyy_Xqa.mjs";import{n as c}from"./constants-BXvmkg7Y.mjs";import{spawn as l}from"node:child_process";import{closeSync as u,existsSync as d,mkdirSync as f,openSync as p,statSync as m}from"node:fs";import{basename as h,dirname as g,join as _}from"node:path";import{homedir as v}from"node:os";import{setTimeout as y}from"node:timers/promises";const b=`Open Knowledge.app`,x=`/Applications/${b}`;function S(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return m(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function C(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(w(e,x))return x;let t=_(e.homeDir??v(),`Applications`,b);return w(e,t)?t:null}function w(e,t){try{let n=_(t,`Contents`,`MacOS`,`Open Knowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function T(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=C(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:e.isTTY!==!0||e.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function E(e){(e.log??(e=>console.error(e)))("Launching Open Knowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function D(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${x}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect desktop bundle at ${x} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${x} but launch dispatch did not fire (caller bug).`}}function O(e){return _(g(e),`..`,`Frameworks`,`Open Knowledge Server.app`,`Contents`,`MacOS`,`Open Knowledge Helper`)}const k=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function A(e){if(e.platform!==`darwin`||!k.test(e.execPath))return null;let t=O(e.execPath);return e.exists(t)?t:null}function j(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??d,a=r[1];return a?{command:A({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function M(e,t){return e.host??t.HOST??`localhost`}function N(e){let t=h(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var P=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function F(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function I(e){d(e.lockDir)||f(e.lockDir,{recursive:!0});let t=p(_(e.lockDir,n),`w`),r=e.spawn??l,{PORT:i,...a}=process.env,o=j();try{let n=r(o.command,[...o.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return n.unref(),n}finally{try{u(t)}catch{}}}function L(e,t,n){return e??(n===void 0?t:void 0)}function R(e,t){return e!==void 0&&t!==null&&t.port>0}function z(e,t,n){return e??(t!=null&&!n?1:0)}async function B(e){let t=e.spawn??l,n=j(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},c=()=>s(`SIGINT`),u=()=>s(`SIGTERM`);process.once(`SIGINT`,c),process.once(`SIGTERM`,u),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=z(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,c),process.removeListener(`SIGTERM`,u)}async function V(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const H=r;function U(e){let t=e.sigtermGraceMs??H,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>y(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function W(e){let{config:t,cwd:n,host:r}=e,c=e.skipAutoInit??!1,l=e.skipUiAutoSpawn??!1,u=e.idleThresholdMs??18e5,{existsSync:d,mkdirSync:f}=await import(`node:fs`),{basename:p,dirname:m}=await import(`node:path`),{bootServer:h,getLogger:g,isProcessAlive:_,readUiLock:v,resolveContentDir:b}=await import(`./dist-CuFjIU6M.mjs`),x=e.log??g(`start`),S=e.singleFile!==void 0,C=e.projectDir??n,w=S?s(e.singleFile).canonicalFilePath:void 0,T=w?m(w):void 0,E=w?p(w):void 0;if(!S){if(!c&&!o(n))throw new P(n);let t=process.env.OK_RECLAIM_DISABLE??null;try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-CeShfDta.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t})}catch(e){x.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-rjX_x5sN.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t})}catch(e){x.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-DnsSeH8x.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t})}catch(e){x.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let D=T??b(t,n);!S&&!d(D)&&(f(D,{recursive:!0}),x.info({contentDir:D},`Created content directory`));let O=null,k=async({lockDir:t})=>{if(O=F({uiLock:v(t),isAlive:_}),O.action===`spawn`&&!l)try{let r=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];I({lockDir:t,cwd:n,spawn:e.spawn,args:r}),x.info({reason:O.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else O.action===`skip`&&x.info({port:O.port,pid:O.pid},`UI already running at port ${O.port}`)},A=e.reactShellDistDir===void 0,j=i(),M=await h({config:t,contentDir:D,projectDir:S?C:n,contentRoot:S?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:a,tokenStore:j,...S?{ephemeral:!0,singleDocRelPath:E,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:A,idleShutdownMs:u,skipAutoInit:!0,...A?{spawnUiSiblingFn:k}:{},idleShutdownHandler:e=>U({readUiLock:()=>v(M.lockDir),isAlive:_,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:x}),log:x,...e.serveContentAssets?{serveContentAssets:!0}:{},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});O||={action:`skip`,reason:`alive`,pid:0,port:0};let N=O,L=null;if(N.action===`skip`)L=N.port>0?N.port:null;else if(!l){let t=e.uiBindTimeoutMs??3e3;L=await V({readUiLock:()=>v(M.lockDir),now:Date.now,sleep:e=>y(e),timeoutMs:t,pollIntervalMs:50}),L===null&&x.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:M.httpServer,destroy:M.destroy,lockDir:M.lockDir,contentDir:D,port:M.port,ready:M.ready,degraded:M.degraded,uiSpawnDecision:O,resolvedUiPort:L}}function G(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}function K(t){let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1||n>65535)throw new e(`--ui-port must be a port number between 1 and 65535`);return n}async function q(e,t){let{renderBanner:n}=await import(`./banner-D39r_H1d.mjs`),{dim:r,error:i,warning:a}=await import(`./colors-t2HkW8lF.mjs`),o=process.cwd(),s=e;process.title=N(o);let l=M(t,process.env),u=t.port===void 0?void 0:Number(t.port),d=process.env.PORT?Number(process.env.PORT):void 0,f=t.uiPort===void 0?void 0:Number(t.uiPort),p=L(u,d,f);if(f!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-CuFjIU6M.mjs`);if(R(f,e(t(o)))){await B({cwd:o,uiPort:f});return}}let m;try{m=await W({config:s,cwd:o,host:l,port:p,...f===void 0?{}:{uiPort:f},...t.serveContentAssets?{serveContentAssets:!0}:{},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{},...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof P&&(console.error(i(e.message)),process.exit(1));let t=await import(`./dist-CuFjIU6M.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(i(e.message)),process.exit(1)),f!==void 0&&J(e,t)){await B({cwd:o,uiPort:f});return}let n=Y(e,o,t);n!==null&&(console.error(i(n)),process.exit(1)),console.error(`${i(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let h=!1,g=async e=>{if(!h){h=!0,console.log(r(`\nShutting down (${e})`));try{await m.destroy()}catch(e){console.error(`${i(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)}};process.once(`SIGINT`,()=>{g(`SIGINT`)}),process.once(`SIGTERM`,()=>{g(`SIGTERM`)});let _=`http://${l}:${m.port}`,v=l===`0.0.0.0`||l===`::`?`http://0.0.0.0:${m.port}`:void 0,y=m.resolvedUiPort,b=y!==null&&y>0?`http://${l}:${y}`:_;console.log(n({name:`open-knowledge`,version:c,localUrl:b,apiUrl:b===_?void 0:_,networkUrl:v}));let x={"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`};m.ready.then(async()=>{if(m.degraded.length>0){console.log();for(let e of m.degraded){let t=x[e]??`${e} (check server logs for details)`;console.warn(` ${a(`⚠`)} ${a(e)}: ${r(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-C6LU_1mt.mjs`);e(b)}}).catch(e=>{console.error(` ${i(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function J(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function Y(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=_(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`Open Knowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function X(e){return new t(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,K).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,G).option(`--serve-content-assets`,`Serve content assets from this server`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
|
|
1
|
+
import{n as e,t}from"./esm-CEs3LWY3.mjs";import{bn as n,dt as r}from"./server-lock-BpjJj3OD-DEuL_F6k.mjs";import{i,t as a}from"./gh-detect-BGpLt_9t.mjs";import{Bn as o,ar as s}from"./dist-DLLsPJ9U.mjs";import{n as c}from"./constants-Chrt6UKP.mjs";import{spawn as l}from"node:child_process";import{closeSync as u,existsSync as d,mkdirSync as f,openSync as p,statSync as m}from"node:fs";import{basename as h,dirname as g,join as _}from"node:path";import{homedir as v}from"node:os";import{setTimeout as y}from"node:timers/promises";const b=`Open Knowledge.app`,x=`/Applications/${b}`;function S(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return m(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function C(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(w(e,x))return x;let t=_(e.homeDir??v(),`Applications`,b);return w(e,t)?t:null}function w(e,t){try{let n=_(t,`Contents`,`MacOS`,`Open Knowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function T(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=C(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:e.isTTY!==!0||e.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function E(e){(e.log??(e=>console.error(e)))("Launching Open Knowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function D(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${x}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect desktop bundle at ${x} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${x} but launch dispatch did not fire (caller bug).`}}function O(e){return _(g(e),`..`,`Frameworks`,`Open Knowledge Server.app`,`Contents`,`MacOS`,`Open Knowledge Helper`)}const k=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function A(e){if(e.platform!==`darwin`||!k.test(e.execPath))return null;let t=O(e.execPath);return e.exists(t)?t:null}function j(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??d,a=r[1];return a?{command:A({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function M(e,t){return e.host??t.HOST??`localhost`}function N(e){let t=h(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var P=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function F(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function I(e){d(e.lockDir)||f(e.lockDir,{recursive:!0});let t=p(_(e.lockDir,n),`w`),r=e.spawn??l,{PORT:i,...a}=process.env,o=j();try{let n=r(o.command,[...o.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return n.unref(),n}finally{try{u(t)}catch{}}}function L(e,t,n){return e??(n===void 0?t:void 0)}function R(e,t){return e!==void 0&&t!==null&&t.port>0}function z(e,t,n){return e??(t!=null&&!n?1:0)}async function B(e){let t=e.spawn??l,n=j(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},c=()=>s(`SIGINT`),u=()=>s(`SIGTERM`);process.once(`SIGINT`,c),process.once(`SIGTERM`,u),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=z(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,c),process.removeListener(`SIGTERM`,u)}async function V(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const H=r;function U(e){let t=e.sigtermGraceMs??H,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>y(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function W(e){let{config:t,cwd:n,host:r}=e,c=e.skipAutoInit??!1,l=e.skipUiAutoSpawn??!1,u=e.idleThresholdMs??18e5,{existsSync:d,mkdirSync:f}=await import(`node:fs`),{basename:p,dirname:m}=await import(`node:path`),{bootServer:h,getLogger:g,isProcessAlive:_,readUiLock:v,resolveContentDir:b}=await import(`./dist-CcfJnewj.mjs`),x=e.log??g(`start`),S=e.singleFile!==void 0,C=e.projectDir??n,w=S?s(e.singleFile).canonicalFilePath:void 0,T=w?m(w):void 0,E=w?p(w):void 0;if(!S){if(!c&&!o(n))throw new P(n);let t=process.env.OK_RECLAIM_DISABLE??null;try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-DP6bcoNL.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t})}catch(e){x.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-C3tWHctI.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t})}catch(e){x.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-B3uiMrne.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t})}catch(e){x.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let D=T??b(t,n);!S&&!d(D)&&(f(D,{recursive:!0}),x.info({contentDir:D},`Created content directory`));let O=null,k=async({lockDir:t})=>{if(O=F({uiLock:v(t),isAlive:_}),O.action===`spawn`&&!l)try{let r=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];I({lockDir:t,cwd:n,spawn:e.spawn,args:r}),x.info({reason:O.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else O.action===`skip`&&x.info({port:O.port,pid:O.pid},`UI already running at port ${O.port}`)},A=e.reactShellDistDir===void 0,j=i(),M=await h({config:t,contentDir:D,projectDir:S?C:n,contentRoot:S?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:a,tokenStore:j,...S?{ephemeral:!0,singleDocRelPath:E,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:A,idleShutdownMs:u,skipAutoInit:!0,...A?{spawnUiSiblingFn:k}:{},idleShutdownHandler:e=>U({readUiLock:()=>v(M.lockDir),isAlive:_,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:x}),log:x,...e.serveContentAssets?{serveContentAssets:!0}:{},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});O||={action:`skip`,reason:`alive`,pid:0,port:0};let N=O,L=null;if(N.action===`skip`)L=N.port>0?N.port:null;else if(!l){let t=e.uiBindTimeoutMs??3e3;L=await V({readUiLock:()=>v(M.lockDir),now:Date.now,sleep:e=>y(e),timeoutMs:t,pollIntervalMs:50}),L===null&&x.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:M.httpServer,destroy:M.destroy,lockDir:M.lockDir,contentDir:D,port:M.port,ready:M.ready,degraded:M.degraded,uiSpawnDecision:O,resolvedUiPort:L}}function G(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}function K(t){let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1||n>65535)throw new e(`--ui-port must be a port number between 1 and 65535`);return n}async function q(e,t){let{renderBanner:n}=await import(`./banner-D39r_H1d.mjs`),{dim:r,error:i,warning:a}=await import(`./colors-t2HkW8lF.mjs`),o=process.cwd(),s=e;process.title=N(o);let l=M(t,process.env),u=t.port===void 0?void 0:Number(t.port),d=process.env.PORT?Number(process.env.PORT):void 0,f=t.uiPort===void 0?void 0:Number(t.uiPort),p=L(u,d,f);if(f!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-CcfJnewj.mjs`);if(R(f,e(t(o)))){await B({cwd:o,uiPort:f});return}}let m;try{m=await W({config:s,cwd:o,host:l,port:p,...f===void 0?{}:{uiPort:f},...t.serveContentAssets?{serveContentAssets:!0}:{},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{},...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof P&&(console.error(i(e.message)),process.exit(1));let t=await import(`./dist-CcfJnewj.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(i(e.message)),process.exit(1)),f!==void 0&&J(e,t)){await B({cwd:o,uiPort:f});return}let n=Y(e,o,t);n!==null&&(console.error(i(n)),process.exit(1)),console.error(`${i(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let h=!1,g=async e=>{if(!h){h=!0,console.log(r(`\nShutting down (${e})`));try{await m.destroy()}catch(e){console.error(`${i(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)}};process.once(`SIGINT`,()=>{g(`SIGINT`)}),process.once(`SIGTERM`,()=>{g(`SIGTERM`)});let _=`http://${l}:${m.port}`,v=l===`0.0.0.0`||l===`::`?`http://0.0.0.0:${m.port}`:void 0,y=m.resolvedUiPort,b=y!==null&&y>0?`http://${l}:${y}`:_;console.log(n({name:`open-knowledge`,version:c,localUrl:b,apiUrl:b===_?void 0:_,networkUrl:v}));let x={"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`};m.ready.then(async()=>{if(m.degraded.length>0){console.log();for(let e of m.degraded){let t=x[e]??`${e} (check server logs for details)`;console.warn(` ${a(`⚠`)} ${a(e)}: ${r(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-C6LU_1mt.mjs`);e(b)}}).catch(e=>{console.error(` ${i(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function J(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function Y(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=_(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`Open Knowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function X(e){return new t(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,K).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,G).option(`--serve-content-assets`,`Serve content assets from this server`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
|
|
2
2
|
`),process.exit(2));let e=[];if(t.port!==void 0&&e.push(`--port`),t.uiPort!==void 0&&e.push(`--ui-port`),t.host!==void 0&&e.push(`--host`),e.length>0){let t=process.env.OK_LOG_LEVEL??`info`;(t===`debug`||t===`trace`)&&console.error(`--mode=app: ignoring ${e.join(`, `)}`)}let n=T(S());if(n.available){E({spawn:l});return}console.error(D(n.reason)),process.exit(1)}await q(n,t)})}export{j as _,z as a,E as b,N as c,M as d,q as f,Y as g,X as h,U as i,J as l,I as m,V as n,B as o,R as p,W as r,F as s,P as t,L as u,S as v,T as y};
|
|
3
|
-
//# sourceMappingURL=start-
|
|
3
|
+
//# sourceMappingURL=start-BF1QWSQY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as e,h as t,r as n}from"./start-BF1QWSQY.mjs";export{n as bootStartServer,e as resolveHost,t as startCommand};
|