| 1625 | `}var W3z,D3z,vV6,f3z,Pm1,r3z,o3z;var fm1=y(()=>{W3z={parse:V3z},D3z=Promise.resolve();vV6=new Set(["?","$","@","*","#","-","!","_"]),f3z=new Set(["export","declare","typeset","readonly","local"]),Pm1=new Set(["if","then","elif","else","fi","while","until","for","in","do","done","case","esac","function","select"]);r3z={"=":2,"+=":2,"-=":2,"*=":2,"/=":2,"%=":2,"<<=":2,">>=":2,"&=":2,"^=":2,"|=":2,"||":4,"&&":5,"|":6,"^":7,"&":8,"==":9,"!=":9,"<":10,">":10,"<=":10,">=":10,"<<":11,">>":11,"+":12,"-":12,"*":13,"/":13,"%":13,"**":14},o3z=new Set(["=","+=","-=","*=","/=","%=","<<=",">>=","&=","^=","|=","**"])});var Tm1={};T8(Tm1,{parseCommandRaw:()=>Ao6,parseCommand:()=>Zm1,extractCommandArguments:()=>Gm1,ensureInitialized:()=>z9z,PARSE_ABORTED:()=>eO6});function _9z(q){if(lV4)return;lV4=!0,N(q?"tree-sitter: native module loaded":"tree-sitter: unavailable"),d("tengu_tree_sitter_load",{success:q})}async function z9z(){await Xm1()}async function Zm1(q){if(!q||q.length>nV4)return null;return null}async function Ao6(q){if(!q||q.length>nV4)return null;{await Xm1();let K=BV4();if(_9z(K!==null),!K)return null;try{let _=K.parse(q);if(_===null)return d("tengu_tree_sitter_parse_abort",{cmdLength:q.length,panic:!1}),eO6;return _}catch{return d("tengu_tree_sitter_parse_abort",{cmdLength:q.length,panic:!0}),eO6}}return null}function Gm1(q){if(q.type==="declaration_command"){let z=q.children[0];return z&&e3z.has(z.text)?[z.text]:[]}let K=[],_=!1;for(let z of q.children){if(z.type==="variable_assignment")continue;if(z.type==="command_name"||!_&&z.type==="word"){_=!0,K.push(z.text);continue}if(q9z.has(z.type))K.push(Y9z(z.text));else if(K9z.has(z.type))break}return K}function Y9z(q){return q.length>=2&&(q[0]==='"'&&q.at(-1)==='"'||q[0]==="'"&&q.at(-1)==="'")?q.slice(1,-1):q}var nV4=1e4,e3z,q9z,K9z,lV4=!1,eO6;var qw6=y(()=>{k8();_8();fm1();e3z=new Set(["export","declare","typeset","readonly","local","unset","unsetenv"]),q9z=new Set(["word","string","raw_string","number"]),K9z=new Set(["command_substitution","process_substitution"]);eO6=Symbol("parse-aborted")});function jN8(q){return q.includes(wN8)||q.includes(Cr)}function tV4(q){if(!q)return-2;if(q==="ERROR")return-1;let K=X9z.indexOf(q);return K>=0?K+1:0}function T9z(q){if(!q.includes("{"))return q;let K=[],_=!1,z=!1,Y=0;while(Y<q.length){let $=q[Y];if(_){if($==="'")_=!1;K.push($==="{"?" ":$),Y++}else if(z)if($==="\\"&&(q[Y+1]==='"'||q[Y+1]==="\\"))K.push($,q[Y+1]),Y+=2;else{if($==='"')z=!1;K.push($==="{"?" ":$),Y++}else if($==="\\"&&Y+1<q.length)K.push($,q[Y+1]),Y+=2;else{if($==="'")_=!0;else if($==='"')z=!0;K.push($),Y++}}return K.join("")}async function eV4(q){if(q==="")return{kind:"simple",commands:[]};let K=await Ao6(q);return K===null?{kind:"parse-unavailable"}:Nm1(q,K)}function Nm1(q,K){if(P9z.test(q))return{kind:"too-complex",reason:"Contains control characters"};if(W9z.test(q))return{kind:"too-complex",reason:"Contains Unicode whitespace"};if(D9z.test(q))return{kind:"too-complex",reason:"Contains backslash-escaped whitespace"};if(f9z.test(q))return{kind:"too-complex",reason:"Contains zsh ~[ dynamic directory syntax"};if(Z9z.test(q))return{kind:"too-complex",reason:"Contains zsh =cmd equals expansion"};if(G9z.test(T9z(q)))return{kind:"too-complex",reason:"Contains brace with quote character (expansion obfuscation)"};if(q.trim()==="")return{kind:"simple",commands:[]};if(K===eO6)return{kind:"too-complex",reason:"Parser aborted (timeout or resource limit) — possible adversarial input",nodeType:"PARSE_ABORT"};return v9z(K)}function v9z(q){let K=[],z=XU(q,K,new Map);if(z)return z;return{kind:"simple",commands:K}}function XU(q,K,_){if(q.type==="command"){let z=N9z(q,[],K,_);if(z.kind!=="simple")return z;return K.push(...z.commands),null}if(q.type==="redirected_statement")return k9z(q,K,_);if(q.type==="comment")return null;if($9z.has(q.type)){let z=q.type==="pipeline",Y=!1;if(!z){for(let O of q.children)if(O&&(O.type==="||"||O.type==="&")){Y=!0;break}}let $=Y?new Map(_):null,A=z?new Map(_):_;for(let O of q.children){if(!O)continue;if(A9z.has(O.type)){if(O.type==="||"||O.type==="|"||O.type==="|&"||O.type==="&")A=new Map($??_);continue}let w=XU(O,K,A);if(w)return w}return null}if(q.type==="negated_command"){for(let z of q.children){if(!z)continue;if(z.type==="!")continue;return XU(z,K,_)}return null}if(q.type==="declaration_command"){let z=[];for(let Y of q.children){if(!Y)continue;switch(Y.type){case"export":case"local":case"readonly":case"declare":case"typeset":z.push(Y.text);break;case"word":case"number":case"raw_string":case"string":case"concatenation":{let $=PU(Y,K,_);if(typeof $!=="string")return $;if((z[0]==="declare"||z[0]==="typeset"||z[0]==="local")&&/^-[a-zA-Z]*[niaA]/.test($))return{kind:"too-complex",reason:`declare flag ${$} changes assignment semantics (nameref/integer/array)`,nodeType:"declaration_command"};if((z[0]==="declare"||z[0]==="typeset"||z[0]==="local")&&$[0]!=="-"&&/^[^=]*\[/.test($))return{kind:"too-complex",reason:`declare positional '${$}' contains array subscript — bash evaluates $(cmd) in subscripts`,nodeType:"declaration_command"};z.push($);break}case"variable_assignment":{let $=km1(Y,K,_);if("kind"in $)return $;oV4(_,$),z.push(`${$.name}=${$.value}`);break}case"variable_name":z.push(Y.text);break;default:return EH(Y)}}return K.push({argv:z,envVars:[],redirects:[],text:q.text}),null}if(q.type==="variable_assignment"){let z=km1(q,K,_);if("kind"in z)return z;return oV4(_,z),null}if(q.type==="for_statement"){let z=null,Y=null;for(let A of q.children){if(!A)continue;if(A.type==="variable_name")z=A.text;else if(A.type==="do_group")Y=A;else if(A.type==="for"||A.type==="in"||A.type==="select"||A.type===";")continue;else if(A.type==="command_substitution"){let O=ym1(A,K,_);if(O)return O}else{let O=PU(A,K,_);if(typeof O!=="string")return O}}if(z===null||Y===null)return EH(q);if(z==="PS4"||z==="IFS")return{kind:"too-complex",reason:`${z} as loop variable bypasses assignment validation`,nodeType:"for_statement"};_.set(z,Cr);let $=new Map(_);for(let A of Y.children){if(!A)continue;if(A.type==="do"||A.type==="done"||A.type===";")continue;let O=XU(A,K,$);if(O)return O}return null}if(q.type==="if_statement"||q.type==="while_statement"){let z=!1;for(let Y of q.children){if(!Y)continue;if(Y.type==="if"||Y.type==="fi"||Y.type==="else"||Y.type==="elif"||Y.type==="while"||Y.type==="until"||Y.type===";")continue;if(Y.type==="then"){z=!0;continue}if(Y.type==="do_group"){let w=new Map(_);for(let j of Y.children){if(!j)continue;if(j.type==="do"||j.type==="done"||j.type===";")continue;let H=XU(j,K,w);if(H)return H}continue}if(Y.type==="elif_clause"||Y.type==="else_clause"){let w=new Map(_);for(let j of Y.children){if(!j)continue;if(j.type==="elif"||j.type==="else"||j.type==="then"||j.type===";")continue;let H=XU(j,K,w);if(H)return H}continue}let $=z?new Map(_):_,A=K.length,O=XU(Y,K,$);if(O)return O;if(!z)for(let w=A;w<K.length;w++){let j=K[w];if(j?.argv[0]==="read"){for(let H of j.argv.slice(1))if(!H.startsWith("-")&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(H)){let J=_.get(H);if(J!==void 0&&!jN8(J))return{kind:"too-complex",reason:`'read ${H}' in condition may not execute (||/pipeline/subshell); cannot prove it overwrites tracked literal '${J}'`,nodeType:"if_statement"};_.set(H,Cr)}}}}return null}if(q.type==="subshell"){let z=new Map(_);for(let Y of q.children){if(!Y)continue;if(Y.type==="("||Y.type===")")continue;let $=XU(Y,K,z);if($)return $}return null}if(q.type==="test_command"){let z=["[["];for(let Y of q.children){if(!Y)continue;if(Y.type==="[["||Y.type==="]]")continue;if(Y.type==="["||Y.type==="]")continue;let $=qN4(Y,z,K,_);if($)return $}return K.push({argv:z,envVars:[],redirects:[],text:q.text}),null}if(q.type==="unset_command"){let z=[];for(let Y of q.children){if(!Y)continue;switch(Y.type){case"unset":z.push(Y.text);break;case"variable_name":z.push(Y.text),_.delete(Y.text);break;case"word":{let $=PU(Y,K,_);if(typeof $!=="string")return $;z.push($);break}default:return EH(Y)}}return K.push({argv:z,envVars:[],redirects:[],text:q.text}),null}return EH(q)}function qN4(q,K,_,z){switch(q.type){case"unary_expression":case"binary_expression":case"negated_expression":case"parenthesized_expression":{for(let Y of q.children){if(!Y)continue;let $=qN4(Y,K,_,z);if($)return $}return null}case"test_operator":case"!":case"(":case")":case"&&":case"||":case"==":case"=":case"!=":case"<":case">":case"=~":return K.push(q.text),null;case"regex":case"extglob_pattern":return K.push(q.text),null;default:{let Y=PU(q,_,z);if(typeof Y!=="string")return Y;return K.push(Y),null}}}function k9z(q,K,_){let z=[],Y=null;for(let O of q.children){if(!O)continue;if(O.type==="file_redirect"){let w=KN4(O,K,_);if("kind"in w)return w;z.push(w)}else if(O.type==="heredoc_redirect"){let w=_N4(O);if(w)return w}else if(O.type==="command"||O.type==="pipeline"||O.type==="list"||O.type==="negated_command"||O.type==="declaration_command"||O.type==="unset_command")Y=O;else return EH(O)}if(!Y)return K.push({argv:[],envVars:[],redirects:z,text:q.text}),null;let $=K.length,A=XU(Y,K,_);if(A)return A;if(K.length>$&&z.length>0){let O=K[K.length-1];if(O)O.redirects.push(...z)}return null}function KN4(q,K,_){let z=null,Y=null,$;for(let A of q.children){if(!A)continue;if(A.type==="file_descriptor")$=Number(A.text);else if(A.type in iV4)z=iV4[A.type]??null;else if(A.type==="word"||A.type==="number"){if(A.children.length>0)return EH(A);if(vm1.test(A.text))return EH(A);Y=A.text.replace(/\\(.)/g,"$1")}else if(A.type==="raw_string")Y=YN4(A.text);else if(A.type==="string"){let O=zN4(A,K,_);if(typeof O!=="string")return O;Y=O}else if(A.type==="concatenation"){let O=PU(A,K,_);if(typeof O!=="string")return O;Y=O}else return EH(A)}if(!z||Y===null)return{kind:"too-complex",reason:"Unrecognized redirect shape",nodeType:q.type};return{op:z,target:Y,fd:$}}function _N4(q){let K=null,_=null;for(let Y of q.children){if(!Y)continue;if(Y.type==="heredoc_start")K=Y.text;else if(Y.type==="heredoc_body")_=Y;else if(Y.type==="<<"||Y.type==="<<-"||Y.type==="heredoc_end"||Y.type==="file_descriptor");else return EH(Y)}if(!(K!==null&&(K.startsWith("'")&&K.endsWith("'")||K.startsWith('"')&&K.endsWith('"')||K.startsWith("\\"))))return{kind:"too-complex",reason:"Heredoc with unquoted delimiter undergoes shell expansion",nodeType:"heredoc_redirect"};if(_)for(let Y of _.children){if(!Y)continue;if(Y.type!=="heredoc_content")return EH(Y)}return null}function V9z(q,K,_){for(let z of q.children){if(!z)continue;if(z.type==="<<<")continue;let Y=PU(z,K,_);if(typeof Y!=="string")return Y;if(ON8.test(Y))return EH(z)}return null}function N9z(q,K,_,z){let Y=[],$=[],A=[...K];for(let w of q.children){if(!w)continue;switch(w.type){case"variable_assignment":{let j=km1(w,_,z);if("kind"in j)return j;$.push({name:j.name,value:j.value});break}case"command_name":{let j=PU(w.children[0]??w,_,z);if(typeof j!=="string")return j;Y.push(j);break}case"word":case"number":case"raw_string":case"string":case"concatenation":case"arithmetic_expansion":{let j=PU(w,_,z);if(typeof j!=="string")return j;Y.push(j);break}case"simple_expansion":{let j=HN8(w,z,!1);if(typeof j!=="string")return j;Y.push(j);break}case"file_redirect":{let j=KN4(w,_,z);if("kind"in j)return j;A.push(j);break}case"herestring_redirect":{let j=V9z(w,_,z);if(j)return j;break}default:return EH(w)}}let O=/\$[A-Za-z_]/.test(q.text)||q.text.includes(` |
| 1628 | `)){A=!0;break}z+=H,A=!0;break}let j=ym1(O,K,_);if(j)return j;z+=wN8,$=!0;break}case"simple_expansion":{let w=HN8(O,_,!0);if(typeof w!=="string")return w;if(w===Cr)$=!0;else A=!0;z+=w;break}case"arithmetic_expansion":{let w=Em1(O);if(w)return w;z+=O.text,A=!0;break}default:return EH(O)}}if($&&!A)return EH(q);if(!A&&!$&&q.text.length>2)return EH(q);return z}function Em1(q){for(let K of q.children){if(!K)continue;if(K.children.length===0){if(!y9z.test(K.text))return{kind:"too-complex",reason:`Arithmetic expansion references variable or non-literal: ${K.text}`,nodeType:"arithmetic_expansion"};continue}switch(K.type){case"binary_expression":case"unary_expression":case"ternary_expression":case"parenthesized_expression":{let _=Em1(K);if(_)return _;break}default:return EH(K)}}return null}function E9z(q){let K=null;for(let Y of q.children){if(!Y)continue;if(Y.type==="$("||Y.type===")")continue;if(Y.type==="redirected_statement"&&K===null)K=Y;else return null}if(!K)return null;let _=!1,z=null;for(let Y of K.children){if(!Y)continue;if(Y.type==="command"){let $=Y.children.filter((O)=>O);if($.length!==1)return null;let A=$[0];if(A?.type!=="command_name"||A.text!=="cat")return null;_=!0}else if(Y.type==="heredoc_redirect"){if(_N4(Y)!==null)return null;for(let $ of Y.children)if($?.type==="heredoc_body")z=$.text}else return null}if(!_||z===null)return null;if(Vm1.test(z))return"DANGEROUS";if(/\bsystem\s*\(/.test(z))return"DANGEROUS";return z}function km1(q,K,_){let z=null,Y="",$=!1;for(let A of q.children){if(!A)continue;if(A.type==="variable_name")z=A.text;else if(A.type==="="||A.type==="+="){$=A.type==="+=";continue}else if(A.type==="command_substitution"){let O=ym1(A,K,_);if(O)return O;Y=wN8}else if(A.type==="simple_expansion"){let O=HN8(A,_,!0);if(typeof O!=="string")return O;Y=O}else{let O=PU(A,K,_);if(typeof O!=="string")return O;Y=O}}if(z===null)return{kind:"too-complex",reason:"Variable assignment without name",nodeType:"variable_assignment"};if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(z))return{kind:"too-complex",reason:`Invalid variable name (bash treats as command): ${z}`,nodeType:"variable_assignment"};if(z==="IFS")return{kind:"too-complex",reason:"IFS assignment changes word-splitting — cannot model statically",nodeType:"variable_assignment"};if(z==="PS4"){if($)return{kind:"too-complex",reason:"PS4 += cannot be statically verified — combine into a single PS4= assignment",nodeType:"variable_assignment"};if(jN8(Y))return{kind:"too-complex",reason:"PS4 value derived from cmdsub/variable — runtime unknowable",nodeType:"variable_assignment"};if(!/^[A-Za-z0-9 _+:./=[\]-]*$/.test(Y.replace(/\$\{[A-Za-z_][A-Za-z0-9_]*\}/g,"")))return{kind:"too-complex",reason:"PS4 value outside safe charset — only ${VAR} refs and [A-Za-z0-9 _+:.=/[]-] allowed",nodeType:"variable_assignment"}}if(Y.includes("~"))return{kind:"too-complex",reason:"Tilde in assignment value — bash may expand at assignment time",nodeType:"variable_assignment"};return{name:z,value:Y,isAppend:$}}function HN8(q,K,_){let z=null,Y=!1;for(let A of q.children){if(A?.type==="variable_name"){z=A.text;break}if(A?.type==="special_variable_name"){z=A.text,Y=!0;break}}if(z===null)return EH(q);let $=K.get(z);if($!==void 0){if(jN8($)){if(!_)return EH(q);return Cr}if(!_){if($==="")return EH(q);if(O9z.test($))return EH(q)}return $}if(_){if(J9z.has(z))return Cr;if(Y&&(M9z.has(z)||/^[0-9]+$/.test(z)))return Cr}return EH(q)}function oV4(q,K){let _=q.get(K.name)??"",z=K.isAppend?_+K.value:K.value;q.set(K.name,jN8(z)?Cr:z)}function YN4(q){return q.slice(1,-1)}function EH(q){return{kind:"too-complex",reason:q.type==="ERROR"?"Parse error":sV4.has(q.type)?`Contains ${q.type}`:`Unhandled node type: ${q.type}`,nodeType:q.type}}function Lm1(q){for(let K of q){let _=K.argv;for(;;)if(_[0]==="time"||_[0]==="nohup")_=_.slice(1);else if(_[0]==="timeout"){let $=1;while($<_.length){let A=_[$];if(A==="--foreground"||A==="--preserve-status"||A==="--verbose")$++;else if(/^--(?:kill-after|signal)=[A-Za-z0-9_.+-]+$/.test(A))$++;else if((A==="--kill-after"||A==="--signal")&&_[$+1]&&/^[A-Za-z0-9_.+-]+$/.test(_[$+1]))$+=2;else if(A.startsWith("--"))return{ok:!1,reason:`timeout with ${A} flag cannot be statically analyzed`};else if(A==="-v")$++;else if((A==="-k"||A==="-s")&&_[$+1]&&/^[A-Za-z0-9_.+-]+$/.test(_[$+1]))$+=2;else if(/^-[ks][A-Za-z0-9_.+-]+$/.test(A))$++;else if(A.startsWith("-"))return{ok:!1,reason:`timeout with ${A} flag cannot be statically analyzed`};else break}if(_[$]&&/^\d+(?:\.\d+)?[smhd]?$/.test(_[$]))_=_.slice($+1);else if(_[$])return{ok:!1,reason:`timeout duration '${_[$]}' cannot be statically analyzed`};else break}else if(_[0]==="nice")if(_[1]==="-n"&&_[2]&&/^-?\d+$/.test(_[2]))_=_.slice(3);else if(_[1]&&/^-\d+$/.test(_[1]))_=_.slice(2);else if(_[1]&&/[$(`]/.test(_[1]))return{ok:!1,reason:`nice argument '${_[1]}' contains expansion — cannot statically determine wrapped command`};else _=_.slice(1);else if(_[0]==="env"){let $=1;while($<_.length){let A=_[$];if(A.includes("=")&&!A.startsWith("-"))$++;else if(A==="-i"||A==="-0"||A==="-v")$++;else if(A==="-u"&&_[$+1])$+=2;else if(A.startsWith("-"))return{ok:!1,reason:`env with ${A} flag cannot be statically analyzed`};else break}if($<_.length)_=_.slice($);else break}else if(_[0]==="stdbuf"){let $=1;while($<_.length){let A=_[$];if(w9z.test(A)&&_[$+1])$+=2;else if(j9z.test(A))$++;else if(H9z.test(A))$++;else if(A.startsWith("-"))return{ok:!1,reason:`stdbuf with ${A} flag cannot be statically analyzed`};else break}if($>1&&$<_.length)_=_.slice($);else break}else break;let z=_[0];if(z===void 0)continue;if(z==="")return{ok:!1,reason:"Empty command name — argv[0] may not reflect what bash runs"};if(z.includes(wN8)||z.includes(Cr))return{ok:!1,reason:"Command name is runtime-determined (placeholder argv[0])"};if(z.startsWith("-")||z.startsWith("|")||z.startsWith("&"))return{ok:!1,reason:"Command appears to be an incomplete fragment"};let Y=h9z[z];if(Y!==void 0)for(let $=1;$<_.length;$++){let A=_[$];if(Y.has(A)&&_[$+1]?.includes("["))return{ok:!1,reason:`'${z} ${A}' operand contains array subscript — bash evaluates $(cmd) in subscripts`};if(A.length>2&&A[0]==="-"&&A[1]!=="-"&&!A.includes("[")){for(let O of Y)if(O.length===2&&A.includes(O[1])){if(_[$+1]?.includes("["))return{ok:!1,reason:`'${z} ${O}' (combined in '${A}') operand contains array subscript — bash evaluates $(cmd) in subscripts`}}}for(let O of Y)if(O.length===2&&A.startsWith(O)&&A.length>2&&A.includes("["))return{ok:!1,reason:`'${z} ${O}' (fused) operand contains array subscript — bash evaluates $(cmd) in subscripts`}}if(z==="[[")for(let $=2;$<_.length;$++){if(!S9z.has(_[$]))continue;if(_[$-1]?.includes("[")||_[$+1]?.includes("["))return{ok:!1,reason:`'[[ ... ${_[$]} ... ]]' operand contains array subscript — bash arithmetically evaluates $(cmd) in subscripts`}}if(C9z.has(z)){let $=!1;for(let A=1;A<_.length;A++){let O=_[A];if($){$=!1;continue}if(O[0]==="-"){if(z==="read"){if(aV4.has(O))$=!0;else if(O.length>2&&O[1]!=="-"){for(let w=1;w<O.length;w++)if(aV4.has("-"+O[w])){if(w===O.length-1)$=!0;break}}}continue}if(O.includes("["))return{ok:!1,reason:`'${z}' positional NAME '${O}' contains array subscript — bash evaluates $(cmd) in subscripts`}}}if(Pm1.has(z))return{ok:!1,reason:`Shell keyword '${z}' as command name — tree-sitter mis-parse`};for(let $ of K.argv)if($.includes(` |