MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / ur

Function ur

package/cli.js:1682–1682  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

1680This command would remove a critical system directory. This requires explicit approval and cannot be auto-allowed by permission rules.`,decisionReason:{type:"other",reason:`Dangerous ${q} operation on critical path: ${O}`},suggestions:[]}}return{behavior:"passthrough",message:`No dangerous removals detected for ${q} command`}}function LA(q){let K=[],_=!1;for(let z of q)if(_)K.push(z);else if(z==="--")_=!0;else if(!z?.startsWith("-"))K.push(z);return K}function fy4(q,K,_=[]){let z=[],Y=!1,$=!1;for(let A=0;A<q.length;A++){let O=q[A];if(O===void 0||O===null)continue;if(!$&&O==="--"){$=!0;continue}if(!$&&O.startsWith("-")){let w=O.split("=")[0];if(w&&["-e","--regexp","-f","--file"].includes(w))Y=!0;if(w&&K.has(w)&&!O.includes("="))A++;continue}if(!Y){Y=!0;continue}z.push(O)}return z.length>0?z:_}function s_z(q,K,_,z,Y,$){let A=Wo6[q],O=A(K),w=$??Do6[q],j=a_z[q];if(j&&!j(K))return{behavior:"ask",message:`${q} with flags requires manual approval to ensure path safety. For security, Claude Code cannot automatically validate ${q} commands that use flags, as some flags like --target-directory=PATH can bypass path validation.`,decisionReason:{type:"other",reason:`${q} command with flags requires manual approval`}};if(Y&&w!=="read")return{behavior:"ask",message:"Commands that change directories and perform write operations require explicit approval to ensure paths are evaluated correctly. For security, Claude Code cannot automatically determine the final working directory when 'cd' is used in compound commands.",decisionReason:{type:"other",reason:"Compound command contains cd with write operation - manual approval required to prevent path resolution bypass"}};for(let H of O){let{allowed:J,resolvedPath:M,decisionReason:X}=JS1(H,_,z,w);if(!J){let P=Array.from(ku(z)),W=jS1(P),D=X?.type==="other"||X?.type==="safetyCheck"?X.reason:`${q} in '${M}' was blocked. For security, Claude Code may only ${o_z[q]} the allowed working directories for this session: ${W}.`;if(X?.type==="rule")return{behavior:"deny",message:D,decisionReason:X};return{behavior:"ask",message:D,blockedPath:M,decisionReason:X}}}return{behavior:"passthrough",message:`Path validation passed for ${q} command`}}function Ty4(q,K){return(_,z,Y,$)=>{let A=s_z(q,_,z,Y,$,K);if(A.behavior==="deny")return A;if(q==="rm"||q==="rmdir"){let O=r_z(q,_,z);if(O.behavior!=="passthrough")return O}if(A.behavior==="passthrough")return A;if(A.behavior==="ask"){let O=K??Do6[q],w=[];if(A.blockedPath)if(O==="read"){let j=IZ(A.blockedPath),H=Kw6(j,"session");if(H)w.push(H)}else w.push({type:"addDirectories",directories:[IZ(A.blockedPath)],destination:"session"});if(O==="write"||O==="create")w.push({type:"setMode",mode:"acceptEdits",destination:"session"});A.suggestions=w}return A}}function t_z(q){let K=o$(q,(Y)=>`$${Y}`);if(!K.success)return[];let _=K.tokens,z=[];for(let Y of _)if(typeof Y==="string")z.push(Y);else if(typeof Y==="object"&&Y!==null&&"op"in Y&&Y.op==="glob"&&"pattern"in Y)z.push(String(Y.pattern));return z}function e_z(q,K,_,z){let Y=Ir(q),$=t_z(Y);if($.length===0)return{behavior:"passthrough",message:"Empty command - no paths to validate"};let[A,...O]=$;if(!A||!Gy4.includes(A))return{behavior:"passthrough",message:`Command '${A}' is not a path-restricted command`};let w=A==="sed"&&RV6(Y)?"read":void 0;return Ty4(A,w)(O,K,_,z)}function qzz(q,K,_,z){let Y=Azz(q.argv);if(Y.length===0)return{behavior:"passthrough",message:"Empty command - no paths to validate"};let[$,...A]=Y;if(!$||!Gy4.includes($))return{behavior:"passthrough",message:`Command '${$}' is not a path-restricted command`};let O=$==="sed"&&RV6(Ir(q.text))?"read":void 0;return Ty4($,O)(A,K,_,z)}function Kzz(q,K,_,z){if(z&&q.length>0)return{behavior:"ask",message:"Commands that change directories and write via output redirection require explicit approval to ensure paths are evaluated correctly. For security, Claude Code cannot automatically determine the final working directory when 'cd' is used in compound commands.",decisionReason:{type:"other",reason:"Compound command contains cd with output redirection - manual approval required to prevent path resolution bypass"}};for(let{target:Y}of q){if(Y==="/dev/null")continue;let{allowed:$,resolvedPath:A,decisionReason:O}=JS1(Y,K,_,"create");if(!$){let w=Array.from(ku(_)),j=jS1(w),H=O?.type==="other"||O?.type==="safetyCheck"?O.reason:O?.type==="rule"?`Output redirection to '${A}' was blocked by a deny rule.`:`Output redirection to '${A}' was blocked. For security, Claude Code may only write to files in the allowed working directories for this session: ${j}.`;if(O?.type==="rule")return{behavior:"deny",message:H,decisionReason:O};return{behavior:"ask",message:H,blockedPath:A,decisionReason:O,suggestions:[{type:"addDirectories",directories:[IZ(A)],destination:"session"}]}}}return{behavior:"passthrough",message:"No unsafe redirections found"}}function RN8(q,K,_,z,Y,$){if(!$&&/>>\s*>\s*\(|>\s*>\s*\(|<\s*\(/.test(q.command))return{behavior:"ask",message:"Process substitution (>(...) or <(...)) can execute arbitrary commands and requires manual approval",decisionReason:{type:"other",reason:"Process substitution requires manual approval"}};let{redirections:A,hasDangerousRedirection:O}=Y?_zz(Y):SL(q.command);if(O)return{behavior:"ask",message:"Shell expansion syntax in paths requires manual approval",decisionReason:{type:"other",reason:"Shell expansion syntax in paths requires manual approval"}};let w=Kzz(A,K,_,z);if(w.behavior!=="passthrough")return w;if($)for(let j of $){let H=qzz(j,K,_,z);if(H.behavior==="ask"||H.behavior==="deny")return H}else{let j=F2(q.command);for(let H of j){let J=e_z(H,K,_,z);if(J.behavior==="ask"||J.behavior==="deny")return J}}return{behavior:"passthrough",message:"All path commands validated successfully"}}function _zz(q){let K=[];for(let _ of q)switch(_.op){case">":case">|":case"&>":K.push({target:_.target,operator:">"});break;case">>":case"&>>":K.push({target:_.target,operator:">>"});break;case">&":if(!/^\d+$/.test(_.target))K.push({target:_.target,operator:">"});break;case"<":case"<<":case"<&":case"<<<":break}return{redirections:K,hasDangerousRedirection:!1}}function zzz(q){let K=1;while(K<q.length){let _=q[K],z=q[K+1];if(_==="--foreground"||_==="--preserve-status"||_==="--verbose")K++;else if(/^--(?:kill-after|signal)=[A-Za-z0-9_.+-]+$/.test(_))K++;else if((_==="--kill-after"||_==="--signal")&&z&&Zy4.test(z))K+=2;else if(_==="--"){K++;break}else if(_.startsWith("--"))return-1;else if(_==="-v")K++;else if((_==="-k"||_==="-s")&&z&&Zy4.test(z))K+=2;else if(/^-[ks][A-Za-z0-9_.+-]+$/.test(_))K++;else if(_.startsWith("-"))return-1;else break}return K}function Yzz(q){let K=1;while(K<q.length){let _=q[K];if(/^-[ioe]$/.test(_)&&q[K+1])K+=2;else if(/^-[ioe]./.test(_))K++;else if(/^--(input|output|error)=/.test(_))K++;else if(_.startsWith("-"))return-1;else break}return K>1&&K<q.length?K:-1}function $zz(q){let K=1;while(K<q.length){let _=q[K];if(_.includes("=")&&!_.startsWith("-"))K++;else if(_==="-i"||_==="-0"||_==="-v")K++;else if(_==="-u"&&q[K+1])K+=2;else if(_.startsWith("-"))return-1;else break}return K<q.length?K:-1}function Azz(q){let K=q;for(;;)if(K[0]==="time"||K[0]==="nohup")K=K.slice(K[1]==="--"?2:1);else if(K[0]==="timeout"){let _=zzz(K);if(_<0||!K[_]||!/^\d+(?:\.\d+)?[smhd]?$/.test(K[_]))return K;K=K.slice(_+1)}else if(K[0]==="nice")if(K[1]==="-n"&&K[2]&&/^-?\d+$/.test(K[2]))K=K.slice(K[3]==="--"?4:3);else if(K[1]&&/^-\d+$/.test(K[1]))K=K.slice(K[2]==="--"?3:2);else K=K.slice(K[1]==="--"?2:1);else if(K[0]==="stdbuf"){let _=Yzz(K);if(_<0)return K;K=K.slice(_)}else if(K[0]==="env"){let _=$zz(K);if(_<0)return K;K=K.slice(_)}else return K}var Wo6,Gy4,o_z,Do6,a_z,Zy4;var om1=y(()=>{SG();NX();dz();Tz();LH();xn6();DN();LN8();Wo6={cd:(q)=>q.length===0?[l_z()]:[q.join(" ")],ls:(q)=>{let K=LA(q);return K.length>0?K:["."]},find:(q)=>{let K=[],_=new Set(["-newer","-anewer","-cnewer","-mnewer","-samefile","-path","-wholename","-ilname","-lname","-ipath","-iwholename"]),z=/^-newer[acmBt][acmtB]$/,Y=!1,$=!1;for(let A=0;A<q.length;A++){let O=q[A];if(!O)continue;if($){K.push(O);continue}if(O==="--"){$=!0;continue}if(O.startsWith("-")){if(["-H","-L","-P"].includes(O))continue;if(Y=!0,_.has(O)||z.test(O)){let w=q[A+1];if(w)K.push(w),A++}continue}if(!Y)K.push(O)}return K.length>0?K:["."]},mkdir:LA,touch:LA,rm:LA,rmdir:LA,mv:LA,cp:LA,cat:LA,head:LA,tail:LA,sort:LA,uniq:LA,wc:LA,cut:LA,paste:LA,column:LA,file:LA,stat:LA,diff:LA,awk:LA,strings:LA,hexdump:LA,od:LA,base64:LA,nl:LA,sha256sum:LA,sha1sum:LA,md5sum:LA,tr:(q)=>{let K=q.some((z)=>z==="-d"||z==="--delete"||z.startsWith("-")&&z.includes("d"));return LA(q).slice(K?1:2)},grep:(q)=>{let _=fy4(q,new Set(["-e","--regexp","-f","--file","--exclude","--include","--exclude-dir","--include-dir","-m","--max-count","-A","--after-context","-B","--before-context","-C","--context"]));if(_.length===0&&q.some((z)=>["-r","-R","--recursive"].includes(z)))return["."];return _},rg:(q)=>{return fy4(q,new Set(["-e","--regexp","-f","--file","-t","--type","-T","--type-not","-g","--glob","-m","--max-count","--max-depth","-r","--replace","-A","--after-context","-B","--before-context","-C","--context"]),["."])},sed:(q)=>{let K=[],_=!1,z=!1,Y=!1;for(let $=0;$<q.length;$++){if(_){_=!1;continue}let A=q[$];if(!A)continue;if(!Y&&A==="--"){Y=!0;continue}if(!Y&&A.startsWith("-")){if(["-f","--file"].includes(A)){let O=q[$+1];if(O)K.push(O),_=!0;z=!0}else if(["-e","--expression"].includes(A))_=!0,z=!0;else if(A.includes("e")||A.includes("f"))z=!0;continue}if(!z){z=!0;continue}K.push(A)}return K},jq:(q)=>{let K=[],_=new Set(["-e","--expression","-f","--from-file","--arg","--argjson","--slurpfile","--rawfile","--args","--jsonargs","-L","--library-path","--indent","--tab"]),z=!1,Y=!1;for(let $=0;$<q.length;$++){let A=q[$];if(A===void 0||A===null)continue;if(!Y&&A==="--"){Y=!0;continue}if(!Y&&A.startsWith("-")){let O=A.split("=")[0];if(O&&["-e","--expression"].includes(O))z=!0;if(O&&_.has(O)&&!A.includes("="))$++;continue}if(!z){z=!0;continue}K.push(A)}return K},git:(q)=>{if(q.length>=1&&q[0]==="diff"){if(q.includes("--no-index"))return LA(q.slice(1)).slice(0,2)}return[]}},Gy4=Object.keys(Wo6),o_z={cd:"change directories to",ls:"list files in",find:"search files in",mkdir:"create directories in",touch:"create or modify files in",rm:"remove files from",rmdir:"remove directories from",mv:"move files to/from",cp:"copy files to/from",cat:"concatenate files from",head:"read the beginning of files from",tail:"read the end of files from",sort:"sort contents of files from",uniq:"filter duplicate lines from files in",wc:"count lines/words/bytes in files from",cut:"extract columns from files in",paste:"merge files from",column:"format files from",tr:"transform text from files in",file:"examine file types in",stat:"read file stats from",diff:"compare files from",awk:"process text from files in",strings:"extract strings from files in",hexdump:"display hex dump of files from",od:"display octal dump of files from",base64:"encode/decode files from",nl:"number lines in files from",grep:"search for patterns in files from",rg:"search for patterns in files from",sed:"edit files in",git:"access files with git from",jq:"process JSON from files in",sha256sum:"compute SHA-256 checksums for files in",sha1sum:"compute SHA-1 checksums for files in",md5sum:"compute MD5 checksums for files in"},Do6={cd:"read",ls:"read",find:"read",mkdir:"create",touch:"create",rm:"write",rmdir:"write",mv:"write",cp:"write",cat:"read",head:"read",tail:"read",sort:"read",uniq:"read",wc:"read",cut:"read",paste:"read",column:"read",tr:"read",file:"read",stat:"read",diff:"read",awk:"read",strings:"read",hexdump:"read",od:"read",base64:"read",nl:"read",grep:"read",rg:"read",sed:"write",git:"read",jq:"read",sha256sum:"read",sha1sum:"read",md5sum:"read"},a_z={mv:(q)=>!q.some((K)=>K?.startsWith("-")),cp:(q)=>!q.some((K)=>K?.startsWith("-"))};Zy4=/^[A-Za-z0-9_.+-]+$/});function wzz(){let q=Ozz;if(Z1()==="windows"){let{xargs:K,..._}=q;q=_}return q}function Hzz(q){let K=o$(q,(w)=>`$${w}`);if(!K.success)return!1;let _=K.tokens.map((w)=>{if(typeof w!=="string"){if(w=w,w.op==="glob")return w.pattern}return w});if(_.some((w)=>typeof w!=="string"))return!1;let Y=_;if(Y.length===0)return!1;let $,A=0,O=wzz();for(let[w]of Object.entries(O)){let j=w.split(" ");if(Y.length>=j.length){let H=!0;for(let J=0;J<j.length;J++)if(Y[J]!==j[J]){H=!1;break}if(H){$=O[w],A=j.length;break}}}if(!$)return!1;if(Y[0]==="git"&&Y[1]==="ls-remote")for(let w=2;w<Y.length;w++){let j=Y[w];if(j&&!j.startsWith("-")){if(j.includes("://"))return!1;if(j.includes("@")||j.includes(":"))return!1;if(j.includes("$"))return!1}}for(let w=A;w<Y.length;w++){let j=Y[w];if(!j)continue;if(j.includes("$"))return!1;if(j.includes("{")&&(j.includes(",")||j.includes("..")))return!1}if(!kv6(Y,A,$,{commandName:Y[0],rawCommand:q,xargsTargetCommands:Y[0]==="xargs"?jzz:void 0}))return!1;if($.regex&&!$.regex.test(q))return!1;if(!$.regex&&/`/.test(q))return!1;if(!$.regex&&(Y[0]==="rg"||Y[0]==="grep")&&/[\n\r]/.test(q))return!1;if($.additionalCommandIsDangerousCallback&&$.additionalCommandIsDangerousCallback(q,Y.slice(A)))return!1;return!0}function Jzz(q){return new RegExp(`^${q}(?:\\s|$)[^<>()$\`|{}&;\\n\\r]*$`)}function Pzz(q){let K=!1,_=!1,z=!1;for(let Y=0;Y<q.length;Y++){let $=q[Y];if(z){z=!1;continue}if($==="\\"&&!K){z=!0;continue}if($==="'"&&!_){K=!K;continue}if($==='"'&&!K){_=!_;continue}if(K)continue;if($==="$"){let A=q[Y+1];if(A&&/[A-Za-z_@*#?!$0-9-]/.test(A))return!0}if(_)continue;if($&&/[?*[\]]/.test($))return!0}return!1}function Wzz(q){let K=q.trim();if(K.endsWith(" 2>&1"))K=K.slice(0,-5).trim();if(SF(K))return!1;if(Pzz(K))return!1;if(Hzz(K))return!0;for(let _ of Xzz)if(_.test(K)){if(K.includes("git")&&/\s-c[\s=]/.test(K))return!1;if(K.includes("git")&&/\s--exec-path[\s=]/.test(K))return!1;if(K.includes("git")&&/\s--config-env[\s=]/.test(K))return!1;return!0}return!1}function Dzz(q){return F2(q).some((K)=>SN8(K.trim()))}function ky4(q){let K=q.replace(/^\.?\//,"");return fzz.some((_)=>_.test(K))}function Gzz(q){let K=o$(q,(A)=>`$${A}`);if(!K.success)return[];let _=K.tokens.filter((A)=>typeof A==="string");if(_.length===0)return[];let z=_[0];if(!z)return[];if(!(z in Do6))return[];let Y=Do6[z];if(Y!=="write"&&Y!=="create"||Zzz.has(z))return[];let $=Wo6[z];if(!$)return[];return $(_.slice(1))}function Tzz(q){let K=F2(q);for(let _ of K){let z=_.trim(),Y=Gzz(z);for(let A of Y)if(ky4(A))return!0;let{redirections:$}=SL(z);for(let{target:A}of $)if(ky4(A))return!0}return!1}function hN8(q,K){let{command:_}=q;if(!o$(_,(A)=>`$${A}`).success)return{behavior:"passthrough",message:"Command cannot be parsed, requires further permission checks"};if(Po6(_).behavior!=="passthrough")return{behavior:"passthrough",message:"Command is not read-only, requires further permission checks"};if(SF(_))return{behavior:"ask",message:"Command contains Windows UNC path that could be vulnerable to WebDAV attacks"};let Y=Dzz(_);if(K&&Y)return{behavior:"passthrough",message:"Compound commands with cd and git require permission checks for enhanced security"};if(Y&&Op6())return{behavior:"passthrough",message:"Git commands in directories with bare repository structure require permission checks for enhanced security"};if(Y&&Tzz(_))return{behavior:"passthrough",message:"Compound commands that create git internal files and run git require permission checks for enhanced security"};if(Y&&M7.isSandboxingEnabled()&&Z8()!==r1())return{behavior:"passthrough",message:"Git commands outside the original working directory require permission checks when sandbox is enabled"};if(F2(_).every((A)=>{if(Po6(A).behavior!=="passthrough")return!1;return Wzz(A)}))return{behavior:"allow",updatedInput:q};return{behavior:"passthrough",message:"Command is not read-only, requires further permission checks"}}var vy4,Ozz,U3O,jzz,Mzz,Xzz,fzz,Zzz;var am1=y(()=>{v8();SG();NX();I7();E5();vK();K$();Vv6();DN();EN8();om1();LN8();vy4={"-h":"none","--help":"none","-V":"none","--version":"none","-H":"none","--hidden":"none","-I":"none","--no-ignore":"none","--no-ignore-vcs":"none","--no-ignore-parent":"none","-s":"none","--case-sensitive":"none","-i":"none","--ignore-case":"none","-g":"none","--glob":"none","--regex":"none","-F":"none","--fixed-strings":"none","-a":"none","--absolute-path":"none","-L":"none","--follow":"none","-p":"none","--full-path":"none","-0":"none","--print0":"none","-d":"number","--max-depth":"number","--min-depth":"number","--exact-depth":"number","-t":"string","--type":"string","-e":"string","--extension":"string","-S":"string","--size":"string","--changed-within":"string","--changed-before":"string","-o":"string","--owner":"string","-E":"string","--exclude":"string","--ignore-file":"string","-c":"string","--color":"string","-j":"number","--threads":"number","--max-buffer-time":"string","--max-results":"number","-1":"none","-q":"none","--quiet":"none","--show-errors":"none","--strip-cwd-prefix":"none","--one-file-system":"none","--prune":"none","--search-path":"string","--base-directory":"string","--path-separator":"string","--batch-size":"number","--no-require-git":"none","--hyperlink":"string","--and":"string","--format":"string"},Ozz={xargs:{safeFlags:{"-I":"{}","-n":"number","-P":"number","-L":"number","-s":"number","-E":"EOF","-0":"none","-t":"none","-r":"none","-x":"none","-d":"char"}},...Cn6,file:{safeFlags:{"--brief":"none","-b":"none","--mime":"none","-i":"none","--mime-type":"none","--mime-encoding":"none","--apple":"none","--check-encoding":"none","-c":"none","--exclude":"string","--exclude-quiet":"string","--print0":"none","-0":"none","-f":"string","-F":"string","--separator":"string","--help":"none","--version":"none","-v":"none","--no-dereference":"none","-h":"none","--dereference":"none","-L":"none","--magic-file":"string","-m":"string","--keep-going":"none","-k":"none","--list":"none","-l":"none","--no-buffer":"none","-n":"none","--preserve-date":"none","-p":"none","--raw":"none","-r":"none","-s":"none","--special-files":"none","--uncompress":"none","-z":"none"}},sed:{safeFlags:{"--expression":"string","-e":"string","--quiet":"none","--silent":"none","-n":"none","--regexp-extended":"none","-r":"none","--posix":"none","-E":"none","--line-length":"number","-l":"number","--zero-terminated":"none","-z":"none","--separate":"none","-s":"none","--unbuffered":"none","-u":"none","--debug":"none","--help":"none","--version":"none"},additionalCommandIsDangerousCallback:(q,K)=>!RV6(q)},sort:{safeFlags:{"--ignore-leading-blanks":"none","-b":"none","--dictionary-order":"none","-d":"none","--ignore-case":"none","-f":"none","--general-numeric-sort":"none","-g":"none","--human-numeric-sort":"none","-h":"none","--ignore-nonprinting":"none","-i":"none","--month-sort":"none","-M":"none","--numeric-sort":"none","-n":"none","--random-sort":"none","-R":"none","--reverse":"none","-r":"none","--sort":"string","--stable":"none","-s":"none","--unique":"none","-u":"none","--version-sort":"none","-V":"none","--zero-terminated":"none","-z":"none","--key":"string","-k":"string","--field-separator":"string","-t":"string","--check":"none","-c":"none","--check-char-order":"none","-C":"none","--merge":"none","-m":"none","--buffer-size":"string","-S":"string","--parallel":"number","--batch-size":"number","--help":"none","--version":"none"}},man:{safeFlags:{"-a":"none","--all":"none","-d":"none","-f":"none","--whatis":"none","-h":"none","-k":"none","--apropos":"none","-l":"string","-w":"none","-S":"string","-s":"string"}},help:{safeFlags:{"-d":"none","-m":"none","-s":"none"}},netstat:{safeFlags:{"-a":"none","-L":"none","-l":"none","-n":"none","-f":"string","-g":"none","-i":"none","-I":"string","-s":"none","-r":"none","-m":"none","-v":"none"}},ps:{safeFlags:{"-e":"none","-A":"none","-a":"none","-d":"none","-N":"none","--deselect":"none","-f":"none","-F":"none","-l":"none","-j":"none","-y":"none","-w":"none","-ww":"none","--width":"number","-c":"none","-H":"none","--forest":"none","--headers":"none","--no-headers":"none","-n":"string","--sort":"string","-L":"none","-T":"none","-m":"none","-C":"string","-G":"string","-g":"string","-p":"string","--pid":"string","-q":"string","--quick-pid":"string","-s":"string","--sid":"string","-t":"string","--tty":"string","-U":"string","-u":"string","--user":"string","--help":"none","--info":"none","-V":"none","--version":"none"},additionalCommandIsDangerousCallback:(q,K)=>{return K.some((_)=>!_.startsWith("-")&&/^[a-zA-Z]*e[a-zA-Z]*$/.test(_))}},base64:{respectsDoubleDash:!1,safeFlags:{"-d":"none","-D":"none","--decode":"none","-b":"number","--break":"number","-w":"number","--wrap":"number","-i":"string","--input":"string","--ignore-garbage":"none","-h":"none","--help":"none","--version":"none"}},grep:{safeFlags:{"-e":"string","--regexp":"string","-f":"string","--file":"string","-F":"none","--fixed-strings":"none","-G":"none","--basic-regexp":"none","-E":"none","--extended-regexp":"none","-P":"none","--perl-regexp":"none","-i":"none","--ignore-case":"none","--no-ignore-case":"none","-v":"none","--invert-match":"none","-w":"none","--word-regexp":"none","-x":"none","--line-regexp":"none","-c":"none","--count":"none","--color":"string","--colour":"string","-L":"none","--files-without-match":"none","-l":"none","--files-with-matches":"none","-m":"number","--max-count":"number","-o":"none","--only-matching":"none","-q":"none","--quiet":"none","--silent":"none","-s":"none","--no-messages":"none","-b":"none","--byte-offset":"none","-H":"none","--with-filename":"none","-h":"none","--no-filename":"none","--label":"string","-n":"none","--line-number":"none","-T":"none","--initial-tab":"none","-u":"none","--unix-byte-offsets":"none","-Z":"none","--null":"none","-z":"none","--null-data":"none","-A":"number","--after-context":"number","-B":"number","--before-context":"number","-C":"number","--context":"number","--group-separator":"string","--no-group-separator":"none","-a":"none","--text":"none","--binary-files":"string","-D":"string","--devices":"string","-d":"string","--directories":"string","--exclude":"string","--exclude-from":"string","--exclude-dir":"string","--include":"string","-r":"none","--recursive":"none","-R":"none","--dereference-recursive":"none","--line-buffered":"none","-U":"none","--binary":"none","--help":"none","-V":"none","--version":"none"}},...Q54,sha256sum:{safeFlags:{"-b":"none","--binary":"none","-t":"none","--text":"none","-c":"none","--check":"none","--ignore-missing":"none","--quiet":"none","--status":"none","--strict":"none","-w":"none","--warn":"none","--tag":"none","-z":"none","--zero":"none","--help":"none","--version":"none"}},sha1sum:{safeFlags:{"-b":"none","--binary":"none","-t":"none","--text":"none","-c":"none","--check":"none","--ignore-missing":"none","--quiet":"none","--status":"none","--strict":"none","-w":"none","--warn":"none","--tag":"none","-z":"none","--zero":"none","--help":"none","--version":"none"}},md5sum:{safeFlags:{"-b":"none","--binary":"none","-t":"none","--text":"none","-c":"none","--check":"none","--ignore-missing":"none","--quiet":"none","--status":"none","--strict":"none","-w":"none","--warn":"none","--tag":"none","-z":"none","--zero":"none","--help":"none","--version":"none"}},tree:{safeFlags:{"-a":"none","-d":"none","-l":"none","-f":"none","-x":"none","-L":"number","-P":"string","-I":"string","--gitignore":"none","--gitfile":"string","--ignore-case":"none","--matchdirs":"none","--metafirst":"none","--prune":"none","--info":"none","--infofile":"string","--noreport":"none","--charset":"string","--filelimit":"number","-q":"none","-N":"none","-Q":"none","-p":"none","-u":"none","-g":"none","-s":"none","-h":"none","--si":"none","--du":"none","-D":"none","--timefmt":"string","-F":"none","--inodes":"none","--device":"none","-v":"none","-t":"none","-c":"none","-U":"none","-r":"none","--dirsfirst":"none","--filesfirst":"none","--sort":"string","-i":"none","-A":"none","-S":"none","-n":"none","-C":"none","-X":"none","-J":"none","-H":"string","--nolinks":"none","--hintro":"string","--houtro":"string","-T":"string","--hyperlink":"none","--scheme":"string","--authority":"string","--fromfile":"none","--fromtabfile":"none","--fflinks":"none","--help":"none","--version":"none"}},date:{safeFlags:{"-d":"string","--date":"string","-r":"string","--reference":"string","-u":"none","--utc":"none","--universal":"none","-I":"none","--iso-8601":"string","-R":"none","--rfc-email":"none","--rfc-3339":"string","--debug":"none","--help":"none","--version":"none"},additionalCommandIsDangerousCallback:(q,K)=>{let _=new Set(["-d","--date","-r","--reference","--iso-8601","--rfc-3339"]),z=0;while(z<K.length){let Y=K[z];if(Y.startsWith("--")&&Y.includes("="))z++;else if(Y.startsWith("-"))if(_.has(Y))z+=2;else z++;else{if(!Y.startsWith("+"))return!0;z++}}return!1}},hostname:{safeFlags:{"-f":"none","--fqdn":"none","--long":"none","-s":"none","--short":"none","-i":"none","--ip-address":"none","-I":"none","--all-ip-addresses":"none","-a":"none","--alias":"none","-d":"none","--domain":"none","-A":"none","--all-fqdns":"none","-v":"none","--verbose":"none","-h":"none","--help":"none","-V":"none","--version":"none"},regex:/^hostname(?:\s+(?:-[a-zA-Z]|--[a-zA-Z-]+))*\s*$/},info:{safeFlags:{"-f":"string","--file":"string","-d":"string","--directory":"string","-n":"string","--node":"string","-a":"none","--all":"none","-k":"string","--apropos":"string","-w":"none","--where":"none","--location":"none","--show-options":"none","--vi-keys":"none","--subnodes":"none","-h":"none","--help":"none","--usage":"none","--version":"none"}},lsof:{safeFlags:{"-?":"none","-h":"none","-v":"none","-a":"none","-b":"none","-C":"none","-l":"none","-n":"none","-N":"none","-O":"none","-P":"none","-Q":"none","-R":"none","-t":"none","-U":"none","-V":"none","-X":"none","-H":"none","-E":"none","-F":"none","-g":"none","-i":"none","-K":"none","-L":"none","-o":"none","-r":"none","-s":"none","-S":"none","-T":"none","-x":"none","-A":"string","-c":"string","-d":"string","-e":"string","-k":"string","-p":"string","-u":"string"},additionalCommandIsDangerousCallback:(q,K)=>K.some((_)=>_==="+m"||_.startsWith("+m"))},pgrep:{safeFlags:{"-d":"string","--delimiter":"string","-l":"none","--list-name":"none","-a":"none","--list-full":"none","-v":"none","--inverse":"none","-w":"none","--lightweight":"none","-c":"none","--count":"none","-f":"none","--full":"none","-g":"string","--pgroup":"string","-G":"string","--group":"string","-i":"none","--ignore-case":"none","-n":"none","--newest":"none","-o":"none","--oldest":"none","-O":"string","--older":"string","-P":"string","--parent":"string","-s":"string","--session":"string","-t":"string","--terminal":"string","-u":"string","--euid":"string","-U":"string","--uid":"string","-x":"none","--exact":"none","-F":"string","--pidfile":"string","-L":"none","--logpidfile":"none","-r":"string","--runstates":"string","--ns":"string","--nslist":"string","--help":"none","-V":"none","--version":"none"}},tput:{safeFlags:{"-T":"string","-V":"none","-x":"none"},additionalCommandIsDangerousCallback:(q,K)=>{let _=new Set(["init","reset","rs1","rs2","rs3","is1","is2","is3","iprog","if","rf","clear","flash","mc0","mc4","mc5","mc5i","mc5p","pfkey","pfloc","pfx","pfxl","smcup","rmcup"]),z=new Set(["-T"]),Y=0,$=!1;while(Y<K.length){let A=K[Y];if(A==="--")$=!0,Y++;else if(!$&&A.startsWith("-")){if(A==="-S")return!0;if(!A.startsWith("--")&&A.length>2&&A.includes("S"))return!0;if(z.has(A))Y+=2;else Y++}else{if(_.has(A))return!0;Y++}}return!1}},ss:{safeFlags:{"-h":"none","--help":"none","-V":"none","--version":"none","-n":"none","--numeric":"none","-r":"none","--resolve":"none","-a":"none","--all":"none","-l":"none","--listening":"none","-o":"none","--options":"none","-e":"none","--extended":"none","-m":"none","--memory":"none","-p":"none","--processes":"none","-i":"none","--info":"none","-s":"none","--summary":"none","-4":"none","--ipv4":"none","-6":"none","--ipv6":"none","-0":"none","--packet":"none","-t":"none","--tcp":"none","-M":"none","--mptcp":"none","-S":"none","--sctp":"none","-u":"none","--udp":"none","-d":"none","--dccp":"none","-w":"none","--raw":"none","-x":"none","--unix":"none","--tipc":"none","--vsock":"none","-f":"string","--family":"string","-A":"string","--query":"string","--socket":"string","-Z":"none","--context":"none","-z":"none","--contexts":"none","-b":"none","--bpf":"none","-E":"none","--events":"none","-H":"none","--no-header":"none","-O":"none","--oneline":"none","--tipcinfo":"none","--tos":"none","--cgroup":"none","--inet-sockopt":"none"}},fd:{safeFlags:{...vy4}},fdfind:{safeFlags:{...vy4}},...d54,...XT8},U3O={...bn6,aki:{safeFlags:{"-h":"none","--help":"none","-k":"none","--keyword":"none","-s":"none","--semantic":"none","--no-adaptive":"none","-n":"number","--limit":"number","-o":"number","--offset":"number","--source":"string","--exclude-source":"string","-a":"string","--after":"string","-b":"string","--before":"string","--collection":"string","--drive":"string","--folder":"string","--descendants":"none","-m":"string","--meta":"string","-t":"string","--threshold":"string","--kw-weight":"string","--sem-weight":"string","-j":"none","--json":"none","-c":"none","--chunk":"none","--preview":"none","-d":"none","--full-doc":"none","-v":"none","--verbose":"none","--stats":"none","-S":"number","--summarize":"number","--explain":"none","--examine":"string","--url":"string","--multi-turn":"number","--multi-turn-model":"string","--multi-turn-context":"string","--no-rerank":"none","--audit":"none","--local":"none","--staging":"none"}}};jzz=["echo","printf","wc","grep","head","tail"];Mzz=[...PT8,"cal","uptime","cat","head","tail","wc","stat","strings","hexdump","od","nl","id","uname","free","df","du","locale","groups","nproc","basename","dirname","realpath","cut","paste","tr","column","tac","rev","fold","expand","unexpand","fmt","comm","cmp","numfmt","readlink","diff","true","false","sleep","which","type","expr","test","getconf","seq","tsort","pr"],Xzz=new Set([...Mzz.map(Jzz),/^echo(?:\s+(?:'[^']*'|"[^"$<>\n\r]*"|[^|;&`$(){}><#\\!"'\s]+))*(?:\s+2>&1)?\s*$/,/^claude -h$/,/^claude --help$/,/^uniq(?:\s+(?:-[a-zA-Z]+|--[a-zA-Z-]+(?:=\S+)?|-[fsw]\s+\d+))*(?:\s|$)\s*$/,/^pwd$/,/^whoami$/,/^node -v$/,/^node --version$/,/^python --version$/,/^python3 --version$/,/^history(?:\s+\d+)?\s*$/,/^alias$/,/^arch(?:\s+(?:--help|-h))?\s*$/,/^ip addr$/,/^ifconfig(?:\s+[a-zA-Z][a-zA-Z0-9_-]*)?\s*$/,/^jq(?!\s+.*(?:-f\b|--from-file|--rawfile|--slurpfile|--run-tests|-L\b|--library-path|\benv\b|\$ENV\b))(?:\s+(?:-[a-zA-Z]+|--[a-zA-Z-]+(?:=\S+)?))*(?:\s+'[^'`]*'|\s+"[^"`]*"|\s+[^-\s'"][^\s]*)+\s*$/,/^cd(?:\s+(?:'[^']*'|"[^"]*"|[^\s;|&`$(){}><#\\]+))?$/,/^ls(?:\s+[^<>()$`|{}&;\n\r]*)?$/,/^find(?:\s+(?:\\[()]|(?!-delete\b|-exec\b|-execdir\b|-ok\b|-okdir\b|-fprint0?\b|-fls\b|-fprintf\b)[^<>()$`|{}&;\n\r\s]|\s)+)?$/]);fzz=[/^HEAD$/,/^objects(?:\/|$)/,/^refs(?:\/|$)/,/^hooks(?:\/|$)/];Zzz=new Set(["rm","rmdir","sed"])});async function Vy4(q){let K;do K=await q.next();while(!K.done);return K.value}async function*CN8(q,K=1/0){let _=($)=>{let A=$.next().then(({done:O,value:w})=>({done:O,value:w,generator:$,promise:A}));return A},z=[...q],Y=new Set;while(Y.size<K&&z.length>0){let $=z.shift();Y.add(_($))}while(Y.size>0){let{done:$,value:A,generator:O,promise:w}=await Promise.race(Y);if(Y.delete(w),!$){if(Y.add(_(O)),A!==void 0)yield A}else if(z.length>0){let j=z.shift();Y.add(_(j))}}}async function bN8(q){let K=[];for await(let _ of q)K.push(_);return K}async function*sm1(q){for(let K of q)yield K}var d3O;var ww6=y(()=>{d3O=Symbol("NO_VALUE")});function vzz(){return parseInt(process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY||"",10)||10}async function*xN8(q,K,_,z){let Y=z;for(let{isConcurrencySafe:$,blocks:A}of kzz(q,Y))if($){let O={};for await(let w of Nzz(A,K,_,Y)){if(w.contextModifier){let{toolUseID:j,modifyContext:H}=w.contextModifier;if(!O[j])O[j]=[];O[j].push(H)}yield{message:w.message,newContext:Y}}for(let w of A){let j=O[w.id];if(!j)continue;for(let H of j)Y=H(Y)}yield{newContext:Y}}else for await(let O of Vzz(A,K,_,Y)){if(O.newContext)Y=O.newContext;yield{message:O.message,newContext:Y}}}function kzz(q,K){return q.reduce((_,z)=>{let Y=L5(K.options.tools,z.name),$=Y?.inputSchema.safeParse(z.input),A=$?.success?(()=>{try{return Boolean(Y?.isConcurrencySafe($.data))}catch{return!1}})():!1;if(A&&_[_.length-1]?.isConcurrencySafe)_[_.length-1].blocks.push(z);else _.push({isConcurrencySafe:A,blocks:[z]});return _},[])}async function*Vzz(q,K,_,z){let Y=z;for(let $ of q){z.setInProgressToolUseIDs((A)=>new Set(A).add($.id));for await(let A of fo6($,K.find((O)=>O.message.content.some((w)=>w.type==="tool_use"&&w.id===$.id)),_,Y)){if(A.contextModifier)Y=A.contextModifier.modifyContext(Y);yield{message:A.message,newContext:Y}}Ny4(z,$.id)}}async function*Nzz(q,K,_,z){yield*CN8(q.map(async function*(Y){z.setInProgressToolUseIDs(($)=>new Set($).add(Y.id)),yield*fo6(Y,K.find(($)=>$.message.content.some((A)=>A.type==="tool_use"&&A.id===Y.id)),_,z),Ny4(z,Y.id)}),vzz())}function Ny4(q,K){q.setInProgressToolUseIDs((_)=>{let z=new Set(_);return z.delete(K),z})}var tm1=y(()=>{Bq();ww6();em1()});function yy4(q,K=null){if(!q)return!1;if(q.type==="assistant"){let _=tS(q.message.content);return _?.type==="text"||_?.type==="thinking"||_?.type==="redacted_thinking"}if(q.type==="user"){let _=q.message.content;if(Array.isArray(_)&&_.length>0&&_.every((z)=>("type"in z)&&z.type==="tool_result"))return!0}return K==="end_turn"}function*IN8(q){switch(q.type){case"assistant":for(let K of yX([q])){if(!Go6(K))continue;yield{type:"assistant",message:K.message,parent_tool_use_id:null,session_id:N8(),uuid:K.uuid,error:K.error}}return;case"progress":if(q.data.type==="agent_progress"||q.data.type==="skill_progress")for(let K of yX([q.data.message]))switch(K.type){case"assistant":if(!Go6(K))break;yield{type:"assistant",message:K.message,parent_tool_use_id:q.parentToolUseID,session_id:N8(),uuid:K.uuid,error:K.error};break;case"user":yield{type:"user",message:K.message,parent_tool_use_id:q.parentToolUseID,session_id:N8(),uuid:K.uuid,timestamp:K.timestamp,isSynthetic:K.isMeta||K.isVisibleInTranscriptOnly,tool_use_result:K.mcpMeta?{content:K.toolUseResult,...K.mcpMeta}:K.toolUseResult};break}else if(q.data.type==="bash_progress"||q.data.type==="powershell_progress"){if(!i6(process.env.CLAUDE_CODE_REMOTE)&&!process.env.CLAUDE_CODE_CONTAINER_ID)break;let K=q.parentToolUseID,_=Date.now(),z=Zo6.get(K)||0;if(_-z>=Lzz){if(Zo6.size>=Ezz){let $=Zo6.keys().next().value;if($!==void 0)Zo6.delete($)}Zo6.set(K,_),yield{type:"tool_progress",tool_use_id:q.toolUseID,tool_name:q.data.type==="bash_progress"?"Bash":"PowerShell",parent_tool_use_id:q.parentToolUseID,elapsed_time_seconds:q.data.elapsedTimeSeconds,task_id:q.data.taskId,session_id:N8(),uuid:q.uuid}}}break;case"user":for(let K of yX([q]))yield{type:"user",message:K.message,parent_tool_use_id:null,session_id:N8(),uuid:K.uuid,timestamp:K.timestamp,isSynthetic:K.isMeta||K.isVisibleInTranscriptOnly,tool_use_result:K.mcpMeta?{content:K.toolUseResult,...K.mcpMeta}:K.toolUseResult};return;default:}}async function*Ey4(q,K,_,z){let Y=!ey(),{permissionResult:$,assistantMessage:A}=q,{toolUseID:O}=$;if(!O)return;let w=A.message.content,j;if(Array.isArray(w)){for(let G of w)if(G.type==="tool_use"&&G.id===O){j=G;break}}if(!j)return;let{name:H,input:J}=j;if(!L5(K,H))return;let X=J;if($.behavior==="allow")if($.updatedInput!==void 0)X=$.updatedInput;else N(`Orphaned permission for ${H}: updatedInput is undefined, falling back to original tool input`,{level:"warn"});let P={...j,input:X},W=async()=>({...$,decisionReason:{type:"mode",mode:"default"}});if(!_.some((G)=>G.type==="assistant"&&Array.isArray(G.message.content)&&G.message.content.some((Z)=>Z.type==="tool_use"&&("id"in Z)&&Z.id===O))){if(_.push(A),Y)await fN(_)}yield{...A,session_id:N8(),parent_tool_use_id:null};for await(let G of xN8([P],[A],W,z))if(G.message){if(_.push(G.message),Y)await fN(_);yield{...G.message,session_id:N8(),parent_tool_use_id:null}}}function hV6(q,K,_=yzz){let z=Bu(_),Y=new Map,$=new Map,A=new Map;for(let O of q)if(O.type==="assistant"&&Array.isArray(O.message.content)){for(let w of O.message.content)if(w.type==="tool_use"&&w.name===Cq){let j=w.input;if(j?.file_path&&j?.offset===void 0&&j?.limit===void 0){let H=lq(j.file_path,K);Y.set(w.id,H)}}else if(w.type==="tool_use"&&w.name===tK){let j=w.input;if(j?.file_path&&j?.content){let H=lq(j.file_path,K);$.set(w.id,{filePath:H,content:j.content})}}else if(w.type==="tool_use"&&w.name===X4){let j=w.input;if(j?.file_path){let H=lq(j.file_path,K);A.set(w.id,H)}}}for(let O of q)if(O.type==="user"&&Array.isArray(O.message.content)){for(let w of O.message.content)if(w.type==="tool_result"&&w.tool_use_id){let j=Y.get(w.tool_use_id);if(j&&typeof w.content==="string"&&!w.content.startsWith(_T6)){let X=w.content.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g,"").split(`
1681`).map(vR7).join(`
1682`).trim();if(O.timestamp){let P=new Date(O.timestamp).getTime();z.set(j,{content:X,timestamp:P,offset:void 0,limit:void 0})}}let H=$.get(w.tool_use_id);if(H&&O.timestamp){let M=new Date(O.timestamp).getTime();z.set(H.filePath,{content:H.content,timestamp:M,offset:void 0,limit:void 0})}let J=A.get(w.tool_use_id);if(J&&w.is_error!==!0)try{let{content:M}=vB(J);z.set(J,{content:M,timestamp:ik(J),offset:void 0,limit:void 0})}catch(M){if(!e3(M))throw M}}}return z}function qp1(q){let K=new Set;for(let _ of q)if(_.type==="assistant"&&Array.isArray(_.message.content)){for(let z of _.message.content)if(z.type==="tool_use"&&z.name===_q){let{input:Y}=z;if(typeof Y!=="object"||Y===null||!("command"in Y))continue;let $=hzz(typeof Y.command==="string"?Y.command:void 0);if($)K.add($)}}return K}function hzz(q){if(!q)return;let K=q.trim().split(/\s+/);for(let _ of K){if(/^[A-Za-z_]\w*=/.test(_))continue;if(Rzz.has(_))continue;return _}return}var yzz=10,Ezz=100,Lzz=30000,Zo6,Rzz;var To6=y(()=>{cl6();v8();tm1();Bq();IY();E2();_8();m8();y8();bK();ZE();NG();i1();dz();_K();Zo6=new Map;Rzz=new Set(["sudo"])});import{randomUUID as Szz}from"crypto";import{rm as Czz}from"fs";import{appendFile as bzz,copyFile as Ly4,mkdir as Kp1}from"fs/promises";import{dirname as Ry4,isAbsolute as xzz,join as jw6,relative as Izz}from"path";function vo6(q){Czz(q,{recursive:!0,force:!0,maxRetries:3,retryDelay:100},()=>{})}function mN8(q){return jw6(AC(),"speculation",String(process.pid),q)}function uN8(q,K){return{behavior:"deny",message:q,decisionReason:{type:"other",reason:K}}}async function gzz(q,K,_){let z=!0;for(let Y of K){let $=jw6(q,Y),A=jw6(_,Y);try{await Kp1(Ry4(A),{recursive:!0}),await Ly4($,A)}catch{z=!1,N(`[Speculation] Failed to copy ${Y} to main`)}}return z}function pN8(q,K,_,z,Y,$,A){d("tengu_speculation",{speculation_id:q,outcome:K,duration_ms:Date.now()-_,suggestion_length:z,tools_executed:zp1(Y),completed:$!==null,boundary_type:$?.type,boundary_tool:Fzz($),boundary_detail:Uzz($),...A})}function zp1(q){let K=q.filter(Yp1).flatMap((_)=>_.message.content).filter((_)=>typeof _==="object"&&_!==null&&("type"in _));return $7(K,(_)=>_.type==="tool_result"&&!_.is_error)}function Fzz(q){if(!q)return;switch(q.type){case"bash":return"Bash";case"edit":case"denied_tool":return q.toolName;case"complete":return}}function Uzz(q){if(!q)return;switch(q.type){case"bash":return q.command.slice(0,200);case"edit":return q.filePath;case"denied_tool":return q.detail;case"complete":return}}function Yp1(q){return q.type==="user"&&"message"in q&&Array.isArray(q.message.content)}function Qzz(q){let K=($)=>typeof $==="object"&&$!==null&&$.type==="tool_result"&&typeof $.tool_use_id==="string",_=($)=>!$.is_error&&!(typeof $.content==="string"&&$.content.includes(j0)),z=new Set(q.filter(Yp1).flatMap(($)=>$.message.content).filter(K).filter(_).map(($)=>$.tool_use_id)),Y=($)=>$.type!=="thinking"&&$.type!=="redacted_thinking"&&!($.type==="tool_use"&&!z.has($.id))&&!($.type==="tool_result"&&!z.has($.tool_use_id))&&!($.type==="text"&&($.text===fq6||$.text===j0));return q.map(($)=>{if(!("message"in $)||!Array.isArray($.message.content))return $;let A=$.message.content.filter(Y);if(A.length===$.message.content.length)return $;if(A.length===0)return null;if(!A.some((w)=>w.type!=="text"||w.text!==void 0&&w.text.trim()!==""))return null;return{...$,message:{...$.message,content:A}}}).filter(($)=>$!==null)}function dzz(q,K,_,z){return null}function SV6(q,K){q((_)=>{if(_.speculation.status!=="active")return _;let z=_.speculation,Y=K(z);if(!Object.entries(Y).some(([A,O])=>z[A]!==O))return _;return{..._,speculation:{...z,...Y}}})}function _p1(q){q((K)=>{if(K.speculation.status==="idle")return K;return{...K,speculation:Wq6}})}function Fm1(){return N("[Speculation] enabled=false"),!1}async function czz(q,K,_,z,Y){try{let $=q.toolUseContext.getAppState(),A=mm1($);if(A){w0(`pipeline_${A}`);return}let O={...q,messages:[...q.messages,U8({content:K}),..._]},w=bC(Y);if(w.signal.aborted)return;let j=GN8(),{suggestion:H,generationRequestId:J}=await Bm1(w,j,hL(O));if(w.signal.aborted)return;if(gm1(H,j))return;N(`[Speculation] Pipelined suggestion: "${H.slice(0,50)}..."`),SV6(z,()=>({pipelinedSuggestion:{text:H,promptId:j,generationRequestId:J}}))}catch($){if($ instanceof Error&&$.name==="AbortError")return;N(`[Speculation] Pipelined suggestion failed: ${d6($)}`)}}async function Um1(q,K,_,z=!1,Y){if(!Fm1())return;ou(_);let $=Szz().slice(0,8),A=bC(K.toolUseContext.abortController);if(A.signal.aborted)return;let O=Date.now(),w={current:[]},j={current:new Set},H=mN8($),J=Vx();try{await Kp1(H,{recursive:!0})}catch{N("[Speculation] Failed to create overlay directory");return}let M={current:K};_((X)=>({...X,speculation:{status:"active",id:$,abort:()=>A.abort(),startTime:O,messagesRef:w,writtenPathsRef:j,boundary:null,suggestionLength:q.length,toolUseCount:0,isPipelined:z,contextRef:M}})),N(`[Speculation] Starting speculation ${$}`);try{let X=await hG({promptMessages:[U8({content:q})],cacheSafeParams:Y??hL(K),skipTranscript:!0,canUseTool:async(P,W)=>{let D=pzz.has(P.name),f=Bzz.has(P.name);if(D){let Z=K.toolUseContext.getAppState(),{mode:T,isBypassPermissionsModeAvailable:v}=Z.toolPermissionContext;if(!(T==="acceptEdits"||T==="bypassPermissions"||T==="plan"&&v)){N(`[Speculation] Stopping at file edit: ${P.name}`);let E="file_path"in W?W.file_path:void 0;return SV6(_,()=>({boundary:{type:"edit",toolName:P.name,filePath:E??"",completedAt:Date.now()}})),A.abort(),uN8("Speculation paused: file edit requires permission","speculation_edit_boundary")}}if(D||f){let Z="notebook_path"in W?"notebook_path":("path"in W)?"path":"file_path",T=W[Z];if(T){let v=Izz(J,T);if(xzz(v)||v.startsWith("..")){if(D)return N(`[Speculation] Denied ${P.name}: path outside cwd: ${T}`),uN8("Write outside cwd not allowed during speculation","speculation_write_outside_root");return{behavior:"allow",updatedInput:W,decisionReason:{type:"other",reason:"speculation_read_outside_root"}}}if(D){if(!j.current.has(v)){let V=jw6(H,v);await Kp1(Ry4(V),{recursive:!0});try{await Ly4(jw6(J,v),V)}catch{}j.current.add(v)}W={...W,[Z]:jw6(H,v)}}else if(j.current.has(v))W={...W,[Z]:jw6(H,v)};return N(`[Speculation] ${D?"Write":"Read"} ${T} -> ${W[Z]}`),{behavior:"allow",updatedInput:W,decisionReason:{type:"other",reason:"speculation_file_access"}}}if(f)return{behavior:"allow",updatedInput:W,decisionReason:{type:"other",reason:"speculation_read_default_cwd"}}}if(P.name==="Bash"){let Z="command"in W&&typeof W.command==="string"?W.command:"";if(!Z||hN8({command:Z},ko6(Z)).behavior!=="allow")return N(`[Speculation] Stopping at bash: ${Z.slice(0,50)||"missing command"}`),SV6(_,()=>({boundary:{type:"bash",command:Z,completedAt:Date.now()}})),A.abort(),uN8("Speculation paused: bash boundary","speculation_bash_boundary");return{behavior:"allow",updatedInput:W,decisionReason:{type:"other",reason:"speculation_readonly_bash"}}}N(`[Speculation] Stopping at denied tool: ${P.name}`);let G=String("url"in W&&W.url||"file_path"in W&&W.file_path||"path"in W&&W.path||"command"in W&&W.command||"").slice(0,200);return SV6(_,()=>({boundary:{type:"denied_tool",toolName:P.name,detail:G,completedAt:Date.now()}})),A.abort(),uN8(`Tool ${P.name} not allowed during speculation`,"speculation_unknown_tool")},querySource:"speculation",forkLabel:"speculation",maxTurns:uzz,overrides:{abortController:A,requireCanUseTool:!0},onMessage:(P)=>{if(P.type==="assistant"||P.type==="user"){if(w.current.push(P),w.current.length>=mzz)A.abort();if(Yp1(P)){let W=$7(P.message.content,(D)=>D.type==="tool_result"&&!D.is_error);if(W>0)SV6(_,(D)=>({toolUseCount:D.toolUseCount+W}))}}}});if(A.signal.aborted)return;SV6(_,()=>({boundary:{type:"complete",completedAt:Date.now(),outputTokens:X.totalUsage.output_tokens}})),N(`[Speculation] Complete: ${zp1(w.current)} tools`),czz(M.current,q,w.current,_,A)}catch(X){if(A.abort(),X instanceof Error&&X.name==="AbortError"){vo6(H),_p1(_);return}vo6(H),H6(X instanceof Error?X:Error("Speculation failed")),pN8($,"error",O,q.length,w.current,null,{error_type:X instanceof Error?X.name:"Unknown",error_message:d6(X).slice(0,200),error_phase:"start",is_pipelined:z}),_p1(_)}}async function lzz(q,K,_){if(q.status!=="active")return null;let{id:z,messagesRef:Y,writtenPathsRef:$,abort:A,startTime:O,suggestionLength:w,isPipelined:j}=q,H=Y.current,J=mN8(z),M=Date.now();if(A(),_>0)await gzz(J,$.current,Vx());vo6(J);let X=q.boundary,P=Math.min(M,X?.completedAt??1/0)-O;if(K((W)=>{if(W.speculation.status==="active"&&W.speculation.boundary)X=W.speculation.boundary,P=Math.min(M,X.completedAt??1/0)-O;return{...W,speculation:Wq6,speculationSessionTimeSavedMs:W.speculationSessionTimeSavedMs+P}}),N(X===null?`[Speculation] Accept ${z}: still running, using ${H.length} messages`:`[Speculation] Accept ${z}: already complete`),pN8(z,"accepted",O,w,H,X,{message_count:H.length,time_saved_ms:P,is_pipelined:j}),P>0){let W={type:"speculation-accept",timestamp:new Date().toISOString(),timeSavedMs:P};bzz(Y$(),g6(W)+`
1683`,{mode:384}).catch(()=>{N("[Speculation] Failed to write speculation-accept to transcript")})}return{messages:H,boundary:X,timeSavedMs:P}}function ou(q){q((K)=>{if(K.speculation.status!=="active")return K;let{id:_,abort:z,startTime:Y,boundary:$,suggestionLength:A,messagesRef:O,isPipelined:w}=K.speculation;return N(`[Speculation] Aborting ${_}`),pN8(_,"aborted",Y,A,O.current,$,{abort_reason:"user_typed",is_pipelined:w}),z(),vo6(mN8(_)),{...K,speculation:Wq6}})}async function hy4(q,K,_,z,Y){try{let{setMessages:$,readFileState:A,cwd:O}=Y;_((f)=>{if(f.promptSuggestion.text===null&&f.promptSuggestion.promptId===null)return f;return{...f,promptSuggestion:{text:null,promptId:null,shownAt:0,acceptedAt:0,generationRequestId:null}}});let w=q.messagesRef.current,j=Qzz(w),H=U8({content:z});$((f)=>[...f,H]);let J=await lzz(q,_,j.length),M=J?.boundary?.type==="complete";if(!M){let f=j.findLastIndex((G)=>G.type!=="assistant");j=j.slice(0,f+1)}let X=J?.timeSavedMs??0,P=K+X,W=dzz(j,J?.boundary??null,X,P);$((f)=>[...f,...j]);let D=hV6(j,O,tF);if(A.current=mk6(A.current,D),W)$((f)=>[...f,W]);if(N(`[Speculation] ${J?.boundary?.type??"incomplete"}, injected ${j.length} messages`),M&&q.pipelinedSuggestion){let{text:f,promptId:G,generationRequestId:Z}=q.pipelinedSuggestion;N(`[Speculation] Promoting pipelined suggestion: "${f.slice(0,50)}..."`),_((v)=>({...v,promptSuggestion:{text:f,promptId:G,shownAt:Date.now(),acceptedAt:0,generationRequestId:Z}}));let T={...q.contextRef.current,messages:[...q.contextRef.current.messages,U8({content:z}),...j]};Um1(f,T,_,!0)}return{queryRequired:!M}}catch($){return H6($ instanceof Error?$:Error("handleSpeculationAccept failed")),pN8(q.id,"error",q.startTime,q.suggestionLength,q.messagesRef.current,q.boundary,{error_type:$ instanceof Error?$.name:"Unknown",error_message:d6($).slice(0,200),error_phase:"accept",is_pipelined:q.isPipelined}),vo6(mN8(q.id)),_p1(_),{queryRequired:!0}}}var uzz=20,mzz=100,pzz,Bzz;var Yw6=y(()=>{v8();EV6();DN();am1();B2();V1();_8();y8();NG();nv();U7();E8();i1();Tz();To6();_K();l8();k8();zw6();pzz=new Set(["Edit","Write","NotebookEdit"]),Bzz=new Set(["Read","Glob","Grep","ToolSearch","LSP","TaskGet","TaskList"])});import{randomUUID as nzz}from"crypto";function ur(q){if(!i7())return;if(Vo6.length>=izz)Vo6.shift();Vo6.push(q)}function No6(){if(Vo6.length===0)return[];return Vo6.splice(0).map((K)=>({...K,uuid:nzz(),session_id:N8()}))}function ZN(q,K,_){ur({type:"system",subtype:"task_notification",task_id:q,tool_use_id:_?.toolUseId,status:K,output_file:_?.outputFile??"",summary:_?.summary??"",usage:_?.usage})}var izz=1000,Vo6;var pC=y(()=>{v8();Vo6=[]});function A3(q,K,_){K((z)=>{let Y=z.tasks?.[q];if(!Y)return z;let $=_(Y);if($===Y)return z;return{...z,tasks:{...z.tasks,[q]:$}}})}function H0(q,K){let _=!1;if(K((z)=>{let Y=z.tasks[q.id];_=Y!==void 0;let $=Y&&"retain"in Y?{...q,retain:Y.retain,startTime:Y.startTime,messages:Y.messages,diskLoaded:Y.diskLoaded,pendingMessages:Y.pendingMessages}:q;return{...z,tasks:{...z.tasks,[q.id]:$}}}),_)return;ur({type:"system",subtype:"task_started",task_id:q.id,tool_use_id:q.toolUseId,description:q.description,task_type:q.type,workflow_name:"workflowName"in q?q.workflowName:void 0,prompt:"prompt"in q?q.prompt:void 0})}function CV6(q,K){K((_)=>{let z=_.tasks?.[q];if(!z)return _;if(!mr(z.status))return _;if(!z.notified)return _;if("retain"in z&&(z.evictAfter??1/0)>Date.now())return _;let{[q]:Y,...$}=_.tasks;return{..._,tasks:$}})}function gN8(q){let K=q.tasks??{};return Object.values(K).filter((_)=>_.status==="running")}async function Cy4(q){let K=[],_={},z=[],Y=q.tasks??{};for(let $ of Object.values(Y)){if($.notified)switch($.status){case"completed":case"failed":case"killed":z.push($.id);continue;case"pending":continue;case"running":break}if($.status==="running"){let A=await xy4($.id,$.outputOffset);if(A.content)_[$.id]=A.newOffset}}return{attachments:K,updatedTaskOffsets:_,evictedTaskIds:z}}function by4(q,K,_){let z=Object.keys(K);if(z.length===0&&_.length===0)return;q((Y)=>{let $=!1,A={...Y.tasks};for(let O of z){let w=A[O];if(w?.status==="running")A[O]={...w,outputOffset:K[O]},$=!0}for(let O of _){let w=A[O];if(!w||!mr(w.status)||!w.notified)continue;if("retain"in w&&(w.evictAfter??1/0)>Date.now())continue;delete A[O],$=!0}return $?{...Y,tasks:A}:Y})}var Sy4=3000,BN8=30000;var J0=y(()=>{RY();GN();p2();pC();Ij()});function CL(q){return q.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function e9(q){return CL(q).replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function my4(q){return q.isNonInteractiveSession}function FN8(q){let K=Iy4.get(q);if(K)return K;let _=azz(q);return Iy4.set(q,_),_}function azz(q){try{let K=new uy4.Ajv({allErrors:!0});if(!K.validateSchema(q))return{error:K.errorsText(K.errors)};let z=K.compile(q);return{tool:{...$p1,inputJSONSchema:q,async call(Y){if(!z(Y)){let A=z.errors?.map((O)=>`${O.instancePath||"root"}: ${O.message}`).join(", ");throw new uk(`Output does not match required schema: ${A}`,`StructuredOutput schema mismatch: ${(A??"").slice(0,150)}`)}return{data:"Structured output provided successfully",structured_output:Y}}}}}catch(K){return{error:K instanceof Error?K.message:String(K)}}}var uy4,rzz,ozz,MD="StructuredOutput",$p1,Iy4;var GU=y(()=>{x7();Bq();y8();l8();uy4=O6(cz8(),1),rzz=B6(()=>L.object({}).passthrough()),ozz=B6(()=>L.string().describe("Structured output tool result"));$p1=sq({isMcp:!1,isEnabled(){return!0},isConcurrencySafe(){return!0},isReadOnly(){return!0},isOpenWorld(){return!1},name:MD,searchHint:"return the final response as structured JSON",maxResultSizeChars:1e5,async description(){return"Return structured output in the requested format"},async prompt(){return"Use this tool to return your final response in the requested structured format. You MUST call this tool exactly once at the end of your response to provide the structured output."},get inputSchema(){return rzz()},get outputSchema(){return ozz()},async call(q){return{data:"Structured output provided successfully",structured_output:q}},async checkPermissions(q){return{behavior:"allow",updatedInput:q}},renderToolUseMessage(q){let K=Object.keys(q);if(K.length===0)return null;if(K.length<=3)return K.map((_)=>`${_}: ${g6(q[_])}`).join(", ");return`${K.length} fields: ${K.slice(0,3).join(", ")}…`},renderToolUseRejectedMessage(){return"Structured output rejected"},renderToolUseErrorMessage(){return"Structured output error"},renderToolUseProgressMessage(){return null},renderToolResultMessage(q){return q},mapToolResultToToolResultBlockParam(q,K){return{tool_use_id:K,type:"tool_result",content:q}}}),Iy4=new WeakMap});function EX(q){return q}function pO(q){return q}function py4(q){return szz.test(q)?q:null}var szz;var M0=y(()=>{szz=/^a(?:.+-)?[0-9a-f]{16}$/});function UN8(q){let K=q.indexOf(`
1684`),_=(K===-1?q:q.slice(0,K)).trim();if(!_.startsWith("#")||_.startsWith("#!"))return;return _.replace(/^#+\s*/,"")||void 0}function QN8(q,K){if(K)return q?`agent:builtin:${q}`:"agent:default";else return"agent:custom"}function yo6(){let K=Z7()?.outputStyle??iv;if(K===iv)return"repl_main_thread";return K in Hw6?`repl_main_thread:outputStyle:${K}`:"repl_main_thread:outputStyle:custom"}var dN8=y(()=>{TU();U1()});var Zq6="EnterPlanMode";var a$="AskUserQuestion",By4=12,gy4="Asks the user multiple choice questions to gather information, clarify ambiguity, understand preferences, make decisions or offer them choices.",Fy4,Ap1;var vU=y(()=>{Fy4={markdown:`
1685Preview feature:

Callers 5

ZNFunction · 0.85
H0Function · 0.85
VL8Function · 0.85
callFunction · 0.85
sS6Function · 0.85

Calls 3

i7Function · 0.85
shiftMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected