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

Function PK4

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

Source from the content-addressed store, hash-verified

751`).map((W)=>W.replace(/\r$/,"")).filter(Boolean));return}if(A.code===1){z([]);return}if(["ENOENT","EACCES","EPERM"].includes(A.code)){Y(A);return}if(!j&&nh_(w)){N("rg EAGAIN error detected, retrying with single-threaded mode (-j 1)"),d("tengu_ripgrep_eagain_retry",{}),e44(q,K,_,(W,D,f)=>{$(W,D,f,!0)},!0);return}let J=O&&O.trim().length>0,M=A.signal==="SIGTERM"||A.signal==="SIGKILL"||A.code==="ABORT_ERR",X=A.code==="ERR_CHILD_PROCESS_STDIO_MAXBUFFER",P=[];if(J){if(P=O.trim().split(`
752`).map((W)=>W.replace(/\r$/,"")).filter(Boolean),P.length>0&&(M||X))P=P.slice(0,-1)}if(N(`rg error (signal=${A.signal}, code=${A.code}, stderr: ${w}), ${P.length} results`),A.code!==2&&A.code!=="ABORT_ERR")H6(A);if(M&&P.length===0){Y(new _K4(`Ripgrep search timed out after ${Z1()==="wsl"?60:20} seconds. The search may have matched files but did not complete in time. Try searching a more specific path or pattern.`,P));return}z(P)};e44(q,K,_,(A,O,w)=>{$(A,O,w,!1)})})}function zK4(){let q=gG8();return{mode:q.mode,path:q.command,working:BG8?.working??null}}async function YK4(){if(process.platform!=="darwin"||qK4)return;qK4=!0;let q=gG8();if(q.mode!=="builtin")return;let K=q.command;if(!(await a8("codesign",["-vv","-d",K],{preserveOutputOnError:!1})).stdout.split(`
753`).find((Y)=>Y.includes("linker-signed")))return;try{let Y=await a8("codesign",["--sign","-","--force","--preserve-metadata=entitlements,requirements,flags,runtime",K]);if(Y.code!==0)H6(Error(`Failed to sign ripgrep: ${Y.stdout} ${Y.stderr}`));let $=await a8("xattr",["-d","com.apple.quarantine",K]);if($.code!==0)H6(Error(`Failed to remove quarantine: ${$.stdout} ${$.stderr}`))}catch(Y){H6(Y)}}var ch_,lh_,gG8,Zn6=20000000,_K4,FG8,BG8=null,rh_,qK4=!1;var KC=y(()=>{F4();k8();_8();m8();XK();i41();E8();vK();ch_=dh_(import.meta.url),lh_=_76.join(ch_,"../"),gG8=_1(()=>{if(k_(process.env.USE_BUILTIN_RIPGREP)){let{cmd:z}=wA8("rg",[]);if(z!=="rg")return{mode:"system",command:"rg",args:[]}}if(jj())return{mode:"embedded",command:process.execPath,args:["--no-config"],argv0:"rg"};let K=_76.resolve(lh_,"vendor","ripgrep");return{mode:"builtin",command:process.platform==="win32"?_76.resolve(K,`${process.arch}-win32`,"rg.exe"):_76.resolve(K,`${process.arch}-${process.platform}`,"rg"),args:[]}});_K4=class _K4 extends Error{partialResults;constructor(q,K){super(q);this.partialResults=K;this.name="RipgrepTimeoutError"}};FG8=_1(async(q,K,_=[])=>{if(_76.resolve(q)===_76.resolve(Qh_()))return;try{let z=["--files","--hidden"];_.forEach((O)=>{z.push("--glob",`!${O}`)});let Y=await ih_(z,q,K);if(Y===0)return 0;let $=Math.floor(Math.log10(Y)),A=Math.pow(10,$);return Math.round(Y/A)*A}catch(z){if(z?.name!=="AbortError")H6(z)}},(q,K,_=[])=>`${q}|${_.join(",")}`);rh_=_1(async()=>{if(BG8!==null)return;let q=gG8();try{let K;if(q.argv0){let z=Bun.spawn([q.command,"--version"],{argv0:q.argv0,stderr:"ignore",stdout:"pipe"}),[Y,$]=await Promise.all([z.stdout.text(),z.exited]);K={code:$,stdout:Y}}else K=await a8(q.command,[...q.args,"--version"],{timeout:5000});let _=K.code===0&&!!K.stdout&&K.stdout.startsWith("ripgrep ");BG8={working:_,lastTested:Date.now(),config:q},N(`Ripgrep first use test: ${_?"PASSED":"FAILED"} (mode=${q.mode}, path=${q.command})`),d("tengu_ripgrep_availability",{working:_?1:0,using_system:q.mode==="system"?1:0})}catch(K){BG8={working:!1,lastTested:Date.now(),config:q},H6(K)}})});function fG(q){let K=v1("policySettings")?.strictPluginOnlyCustomization;if(K===!0)return!0;if(Array.isArray(K))return K.includes(q);return!1}function Gn6(q){return q!==void 0&&oh_.has(q)}var oh_;var IA6=y(()=>{U1();oh_=new Set(["plugin","policySettings","built-in","builtin","bundled"])});import{statSync as ah_}from"fs";import{lstat as sh_,readdir as th_,readFile as eh_,realpath as qS_,stat as $K4}from"fs/promises";import{homedir as KS_}from"os";import{dirname as _S_,join as Wv6,resolve as AK4,sep as zS_}from"path";function z76(q,K="Custom item"){let _=q.split(`
754`);for(let z of _){let Y=z.trim();if(Y){let A=Y.match(/^#+\s+(.+)$/)?.[1]??Y;return A.length>100?A.substring(0,97)+"...":A}}return K}function wK4(q){if(q===void 0||q===null)return null;if(!q)return[];let K=[];if(typeof q==="string")K=[q];else if(Array.isArray(q))K=q.filter((z)=>typeof z==="string");if(K.length===0)return[];let _=_C(K);if(_.includes("*"))return["*"];return _}function Y76(q){let K=wK4(q);if(K===null)return q===void 0?void 0:[];if(K.includes("*"))return;return K}function RF(q){let K=wK4(q);if(K===null)return[];return K}async function YS_(q){try{let K=await sh_(q,{bigint:!0});if(K.dev===0n&&K.ino===0n)return null;return`${K.dev}:${K.ino}`}catch{return null}}function $S_(q){let K=hY(q),_=hY(Fz());if(!K||!_)return K;let z=jH(q);if(z&&zJ(z)===zJ(_))return K;let Y=zJ(K),$=zJ(_);if(Y!==$&&Y.startsWith($+zS_))return _;return K}function kh1(q,K){let _=AK4(KS_()).normalize("NFC"),z=$S_(K),Y=AK4(K),$=[];while(!0){if(zJ(Y)===zJ(_))break;let A=Wv6(Y,".claude",q);try{ah_(A),$.push(A)}catch(w){if(!e3(w))throw w}if(z&&zJ(Y)===zJ(z))break;let O=_S_(Y);if(O===Y)break;Y=O}return $}async function AS_(q,K){let _=[],z=new Set;async function Y($){if(K.aborted)return;try{let A=await $K4($,{bigint:!0});if(A.isDirectory()){let O=A.dev!==void 0&&A.ino!==void 0?`${A.dev}:${A.ino}`:await qS_($);if(z.has(O)){N(`Skipping already visited directory (circular symlink): ${$}`);return}z.add(O)}}catch(A){let O=A instanceof Error?A.message:String(A);N(`Failed to stat directory ${$}: ${O}`);return}try{let A=await th_($,{withFileTypes:!0});for(let O of A){if(K.aborted)break;let w=Wv6($,O.name);try{if(O.isSymbolicLink())try{let j=await $K4(w);if(j.isDirectory())await Y(w);else if(j.isFile()&&O.name.endsWith(".md"))_.push(w)}catch(j){let H=j instanceof Error?j.message:String(j);N(`Failed to follow symlink ${w}: ${H}`)}else if(O.isDirectory())await Y(w);else if(O.isFile()&&O.name.endsWith(".md"))_.push(w)}catch(j){let H=j instanceof Error?j.message:String(j);N(`Failed to access ${w}: ${H}`)}}}catch(A){let O=A instanceof Error?A.message:String(A);N(`Failed to read directory ${$}: ${O}`)}}return await Y(q),_}async function vh1(q){let K=i6(process.env.CLAUDE_CODE_USE_NATIVE_FILE_SEARCH),_=AbortSignal.timeout(3000),z;try{z=K?await AS_(q,_):await LF(["--files","--hidden","--follow","--no-ignore","--glob","*.md"],q,_)}catch($){if(e3($))return[];throw $}return(await Promise.all(z.map(async($)=>{try{let A=await eh_($,{encoding:"utf-8"}),{frontmatter:O,content:w}=kH(A,$);return{filePath:$,frontmatter:O,content:w}}catch(A){let O=A instanceof Error?A.message:String(A);return N(`Failed to read/parse markdown file: ${$}: ${O}`),null}}))).filter(($)=>$!==null)}var OK4,ii;var ri=y(()=>{F4();k8();v8();_8();m8();y8();bK();rV();E5();fX();KC();kO();qI();IA6();OK4=["commands","agents","output-styles","skills","workflows",...[]];ii=_1(async function(q,K){let _=Date.now(),z=Wv6(c1(),q),Y=Wv6(MP(),".claude",q),$=kh1(q,K),A=hY(K),O=jH(K);if(A&&O&&O!==A){let f=zJ(Wv6(A,".claude",q));if(!$.some((Z)=>zJ(Z)===f)){let Z=Wv6(O,".claude",q);if(!$.includes(Z))$.push(Z)}}let[w,j,H]=await Promise.all([vh1(Y).then((f)=>f.map((G)=>({...G,baseDir:Y,source:"policySettings"}))),$J("userSettings")&&!(q==="agents"&&fG("agents"))?vh1(z).then((f)=>f.map((G)=>({...G,baseDir:z,source:"userSettings"}))):Promise.resolve([]),$J("projectSettings")&&!(q==="agents"&&fG("agents"))?Promise.all($.map((f)=>vh1(f).then((G)=>G.map((Z)=>({...Z,baseDir:f,source:"projectSettings"}))))):Promise.resolve([])]),J=H.flat(),M=[...w,...j,...J],X=await Promise.all(M.map((f)=>YS_(f.filePath))),P=new Map,W=[];for(let[f,G]of M.entries()){let Z=X[f]??null;if(Z===null){W.push(G);continue}let T=P.get(Z);if(T!==void 0){N(`Skipping duplicate file '${G.filePath}' from ${G.source} (same inode already loaded from ${T})`);continue}P.set(Z,G.source),W.push(G)}let D=M.length-W.length;if(D>0)N(`Deduplicated ${D} files in ${q} (same inode via symlinks or hard links)`);return d("tengu_dir_search",{durationMs:Date.now()-_,managedFilesFound:w.length,userFilesFound:j.length,projectFilesFound:J.length,projectDirsSearched:$.length,subdir:q}),W},(q,K)=>`${q}:${K}`)});function $M(q){switch(q.type){case"generic-error":return q.error;case"path-not-found":return`Path not found: ${q.path} (${q.component})`;case"git-auth-failed":return`Git authentication failed (${q.authType}): ${q.gitUrl}`;case"git-timeout":return`Git ${q.operation} timeout: ${q.gitUrl}`;case"network-error":return`Network error: ${q.url}${q.details?` - ${q.details}`:""}`;case"manifest-parse-error":return`Manifest parse error: ${q.parseError}`;case"manifest-validation-error":return`Manifest validation failed: ${q.validationErrors.join(", ")}`;case"plugin-not-found":return`Plugin ${q.pluginId} not found in marketplace ${q.marketplace}`;case"marketplace-not-found":return`Marketplace ${q.marketplace} not found`;case"marketplace-load-failed":return`Marketplace ${q.marketplace} failed to load: ${q.reason}`;case"mcp-config-invalid":return`MCP server ${q.serverName} invalid: ${q.validationError}`;case"mcp-server-suppressed-duplicate":{let K=q.duplicateOf.startsWith("plugin:")?`server provided by plugin "${q.duplicateOf.split(":")[1]??"?"}"`:`already-configured "${q.duplicateOf}"`;return`MCP server "${q.serverName}" skipped — same command/URL as ${K}`}case"hook-load-failed":return`Hook load failed: ${q.reason}`;case"component-load-failed":return`${q.component} load failed from ${q.path}: ${q.reason}`;case"mcpb-download-failed":return`Failed to download MCPB from ${q.url}: ${q.reason}`;case"mcpb-extract-failed":return`Failed to extract MCPB ${q.mcpbPath}: ${q.reason}`;case"mcpb-invalid-manifest":return`MCPB manifest invalid at ${q.mcpbPath}: ${q.validationError}`;case"lsp-config-invalid":return`Plugin "${q.plugin}" has invalid LSP server config for "${q.serverName}": ${q.validationError}`;case"lsp-server-start-failed":return`Plugin "${q.plugin}" failed to start LSP server "${q.serverName}": ${q.reason}`;case"lsp-server-crashed":if(q.signal)return`Plugin "${q.plugin}" LSP server "${q.serverName}" crashed with signal ${q.signal}`;return`Plugin "${q.plugin}" LSP server "${q.serverName}" crashed with exit code ${q.exitCode??"unknown"}`;case"lsp-request-timeout":return`Plugin "${q.plugin}" LSP server "${q.serverName}" timed out on ${q.method} request after ${q.timeoutMs}ms`;case"lsp-request-failed":return`Plugin "${q.plugin}" LSP server "${q.serverName}" ${q.method} request failed: ${q.error}`;case"marketplace-blocked-by-policy":if(q.blockedByBlocklist)return`Marketplace '${q.marketplace}' is blocked by enterprise policy`;return`Marketplace '${q.marketplace}' is not in the allowed marketplace list`;case"dependency-unsatisfied":{let K=q.reason==="not-enabled"?"disabled — enable it or remove the dependency":"not found in any configured marketplace";return`Dependency "${q.dependency}" is ${K}`}case"plugin-cache-miss":return`Plugin "${q.plugin}" not cached at ${q.installPath} — run /plugins to refresh`}}function jK4(q){return q.endsWith(`@${Tn6}`)}function HK4(q){return Vh1.get(q)}function Nh1(){let q=Z7(),K=[],_=[];for(let[z,Y]of Vh1){if(Y.isAvailable&&!Y.isAvailable())continue;let $=`${z}@${Tn6}`,A=q?.enabledPlugins?.[$],O=A!==void 0?A===!0:Y.defaultEnabled??!0,w={name:z,manifest:{name:z,description:Y.description,version:Y.version},path:Tn6,source:$,repository:$,enabled:O,isBuiltin:!0,hooksConfig:Y.hooks,mcpServers:Y.mcpServers};if(O)K.push(w);else _.push(w)}return{enabled:K,disabled:_}}function JK4(){let{enabled:q}=Nh1(),K=[];for(let _ of q){let z=Vh1.get(_.name);if(!z?.skills)continue;for(let Y of z.skills)K.push(OS_(Y))}return K}function OS_(q){return{type:"prompt",name:q.name,description:q.description,hasUserSpecifiedDescription:!0,allowedTools:q.allowedTools??[],argumentHint:q.argumentHint,whenToUse:q.whenToUse,model:q.model,disableModelInvocation:q.disableModelInvocation??!1,userInvocable:q.userInvocable??!0,contentLength:0,source:"bundled",loadedFrom:"bundled",hooks:q.hooks,context:q.context,agent:q.agent,isEnabled:q.isEnabled??(()=>!0),isHidden:!(q.userInvocable??!0),progressMessage:"running",getPromptForCommand:q.getPromptForCommand}}var Vh1,Tn6="builtin";var vn6=y(()=>{U1();Vh1=new Map});import{join as MK4}from"path";function uA6(){let q={};for(let K of NZ())for(let _ of XK4){let{settings:z}=le(MK4(K,".claude",_));if(!z?.enabledPlugins)continue;Object.assign(q,z.enabledPlugins)}return q}function PK4(){let q={};for(let K of NZ())for(let _ of XK4){let{settings:z}=le(MK4(K,".claude",_));if(!z?.extraKnownMarketplaces)continue;Object.assign(q,z.extraKnownMarketplaces)}return q}var XK4;var UG8=y(()=>{v8();U1();XK4=["settings.json","settings.local.json"]});function Z4(q){if(q.includes("@")){let K=q.split("@");return{name:K[0]||"",marketplace:K[1]}}return{name:q}}function Ru(q){return q!==void 0&&_I.has(q.toLowerCase())}function hF(q){if(q==="managed")throw Error("Cannot install plugins to managed scope");return wS_[q]}function WK4(q){return yh1[q]}var yh1,wS_;var hP=y(()=>{BZ();yh1={policySettings:"managed",userSettings:"user",projectSettings:"project",localSettings:"local",flagSettings:"flag"};wS_={user:"userSettings",project:"projectSettings",local:"localSettings"}});function Eh1(q,K){if(Z4(q).marketplace)return q;let _=Z4(K).marketplace;if(!_||_===jS_)return q;return`${q}@${_}`}async function DK4(q,K,_,z=new Set){let Y=Z4(q).marketplace,$=[],A=new Set,O=[];async function w(H,J){if(H!==q&&_.has(H))return null;let M=Z4(H).marketplace;if(M!==Y&&!(M&&z.has(M)))return{ok:!1,reason:"cross-marketplace",dependency:H,requiredBy:J};if(O.includes(H))return{ok:!1,reason:"cycle",chain:[...O,H]};if(A.has(H))return null;A.add(H);let X=await K(H);if(!X)return{ok:!1,reason:"not-found",missing:H,requiredBy:J};O.push(H);for(let P of X.dependencies??[]){let W=Eh1(P,H),D=await w(W,H);if(D)return D}return O.pop(),$.push(H),null}let j=await w(q,q);if(j)return j;return{ok:!0,closure:$}}function fK4(q){let K=new Set(q.map((w)=>w.source)),_=new Set(q.filter((w)=>w.enabled).map((w)=>w.source)),z=new Set(q.map((w)=>Z4(w.source).name)),Y=new Map;for(let w of _){let j=Z4(w).name;Y.set(j,(Y.get(j)??0)+1)}let $=[],A=!0;while(A){A=!1;for(let w of q){if(!_.has(w.source))continue;for(let j of w.manifest.dependencies??[]){let H=Eh1(j,w.source),J=!Z4(H).marketplace;if(!(J?(Y.get(H)??0)>0:_.has(H))){_.delete(w.source);let X=Y.get(w.name)??0;if(X<=1)Y.delete(w.name);else Y.set(w.name,X-1);$.push({type:"dependency-unsatisfied",source:w.source,plugin:w.name,dependency:H,reason:(J?z.has(H):K.has(H))?"not-enabled":"not-found"}),A=!0;break}}}}return{demoted:new Set(q.filter((w)=>w.enabled&&!_.has(w.source)).map((w)=>w.source)),errors:$}}function Lh1(q,K){let{name:_}=Z4(q);return K.filter((z)=>z.enabled&&z.source!==q&&(z.manifest.dependencies??[]).some((Y)=>{let $=Eh1(Y,z.source);return Z4($).marketplace?$===q:$===_})).map((z)=>z.name)}function ZK4(q){return new Set(Object.entries(v1(q)?.enabledPlugins??{}).filter(([,K])=>K===!0||Array.isArray(K)).map(([K])=>K))}function GK4(q){if(q.length===0)return"";let K=q.length;return` (+ ${K} ${K===1?"dependency":"dependencies"})`}function Rh1(q){if(!q||q.length===0)return"";return` — warning: required by ${q.join(", ")}`}var jS_="inline";var QG8=y(()=>{U1();hP()});var Dv6,C2="claude-plugins-official";var oi=y(()=>{Dv6={source:"github",repo:"anthropics/claude-plugins-official"}});function JS_(q){let K,_=/^[^@/]+@([^:/]+):/.exec(q);if(_)K=_[1];else try{K=new URL(q).hostname}catch{return"unknown"}let z=K.toLowerCase();return HS_.has(z)?z:"other"}function MS_(q){return q.includes(`anthropics/${C2}`)}function KD(q,K,_,z,Y){d("tengu_plugin_remote_fetch",{source:q,host:K?JS_(K):"unknown",is_official:K?MS_(K):!1,outcome:_,duration_ms:Math.round(z),...Y&&{error_kind:Y}})}function zC(q){let K=String(q?.message??q);if(/ENOTFOUND|ECONNREFUSED|EAI_AGAIN|Could not resolve host|Connection refused/i.test(K))return"dns_or_refused";if(/ETIMEDOUT|timed out|timeout/i.test(K))return"timeout";if(/ECONNRESET|socket hang up|Connection reset by peer|remote end hung up/i.test(K))return"conn_reset";if(/403|401|authentication|permission denied/i.test(K))return"auth";if(/404|not found|repository not found/i.test(K))return"not_found";if(/certificate|SSL|TLS|unable to get local issuer/i.test(K))return"tls";if(/Invalid response format|Invalid marketplace schema/i.test(K))return"invalid_schema";return"other"}var HS_;var kn6=y(()=>{k8();oi();HS_=new Set(["github.com","raw.githubusercontent.com","objects.githubusercontent.com","gist.githubusercontent.com","gitlab.com","bitbucket.org","codeberg.org","dev.azure.com","ssh.dev.azure.com","storage.googleapis.com"])});async function XS_(q){try{return!!await TO(q)}catch{return!1}}function TK4(){mA6.cache?.set?.(void 0,Promise.resolve(!1))}var mA6;var dG8=y(()=>{F4();rk();mA6=_1(async()=>{return XS_("git")})});function O7(q,K){if(!process.env.SRT_DEBUG)return;let _=K?.level||"info",z="[SandboxDebug]";switch(_){case"error":console.error(`${z} ${q}`);break;case"warn":console.warn(`${z} ${q}`);break;default:console.error(`${z} ${q}`)}}import{Agent as PS_,createServer as WS_}from"node:http";import{request as vK4}from"node:http";import{request as DS_}from"node:https";import{connect as kK4}from"node:net";import{URL as fS_}from"node:url";function VK4(q){let K=WS_();return K.on("connect",async(_,z)=>{z.on("error",(Y)=>{O7(`Client socket error: ${Y.message}`,{level:"error"})});try{let[Y,$]=_.url.split(":"),A=$===void 0?void 0:parseInt($,10);if(!Y||!A){O7(`Invalid CONNECT request: ${_.url}`,{level:"error"}),z.end(`HTTP/1.1 400 Bad Request\r
755\r
756`);return}if(!await q.filter(A,Y,z)){O7(`Connection blocked to ${Y}:${A}`,{level:"error"}),z.end(`HTTP/1.1 403 Forbidden\r

Callers 1

tK6Function · 0.85

Calls 3

NZFunction · 0.85
leFunction · 0.85
assignMethod · 0.45

Tested by

no test coverage detected