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

Function Yp8

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

Source from the content-addressed store, hash-verified

4091`)){let z=q.split(`
4092`)[0].trim();if(z)return Jo6(R4.name,z)}let _=Kp8(q);if(_)return Jo6(R4.name,_);return DN8(R4.name,q)}function D5Y(q){if(!q.includes("<<"))return null;let K=q.indexOf("<<");if(K<=0)return null;let _=q.substring(0,K).trim();if(!_)return null;let z=Kp8(_);if(z)return z;let Y=_.split(/\s+/).filter(Boolean),$=0;while($<Y.length&&o67.test(Y[$])){let A=Y[$].split("=")[0],O=!1;if(!_p8.has(A))return null;$++}if($>=Y.length)return null;return Y.slice($,$+2).join(" ")||null}function bPK(q){return Jo6(R4.name,q)}function s88(q,K){return lv(q,K)}function i67(q){let _=q.split(`
4093`).filter((z)=>{let Y=z.trim();return Y!==""&&!Y.startsWith("#")});if(_.length===0)return q;return _.join(`
4094`)}function Ir(q){let K=[/^timeout[ \t]+(?:(?:--(?:foreground|preserve-status|verbose)|--(?:kill-after|signal)=[A-Za-z0-9_.+-]+|--(?:kill-after|signal)[ \t]+[A-Za-z0-9_.+-]+|-v|-[ks][ \t]+[A-Za-z0-9_.+-]+|-[ks][A-Za-z0-9_.+-]+)[ \t]+)*(?:--[ \t]+)?\d+(?:\.\d+)?[smhd]?[ \t]+/,/^time[ \t]+(?:--[ \t]+)?/,/^nice(?:[ \t]+-n[ \t]+-?\d+|[ \t]+-\d+)?[ \t]+(?:--[ \t]+)?/,/^stdbuf(?:[ \t]+-[ioe][LN0-9]+)+[ \t]+(?:--[ \t]+)?/,/^nohup[ \t]+(?:--[ \t]+)?/],_=/^([A-Za-z_][A-Za-z0-9_]*)=([A-Za-z0-9_./:-]+)[ \t]+/,z=q,Y="";while(z!==Y){Y=z,z=i67(z);let $=z.match(_);if($){let A=$[1],O=!1;if(_p8.has(A))z=z.replace(_,"")}}Y="";while(z!==Y){Y=z,z=i67(z);for(let $ of K)z=z.replace($,"")}return z.trim()}function s67(q,K){let _=/^([A-Za-z_][A-Za-z0-9_]*(?:\[[^\]]*\])?)\+?=(?:'[^'\n\r]*'|"(?:\\.|[^"$`\\\n\r])*"|\\.|[^ \t\n\r$`;|&()<>\\\\'"])*[ \t]+/,z=q,Y="";while(z!==Y){Y=z,z=i67(z);let $=z.match(_);if(!$)continue;if(K?.test($[1]))break;z=z.slice($[0].length)}return z.trim()}function n67(q,K,_,{stripAllEnvVars:z=!1,skipCompoundCheck:Y=!1}={}){let $=q.command.trim(),A=SL($).commandWithoutRedirections,w=(_==="exact"?[$,A]:[A]).flatMap((H)=>{let J=Ir(H);return J!==H?[H,J]:[H]});if(z){let H=new Set(w),J=0;while(J<w.length){let M=w.length;for(let X=J;X<M;X++){let P=w[X];if(!P)continue;let W=s67(P);if(!H.has(W))w.push(W),H.add(W);let D=Ir(P);if(!H.has(D))w.push(D),H.add(D)}J=M}}let j=new Map;if(_==="prefix"&&!Y){for(let H of w)if(!j.has(H))j.set(H,q18(H).length>1)}return Array.from(K.entries()).filter(([H])=>{let J=a67(H);return w.some((M)=>{switch(J.type){case"exact":return J.command===M;case"prefix":switch(_){case"exact":return J.prefix===M;case"prefix":{if(j.get(M))return!1;if(M===J.prefix)return!0;if(M.startsWith(J.prefix+" "))return!0;let X="xargs "+J.prefix;if(M===X)return!0;return M.startsWith(X+" ")}}break;case"wildcard":if(_==="exact")return!1;if(j.get(M))return!1;return s88(J.pattern,M)}})}).map(([,H])=>H)}function nR6(q,K,_,{skipCompoundCheck:z=!1}={}){let Y=sm(K,R4,"deny"),$=n67(q,Y,_,{stripAllEnvVars:!0,skipCompoundCheck:!0}),A=sm(K,R4,"ask"),O=n67(q,A,_,{stripAllEnvVars:!0,skipCompoundCheck:!0}),w=sm(K,R4,"allow"),j=n67(q,w,_,{skipCompoundCheck:z});return{matchingDenyRules:$,matchingAskRules:O,matchingAllowRules:j}}async function SPK(q,K,_,z,Y){let $=K18(q,K);if($.behavior!=="passthrough")return $;let A=IPK(q,K,z);if(A.behavior==="deny"||A.behavior==="ask")return A;if(!Y&&!i6(process.env.CLAUDE_CODE_DISABLE_COMMAND_INJECTION_CHECK)){let w=await t88(q.command);if(w.behavior!=="passthrough"){let j={type:"other",reason:w.behavior==="ask"&&w.message?w.message:"This command contains patterns that could pose security risks and requires approval"};return{behavior:"ask",message:f_(R4.name,j),decisionReason:j,suggestions:[]}}}if(A.behavior==="allow")return A;let O=_?.commandPrefix?bPK(_.commandPrefix):lR6(q.command);return{...A,suggestions:O}}function f5Y(q,K){let _=q.command.trim(),{matchingDenyRules:z,matchingAskRules:Y}=nR6(q,K,"prefix");if(z[0]!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${_} has been denied.`,decisionReason:{type:"rule",rule:z[0]}};let $=q18(_);if($.length>1){let A;for(let O of $){let w=nR6({command:O},K,"prefix");if(w.matchingDenyRules[0]!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${_} has been denied.`,decisionReason:{type:"rule",rule:w.matchingDenyRules[0]}};A??=w.matchingAskRules[0]}if(A)return{behavior:"ask",message:f_(R4.name),decisionReason:{type:"rule",rule:A}}}if(Y[0]!==void 0)return{behavior:"ask",message:f_(R4.name),decisionReason:{type:"rule",rule:Y[0]}};return{behavior:"allow",updatedInput:q,decisionReason:{type:"other",reason:"Auto-allowed with sandbox (autoAllowBashIfSandboxed enabled)"}}}function Z5Y(q,K,_,z){let Y=[],$=[];for(let A=0;A<q.length;A++){let O=q[A];if(O===`cd ${_}`||O===`cd ${z}`)continue;Y.push(O),$.push(K?.[A])}return{subcommands:Y,astCommandsByIdx:$}}function uPK(q,K){let _=K18(q,K);if(_.behavior!=="passthrough")return _;let z=nR6(q,K,"prefix").matchingDenyRules[0];if(z!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${q.command} has been denied.`,decisionReason:{type:"rule",rule:z}};return null}function G5Y(q,K,_){let z=uPK(q,K);if(z!==null)return z;for(let Y of _){let $=nR6({...q,command:Y.text},K,"prefix").matchingDenyRules[0];if($!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${q.command} has been denied.`,decisionReason:{type:"rule",rule:$}}}return null}function pPK(q,K,_,z){if(!Jq6())return!1;if(K.mode==="auto")return!1;if(K.mode==="bypassPermissions")return!1;let Y=MN8(K);if(Y.length===0)return!1;let $=Z8(),A=XN8(q,$,Y,"allow",_,z);return A.catch(()=>{}),mPK.set(q,A),!0}function zp8(){mPK.clear()}async function l67(q,K,_=e88){let z=K.getAppState(),Y=i6(process.env.CLAUDE_CODE_DISABLE_COMMAND_INJECTION_CHECK),$=g8("tengu_birch_trellis",!0),A=Y?null:!$?null:await Ao6(q.command),O=A?Nm1(q.command,A):{kind:"parse-unavailable"},w=null,j,H,J;{let U=O.kind!=="parse-unavailable",c=!1,K6=!1,t=!1;if(U){c=O.kind==="too-complex",K6=O.kind==="simple"&&!Lm1(O.commands).ok;let q6=O.kind==="simple"?O.commands.map((i)=>i.text):void 0,e=q18(q.command);J=e,t=q6!==void 0&&(q6.length!==e.length||q6.some((i,$6)=>i!==e[$6]))}d("tengu_tree_sitter_shadow",{available:U,astTooComplex:c,astSemanticFail:K6,subsDiffer:t,injectionCheckDisabled:Y,killswitchOff:!$,cmdOverLength:q.command.length>1e4}),O={kind:"parse-unavailable"},A=null}if(O.kind==="too-complex"){let U=uPK(q,z.toolPermissionContext);if(U!==null)return U;let c={type:"other",reason:O.reason};return d("tengu_bash_ast_too_complex",{nodeTypeId:tV4(O.nodeType)}),{behavior:"ask",decisionReason:c,message:f_(R4.name,c),suggestions:[],...{}}}if(O.kind==="simple"){let U=Lm1(O.commands);if(!U.ok){let c=G5Y(q,z.toolPermissionContext,O.commands);if(c!==null)return c;let K6={type:"other",reason:U.reason};return{behavior:"ask",decisionReason:K6,message:f_(R4.name,K6),suggestions:[]}}w=O.commands.map((c)=>c.text),j=O.commands.flatMap((c)=>c.redirects),H=O.commands}if(O.kind==="parse-unavailable"){N("bashToolHasPermission: tree-sitter unavailable, using legacy shell-quote path");let U=o$(q.command);if(!U.success){let c={type:"other",reason:`Command contains malformed syntax that cannot be parsed: ${U.error}`};return{behavior:"ask",decisionReason:c,message:f_(R4.name,c)}}}if(M7.isSandboxingEnabled()&&M7.isAutoAllowBashIfSandboxedEnabled()&&Gb(q)){let U=f5Y(q,z.toolPermissionContext);if(U.behavior!=="passthrough")return U}let M=K18(q,z.toolPermissionContext);if(M.behavior==="deny")return M;if(Jq6()&&z.toolPermissionContext.mode!=="auto"){let U=ON4(z.toolPermissionContext),c=wN4(z.toolPermissionContext),K6=U.length>0,t=c.length>0;if(K6||t){let[q6,e]=await Promise.all([K6?XN8(q.command,Z8(),U,"deny",K.abortController.signal,K.options.isNonInteractiveSession):null,t?XN8(q.command,Z8(),c,"ask",K.abortController.signal,K.options.isNonInteractiveSession):null]);if(K.abortController.signal.aborted)throw new Uz;if(q6)hPK(q.command,"deny",U,q6);if(e)hPK(q.command,"ask",c,e);if(q6?.matches&&q6.confidence==="high")return{behavior:"deny",message:`Denied by Bash prompt rule: "${q6.matchedDescription}"`,decisionReason:{type:"other",reason:`Denied by Bash prompt rule: "${q6.matchedDescription}"`}};if(e?.matches&&e.confidence==="high"){let i;if(_===e88)i=lR6(q.command);else{let $6=await _(q.command,K.abortController.signal,K.options.isNonInteractiveSession);if(K.abortController.signal.aborted)throw new Uz;i=$6?.commandPrefix?bPK($6.commandPrefix):lR6(q.command)}return{behavior:"ask",message:f_(R4.name),decisionReason:{type:"other",reason:`Required by Bash prompt rule: "${e.matchedDescription}"`},suggestions:i,...{}}}}}let X=await VPK(q,(U)=>l67(U,K,_),{isNormalizedCdCommand:r67,isNormalizedGitCommand:SN8},A);if(X.behavior!=="passthrough"){if(X.behavior==="allow"){let U=w===null?await t88(q.command):null;if(U!==null&&U.behavior!=="passthrough"&&U.behavior!=="allow")return z=K.getAppState(),{behavior:"ask",message:f_(R4.name,{type:"other",reason:U.message??"Command contains patterns that require approval"}),decisionReason:{type:"other",reason:U.message??"Command contains patterns that require approval"},...{}};z=K.getAppState();let c=RN8(q,Z8(),z.toolPermissionContext,ko6(q.command),j,H);if(c.behavior!=="passthrough")return c}if(X.behavior==="ask")return z=K.getAppState(),{...X,...{}};return X}if(w===null&&!i6(process.env.CLAUDE_CODE_DISABLE_COMMAND_INJECTION_CHECK)){let U=await t88(q.command);if(U.behavior==="ask"&&U.isBashSecurityCheckForMisparsing){let c=iN4(q.command),K6=c!==null?await t88(c):null;if(c===null||K6?.behavior==="ask"&&K6.isBashSecurityCheckForMisparsing){z=K.getAppState();let t=K18(q,z.toolPermissionContext);if(t.behavior==="allow")return t;let q6={type:"other",reason:U.message};return{behavior:"ask",message:f_(R4.name,q6),decisionReason:q6,suggestions:[],...{}}}}}let P=Z8(),W=Z1()==="windows"?ff(P):P,D=w??J??q18(q.command),{subcommands:f,astCommandsByIdx:G}=Z5Y(D,H,P,W);if(w===null&&f.length>RPK){N(`bashPermissions: ${f.length} subcommands exceeds cap (${RPK}) — returning ask`,{level:"debug"});let U={type:"other",reason:`Command splits into ${f.length} subcommands, too many to safety-check individually`};return{behavior:"ask",message:f_(R4.name,U),decisionReason:U}}let Z=f.filter((U)=>r67(U));if(Z.length>1){let U={type:"other",reason:"Multiple directory changes in one command require approval for clarity"};return{behavior:"ask",decisionReason:U,message:f_(R4.name,U)}}let T=Z.length>0;if(T){if(f.some((c)=>SN8(c.trim()))){let c={type:"other",reason:"Compound commands with cd and git require approval to prevent bare repository attacks"};return{behavior:"ask",decisionReason:c,message:f_(R4.name,c)}}}z=K.getAppState();let v=f.map((U,c)=>IPK({command:U},z.toolPermissionContext,T,G[c]));if(v.find((U)=>U.behavior==="deny")!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${q.command} has been denied.`,decisionReason:{type:"subcommandResults",reasons:new Map(v.map((U,c)=>[f[c],U]))}};let E=RN8(q,Z8(),z.toolPermissionContext,T,j,H);if(E.behavior==="deny")return E;let S=v.find((U)=>U.behavior==="ask"),R=$7(v,(U)=>U.behavior!=="allow");if(E.behavior==="ask"&&S===void 0)return E;if(S!==void 0&&R===1)return{...S,...{}};if(M.behavior==="allow")return M;let x=!1;if(w===null&&!i6(process.env.CLAUDE_CODE_DISABLE_COMMAND_INJECTION_CHECK)){let U=0,c=()=>{U++};if(x=(await Promise.all(f.map((t)=>t88(t,c)))).some((t)=>t.behavior!=="passthrough"),U>0)d("tengu_tree_sitter_security_divergence",{quoteContextDivergence:!0,count:U})}if(v.every((U)=>U.behavior==="allow")&&!x)return{behavior:"allow",updatedInput:q,decisionReason:{type:"subcommandResults",reasons:new Map(v.map((U,c)=>[f[c],U]))}};let I=null;if(_!==e88){if(I=await _(q.command,K.abortController.signal,K.options.isNonInteractiveSession),K.abortController.signal.aborted)throw new Uz}if(z=K.getAppState(),f.length===1){let U=await SPK({command:f[0]},z.toolPermissionContext,I,T,w!==null);if(U.behavior==="ask"||U.behavior==="passthrough")return{...U,...{}};return U}let B=new Map;for(let U of f)B.set(U,await SPK({...q,command:U},z.toolPermissionContext,I?.subcommandPrefixes.get(U),T,w!==null));if(f.every((U)=>{return B.get(U)?.behavior==="allow"}))return{behavior:"allow",updatedInput:q,decisionReason:{type:"subcommandResults",reasons:B}};let p=new Map;for(let[U,c]of B)if(c.behavior==="ask"||c.behavior==="passthrough"){let K6="suggestions"in c?c.suggestions:void 0,t=DU(K6);for(let q6 of t){let e=G9(q6);p.set(e,q6)}if(c.behavior==="ask"&&t.length===0&&c.decisionReason?.type!=="rule")for(let q6 of DU(lR6(U))){let e=G9(q6);p.set(e,q6)}}let C={type:"subcommandResults",reasons:B},g=Array.from(p.values()).slice(0,P5Y),F=g.length>0?[{type:"addRules",rules:g,behavior:"allow",destination:"localSettings"}]:void 0;return{behavior:S!==void 0?"ask":"passthrough",message:f_(R4.name,C),decisionReason:C,suggestions:F,...{}}}function SN8(q){if(q.startsWith("git ")||q==="git")return!0;let K=Ir(q),_=o$(K);if(_.success&&_.tokens.length>0){if(_.tokens[0]==="git")return!0;if(_.tokens[0]==="xargs"&&_.tokens.includes("git"))return!0;return!1}return/^git(?:\s|$)/.test(K)}function r67(q){let K=Ir(q),_=o$(K);if(_.success&&_.tokens.length>0){let z=_.tokens[0];return z==="cd"||z==="pushd"||z==="popd"}return/^(?:cd|pushd|popd)(?:\s|$)/.test(K)}function ko6(q){return q18(q).some((K)=>r67(K.trim()))}var t88,q18,o67,RPK=50,P5Y=5,W5Y,kPK,a67,_p8,xPK,K18=(q,K)=>{let _=q.command.trim(),{matchingDenyRules:z,matchingAskRules:Y,matchingAllowRules:$}=nR6(q,K,"exact");if(z[0]!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${_} has been denied.`,decisionReason:{type:"rule",rule:z[0]}};if(Y[0]!==void 0)return{behavior:"ask",message:f_(R4.name),decisionReason:{type:"rule",rule:Y[0]}};if($[0]!==void 0)return{behavior:"allow",updatedInput:q,decisionReason:{type:"rule",rule:$[0]}};let A={type:"other",reason:"This command requires approval"};return{behavior:"passthrough",message:f_(R4.name,A),decisionReason:A,suggestions:lR6(_)}},IPK=(q,K,_,z)=>{let Y=q.command.trim(),$=K18(q,K);if($.behavior==="deny"||$.behavior==="ask")return $;let{matchingDenyRules:A,matchingAskRules:O,matchingAllowRules:w}=nR6(q,K,"prefix",{skipCompoundCheck:z!==void 0});if(A[0]!==void 0)return{behavior:"deny",message:`Permission to use ${R4.name} with command ${Y} has been denied.`,decisionReason:{type:"rule",rule:A[0]}};if(O[0]!==void 0)return{behavior:"ask",message:f_(R4.name),decisionReason:{type:"rule",rule:O[0]}};let j=RN8(q,Z8(),K,_,z?.redirects,z?[z]:void 0);if(j.behavior!=="passthrough")return j;if($.behavior==="allow")return $;if(w[0]!==void 0)return{behavior:"allow",updatedInput:q,decisionReason:{type:"rule",rule:w[0]}};let H=Dy4(q,K);if(H.behavior!=="passthrough")return H;let J=EPK(q,K);if(J.behavior!=="passthrough")return J;if(R4.isReadOnly(q))return{behavior:"allow",updatedInput:q,decisionReason:{type:"other",reason:"Read-only command is allowed"}};let M={type:"other",reason:"This command requires approval"};return{behavior:"passthrough",message:f_(R4.name,M),decisionReason:M,suggestions:lR6(Y)}},mPK;var DN=y(()=>{LZ();o1();k8();Rm1();SG();qw6();NX();I7();_8();m8();y8();LH();Gf();Fj();br();vK();K$();l8();NB();p0();NPK();EN8();LPK();om1();LN8();IL6();t88=yN8,q18=F2,o67=/^[A-Za-z_]\w*=/;W5Y=new Set(["sh","bash","zsh","fish","csh","tcsh","ksh","dash","cmd","powershell","pwsh","env","xargs","nice","stdbuf","nohup","timeout","time","sudo","doas","pkexec"]);kPK=Ho6;a67=WN8,_p8=new Set(["GOEXPERIMENT","GOOS","GOARCH","CGO_ENABLED","GO111MODULE","RUST_BACKTRACE","RUST_LOG","NODE_ENV","PYTHONUNBUFFERED","PYTHONDONTWRITEBYTECODE","PYTEST_DISABLE_PLUGIN_AUTOLOAD","PYTEST_DEBUG","ANTHROPIC_API_KEY","LANG","LANGUAGE","LC_ALL","LC_CTYPE","LC_TIME","CHARSET","TERM","COLORTERM","NO_COLOR","FORCE_COLOR","TZ","LS_COLORS","LSCOLORS","GREP_COLOR","GREP_COLORS","GCC_COLORS","TIME_STYLE","BLOCK_SIZE","BLOCKSIZE"]);xPK=/^(LD_|DYLD_|PATH$)/;mPK=new Map});function FPK(){e67(),Ia=setInterval(()=>{if(c8("debug","session_keepalive_heartbeat",{refcount:xa}),i6(process.env.CLAUDE_CODE_REMOTE_SEND_KEEPALIVES))HH6?.()},gPK)}function T5Y(){if(e67(),HH6===null)return;_18=setTimeout(()=>{c8("info","session_idle_30s"),_18=null},gPK)}function e67(){if(_18!==null)clearTimeout(_18),_18=null}function Yp8(q){if(HH6=q,xa>0&&Ia===null)FPK()}function z18(){if(HH6=null,Ia!==null)clearInterval(Ia),Ia=null;e67()}function UPK(){if(i6(process.env.CLAUDE_CODE_REMOTE_SEND_KEEPALIVES))HH6?.()}function QPK(){return HH6!==null}function $p8(q){if(xa++,iR6.set(q,(iR6.get(q)??0)+1),xa===1){if(t67=Date.now(),HH6!==null&&Ia===null)FPK()}if(!BPK)BPK=!0,pq(async()=>{c8("info","session_activity_at_shutdown",{refcount:xa,active:Object.fromEntries(iR6),oldest_activity_ms:xa>0&&t67!==null?Date.now()-t67:null})})}function Ap8(q){if(xa>0)xa--;let K=(iR6.get(q)??0)-1;if(K>0)iR6.set(q,K);else iR6.delete(q);if(xa===0&&Ia!==null)clearInterval(Ia),Ia=null,T5Y()}var gPK=30000,HH6=null,xa=0,iR6,t67=null,Ia=null,_18=null,BPK=!1;var rR6=y(()=>{c9();oY();m8();iR6=new Map});var Y18;var q87=y(()=>{Y18=class Y18{returned;queue=[];readResolve;readReject;isDone=!1;hasError;started=!1;constructor(q){this.returned=q}[Symbol.asyncIterator](){if(this.started)throw Error("Stream can only be iterated once");return this.started=!0,this}next(){if(this.queue.length>0)return Promise.resolve({done:!1,value:this.queue.shift()});if(this.isDone)return Promise.resolve({done:!0,value:void 0});if(this.hasError)return Promise.reject(this.hasError);return new Promise((q,K)=>{this.readResolve=q,this.readReject=K})}enqueue(q){if(this.readResolve){let K=this.readResolve;this.readResolve=void 0,this.readReject=void 0,K({done:!1,value:q})}else this.queue.push(q)}done(){if(this.isDone=!0,this.readResolve){let q=this.readResolve;this.readResolve=void 0,this.readReject=void 0,q({done:!0,value:void 0})}}error(q){if(this.hasError=q,this.readReject){let K=this.readReject;this.readResolve=void 0,this.readReject=void 0,K(q)}}return(){if(this.isDone=!0,this.returned)this.returned();return Promise.resolve({done:!0,value:void 0})}}});function oR6(q){if(q instanceof Uz)return q.message||j0;if(!(q instanceof Error))return String(q);let _=K87(q).filter(Boolean).join(`
4095`).trim()||"Command failed with no output";if(_.length<=1e4)return _;let z=5000,Y=_.slice(0,z),$=_.slice(-z);return`${Y}
4096

Callers 2

handleOpenEventMethod · 0.85
initializeMethod · 0.85

Calls 1

FPKFunction · 0.85

Tested by

no test coverage detected