@vpxa/aikit 0.1.132 → 0.1.134

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpxa/aikit",
3
- "version": "0.1.132",
3
+ "version": "0.1.134",
4
4
  "type": "module",
5
5
  "description": "Local-first AI developer toolkit — knowledge base, code analysis, context management, and developer tools for LLM agents",
6
6
  "license": "MIT",
@@ -3747,7 +3747,7 @@ ${e.themeCSS}`),e.fontFamily!==void 0&&(n+=`
3747
3747
  :root { --mermaid-alt-font-family: ${e.altFontFamily}}`),t instanceof Map){let r=ov(e)?[`> *`,`span`]:[`rect`,`polygon`,`ellipse`,`circle`,`path`];t.forEach(e=>{UP(e.styles)||r.forEach(t=>{n+=D9(e.id,t,e.styles)}),UP(e.textStyles)||(n+=D9(e.id,`tspan`,(e?.textStyles||[]).map(e=>e.replace(`color`,`fill`))))})}return n},`createCssStyles`),ndt=V((e,t,n,r)=>ZW(KJe(`${r}{${Sde(t,tdt(e,n),{...e.themeVariables,theme:e.theme,look:e.look},r)}}`),QJe),`createUserStyles`),rdt=V((e=``,t,n)=>{let r=e;return!n&&!t&&(r=r.replace(/marker-end="url\([\d+./:=?A-Za-z-]*?#/g,`marker-end="url(#`)),r=bD(r),r=r.replace(/<br>/g,`<br/>`),r},`cleanUpSvgCode`),idt=V((e=``,t)=>`<iframe style="width:${qut};height:${t?.viewBox?.baseVal?.height?t.viewBox.baseVal.height+`px`:Jut};${Yut}" src="data:text/html;charset=UTF-8;base64,${Xlt(`<body style="${Xut}">${e}</body>`)}" sandbox="${Zut}">
3748
3748
  ${Qut}
3749
3749
  </iframe>`,`putIntoIFrame`),O9=V((e,t,n,r,i)=>{let a=e.append(`div`);a.attr(`id`,n),r&&a.attr(`style`,r);let o=a.append(`svg`).attr(`id`,t).attr(`width`,`100%`).attr(`xmlns`,Wut);return i&&o.attr(`xmlns:xlink`,i),o.append(`g`),e},`appendDivSvgG`),V(W7,`sandboxedIframe`),adt=V((e,t,n,r)=>{e.getElementById(t)?.remove(),e.getElementById(n)?.remove(),e.getElementById(r)?.remove()},`removeExistingElements`),odt=V(async function(e,t,n){w9();let r=U7(t);t=r.code;let i=Z_();H.debug(i),t.length>(i?.maxTextSize??But)&&(t=Vut);let a=`#`+e,o=`i`+e,s=`#`+o,l=`d`+e,u=`#`+l,d=V(()=>{let e=Ny(p?s:u).node();e&&`remove`in e&&e.remove()},`removeTempElements`),f=Ny(`body`),p=i.securityLevel===Hut,m=i.securityLevel===Uut,h=i.fontFamily;n===void 0?(adt(document,e,l,o),p?(f=Ny(W7(Ny(`body`),o).nodes()[0].contentDocument.body),f.node().style.margin=0):f=Ny(`body`),O9(f,e,l)):(n&&(n.innerHTML=``),p?(f=Ny(W7(Ny(n),o).nodes()[0].contentDocument.body),f.node().style.margin=0):f=Ny(n),O9(f,e,l,`font-family: ${h}`,Gut));let g,_;try{g=await T9.fromText(t,{title:r.title})}catch(e){if(i.suppressErrorRendering)throw d(),e;g=await T9.fromText(`error`),_=e}let v=f.select(u).node(),y=g.type,b=v.firstChild,x=b.firstChild,S=g.renderer.getClasses?.(t,g),C=ndt(i,y,S,a),w=document.createElement(`style`);w.innerHTML=C,b.insertBefore(w,x);try{await g.renderer.draw(t,e,`11.14.0`,g)}catch(n){throw i.suppressErrorRendering?d():_ut.draw(t,e,`11.14.0`),n}let T=f.select(`${u} svg`),E=g.db.getAccTitle?.(),D=g.db.getAccDescription?.();$lt(y,T,E,D),f.select(`[id="${e}"]`).selectAll(`foreignobject > *`).attr(`xmlns`,Kut);let O=f.select(u).node().innerHTML;if(H.debug(`config.arrowMarkerAbsolute`,i.arrowMarkerAbsolute),O=rdt(O,p,B_(i.arrowMarkerAbsolute)),p){let e=f.select(u+` svg`).node();O=idt(O,e)}else m||(O=Ff.sanitize(O,{ADD_TAGS:$ut,ADD_ATTR:edt,HTML_INTEGRATION_POINTS:{foreignobject:!0}}));if(Fut(),_)throw _;return d(),{diagramType:y,svg:O,bindFunctions:g.db.bindFunctions}},`render`),V(Qlt,`initialize`),k9=V((e,t={})=>{let{code:n}=H7(e);return T9.fromText(n,t)},`getDiagramFromText`),V($lt,`addA11yInfo`),A9=Object.freeze({render:odt,parse:Zlt,getDiagramFromText:k9,initialize:Qlt,getConfig:Z_,setConfig:X_,getSiteConfig:Y_,updateSiteConfig:J_,reset:V(()=>{ev()},`reset`),globalReset:V(()=>{ev(z_)},`globalReset`),defaultConfig:z_}),xd(Z_().logLevel),ev(Z_()),sdt=V((e,t,n)=>{H.warn(e),oD(e)?(n&&n(e.str,e.hash),t.push({...e,message:e.str,error:e})):(n&&n(e),e instanceof Error&&t.push({str:e.message,message:e.message,hash:e.name,error:e}))},`handleError`),j9=V(async function(e={querySelector:`.mermaid`}){try{await cdt(e)}catch(t){if(oD(t)&&H.error(t.str),R9.parseError&&R9.parseError(t),!e.suppressErrors)throw H.error(`Use the suppressErrors option to suppress these errors`),t}},`run`),cdt=V(async function({postRenderCallback:e,querySelector:t,nodes:n}={querySelector:`.mermaid`}){let r=A9.getConfig();H.debug(`${e?``:`No `}Callback function found`);let i;if(n)i=n;else if(t)i=document.querySelectorAll(t);else throw Error(`Nodes and querySelector are both undefined`);H.debug(`Found ${i.length} diagrams`),r?.startOnLoad!==void 0&&(H.debug(`Start On Load: `+r?.startOnLoad),A9.updateSiteConfig({startOnLoad:r?.startOnLoad}));let a=new yD.InitIDGenerator(r.deterministicIds,r.deterministicIDSeed),o,s=[];for(let t of Array.from(i)){if(H.info(`Rendering diagram: `+t.id),t.getAttribute(`data-processed`))continue;t.setAttribute(`data-processed`,`true`);let n=`mermaid-${a.next()}`;o=t.innerHTML,o=EAe(yD.entityDecode(o)).trim().replace(/<br\s*\/?>/gi,`<br/>`);let r=yD.detectInit(o);r&&H.debug(`Detected early reinit: `,r);try{let{svg:r,bindFunctions:i}=await L9(n,o,t);t.innerHTML=r,e&&await e(n),i&&i(t)}catch(e){sdt(e,s,R9.parseError)}}if(s.length>0)throw s[0]},`runThrowsErrors`),M9=V(function(e){A9.initialize(e)},`initialize`),ldt=V(async function(e,t,n){H.warn(`mermaid.init is deprecated. Please use run instead.`),e&&M9(e);let r={postRenderCallback:n,querySelector:`.mermaid`};typeof t==`string`?r.querySelector=t:t&&(t instanceof HTMLElement?r.nodes=[t]:r.nodes=t),await j9(r)},`init`),udt=V(async(e,{lazyLoad:t=!0}={})=>{w9(),n_(...e),t===!1&&await Nut()},`registerExternalDiagrams`),N9=V(function(){if(R9.startOnLoad){let{startOnLoad:e}=A9.getConfig();e&&R9.run().catch(e=>H.error(`Mermaid failed to initialize`,e))}},`contentLoaded`),typeof document<`u`&&window.addEventListener(`load`,N9,!1),ddt=V(function(e){R9.parseError=e},`setParseErrorHandler`),P9=[],F9=!1,I9=V(async()=>{if(!F9){for(F9=!0;P9.length>0;){let e=P9.shift();if(e)try{await e()}catch(e){H.error(`Error executing queue`,e)}}F9=!1}},`executeQueue`),fdt=V(async(e,t)=>new Promise((n,r)=>{let i=V(()=>new Promise((i,a)=>{A9.parse(e,t).then(e=>{i(e),n(e)},e=>{H.error(`Error parsing`,e),R9.parseError?.(e),a(e),r(e)})}),`performCall`);P9.push(i),I9().catch(r)}),`parse`),L9=V((e,t,n)=>new Promise((r,i)=>{let a=V(()=>new Promise((a,o)=>{A9.render(e,t,n).then(e=>{a(e),r(e)},e=>{H.error(`Error parsing`,e),R9.parseError?.(e),o(e),i(e)})}),`performCall`);P9.push(a),I9().catch(i)}),`render`),R9={startOnLoad:!0,mermaidAPI:A9,parse:fdt,render:L9,init:ldt,run:j9,registerExternalDiagrams:udt,registerLayoutLoaders:xW,initialize:M9,parseError:void 0,contentLoaded:N9,setParseErrorHandler:ddt,detectType:t_,registerIconPacks:NO,getRegisteredDiagramsMetadata:V(()=>Object.keys(e_).map(e=>({id:e})),`getRegisteredDiagramsMetadata`)},pdt=R9}));ed();function z9(e){if(typeof e==`string`)return hdt(e);if(Array.isArray(e))return e.length===0?B9(`*Empty array*`):typeof e[0]==`object`&&e[0]!==null?H9(e):B9(e.map(e=>`- ${String(e)}`).join(`
