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

Function Pzz

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

Source from the content-addressed store, hash-verified

1677`,O),j=w===-1?K.length:w;if(K.slice(O,j).trim().startsWith("#"))return d("tengu_bash_security_check_triggered",{checkId:t9.QUOTED_NEWLINE}),{behavior:"ask",message:"Command contains a quoted newline followed by a #-prefixed line, which can hide arguments from line-based permission checks"}}}return{behavior:"passthrough",message:"No quoted newline-hash pattern"}}function My4(q){let{originalCommand:K}=q,_=new Set(["command","builtin","noglob","nocorrect"]),z=K.trim(),Y=z.split(/\s+/),$="";for(let A of Y){if(/^[A-Za-z_]\w*=/.test(A))continue;if(_.has(A))continue;$=A;break}if(x_z.has($))return d("tengu_bash_security_check_triggered",{checkId:t9.ZSH_DANGEROUS_COMMANDS,subId:1}),{behavior:"ask",message:`Command uses Zsh-specific '${$}' which can bypass security checks`};if($==="fc"&&/\s-\S*e/.test(z))return d("tengu_bash_security_check_triggered",{checkId:t9.ZSH_DANGEROUS_COMMANDS,subId:2}),{behavior:"ask",message:"Command uses 'fc -e' which can execute arbitrary commands via editor"};return{behavior:"passthrough",message:"No Zsh dangerous commands"}}function Po6(q){if(Xy4.test(q))return d("tengu_bash_security_check_triggered",{checkId:t9.CONTROL_CHARACTERS}),{behavior:"ask",message:"Command contains non-printable control characters that could be used to bypass security checks",isBashSecurityCheckForMisparsing:!0};if(Oo6(q))return{behavior:"ask",message:"Command contains single-quoted backslash pattern that could bypass security checks",isBashSecurityCheckForMisparsing:!0};let{processedCommand:K}=Dq6(q,{quotedOnly:!0}),_=q.split(" ")[0]||"",{withDoubleQuotes:z,fullyUnquoted:Y,unquotedKeepQuoteChars:$}=dN4(K,_==="jq"),A={originalCommand:q,baseCommand:_,unquotedContent:z,fullyUnquotedContent:cN4(Y),fullyUnquotedPreStrip:Y,unquotedKeepQuoteChars:$},O=[lN4,nN4,rN4,oN4];for(let J of O){let M=J(A);if(M.behavior==="allow")return{behavior:"passthrough",message:M.decisionReason?.type==="other"||M.decisionReason?.type==="safetyCheck"?M.decisionReason.reason:"Command allowed"};if(M.behavior!=="passthrough")return M.behavior==="ask"?{...M,isBashSecurityCheckForMisparsing:!0}:M}let w=new Set([NN8,VN8]),j=[aN4,Yy4,sN4,tN4,Hy4,Jy4,qy4,NN8,Ky4,_y4,eN4,VN8,$y4,Ay4,wy4,jy4,Oy4,My4,zy4],H=null;for(let J of j){let M=J(A);if(M.behavior==="ask"){if(w.has(J)){if(H===null)H=M;continue}return{...M,isBashSecurityCheckForMisparsing:!0}}}if(H!==null)return H;return{behavior:"passthrough",message:"Command passed all security checks"}}async function yN8(q,K){let z=(await Aw6.parse(q))?.getTreeSitterAnalysis()??null;if(!z)return Po6(q);if(Xy4.test(q))return d("tengu_bash_security_check_triggered",{checkId:t9.CONTROL_CHARACTERS}),{behavior:"ask",message:"Command contains non-printable control characters that could be used to bypass security checks",isBashSecurityCheckForMisparsing:!0};if(Oo6(q))return{behavior:"ask",message:"Command contains single-quoted backslash pattern that could bypass security checks",isBashSecurityCheckForMisparsing:!0};let{processedCommand:Y}=Dq6(q,{quotedOnly:!0}),$=q.split(" ")[0]||"",A=z.quoteContext,O=dN4(Y,$==="jq"),w=A.withDoubleQuotes,j=A.fullyUnquoted,H=A.unquotedKeepQuoteChars,J={originalCommand:q,baseCommand:$,unquotedContent:w,fullyUnquotedContent:cN4(j),fullyUnquotedPreStrip:j,unquotedKeepQuoteChars:H,treeSitter:z};if(!z.dangerousPatterns.hasHeredoc){if(A.fullyUnquoted!==O.fullyUnquoted||A.withDoubleQuotes!==O.withDoubleQuotes)if(K)K();else d("tengu_tree_sitter_security_divergence",{quoteContextDivergence:!0})}let M=[lN4,nN4,rN4,oN4];for(let D of M){let f=D(J);if(f.behavior==="allow")return{behavior:"passthrough",message:f.decisionReason?.type==="other"||f.decisionReason?.type==="safetyCheck"?f.decisionReason.reason:"Command allowed"};if(f.behavior!=="passthrough")return f.behavior==="ask"?{...f,isBashSecurityCheckForMisparsing:!0}:f}let X=new Set([NN8,VN8]),P=[aN4,Yy4,sN4,tN4,Hy4,Jy4,qy4,NN8,Ky4,_y4,eN4,VN8,$y4,Ay4,wy4,jy4,Oy4,My4,zy4],W=null;for(let D of P){let f=D(J);if(f.behavior==="ask"){if(X.has(D)){if(W===null)W=f;continue}return{...f,isBashSecurityCheckForMisparsing:!0}}}if(W!==null)return W;return{behavior:"passthrough",message:"Command passed all security checks"}}var rm1,b_z,x_z,t9,p_z,g_z,Xy4;var EN8=y(()=>{k8();dm1();im1();NX();rm1=/\$\(.*<</,b_z=[{pattern:/<\(/,message:"process substitution <()"},{pattern:/>\(/,message:"process substitution >()"},{pattern:/=\(/,message:"Zsh process substitution =()"},{pattern:/(?:^|[\s;&|])=[a-zA-Z_]/,message:"Zsh equals expansion (=cmd)"},{pattern:/\$\(/,message:"$() command substitution"},{pattern:/\$\{/,message:"${} parameter substitution"},{pattern:/\$\[/,message:"$[] legacy arithmetic expansion"},{pattern:/~\[/,message:"Zsh-style parameter expansion"},{pattern:/\(e:/,message:"Zsh-style glob qualifiers"},{pattern:/\(\+/,message:"Zsh glob qualifier with command execution"},{pattern:/\}\s*always\s*\{/,message:"Zsh always block (try/always construct)"},{pattern:/<#/,message:"PowerShell comment syntax"}],x_z=new Set(["zmodload","emulate","sysopen","sysread","syswrite","sysseek","zpty","ztcp","zsocket","mapfile","zf_rm","zf_mv","zf_ln","zf_chmod","zf_chown","zf_mkdir","zf_rmdir","zf_chgrp"]),t9={INCOMPLETE_COMMANDS:1,JQ_SYSTEM_FUNCTION:2,JQ_FILE_ARGUMENTS:3,OBFUSCATED_FLAGS:4,SHELL_METACHARACTERS:5,DANGEROUS_VARIABLES:6,NEWLINES:7,DANGEROUS_PATTERNS_COMMAND_SUBSTITUTION:8,DANGEROUS_PATTERNS_INPUT_REDIRECTION:9,DANGEROUS_PATTERNS_OUTPUT_REDIRECTION:10,IFS_INJECTION:11,GIT_COMMIT_SUBSTITUTION:12,PROC_ENVIRON_ACCESS:13,MALFORMED_TOKEN_INJECTION:14,BACKSLASH_ESCAPED_WHITESPACE:15,BRACE_EXPANSION:16,CONTROL_CHARACTERS:17,UNICODE_WHITESPACE:18,MID_WORD_HASH:19,ZSH_DANGEROUS_COMMANDS:20,BACKSLASH_ESCAPED_OPERATORS:21,COMMENT_QUOTE_DESYNC:22,QUOTED_NEWLINE:23};p_z=new Set([";","|","&","<",">"]);g_z=/[\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]/;Xy4=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/});function Wy4(q,K){for(let _ of q)if(_.startsWith("-")&&!_.startsWith("--")&&_.length>2)for(let z=1;z<_.length;z++){let Y="-"+_[z];if(!K.includes(Y))return!1}else if(!K.includes(_))return!1;return!0}function F_z(q,K){let _=q.match(/^\s*sed\s+/);if(!_)return!1;let z=q.slice(_[0].length),Y=o$(z);if(!Y.success)return!1;let $=Y.tokens,A=[];for(let j of $)if(typeof j==="string"&&j.startsWith("-")&&j!=="--")A.push(j);if(!Wy4(A,["-n","--quiet","--silent","-E","--regexp-extended","-r","-z","--zero-terminated","--posix"]))return!1;let w=!1;for(let j of A){if(j==="-n"||j==="--quiet"||j==="--silent"){w=!0;break}if(j.startsWith("-")&&!j.startsWith("--")&&j.includes("n")){w=!0;break}}if(!w)return!1;if(K.length===0)return!1;for(let j of K){let H=j.split(";");for(let J of H)if(!U_z(J.trim()))return!1}return!0}function U_z(q){if(!q)return!1;return/^(?:\d+|\d+,\d+)?p$/.test(q)}function Py4(q,K,_,z){let Y=z?.allowFileWrites??!1;if(!Y&&_)return!1;let $=q.match(/^\s*sed\s+/);if(!$)return!1;let A=q.slice($[0].length),O=o$(A);if(!O.success)return!1;let w=O.tokens,j=[];for(let Z of w)if(typeof Z==="string"&&Z.startsWith("-")&&Z!=="--")j.push(Z);let H=["-E","--regexp-extended","-r","--posix"];if(Y)H.push("-i","--in-place");if(!Wy4(j,H))return!1;if(K.length!==1)return!1;let J=K[0].trim();if(!J.startsWith("s"))return!1;let M=J.match(/^s\/(.*?)$/);if(!M)return!1;let X=M[1],P=0,W=-1,D=0;while(D<X.length){if(X[D]==="\\"){D+=2;continue}if(X[D]==="/")P++,W=D;D++}if(P!==2)return!1;let f=X.slice(W+1);if(!/^[gpimIM]*[1-9]?[gpimIM]*$/.test(f))return!1;return!0}function RV6(q,K){let _=K?.allowFileWrites??!1,z;try{z=d_z(q)}catch(O){return!1}let Y=Q_z(q),$=!1,A=!1;if(_)A=Py4(q,z,Y,{allowFileWrites:!0});else $=F_z(q,z),A=Py4(q,z,Y);if(!$&&!A)return!1;for(let O of z)if(A&&O.includes(";"))return!1;for(let O of z)if(c_z(O))return!1;return!0}function Q_z(q){let K=q.match(/^\s*sed\s+/);if(!K)return!1;let _=q.slice(K[0].length),z=o$(_);if(!z.success)return!0;let Y=z.tokens;try{let $=0,A=!1;for(let O=0;O<Y.length;O++){let w=Y[O];if(typeof w!=="string"&&typeof w!=="object")continue;if(typeof w==="object"&&w!==null&&"op"in w&&w.op==="glob")return!0;if(typeof w!=="string")continue;if((w==="-e"||w==="--expression")&&O+1<Y.length){A=!0,O++;continue}if(w.startsWith("--expression=")){A=!0;continue}if(w.startsWith("-e=")){A=!0;continue}if(w.startsWith("-"))continue;if($++,A)return!0;if($>1)return!0}return!1}catch($){return!0}}function d_z(q){let K=[],_=q.match(/^\s*sed\s+/);if(!_)return K;let z=q.slice(_[0].length);if(/-e[wWe]/.test(z)||/-w[eE]/.test(z))throw Error("Dangerous flag combination detected");let Y=o$(z);if(!Y.success)throw Error(`Malformed shell syntax: ${Y.error}`);let $=Y.tokens;try{let A=!1,O=!1;for(let w=0;w<$.length;w++){let j=$[w];if(typeof j!=="string")continue;if((j==="-e"||j==="--expression")&&w+1<$.length){A=!0;let H=$[w+1];if(typeof H==="string")K.push(H),w++;continue}if(j.startsWith("--expression=")){A=!0,K.push(j.slice(13));continue}if(j.startsWith("-e=")){A=!0,K.push(j.slice(3));continue}if(j.startsWith("-"))continue;if(!A&&!O){K.push(j),O=!0;continue}break}}catch(A){throw Error(`Failed to parse sed command: ${A instanceof Error?A.message:"Unknown error"}`)}return K}function c_z(q){let K=q.trim();if(!K)return!1;if(/[^\x01-\x7F]/.test(K))return!0;if(K.includes("{")||K.includes("}"))return!0;if(K.includes(`
1678`))return!0;let _=K.indexOf("#");if(_!==-1&&!(_>0&&K[_-1]==="s"))return!0;if(/^!/.test(K)||/[/\d$]!/.test(K))return!0;if(/\d\s*~\s*\d|,\s*~\s*\d|\$\s*~\s*\d/.test(K))return!0;if(/^,/.test(K))return!0;if(/,\s*[+-]/.test(K))return!0;if(/s\\/.test(K)||/\\[|#%@]/.test(K))return!0;if(/\\\/.*[wW]/.test(K))return!0;if(/\/[^/]*\s+[wWeE]/.test(K))return!0;if(/^s\//.test(K)&&!/^s\/[^/]*\/[^/]*\/[^/]*$/.test(K))return!0;if(/^s./.test(K)&&/[wWeE]$/.test(K)){if(!/^s([^\\\n]).*?\1.*?\1[^wWeE]*$/.test(K))return!0}if(/^[wW]\s*\S+/.test(K)||/^\d+\s*[wW]\s*\S+/.test(K)||/^\$\s*[wW]\s*\S+/.test(K)||/^\/[^/]*\/[IMim]*\s*[wW]\s*\S+/.test(K)||/^\d+,\d+\s*[wW]\s*\S+/.test(K)||/^\d+,\$\s*[wW]\s*\S+/.test(K)||/^\/[^/]*\/[IMim]*,\/[^/]*\/[IMim]*\s*[wW]\s*\S+/.test(K))return!0;if(/^e/.test(K)||/^\d+\s*e/.test(K)||/^\$\s*e/.test(K)||/^\/[^/]*\/[IMim]*\s*e/.test(K)||/^\d+,\d+\s*e/.test(K)||/^\d+,\$\s*e/.test(K)||/^\/[^/]*\/[IMim]*,\/[^/]*\/[IMim]*\s*e/.test(K))return!0;let z=K.match(/s([^\\\n]).*?\1.*?\1(.*?)$/);if(z){let $=z[2]||"";if($.includes("w")||$.includes("W"))return!0;if($.includes("e")||$.includes("E"))return!0}if(K.match(/y([^\\\n])/)){if(/[wWeE]/.test(K))return!0}return!1}function Dy4(q,K){let _=F2(q.command);for(let z of _){let Y=z.trim();if(Y.split(/\s+/)[0]!=="sed")continue;let A=K.mode==="acceptEdits";if(!RV6(Y,{allowFileWrites:A}))return{behavior:"ask",message:"sed command requires approval (contains potentially dangerous operations)",decisionReason:{type:"other",reason:"sed command contains operations that require explicit approval (e.g., write commands, execute commands)"}}}return{behavior:"passthrough",message:"No dangerous sed operations detected"}}var LN8=y(()=>{SG();NX()});import{homedir as l_z}from"os";import{isAbsolute as n_z,resolve as i_z}from"path";function r_z(q,K,_){let z=Wo6[q],Y=z(K);for(let $ of Y){let A=O76($.replace(/^['"]|['"]$/g,"")),O=n_z(A)?A:i_z(_,A);if(Nv6(O))return{behavior:"ask",message:`Dangerous ${q} operation detected: '${O}'
1679
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)+`

Callers 1

WzzFunction · 0.85

Calls 1

testMethod · 0.45

Tested by

no test coverage detected