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

Function dN4

package/cli.js:1666–1666  ·  view source on GitHub ↗
(q,K=!1)

Source from the content-addressed store, hash-verified

1664`){B=w6-S;break}let s=0;for(let a=w6-1;a>=S&&q[a]==="\\";a--)s++;if(s%2===1)continue;if(o==="'")j6=!0;else if(o==='"')G6=!0}}if(B===-1)continue;let p=q.slice(S,S+B),C=0;for(let j6=p.length-1;j6>=0;j6--)if(p[j6]==="\\")C++;else break;if(C%2===1)continue;let g=S+B,U=q.slice(g+1).split(`
1665`),c=-1;for(let j6=0;j6<U.length;j6++){let G6=U[j6];if(V){if(G6.replace(/^\t*/,"")===E){c=j6;break}}else if(G6===E){c=j6;break}let w6=V?G6.replace(/^\t*/,""):G6;if(w6.length>E.length&&w6.startsWith(E)){let o=w6[E.length];if(/^[)}`|&;(<>]$/.test(o)){c=-1;break}}}if(K?.quotedOnly&&!I){let j6;if(c===-1)j6=q.length;else{let w6=U.slice(0,c+1).join(`
1666`).length;j6=g+1+w6}A.push({contentStartIndex:g,contentEndIndex:j6});continue}if(c===-1)continue;let t=U.slice(0,c+1).join(`
1667`).length,q6=g+1+t,e=!1;for(let j6 of A)if(g<j6.contentEndIndex&&j6.contentStartIndex<q6){e=!0;break}if(e)continue;let i=q.slice(Z,S),$6=q.slice(g,q6),M6=i+$6;$.push({fullText:M6,delimiter:E,operatorStartIndex:Z,operatorEndIndex:S,contentStartIndex:g,contentEndIndex:q6})}if($.length===0)return{processedCommand:q,heredocs:_};let W=$.filter((Z,T,v)=>{for(let V of v){if(Z===V)continue;if(Z.operatorStartIndex>V.contentStartIndex&&Z.operatorStartIndex<V.contentEndIndex)return!1}return!0});if(W.length===0)return{processedCommand:q,heredocs:_};if(new Set(W.map((Z)=>Z.contentStartIndex)).size<W.length)return{processedCommand:q,heredocs:_};W.sort((Z,T)=>T.contentEndIndex-Z.contentEndIndex);let f=Z_z(),G=q;return W.forEach((Z,T)=>{let v=W.length-1-T,V=`${D_z}${v}_${f}${f_z}`;_.set(V,Z),G=G.slice(0,Z.operatorStartIndex)+V+G.slice(Z.operatorEndIndex,Z.contentStartIndex)+G.slice(Z.contentEndIndex)}),{processedCommand:G,heredocs:_}}function T_z(q,K){let _=q;for(let[z,Y]of K)_=_.replaceAll(z,Y.fullText);return _}function Qm1(q,K){if(K.size===0)return q;return q.map((_)=>T_z(_,K))}var D_z="__HEREDOC_",f_z="__",G_z;var dm1=y(()=>{G_z=/(?<!<)<<(?!<)(-)?[ \t]*(?:(['"])(\\?\w+)\2|\\?(\w+))/});function cm1(q,K,_){switch(q.type){case"raw_string":K.raw.push([q.startIndex,q.endIndex]);return;case"ansi_c_string":K.ansiC.push([q.startIndex,q.endIndex]);return;case"string":if(!_)K.double.push([q.startIndex,q.endIndex]);for(let z of q.children)if(z)cm1(z,K,!0);return;case"heredoc_redirect":{let z=!1;for(let Y of q.children)if(Y&&Y.type==="heredoc_start"){let $=Y.text[0];z=$==="'"||$==='"'||$==="\\";break}if(z){K.heredoc.push([q.startIndex,q.endIndex]);return}break}}for(let z of q.children)if(z)cm1(z,K,_)}function v_z(q){let K=new Set;for(let[_,z]of q)for(let Y=_;Y<z;Y++)K.add(Y);return K}function BN4(q){return q.filter((K,_)=>!q.some((z,Y)=>Y!==_&&z[0]<=K[0]&&z[1]>=K[1]&&(z[0]<K[0]||z[1]>K[1])))}function k_z(q,K){if(K.length===0)return q;let _=BN4(K).sort((Y,$)=>$[0]-Y[0]),z=q;for(let[Y,$]of _)z=z.slice(0,Y)+z.slice($);return z}function V_z(q,K){if(K.length===0)return q;let _=BN4(K).sort((Y,$)=>$[0]-Y[0]),z=q;for(let[Y,$,A,O]of _)z=z.slice(0,Y)+A+O+z.slice($);return z}function N_z(q,K){let _={raw:[],ansiC:[],double:[],heredoc:[]};cm1(q,_,!1);let{raw:z,ansiC:Y,double:$,heredoc:A}=_,O=[...z,...Y,...$,...A],w=v_z([...z,...Y,...A]),j=new Set;for(let[P,W]of $)j.add(P),j.add(W-1);let H="";for(let P=0;P<K.length;P++){if(w.has(P))continue;if(j.has(P))continue;H+=K[P]}let J=k_z(K,O),M=[];for(let[P,W]of z)M.push([P,W,"'","'"]);for(let[P,W]of Y)M.push([P,W,"$'","'"]);for(let[P,W]of $)M.push([P,W,'"','"']);for(let[P,W]of A)M.push([P,W,"",""]);let X=V_z(K,M);return{withDoubleQuotes:H,fullyUnquoted:J,unquotedKeepQuoteChars:X}}function y_z(q,K){let _=q,z=[],Y=[],$=!1,A=!1,O=!1;function w(j){for(let H of j.children){if(!H)continue;if(H.type==="list")for(let J of H.children){if(!J)continue;if(J.type==="&&"||J.type==="||")z.push(J.type);else if(J.type==="list"||J.type==="redirected_statement")w({...j,children:[J]});else if(J.type==="pipeline")O=!0,Y.push(J.text);else if(J.type==="subshell")$=!0,Y.push(J.text);else if(J.type==="compound_statement")A=!0,Y.push(J.text);else Y.push(J.text)}else if(H.type===";")z.push(";");else if(H.type==="pipeline")O=!0,Y.push(H.text);else if(H.type==="subshell")$=!0,Y.push(H.text);else if(H.type==="compound_statement")A=!0,Y.push(H.text);else if(H.type==="command"||H.type==="declaration_command"||H.type==="variable_assignment")Y.push(H.text);else if(H.type==="redirected_statement"){let J=!1;for(let M of H.children){if(!M||M.type==="file_redirect")continue;J=!0,w({...H,children:[M]})}if(!J)Y.push(H.text)}else if(H.type==="negated_command")Y.push(H.text),w(H);else if(H.type==="if_statement"||H.type==="while_statement"||H.type==="for_statement"||H.type==="case_statement"||H.type==="function_definition")Y.push(H.text),w(H)}}if(w(_),Y.length===0)Y.push(K);return{hasCompoundOperators:z.length>0,hasPipeline:O,hasSubshell:$,hasCommandGroup:A,operators:z,segments:Y}}function E_z(q){let K=q;function _(z){if(z.type===";"||z.type==="&&"||z.type==="||")return!0;if(z.type==="list")return!0;for(let Y of z.children)if(Y&&_(Y))return!0;return!1}return _(K)}function L_z(q){let K=q,_=!1,z=!1,Y=!1,$=!1,A=!1;function O(w){switch(w.type){case"command_substitution":_=!0;break;case"process_substitution":z=!0;break;case"expansion":Y=!0;break;case"heredoc_redirect":$=!0;break;case"comment":A=!0;break}for(let j of w.children)if(j)O(j)}return O(K),{hasCommandSubstitution:_,hasProcessSubstitution:z,hasParameterExpansion:Y,hasHeredoc:$,hasComment:A}}function gN4(q,K){return{quoteContext:N_z(q,K),compoundStructure:y_z(q,K),hasActualOperatorNodes:E_z(q),dangerousPatterns:L_z(q)}}class UN4{originalCommand;constructor(q){this.originalCommand=q}toString(){return this.originalCommand}getPipeSegments(){try{let q=LV6(this.originalCommand),K=[],_=[];for(let z of q)if(z==="|"){if(_.length>0)K.push(_.join(" ")),_=[]}else _.push(z);if(_.length>0)K.push(_.join(" "));return K.length>0?K:[this.originalCommand]}catch{return[this.originalCommand]}}withoutOutputRedirections(){if(!this.originalCommand.includes(">"))return this.originalCommand;let{commandWithoutRedirections:q,redirections:K}=SL(this.originalCommand);return K.length>0?q:this.originalCommand}getOutputRedirections(){let{redirections:q}=SL(this.originalCommand);return q}getTreeSitterAnalysis(){return null}}function lm1(q,K){K(q);for(let _ of q.children)lm1(_,K)}function R_z(q){let K=[];return lm1(q,(_)=>{if(_.type==="pipeline"){for(let z of _.children)if(z.type==="|")K.push(z.startIndex)}}),K.sort((_,z)=>_-z)}function h_z(q){let K=[];return lm1(q,(_)=>{if(_.type==="file_redirect"){let z=_.children,Y=z.find((A)=>A.type===">"||A.type===">>"),$=z.find((A)=>A.type==="word");if(Y&&$)K.push({startIndex:_.startIndex,endIndex:_.endIndex,target:$.text,operator:Y.type})}}),K}class QN4{originalCommand;commandBytes;pipePositions;redirectionNodes;treeSitterAnalysis;constructor(q,K,_,z){this.originalCommand=q,this.commandBytes=Buffer.from(q,"utf8"),this.pipePositions=K,this.redirectionNodes=_,this.treeSitterAnalysis=z}toString(){return this.originalCommand}getPipeSegments(){if(this.pipePositions.length===0)return[this.originalCommand];let q=[],K=0;for(let z of this.pipePositions){let Y=this.commandBytes.subarray(K,z).toString("utf8").trim();if(Y)q.push(Y);K=z+1}let _=this.commandBytes.subarray(K).toString("utf8").trim();if(_)q.push(_);return q}withoutOutputRedirections(){if(this.redirectionNodes.length===0)return this.originalCommand;let q=[...this.redirectionNodes].sort((_,z)=>z.startIndex-_.startIndex),K=this.commandBytes;for(let _ of q)K=Buffer.concat([K.subarray(0,_.startIndex),K.subarray(_.endIndex)]);return K.toString("utf8").trim().replace(/\s+/g," ")}getOutputRedirections(){return this.redirectionNodes.map(({target:q,operator:K})=>({target:q,operator:K}))}getTreeSitterAnalysis(){return this.treeSitterAnalysis}}function nm1(q,K){let _=R_z(K),z=h_z(K),Y=gN4(K,q);return new QN4(q,_,z,Y)}async function C_z(q){if(!q)return null;if(await S_z())try{let{parseCommand:_}=await Promise.resolve().then(() => (qw6(),Tm1)),z=await _(q);if(z)return nm1(q,z.rootNode)}catch{}return new UN4(q)}var S_z,FN4,kN8,Aw6;var im1=y(()=>{F4();SG();S_z=_1(async()=>{try{let{parseCommand:q}=await Promise.resolve().then(() => (qw6(),Tm1));return await q("echo test")!==null}catch{return!1}});Aw6={parse(q){if(q===FN4&&kN8!==void 0)return kN8;return FN4=q,kN8=C_z(q),kN8}}});function dN4(q,K=!1){let _="",z="",Y="",$=!1,A=!1,O=!1;for(let w=0;w<q.length;w++){let j=q[w];if(O){if(O=!1,!$)_+=j;if(!$&&!A)z+=j;if(!$&&!A)Y+=j;continue}if(j==="\\"&&!$){if(O=!0,!$)_+=j;if(!$&&!A)z+=j;if(!$&&!A)Y+=j;continue}if(j==="'"&&!A){$=!$,Y+=j;continue}if(j==='"'&&!$){if(A=!A,Y+=j,!K)continue}if(!$)_+=j;if(!$&&!A)z+=j;if(!$&&!A)Y+=j}return{withDoubleQuotes:_,fullyUnquoted:z,unquotedKeepQuoteChars:Y}}function cN4(q){return q.replace(/\s+2\s*>&\s*1(?=\s|$)/g,"").replace(/[012]?\s*>\s*\/dev\/null(?=\s|$)/g,"").replace(/\s*<\s*\/dev\/null(?=\s|$)/g,"")}function I_z(q,K){if(K.length!==1)throw Error("hasUnescapedChar only works with single characters");let _=0;while(_<q.length){if(q[_]==="\\"&&_+1<q.length){_+=2;continue}if(q[_]===K)return!0;_++}return!1}function lN4(q){if(!q.originalCommand.trim())return{behavior:"allow",updatedInput:{command:q.originalCommand},decisionReason:{type:"other",reason:"Empty command is safe"}};return{behavior:"passthrough",message:"Command is not empty"}}function nN4(q){let{originalCommand:K}=q,_=K.trim();if(/^\s*\t/.test(K))return d("tengu_bash_security_check_triggered",{checkId:t9.INCOMPLETE_COMMANDS,subId:1}),{behavior:"ask",message:"Command appears to be an incomplete fragment (starts with tab)"};if(_.startsWith("-"))return d("tengu_bash_security_check_triggered",{checkId:t9.INCOMPLETE_COMMANDS,subId:2}),{behavior:"ask",message:"Command appears to be an incomplete fragment (starts with flags)"};if(/^\s*(&&|\|\||;|>>?|<)/.test(K))return d("tengu_bash_security_check_triggered",{checkId:t9.INCOMPLETE_COMMANDS,subId:3}),{behavior:"ask",message:"Command appears to be a continuation line (starts with operator)"};return{behavior:"passthrough",message:"Command appears complete"}}function u_z(q){if(!rm1.test(q))return!1;let K=/\$\(cat[ \t]*<<(-?)[ \t]*(?:'+([A-Za-z_]\w*)'+|\\([A-Za-z_]\w*))/g,_,z=[];while((_=K.exec(q))!==null){let w=_[2]||_[3];if(w)z.push({start:_.index,operatorEnd:_.index+_[0].length,delimiter:w,isDash:_[1]==="-"})}if(z.length===0)return!1;let Y=[];for(let{start:w,operatorEnd:j,delimiter:H,isDash:J}of z){let M=q.slice(j),X=M.indexOf(`
1668`);if(X===-1)return!1;let P=M.slice(0,X);if(!/^[ \t]*$/.test(P))return!1;let W=j+X+1,f=q.slice(W).split(`
1669`),G=-1,Z=-1,T=-1;for(let V=0;V<f.length;V++){let E=f[V],S=J?E.replace(/^\t*/,""):E;if(S===H){G=V;let R=f[V+1];if(R===void 0)return!1;let x=R.match(/^([ \t]*)\)/);if(!x)return!1;Z=V+1,T=x[1].length;break}if(S.startsWith(H)){let R=S.slice(H.length),x=R.match(/^([ \t]*)\)/);if(x){G=V,Z=V,T=(J?E.match(/^\t*/)?.[0]??"":"").length+H.length+x[1].length;break}if(/^[)}`|&;(<>]/.test(R))return!1}}if(G===-1)return!1;let v=W;for(let V=0;V<Z;V++)v+=f[V].length+1;v+=T+1,Y.push({start:w,end:v})}for(let w of Y)for(let j of Y){if(j===w)continue;if(j.start>w.start&&j.start<w.end)return!1}let $=[...Y].sort((w,j)=>j.start-w.start),A=q;for(let{start:w,end:j}of $)A=A.slice(0,w)+A.slice(j);if(A.trim().length>0){let w=Math.min(...Y.map((H)=>H.start));if(q.slice(0,w).trim().length===0)return!1}if(!/^[a-zA-Z0-9 \t"'.\-/_@=,:+~]*$/.test(A))return!1;if(Po6(A).behavior!=="passthrough")return!1;return!0}function iN4(q){if(!rm1.test(q))return null;let K=/\$\(cat[ \t]*<<(-?)[ \t]*(?:'+([A-Za-z_]\w*)'+|\\([A-Za-z_]\w*))/g,_=q,z=!1,Y,$=[];while((Y=K.exec(q))!==null){if(Y.index>0&&q[Y.index-1]==="\\")continue;let A=Y[2]||Y[3];if(!A)continue;let O=Y[1]==="-",w=Y.index+Y[0].length,j=q.slice(w),H=j.indexOf(`

Callers 2

Po6Function · 0.85
yN8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected