@vpxa/kb 0.1.22 → 0.1.24
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 +4 -4
- package/packages/chunker/dist/wasm/runtime.js +1 -1
- package/packages/cli/dist/commands/init/user.js +3 -4
- package/packages/server/dist/config.js +1 -1
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/prompts.js +2 -1
- package/packages/server/dist/server.js +3 -1
- package/packages/server/dist/tool-metadata.js +1 -1
- package/packages/server/dist/tools/analyze.tools.js +1 -1
- package/packages/server/dist/tools/bridge.tools.js +1 -1
- package/packages/server/dist/tools/context.tools.js +4 -4
- package/packages/server/dist/tools/execution.tools.js +3 -2
- package/packages/server/dist/tools/forge.tools.js +2 -2
- package/packages/server/dist/tools/forget.tool.js +1 -1
- package/packages/server/dist/tools/infra.tools.js +2 -2
- package/packages/server/dist/tools/list.tool.js +2 -2
- package/packages/server/dist/tools/lookup.tool.js +1 -1
- package/packages/server/dist/tools/manipulation.tools.js +2 -2
- package/packages/server/dist/tools/onboard.tool.js +2 -2
- package/packages/server/dist/tools/persistence.tools.js +4 -4
- package/packages/server/dist/tools/policy.tools.js +3 -2
- package/packages/server/dist/tools/produce.tool.js +1 -1
- package/packages/server/dist/tools/read.tool.js +1 -1
- package/packages/server/dist/tools/reindex.tool.js +1 -1
- package/packages/server/dist/tools/remember.tool.js +1 -1
- package/packages/server/dist/tools/replay.tool.js +1 -1
- package/packages/server/dist/tools/search.tool.js +1 -1
- package/packages/server/dist/tools/toolkit.tools.js +11 -11
- package/packages/server/dist/tools/update.tool.js +1 -1
- package/packages/server/dist/tools/utility.tools.js +8 -8
- package/packages/store/dist/lance-store.d.ts +1 -0
- package/packages/store/dist/lance-store.js +1 -1
- package/packages/tools/dist/audit.js +1 -1
- package/packages/tools/dist/check.js +1 -1
- package/packages/tools/dist/compact.js +2 -2
- package/packages/tools/dist/eval.js +2 -2
- package/packages/tools/dist/file-summary.js +2 -2
- package/packages/tools/dist/queue.js +1 -1
- package/packages/tools/dist/symbol.js +1 -1
- package/packages/tools/dist/test-run.d.ts +3 -1
- package/packages/tools/dist/test-run.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMBEDDING_DEFAULTS as e,SEARCH_DEFAULTS as t,STORE_DEFAULTS as n,createLogger as r,serializeError as i,sourceTypeContentTypes as a}from"../../core/dist/index.js";import{Index as o,connect as s}from"@lancedb/lancedb";function c(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}const l=/^[\w.\-/ ]+$/,u=r(`store`);function d(e,t){if(!l.test(e))throw Error(`Invalid ${t} filter value: contains disallowed characters`);return e.replace(/'/g,`''`)}var f=class{db=null;table=null;dbPath;tableName;_writeQueue=Promise.resolve();enqueueWrite(e){let t=this._writeQueue.then(()=>e());return this._writeQueue=t.then(()=>void 0,()=>void 0),t}constructor(e){this.dbPath=e?.path??n.path,this.tableName=e?.tableName??n.tableName}async initialize(){this.db=await s(this.dbPath),(await this.db.tableNames()).includes(this.tableName)&&(this.table=await this.db.openTable(this.tableName),await this.createFtsIndex())}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async _upsertImpl(e,t){let n=e.map((e,n)=>({id:e.id,vector:Array.from(t[n]),content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath??``,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:JSON.stringify(e.tags),category:e.category??``,version:e.version}));if(this.table){let t=[...new Set(e.map(e=>e.sourcePath))];for(let e of t)try{await this.table.delete(`sourcePath = '${d(e,`sourcePath`)}'`)}catch{}await this.table.add(n)}else try{this.table=await this.db?.createTable(this.tableName,n)??null}catch(e){if(String(e).includes(`already exists`)&&this.db)this.table=await this.db.openTable(this.tableName),await this.table.add(n);else throw e}}async search(e,n){if(!this.table)return[];let r=n?.limit??t.maxResults,i=n?.minScore??t.minScore,a=this.table.search(e).limit(r*2),o=this.buildFilterString(n);return o&&(a=a.where(o)),(await a.toArray()).map(e=>({record:this.fromLanceRecord(e),score:1-(e._distance??1)})).filter(e=>e.score>=i).slice(0,r)}async createFtsIndex(){return this.enqueueWrite(()=>this._createFtsIndexImpl())}async _createFtsIndexImpl(){if(this.table)try{await this.table.createIndex(`content`,{config:o.fts(),replace:!0}),u.info(`FTS index created/updated`,{column:`content`})}catch(e){u.warn(`FTS index creation failed`,i(e))}}async ftsSearch(e,n){if(!this.table)return[];let r=n?.limit??t.maxResults;try{let t=this.table.search(e).limit(r*2),i=this.buildFilterString(n);return i&&(t=t.where(i)),(await t.toArray()).map(e=>({record:this.fromLanceRecord(e),score:e._score??e._relevance_score??0}))}catch(e){return u.warn(`FTS search failed`,i(e)),[]}}async getById(e){if(!this.table)return null;let t=await this.table.query().where(`id = '${d(e,`id`)}'`).limit(1).toArray();return t.length===0?null:this.fromLanceRecord(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){if(!this.table)return 0;let t=await this.getBySourcePath(e);return t.length===0?0:(await this.table.delete(`sourcePath = '${d(e,`sourcePath`)}'`),t.length)}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async _deleteByIdImpl(e){return!this.table||!await this.getById(e)?!1:(await this.table.delete(`id = '${d(e,`id`)}'`),!0)}async getBySourcePath(e){return this.table?(await this.table.query().where(`sourcePath = '${d(e,`sourcePath`)}'`).limit(1e3).toArray()).map(e=>this.fromLanceRecord(e)):[]}async getStats(){if(!this.table)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`lancedb`,embeddingModel:e.model};let t=await this.table.countRows(),n=await this.table.query().select([`sourcePath`,`contentType`,`indexedAt`]).limit(1e5).toArray(),r={},i=new Set,a=null;for(let e of n){let t=e;r[t.contentType]=(r[t.contentType]??0)+1,i.add(t.sourcePath),(!a||t.indexedAt>a)&&(a=t.indexedAt)}return{totalRecords:t,totalFiles:i.size,contentTypeBreakdown:r,lastIndexedAt:a,storeBackend:`lancedb`,embeddingModel:e.model}}async listSourcePaths(){if(!this.table)return[];let e=await this.table.query().select([`sourcePath`]).limit(1e5).toArray();return[...new Set(e.map(e=>e.sourcePath))]}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){if(this.db&&(await this.db.tableNames()).includes(this.tableName))for(let e=1;e<=3;e++)try{await this.db.dropTable(this.tableName);break}catch(t){if(e===3)throw t;let n=e*500;u.warn(`dropTable attempt failed, retrying`,{attempt:e,delayMs:n}),await new Promise(e=>setTimeout(e,n))}this.table=null}async close(){try{this.db&&typeof this.db.close==`function`&&await this.db.close()}catch{}this.table=null,this.db=null}buildFilterString(e){let t=[];if(e?.contentType&&t.push(`contentType = '${d(e.contentType,`contentType`)}'`),e?.sourceType){let n=a(e.sourceType);if(n.length>0){let e=n.map(e=>`'${d(e,`sourceType`)}'`).join(`, `);t.push(`contentType IN (${e})`)}}if(e?.origin&&t.push(`origin = '${d(e.origin,`origin`)}'`),e?.category&&t.push(`category = '${d(e.category,`category`)}'`),e?.tags&&e.tags.length>0){let n=e.tags.map(e=>`tags LIKE '%${d(e,`tag`)}%'`);t.push(`(${n.join(` OR `)})`)}return t.length>0?t.join(` AND `):null}fromLanceRecord(e){return{id:e.id,content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath||void 0,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:c(e.tags),category:e.category||void 0,version:e.version}}};export{f as LanceStore};
|
|
1
|
+
import{EMBEDDING_DEFAULTS as e,SEARCH_DEFAULTS as t,STORE_DEFAULTS as n,createLogger as r,serializeError as i,sourceTypeContentTypes as a}from"../../core/dist/index.js";import{Index as o,connect as s}from"@lancedb/lancedb";function c(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}const l=/^[\w.\-/ ]+$/,u=r(`store`);function d(e,t){if(!l.test(e))throw Error(`Invalid ${t} filter value: contains disallowed characters`);return e.replace(/'/g,`''`)}var f=class{db=null;table=null;dbPath;tableName;_ftsReady=!1;_writeQueue=Promise.resolve();enqueueWrite(e){let t=this._writeQueue.then(()=>e());return this._writeQueue=t.then(()=>void 0,()=>void 0),t}constructor(e){this.dbPath=e?.path??n.path,this.tableName=e?.tableName??n.tableName}async initialize(){this.db=await s(this.dbPath),(await this.db.tableNames()).includes(this.tableName)&&(this.table=await this.db.openTable(this.tableName),await this.createFtsIndex())}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async _upsertImpl(e,t){let n=e.map((e,n)=>({id:e.id,vector:Array.from(t[n]),content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath??``,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:JSON.stringify(e.tags),category:e.category??``,version:e.version}));if(this.table){let t=[...new Set(e.map(e=>e.sourcePath))];for(let e of t)try{await this.table.delete(`sourcePath = '${d(e,`sourcePath`)}'`)}catch{}await this.table.add(n)}else try{this.table=await this.db?.createTable(this.tableName,n)??null}catch(e){if(String(e).includes(`already exists`)&&this.db)this.table=await this.db.openTable(this.tableName),await this.table.add(n);else throw e}}async search(e,n){if(!this.table)return[];let r=n?.limit??t.maxResults,i=n?.minScore??t.minScore,a=this.table.search(e).limit(r*2),o=this.buildFilterString(n);return o&&(a=a.where(o)),(await a.toArray()).map(e=>({record:this.fromLanceRecord(e),score:1-(e._distance??1)})).filter(e=>e.score>=i).slice(0,r)}async createFtsIndex(){return this.enqueueWrite(()=>this._createFtsIndexImpl())}async _createFtsIndexImpl(){if(this.table)try{await this.table.createIndex(`content`,{config:o.fts(),replace:!0}),this._ftsReady=!0,u.info(`FTS index created/updated`,{column:`content`})}catch(e){u.warn(`FTS index creation failed`,i(e))}}async ftsSearch(e,n){if(!this.table||!this._ftsReady)return[];let r=n?.limit??t.maxResults;try{let t=this.table.search(e).limit(r*2),i=this.buildFilterString(n);return i&&(t=t.where(i)),(await t.toArray()).map(e=>({record:this.fromLanceRecord(e),score:e._score??e._relevance_score??0}))}catch(e){return(e instanceof Error?e.message:String(e)).includes(`INVERTED index`)?(u.debug(`FTS search skipped — index not yet available`),this._ftsReady=!1):u.warn(`FTS search failed`,i(e)),[]}}async getById(e){if(!this.table)return null;let t=await this.table.query().where(`id = '${d(e,`id`)}'`).limit(1).toArray();return t.length===0?null:this.fromLanceRecord(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){if(!this.table)return 0;let t=await this.getBySourcePath(e);return t.length===0?0:(await this.table.delete(`sourcePath = '${d(e,`sourcePath`)}'`),t.length)}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async _deleteByIdImpl(e){return!this.table||!await this.getById(e)?!1:(await this.table.delete(`id = '${d(e,`id`)}'`),!0)}async getBySourcePath(e){return this.table?(await this.table.query().where(`sourcePath = '${d(e,`sourcePath`)}'`).limit(1e3).toArray()).map(e=>this.fromLanceRecord(e)):[]}async getStats(){if(!this.table)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`lancedb`,embeddingModel:e.model};let t=await this.table.countRows(),n=await this.table.query().select([`sourcePath`,`contentType`,`indexedAt`]).limit(1e5).toArray(),r={},i=new Set,a=null;for(let e of n){let t=e;r[t.contentType]=(r[t.contentType]??0)+1,i.add(t.sourcePath),(!a||t.indexedAt>a)&&(a=t.indexedAt)}return{totalRecords:t,totalFiles:i.size,contentTypeBreakdown:r,lastIndexedAt:a,storeBackend:`lancedb`,embeddingModel:e.model}}async listSourcePaths(){if(!this.table)return[];let e=await this.table.query().select([`sourcePath`]).limit(1e5).toArray();return[...new Set(e.map(e=>e.sourcePath))]}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){if(this.db&&(await this.db.tableNames()).includes(this.tableName))for(let e=1;e<=3;e++)try{await this.db.dropTable(this.tableName);break}catch(t){if(e===3)throw t;let n=e*500;u.warn(`dropTable attempt failed, retrying`,{attempt:e,delayMs:n}),await new Promise(e=>setTimeout(e,n))}this.table=null}async close(){try{this.db&&typeof this.db.close==`function`&&await this.db.close()}catch{}this.table=null,this.db=null}buildFilterString(e){let t=[];if(e?.contentType&&t.push(`contentType = '${d(e.contentType,`contentType`)}'`),e?.sourceType){let n=a(e.sourceType);if(n.length>0){let e=n.map(e=>`'${d(e,`sourceType`)}'`).join(`, `);t.push(`contentType IN (${e})`)}}if(e?.origin&&t.push(`origin = '${d(e.origin,`origin`)}'`),e?.category&&t.push(`category = '${d(e.category,`category`)}'`),e?.tags&&e.tags.length>0){let n=e.tags.map(e=>`tags LIKE '%${d(e,`tag`)}%'`);t.push(`(${n.join(` OR `)})`)}return t.length>0?t.join(` AND `):null}fromLanceRecord(e){return{id:e.id,content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath||void 0,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:c(e.tags),category:e.category||void 0,version:e.version}}};export{f as LanceStore};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{check as e,summarizeCheckResult as t}from"./check.js";import{findDeadSymbols as n}from"./dead-symbols.js";import{health as r}from"./health.js";import{resolvePath as i}from"./path-resolver.js";import{errorResponse as a,okResponse as o}from"./response-envelope.js";import{DependencyAnalyzer as s,EntryPointAnalyzer as c,PatternAnalyzer as l,StructureAnalyzer as u}from"../../analyzers/dist/index.js";const d=[`structure`,`dependencies`,`patterns`,`health`,`dead_symbols`,`check`,`entry_points`];async function f(f,m,h={}){let g=Date.now(),_=i(h.path),v=h.checks??d,y=h.detail??`summary`,b=[],x={score:100,recommendations:b};try{let i=[];v.includes(`structure`)&&i.push((async()=>{let e=await new u().analyze(_,{format:`json`}),t=e.data;x.structure={files:t.stats?.totalFiles??e.meta.fileCount,packages:Array.isArray(t.packages)?t.packages.length:0,languages:t.stats?.languages??{}}})()),v.includes(`dependencies`)&&i.push((async()=>{let e=(await new s().analyze(_)).data,t=e.imports??[];x.dependencies={external:e.external?.length??t.filter(e=>e.isExternal).length,internal:e.internal?.length??t.filter(e=>!e.isExternal).length}})()),v.includes(`patterns`)&&i.push((async()=>{x.patterns=((await new l().analyze(_)).data.patterns??[]).map(e=>({name:e.pattern,confidence:e.confidence,count:e.locations.length}))})()),v.includes(`entry_points`)&&i.push((async()=>{let e=(await new c().analyze(_)).data,t=e.entryPoints??[],n={};for(let e of t)n[e.type]=(n[e.type]??0)+1;x.entryPoints={total:e.total??t.length,types:n}})()),v.includes(`health`)&&i.push((async()=>{let e=r(_);x.health={score:e.score,checks:e.checks.length,passed:e.checks.filter(e=>e.status===`pass`).length,warned:e.checks.filter(e=>e.status===`warn`).length,failed:e.checks.filter(e=>e.status===`fail`).length},e.score<70&&b.push({priority:`medium`,area:`health`,message:`Health score ${e.score}/100 — ${x.health.failed} failed checks`})})()),v.includes(`dead_symbols`)&&i.push((async()=>{let e=await n(m,f,{rootPath:_});x.deadSymbols={source:e.totalDeadSource,docs:e.totalDeadDocs},e.totalDeadSource>0&&b.push({priority:e.totalDeadSource>10?`high`:`medium`,area:`dead-code`,message:`${e.totalDeadSource} unused exports in source files`})})()),v.includes(`check`)&&i.push((async()=>{let n=t(await e({cwd:_}));x.typecheck={passed:n.tsc.passed,errorCount:n.tsc.errorCount,topErrors:n.tsc.topErrors},x.lint={passed:n.biome.passed,errorCount:n.biome.errorCount,topErrors:n.biome.topErrors},n.tsc.passed||b.push({priority:`high`,area:`type-safety`,message:`Fix ${n.tsc.errorCount} tsc error(s)`}),n.biome.passed||b.push({priority:`medium`,area:`lint`,message:`Fix ${n.biome.errorCount} lint error(s)`})})()),await Promise.all(i);let a=0;x.typecheck&&!x.typecheck.passed&&(a+=15),x.lint&&!x.lint.passed&&(a+=5),x.health&&x.health.score<80&&(a+=10),x.deadSymbols&&x.deadSymbols.source>10&&(a+=5),x.entryPoints&&x.entryPoints.total===0&&(a+=5),x.score=Math.max(0,100-a);let d={high:0,medium:1,low:2};b.sort((e,t)=>d[e.priority]-d[t.priority]);let h=p(x,y),S=[];return x.typecheck&&!x.typecheck.passed&&S.push({tool:`check`,reason:`Get full error details`,suggested_args:{detail:`errors`}}),x.deadSymbols&&x.deadSymbols.source>0&&S.push({tool:`dead_symbols`,reason:`See which exports are unused`,suggested_args:{root_path:_}}),o(`audit`,h,x,{durationMs:Date.now()-g,detail:y},S)}catch{return a(`audit`,{code:`ANALYSIS_FAILED`,category:`runtime`,retryable:!1,message:`Audit failed
|
|
1
|
+
import{check as e,summarizeCheckResult as t}from"./check.js";import{findDeadSymbols as n}from"./dead-symbols.js";import{health as r}from"./health.js";import{resolvePath as i}from"./path-resolver.js";import{errorResponse as a,okResponse as o}from"./response-envelope.js";import{DependencyAnalyzer as s,EntryPointAnalyzer as c,PatternAnalyzer as l,StructureAnalyzer as u}from"../../analyzers/dist/index.js";const d=[`structure`,`dependencies`,`patterns`,`health`,`dead_symbols`,`check`,`entry_points`];async function f(f,m,h={}){let g=Date.now(),_=i(h.path),v=h.checks??d,y=h.detail??`summary`,b=[],x={score:100,recommendations:b};try{let i=[];v.includes(`structure`)&&i.push((async()=>{let e=await new u().analyze(_,{format:`json`}),t=e.data;x.structure={files:t.stats?.totalFiles??e.meta.fileCount,packages:Array.isArray(t.packages)?t.packages.length:0,languages:t.stats?.languages??{}}})()),v.includes(`dependencies`)&&i.push((async()=>{let e=(await new s().analyze(_)).data,t=e.imports??[];x.dependencies={external:e.external?.length??t.filter(e=>e.isExternal).length,internal:e.internal?.length??t.filter(e=>!e.isExternal).length}})()),v.includes(`patterns`)&&i.push((async()=>{x.patterns=((await new l().analyze(_)).data.patterns??[]).map(e=>({name:e.pattern,confidence:e.confidence,count:e.locations.length}))})()),v.includes(`entry_points`)&&i.push((async()=>{let e=(await new c().analyze(_)).data,t=e.entryPoints??[],n={};for(let e of t)n[e.type]=(n[e.type]??0)+1;x.entryPoints={total:e.total??t.length,types:n}})()),v.includes(`health`)&&i.push((async()=>{let e=r(_);x.health={score:e.score,checks:e.checks.length,passed:e.checks.filter(e=>e.status===`pass`).length,warned:e.checks.filter(e=>e.status===`warn`).length,failed:e.checks.filter(e=>e.status===`fail`).length},e.score<70&&b.push({priority:`medium`,area:`health`,message:`Health score ${e.score}/100 — ${x.health.failed} failed checks`})})()),v.includes(`dead_symbols`)&&i.push((async()=>{let e=await n(m,f,{rootPath:_});x.deadSymbols={source:e.totalDeadSource,docs:e.totalDeadDocs},e.totalDeadSource>0&&b.push({priority:e.totalDeadSource>10?`high`:`medium`,area:`dead-code`,message:`${e.totalDeadSource} unused exports in source files`})})()),v.includes(`check`)&&i.push((async()=>{let n=t(await e({cwd:_}));x.typecheck={passed:n.tsc.passed,errorCount:n.tsc.errorCount,topErrors:n.tsc.topErrors},x.lint={passed:n.biome.passed,errorCount:n.biome.errorCount,topErrors:n.biome.topErrors},n.tsc.passed||b.push({priority:`high`,area:`type-safety`,message:`Fix ${n.tsc.errorCount} tsc error(s)`}),n.biome.passed||b.push({priority:`medium`,area:`lint`,message:`Fix ${n.biome.errorCount} lint error(s)`})})()),await Promise.all(i);let a=0;x.typecheck&&!x.typecheck.passed&&(a+=15),x.lint&&!x.lint.passed&&(a+=5),x.health&&x.health.score<80&&(a+=10),x.deadSymbols&&x.deadSymbols.source>10&&(a+=5),x.entryPoints&&x.entryPoints.total===0&&(a+=5),x.score=Math.max(0,100-a);let d={high:0,medium:1,low:2};b.sort((e,t)=>d[e.priority]-d[t.priority]);let h=p(x,y),S=[];return x.typecheck&&!x.typecheck.passed&&S.push({tool:`check`,reason:`Get full error details`,suggested_args:{detail:`errors`}}),x.deadSymbols&&x.deadSymbols.source>0&&S.push({tool:`dead_symbols`,reason:`See which exports are unused`,suggested_args:{root_path:_}}),o(`audit`,h,x,{durationMs:Date.now()-g,detail:y},S)}catch(e){return a(`audit`,{code:`ANALYSIS_FAILED`,category:`runtime`,retryable:!1,message:`Audit failed: ${e instanceof Error?e.message:String(e)}`},Date.now()-g)}}function p(e,t){let n=[];if(n.push(`## Audit Report — Score: ${e.score}/100\n`),e.structure&&n.push(`**Structure:** ${e.structure.files} files, ${e.structure.packages} packages, ${Object.keys(e.structure.languages).length} languages`),e.entryPoints){let t=Object.entries(e.entryPoints.types).map(([e,t])=>`${t} ${e}`).join(`, `);n.push(`**Entry Points:** ${e.entryPoints.total} (${t||`none`})`)}if(e.dependencies&&n.push(`**Dependencies:** ${e.dependencies.external} external, ${e.dependencies.internal} internal`),e.health&&n.push(`**Health:** ${e.health.score}/100 (${e.health.passed}✓ ${e.health.warned}⚠ ${e.health.failed}✗)`),e.deadSymbols&&n.push(`**Dead Symbols:** ${e.deadSymbols.source} in source (actionable), ${e.deadSymbols.docs} in docs`),e.typecheck){let t=e.typecheck.passed?`✓ passed`:`✗ ${e.typecheck.errorCount} errors`;n.push(`**Typecheck:** ${t}`)}if(e.lint){let t=e.lint.passed?`✓ passed`:`✗ ${e.lint.errorCount} errors`;n.push(`**Lint:** ${t}`)}if(e.recommendations.length>0){n.push(`
|
|
2
2
|
### Recommendations
|
|
3
3
|
`);for(let t of e.recommendations){let e=t.priority===`high`?`🔴`:t.priority===`medium`?`🟡`:`🟢`;n.push(`${e} **${t.area}:** ${t.message}`)}}if(t===`full`&&e.patterns&&e.patterns.length>0){n.push(`
|
|
4
4
|
### Patterns Detected
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{parseBiome as e,parseTsc as t}from"./parse-output.js";import{exec as n}from"node:child_process";import{readFile as r}from"node:fs/promises";import{join as i}from"node:path";import{promisify as a}from"node:util";const o=a(n);let s=0;function c(e){let t=e;return[t.stdout?.toString()??``,t.stderr?.toString()??``].filter(Boolean).join(`
|
|
2
|
-
`).trim()||t.message||`Command failed`}async function l(e={}){if(s>=2)throw Error(`Too many concurrent check runs (max 2). Try again later.`);s++;try{return await u(e)}finally{s--}}async function u(n){let a=n.cwd??process.cwd(),s={errors:[],passed:!0,raw:``},l={errors:[],passed:!0,raw:``};if(!n.skipTypes)try{let e=i(a,`package.json`),t=!1;try{t=!!JSON.parse(await r(e,`utf-8`)).scripts?.typecheck}catch{}if(t&&!n.files?.length)await o(`npx turbo run typecheck`,{cwd:a,timeout:12e4});else{let e=[`--noEmit`];n.files?.length&&e.push(...n.files),await o(`npx tsc ${e.join(` `)}`,{cwd:a,timeout:12e4})}}catch(e){s.raw=c(e),s.errors=t(s.raw),s.passed=s.errors.length===0}if(!n.skipLint)try{let e=[`check`];n.files?.length&&e.push(...n.files),await o(`npx biome ${e.join(` `)}`,{cwd:a,timeout:12e4})}catch(t){l.raw=c(t),l.errors=e(l.raw),l.passed=l.errors.length===0}let u=n.detail??`
|
|
2
|
+
`).trim()||t.message||`Command failed`}async function l(e={}){if(s>=2)throw Error(`Too many concurrent check runs (max 2). Try again later.`);s++;try{return await u(e)}finally{s--}}async function u(n){let a=n.cwd??process.cwd(),s={errors:[],passed:!0,raw:``},l={errors:[],passed:!0,raw:``};if(!n.skipTypes)try{let e=i(a,`package.json`),t=!1;try{t=!!JSON.parse(await r(e,`utf-8`)).scripts?.typecheck}catch{}if(t&&!n.files?.length)await o(`npx turbo run typecheck`,{cwd:a,timeout:12e4});else{let e=[`--noEmit`];n.files?.length&&e.push(...n.files),await o(`npx tsc ${e.join(` `)}`,{cwd:a,timeout:12e4})}}catch(e){s.raw=c(e),s.errors=t(s.raw),s.passed=s.errors.length===0}if(!n.skipLint)try{let e=[`check`];n.files?.length&&e.push(...n.files),await o(`npx biome ${e.join(` `)}`,{cwd:a,timeout:12e4})}catch(t){l.raw=c(t),l.errors=e(l.raw),l.passed=l.errors.length===0}let u=n.detail??`errors`,d={tsc:s,biome:l,passed:s.passed&&l.passed};return u===`full`?d:{tsc:{errors:s.errors,passed:s.passed},biome:{errors:l.errors,passed:l.passed},passed:d.passed}}function d(e){let t=e.tsc.errors.filter(e=>e.severity===`error`),n=e.tsc.errors.filter(e=>e.severity===`warning`),r=e.biome.errors.filter(e=>e.severity===`error`),i=e.biome.errors.filter(e=>e.severity===`warning`);return{passed:e.passed,tsc:{passed:e.tsc.passed,errorCount:t.length,warningCount:n.length,topErrors:t.slice(0,3).map(e=>`${e.file}:${e.line} — ${e.message}`)},biome:{passed:e.biome.passed,errorCount:r.length,warningCount:i.length,topErrors:r.slice(0,3).map(e=>`${e.file}:${e.line} — ${e.message}`)}}}export{l as check,d as summarizeCheckResult};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{cosineSimilarity as e,segment as t}from"./text-utils.js";import{readFile as n}from"node:fs/promises";async function
|
|
1
|
+
import{cosineSimilarity as e,segment as t}from"./text-utils.js";import{readFile as n,stat as r}from"node:fs/promises";async function i(i,a){let{query:o,maxChars:s=3e3,minScore:c=.3,segmentation:l=`paragraph`}=a,u;if(a.text)u=a.text;else if(a.path){let e;try{e=await r(a.path)}catch(e){let t=e.code;throw t===`ENOENT`?Error(`File not found: ${a.path}. Check the path and try again.`):t===`EACCES`||t===`EPERM`?Error(`Permission denied reading ${a.path}. The file exists but is not accessible.`):e}if(e.size>1e7)throw Error(`File too large (${(e.size/1e6).toFixed(1)}MB). compact supports files up to 10MB. Consider splitting or using search instead.`);u=a.cache?(await a.cache.get(a.path)).content:await n(a.path,`utf-8`)}else throw Error(`Either "text" or "path" must be provided`);if(u.length<=s)return{text:u,originalChars:u.length,compressedChars:u.length,ratio:1,segmentsKept:1,segmentsTotal:1};let d=t(u,l);if(d.length===0)return{text:``,originalChars:u.length,compressedChars:0,ratio:0,segmentsKept:0,segmentsTotal:0};let f=await i.embed(o),p=[];for(let t=0;t<d.length;t++){let n=e(f,await i.embed(d[t]));p.push({text:d[t],score:n,index:t})}let m=p.filter(e=>e.score>=c).sort((e,t)=>t.score-e.score),h=[],g=0;for(let e of m){if(g+e.text.length>s){g===0&&(h.push({...e,text:e.text.slice(0,s)}),g=s);break}h.push(e),g+=e.text.length+2}h.sort((e,t)=>e.index-t.index);let _=h.map(e=>e.text).join(`
|
|
2
2
|
|
|
3
|
-
`);return{text:
|
|
3
|
+
`);return{text:_,originalChars:u.length,compressedChars:_.length,ratio:_.length/u.length,segmentsKept:h.length,segmentsTotal:d.length}}export{i as compact};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"node:vm";function t(t){let{code:i,lang:a=`js`,timeout:o=5e3}=t,s=Date.now();try{let t=a===`ts`?r(i):i,
|
|
2
|
-
`)+(d===void 0?``:`\n→ ${n(d)}`):d===void 0?`(no output)`:n(d),durationMs:Date.now()-
|
|
1
|
+
import e from"node:vm";function t(t){let{code:i,lang:a=`js`,timeout:o=5e3}=t,s=Math.min(Math.max(o,100),1e4),c=Date.now();try{let t=a===`ts`?r(i):i,o=[],l={console:{log:(...e)=>o.push(e.map(String).join(` `)),error:(...e)=>o.push(`[error] ${e.map(String).join(` `)}`),warn:(...e)=>o.push(`[warn] ${e.map(String).join(` `)}`)},setTimeout:void 0,setInterval:void 0,setImmediate:void 0,fetch:void 0,process:void 0,require:void 0,JSON,Math,Date,Array,Object,String,Number,Boolean,Map,Set,RegExp,Error,Promise,parseInt,parseFloat,isNaN,isFinite},u=e.createContext(l,{codeGeneration:{strings:!1,wasm:!1}}),d=e.runInContext(t,u,{timeout:s});return{success:!0,output:o.length>0?o.join(`
|
|
2
|
+
`)+(d===void 0?``:`\n→ ${n(d)}`):d===void 0?`(no output)`:n(d),durationMs:Date.now()-c}}catch(e){return{success:!1,output:``,error:e.message,durationMs:Date.now()-c}}}function n(e){if(e===void 0)return`undefined`;if(e===null)return`null`;if(typeof e==`object`)try{return JSON.stringify(e,null,2)}catch{return String(e)}return String(e)}function r(e){return e.replace(/^\s*import\s+type\s+.*?;\s*$/gm,``).replace(/^\s*(?:export\s+)?interface\s+\w+[^{]*\{[\s\S]*?^\s*}\s*$/gm,``).replace(/^\s*(?:export\s+)?type\s+\w+\s*=.*?;\s*$/gm,``).replace(/([,(]\s*[A-Za-z_$][\w$]*)\s*:\s*[^,)=\n]+/g,`$1`).replace(/\)\s*:\s*[^={\n]+(?=\s*(?:=>|\{))/g,`)`).replace(/\s+as\s+[A-Za-z_$][\w$<>,[\]|&\s.]*/g,``).replace(/<(?:[A-Za-z_$][\w$]*\s*,?\s*)+>(?=\s*\()/g,``)}export{t as evaluate};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readFile as e}from"node:fs/promises";import{extname as
|
|
2
|
-
`),
|
|
1
|
+
import{readFile as e,stat as t}from"node:fs/promises";import{extname as n}from"node:path";import{SUPPORTED_EXTENSIONS as r,WasmRuntime as i,extractCalls as a,extractImports as o,extractSymbols as s}from"../../chunker/dist/index.js";async function c(a){let{path:o,previewLines:s=3}=a;if(!a.content){let e;try{e=await t(o)}catch(e){let t=e.code;throw t===`ENOENT`?Error(`File not found: ${o}. Check the path and try again.`):t===`EACCES`||t===`EPERM`?Error(`Permission denied reading ${o}. The file exists but is not accessible.`):e}if(e.size>1e7)throw Error(`File too large (${(e.size/1e6).toFixed(1)}MB). file_summary supports files up to 10MB. Use search or compact with a query instead.`)}let c=a.content??await e(o,`utf-8`),d=c.split(`
|
|
2
|
+
`),f=o.split(`.`).pop()??``,p=n(o);return i.get()&&r.has(p)?l(o,c,d,f,p):u(o,c,d,f)}async function l(e,t,n,r,i){let[c,l,u]=await Promise.all([s(t,i,e),o(t,i,e),a(t,i,e).catch(()=>[])]),f=l.map(e=>`import ${e.specifiers.length>0?`{ ${e.specifiers.join(`, `)} }`:`*`} from '${e.source}'`),p=[],m=[],h=[],g=[],_=[];for(let e of c)switch(e.exported&&p.push(e.name),e.kind){case`function`:case`method`:m.push({name:e.name,line:e.line,exported:e.exported,signature:e.signature});break;case`class`:h.push({name:e.name,line:e.line,exported:e.exported,signature:e.signature});break;case`interface`:g.push({name:e.name,line:e.line,exported:e.exported});break;case`type`:_.push({name:e.name,line:e.line,exported:e.exported});break}let v=l.map(e=>({source:e.source,specifiers:e.specifiers,isExternal:e.isExternal})),y=u.map(e=>({caller:e.callerName,callee:e.calleeName,line:e.line}));return{path:e,lines:n.length,language:d(r),imports:f,exports:p,functions:m,classes:h,interfaces:g,types:_,importDetails:v,callEdges:y.length>0?y:void 0,estimatedTokens:Math.ceil(t.length/4)}}function u(e,t,n,r){let i=[],a=[],o=[],s=[],c=[],l=[];for(let e=0;e<n.length;e+=1){let t=n[e],r=e+1;if(/^import\s+.+/.test(t)){i.push(t.trim());continue}let u=t.match(/^export\s+(?:async\s+)?function\s+(\w+)/);if(u){o.push({name:u[1],line:r,exported:!0}),a.push(u[1]);continue}let d=t.match(/^(?:async\s+)?function\s+(\w+)/);if(d){o.push({name:d[1],line:r,exported:!1});continue}let f=t.match(/^(export\s+)?const\s+(\w+)\s*=.*(?:=>|\bfunction\b)/);if(f){let e=!!f[1];o.push({name:f[2],line:r,exported:e}),e&&a.push(f[2]);continue}let p=t.match(/^export\s+const\s+(\w+)\s*=/);if(p){a.push(p[1]);continue}let m=t.match(/^(export\s+)?(?:abstract\s+)?class\s+(\w+)/);if(m){let e=!!m[1];s.push({name:m[2],line:r,exported:e}),e&&a.push(m[2]);continue}let h=t.match(/^(export\s+)?interface\s+(\w+)/);if(h){let e=!!h[1];c.push({name:h[2],line:r,exported:e}),e&&a.push(h[2]);continue}let g=t.match(/^(export\s+)?type\s+(\w+)/);if(g){let e=!!g[1];l.push({name:g[2],line:r,exported:e}),e&&a.push(g[2]);continue}let _=t.match(/^export\s+\{(.+)\}/);if(_){let e=_[1].split(`,`).map(e=>e.trim().split(/\s+as\s+/).pop()?.trim()??``).filter(Boolean);a.push(...e)}}return{path:e,lines:n.length,language:d(r),imports:i,exports:a,functions:o,classes:s,interfaces:c,types:l,estimatedTokens:Math.ceil(t.length/4)}}function d(e){return{ts:`typescript`,tsx:`typescript-jsx`,js:`javascript`,jsx:`javascript-jsx`,py:`python`,rs:`rust`,go:`go`,java:`java`,rb:`ruby`,md:`markdown`,json:`json`,yaml:`yaml`,yml:`yaml`,css:`css`,html:`html`,sh:`shell`,bash:`shell`}[e]??e}export{c as fileSummary};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname as e,resolve as t}from"node:path";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{KB_PATHS as o}from"../../core/dist/index.js";const s=o.state;function c(e){return t(e??process.cwd(),s,`queue.json`)}function l(e){let t=c(e);if(!n(t))return{};try{return JSON.parse(i(t,`utf-8`))}catch{return{}}}function u(t,i){let o=c(i),s=e(o);n(s)||r(s,{recursive:!0}),a(o,`${JSON.stringify(t,null,2)}\n`,`utf-8`)}function d(){return`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`}function f(e,t){let n=l(t);if(n[e])throw Error(`Queue "${e}" already exists`);let r={name:e,items:[]};return n[e]=r,u(n,t),r}function p(e,t,n,r){let i=l(r);i[e]||(i[e]={name:e,items:[]});let a=new Date().toISOString(),o={id:d(),title:t,status:`pending`,data:n,createdAt:a,updatedAt:a};return i[e].items.push(o),u(i,r),o}function m(e,t){let n=l(t),r=n[e];if(!r)throw Error(`Queue "${e}" does not exist`);let i=r.items.find(e=>e.status===`pending`);return i?(i.status=`in-progress`,i.updatedAt=new Date().toISOString(),u(n,t),i):null}function h(e,t,n){let r=l(n),i=r[e];if(!i)throw Error(`Queue "${e}" does not exist`);let a=i.items.find(e=>e.id===t);if(!a)throw Error(`Item "${t}" not found in queue "${e}"`);return a.status=`done`,a.updatedAt=new Date().toISOString(),u(r,n),a}function g(e,t,n,r){let i=l(r),a=i[e];if(!a)throw Error(`Queue "${e}" does not exist`);let o=a.items.find(e=>e.id===t);if(!o)throw Error(`Item "${t}" not found in queue "${e}"`);return o.status=`failed`,o.error=n,o.updatedAt=new Date().toISOString(),u(i,r),o}function _(e,t){return l(t)[e]??null}function v(e){let t=l(e);return Object.values(t).map(e=>({name:e.name,pending:e.items.filter(e=>e.status===`pending`).length,done:e.items.filter(e=>e.status===`done`).length,failed:e.items.filter(e=>e.status===`failed`).length,total:e.items.length}))}function y(e,t){let n=l(t),r=n[e];if(!r)throw Error(`Queue "${e}" does not exist`);let i=r.items.length;r.items=r.items.filter(e=>e.status===`pending`||e.status===`in-progress`);let a=i-r.items.length;return u(n,t),a}function b(e,t){let n=l(t);return n[e]?(delete n[e],u(n,t),!0):!1}export{y as queueClear,f as queueCreate,b as queueDelete,h as queueDone,g as queueFail,_ as queueGet,v as queueList,m as queueNext,p as queuePush};
|
|
1
|
+
import{dirname as e,resolve as t}from"node:path";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{KB_PATHS as o}from"../../core/dist/index.js";const s=o.state;function c(e){return t(e??process.cwd(),s,`queue.json`)}function l(e){let t=c(e);if(!n(t))return{};try{return JSON.parse(i(t,`utf-8`))}catch{return{}}}function u(t,i){let o=c(i),s=e(o);n(s)||r(s,{recursive:!0}),a(o,`${JSON.stringify(t,null,2)}\n`,`utf-8`)}function d(){return`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`}function f(e,t){let n=l(t);if(n[e])throw Error(`Queue "${e}" already exists`);let r={name:e,items:[]};return n[e]=r,u(n,t),r}function p(e,t,n,r){let i=l(r);i[e]||(i[e]={name:e,items:[]});let a=new Date().toISOString(),o={id:d(),title:t,status:`pending`,data:n,createdAt:a,updatedAt:a};if(i[e].items.length>=500)throw Error(`Queue "${e}" has reached the maximum of 500 items. Clear completed items with queue({ action: "clear" }) before adding more.`);return i[e].items.push(o),u(i,r),o}function m(e,t){let n=l(t),r=n[e];if(!r)throw Error(`Queue "${e}" does not exist`);let i=r.items.find(e=>e.status===`pending`);return i?(i.status=`in-progress`,i.updatedAt=new Date().toISOString(),u(n,t),i):null}function h(e,t,n){let r=l(n),i=r[e];if(!i)throw Error(`Queue "${e}" does not exist`);let a=i.items.find(e=>e.id===t);if(!a)throw Error(`Item "${t}" not found in queue "${e}"`);return a.status=`done`,a.updatedAt=new Date().toISOString(),u(r,n),a}function g(e,t,n,r){let i=l(r),a=i[e];if(!a)throw Error(`Queue "${e}" does not exist`);let o=a.items.find(e=>e.id===t);if(!o)throw Error(`Item "${t}" not found in queue "${e}"`);return o.status=`failed`,o.error=n,o.updatedAt=new Date().toISOString(),u(i,r),o}function _(e,t){return l(t)[e]??null}function v(e){let t=l(e);return Object.values(t).map(e=>({name:e.name,pending:e.items.filter(e=>e.status===`pending`).length,done:e.items.filter(e=>e.status===`done`).length,failed:e.items.filter(e=>e.status===`failed`).length,total:e.items.length}))}function y(e,t){let n=l(t),r=n[e];if(!r)throw Error(`Queue "${e}" does not exist`);let i=r.items.length;r.items=r.items.filter(e=>e.status===`pending`||e.status===`in-progress`);let a=i-r.items.length;return u(n,t),a}function b(e,t){let n=l(t);return n[e]?(delete n[e],u(n,t),!0):!1}export{y as queueClear,f as queueCreate,b as queueDelete,h as queueDone,g as queueFail,_ as queueGet,v as queueList,m as queueNext,p as queuePush};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import{extname as e}from"node:path";import{SUPPORTED_EXTENSIONS as t,WasmRuntime as n,extractSymbols as r,resolveScopes as i}from"../../chunker/dist/index.js";function a(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}async function o(o,s,c){let{name:l,limit:u=20,graphStore:d}=c,f=o.embedQuery?.bind(o)??o.embed.bind(o),p=[`export function ${l}`,`export class ${l}`,`export const ${l}`,`export interface ${l}`,`export type ${l}`,`export enum ${l}`].join(` | `),m=await s.search(await f(p),{limit:u*2}),h=RegExp(`^export\\s+(?:default\\s+)?(?:async\\s+)?(?:function|class|const|let|interface|type|enum)\\s+${a(l)}\\b`,`m`),g;for(let i of m){if(!h.test(i.record.content))continue;let a=i.record.content.match(/export\s+(?:default\s+)?(?:async\s+)?(\w+)/)?.[1]??`unknown`;g={path:i.record.sourcePath,line:i.record.startLine,kind:a};let o=e(i.record.sourcePath);if(n.get()&&t.has(o))try{let e=(await r(i.record.content,o,i.record.sourcePath)).find(e=>e.name===l&&e.exported);e&&(g.kind=e.kind,e.signature&&(g.signature=e.signature))}catch{}break}let _=RegExp(`import\\s+.*\\b${a(l)}\\b.*from\\s+`,`m`),v=await s.search(await f(`import ${l} from`),{limit:u*3}),y=[],b=new Set;for(let e of v){let t=e.record.content.split(`
|
|
2
|
-
`);for(let n=0;n<t.length;n++){let r=t[n];if(!_.test(r))continue;let i=`${e.record.sourcePath}:${r.trim()}`;b.has(i)||(b.add(i),y.push({path:e.record.sourcePath,line:e.record.startLine+n,importStatement:r.trim()}))}}let x=RegExp(`\\b${a(l)}\\b`),S=await s.search(await f(l),{limit:u*3}),C=[],w=new Set;for(let r of S){if(g&&r.record.sourcePath===g.path)continue;let a=r.record.content.split(`
|
|
2
|
+
`);for(let n=0;n<t.length;n++){let r=t[n];if(!_.test(r))continue;let i=`${e.record.sourcePath}:${r.trim()}`;b.has(i)||(b.add(i),y.push({path:e.record.sourcePath,line:e.record.startLine+n,importStatement:r.trim()}))}}let x=RegExp(`\\b${a(l)}\\b`),S=await s.search(await f(l),{limit:u*3}),C=[],w=new Set;for(let r of S){if(C.length>=u)break;if(g&&r.record.sourcePath===g.path)continue;let a=r.record.content.split(`
|
|
3
3
|
`);for(let o=0;o<a.length;o++){let s=a[o];if(!x.test(s)||_.test(s))continue;let c=`${r.record.sourcePath}:${r.record.startLine+o}`;if(w.has(c))continue;w.add(c);let l,u=e(r.record.sourcePath);if(n.get()&&t.has(u))try{let e=await i(r.record.content,u,o+1);e.length>0&&(l=e[0].name)}catch{}C.push({path:r.record.sourcePath,line:r.record.startLine+o,context:s.trim().slice(0,120),scope:l});break}}let T;if(d)try{let e={importedByModules:[],siblingSymbols:[]},t=await d.findNodes({namePattern:l});if(t.length>0){let n=t[0];n.sourcePath?e.definingModule=n.sourcePath:g&&(e.definingModule=g.path);let r=await d.getNeighbors(n.id,{direction:`incoming`,edgeType:`imports`});for(let t of r.nodes)e.importedByModules.push(t.sourcePath??t.name);if(e.definingModule){let t=await d.findNodes({sourcePath:e.definingModule});for(let n of t)n.name!==l&&n.type!==`module`&&e.siblingSymbols.push(`${n.type}:${n.name}`);e.siblingSymbols=e.siblingSymbols.slice(0,15)}}(e.definingModule||e.importedByModules.length>0||e.siblingSymbols.length>0)&&(T=e)}catch{}return{name:l,definedIn:g,importedBy:y.slice(0,u),referencedIn:C.slice(0,u),graphContext:T}}export{o as symbol};
|
|
@@ -6,11 +6,13 @@ interface TestRunOptions {
|
|
|
6
6
|
cwd?: string;
|
|
7
7
|
timeout?: number;
|
|
8
8
|
grep?: string;
|
|
9
|
+
/** Include full raw output in result (default: false to save tokens) */
|
|
10
|
+
includeRaw?: boolean;
|
|
9
11
|
}
|
|
10
12
|
interface TestRunResult {
|
|
11
13
|
summary: ParsedTestSummary;
|
|
12
14
|
passed: boolean;
|
|
13
|
-
raw
|
|
15
|
+
raw?: string;
|
|
14
16
|
durationMs: number;
|
|
15
17
|
}
|
|
16
18
|
declare function testRun(options?: TestRunOptions): Promise<TestRunResult>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{parseVitest as e}from"./parse-output.js";import{exec as t}from"node:child_process";import{promisify as n}from"node:util";const r=n(t);let i=0;async function a(e={}){if(i>=2)throw Error(`Too many concurrent test runs (max 2). Try again later.`);i++;try{return await o(e)}finally{i--}}async function o(t){let n=t.cwd??process.cwd(),i=t.timeout??6e4,a=Date.now(),o=[`vitest`,`run`,`--reporter=verbose`,`--no-color`];t.files?.length&&o.push(...t.files),t.grep&&o.push(`--testNamePattern`,t.grep);try{let{stdout:
|
|
1
|
+
import{parseVitest as e}from"./parse-output.js";import{exec as t}from"node:child_process";import{promisify as n}from"node:util";const r=n(t);let i=0;async function a(e={}){if(i>=2)throw Error(`Too many concurrent test runs (max 2). Try again later.`);i++;try{return await o(e)}finally{i--}}async function o(t){let n=t.cwd??process.cwd(),i=t.timeout??6e4,a=Date.now(),o=[`vitest`,`run`,`--reporter=verbose`,`--no-color`];t.files?.length&&o.push(...t.files),t.grep&&o.push(`--testNamePattern`,t.grep);try{let{stdout:s}=await r(`npx ${o.join(` `)}`,{cwd:n,timeout:i}),c=s.toString(),l=e(c);return{summary:l,passed:l.failed===0,...t.includeRaw&&{raw:c},durationMs:Date.now()-a}}catch(n){let r=s(n);return{summary:e(r),passed:!1,...t.includeRaw&&{raw:r},durationMs:Date.now()-a}}}function s(e){let t=e;return[t.stdout?.toString()??``,t.stderr?.toString()??``].filter(Boolean).join(`
|
|
2
2
|
`).trim()||t.message||`Test run failed`}function c(e,t,n){if(e===0)return{isError:!1};if(e===1&&n){if(/\b(grep|rg|ripgrep|ag|ack|findstr)\b/i.test(n))return{isError:!1,reason:`grep: no matches (exit 1 is normal)`};if(/\bdiff\b/i.test(n))return{isError:!1,reason:`diff: files differ (exit 1 is normal)`}}return{isError:!0}}export{c as classifyExitCode,a as testRun};
|