niumagents-cli 0.1.7 → 0.1.9
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/nium.js +727 -393
- package/package.json +1 -1
package/dist/nium.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var al=Object.defineProperty;var S=(o,e)=>()=>(o&&(e=o(o=0)),e);var j=(o,e)=>{for(var t in e)al(o,t,{get:e[t],enumerable:!0})};import{existsSync as ke,mkdirSync as Qt,copyFileSync as ui,writeFileSync as cl}from"fs";import{join as se,dirname as gi}from"path";import{fileURLToPath as ll}from"url";import oe from"chalk";function pi(){let o=[se(Zt,"..","..","examples"),se(Zt,"..","examples"),se(Zt,"examples"),se(Zt,"..","..","..","examples")];for(let e of o)if(ke(e))return gi(e);return se(Zt,"..")}function mi(){return vo||(vo=se(process.cwd(),".nium")),vo}function ul(){if(!To){let o=pi();To=se(o,"examples","config.example.json")}return To}function gl(){if(!bo){let o=pi();bo=se(o,"examples",".env.example")}return bo}function di(){let o=mi(),e=ul();try{if(!ke(o)){console.log(oe.blue("\u{1F527} \u521D\u59CB\u5316\u5DE5\u4F5C\u76EE\u5F55...")),Qt(o,{recursive:!0}),console.log(oe.green("\u2713 \u521B\u5EFA .nium \u76EE\u5F55"));let c=se(o,"config.json");ke(e)?(ui(e,c),console.log(oe.green("\u2713 \u590D\u5236 config.example.json \u5230 .nium/config.json")),console.log(oe.yellow(`
|
|
3
3
|
\u26A0\uFE0F \u8BF7\u7F16\u8F91 .nium/config.json \u6587\u4EF6\u914D\u7F6E API \u5BC6\u94A5\u548C\u6A21\u578B
|
|
4
|
-
`))):(console.log(
|
|
4
|
+
`))):(console.log(oe.yellow(`\u26A0\uFE0F \u672A\u627E\u5230 config.example.json: ${e}`)),cl(c,JSON.stringify({models:{defaultModel:{apiKey:"your-api-key-here",baseURL:"https://api.openai.com/v1",model:"gpt-4o",provider:"openai",maxToken:128e3},liteModel:{apiKey:"your-api-key-here",baseURL:"https://api.openai.com/v1",model:"gpt-3.5-turbo",provider:"openai",maxToken:16385}},mcpServers:[]},null,2)),console.log(oe.green("\u2713 \u521B\u5EFA\u9ED8\u8BA4\u7684 .nium/config.json \u6587\u4EF6")),console.log(oe.yellow(`
|
|
5
5
|
\u26A0\uFE0F \u8BF7\u7F16\u8F91 .nium/config.json \u6587\u4EF6\u914D\u7F6E API \u5BC6\u94A5\u548C\u6A21\u578B
|
|
6
|
-
`)))}let t=
|
|
7
|
-
`;
|
|
6
|
+
`)))}let t=se(o,"agents");ke(t)||(Qt(t,{recursive:!0}),console.log(oe.green("\u2713 \u521B\u5EFA .nium/agents \u76EE\u5F55")));let n=se(o,"docs");ke(n)||(Qt(n,{recursive:!0}),console.log(oe.green("\u2713 \u521B\u5EFA .nium/docs \u76EE\u5F55")));let r=se(o,"archives");ke(r)||(Qt(r,{recursive:!0}),console.log(oe.green("\u2713 \u521B\u5EFA .nium/archives \u76EE\u5F55")));let s=se(o,"logs");ke(s)||(Qt(s,{recursive:!0}),console.log(oe.green("\u2713 \u521B\u5EFA .nium/logs \u76EE\u5F55")));let i=gl(),a=se(o,".env");return ke(a)||(ke(i)?(ui(i,a),console.log(oe.green("\u2713 \u590D\u5236 examples/.env.example \u5230 .nium/.env"))):(console.log(oe.yellow(`\u26A0\uFE0F \u672A\u627E\u5230 .env.example: ${i}`)),console.log(oe.yellow(" \u5C06\u4F7F\u7528\u9ED8\u8BA4\u73AF\u5883\u53D8\u91CF\u914D\u7F6E")))),o}catch(t){console.log(oe.red(`\u274C \u521D\u59CB\u5316\u5DE5\u4F5C\u76EE\u5F55\u5931\u8D25: ${t.message}`)),process.exit(1)}}function le(o){return se(mi(),o)}var Zt,vo,bo,To,Le=S(()=>{Zt=typeof __dirname<"u"?__dirname:gi(ll(import.meta.url)),vo=null,bo=null,To=null});var ko,gr,Po=S(()=>{ko={level:"INFO",debugMode:!1,consoleOutput:!0,fileOutput:!0,enableTimestamp:!0,rotationStrategy:"daily",maxFileSize:10485760,maxFiles:30},gr={ERROR:0,WARN:1,INFO:2,SUCCESS:2,DEBUG:3,TRACE:4}});import gt from"chalk";var en,D,tn=S(()=>{en=class{colors;constructor(){this.colors={INFO:gt.blue,WARN:gt.yellow,ERROR:gt.red,SUCCESS:gt.green,DEBUG:gt.magenta,TRACE:gt.gray}}format(e){let t="";if(e.timestamp){let n=new Date(e.timestamp).toLocaleString("zh-CN");t+=`[${n}] `}return t+=`[${e.level.padEnd(7)}] ${e.message}`,e.context&&(t+=` ${JSON.stringify(e.context)}`),t}colorize(e,t){let n=this.colors[t];return n(e)}},D=new en});import{existsSync as pl,readFileSync as ml,appendFileSync as fi,writeFileSync as dl,createReadStream as fl}from"fs";import{createInterface as hl}from"readline";var pe,me,nn=S(()=>{pe=class{filePath;constructor(e){this.filePath=e}append(e){try{let t=JSON.stringify(e)+`
|
|
7
|
+
`;fi(this.filePath,t,"utf-8")}catch(t){throw new Error(`Failed to append to JSONL file: ${t.message}`)}}appendBatch(e){try{let t=e.map(n=>JSON.stringify(n)).join(`
|
|
8
8
|
`)+`
|
|
9
|
-
`;
|
|
10
|
-
`;
|
|
11
|
-
`).filter(c=>c.trim().length>0),
|
|
9
|
+
`;fi(this.filePath,t,"utf-8")}catch(t){throw new Error(`Failed to append batch to JSONL file: ${t.message}`)}}create(e){try{let t=JSON.stringify(e)+`
|
|
10
|
+
`;dl(this.filePath,t,"utf-8")}catch(t){throw new Error(`Failed to create JSONL file: ${t.message}`)}}getFilePath(){return this.filePath}},me=class{filePath;constructor(e){this.filePath=e}exists(){return pl(this.filePath)}readAllSync(e={}){if(!this.exists())return[];try{let n=ml(this.filePath,"utf-8").split(`
|
|
11
|
+
`).filter(c=>c.trim().length>0),r=[],s=e.startLine||0,i=e.limit?s+e.limit:n.length,a=n.slice(s,i);for(let c of a)try{let l=JSON.parse(c);(!e.filter||e.filter(l))&&r.push(l)}catch{console.warn(`Invalid JSON line in ${this.filePath}: ${c.substring(0,50)}...`)}return r}catch(t){throw new Error(`Failed to read JSONL file: ${t.message}`)}}async readStream(e,t={}){if(this.exists())return new Promise((n,r)=>{let s=fl(this.filePath,{encoding:"utf-8"}),i=hl({input:s,crlfDelay:1/0}),a=0,c=0,l=t.startLine||0,{limit:g}=t;i.on("line",async p=>{try{if(p.trim().length===0)return;if(a<l){a++;return}if(g&&c>=g){i.close();return}let u=JSON.parse(p);(!t.filter||t.filter(u))&&(await e(u,a),c++),a++}catch{console.warn(`Invalid JSON line at line ${a}: ${p.substring(0,50)}...`),a++}}),i.on("close",()=>{n()}),i.on("error",p=>{r(new Error(`Failed to read JSONL stream: ${p.message}`))})})}async count(){if(!this.exists())return 0;let e=0;return await this.readStream(()=>{e++}),e}getFilePath(){return this.filePath}}});import{existsSync as $o,mkdirSync as yl,renameSync as Cl,writeFileSync as hi}from"fs";import{join as rn}from"path";function pr(){return ne.initLogger()}function yi(o){ne.configureLogger(o)}function mr(o){ne.setDebugMode(o)}function Ci(o){ne.setLogLevel(o)}function Si(o){ne.setFormatter(o)}var on,ne,Eo=S(()=>{Le();nn();Po();tn();on=class{config;logsDir;currentLogPath;logDatePath;isInitialized=!1;formatter;constructor(){this.config={...ko},this.logsDir=le("logs"),this.currentLogPath=rn(this.logsDir,"current.jsonl"),this.logDatePath=rn(this.logsDir,".current_date"),this.formatter=D}getTodayDateString(){let e=new Date,t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${t}-${n}-${r}`}async getLogFileDate(){try{return $o(this.logDatePath)&&new me(this.logDatePath).readAllSync()[0]?.date||null}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(D.colorize(`\u8BFB\u53D6\u65E5\u5FD7\u6587\u4EF6\u65E5\u671F\u5931\u8D25: ${t}`,"ERROR")),null}}async archiveLogFile(e){try{let t=rn(this.logsDir,`${e}.jsonl`);if($o(t)){let r=new me(this.currentLogPath).readAllSync();await new pe(t).appendBatch(r),console.log(D.colorize(`\u2713 \u65E5\u5FD7\u5DF2\u8FFD\u52A0\u5230\u5F52\u6863\u6587\u4EF6: ${e}.jsonl`,"SUCCESS"))}else Cl(this.currentLogPath,t),console.log(D.colorize(`\u2713 \u65E5\u5FD7\u5DF2\u5F52\u6863: ${e}.jsonl`,"SUCCESS"))}catch(t){let n=t instanceof Error?t.message:String(t);console.error(D.colorize(`\u5F52\u6863\u65E5\u5FD7\u5931\u8D25: ${n}`,"ERROR"))}}async createNewLogFile(e){try{hi(this.currentLogPath,"","utf-8"),hi(this.logDatePath,JSON.stringify({date:e})+`
|
|
12
|
+
`,"utf-8");let t=new pe(this.currentLogPath),n={timestamp:new Date().toISOString(),level:"INFO",message:`\u65E5\u5FD7\u6587\u4EF6\u521B\u5EFA - \u65E5\u671F: ${e}`,date:e};await t.append(n)}catch(t){let n=t instanceof Error?t.message:String(t);console.error(D.colorize(`\u521B\u5EFA\u65E5\u5FD7\u6587\u4EF6\u5931\u8D25: ${n}`,"ERROR"))}}async initLogger(){try{$o(this.logsDir)||(yl(this.logsDir,{recursive:!0}),console.log(D.colorize("\u521B\u5EFA\u65E5\u5FD7\u76EE\u5F55: .nium/logs","DEBUG")));let e=this.getTodayDateString(),t=await this.getLogFileDate();(!t||t!==e)&&(t&&(console.log(D.colorize(`\u68C0\u6D4B\u5230\u65E7\u65E5\u5FD7\u6587\u4EF6 (${t})\uFF0C\u6B63\u5728\u5F52\u6863...`,"WARN")),await this.archiveLogFile(t)),await this.createNewLogFile(e),console.log(D.colorize(`\u2713 \u521B\u5EFA\u65B0\u65E5\u5FD7\u6587\u4EF6: ${e}`,"SUCCESS"))),this.isInitialized=!0}catch(e){let t=e instanceof Error?e.message:String(e);console.error(D.colorize(`\u521D\u59CB\u5316\u65E5\u5FD7\u7CFB\u7EDF\u5931\u8D25: ${t}`,"ERROR"))}}configureLogger(e){this.config={...this.config,...e},e.logDir&&(this.logsDir=e.logDir,this.currentLogPath=rn(this.logsDir,"current.jsonl"),this.logDatePath=rn(this.logsDir,".current_date")),e.formatter&&(this.formatter=e.formatter)}setFormatter(e){this.formatter=e}shouldLog(e){let t=this.config.debugMode?"DEBUG":this.config.level;return gr[e]<=gr[t]}extractSessionId(e){if(e&&typeof e=="object")return e.sessionId||e.id}hasContextLogMethod(e,t){return e&&typeof e[t]=="function"}async writeLog(e,t,n=null){try{if(!this.shouldLog(e))return;this.isInitialized||await this.initLogger();let r=typeof t=="string"?t:JSON.stringify(t),s=e.toLowerCase();if(this.hasContextLogMethod(n,s)){n[s](t);return}let i=new Date().toISOString(),a=this.getTodayDateString(),c={timestamp:i,level:e,message:r,sessionId:this.extractSessionId(n),date:a};if(this.config.consoleOutput){let l=this.formatter.format(c),g=this.formatter.colorize(l,e);console.log(g)}this.config.fileOutput&&await new pe(this.currentLogPath).append(c)}catch(r){let s=r instanceof Error?r.message:String(r);console.error(D.colorize(`\u5199\u5165\u65E5\u5FD7\u5931\u8D25: ${s}`,"ERROR"))}}setDebugMode(e){this.config.debugMode=e}setLogLevel(e){this.config.level=e}},ne=new on});import{join as xi}from"path";async function wi(o){try{let e=le("logs"),t=xi(e,"current.jsonl"),n=new me(t);return await n.exists()?await n.readAllSync({filter:o?.level?s=>s.level===o.level:void 0,limit:o?.limit}):[]}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(D.colorize(`\u8BFB\u53D6\u65E5\u5FD7\u5931\u8D25: ${t}`,"ERROR")),[]}}async function vi(o,e){try{let t=le("logs"),n=xi(t,`${o}.jsonl`),r=new me(n);return await r.exists()?await r.readAllSync({filter:e?.level?i=>i.level===e.level:void 0,limit:e?.limit}):[]}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(D.colorize(`\u8BFB\u53D6\u5F52\u6863\u65E5\u5FD7\u5931\u8D25: ${n}`,"ERROR")),[]}}function bi(o){return`[${new Date(o.timestamp).toLocaleString("zh-CN")}] [${o.level.padEnd(7)}] ${o.message}`}function Ti(o){let e={total:o.length,byLevel:{INFO:0,WARN:0,ERROR:0,SUCCESS:0,DEBUG:0,TRACE:0}};for(let t of o)t.level in e.byLevel&&e.byLevel[t.level]++;return e}var ki=S(()=>{Le();nn();tn()});async function Pi(o,e=null){await ne.writeLog("INFO",o,e)}async function $(o,e=null){await ne.writeLog("INFO",o,e)}async function $i(o,e=null){await ne.writeLog("SUCCESS",o,e)}async function Mo(o,e=null){await ne.writeLog("WARN",o,e)}async function H(o,e=null){await Mo(o,e)}async function K(o,e=null){await ne.writeLog("ERROR",o,e)}async function C(o,e=null){await ne.writeLog("DEBUG",o,e)}async function Ei(o,e=null){await ne.writeLog("TRACE",o,e)}function J(o,e=null){Pi(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function Be(o,e=null){$(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function sn(o,e=null){$i(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function pt(o,e=null){Mo(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function Io(o,e=null){H(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function de(o,e=null){K(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function Z(o,e=null){C(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}function Sl(o,e=null){Ei(o,e).catch(t=>console.error(D.colorize(`\u65E5\u5FD7\u5199\u5165\u5931\u8D25: ${t}`,"ERROR")))}var Mi=S(()=>{Eo();tn()});var Ao={};j(Ao,{ChalkFormatter:()=>en,DEFAULT_CONFIG:()=>ko,LOG_LEVEL_PRIORITIES:()=>gr,LoggerManager:()=>on,configureLogger:()=>yi,default:()=>ne,defaultFormatter:()=>D,formatLogEntry:()=>bi,getLogStats:()=>Ti,initLogger:()=>pr,log:()=>Pi,logDebug:()=>C,logDebugSync:()=>Z,logError:()=>K,logErrorSync:()=>de,logInfo:()=>$,logInfoSync:()=>Be,logSuccess:()=>$i,logSuccessSync:()=>sn,logSync:()=>J,logTrace:()=>Ei,logTraceSync:()=>Sl,logWarn:()=>H,logWarnSync:()=>Io,logWarning:()=>Mo,logWarningSync:()=>pt,loggerManager:()=>ne,readArchivedLogs:()=>vi,readCurrentLogs:()=>wi,setDebugMode:()=>mr,setFormatter:()=>Si,setLogLevel:()=>Ci});var Y=S(()=>{Po();tn();Eo();ki();Mi()});import{existsSync as Ii,mkdirSync as xl,readdirSync as wl}from"fs";import{join as Ai}from"path";function Li(){Ii(mt)||xl(mt,{recursive:!0})}function Ri(o){if(!o||!o.messages||o.messages.length===0)return null;Li();let e=new Date().toISOString().replace(/[:.]/g,"-"),t=o.sessionId?o.sessionId.substring(0,8):"unknown",n=o.currentTask?o.currentTask.substring(0,30).replace(/[^\w\u4e00-\u9fa5]/g,"_"):"unnamed",r=`session_${t}_${e}_${n}.jsonl`,s=Ai(mt,r),i={type:"session_metadata",data:{sessionId:o.sessionId,currentTask:o.currentTask,createdAt:o.createdAt,archivedAt:new Date().toISOString(),messageCount:o.messages.length,taskCount:o.tasks?o.tasks.length:0}};try{let a=new pe(s);if(a.create(i),o.tasks&&o.tasks.length>0){let c={type:"tasks_data",data:o.tasks};a.append(c)}o.messages&&o.messages.length>0&&o.messages.map(l=>({...l,id:l.id||`msg_${Date.now()}_${Math.random().toString(36).substr(2,9)}`})).forEach(l=>{a.append({type:"message",data:l})})}catch(a){return console.error("\u5F52\u6863\u4F1A\u8BDD\u5931\u8D25:",a),null}return s}function vl(){return Li(),Ii(mt)?wl(mt).filter(e=>e.endsWith(".jsonl")).map(e=>{let t=Ai(mt,e);try{let r=new me(t).readAllSync({limit:1})[0];return!r||r.type!=="session_metadata"?null:{fileName:e,filePath:t,sessionId:r.data.sessionId,sessionIdShort:r.data.sessionId?r.data.sessionId.substring(0,8):"unknown",currentTask:r.data.currentTask||"\u672A\u547D\u540D\u4EFB\u52A1",timestamp:r.data.archivedAt,archivedAt:r.data.archivedAt,messageCount:r.data.messageCount||0,taskCount:r.data.taskCount||0}}catch(n){return console.error(`\u8BFB\u53D6\u5F52\u6863\u6587\u4EF6\u5931\u8D25: ${e}`,n),null}}).filter(e=>e!==null).sort((e,t)=>new Date(t.archivedAt).getTime()-new Date(e.archivedAt).getTime()):[]}function Di(){let o=vl();if(o.length===0)return"\u6682\u65E0\u5F52\u6863\u4F1A\u8BDD";let e=`
|
|
12
13
|
=== \u5F52\u6863\u4F1A\u8BDD\u5217\u8868 ===
|
|
13
14
|
|
|
14
|
-
`;return
|
|
15
|
+
`;return o.forEach((t,n)=>{let s=new Date(t.archivedAt).toLocaleString("zh-CN");e+=`[${n+1}] ${t.currentTask}
|
|
15
16
|
`,e+=` \u4F1A\u8BDDID: ${t.sessionIdShort||"unknown"}
|
|
16
17
|
`,e+=` \u5F52\u6863\u65F6\u95F4: ${s}
|
|
17
18
|
`,e+=` \u4EFB\u52A1\u6570\u91CF: ${t.taskCount||0}
|
|
18
19
|
`,e+=` \u6D88\u606F\u6570\u91CF: ${t.messageCount}
|
|
19
20
|
`,e+=` \u6587\u4EF6\u540D: ${t.fileName}
|
|
20
21
|
|
|
21
|
-
`}),e}var
|
|
22
|
-
\u2705 \u4EFB\u52A1\u5B8C\u6210: ${v.currentTask}`)),console.log(
|
|
22
|
+
`}),e}var mt,Lo=S(()=>{Le();nn();mt=le("archives")});function qe(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){let e=Math.random()*16|0;return(o==="x"?e:e&3|8).toString(16)})}function Ro(){return"S"+qe()}function dr(){return"T"+qe()}var fr=S(()=>{});var ji={};j(ji,{SESSION_FILE:()=>Re,archiveSession:()=>Ke,associateMessageWithTask:()=>Fi,completeCurrentTask:()=>ht,loadSession:()=>Oo,saveSession:()=>ie,sessionState:()=>v,setCurrentTaskId:()=>ft,startNewTask:()=>hr});import{writeFileSync as bl,existsSync as Oi}from"fs";import dt from"chalk";function Do(){return{sessionId:Ro(),messages:[],tasks:[],currentTask:null,currentTaskId:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}function Tl(){try{v.messages&&v.messages.length>0&&Ri(v)&&C("\u4F1A\u8BDD\u5DF2\u5F52\u6863"),v=Do(),new pe(Re).create(v)}catch(o){let e=o instanceof Error?o.message:String(o);console.log(dt.yellow(`Warning: Failed to archive session - ${e}`)),v=Do();try{new pe(Re).create(v)}catch{}}}function Oo(){try{if(Oi(Re)){let e=new me(Re).readAllSync(),t=e.length>0?e[0]:null;return v={sessionId:t&&t.sessionId||Ro(),messages:t&&t.messages||[],tasks:t&&t.tasks||[],currentTask:t&&t.currentTask||null,currentTaskId:t&&t.currentTaskId||null,createdAt:t&&t.createdAt||new Date().toISOString(),updatedAt:new Date().toISOString()},!0}}catch(o){let e=o instanceof Error?o.message:String(o);console.log(dt.yellow(`Warning: Could not load session - ${e}`))}return!1}function hr(o){let e=dr(),t={id:e,description:o,createdAt:new Date().toISOString(),messageIds:[]};return v.tasks.push(t),v.currentTask=o,v.currentTaskId=e,e}function Fi(o){if(v.currentTaskId&&o){let e=v.currentTaskId;o.taskId=e;let t=v.tasks.find(n=>n.id===e);if(t&&!o.id){let n=qe();o.id=n,t.messageIds.push(n)}}return o}function ft(o){v.currentTaskId=o,v.updatedAt=new Date().toISOString(),ie(),console.log(dt.blue(`[\u4F1A\u8BDD\u7BA1\u7406] \u5F53\u524D\u4EFB\u52A1ID\u5DF2\u8BBE\u7F6E\u4E3A: ${o}`))}function ie(o,e=null){try{if(e&&e!==v.currentTask&&hr(e),o){let n=o.map(r=>Fi({...r}));v={...v,messages:n,updatedAt:new Date().toISOString()}}else v={...v,updatedAt:new Date().toISOString()};Oi(Re)&&bl(Re,"","utf-8"),new pe(Re).create(v)}catch(t){let n=t instanceof Error?t.message:String(t);console.log(dt.yellow(`Warning: Could not save session - ${n}`))}}function Ke(){return Tl()}function kl(){if(v.currentTask&&v.currentTaskId){let o=v.tasks.find(e=>e.id===v.currentTaskId);if(o){let e=o.tokenCount||0;console.log(dt.green(`
|
|
23
|
+
\u2705 \u4EFB\u52A1\u5B8C\u6210: ${v.currentTask}`)),console.log(dt.blue(`\u{1F4CA} Token\u603B\u5F00\u9500: ${e.toLocaleString()} tokens`))}v.currentTask=null,v.currentTaskId=null,ie()}}function ht(){return kl()}var Re,v,De=S(()=>{Y();Le();Lo();nn();fr();Re=le("session.jsonl");v=Do()});var Fo,_i=S(()=>{Fo={name:"coder",description:"\u4EE3\u7801\u7F16\u5199\u548C\u5F00\u53D1\uFF0C\u5305\u62EC\u65B0\u6587\u4EF6\u521B\u5EFA\u548C\u73B0\u6709\u6587\u4EF6\u4FEE\u6539\uFF0C\u652F\u6301\u591A\u8BED\u8A00\u9879\u76EE",keywords:["code","\u4EE3\u7801","\u7F16\u7A0B","\u5F00\u53D1","\u5199\u4EE3\u7801","\u4EE3\u7801\u4FEE\u6539","\u65B0\u5EFA\u6587\u4EF6","\u4F9D\u8D56\u68C0\u67E5","\u5B9E\u73B0\u529F\u80FD","\u6DFB\u52A0\u7279\u6027","\u4FEE\u590Dbug","\u91CD\u6784","\u5B9E\u73B0","\u5F00\u53D1","\u7F16\u5199","\u521B\u5EFA\u7C7B","\u521B\u5EFA\u51FD\u6570","\u6DFB\u52A0\u65B9\u6CD5","\u5199\u4E00\u4E2A","\u751F\u6210\u4EE3\u7801","\u65B0\u589E\u529F\u80FD","feature","implement","develop","create","add function","add","method","write code","generate code","refactor code","fix code","update code","modify code","\u7F16\u7801","\u5199\u529F\u80FD","\u52A0\u529F\u80FD","\u6539\u4EE3\u7801","\u5199\u63A5\u53E3","\u5199API","\u5F00\u53D1\u63A5\u53E3","\u5B9E\u73B0\u63A5\u53E3"],prompt:`\u4F60\u662F\u4E00\u4F4D\u8DE8\u8BED\u8A00\u4EE3\u7801\u7F16\u5199\u4E13\u5BB6\u3002\u4F60\u7684\u4EFB\u52A1\u662F\u6839\u636E\u7528\u6237\u9700\u6C42\u7F16\u5199\u9AD8\u8D28\u91CF\u3001\u53EF\u7EF4\u62A4\u7684\u4EE3\u7801\uFF0C\u652F\u6301\u591A\u79CD\u7F16\u7A0B\u8BED\u8A00\u548C\u9879\u76EE\u7C7B\u578B\u3002
|
|
23
24
|
|
|
24
25
|
## \u6838\u5FC3\u89C4\u5219
|
|
25
26
|
|
|
@@ -204,92 +205,15 @@ var oc=Object.defineProperty;var C=(r,e)=>()=>(r&&(e=r(r=0)),e);var U=(r,e)=>{fo
|
|
|
204
205
|
- \u4F7F\u7528 \`grep()\` \u6216 \`search\` \u5DE5\u5177\u67E5\u627E\u6240\u6709\u5F15\u7528
|
|
205
206
|
- \u5236\u5B9A\u5168\u9762\u7684\u66F4\u65B0\u8BA1\u5212\uFF0C\u786E\u4FDD\u6240\u6709\u4F9D\u8D56\u90FD\u5F97\u5230\u9002\u5F53\u5904\u7406
|
|
206
207
|
|
|
207
|
-
\u786E\u4FDD\u5728\u5B8C\u6210\u4EE3\u7801\u7F16\u5199\u548C\u6587\u4EF6\u5199\u5165\u4E4B\u540E\uFF0C\u5FC5\u987B\u6267\u884C\u4F9D\u8D56\u68C0\u67E5\u6B65\u9AA4\uFF01`}});var
|
|
208
|
+
\u786E\u4FDD\u5728\u5B8C\u6210\u4EE3\u7801\u7F16\u5199\u548C\u6587\u4EF6\u5199\u5165\u4E4B\u540E\uFF0C\u5FC5\u987B\u6267\u884C\u4F9D\u8D56\u68C0\u67E5\u6B65\u9AA4\uFF01`}});var yt={};j(yt,{LITE_MODEL:()=>Pe,MODEL:()=>fe,getDefaultModelConfig:()=>Ye,getLiteModelConfig:()=>an,getLiteModelMaxToken:()=>No,getMCPServerConfigs:()=>Uo,getMaxToken:()=>_o,getProvider:()=>El});import{readFileSync as Pl}from"fs";function jo(){if(!yr)try{let o=le("config.json"),e=Pl(o,"utf-8");yr=JSON.parse(e)}catch(o){console.error("Failed to load config.json:",o.message),yr={models:{defaultModel:{apiKey:"",authToken:"",baseURL:"https://api.openai.com/v1",model:"gpt-4o-mini",provider:"openai"}}}}return yr}function Ye(){let o=jo(),e={apiKey:"",authToken:"",baseURL:"https://api.openai.com/v1",model:"gpt-4o-mini",provider:"openai",maxToken:128e3},t=o.models?.defaultModel||e;return t.provider==="anthropic"&&t.disableExperimentalBetas===void 0&&(t.disableExperimentalBetas=!0),t}function an(){let e=jo().models?.liteModel||Ye();return e.provider==="anthropic"&&e.disableExperimentalBetas===void 0&&(e.disableExperimentalBetas=!0),e}function Ni(){return Ye().model||"gpt-4o-mini"}function $l(){return an().model||Ni()}function El(){return Ye().provider||"openai"}function fe(){return Ni()}function Pe(){return $l()}function _o(){return Ye().maxToken||128e3}function No(){return an().maxToken||16385}function Uo(){return jo().mcpServers||[]}var yr,ae=S(()=>{Le();yr=null});var Xe,Cr=S(()=>{Xe=class{config;constructor(e){this.config=e}getModelName(){return this.config.model}getProviderType(){return this.config.provider}_getApiKey(){return this.config.apiKey}_getAuthToken(){return this.config.authToken}_getBaseURL(){return this.config.baseURL}}});import Ml from"openai";var Wo,Ui,Wi=S(()=>{Cr();Wo=class extends Xe{client=null;constructor(e){super(e)}_initClient(){if(!this.client){let e={baseURL:this.config.baseURL||"https://api.openai.com/v1",defaultHeaders:{}};this.config.apiKey?e.apiKey=this.config.apiKey:this.config.authToken&&(this.config.authToken.startsWith("Bearer ")?e.apiKey=this.config.authToken.slice(7):e.apiKey=this.config.authToken),this.client=new Ml(e)}return this.client}async callModel(e){let{model:t=this.getModelName(),messages:n,temperature:r=.1,max_tokens:s,tools:i,tool_choice:a}=e,c=this._initClient(),l=[...n],g={model:t,messages:l,temperature:r,max_tokens:s};i&&i.length>0&&(g.tools=i.map(u=>({type:"function",function:{name:u.name,description:u.description,parameters:u.input_schema}})),a&&(a.type==="any"||(g.tool_choice=a)));let p=await c.chat.completions.create(g);return this._processReasoningContent(p),p}_processReasoningContent(e){if(e.choices&&e.choices[0]&&e.choices[0].message&&e.choices[0].message.reasoning_content){let{message:t}=e.choices[0],n=t.reasoning_content;if(t.tool_calls&&t.tool_calls.length>0){t.content?typeof t.content=="string"&&(t.content=`${n}
|
|
208
209
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
1. **quickProjectScan()** - \u5FEB\u901F\u626B\u63CF\u5E76\u751F\u6210\u5B8C\u6574\u7684\u9879\u76EE\u4FE1\u606F
|
|
212
|
-
- \u81EA\u52A8\u626B\u63CF\u6240\u6709\u6587\u4EF6
|
|
213
|
-
- \u5206\u6790\u76EE\u5F55\u7ED3\u6784
|
|
214
|
-
- \u68C0\u6D4B\u7F16\u7A0B\u8BED\u8A00
|
|
215
|
-
- \u751F\u6210 \`.nium/project/project.json\` \u6587\u4EF6
|
|
216
|
-
- \u63A8\u8350\u7528\u4E8E\uFF1A\u9996\u6B21\u63A2\u7D22\u3001\u751F\u6210\u9879\u76EE\u4FE1\u606F
|
|
217
|
-
|
|
218
|
-
2. **glob(pattern)** - \u6309\u6A21\u5F0F\u641C\u7D22\u6587\u4EF6
|
|
219
|
-
- \u4F8B\u5982\uFF1A\`glob('**/*.js')\` \u67E5\u627E\u6240\u6709 JS \u6587\u4EF6
|
|
220
|
-
- \u4F8B\u5982\uFF1A\`glob('src/**/*')\` \u67E5\u627E src \u76EE\u5F55\u4E0B\u6240\u6709\u6587\u4EF6
|
|
221
|
-
|
|
222
|
-
3. **grep(pattern, path)** - \u5728\u6587\u4EF6\u4E2D\u641C\u7D22\u5185\u5BB9
|
|
223
|
-
- \u4F8B\u5982\uFF1A\`grep('export.*API', 'src')\` \u67E5\u627E API \u5BFC\u51FA
|
|
224
|
-
|
|
225
|
-
4. **read(path)** - \u8BFB\u53D6\u6587\u4EF6\u5185\u5BB9
|
|
226
|
-
- \u7528\u4E8E\u6DF1\u5165\u4E86\u89E3\u5173\u952E\u6587\u4EF6
|
|
227
|
-
|
|
228
|
-
## \u5DE5\u4F5C\u7B56\u7565
|
|
229
|
-
|
|
230
|
-
### \u573A\u666F 1\uFF1A\u7528\u6237\u8981\u6C42"\u63A2\u7D22\u9879\u76EE"\u6216"\u751F\u6210\u9879\u76EE\u4FE1\u606F"
|
|
231
|
-
|
|
232
|
-
**\u7B56\u7565\uFF1A\u4F7F\u7528\u5FEB\u901F\u626B\u63CF**
|
|
233
|
-
|
|
234
|
-
1. \u76F4\u63A5\u8C03\u7528 \`quickProjectScan()\` \u5DE5\u5177
|
|
235
|
-
2. \u5DE5\u5177\u4F1A\u81EA\u52A8\u5B8C\u6210\u6240\u6709\u626B\u63CF\u548C\u4FE1\u606F\u6536\u96C6
|
|
236
|
-
3. \u5411\u7528\u6237\u6C47\u62A5\u63A2\u7D22\u5B8C\u6210\uFF0C\u9879\u76EE\u4FE1\u606F\u5DF2\u751F\u6210
|
|
237
|
-
4. \u5982\u9700\u67E5\u770B\u9879\u76EE\u4FE1\u606F\uFF0C\u53EF\u8BFB\u53D6 \`.nium/project/project.json\` \u6587\u4EF6
|
|
238
|
-
|
|
239
|
-
### \u573A\u666F 2\uFF1A\u7528\u6237\u63D0\u51FA\u5177\u4F53\u95EE\u9898\uFF08\u5982"\u524D\u7AEF\u4EE3\u7801\u5728\u54EA\u91CC\uFF1F"\uFF09
|
|
240
|
-
|
|
241
|
-
**\u7B56\u7565\uFF1A\u4F7F\u7528\u5DE5\u5177\u7EC4\u5408\u8FDB\u884C\u667A\u80FD\u5206\u6790**
|
|
242
|
-
|
|
243
|
-
1. \u4F7F\u7528 \`glob()\` \u641C\u7D22\u76F8\u5173\u6587\u4EF6
|
|
244
|
-
2. \u5FC5\u8981\u65F6\u4F7F\u7528 \`read()\` \u8BFB\u53D6\u5173\u952E\u6587\u4EF6
|
|
245
|
-
3. \u5206\u6790\u5E76\u56DE\u7B54\u7528\u6237\u95EE\u9898
|
|
246
|
-
|
|
247
|
-
### \u573A\u666F 3\uFF1A\u7528\u6237\u8981\u6C42"\u63A2\u7D22\u5E76\u5206\u6790\u67D0\u4E2A\u65B9\u9762"
|
|
248
|
-
|
|
249
|
-
**\u7B56\u7565\uFF1A\u6DF7\u5408\u4F7F\u7528**
|
|
250
|
-
|
|
251
|
-
1. \u5148\u8C03\u7528 \`quickProjectScan()\` \u83B7\u53D6\u6574\u4F53\u7ED3\u6784
|
|
252
|
-
2. \u518D\u4F7F\u7528\u5176\u4ED6\u5DE5\u5177\u6DF1\u5165\u5206\u6790\u7279\u5B9A\u65B9\u9762
|
|
253
|
-
3. \u6574\u5408\u4FE1\u606F\u5E76\u7ED9\u51FA\u5168\u9762\u7684\u7B54\u6848
|
|
254
|
-
|
|
255
|
-
## \u793A\u4F8B\u5BF9\u8BDD
|
|
256
|
-
|
|
257
|
-
**\u7528\u6237**\uFF1A\u63A2\u7D22\u8FD9\u4E2A\u9879\u76EE **\u4F60\u7684\u884C\u52A8**\uFF1A
|
|
210
|
+
${t.content}`):t.content=n;return}try{let r=[];try{let s=JSON.parse(n);Array.isArray(s)&&s.length>0?(r=s.filter(i=>i&&i.name).map(i=>({id:`call_${i.name}_${Date.now()}`,type:"function",function:{name:i.name,arguments:JSON.stringify(i.parameters||{})}})),t.tool_calls=r):t.content||(t.content=n)}catch{t.content||(t.content=n)}}catch(r){console.warn("Failed to process reasoning_content:",r)}}}},Ui=Wo});var zo,zi,Vi=S(()=>{Cr();Y();zo=class extends Xe{client=null;constructor(e){super(e)}async _initClient(){if(!this.client){let{Anthropic:e}=await import("@anthropic-ai/sdk"),t={};this.config.apiKey?t.apiKey=this.config.apiKey:this.config.authToken&&(this.config.authToken.startsWith("Bearer ")?t.apiKey=this.config.authToken.slice(7):t.apiKey=this.config.authToken),this.config.disableExperimentalBetas!==!1&&(t.defaultHeaders={...t.defaultHeaders,"anthropic-beta":""}),this.client=new e(t)}return this.client}async callModel(e){let{model:t=this.getModelName(),messages:n,temperature:r=.1,max_tokens:s=4096,tools:i,tool_choice:a}=e,c=await this._initClient(),l=[...n],g="",p=l.filter(f=>f.role==="system");p.length>0&&(g=p.map(f=>f.content).join(`
|
|
258
211
|
|
|
259
|
-
|
|
260
|
-
2. \u8C03\u7528 quickProjectScan()
|
|
261
|
-
3. \u5411\u7528\u6237\u6C47\u62A5: "\u6211\u5DF2\u7ECF\u5B8C\u6210\u4E86\u9879\u76EE\u63A2\u7D22\uFF0C\u9879\u76EE\u4FE1\u606F\u5DF2\u4FDD\u5B58\u5230 \`.nium/project/project.json\`"
|
|
262
|
-
4. \u5982\u9700\u67E5\u770B\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u53EF\u8BFB\u53D6\u8BE5 JSON \u6587\u4EF6\u5E76\u5C55\u793A\u5173\u952E\u4FE1\u606F
|
|
212
|
+
`)),l=l.filter(f=>f.role!=="system");let u=[],m=0;for(;m<l.length;){let f=l[m];if(f.role==="assistant"){let T=[];if(f.content&&typeof f.content=="string"&&T.push({type:"text",text:f.content}),f.tool_calls&&f.tool_calls.length>0)for(let x of f.tool_calls)T.push({type:"tool_use",id:x.id,name:x.function.name,input:JSON.parse(x.function.arguments)});T.length>0&&u.push({role:"assistant",content:T}),m++}else if(f.role==="tool"){let T=[];for(;m<l.length&&l[m].role==="tool";){let x=l[m];T.push({type:"tool_result",tool_use_id:x.tool_call_id,content:x.content||"No result"}),m++}T.length>0&&u.push({role:"user",content:T})}else if(f.role==="user"){let T=typeof f.content=="string"?[{type:"text",text:f.content}]:Array.isArray(f.content)?f.content:[{type:"text",text:String(f.content)}];u.push({role:"user",content:T}),m++}else m++}let d={model:t,max_tokens:s,temperature:r,system:g||"You are a helpful assistant.",messages:u};i&&i.length>0&&(d.tools=i,a&&(d.tool_choice=a));let y=await c.messages.create(d);C(`[Anthropic Provider] Response content blocks: ${JSON.stringify(y.content,null,2)}`);let w=[],h="";for(let f of y.content)if(f.type==="text")h+=f.text;else if(f.type==="tool_use")C(`[Anthropic Provider] Tool use block: ${JSON.stringify({id:f.id,name:f.name,input:f.input,inputKeys:Object.keys(f.input||{})},null,2)}`),w.push({id:f.id,type:"function",function:{name:f.name,arguments:JSON.stringify(f.input)}});else if(f.type==="thinking"){let T=f.thinking||"";T&&(h=T+(h?`
|
|
263
213
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
1. think: \u9700\u8981\u67E5\u627E\u524D\u7AEF\u76F8\u5173\u6587\u4EF6\uFF0C\u4F7F\u7528 glob \u641C\u7D22
|
|
267
|
-
2. \u8C03\u7528 glob('\\*_/_.{jsx,tsx,vue}')
|
|
268
|
-
3. \u5206\u6790\u7ED3\u679C\u5E76\u56DE\u7B54
|
|
269
|
-
|
|
270
|
-
**\u7528\u6237**\uFF1A\u63A2\u7D22\u9879\u76EE\u5E76\u544A\u8BC9\u6211 API \u662F\u5982\u4F55\u5B9A\u4E49\u7684 **\u4F60\u7684\u884C\u52A8**\uFF1A
|
|
271
|
-
|
|
272
|
-
1. think: \u5148\u83B7\u53D6\u6574\u4F53\u7ED3\u6784\uFF0C\u518D\u6DF1\u5165\u5206\u6790 API
|
|
273
|
-
2. \u8C03\u7528 quickProjectScan()
|
|
274
|
-
3. \u8C03\u7528 glob('**/routes/**') \u6216 grep('router', 'src')
|
|
275
|
-
4. \u8C03\u7528 read() \u8BFB\u53D6\u5173\u952E\u8DEF\u7531\u6587\u4EF6
|
|
276
|
-
5. \u6574\u5408\u4FE1\u606F\u5E76\u89E3\u91CA API \u67B6\u6784
|
|
277
|
-
|
|
278
|
-
## \u6838\u5FC3\u539F\u5219
|
|
279
|
-
|
|
280
|
-
1. **\u9AD8\u6548\u4F18\u5148**\uFF1A\u5BF9\u4E8E\u6807\u51C6\u7684\u63A2\u7D22\u8BF7\u6C42\uFF0C\u4F18\u5148\u4F7F\u7528 \`quickProjectScan()\`
|
|
281
|
-
2. **\u7CBE\u51C6\u56DE\u7B54**\uFF1A\u5BF9\u4E8E\u5177\u4F53\u95EE\u9898\uFF0C\u4F7F\u7528\u6700\u5408\u9002\u7684\u5DE5\u5177\u7EC4\u5408
|
|
282
|
-
3. **\u6DF1\u5EA6\u5206\u6790**\uFF1A\u5FC5\u8981\u65F6\u6DF1\u5165\u8BFB\u53D6\u548C\u5206\u6790\u5173\u952E\u4EE3\u7801\u6587\u4EF6
|
|
283
|
-
4. **\u6E05\u6670\u8868\u8FBE**\uFF1A\u4EE5\u7ED3\u6784\u5316\u3001\u6613\u61C2\u7684\u65B9\u5F0F\u5448\u73B0\u5206\u6790\u7ED3\u679C
|
|
284
|
-
5. **\u5408\u7406\u5C55\u793A**\uFF1A\u63A2\u7D22\u5B8C\u6210\u540E\uFF0C\u544A\u8BC9\u7528\u6237\u9879\u76EE\u4FE1\u606F\u5DF2\u751F\u6210\uFF0C\u53EF\u6839\u636E\u9700\u8981\u8BFB\u53D6\u5E76\u5C55\u793A\u5173\u952E\u4FE1\u606F`}});function Js(){return Object.values(Ac)}var Ac,Gs=C(()=>{Ws();Hs();Ac={[no.name]:no,[ro.name]:ro}});var Ze={};U(Ze,{LITE_MODEL:()=>fe,MODEL:()=>de,getDefaultModelConfig:()=>Ie,getLiteModelConfig:()=>Rt,getLiteModelMaxToken:()=>io,getMCPServerConfigs:()=>ao,getMaxToken:()=>so,getProvider:()=>jc});import{readFileSync as Lc}from"fs";function oo(){if(!Jn)try{let r=ae("config.json"),e=Lc(r,"utf-8");Jn=JSON.parse(e)}catch(r){console.error("Failed to load config.json:",r.message),Jn={models:{defaultModel:{apiKey:"",baseURL:"https://api.openai.com/v1",model:"gpt-4o-mini",provider:"openai"}}}}return Jn}function Ie(){let r=oo(),e={apiKey:"",baseURL:"https://api.openai.com/v1",model:"gpt-4o-mini",provider:"openai",maxToken:128e3};return r.models?.defaultModel||e}function Rt(){return oo().models?.liteModel||Ie()}function zs(){return Ie().model||"gpt-4o-mini"}function Dc(){return Rt().model||zs()}function jc(){return Ie().provider||"openai"}function de(){return zs()}function fe(){return Dc()}function so(){return Ie().maxToken||128e3}function io(){return Rt().maxToken||16385}function ao(){return oo().mcpServers||[]}var Jn,ee=C(()=>{Me();Jn=null});var Ae,Gn=C(()=>{Ae=class{config;constructor(e){this.config=e}getModelName(){return this.config.model}getProviderType(){return this.config.provider}_getApiKey(){return this.config.apiKey}_getBaseURL(){return this.config.baseURL}}});import Oc from"openai";var co,qs,Bs=C(()=>{Gn();co=class extends Ae{client=null;constructor(e){super(e)}_initClient(){return this.client||(this.client=new Oc({apiKey:this.config.apiKey,baseURL:this.config.baseURL||"https://api.openai.com/v1"})),this.client}async callModel(e){let{model:t=this.getModelName(),messages:n,temperature:o=.1,max_tokens:s,tools:i,tool_choice:a}=e,c=this._initClient(),l=[...n],p={model:t,messages:l,temperature:o,max_tokens:s};i&&i.length>0&&(p.tools=i.map(g=>({type:"function",function:{name:g.name,description:g.description,parameters:g.input_schema}})),a&&(a.type==="any"||(p.tool_choice=a)));let u=await c.chat.completions.create(p);return this._processReasoningContent(u),u}_processReasoningContent(e){if(e.choices&&e.choices[0]&&e.choices[0].message&&e.choices[0].message.reasoning_content){let{message:t}=e.choices[0],n=t.reasoning_content;if(t.tool_calls&&t.tool_calls.length>0){t.content?typeof t.content=="string"&&(t.content=`${n}
|
|
285
|
-
|
|
286
|
-
${t.content}`):t.content=n;return}try{let o=[];try{let s=JSON.parse(n);Array.isArray(s)&&s.length>0?(o=s.filter(i=>i&&i.name).map(i=>({id:`call_${i.name}_${Date.now()}`,type:"function",function:{name:i.name,arguments:JSON.stringify(i.parameters||{})}})),t.tool_calls=o):t.content||(t.content=n)}catch{t.content||(t.content=n)}}catch(o){console.warn("Failed to process reasoning_content:",o)}}}},qs=co});var lo,Ys,Ks=C(()=>{Gn();lo=class extends Ae{client=null;constructor(e){super(e)}async _initClient(){if(!this.client){let{Anthropic:e}=await import("@anthropic-ai/sdk");this.client=new e({apiKey:this.config.apiKey})}return this.client}async callModel(e){let{model:t=this.getModelName(),messages:n,temperature:o=.1,max_tokens:s=4096,tools:i,tool_choice:a}=e,c=await this._initClient(),l=[...n],p="",u=l.filter(d=>d.role==="system");u.length>0&&(p=u.map(d=>d.content).join(`
|
|
287
|
-
|
|
288
|
-
`)),l=l.filter(d=>d.role!=="system");let g=[],m=0;for(;m<l.length;){let d=l[m];if(d.role==="assistant"){let k=[];if(d.content&&typeof d.content=="string"&&k.push({type:"text",text:d.content}),d.tool_calls&&d.tool_calls.length>0)for(let T of d.tool_calls)k.push({type:"tool_use",id:T.id,name:T.function.name,input:JSON.parse(T.function.arguments)});k.length>0&&g.push({role:"assistant",content:k}),m++}else if(d.role==="tool"){let k=[];for(;m<l.length&&l[m].role==="tool";){let T=l[m];k.push({type:"tool_result",tool_use_id:T.tool_call_id,content:T.content||"No result"}),m++}k.length>0&&g.push({role:"user",content:k})}else if(d.role==="user"){let k=typeof d.content=="string"?[{type:"text",text:d.content}]:Array.isArray(d.content)?d.content:[{type:"text",text:String(d.content)}];g.push({role:"user",content:k}),m++}else m++}let S={model:t,max_tokens:s,temperature:o,system:p||"You are a helpful assistant.",messages:g};i&&i.length>0&&(S.tools=i,a&&(S.tool_choice=a));let b=await c.messages.create(S);console.log("[Anthropic Provider] Response content blocks:",JSON.stringify(b.content,null,2));let f=[],y="";for(let d of b.content)if(d.type==="text")y+=d.text;else if(d.type==="tool_use")console.log("[Anthropic Provider] Tool use block:",{id:d.id,name:d.name,input:d.input,inputKeys:Object.keys(d.input||{})}),f.push({id:d.id,type:"function",function:{name:d.name,arguments:JSON.stringify(d.input)}});else if(d.type==="thinking"){let k=d.thinking||"";k&&(y=k+(y?`
|
|
289
|
-
|
|
290
|
-
`+y:""))}return{choices:[{message:{content:y||null,tool_calls:f.length>0?f:void 0},finish_reason:b.stop_reason==="end_turn"?"stop":b.stop_reason}]}}},Ys=lo});var Ft,Xs=C(()=>{ee();Gn();Bs();Ks();Ft=class{static async getProvider(){let e=Ie();return this.createProvider(e)}static async getLiteProvider(){let e=Rt();return this.createProvider(e)}static async createProvider(e){switch(e.provider||"openai"){case"anthropic":return new Ys(e);case"openai":default:return new qs(e)}}}});function et(r){return r&&typeof r=="object"&&r.__tool_result===!0}function _t(r){return et(r)?r.result:r}var I,J=C(()=>{I=class{get name(){return this.getDefinition().name}get description(){return this.getDefinition().description}get inputSchema(){return this.getDefinition().input_schema}createToolResult(e,t=null,n=!0){return{__tool_result:!0,result:e,display:t!==null?t:e,shouldPrint:n}}formatError(e,t){let n=t instanceof Error?t.message:String(t);return`Error: ${e} failed - ${n}`}formatAction(e){let t=this.name,n=Object.entries(e).map(([o,s])=>{let i=s;return typeof s=="string"&&s.length>50&&(i=s.substring(0,50)+"..."),`${o}=${JSON.stringify(i)}`}).join(", ");return`${t}(${n})`}formatObservation(e){if(et(e)){let{display:t}=e;return Array.isArray(t)?t.join(`
|
|
214
|
+
`+h:""))}return{choices:[{message:{content:h||null,tool_calls:w.length>0?w:void 0},finish_reason:y.stop_reason==="end_turn"?"stop":y.stop_reason}]}}},zi=zo});var cn,Hi=S(()=>{ae();Cr();Wi();Vi();cn=class{static async getProvider(){let e=Ye();return this.createProvider(e)}static async getLiteProvider(){let e=an();return this.createProvider(e)}static async createProvider(e){switch(e.provider||"openai"){case"anthropic":return new zi(e);case"openai":default:return new Ui(e)}}}});function Ct(o){return o&&typeof o=="object"&&o.__tool_result===!0}function ln(o){return Ct(o)?o.result:o}var E,q=S(()=>{E=class{get name(){return this.getDefinition().name}get description(){return this.getDefinition().description}get inputSchema(){return this.getDefinition().input_schema}createToolResult(e,t=null,n=!0){return{__tool_result:!0,result:e,display:t!==null?t:e,shouldPrint:n}}formatError(e,t){let n=t instanceof Error?t.message:String(t);return`Error: ${e} failed - ${n}`}formatAction(e){let t=this.name,n=Object.entries(e).map(([r,s])=>{let i=s;return typeof s=="string"&&s.length>50&&(i=s.substring(0,50)+"..."),`${r}=${JSON.stringify(i)}`}).join(", ");return`${t}(${n})`}formatObservation(e){if(Ct(e)){let{display:t}=e;return Array.isArray(t)?t.join(`
|
|
291
215
|
`):String(t)}return Array.isArray(e)?e.join(`
|
|
292
|
-
`):String(e)}shouldPrintObservation(e){return
|
|
216
|
+
`):String(e)}shouldPrintObservation(e){return Ct(e)?e.shouldPrint:!0}}});var he,un=S(()=>{q();he=class extends E{getDefinition(){let e=this.getBaseDefinition(),t="IMPORTANT: User confirmation is automatically required - DO NOT call askUser tool before calling this tool.",{description:n}=e;if(!n.includes("User confirmation is automatically required"))if(n.trim().startsWith("IMPORTANT:"))if(n.match(/^IMPORTANT:[^\n]*(\n[^\n]*)*?\n\n/)){let s=n.indexOf(`
|
|
293
217
|
`);n=n.slice(0,s)+`
|
|
294
218
|
- User confirmation is automatically required - DO NOT call askUser tool before calling this tool`+n.slice(s)}else{let s=n.indexOf(`
|
|
295
219
|
`);s!==-1?n=n.slice(0,s)+`
|
|
@@ -297,33 +221,74 @@ ${t.content}`):t.content=n;return}try{let o=[];try{let s=JSON.parse(n);Array.isA
|
|
|
297
221
|
|
|
298
222
|
`+n}else n=t+`
|
|
299
223
|
|
|
300
|
-
`+n;return{...e,description:n,requiresConfirmation:!0}}getConfirmationMessage(e){return null}}});var
|
|
301
|
-
|
|
224
|
+
`+n;return{...e,description:n,requiresConfirmation:!0}}getConfirmationMessage(e){return null}}});var Vo={};j(Vo,{BaseTool:()=>E,ConfirmableTool:()=>he,extractToolResult:()=>ln,isToolResult:()=>Ct});var Ho=S(()=>{q();un()});import{readFileSync as Ji,statSync as Il}from"fs";import{resolve as Al}from"path";function gn(o){return Gi.execute(o)}var St,Gi,pn,Bi=S(()=>{q();St=class extends E{lastReadPath="";getDefinition(){return{name:"read",description:`Read content from a specified file path.
|
|
225
|
+
|
|
226
|
+
\u{1F4CB} USE CASES:
|
|
227
|
+
- View file content for analysis or editing
|
|
228
|
+
- Check file existence and readability
|
|
229
|
+
- Process large files with automatic chunking
|
|
230
|
+
- Read configuration files
|
|
231
|
+
|
|
232
|
+
\u{1F511} PARAMETERS:
|
|
233
|
+
- path: File path to read (relative or absolute)
|
|
234
|
+
- silent: If true, returns success message instead of full content (useful for large files)
|
|
235
|
+
- chunkSize: Return content in chunks of specified bytes (e.g., 1024 * 1024 for 1MB chunks)
|
|
236
|
+
- autoChunk: Automatically split large files (>5MB) into manageable chunks
|
|
237
|
+
|
|
238
|
+
\u{1F4A1} EXAMPLES:
|
|
239
|
+
- read({ path: "package.json" }) - Read entire package.json file
|
|
240
|
+
- read({ path: "large.log", autoChunk: true }) - Read large log file in chunks
|
|
241
|
+
- read({ path: "config.json", silent: true }) - Verify config.json exists
|
|
242
|
+
|
|
243
|
+
\u{1F4DD} RETURN VALUE:
|
|
244
|
+
- Complete file content as string (for small files)
|
|
245
|
+
- Array of file chunks (for large files with chunking)
|
|
246
|
+
- Success message (with silent: true)`,input_schema:{type:"object",properties:{path:{type:"string",description:"File path to read (relative or absolute)"},silent:{type:"boolean",description:"If true, returns success message instead of full content"},chunkSize:{type:"number",description:"Return content in chunks of specified bytes (optional)"},autoChunk:{type:"boolean",description:"Automatically split large files into chunks (optional)"}},required:["path"]}}}execute(e){try{let t=e.path.trim(),n=Al(t);if(this.lastReadPath=t,e.silent)return Ji(n,"utf-8"),this.createToolResult("file content",`\u6587\u4EF6 ${t} \u8BFB\u53D6\u6210\u529F\uFF08\u9759\u9ED8\u6A21\u5F0F\uFF0C\u5185\u5BB9\u672A\u663E\u793A\uFF09`,!0);let r=Ji(n,"utf-8");if(e.chunkSize||e.autoChunk){let a=Il(n).size,c=1024*1024,l=5*1024*1024,g=e.chunkSize||c;if(e.autoChunk&&a<=l)return r;g=Math.max(1,g);let p=[];for(let u=0;u<r.length;u+=g)p.push(r.slice(u,u+g));return this.createToolResult(p,`\u6587\u4EF6 ${t} \u5DF2\u5206\u5757\u8BFB\u53D6\uFF0C\u5171 ${p.length} \u5757\uFF0C\u6BCF\u5757 ${g} \u5B57\u8282`,!0)}return r}catch(t){let r=`Error: Cannot read file ${e.path.trim()} - ${t instanceof Error?t.message:String(t)}`;return this.createToolResult(r,r,!0)}}formatObservation(e){if(typeof e=="object"&&e.__tool_result)return super.formatObservation(e);if(Array.isArray(e)&&this.lastReadPath)return`\u8BFB\u53D6\u6587\u4EF6 ${this.lastReadPath}\uFF0C\u5171 ${e.length} \u5757`;if(typeof e=="string"&&this.lastReadPath){let n=e.split(`
|
|
247
|
+
`).length;return`\u8BFB\u53D6\u6587\u4EF6 ${this.lastReadPath}\uFF0C\u5171 ${n} \u884C`}return super.formatObservation(e)}},Gi=new St;pn=Gi});function qi(o){if(typeof o!="string")return o;let e=o.replace(/\\n/g,`
|
|
302
248
|
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\'/g,"'");return e=e.replace(/\r\n/g,`
|
|
303
249
|
`).replace(/\r/g,`
|
|
304
|
-
`),e}function
|
|
250
|
+
`),e}function Sr(o){return o.includes(`\r
|
|
305
251
|
`)?`\r
|
|
306
|
-
`:
|
|
252
|
+
`:o.includes(`
|
|
307
253
|
`)?`
|
|
308
|
-
`:
|
|
254
|
+
`:o.includes("\r")?"\r":Jo}var Jo,Go=S(()=>{Jo=process.platform==="win32"?`\r
|
|
309
255
|
`:`
|
|
310
|
-
`});import{mkdirSync as
|
|
256
|
+
`});import{mkdirSync as Ll}from"fs";import{resolve as Rl}from"path";function mn(o){return Ki.execute(o)}var xt,Ki,Qe,Bo=S(()=>{q();xt=class extends E{getDefinition(){return{name:"mkdir",description:"Create a directory and all necessary parent directories (like mkdir -p). Returns a confirmation message.",input_schema:{type:"object",properties:{path:{type:"string",description:"The directory path to create"}},required:["path"]}}}execute(e){try{let t=Rl(e.path);return Ll(t,{recursive:!0}),`Directory created: ${e.path}`}catch(t){return this.formatError(`Cannot create directory ${e.path}`,t)}}},Ki=new xt;Qe=Ki});import{readFileSync as Dl,writeFileSync as Yi,existsSync as Ol}from"fs";import{resolve as Fl,dirname as jl}from"path";function dn(o){return Xi.execute(o)}var wt,Xi,fn,Qi=S(()=>{Go();Bo();q();wt=class extends E{getDefinition(){return{name:"write",description:`Write content to a file - ONLY for creating NEW files.
|
|
311
257
|
|
|
312
|
-
\
|
|
313
|
-
-
|
|
314
|
-
-
|
|
315
|
-
-
|
|
316
|
-
-
|
|
258
|
+
\u{1F4CB} USE CASES:
|
|
259
|
+
- Create brand new files that don't exist yet
|
|
260
|
+
- Initialize empty files
|
|
261
|
+
- Overwrite existing files intentionally (use with caution)
|
|
262
|
+
- Generate files from templates
|
|
317
263
|
|
|
318
|
-
\
|
|
264
|
+
\u26A0\uFE0F CRITICAL SAFETY WARNING:
|
|
265
|
+
- write() BLINDLY OVERWRITES files, potentially losing concurrent changes
|
|
266
|
+
- For EXISTING files, ALWAYS use merge() instead for safe updates
|
|
267
|
+
- Only use write() when you're sure the file doesn't exist or you want to completely replace it
|
|
268
|
+
|
|
269
|
+
\u{1F511} TOOL SELECTION GUIDE:
|
|
319
270
|
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
320
271
|
\u2502 Creating NEW file \u2192 write() \u2705 \u2502
|
|
321
272
|
\u2502 Modifying EXISTING file \u2192 merge() \u2705 \u2502
|
|
322
273
|
\u2502 Overwriting EXISTING \u2192 write() \u26A0\uFE0F RISKY \u2502
|
|
323
|
-
\u2502 Small precise edits \u2192
|
|
324
|
-
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
274
|
+
\u2502 Small precise edits \u2192 searchReplace() \u2705 \u2502
|
|
275
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
276
|
+
|
|
277
|
+
\u{1F511} PARAMETERS:
|
|
278
|
+
- path: File path to write to (relative or absolute)
|
|
279
|
+
- content: Complete file content to write (required, cannot be empty)
|
|
280
|
+
|
|
281
|
+
\u{1F4A1} EXAMPLES:
|
|
282
|
+
- write({ path: "new-file.txt", content: "Hello World" }) - Create new text file
|
|
283
|
+
- write({ path: "config.json", content: '{ "key": "value" }' }) - Create new JSON file
|
|
284
|
+
- write({ path: "script.sh", content: "#!/bin/bash
|
|
285
|
+
echo 'test'" }) - Create new shell script
|
|
286
|
+
|
|
287
|
+
\u{1F4DD} RETURN VALUE:
|
|
288
|
+
- "done" on successful write
|
|
289
|
+
- Error message if write fails`,input_schema:{type:"object",properties:{path:{type:"string",description:"File path to write to"},content:{type:"string",description:"Complete file content to write (required, cannot be empty)"}},required:["path","content"]}}}execute(e){try{let t=Fl(e.path),n=jl(t),r=Qe.execute({path:n});if(r.startsWith("Error:"))return r;let s=qi(e.content);typeof s!="string"&&(s=String(s||""));let i=Jo;if(Ol(t)){let a=Dl(t,"utf-8");i=Sr(a);let c=`${t}.base`;Yi(c,a,"utf-8")}return i===`\r
|
|
325
290
|
`&&(s=s.replace(/\n/g,`\r
|
|
326
|
-
`)),
|
|
291
|
+
`)),Yi(t,s,"utf-8"),"done"}catch(t){return this.formatError(`Cannot write ${e.path}`,t)}}},Xi=new wt;fn=Xi});import{unlinkSync as _l,existsSync as Nl,statSync as Ul,rmdirSync as Wl}from"fs";import{resolve as zl}from"path";function hn(o){return typeof o=="object"&&o!==null&&"path"in o?qo.execute(o):qo.execute({path:o})}var vt,qo,yn,Zi=S(()=>{un();vt=class extends he{getBaseDefinition(){return{name:"delete",description:`Delete a file, multiple files or directories at the specified path(s).
|
|
327
292
|
|
|
328
293
|
IMPORTANT:
|
|
329
294
|
- This action cannot be undone
|
|
@@ -335,56 +300,74 @@ Examples:
|
|
|
335
300
|
- deleteFile("temp.txt") - delete a single file named temp.txt
|
|
336
301
|
- deleteFile("temp_dir") - delete a single empty directory named temp_dir
|
|
337
302
|
- deleteFile({ path: "temp.txt" }) - delete a single file
|
|
338
|
-
- deleteFile({ path: ["file1.txt", "dir1", "file2.txt"] }) - delete multiple files and directories`,input_schema:{type:"object",properties:{path:{type:"string",description:"The file path to delete (relative or absolute), or an array of file paths",oneOf:[{type:"string",description:"The file path to delete (relative or absolute)"},{type:"array",items:{type:"string",description:"A file path to delete"},description:"Array of file paths to delete"}]}},required:["path"]}}}getConfirmationMessage(e){let t=Array.isArray(e.path)?e.path:[e.path];return t.length===1?`\u5220\u9664: ${t[0]}`:`\u5220\u9664 ${t.length} \u4E2A\u6587\u4EF6/\u76EE\u5F55`}execute(e){try{let t=Array.isArray(e.path)?e.path:[e.path],n=[];for(let l of t)try{let
|
|
303
|
+
- deleteFile({ path: ["file1.txt", "dir1", "file2.txt"] }) - delete multiple files and directories`,input_schema:{type:"object",properties:{path:{type:"string",description:"The file path to delete (relative or absolute), or an array of file paths",oneOf:[{type:"string",description:"The file path to delete (relative or absolute)"},{type:"array",items:{type:"string",description:"A file path to delete"},description:"Array of file paths to delete"}]}},required:["path"]}}}getConfirmationMessage(e){let t=Array.isArray(e.path)?e.path:[e.path];return t.length===1?`\u5220\u9664: ${t[0]}`:`\u5220\u9664 ${t.length} \u4E2A\u6587\u4EF6/\u76EE\u5F55`}execute(e){try{let t=Array.isArray(e.path)?e.path:[e.path],n=[];for(let l of t)try{let g=zl(l);if(!Nl(g)){n.push(`Warning: Path not found - ${l}`);continue}Ul(g).isDirectory()?(Wl(g),n.push(`Directory deleted: ${l}`)):(_l(g),n.push(`File deleted: ${l}`))}catch(g){n.push(`Error: Cannot delete ${l} - ${g instanceof Error?g.message:"Unknown error"}`)}if(t.length===1)return n[0];let r=n.filter(l=>l.startsWith("File deleted")).length,s=n.filter(l=>l.startsWith("Directory deleted")).length,i=n.filter(l=>l.startsWith("Error")).length,a=n.filter(l=>l.startsWith("Warning")).length,c=r+s;return`${n.join(`
|
|
339
304
|
`)}
|
|
340
305
|
|
|
341
|
-
Summary: ${c} items deleted (${
|
|
306
|
+
Summary: ${c} items deleted (${r} files, ${s} directories), ${a} warnings, ${i} errors`}catch(t){return this.formatError("Cannot process delete operation",t)}}},qo=new vt;yn=qo});import{renameSync as Vl,existsSync as xr,statSync as Hl,mkdirSync as Jl}from"fs";import{resolve as ea,dirname as Gl}from"path";function Cn(o){return o&&typeof o=="object"&&"source"in o&&"destination"in o?ta.execute(o):"Error: Invalid input format. Expected { source: string, destination: string }"}var bt,ta,Sn,na=S(()=>{un();bt=class extends he{getBaseDefinition(){return{name:"move",description:`Move or rename a file or directory from source to destination.
|
|
342
307
|
|
|
343
308
|
Examples:
|
|
344
309
|
- moveFile({ source: "old.txt", destination: "new.txt" }) - rename a file
|
|
345
310
|
- moveFile({ source: "file.txt", destination: "folder/file.txt" }) - move a file to a different directory
|
|
346
311
|
- moveFile({ source: "old_folder", destination: "new_folder" }) - rename a directory
|
|
347
|
-
- moveFile({ source: "folder/file.txt", destination: "new_location/file.txt" }) - move a file with rename`,input_schema:{type:"object",properties:{source:{type:"string",description:"The source file or directory path to move"},destination:{type:"string",description:"The destination path (new name or location)"}},required:["source","destination"]}}}getConfirmationMessage(e){return`\u79FB\u52A8/\u91CD\u547D\u540D: ${e.source} \u2192 ${e.destination}`}execute(e){try{let{source:t,destination:n}=e,
|
|
312
|
+
- moveFile({ source: "folder/file.txt", destination: "new_location/file.txt" }) - move a file with rename`,input_schema:{type:"object",properties:{source:{type:"string",description:"The source file or directory path to move"},destination:{type:"string",description:"The destination path (new name or location)"}},required:["source","destination"]}}}getConfirmationMessage(e){return`\u79FB\u52A8/\u91CD\u547D\u540D: ${e.source} \u2192 ${e.destination}`}execute(e){try{let{source:t,destination:n}=e,r=ea(t),s=ea(n);if(!xr(r))return`Error: Source path does not exist - ${t}`;if(xr(s))return`Error: Destination already exists - ${n}`;let i=Gl(s);return xr(i)||Jl(i,{recursive:!0}),Vl(r,s),xr(s)?`${Hl(r).isDirectory()?"Directory":"File"} moved successfully from "${t}" to "${n}"`:`Error: Failed to move ${t} to ${n}`}catch(t){return this.formatError("Move operation",t)}}},ta=new bt;Sn=ta});import{existsSync as wr,statSync as ra,readFileSync as oa,writeFileSync as sa,mkdirSync as ia,readdirSync as Bl}from"fs";import{resolve as aa,join as ca,dirname as ql}from"path";function xn(o){return o&&typeof o=="object"&&"source"in o&&"destination"in o?la.execute(o):"Error: Invalid input format. Expected { source: string, destination: string }"}var Tt,la,wn,ua=S(()=>{un();Tt=class extends he{getBaseDefinition(){return{name:"copy",description:`Copy a file or directory from source to destination.
|
|
348
313
|
|
|
349
314
|
Examples:
|
|
350
315
|
- copyFile({ source: "file.txt", destination: "file_copy.txt" }) - copy a file
|
|
351
316
|
- copyFile({ source: "file.txt", destination: "folder/file.txt" }) - copy a file to a different directory
|
|
352
317
|
- copyFile({ source: "folder", destination: "folder_copy" }) - copy an entire directory (recursively)
|
|
353
|
-
- copyFile({ source: "folder/subdir", destination: "new_location/subdir" }) - copy a subdirectory`,input_schema:{type:"object",properties:{source:{type:"string",description:"The source file or directory path to copy"},destination:{type:"string",description:"The destination path (new location)"}},required:["source","destination"]}}}getConfirmationMessage(e){return`\u590D\u5236: ${e.source} \u2192 ${e.destination}`}execute(e){try{let{source:t,destination:n}=e,
|
|
354
|
-
`),
|
|
318
|
+
- copyFile({ source: "folder/subdir", destination: "new_location/subdir" }) - copy a subdirectory`,input_schema:{type:"object",properties:{source:{type:"string",description:"The source file or directory path to copy"},destination:{type:"string",description:"The destination path (new location)"}},required:["source","destination"]}}}getConfirmationMessage(e){return`\u590D\u5236: ${e.source} \u2192 ${e.destination}`}execute(e){try{let{source:t,destination:n}=e,r=aa(t),s=aa(n);if(!wr(r))return`Error: Source path does not exist - ${t}`;if(r===s)return"Error: Source and destination paths are identical";let i=ra(r),a=0,c=0;if(i.isDirectory())return this.copyDirectory(r,s,a,c),`Directory copied successfully from "${t}" to "${n}" (${a} files, ${c} directories)`;{let l=ql(s);return wr(l)||ia(l,{recursive:!0}),sa(s,oa(r)),wr(s)?`File copied successfully from "${t}" to "${n}"`:`Error: Failed to copy file from "${t}" to "${n}"`}}catch(t){return this.formatError("Copy operation",t)}}copyDirectory(e,t,n,r){wr(t)||(ia(t,{recursive:!0}),r++),Bl(e).forEach(i=>{let a=ca(e,i),c=ca(t,i);ra(a).isDirectory()?this.copyDirectory(a,c,n,r):(sa(c,oa(a)),n++)})}},la=new Tt;wn=la});import{diff3Merge as Kl}from"node-diff3";function ga(o,e,t){let n=o.split(`
|
|
319
|
+
`),r=e.split(`
|
|
355
320
|
`),s=t.split(`
|
|
356
|
-
`);console.log(` [merge] \u5F00\u59CB\u4E09\u8DEF\u5408\u5E76: base=${n.length}\u884C, current=${
|
|
321
|
+
`);console.log(` [merge] \u5F00\u59CB\u4E09\u8DEF\u5408\u5E76: base=${n.length}\u884C, current=${r.length}\u884C, incoming=${s.length}\u884C`);let i=Date.now(),a=Kl(r,n,s,{excludeFalseConflicts:!0}),c=((Date.now()-i)/1e3).toFixed(2);console.log(` [merge] diff3Merge \u5B8C\u6210\uFF0C\u8017\u65F6 ${c}s\uFF0C\u7ED3\u679C\u533A\u57DF\u6570: ${a.length}`);let l=[],g=[];for(let p of a)if(p.ok)l.push(...p.ok);else if(p.conflict){let u=l.length+1,m=p.conflict.a||[],d=p.conflict.o||[],y=p.conflict.b||[];g.push({lineNumber:u,base:d.join(`
|
|
357
322
|
`),current:m.join(`
|
|
358
|
-
`),incoming:
|
|
359
|
-
`)}),l.push("<<<<<<< CURRENT"),l.push(...m),l.push("======="),l.push(...
|
|
360
|
-
`),hasConflicts:
|
|
323
|
+
`),incoming:y.join(`
|
|
324
|
+
`)}),l.push("<<<<<<< CURRENT"),l.push(...m),l.push("======="),l.push(...y),l.push(">>>>>>> INCOMING")}return{merged:l.join(`
|
|
325
|
+
`),hasConflicts:g.length>0,conflicts:g}}var pa=S(()=>{});import{readFileSync as ma,writeFileSync as vr,existsSync as Ko,unlinkSync as Yo}from"fs";import{resolve as Yl}from"path";function Xo(o){return o.replace(/\r\n/g,`
|
|
361
326
|
`).replace(/\r/g,`
|
|
362
|
-
`)}function
|
|
327
|
+
`)}function vn(o){return da.execute(o)}var Xl,kt,da,bn,fa=S(()=>{Go();pa();q();Xl={lineRatioThreshold:.5,minLineDiff:100},kt=class extends E{getDefinition(){return{name:"merge",description:`Smart file merge tool - THE SAFE CHOICE for modifying existing files.
|
|
328
|
+
|
|
329
|
+
\u{1F4CB} USE CASES:
|
|
330
|
+
- Update existing files without losing concurrent changes
|
|
331
|
+
- Modify large files with safety checks
|
|
332
|
+
- Merge code changes from different sources
|
|
333
|
+
- Create new files when they don't exist yet
|
|
363
334
|
|
|
364
|
-
\u{
|
|
335
|
+
\u{1F504} INTELLIGENT BEHAVIOR:
|
|
336
|
+
1. File doesn't exist \u2192 Creates new file automatically
|
|
337
|
+
2. No concurrent edits \u2192 Direct write (fast path)
|
|
338
|
+
3. Concurrent edits detected \u2192 Three-way merge with conflict markers
|
|
339
|
+
4. Large deletions (>50%, >100 lines) \u2192 Returns warning, requires confirmation
|
|
340
|
+
|
|
341
|
+
\u26A0\uFE0F CRITICAL SAFETY FEATURES:
|
|
342
|
+
- Preserves concurrent changes from other processes
|
|
343
|
+
- Detects and marks merge conflicts
|
|
344
|
+
- Prevents accidental large deletions
|
|
345
|
+
- Maintains original line ending styles
|
|
346
|
+
- Automatically creates parent directories if needed
|
|
347
|
+
|
|
348
|
+
\u{1F511} TOOL SELECTION GUIDE:
|
|
365
349
|
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
366
350
|
\u2502 Scenario \u2502 Tool \u2502 Why \u2502
|
|
367
351
|
\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524
|
|
368
352
|
\u2502 Create NEW file \u2502 write() \u2502 No merge needed \u2502
|
|
369
|
-
\u2502 Small precise edits \u2502
|
|
353
|
+
\u2502 Small precise edits \u2502 searchReplace() \u2502 Token efficient \u2502
|
|
370
354
|
\u2502 Modify EXISTING file \u2502 merge() \u2502 Safe & smart \u2502
|
|
371
355
|
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
372
356
|
|
|
373
|
-
\u{
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
4. Large difference detected \u2192 Returns warning, requires confirmation
|
|
357
|
+
\u{1F511} PARAMETERS:
|
|
358
|
+
- path: File path to merge/modify
|
|
359
|
+
- newContent: Complete new version of the file content
|
|
360
|
+
- confirmLargeChange: Set to true to confirm large deletions (>50% of file)
|
|
378
361
|
|
|
379
|
-
\
|
|
380
|
-
-
|
|
381
|
-
-
|
|
382
|
-
- merge(
|
|
362
|
+
\u{1F4A1} EXAMPLES:
|
|
363
|
+
- merge({ path: "app.js", newContent: updatedCode }) - Safely update app.js
|
|
364
|
+
- merge({ path: "config.json", newContent: newConfig }) - Merge updated config
|
|
365
|
+
- merge({ path: "large-file.js", newContent: trimmedContent, confirmLargeChange: true }) - Confirm large deletion
|
|
383
366
|
|
|
384
|
-
\u{
|
|
385
|
-
-
|
|
386
|
-
-
|
|
387
|
-
-
|
|
367
|
+
\u{1F4DD} RETURN VALUE:
|
|
368
|
+
- "Merge successful" messages on success
|
|
369
|
+
- Conflict details with markers if merge conflicts exist
|
|
370
|
+
- Warning message for large deletions requiring confirmation`,input_schema:{type:"object",properties:{path:{type:"string",description:"File path to merge/modify"},newContent:{type:"string",description:"Complete new version of the entire file content"},confirmLargeChange:{type:"boolean",description:"Set to true to confirm large deletions (>50% difference)"}},required:["path","newContent"]}}}execute(e){try{return!e.newContent||e.newContent.trim().length===0?this.formatError("Merge","newContent parameter is required"):this.performThreeWayMerge(e)}catch(t){return this.formatError("Merge",t)}}checkLargeDeletion(e,t,n=Xl){if(t>=e)return{isLargeDeletion:!1,deletionRatio:0,message:""};let r=e-t,s=e>0?r/e:0,i=r>=n.minLineDiff&&s>=n.lineRatioThreshold,a="";if(i){let c=Math.round(s*100);a=`\u26A0\uFE0F LARGE DELETION DETECTED: ${e} \u2192 ${t} lines (${c}% deleted, ${r} lines removed).
|
|
388
371
|
|
|
389
372
|
This may indicate:
|
|
390
373
|
- Incomplete content (missing parts of the file)
|
|
@@ -392,30 +375,30 @@ This may indicate:
|
|
|
392
375
|
- Wrong file content
|
|
393
376
|
|
|
394
377
|
To proceed, call merge() again with confirmLargeChange=true.
|
|
395
|
-
Or review your newContent to ensure it's complete.`}return{isLargeDeletion:i,deletionRatio:s,message:a}}performThreeWayMerge(e){try{console.log(` [MergeTool] \u5F00\u59CB\u667A\u80FD\u5408\u5E76: ${e.path}`);let t=
|
|
396
|
-
`?"CRLF":"LF"}`);let i=
|
|
378
|
+
Or review your newContent to ensure it's complete.`}return{isLargeDeletion:i,deletionRatio:s,message:a}}performThreeWayMerge(e){try{console.log(` [MergeTool] \u5F00\u59CB\u667A\u80FD\u5408\u5E76: ${e.path}`);let t=Yl(e.path),n=`${t}.base`;if(!Ko(t))return console.log(" [MergeTool] \u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u521B\u5EFA\u65B0\u6587\u4EF6"),this.writeNewFile(t,n,e.newContent);console.log(" [MergeTool] \u8BFB\u53D6\u5F53\u524D\u6587\u4EF6\u5185\u5BB9...");let r=ma(t,"utf-8");console.log(` [MergeTool] \u5F53\u524D\u6587\u4EF6\u5927\u5C0F: ${r.length} \u5B57\u7B26`);let s=Sr(r);console.log(` [MergeTool] \u68C0\u6D4B\u5230\u884C\u7ED3\u675F\u7B26: ${s===`\r
|
|
379
|
+
`?"CRLF":"LF"}`);let i=Xo(r),a=Xo(e.newContent),c=i.split(`
|
|
397
380
|
`).length,l=a.split(`
|
|
398
|
-
`).length;if(!e.confirmLargeChange){let
|
|
399
|
-
`&&(
|
|
400
|
-
`)),
|
|
401
|
-
`).length}\u884C, current=${c}\u884C, incoming=${l}\u884C`);let m=Date.now(),
|
|
402
|
-
`&&(
|
|
403
|
-
`)),
|
|
381
|
+
`).length;if(!e.confirmLargeChange){let h=this.checkLargeDeletion(c,l);if(h.isLargeDeletion)return console.log(` [MergeTool] \u68C0\u6D4B\u5230\u5927\u5E45\u5220\u51CF\uFF08${c} \u2192 ${l}\u884C\uFF09\uFF0C\u9700\u8981\u786E\u8BA4`),h.message}let g=r,p=!1;Ko(n)&&(console.log(" [MergeTool] \u53D1\u73B0\u57FA\u7840\u7248\u672C\u6587\u4EF6\uFF0C\u8BFB\u53D6\u4E2D..."),g=ma(n,"utf-8"),p=!0,console.log(` [MergeTool] \u57FA\u7840\u7248\u672C\u5927\u5C0F: ${g.length} \u5B57\u7B26`));let u=Xo(g);if(u===i){console.log(" [MergeTool] \u65E0\u5E76\u53D1\u4FEE\u6539\uFF08base === current\uFF09\uFF0C\u76F4\u63A5\u5199\u5165");let h=a;if(s===`\r
|
|
382
|
+
`&&(h=h.replace(/\n/g,`\r
|
|
383
|
+
`)),vr(t,h,"utf-8"),p)try{Yo(n)}catch{}return"Merge successful (direct write, no concurrent edits)."}console.log(" [MergeTool] \u68C0\u6D4B\u5230\u5E76\u53D1\u4FEE\u6539\uFF0C\u6267\u884C\u4E09\u8DEF\u5408\u5E76..."),console.log(` [MergeTool] base=${u.split(`
|
|
384
|
+
`).length}\u884C, current=${c}\u884C, incoming=${l}\u884C`);let m=Date.now(),d=ga(u,i,a),y=((Date.now()-m)/1e3).toFixed(2);console.log(` [MergeTool] threeWayMerge \u5B8C\u6210\uFF0C\u8017\u65F6 ${y}s, \u6709\u51B2\u7A81: ${d.hasConflicts}`);let w=d.merged;if(s===`\r
|
|
385
|
+
`&&(w=w.replace(/\n/g,`\r
|
|
386
|
+
`)),d.hasConflicts)return vr(t,w,"utf-8"),`Merge completed with CONFLICTS. File saved with conflict markers.
|
|
404
387
|
Conflicts:
|
|
405
|
-
${
|
|
388
|
+
${d.conflicts.map(b=>`Line ${b.lineNumber}: BASE="${b.base.substring(0,50)}..." | CURRENT="${b.current.substring(0,50)}..." | INCOMING="${b.incoming.substring(0,50)}..."`).join(`
|
|
406
389
|
`)}
|
|
407
390
|
|
|
408
|
-
Please resolve conflicts manually or use write() to overwrite.`;if(
|
|
409
|
-
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\'/g,"'")),
|
|
391
|
+
Please resolve conflicts manually or use write() to overwrite.`;if(vr(t,w,"utf-8"),p)try{Yo(n)}catch{}return"Merge successful (three-way merge, concurrent edits preserved)."}catch(t){return this.formatError("Merge",t)}}writeNewFile(e,t,n){try{let r=typeof n=="string"?n:String(n||"");if(vr(e,r,"utf-8"),Ko(t))try{Yo(t)}catch{}return`File created: ${e}`}catch(r){return this.formatError("Failed to create file",r)}}},da=new kt;bn=da});import{EOL as Qo}from"os";function ha(o,e={}){let{preserveEscapes:t=!1,targetFormat:n="lf"}=e,r=o;if(t||(r=r.replace(/\\n/g,`
|
|
392
|
+
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\'/g,"'")),r=r.replace(/\r\n/g,`
|
|
410
393
|
`).replace(/\r/g,`
|
|
411
|
-
`),n!=="preserve"&&n!=="lf")switch(n){case"crlf":
|
|
412
|
-
`);break;case"cr":
|
|
413
|
-
`&&(
|
|
414
|
-
`));break}return
|
|
415
|
-
`,
|
|
416
|
-
`,
|
|
394
|
+
`),n!=="preserve"&&n!=="lf")switch(n){case"crlf":r=r.replace(/\n/g,`\r
|
|
395
|
+
`);break;case"cr":r=r.replace(/\n/g,"\r");break;case"platform":Qo===`\r
|
|
396
|
+
`&&(r=r.replace(/\n/g,`\r
|
|
397
|
+
`));break}return r}function Ql(o){if(!o)return{style:"none",dominant:Qo,statistics:{crlf:0,lf:0,cr:0},confidence:0};let e={crlf:(o.match(/\r\n/g)||[]).length,lf:(o.match(/(?<!\r)\n/g)||[]).length,cr:(o.match(/\r(?!\n)/g)||[]).length},t=e.crlf+e.lf+e.cr;if(t===0)return{style:"none",dominant:Qo,statistics:e,confidence:0};let n=`
|
|
398
|
+
`,r=e.lf,s="lf";e.crlf>r&&(n=`\r
|
|
399
|
+
`,r=e.crlf,s="crlf"),e.cr>r&&(n="\r",r=e.cr,s="cr");let i=r/t,a;return i===1||i>.8?a=s:a="mixed",{style:a,dominant:n,statistics:e,confidence:i}}var br,ya=S(()=>{br=class{originalContent;normalizedContent;originalStyle;constructor(e){this.originalContent=e,this.originalStyle=Ql(e),this.normalizedContent=ha(e,{preserveEscapes:!0,targetFormat:"lf"})}getNormalizedContent(){return this.normalizedContent}getOriginalStyle(){return this.originalStyle}restoreLineEndings(e){return this.originalStyle.style==="crlf"||this.originalStyle.dominant===`\r
|
|
417
400
|
`?e.replace(/\n/g,`\r
|
|
418
|
-
`):this.originalStyle.style==="cr"||this.originalStyle.dominant==="\r"?e.replace(/\n/g,"\r"):e}convertTo(e){return
|
|
401
|
+
`):this.originalStyle.style==="cr"||this.originalStyle.dominant==="\r"?e.replace(/\n/g,"\r"):e}convertTo(e){return ha(this.originalContent,{preserveEscapes:!0,targetFormat:e})}}});import{existsSync as Zl,readFileSync as eu,writeFileSync as tu}from"fs";import{resolve as nu}from"path";function Tn(o){return Ca.execute(o)}var Pt,Ca,kn,Sa=S(()=>{q();ya();Pt=class extends E{getDefinition(){return{name:"searchReplace",description:`Perform TARGETED SEARCH & REPLACE operations on files.
|
|
419
402
|
|
|
420
403
|
\u{1F3AF} PERFECT FOR:
|
|
421
404
|
- Small configuration updates (port numbers, URLs, etc.)
|
|
@@ -436,39 +419,120 @@ Please resolve conflicts manually or use write() to overwrite.`;if(Yn(t,f,"utf-8
|
|
|
436
419
|
\u{1F4A1} TIPS:
|
|
437
420
|
- Use precise search text to avoid unintended replacements
|
|
438
421
|
- Test with small changes first
|
|
439
|
-
- For complex modifications, consider using merge() tool instead`,input_schema:{type:"object",properties:{path:{type:"string",description:"The file path to perform search/replace operations on"},operations:{type:"array",description:"Array of search/replace operations. Each operation replaces search text with replace text.",items:{type:"object",properties:{search:{type:"string",description:"Exact text to search for"},replace:{type:"string",description:"Text to replace the search text with"}},required:["search","replace"]}}},required:["path","operations"]}}}execute(e){try{if(!e.path||e.path.trim().length===0)return this.formatError("SearchReplace","Path parameter is required");if(!e.operations||!Array.isArray(e.operations)||e.operations.length===0)return this.formatError("SearchReplace","Operations array is required and must not be empty");let t=
|
|
440
|
-
`)&&(
|
|
441
|
-
`)),
|
|
422
|
+
- For complex modifications, consider using merge() tool instead`,input_schema:{type:"object",properties:{path:{type:"string",description:"The file path to perform search/replace operations on"},operations:{type:"array",description:"Array of search/replace operations. Each operation replaces search text with replace text.",items:{type:"object",properties:{search:{type:"string",description:"Exact text to search for"},replace:{type:"string",description:"Text to replace the search text with"}},required:["search","replace"]}}},required:["path","operations"]}}}execute(e){try{if(!e.path||e.path.trim().length===0)return this.formatError("SearchReplace","Path parameter is required");if(!e.operations||!Array.isArray(e.operations)||e.operations.length===0)return this.formatError("SearchReplace","Operations array is required and must not be empty");let t=nu(e.path);if(!Zl(t))return this.formatError("SearchReplace",`File not found: ${t}`);let n=eu(t,"utf-8"),r=new br(n),s=r.getOriginalStyle(),i=r.getNormalizedContent(),a=0,c=[];for(let[p,u]of e.operations.entries()){let{search:m,replace:d}=u;if(!m||m.trim().length===0){c.push(`\u274C Operation ${p+1}: empty search text`);continue}try{i.includes(m)?(i=i.replace(m,d),a++,c.push(`\u2705 Operation ${p+1}: "${m.substring(0,30)}..." \u2192 "${d.substring(0,30)}..."`)):c.push(`\u274C Operation ${p+1}: search text not found "${m.substring(0,30)}..."`)}catch(y){c.push(`\u274C Operation ${p+1}: ${y instanceof Error?y.message:String(y)}`)}}if(a>0){let p=r.restoreLineEndings(i);(s.style==="crlf"||s.dominant===`\r
|
|
423
|
+
`)&&(p=p.replace(/\n/g,`\r
|
|
424
|
+
`)),tu(t,p,"utf-8")}let l=`Search/replace completed. ${a} of ${e.operations.length} operations applied successfully.`,g=c.length>0?`
|
|
442
425
|
|
|
443
426
|
Operation details:
|
|
444
427
|
${c.join(`
|
|
445
|
-
`)}`:"";return l+
|
|
446
|
-
`).forEach(
|
|
428
|
+
`)}`:"";return l+g}catch(t){return this.formatError("SearchReplace",t)}}formatError(e,t){let n=t instanceof Error?t.message:String(t);return`[${e} Error] ${n}`}},Ca=new Pt;kn=Ca});var Zo={};j(Zo,{CopyTool:()=>Tt,DeleteTool:()=>vt,MergeTool:()=>kt,MkdirTool:()=>xt,MoveTool:()=>bt,ReadTool:()=>St,SearchReplaceTool:()=>Pt,WriteTool:()=>wt,copyFile:()=>xn,copyTool:()=>wn,deleteFile:()=>hn,deleteTool:()=>yn,merge:()=>vn,mergeTool:()=>bn,mkdir:()=>mn,mkdirTool:()=>Qe,moveFile:()=>Cn,moveTool:()=>Sn,read:()=>gn,readTool:()=>pn,searchReplace:()=>Tn,searchReplaceTool:()=>kn,write:()=>dn,writeTool:()=>fn});var Tr=S(()=>{Bi();Qi();Bo();Zi();na();ua();fa();Sa()});import{readFileSync as ru,existsSync as ou}from"fs";import{resolve as su}from"path";function au(o){let e=su(o,".niumignore"),t=[];if(ou(e))try{ru(e,"utf-8").split(`
|
|
429
|
+
`).forEach(r=>{let s=r.trim();s&&!s.startsWith("#")&&t.push(cu(s))})}catch(n){console.warn(`Error reading .niumignore file: ${n instanceof Error?n.message:"Unknown error"}`)}return t}function $t(o,e=!0){let t=au(o);return e?[...iu,...t]:t}function cu(o){if(o.startsWith("!")){let e=o.slice(1);return e.includes("/")||e.includes("\\")?o:`!**/${e}`}return o.includes("*")||o.includes("?")||o.includes("{")||o.includes("[")?o:o.endsWith("/")?`**/${o.slice(0,-1)}/**`:o.startsWith("*.")?o:!o.includes("/")&&!o.includes("\\")?`**/${o}/**`:o}var iu,kr=S(()=>{iu=["**/.git/**","**/.svn/**","**/.hg/**","**/node_modules/**","**/vendor/**","**/.pnpm/**","**/bower_components/**","**/dist/**","**/build/**","**/out/**","**/target/**","**/.next/**","**/.nuxt/**","**/.output/**","**/.idea/**","**/.vscode/**","**/.vs/**","**/*.swp","**/*.swo","**/*~","**/.DS_Store","**/Thumbs.db","**/desktop.ini","**/.cache/**","**/tmp/**","**/temp/**","**/__pycache__/**","**/*.pyc","**/.pytest_cache/**","**/*.log","**/logs/**","**/.nium/archives/**","**/.nium/session.json","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/Gemfile.lock","**/Pipfile.lock","**/poetry.lock","**/Cargo.lock"]});import{globSync as xa}from"glob";function Pn(o){return wa.execute(o)}var Et,wa,$n,va=S(()=>{q();kr();Et=class extends E{getDefinition(){return{name:"glob",description:`Search for files matching a glob pattern.
|
|
447
430
|
|
|
448
431
|
Examples:
|
|
449
432
|
- glob("*.js") - all .js files in current directory
|
|
450
433
|
- glob("**/*.ts") - all .ts files recursively
|
|
451
434
|
- glob("src/**/*.{js,ts}") - all .js and .ts files under src/
|
|
452
435
|
|
|
453
|
-
Returns an array of matching file paths.`,input_schema:{type:"object",properties:{pattern:{type:"string",description:'The glob pattern to match (e.g., "*.js", "**/*.ts")'},cwd:{type:"string",description:"Optional: the directory to search in (defaults to current directory)"}},required:["pattern"]}}}execute(e){try{let t=e.cwd||process.cwd(),n
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
-
|
|
457
|
-
-
|
|
458
|
-
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
-
|
|
470
|
-
-
|
|
471
|
-
-
|
|
436
|
+
Returns an array of matching file paths.`,input_schema:{type:"object",properties:{pattern:{type:"string",description:'The glob pattern to match (e.g., "*.js", "**/*.ts")'},cwd:{type:"string",description:"Optional: the directory to search in (defaults to current directory)"}},required:["pattern"]}}}execute(e){try{let t=e.cwd||process.cwd(),n=$t(t),r=xa(e.pattern,{nodir:!0,cwd:e.cwd,ignore:n});if(r.length===0&&!e.pattern.startsWith("*")&&!e.pattern.startsWith("**")){let s=`**/${e.pattern}`;r=xa(s,{nodir:!0,cwd:e.cwd,ignore:n})}return r.length>0?r:`No files matching pattern: ${e.pattern}`}catch(t){return this.formatError("Glob pattern",t)}}},wa=new Et;$n=wa});import{readFileSync as ba}from"fs";import{dirname as lu}from"path";import{globSync as uu}from"glob";function En(o){return Ta.execute(o)}var Mt,Ta,Mn,ka=S(()=>{q();kr();Mt=class extends E{getDefinition(){return{name:"grep",description:`Search for text patterns in files using regular expressions with glob support.
|
|
437
|
+
|
|
438
|
+
\u{1F4CB} USE CASES:
|
|
439
|
+
- Find code patterns and function definitions
|
|
440
|
+
- Search for TODOs and FIXMEs across the codebase
|
|
441
|
+
- Locate configuration settings in multiple files
|
|
442
|
+
- Find all occurrences of a specific variable or class
|
|
443
|
+
- Search for error messages and log patterns
|
|
444
|
+
|
|
445
|
+
\u{1F511} PARAMETERS:
|
|
446
|
+
- pattern: Regular expression pattern to search for (required)
|
|
447
|
+
- path: File path or glob pattern (supports **/*.js, *.{js,ts}, etc.)
|
|
448
|
+
|
|
449
|
+
\u{1F4A1} EXAMPLES:
|
|
450
|
+
- grep({ pattern: "function.*foo", path: "src/main.js" }) - Find function definitions containing "foo" in a single file
|
|
451
|
+
- grep({ pattern: "TODO", path: "**/*.js" }) - Find all TODOs in all JavaScript files
|
|
452
|
+
- grep({ pattern: "import", path: "src/**/*.{js,ts}" }) - Find all import statements in JS/TS files
|
|
453
|
+
- grep({ pattern: "class.*Component", path: "src/components/**/*.tsx" }) - Find React components
|
|
454
|
+
- grep({ pattern: "error", path: "logs/**/*.log" }) - Search for errors in log files
|
|
455
|
+
|
|
456
|
+
\u{1F4DD} RETURN VALUE:
|
|
457
|
+
- Array of matching lines with filenames and line numbers
|
|
458
|
+
- Matching lines formatted as: filename:line: content
|
|
459
|
+
- Summary statistics for multiple files
|
|
460
|
+
- Helpful error messages for invalid patterns or no matches
|
|
461
|
+
|
|
462
|
+
\u{1F50D} FEATURES:
|
|
463
|
+
- Supports regular expressions (regex)
|
|
464
|
+
- Cross-platform glob pattern matching
|
|
465
|
+
- Ignores system and gitignore files
|
|
466
|
+
- Case-sensitive matching (use regex flags for case-insensitive)
|
|
467
|
+
- Handles large files efficiently`,input_schema:{type:"object",properties:{pattern:{type:"string",description:"Regular expression pattern to search for"},path:{type:"string",description:"File path or glob pattern (e.g., 'src/main.js' or '**/*.js')"}},required:["pattern","path"]}}}execute(e){try{let t=[];try{let i=e.path.includes("/")||e.path.includes("\\")?lu(e.path):process.cwd(),c={nodir:!0,windowsPathsNoEscape:!0,absolute:!1,ignore:$t(i)};if(e.path.includes("*")||e.path.includes("?")||e.path.includes("{")){if(console.log(`Processing glob pattern: ${e.path}`),t=uu(e.path,c),t.length===0)return`No files found matching pattern: ${e.path}`;console.log(`Found ${t.length} files matching pattern`)}else try{let g=ba(e.path,"utf-8");t=[e.path]}catch(g){return g instanceof Error?`Error: ${g.message}`:`Error: Could not read file: ${e.path}`}}catch(i){return console.error("Glob error:",i),i instanceof Error?`Error: Grep failed - ${i.message}`:`Error: Grep failed - Unknown error processing glob pattern: ${e.path}`}if(t.length===0)return`No files found matching pattern: ${e.path}`;let n=new RegExp(e.pattern),r=[],s=0;return t.forEach(i=>{try{let c=ba(i,"utf-8").split(`
|
|
468
|
+
`),l=[];c.forEach((g,p)=>{n.test(g)&&(l.push(`${i}:${p+1}: ${g}`),s++)}),l.length>0&&r.push(...l)}catch(a){r.push(`Error reading file ${i}: ${a instanceof Error?a.message:"Unknown error"}`)}}),s>0?(t.length>1&&r.unshift(`Found ${s} matches in ${t.length} files`),r):`No matches found for pattern: ${e.pattern} in ${t.length} files`}catch(t){return this.formatError("Grep",t)}}},Ta=new Mt;Mn=Ta});var es={};j(es,{GlobTool:()=>Et,GrepTool:()=>Mt,glob:()=>Pn,globTool:()=>$n,grep:()=>En,grepTool:()=>Mn});var Pr=S(()=>{va();ka()});import{execSync as gu,exec as pu,spawnSync as mu}from"child_process";import*as $r from"os";async function $a(){if(Pa)return ts;Pa=!0;try{let o=await import("iconv-lite");return ts=o.default||o,ts}catch{return console.warn("iconv-lite not available, using utf8 fallback for Windows encoding"),null}}function In(o){return Promise.resolve(At.execute(o))}var ts,Pa,It,At,Ea=S(()=>{q();ts=null,Pa=!1;It=class o extends E{static HIGH_RISK_COMMANDS=["rm -rf","rm -r","del /q /s","erase /f /s","format","mkfs","dd if=","mv /force","shred","wipe","truncate -s 0","> filename","chmod -R 000","chown -R root:root"];isHighRiskCommand(e){if(!e)return!1;let t=e.toLowerCase().trim();return o.HIGH_RISK_COMMANDS.some(n=>t.includes(n.toLowerCase()))}isUnixCommand(e){return["ls","pwd","which","cat","rm","cp","mv","mkdir","grep","find","head","tail","touch","chmod","chown","ps","kill","ifconfig","netstat","top","df","du","wc","awk","sed","tar","gzip","ssh"].includes(e.toLowerCase())}convertUnixToWindowsCommand(e){let t={ls:"dir","ls -la":"dir","ls -l":"dir","ls -a":"dir /a",pwd:"cd",which:"where",cat:"type",rm:"del","rm -rf":"rmdir /s /q","rm -r":"rmdir /s /q",cp:"copy","cp -r":"xcopy /e /i /y",mv:"move",mkdir:"mkdir","mkdir -p":"mkdir",grep:"findstr",find:"findstr",head:"more",tail:"more +n",touch:"type nul >",chmod:"attrib",chown:"attrib",ps:"tasklist",kill:"taskkill",ifconfig:"ipconfig",netstat:"netstat",top:"tasklist /v",df:"wmic logicaldisk get size,freespace,caption",du:"dir /s",wc:'find /c /v ""'};if(t[e])return t[e];let n=Object.entries(t).sort((r,s)=>s[0].length-r[0].length);for(let[r,s]of n)if(e.startsWith(r+" ")){if(r==="rm -rf"||r==="rm -r"){let i=e.substring(r.length).trim();return`${s} ${i}`}return e.replace(r,s)}return e}getShellCommand(e){let t=$r.platform(),n=e||"";return t==="win32"&&n&&(n=this.convertUnixToWindowsCommand(n)),t==="win32"?{shell:"cmd.exe",args:[],cmd:n}:{shell:"/bin/sh",args:["-c"],cmd:n}}getDefinition(){return{name:"shell",description:`Execute shell commands on the system with intelligent cross-platform support.
|
|
469
|
+
|
|
470
|
+
\u{1F30D} **\u667A\u80FD\u73AF\u5883\u611F\u77E5**
|
|
471
|
+
\u6B64\u5DE5\u5177\u4F1A\u6839\u636E\u5F53\u524D\u8FD0\u884C\u5E73\u53F0\u81EA\u52A8\u4F18\u5316\u547D\u4EE4\u6267\u884C\uFF1A
|
|
472
|
+
- Windows: \u81EA\u52A8\u8F6C\u6362Unix\u547D\u4EE4\u4E3AWindows\u7B49\u4EF7\u547D\u4EE4
|
|
473
|
+
- macOS/Linux: \u4F7F\u7528\u539F\u751FUnix\u547D\u4EE4
|
|
474
|
+
|
|
475
|
+
\u{1F4CB} **USE CASES:**
|
|
476
|
+
- Run system commands and utilities
|
|
477
|
+
- Execute package managers (npm, pip, brew, winget, etc.)
|
|
478
|
+
- Run build scripts and automation tasks
|
|
479
|
+
- List directory contents and file operations
|
|
480
|
+
- Install dependencies and software packages
|
|
481
|
+
|
|
482
|
+
\u26A0\uFE0F **CRITICAL SAFETY FEATURES:**
|
|
483
|
+
- High-risk commands (rm -rf, format, etc.) require user confirmation
|
|
484
|
+
- **Cross-platform compatibility with automatic Unix-to-Windows command conversion**
|
|
485
|
+
- Automatic UTF-8 encoding handling
|
|
486
|
+
- Command not found detection with helpful suggestions
|
|
487
|
+
- Configurable timeout protection
|
|
488
|
+
|
|
489
|
+
\u{1F511} **PARAMETERS:**
|
|
490
|
+
- command: Shell command to execute (required)
|
|
491
|
+
- timeout: Maximum execution time in milliseconds (default: 60000)
|
|
492
|
+
- captureOutput: Whether to capture and return command output (default: true)
|
|
493
|
+
|
|
494
|
+
\u{1F4A1} **CROSS-PLATFORM EXAMPLES:**
|
|
495
|
+
- shell({ command: "ls -la" }) - List directory (auto-converts to 'dir' on Windows)
|
|
496
|
+
- shell({ command: "pwd" }) - Show current directory (auto-converts to 'cd' on Windows)
|
|
497
|
+
- shell({ command: "which node" }) - Find command location (auto-converts to 'where' on Windows)
|
|
498
|
+
- shell({ command: "cat file.txt" }) - Display file content (auto-converts to 'type' on Windows)
|
|
499
|
+
- shell({ command: "npm install", timeout: 30000 }) - Run npm install with 30s timeout
|
|
500
|
+
- shell({ command: "python --version" }) - Check Python version
|
|
501
|
+
- shell({ command: "git status" }) - Check git repository status
|
|
502
|
+
|
|
503
|
+
\u{1F4DD} **RETURN VALUE:**
|
|
504
|
+
- Command output with platform information
|
|
505
|
+
- **Helpful error messages with platform-specific suggestions**
|
|
506
|
+
- **Unix-to-Windows command conversion notifications**
|
|
507
|
+
- Execution status and success flag
|
|
508
|
+
- Friendly installation suggestions for missing commands
|
|
509
|
+
|
|
510
|
+
\u{1F504} **AUTOMATIC CONVERSIONS:**
|
|
511
|
+
- ls \u2192 dir, pwd \u2192 cd, which \u2192 where, cat \u2192 type
|
|
512
|
+
- rm -rf \u2192 rmdir /s /q, cp \u2192 copy, mv \u2192 move
|
|
513
|
+
- grep \u2192 findstr, ps \u2192 tasklist, ifconfig \u2192 ipconfig`,input_schema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute"},timeout:{type:"number",description:"Maximum execution time in milliseconds (default: 60000)",default:6e4},captureOutput:{type:"boolean",description:"Whether to capture and return command output (default: true)",default:!0}},required:["command"]},requiresConfirmation:!1}}getDynamicDefinition(e){return{...this.getDefinition(),requiresConfirmation:this.isHighRiskCommand(e.command)}}isCommandNotFoundError(e,t){if(!e)return!1;let n=e.toLowerCase();return(t==="win32"?["\u4E0D\u662F\u5185\u90E8\u6216\u5916\u90E8\u547D\u4EE4","\u4E0D\u662F\u53EF\u8FD0\u884C\u7684\u7A0B\u5E8F","is not recognized as an internal or external command","is not recognized as","'command' is not recognized","\u627E\u4E0D\u5230\u547D\u4EE4","\u65E0\u6CD5\u5C06","command not found"]:["command not found","not found","no such file or directory","cannot find","bash: command not found","sh: command not found","zsh: command not found"]).some(a=>n.includes(a))}extractCommandName(e){let t=e?e.trim():"",n=t.match(/^(\S+)/);return n?n[1]:t}generateCommandNotFoundMessage(e,t){let n=t==="win32"?"Windows":t==="darwin"?"macOS":"Linux",r={git:{win:"Download from https://git-scm.com/download/win or use 'winget install Git.Git'",unix:"Install using: sudo apt-get install git (Ubuntu/Debian) or brew install git (macOS)",description:"Version control system"},python:{win:"Download from https://www.python.org/downloads/ or use 'winget install Python.Python.3'",unix:"Install using: sudo apt-get install python3 (Ubuntu/Debian) or brew install python3 (macOS)",description:"Python programming language"},node:{win:"Download from https://nodejs.org/ or use 'winget install OpenJS.NodeJS'",unix:"Install using: sudo apt-get install nodejs (Ubuntu/Debian) or brew install node (macOS)",description:"Node.js JavaScript runtime"},npm:{win:"Install Node.js from https://nodejs.org/ (includes npm)",unix:"Install Node.js (includes npm): sudo apt-get install nodejs npm or brew install node",description:"Node Package Manager (comes with Node.js)"},docker:{win:"Download Docker Desktop from https://www.docker.com/products/docker-desktop",unix:"Install using: sudo apt-get install docker.io (Ubuntu/Debian) or brew install docker (macOS)",description:"Container platform"},curl:{win:"Usually built-in on Windows 10+. If missing, download from https://curl.se/windows/",unix:"Install using: sudo apt-get install curl (Ubuntu/Debian) or brew install curl (macOS)",description:"Command-line tool for transferring data with URLs"},wget:{win:"Download from https://eternallybored.org/misc/wget/ or use 'winget install GNU.Wget'",unix:"Install using: sudo apt-get install wget (Ubuntu/Debian) or brew install wget (macOS)",description:"Network downloader"},make:{win:"Install via Chocolatey: choco install make or use WSL",unix:"Install using: sudo apt-get install build-essential (Ubuntu/Debian) or xcode-select --install (macOS)",description:"Build automation tool"},gcc:{win:"Install MinGW from http://mingw.org/ or use Visual Studio Build Tools",unix:"Install using: sudo apt-get install build-essential (Ubuntu/Debian) or xcode-select --install (macOS)",description:"GNU Compiler Collection"},code:{win:"Install VS Code from https://code.visualstudio.com/ and add to PATH during installation",unix:"Install VS Code and run: sudo ln -s /Applications/Visual\\ Studio\\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/code",description:"Visual Studio Code editor"}};if(e.toLowerCase()==="ls"&&t==="win32")return`\u274C Command Not Found: '${e}'
|
|
514
|
+
|
|
515
|
+
\u{1F5A5}\uFE0F Current Environment: ${n}
|
|
516
|
+
|
|
517
|
+
\u{1F504} Unix to Windows Translation: The 'ls' command is a Unix/Linux command. On Windows, use 'dir' instead.
|
|
518
|
+
|
|
519
|
+
\u{1F4A1} Windows Equivalent Commands:
|
|
520
|
+
- ls \u2192 dir
|
|
521
|
+
- ls -la \u2192 dir
|
|
522
|
+
- ls -l \u2192 dir
|
|
523
|
+
- ls -a \u2192 dir /a
|
|
524
|
+
|
|
525
|
+
\u{1F4CB} Common Windows Directory Commands:
|
|
526
|
+
- dir: List directory contents
|
|
527
|
+
- dir /a: List all files including hidden ones
|
|
528
|
+
- dir /w: Wide format listing
|
|
529
|
+
- dir /p: Pause after each screen
|
|
530
|
+
- dir /s: List files in all subdirectories
|
|
531
|
+
|
|
532
|
+
\u{1F3AF} Try this instead:
|
|
533
|
+
dir
|
|
534
|
+
|
|
535
|
+
\u26A0\uFE0F Please use Windows equivalent commands for better compatibility.`;let s=r[e.toLowerCase()],i=`\u274C Command Not Found: '${e}'
|
|
472
536
|
|
|
473
537
|
`;return i+=`\u{1F5A5}\uFE0F Current Environment: ${n}
|
|
474
538
|
|
|
@@ -493,36 +557,38 @@ Examples:
|
|
|
493
557
|
`,i+=` - dnf: sudo dnf install <package-name> (Fedora)
|
|
494
558
|
`))),i+=`
|
|
495
559
|
\u26A0\uFE0F Please install the required command before proceeding.
|
|
496
|
-
`,i+=" The AI assistant cannot continue without this tool being available.",i}async execute(e){try{let{command:t,timeout:n=6e4,captureOutput:
|
|
497
|
-
${
|
|
560
|
+
`,i+=" The AI assistant cannot continue without this tool being available.",i}async execute(e){try{let{command:t,timeout:n=6e4,captureOutput:r=!0}=e;if(!t){let u=$r.platform(),d=`Running on ${u} with ${u==="win32"?"cmd.exe":"/bin/sh"}`,y=`Executing command: ${t}`;return console.error("[SHELL TOOL ERROR] Command is undefined or null"),console.error("[SHELL TOOL ERROR] Input received:",JSON.stringify(e,null,2)),console.error("[SHELL TOOL ERROR] Stack trace:",new Error().stack),this.createToolResult({error:"Command is undefined or null",success:!1},`${d}
|
|
561
|
+
${y}
|
|
498
562
|
|
|
499
563
|
Command failed with error:
|
|
500
|
-
TypeError: Command is undefined or null`)}let s
|
|
564
|
+
TypeError: Command is undefined or null`)}let s=$r.platform(),{shell:i,args:a,cmd:c}=this.getShellCommand(t),l={shell:i,timeout:n,encoding:"utf8",windowsHide:!0,windowsVerbatimArguments:s==="win32"},g=`Running on ${s} with ${i}`,p=`Executing command: ${t}`;if(r)try{let u="";if(s==="win32"){let m=`chcp 65001 >nul 2>&1 && ${c}`,d=mu("cmd.exe",["/c",m],{stdio:"pipe",windowsHide:!0,encoding:"buffer"}),y=d.stdout||Buffer.alloc(0),w=d.stderr||Buffer.alloc(0),h=Buffer.concat([y,w]);try{let b=await $a();if(b){let f=["cp936","gbk","utf8","gb2312","big5"],T=!1;for(let x of f)try{if(u=b.decode(h,x),/[\u4e00-\u9fff]/.test(u)||u.length>0){T=!0;break}}catch{continue}T||(u=h.toString("utf8"))}else u=h.toString("utf8");d.status===0&&u&&u.trim()&&(u+=`
|
|
501
565
|
|
|
502
|
-
\u2705 Windows\u7F16\u7801\u5DF2\u4F18\u5316\u5904\u7406`)}catch{
|
|
503
|
-
${
|
|
566
|
+
\u2705 Windows\u7F16\u7801\u5DF2\u4F18\u5316\u5904\u7406`)}catch{u=h.toString("utf8")}}else{let m=[...a,c].join(" ");u=gu(m,l).toString()}if(this.isCommandNotFoundError(u,s)){let m=this.extractCommandName(t),d=this.generateCommandNotFoundMessage(m,s);return this.createToolResult({error:u,success:!1,commandNotFound:!0},`${g}
|
|
567
|
+
${p}
|
|
504
568
|
|
|
505
|
-
${
|
|
569
|
+
${d}
|
|
506
570
|
|
|
507
571
|
Original error:
|
|
508
|
-
${
|
|
509
|
-
${
|
|
572
|
+
${u}`,!0)}return this.createToolResult(u,`${g}
|
|
573
|
+
${p}
|
|
510
574
|
|
|
511
575
|
Command output:
|
|
512
|
-
${
|
|
513
|
-
|
|
576
|
+
${u}`)}catch(u){let m="";if(s==="win32"&&u.stderr){let d=Buffer.isBuffer(u.stderr)?u.stderr:Buffer.from(u.stderr),y=await $a();if(y)try{let w=["cp936","gbk","utf8","gb2312"],h="";for(let b of w)try{if(h=y.decode(d,b),h.length>0){m+=h;break}}catch{continue}h||(m+=d.toString("utf8"))}catch{m+=d.toString("utf8")}else m+=d.toString("utf8")}else u.stderr&&(m+=u.stderr),u.stdout&&(m+=u.stdout),m||(m=String(u));if(this.isCommandNotFoundError(m,s)){let d=this.extractCommandName(t),y=this.generateCommandNotFoundMessage(d,s),w=y;return s==="win32"&&this.isUnixCommand(d)&&(w=`\u{1F504} Command Auto-Conversion: Unix command '${d}' was automatically converted to Windows equivalent
|
|
577
|
+
|
|
578
|
+
${y}`),this.createToolResult({error:m,success:!1,commandNotFound:!0},`${g}
|
|
579
|
+
${p}
|
|
514
580
|
|
|
515
|
-
${
|
|
581
|
+
${w}
|
|
516
582
|
|
|
517
583
|
Original error:
|
|
518
|
-
${m}`,!0)}return this.createToolResult({error:m,success:!1},`${
|
|
519
|
-
${
|
|
584
|
+
${m}`,!0)}return this.createToolResult({error:m,success:!1},`${g}
|
|
585
|
+
${p}
|
|
520
586
|
|
|
521
587
|
Command failed with error:
|
|
522
|
-
${m}`,!0)}else{let
|
|
523
|
-
${
|
|
588
|
+
${m}`,!0)}else{let u=t;s==="win32"?u=`chcp 65001 > nul && ${c}`:u=[...a,c].join(" ");let m=pu(u,l);return this.createToolResult({success:!0,message:"Command started in background"},`${g}
|
|
589
|
+
${p}
|
|
524
590
|
|
|
525
|
-
Command started in background. No output will be captured.`,!0)}}catch(t){return this.formatError("Cannot execute shell command",t)}}formatAction(e){let t=super.formatAction(e);return this.isHighRiskCommand(e.command)?`${t} \u26A0\uFE0F HIGH RISK COMMAND - Requires confirmation!`:t}},
|
|
591
|
+
Command started in background. No output will be captured.`,!0)}}catch(t){return this.formatError("Cannot execute shell command",t)}}formatAction(e){let t=super.formatAction(e);return this.isHighRiskCommand(e.command)?`${t} \u26A0\uFE0F HIGH RISK COMMAND - Requires confirmation!`:t}},At=new It});var ns={};j(ns,{ShellTool:()=>It,shell:()=>In,shellTool:()=>At});var Er=S(()=>{Ea()});var os={};j(os,{THINK_TOOL:()=>Mr,ThinkTool:()=>Ze,extractThought:()=>Ir,isThinkTool:()=>Dt,think:()=>Lt,thinkTool:()=>Rt});function Lt(o){return rs.execute(o)}function Dt(o){return o==="think"}function Ir(o){if(!o||!o.function||o.function.name!=="think")return null;try{return JSON.parse(o.function.arguments).thought||null}catch{return null}}var Ze,rs,Rt,Mr,An=S(()=>{q();Ze=class extends E{getDefinition(){return{name:"think",description:`Use this tool to think, reason, and reflect before taking actions.
|
|
526
592
|
This is a zero-side-effect tool that makes your thinking process observable.
|
|
527
593
|
|
|
528
594
|
IMPORTANT: You should call this tool:
|
|
@@ -530,27 +596,51 @@ IMPORTANT: You should call this tool:
|
|
|
530
596
|
- AFTER receiving an Observation (to reflect on the result)
|
|
531
597
|
- When you need to analyze complex situations
|
|
532
598
|
|
|
533
|
-
The thought content will be logged but won't change any data or state.`,input_schema:{type:"object",properties:{thought:{type:"string",description:"Your internal reasoning, analysis, or reflection. Be detailed and explicit about your thought process."}},required:["thought"]}}}execute(e){return"Noted. Continue with your action."}},
|
|
599
|
+
The thought content will be logged but won't change any data or state.`,input_schema:{type:"object",properties:{thought:{type:"string",description:"Your internal reasoning, analysis, or reflection. Be detailed and explicit about your thought process."}},required:["thought"]}}}execute(e){return"Noted. Continue with your action."}},rs=new Ze;Rt=rs,Mr=rs.getDefinition()});var us={};j(us,{SYSTEM_PROMPT:()=>et,generateAgentMatchingPrompt:()=>ls,generateSystemPrompt:()=>Ma,generateTaskComplexityEvaluationPrompt:()=>ss,generateTaskPlanningConversionPrompt:()=>cs,generateTaskPlanningMarkdownPrompt:()=>as,generateTaskPlanningPrompt:()=>is});function Ma(o=Ln()){return`You are an expert code assistant that follows the ReAct (Reasoning + Acting) pattern with enhanced thinking capabilities. Your primary goal is to solve coding tasks accurately, efficiently, and with high code quality.
|
|
534
600
|
|
|
535
601
|
<instructions>
|
|
536
602
|
You have access to a comprehensive set of tools, with the 'think' tool being specially designed for observable reasoning.
|
|
537
603
|
|
|
604
|
+
<environment_awareness>
|
|
605
|
+
\u{1F30D} **\u6838\u5FC3\u539F\u5219\uFF1A\u4F60\u5FC5\u987B\u59CB\u7EC8\u611F\u77E5\u5E76\u9002\u5E94\u8FD0\u884C\u73AF\u5883**
|
|
606
|
+
|
|
607
|
+
**\u73AF\u5883\u611F\u77E5\u662F\u4F60\u7684\u7B2C\u4E00\u4F18\u5148\u7EA7**\uFF1A\u5728\u601D\u8003\u3001\u89C4\u5212\u548C\u6267\u884C\u4EFB\u4F55\u4EFB\u52A1\u4E4B\u524D\uFF0C\u4F60\u5FC5\u987B\uFF1A
|
|
608
|
+
1. \u68C0\u67E5\u5E76\u7406\u89E3\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0\uFF08Windows/macOS/Linux\uFF09
|
|
609
|
+
2. \u6839\u636E\u5E73\u53F0\u7279\u6027\u8C03\u6574\u547D\u4EE4\u9009\u62E9\u548C\u4EE3\u7801\u751F\u6210\u7B56\u7565
|
|
610
|
+
3. \u4E3B\u52A8\u4F7F\u7528\u5E73\u53F0\u539F\u751F\u547D\u4EE4\u548C\u5DE5\u5177
|
|
611
|
+
4. \u9884\u89C1\u5E76\u89E3\u51B3\u8DE8\u5E73\u53F0\u517C\u5BB9\u6027\u95EE\u9898
|
|
612
|
+
|
|
613
|
+
**\u5E73\u53F0\u547D\u4EE4\u4F18\u5148\u7EA7\u89C4\u5219**\uFF1A
|
|
614
|
+
- Windows: \u4F18\u5148\u4F7F\u7528 dir\u3001copy\u3001move\u3001del\u3001where\u3001findstr\u3001ipconfig\u3001tasklist
|
|
615
|
+
- macOS/Linux: \u4F18\u5148\u4F7F\u7528 ls\u3001cp\u3001mv\u3001rm\u3001which\u3001grep\u3001ifconfig\u3001ps
|
|
616
|
+
|
|
617
|
+
**\u8DE8\u5E73\u53F0\u51B3\u7B56\u6846\u67B6**\uFF1A
|
|
618
|
+
1. \u8BC6\u522B\u7528\u6237\u8BF7\u6C42\u7684\u6F5C\u5728\u5E73\u53F0\u4F9D\u8D56\u6027
|
|
619
|
+
2. \u9009\u62E9\u6700\u9002\u5408\u5F53\u524D\u5E73\u53F0\u7684\u5B9E\u73B0\u65B9\u6848
|
|
620
|
+
3. \u5982\u679C\u6D89\u53CAshell\u547D\u4EE4\uFF0C\u4F7F\u7528\u5E73\u53F0\u539F\u751F\u547D\u4EE4
|
|
621
|
+
4. \u4E3B\u52A8\u8BF4\u660E\u8DE8\u5E73\u53F0\u8003\u8651\u56E0\u7D20
|
|
622
|
+
</environment_awareness>
|
|
623
|
+
|
|
538
624
|
<workflow>
|
|
539
625
|
You must follow this strict thinking pattern for EVERY response:
|
|
540
626
|
|
|
541
627
|
1. FIRST: Call the 'think' tool to analyze the situation
|
|
542
628
|
- Examine the user request and available context thoroughly
|
|
629
|
+
- **\u68C0\u67E5\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u5E76\u8003\u8651\u5E73\u53F0\u7279\u6027**
|
|
543
630
|
- Identify knowledge gaps and needed information
|
|
544
631
|
- Plan a clear sequence of actions to accomplish the task
|
|
632
|
+
- **\u6839\u636E\u73AF\u5883\u4FE1\u606F\u8C03\u6574\u6267\u884C\u7B56\u7565**
|
|
545
633
|
- Explain your reasoning with specific details
|
|
546
634
|
|
|
547
635
|
2. THEN: Execute your planned action
|
|
548
636
|
- Call the appropriate tool with correct parameters (based on the available tools list)
|
|
637
|
+
- **\u786E\u4FDD\u547D\u4EE4\u548C\u4EE3\u7801\u9002\u5408\u5F53\u524D\u5E73\u53F0\u73AF\u5883**
|
|
549
638
|
- Ensure parameter values are properly formatted
|
|
550
639
|
- If task is complete, provide a comprehensive final answer
|
|
551
640
|
|
|
552
641
|
3. AFTER receiving an Observation: Call 'think' again to reflect
|
|
553
642
|
- Analyze the tool result critically
|
|
643
|
+
- **\u9A8C\u8BC1\u7ED3\u679C\u662F\u5426\u7B26\u5408\u5F53\u524D\u5E73\u53F0\u9884\u671F**
|
|
554
644
|
- Verify if the expected outcome was achieved
|
|
555
645
|
- Adjust your plan if necessary
|
|
556
646
|
- Decide on the next appropriate action
|
|
@@ -561,7 +651,7 @@ This cycle continues: think \u2192 act \u2192 observe \u2192 think \u2192 act \u
|
|
|
561
651
|
<available_tools>
|
|
562
652
|
You have access to the following tools (detailed schemas are provided separately):
|
|
563
653
|
|
|
564
|
-
${
|
|
654
|
+
${o.map(t=>`- ${t.name}: ${t.description}`).join(`
|
|
565
655
|
`)}
|
|
566
656
|
|
|
567
657
|
The system will provide you with the exact parameter schemas for each tool. When using tools, pay special attention to required parameters and their formats.
|
|
@@ -573,7 +663,14 @@ Use the tool definitions to understand what parameters each tool requires.
|
|
|
573
663
|
2. ALWAYS call 'think' tool AFTER receiving an Observation to reflect
|
|
574
664
|
3. The 'think' tool is zero-side-effect - it only makes your reasoning observable
|
|
575
665
|
4. NEVER write "Observation:" yourself - the system provides it
|
|
576
|
-
5. When you
|
|
666
|
+
5. TASK COMPLETION: When you have completed the task, use the 'finish' tool
|
|
667
|
+
- Call finish({ answer: "comprehensive summary", success: true })
|
|
668
|
+
- The answer should detail what was accomplished, files modified, results achieved
|
|
669
|
+
- This is the RECOMMENDED way to signal task completion
|
|
670
|
+
- Alternative: Return plain text without tool calls (implicit completion fallback)
|
|
671
|
+
- NEVER consider a task complete after just generating a summary
|
|
672
|
+
- ALWAYS continue execution until all steps in your plan are finished
|
|
673
|
+
- ONLY end the task when you have successfully completed the user's original request
|
|
577
674
|
6. Think deeply and systematically: analyze context, plan actions, reflect on results
|
|
578
675
|
7. If you encounter errors or unexpected results, use 'think' to analyze the problem and determine the best next step
|
|
579
676
|
8. ALWAYS maintain high code quality standards - follow project conventions, add appropriate comments, and write clean code
|
|
@@ -590,7 +687,7 @@ When modifying existing code:
|
|
|
590
687
|
- Plan how to update each reference appropriately
|
|
591
688
|
5. Choose the appropriate tool:
|
|
592
689
|
- Use merge() for comprehensive changes to individual files
|
|
593
|
-
- Use
|
|
690
|
+
- Use searchReplace() for batch updates across multiple files (e.g., updating function calls)
|
|
594
691
|
6. If conflicts occur, call think() to decide whether to fix or use write() to overwrite
|
|
595
692
|
7. After making changes, verify the updates by calling grep() again to ensure all references are correctly updated
|
|
596
693
|
|
|
@@ -601,7 +698,7 @@ When creating new files:
|
|
|
601
698
|
|
|
602
699
|
When renaming or doing batch replacements:
|
|
603
700
|
1. Call think() to identify all occurrences and plan the replacement strategy
|
|
604
|
-
2. Use
|
|
701
|
+
2. Use searchReplace() with appropriate search pattern and replacement text
|
|
605
702
|
- For simple text: provide literal strings
|
|
606
703
|
- For patterns: use regex patterns
|
|
607
704
|
- Can target single file or multiple files with glob patterns
|
|
@@ -609,7 +706,7 @@ When renaming or doing batch replacements:
|
|
|
609
706
|
|
|
610
707
|
CRITICAL FILE OPERATION RULES:
|
|
611
708
|
- merge() and write() REQUIRE the complete file content, not just changes
|
|
612
|
-
-
|
|
709
|
+
- searchReplace() is ideal for renaming identifiers, updating imports, or pattern-based replacements
|
|
613
710
|
- Read the file first, prepare the full new version, then call merge() or write()
|
|
614
711
|
- NEVER skip the thinking steps - they make your reasoning observable and debuggable
|
|
615
712
|
- NEVER modify files without first reading their current content
|
|
@@ -752,15 +849,15 @@ Example 2 - Adding a dependency:
|
|
|
752
849
|
<scenario>User asks: Create a config.json file</scenario>
|
|
753
850
|
<correct_response>
|
|
754
851
|
Step 1 - Think first:
|
|
755
|
-
Call think: "The user wants a config.json file. I should create a new file with write() since it doesn't exist yet. Let me prepare a default JSON structure with common configuration options that would be useful."
|
|
852
|
+
Call think({ thought: "The user wants a config.json file. I should create a new file with write() since it doesn't exist yet. Let me prepare a default JSON structure with common configuration options that would be useful." })
|
|
756
853
|
|
|
757
854
|
Step 2 - Execute action:
|
|
758
|
-
Call write
|
|
855
|
+
Call write({ path: "config.json", content: "{"default": true, "settings": {}}" })
|
|
759
856
|
|
|
760
857
|
[System provides: Observation: done]
|
|
761
858
|
|
|
762
859
|
Step 3 - Think again to reflect:
|
|
763
|
-
Call think: "Write operation successful. The config.json file has been created with default settings. Task is complete."
|
|
860
|
+
Call think({ thought: "Write operation successful. The config.json file has been created with default settings. Task is complete." })
|
|
764
861
|
|
|
765
862
|
Step 4 - Provide final answer:
|
|
766
863
|
"Created config.json with default configuration that includes common settings."
|
|
@@ -771,23 +868,28 @@ Step 4 - Provide final answer:
|
|
|
771
868
|
<scenario>User asks: Add a new function to utils.js</scenario>
|
|
772
869
|
<correct_response>
|
|
773
870
|
Step 1 - Think:
|
|
774
|
-
Call think: "Need to add a function to utils.js. First I should read the existing file to understand its structure, coding style, and existing functions to ensure consistency."
|
|
871
|
+
Call think({ thought: "Need to add a function to utils.js. First I should read the existing file to understand its structure, coding style, and existing functions to ensure consistency." })
|
|
775
872
|
|
|
776
873
|
Step 2 - Read file:
|
|
777
|
-
Call read
|
|
874
|
+
Call read({ path: "utils.js" })
|
|
778
875
|
|
|
779
876
|
[System provides: Observation: <file content>]
|
|
780
877
|
|
|
781
878
|
Step 3 - Think about the content:
|
|
782
|
-
Call think: "I can see the current structure. The file has 3 existing utility functions with JSDoc comments and follows a specific naming convention. I'll add the new function at the end, following the same style pattern, and use merge() to safely integrate it."
|
|
879
|
+
Call think({ thought: "I can see the current structure. The file has 3 existing utility functions with JSDoc comments and follows a specific naming convention. I'll add the new function at the end, following the same style pattern, and use merge() to safely integrate it." })
|
|
783
880
|
|
|
784
881
|
Step 4 - Merge changes:
|
|
785
|
-
Call merge
|
|
882
|
+
Call merge({ path: "utils.js", content: "// Existing content...
|
|
883
|
+
// New function added here
|
|
884
|
+
function newFunction() {
|
|
885
|
+
// Implementation
|
|
886
|
+
}
|
|
887
|
+
" })
|
|
786
888
|
|
|
787
889
|
[System provides: Observation: merge successful]
|
|
788
890
|
|
|
789
891
|
Step 5 - Think about result:
|
|
790
|
-
Call think: "Merge completed successfully without conflicts. The new function is now integrated into utils.js following the project's coding style."
|
|
892
|
+
Call think({ thought: "Merge completed successfully without conflicts. The new function is now integrated into utils.js following the project's coding style." })
|
|
791
893
|
|
|
792
894
|
Step 6 - Final answer:
|
|
793
895
|
"Successfully added the new function to utils.js using safe merge, maintaining consistency with existing code style."
|
|
@@ -802,24 +904,24 @@ The key difference from traditional tool calling:
|
|
|
802
904
|
|
|
803
905
|
This makes your decision-making process transparent, debuggable, and more reliable. Always prioritize clarity and thoroughness in your thinking process.
|
|
804
906
|
</final_note>
|
|
805
|
-
</instructions>`}function
|
|
907
|
+
</instructions>`}function ss(o){return`\u4F60\u662F\u4E00\u4E2A\u4EFB\u52A1\u590D\u6742\u5EA6\u8BC4\u4F30\u4E13\u5BB6\u3002\u8BF7\u8BC4\u4F30\u4EE5\u4E0B\u4EFB\u52A1\u7684\u590D\u6742\u5EA6\u3002
|
|
806
908
|
|
|
807
909
|
\u4EFB\u52A1\u63CF\u8FF0\uFF1A
|
|
808
|
-
${
|
|
910
|
+
${o}
|
|
809
911
|
|
|
810
912
|
\u8BC4\u4F30\u6807\u51C6\uFF1A
|
|
811
913
|
- SIMPLE\uFF08\u7B80\u5355\u4EFB\u52A1\uFF09\uFF1A\u5355\u4E00\u660E\u786E\u7684\u64CD\u4F5C\uFF0C\u6BD4\u5982\u8BFB\u53D6\u6587\u4EF6\u3001\u521B\u5EFA\u7B80\u5355\u6587\u4EF6\u3001\u6267\u884C\u5355\u4E2A\u547D\u4EE4\u7B49\uFF0C\u4E0D\u9700\u8981\u590D\u6742\u601D\u8003\u6216\u89C4\u5212
|
|
812
914
|
- MEDIUM\uFF08\u4E2D\u7B49\u4EFB\u52A1\uFF09\uFF1A\u9700\u89812-3\u4E2A\u6B65\u9AA4\u7684\u64CD\u4F5C\uFF0C\u53EF\u80FD\u6D89\u53CA\u7B80\u5355\u7684\u6587\u4EF6\u4FEE\u6539\u6216\u57FA\u672C\u903B\u8F91
|
|
813
915
|
- COMPLEX\uFF08\u590D\u6742\u4EFB\u52A1\uFF09\uFF1A\u9700\u8981\u591A\u4E2A\u6B65\u9AA4\uFF083\u4E2A\u4EE5\u4E0A\uFF09\u3001\u6D89\u53CA\u591A\u4E2A\u6587\u4EF6\u4FEE\u6539\u3001\u9700\u8981\u8BE6\u7EC6\u89C4\u5212\u6216\u903B\u8F91\u63A8\u7406\u7684\u4EFB\u52A1
|
|
814
916
|
|
|
815
|
-
\u8BF7\u53EA\u56DE\u590D "SIMPLE"\u3001"MEDIUM" \u6216 "COMPLEX"\uFF0C\u4E0D\u8981\u6709\u5176\u4ED6\u5185\u5BB9\u3002`}function
|
|
917
|
+
\u8BF7\u53EA\u56DE\u590D "SIMPLE"\u3001"MEDIUM" \u6216 "COMPLEX"\uFF0C\u4E0D\u8981\u6709\u5176\u4ED6\u5185\u5BB9\u3002`}function is(o,e=[]){let t=e.length>0?e.map(r=>`${r.name}(${r.description})`).join(", "):"default",n=e.length>0?`
|
|
816
918
|
|
|
817
919
|
\u53EF\u7528\u7684\u5B50\u667A\u80FD\u4F53\uFF1A
|
|
818
|
-
${e.map(
|
|
920
|
+
${e.map(r=>`- ${r.name}: ${r.description}`).join(`
|
|
819
921
|
`)}`:"";return`\u4F60\u662F\u4E00\u4F4D\u4EFB\u52A1\u89C4\u5212\u4E13\u5BB6\u3002\u8BF7\u4E3A\u4EE5\u4E0B\u7528\u6237\u8BF7\u6C42\u751F\u6210\u4E00\u4E2A\u9AD8\u8D28\u91CF\u7684\u6267\u884C\u8BA1\u5212\u3002
|
|
820
922
|
|
|
821
923
|
\u7528\u6237\u8BF7\u6C42\uFF1A
|
|
822
|
-
${
|
|
924
|
+
${o}
|
|
823
925
|
${n}
|
|
824
926
|
|
|
825
927
|
## \u89C4\u5212\u8981\u6C42
|
|
@@ -905,13 +1007,13 @@ ${n}
|
|
|
905
1007
|
}
|
|
906
1008
|
\`\`\`
|
|
907
1009
|
|
|
908
|
-
\u8BF7\u4F7F\u7528 create_task_plan \u5DE5\u5177\u8FD4\u56DE\u7ED3\u6784\u5316\u7684\u4EFB\u52A1\u89C4\u5212\u3002`}function
|
|
1010
|
+
\u8BF7\u4F7F\u7528 create_task_plan \u5DE5\u5177\u8FD4\u56DE\u7ED3\u6784\u5316\u7684\u4EFB\u52A1\u89C4\u5212\u3002`}function as(o,e=[]){let t=e.length>0?`
|
|
909
1011
|
\u53EF\u7528\u7684\u5B50\u667A\u80FD\u4F53\uFF1A
|
|
910
1012
|
${e.map(n=>`- ${n.name}: ${n.description}`).join(`
|
|
911
1013
|
`)}`:"";return`\u4F60\u662F\u4E00\u4E2A\u4EFB\u52A1\u89C4\u5212\u4E13\u5BB6\u3002\u8BF7\u4E3A\u4EE5\u4E0B\u4EFB\u52A1\u751F\u6210\u8BE6\u7EC6\u3001\u7ED3\u6784\u5316\u7684\u6267\u884C\u8BA1\u5212\u3002
|
|
912
1014
|
|
|
913
1015
|
\u4EFB\u52A1\u63CF\u8FF0\uFF1A
|
|
914
|
-
${
|
|
1016
|
+
${o}
|
|
915
1017
|
${t}
|
|
916
1018
|
|
|
917
1019
|
\u8BF7\u6309\u7167\u4EE5\u4E0BMarkdown\u683C\u5F0F\u8F93\u51FA\u4EFB\u52A1\u89C4\u5212\uFF1A
|
|
@@ -939,14 +1041,14 @@ ${t}
|
|
|
939
1041
|
- \u6B65\u9AA4\u4E4B\u95F4\u5FC5\u987B\u6709\u660E\u786E\u7684\u4F9D\u8D56\u5173\u7CFB\u548C\u987A\u5E8F\u903B\u8F91
|
|
940
1042
|
- \u6BCF\u4E2A\u6B65\u9AA4\u5FC5\u987B\u6807\u6CE8\u6700\u9002\u5408\u7684\u63A8\u8350\u5B50\u667A\u80FD\u4F53
|
|
941
1043
|
- \u4EFB\u52A1\u6982\u8FF0\u5E94\u8BE5\u7B80\u660E\u627C\u8981\u5730\u6982\u62EC\u6574\u4E2A\u4EFB\u52A1\u7684\u76EE\u7684\u548C\u8303\u56F4
|
|
942
|
-
- \u9884\u671F\u7ED3\u679C\u5E94\u8BE5\u5177\u4F53\u3001\u53EF\u8861\u91CF\uFF0C\u660E\u786E\u8BF4\u660E\u5B8C\u6210\u540E\u7684\u72B6\u6001`}function
|
|
1044
|
+
- \u9884\u671F\u7ED3\u679C\u5E94\u8BE5\u5177\u4F53\u3001\u53EF\u8861\u91CF\uFF0C\u660E\u786E\u8BF4\u660E\u5B8C\u6210\u540E\u7684\u72B6\u6001`}function cs(o){return`\u8BF7\u5C06\u4EE5\u4E0B Markdown \u683C\u5F0F\u7684\u4EFB\u52A1\u89C4\u5212\u8F6C\u6362\u4E3A\u7ED3\u6784\u5316\u683C\u5F0F\u3002
|
|
943
1045
|
|
|
944
|
-
${
|
|
1046
|
+
${o}
|
|
945
1047
|
|
|
946
|
-
\u8BF7\u4F7F\u7528 create_task_plan \u5DE5\u5177\u8FD4\u56DE\u7ED3\u6784\u5316\u7684\u4EFB\u52A1\u89C4\u5212\u6570\u636E\u3002`}function
|
|
1048
|
+
\u8BF7\u4F7F\u7528 create_task_plan \u5DE5\u5177\u8FD4\u56DE\u7ED3\u6784\u5316\u7684\u4EFB\u52A1\u89C4\u5212\u6570\u636E\u3002`}function ls(o,e){return`\u4F60\u662F\u4E00\u4E2A\u667A\u80FD\u4F53\u5339\u914D\u4E13\u5BB6\u3002\u8BF7\u4ED4\u7EC6\u5206\u6790\u4EE5\u4E0B\u4EFB\u52A1\u63CF\u8FF0\uFF0C\u5E76\u4ECE\u63D0\u4F9B\u7684\u667A\u80FD\u4F53\u5217\u8868\u4E2D\u9009\u62E9\u6700\u5339\u914D\u3001\u6700\u9AD8\u6548\u7684\u4E00\u4E2A\u3002
|
|
947
1049
|
|
|
948
1050
|
\u4EFB\u52A1\u63CF\u8FF0\uFF1A
|
|
949
|
-
${
|
|
1051
|
+
${o}
|
|
950
1052
|
|
|
951
1053
|
\u53EF\u7528\u667A\u80FD\u4F53\uFF1A
|
|
952
1054
|
${e}
|
|
@@ -957,7 +1059,7 @@ ${e}
|
|
|
957
1059
|
3. \u667A\u80FD\u4F53\u7684\u4E13\u957F\u662F\u5426\u80FD\u591F\u89E3\u51B3\u4EFB\u52A1\u4E2D\u7684\u6838\u5FC3\u6311\u6218
|
|
958
1060
|
4. \u8003\u8651\u4EFB\u52A1\u7684\u590D\u6742\u5EA6\u548C\u667A\u80FD\u4F53\u7684\u5904\u7406\u80FD\u529B
|
|
959
1061
|
|
|
960
|
-
\u8BF7\u53EA\u8FD4\u56DE\u6700\u4F73\u5339\u914D\u7684\u667A\u80FD\u4F53\u540D\u79F0\uFF08\u5B8C\u5168\u5339\u914D\u667A\u80FD\u4F53\u540D\u79F0\u5B57\u7B26\u4E32\uFF09\uFF0C\u5982\u679C\u6CA1\u6709\u5408\u9002\u7684\u5339\u914D\u6216\u5339\u914D\u5EA6\u4E0D\u8DB360%\uFF0C\u8BF7\u8FD4\u56DE"default"\u3002`}var
|
|
1062
|
+
\u8BF7\u53EA\u8FD4\u56DE\u6700\u4F73\u5339\u914D\u7684\u667A\u80FD\u4F53\u540D\u79F0\uFF08\u5B8C\u5168\u5339\u914D\u667A\u80FD\u4F53\u540D\u79F0\u5B57\u7B26\u4E32\uFF09\uFF0C\u5982\u679C\u6CA1\u6709\u5408\u9002\u7684\u5339\u914D\u6216\u5339\u914D\u5EA6\u4E0D\u8DB360%\uFF0C\u8BF7\u8FD4\u56DE"default"\u3002`}var et,tt=S(()=>{Ot();et=Ma()});var Oe={};j(Oe,{TaskComplexity:()=>Ar,evaluateTaskComplexity:()=>du,generatePlanSummary:()=>Dn,generateTaskPlan:()=>Rn,getTaskFilePath:()=>xu,listTaskPlans:()=>vu,loadTaskPlan:()=>wu,updateTaskStatus:()=>nt});import R from"chalk";import ye from"fs";import ve from"path";async function du(o){let e=ss(o);try{let t=await ee({model:Pe(),messages:[{role:"user",content:e}],temperature:.1,max_tokens:10,useCompression:!0}),{content:n}=t.choices[0].message;return(n?n.trim():"").toUpperCase().includes("COMPLEX")?(console.log(R.yellow("[\u4EFB\u52A1\u8BC4\u4F30] \u68C0\u6D4B\u5230\u590D\u6742\u4EFB\u52A1\uFF0C\u5C06\u8FDB\u884C\u4EFB\u52A1\u89C4\u5212")),Ar.COMPLEX):(console.log(R.blue("[\u4EFB\u52A1\u8BC4\u4F30] \u68C0\u6D4B\u5230\u7B80\u5355\u4EFB\u52A1\uFF0C\u4F7F\u7528\u5355\u6B65\u9AA4\u6A21\u5F0F")),Ar.SIMPLE)}catch(t){return console.log(R.yellow(`[\u4EFB\u52A1\u8BC4\u4F30] \u8BC4\u4F30\u5931\u8D25\uFF0C\u9ED8\u8BA4\u4E3A\u7B80\u5355\u4EFB\u52A1: ${t.message}`)),Ar.SIMPLE}}function Ia(o=[]){let e=o.length>0?o.map(t=>t.name).join(", "):"default";return{name:"create_task_plan",description:"\u751F\u6210\u8BE6\u7EC6\u7684\u4EFB\u52A1\u6267\u884C\u89C4\u5212\uFF0C\u5305\u542B\u591A\u4E2A\u6B65\u9AA4\u548C\u63A8\u8350\u7684\u5B50\u667A\u80FD\u4F53",input_schema:{type:"object",properties:{overview:{type:"string",description:"\u4EFB\u52A1\u6982\u8FF0\uFF0C\u7B80\u8981\u63CF\u8FF0\u4EFB\u52A1\u76EE\u6807"},steps:{type:"array",description:"\u6267\u884C\u6B65\u9AA4\u5217\u8868\uFF0C\u5FC5\u987B\u5305\u542B2-4\u4E2A\u6B65\u9AA4",items:{type:"object",properties:{description:{type:"string",description:"\u6B65\u9AA4\u7684\u8BE6\u7EC6\u63CF\u8FF0\uFF0C\u5E94\u8BE5\u662F\u5927\u9897\u7C92\u5EA6\u7684\u4EFB\u52A1\u62C6\u5206"},subAgent:{type:"string",description:`\u63A8\u8350\u4F7F\u7528\u7684\u5B50\u667A\u80FD\u4F53\u540D\u79F0\u3002\u53EF\u7528\u9009\u9879: ${e}\u3002\u5982\u679C\u6CA1\u6709\u5408\u9002\u7684\u5B50\u667A\u80FD\u4F53\uFF0C\u4F7F\u7528"default"`},allowedTools:{type:"array",description:`\u8BE5\u6B65\u9AA4\u5141\u8BB8\u4F7F\u7528\u7684\u5DE5\u5177\u5217\u8868\uFF08\u4EC5\u5F53 subAgent \u4E3A "default" \u65F6\u751F\u6548\uFF09\u3002
|
|
961
1063
|
\u5E38\u7528\u5DE5\u5177\u7EC4\u5408\uFF1A
|
|
962
1064
|
- \u53EA\u8BFB\u5206\u6790: ["read", "glob", "grep", "quickProjectScan", "think", "askUser"]
|
|
963
1065
|
- \u4EE3\u7801\u63A2\u7D22: ["read", "glob", "grep", "quickProjectScan", "shell", "think"]
|
|
@@ -965,53 +1067,53 @@ ${e}
|
|
|
965
1067
|
- \u6D4B\u8BD5\u9A8C\u8BC1: ["read", "shell", "glob", "grep", "think"]
|
|
966
1068
|
|
|
967
1069
|
\u5982\u679C\u4E3A\u7A7A\u6570\u7EC4\u6216\u4E0D\u6307\u5B9A\uFF0C\u5219\u4F7F\u7528\u6240\u6709\u53EF\u7528\u5DE5\u5177\u3002
|
|
968
|
-
\u5982\u679C\u4F7F\u7528\u81EA\u5B9A\u4E49\u5B50\u667A\u80FD\u4F53(\u975Edefault)\uFF0C\u6B64\u5B57\u6BB5\u4F1A\u88AB\u5FFD\u7565\u3002`,items:{type:"string"}}},required:["description","subAgent"]},minItems:2,maxItems:4},expectedResult:{type:"string",description:"\u9884\u671F\u7ED3\u679C\uFF0C\u63CF\u8FF0\u5B8C\u6210\u540E\u7684\u9884\u671F\u6548\u679C"}},required:["overview","steps","expectedResult"]}}}async function
|
|
1070
|
+
\u5982\u679C\u4F7F\u7528\u81EA\u5B9A\u4E49\u5B50\u667A\u80FD\u4F53(\u975Edefault)\uFF0C\u6B64\u5B57\u6BB5\u4F1A\u88AB\u5FFD\u7565\u3002`,items:{type:"string"}}},required:["description","subAgent"]},minItems:2,maxItems:4},expectedResult:{type:"string",description:"\u9884\u671F\u7ED3\u679C\uFF0C\u63CF\u8FF0\u5B8C\u6210\u540E\u7684\u9884\u671F\u6548\u679C"}},required:["overview","steps","expectedResult"]}}}async function fu(o,e=[]){console.log(R.blue("[\u4EFB\u52A1\u89C4\u5212] \u5C1D\u8BD5\u65B9\u68481: Function Calling"));let t=is(o,e),n=Ia(e),s=(await ee({model:fe(),messages:[{role:"user",content:t}],temperature:.3,max_tokens:2e3,tools:[n],tool_choice:{type:"function",function:{name:"create_task_plan"}}}))?.choices?.[0]?.message?.tool_calls;if(!s||s.length===0)throw new Error("\u6A21\u578B\u6CA1\u6709\u8FD4\u56DE function call");let i=JSON.parse(s[0].function.arguments);if(!i.steps||i.steps.length<2)throw new Error(`\u6B65\u9AA4\u6570\u91CF\u4E0D\u8DB3: ${i.steps?.length||0}`);return i}async function hu(o,e=[]){console.log(R.yellow("[\u4EFB\u52A1\u89C4\u5212] \u5C1D\u8BD5\u65B9\u68482: Markdown + Function Call \u8F6C\u6362"));let t=as(o,e),r=(await ee({model:fe(),messages:[{role:"user",content:t}],temperature:.3,max_tokens:2e3}))?.choices?.[0]?.message?.content||"";if(!r)throw new Error("\u65E0\u6CD5\u751F\u6210 Markdown \u89C4\u5212");let s=cs(r),i=Ia(e),c=(await ee({model:fe(),messages:[{role:"user",content:s}],temperature:.1,max_tokens:1500,tools:[i],tool_choice:{type:"function",function:{name:"create_task_plan"}}}))?.choices?.[0]?.message?.tool_calls;if(!c||c.length===0)throw new Error("\u65E0\u6CD5\u8F6C\u6362 Markdown \u4E3A\u7ED3\u6784\u5316\u6570\u636E");let l=JSON.parse(c[0].function.arguments);return l.markdown=r,l}function yu(o){return console.log(R.yellow("[\u4EFB\u52A1\u89C4\u5212] \u4F7F\u7528\u9ED8\u8BA4\u964D\u7EA7\u65B9\u6848")),{overview:o,steps:[{description:"\u9700\u6C42\u5206\u6790\u4E0E\u6280\u672F\u65B9\u6848\u8BBE\u8BA1",subAgent:"default"},{description:"\u6838\u5FC3\u529F\u80FD\u5B9E\u73B0",subAgent:"default"},{description:"\u6D4B\u8BD5\u9A8C\u8BC1\u4E0E\u4EE3\u7801\u4F18\u5316",subAgent:"default"}],expectedResult:"\u5B8C\u6210\u4EFB\u52A1\u7684\u6240\u6709\u6B65\u9AA4\uFF0C\u8FBE\u5230\u9884\u671F\u7684\u529F\u80FD\u76EE\u6807"}}function Cu(o){let e=o.steps.map((t,n)=>`- [ ] ${t.description}
|
|
969
1071
|
- \u63A8\u8350\u5B50\u667A\u80FD\u4F53: ${t.subAgent}`).join(`
|
|
970
1072
|
|
|
971
1073
|
`);return`# \u4EFB\u52A1\u89C4\u5212
|
|
972
1074
|
|
|
973
1075
|
## \u4EFB\u52A1\u6982\u8FF0
|
|
974
|
-
${
|
|
1076
|
+
${o.overview}
|
|
975
1077
|
|
|
976
1078
|
## \u6267\u884C\u6B65\u9AA4
|
|
977
1079
|
${e}
|
|
978
1080
|
|
|
979
1081
|
## \u9884\u671F\u7ED3\u679C
|
|
980
|
-
${
|
|
1082
|
+
${o.expectedResult}`}async function Rn(o,e=[]){if(!o||typeof o!="string")throw new Error("\u65E0\u6548\u7684\u7528\u6237\u8BF7\u6C42");console.log(R.blue("[\u4EFB\u52A1\u89C4\u5212] \u6B63\u5728\u751F\u6210\u4EFB\u52A1\u89C4\u5212..."));let t=null,n="unknown";try{t=await fu(o,e),n="Function Calling",console.log(R.green("[\u4EFB\u52A1\u89C4\u5212] \u2713 Function Calling \u65B9\u6848\u6210\u529F"))}catch(c){console.log(R.yellow(`[\u4EFB\u52A1\u89C4\u5212] Function Calling \u5931\u8D25: ${c.message}`));try{t=await hu(o,e),n="Markdown + Conversion",console.log(R.green("[\u4EFB\u52A1\u89C4\u5212] \u2713 Markdown \u8F6C\u6362\u65B9\u6848\u6210\u529F"))}catch(l){console.log(R.yellow(`[\u4EFB\u52A1\u89C4\u5212] Markdown \u8F6C\u6362\u5931\u8D25: ${l.message}`)),t=yu(o),n="Default Fallback",console.log(R.yellow("[\u4EFB\u52A1\u89C4\u5212] \u26A0 \u4F7F\u7528\u9ED8\u8BA4\u964D\u7EA7\u65B9\u6848"))}}let r=t.markdown||Cu(t),s=t.steps.map((c,l)=>({step:l+1,description:c.description,status:"pending",subAgent:c.subAgent||"default",allowedTools:c.allowedTools||void 0})),i=dr(),a={markdown:r,tasks:s,taskId:i,strategy:n};return await Su(r,i,a),console.log(R.green(`[\u4EFB\u52A1\u89C4\u5212] \u2713 \u4EFB\u52A1\u89C4\u5212\u751F\u6210\u5B8C\u6210 (\u7B56\u7565: ${n})`)),console.log(R.cyan(`[\u4EFB\u52A1\u89C4\u5212] \u5171\u5305\u542B ${s.length} \u4E2A\u4EFB\u52A1\u6B65\u9AA4`)),console.log(R.gray("\u2500".repeat(50))),console.log(r),console.log(R.gray("\u2500".repeat(50))),a}async function Su(o,e,t){let n=ve.join(process.cwd(),".nium","tasks");ye.existsSync(n)||ye.mkdirSync(n,{recursive:!0});let r=`# \u4EFB\u52A1\u89C4\u5212 (ID: ${e})
|
|
981
1083
|
|
|
982
1084
|
## \u4EFB\u52A1\u6982\u8FF0
|
|
983
|
-
${
|
|
1085
|
+
${o.substring(o.indexOf("## \u4EFB\u52A1\u6982\u8FF0")+7)}
|
|
984
1086
|
|
|
985
1087
|
## \u66F4\u65B0\u65F6\u95F4
|
|
986
|
-
${new Date().toLocaleString()}`,s=
|
|
987
|
-
`),a=!1,c=1,l=[];for(let
|
|
988
|
-
`),"utf8"),console.log(
|
|
1088
|
+
${new Date().toLocaleString()}`,s=ve.join(n,`${e}.md`);if(ye.writeFileSync(s,r,"utf8"),console.log(R.green(`[\u4EFB\u52A1\u6587\u4EF6] \u4EFB\u52A1\u89C4\u5212\u5DF2\u4FDD\u5B58\u5230: ${s}`)),t){let i={taskId:t.taskId,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),status:"pending",currentStep:0,totalSteps:t.tasks.length,strategy:t.strategy,markdown:t.markdown,tasks:t.tasks.map(c=>({step:c.step,description:c.description,status:c.status,subAgent:c.subAgent,startTime:null,endTime:null,duration:null,error:null}))},a=ve.join(n,`${e}.json`);ye.writeFileSync(a,JSON.stringify(i,null,2),"utf8"),console.log(R.green(`[\u4EFB\u52A1\u6587\u4EF6] JSON \u6570\u636E\u5DF2\u4FDD\u5B58\u5230: ${a}`))}}async function nt(o,e,t){let n=ve.join(process.cwd(),".nium","tasks"),r=ve.join(n,`${o}.md`);if(!ye.existsSync(r))return console.log(R.red(`[\u4EFB\u52A1\u66F4\u65B0] \u4EFB\u52A1\u6587\u4EF6\u4E0D\u5B58\u5728: ${r}`)),!1;try{let i=ye.readFileSync(r,"utf8").split(`
|
|
1089
|
+
`),a=!1,c=1,l=[];for(let g of i){if(g.trim().includes("## \u6267\u884C\u6B65\u9AA4")||g.trim().includes("##\u6267\u884C\u6B65\u9AA4")){a=!0,l.push(g);continue}if(g.trim().includes("## \u66F4\u65B0\u65F6\u95F4")){l.push("## \u66F4\u65B0\u65F6\u95F4"),l.push(new Date().toLocaleString());continue}if(a&&g.trim().startsWith("##")&&!g.trim().includes("\u66F4\u65B0\u65F6\u95F4")){a=!1,l.push(g);continue}if(a){let p=g.trim().match(/^-\s*\[(.)\]\s*(.+)/);if(p&&c===e){let u=" ";t==="in_progress"&&(u="-"),t==="completed"&&(u="x"),l.push(`- [${u}] ${p[2]}`),c++;continue}p&&c++}l.push(g)}return ye.writeFileSync(r,l.join(`
|
|
1090
|
+
`),"utf8"),console.log(R.green(`[\u4EFB\u52A1\u66F4\u65B0] \u4EFB\u52A1 ${o} \u6B65\u9AA4 ${e} \u72B6\u6001\u5DF2\u66F4\u65B0\u4E3A ${t}`)),!0}catch(s){return console.log(R.red(`[\u4EFB\u52A1\u66F4\u65B0] \u66F4\u65B0\u4EFB\u52A1\u72B6\u6001\u5931\u8D25: ${s.message}`)),!1}}function xu(o){let e=ve.join(process.cwd(),".nium","tasks");return ve.join(e,`${o}.md`)}function wu(o){let e=ve.join(process.cwd(),".nium","tasks"),t=ve.join(e,`${o}.json`);if(!ye.existsSync(t))return console.log(R.red(`[\u4EFB\u52A1\u52A0\u8F7D] \u4EFB\u52A1\u6587\u4EF6\u4E0D\u5B58\u5728: ${t}`)),null;try{let n=ye.readFileSync(t,"utf8"),r=JSON.parse(n);return console.log(R.green(`[\u4EFB\u52A1\u52A0\u8F7D] \u6210\u529F\u52A0\u8F7D\u4EFB\u52A1: ${o}`)),r}catch(n){return console.log(R.red(`[\u4EFB\u52A1\u52A0\u8F7D] \u89E3\u6790\u4EFB\u52A1\u6587\u4EF6\u5931\u8D25: ${n.message}`)),null}}function vu(){let o=ve.join(process.cwd(),".nium","tasks");return ye.existsSync(o)?ye.readdirSync(o).filter(n=>n.endsWith(".json")).map(n=>n.replace(".json","")):[]}function Dn(o){if(!o||!o.tasks||o.tasks.length===0)return"\u65E0\u6709\u6548\u4EFB\u52A1\u6B65\u9AA4";let e=R.cyan(`
|
|
989
1091
|
\u{1F4CB} \u4EFB\u52A1\u89C4\u5212\u6458\u8981:
|
|
990
|
-
`);e+=
|
|
991
|
-
`;for(let t of
|
|
992
|
-
`}return e+=
|
|
993
|
-
`),
|
|
994
|
-
`)}function
|
|
995
|
-
`)}function
|
|
996
|
-
`);if(
|
|
997
|
-
`):(
|
|
998
|
-
`):"\u6682\u65E0\u9879\u76EE\u4FE1\u606F\u3002")}function
|
|
999
|
-
*...\u8FD8\u6709 ${Object.keys(e.dependencies).length-10} \u4E2A\u4F9D\u8D56*`),
|
|
1000
|
-
*...\u8FD8\u6709 ${Object.keys(e.devDependencies).length-10} \u4E2A\u4F9D\u8D56*`),
|
|
1001
|
-
*...\u8FD8\u6709 ${e.entryPoints.length-5} \u4E2A\u5165\u53E3\u6587\u4EF6*`),
|
|
1002
|
-
*...\u8FD8\u6709 ${e.codeStandards.length-5} \u4E2A\u89C4\u8303*`),
|
|
1003
|
-
`);if(!
|
|
1092
|
+
`);e+=R.gray("\u2500".repeat(50))+`
|
|
1093
|
+
`;for(let t of o.tasks){let n=t.subAgent!=="default"?R.green(`[${t.subAgent}]`):R.gray("[\u9ED8\u8BA4\u667A\u80FD\u4F53]");e+=`${t.step}. ${t.description} ${n}
|
|
1094
|
+
`}return e+=R.gray("\u2500".repeat(50)),e}var Ar,be=S(()=>{ae();Ce();fr();tt();Ar={SIMPLE:"simple",COMPLEX:"complex"}});function On(o,e={format:"markdown"}){let{format:t,maxSections:n=100,detailed:r=!0,customTitle:s}=e;switch(t){case"markdown":return Aa(o,r,s);case"text":return bu(o,r);case"summary":return Tu(o,n);default:return Aa(o,r,s)}}function Aa(o,e,t){let n=[];return n.push(t||`# \u9879\u76EE\u7ED3\u6784\u4FE1\u606F
|
|
1095
|
+
`),ku(n,o,e),Pu(n,o,e),$u(n,o,e),Eu(n,o,e),Mu(n,o,e),Iu(n,o,e),Au(n,o,e),n.length<=1?"\u6682\u65E0\u8BE6\u7EC6\u9879\u76EE\u7ED3\u6784\u4FE1\u606F\u3002":n.join(`
|
|
1096
|
+
`)}function bu(o,e){let t=[];if(t.push("\u{1F4CA} \u9879\u76EE\u57FA\u7840\u4FE1\u606F\u6458\u8981"),t.push("\u2550".repeat(50)),t.push(""),t.push(`\u{1F4E6} \u9879\u76EE\u540D\u79F0: ${o.projectName||"\u672A\u77E5"}`),t.push(`\u{1F4CC} \u7248\u672C: ${o.version||"\u672A\u77E5"}`),o.description&&t.push(`\u{1F4DD} \u63CF\u8FF0: ${o.description}`),t.push(""),t.push(`\u{1F310} \u4E3B\u8981\u8BED\u8A00: ${o.primaryLanguage||"\u672A\u77E5"}`),o.buildTool&&t.push(`\u{1F527} \u6784\u5EFA\u5DE5\u5177: ${o.buildTool}`),o.packageManager&&t.push(`\u{1F4E6} \u5305\u7BA1\u7406\u5668: ${o.packageManager}`),o.runtime&&t.push(`\u2699\uFE0F \u8FD0\u884C\u65F6: ${o.runtime}`),t.push(""),o.fileStats){t.push("\u{1F4C1} \u6587\u4EF6\u7EDF\u8BA1:");let n=o.fileStats;t.push(` \u603B\u6587\u4EF6\u6570: ${n.totalFiles||0}`),t.push(` \u6E90\u4EE3\u7801\u6587\u4EF6: ${n.sourceFiles||0}`),t.push(` \u914D\u7F6E\u6587\u4EF6: ${n.configFiles||0}`),t.push(` \u6587\u6863\u6587\u4EF6: ${n.docFiles||0}`),t.push(` \u6D4B\u8BD5\u6587\u4EF6: ${n.testFiles||0}`),t.push("")}return o.dependencyCount&&(t.push("\u{1F4DA} \u4F9D\u8D56\u7EDF\u8BA1:"),t.push(` \u751F\u4EA7\u4F9D\u8D56: ${o.dependencyCount.production||0} \u4E2A`),t.push(` \u5F00\u53D1\u4F9D\u8D56: ${o.dependencyCount.development||0} \u4E2A`),t.push("")),o.languages&&o.languages.length>0&&(t.push("\u{1F30D} \u8BED\u8A00\u5206\u5E03:"),o.languages.slice(0,5).forEach(n=>{t.push(` ${n.language}: ${n.count} \u4E2A\u6587\u4EF6 (${n.percentage})`)}),t.push("")),t.join(`
|
|
1097
|
+
`)}function Tu(o,e){let t=[],n=0;if((o.projectName||o.version||o.description)&&(o.projectName&&t.push(`**\u9879\u76EE\u540D\u79F0**: ${o.projectName}`),o.version&&t.push(`**\u7248\u672C**: ${o.version}`),o.description&&t.push(`**\u63CF\u8FF0**: ${o.description}`),n++),n>=e||((o.primaryLanguage||o.buildTool)&&(t.push(""),o.primaryLanguage&&t.push(`**\u4E3B\u8981\u8BED\u8A00**: ${o.primaryLanguage}`),o.buildTool&&t.push(`**\u6784\u5EFA\u5DE5\u5177**: ${o.buildTool}`),o.packageManager&&t.push(`**\u5305\u7BA1\u7406\u5668**: ${o.packageManager}`),o.runtime&&t.push(`**\u8FD0\u884C\u65F6**: ${o.runtime}`),n++),n>=e))return t.join(`
|
|
1098
|
+
`);if(o.fileStats){t.push("");let r=o.fileStats;r.totalFiles&&t.push(`**\u603B\u6587\u4EF6\u6570**: ${r.totalFiles}`),r.sourceFiles&&t.push(`**\u6E90\u6587\u4EF6**: ${r.sourceFiles}`),r.configFiles&&t.push(`**\u914D\u7F6E\u6587\u4EF6**: ${r.configFiles}`),r.testFiles&&t.push(`**\u6D4B\u8BD5\u6587\u4EF6**: ${r.testFiles}`),n++}return n>=e||(o.languages&&o.languages.length>0&&(t.push(""),t.push("**\u8BED\u8A00\u5206\u5E03**:"),o.languages.slice(0,5).forEach(r=>{t.push(`- ${r.language}: ${r.percentage}%`)}),n++),n>=e)||(o.dependencies&&Object.keys(o.dependencies).length>0&&(t.push(""),t.push("**\u4E3B\u8981\u4F9D\u8D56**:"),Object.entries(o.dependencies).slice(0,5).forEach(([s,i])=>{t.push(`- ${s}: ${i}`)}),n++),n>=e)?t.join(`
|
|
1099
|
+
`):(o.codeStandards&&o.codeStandards.length>0&&(t.push(""),t.push("**\u4EE3\u7801\u89C4\u8303**:"),o.codeStandards.slice(0,3).forEach(r=>{t.push(`- ${r}`)})),t.length>0?t.join(`
|
|
1100
|
+
`):"\u6682\u65E0\u9879\u76EE\u4FE1\u606F\u3002")}function ku(o,e,t){!e.projectName&&!e.version&&!e.description||(o.push("## \u9879\u76EE\u57FA\u672C\u4FE1\u606F"),e.projectName&&o.push(`**\u9879\u76EE\u540D\u79F0**: ${e.projectName}`),e.version&&o.push(`**\u7248\u672C**: ${e.version}`),e.description&&o.push(`**\u63CF\u8FF0**: ${e.description}`),o.push(""))}function Pu(o,e,t){!e.primaryLanguage&&!e.buildTool&&!e.packageManager&&!e.runtime||(o.push("## \u6280\u672F\u6808\u4FE1\u606F"),e.primaryLanguage&&o.push(`**\u4E3B\u8981\u7F16\u7A0B\u8BED\u8A00**: ${e.primaryLanguage}`),e.buildTool&&o.push(`**\u6784\u5EFA\u5DE5\u5177**: ${e.buildTool}`),e.packageManager&&o.push(`**\u5305\u7BA1\u7406\u5668**: ${e.packageManager}`),e.runtime&&o.push(`**\u8FD0\u884C\u65F6**: ${e.runtime}`),o.push(""))}function $u(o,e,t){if(!e.fileStats)return;let n=e.fileStats;o.push("## \u6587\u4EF6\u7EDF\u8BA1"),n.totalFiles&&o.push(`- **\u603B\u6587\u4EF6\u6570**: ${n.totalFiles}`),n.sourceFiles&&o.push(`- **\u6E90\u6587\u4EF6**: ${n.sourceFiles}`),n.configFiles&&o.push(`- **\u914D\u7F6E\u6587\u4EF6**: ${n.configFiles}`),n.docFiles&&o.push(`- **\u6587\u6863\u6587\u4EF6**: ${n.docFiles}`),n.testFiles&&o.push(`- **\u6D4B\u8BD5\u6587\u4EF6**: ${n.testFiles}`),o.push("")}function Eu(o,e,t){!e.languages||e.languages.length===0||(o.push("## \u7F16\u7A0B\u8BED\u8A00\u5206\u6790"),t?e.languages.forEach(n=>{o.push(`- **${n.language}**: ${n.count} \u4E2A\u6587\u4EF6 (${n.percentage}%)`)}):e.languages.slice(0,5).forEach(n=>{o.push(`- **${n.language}**: ${n.percentage}%`)}),o.push(""))}function Mu(o,e,t){let n=e.dependencies&&Object.keys(e.dependencies).length>0,r=e.devDependencies&&Object.keys(e.devDependencies).length>0;!n&&!r||(o.push("## \u4F9D\u8D56\u5173\u7CFB"),n&&(o.push("### \u751F\u4EA7\u4F9D\u8D56"),(t?Object.entries(e.dependencies):Object.entries(e.dependencies).slice(0,10)).forEach(([i,a])=>{o.push(`- **${i}**: ${a}`)}),!t&&Object.keys(e.dependencies).length>10&&o.push(`
|
|
1101
|
+
*...\u8FD8\u6709 ${Object.keys(e.dependencies).length-10} \u4E2A\u4F9D\u8D56*`),o.push("")),r&&(o.push("### \u5F00\u53D1\u4F9D\u8D56"),(t?Object.entries(e.devDependencies):Object.entries(e.devDependencies).slice(0,10)).forEach(([i,a])=>{o.push(`- **${i}**: ${a}`)}),!t&&Object.keys(e.devDependencies).length>10&&o.push(`
|
|
1102
|
+
*...\u8FD8\u6709 ${Object.keys(e.devDependencies).length-10} \u4E2A\u4F9D\u8D56*`),o.push("")))}function Iu(o,e,t){if(!e.entryPoints||e.entryPoints.length===0)return;o.push("## \u5165\u53E3\u6587\u4EF6"),(t?e.entryPoints:e.entryPoints.slice(0,5)).forEach(r=>{o.push(`- \`${r}\``)}),!t&&e.entryPoints.length>5&&o.push(`
|
|
1103
|
+
*...\u8FD8\u6709 ${e.entryPoints.length-5} \u4E2A\u5165\u53E3\u6587\u4EF6*`),o.push("")}function Au(o,e,t){if(!e.codeStandards||e.codeStandards.length===0)return;o.push("## \u4EE3\u7801\u89C4\u8303"),(t?e.codeStandards:e.codeStandards.slice(0,5)).forEach(r=>{o.push(`- ${r}`)}),!t&&e.codeStandards.length>5&&o.push(`
|
|
1104
|
+
*...\u8FD8\u6709 ${e.codeStandards.length-5} \u4E2A\u89C4\u8303*`),o.push("")}var Lr=S(()=>{});import*as Ft from"os";var Fe,je,_e,Ne,La=S(()=>{Y();Lr();Fe=class{originalTask;plan;stepSummaries;sharedState;stepDependencies;explorationHistory;constructor(){this.originalTask=null,this.plan={tasks:[],currentStep:0,totalSteps:0},this.stepSummaries=new Map,this.sharedState={projectInfo:null,rules:null,dependencies:null,recentFiles:[],knownIssues:[]},this.stepDependencies=new Map,this.explorationHistory=null}initializeTask(e,t){this.originalTask=e,this.plan={tasks:t.tasks||[],currentStep:0,totalSteps:t.tasks?.length||0},$(`\u5168\u5C40\u4E0A\u4E0B\u6587\u521D\u59CB\u5316: ${this.plan.totalSteps} \u4E2A\u6B65\u9AA4`)}recordStepCompletion(e,t,n={}){this.stepSummaries.set(e,{summary:t,metadata:n,timestamp:new Date().toISOString()}),C(`\u6B65\u9AA4 ${e} \u6458\u8981\u5DF2\u8BB0\u5F55: ${t.substring(0,50)}...`)}getStepSummary(e){return this.stepSummaries.get(e)}updateSharedState(e,t){this.sharedState.hasOwnProperty(e)?(this.sharedState[e]=t,C(`\u5171\u4EAB\u72B6\u6001\u66F4\u65B0: ${e}`)):C(`\u8B66\u544A: \u672A\u77E5\u7684\u5171\u4EAB\u72B6\u6001\u952E: ${e}`)}addRecentFile(e){this.sharedState.recentFiles.unshift(e),this.sharedState.recentFiles.length>10&&this.sharedState.recentFiles.pop()}setStepDependencies(e,t){this.stepDependencies.set(e,t)}getCompactSummary(){return{task:this.originalTask,progress:`${this.plan.currentStep}/${this.plan.totalSteps}`,completedSteps:Array.from(this.stepSummaries.keys()),recentFiles:this.sharedState.recentFiles.slice(0,5)}}getPlan(){return this.plan}setCurrentStep(e){this.plan.currentStep=e}getSharedState(){return this.sharedState}getStepDependencies(){return this.stepDependencies}getOriginalTask(){return this.originalTask}recordExplorationResult(e){let t=e.length>200?e.substring(0,200)+"...":e;this.explorationHistory={timestamp:Date.now(),content:e,summary:t},$("\u5DF2\u8BB0\u5F55\u9879\u76EE\u63A2\u7D22\u7ED3\u679C\u5230\u5168\u5C40\u4E0A\u4E0B\u6587")}getExplorationHistory(){return this.explorationHistory}},je=class{globalContext;constructor(e){this.globalContext=e}async selectRelevantHistory(e,t,n){let r=[],s=this.globalContext.getStepDependencies().get(e)||[];for(let c of s){let l=this.globalContext.getStepSummary(c);l&&r.push({stepId:c,type:"dependency",content:l.summary,metadata:l.metadata})}let i=this.getRecentCompletedSteps(3);for(let c of i)if(!s.includes(c)){let l=this.globalContext.getStepSummary(c);l&&this.isLikelyRelevant(l.summary,t)&&r.push({stepId:c,type:"recent",content:l.summary,metadata:l.metadata})}if(n==="explorer")C("\u8DF3\u8FC7\u63A2\u7D22\u5386\u53F2\u6CE8\u5165 (\u5F53\u524D\u4E3A explorer \u667A\u80FD\u4F53)");else{let c=this.globalContext.getExplorationHistory();c&&(r.push({stepId:0,type:"exploration",content:c.content,metadata:{timestamp:c.timestamp,summary:c.summary}}),C(`\u5DF2\u6DFB\u52A0\u63A2\u7D22\u5386\u53F2\u5230\u4E0A\u4E0B\u6587 (\u667A\u80FD\u4F53: ${n||"unknown"})`))}return C(`\u4E3A\u6B65\u9AA4 ${e} \u9009\u62E9\u4E86 ${r.length} \u6761\u76F8\u5173\u5386\u53F2`),r}getRecentCompletedSteps(e){return Array.from(this.globalContext.getStepDependencies().keys()).slice(-e)}isLikelyRelevant(e,t){let n=a=>a.toLowerCase().split(/\s+/).filter(c=>c.length>3).slice(0,10),r=new Set(n(e));return n(t).filter(a=>r.has(a)).length>=2}async selectRelevantHistoryWithLLM(e,t,n){let{MODEL:r}=await Promise.resolve().then(()=>(ae(),yt)),{callModelAPI:s}=await Promise.resolve().then(()=>(Ce(),jt)),i=Array.from(this.globalContext.getStepDependencies().entries()).map(([c,l])=>{let g=this.globalContext.getStepSummary(c);return g?`\u6B65\u9AA4${c}: ${g.summary}`:""}).filter(Boolean).join(`
|
|
1105
|
+
`);if(!i){if(!(n==="explorer")){let l=this.globalContext.getExplorationHistory();if(l)return[{stepId:0,type:"exploration",content:l.content,metadata:{timestamp:l.timestamp,summary:l.summary}}]}return[]}let a=`\u4EFB\u52A1: ${this.globalContext.getOriginalTask()||""}
|
|
1004
1106
|
|
|
1005
1107
|
\u5DF2\u5B8C\u6210\u7684\u5386\u53F2\u6B65\u9AA4\u6458\u8981:
|
|
1006
|
-
${
|
|
1108
|
+
${i}
|
|
1007
1109
|
|
|
1008
1110
|
\u5F53\u524D\u6B65\u9AA4: ${t}
|
|
1009
1111
|
|
|
1010
1112
|
\u95EE\u9898: \u5F53\u524D\u6B65\u9AA4\u9700\u8981\u54EA\u4E9B\u5386\u53F2\u6B65\u9AA4\u7684\u4FE1\u606F\uFF1F\u8BF7\u5206\u6790\u4F9D\u8D56\u5173\u7CFB\u3002
|
|
1011
1113
|
\u8F93\u51FA\u683C\u5F0F: \u8FD4\u56DEJSON\u6570\u7EC4\uFF0C\u5305\u542B\u76F8\u5173\u6B65\u9AA4ID\uFF0C\u4F8B\u5982 [1, 3]\u3002\u5982\u679C\u4E0D\u9700\u8981\u5386\u53F2\u4FE1\u606F\uFF0C\u8FD4\u56DE []\u3002
|
|
1012
|
-
\u53EA\u8FD4\u56DEJSON\uFF0C\u4E0D\u8981\u5176\u4ED6\u89E3\u91CA\u3002`;try{let
|
|
1114
|
+
\u53EA\u8FD4\u56DEJSON\uFF0C\u4E0D\u8981\u5176\u4ED6\u89E3\u91CA\u3002`;try{let l=(await s({model:r(),messages:[{role:"user",content:a}],temperature:.1,max_tokens:100})).choices[0].message.content?.trim()||"[]",p=JSON.parse(l).map(m=>{let d=this.globalContext.getStepSummary(m);return d?{stepId:m,type:"llm_selected",content:d.summary,metadata:d.metadata}:null}).filter(m=>m!==null);if(n==="explorer")C("\u8DF3\u8FC7\u63A2\u7D22\u5386\u53F2\u6CE8\u5165 (LLM\u6A21\u5F0F, \u5F53\u524D\u4E3A explorer \u667A\u80FD\u4F53)");else{let m=this.globalContext.getExplorationHistory();m&&(p.push({stepId:0,type:"exploration",content:m.content,metadata:{timestamp:m.timestamp,summary:m.summary}}),C(`\u5DF2\u6DFB\u52A0\u63A2\u7D22\u5386\u53F2\u5230\u4E0A\u4E0B\u6587 (LLM\u6A21\u5F0F, \u667A\u80FD\u4F53: ${n||"unknown"})`))}return $(`LLM \u4E3A\u6B65\u9AA4 ${e} \u9009\u62E9\u4E86 ${p.length} \u6761\u76F8\u5173\u5386\u53F2`),p}catch(c){return C(`LLM \u9009\u62E9\u5386\u53F2\u5931\u8D25\uFF0C\u964D\u7EA7\u5230\u542F\u53D1\u5F0F\u65B9\u6CD5: ${c instanceof Error?c.message:String(c)}`),this.selectRelevantHistory(e,t,n)}}},_e=class{globalContext;disclosure;constructor(e,t){this.globalContext=e,this.disclosure=t}async buildIsolatedContext(e,t,n="",r=!1,s,i){let a=[];n&&a.push({role:"system",content:n});let c=await this.buildProjectEnvironmentContext();c&&a.push({role:"system",content:`## \u9879\u76EE\u73AF\u5883\u4FE1\u606F
|
|
1013
1115
|
|
|
1014
|
-
${
|
|
1116
|
+
${c}`}),a.push({role:"user",content:`\u539F\u59CB\u4EFB\u52A1: ${this.globalContext.getOriginalTask()||""}`}),this.globalContext.getSharedState().rules&&a.push({role:"system",content:`\u26A0\uFE0F \u3010\u91CD\u8981\u3011\u9879\u76EE\u89C4\u5219 - \u6A21\u578B\u5FC5\u987B\u4E25\u683C\u9075\u5B88
|
|
1015
1117
|
|
|
1016
1118
|
===============================
|
|
1017
1119
|
===== \u9879\u76EE\u89C4\u5219\u4E0E\u7EA6\u5B9A =====
|
|
@@ -1020,52 +1122,99 @@ ${a}`}),i.push({role:"user",content:`\u539F\u59CB\u4EFB\u52A1: ${this.globalCont
|
|
|
1020
1122
|
${this.globalContext.getSharedState().rules}
|
|
1021
1123
|
|
|
1022
1124
|
===============================
|
|
1023
|
-
\u26A0\uFE0F \u91CD\u8981\u63D0\u9192\uFF1A\u5728\u6267\u884C\u6240\u6709\u4EFB\u52A1\u65F6\uFF0C\u5FC5\u987B\u4E25\u683C\u9075\u5B88\u4E0A\u8FF0\u9879\u76EE\u89C4\u5219\u548C\u7EA6\u5B9A\uFF0C\u786E\u4FDD\u751F\u6210\u7684\u4EE3\u7801\u3001\u6587\u4EF6\u7ED3\u6784\u548C\u5B9E\u73B0\u65B9\u5F0F\u7B26\u5408\u9879\u76EE\u8981\u6C42\u3002\u5982\u679C\u8FDD\u53CD\u89C4\u5219\uFF0C\u53EF\u80FD\u5BFC\u81F4\u4EFB\u52A1\u5931\u8D25\u6216\u9700\u8981\u91CD\u65B0\u6267\u884C\u3002`});let
|
|
1125
|
+
\u26A0\uFE0F \u91CD\u8981\u63D0\u9192\uFF1A\u5728\u6267\u884C\u6240\u6709\u4EFB\u52A1\u65F6\uFF0C\u5FC5\u987B\u4E25\u683C\u9075\u5B88\u4E0A\u8FF0\u9879\u76EE\u89C4\u5219\u548C\u7EA6\u5B9A\uFF0C\u786E\u4FDD\u751F\u6210\u7684\u4EE3\u7801\u3001\u6587\u4EF6\u7ED3\u6784\u548C\u5B9E\u73B0\u65B9\u5F0F\u7B26\u5408\u9879\u76EE\u8981\u6C42\u3002\u5982\u679C\u8FDD\u53CD\u89C4\u5219\uFF0C\u53EF\u80FD\u5BFC\u81F4\u4EFB\u52A1\u5931\u8D25\u6216\u9700\u8981\u91CD\u65B0\u6267\u884C\u3002`});let l;if(r?l=await this.disclosure.selectRelevantHistoryWithLLM(e,t,i):l=await this.disclosure.selectRelevantHistory(e,t,i),l.length>0){let g=l.map(p=>`[\u6B65\u9AA4${p.stepId}] ${p.content}`).join(`
|
|
1024
1126
|
|
|
1025
|
-
`);
|
|
1026
|
-
${
|
|
1027
|
-
${t}`}),s&&s.length>0&&
|
|
1127
|
+
`);a.push({role:"user",content:`\u76F8\u5173\u5386\u53F2\u4FE1\u606F:
|
|
1128
|
+
${g}`})}return a.push({role:"user",content:`\u5F53\u524D\u4EFB\u52A1 (\u6B65\u9AA4 ${e}/${this.globalContext.getPlan().totalSteps}):
|
|
1129
|
+
${t}`}),s&&s.length>0&&a.push({role:"system",content:`\u26A0\uFE0F \u672C\u6B65\u9AA4\u5DE5\u5177\u4F7F\u7528\u9650\u5236:
|
|
1028
1130
|
\u4F60\u53EA\u80FD\u4F7F\u7528\u4EE5\u4E0B\u5DE5\u5177: ${s.join(", ")}
|
|
1029
1131
|
|
|
1030
1132
|
\u5982\u679C\u4F60\u5C1D\u8BD5\u4F7F\u7528\u672A\u6388\u6743\u7684\u5DE5\u5177\uFF0C\u8C03\u7528\u4F1A\u88AB\u62D2\u7EDD\u3002
|
|
1031
|
-
\u8BF7\u4E25\u683C\u9075\u5B88\u5DE5\u5177\u4F7F\u7528\u8303\u56F4\uFF0C\u4E13\u6CE8\u4E8E\u5F53\u524D\u6B65\u9AA4\u7684\u76EE\u6807\u3002`}),this.globalContext.getSharedState().recentFiles.length>0&&
|
|
1133
|
+
\u8BF7\u4E25\u683C\u9075\u5B88\u5DE5\u5177\u4F7F\u7528\u8303\u56F4\uFF0C\u4E13\u6CE8\u4E8E\u5F53\u524D\u6B65\u9AA4\u7684\u76EE\u6807\u3002`}),this.globalContext.getSharedState().recentFiles.length>0&&a.push({role:"system",content:`\u6700\u8FD1\u8BBF\u95EE\u7684\u6587\u4EF6: ${this.globalContext.getSharedState().recentFiles.slice(0,5).join(", ")}`}),t.match(/实现|创建|编写|设计|开发|生成/)&&a.push({role:"system",content:`\u26A0\uFE0F CRITICAL REMINDER FOR CODE TASKS:
|
|
1032
1134
|
- You MUST use Action: write(path, content) to save any code you generate
|
|
1033
1135
|
- You MUST use Action: merge(path, content) to modify existing files
|
|
1034
1136
|
- NEVER just output code without saving it using Action:
|
|
1035
1137
|
- Follow the exact format: "Thought: ..." then "Action: tool_name(args)"
|
|
1036
|
-
- When task is done, use "Answer: ..." to finish`})
|
|
1037
|
-
|
|
1138
|
+
- When task is done, use "Answer: ..." to finish`}),$(`\u4E3A\u6B65\u9AA4 ${e} \u6784\u5EFA\u4E86\u9694\u79BB\u4E0A\u4E0B\u6587\uFF0C\u5305\u542B ${a.length} \u6761\u6D88\u606F`),s&&$(`\u5DE5\u5177\u9650\u5236: ${s.join(", ")}`),C(`\u4E0A\u4E0B\u6587\u8BE6\u60C5: \u5386\u53F2 ${l.length} \u6761, \u6587\u4EF6 ${this.globalContext.getSharedState().recentFiles.length} \u4E2A`),a}buildSimpleContext(e,t=""){let n=[];return t&&n.push({role:"system",content:t}),n.push({role:"user",content:e}),$("\u6784\u5EFA\u4E86\u7B80\u5316\u4E0A\u4E0B\u6587\uFF08\u7B80\u5355\u4EFB\u52A1\u6A21\u5F0F\uFF09"),n}async buildProjectEnvironmentContext(){try{let e=Ft.platform(),t=Ft.arch(),n=Ft.version(),r=process.cwd(),s=`\u{1F30D} **\u667A\u80FD\u73AF\u5883\u611F\u77E5\u7CFB\u7EDF**
|
|
1139
|
+
|
|
1140
|
+
**\u91CD\u8981\u63D0\u9192\uFF1A\u4F60\u5FC5\u987B\u59CB\u7EC8\u8003\u8651\u5F53\u524D\u8FD0\u884C\u73AF\u5883\uFF0C\u8FD9\u76F4\u63A5\u5F71\u54CD\u4F60\u7684\u547D\u4EE4\u9009\u62E9\u548C\u4EE3\u7801\u751F\u6210\u7B56\u7565\u3002**
|
|
1141
|
+
|
|
1142
|
+
### \u{1F4CA} \u5F53\u524D\u8FD0\u884C\u73AF\u5883
|
|
1143
|
+
- **\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0:** ${e} ${e==="win32"?"(Windows)":e==="darwin"?"(macOS)":"(Linux)"}
|
|
1038
1144
|
- **\u64CD\u4F5C\u7CFB\u7EDF\u7248\u672C:** ${n}
|
|
1039
1145
|
- **\u7CFB\u7EDF\u67B6\u6784:** ${t}
|
|
1040
|
-
- **\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55:** ${
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1146
|
+
- **\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55:** ${r}
|
|
1147
|
+
- **\u9ED8\u8BA4Shell:** ${e==="win32"?"cmd.exe (Windows\u547D\u4EE4\u63D0\u793A\u7B26)":e==="darwin"?"zsh (macOS\u7EC8\u7AEF)":"bash (Linux\u7EC8\u7AEF)"}
|
|
1148
|
+
|
|
1149
|
+
### \u{1F3AF} \u5E73\u53F0\u7279\u5B9A\u6307\u5BFC\u539F\u5219
|
|
1150
|
+
|
|
1151
|
+
#### ${e==="win32"?"\u{1FA9F} Windows\u73AF\u5883\u6307\u5BFC":e==="darwin"?"\u{1F34E} macOS\u73AF\u5883\u6307\u5BFC":"\u{1F427} Linux\u73AF\u5883\u6307\u5BFC"}
|
|
1152
|
+
${e==="win32"?`
|
|
1153
|
+
**Windows\u7279\u5B9A\u6CE8\u610F\u4E8B\u9879\uFF1A**
|
|
1154
|
+
- \u4F7F\u7528Windows\u7B49\u4EF7\u547D\u4EE4\uFF1Adir(\u4EE3\u66FFls), where(\u4EE3\u66FFwhich), type(\u4EE3\u66FFcat)
|
|
1155
|
+
- \u8DEF\u5F84\u5206\u9694\u7B26\u4F7F\u7528\u53CD\u659C\u6760()\uFF0C\u4F46Node.js\u901A\u5E38\u652F\u6301\u6B63\u659C\u6760(/)
|
|
1156
|
+
- \u73AF\u5883\u53D8\u91CF\u4F7F\u7528%VAR%\u683C\u5F0F\uFF0C\u4F46PowerShell\u4F7F\u7528$env:VAR
|
|
1157
|
+
- \u63A8\u8350\u4F7F\u7528PowerShell\u6216CMD\uFF0C\u907F\u514DUnix\u7279\u6709\u547D\u4EE4
|
|
1158
|
+
- \u6587\u4EF6\u7F16\u7801\u6CE8\u610FUTF-8\u4E0EGBK\u7684\u533A\u522B
|
|
1159
|
+
- \u4F7F\u7528chcp 65001\u8BBE\u7F6EUTF-8\u7F16\u7801\u907F\u514D\u4E2D\u6587\u4E71\u7801`:e==="darwin"?`
|
|
1160
|
+
**macOS\u7279\u5B9A\u6CE8\u610F\u4E8B\u9879\uFF1A**
|
|
1161
|
+
- \u4F7F\u7528Homebrew\u4F5C\u4E3A\u9996\u9009\u5305\u7BA1\u7406\u5668\uFF1Abrew install package
|
|
1162
|
+
- \u9ED8\u8BA4shell\u662Fzsh\uFF0C\u652F\u6301\u73B0\u4EE3shell\u7279\u6027
|
|
1163
|
+
- \u4F7F\u7528ls\u3001grep\u3001find\u7B49Unix\u539F\u751F\u547D\u4EE4
|
|
1164
|
+
- \u5E94\u7528\u5B89\u88C5\u5728/Applications\u76EE\u5F55
|
|
1165
|
+
- \u4F7F\u7528launchctl\u7BA1\u7406\u670D\u52A1
|
|
1166
|
+
- \u914D\u7F6E\u6587\u4EF6\u901A\u5E38\u5728~/.zshrc`:`
|
|
1167
|
+
**Linux\u7279\u5B9A\u6CE8\u610F\u4E8B\u9879\uFF1A**
|
|
1168
|
+
- \u6839\u636E\u53D1\u884C\u7248\u4F7F\u7528\u9002\u5F53\u7684\u5305\u7BA1\u7406\u5668\uFF1Aapt(Ubuntu/Debian)\u3001yum/dnf(CentOS/RHEL)\u3001pacman(Arch)
|
|
1169
|
+
- \u4F7F\u7528ls\u3001grep\u3001find\u3001awk\u3001sed\u7B49GNU\u5DE5\u5177
|
|
1170
|
+
- \u670D\u52A1\u7BA1\u7406\u4F7F\u7528systemctl\u547D\u4EE4
|
|
1171
|
+
- \u914D\u7F6E\u6587\u4EF6\u901A\u5E38\u5728~/.bashrc\u6216~/.profile
|
|
1172
|
+
- \u6CE8\u610F\u6743\u9650\u7BA1\u7406\uFF0C\u9002\u5F53\u4F7F\u7528sudo`}
|
|
1173
|
+
|
|
1174
|
+
### \u{1F527} \u8DE8\u5E73\u53F0\u5F00\u53D1\u6700\u4F73\u5B9E\u8DF5
|
|
1175
|
+
- **\u8DEF\u5F84\u5904\u7406\uFF1A** \u4F7F\u7528path.join()\u548Cpath.sep\u786E\u4FDD\u8DE8\u5E73\u53F0\u517C\u5BB9\u6027
|
|
1176
|
+
- **\u73AF\u5883\u53D8\u91CF\uFF1A** \u4F7F\u7528process.env\u8BBF\u95EE\uFF0C\u907F\u514D\u5E73\u53F0\u7279\u5B9A\u8BED\u6CD5
|
|
1177
|
+
- **\u547D\u4EE4\u6267\u884C\uFF1A** \u4F18\u5148\u4F7F\u7528Node.js API\uFF0C\u5FC5\u8981\u65F6\u4F7F\u7528\u8DE8\u5E73\u53F0\u547D\u4EE4
|
|
1178
|
+
- **\u6587\u4EF6\u7CFB\u7EDF\uFF1A** \u6CE8\u610FWindows\u4E0D\u533A\u5206\u5927\u5C0F\u5199\uFF0CUnix\u7CFB\u7EDF\u533A\u5206\u5927\u5C0F\u5199
|
|
1179
|
+
- **\u884C\u5C3E\u7B26\uFF1A** Windows\u4F7F\u7528\r
|
|
1180
|
+
\uFF0CUnix\u4F7F\u7528
|
|
1181
|
+
\uFF0C\u4F7F\u7528os.EOL\u83B7\u53D6\u6B63\u786E\u683C\u5F0F
|
|
1182
|
+
|
|
1183
|
+
### \u26A1 \u547D\u4EE4\u9009\u62E9\u7B56\u7565
|
|
1184
|
+
1. **\u6587\u4EF6\u64CD\u4F5C\uFF1A** ${e==="win32"?"\u4F7F\u7528dir\u3001copy\u3001move\u3001del":"\u4F7F\u7528ls\u3001cp\u3001mv\u3001rm"}
|
|
1185
|
+
2. **\u6587\u672C\u5904\u7406\uFF1A** ${e==="win32"?"\u4F7F\u7528findstr\u3001more":"\u4F7F\u7528grep\u3001less\u3001cat"}
|
|
1186
|
+
3. **\u7CFB\u7EDF\u4FE1\u606F\uFF1A** ${e==="win32"?"\u4F7F\u7528ipconfig\u3001tasklist":"\u4F7F\u7528ifconfig\u3001ps"}
|
|
1187
|
+
4. **\u5305\u7BA1\u7406\uFF1A** ${e==="win32"?"\u4F7F\u7528npm\u3001winget\u3001choco":e==="darwin"?"\u4F7F\u7528npm\u3001brew":"\u4F7F\u7528npm\u3001apt\u3001yum\u3001dnf"}
|
|
1188
|
+
|
|
1189
|
+
### \u{1F6A8} \u91CD\u8981\u63D0\u9192
|
|
1190
|
+
- \u5728\u6267\u884Cshell\u547D\u4EE4\u524D\uFF0C\u52A1\u5FC5\u8003\u8651\u5F53\u524D\u5E73\u53F0\u7279\u6027
|
|
1191
|
+
- \u5F53\u7528\u6237\u8BF7\u6C42\u4F7F\u7528Unix\u547D\u4EE4\u65F6\uFF0C${e==="win32"?"\u81EA\u52A8\u8F6C\u6362\u4E3AWindows\u7B49\u4EF7\u547D\u4EE4":"\u76F4\u63A5\u4F7F\u7528Unix\u547D\u4EE4"}
|
|
1192
|
+
- \u63D0\u4F9B\u547D\u4EE4\u5EFA\u8BAE\u65F6\uFF0C\u4F18\u5148\u63A8\u8350${e==="win32"?"Windows\u539F\u751F":"Unix\u539F\u751F"}\u65B9\u6848
|
|
1193
|
+
- \u9047\u5230\u8DE8\u5E73\u53F0\u517C\u5BB9\u6027\u95EE\u9898\u65F6\uFF0C\u4E3B\u52A8\u63D0\u51FA\u89E3\u51B3\u65B9\u6848`;try{let i=await import("fs"),c=(await import("path")).join(r,".nium/project/project.json");if(i.existsSync(c)){let l=i.readFileSync(c,"utf-8");try{let g=JSON.parse(l),p=this.extractProjectSummaryFromJSON(g);s+=`
|
|
1045
1194
|
**\u9879\u76EE\u7ED3\u6784\u6458\u8981:**
|
|
1046
|
-
${
|
|
1195
|
+
${p}
|
|
1047
1196
|
|
|
1048
|
-
**\u5B8C\u6574\u7ED3\u6784\u6587\u6863:** \u5982\u9700\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u8BF7\u4F7F\u7528 read('.nium/project/project.json')`}catch(
|
|
1197
|
+
**\u5B8C\u6574\u7ED3\u6784\u6587\u6863:** \u5982\u9700\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u8BF7\u4F7F\u7528 read('.nium/project/project.json')`}catch(g){C(`\u89E3\u6790project.json\u5931\u8D25\uFF0C\u4F7F\u7528\u6587\u672C\u6458\u8981: ${g}`);let p=this.extractProjectSummary(l);s+=`
|
|
1049
1198
|
**\u9879\u76EE\u7ED3\u6784\u6458\u8981:**
|
|
1050
|
-
${
|
|
1199
|
+
${p}
|
|
1051
1200
|
|
|
1052
|
-
**\u5B8C\u6574\u7ED3\u6784\u6587\u6863:** \u5982\u9700\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u8BF7\u4F7F\u7528 read('.nium/project/project.json')`}}}catch(i){
|
|
1053
|
-
`),n=[],
|
|
1054
|
-
`)}},
|
|
1055
|
-
`);if(
|
|
1201
|
+
**\u5B8C\u6574\u7ED3\u6784\u6587\u6863:** \u5982\u9700\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u8BF7\u4F7F\u7528 read('.nium/project/project.json')`}}}catch(i){C(`\u83B7\u53D6\u9879\u76EE\u7ED3\u6784\u4FE1\u606F\u5931\u8D25: ${i}`)}return s}catch(e){return C(`\u6784\u5EFA\u9879\u76EE\u73AF\u5883\u4E0A\u4E0B\u6587\u5931\u8D25: ${e}`),null}}extractProjectSummaryFromJSON(e){return On(e,{format:"summary",maxSections:3})}extractProjectSummary(e){let t=e.split(`
|
|
1202
|
+
`),n=[],r=!1,s=0;for(let i of t){if(i.includes("## \u9879\u76EE\u6982\u8FF0")){r=!0;continue}if(r){if(i.startsWith("##")&&!i.includes("\u9879\u76EE\u6982\u8FF0"))break;if(i.trim()&&(n.push(i),s++,s>=15))break}}return n.join(`
|
|
1203
|
+
`)}},Ne=class{async extractSummary(e){let t=[],n=[],r=null;for(let i of e)if(i.role==="assistant"){if(i.tool_calls&&i.tool_calls.length>0)for(let a of i.tool_calls){let c=a.function.name;c!=="think"&&t.push(c)}if(i.content&&i.content.includes("Answer:")){let a=i.content.match(/Answer:\s*(.+)/s);a&&(r=a[1].trim().substring(0,200))}}else i.role==="tool"&&i.content&&n.push(i.content.substring(0,100));let s="";return r?s=`\u5B8C\u6210: ${r}`:(s=`\u6267\u884C\u4E86 ${t.length} \u4E2A\u5DE5\u5177\u8C03\u7528`,t.length>0&&(s+=` (${t.slice(0,3).join(", ")})`)),C(`\u63D0\u53D6\u6458\u8981: ${s.substring(0,50)}...`),s}async extractSummaryWithLLM(e){let{LITE_MODEL:t}=await Promise.resolve().then(()=>(ae(),yt)),{callModelAPI:n}=await Promise.resolve().then(()=>(Ce(),jt)),r=e.filter(s=>s.content).map(s=>`${s.role}: ${s.content.substring(0,500)}`).join(`
|
|
1204
|
+
`);if(r.length<100)return this.extractSummary(e);try{let i=(await n({model:t(),messages:[{role:"system",content:"\u4F60\u662F\u4E00\u4E2A\u6458\u8981\u52A9\u624B\u3002\u8BF7\u5C06\u4E0B\u9762\u7684\u4EFB\u52A1\u6267\u884C\u8FC7\u7A0B\u538B\u7F29\u6210\u7B80\u6D01\u7684\u6458\u8981\uFF08\u4E0D\u8D85\u8FC7100\u5B57\uFF09\uFF0C\u4FDD\u7559\u5173\u952E\u64CD\u4F5C\u548C\u7ED3\u679C\u3002"},{role:"user",content:r}],temperature:.1,max_tokens:150,useCompression:!0})).choices[0].message.content?.trim()||"\u6267\u884C\u5B8C\u6210";return $(`LLM \u751F\u6210\u6458\u8981: ${i.substring(0,50)}...`),i}catch(s){return C(`LLM \u6458\u8981\u5931\u8D25\uFF0C\u964D\u7EA7\u5230\u542F\u53D1\u5F0F\u65B9\u6CD5: ${s instanceof Error?s.message:String(s)}`),this.extractSummary(e)}}extractMetadata(e){let t={toolsUsed:[],filesAccessed:[],errors:[],iterations:0};for(let n of e)if(n.role==="assistant"){if(t.iterations++,n.tool_calls&&n.tool_calls.length>0)for(let r of n.tool_calls){let s=r.function.name;if(s!=="think"&&(t.toolsUsed.push(s),["read","write","merge"].includes(s)))try{let i=JSON.parse(r.function.arguments),a=i.path||i.newContent;a&&t.filesAccessed.push(a)}catch{}}}else n.role==="tool"&&n.content&&n.content.includes("Error:")&&t.errors.push(n.content.substring(0,100));return t}}});var Fn,gs=S(()=>{Fn=class{anchors=[];originalQuestion;modelClient;constructor(e,t){this.originalQuestion=e,this.modelClient=t,this.initializeAnchor()}initializeAnchor(){let e={originalQuestion:this.originalQuestion,keyConstraints:this.extractConstraints(this.originalQuestion),successCriteria:this.extractSuccessCriteria(this.originalQuestion),iterationAdded:0,semanticSignature:this.generateSemanticSignature(this.originalQuestion)};this.anchors.push(e)}extractConstraints(e){let t=[/必须\s*[::]\s*(.+?)(?=\n|$)/g,/需要\s*[::]\s*(.+?)(?=\n|$)/g,/要求\s*[::]\s*(.+?)(?=\n|$)/g,/不能\s*[::]\s*(.+?)(?=\n|$)/g],n=[];return t.forEach(r=>{let s=e.match(r);s&&n.push(...s)}),n.length>0?n:["\u5B8C\u6210\u7528\u6237\u8BF7\u6C42\u7684\u4EFB\u52A1"]}extractSuccessCriteria(e){let t=[/目标\s*[::]\s*(.+?)(?=\n|$)/g,/标准\s*[::]\s*(.+?)(?=\n|$)/g,/结果\s*[::]\s*(.+?)(?=\n|$)/g,/输出\s*[::]\s*(.+?)(?=\n|$)/g],n=[];return t.forEach(r=>{let s=e.match(r);s&&n.push(...s)}),n.length>0?n:["\u63D0\u4F9B\u51C6\u786E\u548C\u6709\u7528\u7684\u7B54\u6848"]}generateSemanticSignature(e){return this.extractKeywords(e).join("|")}extractKeywords(e){let t=e.toLowerCase().replace(/[^\u4e00-\u9fa5a-zA-Z\s]/g," ").split(/\s+/).filter(i=>i.length>2),n=["\u7684","\u4E86","\u5728","\u662F","\u6211","\u6709","\u548C","\u5C31","the","is","at","which","on","to","of","a","an"],r=t.filter(i=>!n.includes(i)),s=new Map;return r.forEach(i=>{s.set(i,(s.get(i)||0)+1)}),Array.from(s.entries()).sort((i,a)=>a[1]-i[1]).slice(0,10).map(([i])=>i)}async calculateSemanticSimilarity(e){let t=this.extractKeywords(e),r=this.anchors[0].semanticSignature.split("|"),s=t.filter(c=>r.some(l=>l===c||l.includes(c)||c.includes(l))),i=new Set([...t,...r]);return i.size>0?s.length/i.size:0}shouldInjectAnchor(e,t,n){if(t<.2)return!0;let r=this.getAnchorFrequency(t);return e%r===0?!0:t>=.2&&t<.6&&n&&n.length>1e3?e%Math.max(1,Math.floor(r/2))===0:!1}getAnchorFrequency(e){return e<.2?3:e<.4?5:e<.6?8:10}generateAnchorPrompt(e,t,n){let r=this.anchors[0],s=`\u{1F3AF} \u4E0A\u4E0B\u6587\u951A\u70B9\u63D0\u9192 (\u8FED\u4EE3 ${e}):
|
|
1056
1205
|
|
|
1057
1206
|
\u26A0\uFE0F \u91CD\u8981: \u8BF7\u4E25\u683C\u9075\u5FAA\u4EE5\u4E0B\u8981\u6C42\uFF0C\u8FD9\u662F\u89E3\u51B3\u7528\u6237\u95EE\u9898\u7684\u6838\u5FC3\u6307\u5BFC\uFF1A
|
|
1058
1207
|
|
|
1059
|
-
\u539F\u59CB\u4EFB\u52A1: ${
|
|
1208
|
+
\u539F\u59CB\u4EFB\u52A1: ${r.originalQuestion}
|
|
1060
1209
|
|
|
1061
1210
|
\u{1F3AF} \u5173\u952E\u7EA6\u675F (\u5FC5\u987B\u9075\u5B88):
|
|
1062
|
-
${
|
|
1211
|
+
${r.keyConstraints.map(i=>` \u2022 ${i}`).join(`
|
|
1063
1212
|
`)}
|
|
1064
1213
|
|
|
1065
1214
|
\u2705 \u6210\u529F\u6807\u51C6 (\u5FC5\u987B\u8FBE\u6210):
|
|
1066
|
-
${
|
|
1067
|
-
`)}
|
|
1068
|
-
|
|
1215
|
+
${r.successCriteria.map(i=>` \u2022 ${i}`).join(`
|
|
1216
|
+
`)}`;return t&&(s+=`
|
|
1217
|
+
|
|
1069
1218
|
\u{1F504} \u5F53\u524D\u504F\u79BB\u63D0\u9192: ${t}`),s+=`
|
|
1070
1219
|
|
|
1071
1220
|
\u{1F4A1} \u884C\u52A8\u6307\u5BFC:
|
|
@@ -1075,7 +1224,7 @@ ${o.successCriteria.map(i=>` \u2022 ${i}`).join(`
|
|
|
1075
1224
|
4. \u786E\u4FDD\u6BCF\u4E00\u6B65\u90FD\u671D\u7740\u6700\u7EC8\u76EE\u6807\u524D\u8FDB
|
|
1076
1225
|
5. \u6700\u7EC8\u7B54\u6848\u5FC5\u987B\u76F4\u63A5\u56DE\u5E94\u539F\u59CB\u95EE\u9898\u7684\u8981\u6C42
|
|
1077
1226
|
|
|
1078
|
-
\u26A1 \u5F3A\u5236\u6267\u884C: \u8FD9\u662F\u6700\u9AD8\u4F18\u5148\u7EA7\u6307\u4EE4\uFF0C\u8986\u76D6\u5176\u4ED6\u6240\u6709\u4E00\u822C\u6027\u5EFA\u8BAE\u3002`,s}createAnchorMessage(e,t,n,
|
|
1227
|
+
\u26A1 \u5F3A\u5236\u6267\u884C: \u8FD9\u662F\u6700\u9AD8\u4F18\u5148\u7EA7\u6307\u4EE4\uFF0C\u8986\u76D6\u5176\u4ED6\u6240\u6709\u4E00\u822C\u6027\u5EFA\u8BAE\u3002`,s}createAnchorMessage(e,t,n,r,s){let i=this.generateAnchorPrompt(e,r,s),a="medium";t<.3||n==="severe"?a="high":t>.7&&(!n||n==="none")&&(a="low");let c={type:"context_anchor",iteration:e,similarity:t,priority:a,driftLevel:n,timestamp:new Date().toISOString()};return{role:"system",content:i,metadata:c}}addMidwayAnchor(e,t,n){let r={originalQuestion:this.originalQuestion,keyConstraints:this.extractConstraints(t),successCriteria:this.extractSuccessCriteria(t),iterationAdded:e,semanticSignature:this.generateSemanticSignature(t+" "+n)};this.anchors.push(r)}getOriginalQuestion(){return this.originalQuestion}getAnchors(){return this.anchors}}});var jn,ps=S(()=>{ae();jn=class{modelClient;constructor(e){this.modelClient=e}async analyzeSemanticDrift(e,t,n){let r=`\u5206\u6790\u4EE5\u4E0B\u4E24\u4E2A\u6587\u672C\u7684\u8BED\u4E49\u76F8\u4F3C\u5EA6\u548C\u504F\u79BB\u7A0B\u5EA6\uFF1A
|
|
1079
1228
|
|
|
1080
1229
|
\u539F\u59CB\u6587\u672C: "${e}"
|
|
1081
1230
|
|
|
@@ -1087,7 +1236,7 @@ ${o.successCriteria.map(i=>` \u2022 ${i}`).join(`
|
|
|
1087
1236
|
3. keyTopics: \u4E24\u4E2A\u6587\u672C\u7684\u5173\u952E\u4E3B\u9898\u5217\u8868
|
|
1088
1237
|
4. deviationFactors: \u5BFC\u81F4\u504F\u79BB\u7684\u56E0\u7D20\u5217\u8868
|
|
1089
1238
|
|
|
1090
|
-
\u53EA\u8FD4\u56DEJSON\uFF0C\u4E0D\u8981\u5176\u4ED6\u89E3\u91CA\u3002`;try{let i=(await this.modelClient({model:
|
|
1239
|
+
\u53EA\u8FD4\u56DEJSON\uFF0C\u4E0D\u8981\u5176\u4ED6\u89E3\u91CA\u3002`;try{let i=(await this.modelClient({model:Pe(),messages:[{role:"user",content:r}],temperature:.1,max_tokens:200})).choices[0].message.content?.trim();if(i)return JSON.parse(i);throw new Error("Empty response from model")}catch{return this.simpleSemanticAnalysis(e,t)}}simpleSemanticAnalysis(e,t){let n=this.extractKeywords(e),r=this.extractKeywords(t),i=n.filter(c=>r.some(l=>l.includes(c)||c.includes(l))).length/Math.max(n.length,r.length),a;return i>.6?a="none":i>.4?a="minor":i>.2?a="moderate":a="severe",{similarityScore:i,driftLevel:a,keyTopics:[...new Set([...n,...r])],deviationFactors:this.identifyDeviationFactors(n,r)}}extractKeywords(e){let t=e.toLowerCase().replace(/[^\u4e00-\u9fa5a-zA-Z\s]/g," ").split(/\s+/).filter(r=>r.length>2),n=["\u7684","\u4E86","\u5728","\u662F","\u6211","\u6709","\u548C","\u5C31","the","is","at","which","on","to","of","a","an"];return[...new Set(t.filter(r=>!n.includes(r)))]}identifyDeviationFactors(e,t){let n=[],r=e.filter(i=>!t.some(a=>a.includes(i)||i.includes(a))),s=t.filter(i=>!e.some(a=>a.includes(i)||i.includes(a)));return r.length>0&&n.push(`\u4E22\u5931\u4E86\u5173\u952E\u4E3B\u9898: ${r.slice(0,3).join(", ")}`),s.length>0&&n.push(`\u5F15\u5165\u4E86\u65B0\u7684\u4E3B\u9898: ${s.slice(0,3).join(", ")}`),n.length===0&&n.push("\u8BED\u4E49\u76F8\u5173\u6027\u8F83\u4F4E"),n}generateCorrectionPrompt(e,t,n){let r=`\u26A0\uFE0F \u504F\u79BB\u68C0\u6D4B\u8B66\u544A
|
|
1091
1240
|
|
|
1092
1241
|
\u68C0\u6D4B\u5230${t==="severe"?"\u4E25\u91CD":"\u8F7B\u5FAE"}\u504F\u79BB\u539F\u59CB\u95EE\u9898\u3002
|
|
1093
1242
|
|
|
@@ -1097,17 +1246,47 @@ ${o.successCriteria.map(i=>` \u2022 ${i}`).join(`
|
|
|
1097
1246
|
${n.map(s=>`\u2022 ${s}`).join(`
|
|
1098
1247
|
`)}
|
|
1099
1248
|
|
|
1100
|
-
\u8BF7\u7ACB\u5373\u8C03\u6574\u601D\u8DEF\uFF0C\u91CD\u65B0\u805A\u7126\u4E8E\u539F\u59CB\u95EE\u9898\u7684\u6838\u5FC3\u8981\u6C42\u3002`;return t==="severe"&&(
|
|
1249
|
+
\u8BF7\u7ACB\u5373\u8C03\u6574\u601D\u8DEF\uFF0C\u91CD\u65B0\u805A\u7126\u4E8E\u539F\u59CB\u95EE\u9898\u7684\u6838\u5FC3\u8981\u6C42\u3002`;return t==="severe"&&(r+=`
|
|
1250
|
+
|
|
1251
|
+
\u{1F3AF} \u91CD\u8981\u63D0\u9192\uFF1A\u8BF7\u91CD\u65B0\u5F00\u59CB\u5206\u6790\u539F\u59CB\u95EE\u9898\uFF0C\u5FFD\u7565\u4E4B\u524D\u7684\u8FB9\u7F18\u63A2\u7D22\u3002`),r}}});function Ra(o){let e=Lu[o],t=process.env[o]||e.defaultValue;switch(e.type){case"boolean":return t.toLowerCase()==="true";case"number":return parseFloat(t);case"string":default:return t}}function Ue(o){let e=Ra(o);return typeof e=="number"?e:parseFloat(String(e))}function ms(o){let e=Ra(o);return typeof e=="boolean"?e:String(e).toLowerCase()==="true"}var Lu,ds=S(()=>{Lu={USE_LLM_DISCLOSURE:{name:"USE_LLM_DISCLOSURE",defaultValue:"true",description:"\u662F\u5426\u4F7F\u7528 LLM \u667A\u80FD\u62AB\u9732\u5386\u53F2\u4FE1\u606F\u3002\u542F\u7528\u540E\uFF0C\u7CFB\u7EDF\u4F1A\u4F7F\u7528 LLM \u5206\u6790\u5E76\u7B5B\u9009\u76F8\u5173\u5386\u53F2\u4E0A\u4E0B\u6587\uFF0C\u63D0\u9AD8\u4EFB\u52A1\u6267\u884C\u7CBE\u51C6\u5EA6",type:"boolean",category:"LLM \u914D\u7F6E",example:"true"},USE_LLM_SUMMARY:{name:"USE_LLM_SUMMARY",defaultValue:"true",description:"\u662F\u5426\u4F7F\u7528 LLM \u751F\u6210\u4EFB\u52A1\u6458\u8981\u3002\u542F\u7528\u540E\uFF0C\u6BCF\u4E2A\u6B65\u9AA4\u5B8C\u6210\u65F6\u4F1A\u751F\u6210\u7B80\u6D01\u6458\u8981\u4F9B\u540E\u7EED\u6B65\u9AA4\u53C2\u8003",type:"boolean",category:"LLM \u914D\u7F6E",example:"true"},CONTEXT_COMPRESSION_INTERVAL:{name:"CONTEXT_COMPRESSION_INTERVAL",defaultValue:"15",description:"\u4E0A\u4E0B\u6587\u538B\u7F29\u95F4\u9694\uFF08\u8FED\u4EE3\u6B21\u6570\uFF09\u3002\u6BCF\u9694\u591A\u5C11\u6B21\u8FED\u4EE3\u6267\u884C\u4E00\u6B21\u4E0A\u4E0B\u6587\u538B\u7F29\uFF0C\u907F\u514D\u4E0A\u4E0B\u6587\u8FC7\u957F",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"15"},CONTEXT_SEMANTIC_CHECK_INTERVAL:{name:"CONTEXT_SEMANTIC_CHECK_INTERVAL",defaultValue:"5",description:"\u8BED\u4E49\u68C0\u67E5\u95F4\u9694\uFF08\u8FED\u4EE3\u6B21\u6570\uFF09\u3002\u6BCF\u9694\u591A\u5C11\u6B21\u8FED\u4EE3\u68C0\u67E5\u4E00\u6B21\u8BED\u4E49\u504F\u79BB\u60C5\u51B5",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"5"},CONTEXT_ANCHOR_INTERVAL:{name:"CONTEXT_ANCHOR_INTERVAL",defaultValue:"10",description:"\u951A\u70B9\u6CE8\u5165\u95F4\u9694\uFF08\u8FED\u4EE3\u6B21\u6570\uFF09\u3002\u6BCF\u9694\u591A\u5C11\u6B21\u8FED\u4EE3\u6CE8\u5165\u4E00\u6B21\u539F\u59CB\u4EFB\u52A1\u951A\u70B9\uFF0C\u9632\u6B62\u4EFB\u52A1\u504F\u79BB",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"10"},CONTEXT_SIMILARITY_THRESHOLD:{name:"CONTEXT_SIMILARITY_THRESHOLD",defaultValue:"0.3",description:"\u8BED\u4E49\u76F8\u4F3C\u5EA6\u9608\u503C\uFF080-1\uFF09\u3002\u4F4E\u4E8E\u6B64\u9608\u503C\u8BA4\u4E3A\u8BED\u4E49\u504F\u79BB\uFF0C\u9700\u8981\u89E6\u53D1\u7EA0\u6B63\u673A\u5236",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"0.3"},CONTEXT_MAX_MESSAGES:{name:"CONTEXT_MAX_MESSAGES",defaultValue:"50",description:"\u538B\u7F29\u524D\u6700\u5927\u6D88\u606F\u6570\u3002\u4E0A\u4E0B\u6587\u6D88\u606F\u6570\u8D85\u8FC7\u6B64\u503C\u65F6\u89E6\u53D1\u538B\u7F29",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"50"},CONTEXT_DRIFT_THRESHOLD:{name:"CONTEXT_DRIFT_THRESHOLD",defaultValue:"0.25",description:"\u4E0A\u4E0B\u6587\u504F\u79BB\u7EA0\u6B63\u9608\u503C\uFF080-1\uFF09\u3002\u8BED\u4E49\u504F\u79BB\u5EA6\u8D85\u8FC7\u6B64\u503C\u65F6\u89E6\u53D1\u504F\u79BB\u7EA0\u6B63",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"0.25"},CONTEXT_COMPRESSION_RATIO:{name:"CONTEXT_COMPRESSION_RATIO",defaultValue:"0.7",description:"\u76EE\u6807\u538B\u7F29\u7387\uFF080-1\uFF09\u3002\u538B\u7F29\u540E\u7684\u4E0A\u4E0B\u6587\u76EE\u6807\u5927\u5C0F\u76F8\u5BF9\u4E8E\u539F\u59CB\u5927\u5C0F\u7684\u6BD4\u4F8B",type:"number",category:"\u4E0A\u4E0B\u6587\u4F18\u5316",example:"0.7"}}});function Rr(){return{...Du,compressionInterval:Ue("CONTEXT_COMPRESSION_INTERVAL"),semanticCheckInterval:Ue("CONTEXT_SEMANTIC_CHECK_INTERVAL"),anchorInjectionInterval:Ue("CONTEXT_ANCHOR_INTERVAL"),similarityThreshold:Ue("CONTEXT_SIMILARITY_THRESHOLD"),maxMessagesBeforeCompression:Ue("CONTEXT_MAX_MESSAGES"),driftCorrectionThreshold:Ue("CONTEXT_DRIFT_THRESHOLD"),compressionRatioTarget:Ue("CONTEXT_COMPRESSION_RATIO")}}var Du,fs=S(()=>{ds();Du={compressionInterval:15,semanticCheckInterval:5,anchorInjectionInterval:10,similarityThreshold:.3,maxMessagesBeforeCompression:50,enableSmartCompression:!0,enableSemanticAnalysis:!0,enableAnchorSystem:!0,driftCorrectionThreshold:.25,maxContextLength:100,compressionRatioTarget:.7}});var Fa={};j(Fa,{getGitDiff:()=>Nn,getGitStatus:()=>_n,gitAddAll:()=>hs,gitCommit:()=>ys,hasUncommittedChanges:()=>Un,isGitAvailable:()=>_u});import{execSync as rt}from"child_process";import{existsSync as Da,writeFileSync as Ou,unlinkSync as Fu}from"fs";import{join as Oa}from"path";import{tmpdir as ju}from"os";function _u(){try{let o=Oa(process.cwd(),".git");return Da(o)?(rt("git --version",{stdio:"ignore"}),C("Git is available"),!0):(C("Git not available: .git directory not found"),!1)}catch(o){return C(`Git not available: ${o.message}`),!1}}function _n(){try{return rt("git status",{encoding:"utf-8"})}catch(o){return H(`Failed to get git status: ${o.message}`),""}}function Nn(){try{let o=rt("git diff --cached",{encoding:"utf-8"}),e=rt("git diff",{encoding:"utf-8"}),t="";return o&&(t+=`=== Staged Changes ===
|
|
1252
|
+
`+o+`
|
|
1253
|
+
`),e&&(t+=`=== Unstaged Changes ===
|
|
1254
|
+
`+e),t||"No changes detected"}catch(o){return H(`Failed to get git diff: ${o.message}`),""}}function hs(){try{rt("git add .",{stdio:"inherit"})}catch(o){throw new Error(`Failed to stage changes: ${o.message}`)}}function ys(o){let e=Oa(ju(),`git-commit-${Date.now()}.txt`);try{Ou(e,o,"utf-8"),rt(`git commit -F "${e}"`,{stdio:"inherit"})}catch(t){throw new Error(`Failed to commit: ${t.message}`)}finally{try{Da(e)&&Fu(e)}catch(t){H(`Failed to cleanup temporary file: ${t.message}`)}}}function Un(){try{return rt("git status --porcelain",{encoding:"utf-8"}).trim().length>0}catch(o){return H(`Failed to check for uncommitted changes: ${o.message}`),!1}}var Dr=S(()=>{Y()});var Ss={};j(Ss,{FileChangeTracker:()=>We,createFileChangeTracker:()=>Or,detectFileChanges:()=>jr,generateChangeSummary:()=>_r,getCurrentSessionFileChanges:()=>zr,getFileChangeTracker:()=>ce,getSessionFileChanges:()=>Wr,handleGitCommit:()=>Ur,recordFileChange:()=>Nr,resetFileChangeTracker:()=>Fr});import{execSync as Cs}from"child_process";function ce(o){return _t||(_t=new We(o)),_t}function Or(o){return new We(o)}function Fr(){_t&&(_t.stopWatching(),_t=null)}async function jr(o,e){return ce(e).detectFileChanges(o)}function _r(o="text"){return ce().generateChangeSummaryText(o)}function Nr(o){let e={id:qe(),filePath:o.filePath,changeType:o.changeType,timestamp:new Date().toISOString(),source:o.source||"manual",content:o.content,size:o.size};return ce().trackSessionFileChange("default-session",void 0,[e]),e}async function Ur(o){return ce().handleGitCommit(o)}function Wr(o){return ce().getSessionFileChanges(o)}function zr(){return ce().getCurrentSessionFileChanges()}var Nu,We,_t,ot=S(()=>{fr();Dr();Nu={maxCommitHistory:50,enableGitIntegration:!0,trackSessionChanges:!0,autoDetectChanges:!0,excludePatterns:["node_modules",".git","dist","build","*.log",".DS_Store","*.tmp","*.temp"],maxFileSize:1024*1024,enableFileHashing:!0,gitStatusCheckInterval:5e3,maxContentLength:1e3,maxHistoryEntries:100,enableRealTimeMonitoring:!1,sessionTimeoutMinutes:60,enableChangeNotifications:!1,logLevel:"info"},We=class{config;sessionChanges=new Map;commitHistory=[];gitStatusCache=new Map;changeCallbacks=[];isWatching=!1;gitStatusTimer;constructor(e){this.config={...Nu,...e}}async detectFileChanges(e){try{let t=[];if(this.config.enableGitIntegration){let s=await this.detectGitChanges();t.push(...s)}let n=await this.detectFilesystemChanges();t.push(...n);let r={hasChanges:t.length>0,changes:t,summary:this.generateChangeSummary(t)};return t.length>0&&this.triggerChangeCallbacks(t),r}catch(t){return console.error("\u68C0\u6D4B\u6587\u4EF6\u53D8\u66F4\u65F6\u51FA\u9519:",t),{hasChanges:!1,changes:[],summary:{totalFiles:0,addedFiles:0,modifiedFiles:0,deletedFiles:0,renamedFiles:0,totalSize:0}}}}async detectGitChanges(){let e=[];try{if(!Un())return e;let t=_n(),n=Nn(),r=this.parseGitStatus(t),s=this.getCurrentGitHash(),i=this.getCurrentBranch(),a=new Date().toISOString();for(let c of r){let l;switch(c.status){case"A":l="added";break;case"M":l="modified";break;case"D":l="deleted";break;case"R":l="renamed";break;default:continue}let g={id:qe(),filePath:c.filePath,changeType:l,timestamp:a,source:"git-status",diff:this.config.enableFileHashing?n:void 0,commitHash:s,branch:i,checksum:this.config.enableFileHashing?await this.generateFileChecksum(c.filePath):void 0};e.push(g),this.gitStatusCache.set(c.filePath,c.status)}}catch(t){console.error("\u68C0\u6D4BGit\u53D8\u66F4\u65F6\u51FA\u9519:",t)}return e}parseGitStatus(e){let t=[];try{let n=Cs("git status --porcelain",{encoding:"utf-8"});for(let r of n.trim().split(`
|
|
1255
|
+
`))if(r.length>=3){let s=r.substring(0,2).trim(),i=r.substring(3).trim();t.push({filePath:i,status:s})}}catch(n){console.warn("\u89E3\u6790Git\u72B6\u6001\u5931\u8D25:",n)}return t}getCurrentGitHash(){try{return Cs("git rev-parse HEAD",{encoding:"utf-8"}).trim()}catch{return"unknown"}}getCurrentBranch(){try{return Cs("git rev-parse --abbrev-ref HEAD",{encoding:"utf-8"}).trim()}catch{return"unknown"}}async detectFilesystemChanges(){return[]}generateChangeSummary(e){let t={totalFiles:e.length,addedFiles:0,modifiedFiles:0,deletedFiles:0,renamedFiles:0,totalSize:0};for(let n of e){switch(n.changeType){case"added":t.addedFiles++;break;case"modified":t.modifiedFiles++;break;case"deleted":t.deletedFiles++;break;case"renamed":t.renamedFiles++;break}n.size&&(t.totalSize+=n.size)}return t}async generateFileChecksum(e){try{return`sha256:${e}:${Date.now()}`}catch(t){return console.error("\u751F\u6210\u6587\u4EF6\u6821\u9A8C\u548C\u65F6\u51FA\u9519:",t),""}}triggerChangeCallbacks(e){for(let t of this.changeCallbacks)try{t(e)}catch(n){console.error("\u6267\u884C\u53D8\u66F4\u56DE\u8C03\u65F6\u51FA\u9519:",n)}}trackSessionFileChange(e,t,n){if(!this.config.trackSessionChanges)return;let r=this.sessionChanges.get(e),s=new Date().toISOString();if(r){let i=[...r.changes];for(let a of n){let c=i.findIndex(l=>l.filePath===a.filePath&&l.changeType===a.changeType);c>=0?i[c]=a:i.push(a)}r.changes=i,r.updatedAt=s,r.totalFiles=i.length,r.totalSize=i.reduce((a,c)=>a+(c.size||0),0)}else this.sessionChanges.set(e,{sessionId:e,taskId:t,changes:[...n],committed:!1,createdAt:s,updatedAt:s,totalFiles:n.length,totalSize:n.reduce((i,a)=>i+(a.size||0),0)})}getSessionFileChanges(e){return this.sessionChanges.get(e)}getAllSessionFileChanges(){return new Map(this.sessionChanges)}getCurrentSessionFileChanges(){let e,t="";for(let n of this.sessionChanges.values())n.updatedAt>t&&(t=n.updatedAt,e=n);return e}async handleGitCommit(e){if(!this.config.enableGitIntegration)return null;try{let t={hash:e.hash||this.getCurrentGitHash(),message:e.commitMessage,author:e.author||"Unknown",timestamp:new Date().toISOString(),branch:e.branch||this.getCurrentBranch(),files:[]};return this.commitHistory.unshift(t),this.commitHistory.length>this.config.maxCommitHistory&&(this.commitHistory=this.commitHistory.slice(0,this.config.maxCommitHistory)),this.markSessionChangesAsCommitted(t),t}catch(t){return console.error("\u5904\u7406Git\u63D0\u4EA4\u4E8B\u4EF6\u65F6\u51FA\u9519:",t),null}}markSessionChangesAsCommitted(e){for(let t of this.sessionChanges.values())!t.committed&&t.updatedAt>e.timestamp&&(t.committed=!0)}onChange(e){this.changeCallbacks.push(e)}removeChangeCallback(e){let t=this.changeCallbacks.indexOf(e);t>=0&&this.changeCallbacks.splice(t,1)}startWatching(){this.isWatching||(this.isWatching=!0,this.config.enableGitIntegration&&(this.gitStatusTimer=setInterval(async()=>{try{await this.detectFileChanges()}catch(e){console.error("\u76D1\u63A7Git\u72B6\u6001\u65F6\u51FA\u9519:",e)}},this.config.gitStatusCheckInterval)))}stopWatching(){this.isWatching&&(this.isWatching=!1,this.gitStatusTimer&&(clearInterval(this.gitStatusTimer),this.gitStatusTimer=void 0))}getCommitHistory(){return[...this.commitHistory]}cleanup(e=30){let t=new Date;t.setDate(t.getDate()-e);let n=t.toISOString();for(let[r,s]of this.sessionChanges.entries())s.updatedAt<n&&s.committed&&this.sessionChanges.delete(r);this.commitHistory=this.commitHistory.filter(r=>r.timestamp>n)}getConfig(){return{...this.config}}updateConfig(e){this.config={...this.config,...e}}generateChangeSummaryText(e="text"){let t=[];for(let s of this.sessionChanges.values())t.push(...s.changes);if(e==="json")return JSON.stringify(this.generateChangeSummary(t),null,2);let n=this.generateChangeSummary(t),r=`\u{1F4CA} \u6587\u4EF6\u53D8\u52A8\u6458\u8981
|
|
1256
|
+
|
|
1257
|
+
`;return r+=`\u{1F4C1} \u603B\u6587\u4EF6\u6570: ${n.totalFiles}
|
|
1258
|
+
`,r+=`\u2795 \u65B0\u589E\u6587\u4EF6: ${n.addedFiles}
|
|
1259
|
+
`,r+=`\u270F\uFE0F \u4FEE\u6539\u6587\u4EF6: ${n.modifiedFiles}
|
|
1260
|
+
`,r+=`\u{1F5D1}\uFE0F \u5220\u9664\u6587\u4EF6: ${n.deletedFiles}
|
|
1261
|
+
`,r+=`\u{1F504} \u91CD\u547D\u540D\u6587\u4EF6: ${n.renamedFiles}
|
|
1262
|
+
`,r+=`\u{1F4E6} \u603B\u5927\u5C0F: ${(n.totalSize/1024).toFixed(2)} KB
|
|
1263
|
+
`,r+=`
|
|
1264
|
+
\u{1F550} \u751F\u6210\u65F6\u95F4: ${new Date().toLocaleString()}`,r}},_t=null});function ze(o,e){if(!Vr){let t=o||new We;Vr=new Hr(t,e)}return Vr}function ja(o,e){return new Hr(o,e)}function _a(){Vr=null}var Uu,Hr,Vr,Wn=S(()=>{ot();Uu={promptIntegration:{enabled:!0,maxSummaryLength:500,includeFileList:!0,includeChangeDetails:!1,priority:"low"},anchorIntegration:{enabled:!0,anchorPrefix:"workspace-change-",includeAllChanges:!1},toolIntegration:{enabled:!0,maxResultsPerQuery:20},workspaceAuxiliary:{enabled:!0,role:"helper",maxContextRatio:.2}},Hr=class{fileChangeTracker;config;anchors=new Map;constructor(e,t){this.fileChangeTracker=e,this.config={...Uu,...t}}generatePromptIntegrationContent(){if(!this.config.promptIntegration.enabled)return"";try{let e=this.fileChangeTracker.getCurrentSessionFileChanges();if(!e||e.changes.length===0)return"";let t=`\u{1F4A1} \u5DE5\u4F5C\u533A\u6587\u4EF6\u53D8\u66F4\u4FE1\u606F\uFF08\u4EC5\u4F5C\u8F85\u52A9\u53C2\u8003\uFF09\uFF1A
|
|
1265
|
+
|
|
1266
|
+
`,n=this.config.promptIntegration.maxSummaryLength-t.length,s=this.fileChangeTracker.generateChangeSummaryText("text").split(`
|
|
1267
|
+
`),i="";for(let a of s)if(i.length+a.length<n)i+=a+`
|
|
1268
|
+
`;else break;if(t+=i+`
|
|
1269
|
+
`,n=this.config.promptIntegration.maxSummaryLength-t.length,this.config.promptIntegration.includeFileList&&n>50){t+=`\u{1F4CB} \u53D8\u66F4\u6587\u4EF6\u5217\u8868\uFF1A
|
|
1270
|
+
`;let a=e.changes.map(c=>` - ${c.changeType==="added"?"\u2795":c.changeType==="modified"?"\u270F\uFE0F":c.changeType==="deleted"?"\u{1F5D1}\uFE0F":"\u{1F504}"} ${c.filePath}`);for(let c of a)if(t.length+c.length<this.config.promptIntegration.maxSummaryLength)t+=c+`
|
|
1271
|
+
`;else{t+=` ...\uFF08\u66F4\u591A\u6587\u4EF6\u53D8\u66F4\u8BF7\u4F7F\u7528\u5DE5\u5177\u67E5\u8BE2\uFF09
|
|
1272
|
+
`;break}t+=`
|
|
1273
|
+
`}return this.config.promptIntegration.includeChangeDetails&&n>100&&(t+=`\u{1F4DD} \u53D8\u66F4\u8BE6\u60C5\u9884\u89C8\uFF1A
|
|
1274
|
+
`),t+=`\u26A0\uFE0F \u4EE5\u4E0A\u5DE5\u4F5C\u533A\u4FE1\u606F\u4EC5\u4F5C\u4E3A\u8F85\u52A9\u53C2\u8003\uFF0C\u60A8\u5E94\u4E13\u6CE8\u4E8E\u89E3\u51B3\u5F53\u524D\u4E3B\u8981\u4EFB\u52A1\u3002
|
|
1275
|
+
`,t}catch(e){return console.error("\u751F\u6210\u63D0\u793A\u8BCD\u96C6\u6210\u5185\u5BB9\u65F6\u51FA\u9519:",e),""}}generateChangeAnchors(){if(!this.config.anchorIntegration.enabled)return new Map;try{let e=new Map,t=this.fileChangeTracker.getCurrentSessionFileChanges();if(t&&t.changes.length>0)for(let n of t.changes){let r=`${this.config.anchorIntegration.anchorPrefix}${n.id}`;e.set(r,n.filePath),this.anchors.set(r,n.id)}return e}catch(e){return console.error("\u751F\u6210\u53D8\u66F4\u951A\u70B9\u65F6\u51FA\u9519:",e),new Map}}getChangeByAnchor(e){let t=this.anchors.get(e);if(!t)return;let n=this.fileChangeTracker.getCurrentSessionFileChanges();if(n)return n.changes.find(r=>r.id===t)}async searchFileChanges(e){if(!this.config.toolIntegration.enabled)return[];try{let t=this.fileChangeTracker.getCurrentSessionFileChanges();if(!t||t.changes.length===0)return[];let n=[...t.changes];e.filter&&(n=this.applyFilter(n,e.filter)),e.sortBy&&(n=this.applySort(n,e.sortBy,e.sortOrder||"desc"));let r=e.limit||this.config.toolIntegration.maxResultsPerQuery,s=e.offset||0;return n=n.slice(s,s+r),e.includeContent,n}catch(t){return console.error("\u641C\u7D22\u6587\u4EF6\u53D8\u66F4\u65F6\u51FA\u9519:",t),[]}}getChangeSummary(){try{let e=this.fileChangeTracker.getCurrentSessionFileChanges();return!e||e.changes.length===0?{totalFiles:0,addedFiles:0,modifiedFiles:0,deletedFiles:0,renamedFiles:0,totalSize:0}:{totalFiles:e.changes.length,addedFiles:e.changes.filter(n=>n.changeType==="added").length,modifiedFiles:e.changes.filter(n=>n.changeType==="modified").length,deletedFiles:e.changes.filter(n=>n.changeType==="deleted").length,renamedFiles:e.changes.filter(n=>n.changeType==="renamed").length,totalSize:e.changes.reduce((n,r)=>n+(r.size||0),0)}}catch(e){return console.error("\u83B7\u53D6\u53D8\u66F4\u6458\u8981\u65F6\u51FA\u9519:",e),{totalFiles:0,addedFiles:0,modifiedFiles:0,deletedFiles:0,renamedFiles:0,totalSize:0}}}applyFilter(e,t){return e.filter(n=>{if(t.changeTypes&&t.changeTypes.length>0&&!t.changeTypes.includes(n.changeType)||t.filePatterns&&t.filePatterns.length>0&&!t.filePatterns.some(s=>new RegExp(s.replace(/\*/g,".*").replace(/\?/g,".")).test(n.filePath)))return!1;if(t.dateRange){let r=new Date(n.timestamp),s=new Date(t.dateRange.start),i=new Date(t.dateRange.end);if(r<s||r>i)return!1}return!(t.author&&n.author!==t.author||t.branch&&n.branch!==t.branch||t.minFileSize&&(n.size||0)<t.minFileSize||t.maxFileSize&&(n.size||0)>t.maxFileSize||t.sessionId&&n.sessionId!==t.sessionId||t.taskId&&n.taskId!==t.taskId)})}applySort(e,t,n){return[...e].sort((r,s)=>{let i,a;switch(t){case"timestamp":i=new Date(r.timestamp).getTime(),a=new Date(s.timestamp).getTime();break;case"filePath":i=r.filePath,a=s.filePath;break;case"size":i=r.size||0,a=s.size||0;break;case"type":i=r.changeType,a=s.changeType;break;default:i=new Date(r.timestamp).getTime(),a=new Date(s.timestamp).getTime()}return i<a?n==="asc"?-1:1:i>a?n==="asc"?1:-1:0})}updateConfig(e){this.config={...this.config,...e}}getConfig(){return{...this.config}}shouldIncludeWorkspaceContext(e){return!!this.config.workspaceAuxiliary.enabled}getMaxWorkspaceContextLength(e){return this.config.workspaceAuxiliary.enabled?Math.floor(e*this.config.workspaceAuxiliary.maxContextRatio):0}},Vr=null});var xs={};j(xs,{AnchorInjector:()=>st,createAnchorInjector:()=>Na});function Na(o,e){return new st(o,e)}var st,zn=S(()=>{gs();ps();fs();Y();Wn();ot();st=class{anchorManager;semanticAnalyzer;contextConfig;constructor(e,t){this.anchorManager=new Fn(e),this.semanticAnalyzer=new jn(t),this.contextConfig=Rr()}async injectAnchors(e){let{taskDescription:t,iterations:n,messages:r,lastSemanticCheckIteration:s,session:i,logWarning:a}=e,c=s,l=[...r];if(this.contextConfig.enableAnchorSystem)try{let g=ce(),p=ze(g);await g.detectFileChanges();let u=p.generateChangeAnchors();if(u.size>0){let d={role:"system",content:`\u{1F4A1} \u5DE5\u4F5C\u533A\u6587\u4EF6\u53D8\u66F4\u951A\u70B9\uFF08\u4EC5\u4F5C\u8F85\u52A9\u53C2\u8003\uFF09\uFF1A
|
|
1276
|
+
${Array.from(u.entries()).map(([w,h])=>`${w}: ${h}`).join(`
|
|
1277
|
+
`)}
|
|
1101
1278
|
|
|
1102
|
-
\u{1F3AF} \u91CD\u8981\u63D0\u9192\uFF1A\u8BF7\u91CD\u65B0\u5F00\u59CB\u5206\u6790\u539F\u59CB\u95EE\u9898\uFF0C\u5FFD\u7565\u4E4B\u524D\u7684\u8FB9\u7F18\u63A2\u7D22\u3002`),o}}});var Oo=C(()=>{Ni();Do();jo()});var Ui={};U(Ui,{GradleBuildParser:()=>fn,JavaDependencyAnalyzer:()=>lr,MavenPomParser:()=>cr,analyzeJavaProject:()=>Fo});import{readFileSync as ir,existsSync as ar}from"fs";import{resolve as Ro}from"path";import{parseString as _l}from"xml2js";async function Fo(r=process.cwd()){let e=Ro(r,"pom.xml"),t=Ro(r,"build.gradle"),n=Ro(r,"build.gradle.kts"),o=null;try{if(ar(e)){let i=ir(e,"utf-8");o=await new cr(i,e).parse()}else if(ar(t)){let i=ir(t,"utf-8");o=new fn(i,t).parse()}else if(ar(n)){let i=ir(n,"utf-8");o=new fn(i,n).parse()}if(!o)return null;let s={project:o,conflicts:[],outdated:[],unused:[],recommendations:[]};return s.recommendations=lr.generateRecommendations(s),s}catch(s){return console.error("Error analyzing Java project:",s),null}}var cr,fn,lr,_o=C(()=>{cr=class{content;filePath;constructor(e,t){this.content=e,this.filePath=t}async parse(){try{return new Promise((e,t)=>{_l(this.content,{explicitArray:!1},(n,o)=>{if(n){t(n);return}try{let{project:s}=o;if(!s){e(null);return}let i={name:s.artifactId||s.name||"unknown",version:s.version||"0.0.0",description:s.description||"",groupId:s.groupId||s.parent?.groupId,artifactId:s.artifactId,packaging:s.packaging||"jar",javaVersion:this.extractJavaVersion(s),buildToolVersion:this.extractMavenVersion(),parent:s.parent?{groupId:s.parent.groupId,artifactId:s.parent.artifactId,version:s.parent.version}:void 0,dependencies:this.extractDependencies(s.dependencies?.dependency),dependencyManagement:this.extractDependencies(s.dependencyManagement?.dependencies?.dependency),properties:this.extractProperties(s.properties),modules:s.modules?.module?Array.isArray(s.modules.module)?s.modules.module:[s.modules.module]:void 0,repositories:this.extractRepositories(s.repositories?.repository)};e(i)}catch(s){t(s)}})})}catch(e){return console.error("Error parsing POM XML:",e),null}}extractJavaVersion(e){return e.properties?.["java.version"]||e.properties?.["maven.compiler.source"]||e.properties?.["maven.compiler.target"]||e.build?.plugins?.plugin?.find(n=>n.artifactId==="maven-compiler-plugin")?.configuration?.source}extractMavenVersion(){let e=this.content.match(/modelVersion>([^<]+)</);return e?e[1]:void 0}extractDependencies(e){return e?(Array.isArray(e)?e:[e]).map(n=>({groupId:n.groupId,artifactId:n.artifactId,version:n.version||"unknown",scope:n.scope||"compile",type:n.type||"jar",classifier:n.classifier,optional:n.optional==="true",exclusions:n.exclusions?.exclusion?(Array.isArray(n.exclusions.exclusion)?n.exclusions.exclusion:[n.exclusions.exclusion]).map(o=>({groupId:o.groupId,artifactId:o.artifactId})):void 0})):[]}extractProperties(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{n!=="$"&&(t[n]=e[n])}),t}extractRepositories(e){return e?(Array.isArray(e)?e:[e]).map(n=>n.url).filter(Boolean):[]}},fn=class{content;filePath;constructor(e,t){this.content=e,this.filePath=t}parse(){try{let e=this.filePath.endsWith(".kts");return{name:this.extractProjectName(),version:this.extractVersion(),description:this.extractDescription(),groupId:this.extractGroup(),artifactId:this.extractProjectName(),javaVersion:this.extractJavaVersion(),buildToolVersion:this.extractGradleVersion(),dependencies:this.extractDependencies(e),dependencyManagement:[],properties:this.extractProperties(e)}}catch(e){return console.error("Error parsing Gradle build file:",e),null}}extractProjectName(){let e=this.content.match(/rootProject\.name\s*=\s*['"]([^'"]+)['"]/)||this.content.match(/project\(['"]([^'"]+)['"]\)/)||this.content.match(/name\s*=\s*['"]([^'"]+)['"]/);if(e)return e[1];let t=this.filePath.split(/[/\\]/);return t[t.length-2]||"unknown"}extractVersion(){let e=this.content.match(/version\s*=\s*['"]([^'"]+)['"]/);return e?e[1]:"0.0.0"}extractDescription(){let e=this.content.match(/description\s*=\s*['"]([^'"]+)['"]/);return e?e[1]:""}extractGroup(){let e=this.content.match(/group\s*=\s*['"]([^'"]+)['"]/);return e?e[1]:""}extractJavaVersion(){let e=this.content.match(/sourceCompatibility\s*=\s*['"]?([^'"\s]+)['"]?/)||this.content.match(/targetCompatibility\s*=\s*['"]?([^'"\s]+)['"]?/)||this.content.match(/java\.toolchain\.languageVersion\s*=\s*JavaLanguageVersion\.of\((\d+)\)/);return e?e[1]:void 0}extractGradleVersion(){let e=this.filePath.replace(/build\.gradle(\.kts)?$/,"gradle/wrapper/gradle-wrapper.properties");if(ar(e))try{let n=ir(e,"utf-8").match(/distributionUrl=.*gradle-(\d+\.\d+(?:\.\d+)?)-/);if(n)return n[1]}catch{}}extractDependencies(e){let t=[];return[/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*['"]([^:'"]+):([^:'"]+):([^:'"]+)['"]/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*['"]([^:'"]+):([^:'"]+)['"]/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*group\s*:\s*['"]([^'"]+)['"],\s*name\s*:\s*['"]([^'"]+)['"],\s*version\s*:\s*['"]([^'"]+)['"]\s*\)/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*group\s*:\s*['"]([^'"]+)['"],\s*name\s*:\s*['"]([^'"]+)['"]\s*\)/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*["']([^"']+):([^"']+):([^"']+)["']\s*\)/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*["']([^"']+):([^"']+)["']\s*\)/g].forEach(o=>{let s;for(;(s=o.exec(this.content))!==null;){let i,a,c,l;if(s.length===5)[,i,a,c,l]=s;else if(s.length===4)[,i,a,c]=s,l="managed";else continue;t.push({groupId:a,artifactId:c,version:l,scope:i.toLowerCase(),type:"jar"})}}),t}extractProperties(e){let t={},n=e?/val\s+(\w+)\s*=\s*['"]([^'"]+)['"]/g:/(\w+)\s*=\s*['"]([^'"]+)['"]/g,o;for(;(o=n.exec(this.content))!==null;)t[o[1]]=o[2];return t}},lr=class{static analyzeConflicts(e){let t=new Map,n=new Map;e.forEach(s=>{s.dependencies.forEach(i=>{let a=`${i.groupId}:${i.artifactId}`;t.has(a)||(t.set(a,new Set),n.set(a,[])),t.get(a).add(i.version),n.get(a).push(`${s.name} (${i.scope})`)})});let o=[];return t.forEach((s,i)=>{if(s.size>1){let[a,c]=i.split(":"),l=Array.from(s);o.push({groupId:a,artifactId:c,versions:l,locations:n.get(i)||[],severity:this.calculateConflictSeverity(l)})}}),o}static calculateConflictSeverity(e){let t=e.map(o=>o.split(".")[0]).filter(o=>/^\d+$/.test(o));return new Set(t).size>1?"high":e.length>2?"medium":"low"}static generateRecommendations(e){let t=[];return e.conflicts.length>0&&t.push(`\u53D1\u73B0 ${e.conflicts.length} \u4E2A\u4F9D\u8D56\u51B2\u7A81\uFF0C\u5EFA\u8BAE\u7EDF\u4E00\u7248\u672C\u7BA1\u7406`),e.outdated.length>0&&t.push(`${e.outdated.length} \u4E2A\u4F9D\u8D56\u5B58\u5728\u66F4\u65B0\u7248\u672C`),e.unused.length>0&&t.push(`${e.unused.length} \u4E2A\u4F9D\u8D56\u53EF\u80FD\u672A\u88AB\u4F7F\u7528\uFF0C\u5EFA\u8BAE\u68C0\u67E5`),e.project.dependencies.some(o=>o.groupId==="org.springframework.boot")&&t.push("\u9879\u76EE\u4F7F\u7528Spring Boot\uFF0C\u5EFA\u8BAE\u4F7F\u7528Spring Dependency Management\u63D2\u4EF6"),t}}});import{existsSync as Vi,readFileSync as Nl}from"fs";import{resolve as Wi,dirname as Ul}from"path";function Ji(r=process.cwd()){let e={name:"unknown",version:"0.0.0",description:"",languages:["Unknown"],primaryLanguage:"Unknown",configFiles:[]},t=new Set,n=[],o="Unknown",s,i=null;for(let[a,c]of Object.entries(Hi))for(let l of c.files){if(l.includes("*"))continue;let p=Wi(r,l);if(Vi(p)&&(t.add(c.language),n.push(l),o==="Unknown")){o=c.language,s=a;try{let u=Nl(p,"utf-8"),g=c.parser(u,p);g instanceof Promise?console.warn(`Async parser not supported in sync readProjectConfig: ${a}`):i=g}catch(u){console.warn(`Error parsing ${l}: ${u instanceof Error?u.message:"Unknown error"}`)}}}return t.size===0?e:{...e,...i||{},languages:Array.from(t),primaryLanguage:o,buildTool:s,configFiles:n}}function Vl(r,e){try{let t=JSON.parse(r);return{name:t.name||"unknown",version:t.version||"0.0.0",description:t.description||"",dependencies:t.dependencies||{},devDependencies:t.devDependencies||{},entryPoints:[t.main,...typeof t.bin=="string"?[t.bin]:Object.values(t.bin||{})].filter(Boolean)}}catch{return null}}function Wl(r,e){try{let t=r.match(/name\s*=\s*['"]([^'"]+)['"]/),n=r.match(/version\s*=\s*['"]([^'"]+)['"]/),o=r.match(/description\s*=\s*['"]([^'"]+)['"]/);return{name:t?t[1]:"unknown",version:n?n[1]:"0.0.0",description:o?o[1]:""}}catch{return null}}function Hl(r,e){try{let t=r.match(/name\s*=\s*"([^"]+)"/),n=r.match(/version\s*=\s*"([^"]+)"/),o=r.match(/description\s*=\s*"([^"]+)"/);return{name:t?t[1]:"unknown",version:n?n[1]:"0.0.0",description:o?o[1]:""}}catch{return null}}function Jl(r,e){try{return{name:e.split(/[/\\]/).slice(-2,-1)[0]||"unknown",version:"0.0.0",description:""}}catch{return null}}function Gl(r,e){try{let t=r.match(/module\s+([^\s]+)/),n=r.match(/go\s+([^\s]+)/),o={},s=/require\s+([^\s]+)\s+([^\s]+)/g,i;for(;(i=s.exec(r))!==null;)o[i[1]]=i[2];return{name:t&&t[1].split("/").pop()||"unknown",version:n?n[1]:"0.0.0",description:"",dependencies:o}}catch{return null}}function zl(r,e){try{let t=r.match(/name\s*=\s*"([^"]+)"/),n=r.match(/version\s*=\s*"([^"]+)"/),o=r.match(/description\s*=\s*"([^"]+)"/);return{name:t?t[1]:"unknown",version:n?n[1]:"0.0.0",description:o?o[1]:""}}catch{return null}}function ql(r,e){try{return{name:e.split(/[/\\]/).slice(-2,-1)[0]||"unknown",version:"0.0.0",description:""}}catch{return null}}function Bl(r,e){try{let t=JSON.parse(r);return{name:t.name||"unknown",version:t.version||"0.0.0",description:t.description||"",dependencies:t.require||{},devDependencies:t["require-dev"]||{}}}catch{return null}}function Yl(r,e){try{let n=(e.split(/[/\\]/).pop()||"unknown").replace(/\.(cs|vb|fs)proj$/,""),o=r.match(/<Version>(.*?)<\/Version>/),s=r.match(/<Description>(.*?)<\/Description>/);return{name:n,version:o?o[1]:"0.0.0",description:s?s[1]:""}}catch{return null}}function Gi(r){let e=r.map(t=>`${t.groupId}:${t.artifactId}`);return e.some(t=>t.includes("spring-boot"))?"Spring Boot":e.some(t=>t.includes("spring"))?"Spring Framework":e.some(t=>t.includes("jakarta")||t.includes("javax"))?"Jakarta EE":e.some(t=>t.includes("hibernate"))?"Hibernate":e.some(t=>t.includes("mybatis"))?"MyBatis":e.some(t=>t.includes("struts"))?"Struts":"Java Standard"}async function Kl(r,e){try{let t=await Fo(Ul(e));if(!t)return null;let n=t.project,o={};n.dependencies.forEach(i=>{o[`${i.groupId}:${i.artifactId}`]=i.version});let s=Gi(n.dependencies);return{name:n.name,version:n.version,description:n.description||"",dependencies:o,languageExtensionInfo:{javaDetails:n,framework:s,javaVersion:n.javaVersion,buildToolVersion:n.buildToolVersion||"Maven"},configFiles:["pom.xml"]}}catch(t){return console.error("Error parsing POM XML with enhanced parser:",t),null}}async function Xl(r,e){try{let t=await Promise.resolve().then(()=>(_o(),Ui)),o=new t.GradleBuildParser(r,e).parse();if(!o)return null;let s={};o.dependencies.forEach(a=>{s[`${a.groupId}:${a.artifactId}`]=a.version});let i=Gi(o.dependencies);return{name:o.name,version:o.version,description:o.description||"",dependencies:s,languageExtensionInfo:{javaDetails:o,framework:i,javaVersion:o.javaVersion,buildToolVersion:o.buildToolVersion||"Gradle"},configFiles:[e.split("/").pop()||"build.gradle"]}}catch(t){return console.error("Error parsing Gradle build file with enhanced parser:",t),null}}function zi(r=process.cwd()){let e=[];for(let[t,n]of Object.entries(Hi))for(let o of n.files){if(o.includes("*"))continue;let s=Wi(r,o);if(Vi(s)){e.push(t);break}}return e}var Hi,qi=C(()=>{_o();Hi={nodejs:{files:["package.json"],language:"JavaScript/TypeScript",parser:Vl},"java-maven":{files:["pom.xml"],language:"Java",parser:Kl},"java-gradle":{files:["build.gradle","build.gradle.kts"],language:"Java",parser:async(r,e)=>await Xl(r,e)},"python-pip":{files:["setup.py","setup.cfg"],language:"Python",parser:Wl},"python-poetry":{files:["pyproject.toml"],language:"Python",parser:Hl},"python-pipenv":{files:["Pipfile"],language:"Python",parser:Jl},go:{files:["go.mod"],language:"Go",parser:Gl},rust:{files:["Cargo.toml"],language:"Rust",parser:zl},ruby:{files:["Gemfile"],language:"Ruby",parser:ql},php:{files:["composer.json"],language:"PHP",parser:Bl},dotnet:{files:["*.csproj","*.vbproj","*.fsproj"],language:"C#/.NET",parser:Yl}}});import{writeFileSync as Ql,existsSync as Zl,mkdirSync as eu}from"fs";import{resolve as Bi}from"path";function Yi(r,e=process.cwd()){let t=Bi(e,".nium","project");Zl(t)||eu(t,{recursive:!0});let o=Bi(t,"project.json"),s=JSON.stringify(r,null,2);Ql(o,s,"utf-8"),console.log(`\u2705 \u9879\u76EE\u4FE1\u606F\u5DF2\u4FDD\u5B58\u81F3: ${o}`)}function Ki(r){let e=r.reduce((t,n)=>t+n.count,0);return r.map(t=>({...t,percentage:e>0?(t.count/e*100).toFixed(1)+"%":"0%"}))}var Xi=C(()=>{sr()});import{createHash as tu}from"crypto";import{readFileSync as Qi,writeFileSync as nu,existsSync as ru,statSync as ou}from"fs";import{resolve as su}from"path";function iu(r){try{let e=Qi(r),t=tu("md5");return t.update(e),t.digest("hex")}catch(e){return console.warn(`\u26A0\uFE0F \u65E0\u6CD5\u8BA1\u7B97\u6587\u4EF6 MD5: ${r}`,e),""}}function au(r,e=process.cwd()){try{let t=su(e,r),n=ou(t),o=iu(t);return{path:r,size:n.size,md5:o,updatedAt:n.mtime.toISOString(),description:""}}catch(t){return console.warn(`\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u6587\u4EF6\u4FE1\u606F: ${r}`,t),null}}function cu(r){let e=new Map;if(!ru(r))return e;try{let n=Qi(r,"utf-8").trim().split(`
|
|
1103
|
-
`);
|
|
1279
|
+
\u26A0\uFE0F \u4EE5\u4E0A\u951A\u70B9\u4FE1\u606F\u4EC5\u4F5C\u4E3A\u8F85\u52A9\u53C2\u8003\uFF0C\u60A8\u5E94\u4E13\u6CE8\u4E8E\u89E3\u51B3\u5F53\u524D\u4E3B\u8981\u4EFB\u52A1\u3002`},y=l.findIndex(w=>w.role==="system");y!==-1&&l.splice(y+1,0,d),C(`\u5DF2\u6CE8\u5165 ${u.size} \u4E2A\u6587\u4EF6\u53D8\u66F4\u951A\u70B9`)}}catch(g){C(`\u751F\u6210\u6587\u4EF6\u53D8\u66F4\u951A\u70B9\u65F6\u51FA\u9519: ${g}`)}if(this.contextConfig.enableSemanticAnalysis&&n-c>=this.contextConfig.semanticCheckInterval)try{let g=l.map(u=>u.content).filter(Boolean).join(`
|
|
1280
|
+
`),p=await this.semanticAnalyzer.analyzeSemanticDrift(t||this.anchorManager.getOriginalQuestion(),g,n);if(C(`\u8BED\u4E49\u5206\u6790 - \u76F8\u4F3C\u5EA6: ${p.similarityScore.toFixed(2)}, \u504F\u79BB\u7EA7\u522B: ${p.driftLevel}`),p.driftLevel==="severe"||p.driftLevel==="moderate"&&p.similarityScore<this.contextConfig.similarityThreshold){let u=`\u26A0\uFE0F \u68C0\u6D4B\u5230${p.driftLevel==="severe"?"\u4E25\u91CD":"\u4E2D\u5EA6"}\u504F\u79BB\uFF0C\u6B63\u5728\u7EA0\u6B63...`;a?a(u,i):C(u);let m=`\u68C0\u6D4B\u5230${p.driftLevel}\u504F\u79BB\uFF1A${p.deviationFactors.join("; ")}`,d=await this.anchorManager.createAnchorMessage(n,p.similarityScore,p.driftLevel,m,g);C(`\u{1F3AF} \u6CE8\u5165\u504F\u79BB\u7EA0\u6B63\u951A\u70B9\uFF08\u8FED\u4EE3 ${n}\uFF0C\u504F\u79BB\u7EA7\u522B: ${p.driftLevel}\uFF0C\u4F18\u5148\u7EA7: ${d.metadata?.priority}}`),l.push(d)}c=n}catch(g){H(`\u8BED\u4E49\u5206\u6790\u5931\u8D25: ${g.message}`)}if(this.contextConfig.enableAnchorSystem&&n%this.contextConfig.anchorInjectionInterval===0)try{let g=l.map(u=>u.content).filter(Boolean).join(`
|
|
1281
|
+
`),p=await this.anchorManager.calculateSemanticSimilarity(g);if(await this.anchorManager.shouldInjectAnchor(n,p,g)){let u=await this.anchorManager.createAnchorMessage(n,p,void 0,void 0,g);C(`\u{1F3AF} \u6CE8\u5165\u4E0A\u4E0B\u6587\u951A\u70B9\uFF08\u8FED\u4EE3 ${n}\uFF0C\u76F8\u4F3C\u5EA6: ${p.toFixed(2)}\uFF0C\u4F18\u5148\u7EA7: ${u.metadata?.priority}}`),l.push(u)}}catch(g){H(`\u951A\u70B9\u6CE8\u5165\u5931\u8D25: ${g.message}`)}return{messages:l,lastSemanticCheckIteration:c}}}});var ws=S(()=>{La();gs();ps();zn()});var Ua={};j(Ua,{GradleBuildParser:()=>Vn,JavaDependencyAnalyzer:()=>qr,MavenPomParser:()=>Br,analyzeJavaProject:()=>bs});import{readFileSync as Jr,existsSync as Gr}from"fs";import{resolve as vs}from"path";import{parseString as Wu}from"xml2js";async function bs(o=process.cwd()){let e=vs(o,"pom.xml"),t=vs(o,"build.gradle"),n=vs(o,"build.gradle.kts"),r=null;try{if(Gr(e)){let i=Jr(e,"utf-8");r=await new Br(i,e).parse()}else if(Gr(t)){let i=Jr(t,"utf-8");r=new Vn(i,t).parse()}else if(Gr(n)){let i=Jr(n,"utf-8");r=new Vn(i,n).parse()}if(!r)return null;let s={project:r,conflicts:[],outdated:[],unused:[],recommendations:[]};return s.recommendations=qr.generateRecommendations(s),s}catch(s){return console.error("Error analyzing Java project:",s),null}}var Br,Vn,qr,Ts=S(()=>{Br=class{content;filePath;constructor(e,t){this.content=e,this.filePath=t}async parse(){try{return new Promise((e,t)=>{Wu(this.content,{explicitArray:!1},(n,r)=>{if(n){t(n);return}try{let{project:s}=r;if(!s){e(null);return}let i={name:s.artifactId||s.name||"unknown",version:s.version||"0.0.0",description:s.description||"",groupId:s.groupId||s.parent?.groupId,artifactId:s.artifactId,packaging:s.packaging||"jar",javaVersion:this.extractJavaVersion(s),buildToolVersion:this.extractMavenVersion(),parent:s.parent?{groupId:s.parent.groupId,artifactId:s.parent.artifactId,version:s.parent.version}:void 0,dependencies:this.extractDependencies(s.dependencies?.dependency),dependencyManagement:this.extractDependencies(s.dependencyManagement?.dependencies?.dependency),properties:this.extractProperties(s.properties),modules:s.modules?.module?Array.isArray(s.modules.module)?s.modules.module:[s.modules.module]:void 0,repositories:this.extractRepositories(s.repositories?.repository)};e(i)}catch(s){t(s)}})})}catch(e){return console.error("Error parsing POM XML:",e),null}}extractJavaVersion(e){return e.properties?.["java.version"]||e.properties?.["maven.compiler.source"]||e.properties?.["maven.compiler.target"]||e.build?.plugins?.plugin?.find(n=>n.artifactId==="maven-compiler-plugin")?.configuration?.source}extractMavenVersion(){let e=this.content.match(/modelVersion>([^<]+)</);return e?e[1]:void 0}extractDependencies(e){return e?(Array.isArray(e)?e:[e]).map(n=>({groupId:n.groupId,artifactId:n.artifactId,version:n.version||"unknown",scope:n.scope||"compile",type:n.type||"jar",classifier:n.classifier,optional:n.optional==="true",exclusions:n.exclusions?.exclusion?(Array.isArray(n.exclusions.exclusion)?n.exclusions.exclusion:[n.exclusions.exclusion]).map(r=>({groupId:r.groupId,artifactId:r.artifactId})):void 0})):[]}extractProperties(e){if(!e)return{};let t={};return Object.keys(e).forEach(n=>{n!=="$"&&(t[n]=e[n])}),t}extractRepositories(e){return e?(Array.isArray(e)?e:[e]).map(n=>n.url).filter(Boolean):[]}},Vn=class{content;filePath;constructor(e,t){this.content=e,this.filePath=t}parse(){try{let e=this.filePath.endsWith(".kts");return{name:this.extractProjectName(),version:this.extractVersion(),description:this.extractDescription(),groupId:this.extractGroup(),artifactId:this.extractProjectName(),javaVersion:this.extractJavaVersion(),buildToolVersion:this.extractGradleVersion(),dependencies:this.extractDependencies(e),dependencyManagement:[],properties:this.extractProperties(e)}}catch(e){return console.error("Error parsing Gradle build file:",e),null}}extractProjectName(){let e=this.content.match(/rootProject\.name\s*=\s*['"]([^'"]+)['"]/)||this.content.match(/project\(['"]([^'"]+)['"]\)/)||this.content.match(/name\s*=\s*['"]([^'"]+)['"]/);if(e)return e[1];let t=this.filePath.split(/[/\\]/);return t[t.length-2]||"unknown"}extractVersion(){let e=this.content.match(/version\s*=\s*['"]([^'"]+)['"]/);return e?e[1]:"0.0.0"}extractDescription(){let e=this.content.match(/description\s*=\s*['"]([^'"]+)['"]/);return e?e[1]:""}extractGroup(){let e=this.content.match(/group\s*=\s*['"]([^'"]+)['"]/);return e?e[1]:""}extractJavaVersion(){let e=this.content.match(/sourceCompatibility\s*=\s*['"]?([^'"\s]+)['"]?/)||this.content.match(/targetCompatibility\s*=\s*['"]?([^'"\s]+)['"]?/)||this.content.match(/java\.toolchain\.languageVersion\s*=\s*JavaLanguageVersion\.of\((\d+)\)/);return e?e[1]:void 0}extractGradleVersion(){let e=this.filePath.replace(/build\.gradle(\.kts)?$/,"gradle/wrapper/gradle-wrapper.properties");if(Gr(e))try{let n=Jr(e,"utf-8").match(/distributionUrl=.*gradle-(\d+\.\d+(?:\.\d+)?)-/);if(n)return n[1]}catch{}}extractDependencies(e){let t=[];return[/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*['"]([^:'"]+):([^:'"]+):([^:'"]+)['"]/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*['"]([^:'"]+):([^:'"]+)['"]/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*group\s*:\s*['"]([^'"]+)['"],\s*name\s*:\s*['"]([^'"]+)['"],\s*version\s*:\s*['"]([^'"]+)['"]\s*\)/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*group\s*:\s*['"]([^'"]+)['"],\s*name\s*:\s*['"]([^'"]+)['"]\s*\)/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*["']([^"']+):([^"']+):([^"']+)["']\s*\)/g,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation)\s*\(\s*["']([^"']+):([^"']+)["']\s*\)/g].forEach(r=>{let s;for(;(s=r.exec(this.content))!==null;){let i,a,c,l;if(s.length===5)[,i,a,c,l]=s;else if(s.length===4)[,i,a,c]=s,l="managed";else continue;t.push({groupId:a,artifactId:c,version:l,scope:i.toLowerCase(),type:"jar"})}}),t}extractProperties(e){let t={},n=e?/val\s+(\w+)\s*=\s*['"]([^'"]+)['"]/g:/(\w+)\s*=\s*['"]([^'"]+)['"]/g,r;for(;(r=n.exec(this.content))!==null;)t[r[1]]=r[2];return t}},qr=class{static analyzeConflicts(e){let t=new Map,n=new Map;e.forEach(s=>{s.dependencies.forEach(i=>{let a=`${i.groupId}:${i.artifactId}`;t.has(a)||(t.set(a,new Set),n.set(a,[])),t.get(a).add(i.version),n.get(a).push(`${s.name} (${i.scope})`)})});let r=[];return t.forEach((s,i)=>{if(s.size>1){let[a,c]=i.split(":"),l=Array.from(s);r.push({groupId:a,artifactId:c,versions:l,locations:n.get(i)||[],severity:this.calculateConflictSeverity(l)})}}),r}static calculateConflictSeverity(e){let t=e.map(r=>r.split(".")[0]).filter(r=>/^\d+$/.test(r));return new Set(t).size>1?"high":e.length>2?"medium":"low"}static generateRecommendations(e){let t=[];return e.conflicts.length>0&&t.push(`\u53D1\u73B0 ${e.conflicts.length} \u4E2A\u4F9D\u8D56\u51B2\u7A81\uFF0C\u5EFA\u8BAE\u7EDF\u4E00\u7248\u672C\u7BA1\u7406`),e.outdated.length>0&&t.push(`${e.outdated.length} \u4E2A\u4F9D\u8D56\u5B58\u5728\u66F4\u65B0\u7248\u672C`),e.unused.length>0&&t.push(`${e.unused.length} \u4E2A\u4F9D\u8D56\u53EF\u80FD\u672A\u88AB\u4F7F\u7528\uFF0C\u5EFA\u8BAE\u68C0\u67E5`),e.project.dependencies.some(r=>r.groupId==="org.springframework.boot")&&t.push("\u9879\u76EE\u4F7F\u7528Spring Boot\uFF0C\u5EFA\u8BAE\u4F7F\u7528Spring Dependency Management\u63D2\u4EF6"),t}}});import{existsSync as Wa,readFileSync as zu}from"fs";import{resolve as za,dirname as Vu}from"path";function Ha(o=process.cwd()){let e={name:"unknown",version:"0.0.0",description:"",languages:["Unknown"],primaryLanguage:"Unknown",configFiles:[]},t=new Set,n=[],r="Unknown",s,i=null;for(let[a,c]of Object.entries(Va))for(let l of c.files){if(l.includes("*"))continue;let g=za(o,l);if(Wa(g)&&(t.add(c.language),n.push(l),r==="Unknown")){r=c.language,s=a;try{let p=zu(g,"utf-8"),u=c.parser(p,g);u instanceof Promise?console.warn(`Async parser not supported in sync readProjectConfig: ${a}`):i=u}catch(p){console.warn(`Error parsing ${l}: ${p instanceof Error?p.message:"Unknown error"}`)}}}return t.size===0?e:{...e,...i||{},languages:Array.from(t),primaryLanguage:r,buildTool:s,configFiles:n}}function Hu(o,e){try{let t=JSON.parse(o);return{name:t.name||"unknown",version:t.version||"0.0.0",description:t.description||"",dependencies:t.dependencies||{},devDependencies:t.devDependencies||{},entryPoints:[t.main,...typeof t.bin=="string"?[t.bin]:Object.values(t.bin||{})].filter(Boolean)}}catch{return null}}function Ju(o,e){try{let t=o.match(/name\s*=\s*['"]([^'"]+)['"]/),n=o.match(/version\s*=\s*['"]([^'"]+)['"]/),r=o.match(/description\s*=\s*['"]([^'"]+)['"]/);return{name:t?t[1]:"unknown",version:n?n[1]:"0.0.0",description:r?r[1]:""}}catch{return null}}function Gu(o,e){try{let t=o.match(/name\s*=\s*"([^"]+)"/),n=o.match(/version\s*=\s*"([^"]+)"/),r=o.match(/description\s*=\s*"([^"]+)"/);return{name:t?t[1]:"unknown",version:n?n[1]:"0.0.0",description:r?r[1]:""}}catch{return null}}function Bu(o,e){try{return{name:e.split(/[/\\]/).slice(-2,-1)[0]||"unknown",version:"0.0.0",description:""}}catch{return null}}function qu(o,e){try{let t=o.match(/module\s+([^\s]+)/),n=o.match(/go\s+([^\s]+)/),r={},s=/require\s+([^\s]+)\s+([^\s]+)/g,i;for(;(i=s.exec(o))!==null;)r[i[1]]=i[2];return{name:t&&t[1].split("/").pop()||"unknown",version:n?n[1]:"0.0.0",description:"",dependencies:r}}catch{return null}}function Ku(o,e){try{let t=o.match(/name\s*=\s*"([^"]+)"/),n=o.match(/version\s*=\s*"([^"]+)"/),r=o.match(/description\s*=\s*"([^"]+)"/);return{name:t?t[1]:"unknown",version:n?n[1]:"0.0.0",description:r?r[1]:""}}catch{return null}}function Yu(o,e){try{return{name:e.split(/[/\\]/).slice(-2,-1)[0]||"unknown",version:"0.0.0",description:""}}catch{return null}}function Xu(o,e){try{let t=JSON.parse(o);return{name:t.name||"unknown",version:t.version||"0.0.0",description:t.description||"",dependencies:t.require||{},devDependencies:t["require-dev"]||{}}}catch{return null}}function Qu(o,e){try{let n=(e.split(/[/\\]/).pop()||"unknown").replace(/\.(cs|vb|fs)proj$/,""),r=o.match(/<Version>(.*?)<\/Version>/),s=o.match(/<Description>(.*?)<\/Description>/);return{name:n,version:r?r[1]:"0.0.0",description:s?s[1]:""}}catch{return null}}function Ja(o){let e=o.map(t=>`${t.groupId}:${t.artifactId}`);return e.some(t=>t.includes("spring-boot"))?"Spring Boot":e.some(t=>t.includes("spring"))?"Spring Framework":e.some(t=>t.includes("jakarta")||t.includes("javax"))?"Jakarta EE":e.some(t=>t.includes("hibernate"))?"Hibernate":e.some(t=>t.includes("mybatis"))?"MyBatis":e.some(t=>t.includes("struts"))?"Struts":"Java Standard"}async function Zu(o,e){try{let t=await bs(Vu(e));if(!t)return null;let n=t.project,r={};n.dependencies.forEach(i=>{r[`${i.groupId}:${i.artifactId}`]=i.version});let s=Ja(n.dependencies);return{name:n.name,version:n.version,description:n.description||"",dependencies:r,languageExtensionInfo:{javaDetails:n,framework:s,javaVersion:n.javaVersion,buildToolVersion:n.buildToolVersion||"Maven"},configFiles:["pom.xml"]}}catch(t){return console.error("Error parsing POM XML with enhanced parser:",t),null}}async function eg(o,e){try{let t=await Promise.resolve().then(()=>(Ts(),Ua)),r=new t.GradleBuildParser(o,e).parse();if(!r)return null;let s={};r.dependencies.forEach(a=>{s[`${a.groupId}:${a.artifactId}`]=a.version});let i=Ja(r.dependencies);return{name:r.name,version:r.version,description:r.description||"",dependencies:s,languageExtensionInfo:{javaDetails:r,framework:i,javaVersion:r.javaVersion,buildToolVersion:r.buildToolVersion||"Gradle"},configFiles:[e.split("/").pop()||"build.gradle"]}}catch(t){return console.error("Error parsing Gradle build file with enhanced parser:",t),null}}function Ga(o=process.cwd()){let e=[];for(let[t,n]of Object.entries(Va))for(let r of n.files){if(r.includes("*"))continue;let s=za(o,r);if(Wa(s)){e.push(t);break}}return e}var Va,Ba=S(()=>{Ts();Va={nodejs:{files:["package.json"],language:"JavaScript/TypeScript",parser:Hu},"java-maven":{files:["pom.xml"],language:"Java",parser:Zu},"java-gradle":{files:["build.gradle","build.gradle.kts"],language:"Java",parser:async(o,e)=>await eg(o,e)},"python-pip":{files:["setup.py","setup.cfg"],language:"Python",parser:Ju},"python-poetry":{files:["pyproject.toml"],language:"Python",parser:Gu},"python-pipenv":{files:["Pipfile"],language:"Python",parser:Bu},go:{files:["go.mod"],language:"Go",parser:qu},rust:{files:["Cargo.toml"],language:"Rust",parser:Ku},ruby:{files:["Gemfile"],language:"Ruby",parser:Yu},php:{files:["composer.json"],language:"PHP",parser:Xu},dotnet:{files:["*.csproj","*.vbproj","*.fsproj"],language:"C#/.NET",parser:Qu}}});import{writeFileSync as tg,existsSync as ng,mkdirSync as rg}from"fs";import{resolve as qa}from"path";function Ka(o,e=process.cwd()){let t=qa(e,".nium","project");ng(t)||rg(t,{recursive:!0});let r=qa(t,"project.json"),s=JSON.stringify(o,null,2);tg(r,s,"utf-8"),console.log(`\u2705 \u9879\u76EE\u4FE1\u606F\u5DF2\u4FDD\u5B58\u81F3: ${r}`)}function Ya(o){let e=o.reduce((t,n)=>t+n.count,0);return o.map(t=>({...t,percentage:e>0?(t.count/e*100).toFixed(1)+"%":"0%"}))}var Xa=S(()=>{Lr()});import{createHash as og}from"crypto";import{readFileSync as Qa,writeFileSync as sg,existsSync as ig,statSync as ag}from"fs";import{resolve as cg}from"path";function lg(o){try{let e=Qa(o),t=og("md5");return t.update(e),t.digest("hex")}catch(e){return console.warn(`\u26A0\uFE0F \u65E0\u6CD5\u8BA1\u7B97\u6587\u4EF6 MD5: ${o}`,e),""}}function ug(o,e=process.cwd()){try{let t=cg(e,o),n=ag(t),r=lg(t);return{path:o,size:n.size,md5:r,updatedAt:n.mtime.toISOString(),description:""}}catch(t){return console.warn(`\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u6587\u4EF6\u4FE1\u606F: ${o}`,t),null}}function gg(o){let e=new Map;if(!ig(o))return e;try{let n=Qa(o,"utf-8").trim().split(`
|
|
1282
|
+
`);for(let r of n)if(r.trim())try{let s=JSON.parse(r);e.set(s.path,s)}catch(s){console.warn(`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790 JSONL \u884C: ${r}`,s)}}catch(t){console.warn(`\u26A0\uFE0F \u8BFB\u53D6 JSONL \u6587\u4EF6\u5931\u8D25: ${o}`,t)}return e}function pg(o,e){try{let t=[],n=Array.from(o.entries()).sort((r,s)=>r[0].localeCompare(s[0]));for(let[,r]of n)t.push(JSON.stringify(r));sg(e,t.join(`
|
|
1104
1283
|
`)+`
|
|
1105
|
-
`,"utf-8")}catch(t){throw console.error(`\u274C \u5199\u5165 JSONL \u6587\u4EF6\u5931\u8D25: ${e}`,t),t}}function
|
|
1106
|
-
`)}var ta=C(()=>{});var H,ye=C(()=>{H=class{getCommonDirectoryDescriptions(){return{src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u6240\u6709\u4E3B\u8981\u7684\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",dist:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",components:"\u7EC4\u4EF6\u76EE\u5F55",pages:"\u9875\u9762\u76EE\u5F55",public:"\u516C\u5171\u8D44\u6E90\u76EE\u5F55",assets:"\u9759\u6001\u8D44\u6E90\u76EE\u5F55",utils:"\u5DE5\u5177\u51FD\u6570\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",services:"\u670D\u52A1\u5C42\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",controllers:"\u63A7\u5236\u5668\u76EE\u5F55",routes:"\u8DEF\u7531\u5B9A\u4E49\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",plugins:"\u63D2\u4EF6\u76EE\u5F55",hooks:"\u94A9\u5B50\u51FD\u6570\u76EE\u5F55",types:"\u7C7B\u578B\u5B9A\u4E49\u76EE\u5F55",interfaces:"\u63A5\u53E3\u5B9A\u4E49\u76EE\u5F55",schemas:"\u6570\u636E\u7ED3\u6784\u5B9A\u4E49\u76EE\u5F55"}}}});import{existsSync as No,readFileSync as na}from"fs";import{resolve as Uo}from"path";var ur,ra=C(()=>{ye();ur=class extends H{getLanguageName(){return"JavaScript/TypeScript"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u6240\u6709\u4E3B\u8981\u7684 JavaScript/TypeScript \u4EE3\u7801",lib:"\u7F16\u8BD1\u540E\u7684\u5E93\u6587\u4EF6\u76EE\u5F55",dist:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u6253\u5305\u540E\u7684\u751F\u4EA7\u4EE3\u7801",public:"\u516C\u5171\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u9759\u6001\u6587\u4EF6",assets:"\u9759\u6001\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u56FE\u7247\u3001\u6837\u5F0F\u7B49",components:"React/Vue \u7EC4\u4EF6\u76EE\u5F55",pages:"\u9875\u9762\u7EC4\u4EF6\u76EE\u5F55",hooks:"React \u94A9\u5B50\u51FD\u6570\u76EE\u5F55",context:"React \u4E0A\u4E0B\u6587\u76EE\u5F55",redux:"Redux \u72B6\u6001\u7BA1\u7406\u76EE\u5F55",store:"\u72B6\u6001\u7BA1\u7406\u76EE\u5F55",actions:"Redux \u52A8\u4F5C\u76EE\u5F55",reducers:"Redux \u5F52\u7EA6\u5668\u76EE\u5F55",slices:"Redux Toolkit \u5207\u7247\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",utils:"\u5DE5\u5177\u51FD\u6570\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",services:"API \u670D\u52A1\u76EE\u5F55",api:"API \u63A5\u53E3\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",types:"TypeScript \u7C7B\u578B\u5B9A\u4E49\u76EE\u5F55",interfaces:"TypeScript \u63A5\u53E3\u5B9A\u4E49\u76EE\u5F55",schemas:"\u6570\u636E\u7ED3\u6784\u5B9A\u4E49\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u6D4B\u8BD5\u7B49\u811A\u672C",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",__tests__:"Jest \u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55",spec:"Jasmine/Mocha \u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55"}}async detectVersions(e,t){let n={},o=Uo(e,"package.json");if(No(o))try{let s=na(o,"utf-8"),i=JSON.parse(s);i.engines&&(i.engines.node&&(n["Node.js"]=i.engines.node),i.engines.npm&&(n.npm=i.engines.npm),i.engines.yarn&&(n.yarn=i.engines.yarn),i.engines.pnpm&&(n.pnpm=i.engines.pnpm))}catch{}return n}findEntryPoints(e,t){let n=[],o=["index.js","index.ts","index.mjs","index.cjs","app.js","app.ts","main.js","main.ts","server.js","server.ts","src/index.js","src/index.ts","src/main.js","src/main.ts","src/app.js","src/app.ts","next.config.js","vite.config.js","webpack.config.js","rollup.config.js"],s=Uo(t,"package.json");if(No(s))try{let i=na(s,"utf-8"),a=JSON.parse(i);a.main&&n.push(a.main),a.bin&&(typeof a.bin=="string"?n.push(a.bin):n.push(...Object.values(a.bin)))}catch{}return o.forEach(i=>{e.includes(i)&&n.push(i)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={ESLint:[".eslintrc.js",".eslintrc.json",".eslintrc.yml",".eslintrc.yaml",".eslintrc"],Prettier:[".prettierrc",".prettierrc.json",".prettierrc.yml",".prettierrc.yaml",".prettierrc.js","prettier.config.js"],EditorConfig:[".editorconfig"],TypeScript:["tsconfig.json"],Flow:[".flowconfig"],Jest:["jest.config.js","jest.config.ts","jest.config.json"],Vitest:["vitest.config.js","vitest.config.ts"],Mocha:["mocha.opts",".mocharc.js"],Jasmine:["jasmine.json"]};for(let[o,s]of Object.entries(n))for(let i of s)if(No(Uo(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".js",".mjs",".cjs",".jsx",".ts",".tsx",".vue",".svelte",".astro"]}getCommonTestExtensions(){return[".test.js",".test.ts",".test.jsx",".test.tsx",".spec.js",".spec.ts",".spec.jsx",".spec.tsx"]}getCommonConfigFiles(){return["package.json","tsconfig.json","tsconfig.node.json","jsconfig.json",".eslintrc.js",".eslintrc.json",".prettierrc",".prettierrc.json",".editorconfig","vite.config.js","vite.config.ts","webpack.config.js","webpack.config.ts","rollup.config.js","rollup.config.ts","next.config.js","next.config.mjs","nuxt.config.js","nuxt.config.ts","astro.config.mjs","astro.config.ts"]}}});import{existsSync as gr,readFileSync as pr}from"fs";import{resolve as hn}from"path";var mr,oa=C(()=>{ye();mr=class extends H{getLanguageName(){return"Java"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u6839\u76EE\u5F55","src/main/java":"\u4E3B\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u751F\u4EA7\u4EE3\u7801","src/main/resources":"\u4E3B\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u914D\u7F6E\u6587\u4EF6\u548C\u9759\u6001\u8D44\u6E90","src/test/java":"\u6D4B\u8BD5\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5","src/test/resources":"\u6D4B\u8BD5\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u6D4B\u8BD5\u914D\u7F6E\u6587\u4EF6",target:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u7C7B\u6587\u4EF6\u548C\u6253\u5305\u4EA7\u7269",lib:"\u5916\u90E8\u4F9D\u8D56\u5E93\u76EE\u5F55",libs:"\u5916\u90E8\u4F9D\u8D56\u5E93\u76EE\u5F55",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55",gradle:"Gradle \u6784\u5EFA\u7CFB\u7EDF\u76EE\u5F55",maven:"Maven \u6784\u5EFA\u7CFB\u7EDF\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C"}}async detectVersions(e,t){let n={},o=hn(e,"pom.xml");if(gr(o))try{let a=pr(o,"utf-8"),c=a.match(/<java\.version>([^<]+)<\/java\.version>/)||a.match(/<maven\.compiler\.source>([^<]+)<\/maven\.compiler\.source>/);c&&(n.Java=c[1])}catch{}let s=hn(e,"build.gradle"),i=hn(e,"build.gradle.kts");if(gr(s))try{let a=pr(s,"utf-8"),c=a.match(/sourceCompatibility\s*=\s*['"]?([^'"\\s]+)['"]?/)||a.match(/targetCompatibility\s*=\s*['"]?([^'"\\s]+)['"]?/);c&&(n.Java=c[1])}catch{}else if(gr(i))try{let a=pr(i,"utf-8"),c=a.match(/sourceCompatibility\s*=\s*JavaVersion\.VERSION_(\d+_\d+)/)||a.match(/targetCompatibility\s*=\s*JavaVersion\.VERSION_(\d+_\d+)/);c&&(n.Java=c[1].replace("_","."))}catch{}return n}findEntryPoints(e,t){let n=[],o=["src/main/java/**/Main.java","src/main/java/**/Application.java","src/main/java/**/App.java","src/main/java/**/Bootstrap.java","src/main/java/**/Launcher.java"];return e.forEach(s=>{if(s.endsWith(".java"))try{pr(hn(t,s),"utf-8").includes("public static void main(String[] args)")&&n.push(s)}catch{}}),o.forEach(s=>{let i=new RegExp(s.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*"));e.forEach(a=>{i.test(a)&&n.push(a)})}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={Checkstyle:["checkstyle.xml","google_checks.xml","sun_checks.xml"],PMD:["pmd.xml",".pmd"],FindBugs:["findbugs.xml",".findbugs"],SpotBugs:["spotbugs.xml",".spotbugs"],SonarQube:["sonar-project.properties"],EditorConfig:[".editorconfig"],Maven:["pom.xml"],Gradle:["build.gradle","build.gradle.kts"]};for(let[o,s]of Object.entries(n))for(let i of s)if(gr(hn(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".java",".class",".jar",".war",".ear"]}getCommonTestExtensions(){return["Test.java","Tests.java"]}getCommonConfigFiles(){return["pom.xml","build.gradle","build.gradle.kts","settings.gradle","gradle.properties","checkstyle.xml","pmd.xml","spotbugs.xml","sonar-project.properties",".editorconfig"]}}});import{existsSync as yn,readFileSync as Sn}from"fs";import{resolve as xt}from"path";var dr,sa=C(()=>{ye();dr=class extends H{getLanguageName(){return"Python"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 Python \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",main:"\u4E3B\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",__pycache__:"Python \u7F16\u8BD1\u7F13\u5B58\u76EE\u5F55",venv:"\u865A\u62DF\u73AF\u5883\u76EE\u5F55",".venv":"\u865A\u62DF\u73AF\u5883\u76EE\u5F55",env:"\u73AF\u5883\u53D8\u91CF\u914D\u7F6E\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",data:"\u6570\u636E\u6587\u4EF6\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",dist:"\u6253\u5305\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u53D1\u5E03\u7684\u5305\u6587\u4EF6",requirements:"\u4F9D\u8D56\u7BA1\u7406\u76EE\u5F55"}}async detectVersions(e,t){let n={},o=xt(e,".python-version");if(yn(o))try{let a=Sn(o,"utf-8");n.Python=a.trim()}catch{}let s=xt(e,"pyproject.toml");if(yn(s))try{let c=Sn(s,"utf-8").match(/python\s*=\s*['"]([^'"]+)['"]/);c&&(n.Python=c[1])}catch{}let i=xt(e,"setup.py");if(yn(i))try{let c=Sn(i,"utf-8").match(/python_requires\s*=\s*['"]([^'"]+)['"]/);c&&(n.Python=c[1])}catch{}return n}findEntryPoints(e,t){let n=[];["main.py","__main__.py","app.py","run.py","manage.py","server.py","cli.py","setup.py","src/main.py","src/__main__.py","src/app.py"].forEach(i=>{e.includes(i)&&n.push(i)});let s=xt(t,"setup.py");if(yn(s))try{let a=Sn(s,"utf-8").match(/entry_points\s*=\s*\{[^}]+\}/s);if(a){let l=a[0].match(/console_scripts\s*:\s*\[([^\]]+)\]/s);if(l){let u=l[1].match(/([^=]+)\s*=\s*([^,]+)/g);u&&u.forEach(g=>{let[m,S]=g.split("=").map(f=>f.trim()),b=S.replace(/\./g,"/").replace(":","/")+".py";n.push(b)})}}}catch{}return[...new Set(n)]}detectCodeStandards(e){let t=[],n={Black:["pyproject.toml","setup.cfg"],Pylint:[".pylintrc","pylintrc","setup.cfg"],Flake8:[".flake8","flake8.cfg","setup.cfg"],Mypy:["mypy.ini",".mypy.ini","setup.cfg","pyproject.toml"],isort:[".isort.cfg","setup.cfg","pyproject.toml"],Bandit:[".bandit","bandit.yml"],Pytest:["pytest.ini","setup.cfg","conftest.py"],EditorConfig:[".editorconfig"]};for(let[o,s]of Object.entries(n))for(let i of s)if(yn(xt(e,i)))if(o==="Black")try{if(Sn(xt(e,i),"utf-8").includes("[tool.black]")){t.push(o);break}}catch{}else{t.push(o);break}return t}getCommonSourceExtensions(){return[".py",".pyc",".pyo",".pyd",".pyx",".pxd",".pxi"]}getCommonTestExtensions(){return[".test.py",".spec.py","_test.py","test_*.py","*_test.py"]}getCommonConfigFiles(){return["pyproject.toml","setup.py","setup.cfg","requirements.txt","requirements-dev.txt","Pipfile","Pipfile.lock","poetry.lock",".pylintrc",".flake8","mypy.ini",".isort.cfg","pytest.ini","conftest.py",".editorconfig"]}}});import{existsSync as Vo,readFileSync as Wo}from"fs";import{resolve as fr}from"path";var hr,ia=C(()=>{ye();hr=class extends H{getLanguageName(){return"Go"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF08\u4F20\u7EDF Go \u9879\u76EE\u7ED3\u6784\uFF09",cmd:"\u547D\u4EE4\u884C\u5DE5\u5177\u76EE\u5F55\uFF0C\u5305\u542B\u53EF\u6267\u884C\u7A0B\u5E8F\u7684\u5165\u53E3\u70B9",internal:"\u5185\u90E8\u5305\u76EE\u5F55\uFF0C\u4EC5\u672C\u9879\u76EE\u53EF\u4F7F\u7528",pkg:"\u53EF\u5BFC\u51FA\u5305\u76EE\u5F55\uFF0C\u4F9B\u5176\u4ED6\u9879\u76EE\u4F7F\u7528",api:"API \u5B9A\u4E49\u76EE\u5F55",web:"Web \u5E94\u7528\u76F8\u5173\u4EE3\u7801\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",handlers:"\u8BF7\u6C42\u5904\u7406\u5668\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",vendor:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5E93\u76EE\u5F55",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55"}}async detectVersions(e,t){let n={},o=fr(e,"go.mod");if(Vo(o))try{let a=Wo(o,"utf-8").match(/^go\s+(\d+\.\d+)/m);a&&(n.Go=a[1])}catch{}let s=fr(e,"go.sum");if(Vo(s))try{let a=Wo(s,"utf-8").match(/^golang\.org\/x\/sys\/v\d+\/[^\s]+\s+go(\d+\.\d+)/);a&&!n.Go&&(n.Go=a[1])}catch{}return n}findEntryPoints(e,t){let n=[];return["main.go","cmd/main.go","cmd/app/main.go","cmd/server/main.go","cmd/cli/main.go","src/main.go"].forEach(s=>{e.includes(s)&&n.push(s)}),e.forEach(s=>{if(s.endsWith(".go"))try{Wo(fr(t,s),"utf-8").includes("func main()")&&n.push(s)}catch{}}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={GoFmt:[".gofmt"],GoLint:[".golint"],"GolangCI-Lint":[".golangci.yml",".golangci.yaml"],EditorConfig:[".editorconfig"],GoMod:["go.mod"],GoSum:["go.sum"]};for(let[o,s]of Object.entries(n))for(let i of s)if(Vo(fr(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".go",".mod",".sum"]}getCommonTestExtensions(){return["_test.go",".test.go"]}getCommonConfigFiles(){return["go.mod","go.sum",".golangci.yml",".golangci.yaml",".editorconfig","Makefile"]}}});import{existsSync as aa,readFileSync as uu}from"fs";import{resolve as ca}from"path";var yr,la=C(()=>{ye();yr=class extends H{getLanguageName(){return"Rust"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 Rust \u4EE3\u7801","src/bin":"\u4E8C\u8FDB\u5236\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u591A\u4E2A\u53EF\u6267\u884C\u7A0B\u5E8F","src/lib.rs":"\u5E93\u9879\u76EE\u7684\u4E3B\u5165\u53E3\u6587\u4EF6","src/main.rs":"\u4E8C\u8FDB\u5236\u9879\u76EE\u7684\u4E3B\u5165\u53E3\u6587\u4EF6",target:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6\u548C\u4F9D\u8D56",tests:"\u96C6\u6210\u6D4B\u8BD5\u76EE\u5F55\uFF0C\u5305\u542B\u96C6\u6210\u6D4B\u8BD5\u4EE3\u7801",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",benches:"\u57FA\u51C6\u6D4B\u8BD5\u76EE\u5F55\uFF0C\u5305\u542B\u6027\u80FD\u6D4B\u8BD5\u4EE3\u7801",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",".cargo":"Cargo \u914D\u7F6E\u76EE\u5F55",vendor:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5E93\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55"}}async detectVersions(e,t){let n={},o=ca(e,"Cargo.toml");if(aa(o))try{let i=uu(o,"utf-8").match(/rust-version\s*=\s*['"]([^'"]+)['"]/);i&&(n.Rust=i[1])}catch{}return n}findEntryPoints(e,t){let n=[];return["src/main.rs","src/lib.rs","src/bin/main.rs","src/bin/*.rs"].forEach(s=>{if(s.includes("*")){let i=new RegExp(s.replace(/\*/g,"[^/]*"));e.forEach(a=>{i.test(a)&&n.push(a)})}else e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={Rustfmt:["rustfmt.toml",".rustfmt.toml"],Clippy:["clippy.toml",".clippy.toml"],EditorConfig:[".editorconfig"],Cargo:["Cargo.toml","Cargo.lock"]};for(let[o,s]of Object.entries(n))for(let i of s)if(aa(ca(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".rs",".toml",".lock"]}getCommonTestExtensions(){return["_test.rs",".test.rs","tests/*.rs"]}getCommonConfigFiles(){return["Cargo.toml","Cargo.lock","rustfmt.toml",".rustfmt.toml","clippy.toml",".clippy.toml",".editorconfig"]}}});import{existsSync as Ho,readFileSync as ua}from"fs";import{resolve as Jo}from"path";var Sr,ga=C(()=>{ye();Sr=class extends H{getLanguageName(){return"PHP"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 PHP \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",public:"\u516C\u5171\u8BBF\u95EE\u76EE\u5F55\uFF0C\u5305\u542B\u5165\u53E3\u6587\u4EF6\u548C\u9759\u6001\u8D44\u6E90","index.php":"\u7F51\u7AD9\u5165\u53E3\u6587\u4EF6",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",vendor:"Composer \u4F9D\u8D56\u5E93\u76EE\u5F55",composer:"Composer \u76F8\u5173\u6587\u4EF6\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",controllers:"\u63A7\u5236\u5668\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",views:"\u89C6\u56FE\u6A21\u677F\u76EE\u5F55",routes:"\u8DEF\u7531\u5B9A\u4E49\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55"}}async detectVersions(e,t){let n={},o=Jo(e,"composer.json");if(Ho(o))try{let i=ua(o,"utf-8"),a=JSON.parse(i);a.require&&a.require.php&&(n.PHP=a.require.php)}catch{}let s=Jo(e,".php-version");if(Ho(s))try{let i=ua(s,"utf-8");n.PHP=i.trim()}catch{}return n}findEntryPoints(e,t){let n=[];return["index.php","public/index.php","app/index.php","src/index.php","cli.php","artisan","bin/console","composer.json"].forEach(s=>{e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={PHP_CodeSniffer:["phpcs.xml","phpcs.xml.dist",".phpcs.xml",".phpcs.xml.dist"],PHPStan:["phpstan.neon","phpstan.neon.dist","phpstan.yml","phpstan.yml.dist"],Psalm:["psalm.xml","psalm.xml.dist","psalm.yml","psalm.yml.dist"],"PHP-CS-Fixer":[".php-cs-fixer.php",".php-cs-fixer.dist.php"],EditorConfig:[".editorconfig"],PHPUnit:["phpunit.xml","phpunit.xml.dist"],Composer:["composer.json","composer.lock"]};for(let[o,s]of Object.entries(n))for(let i of s)if(Ho(Jo(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".php",".phtml",".phar",".json",".lock"]}getCommonTestExtensions(){return[".test.php",".spec.php","Test.php","Tests.php","tests/*.php"]}getCommonConfigFiles(){return["composer.json","composer.lock","phpcs.xml","phpstan.neon","psalm.xml",".php-cs-fixer.php","phpunit.xml",".editorconfig",".php-version"]}}});import{existsSync as Go,readFileSync as pa}from"fs";import{resolve as zo}from"path";var Cr,ma=C(()=>{ye();Cr=class extends H{getLanguageName(){return"Ruby"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 Ruby \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",vendor:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5E93\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",controllers:"\u63A7\u5236\u5668\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",views:"\u89C6\u56FE\u6A21\u677F\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",routes:"\u8DEF\u7531\u5B9A\u4E49\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",spec:"RSpec \u6D4B\u8BD5\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",Gemfile:"RubyGems \u4F9D\u8D56\u914D\u7F6E\u6587\u4EF6"}}async detectVersions(e,t){let n={},o=zo(e,".ruby-version");if(Go(o))try{let i=pa(o,"utf-8");n.Ruby=i.trim()}catch{}let s=zo(e,"Gemfile");if(Go(s))try{let a=pa(s,"utf-8").match(/ruby\s+['"]([^'"]+)['"]/);a&&!n.Ruby&&(n.Ruby=a[1])}catch{}return n}findEntryPoints(e,t){let n=[];return["main.rb","app.rb","bin/rails","bin/rake","bin/console","config.ru","Rakefile","Gemfile"].forEach(s=>{e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={RuboCop:[".rubocop.yml",".rubocop.yaml",".rubocop_todo.yml"],RSpec:["spec/spec_helper.rb","spec/rails_helper.rb"],Minitest:["test/test_helper.rb"],EditorConfig:[".editorconfig"],Bundler:["Gemfile","Gemfile.lock"]};for(let[o,s]of Object.entries(n))for(let i of s)if(Go(zo(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".rb",".gemspec",".rake",".ru",".lock"]}getCommonTestExtensions(){return["_test.rb",".test.rb","test_*.rb","*_test.rb","spec/**/*.rb","test/**/*.rb"]}getCommonConfigFiles(){return["Gemfile","Gemfile.lock",".rubocop.yml",".ruby-version",".ruby-gemset","Rakefile","config.ru",".editorconfig"]}}});import{existsSync as da,readFileSync as fa}from"fs";import{resolve as qo}from"path";import{globSync as Bo}from"glob";var xr,ha=C(()=>{ye();xr=class extends H{getLanguageName(){return".NET"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 .NET \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",bin:"\u7F16\u8BD1\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6",obj:"\u4E2D\u95F4\u7F16\u8BD1\u8F93\u51FA\u76EE\u5F55",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",packages:"NuGet \u5305\u76EE\u5F55",nuget:"NuGet \u76F8\u5173\u6587\u4EF6\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",Controllers:"\u63A7\u5236\u5668\u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",Models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",Views:"\u89C6\u56FE\u6A21\u677F\u76EE\u5F55\uFF08ASP.NET MVC \u9879\u76EE\uFF09",Pages:"Razor Pages \u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",wwwroot:"\u9759\u6001\u8D44\u6E90\u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55"}}async detectVersions(e,t){let n={},o=[...Bo("*.csproj",{cwd:e}),...Bo("*.vbproj",{cwd:e}),...Bo("*.fsproj",{cwd:e})];for(let i of o)try{let a=qo(e,i),c=fa(a,"utf-8"),l=c.match(/<TargetFramework>([^<]+)<\/TargetFramework>/)||c.match(/<TargetFrameworks>([^<]+)<\/TargetFrameworks>/);if(l){n[".NET Framework"]=l[1];break}let p=c.match(/<LangVersion>([^<]+)<\/LangVersion>/);p&&(n["C# Version"]=p[1])}catch{}let s=qo(e,"global.json");if(da(s))try{let i=fa(s,"utf-8"),a=JSON.parse(i);a.sdk&&a.sdk.version&&(n[".NET SDK"]=a.sdk.version)}catch{}return n}findEntryPoints(e,t){let n=[];return["Program.cs","Startup.cs","App.xaml.cs","MainWindow.xaml.cs","Program.vb","Startup.vb","App.xaml.vb","MainWindow.xaml.vb","Program.fs","Startup.fs"].forEach(s=>{e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={StyleCop:[".stylecop","stylecop.json","stylecop.ruleset"],EditorConfig:[".editorconfig"],xUnit:["xunit.runner.json"],NUnit:["nunit.config","nunit3.config"],MSTest:["app.config","web.config"],NuGet:["nuget.config","packages.config"]};for(let[o,s]of Object.entries(n))for(let i of s)if(da(qo(e,i))){t.push(o);break}return t}getCommonSourceExtensions(){return[".cs",".vb",".fs",".csproj",".vbproj",".fsproj",".config",".json",".xml"]}getCommonTestExtensions(){return["Test.cs","Tests.cs","Test.vb","Tests.vb","Test.fs","Tests.fs","*Test.csproj","*Tests.csproj"]}getCommonConfigFiles(){return["*.csproj","*.vbproj","*.fsproj","appsettings.json","app.config","web.config","nuget.config","packages.config","global.json",".editorconfig"]}}});var Yo,Cn,ya=C(()=>{ra();oa();sa();ia();la();ga();ma();ha();Yo=class r{static instance;handlers=new Map;constructor(){this.registerHandlers()}static getInstance(){return r.instance||(r.instance=new r),r.instance}registerHandlers(){[new ur,new mr,new dr,new hr,new yr,new Sr,new Cr,new xr].forEach(t=>{let n=t.getLanguageName();this.handlers.set(n.toLowerCase(),t),this.registerLanguageAliases(n,t)})}registerLanguageAliases(e,t){let n={"javascript/typescript":["javascript","typescript","node.js","nodejs"],java:["java","jdk","jvm"],python:["python","py"],go:["go","golang"],rust:["rust","rs"],php:["php"],ruby:["ruby","rb"],".net":["c#/.net","csharp","dotnet",".net","vb.net","f#"]},o=e.toLowerCase();n[o]&&n[o].forEach(s=>{this.handlers.set(s.toLowerCase(),t)})}getHandler(e){if(!e)return null;let t=e.toLowerCase();return this.handlers.get(t)||null}getSupportedLanguages(){return Array.from(new Set(Array.from(this.handlers.values()).map(e=>e.getLanguageName())))}getDirectoryDescriptions(e){let t=this.getHandler(e);return t?t.getDirectoryDescriptions():{src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u6240\u6709\u4E3B\u8981\u7684\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",dist:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55"}}async detectVersions(e,t,n){let o=this.getHandler(e);return o?await o.detectVersions(t,n):{}}findEntryPoints(e,t,n){let o=this.getHandler(e);return o?o.findEntryPoints(t,n):[]}detectCodeStandards(e,t){let n=this.getHandler(e);return n?n.detectCodeStandards(t):[]}getCommonSourceExtensions(e){let t=this.getHandler(e);return t?t.getCommonSourceExtensions():[]}getCommonTestExtensions(e){let t=this.getHandler(e);return t?t.getCommonTestExtensions():[]}getCommonConfigFiles(e){let t=this.getHandler(e);return t?t.getCommonConfigFiles():[]}getDirectoryDescriptionsForLanguages(e){let t={};return e.forEach(n=>{let o=this.getDirectoryDescriptions(n);Object.assign(t,o)}),t}async detectVersionsForLanguages(e,t,n){let o={};for(let s of e){let i=await this.detectVersions(s,t,n);Object.assign(o,i)}return o}findEntryPointsForLanguages(e,t,n){let o=[];for(let s of e){let i=this.findEntryPoints(s,t,n);o.push(...i)}return[...new Set(o)]}detectCodeStandardsForLanguages(e,t){let n=[];for(let o of e){let s=this.detectCodeStandards(o,t);n.push(...s)}return[...new Set(n)]}},Cn=Yo.getInstance()});var Ca={};U(Ca,{QuickProjectScanTool:()=>Fe,quickProjectScan:()=>bt,quickProjectScanTool:()=>vt});import{existsSync as Re}from"fs";import{globSync as gu}from"glob";async function bt(){return Sa.execute({})}var Fe,Sa,vt,Ko=C(()=>{J();Qn();qi();Xi();ta();ya();Fe=class extends I{getDefinition(){return{name:"quickProjectScan",description:"Quickly scan the entire project structure, analyze directories, detect languages, and save project information to .nium/project/project.json. Use this when the user asks to explore or analyze the project structure.",input_schema:{type:"object",properties:{},required:[]}}}async execute(e){try{let t=[],n=process.cwd();t.push(`\u{1F50D} \u5F00\u59CB\u63A2\u7D22\u5DE5\u7A0B\u7ED3\u6784...
|
|
1107
|
-
`),t.push("\u{1F4C2} \u626B\u63CF\u9879\u76EE\u6587\u4EF6...");let
|
|
1108
|
-
`),t.push("\u{1F4CB} \u68C0\u6D4B\u9879\u76EE\u7C7B\u578B\u548C\u914D\u7F6E...");let c=
|
|
1109
|
-
`)}catch(t){return this.formatError("Quick project scan",t)}}detectProjectLanguages(e){let t={".js":"JavaScript",".mjs":"JavaScript (ES Modules)",".cjs":"JavaScript (CommonJS)",".jsx":"React JavaScript",".ts":"TypeScript",".tsx":"React TypeScript",".java":"Java",".class":"Java",".jar":"Java","pom.xml":"Java (Maven)","build.gradle":"Java (Gradle)",".py":"Python","requirements.txt":"Python","setup.py":"Python","pyproject.toml":"Python",".c":"C",".cpp":"C++",".h":"C/C++",".hpp":"C++","CMakeLists.txt":"C/C++ (CMake)",".go":"Go","go.mod":"Go",".rs":"Rust","Cargo.toml":"Rust",".php":"PHP","composer.json":"PHP (Composer)",".rb":"Ruby",Gemfile:"Ruby",".cs":"C#",".vb":"Visual Basic","packages.config":".NET",".html":"HTML",".css":"CSS",".scss":"SCSS",".less":"Less",".json":"JSON",".xml":"XML",".yml":"YAML",".yaml":"YAML",".md":"Markdown"},n={};e.forEach(a=>{if(t[a]){n[t[a]]=(n[t[a]]||0)+1;return}let c=a.lastIndexOf(".");if(c>-1){let l=a.substring(c);t[l]&&(n[t[l]]=(n[t[l]]||0)+1)}});let
|
|
1110
|
-
`):"\u6682\u65E0\u7248\u672C\u4FE1\u606F",
|
|
1284
|
+
`,"utf-8")}catch(t){throw console.error(`\u274C \u5199\u5165 JSONL \u6587\u4EF6\u5931\u8D25: ${e}`,t),t}}function Za(o,e,t=process.cwd(),n=!0){n&&console.log(` \u{1F4D6} \u6B63\u5728\u8BFB\u53D6\u73B0\u6709\u6587\u4EF6\u4FE1\u606F: ${e}`);let r=gg(e),s={added:0,updated:0,deleted:0,unchanged:0},i=new Map,a=new Set(o),c=o.length,l=0,g=Date.now();n&&(console.log(` \u{1F4CB} \u8BFB\u53D6\u73B0\u6709\u6587\u4EF6\u4FE1\u606F\u5B8C\u6210\uFF0C\u5DF2\u6709 ${r.size} \u6761\u8BB0\u5F55`),console.log(` \u{1F680} \u5F00\u59CB\u5904\u7406 ${c} \u4E2A\u6587\u4EF6...`));for(let p of o){if(l++,n&&l===1&&console.log(` \u{1F504} \u5904\u7406\u7B2C 1 \u4E2A\u6587\u4EF6: ${p}`),n&&l%50===0){let d=(l/c*100).toFixed(1),y=((Date.now()-g)/1e3).toFixed(1);console.log(` \u{1F4CA} \u5904\u7406\u8FDB\u5EA6: ${l}/${c} (${d}%) - \u5DF2\u7528\u65F6 ${y}s`)}let u=r.get(p),m=ug(p,t);m&&(u?u.md5!==m.md5?(i.set(p,{...m,description:u.description}),s.updated++):(i.set(p,u),s.unchanged++):(i.set(p,m),s.added++))}if(n){let p=((Date.now()-g)/1e3).toFixed(1);console.log(` \u2705 \u6587\u4EF6\u5904\u7406\u5B8C\u6210: ${c} \u4E2A\u6587\u4EF6, \u603B\u7528\u65F6 ${p}s`)}n&&console.log(" \u{1F50D} \u6B63\u5728\u68C0\u6D4B\u5DF2\u5220\u9664\u7684\u6587\u4EF6...");for(let[p]of r)a.has(p)||s.deleted++;return n&&console.log(` \u{1F4CA} \u68C0\u6D4B\u5230 ${s.deleted} \u4E2A\u5DF2\u5220\u9664\u7684\u6587\u4EF6`),n&&console.log(` \u{1F4BE} \u6B63\u5728\u5199\u5165 ${i.size} \u6761\u6587\u4EF6\u4FE1\u606F\u5230 JSONL...`),pg(i,e),n&&console.log(" \u2705 JSONL \u6587\u4EF6\u5199\u5165\u5B8C\u6210"),s}function ec(o){let e=o.added+o.updated+o.deleted+o.unchanged,t=[];return t.push("\u{1F4C4} \u6587\u4EF6\u4FE1\u606F\u66F4\u65B0\u6458\u8981"),t.push("\u2500".repeat(40)),t.push(`\u603B\u6587\u4EF6\u6570: ${e}`),o.added>0&&t.push(`\u2795 \u65B0\u589E: ${o.added} \u4E2A\u6587\u4EF6`),o.updated>0&&t.push(`\u{1F504} \u66F4\u65B0: ${o.updated} \u4E2A\u6587\u4EF6`),o.deleted>0&&t.push(`\u2796 \u5220\u9664: ${o.deleted} \u4E2A\u6587\u4EF6`),o.unchanged>0&&t.push(`\u2705 \u672A\u53D8: ${o.unchanged} \u4E2A\u6587\u4EF6`),t.push("\u2500".repeat(40)),t.join(`
|
|
1285
|
+
`)}var tc=S(()=>{});var X,$e=S(()=>{X=class{getCommonDirectoryDescriptions(){return{src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u6240\u6709\u4E3B\u8981\u7684\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",dist:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",components:"\u7EC4\u4EF6\u76EE\u5F55",pages:"\u9875\u9762\u76EE\u5F55",public:"\u516C\u5171\u8D44\u6E90\u76EE\u5F55",assets:"\u9759\u6001\u8D44\u6E90\u76EE\u5F55",utils:"\u5DE5\u5177\u51FD\u6570\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",services:"\u670D\u52A1\u5C42\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",controllers:"\u63A7\u5236\u5668\u76EE\u5F55",routes:"\u8DEF\u7531\u5B9A\u4E49\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",plugins:"\u63D2\u4EF6\u76EE\u5F55",hooks:"\u94A9\u5B50\u51FD\u6570\u76EE\u5F55",types:"\u7C7B\u578B\u5B9A\u4E49\u76EE\u5F55",interfaces:"\u63A5\u53E3\u5B9A\u4E49\u76EE\u5F55",schemas:"\u6570\u636E\u7ED3\u6784\u5B9A\u4E49\u76EE\u5F55"}}}});import{existsSync as ks,readFileSync as nc}from"fs";import{resolve as Ps}from"path";var Kr,rc=S(()=>{$e();Kr=class extends X{getLanguageName(){return"JavaScript/TypeScript"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u6240\u6709\u4E3B\u8981\u7684 JavaScript/TypeScript \u4EE3\u7801",lib:"\u7F16\u8BD1\u540E\u7684\u5E93\u6587\u4EF6\u76EE\u5F55",dist:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u6253\u5305\u540E\u7684\u751F\u4EA7\u4EE3\u7801",public:"\u516C\u5171\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u9759\u6001\u6587\u4EF6",assets:"\u9759\u6001\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u56FE\u7247\u3001\u6837\u5F0F\u7B49",components:"React/Vue \u7EC4\u4EF6\u76EE\u5F55",pages:"\u9875\u9762\u7EC4\u4EF6\u76EE\u5F55",hooks:"React \u94A9\u5B50\u51FD\u6570\u76EE\u5F55",context:"React \u4E0A\u4E0B\u6587\u76EE\u5F55",redux:"Redux \u72B6\u6001\u7BA1\u7406\u76EE\u5F55",store:"\u72B6\u6001\u7BA1\u7406\u76EE\u5F55",actions:"Redux \u52A8\u4F5C\u76EE\u5F55",reducers:"Redux \u5F52\u7EA6\u5668\u76EE\u5F55",slices:"Redux Toolkit \u5207\u7247\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",utils:"\u5DE5\u5177\u51FD\u6570\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",services:"API \u670D\u52A1\u76EE\u5F55",api:"API \u63A5\u53E3\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",types:"TypeScript \u7C7B\u578B\u5B9A\u4E49\u76EE\u5F55",interfaces:"TypeScript \u63A5\u53E3\u5B9A\u4E49\u76EE\u5F55",schemas:"\u6570\u636E\u7ED3\u6784\u5B9A\u4E49\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u6D4B\u8BD5\u7B49\u811A\u672C",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",__tests__:"Jest \u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55",spec:"Jasmine/Mocha \u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55"}}async detectVersions(e,t){let n={},r=Ps(e,"package.json");if(ks(r))try{let s=nc(r,"utf-8"),i=JSON.parse(s);i.engines&&(i.engines.node&&(n["Node.js"]=i.engines.node),i.engines.npm&&(n.npm=i.engines.npm),i.engines.yarn&&(n.yarn=i.engines.yarn),i.engines.pnpm&&(n.pnpm=i.engines.pnpm))}catch{}return n}findEntryPoints(e,t){let n=[],r=["index.js","index.ts","index.mjs","index.cjs","app.js","app.ts","main.js","main.ts","server.js","server.ts","src/index.js","src/index.ts","src/main.js","src/main.ts","src/app.js","src/app.ts","next.config.js","vite.config.js","webpack.config.js","rollup.config.js"],s=Ps(t,"package.json");if(ks(s))try{let i=nc(s,"utf-8"),a=JSON.parse(i);a.main&&n.push(a.main),a.bin&&(typeof a.bin=="string"?n.push(a.bin):n.push(...Object.values(a.bin)))}catch{}return r.forEach(i=>{e.includes(i)&&n.push(i)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={ESLint:[".eslintrc.js",".eslintrc.json",".eslintrc.yml",".eslintrc.yaml",".eslintrc"],Prettier:[".prettierrc",".prettierrc.json",".prettierrc.yml",".prettierrc.yaml",".prettierrc.js","prettier.config.js"],EditorConfig:[".editorconfig"],TypeScript:["tsconfig.json"],Flow:[".flowconfig"],Jest:["jest.config.js","jest.config.ts","jest.config.json"],Vitest:["vitest.config.js","vitest.config.ts"],Mocha:["mocha.opts",".mocharc.js"],Jasmine:["jasmine.json"]};for(let[r,s]of Object.entries(n))for(let i of s)if(ks(Ps(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".js",".mjs",".cjs",".jsx",".ts",".tsx",".vue",".svelte",".astro"]}getCommonTestExtensions(){return[".test.js",".test.ts",".test.jsx",".test.tsx",".spec.js",".spec.ts",".spec.jsx",".spec.tsx"]}getCommonConfigFiles(){return["package.json","tsconfig.json","tsconfig.node.json","jsconfig.json",".eslintrc.js",".eslintrc.json",".prettierrc",".prettierrc.json",".editorconfig","vite.config.js","vite.config.ts","webpack.config.js","webpack.config.ts","rollup.config.js","rollup.config.ts","next.config.js","next.config.mjs","nuxt.config.js","nuxt.config.ts","astro.config.mjs","astro.config.ts"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});import{existsSync as Te,readFileSync as Nt,writeFileSync as mg,mkdirSync as dg}from"fs";import{resolve as Ve,dirname as fg}from"path";var Yr,oc=S(()=>{$e();Yr=class extends X{getLanguageName(){return"Java"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u6839\u76EE\u5F55","src/main/java":"\u4E3B\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u751F\u4EA7\u4EE3\u7801","src/main/resources":"\u4E3B\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u914D\u7F6E\u6587\u4EF6\u548C\u9759\u6001\u8D44\u6E90","src/test/java":"\u6D4B\u8BD5\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5","src/test/resources":"\u6D4B\u8BD5\u8D44\u6E90\u76EE\u5F55\uFF0C\u5305\u542B\u6D4B\u8BD5\u914D\u7F6E\u6587\u4EF6",target:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u7C7B\u6587\u4EF6\u548C\u6253\u5305\u4EA7\u7269",lib:"\u5916\u90E8\u4F9D\u8D56\u5E93\u76EE\u5F55",libs:"\u5916\u90E8\u4F9D\u8D56\u5E93\u76EE\u5F55",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55",gradle:"Gradle \u6784\u5EFA\u7CFB\u7EDF\u76EE\u5F55",maven:"Maven \u6784\u5EFA\u7CFB\u7EDF\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C"}}async detectVersions(e,t){let n={},r=Ve(e,"pom.xml");if(Te(r))try{let a=Nt(r,"utf-8"),c=a.match(/<java\.version>([^<]+)<\/java\.version>/)||a.match(/<maven\.compiler\.source>([^<]+)<\/maven\.compiler\.source>/);c&&(n.Java=c[1])}catch{}let s=Ve(e,"build.gradle"),i=Ve(e,"build.gradle.kts");if(Te(s))try{let a=Nt(s,"utf-8"),c=a.match(/sourceCompatibility\s*=\s*['"]?([^'"\\s]+)['"]?/)||a.match(/targetCompatibility\s*=\s*['"]?([^'"\\s]+)['"]?/);c&&(n.Java=c[1])}catch{}else if(Te(i))try{let a=Nt(i,"utf-8"),c=a.match(/sourceCompatibility\s*=\s*JavaVersion\.VERSION_(\d+_\d+)/)||a.match(/targetCompatibility\s*=\s*JavaVersion\.VERSION_(\d+_\d+)/);c&&(n.Java=c[1].replace("_","."))}catch{}return n}findEntryPoints(e,t){let n=[],r=["src/main/java/**/Main.java","src/main/java/**/Application.java","src/main/java/**/App.java","src/main/java/**/Bootstrap.java","src/main/java/**/Launcher.java"];return e.forEach(s=>{if(s.endsWith(".java"))try{Nt(Ve(t,s),"utf-8").includes("public static void main(String[] args)")&&n.push(s)}catch{}}),r.forEach(s=>{let i=new RegExp(s.replace(/\*\*/g,".*").replace(/\*/g,"[^/]*"));e.forEach(a=>{i.test(a)&&n.push(a)})}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={Checkstyle:["checkstyle.xml","google_checks.xml","sun_checks.xml"],PMD:["pmd.xml",".pmd"],FindBugs:["findbugs.xml",".findbugs"],SpotBugs:["spotbugs.xml",".spotbugs"],SonarQube:["sonar-project.properties"],EditorConfig:[".editorconfig"],Maven:["pom.xml"],Gradle:["build.gradle","build.gradle.kts"]};for(let[r,s]of Object.entries(n))for(let i of s)if(Te(Ve(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".java",".class",".jar",".war",".ear"]}getCommonTestExtensions(){return["Test.java","Tests.java"]}getCommonConfigFiles(){return["pom.xml","build.gradle","build.gradle.kts","settings.gradle","gradle.properties","checkstyle.xml","pmd.xml","spotbugs.xml","sonar-project.properties",".editorconfig"]}async analyzeDependencies(e,t){let n={dependencies:[],conflicts:[],recommendations:[]};try{let r=Ve(e,"pom.xml"),s=Ve(e,"build.gradle"),i=Ve(e,"build.gradle.kts");if(!Te(r)&&!Te(s)&&!Te(i))return n;Te(r)?await this.analyzeMavenDependencies(r,n):Te(s)?this.analyzeGradleDependencies(s,n):Te(i)&&this.analyzeGradleDependencies(i,n),this.detectDependencyConflicts(n),this.generateRecommendations(n)}catch(r){console.error("\u4F9D\u8D56\u5206\u6790\u5931\u8D25:",r)}return n}async analyzeMavenDependencies(e,t){let n=Nt(e,"utf-8"),r=await import("xml2js");return new Promise((s,i)=>{r.parseString(n,{explicitArray:!1},(a,c)=>{if(a){i(a);return}let{project:l}=c;if(!l){s();return}let g=l.dependencies?.dependency;g&&(Array.isArray(g)?g:[g]).forEach(u=>{t.dependencies.push({groupId:u.groupId,artifactId:u.artifactId,version:u.version||"unknown",scope:u.scope||"compile",type:u.type||"jar"})}),s()})})}analyzeGradleDependencies(e,t){let n=Nt(e,"utf-8");[/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation|testCompile|testApi|testCompileOnly|testRuntimeOnly)\s*['"]([^:'"]+):([^:'"]+):([^:'"]+)['"]/gms,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation|testCompile|testApi|testCompileOnly|testRuntimeOnly)\s*['"]([^:'"]+):([^:'"]+)['"]/gms,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation|testCompile|testApi|testCompileOnly|testRuntimeOnly)\s*\(\s*group\s*:\s*['"]([^'"]+)['"],\s*name\s*:\s*['"]([^'"]+)['"],\s*version\s*:\s*['"]([^'"]+)['"][^)]*\)/gms,/(implementation|compile|api|compileOnly|runtimeOnly|testImplementation|testCompile|testApi|testCompileOnly|testRuntimeOnly)\s*\(\s*["']([^"']+):([^"']+):([^"']+)["']\s*\)/gms].forEach(s=>{let i;for(;(i=s.exec(n))!==null;){let a,c,l,g;if(i.length===5)[,a,c,l,g]=i;else if(i.length===4)[,a,c,l]=i,g="managed";else continue;t.dependencies.push({groupId:c,artifactId:l,version:g,scope:a.toLowerCase(),type:"jar"})}})}detectDependencyConflicts(e){let t=new Map;e.dependencies.forEach(n=>{if(n.groupId&&n.artifactId){let r=`${n.groupId}:${n.artifactId}`;t.has(r)||t.set(r,new Set),t.get(r)?.add(n.version)}}),t.forEach((n,r)=>{if(n.size>1){let[s,i]=r.split(":");e.conflicts.push({groupId:s,artifactId:i,versions:Array.from(n),severity:this.calculateConflictSeverity(Array.from(n))})}})}calculateConflictSeverity(e){let t=e.map(r=>{let s=r.match(/^(\d+)/);return s?parseInt(s[1]):0});return new Set(t).size>1?"high":e.length>2?"medium":"low"}generateRecommendations(e){let t=[];e.conflicts.length>0&&t.push(`${e.conflicts.length} \u4E2A\u4F9D\u8D56\u5B58\u5728\u7248\u672C\u51B2\u7A81\uFF0C\u5EFA\u8BAE\u7EDF\u4E00\u7248\u672C`),e.dependencies.some(s=>s.groupId==="org.springframework.boot")&&t.push("\u9879\u76EE\u4F7F\u7528Spring Boot\uFF0C\u5EFA\u8BAE\u4F7F\u7528Spring Dependency Management\u63D2\u4EF6\u7BA1\u7406\u4F9D\u8D56\u7248\u672C");let r=this.detectJavaVersion(e);if(r){let s=parseInt(r);s<11?t.push("Java\u7248\u672C\u8F83\u65E7\uFF0C\u5EFA\u8BAE\u5347\u7EA7\u5230Java 11\u6216\u66F4\u9AD8\u7248\u672C"):s>=17&&t.push("\u4F7F\u7528\u73B0\u4EE3Java\u7248\u672C\uFF0C\u53EF\u4EE5\u4EAB\u53D7\u6700\u65B0\u7279\u6027")}e.recommendations=t}detectJavaVersion(e){}saveDependencyAnalysis(e,t){try{let n=`${t}/.nium/java-dependency-analysis.json`;dg(fg(n),{recursive:!0}),mg(n,JSON.stringify({scanTime:new Date().toISOString(),dependencies:e.dependencies,conflicts:e.conflicts,recommendations:e.recommendations},null,2))}catch(n){console.error("\u4FDD\u5B58\u4F9D\u8D56\u5206\u6790\u7ED3\u679C\u5931\u8D25:",n)}}}});import{existsSync as Hn,readFileSync as Jn}from"fs";import{resolve as Ut}from"path";var Xr,sc=S(()=>{$e();Xr=class extends X{getLanguageName(){return"Python"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 Python \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",main:"\u4E3B\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",__pycache__:"Python \u7F16\u8BD1\u7F13\u5B58\u76EE\u5F55",venv:"\u865A\u62DF\u73AF\u5883\u76EE\u5F55",".venv":"\u865A\u62DF\u73AF\u5883\u76EE\u5F55",env:"\u73AF\u5883\u53D8\u91CF\u914D\u7F6E\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",data:"\u6570\u636E\u6587\u4EF6\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",dist:"\u6253\u5305\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u53D1\u5E03\u7684\u5305\u6587\u4EF6",requirements:"\u4F9D\u8D56\u7BA1\u7406\u76EE\u5F55"}}async detectVersions(e,t){let n={},r=Ut(e,".python-version");if(Hn(r))try{let a=Jn(r,"utf-8");n.Python=a.trim()}catch{}let s=Ut(e,"pyproject.toml");if(Hn(s))try{let c=Jn(s,"utf-8").match(/python\s*=\s*['"]([^'"]+)['"]/);c&&(n.Python=c[1])}catch{}let i=Ut(e,"setup.py");if(Hn(i))try{let c=Jn(i,"utf-8").match(/python_requires\s*=\s*['"]([^'"]+)['"]/);c&&(n.Python=c[1])}catch{}return n}findEntryPoints(e,t){let n=[];["main.py","__main__.py","app.py","run.py","manage.py","server.py","cli.py","setup.py","src/main.py","src/__main__.py","src/app.py"].forEach(i=>{e.includes(i)&&n.push(i)});let s=Ut(t,"setup.py");if(Hn(s))try{let a=Jn(s,"utf-8").match(/entry_points\s*=\s*\{[^}]+\}/s);if(a){let l=a[0].match(/console_scripts\s*:\s*\[([^\]]+)\]/s);if(l){let p=l[1].match(/([^=]+)\s*=\s*([^,]+)/g);p&&p.forEach(u=>{let[m,d]=u.split("=").map(w=>w.trim()),y=d.replace(/\./g,"/").replace(":","/")+".py";n.push(y)})}}}catch{}return[...new Set(n)]}detectCodeStandards(e){let t=[],n={Black:["pyproject.toml","setup.cfg"],Pylint:[".pylintrc","pylintrc","setup.cfg"],Flake8:[".flake8","flake8.cfg","setup.cfg"],Mypy:["mypy.ini",".mypy.ini","setup.cfg","pyproject.toml"],isort:[".isort.cfg","setup.cfg","pyproject.toml"],Bandit:[".bandit","bandit.yml"],Pytest:["pytest.ini","setup.cfg","conftest.py"],EditorConfig:[".editorconfig"]};for(let[r,s]of Object.entries(n))for(let i of s)if(Hn(Ut(e,i)))if(r==="Black")try{if(Jn(Ut(e,i),"utf-8").includes("[tool.black]")){t.push(r);break}}catch{}else{t.push(r);break}return t}getCommonSourceExtensions(){return[".py",".pyc",".pyo",".pyd",".pyx",".pxd",".pxi"]}getCommonTestExtensions(){return[".test.py",".spec.py","_test.py","test_*.py","*_test.py"]}getCommonConfigFiles(){return["pyproject.toml","setup.py","setup.cfg","requirements.txt","requirements-dev.txt","Pipfile","Pipfile.lock","poetry.lock",".pylintrc",".flake8","mypy.ini",".isort.cfg","pytest.ini","conftest.py",".editorconfig"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});import{existsSync as $s,readFileSync as Es}from"fs";import{resolve as Qr}from"path";var Zr,ic=S(()=>{$e();Zr=class extends X{getLanguageName(){return"Go"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF08\u4F20\u7EDF Go \u9879\u76EE\u7ED3\u6784\uFF09",cmd:"\u547D\u4EE4\u884C\u5DE5\u5177\u76EE\u5F55\uFF0C\u5305\u542B\u53EF\u6267\u884C\u7A0B\u5E8F\u7684\u5165\u53E3\u70B9",internal:"\u5185\u90E8\u5305\u76EE\u5F55\uFF0C\u4EC5\u672C\u9879\u76EE\u53EF\u4F7F\u7528",pkg:"\u53EF\u5BFC\u51FA\u5305\u76EE\u5F55\uFF0C\u4F9B\u5176\u4ED6\u9879\u76EE\u4F7F\u7528",api:"API \u5B9A\u4E49\u76EE\u5F55",web:"Web \u5E94\u7528\u76F8\u5173\u4EE3\u7801\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",handlers:"\u8BF7\u6C42\u5904\u7406\u5668\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",vendor:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5E93\u76EE\u5F55",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55"}}async detectVersions(e,t){let n={},r=Qr(e,"go.mod");if($s(r))try{let a=Es(r,"utf-8").match(/^go\s+(\d+\.\d+)/m);a&&(n.Go=a[1])}catch{}let s=Qr(e,"go.sum");if($s(s))try{let a=Es(s,"utf-8").match(/^golang\.org\/x\/sys\/v\d+\/[^\s]+\s+go(\d+\.\d+)/);a&&!n.Go&&(n.Go=a[1])}catch{}return n}findEntryPoints(e,t){let n=[];return["main.go","cmd/main.go","cmd/app/main.go","cmd/server/main.go","cmd/cli/main.go","src/main.go"].forEach(s=>{e.includes(s)&&n.push(s)}),e.forEach(s=>{if(s.endsWith(".go"))try{Es(Qr(t,s),"utf-8").includes("func main()")&&n.push(s)}catch{}}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={GoFmt:[".gofmt"],GoLint:[".golint"],"GolangCI-Lint":[".golangci.yml",".golangci.yaml"],EditorConfig:[".editorconfig"],GoMod:["go.mod"],GoSum:["go.sum"]};for(let[r,s]of Object.entries(n))for(let i of s)if($s(Qr(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".go",".mod",".sum"]}getCommonTestExtensions(){return["_test.go",".test.go"]}getCommonConfigFiles(){return["go.mod","go.sum",".golangci.yml",".golangci.yaml",".editorconfig","Makefile"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});import{existsSync as ac,readFileSync as hg}from"fs";import{resolve as cc}from"path";var eo,lc=S(()=>{$e();eo=class extends X{getLanguageName(){return"Rust"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 Rust \u4EE3\u7801","src/bin":"\u4E8C\u8FDB\u5236\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u591A\u4E2A\u53EF\u6267\u884C\u7A0B\u5E8F","src/lib.rs":"\u5E93\u9879\u76EE\u7684\u4E3B\u5165\u53E3\u6587\u4EF6","src/main.rs":"\u4E8C\u8FDB\u5236\u9879\u76EE\u7684\u4E3B\u5165\u53E3\u6587\u4EF6",target:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6\u548C\u4F9D\u8D56",tests:"\u96C6\u6210\u6D4B\u8BD5\u76EE\u5F55\uFF0C\u5305\u542B\u96C6\u6210\u6D4B\u8BD5\u4EE3\u7801",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",benches:"\u57FA\u51C6\u6D4B\u8BD5\u76EE\u5F55\uFF0C\u5305\u542B\u6027\u80FD\u6D4B\u8BD5\u4EE3\u7801",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",".cargo":"Cargo \u914D\u7F6E\u76EE\u5F55",vendor:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5E93\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55"}}async detectVersions(e,t){let n={},r=cc(e,"Cargo.toml");if(ac(r))try{let i=hg(r,"utf-8").match(/rust-version\s*=\s*['"]([^'"]+)['"]/);i&&(n.Rust=i[1])}catch{}return n}findEntryPoints(e,t){let n=[];return["src/main.rs","src/lib.rs","src/bin/main.rs","src/bin/*.rs"].forEach(s=>{if(s.includes("*")){let i=new RegExp(s.replace(/\*/g,"[^/]*"));e.forEach(a=>{i.test(a)&&n.push(a)})}else e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={Rustfmt:["rustfmt.toml",".rustfmt.toml"],Clippy:["clippy.toml",".clippy.toml"],EditorConfig:[".editorconfig"],Cargo:["Cargo.toml","Cargo.lock"]};for(let[r,s]of Object.entries(n))for(let i of s)if(ac(cc(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".rs",".toml",".lock"]}getCommonTestExtensions(){return["_test.rs",".test.rs","tests/*.rs"]}getCommonConfigFiles(){return["Cargo.toml","Cargo.lock","rustfmt.toml","clippy.toml",".editorconfig","Makefile"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});import{existsSync as Ms,readFileSync as uc}from"fs";import{resolve as Is}from"path";var to,gc=S(()=>{$e();to=class extends X{getLanguageName(){return"PHP"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 PHP \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",public:"\u516C\u5171\u8BBF\u95EE\u76EE\u5F55\uFF0C\u5305\u542B\u5165\u53E3\u6587\u4EF6\u548C\u9759\u6001\u8D44\u6E90","index.php":"\u7F51\u7AD9\u5165\u53E3\u6587\u4EF6",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",vendor:"Composer \u4F9D\u8D56\u5E93\u76EE\u5F55",composer:"Composer \u76F8\u5173\u6587\u4EF6\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",controllers:"\u63A7\u5236\u5668\u76EE\u5F55",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55",views:"\u89C6\u56FE\u6A21\u677F\u76EE\u5F55",routes:"\u8DEF\u7531\u5B9A\u4E49\u76EE\u5F55",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55"}}async detectVersions(e,t){let n={},r=Is(e,"composer.json");if(Ms(r))try{let i=uc(r,"utf-8"),a=JSON.parse(i);a.require&&a.require.php&&(n.PHP=a.require.php)}catch{}let s=Is(e,".php-version");if(Ms(s))try{let i=uc(s,"utf-8");n.PHP=i.trim()}catch{}return n}findEntryPoints(e,t){let n=[];return["index.php","public/index.php","app/index.php","src/index.php","cli.php","artisan","bin/console","composer.json"].forEach(s=>{e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={PHP_CodeSniffer:["phpcs.xml","phpcs.xml.dist",".phpcs.xml",".phpcs.xml.dist"],PHPStan:["phpstan.neon","phpstan.neon.dist","phpstan.yml","phpstan.yml.dist"],Psalm:["psalm.xml","psalm.xml.dist","psalm.yml","psalm.yml.dist"],"PHP-CS-Fixer":[".php-cs-fixer.php",".php-cs-fixer.dist.php"],EditorConfig:[".editorconfig"],PHPUnit:["phpunit.xml","phpunit.xml.dist"],Composer:["composer.json","composer.lock"]};for(let[r,s]of Object.entries(n))for(let i of s)if(Ms(Is(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".php",".phtml",".phar",".json",".lock"]}getCommonTestExtensions(){return[".test.php",".spec.php","Test.php","Tests.php","tests/*.php"]}getCommonConfigFiles(){return["composer.json","composer.lock","phpcs.xml","phpstan.neon","psalm.xml",".php-cs-fixer.php","phpunit.xml",".editorconfig",".php-version"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});import{existsSync as As,readFileSync as pc}from"fs";import{resolve as Ls}from"path";var no,mc=S(()=>{$e();no=class extends X{getLanguageName(){return"Ruby"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 Ruby \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",vendor:"\u7B2C\u4E09\u65B9\u4F9D\u8D56\u5E93\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",controllers:"\u63A7\u5236\u5668\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",views:"\u89C6\u56FE\u6A21\u677F\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",routes:"\u8DEF\u7531\u5B9A\u4E49\u76EE\u5F55\uFF08Rails \u9879\u76EE\uFF09",middleware:"\u4E2D\u95F4\u4EF6\u76EE\u5F55",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",spec:"RSpec \u6D4B\u8BD5\u76EE\u5F55",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",build:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",Gemfile:"RubyGems \u4F9D\u8D56\u914D\u7F6E\u6587\u4EF6"}}async detectVersions(e,t){let n={},r=Ls(e,".ruby-version");if(As(r))try{let i=pc(r,"utf-8");n.Ruby=i.trim()}catch{}let s=Ls(e,"Gemfile");if(As(s))try{let a=pc(s,"utf-8").match(/ruby\s+['"]([^'"]+)['"]/);a&&!n.Ruby&&(n.Ruby=a[1])}catch{}return n}findEntryPoints(e,t){let n=[];return["main.rb","app.rb","bin/rails","bin/rake","bin/console","config.ru","Rakefile","Gemfile"].forEach(s=>{e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={RuboCop:[".rubocop.yml",".rubocop.yaml",".rubocop_todo.yml"],RSpec:["spec/spec_helper.rb","spec/rails_helper.rb"],Minitest:["test/test_helper.rb"],EditorConfig:[".editorconfig"],Bundler:["Gemfile","Gemfile.lock"]};for(let[r,s]of Object.entries(n))for(let i of s)if(As(Ls(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".rb",".gemspec",".rake",".ru",".lock"]}getCommonTestExtensions(){return["_test.rb",".test.rb","test_*.rb","*_test.rb","spec/**/*.rb","test/**/*.rb"]}getCommonConfigFiles(){return["Gemfile","Gemfile.lock",".rubocop.yml",".ruby-version",".ruby-gemset","Rakefile","config.ru",".editorconfig"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});import{existsSync as dc,readFileSync as fc}from"fs";import{resolve as Rs}from"path";import{globSync as Ds}from"glob";var ro,hc=S(()=>{$e();ro=class extends X{getLanguageName(){return".NET"}getDirectoryDescriptions(){return{...this.getCommonDirectoryDescriptions(),src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4E3B\u8981\u7684 .NET \u4EE3\u7801",app:"\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801\u76EE\u5F55",bin:"\u7F16\u8BD1\u8F93\u51FA\u76EE\u5F55\uFF0C\u5305\u542B\u7F16\u8BD1\u540E\u7684\u4E8C\u8FDB\u5236\u6587\u4EF6",obj:"\u4E2D\u95F4\u7F16\u8BD1\u8F93\u51FA\u76EE\u5F55",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",libs:"\u5E93\u6587\u4EF6\u76EE\u5F55",packages:"NuGet \u5305\u76EE\u5F55",nuget:"NuGet \u76F8\u5173\u6587\u4EF6\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55",Controllers:"\u63A7\u5236\u5668\u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",Models:"\u6570\u636E\u6A21\u578B\u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",Views:"\u89C6\u56FE\u6A21\u677F\u76EE\u5F55\uFF08ASP.NET MVC \u9879\u76EE\uFF09",Pages:"Razor Pages \u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",wwwroot:"\u9759\u6001\u8D44\u6E90\u76EE\u5F55\uFF08ASP.NET \u9879\u76EE\uFF09",services:"\u4E1A\u52A1\u903B\u8F91\u670D\u52A1\u76EE\u5F55",helpers:"\u8F85\u52A9\u51FD\u6570\u76EE\u5F55",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",scripts:"\u811A\u672C\u76EE\u5F55\uFF0C\u5305\u542B\u6784\u5EFA\u3001\u90E8\u7F72\u7B49\u811A\u672C",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55"}}async detectVersions(e,t){let n={},r=[...Ds("*.csproj",{cwd:e}),...Ds("*.vbproj",{cwd:e}),...Ds("*.fsproj",{cwd:e})];for(let i of r)try{let a=Rs(e,i),c=fc(a,"utf-8"),l=c.match(/<TargetFramework>([^<]+)<\/TargetFramework>/)||c.match(/<TargetFrameworks>([^<]+)<\/TargetFrameworks>/);if(l){n[".NET Framework"]=l[1];break}let g=c.match(/<LangVersion>([^<]+)<\/LangVersion>/);g&&(n["C# Version"]=g[1])}catch{}let s=Rs(e,"global.json");if(dc(s))try{let i=fc(s,"utf-8"),a=JSON.parse(i);a.sdk&&a.sdk.version&&(n[".NET SDK"]=a.sdk.version)}catch{}return n}findEntryPoints(e,t){let n=[];return["Program.cs","Startup.cs","App.xaml.cs","MainWindow.xaml.cs","Program.vb","Startup.vb","App.xaml.vb","MainWindow.xaml.vb","Program.fs","Startup.fs"].forEach(s=>{e.includes(s)&&n.push(s)}),[...new Set(n)]}detectCodeStandards(e){let t=[],n={StyleCop:[".stylecop","stylecop.json","stylecop.ruleset"],EditorConfig:[".editorconfig"],xUnit:["xunit.runner.json"],NUnit:["nunit.config","nunit3.config"],MSTest:["app.config","web.config"],NuGet:["nuget.config","packages.config"]};for(let[r,s]of Object.entries(n))for(let i of s)if(dc(Rs(e,i))){t.push(r);break}return t}getCommonSourceExtensions(){return[".cs",".vb",".fs",".csproj",".vbproj",".fsproj",".config",".json",".xml"]}getCommonTestExtensions(){return["Test.cs","Tests.cs","Test.vb","Tests.vb","Test.fs","Tests.fs","*Test.csproj","*Tests.csproj"]}getCommonConfigFiles(){return["*.csproj","*.vbproj","*.fsproj","appsettings.json","app.config","web.config","nuget.config","packages.config","global.json",".editorconfig"]}async analyzeDependencies(e,t){return{dependencies:[],conflicts:[],recommendations:[]}}}});var Os,Wt,yc=S(()=>{rc();oc();sc();ic();lc();gc();mc();hc();Os=class o{static instance;handlers=new Map;constructor(){this.registerHandlers()}static getInstance(){return o.instance||(o.instance=new o),o.instance}registerHandlers(){[new Kr,new Yr,new Xr,new Zr,new eo,new to,new no,new ro].forEach(t=>{let n=t.getLanguageName();this.handlers.set(n.toLowerCase(),t),this.registerLanguageAliases(n,t)})}registerLanguageAliases(e,t){let n={"javascript/typescript":["javascript","typescript","node.js","nodejs"],java:["java","jdk","jvm"],python:["python","py"],go:["go","golang"],rust:["rust","rs"],php:["php"],ruby:["ruby","rb"],".net":["c#/.net","csharp","dotnet",".net","vb.net","f#"]},r=e.toLowerCase();n[r]&&n[r].forEach(s=>{this.handlers.set(s.toLowerCase(),t)})}getHandler(e){if(!e)return null;let t=e.toLowerCase();return this.handlers.get(t)||null}getSupportedLanguages(){return Array.from(new Set(Array.from(this.handlers.values()).map(e=>e.getLanguageName())))}getDirectoryDescriptions(e){let t=this.getHandler(e);return t?t.getDirectoryDescriptions():{src:"\u6E90\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u6240\u6709\u4E3B\u8981\u7684\u5E94\u7528\u7A0B\u5E8F\u4EE3\u7801",test:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",tests:"\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5",docs:"\u6587\u6863\u76EE\u5F55\uFF0C\u5305\u542B\u9879\u76EE\u6587\u6863\u548C\u8BF4\u660E",examples:"\u793A\u4F8B\u4EE3\u7801\u76EE\u5F55\uFF0C\u5305\u542B\u4F7F\u7528\u793A\u4F8B",bin:"\u53EF\u6267\u884C\u6587\u4EF6\u76EE\u5F55\uFF0C\u5305\u542B CLI \u547D\u4EE4\u811A\u672C",lib:"\u5E93\u6587\u4EF6\u76EE\u5F55",dist:"\u6784\u5EFA\u8F93\u51FA\u76EE\u5F55",build:"\u6784\u5EFA\u811A\u672C\u548C\u914D\u7F6E\u76EE\u5F55",config:"\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55"}}async detectVersions(e,t,n){let r=this.getHandler(e);return r?await r.detectVersions(t,n):{}}findEntryPoints(e,t,n){let r=this.getHandler(e);return r?r.findEntryPoints(t,n):[]}detectCodeStandards(e,t){let n=this.getHandler(e);return n?n.detectCodeStandards(t):[]}getCommonSourceExtensions(e){let t=this.getHandler(e);return t?t.getCommonSourceExtensions():[]}getCommonTestExtensions(e){let t=this.getHandler(e);return t?t.getCommonTestExtensions():[]}getCommonConfigFiles(e){let t=this.getHandler(e);return t?t.getCommonConfigFiles():[]}getDirectoryDescriptionsForLanguages(e){let t={};return e.forEach(n=>{let r=this.getDirectoryDescriptions(n);Object.assign(t,r)}),t}async detectVersionsForLanguages(e,t,n){let r={};for(let s of e){let i=await this.detectVersions(s,t,n);Object.assign(r,i)}return r}findEntryPointsForLanguages(e,t,n){let r=[];for(let s of e){let i=this.findEntryPoints(s,t,n);r.push(...i)}return[...new Set(r)]}detectCodeStandardsForLanguages(e,t){let n=[];for(let r of e){let s=this.detectCodeStandards(r,t);n.push(...s)}return[...new Set(n)]}},Wt=Os.getInstance()});var Sc={};j(Sc,{QuickProjectScanTool:()=>at,quickProjectScan:()=>zt,quickProjectScanTool:()=>Vt});import{existsSync as it}from"fs";import{globSync as yg}from"glob";async function zt(){return Cc.execute({})}var at,Cc,Vt,Fs=S(()=>{q();kr();Ba();Xa();tc();yc();at=class extends E{getDefinition(){return{name:"quickProjectScan",description:"Quickly scan the entire project structure, analyze directories, detect languages, and save project information to .nium/project/project.json. Use this when the user asks to explore or analyze the project structure.",input_schema:{type:"object",properties:{},required:[]}}}async execute(e){try{let t=[],n=process.cwd();t.push(`\u{1F50D} \u5F00\u59CB\u63A2\u7D22\u5DE5\u7A0B\u7ED3\u6784...
|
|
1286
|
+
`),t.push("\u{1F4C2} \u626B\u63CF\u9879\u76EE\u6587\u4EF6...");let r=$t(n,!0);t.push(` - \u5E94\u7528 ${r.length} \u6761\u5FFD\u7565\u89C4\u5219`);let s=Date.now(),i=yg("**/*",{nodir:!0,ignore:r,cwd:n}),a=((Date.now()-s)/1e3).toFixed(1);t.push(`\u627E\u5230 ${i.length} \u4E2A\u76F8\u5173\u6587\u4EF6 (\u8017\u65F6 ${a}s)
|
|
1287
|
+
`),t.push("\u{1F4CB} \u68C0\u6D4B\u9879\u76EE\u7C7B\u578B\u548C\u914D\u7F6E...");let c=Ga(n);c.length>0&&t.push(` - \u68C0\u6D4B\u5230\u9879\u76EE\u7C7B\u578B: ${c.join(", ")}`);let l=await Ha(n),g={name:l.name,version:l.version,description:l.description,dependencies:l.dependencies||{},devDependencies:l.devDependencies||{}};t.push(` - \u9879\u76EE\u540D\u79F0: ${g.name}`),t.push(` - \u7248\u672C: ${g.version}`),t.push(` - \u8BED\u8A00: ${l.primaryLanguage}`),l.buildTool&&t.push(` - \u6784\u5EFA\u5DE5\u5177: ${l.buildTool}`),t.push(""),t.push("\u{1F5C2}\uFE0F \u5206\u6790\u76EE\u5F55\u7ED3\u6784...");let p=this.analyzeDirectoryStructure(i);t.push(""),t.push("\u{1F310} \u68C0\u6D4B\u9879\u76EE\u7F16\u7A0B\u8BED\u8A00...");let u=this.detectProjectLanguages(i);t.push(`\u4E3B\u8981\u7F16\u7A0B\u8BED\u8A00: ${u.primaryLanguage||l.primaryLanguage||"\u672A\u77E5"}`),u.languages.length>0&&t.push(`\u68C0\u6D4B\u5230 ${u.languages.length} \u79CD\u7F16\u7A0B\u8BED\u8A00`),t.push(""),t.push("\u2699\uFE0F \u68C0\u6D4B\u8FD0\u884C\u65F6\u7248\u672C...");let m=await this.detectVersions(l,n);if(Object.keys(m).length>0)for(let[x,k]of Object.entries(m))t.push(` - ${x}: ${k}`);else t.push(" - \u672A\u68C0\u6D4B\u5230\u7248\u672C\u4FE1\u606F");t.push(""),t.push("\u{1F4D0} \u68C0\u6D4B\u4EE3\u7801\u89C4\u8303...");let d=this.detectCodeStandards(n,l.languages);d.length>0?t.push(` - \u68C0\u6D4B\u5230\u4EE3\u7801\u89C4\u8303: ${d.join(", ")}`):t.push(" - \u672A\u68C0\u6D4B\u5230\u4EE3\u7801\u89C4\u8303\u914D\u7F6E"),t.push(""),t.push("\u{1F4CB} \u5206\u6790\u9879\u76EE\u4F9D\u8D56...");let y=await this.analyzeDependencies(n,l.languages),w=Object.values(y).reduce((x,k)=>x+(k.dependencies?.length||0),0),h=Object.values(y).reduce((x,k)=>x+(k.conflicts?.length||0),0);t.push(` - \u4F9D\u8D56\u603B\u6570: ${w}`),h>0&&t.push(` - \u4F9D\u8D56\u51B2\u7A81: ${h}`),t.push(""),t.push("\u2705 \u9879\u76EE\u7ED3\u6784\u5206\u6790\u5B8C\u6210"),t.push(""),t.push("\u{1F4BE} \u4FDD\u5B58\u9879\u76EE\u57FA\u7840\u4FE1\u606F...");let b=this.buildProjectBasicInfo(g,p,i,u,l,m,d,y);try{Ka(b,n),t.push("\u2705 \u9879\u76EE\u57FA\u7840\u4FE1\u606F\u5DF2\u4FDD\u5B58\u81F3: .nium/project/"),t.push("")}catch(x){console.error(" \u274C \u4FDD\u5B58\u9879\u76EE\u4FE1\u606F\u5931\u8D25:",x),t.push(`\u26A0\uFE0F \u4FDD\u5B58\u9879\u76EE\u4FE1\u606F\u5931\u8D25: ${x instanceof Error?x.message:"\u672A\u77E5\u9519\u8BEF"}`),t.push("")}t.push("\u{1F4DD} \u66F4\u65B0\u6587\u4EF6\u4FE1\u606F\u5217\u8868...");let f=`${n}/.nium/project/files.jsonl`;try{let x=Date.now(),k=Za(i,f,n),O=((Date.now()-x)/1e3).toFixed(1);t.push("\u2705 \u6587\u4EF6\u4FE1\u606F\u5DF2\u66F4\u65B0\u81F3: .nium/project/files.jsonl"),t.push("");let M=ec(k);t.push(M),t.push("")}catch(x){console.error(" \u274C \u66F4\u65B0\u6587\u4EF6\u4FE1\u606F\u5931\u8D25:",x),t.push(`\u26A0\uFE0F \u66F4\u65B0\u6587\u4EF6\u4FE1\u606F\u5931\u8D25: ${x instanceof Error?x.message:"\u672A\u77E5\u9519\u8BEF"}`),t.push("")}let T=this.generateSummary(g,p,u,l);return t.push("\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"),t.push("\u9879\u76EE\u7ED3\u6784\u6982\u89C8"),t.push("\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"),t.push(T),t.push("\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"),t.push(""),t.join(`
|
|
1288
|
+
`)}catch(t){return this.formatError("Quick project scan",t)}}detectProjectLanguages(e){let t={".js":"JavaScript",".mjs":"JavaScript (ES Modules)",".cjs":"JavaScript (CommonJS)",".jsx":"React JavaScript",".ts":"TypeScript",".tsx":"React TypeScript",".java":"Java",".class":"Java",".jar":"Java","pom.xml":"Java (Maven)","build.gradle":"Java (Gradle)",".py":"Python","requirements.txt":"Python","setup.py":"Python","pyproject.toml":"Python",".c":"C",".cpp":"C++",".h":"C/C++",".hpp":"C++","CMakeLists.txt":"C/C++ (CMake)",".go":"Go","go.mod":"Go",".rs":"Rust","Cargo.toml":"Rust",".php":"PHP","composer.json":"PHP (Composer)",".rb":"Ruby",Gemfile:"Ruby",".cs":"C#",".vb":"Visual Basic","packages.config":".NET",".html":"HTML",".css":"CSS",".scss":"SCSS",".less":"Less",".json":"JSON",".xml":"XML",".yml":"YAML",".yaml":"YAML",".md":"Markdown"},n={};e.forEach(a=>{if(t[a]){n[t[a]]=(n[t[a]]||0)+1;return}let c=a.lastIndexOf(".");if(c>-1){let l=a.substring(c);t[l]&&(n[t[l]]=(n[t[l]]||0)+1)}});let r=Object.entries(n).map(([a,c])=>({language:a,count:c})).sort((a,c)=>c.count-a.count),[s]=r;return{primaryLanguage:s?.language||null,languages:r,totalSourceFiles:r.reduce((a,c)=>a+c.count,0)}}analyzeDirectoryStructure(e){let t={directories:new Set,sourceFiles:[],configFiles:[],docFiles:[],testFiles:[]},n=[".js",".mjs",".cjs",".jsx",".ts",".tsx",".java",".py",".c",".cpp",".cc",".cxx",".h",".hpp",".go",".rs",".php",".rb",".cs",".kt",".kts",".scala",".swift",".m",".mm"],r=[".json",".yaml",".yml",".toml",".ini",".xml",".properties"],s=["package.json","tsconfig.json","pom.xml","build.gradle","settings.gradle","gradle.properties","Cargo.toml","go.mod","requirements.txt","setup.py","pyproject.toml","composer.json","Gemfile",".env",".env.example"];return e.forEach(i=>{let a=i.split("/");if(a.length>1&&t.directories.add(a[0]),i.includes("test")||i.includes("spec")||i.startsWith("test/")||i.startsWith("tests/")||i.includes("__tests__")||i.endsWith(".test.js")||i.endsWith(".test.ts")||i.endsWith(".spec.js")||i.endsWith(".spec.ts")||i.endsWith("Test.java")||i.endsWith("Tests.java")){t.testFiles.push(i);return}let c=i.split("/").pop()||"",l=c.includes(".")?"."+c.split(".").pop():"";i.startsWith("src/")||i.startsWith("lib/")||i.startsWith("app/"),n.includes(l)&&t.sourceFiles.push(i),(r.includes(l)||s.includes(c))&&t.configFiles.push(i),(l===".md"||l===".txt"||l===".rst"||c==="README"||c==="CHANGELOG"||c==="LICENSE"||c==="CONTRIBUTING")&&t.docFiles.push(i)}),{directories:Array.from(t.directories).sort(),sourceFiles:t.sourceFiles.sort(),configFiles:t.configFiles.sort(),docFiles:t.docFiles.sort(),testFiles:t.testFiles.sort()}}async detectVersions(e,t){try{return await Wt.detectVersionsForLanguages(e.languages,t,e.configFiles)}catch{return{}}}detectCodeStandards(e,t){try{return Wt.detectCodeStandardsForLanguages(t,e)}catch{return[]}}async analyzeDependencies(e,t){let n={};try{for(let r of t){let s=Wt.getHandler(r);if(s){let i=await s.analyzeDependencies(e);n[r.toLowerCase()]=i}}}catch(r){console.error("\u4F9D\u8D56\u5206\u6790\u5931\u8D25:",r)}return n}analyzeCoreModules(e){let t=[],n=new Map;e.sourceFiles.forEach(s=>{let i=s.split("/");if(i.length>=2){let a=i.slice(0,2).join("/");n.has(a)||n.set(a,[]),n.get(a).push(s)}});let r={core:"\u6838\u5FC3\u4E1A\u52A1\u903B\u8F91",domain:"\u9886\u57DF\u6A21\u578B\u548C\u4E1A\u52A1\u89C4\u5219",business:"\u4E1A\u52A1\u903B\u8F91\u5C42",service:"\u670D\u52A1\u5C42",services:"\u670D\u52A1\u5C42",model:"\u6570\u636E\u6A21\u578B",models:"\u6570\u636E\u6A21\u578B",entity:"\u5B9E\u4F53\u7C7B",entities:"\u5B9E\u4F53\u7C7B",dao:"\u6570\u636E\u8BBF\u95EE\u5BF9\u8C61",repository:"\u6570\u636E\u4ED3\u5E93\u5C42",repositories:"\u6570\u636E\u4ED3\u5E93\u5C42",db:"\u6570\u636E\u5E93\u64CD\u4F5C",database:"\u6570\u636E\u5E93\u64CD\u4F5C",persistence:"\u6301\u4E45\u5316\u5C42",api:"API \u63A5\u53E3",rest:"REST API",controller:"\u63A7\u5236\u5668",controllers:"\u63A7\u5236\u5668",handler:"\u8BF7\u6C42\u5904\u7406\u5668",handlers:"\u8BF7\u6C42\u5904\u7406\u5668",endpoint:"\u7AEF\u70B9\u5B9A\u4E49",endpoints:"\u7AEF\u70B9\u5B9A\u4E49",route:"\u8DEF\u7531\u5B9A\u4E49",routes:"\u8DEF\u7531\u5B9A\u4E49",view:"\u89C6\u56FE\u5C42",views:"\u89C6\u56FE\u5C42",component:"\u7EC4\u4EF6",components:"\u7EC4\u4EF6",ui:"\u7528\u6237\u754C\u9762",page:"\u9875\u9762",pages:"\u9875\u9762",layout:"\u5E03\u5C40",layouts:"\u5E03\u5C40",template:"\u6A21\u677F",templates:"\u6A21\u677F",util:"\u5DE5\u5177\u51FD\u6570",utils:"\u5DE5\u5177\u51FD\u6570",helper:"\u8F85\u52A9\u51FD\u6570",helpers:"\u8F85\u52A9\u51FD\u6570",lib:"\u5E93\u6587\u4EF6",libs:"\u5E93\u6587\u4EF6",common:"\u516C\u5171\u6A21\u5757",shared:"\u5171\u4EAB\u6A21\u5757",config:"\u914D\u7F6E\u7BA1\u7406",configuration:"\u914D\u7F6E\u7BA1\u7406",settings:"\u8BBE\u7F6E\u7BA1\u7406",constant:"\u5E38\u91CF\u5B9A\u4E49",constants:"\u5E38\u91CF\u5B9A\u4E49",enum:"\u679A\u4E3E\u5B9A\u4E49",enums:"\u679A\u4E3E\u5B9A\u4E49",middleware:"\u4E2D\u95F4\u4EF6",middlewares:"\u4E2D\u95F4\u4EF6",interceptor:"\u62E6\u622A\u5668",interceptors:"\u62E6\u622A\u5668",filter:"\u8FC7\u6EE4\u5668",filters:"\u8FC7\u6EE4\u5668",guard:"\u5B88\u536B",guards:"\u5B88\u536B",client:"\u5BA2\u6237\u7AEF",clients:"\u5BA2\u6237\u7AEF",adapter:"\u9002\u914D\u5668",adapters:"\u9002\u914D\u5668",provider:"\u63D0\u4F9B\u5546",providers:"\u63D0\u4F9B\u5546",integration:"\u5916\u90E8\u96C6\u6210",integrations:"\u5916\u90E8\u96C6\u6210",auth:"\u8BA4\u8BC1\u6388\u6743",authentication:"\u8BA4\u8BC1",authorization:"\u6388\u6743",security:"\u5B89\u5168\u6A21\u5757",cli:"\u547D\u4EE4\u884C\u63A5\u53E3",cmd:"\u547D\u4EE4\u884C\u5DE5\u5177",script:"\u811A\u672C",scripts:"\u811A\u672C",tool:"\u5DE5\u5177",tools:"\u5DE5\u5177\u96C6",test:"\u6D4B\u8BD5",tests:"\u6D4B\u8BD5",spec:"\u6D4B\u8BD5\u89C4\u8303",mock:"\u6A21\u62DF\u6570\u636E",mocks:"\u6A21\u62DF\u6570\u636E",fixture:"\u6D4B\u8BD5\u5939\u5177",fixtures:"\u6D4B\u8BD5\u5939\u5177",type:"\u7C7B\u578B\u5B9A\u4E49",types:"\u7C7B\u578B\u5B9A\u4E49",interface:"\u63A5\u53E3\u5B9A\u4E49",interfaces:"\u63A5\u53E3\u5B9A\u4E49",schema:"\u6570\u636E\u7ED3\u6784\u5B9A\u4E49",schemas:"\u6570\u636E\u7ED3\u6784\u5B9A\u4E49",dto:"\u6570\u636E\u4F20\u8F93\u5BF9\u8C61",vo:"\u503C\u5BF9\u8C61",event:"\u4E8B\u4EF6",events:"\u4E8B\u4EF6",exception:"\u5F02\u5E38\u5904\u7406",exceptions:"\u5F02\u5E38\u5904\u7406",error:"\u9519\u8BEF\u5904\u7406",errors:"\u9519\u8BEF\u5904\u7406",validator:"\u9A8C\u8BC1\u5668",validators:"\u9A8C\u8BC1\u5668",decorator:"\u88C5\u9970\u5668",decorators:"\u88C5\u9970\u5668"};return n.forEach((s,i)=>{if(s.length>=2){let a=i.split("/").pop()||i,c=a.toLowerCase(),l=r[c]||`${a} \u6A21\u5757`;t.push({name:a.charAt(0).toUpperCase()+a.slice(1),description:l,files:s})}}),t.slice(0,10)}generateProjectStructureDoc(e,t,n,r,s,i,a){let c=new Date().toISOString(),l=this.analyzeCoreModules(t),g=Object.keys(i).length>0?Object.entries(i).map(([u,m])=>`**${u}**: ${m}`).join(`
|
|
1289
|
+
`):"\u6682\u65E0\u7248\u672C\u4FE1\u606F",p=a.length>0?a.map(u=>`- ${u}`).join(`
|
|
1111
1290
|
`):"\u6682\u65E0\u4EE3\u7801\u89C4\u8303\u914D\u7F6E";return`# ${e.name} - \u9879\u76EE\u7ED3\u6784\u6587\u6863
|
|
1112
1291
|
|
|
1113
1292
|
> \u6700\u540E\u66F4\u65B0: ${c}
|
|
@@ -1122,10 +1301,10 @@ ${n.map(s=>`\u2022 ${s}`).join(`
|
|
|
1122
1301
|
${s.buildTool?`**\u6784\u5EFA\u5DE5\u5177**: ${s.buildTool}`:""}
|
|
1123
1302
|
|
|
1124
1303
|
### \u8FD0\u884C\u65F6\u7248\u672C
|
|
1125
|
-
${
|
|
1304
|
+
${g}
|
|
1126
1305
|
|
|
1127
1306
|
### \u4EE3\u7801\u89C4\u8303
|
|
1128
|
-
${
|
|
1307
|
+
${p}
|
|
1129
1308
|
|
|
1130
1309
|
---
|
|
1131
1310
|
|
|
@@ -1140,7 +1319,7 @@ ${this.generateDirectoryTree(n)}
|
|
|
1140
1319
|
## \u7F16\u7A0B\u8BED\u8A00\u5206\u6790
|
|
1141
1320
|
|
|
1142
1321
|
### \u8BED\u8A00\u5206\u5E03
|
|
1143
|
-
${
|
|
1322
|
+
${r.languages.length>0?r.languages.map(u=>`- **${u.language}**: ${u.count} \u4E2A\u6587\u4EF6`).join(`
|
|
1144
1323
|
`):"\u6682\u65E0\u68C0\u6D4B\u5230\u7684\u7F16\u7A0B\u8BED\u8A00"}
|
|
1145
1324
|
|
|
1146
1325
|
---
|
|
@@ -1153,11 +1332,11 @@ ${this.generateDirectoryDescriptions(t.directories,s.languages)}
|
|
|
1153
1332
|
|
|
1154
1333
|
## \u6838\u5FC3\u6A21\u5757\u5206\u6790
|
|
1155
1334
|
|
|
1156
|
-
${l.length>0?l.map(
|
|
1335
|
+
${l.length>0?l.map(u=>`### ${u.name}
|
|
1157
1336
|
|
|
1158
|
-
${
|
|
1337
|
+
${u.description}
|
|
1159
1338
|
|
|
1160
|
-
**\u5305\u542B\u6587\u4EF6**: ${
|
|
1339
|
+
**\u5305\u542B\u6587\u4EF6**: ${u.files.length} \u4E2A`).join(`
|
|
1161
1340
|
|
|
1162
1341
|
`):"\u6682\u65E0\u6838\u5FC3\u6A21\u5757\u5206\u6790"}
|
|
1163
1342
|
|
|
@@ -1165,7 +1344,7 @@ ${g.description}
|
|
|
1165
1344
|
|
|
1166
1345
|
## \u6E90\u4EE3\u7801\u6587\u4EF6 (${t.sourceFiles.length} \u4E2A)
|
|
1167
1346
|
|
|
1168
|
-
${t.sourceFiles.length>0?t.sourceFiles.slice(0,50).map(
|
|
1347
|
+
${t.sourceFiles.length>0?t.sourceFiles.slice(0,50).map(u=>`- \`${u}\``).join(`
|
|
1169
1348
|
`)+(t.sourceFiles.length>50?`
|
|
1170
1349
|
|
|
1171
1350
|
*...\u8FD8\u6709 ${t.sourceFiles.length-50} \u4E2A\u6587\u4EF6*`:""):"\u6682\u65E0\u6E90\u4EE3\u7801\u6587\u4EF6"}
|
|
@@ -1174,14 +1353,14 @@ ${t.sourceFiles.length>0?t.sourceFiles.slice(0,50).map(g=>`- \`${g}\``).join(`
|
|
|
1174
1353
|
|
|
1175
1354
|
## \u914D\u7F6E\u6587\u4EF6 (${t.configFiles.length} \u4E2A)
|
|
1176
1355
|
|
|
1177
|
-
${t.configFiles.length>0?t.configFiles.map(
|
|
1356
|
+
${t.configFiles.length>0?t.configFiles.map(u=>`- \`${u}\``).join(`
|
|
1178
1357
|
`):"\u6682\u65E0\u914D\u7F6E\u6587\u4EF6"}
|
|
1179
1358
|
|
|
1180
1359
|
---
|
|
1181
1360
|
|
|
1182
1361
|
## \u6587\u6863\u6587\u4EF6 (${t.docFiles.length} \u4E2A)
|
|
1183
1362
|
|
|
1184
|
-
${t.docFiles.length>0?t.docFiles.slice(0,20).map(
|
|
1363
|
+
${t.docFiles.length>0?t.docFiles.slice(0,20).map(u=>`- \`${u}\``).join(`
|
|
1185
1364
|
`)+(t.docFiles.length>20?`
|
|
1186
1365
|
|
|
1187
1366
|
*...\u8FD8\u6709 ${t.docFiles.length-20} \u4E2A\u6587\u6863*`:""):"\u6682\u65E0\u6587\u6863\u6587\u4EF6"}
|
|
@@ -1190,7 +1369,7 @@ ${t.docFiles.length>0?t.docFiles.slice(0,20).map(g=>`- \`${g}\``).join(`
|
|
|
1190
1369
|
|
|
1191
1370
|
## \u6D4B\u8BD5\u6587\u4EF6 (${t.testFiles.length} \u4E2A)
|
|
1192
1371
|
|
|
1193
|
-
${t.testFiles.length>0?t.testFiles.slice(0,20).map(
|
|
1372
|
+
${t.testFiles.length>0?t.testFiles.slice(0,20).map(u=>`- \`${u}\``).join(`
|
|
1194
1373
|
`)+(t.testFiles.length>20?`
|
|
1195
1374
|
|
|
1196
1375
|
*...\u8FD8\u6709 ${t.testFiles.length-20} \u4E2A\u6D4B\u8BD5\u6587\u4EF6*`:""):"\u6682\u65E0\u6D4B\u8BD5\u6587\u4EF6"}
|
|
@@ -1200,11 +1379,11 @@ ${t.testFiles.length>0?t.testFiles.slice(0,20).map(g=>`- \`${g}\``).join(`
|
|
|
1200
1379
|
## \u4F9D\u8D56\u5173\u7CFB
|
|
1201
1380
|
|
|
1202
1381
|
### \u751F\u4EA7\u4F9D\u8D56
|
|
1203
|
-
${e.dependencies?Object.entries(e.dependencies).map(([
|
|
1382
|
+
${e.dependencies?Object.entries(e.dependencies).map(([u,m])=>`- **${u}**: ${m}`).join(`
|
|
1204
1383
|
`):"\u6682\u65E0\u751F\u4EA7\u4F9D\u8D56"}
|
|
1205
1384
|
|
|
1206
1385
|
### \u5F00\u53D1\u4F9D\u8D56
|
|
1207
|
-
${e.devDependencies?Object.entries(e.devDependencies).map(([
|
|
1386
|
+
${e.devDependencies?Object.entries(e.devDependencies).map(([u,m])=>`- **${u}**: ${m}`).join(`
|
|
1208
1387
|
`):"\u6682\u65E0\u5F00\u53D1\u4F9D\u8D56"}
|
|
1209
1388
|
|
|
1210
1389
|
---
|
|
@@ -1212,34 +1391,54 @@ ${e.devDependencies?Object.entries(e.devDependencies).map(([g,m])=>`- **${g}**:
|
|
|
1212
1391
|
## \u5FEB\u901F\u5BFC\u822A
|
|
1213
1392
|
|
|
1214
1393
|
### \u5165\u53E3\u6587\u4EF6
|
|
1215
|
-
${this.findEntryPoints(e,n,s).map(
|
|
1394
|
+
${this.findEntryPoints(e,n,s).map(u=>`- \`${u}\``).join(`
|
|
1216
1395
|
`)}
|
|
1217
1396
|
|
|
1218
1397
|
### \u6838\u5FC3\u6A21\u5757
|
|
1219
|
-
${this.findCoreModules(t.sourceFiles).map(
|
|
1398
|
+
${this.findCoreModules(t.sourceFiles).map(u=>`- \`${u}\``).join(`
|
|
1220
1399
|
`)}
|
|
1221
1400
|
|
|
1222
1401
|
---
|
|
1223
1402
|
|
|
1224
1403
|
**\u6587\u6863\u751F\u6210\u65F6\u95F4**: ${c}
|
|
1225
1404
|
**\u6587\u6863\u751F\u6210\u5DE5\u5177**: quickProjectScan \u5DE5\u5177
|
|
1226
|
-
`}generateDirectoryTree(e){let t={};e.forEach(s=>{let i=s.split("/"),a=t;i.forEach((c,l)=>{a[c]||(a[c]=l===i.length-1?null:{}),a[c]!==null&&(a=a[c])})});function n(s,i="",a=!0){let c=Object.entries(s),l="";return c.forEach(([p,u
|
|
1227
|
-
`,
|
|
1405
|
+
`}generateDirectoryTree(e){let t={};e.forEach(s=>{let i=s.split("/"),a=t;i.forEach((c,l)=>{a[c]||(a[c]=l===i.length-1?null:{}),a[c]!==null&&(a=a[c])})});function n(s,i="",a=!0){let c=Object.entries(s),l="";return c.forEach(([g,p],u)=>{let m=u===c.length-1,d=m?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",y=m?" ":"\u2502 ";l+=i+d+g+`
|
|
1406
|
+
`,p!==null&&typeof p=="object"&&(l+=n(p,i+y,m))}),l}let r=n(t);return r?r.trim():""}generateDirectoryDescriptions(e,t){let n=Wt.getDirectoryDescriptionsForLanguages(t);return e.map(r=>{let s=n[r]||"\u9879\u76EE\u76EE\u5F55";return`### \`${r}/\`
|
|
1228
1407
|
${s}`}).join(`
|
|
1229
1408
|
|
|
1230
|
-
`)}findEntryPoints(e,t,n){let
|
|
1409
|
+
`)}findEntryPoints(e,t,n){let r=[];n.entryPoints&&n.entryPoints.length>0&&r.push(...n.entryPoints),e.main&&r.push(e.main),e.bin&&(typeof e.bin=="string"?r.push(e.bin):r.push(...Object.values(e.bin)));let s=process.cwd(),i=Wt.findEntryPointsForLanguages(n.languages,t,s);return r.push(...i),[...new Set(r)]}findCoreModules(e){let t=new Set;return e.forEach(n=>{let r=n.match(/^src\/([^\/]+)\//);r&&t.add(`src/${r[1]}/`)}),Array.from(t).sort()}buildProjectBasicInfo(e,t,n,r,s,i,a,c){let l=Ya(r.languages),p=this.analyzeCoreModules(t).map(b=>({name:b.name,description:b.description,fileCount:b.files.length})),u;s.primaryLanguage.includes("JavaScript")||s.primaryLanguage.includes("TypeScript")?it("package-lock.json")?u="npm":it("yarn.lock")?u="yarn":it("pnpm-lock.yaml")?u="pnpm":u="npm":s.primaryLanguage.includes("Python")?it("poetry.lock")?u="poetry":it("Pipfile.lock")?u="pipenv":u="pip":s.primaryLanguage.includes("Java")?it("pom.xml")?u="maven":it("build.gradle")&&(u="gradle"):s.primaryLanguage.includes("Rust")?u="cargo":s.primaryLanguage.includes("Go")?u="go modules":s.primaryLanguage.includes("PHP")?u="composer":s.primaryLanguage.includes("Ruby")&&(u="bundler");let m={...e.dependencies||{}},d={...e.devDependencies||{}},y=Object.keys(m).length,w=Object.keys(d).length;if(c)for(let[b,f]of Object.entries(c))f.dependencies&&f.dependencies.forEach(T=>{let x=T.groupId&&T.artifactId?`${T.groupId}:${T.artifactId}`:T.name||"";x&&T.version&&(T.scope&&T.scope.toLowerCase().includes("test")?d[x]||(d[x]=T.version,w++):m[x]||(m[x]=T.version,y++))});return{projectName:e.name,version:e.version,description:e.description||"",primaryLanguage:r.primaryLanguage||s.primaryLanguage,languages:l,buildTool:s.buildTool,packageManager:u,runtime:s.primaryLanguage.includes("JavaScript")||s.primaryLanguage.includes("TypeScript")?"Node.js":s.primaryLanguage.includes("Java")?"JVM":s.primaryLanguage.includes("Python")?"Python":void 0,fileStats:{totalFiles:n.length,sourceFiles:t.sourceFiles.length,configFiles:t.configFiles.length,docFiles:t.docFiles.length,testFiles:t.testFiles.length},dependencies:m,devDependencies:d,dependencyCount:{production:y,development:w},detailedDependencies:c,runtimeVersions:Object.keys(i).length>0?i:void 0,codeStandards:a,entryPoints:this.findEntryPoints(e,n,s),configFiles:t.configFiles,coreModules:p.length>0?p:void 0,lastScanDate:new Date().toISOString()}}generateSummary(e,t,n,r){return`
|
|
1231
1410
|
\u{1F4E6} \u9879\u76EE: ${e.name} (v${e.version})
|
|
1232
|
-
\u{1F310} \u4E3B\u8981\u8BED\u8A00: ${
|
|
1233
|
-
${
|
|
1411
|
+
\u{1F310} \u4E3B\u8981\u8BED\u8A00: ${r.primaryLanguage}
|
|
1412
|
+
${r.buildTool?`\u{1F527} \u6784\u5EFA\u5DE5\u5177: ${r.buildTool}`:""}
|
|
1234
1413
|
\u{1F4C1} \u4E3B\u8981\u76EE\u5F55: ${t.directories.join(", ")}
|
|
1235
1414
|
\u{1F4DD} \u6E90\u6587\u4EF6: ${t.sourceFiles.length} \u4E2A
|
|
1236
1415
|
\u2699\uFE0F \u914D\u7F6E\u6587\u4EF6: ${t.configFiles.length} \u4E2A
|
|
1237
1416
|
\u{1F4DA} \u6587\u6863\u6587\u4EF6: ${t.docFiles.length} \u4E2A
|
|
1238
1417
|
\u{1F9EA} \u6D4B\u8BD5\u6587\u4EF6: ${t.testFiles.length} \u4E2A
|
|
1239
|
-
`}formatAction(e){return"quickProjectScan()"}formatObservation(e){return String(e)}},
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1418
|
+
`}formatAction(e){return"quickProjectScan()"}formatObservation(e){return String(e)}},Cc=new at;Vt=Cc});var Us={};j(Us,{FINISH_TOOL:()=>xg,FinishTool:()=>oo,extractFinishInfo:()=>Ns,finish:()=>Cg,finishTool:()=>Sg,isFinishResult:()=>wg,isFinishTool:()=>_s});function Cg(o){return js.execute(o)}function _s(o){return o==="finish"}function Ns(o){if(!o||!o.function||o.function.name!=="finish")return null;try{let e=JSON.parse(o.function.arguments);return{answer:e.answer||"",success:e.success!==void 0?e.success:!0}}catch{return null}}function wg(o){return o&&typeof o=="object"&&o.completed===!0&&typeof o.answer=="string"}var oo,js,Sg,xg,so=S(()=>{q();oo=class extends E{getDefinition(){return{name:"finish",description:`Call this tool when you have completed the task and want to provide the final answer.
|
|
1419
|
+
|
|
1420
|
+
IMPORTANT: This is the RECOMMENDED way to signal task completion.
|
|
1421
|
+
|
|
1422
|
+
You should call this tool when:
|
|
1423
|
+
- You have successfully completed all requested actions
|
|
1424
|
+
- You have gathered all necessary information to answer the user's question
|
|
1425
|
+
- You have verified that your work meets the requirements
|
|
1426
|
+
- You are ready to provide a comprehensive summary
|
|
1427
|
+
|
|
1428
|
+
The answer should be detailed and include:
|
|
1429
|
+
- What was accomplished or discovered
|
|
1430
|
+
- Key results, files modified, or actions taken
|
|
1431
|
+
- Any important findings or observations
|
|
1432
|
+
- Recommendations or next steps (if applicable)
|
|
1433
|
+
|
|
1434
|
+
Example usage:
|
|
1435
|
+
finish({
|
|
1436
|
+
answer: "Successfully implemented the user authentication system. Created 3 new files: UserController.java, UserService.java, and SecurityConfig.java. Implemented JWT-based authentication with role-based access control. All tests are passing.",
|
|
1437
|
+
success: true
|
|
1438
|
+
})`,input_schema:{type:"object",properties:{answer:{type:"string",description:"Comprehensive summary of what was accomplished, including key results and any important details"},success:{type:"boolean",description:"Whether the task completed successfully (defaults to true)",default:!0}},required:["answer"]}}}execute(e){return{completed:!0,answer:e.answer,success:e.success!==void 0?e.success:!0}}formatAction(e){let t=e.success!==!1?"\u6210\u529F\u5B8C\u6210":"\u5B8C\u6210\uFF08\u6709\u95EE\u9898\uFF09",n=e.answer.length>50?`${e.answer.substring(0,50)}...`:e.answer;return`finish(status=${t}, answer="${n}")`}formatObservation(e){return"\u4EFB\u52A1\u5DF2\u5B8C\u6210"}shouldPrintObservation(e){return!1}},js=new oo;Sg=js,xg=js.getDefinition()});var zs={};j(zs,{executePlanTask:()=>bg,getGlobalSession:()=>vg,resumePlanTask:()=>Tg,setGlobalSession:()=>Ws});import P from"chalk";function Ws(o){N=o}function vg(){return N}async function bg(o,e=1,t={}){let n=new Fe,r=new je(n),s=new _e(n,r),i=new Ne,{callModelAPI:a}=await Promise.resolve().then(()=>(Ce(),jt)),{AnchorInjector:c}=await Promise.resolve().then(()=>(zn(),xs)),l=new c(o,a),g=Ht(),p={useLLMDisclosure:t.useLLMDisclosure!==void 0?t.useLLMDisclosure:!0,useLLMSummary:t.useLLMSummary!==void 0?t.useLLMSummary:!0,verbose:t.verbose||!1},u=f=>{N?N.log(f):console.log(f)},m=f=>{N?N.info(f):console.log(P.blue(f))},d=f=>{N?N.success(f):console.log(P.green(f))},y=f=>{N?N.warning(f):console.log(P.yellow(f))},w=f=>{N?N.error(f):console.log(P.red(f))},h=" ".repeat(e-1),b=new io({log:u,info:m,success:d,warning:y,error:w});try{let f=await import("fs"),T=await import("path");try{let M=T.join(process.cwd(),".nium/project/project.json");if(f.existsSync(M)){let I=f.statSync(M);(Date.now()-I.mtimeMs)/(1e3*60*60)>24&&y("\u26A0\uFE0F \u9879\u76EE\u7ED3\u6784\u6587\u6863\u5DF2\u8D85\u8FC724\u5C0F\u65F6\uFF0C\u5EFA\u8BAE\u66F4\u65B0")}else{m("\u{1F4CB} \u9996\u6B21\u6267\u884C\u4EFB\u52A1\uFF0C\u6B63\u5728\u626B\u63CF\u9879\u76EE\u7ED3\u6784...");let{quickProjectScan:I}=await Promise.resolve().then(()=>(Fs(),Sc));await I(),d(`\u2705 \u9879\u76EE\u7ED3\u6784\u626B\u63CF\u5B8C\u6210
|
|
1439
|
+
`)}}catch{y("\u9879\u76EE\u7ED3\u6784\u626B\u63CF\u5931\u8D25\uFF0C\u5C06\u7EE7\u7EED\u6267\u884C\u4EFB\u52A1")}u(""),u(`${h}${"\u2550".repeat(60-e*2)}`),m(`${h}\u{1F4CB} \u5F00\u59CB\u89C4\u5212\u4EFB\u52A1 (\u5D4C\u5957\u5C42\u7EA7: ${e})`),u(`${h}${"\u2550".repeat(60-e*2)}`),u("");let x=g.getAllSubAgents(),k=await Rn(o,x);n.initializeTask(o,k),k.taskId&&ft(k.taskId);let O=kg(Dn(k),e);u(O),u(""),b.showTaskStart(o,k.tasks.length,e);for(let M=0;M<k.tasks.length;M++){let I=k.tasks[M],B=I.step;b.showStepProgress(B,k.tasks.length,I,e),n.plan.currentStep=B,k.taskId&&await nt(k.taskId,B,"in_progress");try{let Q=xc(I,g),V=await s.buildIsolatedContext(B,I.description,Q?.prompt||"",p.useLLMDisclosure,I.allowedTools);Q?await wc(B,I.description,Q,V,n,i,g,p,{log:u,info:m,success:d,warning:y,error:w},I.allowedTools):await vc(I.description,V,n,{log:u,info:m},I.allowedTools),b.showStepComplete(B,k.tasks.length,I,e),k.taskId&&await nt(k.taskId,B,"completed")}catch(Q){let V=Q instanceof Error?Q.message:String(Q);throw b.showStepError(B,k.tasks.length,V,e),y(`${h}\u4E2D\u6B62\u540E\u7EED\u6B65\u9AA4\u6267\u884C`),n.recordStepCompletion(B,`\u5931\u8D25: ${V}`,{success:!1,error:V}),Q}}return b.showTaskComplete(k.tasks.length,k.tasks.length,e),ht(),{success:!0,taskId:k.taskId,completedSteps:k.tasks.length,plan:k,planMarkdown:k.markdown,tasks:k.tasks}}catch(f){ht();let T=f instanceof Error?f.message:String(f);throw w(`${h}\u274C \u89C4\u5212\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${T}`),f}}async function Tg(o,e=0,t={}){let{loadTaskPlan:n}=await Promise.resolve().then(()=>(be(),Oe)),r=n(o);if(!r)throw new Error(`\u65E0\u6CD5\u52A0\u8F7D\u4EFB\u52A1\u8BA1\u5212: ${o}`);let s=new Fe,i=new je(s),a=new _e(s,i),c=new Ne,l=Ht(),g={useLLMDisclosure:t.useLLMDisclosure!==void 0?t.useLLMDisclosure:!0,useLLMSummary:t.useLLMSummary!==void 0?t.useLLMSummary:!0,verbose:t.verbose||!1},p=f=>{N?N.log(f):console.log(f)},u=f=>{N?N.info(f):console.log(P.blue(f))},m=f=>{N?N.success(f):console.log(P.green(f))},d=f=>{N?N.warning(f):console.log(P.yellow(f))},y=f=>{N?N.error(f):console.log(P.red(f))};p(P.cyan(`[\u4EFB\u52A1\u6062\u590D] \u6B63\u5728\u6062\u590D\u4EFB\u52A1: ${o}`)),p(P.gray(`\u4ECE\u6B65\u9AA4 ${e||1} \u5F00\u59CB\u6267\u884C`));let w=1,h="",b=new io({log:p,info:u,success:m,warning:d,error:y});try{s.initializeTask(r.taskId,r),r.taskId&&ft(r.taskId),p(""),p(P.cyan("\u2550".repeat(60))),u("\u{1F4CB} \u6062\u590D\u4EFB\u52A1\u6267\u884C"),p(P.cyan("\u2550".repeat(60))),p(""),b.showTaskStart(r.taskId,r.tasks.length,w);let f=e>0?e-1:0;for(let T=f;T<r.tasks.length;T++){let x=r.tasks[T],k=x.step;if(b.showStepProgress(k,r.tasks.length,x,w),s.plan.currentStep=k,r.taskId){let{updateTaskStatus:O}=await Promise.resolve().then(()=>(be(),Oe));await O(r.taskId,k,"in_progress")}try{let O=xc(x,l),M=await a.buildIsolatedContext(k,x.description,O?.prompt||"",g.useLLMDisclosure,x.allowedTools);if(O?await wc(k,x.description,O,M,s,c,l,g,{log:p,info:u,success:m,warning:d,error:y},x.allowedTools):await vc(x.description,M,s,{log:p,info:u},x.allowedTools),b.showStepComplete(k,r.tasks.length,x,w),r.taskId){let{updateTaskStatus:I}=await Promise.resolve().then(()=>(be(),Oe));await I(r.taskId,k,"completed")}}catch(O){let M=O instanceof Error?O.message:String(O);throw b.showStepError(k,r.tasks.length,M,w),d(`${h}\u4E2D\u6B62\u540E\u7EED\u6B65\u9AA4\u6267\u884C`),s.recordStepCompletion(k,`\u5931\u8D25: ${M}`,{success:!1,error:M}),O}}return b.showTaskComplete(r.tasks.length,r.tasks.length,w),ht(),{success:!0,taskId:r.taskId,completedSteps:r.tasks.length-f,resumedFrom:e||1}}catch(f){ht();let T=f instanceof Error?f.message:String(f);throw y(`${h}\u274C \u4EFB\u52A1\u6062\u590D\u6267\u884C\u5931\u8D25: ${T}`),f}}function kg(o,e){return e<=1?o:o.split(`
|
|
1440
|
+
`).map(r=>{if(r.trim().startsWith("#")){let s=r.match(/^#+/)?.[0].length||0,i=Math.min(s+e-1,6),a="#".repeat(i);return r.replace(/^#+/,a)}return r}).join(`
|
|
1441
|
+
`)}function xc(o,e){return o.subAgent&&o.subAgent!=="default"?e.getSubAgent(o.subAgent):null}async function wc(o,e,t,n,r,s,i,a,c,l){let{log:g,info:p,error:u}=c,m=Date.now();p(`\u{1F527} \u4F7F\u7528\u5B50\u667A\u80FD\u4F53: ${t.name}`),g(P.gray(`\u63CF\u8FF0: ${t.description}`)),l&&l.length>0&&g(P.gray(`\u6CE8\u610F: \u5B50\u667A\u80FD\u4F53 ${t.name} \u4E0D\u53D7\u6B65\u9AA4\u5DE5\u5177\u9650\u5236\u5F71\u54CD`)),g("");try{let{SYSTEM_PROMPT:d}=await Promise.resolve().then(()=>(tt(),us)),y=[{role:"system",content:d},...n.filter(b=>b.role!=="system"),...n.filter(b=>b.role==="system"&&b!==n[0])],w=await bc(y,e,c,void 0,t);await Pg(o,w,r,s,a,c);let h=Date.now()-m;i.recordAgentPerformance(t.name,!0,h)}catch(d){let y=Date.now()-m;throw i.recordAgentPerformance(t.name,!1,y),d}}async function vc(o,e,t,n,r){let{log:s,info:i}=n;i("\u{1F916} \u4F7F\u7528\u9ED8\u8BA4React\u667A\u80FD\u4F53"),r&&r.length>0&&s(P.gray(`\u5DE5\u5177\u9650\u5236: ${r.join(", ")}`)),s("");let{SYSTEM_PROMPT:a}=await Promise.resolve().then(()=>(tt(),us)),c=[{role:"system",content:a},...e.filter(l=>l.role!=="system"),...e.filter(l=>l.role==="system")];await bc(c,o,n,r)}async function bc(o,e,t,n,r=null){let{log:s,error:i}=t,{MODEL:a}=await Promise.resolve().then(()=>(ae(),yt)),{callModelAPI:c}=await Promise.resolve().then(()=>(Ce(),jt)),{isThinkTool:l,extractThought:g}=await Promise.resolve().then(()=>(An(),os)),{isFinishTool:p,extractFinishInfo:u}=await Promise.resolve().then(()=>(so(),Us)),{getToolDefinitions:m}=await Promise.resolve().then(()=>(Ot(),Vs)),{tools:d,toolInstances:y,extractToolResult:w}=await Promise.resolve().then(()=>(Ee(),Gn)),{saveSession:h}=await Promise.resolve().then(()=>(De(),ji)),{logDebug:b,logWarn:f}=await Promise.resolve().then(()=>(Y(),Ao)),{AnchorInjector:T}=await Promise.resolve().then(()=>(zn(),xs)),x=[...o],k=0,O=50,M=0,I=new T(e,c),B=m(),Q=n&&n.length>0?B.filter(V=>n.includes(V.name)):B;for(n&&n.length>0&&b(`\u672C\u6B65\u9AA4\u53EF\u7528\u5DE5\u5177: ${Q.map(V=>V.name).join(", ")}`);k<O;){k++,b(`Loop iteration ${k}`);try{let V=await I.injectAnchors({taskDescription:e,iterations:k,messages:x,lastSemanticCheckIteration:M,callModelAPI:c}),{messages:L,lastSemanticCheckIteration:re}=V;x=L,M=re,h(x,e);let te=await c({model:a(),messages:x,temperature:.1,tools:Q}),Xt=te.choices[0].message.tool_calls;if(te.choices[0].finish_reason==="stop"){let{content:F}=te.choices[0].message;if(F&&F.trim()){if(r?.finalAnswerCallback)try{await r.finalAnswerCallback(F)}catch(Ie){let{logError:Ae}=await Promise.resolve().then(()=>(Y(),Ao));Ae(`Error in finalAnswerCallback: ${Ie}`)}s(P.green("\u4EFB\u52A1\u5B8C\u6210:")),s(F),s("")}break}if(!Xt||Xt.length===0){let{content:F}=te.choices[0].message;F&&F.trim()&&(s(P.yellow(F)),s(""));continue}let z=Xt[0],we=z.function.name;if(n&&n.length>0&&!n.includes(we)){let F=`Error: \u5DE5\u5177 '${we}' \u672A\u5728\u672C\u6B65\u9AA4\u7684\u6388\u6743\u5217\u8868\u4E2D\u3002\u5141\u8BB8\u4F7F\u7528\u7684\u5DE5\u5177: ${n.join(", ")}`;i(F),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:F});continue}let cr;try{cr=JSON.parse(z.function.arguments)}catch{i(`\u89E3\u6790\u5DE5\u5177\u53C2\u6570\u5931\u8D25: ${z.function.arguments}`),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:"Error: Invalid JSON arguments"});continue}if(l(we)){let F=g(z);F&&(s(P.cyan(`\u{1F4AD} Think: ${F}`)),s("")),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:"Noted. Continue with your action."});continue}if(p(we)){let F=u(z);if(F){let{answer:Ie,success:Ae}=F;if(r?.finalAnswerCallback)try{await r.finalAnswerCallback(Ie)}catch(il){f(`Error in finalAnswerCallback: ${il}`)}let sl=Ae?"\u2705":"\u26A0\uFE0F";s(P.green(`${sl} \u4EFB\u52A1\u5B8C\u6210 (\u901A\u8FC7 finish \u5DE5\u5177):`)),s(Ie),s(""),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:"Task completed successfully."}),x.push({role:"assistant",content:Ie});break}}if(!d[we]){let F=`Error: Unknown tool '${we}'`;i(F),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:F});continue}let lr=m().find(F=>F.name===we);if(lr&&lr.input_schema&&lr.input_schema.required){let Ie=(lr.input_schema.required||[]).filter(Ae=>cr[Ae]===void 0);if(Ie.length>0){let Ae=`Error: Missing required parameters: ${Ie.join(", ")}`;i(Ae),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:Ae});continue}}let ut=y[we],tl=ut?ut.formatAction(cr):`${we}()`;s(P.blue(`\u{1F527} \u884C\u52A8: ${tl}`)),s("");let ur=await d[we](cr),nl=w(ur),rl=ut?ut.shouldPrintObservation(ur):!0,ol=ut?ut.formatObservation(ur):String(ur);rl&&(s(P.yellow(`\u{1F4CA} \u89C2\u5BDF: ${ol}`)),s("")),x.push({role:"assistant",content:null,tool_calls:[z]}),x.push({role:"tool",tool_call_id:z.id,content:String(nl)}),h(x,e)}catch(V){throw i(`\u9519\u8BEF: ${V.message}`),h(x,e),V}}if(k>=O)throw i("\u9519\u8BEF: \u5DF2\u8FBE\u5230\u6700\u5927\u8FED\u4EE3\u6B21\u6570"),h(x,e),new Error("Maximum iterations reached");return x}async function Pg(o,e,t,n,r,s){let{info:i,log:a}=s,c;r.useLLMSummary?c=await n.extractSummaryWithLLM(e):c=await n.extractSummary(e);let l=n.extractMetadata(e);l.success=!0,t.recordStepCompletion(o,c,l),r.verbose&&(i(`\u6B65\u9AA4 ${o} \u6458\u8981\u5DF2\u8BB0\u5F55\u5230\u5168\u5C40\u4E0A\u4E0B\u6587`),a(""),a(P.gray("\u2500\u2500\u2500 \u6B65\u9AA4\u6267\u884C\u6458\u8981 \u2500\u2500\u2500")),a(P.gray(`\u6458\u8981: ${c}`)),a(P.gray(`\u5DE5\u5177: ${l.toolsUsed.join(", ")}`)),a(P.gray(`\u6587\u4EF6: ${l.filesAccessed.join(", ")}`)),a(P.gray(`\u8FED\u4EE3: ${l.iterations} \u6B21`)))}var io,N,ao=S(()=>{be();co();De();ws();io=class{startTime;stepStartTime=null;log;info;success;warning;error;constructor(e){this.startTime=Date.now(),this.log=e.log,this.info=e.info,this.success=e.success,this.warning=e.warning,this.error=e.error}showTaskStart(e,t,n=1){let r=" ".repeat(n-1);this.log(""),this.log(P.cyan(`${r}\u2554${"\u2550".repeat(58-n*2)}\u2557`)),this.log(P.cyan(`${r}\u2551`)+P.bold.white(" \u{1F680} \u5F00\u59CB\u6267\u884C\u4EFB\u52A1\u8BA1\u5212")+P.cyan(` (\u5171${t}\u6B65)`.padEnd(58-n*2-13))+P.cyan("\u2551")),this.log(P.cyan(`${r}\u255A${"\u2550".repeat(58-n*2)}\u255D`)),this.log("")}showStepProgress(e,t,n,r=1){this.stepStartTime=Date.now();let s=" ".repeat(r-1),i=Math.round(e/t*100),a=this.createProgressBar(i,30);this.log(""),this.log(P.blue(`${s}\u250C${"\u2500".repeat(58-r*2)}\u2510`)),this.log(P.blue(`${s}\u2502`)+` \u6B65\u9AA4 ${e}/${t} (${i}%)`.padEnd(60-r*2)+P.blue("\u2502")),this.log(P.blue(`${s}\u2502`)+` ${a}`.padEnd(60-r*2)+P.blue("\u2502")),this.log(P.blue(`${s}\u2502`)+P.cyan(` \u{1F4CC} ${n.description}`.substring(0,58-r*2)).padEnd(60-r*2)+P.blue("\u2502")),this.log(P.blue(`${s}\u2502`)+P.gray(` \u{1F916} \u667A\u80FD\u4F53: ${n.subAgent}`.substring(0,58-r*2)).padEnd(60-r*2)+P.blue("\u2502")),this.log(P.blue(`${s}\u2514${"\u2500".repeat(58-r*2)}\u2518`)),this.log("")}showStepComplete(e,t,n,r=1){let s=" ".repeat(r-1),i=this.stepStartTime?this.formatDuration(Date.now()-this.stepStartTime):"",a=Math.round(e/t*100);this.success(`${s}\u2705 \u6B65\u9AA4 ${e}/${t} \u5B8C\u6210${P.gray(` (${i})`)}`),this.log("")}showTaskComplete(e,t,n=1){let r=" ".repeat(n-1),s=this.formatDuration(Date.now()-this.startTime),i=Math.round(e/t*100);this.log(""),this.log(P.green(`${r}\u2554${"\u2550".repeat(58-n*2)}\u2557`)),this.log(P.green(`${r}\u2551`)+P.bold.white(" \u{1F389} \u4EFB\u52A1\u6267\u884C\u5B8C\u6210!")+P.green("".padEnd(58-n*2-12))+P.green("\u2551")),this.log(P.green(`${r}\u2551`)+` \u5B8C\u6210\u8FDB\u5EA6: ${e}/${t} (${i}%)`.padEnd(60-n*2)+P.green("\u2551")),this.log(P.green(`${r}\u2551`)+` \u603B\u8017\u65F6: ${s}`.padEnd(60-n*2)+P.green("\u2551")),this.log(P.green(`${r}\u255A${"\u2550".repeat(58-n*2)}\u255D`)),this.log("")}showStepError(e,t,n,r=1){let s=" ".repeat(r-1);this.log(""),this.error(`${s}\u274C \u6B65\u9AA4 ${e}/${t} \u6267\u884C\u5931\u8D25`),this.error(`${s} \u9519\u8BEF: ${n.substring(0,100)}`),this.log("")}createProgressBar(e,t=30){let n=Math.round(e/100*t),r=t-n;return`${P.green("\u2588".repeat(n))+P.gray("\u2591".repeat(r))} ${e}%`}formatDuration(e){if(e<1e3)return`${e}ms`;if(e<6e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.floor(e/6e4),n=(e%6e4/1e3).toFixed(0);return`${t}m ${n}s`}},N=null});import $g from"chalk";async function Bn(o){return await Tc.execute(o)}var Me,Tc,qn,Hs=S(()=>{q();Me=class o extends E{static nestingLevel=0;static MAX_NESTING_LEVEL=2;getDefinition(){let e=o.nestingLevel,t=o.MAX_NESTING_LEVEL,n="USE THIS TOOL FIRST for COMPLEX tasks! This is your PRIMARY tool for handling multi-step, cross-component work.";return e===t-1?n="USE THIS TOOL SPARINGLY for VERY COMPLEX sub-tasks! This is your last level of nesting.":e>=t&&(n="DO NOT USE THIS TOOL - maximum nesting level reached!"),{name:"plan",description:`${n}
|
|
1243
1442
|
|
|
1244
1443
|
IDEAL USE CASES:
|
|
1245
1444
|
- Building new features that span multiple files or components
|
|
@@ -1254,14 +1453,19 @@ AUTOMATIC ADVANTAGES:
|
|
|
1254
1453
|
- Intelligent sub-agent assignment for each step
|
|
1255
1454
|
- Context preservation across all operations
|
|
1256
1455
|
- Comprehensive execution tracking
|
|
1257
|
-
- Maximum
|
|
1456
|
+
- Maximum ${t}-level nesting support for complex sub-tasks
|
|
1258
1457
|
|
|
1259
1458
|
AVOID FOR:
|
|
1260
1459
|
- Single-file edits or queries
|
|
1261
1460
|
- Simple read/write operations
|
|
1262
1461
|
- Individual command execution
|
|
1462
|
+
- When already at maximum nesting level
|
|
1463
|
+
- For small sub-tasks within a larger plan
|
|
1464
|
+
|
|
1465
|
+
RECOMMENDATION BASED ON CURRENT NESTING LEVEL (${e}/${t}):
|
|
1466
|
+
${e===0?"- Feel free to use this tool for complex tasks.":e===t-1?"- Use this tool only if absolutely necessary for very complex sub-tasks.":"- DO NOT use this tool - maximum nesting level reached!"}
|
|
1263
1467
|
|
|
1264
|
-
When you're uncertain if a task needs planning, default to using
|
|
1468
|
+
When you're uncertain if a task needs planning, default to using regular tools directly for sub-tasks!`,input_schema:{type:"object",properties:{task:{type:"string",description:"Detailed description of the complex task to plan and execute. Be specific about the goals and requirements."},planOnly:{type:"boolean",description:"If true, only generate the plan without executing it. The plan will be saved to ./.nium/tasks/ directory for later execution. Default: false"}},required:["task"]}}}async execute(e){let{task:t,planOnly:n=!1}=e;if(n)try{let{generateTaskPlan:r}=await Promise.resolve().then(()=>(be(),Oe)),{getSubAgentManager:s}=await Promise.resolve().then(()=>(co(),kc)),a=s().getAllSubAgents(),c=await r(t,a),l=`\u2705 \u4EFB\u52A1\u89C4\u5212\u5DF2\u751F\u6210\uFF08\u4EC5\u89C4\u5212\u6A21\u5F0F\uFF09
|
|
1265
1469
|
|
|
1266
1470
|
`;return l+=`**\u4EFB\u52A1 ID**: ${c.taskId}
|
|
1267
1471
|
`,l+=`**\u603B\u6B65\u9AA4\u6570**: ${c.tasks.length}
|
|
@@ -1272,19 +1476,19 @@ When you're uncertain if a task needs planning, default to using this tool - it
|
|
|
1272
1476
|
`,l+=`- JSON: ./.nium/tasks/${c.taskId}.json
|
|
1273
1477
|
|
|
1274
1478
|
`,l+=`**\u6267\u884C\u6B65\u9AA4**:
|
|
1275
|
-
`,c.tasks.forEach((p
|
|
1479
|
+
`,c.tasks.forEach((g,p)=>{l+=`${p+1}. ${g.description} [${g.subAgent}]
|
|
1276
1480
|
`}),l+=`
|
|
1277
|
-
\u{1F4A1} \u63D0\u793A: \u4F7F\u7528 todo \u5DE5\u5177\u7684 resume \u529F\u80FD\u6765\u6267\u884C\u6B64\u8BA1\u5212`,this.createToolResult(l,l,!0)}catch(
|
|
1481
|
+
\u{1F4A1} \u63D0\u793A: \u4F7F\u7528 todo \u5DE5\u5177\u7684 resume \u529F\u80FD\u6765\u6267\u884C\u6B64\u8BA1\u5212`,this.createToolResult(l,l,!0)}catch(r){let s=r instanceof Error?r.message:String(r);return this.createToolResult(`Error: Failed to generate plan - ${s}`,`Error: Failed to generate plan - ${s}`,!0)}if(o.nestingLevel>=o.MAX_NESTING_LEVEL)return this.createToolResult(`Error: Maximum nesting level (${o.MAX_NESTING_LEVEL}) reached. Please use regular tools directly instead of the plan tool.`,`Error: Maximum nesting level (${o.MAX_NESTING_LEVEL}) reached. Please use regular tools directly instead of the plan tool.`,!0);o.nestingLevel++;try{let r;try{r=await(await Promise.resolve().then(()=>(ao(),zs))).executePlanTask(t,o.nestingLevel)}catch{console.log($g.yellow("[Plan-Tool] \u8B66\u544A: \u65E0\u6CD5\u5BFC\u5165plan-executor.js\uFF0C\u8FD4\u56DE\u4EFB\u52A1\u89C4\u5212\u5EFA\u8BAE")),r={success:!0,message:"\u4EFB\u52A1\u89C4\u5212\u5DF2\u751F\u6210\uFF0C\u8BF7\u6839\u636E\u89C4\u5212\u6267\u884C\u4EFB\u52A1\u6B65\u9AA4",tasks:[{step:1,description:"\u5206\u6790\u9700\u6C42\u5E76\u786E\u8BA4\u6280\u672F\u6808",status:"pending"},{step:2,description:"\u5B9E\u73B0\u6838\u5FC3\u529F\u80FD\u6A21\u5757",status:"pending"},{step:3,description:"\u7F16\u5199\u6D4B\u8BD5\u7528\u4F8B",status:"pending"},{step:4,description:"\u4EE3\u7801\u5BA1\u67E5\u4E0E\u4F18\u5316",status:"pending"}]}}let s=`\u2705 Task planning and execution completed successfully!
|
|
1278
1482
|
|
|
1279
|
-
`;return s+=`**Task ID**: ${
|
|
1280
|
-
`,s+=`**Completed Steps**: ${
|
|
1483
|
+
`;return s+=`**Task ID**: ${r.taskId}
|
|
1484
|
+
`,s+=`**Completed Steps**: ${r.completedSteps}
|
|
1281
1485
|
|
|
1282
|
-
`,
|
|
1283
|
-
${
|
|
1486
|
+
`,r.planMarkdown&&(s+=`**Generated Plan**:
|
|
1487
|
+
${r.planMarkdown}
|
|
1284
1488
|
|
|
1285
|
-
`),
|
|
1286
|
-
`,
|
|
1287
|
-
`})),this.createToolResult(s,s,!0)}catch(
|
|
1489
|
+
`),r.tasks&&r.tasks.length>0&&(s+=`**Executed Steps**:
|
|
1490
|
+
`,r.tasks.forEach((i,a)=>{s+=`${a+1}. \u2713 ${i.description}
|
|
1491
|
+
`})),this.createToolResult(s,s,!0)}catch(r){let s=r instanceof Error?r.message:String(r);return this.createToolResult(`Error: Task execution failed - ${s}`,`Error: Task execution failed - ${s}`,!0)}finally{o.nestingLevel--}}static getCurrentNestingLevel(){return o.nestingLevel}static resetNestingLevel(){o.nestingLevel=0}formatAction(e){return`plan(task="${e.task.length>100?e.task.substring(0,100)+"...":e.task}", nesting_level=${o.nestingLevel+1})`}formatObservation(e){return typeof e=="string"&&e.includes("Error:")?e:"Task planning completed. Check logs above for details."}},Tc=new Me;qn=Tc});function $c(o){Pc=o}function Kn(){return Pc}var Pc,lo=S(()=>{Pc=null});import He from"readline";import ct from"chalk";async function Yn(o){return await Ec.execute(o)}var Jt,Ec,Xn,Mc=S(()=>{q();lo();Jt=class extends E{getDefinition(){return{name:"askUser",description:`Ask the user a question and wait for their response. This pauses the execution loop until the user provides input.
|
|
1288
1492
|
|
|
1289
1493
|
Use this tool when you need:
|
|
1290
1494
|
- User confirmation or decision
|
|
@@ -1301,7 +1505,7 @@ IMPORTANT:
|
|
|
1301
1505
|
Examples:
|
|
1302
1506
|
- askUser({ question: "Which file should I modify?" }) - Free text input
|
|
1303
1507
|
- askUser({ question: "Proceed with deletion?", choices: ["Yes", "No"] }) - Multiple choice
|
|
1304
|
-
- askUser({ question: "Select an option:", choices: ["Option 1", "Option 2"], allowFreeText: true }) - Choice with custom input allowed`,input_schema:{type:"object",properties:{question:{type:"string",description:"The question to ask the user. Be clear and specific."},choices:{type:"array",items:{type:"string"},description:"Optional: Predefined choices for the user to select from. If provided, user will see a menu."},allowFreeText:{type:"boolean",description:"Optional: If true, allows user to type a custom response even when choices are provided (default: false)",default:!1}},required:["question"]}}}async execute(e){let{question:t,choices:n,allowFreeText:
|
|
1508
|
+
- askUser({ question: "Select an option:", choices: ["Option 1", "Option 2"], allowFreeText: true }) - Choice with custom input allowed`,input_schema:{type:"object",properties:{question:{type:"string",description:"The question to ask the user. Be clear and specific."},choices:{type:"array",items:{type:"string"},description:"Optional: Predefined choices for the user to select from. If provided, user will see a menu."},allowFreeText:{type:"boolean",description:"Optional: If true, allows user to type a custom response even when choices are provided (default: false)",default:!1}},required:["question"]}}}async execute(e){let{question:t,choices:n,allowFreeText:r=!1}=e;try{let s;return n&&n.length>0?s=await this.showChoiceMenu(t,n,r):s=await this.showFreeTextInput(t),this.createToolResult(s,`User responded: ${s}`,!0)}catch(s){return this.formatError("Cannot get user input",s)}}showChoiceMenu(e,t,n){return new Promise(r=>{let s=0,i=t.map(p=>({text:p,value:p}));n&&i.push({text:"\u8F93\u5165\u81EA\u5B9A\u4E49\u7B54\u6848...",value:"__CUSTOM__"});let a=()=>{let p=i.length+5;for(let u=0;u<p;u++)u>0&&He.moveCursor(process.stdout,0,-1),He.clearLine(process.stdout,0);console.log(""),console.log(ct.cyan("\u{1F4AC} "+e)),console.log(""),console.log(ct.gray("\u8BF7\u9009\u62E9 (\u4F7F\u7528\u4E0A\u4E0B\u7BAD\u5934\u952E\uFF0CEnter\u786E\u8BA4):")),console.log(""),i.forEach((u,m)=>{let d=m===s,y=d?ct.green("> "):" ",w=d?ct.green.bold(u.text):ct.white(u.text);console.log(`${y}${w}`)}),console.log("")},c=process.stdin.isTTY?process.stdin.isRaw:!1;process.stdin.isTTY&&process.stdin.setRawMode(!0);let l=async(p,u)=>{if(u.name==="up"){s=Math.max(0,s-1),a();return}else if(u.name==="down"){s=Math.min(i.length-1,s+1),a();return}else if(u.name==="return"||u.name==="enter"){process.stdin.removeListener("keypress",l),process.stdin.isTTY&&process.stdin.setRawMode(c);let m=i.length+5;for(let y=0;y<m;y++)He.moveCursor(process.stdout,0,-1),He.clearLine(process.stdout,0);let d=i[s].value;if(d==="__CUSTOM__"){let y=await this.showFreeTextInput(e);r(y)}else r(d);return}else if(u.name==="escape"||u.ctrl&&u.name==="c"){let m=Kn();m?m.removeListener("keypress",l):(process.stdin.removeListener("keypress",l),process.stdin.isTTY&&process.stdin.setRawMode(c));let d=i.length+5;for(let y=0;y<d;y++)He.moveCursor(process.stdout,0,-1),He.clearLine(process.stdout,0);r("__CANCELLED__");return}},g=Kn();g?g.on("keypress",l):(He.emitKeypressEvents(process.stdin),process.stdin.on("keypress",l)),a()})}showFreeTextInput(e){return new Promise(t=>{let n=e||"\u8BF7\u8F93\u5165\u60A8\u7684\u7B54\u6848",r=process.stdin.listeners("keypress");process.stdin.removeAllListeners("keypress");let s=He.createInterface({input:process.stdin,output:process.stdout});console.log(""),console.log(ct.cyan("\u{1F4AC} "+n)),console.log(""),s.question(ct.gray("\u8BF7\u8F93\u5165\u7B54\u6848: "),i=>{s.removeAllListeners(),process.stdin.pause(),r.forEach(a=>{process.stdin.on("keypress",a)}),process.stdin.resume(),t(i.trim())})})}formatAction(e){let t=e.question||"";return e.choices&&e.choices.length>0?`askUser(question="${t}", choices=[${e.choices.join(", ")}])`:`askUser(question="${t}")`}formatObservation(e){return typeof e=="string"?e==="__CANCELLED__"?"User cancelled the input":`User response: ${e}`:super.formatObservation(e)}},Ec=new Jt;Xn=Ec});async function Qn(o){return await Ic.execute(o)}var Gt,Ic,Zn,Ac=S(()=>{q();Gt=class extends E{getDefinition(){return{name:"todo",description:`Execute and manage saved task plans. Use this tool to:
|
|
1305
1509
|
- Resume execution of a previously generated plan
|
|
1306
1510
|
- List all available task plans
|
|
1307
1511
|
- View details of a specific task plan
|
|
@@ -1315,62 +1519,57 @@ WHEN TO USE:
|
|
|
1315
1519
|
FEATURES:
|
|
1316
1520
|
- Resume from any step (default: continue from last step)
|
|
1317
1521
|
- View task progress and status
|
|
1318
|
-
- List all available plans in ./.nium/tasks/ directory`,input_schema:{type:"object",properties:{action:{type:"string",enum:["resume","list","view"],description:"The action to perform: resume (execute a saved plan), list (show all plans), view (show plan details)"},taskId:{type:"string",description:"The task ID to resume or view. Required for resume and view actions. Format: task-YYYYMMDD-XXX"},resumeFrom:{type:"number",description:"Step number to resume from (1-based). If not specified, resumes from the first incomplete step. Use 1 to restart from the beginning."}},required:["action"]}}}async execute(e){let{action:t,taskId:n,resumeFrom:
|
|
1319
|
-
|
|
1320
|
-
`;return s+=`**\u4EFB\u52A1 ID**: ${
|
|
1321
|
-
`,s+=`**\u5B8C\u6210\u6B65\u9AA4**: ${
|
|
1322
|
-
`,s+=`**\u6062\u590D\u8D77\u70B9**: \u6B65\u9AA4 ${
|
|
1323
|
-
|
|
1324
|
-
`,s+="\u6240\u6709\u6B65\u9AA4\u5DF2\u6210\u529F\u6267\u884C\u5B8C\u6BD5\u3002",this.createToolResult(s,s,!0)}catch(n){let
|
|
1325
|
-
`;
|
|
1326
|
-
|
|
1327
|
-
`;for(let s of n){let i=t(s);if(i){let a=i.tasks.filter(
|
|
1328
|
-
`,
|
|
1329
|
-
`,
|
|
1330
|
-
`,
|
|
1331
|
-
`,
|
|
1332
|
-
`,
|
|
1333
|
-
`}}return
|
|
1334
|
-
\u{1F4A1} \u4F7F\u7528 todo(action="view", taskId="...") \u67E5\u770B\u8BE6\u60C5`,
|
|
1335
|
-
\u{1F4A1} \u4F7F\u7528 todo(action="resume", taskId="...") \u6062\u590D\u6267\u884C`,this.createToolResult(
|
|
1336
|
-
`;
|
|
1337
|
-
|
|
1338
|
-
`,
|
|
1339
|
-
`,
|
|
1340
|
-
`,
|
|
1341
|
-
`,
|
|
1342
|
-
`,
|
|
1343
|
-
`,
|
|
1344
|
-
|
|
1345
|
-
`,
|
|
1346
|
-
`,
|
|
1347
|
-
`;for(let i of n.tasks){let a=i.status==="completed"?"\u2705":i.status==="in_progress"?"\u23F3":i.status==="pending"?"\u{1F4CB}":"\u2753",c=i;
|
|
1348
|
-
`,
|
|
1349
|
-
`,
|
|
1350
|
-
`,c.startTime&&(
|
|
1351
|
-
`),c.endTime&&(
|
|
1352
|
-
`),c.duration&&(
|
|
1353
|
-
`),c.error&&(
|
|
1354
|
-
`),
|
|
1355
|
-
`}let s=n.tasks.find(i=>i.status!=="completed");return s?
|
|
1356
|
-
\u{1F4A1} \u4F7F\u7528 todo(action="resume", taskId="${e}", resumeFrom=${s.step}) \u4ECE\u6B65\u9AA4 ${s.step} \u7EE7\u7EED\u6267\u884C`:
|
|
1357
|
-
\u2705 \u6240\u6709\u6B65\u9AA4\u5DF2\u5B8C\u6210\uFF01`,this.createToolResult(
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
`,
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
`,o+=`
|
|
1370
|
-
\u{1F550} \u751F\u6210\u65F6\u95F4: ${new Date().toLocaleString()}`,o}},Pt=null});var xn={};U(xn,{AgentTools:()=>es,AskUserTool:()=>kt,BaseTool:()=>I,ConfirmableTool:()=>re,CopyTool:()=>it,CoreTools:()=>uo,DeleteTool:()=>ot,FileChangeTools:()=>os,FileChangeTracker:()=>Mt,FileOpsTools:()=>bo,GlobTool:()=>ut,GrepTool:()=>gt,MergeTool:()=>at,MkdirTool:()=>nt,MoveTool:()=>st,PlanTool:()=>Tt,QuickProjectScanTool:()=>Fe,ReadTool:()=>tt,SearchReplaceTool:()=>ct,SearchTools:()=>vo,ShellTool:()=>pt,SystemTools:()=>To,THINK_TOOL:()=>nr,ThinkTool:()=>De,TodoTool:()=>$t,WriteTool:()=>rt,askUser:()=>wn,askUserTool:()=>Tn,copyFile:()=>Yt,copyTool:()=>Kt,createFileChangeTracker:()=>$r,createToolResult:()=>is,deleteFile:()=>Gt,deleteTool:()=>zt,detectFileChanges:()=>Mr,extractThought:()=>rr,extractToolResult:()=>_t,fileChangeTracking:()=>wu,generateChangeSummary:()=>Er,getCurrentSessionFileChanges:()=>Dr,getFileChangeTracker:()=>ge,getSessionFileChanges:()=>Lr,glob:()=>tn,globTool:()=>nn,grep:()=>rn,grepTool:()=>on,handleGitCommit:()=>Ar,isThinkTool:()=>ht,isToolResult:()=>et,merge:()=>Xt,mergeTool:()=>Qt,mkdir:()=>Wt,mkdirTool:()=>Le,moveFile:()=>qt,moveTool:()=>Bt,plan:()=>bn,planTool:()=>vn,quickProjectScan:()=>bt,quickProjectScanTool:()=>vt,read:()=>Ut,readTool:()=>Vt,recordFileChange:()=>Ir,resetFileChangeTracker:()=>Pr,searchReplace:()=>Zt,searchReplaceTool:()=>en,shell:()=>sn,shellTool:()=>mt,think:()=>dt,thinkTool:()=>ft,todo:()=>kn,todoTool:()=>$n,toolInstances:()=>R,tools:()=>ss,write:()=>Ht,writeTool:()=>Jt});function is(r,e=null,t=!0){return{__tool_result:!0,result:r,display:e!==null?e:r,shouldPrint:t}}var R,ss,wu,Se=C(()=>{go();go();Xn();Xn();Zn();Zn();tr();tr();Tr();Tr();jr();jr();Xn();Zn();tr();Tr();jr();R={think:ft,plan:vn,todo:$n,askUser:Tn,quickProjectScan:vt,read:Vt,write:Jt,mkdir:Le,glob:nn,grep:on,shell:mt,merge:Qt,deleteFile:zt,moveFile:Bt,copyFile:Kt,search_replace:en},ss={think:dt,plan:bn,todo:kn,askUser:wn,quickProjectScan:bt,read:Ut,write:Ht,mkdir:Wt,merge:Xt,glob:tn,grep:rn,shell:sn,deleteFile:Gt,moveFile:qt,copyFile:Yt,search_replace:Zt},wu={detectFileChanges:Mr,generateChangeSummary:Er,recordFileChange:Ir,handleGitCommit:Ar,getSessionFileChanges:Lr,getCurrentSessionFileChanges:Dr,getFileChangeTracker:ge,createFileChangeTracker:$r,resetFileChangeTracker:Pr}});var ja=C(()=>{});import{Client as Tu}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as ku}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{StdioClientTransport as $u}from"@modelcontextprotocol/sdk/client/stdio.js";var In,as=C(()=>{K();In=class{client=null;config;connected=!1;tools=[];constructor(e){this.config={timeout:3e4,enabled:!0,...e}}async connect(){h(`Connecting to MCP server: ${this.config.name} (${this.config.transport})`);try{let e;if(this.config.transport==="http"||this.config.transport==="sse"){if(!this.config.url)throw new Error(`URL is required for ${this.config.transport} transport`);e=new ku(new URL(this.config.url))}else if(this.config.transport==="stdio"){if(!this.config.command)throw new Error(`Command is required for ${this.config.transport} transport`);e=new $u({command:this.config.command,args:this.config.args||[],env:this.config.env})}else throw new Error(`Unsupported transport type: ${this.config.transport}`);this.client=new Tu({name:"niumagents-cli",version:"0.1.0"}),await this.client.connect(e),this.connected=!0;let t=await this.client.listTools();this.tools=t.tools.map(n=>({name:n.name,description:n.description,inputSchema:n.inputSchema||{type:"object",properties:{}},serverName:this.config.name})),h(`Loaded ${this.tools.length} tools from ${this.config.name}`)}catch(e){throw h(`Failed to connect to MCP server ${this.config.name}: ${e.message}`),e}}async disconnect(){h(`Disconnecting from MCP server: ${this.config.name}`),this.client=null,this.connected=!1,this.tools=[]}async listTools(){if(!this.client||!this.connected)throw new Error("Not connected to MCP server");return(await this.client.listTools()).tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema||{type:"object",properties:{}},serverName:this.config.name}))}async callTool(e,t){if(!this.client||!this.connected)return{success:!1,error:"Not connected to MCP server"};try{let n=await this.client.callTool({name:e,arguments:t});return{success:!n.isError,content:n.content||n.result,metadata:n.metadata||{}}}catch(n){return{success:!1,error:n.message}}}isConnected(){return this.connected}getConfig(){return this.config}getCachedTools(){return this.tools}}});var Oa=C(()=>{as()});function Et(){return cs.getInstance()}var cs,ls=C(()=>{as();K();cs=class r{static instance=null;clients=new Map;mcpTools=new Map;initialized=!1;constructor(){}static getInstance(){return r.instance||(r.instance=new r),r.instance}async initialize(e){if(this.initialized){z("MCP Manager already initialized");return}M(`Initializing ${e.length} MCP server(s)...`),e.length>0&&(h("MCP Server Configurations:"),e.forEach(t=>{h(` - Server: ${t.name} (${t.transport})`),h(` Enabled: ${t.enabled!==!1}`),t.url?h(` URL: ${t.url}`):t.command&&h(` Command: ${t.command}`)}));for(let t of e){if(t.enabled===!1){h(`Skipping disabled MCP server: ${t.name}`);continue}try{h(`Attempting to connect to MCP server ${t.name} with URL: ${t.url||"N/A"}`),await this.connectToServer(t)}catch(n){Y(`Failed to connect to MCP server ${t.name}: ${n.message}`),h(`Error details for ${t.name}: ${n.message}
|
|
1371
|
-
${n.stack||""}`)}}this.initialized=!0,M(`MCP Manager initialized with ${this.clients.size} server(s) and ${this.mcpTools.size} tool(s)`)}async connectToServer(e){h(`Connecting to MCP server: ${e.name} (${e.transport})`);let t=this.createClient(e);await t.connect(),this.clients.set(e.name,t);let n=t.getCachedTools();for(let o of n)this.registerTool(o);M(`Connected to MCP server: ${e.name} (${n.length} tools)`)}createClient(e){return new In(e)}registerTool(e){let t=e.name;if(this.mcpTools.has(t)){z(`MCP tool ${t} already registered, skipping (using first registered)`);return}this.mcpTools.set(t,e),h(`Registered MCP tool: ${t} from ${e.serverName}`)}getAllTools(){return Array.from(this.mcpTools.values())}getTool(e){return this.mcpTools.get(e)}hasTool(e){return this.mcpTools.has(e)}async callTool(e,t){let n=this.mcpTools.get(e);if(!n)return{success:!1,error:`MCP tool not found: ${e}`};let o=this.clients.get(n.serverName);return o?o.isConnected()?o.callTool(e,t):{success:!1,error:`MCP server not connected: ${n.serverName}`}:{success:!1,error:`MCP server not connected: ${n.serverName}`}}async disconnectAll(){h("Disconnecting all MCP servers...");for(let[e,t]of this.clients.entries())try{await t.disconnect(),h(`Disconnected from MCP server: ${e}`)}catch(n){Y(`Error disconnecting from ${e}: ${n.message}`)}this.clients.clear(),this.mcpTools.clear(),this.initialized=!1,M("All MCP servers disconnected")}getStatus(){let e=Array.from(this.clients.entries()).map(([t,n])=>({name:t,connected:n.isConnected(),toolCount:n.getCachedTools().length}));return{initialized:this.initialized,serversConnected:this.clients.size,toolsAvailable:this.mcpTools.size,servers:e}}}});function Ra(r){let e={};for(let t of r)e[t.name]=new Or(t);return e}function Fa(r){let e={};for(let t of r){let n=new Or(t);e[t.name]=async(...o)=>n.execute(...o)}return e}var Or,_a=C(()=>{ls();J();Se();K();Or=class extends I{mcpTool;constructor(e){super(),this.mcpTool=e}getDefinition(){return{name:this.mcpTool.name,description:`[MCP:${this.mcpTool.serverName}] ${this.mcpTool.description}`,input_schema:{type:"object",properties:this.mcpTool.inputSchema.properties||{},required:this.mcpTool.inputSchema.required}}}async execute(...e){h(`Executing MCP tool: ${this.mcpTool.name}`);let t=this.argsToParams(e),o=await Et().callTool(this.mcpTool.name,t);if(!o.success)throw new Error(o.error||"MCP tool execution failed");let s=this.formatMCPResult(o.content);return is(s,s,!0)}argsToParams(e){if(e.length===1&&typeof e[0]=="object"&&!Array.isArray(e[0]))return e[0];let n=this.mcpTool.inputSchema.properties||{},o=Object.keys(n),s={};return e.forEach((i,a)=>{a<o.length&&(s[o[a]]=i)}),s}formatMCPResult(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>this.formatContentItem(t)).join(`
|
|
1372
|
-
|
|
1373
|
-
`):JSON.stringify(e,null,2)}formatContentItem(e){return typeof e=="string"?e:e.type==="text"?e.text||"":e.type==="image"?`[Image: ${e.data?.substring(0,50)}...]`:e.type==="resource"?`[Resource: ${e.uri||"unknown"}]`:JSON.stringify(e)}formatAction(e){let t=typeof e=="object"?Object.entries(e).map(([n,o])=>`${n}=${JSON.stringify(o)}`).join(", "):JSON.stringify(e);return`${this.mcpTool.name}(${t}) [MCP:${this.mcpTool.serverName}]`}formatObservation(e){return e&&e.__tool_result?String(e.display||e.result):String(e)}shouldPrintObservation(e){return!0}}});var us=C(()=>{ja();Oa();ls();_a()});async function Rr(){if(gs){h("Tools already loaded, skipping");return}M("Loading tools..."),It={...R},Na={...ss};let r=Object.keys(R);M(`Loaded ${r.length} local tools`);let t=Et().getAllTools();if(t.length===0){h("No MCP tools available"),gs=!0;return}let n=Ra(t),o=Fa(t),s=0,i=0;for(let[a,c]of Object.entries(n)){if(It[a]){h(`Skipping MCP tool ${a} (local tool has priority)`),i++;continue}It[a]=c,Na[a]=o[a],s++}M(`Added ${s} MCP tools, skipped ${i} (local priority)`),M(`Total tools available: ${Object.keys(It).length}`),gs=!0}function At(){return It}function Ua(){let r=Object.keys(R),e=Object.keys(It),t=e.filter(n=>!r.includes(n));return{local:r.length,mcp:t.length,total:e.length,localTools:r,mcpTools:t}}var It,Na,gs,An=C(()=>{Se();us();K();It={},Na={},gs=!1});var Zo={};U(Zo,{TOOL_DEFINITIONS:()=>Fr,getRawToolDefinitions:()=>cn,getToolDefinitions:()=>Ln,getToolNames:()=>Wa,isRealTool:()=>Pu});function Va(r){return{name:r.name,description:r.description,input_schema:r.input_schema}}function Ln(){let r=At();if(Object.keys(r).length===0)return Fr.map(Va);let e=[],t=["think","plan","todo","askUser"];for(let n of t)if(r[n]){let o=r[n].getDefinition();o&&e.push(o)}for(let[n,o]of Object.entries(r))if(!t.includes(n)&&o){let s=o.getDefinition();s&&e.push(s)}return e.filter(n=>n!=null).map(Va)}function cn(){return Fr}function Wa(){return Fr.map(r=>r.name)}function Pu(r){return r!=="think"&&Wa().includes(r)}var Fr,St=C(()=>{Se();An();Fr=[R.think.getDefinition(),R.plan.getDefinition(),R.todo.getDefinition(),R.askUser.getDefinition(),R.quickProjectScan.getDefinition(),R.read.getDefinition(),R.write.getDefinition(),R.merge.getDefinition(),R.mkdir.getDefinition(),R.glob.getDefinition(),R.grep.getDefinition(),R.deleteFile.getDefinition(),R.moveFile.getDefinition(),R.copyFile.getDefinition(),R.search_replace.getDefinition(),R.shell.getDefinition()]});function ps(r){return!r||typeof r!="string"?0:Math.ceil(r.length/4)}function $e(r){if(!Array.isArray(r))return 0;let e=0;for(let t of r){if(t.content&&typeof t.content=="string"&&(e+=ps(t.content)),t.tool_calls&&Array.isArray(t.tool_calls))for(let n of t.tool_calls)n.function&&(e+=ps(n.function.name||""),e+=ps(n.function.arguments||""));e+=4}return e}function _r(r,e){return!e||e<=0?0:r/e*100}function ms(r,e,t=80){return _r(r,e)>=t}function ds(r,e,t){return`\u26A0\uFE0F Token usage warning: ${r.toLocaleString()} / ${e.toLocaleString()} tokens (${t.toFixed(1)}%)`}var fs=C(()=>{});import Dn from"chalk";var Nr,Ha=C(()=>{fs();K();Nr=class{options;constructor(e={}){this.options={enabled:e.enabled??!0,threshold:e.threshold??.8,minKeepMessages:e.minKeepMessages??3,maxKeepMessages:e.maxKeepMessages??20,targetUsageAfterCompression:e.targetUsageAfterCompression??.6,useMixedSummary:e.useMixedSummary??!0,llmSummaryTokenThreshold:e.llmSummaryTokenThreshold??500}}shouldCompress(e,t){return this.options.enabled?$e(e)/t>=this.options.threshold:!1}async compress(e,t,n){let o=$e(e),s=e.length;M(`\u5F00\u59CB\u4E0A\u4E0B\u6587\u538B\u7F29: ${s} \u6761\u6D88\u606F, ${o} tokens`);let i=this.calculateDynamicWindowSize(e,t);h(`\u52A8\u6001\u7A97\u53E3\u5927\u5C0F: \u4FDD\u7559\u6700\u8FD1 ${i} \u6761\u5B8C\u6574\u6D88\u606F`);let a=e.slice(0,-i),c=e.slice(-i);if(a.length===0)return z("\u6CA1\u6709\u9700\u8981\u538B\u7F29\u7684\u6D88\u606F,\u8DF3\u8FC7\u538B\u7F29"),{messages:e,stats:{originalMessageCount:s,originalTokenCount:o,compressedMessageCount:s,compressedTokenCount:o,compressionRatio:1,llmSummaryCount:0,heuristicSummaryCount:0}};let{summaryMessage:l,llmCount:p,heuristicCount:u}=await this.createCompressedSummary(a,n),g=[l,...c],m=$e(g),S={originalMessageCount:s,originalTokenCount:o,compressedMessageCount:g.length,compressedTokenCount:m,compressionRatio:m/o,llmSummaryCount:p,heuristicSummaryCount:u};return this.logCompressionStats(S),{messages:g,stats:S}}calculateDynamicWindowSize(e,t){let o=$e(e)/t,s;return o>=.9?(s=this.options.minKeepMessages,h("Token\u538B\u529B\u6781\u9AD8 (>=90%), \u4F7F\u7528\u6700\u5C0F\u7A97\u53E3")):o>=.85?(s=Math.floor(this.options.minKeepMessages+(this.options.maxKeepMessages-this.options.minKeepMessages)*.25),h("Token\u538B\u529B\u9AD8 (>=85%), \u4F7F\u7528\u8F83\u5C0F\u7A97\u53E3")):o>=.8?(s=Math.floor(this.options.minKeepMessages+(this.options.maxKeepMessages-this.options.minKeepMessages)*.5),h("Token\u538B\u529B\u4E2D\u7B49 (>=80%), \u4F7F\u7528\u4E2D\u7B49\u7A97\u53E3")):(s=this.options.maxKeepMessages,h("Token\u538B\u529B\u6B63\u5E38, \u4F7F\u7528\u6700\u5927\u7A97\u53E3")),Math.min(s,e.length)}async createCompressedSummary(e,t){let n=[],o=0,s=0,i=this.groupMessages(e);for(let c of i){let l=$e(c),p=this.assessMessageImportance(c),u;this.options.useMixedSummary&&p==="important"&&l>=this.options.llmSummaryTokenThreshold&&t?(u=await this.generateLLMSummary(c,t),o++,h(`\u4F7F\u7528LLM\u6458\u8981 (${c.length}\u6761\u6D88\u606F, ${l} tokens)`)):(u=this.generateHeuristicSummary(c),s++,h(`\u4F7F\u7528\u542F\u53D1\u5F0F\u6458\u8981 (${c.length}\u6761\u6D88\u606F, ${l} tokens)`)),n.push(u)}return{summaryMessage:{role:"system",content:`[\u5386\u53F2\u4E0A\u4E0B\u6587\u6458\u8981]
|
|
1522
|
+
- List all available plans in ./.nium/tasks/ directory`,input_schema:{type:"object",properties:{action:{type:"string",enum:["resume","list","view"],description:"The action to perform: resume (execute a saved plan), list (show all plans), view (show plan details)"},taskId:{type:"string",description:"The task ID to resume or view. Required for resume and view actions. Format: task-YYYYMMDD-XXX"},resumeFrom:{type:"number",description:"Step number to resume from (1-based). If not specified, resumes from the first incomplete step. Use 1 to restart from the beginning."}},required:["action"]}}}async execute(e){let{action:t,taskId:n,resumeFrom:r}=e;try{switch(t){case"resume":return await this.executeResume(n,r);case"list":return await this.executeList();case"view":return await this.executeView(n);default:return this.createToolResult(`Error: Unknown action '${t}'`,`Error: Unknown action '${t}'`,!0)}}catch(s){let i=s instanceof Error?s.message:String(s);return this.createToolResult(`Error: ${i}`,`Error: ${i}`,!0)}}async executeResume(e,t){if(!e)return this.createToolResult("Error: taskId is required for resume action","Error: taskId is required for resume action",!0);try{let{resumePlanTask:n}=await Promise.resolve().then(()=>(ao(),zs)),r=await n(e,t||0),s=`\u2705 \u4EFB\u52A1\u6062\u590D\u6267\u884C\u5B8C\u6210\uFF01
|
|
1523
|
+
|
|
1524
|
+
`;return s+=`**\u4EFB\u52A1 ID**: ${r.taskId}
|
|
1525
|
+
`,s+=`**\u5B8C\u6210\u6B65\u9AA4**: ${r.completedSteps}
|
|
1526
|
+
`,s+=`**\u6062\u590D\u8D77\u70B9**: \u6B65\u9AA4 ${r.resumedFrom}
|
|
1527
|
+
|
|
1528
|
+
`,s+="\u6240\u6709\u6B65\u9AA4\u5DF2\u6210\u529F\u6267\u884C\u5B8C\u6BD5\u3002",this.createToolResult(s,s,!0)}catch(n){let r=n instanceof Error?n.message:String(n);return this.createToolResult(`Error: Failed to resume task - ${r}`,`Error: Failed to resume task - ${r}`,!0)}}async executeList(){try{let{listTaskPlans:e,loadTaskPlan:t}=await Promise.resolve().then(()=>(be(),Oe)),n=e();if(n.length===0)return this.createToolResult("No saved task plans found in ./.nium/tasks/ directory.","No saved task plans found in ./.nium/tasks/ directory.",!0);let r=`\u{1F4CB} \u5DF2\u4FDD\u5B58\u7684\u4EFB\u52A1\u8BA1\u5212 (\u5171 ${n.length} \u4E2A)
|
|
1529
|
+
`;r+=`${"\u2550".repeat(60)}
|
|
1530
|
+
|
|
1531
|
+
`;for(let s of n){let i=t(s);if(i){let a=i.tasks.filter(g=>g.status==="completed").length,c=i.tasks.length,l=a===c?"\u2705 \u5DF2\u5B8C\u6210":a>0?`\u23F3 \u8FDB\u884C\u4E2D (${a}/${c})`:"\u{1F4CB} \u5F85\u6267\u884C";r+=`**${s}**
|
|
1532
|
+
`,r+=` \u72B6\u6001: ${l}
|
|
1533
|
+
`,r+=` \u6B65\u9AA4: ${c} \u4E2A
|
|
1534
|
+
`,r+=` \u7B56\u7565: ${i.strategy}
|
|
1535
|
+
`,r+=` \u521B\u5EFA\u65F6\u95F4: ${i.createdAt||"N/A"}
|
|
1536
|
+
`,r+=`
|
|
1537
|
+
`}}return r+=`
|
|
1538
|
+
\u{1F4A1} \u4F7F\u7528 todo(action="view", taskId="...") \u67E5\u770B\u8BE6\u60C5`,r+=`
|
|
1539
|
+
\u{1F4A1} \u4F7F\u7528 todo(action="resume", taskId="...") \u6062\u590D\u6267\u884C`,this.createToolResult(r,r,!0)}catch(e){let t=e instanceof Error?e.message:String(e);return this.createToolResult(`Error: Failed to list tasks - ${t}`,`Error: Failed to list tasks - ${t}`,!0)}}async executeView(e){if(!e)return this.createToolResult("Error: taskId is required for view action","Error: taskId is required for view action",!0);try{let{loadTaskPlan:t}=await Promise.resolve().then(()=>(be(),Oe)),n=t(e);if(!n)return this.createToolResult(`Error: Task plan '${e}' not found`,`Error: Task plan '${e}' not found`,!0);let r=`\u{1F4CB} \u4EFB\u52A1\u8BA1\u5212\u8BE6\u60C5
|
|
1540
|
+
`;r+=`${"\u2550".repeat(60)}
|
|
1541
|
+
|
|
1542
|
+
`,r+=`**\u4EFB\u52A1 ID**: ${n.taskId}
|
|
1543
|
+
`,r+=`**\u521B\u5EFA\u65F6\u95F4**: ${n.createdAt||"N/A"}
|
|
1544
|
+
`,r+=`**\u66F4\u65B0\u65F6\u95F4**: ${n.updatedAt||"N/A"}
|
|
1545
|
+
`,r+=`**\u603B\u6B65\u9AA4\u6570**: ${n.tasks.length}
|
|
1546
|
+
`,r+=`**\u89C4\u5212\u7B56\u7565**: ${n.strategy}
|
|
1547
|
+
`,r+=`**\u5F53\u524D\u72B6\u6001**: ${n.status||"N/A"}
|
|
1548
|
+
|
|
1549
|
+
`,r+=`**\u6267\u884C\u6B65\u9AA4**:
|
|
1550
|
+
`,r+=`${"\u2500".repeat(60)}
|
|
1551
|
+
`;for(let i of n.tasks){let a=i.status==="completed"?"\u2705":i.status==="in_progress"?"\u23F3":i.status==="pending"?"\u{1F4CB}":"\u2753",c=i;r+=`${i.step}. ${a} ${i.description}
|
|
1552
|
+
`,r+=` \u667A\u80FD\u4F53: ${i.subAgent}
|
|
1553
|
+
`,r+=` \u72B6\u6001: ${i.status}
|
|
1554
|
+
`,c.startTime&&(r+=` \u5F00\u59CB: ${c.startTime}
|
|
1555
|
+
`),c.endTime&&(r+=` \u5B8C\u6210: ${c.endTime}
|
|
1556
|
+
`),c.duration&&(r+=` \u8017\u65F6: ${c.duration}ms
|
|
1557
|
+
`),c.error&&(r+=` \u9519\u8BEF: ${c.error}
|
|
1558
|
+
`),r+=`
|
|
1559
|
+
`}let s=n.tasks.find(i=>i.status!=="completed");return s?r+=`
|
|
1560
|
+
\u{1F4A1} \u4F7F\u7528 todo(action="resume", taskId="${e}", resumeFrom=${s.step}) \u4ECE\u6B65\u9AA4 ${s.step} \u7EE7\u7EED\u6267\u884C`:r+=`
|
|
1561
|
+
\u2705 \u6240\u6709\u6B65\u9AA4\u5DF2\u5B8C\u6210\uFF01`,this.createToolResult(r,r,!0)}catch(t){let n=t instanceof Error?t.message:String(t);return this.createToolResult(`Error: Failed to view task - ${n}`,`Error: Failed to view task - ${n}`,!0)}}formatAction(e){let{action:t,taskId:n,resumeFrom:r}=e,s=`todo(action="${t}"`;return n&&(s+=`, taskId="${n}"`),r&&(s+=`, resumeFrom=${r}`),s+=")",s}},Ic=new Gt;Zn=Ic});var Js={};j(Js,{AskUserTool:()=>Jt,PlanTool:()=>Me,QuickProjectScanTool:()=>at,THINK_TOOL:()=>Mr,ThinkTool:()=>Ze,TodoTool:()=>Gt,askUser:()=>Yn,askUserTool:()=>Xn,extractThought:()=>Ir,isThinkTool:()=>Dt,plan:()=>Bn,planTool:()=>qn,quickProjectScan:()=>zt,quickProjectScanTool:()=>Vt,think:()=>Lt,thinkTool:()=>Rt,todo:()=>Qn,todoTool:()=>Zn});var uo=S(()=>{An();Hs();Mc();Fs();Ac()});async function Lc(o){return Bs.execute(o)}var Gs,Bs,Rc,Xy,Dc=S(()=>{q();Wn();Gs=class extends E{getDefinition(){return{name:"search_file_changes",description:`Use this tool to search and query file changes in the workspace. This tool provides auxiliary information to help you understand the current state of the workspace.
|
|
1562
|
+
|
|
1563
|
+
IMPORTANT: This tool is for reference only. Your primary focus should be on solving the current task. Use this tool only when you need additional context about workspace changes.
|
|
1564
|
+
|
|
1565
|
+
Typical use cases:
|
|
1566
|
+
- When you need to check what files have been modified recently
|
|
1567
|
+
- When you want to understand the scope of changes in the workspace
|
|
1568
|
+
- When you need to verify if certain files have been changed
|
|
1569
|
+
- When you want to get a summary of changes`,input_schema:{type:"object",properties:{query:{type:"string",description:"Search keywords to filter file changes"},filePatterns:{type:"array",items:{type:"string"},description:"File patterns to match (e.g., ['*.ts', '*.js'])",uniqueItems:!0},changeTypes:{type:"array",items:{type:"string",enum:["added","modified","deleted","renamed"]},description:"Types of changes to include",uniqueItems:!0},dateRange:{type:"object",properties:{start:{type:"string",format:"date-time",description:"Start date for filtering changes"},end:{type:"string",format:"date-time",description:"End date for filtering changes"}},description:"Time range to filter changes"},author:{type:"string",description:"Author to filter changes by"},branch:{type:"string",description:"Git branch to filter changes by"},sortBy:{type:"string",enum:["timestamp","filePath","size","type"],description:"Field to sort results by"},sortOrder:{type:"string",enum:["asc","desc"],description:"Sort order (ascending or descending)"},limit:{type:"integer",minimum:1,maximum:100,description:"Maximum number of results to return"},offset:{type:"integer",minimum:0,description:"Offset for pagination"},includeContent:{type:"boolean",description:"Whether to include file content previews"}}}}}async execute(e){try{let t=ze(),n={query:e.query,filter:{filePatterns:e.filePatterns,changeTypes:e.changeTypes,dateRange:e.dateRange,author:e.author,branch:e.branch},sortBy:e.sortBy,sortOrder:e.sortOrder,limit:e.limit,offset:e.offset,includeContent:e.includeContent};return await t.searchFileChanges(n)}catch(t){throw console.error("\u641C\u7D22\u6587\u4EF6\u53D8\u66F4\u65F6\u51FA\u9519:",t),new Error(`\u641C\u7D22\u6587\u4EF6\u53D8\u66F4\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`)}}},Bs=new Gs;Rc=Bs,Xy=Bs.getDefinition()});var Gn={};j(Gn,{AgentTools:()=>Js,AskUserTool:()=>Jt,BaseTool:()=>E,ConfirmableTool:()=>he,CopyTool:()=>Tt,CoreTools:()=>Vo,DeleteTool:()=>vt,FileChangeTools:()=>Ss,FileChangeTracker:()=>We,FileOpsTools:()=>Zo,GlobTool:()=>Et,GrepTool:()=>Mt,MergeTool:()=>kt,MkdirTool:()=>xt,MoveTool:()=>bt,PlanTool:()=>Me,QuickProjectScanTool:()=>at,ReadTool:()=>St,SearchReplaceTool:()=>Pt,SearchTools:()=>es,ShellTool:()=>It,SystemTools:()=>ns,THINK_TOOL:()=>Mr,ThinkTool:()=>Ze,TodoTool:()=>Gt,WriteTool:()=>wt,aiContextManager:()=>Eg,askUser:()=>Yn,askUserTool:()=>Xn,copyFile:()=>xn,copyTool:()=>wn,createFileChangeTracker:()=>Or,createToolResult:()=>Ks,deleteFile:()=>hn,deleteTool:()=>yn,detectFileChanges:()=>jr,extractThought:()=>Ir,extractToolResult:()=>ln,fileChangeTracking:()=>Mg,generateChangeSummary:()=>_r,getCurrentSessionFileChanges:()=>zr,getFileChangeTracker:()=>ce,getSessionFileChanges:()=>Wr,glob:()=>Pn,globTool:()=>$n,grep:()=>En,grepTool:()=>Mn,handleGitCommit:()=>Ur,isThinkTool:()=>Dt,isToolResult:()=>Ct,merge:()=>vn,mergeTool:()=>bn,mkdir:()=>mn,mkdirTool:()=>Qe,moveFile:()=>Cn,moveTool:()=>Sn,plan:()=>Bn,planTool:()=>qn,quickProjectScan:()=>zt,quickProjectScanTool:()=>Vt,read:()=>gn,readTool:()=>pn,recordFileChange:()=>Nr,resetFileChangeTracker:()=>Fr,searchReplace:()=>Tn,searchReplaceTool:()=>kn,shell:()=>In,shellTool:()=>At,think:()=>Lt,thinkTool:()=>Rt,todo:()=>Qn,todoTool:()=>Zn,toolInstances:()=>U,tools:()=>qs,write:()=>dn,writeTool:()=>fn});function Ks(o,e=null,t=!0){return{__tool_result:!0,result:o,display:e!==null?e:o,shouldPrint:t}}var U,qs,Eg,Mg,Ee=S(()=>{Ho();Ho();Tr();Tr();Pr();Pr();Er();Er();uo();uo();ot();ot();Tr();Pr();Er();uo();Dc();ot();Wn();U={think:Rt,plan:qn,todo:Zn,askUser:Xn,quickProjectScan:Vt,read:pn,write:fn,mkdir:Qe,glob:$n,grep:Mn,shell:At,merge:bn,delete:yn,move:Sn,copy:wn,searchReplace:kn,search_file_changes:Rc},qs={think:Lt,plan:Bn,todo:Qn,askUser:Yn,quickProjectScan:zt,read:gn,write:dn,mkdir:mn,merge:vn,glob:Pn,grep:En,shell:In,delete:hn,move:Cn,copy:xn,searchReplace:Tn,searchFileChanges:Lc},Eg={getAIContextManager:ze,createAIContextManager:ja,resetAIContextManager:_a},Mg={detectFileChanges:jr,generateChangeSummary:_r,recordFileChange:Nr,handleGitCommit:Ur,getSessionFileChanges:Wr,getCurrentSessionFileChanges:zr,getFileChangeTracker:ce,createFileChangeTracker:Or,resetFileChangeTracker:Fr}});var Oc=S(()=>{});import{Client as Ig}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as Ag}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{StdioClientTransport as Lg}from"@modelcontextprotocol/sdk/client/stdio.js";var er,Ys=S(()=>{Y();er=class{client=null;config;connected=!1;tools=[];constructor(e){this.config={timeout:3e4,enabled:!0,...e}}async connect(){C(`Connecting to MCP server: ${this.config.name} (${this.config.transport})`);try{let e;if(this.config.transport==="http"||this.config.transport==="sse"){if(!this.config.url)throw new Error(`URL is required for ${this.config.transport} transport`);e=new Ag(new URL(this.config.url))}else if(this.config.transport==="stdio"){if(!this.config.command)throw new Error(`Command is required for ${this.config.transport} transport`);e=new Lg({command:this.config.command,args:this.config.args||[],env:this.config.env})}else throw new Error(`Unsupported transport type: ${this.config.transport}`);this.client=new Ig({name:"niumagents-cli",version:"0.1.0"}),await this.client.connect(e),this.connected=!0;let t=await this.client.listTools();this.tools=t.tools.map(n=>({name:n.name,description:n.description,inputSchema:n.inputSchema||{type:"object",properties:{}},serverName:this.config.name})),C(`Loaded ${this.tools.length} tools from ${this.config.name}`)}catch(e){throw C(`Failed to connect to MCP server ${this.config.name}: ${e.message}`),e}}async disconnect(){C(`Disconnecting from MCP server: ${this.config.name}`),this.client=null,this.connected=!1,this.tools=[]}async listTools(){if(!this.client||!this.connected)throw new Error("Not connected to MCP server");return(await this.client.listTools()).tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema||{type:"object",properties:{}},serverName:this.config.name}))}async callTool(e,t){if(!this.client||!this.connected)return{success:!1,error:"Not connected to MCP server"};try{let n=await this.client.callTool({name:e,arguments:t});return{success:!n.isError,content:n.content||n.result,metadata:n.metadata||{}}}catch(n){return{success:!1,error:n.message}}}isConnected(){return this.connected}getConfig(){return this.config}getCachedTools(){return this.tools}}});var Fc=S(()=>{Ys()});function Bt(){return Xs.getInstance()}var Xs,Qs=S(()=>{Ys();Y();Xs=class o{static instance=null;clients=new Map;mcpTools=new Map;initialized=!1;constructor(){}static getInstance(){return o.instance||(o.instance=new o),o.instance}async initialize(e){if(this.initialized){H("MCP Manager already initialized");return}$(`Initializing ${e.length} MCP server(s)...`),e.length>0&&(C("MCP Server Configurations:"),e.forEach(t=>{C(` - Server: ${t.name} (${t.transport})`),C(` Enabled: ${t.enabled!==!1}`),t.url?C(` URL: ${t.url}`):t.command&&C(` Command: ${t.command}`)}));for(let t of e){if(t.enabled===!1){C(`Skipping disabled MCP server: ${t.name}`);continue}try{C(`Attempting to connect to MCP server ${t.name} with URL: ${t.url||"N/A"}`),await this.connectToServer(t)}catch(n){K(`Failed to connect to MCP server ${t.name}: ${n.message}`),C(`Error details for ${t.name}: ${n.message}
|
|
1570
|
+
${n.stack||""}`)}}this.initialized=!0,$(`MCP Manager initialized with ${this.clients.size} server(s) and ${this.mcpTools.size} tool(s)`)}async connectToServer(e){C(`Connecting to MCP server: ${e.name} (${e.transport})`);let t=this.createClient(e);await t.connect(),this.clients.set(e.name,t);let n=t.getCachedTools();for(let r of n)this.registerTool(r);$(`Connected to MCP server: ${e.name} (${n.length} tools)`)}createClient(e){return new er(e)}registerTool(e){let t=e.name;if(this.mcpTools.has(t)){H(`MCP tool ${t} already registered, skipping (using first registered)`);return}this.mcpTools.set(t,e),C(`Registered MCP tool: ${t} from ${e.serverName}`)}getAllTools(){return Array.from(this.mcpTools.values())}getTool(e){return this.mcpTools.get(e)}hasTool(e){return this.mcpTools.has(e)}async callTool(e,t){let n=this.mcpTools.get(e);if(!n)return{success:!1,error:`MCP tool not found: ${e}`};let r=this.clients.get(n.serverName);return r?r.isConnected()?r.callTool(e,t):{success:!1,error:`MCP server not connected: ${n.serverName}`}:{success:!1,error:`MCP server not connected: ${n.serverName}`}}async disconnectAll(){C("Disconnecting all MCP servers...");for(let[e,t]of this.clients.entries())try{await t.disconnect(),C(`Disconnected from MCP server: ${e}`)}catch(n){K(`Error disconnecting from ${e}: ${n.message}`)}this.clients.clear(),this.mcpTools.clear(),this.initialized=!1,$("All MCP servers disconnected")}getStatus(){let e=Array.from(this.clients.entries()).map(([t,n])=>({name:t,connected:n.isConnected(),toolCount:n.getCachedTools().length}));return{initialized:this.initialized,serversConnected:this.clients.size,toolsAvailable:this.mcpTools.size,servers:e}}}});function jc(o){let e={};for(let t of o)e[t.name]=new go(t);return e}function _c(o){let e={};for(let t of o){let n=new go(t);e[t.name]=async(...r)=>n.execute(...r)}return e}var go,Nc=S(()=>{Qs();q();Ee();Y();go=class extends E{mcpTool;constructor(e){super(),this.mcpTool=e}getDefinition(){return{name:this.mcpTool.name,description:`[MCP:${this.mcpTool.serverName}] ${this.mcpTool.description}`,input_schema:{type:"object",properties:this.mcpTool.inputSchema.properties||{},required:this.mcpTool.inputSchema.required}}}async execute(...e){C(`Executing MCP tool: ${this.mcpTool.name}`);let t=this.argsToParams(e),r=await Bt().callTool(this.mcpTool.name,t);if(!r.success)throw new Error(r.error||"MCP tool execution failed");let s=this.formatMCPResult(r.content);return Ks(s,s,!0)}argsToParams(e){if(e.length===1&&typeof e[0]=="object"&&!Array.isArray(e[0]))return e[0];let n=this.mcpTool.inputSchema.properties||{},r=Object.keys(n),s={};return e.forEach((i,a)=>{a<r.length&&(s[r[a]]=i)}),s}formatMCPResult(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>this.formatContentItem(t)).join(`
|
|
1571
|
+
|
|
1572
|
+
`):JSON.stringify(e,null,2)}formatContentItem(e){return typeof e=="string"?e:e.type==="text"?e.text||"":e.type==="image"?`[Image: ${e.data?.substring(0,50)}...]`:e.type==="resource"?`[Resource: ${e.uri||"unknown"}]`:JSON.stringify(e)}formatAction(e){let t=typeof e=="object"?Object.entries(e).map(([n,r])=>`${n}=${JSON.stringify(r)}`).join(", "):JSON.stringify(e);return`${this.mcpTool.name}(${t}) [MCP:${this.mcpTool.serverName}]`}formatObservation(e){return e&&e.__tool_result?String(e.display||e.result):String(e)}shouldPrintObservation(e){return!0}}});var Zs=S(()=>{Oc();Fc();Qs();Nc()});async function po(){if(ei){C("Tools already loaded, skipping");return}$("Loading tools..."),qt={...U},Uc={...qs};let o=Object.keys(U);$(`Loaded ${o.length} local tools`);let t=Bt().getAllTools();if(t.length===0){C("No MCP tools available"),ei=!0;return}let n=jc(t),r=_c(t),s=0,i=0;for(let[a,c]of Object.entries(n)){if(qt[a]){C(`Skipping MCP tool ${a} (local tool has priority)`),i++;continue}qt[a]=c,Uc[a]=r[a],s++}$(`Added ${s} MCP tools, skipped ${i} (local priority)`),$(`Total tools available: ${Object.keys(qt).length}`),ei=!0}function Kt(){return qt}function Wc(){let o=Object.keys(U),e=Object.keys(qt),t=e.filter(n=>!o.includes(n));return{local:o.length,mcp:t.length,total:e.length,localTools:o,mcpTools:t}}var qt,Uc,ei,tr=S(()=>{Ee();Zs();Y();qt={},Uc={},ei=!1});var Vs={};j(Vs,{TOOL_DEFINITIONS:()=>mo,getRawToolDefinitions:()=>Ln,getToolDefinitions:()=>nr,getToolNames:()=>Vc,isRealTool:()=>Rg});function zc(o){return{name:o.name,description:o.description,input_schema:o.input_schema}}function nr(){let o=Kt();if(Object.keys(o).length===0)return mo.map(zc);let e=[],t=Me.getCurrentNestingLevel(),n=Me.MAX_NESTING_LEVEL,r=["think","todo","askUser"];t<n&&r.splice(1,0,"plan");for(let s of r)if(o[s]){let i=o[s].getDefinition();i&&e.push(i)}for(let[s,i]of Object.entries(o))if(!r.includes(s)&&i){let a=i.getDefinition();a&&e.push(a)}return e.filter(s=>s!=null).map(zc)}function Ln(){return mo}function Vc(){return mo.map(o=>o.name)}function Rg(o){return o!=="think"&&Vc().includes(o)}var mo,Ot=S(()=>{Ee();tr();Hs();mo=[U.think.getDefinition(),U.plan.getDefinition(),U.todo.getDefinition(),U.askUser.getDefinition(),U.quickProjectScan.getDefinition(),U.read.getDefinition(),U.write.getDefinition(),U.merge.getDefinition(),U.mkdir.getDefinition(),U.glob.getDefinition(),U.grep.getDefinition(),U.delete.getDefinition(),U.move.getDefinition(),U.copy.getDefinition(),U.searchReplace.getDefinition(),U.shell.getDefinition()]});function ti(o){return!o||typeof o!="string"?0:Math.ceil(o.length/4)}function Je(o){if(!Array.isArray(o))return 0;let e=0;for(let t of o){if(t.content&&typeof t.content=="string"&&(e+=ti(t.content)),t.tool_calls&&Array.isArray(t.tool_calls))for(let n of t.tool_calls)n.function&&(e+=ti(n.function.name||""),e+=ti(n.function.arguments||""));e+=4}return e}function fo(o,e){return!e||e<=0?0:o/e*100}function ni(o,e,t=80){return fo(o,e)>=t}function ri(o,e,t){return`\u26A0\uFE0F Token usage warning: ${o.toLocaleString()} / ${e.toLocaleString()} tokens (${t.toFixed(1)}%)`}var oi=S(()=>{});import rr from"chalk";var ho,Hc=S(()=>{oi();Y();ho=class{options;constructor(e={}){this.options={enabled:e.enabled??!0,threshold:e.threshold??.8,minKeepMessages:e.minKeepMessages??3,maxKeepMessages:e.maxKeepMessages??20,targetUsageAfterCompression:e.targetUsageAfterCompression??.6,useMixedSummary:e.useMixedSummary??!0,llmSummaryTokenThreshold:e.llmSummaryTokenThreshold??500}}shouldCompress(e,t){return this.options.enabled?Je(e)/t>=this.options.threshold:!1}async compress(e,t,n){let r=Je(e),s=e.length;$(`\u5F00\u59CB\u4E0A\u4E0B\u6587\u538B\u7F29: ${s} \u6761\u6D88\u606F, ${r} tokens`);let i=this.calculateDynamicWindowSize(e,t);C(`\u52A8\u6001\u7A97\u53E3\u5927\u5C0F: \u4FDD\u7559\u6700\u8FD1 ${i} \u6761\u5B8C\u6574\u6D88\u606F`);let a=e.slice(0,-i),c=e.slice(-i);if(a.length===0)return H("\u6CA1\u6709\u9700\u8981\u538B\u7F29\u7684\u6D88\u606F,\u8DF3\u8FC7\u538B\u7F29"),{messages:e,stats:{originalMessageCount:s,originalTokenCount:r,compressedMessageCount:s,compressedTokenCount:r,compressionRatio:1,llmSummaryCount:0,heuristicSummaryCount:0}};let{summaryMessage:l,llmCount:g,heuristicCount:p}=await this.createCompressedSummary(a,n),u=[l,...c],m=Je(u),d={originalMessageCount:s,originalTokenCount:r,compressedMessageCount:u.length,compressedTokenCount:m,compressionRatio:m/r,llmSummaryCount:g,heuristicSummaryCount:p};return this.logCompressionStats(d),{messages:u,stats:d}}calculateDynamicWindowSize(e,t){let r=Je(e)/t,s;return r>=.9?(s=this.options.minKeepMessages,C("Token\u538B\u529B\u6781\u9AD8 (>=90%), \u4F7F\u7528\u6700\u5C0F\u7A97\u53E3")):r>=.85?(s=Math.floor(this.options.minKeepMessages+(this.options.maxKeepMessages-this.options.minKeepMessages)*.25),C("Token\u538B\u529B\u9AD8 (>=85%), \u4F7F\u7528\u8F83\u5C0F\u7A97\u53E3")):r>=.8?(s=Math.floor(this.options.minKeepMessages+(this.options.maxKeepMessages-this.options.minKeepMessages)*.5),C("Token\u538B\u529B\u4E2D\u7B49 (>=80%), \u4F7F\u7528\u4E2D\u7B49\u7A97\u53E3")):(s=this.options.maxKeepMessages,C("Token\u538B\u529B\u6B63\u5E38, \u4F7F\u7528\u6700\u5927\u7A97\u53E3")),Math.min(s,e.length)}async createCompressedSummary(e,t){let n=[],r=0,s=0,i=this.groupMessages(e);for(let c of i){let l=Je(c),g=this.assessMessageImportance(c),p;this.options.useMixedSummary&&g==="important"&&l>=this.options.llmSummaryTokenThreshold&&t?(p=await this.generateLLMSummary(c,t),r++,C(`\u4F7F\u7528LLM\u6458\u8981 (${c.length}\u6761\u6D88\u606F, ${l} tokens)`)):(p=this.generateHeuristicSummary(c),s++,C(`\u4F7F\u7528\u542F\u53D1\u5F0F\u6458\u8981 (${c.length}\u6761\u6D88\u606F, ${l} tokens)`)),n.push(p)}return{summaryMessage:{role:"system",content:`[\u5386\u53F2\u4E0A\u4E0B\u6587\u6458\u8981]
|
|
1374
1573
|
\u4EE5\u4E0B\u662F\u4E4B\u524D\u7684\u5BF9\u8BDD\u6458\u8981,\u5DF2\u538B\u7F29\u4EE5\u8282\u7701token:
|
|
1375
1574
|
|
|
1376
1575
|
${n.join(`
|
|
@@ -1379,35 +1578,170 @@ ${n.join(`
|
|
|
1379
1578
|
|
|
1380
1579
|
`)}
|
|
1381
1580
|
|
|
1382
|
-
[\u6458\u8981\u7ED3\u675F]`},llmCount:
|
|
1383
|
-
`);return`\u{1F4DD} ${(await t({model:n(),messages:[{role:"system",content:"\u4F60\u662F\u4E00\u4E2A\u5BF9\u8BDD\u6458\u8981\u52A9\u624B\u3002\u8BF7\u5C06\u4E0B\u9762\u7684\u5BF9\u8BDD\u538B\u7F29\u6210\u7B80\u6D01\u7684\u6458\u8981(\u4E0D\u8D85\u8FC7150\u5B57),\u4FDD\u7559\u5173\u952E\u64CD\u4F5C\u3001\u7ED3\u679C\u548C\u91CD\u8981\u4FE1\u606F\u3002"},{role:"user",content:
|
|
1384
|
-
\u2728 \u4E0A\u4E0B\u6587\u538B\u7F29\u5B8C\u6210`)),console.log(
|
|
1385
|
-
`))
|
|
1386
|
-
${
|
|
1387
|
-
`));let
|
|
1388
|
-
`))}else
|
|
1389
|
-
${
|
|
1390
|
-
`))}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1581
|
+
[\u6458\u8981\u7ED3\u675F]`},llmCount:r,heuristicCount:s}}groupMessages(e){let t=[];for(let r=0;r<e.length;r+=3)t.push(e.slice(r,r+3));return t}assessMessageImportance(e){for(let t of e){if(!t.content)continue;let n=t.content.toLowerCase();if(n.includes("error")||n.includes("warning")||n.includes("\u9519\u8BEF")||n.includes("\u8B66\u544A")||t.tool_calls&&t.tool_calls.length>0||t.role==="system"||t.content&&t.content.length>1e3)return"important"}return"normal"}async generateLLMSummary(e,t){try{let{LITE_MODEL:n}=await Promise.resolve().then(()=>(ae(),yt)),r=e.filter(a=>a.content).map(a=>`${a.role}: ${a.content}`).join(`
|
|
1582
|
+
`);return`\u{1F4DD} ${(await t({model:n(),messages:[{role:"system",content:"\u4F60\u662F\u4E00\u4E2A\u5BF9\u8BDD\u6458\u8981\u52A9\u624B\u3002\u8BF7\u5C06\u4E0B\u9762\u7684\u5BF9\u8BDD\u538B\u7F29\u6210\u7B80\u6D01\u7684\u6458\u8981(\u4E0D\u8D85\u8FC7150\u5B57),\u4FDD\u7559\u5173\u952E\u64CD\u4F5C\u3001\u7ED3\u679C\u548C\u91CD\u8981\u4FE1\u606F\u3002"},{role:"user",content:r}],temperature:.1,max_tokens:200,useCompression:!0})).choices?.[0]?.message?.content?.trim()||"\u6267\u884C\u5B8C\u6210"}`}catch(n){return H(`LLM\u6458\u8981\u5931\u8D25,\u964D\u7EA7\u5230\u542F\u53D1\u5F0F\u65B9\u6CD5: ${n instanceof Error?n.message:String(n)}`),this.generateHeuristicSummary(e)}}generateHeuristicSummary(e){let t=[],n=[],r=!1;for(let i of e){if(i.tool_calls&&i.tool_calls.length>0)for(let a of i.tool_calls){let c=a.function.name;c!=="think"&&t.push(c)}if(i.content&&(i.content.includes("Error")||i.content.includes("\u9519\u8BEF"))&&(r=!0),i.content){let a=i.content.match(/\b(created|updated|fixed|implemented|tested|deployed|成功|失败|创建|更新|修复|实现)\b/gi);a&&n.push(...a.slice(0,3))}}let s=`\u6267\u884C\u4E86 ${e.length} \u8F6E\u5BF9\u8BDD`;if(t.length>0){let i=[...new Set(t)];s+=`, \u8C03\u7528\u5DE5\u5177: ${i.slice(0,3).join(", ")}`}return n.length>0&&(s+=`, \u5173\u952E\u64CD\u4F5C: ${[...new Set(n)].slice(0,3).join(", ")}`),r&&(s+=" \u26A0\uFE0F \u5305\u542B\u9519\u8BEF"),`\u{1F4AC} ${s}`}logCompressionStats(e){let t=(e.compressionRatio*100).toFixed(1),n=((1-e.compressionRatio)*100).toFixed(1);console.log(rr.green(`
|
|
1583
|
+
\u2728 \u4E0A\u4E0B\u6587\u538B\u7F29\u5B8C\u6210`)),console.log(rr.cyan(` \u6D88\u606F\u6570: ${e.originalMessageCount} \u2192 ${e.compressedMessageCount} (${e.compressedMessageCount-e.originalMessageCount})`)),console.log(rr.cyan(` Token: ${e.originalTokenCount} \u2192 ${e.compressedTokenCount} (\u8282\u7701 ${n}%)`)),console.log(rr.cyan(` \u538B\u7F29\u6BD4: ${t}%`)),console.log(rr.cyan(` \u6458\u8981\u65B9\u5F0F: LLM ${e.llmSummaryCount}\u6B21, \u542F\u53D1\u5F0F ${e.heuristicSummaryCount}\u6B21
|
|
1584
|
+
`)),$(`\u4E0A\u4E0B\u6587\u538B\u7F29: ${e.originalMessageCount}\u6761 \u2192 ${e.compressedMessageCount}\u6761, ${e.originalTokenCount}tokens \u2192 ${e.compressedTokenCount}tokens (${t}%)`)}updateOptions(e){this.options={...this.options,...e},C(`\u538B\u7F29\u914D\u7F6E\u5DF2\u66F4\u65B0: ${JSON.stringify(this.options)}`)}getOptions(){return{...this.options}}}});var jt={};j(jt,{callModelAPI:()=>ee,getDefaultSystemPrompt:()=>Dg});import or from"chalk";async function ee(o){let{model:e=o.useCompression?Pe():fe(),messages:t,temperature:n=.1,max_tokens:r,useCompression:s=!1,tools:i=nr(),tool_choice:a,compressionOptions:c,enableAutoCompression:l=!0}=o,g=s?await cn.getLiteProvider():await cn.getProvider();C(`\u6A21\u578B\u8C03\u7528\u914D\u7F6E: useCompression=${s}, \u6A21\u578B=${e}, provider=${g.getProviderType()}`),s?C(`\u6B63\u5728\u4F7F\u7528\u8F7B\u91CF\u6A21\u578B: ${e}`):C(`\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u578B: ${e}`),C(`\u5DE5\u5177\u6570\u91CF: ${i?i.length:0}`);let p=s?No():_o(),u=t,m=Je(u),d=fo(m,p),y=h=>(h/1e3).toFixed(1)+"k";if($(`\u4F7F\u7528\u6A21\u578B: ${e}, Token usage: ${y(m)} / ${y(p)} (${d.toFixed(1)}%)`),v.currentTaskId){let h=v.tasks.find(b=>b.id===v.currentTaskId);h&&(h.tokenCount=(h.tokenCount||0)+m)}if(l&&ni(m,p,80)){let h=ri(m,p,d);H(h),console.log(or.yellow(`
|
|
1585
|
+
${h}`)),console.log(or.cyan(`\u{1F504} \u6B63\u5728\u81EA\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587...
|
|
1586
|
+
`));let b=new ho(c);if(b.shouldCompress(u,p))try{let{messages:f,stats:T}=await b.compress(u,p,ee);u=f,m=T.compressedTokenCount,d=fo(m,p),$(`\u538B\u7F29\u540EToken\u4F7F\u7528: ${m} / ${p} (${d.toFixed(1)}%)`)}catch(f){H(`\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25: ${f instanceof Error?f.message:String(f)}`),console.log(or.yellow(`\u26A0\uFE0F \u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25,\u5C06\u4F7F\u7528\u539F\u59CB\u6D88\u606F\u7EE7\u7EED\u6267\u884C
|
|
1587
|
+
`))}else C("\u5F53\u524D\u4E0D\u6EE1\u8DB3\u538B\u7F29\u6761\u4EF6,\u8DF3\u8FC7\u538B\u7F29")}else if(ni(m,p,80)){let h=ri(m,p,d);H(h),console.log(or.yellow(`
|
|
1588
|
+
${h}`)),console.log(or.yellow(`Consider archiving old messages or starting a new session.
|
|
1589
|
+
`))}C(`\u6A21\u578B\u8BF7\u6C42: ${JSON.stringify({model:e,temperature:n,max_tokens:r,messages:u.length>0?`[${u[0].role}, ..., ${u[u.length-1].role}]`:"[]",tools:i?i.length:0})}`);let w;try{w=await g.callModel({model:e,messages:u,temperature:n,max_tokens:r,tools:i,tool_choice:a})}catch(h){throw K(`\u8C03\u7528\u6A21\u578BAPI\u65F6\u53D1\u751F\u9519\u8BEF: ${h instanceof Error?h.message:String(h)}`),h instanceof Error&&h.stack&&C(`\u9519\u8BEF\u5806\u6808: ${h.stack}`),h}if(!w)throw K("\u6A21\u578B\u8FD4\u56DE undefined \u6216 null"),new Error("\u6A21\u578BAPI\u8FD4\u56DE\u7A7A\u54CD\u5E94");if(!w.choices)throw K(`\u6A21\u578B\u8FD4\u56DE\u7F3A\u5C11choices\u5B57\u6BB5: ${JSON.stringify(w)}`),new Error("\u6A21\u578BAPI\u8FD4\u56DE\u7684\u54CD\u5E94\u7F3A\u5C11choices\u5B57\u6BB5");if(!Array.isArray(w.choices)||w.choices.length===0)throw K(`\u6A21\u578B\u8FD4\u56DE\u7A7A\u7684choices\u6570\u7EC4: ${JSON.stringify(w)}`),new Error("\u6A21\u578BAPI\u8FD4\u56DE\u7684choices\u4E3A\u7A7A");return C(`\u6A21\u578B\u8FD4\u56DE: ${JSON.stringify(w)}`),w}function Dg(){return"You are a helpful assistant."}var Ce=S(()=>{ae();Hi();De();Ot();Y();oi();Hc()});import*as ue from"fs";import*as Ge from"path";var si,Jc=S(()=>{Ce();ae();si={name:"explorer",description:"\u667A\u80FD\u63A2\u7D22\u9879\u76EE\u7ED3\u6784\uFF0C\u751F\u6210\u6587\u6863\u6216\u56DE\u7B54\u7ED3\u6784\u76F8\u5173\u95EE\u9898",keywords:["explore","\u9879\u76EE\u7ED3\u6784","\u6587\u4EF6\u5206\u6790","\u76EE\u5F55\u7ED3\u6784","\u9879\u76EE\u6982\u89C8","\u4EE3\u7801\u7EC4\u7EC7","\u67B6\u6784\u5206\u6790"],prompt:`\u4F60\u662F\u4E00\u4F4D\u9879\u76EE\u7ED3\u6784\u5206\u6790\u4E13\u5BB6\u3002\u4F60\u7684\u4EFB\u52A1\u662F\u667A\u80FD\u5730\u63A2\u7D22\u548C\u5206\u6790\u9879\u76EE\u7684\u6574\u4F53\u7ED3\u6784\uFF0C\u5E76\u751F\u6210\u9AD8\u8D28\u91CF\u7684\u603B\u7ED3\u578B\u63CF\u8FF0\u3002
|
|
1590
|
+
|
|
1591
|
+
## \u8F93\u51FA\u8981\u6C42
|
|
1592
|
+
|
|
1593
|
+
- **\u603B\u7ED3\u578B\u63CF\u8FF0**\uFF1A\u4F60\u7684\u8F93\u51FA\u5FC5\u987B\u662F\u7CBE\u7B80\u3001\u7ED3\u6784\u5316\u7684\u603B\u7ED3\uFF0C\u9002\u5408\u4F5C\u4E3A\u52A8\u6001\u63D0\u793A\u8BCD\u4F5C\u7528\u4E8E\u540E\u7EED\u5185\u5BB9
|
|
1594
|
+
- **\u4FBF\u4E8E\u6A21\u578B\u7406\u89E3**\uFF1A\u6E05\u6670\u63CF\u8FF0\u9879\u76EE\u7684\u6838\u5FC3\u7ED3\u6784\u3001\u4E3B\u8981\u6280\u672F\u6808\u548C\u5173\u952E\u6A21\u5757
|
|
1595
|
+
- **\u4FBF\u4E8E\u68C0\u7D22**\uFF1A\u4F7F\u7528\u660E\u786E\u7684\u5173\u952E\u8BCD\u548C\u5C42\u6B21\u7ED3\u6784\uFF0C\u65B9\u4FBF\u76EE\u5F55\u57FA\u4E8E\u6B64\u5185\u5BB9\u8F85\u52A9\u68C0\u7D22
|
|
1596
|
+
- **\u91CD\u70B9\u7A81\u51FA**\uFF1A\u4F18\u5148\u5448\u73B0\u9879\u76EE\u7684\u6838\u5FC3\u67B6\u6784\u3001\u4E3B\u8981\u529F\u80FD\u548C\u5173\u952E\u6587\u4EF6
|
|
1597
|
+
|
|
1598
|
+
## \u53EF\u7528\u5DE5\u5177
|
|
1599
|
+
|
|
1600
|
+
1. **quickProjectScan()** - \u5FEB\u901F\u626B\u63CF\u5E76\u751F\u6210\u5B8C\u6574\u7684\u9879\u76EE\u4FE1\u606F
|
|
1601
|
+
- \u81EA\u52A8\u626B\u63CF\u6240\u6709\u6587\u4EF6
|
|
1602
|
+
- \u5206\u6790\u76EE\u5F55\u7ED3\u6784
|
|
1603
|
+
- \u68C0\u6D4B\u7F16\u7A0B\u8BED\u8A00
|
|
1604
|
+
- \u751F\u6210 \`.nium/project/project.json\` \u6587\u4EF6
|
|
1605
|
+
- \u63A8\u8350\u7528\u4E8E\uFF1A\u9996\u6B21\u63A2\u7D22\u3001\u751F\u6210\u9879\u76EE\u4FE1\u606F
|
|
1606
|
+
|
|
1607
|
+
2. **glob(pattern)** - \u6309\u6A21\u5F0F\u641C\u7D22\u6587\u4EF6
|
|
1608
|
+
- \u4F8B\u5982\uFF1A\`glob('**/*.js')\` \u67E5\u627E\u6240\u6709 JS \u6587\u4EF6
|
|
1609
|
+
- \u4F8B\u5982\uFF1A\`glob('src/**/*')\` \u67E5\u627E src \u76EE\u5F55\u4E0B\u6240\u6709\u6587\u4EF6
|
|
1610
|
+
|
|
1611
|
+
3. **grep(pattern, path)** - \u5728\u6587\u4EF6\u4E2D\u641C\u7D22\u5185\u5BB9
|
|
1612
|
+
- \u4F8B\u5982\uFF1A\`grep('export.*API', 'src')\` \u67E5\u627E API \u5BFC\u51FA
|
|
1613
|
+
|
|
1614
|
+
4. **read(path)** - \u8BFB\u53D6\u6587\u4EF6\u5185\u5BB9
|
|
1615
|
+
- \u7528\u4E8E\u6DF1\u5165\u4E86\u89E3\u5173\u952E\u6587\u4EF6
|
|
1616
|
+
|
|
1617
|
+
## \u5DE5\u4F5C\u7B56\u7565
|
|
1618
|
+
|
|
1619
|
+
### \u573A\u666F 1\uFF1A\u7528\u6237\u8981\u6C42\u63A2\u7D22\u9879\u76EE\u6216\u751F\u6210\u9879\u76EE\u4FE1\u606F
|
|
1620
|
+
|
|
1621
|
+
**\u7B56\u7565\uFF1A\u4F7F\u7528\u5FEB\u901F\u626B\u63CF**
|
|
1622
|
+
|
|
1623
|
+
1. \u76F4\u63A5\u8C03\u7528 \`quickProjectScan()\` \u5DE5\u5177
|
|
1624
|
+
2. \u5DE5\u5177\u4F1A\u81EA\u52A8\u5B8C\u6210\u6240\u6709\u626B\u63CF\u548C\u4FE1\u606F\u6536\u96C6
|
|
1625
|
+
3. \u751F\u6210\u7CBE\u7B80\u7684\u603B\u7ED3\u578B\u63CF\u8FF0\uFF0C\u5305\u62EC\uFF1A
|
|
1626
|
+
- \u9879\u76EE\u540D\u79F0\u548C\u7248\u672C
|
|
1627
|
+
- \u4E3B\u8981\u6280\u672F\u6808
|
|
1628
|
+
- \u6838\u5FC3\u76EE\u5F55\u7ED3\u6784
|
|
1629
|
+
- \u4E3B\u8981\u529F\u80FD\u6A21\u5757
|
|
1630
|
+
- \u5173\u952E\u5165\u53E3\u6587\u4EF6
|
|
1631
|
+
|
|
1632
|
+
### \u573A\u666F 2\uFF1A\u7528\u6237\u63D0\u51FA\u5177\u4F53\u95EE\u9898\uFF08\u5982\u524D\u7AEF\u4EE3\u7801\u5728\u54EA\u91CC\uFF1F\uFF09
|
|
1633
|
+
|
|
1634
|
+
**\u7B56\u7565\uFF1A\u4F7F\u7528\u5DE5\u5177\u7EC4\u5408\u8FDB\u884C\u667A\u80FD\u5206\u6790**
|
|
1635
|
+
|
|
1636
|
+
1. \u4F7F\u7528 \`glob()\` \u641C\u7D22\u76F8\u5173\u6587\u4EF6
|
|
1637
|
+
2. \u5FC5\u8981\u65F6\u4F7F\u7528 \`read()\` \u8BFB\u53D6\u5173\u952E\u6587\u4EF6
|
|
1638
|
+
3. \u751F\u6210\u9488\u5BF9\u6027\u7684\u603B\u7ED3\u63CF\u8FF0\uFF0C\u76F4\u63A5\u56DE\u7B54\u7528\u6237\u95EE\u9898
|
|
1639
|
+
|
|
1640
|
+
### \u573A\u666F 3\uFF1A\u7528\u6237\u8981\u6C42\u63A2\u7D22\u5E76\u5206\u6790\u67D0\u4E2A\u65B9\u9762
|
|
1641
|
+
|
|
1642
|
+
**\u7B56\u7565\uFF1A\u6DF7\u5408\u4F7F\u7528**
|
|
1643
|
+
|
|
1644
|
+
1. \u5148\u8C03\u7528 \`quickProjectScan()\` \u83B7\u53D6\u6574\u4F53\u7ED3\u6784
|
|
1645
|
+
2. \u518D\u4F7F\u7528\u5176\u4ED6\u5DE5\u5177\u6DF1\u5165\u5206\u6790\u7279\u5B9A\u65B9\u9762
|
|
1646
|
+
3. \u6574\u5408\u4FE1\u606F\u5E76\u751F\u6210\u7ED3\u6784\u5316\u7684\u603B\u7ED3\u63CF\u8FF0
|
|
1647
|
+
|
|
1648
|
+
## \u793A\u4F8B\u8F93\u51FA\u683C\u5F0F
|
|
1649
|
+
|
|
1650
|
+
# \u9879\u76EE\u7ED3\u6784\u603B\u7ED3
|
|
1651
|
+
|
|
1652
|
+
## \u9879\u76EE\u6982\u89C8
|
|
1653
|
+
- \u540D\u79F0\uFF1Axxx
|
|
1654
|
+
- \u7248\u672C\uFF1Axxx
|
|
1655
|
+
- \u4E3B\u8981\u8BED\u8A00\uFF1Axxx
|
|
1656
|
+
- \u6784\u5EFA\u5DE5\u5177\uFF1Axxx
|
|
1657
|
+
|
|
1658
|
+
## \u6838\u5FC3\u76EE\u5F55\u7ED3\u6784
|
|
1659
|
+
- src/\uFF1A\u6E90\u4EE3\u7801\u76EE\u5F55
|
|
1660
|
+
- agent/\uFF1A\u667A\u80FD\u4F53\u76F8\u5173\u4EE3\u7801
|
|
1661
|
+
- tools/\uFF1A\u5DE5\u5177\u51FD\u6570
|
|
1662
|
+
- config/\uFF1A\u914D\u7F6E\u6587\u4EF6
|
|
1663
|
+
- test/\uFF1A\u6D4B\u8BD5\u6587\u4EF6\u76EE\u5F55
|
|
1664
|
+
- docs/\uFF1A\u6587\u6863\u76EE\u5F55
|
|
1665
|
+
|
|
1666
|
+
## \u4E3B\u8981\u529F\u80FD\u6A21\u5757
|
|
1667
|
+
1. \u667A\u80FD\u4F53\u7CFB\u7EDF\uFF1A\u5B9E\u73B0\u4E86 ReAct \u5FAA\u73AF\u548C\u4EFB\u52A1\u89C4\u5212
|
|
1668
|
+
2. \u5DE5\u5177\u7CFB\u7EDF\uFF1A\u63D0\u4F9B\u4E86\u6587\u4EF6\u64CD\u4F5C\u3001\u4EE3\u7801\u641C\u7D22\u7B49\u529F\u80FD
|
|
1669
|
+
3. \u4E0A\u4E0B\u6587\u7BA1\u7406\uFF1A\u667A\u80FD\u7BA1\u7406\u5BF9\u8BDD\u4E0A\u4E0B\u6587
|
|
1670
|
+
|
|
1671
|
+
## \u5173\u952E\u6587\u4EF6
|
|
1672
|
+
- src/main.ts\uFF1A\u9879\u76EE\u4E3B\u5165\u53E3
|
|
1673
|
+
- src/config/index.ts\uFF1A\u914D\u7F6E\u7BA1\u7406
|
|
1674
|
+
- src/agent/react-agent.ts\uFF1AReAct \u667A\u80FD\u4F53\u5B9E\u73B0
|
|
1675
|
+
|
|
1676
|
+
## \u6280\u672F\u6808
|
|
1677
|
+
- \u4E3B\u8981\u8BED\u8A00\uFF1ATypeScript
|
|
1678
|
+
- \u8FD0\u884C\u65F6\uFF1ANode.js
|
|
1679
|
+
- \u6838\u5FC3\u4F9D\u8D56\uFF1Axxx
|
|
1680
|
+
|
|
1681
|
+
## \u6838\u5FC3\u539F\u5219
|
|
1682
|
+
|
|
1683
|
+
1. **\u9AD8\u6548\u4F18\u5148**\uFF1A\u5BF9\u4E8E\u6807\u51C6\u7684\u63A2\u7D22\u8BF7\u6C42\uFF0C\u4F18\u5148\u4F7F\u7528 \`quickProjectScan()\`
|
|
1684
|
+
2. **\u7CBE\u51C6\u56DE\u7B54**\uFF1A\u5BF9\u4E8E\u5177\u4F53\u95EE\u9898\uFF0C\u4F7F\u7528\u6700\u5408\u9002\u7684\u5DE5\u5177\u7EC4\u5408
|
|
1685
|
+
3. **\u6DF1\u5EA6\u5206\u6790**\uFF1A\u5FC5\u8981\u65F6\u6DF1\u5165\u8BFB\u53D6\u548C\u5206\u6790\u5173\u952E\u4EE3\u7801\u6587\u4EF6
|
|
1686
|
+
4. **\u6E05\u6670\u8868\u8FBE**\uFF1A\u4EE5\u7ED3\u6784\u5316\u3001\u6613\u61C2\u7684\u65B9\u5F0F\u5448\u73B0\u5206\u6790\u7ED3\u679C
|
|
1687
|
+
5. **\u603B\u7ED3\u4F18\u5148**\uFF1A\u59CB\u7EC8\u751F\u6210\u7CBE\u7B80\u7684\u603B\u7ED3\u578B\u63CF\u8FF0\uFF0C\u907F\u514D\u5197\u4F59\u4FE1\u606F
|
|
1688
|
+
6. **\u4FBF\u4E8E\u68C0\u7D22**\uFF1A\u4F7F\u7528\u660E\u786E\u7684\u5173\u952E\u8BCD\u548C\u5C42\u6B21\u7ED3\u6784\uFF0C\u65B9\u4FBF\u540E\u7EED\u68C0\u7D22\u548C\u7406\u89E3`,finalAnswerCallback:async(o,e)=>{try{let t=process.cwd(),n=Ge.join(t,".nium","docs");ue.existsSync(n)||ue.mkdirSync(n,{recursive:!0});let r=Ge.join(n,"PROJECT.md"),s=`# \u9879\u76EE\u63A2\u7D22\u62A5\u544A
|
|
1689
|
+
|
|
1690
|
+
> \u751F\u6210\u65F6\u95F4: ${new Date().toLocaleString("zh-CN",{timeZone:"Asia/Shanghai"})}
|
|
1691
|
+
> \u751F\u6210\u5DE5\u5177: Explorer Agent
|
|
1692
|
+
|
|
1693
|
+
---
|
|
1694
|
+
|
|
1695
|
+
${o}
|
|
1696
|
+
|
|
1697
|
+
---
|
|
1698
|
+
|
|
1699
|
+
*\u6B64\u6587\u6863\u7531 Explorer Agent \u81EA\u52A8\u751F\u6210\uFF0C\u8BB0\u5F55\u4E86\u9879\u76EE\u7ED3\u6784\u5206\u6790\u7ED3\u679C\u3002*
|
|
1700
|
+
`;if(!ue.existsSync(r))ue.writeFileSync(r,s,"utf-8"),console.log(`
|
|
1701
|
+
\u2713 \u9879\u76EE\u63A2\u7D22\u7ED3\u679C\u5DF2\u4FDD\u5B58\u5230: ${Ge.relative(t,r)}`);else{let i=Ge.join(t,".nium","merge");ue.existsSync(i)||ue.mkdirSync(i,{recursive:!0});let a=`project-merge-${Date.now()}.md`,c=Ge.join(i,a),l=`# PROJECT.md \u5408\u5E76\u8BF7\u6C42
|
|
1702
|
+
|
|
1703
|
+
## \u5F53\u524D\u6587\u4EF6\u5185\u5BB9
|
|
1704
|
+
${ue.readFileSync(r,"utf-8")}
|
|
1705
|
+
|
|
1706
|
+
## \u65B0\u751F\u6210\u5185\u5BB9
|
|
1707
|
+
${s}
|
|
1708
|
+
|
|
1709
|
+
## \u5408\u5E76\u8981\u6C42
|
|
1710
|
+
\u8BF7\u6839\u636E\u4EE5\u4E0B\u539F\u5219\u5408\u5E76\u8FD9\u4E24\u4E2A\u5185\u5BB9\uFF1A
|
|
1711
|
+
1. \u4FDD\u7559\u6700\u65B0\u7684\u751F\u6210\u65F6\u95F4\u548C\u5DE5\u5177\u4FE1\u606F
|
|
1712
|
+
2. \u5408\u5E76\u9879\u76EE\u7ED3\u6784\u63CF\u8FF0\uFF0C\u4FDD\u7559\u66F4\u8BE6\u7EC6\u7684\u4FE1\u606F
|
|
1713
|
+
3. \u5408\u5E76\u6280\u672F\u6808\u4FE1\u606F\uFF0C\u53BB\u9664\u91CD\u590D\u5185\u5BB9
|
|
1714
|
+
4. \u5408\u5E76\u6838\u5FC3\u6A21\u5757\u5206\u6790\uFF0C\u4FDD\u7559\u6240\u6709\u6709\u7528\u4FE1\u606F
|
|
1715
|
+
5. \u786E\u4FDD\u5408\u5E76\u540E\u7684\u6587\u6863\u7ED3\u6784\u6E05\u6670\uFF0C\u4FBF\u4E8E\u9605\u8BFB\u548C\u68C0\u7D22
|
|
1716
|
+
6. \u4FDD\u6301\u8F93\u51FA\u4E3A\u7CBE\u7B80\u7684\u603B\u7ED3\u578B\u63CF\u8FF0\uFF0C\u9002\u5408\u4F5C\u4E3A\u52A8\u6001\u63D0\u793A\u8BCD
|
|
1717
|
+
`;ue.writeFileSync(c,l,"utf-8"),console.log(`
|
|
1718
|
+
\u2713 \u9879\u76EE\u63A2\u7D22\u7ED3\u679C\u5DF2\u751F\u6210\u5408\u5E76\u8BF7\u6C42: ${Ge.relative(t,c)}`),console.log(" \u6B63\u5728\u8C03\u7528\u6A21\u578B\u5904\u7406\u5408\u5E76\u903B\u8F91...");let g=`\u4F60\u662F\u4E00\u4F4D\u4E13\u4E1A\u7684\u6587\u6863\u5408\u5E76\u4E13\u5BB6\u3002\u8BF7\u6839\u636E\u63D0\u4F9B\u7684\u5408\u5E76\u8BF7\u6C42\uFF0C\u5C06\u5F53\u524D\u6587\u4EF6\u5185\u5BB9\u548C\u65B0\u751F\u6210\u5185\u5BB9\u5408\u5E76\u4E3A\u4E00\u4E2A\u9AD8\u8D28\u91CF\u7684 PROJECT.md \u6587\u4EF6\u3002
|
|
1719
|
+
|
|
1720
|
+
${l}
|
|
1721
|
+
|
|
1722
|
+
\u8BF7\u76F4\u63A5\u8FD4\u56DE\u5408\u5E76\u540E\u7684\u5B8C\u6574\u5185\u5BB9\uFF0C\u4E0D\u8981\u6DFB\u52A0\u4EFB\u4F55\u989D\u5916\u7684\u89E3\u91CA\u6216\u8BF4\u660E\u3002`,u=(await ee({model:fe(),messages:[{role:"user",content:g}],temperature:.1,max_tokens:4e3}))?.choices?.[0]?.message?.content;u?(ue.writeFileSync(r,u,"utf-8"),console.log(" \u2713 \u5408\u5E76\u5B8C\u6210\uFF0CPROJECT.md \u5DF2\u66F4\u65B0")):console.log(" \u26A0\uFE0F \u6A21\u578B\u672A\u8FD4\u56DE\u6709\u6548\u5408\u5E76\u7ED3\u679C")}e?.orchestratorContext&&(e.orchestratorContext.recordExplorationResult(o),console.log(" \u2713 \u63A2\u7D22\u7ED3\u679C\u5DF2\u8BB0\u5F55\u5230\u5168\u5C40\u4E0A\u4E0B\u6587"))}catch(t){console.error(`\u4FDD\u5B58\u9879\u76EE\u6587\u6863\u65F6\u51FA\u9519: ${t.message}`)}}}});function Gc(){return Object.values(Og)}var Og,Bc=S(()=>{_i();Jc();Og={[Fo.name]:Fo,[si.name]:si}});var kc={};j(kc,{SubAgentManager:()=>Co,getSubAgentManager:()=>Ht});import{existsSync as Fg,readFileSync as jg,readdirSync as _g}from"fs";import{join as Ng}from"path";import ge from"chalk";function Ht(o={}){return yo?o.matchStrategy&&yo.setMatchStrategy(o.matchStrategy):yo=new Co(o),yo}var Co,yo,co=S(()=>{Le();Bc();ae();Ce();tt();Co=class{subAgents;agentPerformance;matchStrategy;constructor(e={}){this.subAgents=new Map,this.agentPerformance=new Map,this.matchStrategy=e.matchStrategy||"hybrid",this.loadBuiltinAgents(),this.loadSubAgents()}loadBuiltinAgents(){try{let e=Gc();console.log(ge.blue(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] \u52A0\u8F7D ${e.length} \u4E2A\u5185\u7F6E\u5B50\u4EE3\u7406`)),e.forEach(t=>{this.subAgents.set(t.name,t)})}catch(e){console.log(ge.red(`\u274C \u52A0\u8F7D\u5185\u7F6E\u4EE3\u7406\u5931\u8D25: ${e.message}`))}}loadSubAgents(){let e=le("agents");if(!Fg(e)){console.log(ge.gray("[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] .nium/agents \u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u52A0\u8F7D\u81EA\u5B9A\u4E49\u5B50\u667A\u80FD\u4F53"));return}try{let n=_g(e).filter(r=>r.endsWith(".json")||r.endsWith(".md"));console.log(ge.blue(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] \u52A0\u8F7D ${n.length} \u4E2A\u81EA\u5B9A\u4E49\u5B50\u4EE3\u7406`));for(let r of n)try{let s=Ng(e,r),i=jg(s,"utf-8"),a;r.endsWith(".json")?a=JSON.parse(i):r.endsWith(".md")&&(a=this.parseFrontmatter(i)),this.validateConfig(a)?(this.subAgents.set(a.name,a),console.log(ge.green(`\u2713 \u52A0\u8F7D\u81EA\u5B9A\u4E49\u5B50\u667A\u80FD\u4F53: ${a.name}`))):console.log(ge.yellow(`\u26A0\uFE0F \u914D\u7F6E\u6587\u4EF6 ${r} \u683C\u5F0F\u65E0\u6548\uFF0C\u5DF2\u8DF3\u8FC7`))}catch(s){console.log(ge.red(`\u274C \u52A0\u8F7D\u914D\u7F6E\u6587\u4EF6 ${r} \u5931\u8D25: ${s.message}`))}}catch(t){console.log(ge.red(`\u274C \u8BFB\u53D6agents\u76EE\u5F55\u5931\u8D25: ${t.message}`))}}parseFrontmatter(e){let t=/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/,n=e.match(t);if(!n)throw new Error("\u65E0\u6548\u7684 frontmatter \u683C\u5F0F");let[,r,s]=n,i={},a=r.split(`
|
|
1723
|
+
`);for(let c of a){let l=c.trim();if(!l)continue;let g=l.match(/^(\w+)\s*[::]\s*(.+)$/);if(g){let[,p,u]=g;p==="keywords"?i.keywords=u.split(/[,,]/).map(m=>m.trim()).filter(m=>m):i[p]=u.trim()}}return i.prompt=s.trim(),i}validateConfig(e){return!(!e||typeof e!="object"||!e.name||typeof e.name!="string"||!e.description||typeof e.description!="string"||!e.prompt||typeof e.prompt!="string")}async matchSubAgent(e){if(this.subAgents.size===0)return null;let t=Array.from(this.subAgents.values());switch(this.matchStrategy){case"semantic":return await this.matchSubAgentWithAI(e,t);case"hybrid":let n=this.matchSubAgentWithKeywords(e);if(n)return console.log(ge.green(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] Hybrid\u7B56\u7565 - \u5173\u952E\u8BCD\u5339\u914D\u6210\u529F: ${n.name}`)),n;let r=await this.matchSubAgentWithAI(e,t);return r&&console.log(ge.green(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] Hybrid\u7B56\u7565 - \u8BED\u4E49\u5339\u914D\u6210\u529F: ${r.name}`)),r;case"keyword":default:return this.matchSubAgentWithKeywords(e)}}matchSubAgentWithKeywords(e){let t=e.toLowerCase(),n=[];for(let[r,s]of this.subAgents){let i=0;if(s.keywords&&Array.isArray(s.keywords))for(let g of s.keywords)t.includes(g.toLowerCase())&&(i+=10);t.includes(r.toLowerCase())&&(i+=5);let a=s.description.toLowerCase(),c=t.split(/\s+/).filter(g=>g.length>2&&a.includes(g));i+=c.length*2;let l=this.agentPerformance.get(r);if(l){let g=l.success/l.total;i+=g*5;let p=Math.max(0,1-(Date.now()-l.lastUsed)/(10080*60*1e3));i+=p*2}i>0&&n.push({agent:s,score:i})}if(n.length>0){n.sort((s,i)=>i.score-s.score);let r=n[0].agent;return console.log(ge.green(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] \u57FA\u4E8E\u5206\u6570\u5339\u914D\u5230\u667A\u80FD\u4F53: ${r.name} (\u5206\u6570: ${n[0].score.toFixed(1)})`)),r}return null}async matchSubAgentWithAI(e,t){let n=t.map(l=>`${l.name}: ${l.description}`).join(`
|
|
1724
|
+
`),r=ls(e,n),s=await ee({model:Pe(),messages:[{role:"user",content:r}],temperature:0,max_tokens:100,useCompression:!0}),{content:i}=s.choices[0].message,a=i?i.trim():"";return this.getSubAgent(a)||null}recordAgentPerformance(e,t,n){let r=this.agentPerformance.get(e)||{total:0,success:0,avgTime:0,lastUsed:Date.now()};r.total++,t&&r.success++,r.avgTime=(r.avgTime*(r.total-1)+n)/r.total,r.lastUsed=Date.now(),this.agentPerformance.set(e,r)}setMatchStrategy(e){return["keyword","semantic","hybrid"].includes(e)?(this.matchStrategy=e,console.log(ge.blue(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] \u5339\u914D\u7B56\u7565\u5DF2\u8BBE\u7F6E\u4E3A: ${e}`)),!0):(console.error(ge.red(`[\u5B50\u667A\u80FD\u4F53\u7BA1\u7406\u5668] \u65E0\u6548\u7684\u5339\u914D\u7B56\u7565: ${e}`)),!1)}getAllSubAgents(){return Array.from(this.subAgents.values())}getSubAgent(e){return this.subAgents.get(e)||null}},yo=null});import G from"chalk";import lt from"readline";async function So(o,e=!1,t=null,n=null){let r,s=null,i=Rr();if(Z("Initializing react loop with think-tool support"),e&&v.messages&&v.messages.length>0)Z(`Resuming existing session: ${v.sessionId}`),r=v.messages,Be(`\u6062\u590D\u4F1A\u8BDD [ID:${v.sessionId.substring(0,8)}]: ${v.currentTask}`),sn(G.green(`\u4ECE ${v.updatedAt} \u6062\u590D\u4E4B\u524D\u7684\u4F1A\u8BDD [ID:${v.sessionId.substring(0,8)}]`),t),J(G.gray(`\u4E4B\u524D\u7684\u4EFB\u52A1: ${v.currentTask}`),t),v.tasks&&v.tasks.length>0&&J(G.gray(`\u4F1A\u8BDD\u4E2D\u4EFB\u52A1\u6570\u91CF: ${v.tasks.length}`),t),J("",t);else if(o){Z(`Starting new task: ${o.substring(0,50)}${o.length>50?"...":""}`);let g=ce(),p=ze(g);await g.detectFileChanges();let u=p.generatePromptIntegrationContent();r=[{role:"system",content:u?`${et}
|
|
1725
|
+
|
|
1726
|
+
${u}`:et},{role:"user",content:o}],Be(`\u5F00\u59CB\u65B0\u4EFB\u52A1: ${o}`),(i.enableAnchorSystem||i.enableSemanticAnalysis)&&(s=new st(o,ee),Z("\u7EDF\u4E00\u951A\u70B9\u6CE8\u5165\u5668\u5DF2\u521D\u59CB\u5316")),hr(o),ie(r,o)}else{de("No user request provided and no session to resume");return}let a=0,c=100,l=0;for(Z(`Starting execution loop with max ${c} iterations`);a<c;){a++,Z(`Loop iteration ${a}`);try{if(s){let h=await s.injectAnchors({taskDescription:o||v.currentTask,iterations:a,messages:r,lastSemanticCheckIteration:l,session:t,logWarning:pt,callModelAPI:ee}),{messages:b,lastSemanticCheckIteration:f}=h;r=b,l=f}ie(r);let g=fe();t&&J(G.gray(`[\u8FED\u4EE3 ${a}] \u4F7F\u7528\u6A21\u578B: ${g}`),t),Z("Calling Model API with all tools including think");let p=await ee({model:g,messages:r,temperature:.1,tools:nr(),tool_choice:void 0});if(!p||!p.choices||p.choices.length===0){let h=`\u6A21\u578B\u8FD4\u56DE\u65E0\u6548\u54CD\u5E94: ${JSON.stringify(p)}`;throw de(h),new Error(h)}let{choices:u}=p,m=u[0],d=m?.message,y=null,w=null;if(d&&({content:y,tool_calls:w}=d,y&&y.trim())){if(Z(`Model returned text content: ${y.substring(0,100)}...`),!w||w.length===0){if(n?.finalAnswerCallback)try{await n.finalAnswerCallback(y)}catch(h){de(`Error in finalAnswerCallback: ${h}`)}sn(G.green(`
|
|
1727
|
+
\u6700\u7EC8\u7B54\u6848:`),t),J(G.white(y),t),J("",t),r.push({role:"assistant",content:y}),Be("\u4EFB\u52A1\u5B8C\u6210,\u5F52\u6863\u4F1A\u8BDD"),Ke(),Z("Breaking out of react loop after final answer");return}J(G.magenta(`\u{1F4AD} \u601D\u8003: ${y}`),t),J("",t)}if(w&&w.length>0){let h=w[0],b=h.function.name,f=h.function.arguments;Z(`Tool call: ${b} with args: ${f}`);let T;try{T=JSON.parse(f)}catch{de(`Failed to parse tool arguments: ${f}`),r.push({role:"user",content:`Error: Invalid JSON in tool arguments: ${f}`});continue}if(Dt(b)){let M=T.thought||"";J(G.magenta(`\u601D\u8003: ${M}`),t),J("",t),r.push({role:"assistant",content:y||null,tool_calls:[h]}),r.push({role:"tool",tool_call_id:h.id,content:"Noted. Continue."});continue}if(_s(b)){let M=Ns(h);if(M){let{answer:I,success:B}=M;if(n?.finalAnswerCallback)try{await n.finalAnswerCallback(I)}catch(V){de(`Error in finalAnswerCallback: ${V}`)}let Q=B?"\u2705":"\u26A0\uFE0F";sn(G.green(`
|
|
1728
|
+
${Q} \u4EFB\u52A1\u5B8C\u6210 (\u901A\u8FC7 finish \u5DE5\u5177):`),t),J(G.white(I),t),J("",t),r.push({role:"assistant",content:y||null,tool_calls:[h]}),r.push({role:"tool",tool_call_id:h.id,content:"Task completed successfully."}),r.push({role:"assistant",content:I}),Be("\u4EFB\u52A1\u5B8C\u6210(finish\u5DE5\u5177),\u5F52\u6863\u4F1A\u8BDD"),Ke(),Z("Breaking out of react loop after finish tool call");return}}let k=Kt()[b];if(!k){let M=`Unknown tool: ${b}`;de(M),r.push({role:"assistant",content:y||null,tool_calls:[h]}),r.push({role:"tool",tool_call_id:h.id,content:M});continue}let O=k.formatAction(T);J(G.cyan(`\u884C\u52A8: ${O}`),t),J("",t);try{let M=!1;if(b==="shell"&&k&&typeof k.getDynamicDefinition=="function"?M=k.getDynamicDefinition(T).requiresConfirmation||!1:M=Ln().find(te=>te.name===b)?.requiresConfirmation||!1,M&&!await Ug(b,T,t)){let te=`\u5DE5\u5177\u6267\u884C\u5DF2\u53D6\u6D88: ${b}`;Be(te),pt(G.yellow(`\u26A0 ${te}`),t),J(G.gray("\u60A8\u53EF\u4EE5\u7EE7\u7EED\u63D0\u4F9B\u65B0\u7684\u6307\u4EE4\u6216\u4FEE\u6539\u4E4B\u524D\u7684\u8BF7\u6C42\u3002"),t),r.push({role:"assistant",content:y||null,tool_calls:[h]}),r.push({role:"tool",tool_call_id:h.id,content:"Execution cancelled by user"});continue}Z(`\u6267\u884C\u5DE5\u5177: ${b}(${JSON.stringify(T)})`);let I=await Promise.resolve(k.execute(T));Z(`\u5DE5\u5177 ${b} \u6267\u884C\u5B8C\u6210`);let B=ln(I),Q=k?k.shouldPrintObservation(I):!0,L=`${k?k.formatObservation(I):String(I)}`;Q&&(J(G.yellow(`\u{1F4CA} \u89C2\u5BDF: ${L}`),t),J("",t)),r.push({role:"assistant",content:y||null,tool_calls:[h]}),r.push({role:"tool",tool_call_id:h.id,content:String(B)})}catch(M){let I=`\u5DE5\u5177\u6267\u884C\u9519\u8BEF: ${b} - ${M.message}`;de(I),de(I,t),J("",t),r.push({role:"assistant",content:y||null,tool_calls:[h]}),r.push({role:"tool",tool_call_id:h.id,content:`Error: ${I}`}),ie(r,o)}}if((!y||!y.trim())&&(!w||w.length===0)){if(Io("Model returned empty response"),m.finish_reason==="stop"){pt("\u4EFB\u52A1\u5B8C\u6210(\u6A21\u578B\u505C\u6B62)",t),Ke(),Z("Breaking out of react loop after model stop");return}r.push({role:"user",content:"Please continue or provide your final answer."})}}catch(g){de(`\u9519\u8BEF: ${g.message}`,t),pt("\u4F1A\u8BDD\u5DF2\u4FDD\u5B58\u3002\u4F7F\u7528 /resume \u7EE7\u7EED\u3002",t),ie(r,o);return}}if(a>=c){de("\u9519\u8BEF: \u5DF2\u8FBE\u5230\u6700\u5927\u8FED\u4EE3\u6B21\u6570",t);let g=Math.floor(a/i.compressionInterval),p=Math.floor(a/i.anchorInjectionInterval),u=Math.floor(a/i.semanticCheckInterval);Z(`\u4F18\u5316\u7EDF\u8BA1: \u538B\u7F29${g}\u6B21, \u951A\u70B9\u6CE8\u5165${p}\u6B21, \u8BED\u4E49\u68C0\u67E5${u}\u6B21`),ie(r,o)}}async function Ug(o,e,t=null){return new Promise(n=>{let r=0,s=[{text:"\u786E\u8BA4\u6267\u884C",value:!0},{text:"\u4E2D\u65AD\u6267\u884C",value:!1}],i=JSON.stringify(e),a=()=>{for(let d=0;d<8;d++)lt.moveCursor(process.stdout,0,-1),lt.clearLine(process.stdout,0);let m=t?G.yellow(`\u26A0 \u786E\u8BA4\u6267\u884C ${o}(${i})\uFF1F\u6B64\u64CD\u4F5C\u53EF\u80FD\u65E0\u6CD5\u64A4\u9500\u3002`):G.yellow(`\u26A0 Confirm execution of ${o}(${i})? This action may be irreversible.`);console.log(""),console.log(m),console.log(""),console.log(G.cyan("\u8BF7\u9009\u62E9 (\u4F7F\u7528\u4E0A\u4E0B\u7BAD\u5934\u952E\uFF0CEnter\u786E\u8BA4):")),console.log(""),s.forEach((d,y)=>{let w=y===r,h=w?G.green("> "):" ",b=w?G.green.bold(d.text):G.white(d.text);console.log(`${h}${b}`)}),console.log("")},c=process.stdin.isTTY?process.stdin.isRaw:!1,l=[],g=Kn();process.stdin.isTTY&&process.stdin.setRawMode(!0),g?g.__isHandlingConfirmation=!0:(l=process.stdin.listeners("keypress"),process.stdin.removeAllListeners("keypress"));let p=(m,d)=>{if(d.name==="up"){r=Math.max(0,r-1),a();return}else if(d.name==="down"){r=Math.min(s.length-1,r+1),a();return}else if(d.name==="return"||d.name==="enter"){u();for(let y=0;y<8;y++)lt.moveCursor(process.stdout,0,-1),lt.clearLine(process.stdout,0);n(s[r].value);return}else if(d.name==="escape"||d.ctrl&&d.name==="c"){u();for(let y=0;y<8;y++)lt.moveCursor(process.stdout,0,-1),lt.clearLine(process.stdout,0);n(!1);return}},u=()=>{g?(g.removeListener("keypress",p),delete g.__isHandlingConfirmation):(process.stdin.removeListener("keypress",p),l.forEach(m=>{process.stdin.on("keypress",m)})),process.stdin.isTTY&&process.stdin.setRawMode(c)};g?g.on("keypress",p):(lt.emitKeypressEvents(process.stdin),process.stdin.on("keypress",p)),a()})}var ii=S(()=>{ae();Ce();tt();Ee();tr();An();so();De();Ot();zn();fs();lo();ot();Wn();Y()});import _ from"chalk";async function qc(o,e=!1,t=null,n={}){await new sr(t,n).executeTask(o,e)}var sr,Kc=S(()=>{co();be();ii();tt();De();Y();ws();ao();Lr();sr=class{session;subAgentManager;orchestratorContext;progressiveDisclosure;workerContextBuilder;summaryExtractor;options;constructor(e=null,t={}){this.session=e,Ws(e);let n={matchStrategy:t.matchStrategy};this.subAgentManager=Ht(n),this.orchestratorContext=new Fe,this.progressiveDisclosure=new je(this.orchestratorContext),this.workerContextBuilder=new _e(this.orchestratorContext,this.progressiveDisclosure),this.summaryExtractor=new Ne,this.options={useLLMDisclosure:t.useLLMDisclosure!==void 0?t.useLLMDisclosure:!0,useLLMSummary:t.useLLMSummary!==void 0?t.useLLMSummary:!0,verbose:t.verbose||!1}}log(e){this.session?this.session.log(e):console.log(e)}info(e){this.session?this.session.info(e):console.log(_.blue(e))}success(e){this.session?this.session.success(e):console.log(_.green(e))}warning(e){this.session?this.session.warning(e):console.log(_.yellow(e))}error(e){this.session?this.session.error(e):console.log(_.red(e))}async executeTask(e,t=!1){try{if(C("MasterAgent.executeTask called"),t){C("Entering resume session mode"),this.info("\u6062\u590D\u4F1A\u8BDD\u6A21\u5F0F"),await So(e,!0,this.session);return}let{evaluateTaskComplexity:n,TaskComplexity:r}=await Promise.resolve().then(()=>(be(),Oe));await n(e)===r.COMPLEX?await this.executeWithPlanning(e):await this.executeWithSingleAgent(e),this.log(""),this.success("\u2705 \u4EFB\u52A1\u6267\u884C\u5B8C\u6210"),this.options.verbose&&(this.log(""),this.log(_.gray("\u2550\u2550\u2550 \u5168\u5C40\u4E0A\u4E0B\u6587\u6458\u8981 \u2550\u2550\u2550")),this.log(_.gray(JSON.stringify(this.orchestratorContext.getCompactSummary(),null,2))))}catch(n){throw this.error(`\u274C \u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${n.message}`),n}}async executeWithSingleAgent(e){await this.ensureProjectStructure();let t={markdown:"",tasks:[{step:1,description:e,status:"pending",subAgent:"default"}],taskId:"",strategy:"single-agent",totalSteps:1};this.orchestratorContext.initializeTask(e,t);let n=await this.subAgentManager.matchSubAgent(e);if(n){this.info(`\u5339\u914D\u5230\u4E13\u7528\u5B50\u667A\u80FD\u4F53: ${n.name}`),this.log("");let r=await this.workerContextBuilder.buildIsolatedContext(1,e,n.prompt,!1,void 0,n.name);await this.executeSubAgentTask(1,e,n,r)}else this.info("\u4F7F\u7528\u9ED8\u8BA4React\u667A\u80FD\u4F53"),this.log(""),await So(e,!1,this.session)}async executeWithPlanning(e){let t=this.subAgentManager.getAllSubAgents(),n=await Rn(e,t);this.orchestratorContext.initializeTask(e,n),n.taskId&&ft(n.taskId),this.log(Dn(n)),this.log(""),await this.ensureProjectStructure(),await this.loadProjectRules(),this.analyzeStepDependencies(n);for(let r=0;r<n.tasks.length;r++){let s=n.tasks[r],i=s.step;this.log(""),this.info(`\u2501\u2501\u2501 \u6267\u884C\u6B65\u9AA4 ${i}/${n.tasks.length} \u2501\u2501\u2501`),this.log(_.cyan(`\u{1F4CC} ${s.description}`)),this.log(""),this.orchestratorContext.plan.currentStep=i,n.taskId&&await nt(n.taskId,i,"in_progress");try{let a=this.getSubAgentConfig(s),c=await this.workerContextBuilder.buildIsolatedContext(i,s.description,a?.prompt||"",this.options.useLLMDisclosure,void 0,a?.name);this.options.verbose&&this.log(_.gray(`\u4E0A\u4E0B\u6587\u5927\u5C0F: ${c.length} \u6761\u6D88\u606F`)),a?await this.executeSubAgentTask(i,s.description,a,c):await this.executeDefaultAgentWithContext(s.description,c),this.success(`\u2705 \u6B65\u9AA4 ${i} \u5B8C\u6210`),n.taskId&&await nt(n.taskId,i,"completed")}catch(a){throw this.error(`\u274C \u6B65\u9AA4 ${i} \u6267\u884C\u5931\u8D25: ${a.message}`),this.warning("\u4E2D\u6B62\u540E\u7EED\u6B65\u9AA4\u6267\u884C"),this.orchestratorContext.recordStepCompletion(i,`\u5931\u8D25: ${a.message}`,{success:!1,error:a.message}),a}}}async ensureProjectStructure(){try{let{existsSync:e}=await import("fs");if(e(".nium/project/project.json")){C("project.json \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u751F\u6210");return}this.log(""),this.info("\u{1F4CB} \u68C0\u6D4B\u5230\u9879\u76EE\u7ED3\u6784\u6587\u6863\u4E0D\u5B58\u5728\uFF0C\u6267\u884C\u5FEB\u901F\u626B\u63CF..."),this.log("");let{tools:n}=await Promise.resolve().then(()=>(Ee(),Gn));await n.quickProjectScan(),this.success("\u2705 \u9879\u76EE\u7ED3\u6784\u6587\u6863\u5DF2\u751F\u6210"),this.log(""),$("\u5DF2\u81EA\u52A8\u751F\u6210 project.json")}catch(e){C(`\u81EA\u52A8\u751F\u6210\u9879\u76EE\u7ED3\u6784\u6587\u6863\u5931\u8D25: ${e.message}`),this.warning("\u9879\u76EE\u7ED3\u6784\u6587\u6863\u751F\u6210\u5931\u8D25\uFF0C\u5C06\u7EE7\u7EED\u6267\u884C\u4EFB\u52A1")}}async loadProjectRules(){try{let{tools:e,toolInstances:t,extractToolResult:n}=await Promise.resolve().then(()=>(Ee(),Gn)),r="",i=e.read({path:".nium/rules.md"});i&&!i.includes("Error:")&&(r+=i,$("\u5DF2\u52A0\u8F7D\u9879\u76EE\u89C4\u5219\u6587\u4EF6"));let c=e.read({path:".nium/project/project.json"});if(c&&!c.includes("Error:")){r&&(r+=`
|
|
1396
1729
|
|
|
1397
1730
|
---
|
|
1398
1731
|
|
|
1399
|
-
`),
|
|
1732
|
+
`),r+=`## \u9879\u76EE\u5173\u952E\u4FE1\u606F
|
|
1400
1733
|
|
|
1401
|
-
`;try{let l=JSON.parse(c)
|
|
1734
|
+
`;try{let l=JSON.parse(c),g=this.extractProjectKeySummary(l);r+=g,$("\u5DF2\u52A0\u8F7D\u9879\u76EE\u5173\u952E\u4FE1\u606F\u6458\u8981")}catch{r+=c,C("\u89E3\u6790\u9879\u76EE\u7ED3\u6784JSON\u5931\u8D25\uFF0C\u4F7F\u7528\u539F\u59CB\u5185\u5BB9")}}r&&this.orchestratorContext.updateSharedState("rules",r)}catch{C("\u52A0\u8F7D\u9879\u76EE\u6587\u6863\u65F6\u51FA\u9519\uFF0C\u8DF3\u8FC7")}}analyzeStepDependencies(e){for(let t=0;t<e.tasks.length;t++){let n=e.tasks[t].step,r=t>0?[e.tasks[t-1].step]:[];this.orchestratorContext.setStepDependencies(n,r)}C("\u6B65\u9AA4\u4F9D\u8D56\u5173\u7CFB\u5DF2\u5206\u6790")}getSubAgentConfig(e){return e.subAgent&&e.subAgent!=="default"?this.subAgentManager.getSubAgent(e.subAgent):null}async executeSubAgentTask(e,t,n,r){let s=Date.now();this.info(`\u{1F527} \u4F7F\u7528\u5B50\u667A\u80FD\u4F53: ${n.name}`),this.log(_.gray(`\u63CF\u8FF0: ${n.description}`)),this.log("");try{let i=[{role:"system",content:et},...r.filter(g=>g.role!=="system"),...r.filter(g=>g.role==="system"&&g!==r[0])],a={...n,orchestratorContext:this.orchestratorContext},c=await this.runWorkerLoop(i,t,a);await this.recordWorkerResult(e,c);let l=Date.now()-s;this.subAgentManager.recordAgentPerformance(n.name,!0,l)}catch(i){let a=Date.now()-s;throw this.subAgentManager.recordAgentPerformance(n.name,!1,a),i}}async executeDefaultAgentWithContext(e,t){this.info("\u{1F916} \u4F7F\u7528\u9ED8\u8BA4React\u667A\u80FD\u4F53"),this.log("");let n=[{role:"system",content:et},...t.filter(r=>r.role!=="system"),...t.filter(r=>r.role==="system")];await this.runWorkerLoop(n,e)}async runWorkerLoop(e,t,n=null){let{MODEL:r}=await Promise.resolve().then(()=>(ae(),yt)),{callModelAPI:s}=await Promise.resolve().then(()=>(Ce(),jt)),{isThinkTool:i,extractThought:a}=await Promise.resolve().then(()=>(An(),os)),{isFinishTool:c,extractFinishInfo:l}=await Promise.resolve().then(()=>(so(),Us)),{getToolDefinitions:g}=await Promise.resolve().then(()=>(Ot(),Vs)),{tools:p,toolInstances:u,extractToolResult:m}=await Promise.resolve().then(()=>(Ee(),Gn)),d=[...e],y=0,w=50;for(;y<w;){y++;try{ie(d,t);let h=await s({model:r(),messages:d,temperature:.1,tools:g()}),b=h.choices[0].message.tool_calls;if(h.choices[0].finish_reason==="stop"){let{content:L}=h.choices[0].message;if(L&&L.trim()){if(n?.finalAnswerCallback)try{await n.finalAnswerCallback(L,n)}catch(re){K(`Error in finalAnswerCallback: ${re}`)}this.log(_.green("\u4EFB\u52A1\u5B8C\u6210:")),this.log(L),this.log("")}break}if(!b||b.length===0){let{content:L}=h.choices[0].message;if(L&&L.trim()){if(n?.finalAnswerCallback)try{await n.finalAnswerCallback(L,n)}catch(re){K(`Error in finalAnswerCallback: ${re}`)}this.log(_.green("\u4EFB\u52A1\u5B8C\u6210:")),this.log(L),this.log(""),d.push({role:"assistant",content:L});break}continue}let f=b[0],T=f.function.name,x;try{x=JSON.parse(f.function.arguments),this.log(_.gray(`[DEBUG] Tool: ${T}`)),this.log(_.gray(`[DEBUG] Raw arguments: ${f.function.arguments.substring(0,200)}${f.function.arguments.length>200?"...":""}`)),this.log(_.gray(`[DEBUG] Parsed keys: ${Object.keys(x).join(", ")}`)),this.log("")}catch{this.error(`\u89E3\u6790\u5DE5\u5177\u53C2\u6570\u5931\u8D25: ${f.function.arguments}`),d.push({role:"assistant",content:null,tool_calls:[f]}),d.push({role:"tool",tool_call_id:f.id,content:"Error: Invalid JSON arguments"});continue}if(i(T)){let L=a(f);L&&(this.log(_.cyan(`\u{1F4AD} Think: ${L}`)),this.log("")),d.push({role:"assistant",content:null,tool_calls:[f]}),d.push({role:"tool",tool_call_id:f.id,content:"Noted. Continue with your action."});continue}if(c(T)){let L=l(f);if(L){let{answer:re,success:te}=L;if(n?.finalAnswerCallback)try{await n.finalAnswerCallback(re,n)}catch(z){K(`Error in finalAnswerCallback: ${z}`)}let Xt=te?"\u2705":"\u26A0\uFE0F";this.log(_.green(`${Xt} \u4EFB\u52A1\u5B8C\u6210 (\u901A\u8FC7 finish \u5DE5\u5177):`)),this.log(re),this.log(""),d.push({role:"assistant",content:null,tool_calls:[f]}),d.push({role:"tool",tool_call_id:f.id,content:"Task completed successfully."}),d.push({role:"assistant",content:re});break}}if(!p[T]){let L=`Error: Unknown tool '${T}'`;this.error(L),d.push({role:"assistant",content:null,tool_calls:[f]}),d.push({role:"tool",tool_call_id:f.id,content:L});continue}let k=g().find(L=>L.name===T);if(k&&k.input_schema&&k.input_schema.required){let L=k.input_schema.required||[],re=L.filter(te=>x[te]===void 0);if(re.length>0){let te=`Error: Missing required parameters: ${re.join(", ")}
|
|
1402
1735
|
|
|
1403
|
-
Tool: ${
|
|
1404
|
-
Required parameters: ${
|
|
1736
|
+
Tool: ${T}
|
|
1737
|
+
Required parameters: ${L.join(", ")}
|
|
1405
1738
|
Provided parameters: ${Object.keys(x).join(", ")||"none"}
|
|
1406
1739
|
|
|
1407
|
-
Please call the tool again with ALL required parameters.`;this.error(
|
|
1408
|
-
`
|
|
1409
|
-
`
|
|
1410
|
-
|
|
1740
|
+
Please call the tool again with ALL required parameters.`;this.error(te),d.push({role:"assistant",content:null,tool_calls:[f]}),d.push({role:"tool",tool_call_id:f.id,content:te});continue}}let O=u[T],M=O?O.formatAction(x):`${T}()`;this.log(_.blue(`\u{1F527} \u884C\u52A8: ${M}`)),this.log("");let I=await p[T](x),B=m(I),Q=O?O.shouldPrintObservation(I):!0,V=O?O.formatObservation(I):String(I);Q&&(this.log(_.yellow(`\u{1F4CA} \u89C2\u5BDF: ${V}`)),this.log("")),d.push({role:"assistant",content:null,tool_calls:[f]}),d.push({role:"tool",tool_call_id:f.id,content:String(B)}),["read","write","merge"].includes(T)&&x.path&&this.orchestratorContext.addRecentFile(x.path),ie(d,t)}catch(h){throw this.error(`\u9519\u8BEF: ${h.message}`),ie(d,t),h}}if(y>=w)throw this.error("\u9519\u8BEF: \u5DF2\u8FBE\u5230\u6700\u5927\u8FED\u4EE3\u6B21\u6570"),ie(d,t),new Error("Maximum iterations reached");return d}async recordWorkerResult(e,t){let n;this.options.useLLMSummary?n=await this.summaryExtractor.extractSummaryWithLLM(t):n=await this.summaryExtractor.extractSummary(t);let r=this.summaryExtractor.extractMetadata(t);r.success=!0,this.orchestratorContext.recordStepCompletion(e,n,r),this.options.verbose&&this.info(`\u6B65\u9AA4 ${e} \u6458\u8981\u5DF2\u8BB0\u5F55\u5230\u5168\u5C40\u4E0A\u4E0B\u6587`),this.options.verbose&&(this.log(""),this.log(_.gray("\u2500\u2500\u2500 \u6B65\u9AA4\u6267\u884C\u6458\u8981 \u2500\u2500\u2500")),this.log(_.gray(`\u6458\u8981: ${n}`)),this.log(_.gray(`\u5DE5\u5177: ${r.toolsUsed.join(", ")}`)),this.log(_.gray(`\u6587\u4EF6: ${r.filesAccessed.join(", ")}`)),this.log(_.gray(`\u8FED\u4EE3: ${r.iterations} \u6B21`)))}extractProjectKeySummary(e){let t=[];return t.push("**\u57FA\u672C\u4FE1\u606F**"),t.push(`- \u9879\u76EE\u540D\u79F0: ${e.name||"N/A"}`),t.push(`- \u4E3B\u8981\u8BED\u8A00: ${e.language||"N/A"}`),t.push(`- \u6784\u5EFA\u5DE5\u5177: ${e.build_tool||"N/A"}`),t.push(`- \u9879\u76EE\u7C7B\u578B: ${e.project_type||"N/A"}`),t.push(""),e.directory_structure&&e.directory_structure.length>0&&(t.push("**\u6838\u5FC3\u76EE\u5F55** (\u524D8\u4E2A)"),e.directory_structure.slice(0,8).forEach(n=>{t.push(`- ${n}`)}),t.push("")),e.entry_files&&e.entry_files.length>0&&(t.push("**\u5165\u53E3\u6587\u4EF6**"),e.entry_files.forEach(n=>{t.push(`- ${n}`)}),t.push("")),e.dependencies&&e.dependencies.length>0&&(t.push("**\u5173\u952E\u4F9D\u8D56** (\u524D12\u4E2A)"),t.push(e.dependencies.slice(0,12).join(", ")),t.push("")),t.join(`
|
|
1741
|
+
`)}formatProjectStructureInfo(e){return On(e,{format:"markdown",detailed:!0,customTitle:`# \u9879\u76EE\u7ED3\u6784\u4FE1\u606F
|
|
1742
|
+
`})}}});import{readFileSync as Wg}from"fs";import{join as zg}from"path";function Vg(){let o={useLLMDisclosure:!0,useLLMSummary:!0};try{let e=zg(process.cwd(),".nium",".env"),n=Wg(e,"utf-8").split(`
|
|
1743
|
+
`);for(let r of n)if(r.startsWith("USE_LLM_DISCLOSURE=")){let s=r.split("=")[1]?.trim()||"";C(`[\u914D\u7F6E\u8BFB\u53D6] \u4ECE .nium/.env \u6587\u4EF6\u4E2D\u8BFB\u53D6: USE_LLM_DISCLOSURE=${s}`),o.useLLMDisclosure=s.toLowerCase()==="true"}else if(r.startsWith("USE_LLM_SUMMARY=")){let s=r.split("=")[1]?.trim()||"";C(`[\u914D\u7F6E\u8BFB\u53D6] \u4ECE .nium/.env \u6587\u4EF6\u4E2D\u8BFB\u53D6: USE_LLM_SUMMARY=${s}`),o.useLLMSummary=s.toLowerCase()==="true"}}catch(e){C(`[\u914D\u7F6E\u8BFB\u53D6] \u65E0\u6CD5\u8BFB\u53D6 .nium/.env \u6587\u4EF6: ${e.message}`)}return process.env.USE_LLM_DISCLOSURE!==void 0&&(C(`[\u914D\u7F6E\u8BFB\u53D6] \u4ECE\u73AF\u5883\u53D8\u91CF\u4E2D\u8BFB\u53D6: USE_LLM_DISCLOSURE=${process.env.USE_LLM_DISCLOSURE}`),o.useLLMDisclosure=ms("USE_LLM_DISCLOSURE")),process.env.USE_LLM_SUMMARY!==void 0&&(C(`[\u914D\u7F6E\u8BFB\u53D6] \u4ECE\u73AF\u5883\u53D8\u91CF\u4E2D\u8BFB\u53D6: USE_LLM_SUMMARY=${process.env.USE_LLM_SUMMARY}`),o.useLLMSummary=ms("USE_LLM_SUMMARY")),o}async function ai(){try{let o=Vg();return $("[\u914D\u7F6E\u8BFB\u53D6] \u4F7F\u7528\u4E3B\u667A\u80FD\u4F53\uFF08\u4E0A\u4E0B\u6587\u9694\u79BB\u6A21\u5F0F\uFF09"),{executeMasterAgent:qc,MasterAgent:sr,config:o}}catch(o){throw K(`[\u914D\u7F6E\u8BFB\u53D6] \u914D\u7F6E\u8BFB\u53D6\u51FA\u9519: ${o}`),o}}var Yc=S(()=>{Kc();ii();Y();ds()});var Zc={};j(Zc,{COMMANDS:()=>ir,executeCommand:()=>xo,findCommand:()=>Qc,getAvailableCommands:()=>ar,initializeDynamicCommands:()=>Qg,printCommandHelp:()=>ci});import A from"chalk";async function Hg(o,e){if(!o){e.warning("\u8BF7\u63D0\u4F9B\u4EFB\u52A1\u8BF7\u6C42\u5185\u5BB9");return}e.log(),e.info("\u5F00\u59CB\u5904\u7406\u4EFB\u52A1..."),e.log();try{let{executeMasterAgent:t,config:n}=await ai();await t(o,!1,e,n),e.log(),v.sessionId&&(e.log(A.gray(`\u5F53\u524D\u4F1A\u8BDD ID: ${v.sessionId.substring(0,8)}`)),v.tasks&&v.tasks.length>0&&e.log(A.gray(`\u5F53\u524D\u4F1A\u8BDD\u4EFB\u52A1\u6570: ${v.tasks.length}`)),e.log())}catch(t){throw e.error(`\u4EFB\u52A1\u5904\u7406\u5931\u8D25: ${t.message}`),t}}async function Jg(o){if(v.messages&&v.messages.length>0&&v.currentTask){o.log(),o.info(`\u6B63\u5728\u6062\u590D\u4F1A\u8BDD [ID:${v.sessionId?v.sessionId.substring(0,8):"unknown"}]...`),o.log();try{let{executeMasterAgent:e,config:t}=await ai();await e(null,!0,o,t),o.log(),o.success("\u4F1A\u8BDD\u6062\u590D\u5B8C\u6210"),v.sessionId&&(o.log(A.gray(`\u4F1A\u8BDD ID: ${v.sessionId.substring(0,8)}`)),v.tasks&&v.tasks.length>0&&o.log(A.gray(`\u4F1A\u8BDD\u4EFB\u52A1\u6570: ${v.tasks.length}`)),o.log())}catch(e){throw o.error(`\u4F1A\u8BDD\u6062\u590D\u5931\u8D25: ${e.message}`),e}}else o.warning("\u6CA1\u6709\u53EF\u6062\u590D\u7684\u4F1A\u8BDD\u3002\u4F7F\u7528 /chat <\u8BF7\u6C42> \u5F00\u59CB\u65B0\u4EFB\u52A1\u3002")}function Gg(o){Ke(),o.success("\u4F1A\u8BDD\u5DF2\u5F52\u6863\u5E76\u6E05\u7A7A"),o.log()}function Bg(o){let e=Di();o.log(e)}function Xc(o){o.exit()}function qg(o){o.printHelp&&o.printHelp()}function Kg(o){o.log(),o.log(A.cyan("\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")),o.log(A.cyan(" \u{1F4E6} Available Tools ")),o.log(A.cyan("\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")),o.log();let e=Kt(),t=Wc();if(Object.keys(e).length===0){o.warning("No tools loaded yet. Tools will be available after starting a task."),o.log();return}if(o.log(A.bold("\u{1F4CA} Summary:")),o.log(A.gray(` Total Tools: ${t.total}`)),o.log(A.gray(` Local Tools: ${t.local}`)),o.log(A.gray(` MCP Tools: ${t.mcp}`)),o.log(),t.local>0){o.log(A.bold.green("\u{1F527} Local Tools:")),o.log();let{localTools:n}=t;for(let r of n){let s=e[r];if(s&&s.getDefinition){let i=s.getDefinition();o.log(A.green(` \u2022 ${i.name}`)),o.log(A.gray(` ${i.description}`)),o.log()}}}if(t.mcp>0){o.log(A.bold.magenta("\u{1F310} MCP Tools:")),o.log();let{mcpTools:n}=t;for(let r of n){let s=e[r];if(s&&s.getDefinition){let i=s.getDefinition(),a=i.description.match(/\[MCP:([^\]]+)\]/),c=a?a[1]:"unknown",l=i.description.replace(/\[MCP:[^\]]+\]\s*/,"");o.log(A.magenta(` \u2022 ${i.name}`)),o.log(A.gray(` ${l}`)),o.log(A.gray(` (from MCP server: ${c})`)),o.log()}}}o.log(A.cyan("\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")),o.log()}async function Yg(o){o.log(),o.info("\u6B63\u5728\u68C0\u67E5git\u53D8\u66F4...");try{if(!Un()){o.warning("\u6CA1\u6709\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),o.log();return}let e=_n(),t=Nn();o.log(),o.info("\u5F53\u524Dgit\u72B6\u6001:"),o.log(A.gray(e)),o.log();let n=t.length>500?t.substring(0,500)+`
|
|
1744
|
+
...(truncated)`:t;o.info("\u53D8\u66F4\u5185\u5BB9\u9884\u89C8:"),o.log(A.gray(n)),o.log(),o.info("\u6B63\u5728\u4F7F\u7528lite\u6A21\u578B\u751F\u6210commit message...");let s=[{role:"system",content:`\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684git commit message\u751F\u6210\u52A9\u624B\u3002
|
|
1411
1745
|
\u8BF7\u6839\u636E\u63D0\u4F9B\u7684git diff\u5185\u5BB9\uFF0C\u751F\u6210\u4E00\u4E2A\u7B80\u6D01\u660E\u4E86\u7684commit message\u3002
|
|
1412
1746
|
|
|
1413
1747
|
\u8981\u6C42\uFF1A
|
|
@@ -1424,9 +1758,9 @@ feat: \u6DFB\u52A0\u7528\u6237\u8BA4\u8BC1\u529F\u80FD
|
|
|
1424
1758
|
- \u6DFB\u52A0\u767B\u5F55\u548C\u6CE8\u518C\u63A5\u53E3
|
|
1425
1759
|
- \u66F4\u65B0\u7528\u6237\u6A21\u578B`},{role:"user",content:`\u8BF7\u4E3A\u4EE5\u4E0Bgit\u53D8\u66F4\u751F\u6210commit message:
|
|
1426
1760
|
|
|
1427
|
-
${t}`}],i=await
|
|
1761
|
+
${t}`}],i=await ee({messages:s,temperature:.3,useCompression:!0,tools:[]}),a="";if(i.choices&&i.choices.length>0){let{message:l}=i.choices[0];l.content&&(a=l.content.trim())}if(!a){o.error("\u751F\u6210commit message\u5931\u8D25"),o.log();return}o.log();let c=a+`
|
|
1428
1762
|
|
|
1429
|
-
[Generated by niumagents]`;
|
|
1430
|
-
${e.stack||""}`)
|
|
1431
|
-
Commands:`)),this.log(
|
|
1432
|
-
\u63D0\u793A: \u8F93\u5165 / \u540E\u8DDF\u90E8\u5206\u547D\u4EE4\u53EF\u8FDB\u884C\u6A21\u7CCA\u641C\u7D22`)),this.log()}printSessionWarning(){this.warning("\u26A0 \u68C0\u6D4B\u5230\u4E4B\u524D\u7684\u4F1A\u8BDD\uFF01\u4F7F\u7528 /resume \u7EE7\u7EED\u6216 /clear \u5F00\u59CB\u65B0\u4F1A\u8BDD\u3002"),this.log()}printHelp(){
|
|
1763
|
+
[Generated by niumagents]`;o.success("\u751F\u6210\u7684commit message:"),o.log(A.cyan("\u2500".repeat(50))),o.log(A.white(c)),o.log(A.cyan("\u2500".repeat(50))),o.log(),o.info("\u6B63\u5728\u6267\u884C git add ."),hs(),o.success("\u5DF2\u6682\u5B58\u6240\u6709\u53D8\u66F4"),o.info("\u6B63\u5728\u6267\u884C git commit..."),ys(c),o.success("\u63D0\u4EA4\u6210\u529F\uFF01"),o.log()}catch(e){throw o.error(`\u6267\u884Ccommit\u547D\u4EE4\u5931\u8D25: ${e.message}`),o.log(),e}}function Xg(o,e){o.warning(`\u672A\u77E5\u547D\u4EE4: /${e}`);let t=ir.map(n=>`/${n.name}`).join(", ");o.log(A.gray(`\u53EF\u7528\u547D\u4EE4: ${t}`))}function Qc(o){return ir.find(e=>e.name===o)||null}async function xo(o,e,t=""){let n=Qc(e);if(!n){Xg(o,e);return}if(n.requiresArg&&!t&&e!=="chat"){o.warning(`\u547D\u4EE4 /${e} \u9700\u8981\u53C2\u6570`);return}try{n.requiresArg?await n.handler(t,o):await n.handler(o)}catch(r){throw o.error(`\u6267\u884C\u547D\u4EE4 /${e} \u65F6\u51FA\u9519: ${r.message}`),r}}function ar(){return[...ir]}function ci(o){o.log(A.cyan("\u53EF\u7528\u547D\u4EE4:")),ir.forEach(e=>{let t=e.requiresArg?`/${e.name} <\u53C2\u6570>`:`/${e.name}`;o.log(` ${A.white(t)} - ${A.gray(e.description)}`)}),o.log(),o.log(A.gray("\u63D0\u793A: \u76F4\u63A5\u8F93\u5165\u5185\u5BB9\u5C06\u4F5C\u4E3A\u4EFB\u52A1\u8BF7\u6C42\u53D1\u9001")),o.log()}async function Qg(){try{let{isGitAvailable:o}=await Promise.resolve().then(()=>(Dr(),Fa)),e=o();console.log(A.gray(`Git\u73AF\u5883\u68C0\u67E5: ${e?"\u53EF\u7528":"\u4E0D\u53EF\u7528"}`)),console.log(e?A.green("\u2713 /commit \u547D\u4EE4\u53EF\u7528"):A.yellow("\u26A0 Git\u4E0D\u53EF\u7528\uFF0C/commit \u547D\u4EE4\u5C06\u4E0D\u53EF\u7528"))}catch(o){console.log(A.gray(`\u521D\u59CB\u5316\u52A8\u6001\u547D\u4EE4\u65F6\u51FA\u9519: ${o.message}`))}}var ir,li=S(()=>{De();Lo();Yc();tr();Dr();Ce();ir=[{name:"chat",description:"\u5F00\u59CB\u65B0\u4EFB\u52A1",handler:Hg,requiresArg:!0},{name:"resume",description:"\u6062\u590D\u4E2D\u65AD\u7684\u4F1A\u8BDD",handler:Jg,requiresArg:!1},{name:"commit",description:"\u4F7F\u7528AI\u603B\u7ED3\u53D8\u66F4\u5E76\u63D0\u4EA4git commit",handler:Yg,requiresArg:!1},{name:"clear",description:"\u5F52\u6863\u5E76\u6E05\u7A7A\u5F53\u524D\u4F1A\u8BDD",handler:Gg,requiresArg:!1},{name:"history",description:"\u67E5\u770B\u5F52\u6863\u4F1A\u8BDD",handler:Bg,requiresArg:!1},{name:"list_tools",description:"\u5217\u51FA\u6240\u6709\u53EF\u7528\u5DE5\u5177",handler:Kg,requiresArg:!1},{name:"exit",description:"\u9000\u51FA\u5E94\u7528",handler:Xc,requiresArg:!1},{name:"quit",description:"\u9000\u51FA\u5E94\u7528",handler:Xc,requiresArg:!1},{name:"help",description:"\u663E\u793A\u5E2E\u52A9\u4FE1\u606F",handler:qg,requiresArg:!1}]});Le();De();li();Y();ae();Zs();tr();lo();import W from"chalk";import Se from"readline";import Zg from"fuzzysort";var el="0.1.9";var Yt=ar(),wo=class{rl=null;isActive=!1;commandHistory=[];historyIndex=-1;debug=!1;skipLineProcessing=!1;lastExecutedCommand=null;constructor(e={}){this.debug=e.debug||!1,mr(this.debug)}async start(){try{if(!W)throw new Error("chalk\u6A21\u5757\u5BFC\u5165\u5931\u8D25");di(),pr(),$("\u4EA4\u4E92\u5F0F\u4F1A\u8BDD\u542F\u52A8"),this.debug&&(C("Debug\u6A21\u5F0F\u5DF2\u542F\u7528"),console.log(W.magenta("\u26A0 Debug\u6A21\u5F0F\u5DF2\u542F\u7528 - \u5C06\u663E\u793A\u8BE6\u7EC6\u65E5\u5FD7\u4FE1\u606F"))),await this.initializeMCP();let{initializeDynamicCommands:e}=await Promise.resolve().then(()=>(li(),Zc));await e(),this.rl=Se.createInterface({input:process.stdin,output:process.stdout,prompt:W.blue("nium> "),historySize:100,completer:()=>[[],""]}),$c(this.rl),process.stdin.isTTY&&(process.stdin.setRawMode(!0),this.setupKeypressHandling()),this.printWelcome(),Oo()&&v.messages&&v.messages.length>0&&v.currentTask&&this.printSessionWarning(),this.isActive=!0,this.rl.prompt(),this.setupCommandHandler(),this.setupCloseHandler()}catch(e){console.error("\u542F\u52A8\u4F1A\u8BDD\u65F6\u51FA\u9519:",e.message),console.error("\u9519\u8BEF\u5806\u6808:",e.stack),process.exit(1)}}async initializeMCP(){try{let e=Uo();if($(`Loaded ${e.length} MCP server configuration(s)`),e.length===0){C("No MCP servers configured"),await po();return}let t=Bt();$("Initializing MCP manager with configured servers..."),await t.initialize(e),$("Loading all tools (local + MCP)..."),await po();let n=t.getStatus();C(`MCP Status: ${n.serversConnected} servers connected, ${n.toolsAvailable} tools available`),n.serversConnected>0?console.log(W.green(`\u2713 Connected to ${n.serversConnected} MCP server(s), ${n.toolsAvailable} tools available`)):console.log(W.yellow(`\u26A0 Configured ${e.length} MCP server(s) but none connected`))}catch(e){K(`Failed to initialize MCP: ${e.message}`),C(`MCP initialization error details: ${e.message}
|
|
1764
|
+
${e.stack||""}`),$("Continuing with local tools only..."),await po()}}setupKeypressHandling(){Se.emitKeypressEvents(process.stdin,this.rl),process.stdin.on("keypress",(e,t)=>{this.isActive&&(this.rl.__isHandlingConfirmation||t&&(t.name==="up"&&this.commandHistory.length>0&&!t.ctrl&&!t.meta?(this.historyIndex===-1?this.historyIndex=this.commandHistory.length-1:this.historyIndex>0&&this.historyIndex--,this.updatePromptWithHistory()):t.name==="down"&&!t.ctrl&&!t.meta?(this.historyIndex>=0&&(this.historyIndex++,this.historyIndex>=this.commandHistory.length&&(this.historyIndex=-1)),this.updatePromptWithHistory()):t.name==="tab"&&this.handleTabCompletion()))})}async handleTabCompletion(){if(!this.rl)return;let e=this.rl.line.trim();if(e.startsWith("/")){let t=e.slice(1),[n]=t.split(" "),r=n?Zg.go(n,Yt,{key:"name"}):Yt.map(s=>({obj:s,score:0}));if(r.length===1){let s=r[0].obj,i=`/${s.name}${s.requiresArg?" ":""}`;s.requiresArg?(this.skipLineProcessing=!0,this.rl.line=i,this.rl.cursor=i.length,this.rl._refreshLine(),setTimeout(()=>{this.skipLineProcessing=!1},100)):(this.skipLineProcessing=!0,this.rl.line="",this.rl.cursor=0,this.commandHistory.push(i),this.historyIndex=-1,process.nextTick(async()=>{try{this.log(`\u6267\u884C\u547D\u4EE4: /${s.name}`),await s.handler(this)}catch(a){this.error(`\u6267\u884C\u547D\u4EE4 /${s.name} \u65F6\u51FA\u9519: ${a.message}`)}finally{this.isActive&&this.rl&&this.rl.prompt()}}))}else r.length>1&&await this.showCommandSelectionMenu(r)}}async showCommandSelectionMenu(e){if(!this.rl)return;let t=0,n=this.rl.getPrompt(),r=this.rl.line,s=process.stdin.isTTY?process.stdin.isRaw:!1,i=()=>{let a=e.length+3;for(let c=0;c<a;c++)Se.moveCursor(process.stdout,0,-1),Se.clearLine(process.stdout,0);Se.clearLine(process.stdout,1),console.log(""),console.log(W.yellow("\u8BF7\u9009\u62E9\u547D\u4EE4 (\u4F7F\u7528\u4E0A\u4E0B\u7BAD\u5934\u952E\uFF0CEnter\u786E\u8BA4\uFF0CEsc\u53D6\u6D88):")),console.log(""),e.forEach((c,l)=>{let g=c.obj,p=l===t,u=p?W.green("> "):" ",m=p?W.green.bold(`/${g.name}`):W.white(`/${g.name}`),d=W.gray(`- ${g.description}`);console.log(`${u}${m} ${d}`)}),process.stdout.write(n),this.rl.line=r,this.rl.cursor=r.length,this.rl._refreshLine()};return new Promise(a=>{process.stdin.isTTY&&process.stdin.setRawMode(!0);let c=(l,g)=>{if(g.name==="up")return t=Math.max(0,t-1),i(),!1;if(g.name==="down")return t=Math.min(e.length-1,t+1),i(),!1;if(g.name==="return"||g.name==="enter"){let p=e[t].obj,u=`/${p.name}${p.requiresArg?" ":""}`;this.rl.removeListener("keypress",c);for(let m=0;m<e.length+4;m++)Se.moveCursor(process.stdout,0,-1),Se.clearLine(process.stdout,0);return Se.clearLine(process.stdout,1),process.stdout.write(n),this.skipLineProcessing=!0,p.requiresArg?(this.skipLineProcessing=!0,this.rl.line=u,this.rl.cursor=u.length,this.rl._refreshLine(),setTimeout(()=>{this.skipLineProcessing=!1},100)):(this.rl.line="",this.rl.cursor=0,this.commandHistory.push(u),this.historyIndex=-1,process.nextTick(async()=>{try{this.log(`\u6267\u884C\u547D\u4EE4: /${p.name}`),await p.handler(this)}catch(m){this.error(`\u6267\u884C\u547D\u4EE4 /${p.name} \u65F6\u51FA\u9519: ${m.message}`)}finally{this.isActive&&this.rl&&this.rl.prompt()}})),a(),!1}else if(g.name==="escape"||g.ctrl&&g.name==="c"){for(let p=0;p<e.length+4;p++)Se.moveCursor(process.stdout,0,-1),Se.clearLine(process.stdout,0);return this.rl.removeListener("keypress",c),Se.clearLine(process.stdout,1),process.stdout.write(n),this.rl.line=r,this.rl.cursor=r.length,this.rl._refreshLine(),a(),!1}};this.rl.on("keypress",c),i()})}updatePromptWithHistory(){this.rl&&(this.historyIndex>=0&&this.historyIndex<this.commandHistory.length?(this.rl.line=this.commandHistory[this.historyIndex],this.rl.cursor=this.rl.line.length,this.rl._refreshLine()):(this.rl.line="",this.rl.cursor=0,this.rl._refreshLine()))}setupCommandHandler(){this.rl&&this.rl.on("line",async e=>{let t=e.trim();if(this.skipLineProcessing){this.skipLineProcessing=!1,this.isActive&&this.rl&&this.rl.prompt();return}if(t.startsWith("/")){let r=t.slice(1).split(" ")[0];if(Yt=ar(),!(r?Yt.some(i=>i.name===r):!1)&&r){this.isActive&&this.rl&&this.rl.prompt();return}}t&&(this.commandHistory.push(t),this.historyIndex=-1);try{await this.handleCommand(t),this.lastExecutedCommand=t}catch(n){this.error(`\u5904\u7406\u547D\u4EE4\u65F6\u51FA\u9519: ${n.message}`)}finally{this.isActive&&this.rl&&this.rl.prompt()}})}setupCloseHandler(){this.rl&&this.rl.on("close",()=>{this.isActive&&(this.isActive=!1,this.success("\u518D\u89C1\uFF01"),process.exit(0))})}async handleCommand(e){if(e)if(e.startsWith("/")){let t=e.slice(1).split(" "),n=t[0],r=t.slice(1).join(" ");try{await xo(this,n,r),n==="clear"&&this.rl&&(this.rl.line="",this.rl.cursor=0,this.rl._refreshLine())}catch(s){this.error(`\u6267\u884C\u4EFB\u52A1\u65F6\u51FA\u9519: ${s.message}`)}}else try{await xo(this,"chat",e)}catch(t){this.error(`\u6267\u884C\u4EFB\u52A1\u65F6\u51FA\u9519: ${t.message}`)}}printWelcome(){Yt=ar(),this.clear(),this.log(W.green(`NiumAgents-CLI v${el}`)),this.log(W.gray("Options:")),this.log(W.gray(" --debug - \u542F\u7528\u8C03\u8BD5\u6A21\u5F0F\u4EE5\u663E\u793A\u8BE6\u7EC6\u65E5\u5FD7")),this.log(W.gray(`
|
|
1765
|
+
Commands:`)),this.log(W.gray(" <request> - \u5F00\u59CB\u65B0\u4EFB\u52A1 (\u9ED8\u8BA4: /chat)"));let e=Yt.filter(t=>t.name!=="chat");for(let t of e)t.name==="exit"||t.name==="quit"?t.name==="exit"&&this.log(W.gray(" /exit \u6216 /quit - \u9000\u51FA")):this.log(W.gray(` /${t.name} - ${t.description}`));this.log(W.gray(`
|
|
1766
|
+
\u63D0\u793A: \u8F93\u5165 / \u540E\u8DDF\u90E8\u5206\u547D\u4EE4\u53EF\u8FDB\u884C\u6A21\u7CCA\u641C\u7D22`)),this.log()}printSessionWarning(){this.warning("\u26A0 \u68C0\u6D4B\u5230\u4E4B\u524D\u7684\u4F1A\u8BDD\uFF01\u4F7F\u7528 /resume \u7EE7\u7EED\u6216 /clear \u5F00\u59CB\u65B0\u4F1A\u8BDD\u3002"),this.log()}printHelp(){ci(this)}clear(){console.clear()}log(e=""){console.log(e)}success(e){console.log(W.green(e))}warning(e){console.log(W.yellow(e))}error(e){console.log(W.red(e))}info(e){console.log(W.blue(e))}exit(){$("\u4EA4\u4E92\u5F0F\u4F1A\u8BDD\u7ED3\u675F"),this.isActive=!1,this.rl&&this.rl.close()}};import xe from"chalk";async function ep(){try{let o=process.argv.slice(2),e=o.includes("--debug");(o.includes("--help")||o.includes("-h"))&&(console.log(xe.green("NiumAgents-CLI v0.1.8")),console.log(xe.gray("AI Code Agent")),console.log(),console.log(xe.gray("Options:")),console.log(xe.gray(" --debug - \u542F\u7528\u8C03\u8BD5\u6A21\u5F0F\u4EE5\u663E\u793A\u8BE6\u7EC6\u65E5\u5FD7")),console.log(xe.gray(" --help \u6216 -h - \u663E\u793A\u6B64\u5E2E\u52A9\u4FE1\u606F")),console.log(),console.log(xe.gray("Usage:")),console.log(xe.gray(" nium [options]")),console.log(xe.gray(" npm run start [options]")),console.log(),console.log(xe.gray("Example:")),console.log(xe.gray(" nium --debug")),console.log(xe.gray(" npm run start -- --debug")),process.exit(0)),await new wo({debug:e}).start()}catch(o){console.error("\u542F\u52A8\u5E94\u7528\u65F6\u51FA\u9519:",o.message),process.exit(1)}}ep();
|