hablas-ai 1.3.6 → 1.3.8
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/index.js +10 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ Expecting one of '${s.join("', '")}'`);let r=`${e}Help`;return this.on(r,i=>{let
|
|
|
31
31
|
|
|
32
32
|
`)}var je,un,bi,Ds,Ls,_i=L(()=>{"use strict";je=O(require("fs")),un=O(require("path")),bi=O(require("os")),Ds=un.join(bi.homedir(),".hablas","plugins"),Ls=un.join(bi.homedir(),".hablas","plugins.json")});var Dc={};Ne(Dc,{renderDiagnostics:()=>$i,runDiagnostics:()=>Ai});async function Ai(n){let e=[],t=process.version,s=parseInt(t.slice(1).split(".")[0],10);e.push({name:"Node.js",status:s>=20?"ok":s>=18?"warn":"error",message:s>=20?`${t} (recommended)`:s>=18?`${t} (works, but 20+ recommended)`:`${t} (too old, need 20+)`});let r=Mc.join(nt.homedir(),".hablas");if(e.push({name:"Config directory",status:ki.existsSync(r)?"ok":"warn",message:ki.existsSync(r)?r:"Not created yet (will be created on first use)"}),n.provider==="ollama")try{let i=await fetch(`${n.ollamaHost}/api/tags`,{signal:AbortSignal.timeout(5e3)});if(i.ok){let o=await i.json(),a=Array.isArray(o.models)?o.models.length:0;e.push({name:"Ollama",status:"ok",message:`Connected \u2014 ${a} models available`})}else e.push({name:"Ollama",status:"error",message:`HTTP ${i.status}`})}catch(i){let o=i instanceof Error?i.message:String(i);e.push({name:"Ollama",status:"error",message:o.includes("ECONNREFUSED")?"Not running \u2014 start with: ollama serve":`Connection failed: ${o}`})}else{let i=n.apiUrl||"unknown";try{let o=await fetch(`${i}/models`,{signal:AbortSignal.timeout(5e3),headers:{Authorization:"Bearer test"}});e.push({name:"API Provider",status:o.ok||o.status===401?"ok":"warn",message:`${i} \u2014 reachable`})}catch{e.push({name:"API Provider",status:"warn",message:`${i} \u2014 could not verify`})}}try{let i=nt.homedir();if(process.platform!=="win32"){let a=(0,Ic.execSync)(`df -h "${i}" | tail -1`,{encoding:"utf-8"}).trim().split(/\s+/),l=a[3]||"unknown",u=a[4]||"?";e.push({name:"Disk space",status:parseInt(u)>90?"warn":"ok",message:`${l} available (${u} used)`})}else e.push({name:"Disk space",status:"ok",message:"Check skipped on Windows"})}catch{e.push({name:"Disk space",status:"ok",message:"Could not determine"})}return e.push({name:"Active model",status:n.model?"ok":"warn",message:n.model||"No model configured"}),e.push({name:"Platform",status:"ok",message:`${nt.platform()} ${nt.arch()} \u2014 ${nt.cpus().length} cores, ${Math.round(nt.totalmem()/1024/1024/1024)}GB RAM`}),e}function $i(n){let e={ok:"\u2713",warn:"\u26A0",error:"\u2717"},t={ok:"\x1B[32m",warn:"\x1B[33m",error:"\x1B[31m"},s="\x1B[0m",r="\x1B[2m",i=[""," \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"," hablas doctor \u2014 System Diagnostics"," \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",""];for(let l of n){let u=`${t[l.status]}${e[l.status]}${s}`,d=l.name.padEnd(18);i.push(` ${u} ${d}${r}${l.message}${s}`)}let o=n.filter(l=>l.status==="error").length,a=n.filter(l=>l.status==="warn").length;return i.push(""),o>0?i.push(` ${t.error}${o} error(s) found \u2014 fix these for hablas to work properly${s}`):a>0?i.push(` ${t.warn}${a} warning(s) \u2014 hablas should work but check the items above${s}`):i.push(` ${t.ok}All checks passed \u2014 hablas is ready!${s}`),i.push(""),i.join(`
|
|
33
33
|
`)}var ki,Mc,nt,Ic,Ci=L(()=>{"use strict";ki=O(require("fs")),Mc=O(require("path")),nt=O(require("os")),Ic=require("child_process")});function Lc(){let n=[];for(let e of xe){let s=e.role==="hablas"?" \u2605":"";n.push(` @${e.name}${s} \u2014 ${e.title}`),n.push(` ${e.description}`)}return n.join(`
|
|
34
|
-
`)}var xe,Ns=L(()=>{"use strict";xe=[{role:"hablas",name:"Hablas",title:"Team Leader",description:"Software Engineer & Team Coordinator. Receives user requests, creates plans, distributes tasks, and compiles final responses.",expertise:["planning","coordination","architecture","code-review","decision-making"]},{role:"bob",name:"Bob",title:"Architect",description:"System Architect. Designs software architecture, database schemas, API structures, and system blueprints.",expertise:["system-design","architecture","database","api-design","scalability"]},{role:"alex",name:"Alex",title:"Engineer",description:"Full-Stack Engineer. Implements code, builds features, fixes bugs, handles DevOps and deployment.",expertise:["coding","implementation","debugging","devops","testing","deployment"]},{role:"david",name:"David",title:"Data Analyst",description:"Data & Research Specialist. Handles research, data analysis, documentation, and information gathering.",expertise:["research","data-analysis","documentation","ml","optimization"]},{role:"emma",name:"Emma",title:"Product Manager",description:"Product Manager. Analyzes user needs, creates PRDs, competitive analysis, market research, and requirement specifications.",expertise:["product-management","requirements","prd","market-research","competitive-analysis","user-stories"]}]});function zt(){try{if(Et.existsSync(Hn)){let n=Et.readFileSync(Hn,"utf-8"),e=JSON.parse(n);return{...Fc,...e}}}catch{}return{...Fc}}function Ei(n){let e=js.dirname(Hn);Et.existsSync(e)||Et.mkdirSync(e,{recursive:!0}),Et.writeFileSync(Hn,JSON.stringify(n,null,2),"utf-8")}function Ti(){return Hn}var Et,js,Nc,Hn,Fc,Ri=L(()=>{"use strict";Et=O(require("fs")),js=O(require("path")),Nc=O(require("os")),Hn=js.join(Nc.homedir(),".hablas","agents.json"),Fc={hablas:{model:"stepfun-ai/step-3.7-flash",temperature:.7},bob:{model:"stepfun-ai/step-3.7-flash",temperature:.4},alex:{model:"stepfun-ai/step-3.7-flash",temperature:.2},david:{model:"stepfun-ai/step-3.7-flash",temperature:.5},emma:{model:"stepfun-ai/step-3.7-flash",temperature:.6},gate:{model:"stepfun-ai/step-3.
|
|
34
|
+
`)}var xe,Ns=L(()=>{"use strict";xe=[{role:"hablas",name:"Hablas",title:"Team Leader",description:"Software Engineer & Team Coordinator. Receives user requests, creates plans, distributes tasks, and compiles final responses.",expertise:["planning","coordination","architecture","code-review","decision-making"]},{role:"bob",name:"Bob",title:"Architect",description:"System Architect. Designs software architecture, database schemas, API structures, and system blueprints.",expertise:["system-design","architecture","database","api-design","scalability"]},{role:"alex",name:"Alex",title:"Engineer",description:"Full-Stack Engineer. Implements code, builds features, fixes bugs, handles DevOps and deployment.",expertise:["coding","implementation","debugging","devops","testing","deployment"]},{role:"david",name:"David",title:"Data Analyst",description:"Data & Research Specialist. Handles research, data analysis, documentation, and information gathering.",expertise:["research","data-analysis","documentation","ml","optimization"]},{role:"emma",name:"Emma",title:"Product Manager",description:"Product Manager. Analyzes user needs, creates PRDs, competitive analysis, market research, and requirement specifications.",expertise:["product-management","requirements","prd","market-research","competitive-analysis","user-stories"]}]});function zt(){try{if(Et.existsSync(Hn)){let n=Et.readFileSync(Hn,"utf-8"),e=JSON.parse(n);return{...Fc,...e}}}catch{}return{...Fc}}function Ei(n){let e=js.dirname(Hn);Et.existsSync(e)||Et.mkdirSync(e,{recursive:!0}),Et.writeFileSync(Hn,JSON.stringify(n,null,2),"utf-8")}function Ti(){return Hn}var Et,js,Nc,Hn,Fc,Ri=L(()=>{"use strict";Et=O(require("fs")),js=O(require("path")),Nc=O(require("os")),Hn=js.join(Nc.homedir(),".hablas","agents.json"),Fc={hablas:{model:"stepfun-ai/step-3.7-flash",temperature:.7},bob:{model:"stepfun-ai/step-3.7-flash",temperature:.4},alex:{model:"stepfun-ai/step-3.7-flash",temperature:.2},david:{model:"stepfun-ai/step-3.7-flash",temperature:.5},emma:{model:"stepfun-ai/step-3.7-flash",temperature:.6},gate:{model:"stepfun-ai/step-3.5-flash",temperature:.3}}});var Ni={};Ne(Ni,{formatStats:()=>Sy,loadStats:()=>Bn,saveStats:()=>dn,trackAgentUsage:()=>Fi,trackFileModified:()=>wy,trackMessage:()=>Di,trackSession:()=>Ii,trackToolCall:()=>Li});function Bn(){try{if(Tt.existsSync(Pi))return JSON.parse(Tt.readFileSync(Pi,"utf-8"))}catch{}return vy()}function dn(n){try{Tt.existsSync(Oi)||Tt.mkdirSync(Oi,{recursive:!0}),Tt.writeFileSync(Pi,JSON.stringify(n,null,2))}catch{}}function vy(){return{totalSessions:0,totalMessages:0,totalTokensUsed:0,totalToolCalls:0,totalFilesModified:0,totalLinesWritten:0,totalBugsFixed:0,totalCommits:0,agentUsage:{},commandUsage:{},dailyActivity:{},streak:0,longestStreak:0,firstUsed:new Date().toISOString(),lastUsed:new Date().toISOString()}}function Ii(n){return n.totalSessions++,n.lastUsed=new Date().toISOString(),xy(n),n}function Di(n,e=0){n.totalMessages++,n.totalTokensUsed+=e;let t=Hs();return n.dailyActivity[t]||(n.dailyActivity[t]={messages:0,tokens:0,toolCalls:0,filesModified:0,linesWritten:0}),n.dailyActivity[t].messages++,n.dailyActivity[t].tokens+=e,n}function Li(n,e){n.totalToolCalls++,n.commandUsage[e]=(n.commandUsage[e]||0)+1;let t=Hs();return n.dailyActivity[t]||(n.dailyActivity[t]={messages:0,tokens:0,toolCalls:0,filesModified:0,linesWritten:0}),n.dailyActivity[t].toolCalls++,n}function Fi(n,e){return n.agentUsage[e]=(n.agentUsage[e]||0)+1,n}function wy(n,e=0){n.totalFilesModified++,n.totalLinesWritten+=e;let t=Hs();return n.dailyActivity[t]||(n.dailyActivity[t]={messages:0,tokens:0,toolCalls:0,filesModified:0,linesWritten:0}),n.dailyActivity[t].filesModified++,n.dailyActivity[t].linesWritten+=e,n}function xy(n){let e=Hs(),t=Hc(new Date(Date.now()-864e5));n.dailyActivity[t]||n.dailyActivity[e]?n.streak++:n.streak=1,n.streak>n.longestStreak&&(n.longestStreak=n.streak)}function Hs(){return Hc(new Date)}function Hc(n){return n.toISOString().split("T")[0]}function Sy(n){let e=[];e.push(`
|
|
35
35
|
\u{1F4CA} Developer Analytics`),e.push(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),e.push(` Sessions: ${n.totalSessions}`),e.push(` Messages: ${n.totalMessages}`),e.push(` Tokens used: ${n.totalTokensUsed.toLocaleString()}`),e.push(` Tool calls: ${n.totalToolCalls}`),e.push(` Files modified: ${n.totalFilesModified}`),e.push(` Lines written: ${n.totalLinesWritten.toLocaleString()}`),e.push(` Bugs fixed: ${n.totalBugsFixed}`),e.push(` Commits: ${n.totalCommits}`),e.push(""),e.push(` \u{1F525} Streak: ${n.streak} days (best: ${n.longestStreak})`),e.push("");let t=Object.entries(n.agentUsage).sort((r,i)=>i[1]-r[1]).slice(0,5);if(t.length>0){e.push(" Top Agents:");for(let[r,i]of t)e.push(` @${r}: ${i} uses`);e.push("")}let s=Object.entries(n.commandUsage).sort((r,i)=>i[1]-r[1]).slice(0,5);if(s.length>0){e.push(" Top Commands:");for(let[r,i]of s)e.push(` ${r}: ${i} calls`)}return e.join(`
|
|
36
36
|
`)}var Tt,Mi,jc,Oi,Pi,Un=L(()=>{"use strict";Tt=O(require("fs")),Mi=O(require("path")),jc=O(require("os")),Oi=Mi.join(jc.homedir(),".hablas"),Pi=Mi.join(Oi,"analytics.json")});var Uc={};Ne(Uc,{formatScanResults:()=>Hi,runSecurityScan:()=>ji});function $y(n,e){let t=[],s=e.split(`
|
|
37
37
|
`);for(let{pattern:r,name:i,severity:o}of _y){r.lastIndex=0;let a;for(;(a=r.exec(e))!==null;){let u=e.substring(0,a.index).split(`
|
|
@@ -963,7 +963,7 @@ Rate your work. Reply with ONLY a JSON object \u2014 no other text:
|
|
|
963
963
|
`)}getTurnSummary(){let e=this.turnSteps.length,t=this.turnSteps.filter(r=>r.action).length,s=this.turnSteps.filter(r=>r.reflection).length;return`${e} steps, ${t} actions, ${s} reflections`}}});function gs(n=3){return new Il(n)}var N$,Il,Dl=L(()=>{"use strict";N$=[{test:n=>/ENOENT|no such file|not found|does not exist/i.test(n),errorClass:"file_not_found",strategy:"read_first",explanation:"The file or directory does not exist.",suggestion:"Use list_dir to check what files exist, then retry with the correct path.",alternatives:["list_dir","search_codebase"],autoRetry:!1},{test:n=>/EACCES|permission denied/i.test(n),errorClass:"permission_denied",strategy:"graceful_fail",explanation:"Permission denied \u2014 the process lacks access rights.",suggestion:"Check file ownership or try a different path. Do NOT use sudo.",alternatives:[],autoRetry:!1},{test:n=>/EISDIR|is a directory/i.test(n),errorClass:"path_is_directory",strategy:"retry_fixed",explanation:"The path points to a directory, not a file.",suggestion:"Append the filename to the path. Use list_dir to see contents.",alternatives:["list_dir"],autoRetry:!1},{test:n=>/EEXIST|already exists/i.test(n),errorClass:"file_already_exists",strategy:"read_first",explanation:"A file or directory already exists at that path.",suggestion:"Read the existing file first, then decide whether to overwrite or edit it.",alternatives:["read_file","edit_file"],autoRetry:!1},{test:n=>/no match|not found in file|search string not found/i.test(n),errorClass:"search_no_match",strategy:"read_first",explanation:"The search string was not found in the file.",suggestion:"Read the file first to see its actual content, then use the exact text for search/replace.",alternatives:["read_file","search_codebase"],autoRetry:!1},{test:n=>/command not found|not recognized/i.test(n),errorClass:"command_not_found",strategy:"alternative_tool",explanation:"The command does not exist on this system.",suggestion:"Check if the program is installed, or use a different command that achieves the same goal.",alternatives:["run_command"],autoRetry:!1},{test:n=>/timeout|timed out|ETIMEDOUT/i.test(n),errorClass:"command_timeout",strategy:"retry_fixed",explanation:"The command took too long and was terminated.",suggestion:"Try a simpler version of the command, or increase the timeout, or run it in background.",alternatives:[],autoRetry:!1},{test:n=>/exit code|exited with|non-zero/i.test(n),errorClass:"command_exit_error",strategy:"retry_fixed",explanation:"The command executed but returned an error.",suggestion:"Read the error output carefully. Fix the root cause (missing dependency, wrong syntax, etc.).",alternatives:[],autoRetry:!1},{test:n=>/syntax error|unexpected token|parse error|SyntaxError/i.test(n),errorClass:"syntax_error",strategy:"retry_fixed",explanation:"The content has a syntax error.",suggestion:"Review the generated code for syntax issues, fix them, and retry.",alternatives:[],autoRetry:!1},{test:n=>/ECONNREFUSED|ECONNRESET|ENOTFOUND|fetch failed|network/i.test(n),errorClass:"network_error",strategy:"retry_same",explanation:"Network connection failed.",suggestion:"This may be transient. Retry the same operation, or check connectivity.",alternatives:[],autoRetry:!0},{test:n=>/invalid argument|missing required|expected.*but got|type error/i.test(n),errorClass:"invalid_arguments",strategy:"retry_fixed",explanation:"The tool was called with invalid or missing arguments.",suggestion:"Check the tool's parameter requirements and provide correct values.",alternatives:[],autoRetry:!1},{test:n=>/ENOMEM|out of memory|resource|too large|max.*exceeded/i.test(n),errorClass:"resource_limit",strategy:"decompose_task",explanation:"Resource limit exceeded (memory, file size, etc.).",suggestion:"Break the task into smaller pieces, or process less data at once.",alternatives:[],autoRetry:!1}],Il=class{failures=new Map;maxRetriesPerTool;constructor(e=3){this.maxRetriesPerTool=e}resetTurn(){this.failures.clear()}analyze(e,t,s){let r=this.failures.get(e),i=r?r.count+1:1,o={tool:e,count:i,lastError:t,lastStrategy:"retry_same"};if(i>this.maxRetriesPerTool)return o.lastStrategy="ask_user",this.failures.set(e,o),{errorClass:"unknown",strategy:"ask_user",explanation:`Tool "${e}" has failed ${i} times in this turn.`,suggestion:`Stop retrying "${e}". Ask the user for clarification or try a completely different approach.`,alternatives:this.suggestAlternatives(e),autoRetry:!1};for(let a of N$)if(a.test(t)){let l=r?.lastStrategy===a.strategy&&i>=2,u=l?"decompose_task":a.strategy;return o.lastStrategy=u,this.failures.set(e,o),{errorClass:a.errorClass,strategy:u,explanation:a.explanation,suggestion:l?`Previous recovery attempt ("${a.strategy}") also failed. Try breaking this into smaller steps or use a completely different approach.`:a.suggestion,alternatives:a.alternatives,autoRetry:!l&&a.autoRetry}}return o.lastStrategy=i===1?"retry_fixed":"graceful_fail",this.failures.set(e,o),{errorClass:"unknown",strategy:o.lastStrategy,explanation:`Unexpected error from "${e}".`,suggestion:i===1?"Review the error message and adjust your approach.":"This error is persistent. Explain to the user what went wrong and suggest manual steps.",alternatives:this.suggestAlternatives(e),autoRetry:!1}}buildRecoveryMessage(e,t){let s=[`ERROR: ${t}`,"","[Recovery Analysis]",` Type: ${e.errorClass}`,` Strategy: ${e.strategy}`,` Explanation: ${e.explanation}`,` Suggestion: ${e.suggestion}`];switch(e.alternatives.length>0&&s.push(` Alternative tools: ${e.alternatives.join(", ")}`),e.strategy){case"read_first":s.push("","\u2192 ACTION: Read the file or directory first, then retry with correct information.");break;case"retry_fixed":s.push("","\u2192 ACTION: Fix the arguments based on the error, then retry.");break;case"alternative_tool":s.push("","\u2192 ACTION: Use a different tool to achieve the same goal.");break;case"decompose_task":s.push("","\u2192 ACTION: Break this into smaller, simpler steps.");break;case"ask_user":s.push("","\u2192 ACTION: Ask the user for clarification. Do NOT retry automatically.");break;case"graceful_fail":s.push("","\u2192 ACTION: Explain what went wrong clearly. Suggest manual steps if possible.");break}return s.join(`
|
|
964
964
|
`)}getFailureCount(e){return this.failures.get(e)?.count??0}shouldAutoRetry(e){let t=this.failures.get(e);return t?t.count<=1&&t.lastStrategy==="retry_same":!1}suggestAlternatives(e){return{read_file:["search_codebase","list_dir"],write_file:["edit_file","append_to_file"],edit_file:["search_and_replace","write_file","read_file"],search_and_replace:["edit_file","read_file"],patch_file:["edit_file","write_file"],run_command:["search_codebase"],search_codebase:["read_file","list_dir"],delete_file:["run_command"],create_dir:["run_command"],web_search:["scrape_url"]}[e]??[]}}});function j$(){try{if(Lt.existsSync(jr))return JSON.parse(Lt.readFileSync(jr,"utf-8"))}catch{}return{}}function H$(n){try{let e=Hr.dirname(jr);Lt.existsSync(e)||Lt.mkdirSync(e,{recursive:!0}),Lt.writeFileSync(jr,JSON.stringify(n,null,2),"utf-8")}catch{}}function Zm(n,e){let t=0,s=!1,r=!1;for(let i=e;i<n.length;i++){let o=n[i];if(r){r=!1;continue}if(o==="\\"&&s){r=!0;continue}if(o==='"'){s=!s;continue}if(!s&&(o==="{"&&t++,o==="}"&&(t--,t===0)))return n.slice(e,i+1)}return null}function ys(n){if(typeof n.name=="string"&&n.arguments&&typeof n.arguments=="object")return{tool:n.name,args:n.arguments};if(typeof n.tool=="string"&&n.args&&typeof n.args=="object")return{tool:n.tool,args:n.args};if(typeof n.name=="string"&&n.parameters&&typeof n.parameters=="object")return{tool:n.name,args:n.parameters};if(n.function&&typeof n.function=="object"){let e=n.function;if(typeof e.name=="string"){let t={};if(typeof e.arguments=="string")try{t=JSON.parse(e.arguments)}catch{t={}}else e.arguments&&typeof e.arguments=="object"&&(t=e.arguments);return{tool:e.name,args:t}}}return null}function B$(n){return n.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}function U$(n){let e=[],t=/<<?tool[-_]call\s*>>?([\s\S]*?)<<?\/tool[-_]call\s*>>?/gi,s;for(;(s=t.exec(n))!==null;)try{let r=JSON.parse(s[1].trim()),i=ys(r);i&&e.push({...i,format:"xml_tags",rawMatch:s[0]})}catch{}return e}function K$(n){let e=[],t=/<<?tool[-_]call\s*>>?([\s\S]*?)<<?\/tool[-_]call\s*>>?/gi,s;for(;(s=t.exec(n))!==null;)try{let r=JSON.parse(s[1].trim());if(r.parameters||r.name){let i=ys(r);i&&e.push({...i,format:"hermes",rawMatch:s[0]})}}catch{}return e}function q$(n){let e=[],t=/<<?tool[-_]call\s*>>?([\s\S]*?)<<?\/tool[-_]call\s*>>?/gi,s;for(;(s=t.exec(n))!==null;){let r=s[1],i=eg(r);for(let o of i)e.push({...o,format:"xml_tool_call_wrapper",rawMatch:s[0]})}return e}function eg(n){let e=[],t=["read_file","write_file","edit_file","search_and_replace","run_command","search_codebase","list_dir","create_dir","delete_file","append_to_file","patch_file","move_file","get_file_info"];for(let s of t){let r=new RegExp(`<<?${s}(\\s+[\\s\\S]*?)?(?:>>?([\\s\\S]*?)<<?\\/${s}>>?|\\s*\\/?>>?)`,"gi"),i;for(;(i=r.exec(n))!==null;){let o=i[1]||"",a=i[2]||"",l={},u=/(\w+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/g,d;for(;(d=u.exec(o))!==null;){let h=d[1].toLowerCase(),m=d[2]??d[3]??d[4];l[h]=B$(m)}let f=a.trim();f&&(s==="write_file"||s==="append_to_file"?l.content=a:s==="run_command"?l.command=f:s==="patch_file"&&(l.new_content=a)),l.start_line&&(l.start_line=parseInt(l.start_line)),l.end_line&&(l.end_line=parseInt(l.end_line)),l.depth&&(l.depth=parseInt(l.depth)),s==="edit_file"?e.push({tool:"search_and_replace",args:l,format:"xml_prompt",rawMatch:i[0]}):e.push({tool:s,args:l,format:"xml_prompt",rawMatch:i[0]})}}return e}function W$(n){return eg(n)}function G$(n){let e=[],t=/```(?:json|tool_call)?\s*\n([\s\S]*?)\n```/g,s;for(;(s=t.exec(n))!==null;)try{let r=JSON.parse(s[1].trim()),i=ys(r);i&&e.push({...i,format:"markdown_json",rawMatch:s[0]})}catch{}return e}function V$(n){let e=[],t=/\{\s*"function"\s*:/g,s;for(;(s=t.exec(n))!==null;){let r=Zm(n,s.index);if(r)try{let i=JSON.parse(r),o=ys(i);o&&e.push({...o,format:"function_call",rawMatch:r})}catch{}}return e}function z$(n){let e=[],t=/\{\s*"(?:name|tool)"\s*:/g,s;for(;(s=t.exec(n))!==null;){let r=Zm(n,s.index);if(r)try{let i=JSON.parse(r),o=ys(i);o&&e.push({...o,format:"json_object",rawMatch:r})}catch{}}return e}function Y$(n){let e=[],t=/<<?tool[-_]call\s*>>?([\s\S]*?)(?:<<?\/tool[-_]call\s*>>?|$)/gi,s,r=!1;for(;(s=t.exec(n))!==null;){let i=s[1],o=/<function=([^>]+)>/i.exec(i);if(o){r=!0;let a=o[1].trim(),l={},u=/<parameter=([^>]+)>([\s\S]*?)<\/parameter>/gi,d;for(;(d=u.exec(i))!==null;){let f=d[1].trim(),h=d[2].trim();h==="true"?h=!0:h==="false"?h=!1:!isNaN(Number(h))&&h!==""&&(h=Number(h)),l[f]=h}e.push({tool:a,args:l,format:"xml_parameters",rawMatch:s[0]})}}if(!r&&/<function=([^>]+)>/i.test(n)){let i=/<function=([^>]+)>/i.exec(n);if(i){let o=i[1].trim(),a={},l=/<parameter=([^>]+)>([\s\S]*?)<\/parameter>/gi,u;for(;(u=l.exec(n))!==null;){let d=u[1].trim(),f=u[2].trim();f==="true"?f=!0:f==="false"?f=!1:!isNaN(Number(f))&&f!==""&&(f=Number(f)),a[d]=f}e.push({tool:o,args:a,format:"xml_parameters",rawMatch:n})}}return e}function tg(){return Fl||(Fl=new Nl),Fl}var Lt,Hr,Qm,jr,Ll,Nl,Fl,ng=L(()=>{"use strict";Lt=O(require("fs")),Hr=O(require("path")),Qm=O(require("os")),jr=Hr.join(Qm.homedir(),".hablas","model-formats.json");Ll=[{format:"xml_tool_call_wrapper",parse:q$},{format:"xml_prompt",parse:W$},{format:"xml_tags",parse:U$},{format:"xml_parameters",parse:Y$},{format:"hermes",parse:K$},{format:"markdown_json",parse:G$},{format:"function_call",parse:V$},{format:"json_object",parse:z$}],Nl=class{registry;constructor(){this.registry=j$()}parse(e,t,s){if(t&&Array.isArray(t)&&t.length>0){let i=t.filter(o=>o?.function?.name&&typeof o.function.name=="string");if(i.length>0){let o=i.map(a=>({function:{name:a.function.name,arguments:a.function.arguments||{}}}));return s&&this.learnFormat(s,"native"),{toolCalls:o,displayContent:(e||"").trim(),format:"native"}}}let r=e||"";if(!r.trim())return{toolCalls:[],displayContent:"",format:"unknown"};if(s){let i=this.registry[s];if(i&&i.format!=="native"){let o=Ll.find(a=>a.format===i.format);if(o){let a=o.parse(r);if(a.length>0)return this.learnFormat(s,i.format),this.buildResult(a,r)}}}for(let{parse:i}of Ll){let o=i(r);if(o.length>0){let a=o[0].format;return s&&this.learnFormat(s,a),this.buildResult(o,r)}}return{toolCalls:[],displayContent:r.trim(),format:"unknown"}}mightContainToolCall(e){if(!e)return!1;let t=e.trim();return!!(/<<?tool[-_]call[\s>]/i.test(t)||/<function=/i.test(t)||t.includes("```tool_call")||t.includes("```json")&&t.includes('"name"')||/<<?(?:read_file|write_file|run_command|edit_file|search_codebase|create_dir|delete_file|list_dir|append_to_file|patch_file|move_file|get_file_info)[\s>]/i.test(t)||t.startsWith("{")&&(t.includes('"name"')||t.includes('"tool"'))&&(t.includes('"arguments"')||t.includes('"args"')||t.includes('"parameters"'))||t.includes('"function"')&&t.includes('"name"'))}detectFormat(e){for(let{format:t,parse:s}of Ll)if(s(e).length>0)return t;return"unknown"}learnFormat(e,t){let s=this.registry[e];s&&s.format===t?(s.successCount++,s.lastUsed=new Date().toISOString()):this.registry[e]={format:t,successCount:1,lastUsed:new Date().toISOString()},H$(this.registry)}getLearnedFormat(e){return this.registry[e]?.format??null}getLearnedFormats(){let e={};for(let[t,s]of Object.entries(this.registry))e[t]={format:s.format,successCount:s.successCount};return e}buildResult(e,t){let s=e.map(o=>({function:{name:o.tool,arguments:o.args}})),r=t,i=[...e].sort((o,a)=>a.rawMatch.length-o.rawMatch.length);for(let o of i)r=r.replace(o.rawMatch,"");return r=r.replace(/<<?thinking>>?[\s\S]*?<<?\/thinking>>?/gi,""),r=r.replace(/<<?think>>?[\s\S]*?<<?\/think>>?/gi,""),r=r.replace(/\n{3,}/g,`
|
|
965
965
|
|
|
966
|
-
`),{toolCalls:s,displayContent:r.trim(),format:e[0]?.format??"unknown"}}},Fl=null});function X$(n,e,t){let r=tg().parse(e,n,t);return{toolCalls:r.toolCalls,displayContent:r.displayContent}}function Q$(n,e){return n==="write_file"&&typeof e.path=="string"?`create ${e.path}`:(n==="edit_file"||n==="patch_file"||n==="search_and_replace")&&typeof e.path=="string"?`modify ${e.path}`:n==="read_file"&&typeof e.path=="string"?`read ${e.path}`:n==="run_command"&&typeof e.command=="string"?String(e.command).slice(0,80):typeof e.path=="string"?String(e.path):n.replace(/_/g," ")}function Z$(n){let e=(n||"").toLowerCase();return e.includes("eacces")||e.includes("permission")||e.includes("enospc")||e.includes("readonly")||e.includes("security")||e.includes("[write_file]")||e.includes("[delete_file]")||e.includes("[move_file]")||e.includes("[search_and_replace]")}async function ig(n,e,t,s){let r=0,i=Date.now();for(;r<=rg;){let o=await n.execute({name:e,arguments:t});if(o.success||r>=rg)return{success:o.success,output:o.output,error:o.error,duration:Date.now()-i,retries:r};r++,s.info({tool:e,retry:r,error:o.error},"Retrying tool"),await new Promise(a=>setTimeout(a,500))}return{success:!1,output:"",error:"Max retries exceeded",duration:Date.now()-i,retries:r}}async function Br(n){let{identity:e,client:t,registry:s,session:r,contextManager:i,logger:o,io:a={},safetyPolicy:l,abortSignal:u,skipTools:d}=n,f=n.reactEngine??ms(),h=n.errorRecovery??gs(),m=d?[]:s.getOllamaTools(),p=t.getModel(),g=n.maxIterations??J$,x=[],w=[],$=[],A="",y=0,v=!1;for(;y<g;){if(y++,u?.aborted)return{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!1,error:"Aborted",completedNaturally:v};let b=f.buildBudgetWarningPrompt();b&&r.addUserMessage(b,{priority:"critical",tags:["system-budget"]});let S;try{S=await t.chatWithTools(r.getMessages(),m,u)}catch(W){let E=W;if(E.name==="AbortError"||u?.aborted)return{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!1,error:"Aborted",completedNaturally:v};if(y<=1){a.onNotice?.(`Transient model error: ${E.message??"unknown"} \u2014 retrying\u2026`,"retry"),await new Promise(k=>setTimeout(k,1e3)),y--;continue}return a.onError?.(E.message??"Model request failed"),{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!1,error:E.message,completedNaturally:v}}let _=S.message?.content||"",T=S.message?.tool_calls,I=f.parseThinking(_);I.hasThinking&&(f.recordStep({thought:I.thinking}),o.debug({thinking:I.thinking.slice(0,200)},"ReAct thinking"));let{toolCalls:C,displayContent:F}=X$(T,_,p);if(F&&F.trim()&&(A=F,await a.onAssistantText?.(F,e)),C.length===0){r.addAssistantMessage(_,void 0,e.role),v=!0;break}r.addAssistantMessage(_,C,e.role);let H=C.length;for(let W=0;W<C.length;W++){let E=C[W];if(!E?.function?.name)continue;let k=E.function.name,J=E.function.arguments||{},K=s.getSafetyLevel(k)??"confirm";if(!s.get(k)){a.onNotice?.(`Unknown tool: ${k} \u2014 skipping`,"warn"),r.addToolMessage(`Error: Unknown tool "${k}". Available: ${s.getAll().map(Oe=>Oe.name).join(", ")}`);continue}if(await l(k,K,J)==="skip"){r.addToolMessage(`Tool ${k} was skipped by policy/user.`);break}x.push(k),typeof J.path=="string"&&$.push(J.path);let te=Q$(k,J);a.onToolStart?.(k,te,J),a.onToolCall?.(),f.recordStep({thought:I.hasThinking?`Executing: ${k}`:"",action:k,actionInput:J});let Q=await ig(s,k,J,o);a.onToolEnd?.(k,Q.success,Q.error||Q.output,Q.duration,J);let ce;if(Q.success)ce=os(Q.output,sg),f.recordObservation(ce.slice(0,300)),w.push({tool:k,success:!0,summary:Q.output.slice(0,150)});else{let Oe=Q.error||"Unknown error",Fe=h.analyze(k,Oe,J);if(ce=h.buildRecoveryMessage(Fe,Oe),f.recordObservation(`FAILED: ${Oe}`,`Recovery: ${Fe.strategy} \u2014 ${Fe.suggestion}`),o.info({tool:k,errorClass:Fe.errorClass,strategy:Fe.strategy},"Error recovery analysis"),w.push({tool:k,success:!1,summary:Oe.slice(0,150)}),Fe.autoRetry&&!f.isOverBudget()){a.onNotice?.("Auto-retrying (transient error)\u2026","retry");let ye=await ig(s,k,J,o);a.onToolEnd?.(k,ye.success,ye.output,ye.duration,J),ye.success&&(ce=os(ye.output,sg),f.recordObservation(ce.slice(0,300),"Auto-retry succeeded"),w[w.length-1]={tool:k,success:!0,summary:ye.output.slice(0,150)})}}if(r.addToolMessage(ce),Q.success&&k==="read_file"&&typeof J.path=="string"&&i?.addFile(J.path,Q.output),o.info({tool:k,success:Q.success,durationMs:Q.duration,retries:Q.retries},"Tool executed"),!Q.success&&Z$(Q.error)){a.onNotice?.("Critical tool failure \u2014 aborting subsequent tool executions.","warn");break}H>1&&W<H-1}f.isOverBudget()&&a.onNotice?.(`Reached max reasoning steps (${f.getConfig().maxSteps}). Wrapping up.`,"warn")}return y>=g&&!v&&a.onNotice?.(`Reached max iterations (${g}). Stopping.`,"warn"),o.info({summary:f.getTurnSummary(),agent:e.name},"Agentic turn completed"),{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!0,completedNaturally:v}}function qt(n){return[...new Set(n)]}function og(n){return async(e,t)=>{let s=e.replace(/_/g," ");return!n.autoMode&&n.interactive?t==="confirm"&&n.confirm?await n.confirm(`Proceed with ${s}?`)?"allow":"skip":t==="dangerous"&&n.confirmDangerous?await n.confirmDangerous(`Dangerous: ${s}`)?"allow":"skip":"allow":!n.autoMode&&t==="dangerous"?"skip":"allow"}}function ag(){return(n,e)=>e==="dangerous"?"skip":"allow"}var J$,sg,rg,jl=L(()=>{"use strict";da();Ml();Dl();ng();J$=150,sg=2e3,rg=2});var cg,e0,t0,n0,lg,bs,ug=L(()=>{"use strict";cg=O(Ol());jn();pa();fa();Ns();Ri();Fa();jl();e0={hablas:"planner",bob:"architect",alex:"coder",david:"researcher",emma:"product-manager"},t0=(0,cg.default)({level:"silent"}),n0=40,lg={hablas:{role:"hablas",model:"stepfun-ai/step-3.7-flash",temperature:.7},bob:{role:"bob",model:"stepfun-ai/step-3.7-flash",temperature:.4},alex:{role:"alex",model:"stepfun-ai/step-3.7-flash",temperature:.2},david:{role:"david",model:"stepfun-ai/step-3.7-flash",temperature:.5},emma:{role:"emma",model:"stepfun-ai/step-3.7-flash",temperature:.6}},bs=class{baseConfig;agentModels;toolRegistry=null;onOutput=null;channel=null;mindsetRegistry=br();sharedContext=null;contextManager;constructor(e){this.baseConfig=e,this.agentModels=zt(),this.contextManager=new tn(e)}setSharedContext(e){this.sharedContext=e}setChannel(e){this.channel=e}setToolRegistry(e){this.toolRegistry=e}setOutputCallback(e){this.onOutput=e}reloadModels(){this.agentModels=zt()}getAgentModel(e){let t=this.agentModels[e];if(t)return{model:t.model,temperature:t.temperature??lg[e]?.temperature??.5};let s=lg[e];return{model:s.model,temperature:s.temperature??.5}}async runAgent(e,t,s,r,i){let o=Date.now(),a=xe.find($=>$.role===e)
|
|
966
|
+
`),{toolCalls:s,displayContent:r.trim(),format:e[0]?.format??"unknown"}}},Fl=null});function X$(n,e,t){let r=tg().parse(e,n,t);return{toolCalls:r.toolCalls,displayContent:r.displayContent}}function Q$(n,e){return n==="write_file"&&typeof e.path=="string"?`create ${e.path}`:(n==="edit_file"||n==="patch_file"||n==="search_and_replace")&&typeof e.path=="string"?`modify ${e.path}`:n==="read_file"&&typeof e.path=="string"?`read ${e.path}`:n==="run_command"&&typeof e.command=="string"?String(e.command).slice(0,80):typeof e.path=="string"?String(e.path):n.replace(/_/g," ")}function Z$(n){let e=(n||"").toLowerCase();return e.includes("eacces")||e.includes("permission")||e.includes("enospc")||e.includes("readonly")||e.includes("security")||e.includes("[write_file]")||e.includes("[delete_file]")||e.includes("[move_file]")||e.includes("[search_and_replace]")}async function ig(n,e,t,s){let r=0,i=Date.now();for(;r<=rg;){let o=await n.execute({name:e,arguments:t});if(o.success||r>=rg)return{success:o.success,output:o.output,error:o.error,duration:Date.now()-i,retries:r};r++,s.info({tool:e,retry:r,error:o.error},"Retrying tool"),await new Promise(a=>setTimeout(a,500))}return{success:!1,output:"",error:"Max retries exceeded",duration:Date.now()-i,retries:r}}async function Br(n){let{identity:e,client:t,registry:s,session:r,contextManager:i,logger:o,io:a={},safetyPolicy:l,abortSignal:u,skipTools:d}=n,f=n.reactEngine??ms(),h=n.errorRecovery??gs(),m=d?[]:s.getOllamaTools(),p=t.getModel(),g=n.maxIterations??J$,x=[],w=[],$=[],A="",y=0,v=!1;for(;y<g;){if(y++,u?.aborted)return{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!1,error:"Aborted",completedNaturally:v};let b=f.buildBudgetWarningPrompt();b&&r.addUserMessage(b,{priority:"critical",tags:["system-budget"]});let S;try{S=await t.chatWithTools(r.getMessages(),m,u)}catch(W){let E=W;if(E.name==="AbortError"||u?.aborted)return{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!1,error:"Aborted",completedNaturally:v};if(y<=1){a.onNotice?.(`Transient model error: ${E.message??"unknown"} \u2014 retrying\u2026`,"retry"),await new Promise(k=>setTimeout(k,1e3)),y--;continue}return a.onError?.(E.message??"Model request failed"),{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!1,error:E.message,completedNaturally:v}}let _=S.message?.content||"",T=S.message?.tool_calls,I=f.parseThinking(_);I.hasThinking&&(f.recordStep({thought:I.thinking}),o.debug({thinking:I.thinking.slice(0,200)},"ReAct thinking"));let{toolCalls:C,displayContent:F}=X$(T,_,p);if(F&&F.trim()&&(A=F,await a.onAssistantText?.(F,e)),C.length===0){r.addAssistantMessage(_,void 0,e.role),v=!0;break}r.addAssistantMessage(_,C,e.role);let H=C.length;for(let W=0;W<C.length;W++){let E=C[W];if(!E?.function?.name)continue;let k=E.function.name,J=E.function.arguments||{},K=s.getSafetyLevel(k)??"confirm";if(!s.get(k)){a.onNotice?.(`Unknown tool: ${k} \u2014 skipping`,"warn"),r.addToolMessage(`Error: Unknown tool "${k}". Available: ${s.getAll().map(Oe=>Oe.name).join(", ")}`);continue}if(await l(k,K,J)==="skip"){r.addToolMessage(`Tool ${k} was skipped by policy/user.`);break}x.push(k),typeof J.path=="string"&&$.push(J.path);let te=Q$(k,J);a.onToolStart?.(k,te,J),a.onToolCall?.(),f.recordStep({thought:I.hasThinking?`Executing: ${k}`:"",action:k,actionInput:J});let Q=await ig(s,k,J,o);a.onToolEnd?.(k,Q.success,Q.error||Q.output,Q.duration,J);let ce;if(Q.success)ce=os(Q.output,sg),f.recordObservation(ce.slice(0,300)),w.push({tool:k,success:!0,summary:Q.output.slice(0,150)});else{let Oe=Q.error||"Unknown error",Fe=h.analyze(k,Oe,J);if(ce=h.buildRecoveryMessage(Fe,Oe),f.recordObservation(`FAILED: ${Oe}`,`Recovery: ${Fe.strategy} \u2014 ${Fe.suggestion}`),o.info({tool:k,errorClass:Fe.errorClass,strategy:Fe.strategy},"Error recovery analysis"),w.push({tool:k,success:!1,summary:Oe.slice(0,150)}),Fe.autoRetry&&!f.isOverBudget()){a.onNotice?.("Auto-retrying (transient error)\u2026","retry");let ye=await ig(s,k,J,o);a.onToolEnd?.(k,ye.success,ye.output,ye.duration,J),ye.success&&(ce=os(ye.output,sg),f.recordObservation(ce.slice(0,300),"Auto-retry succeeded"),w[w.length-1]={tool:k,success:!0,summary:ye.output.slice(0,150)})}}if(r.addToolMessage(ce),Q.success&&k==="read_file"&&typeof J.path=="string"&&i?.addFile(J.path,Q.output),o.info({tool:k,success:Q.success,durationMs:Q.duration,retries:Q.retries},"Tool executed"),!Q.success&&Z$(Q.error)){a.onNotice?.("Critical tool failure \u2014 aborting subsequent tool executions.","warn");break}H>1&&W<H-1}f.isOverBudget()&&a.onNotice?.(`Reached max reasoning steps (${f.getConfig().maxSteps}). Wrapping up.`,"warn")}return y>=g&&!v&&a.onNotice?.(`Reached max iterations (${g}). Stopping.`,"warn"),o.info({summary:f.getTurnSummary(),agent:e.name},"Agentic turn completed"),{output:A,toolsUsed:qt(x),toolResults:w,touchedFiles:qt($),iterations:y,success:!0,completedNaturally:v}}function qt(n){return[...new Set(n)]}function og(n){return async(e,t)=>{let s=e.replace(/_/g," ");return!n.autoMode&&n.interactive?t==="confirm"&&n.confirm?await n.confirm(`Proceed with ${s}?`)?"allow":"skip":t==="dangerous"&&n.confirmDangerous?await n.confirmDangerous(`Dangerous: ${s}`)?"allow":"skip":"allow":!n.autoMode&&t==="dangerous"?"skip":"allow"}}function ag(){return(n,e)=>e==="dangerous"?"skip":"allow"}var J$,sg,rg,jl=L(()=>{"use strict";da();Ml();Dl();ng();J$=150,sg=2e3,rg=2});var cg,e0,t0,n0,lg,bs,ug=L(()=>{"use strict";cg=O(Ol());jn();pa();fa();Ns();Ri();Fa();jl();e0={hablas:"planner",bob:"architect",alex:"coder",david:"researcher",emma:"product-manager",gate:"gate"},t0=(0,cg.default)({level:"silent"}),n0=40,lg={hablas:{role:"hablas",model:"stepfun-ai/step-3.7-flash",temperature:.7},bob:{role:"bob",model:"stepfun-ai/step-3.7-flash",temperature:.4},alex:{role:"alex",model:"stepfun-ai/step-3.7-flash",temperature:.2},david:{role:"david",model:"stepfun-ai/step-3.7-flash",temperature:.5},emma:{role:"emma",model:"stepfun-ai/step-3.7-flash",temperature:.6},gate:{role:"gate",model:"stepfun-ai/step-3.5-flash",temperature:.3}},bs=class{baseConfig;agentModels;toolRegistry=null;onOutput=null;channel=null;mindsetRegistry=br();sharedContext=null;contextManager;constructor(e){this.baseConfig=e,this.agentModels=zt(),this.contextManager=new tn(e)}setSharedContext(e){this.sharedContext=e}setChannel(e){this.channel=e}setToolRegistry(e){this.toolRegistry=e}setOutputCallback(e){this.onOutput=e}reloadModels(){this.agentModels=zt()}getAgentModel(e){let t=this.agentModels[e];if(t)return{model:t.model,temperature:t.temperature??lg[e]?.temperature??.5};let s=lg[e];return{model:s.model,temperature:s.temperature??.5}}async runAgent(e,t,s,r,i){let o=Date.now(),a;e==="gate"?a={name:"Gate",title:"Hidden Executive Layer",role:"gate"}:a=xe.find($=>$.role===e);let l=this.getAgentModel(e),u=i?.maxIterations||n0,d={...this.baseConfig,model:l.model},f=Me(d),h=this.buildAgentPrompt(a,s),m=new nn(h,30,this.baseConfig.contextBudget);m.addUserMessage(t);let p={name:a.name,title:a.title,role:e};this.emit(a.name,"thinking",`\u2605 Hablas \u2192 Delegating to @${a.name} (${a.title})...`);let g={onAssistantText:$=>{this.emit(a.name,"speaking",$.slice(0,200))},onToolStart:($,A,y)=>{this.emit(a.name,"tool",A),this.channel&&this.channel.emitEvent({type:"act",agent:a.name,toolName:$,toolArgs:this.safeArgs(y),content:A})},onToolEnd:($,A,y)=>{this.channel&&this.channel.emitEvent({type:"observe",agent:a.name,toolName:$,success:A,content:A?this.summarizeOk($,y):`error: ${y.slice(0,120)}`})},onError:$=>this.emit(a.name,"error",$)},x=await Br({identity:p,client:f,registry:this.toolRegistry,session:m,contextManager:this.contextManager,logger:t0,io:g,safetyPolicy:ag(),abortSignal:i?.abortSignal,skipTools:(!r||r.length===0,!1),maxIterations:u});if(this.sharedContext&&x.touchedFiles.length)try{this.sharedContext.set(`files:@${a.name}`,x.touchedFiles.join(", "))}catch{}let w=x.touchedFiles.length?[`@${a.name} touched: ${x.touchedFiles.join(", ")}`]:[];return{agent:e,agentName:a.name,output:x.output||(x.success?"Done.":x.error??"No output"),toolsUsed:x.toolsUsed,toolResults:x.toolResults,duration:Date.now()-o,iterations:x.iterations,success:x.success,error:x.error,discoveries:w,touchedFiles:x.touchedFiles}}async runSequential(e,t,s){let r=[],i="",o=[];for(let a=0;a<e.length;a++){let{role:l,task:u}=e[a];if(s?.abortSignal?.aborted)break;let d=[];if(i&&(d.push("## Previous Agent Results"),d.push(i)),o.length>0){d.push(`
|
|
967
967
|
## Handoff Chain`);for(let p of o)d.push(`- @${p.from} \u2192 @${p.to}: ${p.context.slice(0,100)}`)}let f=d.join(`
|
|
968
968
|
`),h=xe.find(p=>p.role===l);if(h&&a>0){let p=e[a-1].role,g=xe.find(x=>x.role===p);this.emit(h.name,"thinking",`\u2605 Handoff: @${g?.name||p} \u2192 @${h.name} (${h.title})`)}let m=await this.runAgent(l,u,f,t,s);if(r.push(m),m.success&&m.output){let p=m.output.length>600?m.output.slice(0,600)+"...":m.output;i+=`
|
|
969
969
|
|
|
@@ -974,7 +974,10 @@ ${p}`,a<e.length-1&&o.push({from:l,to:e[a+1].role,context:m.output.slice(0,200),
|
|
|
974
974
|
Error: ${i.error}
|
|
975
975
|
Please try a different approach.`;if(i=await this.runAgent(e,t,o,r),i.success)return i;if(e!=="hablas"){this.emit("Hablas","thinking",`@${xe.find(l=>l.role===e)?.name} failed. Hablas taking over...`);let a=`Agent @${e} failed twice on this task.
|
|
976
976
|
Original error: ${i.error}
|
|
977
|
-
Please complete this task.`;return this.runAgent("hablas",t,a,r)}return i}buildAgentPrompt(e,t){
|
|
977
|
+
Please complete this task.`;return this.runAgent("hablas",t,a,r)}return i}buildAgentPrompt(e,t){if(e.role==="gate"){let a=this.mindsetRegistry.get("gate");return a?a.systemPrompt+(t?`
|
|
978
|
+
|
|
979
|
+
## Additional Context
|
|
980
|
+
${t}`:""):"You are the hidden professional decision layer. Analyze the input and decide routing."}let s=e0[e.role]??"coder",r=this.mindsetRegistry.get(s),o=(r?`${r.systemPrompt}
|
|
978
981
|
|
|
979
982
|
---
|
|
980
983
|
|
|
@@ -1098,7 +1101,7 @@ Please compile, synthesize, and present the final unified response to the user.
|
|
|
1098
1101
|
${d.output}`}).join(`
|
|
1099
1102
|
|
|
1100
1103
|
`);return{results:t,finalSynthesis:u,synthesisOk:!1}}}});function ut(n){switch(n){case"Hablas":return c.leader;case"Bob":return c.architect;case"Alex":return c.engineer;case"David":return c.analyst;case"Emma":return c.product;default:return c.primary}}function Kr(n){return n==="Hablas"?"\u2605":"\u25C6"}function Ss(n,e=140){let t=(n||"").replace(/\s+/g," ").trim();return t.length>e?t.slice(0,e-1)+"\u2026":t}var _s,bg=L(()=>{"use strict";yn();_s=class{channel;opts;attached=!1;listener;lastThinking=null;lastLine="";constructor(e,t={}){this.channel=e,this.opts={hideThinking:t.hideThinking??!1,hideActs:t.hideActs??!1,maxChars:t.maxChars??140},this.listener=s=>this.handle(s)}attach(){return this.attached?this:(this.channel.onEvent(this.listener),this.attached=!0,this)}detach(){return this.attached?(this.channel.offEvent(this.listener),this.attached=!1,this):this}handle(e){switch(e.type){case"phase":return this.renderPhase(e);case"handoff":return this.renderHandoff(e);case"thinking":return this.renderThinking(e);case"speak":return this.renderSpeak(e);case"act":return this.renderAct(e);case"observe":return this.renderObserve(e);case"review":return this.renderReview(e);case"summary":return this.renderSummary(e);case"decision":return this.renderDecision(e);case"done":return this.renderDone(e);case"error":return this.renderError(e)}}renderPhase(e){let t=(e.content||"").toString();t&&(this.print(`
|
|
1101
|
-
${c.muted("\u25B8")} ${c.secondary(t)}`),this.lastThinking=null)}renderHandoff(e){let t=e.agent,s=e.to||"";if(!s)return;let r=ut(t),i=ut(s);this.print(` ${r(Kr(t))} ${r(t)} ${c.muted("\u2501\u2501\u25B6")} ${i(Kr(s))} ${i(s)}`),this.lastThinking=null}renderThinking(e){if(this.opts.hideThinking||this.lastThinking===e.agent)return;this.lastThinking=e.agent;let t=ut(e.agent);this.print(` ${t("\u25C9")}
|
|
1104
|
+
${c.muted("\u25B8")} ${c.secondary(t)}`),this.lastThinking=null)}renderHandoff(e){let t=e.agent,s=e.to||"";if(!s)return;let r=ut(t),i=ut(s);this.print(` ${r(Kr(t))} ${r(t)} ${c.muted("\u2501\u2501\u25B6")} ${i(Kr(s))} ${i(s)}`),this.lastThinking=null}renderThinking(e){if(this.opts.hideThinking||this.lastThinking===e.agent)return;this.lastThinking=e.agent;let t=ut(e.agent),s=e.content&&e.content.length>5?e.content:"analyzing and formulating response\u2026";this.print(` ${t("\u25C9")} ${t(e.agent)} ${c.muted("\u2014")} ${s}`)}renderSpeak(e){let t=Ss(e.content||"",this.opts.maxChars);if(!t)return;let s=ut(e.agent),r=e.to?` ${c.muted("\u2192")} ${ut(e.to)("@"+e.to)}`:"",i=`speak:${e.agent}:${e.to||""}:${t}`;i!==this.lastLine&&(this.lastLine=i,this.print(` ${s(Kr(e.agent))} ${s(e.agent)}${r}${c.muted(":")} ${c.secondary(t)}`),this.lastThinking=null)}renderAct(e){if(this.opts.hideActs)return;let t=ut(e.agent),s=e.toolName||"tool",r=e.toolArgs||{},i="";typeof r.path=="string"?i=` ${c.primary(r.path)}`:typeof r.command=="string"?i=` ${c.primary(r.command)}`:typeof r.query=="string"&&(i=` "${c.primary(r.query)}"`);let o=s==="write_file"||s==="edit_file"||s==="patch_file"?"\u270E":s==="run_command"?"\u2318":s==="read_file"?"\u{1F4D6}":s==="search_codebase"?"\u{1F50E}":"\u{1F527}";this.print(` ${t(o)} [Running Tool]: ${t(e.agent)} is executing ${c.strong(s)}${i}...`),this.lastThinking=null}renderObserve(e){if(this.opts.hideActs)return;let t=e.success!==!1,s=t?c.success("\u2713 COMPLETED"):c.error("\u2717 FAILED"),r=Ss(e.content||(t?"Execution succeeded":"Execution failed"),this.opts.maxChars);this.print(` ${c.muted("\u21B3")} ${s}: ${c.muted(r)}`)}renderReview(e){let t=e.agent,s=e.to||"",r=Ss(e.content||"",this.opts.maxChars);if(!r)return;let i=ut(t),o=ut(s);this.print(`
|
|
1102
1105
|
${i("\u270E")} ${c.strong("@"+t)} ${c.muted("reviewing")} ${o("@"+s)}${c.muted(":")} ${c.secondary(r)}`),this.lastThinking=null}renderSummary(e){let t=ut(e.agent),s=e.durationMs?` ${c.muted(`(${(e.durationMs/1e3).toFixed(1)}s)`)}`:"";this.print(` ${t(Kr(e.agent))} ${t(e.agent)} ${c.muted("\u2500\u2500\u25BA")} ${c.leader("\u2605 Hablas")} ${c.muted("\xB7 report submitted")}${s}`),this.lastThinking=null}renderDecision(e){let t=Ss(e.content||"",this.opts.maxChars);if(!t)return;let s=ut(e.agent);this.print(` ${s("\u25C6")} ${s(e.agent)} ${c.muted("decision:")} ${c.secondary(t)}`)}renderDone(e){this.print(`
|
|
1103
1106
|
${c.chrome("\u2500".repeat(56))}`),this.lastThinking=null}renderError(e){let t=ut(e.agent),s=Ss(e.content||"unknown error",this.opts.maxChars);this.print(` ${t("\u25C6")} ${t(e.agent)} ${c.error("\u2717")} ${c.error(s)}`),this.lastThinking=null}print(e){console.log(e)}}});var qr,vg=L(()=>{"use strict";qr=class{plans=new Map;activePlanId=null;nextPlanNum=1;createPlan(e,t,s){let r=`plan_${this.nextPlanNum++}`,i={hablas:"Hablas",bob:"Bob",alex:"Alex",david:"David"},o={id:r,title:e,strategy:t,tasks:s.map((a,l)=>({task_id:`${r}_t${l+1}`,dependent_task_ids:a.dependent_task_ids||[],description:a.description,assignee:a.assignee,assigneeName:a.assigneeName||i[a.assignee]||a.assignee,status:"pending",createdAt:Date.now()})),createdAt:Date.now(),updatedAt:Date.now()};return this.plans.set(r,o),this.activePlanId=r,o}getActivePlan(){return this.activePlanId&&this.plans.get(this.activePlanId)||null}getTask(e){let t=this.getActivePlan();return t&&t.tasks.find(s=>s.task_id===e)||null}startTask(e){let t=this.getTask(e);return!t||!this.areDependenciesMet(e)?!1:(t.status="running",t.startedAt=Date.now(),this.touch(),!0)}finishTask(e,t){let s=this.getTask(e);return s?(s.status="done",s.result=t,s.completedAt=Date.now(),this.touch(),!0):!1}failTask(e,t){let s=this.getTask(e);return s?(s.status="failed",s.error=t,s.completedAt=Date.now(),this.touch(),!0):!1}skipTask(e){let t=this.getTask(e);return t?(t.status="skipped",t.completedAt=Date.now(),this.touch(),!0):!1}resetTask(e){let t=this.getTask(e);return t?(t.status="pending",t.result=void 0,t.error=void 0,t.startedAt=void 0,t.completedAt=void 0,this.touch(),!0):!1}replaceTask(e,t,s){let r=this.getTask(e);return r?(r.description=t,s&&(r.assignee=s),r.status="pending",r.result=void 0,r.error=void 0,this.touch(),!0):!1}areDependenciesMet(e){let t=this.getTask(e);if(!t)return!1;if(t.dependent_task_ids.length===0)return!0;let s=this.getActivePlan();return s?t.dependent_task_ids.every(r=>{let i=s.tasks.find(o=>o.task_id===r);return i&&(i.status==="done"||i.status==="skipped")}):!1}getNextTask(){let e=this.getActivePlan();if(!e)return null;for(let t of e.tasks)if(t.status==="pending"&&this.areDependenciesMet(t.task_id))return t;return null}getDependencyOrder(){let e=this.getActivePlan();if(!e)return[];let t=new Set,s=[],r=new Map(e.tasks.map(o=>[o.task_id,o])),i=o=>{if(t.has(o))return;t.add(o);let a=r.get(o);if(a){for(let l of a.dependent_task_ids)i(l);s.push(a)}};for(let o of e.tasks)i(o.task_id);return s}getProgress(){let e=this.getActivePlan();if(!e)return{total:0,done:0,failed:0,pending:0,running:0,skipped:0,percentage:0};let t=e.tasks.length,s=e.tasks.filter(u=>u.status==="done").length,r=e.tasks.filter(u=>u.status==="failed").length,i=e.tasks.filter(u=>u.status==="pending").length,o=e.tasks.filter(u=>u.status==="running").length,a=e.tasks.filter(u=>u.status==="skipped").length,l=t>0?Math.round((s+a)/t*100):0;return{total:t,done:s,failed:r,pending:i,running:o,skipped:a,percentage:l}}isComplete(){let e=this.getActivePlan();return e?e.tasks.every(t=>t.status==="done"||t.status==="failed"||t.status==="skipped"):!0}serialize(){let e=this.getActivePlan();return e?JSON.stringify(e,null,2):"{}"}deserialize(e){try{let t=JSON.parse(e);return t.id&&t.tasks?(this.plans.set(t.id,t),this.activePlanId=t.id,t):null}catch{return null}}reset(){this.plans.clear(),this.activePlanId=null,this.nextPlanNum=1}clear(){this.plans.clear(),this.activePlanId=null}touch(){let e=this.getActivePlan();e&&(e.updatedAt=Date.now())}}});var le,dt,o0,a0,l0,c0,u0,d0,f0,Wr,wg=L(()=>{"use strict";le=O(require("fs")),dt=O(require("path")),o0=".hablas",a0=`# Project Context \u2014 Hablas AI
|
|
1104
1107
|
|
|
@@ -1227,7 +1230,7 @@ ${d}`),o+=d.length}}}extractSection(e,t){let s=e.split(`
|
|
|
1227
1230
|
${c.accent("\u2726")} ${c.strong("Team Mode Strategy Required")}`),console.log(` ${c.muted("Collaboration requires a stable Git repository root.")}
|
|
1228
1231
|
`);let te=await new ls(t).prompt(` ${c.primary("\u203A")} Specify repo path OR type 'init' to start here: `);if(te.trim().toLowerCase()==="init")try{(0,Lg.execSync)("git init",{cwd:t,stdio:"ignore"}),console.log(` ${c.success("\u2713")} Git repository initialized in ${c.highlight(t)}
|
|
1229
1232
|
`)}catch{console.log(ke("Failed to initialize Git. Please run git init manually.")),process.exit(1)}else{let Q=Ft.resolve(t,te.trim());mt.existsSync(Q)&&s(Q)?(t=Q,n.workingDirectory=t,console.log(` ${c.success("\u2713")} Context switched to repository: ${c.highlight(t)}
|
|
1230
|
-
`)):(console.log(ke(`Path "${Q}" is not a valid Git repository.`)),process.exit(1))}}let r=Me(n),i=new En(t,n),o=new tn(n),a=new ls(t),l=br(),u=new vr,d=new us(t),f=new Dn(t),h=new qr,m=new bs(n);m.setToolRegistry(i);let p=new vs,g=new _s(p).attach(),x=new ws(n,{tokenBudget:500,maxChars:140});if(m.setChannel(p),n.team?.enabled){let Z=n.team.user||"developer",te=n.team.key||"default-key";Re=new rs(t,n,Z,te),await Re.init()&&console.log(` ${c.success("\u2713")} ${c.muted("[Team]")} Scoped cooperative sync initialized successfully.
|
|
1233
|
+
`)):(console.log(ke(`Path "${Q}" is not a valid Git repository.`)),process.exit(1))}}let r=Me(n),i=new En(t,n),o=new tn(n),a=new ls(t),l=br(),u=new vr,d=new us(t),f=new Dn(t),h=new qr,m=new bs(n);m.setToolRegistry(i);let p=new vs,g=new _s(p,{hideActs:!0}).attach(),x=new ws(n,{tokenBudget:500,maxChars:140});if(m.setChannel(p),n.team?.enabled){let Z=n.team.user||"developer",te=n.team.key||"default-key";Re=new rs(t,n,Z,te),await Re.init()&&console.log(` ${c.success("\u2713")} ${c.muted("[Team]")} Scoped cooperative sync initialized successfully.
|
|
1231
1234
|
`)}let w=new Vr(t);f.init();let $=null;n.context?.hablasCoreEnabled&&($=new Wr(t),$.init());let A=await bn(t,n),y=l.getActive(),v=y?y.systemPrompt:Wn,b=vn(v,A,d,f),S=ms({thinkingEnabled:!0,selfEvalEnabled:!0,showThinking:!1,maxSteps:150,minConfidence:.6}),_=gs(3),T=new nn(b,n.historySize),I=Bn();I=Ii(I),dn(I);let C=0,F=0,H=Date.now(),W=n.autoMode||!1,E=0,k=new AbortController;process.on("SIGINT",()=>{let Z=Date.now();if(Z-E<S0){console.log(Yi({turns:C,duration:Date.now()-H,toolCalls:F}));let te=Re?Re.shutdown():Promise.resolve();Promise.resolve(te).finally(()=>process.exit(0)),setTimeout(()=>process.exit(0),2e3);return}E=Z,k.abort(),k=new AbortController,process.stdout.write(`
|
|
1232
1235
|
`),console.log(j("Operation cancelled \u2014 press Ctrl+C again to exit"))});let J=Rs(n);if(console.log(ru(n.model,t)),n.provider==="custom"&&console.log(he(`Provider: ${J}`)),W&&console.log(he("Auto mode enabled \u2014 tool confirmations skipped (plan approval still required)")),(_0()||!Ig())&&(console.log(au()),console.log(""),console.log(he("First run detected \u2014 launching setup wizard...")),console.log(""),a.close(),await Ul(n),k0(),r=Me(n),a.reinitialize()),Ig()){let Z=new Ge("Connecting");Z.start();let te=await r.checkConnection();if(Z.stop(te?"ready":void 0),te){let Q=await r.listModels();console.log(Y(`Connected \xB7 ${Q.length} models available`)),n.provider==="ollama"&&!Q.includes(n.model)&&console.log(j(`Model "${n.model}" not found. Pull: ollama pull ${n.model}`))}else n.provider==="custom"?console.log(Be(`Cannot connect to ${n.apiUrl}`,"Check your --api-url and --api-key, or run /provider test")):n.provider==="nvidia"?console.log(Be("Cannot connect to NVIDIA NIM","Check your API key or run: hablas --setup")):console.log(Be("Cannot connect to Ollama","Start it with: ollama serve \u2014 or switch provider: /provider"))}console.log(iu()),console.log(),console.log(` ${c.accent("\u2605")} ${c.strong("CURRENT MODE: BUILD")} \u2014 Full Multi-Agent Team at Maximum Power`),console.log(` ${c.muted("Hablas + Bob + Alex + David + Emma \u2022 rich live theatre \u2022 no classifier")}`),console.log(` ${c.muted('Switch inside: /mode design or /mode ask | One-shot: hablas build "..."')}`),console.log();let K=!0;for(;K;)try{let te=(await a.prompt(` ${c.primary("\u203A")} `)).trim();if(!te)continue;if(te.startsWith("/")){if(await Fu(te,n,r,i,o,T,t,a,C,l,u,d,ue=>{r=ue},f,h,w,m)==="quit"){K=!1;break}continue}e.info({input:te},"Processing user input");let Q=Ec(te),ce=Ng(Q,t);if(C++,console.log(fu(C)),I=Di(I),dn(I),!W){let U=Sg(ce);if(U){console.log(gu(U));let ue=await a.prompt(` ${c.muted("\u203A")} `),Pe=_g(ue,U);ce=`${ce}
|
|
1233
1236
|
[Clarification: ${Pe.join(", ")}]`}}let Oe=Tg(ce,t,{maxFiles:8,maxTokens:6e3});if(Oe.files.length>0){let U=Rg(Oe);T.addUserMessage(`[Auto-loaded ${Oe.files.length} file(s): ${Oe.mentionedPaths.join(", ")}]
|
|
@@ -1238,10 +1241,8 @@ ${U}`,{priority:"low",tags:["auto-inject"]})}if(n.team?.enabled&&Re){let U=n.tea
|
|
|
1238
1241
|
${c.warning("\u26A0")} ${c.strong("@Consul")}: a teammate locked ${c.highlight(G)} first. Halting to avoid a conflict.
|
|
1239
1242
|
`);continue}}Re.setActivity(ce.slice(0,80))}let Fe=U=>{let ue=U.trim().toLowerCase();return ue.length<12||["hi","hey","\u0627\u0647","ok","thanks","\u0634\u0643\u0631\u0627","yo","hello","\u0635\u0628\u0627\u062D","\u0645\u0633\u0627\u0621","how are","what's up","\u0643\u064A\u0641\u0643","\u062A\u0645\u0627\u0645","\u0627\u064A\u0647","\u0627\u0647","lol","haha"].some(G=>ue.includes(G))?!0:!["build","create","fix","add","implement","design","make","write","update","remove","deploy","test","plan","generate","complete","setup"].some(G=>ue.includes(G))&&ue.length<40},ye=n.agents.enabled&&!Fe(ce);try{if(m&&n.agents.enabled){let U=`User input: "${ce}"
|
|
1240
1243
|
|
|
1241
|
-
Decide the professional routing for this engineering interaction.`,ue=await m.runAgent("gate",U,void 0,i.getOllamaTools(),{abortSignal:k?.signal});if(ue.success&&ue.output){let Pe=ue.output.toLowerCase();Pe.includes("mode: casual")||Pe.includes("casual")?ye=!1:(Pe.includes("mode: build")||Pe.includes("build")||Pe.includes("mode: design"))&&(ye=!0)}}}catch{}if(ye){console.log(`
|
|
1242
|
-
|
|
1243
|
-
`);let U=["hablas","bob","alex","david","emma"];for(let ee of U)I=Fi(I,ee);dn(I),p.reset(),x.resetBudget();let ue={id:"build-"+Date.now(),description:ce.substring(0,100),tasks:[{role:"emma",description:"Analyze the request from product/requirements perspective and clarify if needed."},{role:"bob",description:"Provide architecture, design or structural guidance."},{role:"alex",description:"Execute the core implementation, coding or action based on the input."},{role:"david",description:"Research, data analysis or supporting information."}],strategy:"mixed",createdAt:new Date,approved:!0},Pe=i.getOllamaTools(),D=new xs(p,m,x,n),G=[],P="The team operation completed.",V=!1;try{let ee=await D.run(ce,ue,Pe,{abortSignal:k?.signal,peerReview:!0});G=ee.results||[],P=ee.finalSynthesis||P,V=!!ee.synthesisOk}catch(ee){let de=ee?.message||String(ee);de.includes("Aborted")||ee?.name==="AbortError"?(console.log(` ${c.warning("Operation aborted.")}`),P="Team operation was aborted. Provide more details or try a focused request."):(console.log(ke(`Team error: ${de}`)),P="The team encountered an error during execution. Please review logs and retry."),V=!1}console.log(mn("Hablas","Team Leader")),console.log(gn(P)),T.addAssistantMessage(V?P:`[Team Summary]
|
|
1244
|
-
`+P),await Dg(n,t);continue}else T.addUserMessage(ce);k=new AbortController,S.startTurn(),_.resetTurn(),await Fg(T,r,i,o,{interactive:!0,autoMode:W,input:a,logger:e,config:n,abortSignal:k.signal,reactEngine:S,errorRecovery:_,skipTools:!1,onToolCall:()=>{F++,I=Li(I,"tool_call"),dn(I)}}),await Dg(n,t)}catch(Z){if(Z.code==="ERR_USE_AFTER_CLOSE")break;if(Z.name==="AbortError")continue;console.log(ke(Z.message)),e.error(Z,"REPL error")}a.close(),Re&&await Re.shutdown(),console.log(Yi({turns:C,duration:Date.now()-H,toolCalls:F}))}async function $0(n,e,t,s="build"){let r=e.workingDirectory==="."?process.cwd():e.workingDirectory;e.agents.enabled=!0;let i=Me(e),o=new En(r,e),a=new bs(e);a.setToolRegistry(o);let l=new vs,u=new _s(l).attach(),d=new ws(e,{tokenBudget:500,maxChars:140});a.setChannel(l),l.onEvent(w=>{w.type==="phase"?console.log(`
|
|
1244
|
+
Decide the professional routing for this engineering interaction.`,ue=await m.runAgent("gate",U,void 0,i.getOllamaTools(),{abortSignal:k?.signal});if(ue.success&&ue.output){let Pe=ue.output.toLowerCase();Pe.includes("mode: casual")||Pe.includes("casual")?ye=!1:(Pe.includes("mode: build")||Pe.includes("build")||Pe.includes("mode: design"))&&(ye=!0)}}}catch{}if(ye){let U=["hablas","bob","alex","david","emma"];for(let ee of U)I=Fi(I,ee);dn(I),p.reset(),x.resetBudget();let ue={id:"build-"+Date.now(),description:ce.substring(0,100),tasks:[{role:"emma",description:"Analyze the request from product/requirements perspective and clarify if needed."},{role:"bob",description:"Provide architecture, design or structural guidance."},{role:"alex",description:"Execute the core implementation, coding or action based on the input."},{role:"david",description:"Research, data analysis or supporting information."}],strategy:"mixed",createdAt:new Date,approved:!0},Pe=i.getOllamaTools(),D=new xs(p,m,x,n),G=[],P="The team operation completed.",V=!1;try{let ee=await D.run(ce,ue,Pe,{abortSignal:k?.signal,peerReview:!0});G=ee.results||[],P=ee.finalSynthesis||P,V=!!ee.synthesisOk}catch(ee){let de=ee?.message||String(ee);de.includes("Aborted")||ee?.name==="AbortError"?(console.log(` ${c.warning("Operation aborted.")}`),P="Team operation was aborted. Provide more details or try a focused request."):(console.log(ke(`Team error: ${de}`)),P="The team encountered an error during execution. Please review logs and retry."),V=!1}console.log(mn("Hablas","Team Leader")),console.log(gn(P)),T.addAssistantMessage(V?P:`[Team Summary]
|
|
1245
|
+
`+P),await Dg(n,t);continue}else T.addUserMessage(ce);k=new AbortController,S.startTurn(),_.resetTurn(),await Fg(T,r,i,o,{interactive:!0,autoMode:W,input:a,logger:e,config:n,abortSignal:k.signal,reactEngine:S,errorRecovery:_,skipTools:!1,onToolCall:()=>{F++,I=Li(I,"tool_call"),dn(I)}}),await Dg(n,t)}catch(Z){if(Z.code==="ERR_USE_AFTER_CLOSE")break;if(Z.name==="AbortError")continue;console.log(ke(Z.message)),e.error(Z,"REPL error")}a.close(),Re&&await Re.shutdown(),console.log(Yi({turns:C,duration:Date.now()-H,toolCalls:F}))}async function $0(n,e,t,s="build"){let r=e.workingDirectory==="."?process.cwd():e.workingDirectory;e.agents.enabled=!0;let i=Me(e),o=new En(r,e),a=new bs(e);a.setToolRegistry(o);let l=new vs,u=new _s(l,{hideActs:!0}).attach(),d=new ws(e,{tokenBudget:500,maxChars:140});a.setChannel(l),l.onEvent(w=>{w.type==="phase"?console.log(`
|
|
1245
1246
|
${c.accent("\u25C6")} ${c.strong(w.content)}`):w.type==="handoff"?console.log(` ${c.muted("\u2605")} ${w.agent} \u2501\u2501\u25B6 ${w.to}`):w.type==="speak"?console.log(` ${c.primary(w.agent)}: ${w.content}`):w.type==="act"||w.type==="tool"?console.log(` ${c.warning("\u{1F527}")} [${w.agent}] ${w.content||w.toolName}`):w.type==="summary"||w.type==="observe"?console.log(` ${c.success("\u2713")} ${w.agent||""} ${w.content||""}`):w.type==="error"&&console.log(` ${c.error("\u2717")} ${w.agent}: ${w.content}`)}),console.log(`
|
|
1246
1247
|
${c.accent("\u2605")} ${c.strong("FULL TEAM "+s.toUpperCase())} \u2014 ${e.model} (classification deleted, max power)`);let f={id:`${s}-`+Date.now(),description:n.substring(0,100),tasks:[{role:"emma",description:"Analyze the request from product/requirements perspective and clarify if needed."},{role:"bob",description:"Provide architecture, design or structural guidance."},{role:"alex",description:"Execute the core implementation, coding or action based on the input."},{role:"david",description:"Research, data analysis or supporting information."}],strategy:"mixed",createdAt:new Date,approved:!0},h=o.getOllamaTools(),m=new xs(l,a,d,e),{results:p,finalSynthesis:g,synthesisOk:x}=await m.run(n,f,h,{peerReview:!0});console.log(`
|
|
1247
1248
|
${mn("Hablas","Team Leader")}`),console.log(gn(g||"Team completed the task.")),console.log(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hablas-ai",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "Premium multi-agent AI coding agent for your terminal — local-first via Ollama, NVIDIA NIM, or any OpenAI-compatible API. Watch the team work in front of you.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|