nex-code 0.5.26 → 0.5.27

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.
@@ -120,7 +120,7 @@ Selection rationale: components/CommandCenter.tsx is an existing active editing
120
120
  Files: components/CommandCenter.tsx
121
121
  Implementation outline: read the planned implementation file, locate the Apply button if the first range misses it, then add one aria-label without changing behavior
122
122
  Verification plan: npm test && npm run build
123
- Browser/UI applicability: not required for this deterministic harness scenario`,tool_calls:[]}):o.lastStep<2?(o.lastStep=2,{content:"Reading the accepted implementation file.",tool_calls:[Se("read_file",{path:"components/CommandCenter.tsx",line_start:90,line_end:150},"i2")]}):o.lastStep<3?(o.lastStep=3,{content:"Checking labels inside the same planned file.",tool_calls:[Se("grep",{path:"components/CommandCenter.tsx",pattern:"Apply"},"i3")]}):o.lastStep<4?(o.lastStep=4,{content:"Trying the more specific Apply label in the same file.",tool_calls:[Se("grep",{path:"components/CommandCenter.tsx",pattern:"Apply changes"},"i4")]}):o.lastStep<5?(o.lastStep=5,{content:"Locating the Apply action class inside the same planned file.",tool_calls:[Se("grep",{path:"components/CommandCenter.tsx",pattern:"apply-action"},"i5")]}):o.lastStep<6?(o.lastStep=6,{content:"Reading the located Apply button range.",tool_calls:[Se("read_file",{path:"components/CommandCenter.tsx",line_start:200,line_end:230},"i6")]}):o.lastStep<7?(o.lastStep=7,{content:"Applying the scoped accessibility label.",tool_calls:[Se("edit_file",{path:"components/CommandCenter.tsx",old_text:'<button className="apply-action">Apply</button>',new_text:'<button className="apply-action" aria-label="Apply changes">Apply</button>'},"i7")]}):o.lastStep<8?(o.lastStep=8,{content:"Verifying, committing, pushing, and checking final status.",tool_calls:[Se("bash",{command:'npm test && npm run build && git status --short --branch && git add components/CommandCenter.tsx && git commit -m "fix: clarify command center apply label" && git push origin main && git status --short --branch'},"i8")]}):{content:"Located the Apply button with a same-file search after the initial range missed it, implemented the command center accessibility label, verified with npm test and npm run build, committed the scoped change, pushed main to origin, and confirmed the worktree is clean.",tool_calls:[]}}return{content:"No mock scenario matched this prompt. Set a Scenario A\u2013I prompt (or enable malformed mode) to run deterministic E2E flows.",tool_calls:[]}}var bc=class extends u${constructor(e={}){super({name:"mock",baseUrl:"mock://",models:{"mock-model":{id:"mock-model",name:"Mock Model",maxTokens:4096,contextWindow:8192}},defaultModel:"mock-model",...e})}isConfigured(){return process.env.NEX_MOCK_PROVIDER==="1"}async chat(e,n,o={}){return process.env.NEX_MOCK_NULL_RESPONSE==="1"?null:yp(e)}async stream(e,n,o={}){if(process.env.NEX_MOCK_NULL_RESPONSE==="1")return null;let s=typeof o.onToken=="function"?o.onToken:()=>{},r=yp(e),i=String(r.content||""),a=Math.min(i.length,Math.max(1,Math.floor(i.length/2)));return i&&(s(i.slice(0,a)),s(i.slice(a))),r}normalizeResponse(e){return e}};wp.exports={MockProvider:bc}});var _c=te((kP,_$)=>{_$.exports={name:"nex-code",version:"0.5.26",description:"Run 400B+ open coding models on your codebase without the hardware bill. Ollama Cloud first \u2014 OpenAI, Anthropic, and Gemini when you need them.",bin:{"nex-code":"./dist/nex-code.js"},files:["dist/","examples/","README.md","LICENSE"],engines:{node:">=18.0.0"},scripts:{start:"node dist/nex-code.js",build:"node scripts/build.js",dev:"node scripts/build.js --dev",test:"jest --runInBand","test:orchestrator":"jest tests/orchestrator.test.js --forceExit",coverage:"jest --coverage --forceExit","test:watch":"jest --watch",typecheck:"tsc --noEmit",format:"prettier --write .","scan:secrets":"node scripts/secret-scan.js --staged","install-hooks":"ln -sf ../../hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit && ln -sf ../../hooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push && ln -sf ../../hooks/post-merge .git/hooks/post-merge && chmod +x .git/hooks/post-merge && echo 'Hooks installed (pre-commit, pre-push, post-merge).'",prepublishOnly:"npm run build && npm test","merge-to-main":"bash scripts/merge-to-main.sh",improve:"node scripts/improve.js","extract-examples":"node scripts/extract-examples.js","benchmark:realworld":"node scripts/benchmark-realworld.js","benchmark:reallife":"node scripts/benchmark-reallife.js","benchmark:report":"node scripts/benchmark-reallife-report.js","improve:reallife":"node scripts/improve-reallife.js","benchmark:gate":"node scripts/benchmark-gate.js",release:"bash scripts/release.sh"},keywords:["ai","cli","coding","agent","ollama","ollama-cloud","openai","anthropic","gemini","llm","gpt","agentic","terminal","coding-assistant","open-source","free","qwen3","devstral","kimi-k2","deepseek","local-llm","mcp","model-context-protocol","multi-provider"],repository:{type:"git",url:"https://github.com/hybridpicker/nex-code.git"},bugs:{url:"https://github.com/hybridpicker/nex-code/issues"},homepage:"https://github.com/hybridpicker/nex-code#readme",license:"MIT",dependencies:{axios:"^1.15.0",dotenv:"^16.4.0",pixelmatch:"^7.1.0",pngjs:"^7.0.0"},devDependencies:{esbuild:"^0.27.3",jest:"^29.7.0",prettier:"^3.8.1",typescript:"^5.9.3"},overrides:{"brace-expansion":">=5.0.5",picomatch:">=4.0.4"},jest:{coverageThreshold:{global:{lines:45,functions:30,branches:35},"./cli/sub-agent.js":{lines:70,functions:60,branches:55}}}}});var js=te((xP,vp)=>{var{T:Z}=$n(),$c=5,Oo=(()=>{let t=[];for(let e=0;e<$c;e++)t.push(e);for(let e=$c-2;e>=1;e--)t.push(e);return t})(),_p=["\u273D","\u2726","\u2727","\u2726"],$p=["\xB7 ","\xB7\xB7 ","\xB7\xB7\xB7"," \xB7\xB7"];function kp(t=""){let e=String(t).toLowerCase();return e.includes("search")||e.includes("read")||e.includes("list")||e.includes("inspect")?{glyph:"\u25CC",color:Z.cyan,accent:"scan"}:e.includes("write")||e.includes("edit")||e.includes("patch")||e.includes("build")?{glyph:"\u2726",color:Z.yellow,accent:"shape"}:e.includes("test")||e.includes("diff")||e.includes("check")||e.includes("verify")?{glyph:"\u25A3",color:Z.green,accent:"verify"}:e.includes("wait")||e.includes("github")||e.includes("fetch")||e.includes("browser")?{glyph:"\u25CD",color:Z.blue,accent:"wait"}:{glyph:"\u25CF",color:Z.cyan,accent:"think"}}function xp(t,e,n){let o="";for(let s=0;s<$c;s++)s===t?o+=`${n}${e}${Z.reset}`:s===t-1||s===t+1?o+=`${Z.dim}\xB7${Z.reset}`:o+=`${Z.dim}\xB7${Z.reset}`;return o}function Sp(t){return`${Z.dim}${$p[t%$p.length]}${Z.reset}`}var kc=class{constructor(e="Thinking..."){this.text=e,this.frame=0,this.interval=null,this.startTime=null}_render(){if(this._stopped)return;let e=Oo[this.frame%Oo.length],n=kp(this.text),o=xp(e,n.glyph,n.color),s=Sp(this.frame),r="";if(this.startTime){let i=Math.floor((Date.now()-this.startTime)/1e3);if(i>=60){let a=Math.floor(i/60),l=i%60;r=` ${Z.dim}${a}m ${String(l).padStart(2,"0")}s${Z.reset}`}else i>=1&&(r=` ${Z.dim}${i}s${Z.reset}`)}process.stderr.write(`\x1B[2K\r${n.color}${n.accent.toUpperCase()}${Z.reset}${s} ${o} ${Z.dim}${this.text}${Z.reset}${r}`),this.frame++}start(){this._stopped=!1,this.startTime=Date.now(),process.stderr.isTTY&&(process.stderr.write("\x1B[?25l"),this._render(),this.interval=setInterval(()=>this._render(),100))}update(e){this.text=e}stop(){this._stopped=!0,this.interval&&(clearInterval(this.interval),this.interval=null),process.stderr.isTTY&&process.stderr.write("\x1B[2K\r\x1B[?25h"),this.startTime=null}},xc=class{constructor(e){this.labels=e,this.statuses=e.map(()=>"running"),this.frame=0,this.interval=null,this.startTime=null,this.lineCount=e.length}_formatElapsed(){if(!this.startTime)return"";let e=Math.floor((Date.now()-this.startTime)/1e3);if(e<1)return"";let n=Math.floor(e/60),o=e%60;return n>0?`${n}m ${String(o).padStart(2,"0")}s`:`${o}s`}_render(){if(this._stopped)return;let e=Oo[this.frame%Oo.length],n=`${Z.cyan}\u25CC${Z.reset}`,o=this._formatElapsed(),s=o?` ${Z.dim}${o}${Z.reset}`:"",r=process.stderr.columns||80,i="";for(let a=0;a<this.labels.length;a++){let l,c;switch(this.statuses[a]){case"done":l=`${Z.green}\u2713${Z.reset}`,c=Z.dim;break;case"error":l=`${Z.red}\u2717${Z.reset}`,c=Z.dim;break;case"retry":l=`${Z.yellow}\u21BB${Z.reset}`,c=Z.yellow;break;default:l=a===e?n:`${Z.dim}\xB7${Z.reset}`,c=""}let u=a===this.labels.length-1?s:"",d=r-4-(u?o.length+1:0),f=this.labels[a].length>d?this.labels[a].substring(0,Math.max(10,d-3))+"...":this.labels[a];i+=`\x1B[2K ${l} ${c}${f}${Z.reset}${u}
123
+ Browser/UI applicability: not required for this deterministic harness scenario`,tool_calls:[]}):o.lastStep<2?(o.lastStep=2,{content:"Reading the accepted implementation file.",tool_calls:[Se("read_file",{path:"components/CommandCenter.tsx",line_start:90,line_end:150},"i2")]}):o.lastStep<3?(o.lastStep=3,{content:"Checking labels inside the same planned file.",tool_calls:[Se("grep",{path:"components/CommandCenter.tsx",pattern:"Apply"},"i3")]}):o.lastStep<4?(o.lastStep=4,{content:"Trying the more specific Apply label in the same file.",tool_calls:[Se("grep",{path:"components/CommandCenter.tsx",pattern:"Apply changes"},"i4")]}):o.lastStep<5?(o.lastStep=5,{content:"Locating the Apply action class inside the same planned file.",tool_calls:[Se("grep",{path:"components/CommandCenter.tsx",pattern:"apply-action"},"i5")]}):o.lastStep<6?(o.lastStep=6,{content:"Reading the located Apply button range.",tool_calls:[Se("read_file",{path:"components/CommandCenter.tsx",line_start:200,line_end:230},"i6")]}):o.lastStep<7?(o.lastStep=7,{content:"Applying the scoped accessibility label.",tool_calls:[Se("edit_file",{path:"components/CommandCenter.tsx",old_text:'<button className="apply-action">Apply</button>',new_text:'<button className="apply-action" aria-label="Apply changes">Apply</button>'},"i7")]}):o.lastStep<8?(o.lastStep=8,{content:"Verifying, committing, pushing, and checking final status.",tool_calls:[Se("bash",{command:'npm test && npm run build && git status --short --branch && git add components/CommandCenter.tsx && git commit -m "fix: clarify command center apply label" && git push origin main && git status --short --branch'},"i8")]}):{content:"Located the Apply button with a same-file search after the initial range missed it, implemented the command center accessibility label, verified with npm test and npm run build, committed the scoped change, pushed main to origin, and confirmed the worktree is clean.",tool_calls:[]}}return{content:"No mock scenario matched this prompt. Set a Scenario A\u2013I prompt (or enable malformed mode) to run deterministic E2E flows.",tool_calls:[]}}var bc=class extends u${constructor(e={}){super({name:"mock",baseUrl:"mock://",models:{"mock-model":{id:"mock-model",name:"Mock Model",maxTokens:4096,contextWindow:8192}},defaultModel:"mock-model",...e})}isConfigured(){return process.env.NEX_MOCK_PROVIDER==="1"}async chat(e,n,o={}){return process.env.NEX_MOCK_NULL_RESPONSE==="1"?null:yp(e)}async stream(e,n,o={}){if(process.env.NEX_MOCK_NULL_RESPONSE==="1")return null;let s=typeof o.onToken=="function"?o.onToken:()=>{},r=yp(e),i=String(r.content||""),a=Math.min(i.length,Math.max(1,Math.floor(i.length/2)));return i&&(s(i.slice(0,a)),s(i.slice(a))),r}normalizeResponse(e){return e}};wp.exports={MockProvider:bc}});var _c=te((kP,_$)=>{_$.exports={name:"nex-code",version:"0.5.27",description:"Run 400B+ open coding models on your codebase without the hardware bill. Ollama Cloud first \u2014 OpenAI, Anthropic, and Gemini when you need them.",bin:{"nex-code":"./dist/nex-code.js"},files:["dist/","examples/","README.md","LICENSE"],engines:{node:">=18.0.0"},scripts:{start:"node dist/nex-code.js",build:"node scripts/build.js",dev:"node scripts/build.js --dev",test:"jest --runInBand","test:orchestrator":"jest tests/orchestrator.test.js --forceExit",coverage:"jest --coverage --forceExit","test:watch":"jest --watch",typecheck:"tsc --noEmit",format:"prettier --write .","scan:secrets":"node scripts/secret-scan.js --staged","install-hooks":"ln -sf ../../hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit && ln -sf ../../hooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push && ln -sf ../../hooks/post-merge .git/hooks/post-merge && chmod +x .git/hooks/post-merge && echo 'Hooks installed (pre-commit, pre-push, post-merge).'",prepublishOnly:"npm run build && npm test","merge-to-main":"bash scripts/merge-to-main.sh",improve:"node scripts/improve.js","extract-examples":"node scripts/extract-examples.js","benchmark:realworld":"node scripts/benchmark-realworld.js","benchmark:reallife":"node scripts/benchmark-reallife.js","benchmark:report":"node scripts/benchmark-reallife-report.js","improve:reallife":"node scripts/improve-reallife.js","benchmark:gate":"node scripts/benchmark-gate.js",release:"bash scripts/release.sh"},keywords:["ai","cli","coding","agent","ollama","ollama-cloud","openai","anthropic","gemini","llm","gpt","agentic","terminal","coding-assistant","open-source","free","qwen3","devstral","kimi-k2","deepseek","local-llm","mcp","model-context-protocol","multi-provider"],repository:{type:"git",url:"https://github.com/hybridpicker/nex-code.git"},bugs:{url:"https://github.com/hybridpicker/nex-code/issues"},homepage:"https://github.com/hybridpicker/nex-code#readme",license:"MIT",dependencies:{axios:"^1.15.0",dotenv:"^16.4.0",pixelmatch:"^7.1.0",pngjs:"^7.0.0"},devDependencies:{esbuild:"^0.27.3",jest:"^29.7.0",prettier:"^3.8.1",typescript:"^5.9.3"},overrides:{"brace-expansion":">=5.0.5",picomatch:">=4.0.4"},jest:{coverageThreshold:{global:{lines:45,functions:30,branches:35},"./cli/sub-agent.js":{lines:70,functions:60,branches:55}}}}});var js=te((xP,vp)=>{var{T:Z}=$n(),$c=5,Oo=(()=>{let t=[];for(let e=0;e<$c;e++)t.push(e);for(let e=$c-2;e>=1;e--)t.push(e);return t})(),_p=["\u273D","\u2726","\u2727","\u2726"],$p=["\xB7 ","\xB7\xB7 ","\xB7\xB7\xB7"," \xB7\xB7"];function kp(t=""){let e=String(t).toLowerCase();return e.includes("search")||e.includes("read")||e.includes("list")||e.includes("inspect")?{glyph:"\u25CC",color:Z.cyan,accent:"scan"}:e.includes("write")||e.includes("edit")||e.includes("patch")||e.includes("build")?{glyph:"\u2726",color:Z.yellow,accent:"shape"}:e.includes("test")||e.includes("diff")||e.includes("check")||e.includes("verify")?{glyph:"\u25A3",color:Z.green,accent:"verify"}:e.includes("wait")||e.includes("github")||e.includes("fetch")||e.includes("browser")?{glyph:"\u25CD",color:Z.blue,accent:"wait"}:{glyph:"\u25CF",color:Z.cyan,accent:"think"}}function xp(t,e,n){let o="";for(let s=0;s<$c;s++)s===t?o+=`${n}${e}${Z.reset}`:s===t-1||s===t+1?o+=`${Z.dim}\xB7${Z.reset}`:o+=`${Z.dim}\xB7${Z.reset}`;return o}function Sp(t){return`${Z.dim}${$p[t%$p.length]}${Z.reset}`}var kc=class{constructor(e="Thinking..."){this.text=e,this.frame=0,this.interval=null,this.startTime=null}_render(){if(this._stopped)return;let e=Oo[this.frame%Oo.length],n=kp(this.text),o=xp(e,n.glyph,n.color),s=Sp(this.frame),r="";if(this.startTime){let i=Math.floor((Date.now()-this.startTime)/1e3);if(i>=60){let a=Math.floor(i/60),l=i%60;r=` ${Z.dim}${a}m ${String(l).padStart(2,"0")}s${Z.reset}`}else i>=1&&(r=` ${Z.dim}${i}s${Z.reset}`)}process.stderr.write(`\x1B[2K\r${n.color}${n.accent.toUpperCase()}${Z.reset}${s} ${o} ${Z.dim}${this.text}${Z.reset}${r}`),this.frame++}start(){this._stopped=!1,this.startTime=Date.now(),process.stderr.isTTY&&(process.stderr.write("\x1B[?25l"),this._render(),this.interval=setInterval(()=>this._render(),100))}update(e){this.text=e}stop(){this._stopped=!0,this.interval&&(clearInterval(this.interval),this.interval=null),process.stderr.isTTY&&process.stderr.write("\x1B[2K\r\x1B[?25h"),this.startTime=null}},xc=class{constructor(e){this.labels=e,this.statuses=e.map(()=>"running"),this.frame=0,this.interval=null,this.startTime=null,this.lineCount=e.length}_formatElapsed(){if(!this.startTime)return"";let e=Math.floor((Date.now()-this.startTime)/1e3);if(e<1)return"";let n=Math.floor(e/60),o=e%60;return n>0?`${n}m ${String(o).padStart(2,"0")}s`:`${o}s`}_render(){if(this._stopped)return;let e=Oo[this.frame%Oo.length],n=`${Z.cyan}\u25CC${Z.reset}`,o=this._formatElapsed(),s=o?` ${Z.dim}${o}${Z.reset}`:"",r=process.stderr.columns||80,i="";for(let a=0;a<this.labels.length;a++){let l,c;switch(this.statuses[a]){case"done":l=`${Z.green}\u2713${Z.reset}`,c=Z.dim;break;case"error":l=`${Z.red}\u2717${Z.reset}`,c=Z.dim;break;case"retry":l=`${Z.yellow}\u21BB${Z.reset}`,c=Z.yellow;break;default:l=a===e?n:`${Z.dim}\xB7${Z.reset}`,c=""}let u=a===this.labels.length-1?s:"",d=r-4-(u?o.length+1:0),f=this.labels[a].length>d?this.labels[a].substring(0,Math.max(10,d-3))+"...":this.labels[a];i+=`\x1B[2K ${l} ${c}${f}${Z.reset}${u}
124
124
  `}this.lineCount>0&&(i+=`\x1B[${this.lineCount}A`),process.stderr.write(i),this.frame++}start(){this._stopped=!1,this.startTime=Date.now();let e="\x1B[?25l";for(let n=0;n<this.lineCount;n++)e+=`
125
125
  `;this.lineCount>0&&(e+=`\x1B[${this.lineCount}A`),process.stderr.write(e),this._render(),this.interval=setInterval(()=>this._render(),100)}update(e,n){e>=0&&e<this.statuses.length&&(this.statuses[e]=n)}stop(e={}){if(this._stopped=!0,this.interval&&(clearInterval(this.interval),this.interval=null),!e.silent)this._renderFinal();else{let n="";for(let o=0;o<this.lineCount;o++)n+=`\x1B[2K
126
126
  `;this.lineCount>0&&(n+=`\x1B[${this.lineCount}A`),process.stderr.write(n)}process.stderr.write("\x1B[?25h")}_renderFinal(){let e=this._formatElapsed(),n=e?` ${Z.dim}${e}${Z.reset}`:"",o=process.stderr.columns||80,s="";for(let r=0;r<this.labels.length;r++){let i;switch(this.statuses[r]){case"done":i=`${Z.green}\u2713${Z.reset}`;break;case"error":i=`${Z.red}\u2717${Z.reset}`;break;case"retry":i=`${Z.yellow}\u21BB${Z.reset}`;break;default:i=`${Z.yellow}\u25CB${Z.reset}`}let a=r===this.labels.length-1?n:"",l=o-4-(a?e.length+1:0),c=this.labels[r].length>l?this.labels[r].substring(0,Math.max(10,l-3))+"...":this.labels[r];s+=`\x1B[2K ${i} ${Z.dim}${c}${Z.reset}${a}
@@ -971,16 +971,16 @@ end try`],{timeout:3e3});if(o.stdout&&o.stdout.toString().trim()==="has_image"){
971
971
  [SYSTEM: Output repetition detected \u2014 response truncated (${s}\xD7 repeated paragraph)]`,a;if(t.length>8e3)a=t.slice(0,3e3)+i;else{let l=0,c=-1,u=0;for(;l<2;){let d=t.indexOf(r,u);if(d===-1)break;l++,c=d+r.length,u=d+1}a=c>0?t.slice(0,c)+i:t.slice(0,3e3)+i}return{text:a,truncated:!0,repeatCount:s}}function Bd(t,e=5){if(!t||t.length<40)return{text:t,truncated:!1,repeatCount:0};let n=t.split(`
972
972
  `),o=new Map;for(let p of n){let m=p.trim();m.length>=20&&o.set(m,(o.get(m)||0)+1)}let s=0,r="";for(let[p,m]of o)m>s&&(s=m,r=p);let a=r.toLowerCase().includes("read_file")||r.toLowerCase().includes("reading")?2:e;if(s<=a)return{text:t,truncated:!1,repeatCount:s};let l=`
973
973
 
974
- \u26A0 [Response truncated: repeated paragraph detected (${s}\xD7)]`,c=0,u=-1,d=0;for(;c<e;){let p=t.indexOf(r,d);if(p===-1)break;c++,u=p+r.length,d=p+1}return{text:u>0?t.slice(0,u)+l:t.slice(0,2e3)+l,truncated:!0,repeatCount:s}}var Td=null,Rd=null,Cd=null;function zt(){if(Td===null){let{TOOL_DEFINITIONS:t}=kr();Td=t}return Rd===null&&(Rd=sA()),Cd===null&&(Cd=tA()),[...Td,...Rd,...Cd]}var bl=50;function bA(t){Number.isFinite(t)&&t>0&&(bl=t)}function Ad(t=Gn()){if(process.env.NEX_DISABLE_TOOL_BUDGET==="1")return 1/0;let e=process.env.NEX_MAX_TOOL_CALLS;if(e){let n=parseInt(e,10);if(Number.isFinite(n)&&n>0)return n}return t==="local"?5:30}function Aw(t,e){return`[SYSTEM STOP] Tool-call budget reached (${t}/${e}). You MUST stop calling tools now. Provide your final answer based only on the information already in the conversation. If the task cannot be completed from the gathered evidence, state the blocker plainly and do not invent facts.`}var wl=()=>null;function wA(t){wl=t}var ri=null,Ud=null,nr=null,sr="",or=0,Wd="",Hd=0,_l=new Map,_A=1e4,$A=6e3,kA=/\b((?:API|ACCESS|AUTH|BEARER|CLIENT|GITHUB|GITLAB|SLACK|STRIPE|TWILIO|SENDGRID|AWS|GCP|AZURE|OPENAI|ANTHROPIC|GEMINI|OLLAMA)[_A-Z0-9]*(?:KEY|TOKEN|SECRET|PASS(?:WORD)?|CREDENTIAL)[_A-Z0-9]*)\s*=\s*["']?([A-Za-z0-9\-_.+/=]{10,})["']?/g;function xA(t){return!t||typeof t!="string"?t:t.replace(kA,(e,n)=>`${n}=***REDACTED***`)}var SA=7e3,vA=4e3;function EA(t,e=null){let n=xA(t),o=TC(n),s=e==="read_file"?SA:_A,r=e==="read_file"?vA:$A;if(o>s)try{let{compressToolResult:i}=qn();return i(n,r)}catch{return n}return n}function Yw(t){try{let{getActiveModel:e}=Tt(),n=e(),o=n?`${n.provider}:${n.id}`:"default";if(_l.has(o))return _l.get(o);let s=Ew(t);return _l.set(o,s),s}catch{return Ew(t)}}function TA(){_l.clear()}function RA(t,e){let n=new Set(e);return(t||[]).some(o=>o.role!=="assistant"?!1:Array.isArray(o.tool_calls)?o.tool_calls.some(s=>n.has(s?.function?.name||s?.name)):Array.isArray(o.content)?o.content.some(s=>s?.type==="tool_use"&&n.has(s?.name)):!1)}var ii={hash:null,ts:0},CA=3e4;async function zw(){if(ii.hash&&Date.now()-ii.ts<CA)return ii.hash;try{let t=require("fs").promises,e=require("path"),n=[e.join(process.cwd(),"package.json"),e.join(process.cwd(),".git","HEAD"),e.join(process.cwd(),"README.md"),e.join(process.cwd(),"NEX.md")],s=(await Promise.allSettled(n.map(i=>t.stat(i).then(a=>`${i}:${a.mtimeMs}`)))).filter(i=>i.status==="fulfilled").map(i=>i.value);try{let{getMemoryContextHash:i}=Dr(),a=i();a&&s.push(`memory:${a}`)}catch{}try{let i=e.join(process.cwd(),".nex","brain");if(Be.existsSync(i)){let a=await t.stat(i);s.push(`brain:${a.mtimeMs}`)}}catch{}let r=s.join("|");return ii={hash:r,ts:Date.now()},r}catch{return`fallback:${Date.now()}`}}function $l(){ri=null,Ud=null,ii={hash:null,ts:0},nr=null}var AA=new Set(["spawn_agents"]),Od=10,Pd=10,fl=5,Ow=6e4,Nd=12e4,OA=process.env.NEX_STALE_AUTO_SWITCH!=="0";function PA(t){try{let e=require("fs"),n=require("path"),o=n.join(process.cwd(),".nex","plans");e.existsSync(o)||e.mkdirSync(o,{recursive:!0});let s=n.join(o,"current-plan.md");e.writeFileSync(s,t,"utf-8")}catch{}}YC(t=>{HC(t,"allow"),GC(),console.log(`${h.green} \u2713 ${t}: always allow${h.reset}`)});async function NA(t){let e=t.function.name,n=e;if(typeof e=="string"&&e.includes(".")){let d=e.split(".").pop(),f={exec:"bash",find:"search_files",search:"search_files",grep_search:"grep",list:"list_directory",print_tree:"list_directory",read:"read_file",tree:"list_directory"};zt().some(m=>m.function.name===d)?n=d:f[d]&&(n=f[d])}let o=SC(t.function.arguments),s=t.id||`cli-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;if(!o){let f=zt().find(m=>m.function.name===n),p=f?JSON.stringify(f.function.parameters,null,2):"unknown";return N(`${h.yellow} \u26A0 ${n}: malformed arguments, sending schema hint${h.reset}`),{callId:s,fnName:n,args:null,canExecute:!1,errorResult:{role:"tool",content:`ERROR: Malformed tool arguments. Could not parse your arguments as JSON.
974
+ \u26A0 [Response truncated: repeated paragraph detected (${s}\xD7)]`,c=0,u=-1,d=0;for(;c<e;){let p=t.indexOf(r,d);if(p===-1)break;c++,u=p+r.length,d=p+1}return{text:u>0?t.slice(0,u)+l:t.slice(0,2e3)+l,truncated:!0,repeatCount:s}}var Td=null,Rd=null,Cd=null;function zt(){if(Td===null){let{TOOL_DEFINITIONS:t}=kr();Td=t}return Rd===null&&(Rd=sA()),Cd===null&&(Cd=tA()),[...Td,...Rd,...Cd]}var bl=50;function bA(t){Number.isFinite(t)&&t>0&&(bl=t)}function Ad(t=Gn()){if(process.env.NEX_DISABLE_TOOL_BUDGET==="1")return 1/0;let e=process.env.NEX_MAX_TOOL_CALLS;if(e){let n=parseInt(e,10);if(Number.isFinite(n)&&n>0)return n}return t==="local"?5:30}function Aw(t,e){return`[SYSTEM STOP] Tool-call budget reached (${t}/${e}). You MUST stop calling tools now. Provide your final answer based only on the information already in the conversation. If the task cannot be completed from the gathered evidence, state the blocker plainly and do not invent facts.`}var wl=()=>null;function wA(t){wl=t}var ri=null,Ud=null,nr=null,sr="",or=0,Wd="",Hd=0,_l=new Map,_A=1e4,$A=6e3,kA=/\b((?:API|ACCESS|AUTH|BEARER|CLIENT|GITHUB|GITLAB|SLACK|STRIPE|TWILIO|SENDGRID|AWS|GCP|AZURE|OPENAI|ANTHROPIC|GEMINI|OLLAMA)[_A-Z0-9]*(?:KEY|TOKEN|SECRET|PASS(?:WORD)?|CREDENTIAL)[_A-Z0-9]*)\s*=\s*["']?([A-Za-z0-9\-_.+/=]{10,})["']?/g;function xA(t){return!t||typeof t!="string"?t:t.replace(kA,(e,n)=>`${n}=***REDACTED***`)}var SA=7e3,vA=4e3;function EA(t,e=null){let n=xA(t),o=TC(n),s=e==="read_file"?SA:_A,r=e==="read_file"?vA:$A;if(o>s)try{let{compressToolResult:i}=qn();return i(n,r)}catch{return n}return n}function Yw(t){try{let{getActiveModel:e}=Tt(),n=e(),o=n?`${n.provider}:${n.id}`:"default";if(_l.has(o))return _l.get(o);let s=Ew(t);return _l.set(o,s),s}catch{return Ew(t)}}function TA(){_l.clear()}function RA(t,e){let n=new Set(e);return(t||[]).some(o=>o.role!=="assistant"?!1:Array.isArray(o.tool_calls)?o.tool_calls.some(s=>n.has(s?.function?.name||s?.name)):Array.isArray(o.content)?o.content.some(s=>s?.type==="tool_use"&&n.has(s?.name)):!1)}var ii={hash:null,ts:0},CA=3e4;async function zw(){if(ii.hash&&Date.now()-ii.ts<CA)return ii.hash;try{let t=require("fs").promises,e=require("path"),n=[e.join(process.cwd(),"package.json"),e.join(process.cwd(),".git","HEAD"),e.join(process.cwd(),"README.md"),e.join(process.cwd(),"NEX.md")],s=(await Promise.allSettled(n.map(i=>t.stat(i).then(a=>`${i}:${a.mtimeMs}`)))).filter(i=>i.status==="fulfilled").map(i=>i.value);try{let{getMemoryContextHash:i}=Dr(),a=i();a&&s.push(`memory:${a}`)}catch{}try{let i=e.join(process.cwd(),".nex","brain");if(Be.existsSync(i)){let a=await t.stat(i);s.push(`brain:${a.mtimeMs}`)}}catch{}let r=s.join("|");return ii={hash:r,ts:Date.now()},r}catch{return`fallback:${Date.now()}`}}function $l(){ri=null,Ud=null,ii={hash:null,ts:0},nr=null}var AA=new Set(["spawn_agents"]),Od=10,Pd=10,fl=5,Ow=6e4,Nd=12e4,OA=process.env.NEX_STALE_AUTO_SWITCH!=="0";function PA(t){try{let e=require("fs"),n=require("path"),o=n.join(process.cwd(),".nex","plans");e.existsSync(o)||e.mkdirSync(o,{recursive:!0});let s=n.join(o,"current-plan.md");e.writeFileSync(s,t,"utf-8")}catch{}}YC(t=>{HC(t,"allow"),GC(),console.log(`${h.green} \u2713 ${t}: always allow${h.reset}`)});async function NA(t){let e=t.function.name,n=e;if(typeof e=="string"&&e.includes(".")){let f=e.split(".").pop(),p={exec:"bash",find:"search_files",search:"search_files",grep_search:"grep",list:"list_directory",print_tree:"list_directory",read:"read_file",tree:"list_directory"};zt().some(g=>g.function.name===f)?n=f:p[f]&&(n=p[f])}let o=SC(t.function.arguments),s=t.id||`cli-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;if(!o){let p=zt().find(g=>g.function.name===n),m=p?JSON.stringify(p.function.parameters,null,2):"unknown";return N(`${h.yellow} \u26A0 ${n}: malformed arguments, sending schema hint${h.reset}`),{callId:s,fnName:n,args:null,canExecute:!1,errorResult:{role:"tool",content:`ERROR: Malformed tool arguments. Could not parse your arguments as JSON.
975
975
  Raw input: ${typeof t.function.arguments=="string"?t.function.arguments.substring(0,200):"N/A"}
976
976
 
977
977
  Expected JSON schema for "${n}":
978
- ${p}
978
+ ${m}
979
979
 
980
- Please retry the tool call with valid JSON arguments matching this schema.`,tool_call_id:s}}}if(o&&typeof o.path=="string")try{let d=require("os"),f=Ge.resolve(process.cwd(),o.path.replace(/^~/,d.homedir())),p=o.path;o.path=Ge.relative(process.cwd(),f)||".",Object.defineProperty(o,"_originalPath",{value:p,enumerable:!1})}catch(d){console.error("path resolution failed:",d.message)}o&&(n==="search_files"||n==="grep")&&typeof o.pattern!="string"&&(typeof o.query=="string"?o.pattern=o.query:typeof o.search=="string"&&(o.pattern=o.search));let r=iA(n,o);if(!r.valid){N(`${h.yellow} \u26A0 ${n}: ${r.error.split(`
981
- `)[0]}${h.reset}`);let d=(Nw.get(n)||0)+1;Nw.set(n,d);let f=d>=2?`${r.error}
980
+ Please retry the tool call with valid JSON arguments matching this schema.`,tool_call_id:s}}}if(o&&typeof o.path=="string")try{let f=require("os"),p=Ge.resolve(process.cwd(),o.path.replace(/^~/,f.homedir())),m=o.path;o.path=Ge.relative(process.cwd(),p)||".",Object.defineProperty(o,"_originalPath",{value:m,enumerable:!1})}catch(f){console.error("path resolution failed:",f.message)}o&&(n==="search_files"||n==="grep")&&typeof o.pattern!="string"&&(typeof o.query=="string"?o.pattern=o.query:typeof o.search=="string"&&(o.pattern=o.search));let r=iA(n,o);if(!r.valid){N(`${h.yellow} \u26A0 ${n}: ${r.error.split(`
981
+ `)[0]}${h.reset}`);let f=(Nw.get(n)||0)+1;Nw.set(n,f);let p=f>=2?`${r.error}
982
982
 
983
- [SYSTEM: This is argument error #${d} for "${n}". Study the "Expected parameters" schema above and correct your call \u2014 do not repeat the same mistake.]`:r.error;return{callId:s,fnName:n,args:o,canExecute:!1,errorResult:{role:"tool",content:f,tool_call_id:s}}}let i=r.corrected||o;if(r.corrected){let d=Object.keys(o),f=Object.keys(r.corrected),p=d.filter(m=>!f.includes(m));p.length&&console.log(`${h.dim} \u2713 ${n}: corrected args (${p.join(", ")})${h.reset}`)}if(fo()&&!Fw.has(n))return console.log(`${h.yellow} \u2717 ${n}: blocked in plan mode${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`PLAN MODE: '${n}' is blocked. Only read-only tools are allowed. Present your plan as text output instead of making changes.`,tool_call_id:s}};let a=new Set(["read_file","list_directory","search_files","glob","grep","git_status","git_diff","git_log","git_show","ssh_exec"]),l=new Set(["read_file","list_directory","glob","grep","bash","git_status","git_diff","git_log","ssh_exec"]),c=n==="spawn_agents"&&Array.isArray(i?.agents)&&i.agents.length>0&&i.agents.every(d=>d.background===!0);if(ue&&$e==="plan"&&!a.has(n)&&!n.startsWith("skill_")&&!c)return vs++,ar=n,N(`${h.yellow} \u2717 ${n}: blocked in plan phase (read-only, block #${vs})${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`PLAN PHASE: '${n}' is blocked. Analyze the codebase using read-only tools, then present your findings as text. Edits happen in the next phase.`,tool_call_id:s}};if(ue&&$e==="verify"&&!l.has(n)&&!n.startsWith("skill_"))return N(`${h.yellow} \u2717 ${n}: blocked in verify phase (read + bash only)${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`VERIFY PHASE: '${n}' is blocked. Use read_file and bash (for tests/linters) to verify changes. Report PASS or FAIL.`,tool_call_id:s}};let u=WC(n);if(u==="deny")return console.log(`${h.red} \u2717 ${n}: denied by permissions${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`DENIED: Tool '${n}' is blocked by permissions`,tool_call_id:s}};if(u==="ask"){let d=` Allow ${n}?`;return n==="bash"&&i.command&&(d=` bash: \`${i.command.substring(0,80)}${i.command.length>80?"\u2026":""}\`?`),await qw(d,{toolName:n})?{callId:s,fnName:n,args:i,canExecute:!0,confirmedByUser:!0,errorResult:null}:{callId:s,fnName:n,args:i,canExecute:!1,confirmedByUser:!1,errorResult:{role:"tool",content:`CANCELLED: User declined ${n}`,tool_call_id:s}}}return{callId:s,fnName:n,args:i,canExecute:!0,confirmedByUser:!0,errorResult:null}}async function MA(t,e,n={}){let o=await oA(t,e);if(o!==null)return o;let s=await eA(t,e);return s!==null?s:sf(t,e,n)}function LA(t,e){switch(t){case"read_file":case"write_file":case"edit_file":case"patch_file":case"list_directory":return e._originalPath||e.path||"";case"bash":return(e.command||"").substring(0,60);case"grep":case"search_files":case"glob":return e.pattern||"";case"web_fetch":return(e.url||"").substring(0,50);case"web_search":return(e.query||"").substring(0,40);default:return""}}async function Md(t,e=!1){e||console.log($C(t.fnName,t.args));let n=_w("pre-tool",{tool_name:t.fnName}),o=n.results;if(n.blocked){let w=`BLOCKED: pre-tool hook rejected ${t.fnName}: ${n.blockReason}`;e||console.log(`${h.yellow} [hook pre-tool] BLOCKED: ${n.blockReason}${h.reset}`);let k=bi(t.fnName,t.args,w,!0);return e||console.log(k),{msg:{role:"tool",content:w,tool_call_id:t.callId},summary:k}}if(!e&&o.length>0)for(let w of o)w.success?console.log(`${h.dim} [hook pre-tool] ${w.command} \u2192 ${w.output||"ok"}${h.reset}`):console.log(`${h.yellow} [hook pre-tool] ${w.command} \u2192 ERROR: ${w.error}${h.reset}`);dt?.onToolStart&&dt.onToolStart(t.fnName,t.args);let s=await MA(t.fnName,t.args,{silent:!0,autoConfirm:t.confirmedByUser===!0}),r=null,i;s&&typeof s=="object"&&s.text?(i=String(s.text),Array.isArray(s.images)&&s.images.length>0&&(r=s.images)):i=String(s??"");let a=i.length>5e4?i.substring(0,5e4)+`
983
+ [SYSTEM: This is argument error #${f} for "${n}". Study the "Expected parameters" schema above and correct your call \u2014 do not repeat the same mistake.]`:r.error;return{callId:s,fnName:n,args:o,canExecute:!1,errorResult:{role:"tool",content:p,tool_call_id:s}}}let i=r.corrected||o;if(r.corrected){let f=Object.keys(o),p=Object.keys(r.corrected),m=f.filter(g=>!p.includes(g));m.length&&console.log(`${h.dim} \u2713 ${n}: corrected args (${m.join(", ")})${h.reset}`)}if(fo()&&!Fw.has(n))return console.log(`${h.yellow} \u2717 ${n}: blocked in plan mode${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`PLAN MODE: '${n}' is blocked. Only read-only tools are allowed. Present your plan as text output instead of making changes.`,tool_call_id:s}};let a=new Set(["read_file","list_directory","search_files","glob","grep","git_status","git_diff","git_log","git_show","ssh_exec"]),l=new Set(["read_file","list_directory","glob","grep","bash","git_status","git_diff","git_log","ssh_exec"]),c=n==="spawn_agents"&&Array.isArray(i?.agents)&&i.agents.length>0&&i.agents.every(f=>f.background===!0);if(ue&&$e==="plan"&&!a.has(n)&&!n.startsWith("skill_")&&!c)return vs++,ar=n,N(`${h.yellow} \u2717 ${n}: blocked in plan phase (read-only, block #${vs})${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`PLAN PHASE: '${n}' is blocked. Analyze the codebase using read-only tools, then present your findings as text. Edits happen in the next phase.`,tool_call_id:s}};if(ue&&$e==="verify"&&!l.has(n)&&!n.startsWith("skill_"))return N(`${h.yellow} \u2717 ${n}: blocked in verify phase (read + bash only)${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`VERIFY PHASE: '${n}' is blocked. Use read_file and bash (for tests/linters) to verify changes. Report PASS or FAIL.`,tool_call_id:s}};if(new Set(["write_file","edit_file","patch_file"]).has(n)&&process.env.NEX_SCOPE){let f=i.path||i.file_path||"";if(f){let p=process.env.NEX_SCOPE.split(",").map(w=>w.trim()),m=f.replace(/\\/g,"/");if(!p.some(w=>new RegExp("^"+w.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"___DOUBLESTAR___").replace(/\*/g,"[^/]*").replace(/___DOUBLESTAR___/g,".*")+"$").test(m)||m.endsWith(w)||m===w))return N(`${h.yellow} \u2717 ${n}: ${f} outside scope (--scope ${process.env.NEX_SCOPE})${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`SCOPE BLOCKED: '${f}' is outside the allowed scope. Only these files may be edited: ${process.env.NEX_SCOPE}. Use read_file to inspect other files, but do not edit them.`,tool_call_id:s}}}}let d=WC(n);if(d==="deny")return console.log(`${h.red} \u2717 ${n}: denied by permissions${h.reset}`),{callId:s,fnName:n,args:i,canExecute:!1,errorResult:{role:"tool",content:`DENIED: Tool '${n}' is blocked by permissions`,tool_call_id:s}};if(d==="ask"){let f=` Allow ${n}?`;return n==="bash"&&i.command&&(f=` bash: \`${i.command.substring(0,80)}${i.command.length>80?"\u2026":""}\`?`),await qw(f,{toolName:n})?{callId:s,fnName:n,args:i,canExecute:!0,confirmedByUser:!0,errorResult:null}:{callId:s,fnName:n,args:i,canExecute:!1,confirmedByUser:!1,errorResult:{role:"tool",content:`CANCELLED: User declined ${n}`,tool_call_id:s}}}return{callId:s,fnName:n,args:i,canExecute:!0,confirmedByUser:!0,errorResult:null}}async function MA(t,e,n={}){let o=await oA(t,e);if(o!==null)return o;let s=await eA(t,e);return s!==null?s:sf(t,e,n)}function LA(t,e){switch(t){case"read_file":case"write_file":case"edit_file":case"patch_file":case"list_directory":return e._originalPath||e.path||"";case"bash":return(e.command||"").substring(0,60);case"grep":case"search_files":case"glob":return e.pattern||"";case"web_fetch":return(e.url||"").substring(0,50);case"web_search":return(e.query||"").substring(0,40);default:return""}}async function Md(t,e=!1){e||console.log($C(t.fnName,t.args));let n=_w("pre-tool",{tool_name:t.fnName}),o=n.results;if(n.blocked){let w=`BLOCKED: pre-tool hook rejected ${t.fnName}: ${n.blockReason}`;e||console.log(`${h.yellow} [hook pre-tool] BLOCKED: ${n.blockReason}${h.reset}`);let k=bi(t.fnName,t.args,w,!0);return e||console.log(k),{msg:{role:"tool",content:w,tool_call_id:t.callId},summary:k}}if(!e&&o.length>0)for(let w of o)w.success?console.log(`${h.dim} [hook pre-tool] ${w.command} \u2192 ${w.output||"ok"}${h.reset}`):console.log(`${h.yellow} [hook pre-tool] ${w.command} \u2192 ERROR: ${w.error}${h.reset}`);dt?.onToolStart&&dt.onToolStart(t.fnName,t.args);let s=await MA(t.fnName,t.args,{silent:!0,autoConfirm:t.confirmedByUser===!0}),r=null,i;s&&typeof s=="object"&&s.text?(i=String(s.text),Array.isArray(s.images)&&s.images.length>0&&(r=s.images)):i=String(s??"");let a=i.length>5e4?i.substring(0,5e4)+`
984
984
  ...(truncated ${i.length-5e4} chars)`:i,l=a.split(`
985
985
  `)[0],c=l.startsWith("ERROR")||l.includes("CANCELLED")||l.includes("BLOCKED")||t.fnName==="spawn_agents"&&!/✓ Agent/.test(a)&&/✗ Agent/.test(a),u=bi(t.fnName,t.args,a,c);e||console.log(u),dt?.onToolEnd&&dt.onToolEnd(t.fnName,u,!c);let f=_w("post-tool",{tool_name:t.fnName}).results;if(!e&&f.length>0)for(let w of f)w.success?console.log(`${h.dim} [hook post-tool] ${w.command} \u2192 ${w.output||"ok"}${h.reset}`):console.log(`${h.yellow} [hook post-tool] ${w.command} \u2192 ERROR: ${w.error}${h.reset}`);let m=EA(a,t.fnName);if(t.fnName==="bash"&&t.args?.command){let w=t.args.command.trim();!/cat\s*>|<</.test(w)&&/\bcat\s+\S/.test(w)?m+=`
986
986
  HINT: use read_file instead of bash cat \u2014 it is faster, context-efficient, and the preferred tool for reading files.`:/^\s*ls(\s|$)/.test(w)&&!/npm|yarn|pnpm|make|git\b/.test(w)?m+=`