@vpxa/aikit 0.1.89 → 0.1.91
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 +2 -1
- package/packages/cli/dist/index.js +2 -2
- package/packages/cli/dist/{init-00QyaH6g.js → init-Bq2OlRZG.js} +1 -1
- package/packages/cli/dist/{templates-C-qED27u.js → templates-DrkDLz-X.js} +64 -1
- package/packages/cli/dist/{user-BA8MswUh.js → user-D9ZLFcQD.js} +1 -1
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/{server-CXsoHmuu.js → server-DZ1V42_x.js} +1 -1
- package/packages/store/dist/index.d.ts +3 -0
- package/packages/store/dist/index.js +6 -6
- package/packages/store/dist/lance-store-CQkljFy3.js +1 -0
- package/packages/store/dist/lance-store-jdHZp-V4.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpxa/aikit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.91",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local-first AI developer toolkit — knowledge base, code analysis, context management, and developer tools for LLM agents",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"lru-cache": "^11.x",
|
|
63
63
|
"marked": "^18.x",
|
|
64
64
|
"minimatch": "^10.x",
|
|
65
|
+
"sql.js": "^1.x",
|
|
65
66
|
"tree-sitter-wasms": "~0.1.13",
|
|
66
67
|
"turndown": "^7.x",
|
|
67
68
|
"web-tree-sitter": "~0.24.7",
|
|
@@ -9,7 +9,7 @@ Dead in docs (informational):`);for(let t of e.deadInDocs)console.log(` - ${t.p
|
|
|
9
9
|
Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear`),process.exit(1));let{graphStore:n}=await Y(),r=N(e,`--type`,``),i=N(e,`--name`,``),a=N(e,`--node-id`,``),o=N(e,`--edge-type`,``),s=N(e,`--direction`,`both`),c=M(e,`--depth`,2),l=M(e,`--limit`,50),u=N(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
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}`)}}],Ot=[{name:`remember`,description:`Store curated knowledge`,usage:`aikit remember <title> --category <cat> [--tags tag1,tag2]`,run:async e=>{let t=N(e,`--category`,``).trim(),n=I(N(e,`--tags`,``)),r=e.shift()?.trim()??``,i=await F(),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 Y(),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=N(e,`--reason`,``).trim(),n=e.shift()?.trim()??``;(!n||!t)&&(console.error(`Usage: aikit forget <path> --reason <reason>`),process.exit(1));let{curated:r}=await Y(),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 Y(),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=N(e,`--category`,``).trim()||void 0,n=N(e,`--tag`,``).trim()||void 0,{curated:r}=await Y(),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=N(e,`--reason`,``).trim(),n=e.shift()?.trim()??``,r=await F();(!n||!t||!r.trim())&&(console.error(`Usage: aikit update <path> --reason <reason>`),process.exit(1));let{curated:i}=await Y(),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=M(e,`--max-chars`,3e3),n=N(e,`--path`,``).trim()||void 0,r=N(e,`--segmentation`,`paragraph`),i=e.join(` `).trim(),a=n?void 0:await F();(!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 Y(),s=await ie(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)}}],kt=[{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=M(e,`--limit`,5),n=N(e,`--mode`,`hybrid`),r=M(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 Y(),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=U(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=M(e,`--limit`,10),n=N(e,`--glob`,``).trim()||void 0,r=N(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 Y(),s=await g(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=M(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 Y(),a=await Fe(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: ${at(t.focusRanges)}`)}},{name:`symbol`,description:`Resolve a symbol definition, imports, and references`,usage:`aikit symbol <name> [--limit N]`,run:async e=>{let t=M(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 Y();ht(await Ve(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=N(e,`--direction`,`both`).trim()||`both`,n=M(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 Y();dt(await Ue(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=M(e,`--limit`,5),n=N(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 Y();ft(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=M(e,`--limit`,100),{embedder:n,store:r}=await Y();pt(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 Y(),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 At=[{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 Y(),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 Y();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(Z(X),`packages`,`server`,`dist`,`index.js`),n=N(e,`--transport`,`stdio`),r=N(e,`--port`,`3210`),i=tt(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 [--user|--workspace] [--force] [--guide]`,run:async e=>{let t=e.includes(`--user`),n=e.includes(`--workspace`),r=e.includes(`--guide`),i=e.includes(`--force`);if(t&&n&&(console.error(`Cannot use --user and --workspace together.`),process.exit(1)),r){let{guideProject:e}=await import(`./init-
|
|
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=Me({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}`)}Ne().catch(()=>{})}},{name:`replay-clear`,description:`Clear the replay audit trail`,run:async()=>{je(),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 jt(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 Mt=[{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-BA8MswUh.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-00QyaH6g.js`);await e({force:!0})}if(r(l(i,`.github`,`skills`))){let{smartCopySkills:n}=await import(`./scaffold-D664MT9M.js`),r=jt(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-D664MT9M.js`);await c(i,r,[...t],o,!0)}}}],Nt=[{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=I(N(e,`--files`,``)),r=N(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=Pe(i,n,{description:r});console.log(`Saved workset: ${e.name}`),B(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}B(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)B(t),console.log(``);return}case`delete`:{i||(console.error(`Usage: aikit workset delete <name>`),process.exit(1));let e=ce(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}`),B(e);return}case`remove`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset remove <name> --files f1,f2`),process.exit(1));let e=ke(i,n);if(!e){console.log(`No workset found: ${i}`);return}console.log(`Updated workset: ${e.name}`),B(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 F(),i=Be(n,gt(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=Re(n);if(!e){console.log(`No stash entry found: ${n}`);return}console.log(JSON.stringify(e,null,2));return}case`list`:{let e=ze();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=Le(n);console.log(e?`Deleted stash entry: ${n}`:`No stash entry found: ${n}`);return}case`clear`:{let e=Ie();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=N(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=Ee();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=w(n);console.log(`Queue "${e.name}" created.`);break}case`push`:{let t=Oe(n,e.join(` `)||`Untitled task`);console.log(`Pushed "${t.title}" (${t.id}) to queue "${n}".`);break}case`next`:{let e=De(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=E(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=D(n,t,r);console.log(`Marked "${i.title}" as failed: ${r}`);break}case`get`:{let e=O(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=C(n);console.log(`Cleared ${e} completed/failed items from queue "${n}".`);break}case`delete`:{let e=T(n);console.log(e?`Queue "${n}" deleted.`:`Queue "${n}" not found.`);break}}}}],Q=[...kt,...Ot,...nt,...Dt,...At,...xt,...yt,...Nt,...bt,...Mt,...q];Q.push({name:`help`,description:`Show available commands`,run:async()=>{$()}});async function Pt(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=Et();e&&await e.store.close()}}function $(){console.log(`@vpxa/aikit — Local-first AI developer toolkit
|
|
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(Z(X),`packages`,`server`,`dist`,`index.js`),n=N(e,`--transport`,`stdio`),r=N(e,`--port`,`3210`),i=tt(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 [--user|--workspace] [--force] [--guide]`,run:async e=>{let t=e.includes(`--user`),n=e.includes(`--workspace`),r=e.includes(`--guide`),i=e.includes(`--force`);if(t&&n&&(console.error(`Cannot use --user and --workspace together.`),process.exit(1)),r){let{guideProject:e}=await import(`./init-Bq2OlRZG.js`);await e();return}if(t){let{initUser:e}=await import(`./user-D9ZLFcQD.js`);await e({force:i})}else if(n){let{initProject:e}=await import(`./init-Bq2OlRZG.js`);await e({force:i})}else{let{initSmart:e}=await import(`./init-Bq2OlRZG.js`);await e({force:i})}}},{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=N(e,`--cwd`,``).trim()||void 0,n=N(e,`--files`,``),r=N(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 m({cwd:t,files:i.length>0?i:void 0,skipTypes:a,skipLint:o,detail:r});st(s),s.passed||(process.exitCode=1)}},{name:`batch`,description:`Execute built-in operations from JSON input`,usage:`aikit batch [--file path] [--concurrency N]`,run:async e=>{let t=N(e,`--file`,``).trim()||void 0,n=(()=>{let t=e.indexOf(`--concurrency`);if(t===-1||t+1>=e.length)return 0;let n=Number.parseInt(e.splice(t,2)[1],10);return Number.isNaN(n)?0:n})(),r=await rt(t);r.trim()||(console.error(`Usage: aikit batch [--file path] [--concurrency N]`),process.exit(1));let i=it(r),a=n>0?n:i.concurrency,o=i.operations.some(e=>e.type!==`check`)?await Y():null,s=await p(i.operations,async e=>vt(e,o),{concurrency:a});console.log(JSON.stringify(s,null,2)),s.some(e=>e.status===`error`)&&(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 Y(),r=N(e,`--detail`,`efficient`)||`efficient`,i=N(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=Me({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}`)}Ne().catch(()=>{})}},{name:`replay-clear`,description:`Clear the replay audit trail`,run:async()=>{je(),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 jt(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 Mt=[{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-D9ZLFcQD.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-Bq2OlRZG.js`);await e({force:!0})}if(r(l(i,`.github`,`skills`))){let{smartCopySkills:n}=await import(`./scaffold-D664MT9M.js`),r=jt(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-D664MT9M.js`);await c(i,r,[...t],o,!0)}}}],Nt=[{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=I(N(e,`--files`,``)),r=N(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=Pe(i,n,{description:r});console.log(`Saved workset: ${e.name}`),B(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}B(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)B(t),console.log(``);return}case`delete`:{i||(console.error(`Usage: aikit workset delete <name>`),process.exit(1));let e=ce(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}`),B(e);return}case`remove`:{(!i||n.length===0)&&(console.error(`Usage: aikit workset remove <name> --files f1,f2`),process.exit(1));let e=ke(i,n);if(!e){console.log(`No workset found: ${i}`);return}console.log(`Updated workset: ${e.name}`),B(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 F(),i=Be(n,gt(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=Re(n);if(!e){console.log(`No stash entry found: ${n}`);return}console.log(JSON.stringify(e,null,2));return}case`list`:{let e=ze();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=Le(n);console.log(e?`Deleted stash entry: ${n}`:`No stash entry found: ${n}`);return}case`clear`:{let e=Ie();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=N(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=Ee();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=w(n);console.log(`Queue "${e.name}" created.`);break}case`push`:{let t=Oe(n,e.join(` `)||`Untitled task`);console.log(`Pushed "${t.title}" (${t.id}) to queue "${n}".`);break}case`next`:{let e=De(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=E(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=D(n,t,r);console.log(`Marked "${i.title}" as failed: ${r}`);break}case`get`:{let e=O(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=C(n);console.log(`Cleared ${e} completed/failed items from queue "${n}".`);break}case`delete`:{let e=T(n);console.log(e?`Queue "${n}" deleted.`:`Queue "${n}" not found.`);break}}}}],Q=[...kt,...Ot,...nt,...Dt,...At,...xt,...yt,...Nt,...bt,...Mt,...q];Q.push({name:`help`,description:`Show available commands`,run:async()=>{$()}});async function Pt(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=Et();e&&await e.store.close()}}function $(){console.log(`@vpxa/aikit — Local-first AI developer toolkit
|
|
14
14
|
`),console.log(`Usage: aikit <command> [options]
|
|
15
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{Pt as run};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r}from"./constants-B8_CApx0.js";import{n as i,t as a}from"./templates-
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./constants-B8_CApx0.js";import{n as i,t as a}from"./templates-DrkDLz-X.js";import{guideFlows as o,guideScaffold as s,guideSkills as c,smartCopyClaudeCommands as l,smartCopyFlows as u,smartCopyScaffold as d,smartCopySkills as f}from"./scaffold-D664MT9M.js";import{appendFileSync as p,existsSync as m,mkdirSync as h,readFileSync as g,unlinkSync as _,writeFileSync as v}from"node:fs";import{basename as y,dirname as b,join as x,resolve as S}from"node:path";import{fileURLToPath as C}from"node:url";import{AIKIT_PATHS as w,isUserInstalled as T}from"../../core/dist/index.js";function E(e){return m(S(e,`.cursor`))?`cursor`:m(S(e,`.claude`))?`claude-code`:m(S(e,`.windsurf`))?`windsurf`:`copilot`}function D(e){return{servers:{[e]:{...t}}}}function O(e){let{type:n,...r}=t;return{mcpServers:{[e]:r}}}const k={scaffoldDir:`general`,writeMcpConfig(e,t){let n=S(e,`.vscode`),r=S(n,`mcp.json`);m(r)||(h(n,{recursive:!0}),v(r,`${JSON.stringify(D(t),null,2)}\n`,`utf-8`),console.log(` Created .vscode/mcp.json`))},writeInstructions(e,t){let n=S(e,`.github`),r=S(n,`copilot-instructions.md`);h(n,{recursive:!0}),v(r,i(y(e),t),`utf-8`),console.log(` Updated .github/copilot-instructions.md`)},writeAgentsMd(e,t){v(S(e,`AGENTS.md`),a(y(e),t),`utf-8`),console.log(` Updated AGENTS.md`)}},A={scaffoldDir:`general`,writeMcpConfig(e,t){let n=S(e,`.mcp.json`);m(n)||(v(n,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created .mcp.json`))},writeInstructions(e,t){let n=S(e,`CLAUDE.md`),r=y(e);v(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated CLAUDE.md`)},writeAgentsMd(e,t){}},j={scaffoldDir:`general`,writeMcpConfig(e,t){let n=S(e,`.cursor`),r=S(n,`mcp.json`);m(r)||(h(n,{recursive:!0}),v(r,`${JSON.stringify(O(t),null,2)}\n`,`utf-8`),console.log(` Created .cursor/mcp.json`))},writeInstructions(e,t){let n=S(e,`.cursor`,`rules`),r=S(n,`aikit.mdc`);h(n,{recursive:!0});let o=y(e);v(r,`${i(o,t)}\n---\n\n${a(o,t)}`,`utf-8`),console.log(` Updated .cursor/rules/aikit.mdc`);let s=S(n,`kb.mdc`);m(s)&&s!==r&&(_(s),console.log(` Removed legacy .cursor/rules/kb.mdc`))},writeAgentsMd(e,t){}},M={scaffoldDir:`general`,writeMcpConfig(e,t){let n=S(e,`.vscode`),r=S(n,`mcp.json`);m(r)||(h(n,{recursive:!0}),v(r,`${JSON.stringify(D(t),null,2)}\n`,`utf-8`),console.log(` Created .vscode/mcp.json (Windsurf-compatible)`))},writeInstructions(e,t){let n=S(e,`.windsurfrules`),r=y(e);v(n,`${i(r,t)}\n---\n\n${a(r,t)}`,`utf-8`),console.log(` Updated .windsurfrules`)},writeAgentsMd(e,t){}};function N(e){switch(e){case`copilot`:return k;case`claude-code`:return A;case`cursor`:return j;case`windsurf`:return M}}const P={serverName:n,sources:[{path:`.`,excludePatterns:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.git/**`,`**/${w.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:`lancedb`,path:`${w.data}/lance`},curated:{path:w.aiCurated}};function F(e,t){let n=S(e,`aikit.config.json`);return m(n)&&!t?(console.log(`aikit.config.json already exists. Use --force to overwrite.`),!1):(v(n,`${JSON.stringify(P,null,2)}\n`,`utf-8`),console.log(` Created aikit.config.json`),!0)}function I(e){let t=S(e,`.gitignore`),n=[{dir:`${w.data}/`,label:`AI Kit vector store`},{dir:`${w.state}/`,label:`AI Kit session state`},{dir:`${w.restorePoints}/`,label:`Restore points (codemod/rename undo snapshots)`},{dir:`${w.brainstorm}/`,label:`Brainstorming sessions`},{dir:`${w.handoffs}/`,label:`Handoff documents`}];if(m(t)){let e=g(t,`utf-8`),r=n.filter(t=>!e.includes(t.dir));r.length>0&&(p(t,`\n${r.map(e=>`# ${e.label}\n${e.dir}`).join(`
|
|
2
2
|
`)}\n`,`utf-8`),console.log(` Added ${r.map(e=>e.dir).join(`, `)} to .gitignore`))}else v(t,`${n.map(e=>`# ${e.label}\n${e.dir}`).join(`
|
|
3
3
|
`)}\n`,`utf-8`),console.log(` Created .gitignore with AI Kit entries`)}function L(){return P.serverName}const R=[`decisions`,`patterns`,`conventions`,`troubleshooting`];function z(e){let t=S(e,`.ai`,`curated`);m(t)||(h(t,{recursive:!0}),console.log(` Created .ai/curated/`));for(let e of R){let n=S(t,e);m(n)||h(n,{recursive:!0})}console.log(` Created .ai/curated/{${R.join(`,`)}}/`)}function B(e){let t=e;for(let e=0;e<10;e++){try{let e=x(t,`package.json`);if(m(e)&&JSON.parse(g(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=b(t);if(e===t)break;t=e}return S(e,`..`,`..`,`..`)}async function V(t){let n=process.cwd();if(!F(n,t.force))return;I(n);let i=L(),a=N(E(n));a.writeMcpConfig(n,i),a.writeInstructions(n,i),a.writeAgentsMd(n,i);let o=B(b(C(import.meta.url))),s=JSON.parse(g(S(o,`package.json`),`utf-8`)).version;await f(n,o,[...e],s,t.force),await u(n,o,[...r],s,t.force),await d(n,o,`copilot`,s,t.force),await l(n,o,s,t.force),z(n),console.log(`
|
|
4
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(`
|
|
@@ -111,7 +111,7 @@ search({ query: "SESSION CHECKPOINT", origin: "curated" })
|
|
|
111
111
|
|
|
112
112
|
## AI Kit MCP Server (\`${t}\`)
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
Tools for search, code analysis, persistent memory, validation, and context compression.
|
|
115
115
|
Load them: \`tool_search_tool_regex({ pattern: "aikit" })\`
|
|
116
116
|
|
|
117
117
|
### Skills Reference
|
|
@@ -173,6 +173,69 @@ Need to understand a file?
|
|
|
173
173
|
|
|
174
174
|
---
|
|
175
175
|
|
|
176
|
+
## Guidelines
|
|
177
|
+
|
|
178
|
+
Behavioral guidelines to reduce common LLM coding mistakes. Apply when writing, reviewing, or refactoring code.
|
|
179
|
+
|
|
180
|
+
**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
|
|
181
|
+
|
|
182
|
+
### 1. Think Before Coding
|
|
183
|
+
|
|
184
|
+
**Don't assume. Don't hide confusion. Surface tradeoffs.**
|
|
185
|
+
|
|
186
|
+
- State assumptions explicitly. If uncertain, ask.
|
|
187
|
+
- If multiple interpretations exist, present them — don't pick silently.
|
|
188
|
+
- If a simpler approach exists, say so. Push back when warranted.
|
|
189
|
+
- If something is unclear, stop. Name what's confusing. Ask.
|
|
190
|
+
|
|
191
|
+
### 2. Simplicity First
|
|
192
|
+
|
|
193
|
+
**Minimum code that solves the problem. Nothing speculative.**
|
|
194
|
+
|
|
195
|
+
- No features beyond what was asked.
|
|
196
|
+
- No abstractions for single-use code.
|
|
197
|
+
- No "flexibility" or "configurability" that wasn't requested.
|
|
198
|
+
- No error handling for impossible scenarios.
|
|
199
|
+
- If you write 200 lines and it could be 50, rewrite it.
|
|
200
|
+
|
|
201
|
+
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
|
|
202
|
+
|
|
203
|
+
### 3. Surgical Changes
|
|
204
|
+
|
|
205
|
+
**Touch only what you must. Clean up only your own mess.**
|
|
206
|
+
|
|
207
|
+
When editing existing code:
|
|
208
|
+
- Don't "improve" adjacent code, comments, or formatting.
|
|
209
|
+
- Don't refactor things that aren't broken.
|
|
210
|
+
- Match existing style, even if you'd do it differently.
|
|
211
|
+
- If you notice unrelated dead code, mention it — don't delete it.
|
|
212
|
+
|
|
213
|
+
When your changes create orphans:
|
|
214
|
+
- Remove imports/variables/functions that YOUR changes made unused.
|
|
215
|
+
- Don't remove pre-existing dead code unless asked.
|
|
216
|
+
|
|
217
|
+
The test: Every changed line should trace directly to the user's request.
|
|
218
|
+
|
|
219
|
+
### 4. Goal-Driven Execution
|
|
220
|
+
|
|
221
|
+
**Define success criteria. Loop until verified.**
|
|
222
|
+
|
|
223
|
+
Transform tasks into verifiable goals:
|
|
224
|
+
- "Add validation" → "Write tests for invalid inputs, then make them pass"
|
|
225
|
+
- "Fix the bug" → "Write a test that reproduces it, then make it pass"
|
|
226
|
+
- "Refactor X" → "Ensure tests pass before and after"
|
|
227
|
+
|
|
228
|
+
For multi-step tasks, state a brief plan:
|
|
229
|
+
\`\`\`
|
|
230
|
+
1. [Step] → verify: [check]
|
|
231
|
+
2. [Step] → verify: [check]
|
|
232
|
+
3. [Step] → verify: [check]
|
|
233
|
+
\`\`\`
|
|
234
|
+
|
|
235
|
+
Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
176
239
|
## Full Documentation
|
|
177
240
|
|
|
178
241
|
For complete tool documentation (82 tools), workflow chains, search strategies, session protocol, and persistent memory patterns, load the \`aikit\` skill at session start.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,n as t,r as n}from"./constants-B8_CApx0.js";import{n as r,t as i}from"./templates-C-qED27u.js";import{loadAdapter as a,n as o,r as s,smartCopyFromMemory as c,t as l}from"./scaffold-D664MT9M.js";import{existsSync as u,mkdirSync as d,readFileSync as f,readdirSync as p,rmSync as m,unlinkSync as h,writeFileSync as g}from"node:fs";import{dirname as _,join as v,posix as y,resolve as b,win32 as x}from"node:path";import{fileURLToPath as S}from"node:url";import{mkdir as C,readFile as w,rename as T,unlink as E,writeFile as D}from"node:fs/promises";import{getGlobalDataDir as O,saveRegistry as k}from"../../core/dist/index.js";import{execFileSync as A}from"node:child_process";import{randomUUID as j}from"node:crypto";import{homedir as M}from"node:os";var N=class{isPlatformSupported(){return this.platforms.includes(process.platform)}async readConfig(e){let t=this.getConfigPath(e);if(!u(t))return{};let n=await w(t,`utf-8`);try{return JSON.parse(n)}catch{throw Error(`Invalid JSON in ${t}. Please fix or remove the file before retrying.`)}}async writeConfig(e,t){let n=this.getConfigPath(t),r=_(n),i=v(r,`.aikit-tmp-${j()}.json`);await C(r,{recursive:!0});try{await D(i,`${JSON.stringify(e,null,2)}\n`,`utf-8`),await T(i,n)}catch(e){try{await E(i)}catch{}throw e}}async registerMcp(e,t,n){let r=await this.readConfig(n);r[this.configKey]||(r[this.configKey]={}),r[this.configKey][e]=t,await this.writeConfig(r,n)}async unregisterMcp(e,t){let n=await this.readConfig(t);n[this.configKey]&&(delete n[this.configKey][e],await this.writeConfig(n,t))}getScaffoldRoot(e){return null}getInstructionsRoot(e){return null}getScaffoldPaths(e){return{agents:null,skills:null,prompts:null,flows:null,commands:null,instructions:null,manifest:null}}buildInstructionContent(e,t){return`${e}\n---\n\n${t}`}},P=class extends N{id=`claude-code`;name=`Claude Code`;family=`claude`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(this.getPathModule().resolve(M(),`.claude`)):!1}getConfigPath(){return this.getPathModule().resolve(M(),`.claude`,`mcp.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),`.claude`)}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),`.claude`);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:null,flows:e.resolve(t,`flows`),commands:e.resolve(t,`commands`),instructions:e.resolve(t,`CLAUDE.md`),manifest:e.resolve(t,`.aikit-scaffold.json`)}}buildInstructionContent(e,t){return`${e}\n---\n\n${t}`}getPathModule(){return process.platform===`win32`?x:y}},F=class extends N{id=`codex-cli`;name=`Codex CLI`;family=`codex`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(this.getPathModule().resolve(M(),`.codex`)):!1}getConfigPath(){return this.getPathModule().resolve(M(),`.codex`,`config.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),`.codex`)}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),`.codex`);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:null,flows:e.resolve(t,`flows`),commands:null,instructions:e.resolve(t,`AGENTS.md`),manifest:e.resolve(t,`.aikit-scaffold.json`)}}getPathModule(){return process.platform===`win32`?x:y}},I=class extends N{family=`copilot`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;hasInstructions=!1;async detect(){if(!this.isPlatformSupported())return!1;let e=this.getConfigDir();if(process.platform===`darwin`){let t=this.getMacAppPath();return u(e)||t!==null&&u(t)}return u(e)}getConfigPath(){return this.getPathModule().resolve(this.getConfigDir(),`mcp.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),this.scaffoldBase)}getInstructionsRoot(){let e=this.getInstructionFilePath();return e?this.getPathModule().dirname(e):null}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),this.scaffoldBase);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:e.resolve(this.getConfigDir(),`prompts`),flows:e.resolve(t,`flows`),commands:null,instructions:this.getInstructionFilePath(),manifest:e.resolve(t,`.aikit-scaffold.json`)}}getConfigDir(){let e=this.getPathModule(),t=M();if(process.platform===`win32`){let n=process.env.APPDATA??e.resolve(t,`AppData`,`Roaming`);return e.resolve(n,this.configDirName,`User`)}if(process.platform===`darwin`)return e.resolve(t,`Library`,`Application Support`,this.configDirName,`User`);let n=process.env.XDG_CONFIG_HOME??e.resolve(t,`.config`);return e.resolve(n,this.configDirName,`User`)}getMacAppPath(){return null}getInstructionFilePath(){return null}getPathModule(){return process.platform===`win32`?x:y}},L=class extends N{id=`copilot-cli`;name=`Copilot CLI`;family=`copilot`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(b(M(),`.copilot`)):!1}getConfigPath(){return b(M(),`.copilot`,`mcp-config.json`)}async registerMcp(e,t,n){let r={...t,tools:[`*`]},i=await this.readConfig(n);i[this.configKey]||(i[this.configKey]={}),i[this.configKey][e]=r,await this.writeConfig(i,n)}getScaffoldRoot(){return b(M(),`.copilot`)}getInstructionsRoot(){return null}getScaffoldPaths(){let e=b(M(),`.copilot`);return{agents:b(e,`agents`),skills:b(e,`skills`),prompts:null,flows:b(e,`flows`),commands:null,instructions:b(M(),`.github`,`copilot-instructions.md`),manifest:b(e,`.aikit-scaffold.json`)}}},R=class extends I{id=`cursor`;name=`Cursor`;configKey=`mcpServers`;configDirName=`Cursor`;scaffoldBase=`.cursor`;getMacAppPath(){return`/Applications/Cursor.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.mdc`)}},z=class extends I{id=`cursor-nightly`;name=`Cursor Nightly`;configKey=`mcpServers`;configDirName=`Cursor Nightly`;scaffoldBase=`.cursor`;getMacAppPath(){return`/Applications/Cursor Nightly.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.mdc`)}},B=class e extends N{id=`intellij`;name=`IntelliJ IDEA`;family=`copilot`;platforms=[`win32`,`darwin`,`linux`];scope=`workspace`;configKey=`servers`;static PRODUCTS=[`IntelliJIdea`,`IdeaIC`,`WebStorm`,`PyCharm`,`PyCharmCE`,`GoLand`,`PhpStorm`,`CLion`,`Rider`,`RubyMine`,`RustRover`,`DataGrip`];async detect(){if(!this.isPlatformSupported())return!1;let t=this.getJetBrainsBaseDir();if(!u(t))return!1;try{return p(t,{withFileTypes:!0}).some(t=>t.isDirectory()&&e.PRODUCTS.some(e=>t.name.startsWith(e)))}catch{return!1}}getConfigPath(e){if(!e)throw Error(`IntelliJ adapter requires projectRoot (scope: workspace)`);return b(e,`mcp.json`)}async registerMcp(e,t,n){let r={type:`stdio`,...t};await super.registerMcp(e,r,n)}getScaffoldRoot(e){return e?b(e,`.github`,`agents`):null}getInstructionsRoot(e){return null}getScaffoldPaths(e){return e?{agents:b(e,`.github`,`agents`),skills:null,prompts:null,flows:null,commands:null,instructions:b(e,`AGENTS.md`),manifest:null}:{agents:null,skills:null,prompts:null,flows:null,commands:null,instructions:null,manifest:null}}buildInstructionContent(e,t){return t}getJetBrainsBaseDir(){let e=M();return process.platform===`win32`?b(process.env.APPDATA??b(e,`AppData`,`Roaming`),`JetBrains`):process.platform===`darwin`?b(e,`Library`,`Application Support`,`JetBrains`):b(process.env.XDG_CONFIG_HOME??b(e,`.config`),`JetBrains`)}},V=class extends I{id=`trae`;name=`Trae`;configKey=`servers`;configDirName=`Trae`;scaffoldBase=`.trae`;getMacAppPath(){return`/Applications/Trae.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.md`)}},H=class extends I{id=`vscode`;name=`VS Code`;configKey=`servers`;configDirName=`Code`;scaffoldBase=`.copilot`;hasInstructions=!0;getMacAppPath(){return`/Applications/Visual Studio Code.app`}getInstructionFilePath(){return this.hasInstructions?this.getPathModule().resolve(M(),this.scaffoldBase,`instructions`,`copilot-instructions.md`):null}buildInstructionContent(e,t){return`---\napplyTo: "**"\n---\n\n${e}\n---\n\n${t}`}},U=class extends I{id=`vscode-insiders`;name=`VS Code Insiders`;configKey=`servers`;configDirName=`Code - Insiders`;scaffoldBase=`.copilot`;hasInstructions=!0;getMacAppPath(){return`/Applications/Visual Studio Code - Insiders.app`}getInstructionFilePath(){return this.hasInstructions?this.getPathModule().resolve(M(),this.scaffoldBase,`instructions`,`copilot-instructions.md`):null}buildInstructionContent(e,t){return`---\napplyTo: "**"\n---\n\n${e}\n---\n\n${t}`}},W=class extends I{id=`vscodium`;name=`VSCodium`;configKey=`servers`;configDirName=`VSCodium`;scaffoldBase=`.copilot`;hasInstructions=!0;getMacAppPath(){return`/Applications/VSCodium.app`}getInstructionFilePath(){return this.hasInstructions?this.getPathModule().resolve(M(),this.scaffoldBase,`instructions`,`copilot-instructions.md`):null}buildInstructionContent(e,t){return`---\napplyTo: "**"\n---\n\n${e}\n---\n\n${t}`}},G=class extends I{id=`windsurf`;name=`Windsurf`;configKey=`servers`;configDirName=`Windsurf`;scaffoldBase=`.windsurf`;getMacAppPath(){return`/Applications/Windsurf.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.md`)}},K=class extends N{id=`gemini-cli`;name=`Gemini CLI`;family=`gemini`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(this.getPathModule().resolve(M(),`.gemini`)):!1}getConfigPath(){return this.getPathModule().resolve(M(),`.gemini`,`settings.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),`.gemini`)}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),`.gemini`);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:null,flows:e.resolve(t,`flows`),commands:null,instructions:e.resolve(t,`AGENTS.md`),manifest:e.resolve(t,`.aikit-scaffold.json`)}}getPathModule(){return process.platform===`win32`?x:y}};const q=[new H,new U,new W,new R,new z,new G,new V,new L,new B,new P,new K,new F];function J(){return[...q]}async function Y(e){let t=e?.scope?q.filter(t=>t.scope===e.scope):q;return(await Promise.allSettled(t.map(async e=>await e.detect()?e:null))).flatMap(e=>e.status!==`fulfilled`||e.value===null?[]:[e.value])}function X(e){let t=e;for(let e=0;e<10;e++){try{let e=v(t,`package.json`);if(u(e)&&JSON.parse(f(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=_(t);if(e===t)break;t=e}return b(e,`..`,`..`,`..`)}function Z(){let e={command:t.command,args:t.args?[...t.args]:void 0,type:t.type};if(process.platform!==`win32`){let t=process.env.PATH;t&&(e.env={PATH:t});try{let t=A(`which`,[`npx`],{encoding:`utf-8`,timeout:3e3}).trim();t&&u(t)&&(e.command=t)}catch{}}return e}const Q=new Set([`VS Code`,`VS Code Insiders`,`VSCodium`]);function $(t,n=!1){if(!Q.has(t.name))return;let r=b(_(t.getConfigPath()),`settings.json`),i={};if(u(r))try{let e=f(r,`utf-8`);i=JSON.parse(e)}catch{console.log(` ${t.name}: skipped settings.json (invalid JSON)`);return}let a=!1;for(let[t,r]of Object.entries(e))if(typeof r==`object`&&r){let e=typeof i[t]==`object`&&i[t]!==null?i[t]:{},n={...e,...r};JSON.stringify(n)!==JSON.stringify(e)&&(i[t]=n,a=!0)}else (n||!(t in i))&&(i[t]=r,a=!0);a&&(g(r,`${JSON.stringify(i,null,2)}\n`,`utf-8`),console.log(` ${t.name}: updated settings.json`))}async function ee(e,t,n,f,p=!1){let h=new Map;for(let e of t)e.getScaffoldRoot()!==null&&h.set(e.id,e);if(t.some(e=>Q.has(e.name))){let e=J().find(e=>e.id===`copilot-cli`);e&&h.set(e.id,e)}if(h.size===0){console.log(` No IDEs with global scaffold support detected.`);return}let v=await a(e,`copilot`),y=new Map;for(let e of v){let t=e.path.indexOf(`/`);if(t===-1)continue;let n=e.path.substring(0,t);if(n!==`agents`&&n!==`prompts`)continue;let r=y.get(n)??[];r.push({path:e.path.substring(t+1),content:e.content}),y.set(n,r)}let x=await a(e,`skills`),S=new Set;for(let e of x){let t=e.path.indexOf(`/`);t!==-1&&S.add(e.path.substring(0,t))}let C=await a(e,`flows`),w=new Set;for(let e of C){let t=e.path.indexOf(`/`);t!==-1&&w.add(e.path.substring(0,t))}let T=await a(e,`claude-code`),E=new Set,D=new Set,O=new Set,k=(e,t,n)=>{let r=y.get(n);if(!e||!t||!r||r.length===0)return;let i=`${n}:${t}:${e}`;if(E.has(i))return;E.add(i);let a=o(t)??l(f);a.version=f,c(r,e,a,n,p),s(t,a),O.add(_(t))},A=(e,t,n,r)=>{if(!e||!t||r.length===0)return;let i=`${n}:${t}:${e}`;if(E.has(i))return;if(E.add(i),n===`flows`&&!D.has(e)){for(let n of w){let r=b(e,n,`skills`);u(r)&&(m(r,{recursive:!0,force:!0}),console.log(` ${_(t)}: migrated ${n} flow to steps/ layout`))}D.add(e)}let a=o(t)??l(f);a.version=f,c(r,e,a,n,p),s(t,a),O.add(_(t))};for(let e of h.values()){let t=e.getScaffoldPaths();k(t.agents,t.manifest,`agents`),k(t.prompts,t.manifest,`prompts`),A(t.skills,t.manifest,`skills`,x),A(t.flows,t.manifest,`flows`,C),A(t.commands,t.manifest,`commands`,T)}for(let e of O)console.log(` ${e}: scaffold updated (${S.size} skills)`);let j=new Set,M=r(`aikit`,n),N=i(`aikit`,n);for(let e of h.values()){let t=e.getScaffoldPaths().instructions;!t||j.has(t)||(d(_(t),{recursive:!0}),g(t,e.buildInstructionContent(M,N),`utf-8`),j.add(t))}j.size>0&&console.log(` Instruction files: ${[...j].join(`, `)}`)}function te(e){let t=[];for(let n of e){let e=n.getScaffoldRoot();if(e)if(Q.has(n.name)){let r=n.getInstructionsRoot()??e;t.push(b(r,`kb.instructions.md`)),t.push(b(r,`aikit.instructions.md`))}else n.name===`Cursor`||n.name===`Cursor Nightly`?t.push(b(e,`rules`,`kb.mdc`)):n.name===`Windsurf`&&t.push(b(e,`rules`,`kb.md`))}for(let e of t)u(e)&&(h(e),console.log(` Removed legacy file: ${e}`))}async function ne(e){let t=n,r=X(_(S(import.meta.url))),i=JSON.parse(f(b(r,`package.json`),`utf-8`)).version;console.log(`Initializing @vpxa/aikit v${i}...\n`);let a=O();d(a,{recursive:!0}),console.log(` Global data store: ${a}`),k({version:1,workspaces:{}}),console.log(` Created registry.json`);let o=await Y({scope:`user`});if(o.length===0)console.log(`
|
|
1
|
+
import{a as e,n as t,r as n}from"./constants-B8_CApx0.js";import{n as r,t as i}from"./templates-DrkDLz-X.js";import{loadAdapter as a,n as o,r as s,smartCopyFromMemory as c,t as l}from"./scaffold-D664MT9M.js";import{existsSync as u,mkdirSync as d,readFileSync as f,readdirSync as p,rmSync as m,unlinkSync as h,writeFileSync as g}from"node:fs";import{dirname as _,join as v,posix as y,resolve as b,win32 as x}from"node:path";import{fileURLToPath as S}from"node:url";import{mkdir as C,readFile as w,rename as T,unlink as E,writeFile as D}from"node:fs/promises";import{getGlobalDataDir as O,saveRegistry as k}from"../../core/dist/index.js";import{execFileSync as A}from"node:child_process";import{randomUUID as j}from"node:crypto";import{homedir as M}from"node:os";var N=class{isPlatformSupported(){return this.platforms.includes(process.platform)}async readConfig(e){let t=this.getConfigPath(e);if(!u(t))return{};let n=await w(t,`utf-8`);try{return JSON.parse(n)}catch{throw Error(`Invalid JSON in ${t}. Please fix or remove the file before retrying.`)}}async writeConfig(e,t){let n=this.getConfigPath(t),r=_(n),i=v(r,`.aikit-tmp-${j()}.json`);await C(r,{recursive:!0});try{await D(i,`${JSON.stringify(e,null,2)}\n`,`utf-8`),await T(i,n)}catch(e){try{await E(i)}catch{}throw e}}async registerMcp(e,t,n){let r=await this.readConfig(n);r[this.configKey]||(r[this.configKey]={}),r[this.configKey][e]=t,await this.writeConfig(r,n)}async unregisterMcp(e,t){let n=await this.readConfig(t);n[this.configKey]&&(delete n[this.configKey][e],await this.writeConfig(n,t))}getScaffoldRoot(e){return null}getInstructionsRoot(e){return null}getScaffoldPaths(e){return{agents:null,skills:null,prompts:null,flows:null,commands:null,instructions:null,manifest:null}}buildInstructionContent(e,t){return`${e}\n---\n\n${t}`}},P=class extends N{id=`claude-code`;name=`Claude Code`;family=`claude`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(this.getPathModule().resolve(M(),`.claude`)):!1}getConfigPath(){return this.getPathModule().resolve(M(),`.claude`,`mcp.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),`.claude`)}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),`.claude`);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:null,flows:e.resolve(t,`flows`),commands:e.resolve(t,`commands`),instructions:e.resolve(t,`CLAUDE.md`),manifest:e.resolve(t,`.aikit-scaffold.json`)}}buildInstructionContent(e,t){return`${e}\n---\n\n${t}`}getPathModule(){return process.platform===`win32`?x:y}},F=class extends N{id=`codex-cli`;name=`Codex CLI`;family=`codex`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(this.getPathModule().resolve(M(),`.codex`)):!1}getConfigPath(){return this.getPathModule().resolve(M(),`.codex`,`config.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),`.codex`)}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),`.codex`);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:null,flows:e.resolve(t,`flows`),commands:null,instructions:e.resolve(t,`AGENTS.md`),manifest:e.resolve(t,`.aikit-scaffold.json`)}}getPathModule(){return process.platform===`win32`?x:y}},I=class extends N{family=`copilot`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;hasInstructions=!1;async detect(){if(!this.isPlatformSupported())return!1;let e=this.getConfigDir();if(process.platform===`darwin`){let t=this.getMacAppPath();return u(e)||t!==null&&u(t)}return u(e)}getConfigPath(){return this.getPathModule().resolve(this.getConfigDir(),`mcp.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),this.scaffoldBase)}getInstructionsRoot(){let e=this.getInstructionFilePath();return e?this.getPathModule().dirname(e):null}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),this.scaffoldBase);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:e.resolve(this.getConfigDir(),`prompts`),flows:e.resolve(t,`flows`),commands:null,instructions:this.getInstructionFilePath(),manifest:e.resolve(t,`.aikit-scaffold.json`)}}getConfigDir(){let e=this.getPathModule(),t=M();if(process.platform===`win32`){let n=process.env.APPDATA??e.resolve(t,`AppData`,`Roaming`);return e.resolve(n,this.configDirName,`User`)}if(process.platform===`darwin`)return e.resolve(t,`Library`,`Application Support`,this.configDirName,`User`);let n=process.env.XDG_CONFIG_HOME??e.resolve(t,`.config`);return e.resolve(n,this.configDirName,`User`)}getMacAppPath(){return null}getInstructionFilePath(){return null}getPathModule(){return process.platform===`win32`?x:y}},L=class extends N{id=`copilot-cli`;name=`Copilot CLI`;family=`copilot`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(b(M(),`.copilot`)):!1}getConfigPath(){return b(M(),`.copilot`,`mcp-config.json`)}async registerMcp(e,t,n){let r={...t,tools:[`*`]},i=await this.readConfig(n);i[this.configKey]||(i[this.configKey]={}),i[this.configKey][e]=r,await this.writeConfig(i,n)}getScaffoldRoot(){return b(M(),`.copilot`)}getInstructionsRoot(){return null}getScaffoldPaths(){let e=b(M(),`.copilot`);return{agents:b(e,`agents`),skills:b(e,`skills`),prompts:null,flows:b(e,`flows`),commands:null,instructions:b(M(),`.github`,`copilot-instructions.md`),manifest:b(e,`.aikit-scaffold.json`)}}},R=class extends I{id=`cursor`;name=`Cursor`;configKey=`mcpServers`;configDirName=`Cursor`;scaffoldBase=`.cursor`;getMacAppPath(){return`/Applications/Cursor.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.mdc`)}},z=class extends I{id=`cursor-nightly`;name=`Cursor Nightly`;configKey=`mcpServers`;configDirName=`Cursor Nightly`;scaffoldBase=`.cursor`;getMacAppPath(){return`/Applications/Cursor Nightly.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.mdc`)}},B=class e extends N{id=`intellij`;name=`IntelliJ IDEA`;family=`copilot`;platforms=[`win32`,`darwin`,`linux`];scope=`workspace`;configKey=`servers`;static PRODUCTS=[`IntelliJIdea`,`IdeaIC`,`WebStorm`,`PyCharm`,`PyCharmCE`,`GoLand`,`PhpStorm`,`CLion`,`Rider`,`RubyMine`,`RustRover`,`DataGrip`];async detect(){if(!this.isPlatformSupported())return!1;let t=this.getJetBrainsBaseDir();if(!u(t))return!1;try{return p(t,{withFileTypes:!0}).some(t=>t.isDirectory()&&e.PRODUCTS.some(e=>t.name.startsWith(e)))}catch{return!1}}getConfigPath(e){if(!e)throw Error(`IntelliJ adapter requires projectRoot (scope: workspace)`);return b(e,`mcp.json`)}async registerMcp(e,t,n){let r={type:`stdio`,...t};await super.registerMcp(e,r,n)}getScaffoldRoot(e){return e?b(e,`.github`,`agents`):null}getInstructionsRoot(e){return null}getScaffoldPaths(e){return e?{agents:b(e,`.github`,`agents`),skills:null,prompts:null,flows:null,commands:null,instructions:b(e,`AGENTS.md`),manifest:null}:{agents:null,skills:null,prompts:null,flows:null,commands:null,instructions:null,manifest:null}}buildInstructionContent(e,t){return t}getJetBrainsBaseDir(){let e=M();return process.platform===`win32`?b(process.env.APPDATA??b(e,`AppData`,`Roaming`),`JetBrains`):process.platform===`darwin`?b(e,`Library`,`Application Support`,`JetBrains`):b(process.env.XDG_CONFIG_HOME??b(e,`.config`),`JetBrains`)}},V=class extends I{id=`trae`;name=`Trae`;configKey=`servers`;configDirName=`Trae`;scaffoldBase=`.trae`;getMacAppPath(){return`/Applications/Trae.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.md`)}},H=class extends I{id=`vscode`;name=`VS Code`;configKey=`servers`;configDirName=`Code`;scaffoldBase=`.copilot`;hasInstructions=!0;getMacAppPath(){return`/Applications/Visual Studio Code.app`}getInstructionFilePath(){return this.hasInstructions?this.getPathModule().resolve(M(),this.scaffoldBase,`instructions`,`copilot-instructions.md`):null}buildInstructionContent(e,t){return`---\napplyTo: "**"\n---\n\n${e}\n---\n\n${t}`}},U=class extends I{id=`vscode-insiders`;name=`VS Code Insiders`;configKey=`servers`;configDirName=`Code - Insiders`;scaffoldBase=`.copilot`;hasInstructions=!0;getMacAppPath(){return`/Applications/Visual Studio Code - Insiders.app`}getInstructionFilePath(){return this.hasInstructions?this.getPathModule().resolve(M(),this.scaffoldBase,`instructions`,`copilot-instructions.md`):null}buildInstructionContent(e,t){return`---\napplyTo: "**"\n---\n\n${e}\n---\n\n${t}`}},W=class extends I{id=`vscodium`;name=`VSCodium`;configKey=`servers`;configDirName=`VSCodium`;scaffoldBase=`.copilot`;hasInstructions=!0;getMacAppPath(){return`/Applications/VSCodium.app`}getInstructionFilePath(){return this.hasInstructions?this.getPathModule().resolve(M(),this.scaffoldBase,`instructions`,`copilot-instructions.md`):null}buildInstructionContent(e,t){return`---\napplyTo: "**"\n---\n\n${e}\n---\n\n${t}`}},G=class extends I{id=`windsurf`;name=`Windsurf`;configKey=`servers`;configDirName=`Windsurf`;scaffoldBase=`.windsurf`;getMacAppPath(){return`/Applications/Windsurf.app`}getInstructionFilePath(){return this.getPathModule().resolve(M(),this.scaffoldBase,`rules`,`aikit.md`)}},K=class extends N{id=`gemini-cli`;name=`Gemini CLI`;family=`gemini`;platforms=[`win32`,`darwin`,`linux`];scope=`user`;configKey=`mcpServers`;async detect(){return this.isPlatformSupported()?u(this.getPathModule().resolve(M(),`.gemini`)):!1}getConfigPath(){return this.getPathModule().resolve(M(),`.gemini`,`settings.json`)}getScaffoldRoot(){return this.getPathModule().resolve(M(),`.gemini`)}getScaffoldPaths(){let e=this.getPathModule(),t=e.resolve(M(),`.gemini`);return{agents:e.resolve(t,`agents`),skills:e.resolve(t,`skills`),prompts:null,flows:e.resolve(t,`flows`),commands:null,instructions:e.resolve(t,`AGENTS.md`),manifest:e.resolve(t,`.aikit-scaffold.json`)}}getPathModule(){return process.platform===`win32`?x:y}};const q=[new H,new U,new W,new R,new z,new G,new V,new L,new B,new P,new K,new F];function J(){return[...q]}async function Y(e){let t=e?.scope?q.filter(t=>t.scope===e.scope):q;return(await Promise.allSettled(t.map(async e=>await e.detect()?e:null))).flatMap(e=>e.status!==`fulfilled`||e.value===null?[]:[e.value])}function X(e){let t=e;for(let e=0;e<10;e++){try{let e=v(t,`package.json`);if(u(e)&&JSON.parse(f(e,`utf8`)).name===`@vpxa/aikit`)return t}catch{}let e=_(t);if(e===t)break;t=e}return b(e,`..`,`..`,`..`)}function Z(){let e={command:t.command,args:t.args?[...t.args]:void 0,type:t.type};if(process.platform!==`win32`){let t=process.env.PATH;t&&(e.env={PATH:t});try{let t=A(`which`,[`npx`],{encoding:`utf-8`,timeout:3e3}).trim();t&&u(t)&&(e.command=t)}catch{}}return e}const Q=new Set([`VS Code`,`VS Code Insiders`,`VSCodium`]);function $(t,n=!1){if(!Q.has(t.name))return;let r=b(_(t.getConfigPath()),`settings.json`),i={};if(u(r))try{let e=f(r,`utf-8`);i=JSON.parse(e)}catch{console.log(` ${t.name}: skipped settings.json (invalid JSON)`);return}let a=!1;for(let[t,r]of Object.entries(e))if(typeof r==`object`&&r){let e=typeof i[t]==`object`&&i[t]!==null?i[t]:{},n={...e,...r};JSON.stringify(n)!==JSON.stringify(e)&&(i[t]=n,a=!0)}else (n||!(t in i))&&(i[t]=r,a=!0);a&&(g(r,`${JSON.stringify(i,null,2)}\n`,`utf-8`),console.log(` ${t.name}: updated settings.json`))}async function ee(e,t,n,f,p=!1){let h=new Map;for(let e of t)e.getScaffoldRoot()!==null&&h.set(e.id,e);if(t.some(e=>Q.has(e.name))){let e=J().find(e=>e.id===`copilot-cli`);e&&h.set(e.id,e)}if(h.size===0){console.log(` No IDEs with global scaffold support detected.`);return}let v=await a(e,`copilot`),y=new Map;for(let e of v){let t=e.path.indexOf(`/`);if(t===-1)continue;let n=e.path.substring(0,t);if(n!==`agents`&&n!==`prompts`)continue;let r=y.get(n)??[];r.push({path:e.path.substring(t+1),content:e.content}),y.set(n,r)}let x=await a(e,`skills`),S=new Set;for(let e of x){let t=e.path.indexOf(`/`);t!==-1&&S.add(e.path.substring(0,t))}let C=await a(e,`flows`),w=new Set;for(let e of C){let t=e.path.indexOf(`/`);t!==-1&&w.add(e.path.substring(0,t))}let T=await a(e,`claude-code`),E=new Set,D=new Set,O=new Set,k=(e,t,n)=>{let r=y.get(n);if(!e||!t||!r||r.length===0)return;let i=`${n}:${t}:${e}`;if(E.has(i))return;E.add(i);let a=o(t)??l(f);a.version=f,c(r,e,a,n,p),s(t,a),O.add(_(t))},A=(e,t,n,r)=>{if(!e||!t||r.length===0)return;let i=`${n}:${t}:${e}`;if(E.has(i))return;if(E.add(i),n===`flows`&&!D.has(e)){for(let n of w){let r=b(e,n,`skills`);u(r)&&(m(r,{recursive:!0,force:!0}),console.log(` ${_(t)}: migrated ${n} flow to steps/ layout`))}D.add(e)}let a=o(t)??l(f);a.version=f,c(r,e,a,n,p),s(t,a),O.add(_(t))};for(let e of h.values()){let t=e.getScaffoldPaths();k(t.agents,t.manifest,`agents`),k(t.prompts,t.manifest,`prompts`),A(t.skills,t.manifest,`skills`,x),A(t.flows,t.manifest,`flows`,C),A(t.commands,t.manifest,`commands`,T)}for(let e of O)console.log(` ${e}: scaffold updated (${S.size} skills)`);let j=new Set,M=r(`aikit`,n),N=i(`aikit`,n);for(let e of h.values()){let t=e.getScaffoldPaths().instructions;!t||j.has(t)||(d(_(t),{recursive:!0}),g(t,e.buildInstructionContent(M,N),`utf-8`),j.add(t))}j.size>0&&console.log(` Instruction files: ${[...j].join(`, `)}`)}function te(e){let t=[];for(let n of e){let e=n.getScaffoldRoot();if(e)if(Q.has(n.name)){let r=n.getInstructionsRoot()??e;t.push(b(r,`kb.instructions.md`)),t.push(b(r,`aikit.instructions.md`))}else n.name===`Cursor`||n.name===`Cursor Nightly`?t.push(b(e,`rules`,`kb.mdc`)):n.name===`Windsurf`&&t.push(b(e,`rules`,`kb.md`))}for(let e of t)u(e)&&(h(e),console.log(` Removed legacy file: ${e}`))}async function ne(e){let t=n,r=X(_(S(import.meta.url))),i=JSON.parse(f(b(r,`package.json`),`utf-8`)).version;console.log(`Initializing @vpxa/aikit v${i}...\n`);let a=O();d(a,{recursive:!0}),console.log(` Global data store: ${a}`),k({version:1,workspaces:{}}),console.log(` Created registry.json`);let o=await Y({scope:`user`});if(o.length===0)console.log(`
|
|
2
2
|
No supported IDEs detected. You can manually add the MCP server config.`);else{console.log(`\n Detected ${o.length} IDE(s):`);let n=Z();for(let e of o)try{await e.registerMcp(t,n),console.log(` ${e.name}: configured ${t}`)}catch(t){console.log(` ${e.name}: failed to configure (${t.message})`)}for(let t of o)$(t,e.force)}console.log(`
|
|
3
3
|
Installing scaffold files:`),await ee(r,o,t,i,e.force),te(o),console.log(`
|
|
4
4
|
User-level AI Kit installation complete!`),console.log(`
|
|
@@ -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-C5IU9Lau.js`),import(`./dashboard-static-BfIe0Si1.js`),import(`./settings-static-BosGZSPf.js`),import(`./routes-0OCkdgRe.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-
|
|
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-C5IU9Lau.js`),import(`./dashboard-static-BfIe0Si1.js`),import(`./settings-static-BosGZSPf.js`),import(`./routes-0OCkdgRe.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-DZ1V42_x.js`),import(`@modelcontextprotocol/sdk/server/streamableHttp.js`),import(`./version-check-AMfxaZUw.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.kb)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`);g=new e(s.kb.indexer,l,s.kb.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-C5IU9Lau.js`),import(`./server-DZ1V42_x.js`),import(`./version-check-AMfxaZUw.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.kb)throw Error(`AI Kit components are not available after initialization`);let{SmartIndexScheduler:e}=await import(`../../indexer/dist/index.js`),t=new e(f.kb.indexer,l,f.kb.store);t.start(),f.setSmartScheduler(t),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};
|
|
@@ -558,7 +558,7 @@ The output must:
|
|
|
558
558
|
|
|
559
559
|
Output ONLY the README.md content, nothing else.`;if(t.available)try{let i=(await t.createMessage({prompt:e,systemPrompt:s,context:o?`Step name: ${r}\nSource format: ${n}\nMetadata:\n${o}`:`Step name: ${r}\nSource format: ${n}`,maxTokens:4096,modelPreferences:{intelligencePriority:.8,speedPriority:.4,costPriority:.2}})).text.trim();if(i.length>0)return i}catch(e){G.debug(`Flow transform sampling failed; using fallback formatting`,{error:q(e),sourceFormat:n,stepName:r})}let c=typeof i?.description==`string`&&i.description.trim().length>0?i.description.trim():null,l=Wo(i?.produces),u=Wo(i?.requires);return[`# ${a}`,``,`## Purpose`,``,c??`${a} step.`,``,`## Instructions`,``,e.trim(),``,`## Artifacts`,``,...l.length>0?l.map(e=>`- ${e}`):[`- ${r}.md`],...u.length>0?[``,`## Prerequisites`,``,...u.map(e=>`- ${e}`)]:[],``].join(`
|
|
560
560
|
`).trimEnd().concat(`
|
|
561
|
-
`)}}function K(e){return{content:[{type:`text`,text:e}]}}function q(e){return e instanceof Error?e.message:String(e)}function Ko(e,t){function n(){return t.sources?.[0]?.path??process.cwd()}function r(){return t.allRoots?.length?t.allRoots:[n()]}function i(){return g(O(),`flows`,`registry.json`)}function d(e){return g(e??n(),`.flows`)}let m={before:[],after:[{id:`_docs-sync`,description:`Synchronize project documentation — update docs/ folder based on changes made during the flow.`,position:`after`,skills:[`docs`]}]};function h(e,t,r){let i=t?.installPath?p(t.installPath):e.replaceAll(`:`,`-`),o=_(Zt(),`.copilot`,`flows`,i).replaceAll(`\\`,`/`);if(a(o))return o;let s=_(Zt(),`.claude`,`flows`,i).replaceAll(`\\`,`/`);if(a(s))return s;let c=_(r??n(),`.github`,`flows`,i).replaceAll(`\\`,`/`);return a(c)?c:t?.installPath&&a(t.installPath)?t.installPath.replaceAll(`\\`,`/`):null}function v(e,t,n){let r=h(e.name,e,n);return r?_(r,t).replaceAll(`\\`,`/`):t}function y(e,t){let r=e.replace(/^_/,``),i=t??n(),o=[g(i,`.github`,`flows`,`_epilogue`,`steps`,r,`README.md`),g(i,`.github`,`flows`,`_epilogue`,r,`README.md`)];for(let e of o)if(a(e))return e.replaceAll(`\\`,`/`);return null}function b(e){return[...m.before.map(e=>e.id),...e.manifest.steps.map(e=>e.id),...m.after.map(e=>e.id)]}function x(e,t,n){let r=t?e.manifest.steps.find(e=>e.id===t)??null:null,i=!r&&t?[...m.before,...m.after].find(e=>e.id===t)??null:null;return{currentStep:r,epilogueStep:i,instructionPath:r&&t?v(e,r.instruction,n):null,description:r?.description??i?.description??null}}function S(){try{let e=g(kn(`npm root -g`,{encoding:`utf-8`}).trim(),`@fission-ai`,`openspec`);if(a(e))return{path:e,sourceType:`npm-global`,isGit:!1}}catch{}return{path:`https://github.com/Fission-AI/OpenSpec.git`,sourceType:`git`,isGit:!0}}function C(e){let t=_(e);if(a(g(t,`.claude-plugin`,`plugin.json`)))return{path:t,sourceType:`claude-plugin`};let n=Zt(),r=g(n,`.claude`,`plugins`,e);if(a(g(r,`.claude-plugin`,`plugin.json`)))return{path:r,sourceType:`claude-plugin`};let i=g(n,`.claude`,`plugins`);if(!a(i))return null;for(let t of c(i,{withFileTypes:!0})){if(!t.isDirectory())continue;let n=g(i,t.name,`.claude-plugin`,`plugin.json`);if(a(n))try{if(JSON.parse(s(n,`utf-8`)).name===e)return{path:g(i,t.name),sourceType:`claude-plugin`}}catch{}}return null}async function w(e){let{FlowRegistryManager:r,FlowStateMachine:a,FlowLoader:o,GitInstaller:s}=await import(`../../flows/dist/index.js`),c=g(t.stateDir??g(n(),`.aikit-state`),`flows`,`installed`);return{registry:new r(i()),stateMachine:new a(d(e),m),loader:new o,installer:new s(c)}}async function T(){let e=r();for(let t of e){let e=d(t);if(a(e))for(let n of c(e,{withFileTypes:!0})){if(!n.isDirectory())continue;let r=g(e,n.name,`meta.json`);if(a(r))try{let e=JSON.parse(s(r,`utf-8`));if(e.status===`active`)return e.primaryRoot?e.primaryRoot:t}catch{}}}return null}async function E(e){return e||(await T()??n())}function D(e,t,n){let r=g(d(t),e,`meta.json`),i=s(r,`utf-8`),a=JSON.parse(i);a.roots=n.map(e=>e.replaceAll(`\\`,`/`)),a.primaryRoot=t.replaceAll(`\\`,`/`),f(r,JSON.stringify(a,null,2),`utf-8`)}function k(e,t){let n=g(d(t),e,`meta.json`);if(!a(n))return;let r=s(n,`utf-8`),i=JSON.parse(r),c=i.roots;if(!c||c.length<=1)return;let l=t.replaceAll(`\\`,`/`);for(let t of c){if(t===l)continue;let n=g(t,`.flows`,e);o(n,{recursive:!0}),f(g(n,`meta.json`),r,`utf-8`),o(g(n,i.artifactsDir??`.spec`),{recursive:!0})}}let ee=L(`flow_list`);e.registerTool(`flow_list`,{title:ee.title,description:`List all installed flows and their steps`,annotations:ee.annotations,inputSchema:{}},async()=>{try{let{registry:e,stateMachine:t,installer:n}=await w(await E()),i=e.list(),a=t.getStatus(),o={flows:i.map(e=>{let t={name:e.name,version:e.version,source:e.source,sourceType:e.sourceType,format:e.format,steps:e.manifest.steps.map(e=>e.id)};if(e.sourceType===`git`&&e.commitSha){let r=n.hasUpdates(e.installPath);return{...t,commitSha:e.commitSha,updateAvailable:r.success&&r.data?r.data.hasUpdates:void 0}}return t}),activeFlow:a.success&&a.data?{flow:a.data.flow,status:a.data.status,currentStep:a.data.currentStep,slug:a.data.slug,topic:a.data.topic,runDir:a.data.runDir}:null,allRoots:r().map(e=>e.replaceAll(`\\`,`/`))};return K(JSON.stringify(o,null,2))}catch(e){return G.error(`flow_list failed`,A(e)),K(`Error: ${q(e)}`)}});let te=L(`flow_info`);e.registerTool(`flow_info`,{title:te.title,description:`Show detailed information about a specific flow`,annotations:te.annotations,inputSchema:{name:P.string().describe(`Flow name to get info for`)}},async({name:e})=>{try{let{registry:t,installer:n}=await w(),r=t.get(e);if(!r)return K(`Flow "${e}" not found. Use flow_list to see available flows.`);let i=r.commitSha??null,a;if(r.sourceType===`git`&&r.installPath){let e=n.hasUpdates(r.installPath);a=e.success&&e.data?e.data.hasUpdates:void 0}let o={name:r.name,version:r.version,description:r.manifest.description,source:r.source,sourceType:r.sourceType,format:r.format,commitSha:i,updateAvailable:a,installPath:h(r.name,r),registeredAt:r.registeredAt,updatedAt:r.updatedAt,steps:r.manifest.steps.map(e=>({id:e.id,name:e.name,instruction:v(r,e.instruction),produces:e.produces,requires:e.requires,description:e.description})),agents:r.manifest.agents,artifactsDir:r.manifest.artifacts_dir,install:r.manifest.install};return K(JSON.stringify(o,null,2))}catch(e){return G.error(`flow_info failed`,A(e)),K(`Error: ${q(e)}`)}});let j=L(`flow_start`);e.registerTool(`flow_start`,{title:j.title,description:`Start a flow. Sets the active flow and positions at the first step.`,annotations:j.annotations,inputSchema:{flow:P.string().describe(`Flow name to start (use flow_list to see options)`),topic:P.string().optional().describe(`Human-readable topic for the run (e.g. "Add authentication"). Used as directory name under .flows/.`),roots:P.array(P.string()).optional().describe(`Workspace roots participating in this flow. For multi-repo tasks, list all repos that need a .flows/<slug>/ directory. Flow state is synchronized across all listed roots. Omit for single-root workspaces (defaults to primary root).`)}},async({flow:e,topic:t,roots:i})=>{try{if(i&&i.length>0){let e=new Set(r().map(e=>e.replaceAll(`\\`,`/`))),t=i.filter(t=>!e.has(t.replaceAll(`\\`,`/`)));if(t.length>0)return K(`Invalid roots — not part of the workspace: ${t.join(`, `)}. Available roots: ${[...e].join(`, `)}`)}let a=i?.[0]??n(),{registry:o,stateMachine:s}=await w(a),c=o.get(e);if(!c)return K(`Flow "${e}" not found. Use flow_list to see available flows.`);let l=s.start(c.name,c.manifest,t);if(!l.success||!l.data)return K(`Cannot start: ${l.error}`);let u=l.data;if(i&&i.length>1)try{D(u.slug,a,i),k(u.slug,a)}catch(e){return s.reset(),K(`Flow created but failed to sync to secondary roots — rolled back. Error: ${e instanceof Error?e.message:String(e)}`)}let{instructionPath:d,description:f}=x(c,u.currentStep,a),p=b(c),m={started:!0,flow:u.flow,slug:u.slug,topic:u.topic,runDir:u.runDir,artifactsPath:g(u.runDir,c.manifest.artifacts_dir).replaceAll(`\\`,`/`),currentStep:u.currentStep,currentStepInstruction:d,currentStepDescription:f,phase:u.phase,isEpilogue:u.isEpilogue,totalSteps:p.length,stepSequence:p,artifactsDir:c.manifest.artifacts_dir,roots:i??[a.replaceAll(`\\`,`/`)]};return K(JSON.stringify(m,null,2))}catch(e){return G.error(`flow_start failed`,A(e)),K(`Error: ${q(e)}`)}});let ne=L(`flow_step`);e.registerTool(`flow_step`,{title:ne.title,description:`Advance the active flow: complete current step and move to next, skip current step, or redo current step.`,annotations:ne.annotations,inputSchema:{action:P.enum([`next`,`skip`,`redo`]).describe(`next: mark current step done and advance. skip: skip current step. redo: repeat current step.`)}},async({action:e})=>{try{let t=await E(),{registry:n,stateMachine:r}=await w(t),i=r.getStatus();if(!i.success||!i.data)return K(`No active flow. Use flow_start first.`);let a=n.get(i.data.flow);if(!a)return K(`Flow "${i.data.flow}" not found in registry.`);let o=r.step(e,a.manifest);if(!o.success||!o.data)return K(`Cannot ${e}: ${o.error}`);k(o.data.slug,t);let s=o.data,{instructionPath:c,description:l}=x(a,s.currentStep,t),u=b(a),d={flow:s.flow,status:s.status,action:e,slug:s.slug,topic:s.topic,runDir:s.runDir,artifactsPath:g(s.runDir,a.manifest.artifacts_dir).replaceAll(`\\`,`/`),currentStep:s.currentStep,currentStepInstruction:c,currentStepDescription:l,phase:s.phase,isEpilogue:s.isEpilogue,completedSteps:s.completedSteps,skippedSteps:s.skippedSteps,totalSteps:u.length,remaining:u.filter(e=>!s.completedSteps.includes(e)&&!s.skippedSteps.includes(e)&&e!==s.currentStep)};return K(JSON.stringify(d,null,2))}catch(e){return G.error(`flow_step failed`,A(e)),K(`Error: ${q(e)}`)}});let re=L(`flow_status`);e.registerTool(`flow_status`,{title:re.title,description:`Show the current flow execution state — which flow is active, current step, completed steps, and artifacts.`,annotations:re.annotations,inputSchema:{}},async()=>{try{let e=await E(),{registry:t,stateMachine:n}=await w(e),i=n.getStatus();if(!i.success||!i.data)return K(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let a=i.data,o=t.get(a.flow),s=o?x(o,a.currentStep,e):null,c=o?b(o):[],l=s?.instructionPath??null,u={flow:a.flow,status:a.status,slug:a.slug,topic:a.topic,runDir:a.runDir,artifactsPath:o?g(a.runDir,o.manifest.artifacts_dir).replaceAll(`\\`,`/`):null,currentStep:a.currentStep,currentStepInstruction:l,instructionPath:l,currentStepDescription:s?.description??null,phase:a.phase,isEpilogue:a.isEpilogue,completedSteps:a.completedSteps,skippedSteps:a.skippedSteps,artifacts:a.artifacts,startedAt:a.startedAt,updatedAt:a.updatedAt,totalSteps:c.length,progress:o?`${a.completedSteps.length+a.skippedSteps.length}/${c.length}`:`unknown`,workspaceRoot:e.replaceAll(`\\`,`/`),primaryRoot:(a.primaryRoot??e).replaceAll(`\\`,`/`),roots:a.roots??[e.replaceAll(`\\`,`/`)],allRoots:r().map(e=>e.replaceAll(`\\`,`/`))};return K(JSON.stringify(u,null,2))}catch(e){return G.error(`flow_status failed`,A(e)),K(`Error: ${q(e)}`)}});let M=L(`flow_read_instruction`);e.registerTool(`flow_read_instruction`,{title:M.title===`flow_read_instruction`?`Flow Read Instruction`:M.title,description:`Read the instruction content for a flow step. If step is omitted, reads the current step.`,annotations:M.title===`flow_read_instruction`?{readOnlyHint:!0,idempotentHint:!0}:M.annotations,inputSchema:{step:P.string().optional().describe(`Step id or name to read. Defaults to the current step.`)}},async({step:e})=>{try{let t=await E(),{registry:n,stateMachine:r}=await w(t),i=r.getStatus();if(!i.success||!i.data)return K(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let a=i.data,o=n.get(a.flow);if(!o)return K(`Flow "${a.flow}" not found in registry.`);let s=e??a.currentStep;if(!s)return K(`No current step is available for the active flow.`);let c=o.manifest.steps.find(e=>e.id===s||e.name===s);if(!c){let e=y(s,t);if(e){let n=await Yt(e,`utf-8`),r=g(a.runDir,o.manifest.artifacts_dir).replaceAll(`\\`,`/`),i=a.runDir.replaceAll(`\\`,`/`);return n=n.replaceAll(`{{artifacts_path}}`,r).replaceAll(`{{run_dir}}`,i).replaceAll(`{{workspace_root}}`,(a.primaryRoot??t).replaceAll(`\\`,`/`)).replaceAll(`{{all_roots}}`,JSON.stringify(a.roots??[t.replaceAll(`\\`,`/`)],null,2)),K(n)}return K(`Step "${s}" not found in flow "${a.flow}".`)}let l=await Yt(v(o,c.instruction,t),`utf-8`),u=g(a.runDir,o.manifest.artifacts_dir).replaceAll(`\\`,`/`),d=a.runDir.replaceAll(`\\`,`/`);l=l.replaceAll(`{{artifacts_path}}`,u).replaceAll(`{{run_dir}}`,d).replaceAll(`{{workspace_root}}`,(a.primaryRoot??t).replaceAll(`\\`,`/`)).replaceAll(`{{all_roots}}`,JSON.stringify(a.roots??[t.replaceAll(`\\`,`/`)],null,2));for(let e of[`spec-driven`])l=l.replaceAll(`${e}/${a.slug}/`,`${u}/`);return K(l)}catch(e){return G.error(`flow_read_instruction failed`,A(e)),e instanceof Error&&`code`in e&&e.code===`ENOENT`?K(`Could not read instruction file: ${e.message}`):K(`Error: ${q(e)}`)}});let ie=L(`flow_reset`);e.registerTool(`flow_reset`,{title:ie.title,description:`Reset the active flow, clearing all state. Use to start over or switch to a different flow.`,annotations:ie.annotations,inputSchema:{}},async()=>{try{let e=await E(),{stateMachine:t}=await w(e),n=t.getStatus(),r=t.reset();return r.success?(n.success&&n.data&&k(n.data.slug,e),K(`Flow abandoned. Use flow_start to begin a new flow.`)):K(`Reset failed: ${r.error}`)}catch(e){return G.error(`flow_reset failed`,A(e)),K(`Error: ${q(e)}`)}});let ae=L(`flow_runs`);e.registerTool(`flow_runs`,{title:ae.title===`flow_runs`?`Flow Runs`:ae.title,description:`List all flow runs (current and past). Shows topic, flow, status, and progress for each run under .flows/.`,annotations:{readOnlyHint:!0,idempotentHint:!0},inputSchema:{flow:P.string().optional().describe(`Filter by flow name`),status:P.string().optional().describe(`Filter by status (active, completed, abandoned)`)}},async({flow:e,status:t})=>{try{let n=r(),i=[];for(let r of n){let{stateMachine:n}=await w(r),a=n.listRuns({flow:e,status:t});for(let e of a)i.push({...JSON.parse(JSON.stringify(e)),root:r.replaceAll(`\\`,`/`)})}let a=new Set,o=i.filter(e=>{let t=e.id;return a.has(t)?!1:(a.add(t),!0)});return o.length===0?K(`No flow runs found.`):K(JSON.stringify(o,null,2))}catch(e){return G.error(`flow_runs failed`,A(e)),K(`Error: ${q(e)}`)}});let oe=L(`flow_add`);e.registerTool(`flow_add`,{title:oe.title,description:`Install a new development flow from a git repository URL or local directory path. Use when the user wants to add, install, import, or onboard a new workflow — for example: "use this as a flow", "add this flow", "add this flow URL", "install a flow", or "onboard a flow". Accepts git URLs (https://..., git@...) and local filesystem paths. Also accepts the shorthand "openspec" to install the OpenSpec flow (auto-detects local npm global install or clones from GitHub).`,annotations:oe.annotations,inputSchema:{source:P.string().describe(`Git repository URL (https://... or git@...) or absolute/local directory path containing a flow definition. Use "openspec" as a shorthand to auto-resolve the OpenSpec flow.`),name:P.string().optional().describe(`Optional override for the installed flow name. If omitted, the name comes from the flow manifest.`),token:P.string().optional().describe(`Authentication token for private/GHE repositories`)}},async({source:t,name:n,token:r})=>{try{let{registry:i,loader:a,installer:o}=await w(),s=Go(e),c=t===`openspec`||t.startsWith(`openspec:`),l,u=t,d;if(c){let e=S();u=e.path,l=e.sourceType}let f=c?null:C(u);f&&(u=f.path,l=f.sourceType);let m=/^https?:\/\/|^git@/.test(u),h;if(m){let e=o.clone(u,r);if(!e.success||!e.data)return K(`Failed to clone flow: ${e.error}`);h=e.data}else{let e=_(u);d=e;let t=n||p(e)||`custom-flow`,r=o.copyLocal(e,t);if(!r.success||!r.data)return K(`Failed to copy flow: ${r.error}`);h=r.data}let g=await a.load(h,{forceAssetSync:!0,transform:s});if(!g.success||!g.data)return o.remove(h),K(`Failed to load flow manifest: ${g.error}`);let{manifest:v,format:y}=g.data,b=n||v.name,x=l??(m?`git`:`local`);if(i.has(b))return o.remove(h),K(`Flow "${b}" is already installed. Use flow_update to update it, or flow_remove then flow_add to replace.`);if(v.install.length>0){let e=o.runInstallDeps(v.install);if(!e.success)return o.remove(h),K(`Dependency install failed: ${e.error}`)}let T=new Date().toISOString(),E=m?o.getLocalCommit(h):void 0,D=i.register({name:b,version:v.version,source:x===`local`||x===`claude-plugin`?d??t:t,sourceType:x,installPath:h,format:y,registeredAt:T,updatedAt:T,manifest:v,...E?{commitSha:E}:{}});if(!D.success)return o.remove(h),K(`Failed to register flow: ${D.error}`);let O=v.steps.length;return K(`Flow "${b}" installed successfully (${O} steps). Use flow_start({ flow: "${b}" }) to begin.`)}catch(e){return G.error(`flow_add failed`,A(e)),K(`Error: ${q(e)}`)}});let se=L(`flow_remove`);e.registerTool(`flow_remove`,{title:se.title,description:`Remove an installed flow by name. Unregisters it and deletes its files when applicable. Builtin flows cannot be removed.`,annotations:se.annotations,inputSchema:{name:P.string().describe(`Name of the flow to remove.`)}},async({name:e})=>{try{let{registry:t,installer:n}=await w();if(!t.has(e))return K(`Flow "${e}" is not installed.`);let r=t.get(e);if(!r)return K(`Flow "${e}" is not installed.`);if(r.sourceType===`builtin`)return K(`Cannot remove builtin flow "${e}".`);let i=n.remove(r.installPath);if(!i.success)return K(`Failed to remove flow files: ${i.error}`);let a=t.unregister(e);return a.success?K(`Flow "${e}" removed successfully.`):K(`Failed to unregister flow: ${a.error}`)}catch(e){return G.error(`flow_remove failed`,A(e)),K(`Error: ${q(e)}`)}});let ce=L(`flow_update`);e.registerTool(`flow_update`,{title:ce.title,description:`Update an installed flow to its latest version. For git-based flows, pulls the latest changes. For npm-global flows (e.g. OpenSpec), runs npm update.`,annotations:ce.annotations,inputSchema:{name:P.string().describe(`Name of the flow to update.`)}},async({name:t})=>{try{let{registry:n,loader:r,installer:i}=await w(),o=Go(e);if(!n.has(t))return K(`Flow "${t}" is not installed.`);let s=n.get(t);if(!s||s.sourceType!==`git`&&s.sourceType!==`npm-global`&&s.sourceType!==`local`&&s.sourceType!==`claude-plugin`)return K(`Flow "${t}" was not installed from git, npm, or a local source — cannot update. Remove and re-add instead.`);if(s.sourceType===`local`||s.sourceType===`claude-plugin`){let e=_(s.source);if(!a(e))return K(`Source path no longer exists: ${e}`);let t=`${s.installPath}.updating`,c=`${s.installPath}.backup`;a(t)&&u(t,{recursive:!0,force:!0}),a(c)&&u(c,{recursive:!0,force:!0});let d=i.copyLocal(e,p(t));if(!d.success||!d.data)return K(`Failed to copy flow: ${d.error}`);let f=await r.load(t,{forceAssetSync:!0,transform:o});if(!f.success||!f.data)return i.remove(t),K(`Failed to load flow manifest: ${f.error}`);let m=!1;try{l(s.installPath,c),l(t,s.installPath);let e=await r.load(s.installPath,{forceAssetSync:!0,transform:o});if(!e.success||!e.data)throw Error(`Failed to load flow manifest: ${e.error}`);let a=e.data.manifest,d=e.data.format,f=n.register({...s,version:a.version,format:d,installPath:s.installPath,manifest:a,updatedAt:new Date().toISOString()});if(!f.success)throw Error(`Failed to refresh flow registry entry: ${f.error}`);if(m=!0,a.install.length>0){let e=i.runInstallDeps(a.install);if(!e.success)throw Error(`Dependency install failed: ${e.error}`)}u(c,{recursive:!0,force:!0})}catch(e){return a(t)&&u(t,{recursive:!0,force:!0}),a(c)&&(a(s.installPath)&&u(s.installPath,{recursive:!0,force:!0}),l(c,s.installPath)),m&&n.register(s),K(q(e))}return K(`Flow "${s.name}" updated from ${s.sourceType} source successfully.`)}if(s.sourceType===`npm-global`){try{kn(`npm update -g @fission-ai/openspec`,{encoding:`utf-8`,stdio:`pipe`})}catch(e){return K(`npm update failed: ${q(e)}`)}let e=S(),i=await r.load(e.path,{forceAssetSync:!0,transform:o}),a=i.success&&i.data?i.data.manifest:null,c=i.success&&i.data?i.data.format:s.format;if(a){let t=n.register({...s,version:a.version,format:c,installPath:e.path,manifest:a,updatedAt:new Date().toISOString()});if(!t.success)return K(`Failed to refresh flow registry entry: ${t.error}`)}return K(`Flow "${t}" updated via npm successfully.`)}let c=i.update(s.installPath);if(!c.success)return K(`Update failed: ${c.error}`);let d=await r.load(s.installPath,{forceAssetSync:!0,transform:o}),f=d.success&&d.data?d.data.manifest:null,m=d.success&&d.data?d.data.format:s.format;if(f){let e=i.getLocalCommit(s.installPath),t=n.register({...s,version:f.version,format:m,manifest:f,updatedAt:new Date().toISOString(),...e?{commitSha:e}:{}});if(!t.success)return K(`Failed to refresh flow registry entry: ${t.error}`)}let h=f?.install??s.manifest.install;if(h.length>0){let e=i.runInstallDeps(h);if(!e.success)return K(`Dependency install failed: ${e.error}`)}return K(`Flow "${t}" updated successfully.`)}catch(e){return G.error(`flow_update failed`,A(e)),K(`Error: ${q(e)}`)}})}const qo=D(`tools`);function Jo(e){let t=L(`evidence_map`);e.registerTool(`evidence_map`,{title:t.title,description:`Track verified/assumed/unresolved claims for complex tasks. Gate readiness: YIELD (proceed), HOLD (unknowns), HARD_BLOCK (critical gaps). Persists across calls.`,inputSchema:{action:P.enum([`create`,`add`,`update`,`get`,`gate`,`list`,`delete`]).describe(`Operation to perform`),task_id:P.string().optional().describe(`Task identifier (required for all except list)`),tier:P.enum([`floor`,`standard`,`critical`]).optional().describe(`FORGE tier (required for create)`),claim:P.string().optional().describe(`Critical-path claim text (for add)`),status:P.enum([`V`,`A`,`U`]).optional().describe(`Evidence status: V=Verified, A=Assumed, U=Unresolved`),receipt:P.string().optional().describe(`Evidence receipt: tool→ref for V, reasoning for A, attempts for U`),id:P.number().optional().describe(`Entry ID (for update)`),critical_path:P.boolean().default(!0).describe(`Whether this claim is on the critical path`),unknown_type:P.enum([`contract`,`convention`,`freshness`,`runtime`,`data-flow`,`impact`]).optional().describe(`Typed unknown classification`),safety_gate:P.enum([`provenance`,`commitment`,`coverage`]).optional().describe(`Safety gate tag: provenance (claim→evidence), commitment (user-approved), coverage (nothing dropped)`),retry_count:P.number().default(0).describe(`Retry count for gate evaluation (0 = first attempt)`),max_retries:P.number().int().min(0).optional().describe(`Maximum retries before escalating. Default: 3`),timeout_action:P.enum([`iterate`,`retry`,`manual`,`terminate`]).optional().describe(`Action to take when gate retries are exhausted. Default: manual`),cwd:P.string().optional().describe(`Working directory for evidence map storage (default: server cwd). Use root_path from forge_ground to match.`)},annotations:t.annotations},async({action:e,task_id:t,tier:n,claim:r,status:i,receipt:a,id:o,critical_path:s,unknown_type:c,safety_gate:l,retry_count:u,max_retries:d,timeout_action:f,cwd:p})=>{try{switch(e){case`create`:if(!t)throw Error(`task_id required for create`);if(!n)throw Error(`tier required for create`);return Ae({action:`create`,taskId:t,tier:n},p),{content:[{type:`text`,text:`Created evidence map "${t}" (tier: ${n}).\n\n---\n_Next: Use \`evidence_map\` with action "add" to record critical-path claims._`}]};case`add`:{if(!t)throw Error(`task_id required for add`);if(!r)throw Error(`claim required for add`);if(!i)throw Error(`status required for add`);let e=Ae({action:`add`,taskId:t,claim:r,status:i,receipt:a??``,criticalPath:s,unknownType:c,safetyGate:l},p),n=[`Added entry #${e.entry?.id} to "${t}": [${i}] ${r}`];return e.formattedMap&&n.push(``,e.formattedMap),{content:[{type:`text`,text:n.join(`
|
|
561
|
+
`)}}function K(e){return{content:[{type:`text`,text:e}]}}function q(e){return e instanceof Error?e.message:String(e)}function Ko(e,t){function n(){return t.sources?.[0]?.path??process.cwd()}function r(e){let t=[];try{let n=c(e,{withFileTypes:!0});for(let r of n){if(!r.isDirectory()||r.name.startsWith(`.`))continue;let n=g(e,r.name);a(g(n,`.git`))&&t.push(n)}}catch{}return t}function i(){let e=t.allRoots?.length?t.allRoots:[n()],i=new Set(e);for(let t of e)for(let e of r(t))i.add(e);return[...i]}function d(e){let r=e.replaceAll(`\\`,`/`);if(i().map(e=>e.replaceAll(`\\`,`/`)).includes(r))return!0;let o=(t.allRoots?.length?t.allRoots:[n()]).map(e=>e.replaceAll(`\\`,`/`));for(let t of o)if(r.startsWith(`${t}/`)&&a(g(e,`.git`)))return!0;return!1}function m(){return g(O(),`flows`,`registry.json`)}function h(e){return g(e??n(),`.flows`)}let v={before:[],after:[{id:`_docs-sync`,description:`Synchronize project documentation — update docs/ folder based on changes made during the flow.`,position:`after`,skills:[`docs`]}]};function y(e,t,r){let i=t?.installPath?p(t.installPath):e.replaceAll(`:`,`-`),o=_(Zt(),`.copilot`,`flows`,i).replaceAll(`\\`,`/`);if(a(o))return o;let s=_(Zt(),`.claude`,`flows`,i).replaceAll(`\\`,`/`);if(a(s))return s;let c=_(r??n(),`.github`,`flows`,i).replaceAll(`\\`,`/`);return a(c)?c:t?.installPath&&a(t.installPath)?t.installPath.replaceAll(`\\`,`/`):null}function b(e,t,n){let r=y(e.name,e,n);return r?_(r,t).replaceAll(`\\`,`/`):t}function x(e,t){let r=e.replace(/^_/,``),i=t??n(),o=[g(i,`.github`,`flows`,`_epilogue`,`steps`,r,`README.md`),g(i,`.github`,`flows`,`_epilogue`,r,`README.md`)];for(let e of o)if(a(e))return e.replaceAll(`\\`,`/`);return null}function S(e){return[...v.before.map(e=>e.id),...e.manifest.steps.map(e=>e.id),...v.after.map(e=>e.id)]}function C(e,t,n){let r=t?e.manifest.steps.find(e=>e.id===t)??null:null,i=!r&&t?[...v.before,...v.after].find(e=>e.id===t)??null:null;return{currentStep:r,epilogueStep:i,instructionPath:r&&t?b(e,r.instruction,n):null,description:r?.description??i?.description??null}}function w(){try{let e=g(kn(`npm root -g`,{encoding:`utf-8`}).trim(),`@fission-ai`,`openspec`);if(a(e))return{path:e,sourceType:`npm-global`,isGit:!1}}catch{}return{path:`https://github.com/Fission-AI/OpenSpec.git`,sourceType:`git`,isGit:!0}}function T(e){let t=_(e);if(a(g(t,`.claude-plugin`,`plugin.json`)))return{path:t,sourceType:`claude-plugin`};let n=Zt(),r=g(n,`.claude`,`plugins`,e);if(a(g(r,`.claude-plugin`,`plugin.json`)))return{path:r,sourceType:`claude-plugin`};let i=g(n,`.claude`,`plugins`);if(!a(i))return null;for(let t of c(i,{withFileTypes:!0})){if(!t.isDirectory())continue;let n=g(i,t.name,`.claude-plugin`,`plugin.json`);if(a(n))try{if(JSON.parse(s(n,`utf-8`)).name===e)return{path:g(i,t.name),sourceType:`claude-plugin`}}catch{}}return null}async function E(e){let{FlowRegistryManager:r,FlowStateMachine:i,FlowLoader:a,GitInstaller:o}=await import(`../../flows/dist/index.js`),s=g(t.stateDir??g(n(),`.aikit-state`),`flows`,`installed`);return{registry:new r(m()),stateMachine:new i(h(e),v),loader:new a,installer:new o(s)}}async function D(){let e=i();for(let t of e){let e=h(t);if(a(e))for(let n of c(e,{withFileTypes:!0})){if(!n.isDirectory())continue;let r=g(e,n.name,`meta.json`);if(a(r))try{let e=JSON.parse(s(r,`utf-8`));if(e.status===`active`)return e.primaryRoot?e.primaryRoot:t}catch{}}}return null}async function k(e){return e||(await D()??n())}function ee(e,t,n){let r=g(h(t),e,`meta.json`),i=s(r,`utf-8`),a=JSON.parse(i);a.roots=n.map(e=>e.replaceAll(`\\`,`/`)),a.primaryRoot=t.replaceAll(`\\`,`/`),f(r,JSON.stringify(a,null,2),`utf-8`)}function te(e,t){let n=g(h(t),e,`meta.json`);if(!a(n))return;let r=s(n,`utf-8`),i=JSON.parse(r),c=i.roots;if(!c||c.length<=1)return;let l=t.replaceAll(`\\`,`/`);for(let t of c){if(t===l)continue;let n=g(t,`.flows`,e);o(n,{recursive:!0}),f(g(n,`meta.json`),r,`utf-8`),o(g(n,i.artifactsDir??`.spec`),{recursive:!0})}}let j=L(`flow_list`);e.registerTool(`flow_list`,{title:j.title,description:`List all installed flows and their steps`,annotations:j.annotations,inputSchema:{}},async()=>{try{let{registry:e,stateMachine:r,installer:a}=await E(await k()),o=e.list(),s=r.getStatus(),c={flows:o.map(e=>{let t={name:e.name,version:e.version,source:e.source,sourceType:e.sourceType,format:e.format,steps:e.manifest.steps.map(e=>e.id)};if(e.sourceType===`git`&&e.commitSha){let n=a.hasUpdates(e.installPath);return{...t,commitSha:e.commitSha,updateAvailable:n.success&&n.data?n.data.hasUpdates:void 0}}return t}),activeFlow:s.success&&s.data?{flow:s.data.flow,status:s.data.status,currentStep:s.data.currentStep,slug:s.data.slug,topic:s.data.topic,runDir:s.data.runDir}:null,allRoots:i().map(e=>e.replaceAll(`\\`,`/`)),discoveredRepos:(()=>{let e=(t.allRoots?.length?t.allRoots:[n()]).map(e=>e.replaceAll(`\\`,`/`)),r=i().map(e=>e.replaceAll(`\\`,`/`)).filter(t=>!e.includes(t));return r.length>0?r:void 0})()};return K(JSON.stringify(c,null,2))}catch(e){return G.error(`flow_list failed`,A(e)),K(`Error: ${q(e)}`)}});let ne=L(`flow_info`);e.registerTool(`flow_info`,{title:ne.title,description:`Show detailed information about a specific flow`,annotations:ne.annotations,inputSchema:{name:P.string().describe(`Flow name to get info for`)}},async({name:e})=>{try{let{registry:t,installer:n}=await E(),r=t.get(e);if(!r)return K(`Flow "${e}" not found. Use flow_list to see available flows.`);let i=r.commitSha??null,a;if(r.sourceType===`git`&&r.installPath){let e=n.hasUpdates(r.installPath);a=e.success&&e.data?e.data.hasUpdates:void 0}let o={name:r.name,version:r.version,description:r.manifest.description,source:r.source,sourceType:r.sourceType,format:r.format,commitSha:i,updateAvailable:a,installPath:y(r.name,r),registeredAt:r.registeredAt,updatedAt:r.updatedAt,steps:r.manifest.steps.map(e=>({id:e.id,name:e.name,instruction:b(r,e.instruction),produces:e.produces,requires:e.requires,description:e.description})),agents:r.manifest.agents,artifactsDir:r.manifest.artifacts_dir,install:r.manifest.install};return K(JSON.stringify(o,null,2))}catch(e){return G.error(`flow_info failed`,A(e)),K(`Error: ${q(e)}`)}});let re=L(`flow_start`);e.registerTool(`flow_start`,{title:re.title,description:`Start a flow. Sets the active flow and positions at the first step.`,annotations:re.annotations,inputSchema:{flow:P.string().describe(`Flow name to start (use flow_list to see options)`),topic:P.string().optional().describe(`Human-readable topic for the run (e.g. "Add authentication"). Used as directory name under .flows/.`),roots:P.array(P.string()).optional().describe(`Workspace roots participating in this flow. For multi-repo tasks, list all repos that need a .flows/<slug>/ directory. Flow state is synchronized across all listed roots. Omit for single-root workspaces (defaults to primary root).`)}},async({flow:e,topic:t,roots:r})=>{try{if(r&&r.length>0){let e=r.filter(e=>!d(e));if(e.length>0)return K(`Invalid roots — not part of the workspace or a recognized sub-repository: ${e.join(`, `)}. Available roots: ${i().map(e=>e.replaceAll(`\\`,`/`)).join(`, `)}`)}let a=r?.[0]??n(),{registry:o,stateMachine:s}=await E(a),c=o.get(e);if(!c)return K(`Flow "${e}" not found. Use flow_list to see available flows.`);let l=s.start(c.name,c.manifest,t);if(!l.success||!l.data)return K(`Cannot start: ${l.error}`);let u=l.data;if(r&&r.length>1)try{ee(u.slug,a,r),te(u.slug,a)}catch(e){return s.reset(),K(`Flow created but failed to sync to secondary roots — rolled back. Error: ${e instanceof Error?e.message:String(e)}`)}let{instructionPath:f,description:p}=C(c,u.currentStep,a),m=S(c),h={started:!0,flow:u.flow,slug:u.slug,topic:u.topic,runDir:u.runDir,artifactsPath:g(u.runDir,c.manifest.artifacts_dir).replaceAll(`\\`,`/`),currentStep:u.currentStep,currentStepInstruction:f,currentStepDescription:p,phase:u.phase,isEpilogue:u.isEpilogue,totalSteps:m.length,stepSequence:m,artifactsDir:c.manifest.artifacts_dir,roots:r??[a.replaceAll(`\\`,`/`)]};return K(JSON.stringify(h,null,2))}catch(e){return G.error(`flow_start failed`,A(e)),K(`Error: ${q(e)}`)}});let M=L(`flow_step`);e.registerTool(`flow_step`,{title:M.title,description:`Advance the active flow: complete current step and move to next, skip current step, or redo current step.`,annotations:M.annotations,inputSchema:{action:P.enum([`next`,`skip`,`redo`]).describe(`next: mark current step done and advance. skip: skip current step. redo: repeat current step.`)}},async({action:e})=>{try{let t=await k(),{registry:n,stateMachine:r}=await E(t),i=r.getStatus();if(!i.success||!i.data)return K(`No active flow. Use flow_start first.`);let a=n.get(i.data.flow);if(!a)return K(`Flow "${i.data.flow}" not found in registry.`);let o=r.step(e,a.manifest);if(!o.success||!o.data)return K(`Cannot ${e}: ${o.error}`);te(o.data.slug,t);let s=o.data,{instructionPath:c,description:l}=C(a,s.currentStep,t),u=S(a),d={flow:s.flow,status:s.status,action:e,slug:s.slug,topic:s.topic,runDir:s.runDir,artifactsPath:g(s.runDir,a.manifest.artifacts_dir).replaceAll(`\\`,`/`),currentStep:s.currentStep,currentStepInstruction:c,currentStepDescription:l,phase:s.phase,isEpilogue:s.isEpilogue,completedSteps:s.completedSteps,skippedSteps:s.skippedSteps,totalSteps:u.length,remaining:u.filter(e=>!s.completedSteps.includes(e)&&!s.skippedSteps.includes(e)&&e!==s.currentStep)};return K(JSON.stringify(d,null,2))}catch(e){return G.error(`flow_step failed`,A(e)),K(`Error: ${q(e)}`)}});let ie=L(`flow_status`);e.registerTool(`flow_status`,{title:ie.title,description:`Show the current flow execution state — which flow is active, current step, completed steps, and artifacts.`,annotations:ie.annotations,inputSchema:{}},async()=>{try{let e=await k(),{registry:r,stateMachine:a}=await E(e),o=a.getStatus();if(!o.success||!o.data)return K(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let s=o.data,c=r.get(s.flow),l=c?C(c,s.currentStep,e):null,u=c?S(c):[],d=l?.instructionPath??null,f={flow:s.flow,status:s.status,slug:s.slug,topic:s.topic,runDir:s.runDir,artifactsPath:c?g(s.runDir,c.manifest.artifacts_dir).replaceAll(`\\`,`/`):null,currentStep:s.currentStep,currentStepInstruction:d,instructionPath:d,currentStepDescription:l?.description??null,phase:s.phase,isEpilogue:s.isEpilogue,completedSteps:s.completedSteps,skippedSteps:s.skippedSteps,artifacts:s.artifacts,startedAt:s.startedAt,updatedAt:s.updatedAt,totalSteps:u.length,progress:c?`${s.completedSteps.length+s.skippedSteps.length}/${u.length}`:`unknown`,workspaceRoot:e.replaceAll(`\\`,`/`),primaryRoot:(s.primaryRoot??e).replaceAll(`\\`,`/`),roots:s.roots??[e.replaceAll(`\\`,`/`)],allRoots:i().map(e=>e.replaceAll(`\\`,`/`)),discoveredRepos:(()=>{let e=(t.allRoots?.length?t.allRoots:[n()]).map(e=>e.replaceAll(`\\`,`/`)),r=i().map(e=>e.replaceAll(`\\`,`/`)).filter(t=>!e.includes(t));return r.length>0?r:void 0})()};return K(JSON.stringify(f,null,2))}catch(e){return G.error(`flow_status failed`,A(e)),K(`Error: ${q(e)}`)}});let ae=L(`flow_read_instruction`);e.registerTool(`flow_read_instruction`,{title:ae.title===`flow_read_instruction`?`Flow Read Instruction`:ae.title,description:`Read the instruction content for a flow step. If step is omitted, reads the current step.`,annotations:ae.title===`flow_read_instruction`?{readOnlyHint:!0,idempotentHint:!0}:ae.annotations,inputSchema:{step:P.string().optional().describe(`Step id or name to read. Defaults to the current step.`)}},async({step:e})=>{try{let t=await k(),{registry:n,stateMachine:r}=await E(t),i=r.getStatus();if(!i.success||!i.data)return K(`No active flow. Use flow_start to begin one, or flow_list to see available flows.`);let a=i.data,o=n.get(a.flow);if(!o)return K(`Flow "${a.flow}" not found in registry.`);let s=e??a.currentStep;if(!s)return K(`No current step is available for the active flow.`);let c=o.manifest.steps.find(e=>e.id===s||e.name===s);if(!c){let e=x(s,t);if(e){let n=await Yt(e,`utf-8`),r=g(a.runDir,o.manifest.artifacts_dir).replaceAll(`\\`,`/`),i=a.runDir.replaceAll(`\\`,`/`);return n=n.replaceAll(`{{artifacts_path}}`,r).replaceAll(`{{run_dir}}`,i).replaceAll(`{{workspace_root}}`,(a.primaryRoot??t).replaceAll(`\\`,`/`)).replaceAll(`{{all_roots}}`,JSON.stringify(a.roots??[t.replaceAll(`\\`,`/`)],null,2)),K(n)}return K(`Step "${s}" not found in flow "${a.flow}".`)}let l=await Yt(b(o,c.instruction,t),`utf-8`),u=g(a.runDir,o.manifest.artifacts_dir).replaceAll(`\\`,`/`),d=a.runDir.replaceAll(`\\`,`/`);l=l.replaceAll(`{{artifacts_path}}`,u).replaceAll(`{{run_dir}}`,d).replaceAll(`{{workspace_root}}`,(a.primaryRoot??t).replaceAll(`\\`,`/`)).replaceAll(`{{all_roots}}`,JSON.stringify(a.roots??[t.replaceAll(`\\`,`/`)],null,2));for(let e of[`spec-driven`])l=l.replaceAll(`${e}/${a.slug}/`,`${u}/`);return K(l)}catch(e){return G.error(`flow_read_instruction failed`,A(e)),e instanceof Error&&`code`in e&&e.code===`ENOENT`?K(`Could not read instruction file: ${e.message}`):K(`Error: ${q(e)}`)}});let oe=L(`flow_reset`);e.registerTool(`flow_reset`,{title:oe.title,description:`Reset the active flow, clearing all state. Use to start over or switch to a different flow.`,annotations:oe.annotations,inputSchema:{}},async()=>{try{let e=await k(),{stateMachine:t}=await E(e),n=t.getStatus(),r=t.reset();return r.success?(n.success&&n.data&&te(n.data.slug,e),K(`Flow abandoned. Use flow_start to begin a new flow.`)):K(`Reset failed: ${r.error}`)}catch(e){return G.error(`flow_reset failed`,A(e)),K(`Error: ${q(e)}`)}});let se=L(`flow_runs`);e.registerTool(`flow_runs`,{title:se.title===`flow_runs`?`Flow Runs`:se.title,description:`List all flow runs (current and past). Shows topic, flow, status, and progress for each run under .flows/.`,annotations:{readOnlyHint:!0,idempotentHint:!0},inputSchema:{flow:P.string().optional().describe(`Filter by flow name`),status:P.string().optional().describe(`Filter by status (active, completed, abandoned)`)}},async({flow:e,status:t})=>{try{let n=i(),r=[];for(let i of n){let{stateMachine:n}=await E(i),a=n.listRuns({flow:e,status:t});for(let e of a)r.push({...JSON.parse(JSON.stringify(e)),root:i.replaceAll(`\\`,`/`)})}let a=new Set,o=r.filter(e=>{let t=e.id;return a.has(t)?!1:(a.add(t),!0)});return o.length===0?K(`No flow runs found.`):K(JSON.stringify(o,null,2))}catch(e){return G.error(`flow_runs failed`,A(e)),K(`Error: ${q(e)}`)}});let ce=L(`flow_add`);e.registerTool(`flow_add`,{title:ce.title,description:`Install a new development flow from a git repository URL or local directory path. Use when the user wants to add, install, import, or onboard a new workflow — for example: "use this as a flow", "add this flow", "add this flow URL", "install a flow", or "onboard a flow". Accepts git URLs (https://..., git@...) and local filesystem paths. Also accepts the shorthand "openspec" to install the OpenSpec flow (auto-detects local npm global install or clones from GitHub).`,annotations:ce.annotations,inputSchema:{source:P.string().describe(`Git repository URL (https://... or git@...) or absolute/local directory path containing a flow definition. Use "openspec" as a shorthand to auto-resolve the OpenSpec flow.`),name:P.string().optional().describe(`Optional override for the installed flow name. If omitted, the name comes from the flow manifest.`),token:P.string().optional().describe(`Authentication token for private/GHE repositories`)}},async({source:t,name:n,token:r})=>{try{let{registry:i,loader:a,installer:o}=await E(),s=Go(e),c=t===`openspec`||t.startsWith(`openspec:`),l,u=t,d;if(c){let e=w();u=e.path,l=e.sourceType}let f=c?null:T(u);f&&(u=f.path,l=f.sourceType);let m=/^https?:\/\/|^git@/.test(u),h;if(m){let e=o.clone(u,r);if(!e.success||!e.data)return K(`Failed to clone flow: ${e.error}`);h=e.data}else{let e=_(u);d=e;let t=n||p(e)||`custom-flow`,r=o.copyLocal(e,t);if(!r.success||!r.data)return K(`Failed to copy flow: ${r.error}`);h=r.data}let g=await a.load(h,{forceAssetSync:!0,transform:s});if(!g.success||!g.data)return o.remove(h),K(`Failed to load flow manifest: ${g.error}`);let{manifest:v,format:y}=g.data,b=n||v.name,x=l??(m?`git`:`local`);if(i.has(b))return o.remove(h),K(`Flow "${b}" is already installed. Use flow_update to update it, or flow_remove then flow_add to replace.`);if(v.install.length>0){let e=o.runInstallDeps(v.install);if(!e.success)return o.remove(h),K(`Dependency install failed: ${e.error}`)}let S=new Date().toISOString(),C=m?o.getLocalCommit(h):void 0,D=i.register({name:b,version:v.version,source:x===`local`||x===`claude-plugin`?d??t:t,sourceType:x,installPath:h,format:y,registeredAt:S,updatedAt:S,manifest:v,...C?{commitSha:C}:{}});if(!D.success)return o.remove(h),K(`Failed to register flow: ${D.error}`);let O=v.steps.length;return K(`Flow "${b}" installed successfully (${O} steps). Use flow_start({ flow: "${b}" }) to begin.`)}catch(e){return G.error(`flow_add failed`,A(e)),K(`Error: ${q(e)}`)}});let le=L(`flow_remove`);e.registerTool(`flow_remove`,{title:le.title,description:`Remove an installed flow by name. Unregisters it and deletes its files when applicable. Builtin flows cannot be removed.`,annotations:le.annotations,inputSchema:{name:P.string().describe(`Name of the flow to remove.`)}},async({name:e})=>{try{let{registry:t,installer:n}=await E();if(!t.has(e))return K(`Flow "${e}" is not installed.`);let r=t.get(e);if(!r)return K(`Flow "${e}" is not installed.`);if(r.sourceType===`builtin`)return K(`Cannot remove builtin flow "${e}".`);let i=n.remove(r.installPath);if(!i.success)return K(`Failed to remove flow files: ${i.error}`);let a=t.unregister(e);return a.success?K(`Flow "${e}" removed successfully.`):K(`Failed to unregister flow: ${a.error}`)}catch(e){return G.error(`flow_remove failed`,A(e)),K(`Error: ${q(e)}`)}});let ue=L(`flow_update`);e.registerTool(`flow_update`,{title:ue.title,description:`Update an installed flow to its latest version. For git-based flows, pulls the latest changes. For npm-global flows (e.g. OpenSpec), runs npm update.`,annotations:ue.annotations,inputSchema:{name:P.string().describe(`Name of the flow to update.`)}},async({name:t})=>{try{let{registry:n,loader:r,installer:i}=await E(),o=Go(e);if(!n.has(t))return K(`Flow "${t}" is not installed.`);let s=n.get(t);if(!s||s.sourceType!==`git`&&s.sourceType!==`npm-global`&&s.sourceType!==`local`&&s.sourceType!==`claude-plugin`)return K(`Flow "${t}" was not installed from git, npm, or a local source — cannot update. Remove and re-add instead.`);if(s.sourceType===`local`||s.sourceType===`claude-plugin`){let e=_(s.source);if(!a(e))return K(`Source path no longer exists: ${e}`);let t=`${s.installPath}.updating`,c=`${s.installPath}.backup`;a(t)&&u(t,{recursive:!0,force:!0}),a(c)&&u(c,{recursive:!0,force:!0});let d=i.copyLocal(e,p(t));if(!d.success||!d.data)return K(`Failed to copy flow: ${d.error}`);let f=await r.load(t,{forceAssetSync:!0,transform:o});if(!f.success||!f.data)return i.remove(t),K(`Failed to load flow manifest: ${f.error}`);let m=!1;try{l(s.installPath,c),l(t,s.installPath);let e=await r.load(s.installPath,{forceAssetSync:!0,transform:o});if(!e.success||!e.data)throw Error(`Failed to load flow manifest: ${e.error}`);let a=e.data.manifest,d=e.data.format,f=n.register({...s,version:a.version,format:d,installPath:s.installPath,manifest:a,updatedAt:new Date().toISOString()});if(!f.success)throw Error(`Failed to refresh flow registry entry: ${f.error}`);if(m=!0,a.install.length>0){let e=i.runInstallDeps(a.install);if(!e.success)throw Error(`Dependency install failed: ${e.error}`)}u(c,{recursive:!0,force:!0})}catch(e){return a(t)&&u(t,{recursive:!0,force:!0}),a(c)&&(a(s.installPath)&&u(s.installPath,{recursive:!0,force:!0}),l(c,s.installPath)),m&&n.register(s),K(q(e))}return K(`Flow "${s.name}" updated from ${s.sourceType} source successfully.`)}if(s.sourceType===`npm-global`){try{kn(`npm update -g @fission-ai/openspec`,{encoding:`utf-8`,stdio:`pipe`})}catch(e){return K(`npm update failed: ${q(e)}`)}let e=w(),i=await r.load(e.path,{forceAssetSync:!0,transform:o}),a=i.success&&i.data?i.data.manifest:null,c=i.success&&i.data?i.data.format:s.format;if(a){let t=n.register({...s,version:a.version,format:c,installPath:e.path,manifest:a,updatedAt:new Date().toISOString()});if(!t.success)return K(`Failed to refresh flow registry entry: ${t.error}`)}return K(`Flow "${t}" updated via npm successfully.`)}let c=i.update(s.installPath);if(!c.success)return K(`Update failed: ${c.error}`);let d=await r.load(s.installPath,{forceAssetSync:!0,transform:o}),f=d.success&&d.data?d.data.manifest:null,m=d.success&&d.data?d.data.format:s.format;if(f){let e=i.getLocalCommit(s.installPath),t=n.register({...s,version:f.version,format:m,manifest:f,updatedAt:new Date().toISOString(),...e?{commitSha:e}:{}});if(!t.success)return K(`Failed to refresh flow registry entry: ${t.error}`)}let h=f?.install??s.manifest.install;if(h.length>0){let e=i.runInstallDeps(h);if(!e.success)return K(`Dependency install failed: ${e.error}`)}return K(`Flow "${t}" updated successfully.`)}catch(e){return G.error(`flow_update failed`,A(e)),K(`Error: ${q(e)}`)}})}const qo=D(`tools`);function Jo(e){let t=L(`evidence_map`);e.registerTool(`evidence_map`,{title:t.title,description:`Track verified/assumed/unresolved claims for complex tasks. Gate readiness: YIELD (proceed), HOLD (unknowns), HARD_BLOCK (critical gaps). Persists across calls.`,inputSchema:{action:P.enum([`create`,`add`,`update`,`get`,`gate`,`list`,`delete`]).describe(`Operation to perform`),task_id:P.string().optional().describe(`Task identifier (required for all except list)`),tier:P.enum([`floor`,`standard`,`critical`]).optional().describe(`FORGE tier (required for create)`),claim:P.string().optional().describe(`Critical-path claim text (for add)`),status:P.enum([`V`,`A`,`U`]).optional().describe(`Evidence status: V=Verified, A=Assumed, U=Unresolved`),receipt:P.string().optional().describe(`Evidence receipt: tool→ref for V, reasoning for A, attempts for U`),id:P.number().optional().describe(`Entry ID (for update)`),critical_path:P.boolean().default(!0).describe(`Whether this claim is on the critical path`),unknown_type:P.enum([`contract`,`convention`,`freshness`,`runtime`,`data-flow`,`impact`]).optional().describe(`Typed unknown classification`),safety_gate:P.enum([`provenance`,`commitment`,`coverage`]).optional().describe(`Safety gate tag: provenance (claim→evidence), commitment (user-approved), coverage (nothing dropped)`),retry_count:P.number().default(0).describe(`Retry count for gate evaluation (0 = first attempt)`),max_retries:P.number().int().min(0).optional().describe(`Maximum retries before escalating. Default: 3`),timeout_action:P.enum([`iterate`,`retry`,`manual`,`terminate`]).optional().describe(`Action to take when gate retries are exhausted. Default: manual`),cwd:P.string().optional().describe(`Working directory for evidence map storage (default: server cwd). Use root_path from forge_ground to match.`)},annotations:t.annotations},async({action:e,task_id:t,tier:n,claim:r,status:i,receipt:a,id:o,critical_path:s,unknown_type:c,safety_gate:l,retry_count:u,max_retries:d,timeout_action:f,cwd:p})=>{try{switch(e){case`create`:if(!t)throw Error(`task_id required for create`);if(!n)throw Error(`tier required for create`);return Ae({action:`create`,taskId:t,tier:n},p),{content:[{type:`text`,text:`Created evidence map "${t}" (tier: ${n}).\n\n---\n_Next: Use \`evidence_map\` with action "add" to record critical-path claims._`}]};case`add`:{if(!t)throw Error(`task_id required for add`);if(!r)throw Error(`claim required for add`);if(!i)throw Error(`status required for add`);let e=Ae({action:`add`,taskId:t,claim:r,status:i,receipt:a??``,criticalPath:s,unknownType:c,safetyGate:l},p),n=[`Added entry #${e.entry?.id} to "${t}": [${i}] ${r}`];return e.formattedMap&&n.push(``,e.formattedMap),{content:[{type:`text`,text:n.join(`
|
|
562
562
|
`)}]}}case`update`:{if(!t)throw Error(`task_id required for update`);if(o===void 0)throw Error(`id required for update`);if(!i)throw Error(`status required for update`);let e=Ae({action:`update`,taskId:t,id:o,status:i,receipt:a??``},p),n=[`Updated entry #${o} in "${t}" → ${i}`];return e.formattedMap&&n.push(``,e.formattedMap),{content:[{type:`text`,text:n.join(`
|
|
563
563
|
`)}]}}case`get`:{if(!t)throw Error(`task_id required for get`);let e=Ae({action:`get`,taskId:t},p);return e.state?{content:[{type:`text`,text:[`## Evidence Map: ${t} (${e.state.tier})`,``,e.formattedMap??`No entries.`,``,`_${e.state.entries.length} entries — created ${e.state.createdAt}_`].join(`
|
|
564
564
|
`)}]}:{content:[{type:`text`,text:`Evidence map "${t}" not found.`}]}}case`gate`:{if(!t)throw Error(`task_id required for gate`);let e=Ae({action:`gate`,taskId:t,retryCount:u,maxRetries:d,timeoutAction:f},p);if(!e.gate)return{content:[{type:`text`,text:`Evidence map "${t}" not found.`}]};let n=e.gate,r=[`## FORGE Gate: **${n.verdict}**`,``,`**Reason:** ${n.reason}`,``,`**Stats:** ${n.stats.verified}V / ${n.stats.assumed}A / ${n.stats.unresolved}U (${n.stats.total} total)`];return n.action&&r.push(``,`**Recommended action:** ${n.action}`),n.retriesRemaining!==void 0&&r.push(`**Retries remaining:** ${n.retriesRemaining}`),n.summary&&r.push(``,`**Summary:** ${n.summary}`),n.warnings.length>0&&r.push(``,`**Warnings:**`,...n.warnings.map(e=>`- ⚠️ ${e}`)),n.unresolvedCritical.length>0&&r.push(``,`**Blocking entries:**`,...n.unresolvedCritical.map(e=>`- #${e.id}: ${e.claim} [${e.unknownType??`untyped`}]`)),n.safetyGates&&(r.push(``,`**Safety Gates:**`,`- Provenance: ${n.safetyGates.provenance}`,`- Commitment: ${n.safetyGates.commitment}`,`- Coverage: ${n.safetyGates.coverage}`),n.safetyGates.failures.length>0&&r.push(``,`**Safety failures:**`,...n.safetyGates.failures.map(e=>`- \u{1F6D1} ${e}`))),n.annotation&&r.push(``,`**Annotation:**`,n.annotation),e.formattedMap&&r.push(``,`---`,``,e.formattedMap),r.push(``,`---`,`_Next: ${n.verdict===`YIELD`?`Proceed to implementation.`:n.action===`iterate`?`Re-run the build loop, then evaluate the gate again.`:n.action===`retry`?`Re-evaluate the gate after refreshing evidence.`:n.action===`manual`?`Ask for human review before proceeding.`:`Abort the current path and terminate the task.`}_`),{content:[{type:`text`,text:r.join(`
|
|
@@ -287,6 +287,9 @@ interface SqliteAdapterOptions {
|
|
|
287
287
|
*
|
|
288
288
|
* Tries the primary adapter first; if it fails to load (missing native binary,
|
|
289
289
|
* unsupported platform, etc.), falls back to the other adapter transparently.
|
|
290
|
+
*
|
|
291
|
+
* Auto-heals NODE_MODULE_VERSION mismatches by re-downloading the correct
|
|
292
|
+
* prebuild binary for the current Node.js version.
|
|
290
293
|
*/
|
|
291
294
|
declare function createSqliteAdapter(dbPath: string, options?: SqliteAdapterOptions): Promise<ISqliteAdapter>;
|
|
292
295
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./lance-store-
|
|
1
|
+
import{t as e}from"./lance-store-CQkljFy3.js";import{createRequire as t}from"node:module";import{AIKIT_PATHS as n}from"../../core/dist/index.js";import{execSync as r}from"node:child_process";import{existsSync as i,mkdirSync as a,readFileSync as o,writeFileSync as s}from"node:fs";import{dirname as c,join as l}from"node:path";var u=class{type=`better-sqlite3`;db=null;async open(e){let t=(await import(`better-sqlite3`)).default;this.db=new t(e)}exec(e){this.getDb().exec(e)}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){return this.getDb().prepare(e).all(...t)}run(e,t=[]){this.getDb().prepare(e).run(...t)}flush(){}close(){this.db&&=(this.db.close(),null)}getDb(){if(!this.db)throw Error(`BetterSqliteAdapter: database not opened`);return this.db}},d=class{type=`sql.js`;db=null;dbPath=``;dirty=!1;inTransaction=!1;async open(e){this.dbPath=e;let t=(await import(`sql.js`)).default,n=await t();if(i(e)){let t=o(e);this.db=new n.Database(t)}else this.db=new n.Database}exec(e){let t=e.trimStart().toUpperCase();t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.getDb().run(e),this.dirty=!0}pragma(e){this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);t.length>0&&n.bind(t);let r=[];for(;n.step();)r.push(n.getAsObject());return n.free(),r}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=!this.inTransaction&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));if(i&&n.run(`SAVEPOINT fk_check`),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`)}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export();s(this.dbPath,Buffer.from(e)),this.dirty=!1}close(){this.db&&=(this.flush(),this.db.close(),null)}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};function f(e){let t=e instanceof Error?e.message:String(e);return t.includes(`NODE_MODULE_VERSION`)||t.includes(`was compiled against a different Node.js version`)}function p(){try{let e=c(t(import.meta.url).resolve(`better-sqlite3/package.json`));return console.error(`[aikit] Native module version mismatch detected — re-downloading prebuild for Node ${process.version}...`),r(`npm rebuild better-sqlite3`,{cwd:e,stdio:`pipe`,timeout:6e4}),console.error(`[aikit] Prebuild re-downloaded successfully`),!0}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(`[aikit] Auto-heal failed: ${t}`),!1}}async function m(e,t){let n=t?.primary??`better-sqlite3`,r=[n,n===`better-sqlite3`?`sql.js`:`better-sqlite3`],i=!1;for(let t of r)try{let r=t===`better-sqlite3`?new u:new d;return await r.open(e),t!==n&&console.error(`[aikit] SQLite adapter: primary "${n}" unavailable, using fallback "${t}"`),r}catch(n){let r=n instanceof Error?n.message:String(n);if(console.error(`[aikit] SQLite adapter "${t}" failed to load: ${r}`),t===`better-sqlite3`&&!i&&f(n)&&(i=!0,p()))try{let t=new u;return await t.open(e),console.error(`[aikit] SQLite adapter "better-sqlite3" loaded after auto-heal`),t}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[aikit] Retry after heal still failed: ${t}`)}}throw Error(`[aikit] No SQLite adapter available. Tried: ${r.join(`, `)}. Install either better-sqlite3 or sql.js.`)}var h=class{adapter=null;dbPath;adapterOptions;constructor(e){let t=e?.path??n.data;this.dbPath=l(t,`graph.db`),this.adapterOptions=e?.sqliteAdapter}async initialize(){let e=c(this.dbPath);i(e)||a(e,{recursive:!0}),this.adapter=await m(this.dbPath,this.adapterOptions),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,
|
|
@@ -39,7 +39,7 @@ import{t as e}from"./lance-store-jdHZp-V4.js";import{AIKIT_PATHS as t}from"../..
|
|
|
39
39
|
FOREIGN KEY (process_id) REFERENCES processes(id) ON DELETE CASCADE,
|
|
40
40
|
FOREIGN KEY (node_id) REFERENCES nodes(id) ON DELETE CASCADE
|
|
41
41
|
)
|
|
42
|
-
`),e.exec(`CREATE INDEX IF NOT EXISTS idx_process_steps_node ON process_steps(node_id)`)}migrateSchema(e){for(let t of[`ALTER TABLE edges ADD COLUMN confidence REAL DEFAULT 1.0`,`ALTER TABLE nodes ADD COLUMN community TEXT`])try{e.exec(t)}catch{}e.exec(`CREATE INDEX IF NOT EXISTS idx_nodes_community ON nodes(community)`)}getAdapter(){if(!this.adapter)throw Error(`SqliteGraphStore not initialized — call initialize() first`);return this.adapter}async ensureOpen(){this.adapter||(this.adapter=await
|
|
42
|
+
`),e.exec(`CREATE INDEX IF NOT EXISTS idx_process_steps_node ON process_steps(node_id)`)}migrateSchema(e){for(let t of[`ALTER TABLE edges ADD COLUMN confidence REAL DEFAULT 1.0`,`ALTER TABLE nodes ADD COLUMN community TEXT`])try{e.exec(t)}catch{}e.exec(`CREATE INDEX IF NOT EXISTS idx_nodes_community ON nodes(community)`)}getAdapter(){if(!this.adapter)throw Error(`SqliteGraphStore not initialized — call initialize() first`);return this.adapter}async ensureOpen(){this.adapter||(this.adapter=await m(this.dbPath,this.adapterOptions),this.configureAdapter(this.adapter))}query(e,t=[]){return this.getAdapter().queryAll(e,t)}run(e,t=[]){this.getAdapter().run(e,t)}async upsertNode(e){await this.ensureOpen(),this.run(`INSERT INTO nodes (id, type, name, properties, source_record_id, source_path, created_at, community)
|
|
43
43
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
44
44
|
ON CONFLICT(id) DO UPDATE SET
|
|
45
45
|
type = excluded.type, name = excluded.name, properties = excluded.properties,
|
|
@@ -57,19 +57,19 @@ import{t as e}from"./lance-store-jdHZp-V4.js";import{AIKIT_PATHS as t}from"../..
|
|
|
57
57
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
58
58
|
ON CONFLICT(id) DO UPDATE SET
|
|
59
59
|
from_id = excluded.from_id, to_id = excluded.to_id,
|
|
60
|
-
type = excluded.type, weight = excluded.weight, confidence = excluded.confidence, properties = excluded.properties`,[t.id,t.fromId,t.toId,t.type,t.weight??1,t.confidence??1,JSON.stringify(t.properties??{})]);t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}finally{t.pragma(`foreign_keys = ON`)}}async getNode(e){await this.ensureOpen();let t=this.query(`SELECT * FROM nodes WHERE id = ?`,[e]);return t.length>0?
|
|
60
|
+
type = excluded.type, weight = excluded.weight, confidence = excluded.confidence, properties = excluded.properties`,[t.id,t.fromId,t.toId,t.type,t.weight??1,t.confidence??1,JSON.stringify(t.properties??{})]);t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}finally{t.pragma(`foreign_keys = ON`)}}async getNode(e){await this.ensureOpen();let t=this.query(`SELECT * FROM nodes WHERE id = ?`,[e]);return t.length>0?_(t[0]):null}async getNeighbors(e,t){await this.ensureOpen();let n=t?.direction??`both`,r=t?.edgeType,i=t?.limit??50,a=[],o=[],s=new Set;if(n===`outgoing`||n===`both`){let t=`
|
|
61
61
|
SELECT e.id AS edge_id, e.from_id, e.to_id, e.type AS edge_type, e.weight,
|
|
62
62
|
e.confidence AS edge_confidence, e.properties AS edge_props,
|
|
63
63
|
n.id AS node_id, n.type AS node_type, n.name AS node_name, n.properties AS node_props,
|
|
64
64
|
n.source_record_id AS node_src_rec, n.source_path AS node_src_path,
|
|
65
65
|
n.created_at AS node_created, n.community AS node_community
|
|
66
|
-
FROM edges e JOIN nodes n ON e.to_id = n.id WHERE e.from_id = ?`,n=[e];r&&(t+=` AND e.type = ?`,n.push(r)),t+=` LIMIT ?`,n.push(i);let c=this.query(t,n);for(let e of c)o.push(
|
|
66
|
+
FROM edges e JOIN nodes n ON e.to_id = n.id WHERE e.from_id = ?`,n=[e];r&&(t+=` AND e.type = ?`,n.push(r)),t+=` LIMIT ?`,n.push(i);let c=this.query(t,n);for(let e of c)o.push(y(e)),s.has(e.node_id)||(s.add(e.node_id),a.push(b(e)))}if(n===`incoming`||n===`both`){let t=`
|
|
67
67
|
SELECT e.id AS edge_id, e.from_id, e.to_id, e.type AS edge_type, e.weight,
|
|
68
68
|
e.confidence AS edge_confidence, e.properties AS edge_props,
|
|
69
69
|
n.id AS node_id, n.type AS node_type, n.name AS node_name, n.properties AS node_props,
|
|
70
70
|
n.source_record_id AS node_src_rec, n.source_path AS node_src_path,
|
|
71
71
|
n.created_at AS node_created, n.community AS node_community
|
|
72
|
-
FROM edges e JOIN nodes n ON e.from_id = n.id WHERE e.to_id = ?`,n=[e];r&&(t+=` AND e.type = ?`,n.push(r)),t+=` LIMIT ?`,n.push(i);let c=this.query(t,n);for(let e of c)o.push(
|
|
72
|
+
FROM edges e JOIN nodes n ON e.from_id = n.id WHERE e.to_id = ?`,n=[e];r&&(t+=` AND e.type = ?`,n.push(r)),t+=` LIMIT ?`,n.push(i);let c=this.query(t,n);for(let e of c)o.push(y(e)),s.has(e.node_id)||(s.add(e.node_id),a.push(b(e)))}return{nodes:a,edges:o}}async traverse(e,t){await this.ensureOpen();let n=t?.maxDepth??2,r=t?.direction??`both`,i=t?.edgeType,a=t?.limit??50,o=new Map,s=new Map,c=new Set,l=[{nodeId:e,depth:0}];for(;l.length>0&&o.size<a;){let e=l.shift();if(!e||c.has(e.nodeId)||e.depth>n)continue;c.add(e.nodeId);let t=await this.getNeighbors(e.nodeId,{direction:r,edgeType:i,limit:a-o.size});for(let r of t.nodes)o.has(r.id)||(o.set(r.id,r),e.depth+1<n&&l.push({nodeId:r.id,depth:e.depth+1}));for(let e of t.edges)s.set(e.id,e)}return{nodes:[...o.values()],edges:[...s.values()]}}async findNodes(e){await this.ensureOpen();let t=[],n=[];e.type&&(t.push(`type = ?`),n.push(e.type)),e.namePattern&&(t.push(`name LIKE ?`),n.push(`%${e.namePattern}%`)),e.sourcePath&&(t.push(`source_path = ?`),n.push(e.sourcePath));let r=t.length>0?`WHERE ${t.join(` AND `)}`:``,i=e.limit??100;return this.query(`SELECT * FROM nodes ${r} LIMIT ?`,[...n,i]).map(e=>_(e))}async findEdges(e){await this.ensureOpen();let t=[],n=[];e.type&&(t.push(`type = ?`),n.push(e.type)),e.fromId&&(t.push(`from_id = ?`),n.push(e.fromId)),e.toId&&(t.push(`to_id = ?`),n.push(e.toId));let r=t.length>0?`WHERE ${t.join(` AND `)}`:``,i=e.limit??100;return this.query(`SELECT * FROM edges ${r} LIMIT ?`,[...n,i]).map(e=>v(e))}async deleteNode(e){await this.ensureOpen();let t=this.getAdapter();t.exec(`BEGIN TRANSACTION`);try{this.run(`DELETE FROM edges WHERE from_id = ? OR to_id = ?`,[e,e]),this.run(`DELETE FROM nodes WHERE id = ?`,[e]),t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}}async deleteBySourcePath(e){await this.ensureOpen();let t=this.query(`SELECT id FROM nodes WHERE source_path = ?`,[e]);if(t.length===0)return 0;let n=this.getAdapter();n.exec(`BEGIN TRANSACTION`);try{for(let e of t)this.run(`DELETE FROM edges WHERE from_id = ? OR to_id = ?`,[e.id,e.id]);this.run(`DELETE FROM nodes WHERE source_path = ?`,[e]),n.exec(`COMMIT`),n.flush()}catch(e){throw n.exec(`ROLLBACK`),e}return t.length}async clear(){await this.ensureOpen(),this.run(`DELETE FROM process_steps`),this.run(`DELETE FROM processes`),this.run(`DELETE FROM edges`),this.run(`DELETE FROM nodes`),this.getAdapter().flush()}async getStats(){await this.ensureOpen();let e=this.query(`SELECT COUNT(*) as count FROM nodes`)[0]?.count??0,t=this.query(`SELECT COUNT(*) as count FROM edges`)[0]?.count??0,n=this.query(`SELECT type, COUNT(*) as count FROM nodes GROUP BY type`),r={};for(let e of n)r[e.type]=e.count;let i=this.query(`SELECT type, COUNT(*) as count FROM edges GROUP BY type`),a={};for(let e of i)a[e.type]=e.count;return{nodeCount:e,edgeCount:t,nodeTypes:r,edgeTypes:a}}async validate(){await this.ensureOpen();let e=await this.getStats(),t=this.query(`SELECT e.id AS edgeId,
|
|
73
73
|
CASE
|
|
74
74
|
WHEN n1.id IS NULL THEN e.from_id
|
|
75
75
|
WHEN n2.id IS NULL THEN e.to_id
|
|
@@ -87,4 +87,4 @@ import{t as e}from"./lance-store-jdHZp-V4.js";import{AIKIT_PATHS as t}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:
|
|
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:g(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){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.adapter.close(),null)}};function g(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}function _(e){return{id:e.id,type:e.type,name:e.name,properties:g(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 v(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:g(e.properties)}}function y(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:g(e.edge_props??`{}`)}}function b(e){return{id:e.node_id,type:e.node_type,name:e.node_name,properties:g(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 x(e){switch(e.backend){case`lancedb`:{let{LanceStore:t}=await import(`./lance-store-CQkljFy3.js`).then(e=>e.n);return new t({path:e.path})}default:throw Error(`Unknown store backend: "${e.backend}". Supported: lancedb`)}}export{e as LanceStore,h as SqliteGraphStore,m as createSqliteAdapter,x as createStore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";import{EMBEDDING_DEFAULTS as e,SEARCH_DEFAULTS as t,STORE_DEFAULTS as n,createLogger as r,serializeError as i,sourceTypeContentTypes as a}from"../../core/dist/index.js";import{Index as o,connect as s}from"@lancedb/lancedb";var c=Object.defineProperty,l=((e,t)=>{let n={};for(var r in e)c(n,r,{get:e[r],enumerable:!0});return t||c(n,Symbol.toStringTag,{value:`Module`}),n})({LanceStore:()=>m});function u(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}const d=/^[\w.\-/ ]+$/,f=r(`store`);function p(e,t){if(!d.test(e))throw Error(`Invalid ${t} filter value: contains disallowed characters`);return e.replace(/'/g,`''`)}var m=class r{db=null;table=null;dbPath;tableName;_draining=!1;_priorityQueue=[];_normalQueue=[];_ftsReady=!1;_ftsRecoveryAttemptAt=0;static FTS_RECOVERY_COOLDOWN_MS=300*1e3;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}}}constructor(e){this.dbPath=e?.path??n.path,this.tableName=e?.tableName??n.tableName}async initialize(){this.db=await s(this.dbPath),(await this.db.tableNames()).includes(this.tableName)&&(this.table=await this.db.openTable(this.tableName),await this.createFtsIndex())}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async 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 _upsertImpl(e,t){let n=e.map((e,n)=>({id:e.id,vector:Array.from(t[n]),content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath??``,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:JSON.stringify(e.tags),category:e.category??``,version:e.version}));if(this.table){let t=[...new Set(e.map(e=>e.sourcePath))];for(let e of t)try{await this.table.delete(`sourcePath = '${p(e,`sourcePath`)}'`)}catch{}await this.table.add(n)}else try{this.table=await this.db?.createTable(this.tableName,n)??null}catch(e){if(String(e).includes(`already exists`)&&this.db)this.table=await this.db.openTable(this.tableName),await this.table.add(n);else throw e}}async search(e,n){if(!this.table)return[];let r=n?.limit??t.maxResults,i=n?.minScore??t.minScore,a=this.table.search(e).limit(r*2),o=this.buildFilterString(n);return o&&(a=a.where(o)),(await a.toArray()).map(e=>({record:this.fromLanceRecord(e),score:1-(e._distance??1)})).filter(e=>e.score>=i).slice(0,r)}async createFtsIndex(){return this.enqueueWrite(()=>this._createFtsIndexImpl())}async _createFtsIndexImpl(){if(this.table)try{await this.table.createIndex(`content`,{config:o.fts({withPosition:!0}),replace:!0}),this._ftsReady=!0,this._ftsRecoveryAttemptAt=0,f.info(`FTS index created/updated`,{column:`content`})}catch(e){f.warn(`FTS index creation failed`,i(e))}}async ftsSearch(e,n){if(!this.table)return[];if(!this._ftsReady){let e=Date.now();if(e-this._ftsRecoveryAttemptAt<r.FTS_RECOVERY_COOLDOWN_MS)return[];this._ftsRecoveryAttemptAt=e;try{await this.createFtsIndex()}catch{return[]}if(!this._ftsReady)return[]}let a=n?.limit??t.maxResults;try{let t=this.table.search(e).limit(a*2),r=this.buildFilterString(n);return r&&(t=t.where(r)),(await t.toArray()).map(e=>({record:this.fromLanceRecord(e),score:e._score??e._relevance_score??0}))}catch(e){return(e instanceof Error?e.message:String(e)).includes(`INVERTED index`)?(f.debug(`FTS search skipped — index not yet available`),this._ftsReady=!1):f.warn(`FTS search failed`,i(e)),[]}}async getById(e){if(!this.table)return null;let t=await this.table.query().where(`id = '${p(e,`id`)}'`).limit(1).toArray();return t.length===0?null:this.fromLanceRecord(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){if(!this.table)return 0;let t=await this.getBySourcePath(e);return t.length===0?0:(await this.table.delete(`sourcePath = '${p(e,`sourcePath`)}'`),t.length)}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async deleteByIdInteractive(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e),!0)}async _deleteByIdImpl(e){return!this.table||!await this.getById(e)?!1:(await this.table.delete(`id = '${p(e,`id`)}'`),!0)}async getBySourcePath(e){return this.table?(await this.table.query().where(`sourcePath = '${p(e,`sourcePath`)}'`).limit(1e3).toArray()).map(e=>this.fromLanceRecord(e)):[]}async getStats(){if(!this.table)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`lancedb`,embeddingModel:e.model};let t=await this.table.countRows(),n=await this.table.query().select([`sourcePath`,`contentType`,`indexedAt`]).limit(1e5).toArray(),r={},i=new Set,a=null;for(let e of n){let t=e;r[t.contentType]=(r[t.contentType]??0)+1,i.add(t.sourcePath),(!a||t.indexedAt>a)&&(a=t.indexedAt)}return{totalRecords:t,totalFiles:i.size,contentTypeBreakdown:r,lastIndexedAt:a,storeBackend:`lancedb`,embeddingModel:e.model}}async listSourcePaths(){if(!this.table)return[];let e=await this.table.query().select([`sourcePath`]).limit(1e5).toArray();return[...new Set(e.map(e=>e.sourcePath))]}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){if(this.db&&(await this.db.tableNames()).includes(this.tableName))for(let e=1;e<=3;e++)try{await this.db.dropTable(this.tableName);break}catch(t){if(e===3)throw t;let n=e*500;f.warn(`dropTable attempt failed, retrying`,{attempt:e,delayMs:n}),await new Promise(e=>setTimeout(e,n))}this.table=null}async close(){try{this.db&&typeof this.db.close==`function`&&await this.db.close()}catch{}this.table=null,this.db=null}buildFilterString(e){let t=[];if(e?.contentType&&t.push(`contentType = '${p(e.contentType,`contentType`)}'`),e?.sourceType){let n=a(e.sourceType);if(n.length>0){let e=n.map(e=>`'${p(e,`sourceType`)}'`).join(`, `);t.push(`contentType IN (${e})`)}}if(e?.origin&&t.push(`origin = '${p(e.origin,`origin`)}'`),e?.category&&t.push(`category = '${p(e.category,`category`)}'`),e?.tags&&e.tags.length>0){let n=e.tags.map(e=>`tags LIKE '%${p(e,`tag`)}%'`);t.push(`(${n.join(` OR `)})`)}return t.length>0?t.join(` AND `):null}fromLanceRecord(e){return{id:e.id,content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath||void 0,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:u(e.tags),category:e.category||void 0,version:e.version}}};export{l as n,m as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{EMBEDDING_DEFAULTS as e,SEARCH_DEFAULTS as t,STORE_DEFAULTS as n,createLogger as r,serializeError as i,sourceTypeContentTypes as a}from"../../core/dist/index.js";import{Index as o,connect as s}from"@lancedb/lancedb";var c=Object.defineProperty,l=((e,t)=>{let n={};for(var r in e)c(n,r,{get:e[r],enumerable:!0});return t||c(n,Symbol.toStringTag,{value:`Module`}),n})({LanceStore:()=>m});function u(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}const d=/^[\w.\-/ ]+$/,f=r(`store`);function p(e,t){if(!d.test(e))throw Error(`Invalid ${t} filter value: contains disallowed characters`);return e.replace(/'/g,`''`)}var m=class r{db=null;table=null;dbPath;tableName;_draining=!1;_priorityQueue=[];_normalQueue=[];_ftsReady=!1;_ftsRecoveryAttemptAt=0;static FTS_RECOVERY_COOLDOWN_MS=300*1e3;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}}}constructor(e){this.dbPath=e?.path??n.path,this.tableName=e?.tableName??n.tableName}async initialize(){this.db=await s(this.dbPath),(await this.db.tableNames()).includes(this.tableName)&&(this.table=await this.db.openTable(this.tableName),await this.createFtsIndex())}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async 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 _upsertImpl(e,t){let n=e.map((e,n)=>({id:e.id,vector:Array.from(t[n]),content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath??``,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:JSON.stringify(e.tags),category:e.category??``,version:e.version}));if(this.table){let t=[...new Set(e.map(e=>e.sourcePath))];for(let e of t)try{await this.table.delete(`sourcePath = '${p(e,`sourcePath`)}'`)}catch{}await this.table.add(n)}else try{this.table=await this.db?.createTable(this.tableName,n)??null}catch(e){if(String(e).includes(`already exists`)&&this.db)this.table=await this.db.openTable(this.tableName),await this.table.add(n);else throw e}}async search(e,n){if(!this.table)return[];let r=n?.limit??t.maxResults,i=n?.minScore??t.minScore,a=this.table.search(e).limit(r*2),o=this.buildFilterString(n);return o&&(a=a.where(o)),(await a.toArray()).map(e=>({record:this.fromLanceRecord(e),score:1-(e._distance??1)})).filter(e=>e.score>=i).slice(0,r)}async createFtsIndex(){return this.enqueueWrite(()=>this._createFtsIndexImpl())}async _createFtsIndexImpl(){if(this.table)try{await this.table.createIndex(`content`,{config:o.fts({withPosition:!0}),replace:!0}),this._ftsReady=!0,this._ftsRecoveryAttemptAt=0,f.info(`FTS index created/updated`,{column:`content`})}catch(e){f.warn(`FTS index creation failed`,i(e))}}async ftsSearch(e,n){if(!this.table)return[];if(!this._ftsReady){let e=Date.now();if(e-this._ftsRecoveryAttemptAt<r.FTS_RECOVERY_COOLDOWN_MS)return[];this._ftsRecoveryAttemptAt=e;try{await this.createFtsIndex()}catch{return[]}if(!this._ftsReady)return[]}let a=n?.limit??t.maxResults;try{let t=this.table.search(e).limit(a*2),r=this.buildFilterString(n);return r&&(t=t.where(r)),(await t.toArray()).map(e=>({record:this.fromLanceRecord(e),score:e._score??e._relevance_score??0}))}catch(e){return(e instanceof Error?e.message:String(e)).includes(`INVERTED index`)?(f.debug(`FTS search skipped — index not yet available`),this._ftsReady=!1):f.warn(`FTS search failed`,i(e)),[]}}async getById(e){if(!this.table)return null;let t=await this.table.query().where(`id = '${p(e,`id`)}'`).limit(1).toArray();return t.length===0?null:this.fromLanceRecord(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){if(!this.table)return 0;let t=await this.getBySourcePath(e);return t.length===0?0:(await this.table.delete(`sourcePath = '${p(e,`sourcePath`)}'`),t.length)}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async deleteByIdInteractive(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e),!0)}async _deleteByIdImpl(e){return!this.table||!await this.getById(e)?!1:(await this.table.delete(`id = '${p(e,`id`)}'`),!0)}async getBySourcePath(e){return this.table?(await this.table.query().where(`sourcePath = '${p(e,`sourcePath`)}'`).limit(1e3).toArray()).map(e=>this.fromLanceRecord(e)):[]}async getStats(){if(!this.table)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`lancedb`,embeddingModel:e.model};let t=await this.table.countRows(),n=await this.table.query().select([`sourcePath`,`contentType`,`indexedAt`]).limit(1e5).toArray(),r={},i=new Set,a=null;for(let e of n){let t=e;r[t.contentType]=(r[t.contentType]??0)+1,i.add(t.sourcePath),(!a||t.indexedAt>a)&&(a=t.indexedAt)}return{totalRecords:t,totalFiles:i.size,contentTypeBreakdown:r,lastIndexedAt:a,storeBackend:`lancedb`,embeddingModel:e.model}}async listSourcePaths(){if(!this.table)return[];let e=await this.table.query().select([`sourcePath`]).limit(1e5).toArray();return[...new Set(e.map(e=>e.sourcePath))]}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){if(this.db&&(await this.db.tableNames()).includes(this.tableName))for(let e=1;e<=3;e++)try{await this.db.dropTable(this.tableName);break}catch(t){if(e===3)throw t;let n=e*500;f.warn(`dropTable attempt failed, retrying`,{attempt:e,delayMs:n}),await new Promise(e=>setTimeout(e,n))}this.table=null}async close(){try{this.db&&typeof this.db.close==`function`&&await this.db.close()}catch{}this.table=null,this.db=null}buildFilterString(e){let t=[];if(e?.contentType&&t.push(`contentType = '${p(e.contentType,`contentType`)}'`),e?.sourceType){let n=a(e.sourceType);if(n.length>0){let e=n.map(e=>`'${p(e,`sourceType`)}'`).join(`, `);t.push(`contentType IN (${e})`)}}if(e?.origin&&t.push(`origin = '${p(e.origin,`origin`)}'`),e?.category&&t.push(`category = '${p(e.category,`category`)}'`),e?.tags&&e.tags.length>0){let n=e.tags.map(e=>`tags LIKE '%${p(e,`tag`)}%'`);t.push(`(${n.join(` OR `)})`)}return t.length>0?t.join(` AND `):null}fromLanceRecord(e){return{id:e.id,content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath||void 0,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:u(e.tags),category:e.category||void 0,version:e.version}}};export{l as n,m as t};
|