@vpxa/aikit 0.1.69 → 0.1.71

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.69",
3
+ "version": "0.1.71",
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",
@@ -1,4 +1,4 @@
1
- import{dirname as e,extname as t,join as n}from"node:path";import{CHUNK_SIZES as r,createLogger as i}from"../../core/dist/index.js";import{existsSync as a,readFileSync as o}from"node:fs";import{fileURLToPath as s}from"node:url";const c=n(e(s(import.meta.url)),`..`,`..`,`wasm`),l={".ts":`tree-sitter-typescript.wasm`,".tsx":`tree-sitter-typescript.wasm`,".mts":`tree-sitter-typescript.wasm`,".cts":`tree-sitter-typescript.wasm`,".js":`tree-sitter-javascript.wasm`,".jsx":`tree-sitter-javascript.wasm`,".mjs":`tree-sitter-javascript.wasm`,".cjs":`tree-sitter-javascript.wasm`,".py":`tree-sitter-python.wasm`,".go":`tree-sitter-go.wasm`,".rs":`tree-sitter-rust.wasm`,".java":`tree-sitter-java.wasm`,".kt":`tree-sitter-kotlin.wasm`,".kts":`tree-sitter-kotlin.wasm`,".scala":`tree-sitter-scala.wasm`,".sc":`tree-sitter-scala.wasm`,".c":`tree-sitter-c.wasm`,".h":`tree-sitter-c.wasm`,".cpp":`tree-sitter-cpp.wasm`,".cc":`tree-sitter-cpp.wasm`,".cxx":`tree-sitter-cpp.wasm`,".hpp":`tree-sitter-cpp.wasm`,".hxx":`tree-sitter-cpp.wasm`,".cs":`tree-sitter-c_sharp.wasm`,".swift":`tree-sitter-swift.wasm`,".rb":`tree-sitter-ruby.wasm`,".php":`tree-sitter-php.wasm`},u=new Set(Object.keys(l));function d(e){let t=l[e];if(!t)return null;let r=n(c,t);return a(r)?r:null}function f(){let e=n(c,`tree-sitter.wasm`);return a(e)?e:null}const p=i(`wasm-runtime`);async function m(){let e=await import(`web-tree-sitter`),t=typeof e.default?.init==`function`?e.default:e.Parser;if(!t||typeof t.init!=`function`)throw Error(`Unsupported web-tree-sitter export shape: ${Object.keys(e).join(`, `)}`);return t}var h=class e{static instance=null;parser=null;languages=new Map;loadedGrammars=new Map;static async initialize(){if(e.instance)return e.instance;let t=new e;return await t.init()?(e.instance=t,t):null}static get(){return e.instance}static async ensure(){let t=e.get();if(t)return t;let n=await e.initialize();if(!n)throw Error(`Failed to initialize WASM tree-sitter runtime`);return n}static dispose(){e.instance&&=(e.instance.parser?.delete(),e.instance.parser=null,e.instance.languages.clear(),e.instance.loadedGrammars.clear(),null)}async init(){try{let e=f();if(!e)return p.warn(`Parser WASM file not found`),!1;let t=await m();return await t.init({locateFile:()=>e}),this.parser=new t,p.info(`WASM tree-sitter parser initialized`),!0}catch(e){return p.warn(`Failed to initialize WASM tree-sitter`,{error:String(e)}),!1}}async loadLanguage(e){let t=this.languages.get(e);if(t)return t;let n=d(e);if(!n)return null;let r=this.loadedGrammars.get(n);if(r)return this.languages.set(e,r),r;try{let t=await(await m()).Language.load(n);return this.loadedGrammars.set(n,t),this.languages.set(e,t),p.info(`Loaded grammar`,{ext:e}),t}catch(t){return p.warn(`Failed to load grammar`,{ext:e,error:String(t)}),null}}async parse(e,t){if(!this.parser)return null;let n=await this.loadLanguage(t);return n?(this.parser.setLanguage(n),this.parser.parse(e)):null}hasLanguage(e){return u.has(e)}isLanguageLoaded(e){return this.languages.has(e)}getParser(){return this.parser}getLanguage(e){return this.languages.get(e)??null}};async function ee(){return await h.initialize()!==null}const g=new Set([`function_declaration`,`method_definition`,`arrow_function`,`function_definition`,`function_declaration`,`method_declaration`,`function_item`,`method_declaration`,`constructor_declaration`]),_=new Set([`call_expression`,`new_expression`,`call`]);function v(e,n){let r=t(n).toLowerCase(),i=h.get();if(i?.isLanguageLoaded(r)){let t=i.getParser(),a=i.getLanguage(r);if(t&&a){t.setLanguage(a);let r=t.parse(e);if(r){let e=[];return y(r.rootNode,n,`<module>`,e),e}}}return null}function y(e,t,n,r){if(!e)return;let i=n;if(g.has(e.type)&&(i=te(e)??n),_.has(e.type)){let n=b(e);n&&r.push({callerFile:t,callerName:i,calleeName:n,line:(e.startPosition?.row??0)+1})}for(let n=0;n<(e.childCount??0);n++){let a=e.child(n);a&&y(a,t,i,r)}}function te(e){for(let t=0;t<(e.childCount??0);t++){let n=e.child(t);if(n&&(n.type===`identifier`||n.type===`property_identifier`||n.type===`name`))return n.text??null}return null}function b(e){let t=e.childForFieldName?.(`function`)??e.child(0);return t?t.type===`identifier`||t.type===`name`?t.text??null:t.type===`member_expression`||t.type===`attribute`?(t.childForFieldName?.(`property`)??t.childForFieldName?.(`attribute`))?.text??null:e.type===`new_expression`?e.child(1)?.text??null:null:null}var x=class{maxChunkSize;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.code.max}chunk(e,t){let n=this.findDeclarationBoundaries(e);if(n.length===0)return this.fallbackChunk(e,t);let r=[];for(let i=0;i<n.length;i++){let a=n[i].offset,o=i+1<n.length?n[i+1].offset:e.length,s=e.slice(a,o).trim();if(s=`// File: ${t.sourcePath}\n`+s,s.length>this.maxChunkSize){let n=this.splitByLines(s,this.maxChunkSize),i=this.getLineNumber(e,a);for(let e of n){let n=e.split(`
1
+ import{dirname as e,extname as t,join as n}from"node:path";import{CHUNK_SIZES as r,createLogger as i}from"../../core/dist/index.js";import{existsSync as a,readFileSync as o}from"node:fs";import{fileURLToPath as s}from"node:url";const c=e(s(import.meta.url));function l(){let e=[n(c,`..`,`..`,`wasm`),n(c,`..`,`wasm`)];for(let t of e)if(a(n(t,`tree-sitter.wasm`)))return t;return e[0]}const u=l(),d={".ts":`tree-sitter-typescript.wasm`,".tsx":`tree-sitter-typescript.wasm`,".mts":`tree-sitter-typescript.wasm`,".cts":`tree-sitter-typescript.wasm`,".js":`tree-sitter-javascript.wasm`,".jsx":`tree-sitter-javascript.wasm`,".mjs":`tree-sitter-javascript.wasm`,".cjs":`tree-sitter-javascript.wasm`,".py":`tree-sitter-python.wasm`,".go":`tree-sitter-go.wasm`,".rs":`tree-sitter-rust.wasm`,".java":`tree-sitter-java.wasm`,".kt":`tree-sitter-kotlin.wasm`,".kts":`tree-sitter-kotlin.wasm`,".scala":`tree-sitter-scala.wasm`,".sc":`tree-sitter-scala.wasm`,".c":`tree-sitter-c.wasm`,".h":`tree-sitter-c.wasm`,".cpp":`tree-sitter-cpp.wasm`,".cc":`tree-sitter-cpp.wasm`,".cxx":`tree-sitter-cpp.wasm`,".hpp":`tree-sitter-cpp.wasm`,".hxx":`tree-sitter-cpp.wasm`,".cs":`tree-sitter-c_sharp.wasm`,".swift":`tree-sitter-swift.wasm`,".rb":`tree-sitter-ruby.wasm`,".php":`tree-sitter-php.wasm`},f=new Set(Object.keys(d));function p(e){let t=d[e];if(!t)return null;let r=n(u,t);return a(r)?r:null}function m(){let e=n(u,`tree-sitter.wasm`);return a(e)?e:null}const h=i(`wasm-runtime`);async function g(){let e=await import(`web-tree-sitter`),t=typeof e.default?.init==`function`?e.default:e.Parser;if(!t||typeof t.init!=`function`)throw Error(`Unsupported web-tree-sitter export shape: ${Object.keys(e).join(`, `)}`);return t}var _=class e{static instance=null;parser=null;languages=new Map;loadedGrammars=new Map;static async initialize(){if(e.instance)return e.instance;let t=new e;return await t.init()?(e.instance=t,t):null}static get(){return e.instance}static async ensure(){let t=e.get();if(t)return t;let n=await e.initialize();if(!n)throw Error(`Failed to initialize WASM tree-sitter runtime`);return n}static dispose(){e.instance&&=(e.instance.parser?.delete(),e.instance.parser=null,e.instance.languages.clear(),e.instance.loadedGrammars.clear(),null)}async init(){try{let e=m();if(!e)return h.warn(`Parser WASM file not found`),!1;let t=await g();return await t.init({locateFile:()=>e}),this.parser=new t,h.info(`WASM tree-sitter parser initialized`),!0}catch(e){return h.warn(`Failed to initialize WASM tree-sitter`,{error:String(e)}),!1}}async loadLanguage(e){let t=this.languages.get(e);if(t)return t;let n=p(e);if(!n)return null;let r=this.loadedGrammars.get(n);if(r)return this.languages.set(e,r),r;try{let t=await(await g()).Language.load(n);return this.loadedGrammars.set(n,t),this.languages.set(e,t),h.info(`Loaded grammar`,{ext:e}),t}catch(t){return h.warn(`Failed to load grammar`,{ext:e,error:String(t)}),null}}async parse(e,t){if(!this.parser)return null;let n=await this.loadLanguage(t);return n?(this.parser.setLanguage(n),this.parser.parse(e)):null}hasLanguage(e){return f.has(e)}isLanguageLoaded(e){return this.languages.has(e)}getParser(){return this.parser}getLanguage(e){return this.languages.get(e)??null}};async function ee(){return await _.initialize()!==null}const v=new Set([`function_declaration`,`method_definition`,`arrow_function`,`function_definition`,`function_declaration`,`method_declaration`,`function_item`,`method_declaration`,`constructor_declaration`]),y=new Set([`call_expression`,`new_expression`,`call`]);function b(e,n){let r=t(n).toLowerCase(),i=_.get();if(i?.isLanguageLoaded(r)){let t=i.getParser(),a=i.getLanguage(r);if(t&&a){t.setLanguage(a);let r=t.parse(e);if(r){let e=[];return x(r.rootNode,n,`<module>`,e),e}}}return null}function x(e,t,n,r){if(!e)return;let i=n;if(v.has(e.type)&&(i=te(e)??n),y.has(e.type)){let n=S(e);n&&r.push({callerFile:t,callerName:i,calleeName:n,line:(e.startPosition?.row??0)+1})}for(let n=0;n<(e.childCount??0);n++){let a=e.child(n);a&&x(a,t,i,r)}}function te(e){for(let t=0;t<(e.childCount??0);t++){let n=e.child(t);if(n&&(n.type===`identifier`||n.type===`property_identifier`||n.type===`name`))return n.text??null}return null}function S(e){let t=e.childForFieldName?.(`function`)??e.child(0);return t?t.type===`identifier`||t.type===`name`?t.text??null:t.type===`member_expression`||t.type===`attribute`?(t.childForFieldName?.(`property`)??t.childForFieldName?.(`attribute`))?.text??null:e.type===`new_expression`?e.child(1)?.text??null:null:null}var C=class{maxChunkSize;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.code.max}chunk(e,t){let n=this.findDeclarationBoundaries(e);if(n.length===0)return this.fallbackChunk(e,t);let r=[];for(let i=0;i<n.length;i++){let a=n[i].offset,o=i+1<n.length?n[i+1].offset:e.length,s=e.slice(a,o).trim();if(s=`// File: ${t.sourcePath}\n`+s,s.length>this.maxChunkSize){let n=this.splitByLines(s,this.maxChunkSize),i=this.getLineNumber(e,a);for(let e of n){let n=e.split(`
2
2
  `).length;r.push({text:e,sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:r.length,totalChunks:0,startLine:i,endLine:i+n-1}),i+=n}}else{let n=this.getLineNumber(e,a);r.push({text:s,sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:r.length,totalChunks:0,startLine:n,endLine:n+s.split(`
3
3
  `).length-1})}}if(n[0].offset>0){let i=e.slice(0,n[0].offset).trim();i.length>0&&r.unshift({text:`// File: ${t.sourcePath}\n${i}`,sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:0,totalChunks:0,startLine:1,endLine:this.getLineNumber(e,n[0].offset)-1})}return r.map((e,t)=>({...e,chunkIndex:t,totalChunks:r.length}))}findDeclarationBoundaries(e){let t=/^(?:export\s+)?(?:default\s+)?(?:async\s+)?(?:function|class|interface|type|const|enum|abstract\s+class)\s+(\w+)/gm,n=[],r;for(;(r=t.exec(e))!==null;){let t=e.lastIndexOf(`
4
4
  `,r.index-1)+1,i=t,a=e.slice(0,t).split(`
@@ -8,17 +8,17 @@ import{dirname as e,extname as t,join as n}from"node:path";import{CHUNK_SIZES as
8
8
  `),r=[],i=[],a=0;for(let e of n)a+e.length+1>t&&i.length>0?(r.push(i.join(`
9
9
  `)),i=[e],a=e.length):(i.push(e),a+=e.length+1);return i.length>0&&r.push(i.join(`
10
10
  `)),r}getLineNumber(e,t){return e.slice(0,t).split(`
11
- `).length}},S=class{maxChunkSize;overlap;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.default.max,this.overlap=e?.overlap??r.default.overlap}chunk(e,t){if(e.length<=this.maxChunkSize)return[{text:e,sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:0,totalChunks:1,startLine:1,endLine:e.split(`
11
+ `).length}},w=class{maxChunkSize;overlap;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.default.max,this.overlap=e?.overlap??r.default.overlap}chunk(e,t){if(e.length<=this.maxChunkSize)return[{text:e,sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:0,totalChunks:1,startLine:1,endLine:e.split(`
12
12
  `).length}];let n=e.split(`
13
13
  `),r=[],i=[],a=0,o=1;for(let e=0;e<n.length;e++){let s=n[e];if(a+s.length+1>this.maxChunkSize&&i.length>0){r.push({text:i.join(`
14
14
  `),sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:r.length,totalChunks:0,startLine:o,endLine:o+i.length-1});let e=[],n=0;for(let t=i.length-1;t>=0&&!(n+i[t].length+1>this.overlap);t--)e.unshift(i[t]),n+=i[t].length+1;o=o+i.length-e.length,i=[...e,s],a=n+s.length+1}else i.push(s),a+=s.length+1}return i.length>0&&r.push({text:i.join(`
15
- `),sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:r.length,totalChunks:0,startLine:o,endLine:o+i.length-1}),r.map((e,t)=>({...e,chunkIndex:t,totalChunks:r.length}))}},C=class{maxChunkSize;minChunkSize;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.markdown.max,this.minChunkSize=e?.minChunkSize??r.markdown.min}chunk(e,t){let n=this.splitByHeadings(e),r=[];for(let e of n){if(e.text.trim().length<this.minChunkSize&&r.length>0){let t=r[r.length-1];t.text+=`\n\n${e.text}`,t.endLine=e.endLine;continue}if(e.text.length>this.maxChunkSize){let n=this.splitByParagraphs(e.text,this.maxChunkSize),i=e.startLine;for(let a of n){let n=a.split(`
15
+ `),sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:r.length,totalChunks:0,startLine:o,endLine:o+i.length-1}),r.map((e,t)=>({...e,chunkIndex:t,totalChunks:r.length}))}},T=class{maxChunkSize;minChunkSize;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.markdown.max,this.minChunkSize=e?.minChunkSize??r.markdown.min}chunk(e,t){let n=this.splitByHeadings(e),r=[];for(let e of n){if(e.text.trim().length<this.minChunkSize&&r.length>0){let t=r[r.length-1];t.text+=`\n\n${e.text}`,t.endLine=e.endLine;continue}if(e.text.length>this.maxChunkSize){let n=this.splitByParagraphs(e.text,this.maxChunkSize),i=e.startLine;for(let a of n){let n=a.split(`
16
16
  `).length;r.push({text:a,sourcePath:t.sourcePath,contentType:t.contentType,headingPath:e.headingPath,chunkIndex:r.length,totalChunks:0,startLine:i,endLine:i+n-1}),i+=n}}else r.push({text:e.text,sourcePath:t.sourcePath,contentType:t.contentType,headingPath:e.headingPath,chunkIndex:r.length,totalChunks:0,startLine:e.startLine,endLine:e.endLine})}return r.map((e,t)=>({...e,chunkIndex:t,totalChunks:r.length}))}splitByHeadings(e){let t=e.split(`
17
- `),n=[],r=null,i=[],a=!1;for(let e=0;e<t.length;e++){/^```/.test(t[e])&&(a=!a);let o=a?null:t[e].match(/^(#{1,6})\s+(.+)/);if(o){r&&n.push(r);let a=o[1].length,s=o[2].trim();for(;i.length>=a;)i.pop();i.push(`${`#`.repeat(a)} ${s}`),r={text:t[e],headingPath:i.join(` > `),startLine:e+1,endLine:e+1}}else r?(r.text+=`\n${t[e]}`,r.endLine=e+1):r={text:t[e],headingPath:`(intro)`,startLine:e+1,endLine:e+1}}return r&&n.push(r),n}splitByParagraphs(e,t){let n=e.split(/\n\n+/),r=[],i=``;for(let e of n)`${i}\n\n${e}`.length>t&&i.length>0?(r.push(i.trim()),i=e):i=i?`${i}\n\n${e}`:e;return i.trim()&&r.push(i.trim()),r}};const w=new Set([`function_declaration`,`class_declaration`,`interface_declaration`,`type_alias_declaration`,`enum_declaration`,`lexical_declaration`,`variable_declaration`,`export_statement`,`function_definition`,`class_definition`,`decorated_definition`,`class_declaration`,`interface_declaration`,`enum_declaration`,`function_declaration`,`method_declaration`,`type_declaration`,`function_item`,`struct_item`,`enum_item`,`trait_item`,`impl_item`,`const_item`,`static_item`,`type_item`]),T=new Set([`import_statement`,`import_from_statement`,`import_declaration`,`package_declaration`,`use_declaration`,`extern_crate_declaration`,`import_spec`,`package_clause`]);var E=class{maxChunkSize;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.code.max}chunk(e,t){let n=h.get();if(!n)return this.singleChunk(e,t);let r=this.extractExt(t.sourcePath),i=n.getLanguage(r);if(!i)return this.singleChunk(e,t);let a=n.getParser();if(!a)return this.singleChunk(e,t);a.setLanguage(i);let o=a.parse(e);if(!o)return this.singleChunk(e,t);let s=this.findAstBoundaries(o.rootNode,e);return s.length===0?this.singleChunk(e,t):this.buildChunks(s,e,t)}findAstBoundaries(e,t){let n=[];for(let t of e.children){if(!t.isNamed)continue;let e=w.has(t.type),r=T.has(t.type);(e||r)&&n.push({startOffset:t.startIndex,endOffset:t.endIndex,startLine:t.startPosition.row+1,endLine:t.endPosition.row+1,isPreamble:r})}return n}buildChunks(e,t,n){let r=[],i=null,a=0,o=0;for(let s of e){if(s.isPreamble){i===null&&(i=s.startLine),a=s.endOffset,o=s.endLine;continue}if(i!==null){let e=t.slice(0,a).trim();e.length>0&&r.push({text:`// File: ${n.sourcePath}\n${e}`,sourcePath:n.sourcePath,contentType:n.contentType,chunkIndex:0,totalChunks:0,startLine:i,endLine:o}),i=null}let e=t.slice(s.startOffset,s.endOffset).trim();if(e=`// File: ${n.sourcePath}\n`+e,e.length>this.maxChunkSize){let t=this.splitByLines(e,this.maxChunkSize),i=s.startLine;for(let e of t){let t=e.split(`
17
+ `),n=[],r=null,i=[],a=!1;for(let e=0;e<t.length;e++){/^```/.test(t[e])&&(a=!a);let o=a?null:t[e].match(/^(#{1,6})\s+(.+)/);if(o){r&&n.push(r);let a=o[1].length,s=o[2].trim();for(;i.length>=a;)i.pop();i.push(`${`#`.repeat(a)} ${s}`),r={text:t[e],headingPath:i.join(` > `),startLine:e+1,endLine:e+1}}else r?(r.text+=`\n${t[e]}`,r.endLine=e+1):r={text:t[e],headingPath:`(intro)`,startLine:e+1,endLine:e+1}}return r&&n.push(r),n}splitByParagraphs(e,t){let n=e.split(/\n\n+/),r=[],i=``;for(let e of n)`${i}\n\n${e}`.length>t&&i.length>0?(r.push(i.trim()),i=e):i=i?`${i}\n\n${e}`:e;return i.trim()&&r.push(i.trim()),r}};const E=new Set([`function_declaration`,`class_declaration`,`interface_declaration`,`type_alias_declaration`,`enum_declaration`,`lexical_declaration`,`variable_declaration`,`export_statement`,`function_definition`,`class_definition`,`decorated_definition`,`class_declaration`,`interface_declaration`,`enum_declaration`,`function_declaration`,`method_declaration`,`type_declaration`,`function_item`,`struct_item`,`enum_item`,`trait_item`,`impl_item`,`const_item`,`static_item`,`type_item`]),ne=new Set([`import_statement`,`import_from_statement`,`import_declaration`,`package_declaration`,`use_declaration`,`extern_crate_declaration`,`import_spec`,`package_clause`]);var D=class{maxChunkSize;constructor(e){this.maxChunkSize=e?.maxChunkSize??r.code.max}chunk(e,t){let n=_.get();if(!n)return this.singleChunk(e,t);let r=this.extractExt(t.sourcePath),i=n.getLanguage(r);if(!i)return this.singleChunk(e,t);let a=n.getParser();if(!a)return this.singleChunk(e,t);a.setLanguage(i);let o=a.parse(e);if(!o)return this.singleChunk(e,t);let s=this.findAstBoundaries(o.rootNode,e);return s.length===0?this.singleChunk(e,t):this.buildChunks(s,e,t)}findAstBoundaries(e,t){let n=[];for(let t of e.children){if(!t.isNamed)continue;let e=E.has(t.type),r=ne.has(t.type);(e||r)&&n.push({startOffset:t.startIndex,endOffset:t.endIndex,startLine:t.startPosition.row+1,endLine:t.endPosition.row+1,isPreamble:r})}return n}buildChunks(e,t,n){let r=[],i=null,a=0,o=0;for(let s of e){if(s.isPreamble){i===null&&(i=s.startLine),a=s.endOffset,o=s.endLine;continue}if(i!==null){let e=t.slice(0,a).trim();e.length>0&&r.push({text:`// File: ${n.sourcePath}\n${e}`,sourcePath:n.sourcePath,contentType:n.contentType,chunkIndex:0,totalChunks:0,startLine:i,endLine:o}),i=null}let e=t.slice(s.startOffset,s.endOffset).trim();if(e=`// File: ${n.sourcePath}\n`+e,e.length>this.maxChunkSize){let t=this.splitByLines(e,this.maxChunkSize),i=s.startLine;for(let e of t){let t=e.split(`
18
18
  `).length;r.push({text:e,sourcePath:n.sourcePath,contentType:n.contentType,chunkIndex:0,totalChunks:0,startLine:i,endLine:i+t-1}),i+=t}}else r.push({text:e,sourcePath:n.sourcePath,contentType:n.contentType,chunkIndex:0,totalChunks:0,startLine:s.startLine,endLine:s.endLine})}if(i!==null){let e=t.slice(0,a).trim();e.length>0&&r.push({text:`// File: ${n.sourcePath}\n${e}`,sourcePath:n.sourcePath,contentType:n.contentType,chunkIndex:0,totalChunks:0,startLine:i,endLine:o})}return r.map((e,t)=>({...e,chunkIndex:t,totalChunks:r.length}))}splitByLines(e,t){let n=e.split(`
19
19
  `),r=[],i=[],a=0;for(let e of n)a+e.length+1>t&&i.length>0&&(r.push(i.join(`
20
20
  `)),i=[],a=0),i.push(e),a+=e.length+1;return i.length>0&&r.push(i.join(`
21
21
  `)),r}extractExt(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t).toLowerCase():``}singleChunk(e,t){return[{text:`// File: ${t.sourcePath}\n${e}`,sourcePath:t.sourcePath,contentType:t.contentType,chunkIndex:0,totalChunks:1,startLine:1,endLine:e.split(`
22
- `).length}]}};async function ne(e){let t=e.toLowerCase();switch(t){case`.md`:case`.mdx`:return new C;case`.ts`:case`.tsx`:case`.mts`:case`.cts`:case`.js`:case`.jsx`:case`.mjs`:case`.cjs`:case`.py`:case`.go`:case`.rs`:case`.java`:if(u.has(t)){let e=await h.initialize();if(e)return await e.loadLanguage(t),new E}return new x;default:return new S}}function re(e){let t=e.toLowerCase();switch(t){case`.md`:case`.mdx`:return new C;case`.ts`:case`.tsx`:case`.mts`:case`.cts`:case`.js`:case`.jsx`:case`.mjs`:case`.cjs`:case`.py`:case`.go`:case`.rs`:case`.java`:return h.get()?.isLanguageLoaded(t)?new E:new x;default:return new S}}const D=i(`query-executor`),O=e(s(import.meta.url));function k(){let e=n(O,`..`,`queries`);if(a(e))return e;let t=n(O,`..`,`..`,`src`,`queries`);return a(t)?t:e}const A=k(),j={".ts":`typescript`,".tsx":`typescript`,".mts":`typescript`,".cts":`typescript`,".js":`javascript`,".jsx":`javascript`,".mjs":`javascript`,".cjs":`javascript`,".py":`python`,".go":`go`,".rs":`rust`,".java":`java`};var M=class{queryCache=new Map;scmCache=new Map;execute(e,t,n,r){let i=this.getOrCompile(t,n,r);return i?i.matches(e).map(e=>N(e)):[]}executeCaptures(e,t,n,r){let i=this.getOrCompile(t,n,r);return i?i.captures(e).map(e=>P(e)):[]}executeRaw(e,t,n){return t.query(n).matches(e).map(e=>N(e))}getOrCompile(e,t,n){let r=j[t];if(!r)return null;let i=`${r}:${n}`,a=this.queryCache.get(i);if(a)return a;let o=this.loadScm(r,n);if(!o)return null;try{let t=e.query(o);return this.queryCache.set(i,t),t}catch(e){throw D.warn(`Failed to compile query`,{langDir:r,queryType:n,error:String(e)}),Error(`Failed to compile ${r}/${n}.scm: ${String(e)}`)}}loadScm(e,t){let r=`${e}:${t}`,i=this.scmCache.get(r);if(i!==void 0)return i;let a=n(A,e,`${t}.scm`);try{let e=o(a,`utf-8`);return this.scmCache.set(r,e),e}catch{return D.info(`Query file not found (graceful skip)`,{langDir:e,queryType:t}),null}}dispose(){this.queryCache.clear(),this.scmCache.clear()}static resolveQueryDir(e){return n(A,e)}};function N(e){let t=new Map;for(let n of e.captures)t.set(n.name,P(n));return{pattern:e.pattern,captures:t}}function P(e){let{node:t}=e;return{name:e.name,text:t.text,nodeType:t.type,startLine:t.startPosition.row,endLine:t.endPosition.row,startColumn:t.startPosition.column,endColumn:t.endPosition.column,node:t}}const F=new M,I=new Set([`function_declaration`,`method_definition`,`arrow_function`,`function_definition`,`method_declaration`,`constructor_declaration`,`function_declaration`,`method_declaration`,`function_item`]);async function L(e,t,n=``){let r=await h.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);return a?F.execute(i.rootNode,a,t,`calls`).map(e=>R(e,i.rootNode,n)).filter(e=>e!==null):[]}function R(e,t,n){let r=e.captures.get(`callee`);if(!r)return null;let i=e.captures.get(`node`);return{callerFile:n,callerName:z(i?.node??r.node),calleeName:r.text,line:(i?.startLine??r.startLine)+1}}function z(e){let t=e.parent;for(;t;){if(I.has(t.type)){let e=B(t);if(e)return e}t=t.parent}return`<module>`}function B(e){let t=e.childForFieldName(`name`);if(t)return t.text;for(let t of e.children)if(t.type===`identifier`||t.type===`property_identifier`||t.type===`field_identifier`)return t.text;return null}const V=new M,H={handler:`lambda-handler`,lambdaHandler:`lambda-handler`,main:`main`,__name__:`main`,app:`server`,server:`server`,router:`server`,urlpatterns:`server`,init:`main`},U={SpringBootApplication:`server`,RestController:`server`,Controller:`server`};async function W(e,t,n=``){let r=await h.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);if(!a)return[];let o=V.execute(i.rootNode,a,t,`entry-points`),s=[],c=new Set;for(let e of o){let r=G(e,t,n);if(r){let e=`${r.name}:${r.type}`;c.has(e)||(c.add(e),s.push(r))}}return s}function G(e,t,n){let r=e.captures.get(`name`);if(!r)return null;let i=r.text,a=e.captures.get(`_parent`);if(a){let e=a.text;if([`Construct`,`Stack`,`NestedStack`,`Stage`].includes(e))return{name:i,type:`cdk-construct`,filePath:n}}let o=e.captures.get(`_ann`);if(o){let e=U[o.text];if(e)return{name:i,type:e,filePath:n}}let s=H[i];return s?{name:i,type:s,filePath:n}:t===`.go`&&i.toLowerCase().startsWith(`handle`)?{name:i,type:`server`,filePath:n,trigger:`HTTP handler`}:{name:i,type:`main`,filePath:n}}const K=new M;async function q(e,t,n=``){let r=await h.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);if(!a)return[];let o=K.execute(i.rootNode,a,t,`imports`),s=[];for(let e of o){let r=e.captures.get(`source`);if(!r){let r=e.captures.get(`node`);if(r){let e=ie(r.text,t);e&&s.push({source:e.source,specifiers:e.specifiers,filePath:n,isExternal:Y(e.source,t),confidence:`high`})}continue}let i=r.text,a=J(i,t),o=X(e.captures.get(`node`)?.text??``,t,a);s.push({source:a,specifiers:o,filePath:n,isExternal:Y(a,t),confidence:`high`})}return s}function J(e,t){let n=e.replace(/^['"`]|['"`]$/g,``);return t===`.go`&&(n=n.replace(/^"|"$/g,``)),n}function Y(e,t){return t===`.py`?!e.startsWith(`.`):t===`.go`?e.includes(`/`)||e.includes(`.`):t===`.java`?!0:t===`.rs`?!e.startsWith(`self`)&&!e.startsWith(`super`)&&!e.startsWith(`crate`):!e.startsWith(`.`)&&!e.startsWith(`/`)}function X(e,t,n){if(!e)return[n];if(t===`.py`){let t=e.match(/import\s+(.+)$/m);return t?t[1].split(`,`).map(e=>e.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean):[n]}if(t===`.java`){let e=n.split(`.`);return[e[e.length-1]]}if(t===`.go`){let e=n.split(`/`);return[e[e.length-1]]}if(t===`.rs`){if(n.includes(`{`)){let e=n.match(/\{([^}]+)\}/);if(e)return e[1].split(`,`).map(e=>e.trim()).filter(Boolean)}let e=n.split(`::`);return[e[e.length-1]]}let r=e.match(/\{([^}]+)\}/);if(r)return r[1].split(`,`).map(e=>e.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean);let i=e.match(/import\s+(\w+)/);return i?[i[1]]:[n]}function ie(e,t){if(t===`.py`){let t=e.match(/^import\s+([\w.]+)/);if(t)return{source:t[1],specifiers:[t[1]]}}return null}const ae=new M;async function oe(e,t,n=``){let r=await h.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);if(!a)return[];let o=ae.execute(i.rootNode,a,t,`patterns`),s=new Map;for(let e of o){let r=se(e,t);if(!r)continue;let i=e.captures.get(`name`),a=`${n}:${(e.captures.get(`node`)?.startLine??i?.startLine??0)+1}`,o=s.get(r.pattern);o?o.locations.push(a):s.set(r.pattern,{description:r.description,locations:[a]})}let c=[];for(let[e,{description:t,locations:n}]of s)c.push({pattern:e,description:t,locations:n,confidence:`high`});return c}function se(e,t){let n=e.captures.get(`name`)?.text;if(!n)return null;let r=e.captures.get(`node`)?.nodeType??``;if(/^(create|build)[A-Z]/.test(n)||/^(of|from|new)[A-Z]/.test(n))return{pattern:`factory`,description:`Factory function/method`};if(/^(register|bind)$/.test(n))return{pattern:`dependency-injection`,description:`DI container registration`};if(/^(Injectable|Component|Service|Controller|Module|Singleton|Repository|Bean)$/.test(n))return{pattern:`dependency-injection`,description:`Framework DI annotation`};if(/^(Map|WeakMap|Set)$/.test(n))return{pattern:`cached-instance`,description:`Cached Map/Set instance`};if(t===`.py`){if(n===`__new__`)return{pattern:`singleton`,description:`Singleton pattern (__new__ override)`};if(n===`__enter__`)return{pattern:`context-manager`,description:`Context manager pattern`};if(r===`decorated_definition`)return{pattern:`decorator`,description:`Decorator usage`}}if(t===`.go`){if(r===`type_declaration`)return{pattern:`interface`,description:`Interface definition`};if(r===`go_statement`)return{pattern:`concurrency`,description:`Goroutine concurrency pattern`};if(n===`make`)return{pattern:`concurrency`,description:`Channel/make pattern`}}if(t===`.rs`){if(r===`impl_item`)return{pattern:`trait-impl`,description:`Trait implementation`};if(r===`attribute_item`){if(n===`derive`)return{pattern:`derive`,description:`Derive macro attribute`};if(n===`test`)return{pattern:`test`,description:`Test attribute`}}}if(t===`.java`){if(r===`class_declaration`)return{pattern:`singleton`,description:`Singleton pattern (private constructor)`};if(r===`marker_annotation`)return{pattern:`dependency-injection`,description:`Framework DI annotation`}}if(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(t)){if(r===`class_declaration`)return{pattern:`singleton`,description:`Singleton pattern (private constructor)`};if(r===`decorator`)return{pattern:`decorator`,description:`Framework decorator pattern`}}return{pattern:r||`unknown`,description:`Detected pattern: ${n}`}}const ce=new Set([`function_declaration`,`method_definition`,`arrow_function`,`class_declaration`,`function_definition`,`class_definition`,`method_declaration`,`constructor_declaration`,`class_declaration`,`function_declaration`,`method_declaration`,`function_item`,`impl_item`]);async function le(e,t,n){let r=await(await h.ensure()).parse(e,t);if(!r)return[{name:`<module>`,type:`module`,line:1}];let i=ue(r.rootNode,n-1);if(!i)return[{name:`<module>`,type:`module`,line:1}];let a=[];return de(i,a),a.push({name:`<module>`,type:`module`,line:1}),a}function ue(e,t){let n=null;function r(e){if(e.startPosition.row<=t&&e.endPosition.row>=t){n=e;for(let t of e.children)r(t)}}return r(e),n}function de(e,t){let n=e.parent;for(;n;){if(ce.has(n.type)){let e=fe(n),r=pe(n.type);t.push({name:e??`<anonymous>`,type:r,line:n.startPosition.row+1})}n=n.parent}}function fe(e){let t=e.childForFieldName(`name`);if(t)return t.text;for(let t of e.children)if(t.type===`identifier`||t.type===`type_identifier`||t.type===`property_identifier`||t.type===`field_identifier`)return t.text;return null}function pe(e){return e.includes(`class`)||e===`impl_item`?`class`:`function`}const me=new M,he={function_declaration:`function`,class_declaration:`class`,interface_declaration:`interface`,type_alias_declaration:`type`,enum_declaration:`enum`,lexical_declaration:`const`,method_definition:`method`,public_field_definition:`variable`,field_definition:`variable`,function_definition:`function`,class_definition:`class`,expression_statement:`variable`,method_declaration:`method`,constructor_declaration:`method`,field_declaration:`variable`,type_spec:`type`,type_declaration:`type`,const_spec:`const`,var_spec:`variable`,function_item:`function`,struct_item:`class`,enum_item:`enum`,trait_item:`interface`,impl_item:`type`,const_item:`const`,static_item:`variable`,type_item:`type`};async function ge(e,t,n=``){let r=await h.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);return a?_e(me.execute(i.rootNode,a,t,`symbols`),t,n):[]}function _e(e,t,n){let r=new Map;for(let n of e){let e=n.captures.get(`name`);if(!e)continue;let i=`${e.text}:${(n.captures.get(`node`)?.startLine??e.startLine)+1}`,a=ve(n,t),o=r.get(i);(!o||!o.exported&&a)&&r.set(i,{match:n,exported:a})}let i=[];for(let{match:e,exported:a}of r.values()){let r=e.captures.get(`name`),o=e.captures.get(`node`);if(!r)continue;let s=he[o?.nodeType??r.nodeType]??`variable`,c=(o?.startLine??r.startLine)+1,l=ye(s,o?.node,t),u=o?.node??r.node;i.push({name:r.text,kind:l,exported:a,filePath:n,line:c,signature:be(o?.node,l),returnType:$(o?.node,l),jsdoc:we(u),decorators:Te(u),typeBody:Ee(o?.node,l)})}return i}function ve(e,t){if(e.captures.has(`exported`))return!0;let n=e.captures.get(`name`)?.text;if(!n)return!1;if(t===`.py`)return!n.startsWith(`_`);if(t===`.go`)return/^[A-Z]/.test(n);if(t===`.java`){let t=e.captures.get(`node`)?.text??``;return/\bpublic\b/.test(t)}return!1}function ye(e,t,n){if(n===`.go`&&e===`type`&&t?.children){let e=t.type===`type_declaration`?t.children.flatMap(e=>e.children??[]):t.children;for(let t of e){if(t.type===`interface_type`)return`interface`;if(t.type===`struct_type`)return`class`}}return e}function be(e,t){if(e){if(t===`function`||t===`method`)return xe(e);if(t===`class`)return Se(e);if(t===`interface`)return Ce(e)}}function xe(e){let t=e.childForFieldName(`parameters`)??e.childForFieldName(`parameter_list`),n=e.childForFieldName(`return_type`)??e.childForFieldName(`type`),r=e.childForFieldName(`result`);if(!t){for(let t of e.children)if(t.type===`formal_parameters`||t.type===`parameter_list`||t.type===`parameters`){let e=t.text;return n&&(e+=n.text),r&&(e+=` ${r.text}`),e.length>120?`${e.slice(0,117)}...`:e}return}let i=t.text;return n&&(i+=n.text),r&&(i+=` ${r.text}`),i.length>120?`${i.slice(0,117)}...`:i}function Se(e){let t=e.childForFieldName(`body`)??e.childForFieldName(`field_declaration_list`);if(!t){for(let t of e.children)if(t.type===`struct_type`||t.type===`class_body`)return Z(t);return}return Z(t)}function Z(e){let t=[];for(let n of e.children){if(n.type===`method_definition`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`method_declaration`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`field_declaration`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`function_definition`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}}if(t.length===0)return;let n=t.join(`, `);return n.length>120?`${n.slice(0,117)}...`:n}function Ce(e){let t=e.childForFieldName(`body`);if(!t){for(let t of e.children)if(t.type===`interface_type`)return Q(t);return}return Q(t)}function Q(e){let t=[];for(let n of e.children){if(n.type===`property_signature`||n.type===`method_signature`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`method_declaration`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`method_spec`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`function_signature_item`||n.type===`declaration_list`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}}if(t.length===0)return;let n=t.join(`, `);return n.length>120?`${n.slice(0,117)}...`:n}function $(e,t){if(!e||t!==`function`&&t!==`method`)return;let n=e.childForFieldName(`return_type`)??e.childForFieldName(`type`);if(n){let e=n.text.replace(/^:\s*/,``).trim();return e.length>200?`${e.slice(0,200)}…`:e}let r=e.childForFieldName(`result`);if(r)return r.text.trim()}function we(e){let t=e.parent;if(!t?.children)return;let n=t.children.indexOf(e);if(n<=0)return;let r=t.children[n-1];if(r){if(r.type===`comment`||r.type===`block_comment`||r.type===`doc_comment`)return r.text.replace(/^\/\*\*?\s*|\s*\*\/$/g,``).split(`
22
+ `).length}]}};async function re(e){let t=e.toLowerCase();switch(t){case`.md`:case`.mdx`:return new T;case`.ts`:case`.tsx`:case`.mts`:case`.cts`:case`.js`:case`.jsx`:case`.mjs`:case`.cjs`:case`.py`:case`.go`:case`.rs`:case`.java`:if(f.has(t)){let e=await _.initialize();if(e)return await e.loadLanguage(t),new D}return new C;default:return new w}}function ie(e){let t=e.toLowerCase();switch(t){case`.md`:case`.mdx`:return new T;case`.ts`:case`.tsx`:case`.mts`:case`.cts`:case`.js`:case`.jsx`:case`.mjs`:case`.cjs`:case`.py`:case`.go`:case`.rs`:case`.java`:return _.get()?.isLanguageLoaded(t)?new D:new C;default:return new w}}const O=i(`query-executor`),k=e(s(import.meta.url));function A(){let e=n(k,`..`,`queries`);if(a(e))return e;let t=n(k,`..`,`..`,`src`,`queries`);return a(t)?t:e}const j=A(),M={".ts":`typescript`,".tsx":`typescript`,".mts":`typescript`,".cts":`typescript`,".js":`javascript`,".jsx":`javascript`,".mjs":`javascript`,".cjs":`javascript`,".py":`python`,".go":`go`,".rs":`rust`,".java":`java`};var N=class{queryCache=new Map;scmCache=new Map;execute(e,t,n,r){let i=this.getOrCompile(t,n,r);return i?i.matches(e).map(e=>P(e)):[]}executeCaptures(e,t,n,r){let i=this.getOrCompile(t,n,r);return i?i.captures(e).map(e=>F(e)):[]}executeRaw(e,t,n){return t.query(n).matches(e).map(e=>P(e))}getOrCompile(e,t,n){let r=M[t];if(!r)return null;let i=`${r}:${n}`,a=this.queryCache.get(i);if(a)return a;let o=this.loadScm(r,n);if(!o)return null;try{let t=e.query(o);return this.queryCache.set(i,t),t}catch(e){throw O.warn(`Failed to compile query`,{langDir:r,queryType:n,error:String(e)}),Error(`Failed to compile ${r}/${n}.scm: ${String(e)}`)}}loadScm(e,t){let r=`${e}:${t}`,i=this.scmCache.get(r);if(i!==void 0)return i;let a=n(j,e,`${t}.scm`);try{let e=o(a,`utf-8`);return this.scmCache.set(r,e),e}catch{return O.info(`Query file not found (graceful skip)`,{langDir:e,queryType:t}),null}}dispose(){this.queryCache.clear(),this.scmCache.clear()}static resolveQueryDir(e){return n(j,e)}};function P(e){let t=new Map;for(let n of e.captures)t.set(n.name,F(n));return{pattern:e.pattern,captures:t}}function F(e){let{node:t}=e;return{name:e.name,text:t.text,nodeType:t.type,startLine:t.startPosition.row,endLine:t.endPosition.row,startColumn:t.startPosition.column,endColumn:t.endPosition.column,node:t}}const I=new N,L=new Set([`function_declaration`,`method_definition`,`arrow_function`,`function_definition`,`method_declaration`,`constructor_declaration`,`function_declaration`,`method_declaration`,`function_item`]);async function R(e,t,n=``){let r=await _.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);return a?I.execute(i.rootNode,a,t,`calls`).map(e=>z(e,i.rootNode,n)).filter(e=>e!==null):[]}function z(e,t,n){let r=e.captures.get(`callee`);if(!r)return null;let i=e.captures.get(`node`);return{callerFile:n,callerName:B(i?.node??r.node),calleeName:r.text,line:(i?.startLine??r.startLine)+1}}function B(e){let t=e.parent;for(;t;){if(L.has(t.type)){let e=V(t);if(e)return e}t=t.parent}return`<module>`}function V(e){let t=e.childForFieldName(`name`);if(t)return t.text;for(let t of e.children)if(t.type===`identifier`||t.type===`property_identifier`||t.type===`field_identifier`)return t.text;return null}const H=new N,U={handler:`lambda-handler`,lambdaHandler:`lambda-handler`,main:`main`,__name__:`main`,app:`server`,server:`server`,router:`server`,urlpatterns:`server`,init:`main`},W={SpringBootApplication:`server`,RestController:`server`,Controller:`server`};async function G(e,t,n=``){let r=await _.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);if(!a)return[];let o=H.execute(i.rootNode,a,t,`entry-points`),s=[],c=new Set;for(let e of o){let r=K(e,t,n);if(r){let e=`${r.name}:${r.type}`;c.has(e)||(c.add(e),s.push(r))}}return s}function K(e,t,n){let r=e.captures.get(`name`);if(!r)return null;let i=r.text,a=e.captures.get(`_parent`);if(a){let e=a.text;if([`Construct`,`Stack`,`NestedStack`,`Stage`].includes(e))return{name:i,type:`cdk-construct`,filePath:n}}let o=e.captures.get(`_ann`);if(o){let e=W[o.text];if(e)return{name:i,type:e,filePath:n}}let s=U[i];return s?{name:i,type:s,filePath:n}:t===`.go`&&i.toLowerCase().startsWith(`handle`)?{name:i,type:`server`,filePath:n,trigger:`HTTP handler`}:{name:i,type:`main`,filePath:n}}const q=new N;async function J(e,t,n=``){let r=await _.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);if(!a)return[];let o=q.execute(i.rootNode,a,t,`imports`),s=[];for(let e of o){let r=e.captures.get(`source`);if(!r){let r=e.captures.get(`node`);if(r){let e=oe(r.text,t);e&&s.push({source:e.source,specifiers:e.specifiers,filePath:n,isExternal:X(e.source,t),confidence:`high`})}continue}let i=r.text,a=Y(i,t),o=ae(e.captures.get(`node`)?.text??``,t,a);s.push({source:a,specifiers:o,filePath:n,isExternal:X(a,t),confidence:`high`})}return s}function Y(e,t){let n=e.replace(/^['"`]|['"`]$/g,``);return t===`.go`&&(n=n.replace(/^"|"$/g,``)),n}function X(e,t){return t===`.py`?!e.startsWith(`.`):t===`.go`?e.includes(`/`)||e.includes(`.`):t===`.java`?!0:t===`.rs`?!e.startsWith(`self`)&&!e.startsWith(`super`)&&!e.startsWith(`crate`):!e.startsWith(`.`)&&!e.startsWith(`/`)}function ae(e,t,n){if(!e)return[n];if(t===`.py`){let t=e.match(/import\s+(.+)$/m);return t?t[1].split(`,`).map(e=>e.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean):[n]}if(t===`.java`){let e=n.split(`.`);return[e[e.length-1]]}if(t===`.go`){let e=n.split(`/`);return[e[e.length-1]]}if(t===`.rs`){if(n.includes(`{`)){let e=n.match(/\{([^}]+)\}/);if(e)return e[1].split(`,`).map(e=>e.trim()).filter(Boolean)}let e=n.split(`::`);return[e[e.length-1]]}let r=e.match(/\{([^}]+)\}/);if(r)return r[1].split(`,`).map(e=>e.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean);let i=e.match(/import\s+(\w+)/);return i?[i[1]]:[n]}function oe(e,t){if(t===`.py`){let t=e.match(/^import\s+([\w.]+)/);if(t)return{source:t[1],specifiers:[t[1]]}}return null}const se=new N;async function ce(e,t,n=``){let r=await _.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);if(!a)return[];let o=se.execute(i.rootNode,a,t,`patterns`),s=new Map;for(let e of o){let r=le(e,t);if(!r)continue;let i=e.captures.get(`name`),a=`${n}:${(e.captures.get(`node`)?.startLine??i?.startLine??0)+1}`,o=s.get(r.pattern);o?o.locations.push(a):s.set(r.pattern,{description:r.description,locations:[a]})}let c=[];for(let[e,{description:t,locations:n}]of s)c.push({pattern:e,description:t,locations:n,confidence:`high`});return c}function le(e,t){let n=e.captures.get(`name`)?.text;if(!n)return null;let r=e.captures.get(`node`)?.nodeType??``;if(/^(create|build)[A-Z]/.test(n)||/^(of|from|new)[A-Z]/.test(n))return{pattern:`factory`,description:`Factory function/method`};if(/^(register|bind)$/.test(n))return{pattern:`dependency-injection`,description:`DI container registration`};if(/^(Injectable|Component|Service|Controller|Module|Singleton|Repository|Bean)$/.test(n))return{pattern:`dependency-injection`,description:`Framework DI annotation`};if(/^(Map|WeakMap|Set)$/.test(n))return{pattern:`cached-instance`,description:`Cached Map/Set instance`};if(t===`.py`){if(n===`__new__`)return{pattern:`singleton`,description:`Singleton pattern (__new__ override)`};if(n===`__enter__`)return{pattern:`context-manager`,description:`Context manager pattern`};if(r===`decorated_definition`)return{pattern:`decorator`,description:`Decorator usage`}}if(t===`.go`){if(r===`type_declaration`)return{pattern:`interface`,description:`Interface definition`};if(r===`go_statement`)return{pattern:`concurrency`,description:`Goroutine concurrency pattern`};if(n===`make`)return{pattern:`concurrency`,description:`Channel/make pattern`}}if(t===`.rs`){if(r===`impl_item`)return{pattern:`trait-impl`,description:`Trait implementation`};if(r===`attribute_item`){if(n===`derive`)return{pattern:`derive`,description:`Derive macro attribute`};if(n===`test`)return{pattern:`test`,description:`Test attribute`}}}if(t===`.java`){if(r===`class_declaration`)return{pattern:`singleton`,description:`Singleton pattern (private constructor)`};if(r===`marker_annotation`)return{pattern:`dependency-injection`,description:`Framework DI annotation`}}if(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(t)){if(r===`class_declaration`)return{pattern:`singleton`,description:`Singleton pattern (private constructor)`};if(r===`decorator`)return{pattern:`decorator`,description:`Framework decorator pattern`}}return{pattern:r||`unknown`,description:`Detected pattern: ${n}`}}const ue=new Set([`function_declaration`,`method_definition`,`arrow_function`,`class_declaration`,`function_definition`,`class_definition`,`method_declaration`,`constructor_declaration`,`class_declaration`,`function_declaration`,`method_declaration`,`function_item`,`impl_item`]);async function de(e,t,n){let r=await(await _.ensure()).parse(e,t);if(!r)return[{name:`<module>`,type:`module`,line:1}];let i=fe(r.rootNode,n-1);if(!i)return[{name:`<module>`,type:`module`,line:1}];let a=[];return pe(i,a),a.push({name:`<module>`,type:`module`,line:1}),a}function fe(e,t){let n=null;function r(e){if(e.startPosition.row<=t&&e.endPosition.row>=t){n=e;for(let t of e.children)r(t)}}return r(e),n}function pe(e,t){let n=e.parent;for(;n;){if(ue.has(n.type)){let e=me(n),r=he(n.type);t.push({name:e??`<anonymous>`,type:r,line:n.startPosition.row+1})}n=n.parent}}function me(e){let t=e.childForFieldName(`name`);if(t)return t.text;for(let t of e.children)if(t.type===`identifier`||t.type===`type_identifier`||t.type===`property_identifier`||t.type===`field_identifier`)return t.text;return null}function he(e){return e.includes(`class`)||e===`impl_item`?`class`:`function`}const ge=new N,_e={function_declaration:`function`,class_declaration:`class`,interface_declaration:`interface`,type_alias_declaration:`type`,enum_declaration:`enum`,lexical_declaration:`const`,method_definition:`method`,public_field_definition:`variable`,field_definition:`variable`,function_definition:`function`,class_definition:`class`,expression_statement:`variable`,method_declaration:`method`,constructor_declaration:`method`,field_declaration:`variable`,type_spec:`type`,type_declaration:`type`,const_spec:`const`,var_spec:`variable`,function_item:`function`,struct_item:`class`,enum_item:`enum`,trait_item:`interface`,impl_item:`type`,const_item:`const`,static_item:`variable`,type_item:`type`};async function ve(e,t,n=``){let r=await _.ensure(),i=await r.parse(e,t);if(!i)return[];let a=r.getLanguage(t);return a?ye(ge.execute(i.rootNode,a,t,`symbols`),t,n):[]}function ye(e,t,n){let r=new Map;for(let n of e){let e=n.captures.get(`name`);if(!e)continue;let i=`${e.text}:${(n.captures.get(`node`)?.startLine??e.startLine)+1}`,a=be(n,t),o=r.get(i);(!o||!o.exported&&a)&&r.set(i,{match:n,exported:a})}let i=[];for(let{match:e,exported:a}of r.values()){let r=e.captures.get(`name`),o=e.captures.get(`node`);if(!r)continue;let s=_e[o?.nodeType??r.nodeType]??`variable`,c=(o?.startLine??r.startLine)+1,l=xe(s,o?.node,t),u=o?.node??r.node;i.push({name:r.text,kind:l,exported:a,filePath:n,line:c,signature:Se(o?.node,l),returnType:Te(o?.node,l),jsdoc:Ee(u),decorators:De(u),typeBody:Oe(o?.node,l)})}return i}function be(e,t){if(e.captures.has(`exported`))return!0;let n=e.captures.get(`name`)?.text;if(!n)return!1;if(t===`.py`)return!n.startsWith(`_`);if(t===`.go`)return/^[A-Z]/.test(n);if(t===`.java`){let t=e.captures.get(`node`)?.text??``;return/\bpublic\b/.test(t)}return!1}function xe(e,t,n){if(n===`.go`&&e===`type`&&t?.children){let e=t.type===`type_declaration`?t.children.flatMap(e=>e.children??[]):t.children;for(let t of e){if(t.type===`interface_type`)return`interface`;if(t.type===`struct_type`)return`class`}}return e}function Se(e,t){if(e){if(t===`function`||t===`method`)return Z(e);if(t===`class`)return Ce(e);if(t===`interface`)return we(e)}}function Z(e){let t=e.childForFieldName(`parameters`)??e.childForFieldName(`parameter_list`),n=e.childForFieldName(`return_type`)??e.childForFieldName(`type`),r=e.childForFieldName(`result`);if(!t){for(let t of e.children)if(t.type===`formal_parameters`||t.type===`parameter_list`||t.type===`parameters`){let e=t.text;return n&&(e+=n.text),r&&(e+=` ${r.text}`),e.length>120?`${e.slice(0,117)}...`:e}return}let i=t.text;return n&&(i+=n.text),r&&(i+=` ${r.text}`),i.length>120?`${i.slice(0,117)}...`:i}function Ce(e){let t=e.childForFieldName(`body`)??e.childForFieldName(`field_declaration_list`);if(!t){for(let t of e.children)if(t.type===`struct_type`||t.type===`class_body`)return Q(t);return}return Q(t)}function Q(e){let t=[];for(let n of e.children){if(n.type===`method_definition`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`method_declaration`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`field_declaration`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`function_definition`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}}if(t.length===0)return;let n=t.join(`, `);return n.length>120?`${n.slice(0,117)}...`:n}function we(e){let t=e.childForFieldName(`body`);if(!t){for(let t of e.children)if(t.type===`interface_type`)return $(t);return}return $(t)}function $(e){let t=[];for(let n of e.children){if(n.type===`property_signature`||n.type===`method_signature`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`method_declaration`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`method_spec`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}if(n.type===`function_signature_item`||n.type===`declaration_list`){let e=n.childForFieldName(`name`);e&&t.push(e.text)}}if(t.length===0)return;let n=t.join(`, `);return n.length>120?`${n.slice(0,117)}...`:n}function Te(e,t){if(!e||t!==`function`&&t!==`method`)return;let n=e.childForFieldName(`return_type`)??e.childForFieldName(`type`);if(n){let e=n.text.replace(/^:\s*/,``).trim();return e.length>200?`${e.slice(0,200)}…`:e}let r=e.childForFieldName(`result`);if(r)return r.text.trim()}function Ee(e){let t=e.parent;if(!t?.children)return;let n=t.children.indexOf(e);if(n<=0)return;let r=t.children[n-1];if(r){if(r.type===`comment`||r.type===`block_comment`||r.type===`doc_comment`)return r.text.replace(/^\/\*\*?\s*|\s*\*\/$/g,``).split(`
23
23
  `).map(e=>e.replace(/^\s*\*\s?/,``).trim()).filter(e=>e.length>0&&!e.startsWith(`@`))[0]?.slice(0,200)||void 0;if(e.children[0]?.type===`expression_statement`){let t=e.children[0].children[0];if(t&&(t.type===`string`||t.type===`concatenated_string`))return t.text.replace(/^['"`]{1,3}|['"`]{1,3}$/g,``).trim().split(`
24
- `)[0]?.trim()?.slice(0,200)||void 0}}}function Te(e){let t=e.parent;if(!t?.children)return;let n=t.children.indexOf(e),r=[];for(let e=n-1;e>=0;e--){let n=t.children[e];if(n.type===`decorator`||n.type===`annotation`||n.type===`marker_annotation`){let e=n.text.trim();r.unshift(e.length>100?`${e.slice(0,100)}…`:e)}else if(n.type!==`comment`&&n.type!==`block_comment`&&n.type!==`doc_comment`)break}return r.length>0?r:void 0}function Ee(e,t){if(!e||t!==`interface`&&t!==`type`)return;let n=e.childForFieldName(`body`)??e.childForFieldName(`value`)??e.children.find(e=>e.type===`object_type`||e.type===`interface_body`||e.type===`type_body`);if(!n)return;let r=n.text.replace(/\n\s*/g,` `).replace(/\s+/g,` `).trim();return r.length>500?`${r.slice(0,500)}…`:r}export{x as CodeChunker,S as GenericChunker,C as MarkdownChunker,M as QueryExecutor,u as SUPPORTED_EXTENSIONS,E as WasmChunker,h as WasmRuntime,ne as createChunker,re as createChunkerSync,W as detectEntryPoints,oe as detectPatterns,v as extractCallEdges,L as extractCalls,q as extractImports,ge as extractSymbols,ee as initializeWasm,d as resolveGrammarPath,f as resolveParserWasmPath,le as resolveScopes};
24
+ `)[0]?.trim()?.slice(0,200)||void 0}}}function De(e){let t=e.parent;if(!t?.children)return;let n=t.children.indexOf(e),r=[];for(let e=n-1;e>=0;e--){let n=t.children[e];if(n.type===`decorator`||n.type===`annotation`||n.type===`marker_annotation`){let e=n.text.trim();r.unshift(e.length>100?`${e.slice(0,100)}…`:e)}else if(n.type!==`comment`&&n.type!==`block_comment`&&n.type!==`doc_comment`)break}return r.length>0?r:void 0}function Oe(e,t){if(!e||t!==`interface`&&t!==`type`)return;let n=e.childForFieldName(`body`)??e.childForFieldName(`value`)??e.children.find(e=>e.type===`object_type`||e.type===`interface_body`||e.type===`type_body`);if(!n)return;let r=n.text.replace(/\n\s*/g,` `).replace(/\s+/g,` `).trim();return r.length>500?`${r.slice(0,500)}…`:r}export{C as CodeChunker,w as GenericChunker,T as MarkdownChunker,N as QueryExecutor,f as SUPPORTED_EXTENSIONS,D as WasmChunker,_ as WasmRuntime,re as createChunker,ie as createChunkerSync,G as detectEntryPoints,ce as detectPatterns,b as extractCallEdges,R as extractCalls,J as extractImports,ve as extractSymbols,ee as initializeWasm,p as resolveGrammarPath,m as resolveParserWasmPath,de as resolveScopes};
@@ -3957,7 +3957,7 @@ ${e.themeCSS}`),e.fontFamily!==void 0&&(n+=`
3957
3957
  .tree-metadata { color: var(--aikit-muted, #9ca3af); font: 500 11px var(--aikit-font-sans, Inter, sans-serif); }
3958
3958
  .tree-children { margin-left: 18px; padding-left: 12px; border-left: 1px dashed var(--aikit-border, #3c3c3c); }
3959
3959
  .tree-children[hidden] { display: none; }
3960
- `;function G9(e){return typeof e==`object`&&!!e&&typeof e.label==`string`}var Pdt={name:`tree`,label:`Tree`,detect(e){if(Array.isArray(e)){let t=e[0];return G9(t)&&Array.isArray(t.children)?.7:0}if(typeof e!=`object`||!e)return 0;let t=e;if(Array.isArray(t.root)){let e=t.root[0];return G9(e)&&Array.isArray(e.children)?.85:0}return G9(t.root)&&Array.isArray(t.root.children)?.85:0},render(e,t,n){Xu(`tpl-tree`,Ndt);let r=t,i=Array.isArray(r)?r:Array.isArray(r.root)?r.root:[r.root],a=Zu(`div`,`block tpl-tree`),o=(e,t)=>{let n=Zu(`div`,`tree-node`),r=Zu(`div`,`tree-row`);if(r.id=ed(e.id??`${e.label}-${t}`),e.children?.length){let i=document.createElement(`button`),a=t<1;i.className=`tree-toggle`,i.textContent=a?`▼`:`▶`,r.appendChild(i);let s=Zu(`div`,`tree-children`);s.dataset.depth=String(t),s.hidden=!a;for(let n of e.children)s.appendChild(o(n,t+1));i.addEventListener(`click`,()=>{s.hidden=!s.hidden,i.textContent=s.hidden?`▶`:`▼`}),n.appendChild(r),n.appendChild(s)}else r.appendChild(Zu(`span`,`tree-spacer`)),n.appendChild(r);if(e.icon&&r.appendChild(Zu(`span`,`tree-icon`,e.icon)),r.appendChild(Zu(`span`,`tree-label`,e.label)),e.metadata&&Object.keys(e.metadata).length>0){let t=Zu(`span`,`tree-metadata`);t.textContent=Object.entries(e.metadata).map(([e,t])=>`${e}: ${$u(t)}`).join(` · `),r.appendChild(t)}return n};for(let e of i)a.appendChild(o(e,0));e.appendChild(a)},styles(){return Ndt}},K9=new Xse({name:`AI Kit Present`,version:`1.0.0`}),Fdt=document.getElementById(`app`);if(!Fdt)throw Error(`Missing #app element`);var q9=Fdt,J9=new ldt;J9.register(Odt),J9.register(gdt),J9.register(Adt),J9.register(Sdt),J9.register(wdt),J9.register(Mdt),J9.register(mdt),J9.register(Edt),J9.register(Pdt),J9.register(ydt);var Idt=idt(K9),Y9={app:K9,data:adt(K9),emitAction:Idt},X9=new fdt,Ldt=new cdt,Rdt=new odt(K9);K9.connect().then(()=>{let e=K9.getHostContext();e&&(X9.apply(e),Ldt.apply(e),Rdt.apply(e))}),K9.onhostcontextchanged=e=>{X9.apply(e),Ldt.apply(e),Rdt.apply(e),Q9?.onThemeChange&&Q9.onThemeChange(X9.getTheme())};var Z9;K9.ontoolinputpartial=e=>{let t=e.arguments;t&&(q9.dataset.streaming=`true`,clearTimeout(Z9),Z9=setTimeout(()=>{try{let e=t.content;if(!e)return;zdt({title:t.title,template:t.template,content:e})}catch{}},80))},K9.ontoolinput=()=>{clearTimeout(Z9),delete q9.dataset.streaming};function zdt(e){if(q9.innerHTML=``,e.title){let t=Zu(`div`,`header`);t.appendChild(Zu(`h1`,``,e.title)),t.appendChild(Zu(`span`,`badge streaming`,`⟳`)),q9.appendChild(t)}let t=Zu(`div`,`content`);if(Array.isArray(e.content)&&e.content.length>0&&td(e.content[0]))for(let n of e.content)td(n)&&t.appendChild(Yut(n,Y9));else t.appendChild(B9(e.content));q9.appendChild(t)}K9.ontoolresult=e=>{if(clearTimeout(Z9),delete q9.dataset.streaming,e.structuredContent)try{$9(e.structuredContent);return}catch(e){Bdt(`Render error`,e);return}let t=e.content?.find(e=>e.type===`text`)?.text;if(!t){q9.innerHTML=`<p>No data received.</p>`;return}try{$9(JSON.parse(t))}catch{$9({content:t})}};var Q9=null;function Bdt(e,t){q9.innerHTML=``;let n=Zu(`div`,`error-panel`);n.appendChild(Zu(`h3`,``,`⚠ ${e}`)),n.appendChild(Zu(`pre`,``,t instanceof Error?t.message:String(t))),q9.appendChild(n)}function $9(e){if(Q9?.destroy&&Q9.destroy(),Q9=null,q9.innerHTML=``,!e.content){q9.innerHTML=`<p class="no-data">No content data received.</p>`;return}if(e.title){let t=Zu(`div`,`header`);t.appendChild(Zu(`h1`,``,e.title)),t.appendChild(Zu(`span`,`badge`,`AI KIT`)),q9.appendChild(t)}let t=e.template?J9.get(e.template):J9.detect(e.content),n=Zu(`div`,`content`);if(t)Q9=t,t.render(n,e.content,Y9);else if(Array.isArray(e.content)&&e.content.length>0&&td(e.content[0]))for(let t of e.content)td(t)&&n.appendChild(Yut(t,Y9));else n.appendChild(B9(e.content));q9.appendChild(n),e.actions?.length&&q9.appendChild(rdt(e.actions,Y9))}</script>
3960
+ `;function G9(e){return typeof e==`object`&&!!e&&typeof e.label==`string`}var Pdt={name:`tree`,label:`Tree`,detect(e){if(Array.isArray(e)){let t=e[0];return G9(t)&&Array.isArray(t.children)?.7:0}if(typeof e!=`object`||!e)return 0;let t=e;if(Array.isArray(t.root)){let e=t.root[0];return G9(e)&&Array.isArray(e.children)?.85:0}return G9(t.root)&&Array.isArray(t.root.children)?.85:0},render(e,t,n){Xu(`tpl-tree`,Ndt);let r=t,i=Array.isArray(r)?r:Array.isArray(r.root)?r.root:[r.root],a=Zu(`div`,`block tpl-tree`),o=(e,t)=>{let n=Zu(`div`,`tree-node`),r=Zu(`div`,`tree-row`);if(r.id=ed(e.id??`${e.label}-${t}`),e.children?.length){let i=document.createElement(`button`),a=t<1;i.className=`tree-toggle`,i.textContent=a?`▼`:`▶`,r.appendChild(i);let s=Zu(`div`,`tree-children`);s.dataset.depth=String(t),s.hidden=!a;for(let n of e.children)s.appendChild(o(n,t+1));i.addEventListener(`click`,()=>{s.hidden=!s.hidden,i.textContent=s.hidden?`▶`:`▼`}),n.appendChild(r),n.appendChild(s)}else r.appendChild(Zu(`span`,`tree-spacer`)),n.appendChild(r);if(e.icon&&r.appendChild(Zu(`span`,`tree-icon`,e.icon)),r.appendChild(Zu(`span`,`tree-label`,e.label)),e.metadata&&Object.keys(e.metadata).length>0){let t=Zu(`span`,`tree-metadata`);t.textContent=Object.entries(e.metadata).map(([e,t])=>`${e}: ${$u(t)}`).join(` · `),r.appendChild(t)}return n};for(let e of i)a.appendChild(o(e,0));e.appendChild(a)},styles(){return Ndt}},K9=new Xse({name:`AI Kit Present`,version:`1.0.0`}),Fdt=document.getElementById(`app`);if(!Fdt)throw Error(`Missing #app element`);var q9=Fdt,J9=new ldt;J9.register(Odt),J9.register(gdt),J9.register(Adt),J9.register(Sdt),J9.register(wdt),J9.register(Mdt),J9.register(mdt),J9.register(Edt),J9.register(Pdt),J9.register(ydt);var Idt=idt(K9),Y9={app:K9,data:adt(K9),emitAction:Idt},X9=new fdt,Ldt=new cdt,Rdt=new odt(K9);K9.connect().then(()=>{let e=K9.getHostContext();e&&(X9.apply(e),Ldt.apply(e),Rdt.apply(e))}),K9.onhostcontextchanged=e=>{X9.apply(e),Ldt.apply(e),Rdt.apply(e),Q9?.onThemeChange&&Q9.onThemeChange(X9.getTheme())};var Z9;K9.ontoolinputpartial=e=>{let t=e.arguments;t&&(q9.dataset.streaming=`true`,clearTimeout(Z9),Z9=setTimeout(()=>{try{let e=t.content;if(!e)return;zdt({title:t.title,template:t.template,content:e})}catch{}},80))},K9.ontoolinput=()=>{clearTimeout(Z9),delete q9.dataset.streaming};function zdt(e){if(q9.innerHTML=``,e.title){let t=Zu(`div`,`header`);t.appendChild(Zu(`h1`,``,e.title)),t.appendChild(Zu(`span`,`badge streaming`,`⟳`)),q9.appendChild(t)}let t=e.content;if(!Array.isArray(t)&&typeof t==`object`&&t){let e=t;Array.isArray(e.blocks)&&e.blocks.length>0&&(t=e.blocks)}let n=Zu(`div`,`content`);if(Array.isArray(t)&&t.length>0&&td(t[0]))for(let e of t)td(e)&&n.appendChild(Yut(e,Y9));else n.appendChild(B9(t));q9.appendChild(n)}K9.ontoolresult=e=>{if(clearTimeout(Z9),delete q9.dataset.streaming,e.structuredContent)try{$9(e.structuredContent);return}catch(e){Bdt(`Render error`,e);return}let t=e.content?.find(e=>e.type===`text`)?.text;if(!t){q9.innerHTML=`<p>No data received.</p>`;return}try{$9(JSON.parse(t))}catch{$9({content:t})}};var Q9=null;function Bdt(e,t){q9.innerHTML=``;let n=Zu(`div`,`error-panel`);n.appendChild(Zu(`h3`,``,`⚠ ${e}`)),n.appendChild(Zu(`pre`,``,t instanceof Error?t.message:String(t))),q9.appendChild(n)}function $9(e){Q9?.destroy&&Q9.destroy(),Q9=null,q9.innerHTML=``;let t=e.content;if(!Array.isArray(t)&&typeof t==`object`&&t){let e=t;Array.isArray(e.blocks)&&e.blocks.length>0&&(t=e.blocks)}if(!t){q9.innerHTML=`<p class="no-data">No content data received.</p>`;return}if(e.title){let t=Zu(`div`,`header`);t.appendChild(Zu(`h1`,``,e.title)),t.appendChild(Zu(`span`,`badge`,`AI KIT`)),q9.appendChild(t)}let n=e.template?J9.get(e.template):J9.detect(t),r=Zu(`div`,`content`);if(n)Q9=n,n.render(r,t,Y9);else if(Array.isArray(t)&&t.length>0&&td(t[0]))for(let e of t)td(e)&&r.appendChild(Yut(e,Y9));else r.appendChild(B9(t));q9.appendChild(r),e.actions?.length&&q9.appendChild(rdt(e.actions,Y9))}</script>
3961
3961
  </head>
3962
3962
  <body>
3963
3963
  <div id="app">
@@ -1 +1 @@
1
- import{t as e}from"./curated-manager-DX-_oJg0.js";import{readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{parseArgs as a}from"node:util";import{createLogger as o,serializeError as s}from"../../core/dist/index.js";const c=n(i(import.meta.url)),l=(()=>{try{let e=r(c,`..`,`..`,`..`,`package.json`);return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}})(),u=o(`server`),{values:d}=a({options:{transport:{type:`string`,default:process.env.AIKIT_TRANSPORT??`stdio`},port:{type:`string`,default:process.env.AIKIT_PORT??`3210`}}});async function f(){if(process.on(`unhandledRejection`,e=>{u.error(`Unhandled rejection`,s(e))}),u.info(`Starting MCP AI Kit server`,{version:l}),d.transport===`http`){let[{default:e},{loadConfig:t,resolveIndexMode:n},{registerDashboardRoutes:r,resolveDashboardDir:i}]=await Promise.all([import(`express`),import(`./config-C5IU9Lau.js`),import(`./dashboard-static-BfIe0Si1.js`)]),a=t();u.info(`Config loaded`,{sourceCount:a.sources.length,storePath:a.store.path});let o=e();o.use(e.json());let c=Number(d.port);o.use((e,t,n)=>{if(t.setHeader(`Access-Control-Allow-Origin`,process.env.AIKIT_CORS_ORIGIN??`http://localhost:${c}`),t.setHeader(`Access-Control-Allow-Methods`,`GET, POST, DELETE, OPTIONS`),t.setHeader(`Access-Control-Allow-Headers`,`Content-Type, Authorization`),e.method===`OPTIONS`){t.status(204).end();return}n()}),r(o,i(),u),o.get(`/health`,(e,t)=>{t.json({status:`ok`})});let l=!1,f=null,p=null,m=null,h=Promise.resolve();o.post(`/mcp`,async(e,t)=>{if(!l||!p||!m){t.status(503).json({jsonrpc:`2.0`,error:{code:-32603,message:`Server initializing — please retry in a few seconds`},id:null});return}let n=h,r;h=new Promise(e=>{r=e}),await n;try{let n=new m({sessionIdGenerator:void 0});await p.connect(n),await n.handleRequest(e,t,e.body),n.close()}catch(e){if(u.error(`MCP handler error`,s(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()}}),o.get(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))}),o.delete(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))});let g=o.listen(c,`127.0.0.1`,()=>{u.info(`MCP server listening`,{url:`http://127.0.0.1:${c}/mcp`,port:c}),setTimeout(async()=>{try{let[{createLazyServer:e,ALL_TOOL_NAMES:t},{StreamableHTTPServerTransport:r},{checkForUpdates:i,autoUpgradeScaffold:o}]=await Promise.all([import(`./server-DFqOZEJC.js`),import(`@modelcontextprotocol/sdk/server/streamableHttp.js`),import(`./version-check-D4j0Pykd.js`)]);i(),o();let c=n(a),d=e(a,c);p=d.server,m=r,l=!0,u.info(`MCP server configured (lazy — AI Kit initializing in background)`,{toolCount:t.length,resourceCount:2}),d.startInit(),c===`auto`?d.ready.then(async()=>{try{let e=a.sources.map(e=>e.path).join(`, `);u.info(`Running initial index`,{sourcePaths:e}),await d.runInitialIndex(),u.info(`Initial index complete`)}catch(e){u.error(`Initial index failed; will retry on aikit_reindex`,s(e))}}).catch(e=>u.error(`AI Kit init or indexing failed`,s(e))):c===`smart`?d.ready.then(async()=>{try{if(!d.kb)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`);f=new e(d.kb.indexer,a,d.kb.store),f.start(),d.setSmartScheduler(f),u.info(`Smart index scheduler started (HTTP mode)`)}catch(e){u.error(`Failed to start smart index scheduler`,s(e))}}).catch(e=>u.error(`AI Kit initialization failed`,s(e))):(d.ready.catch(e=>u.error(`AI Kit initialization failed`,s(e))),u.info(`Initial full indexing skipped in HTTP mode`,{indexMode:c}))}catch(e){u.error(`Failed to load server modules`,s(e))}},100)}),_=async e=>{u.info(`Shutdown signal received`,{signal:e}),f?.stop(),g.close(),p&&await p.close(),process.exit(0)};process.on(`SIGINT`,()=>_(`SIGINT`)),process.on(`SIGTERM`,()=>_(`SIGTERM`))}else{let[{loadConfig:e,reconfigureForWorkspace:t,resolveIndexMode:n},{createLazyServer:r},{checkForUpdates:a,autoUpgradeScaffold:o},{RootsListChangedNotificationSchema:c}]=await Promise.all([import(`./config-C5IU9Lau.js`),import(`./server-DFqOZEJC.js`),import(`./version-check-D4j0Pykd.js`),import(`@modelcontextprotocol/sdk/types.js`)]),l=e();u.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path}),a(),o();let d=n(l),f=r(l,d),{server:p,startInit:m,ready:h,runInitialIndex:g}=f,{StdioServerTransport:_}=await import(`@modelcontextprotocol/sdk/server/stdio.js`),v=new _;await p.connect(v),u.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 u.info(`MCP roots resolved`,{rootUri:n,rootPath:r,rootCount:e.length}),t(l,r),!0},b=!1;try{b=y((await p.server.listRoots()).roots),b||u.info(`No MCP roots yet; waiting for roots/list_changed notification`)}catch(e){u.warn(`MCP roots/list not supported by client; using cwd fallback`,{cwd:process.cwd(),...s(e)}),b=!0}b||=await new Promise(e=>{let t=setTimeout(()=>{u.warn(`Timed out waiting for MCP roots/list_changed; using cwd fallback`,{cwd:process.cwd()}),e(!1)},5e3);p.server.setNotificationHandler(c,async()=>{clearTimeout(t);try{e(y((await p.server.listRoots()).roots))}catch(t){u.warn(`roots/list retry failed after notification`,s(t)),e(!1)}})}),m();let x=null,S=()=>{x&&clearTimeout(x),x=setTimeout(()=>{u.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=>{u.error(`Initialization failed — server will continue with limited tools`,s(e))}),d===`auto`?g().catch(e=>u.error(`Initial index failed`,s(e))):d===`smart`?h.then(async()=>{try{if(!f.kb)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(f.kb.indexer,l,f.kb.store);t.start(),f.setSmartScheduler(t),u.info(`Smart index scheduler started (stdio mode)`)}catch(e){u.error(`Failed to start smart index scheduler`,s(e))}}).catch(e=>u.error(`AI Kit init failed for smart scheduler`,s(e))):u.warn(`Initial full indexing skipped; use aikit_reindex to index manually`,{indexMode:d})}}f().catch(e=>{u.error(`Fatal error`,s(e)),process.exit(1)});export{e as CuratedKnowledgeManager};
1
+ import{t as e}from"./curated-manager-DX-_oJg0.js";import{readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{parseArgs as a}from"node:util";import{createLogger as o,serializeError as s}from"../../core/dist/index.js";const c=n(i(import.meta.url)),l=(()=>{try{let e=r(c,`..`,`..`,`..`,`package.json`);return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}})(),u=o(`server`),{values:d}=a({options:{transport:{type:`string`,default:process.env.AIKIT_TRANSPORT??`stdio`},port:{type:`string`,default:process.env.AIKIT_PORT??`3210`}}});async function f(){if(process.on(`unhandledRejection`,e=>{u.error(`Unhandled rejection`,s(e))}),u.info(`Starting MCP AI Kit server`,{version:l}),d.transport===`http`){let[{default:e},{loadConfig:t,resolveIndexMode:n},{registerDashboardRoutes:r,resolveDashboardDir:i}]=await Promise.all([import(`express`),import(`./config-C5IU9Lau.js`),import(`./dashboard-static-BfIe0Si1.js`)]),a=t();u.info(`Config loaded`,{sourceCount:a.sources.length,storePath:a.store.path});let o=e();o.use(e.json());let c=Number(d.port);o.use((e,t,n)=>{if(t.setHeader(`Access-Control-Allow-Origin`,process.env.AIKIT_CORS_ORIGIN??`http://localhost:${c}`),t.setHeader(`Access-Control-Allow-Methods`,`GET, POST, DELETE, OPTIONS`),t.setHeader(`Access-Control-Allow-Headers`,`Content-Type, Authorization`),e.method===`OPTIONS`){t.status(204).end();return}n()}),r(o,i(),u),o.get(`/health`,(e,t)=>{t.json({status:`ok`})});let l=!1,f=null,p=null,m=null,h=Promise.resolve();o.post(`/mcp`,async(e,t)=>{if(!l||!p||!m){t.status(503).json({jsonrpc:`2.0`,error:{code:-32603,message:`Server initializing — please retry in a few seconds`},id:null});return}let n=h,r;h=new Promise(e=>{r=e}),await n;try{let n=new m({sessionIdGenerator:void 0});await p.connect(n),await n.handleRequest(e,t,e.body),n.close()}catch(e){if(u.error(`MCP handler error`,s(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()}}),o.get(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))}),o.delete(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))});let g=o.listen(c,`127.0.0.1`,()=>{u.info(`MCP server listening`,{url:`http://127.0.0.1:${c}/mcp`,port:c}),setTimeout(async()=>{try{let[{createLazyServer:e,ALL_TOOL_NAMES:t},{StreamableHTTPServerTransport:r},{checkForUpdates:i,autoUpgradeScaffold:o}]=await Promise.all([import(`./server-DOXU8yxT.js`),import(`@modelcontextprotocol/sdk/server/streamableHttp.js`),import(`./version-check-D4j0Pykd.js`)]);i(),o();let c=n(a),d=e(a,c);p=d.server,m=r,l=!0,u.info(`MCP server configured (lazy — AI Kit initializing in background)`,{toolCount:t.length,resourceCount:2}),d.startInit(),c===`auto`?d.ready.then(async()=>{try{let e=a.sources.map(e=>e.path).join(`, `);u.info(`Running initial index`,{sourcePaths:e}),await d.runInitialIndex(),u.info(`Initial index complete`)}catch(e){u.error(`Initial index failed; will retry on aikit_reindex`,s(e))}}).catch(e=>u.error(`AI Kit init or indexing failed`,s(e))):c===`smart`?d.ready.then(async()=>{try{if(!d.kb)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`);f=new e(d.kb.indexer,a,d.kb.store),f.start(),d.setSmartScheduler(f),u.info(`Smart index scheduler started (HTTP mode)`)}catch(e){u.error(`Failed to start smart index scheduler`,s(e))}}).catch(e=>u.error(`AI Kit initialization failed`,s(e))):(d.ready.catch(e=>u.error(`AI Kit initialization failed`,s(e))),u.info(`Initial full indexing skipped in HTTP mode`,{indexMode:c}))}catch(e){u.error(`Failed to load server modules`,s(e))}},100)}),_=async e=>{u.info(`Shutdown signal received`,{signal:e}),f?.stop(),g.close(),p&&await p.close(),process.exit(0)};process.on(`SIGINT`,()=>_(`SIGINT`)),process.on(`SIGTERM`,()=>_(`SIGTERM`))}else{let[{loadConfig:e,reconfigureForWorkspace:t,resolveIndexMode:n},{createLazyServer:r},{checkForUpdates:a,autoUpgradeScaffold:o},{RootsListChangedNotificationSchema:c}]=await Promise.all([import(`./config-C5IU9Lau.js`),import(`./server-DOXU8yxT.js`),import(`./version-check-D4j0Pykd.js`),import(`@modelcontextprotocol/sdk/types.js`)]),l=e();u.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path}),a(),o();let d=n(l),f=r(l,d),{server:p,startInit:m,ready:h,runInitialIndex:g}=f,{StdioServerTransport:_}=await import(`@modelcontextprotocol/sdk/server/stdio.js`),v=new _;await p.connect(v),u.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 u.info(`MCP roots resolved`,{rootUri:n,rootPath:r,rootCount:e.length}),t(l,r),!0},b=!1;try{b=y((await p.server.listRoots()).roots),b||u.info(`No MCP roots yet; waiting for roots/list_changed notification`)}catch(e){u.warn(`MCP roots/list not supported by client; using cwd fallback`,{cwd:process.cwd(),...s(e)}),b=!0}b||=await new Promise(e=>{let t=setTimeout(()=>{u.warn(`Timed out waiting for MCP roots/list_changed; using cwd fallback`,{cwd:process.cwd()}),e(!1)},5e3);p.server.setNotificationHandler(c,async()=>{clearTimeout(t);try{e(y((await p.server.listRoots()).roots))}catch(t){u.warn(`roots/list retry failed after notification`,s(t)),e(!1)}})}),m();let x=null,S=()=>{x&&clearTimeout(x),x=setTimeout(()=>{u.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=>{u.error(`Initialization failed — server will continue with limited tools`,s(e))}),d===`auto`?g().catch(e=>u.error(`Initial index failed`,s(e))):d===`smart`?h.then(async()=>{try{if(!f.kb)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(f.kb.indexer,l,f.kb.store);t.start(),f.setSmartScheduler(t),u.info(`Smart index scheduler started (stdio mode)`)}catch(e){u.error(`Failed to start smart index scheduler`,s(e))}}).catch(e=>u.error(`AI Kit init failed for smart scheduler`,s(e))):u.warn(`Initial full indexing skipped; use aikit_reindex to index manually`,{indexMode:d})}}f().catch(e=>{u.error(`Fatal error`,s(e)),process.exit(1)});export{e as CuratedKnowledgeManager};