@vpxa/aikit 0.1.110 → 0.1.111
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 +1 -1
- package/packages/cli/dist/index.js +9 -9
- package/packages/cli/dist/init-BfmAvMGq.js +7 -0
- package/packages/core/dist/index.d.ts +4 -2
- package/packages/core/dist/index.js +1 -1
- package/packages/embeddings/dist/index.d.ts +8 -0
- package/packages/embeddings/dist/index.js +1 -1
- package/packages/indexer/dist/index.d.ts +8 -0
- package/packages/indexer/dist/index.js +1 -1
- package/packages/server/dist/config-BL-I_FFY.js +1 -0
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/{server-DGVHkoLk.js → server-BnPh8aSm.js} +2 -2
- package/packages/store/dist/index.d.ts +9 -0
- package/packages/store/dist/index.js +2 -2
- package/packages/store/dist/{sqlite-vec-store-CfcO7e_I.js → sqlite-vec-store-Bnn0_imk.js} +27 -25
- package/packages/cli/dist/init-X00JY_h4.js +0 -7
- package/packages/server/dist/config-CnpI4Eu3.js +0 -1
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{i as e,t}from"./constants-Nz_Z7XS-.js";import{copyFileSync as n,existsSync as r,mkdirSync as i,readFileSync as a}from"node:fs";import{basename as o,dirname as s,join as c,resolve as l}from"node:path";import{fileURLToPath as u}from"node:url";import{addToWorkset as d,audit as f,check as p,checkpointLatest as m,checkpointList as h,checkpointLoad as ee,checkpointSave as te,codemod as ne,compact as re,dataTransform as ie,delegate as ae,delegateListModels as oe,deleteWorkset as se,diffParse as ce,evaluate as le,fileSummary as ue,find as de,findDeadSymbols as fe,findExamples as pe,getWorkset as me,gitContext as he,graphQuery as ge,guide as _e,health as ve,laneCreate as ye,laneDiff as be,laneDiscard as xe,laneList as Se,laneMerge as Ce,laneStatus as
|
|
2
|
-
`);let o=await t({path:a,mode:r,outDir:i});for(let e of o.steps){let t=e.status===`success`?`✓`:`✗`,n=e.status===`success`?`${e.durationMs}ms, ${e.output.length} chars`:e.error;console.log(` ${t} ${e.name} — ${n}`)}console.log(`\nTotal: ${o.totalDurationMs}ms`),o.outDir&&console.log(`Output written to: ${o.outDir}`)}}];function P(e,t,n){let r=e.indexOf(t);if(r===-1||r+1>=e.length)return n;let i=Number.parseInt(e.splice(r,2)[1],10);return Number.isNaN(i)?n:i}function F(e,t,n){let r=e.indexOf(t);return r===-1||r+1>=e.length?n:e.splice(r,2)[1]}function I(e,t){let n=e.indexOf(t);return n===-1?!1:(e.splice(n,1),!0)}async function L(){if(process.stdin.isTTY)return``;let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf-8`)}function R(e){return e.split(`,`).map(e=>e.trim()).filter(Boolean)}function
|
|
3
|
-
`))console.log(` ${e}`)}}function B(e){console.log(e.id),console.log(` Command: ${e.command}${e.args.length>0?` ${e.args.join(` `)}`:``}`),console.log(` PID: ${e.pid??`unknown`}`),console.log(` Status: ${e.status}`),console.log(` Started: ${e.startedAt}`),e.exitCode!==void 0&&console.log(` Exit code: ${e.exitCode}`),console.log(` Logs: ${e.logs.length}`)}function
|
|
1
|
+
import{i as e,t}from"./constants-Nz_Z7XS-.js";import{copyFileSync as n,existsSync as r,mkdirSync as i,readFileSync as a}from"node:fs";import{basename as o,dirname as s,join as c,resolve as l}from"node:path";import{fileURLToPath as u}from"node:url";import{addToWorkset as d,audit as f,check as p,checkpointLatest as m,checkpointList as h,checkpointLoad as ee,checkpointSave as te,codemod as ne,compact as re,dataTransform as ie,delegate as ae,delegateListModels as oe,deleteWorkset as se,diffParse as ce,evaluate as le,fileSummary as ue,find as de,findDeadSymbols as fe,findExamples as pe,getWorkset as me,gitContext as he,graphQuery as ge,guide as _e,health as ve,laneCreate as ye,laneDiff as be,laneDiscard as xe,laneList as Se,laneMerge as Ce,laneStatus as we,listWorksets as Te,parseOutput as g,processList as _,processLogs as v,processStart as y,processStatus as b,processStop as x,queueClear as S,queueCreate as C,queueDelete as w,queueDone as T,queueFail as E,queueGet as D,queueList as O,queueNext as Ee,queuePush as De,removeFromWorkset as Oe,rename as ke,replayClear as Ae,replayList as je,replayTrim as Me,saveWorkset as Ne,scopeMap as Pe,stashClear as Fe,stashDelete as Ie,stashGet as Le,stashList as Re,stashSet as ze,symbol as Be,testRun as Ve,trace as He,watchList as Ue,watchStart as We,watchStop as Ge}from"../../tools/dist/index.js";import{readFile as k}from"node:fs/promises";import{AIKIT_PATHS as A,EMBEDDING_DEFAULTS as j,getGlobalDataDir as Ke,getPartitionDir as M,isUserInstalled as qe,registerWorkspace as Je}from"../../core/dist/index.js";import{initializeWasm as Ye}from"../../chunker/dist/index.js";import{OnnxEmbedder as Xe}from"../../embeddings/dist/index.js";import{IncrementalIndexer as Ze}from"../../indexer/dist/index.js";import{SqliteGraphStore as N,createSqliteAdapter as Qe,createStore as $e}from"../../store/dist/index.js";import{fork as et}from"node:child_process";const tt=[{name:`analyze`,description:`Run analyzer output for a path`,usage:`aikit analyze <type> <path>`,run:async e=>{let t=e.shift()?.trim()??``,n=e.shift()?.trim()??``;(!t||!n)&&(console.error(`Usage: aikit analyze <type> <path>`),console.error(`Types: structure, deps, symbols, patterns, entry-points, blast-radius, diagram`),process.exit(1));let{BlastRadiusAnalyzer:r,DependencyAnalyzer:i,DiagramGenerator:a,EntryPointAnalyzer:o,PatternAnalyzer:s,StructureAnalyzer:c,SymbolAnalyzer:u}=await import(`../../analyzers/dist/index.js`),d=l(n),f;switch(t){case`structure`:f=await new c().analyze(d,{format:`markdown`});break;case`deps`:case`dependencies`:f=await new i().analyze(d,{format:`markdown`});break;case`symbols`:f=await new u().analyze(d,{format:`markdown`});break;case`patterns`:f=await new s().analyze(d,{format:`markdown`});break;case`entry-points`:f=await new o().analyze(d,{format:`markdown`});break;case`blast-radius`:f=await new r().analyze(process.cwd(),{files:[n],format:`markdown`});break;case`diagram`:f=await new a().analyze(d,{diagramType:`architecture`});break;default:console.error(`Unknown analyze type: ${t}`),console.error(`Types: structure, deps, symbols, patterns, entry-points, blast-radius, diagram`),process.exit(1)}console.log(f.output)}},{name:`onboard`,description:`Run all analyses for first-time codebase onboarding`,usage:`aikit onboard <path> [--generate] [--out-dir <dir>]`,run:async e=>{let{onboard:t}=await import(`../../tools/dist/index.js`),n=``,r=`memory`,i;for(let t=0;t<e.length;t++){let a=e[t].trim();a===`--generate`?r=`generate`:a===`--out-dir`&&t+1<e.length?i=e[++t].trim():a.startsWith(`--`)||(n=a)}n||=process.cwd();let a=l(n);console.log(`Onboarding: ${a} (mode: ${r})`),console.log(`Running analyses...
|
|
2
|
+
`);let o=await t({path:a,mode:r,outDir:i});for(let e of o.steps){let t=e.status===`success`?`✓`:`✗`,n=e.status===`success`?`${e.durationMs}ms, ${e.output.length} chars`:e.error;console.log(` ${t} ${e.name} — ${n}`)}console.log(`\nTotal: ${o.totalDurationMs}ms`),o.outDir&&console.log(`Output written to: ${o.outDir}`)}}];function P(e,t,n){let r=e.indexOf(t);if(r===-1||r+1>=e.length)return n;let i=Number.parseInt(e.splice(r,2)[1],10);return Number.isNaN(i)?n:i}function F(e,t,n){let r=e.indexOf(t);return r===-1||r+1>=e.length?n:e.splice(r,2)[1]}function I(e,t){let n=e.indexOf(t);return n===-1?!1:(e.splice(n,1),!0)}async function L(){if(process.stdin.isTTY)return``;let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf-8`)}function R(e){return e.split(`,`).map(e=>e.trim()).filter(Boolean)}function nt(e){return e.map(e=>{let t=e.heading?` ${e.heading}`:``;return`${e.start}-${e.end}${t}`}).join(`, `)}function rt(e){switch(e.tool){case`tsc`:case`biome`:console.log(`${e.tool} errors: ${e.errors.length}`);for(let t of e.errors){let e=[t.line,t.column].filter(e=>e!==void 0).join(`:`),n=e?`${t.file}:${e}`:t.file,r=t.code?` ${t.code}`:``;console.log(`- ${n} [${t.severity}${r}] ${t.message}`)}return;case`vitest`:console.log(`Vitest summary`),console.log(` Passed: ${e.summary.passed}`),console.log(` Failed: ${e.summary.failed}`),console.log(` Skipped: ${e.summary.skipped}`),e.summary.duration!==void 0&&console.log(` Duration: ${e.summary.duration}ms`);for(let t of e.summary.tests)t.status===`fail`&&(console.log(`- ${t.name}${t.file?` (${t.file})`:``}`),t.error&&console.log(` ${t.error}`));return;case`git-status`:console.log(`Branch: ${e.status.branch??`unknown`}`),console.log(`Staged: ${e.status.staged.length}`);for(let t of e.status.staged)console.log(` ${t.status} ${t.file}`);console.log(`Unstaged: ${e.status.unstaged.length}`);for(let t of e.status.unstaged)console.log(` ${t.status} ${t.file}`);console.log(`Untracked: ${e.status.untracked.length}`);for(let t of e.status.untracked)console.log(` ?? ${t}`);return}}function it(e){console.log(`Overall: ${e.passed?`passed`:`failed`}`),z(`tsc`,e.tsc.passed,e.tsc.errors),z(`biome`,e.biome.passed,e.biome.errors)}function z(e,t,n){console.log(`${e}: ${t?`passed`:`${n.length} issue(s)`}`);for(let e of n){let t=[e.line,e.column].filter(e=>e!==void 0).join(`:`),n=t?`${e.file}:${t}`:e.file,r=e.code?` ${e.code}`:``;console.log(` - ${n} [${e.severity}${r}] ${e.message}`)}}function at(e){console.log(`Vitest: ${e.passed?`passed`:`failed`}`),console.log(` Duration: ${e.durationMs}ms`),console.log(` Passed: ${e.summary.passed}`),console.log(` Failed: ${e.summary.failed}`),console.log(` Skipped: ${e.summary.skipped}`),e.summary.suites!==void 0&&console.log(` Suites: ${e.summary.suites}`);let t=e.summary.tests.filter(e=>e.status===`fail`);if(t.length!==0){console.log(`Failed tests:`);for(let e of t)console.log(` - ${e.name}${e.file?` (${e.file})`:``}`),e.error&&console.log(` ${e.error}`)}}function ot(e){console.log(`Branch: ${e.branch}`),console.log(`Staged: ${e.status.staged.length}`);for(let t of e.status.staged)console.log(` - ${t}`);console.log(`Modified: ${e.status.modified.length}`);for(let t of e.status.modified)console.log(` - ${t}`);console.log(`Untracked: ${e.status.untracked.length}`);for(let t of e.status.untracked)console.log(` - ${t}`);if(console.log(``),console.log(`Recent commits:`),e.recentCommits.length===0)console.log(` none`);else for(let t of e.recentCommits)console.log(` - ${t.hash} ${t.message}`),console.log(` ${t.author} @ ${t.date}`);e.diff&&(console.log(``),console.log(`Diff stat:`),console.log(e.diff))}function st(e){if(e.length===0){console.log(`No diff files found.`);return}for(let t of e){let e=t.oldPath?` (from ${t.oldPath})`:``;console.log(`${t.path}${e}`),console.log(` Status: ${t.status}`),console.log(` Changes: +${t.additions} -${t.deletions}`),console.log(` Hunks: ${t.hunks.length}`);for(let e of t.hunks){let t=e.header?` ${e.header}`:``;console.log(` @@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@${t}`)}}}function ct(e){if(console.log(`Start: ${e.start}`),console.log(`Direction: ${e.direction}`),console.log(`Depth reached: ${e.depth}`),console.log(`Nodes: ${e.nodes.length}`),e.nodes.length===0){console.log(`No trace nodes found.`);return}for(let t of e.nodes)console.log(` - [${t.relationship}] ${t.path}:${t.line} ${t.symbol}`)}function lt(e){if(console.log(`Query: ${e.query}`),console.log(`Examples: ${e.examples.length} shown (${e.totalFound} total)`),e.examples.length===0){console.log(`No matching examples found.`);return}for(let t of e.examples){console.log(``),console.log(`${t.path}:${t.startLine}-${t.endLine}`),console.log(` Context: ${t.context}`),console.log(` Relevance: ${(t.relevance*100).toFixed(1)}%`);for(let e of t.content.split(`
|
|
3
|
+
`))console.log(` ${e}`)}}function B(e){console.log(e.id),console.log(` Command: ${e.command}${e.args.length>0?` ${e.args.join(` `)}`:``}`),console.log(` PID: ${e.pid??`unknown`}`),console.log(` Status: ${e.status}`),console.log(` Started: ${e.startedAt}`),e.exitCode!==void 0&&console.log(` Exit code: ${e.exitCode}`),console.log(` Logs: ${e.logs.length}`)}function ut(e){if(console.log(`Exports scanned: ${e.totalExports}`),console.log(`Dead in source: ${e.totalDeadSource} (actionable)`),console.log(`Dead in docs: ${e.totalDeadDocs} (informational)`),e.totalDeadSource===0&&e.totalDeadDocs===0){console.log(`No dead symbols found.`);return}if(e.deadInSource.length>0){console.log(`
|
|
4
4
|
Dead in source (actionable):`);for(let t of e.deadInSource)console.log(` - ${t.path}:${t.line} ${t.kind} ${t.name}`)}if(e.deadInDocs.length>0){console.log(`
|
|
5
|
-
Dead in docs (informational):`);for(let t of e.deadInDocs)console.log(` - ${t.path}:${t.line} ${t.kind} ${t.name}`)}}function
|
|
6
|
-
`))console.log(` ${t}`)}function U(e,t){if(console.log(`${e}:`),t.length===0){console.log(` none`),console.log(``);return}for(let e of t)console.log(` - ${e}`);console.log(``)}function dt(e){let t=e.trim();if(!t)return``;try{return JSON.parse(t)}catch{return e}}function ft(e){let t=e.trim();if(!t)return{};let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Checkpoint data must be a JSON object.`);return n}function pt(e,t,n=60){let r=new Map;for(let t=0;t<e.length;t++){let i=e[t];r.set(i.record.id,{record:i.record,score:1/(n+t+1)})}for(let e=0;e<t.length;e++){let i=t[e],a=r.get(i.record.id);a?a.score+=1/(n+e+1):r.set(i.record.id,{record:i.record,score:1/(n+e+1)})}return[...r.values()].sort((e,t)=>t.score-e.score)}const mt=[{name:`parse-output`,description:`Parse build or tool output from stdin`,usage:`aikit parse-output [--tool tsc|vitest|biome|git-status]`,run:async e=>{let t=F(e,`--tool`,``).trim()||void 0,n=await L();n.trim()||(console.error(`Usage: aikit parse-output [--tool tsc|vitest|biome|git-status]`),process.exit(1)),tt(v(n,t))}},{name:`git`,description:`Show git branch, status, recent commits, and optional diff stats`,usage:`aikit git [--cwd path] [--commit-count N] [--diff]`,run:async e=>{it(await he({cwd:F(e,`--cwd`,``).trim()||void 0,commitCount:P(e,`--commit-count`,5),includeDiff:I(e,`--diff`)}))}},{name:`diff`,description:`Parse unified diff text from stdin into structured file changes`,usage:`git diff | aikit diff`,run:async()=>{let e=await L();e.trim()||(console.error(`Usage: git diff | aikit diff`),process.exit(1)),at(ce({diff:e}))}},{name:`summarize`,description:`Show a structural summary of a file`,usage:`aikit summarize <path>`,run:async e=>{let t=e.shift()?.trim();t||(console.error(`Usage: aikit summarize <path>`),process.exit(1)),lt(await ue({path:l(t)}))}},{name:`checkpoint`,description:`Save and restore lightweight session checkpoints`,usage:`aikit checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]`,run:async e=>{let t=e.shift()?.trim();switch(t||(console.error(`Usage: aikit checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]`),process.exit(1)),t){case`save`:{let t=e.shift()?.trim(),n=F(e,`--data`,``),r=F(e,`--notes`,``).trim()||void 0,i=n.trim()?``:await L();t||(console.error(`Usage: aikit checkpoint save <label> [--data json] [--notes text]`),process.exit(1)),H(te(t,ft(n||i),{notes:r}));return}case`load`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit checkpoint load <id>`),process.exit(1));let n=ee(t);if(!n){console.log(`No checkpoint found: ${t}`);return}H(n);return}case`list`:{let e=h();if(e.length===0){console.log(`No checkpoints saved.`);return}console.log(`Checkpoints (${e.length})`),console.log(`─`.repeat(60));for(let t of e)console.log(`${t.id}`),console.log(` Label: ${t.label}`),console.log(` Created: ${t.createdAt}`);return}case`latest`:{let e=m();if(!e){console.log(`No checkpoints saved.`);return}H(e);return}default:console.error(`Unknown checkpoint action: ${t}`),console.error(`Actions: save, load, list, latest`),process.exit(1)}}}],ht=[{name:`proc`,description:`Manage in-memory child processes`,usage:`aikit proc <start|stop|status|list|logs> ...`,run:async e=>{let t=e.shift()?.trim()??``;switch(t){case`start`:{let t=e.shift()?.trim(),n=e.shift()?.trim();(!t||!n)&&(console.error(`Usage: aikit proc start <id> <command> [args...]`),process.exit(1)),B(x(t,n,e));return}case`stop`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit proc stop <id>`),process.exit(1));let n=C(t);if(!n){console.log(`No managed process found: ${t}`);return}B(n);return}case`status`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit proc status <id>`),process.exit(1));let n=S(t);if(!n){console.log(`No managed process found: ${t}`);return}B(n);return}case`list`:{let e=y();if(e.length===0){console.log(`No managed processes.`);return}for(let t of e)B(t),console.log(``);return}case`logs`:{let t=P(e,`--tail`,50),n=e.shift()?.trim();n||(console.error(`Usage: aikit proc logs <id> [--tail N]`),process.exit(1));let r=b(n,t);if(r.length===0){console.log(`No logs found for process: ${n}`);return}for(let e of r)console.log(e);return}default:console.error(`Unknown proc action: ${t}`),console.error(`Actions: start, stop, status, list, logs`),process.exit(1)}}},{name:`watch`,description:`Manage in-memory filesystem watchers`,usage:`aikit watch <start|stop|list> ...`,run:async e=>{let t=e.shift()?.trim()??``;switch(t){case`start`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit watch start <path>`),process.exit(1));let n=He({path:l(t)});console.log(`Started watcher: ${n.id}`),console.log(` Path: ${n.path}`),console.log(` Status: ${n.status}`);return}case`stop`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit watch stop <id>`),process.exit(1));let n=Ue(t);console.log(n?`Stopped watcher: ${t}`:`Watcher not found: ${t}`);return}case`list`:{let e=Ve();if(e.length===0){console.log(`No active watchers.`);return}for(let t of e)console.log(`${t.id}`),console.log(` Path: ${t.path}`),console.log(` Status: ${t.status}`),console.log(` Events: ${t.eventCount}`);return}default:console.error(`Unknown watch action: ${t}`),console.error(`Actions: start, stop, list`),process.exit(1)}}},{name:`delegate`,description:`Delegate a task to a local Ollama model`,usage:`aikit delegate [--model name] [--system prompt] [--temp 0.3] <prompt | --stdin>`,run:async e=>{if((e[0]===`models`?e.shift():void 0)===`models`){try{let e=await oe();if(e.length===0){console.log(`No Ollama models available. Pull one with: ollama pull gemma4:e2b`);return}for(let t of e)console.log(t)}catch{console.error(`Ollama is not running. Start it with: ollama serve`),process.exit(1)}return}let t=F(e,`--model`,``),n=F(e,`--system`,``),r=P(e,`--temp`,.3),i=F(e,`--context`,``),a=e.join(` `);a||=await L(),a||(console.error(`Usage: aikit delegate [--model name] <prompt>`),process.exit(1));let o;i&&(o=await j(l(i),`utf-8`));let s=await ae({prompt:a,model:t||void 0,system:n||void 0,context:o,temperature:r});s.error&&(console.error(`Error: ${s.error}`),process.exit(1)),console.log(s.response),console.error(`\n(${s.model}, ${s.durationMs}ms, ${s.tokenCount??`?`} tokens)`)}}],gt=[{name:`eval`,description:`Evaluate JavaScript or TypeScript in a constrained VM sandbox`,usage:`aikit eval [code] [--lang js|ts] [--timeout ms]`,run:async e=>{let t=F(e,`--lang`,`js`),n=P(e,`--timeout`,5e3),r=e.join(` `),i=r.trim()?``:await L(),a=r||i;a.trim()||(console.error(`Usage: aikit eval [code] [--lang js|ts] [--timeout ms]`),process.exit(1));let o=le({code:a,lang:t===`ts`?`ts`:`js`,timeout:n});if(!o.success){console.error(`Eval failed in ${o.durationMs}ms: ${o.error}`),process.exitCode=1;return}console.log(`Eval succeeded in ${o.durationMs}ms`),console.log(`─`.repeat(60)),console.log(o.output)}},{name:`test`,description:`Run Vitest for all tests or a specific subset`,usage:`aikit test [files...] [--grep pattern] [--cwd path] [--timeout ms]`,run:async e=>{let t=F(e,`--grep`,``).trim()||void 0,n=F(e,`--cwd`,``).trim()||void 0,r=P(e,`--timeout`,6e4),i=e.filter(Boolean),a=await ze({files:i.length>0?i:void 0,grep:t,cwd:n,timeout:r});rt(a),a.passed||(process.exitCode=1)}},{name:`rename`,description:`Rename a symbol across files using whole-word regex matching`,usage:`aikit rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`,run:async e=>{let t=e.shift()?.trim()??``,n=e.shift()?.trim()??``,r=e.shift()?.trim()??``;(!t||!n||!r)&&(console.error(`Usage: aikit rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`),process.exit(1));let i=R(F(e,`--extensions`,``)),a=R(F(e,`--exclude`,``)),o=await De({oldName:t,newName:n,rootPath:l(r),extensions:i.length>0?i:void 0,exclude:a.length>0?a:void 0,dryRun:I(e,`--dry-run`)});console.log(JSON.stringify(o,null,2))}},{name:`codemod`,description:`Apply regex-based codemod rules from a JSON file across a path`,usage:`aikit codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`,run:async e=>{let t=e.shift()?.trim()??``,n=F(e,`--rules`,``).trim();(!t||!n)&&(console.error(`Usage: aikit codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`),process.exit(1));let r=await j(l(n),`utf-8`),i;try{i=JSON.parse(r)}catch{throw Error(`Failed to parse rules file as JSON: ${n}`)}if(!Array.isArray(i))throw Error(`Codemod rules file must contain a JSON array.`);let a=R(F(e,`--extensions`,``)),o=R(F(e,`--exclude`,``)),s=await ne({rootPath:l(t),rules:i,extensions:a.length>0?a:void 0,exclude:o.length>0?o:void 0,dryRun:I(e,`--dry-run`)});console.log(JSON.stringify(s,null,2))}},{name:`transform`,description:`Apply jq-like transforms to JSON from stdin`,usage:`cat data.json | aikit transform <expression>`,run:async e=>{let t=e.join(` `).trim(),n=await L();(!t||!n.trim())&&(console.error(`Usage: cat data.json | aikit transform <expression>`),process.exit(1));let r=ie({input:n,expression:t});console.log(r.outputString)}}];function W(){let e=process.env.AIKIT_CONFIG_PATH??(r(l(process.cwd(),`aikit.config.json`))?l(process.cwd(),`aikit.config.json`):null);if(!e)return _t();let t=a(e,`utf-8`),n;try{n=JSON.parse(t)}catch{console.error(`Failed to parse ${e} as JSON. Ensure the file contains valid JSON.`),process.exit(1)}let i=s(e);return n.sources=n.sources.map(e=>({...e,path:l(i,e.path)})),n.store.path=l(i,n.store.path),n.curated=n.curated??{path:`curated`},n.curated.path=l(i,n.curated.path),G(n,i),n}function _t(){let e=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),t={sources:[{path:e,excludePatterns:[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:`mixedbread-ai/mxbai-embed-large-v1`,dimensions:1024},store:{backend:`sqlite-vec`,path:l(e,M.data)},curated:{path:l(e,M.aiCurated)},stateDir:l(e,M.state)};return G(t,e),t}function G(e,t){if(!Ge())return;let n=Ke(t);e.store.path=l(N(n.partition)),e.stateDir=l(N(n.partition),`state`),e.curated||={path:l(t,M.aiCurated)}}async function vt(){let e=W(),t=new Je({model:e.embedding.model,dimensions:e.embedding.dimensions});await t.initialize();let n=await Ze({backend:e.store.backend,path:e.store.path,embeddingDim:e.embedding.dimensions});await n.initialize();let r=new Ye(t,n),{CuratedKnowledgeManager:i}=await import(`../../server/dist/index.js`),a=new i(e.curated.path,n,t),o;try{let t=new Xe({path:e.store.path});await t.initialize(),o=t,r.setGraphStore(o)}catch(e){console.error(`[aikit] Graph store init failed (non-fatal): ${e.message}`),o={initialize:async()=>{},upsertNode:async()=>{},upsertEdge:async()=>{},upsertNodes:async()=>{},upsertEdges:async()=>{},getNode:async()=>null,getNeighbors:async()=>({nodes:[],edges:[]}),traverse:async()=>({nodes:[],edges:[]}),findNodes:async()=>[],findEdges:async()=>[],deleteNode:async()=>{},deleteBySourcePath:async()=>0,clear:async()=>{},getStats:async()=>({nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}}),validate:async()=>({valid:!0,orphanNodes:[],danglingEdges:[],stats:{nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}}}),setNodeCommunity:async()=>{},detectCommunities:async()=>({}),traceProcess:async()=>({id:``,entryNodeId:``,label:``,properties:{},steps:[]}),getProcesses:async()=>[],deleteProcess:async()=>{},depthGroupedTraversal:async()=>({}),getCohesionScore:async()=>0,getSymbol360:async()=>({node:{id:``,type:``,name:``,properties:{}},incoming:[],outgoing:[],community:null,processes:[]}),close:async()=>{}}}return await qe().catch(()=>{}),{config:e,embedder:t,store:n,graphStore:o,indexer:r,curated:a}}async function yt(){let e=await import(`../../flows/dist/index.js`),{FlowLoader:t,FlowRegistryManager:n,FlowStateMachine:r,GitInstaller:a}=e,o=typeof e.getBuiltinFlows==`function`?e.getBuiltinFlows:void 0,s=W(),l=c(s.stateDir??c(s.sources[0].path,`.aikit-state`),`flows`,`installed`),u=c(We(),`flows`);i(u,{recursive:!0});let d=c(u,`registry.json`),f=s.sources[0].path,p=c(f,`.flows`);return{loader:new t,registry:new n(d),stateMachine:new r(p,{before:[],after:[{id:`_docs-sync`,description:`Synchronize project documentation — update docs/ folder based on changes made during the flow.`,position:`after`,skills:[`docs`]}]}),git:new a(l),getBuiltinFlows:o,cwd:f}}const K=[e=>c(`skills`,e,`SKILL.md`),e=>c(`skills`,e,`README.md`),e=>c(e,`SKILL.md`),e=>c(e,`README.md`)];function bt(e,t){for(let a of t.steps){let t=c(e,a.instruction);if(r(t))continue;let o=!1;for(let l of K){let u=c(e,l(a.id));if(r(u)){let e=s(t);r(e)||i(e,{recursive:!0}),n(u,t),o=!0;break}}o||console.warn(`Warning: instruction file for step "${a.id}" not found.\n Expected: ${a.instruction}\n Searched: ${K.map(e=>e(a.id)).join(`, `)}`)}}const xt=[{name:`flow`,description:`Manage pluggable development flows`,usage:`flow <add|remove|list|info|use|update|status|start|reset> [args]`,run:async e=>{let t=e[0];if(!t){console.log(`Usage: aikit flow <add|remove|list|info|use|update|status|start|reset|runs>`),console.log(``),console.log(`Commands:`),console.log(` add <source> Install a flow from git URL or local path`),console.log(` remove <name> Remove an installed flow`),console.log(` list List all installed flows`),console.log(` info <name> Show details of a flow`),console.log(` use <name> Set active flow (start it)`),console.log(` update <name> Update a flow from its source`),console.log(` status Show current flow execution status`),console.log(` start [name] Start a flow (or resume)`),console.log(` reset Reset the active flow`),console.log(` runs List all flow runs`);return}let n=await yt();switch(t){case`add`:{let t=e[1];if(!t){console.error(`Usage: aikit flow add <source>`),console.error(` source: git URL (https://...) or local path`);return}let i=t.startsWith(`http`)||t.startsWith(`git@`)||t.endsWith(`.git`),a=l(t),s=r(a);if(!i&&!s){console.error(`Source not found: ${t}`),console.error(`Provide a git URL or existing local path.`);return}let c,u;if(i){console.log(`Cloning ${t}...`);let e=n.git.clone(t);if(!e.success||!e.data){console.error(e.error??`Failed to clone flow`);return}c=e.data,u=`git`}else{let r=e[2]||o(a);console.log(`Copying local flow from ${t}...`);let i=n.git.copyLocal(a,r);if(!i.success||!i.data){console.error(i.error??`Failed to copy local flow`);return}c=i.data,u=`local`}let d=await n.loader.load(c);if(!d.success||!d.data){console.error(d.error??`Failed to load flow`),n.git.remove(c);return}let{manifest:f,format:p}=d.data;if(bt(c,f),f.install.length>0){console.log(`Installing ${f.install.length} dependencies...`);let e=n.git.runInstallDeps(f.install);if(!e.success){console.error(`Dependency install failed: ${e.error}`),n.git.remove(c);return}}let m=new Date().toISOString(),h=n.registry.register({name:f.name,version:f.version,source:t,sourceType:u,installPath:c,format:p,registeredAt:m,updatedAt:m,manifest:f});if(!h.success){console.error(h.error??`Failed to register flow`),n.git.remove(c);return}console.log(`✓ Flow "${f.name}" v${f.version} installed (${p} format)`),console.log(` Steps: ${f.steps.map(e=>e.id).join(` → `)}`);break}case`remove`:{let t=e[1];if(!t){console.error(`Usage: aikit flow remove <name>`);return}let r=n.registry.get(t);if(!r){console.error(`Flow "${t}" not found`);return}let i=n.git.remove(r.installPath);if(!i.success){console.error(i.error??`Failed to remove flow files`);return}let a=n.registry.unregister(t);if(!a.success){console.error(a.error??`Failed to unregister flow`);return}console.log(`✓ Flow "${t}" removed`);break}case`list`:{let e=n.registry.list();if(e.length===0){console.log("No flows installed. Use `aikit flow add <source>` to install one.");return}console.log(`Installed Flows:`),console.log(`─`.repeat(60));for(let t of e){let e=t.manifest.steps.map(e=>e.id).join(` → `);console.log(` ${t.name} v${t.version} (${t.sourceType}, ${t.format})`),console.log(` Steps: ${e}`)}let t=n.stateMachine.getStatus();t.success&&t.data&&(console.log(``),console.log(`Active: ${t.data.flow} (${t.data.status}, step: ${t.data.currentStep??`done`})`));break}case`info`:{let t=e[1];if(!t){console.error(`Usage: aikit flow info <name>`);return}let r=n.registry.get(t);if(!r){console.error(`Flow "${t}" not found`);return}console.log(`Flow: ${r.name}`),console.log(`Version: ${r.version}`),console.log(`Source: ${r.source} (${r.sourceType})`),console.log(`Format: ${r.format}`),console.log(`Path: ${r.installPath}`),console.log(`Registered: ${r.registeredAt}`),console.log(`Updated: ${r.updatedAt}`),console.log(``),console.log(`Steps:`);for(let e of r.manifest.steps){let t=e.requires.length?` (requires: ${e.requires.join(`, `)})`:``;console.log(` ${e.id}: ${e.name}${t}`),console.log(` Skill: ${e.skill}`),console.log(` Produces: ${e.produces.join(`, `)}`)}if(r.manifest.install.length>0){console.log(``),console.log(`Dependencies:`);for(let e of r.manifest.install)console.log(` ${e}`)}break}case`use`:case`start`:{let r=e[1],i=r?n.registry.get(r):null;if(t===`use`&&!r){console.error(`Usage: aikit flow use <name>`);return}if(t===`start`&&!r){let e=n.stateMachine.getStatus();if(e.success&&e.data&&e.data.status===`active`){console.log(`Resuming flow: ${e.data.flow}`),console.log(`Current step: ${e.data.currentStep}`),console.log(`Completed: ${e.data.completedSteps.join(`, `)||`none`}`);return}console.error("No active flow. Use `aikit flow start <name>` to begin one.");return}if(!i){console.error(`Flow "${r}" not found. Use \`aikit flow list\` to see installed flows.`);return}let a=e[2],o=n.stateMachine.start(i.name,i.manifest,a);if(!o.success||!o.data){console.error(o.error??`Failed to start flow`);return}let s=o.data;console.log(`✓ Flow "${i.name}" started`),console.log(` Topic: ${s.topic}`),console.log(` Run directory: ${s.runDir}`),console.log(` Current step: ${s.currentStep}`),console.log(` Steps: ${i.manifest.steps.map(e=>e.id).join(` → `)}`);break}case`update`:{let t=e[1];if(!t){console.error(`Usage: aikit flow update <name>`);return}let r=n.registry.get(t);if(!r){console.error(`Flow "${t}" not found`);return}if(r.sourceType!==`git`){console.error(`Flow "${t}" is ${r.sourceType}, not updatable via git`);return}console.log(`Updating ${t}...`);let i=n.git.update(r.installPath);if(!i.success){console.error(i.error??`Failed to update flow`);return}let a=await n.loader.load(r.installPath);if(a.success&&a.data){let e=new Date().toISOString(),t=n.registry.register({...r,version:a.data.manifest.version,format:a.data.format,manifest:a.data.manifest,updatedAt:e});if(!t.success){console.error(t.error??`Failed to refresh flow registry entry`);return}}console.log(`✓ Flow "${t}" updated`);break}case`status`:{let e=n.stateMachine.getStatus();if(!e.success||!e.data){console.log(`No active flow.`);return}let t=e.data;if(console.log(`Flow: ${t.flow}`),console.log(`Topic: ${t.topic}`),console.log(`Slug: ${t.slug}`),console.log(`Run Dir: ${t.runDir}`),console.log(`Status: ${t.status}`),console.log(`Current Step: ${t.currentStep??`(completed)`}`),console.log(`Completed: ${t.completedSteps.join(`, `)||`none`}`),t.skippedSteps.length>0&&console.log(`Skipped: ${t.skippedSteps.join(`, `)}`),console.log(`Started: ${t.startedAt}`),console.log(`Updated: ${t.updatedAt}`),Object.keys(t.artifacts).length>0){console.log(`Artifacts:`);for(let[e,n]of Object.entries(t.artifacts))console.log(` ${e}: ${n}`)}break}case`reset`:{let e=n.stateMachine.reset();if(!e.success){console.error(e.error??`Failed to reset flow state`);return}console.log(`✓ Flow abandoned`);break}case`runs`:{let t=e[1],r=e[2],i=n.stateMachine.listRuns({flow:t,status:r});if(i.length===0){console.log(`No flow runs found.`);return}console.log(`Flow Runs:`),console.log(`─`.repeat(80));for(let e of i){let t=e.currentStep?` → ${e.currentStep}`:``;console.log(` ${e.id} [${e.status}] ${e.flow}${t}`),console.log(` Topic: ${e.topic}`),console.log(` Started: ${e.startedAt} | Updated: ${e.updatedAt}`)}break}default:console.error(`Unknown flow command: ${t}`),console.log("Use `aikit flow` for help.")}}}];let q=null;async function J(){return q||=await vt(),q}function St(){return q}const Ct=[{name:`graph`,description:`Query the knowledge graph`,usage:`aikit graph <action> [options]
|
|
5
|
+
Dead in docs (informational):`);for(let t of e.deadInDocs)console.log(` - ${t.path}:${t.line} ${t.kind} ${t.name}`)}}function dt(e){console.log(e.path),console.log(` Language: ${e.language}`),console.log(` Lines: ${e.lines}`),console.log(` Estimated tokens: ~${e.estimatedTokens}`),console.log(``),U(`Imports`,e.imports),U(`Exports`,e.exports),U(`Functions`,e.functions.map(e=>`${e.name} @ line ${e.line}${e.exported?` [exported]`:``}`)),U(`Classes`,e.classes.map(e=>`${e.name} @ line ${e.line}${e.exported?` [exported]`:``}`)),U(`Interfaces`,e.interfaces.map(e=>`${e.name} @ line ${e.line}`)),U(`Types`,e.types.map(e=>`${e.name} @ line ${e.line}`))}function ft(e){if(console.log(`Symbol: ${e.name}`),e.definedIn?console.log(`Defined in: ${e.definedIn.path}:${e.definedIn.line} (${e.definedIn.kind})`):console.log(`Defined in: not found`),console.log(``),console.log(`Imported by:`),e.importedBy.length===0)console.log(` none`);else for(let t of e.importedBy)console.log(` - ${t.path}:${t.line} ${t.importStatement}`);if(console.log(``),console.log(`Referenced in:`),e.referencedIn.length===0)console.log(` none`);else for(let t of e.referencedIn)console.log(` - ${t.path}:${t.line} ${t.context}`)}function V(e){console.log(e.name),console.log(` Files: ${e.files.length}`),console.log(` Updated: ${e.updated}`),e.description&&console.log(` Description: ${e.description}`);for(let t of e.files)console.log(` - ${t}`)}function H(e){if(console.log(e.id),console.log(` Label: ${e.label}`),console.log(` Created: ${e.createdAt}`),e.notes&&console.log(` Notes: ${e.notes}`),e.files?.length){console.log(` Files: ${e.files.length}`);for(let t of e.files)console.log(` - ${t}`)}console.log(` Data:`);for(let t of JSON.stringify(e.data,null,2).split(`
|
|
6
|
+
`))console.log(` ${t}`)}function U(e,t){if(console.log(`${e}:`),t.length===0){console.log(` none`),console.log(``);return}for(let e of t)console.log(` - ${e}`);console.log(``)}function pt(e){let t=e.trim();if(!t)return``;try{return JSON.parse(t)}catch{return e}}function mt(e){let t=e.trim();if(!t)return{};let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Checkpoint data must be a JSON object.`);return n}function ht(e,t,n=60){let r=new Map;for(let t=0;t<e.length;t++){let i=e[t];r.set(i.record.id,{record:i.record,score:1/(n+t+1)})}for(let e=0;e<t.length;e++){let i=t[e],a=r.get(i.record.id);a?a.score+=1/(n+e+1):r.set(i.record.id,{record:i.record,score:1/(n+e+1)})}return[...r.values()].sort((e,t)=>t.score-e.score)}const gt=[{name:`parse-output`,description:`Parse build or tool output from stdin`,usage:`aikit parse-output [--tool tsc|vitest|biome|git-status]`,run:async e=>{let t=F(e,`--tool`,``).trim()||void 0,n=await L();n.trim()||(console.error(`Usage: aikit parse-output [--tool tsc|vitest|biome|git-status]`),process.exit(1)),rt(g(n,t))}},{name:`git`,description:`Show git branch, status, recent commits, and optional diff stats`,usage:`aikit git [--cwd path] [--commit-count N] [--diff]`,run:async e=>{ot(await he({cwd:F(e,`--cwd`,``).trim()||void 0,commitCount:P(e,`--commit-count`,5),includeDiff:I(e,`--diff`)}))}},{name:`diff`,description:`Parse unified diff text from stdin into structured file changes`,usage:`git diff | aikit diff`,run:async()=>{let e=await L();e.trim()||(console.error(`Usage: git diff | aikit diff`),process.exit(1)),st(ce({diff:e}))}},{name:`summarize`,description:`Show a structural summary of a file`,usage:`aikit summarize <path>`,run:async e=>{let t=e.shift()?.trim();t||(console.error(`Usage: aikit summarize <path>`),process.exit(1)),dt(await ue({path:l(t)}))}},{name:`checkpoint`,description:`Save and restore lightweight session checkpoints`,usage:`aikit checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]`,run:async e=>{let t=e.shift()?.trim();switch(t||(console.error(`Usage: aikit checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]`),process.exit(1)),t){case`save`:{let t=e.shift()?.trim(),n=F(e,`--data`,``),r=F(e,`--notes`,``).trim()||void 0,i=n.trim()?``:await L();t||(console.error(`Usage: aikit checkpoint save <label> [--data json] [--notes text]`),process.exit(1)),H(te(t,mt(n||i),{notes:r}));return}case`load`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit checkpoint load <id>`),process.exit(1));let n=ee(t);if(!n){console.log(`No checkpoint found: ${t}`);return}H(n);return}case`list`:{let e=h();if(e.length===0){console.log(`No checkpoints saved.`);return}console.log(`Checkpoints (${e.length})`),console.log(`─`.repeat(60));for(let t of e)console.log(`${t.id}`),console.log(` Label: ${t.label}`),console.log(` Created: ${t.createdAt}`);return}case`latest`:{let e=m();if(!e){console.log(`No checkpoints saved.`);return}H(e);return}default:console.error(`Unknown checkpoint action: ${t}`),console.error(`Actions: save, load, list, latest`),process.exit(1)}}}],_t=[{name:`proc`,description:`Manage in-memory child processes`,usage:`aikit proc <start|stop|status|list|logs> ...`,run:async e=>{let t=e.shift()?.trim()??``;switch(t){case`start`:{let t=e.shift()?.trim(),n=e.shift()?.trim();(!t||!n)&&(console.error(`Usage: aikit proc start <id> <command> [args...]`),process.exit(1)),B(y(t,n,e));return}case`stop`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit proc stop <id>`),process.exit(1));let n=x(t);if(!n){console.log(`No managed process found: ${t}`);return}B(n);return}case`status`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit proc status <id>`),process.exit(1));let n=b(t);if(!n){console.log(`No managed process found: ${t}`);return}B(n);return}case`list`:{let e=_();if(e.length===0){console.log(`No managed processes.`);return}for(let t of e)B(t),console.log(``);return}case`logs`:{let t=P(e,`--tail`,50),n=e.shift()?.trim();n||(console.error(`Usage: aikit proc logs <id> [--tail N]`),process.exit(1));let r=v(n,t);if(r.length===0){console.log(`No logs found for process: ${n}`);return}for(let e of r)console.log(e);return}default:console.error(`Unknown proc action: ${t}`),console.error(`Actions: start, stop, status, list, logs`),process.exit(1)}}},{name:`watch`,description:`Manage in-memory filesystem watchers`,usage:`aikit watch <start|stop|list> ...`,run:async e=>{let t=e.shift()?.trim()??``;switch(t){case`start`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit watch start <path>`),process.exit(1));let n=We({path:l(t)});console.log(`Started watcher: ${n.id}`),console.log(` Path: ${n.path}`),console.log(` Status: ${n.status}`);return}case`stop`:{let t=e.shift()?.trim();t||(console.error(`Usage: aikit watch stop <id>`),process.exit(1));let n=Ge(t);console.log(n?`Stopped watcher: ${t}`:`Watcher not found: ${t}`);return}case`list`:{let e=Ue();if(e.length===0){console.log(`No active watchers.`);return}for(let t of e)console.log(`${t.id}`),console.log(` Path: ${t.path}`),console.log(` Status: ${t.status}`),console.log(` Events: ${t.eventCount}`);return}default:console.error(`Unknown watch action: ${t}`),console.error(`Actions: start, stop, list`),process.exit(1)}}},{name:`delegate`,description:`Delegate a task to a local Ollama model`,usage:`aikit delegate [--model name] [--system prompt] [--temp 0.3] <prompt | --stdin>`,run:async e=>{if((e[0]===`models`?e.shift():void 0)===`models`){try{let e=await oe();if(e.length===0){console.log(`No Ollama models available. Pull one with: ollama pull gemma4:e2b`);return}for(let t of e)console.log(t)}catch{console.error(`Ollama is not running. Start it with: ollama serve`),process.exit(1)}return}let t=F(e,`--model`,``),n=F(e,`--system`,``),r=P(e,`--temp`,.3),i=F(e,`--context`,``),a=e.join(` `);a||=await L(),a||(console.error(`Usage: aikit delegate [--model name] <prompt>`),process.exit(1));let o;i&&(o=await k(l(i),`utf-8`));let s=await ae({prompt:a,model:t||void 0,system:n||void 0,context:o,temperature:r});s.error&&(console.error(`Error: ${s.error}`),process.exit(1)),console.log(s.response),console.error(`\n(${s.model}, ${s.durationMs}ms, ${s.tokenCount??`?`} tokens)`)}}],vt=[{name:`eval`,description:`Evaluate JavaScript or TypeScript in a constrained VM sandbox`,usage:`aikit eval [code] [--lang js|ts] [--timeout ms]`,run:async e=>{let t=F(e,`--lang`,`js`),n=P(e,`--timeout`,5e3),r=e.join(` `),i=r.trim()?``:await L(),a=r||i;a.trim()||(console.error(`Usage: aikit eval [code] [--lang js|ts] [--timeout ms]`),process.exit(1));let o=le({code:a,lang:t===`ts`?`ts`:`js`,timeout:n});if(!o.success){console.error(`Eval failed in ${o.durationMs}ms: ${o.error}`),process.exitCode=1;return}console.log(`Eval succeeded in ${o.durationMs}ms`),console.log(`─`.repeat(60)),console.log(o.output)}},{name:`test`,description:`Run Vitest for all tests or a specific subset`,usage:`aikit test [files...] [--grep pattern] [--cwd path] [--timeout ms]`,run:async e=>{let t=F(e,`--grep`,``).trim()||void 0,n=F(e,`--cwd`,``).trim()||void 0,r=P(e,`--timeout`,6e4),i=e.filter(Boolean),a=await Ve({files:i.length>0?i:void 0,grep:t,cwd:n,timeout:r});at(a),a.passed||(process.exitCode=1)}},{name:`rename`,description:`Rename a symbol across files using whole-word regex matching`,usage:`aikit rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`,run:async e=>{let t=e.shift()?.trim()??``,n=e.shift()?.trim()??``,r=e.shift()?.trim()??``;(!t||!n||!r)&&(console.error(`Usage: aikit rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`),process.exit(1));let i=R(F(e,`--extensions`,``)),a=R(F(e,`--exclude`,``)),o=await ke({oldName:t,newName:n,rootPath:l(r),extensions:i.length>0?i:void 0,exclude:a.length>0?a:void 0,dryRun:I(e,`--dry-run`)});console.log(JSON.stringify(o,null,2))}},{name:`codemod`,description:`Apply regex-based codemod rules from a JSON file across a path`,usage:`aikit codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`,run:async e=>{let t=e.shift()?.trim()??``,n=F(e,`--rules`,``).trim();(!t||!n)&&(console.error(`Usage: aikit codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]`),process.exit(1));let r=await k(l(n),`utf-8`),i;try{i=JSON.parse(r)}catch{throw Error(`Failed to parse rules file as JSON: ${n}`)}if(!Array.isArray(i))throw Error(`Codemod rules file must contain a JSON array.`);let a=R(F(e,`--extensions`,``)),o=R(F(e,`--exclude`,``)),s=await ne({rootPath:l(t),rules:i,extensions:a.length>0?a:void 0,exclude:o.length>0?o:void 0,dryRun:I(e,`--dry-run`)});console.log(JSON.stringify(s,null,2))}},{name:`transform`,description:`Apply jq-like transforms to JSON from stdin`,usage:`cat data.json | aikit transform <expression>`,run:async e=>{let t=e.join(` `).trim(),n=await L();(!t||!n.trim())&&(console.error(`Usage: cat data.json | aikit transform <expression>`),process.exit(1));let r=ie({input:n,expression:t});console.log(r.outputString)}}];function W(){let e=process.env.AIKIT_CONFIG_PATH??(r(l(process.cwd(),`aikit.config.json`))?l(process.cwd(),`aikit.config.json`):null);if(!e)return yt();let t=a(e,`utf-8`),n;try{n=JSON.parse(t)}catch{console.error(`Failed to parse ${e} as JSON. Ensure the file contains valid JSON.`),process.exit(1)}let i=s(e);return n.sources=n.sources.map(e=>({...e,path:l(i,e.path)})),n.store.path=l(i,n.store.path),n.curated=n.curated??{path:`curated`},n.curated.path=l(i,n.curated.path),G(n,i),n}function yt(){let e=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),t={sources:[{path:e,excludePatterns:[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:j.model,dimensions:j.dimensions},store:{backend:`sqlite-vec`,path:l(e,A.data)},curated:{path:l(e,A.aiCurated)},stateDir:l(e,A.state)};return G(t,e),t}function G(e,t){if(!qe())return;let n=Je(t);e.store.path=l(M(n.partition)),e.stateDir=l(M(n.partition),`state`),e.curated||={path:l(t,A.aiCurated)}}async function bt(){let e=W(),t=new Xe({model:e.embedding.model,dimensions:e.embedding.dimensions});await t.initialize();let n=null;if(e.store.backend===`sqlite-vec`){let t=l(e.store.path,`aikit.db`),i=s(t);if(!r(i)){let{mkdirSync:e}=await import(`node:fs`);e(i,{recursive:!0})}n=await Qe(t)}let i=await $e({backend:e.store.backend,path:e.store.path,embeddingDim:e.embedding.dimensions,adapter:n??void 0});await i.initialize();let a=new Ze(t,i),{CuratedKnowledgeManager:o}=await import(`../../server/dist/index.js`),c=new o(e.curated.path,i,t),u;try{let t=n?new N({adapter:n}):new N({path:e.store.path});await t.initialize(),u=t,a.setGraphStore(u)}catch(e){console.error(`[aikit] Graph store init failed (non-fatal): ${e.message}`),u={initialize:async()=>{},upsertNode:async()=>{},upsertEdge:async()=>{},upsertNodes:async()=>{},upsertEdges:async()=>{},getNode:async()=>null,getNeighbors:async()=>({nodes:[],edges:[]}),traverse:async()=>({nodes:[],edges:[]}),findNodes:async()=>[],findEdges:async()=>[],deleteNode:async()=>{},deleteBySourcePath:async()=>0,clear:async()=>{},getStats:async()=>({nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}}),validate:async()=>({valid:!0,orphanNodes:[],danglingEdges:[],stats:{nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}}}),setNodeCommunity:async()=>{},detectCommunities:async()=>({}),traceProcess:async()=>({id:``,entryNodeId:``,label:``,properties:{},steps:[]}),getProcesses:async()=>[],deleteProcess:async()=>{},depthGroupedTraversal:async()=>({}),getCohesionScore:async()=>0,getSymbol360:async()=>({node:{id:``,type:``,name:``,properties:{}},incoming:[],outgoing:[],community:null,processes:[]}),close:async()=>{}}}return await Ye().catch(()=>{}),{config:e,embedder:t,store:i,graphStore:u,indexer:a,curated:c,sqliteAdapter:n}}async function xt(){let e=await import(`../../flows/dist/index.js`),{FlowLoader:t,FlowRegistryManager:n,FlowStateMachine:r,GitInstaller:a}=e,o=typeof e.getBuiltinFlows==`function`?e.getBuiltinFlows:void 0,s=W(),l=c(s.stateDir??c(s.sources[0].path,`.aikit-state`),`flows`,`installed`),u=c(Ke(),`flows`);i(u,{recursive:!0});let d=c(u,`registry.json`),f=s.sources[0].path,p=c(f,`.flows`);return{loader:new t,registry:new n(d),stateMachine:new r(p,{before:[],after:[{id:`_docs-sync`,description:`Synchronize project documentation — update docs/ folder based on changes made during the flow.`,position:`after`,skills:[`docs`]}]}),git:new a(l),getBuiltinFlows:o,cwd:f}}const K=[e=>c(`skills`,e,`SKILL.md`),e=>c(`skills`,e,`README.md`),e=>c(e,`SKILL.md`),e=>c(e,`README.md`)];function St(e,t){for(let a of t.steps){let t=c(e,a.instruction);if(r(t))continue;let o=!1;for(let l of K){let u=c(e,l(a.id));if(r(u)){let e=s(t);r(e)||i(e,{recursive:!0}),n(u,t),o=!0;break}}o||console.warn(`Warning: instruction file for step "${a.id}" not found.\n Expected: ${a.instruction}\n Searched: ${K.map(e=>e(a.id)).join(`, `)}`)}}const Ct=[{name:`flow`,description:`Manage pluggable development flows`,usage:`flow <add|remove|list|info|use|update|status|start|reset> [args]`,run:async e=>{let t=e[0];if(!t){console.log(`Usage: aikit flow <add|remove|list|info|use|update|status|start|reset|runs>`),console.log(``),console.log(`Commands:`),console.log(` add <source> Install a flow from git URL or local path`),console.log(` remove <name> Remove an installed flow`),console.log(` list List all installed flows`),console.log(` info <name> Show details of a flow`),console.log(` use <name> Set active flow (start it)`),console.log(` update <name> Update a flow from its source`),console.log(` status Show current flow execution status`),console.log(` start [name] Start a flow (or resume)`),console.log(` reset Reset the active flow`),console.log(` runs List all flow runs`);return}let n=await xt();switch(t){case`add`:{let t=e[1];if(!t){console.error(`Usage: aikit flow add <source>`),console.error(` source: git URL (https://...) or local path`);return}let i=t.startsWith(`http`)||t.startsWith(`git@`)||t.endsWith(`.git`),a=l(t),s=r(a);if(!i&&!s){console.error(`Source not found: ${t}`),console.error(`Provide a git URL or existing local path.`);return}let c,u;if(i){console.log(`Cloning ${t}...`);let e=n.git.clone(t);if(!e.success||!e.data){console.error(e.error??`Failed to clone flow`);return}c=e.data,u=`git`}else{let r=e[2]||o(a);console.log(`Copying local flow from ${t}...`);let i=n.git.copyLocal(a,r);if(!i.success||!i.data){console.error(i.error??`Failed to copy local flow`);return}c=i.data,u=`local`}let d=await n.loader.load(c);if(!d.success||!d.data){console.error(d.error??`Failed to load flow`),n.git.remove(c);return}let{manifest:f,format:p}=d.data;if(St(c,f),f.install.length>0){console.log(`Installing ${f.install.length} dependencies...`);let e=n.git.runInstallDeps(f.install);if(!e.success){console.error(`Dependency install failed: ${e.error}`),n.git.remove(c);return}}let m=new Date().toISOString(),h=n.registry.register({name:f.name,version:f.version,source:t,sourceType:u,installPath:c,format:p,registeredAt:m,updatedAt:m,manifest:f});if(!h.success){console.error(h.error??`Failed to register flow`),n.git.remove(c);return}console.log(`✓ Flow "${f.name}" v${f.version} installed (${p} format)`),console.log(` Steps: ${f.steps.map(e=>e.id).join(` → `)}`);break}case`remove`:{let t=e[1];if(!t){console.error(`Usage: aikit flow remove <name>`);return}let r=n.registry.get(t);if(!r){console.error(`Flow "${t}" not found`);return}let i=n.git.remove(r.installPath);if(!i.success){console.error(i.error??`Failed to remove flow files`);return}let a=n.registry.unregister(t);if(!a.success){console.error(a.error??`Failed to unregister flow`);return}console.log(`✓ Flow "${t}" removed`);break}case`list`:{let e=n.registry.list();if(e.length===0){console.log("No flows installed. Use `aikit flow add <source>` to install one.");return}console.log(`Installed Flows:`),console.log(`─`.repeat(60));for(let t of e){let e=t.manifest.steps.map(e=>e.id).join(` → `);console.log(` ${t.name} v${t.version} (${t.sourceType}, ${t.format})`),console.log(` Steps: ${e}`)}let t=n.stateMachine.getStatus();t.success&&t.data&&(console.log(``),console.log(`Active: ${t.data.flow} (${t.data.status}, step: ${t.data.currentStep??`done`})`));break}case`info`:{let t=e[1];if(!t){console.error(`Usage: aikit flow info <name>`);return}let r=n.registry.get(t);if(!r){console.error(`Flow "${t}" not found`);return}console.log(`Flow: ${r.name}`),console.log(`Version: ${r.version}`),console.log(`Source: ${r.source} (${r.sourceType})`),console.log(`Format: ${r.format}`),console.log(`Path: ${r.installPath}`),console.log(`Registered: ${r.registeredAt}`),console.log(`Updated: ${r.updatedAt}`),console.log(``),console.log(`Steps:`);for(let e of r.manifest.steps){let t=e.requires.length?` (requires: ${e.requires.join(`, `)})`:``;console.log(` ${e.id}: ${e.name}${t}`),console.log(` Skill: ${e.skill}`),console.log(` Produces: ${e.produces.join(`, `)}`)}if(r.manifest.install.length>0){console.log(``),console.log(`Dependencies:`);for(let e of r.manifest.install)console.log(` ${e}`)}break}case`use`:case`start`:{let r=e[1],i=r?n.registry.get(r):null;if(t===`use`&&!r){console.error(`Usage: aikit flow use <name>`);return}if(t===`start`&&!r){let e=n.stateMachine.getStatus();if(e.success&&e.data&&e.data.status===`active`){console.log(`Resuming flow: ${e.data.flow}`),console.log(`Current step: ${e.data.currentStep}`),console.log(`Completed: ${e.data.completedSteps.join(`, `)||`none`}`);return}console.error("No active flow. Use `aikit flow start <name>` to begin one.");return}if(!i){console.error(`Flow "${r}" not found. Use \`aikit flow list\` to see installed flows.`);return}let a=e[2],o=n.stateMachine.start(i.name,i.manifest,a);if(!o.success||!o.data){console.error(o.error??`Failed to start flow`);return}let s=o.data;console.log(`✓ Flow "${i.name}" started`),console.log(` Topic: ${s.topic}`),console.log(` Run directory: ${s.runDir}`),console.log(` Current step: ${s.currentStep}`),console.log(` Steps: ${i.manifest.steps.map(e=>e.id).join(` → `)}`);break}case`update`:{let t=e[1];if(!t){console.error(`Usage: aikit flow update <name>`);return}let r=n.registry.get(t);if(!r){console.error(`Flow "${t}" not found`);return}if(r.sourceType!==`git`){console.error(`Flow "${t}" is ${r.sourceType}, not updatable via git`);return}console.log(`Updating ${t}...`);let i=n.git.update(r.installPath);if(!i.success){console.error(i.error??`Failed to update flow`);return}let a=await n.loader.load(r.installPath);if(a.success&&a.data){let e=new Date().toISOString(),t=n.registry.register({...r,version:a.data.manifest.version,format:a.data.format,manifest:a.data.manifest,updatedAt:e});if(!t.success){console.error(t.error??`Failed to refresh flow registry entry`);return}}console.log(`✓ Flow "${t}" updated`);break}case`status`:{let e=n.stateMachine.getStatus();if(!e.success||!e.data){console.log(`No active flow.`);return}let t=e.data;if(console.log(`Flow: ${t.flow}`),console.log(`Topic: ${t.topic}`),console.log(`Slug: ${t.slug}`),console.log(`Run Dir: ${t.runDir}`),console.log(`Status: ${t.status}`),console.log(`Current Step: ${t.currentStep??`(completed)`}`),console.log(`Completed: ${t.completedSteps.join(`, `)||`none`}`),t.skippedSteps.length>0&&console.log(`Skipped: ${t.skippedSteps.join(`, `)}`),console.log(`Started: ${t.startedAt}`),console.log(`Updated: ${t.updatedAt}`),Object.keys(t.artifacts).length>0){console.log(`Artifacts:`);for(let[e,n]of Object.entries(t.artifacts))console.log(` ${e}: ${n}`)}break}case`reset`:{let e=n.stateMachine.reset();if(!e.success){console.error(e.error??`Failed to reset flow state`);return}console.log(`✓ Flow abandoned`);break}case`runs`:{let t=e[1],r=e[2],i=n.stateMachine.listRuns({flow:t,status:r});if(i.length===0){console.log(`No flow runs found.`);return}console.log(`Flow Runs:`),console.log(`─`.repeat(80));for(let e of i){let t=e.currentStep?` → ${e.currentStep}`:``;console.log(` ${e.id} [${e.status}] ${e.flow}${t}`),console.log(` Topic: ${e.topic}`),console.log(` Started: ${e.startedAt} | Updated: ${e.updatedAt}`)}break}default:console.error(`Unknown flow command: ${t}`),console.log("Use `aikit flow` for help.")}}}];let q=null;async function J(){return q||=await bt(),q}function wt(){return q}const Tt=[{name:`graph`,description:`Query the knowledge graph`,usage:`aikit graph <action> [options]
|
|
7
7
|
Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear
|
|
8
8
|
Options: --type, --name, --node-id, --edge-type, --direction, --depth, --limit, --source-path`,run:async e=>{let t=e.shift()?.trim()??``;t||(console.error(`Usage: aikit graph <action>
|
|
9
9
|
Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear`),process.exit(1));let{graphStore:n}=await J(),r=F(e,`--type`,``),i=F(e,`--name`,``),a=F(e,`--node-id`,``),o=F(e,`--edge-type`,``),s=F(e,`--direction`,`both`),c=P(e,`--depth`,2),l=P(e,`--limit`,50),u=F(e,`--source-path`,``),d={stats:`stats`,"find-nodes":`find_nodes`,"find-edges":`find_edges`,neighbors:`neighbors`,traverse:`traverse`,delete:`delete`,clear:`clear`}[t];d||(console.error(`Unknown graph action: ${t}`),console.error(`Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear`),process.exit(1));let f=await ge(n,{action:d,nodeType:r||void 0,namePattern:i||void 0,sourcePath:u||void 0,nodeId:a||void 0,edgeType:o||void 0,direction:s,maxDepth:c,limit:l});if(console.log(f.summary),f.nodes&&f.nodes.length>0){console.log(`
|
|
10
10
|
Nodes:`);for(let e of f.nodes){let t=Object.keys(e.properties).length>0?` ${JSON.stringify(e.properties)}`:``;console.log(` ${e.name} (${e.type}, id: ${e.id})${t}`)}}if(f.edges&&f.edges.length>0){console.log(`
|
|
11
|
-
Edges:`);for(let e of f.edges){let t=e.weight===1?``:` (weight: ${e.weight})`;console.log(` ${e.fromId} --[${e.type}]--> ${e.toId}${t}`)}}f.stats&&(console.log(`\nNode types: ${JSON.stringify(f.stats.nodeTypes)}`),console.log(`Edge types: ${JSON.stringify(f.stats.edgeTypes)}`)),f.deleted!==void 0&&console.log(`Deleted: ${f.deleted}`)}}],Y=[{name:`remember`,description:`Store curated knowledge`,usage:`aikit remember <title> --category <cat> [--tags tag1,tag2]`,run:async e=>{let t=F(e,`--category`,``).trim(),n=R(F(e,`--tags`,``)),r=e.shift()?.trim()??``,i=await L(),a=i.trim().length>0?i:e.join(` `).trim();(!r||!t||!a.trim())&&(console.error(`Usage: aikit remember <title> --category <cat> [--tags tag1,tag2]`),process.exit(1));let{curated:o}=await J(),s=await o.remember(r,a,t,n);console.log(`Stored curated entry`),console.log(` Path: ${s.path}`),console.log(` Category: ${t}`),n.length>0&&console.log(` Tags: ${n.join(`, `)}`)}},{name:`forget`,description:`Remove a curated entry`,usage:`aikit forget <path> --reason <reason>`,run:async e=>{let t=F(e,`--reason`,``).trim(),n=e.shift()?.trim()??``;(!n||!t)&&(console.error(`Usage: aikit forget <path> --reason <reason>`),process.exit(1));let{curated:r}=await J(),i=await r.forget(n,t);console.log(`Removed curated entry: ${i.path}`)}},{name:`read`,description:`Read a curated entry`,usage:`aikit read <path>`,run:async e=>{let t=e.shift()?.trim()??``;t||(console.error(`Usage: aikit read <path>`),process.exit(1));let{curated:n}=await J(),r=await n.read(t);console.log(r.title),console.log(`─`.repeat(60)),console.log(`Path: ${r.path}`),console.log(`Category: ${r.category}`),console.log(`Version: ${r.version}`),console.log(`Tags: ${r.tags.length>0?r.tags.join(`, `):`None`}`),console.log(``),console.log(r.content)}},{name:`list`,description:`List curated entries`,usage:`aikit list [--category <cat>] [--tag <tag>]`,run:async e=>{let t=F(e,`--category`,``).trim()||void 0,n=F(e,`--tag`,``).trim()||void 0,{curated:r}=await J(),i=await r.list({category:t,tag:n});if(i.length===0){console.log(`No curated entries found.`);return}console.log(`Curated entries (${i.length})`),console.log(`─`.repeat(60));for(let e of i){console.log(e.path),console.log(` ${e.title}`),console.log(` Category: ${e.category} | Version: ${e.version}`),console.log(` Tags: ${e.tags.length>0?e.tags.join(`, `):`None`}`);let t=e.contentPreview.replace(/\s+/g,` `).trim();t&&console.log(` Preview: ${t}`),console.log(``)}}},{name:`update`,description:`Update a curated entry`,usage:`aikit update <path> --reason <reason>`,run:async e=>{let t=F(e,`--reason`,``).trim(),n=e.shift()?.trim()??``,r=await L();(!n||!t||!r.trim())&&(console.error(`Usage: aikit update <path> --reason <reason>`),process.exit(1));let{curated:i}=await J(),a=await i.update(n,r,t);console.log(`Updated curated entry`),console.log(` Path: ${a.path}`),console.log(` Version: ${a.version}`)}},{name:`compact`,description:`Compress text for context`,usage:`aikit compact <query> [--path <file>] [--max-chars N] [--segmentation paragraph|sentence|line]`,run:async e=>{let t=P(e,`--max-chars`,3e3),n=F(e,`--path`,``).trim()||void 0,r=F(e,`--segmentation`,`paragraph`),i=e.join(` `).trim(),a=n?void 0:await L();(!i||!n&&!a?.trim())&&(console.error(`Usage: aikit compact <query> --path <file> OR cat file | aikit compact <query>`),process.exit(1));let{embedder:o}=await J(),s=await re(o,{text:a,path:n,query:i,maxChars:t,segmentation:r});console.log(`Compressed ${s.originalChars} chars to ${s.compressedChars} chars`),console.log(`Ratio: ${(s.ratio*100).toFixed(1)}% | Segments: ${s.segmentsKept}/${s.segmentsTotal}`),console.log(``),console.log(s.text)}}],wt=[{name:`search`,description:`Search the AI Kit index`,usage:`aikit search <query> [--limit N] [--mode hybrid|semantic|keyword] [--graph-hops 0-3]`,run:async e=>{let t=P(e,`--limit`,5),n=F(e,`--mode`,`hybrid`),r=P(e,`--graph-hops`,0),i=e.join(` `).trim();i||(console.error(`Usage: aikit search <query>`),process.exit(1));let{embedder:a,store:o,graphStore:s}=await J(),c=await a.embedQuery(i),l;if(n===`keyword`)l=await o.ftsSearch(i,{limit:t});else if(n===`semantic`)l=await o.search(c,{limit:t});else{let[e,n]=await Promise.all([o.search(c,{limit:t*2}),o.ftsSearch(i,{limit:t*2}).catch(()=>[])]);l=pt(e,n).slice(0,t)}if(l.length===0){console.log(`No results found.`);return}for(let{record:e,score:t}of l){console.log(`\n${`─`.repeat(60)}`),console.log(`[${(t*100).toFixed(1)}%] ${e.sourcePath}:${e.startLine}-${e.endLine}`),console.log(` Type: ${e.contentType} | Origin: ${e.origin}`),e.tags.length>0&&console.log(` Tags: ${e.tags.join(`, `)}`),console.log(``);let n=e.content.length>500?`${e.content.slice(0,500)}...`:e.content;console.log(n)}if(console.log(`\n${`─`.repeat(60)}`),console.log(`${l.length} result(s) found.`),r>0&&l.length>0)try{let{graphAugmentSearch:e}=await import(`../../tools/dist/index.js`),t=(await e(s,l.map(e=>({recordId:e.record.id,score:e.score,sourcePath:e.record.sourcePath})),{hops:r,maxPerHit:5})).filter(e=>e.graphContext.nodes.length>0);if(t.length>0){console.log(`\nGraph context (${r} hop${r>1?`s`:``}):\n`);for(let e of t){console.log(` ${e.sourcePath}:`);for(let t of e.graphContext.nodes.slice(0,5))console.log(` → ${t.name} (${t.type})`);for(let t of e.graphContext.edges.slice(0,5))console.log(` → ${t.fromId} --[${t.type}]--> ${t.toId}`)}}}catch(e){console.error(`[graph] augmentation failed: ${e.message}`)}}},{name:`find`,description:`Run federated search across indexed content and files`,usage:`aikit find [query] [--glob <pattern>] [--pattern <regex>] [--limit N]`,run:async e=>{let t=P(e,`--limit`,10),n=F(e,`--glob`,``).trim()||void 0,r=F(e,`--pattern`,``).trim()||void 0,i=e.join(` `).trim()||void 0;!i&&!n&&!r&&(console.error(`Usage: aikit find [query] [--glob <pattern>] [--pattern <regex>] [--limit N]`),process.exit(1));let{embedder:a,store:o}=await J(),s=await de(a,o,{query:i,glob:n,pattern:r,limit:t});if(s.results.length===0){console.log(`No matches found.`);return}console.log(`Strategies: ${s.strategies.join(`, `)}`),console.log(`Results: ${s.results.length} shown (${s.totalFound} total)`);for(let e of s.results){let t=e.lineRange?`:${e.lineRange.start}-${e.lineRange.end}`:``;console.log(`\n[${e.source}] ${e.path}${t}`),console.log(` Score: ${(e.score*100).toFixed(1)}%`),e.preview&&console.log(` ${e.preview.replace(/\s+/g,` `).trim()}`)}}},{name:`scope-map`,description:`Generate a reading plan for a task`,usage:`aikit scope-map <task> [--max-files N]`,run:async e=>{let t=P(e,`--max-files`,15),n=e.join(` `).trim();n||(console.error(`Usage: aikit scope-map <task> [--max-files N]`),process.exit(1));let{embedder:r,store:i}=await J(),a=await Me(r,i,{task:n,maxFiles:t});console.log(`Task: ${a.task}`),console.log(`Files: ${a.files.length}`),console.log(`Estimated tokens: ${a.totalEstimatedTokens}`),console.log(``),console.log(`Reading order:`);for(let e of a.readingOrder)console.log(` ${e}`);for(let[e,t]of a.files.entries())console.log(`\n${e+1}. ${t.path}`),console.log(` Relevance: ${(t.relevance*100).toFixed(1)}% | Tokens: ${t.estimatedTokens}`),console.log(` Why: ${t.reason}`),t.focusRanges.length>0&&console.log(` Focus: ${et(t.focusRanges)}`)}},{name:`symbol`,description:`Resolve a symbol definition, imports, and references`,usage:`aikit symbol <name> [--limit N]`,run:async e=>{let t=P(e,`--limit`,20),n=e.join(` `).trim();n||(console.error(`Usage: aikit symbol <name> [--limit N]`),process.exit(1));let{embedder:r,store:i}=await J();ut(await Re(r,i,{name:n,limit:t}))}},{name:`trace`,description:`Trace forward/backward flow for a symbol or file location`,usage:`aikit trace <start> [--direction forward|backward|both] [--max-depth N]`,run:async e=>{let t=F(e,`--direction`,`both`).trim()||`both`,n=P(e,`--max-depth`,3),r=e.join(` `).trim();(!r||![`forward`,`backward`,`both`].includes(t))&&(console.error(`Usage: aikit trace <start> [--direction forward|backward|both] [--max-depth N]`),process.exit(1));let{embedder:i,store:a}=await J();ot(await Be(i,a,{start:r,direction:t,maxDepth:n}))}},{name:`examples`,description:`Find real code examples of a symbol or pattern`,usage:`aikit examples <query> [--limit N] [--content-type type]`,run:async e=>{let t=P(e,`--limit`,5),n=F(e,`--content-type`,``).trim()||void 0,r=e.join(` `).trim();r||(console.error(`Usage: aikit examples <query> [--limit N] [--content-type type]`),process.exit(1));let{embedder:i,store:a}=await J();st(await pe(i,a,{query:r,limit:t,contentType:n}))}},{name:`dead-symbols`,description:`Find exported symbols that appear to be unused`,usage:`aikit dead-symbols [--limit N]`,run:async e=>{let t=P(e,`--limit`,100),{embedder:n,store:r}=await J();ct(await fe(n,r,{limit:t}))}},{name:`lookup`,description:`Look up indexed content by record ID or source path`,usage:`aikit lookup <id>`,run:async e=>{let t=e.join(` `).trim();t||(console.error(`Usage: aikit lookup <id>`),process.exit(1));let{store:n}=await J(),r=await n.getById(t);if(r){console.log(r.id),console.log(`─`.repeat(60)),console.log(`Path: ${r.sourcePath}`),console.log(`Chunk: ${r.chunkIndex+1}/${r.totalChunks}`),console.log(`Lines: ${r.startLine}-${r.endLine}`),console.log(`Type: ${r.contentType} | Origin: ${r.origin}`),r.tags.length>0&&console.log(`Tags: ${r.tags.join(`, `)}`),console.log(``),console.log(r.content);return}let i=await n.getBySourcePath(t);if(i.length===0){console.log(`No indexed content found for: ${t}`);return}i.sort((e,t)=>e.chunkIndex-t.chunkIndex),console.log(t),console.log(`─`.repeat(60)),console.log(`Chunks: ${i.length} | Type: ${i[0].contentType}`);for(let e of i){let t=e.startLine?` (lines ${e.startLine}-${e.endLine})`:``;console.log(`\nChunk ${e.chunkIndex+1}/${e.totalChunks}${t}`),console.log(e.content)}}}],X=s(u(import.meta.url));function Z(e){let t=e;for(let e=0;e<10;e++){try{let e=c(t,`package.json`);if(r(e)&&JSON.parse(a(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=s(t);if(e===t)break;t=e}return l(e,`..`,`..`,`..`)}const Tt=[{name:`status`,description:`Show AI Kit index status and statistics`,run:async()=>{let{isUserInstalled:e,getGlobalDataDir:t,computePartitionKey:n,listWorkspaces:r}=await import(`../../core/dist/index.js`),{existsSync:i}=await import(`node:fs`),a=process.cwd(),o=e(),s=i(l(a,`.vscode`,`mcp.json`)),c,u;if(o&&s)c=`workspace (overrides user-level for this workspace)`,u=l(a,`.aikit-data`);else if(o){let e=n(a);c=i(l(a,`AGENTS.md`))?`user (workspace scaffolded)`:`user (workspace not scaffolded)`,u=l(t(),e)}else c=`workspace`,u=l(a,`.aikit-data`);if(console.log(`AI Kit Status`),console.log(`─`.repeat(40)),console.log(` Mode: ${c}`),console.log(` Data: ${u}`),o&&!s){let e=r();console.log(` Registry: ${e.length} workspace(s) enrolled`)}try{let{store:e}=await J(),t=await e.getStats(),n=await e.listSourcePaths();console.log(` Records: ${t.totalRecords}`),console.log(` Files: ${t.totalFiles}`),console.log(` Indexed: ${t.lastIndexedAt??`Never`}`),console.log(` Backend: ${t.storeBackend}`),console.log(` Model: ${t.embeddingModel}`),console.log(``),console.log(`Content Types:`);for(let[e,n]of Object.entries(t.contentTypeBreakdown))console.log(` ${e}: ${n}`);if(n.length>0){console.log(``),console.log(`Files (${n.length} total):`);for(let e of n.slice(0,20))console.log(` ${e}`);n.length>20&&console.log(` ... and ${n.length-20} more`)}}catch{console.log(``),console.log(" Index not available — run `aikit reindex` to index this workspace.")}o&&!s&&!i(l(a,`AGENTS.md`))&&(console.log(``),console.log(" Action: Run `npx @vpxa/aikit init` to add AGENTS.md and copilot-instructions.md"))}},{name:`reindex`,description:`Re-index the AI Kit index from configured sources`,usage:`aikit reindex [--full]`,run:async e=>{let t=e.includes(`--full`),{store:n,indexer:r,curated:i,config:a}=await J();console.log(`Indexing sources...`);let o=e=>{e.phase===`chunking`&&e.currentFile&&process.stdout.write(`\r [${e.filesProcessed+1}/${e.filesTotal}] ${e.currentFile}`),e.phase===`done`&&process.stdout.write(`
|
|
12
|
-
`)},s;t?(console.log(`Dropping existing index for full reindex...`),s=await r.reindexAll(a,o)):s=await r.index(a,o),console.log(`Done: ${s.filesProcessed} files, ${s.chunksCreated} chunks in ${(s.durationMs/1e3).toFixed(1)}s`),console.log(`Building FTS index...`),await n.createFtsIndex(),console.log(`Re-indexing curated entries...`);let c=await i.reindexAll();console.log(`Curated: ${c.indexed} entries restored`)}},{name:`serve`,description:`Start the MCP server (stdio or HTTP)`,usage:`aikit serve [--transport stdio|http] [--port N]`,run:async e=>{let t=l(
|
|
13
|
-
Suggested next steps:`);for(let e of o.next)console.log(` → ${e.tool}: ${e.reason}`)}}else console.error(o.error?.message??`Audit failed`),process.exitCode=1}},{name:`guide`,description:`Tool discovery — recommend AI Kit tools for a given goal`,usage:`aikit guide <goal> [--max N]`,run:async e=>{let t=e.indexOf(`--max`),n=5;t!==-1&&t+1<e.length&&(n=Number.parseInt(e.splice(t,2)[1],10)||5);let r=e.join(` `).trim();r||(console.error(`Usage: aikit guide <goal> [--max N]`),console.error(`Example: aikit guide "audit this project"`),process.exit(1));let i=_e(r,n);console.log(`Workflow: ${i.workflow}`),console.log(` ${i.description}\n`),console.log(`Recommended tools:`);for(let e of i.tools){let t=e.suggestedArgs?` ${JSON.stringify(e.suggestedArgs)}`:``;console.log(` ${e.order}. ${e.tool} — ${e.reason}${t}`)}i.alternativeWorkflows.length>0&&console.log(`\nAlternatives: ${i.alternativeWorkflows.join(`, `)}`)}},{name:`replay`,description:`Show recent tool invocation audit trail`,usage:`aikit replay [--last N] [--tool <name>] [--source mcp|cli]`,run:async e=>{let t=ke({last:Number.parseInt(e[e.indexOf(`--last`)+1],10)||20,tool:e.includes(`--tool`)?e[e.indexOf(`--tool`)+1]:void 0,source:e.includes(`--source`)?e[e.indexOf(`--source`)+1]:void 0});if(t.length===0){console.log(`No replay entries. Activity is logged when tools are invoked.`);return}console.log(`Replay Log (${t.length} entries)\n`);for(let e of t){let t=e.ts.split(`T`)[1]?.split(`.`)[0]??e.ts,n=e.status===`ok`?`✓`:`✗`;console.log(`${t} ${n} ${e.tool} (${e.durationMs}ms) [${e.source}]`),console.log(` in: ${e.input}`),console.log(` out: ${e.output}`)}Ae().catch(()=>{})}},{name:`replay-clear`,description:`Clear the replay audit trail`,run:async()=>{Oe(),console.log(`Replay log cleared.`)}},{name:`dashboard`,description:`Launch web dashboard for knowledge graph visualization`,usage:`aikit dashboard [--port <port>] [--no-open]`,run:async e=>{let t=e.indexOf(`--port`),n=t!==-1&&e[t+1]?Number.parseInt(e[t+1],10):3210,r=Number.isFinite(n)?n:3210,i=e.includes(`--no-open`);console.log(`Starting AI Kit server on port ${r}...`);let{spawn:a}=await import(`node:child_process`),{platform:o}=await import(`node:os`),s=l(Z(X),`packages`,`server`,`dist`,`index.js`),c=a(process.execPath,[s,`--transport`,`http`,`--port`,String(r)],{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,AIKIT_TRANSPORT:`http`,AIKIT_PORT:String(r)}}),u=`http://localhost:${r}/_dashboard/`,d=`http://localhost:${r}/health`,f=!1;for(let e=0;e<30;e+=1){try{if((await fetch(d)).ok){f=!0;break}}catch{}await new Promise(e=>setTimeout(e,1e3))}if(f||(console.error(`Server failed to start within 30 seconds.`),c.kill(),process.exit(1)),console.log(`AI Kit Dashboard: ${u}`),console.log(`Press Ctrl+C to stop.`),!i){let e=o();e===`win32`?a(`cmd`,[`/c`,`start`,``,u],{stdio:`ignore`,detached:!0}).unref():a(e===`darwin`?`open`:`xdg-open`,[u],{stdio:`ignore`,detached:!0}).unref()}let p=()=>{c.kill(),process.exit(0)};process.on(`SIGINT`,p),process.on(`SIGTERM`,p),await new Promise(e=>{c.on(`exit`,()=>e())})}},{name:`settings`,description:`Launch web UI to manage AI Kit configuration and environment variables`,usage:`aikit settings [--port <port>] [--no-open]`,run:async e=>{let t=e.indexOf(`--port`),n=t!==-1&&e[t+1]?Number.parseInt(e[t+1],10):3210,r=Number.isFinite(n)?n:3210,i=e.includes(`--no-open`);console.log(`Starting AI Kit server on port ${r}...`);let{spawn:a}=await import(`node:child_process`),{platform:o}=await import(`node:os`),s=l(Z(X),`packages`,`server`,`dist`,`index.js`),c=a(process.execPath,[s,`--transport`,`http`,`--port`,String(r)],{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,AIKIT_TRANSPORT:`http`,AIKIT_PORT:String(r)}}),u=`http://localhost:${r}/settings/`,d=`http://localhost:${r}/health`,f=!1;for(let e=0;e<30;e+=1){try{if((await fetch(d)).ok){f=!0;break}}catch{}await new Promise(e=>setTimeout(e,1e3))}if(f||(console.error(`Server failed to start within 30 seconds.`),c.kill(),process.exit(1)),console.log(`AI Kit Settings: ${u}`),console.log(`Press Ctrl+C to stop.`),!i){let e=o();e===`win32`?a(`cmd`,[`/c`,`start`,``,u],{stdio:`ignore`,detached:!0}).unref():a(e===`darwin`?`open`:`xdg-open`,[u],{stdio:`ignore`,detached:!0}).unref()}let p=()=>{c.kill(),process.exit(0)};process.on(`SIGINT`,p),process.on(`SIGTERM`,p),await new Promise(e=>{c.on(`exit`,()=>e())})}}];function Et(e){let t=e;for(let e=0;e<10;e++){try{let e=c(t,`package.json`);if(r(e)&&JSON.parse(a(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=s(t);if(e===t)break;t=e}return l(e,`..`,`..`,`..`)}const Dt=[{name:`upgrade`,description:`Upgrade AI Kit agents, prompts, and skills to the latest version (user-level and workspace-level)`,usage:`aikit upgrade`,run:async()=>{let{initUser:n}=await import(`./user-D4p6n-Q5.js`);await n({force:!0});let i=process.cwd(),o=r(l(i,`.github`,`.aikit-scaffold.json`)),c=r(l(i,`.github`,`agents`)),d=r(l(i,`.github`,`prompts`)),f=r(l(i,`.claude`,`commands`));if(o||c||d||f){let{initScaffoldOnly:e}=await import(`./init-X00JY_h4.js`);await e({force:!0})}if(r(l(i,`.github`,`skills`))){let{smartCopySkills:n}=await import(`./scaffold-BLeqLPMe.js`),r=Et(s(u(import.meta.url))),o=JSON.parse(a(l(r,`package.json`),`utf-8`)).version;await n(i,r,[...e],o,!0);let{smartCopyFlows:c}=await import(`./scaffold-BLeqLPMe.js`);await c(i,r,[...t],o,!0)}}}],Ot=[{name:`workset`,description:`Manage saved file sets`,usage:`aikit workset <action> [name] [--files f1,f2] [--description desc]`,run:async e=>{let t=e.shift()?.trim(),n=R(F(e,`--files`,``)),r=F(e,`--description`,``).trim()||void 0,i=e.shift()?.trim();switch(t||(console.error(`Usage: aikit workset <action> [name] [--files f1,f2] [--description desc]`),console.error(`Actions: save, get, list, delete, add, remove`),process.exit(1)),t){case`save`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset save <name> --files f1,f2 [--description desc]`),process.exit(1));let e=je(i,n,{description:r});console.log(`Saved workset: ${e.name}`),V(e);return}case`get`:{i||(console.error(`Usage: aikit workset get <name>`),process.exit(1));let e=me(i);if(!e){console.log(`No workset found: ${i}`);return}V(e);return}case`list`:{let e=_();if(e.length===0){console.log(`No worksets saved.`);return}console.log(`Worksets (${e.length})`),console.log(`─`.repeat(60));for(let t of e)V(t),console.log(``);return}case`delete`:{i||(console.error(`Usage: aikit workset delete <name>`),process.exit(1));let e=se(i);console.log(e?`Deleted workset: ${i}`:`No workset found: ${i}`);return}case`add`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset add <name> --files f1,f2`),process.exit(1));let e=d(i,n);console.log(`Updated workset: ${e.name}`),V(e);return}case`remove`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset remove <name> --files f1,f2`),process.exit(1));let e=Ee(i,n);if(!e){console.log(`No workset found: ${i}`);return}console.log(`Updated workset: ${e.name}`),V(e);return}default:console.error(`Unknown workset action: ${t}`),console.error(`Actions: save, get, list, delete, add, remove`),process.exit(1)}}},{name:`stash`,description:`Persist and retrieve named intermediate values`,usage:`aikit stash <set|get|list|delete|clear> [key] [value]`,run:async e=>{let t=e.shift()?.trim(),n=e.shift()?.trim();switch(t||(console.error(`Usage: aikit stash <set|get|list|delete|clear> [key] [value]`),process.exit(1)),t){case`set`:{n||(console.error(`Usage: aikit stash set <key> <value>`),process.exit(1));let t=e.join(` `),r=t.trim()?``:await L(),i=Le(n,dt(t||r));console.log(`Stored stash entry: ${i.key}`),console.log(` Type: ${i.type}`),console.log(` Stored: ${i.storedAt}`);return}case`get`:{n||(console.error(`Usage: aikit stash get <key>`),process.exit(1));let e=Fe(n);if(!e){console.log(`No stash entry found: ${n}`);return}console.log(JSON.stringify(e,null,2));return}case`list`:{let e=Ie();if(e.length===0){console.log(`No stash entries saved.`);return}console.log(`Stash entries (${e.length})`),console.log(`─`.repeat(60));for(let t of e)console.log(`${t.key} (${t.type})`),console.log(` Stored: ${t.storedAt}`);return}case`delete`:{n||(console.error(`Usage: aikit stash delete <key>`),process.exit(1));let e=Pe(n);console.log(e?`Deleted stash entry: ${n}`:`No stash entry found: ${n}`);return}case`clear`:{let e=Ne();console.log(`Cleared ${e} stash entr${e===1?`y`:`ies`}.`);return}default:console.error(`Unknown stash action: ${t}`),console.error(`Actions: set, get, list, delete, clear`),process.exit(1)}}},{name:`lane`,description:`Manage verified lanes — isolated file copies for parallel exploration`,usage:`aikit lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]`,run:async e=>{let t=e.shift();if((!t||![`create`,`list`,`status`,`diff`,`merge`,`discard`].includes(t))&&(console.error(`Usage: aikit lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]`),process.exit(1)),t===`list`){let e=Se();if(e.length===0){console.log(`No active lanes.`);return}for(let t of e)console.log(`${t.name} (${t.sourceFiles.length} files, created ${t.createdAt})`);return}let n=e.shift();switch(n||(console.error(`Lane name is required for "${t}".`),process.exit(1)),t){case`create`:{let t=F(e,`--files`,``);t||(console.error(`Usage: aikit lane create <name> --files file1.ts,file2.ts`),process.exit(1));let r=ye(n,t.split(`,`).map(e=>e.trim()));console.log(`Lane "${r.name}" created with ${r.sourceFiles.length} files.`);break}case`status`:{let e=g(n);console.log(`Lane: ${e.name}`),console.log(`Modified: ${e.modified} | Added: ${e.added} | Deleted: ${e.deleted}`);for(let t of e.entries)console.log(` ${t.status.padEnd(10)} ${t.file}`);break}case`diff`:{let e=be(n);console.log(`Lane: ${e.name} — ${e.modified} modified, ${e.added} added, ${e.deleted} deleted`);for(let t of e.entries)t.diff&&(console.log(`\n--- ${t.file} (${t.status})`),console.log(t.diff));break}case`merge`:{let e=Ce(n);console.log(`Merged ${e.filesMerged} files from lane "${e.name}".`);for(let t of e.files)console.log(` ${t}`);break}case`discard`:{let e=xe(n);console.log(e?`Lane "${n}" discarded.`:`Lane "${n}" not found.`);break}}}},{name:`queue`,description:`Manage task queues for sequential agent operations`,usage:`aikit queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]`,run:async e=>{let t=e.shift();if((!t||![`create`,`push`,`next`,`done`,`fail`,`get`,`list`,`clear`,`delete`].includes(t))&&(console.error(`Usage: aikit queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]`),process.exit(1)),t===`list`){let e=A();if(e.length===0){console.log(`No queues.`);return}for(let t of e)console.log(`${t.name} pending:${t.pending} done:${t.done} failed:${t.failed} total:${t.total}`);return}let n=e.shift();switch(n||(console.error(`Queue name is required for "${t}".`),process.exit(1)),t){case`create`:{let e=T(n);console.log(`Queue "${e.name}" created.`);break}case`push`:{let t=Te(n,e.join(` `)||`Untitled task`);console.log(`Pushed "${t.title}" (${t.id}) to queue "${n}".`);break}case`next`:{let e=we(n);console.log(e?`Next: ${e.title} (${e.id})`:`No pending items in queue "${n}".`);break}case`done`:{let t=e.shift();t||(console.error(`Usage: aikit queue done <name> <id>`),process.exit(1));let r=D(n,t);console.log(`Marked "${r.item.title}" as done.`);break}case`fail`:{let t=e.shift(),r=e.join(` `)||`Unknown error`;t||(console.error(`Usage: aikit queue fail <name> <id> [error message]`),process.exit(1));let i=O(n,t,r);console.log(`Marked "${i.title}" as failed: ${r}`);break}case`get`:{let e=k(n);if(!e){console.log(`Queue "${n}" not found.`);return}console.log(`Queue: ${e.name} (${e.items.length} items)`);for(let t of e.items){let e=t.error?` — ${t.error}`:``;console.log(` ${t.status.padEnd(12)} ${t.id} ${t.title}${e}`)}break}case`clear`:{let e=w(n);console.log(`Cleared ${e} completed/failed items from queue "${n}".`);break}case`delete`:{let e=E(n);console.log(e?`Queue "${n}" deleted.`:`Queue "${n}" not found.`);break}}}}],Q=[...wt,...Y,...$e,...Ct,...Tt,...gt,...mt,...Ot,...ht,...Dt,...xt];Q.push({name:`help`,description:`Show available commands`,run:async()=>{$()}});async function kt(e){let t=[...e],n=t.shift();if(!n||n===`--help`||n===`-h`){$();return}if(n===`--version`||n===`-v`){let e=l(s(u(import.meta.url)),`..`,`..`,`..`,`package.json`),t=JSON.parse(a(e,`utf-8`));console.log(t.version);return}if(n&&new Set([`--user`,`--workspace`,`--guide`,`--smart`]).has(n)){let e=Q.find(e=>e.name===`init`);if(e){await e.run([n,...t]);return}}let r=Q.find(e=>e.name===n);r||(console.error(`Unknown command: ${n}`),$(),process.exit(1));try{await r.run(t)}finally{let e=St();e&&await e.store.close()}}function $(){console.log(`@vpxa/aikit — Local-first AI developer toolkit
|
|
11
|
+
Edges:`);for(let e of f.edges){let t=e.weight===1?``:` (weight: ${e.weight})`;console.log(` ${e.fromId} --[${e.type}]--> ${e.toId}${t}`)}}f.stats&&(console.log(`\nNode types: ${JSON.stringify(f.stats.nodeTypes)}`),console.log(`Edge types: ${JSON.stringify(f.stats.edgeTypes)}`)),f.deleted!==void 0&&console.log(`Deleted: ${f.deleted}`)}}],Et=[{name:`remember`,description:`Store curated knowledge`,usage:`aikit remember <title> --category <cat> [--tags tag1,tag2]`,run:async e=>{let t=F(e,`--category`,``).trim(),n=R(F(e,`--tags`,``)),r=e.shift()?.trim()??``,i=await L(),a=i.trim().length>0?i:e.join(` `).trim();(!r||!t||!a.trim())&&(console.error(`Usage: aikit remember <title> --category <cat> [--tags tag1,tag2]`),process.exit(1));let{curated:o}=await J(),s=await o.remember(r,a,t,n);console.log(`Stored curated entry`),console.log(` Path: ${s.path}`),console.log(` Category: ${t}`),n.length>0&&console.log(` Tags: ${n.join(`, `)}`)}},{name:`forget`,description:`Remove a curated entry`,usage:`aikit forget <path> --reason <reason>`,run:async e=>{let t=F(e,`--reason`,``).trim(),n=e.shift()?.trim()??``;(!n||!t)&&(console.error(`Usage: aikit forget <path> --reason <reason>`),process.exit(1));let{curated:r}=await J(),i=await r.forget(n,t);console.log(`Removed curated entry: ${i.path}`)}},{name:`read`,description:`Read a curated entry`,usage:`aikit read <path>`,run:async e=>{let t=e.shift()?.trim()??``;t||(console.error(`Usage: aikit read <path>`),process.exit(1));let{curated:n}=await J(),r=await n.read(t);console.log(r.title),console.log(`─`.repeat(60)),console.log(`Path: ${r.path}`),console.log(`Category: ${r.category}`),console.log(`Version: ${r.version}`),console.log(`Tags: ${r.tags.length>0?r.tags.join(`, `):`None`}`),console.log(``),console.log(r.content)}},{name:`list`,description:`List curated entries`,usage:`aikit list [--category <cat>] [--tag <tag>]`,run:async e=>{let t=F(e,`--category`,``).trim()||void 0,n=F(e,`--tag`,``).trim()||void 0,{curated:r}=await J(),i=await r.list({category:t,tag:n});if(i.length===0){console.log(`No curated entries found.`);return}console.log(`Curated entries (${i.length})`),console.log(`─`.repeat(60));for(let e of i){console.log(e.path),console.log(` ${e.title}`),console.log(` Category: ${e.category} | Version: ${e.version}`),console.log(` Tags: ${e.tags.length>0?e.tags.join(`, `):`None`}`);let t=e.contentPreview.replace(/\s+/g,` `).trim();t&&console.log(` Preview: ${t}`),console.log(``)}}},{name:`update`,description:`Update a curated entry`,usage:`aikit update <path> --reason <reason>`,run:async e=>{let t=F(e,`--reason`,``).trim(),n=e.shift()?.trim()??``,r=await L();(!n||!t||!r.trim())&&(console.error(`Usage: aikit update <path> --reason <reason>`),process.exit(1));let{curated:i}=await J(),a=await i.update(n,r,t);console.log(`Updated curated entry`),console.log(` Path: ${a.path}`),console.log(` Version: ${a.version}`)}},{name:`compact`,description:`Compress text for context`,usage:`aikit compact <query> [--path <file>] [--max-chars N] [--segmentation paragraph|sentence|line]`,run:async e=>{let t=P(e,`--max-chars`,3e3),n=F(e,`--path`,``).trim()||void 0,r=F(e,`--segmentation`,`paragraph`),i=e.join(` `).trim(),a=n?void 0:await L();(!i||!n&&!a?.trim())&&(console.error(`Usage: aikit compact <query> --path <file> OR cat file | aikit compact <query>`),process.exit(1));let{embedder:o}=await J(),s=await re(o,{text:a,path:n,query:i,maxChars:t,segmentation:r});console.log(`Compressed ${s.originalChars} chars to ${s.compressedChars} chars`),console.log(`Ratio: ${(s.ratio*100).toFixed(1)}% | Segments: ${s.segmentsKept}/${s.segmentsTotal}`),console.log(``),console.log(s.text)}}],Dt=[{name:`search`,description:`Search the AI Kit index`,usage:`aikit search <query> [--limit N] [--mode hybrid|semantic|keyword] [--graph-hops 0-3]`,run:async e=>{let t=P(e,`--limit`,5),n=F(e,`--mode`,`hybrid`),r=P(e,`--graph-hops`,0),i=e.join(` `).trim();i||(console.error(`Usage: aikit search <query>`),process.exit(1));let{embedder:a,store:o,graphStore:s}=await J(),c=await a.embedQuery(i),l;if(n===`keyword`)l=await o.ftsSearch(i,{limit:t});else if(n===`semantic`)l=await o.search(c,{limit:t});else{let[e,n]=await Promise.all([o.search(c,{limit:t*2}),o.ftsSearch(i,{limit:t*2}).catch(()=>[])]);l=ht(e,n).slice(0,t)}if(l.length===0){console.log(`No results found.`);return}for(let{record:e,score:t}of l){console.log(`\n${`─`.repeat(60)}`),console.log(`[${(t*100).toFixed(1)}%] ${e.sourcePath}:${e.startLine}-${e.endLine}`),console.log(` Type: ${e.contentType} | Origin: ${e.origin}`),e.tags.length>0&&console.log(` Tags: ${e.tags.join(`, `)}`),console.log(``);let n=e.content.length>500?`${e.content.slice(0,500)}...`:e.content;console.log(n)}if(console.log(`\n${`─`.repeat(60)}`),console.log(`${l.length} result(s) found.`),r>0&&l.length>0)try{let{graphAugmentSearch:e}=await import(`../../tools/dist/index.js`),t=(await e(s,l.map(e=>({recordId:e.record.id,score:e.score,sourcePath:e.record.sourcePath})),{hops:r,maxPerHit:5})).filter(e=>e.graphContext.nodes.length>0);if(t.length>0){console.log(`\nGraph context (${r} hop${r>1?`s`:``}):\n`);for(let e of t){console.log(` ${e.sourcePath}:`);for(let t of e.graphContext.nodes.slice(0,5))console.log(` → ${t.name} (${t.type})`);for(let t of e.graphContext.edges.slice(0,5))console.log(` → ${t.fromId} --[${t.type}]--> ${t.toId}`)}}}catch(e){console.error(`[graph] augmentation failed: ${e.message}`)}}},{name:`find`,description:`Run federated search across indexed content and files`,usage:`aikit find [query] [--glob <pattern>] [--pattern <regex>] [--limit N]`,run:async e=>{let t=P(e,`--limit`,10),n=F(e,`--glob`,``).trim()||void 0,r=F(e,`--pattern`,``).trim()||void 0,i=e.join(` `).trim()||void 0;!i&&!n&&!r&&(console.error(`Usage: aikit find [query] [--glob <pattern>] [--pattern <regex>] [--limit N]`),process.exit(1));let{embedder:a,store:o}=await J(),s=await de(a,o,{query:i,glob:n,pattern:r,limit:t});if(s.results.length===0){console.log(`No matches found.`);return}console.log(`Strategies: ${s.strategies.join(`, `)}`),console.log(`Results: ${s.results.length} shown (${s.totalFound} total)`);for(let e of s.results){let t=e.lineRange?`:${e.lineRange.start}-${e.lineRange.end}`:``;console.log(`\n[${e.source}] ${e.path}${t}`),console.log(` Score: ${(e.score*100).toFixed(1)}%`),e.preview&&console.log(` ${e.preview.replace(/\s+/g,` `).trim()}`)}}},{name:`scope-map`,description:`Generate a reading plan for a task`,usage:`aikit scope-map <task> [--max-files N]`,run:async e=>{let t=P(e,`--max-files`,15),n=e.join(` `).trim();n||(console.error(`Usage: aikit scope-map <task> [--max-files N]`),process.exit(1));let{embedder:r,store:i}=await J(),a=await Pe(r,i,{task:n,maxFiles:t});console.log(`Task: ${a.task}`),console.log(`Files: ${a.files.length}`),console.log(`Estimated tokens: ${a.totalEstimatedTokens}`),console.log(``),console.log(`Reading order:`);for(let e of a.readingOrder)console.log(` ${e}`);for(let[e,t]of a.files.entries())console.log(`\n${e+1}. ${t.path}`),console.log(` Relevance: ${(t.relevance*100).toFixed(1)}% | Tokens: ${t.estimatedTokens}`),console.log(` Why: ${t.reason}`),t.focusRanges.length>0&&console.log(` Focus: ${nt(t.focusRanges)}`)}},{name:`symbol`,description:`Resolve a symbol definition, imports, and references`,usage:`aikit symbol <name> [--limit N]`,run:async e=>{let t=P(e,`--limit`,20),n=e.join(` `).trim();n||(console.error(`Usage: aikit symbol <name> [--limit N]`),process.exit(1));let{embedder:r,store:i}=await J();ft(await Be(r,i,{name:n,limit:t}))}},{name:`trace`,description:`Trace forward/backward flow for a symbol or file location`,usage:`aikit trace <start> [--direction forward|backward|both] [--max-depth N]`,run:async e=>{let t=F(e,`--direction`,`both`).trim()||`both`,n=P(e,`--max-depth`,3),r=e.join(` `).trim();(!r||![`forward`,`backward`,`both`].includes(t))&&(console.error(`Usage: aikit trace <start> [--direction forward|backward|both] [--max-depth N]`),process.exit(1));let{embedder:i,store:a}=await J();ct(await He(i,a,{start:r,direction:t,maxDepth:n}))}},{name:`examples`,description:`Find real code examples of a symbol or pattern`,usage:`aikit examples <query> [--limit N] [--content-type type]`,run:async e=>{let t=P(e,`--limit`,5),n=F(e,`--content-type`,``).trim()||void 0,r=e.join(` `).trim();r||(console.error(`Usage: aikit examples <query> [--limit N] [--content-type type]`),process.exit(1));let{embedder:i,store:a}=await J();lt(await pe(i,a,{query:r,limit:t,contentType:n}))}},{name:`dead-symbols`,description:`Find exported symbols that appear to be unused`,usage:`aikit dead-symbols [--limit N]`,run:async e=>{let t=P(e,`--limit`,100),{embedder:n,store:r}=await J();ut(await fe(n,r,{limit:t}))}},{name:`lookup`,description:`Look up indexed content by record ID or source path`,usage:`aikit lookup <id>`,run:async e=>{let t=e.join(` `).trim();t||(console.error(`Usage: aikit lookup <id>`),process.exit(1));let{store:n}=await J(),r=await n.getById(t);if(r){console.log(r.id),console.log(`─`.repeat(60)),console.log(`Path: ${r.sourcePath}`),console.log(`Chunk: ${r.chunkIndex+1}/${r.totalChunks}`),console.log(`Lines: ${r.startLine}-${r.endLine}`),console.log(`Type: ${r.contentType} | Origin: ${r.origin}`),r.tags.length>0&&console.log(`Tags: ${r.tags.join(`, `)}`),console.log(``),console.log(r.content);return}let i=await n.getBySourcePath(t);if(i.length===0){console.log(`No indexed content found for: ${t}`);return}i.sort((e,t)=>e.chunkIndex-t.chunkIndex),console.log(t),console.log(`─`.repeat(60)),console.log(`Chunks: ${i.length} | Type: ${i[0].contentType}`);for(let e of i){let t=e.startLine?` (lines ${e.startLine}-${e.endLine})`:``;console.log(`\nChunk ${e.chunkIndex+1}/${e.totalChunks}${t}`),console.log(e.content)}}}],Y=s(u(import.meta.url));function X(e){let t=e;for(let e=0;e<10;e++){try{let e=c(t,`package.json`);if(r(e)&&JSON.parse(a(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=s(t);if(e===t)break;t=e}return l(e,`..`,`..`,`..`)}const Z=[{name:`status`,description:`Show AI Kit index status and statistics`,run:async()=>{let{isUserInstalled:e,getGlobalDataDir:t,computePartitionKey:n,listWorkspaces:r}=await import(`../../core/dist/index.js`),{existsSync:i}=await import(`node:fs`),a=process.cwd(),o=e(),s=i(l(a,`.vscode`,`mcp.json`)),c,u;if(o&&s)c=`workspace (overrides user-level for this workspace)`,u=l(a,`.aikit-data`);else if(o){let e=n(a);c=i(l(a,`AGENTS.md`))?`user (workspace scaffolded)`:`user (workspace not scaffolded)`,u=l(t(),e)}else c=`workspace`,u=l(a,`.aikit-data`);if(console.log(`AI Kit Status`),console.log(`─`.repeat(40)),console.log(` Mode: ${c}`),console.log(` Data: ${u}`),o&&!s){let e=r();console.log(` Registry: ${e.length} workspace(s) enrolled`)}try{let{store:e}=await J(),t=await e.getStats(),n=await e.listSourcePaths();console.log(` Records: ${t.totalRecords}`),console.log(` Files: ${t.totalFiles}`),console.log(` Indexed: ${t.lastIndexedAt??`Never`}`),console.log(` Backend: ${t.storeBackend}`),console.log(` Model: ${t.embeddingModel}`),console.log(``),console.log(`Content Types:`);for(let[e,n]of Object.entries(t.contentTypeBreakdown))console.log(` ${e}: ${n}`);if(n.length>0){console.log(``),console.log(`Files (${n.length} total):`);for(let e of n.slice(0,20))console.log(` ${e}`);n.length>20&&console.log(` ... and ${n.length-20} more`)}}catch{console.log(``),console.log(" Index not available — run `aikit reindex` to index this workspace.")}o&&!s&&!i(l(a,`AGENTS.md`))&&(console.log(``),console.log(" Action: Run `npx @vpxa/aikit init` to add AGENTS.md and copilot-instructions.md"))}},{name:`reindex`,description:`Re-index the AI Kit index from configured sources`,usage:`aikit reindex [--full]`,run:async e=>{let t=e.includes(`--full`),{store:n,indexer:r,curated:i,config:a}=await J();console.log(`Indexing sources...`);let o=e=>{e.phase===`chunking`&&e.currentFile&&process.stdout.write(`\r [${e.filesProcessed+1}/${e.filesTotal}] ${e.currentFile}`),e.phase===`done`&&process.stdout.write(`
|
|
12
|
+
`)},s;t?(console.log(`Dropping existing index for full reindex...`),s=await r.reindexAll(a,o)):s=await r.index(a,o),console.log(`Done: ${s.filesProcessed} files, ${s.chunksCreated} chunks in ${(s.durationMs/1e3).toFixed(1)}s`),console.log(`Building FTS index...`),await n.createFtsIndex(),console.log(`Re-indexing curated entries...`);let c=await i.reindexAll();console.log(`Curated: ${c.indexed} entries restored`)}},{name:`serve`,description:`Start the MCP server (stdio or HTTP)`,usage:`aikit serve [--transport stdio|http] [--port N]`,run:async e=>{let t=l(X(Y),`packages`,`server`,`dist`,`index.js`),n=F(e,`--transport`,`stdio`),r=F(e,`--port`,`3210`),i=et(t,[],{stdio:n===`stdio`?[`pipe`,`pipe`,`inherit`,`ipc`]:`inherit`,env:{...process.env,AIKIT_TRANSPORT:n,AIKIT_PORT:r}});n===`stdio`&&i.stdin&&i.stdout&&(process.stdin.pipe(i.stdin),i.stdout.pipe(process.stdout)),i.on(`exit`,e=>process.exit(e??0)),process.on(`SIGINT`,()=>i.kill(`SIGINT`)),process.on(`SIGTERM`,()=>i.kill(`SIGTERM`)),await new Promise(()=>{})}},{name:`init`,description:`Initialize AI Kit in the current directory`,usage:`aikit init [--workspace] [--smart] [--force] [--guide]`,run:async e=>{let t=e.includes(`--user`),n=e.includes(`--workspace`),r=e.includes(`--smart`),i=e.includes(`--guide`),a=e.includes(`--force`);if(t&&n&&(console.error(`Cannot use --user and --workspace together.`),process.exit(1)),i){let{guideProject:e}=await import(`./init-BfmAvMGq.js`);await e();return}if(r){let{initSmart:e}=await import(`./init-BfmAvMGq.js`);await e({force:a})}else if(t){let{initUser:e}=await import(`./user-D4p6n-Q5.js`);await e({force:a})}else if(n){let{initProject:e}=await import(`./init-BfmAvMGq.js`);await e({force:a})}else{let{initUser:e}=await import(`./user-D4p6n-Q5.js`);await e({force:a})}}},{name:`check`,description:`Run incremental typecheck and lint`,usage:`aikit check [--cwd <dir>] [--files f1,f2] [--skip-types] [--skip-lint] [--detail efficient|normal|full]`,run:async e=>{let t=F(e,`--cwd`,``).trim()||void 0,n=F(e,`--files`,``),r=F(e,`--detail`,`full`)||`full`,i=n.split(`,`).map(e=>e.trim()).filter(Boolean),a=!1;e.includes(`--skip-types`)&&(e.splice(e.indexOf(`--skip-types`),1),a=!0);let o=!1;e.includes(`--skip-lint`)&&(e.splice(e.indexOf(`--skip-lint`),1),o=!0);let s=await p({cwd:t,files:i.length>0?i:void 0,skipTypes:a,skipLint:o,detail:r});it(s),s.passed||(process.exitCode=1)}},{name:`health`,description:`Run project health checks on the current directory`,usage:`aikit health [path]`,run:async e=>{let t=ve(e.shift());console.log(`Project Health: ${t.path}`),console.log(`─`.repeat(50));for(let e of t.checks){let t=e.status===`pass`?`+`:e.status===`warn`?`~`:`X`;console.log(` [${t}] ${e.name}: ${e.message}`)}console.log(`─`.repeat(50)),console.log(`Score: ${t.score}% — ${t.summary}`)}},{name:`audit`,description:`Run a unified project audit (structure, deps, patterns, health, dead symbols, check)`,usage:`aikit audit [path] [--checks structure,dependencies,patterns,health,dead_symbols,check,entry_points] [--detail efficient|normal|full]`,run:async e=>{let{store:t,embedder:n}=await J(),r=F(e,`--detail`,`efficient`)||`efficient`,i=F(e,`--checks`,``),a=i?i.split(`,`).map(e=>e.trim()):void 0,o=await f(t,n,{path:e.shift()||`.`,checks:a,detail:r});if(o.ok){if(console.log(o.summary),o.next&&o.next.length>0){console.log(`
|
|
13
|
+
Suggested next steps:`);for(let e of o.next)console.log(` → ${e.tool}: ${e.reason}`)}}else console.error(o.error?.message??`Audit failed`),process.exitCode=1}},{name:`guide`,description:`Tool discovery — recommend AI Kit tools for a given goal`,usage:`aikit guide <goal> [--max N]`,run:async e=>{let t=e.indexOf(`--max`),n=5;t!==-1&&t+1<e.length&&(n=Number.parseInt(e.splice(t,2)[1],10)||5);let r=e.join(` `).trim();r||(console.error(`Usage: aikit guide <goal> [--max N]`),console.error(`Example: aikit guide "audit this project"`),process.exit(1));let i=_e(r,n);console.log(`Workflow: ${i.workflow}`),console.log(` ${i.description}\n`),console.log(`Recommended tools:`);for(let e of i.tools){let t=e.suggestedArgs?` ${JSON.stringify(e.suggestedArgs)}`:``;console.log(` ${e.order}. ${e.tool} — ${e.reason}${t}`)}i.alternativeWorkflows.length>0&&console.log(`\nAlternatives: ${i.alternativeWorkflows.join(`, `)}`)}},{name:`replay`,description:`Show recent tool invocation audit trail`,usage:`aikit replay [--last N] [--tool <name>] [--source mcp|cli]`,run:async e=>{let t=je({last:Number.parseInt(e[e.indexOf(`--last`)+1],10)||20,tool:e.includes(`--tool`)?e[e.indexOf(`--tool`)+1]:void 0,source:e.includes(`--source`)?e[e.indexOf(`--source`)+1]:void 0});if(t.length===0){console.log(`No replay entries. Activity is logged when tools are invoked.`);return}console.log(`Replay Log (${t.length} entries)\n`);for(let e of t){let t=e.ts.split(`T`)[1]?.split(`.`)[0]??e.ts,n=e.status===`ok`?`✓`:`✗`;console.log(`${t} ${n} ${e.tool} (${e.durationMs}ms) [${e.source}]`),console.log(` in: ${e.input}`),console.log(` out: ${e.output}`)}Me().catch(()=>{})}},{name:`replay-clear`,description:`Clear the replay audit trail`,run:async()=>{Ae(),console.log(`Replay log cleared.`)}},{name:`dashboard`,description:`Launch web dashboard for knowledge graph visualization`,usage:`aikit dashboard [--port <port>] [--no-open]`,run:async e=>{let t=e.indexOf(`--port`),n=t!==-1&&e[t+1]?Number.parseInt(e[t+1],10):3210,r=Number.isFinite(n)?n:3210,i=e.includes(`--no-open`);console.log(`Starting AI Kit server on port ${r}...`);let{spawn:a}=await import(`node:child_process`),{platform:o}=await import(`node:os`),s=l(X(Y),`packages`,`server`,`dist`,`index.js`),c=a(process.execPath,[s,`--transport`,`http`,`--port`,String(r)],{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,AIKIT_TRANSPORT:`http`,AIKIT_PORT:String(r)}}),u=`http://localhost:${r}/_dashboard/`,d=`http://localhost:${r}/health`,f=!1;for(let e=0;e<30;e+=1){try{if((await fetch(d)).ok){f=!0;break}}catch{}await new Promise(e=>setTimeout(e,1e3))}if(f||(console.error(`Server failed to start within 30 seconds.`),c.kill(),process.exit(1)),console.log(`AI Kit Dashboard: ${u}`),console.log(`Press Ctrl+C to stop.`),!i){let e=o();e===`win32`?a(`cmd`,[`/c`,`start`,``,u],{stdio:`ignore`,detached:!0}).unref():a(e===`darwin`?`open`:`xdg-open`,[u],{stdio:`ignore`,detached:!0}).unref()}let p=()=>{c.kill(),process.exit(0)};process.on(`SIGINT`,p),process.on(`SIGTERM`,p),await new Promise(e=>{c.on(`exit`,()=>e())})}},{name:`settings`,description:`Launch web UI to manage AI Kit configuration and environment variables`,usage:`aikit settings [--port <port>] [--no-open]`,run:async e=>{let t=e.indexOf(`--port`),n=t!==-1&&e[t+1]?Number.parseInt(e[t+1],10):3210,r=Number.isFinite(n)?n:3210,i=e.includes(`--no-open`);console.log(`Starting AI Kit server on port ${r}...`);let{spawn:a}=await import(`node:child_process`),{platform:o}=await import(`node:os`),s=l(X(Y),`packages`,`server`,`dist`,`index.js`),c=a(process.execPath,[s,`--transport`,`http`,`--port`,String(r)],{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,AIKIT_TRANSPORT:`http`,AIKIT_PORT:String(r)}}),u=`http://localhost:${r}/settings/`,d=`http://localhost:${r}/health`,f=!1;for(let e=0;e<30;e+=1){try{if((await fetch(d)).ok){f=!0;break}}catch{}await new Promise(e=>setTimeout(e,1e3))}if(f||(console.error(`Server failed to start within 30 seconds.`),c.kill(),process.exit(1)),console.log(`AI Kit Settings: ${u}`),console.log(`Press Ctrl+C to stop.`),!i){let e=o();e===`win32`?a(`cmd`,[`/c`,`start`,``,u],{stdio:`ignore`,detached:!0}).unref():a(e===`darwin`?`open`:`xdg-open`,[u],{stdio:`ignore`,detached:!0}).unref()}let p=()=>{c.kill(),process.exit(0)};process.on(`SIGINT`,p),process.on(`SIGTERM`,p),await new Promise(e=>{c.on(`exit`,()=>e())})}}];function Ot(e){let t=e;for(let e=0;e<10;e++){try{let e=c(t,`package.json`);if(r(e)&&JSON.parse(a(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=s(t);if(e===t)break;t=e}return l(e,`..`,`..`,`..`)}const kt=[{name:`upgrade`,description:`Upgrade AI Kit agents, prompts, and skills to the latest version (user-level and workspace-level)`,usage:`aikit upgrade`,run:async()=>{let{initUser:n}=await import(`./user-D4p6n-Q5.js`);await n({force:!0});let i=process.cwd(),o=r(l(i,`.github`,`.aikit-scaffold.json`)),c=r(l(i,`.github`,`agents`)),d=r(l(i,`.github`,`prompts`)),f=r(l(i,`.claude`,`commands`));if(o||c||d||f){let{initScaffoldOnly:e}=await import(`./init-BfmAvMGq.js`);await e({force:!0})}if(r(l(i,`.github`,`skills`))){let{smartCopySkills:n}=await import(`./scaffold-BLeqLPMe.js`),r=Ot(s(u(import.meta.url))),o=JSON.parse(a(l(r,`package.json`),`utf-8`)).version;await n(i,r,[...e],o,!0);let{smartCopyFlows:c}=await import(`./scaffold-BLeqLPMe.js`);await c(i,r,[...t],o,!0)}}}],At=[{name:`workset`,description:`Manage saved file sets`,usage:`aikit workset <action> [name] [--files f1,f2] [--description desc]`,run:async e=>{let t=e.shift()?.trim(),n=R(F(e,`--files`,``)),r=F(e,`--description`,``).trim()||void 0,i=e.shift()?.trim();switch(t||(console.error(`Usage: aikit workset <action> [name] [--files f1,f2] [--description desc]`),console.error(`Actions: save, get, list, delete, add, remove`),process.exit(1)),t){case`save`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset save <name> --files f1,f2 [--description desc]`),process.exit(1));let e=Ne(i,n,{description:r});console.log(`Saved workset: ${e.name}`),V(e);return}case`get`:{i||(console.error(`Usage: aikit workset get <name>`),process.exit(1));let e=me(i);if(!e){console.log(`No workset found: ${i}`);return}V(e);return}case`list`:{let e=Te();if(e.length===0){console.log(`No worksets saved.`);return}console.log(`Worksets (${e.length})`),console.log(`─`.repeat(60));for(let t of e)V(t),console.log(``);return}case`delete`:{i||(console.error(`Usage: aikit workset delete <name>`),process.exit(1));let e=se(i);console.log(e?`Deleted workset: ${i}`:`No workset found: ${i}`);return}case`add`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset add <name> --files f1,f2`),process.exit(1));let e=d(i,n);console.log(`Updated workset: ${e.name}`),V(e);return}case`remove`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset remove <name> --files f1,f2`),process.exit(1));let e=Oe(i,n);if(!e){console.log(`No workset found: ${i}`);return}console.log(`Updated workset: ${e.name}`),V(e);return}default:console.error(`Unknown workset action: ${t}`),console.error(`Actions: save, get, list, delete, add, remove`),process.exit(1)}}},{name:`stash`,description:`Persist and retrieve named intermediate values`,usage:`aikit stash <set|get|list|delete|clear> [key] [value]`,run:async e=>{let t=e.shift()?.trim(),n=e.shift()?.trim();switch(t||(console.error(`Usage: aikit stash <set|get|list|delete|clear> [key] [value]`),process.exit(1)),t){case`set`:{n||(console.error(`Usage: aikit stash set <key> <value>`),process.exit(1));let t=e.join(` `),r=t.trim()?``:await L(),i=ze(n,pt(t||r));console.log(`Stored stash entry: ${i.key}`),console.log(` Type: ${i.type}`),console.log(` Stored: ${i.storedAt}`);return}case`get`:{n||(console.error(`Usage: aikit stash get <key>`),process.exit(1));let e=Le(n);if(!e){console.log(`No stash entry found: ${n}`);return}console.log(JSON.stringify(e,null,2));return}case`list`:{let e=Re();if(e.length===0){console.log(`No stash entries saved.`);return}console.log(`Stash entries (${e.length})`),console.log(`─`.repeat(60));for(let t of e)console.log(`${t.key} (${t.type})`),console.log(` Stored: ${t.storedAt}`);return}case`delete`:{n||(console.error(`Usage: aikit stash delete <key>`),process.exit(1));let e=Ie(n);console.log(e?`Deleted stash entry: ${n}`:`No stash entry found: ${n}`);return}case`clear`:{let e=Fe();console.log(`Cleared ${e} stash entr${e===1?`y`:`ies`}.`);return}default:console.error(`Unknown stash action: ${t}`),console.error(`Actions: set, get, list, delete, clear`),process.exit(1)}}},{name:`lane`,description:`Manage verified lanes — isolated file copies for parallel exploration`,usage:`aikit lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]`,run:async e=>{let t=e.shift();if((!t||![`create`,`list`,`status`,`diff`,`merge`,`discard`].includes(t))&&(console.error(`Usage: aikit lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]`),process.exit(1)),t===`list`){let e=Se();if(e.length===0){console.log(`No active lanes.`);return}for(let t of e)console.log(`${t.name} (${t.sourceFiles.length} files, created ${t.createdAt})`);return}let n=e.shift();switch(n||(console.error(`Lane name is required for "${t}".`),process.exit(1)),t){case`create`:{let t=F(e,`--files`,``);t||(console.error(`Usage: aikit lane create <name> --files file1.ts,file2.ts`),process.exit(1));let r=ye(n,t.split(`,`).map(e=>e.trim()));console.log(`Lane "${r.name}" created with ${r.sourceFiles.length} files.`);break}case`status`:{let e=we(n);console.log(`Lane: ${e.name}`),console.log(`Modified: ${e.modified} | Added: ${e.added} | Deleted: ${e.deleted}`);for(let t of e.entries)console.log(` ${t.status.padEnd(10)} ${t.file}`);break}case`diff`:{let e=be(n);console.log(`Lane: ${e.name} — ${e.modified} modified, ${e.added} added, ${e.deleted} deleted`);for(let t of e.entries)t.diff&&(console.log(`\n--- ${t.file} (${t.status})`),console.log(t.diff));break}case`merge`:{let e=Ce(n);console.log(`Merged ${e.filesMerged} files from lane "${e.name}".`);for(let t of e.files)console.log(` ${t}`);break}case`discard`:{let e=xe(n);console.log(e?`Lane "${n}" discarded.`:`Lane "${n}" not found.`);break}}}},{name:`queue`,description:`Manage task queues for sequential agent operations`,usage:`aikit queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]`,run:async e=>{let t=e.shift();if((!t||![`create`,`push`,`next`,`done`,`fail`,`get`,`list`,`clear`,`delete`].includes(t))&&(console.error(`Usage: aikit queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]`),process.exit(1)),t===`list`){let e=O();if(e.length===0){console.log(`No queues.`);return}for(let t of e)console.log(`${t.name} pending:${t.pending} done:${t.done} failed:${t.failed} total:${t.total}`);return}let n=e.shift();switch(n||(console.error(`Queue name is required for "${t}".`),process.exit(1)),t){case`create`:{let e=C(n);console.log(`Queue "${e.name}" created.`);break}case`push`:{let t=De(n,e.join(` `)||`Untitled task`);console.log(`Pushed "${t.title}" (${t.id}) to queue "${n}".`);break}case`next`:{let e=Ee(n);console.log(e?`Next: ${e.title} (${e.id})`:`No pending items in queue "${n}".`);break}case`done`:{let t=e.shift();t||(console.error(`Usage: aikit queue done <name> <id>`),process.exit(1));let r=T(n,t);console.log(`Marked "${r.item.title}" as done.`);break}case`fail`:{let t=e.shift(),r=e.join(` `)||`Unknown error`;t||(console.error(`Usage: aikit queue fail <name> <id> [error message]`),process.exit(1));let i=E(n,t,r);console.log(`Marked "${i.title}" as failed: ${r}`);break}case`get`:{let e=D(n);if(!e){console.log(`Queue "${n}" not found.`);return}console.log(`Queue: ${e.name} (${e.items.length} items)`);for(let t of e.items){let e=t.error?` — ${t.error}`:``;console.log(` ${t.status.padEnd(12)} ${t.id} ${t.title}${e}`)}break}case`clear`:{let e=S(n);console.log(`Cleared ${e} completed/failed items from queue "${n}".`);break}case`delete`:{let e=w(n);console.log(e?`Queue "${n}" deleted.`:`Queue "${n}" not found.`);break}}}}],Q=[...Dt,...Et,...tt,...Tt,...Z,...vt,...gt,...At,..._t,...kt,...Ct];Q.push({name:`help`,description:`Show available commands`,run:async()=>{$()}});async function jt(e){let t=[...e],n=t.shift();if(!n||n===`--help`||n===`-h`){$();return}if(n===`--version`||n===`-v`){let e=l(s(u(import.meta.url)),`..`,`..`,`..`,`package.json`),t=JSON.parse(a(e,`utf-8`));console.log(t.version);return}if(n&&new Set([`--user`,`--workspace`,`--guide`,`--smart`]).has(n)){let e=Q.find(e=>e.name===`init`);if(e){await e.run([n,...t]);return}}let r=Q.find(e=>e.name===n);r||(console.error(`Unknown command: ${n}`),$(),process.exit(1));try{await r.run(t)}finally{let e=wt();e&&await e.store.close()}}function $(){console.log(`@vpxa/aikit — Local-first AI developer toolkit
|
|
14
14
|
`),console.log(`Usage: aikit <command> [options]
|
|
15
|
-
`),console.log(`Commands:`);let e=Math.max(...Q.map(e=>e.name.length));for(let t of Q)console.log(` ${t.name.padEnd(e+2)}${t.description}`);console.log(``),console.log(`Options:`),console.log(` --help, -h Show this help`),console.log(` --version, -v Show version`)}export{
|
|
15
|
+
`),console.log(`Commands:`);let e=Math.max(...Q.map(e=>e.name.length));for(let t of Q)console.log(` ${t.name.padEnd(e+2)}${t.description}`);console.log(``),console.log(`Options:`),console.log(` --help, -h Show this help`),console.log(` --version, -v Show version`)}export{jt as run};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./constants-Nz_Z7XS-.js";import{n as i,t as a}from"./templates-BRWMrqFI.js";import{guideFlows as o,guideScaffold as s,guideSkills as c,smartCopyFlows as l,smartCopyScaffold as u,smartCopySkills as d}from"./scaffold-BLeqLPMe.js";import{appendFileSync as f,existsSync as p,mkdirSync as m,readFileSync as h,unlinkSync as g,writeFileSync as _}from"node:fs";import{basename as v,dirname as y,join as b,resolve as x}from"node:path";import{fileURLToPath as S}from"node:url";import{AIKIT_PATHS as C,EMBEDDING_DEFAULTS as w,isUserInstalled as T}from"../../core/dist/index.js";function E(e){return p(x(e,`.cursor`))?`cursor`:p(x(e,`.claude`))?`claude-code`:p(x(e,`.windsurf`))?`windsurf`:p(x(e,`.zed`))?`zed`:p(x(e,`.idea`))?`intellij`:`copilot`}function D(e){let t=[];return p(x(e,`.cursor`))&&t.push(`cursor`),(p(x(e,`.claude`))||p(x(e,`CLAUDE.md`)))&&t.push(`claude-code`),p(x(e,`.windsurf`))&&t.push(`windsurf`),p(x(e,`.zed`))&&t.push(`zed`),p(x(e,`.idea`))&&t.push(`intellij`),p(x(e,`.gemini`))&&t.push(`gemini-cli`),(p(x(e,`.codex`))||p(x(e,`codex.md`)))&&t.push(`codex-cli`),t.push(`copilot`),[...new Set(t)]}function O(e){return{servers:{[e]:{...t}}}}function k(e){let{type:n,...r}=t;return{mcpServers:{[e]:r}}}function A(e){let{type:n,...r}=t;return{context_servers:{[e]:{...r}}}}const j={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.vscode`),r=x(n,`mcp.json`);p(r)||(m(n,{recursive:!0}),_(r,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created .vscode/mcp.json`))},writeInstructions(e,t){let n=x(e,`.github`),r=x(n,`copilot-instructions.md`);m(n,{recursive:!0}),_(r,i(v(e),t),`utf-8`),console.log(` Updated .github/copilot-instructions.md`)},writeAgentsMd(e,t){_(x(e,`AGENTS.md`),a(v(e),t),`utf-8`),console.log(` Updated AGENTS.md`)}},M={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.mcp.json`);p(n)||(_(n,`${JSON.stringify(k(t),null,2)}\n`,`utf-8`),console.log(` Created .mcp.json`))},writeInstructions(e,t){let n=x(e,`CLAUDE.md`),r=v(e);_(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated CLAUDE.md`)},writeAgentsMd(e,t){}},N={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.cursor`),r=x(n,`mcp.json`);p(r)||(m(n,{recursive:!0}),_(r,`${JSON.stringify(k(t),null,2)}\n`,`utf-8`),console.log(` Created .cursor/mcp.json`))},writeInstructions(e,t){let n=x(e,`.cursor`,`rules`),r=x(n,`aikit.mdc`);m(n,{recursive:!0});let o=v(e);_(r,`${i(o,t)}\n---\n\n${a(o,t)}`,`utf-8`),console.log(` Updated .cursor/rules/aikit.mdc`);let s=x(n,`kb.mdc`);p(s)&&s!==r&&(g(s),console.log(` Removed legacy .cursor/rules/kb.mdc`))},writeAgentsMd(e,t){}},P={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.vscode`),r=x(n,`mcp.json`);p(r)||(m(n,{recursive:!0}),_(r,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created .vscode/mcp.json (Windsurf-compatible)`))},writeInstructions(e,t){let n=x(e,`.windsurfrules`),r=v(e);_(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated .windsurfrules`)},writeAgentsMd(e,t){}},F={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.zed`),r=x(n,`settings.json`);if(m(n,{recursive:!0}),!p(r))_(r,`${JSON.stringify(A(t),null,2)}\n`,`utf-8`),console.log(` Created .zed/settings.json`);else{let e;try{e=JSON.parse(h(r,`utf-8`))}catch{console.warn(` ⚠ .zed/settings.json contains invalid JSON — skipping MCP config merge`);return}e.context_servers?.[t]||(e.context_servers={...e.context_servers,...A(t).context_servers},_(r,`${JSON.stringify(e,null,2)}\n`,`utf-8`),console.log(` Updated .zed/settings.json with context_servers`))}},writeInstructions(e,t){let n=x(e,`.rules`),r=v(e);_(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated .rules`)},writeAgentsMd(e,t){}},I={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`mcp.json`);p(n)||(_(n,`${JSON.stringify(k(t),null,2)}\n`,`utf-8`),console.log(` Created mcp.json`))},writeInstructions(e,t){let n=x(e,`.aiassistant`,`rules`),r=x(n,`aikit.md`);m(n,{recursive:!0});let o=v(e);_(r,`${i(o,t)}\n---\n\n${a(o,t)}`,`utf-8`),console.log(` Updated .aiassistant/rules/aikit.md`)},writeAgentsMd(e,t){}};function L(e){switch(e){case`copilot`:return j;case`claude-code`:return M;case`cursor`:return N;case`windsurf`:return P;case`zed`:return F;case`intellij`:return I;case`gemini-cli`:case`codex-cli`:return j}}const R={serverName:n,sources:[{path:`.`,excludePatterns:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.git/**`,`**/${C.data}/**`,`**/coverage/**`,`**/*.min.js`,`**/package-lock.json`,`**/pnpm-lock.yaml`]}],indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:w.model,dimensions:w.dimensions},store:{backend:`sqlite-vec`,path:C.data},curated:{path:C.aiCurated}};function z(e,t){let n=x(e,`aikit.config.json`);return p(n)&&!t?(console.log(`aikit.config.json already exists. Use --force to overwrite.`),!1):(_(n,`${JSON.stringify(R,null,2)}\n`,`utf-8`),console.log(` Created aikit.config.json`),!0)}function B(e){let t=x(e,`.gitignore`),n=[{dir:`${C.data}/`,label:`AI Kit vector store`},{dir:`${C.state}/`,label:`AI Kit session state`},{dir:`${C.restorePoints}/`,label:`Restore points (codemod/rename undo snapshots)`},{dir:`${C.brainstorm}/`,label:`Brainstorming sessions`},{dir:`${C.handoffs}/`,label:`Handoff documents`}];if(p(t)){let e=h(t,`utf-8`),r=n.filter(t=>!e.includes(t.dir));r.length>0&&(f(t,`\n${r.map(e=>`# ${e.label}\n${e.dir}`).join(`
|
|
2
|
+
`)}\n`,`utf-8`),console.log(` Added ${r.map(e=>e.dir).join(`, `)} to .gitignore`))}else _(t,`${n.map(e=>`# ${e.label}\n${e.dir}`).join(`
|
|
3
|
+
`)}\n`,`utf-8`),console.log(` Created .gitignore with AI Kit entries`)}function V(){return R.serverName}const H=[`decisions`,`patterns`,`conventions`,`troubleshooting`];function U(e){let t=x(e,`.ai`,`curated`);p(t)||(m(t,{recursive:!0}),console.log(` Created .ai/curated/`));for(let e of H){let n=x(t,e);p(n)||m(n,{recursive:!0})}console.log(` Created .ai/curated/{${H.join(`,`)}}/`)}function W(e){switch(e){case`zed`:return`zed`;case`intellij`:return`intellij`;case`claude-code`:return`claude-code`;case`gemini-cli`:return`gemini`;case`codex-cli`:return`codex`;default:return`copilot`}}function G(e){let t=e;for(let e=0;e<10;e++){try{let e=b(t,`package.json`);if(p(e)&&JSON.parse(h(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=y(t);if(e===t)break;t=e}return x(e,`..`,`..`,`..`)}async function K(t){let n=process.cwd();if(!z(n,t.force))return;B(n);let i=V(),a=L(E(n));a.writeMcpConfig(n,i),a.writeInstructions(n,i),a.writeAgentsMd(n,i);let o=G(y(S(import.meta.url))),s=JSON.parse(h(x(o,`package.json`),`utf-8`)).version;await d(n,o,[...e],s,t.force),await l(n,o,[...r],s,t.force);let c=D(n),f=new Set;for(let e of c){let r=W(e);f.has(r)||(f.add(r),await u(n,o,r,s,t.force))}U(n),console.log(`
|
|
4
|
+
AI Kit initialized! Next steps:`),console.log(` aikit reindex Index your codebase`),console.log(` aikit search Search indexed content`),console.log(` aikit serve Start MCP server for IDE integration`),T()&&console.log(`
|
|
5
|
+
Note: User-level AI Kit is also installed. This workspace uses its own local data store.`)}async function q(e){T()?await J(e):await K(e)}async function J(e){let t=process.cwd(),n=V(),i=L(E(t));i.writeInstructions(t,n),i.writeAgentsMd(t,n);let a=G(y(S(import.meta.url))),o=JSON.parse(h(x(a,`package.json`),`utf-8`)).version,s=D(t),c=new Set;for(let n of s){let r=W(n);c.has(r)||(c.add(r),await u(t,a,r,o,e.force))}await l(t,a,[...r],o,e.force),U(t),B(t),console.log(`
|
|
6
|
+
Workspace scaffolded for user-level AI Kit! Files added:`),console.log(` Instruction files (AGENTS.md, copilot-instructions.md, etc.)`),console.log(` .ai/curated/ directories`),console.log(` .github/agents/ & .github/prompts/`),console.log(`
|
|
7
|
+
The user-level AI Kit server will auto-index this workspace when opened in your IDE.`)}async function Y(){let t=process.cwd(),n=D(t),i=G(y(S(import.meta.url))),a=[...await c(t,i,[...e])],l=new Set;for(let e of n){let n=W(e);l.has(n)||(l.add(n),a.push(...await s(t,i,n)))}a.push(...await o(t,i,[...r]));let u={summary:{total:a.length,new:a.filter(e=>e.status===`new`).length,outdated:a.filter(e=>e.status===`outdated`).length,current:a.filter(e=>e.status===`current`).length},files:a};console.log(JSON.stringify(u,null,2))}export{Y as guideProject,K as initProject,J as initScaffoldOnly,q as initSmart};
|
|
@@ -47,8 +47,8 @@ declare const CHUNK_SIZES: {
|
|
|
47
47
|
};
|
|
48
48
|
/** Default embedding config */
|
|
49
49
|
declare const EMBEDDING_DEFAULTS: {
|
|
50
|
-
readonly model: "mixedbread-ai/mxbai-embed-large-v1";
|
|
51
|
-
readonly dimensions:
|
|
50
|
+
readonly model: "mixedbread-ai/mxbai-embed-large-v1"; /** Effective output dimensions (matryoshka truncation from native 1024) */
|
|
51
|
+
readonly dimensions: 512;
|
|
52
52
|
};
|
|
53
53
|
/** Default store config */
|
|
54
54
|
declare const STORE_DEFAULTS: {
|
|
@@ -112,6 +112,8 @@ interface KnowledgeRecord {
|
|
|
112
112
|
endLine: number;
|
|
113
113
|
/** File hash for incremental indexing */
|
|
114
114
|
fileHash: string;
|
|
115
|
+
/** SHA-256 of normalized chunk content for dedup */
|
|
116
|
+
contentHash?: string;
|
|
115
117
|
/** ISO timestamp when this record was created/updated */
|
|
116
118
|
indexedAt: string;
|
|
117
119
|
/** How this record was created */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{basename as e,extname as t,join as n,resolve as r}from"node:path";import{createHash as i}from"node:crypto";import{appendFileSync as a,closeSync as o,constants as s,existsSync as c,mkdirSync as l,openSync as ee,readFileSync as u,readdirSync as d,renameSync as f,statSync as te,unlinkSync as p,writeFileSync as m}from"node:fs";import{homedir as h}from"node:os";const g={ai:`.ai`,aiContext:`.ai/context`,aiCurated:`.ai/curated`,restorePoints:`.ai/restore-points`,data:`.aikit-data`,state:`.aikit-state`,logs:`.aikit-state/logs`,brainstorm:`.brainstorm`,handoffs:`.handoffs`},_={root:`.aikit-data`,registry:`registry.json`},v={markdown:{max:1500,min:100},code:{max:2e3,min:50},config:{max:3e3,min:50},default:{max:1500,min:100,overlap:200}},y={model:`mixedbread-ai/mxbai-embed-large-v1`,dimensions:
|
|
1
|
+
import{basename as e,extname as t,join as n,resolve as r}from"node:path";import{createHash as i}from"node:crypto";import{appendFileSync as a,closeSync as o,constants as s,existsSync as c,mkdirSync as l,openSync as ee,readFileSync as u,readdirSync as d,renameSync as f,statSync as te,unlinkSync as p,writeFileSync as m}from"node:fs";import{homedir as h}from"node:os";const g={ai:`.ai`,aiContext:`.ai/context`,aiCurated:`.ai/curated`,restorePoints:`.ai/restore-points`,data:`.aikit-data`,state:`.aikit-state`,logs:`.aikit-state/logs`,brainstorm:`.brainstorm`,handoffs:`.handoffs`},_={root:`.aikit-data`,registry:`registry.json`},v={markdown:{max:1500,min:100},code:{max:2e3,min:50},config:{max:3e3,min:50},default:{max:1500,min:100,overlap:200}},y={model:`mixedbread-ai/mxbai-embed-large-v1`,dimensions:512},b={backend:`sqlite-vec`,path:g.data,tableName:`knowledge`},x={maxFileSizeBytes:1e6,maxCuratedFileSizeBytes:5e4},S={maxResults:10,minScore:.25},C=/^[a-z][a-z0-9-]*$/,w=[`decisions`,`patterns`,`troubleshooting`,`conventions`,`architecture`],T={".ts":`code-typescript`,".tsx":`code-typescript`,".mts":`code-typescript`,".cts":`code-typescript`,".js":`code-javascript`,".jsx":`code-javascript`,".mjs":`code-javascript`,".cjs":`code-javascript`,".py":`code-python`,".json":`config-json`,".yaml":`config-yaml`,".yml":`config-yaml`,".toml":`config-toml`,".env":`config-env`,".md":`markdown`,".mdx":`markdown`},E=[/\.test\.[jt]sx?$/,/\.spec\.[jt]sx?$/,/(^|\/)__tests__\//,/(^|\/)test\//,/(^|\/)tests\//,/(^|\/)spec\//,/(^|\/)fixtures\//],ne=[/\.stack\.[jt]s$/,/(^|\/)stacks\//,/(^|\/)constructs\//,/cdk\.json$/];function re(n){let r=t(n).toLowerCase(),i=e(n).toLowerCase();return n.includes(`${g.aiContext}/`)?`produced-knowledge`:n.includes(`${g.aiCurated}/`)?`curated-knowledge`:E.some(e=>e.test(n))?`test-code`:ne.some(e=>e.test(n))?`cdk-stack`:r in T?T[r]:i.startsWith(`.env`)?`config-env`:[`.go`,`.rs`,`.java`,`.rb`,`.php`,`.sh`,`.ps1`,`.sql`,`.graphql`,`.proto`,`.css`,`.scss`,`.less`,`.html`,`.htm`,`.vue`,`.svelte`,`.astro`,`.hbs`,`.ejs`,`.svg`].includes(r)?`code-other`:`unknown`}const D={"code-typescript":`source`,"code-javascript":`source`,"code-python":`source`,"code-other":`source`,"cdk-stack":`source`,"test-code":`test`,markdown:`documentation`,documentation:`documentation`,"curated-knowledge":`documentation`,"produced-knowledge":`documentation`,"config-json":`config`,"config-yaml":`config`,"config-toml":`config`,"config-env":`config`,unknown:`source`};function ie(e){return D[e]??`source`}function O(e){return Object.entries(D).filter(([,t])=>t===e).map(([e])=>e)}var k=class extends Error{constructor(e,t,n){super(e,n===void 0?void 0:{cause:n}),this.code=t,this.name=`AikitError`}},A=class extends k{constructor(e,t){super(e,`EMBEDDING_ERROR`,t),this.name=`EmbeddingError`}},j=class extends k{constructor(e,t){super(e,`STORE_ERROR`,t),this.name=`StoreError`}},M=class extends k{constructor(e,t){super(e,`INDEX_ERROR`,t),this.name=`IndexError`}},N=class extends k{constructor(e,t){super(e,`CONFIG_ERROR`,t),this.name=`ConfigError`}};function P(){return process.env.AIKIT_GLOBAL_DATA_DIR??r(h(),_.root)}function F(t){let n=r(t);return`${e(n).toLowerCase().replace(/[^a-z0-9-]/g,`-`)||`workspace`}-${i(`sha256`).update(n).digest(`hex`).slice(0,8)}`}function I(){let e=r(P(),_.registry);if(!c(e))return{version:1,workspaces:{}};let t=u(e,`utf-8`);try{return JSON.parse(t)}catch{return{version:1,workspaces:{}}}}function L(e,t=5e3){let n=`${e}.lock`,r=Date.now()+t,i=10;for(;Date.now()<r;)try{let e=ee(n,s.O_CREAT|s.O_EXCL|s.O_WRONLY);return m(e,`${process.pid}\n`),o(e),n}catch(e){if(e.code!==`EEXIST`)throw e;try{let{mtimeMs:e}=te(n);if(Date.now()-e>3e4){p(n);continue}}catch{}let t=new SharedArrayBuffer(4);Atomics.wait(new Int32Array(t),0,0,i),i=Math.min(i*2,200)}throw Error(`Failed to acquire registry lock after ${t}ms`)}function R(e){try{p(e)}catch{}}function z(e){let t=P();l(t,{recursive:!0});let n=r(t,_.registry),i=L(n);try{let t=`${n}.tmp`;m(t,JSON.stringify(e,null,2),`utf-8`),f(t,n)}finally{R(i)}}function B(e){let t=I(),n=F(e),i=new Date().toISOString();return t.workspaces[n]?t.workspaces[n].lastAccessedAt=i:t.workspaces[n]={partition:n,workspacePath:r(e),registeredAt:i,lastAccessedAt:i},l(U(n),{recursive:!0}),z(t),t.workspaces[n]}function V(e){let t=I(),n=F(e);return t.workspaces[n]}function H(){let e=I();return Object.values(e.workspaces)}function U(e){return r(P(),e)}function W(){return c(r(P(),_.registry))}function G(e){return W()?r(U(B(e).partition),`state`):r(e,g.state)}const K={debug:0,info:1,warn:2,error:3},q=[];let J=process.env.AIKIT_LOG_LEVEL??`info`,Y=process.env.AIKIT_LOG_FILE_SINK===`true`||process.env.AIKIT_LOG_FILE_SINK!==`false`&&!process.env.VITEST&&process.env.NODE_ENV!==`test`;function ae(){return Y?process.env.VITEST||process.env.NODE_ENV===`test`?process.env.AIKIT_LOG_FILE_SINK===`true`:!0:!1}let X;function Z(){return X||=n(G(process.cwd()),`logs`),X}function oe(e){let t=e.toISOString().slice(0,10);return n(Z(),`${t}.jsonl`)}let Q=0;function se(){let e=Date.now();if(!(e-Q<36e5)){Q=e;try{let t=Z(),r=new Date(e-30*864e5).toISOString().slice(0,10);for(let e of d(t))if(e.endsWith(`.jsonl`)&&e.slice(0,10)<r)try{p(n(t,e))}catch{}}catch{}}}function ce(e,t){try{l(Z(),{recursive:!0}),a(oe(t),`${e}\n`),se()}catch{}}function le(e){J=e}function ue(){return J}function de(e){Y=e}function fe(){X=void 0}function pe(e){if(e instanceof Error){let t={error:e.message};return e.stack&&(t.stack=e.stack),e.cause!==void 0&&(t.cause=e.cause instanceof Error?e.cause.message:String(e.cause)),t}return{error:String(e)}}function $(e){return q.push(e),()=>{let t=q.indexOf(e);t>=0&&q.splice(t,1)}}function me(e){function t(t,n,r){if(K[t]<K[J])return;let i=new Date,a={ts:i.toISOString(),level:t,component:e,msg:n,...r},o=JSON.stringify(a);console.error(o);for(let i of q)try{i({level:t,component:e,message:n,data:r})}catch{}ae()&&(t===`warn`||t===`error`)&&ce(o,i)}return{debug:(e,n)=>t(`debug`,e,n),info:(e,n)=>t(`info`,e,n),warn:(e,n)=>t(`warn`,e,n),error:(e,n)=>t(`error`,e,n)}}const he=[`indexed`,`curated`,`produced`],ge=[`source`,`documentation`,`test`,`config`,`generated`],_e=[`auto`,`manual`,`smart`],ve=[`efficient`,`normal`,`full`],ye=[`documentation`,`code-typescript`,`code-javascript`,`code-python`,`code-other`,`config-json`,`config-yaml`,`config-toml`,`config-env`,`test-code`,`cdk-stack`,`markdown`,`curated-knowledge`,`produced-knowledge`,`unknown`];export{_ as AIKIT_GLOBAL_PATHS,g as AIKIT_PATHS,k as AikitError,C as CATEGORY_PATTERN,v as CHUNK_SIZES,ye as CONTENT_TYPES,N as ConfigError,w as DEFAULT_CATEGORIES,y as EMBEDDING_DEFAULTS,A as EmbeddingError,x as FILE_LIMITS,_e as INDEX_MODES,M as IndexError,he as KNOWLEDGE_ORIGINS,S as SEARCH_DEFAULTS,ge as SOURCE_TYPES,b as STORE_DEFAULTS,j as StoreError,ve as TOKEN_BUDGETS,$ as addLogListener,F as computePartitionKey,ie as contentTypeToSourceType,me as createLogger,re as detectContentType,P as getGlobalDataDir,ue as getLogLevel,U as getPartitionDir,W as isUserInstalled,H as listWorkspaces,I as loadRegistry,V as lookupWorkspace,B as registerWorkspace,fe as resetLogDir,G as resolveStateDir,z as saveRegistry,pe as serializeError,de as setFileSinkEnabled,le as setLogLevel,O as sourceTypeContentTypes};
|
|
@@ -28,12 +28,20 @@ declare class OnnxEmbedder implements IEmbedder {
|
|
|
28
28
|
private pipe;
|
|
29
29
|
readonly dimensions: number;
|
|
30
30
|
readonly modelId: string;
|
|
31
|
+
private readonly nativeDim;
|
|
31
32
|
private readonly queryPrefix;
|
|
32
33
|
constructor(options?: {
|
|
33
34
|
model?: string;
|
|
34
35
|
dimensions?: number;
|
|
36
|
+
nativeDim?: number;
|
|
35
37
|
queryPrefix?: string;
|
|
36
38
|
});
|
|
39
|
+
/**
|
|
40
|
+
* Matryoshka truncation: slice to targetDim and re-normalize.
|
|
41
|
+
* Only applied when targetDim < nativeDim.
|
|
42
|
+
* Modular — swap this function to change truncation strategy.
|
|
43
|
+
*/
|
|
44
|
+
private truncateAndRenorm;
|
|
37
45
|
private detectQueryPrefix;
|
|
38
46
|
initialize(): Promise<void>;
|
|
39
47
|
private isCorruptionError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{rm as e}from"node:fs/promises";import{homedir as t}from"node:os";import{join as n}from"node:path";import{EMBEDDING_DEFAULTS as r}from"../../core/dist/index.js";import{env as i,pipeline as a}from"@huggingface/transformers";i.cacheDir=n(t(),`.cache`,`huggingface`,`transformers-js`);var o=class{pipe=null;dimensions;modelId;queryPrefix;constructor(e){this.modelId=e?.model??r.model,this.dimensions=e?.dimensions??r.dimensions,this.queryPrefix=e?.queryPrefix??this.detectQueryPrefix(this.modelId)}detectQueryPrefix(e){let t=e.toLowerCase();return t.includes(`bge`)||t.includes(`mxbai-embed`)?`Represent this sentence for searching relevant passages: `:t.includes(`/e5-`)||t.includes(`multilingual-e5`)?`query: `:``}async initialize(){if(!this.pipe)try{this.pipe=await a(`feature-extraction`,this.modelId,{dtype:`q8`})}catch(r){let o=r.message?.toLowerCase()??``;if(this.isCorruptionError(o)){let r=n(i.cacheDir??n(t(),`.cache`,`huggingface`,`transformers-js`),this.modelId);console.error(`[aikit:auto-heal] Detected corrupted model cache for "${this.modelId}". Clearing cache at ${r} and retrying download...`);try{await e(r,{recursive:!0,force:!0})}catch{}try{this.pipe=await a(`feature-extraction`,this.modelId,{dtype:`q8`}),console.error(`[aikit:auto-heal] Model "${this.modelId}" re-downloaded successfully.`);return}catch(e){throw Error(`Failed to initialize embedding model "${this.modelId}" after auto-heal: ${e.message}`)}}throw Error(`Failed to initialize embedding model "${this.modelId}": ${r.message}`)}}isCorruptionError(e){return[`protobuf`,`invalid model`,`invalid onnx`,`unexpected end`,`unexpected token`,`failed to load`,`checksum`,`corrupt`,`could not load`,`onnx`,`malformed`].some(t=>e.includes(t))}async shutdown(){this.pipe=null}async embed(e){this.pipe||await this.initialize();let t=await this.pipe?.(e,{pooling:`mean`,normalize:!0});if(!t)throw Error(`Embedding pipeline returned no output`);
|
|
1
|
+
import{rm as e}from"node:fs/promises";import{homedir as t}from"node:os";import{join as n}from"node:path";import{EMBEDDING_DEFAULTS as r}from"../../core/dist/index.js";import{env as i,pipeline as a}from"@huggingface/transformers";i.cacheDir=n(t(),`.cache`,`huggingface`,`transformers-js`);var o=class{pipe=null;dimensions;modelId;nativeDim;queryPrefix;constructor(e){if(this.modelId=e?.model??r.model,this.nativeDim=e?.nativeDim??1024,this.dimensions=e?.dimensions??r.dimensions,this.dimensions>this.nativeDim)throw Error(`Configured dimensions (${this.dimensions}) exceeds model native output (${this.nativeDim}). Matryoshka truncation cannot upscale — dimensions must be <= nativeDim.`);this.queryPrefix=e?.queryPrefix??this.detectQueryPrefix(this.modelId)}truncateAndRenorm(e){if(this.dimensions>=this.nativeDim)return e;let t=e.subarray(0,this.dimensions),n=0;for(let e=0;e<t.length;e++)n+=t[e]*t[e];if(n=Math.sqrt(n),n===0)return new Float32Array(this.dimensions);let r=new Float32Array(this.dimensions);for(let e=0;e<this.dimensions;e++)r[e]=t[e]/n;return r}detectQueryPrefix(e){let t=e.toLowerCase();return t.includes(`bge`)||t.includes(`mxbai-embed`)?`Represent this sentence for searching relevant passages: `:t.includes(`/e5-`)||t.includes(`multilingual-e5`)?`query: `:``}async initialize(){if(!this.pipe)try{this.pipe=await a(`feature-extraction`,this.modelId,{dtype:`q8`})}catch(r){let o=r.message?.toLowerCase()??``;if(this.isCorruptionError(o)){let r=n(i.cacheDir??n(t(),`.cache`,`huggingface`,`transformers-js`),this.modelId);console.error(`[aikit:auto-heal] Detected corrupted model cache for "${this.modelId}". Clearing cache at ${r} and retrying download...`);try{await e(r,{recursive:!0,force:!0})}catch{}try{this.pipe=await a(`feature-extraction`,this.modelId,{dtype:`q8`}),console.error(`[aikit:auto-heal] Model "${this.modelId}" re-downloaded successfully.`);return}catch(e){throw Error(`Failed to initialize embedding model "${this.modelId}" after auto-heal: ${e.message}`)}}throw Error(`Failed to initialize embedding model "${this.modelId}": ${r.message}`)}}isCorruptionError(e){return[`protobuf`,`invalid model`,`invalid onnx`,`unexpected end`,`unexpected token`,`failed to load`,`checksum`,`corrupt`,`could not load`,`onnx`,`malformed`].some(t=>e.includes(t))}async shutdown(){this.pipe=null}async embed(e){this.pipe||await this.initialize();let t=await this.pipe?.(e,{pooling:`mean`,normalize:!0});if(!t)throw Error(`Embedding pipeline returned no output`);let n=new Float32Array(t.data);return this.truncateAndRenorm(n)}async embedQuery(e){return this.embed(this.queryPrefix+e)}async embedBatch(e,t=64){if(e.length===0)return[];this.pipe||await this.initialize();let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t),a=await this.pipe?.(i,{pooling:`mean`,normalize:!0});if(!a)throw Error(`Embedding pipeline returned no output`);if(i.length===1){let e=new Float32Array(a.data);n.push(this.truncateAndRenorm(e))}else for(let e=0;e<i.length;e++){let t=e*this.nativeDim,r=a.data.slice(t,t+this.nativeDim);n.push(this.truncateAndRenorm(new Float32Array(r)))}}return n}};export{o as OnnxEmbedder};
|
|
@@ -99,6 +99,7 @@ interface IndexResult {
|
|
|
99
99
|
filesProcessed: number;
|
|
100
100
|
filesSkipped: number;
|
|
101
101
|
chunksCreated: number;
|
|
102
|
+
chunksDeduped: number;
|
|
102
103
|
filesRemoved: number;
|
|
103
104
|
durationMs: number;
|
|
104
105
|
}
|
|
@@ -112,6 +113,12 @@ declare class IncrementalIndexer {
|
|
|
112
113
|
/** Whether an index operation is currently in progress. */
|
|
113
114
|
get isIndexing(): boolean;
|
|
114
115
|
constructor(embedder: IEmbedder, store: IKnowledgeStore);
|
|
116
|
+
/**
|
|
117
|
+
* Normalize chunk text for content-based dedup hashing.
|
|
118
|
+
* Strips the file path header, lowercases, collapses whitespace.
|
|
119
|
+
* Modular — swap this to change dedup normalization strategy.
|
|
120
|
+
*/
|
|
121
|
+
private normalizeChunkText;
|
|
115
122
|
/** Set the graph store for auto-population during indexing and cleanup on re-index. */
|
|
116
123
|
setGraphStore(graphStore: IGraphStore): void;
|
|
117
124
|
/** Set the hash cache for faster incremental checks. */
|
|
@@ -161,6 +168,7 @@ declare class SmartIndexScheduler {
|
|
|
161
168
|
private readonly config;
|
|
162
169
|
private readonly store?;
|
|
163
170
|
private trickleTimer;
|
|
171
|
+
private stopped;
|
|
164
172
|
private readonly trickleIntervalMs;
|
|
165
173
|
private readonly batchSize;
|
|
166
174
|
private readonly priorityQueue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash as e}from"node:crypto";import{existsSync as t,readFileSync as n,realpathSync as r,statSync as i,writeFileSync as a}from"node:fs";import{lstat as o,readFile as s,readdir as c,stat as l}from"node:fs/promises";import{dirname as u,extname as d,join as f,relative as p,resolve as m}from"node:path";import{AIKIT_PATHS as h,FILE_LIMITS as g,createLogger as _,detectContentType as v,serializeError as y}from"../../core/dist/index.js";import{minimatch as b}from"minimatch";import{availableParallelism as x,loadavg as S}from"node:os";import{createChunkerSync as C}from"../../chunker/dist/index.js";function w(t){return e(`sha256`).update(t).digest(`hex`).slice(0,16)}function T(t,n){let r=`${t}:${n}`;return e(`sha256`).update(r).digest(`hex`).slice(0,16)}const E=_(`indexer`);var D=class e{static BINARY_EXTENSIONS=new Set(`.node,.so,.dylib,.dll,.wasm,.bin,.exe,.png,.jpg,.jpeg,.gif,.bmp,.ico,.webp,.svg,.mp3,.mp4,.wav,.avi,.mov,.flac,.zip,.gz,.tar,.bz2,.7z,.rar,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.ttf,.otf,.woff,.woff2,.eot,.pyc,.class,.o,.obj,.a,.lib`.split(`,`));async crawl(e){let t=[],n=new Set;return await this.walkDir(e.rootDir,e.rootDir,e.excludePatterns,t,n),t}async walkDir(t,n,i,a,u){let m;try{m=await c(t,{withFileTypes:!0})}catch(e){let n=e.code;(n===`EACCES`||n===`EPERM`)&&E.warn(`Permission denied, skipping directory`,{dir:t});return}for(let c of m){let m=f(t,c.name),_=p(n,m).replace(/\\/g,`/`);if(!this.isExcluded(_,i)){if(c.isDirectory()){if(c.name.startsWith(`.`)&&!(c.name===h.ai.slice(1)&&_.startsWith(h.ai)))continue;try{if((await o(m)).isSymbolicLink())continue}catch{continue}let e;try{e=r(m)}catch{continue}if(u.has(e))continue;u.add(e),await this.walkDir(m,n,i,a,u)}else if(c.isFile()){let t=d(c.name).toLowerCase();if(e.BINARY_EXTENSIONS.has(t))continue;try{if((await l(m)).size>g.maxFileSizeBytes)continue;let e=await s(m,`utf-8`);if(e.includes(`\0`))continue;a.push({relativePath:_,absolutePath:m,content:e,extension:t})}catch{}}}}}isExcluded(e,t){return t.some(t=>b(e,t,{dot:!0}))}};const O=new Set([`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`]),k=[{pattern:/^export\s+(?:async\s+)?function\s+(\w+)/gm,kind:`function`,exported:!0},{pattern:/^export\s+(?:default\s+)?class\s+(\w+)/gm,kind:`class`,exported:!0},{pattern:/^export\s+interface\s+(\w+)/gm,kind:`interface`,exported:!0},{pattern:/^export\s+type\s+(\w+)/gm,kind:`type`,exported:!0},{pattern:/^export\s+(?:const|let)\s+(\w+)/gm,kind:`const`,exported:!0},{pattern:/^export\s+enum\s+(\w+)/gm,kind:`enum`,exported:!0},{pattern:/^(?:async\s+)?function\s+(\w+)/gm,kind:`function`,exported:!1},{pattern:/^class\s+(\w+)/gm,kind:`class`,exported:!1},{pattern:/^interface\s+(\w+)/gm,kind:`interface`,exported:!1},{pattern:/^type\s+(\w+)/gm,kind:`type`,exported:!1},{pattern:/^enum\s+(\w+)/gm,kind:`enum`,exported:!1}],A=[/import\s+(?:(?:type\s+)?(?:(?:\{[^}]*\}|[\w*]+)\s+from\s+)?)['"]([^'"]+)['"]/g,/import\(\s*['"]([^'"]+)['"]\s*\)/g,/require\(\s*['"]([^'"]+)['"]\s*\)/g];function j(t,n,r){return e(`sha256`).update(`${t}:${n}:${r}`).digest(`hex`).slice(0,16)}function M(t,n,r){return e(`sha256`).update(`${t}-${r}-${n}`).digest(`hex`).slice(0,16)}function N(e,t){return f(u(t),e).replace(/\\/g,`/`).replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/,``)}function P(e){return e.replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/,``)}function F(e,t,n){let r=d(t).toLowerCase();if(!O.has(r))return{nodes:[],edges:[]};let i=[],a=[],o=new Date().toISOString(),s=new Set,c=P(t),l=j(`module`,c,c);i.push({id:l,type:`module`,name:t,properties:{ext:r},sourcePath:t,createdAt:o});for(let{pattern:n,kind:r,exported:c}of k){let u=new RegExp(n.source,n.flags),d;for(;(d=u.exec(e))!==null;){let e=d[1],n=`${r}:${e}`;if(s.has(n))continue;s.add(n);let u=j(r,e,t);i.push({id:u,type:r,name:e,properties:{exported:c},sourcePath:t,createdAt:o}),a.push({id:M(l,u,`defines`),fromId:l,toId:u,type:`defines`,weight:c?1:.5})}}let u=n?.workspacePackages,f=new Set;for(let n of A){let r=new RegExp(n.source,n.flags),i;for(;(i=r.exec(e))!==null;){let e=i[1];if(f.has(e))continue;let n;if(e.startsWith(`.`))n=N(e,t);else if(u){let t=e.startsWith(`@`)?e.split(`/`).slice(0,2).join(`/`):e.split(`/`)[0],r=u.get(t);if(!r)continue;n=r}else continue;f.add(e);let r=P(n),o=j(`module`,r,r);a.push({id:M(l,o,`imports`),fromId:l,toId:o,type:`imports`,properties:{source:e}})}}return{nodes:i,edges:a}}const I=_(`hash-cache`);var L=class{cache;filePath;dirty=!1;constructor(e){this.filePath=m(e,`file-hashes.json`),this.cache=new Map}load(){if(t(this.filePath))try{let e=n(this.filePath,`utf-8`),t=JSON.parse(e);this.cache=new Map(Object.entries(t)),I.info(`Hash cache loaded`,{entries:this.cache.size})}catch(e){I.warn(`Hash cache load failed, starting fresh`,{err:e}),this.cache=new Map}}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t),this.dirty=!0}delete(e){this.cache.delete(e)&&(this.dirty=!0)}flush(){if(this.dirty)try{let e={};for(let[t,n]of this.cache)e[t]=n;a(this.filePath,JSON.stringify(e),`utf-8`),this.dirty=!1}catch(e){I.warn(`Hash cache flush failed`,{err:e})}}clear(){this.cache.clear(),this.dirty=!0,this.flush()}get size(){return this.cache.size}};const R=_(`indexer`),z=()=>new Promise(e=>setImmediate(e));async function B(e,t,n,r){let i=0;async function a(){for(;i<e.length;){let n=i++;try{await t(e[n])}catch(t){r?.(e[n],t)}n%10==0&&await z()}}await Promise.all(Array.from({length:Math.min(n,e.length)},()=>a()))}function V(e){let t=x(),n=S()[0]/t;return n>1.5?2:n>1?Math.max(2,Math.floor(e/2)):e}const H=Math.max(2,Math.min(4,Math.floor(x()*.5)));var U=class{crawler;indexing=!1;graphStore;hashCache;get isIndexing(){return this.indexing}constructor(e,t){this.embedder=e,this.store=t,this.crawler=new D}setGraphStore(e){this.graphStore=e}setHashCache(e){this.hashCache=e}async index(e,t){if(this.indexing)throw Error(`Indexing is already in progress`);this.indexing=!0;try{return await this.doIndex(e,t,{})}finally{this.indexing=!1}}async getChangedFiles(e){let t=e.indexing.concurrency??H,n=await this.crawlSources(e),{filesToProcess:r}=await this.planIndexWork(n,t,{});return r.map(e=>e.relativePath)}async indexFiles(e,t,n){if(this.indexing)throw Error(`Indexing is already in progress`);this.indexing=!0;try{return await this.doIndexFiles(e,t,n)}finally{this.indexing=!1}}async doIndex(e,t,n={}){let r=Date.now(),i=e.indexing.concurrency??H;t?.({phase:`crawling`,filesTotal:0,filesProcessed:0,chunksTotal:0,chunksProcessed:0});let a=await this.crawlSources(e),{filesToProcess:o,filesSkipped:s,pathsToRemove:c}=await this.planIndexWork(a,i,{skipHashCheck:n.skipHashCheck}),{filesProcessed:l,chunksCreated:u}=await this.processFiles(a,o,i,t,{graphCleared:n.graphCleared}),d=await this.cleanupRemovedFiles(c,i,o.length,l,u,t);return this.hashCache?.flush(),t?.({phase:`done`,filesTotal:o.length,filesProcessed:l,chunksTotal:u,chunksProcessed:u}),{filesProcessed:l,filesSkipped:s,chunksCreated:u,filesRemoved:d,durationMs:Date.now()-r}}async doIndexFiles(e,t,n){let r=Date.now(),i=e.indexing.concurrency??H,a=new Set(t);if(a.size===0)return{filesProcessed:0,filesSkipped:0,chunksCreated:0,filesRemoved:0,durationMs:Date.now()-r};n?.({phase:`crawling`,filesTotal:0,filesProcessed:0,chunksTotal:0,chunksProcessed:0});let o=await this.crawlSources(e),{filesToProcess:s,filesSkipped:c}=await this.planIndexWork(o,i,{requestedPaths:a}),{filesProcessed:l,chunksCreated:u}=await this.processFiles(o,s,i,n,{});return this.hashCache?.flush(),n?.({phase:`done`,filesTotal:s.length,filesProcessed:l,chunksTotal:u,chunksProcessed:u}),{filesProcessed:l,filesSkipped:c,chunksCreated:u,filesRemoved:0,durationMs:Date.now()-r}}async crawlSources(e){return(await Promise.all(e.sources.map(e=>this.crawler.crawl({rootDir:e.path,excludePatterns:e.excludePatterns})))).flat()}async planIndexWork(e,t,n){let r=n.requestedPaths,i=r?e.filter(e=>r.has(e.relativePath)):e;if(n.skipHashCheck)return{filesToProcess:i,filesSkipped:0,pathsToRemove:[]};let a=r?[]:await this.getPathsToRemove(e),o=0,s=[];return await B(i,async e=>{let t=w(e.content);if(this.hashCache){if(this.hashCache.get(e.relativePath)===t){o++;return}}else{let n=await this.store.getBySourcePath(e.relativePath);if(n.length>0&&n[0].fileHash===t){o++;return}}s.push(e)},V(t),(e,t)=>R.error(`Hash check failed`,{sourcePath:e.relativePath,...y(t)})),{filesToProcess:s,filesSkipped:o,pathsToRemove:a}}async getPathsToRemove(e){let t=await this.store.listSourcePaths(),n=new Set(e.map(e=>e.relativePath));return t.filter(e=>!n.has(e)&&!e.startsWith(`${h.aiCurated}/`))}async buildWorkspacePackageMap(e){let t=new Map;for(let n of e)if(n.relativePath.endsWith(`package.json`))try{let e=JSON.parse(n.content);if(typeof e.name!=`string`||e.name.length===0)continue;let r=n.relativePath===`package.json`?``:n.relativePath.replace(/\/package\.json$/,``),i=``;if(typeof e.exports==`string`)i=e.exports;else if(e.exports&&typeof e.exports==`object`){let t=e.exports,n=t[`.`]??t;if(typeof n==`string`)i=n;else if(n&&typeof n==`object`){let e=n,t=e.import??e.module??e.default??e.require;typeof t==`string`&&(i=t)}}!i&&typeof e.module==`string`&&(i=e.module),!i&&typeof e.main==`string`&&(i=e.main);let a=i.replace(/^\.\//,``).replace(/^dist\//,`src/`).replace(/\.(ts|js|mjs|cjs|tsx|jsx)$/,``),o=a?r?`${r}/${a}`:a:r?`${r}/src/index`:`src/index`;t.set(e.name,o)}catch{}return t}async processFiles(e,t,n,r,i={}){let a=0,o=0,s=t.length,c=this.graphStore?await this.buildWorkspacePackageMap(e):void 0,l=[],u=[],d=0,f=[],p=[],m=new Map,h=0,g=async()=>{if(f.length===0)return;let e=f,t=p,n=m;f=[],p=[],m=new Map,h=0,await this.store.upsert(e,t);for(let[e,t]of n)this.hashCache?.set(e,t)},_=async()=>{if(this.graphStore){try{l.length>0&&await this.graphStore.upsertNodes(l),u.length>0&&await this.graphStore.upsertEdges(u)}catch(e){R.warn(`Graph batch flush failed`,y(e))}l=[],u=[],d=0}};return await B(t,async e=>{r?.({phase:`chunking`,filesTotal:s,filesProcessed:a,chunksTotal:o,chunksProcessed:o,currentFile:e.relativePath});let t=v(e.relativePath),n=C(e.extension).chunk(e.content,{sourcePath:e.relativePath,contentType:t});if(n.length===0)return;r?.({phase:`embedding`,filesTotal:s,filesProcessed:a,chunksTotal:o+n.length,chunksProcessed:o,currentFile:e.relativePath});let b=await this.embedder.embedBatch(n.map(e=>e.text)),x=w(e.content),S=n.map((t,n)=>({id:T(e.relativePath,n),content:t.text,sourcePath:t.sourcePath,contentType:t.contentType,headingPath:t.headingPath,chunkIndex:t.chunkIndex,totalChunks:t.totalChunks,startLine:t.startLine,endLine:t.endLine,fileHash:x,indexedAt:new Date().toISOString(),origin:`indexed`,tags:[],version:1}));if(r?.({phase:`storing`,filesTotal:s,filesProcessed:a,chunksTotal:o+n.length,chunksProcessed:o,currentFile:e.relativePath}),f.push(...S),p.push(...b),m.set(e.relativePath,x),h++,h>=20&&await g(),this.graphStore)try{i.graphCleared||await this.graphStore.deleteBySourcePath(e.relativePath);let t=F(e.content,e.relativePath,{workspacePackages:c});t.nodes.length>0&&l.push(...t.nodes),t.edges.length>0&&u.push(...t.edges),d++,d>=50&&await _()}catch(t){R.warn(`Graph extraction failed`,{sourcePath:e.relativePath,...y(t)})}a++,o+=n.length},V(n),(e,t)=>R.error(`Processing failed`,{sourcePath:e.relativePath,...y(t)})),await g(),await _(),{filesProcessed:a,chunksCreated:o}}async cleanupRemovedFiles(e,t,n,r,i,a){if(e.length===0)return 0;let o=0;return a?.({phase:`cleanup`,filesTotal:n,filesProcessed:r,chunksTotal:i,chunksProcessed:i}),await B(e,async e=>{await this.store.deleteBySourcePath(e),this.hashCache?.delete(e),this.graphStore&&await this.graphStore.deleteBySourcePath(e).catch(t=>R.warn(`Graph cleanup failed`,{sourcePath:e,...y(t)})),o++},V(t),(e,t)=>R.error(`Cleanup failed`,{sourcePath:e,...y(t)})),o}async reindexAll(e,t){if(this.indexing)throw Error(`Indexing is already in progress`);this.indexing=!0;try{if(await this.store.dropTable(),this.graphStore)try{let e=await this.graphStore.getStats();e.nodeCount>0&&(await this.graphStore.clear(),R.info(`Graph store cleared`,{nodeCount:e.nodeCount,edgeCount:e.edgeCount}))}catch(e){R.warn(`Graph store clear failed`,y(e))}return await this.doReindex(e,t)}catch(e){throw this.indexing=!1,e}}async doReindex(e,t){try{return await this.doIndex(e,t,{skipHashCheck:!0,graphCleared:!0})}finally{this.indexing=!1}}async getStats(){return this.store.getStats()}};const W=_(`smart-index`),G=1.5;var K=class{trickleTimer=null;trickleIntervalMs;batchSize;priorityQueue=[];changedFiles=[];lastRefreshTime=0;refreshing=!1;constructor(e,t,n){this.indexer=e,this.config=t,this.store=n,this.trickleIntervalMs=t.indexing.trickleIntervalMs??this.readPositiveIntEnv(`AIKIT_SMART_TRICKLE_MS`,3e4),this.batchSize=t.indexing.trickleBatchSize??this.readPositiveIntEnv(`AIKIT_SMART_BATCH_SIZE`,1)}start(){this.stop(),W.info(`Smart index scheduler started (trickle mode)`,{intervalMs:this.trickleIntervalMs,batchSize:this.batchSize}),this.scheduleTick()}stop(){this.trickleTimer&&=(clearTimeout(this.trickleTimer),null)}prioritize(...e){let t=[...new Set(e.filter(Boolean))].filter(e=>{try{return!i(e).isDirectory()}catch{return W.debug(`Skipping non-existent path`,{path:e}),!1}});for(let e of t){let t=this.priorityQueue.indexOf(e);t>=0&&this.priorityQueue.splice(t,1)}for(let e of t.reverse())this.priorityQueue.unshift(e);this.priorityQueue.length>500&&(this.priorityQueue.length=500),t.length>0&&W.info(`Files prioritized for trickle indexing`,{added:t.length,queued:this.priorityQueue.length})}getState(){return{mode:`smart`,queueSize:this.priorityQueue.length,changedFilesSize:this.changedFiles.length,intervalMs:this.trickleIntervalMs,batchSize:this.batchSize,running:this.trickleTimer!==null}}readPositiveIntEnv(e,t){let n=Number(process.env[e]);return Number.isFinite(n)&&n>0?n:t}scheduleTick(){this.trickleTimer=setTimeout(()=>void this.tick(),this.trickleIntervalMs),this.trickleTimer.unref&&this.trickleTimer.unref()}async tick(){try{if(this.indexer.isIndexing){W.info(`Skipping trickle tick — indexing already in progress`);return}let e=this.getCpuCount(),t=S()[0];if(e>0&&t/e>G){W.info(`Skipping trickle tick — system load too high`,{load:t.toFixed(2),cpuCount:e,threshold:G});return}let n=await this.pickFiles();if(n.length===0){await this.maybeRefreshChangedFiles();return}W.info(`Trickle indexing tick started`,{count:n.length,files:n});let r=await this.indexer.indexFiles(this.config,n);if(this.store)try{await this.store.createFtsIndex()}catch(e){W.warn(`FTS index rebuild failed after trickle tick`,{error:String(e)})}this.changedFiles=this.changedFiles.filter(e=>!n.includes(e)),W.info(`Trickle indexing tick complete`,{filesProcessed:r.filesProcessed,filesSkipped:r.filesSkipped,chunksCreated:r.chunksCreated})}catch(e){W.error(`Trickle indexing tick failed`,{error:String(e)})}finally{this.scheduleTick()}}getCpuCount(){try{return typeof x==`function`?x():4}catch{return 4}}async pickFiles(){let e=[];for(;e.length<this.batchSize&&this.priorityQueue.length>0;){let t=this.priorityQueue.shift();t&&!e.includes(t)&&e.push(t)}if(e.length<this.batchSize)for(await this.maybeRefreshChangedFiles();e.length<this.batchSize&&this.changedFiles.length>0;){let t=this.changedFiles.shift();t&&!e.includes(t)&&e.push(t)}return e}async maybeRefreshChangedFiles(){let e=Date.now();if(!(this.refreshing||this.changedFiles.length>0&&e-this.lastRefreshTime<6e5)){this.refreshing=!0;try{this.changedFiles=await this.indexer.getChangedFiles(this.config),this.lastRefreshTime=e,this.changedFiles.length>0&&W.info(`Refreshed changed files for trickle indexing`,{count:this.changedFiles.length})}catch(e){W.error(`Failed to refresh changed files for trickle indexing`,{error:String(e)})}finally{this.refreshing=!1}}}};export{L as FileHashCache,D as FilesystemCrawler,U as IncrementalIndexer,K as SmartIndexScheduler,F as extractGraph,T as generateRecordId,w as hashContent};
|
|
1
|
+
import{createHash as e}from"node:crypto";import{existsSync as t,readFileSync as n,realpathSync as r,statSync as i,writeFileSync as a}from"node:fs";import{lstat as o,readFile as s,readdir as c,stat as l}from"node:fs/promises";import{dirname as u,extname as d,join as f,relative as p,resolve as m}from"node:path";import{AIKIT_PATHS as h,FILE_LIMITS as g,createLogger as _,detectContentType as v,serializeError as y}from"../../core/dist/index.js";import{minimatch as b}from"minimatch";import{availableParallelism as x,loadavg as S}from"node:os";import{createChunkerSync as C}from"../../chunker/dist/index.js";function w(t){return e(`sha256`).update(t).digest(`hex`).slice(0,16)}function T(t,n){let r=`${t}:${n}`;return e(`sha256`).update(r).digest(`hex`).slice(0,16)}const E=_(`indexer`);var D=class e{static BINARY_EXTENSIONS=new Set(`.node,.so,.dylib,.dll,.wasm,.bin,.exe,.png,.jpg,.jpeg,.gif,.bmp,.ico,.webp,.svg,.mp3,.mp4,.wav,.avi,.mov,.flac,.zip,.gz,.tar,.bz2,.7z,.rar,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.ttf,.otf,.woff,.woff2,.eot,.pyc,.class,.o,.obj,.a,.lib`.split(`,`));async crawl(e){let t=[],n=new Set;return await this.walkDir(e.rootDir,e.rootDir,e.excludePatterns,t,n),t}async walkDir(t,n,i,a,u){let m;try{m=await c(t,{withFileTypes:!0})}catch(e){let n=e.code;(n===`EACCES`||n===`EPERM`)&&E.warn(`Permission denied, skipping directory`,{dir:t});return}for(let c of m){let m=f(t,c.name),_=p(n,m).replace(/\\/g,`/`);if(!this.isExcluded(_,i)){if(c.isDirectory()){if(c.name.startsWith(`.`)&&!(c.name===h.ai.slice(1)&&_.startsWith(h.ai)))continue;try{if((await o(m)).isSymbolicLink())continue}catch{continue}let e;try{e=r(m)}catch{continue}if(u.has(e))continue;u.add(e),await this.walkDir(m,n,i,a,u)}else if(c.isFile()){let t=d(c.name).toLowerCase();if(e.BINARY_EXTENSIONS.has(t))continue;try{if((await l(m)).size>g.maxFileSizeBytes)continue;let e=await s(m,`utf-8`);if(e.includes(`\0`))continue;a.push({relativePath:_,absolutePath:m,content:e,extension:t})}catch{}}}}}isExcluded(e,t){return t.some(t=>b(e,t,{dot:!0}))}};const O=new Set([`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`]),k=[{pattern:/^export\s+(?:async\s+)?function\s+(\w+)/gm,kind:`function`,exported:!0},{pattern:/^export\s+(?:default\s+)?class\s+(\w+)/gm,kind:`class`,exported:!0},{pattern:/^export\s+interface\s+(\w+)/gm,kind:`interface`,exported:!0},{pattern:/^export\s+type\s+(\w+)/gm,kind:`type`,exported:!0},{pattern:/^export\s+(?:const|let)\s+(\w+)/gm,kind:`const`,exported:!0},{pattern:/^export\s+enum\s+(\w+)/gm,kind:`enum`,exported:!0},{pattern:/^(?:async\s+)?function\s+(\w+)/gm,kind:`function`,exported:!1},{pattern:/^class\s+(\w+)/gm,kind:`class`,exported:!1},{pattern:/^interface\s+(\w+)/gm,kind:`interface`,exported:!1},{pattern:/^type\s+(\w+)/gm,kind:`type`,exported:!1},{pattern:/^enum\s+(\w+)/gm,kind:`enum`,exported:!1}],A=[/import\s+(?:(?:type\s+)?(?:(?:\{[^}]*\}|[\w*]+)\s+from\s+)?)['"]([^'"]+)['"]/g,/import\(\s*['"]([^'"]+)['"]\s*\)/g,/require\(\s*['"]([^'"]+)['"]\s*\)/g];function j(t,n,r){return e(`sha256`).update(`${t}:${n}:${r}`).digest(`hex`).slice(0,16)}function M(t,n,r){return e(`sha256`).update(`${t}-${r}-${n}`).digest(`hex`).slice(0,16)}function N(e,t){return f(u(t),e).replace(/\\/g,`/`).replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/,``)}function P(e){return e.replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/,``)}function F(e,t,n){let r=d(t).toLowerCase();if(!O.has(r))return{nodes:[],edges:[]};let i=[],a=[],o=new Date().toISOString(),s=new Set,c=P(t),l=j(`module`,c,c);i.push({id:l,type:`module`,name:t,properties:{ext:r},sourcePath:t,createdAt:o});for(let{pattern:n,kind:r,exported:c}of k){let u=new RegExp(n.source,n.flags),d;for(;(d=u.exec(e))!==null;){let e=d[1],n=`${r}:${e}`;if(s.has(n))continue;s.add(n);let u=j(r,e,t);i.push({id:u,type:r,name:e,properties:{exported:c},sourcePath:t,createdAt:o}),a.push({id:M(l,u,`defines`),fromId:l,toId:u,type:`defines`,weight:c?1:.5})}}let u=n?.workspacePackages,f=new Set;for(let n of A){let r=new RegExp(n.source,n.flags),i;for(;(i=r.exec(e))!==null;){let e=i[1];if(f.has(e))continue;let n;if(e.startsWith(`.`))n=N(e,t);else if(u){let t=e.startsWith(`@`)?e.split(`/`).slice(0,2).join(`/`):e.split(`/`)[0],r=u.get(t);if(!r)continue;n=r}else continue;f.add(e);let r=P(n),o=j(`module`,r,r);a.push({id:M(l,o,`imports`),fromId:l,toId:o,type:`imports`,properties:{source:e}})}}return{nodes:i,edges:a}}const I=_(`hash-cache`);var L=class{cache;filePath;dirty=!1;constructor(e){this.filePath=m(e,`file-hashes.json`),this.cache=new Map}load(){if(t(this.filePath))try{let e=n(this.filePath,`utf-8`),t=JSON.parse(e);this.cache=new Map(Object.entries(t)),I.info(`Hash cache loaded`,{entries:this.cache.size})}catch(e){I.warn(`Hash cache load failed, starting fresh`,{err:e}),this.cache=new Map}}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t),this.dirty=!0}delete(e){this.cache.delete(e)&&(this.dirty=!0)}flush(){if(this.dirty)try{let e={};for(let[t,n]of this.cache)e[t]=n;a(this.filePath,JSON.stringify(e),`utf-8`),this.dirty=!1}catch(e){I.warn(`Hash cache flush failed`,{err:e})}}clear(){this.cache.clear(),this.dirty=!0,this.flush()}get size(){return this.cache.size}};const R=_(`indexer`),z=()=>new Promise(e=>setImmediate(e));async function B(e,t,n,r){let i=0;async function a(){for(;i<e.length;){let n=i++;try{await t(e[n])}catch(t){r?.(e[n],t)}n%10==0&&await z()}}await Promise.all(Array.from({length:Math.min(n,e.length)},()=>a()))}function V(e){let t=x(),n=S()[0]/t;return n>1.5?2:n>1?Math.max(2,Math.floor(e/2)):e}const H=Math.max(2,Math.min(4,Math.floor(x()*.5)));var U=class{crawler;indexing=!1;graphStore;hashCache;get isIndexing(){return this.indexing}constructor(e,t){this.embedder=e,this.store=t,this.crawler=new D}normalizeChunkText(e){return e.replace(/^\/\/ File: [^\n]*\n?/,``).toLowerCase().replace(/\s+/g,` `).trim()}setGraphStore(e){this.graphStore=e}setHashCache(e){this.hashCache=e}async index(e,t){if(this.indexing)throw Error(`Indexing is already in progress`);this.indexing=!0;try{return await this.doIndex(e,t,{})}finally{this.indexing=!1}}async getChangedFiles(e){let t=e.indexing.concurrency??H,n=await this.crawlSources(e),{filesToProcess:r}=await this.planIndexWork(n,t,{});return r.map(e=>e.relativePath)}async indexFiles(e,t,n){if(this.indexing)throw Error(`Indexing is already in progress`);this.indexing=!0;try{return await this.doIndexFiles(e,t,n)}finally{this.indexing=!1}}async doIndex(e,t,n={}){let r=Date.now(),i=e.indexing.concurrency??H;t?.({phase:`crawling`,filesTotal:0,filesProcessed:0,chunksTotal:0,chunksProcessed:0});let a=await this.crawlSources(e),{filesToProcess:o,filesSkipped:s,pathsToRemove:c}=await this.planIndexWork(a,i,{skipHashCheck:n.skipHashCheck}),{filesProcessed:l,chunksCreated:u,chunksDeduped:d}=await this.processFiles(a,o,i,t,{graphCleared:n.graphCleared}),f=await this.cleanupRemovedFiles(c,i,o.length,l,u,t);return this.hashCache?.flush(),t?.({phase:`done`,filesTotal:o.length,filesProcessed:l,chunksTotal:u,chunksProcessed:u}),{filesProcessed:l,filesSkipped:s,chunksCreated:u,chunksDeduped:d,filesRemoved:f,durationMs:Date.now()-r}}async doIndexFiles(e,t,n){let r=Date.now(),i=e.indexing.concurrency??H,a=new Set(t);if(a.size===0)return{filesProcessed:0,filesSkipped:0,chunksCreated:0,chunksDeduped:0,filesRemoved:0,durationMs:Date.now()-r};n?.({phase:`crawling`,filesTotal:0,filesProcessed:0,chunksTotal:0,chunksProcessed:0});let o=await this.crawlSources(e),{filesToProcess:s,filesSkipped:c}=await this.planIndexWork(o,i,{requestedPaths:a}),{filesProcessed:l,chunksCreated:u,chunksDeduped:d}=await this.processFiles(o,s,i,n,{});return this.hashCache?.flush(),n?.({phase:`done`,filesTotal:s.length,filesProcessed:l,chunksTotal:u,chunksProcessed:u}),{filesProcessed:l,filesSkipped:c,chunksCreated:u,chunksDeduped:d,filesRemoved:0,durationMs:Date.now()-r}}async crawlSources(e){return(await Promise.all(e.sources.map(e=>this.crawler.crawl({rootDir:e.path,excludePatterns:e.excludePatterns})))).flat()}async planIndexWork(e,t,n){let r=n.requestedPaths,i=r?e.filter(e=>r.has(e.relativePath)):e;if(n.skipHashCheck)return{filesToProcess:i,filesSkipped:0,pathsToRemove:[]};let a=r?[]:await this.getPathsToRemove(e),o=0,s=[];return await B(i,async e=>{let t=w(e.content);if(this.hashCache){if(this.hashCache.get(e.relativePath)===t){o++;return}}else{let n=await this.store.getBySourcePath(e.relativePath);if(n.length>0&&n[0].fileHash===t){o++;return}}s.push(e)},V(t),(e,t)=>R.error(`Hash check failed`,{sourcePath:e.relativePath,...y(t)})),{filesToProcess:s,filesSkipped:o,pathsToRemove:a}}async getPathsToRemove(e){let t=await this.store.listSourcePaths(),n=new Set(e.map(e=>e.relativePath));return t.filter(e=>!n.has(e)&&!e.startsWith(`${h.aiCurated}/`))}async buildWorkspacePackageMap(e){let t=new Map;for(let n of e)if(n.relativePath.endsWith(`package.json`))try{let e=JSON.parse(n.content);if(typeof e.name!=`string`||e.name.length===0)continue;let r=n.relativePath===`package.json`?``:n.relativePath.replace(/\/package\.json$/,``),i=``;if(typeof e.exports==`string`)i=e.exports;else if(e.exports&&typeof e.exports==`object`){let t=e.exports,n=t[`.`]??t;if(typeof n==`string`)i=n;else if(n&&typeof n==`object`){let e=n,t=e.import??e.module??e.default??e.require;typeof t==`string`&&(i=t)}}!i&&typeof e.module==`string`&&(i=e.module),!i&&typeof e.main==`string`&&(i=e.main);let a=i.replace(/^\.\//,``).replace(/^dist\//,`src/`).replace(/\.(ts|js|mjs|cjs|tsx|jsx)$/,``),o=a?r?`${r}/${a}`:a:r?`${r}/src/index`:`src/index`;t.set(e.name,o)}catch{}return t}async processFiles(t,n,r,i,a={}){let o=0,s=0,c=0,l=n.length,u=this.graphStore?await this.buildWorkspacePackageMap(t):void 0,d=new Map,f=[],p=[],m=0,h=[],g=[],_=new Map,b=0,x=async()=>{if(h.length===0)return;let e=h,t=g,n=_;h=[],g=[],_=new Map,b=0,await this.store.upsert(e,t);for(let[e,t]of n)this.hashCache?.set(e,t)},S=async()=>{if(this.graphStore){try{f.length>0&&await this.graphStore.upsertNodes(f),p.length>0&&await this.graphStore.upsertEdges(p)}catch(e){R.warn(`Graph batch flush failed`,y(e))}f=[],p=[],m=0}};return await B(n,async t=>{i?.({phase:`chunking`,filesTotal:l,filesProcessed:o,chunksTotal:s,chunksProcessed:s,currentFile:t.relativePath});let n=v(t.relativePath),r=C(t.extension).chunk(t.content,{sourcePath:t.relativePath,contentType:n});if(r.length===0)return;let E=w(t.content),D=new Date().toISOString(),O=(e,n,r)=>({id:T(t.relativePath,n),content:e.text,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:E,contentHash:r,indexedAt:D,origin:`indexed`,tags:[],version:1}),k=[],A=[];for(let t=0;t<r.length;t++){let n=r[t],i=e(`sha256`).update(this.normalizeChunkText(n.text)).digest(`hex`),a=O(n,t,i),o=d.get(i);if(o&&this.store.upsertWithoutVector){A.push({record:a,sourceRecordId:o}),c++;continue}d.set(i,a.id),k.push({chunk:n,record:a})}i?.({phase:`embedding`,filesTotal:l,filesProcessed:o,chunksTotal:s+r.length,chunksProcessed:s,currentFile:t.relativePath});let j=k.length>0?await this.embedder.embedBatch(k.map(({chunk:e})=>e.text)):[],M=k.map(({record:e})=>e);if(i?.({phase:`storing`,filesTotal:l,filesProcessed:o,chunksTotal:s+r.length,chunksProcessed:s,currentFile:t.relativePath}),M.length>0&&(h.push(...M),g.push(...j),_.set(t.relativePath,E),b++,b>=20&&await x()),A.length>0&&h.length>0&&await x(),this.store.upsertWithoutVector)for(let{record:e,sourceRecordId:t}of A)await this.store.upsertWithoutVector(e,t);if(M.length===0&&A.length>0&&this.hashCache?.set(t.relativePath,E),this.graphStore)try{a.graphCleared||await this.graphStore.deleteBySourcePath(t.relativePath);let e=F(t.content,t.relativePath,{workspacePackages:u});e.nodes.length>0&&f.push(...e.nodes),e.edges.length>0&&p.push(...e.edges),m++,m>=50&&await S()}catch(e){R.warn(`Graph extraction failed`,{sourcePath:t.relativePath,...y(e)})}o++,s+=r.length},V(r),(e,t)=>R.error(`Processing failed`,{sourcePath:e.relativePath,...y(t)})),await x(),await S(),{filesProcessed:o,chunksCreated:s,chunksDeduped:c}}async cleanupRemovedFiles(e,t,n,r,i,a){if(e.length===0)return 0;let o=0;return a?.({phase:`cleanup`,filesTotal:n,filesProcessed:r,chunksTotal:i,chunksProcessed:i}),await B(e,async e=>{await this.store.deleteBySourcePath(e),this.hashCache?.delete(e),this.graphStore&&await this.graphStore.deleteBySourcePath(e).catch(t=>R.warn(`Graph cleanup failed`,{sourcePath:e,...y(t)})),o++},V(t),(e,t)=>R.error(`Cleanup failed`,{sourcePath:e,...y(t)})),o}async reindexAll(e,t){if(this.indexing)throw Error(`Indexing is already in progress`);this.indexing=!0;try{if(await this.store.dropTable(),this.graphStore)try{let e=await this.graphStore.getStats();e.nodeCount>0&&(await this.graphStore.clear(),R.info(`Graph store cleared`,{nodeCount:e.nodeCount,edgeCount:e.edgeCount}))}catch(e){R.warn(`Graph store clear failed`,y(e))}return await this.doReindex(e,t)}catch(e){throw this.indexing=!1,e}}async doReindex(e,t){try{return await this.doIndex(e,t,{skipHashCheck:!0,graphCleared:!0})}finally{this.indexing=!1}}async getStats(){return this.store.getStats()}};const W=_(`smart-index`),G=1.5;var K=class{trickleTimer=null;stopped=!1;trickleIntervalMs;batchSize;priorityQueue=[];changedFiles=[];lastRefreshTime=0;refreshing=!1;constructor(e,t,n){this.indexer=e,this.config=t,this.store=n,this.trickleIntervalMs=t.indexing.trickleIntervalMs??this.readPositiveIntEnv(`AIKIT_SMART_TRICKLE_MS`,3e4),this.batchSize=t.indexing.trickleBatchSize??this.readPositiveIntEnv(`AIKIT_SMART_BATCH_SIZE`,1)}start(){this.trickleTimer&&=(clearTimeout(this.trickleTimer),null),this.stopped=!1,W.info(`Smart index scheduler started (trickle mode)`,{intervalMs:this.trickleIntervalMs,batchSize:this.batchSize}),this.scheduleTick()}stop(){this.stopped=!0,this.trickleTimer&&=(clearTimeout(this.trickleTimer),null)}prioritize(...e){let t=[...new Set(e.filter(Boolean))].filter(e=>{try{return!i(e).isDirectory()}catch{return W.debug(`Skipping non-existent path`,{path:e}),!1}});for(let e of t){let t=this.priorityQueue.indexOf(e);t>=0&&this.priorityQueue.splice(t,1)}for(let e of t.reverse())this.priorityQueue.unshift(e);this.priorityQueue.length>500&&(this.priorityQueue.length=500),t.length>0&&W.info(`Files prioritized for trickle indexing`,{added:t.length,queued:this.priorityQueue.length})}getState(){return{mode:`smart`,queueSize:this.priorityQueue.length,changedFilesSize:this.changedFiles.length,intervalMs:this.trickleIntervalMs,batchSize:this.batchSize,running:this.trickleTimer!==null}}readPositiveIntEnv(e,t){let n=Number(process.env[e]);return Number.isFinite(n)&&n>0?n:t}scheduleTick(){this.trickleTimer=setTimeout(()=>void this.tick(),this.trickleIntervalMs),this.trickleTimer.unref&&this.trickleTimer.unref()}async tick(){if(!this.stopped)try{if(this.indexer.isIndexing){W.info(`Skipping trickle tick — indexing already in progress`);return}let e=this.getCpuCount(),t=S()[0];if(e>0&&t/e>G){W.info(`Skipping trickle tick — system load too high`,{load:t.toFixed(2),cpuCount:e,threshold:G});return}let n=await this.pickFiles();if(n.length===0){await this.maybeRefreshChangedFiles();return}W.info(`Trickle indexing tick started`,{count:n.length,files:n});let r=await this.indexer.indexFiles(this.config,n);if(this.store)try{await this.store.createFtsIndex()}catch(e){W.warn(`FTS index rebuild failed after trickle tick`,{error:String(e)})}this.changedFiles=this.changedFiles.filter(e=>!n.includes(e)),W.info(`Trickle indexing tick complete`,{filesProcessed:r.filesProcessed,filesSkipped:r.filesSkipped,chunksCreated:r.chunksCreated})}catch(e){W.error(`Trickle indexing tick failed`,{error:String(e)})}finally{this.stopped||this.scheduleTick()}}getCpuCount(){try{return typeof x==`function`?x():4}catch{return 4}}async pickFiles(){let e=[];for(;e.length<this.batchSize&&this.priorityQueue.length>0;){let t=this.priorityQueue.shift();t&&!e.includes(t)&&e.push(t)}if(e.length<this.batchSize)for(await this.maybeRefreshChangedFiles();e.length<this.batchSize&&this.changedFiles.length>0;){let t=this.changedFiles.shift();t&&!e.includes(t)&&e.push(t)}return e}async maybeRefreshChangedFiles(){let e=Date.now();if(!(this.refreshing||this.changedFiles.length>0&&e-this.lastRefreshTime<6e5)){this.refreshing=!0;try{this.changedFiles=await this.indexer.getChangedFiles(this.config),this.lastRefreshTime=e,this.changedFiles.length>0&&W.info(`Refreshed changed files for trickle indexing`,{count:this.changedFiles.length})}catch(e){W.error(`Failed to refresh changed files for trickle indexing`,{error:String(e)})}finally{this.refreshing=!1}}}};export{L as FileHashCache,D as FilesystemCrawler,U as IncrementalIndexer,K as SmartIndexScheduler,F as extractGraph,T as generateRecordId,w as hashContent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{AIKIT_PATHS as a,EMBEDDING_DEFAULTS as o,createLogger as s,getPartitionDir as c,isUserInstalled as l,registerWorkspace as u,serializeError as d}from"../../core/dist/index.js";const f=n(i(import.meta.url)),p=s(`server`),m=[`auto`,`manual`,`smart`];function h(e){return typeof e==`string`&&m.includes(e)}function g(e,t,n){let i=r(e),a=r(t);if(!i.startsWith(a))throw Error(`Config ${n} path escapes workspace root: ${e} is not under ${t}`);return i}function _(e){let t=process.env.AIKIT_INDEX_MODE;if(h(t))return t;if(e.indexMode)return e.indexMode;let n=process.env.AIKIT_AUTO_INDEX;return n===void 0?e.autoIndex===void 0?`smart`:e.autoIndex?`auto`:`manual`:n===`true`?`auto`:`manual`}function v(){let i=process.env.AIKIT_CONFIG_PATH??(e(r(process.cwd(),`aikit.config.json`))?r(process.cwd(),`aikit.config.json`):r(f,`..`,`..`,`..`,`aikit.config.json`));try{if(!e(i))return p.info(`No config file found, using defaults`,{configPath:i}),y();let o=t(i,`utf-8`),s=JSON.parse(o);if(!s.sources||!Array.isArray(s.sources)||s.sources.length===0)throw Error(`Config must have at least one source`);if(!s.store?.path)throw Error(`Config must specify store.path`);if(s.autoIndex!==void 0&&typeof s.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(s.indexMode!==void 0&&!h(s.indexMode))throw Error(`Config indexMode must be one of: ${m.join(`, `)}`);let c=n(i);return s.sources=s.sources.map(e=>({...e,path:g(r(c,e.path),c,`source`)})),s.store.path=g(r(c,s.store.path),c,`store`),s.curated=s.curated??{path:a.aiCurated},s.curated.path=g(r(c,s.curated.path),c,`curated`),b(s,c),s.indexMode=_(s),s}catch(e){return p.error(`Failed to load config`,{configPath:i,...d(e)}),p.warn(`Falling back to default configuration`,{configPath:i}),y()}}function y(){let e=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),t={sources:[{path:e,excludePatterns:[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:o.model,dimensions:o.dimensions},store:{backend:`sqlite-vec`,path:r(e,a.data)},curated:{path:r(e,a.aiCurated)},onboardDir:r(e,a.aiContext),stateDir:r(e,a.state)};return b(t,e),t.indexMode=_(t),t}function b(e,t){if(!l())return;let n=t,i=u(n);e.store.path=r(c(i.partition)),e.onboardDir=r(c(i.partition),`onboard`),e.stateDir=r(c(i.partition),`state`),e.curated||={path:r(n,a.aiCurated)}}function x(t,n){if(!e(n))throw Error(`Workspace root does not exist: ${n}`);p.info(`Reconfiguring for workspace root`,{workspaceRoot:n});try{process.chdir(n),p.info(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){p.warn(`Failed to chdir to workspace root`,{workspaceRoot:n,...d(e)})}t.sources=[{path:n,excludePatterns:t.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],t.store.path=r(n,a.data),t.curated={path:r(n,a.aiCurated)},t.onboardDir=r(n,a.aiContext),t.stateDir=r(n,a.state),b(t,n)}export{v as loadConfig,x as reconfigureForWorkspace,_ as resolveIndexMode};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./curated-manager-CXSPygmJ.js";import{readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";import{parseArgs as o}from"node:util";import{createLogger as s,serializeError as c}from"../../core/dist/index.js";const l=n(i(import.meta.url)),u=(()=>{try{let e=r(l,`..`,`..`,`..`,`package.json`);return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}})(),d=s(`server`);function f(){return process.env.AIKIT_TRANSPORT?process.env.AIKIT_TRANSPORT:process.stdin.isTTY?`http`:`stdio`}const{values:p}=(()=>{let e=process.argv[1];if(!e)return!1;try{return import.meta.url===a(e).href}catch{return!1}})()?o({allowPositionals:!0,options:{transport:{type:`string`,default:f()},port:{type:`string`,default:process.env.AIKIT_PORT??`3210`}}}):{values:{transport:f(),port:process.env.AIKIT_PORT??`3210`}};async function m(){if(process.on(`unhandledRejection`,e=>{d.error(`Unhandled rejection`,c(e))}),d.info(`Starting MCP AI Kit server`,{version:u}),p.transport===`http`){let[{default:e},{loadConfig:t,resolveIndexMode:n},{registerDashboardRoutes:r,resolveDashboardDir:i},{registerSettingsRoutes:a,resolveSettingsDir:o},{createSettingsRouter:s}]=await Promise.all([import(`express`),import(`./config-
|
|
1
|
+
import{t as e}from"./curated-manager-CXSPygmJ.js";import{readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";import{parseArgs as o}from"node:util";import{createLogger as s,serializeError as c}from"../../core/dist/index.js";const l=n(i(import.meta.url)),u=(()=>{try{let e=r(l,`..`,`..`,`..`,`package.json`);return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}})(),d=s(`server`);function f(){return process.env.AIKIT_TRANSPORT?process.env.AIKIT_TRANSPORT:process.stdin.isTTY?`http`:`stdio`}const{values:p}=(()=>{let e=process.argv[1];if(!e)return!1;try{return import.meta.url===a(e).href}catch{return!1}})()?o({allowPositionals:!0,options:{transport:{type:`string`,default:f()},port:{type:`string`,default:process.env.AIKIT_PORT??`3210`}}}):{values:{transport:f(),port:process.env.AIKIT_PORT??`3210`}};async function m(){if(process.on(`unhandledRejection`,e=>{d.error(`Unhandled rejection`,c(e))}),d.info(`Starting MCP AI Kit server`,{version:u}),p.transport===`http`){let[{default:e},{loadConfig:t,resolveIndexMode:n},{registerDashboardRoutes:r,resolveDashboardDir:i},{registerSettingsRoutes:a,resolveSettingsDir:o},{createSettingsRouter:s}]=await Promise.all([import(`express`),import(`./config-BL-I_FFY.js`),import(`./dashboard-static-BfIe0Si1.js`),import(`./settings-static-BosGZSPf.js`),import(`./routes-OaSHcA6x.js`)]),l=t();d.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path});let u=e();u.use(e.json());let f=Number(p.port);u.use((e,t,n)=>{if(t.setHeader(`Access-Control-Allow-Origin`,process.env.AIKIT_CORS_ORIGIN??`http://localhost:${f}`),t.setHeader(`Access-Control-Allow-Methods`,`GET, POST, PUT, PATCH, DELETE, OPTIONS`),t.setHeader(`Access-Control-Allow-Headers`,`Content-Type, Authorization`),e.method===`OPTIONS`){t.status(204).end();return}n()}),r(u,i(),d);let m=new Date().toISOString();u.use(`/settings/api`,s({log:d,mcpInfo:()=>({transport:`http`,port:f,pid:process.pid,startedAt:m})})),a(u,o(),d),u.get(`/health`,(e,t)=>{t.json({status:`ok`})});let h=!1,g=null,_=null,v=null,y=Promise.resolve();u.post(`/mcp`,async(e,t)=>{if(!h||!_||!v){t.status(503).json({jsonrpc:`2.0`,error:{code:-32603,message:`Server initializing — please retry in a few seconds`},id:null});return}let n=y,r;y=new Promise(e=>{r=e}),await n;try{let n=new v({sessionIdGenerator:void 0});await _.connect(n),await n.handleRequest(e,t,e.body),n.close()}catch(e){if(d.error(`MCP handler error`,c(e)),!t.headersSent){let n=e instanceof Error?e.message:String(e),r=n.includes(`Not Acceptable`);t.status(r?406:500).json({jsonrpc:`2.0`,error:{code:r?-32e3:-32603,message:r?n:`Internal server error`},id:null})}}finally{r()}}),u.get(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))}),u.delete(`/mcp`,(e,t)=>{t.writeHead(405).end(JSON.stringify({jsonrpc:`2.0`,error:{code:-32e3,message:`Method not allowed.`},id:null}))});let b=u.listen(f,`127.0.0.1`,()=>{d.info(`MCP server listening`,{url:`http://127.0.0.1:${f}/mcp`,port:f}),setTimeout(async()=>{try{let[{createLazyServer:e,ALL_TOOL_NAMES:t},{StreamableHTTPServerTransport:r},{checkForUpdates:i,autoUpgradeScaffold:a}]=await Promise.all([import(`./server-BnPh8aSm.js`),import(`@modelcontextprotocol/sdk/server/streamableHttp.js`),import(`./version-check-Bj07vc5x.js`)]);i(),a();let o=n(l),s=e(l,o);_=s.server,v=r,h=!0,d.info(`MCP server configured (lazy — AI Kit initializing in background)`,{toolCount:t.length,resourceCount:2}),s.startInit(),o===`auto`?s.ready.then(async()=>{try{let e=l.sources.map(e=>e.path).join(`, `);d.info(`Running initial index`,{sourcePaths:e}),await s.runInitialIndex(),d.info(`Initial index complete`)}catch(e){d.error(`Initial index failed; will retry on aikit_reindex`,c(e))}}).catch(e=>d.error(`AI Kit init or indexing failed`,c(e))):o===`smart`?s.ready.then(async()=>{try{if(!s.aikit)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`);g=new e(s.aikit.indexer,l,s.aikit.store),g.start(),s.setSmartScheduler(g),d.info(`Smart index scheduler started (HTTP mode)`)}catch(e){d.error(`Failed to start smart index scheduler`,c(e))}}).catch(e=>d.error(`AI Kit initialization failed`,c(e))):(s.ready.catch(e=>d.error(`AI Kit initialization failed`,c(e))),d.info(`Initial full indexing skipped in HTTP mode`,{indexMode:o}))}catch(e){d.error(`Failed to load server modules`,c(e))}},100)}),x=async e=>{d.info(`Shutdown signal received`,{signal:e}),g?.stop(),b.close(),_&&await _.close(),process.exit(0)};process.on(`SIGINT`,()=>x(`SIGINT`)),process.on(`SIGTERM`,()=>x(`SIGTERM`))}else{let[{loadConfig:e,reconfigureForWorkspace:t,resolveIndexMode:n},{createLazyServer:r},{checkForUpdates:a,autoUpgradeScaffold:o},{RootsListChangedNotificationSchema:s}]=await Promise.all([import(`./config-BL-I_FFY.js`),import(`./server-BnPh8aSm.js`),import(`./version-check-Bj07vc5x.js`),import(`@modelcontextprotocol/sdk/types.js`)]),l=e();d.info(`Config loaded`,{sourceCount:l.sources.length,storePath:l.store.path}),a(),o();let u=n(l),f=r(l,u),{server:p,startInit:m,ready:h,runInitialIndex:g}=f,{StdioServerTransport:_}=await import(`@modelcontextprotocol/sdk/server/stdio.js`),v=new _;await p.connect(v),d.info(`MCP server started`,{transport:`stdio`});let y=e=>{if(e.length===0)return!1;let n=e[0].uri,r=n.startsWith(`file://`)?i(n):n;return d.info(`MCP roots resolved`,{rootUri:n,rootPath:r,rootCount:e.length}),t(l,r),l.allRoots=e.map(e=>{let t=e.uri;return t.startsWith(`file://`)?i(t):t}),!0},b=!1;try{b=y((await p.server.listRoots()).roots),b||d.info(`No MCP roots yet; waiting for roots/list_changed notification`)}catch(e){d.warn(`MCP roots/list not supported by client; using cwd fallback`,{cwd:process.cwd(),...c(e)}),b=!0}b||=await new Promise(e=>{let t=setTimeout(()=>{d.warn(`Timed out waiting for MCP roots/list_changed; using cwd fallback`,{cwd:process.cwd()}),e(!1)},5e3);p.server.setNotificationHandler(s,async()=>{clearTimeout(t);try{e(y((await p.server.listRoots()).roots))}catch(t){d.warn(`roots/list retry failed after notification`,c(t)),e(!1)}})}),m();let x=null,S=()=>{x&&clearTimeout(x),x=setTimeout(()=>{d.info(`Auto-shutdown: no activity for 30 minutes — exiting`),process.exit(0)},18e5),x.unref&&x.unref()};S(),process.stdin.on(`data`,()=>S()),h.catch(e=>{d.error(`Initialization failed — server will continue with limited tools`,c(e))}),u===`auto`?g().catch(e=>d.error(`Initial index failed`,c(e))):u===`smart`?h.then(async()=>{try{if(!f.aikit)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(f.aikit.indexer,l,f.aikit.store);t.start(),f.setSmartScheduler(t),d.info(`Smart index scheduler started (stdio mode)`)}catch(e){d.error(`Failed to start smart index scheduler`,c(e))}}).catch(e=>d.error(`AI Kit init failed for smart scheduler`,c(e))):d.warn(`Initial full indexing skipped; use aikit_reindex to index manually`,{indexMode:u})}}m().catch(e=>{d.error(`Fatal error`,c(e)),process.exit(1)});export{e as CuratedKnowledgeManager};
|
|
@@ -15,7 +15,7 @@ import{n as e,t}from"./curated-manager-CXSPygmJ.js";import{autoUpgradeScaffold a
|
|
|
15
15
|
`)}`;n.push({title:`Dependencies: ${r}`,content:t,category:`context`,tags:[`architecture`,`dependencies`,`analysis`],hash:L(`deps-${r}`),quality:.7,source:e.toolName})}}if(e.toolName===`blast_radius`){let r=e.args.changed_files,i=Array.isArray(r)?r.map(String).join(`, `):String(r??``);if(i&&t.length>50){let r=t.slice(0,400);n.push({title:`Blast radius: ${i.slice(0,60)}`,content:`Impact analysis for changes to ${i}:\n${r}`,category:`context`,tags:[`architecture`,`blast-radius`,`impact`],hash:L(`blast-${i}`),quality:.6,source:e.toolName,ttlMs:36e5})}}if(e.toolName===`analyze`&&e.args.aspect===`entry_points`){let r=t.split(/\r?\n/).filter(e=>/(?:entry|export|main|bin)\b/i.test(e)).slice(0,10);r.length>0&&n.push({title:`Project entry points`,content:`Detected entry points:\n${r.join(`
|
|
16
16
|
`)}`,category:`context`,tags:[`architecture`,`entry-points`],hash:L(`entry-points`),quality:.7,source:e.toolName})}if(e.toolName===`scope_map`){let r=typeof e.args.task==`string`?e.args.task:``;r&&t.length>100&&n.push({title:`Scope map: ${r.slice(0,60)}`,content:`Scope analysis for "${r}":\n${t.slice(0,500)}`,category:`context`,tags:[`planning`,`scope-map`],hash:L(`scope-${r}`),quality:.6,source:e.toolName,ttlMs:72e5})}return e.toolName===`onboard`&&t.length>200&&n.push({title:`Onboard analysis summary`,content:`Codebase onboarding analysis:\n${t.slice(0,800)}`,category:`context`,tags:[`onboarding`,`analysis`,`structure`],hash:L(`onboard-summary`),quality:.9,source:e.toolName}),n}};function Yn(e,t){let n=[],r=e.toLowerCase();r.includes(`biome`)?n.push({title:`Linter: Biome`,content:`This project uses Biome for linting and formatting.`,category:`conventions`,tags:[`tooling`,`linter`,`biome`],hash:L(`convention-linter-biome`),quality:.8,source:t}):r.includes(`eslint`)&&n.push({title:`Linter: ESLint`,content:`This project uses ESLint for linting.`,category:`conventions`,tags:[`tooling`,`linter`,`eslint`],hash:L(`convention-linter-eslint`),quality:.8,source:t}),r.includes(`prettier`)&&n.push({title:`Formatter: Prettier`,content:`This project uses Prettier for code formatting.`,category:`conventions`,tags:[`tooling`,`formatter`,`prettier`],hash:L(`convention-formatter-prettier`),quality:.8,source:t}),(/strict\s*(?:mode)?.*(?:enabled|true)/i.test(e)||/"strict"\s*:\s*true/.test(e))&&n.push({title:`TypeScript strict mode enabled`,content:`This project has TypeScript strict mode enabled. Ensure all types are explicit.`,category:`conventions`,tags:[`typescript`,`strict`,`config`],hash:L(`convention-ts-strict`),quality:.8,source:t});for(let e of[`pnpm`,`yarn`,`npm`,`bun`])if(r.includes(e)&&(r.includes(`lockfile`)||r.includes(`workspace`)||r.includes(`${e} run`))){n.push({title:`Package manager: ${e}`,content:`This project uses ${e} as its package manager.`,category:`conventions`,tags:[`tooling`,`package-manager`,e],hash:L(`convention-pm-${e}`),quality:.7,source:t});break}return(r.includes(`monorepo`)||r.includes(`workspaces`)||/packages\/\w+/.test(e))&&n.push({title:`Monorepo structure detected`,content:`This project uses a monorepo structure with multiple packages.`,category:`conventions`,tags:[`architecture`,`monorepo`],hash:L(`convention-monorepo`),quality:.7,source:t}),n}function Xn(e,t){let n=[],r=e.matchAll(/(?:pattern|convention):\s*(.+?)(?:\n|$)/gi);for(let e of r){let r=e[1]?.trim();r&&r.length>20&&r.length<200&&n.push({title:`Pattern: ${r.slice(0,80)}`,content:r,category:`patterns`,tags:[`detected-pattern`],hash:L(`pattern-${r}`),quality:.6,source:t})}return n}const Zn={name:`convention-detection`,tools:[`check`,`analyze`,`onboard`],extract(e){let t=Gn(e.result);if(!t||e.isError)return[];let n=[];return n.push(...Yn(t,e.toolName)),e.toolName===`analyze`&&e.args.aspect===`patterns`&&n.push(...Xn(t,e.toolName)),n}};function Qn(e,t){return e.match(t)?.[1]?.trim()||null}function $n(e,t,n,r,i,a){return{title:e,content:t,category:`context`,tags:n,hash:L(r),quality:i,source:a}}const er={name:`environment-facts`,tools:[`env`,`config`,`status`],extract(e){let t=Gn(e.result);if(!t)return[];let n=[],r=Qn(t,/node(?:\.js)?\s*[:=]\s*([^\r\n]+)/i);r&&n.push($n(`Node.js version`,`Detected Node.js version: ${r}`,[`environment`,`node`],`node-version-${r}`,.4,e.toolName));let i=Qn(t,/(?:^|\n)os\s*[:=]\s*([^\r\n]+)/i);i&&n.push($n(`Operating system`,`Detected OS: ${i}`,[`environment`,`os`],`os-${i}`,.4,e.toolName));let a=Qn(t,/workspace(?: path)?\s*[:=]\s*([^\r\n]+)/i);a&&n.push($n(`Workspace path`,`Primary workspace path: ${a}`,[`environment`,`workspace`],`workspace-${a}`,.4,e.toolName));let o=Qn(t,/store(?: backend)?\s*[:=]\s*([^\r\n]+)/i);o&&n.push($n(`Store backend`,`Configured store backend: ${o}`,[`environment`,`storage`],`store-${o}`,.6,e.toolName));let s=Qn(t,/embedding(?: model)?\s*[:=]\s*([^\r\n]+)/i);return s&&n.push($n(`Embedding model`,`Configured embedding model: ${s}`,[`environment`,`embedding`],`embedding-${s}`,.6,e.toolName)),n}},tr={name:`research-results`,tools:[`web_search`,`web_fetch`,`search`],extract(e){let t=Gn(e.result);if(!t||t.length<100||e.isError)return[];let n=[];if(e.toolName===`web_search`){let r=typeof e.args.query==`string`?e.args.query:``;if(r&&t.length>200){let i=t.slice(0,800);n.push({title:`Web research: ${r.slice(0,80)}`,content:`Research query: "${r}"\n\nKey findings:\n${i}`,category:`context`,tags:[`research`,`web-search`],hash:L(`web-search-${r}`),quality:Math.min(.8,Kn(i)+.2),source:e.toolName,ttlMs:864e5})}}if(e.toolName===`web_fetch`){let r=e.args.urls,i=Array.isArray(r)?String(r[0]??``):typeof e.args.url==`string`?e.args.url:``;if(i&&t.length>200){let r=t.split(/\r?\n/).find(e=>e.trim().length>10)?.trim()??i,a=t.slice(0,600);n.push({title:`Fetched: ${r.slice(0,80)}`,content:`Source: ${i}\n\n${a}`,category:`context`,tags:[`research`,`web-fetch`],hash:L(`web-fetch-${i}`),quality:Kn(a),source:e.toolName,ttlMs:864e5})}}if(e.toolName===`search`){let r=typeof e.args.query==`string`?e.args.query:``;(typeof e.args.origin==`string`?e.args.origin:``)===`curated`&&r&&t.length>100&&n.push({title:`Curated search: ${r.slice(0,80)}`,content:`Searched curated knowledge for: "${r}"\n\nResults:\n${t.slice(0,500)}`,category:`context`,tags:[`research`,`curated-search`],hash:L(`curated-search-${r}`),quality:.5,source:e.toolName,ttlMs:36e5})}return n}};function nr(e){let t=e.toLowerCase();return t.includes(`vitest`)?`vitest`:t.includes(`jest`)?`jest`:t.includes(`mocha`)?`mocha`:t.includes(`playwright`)?`playwright`:t.includes(`cypress`)?`cypress`:null}function rr(e){let t=[/(\S+\.test\.\w+)/,/(\S+\.spec\.\w+)/,/(\S+_test\.\w+)/,/__tests__\/\S+/],n=new Set;for(let r of t){let t=e.matchAll(new RegExp(r.source,`g`));for(let e of t){let t=e[0].match(/\.(test|spec)\.\w+$/);t&&n.add(t[0])}}return n.size>0?[...n].join(`, `):null}const ir={name:`test-results`,tools:[`check`,`test_run`],extract(e){let t=Gn(e.result);if(!t)return[];let n=[],r=nr(t);r&&n.push({title:`Test framework: ${r}`,content:`This project uses ${r} for testing. Detected from ${e.toolName} output.`,category:`context`,tags:[`testing`,`environment`,r],hash:L(`test-framework-${r}`),quality:.7,source:e.toolName});let i=rr(t);return i&&n.push({title:`Test file pattern: ${i}`,content:`Test files use the naming pattern: ${i}. Follow this convention when creating new tests.`,category:`conventions`,tags:[`testing`,`naming-convention`],hash:L(`test-pattern-${i}`),quality:.7,source:e.toolName}),n}};function ar(e){let t=e.toLowerCase();return/enoent|no such file|not found/i.test(e)?{type:`missing-file`,actionable:!1}:/econnreset|econnrefused|etimedout|fetch failed/i.test(e)?{type:`network`,actionable:!1}:/permission denied|eacces/i.test(e)?{type:`permission`,actionable:!0}:/type\s*error|cannot.*property|is not a function/i.test(e)?{type:`type-error`,actionable:!0}:/syntax\s*error|unexpected token|parsing error/i.test(e)?{type:`syntax`,actionable:!0}:/out of memory|heap|allocation/i.test(e)?{type:`memory`,actionable:!0}:/timeout|timed out/i.test(e)?{type:`timeout`,actionable:t.includes(`increase`)||t.includes(`config`)}:/import|require|module not found|cannot find module/i.test(e)?{type:`module-resolution`,actionable:!0}:{type:`unknown`,actionable:e.length>100}}const or={name:`tool-failure-patterns`,tools:[],extract(e){if(!e.isError)return[];let t=Gn(e.result);if(!t||t.length<30)return[];let{type:n,actionable:r}=ar(t);if(!r)return[];let i=t.slice(0,500),a=Kn(i);return a<.2?[]:[{title:`${n} error in ${e.toolName}`,content:`Tool \`${e.toolName}\` failed with a ${n} error.\n\nArgs: ${JSON.stringify(e.args,null,2).slice(0,200)}\n\nError:\n${i}`,category:`context`,tags:[`errors`,n,e.toolName],hash:L(`smart-error-${n}-${e.toolName}-${t.slice(0,80)}`),quality:Math.min(.7,a+.1),source:e.toolName,ttlMs:72e5}]}};var sr=class{extractors=[];register(e){this.extractors.push(e)}getExtractors(e){return this.extractors.filter(t=>t.tools.length===0||t.tools.includes(e))}extractAll(e){return this.getExtractors(e.toolName).flatMap(t=>t.extract(e))}};function cr(e){return{content:[{type:`text`,text:(e instanceof Error,String(e))}],isError:!0}}function lr(e,t){try{e.push(t)}catch{}}function ur(e){return async(t,n)=>{let r=Date.now();try{let i=await n();return lr(e,{toolName:t.toolName,args:t.args,result:i,durationMs:Date.now()-r,isError:i.isError===!0,timestamp:new Date().toISOString()}),i}catch(n){throw lr(e,{toolName:t.toolName,args:t.args,result:cr(n),durationMs:Date.now()-r,isError:!0,timestamp:new Date().toISOString()}),n}}}const dr=D(`auto-knowledge`);var fr=class{queue=[];timer=null;seenHashes=new Map;storedCount=0;droppedCount=0;dedupedCount=0;config;existingTitles=null;constructor(e,t,n={}){this.registry=e,this.curated=t,this.config={...Wn,...n}}push(e){if(!(!this.config.enabled||!this.curated)&&!(this.storedCount>=this.config.maxFactsPerSession)){if(this.queue.push(e),this.queue.length>=this.config.batchSize){this.flush().catch(e=>{dr.warn(`Auto-knowledge flush error`,{error:String(e)})});return}this.scheduleBatch()}}async flush(){this.timer&&=(clearTimeout(this.timer),null);let e=this.queue.splice(0);if(e.length===0||!this.curated)return;this.existingTitles===null&&(this.existingTitles=await this.loadExistingTitles());let t=new Map;for(let n of e)for(let e of this.registry.extractAll(n)){if(e.quality<this.config.minQuality){this.droppedCount++;continue}if(this.isSeenRecently(e)){this.dedupedCount++;continue}if(t.has(e.hash)){this.dedupedCount++;continue}if(this.existingTitles.has(this.normalizeTitle(e.title))){this.dedupedCount++;continue}t.set(e.hash,e)}for(let e of t.values()){if(this.storedCount>=this.config.maxFactsPerSession)break;try{await this.curated.remember(e.title,e.content,e.category,e.tags),this.seenHashes.set(e.hash,Date.now()),this.existingTitles.add(this.normalizeTitle(e.title)),this.storedCount++,dr.info(`Auto-knowledge stored`,{title:e.title,category:e.category,quality:e.quality,source:e.source})}catch(t){dr.warn(`Auto-knowledge store failed`,{title:e.title,error:String(t)})}}}reset(){this.queue=[],this.seenHashes.clear(),this.storedCount=0,this.droppedCount=0,this.dedupedCount=0,this.existingTitles=null,this.timer&&=(clearTimeout(this.timer),null)}getStats(){return{queued:this.queue.length,stored:this.storedCount,seen:this.seenHashes.size,dropped:this.droppedCount,deduped:this.dedupedCount}}isSeenRecently(e){let t=this.seenHashes.get(e.hash);return t==null?!1:e.ttlMs==null?!0:Date.now()-t<e.ttlMs}normalizeTitle(e){return e.toLowerCase().trim()}async loadExistingTitles(){let e=new Set,t=this.curated;if(!t)return e;try{let n=await t.list();for(let t of n)e.add(this.normalizeTitle(t.title))}catch{dr.warn(`Failed to load existing curated titles for dedup`,{})}return e}scheduleBatch(){this.timer||=setTimeout(()=>{this.timer=null,this.flush().catch(e=>{dr.warn(`Auto-knowledge flush error`,{error:String(e)})})},this.config.debounceMs)}};const pr=new Set([`compact`,`digest`,`file_summary`,`stratum_card`,`present`,`web_fetch`,`web_search`,`check`,`audit`]);function mr(e){switch(e){case`efficient`:return{threshold:2e3,tokenBudget:1e3};case`full`:return{threshold:1/0};default:return{threshold:4e3,tokenBudget:2e3}}}function hr(e){let t=e?.threshold??4e3,n=e?.tokenBudget??2e3;return async(e,r)=>{if(pr.has(e.toolName))return r();let i=await r();if(!Array.isArray(i.content))return i;let a=0;for(let e of i.content)e.type===`text`&&typeof e.text==`string`&&(a+=e.text.length);if(a<t)return i;let o=i.content.map(r=>{if(r.type!==`text`||typeof r.text!=`string`||r.text.length<t)return r;let i=ge({text:r.text,tool:e.toolName,tokenBudget:n});return{...r,text:i.text}});return{...i,content:o}}}const gr=D(`tool-pipeline`);function _r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function vr(e,t){return e.tools?(Array.isArray(e.tools)?e.tools:[e.tools]).includes(t):!0}function yr(e){return e.middleware.critical===!0}var br=class{entries=[];use(e,t){this.entries.push({middleware:e,order:t?.order??100,tools:t?.tools,name:t?.name??e.name??`anonymous`})}useFor(e,t,n){this.use(t,{order:n?.order,tools:e,name:n?.name})}wrap(e,t,n,r){let i=this.entries.filter(t=>vr(t,e)).sort((e,t)=>e.order-t.order);return async(a,o)=>{let s={toolName:e,args:_r(a)?a:{},requestId:te(),meta:r,extra:o,toolConfig:n},c=async n=>{let r=i[n];if(!r)return await t(s.args,o);let a=!1,l=!1,u,d=async()=>{a=!0;let e=await c(n+1);return l=!0,u=e,e};try{return await r.middleware(s,d)}catch(t){if(yr(r))throw t;if(gr.warn(`Middleware failed for tool`,{middleware:r.name,tool:e,error:String(t)}),a){if(l&&u)return u;throw t}return c(n+1)}};return c(0)}}getMiddlewareNames(){return this.entries.map(e=>e.name)}};const xr=D(`auto-gc`);let Sr=`warming`,Cr=null,wr=0;function Tr(){let e=[...Fr()];if(e.length<10)return 0;e.sort((e,t)=>e-t);let t=Math.floor(e.length*.95);return e[Math.min(t,e.length-1)]}function Er(e){let t=Tr();if(t===0){Sr=`warming`;return}if(t>500){Sr=`degraded`;let n=Date.now();if(Cr&&n-Cr<36e5){xr.debug(`GC cooldown active — skipping`,{lastGcAgoMs:n-Cr});return}Cr=n,wr++,xr.warn(`p95 latency exceeds threshold, triggering GC`,{p95:t,cycle:wr}),e&&e().catch(e=>xr.error(`GC callback failed`,{err:String(e)}))}else t<200&&(Sr=`healthy`)}function Dr(){return{state:Sr,p95:Tr(),lastGcAt:Cr,gcCount:wr,bufferSize:Fr().length}}const Or=/key|token|secret|auth|password|bearer/i,kr=new Set([`eval`,`env`]);function Ar(e,t){if(kr.has(e))return JSON.stringify({_redacted:!0,tool:e});if(e===`http`&&t.headers&&typeof t.headers==`object`){let e={...t},n={};for(let[e,r]of Object.entries(t.headers))n[e]=Or.test(e)?`[REDACTED]`:r;return e.headers=n,JSON.stringify(e).slice(0,200)}return JSON.stringify(t).slice(0,200)}const jr=new Map,Mr=[];function Nr(e,t,n,r,i){let a=jr.get(e);a||(a={callCount:0,totalDurationMs:0,totalInputChars:0,totalOutputChars:0,errorCount:0},jr.set(e,a)),a.callCount++,a.totalDurationMs+=t,a.totalInputChars+=n,a.totalOutputChars+=r,i&&a.errorCount++,Mr.push(t),Mr.length>100&&Mr.shift(),Mr.length>=10&&Mr.length%20==0&&Er()}function Pr(){return Array.from(jr.entries()).map(([e,t])=>({tool:e,...t}))}function Fr(){return Mr}function Ir(){return async(e,t)=>{let n=Date.now(),r=JSON.stringify(e.args??{}).length;try{let i=await t(),a=Date.now()-n,o=JSON.stringify(i);return vt({ts:new Date().toISOString(),source:`mcp`,tool:e.toolName,input:Ar(e.toolName,e.args),durationMs:a,status:`ok`,output:o.slice(0,200)}),Nr(e.toolName,a,r,o.length,!1),i}catch(t){let i=Date.now()-n;throw vt({ts:new Date().toISOString(),source:`mcp`,tool:e.toolName,input:Ar(e.toolName,e.args),durationMs:i,status:`error`,output:t instanceof Error?t.message:String(t)}),Nr(e.toolName,i,r,0,!0),t}}}function Lr(e,t){e.resource(`aikit-curated-index`,`aikit://curated`,{description:`Index of all curated knowledge entries`,mimeType:`text/markdown`},async()=>{let e=(await t.list()).map(e=>`- [${e.title}](aikit://curated/${e.path}) — ${e.category}`);return{contents:[{uri:`aikit://curated`,text:`# Curated Knowledge Index\n\n${e.length>0?e.join(`
|
|
17
17
|
`):`_No curated entries yet._`}`,mimeType:`text/markdown`}]}});let n=new Jt(`aikit://curated/{+path}`,{list:async()=>({resources:(await t.list()).map(e=>({uri:`aikit://curated/${e.path}`,name:e.title,description:`[${e.category}] ${e.contentPreview?.slice(0,80)??``}`,mimeType:`text/markdown`}))})});e.resource(`aikit-curated-entry`,n,{description:`A curated knowledge entry`,mimeType:`text/markdown`},async(e,n)=>{let r=n.path;if(!r)throw Error(`Missing path variable in curated resource URI`);let i=await t.read(r);return{contents:[{uri:e.toString(),text:`---\ntitle: ${i.title}\ncategory: ${i.category}\ntags: ${i.tags?.join(`, `)??``}\nversion: ${i.version??1}\n---\n\n${i.content??i.contentPreview??``}`,mimeType:`text/markdown`}]}})}function Rr(e,t,n){e.resource(`aikit-status`,`aikit://status`,{description:`Current AI Kit status and statistics`,mimeType:`text/plain`},async()=>{let e=await t.getStats();return{contents:[{uri:`aikit://status`,text:`AI Kit: ${e.totalRecords} records from ${e.totalFiles} files. Last indexed: ${e.lastIndexedAt??`Never`}`,mimeType:`text/plain`}]}}),e.resource(`aikit-file-tree`,`aikit://file-tree`,{description:`List of all indexed source files`,mimeType:`text/plain`},async()=>({contents:[{uri:`aikit://file-tree`,text:(await t.listSourcePaths()).sort().join(`
|
|
18
|
-
`),mimeType:`text/plain`}]})),Lr(e,n)}const zr=[`er_push`,`er_pull`,`er_sync_status`],Br=[...zr,`er_update_policy`,`er_evolve_review`],Vr=new Set(Br);function Hr(e){return e.toolProfiles}const Ur=new Set(`changelog.check.checkpoint.codemod.compact.config.data_transform.delegate.diff_parse.digest.encode.env.eval.evidence_map.file_summary.forge_classify.git_context.graph.guide.health.http.knowledge.lane.measure.onboard.parse_output.present.process.produce_knowledge.queue.regex_test.reindex.rename.replay.restore.schema_validate.session_digest.scope_map.stash.status.stratum_card.test_run.time.watch.web_fetch.web_search.workset`.split(`.`)),Wr=5e3,Gr=new Set(`changelog.check.checkpoint.codemod.data_transform.delegate.diff_parse.encode.env.eval.evidence_map.flow.describe_tool.list_tools.search_tools.forge_classify.git_context.guide.present.health.http.lane.measure.parse_output.process.produce_knowledge.queue.regex_test.rename.replay.restore.schema_validate.session_digest.stash.status.test_run.time.watch.web_fetch.web_search.workset`.split(`.`)),R=`analyze.audit.blast_radius.changelog.check.checkpoint.codemod.compact.config.data_transform.dead_symbols.delegate.diff_parse.digest.encode.env.eval.evidence_map.file_summary.find.flow.forge_classify.forge_ground.git_context.graph.guide.health.http.knowledge.lane.describe_tool.list_tools.lookup.measure.onboard.parse_output.present.process.produce_knowledge.queue.regex_test.reindex.rename.replay.restore.schema_validate.scope_map.search.search_tools.session_digest.stash.status.stratum_card.symbol.test_run.time.trace.watch.web_fetch.web_search.workset`.split(`.`);function Kr(){let e=(async(e,t)=>{let n=await t(),r=e.toolConfig??{};if(r.outputSchema==null||n.structuredContent!=null)return n;try{n.structuredContent=qr(r.outputSchema)??{}}catch{n.structuredContent={}}return n});return e.critical=!0,e}function qr(e){if(!e)return{};if(e.anyOf){let t=e.anyOf.find(e=>e.type!==`null`);return t?qr(t):null}switch(e.type){case`object`:{let t={},n=e.properties??e.shape;if(n)for(let[e,r]of Object.entries(n))t[e]=qr(r);return t}case`array`:return[];case`string`:return``;case`number`:case`integer`:return 0;case`boolean`:return!1;case`nullable`:return null;case`optional`:return;case`record`:return{};default:return{}}}const z={search:{title:`Hybrid Search`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},find:{title:`Federated Find`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},symbol:{title:`Symbol Resolver — Cross-Module Definitions & References`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},trace:{title:`Data Flow Tracer — Cross-Module Call & Import Chains`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},scope_map:{title:`Task Scope Map`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},lookup:{title:`Chunk Lookup`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},dead_symbols:{title:`Dead Symbol Finder`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},file_summary:{title:`File Summary`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},analyze:{title:`Analyze`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`analysis`]},blast_radius:{title:`Blast Radius`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`analysis`,`search`]},knowledge:{title:`Knowledge`,annotations:{readOnlyHint:!1},category:[`knowledge`]},produce_knowledge:{title:`Produce Knowledge`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`knowledge`]},compact:{title:`Semantic Compactor`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`compression`]},digest:{title:`Multi-Source Digest`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`compression`]},stratum_card:{title:`Stratum Card`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`compression`]},forge_ground:{title:`FORGE Ground`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`forge`]},forge_classify:{title:`FORGE Classify`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`forge`]},evidence_map:{title:`Evidence Map`,annotations:{readOnlyHint:!1},category:[`forge`]},present:{title:`Rich Content Presenter`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`presentation`]},check:{title:`Typecheck & Lint`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`execution`]},test_run:{title:`Run Tests`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`execution`]},eval:{title:`Evaluate Code`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`execution`]},audit:{title:`Project Audit`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`execution`]},rename:{title:`Rename Symbol`,annotations:{readOnlyHint:!1,destructiveHint:!0},category:[`manipulation`]},restore:{title:`Restore`,annotations:{readOnlyHint:!1},category:[`manipulation`]},codemod:{title:`Codemod`,annotations:{readOnlyHint:!1,destructiveHint:!0},category:[`manipulation`]},data_transform:{title:`Data Transform`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`manipulation`]},stash:{title:`Stash Values`,annotations:{readOnlyHint:!1},category:[`session`]},checkpoint:{title:`Session Checkpoint`,annotations:{readOnlyHint:!1},category:[`session`]},session_digest:{title:`Session Digest`,annotations:{readOnlyHint:!0,idempotentHint:!1},category:[`session`]},workset:{title:`Workset Manager`,annotations:{readOnlyHint:!1},category:[`session`]},lane:{title:`Exploration Lane`,annotations:{readOnlyHint:!1},category:[`session`]},git_context:{title:`Git Context`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`git`]},diff_parse:{title:`Diff Parser`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`git`]},parse_output:{title:`Parse Build Output`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`git`]},process:{title:`Process Manager`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`process`]},watch:{title:`File Watcher`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`process`]},delegate:{title:`Delegate Task`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`process`]},config:{title:`Configuration Manager`,annotations:{readOnlyHint:!1},category:[`system`]},status:{title:`AI Kit Status`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},health:{title:`Health Check`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},reindex:{title:`Reindex`,annotations:{readOnlyHint:!1},category:[`system`]},onboard:{title:`Onboard Codebase`,annotations:{readOnlyHint:!1},category:[`system`]},graph:{title:`Code Knowledge Graph — Module & Symbol Relationships`,annotations:{readOnlyHint:!1},category:[`system`]},guide:{title:`Tool Guide`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},replay:{title:`Replay History`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},list_tools:{title:`List Available Tools`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`meta`]},describe_tool:{title:`Describe Tool`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`meta`]},search_tools:{title:`Search Tools`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`meta`]},changelog:{title:`Generate Changelog`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},regex_test:{title:`Regex Tester`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},encode:{title:`Encode / Decode`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},measure:{title:`Code Metrics`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},schema_validate:{title:`Schema Validator`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},env:{title:`Environment Info`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},time:{title:`Date & Time`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},web_fetch:{title:`Web Fetch`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`web`]},web_search:{title:`Web Search`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`web`]},http:{title:`HTTP Request`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`web`]},queue:{title:`Operation Queue`,annotations:{readOnlyHint:!1},category:[`queue`]},bridge_push:{title:`Bridge Push`,annotations:{readOnlyHint:!1},category:[`system`]},bridge_pull:{title:`Bridge Pull`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},bridge_sync:{title:`Bridge Sync Status`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},er_push:{title:`Enterprise Push`,annotations:{readOnlyHint:!1},category:[`system`]},er_pull:{title:`Enterprise Pull`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},er_sync_status:{title:`Enterprise Sync Status`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},er_update_policy:{title:`Enterprise Update Policy`,annotations:{readOnlyHint:!1},category:[`system`]},er_evolve_review:{title:`Enterprise Evolution Review`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},evolution_state:{title:`Evolution State`,annotations:{readOnlyHint:!1},category:[`system`]},policy_check:{title:`Policy Check`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},flow:{title:`Flow`,annotations:{readOnlyHint:!1},category:[`flow`]}};function B(e){return z[e]??{title:e,annotations:{readOnlyHint:!1},category:[]}}const Jr=Symbol(`toolPipelineState`);function Yr(e){return e[Jr]}function Xr(e,t){e[Jr]=t}function Zr(e,t,n=``){let r=Yr(e);if(r){r.pipeline=t,r.prefix=n;return}Xr(e,{originalRegisterTool:e.registerTool.bind(e),pipeline:t,prefix:n}),e.registerTool=(n,r,i)=>{let a=Yr(e),o=a?.prefix?`${a.prefix}${n}`:n;if(!i)return a?.originalRegisterTool(o,r);if((a?.pipeline??t).getMiddlewareNames().length===0)return a?.originalRegisterTool(o,r,i);let s=B(n),c=(a?.pipeline??t).wrap(n,i,r,s);return a?.originalRegisterTool(o,r,c)}}const Qr={analyze:1,audit:1,blast_radius:1,changelog:1,check:2,checkpoint:2,codemod:2,compact:1,config:0,data_transform:1,dead_symbols:1,delegate:3,describe_tool:1,diff_parse:1,digest:1,encode:1,env:0,eval:2,evidence_map:2,file_summary:1,find:1,flow:3,forge_classify:1,forge_ground:2,git_context:1,graph:1,guide:0,health:0,http:1,lane:2,list_tools:1,lookup:1,measure:1,onboard:3,parse_output:1,present:1,process:3,produce_knowledge:3,queue:3,regex_test:1,reindex:3,rename:2,replay:1,restore:2,schema_validate:1,scope_map:1,search:1,search_tools:1,session_digest:2,stash:2,status:0,stratum_card:1,symbol:1,test_run:2,time:0,trace:1,watch:3,web_fetch:1,web_search:1,workset:2};function $r(e,t){return e.filter(e=>(Qr[e]??0)<=t)}const ei=new Set([`status`,`config`,`guide`,`health`]),ti={full:{description:`All tools enabled (default)`,includeCategories:[]},safe:{description:`Read-only tools — no file/state modifications`,includeCategories:[`search`,`analysis`,`compression`,`utilities`,`system`,`git`,`flow`],excludeTools:[`reindex`,`onboard`]},research:{description:`Search, analysis, knowledge, and web access`,includeCategories:[`search`,`analysis`,`knowledge`,`compression`,`web`,`system`,`flow`]},minimal:{description:`Essential tools only — search, status, basic operations`,includeCategories:[`search`,`system`],includeTools:[`compact`,`file_summary`,`check`,`test_run`]},discovery:{description:`Full toolset plus discovery-oriented meta-tools for guided tool exploration`,includeCategories:[],includeTools:[`list_tools`,`describe_tool`,`search_tools`]}};function ni(e,t){let n=ti[e];if(n)return n;let r=t?.[e];if(r)return r;throw Error(`Unknown tool profile: ${e}`)}function ri(e,t,n){return t.includes(`*`)?!0:(n[e]?.category??[]).some(e=>t.includes(e))}function ii(e,t,n,r){if(t.includes(`*`)){for(let t of n)e.add(t);return}for(let i of n)ri(i,t,r)&&e.add(i)}function ai(e,t,n){if(t.includes(`*`)){e.clear();return}for(let r of[...e])ri(r,t,n)&&e.delete(r)}function oi(e,t,n){if(!e||e.length===0||e.includes(`*`))return new Set(t);let r=new Set;return ii(r,e,t,n),r}function si(e,t){return e===void 0?t:t===void 0?e:Math.min(e,t)}function ci(e,t,n=0,r=[]){if(n>10)throw Error(`Tool profile inheritance exceeded max depth 10: ${[...r,e].join(` -> `)}`);if(r.includes(e))throw Error(`Tool profile inheritance cycle detected: ${[...r,e].join(` -> `)}`);let i=ni(e,t);return si(i.extends?ci(i.extends,t,n+1,[...r,e]):void 0,i.maxTier)}function li(e,t,n,r){let i=(e,a,o)=>{if(a>10)throw Error(`Tool profile inheritance exceeded max depth 10: ${[...o,e].join(` -> `)}`);if(o.includes(e))throw Error(`Tool profile inheritance cycle detected: ${[...o,e].join(` -> `)}`);let s=ni(e,r),c=[...o,e],l=s.extends?i(s.extends,a+1,c):oi(s.includeCategories,t,n);s.extends&&s.includeCategories?.length&&ii(l,s.includeCategories,t,n),s.excludeCategories?.length&&ai(l,s.excludeCategories,n);for(let e of s.includeTools??[])l.add(e);for(let e of s.excludeTools??[])l.delete(e);return l},a=i(e,0,[]),o=ci(e,r);if(o!==void 0){let e=$r([...a],o);a.clear();for(let t of e)a.add(t)}for(let e of ei)a.add(e);return a}const ui=new Set([`search`,`analysis`,`knowledge`,`compression`,`forge`,`presentation`,`execution`,`manipulation`,`session`,`git`,`process`,`system`,`meta`,`utilities`,`web`,`queue`,`flow`]);function di(e,t,n,r){let i=li(process.env.AIKIT_TOOLSET||e.toolProfile||`full`,t,n,r);if(e.features&&e.features.length>0){let a=e.features.filter(e=>!ui.has(e));if(a.length>0)throw Error(`Unknown feature group(s): ${a.join(`, `)}. Valid categories: ${[...ui].join(`, `)}`);let o={description:`Synthetic profile from features config`,includeCategories:e.features},s=li(`_features`,t,n,{...r,_features:o});for(let e of i)!s.has(e)&&!ei.has(e)&&i.delete(e)}if(e.readOnly)for(let e of[...i])n[e]?.annotations?.readOnlyHint===!1&&!ei.has(e)&&i.delete(e);for(let e of ei)i.add(e);return i}const fi=I.object({totalRecords:I.number(),totalFiles:I.number(),lastIndexedAt:I.string().nullable(),onboarded:I.boolean(),onboardDir:I.string(),contentTypes:I.record(I.string(),I.number()),wasmAvailable:I.boolean(),graphStats:I.object({nodes:I.number(),edges:I.number()}).nullable(),curatedCount:I.number(),serverVersion:I.string(),scaffoldVersion:I.string().nullable(),workspaceScaffoldVersion:I.string().nullable(),upgradeAvailable:I.boolean(),storeBackend:I.string().optional(),storeDiagnostics:I.object({adapterType:I.string(),vectorSearchEnabled:I.boolean(),degradedMode:I.boolean(),dbPath:I.string(),dbSizeBytes:I.number().nullable(),embeddingDim:I.number()}).nullable().optional(),contextPressure:I.number().min(0).max(100).describe(`0–100 score indicating AI Kit saturation`)});I.object({entries:I.array(I.object({path:I.string(),title:I.string(),category:I.string(),tags:I.array(I.string()),version:I.number(),preview:I.string()})),totalCount:I.number()});const pi=I.object({ok:I.boolean(),checks:I.array(I.object({name:I.string(),ok:I.boolean(),message:I.string().optional()}))}),mi=I.object({summary:I.object({totalFiles:I.number(),totalLines:I.number(),totalCodeLines:I.number(),totalFunctions:I.number(),avgComplexity:I.number(),maxComplexity:I.object({value:I.number(),file:I.string()})}),files:I.array(I.object({path:I.string(),lines:I.number(),code:I.number(),complexity:I.number(),functions:I.number()}))}),hi=I.object({platform:I.string(),arch:I.string(),nodeVersion:I.string(),cwd:I.string(),cpus:I.number(),memoryFreeGb:I.number(),memoryTotalGb:I.number()}),gi=I.object({iso:I.string(),unix:I.number(),timezone:I.string(),formatted:I.string()}),_i=I.object({passed:I.boolean(),errorCount:I.number(),warningCount:I.number(),topErrors:I.array(I.string())}),vi=I.object({passed:I.boolean(),tsc:_i,biome:_i}),yi=I.object({name:I.string(),definedIn:I.object({path:I.string(),line:I.number(),kind:I.string(),signature:I.string().optional()}).nullable(),importedBy:I.array(I.object({path:I.string(),line:I.number(),importStatement:I.string()})),referencedIn:I.array(I.object({path:I.string(),line:I.number(),context:I.string(),scope:I.string().optional()})),graphContext:I.object({definingModule:I.string().optional(),importedByModules:I.array(I.string()),siblingSymbols:I.array(I.string())}).nullable()}),bi=I.object({sourcePath:I.string(),contentType:I.string(),score:I.number(),headingPath:I.string().optional(),startLine:I.number().optional(),endLine:I.number().optional(),origin:I.string().optional(),category:I.string().optional(),tags:I.array(I.string()).optional()}),xi=I.object({results:I.array(bi),totalResults:I.number(),searchMode:I.string(),query:I.string()}),Si=I.object({path:I.string(),line:I.number().optional(),matchType:I.string(),preview:I.string()}),Ci=I.object({matches:I.array(Si),totalMatches:I.number(),pattern:I.string(),truncated:I.boolean()}),wi=I.object({path:I.string(),relevance:I.number(),estimatedTokens:I.number(),focusLines:I.array(I.string()).optional()}),Ti=I.object({files:I.array(wi),totalFiles:I.number(),totalEstimatedTokens:I.number(),task:I.string()}),Ei=I.object({path:I.string(),impact:I.string(),reason:I.string()}),Di=I.object({changedFiles:I.array(I.string()),affectedFiles:I.array(Ei),totalAffected:I.number(),riskLevel:I.string()}),Oi=I.object({name:I.string(),passed:I.boolean(),message:I.string().optional(),severity:I.string().optional()}),ki=I.object({passed:I.boolean(),score:I.number(),checks:I.array(Oi),summary:I.string()}),Ai=I.object({id:I.string(),name:I.string(),type:I.string(),sourcePath:I.string().optional()}),ji=I.object({fromId:I.string(),toId:I.string(),type:I.string()}),Mi=I.object({nodes:I.array(Ai),edges:I.array(ji),totalNodes:I.number(),totalEdges:I.number(),query:I.string()}),Ni=I.object({symbols:I.array(I.object({name:I.string(),path:I.string(),line:I.number().optional(),kind:I.string()})),totalDead:I.number()});I.object({files:I.number(),packages:I.number(),languages:I.record(I.string(),I.number()),tree:I.string()});const Pi=I.object({path:I.string(),language:I.string(),lines:I.number(),imports:I.number(),exports:I.number(),functions:I.number(),classes:I.number()}),Fi=I.object({gitRoot:I.string(),branch:I.string(),commitCount:I.number(),hasUncommitted:I.boolean(),recentCommits:I.array(I.object({hash:I.string(),message:I.string(),author:I.string(),date:I.string()}))}),Ii=I.object({originalChars:I.number(),compressedChars:I.number(),ratio:I.number(),segmentsKept:I.number(),segmentsTotal:I.number()}),Li=I.object({passed:I.boolean(),totalTests:I.number(),passedTests:I.number(),failedTests:I.number(),skippedTests:I.number(),duration:I.number().describe(`Duration in milliseconds`),failures:I.array(I.object({name:I.string(),message:I.string(),file:I.string().optional()}))}),Ri=D(`utils:enrich`);async function V(e,t){let n={curated:[],graph:[]},r=t.limit??3,[i,a]=await Promise.allSettled([zi(e,t.query,r),Bi(e,t.filePath)]);return i.status===`fulfilled`?n.curated=i.value:Ri.debug(`Curated enrichment failed`,{error:i.reason}),a.status===`fulfilled`?n.graph=a.value:Ri.debug(`Graph enrichment failed`,{error:a.reason}),n}async function zi(e,t,n){if(!e.store||!t)return[];try{let r=await e.store.ftsSearch(t,{origin:`curated`,limit:n});if(r.length>0)return r.map(e=>Vi(e.record));if(e.embedder){let r=await e.embedder.embedQuery(t);return(await e.store.search(r,{origin:`curated`,limit:n,minScore:.3})).map(e=>Vi(e.record))}return[]}catch(e){return Ri.debug(`Curated enrichment failed`,{error:e}),[]}}async function Bi(e,t){if(!e.graphStore||!t)return[];try{let n=await e.graphStore.findNodes({sourcePath:t,limit:1});if(n.length===0){let r=t.split(/[/\\]/).pop()?.replace(/\.\w+$/,``)||``;if(!r)return[];let i=await e.graphStore.findNodes({namePattern:r,type:`module`,limit:1});if(i.length===0)return[];n.push(i[0])}let r=n[0],i=await e.graphStore.getNeighbors(r.id,{direction:`both`,limit:10}),a=[];for(let e of i.edges){let t=e.fromId===r.id?e.toId:e.fromId,n=i.nodes.find(e=>e.id===t);if(!n)continue;let o=e.fromId===r.id?`->`:`<-`;a.push(`${o} ${e.type}: ${n.name} (${n.type})`)}return a}catch(e){return Ri.debug(`Graph enrichment failed`,{error:e}),[]}}function H(e){let t=[];if(e.curated.length>0){t.push(`**Curated Knowledge:**`);for(let n of e.curated)t.push(`- ${n}`)}if(e.graph.length>0){t.push(`**Graph Context:**`);for(let n of e.graph)t.push(`- ${n}`)}return t.length===0?``:`\n\n---\n## Enrichment\n${t.join(`
|
|
18
|
+
`),mimeType:`text/plain`}]})),Lr(e,n)}const zr=[`er_push`,`er_pull`,`er_sync_status`],Br=[...zr,`er_update_policy`,`er_evolve_review`],Vr=new Set(Br);function Hr(e){return e.toolProfiles}const Ur=new Set(`changelog.check.checkpoint.codemod.compact.config.data_transform.delegate.diff_parse.digest.encode.env.eval.evidence_map.file_summary.forge_classify.git_context.graph.guide.health.http.knowledge.lane.measure.onboard.parse_output.present.process.produce_knowledge.queue.regex_test.reindex.rename.replay.restore.schema_validate.session_digest.scope_map.stash.status.stratum_card.test_run.time.watch.web_fetch.web_search.workset`.split(`.`)),Wr=5e3,Gr=new Set(`changelog.check.checkpoint.codemod.data_transform.delegate.diff_parse.encode.env.eval.evidence_map.flow.describe_tool.list_tools.search_tools.forge_classify.git_context.guide.present.health.http.lane.measure.parse_output.process.produce_knowledge.queue.regex_test.rename.replay.restore.schema_validate.session_digest.stash.status.test_run.time.watch.web_fetch.web_search.workset`.split(`.`)),R=`analyze.audit.blast_radius.changelog.check.checkpoint.codemod.compact.config.data_transform.dead_symbols.delegate.diff_parse.digest.encode.env.eval.evidence_map.file_summary.find.flow.forge_classify.forge_ground.git_context.graph.guide.health.http.knowledge.lane.describe_tool.list_tools.lookup.measure.onboard.parse_output.present.process.produce_knowledge.queue.regex_test.reindex.rename.replay.restore.schema_validate.scope_map.search.search_tools.session_digest.stash.status.stratum_card.symbol.test_run.time.trace.watch.web_fetch.web_search.workset`.split(`.`);function Kr(){let e=(async(e,t)=>{let n=await t(),r=e.toolConfig??{};if(r.outputSchema==null||n.structuredContent!=null)return n;try{n.structuredContent=qr(r.outputSchema)??{}}catch{n.structuredContent={}}return n});return e.critical=!0,e}function qr(e){if(!e)return{};if(e.anyOf){let t=e.anyOf.find(e=>e.type!==`null`);return t?qr(t):null}switch(e.type){case`object`:{let t={},n=e.properties??e.shape;if(n)for(let[e,r]of Object.entries(n))t[e]=qr(r);return t}case`array`:return[];case`string`:return``;case`number`:case`integer`:return 0;case`boolean`:return!1;case`nullable`:return null;case`optional`:return;case`record`:return{};default:return{}}}const z={search:{title:`Hybrid Search`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},find:{title:`Federated Find`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},symbol:{title:`Symbol Resolver — Cross-Module Definitions & References`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},trace:{title:`Data Flow Tracer — Cross-Module Call & Import Chains`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},scope_map:{title:`Task Scope Map`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},lookup:{title:`Chunk Lookup`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},dead_symbols:{title:`Dead Symbol Finder`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},file_summary:{title:`File Summary`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`search`]},analyze:{title:`Analyze`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`analysis`]},blast_radius:{title:`Blast Radius`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`analysis`,`search`]},knowledge:{title:`Knowledge`,annotations:{readOnlyHint:!1},category:[`knowledge`]},produce_knowledge:{title:`Produce Knowledge`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`knowledge`]},compact:{title:`Semantic Compactor`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`compression`]},digest:{title:`Multi-Source Digest`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`compression`]},stratum_card:{title:`Stratum Card`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`compression`]},forge_ground:{title:`FORGE Ground`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`forge`]},forge_classify:{title:`FORGE Classify`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`forge`]},evidence_map:{title:`Evidence Map`,annotations:{readOnlyHint:!1},category:[`forge`]},present:{title:`Rich Content Presenter`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`presentation`]},check:{title:`Typecheck & Lint`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`execution`]},test_run:{title:`Run Tests`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`execution`]},eval:{title:`Evaluate Code`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`execution`]},audit:{title:`Project Audit`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`execution`]},rename:{title:`Rename Symbol`,annotations:{readOnlyHint:!1,destructiveHint:!0},category:[`manipulation`]},restore:{title:`Restore`,annotations:{readOnlyHint:!1},category:[`manipulation`]},codemod:{title:`Codemod`,annotations:{readOnlyHint:!1,destructiveHint:!0},category:[`manipulation`]},data_transform:{title:`Data Transform`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`manipulation`]},stash:{title:`Stash Values`,annotations:{readOnlyHint:!1},category:[`session`]},checkpoint:{title:`Session Checkpoint`,annotations:{readOnlyHint:!1},category:[`session`]},session_digest:{title:`Session Digest`,annotations:{readOnlyHint:!0,idempotentHint:!1},category:[`session`]},workset:{title:`Workset Manager`,annotations:{readOnlyHint:!1},category:[`session`]},lane:{title:`Exploration Lane`,annotations:{readOnlyHint:!1},category:[`session`]},git_context:{title:`Git Context`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`git`]},diff_parse:{title:`Diff Parser`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`git`]},parse_output:{title:`Parse Build Output`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`git`]},process:{title:`Process Manager`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`process`]},watch:{title:`File Watcher`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`process`]},delegate:{title:`Delegate Task`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`process`]},config:{title:`Configuration Manager`,annotations:{readOnlyHint:!1},category:[`system`]},status:{title:`AI Kit Status`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},health:{title:`Health Check`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},reindex:{title:`Reindex`,annotations:{readOnlyHint:!1},category:[`system`]},onboard:{title:`Onboard Codebase`,annotations:{readOnlyHint:!1},category:[`system`]},graph:{title:`Code Knowledge Graph — Module & Symbol Relationships`,annotations:{readOnlyHint:!1},category:[`system`]},guide:{title:`Tool Guide`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},replay:{title:`Replay History`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},list_tools:{title:`List Available Tools`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`meta`]},describe_tool:{title:`Describe Tool`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`meta`]},search_tools:{title:`Search Tools`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`meta`]},changelog:{title:`Generate Changelog`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},regex_test:{title:`Regex Tester`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},encode:{title:`Encode / Decode`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},measure:{title:`Code Metrics`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},schema_validate:{title:`Schema Validator`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},env:{title:`Environment Info`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},time:{title:`Date & Time`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`utilities`]},web_fetch:{title:`Web Fetch`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`web`]},web_search:{title:`Web Search`,annotations:{readOnlyHint:!0,openWorldHint:!0},category:[`web`]},http:{title:`HTTP Request`,annotations:{readOnlyHint:!1,openWorldHint:!0},category:[`web`]},queue:{title:`Operation Queue`,annotations:{readOnlyHint:!1},category:[`queue`]},bridge_push:{title:`Bridge Push`,annotations:{readOnlyHint:!1},category:[`system`]},bridge_pull:{title:`Bridge Pull`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},bridge_sync:{title:`Bridge Sync Status`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},er_push:{title:`Enterprise Push`,annotations:{readOnlyHint:!1},category:[`system`]},er_pull:{title:`Enterprise Pull`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},er_sync_status:{title:`Enterprise Sync Status`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},er_update_policy:{title:`Enterprise Update Policy`,annotations:{readOnlyHint:!1},category:[`system`]},er_evolve_review:{title:`Enterprise Evolution Review`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},evolution_state:{title:`Evolution State`,annotations:{readOnlyHint:!1},category:[`system`]},policy_check:{title:`Policy Check`,annotations:{readOnlyHint:!0,idempotentHint:!0},category:[`system`]},flow:{title:`Flow`,annotations:{readOnlyHint:!1},category:[`flow`]}};function B(e){return z[e]??{title:e,annotations:{readOnlyHint:!1},category:[]}}const Jr=Symbol(`toolPipelineState`);function Yr(e){return e[Jr]}function Xr(e,t){e[Jr]=t}function Zr(e,t,n=``){let r=Yr(e);if(r){r.pipeline=t,r.prefix=n;return}Xr(e,{originalRegisterTool:e.registerTool.bind(e),pipeline:t,prefix:n}),e.registerTool=(n,r,i)=>{let a=Yr(e),o=a?.prefix?`${a.prefix}${n}`:n;if(!i)return a?.originalRegisterTool(o,r);if((a?.pipeline??t).getMiddlewareNames().length===0)return a?.originalRegisterTool(o,r,i);let s=B(n),c=(a?.pipeline??t).wrap(n,i,r,s);return a?.originalRegisterTool(o,r,c)}}const Qr={analyze:1,audit:1,blast_radius:1,changelog:1,check:2,checkpoint:2,codemod:2,compact:1,config:0,data_transform:1,dead_symbols:1,delegate:3,describe_tool:1,diff_parse:1,digest:1,encode:1,env:0,eval:2,evidence_map:2,file_summary:1,find:1,flow:3,forge_classify:1,forge_ground:2,git_context:1,graph:1,guide:0,health:0,http:1,lane:2,list_tools:1,lookup:1,measure:1,onboard:3,parse_output:1,present:1,process:3,produce_knowledge:3,queue:3,regex_test:1,reindex:3,rename:2,replay:1,restore:2,schema_validate:1,scope_map:1,search:1,search_tools:1,session_digest:2,stash:2,status:0,stratum_card:1,symbol:1,test_run:2,time:0,trace:1,watch:3,web_fetch:1,web_search:1,workset:2};function $r(e,t){return e.filter(e=>(Qr[e]??0)<=t)}const ei=new Set([`status`,`config`,`guide`,`health`]),ti={full:{description:`All tools enabled (default)`,includeCategories:[]},safe:{description:`Read-only tools — no file/state modifications`,includeCategories:[`search`,`analysis`,`compression`,`utilities`,`system`,`git`,`flow`],excludeTools:[`reindex`,`onboard`]},research:{description:`Search, analysis, knowledge, and web access`,includeCategories:[`search`,`analysis`,`knowledge`,`compression`,`web`,`system`,`flow`]},minimal:{description:`Essential tools only — search, status, basic operations`,includeCategories:[`search`,`system`],includeTools:[`compact`,`file_summary`,`check`,`test_run`]},discovery:{description:`Full toolset plus discovery-oriented meta-tools for guided tool exploration`,includeCategories:[],includeTools:[`list_tools`,`describe_tool`,`search_tools`]}};function ni(e,t){let n=ti[e];if(n)return n;let r=t?.[e];if(r)return r;throw Error(`Unknown tool profile: ${e}`)}function ri(e,t,n){return t.includes(`*`)?!0:(n[e]?.category??[]).some(e=>t.includes(e))}function ii(e,t,n,r){if(t.includes(`*`)){for(let t of n)e.add(t);return}for(let i of n)ri(i,t,r)&&e.add(i)}function ai(e,t,n){if(t.includes(`*`)){e.clear();return}for(let r of[...e])ri(r,t,n)&&e.delete(r)}function oi(e,t,n){if(!e||e.length===0||e.includes(`*`))return new Set(t);let r=new Set;return ii(r,e,t,n),r}function si(e,t){return e===void 0?t:t===void 0?e:Math.min(e,t)}function ci(e,t,n=0,r=[]){if(n>10)throw Error(`Tool profile inheritance exceeded max depth 10: ${[...r,e].join(` -> `)}`);if(r.includes(e))throw Error(`Tool profile inheritance cycle detected: ${[...r,e].join(` -> `)}`);let i=ni(e,t);return si(i.extends?ci(i.extends,t,n+1,[...r,e]):void 0,i.maxTier)}function li(e,t,n,r){let i=(e,a,o)=>{if(a>10)throw Error(`Tool profile inheritance exceeded max depth 10: ${[...o,e].join(` -> `)}`);if(o.includes(e))throw Error(`Tool profile inheritance cycle detected: ${[...o,e].join(` -> `)}`);let s=ni(e,r),c=[...o,e],l=s.extends?i(s.extends,a+1,c):oi(s.includeCategories,t,n);s.extends&&s.includeCategories?.length&&ii(l,s.includeCategories,t,n),s.excludeCategories?.length&&ai(l,s.excludeCategories,n);for(let e of s.includeTools??[])l.add(e);for(let e of s.excludeTools??[])l.delete(e);return l},a=i(e,0,[]),o=ci(e,r);if(o!==void 0){let e=$r([...a],o);a.clear();for(let t of e)a.add(t)}for(let e of ei)a.add(e);return a}const ui=new Set([`search`,`analysis`,`knowledge`,`compression`,`forge`,`presentation`,`execution`,`manipulation`,`session`,`git`,`process`,`system`,`meta`,`utilities`,`web`,`queue`,`flow`]);function di(e,t,n,r){let i=li(process.env.AIKIT_TOOLSET||e.toolProfile||`full`,t,n,r);if(e.features&&e.features.length>0){let a=e.features.filter(e=>!ui.has(e));if(a.length>0)throw Error(`Unknown feature group(s): ${a.join(`, `)}. Valid categories: ${[...ui].join(`, `)}`);let o={description:`Synthetic profile from features config`,includeCategories:e.features},s=li(`_features`,t,n,{...r,_features:o});for(let e of i)!s.has(e)&&!ei.has(e)&&i.delete(e)}if(e.readOnly)for(let e of[...i])n[e]?.annotations?.readOnlyHint===!1&&!ei.has(e)&&i.delete(e);for(let e of ei)i.add(e);return i}const fi=I.object({totalRecords:I.number(),totalFiles:I.number(),lastIndexedAt:I.string().nullable(),onboarded:I.boolean(),onboardDir:I.string(),contentTypes:I.record(I.string(),I.number()),wasmAvailable:I.boolean(),graphStats:I.object({nodes:I.number(),edges:I.number()}).nullable(),curatedCount:I.number(),serverVersion:I.string(),scaffoldVersion:I.string().nullable(),workspaceScaffoldVersion:I.string().nullable(),upgradeAvailable:I.boolean(),storeBackend:I.string().optional(),storeDiagnostics:I.object({adapterType:I.string(),vectorSearchEnabled:I.boolean(),degradedMode:I.boolean(),dbPath:I.string(),dbSizeBytes:I.number().nullable(),embeddingDim:I.number(),vectorDtype:I.string()}).nullable().optional(),contextPressure:I.number().min(0).max(100).describe(`0–100 score indicating AI Kit saturation`)});I.object({entries:I.array(I.object({path:I.string(),title:I.string(),category:I.string(),tags:I.array(I.string()),version:I.number(),preview:I.string()})),totalCount:I.number()});const pi=I.object({ok:I.boolean(),checks:I.array(I.object({name:I.string(),ok:I.boolean(),message:I.string().optional()}))}),mi=I.object({summary:I.object({totalFiles:I.number(),totalLines:I.number(),totalCodeLines:I.number(),totalFunctions:I.number(),avgComplexity:I.number(),maxComplexity:I.object({value:I.number(),file:I.string()})}),files:I.array(I.object({path:I.string(),lines:I.number(),code:I.number(),complexity:I.number(),functions:I.number()}))}),hi=I.object({platform:I.string(),arch:I.string(),nodeVersion:I.string(),cwd:I.string(),cpus:I.number(),memoryFreeGb:I.number(),memoryTotalGb:I.number()}),gi=I.object({iso:I.string(),unix:I.number(),timezone:I.string(),formatted:I.string()}),_i=I.object({passed:I.boolean(),errorCount:I.number(),warningCount:I.number(),topErrors:I.array(I.string())}),vi=I.object({passed:I.boolean(),tsc:_i,biome:_i}),yi=I.object({name:I.string(),definedIn:I.object({path:I.string(),line:I.number(),kind:I.string(),signature:I.string().optional()}).nullable(),importedBy:I.array(I.object({path:I.string(),line:I.number(),importStatement:I.string()})),referencedIn:I.array(I.object({path:I.string(),line:I.number(),context:I.string(),scope:I.string().optional()})),graphContext:I.object({definingModule:I.string().optional(),importedByModules:I.array(I.string()),siblingSymbols:I.array(I.string())}).nullable()}),bi=I.object({sourcePath:I.string(),contentType:I.string(),score:I.number(),headingPath:I.string().optional(),startLine:I.number().optional(),endLine:I.number().optional(),origin:I.string().optional(),category:I.string().optional(),tags:I.array(I.string()).optional()}),xi=I.object({results:I.array(bi),totalResults:I.number(),searchMode:I.string(),query:I.string()}),Si=I.object({path:I.string(),line:I.number().optional(),matchType:I.string(),preview:I.string()}),Ci=I.object({matches:I.array(Si),totalMatches:I.number(),pattern:I.string(),truncated:I.boolean()}),wi=I.object({path:I.string(),relevance:I.number(),estimatedTokens:I.number(),focusLines:I.array(I.string()).optional()}),Ti=I.object({files:I.array(wi),totalFiles:I.number(),totalEstimatedTokens:I.number(),task:I.string()}),Ei=I.object({path:I.string(),impact:I.string(),reason:I.string()}),Di=I.object({changedFiles:I.array(I.string()),affectedFiles:I.array(Ei),totalAffected:I.number(),riskLevel:I.string()}),Oi=I.object({name:I.string(),passed:I.boolean(),message:I.string().optional(),severity:I.string().optional()}),ki=I.object({passed:I.boolean(),score:I.number(),checks:I.array(Oi),summary:I.string()}),Ai=I.object({id:I.string(),name:I.string(),type:I.string(),sourcePath:I.string().optional()}),ji=I.object({fromId:I.string(),toId:I.string(),type:I.string()}),Mi=I.object({nodes:I.array(Ai),edges:I.array(ji),totalNodes:I.number(),totalEdges:I.number(),query:I.string()}),Ni=I.object({symbols:I.array(I.object({name:I.string(),path:I.string(),line:I.number().optional(),kind:I.string()})),totalDead:I.number()});I.object({files:I.number(),packages:I.number(),languages:I.record(I.string(),I.number()),tree:I.string()});const Pi=I.object({path:I.string(),language:I.string(),lines:I.number(),imports:I.number(),exports:I.number(),functions:I.number(),classes:I.number()}),Fi=I.object({gitRoot:I.string(),branch:I.string(),commitCount:I.number(),hasUncommitted:I.boolean(),recentCommits:I.array(I.object({hash:I.string(),message:I.string(),author:I.string(),date:I.string()}))}),Ii=I.object({originalChars:I.number(),compressedChars:I.number(),ratio:I.number(),segmentsKept:I.number(),segmentsTotal:I.number()}),Li=I.object({passed:I.boolean(),totalTests:I.number(),passedTests:I.number(),failedTests:I.number(),skippedTests:I.number(),duration:I.number().describe(`Duration in milliseconds`),failures:I.array(I.object({name:I.string(),message:I.string(),file:I.string().optional()}))}),Ri=D(`utils:enrich`);async function V(e,t){let n={curated:[],graph:[]},r=t.limit??3,[i,a]=await Promise.allSettled([zi(e,t.query,r),Bi(e,t.filePath)]);return i.status===`fulfilled`?n.curated=i.value:Ri.debug(`Curated enrichment failed`,{error:i.reason}),a.status===`fulfilled`?n.graph=a.value:Ri.debug(`Graph enrichment failed`,{error:a.reason}),n}async function zi(e,t,n){if(!e.store||!t)return[];try{let r=await e.store.ftsSearch(t,{origin:`curated`,limit:n});if(r.length>0)return r.map(e=>Vi(e.record));if(e.embedder){let r=await e.embedder.embedQuery(t);return(await e.store.search(r,{origin:`curated`,limit:n,minScore:.3})).map(e=>Vi(e.record))}return[]}catch(e){return Ri.debug(`Curated enrichment failed`,{error:e}),[]}}async function Bi(e,t){if(!e.graphStore||!t)return[];try{let n=await e.graphStore.findNodes({sourcePath:t,limit:1});if(n.length===0){let r=t.split(/[/\\]/).pop()?.replace(/\.\w+$/,``)||``;if(!r)return[];let i=await e.graphStore.findNodes({namePattern:r,type:`module`,limit:1});if(i.length===0)return[];n.push(i[0])}let r=n[0],i=await e.graphStore.getNeighbors(r.id,{direction:`both`,limit:10}),a=[];for(let e of i.edges){let t=e.fromId===r.id?e.toId:e.fromId,n=i.nodes.find(e=>e.id===t);if(!n)continue;let o=e.fromId===r.id?`->`:`<-`;a.push(`${o} ${e.type}: ${n.name} (${n.type})`)}return a}catch(e){return Ri.debug(`Graph enrichment failed`,{error:e}),[]}}function H(e){let t=[];if(e.curated.length>0){t.push(`**Curated Knowledge:**`);for(let n of e.curated)t.push(`- ${n}`)}if(e.graph.length>0){t.push(`**Graph Context:**`);for(let n of e.graph)t.push(`- ${n}`)}return t.length===0?``:`\n\n---\n## Enrichment\n${t.join(`
|
|
19
19
|
`)}`}function Vi(e){let t=Hi(e.metadata,`title`)||e.sourcePath||`Untitled`;return`[${Hi(e.metadata,`category`)}] ${t}: ${e.content.slice(0,200)}`}function Hi(e,t){let n=e?.[t];return typeof n==`string`?n:``}function U(e,t){return{content:[{type:`text`,text:`[ERROR:${e}] ${t}`}],isError:!0}}const Ui=D(`tools`),Wi=I.number().min(100).max(5e4).optional().describe(`Maximum token budget for the response. When set, output is truncated to fit.`);function Gi(e,t){return t?zt(e,t):e}function Ki(){let e=[];return sn.get()||e.push(`Tree-sitter unavailable — using regex fallback, symbol/pattern confidence reduced`),e.length===0?``:`\n\n> **⚠ Caveats:** ${e.join(`; `)}`}function qi(e){return(e??[]).map(e=>{if(typeof e==`string`)return e;if(e&&typeof e==`object`&&`path`in e)return typeof e.path==`string`?e.path:void 0}).filter(e=>!!e)}function Ji(e){let t=[],n=e.filter(e=>/\.(ts|tsx|js|jsx)$/.test(e)&&/(service|store|model|schema|migration)/i.test(e)),r=e.filter(e=>/\.(ts|tsx|js|jsx)$/.test(e)&&!n.includes(e)),i=e.filter(e=>!/\.(ts|tsx|js|jsx)$/.test(e));return(n.length>0||r.length>0||i.length>0)&&(t.push(`
|
|
20
20
|
|
|
21
21
|
### Risk Assessment`),n.length>0&&t.push(`- 🔴 **High risk** (${n.length}): ${n.slice(0,5).map(e=>`\`${e}\``).join(`, `)}`),r.length>0&&t.push(`- 🟡 **Medium risk** (${r.length}): source files`),i.length>0&&t.push(`- 🟢 **Low risk** (${i.length}): non-source files`)),t.join(`
|
|
@@ -1256,7 +1256,7 @@ Use \`status({})\` to check smart indexing queue status.`}]};let l=xa(c).createT
|
|
|
1256
1256
|
---
|
|
1257
1257
|
|
|
1258
1258
|
`),A=(c===`hybrid`?`hybrid (vector + keyword RRF)`:c===`keyword`?`keyword (FTS)`:`semantic (vector)`)+T,M=vu(b,e),te=M.length>0?`\n_Distinctive terms: ${M.map(e=>`\`${e}\``).join(`, `)}_`:``,N=await bu(n,b),P=[];if(b.length===0)P.push("`reindex` — no results found, index may be stale"),P.push("`find` — try federated search with glob/regex");else{let e=b[0]?.record.sourcePath;e&&P.push(`\`lookup\` — see all chunks from \`${e}\``),P.push("`symbol` — resolve a specific symbol from the results"),P.push("`compact` — compress a result file for focused reading")}let ne=[O?`${O}\n\n`:``,N?`${N}\n\n`:``,ee,`\n\n---\n_Search mode: ${A} | ${b.length} results_${te}`,`\n_Next: ${P.join(` | `)}_`],re=C+ne.join(``);g&&(re=zt(re,g));let ae=new Set,oe=[];for(let e of b){if(e.record.origin!==`curated`||e.record.sourcePath.startsWith(`[`))continue;let t=Ts(e.record.sourcePath);if(!t)continue;let n=Cs(t,e.record.headingPath??t);n&&!ae.has(n.uri)&&(ae.add(n.uri),oe.push(n))}return{content:[{type:`text`,text:re},...oe],structuredContent:{results:b.map(e=>({sourcePath:e.record.sourcePath,contentType:e.record.contentType,score:e.score,...e.record.headingPath?{headingPath:e.record.headingPath}:{},...e.record.startLine?{startLine:e.record.startLine}:{},...e.record.endLine?{endLine:e.record.endLine}:{},...e.record.origin===`indexed`?{}:{origin:e.record.origin},...e.record.category?{category:e.record.category}:{},...e.record.tags?.length?{tags:e.record.tags}:{}})),totalResults:b.length,searchMode:c,query:e}}}catch(e){return pu.error(`Search failed`,j(e)),U(`INTERNAL`,`Search failed: ${e instanceof Error?e.message:String(e)}`)}})}const Su=D(`tools`);function Cu(e,t){let n=B(`session_digest`);e.registerTool(`session_digest`,{title:n.title,description:`Compress the current session's tool trajectory into a focused digest. Aggregates replay log, stash state, and checkpoints. Supports deterministic and LLM-assisted (sampling) modes with configurable token budget.`,inputSchema:{scope:I.enum([`tools`,`stash`,`all`]).default(`all`).describe(`What to include: tools (replay only), stash (stash + checkpoints only), or all`),since:I.string().optional().describe(`ISO timestamp — only include activity after this time`),last:I.number().min(1).max(500).optional().describe(`Max replay entries to consider (default: 50)`),focus:I.string().optional().describe(`Focus query — prioritize entries matching this topic`),mode:I.enum([`deterministic`,`sampling`]).default(`deterministic`).describe(`Summary mode: deterministic (fast, template-based) or sampling (LLM-assisted, richer)`),token_budget:I.number().min(100).max(8e3).default(2e3).describe(`Target token budget for the digest output`),persist:I.boolean().default(!0).describe(`Auto-save digest to stash for crash recovery`)},annotations:n.annotations},async({scope:e,since:n,last:r,focus:i,mode:a,token_budget:o,persist:s})=>{try{let c={scope:e,since:n,last:r,focus:i,mode:a,tokenBudget:o,persist:s};return{content:[{type:`text`,text:(a===`sampling`&&t?.available?await Dt(c,async(e,n,r)=>(await t.createMessage({prompt:e,systemPrompt:n,maxTokens:r})).text):Et(c)).digest}]}}catch(e){return Su.error(`Session digest failed`,j(e)),U(`INTERNAL`,`Session digest failed: ${e instanceof Error?e.message:String(e)}`)}})}const wu=D(`tools`);function Tu(e,t,n,r=15e3){let i,a=new Promise(e=>{i=setTimeout(()=>{wu.warn(`Status sub-operation "${n}" timed out after ${r}ms`),e({value:t,timedOut:!0})},r)});return Promise.race([e.then(e=>(clearTimeout(i),{value:e,timedOut:!1}),e=>(clearTimeout(i),wu.warn(`Status sub-operation "${n}" failed: ${e instanceof Error?e.message:String(e)}`),{value:t,timedOut:!1})),a])}const Eu=5*6e4;let Du=null,Ou=null;function ku(e,t,n,r){let i=Math.min(e/2e4,1),a=Math.min((t+n)/5e4,1),o=Math.min(r/200,1);return Math.round(i*40+a*35+o*25)}function Au(){let e=Date.now();if(Du&&e-Du.ts<Eu)return Du.value;try{let t=_(Cn(),`.copilot`,`.aikit-scaffold.json`);if(!a(t))return Du={value:null,ts:e},null;let n=JSON.parse(s(t,`utf-8`)).version??null;return Du={value:n,ts:e},n}catch{return Du={value:null,ts:e},null}}function ju(){let e=Date.now();if(Ou&&e-Ou.ts<Eu)return Ou.value;try{let t=_(process.cwd(),`.github`,`.aikit-scaffold.json`);if(!a(t))return Ou={value:null,ts:e},null;let n=JSON.parse(s(t,`utf-8`)).version??null;return Ou={value:n,ts:e},n}catch{return Ou={value:null,ts:e},null}}function Mu(e){let t=B(`status`);e.registerTool(`status`,{title:t.title,description:`Get the current status and statistics of the AI Kit index.`,outputSchema:fi,annotations:t.annotations},async()=>{let e=r(),t=Au(),a=ju(),o=t!=null&&t!==e,s=a!=null&&a!==e,c=[`## AI Kit Status`,``,`⏳ **AI Kit is initializing** — index stats will be available shortly.`,``,`### Runtime`,`- **Tree-sitter (WASM)**: ${sn.get()?`✅ Available (AST analysis)`:`⚠ Unavailable (regex fallback)`}`,``,`### Version`,`- **Server**: ${e}`,`- **Scaffold (user)**: ${t??`not installed`}`,`- **Scaffold (workspace)**: ${a??`not installed`}`];if(o||s){let r=i(),l=[];o&&l.push(`user scaffold v${t}`),s&&l.push(`workspace scaffold v${a}`);let u=l.join(`, `);r.state===`success`?c.push(``,`### ✅ Upgrade Applied`,`- Server v${e} — ${u} auto-upgraded successfully.`,`- _Restart the MCP server to use the updated version._`):r.state===`pending`?c.push(``,`### ⏳ Upgrade In Progress`,`- Server v${e} ≠ ${u}`,`- Auto-upgrade is running in the background…`):r.state===`failed`?(n(),c.push(``,`### ⬆ Upgrade Available (auto-upgrade failed, retrying)`,`- Server v${e} ≠ ${u}`,`- Error: ${r.error??`unknown`}`)):(n(),c.push(``,`### ⬆ Upgrade Available`,`- Server v${e} ≠ ${u}`,`- Auto-upgrade triggered — check again shortly.`))}let l={totalRecords:0,totalFiles:0,lastIndexedAt:null,onboarded:!1,onboardDir:``,contentTypes:{},wasmAvailable:!!sn.get(),graphStats:null,curatedCount:0,serverVersion:e,scaffoldVersion:t??null,workspaceScaffoldVersion:a??null,upgradeAvailable:o||s,contextPressure:0};return{content:[{type:`text`,text:c.join(`
|
|
1259
|
-
`)}],structuredContent:l}})}function Nu(e,t,o,s,c,l,u,f){let p=B(`status`);e.registerTool(`status`,{title:p.title,description:`Get the current status and statistics of the AI Kit index.`,outputSchema:fi,annotations:p.annotations},async()=>{let e=[];try{let[p,m]=await Promise.all([Tu(t.getStats(),{totalRecords:0,totalFiles:0,lastIndexedAt:null,contentTypeBreakdown:{}},`store.getStats`),Tu(t.listSourcePaths(),[],`store.listSourcePaths`)]),h=p.value;p.timedOut&&e.push(`⚠ Index stats timed out — values may be incomplete`);let g=m.value;m.timedOut&&e.push(`⚠ File listing timed out`);let v=null,b=0,x=[`## AI Kit Status`,``,`- **Total Records**: ${h.totalRecords}`,`- **Total Files**: ${h.totalFiles}`,`- **Last Indexed**: ${h.lastIndexedAt??`Never`}`,``,`### Content Types`,...Object.entries(h.contentTypeBreakdown).map(([e,t])=>`- ${e}: ${t}`),``,`### Indexed Files`,...g.slice(0,50).map(e=>`- ${e}`),g.length>50?`\n... and ${g.length-50} more files`:``];if(o)try{let t=await Tu(o.getStats(),{nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}},`graphStore.getStats`);if(t.timedOut)e.push(`⚠ Graph stats timed out`),x.push(``,`### Knowledge Graph`,`- Graph stats timed out`);else{let e=t.value;v={nodes:e.nodeCount,edges:e.edgeCount},x.push(``,`### Knowledge Graph`,`- **Nodes**: ${e.nodeCount}`,`- **Edges**: ${e.edgeCount}`,...Object.entries(e.nodeTypes).map(([e,t])=>` - ${e}: ${t}`));try{let e=await Tu(o.validate(),{valid:!0,danglingEdges:[],orphanNodes:[],stats:{nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}}},`graphStore.validate`);if(!e.timedOut){let t=e.value;t.valid||x.push(`- **⚠ Integrity Issues**: ${t.danglingEdges.length} dangling edges`),t.orphanNodes.length>0&&x.push(`- **Orphan nodes**: ${t.orphanNodes.length}`)}}catch{}}}catch{x.push(``,`### Knowledge Graph`,`- Graph store unavailable`)}let S=l?.onboardDir??_(process.cwd(),y.aiContext),C=a(S),w=c?.onboardComplete||C;if(x.push(``,`### Onboard Status`,w?`- ✅ Complete${c?.onboardTimestamp?` (last: ${c.onboardTimestamp})`:``}`:'- ❌ Not run — call `onboard({ path: "." })` to analyze the codebase',`- **Onboard Directory**: \`${S}\``),s)try{let t=await Tu(s.list(),[],`curated.list`);if(t.timedOut)e.push(`⚠ Curated knowledge listing timed out`),x.push(``,`### Curated Knowledge`,`- Listing timed out`);else{let e=t.value;b=e.length,x.push(``,`### Curated Knowledge`,e.length>0?`- ${e.length} entries`:'- Empty — use `knowledge({ action: "remember", ... })` to persist decisions')}}catch{x.push(``,`### Curated Knowledge`,`- Unable to read curated entries`)}let T=ku(h.totalRecords,v?.nodes??0,v?.edges??0,b);x.push(``),x.push(`## 📊 Context Pressure: ${T}/100`),T>=80?x.push(`⚠️ High pressure — consider pruning stale entries or compacting context.`):T>=50?x.push(`ℹ️ Moderate pressure — AI Kit memory is well-populated.`):x.push(`✅ Low pressure — plenty of headroom for more content.`);let E=0;if(h.lastIndexedAt){E=new Date(h.lastIndexedAt).getTime();let e=(Date.now()-E)/(1e3*60*60);x.push(``,`### Index Freshness`,e>24?u===`smart`?`- ⚠ Last indexed ${Math.floor(e)}h ago — smart indexing will refresh automatically`:`- ⚠ Last indexed ${Math.floor(e)}h ago — may be stale. Run \`reindex({})\``:`- ✅ Last indexed ${e<1?`less than 1h`:`${Math.floor(e)}h`} ago`)}let D=null,O=t;if(typeof O.getDiagnostics==`function`)try{D=O.getDiagnostics(),x.push(``,`### Storage`,`- **Backend**: ${l?.store?.backend??`unknown`}`,`- **Adapter**: ${D.adapterType}`,`- **Vector search**: ${D.vectorSearchEnabled?`✅ enabled`:`⚠ disabled (FTS-only fallback)`}`,D.dbPath?`- **DB**: ${D.dbPath}`:``,D.dbSizeBytes==null?``:`- **DB size**: ${(D.dbSizeBytes/1024/1024).toFixed(2)} MB`,`- **Embedding dim**: ${D.embeddingDim}`)}catch{}if(u===`smart`)if(x.push(``,`### Smart Indexing`),f){let e=f();e?x.push(`- **Mode**: Smart (trickle)`,`- **Status**: ${e.running?`✅ Running`:`⏸ Stopped`}`,`- **Queue**: ${e.queueSize} files pending`,`- **Changed files**: ${e.changedFilesSize} detected`,`- **Interval**: ${Math.round(e.intervalMs/1e3)}s per batch of ${e.batchSize}`):x.push(`- **Mode**: Smart (trickle)`,`- **Status**: scheduler state unavailable (init may have failed)`)}else x.push(`- **Mode**: Smart (trickle) — scheduler state unavailable`);{try{let e=_(process.cwd(),y.data,`stash`);if(a(e)){let t=d(e).mtimeMs;t>E&&(E=t)}}catch{}let e=[];if(s)try{let t=b>0?await s.list():[];for(let e of t){let t=new Date(e.updated||e.created).getTime();t>E&&(E=t)}e.push(...t.sort((e,t)=>new Date(t.updated).getTime()-new Date(e.updated).getTime()).slice(0,5))}catch{}let t=E>0?Date.now()-E:0;if(t>=144e5){let n=Math.floor(t/36e5);if(x.push(``,`### 🌅 Session Briefing`,`_${n}+ hours since last activity — here's what to pick up:_`,``),e.length>0){x.push(`**Recent decisions/notes:**`);for(let t of e)x.push(`- **${t.title}** (${t.category??`note`}) — ${(t.contentPreview??``).slice(0,80)}…`)}x.push(``,`**Suggested next steps:**`,'- `search({ query: "SESSION CHECKPOINT", origin: "curated" })` — find your last checkpoint',"- `restore({})` — resume from a saved checkpoint",'- `knowledge({ action: "list" })` — browse all stored knowledge')}}x.push(``,`### Runtime`,`- **Tree-sitter (WASM)**: ${sn.get()?`✅ Available (AST analysis)`:`⚠ Unavailable (regex fallback)`}`);let k=Au(),ee=ju(),A=r(),j=k!=null&&k!==A,M=ee!=null&&ee!==A;if(j||M){let e=i(),t=[];j&&t.push(`user scaffold v${k}`),M&&t.push(`workspace scaffold v${ee}`);let r=t.join(`, `);e.state===`success`?x.push(``,`### ✅ Upgrade Applied`,`- Server v${A} — ${r} auto-upgraded successfully.`,`- _Restart the MCP server to use the updated version._`):e.state===`pending`?x.push(``,`### ⏳ Upgrade In Progress`,`- Server v${A} ≠ ${r}`,`- Auto-upgrade is running in the background…`):e.state===`failed`?(n(),x.push(``,`### ⬆ Upgrade Available (auto-upgrade failed, retrying)`,`- Server v${A} ≠ ${r}`,`- Error: ${e.error??`unknown`}`)):(n(),x.push(``,`### ⬆ Upgrade Available`,`- Server v${A} ≠ ${r}`,`- Auto-upgrade triggered — check again shortly.`))}e.length>0&&x.push(``,`### ⚠ Warnings`,...e.map(e=>`- ${e}`));let te=Pr();if(te.length>0){let e=te.sort((e,t)=>t.callCount-e.callCount);x.push(``,`### Tool Usage This Session`,``),x.push(`| Tool | Calls | Tokens In | Tokens Out | Errors | Avg Latency |`),x.push(`|------|-------|-----------|------------|--------|-------------|`);for(let t of e.slice(0,15)){let e=Math.round(t.totalInputChars/4),n=Math.round(t.totalOutputChars/4),r=Math.round(t.totalDurationMs/t.callCount);x.push(`| ${t.tool} | ${t.callCount} | ${e.toLocaleString()} | ${n.toLocaleString()} | ${t.errorCount} | ${r}ms |`)}}let N=Dr();if(N.bufferSize>=10){let e=N.state===`healthy`?`🟢`:N.state===`degraded`?`🔴`:`🟡`;x.push(``,`### Auto-GC: ${e} ${N.state}`),x.push(`- p95 latency: ${N.p95}ms | buffer: ${N.bufferSize} samples`),N.gcCount>0&&x.push(`- GC cycles triggered: ${N.gcCount}`)}let P=x.join(`
|
|
1259
|
+
`)}],structuredContent:l}})}function Nu(e,t,o,s,c,l,u,f){let p=B(`status`);e.registerTool(`status`,{title:p.title,description:`Get the current status and statistics of the AI Kit index.`,outputSchema:fi,annotations:p.annotations},async()=>{let e=[];try{let[p,m]=await Promise.all([Tu(t.getStats(),{totalRecords:0,totalFiles:0,lastIndexedAt:null,contentTypeBreakdown:{}},`store.getStats`),Tu(t.listSourcePaths(),[],`store.listSourcePaths`)]),h=p.value;p.timedOut&&e.push(`⚠ Index stats timed out — values may be incomplete`);let g=m.value;m.timedOut&&e.push(`⚠ File listing timed out`);let v=null,b=0,x=[`## AI Kit Status`,``,`- **Total Records**: ${h.totalRecords}`,`- **Total Files**: ${h.totalFiles}`,`- **Last Indexed**: ${h.lastIndexedAt??`Never`}`,``,`### Content Types`,...Object.entries(h.contentTypeBreakdown).map(([e,t])=>`- ${e}: ${t}`),``,`### Indexed Files`,...g.slice(0,50).map(e=>`- ${e}`),g.length>50?`\n... and ${g.length-50} more files`:``];if(o)try{let t=await Tu(o.getStats(),{nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}},`graphStore.getStats`);if(t.timedOut)e.push(`⚠ Graph stats timed out`),x.push(``,`### Knowledge Graph`,`- Graph stats timed out`);else{let e=t.value;v={nodes:e.nodeCount,edges:e.edgeCount},x.push(``,`### Knowledge Graph`,`- **Nodes**: ${e.nodeCount}`,`- **Edges**: ${e.edgeCount}`,...Object.entries(e.nodeTypes).map(([e,t])=>` - ${e}: ${t}`));try{let e=await Tu(o.validate(),{valid:!0,danglingEdges:[],orphanNodes:[],stats:{nodeCount:0,edgeCount:0,nodeTypes:{},edgeTypes:{}}},`graphStore.validate`);if(!e.timedOut){let t=e.value;t.valid||x.push(`- **⚠ Integrity Issues**: ${t.danglingEdges.length} dangling edges`),t.orphanNodes.length>0&&x.push(`- **Orphan nodes**: ${t.orphanNodes.length}`)}}catch{}}}catch{x.push(``,`### Knowledge Graph`,`- Graph store unavailable`)}let S=l?.onboardDir??_(process.cwd(),y.aiContext),C=a(S),w=c?.onboardComplete||C;if(x.push(``,`### Onboard Status`,w?`- ✅ Complete${c?.onboardTimestamp?` (last: ${c.onboardTimestamp})`:``}`:'- ❌ Not run — call `onboard({ path: "." })` to analyze the codebase',`- **Onboard Directory**: \`${S}\``),s)try{let t=await Tu(s.list(),[],`curated.list`);if(t.timedOut)e.push(`⚠ Curated knowledge listing timed out`),x.push(``,`### Curated Knowledge`,`- Listing timed out`);else{let e=t.value;b=e.length,x.push(``,`### Curated Knowledge`,e.length>0?`- ${e.length} entries`:'- Empty — use `knowledge({ action: "remember", ... })` to persist decisions')}}catch{x.push(``,`### Curated Knowledge`,`- Unable to read curated entries`)}let T=ku(h.totalRecords,v?.nodes??0,v?.edges??0,b);x.push(``),x.push(`## 📊 Context Pressure: ${T}/100`),T>=80?x.push(`⚠️ High pressure — consider pruning stale entries or compacting context.`):T>=50?x.push(`ℹ️ Moderate pressure — AI Kit memory is well-populated.`):x.push(`✅ Low pressure — plenty of headroom for more content.`);let E=0;if(h.lastIndexedAt){E=new Date(h.lastIndexedAt).getTime();let e=(Date.now()-E)/(1e3*60*60);x.push(``,`### Index Freshness`,e>24?u===`smart`?`- ⚠ Last indexed ${Math.floor(e)}h ago — smart indexing will refresh automatically`:`- ⚠ Last indexed ${Math.floor(e)}h ago — may be stale. Run \`reindex({})\``:`- ✅ Last indexed ${e<1?`less than 1h`:`${Math.floor(e)}h`} ago`)}let D=null,O=t;if(typeof O.getDiagnostics==`function`)try{D=O.getDiagnostics(),x.push(``,`### Storage`,`- **Backend**: ${l?.store?.backend??`unknown`}`,`- **Adapter**: ${D.adapterType}`,`- **Vector search**: ${D.vectorSearchEnabled?`✅ enabled`:`⚠ disabled (FTS-only fallback)`}`,D.dbPath?`- **DB**: ${D.dbPath}`:``,D.dbSizeBytes==null?``:`- **DB size**: ${(D.dbSizeBytes/1024/1024).toFixed(2)} MB`,`- **Embedding dim**: ${D.embeddingDim}`,`- **Vector dtype**: ${D.vectorDtype}`)}catch{}if(u===`smart`)if(x.push(``,`### Smart Indexing`),f){let e=f();e?x.push(`- **Mode**: Smart (trickle)`,`- **Status**: ${e.running?`✅ Running`:`⏸ Stopped`}`,`- **Queue**: ${e.queueSize} files pending`,`- **Changed files**: ${e.changedFilesSize} detected`,`- **Interval**: ${Math.round(e.intervalMs/1e3)}s per batch of ${e.batchSize}`):x.push(`- **Mode**: Smart (trickle)`,`- **Status**: scheduler state unavailable (init may have failed)`)}else x.push(`- **Mode**: Smart (trickle) — scheduler state unavailable`);{try{let e=_(process.cwd(),y.data,`stash`);if(a(e)){let t=d(e).mtimeMs;t>E&&(E=t)}}catch{}let e=[];if(s)try{let t=b>0?await s.list():[];for(let e of t){let t=new Date(e.updated||e.created).getTime();t>E&&(E=t)}e.push(...t.sort((e,t)=>new Date(t.updated).getTime()-new Date(e.updated).getTime()).slice(0,5))}catch{}let t=E>0?Date.now()-E:0;if(t>=144e5){let n=Math.floor(t/36e5);if(x.push(``,`### 🌅 Session Briefing`,`_${n}+ hours since last activity — here's what to pick up:_`,``),e.length>0){x.push(`**Recent decisions/notes:**`);for(let t of e)x.push(`- **${t.title}** (${t.category??`note`}) — ${(t.contentPreview??``).slice(0,80)}…`)}x.push(``,`**Suggested next steps:**`,'- `search({ query: "SESSION CHECKPOINT", origin: "curated" })` — find your last checkpoint',"- `restore({})` — resume from a saved checkpoint",'- `knowledge({ action: "list" })` — browse all stored knowledge')}}x.push(``,`### Runtime`,`- **Tree-sitter (WASM)**: ${sn.get()?`✅ Available (AST analysis)`:`⚠ Unavailable (regex fallback)`}`);let k=Au(),ee=ju(),A=r(),j=k!=null&&k!==A,M=ee!=null&&ee!==A;if(j||M){let e=i(),t=[];j&&t.push(`user scaffold v${k}`),M&&t.push(`workspace scaffold v${ee}`);let r=t.join(`, `);e.state===`success`?x.push(``,`### ✅ Upgrade Applied`,`- Server v${A} — ${r} auto-upgraded successfully.`,`- _Restart the MCP server to use the updated version._`):e.state===`pending`?x.push(``,`### ⏳ Upgrade In Progress`,`- Server v${A} ≠ ${r}`,`- Auto-upgrade is running in the background…`):e.state===`failed`?(n(),x.push(``,`### ⬆ Upgrade Available (auto-upgrade failed, retrying)`,`- Server v${A} ≠ ${r}`,`- Error: ${e.error??`unknown`}`)):(n(),x.push(``,`### ⬆ Upgrade Available`,`- Server v${A} ≠ ${r}`,`- Auto-upgrade triggered — check again shortly.`))}e.length>0&&x.push(``,`### ⚠ Warnings`,...e.map(e=>`- ${e}`));let te=Pr();if(te.length>0){let e=te.sort((e,t)=>t.callCount-e.callCount);x.push(``,`### Tool Usage This Session`,``),x.push(`| Tool | Calls | Tokens In | Tokens Out | Errors | Avg Latency |`),x.push(`|------|-------|-----------|------------|--------|-------------|`);for(let t of e.slice(0,15)){let e=Math.round(t.totalInputChars/4),n=Math.round(t.totalOutputChars/4),r=Math.round(t.totalDurationMs/t.callCount);x.push(`| ${t.tool} | ${t.callCount} | ${e.toLocaleString()} | ${n.toLocaleString()} | ${t.errorCount} | ${r}ms |`)}}let N=Dr();if(N.bufferSize>=10){let e=N.state===`healthy`?`🟢`:N.state===`degraded`?`🔴`:`🟡`;x.push(``,`### Auto-GC: ${e} ${N.state}`),x.push(`- p95 latency: ${N.p95}ms | buffer: ${N.bufferSize} samples`),N.gcCount>0&&x.push(`- GC cycles triggered: ${N.gcCount}`)}let P=x.join(`
|
|
1260
1260
|
`),ne={totalRecords:h.totalRecords,totalFiles:h.totalFiles,lastIndexedAt:h.lastIndexedAt??null,onboarded:w,onboardDir:S,contentTypes:h.contentTypeBreakdown,wasmAvailable:!!sn.get(),graphStats:v,curatedCount:b,serverVersion:A,scaffoldVersion:k??null,workspaceScaffoldVersion:ee??null,upgradeAvailable:j||M,storeBackend:l?.store?.backend,storeDiagnostics:D??null,contextPressure:T};return{content:[{type:`text`,text:P+(u===`smart`?"\n\n---\n_Next: Use `search` to query indexed content or `graph({action:'find_nodes', name_pattern:'<top-level-module>'})` → then `graph({action:'neighbors', node_id})` for relationships. Smart indexing handles updates automatically._":"\n\n---\n_Next: Use `search` to query indexed content, `graph({action:'find_nodes', name_pattern:'<top-level-module>'})` → then `graph({action:'neighbors', node_id})` for relationships, or `reindex` to refresh the index._")}],structuredContent:ne}}catch(e){return wu.error(`Status failed`,j(e)),U(`INTERNAL`,`Status check failed: ${e instanceof Error?e.message:String(e)}`)}})}const Pu=D(`tools`);function Fu(e){let t=B(`web_search`);e.registerTool(`web_search`,{title:t.title,description:`PREFERRED web search — fans out to multiple keyless providers (DuckDuckGo + Bing-HTML + Mojeek) by default, returning a deduplicated, consensus-ranked union within a 10s deadline. Optional providers (SearXNG, Google, Brave, Bing API) join the fan-out automatically when their env vars are set. Pass one query or multiple for parallel searching.`,inputSchema:{queries:I.array(I.string().max(2e3)).min(1).max(5).describe('Search queries (1–5). Single: `["react hooks"]`. Multiple searched in parallel.'),limit:I.number().min(1).max(20).default(5).describe(`Max results per query`),site:I.string().optional().describe(`Restrict to domain (e.g., "docs.aws.amazon.com")`),provider:I.enum([`multi`,`duckduckgo`,`bing-html`,`mojeek`,`searxng`,`google`,`brave`,`bing`]).optional().describe("Search provider. Defaults to env AIKIT_SEARCH_PROVIDER, then `multi` (fan-out). Single keyless: `duckduckgo`, `bing-html`, `mojeek`. Self-hosted: `searxng` (requires SEARXNG_URL). Keyed APIs: `google` (GOOGLE_API_KEY+GOOGLE_CSE_ID), `brave` (BRAVE_API_KEY), `bing` (BING_API_KEY). Missing keys auto-fall back to duckduckgo.")},annotations:t.annotations},async({queries:e,limit:t,site:n,provider:r})=>{let i=e,a=async e=>{let i=await Wt({query:e,limit:t,site:n,provider:r}),a=[`## Search: ${i.query} _(via ${i.provider})_`,``];if(i.results.length===0)a.push(`No results found.`);else for(let e of i.results)a.push(`### [${e.title}](${e.url})`,e.snippet,``);return a.join(`
|
|
1261
1261
|
`)};if(i.length===1)try{return{content:[{type:`text`,text:`${await a(i[0])}\n---\n_Next: Use \`web_fetch\` to read any of these pages in full._`}]}}catch(e){return Pu.error(`Web search failed`,j(e)),U(`INTERNAL`,`Web search failed: ${e instanceof Error?e.message:String(e)}`)}let o=await Promise.allSettled(i.map(e=>a(e))),s=[],c=0;for(let e=0;e<o.length;e++){let t=o[e];if(t.status===`fulfilled`)s.push(t.value);else{c++;let n=t.reason instanceof Error?t.reason.message:String(t.reason);Pu.error(`Web search failed`,{query:i[e],error:n}),s.push(`## ❌ Search failed: ${i[e]}\n\n${n}`)}}let l=`_Searched ${o.length-c}/${o.length} queries successfully._`;s.push(``,`---`,l,"_Next: Use `web_fetch` to read any of these pages in full._");let u=s.join(`
|
|
1262
1262
|
|
|
@@ -183,6 +183,8 @@ interface IKnowledgeStore {
|
|
|
183
183
|
upsert(records: KnowledgeRecord[], vectors: Float32Array[]): Promise<void>;
|
|
184
184
|
/** Add or update records with priority over bulk indexing writes */
|
|
185
185
|
upsertInteractive(records: KnowledgeRecord[], vectors: Float32Array[]): Promise<void>;
|
|
186
|
+
/** Add or update a record by reusing an existing vector instead of embedding again */
|
|
187
|
+
upsertWithoutVector?(record: KnowledgeRecord, sourceRecordId: string): Promise<void>;
|
|
186
188
|
/** Search by vector similarity */
|
|
187
189
|
search(queryVector: Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
|
|
188
190
|
/** Get a specific record by ID */
|
|
@@ -404,6 +406,7 @@ declare class SqliteVecStore implements IKnowledgeStore {
|
|
|
404
406
|
dbPath: string;
|
|
405
407
|
dbSizeBytes: number | null;
|
|
406
408
|
embeddingDim: number;
|
|
409
|
+
vectorDtype: string;
|
|
407
410
|
};
|
|
408
411
|
private createKnowledgeTable;
|
|
409
412
|
private createFtsTable;
|
|
@@ -412,6 +415,12 @@ declare class SqliteVecStore implements IKnowledgeStore {
|
|
|
412
415
|
private _drain;
|
|
413
416
|
upsert(records: KnowledgeRecord[], vectors: Float32Array[]): Promise<void>;
|
|
414
417
|
upsertInteractive(records: KnowledgeRecord[], vectors: Float32Array[]): Promise<void>;
|
|
418
|
+
/**
|
|
419
|
+
* Insert a knowledge record and copy the vector from an existing record.
|
|
420
|
+
* Used for chunk dedup — when content hash matches, skip re-embedding.
|
|
421
|
+
*/
|
|
422
|
+
upsertWithoutVector(record: KnowledgeRecord, sourceRecordId: string): Promise<void>;
|
|
423
|
+
private upsertKnowledgeRow;
|
|
415
424
|
private _upsertImpl;
|
|
416
425
|
search(queryVector: Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
|
|
417
426
|
ftsSearch(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./lance-store-BRoi-4qY.js";import{i as t,r as n,t as r}from"./sqlite-vec-store-
|
|
1
|
+
import{t as e}from"./lance-store-BRoi-4qY.js";import{i as t,r as n,t as r}from"./sqlite-vec-store-Bnn0_imk.js";import{AIKIT_PATHS as i}from"../../core/dist/index.js";import{existsSync as a,mkdirSync as o}from"node:fs";import{dirname as s,join as c}from"node:path";var l=class{adapter=null;reopenPromise=null;dbPath;externalAdapter;constructor(e={}){if(e.adapter)this.adapter=e.adapter,this.externalAdapter=!0,this.dbPath=``;else{let t=e.path??i.data;this.dbPath=c(t,`graph.db`),this.externalAdapter=!1}}async initialize(){if(this.externalAdapter){let e=this.getAdapter();this.createTables(e),this.migrateSchema(e),e.flush();return}let e=s(this.dbPath);a(e)||o(e,{recursive:!0}),this.adapter=await t(this.dbPath),this.configureAdapter(this.adapter),this.createTables(this.adapter),this.migrateSchema(this.adapter),this.adapter.flush()}configureAdapter(e){e.pragma(`journal_mode = WAL`),e.pragma(`foreign_keys = ON`)}createTables(e){e.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS nodes (
|
|
3
3
|
id TEXT PRIMARY KEY,
|
|
4
4
|
type TEXT NOT NULL,
|
|
@@ -87,4 +87,4 @@ import{t as e}from"./lance-store-BRoi-4qY.js";import{i as t,r as n,t as r}from".
|
|
|
87
87
|
VALUES (?, ?, ?, '{}', ?)`,[a,e,t,o]);for(let e=0;e<n.length;e++)this.run(`INSERT INTO process_steps (process_id, node_id, step_order) VALUES (?, ?, ?)`,[a,n[e],e]);s.exec(`COMMIT`),s.flush()}catch(e){throw s.exec(`ROLLBACK`),e}return{id:a,entryNodeId:e,label:t,properties:{},steps:n,createdAt:o}}async getProcesses(e){await this.ensureOpen();let t;t=e?this.query(`SELECT DISTINCT p.id, p.entry_node_id, p.label, p.properties, p.created_at
|
|
88
88
|
FROM processes p
|
|
89
89
|
JOIN process_steps ps ON p.id = ps.process_id
|
|
90
|
-
WHERE ps.node_id = ?`,[e]):this.query(`SELECT * FROM processes`);let n=[];for(let e of t){let t=this.query(`SELECT node_id FROM process_steps WHERE process_id = ? ORDER BY step_order`,[e.id]);n.push({id:e.id,entryNodeId:e.entry_node_id,label:e.label,properties:u(e.properties),steps:t.map(e=>e.node_id),createdAt:e.created_at})}return n}async deleteProcess(e){await this.ensureOpen();let t=this.getAdapter();t.exec(`BEGIN TRANSACTION`);try{this.run(`DELETE FROM process_steps WHERE process_id = ?`,[e]),this.run(`DELETE FROM processes WHERE id = ?`,[e]),t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}}async depthGroupedTraversal(e,t=3,n){await this.ensureOpen();let r=n?.direction??`both`,i=n?.edgeType,a=n?.limit??100,o={},s=new Set;s.add(e);let c=[e];for(let e=1;e<=t;e++){let t=[],n=[];for(let e of c){let o=await this.getNeighbors(e,{direction:r,edgeType:i,limit:a});for(let e of o.nodes)s.has(e.id)||(s.add(e.id),t.push(e.id),n.push(e))}if(n.length>0&&(o[e]=n),c=t,c.length===0||s.size>=a)break}return o}async getCohesionScore(e){await this.ensureOpen();let t=this.query(`SELECT id FROM nodes WHERE community = ?`,[e]);if(t.length===0)return 0;let n=new Set(t.map(e=>e.id)),r=t.map(()=>`?`).join(`,`),i=t.map(e=>e.id),a=this.query(`SELECT from_id, to_id FROM edges WHERE from_id IN (${r}) OR to_id IN (${r})`,[...i,...i]);if(a.length===0)return 0;let o=0;for(let e of a)n.has(e.from_id)&&n.has(e.to_id)&&o++;return o/a.length}async getSymbol360(e){let t=await this.getNode(e);if(!t)throw Error(`Node '${e}' not found`);let n=await this.findEdges({toId:e}),r=await this.findEdges({fromId:e}),i=await this.getProcesses(e);return{node:t,incoming:n,outgoing:r,community:t.community??null,processes:i}}async close(){this.adapter&&=(this.externalAdapter||this.adapter.close(),null)}};function u(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}function d(e){return{id:e.id,type:e.type,name:e.name,properties:u(e.properties),sourceRecordId:e.source_record_id??void 0,sourcePath:e.source_path??void 0,createdAt:e.created_at,community:e.community??void 0}}function f(e){return{id:e.id,fromId:e.from_id,toId:e.to_id,type:e.type,weight:e.weight??1,confidence:e.confidence??1,properties:u(e.properties)}}function p(e){return{id:e.edge_id,fromId:e.from_id,toId:e.to_id,type:e.edge_type,weight:e.weight??1,confidence:e.edge_confidence??1,properties:u(e.edge_props??`{}`)}}function m(e){return{id:e.node_id,type:e.node_type,name:e.node_name,properties:u(e.node_props??`{}`),sourceRecordId:e.node_src_rec??void 0,sourcePath:e.node_src_path??void 0,createdAt:e.node_created,community:e.node_community??void 0}}async function h(e){switch(e.backend){case`lancedb`:{let{LanceStore:t}=await import(`./lance-store-BRoi-4qY.js`).then(e=>e.n);return new t({path:e.path})}case`sqlite-vec`:{let{SqliteVecStore:t}=await import(`./sqlite-vec-store-
|
|
90
|
+
WHERE ps.node_id = ?`,[e]):this.query(`SELECT * FROM processes`);let n=[];for(let e of t){let t=this.query(`SELECT node_id FROM process_steps WHERE process_id = ? ORDER BY step_order`,[e.id]);n.push({id:e.id,entryNodeId:e.entry_node_id,label:e.label,properties:u(e.properties),steps:t.map(e=>e.node_id),createdAt:e.created_at})}return n}async deleteProcess(e){await this.ensureOpen();let t=this.getAdapter();t.exec(`BEGIN TRANSACTION`);try{this.run(`DELETE FROM process_steps WHERE process_id = ?`,[e]),this.run(`DELETE FROM processes WHERE id = ?`,[e]),t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}}async depthGroupedTraversal(e,t=3,n){await this.ensureOpen();let r=n?.direction??`both`,i=n?.edgeType,a=n?.limit??100,o={},s=new Set;s.add(e);let c=[e];for(let e=1;e<=t;e++){let t=[],n=[];for(let e of c){let o=await this.getNeighbors(e,{direction:r,edgeType:i,limit:a});for(let e of o.nodes)s.has(e.id)||(s.add(e.id),t.push(e.id),n.push(e))}if(n.length>0&&(o[e]=n),c=t,c.length===0||s.size>=a)break}return o}async getCohesionScore(e){await this.ensureOpen();let t=this.query(`SELECT id FROM nodes WHERE community = ?`,[e]);if(t.length===0)return 0;let n=new Set(t.map(e=>e.id)),r=t.map(()=>`?`).join(`,`),i=t.map(e=>e.id),a=this.query(`SELECT from_id, to_id FROM edges WHERE from_id IN (${r}) OR to_id IN (${r})`,[...i,...i]);if(a.length===0)return 0;let o=0;for(let e of a)n.has(e.from_id)&&n.has(e.to_id)&&o++;return o/a.length}async getSymbol360(e){let t=await this.getNode(e);if(!t)throw Error(`Node '${e}' not found`);let n=await this.findEdges({toId:e}),r=await this.findEdges({fromId:e}),i=await this.getProcesses(e);return{node:t,incoming:n,outgoing:r,community:t.community??null,processes:i}}async close(){this.adapter&&=(this.externalAdapter||this.adapter.close(),null)}};function u(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}function d(e){return{id:e.id,type:e.type,name:e.name,properties:u(e.properties),sourceRecordId:e.source_record_id??void 0,sourcePath:e.source_path??void 0,createdAt:e.created_at,community:e.community??void 0}}function f(e){return{id:e.id,fromId:e.from_id,toId:e.to_id,type:e.type,weight:e.weight??1,confidence:e.confidence??1,properties:u(e.properties)}}function p(e){return{id:e.edge_id,fromId:e.from_id,toId:e.to_id,type:e.edge_type,weight:e.weight??1,confidence:e.edge_confidence??1,properties:u(e.edge_props??`{}`)}}function m(e){return{id:e.node_id,type:e.node_type,name:e.node_name,properties:u(e.node_props??`{}`),sourceRecordId:e.node_src_rec??void 0,sourcePath:e.node_src_path??void 0,createdAt:e.node_created,community:e.node_community??void 0}}async function h(e){switch(e.backend){case`lancedb`:{let{LanceStore:t}=await import(`./lance-store-BRoi-4qY.js`).then(e=>e.n);return new t({path:e.path})}case`sqlite-vec`:{let{SqliteVecStore:t}=await import(`./sqlite-vec-store-Bnn0_imk.js`).then(e=>e.n);return new t({path:e.path,adapter:e.adapter,embeddingDim:e.embeddingDim})}default:{let t=e.backend;throw Error(`Unknown store backend: "${t}". Supported: lancedb, sqlite-vec`)}}}export{e as LanceStore,l as SqliteGraphStore,r as SqliteVecStore,n as createSqlJsAdapter,t as createSqliteAdapter,h as createStore};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e,t}from"./rolldown-runtime-BynbHzcv.js";import{createRequire as n}from"node:module";import{EMBEDDING_DEFAULTS as r,SEARCH_DEFAULTS as i,STORE_DEFAULTS as a,createLogger as o,serializeError as s,sourceTypeContentTypes as c}from"../../core/dist/index.js";import{existsSync as l,mkdirSync as u,readFileSync as d,renameSync as f,unlinkSync as p,writeFileSync as m}from"node:fs";import{dirname as h}from"node:path";const g=o(`sqlite-adapter`),_=n(import.meta.url);var v=class{type=`better-sqlite3`;vectorCapable=!1;db=null;stmtCache=new Map;async open(e){let t;try{t=_(`better-sqlite3`)}catch(e){throw Error(`better-sqlite3 native binding unavailable: ${e instanceof Error?e.message:String(e)}`)}this.db=new t(e),this.db.pragma(`journal_mode = WAL`),this.db.pragma(`foreign_keys = ON`),this.db.pragma(`synchronous = NORMAL`);try{_(`sqlite-vec`).load(this.db),this.vectorCapable=!0,g.info(`sqlite-vec extension loaded`)}catch(e){this.vectorCapable=!1,g.warn(`sqlite-vec extension failed to load; vector search disabled`,s(e))}}exec(e){this.getDb().exec(e)}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){let n=this.prepareCached(e);return t.length>0?n.all(...t):n.all()}run(e,t=[]){let n=this.prepareCached(e);t.length>0?n.run(...t):n.run()}flush(){}close(){this.db&&=(this.stmtCache.clear(),this.db.close(),null)}getDb(){if(!this.db)throw Error(`BetterSqlite3Adapter: database not opened`);return this.db}prepareCached(e){let t=this.stmtCache.get(e);if(t)return t;let n=this.getDb().prepare(e);return this.stmtCache.set(e,n),n}};function y(e){return _.resolve(`sql.js/dist/${e}`)}var b=class{type=`sql.js`;vectorCapable=!1;db=null;dbPath=``;dirty=!1;inTransaction=!1;async open(e){this.dbPath=e;let t=(await import(`sql.js`)).default,n=await t({locateFile:e=>y(e)});if(l(e)){let t=d(e);this.db=new n.Database(t)}else this.db=new n.Database}exec(e){let t=e.trimStart().toUpperCase();this.getDb().run(e),t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.dirty=!0}pragma(e){this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);try{t.length>0&&n.bind(t);let e=[];for(;n.step();)e.push(n.getAsObject());return e}finally{n.free()}}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=!this.inTransaction&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));i&&n.run(`SAVEPOINT fk_check`);try{if(t.length>0){let r=n.prepare(e);try{r.bind(t),r.step()}finally{r.free()}}else n.run(e);if(i){if(n.exec(`PRAGMA foreign_key_check`).length>0)throw n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`),Error(`FOREIGN KEY constraint failed`);n.run(`RELEASE fk_check`)}}catch(e){if(i)try{n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`)}catch{}throw e}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export(),t=`${this.dbPath}.tmp`;m(t,Buffer.from(e)),f(t,this.dbPath),this.dirty=!1}close(){if(this.db){let e=this.db,t;try{this.flush()}catch(e){t=e;try{p(`${this.dbPath}.tmp`)}catch{}}try{e.close()}finally{this.db=null}if(t)throw t}}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};let x=!1;async function S(e){let t=new v;try{return await t.open(e),t}catch(e){x||(x=!0,g.warn(`[aikit] better-sqlite3 unavailable — falling back to sql.js (vector search disabled). Reinstall with prebuild support or rebuild from source to enable vector search.`,s(e)))}let n=new b;try{return await n.open(e),n}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[aikit] SQLite adapter "sql.js" failed to load: ${t}`)}}async function C(e){let t=new b;return await t.open(e),t}var w=t({SqliteVecStore:()=>A});const
|
|
1
|
+
import{n as e,t}from"./rolldown-runtime-BynbHzcv.js";import{createRequire as n}from"node:module";import{EMBEDDING_DEFAULTS as r,SEARCH_DEFAULTS as i,STORE_DEFAULTS as a,createLogger as o,serializeError as s,sourceTypeContentTypes as c}from"../../core/dist/index.js";import{existsSync as l,mkdirSync as u,readFileSync as d,renameSync as f,unlinkSync as p,writeFileSync as m}from"node:fs";import{dirname as h}from"node:path";const g=o(`sqlite-adapter`),_=n(import.meta.url);var v=class{type=`better-sqlite3`;vectorCapable=!1;db=null;stmtCache=new Map;async open(e){let t;try{t=_(`better-sqlite3`)}catch(e){throw Error(`better-sqlite3 native binding unavailable: ${e instanceof Error?e.message:String(e)}`)}this.db=new t(e),this.db.pragma(`journal_mode = WAL`),this.db.pragma(`foreign_keys = ON`),this.db.pragma(`synchronous = NORMAL`);try{_(`sqlite-vec`).load(this.db),this.vectorCapable=!0,g.info(`sqlite-vec extension loaded`)}catch(e){this.vectorCapable=!1,g.warn(`sqlite-vec extension failed to load; vector search disabled`,s(e))}}exec(e){this.getDb().exec(e)}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){let n=this.prepareCached(e);return t.length>0?n.all(...t):n.all()}run(e,t=[]){let n=this.prepareCached(e);t.length>0?n.run(...t):n.run()}flush(){}close(){this.db&&=(this.stmtCache.clear(),this.db.close(),null)}getDb(){if(!this.db)throw Error(`BetterSqlite3Adapter: database not opened`);return this.db}prepareCached(e){let t=this.stmtCache.get(e);if(t)return t;let n=this.getDb().prepare(e);return this.stmtCache.set(e,n),n}};function y(e){return _.resolve(`sql.js/dist/${e}`)}var b=class{type=`sql.js`;vectorCapable=!1;db=null;dbPath=``;dirty=!1;inTransaction=!1;async open(e){this.dbPath=e;let t=(await import(`sql.js`)).default,n=await t({locateFile:e=>y(e)});if(l(e)){let t=d(e);this.db=new n.Database(t)}else this.db=new n.Database}exec(e){let t=e.trimStart().toUpperCase();this.getDb().run(e),t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.dirty=!0}pragma(e){this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);try{t.length>0&&n.bind(t);let e=[];for(;n.step();)e.push(n.getAsObject());return e}finally{n.free()}}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=!this.inTransaction&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));i&&n.run(`SAVEPOINT fk_check`);try{if(t.length>0){let r=n.prepare(e);try{r.bind(t),r.step()}finally{r.free()}}else n.run(e);if(i){if(n.exec(`PRAGMA foreign_key_check`).length>0)throw n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`),Error(`FOREIGN KEY constraint failed`);n.run(`RELEASE fk_check`)}}catch(e){if(i)try{n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`)}catch{}throw e}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export(),t=`${this.dbPath}.tmp`;m(t,Buffer.from(e)),f(t,this.dbPath),this.dirty=!1}close(){if(this.db){let e=this.db,t;try{this.flush()}catch(e){t=e;try{p(`${this.dbPath}.tmp`)}catch{}}try{e.close()}finally{this.db=null}if(t)throw t}}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};let x=!1;async function S(e){let t=new v;try{return await t.open(e),t}catch(e){x||(x=!0,g.warn(`[aikit] better-sqlite3 unavailable — falling back to sql.js (vector search disabled). Reinstall with prebuild support or rebuild from source to enable vector search.`,s(e)))}let n=new b;try{return await n.open(e),n}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[aikit] SQLite adapter "sql.js" failed to load: ${t}`)}}async function C(e){let t=new b;return await t.open(e),t}var w=t({SqliteVecStore:()=>A});function T(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n]<0?-e[n]:e[n];r>t&&(t=r)}let n=new Int8Array(e.length);if(t===0)return Buffer.from(n.buffer,n.byteOffset,n.byteLength);let r=127/t;for(let t=0;t<e.length;t++){let i=Math.round(e[t]*r);n[t]=i<-127?-127:i>127?127:i}return Buffer.from(n.buffer,n.byteOffset,n.byteLength)}const E=/^[\w.\-/ ]+$/,D=o(`sqlite-vec-store`);function O(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function k(e,t){if(!E.test(e))throw Error(`Invalid ${t} filter value: contains disallowed characters`);return e}var A=class{adapter=null;externalAdapter;dbPath;embeddingDim;vectorEnabled=!1;warnedVectorDisabled=!1;_draining=!1;_priorityQueue=[];_normalQueue=[];constructor(e={}){this.embeddingDim=e.embeddingDim??r.dimensions,e.adapter?(this.adapter=e.adapter,this.externalAdapter=!0,this.dbPath=``):(this.dbPath=e.path??`${a.path}/aikit.db`,this.externalAdapter=!1)}async initialize(){if(!this.adapter){let e=h(this.dbPath);l(e)||u(e,{recursive:!0}),this.adapter=await S(this.dbPath)}this.vectorEnabled=this.adapter.vectorCapable,this.createKnowledgeTable(),this.createFtsTable(),this.vectorEnabled?this.ensureVecTable():this.warnedVectorDisabled||(this.warnedVectorDisabled=!0,D.warn(`SqliteVecStore: vector search disabled (sqlite-vec extension not loaded). Hybrid search will return FTS-only results.`))}getDiagnostics(){let t=this.adapter,n=t?t.constructor.name:`unknown`,r=null,i=this.externalAdapter?``:this.dbPath;if(i)try{let{statSync:t}=e(`node:fs`);r=t(i).size}catch{r=null}return{adapterType:n,vectorSearchEnabled:this.vectorEnabled,degradedMode:!this.vectorEnabled,dbPath:i,dbSizeBytes:r,embeddingDim:this.embeddingDim,vectorDtype:`int8`}}createKnowledgeTable(){let e=this.getAdapter();e.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS knowledge (
|
|
3
3
|
id TEXT PRIMARY KEY,
|
|
4
4
|
content TEXT NOT NULL,
|
|
@@ -10,46 +10,48 @@ import{n as e,t}from"./rolldown-runtime-BynbHzcv.js";import{createRequire as n}f
|
|
|
10
10
|
startLine INTEGER NOT NULL DEFAULT 0,
|
|
11
11
|
endLine INTEGER NOT NULL DEFAULT 0,
|
|
12
12
|
fileHash TEXT NOT NULL DEFAULT '',
|
|
13
|
+
content_hash TEXT NOT NULL DEFAULT '',
|
|
13
14
|
indexedAt TEXT NOT NULL,
|
|
14
15
|
origin TEXT NOT NULL DEFAULT 'indexed',
|
|
15
16
|
tags TEXT NOT NULL DEFAULT '[]',
|
|
16
17
|
category TEXT NOT NULL DEFAULT '',
|
|
17
18
|
version INTEGER NOT NULL DEFAULT 1
|
|
18
19
|
)
|
|
19
|
-
`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_sourcePath ON knowledge(sourcePath)`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_contentType ON knowledge(contentType)`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_origin ON knowledge(origin)`)}createFtsTable(){this.getAdapter().exec(`
|
|
20
|
+
`),e.queryAll(`PRAGMA table_info(knowledge)`).some(e=>e.name===`content_hash`)||e.exec(`ALTER TABLE knowledge ADD COLUMN content_hash TEXT NOT NULL DEFAULT ''`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_sourcePath ON knowledge(sourcePath)`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_contentType ON knowledge(contentType)`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_content_hash ON knowledge(content_hash)`),e.exec(`CREATE INDEX IF NOT EXISTS idx_knowledge_origin ON knowledge(origin)`)}createFtsTable(){this.getAdapter().exec(`
|
|
20
21
|
CREATE VIRTUAL TABLE IF NOT EXISTS knowledge_fts USING fts5(
|
|
21
22
|
id UNINDEXED,
|
|
22
23
|
content,
|
|
23
24
|
tokenize = 'unicode61 remove_diacritics 2'
|
|
24
25
|
)
|
|
25
|
-
`)}ensureVecTable(){let e=this.getAdapter(),t=e.queryAll(`SELECT name, sql FROM sqlite_master WHERE type='table' AND name='vec_knowledge'`);if(t.length>0){let n=
|
|
26
|
+
`)}ensureVecTable(){let e=this.getAdapter(),t=e.queryAll(`SELECT name, sql FROM sqlite_master WHERE type='table' AND name='vec_knowledge'`);if(t.length>0){let n=t[0].sql??``,r=n.match(/(?:float|int8)\[(\d+)\]/i),i=r?Number(r[1]):null,a=/int8\[/i.test(n);(i!==null&&i!==this.embeddingDim||!a)&&(D.warn(`Vec table schema mismatch — dropping for recreation`,{existingDim:i,newDim:this.embeddingDim,wasInt8:a}),e.exec(`DROP TABLE vec_knowledge`))}e.exec(`
|
|
26
27
|
CREATE VIRTUAL TABLE IF NOT EXISTS vec_knowledge USING vec0(
|
|
27
|
-
embedding
|
|
28
|
+
embedding int8[${this.embeddingDim}] distance_metric=cosine,
|
|
28
29
|
+knowledge_id TEXT
|
|
29
30
|
)
|
|
30
|
-
`)}enqueueWrite(e,t=!1){return new Promise((n,r)=>{let i=async()=>{try{n(await e())}catch(e){r(e)}};t?this._priorityQueue.push(i):this._normalQueue.push(i),this._drain()})}async _drain(){if(!this._draining){this._draining=!0;try{for(;this._priorityQueue.length>0||this._normalQueue.length>0;){let e=this._priorityQueue.shift()??this._normalQueue.shift();e&&await e()}}finally{this._draining=!1}}}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 upsertInteractive(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),!0)}}async
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
`)}enqueueWrite(e,t=!1){return new Promise((n,r)=>{let i=async()=>{try{n(await e())}catch(e){r(e)}};t?this._priorityQueue.push(i):this._normalQueue.push(i),this._drain()})}async _drain(){if(!this._draining){this._draining=!0;try{for(;this._priorityQueue.length>0||this._normalQueue.length>0;){let e=this._priorityQueue.shift()??this._normalQueue.shift();e&&await e()}}finally{this._draining=!1}}}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 upsertInteractive(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),!0)}}async upsertWithoutVector(e,t){return this.enqueueWrite(async()=>{let n=this.getAdapter(),r=e;n.exec(`BEGIN`);try{if(this.upsertKnowledgeRow(r),n.run(`DELETE FROM knowledge_fts WHERE id = ?`,[r.id]),n.run(`INSERT INTO knowledge_fts (id, content) VALUES (?, ?)`,[r.id,r.content]),this.vectorEnabled){let e=n.queryAll(`SELECT embedding FROM vec_knowledge WHERE knowledge_id = ?`,[t]);e.length>0?(n.run(`DELETE FROM vec_knowledge WHERE knowledge_id = ?`,[r.id]),n.run(`INSERT INTO vec_knowledge (embedding, knowledge_id) VALUES (vec_int8(?), ?)`,[e[0].embedding,r.id])):D.warn(`upsertWithoutVector: source vector not found, record will lack vector`,{recordId:r.id,sourceRecordId:t})}n.exec(`COMMIT`)}catch(e){try{n.exec(`ROLLBACK`)}catch{}throw e}n.flush()})}upsertKnowledgeRow(e){this.getAdapter().run(`INSERT INTO knowledge (id, content, sourcePath, contentType, headingPath, chunkIndex,
|
|
32
|
+
totalChunks, startLine, endLine, fileHash, content_hash, indexedAt, origin, tags, category, version)
|
|
33
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
34
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
35
|
+
content = excluded.content,
|
|
36
|
+
sourcePath = excluded.sourcePath,
|
|
37
|
+
contentType = excluded.contentType,
|
|
38
|
+
headingPath = excluded.headingPath,
|
|
39
|
+
chunkIndex = excluded.chunkIndex,
|
|
40
|
+
totalChunks = excluded.totalChunks,
|
|
41
|
+
startLine = excluded.startLine,
|
|
42
|
+
endLine = excluded.endLine,
|
|
43
|
+
fileHash = excluded.fileHash,
|
|
44
|
+
content_hash = excluded.content_hash,
|
|
45
|
+
indexedAt = excluded.indexedAt,
|
|
46
|
+
origin = excluded.origin,
|
|
47
|
+
tags = excluded.tags,
|
|
48
|
+
category = excluded.category,
|
|
49
|
+
version = excluded.version`,[e.id,e.content,e.sourcePath,e.contentType,e.headingPath??``,e.chunkIndex,e.totalChunks,e.startLine,e.endLine,e.fileHash,e.contentHash??``,e.indexedAt,e.origin,JSON.stringify(e.tags??[]),e.category??``,e.version])}async _upsertImpl(e,t){let n=this.getAdapter();n.exec(`BEGIN`);try{for(let r=0;r<e.length;r++){let i=e[r];this.upsertKnowledgeRow(i),n.run(`DELETE FROM knowledge_fts WHERE id = ?`,[i.id]),n.run(`INSERT INTO knowledge_fts (id, content) VALUES (?, ?)`,[i.id,i.content]),this.vectorEnabled&&(n.run(`DELETE FROM vec_knowledge WHERE knowledge_id = ?`,[i.id]),n.run(`INSERT INTO vec_knowledge (embedding, knowledge_id) VALUES (vec_int8(?), ?)`,[T(t[r]),i.id]))}n.exec(`COMMIT`)}catch(e){try{n.exec(`ROLLBACK`)}catch{}throw e}n.flush()}async search(e,t){if(!this.vectorEnabled)return this.warnedVectorDisabled||(this.warnedVectorDisabled=!0,D.warn(`search() called but vector backend is disabled — returning []`)),[];let n=this.getAdapter(),r=t?.limit??i.maxResults,a=t?.minScore??i.minScore,o=r*4,c=`
|
|
48
50
|
SELECT k.*, v.distance AS _distance
|
|
49
51
|
FROM (
|
|
50
52
|
SELECT knowledge_id, distance
|
|
51
53
|
FROM vec_knowledge
|
|
52
|
-
WHERE embedding MATCH ?
|
|
54
|
+
WHERE embedding MATCH vec_int8(?)
|
|
53
55
|
ORDER BY distance
|
|
54
56
|
LIMIT ?
|
|
55
57
|
) v
|
|
@@ -57,7 +59,7 @@ import{n as e,t}from"./rolldown-runtime-BynbHzcv.js";import{createRequire as n}f
|
|
|
57
59
|
${this.buildFilterSqlSuffix(t)}
|
|
58
60
|
ORDER BY v.distance ASC
|
|
59
61
|
LIMIT ?
|
|
60
|
-
`,l;try{l=n.queryAll(c,[
|
|
62
|
+
`,l;try{l=n.queryAll(c,[T(e),o,r])}catch(e){return D.warn(`vector search failed`,s(e)),[]}return l.map(e=>({record:this.fromRow(e),score:1-(e._distance??1)})).filter(e=>e.score>=a).slice(0,r)}async ftsSearch(e,t){if(!e||e.trim().length===0)return[];let n=this.getAdapter(),r=t?.limit??i.maxResults,a=`
|
|
61
63
|
SELECT k.*, bm25(knowledge_fts) AS _bm25
|
|
62
64
|
FROM knowledge_fts
|
|
63
65
|
JOIN knowledge k ON k.id = knowledge_fts.id
|
|
@@ -65,4 +67,4 @@ import{n as e,t}from"./rolldown-runtime-BynbHzcv.js";import{createRequire as n}f
|
|
|
65
67
|
${this.buildFilterSqlSuffix(t,!0)}
|
|
66
68
|
ORDER BY _bm25 ASC
|
|
67
69
|
LIMIT ?
|
|
68
|
-
`,o;try{let t=j(e);o=n.queryAll(a,[t,r])}catch(e){return
|
|
70
|
+
`,o;try{let t=j(e);o=n.queryAll(a,[t,r])}catch(e){return D.warn(`fts search failed`,s(e)),[]}return o.map(e=>({record:this.fromRow(e),score:M(e._bm25)}))}async getById(e){let t=this.getAdapter().queryAll(`SELECT * FROM knowledge WHERE id = ? LIMIT 1`,[e]);return t.length===0?null:this.fromRow(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){let t=this.getAdapter(),n=t.queryAll(`SELECT id FROM knowledge WHERE sourcePath = ?`,[e]);if(n.length===0)return 0;t.exec(`BEGIN`);try{for(let{id:e}of n)this.vectorEnabled&&t.run(`DELETE FROM vec_knowledge WHERE knowledge_id = ?`,[e]),t.run(`DELETE FROM knowledge_fts WHERE id = ?`,[e]);t.run(`DELETE FROM knowledge WHERE sourcePath = ?`,[e]),t.exec(`COMMIT`)}catch(e){try{t.exec(`ROLLBACK`)}catch{}throw e}return t.flush(),n.length}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async deleteByIdInteractive(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e),!0)}async _deleteByIdImpl(e){let t=this.getAdapter();if(t.queryAll(`SELECT id FROM knowledge WHERE id = ? LIMIT 1`,[e]).length===0)return!1;t.exec(`BEGIN`);try{this.vectorEnabled&&t.run(`DELETE FROM vec_knowledge WHERE knowledge_id = ?`,[e]),t.run(`DELETE FROM knowledge_fts WHERE id = ?`,[e]),t.run(`DELETE FROM knowledge WHERE id = ?`,[e]),t.exec(`COMMIT`)}catch(e){try{t.exec(`ROLLBACK`)}catch{}throw e}return t.flush(),!0}async getBySourcePath(e){return this.getAdapter().queryAll(`SELECT * FROM knowledge WHERE sourcePath = ? ORDER BY chunkIndex ASC`,[e]).map(e=>this.fromRow(e))}async getStats(){let e=this.getAdapter(),t=e.queryAll(`SELECT COUNT(*) AS n FROM knowledge`)[0]?.n??0;if(t===0)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`sqlite-vec`,embeddingModel:r.model};let n=e.queryAll(`SELECT COUNT(DISTINCT sourcePath) AS n FROM knowledge`),i=e.queryAll(`SELECT contentType, COUNT(*) AS n FROM knowledge GROUP BY contentType`),a=e.queryAll(`SELECT MAX(indexedAt) AS ts FROM knowledge`),o={};for(let e of i)o[e.contentType]=e.n;return{totalRecords:t,totalFiles:n[0]?.n??0,contentTypeBreakdown:o,lastIndexedAt:a[0]?.ts??null,storeBackend:`sqlite-vec`,embeddingModel:r.model}}async listSourcePaths(){return this.getAdapter().queryAll(`SELECT DISTINCT sourcePath FROM knowledge ORDER BY sourcePath`).map(e=>e.sourcePath)}async createFtsIndex(){this.createFtsTable()}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){let e=this.getAdapter();e.exec(`DROP TABLE IF EXISTS knowledge_fts`),this.vectorEnabled&&e.exec(`DROP TABLE IF EXISTS vec_knowledge`),e.exec(`DROP TABLE IF EXISTS knowledge`),e.flush(),this.createKnowledgeTable(),this.createFtsTable(),this.vectorEnabled&&this.ensureVecTable()}async close(){for(;this._priorityQueue.length>0||this._normalQueue.length>0||this._draining;)await new Promise(e=>setTimeout(e,5));this.adapter&&!this.externalAdapter&&this.adapter.close(),this.adapter=null}getAdapter(){if(!this.adapter)throw Error(`SqliteVecStore: not initialized — call initialize() first`);return this.adapter}buildFilterSqlSuffix(e,t=!1){if(!e)return``;let n=[];if(e.contentType&&n.push(`k.contentType = '${k(e.contentType,`contentType`)}'`),e.sourceType){let t=c(e.sourceType);if(t.length>0){let e=t.map(e=>`'${k(e,`sourceType`)}'`).join(`, `);n.push(`k.contentType IN (${e})`)}}if(e.origin&&n.push(`k.origin = '${k(e.origin,`origin`)}'`),e.category&&n.push(`k.category = '${k(e.category,`category`)}'`),e.tags&&e.tags.length>0){let t=e.tags.map(e=>`k.tags LIKE '%' || '${k(e,`tag`)}' || '%'`);n.push(`(${t.join(` OR `)})`)}if(n.length===0)return``;let r=n.join(` AND `);return t?`AND ${r}`:`WHERE ${r}`}fromRow(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,contentHash:e.content_hash||void 0,indexedAt:e.indexedAt,origin:e.origin,tags:O(e.tags),category:e.category||void 0,version:e.version}}};function j(e){let t=e.replace(/["'()*:^-]/g,` `).trim();return t?t.split(/\s+/).filter(e=>e.length>0).map(e=>`"${e}"`).join(` OR `):`""`}function M(e){return e==null||Number.isNaN(e)?0:1-Math.exp(-Math.abs(e)/5)}export{S as i,w as n,C as r,A as t};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r}from"./constants-Nz_Z7XS-.js";import{n as i,t as a}from"./templates-BRWMrqFI.js";import{guideFlows as o,guideScaffold as s,guideSkills as c,smartCopyFlows as l,smartCopyScaffold as u,smartCopySkills as d}from"./scaffold-BLeqLPMe.js";import{appendFileSync as f,existsSync as p,mkdirSync as m,readFileSync as h,unlinkSync as g,writeFileSync as _}from"node:fs";import{basename as v,dirname as y,join as b,resolve as x}from"node:path";import{fileURLToPath as S}from"node:url";import{AIKIT_PATHS as C,isUserInstalled as w}from"../../core/dist/index.js";function T(e){return p(x(e,`.cursor`))?`cursor`:p(x(e,`.claude`))?`claude-code`:p(x(e,`.windsurf`))?`windsurf`:p(x(e,`.zed`))?`zed`:p(x(e,`.idea`))?`intellij`:`copilot`}function E(e){let t=[];return p(x(e,`.cursor`))&&t.push(`cursor`),(p(x(e,`.claude`))||p(x(e,`CLAUDE.md`)))&&t.push(`claude-code`),p(x(e,`.windsurf`))&&t.push(`windsurf`),p(x(e,`.zed`))&&t.push(`zed`),p(x(e,`.idea`))&&t.push(`intellij`),p(x(e,`.gemini`))&&t.push(`gemini-cli`),(p(x(e,`.codex`))||p(x(e,`codex.md`)))&&t.push(`codex-cli`),t.push(`copilot`),[...new Set(t)]}function D(e){return{servers:{[e]:{...t}}}}function O(e){let{type:n,...r}=t;return{mcpServers:{[e]:r}}}function k(e){let{type:n,...r}=t;return{context_servers:{[e]:{...r}}}}const A={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.vscode`),r=x(n,`mcp.json`);p(r)||(m(n,{recursive:!0}),_(r,`${JSON.stringify(D(t),null,2)}\n`,`utf-8`),console.log(` Created .vscode/mcp.json`))},writeInstructions(e,t){let n=x(e,`.github`),r=x(n,`copilot-instructions.md`);m(n,{recursive:!0}),_(r,i(v(e),t),`utf-8`),console.log(` Updated .github/copilot-instructions.md`)},writeAgentsMd(e,t){_(x(e,`AGENTS.md`),a(v(e),t),`utf-8`),console.log(` Updated AGENTS.md`)}},j={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.mcp.json`);p(n)||(_(n,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created .mcp.json`))},writeInstructions(e,t){let n=x(e,`CLAUDE.md`),r=v(e);_(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated CLAUDE.md`)},writeAgentsMd(e,t){}},M={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.cursor`),r=x(n,`mcp.json`);p(r)||(m(n,{recursive:!0}),_(r,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created .cursor/mcp.json`))},writeInstructions(e,t){let n=x(e,`.cursor`,`rules`),r=x(n,`aikit.mdc`);m(n,{recursive:!0});let o=v(e);_(r,`${i(o,t)}\n---\n\n${a(o,t)}`,`utf-8`),console.log(` Updated .cursor/rules/aikit.mdc`);let s=x(n,`kb.mdc`);p(s)&&s!==r&&(g(s),console.log(` Removed legacy .cursor/rules/kb.mdc`))},writeAgentsMd(e,t){}},N={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.vscode`),r=x(n,`mcp.json`);p(r)||(m(n,{recursive:!0}),_(r,`${JSON.stringify(D(t),null,2)}\n`,`utf-8`),console.log(` Created .vscode/mcp.json (Windsurf-compatible)`))},writeInstructions(e,t){let n=x(e,`.windsurfrules`),r=v(e);_(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated .windsurfrules`)},writeAgentsMd(e,t){}},P={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`.zed`),r=x(n,`settings.json`);if(m(n,{recursive:!0}),!p(r))_(r,`${JSON.stringify(k(t),null,2)}\n`,`utf-8`),console.log(` Created .zed/settings.json`);else{let e;try{e=JSON.parse(h(r,`utf-8`))}catch{console.warn(` ⚠ .zed/settings.json contains invalid JSON — skipping MCP config merge`);return}e.context_servers?.[t]||(e.context_servers={...e.context_servers,...k(t).context_servers},_(r,`${JSON.stringify(e,null,2)}\n`,`utf-8`),console.log(` Updated .zed/settings.json with context_servers`))}},writeInstructions(e,t){let n=x(e,`.rules`),r=v(e);_(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated .rules`)},writeAgentsMd(e,t){}},F={scaffoldDir:`general`,writeMcpConfig(e,t){let n=x(e,`mcp.json`);p(n)||(_(n,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created mcp.json`))},writeInstructions(e,t){let n=x(e,`.aiassistant`,`rules`),r=x(n,`aikit.md`);m(n,{recursive:!0});let o=v(e);_(r,`${i(o,t)}\n---\n\n${a(o,t)}`,`utf-8`),console.log(` Updated .aiassistant/rules/aikit.md`)},writeAgentsMd(e,t){}};function I(e){switch(e){case`copilot`:return A;case`claude-code`:return j;case`cursor`:return M;case`windsurf`:return N;case`zed`:return P;case`intellij`:return F;case`gemini-cli`:case`codex-cli`:return A}}const L={serverName:n,sources:[{path:`.`,excludePatterns:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.git/**`,`**/${C.data}/**`,`**/coverage/**`,`**/*.min.js`,`**/package-lock.json`,`**/pnpm-lock.yaml`]}],indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:`mixedbread-ai/mxbai-embed-large-v1`,dimensions:1024},store:{backend:`sqlite-vec`,path:C.data},curated:{path:C.aiCurated}};function R(e,t){let n=x(e,`aikit.config.json`);return p(n)&&!t?(console.log(`aikit.config.json already exists. Use --force to overwrite.`),!1):(_(n,`${JSON.stringify(L,null,2)}\n`,`utf-8`),console.log(` Created aikit.config.json`),!0)}function z(e){let t=x(e,`.gitignore`),n=[{dir:`${C.data}/`,label:`AI Kit vector store`},{dir:`${C.state}/`,label:`AI Kit session state`},{dir:`${C.restorePoints}/`,label:`Restore points (codemod/rename undo snapshots)`},{dir:`${C.brainstorm}/`,label:`Brainstorming sessions`},{dir:`${C.handoffs}/`,label:`Handoff documents`}];if(p(t)){let e=h(t,`utf-8`),r=n.filter(t=>!e.includes(t.dir));r.length>0&&(f(t,`\n${r.map(e=>`# ${e.label}\n${e.dir}`).join(`
|
|
2
|
-
`)}\n`,`utf-8`),console.log(` Added ${r.map(e=>e.dir).join(`, `)} to .gitignore`))}else _(t,`${n.map(e=>`# ${e.label}\n${e.dir}`).join(`
|
|
3
|
-
`)}\n`,`utf-8`),console.log(` Created .gitignore with AI Kit entries`)}function B(){return L.serverName}const V=[`decisions`,`patterns`,`conventions`,`troubleshooting`];function H(e){let t=x(e,`.ai`,`curated`);p(t)||(m(t,{recursive:!0}),console.log(` Created .ai/curated/`));for(let e of V){let n=x(t,e);p(n)||m(n,{recursive:!0})}console.log(` Created .ai/curated/{${V.join(`,`)}}/`)}function U(e){switch(e){case`zed`:return`zed`;case`intellij`:return`intellij`;case`claude-code`:return`claude-code`;case`gemini-cli`:return`gemini`;case`codex-cli`:return`codex`;default:return`copilot`}}function W(e){let t=e;for(let e=0;e<10;e++){try{let e=b(t,`package.json`);if(p(e)&&JSON.parse(h(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=y(t);if(e===t)break;t=e}return x(e,`..`,`..`,`..`)}async function G(t){let n=process.cwd();if(!R(n,t.force))return;z(n);let i=B(),a=I(T(n));a.writeMcpConfig(n,i),a.writeInstructions(n,i),a.writeAgentsMd(n,i);let o=W(y(S(import.meta.url))),s=JSON.parse(h(x(o,`package.json`),`utf-8`)).version;await d(n,o,[...e],s,t.force),await l(n,o,[...r],s,t.force);let c=E(n),f=new Set;for(let e of c){let r=U(e);f.has(r)||(f.add(r),await u(n,o,r,s,t.force))}H(n),console.log(`
|
|
4
|
-
AI Kit initialized! Next steps:`),console.log(` aikit reindex Index your codebase`),console.log(` aikit search Search indexed content`),console.log(` aikit serve Start MCP server for IDE integration`),w()&&console.log(`
|
|
5
|
-
Note: User-level AI Kit is also installed. This workspace uses its own local data store.`)}async function K(e){w()?await q(e):await G(e)}async function q(e){let t=process.cwd(),n=B(),i=I(T(t));i.writeInstructions(t,n),i.writeAgentsMd(t,n);let a=W(y(S(import.meta.url))),o=JSON.parse(h(x(a,`package.json`),`utf-8`)).version,s=E(t),c=new Set;for(let n of s){let r=U(n);c.has(r)||(c.add(r),await u(t,a,r,o,e.force))}await l(t,a,[...r],o,e.force),H(t),z(t),console.log(`
|
|
6
|
-
Workspace scaffolded for user-level AI Kit! Files added:`),console.log(` Instruction files (AGENTS.md, copilot-instructions.md, etc.)`),console.log(` .ai/curated/ directories`),console.log(` .github/agents/ & .github/prompts/`),console.log(`
|
|
7
|
-
The user-level AI Kit server will auto-index this workspace when opened in your IDE.`)}async function J(){let t=process.cwd(),n=E(t),i=W(y(S(import.meta.url))),a=[...await c(t,i,[...e])],l=new Set;for(let e of n){let n=U(e);l.has(n)||(l.add(n),a.push(...await s(t,i,n)))}a.push(...await o(t,i,[...r]));let u={summary:{total:a.length,new:a.filter(e=>e.status===`new`).length,outdated:a.filter(e=>e.status===`outdated`).length,current:a.filter(e=>e.status===`current`).length},files:a};console.log(JSON.stringify(u,null,2))}export{J as guideProject,G as initProject,q as initScaffoldOnly,K as initSmart};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{AIKIT_PATHS as a,createLogger as o,getPartitionDir as s,isUserInstalled as c,registerWorkspace as l,serializeError as u}from"../../core/dist/index.js";const d=n(i(import.meta.url)),f=o(`server`),p=[`auto`,`manual`,`smart`];function m(e){return typeof e==`string`&&p.includes(e)}function h(e,t,n){let i=r(e),a=r(t);if(!i.startsWith(a))throw Error(`Config ${n} path escapes workspace root: ${e} is not under ${t}`);return i}function g(e){let t=process.env.AIKIT_INDEX_MODE;if(m(t))return t;if(e.indexMode)return e.indexMode;let n=process.env.AIKIT_AUTO_INDEX;return n===void 0?e.autoIndex===void 0?`smart`:e.autoIndex?`auto`:`manual`:n===`true`?`auto`:`manual`}function _(){let i=process.env.AIKIT_CONFIG_PATH??(e(r(process.cwd(),`aikit.config.json`))?r(process.cwd(),`aikit.config.json`):r(d,`..`,`..`,`..`,`aikit.config.json`));try{if(!e(i))return f.info(`No config file found, using defaults`,{configPath:i}),v();let o=t(i,`utf-8`),s=JSON.parse(o);if(!s.sources||!Array.isArray(s.sources)||s.sources.length===0)throw Error(`Config must have at least one source`);if(!s.store?.path)throw Error(`Config must specify store.path`);if(s.autoIndex!==void 0&&typeof s.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(s.indexMode!==void 0&&!m(s.indexMode))throw Error(`Config indexMode must be one of: ${p.join(`, `)}`);let c=n(i);return s.sources=s.sources.map(e=>({...e,path:h(r(c,e.path),c,`source`)})),s.store.path=h(r(c,s.store.path),c,`store`),s.curated=s.curated??{path:a.aiCurated},s.curated.path=h(r(c,s.curated.path),c,`curated`),y(s,c),s.indexMode=g(s),s}catch(e){return f.error(`Failed to load config`,{configPath:i,...u(e)}),f.warn(`Falling back to default configuration`,{configPath:i}),v()}}function v(){let e=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),t={sources:[{path:e,excludePatterns:[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:`mixedbread-ai/mxbai-embed-large-v1`,dimensions:1024},store:{backend:`sqlite-vec`,path:r(e,a.data)},curated:{path:r(e,a.aiCurated)},onboardDir:r(e,a.aiContext),stateDir:r(e,a.state)};return y(t,e),t.indexMode=g(t),t}function y(e,t){if(!c())return;let n=t,i=l(n);e.store.path=r(s(i.partition)),e.onboardDir=r(s(i.partition),`onboard`),e.stateDir=r(s(i.partition),`state`),e.curated||={path:r(n,a.aiCurated)}}function b(t,n){if(!e(n))throw Error(`Workspace root does not exist: ${n}`);f.info(`Reconfiguring for workspace root`,{workspaceRoot:n});try{process.chdir(n),f.info(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){f.warn(`Failed to chdir to workspace root`,{workspaceRoot:n,...u(e)})}t.sources=[{path:n,excludePatterns:t.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],t.store.path=r(n,a.data),t.curated={path:r(n,a.aiCurated)},t.onboardDir=r(n,a.aiContext),t.stateDir=r(n,a.state),y(t,n)}export{_ as loadConfig,b as reconfigureForWorkspace,g as resolveIndexMode};
|