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

Function s88

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

Source from the content-addressed store, hash-verified

4089${K}`:q},mapToolResultToToolResultBlockParam({interrupted:q,stdout:K,stderr:_,isImage:z,backgroundTaskId:Y,backgroundedByUser:$,assistantAutoBackgrounded:A,structuredContent:O,persistedOutputPath:w,persistedOutputSize:j},H){if(O&&O.length>0)return{tool_use_id:H,type:"tool_result",content:O};if(z){let P=TI8(K,H);if(P)return P}let J=K;if(K)J=K.replace(/^(\s*\n)+/,""),J=J.trimEnd();if(w){let P=Xa6(J,WN6);J=DN6({filepath:w,originalSize:j??0,isJson:!1,preview:P.preview,hasMore:P.hasMore})}let M=_.trim();if(q){if(_)M+=fPK;M+="<error>Command was aborted before completion</error>"}let X="";if(Y){let P=sz(Y);if(A)X=`Command exceeded the assistant-mode blocking budget (${oKY/1000}s) and was moved to the background with ID: ${Y}. It is still running — you will be notified when it completes. Output is being written to: ${P}. In assistant mode, delegate long-running work to a subagent or use run_in_background to keep this conversation responsive.`;else if($)X=`Command was manually backgrounded by user with ID: ${Y}. Output is being written to: ${P}`;else X=`Command running in background with ID: ${Y}. Output is being written to: ${P}`}return{tool_use_id:H,type:"tool_result",content:[J,M,X].filter(Boolean).join(`
4090`),is_error:q}},async call(q,K,_,z,Y){if(q._simulatedSedEdit)return A5Y(q._simulatedSedEdit,K,z);let{abortController:$,getAppState:A,setAppState:O,setToolJSX:w}=K,j=new kp6,H="",J,M=0,X=!1,P,W=!K.agentId,D=!W;try{let B=O5Y({input:q,abortController:$,setAppState:K.setAppStateForTasks??O,setToolJSX:w,preventCwdChanges:D,isMainThread:W,toolUseId:K.toolUseId,agentId:K.agentId}),p;do if(p=await B.next(),!p.done&&Y){let F=p.value;Y({toolUseID:`bash-progress-${M++}`,data:{type:"bash_progress",output:F.output,fullOutput:F.fullOutput,elapsedTimeSeconds:F.elapsedTimeSeconds,totalLines:F.totalLines,totalBytes:F.totalBytes,taskId:F.taskId,timeoutMs:F.timeoutMs}})}while(!p.done);P=p.value,yI8(q.command,P.code,P.stdout);let C=P.interrupted&&$.signal.reason==="interrupt";if(j.append((P.stdout||"").trimEnd()+fPK),J=nXK(q.command,P.code,P.stdout||"",""),P.stdout&&P.stdout.includes(".git/index.lock': File exists"))d("tengu_git_index_lock_error",{});if(J.isError&&!C){if(P.code!==0)j.append(`Exit code ${P.code}`)}if(!D){let F=A();if(VI8(F.toolPermissionContext))H=kI8("")}let g=M7.annotateStderrWithSandboxFailures(q.command,P.stdout||"");if(P.preSpawnError)throw Error(P.preSpawnError);if(J.isError&&!C)throw new AE("",g,P.code,P.interrupted);X=P.interrupted}finally{if(w)w(null)}let f=j.toString(),G=67108864,Z,T;if(P.outputFilePath&&P.outputTaskId)try{let B=await nKY(P.outputFilePath);T=B.size,await Cw6();let p=Ma6(P.outputTaskId,!1);if(B.size>G)await iKY(P.outputFilePath,G);try{await rKY(P.outputFilePath,p)}catch{await lKY(P.outputFilePath,p)}Z=p}catch{}let v=q.command.split(" ")[0];d("tengu_bash_tool_command_executed",{command_type:v,stdout_length:f.length,stderr_length:0,exit_code:P.code,interrupted:X});let V=jh4(q.command);if(V)d("tengu_code_indexing_tool_used",{tool:V,source:"cli",success:P.code===0});let E=GI8(f),S=C68(E,q.command);if(E=S.stripped,W&&S.hints.length>0)for(let B of S.hints)x68(B);let R=U68(E),x=E;if(R){let B=await vI8(E,P.outputFilePath,T);if(B)x=B;else R=!1}return{data:{stdout:x,stderr:H,interrupted:X,isImage:R,returnCodeInterpretation:J?.message,noOutputExpected:K5Y(q.command),backgroundTaskId:P.backgroundTaskId,backgroundedByUser:P.backgroundedByUser,assistantAutoBackgrounded:P.assistantAutoBackgrounded,dangerouslyDisableSandbox:"dangerouslyDisableSandbox"in q?q.dangerouslyDisableSandbox:void 0,persistedOutputPath:Z,persistedOutputSize:T}}},renderToolUseErrorMessage:CzK,isResultTruncated(q){return UC(q.stdout)||UC(q.stderr)}})});async function w5Y(q,K,_,z){if(K.filter((H)=>{let J=H.trim();return z.isNormalizedCdCommand(J)}).length>1){let H={type:"other",reason:"Multiple directory changes in one command require approval for clarity"};return{behavior:"ask",decisionReason:H,message:f_(R4.name,H)}}{let H=!1,J=!1;for(let M of K){let X=F2(M);for(let P of X){let W=P.trim();if(z.isNormalizedCdCommand(W))H=!0;if(z.isNormalizedGitCommand(W))J=!0}}if(H&&J){let M={type:"other",reason:"Compound commands with cd and git require approval to prevent bare repository attacks"};return{behavior:"ask",decisionReason:M,message:f_(R4.name,M)}}}let $=new Map;for(let H of K){let J=H.trim();if(!J)continue;let M=await _({...q,command:J});$.set(J,M)}let A=Array.from($.entries()).find(([,H])=>H.behavior==="deny");if(A){let[H,J]=A;return{behavior:"deny",message:J.behavior==="deny"?J.message:`Permission denied for: ${H}`,decisionReason:{type:"subcommandResults",reasons:$}}}if(Array.from($.values()).every((H)=>H.behavior==="allow"))return{behavior:"allow",updatedInput:q,decisionReason:{type:"subcommandResults",reasons:$}};let w=[];for(let[,H]of $)if(H.behavior!=="allow"&&"suggestions"in H&&H.suggestions)w.push(...H.suggestions);let j={type:"subcommandResults",reasons:$};return{behavior:"ask",message:f_(R4.name,j),decisionReason:j,suggestions:w.length>0?w:void 0}}async function j5Y(q){if(!q.includes(">"))return q;return(await Aw6.parse(q))?.withoutOutputRedirections()??q}async function VPK(q,K,_,z){let Y=z&&z!==eO6?nm1(q.command,z):await Aw6.parse(q.command);if(!Y)return{behavior:"passthrough",message:"Failed to parse command"};return H5Y(q,K,_,Y)}async function H5Y(q,K,_,z){let Y=z.getTreeSitterAnalysis();if(Y?Y.compoundStructure.hasSubshell||Y.compoundStructure.hasCommandGroup:yPK(q.command)){let w=await yN8(q.command),j={type:"other",reason:w.behavior==="ask"&&w.message?w.message:"This command uses shell operators that require approval for safety"};return{behavior:"ask",message:f_(R4.name,j),decisionReason:j}}let A=z.getPipeSegments();if(A.length<=1)return{behavior:"passthrough",message:"No pipes found in command"};let O=await Promise.all(A.map((w)=>j5Y(w)));return w5Y(q,O,K,_)}var NPK=y(()=>{SG();im1();qw6();Fj();p0();EN8()});function M5Y(q){return J5Y.includes(q)}function X5Y(q,K){let _=q.trim(),[z]=_.split(/\s+/);if(!z)return{behavior:"passthrough",message:"Base command not found"};if(K.mode==="acceptEdits"&&M5Y(z))return{behavior:"allow",updatedInput:{command:q},decisionReason:{type:"mode",mode:"acceptEdits"}};return{behavior:"passthrough",message:`No mode-specific handling for '${z}' in ${K.mode} mode`}}function EPK(q,K){if(K.mode==="bypassPermissions")return{behavior:"passthrough",message:"Bypass mode is handled in main permission flow"};if(K.mode==="dontAsk")return{behavior:"passthrough",message:"DontAsk mode is handled in main permission flow"};let _=F2(q.command);for(let z of _){let Y=X5Y(z,K);if(Y.behavior!=="passthrough")return Y}return{behavior:"passthrough",message:"No mode-specific validation required"}}var J5Y;var LPK=y(()=>{SG();J5Y=["mkdir","touch","rm","rmdir","mv","cp","sed"]});function hPK(q,K,_,z){return}function Kp8(q){let K=q.trim().split(/\s+/).filter(Boolean);if(K.length===0)return null;let _=0;while(_<K.length&&o67.test(K[_])){let $=K[_].split("=")[0],A=!1;if(!_p8.has($))return null;_++}let z=K.slice(_);if(z.length<2)return null;let Y=z[1];if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(Y))return null;return z.slice(0,2).join(" ")}function CPK(q){let K=q.trim().split(/\s+/).filter(Boolean),_=0;while(_<K.length&&o67.test(K[_])){let Y=K[_].split("=")[0],$=!1;if(!_p8.has(Y))return null;_++}let z=K[_];if(!z)return null;if(!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(z))return null;if(W5Y.has(z))return null;return z}function lR6(q){let K=D5Y(q);if(K)return Jo6(R4.name,K);if(q.includes(`
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(`

Callers 3

preparePermissionMatcherFunction · 0.85
n67Function · 0.85
V$YFunction · 0.85

Calls 1

lvFunction · 0.85

Tested by

no test coverage detected