| 2971 | ${z}`;throw new zB(Y)}var Ooz,woz,joz;var uL6=y(()=>{p0();_8();y8();i1();Fj();IG();Hr();Ooz=(()=>{let q;return()=>{if(!q)q=(xL6(),Eq(UI8)).PowerShellTool;return q}})(),woz=/```!\s*\n?([\s\S]*?)\n?```/g,joz=/(?<=^|\s)!`([^`]+)`/gm});function mYK(q){Joz=q}var Joz=null;import{realpath as Moz}from"fs/promises";import{basename as iI8,dirname as pj6,isAbsolute as pYK,join as fa,sep as pL6,relative as Xoz}from"path";function VK6(q,K){switch(q){case"policySettings":return fa(MP(),".claude",K);case"userSettings":return fa(c1(),K);case"projectSettings":return`.claude/${K}`;case"plugin":return"plugin";default:return""}}function rI8(q){let K=[q.name,q.description,q.whenToUse].filter(Boolean).join(" ");return E3(K)}async function Poz(q){try{return await Moz(q)}catch{return null}}function Woz(q,K){if(!q.hooks)return;let _=Th().safeParse(q.hooks);if(!_.success){N(`Invalid hooks in skill '${K}': ${_.error.message}`);return}return _.data}function Doz(q){if(!q.paths)return;let K=fn6(q.paths).map((_)=>{return _.endsWith("/**")?_.slice(0,-3):_}).filter((_)=>_.length>0);if(K.length===0||K.every((_)=>_==="**"))return;return K}function _s1(q,K,_,z="Skill"){let Y=Lu(q.description,_),$=Y??z76(K,z),A=q["user-invocable"]===void 0?!0:Pv6(q["user-invocable"]),O=q.model==="inherit"?void 0:q.model?A5(q.model):void 0,w=q.effort,j=w!==void 0?OC(w):void 0;if(w!==void 0&&j===void 0)N(`Skill ${_} has invalid effort '${w}'. Valid options: ${DL.join(", ")} or an integer`);return{displayName:q.name!=null?String(q.name):void 0,description:$,hasUserSpecifiedDescription:Y!==null,allowedTools:RF(q["allowed-tools"]),argumentHint:q["argument-hint"]!=null?String(q["argument-hint"]):void 0,argumentNames:AI8(q.arguments),whenToUse:q.when_to_use,version:q.version,model:O,disableModelInvocation:Pv6(q["disable-model-invocation"]),userInvocable:A,hooks:Woz(q,_),executionContext:q.context==="fork"?"fork":void 0,agent:q.agent,effort:j,shell:pG8(q.shell,_)}}function zs1({skillName:q,displayName:K,description:_,hasUserSpecifiedDescription:z,markdownContent:Y,allowedTools:$,argumentHint:A,argumentNames:O,whenToUse:w,version:j,model:H,disableModelInvocation:J,userInvocable:M,source:X,baseDir:P,loadedFrom:W,hooks:D,executionContext:f,agent:G,paths:Z,effort:T,shell:v}){return{type:"prompt",name:q,description:_,hasUserSpecifiedDescription:z,allowedTools:$,argumentHint:A,argNames:O.length>0?O:void 0,whenToUse:w,version:j,model:H,disableModelInvocation:J,userInvocable:M,context:f,agent:G,effort:T,paths:Z,contentLength:Y.length,isHidden:!M,progressMessage:"running",userFacingName(){return K||q},source:X,loadedFrom:W,hooks:D,skillRoot:P,async getPromptForCommand(V,E){let S=P?`Base directory for this skill: ${P} |
| 2972 | |
| 2973 | ${Y}`:Y;if(S=DL6(S,V,!0,O),P){let R=process.platform==="win32"?P.replace(/\\/g,"/"):P;S=S.replace(/\$\{CLAUDE_SKILL_DIR\}/g,R)}if(S=S.replace(/\$\{CLAUDE_SESSION_ID\}/g,N8()),W!=="mcp")S=await pQ(S,{...E,getAppState(){let R=E.getAppState();return{...R,toolPermissionContext:{...R.toolPermissionContext,alwaysAllowRules:{...R.toolPermissionContext.alwaysAllowRules,command:$}}}}},`/${q}`,v);return[{type:"text",text:S}]}}}async function mL6(q,K){let _=X8(),z;try{z=await _.readdir(q)}catch($){if(!e3($))H6($);return[]}return(await Promise.all(z.map(async($)=>{try{if(!$.isDirectory()&&!$.isSymbolicLink())return null;let A=fa(q,$.name),O=fa(A,"SKILL.md"),w;try{w=await _.readFile(O,{encoding:"utf-8"})}catch(P){if(!_7(P))N(`[skills] failed to read ${O}: ${P}`,{level:"warn"});return null}let{frontmatter:j,content:H}=kH(w,O),J=$.name,M=_s1(j,H,J),X=Doz(j);return{skill:zs1({...M,skillName:J,markdownContent:H,source:K,baseDir:A,loadedFrom:"skills",paths:X}),filePath:O}}catch(A){return H6(A),null}}))).filter(($)=>$!==null)}function Ys1(q){return/^skill\.md$/i.test(iI8(q))}function foz(q){let K=new Map;for(let z of q){let Y=pj6(z.filePath),$=K.get(Y)??[];$.push(z),K.set(Y,$)}let _=[];for(let[z,Y]of K){let $=Y.filter((A)=>Ys1(A.filePath));if($.length>0){let A=$[0];if($.length>1)N(`Multiple skill files found in ${z}, using ${iI8(A.filePath)}`);_.push(A)}else _.push(...Y)}return _}function gYK(q,K){let _=K.endsWith(pL6)?K.slice(0,-1):K;if(q===_)return"";let z=q.slice(_.length+1);return z?z.split(pL6).join(":"):""}function Zoz(q,K){let _=pj6(q),z=pj6(_),Y=iI8(_),$=gYK(z,K);return $?`${$}:${Y}`:Y}function Goz(q,K){let _=iI8(q),z=pj6(q),Y=_.replace(/\.md$/,""),$=gYK(z,K);return $?`${$}:${Y}`:Y}function Toz(q){return Ys1(q.filePath)?Zoz(q.filePath,q.baseDir):Goz(q.filePath,q.baseDir)}async function voz(q){try{let K=await ii("commands",q),_=foz(K),z=[];for(let{baseDir:Y,filePath:$,frontmatter:A,content:O,source:w}of _)try{let H=Ys1($)?pj6($):void 0,J=Toz({baseDir:Y,filePath:$,frontmatter:A,content:O,source:w}),M=_s1(A,O,J,"Custom command");z.push({skill:zs1({...M,skillName:J,displayName:void 0,markdownContent:O,source:w,baseDir:H,loadedFrom:"commands_DEPRECATED",paths:void 0}),filePath:$})}catch(j){H6(j)}return z}catch(K){return H6(K),[]}}function oI8(){$s1.cache?.clear?.(),ii.cache?.clear?.(),BL6.clear(),aI8.clear()}function FYK(q){return As1.subscribe(()=>{try{q()}catch(K){H6(K)}})}async function gL6(q,K){let _=X8(),z=K.endsWith(pL6)?K.slice(0,-1):K,Y=[];for(let $ of q){let A=pj6($);while(A.startsWith(z+pL6)){let O=fa(A,".claude","skills");if(!Ks1.has(O)){Ks1.add(O);try{if(await _.stat(O),await m41(A,z)){N(`[skills] Skipped gitignored skills dir: ${O}`);continue}Y.push(O)}catch{}}let w=pj6(A);if(w===A)break;A=w}}return Y.sort(($,A)=>A.split(pL6).length-$.split(pL6).length)}async function FL6(q){if(!$J("projectSettings")||fG("skills")){N("[skills] Dynamic skill discovery skipped: projectSettings disabled or plugin-only policy");return}if(q.length===0)return;let K=new Set(Za.keys()),_=await Promise.all(q.map((Y)=>mL6(Y,"projectSettings")));for(let Y=_.length-1;Y>=0;Y--)for(let{skill:$}of _[Y]??[])if($.type==="prompt")Za.set($.name,$);let z=_.flat().length;if(z>0){let Y=[...Za.keys()].filter(($)=>!K.has($));if(N(`[skills] Dynamically discovered ${z} skills from ${q.length} directories`),Y.length>0)d("tengu_dynamic_skills_changed",{source:"file_operation",previousCount:K.size,newCount:Za.size,addedCount:Y.length,directoryCount:q.length})}As1.emit()}function UYK(){return Array.from(Za.values())}function UL6(q,K){if(BL6.size===0)return[];let _=[];for(let[z,Y]of BL6){if(Y.type!=="prompt"||!Y.paths||Y.paths.length===0)continue;let $=BYK.default().add(Y.paths);for(let A of q){let O=pYK(A)?Xoz(K,A):A;if(!O||O.startsWith("..")||pYK(O))continue;if($.ignores(O)){Za.set(z,Y),BL6.delete(z),aI8.add(z),_.push(z),N(`[skills] Activated conditional skill '${z}' (matched path: ${O})`);break}}}if(_.length>0)d("tengu_dynamic_skills_changed",{source:"conditional_paths",previousCount:Za.size-_.length,newCount:Za.size,addedCount:_.length,directoryCount:0}),As1.emit();return _}function QYK(){Ks1.clear(),Za.clear(),BL6.clear(),aI8.clear()}var BYK,$s1,Ks1,Za,BL6,aI8,As1;var Ga=y(()=>{F4();v8();k8();ON();S68();_8();q0();m8();y8();rV();e7();p41();E8();ri();aq();uL6();kO();qI();IA6();vh();BYK=O6(n$6(),1);$s1=_1(async(q)=>{let K=fa(c1(),"skills"),_=fa(MP(),".claude","skills"),z=kh1("skills",q);N(`Loading skills from: managed=${_}, user=${K}, project=[${z.join(", ")}]`);let Y=NZ(),$=fG("skills"),A=$J("projectSettings")&&!$;if(f9()){if(Y.length===0||!A)return N(`[bare] Skipping skill dir discovery (${Y.length===0?"no --add-dir":"projectSettings disabled or skillsLocked"})`),[];return(await Promise.all(Y.map((T)=>mL6(fa(T,".claude","skills"),"projectSettings")))).flat().map((T)=>T.skill)}let[O,w,j,H,J]=await Promise.all([i6(process.env.CLAUDE_CODE_DISABLE_POLICY_SKILLS)?Promise.resolve([]):mL6(_,"policySettings"),$J("userSettings")&&!$?mL6(K,"userSettings"):Promise.resolve([]),A?Promise.all(z.map((Z)=>mL6(Z,"projectSettings"))):Promise.resolve([]),A?Promise.all(Y.map((Z)=>mL6(fa(Z,".claude","skills"),"projectSettings"))):Promise.resolve([]),$?Promise.resolve([]):voz(q)]),M=[...O,...w,...j.flat(),...H.flat(),...J],X=await Promise.all(M.map(({skill:Z,filePath:T})=>Z.type==="prompt"?Poz(T):Promise.resolve(null))),P=new Map,W=[];for(let Z=0;Z<M.length;Z++){let T=M[Z];if(T===void 0||T.skill.type!=="prompt")continue;let{skill:v}=T,V=X[Z];if(V===null||V===void 0){W.push(v);continue}let E=P.get(V);if(E!==void 0){N(`Skipping duplicate skill '${v.name}' from ${v.source} (same file already loaded from ${E})`);continue}P.set(V,v.source),W.push(v)}let D=M.length-W.length;if(D>0)N(`Deduplicated ${D} skills (same file)`);let f=[],G=[];for(let Z of W)if(Z.type==="prompt"&&Z.paths&&Z.paths.length>0&&!aI8.has(Z.name))G.push(Z);else f.push(Z);for(let Z of G)BL6.set(Z.name,Z);if(G.length>0)N(`[skills] ${G.length} conditional skills stored (activated when matching files are touched)`);return N(`Loaded ${W.length} unique skills (${f.length} unconditional, ${G.length} conditional, managed: ${O.length}, user: ${w.length}, project: ${j.flat().length}, additional: ${H.flat().length}, legacy commands: ${J.length})`),f});Ks1=new Set,Za=new Map,BL6=new Map,aI8=new Set,As1=Dz();mYK({createSkillCommand:zs1,parseSkillFrontmatterFields:_s1})});function Os1(q){let K=ww();if(K.lastSessionId!==q)return;let _;if(K.lastModelUsage)_=Object.fromEntries(Object.entries(K.lastModelUsage).map(([z,Y])=>[z,{...Y,contextWindow:lf(z,QM()),maxOutputTokens:t86(z).default}]));return{totalCostUSD:K.lastCost??0,totalAPIDuration:K.lastAPIDuration??0,totalAPIDurationWithoutRetries:K.lastAPIDurationWithoutRetries??0,totalToolDuration:K.lastToolDuration??0,totalLinesAdded:K.lastLinesAdded??0,totalLinesRemoved:K.lastLinesRemoved??0,lastDuration:K.lastDuration,modelUsage:_}}function sI8(q){let K=Os1(q);if(!K)return!1;return Bb6(K),!0}function tI8(q){jw((K)=>({...K,lastCost:fW(),lastAPIDuration:ay(),lastAPIDurationWithoutRetries:Qn8(),lastToolDuration:dn8(),lastDuration:RX6(),lastLinesAdded:l36(),lastLinesRemoved:n36(),lastTotalInputTokens:bk(),lastTotalOutputTokens:Gc(),lastTotalCacheCreationInputTokens:Ib6(),lastTotalCacheReadInputTokens:xb6(),lastTotalWebSearchRequests:sn8(),lastFpsAverage:q?.averageFps,lastFpsLow1Pct:q?.low1PctFps,lastModelUsage:Object.fromEntries(Object.entries(Nx()).map(([_,z])=>[_,{inputTokens:z.inputTokens,outputTokens:z.outputTokens,cacheReadInputTokens:z.cacheReadInputTokens,cacheCreationInputTokens:z.cacheCreationInputTokens,webSearchRequests:z.webSearchRequests,costUSD:z.costUSD}])),lastSessionId:N8()}))}function a68(q,K=4){return`$${q>0.5?Voz(q,100).toFixed(2):q.toFixed(K)}`}function koz(){let q=Nx();if(Object.keys(q).length===0)return"Usage: 0 input, 0 output, 0 cache read, 0 cache write";let K={};for(let[z,Y]of Object.entries(q)){let $=bY(z);if(!K[$])K[$]={inputTokens:0,outputTokens:0,cacheReadInputTokens:0,cacheCreationInputTokens:0,webSearchRequests:0,costUSD:0,contextWindow:0,maxOutputTokens:0};let A=K[$];A.inputTokens+=Y.inputTokens,A.outputTokens+=Y.outputTokens,A.cacheReadInputTokens+=Y.cacheReadInputTokens,A.cacheCreationInputTokens+=Y.cacheCreationInputTokens,A.webSearchRequests+=Y.webSearchRequests,A.costUSD+=Y.costUSD}let _="Usage by model:";for(let[z,Y]of Object.entries(K)){let $=` ${mK(Y.inputTokens)} input, ${mK(Y.outputTokens)} output, ${mK(Y.cacheReadInputTokens)} cache read, ${mK(Y.cacheCreationInputTokens)} cache write`+(Y.webSearchRequests>0?`, ${mK(Y.webSearchRequests)} web search`:"")+` (${a68(Y.costUSD)})`;_+=` |
| 2974 | `+`${z}:`.padStart(21)+$}return _}function eI8(){let q=a68(fW())+(qi8()?" (costs may be inaccurate due to usage of unknown models)":""),K=koz();return $8.dim(`Total cost: ${q} |
| 2975 | Total duration (API): ${I5(ay())} |
| 2976 | Total duration (wall): ${I5(RX6())} |
| 2977 | Total code changes: ${l36()} ${l36()===1?"line":"lines"} added, ${n36()} ${n36()===1?"line":"lines"} removed |
| 2978 | ${K}`)}function Voz(q,K){return Math.round(q*K)/K}function Noz(q,K,_){let z=Yi8(_)??{inputTokens:0,outputTokens:0,cacheReadInputTokens:0,cacheCreationInputTokens:0,webSearchRequests:0,costUSD:0,contextWindow:0,maxOutputTokens:0};return z.inputTokens+=K.input_tokens,z.outputTokens+=K.output_tokens,z.cacheReadInputTokens+=K.cache_read_input_tokens??0,z.cacheCreationInputTokens+=K.cache_creation_input_tokens??0,z.webSearchRequests+=K.server_tool_use?.web_search_requests??0,z.costUSD+=q,z.contextWindow=lf(_,QM()),z.maxOutputTokens=t86(_).default,z}function QL6(q,K,_){let z=Noz(q,K,_);Un8(q,z,_);let Y=BK()&&K.speed==="fast"?{model:_,speed:"fast"}:{model:_};Hi8()?.add(q,Y),bX6()?.add(K.input_tokens,{...Y,type:"input"}),bX6()?.add(K.output_tokens,{...Y,type:"output"}),bX6()?.add(K.cache_read_input_tokens??0,{...Y,type:"cacheRead"}),bX6()?.add(K.cache_creation_input_tokens??0,{...Y,type:"cacheCreation"});let $=q;for(let A of Tx4(K)){let O=q86(A.model,A);d("tengu_advisor_tool_token_usage",{advisor_model:A.model,input_tokens:A.input_tokens,output_tokens:A.output_tokens,cache_read_input_tokens:A.cache_read_input_tokens??0,cache_creation_input_tokens:A.cache_creation_input_tokens??0,cost_usd_micros:Math.round(O*1e6)}),$+=QL6(O,A,A.model)}return $}var Tb=y(()=>{x3();v8();k8();eq6();V1();fP();xf();U7();aq();wn()});function Ku8(q,K){if(K===0)return q;return q.map((_)=>({..._,oldStart:_.oldStart+K,newStart:_.newStart+K}))}function s68(q){return q.replaceAll("&",dYK).replaceAll("$",cYK)}function lYK(q){return q.replaceAll(dYK,"&").replaceAll(cYK,"$")}function t68(q,K){let _=0,z=0;if(q.length===0&&K)_=K.split(/\r?\n/).length;else _=q.reduce((Y,$)=>Y+$7($.lines,(A)=>A.startsWith("+")),0),z=q.reduce((Y,$)=>Y+$7($.lines,(A)=>A.startsWith("-")),0);t58(_,z),K38()?.add(_,{type:"added"}),K38()?.add(z,{type:"removed"}),d("tengu_file_changed",{lines_added:_,lines_removed:z})}function _u8({filePath:q,oldContent:K,newContent:_,ignoreWhitespace:z=!1,singleHunk:Y=!1}){let $=Ck6(q,q,s68(K),s68(_),void 0,void 0,{ignoreWhitespace:z,context:Y?1e5:dL6,timeout:qu8});if(!$)return[];return $.hunks.map((A)=>({...A,lines:A.lines.map(lYK)}))}function _y({filePath:q,fileContents:K,edits:_,ignoreWhitespace:z=!1}){let Y=s68(jl(K)),$=Ck6(q,q,Y,_.reduce((A,O)=>{let{old_string:w,new_string:j}=O,H="replace_all"in O?O.replace_all:!1,J=s68(jl(w)),M=s68(jl(j));if(H)return A.replaceAll(J,()=>M);else return A.replace(J,()=>M)},Y),void 0,void 0,{context:dL6,ignoreWhitespace:z,timeout:qu8});if(!$)return[];return $.hunks.map((A)=>({...A,lines:A.lines.map(lYK)}))}var dL6=3,qu8=5000,dYK="<<:AMPERSAND_TOKEN:>>",cYK="<<:DOLLAR_TOKEN:>>";var BQ=y(()=>{RO6();k8();v8();Tb();bK()});import{createHash as nYK}from"crypto";function yoz(q){return nYK("sha256").update(q).digest("hex").slice(0,16)}function Eoz(q){return nYK("sha256").update(q).digest("hex")}function em(q){let K={operation:q.operation,tool:q.tool,filePathHash:yoz(q.filePath)};if(q.content!==void 0&&q.content.length<=Loz)K.contentHash=Eoz(q.content);if(q.type!==void 0)K.type=q.type;d("tengu_file_operation",K)}var Loz=102400;var zu8=y(()=>{k8()});import{access as Roz,readFile as hoz}from"fs/promises";import{dirname as Soz,join as Coz,relative as boz,sep as xoz}from"path";async function rYK(){if(!await YJ())return null;if(await aYK())return null;let{stdout:K,code:_}=await a8(L7(),["--no-optional-locks","diff","HEAD","--shortstat"],{timeout:Yu8,preserveOutputOnError:!1});if(_===0){let w=goz(K);if(w&&w.filesCount>uoz)return{stats:w,perFileStats:new Map,hunks:new Map}}let{stdout:z,code:Y}=await a8(L7(),["--no-optional-locks","diff","HEAD","--numstat"],{timeout:Yu8,preserveOutputOnError:!1});if(Y!==0)return null;let{stats:$,perFileStats:A}=moz(z),O=js1-A.size;if(O>0){let w=await Boz(O);if(w){$.filesCount+=w.size;for(let[j,H]of w)A.set(j,H)}}return{stats:$,perFileStats:A,hunks:new Map}}async function oYK(){if(!await YJ())return new Map;if(await aYK())return new Map;let{stdout:K,code:_}=await a8(L7(),["--no-optional-locks","diff","HEAD"],{timeout:Yu8,preserveOutputOnError:!1});if(_!==0)return new Map;return poz(K)}function moz(q){let K=q.trim().split(` |
| 2979 | `).filter(Boolean),_=0,z=0,Y=0,$=new Map;for(let A of K){let O=A.split("\t");if(O.length<3)continue;Y++;let w=O[0],j=O[1],H=O.slice(2).join("\t"),J=w==="-"||j==="-",M=J?0:parseInt(w??"0",10)||0,X=J?0:parseInt(j??"0",10)||0;if(_+=M,z+=X,$.size<js1)$.set(H,{added:M,removed:X,isBinary:J})}return{stats:{filesCount:Y,linesAdded:_,linesRemoved:z},perFileStats:$}}function poz(q){let K=new Map;if(!q.trim())return K;let _=q.split(/^diff --git /m).filter(Boolean);for(let z of _){if(K.size>=js1)break;if(z.length>iYK)continue;let Y=z.split(` |
| 2980 | `),$=Y[0]?.match(/^a\/(.+?) b\/(.+)$/);if(!$)continue;let A=$[2]??$[1]??"",O=[],w=null,j=0;for(let H=1;H<Y.length;H++){let J=Y[H]??"",M=J.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(M){if(w)O.push(w);w={oldStart:parseInt(M[1]??"0",10),oldLines:parseInt(M[2]??"1",10),newStart:parseInt(M[3]??"0",10),newLines:parseInt(M[4]??"1",10),lines:[]};continue}if(J.startsWith("index ")||J.startsWith("---")||J.startsWith("+++")||J.startsWith("new file")||J.startsWith("deleted file")||J.startsWith("old mode")||J.startsWith("new mode")||J.startsWith("Binary files"))continue;if(w&&(J.startsWith("+")||J.startsWith("-")||J.startsWith(" ")||J==="")){if(j>=Ioz)continue;w.lines.push(""+J),j++}}if(w)O.push(w);if(O.length>0)K.set(A,O)}return K}async function aYK(){let q=await Ap6(Z8());if(!q)return!1;return(await Promise.all(["MERGE_HEAD","REBASE_HEAD","CHERRY_PICK_HEAD","REVERT_HEAD"].map((z)=>Roz(Coz(q,z)).then(()=>!0).catch(()=>!1)))).some(Boolean)}async function Boz(q){let{stdout:K,code:_}=await a8(L7(),["--no-optional-locks","ls-files","--others","--exclude-standard"],{timeout:Yu8,preserveOutputOnError:!1});if(_!==0||!K.trim())return null;let z=K.trim().split(` |