@devflow-tools/devflow 0.7.4 → 0.7.5
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/dist/cli.js +1 -1
- package/dist/hooks/pre-tool-use.js +2 -0
- package/dist/plugin/hooks.json +2 -2
- package/dist/plugin/skills/devflow/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:animation/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:context/SKILL.md +3 -0
- package/dist/plugin/skills/devflow:css/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:docker/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:doctor/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:electron/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:git/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:graph/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:graphql/SKILL.md +3 -0
- package/dist/plugin/skills/devflow:knowledge/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:memory/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:nest/SKILL.md +3 -0
- package/dist/plugin/skills/devflow:nextjs/SKILL.md +3 -0
- package/dist/plugin/skills/devflow:performance/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:react/SKILL.md +7 -0
- package/dist/plugin/skills/devflow:start/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:tailwind/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:taro/SKILL.md +2 -0
- package/dist/plugin/skills/devflow:ui-layout/SKILL.md +1 -0
- package/dist/plugin/skills/devflow:vue/SKILL.md +4 -0
- package/dist/plugin/skills/devflow:workflow/SKILL.md +2 -0
- package/dist/server.js +2 -2
- package/package.json +16 -14
- package/scripts/postinstall.js +123 -0
package/dist/cli.js
CHANGED
|
@@ -22,7 +22,7 @@ ${t.pid??0}`),t.unref(),{pid:t.pid??0}}async function I(){let e=ge(process.cwd()
|
|
|
22
22
|
`)}var Hn=createRequire(import.meta.url),Bn="shilongfeicool/dev-flow";function he(){return join(homedir(),".devflow","dashboard")}function Vn(){try{return Hn("../../package.json").version??"0.0.0"}catch{return "0.0.0"}}function G(){let e=he(),o=join(e,"cache.json");if(!existsSync(o))return null;try{let n=JSON.parse(readFileSync(o,"utf-8"));if(existsSync(n.path))return n}catch{}return null}async function zn(e,o){let n=he(),t=join(n,"versions",e);if(existsSync(t)&&existsSync(join(t,"server.js")))return xo(n,t,e),join(n,"current");let r=`https://github.com/${Bn}/releases/download/v${e}/dashboard-standalone.tar.gz`;o?.(`Downloading Dashboard v${e} ...`);let s=join(n,"temp");mkdirSync(s,{recursive:true});try{let i=join(s,"dashboard.tar.gz"),a=await fetch(r);if(!a.ok)throw new Error(`Download failed: HTTP ${a.status} ${a.statusText}
|
|
23
23
|
URL: ${r}
|
|
24
24
|
The Dashboard asset may not have been published for v${e}.`);if(!a.body)throw new Error("Download failed: empty response body");let d=a.body.getReader(),u=[];for(;;){let{done:w,value:$}=await d.read();if(w)break;u.push($);}let p=u.reduce((w,$)=>w+$.length,0),h=new Uint8Array(p),C=0;for(let w of u)h.set(w,C),C+=w.length;writeFileSync(i,h),mkdirSync(t,{recursive:!0});try{execSync(`tar -xzf "${i}" -C "${t}"`,{stdio:"pipe"});}catch(w){throw new Error(`Failed to extract Dashboard archive: ${w.message}
|
|
25
|
-
Ensure 'tar' is available on your system.`)}xo(n,t,e);let j={version:e,path:join(n,"current"),downloadedAt:new Date().toISOString()};return writeFileSync(join(n,"cache.json"),JSON.stringify(j,null,2)),o?.(`Dashboard v${e} installed`),j.path}finally{rmSync(s,{recursive:true,force:true});}}function xo(e,o,n){let t=join(e,"current");(existsSync(t)||Yn(t))&&rmSync(t,{recursive:true,force:true}),symlinkSync(o,t,"junction");let r=join(e,"cache.json"),s;try{s=JSON.parse(readFileSync(r,"utf-8"));}catch{s={version:"",path:t,downloadedAt:""};}s.version=n,s.path=t,s.downloadedAt=new Date().toISOString(),writeFileSync(r,JSON.stringify(s,null,2));}function Yn(e){try{return lstatSync(e).isSymbolicLink()}catch{return false}}async function N(e){let o=Vn(),n=G();if(n&&n.version===o&&!e?.force)return n.path;if(e?.force&&n){let t=join(he(),"versions",n.version);existsSync(t)&&rmSync(t,{recursive:true,force:true});}return zn(o,t=>{console.log(t);})}function P(){return join(process.cwd(),".devflow","dashboard.pid")}function tt(e){let o="<html><body><h1>DevFlow</h1><p>Dashboard is being downloaded...</p></body></html>";try{let t=[resolve(process.cwd(),"node_modules","@devflow-tools","devflow","dist","fallback.html"),resolve(process.cwd(),"apps","server","public","fallback.html")];for(let r of t)if(existsSync(r)){o=readFileSync(r,"utf-8");break}}catch{}createServer((t,r)=>{r.writeHead(200,{"Content-Type":"text/html"}),r.end(o);}).listen(e,()=>{console.log(l.yellow(` Fallback page served on port ${e} (dashboard downloading...)`));});}async function rt(e,o=15e3){let n=Date.now();for(;Date.now()-n<o;){try{if((await fetch(`http://localhost:${e}/api/projects/active`,{headers:{"x-api-key":"dev-key-000000"}})).ok)return !0}catch{}await new Promise(t=>setTimeout(t,500));}return false}async function Io(e){console.log(l.blue("Starting DevFlow server..."));let{pid:o}=await W({port:e.port});console.log(l.green(` Server started (PID: ${o})`)),console.log(l.blue(" Waiting for server..."));let n=await rt(e.port);if(console.log(n?l.green(" Server ready"):l.yellow(" Server started but health check timed out")),!e.noDashboard){console.log(l.blue("Preparing Dashboard..."));let t=G();if(!t){console.log(l.blue(" Dashboard not found, downloading..."));try{await N(),console.log(l.green(" Dashboard download complete")),t=G();}catch{console.log(l.red(" Dashboard download failed")),console.log(l.yellow(` You can still use the API at http://localhost:${e.port}`)),console.log(l.yellow(" To manually download the dashboard, visit: https://github.com/devflow-tools/devflow"));}}if(t)try{let r=await N(),s=join(r,"server.js");if(existsSync(s)){let i=spawn("node",[s],{env:{...process.env,PORT:String(e.dashboardPort)},stdio:"ignore",detached:!0});if(i.pid){let a=P(),d=join(process.cwd(),".devflow");existsSync(d)||mkdirSync(d,{recursive:!0}),writeFileSync(a,`${e.dashboardPort}
|
|
25
|
+
Ensure 'tar' is available on your system.`)}xo(n,t,e);let j={version:e,path:join(n,"current"),downloadedAt:new Date().toISOString()};return writeFileSync(join(n,"cache.json"),JSON.stringify(j,null,2)),o?.(`Dashboard v${e} installed`),j.path}finally{rmSync(s,{recursive:true,force:true});}}function xo(e,o,n){let t=join(e,"current");(existsSync(t)||Yn(t))&&rmSync(t,{recursive:true,force:true}),symlinkSync(o,t,"junction");let r=join(e,"cache.json"),s;try{s=JSON.parse(readFileSync(r,"utf-8"));}catch{s={version:"",path:t,downloadedAt:""};}s.version=n,s.path=t,s.downloadedAt=new Date().toISOString(),writeFileSync(r,JSON.stringify(s,null,2));}function Yn(e){try{return lstatSync(e).isSymbolicLink()}catch{return false}}async function N(e){let o=Vn(),n=G();if(n&&n.version===o&&!e?.force)return n.path;if(e?.force&&n){let t=join(he(),"versions",n.version);existsSync(t)&&rmSync(t,{recursive:true,force:true});}return zn(o,t=>{console.log(t);})}function P(){return join(process.cwd(),".devflow","dashboard.pid")}function tt(e){let o="<html><body><h1>DevFlow</h1><p>Dashboard is being downloaded...</p></body></html>";try{let t=[resolve(process.cwd(),"node_modules","@devflow-tools","devflow","dist","fallback.html"),resolve(process.cwd(),"apps","server","public","fallback.html")];for(let r of t)if(existsSync(r)){o=readFileSync(r,"utf-8");break}}catch{}createServer((t,r)=>{r.writeHead(200,{"Content-Type":"text/html"}),r.end(o);}).listen(e,()=>{console.log(l.yellow(` Fallback page served on port ${e} (dashboard downloading...)`));});}async function rt(e,o=15e3){let n=Date.now();for(;Date.now()-n<o;){try{if((await fetch(`http://localhost:${e}/api/projects/active`,{headers:{"x-api-key":"dev-key-000000"}})).ok)return !0}catch{}await new Promise(t=>setTimeout(t,500));}return false}async function Io(e){console.log(l.blue("Starting DevFlow server..."));let{pid:o}=await W({port:e.port});console.log(l.green(` Server started (PID: ${o})`)),console.log(l.blue(" Waiting for server..."));let n=await rt(e.port);if(console.log(n?l.green(" Server ready"):l.yellow(" Server started but health check timed out")),!e.noDashboard){console.log(l.blue("Preparing Dashboard..."));let t=G();if(!t){console.log(l.blue(" Dashboard not found, downloading..."));try{await N(),console.log(l.green(" Dashboard download complete")),t=G();}catch{console.log(l.red(" Dashboard download failed")),console.log(l.yellow(` You can still use the API at http://localhost:${e.port}`)),console.log(l.yellow(" To manually download the dashboard, visit: https://github.com/devflow-tools/devflow"));}}if(t)try{let r=await N(),s=join(r,"server.js");if(existsSync(s)){let i=spawn("node",[s],{env:{...process.env,PORT:String(e.dashboardPort)},cwd:r,stdio:"ignore",detached:!0});if(i.pid){let a=P(),d=join(process.cwd(),".devflow");existsSync(d)||mkdirSync(d,{recursive:!0}),writeFileSync(a,`${e.dashboardPort}
|
|
26
26
|
${i.pid}`),i.unref(),console.log(l.green(` Dashboard started (PID: ${i.pid})`));}}}catch{tt(e.dashboardPort);}}console.log(""),console.log(l.green("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")),console.log(l.green("\u2551")+" \u{1F680} DevFlow Started! "+l.green("\u2551")),console.log(l.green("\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563")),console.log(l.green("\u2551")+` \u{1F5A5}\uFE0F Server: http://localhost:${e.port}`.padEnd(57)+l.green("\u2551")),console.log(l.green("\u2551")+` \u{1F3A8} Dashboard: http://localhost:${e.dashboardPort}`.padEnd(57)+l.green("\u2551")),console.log(l.green("\u2551")+" "+l.green("\u2551")),console.log(l.green("\u2551")+" Press Ctrl+C to stop all services "+l.green("\u2551")),console.log(l.green("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")),e.background||await new Promise(t=>{let r=false,s=async()=>{if(r)return;r=true,console.log(l.blue(`
|
|
27
27
|
Shutting down...`));let i=P();if(existsSync(i))try{let a=readFileSync(i,"utf-8").trim().split(`
|
|
28
28
|
`),d=a.length>=2?a[1]:a[0],u=parseInt(d,10);process.kill(u),unlinkSync(i);}catch{}await I(),console.log(l.green("All services stopped.")),t();};process.on("SIGINT",s),process.on("SIGTERM",s);});}async function Oo(){let e=false,o=P();if(existsSync(o))try{let t=R(o);t!==null&&(process.kill(t),console.log(l.green(`Dashboard stopped (PID: ${t})`))),unlinkSync(o),e=!0;}catch{unlinkSync(o),console.log(l.yellow("Dashboard process not found, cleaned up PID file"));}await I()&&(console.log(l.green("Server stopped")),e=true),e||console.log(l.dim("No DevFlow services running"));}function at(){return join(process.cwd(),".devflow","devflow.db")}async function To(){console.log(l.blue("DevFlow Status")),console.log(l.dim("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));let e=await F(),o=e.port??ue;e.running?console.log(`Server: ${l.green("\u2713")} running (port ${o}${e.pid?`, PID ${e.pid}`:""})`):console.log(`Server: ${l.yellow("\u25CB")} not running`);let n=P();if(existsSync(n)){let r=pe(n),s=R(n);if(s!==null)try{process.kill(s,0);let i=r!==null?`port ${r}`:"port 17788";console.log(`Dashboard: ${l.green("\u2713")} running (${i}, PID ${s})`);}catch{console.log(`Dashboard: ${l.red("\u2717")} PID ${s} not found (stale PID file)`);}else console.log(`Dashboard: ${l.yellow("\u25CB")} not running (unreadable PID file)`);}else console.log(`Dashboard: ${l.yellow("\u25CB")} not running`);let t=at();if(existsSync(t)){let s=(statSync(t).size/1024/1024).toFixed(1);console.log(`Data: .devflow/devflow.db (${s} MB)`);}else console.log(`Data: ${l.dim("no database")}`);}var ft=createRequire(import.meta.url);function wt(){let e=[resolve(dirname(ft.resolve("../../package.json")),"dist","plugin"),resolve(process.cwd(),"plugins","claude-code")];for(let o of e)if(existsSync(join(o,".claude-plugin","plugin.json")))return o;return null}function ht(e,o){let n={};if(existsSync(e))try{n=JSON.parse(readFileSync(e,"utf-8"));}catch{n={};}let t={...n,...o};writeFileSync(e,JSON.stringify(t,null,2));}async function Ao(e){if(console.log(l.blue("DevFlow Setup")),console.log(l.dim("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),!e.skipMcp)try{let o=await L({agent:e.agent,command:"devflow-mcp"});for(let n of o)console.log(l.green(` \u2713 MCP: ${n}`));}catch(o){console.log(l.yellow(` \u26A0 MCP setup failed: ${o.message}`)),console.log(l.dim(" You can configure MCP manually with: devflow connect"));}if(!e.skipPlugin){let o=wt();if(o){let n=join(homedir(),".claude","plugins");mkdirSync(n,{recursive:true});let t=join(n,"known_marketplaces.json");ht(t,{devflow:{source:{directory:o}}}),console.log(l.green(` \u2713 Plugin registered: ${o}`));}else console.log(l.yellow(" \u26A0 Plugin directory not found")),console.log(l.dim(" The Claude Code plugin may not be available."));}console.log(""),console.log(l.green("Setup complete!")),console.log(l.dim("Restart Claude Code to use /devflow:* commands"));}var Mo=new Command("list").description("List available plugins").option("-i, --installed","Show only installed plugins").action(async e=>{let o=D();if(e.installed){let n=Le();if(n.length===0){console.log("No plugins installed."),console.log(`
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {existsSync,readFileSync,mkdirSync,writeFileSync,unlinkSync,readdirSync}from'fs';import {join}from'path';import {homedir}from'os';var g=1e4,D=300*1e3,l=class{constructor(e){this.retryScheduled=false;this.apiUrl=e?.apiUrl??process.env.DEVFLOW_API_URL??"http://localhost:13337",this.apiKey=e?.apiKey??process.env.DEVFLOW_API_KEY??"dev-key-000000",this.cacheDir=e?.cacheDir??join(homedir(),".devflow","telemetry-cache");}async sendEvent(e){let t=this.truncateInput(e.input),o={...e,input:t};try{let r=await fetch(`${this.apiUrl}/api/telemetry/tool-call`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.apiKey},body:JSON.stringify(o)});if(!r.ok)throw new Error(`Server responded ${r.status}`)}catch{this.cacheEvent({type:"tool_call",payload:o});}}async sendExecutionStart(e,t,o){let r={executionId:e,skillName:t,startedAt:o};try{let n=await fetch(`${this.apiUrl}/api/telemetry/skill-execution/start`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.apiKey},body:JSON.stringify(r)});if(!n.ok)throw new Error(`Server responded ${n.status}`)}catch{this.cacheEvent({type:"execution_start",payload:r});}}async flushCache(){if(!existsSync(this.cacheDir))return;let e=readdirSync(this.cacheDir).filter(t=>t.endsWith(".json"));for(let t of e)try{let o=join(this.cacheDir,t),r=readFileSync(o,"utf8"),n=JSON.parse(r),u=n.type==="execution_start"?"/api/telemetry/skill-execution/start":"/api/telemetry/tool-call";(await fetch(`${this.apiUrl}${u}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.apiKey},body:JSON.stringify(n.payload)})).ok&&unlinkSync(o);}catch{}}cacheEvent(e){try{existsSync(this.cacheDir)||mkdirSync(this.cacheDir,{recursive:!0});let t=join(this.cacheDir,`${Date.now()}_${Math.random().toString(36).slice(2,11)}.json`);writeFileSync(t,JSON.stringify(e,null,2)),this.scheduleRetry();}catch{}}scheduleRetry(){this.retryScheduled||(this.retryScheduled=true,setTimeout(()=>{this.retryScheduled=false,this.flushCache().catch(()=>{});},D).unref());}truncateInput(e){let t=JSON.stringify(e);return t.length<=g?e:{_truncated:true,_original_size:t.length,_preview:t.substring(0,g)+"..."}}};var p=class{constructor(e){this.projectRoot=e;}detect(){let e=join(this.projectRoot,".devflow","current-skill.json");if(!existsSync(e))return null;try{let t=readFileSync(e,"utf8");return JSON.parse(t)}catch{return null}}startExecution(e,t){let o=join(this.projectRoot,".devflow");existsSync(o)||mkdirSync(o,{recursive:true});let r=this.getCurrentExecutionId();if(r)return r;let n=`exec_${Date.now()}_${Math.random().toString(36).slice(2,11)}`;return writeFileSync(join(o,"current-execution-id"),n),writeFileSync(join(o,"current-skill.json"),JSON.stringify({name:e,required_mcp_tools:t?.required_mcp_tools??[]})),n}getCurrentExecutionId(){let e=join(this.projectRoot,".devflow","current-execution-id");if(!existsSync(e))return null;try{return readFileSync(e,"utf8").trim()}catch{return null}}endExecution(){let e=join(this.projectRoot,".devflow"),t=join(e,"current-skill.json"),o=join(e,"current-execution-id");try{existsSync(t)&&unlinkSync(t);}catch{}try{existsSync(o)&&unlinkSync(o);}catch{}}};async function P(i){try{if(!i||i.trim()==="")return {decision:"allow"};let e=JSON.parse(i),t=process.cwd(),o=new p(t),r=o.detect(),n=e.tool_name.startsWith("mcp__devflow__"),u=n?e.tool_name.replace("mcp__devflow__",""):void 0,d=r?.required_mcp_tools??[],h=d.length>0,y=h&&!n,a;y?a={decision:"block",reason:`Skill "${r?.name||"unknown"}" requires MCP tools. Use one of: ${d.join(", ")}`}:a={decision:"allow"};let S=o.getCurrentExecutionId()??`exec_orphan_${Date.now()}`,w=new l,x={eventId:`evt_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,executionId:S,timestamp:Date.now(),toolName:e.tool_name,toolType:n?"mcp":e.tool_name==="Agent"?"subagent":"direct",isMcpTool:n,mcpToolName:u,mcpEnforced:n&&h,mcpFallback:!n&&!h,input:e.tool_input,tokensUsed:0,duration:0,blocked:y,blockReason:y?a.reason:void 0};return w.sendEvent(x).catch(()=>{}),a}catch{return {decision:"allow"}}}if(process.argv[1]?.endsWith("pre-tool-use")||process.argv[1]?.endsWith("pre-tool-use.js")){let i="";process.stdin.setEncoding("utf8"),process.stdin.on("data",e=>{i+=e;}),process.stdin.on("end",async()=>{let e=await P(i);console.log(JSON.stringify(e));}),process.stdin.on("error",()=>{console.log(JSON.stringify({decision:"allow"})),process.exit(0);}),setTimeout(()=>{console.log(JSON.stringify({decision:"allow"})),process.exit(0);},4e3).unref();}
|
|
2
|
+
export{P as handlePreToolUse};
|
package/dist/plugin/hooks.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"PreToolUse": [
|
|
16
16
|
{
|
|
17
|
-
"matcher": "
|
|
17
|
+
"matcher": "*",
|
|
18
18
|
"hooks": [
|
|
19
19
|
{
|
|
20
20
|
"type": "command",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"PostToolUse": [
|
|
28
28
|
{
|
|
29
|
-
"matcher": "
|
|
29
|
+
"matcher": "*",
|
|
30
30
|
"hooks": [
|
|
31
31
|
{
|
|
32
32
|
"type": "command",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: devflow:react
|
|
3
3
|
description: React 18 专家能力 — Bug 诊断、组件重构、性能优化、Hooks 审查
|
|
4
|
+
required_mcp_tools:
|
|
5
|
+
- react_diagnose_bug
|
|
6
|
+
- react_new_feature
|
|
7
|
+
- react_audit_performance
|
|
8
|
+
- react_review_hooks
|
|
9
|
+
- react_refactor_component
|
|
10
|
+
- react_new_component
|
|
4
11
|
---
|
|
5
12
|
|
|
6
13
|
# ⚛️ REACT
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import'reflect-metadata';import {Reflector,APP_GUARD,APP_INTERCEPTOR,NestFactory}from'@nestjs/core';import {FastifyAdapter}from'@nestjs/platform-fastify';import {Injectable,Inject,Global,Module,Optional,Get,Query,Param,Post,Body,Delete,Controller,Headers,Res,Put,Catch,UnauthorizedException,NotFoundException,BadRequestException,SetMetadata,Logger,HttpException,HttpStatus}from'@nestjs/common';import {existsSync,readFileSync}from'fs';import {join}from'path';import {createEngines}from'@devflow-tools/context-engine';import {TelemetryEngine}from'@devflow-tools/telemetry';import {WorkflowEngine}from'@devflow-tools/workflow-engine';import {loadPlugins}from'@devflow-tools/sdk';import {Subject}from'rxjs';import {KnowledgeEngine}from'@devflow-tools/knowledge-engine';import {BenchmarkEngine}from'@devflow-tools/benchmark';import {DevFlowDatabase}from'@devflow-tools/database';import {map}from'rxjs/operators';var ye=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var o=(c,t,e,r)=>{for(var s=r>1?void 0:r?Re(t,e):t,n=c.length-1,a;n>=0;n--)(a=c[n])&&(s=(r?a(t,e,s):a(s))||s);return r&&s&&ye(t,e,s),s},i=(c,t)=>(e,r)=>t(e,r,c);var xt="isPublic",Jt=()=>SetMetadata(xt,true);var Et={MISSING_API_KEY:"AUTH_MISSING_API_KEY",INVALID_API_KEY:"AUTH_INVALID_API_KEY"};var Se=(process.env.DEVFLOW_API_KEYS??"dev-key-000000").split(",").map(c=>c.trim()).filter(Boolean),W=class{constructor(t){this.reflector=t;}canActivate(t){if(this.reflector.getAllAndOverride(xt,[t.getHandler(),t.getClass()]))return true;let s=t.switchToHttp().getRequest().headers["x-api-key"];if(!s)throw new UnauthorizedException({error:{code:Et.MISSING_API_KEY,message:"X-API-Key header is required",details:{}}});if(!Se.includes(s))throw new UnauthorizedException({error:{code:Et.INVALID_API_KEY,message:"Invalid API key",details:{}}});return true}};W=o([Injectable(),i(0,Inject(Reflector))],W);var X=class{};X=o([Global(),Module({providers:[W,{provide:APP_GUARD,useClass:W}]})],X);var f={WORKFLOW_NOT_FOUND:"WORKFLOW_NOT_FOUND",RUN_NOT_FOUND:"RUN_NOT_FOUND",MEMORY_KEY_NOT_FOUND:"MEMORY_KEY_NOT_FOUND",PROJECT_NOT_FOUND:"PROJECT_NOT_FOUND",NODE_NOT_FOUND:"NODE_NOT_FOUND",PLUGIN_NOT_FOUND:"PLUGIN_NOT_FOUND",INTERNAL_ERROR:"INTERNAL_ERROR"};var v=class{constructor(t){this.database=t;this.projects=new Map;this.activeProjectRoot=process.env.DEVFLOW_PROJECT_ROOT??null;}onModuleInit(){if(!process.env.DEVFLOW_PROJECT_ROOT&&this.database){let t=this.database.getSetting("activeProjectRoot");t&&(this.activeProjectRoot=t);}}setActiveProject(t){this.activeProjectRoot=t,this.database&&this.database.setSetting("activeProjectRoot",t);}disconnectProject(){this.activeProjectRoot=null,this.database&&this.database.deleteSetting("activeProjectRoot");}getActiveProjectRoot(){return this.activeProjectRoot}async list(){return Array.from(this.projects.values())}async getById(t){let e=this.projects.get(t);if(!e)throw new NotFoundException({error:{code:f.PROJECT_NOT_FOUND,message:`Project "${t}" not found`,details:{}}});return e}async create(t){let e=`proj_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,r={id:e,name:t.name,rootPath:t.rootPath,stack:t.stack,createdAt:Date.now()};return this.projects.set(e,r),this.activeProjectRoot||this.setActiveProject(t.rootPath),r}async delete(t){if(!this.projects.has(t))throw new NotFoundException({error:{code:f.PROJECT_NOT_FOUND,message:`Project "${t}" not found`,details:{}}});this.projects.delete(t);}async getOnboardingPack(t){let e=join(t,".devflow","onboarding-pack.json");if(!existsSync(e))throw new NotFoundException({error:{code:f.PROJECT_NOT_FOUND,message:"Onboarding pack not found. Run `devflow init` first.",details:{}}});return JSON.parse(readFileSync(e,"utf-8"))}async getOnboardingPackByRoot(t){let e=join(t,".devflow","onboarding-pack.json");try{return existsSync(e)?JSON.parse(readFileSync(e,"utf-8")):null}catch{return null}}};v=o([Injectable(),i(0,Optional()),i(0,Inject("DATABASE"))],v);var R=class{constructor(t){this.service=t;}async list(){return this.service.list()}async getOnboardingPackByRoot(t){if(!t)throw new BadRequestException("rootPath is required");return this.service.getOnboardingPackByRoot(t)}async getById(t){return this.service.getById(t)}async getOnboardingPack(t){let e=await this.service.getById(t);return this.service.getOnboardingPack(e.rootPath)}async create(t){return this.service.create(t)}async connect(t){return this.service.setActiveProject(t.rootPath),{rootPath:t.rootPath}}async switchProject(t){return this.service.setActiveProject(t.rootPath),{rootPath:t.rootPath}}async getActive(){return {rootPath:this.service.getActiveProjectRoot()}}async disconnect(){return this.service.disconnectProject(),{ok:true}}async delete(t){return this.service.delete(t)}};o([Get()],R.prototype,"list",1),o([Get("onboarding-pack"),i(0,Query("rootPath"))],R.prototype,"getOnboardingPackByRoot",1),o([Get(":id"),i(0,Param("id"))],R.prototype,"getById",1),o([Get(":id/onboarding-pack"),i(0,Param("id"))],R.prototype,"getOnboardingPack",1),o([Post(),i(0,Body())],R.prototype,"create",1),o([Post("connect"),i(0,Body())],R.prototype,"connect",1),o([Post("switch"),i(0,Body())],R.prototype,"switchProject",1),o([Get("active")],R.prototype,"getActive",1),o([Delete("active")],R.prototype,"disconnect",1),o([Delete(":id"),i(0,Param("id"))],R.prototype,"delete",1),R=o([Controller("projects"),i(0,Inject(v))],R);var P=class{};P=o([Module({controllers:[R],providers:[v],exports:[v]})],P);var S=class{constructor(){this.engine=new TelemetryEngine;}async recordEvent(t){await this.engine.recordEvent(t);}async listRuns(t,e,r){let s=Array.from(this.engine.runs.values()),n=s;return r&&(n=s.filter(a=>a.meta?.source===r)),n.slice(e,e+t).map(a=>({id:a.meta?.runId??"",agent:a.meta?.agent??"",mode:a.meta?.mode??"",source:a.meta?.source??"unknown",status:a.status,startedAt:a.startedAt,tokenUsed:a.tokenUsed}))}async getRun(t){let e=this.engine.runs.get(t);if(!e)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});return e}async getTimeline(t,e){return Array.from(this.engine.runs.values()).filter(s=>!(t&&s.startedAt<Number(t)||e&&s.startedAt>Number(e))).flatMap(s=>s.steps?.map(n=>({runId:s.meta?.runId,stepId:n.stepId,type:n.type,duration:n.duration,timestamp:n.timestamp}))??[])}async getRunEvents(t){return this.engine.listEvents(t)}async getRunStats(t){return this.engine.getRunStats(t)}async getFeedbackStats(t,e){let r=this.collectAllEvents(),s=e!=null?Date.now()-e*24*60*60*1e3:void 0,n=r.filter(d=>!(d.data?.toolName!=="context_feedback"||t&&d.data?.toolInput?.projectRoot!==t||s!=null&&(d.timestamp??0)<s)),a=n.length,u=n.filter(d=>d.data?.toolInput?.feedback==="hit").length,l=n.filter(d=>d.data?.toolInput?.feedback==="partial").length,g=n.filter(d=>d.data?.toolInput?.feedback==="miss").length;return {total:a,hits:u,partials:l,misses:g,hitRate:a>0?u/a:0,partialRate:a>0?l/a:0,missRate:a>0?g/a:0}}collectAllEvents(){let t=this.engine.events;if(!t)return [];let e=[];for(let r of t.values())Array.isArray(r)&&e.push(...r);return e}async getStats(t=7){let e=Array.from(this.engine.runs.values()),r=Date.now(),s=r-t*24*60*60*1e3,n=e.filter(p=>p.startedAt>=s),a={};for(let p of n){let y=new Date(p.startedAt).toISOString().slice(0,10);a[y]||(a[y]={runs:0,tokens:0}),a[y].runs++,a[y].tokens+=p.tokenUsed??0;}let u=0,l=0,g=0;for(let p of n){let y=this.engine.events.get(p.meta?.runId)??[];u+=p.tokenUsed??0,l+=y.filter(G=>G.kind==="llm_call").length,g+=y.filter(G=>G.kind==="tool_use").length;}let d=new Date(s).toISOString().slice(0,10),j=new Date(r).toISOString().slice(0,10);return {period:{from:d,to:j},summary:{totalRuns:n.length,completedRuns:n.filter(p=>p.status==="completed").length,failedRuns:n.filter(p=>p.status==="failed").length,totalTokens:u,totalLlmCalls:l,totalToolUses:g,avgRunDuration:n.length>0?Math.round(n.reduce((p,y)=>p+((y.finishedAt??r)-y.startedAt),0)/n.length):0},byDay:Object.entries(a).map(([p,y])=>({date:p,...y})).sort((p,y)=>p.date.localeCompare(y.date)),byWorkflow:this.buildWorkflowBreakdown(n,r),byPlugin:this.buildPluginBreakdown(n)}}buildWorkflowBreakdown(t,e){let r={};for(let s of t){let n=s.workflowName??s.meta?.workflowName??"unknown";r[n]||(r[n]={runs:0,completed:0,failed:0,avgDuration:0}),r[n].runs++,s.status==="completed"?r[n].completed++:r[n].failed++,r[n].avgDuration+=(s.finishedAt??e)-s.startedAt;}for(let s of Object.keys(r))r[s].avgDuration=r[s].runs>0?Math.round(r[s].avgDuration/r[s].runs):0;return Object.entries(r).map(([s,n])=>({name:s,runs:n.runs,successRate:n.runs>0?n.completed/n.runs:0,avgDuration:n.avgDuration}))}buildPluginBreakdown(t){let e={};for(let r of t){let s=r.pluginName??r.meta?.pluginName??"none";e[s]||(e[s]={runs:0,completed:0,failed:0}),e[s].runs++,r.status==="completed"?e[s].completed++:e[s].failed++;}return Object.entries(e).map(([r,s])=>({name:r,runs:s.runs,successRate:s.runs>0?s.completed/s.runs:0}))}async getOpsRoiSummary(){let t=Array.from(this.engine.runs.values()),e=Date.now(),r=t.length,s=t.filter(k=>k.status==="completed").length,n=r>0?s/r:0,a=t.reduce((k,Y)=>k+(Y.tokenUsed??0),0),u=r>0?a/r:0,l=t.reduce((k,Y)=>{let It=Y.startedAt??0,jt=Y.finishedAt??e;return k+(jt-It)},0),g=r>0?l/r:0,d=t.filter(k=>k.relevanceFeedback==="hit"||k.meta?.relevanceFeedback==="hit").length,j=t.filter(k=>k.relevanceFeedback!==void 0||k.meta?.relevanceFeedback!==void 0).length,p=await this.getFeedbackStats(),y=d+p.hits,G=j+p.total,Rt=G>0?y/G:0;return {period:"all-time",totalRuns:r,successfulRuns:s,successRate:n,avgTokenUsage:u,avgDuration:g,feedbackHitRate:Rt,trend:"stable"}}async getExperimentalRoiSummary(){return {totalScenarios:0,avgTimeSavedRate:0,avgTokenReductionRate:0,avgFirstPassLift:0,avgReworkReductionRate:0,conclusion:"No experimental data available yet"}}async getRoiSummary(t=7){let e=Array.from(this.engine.runs.values()),r=Date.now(),s=r-t*24*60*60*1e3,n=e.filter(m=>m.startedAt>=s),a=n.length,u=n.filter(m=>m.status==="completed").length,l=n.filter(m=>m.status!=="completed").length,g=a>0?Math.round(n.reduce((m,h)=>m+((h.finishedAt??r)-h.startedAt),0)/a):0,d=a>0?Math.round(n.reduce((m,h)=>m+(h.tokenUsed??0),0)/a):0,j=n.filter(m=>m.firstPassSuccess===true||m.meta?.firstPassSuccess===true).length,p=a>0?j/a:0,y=n.filter(m=>m.relevanceFeedback==="hit"||m.meta?.relevanceFeedback==="hit").length,G=n.filter(m=>m.relevanceFeedback!==void 0||m.meta?.relevanceFeedback!==void 0).length,Rt=await this.getFeedbackStats(void 0,t),k=y+Rt.hits,Y=G+Rt.total,It=Y>0?k/Y:0,jt=n.reduce((m,h)=>m+(h.retryCount??h.meta?.retryCount??0),0),he=a>0?jt/a:0,ve=g,dt={context_insufficient:0,knowledge_missing:0,workflow_design_issue:0,tool_error:0,agent_override:0,unknown:0};for(let m of n)if(m.status!=="completed"){let h=m.meta?.runId;if(h)try{let Wt=await this.engine.classifyFailure(h);dt[Wt]=(dt[Wt]??0)+1;}catch{dt.unknown++;}else dt.unknown++;}let z={};for(let m of n){let h=new Date(m.startedAt).toISOString().slice(0,10);z[h]||(z[h]={runs:0,tokens:0,failures:0}),z[h].runs++,z[h].tokens+=m.tokenUsed??0,m.status!=="completed"&&z[h].failures++;}return {period:{from:new Date(s).toISOString().slice(0,10),to:new Date(r).toISOString().slice(0,10)},overview:{totalRuns:a,completedRuns:u,failedRuns:l,avgDuration:g,avgTokens:d,firstPassSuccessRate:p,feedbackHitRate:It},efficiency:{totalTokensSaved:0,avgTimePerTask:ve,avgRetryCount:he},failures:{total:l,breakdown:dt},workflows:this.buildWorkflowBreakdown(n,r),plugins:this.buildPluginBreakdown(n),byDay:Object.entries(z).map(([m,h])=>({date:m,...h})).sort((m,h)=>m.date.localeCompare(h.date))}}async getPluginEffectiveness(t,e){await this.getPluginUsageStats(t);let n=Array.from(this.engine.runs.values()).filter(g=>!((g.pluginName??g.meta?.pluginName)!==t||e&&g.meta?.projectRoot!==e)),a=n.length,u=n.filter(g=>g.status==="completed").length,l=a>0?n.reduce((g,d)=>g+((d.finishedAt??Date.now())-d.startedAt),0)/a:0;return {name:t,installCount:1,activeRate:a>0?1:0,successRate:a>0?u/a:0,avgTokenImpact:-l*.1,lastUsedAt:n.length>0?new Date(Math.max(...n.map(g=>g.startedAt))).toISOString():void 0,recommendation:this.getRecommendation(a>0?u/a:0,a)}}async getPluginUsageStats(t){let r=Array.from(this.engine.runs.values()).filter(d=>(d.pluginName??d.meta?.pluginName)===t),s=r.length,n=r.filter(d=>d.status==="completed").length,a=new Set;for(let d of r){let j=d.meta?.projectRoot;j&&a.add(j);}let u=s>0?r.reduce((d,j)=>d+((j.finishedAt??Date.now())-j.startedAt),0)/s:0,l=r.map(d=>d.startedAt).filter(d=>typeof d=="number"),g=l.length>0?new Date(Math.max(...l)).toISOString():void 0;return {activeProjects:a.size,totalRuns:s,successfulRuns:n,avgTokenImpact:-u*.1,lastUsedAt:g}}getRecommendation(t,e){return e===0?"remove":t>.8?"install":t>.5?"optimize":"remove"}async classifyFailure(t){let e=await this.getRun(t).catch(()=>null);if(!e||e.status!=="failed")return {};let r=e.steps?.find(n=>n.status==="failed");if(!r)return {};let s=r.error?.toLowerCase()??"";return s.includes("context")||s.includes("insufficient")?{failureCategory:"context_insufficient",failureReason:"Context provided was insufficient for the task",suggestedActions:[{action:"Supplement task context",priority:"high"},{action:"View graph roots",priority:"medium"},{action:"Add related memory",priority:"medium"}]}:s.includes("knowledge")||s.includes("docs")?{failureCategory:"knowledge_missing",failureReason:"Required knowledge was not available",suggestedActions:[{action:"Sync knowledge source",priority:"high"},{action:"Add docs source",priority:"medium"}]}:s.includes("workflow")||s.includes("step")?{failureCategory:"workflow_design_issue",failureReason:"Workflow design issue detected",suggestedActions:[{action:"Adjust specific step",priority:"high"},{action:"Split workflow",priority:"medium"}]}:s.includes("tool")||s.includes("connection")?{failureCategory:"tool_error",failureReason:"Tool execution error",suggestedActions:[{action:"Check tool connectivity",priority:"high"},{action:"Retry or fallback",priority:"medium"}]}:{failureCategory:"agent_override",failureReason:"Agent override detected",suggestedActions:[{action:"Enable/strengthen enforcer",priority:"high"}]}}async cleanup(t){let e=this.engine.runs,r=Date.now()-t*24*60*60*1e3,s=0;for(let[n,a]of e)a.startedAt&&a.startedAt<r&&(e.delete(n),s++);return s}};S=o([Injectable()],S);var A=class{constructor(t,e){this.telemetryService=t;this.database=e;this.projectStats=new Map;this.benchmarkResults=[];}async recordTelemetryEvent(t){let e=`evt_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,r=t.toolName?"tool_use":"step_end",s={id:e,runId:t.metadata?.runId??`event_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,stepId:e,kind:r,timestamp:Date.now(),duration:t.durationMs,data:{toolName:t.toolName,toolInput:t.args,errorMessage:t.error},metadata:{source:"claude-code"}};return await this.telemetryService.recordEvent(s),{eventId:e}}async getProjectStats(t){return this.database?this.database.getProjectStats(t):this.projectStats.get(t)??null}async updateProjectStats(t,e){if(this.database){let a={...await this.getProjectStats(t)??{projectRoot:t,totalRuns:0,successfulRuns:0,totalTokens:0,lastActiveAt:Date.now(),topTools:[]},...e,lastActiveAt:Date.now()};return await this.database.upsertProjectStats(a),a}let s={...this.projectStats.get(t)??{projectRoot:t,totalRuns:0,successfulRuns:0,totalTokens:0,lastActiveAt:Date.now(),topTools:[]},...e,lastActiveAt:Date.now()};return this.projectStats.set(t,s),s}recordBenchmarkResult(t){this.benchmarkResults.push(t);}getBenchmarkResults(t){return t?this.benchmarkResults.filter(e=>this.projectStats.get(e.scenarioId)?.projectRoot===t):this.benchmarkResults}async getPluginEffectiveness(t){return []}};A=o([Injectable(),i(0,Inject(S)),i(1,Optional()),i(1,Inject("DATABASE"))],A);var D=class{constructor(t){this.dataService=t;this.feedbackEntries=[];}async indexProject(t){let{context:e,codegraph:r}=await createEngines(t);await e.index(t);let s=r.getStats();return {totalFiles:s.fileCount,totalSymbols:s.nodeCount,lastIndexTime:s.lastUpdated,indexing:r.isIndexing()}}async getStatus(t){try{let{codegraph:e}=await createEngines(t),r=e.getStats();return {totalFiles:r.fileCount,totalSymbols:r.nodeCount,lastIndexTime:r.lastUpdated,indexing:e.isIndexing()}}catch{return {totalFiles:0,totalSymbols:0,lastIndexTime:0,indexing:false}}}async buildContext(t,e,r,s){let{context:n}=await createEngines(t);return n.build({query:e,mode:r,maxTokens:s??8e3,includeGraph:r==="deep"})}async buildTaskContext(t,e,r,s){let{context:n}=await createEngines(t);return n.buildTaskContext(e,{mode:r,maxTokens:s??8e3})}async findSymbol(t,e){let{indexer:r}=await createEngines(t);return r.findSymbol(e)}async recordFeedback(t,e,r,s){let n={query:e,feedback:r,timestamp:Date.now(),projectRoot:t};return this.feedbackEntries.push(n),this.dataService&&await this.dataService.recordTelemetryEvent({toolName:"context_feedback",args:{query:e,feedback:r,taskType:s?.taskType,contextMode:s?.contextMode,projectRoot:t},durationMs:0,success:true,metadata:{projectRoot:t,query:e,taskType:s?.taskType}}),n}async getFeedbackSummaries(){let t=this.feedbackEntries.length,e=this.feedbackEntries.filter(n=>n.feedback==="hit").length,r=this.feedbackEntries.filter(n=>n.feedback==="partial").length,s=this.feedbackEntries.filter(n=>n.feedback==="miss").length;return {total:t,hits:e,partials:r,misses:s,hitRate:t>0?e/t:0}}};D=o([Injectable(),i(0,Optional()),i(0,Inject(A))],D);var I=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async status(t,e){return this.service.getStatus(this.resolveRootPath(t,e))}async index(t,e){return this.service.indexProject(this.resolveRootPath(t.rootPath,e))}async build(t,e){return this.service.buildContext(this.resolveRootPath(t.rootPath,e),t.query,t.mode??"fast",t.maxTokens)}async buildTask(t,e){return this.service.buildTaskContext(this.resolveRootPath(t.rootPath,e),t.query,t.mode??"fast",t.maxTokens)}async feedback(t,e){return this.service.recordFeedback(this.resolveRootPath(t.rootPath,e),t.query,t.feedback,{taskType:t.taskType,contextMode:t.contextMode,runId:t.runId,tokenCount:t.tokenCount})}async feedbackSummary(){return this.service.getFeedbackSummaries()}async findSymbol(t,e,r){return this.service.findSymbol(this.resolveRootPath(e,r),t)}};o([Get("status"),i(0,Query("rootPath")),i(1,Headers("x-devflow-project"))],I.prototype,"status",1),o([Post("index"),i(0,Body()),i(1,Headers("x-devflow-project"))],I.prototype,"index",1),o([Post("build"),i(0,Body()),i(1,Headers("x-devflow-project"))],I.prototype,"build",1),o([Post("build-task"),i(0,Body()),i(1,Headers("x-devflow-project"))],I.prototype,"buildTask",1),o([Post("feedback"),i(0,Body()),i(1,Headers("x-devflow-project"))],I.prototype,"feedback",1),o([Get("feedback-summary")],I.prototype,"feedbackSummary",1),o([Get("symbol/:name"),i(0,Param("name")),i(1,Query("rootPath")),i(2,Headers("x-devflow-project"))],I.prototype,"findSymbol",1),I=o([Controller("context"),i(0,Inject(D)),i(1,Inject(v))],I);var N=class{constructor(t){this.dataService=t;}async recordTelemetryEvent(t){return {success:true,...await this.dataService.recordTelemetryEvent(t)}}async getProjectStats(t){return this.dataService.getProjectStats(t)}async updateProjectStats(t){return this.dataService.updateProjectStats(t.projectRoot,t.stats)}recordBenchmarkResult(t){return this.dataService.recordBenchmarkResult(t),{success:true}}getBenchmarkResults(t){return this.dataService.getBenchmarkResults(t)}};o([Post("telemetry/event"),i(0,Body())],N.prototype,"recordTelemetryEvent",1),o([Get("project/stats"),i(0,Query("rootPath"))],N.prototype,"getProjectStats",1),o([Post("project/stats"),i(0,Body())],N.prototype,"updateProjectStats",1),o([Post("benchmark/result"),i(0,Body())],N.prototype,"recordBenchmarkResult",1),o([Get("benchmark/results"),i(0,Query("projectRoot"))],N.prototype,"getBenchmarkResults",1),N=o([Controller("data"),i(0,Inject(A))],N);var w=class{constructor(t){this.service=t;}async listRuns(t,e,r){return this.service.listRuns(Number(t)||20,Number(e)||0,r)}async getRun(t){let e=await this.service.getRun(t),r=await this.service.classifyFailure(t);return {...e,...r}}async getTimeline(t,e){return this.service.getTimeline(t,e)}async getRunEvents(t){return this.service.getRunEvents(t)}async getRunStats(t){return this.service.getRunStats(t)}async getStats(t){return this.service.getStats(Number(t)||7)}async getRoiSummary(t){return this.service.getRoiSummary(Number(t)||7)}async cleanup(t){return {ok:true,data:{removedRuns:await this.service.cleanup(t.olderThanDays??30)}}}};o([Get("runs"),i(0,Query("limit")),i(1,Query("offset")),i(2,Query("source"))],w.prototype,"listRuns",1),o([Get("runs/:id"),i(0,Param("id"))],w.prototype,"getRun",1),o([Get("timeline"),i(0,Query("from")),i(1,Query("to"))],w.prototype,"getTimeline",1),o([Get("runs/:runId/events"),i(0,Param("runId"))],w.prototype,"getRunEvents",1),o([Get("runs/:runId/stats"),i(0,Param("runId"))],w.prototype,"getRunStats",1),o([Get("stats"),i(0,Query("days"))],w.prototype,"getStats",1),o([Get("roi-summary"),i(0,Query("days"))],w.prototype,"getRoiSummary",1),o([Post("cleanup"),i(0,Body())],w.prototype,"cleanup",1),w=o([Controller("telemetry"),i(0,Inject(S))],w);var O=class{};O=o([Module({controllers:[w],providers:[S],exports:[S]})],O);var H=class{};H=o([Module({imports:[O],controllers:[N],providers:[A],exports:[A]})],H);var x=class{};x=o([Module({imports:[P,H],controllers:[I],providers:[D],exports:[D]})],x);var F=class{async getFullGraph(t){let{graph:e}=await createEngines(t);return e.export()}async getLayeredGraph(t){let{graph:e}=await createEngines(t);return e.getLayeredGraph()}async getNode(t,e){let{codegraph:r}=await createEngines(t),s=r.getNode(e);if(!s)throw new NotFoundException({error:{code:f.NODE_NOT_FOUND,message:`Node "${e}" not found`,details:{}}});return s}async expandNode(t,e,r,s){let{graph:n}=await createEngines(t),a=n.expand([e],{depth:r,direction:s});return {node:a.nodes.find(u=>u.id===e),subGraph:a}}};F=o([Injectable()],F);var M=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async getFullGraph(t,e,r){return e==="layered"?this.service.getLayeredGraph(this.resolveRootPath(t,r)):this.service.getFullGraph(this.resolveRootPath(t,r))}async getNode(t,e,r){return this.service.getNode(this.resolveRootPath(t,r),e)}async expandNode(t,e,r,s,n){return this.service.expandNode(this.resolveRootPath(t,n),e,Number(r)||2,s||"both")}};o([Get(),i(0,Query("rootPath")),i(1,Query("view")),i(2,Headers("x-devflow-project"))],M.prototype,"getFullGraph",1),o([Get(":nodeId"),i(0,Query("rootPath")),i(1,Param("nodeId")),i(2,Headers("x-devflow-project"))],M.prototype,"getNode",1),o([Get(":nodeId/expand"),i(0,Query("rootPath")),i(1,Param("nodeId")),i(2,Query("depth")),i(3,Query("direction")),i(4,Headers("x-devflow-project"))],M.prototype,"expandNode",1),M=o([Controller("graph"),i(0,Inject(F)),i(1,Inject(v))],M);var et=class{};et=o([Module({imports:[x,P],controllers:[M],providers:[F],exports:[F]})],et);var U=class{constructor(){this.engine=new WorkflowEngine;this.events=new Map;this.engineRunIds=new Map;}async onModuleInit(){try{let t=await loadPlugins(),e=Array.from(t.values());for(let s of e)for(let n of s.workflow?.templates??[])this.engine.register(n);let r=await this.engine.list();console.log(`[WorkflowService] Loaded ${e.length} plugins with ${r.length} workflows`);}catch(t){console.error("[WorkflowService] Failed to load plugins:",t);}}async list(){return this.engine.list()}async run(t,e){if(!(await this.engine.list()).find(a=>a.name===t))throw new NotFoundException({error:{code:f.WORKFLOW_NOT_FOUND,message:`Workflow "${t}" not found`,details:{}}});let s=`run_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,n=new Subject;return this.events.set(s,n),this.engine.run(t,e).then(a=>{this.engineRunIds.set(s,a.runId);let u=this.engine.getRun(a.runId);if(u){for(let l of u.steps)n.next({runId:s,stepId:l.stepId,status:l.status==="success"?"completed":l.status==="failed"?"failed":"started",output:l.output,error:l.error,timestamp:Date.now()});a.status!=="running"&&n.complete();}a.status==="running"&&this.engine.onEvent(a.runId,l=>{n.next({runId:s,stepId:l.stepId,status:l.type==="step-done"?"completed":l.type==="step-error"?"failed":"started",output:"output"in l?l.output:void 0,error:"error"in l?l.error:void 0,timestamp:Date.now()});});}).catch(a=>{n.next({runId:s,stepId:"engine",status:"failed",error:a.message,timestamp:Date.now()}),n.complete();}),{runId:s}}async listRuns(t,e){return (await this.engine.listRuns()).map(n=>({runId:Array.from(this.engineRunIds.entries()).find(([,u])=>u===n.runId)?.[0]??n.runId,workflowName:n.type,status:n.status,steps:n.steps.map(u=>({stepId:u.stepId,status:u.status,output:u.output,error:u.error,startedAt:0})),startedAt:n.startedAt,finishedAt:n.finishedAt})).slice(e,e+t)}async getRun(t){let e=this.engineRunIds.get(t)??t,r=this.engine.getRun(e);if(!r)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});return {runId:t,workflowName:r.type,status:r.status,steps:r.steps.map(s=>({stepId:s.stepId,status:s.status,output:s.output,error:s.error})),startedAt:r.startedAt,finishedAt:r.finishedAt}}streamRun(t){let e=this.events.get(t);if(!e)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});return e}async approveRun(t){let e=this.engineRunIds.get(t)??t,r=this.engine.getRun(e);if(!r)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});let s=r.steps.find(n=>n.status==="awaiting_approval");s&&await this.engine.approve(e,s.stepId);}async rejectRun(t,e){let r=this.engineRunIds.get(t)??t,s=this.engine.getRun(r);if(!s)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});let n=s.steps.find(a=>a.status==="awaiting_approval");n&&await this.engine.reject(r,n.stepId,e??"Rejected");}async getNextStep(t){if(!t){(await this.engine.list())[0];return null}let e=this.engineRunIds.get(t)??t,r=this.engine.getRun(e);return r?(Array.isArray(r.steps)?r.steps:[]).find(n=>n.status==="pending")??null:null}};U=o([Injectable()],U);var b=class{constructor(t){this.service=t;}async list(){return this.service.list()}async run(t,e){return this.service.run(t,e.input??{})}async listRuns(t,e){return this.service.listRuns(Number(t)||20,Number(e)||0)}async getRun(t){return this.service.getRun(t)}async stream(t,e){e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let s=this.service.streamRun(t).subscribe({next:n=>{e.raw.write(`event: step-${n.status}
|
|
1
|
+
import'reflect-metadata';import {Reflector,APP_GUARD,APP_INTERCEPTOR,NestFactory}from'@nestjs/core';import {FastifyAdapter}from'@nestjs/platform-fastify';import {Injectable,Inject,Global,Module,Optional,Get,Query,Param,Post,Body,Delete,Controller,Headers,Res,Put,Catch,UnauthorizedException,NotFoundException,BadRequestException,SetMetadata,Logger,HttpException,HttpStatus}from'@nestjs/common';import {existsSync,readFileSync}from'fs';import {join}from'path';import {createEngines}from'@devflow-tools/context-engine';import {TelemetryEngine}from'@devflow-tools/telemetry';import {WorkflowEngine}from'@devflow-tools/workflow-engine';import {loadPlugins}from'@devflow-tools/sdk';import {Subject}from'rxjs';import {KnowledgeEngine}from'@devflow-tools/knowledge-engine';import {BenchmarkEngine}from'@devflow-tools/benchmark';import {DevFlowDatabase}from'@devflow-tools/database';import {map}from'rxjs/operators';var be=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var i=(c,t,e,r)=>{for(var s=r>1?void 0:r?Pe(t,e):t,n=c.length-1,a;n>=0;n--)(a=c[n])&&(s=(r?a(t,e,s):a(s))||s);return r&&s&&be(t,e,s),s},o=(c,t)=>(e,r)=>t(e,r,c);var Tt="isPublic",Qt=()=>SetMetadata(Tt,true);var At={MISSING_API_KEY:"AUTH_MISSING_API_KEY",INVALID_API_KEY:"AUTH_INVALID_API_KEY"};var Ie=(process.env.DEVFLOW_API_KEYS??"dev-key-000000").split(",").map(c=>c.trim()).filter(Boolean),V=class{constructor(t){this.reflector=t;}canActivate(t){if(this.reflector.getAllAndOverride(Tt,[t.getHandler(),t.getClass()]))return true;let s=t.switchToHttp().getRequest().headers["x-api-key"];if(!s)throw new UnauthorizedException({error:{code:At.MISSING_API_KEY,message:"X-API-Key header is required",details:{}}});if(!Ie.includes(s))throw new UnauthorizedException({error:{code:At.INVALID_API_KEY,message:"Invalid API key",details:{}}});return true}};V=i([Injectable(),o(0,Inject(Reflector))],V);var X=class{};X=i([Global(),Module({providers:[V,{provide:APP_GUARD,useClass:V}]})],X);var f={WORKFLOW_NOT_FOUND:"WORKFLOW_NOT_FOUND",RUN_NOT_FOUND:"RUN_NOT_FOUND",MEMORY_KEY_NOT_FOUND:"MEMORY_KEY_NOT_FOUND",PROJECT_NOT_FOUND:"PROJECT_NOT_FOUND",NODE_NOT_FOUND:"NODE_NOT_FOUND",PLUGIN_NOT_FOUND:"PLUGIN_NOT_FOUND",INTERNAL_ERROR:"INTERNAL_ERROR"};var y=class{constructor(t){this.database=t;this.projects=new Map;this.activeProjectRoot=process.env.DEVFLOW_PROJECT_ROOT??null;}onModuleInit(){if(!process.env.DEVFLOW_PROJECT_ROOT&&this.database){let t=this.database.getSetting("activeProjectRoot");t&&(this.activeProjectRoot=t);}}setActiveProject(t){this.activeProjectRoot=t,this.database&&this.database.setSetting("activeProjectRoot",t);}disconnectProject(){this.activeProjectRoot=null,this.database&&this.database.deleteSetting("activeProjectRoot");}getActiveProjectRoot(){return this.activeProjectRoot}async list(){return Array.from(this.projects.values())}async getById(t){let e=this.projects.get(t);if(!e)throw new NotFoundException({error:{code:f.PROJECT_NOT_FOUND,message:`Project "${t}" not found`,details:{}}});return e}async create(t){let e=`proj_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,r={id:e,name:t.name,rootPath:t.rootPath,stack:t.stack,createdAt:Date.now()};return this.projects.set(e,r),this.activeProjectRoot||this.setActiveProject(t.rootPath),r}async delete(t){if(!this.projects.has(t))throw new NotFoundException({error:{code:f.PROJECT_NOT_FOUND,message:`Project "${t}" not found`,details:{}}});this.projects.delete(t);}async getOnboardingPack(t){let e=join(t,".devflow","onboarding-pack.json");if(!existsSync(e))throw new NotFoundException({error:{code:f.PROJECT_NOT_FOUND,message:"Onboarding pack not found. Run `devflow init` first.",details:{}}});return JSON.parse(readFileSync(e,"utf-8"))}async getOnboardingPackByRoot(t){let e=join(t,".devflow","onboarding-pack.json");try{return existsSync(e)?JSON.parse(readFileSync(e,"utf-8")):null}catch{return null}}};y=i([Injectable(),o(0,Optional()),o(0,Inject("DATABASE"))],y);var b=class{constructor(t){this.service=t;}async list(){return this.service.list()}async getOnboardingPackByRoot(t){if(!t)throw new BadRequestException("rootPath is required");return this.service.getOnboardingPackByRoot(t)}async getById(t){return this.service.getById(t)}async getOnboardingPack(t){let e=await this.service.getById(t);return this.service.getOnboardingPack(e.rootPath)}async create(t){return this.service.create(t)}async connect(t){return this.service.setActiveProject(t.rootPath),{rootPath:t.rootPath}}async switchProject(t){return this.service.setActiveProject(t.rootPath),{rootPath:t.rootPath}}async getActive(){return {rootPath:this.service.getActiveProjectRoot()}}async disconnect(){return this.service.disconnectProject(),{ok:true}}async delete(t){return this.service.delete(t)}};i([Get()],b.prototype,"list",1),i([Get("onboarding-pack"),o(0,Query("rootPath"))],b.prototype,"getOnboardingPackByRoot",1),i([Get(":id"),o(0,Param("id"))],b.prototype,"getById",1),i([Get(":id/onboarding-pack"),o(0,Param("id"))],b.prototype,"getOnboardingPack",1),i([Post(),o(0,Body())],b.prototype,"create",1),i([Post("connect"),o(0,Body())],b.prototype,"connect",1),i([Post("switch"),o(0,Body())],b.prototype,"switchProject",1),i([Get("active")],b.prototype,"getActive",1),i([Delete("active")],b.prototype,"disconnect",1),i([Delete(":id"),o(0,Param("id"))],b.prototype,"delete",1),b=i([Controller("projects"),o(0,Inject(y))],b);var P=class{};P=i([Module({controllers:[b],providers:[y],exports:[y]})],P);var S=class{constructor(t){this.engine=new TelemetryEngine;this.db=t??null;}async recordEvent(t){await this.engine.recordEvent(t);}async listRuns(t,e,r){let s=Array.from(this.engine.runs.values()),n=s;return r&&(n=s.filter(a=>a.meta?.source===r)),n.slice(e,e+t).map(a=>({id:a.meta?.runId??"",agent:a.meta?.agent??"",mode:a.meta?.mode??"",source:a.meta?.source??"unknown",status:a.status,startedAt:a.startedAt,tokenUsed:a.tokenUsed}))}async getRun(t){let e=this.engine.runs.get(t);if(!e)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});return e}async getTimeline(t,e){return Array.from(this.engine.runs.values()).filter(s=>!(t&&s.startedAt<Number(t)||e&&s.startedAt>Number(e))).flatMap(s=>s.steps?.map(n=>({runId:s.meta?.runId,stepId:n.stepId,type:n.type,duration:n.duration,timestamp:n.timestamp}))??[])}async getRunEvents(t){return this.engine.listEvents(t)}async getRunStats(t){return this.engine.getRunStats(t)}async getFeedbackStats(t,e){let r=this.collectAllEvents(),s=e!=null?Date.now()-e*24*60*60*1e3:void 0,n=r.filter(m=>!(m.data?.toolName!=="context_feedback"||t&&m.data?.toolInput?.projectRoot!==t||s!=null&&(m.timestamp??0)<s)),a=n.length,u=n.filter(m=>m.data?.toolInput?.feedback==="hit").length,l=n.filter(m=>m.data?.toolInput?.feedback==="partial").length,g=n.filter(m=>m.data?.toolInput?.feedback==="miss").length;return {total:a,hits:u,partials:l,misses:g,hitRate:a>0?u/a:0,partialRate:a>0?l/a:0,missRate:a>0?g/a:0}}collectAllEvents(){let t=this.engine.events;if(!t)return [];let e=[];for(let r of t.values())Array.isArray(r)&&e.push(...r);return e}async getStats(t=7){let e=Array.from(this.engine.runs.values()),r=Date.now(),s=r-t*24*60*60*1e3,n=e.filter(p=>p.startedAt>=s),a={};for(let p of n){let R=new Date(p.startedAt).toISOString().slice(0,10);a[R]||(a[R]={runs:0,tokens:0}),a[R].runs++,a[R].tokens+=p.tokenUsed??0;}let u=0,l=0,g=0;for(let p of n){let R=this.engine.events.get(p.meta?.runId)??[];u+=p.tokenUsed??0,l+=R.filter(K=>K.kind==="llm_call").length,g+=R.filter(K=>K.kind==="tool_use").length;}let m=new Date(s).toISOString().slice(0,10),I=new Date(r).toISOString().slice(0,10);return {period:{from:m,to:I},summary:{totalRuns:n.length,completedRuns:n.filter(p=>p.status==="completed").length,failedRuns:n.filter(p=>p.status==="failed").length,totalTokens:u,totalLlmCalls:l,totalToolUses:g,avgRunDuration:n.length>0?Math.round(n.reduce((p,R)=>p+((R.finishedAt??r)-R.startedAt),0)/n.length):0},byDay:Object.entries(a).map(([p,R])=>({date:p,...R})).sort((p,R)=>p.date.localeCompare(R.date)),byWorkflow:this.buildWorkflowBreakdown(n,r),byPlugin:this.buildPluginBreakdown(n)}}buildWorkflowBreakdown(t,e){let r={};for(let s of t){let n=s.workflowName??s.meta?.workflowName??"unknown";r[n]||(r[n]={runs:0,completed:0,failed:0,avgDuration:0}),r[n].runs++,s.status==="completed"?r[n].completed++:r[n].failed++,r[n].avgDuration+=(s.finishedAt??e)-s.startedAt;}for(let s of Object.keys(r))r[s].avgDuration=r[s].runs>0?Math.round(r[s].avgDuration/r[s].runs):0;return Object.entries(r).map(([s,n])=>({name:s,runs:n.runs,successRate:n.runs>0?n.completed/n.runs:0,avgDuration:n.avgDuration}))}buildPluginBreakdown(t){let e={};for(let r of t){let s=r.pluginName??r.meta?.pluginName??"none";e[s]||(e[s]={runs:0,completed:0,failed:0}),e[s].runs++,r.status==="completed"?e[s].completed++:e[s].failed++;}return Object.entries(e).map(([r,s])=>({name:r,runs:s.runs,successRate:s.runs>0?s.completed/s.runs:0}))}async getOpsRoiSummary(){let t=Array.from(this.engine.runs.values()),e=Date.now(),r=t.length,s=t.filter(k=>k.status==="completed").length,n=r>0?s/r:0,a=t.reduce((k,J)=>k+(J.tokenUsed??0),0),u=r>0?a/r:0,l=t.reduce((k,J)=>{let jt=J.startedAt??0,Nt=J.finishedAt??e;return k+(Nt-jt)},0),g=r>0?l/r:0,m=t.filter(k=>k.relevanceFeedback==="hit"||k.meta?.relevanceFeedback==="hit").length,I=t.filter(k=>k.relevanceFeedback!==void 0||k.meta?.relevanceFeedback!==void 0).length,p=await this.getFeedbackStats(),R=m+p.hits,K=I+p.total,Rt=K>0?R/K:0;return {period:"all-time",totalRuns:r,successfulRuns:s,successRate:n,avgTokenUsage:u,avgDuration:g,feedbackHitRate:Rt,trend:"stable"}}async getExperimentalRoiSummary(){return {totalScenarios:0,avgTimeSavedRate:0,avgTokenReductionRate:0,avgFirstPassLift:0,avgReworkReductionRate:0,conclusion:"No experimental data available yet"}}async getRoiSummary(t=7){let e=Array.from(this.engine.runs.values()),r=Date.now(),s=r-t*24*60*60*1e3,n=e.filter(d=>d.startedAt>=s),a=n.length,u=n.filter(d=>d.status==="completed").length,l=n.filter(d=>d.status!=="completed").length,g=a>0?Math.round(n.reduce((d,h)=>d+((h.finishedAt??r)-h.startedAt),0)/a):0,m=a>0?Math.round(n.reduce((d,h)=>d+(h.tokenUsed??0),0)/a):0,I=n.filter(d=>d.firstPassSuccess===true||d.meta?.firstPassSuccess===true).length,p=a>0?I/a:0,R=n.filter(d=>d.relevanceFeedback==="hit"||d.meta?.relevanceFeedback==="hit").length,K=n.filter(d=>d.relevanceFeedback!==void 0||d.meta?.relevanceFeedback!==void 0).length,Rt=await this.getFeedbackStats(void 0,t),k=R+Rt.hits,J=K+Rt.total,jt=J>0?k/J:0,Nt=n.reduce((d,h)=>d+(h.retryCount??h.meta?.retryCount??0),0),ye=a>0?Nt/a:0,Re=g,mt={context_insufficient:0,knowledge_missing:0,workflow_design_issue:0,tool_error:0,agent_override:0,unknown:0};for(let d of n)if(d.status!=="completed"){let h=d.meta?.runId;if(h)try{let Vt=await this.engine.classifyFailure(h);mt[Vt]=(mt[Vt]??0)+1;}catch{mt.unknown++;}else mt.unknown++;}let z={};for(let d of n){let h=new Date(d.startedAt).toISOString().slice(0,10);z[h]||(z[h]={runs:0,tokens:0,failures:0}),z[h].runs++,z[h].tokens+=d.tokenUsed??0,d.status!=="completed"&&z[h].failures++;}return {period:{from:new Date(s).toISOString().slice(0,10),to:new Date(r).toISOString().slice(0,10)},overview:{totalRuns:a,completedRuns:u,failedRuns:l,avgDuration:g,avgTokens:m,firstPassSuccessRate:p,feedbackHitRate:jt},efficiency:{totalTokensSaved:0,avgTimePerTask:Re,avgRetryCount:ye},failures:{total:l,breakdown:mt},workflows:this.buildWorkflowBreakdown(n,r),plugins:this.buildPluginBreakdown(n),byDay:Object.entries(z).map(([d,h])=>({date:d,...h})).sort((d,h)=>d.date.localeCompare(h.date))}}async getPluginEffectiveness(t,e){await this.getPluginUsageStats(t);let n=Array.from(this.engine.runs.values()).filter(g=>!((g.pluginName??g.meta?.pluginName)!==t||e&&g.meta?.projectRoot!==e)),a=n.length,u=n.filter(g=>g.status==="completed").length,l=a>0?n.reduce((g,m)=>g+((m.finishedAt??Date.now())-m.startedAt),0)/a:0;return {name:t,installCount:1,activeRate:a>0?1:0,successRate:a>0?u/a:0,avgTokenImpact:-l*.1,lastUsedAt:n.length>0?new Date(Math.max(...n.map(g=>g.startedAt))).toISOString():void 0,recommendation:this.getRecommendation(a>0?u/a:0,a)}}async getPluginUsageStats(t){let r=Array.from(this.engine.runs.values()).filter(m=>(m.pluginName??m.meta?.pluginName)===t),s=r.length,n=r.filter(m=>m.status==="completed").length,a=new Set;for(let m of r){let I=m.meta?.projectRoot;I&&a.add(I);}let u=s>0?r.reduce((m,I)=>m+((I.finishedAt??Date.now())-I.startedAt),0)/s:0,l=r.map(m=>m.startedAt).filter(m=>typeof m=="number"),g=l.length>0?new Date(Math.max(...l)).toISOString():void 0;return {activeProjects:a.size,totalRuns:s,successfulRuns:n,avgTokenImpact:-u*.1,lastUsedAt:g}}getRecommendation(t,e){return e===0?"remove":t>.8?"install":t>.5?"optimize":"remove"}async classifyFailure(t){let e=await this.getRun(t).catch(()=>null);if(!e||e.status!=="failed")return {};let r=e.steps?.find(n=>n.status==="failed");if(!r)return {};let s=r.error?.toLowerCase()??"";return s.includes("context")||s.includes("insufficient")?{failureCategory:"context_insufficient",failureReason:"Context provided was insufficient for the task",suggestedActions:[{action:"Supplement task context",priority:"high"},{action:"View graph roots",priority:"medium"},{action:"Add related memory",priority:"medium"}]}:s.includes("knowledge")||s.includes("docs")?{failureCategory:"knowledge_missing",failureReason:"Required knowledge was not available",suggestedActions:[{action:"Sync knowledge source",priority:"high"},{action:"Add docs source",priority:"medium"}]}:s.includes("workflow")||s.includes("step")?{failureCategory:"workflow_design_issue",failureReason:"Workflow design issue detected",suggestedActions:[{action:"Adjust specific step",priority:"high"},{action:"Split workflow",priority:"medium"}]}:s.includes("tool")||s.includes("connection")?{failureCategory:"tool_error",failureReason:"Tool execution error",suggestedActions:[{action:"Check tool connectivity",priority:"high"},{action:"Retry or fallback",priority:"medium"}]}:{failureCategory:"agent_override",failureReason:"Agent override detected",suggestedActions:[{action:"Enable/strengthen enforcer",priority:"high"}]}}async cleanup(t){let e=this.engine.runs,r=Date.now()-t*24*60*60*1e3,s=0;for(let[n,a]of e)a.startedAt&&a.startedAt<r&&(e.delete(n),s++);return s}async recordExecutionStart(t){this.db&&this.db.insertSkillExecution({executionId:t.executionId,skillName:t.skillName,startedAt:t.startedAt,status:"running"});}async recordToolCall(t){this.db&&this.db.insertToolCallEvent({eventId:t.eventId,executionId:t.executionId,timestamp:t.timestamp,toolName:t.toolName,toolType:t.toolType,isMcpTool:t.isMcpTool,mcpToolName:t.mcpToolName,mcpEnforced:t.mcpEnforced,mcpFallback:t.mcpFallback,input:t.input,tokensUsed:t.tokensUsed,duration:t.duration,parentToolCallId:t.parentToolCallId,subagentId:t.subagentId,error:t.error,blocked:t.blocked,blockReason:t.blockReason});}async recordExecutionComplete(t){this.db&&this.db.updateSkillExecution(t.executionId,{status:t.status,finishedAt:t.finishedAt,totalDuration:t.summary.totalDuration,totalTokens:t.summary.totalTokens,mcpComplianceRate:t.summary.mcpComplianceRate});}async getExecutions(t,e){return this.db?this.db.listSkillExecutions(t,e):[]}async getExecutionEvents(t){return this.db?this.db.listToolCallEvents(t):[]}async getMcpCompliance(){return this.db?this.db.getMcpCompliance():{overall:0,bySkill:{},missedTools:[]}}};S=i([Injectable(),o(0,Optional()),o(0,Inject("DATABASE"))],S);var N=class{constructor(t,e){this.telemetryService=t;this.database=e;this.projectStats=new Map;this.benchmarkResults=[];}async recordTelemetryEvent(t){let e=`evt_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,r=t.toolName?"tool_use":"step_end",s={id:e,runId:t.metadata?.runId??`event_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,stepId:e,kind:r,timestamp:Date.now(),duration:t.durationMs,data:{toolName:t.toolName,toolInput:t.args,errorMessage:t.error},metadata:{source:"claude-code"}};return await this.telemetryService.recordEvent(s),{eventId:e}}async getProjectStats(t){return this.database?this.database.getProjectStats(t):this.projectStats.get(t)??null}async updateProjectStats(t,e){if(this.database){let a={...await this.getProjectStats(t)??{projectRoot:t,totalRuns:0,successfulRuns:0,totalTokens:0,lastActiveAt:Date.now(),topTools:[]},...e,lastActiveAt:Date.now()};return await this.database.upsertProjectStats(a),a}let s={...this.projectStats.get(t)??{projectRoot:t,totalRuns:0,successfulRuns:0,totalTokens:0,lastActiveAt:Date.now(),topTools:[]},...e,lastActiveAt:Date.now()};return this.projectStats.set(t,s),s}recordBenchmarkResult(t){this.benchmarkResults.push(t);}getBenchmarkResults(t){return t?this.benchmarkResults.filter(e=>this.projectStats.get(e.scenarioId)?.projectRoot===t):this.benchmarkResults}async getPluginEffectiveness(t){return []}};N=i([Injectable(),o(0,Inject(S)),o(1,Optional()),o(1,Inject("DATABASE"))],N);var F=class{constructor(t){this.dataService=t;this.feedbackEntries=[];}async indexProject(t){let{context:e,codegraph:r}=await createEngines(t);await e.index(t);let s=r.getStats();return {totalFiles:s.fileCount,totalSymbols:s.nodeCount,lastIndexTime:s.lastUpdated,indexing:r.isIndexing()}}async getStatus(t){try{let{codegraph:e}=await createEngines(t),r=e.getStats();return {totalFiles:r.fileCount,totalSymbols:r.nodeCount,lastIndexTime:r.lastUpdated,indexing:e.isIndexing()}}catch{return {totalFiles:0,totalSymbols:0,lastIndexTime:0,indexing:false}}}async buildContext(t,e,r,s){let{context:n}=await createEngines(t);return n.build({query:e,mode:r,maxTokens:s??8e3,includeGraph:r==="deep"})}async buildTaskContext(t,e,r,s){let{context:n}=await createEngines(t);return n.buildTaskContext(e,{mode:r,maxTokens:s??8e3})}async findSymbol(t,e){let{indexer:r}=await createEngines(t);return r.findSymbol(e)}async recordFeedback(t,e,r,s){let n={query:e,feedback:r,timestamp:Date.now(),projectRoot:t};return this.feedbackEntries.push(n),this.dataService&&await this.dataService.recordTelemetryEvent({toolName:"context_feedback",args:{query:e,feedback:r,taskType:s?.taskType,contextMode:s?.contextMode,projectRoot:t},durationMs:0,success:true,metadata:{projectRoot:t,query:e,taskType:s?.taskType}}),n}async getFeedbackSummaries(){let t=this.feedbackEntries.length,e=this.feedbackEntries.filter(n=>n.feedback==="hit").length,r=this.feedbackEntries.filter(n=>n.feedback==="partial").length,s=this.feedbackEntries.filter(n=>n.feedback==="miss").length;return {total:t,hits:e,partials:r,misses:s,hitRate:t>0?e/t:0}}};F=i([Injectable(),o(0,Optional()),o(0,Inject(N))],F);var x=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async status(t,e){return this.service.getStatus(this.resolveRootPath(t,e))}async index(t,e){return this.service.indexProject(this.resolveRootPath(t.rootPath,e))}async build(t,e){return this.service.buildContext(this.resolveRootPath(t.rootPath,e),t.query,t.mode??"fast",t.maxTokens)}async buildTask(t,e){return this.service.buildTaskContext(this.resolveRootPath(t.rootPath,e),t.query,t.mode??"fast",t.maxTokens)}async feedback(t,e){return this.service.recordFeedback(this.resolveRootPath(t.rootPath,e),t.query,t.feedback,{taskType:t.taskType,contextMode:t.contextMode,runId:t.runId,tokenCount:t.tokenCount})}async feedbackSummary(){return this.service.getFeedbackSummaries()}async findSymbol(t,e,r){return this.service.findSymbol(this.resolveRootPath(e,r),t)}};i([Get("status"),o(0,Query("rootPath")),o(1,Headers("x-devflow-project"))],x.prototype,"status",1),i([Post("index"),o(0,Body()),o(1,Headers("x-devflow-project"))],x.prototype,"index",1),i([Post("build"),o(0,Body()),o(1,Headers("x-devflow-project"))],x.prototype,"build",1),i([Post("build-task"),o(0,Body()),o(1,Headers("x-devflow-project"))],x.prototype,"buildTask",1),i([Post("feedback"),o(0,Body()),o(1,Headers("x-devflow-project"))],x.prototype,"feedback",1),i([Get("feedback-summary")],x.prototype,"feedbackSummary",1),i([Get("symbol/:name"),o(0,Param("name")),o(1,Query("rootPath")),o(2,Headers("x-devflow-project"))],x.prototype,"findSymbol",1),x=i([Controller("context"),o(0,Inject(F)),o(1,Inject(y))],x);var T=class{constructor(t){this.dataService=t;}async recordTelemetryEvent(t){return {success:true,...await this.dataService.recordTelemetryEvent(t)}}async getProjectStats(t){return this.dataService.getProjectStats(t)}async updateProjectStats(t){return this.dataService.updateProjectStats(t.projectRoot,t.stats)}recordBenchmarkResult(t){return this.dataService.recordBenchmarkResult(t),{success:true}}getBenchmarkResults(t){return this.dataService.getBenchmarkResults(t)}};i([Post("telemetry/event"),o(0,Body())],T.prototype,"recordTelemetryEvent",1),i([Get("project/stats"),o(0,Query("rootPath"))],T.prototype,"getProjectStats",1),i([Post("project/stats"),o(0,Body())],T.prototype,"updateProjectStats",1),i([Post("benchmark/result"),o(0,Body())],T.prototype,"recordBenchmarkResult",1),i([Get("benchmark/results"),o(0,Query("projectRoot"))],T.prototype,"getBenchmarkResults",1),T=i([Controller("data"),o(0,Inject(N))],T);var v=class{constructor(t){this.service=t;}async listRuns(t,e,r){return this.service.listRuns(Number(t)||20,Number(e)||0,r)}async getRun(t){let e=await this.service.getRun(t),r=await this.service.classifyFailure(t);return {...e,...r}}async getTimeline(t,e){return this.service.getTimeline(t,e)}async getRunEvents(t){return this.service.getRunEvents(t)}async getRunStats(t){return this.service.getRunStats(t)}async getStats(t){return this.service.getStats(Number(t)||7)}async getRoiSummary(t){return this.service.getRoiSummary(Number(t)||7)}async cleanup(t){return {ok:true,data:{removedRuns:await this.service.cleanup(t.olderThanDays??30)}}}async startSkillExecution(t){return await this.service.recordExecutionStart(t),{executionId:t.executionId}}async recordToolCall(t){return await this.service.recordToolCall(t),{eventId:t.eventId}}async completeSkillExecution(t){return await this.service.recordExecutionComplete(t),{}}async getExecutions(t,e){return {data:await this.service.getExecutions(Number(t)||20,e)}}async getExecutionEvents(t){return {data:await this.service.getExecutionEvents(t)}}async getMcpCompliance(){return await this.service.getMcpCompliance()}};i([Get("runs"),o(0,Query("limit")),o(1,Query("offset")),o(2,Query("source"))],v.prototype,"listRuns",1),i([Get("runs/:id"),o(0,Param("id"))],v.prototype,"getRun",1),i([Get("timeline"),o(0,Query("from")),o(1,Query("to"))],v.prototype,"getTimeline",1),i([Get("runs/:runId/events"),o(0,Param("runId"))],v.prototype,"getRunEvents",1),i([Get("runs/:runId/stats"),o(0,Param("runId"))],v.prototype,"getRunStats",1),i([Get("stats"),o(0,Query("days"))],v.prototype,"getStats",1),i([Get("roi-summary"),o(0,Query("days"))],v.prototype,"getRoiSummary",1),i([Post("cleanup"),o(0,Body())],v.prototype,"cleanup",1),i([Post("skill-execution/start"),o(0,Body())],v.prototype,"startSkillExecution",1),i([Post("tool-call"),o(0,Body())],v.prototype,"recordToolCall",1),i([Post("skill-execution/complete"),o(0,Body())],v.prototype,"completeSkillExecution",1),i([Get("executions"),o(0,Query("limit")),o(1,Query("skillName"))],v.prototype,"getExecutions",1),i([Get("executions/:id/events"),o(0,Param("id"))],v.prototype,"getExecutionEvents",1),i([Get("mcp-compliance")],v.prototype,"getMcpCompliance",1),v=i([Controller("telemetry"),o(0,Inject(S))],v);var _=class{};_=i([Module({controllers:[v],providers:[S],exports:[S]})],_);var Y=class{};Y=i([Module({imports:[_],controllers:[T],providers:[N],exports:[N]})],Y);var E=class{};E=i([Module({imports:[P,Y],controllers:[x],providers:[F],exports:[F]})],E);var U=class{async getFullGraph(t){let{graph:e}=await createEngines(t);return e.export()}async getLayeredGraph(t){let{graph:e}=await createEngines(t);return e.getLayeredGraph()}async getNode(t,e){let{codegraph:r}=await createEngines(t),s=r.getNode(e);if(!s)throw new NotFoundException({error:{code:f.NODE_NOT_FOUND,message:`Node "${e}" not found`,details:{}}});return s}async expandNode(t,e,r,s){let{graph:n}=await createEngines(t),a=n.expand([e],{depth:r,direction:s});return {node:a.nodes.find(u=>u.id===e),subGraph:a}}};U=i([Injectable()],U);var C=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async getFullGraph(t,e,r){return e==="layered"?this.service.getLayeredGraph(this.resolveRootPath(t,r)):this.service.getFullGraph(this.resolveRootPath(t,r))}async getNode(t,e,r){return this.service.getNode(this.resolveRootPath(t,r),e)}async expandNode(t,e,r,s,n){return this.service.expandNode(this.resolveRootPath(t,n),e,Number(r)||2,s||"both")}};i([Get(),o(0,Query("rootPath")),o(1,Query("view")),o(2,Headers("x-devflow-project"))],C.prototype,"getFullGraph",1),i([Get(":nodeId"),o(0,Query("rootPath")),o(1,Param("nodeId")),o(2,Headers("x-devflow-project"))],C.prototype,"getNode",1),i([Get(":nodeId/expand"),o(0,Query("rootPath")),o(1,Param("nodeId")),o(2,Query("depth")),o(3,Query("direction")),o(4,Headers("x-devflow-project"))],C.prototype,"expandNode",1),C=i([Controller("graph"),o(0,Inject(U)),o(1,Inject(y))],C);var et=class{};et=i([Module({imports:[E,P],controllers:[C],providers:[U],exports:[U]})],et);var B=class{constructor(){this.engine=new WorkflowEngine;this.events=new Map;this.engineRunIds=new Map;}async onModuleInit(){try{let t=await loadPlugins(),e=Array.from(t.values());for(let s of e)for(let n of s.workflow?.templates??[])this.engine.register(n);let r=await this.engine.list();console.log(`[WorkflowService] Loaded ${e.length} plugins with ${r.length} workflows`);}catch(t){console.error("[WorkflowService] Failed to load plugins:",t);}}async list(){return this.engine.list()}async run(t,e){if(!(await this.engine.list()).find(a=>a.name===t))throw new NotFoundException({error:{code:f.WORKFLOW_NOT_FOUND,message:`Workflow "${t}" not found`,details:{}}});let s=`run_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,n=new Subject;return this.events.set(s,n),this.engine.run(t,e).then(a=>{this.engineRunIds.set(s,a.runId);let u=this.engine.getRun(a.runId);if(u){for(let l of u.steps)n.next({runId:s,stepId:l.stepId,status:l.status==="success"?"completed":l.status==="failed"?"failed":"started",output:l.output,error:l.error,timestamp:Date.now()});a.status!=="running"&&n.complete();}a.status==="running"&&this.engine.onEvent(a.runId,l=>{n.next({runId:s,stepId:l.stepId,status:l.type==="step-done"?"completed":l.type==="step-error"?"failed":"started",output:"output"in l?l.output:void 0,error:"error"in l?l.error:void 0,timestamp:Date.now()});});}).catch(a=>{n.next({runId:s,stepId:"engine",status:"failed",error:a.message,timestamp:Date.now()}),n.complete();}),{runId:s}}async listRuns(t,e){return (await this.engine.listRuns()).map(n=>({runId:Array.from(this.engineRunIds.entries()).find(([,u])=>u===n.runId)?.[0]??n.runId,workflowName:n.type,status:n.status,steps:n.steps.map(u=>({stepId:u.stepId,status:u.status,output:u.output,error:u.error,startedAt:0})),startedAt:n.startedAt,finishedAt:n.finishedAt})).slice(e,e+t)}async getRun(t){let e=this.engineRunIds.get(t)??t,r=this.engine.getRun(e);if(!r)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});return {runId:t,workflowName:r.type,status:r.status,steps:r.steps.map(s=>({stepId:s.stepId,status:s.status,output:s.output,error:s.error})),startedAt:r.startedAt,finishedAt:r.finishedAt}}streamRun(t){let e=this.events.get(t);if(!e)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});return e}async approveRun(t){let e=this.engineRunIds.get(t)??t,r=this.engine.getRun(e);if(!r)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});let s=r.steps.find(n=>n.status==="awaiting_approval");s&&await this.engine.approve(e,s.stepId);}async rejectRun(t,e){let r=this.engineRunIds.get(t)??t,s=this.engine.getRun(r);if(!s)throw new NotFoundException({error:{code:f.RUN_NOT_FOUND,message:`Run "${t}" not found`,details:{}}});let n=s.steps.find(a=>a.status==="awaiting_approval");n&&await this.engine.reject(r,n.stepId,e??"Rejected");}async getNextStep(t){if(!t){(await this.engine.list())[0];return null}let e=this.engineRunIds.get(t)??t,r=this.engine.getRun(e);return r?(Array.isArray(r.steps)?r.steps:[]).find(n=>n.status==="pending")??null:null}};B=i([Injectable()],B);var w=class{constructor(t){this.service=t;}async list(){return this.service.list()}async run(t,e){return this.service.run(t,e.input??{})}async listRuns(t,e){return this.service.listRuns(Number(t)||20,Number(e)||0)}async getRun(t){return this.service.getRun(t)}async stream(t,e){e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let s=this.service.streamRun(t).subscribe({next:n=>{e.raw.write(`event: step-${n.status}
|
|
2
2
|
data: ${JSON.stringify(n)}
|
|
3
3
|
|
|
4
4
|
`);},error:n=>{e.raw.write(`event: error
|
|
@@ -7,4 +7,4 @@ data: ${JSON.stringify({error:n.message})}
|
|
|
7
7
|
`),e.raw.end();},complete:()=>{e.raw.write(`event: done
|
|
8
8
|
data: {}
|
|
9
9
|
|
|
10
|
-
`),e.raw.end();}});e.raw.on("close",()=>s.unsubscribe());}async approve(t){return await this.service.approveRun(t),{approved:true}}async reject(t,e){return await this.service.rejectRun(t,e.reason),{rejected:true}}async nextStep(t){return this.service.getNextStep(t)}};o([Get()],b.prototype,"list",1),o([Post(":type/run"),i(0,Param("type")),i(1,Body())],b.prototype,"run",1),o([Get("runs"),i(0,Query("limit")),i(1,Query("offset"))],b.prototype,"listRuns",1),o([Get("runs/:id"),i(0,Param("id"))],b.prototype,"getRun",1),o([Get("runs/:id/stream"),i(0,Param("id")),i(1,Res())],b.prototype,"stream",1),o([Post("runs/:id/approve"),i(0,Param("id"))],b.prototype,"approve",1),o([Post("runs/:id/reject"),i(0,Param("id")),i(1,Body())],b.prototype,"reject",1),o([Get("next-step"),i(0,Query("runId"))],b.prototype,"nextStep",1),b=o([Controller("workflows"),i(0,Inject(U))],b);var rt=class{};rt=o([Module({controllers:[b],providers:[U],exports:[U]})],rt);var B=class{async getAll(t){let{memory:e}=await createEngines(t),r=await e.getProjectContext(),s=await e.getUserPreferences();return {project:{stack:r.stack,conventions:r.conventions,metadata:r.metadata},user:{preferences:s.preferences,stack:s.stack}}}async update(t,e,r,s){let{memory:n}=await createEngines(t);if(e==="user")await n.updateUserPreference(r,s);else if(e==="project"){let a=await n.getProjectContext();a.metadata[r]=s,await n.setProjectContext(a);}else throw new NotFoundException({error:{code:f.MEMORY_KEY_NOT_FOUND,message:`Layer "${e}" not found`,details:{}}})}async getCandidates(t){let{memory:e}=await createEngines(t);return e.getCandidates()}async approveCandidate(t,e){let{memory:r}=await createEngines(t);await r.approveCandidate(e);}async rejectCandidate(t,e){let{memory:r}=await createEngines(t);await r.rejectCandidate(e);}};B=o([Injectable()],B);var T=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async getAll(t,e){return this.service.getAll(this.resolveRootPath(t,e))}async update(t,e,r,s,n){return await this.service.update(this.resolveRootPath(t,n),e,r,s.value),{ok:true}}async getCandidates(t,e){return this.service.getCandidates(this.resolveRootPath(t,e))}async approve(t,e,r){return await this.service.approveCandidate(this.resolveRootPath(t,r),e),{approved:true}}async reject(t,e,r){return await this.service.rejectCandidate(this.resolveRootPath(t,r),e),{rejected:true}}};o([Get(),i(0,Query("rootPath")),i(1,Headers("x-devflow-project"))],T.prototype,"getAll",1),o([Put(":layer/:key"),i(0,Query("rootPath")),i(1,Param("layer")),i(2,Param("key")),i(3,Body()),i(4,Headers("x-devflow-project"))],T.prototype,"update",1),o([Get("candidates"),i(0,Query("rootPath")),i(1,Headers("x-devflow-project"))],T.prototype,"getCandidates",1),o([Post("candidates/:id/approve"),i(0,Query("rootPath")),i(1,Param("id")),i(2,Headers("x-devflow-project"))],T.prototype,"approve",1),o([Post("candidates/:id/reject"),i(0,Query("rootPath")),i(1,Param("id")),i(2,Headers("x-devflow-project"))],T.prototype,"reject",1),T=o([Controller("memory"),i(0,Inject(B)),i(1,Inject(v))],T);var st=class{};st=o([Module({imports:[x,P],controllers:[T],providers:[B],exports:[B]})],st);var L=class{constructor(t){this.projectsService=t;}getEngine(t){return new KnowledgeEngine({projectRoot:t})}async onModuleInit(){let t=this.projectsService.getActiveProjectRoot()??process.env.DEVFLOW_PROJECT_ROOT??process.cwd();try{let e=this.getEngine(t),r=await e.getSources(),s=Date.now()-10080*60*1e3;for(let n of r)(!n.lastSyncTime||n.lastSyncTime<s)&&await e.syncDocs(n.source.name);}catch{}}async search(t,e,r){return this.getEngine(t).search(e,{sources:r&&r!=="all"?[r]:void 0})}async sync(t,e){return this.getEngine(t).syncDocs(e??"")}async getSources(t){return this.getEngine(t).getSources()}};L=o([Injectable(),i(0,Inject(v))],L);var C=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async search(t,e,r,s){return this.service.search(this.resolveRootPath(t,s),e??"",r)}async sync(t,e){return this.service.sync(this.resolveRootPath(t.rootPath,e),t.pluginName)}async getSources(t,e){return {ok:true,data:await this.service.getSources(this.resolveRootPath(t,e))}}};o([Get("search"),i(0,Query("rootPath")),i(1,Query("q")),i(2,Query("scope")),i(3,Headers("x-devflow-project"))],C.prototype,"search",1),o([Post("sync"),i(0,Body()),i(1,Headers("x-devflow-project"))],C.prototype,"sync",1),o([Get("sources"),i(0,Query("rootPath")),i(1,Headers("x-devflow-project"))],C.prototype,"getSources",1),C=o([Controller("knowledge"),i(0,Inject(L)),i(1,Inject(v))],C);var nt=class{};nt=o([Module({imports:[x,P],controllers:[C],providers:[L],exports:[L]})],nt);var q=class{constructor(){this.results=[];this.scenarioIds=[];this.engine=new BenchmarkEngine,this.registerDefaultScenarios();}registerDefaultScenarios(){let t=[{id:"understand-codebase",category:"understand",desc:"\u7406\u89E3\u4EE3\u7801\u5E93\u67B6\u6784",expectedFiles:2},{id:"modify-component",category:"modify",desc:"\u4FEE\u6539 React \u7EC4\u4EF6",expectedFiles:1,expectedComponents:1},{id:"review-code",category:"review",desc:"\u4EE3\u7801\u5BA1\u67E5",expectedIssues:2}];for(let e of t)this.engine.registerScenario(e),this.scenarioIds.push(e.id);}async runScenarioSet(t){let e=async a=>({prepTimeMs:1e3+Math.random()*500,tokenCount:500+Math.floor(Math.random()*200),firstPassSuccess:Math.random()>.5,reworkCount:Math.floor(Math.random()*3),durationMs:5e3+Math.random()*3e3}),r=async a=>({prepTimeMs:500+Math.random()*300,tokenCount:300+Math.floor(Math.random()*100),firstPassSuccess:Math.random()>.2,reworkCount:Math.floor(Math.random()*2),durationMs:3e3+Math.random()*2e3}),s=t??this.scenarioIds,n=await this.engine.runScenarioBatch(s,e,r);return this.results=n,n}async getScenarioResults(){return this.results.length===0&&await this.runScenarioSet(),this.results}async getComparisonSummary(){let t=await this.getScenarioResults(),e=t.length;return {totalScenarios:e,avgTimeSavedRate:t.reduce((r,s)=>r+s.comparison.timeSavedRate,0)/e,avgTokenReductionRate:t.reduce((r,s)=>r+s.comparison.tokenReductionRate,0)/e,avgFirstPassLift:t.reduce((r,s)=>r+s.comparison.firstPassLift,0)/e,avgReworkReductionRate:t.reduce((r,s)=>r+s.comparison.reworkReductionRate,0)/e}}async getExperimentalRoiSummary(){let t=await this.getComparisonSummary();return {totalScenarios:t.totalScenarios,avgTimeSavedRate:t.avgTimeSavedRate,avgTokenReductionRate:t.avgTokenReductionRate,avgFirstPassLift:t.avgFirstPassLift,avgReworkReductionRate:t.avgReworkReductionRate,conclusion:"DevFlow shows significant improvement in all metrics"}}};q=o([Injectable()],q);var _=class{constructor(t){this.service=t;}async run(t){return this.service.runScenarioSet(t.scenarioIds)}async getResults(){return this.service.getScenarioResults()}async getComparisonSummary(){return this.service.getComparisonSummary()}async getExperimentalRoiSummary(){return this.service.getExperimentalRoiSummary()}};o([Post("run"),i(0,Body())],_.prototype,"run",1),o([Get("results")],_.prototype,"getResults",1),o([Get("summary")],_.prototype,"getComparisonSummary",1),o([Get("roi-summary")],_.prototype,"getExperimentalRoiSummary",1),_=o([Controller("benchmark"),i(0,Inject(q))],_);var ot=class{};ot=o([Module({controllers:[_],providers:[q],exports:[q]})],ot);var $=class{constructor(t){this.telemetryService=t;this.plugins=new Map;this.installRecords=[];}async list(t,e){let r=Array.from(this.plugins.values());if(t){let s=t.toLowerCase();r=r.filter(n=>n.name.toLowerCase().includes(s)||n.description.toLowerCase().includes(s));}return e&&(r=r.filter(s=>s.tags.includes(e))),r}async getByName(t){let e=this.plugins.get(t);if(!e)throw new NotFoundException({error:{code:f.PLUGIN_NOT_FOUND,message:`Plugin "${t}" not found`,details:{}}});return e}async publish(t){let e=t.npmPackage.replace(/^@devflow-tools\/plugin-/,""),r={name:e,npmPackage:t.npmPackage,version:t.version,description:t.description,tags:t.tags??[],createdAt:Date.now()};return this.plugins.set(e,r),r}async install(t,e){let r=t.startsWith("@devflow-tools/plugin-")?t:`@devflow-tools/plugin-${t}`,s=t.replace(/^@devflow-tools\/plugin-/,"");return this.plugins.set(s,{name:s,npmPackage:r,version:"0.1.0",description:"Installed plugin",tags:[],createdAt:Date.now()}),e&&await this.recordPluginInstall(s,e),{ok:true,name:s}}async uninstall(t,e){let r=t.replace(/^@devflow-tools\/plugin-/,"");return this.plugins.delete(r),e&&await this.recordPluginUninstall(r,e),{ok:true,name:r}}async recordPluginInstall(t,e){let r=this.installRecords.find(s=>s.pluginName===t&&s.projectRoot===e);r?r.uninstalledAt=void 0:this.installRecords.push({pluginName:t,projectRoot:e,installedAt:Date.now()});}async recordPluginUninstall(t,e){let r=this.installRecords.find(s=>s.pluginName===t&&s.projectRoot===e);r&&(r.uninstalledAt=Date.now());}async listInstalledProjects(t){return this.installRecords.filter(e=>e.pluginName===t&&!e.uninstalledAt).map(e=>e.projectRoot)}async buildPluginEffectiveness(t){let r=(await this.listInstalledProjects(t)).length,s=await this.telemetryService.getPluginUsageStats(t),n=r>0?s.activeProjects/r:0,a=s.totalRuns>0?s.successfulRuns/s.totalRuns:0,u="optimize";return n>.7&&a>.8?u="install":(n<.3||a<.5)&&(u="remove"),{name:t,installCount:r,usageCount:s.totalRuns,activeRate:n,successRate:a,avgTokenImpact:s.avgTokenImpact,lastUsedAt:s.lastUsedAt,recommendation:u}}async getPluginEffectiveness(t){let e=t?this.installRecords.filter(n=>n.projectRoot===t&&!n.uninstalledAt):this.installRecords.filter(n=>!n.uninstalledAt),r=[...new Set(e.map(n=>n.pluginName))],s=[];for(let n of r){let a=await this.buildPluginEffectiveness(n);s.push(a);}return s}};$=o([Injectable(),i(0,Inject(S))],$);var E=class{constructor(t){this.service=t;}async list(t,e){return this.service.list(t,e)}async getPluginEffectiveness(t){return this.service.getPluginEffectiveness(t)}async getByName(t){return this.service.getByName(t)}async publish(t){return this.service.publish(t)}async install(t,e){return this.service.install(t.name,t.rootPath??e)}async uninstall(t,e,r){return this.service.uninstall(t,e.rootPath??r)}};o([Get("plugins"),i(0,Query("search")),i(1,Query("tag"))],E.prototype,"list",1),o([Get("plugins/effectiveness"),i(0,Query("rootPath"))],E.prototype,"getPluginEffectiveness",1),o([Get("plugins/:name"),i(0,Param("name"))],E.prototype,"getByName",1),o([Post("plugins"),i(0,Body())],E.prototype,"publish",1),o([Post("plugins/install"),i(0,Body()),i(1,Headers("x-devflow-project"))],E.prototype,"install",1),o([Post("plugins/:name/uninstall"),i(0,Param("name")),i(1,Body()),i(2,Headers("x-devflow-project"))],E.prototype,"uninstall",1),E=o([Controller("registry"),i(0,Inject($))],E);var it=class{};it=o([Module({imports:[O],controllers:[E],providers:[$],exports:[$]})],it);var fe={provide:"DATABASE",useFactory:()=>{let c=process.cwd();return new DevFlowDatabase(c)}},at=class{};at=o([Global(),Module({providers:[fe],exports:[fe]})],at);var ct=class{intercept(t,e){return e.handle().pipe(map(r=>r&&typeof r=="object"&&"error"in r?r:{ok:true,data:r??null}))}};ct=o([Injectable()],ct);var Q=class{constructor(){this.startTime=Date.now();}health(){return {version:"0.2.3",uptime:Date.now()-this.startTime}}};o([Jt(),Get("health")],Q.prototype,"health",1),Q=o([Controller()],Q);var ut=class{};ut=o([Module({imports:[at,X,P,x,et,rt,st,nt,O,ot,it,H],controllers:[Q],providers:[{provide:APP_INTERCEPTOR,useClass:ct}]})],ut);var K=class{constructor(){this.logger=new Logger(K.name);}catch(t,e){let s=e.switchToHttp().getResponse();if(t instanceof HttpException){let n=t.getStatus(),a=t.getResponse();if(typeof a=="object"&&a!==null&&"error"in a){s.status(n).send(a);return}let u=typeof a=="string"?a:a.message??"Request failed";s.status(n).send({error:{code:f.INTERNAL_ERROR,message:u,details:{}}});return}this.logger.error("Unhandled exception",t instanceof Error?t.stack:String(t)),s.status(HttpStatus.INTERNAL_SERVER_ERROR).send({error:{code:f.INTERNAL_ERROR,message:"Internal server error",details:{}}});}};K=o([Catch()],K);async function ns(){let c=await NestFactory.create(ut,new FastifyAdapter);return c.setGlobalPrefix("api"),c.useGlobalFilters(new K),c.enableCors({origin:true,credentials:true}),await c.listen({port:13337,host:"0.0.0.0"}),c}(process.argv[1]?.endsWith("main.js")||process.argv[1]?.endsWith("main.ts"))&&ns();export{ns as bootstrap};
|
|
10
|
+
`),e.raw.end();}});e.raw.on("close",()=>s.unsubscribe());}async approve(t){return await this.service.approveRun(t),{approved:true}}async reject(t,e){return await this.service.rejectRun(t,e.reason),{rejected:true}}async nextStep(t){return this.service.getNextStep(t)}};i([Get()],w.prototype,"list",1),i([Post(":type/run"),o(0,Param("type")),o(1,Body())],w.prototype,"run",1),i([Get("runs"),o(0,Query("limit")),o(1,Query("offset"))],w.prototype,"listRuns",1),i([Get("runs/:id"),o(0,Param("id"))],w.prototype,"getRun",1),i([Get("runs/:id/stream"),o(0,Param("id")),o(1,Res())],w.prototype,"stream",1),i([Post("runs/:id/approve"),o(0,Param("id"))],w.prototype,"approve",1),i([Post("runs/:id/reject"),o(0,Param("id")),o(1,Body())],w.prototype,"reject",1),i([Get("next-step"),o(0,Query("runId"))],w.prototype,"nextStep",1),w=i([Controller("workflows"),o(0,Inject(B))],w);var rt=class{};rt=i([Module({controllers:[w],providers:[B],exports:[B]})],rt);var L=class{async getAll(t){let{memory:e}=await createEngines(t),r=await e.getProjectContext(),s=await e.getUserPreferences();return {project:{stack:r.stack,conventions:r.conventions,metadata:r.metadata},user:{preferences:s.preferences,stack:s.stack}}}async update(t,e,r,s){let{memory:n}=await createEngines(t);if(e==="user")await n.updateUserPreference(r,s);else if(e==="project"){let a=await n.getProjectContext();a.metadata[r]=s,await n.setProjectContext(a);}else throw new NotFoundException({error:{code:f.MEMORY_KEY_NOT_FOUND,message:`Layer "${e}" not found`,details:{}}})}async getCandidates(t){let{memory:e}=await createEngines(t);return e.getCandidates()}async approveCandidate(t,e){let{memory:r}=await createEngines(t);await r.approveCandidate(e);}async rejectCandidate(t,e){let{memory:r}=await createEngines(t);await r.rejectCandidate(e);}};L=i([Injectable()],L);var A=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async getAll(t,e){return this.service.getAll(this.resolveRootPath(t,e))}async update(t,e,r,s,n){return await this.service.update(this.resolveRootPath(t,n),e,r,s.value),{ok:true}}async getCandidates(t,e){return this.service.getCandidates(this.resolveRootPath(t,e))}async approve(t,e,r){return await this.service.approveCandidate(this.resolveRootPath(t,r),e),{approved:true}}async reject(t,e,r){return await this.service.rejectCandidate(this.resolveRootPath(t,r),e),{rejected:true}}};i([Get(),o(0,Query("rootPath")),o(1,Headers("x-devflow-project"))],A.prototype,"getAll",1),i([Put(":layer/:key"),o(0,Query("rootPath")),o(1,Param("layer")),o(2,Param("key")),o(3,Body()),o(4,Headers("x-devflow-project"))],A.prototype,"update",1),i([Get("candidates"),o(0,Query("rootPath")),o(1,Headers("x-devflow-project"))],A.prototype,"getCandidates",1),i([Post("candidates/:id/approve"),o(0,Query("rootPath")),o(1,Param("id")),o(2,Headers("x-devflow-project"))],A.prototype,"approve",1),i([Post("candidates/:id/reject"),o(0,Query("rootPath")),o(1,Param("id")),o(2,Headers("x-devflow-project"))],A.prototype,"reject",1),A=i([Controller("memory"),o(0,Inject(L)),o(1,Inject(y))],A);var st=class{};st=i([Module({imports:[E,P],controllers:[A],providers:[L],exports:[L]})],st);var q=class{constructor(t){this.projectsService=t;}getEngine(t){return new KnowledgeEngine({projectRoot:t})}async onModuleInit(){let t=this.projectsService.getActiveProjectRoot()??process.env.DEVFLOW_PROJECT_ROOT??process.cwd();try{let e=this.getEngine(t),r=await e.getSources(),s=Date.now()-10080*60*1e3;for(let n of r)(!n.lastSyncTime||n.lastSyncTime<s)&&await e.syncDocs(n.source.name);}catch{}}async search(t,e,r){return this.getEngine(t).search(e,{sources:r&&r!=="all"?[r]:void 0})}async sync(t,e){return this.getEngine(t).syncDocs(e??"")}async getSources(t){return this.getEngine(t).getSources()}};q=i([Injectable(),o(0,Inject(y))],q);var $=class{constructor(t,e){this.service=t;this.projects=e;}resolveRootPath(t,e){let r=t??e??this.projects.getActiveProjectRoot();if(!r)throw new BadRequestException("rootPath is required \u2014 no active project connected");return r}async search(t,e,r,s){return this.service.search(this.resolveRootPath(t,s),e??"",r)}async sync(t,e){return this.service.sync(this.resolveRootPath(t.rootPath,e),t.pluginName)}async getSources(t,e){return {ok:true,data:await this.service.getSources(this.resolveRootPath(t,e))}}};i([Get("search"),o(0,Query("rootPath")),o(1,Query("q")),o(2,Query("scope")),o(3,Headers("x-devflow-project"))],$.prototype,"search",1),i([Post("sync"),o(0,Body()),o(1,Headers("x-devflow-project"))],$.prototype,"sync",1),i([Get("sources"),o(0,Query("rootPath")),o(1,Headers("x-devflow-project"))],$.prototype,"getSources",1),$=i([Controller("knowledge"),o(0,Inject(q)),o(1,Inject(y))],$);var nt=class{};nt=i([Module({imports:[E,P],controllers:[$],providers:[q],exports:[q]})],nt);var G=class{constructor(){this.results=[];this.scenarioIds=[];this.engine=new BenchmarkEngine,this.registerDefaultScenarios();}registerDefaultScenarios(){let t=[{id:"understand-codebase",category:"understand",desc:"\u7406\u89E3\u4EE3\u7801\u5E93\u67B6\u6784",expectedFiles:2},{id:"modify-component",category:"modify",desc:"\u4FEE\u6539 React \u7EC4\u4EF6",expectedFiles:1,expectedComponents:1},{id:"review-code",category:"review",desc:"\u4EE3\u7801\u5BA1\u67E5",expectedIssues:2}];for(let e of t)this.engine.registerScenario(e),this.scenarioIds.push(e.id);}async runScenarioSet(t){let e=async a=>({prepTimeMs:1e3+Math.random()*500,tokenCount:500+Math.floor(Math.random()*200),firstPassSuccess:Math.random()>.5,reworkCount:Math.floor(Math.random()*3),durationMs:5e3+Math.random()*3e3}),r=async a=>({prepTimeMs:500+Math.random()*300,tokenCount:300+Math.floor(Math.random()*100),firstPassSuccess:Math.random()>.2,reworkCount:Math.floor(Math.random()*2),durationMs:3e3+Math.random()*2e3}),s=t??this.scenarioIds,n=await this.engine.runScenarioBatch(s,e,r);return this.results=n,n}async getScenarioResults(){return this.results.length===0&&await this.runScenarioSet(),this.results}async getComparisonSummary(){let t=await this.getScenarioResults(),e=t.length;return {totalScenarios:e,avgTimeSavedRate:t.reduce((r,s)=>r+s.comparison.timeSavedRate,0)/e,avgTokenReductionRate:t.reduce((r,s)=>r+s.comparison.tokenReductionRate,0)/e,avgFirstPassLift:t.reduce((r,s)=>r+s.comparison.firstPassLift,0)/e,avgReworkReductionRate:t.reduce((r,s)=>r+s.comparison.reworkReductionRate,0)/e}}async getExperimentalRoiSummary(){let t=await this.getComparisonSummary();return {totalScenarios:t.totalScenarios,avgTimeSavedRate:t.avgTimeSavedRate,avgTokenReductionRate:t.avgTokenReductionRate,avgFirstPassLift:t.avgFirstPassLift,avgReworkReductionRate:t.avgReworkReductionRate,conclusion:"DevFlow shows significant improvement in all metrics"}}};G=i([Injectable()],G);var D=class{constructor(t){this.service=t;}async run(t){return this.service.runScenarioSet(t.scenarioIds)}async getResults(){return this.service.getScenarioResults()}async getComparisonSummary(){return this.service.getComparisonSummary()}async getExperimentalRoiSummary(){return this.service.getExperimentalRoiSummary()}};i([Post("run"),o(0,Body())],D.prototype,"run",1),i([Get("results")],D.prototype,"getResults",1),i([Get("summary")],D.prototype,"getComparisonSummary",1),i([Get("roi-summary")],D.prototype,"getExperimentalRoiSummary",1),D=i([Controller("benchmark"),o(0,Inject(G))],D);var ot=class{};ot=i([Module({controllers:[D],providers:[G],exports:[G]})],ot);var H=class{constructor(t){this.telemetryService=t;this.plugins=new Map;this.installRecords=[];}async list(t,e){let r=Array.from(this.plugins.values());if(t){let s=t.toLowerCase();r=r.filter(n=>n.name.toLowerCase().includes(s)||n.description.toLowerCase().includes(s));}return e&&(r=r.filter(s=>s.tags.includes(e))),r}async getByName(t){let e=this.plugins.get(t);if(!e)throw new NotFoundException({error:{code:f.PLUGIN_NOT_FOUND,message:`Plugin "${t}" not found`,details:{}}});return e}async publish(t){let e=t.npmPackage.replace(/^@devflow-tools\/plugin-/,""),r={name:e,npmPackage:t.npmPackage,version:t.version,description:t.description,tags:t.tags??[],createdAt:Date.now()};return this.plugins.set(e,r),r}async install(t,e){let r=t.startsWith("@devflow-tools/plugin-")?t:`@devflow-tools/plugin-${t}`,s=t.replace(/^@devflow-tools\/plugin-/,"");return this.plugins.set(s,{name:s,npmPackage:r,version:"0.1.0",description:"Installed plugin",tags:[],createdAt:Date.now()}),e&&await this.recordPluginInstall(s,e),{ok:true,name:s}}async uninstall(t,e){let r=t.replace(/^@devflow-tools\/plugin-/,"");return this.plugins.delete(r),e&&await this.recordPluginUninstall(r,e),{ok:true,name:r}}async recordPluginInstall(t,e){let r=this.installRecords.find(s=>s.pluginName===t&&s.projectRoot===e);r?r.uninstalledAt=void 0:this.installRecords.push({pluginName:t,projectRoot:e,installedAt:Date.now()});}async recordPluginUninstall(t,e){let r=this.installRecords.find(s=>s.pluginName===t&&s.projectRoot===e);r&&(r.uninstalledAt=Date.now());}async listInstalledProjects(t){return this.installRecords.filter(e=>e.pluginName===t&&!e.uninstalledAt).map(e=>e.projectRoot)}async buildPluginEffectiveness(t){let r=(await this.listInstalledProjects(t)).length,s=await this.telemetryService.getPluginUsageStats(t),n=r>0?s.activeProjects/r:0,a=s.totalRuns>0?s.successfulRuns/s.totalRuns:0,u="optimize";return n>.7&&a>.8?u="install":(n<.3||a<.5)&&(u="remove"),{name:t,installCount:r,usageCount:s.totalRuns,activeRate:n,successRate:a,avgTokenImpact:s.avgTokenImpact,lastUsedAt:s.lastUsedAt,recommendation:u}}async getPluginEffectiveness(t){let e=t?this.installRecords.filter(n=>n.projectRoot===t&&!n.uninstalledAt):this.installRecords.filter(n=>!n.uninstalledAt),r=[...new Set(e.map(n=>n.pluginName))],s=[];for(let n of r){let a=await this.buildPluginEffectiveness(n);s.push(a);}return s}};H=i([Injectable(),o(0,Inject(S))],H);var j=class{constructor(t){this.service=t;}async list(t,e){return this.service.list(t,e)}async getPluginEffectiveness(t){return this.service.getPluginEffectiveness(t)}async getByName(t){return this.service.getByName(t)}async publish(t){return this.service.publish(t)}async install(t,e){return this.service.install(t.name,t.rootPath??e)}async uninstall(t,e,r){return this.service.uninstall(t,e.rootPath??r)}};i([Get("plugins"),o(0,Query("search")),o(1,Query("tag"))],j.prototype,"list",1),i([Get("plugins/effectiveness"),o(0,Query("rootPath"))],j.prototype,"getPluginEffectiveness",1),i([Get("plugins/:name"),o(0,Param("name"))],j.prototype,"getByName",1),i([Post("plugins"),o(0,Body())],j.prototype,"publish",1),i([Post("plugins/install"),o(0,Body()),o(1,Headers("x-devflow-project"))],j.prototype,"install",1),i([Post("plugins/:name/uninstall"),o(0,Param("name")),o(1,Body()),o(2,Headers("x-devflow-project"))],j.prototype,"uninstall",1),j=i([Controller("registry"),o(0,Inject(H))],j);var it=class{};it=i([Module({imports:[_],controllers:[j],providers:[H],exports:[H]})],it);var ve={provide:"DATABASE",useFactory:()=>{let c=process.cwd();return new DevFlowDatabase(c)}},at=class{};at=i([Global(),Module({providers:[ve],exports:[ve]})],at);var ct=class{intercept(t,e){return e.handle().pipe(map(r=>r&&typeof r=="object"&&"error"in r?r:{ok:true,data:r??null}))}};ct=i([Injectable()],ct);var Q=class{constructor(){this.startTime=Date.now();}health(){return {version:"0.2.3",uptime:Date.now()-this.startTime}}};i([Qt(),Get("health")],Q.prototype,"health",1),Q=i([Controller()],Q);var ut=class{};ut=i([Module({imports:[at,X,P,E,et,rt,st,nt,_,ot,it,Y],controllers:[Q],providers:[{provide:APP_INTERCEPTOR,useClass:ct}]})],ut);var W=class{constructor(){this.logger=new Logger(W.name);}catch(t,e){let s=e.switchToHttp().getResponse();if(t instanceof HttpException){let n=t.getStatus(),a=t.getResponse();if(typeof a=="object"&&a!==null&&"error"in a){s.status(n).send(a);return}let u=typeof a=="string"?a:a.message??"Request failed";s.status(n).send({error:{code:f.INTERNAL_ERROR,message:u,details:{}}});return}this.logger.error("Unhandled exception",t instanceof Error?t.stack:String(t)),s.status(HttpStatus.INTERNAL_SERVER_ERROR).send({error:{code:f.INTERNAL_ERROR,message:"Internal server error",details:{}}});}};W=i([Catch()],W);async function is(){let c=await NestFactory.create(ut,new FastifyAdapter);return c.setGlobalPrefix("api"),c.useGlobalFilters(new W),c.enableCors({origin:true,credentials:true}),await c.listen({port:13337,host:"0.0.0.0"}),c}(process.argv[1]?.endsWith("main.js")||process.argv[1]?.endsWith("main.ts"))&&is();export{is as bootstrap};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devflow-tools/devflow",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "DevFlow - Developer Intelligence Platform (Distribution Package)",
|
|
6
6
|
"bin": {
|
|
@@ -10,20 +10,21 @@
|
|
|
10
10
|
"build": "tsup",
|
|
11
11
|
"build:watch": "tsup --watch",
|
|
12
12
|
"clean": "rm -rf dist",
|
|
13
|
-
"postbuild": "cp ../../apps/server/public/fallback.html dist/fallback.html && npx tsx scripts/bundle-plugin.ts"
|
|
13
|
+
"postbuild": "cp ../../apps/server/public/fallback.html dist/fallback.html && npx tsx scripts/bundle-plugin.ts",
|
|
14
|
+
"postinstall": "node scripts/postinstall.js"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@colbymchenry/codegraph": "^1.1.1",
|
|
17
|
-
"@devflow-tools/adapters": "^0.7.
|
|
18
|
-
"@devflow-tools/benchmark": "^0.7.
|
|
19
|
-
"@devflow-tools/context-engine": "^0.7.
|
|
20
|
-
"@devflow-tools/database": "^0.7.
|
|
21
|
-
"@devflow-tools/knowledge-engine": "^0.7.
|
|
22
|
-
"@devflow-tools/mcp-server": "^0.7.
|
|
23
|
-
"@devflow-tools/memory-engine": "^0.7.
|
|
24
|
-
"@devflow-tools/sdk": "^0.7.
|
|
25
|
-
"@devflow-tools/telemetry": "^0.7.
|
|
26
|
-
"@devflow-tools/workflow-engine": "^0.7.
|
|
18
|
+
"@devflow-tools/adapters": "^0.7.5",
|
|
19
|
+
"@devflow-tools/benchmark": "^0.7.5",
|
|
20
|
+
"@devflow-tools/context-engine": "^0.7.5",
|
|
21
|
+
"@devflow-tools/database": "^0.7.5",
|
|
22
|
+
"@devflow-tools/knowledge-engine": "^0.7.5",
|
|
23
|
+
"@devflow-tools/mcp-server": "^0.7.5",
|
|
24
|
+
"@devflow-tools/memory-engine": "^0.7.5",
|
|
25
|
+
"@devflow-tools/sdk": "^0.7.5",
|
|
26
|
+
"@devflow-tools/telemetry": "^0.7.5",
|
|
27
|
+
"@devflow-tools/workflow-engine": "^0.7.5",
|
|
27
28
|
"@inquirer/prompts": "^7.10.1",
|
|
28
29
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
29
30
|
"@nestjs/common": "^10.4.0",
|
|
@@ -47,7 +48,8 @@
|
|
|
47
48
|
"files": [
|
|
48
49
|
"dist",
|
|
49
50
|
"bin",
|
|
50
|
-
"plugin-registry.json"
|
|
51
|
+
"plugin-registry.json",
|
|
52
|
+
"scripts/postinstall.js"
|
|
51
53
|
],
|
|
52
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "c9055f06bb1db49bef3c241f9223893711425e57"
|
|
53
55
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// packages/devflow/scripts/postinstall.js
|
|
2
|
+
//
|
|
3
|
+
// Auto-configures .claude/hooks.json in the consuming project so that Claude
|
|
4
|
+
// Code invokes the devflow PreToolUse hook on every tool call.
|
|
5
|
+
//
|
|
6
|
+
// This file is plain ESM JavaScript (not TypeScript) because it must run during
|
|
7
|
+
// `npm install` before any build step has compiled the package.
|
|
8
|
+
//
|
|
9
|
+
// If anything goes wrong we log a warning and exit 0 — we must never break a
|
|
10
|
+
// user's `npm install`.
|
|
11
|
+
|
|
12
|
+
import { writeFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
13
|
+
import { join, dirname } from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
|
|
16
|
+
const TAG = '[devflow]';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Walk up from CWD looking for a directory that contains both a package.json
|
|
20
|
+
* and a node_modules folder. That's the consumer's project root.
|
|
21
|
+
*/
|
|
22
|
+
function findProjectRoot() {
|
|
23
|
+
let dir = process.cwd();
|
|
24
|
+
for (let i = 0; i < 10; i++) {
|
|
25
|
+
const pkgJson = join(dir, 'package.json');
|
|
26
|
+
const nodeModules = join(dir, 'node_modules');
|
|
27
|
+
if (existsSync(pkgJson) && existsSync(nodeModules)) {
|
|
28
|
+
return dir;
|
|
29
|
+
}
|
|
30
|
+
const parent = dirname(dir);
|
|
31
|
+
if (parent === dir) break; // reached filesystem root
|
|
32
|
+
dir = parent;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the absolute path to the compiled hook handler that ships inside the
|
|
39
|
+
* devflow package (dist/hooks/pre-tool-use.js). We derive it from the location
|
|
40
|
+
* of this very script so it works regardless of how npm hoisted the package.
|
|
41
|
+
*/
|
|
42
|
+
function resolveHookHandlerPath() {
|
|
43
|
+
const thisFile = fileURLToPath(import.meta.url);
|
|
44
|
+
const packageDir = dirname(dirname(thisFile)); // scripts/ -> package root
|
|
45
|
+
return join(packageDir, 'dist', 'hooks', 'pre-tool-use.js');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function autoConfigure() {
|
|
49
|
+
try {
|
|
50
|
+
const projectRoot = findProjectRoot();
|
|
51
|
+
if (!projectRoot) {
|
|
52
|
+
log('No project root found, skipping auto-config');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const claudeDir = join(projectRoot, '.claude');
|
|
57
|
+
const hooksFile = join(claudeDir, 'hooks.json');
|
|
58
|
+
const hookHandlerPath = resolveHookHandlerPath();
|
|
59
|
+
|
|
60
|
+
// 1. Ensure .claude/ directory exists
|
|
61
|
+
if (!existsSync(claudeDir)) {
|
|
62
|
+
mkdirSync(claudeDir, { recursive: true });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 2. Read any existing hooks.json (merge, don't clobber)
|
|
66
|
+
let existingConfig = {};
|
|
67
|
+
if (existsSync(hooksFile)) {
|
|
68
|
+
try {
|
|
69
|
+
existingConfig = JSON.parse(readFileSync(hooksFile, 'utf8'));
|
|
70
|
+
} catch {
|
|
71
|
+
// Corrupt file — start fresh rather than crashing npm install
|
|
72
|
+
existingConfig = {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 3. Build the new PreToolUse entry
|
|
77
|
+
const newCommand = `node "${hookHandlerPath}"`;
|
|
78
|
+
const newEntry = {
|
|
79
|
+
matcher: '*',
|
|
80
|
+
hooks: [
|
|
81
|
+
{
|
|
82
|
+
type: 'command',
|
|
83
|
+
command: newCommand,
|
|
84
|
+
timeout: 5000,
|
|
85
|
+
fallback: 'allow',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// 4. Deduplicate — if an entry with the same command already exists, skip
|
|
91
|
+
const existingPreToolUse = existingConfig?.hooks?.PreToolUse ?? [];
|
|
92
|
+
const alreadyRegistered = existingPreToolUse.some(
|
|
93
|
+
(entry) =>
|
|
94
|
+
entry.hooks?.some((h) => h.command === newCommand),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const mergedPreToolUse = alreadyRegistered
|
|
98
|
+
? existingPreToolUse
|
|
99
|
+
: [...existingPreToolUse, newEntry];
|
|
100
|
+
|
|
101
|
+
const mergedConfig = {
|
|
102
|
+
...existingConfig,
|
|
103
|
+
hooks: {
|
|
104
|
+
...(existingConfig.hooks ?? {}),
|
|
105
|
+
PreToolUse: mergedPreToolUse,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// 5. Write the merged config
|
|
110
|
+
writeFileSync(hooksFile, JSON.stringify(mergedConfig, null, 2) + '\n');
|
|
111
|
+
log(`Hooks auto-configured at ${hooksFile}`);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
114
|
+
console.error(`${TAG} Auto-config warning: ${msg}`);
|
|
115
|
+
// Exit 0 — never break npm install
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function log(msg) {
|
|
120
|
+
console.log(`${TAG} ${msg}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
autoConfigure();
|