3750
- `));if(typeof e==`object`&&e){let t=e;return Array.isArray(t.nodes)&&Array.isArray(t.edges)?Edt(t):Array.isArray(t.metrics)?Tdt(t.metrics):U9(t)}return B9(String(e))}function hdt(e){let t=e.trim();if(/^(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|gitGraph)\b/i.test(t))return V9(t);if(/^#{1,6}\s|^\s*[-*]\s|\*\*|__|\[.*\]\(|```/.test(t))return B9(t);if((t.startsWith(`{`)||t.startsWith(`[`))&&(t.endsWith(`}`)||t.endsWith(`]`)))try{return z9(JSON.parse(t))}catch{}return B9(t)}function gdt(e,t,n){let r=B(`div`,`comparison-side ${n}`),i=e&&typeof e==`object`&&!Array.isArray(e)?e:null,a=String(i?.label??i?.title??t),o=Array.isArray(i?.items)?i.items:Array.isArray(e)?e:e==null?[]:[e];r.appendChild(B(`div`,`comparison-label`,a));let s=B(`ul`,`comparison-items`);for(let e of o)s.appendChild(B(`li`,``,od(e)));return r.appendChild(s),r}function _dt(e){let t=B(`div`,`actions`);for(let n of e){if(n.type===`select`&&n.options){let e=document.createElement(`select`);e.className=`action-select`;let r=document.createElement(`option`);r.textContent=n.label,r.disabled=!0,r.selected=!0,e.appendChild(r);for(let t of n.options){let n=document.createElement(`option`);typeof t==`string`?(n.value=t,n.textContent=t):(n.value=t.value,n.textContent=t.label),e.appendChild(n)}t.appendChild(e);continue}let e=document.createElement(`button`);e.className=`action-btn ${n.variant??`default`}`,e.textContent=n.label,t.appendChild(e)}return t}function vdt(e,t){switch(e.type){case`markdown`:return B9(String(e.value??``));case`mermaid`:return V9(String(e.value??``));case`table`:{let t=e.value;if(Array.isArray(t)){if(t.length>0&&Array.isArray(t[0])){let e=t,n=e[0].map(String);return H9(e.slice(1).map(e=>Object.fromEntries(n.map((t,n)=>[t,e[n]]))))}return H9(t)}if(t&&typeof t==`object`&&`headers`in t&&`rows`in t){let{headers:e,rows:n}=t;return H9(n.map(t=>Object.fromEntries(e.map((e,n)=>[e,t[n]]))))}return H9([])}case`code`:return Cdt(String(e.value??``),e.language);case`tree`:return U9(e.value);case`cards`:return wdt(e.value);case`metrics`:return Tdt(e.value);case`graph`:return Edt(e.value);case`chart`:return xce(e);case`kv`:{let t=e.value;return t&&typeof t==`object`&&!Array.isArray(t)?H9(Object.entries(t).map(([e,t])=>({Key:e,Value:t}))):B9(JSON.stringify(t,null,2))}case`comparison`:{let t=e.value;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t;if(`left`in e||`right`in e){let t=B(`div`,`block block-comparison`);return t.appendChild(gdt(e.left,`Left`,`comparison-left`)),t.appendChild(gdt(e.right,`Right`,`comparison-right`)),t}if(Array.isArray(e.headers)&&Array.isArray(e.rows)){let t=e.headers;return H9(e.rows.map(e=>Object.fromEntries(t.map((t,n)=>[t,e[n]]))))}if(Array.isArray(e.columns)){let t=e.columns,n=Math.max(...t.map(e=>e.items?.length??0)),r=[];for(let e=0;e<n;e++){let n={};for(let r of t)n[r.name]=r.items?.[e]??``;r.push(n)}return H9(r)}}return B9(JSON.stringify(t,null,2))}case`actions`:{let n=Array.isArray(e.value)?e.value:[],r=t?Ddt(n,t):_dt(n);return r.classList.add(`block`,`block-actions`),r}case`timeline`:{let t=e.value;return Array.isArray(t)?H9(t.map(e=>{if(e&&typeof e==`object`){let t=e;return{Status:t.status??t.state??``,Time:t.time??t.date??t.timestamp??``,Description:t.label??t.description??t.title??t.text??``}}return{Status:``,Time:``,Description:String(e)}})):B9(JSON.stringify(t,null,2))}case`heading`:return B9(`## ${String(e.value??``)}`);case`checklist`:{let t=Array.isArray(e.value)?e.value:e.value?.items;if(!Array.isArray(t))return B9(JSON.stringify(e.value,null,2));let n=B(`div`,`block block-checklist`);for(let e of t){let t=B(`div`,`checklist-item ${e.checked?`checked`:``}`),r=B(`div`,`checklist-check ${e.checked?`checked`:``}`,e.checked?`✓`:``),i=B(`div`,``);i.appendChild(B(`div`,`checklist-label`,String(e.label??``))),e.note&&i.appendChild(B(`div`,`checklist-note`,String(e.note))),t.appendChild(r),t.appendChild(i),n.appendChild(t)}return n}case`status-board`:{let t=e.value,n=[];if(Array.isArray(t))for(let e of t)if(Array.isArray(e.items)){let t=e.category?.trim();for(let r of e.items)n.push({...r,label:t?`${t}: ${r.label}`:r.label})}else n.push(e);else t&&typeof t==`object`&&Array.isArray(t.items)&&n.push(...t.items);if(n.length===0)return B9(JSON.stringify(e.value,null,2));let r=B(`div`,`block block-status-board`);for(let e of n){let t=B(`div`,`status-row`);t.appendChild(B(`div`,`status-indicator ${e.status??`pending`}`,``)),t.appendChild(B(`span`,`status-label`,String(e.label??``))),e.detail&&t.appendChild(B(`span`,`status-detail`,String(e.detail))),r.appendChild(t)}return r}case`prompt`:{let t=e.value;if(!t?.question)return B9(JSON.stringify(e.value,null,2));let n=B(`div`,`block block-prompt prompt-block`);return n.appendChild(B(`div`,`prompt-question`,String(t.question))),t.context&&n.appendChild(B(`div`,`prompt-context`,String(t.context))),t.placeholder&&n.appendChild(B(`div`,`prompt-placeholder`,String(t.placeholder))),n}case`progress`:{let t;if(Array.isArray(e.value))t=e.value;else if(e.value&&typeof e.value==`object`){let n=e.value;t=Array.isArray(n.items)?n.items:[n]}else return B9(JSON.stringify(e.value,null,2));let n=B(`div`,`block block-progress progress-list`);for(let e of t){let t=typeof e.max==`number`?e.max:100,r=typeof e.value==`number`?e.value:0,i=t>0?Math.min(100,r/t*100):0,a=(typeof e.color==`string`?e.color:``)||(i>=100?`var(--success, #22c55e)`:i>=60?`var(--primary, #818cf8)`:i>=30?`var(--warning, #f59e0b)`:`var(--error, #ef4444)`),o=B(`div`,`progress-item`),s=B(`div`,`progress-header`);s.appendChild(B(`span`,`progress-label`,String(e.label??``))),s.appendChild(B(`span`,`progress-value`,`${r}/${t}`)),o.appendChild(s);let l=B(`div`,`progress-track`),u=B(`div`,`progress-fill`);u.style.width=`${i.toFixed(1)}%`,u.style.background=a,l.appendChild(u),o.appendChild(l),n.appendChild(o)}return n}case`viewer-link`:{let t=e.value,n=(typeof t.label==`string`?t.label.trim():``)||(typeof t.viewerType==`string`?t.viewerType.trim():``)||`Open viewer`,r=typeof t.description==`string`?t.description.trim():``,i=typeof t.icon==`string`&&t.icon.trim()||`🔗`,a=B(`div`,`block block-viewer-link`);a.style.borderLeft=`4px solid var(--color-primary, #818cf8)`,a.style.padding=`12px 16px`,a.style.borderRadius=`8px`,a.style.background=`var(--color-card, #1e293b)`;let o=B(`div`,``,`${i} ${n}`);if(o.style.fontWeight=`600`,a.appendChild(o),r){let e=B(`div`,``,r);e.style.fontSize=`0.85rem`,e.style.color=`var(--color-muted, #94a3b8)`,a.appendChild(e)}if(t?.url){let e=String(t.url).trim();if(/^https?:\/\//i.test(e)||/^file:\/\//i.test(e)){let t=document.createElement(`a`);return t.href=e,t.target=`_blank`,t.rel=`noopener noreferrer`,t.style.color=`inherit`,t.style.textDecoration=`none`,t.appendChild(a.cloneNode(!0)),t}}return a}case`docs-browser`:{let t=e.value,n=Array.isArray(t?.files)?t.files:[],r=B(`div`,`block block-docs-browser`);r.style.border=`1px solid var(--color-border, #334155)`,r.style.borderRadius=`8px`,r.style.overflow=`hidden`;let i=typeof t.title==`string`?t.title.trim():``;if(i){let e=B(`div`,``,i);e.style.padding=`12px`,e.style.fontWeight=`600`,r.appendChild(e)}if(n.length===0)return r.appendChild(B(`div`,``,`No documentation files.`)),r;for(let[e,t]of n.entries()){let n=document.createElement(`details`);e===0&&(n.open=!0);let i=document.createElement(`summary`);i.style.cssText=`padding:8px 12px; cursor:pointer; display:flex; align-items:center; justify-content:space-between; gap:12px;`;let a=t?.path?.trim()||`document-${e+1}`,o=t?.title?.trim()||a.split(/[\\/]/).pop()||a,s=B(`div`,``);s.appendChild(B(`span`,``,a));let l=s.firstElementChild;l instanceof HTMLElement&&(l.style.cssText=`font-family:monospace; font-size:0.85rem; color:var(--color-muted, #94a3b8);`);let u=B(`span`,``,o);if(u.style.fontWeight=`600`,s.appendChild(u),i.appendChild(s),t?.status){let e=B(`span`,``,t.status),n={current:`background:#14532d; color:#bbf7d0;`,stale:`background:#713f12; color:#fde68a;`,missing:`background:#7f1d1d; color:#fecaca;`};e.style.cssText=`padding:2px 8px; border-radius:999px; font-size:0.75rem; text-transform:uppercase; ${n[t.status]||``}`,i.appendChild(e)}n.appendChild(i);let d=B(`div`,``);d.style.cssText=`padding:12px; border-top:1px solid var(--color-border, #334155);`,t?.content?.trim()?d.appendChild(B9(t.content)):d.appendChild(B(`div`,``,`No content available.`)),n.appendChild(d),r.appendChild(n)}return r}case`text`:return B9(String(e.value??``));case`paragraph`:{let t=document.createElement(`p`);return t.textContent=String(e.value??``),t.classList.add(`block`,`block-paragraph`),t}case`separator`:{let e=document.createElement(`hr`);return e.classList.add(`block`,`block-separator`),e}default:return B9(JSON.stringify(e.value,null,2))}}function ydt(e,t){let n=vdt(e,t);return e.title&&n.insertBefore(B(`div`,`block-title`,e.title),n.firstChild),n}function B9(e){let t=B(`div`,`block block-markdown`);return t.innerHTML=uce(e),t}var bdt=null;function xdt(){return bdt||=$u(()=>Promise.resolve().then(()=>(mdt(),Klt)).then(e=>(e.default.initialize({startOnLoad:!1,theme:`default`}),e.default)),void 0,import.meta.url),bdt}var Sdt=0;function V9(e){let t=B(`div`,`block block-mermaid`),n=B(`pre`,`mermaid-source`,e);t.appendChild(n);let r=`mermaid-${++Sdt}`;return xdt().then(t=>t.render(r,e)).then(({svg:e})=>{t.innerHTML=e}).catch(()=>{n.classList.add(`mermaid-fallback`)}),t}function H9(e){let t=B(`div`,`block block-table`);if(e.length===0)return B9(`*Empty table*`);let n=Object.keys(e[0]),r=-1,i=!0,a=[...e],o=``,s=document.createElement(`input`);s.className=`table-filter`,s.placeholder=`Filter...`,s.addEventListener(`input`,()=>{o=s.value.toLowerCase(),p()}),t.appendChild(s);let l=document.createElement(`table`),u=document.createElement(`thead`),d=document.createElement(`tr`);n.forEach((e,t)=>{let n=document.createElement(`th`);n.textContent=e;let a=B(`span`,`sort-icon`,`⇅`);n.appendChild(a),n.addEventListener(`click`,()=>{r===t?i=!i:(r=t,i=!0),p()}),d.appendChild(n)}),u.appendChild(d),l.appendChild(u);let f=document.createElement(`tbody`);l.appendChild(f),t.appendChild(l);function p(){if(a=[...e],o&&(a=a.filter(e=>n.some(t=>String(e[t]??``).toLowerCase().includes(o)))),r>=0){let e=n[r];a.sort((t,n)=>{let r=String(t[e]??``),a=String(n[e]??``),o=r.localeCompare(a,void 0,{numeric:!0});return i?o:-o})}f.innerHTML=``;for(let e of a){let t=document.createElement(`tr`);for(let r of n){let n=document.createElement(`td`);n.textContent=String(e[r]??``),t.appendChild(n)}f.appendChild(t)}}return p(),t}function Cdt(e,t){let n=B(`div`,`block block-code`),r=B(`div`,`code-header`);r.appendChild(B(`span`,``,t??`code`));let i=document.createElement(`button`);i.className=`copy-btn`,i.textContent=`Copy`,i.addEventListener(`click`,()=>{navigator.clipboard.writeText(e).then(()=>{i.textContent=`Copied!`,setTimeout(()=>{i.textContent=`Copy`},1500)})}),r.appendChild(i),n.appendChild(r);let a=document.createElement(`pre`),o=document.createElement(`code`);return o.textContent=e,a.appendChild(o),n.appendChild(a),n}function U9(e,t=0){let n=B(`div`,t===0?`block block-tree`:``),r=typeof e.name==`string`?e.name:typeof e.label==`string`?e.label:null,i=Array.isArray(e.children)?e.children:null;if(r&&i){if(i.length===0)return B(`div`,`tree-leaf`,`📄 ${r}`);let a=B(`div`,`tree-node`),o=B(`span`,`tree-toggle`,`▼`),s=B(`div`,`tree-children`),l=!0;s.style.display=``,o.addEventListener(`click`,()=>{l=!l,o.textContent=l?`▼`:`▶`,s.style.display=l?``:`none`}),a.appendChild(o),a.appendChild(document.createTextNode(` ${r}`));for(let e of i)typeof e==`object`&&e&&!Array.isArray(e)?s.appendChild(U9(e,t+1)):s.appendChild(B(`div`,`tree-leaf`,`📄 ${od(e)}`));for(let[n,r]of Object.entries(e))if(!(n===`name`||n===`label`||n===`children`))if(typeof r==`object`&&r&&!Array.isArray(r))s.appendChild(U9({[n]:r},t+1));else{let e=B(`div`,`tree-leaf`);e.innerHTML=`<strong>${ad(n)}:</strong> ${ad(od(r))}`,s.appendChild(e)}return a.appendChild(s),n.appendChild(a),n}if(r)return n.appendChild(B(`div`,`tree-leaf`,`📄 ${r}`)),n;for(let[r,i]of Object.entries(e))if(typeof i==`object`&&i&&!Array.isArray(i)){let e=B(`div`,`tree-node`),a=B(`span`,`tree-toggle`,`▼`),o=U9(i,t+1);o.className=`tree-children`;let s=!0;a.addEventListener(`click`,()=>{s=!s,a.textContent=s?`▼`:`▶`,o.style.display=s?``:`none`}),e.appendChild(a),e.appendChild(document.createTextNode(` ${r}`)),e.appendChild(o),n.appendChild(e)}else{let e=B(`div`,`tree-leaf`);e.innerHTML=`<strong>${ad(r)}:</strong> ${ad(od(i))}`,n.appendChild(e)}return n}function wdt(e){let t=B(`div`,`block block-cards`);for(let n of e){let e=B(`div`,`card`);if(n.title&&e.appendChild(B(`div`,`card-title`,String(n.title))),(n.body||n.description)&&e.appendChild(B(`div`,`card-body`,String(n.body??n.description))),n.badge||n.status){let t=String(n.variant??n.status??`default`).toLowerCase(),r=[`success`,`warning`,`error`].includes(t)?t:``;e.appendChild(B(`span`,`card-badge ${r}`,String(n.badge??n.status)))}t.appendChild(e)}return t}function Tdt(e){let t=B(`div`,`block block-metrics`);for(let n of e){let e=B(`div`,`metric`);e.appendChild(B(`div`,`metric-value`,String(n.value))),e.appendChild(B(`div`,`metric-label`,n.label)),t.appendChild(e)}return t}function Edt(e){let t=[`graph LR`],n=new Map;for(let r of e.nodes){let e=String(r.id??r.name??``),i=String(r.label??r.name??e);n.set(e,i),t.push(` ${sd(e)}["${ad(i)}"]`)}for(let n of e.edges){let e=sd(String(n.source??n.from??``)),r=sd(String(n.target??n.to??``)),i=n.label?`|${ad(String(n.label))}|`:``;t.push(` ${e} -->${i} ${r}`)}return V9(t.join(`
3750
+ `));if(typeof e==`object`&&e){let t=e;return Array.isArray(t.nodes)&&Array.isArray(t.edges)?Edt(t):Array.isArray(t.metrics)?Tdt(t.metrics):U9(t)}return B9(String(e))}function hdt(e){let t=e.trim();if(/^(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|gitGraph)\b/i.test(t))return V9(t);if(/^#{1,6}\s|^\s*[-*]\s|\*\*|__|\[.*\]\(|```/.test(t))return B9(t);if((t.startsWith(`{`)||t.startsWith(`[`))&&(t.endsWith(`}`)||t.endsWith(`]`)))try{return z9(JSON.parse(t))}catch{}return B9(t)}function gdt(e,t,n){let r=B(`div`,`comparison-side ${n}`),i=e&&typeof e==`object`&&!Array.isArray(e)?e:null,a=String(i?.label??i?.title??t),o=Array.isArray(i?.items)?i.items:Array.isArray(e)?e:e==null?[]:[e];r.appendChild(B(`div`,`comparison-label`,a));let s=B(`ul`,`comparison-items`);for(let e of o)s.appendChild(B(`li`,``,od(e)));return r.appendChild(s),r}function _dt(e){let t=B(`div`,`actions`);for(let n of e){if(n.type===`select`&&n.options){let e=document.createElement(`select`);e.className=`action-select`;let r=document.createElement(`option`);r.textContent=n.label,r.disabled=!0,r.selected=!0,e.appendChild(r);for(let t of n.options){let n=document.createElement(`option`);typeof t==`string`?(n.value=t,n.textContent=t):(n.value=t.value,n.textContent=t.label),e.appendChild(n)}t.appendChild(e);continue}let e=document.createElement(`button`);e.className=`action-btn ${n.variant??`default`}`,e.textContent=n.label,t.appendChild(e)}return t}function vdt(e,t){switch(e.type){case`markdown`:return B9(String(e.value??``));case`mermaid`:return V9(String(e.value??``));case`table`:{let t=e.value;if(Array.isArray(t)){if(t.length>0&&Array.isArray(t[0])){let e=t,n=e[0].map(String);return H9(e.slice(1).map(e=>Object.fromEntries(n.map((t,n)=>[t,e[n]]))))}return H9(t)}if(t&&typeof t==`object`&&`headers`in t&&`rows`in t){let{headers:e,rows:n}=t;return H9(n.map(t=>Object.fromEntries(e.map((e,n)=>[e,t[n]]))))}return H9([])}case`code`:return Cdt(String(e.value??``),e.language);case`tree`:return U9(e.value);case`cards`:return wdt(e.value);case`metrics`:return Tdt(e.value);case`graph`:return Edt(e.value);case`chart`:return xce(e);case`kv`:{let t=e.value;return t&&typeof t==`object`&&!Array.isArray(t)?H9(Object.entries(t).map(([e,t])=>({Key:e,Value:t}))):B9(JSON.stringify(t,null,2))}case`comparison`:{let t=e.value;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t;if(`left`in e||`right`in e){let t=B(`div`,`block block-comparison`);return t.appendChild(gdt(e.left,`Left`,`comparison-left`)),t.appendChild(gdt(e.right,`Right`,`comparison-right`)),t}if(Array.isArray(e.headers)&&Array.isArray(e.rows)){let t=e.headers;return H9(e.rows.map(e=>Object.fromEntries(t.map((t,n)=>[t,e[n]]))))}if(Array.isArray(e.columns)){let t=e.columns,n=Math.max(...t.map(e=>e.items?.length??0)),r=[];for(let e=0;e<n;e++){let n={};for(let r of t)n[r.name]=r.items?.[e]??``;r.push(n)}return H9(r)}}return B9(JSON.stringify(t,null,2))}case`actions`:{let n=Array.isArray(e.value)?e.value:[],r=t?Ddt(n,t):_dt(n);return r.classList.add(`block`,`block-actions`),r}case`timeline`:{let t=e.value;return Array.isArray(t)?H9(t.map(e=>{if(e&&typeof e==`object`){let t=e;return{Status:t.status??t.state??``,Time:t.time??t.date??t.timestamp??``,Description:t.label??t.description??t.title??t.text??``}}return{Status:``,Time:``,Description:String(e)}})):B9(JSON.stringify(t,null,2))}case`heading`:return B9(`## ${String(e.value??``)}`);case`checklist`:{let t=Array.isArray(e.value)?e.value:e.value?.items;if(!Array.isArray(t))return B9(JSON.stringify(e.value,null,2));let n=B(`div`,`block block-checklist`);for(let e of t){let t=B(`div`,`checklist-item ${e.checked?`checked`:``}`),r=B(`div`,`checklist-check ${e.checked?`checked`:``}`,e.checked?`✓`:``),i=B(`div`,``);i.appendChild(B(`div`,`checklist-label`,String(e.label??``))),e.note&&i.appendChild(B(`div`,`checklist-note`,String(e.note))),t.appendChild(r),t.appendChild(i),n.appendChild(t)}return n}case`status-board`:{let t=e.value,n=[];if(Array.isArray(t))for(let e of t)if(Array.isArray(e.items)){let t=e.category?.trim();for(let r of e.items)n.push({...r,label:t?`${t}: ${r.label}`:r.label})}else n.push(e);else t&&typeof t==`object`&&Array.isArray(t.items)&&n.push(...t.items);if(n.length===0)return B9(JSON.stringify(e.value,null,2));let r=B(`div`,`block block-status-board`);for(let e of n){let t=B(`div`,`status-row`);t.appendChild(B(`div`,`status-indicator ${e.status??`pending`}`,``)),t.appendChild(B(`span`,`status-label`,String(e.label??``))),e.detail&&t.appendChild(B(`span`,`status-detail`,String(e.detail))),r.appendChild(t)}return r}case`prompt`:{let t=e.value;if(!t?.question)return B9(JSON.stringify(e.value,null,2));let n=B(`div`,`block block-prompt prompt-block`);return n.appendChild(B(`div`,`prompt-question`,String(t.question))),t.context&&n.appendChild(B(`div`,`prompt-context`,String(t.context))),t.placeholder&&n.appendChild(B(`div`,`prompt-placeholder`,String(t.placeholder))),n}case`progress`:{let t;if(Array.isArray(e.value))t=e.value;else if(e.value&&typeof e.value==`object`){let n=e.value;t=Array.isArray(n.items)?n.items:[n]}else return B9(JSON.stringify(e.value,null,2));let n=B(`div`,`block block-progress progress-list`);for(let e of t){let t=typeof e.max==`number`?e.max:100,r=typeof e.value==`number`?e.value:0,i=t>0?Math.min(100,r/t*100):0,a=(typeof e.color==`string`?e.color:``)||(i>=100?`var(--success, #22c55e)`:i>=60?`var(--primary, #818cf8)`:i>=30?`var(--warning, #f59e0b)`:`var(--error, #ef4444)`),o=B(`div`,`progress-item`),s=B(`div`,`progress-header`);s.appendChild(B(`span`,`progress-label`,String(e.label??``))),s.appendChild(B(`span`,`progress-value`,`${r}/${t}`)),o.appendChild(s);let l=B(`div`,`progress-track`),u=B(`div`,`progress-fill`);u.style.width=`${i.toFixed(1)}%`,u.style.background=a,l.appendChild(u),o.appendChild(l),n.appendChild(o)}return n}case`docs-browser`:{let t=e.value,n=Array.isArray(t?.files)?t.files:[],r=B(`div`,`block block-docs-browser`);r.style.border=`1px solid var(--color-border, #334155)`,r.style.borderRadius=`8px`,r.style.overflow=`hidden`;let i=typeof t.title==`string`?t.title.trim():``;if(i){let e=B(`div`,``,i);e.style.padding=`12px`,e.style.fontWeight=`600`,r.appendChild(e)}if(n.length===0)return r.appendChild(B(`div`,``,`No documentation files.`)),r;for(let[e,t]of n.entries()){let n=document.createElement(`details`);e===0&&(n.open=!0);let i=document.createElement(`summary`);i.style.cssText=`padding:8px 12px; cursor:pointer; display:flex; align-items:center; justify-content:space-between; gap:12px;`;let a=t?.path?.trim()||`document-${e+1}`,o=t?.title?.trim()||a.split(/[\\/]/).pop()||a,s=B(`div`,``);s.appendChild(B(`span`,``,a));let l=s.firstElementChild;l instanceof HTMLElement&&(l.style.cssText=`font-family:monospace; font-size:0.85rem; color:var(--color-muted, #94a3b8);`);let u=B(`span`,``,o);if(u.style.fontWeight=`600`,s.appendChild(u),i.appendChild(s),t?.status){let e=B(`span`,``,t.status),n={current:`background:#14532d; color:#bbf7d0;`,stale:`background:#713f12; color:#fde68a;`,missing:`background:#7f1d1d; color:#fecaca;`};e.style.cssText=`padding:2px 8px; border-radius:999px; font-size:0.75rem; text-transform:uppercase; ${n[t.status]||``}`,i.appendChild(e)}n.appendChild(i);let d=B(`div`,``);d.style.cssText=`padding:12px; border-top:1px solid var(--color-border, #334155);`,t?.content?.trim()?d.appendChild(B9(t.content)):d.appendChild(B(`div`,``,`No content available.`)),n.appendChild(d),r.appendChild(n)}return r}case`text`:return B9(String(e.value??``));case`paragraph`:{let t=document.createElement(`p`);return t.textContent=String(e.value??``),t.classList.add(`block`,`block-paragraph`),t}case`separator`:{let e=document.createElement(`hr`);return e.classList.add(`block`,`block-separator`),e}default:return B9(JSON.stringify(e.value,null,2))}}function ydt(e,t){let n=vdt(e,t);return e.title&&n.insertBefore(B(`div`,`block-title`,e.title),n.firstChild),n}function B9(e){let t=B(`div`,`block block-markdown`);return t.innerHTML=uce(e),t}var bdt=null;function xdt(){return bdt||=$u(()=>Promise.resolve().then(()=>(mdt(),Klt)).then(e=>(e.default.initialize({startOnLoad:!1,theme:`default`}),e.default)),void 0,import.meta.url),bdt}var Sdt=0;function V9(e){let t=B(`div`,`block block-mermaid`),n=B(`pre`,`mermaid-source`,e);t.appendChild(n);let r=`mermaid-${++Sdt}`;return xdt().then(t=>t.render(r,e)).then(({svg:e})=>{t.innerHTML=e}).catch(()=>{n.classList.add(`mermaid-fallback`)}),t}function H9(e){let t=B(`div`,`block block-table`);if(e.length===0)return B9(`*Empty table*`);let n=Object.keys(e[0]),r=-1,i=!0,a=[...e],o=``,s=document.createElement(`input`);s.className=`table-filter`,s.placeholder=`Filter...`,s.addEventListener(`input`,()=>{o=s.value.toLowerCase(),p()}),t.appendChild(s);let l=document.createElement(`table`),u=document.createElement(`thead`),d=document.createElement(`tr`);n.forEach((e,t)=>{let n=document.createElement(`th`);n.textContent=e;let a=B(`span`,`sort-icon`,`⇅`);n.appendChild(a),n.addEventListener(`click`,()=>{r===t?i=!i:(r=t,i=!0),p()}),d.appendChild(n)}),u.appendChild(d),l.appendChild(u);let f=document.createElement(`tbody`);l.appendChild(f),t.appendChild(l);function p(){if(a=[...e],o&&(a=a.filter(e=>n.some(t=>String(e[t]??``).toLowerCase().includes(o)))),r>=0){let e=n[r];a.sort((t,n)=>{let r=String(t[e]??``),a=String(n[e]??``),o=r.localeCompare(a,void 0,{numeric:!0});return i?o:-o})}f.innerHTML=``;for(let e of a){let t=document.createElement(`tr`);for(let r of n){let n=document.createElement(`td`);n.textContent=String(e[r]??``),t.appendChild(n)}f.appendChild(t)}}return p(),t}function Cdt(e,t){let n=B(`div`,`block block-code`),r=B(`div`,`code-header`);r.appendChild(B(`span`,``,t??`code`));let i=document.createElement(`button`);i.className=`copy-btn`,i.textContent=`Copy`,i.addEventListener(`click`,()=>{navigator.clipboard.writeText(e).then(()=>{i.textContent=`Copied!`,setTimeout(()=>{i.textContent=`Copy`},1500)})}),r.appendChild(i),n.appendChild(r);let a=document.createElement(`pre`),o=document.createElement(`code`);return o.textContent=e,a.appendChild(o),n.appendChild(a),n}function U9(e,t=0){let n=B(`div`,t===0?`block block-tree`:``),r=typeof e.name==`string`?e.name:typeof e.label==`string`?e.label:null,i=Array.isArray(e.children)?e.children:null;if(r&&i){if(i.length===0)return B(`div`,`tree-leaf`,`📄 ${r}`);let a=B(`div`,`tree-node`),o=B(`span`,`tree-toggle`,`▼`),s=B(`div`,`tree-children`),l=!0;s.style.display=``,o.addEventListener(`click`,()=>{l=!l,o.textContent=l?`▼`:`▶`,s.style.display=l?``:`none`}),a.appendChild(o),a.appendChild(document.createTextNode(` ${r}`));for(let e of i)typeof e==`object`&&e&&!Array.isArray(e)?s.appendChild(U9(e,t+1)):s.appendChild(B(`div`,`tree-leaf`,`📄 ${od(e)}`));for(let[n,r]of Object.entries(e))if(!(n===`name`||n===`label`||n===`children`))if(typeof r==`object`&&r&&!Array.isArray(r))s.appendChild(U9({[n]:r},t+1));else{let e=B(`div`,`tree-leaf`);e.innerHTML=`<strong>${ad(n)}:</strong> ${ad(od(r))}`,s.appendChild(e)}return a.appendChild(s),n.appendChild(a),n}if(r)return n.appendChild(B(`div`,`tree-leaf`,`📄 ${r}`)),n;for(let[r,i]of Object.entries(e))if(typeof i==`object`&&i&&!Array.isArray(i)){let e=B(`div`,`tree-node`),a=B(`span`,`tree-toggle`,`▼`),o=U9(i,t+1);o.className=`tree-children`;let s=!0;a.addEventListener(`click`,()=>{s=!s,a.textContent=s?`▼`:`▶`,o.style.display=s?``:`none`}),e.appendChild(a),e.appendChild(document.createTextNode(` ${r}`)),e.appendChild(o),n.appendChild(e)}else{let e=B(`div`,`tree-leaf`);e.innerHTML=`<strong>${ad(r)}:</strong> ${ad(od(i))}`,n.appendChild(e)}return n}function wdt(e){let t=B(`div`,`block block-cards`);for(let n of e){let e=B(`div`,`card`);if(n.title&&e.appendChild(B(`div`,`card-title`,String(n.title))),(n.body||n.description)&&e.appendChild(B(`div`,`card-body`,String(n.body??n.description))),n.badge||n.status){let t=String(n.variant??n.status??`default`).toLowerCase(),r=[`success`,`warning`,`error`].includes(t)?t:``;e.appendChild(B(`span`,`card-badge ${r}`,String(n.badge??n.status)))}t.appendChild(e)}return t}function Tdt(e){let t=B(`div`,`block block-metrics`);for(let n of e){let e=B(`div`,`metric`);e.appendChild(B(`div`,`metric-value`,String(n.value))),e.appendChild(B(`div`,`metric-label`,n.label)),t.appendChild(e)}return t}function Edt(e){let t=[`graph LR`],n=new Map;for(let r of e.nodes){let e=String(r.id??r.name??``),i=String(r.label??r.name??e);n.set(e,i),t.push(` ${sd(e)}["${ad(i)}"]`)}for(let n of e.edges){let e=sd(String(n.source??n.from??``)),r=sd(String(n.target??n.to??``)),i=n.label?`|${ad(String(n.label))}|`:``;t.push(` ${e} -->${i} ${r}`)}return V9(t.join(`
3751
3751
  `))}function Ddt(e,t){let n=B(`div`,`actions`);for(let r of e)if(r.type===`select`&&r.options){let e=document.createElement(`select`);e.className=`action-select`;let i=document.createElement(`option`);i.textContent=r.label,i.disabled=!0,i.selected=!0,e.appendChild(i);for(let t of r.options){let n=document.createElement(`option`);typeof t==`string`?(n.value=t,n.textContent=t):(n.value=t.value,n.textContent=t.label),e.appendChild(n)}e.addEventListener(`change`,()=>{t.emitAction(r,e.value)}),n.appendChild(e)}else{let e=document.createElement(`button`);e.className=`action-btn ${r.variant??`default`}`,e.textContent=r.label,e.addEventListener(`click`,()=>t.emitAction(r)),n.appendChild(e)}return n}function Odt(){if(typeof document<`u`){let e=document.createElement(`style`);e.textContent=`
3752
3752
  .checklist-item { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; }
3753
3753
  .checklist-check { width: 20px; height: 20px; border-radius: 4px; border: 2px solid var(--color-border, #334155); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.75rem; }
@@ -1 +1 @@
1
- import{t as e}from"./curated-manager-BkSgtNC2.js";import{readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";import{parseArgs as o}from"node:util";import{createLogger as s,serializeError as c}from"../../core/dist/index.js";const l=n(i(import.meta.url)),u=(()=>{try{let e=r(l,`..`,`..`,`..`,`package.json`);return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}})(),d=s(`server`);function f(){return process.env.AIKIT_TRANSPORT?process.env.AIKIT_TRANSPORT:process.stdin.isTTY?`http`:`stdio`}const{values:p}=(()=>{let e=process.argv[1];if(!e)return!1;try{return import.meta.url===a(e).href}catch{return!1}})()?o({allowPositionals:!0,options:{transport:{type:`string`,default:f()},port:{type:`string`,default:process.env.AIKIT_PORT??`3210`}}}):{values:{transport:f(),port:process.env.AIKIT_PORT??`3210`}};async function m(){if(process.on(`unhandledRejection`,e=>{d.error(`Unhandled rejection`,c(e))}),d.info(`Starting MCP AI Kit server`,{version:u}),p.transport===`http`){let[{default:e},{loadConfig:t,resolveIndexMode:n},{registerDashboardRoutes:r,resolveDashboardDir:i},{registerSettingsRoutes:a,resolveSettingsDir:o},{createSettingsRouter:s}]=await Promise.all([import(`express`),import(`./config-D4z6-EcI.js`),import(`./dashboard-static-BfIe0Si1.js`),import(`./settings-static-BosGZSPf.js`),import(`./routes-OaSHcA6x.js`)]),l=t();d.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path});let u=e();u.use(e.json());let f=Number(p.port);u.use((e,t,n)=>{if(t.setHeader(`Access-Control-Allow-Origin`,process.env.AIKIT_CORS_ORIGIN??`http://localhost:${f}`),t.setHeader(`Access-Control-Allow-Methods`,`GET, POST, PUT, PATCH, DELETE, OPTIONS`),t.setHeader(`Access-Control-Allow-Headers`,`Content-Type, Authorization`),e.method===`OPTIONS`){t.status(204).end();return}n()}),r(u,i(),d);let m=new Date().toISOString();u.use(`/settings/api`,s({log:d,mcpInfo:()=>({transport:`http`,port:f,pid:process.pid,startedAt:m})})),a(u,o(),d),u.get(`/health`,(e,t)=>{t.json({status:`ok`})});let h=!1,g=null,_=null,v=null,y=Promise.resolve();u.post(`/mcp`,async(e,t)=>{if(!h||!_||!v){t.status(503).json({jsonrpc:`2.0`,error:{code:-32603,message:`Server initializing — please retry in a few seconds`},id:null});return}let n=y,r;y=new Promise(e=>{r=e}),await n;try{let n=new v({sessionIdGenerator:void 0});await _.connect(n),await n.handleRequest(e,t,e.body),n.close()}catch(e){if(d.error(`MCP handler error`,c(e)),!t.headersSent){let n=e instanceof Error?e.message:String(e),r=n.includes(`Not Acceptable`);t.status(r?406:500).json({jsonrpc:`2.0`,error:{code:r?-32e3:-32603,message:r?n:`Internal server error`},id:null})}}finally{r()}}),u.get(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))}),u.delete(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))});let b=u.listen(f,`127.0.0.1`,()=>{d.info(`MCP server listening`,{url:`http://127.0.0.1:${f}/mcp`,port:f}),setTimeout(async()=>{try{let[{createLazyServer:e,ALL_TOOL_NAMES:t},{StreamableHTTPServerTransport:r},{checkForUpdates:i,autoUpgradeScaffold:a}]=await Promise.all([import(`./server-zA3SovxH.js`),import(`@modelcontextprotocol/sdk/server/streamableHttp.js`),import(`./version-check-Bj07vc5x.js`)]);i(),a();let o=n(l),s=e(l,o);_=s.server,v=r,h=!0,d.info(`MCP server configured (lazy — AI Kit initializing in background)`,{toolCount:t.length,resourceCount:2}),s.startInit(),o===`auto`?s.ready.then(async()=>{try{let e=l.sources.map(e=>e.path).join(`, `);d.info(`Running initial index`,{sourcePaths:e}),await s.runInitialIndex(),d.info(`Initial index complete`)}catch(e){d.error(`Initial index failed; will retry on aikit_reindex`,c(e))}}).catch(e=>d.error(`AI Kit init or indexing failed`,c(e))):o===`smart`?s.ready.then(async()=>{try{if(!s.aikit)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(s.aikit.indexer,l,s.aikit.store),n=s.aikit.store;g=t,t.start(),n.onBeforeClose&&n.onBeforeClose(()=>t.stop()),s.setSmartScheduler(t),d.info(`Smart index scheduler started (HTTP mode)`)}catch(e){d.error(`Failed to start smart index scheduler`,c(e))}}).catch(e=>d.error(`AI Kit initialization failed`,c(e))):(s.ready.catch(e=>d.error(`AI Kit initialization failed`,c(e))),d.info(`Initial full indexing skipped in HTTP mode`,{indexMode:o}))}catch(e){d.error(`Failed to load server modules`,c(e))}},100)}),x=async e=>{d.info(`Shutdown signal received`,{signal:e}),g?.stop(),b.close(),_&&await _.close(),process.exit(0)};process.on(`SIGINT`,()=>x(`SIGINT`)),process.on(`SIGTERM`,()=>x(`SIGTERM`))}else{let[{loadConfig:e,reconfigureForWorkspace:t,resolveIndexMode:n},{createLazyServer:r},{checkForUpdates:a,autoUpgradeScaffold:o},{RootsListChangedNotificationSchema:s}]=await Promise.all([import(`./config-D4z6-EcI.js`),import(`./server-zA3SovxH.js`),import(`./version-check-Bj07vc5x.js`),import(`@modelcontextprotocol/sdk/types.js`)]),l=e();d.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path}),a(),o();let u=n(l),f=r(l,u),{server:p,startInit:m,ready:h,runInitialIndex:g}=f,{StdioServerTransport:_}=await import(`@modelcontextprotocol/sdk/server/stdio.js`),v=new _;await p.connect(v),d.info(`MCP server started`,{transport:`stdio`});let y=e=>{if(e.length===0)return!1;let n=e[0].uri,r=n.startsWith(`file://`)?i(n):n;return d.info(`MCP roots resolved`,{rootUri:n,rootPath:r,rootCount:e.length}),t(l,r),l.allRoots=e.map(e=>{let t=e.uri;return t.startsWith(`file://`)?i(t):t}),!0},b=!1;try{b=y((await p.server.listRoots()).roots),b||d.info(`No MCP roots yet; waiting for roots/list_changed notification`)}catch(e){d.warn(`MCP roots/list not supported by client; using cwd fallback`,{cwd:process.cwd(),...c(e)}),b=!0}b||=await new Promise(e=>{let t=setTimeout(()=>{d.warn(`Timed out waiting for MCP roots/list_changed; using cwd fallback`,{cwd:process.cwd()}),e(!1)},5e3);p.server.setNotificationHandler(s,async()=>{clearTimeout(t);try{e(y((await p.server.listRoots()).roots))}catch(t){d.warn(`roots/list retry failed after notification`,c(t)),e(!1)}})}),m();let x=null,S=()=>{x&&clearTimeout(x),x=setTimeout(()=>{d.info(`Auto-shutdown: no activity for 30 minutes — exiting`),process.exit(0)},18e5),x.unref&&x.unref()};S(),process.stdin.on(`data`,()=>S()),h.catch(e=>{d.error(`Initialization failed — server will continue with limited tools`,c(e))}),u===`auto`?g().catch(e=>d.error(`Initial index failed`,c(e))):u===`smart`?h.then(async()=>{try{if(!f.aikit)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(f.aikit.indexer,l,f.aikit.store),n=f.aikit.store;t.start(),n.onBeforeClose&&n.onBeforeClose(()=>t.stop()),f.setSmartScheduler(t),d.info(`Smart index scheduler started (stdio mode)`)}catch(e){d.error(`Failed to start smart index scheduler`,c(e))}}).catch(e=>d.error(`AI Kit init failed for smart scheduler`,c(e))):d.warn(`Initial full indexing skipped; use aikit_reindex to index manually`,{indexMode:u})}}m().catch(e=>{d.error(`Fatal error`,c(e)),process.exit(1)});export{e as CuratedKnowledgeManager};
1
+ import{t as e}from"./curated-manager-BkSgtNC2.js";import{readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";import{parseArgs as o}from"node:util";import{createLogger as s,serializeError as c}from"../../core/dist/index.js";const l=n(i(import.meta.url)),u=(()=>{try{let e=r(l,`..`,`..`,`..`,`package.json`);return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}})(),d=s(`server`);function f(){return process.env.AIKIT_TRANSPORT?process.env.AIKIT_TRANSPORT:process.stdin.isTTY?`http`:`stdio`}const{values:p}=(()=>{let e=process.argv[1];if(!e)return!1;try{return import.meta.url===a(e).href}catch{return!1}})()?o({allowPositionals:!0,options:{transport:{type:`string`,default:f()},port:{type:`string`,default:process.env.AIKIT_PORT??`3210`}}}):{values:{transport:f(),port:process.env.AIKIT_PORT??`3210`}};async function m(){if(process.on(`unhandledRejection`,e=>{d.error(`Unhandled rejection`,c(e))}),d.info(`Starting MCP AI Kit server`,{version:u}),p.transport===`http`){let[{default:e},{loadConfig:t,resolveIndexMode:n},{registerDashboardRoutes:r,resolveDashboardDir:i},{registerSettingsRoutes:a,resolveSettingsDir:o},{createSettingsRouter:s}]=await Promise.all([import(`express`),import(`./config-D4z6-EcI.js`),import(`./dashboard-static-BfIe0Si1.js`),import(`./settings-static-BosGZSPf.js`),import(`./routes-OaSHcA6x.js`)]),l=t();d.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path});let u=e();u.use(e.json());let f=Number(p.port);u.use((e,t,n)=>{if(t.setHeader(`Access-Control-Allow-Origin`,process.env.AIKIT_CORS_ORIGIN??`http://localhost:${f}`),t.setHeader(`Access-Control-Allow-Methods`,`GET, POST, PUT, PATCH, DELETE, OPTIONS`),t.setHeader(`Access-Control-Allow-Headers`,`Content-Type, Authorization`),e.method===`OPTIONS`){t.status(204).end();return}n()}),r(u,i(),d);let m=new Date().toISOString();u.use(`/settings/api`,s({log:d,mcpInfo:()=>({transport:`http`,port:f,pid:process.pid,startedAt:m})})),a(u,o(),d),u.get(`/health`,(e,t)=>{t.json({status:`ok`})});let h=!1,g=null,_=null,v=null,y=Promise.resolve();u.post(`/mcp`,async(e,t)=>{if(!h||!_||!v){t.status(503).json({jsonrpc:`2.0`,error:{code:-32603,message:`Server initializing — please retry in a few seconds`},id:null});return}let n=y,r;y=new Promise(e=>{r=e}),await n;try{let n=new v({sessionIdGenerator:void 0});await _.connect(n),await n.handleRequest(e,t,e.body),n.close()}catch(e){if(d.error(`MCP handler error`,c(e)),!t.headersSent){let n=e instanceof Error?e.message:String(e),r=n.includes(`Not Acceptable`);t.status(r?406:500).json({jsonrpc:`2.0`,error:{code:r?-32e3:-32603,message:r?n:`Internal server error`},id:null})}}finally{r()}}),u.get(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))}),u.delete(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))});let b=u.listen(f,`127.0.0.1`,()=>{d.info(`MCP server listening`,{url:`http://127.0.0.1:${f}/mcp`,port:f}),setTimeout(async()=>{try{let[{createLazyServer:e,ALL_TOOL_NAMES:t},{StreamableHTTPServerTransport:r},{checkForUpdates:i,autoUpgradeScaffold:a}]=await Promise.all([import(`./server-Cn7iAvm9.js`),import(`@modelcontextprotocol/sdk/server/streamableHttp.js`),import(`./version-check-Bj07vc5x.js`)]);i(),a();let o=n(l),s=e(l,o);_=s.server,v=r,h=!0,d.info(`MCP server configured (lazy — AI Kit initializing in background)`,{toolCount:t.length,resourceCount:2}),s.startInit(),o===`auto`?s.ready.then(async()=>{try{let e=l.sources.map(e=>e.path).join(`, `);d.info(`Running initial index`,{sourcePaths:e}),await s.runInitialIndex(),d.info(`Initial index complete`)}catch(e){d.error(`Initial index failed; will retry on aikit_reindex`,c(e))}}).catch(e=>d.error(`AI Kit init or indexing failed`,c(e))):o===`smart`?s.ready.then(async()=>{try{if(!s.aikit)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(s.aikit.indexer,l,s.aikit.store),n=s.aikit.store;g=t,t.start(),n.onBeforeClose&&n.onBeforeClose(()=>t.stop()),s.setSmartScheduler(t),d.info(`Smart index scheduler started (HTTP mode)`)}catch(e){d.error(`Failed to start smart index scheduler`,c(e))}}).catch(e=>d.error(`AI Kit initialization failed`,c(e))):(s.ready.catch(e=>d.error(`AI Kit initialization failed`,c(e))),d.info(`Initial full indexing skipped in HTTP mode`,{indexMode:o}))}catch(e){d.error(`Failed to load server modules`,c(e))}},100)}),x=async e=>{d.info(`Shutdown signal received`,{signal:e}),g?.stop(),b.close(),_&&await _.close(),process.exit(0)};process.on(`SIGINT`,()=>x(`SIGINT`)),process.on(`SIGTERM`,()=>x(`SIGTERM`))}else{let[{loadConfig:e,reconfigureForWorkspace:t,resolveIndexMode:n},{createLazyServer:r},{checkForUpdates:a,autoUpgradeScaffold:o},{RootsListChangedNotificationSchema:s}]=await Promise.all([import(`./config-D4z6-EcI.js`),import(`./server-Cn7iAvm9.js`),import(`./version-check-Bj07vc5x.js`),import(`@modelcontextprotocol/sdk/types.js`)]),l=e();d.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path}),a(),o();let u=n(l),f=r(l,u),{server:p,startInit:m,ready:h,runInitialIndex:g}=f,{StdioServerTransport:_}=await import(`@modelcontextprotocol/sdk/server/stdio.js`),v=new _;await p.connect(v),d.info(`MCP server started`,{transport:`stdio`});let y=e=>{if(e.length===0)return!1;let n=e[0].uri,r=n.startsWith(`file://`)?i(n):n;return d.info(`MCP roots resolved`,{rootUri:n,rootPath:r,rootCount:e.length}),t(l,r),l.allRoots=e.map(e=>{let t=e.uri;return t.startsWith(`file://`)?i(t):t}),!0},b=!1;try{b=y((await p.server.listRoots()).roots),b||d.info(`No MCP roots yet; waiting for roots/list_changed notification`)}catch(e){d.warn(`MCP roots/list not supported by client; using cwd fallback`,{cwd:process.cwd(),...c(e)}),b=!0}b||=await new Promise(e=>{let t=setTimeout(()=>{d.warn(`Timed out waiting for MCP roots/list_changed; using cwd fallback`,{cwd:process.cwd()}),e(!1)},5e3);p.server.setNotificationHandler(s,async()=>{clearTimeout(t);try{e(y((await p.server.listRoots()).roots))}catch(t){d.warn(`roots/list retry failed after notification`,c(t)),e(!1)}})}),m();let x=null,S=()=>{x&&clearTimeout(x),x=setTimeout(()=>{d.info(`Auto-shutdown: no activity for 30 minutes — exiting`),process.exit(0)},18e5),x.unref&&x.unref()};S(),process.stdin.on(`data`,()=>S()),h.catch(e=>{d.error(`Initialization failed — server will continue with limited tools`,c(e))}),u===`auto`?g().catch(e=>d.error(`Initial index failed`,c(e))):u===`smart`?h.then(async()=>{try{if(!f.aikit)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(f.aikit.indexer,l,f.aikit.store),n=f.aikit.store;t.start(),n.onBeforeClose&&n.onBeforeClose(()=>t.stop()),f.setSmartScheduler(t),d.info(`Smart index scheduler started (stdio mode)`)}catch(e){d.error(`Failed to start smart index scheduler`,c(e))}}).catch(e=>d.error(`AI Kit init failed for smart scheduler`,c(e))):d.warn(`Initial full indexing skipped; use aikit_reindex to index manually`,{indexMode:u})}}m().catch(e=>{d.error(`Fatal error`,c(e)),process.exit(1)});export{e as CuratedKnowledgeManager};