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

Function Pa

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

Source from the content-addressed store, hash-verified

2623 fi
2624 `}var Xa1="\\",t_K=1e4,Knz,e_K=async(q)=>{let K=q.includes("zsh")?"zsh":q.includes("bash")?"bash":"sh";return N(`Creating shell snapshot for ${K} (${q})`),new Promise(async(_)=>{try{let z=Da1(q);N(`Looking for shell config file: ${z}`);let Y=await u5(z);if(!Y)N(`Shell config file not found: ${z}, creating snapshot with Claude Code defaults only`);let $=Date.now(),A=Math.random().toString(36).substring(2,8),O=Pa1(c1(),"shell-snapshots");N(`Snapshots directory: ${O}`);let w=Pa1(O,`snapshot-${K}-${$}-${A}.sh`);await tlz(O,{recursive:!0});let j=await $nz(q,w,Y);N(`Creating snapshot at: ${w}`),N(`Execution timeout: ${t_K}ms`),slz(q,["-c","-l",j],{env:{...process.env.CLAUDE_CODE_DONT_INHERIT_ENV?{}:Ym(),SHELL:q,GIT_EDITOR:"true",CLAUDECODE:"1"},timeout:t_K,maxBuffer:1048576,encoding:"utf8"},async(H,J,M)=>{if(H){let X=H;if(N(`Shell snapshot creation failed: ${H.message}`),N("Error details:"),N(` - Error code: ${X?.code}`),N(` - Error signal: ${X?.signal}`),N(` - Error killed: ${X?.killed}`),N(` - Shell path: ${q}`),N(` - Config file: ${Da1(q)}`),N(` - Config file exists: ${Y}`),N(` - Working directory: ${Z8()}`),N(` - Claude home: ${c1()}`),N(`Full snapshot script:
2625${j}`),J)N(`stdout output (${J.length} chars):
2626${J}`);else N("No stdout output captured");if(M)N(`stderr output (${M.length} chars): ${M}`);else N("No stderr output captured");H6(Error(`Failed to create shell snapshot: ${H.message}`));let P=X?.signal?HI8.constants.signals[X.signal]:void 0;d("tengu_shell_snapshot_failed",{stderr_length:M?.length||0,has_error_code:!!X?.code,error_signal_number:P,error_killed:X?.killed}),_(void 0)}else{let X;try{X=(await elz(w)).size}catch{}if(X!==void 0)N(`Shell snapshot created successfully (${X} bytes)`),pq(async()=>{try{await X8().unlink(w),N(`Cleaned up session snapshot: ${w}`)}catch(P){N(`Error cleaning up session snapshot: ${P}`)}}),_(w);else{N(`Shell snapshot file not found after creation: ${w}`),N(`Checking if parent directory still exists: ${O}`);try{let P=await X8().readdir(O);N(`Directory contains ${P.length} files`)}catch{N(`Parent directory does not exist or is not accessible: ${O}`)}d("tengu_shell_unknown_error",{}),_(void 0)}}})}catch(z){if(N(`Unexpected error during snapshot creation: ${z}`),z instanceof Error)N(`Error stack trace: ${z.stack}`);H6(z),d("tengu_shell_snapshot_error",{}),_(void 0)}})};var qzK=y(()=>{Df();k8();c9();I7();_8();ju();m8();bK();e7();E8();vK();KC();bw6();NX();Knz=[".git",".svn",".hg",".bzr",".jj",".sl"]});function JI8(q,K){let _=q.lastIndexOf(" -");if(_>0){let z=q.substring(0,_),Y=q.substring(_+1);return`${E4([z])} ${Y} ${E4([K])}`}else return`${E4([q])} ${E4([K])}`}var fa1=y(()=>{NX()});function Za1(q){if(/\d\s*<<\s*\d/.test(q)||/\[\[\s*\d+\s*<<\s*\d+\s*\]\]/.test(q)||/\$\(\(.*<<.*\)\)/.test(q))return!1;return/<<-?\s*(?:(['"]?)(\w+)\1|\\(\w+))/.test(q)}function Anz(q){let K=/'(?:[^'\\]|\\.)*\n(?:[^'\\]|\\.)*'/,_=/"(?:[^"\\]|\\.)*\n(?:[^"\\]|\\.)*"/;return K.test(q)||_.test(q)}function KzK(q,K=!0){if(Za1(q)||Anz(q)){let z=`'${q.replace(/'/g,`'"'"'`)}'`;if(Za1(q))return z;return K?`${z} < /dev/null`:z}if(K)return E4([q,"<","/dev/null"]);return E4([q])}function Onz(q){return/(?:^|[\s;&|])<(?![<(])\s*\S+/.test(q)}function _zK(q){if(Za1(q))return!1;if(Onz(q))return!1;return!0}function zzK(q){return q.replace(wnz,"$1/dev/null")}var wnz;var YzK=y(()=>{NX();wnz=/(\d?&?>+\s*)[Nn][Uu][Ll](?=\s|$|[|&;)\n])/g});function MI8(){return $zK}function AzK(){$zK.clear()}var $zK;var XI8=y(()=>{$zK=new Map});function jzK(){if(!OzK||wzK===null)return null;return`${OzK},${wzK},0`}var OzK=null,wzK=null;var HzK=y(()=>{c9();_8();y8();XK();E8();vK()});import{access as jnz}from"fs/promises";import{tmpdir as Hnz}from"os";import{join as Jnz}from"path";import{join as PI8}from"path/posix";function Mnz(q){if(process.env.CLAUDE_CODE_SHELL_PREFIX)return"{ shopt -u extglob || setopt NO_EXTENDED_GLOB; } >/dev/null 2>&1 || true";if(q.includes("bash"))return"shopt -u extglob 2>/dev/null || true";else if(q.includes("zsh"))return"setopt NO_EXTENDED_GLOB 2>/dev/null || true";return null}async function JzK(q,K){let _,z=K?.skipSnapshot?Promise.resolve(void 0):e_K(q).catch(($)=>{N(`Failed to create shell snapshot: ${$}`);return}),Y;return{type:"bash",shellPath:q,detached:!0,async buildExecCommand($,A){let O=await z;if(O)try{await jnz(O)}catch{N(`Snapshot file missing, falling back to login shell: ${O}`),O=void 0}Y=O,_=A.sandboxTmpDir;let w=Hnz(),H=Z1()==="windows"?ff(w):w,J=A.useSandbox?PI8(A.sandboxTmpDir,`cwd-${A.id}`):PI8(H,`claude-${A.id}-cwd`),M=A.useSandbox?PI8(A.sandboxTmpDir,`cwd-${A.id}`):Jnz(w,`claude-${A.id}-cwd`),X=zzK($),P=_zK(X),W=KzK(X,P);if(X.includes("|")&&P)W=o_K(X);let D=[];if(O){let T=Z1()==="windows"?ff(O):O;D.push(`source ${E4([T])} 2>/dev/null || true`)}let f=await g5K();if(f)D.push(f);let G=Mnz(q);if(G)D.push(G);D.push(`eval ${W}`),D.push(`pwd -P >| ${E4([J])}`);let Z=D.join(" && ");if(process.env.CLAUDE_CODE_SHELL_PREFIX)Z=JI8(process.env.CLAUDE_CODE_SHELL_PREFIX,Z);return{commandString:Z,cwdFilePath:M}},getSpawnArgs($){let A=Y!==void 0;if(A)N("Spawning shell without login (-l flag skipped)");return["-c",...A?[]:["-l"],$]},async getEnvironmentOverrides($){let A=$.includes("tmux"),O=jzK(),w={};if(O)w.TMUX=O;if(_){let j=_;if(Z1()==="windows")j=ff(j);w.TMPDIR=j,w.CLAUDE_CODE_TMPDIR=j,w.TMPPREFIX=PI8(j,"zsh")}for(let[j,H]of MI8())w[j]=H;return w}}}var MzK=y(()=>{s_K();qzK();fa1();NX();YzK();_8();vK();tE6();XI8();HzK();NB()});import{realpath as XzK,stat as Xnz}from"fs/promises";async function PzK(q){try{return(await Xnz(q)).isFile()?q:null}catch{return null}}async function Pnz(){let q=await TO("pwsh");if(q){if(Z1()==="linux"){let _=await XzK(q).catch(()=>q);if(q.startsWith("/snap/")||_.startsWith("/snap/")){let z=await PzK("/opt/microsoft/powershell/7/pwsh")??await PzK("/usr/bin/pwsh");if(z){let Y=await XzK(z).catch(()=>z);if(!z.startsWith("/snap/")&&!Y.startsWith("/snap/"))return z}}}return q}let K=await TO("powershell");if(K)return K;return null}function Pa(){if(!Ga1)Ga1=Pnz();return Ga1}async function WzK(){let q=await Pa();if(!q)return null;return q.split(/[/\\]/).pop().toLowerCase().replace(/\.exe$/,"")==="pwsh"?"core":"desktop"}var Ga1=null;var GL6=y(()=>{vK();rk()});import{tmpdir as Wnz}from"os";import{join as Dnz}from"path";import{join as fnz}from"path/posix";function Ta1(q){return["-NoProfile","-NonInteractive","-Command",q]}function Znz(q){return Buffer.from(q,"utf16le").toString("base64")}function DzK(q){let K;return{type:"powershell",shellPath:q,detached:!1,async buildExecCommand(_,z){K=z.useSandbox?z.sandboxTmpDir:void 0;let Y=z.useSandbox&&z.sandboxTmpDir?fnz(z.sandboxTmpDir,`claude-pwd-ps-${z.id}`):Dnz(Wnz(),`claude-pwd-ps-${z.id}`),A=`
2627; $_ec = if ($null -ne $LASTEXITCODE) { $LASTEXITCODE } elseif ($?) { 0 } else { 1 }
2628; (Get-Location).Path | Out-File -FilePath '${Y.replace(/'/g,"''")}' -Encoding utf8 -NoNewline

Callers 5

WzKFunction · 0.85
cli.jsFile · 0.85
vizFunction · 0.85
$ozFunction · 0.85
hQ8Function · 0.85

Calls 1

PnzFunction · 0.85

Tested by

no test coverage detected